links

lynx-like text mode web browser
git clone anongit@rnpnr.xyz:links.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 08d9bc3e0a4fe9c902fff5f0c3b32243f4977e0d
Parent: 3bbdb87105451b791ba0f5a3065ebc619fef982d
Author: opask
Date:   Wed, 25 Jul 2018 05:14:43 -0600

minor style cleanup

Diffstat:
Mblock.c | 52++++++++++++++++++++++++++++++++--------------------
Mfile.c | 10++--------
Mmain.c | 4++--
Mobjreq.c | 72++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
Mterminal.c | 26+++++++++++++-------------
Murl.c | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
Mx.c | 23++++++++++++++---------
7 files changed, 173 insertions(+), 101 deletions(-)

diff --git a/block.c b/block.c @@ -100,7 +100,8 @@ static void block_edit_abort(struct dialog_data *data) struct dialog *dlg = data->dlg; free(dlg->udata2); - if (item) block_delete_item(&item->head); + if (item) + block_delete_item(&item->head); } /* Puts url into the block list */ @@ -135,15 +136,19 @@ static void block_edit_item_fn(struct dialog_data *dlg) unsigned char *text = TEXT_(T_ENTER_URL); - if (dlg->win->term->spec->braille) y += gf_val(1, G_BFU_FONT_SIZE); + if (dlg->win->term->spec->braille) + y += gf_val(1, G_BFU_FONT_SIZE); max_text_width(term, text, &max, AL_LEFT); min_text_width(term, text, &min, AL_LEFT); max_buttons_width(term, dlg->items + 1, 2, &max); min_buttons_width(term, dlg->items + 1, 2, &min); - if (max < dlg->dlg->items->dlen) max = dlg->dlg->items->dlen; + if (max < dlg->dlg->items->dlen) + max = dlg->dlg->items->dlen; w = term->x * 9 / 10 - 2 * DIALOG_LB; - if (w > max) w = max; - if (w < min) w = min; + if (w > max) + w = max; + if (w < min) + w = min; rw = w; dlg_format_text_and_field(dlg, NULL, text, dlg->items, 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT); y += LL; @@ -154,7 +159,8 @@ static void block_edit_item_fn(struct dialog_data *dlg) center_dlg(dlg); draw_dlg(dlg); y = dlg->y + DIALOG_TB; - if (dlg->win->term->spec->braille) y += gf_val(1, G_BFU_FONT_SIZE); + if (dlg->win->term->spec->braille) + y += gf_val(1, G_BFU_FONT_SIZE); dlg_format_text_and_field(dlg, term, text, dlg->items, dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT); y += LL; dlg_format_buttons(dlg, term, dlg->items + 1, 2, dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER); @@ -172,8 +178,10 @@ static void block_edit_item(struct dialog_data *dlg, struct list *data, void (*o unsigned char *url, *txt; /*Allocate space for dialog, 4 items followed by 1 string*/ - d = xmalloc(sizeof(struct dialog) + 4 * sizeof(struct dialog_item) + 1 * MAX_STR_LEN); - memset(d, 0, sizeof(struct dialog) + 4 * sizeof(struct dialog_item) + 1 * MAX_STR_LEN); + d = xmalloc(sizeof(struct dialog) + 4 * sizeof(struct dialog_item) + + 1 * MAX_STR_LEN); + memset(d, 0, sizeof(struct dialog) + 4 * sizeof(struct dialog_item) + + 1 * MAX_STR_LEN); /*Set up this string */ url = (unsigned char *)&d->items[4]; @@ -189,16 +197,16 @@ static void block_edit_item(struct dialog_data *dlg, struct list *data, void (*o s->dlg = dlg; switch (dlg_title) { - case TITLE_EDIT: - d->title = TEXT_(T_BLOCK_EDIT); - break; + case TITLE_EDIT: + d->title = TEXT_(T_BLOCK_EDIT); + break; - case TITLE_ADD: - d->title = TEXT_(T_BLOCK_ADD); - break; + case TITLE_ADD: + d->title = TEXT_(T_BLOCK_ADD); + break; - default: - internal("Unsupported dialog title.\n"); + default: + internal("Unsupported dialog title.\n"); } d->udata = neww; @@ -300,19 +308,23 @@ static unsigned char *find_first_match(unsigned char *s, unsigned char *p, unsig } } *ii = i; - if (!p[i] || p[i] == '*') return s; + if (!p[i] || p[i] == '*') + return s; return NULL; } static int simple_glob_match(unsigned char *s, unsigned char *p) { unsigned i; - if (find_first_match(s, p, &i) != s) return 0; - if (!p[i]) return !s[i]; + if (find_first_match(s, p, &i) != s) + return 0; + if (!p[i]) + return !s[i]; while (1) { s += i; p += i + 1; - if (!(s = find_first_match(s, p, &i))) return 0; + if (!(s = find_first_match(s, p, &i))) + return 0; if (!p[i]) { s += strlen(cast_const_char s) - i; return !!find_first_match(s, p, &i); diff --git a/file.c b/file.c @@ -414,11 +414,7 @@ void file_func(struct connection *c) head = stracpy(cast_uchar "\r\nContent-Type: text/html\r\n"); } else { free(name); - if ( -#ifndef __WATCOMC__ - stt.st_size < 0 || -#endif - stt.st_size > MAXINT) { + if (stt.st_size < 0 || stt.st_size > MAXINT) { EINTRLOOP(rs, close(h)); setcstate(c, S_LARGE_FILE); abort_connection(c); return; @@ -431,9 +427,7 @@ void file_func(struct connection *c) setcstate(c, S_OUT_OF_MEM); abort_connection(c); return; } - if ((r = hard_read(h, file, (int)stt.st_size)) - != stt.st_size - ) { + if ((r = hard_read(h, file, (int)stt.st_size)) != stt.st_size) { free(file); EINTRLOOP(rs, close(h)); setcstate(c, r == -1 ? get_error_from_errno(errno) : S_FILE_ERROR); diff --git a/main.c b/main.c @@ -255,9 +255,9 @@ void gfx_connection(int h) goto err_close_free; term = init_gfx_term(win_func, cwd, info, info_len); if (term) { - if (hold_conn) { + if (hold_conn) term->handle_to_close = h; - } else { + else { hard_write(h, cast_uchar "x", 1); EINTRLOOP(r, close(h)); } diff --git a/objreq.c b/objreq.c @@ -322,7 +322,11 @@ static void objreq_end(struct status *stat, void *data) set_ce_internal(rq); if (stat->state < 0) { - if (!stat->ce && rq->state == O_WAITING && (stat->state == S_INVALID_CERTIFICATE || stat->state == S_DOWNGRADED_METHOD || stat->state == S_INSECURE_CIPHER) && ssl_options.certificates == SSL_WARN_ON_INVALID_CERTIFICATE) { + if (!stat->ce && rq->state == O_WAITING + && (stat->state == S_INVALID_CERTIFICATE + || stat->state == S_DOWNGRADED_METHOD + || stat->state == S_INSECURE_CIPHER) + && ssl_options.certificates == SSL_WARN_ON_INVALID_CERTIFICATE) { if (!cert_window(rq)) { rq->hold = HOLD_CERT; rq->redirect_cnt = 0; @@ -339,9 +343,16 @@ static void objreq_end(struct status *stat, void *data) free(rq->goto_position); rq->goto_position = pos; } - if (!http_options.bug_302_redirect && !stat->ce->redirect_get && (p = cast_uchar strchr(cast_const_char u, POST_CHAR))) add_to_strn(&u, p); + if (!http_options.bug_302_redirect + && !stat->ce->redirect_get + && (p = cast_uchar strchr(cast_const_char u, POST_CHAR))) + add_to_strn(&u, p); cache = rq->cache; - if (cache < NC_RELOAD && (!strcmp(cast_const_char u, cast_const_char rq->url) || !strcmp(cast_const_char u, cast_const_char rq->orig_url) || rq->redirect_cnt >= MAX_CACHED_REDIRECTS)) cache = NC_RELOAD; + if (cache < NC_RELOAD + && (!strcmp(cast_const_char u, cast_const_char rq->url) + || !strcmp(cast_const_char u, cast_const_char rq->orig_url) + || rq->redirect_cnt >= MAX_CACHED_REDIRECTS)) + cache = NC_RELOAD; allow_flags = get_allow_flags(rq->url); free(rq->url); rq->url = u; @@ -352,15 +363,22 @@ static void objreq_end(struct status *stat, void *data) rq->stat.state = S_CYCLIC_REDIRECT; } } - if (stat->ce && rq->state == O_WAITING && (stat->ce->http_code == 401 || stat->ce->http_code == 407)) { - unsigned char *realm = get_auth_realm(rq->url, stat->ce->head, stat->ce->http_code == 407); + if (stat->ce && rq->state == O_WAITING + && (stat->ce->http_code == 401 || stat->ce->http_code == 407)) { + unsigned char *realm = get_auth_realm(rq->url, + stat->ce->head, + stat->ce->http_code == 407); unsigned char *user; - if (!realm) goto xx; - if (stat->ce->http_code == 401 && !find_auth(rq->url, realm)) { + if (!realm) + goto xx; + if (stat->ce->http_code == 401 + && !find_auth(rq->url, realm)) { free(realm); - if (rq->redirect_cnt++ >= MAX_REDIRECTS) goto maxrd; + if (rq->redirect_cnt++ >= MAX_REDIRECTS) + goto maxrd; change_connection(stat, NULL, PRI_CANCEL); - load_url(rq->url, rq->prev_url, &rq->stat, rq->pri, NC_RELOAD, 0, 0, 0); + load_url(rq->url, rq->prev_url, &rq->stat, + rq->pri, NC_RELOAD, 0, 0, 0); return; } user = get_user_name(rq->url); @@ -380,16 +398,21 @@ static void objreq_end(struct status *stat, void *data) goto xx; } } - if ((stat->state < 0 || stat->state == S_TRANS) && stat->ce && !stat->ce->redirect && stat->ce->http_code != 401 && stat->ce->http_code != 407) { + if ((stat->state < 0 || stat->state == S_TRANS) + && stat->ce && !stat->ce->redirect + && stat->ce->http_code != 401 + && stat->ce->http_code != 407) { rq->state = O_LOADING; if (0) { xx: rq->state = O_OK; } - if (!rq->ce) (rq->ce = stat->ce)->refcount++; + if (!rq->ce) + (rq->ce = stat->ce)->refcount++; } tm: - if (rq->timer != NULL) kill_timer(rq->timer); + if (rq->timer != NULL) + kill_timer(rq->timer); rq->timer = install_timer(0, object_timer, rq); } @@ -403,17 +426,22 @@ static void object_timer(void *rq_) set_ce_internal(rq); last = rq->last_bytes; - if (rq->ce) rq->last_bytes = rq->ce->length; - if (rq->stat.state < 0 && !rq->hold && (!rq->ce_internal || !rq->ce_internal->redirect || rq->stat.state == S_CYCLIC_REDIRECT)) { + if (rq->ce) + rq->last_bytes = rq->ce->length; + if (rq->stat.state < 0 && !rq->hold + && (!rq->ce_internal || !rq->ce_internal->redirect + || rq->stat.state == S_CYCLIC_REDIRECT)) { if (rq->ce_internal && rq->stat.state != S_CYCLIC_REDIRECT) { rq->state = rq->stat.state != S__OK ? O_INCOMPLETE : O_OK; - } else rq->state = O_FAILED; + } else + rq->state = O_FAILED; } if (rq->stat.state != S_TRANS) { if (rq->stat.state >= 0) rq->timer = install_timer(STAT_UPDATE_MAX, object_timer, rq); rq->last_update = get_time() - STAT_UPDATE_MAX; - if (rq->upcall) rq->upcall(rq, rq->data); + if (rq->upcall) + rq->upcall(rq, rq->data); } else { uttime ct = get_time(); uttime t = ct - rq->last_update; @@ -430,11 +458,15 @@ void release_object_get_stat(struct object_request **rqq, struct status *news, i struct object_request *rq = *rqq; if (!rq) return; *rqq = NULL; - if (--rq->refcount) return; + if (--rq->refcount) + return; change_connection(&rq->stat, news, pri); - if (rq->timer != NULL) kill_timer(rq->timer); - if (rq->ce_internal) rq->ce_internal->refcount--; - if (rq->ce) rq->ce->refcount--; + if (rq->timer != NULL) + kill_timer(rq->timer); + if (rq->ce_internal) + rq->ce_internal->refcount--; + if (rq->ce) + rq->ce->refcount--; free(rq->orig_url); free(rq->url); free(rq->prev_url); diff --git a/terminal.c b/terminal.c @@ -508,17 +508,18 @@ static void empty_window_handler(struct window *win, struct links_event *ev, int int x, y; void (*fn)(void *) = ewd->fn; void *data = ewd->data; - if (ewd->b) return; + if (ewd->b) + return; switch ((int)ev->ev) { - case EV_INIT: - case EV_RESIZE: - case EV_REDRAW: - get_parent_ptr(win, &x, &y); - set_window_ptr(win, x, y); - return; - case EV_ABORT: - fn(data); - return; + case EV_INIT: + case EV_RESIZE: + case EV_REDRAW: + get_parent_ptr(win, &x, &y); + set_window_ptr(win, x, y); + return; + case EV_ABORT: + fn(data); + return; } ewd->b = 1; ln = win->list_entry.next; @@ -1022,10 +1023,9 @@ static void redraw_screen(struct terminal *term) memcpy(&term->last_screen[p], &term->screen[p], sizeof(chr)); continue; } - /*if ((term->screen[p].at & 0x38) == (term->last_screen[p].at & 0x38) && (term->screen[p].ch == 0 || term->screen[p].ch == 1 || term->screen[p].ch == ' ') && (term->last_screen[p].ch == 0 || term->last_screen[p].ch == 1 || term->last_screen[p].ch == ' ') && (x != term->cx || y != term->cy)) continue;*/ - /*fprintf(stderr, "%d.%d : %d-%d -> %d-%d\n", x, y, term->last_screen[p].ch, term->last_screen[p].at, term->screen[p].ch, term->screen[p].at);*/ memcpy(&term->last_screen[p], &term->screen[p], sizeof(chr)); - if (cx == x && cy == y) goto pc;/*PRINT_CHAR(p)*/ + if (cx == x && cy == y) + goto pc; else if (cy == y && x - cx < 10 && x - cx > 0) { for (i = x - cx; i >= 0; i--) { ppc: diff --git a/url.c b/url.c @@ -42,11 +42,16 @@ static int get_prot_info(unsigned char *prot, int *port, void (**func)(struct co int i; for (i = 0; protocols[i].prot; i++) if (!casestrcmp(cast_uchar protocols[i].prot, prot)) { - if (port) *port = protocols[i].port; - if (func) *func = protocols[i].func; - if (nc_func) *nc_func = protocols[i].nc_func; - if (allow_post) *allow_post = protocols[i].allow_post; - if (bypasses_socks) *bypasses_socks = protocols[i].bypasses_socks; + if (port) + *port = protocols[i].port; + if (func) + *func = protocols[i].func; + if (nc_func) + *nc_func = protocols[i].nc_func; + if (allow_post) + *allow_post = protocols[i].allow_post; + if (bypasses_socks) + *bypasses_socks = protocols[i].bypasses_socks; return 0; } return -1; @@ -57,28 +62,46 @@ int parse_url(unsigned char *url, int *prlen, unsigned char **user, int *uslen, unsigned char *p, *q; unsigned char p_c[2]; int a; - if (prlen) *prlen = 0; - if (user) *user = NULL; - if (uslen) *uslen = 0; - if (pass) *pass = NULL; - if (palen) *palen = 0; - if (host) *host = NULL; - if (holen) *holen = 0; - if (port) *port = NULL; - if (polen) *polen = 0; - if (data) *data = NULL; - if (dalen) *dalen = 0; - if (post) *post = NULL; - if (!url || !(p = cast_uchar strchr(cast_const_char url, ':'))) return -1; - if (prlen) *prlen = (int)(p - url); - if ((a = check_protocol(url, (int)(p - url))) == -1) return -1; + if (prlen) + *prlen = 0; + if (user) + *user = NULL; + if (uslen) + *uslen = 0; + if (pass) + *pass = NULL; + if (palen) + *palen = 0; + if (host) + *host = NULL; + if (holen) + *holen = 0; + if (port) + *port = NULL; + if (polen) + *polen = 0; + if (data) + *data = NULL; + if (dalen) + *dalen = 0; + if (post) + *post = NULL; + if (!url || !(p = cast_uchar strchr(cast_const_char url, ':'))) + return -1; + if (prlen) + *prlen = (int)(p - url); + if ((a = check_protocol(url, (int)(p - url))) == -1) + return -1; if (p[1] != '/' || p[2] != '/') { - if (protocols[a].need_slashes) return -1; + if (protocols[a].need_slashes) + return -1; p -= 2; } if (protocols[a].free_syntax) { - if (data) *data = p + 3; - if (dalen) *dalen = (int)strlen(cast_const_char(p + 3)); + if (data) + *data = p + 3; + if (dalen) + *dalen = (int)strlen(cast_const_char(p + 3)); return 0; } p += 3; @@ -90,13 +113,19 @@ int parse_url(unsigned char *url, int *prlen, unsigned char **user, int *uslen, q = q + 1 + strcspn(cast_const_char(q + 1), "@"); pp = cast_uchar strchr(cast_const_char p, ':'); if (!pp || pp > q) { - if (user) *user = p; - if (uslen) *uslen = (int)(q - p); + if (user) + *user = p; + if (uslen) + *uslen = (int)(q - p); } else { - if (user) *user = p; - if (uslen) *uslen = (int)(pp - p); - if (pass) *pass = pp + 1; - if (palen) *palen = (int)(q - pp - 1); + if (user) + *user = p; + if (uslen) + *uslen = (int)(pp - p); + if (pass) + *pass = pp + 1; + if (palen) + *palen = (int)(q - pp - 1); } p = q + 1; } diff --git a/x.c b/x.c @@ -189,8 +189,7 @@ static unsigned char process_events_in_progress=0; static inline void X_SCHEDULE_PROCESS_EVENTS(void) { - if (!process_events_in_progress) - { + if (!process_events_in_progress) { register_bottom_half(x_process_events, NULL); process_events_in_progress = 1; } @@ -209,10 +208,9 @@ static void x_do_flush(void *ignore) static inline void X_FLUSH(void) { - if (!flush_in_progress) - { + if (!flush_in_progress) { register_bottom_half(x_do_flush, NULL); - flush_in_progress=1; + flush_in_progress = 1; } } @@ -245,8 +243,10 @@ static int x_test_for_failure(void) /* suppose l<h */ static void x_clip_number(int *n,int l,int h) { - if ((*n)<l)*n=l; - if ((*n)>h)*n=h; + if ((*n) < l) + *n=l; + if ((*n) > h) + *n=h; } @@ -320,8 +320,13 @@ static unsigned char *x_query_palette(void) static inline int trans_key(unsigned char * str, int table) { - if (table==utf8_table){int a; GET_UTF_8(str,a);return a;} - if (*str<128)return *str; + if (table == utf8_table) { + int a; + GET_UTF_8(str,a); + return a; + } + if (*str < 128) + return *str; return cp2u(*str,table); }