Commit: 62eb5aa3d6f9ae5bdeb04a7d11297ef60b54c5ff
Parent: 223b598028b0e88ac76cd187fcf2ada390d0a0d8
Author: Randy Palamar
Date: Mon, 28 Nov 2022 21:14:06 -0700
add and apply .clang-format
Diffstat:
A | .clang-format | | | 36 | ++++++++++++++++++++++++++++++++++++ |
M | Makefile | | | 2 | ++ |
M | auth.c | | | 197 | +++++++++++++++++++++++++++++++++++++++++++++++++------------------------------ |
M | bfu.c | | | 1440 | ++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- |
M | bookmark.c | | | 311 | +++++++++++++++++++++++++++++++++++++++++++++---------------------------------- |
M | cache.c | | | 229 | +++++++++++++++++++++++++++++++++++++++++++++++++------------------------------ |
M | charsets.c | | | 179 | +++++++++++++++++++++++++++++++++++++++++++++---------------------------------- |
M | compress.c | | | 158 | ++++++++++++++++++++++++++++++++++++++++++++++++------------------------------- |
M | connect.c | | | 366 | ++++++++++++++++++++++++++++++++++++++++++++++++------------------------------- |
M | cookies.c | | | 64 | +++++++++++++++++++++++++++++++++++++--------------------------- |
M | data.c | | | 29 | +++++++++++++++++++---------- |
M | default.c | | | 1026 | +++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------- |
M | dns.c | | | 193 | +++++++++++++++++++++++++++++++++++++++++++++++++------------------------------ |
M | error.c | | | 15 | ++++++++++----- |
M | file.c | | | 178 | +++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------- |
M | html.c | | | 2649 | +++++++++++++++++++++++++++++++++++++++++++++++++------------------------------ |
M | html_r.c | | | 1089 | ++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- |
M | html_tbl.c | | | 1279 | +++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------- |
M | http.c | | | 323 | ++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- |
M | https.c | | | 103 | ++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- |
M | kbd.c | | | 752 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------ |
M | language.c | | | 5 | +++-- |
M | links.h | | | 1149 | ++++++++++++++++++++++++++++++++++++++++++++----------------------------------- |
M | listedit.c | | | 1477 | +++++++++++++++++++++++++++++++++++++++++++++---------------------------------- |
M | main.c | | | 146 | +++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------- |
M | memory.c | | | 32 | +++++++++++++++++++------------- |
M | menu.c | | | 1281 | +++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------- |
M | objreq.c | | | 263 | ++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- |
M | os_dep.c | | | 271 | ++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- |
M | os_dep.h | | | 10 | +++++++--- |
M | sched.c | | | 368 | ++++++++++++++++++++++++++++++++++++++++++++++++------------------------------- |
M | select.c | | | 397 | ++++++++++++++++++++++++++++++++++++++++++++++++------------------------------- |
M | session.c | | | 2052 | ++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- |
M | setup.h | | | 149 | ++++++++++++++++++++++++++++++++++++++++--------------------------------------- |
M | string.c | | | 102 | +++++++++++++++++++++++++++++++++++++++++++++++++------------------------------ |
M | suffix.c | | | 35 | +++++++++++++++++++++-------------- |
M | terminal.c | | | 621 | ++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- |
M | types.c | | | 608 | ++++++++++++++++++++++++++++++++++++++++++++++++------------------------------- |
M | url.c | | | 333 | +++++++++++++++++++++++++++++++++++++++++++++++++------------------------------ |
M | view.c | | | 3040 | +++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------- |
40 files changed, 14546 insertions(+), 8411 deletions(-)
diff --git a/.clang-format b/.clang-format
@@ -0,0 +1,36 @@
+AlignAfterOpenBracket: Align
+AlignArrayOfStructures: Left
+AlignConsecutiveBitFields:
+ Enabled: true
+ AcrossEmptyLines: false
+ AcrossComments: false
+AlignConsecutiveMacros:
+ Enabled: true
+ AcrossEmptyLines: false
+ AcrossComments: false
+AlignEscapedNewlines: Right
+AlignOperands: Align
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: false
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: true
+BinPackArguments: true
+BinPackParameters: true
+BreakBeforeBinaryOperators: NonAssignment
+BreakBeforeBraces: Linux
+ColumnLimit: 80
+Cpp11BracedListStyle: false
+ForEachMacros: [foreach, foreachfrom, foreachbackfrom, foreachback]
+IndentGotoLabels: false
+IndentPPDirectives: BeforeHash
+IndentWidth: 8
+MaxEmptyLinesToKeep: 1
+PointerAlignment: Right
+ReflowComments: true
+SpaceAfterCStyleCast: false
+TabWidth: 8
+UseCRLF: false
+UseTab: AlignWithSpaces
+...
diff --git a/Makefile b/Makefile
@@ -59,6 +59,8 @@ $(OBJ): config.h config.mk
links: $(OBJ)
$(CC) -o $@ $(OBJ) $(LDFLAGS)
+format:
+ clang-format -i $(SRC) links.h os_dep.h setup.h
clean:
rm -f *.o links
diff --git a/auth.c b/auth.c
@@ -2,11 +2,10 @@
#include "links.h"
-static struct list_head auth = {&auth, &auth};
+static struct list_head auth = { &auth, &auth };
struct http_auth {
- list_entry_1st
- unsigned char *host;
+ list_entry_1st unsigned char *host;
int port;
unsigned char *realm;
unsigned char *user;
@@ -16,38 +15,42 @@ struct http_auth {
int proxy;
};
-static const unsigned char base64_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+static const unsigned char base64_chars[] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-static unsigned char *base64_encode(unsigned char *in, size_t inlen)
+static unsigned char *
+base64_encode(unsigned char *in, size_t inlen)
{
unsigned char *out, *outstr;
size_t data_len;
int line_mask = ~0;
int col;
- if (inlen > INT_MAX / 2) overalloc();
+ if (inlen > INT_MAX / 2)
+ overalloc();
data_len = ((inlen + 2) / 3) * 4;
out = outstr = xmalloc(data_len + 1);
col = 0;
while (inlen >= 3) {
- *out++ = base64_chars[ (int)(in[0] >> 2) ];
- *out++ = base64_chars[ (int)((in[0] << 4 | in[1] >> 4) & 63) ];
- *out++ = base64_chars[ (int)((in[1] << 2 | in[2] >> 6) & 63) ];
- *out++ = base64_chars[ (int)(in[2] & 63) ];
- inlen -= 3; in += 3;
+ *out++ = base64_chars[(int)(in[0] >> 2)];
+ *out++ = base64_chars[(int)((in[0] << 4 | in[1] >> 4) & 63)];
+ *out++ = base64_chars[(int)((in[1] << 2 | in[2] >> 6) & 63)];
+ *out++ = base64_chars[(int)(in[2] & 63)];
+ inlen -= 3;
+ in += 3;
if (!((col += 4) & line_mask))
*out++ = '\n';
}
switch (inlen) {
case 1:
- *out++ = base64_chars[ (int)(in[0] >> 2) ];
- *out++ = base64_chars[ (int)(in[0] << 4 & 63) ];
+ *out++ = base64_chars[(int)(in[0] >> 2)];
+ *out++ = base64_chars[(int)(in[0] << 4 & 63)];
*out++ = '=';
*out++ = '=';
break;
case 2:
- *out++ = base64_chars[ (int)(in[0] >> 2) ];
- *out++ = base64_chars[ (int)((in[0] << 4 | in[1] >> 4) & 63) ];
- *out++ = base64_chars[ (int)((in[1] << 2) & 63) ];
+ *out++ = base64_chars[(int)(in[0] >> 2)];
+ *out++ = base64_chars[(int)((in[0] << 4 | in[1] >> 4) & 63)];
+ *out++ = base64_chars[(int)((in[1] << 2) & 63)];
*out++ = '=';
default:;
}
@@ -55,7 +58,8 @@ static unsigned char *base64_encode(unsigned char *in, size_t inlen)
return outstr;
}
-static unsigned char *basic_encode(unsigned char *user, unsigned char *password)
+static unsigned char *
+basic_encode(unsigned char *user, unsigned char *password)
{
unsigned char *e, *p;
p = stracpy(user);
@@ -66,24 +70,31 @@ static unsigned char *basic_encode(unsigned char *user, unsigned char *password)
return e;
}
-unsigned char *get_auth_realm(unsigned char *url, unsigned char *head, int proxy)
+unsigned char *
+get_auth_realm(unsigned char *url, unsigned char *head, int proxy)
{
unsigned char *ch = head;
unsigned char *h, *q, *r;
int l;
int unknown = 0;
int known = 0;
- try_next:
- h = parse_http_header(ch, !proxy ? (unsigned char *)"WWW-Authenticate" : (unsigned char *)"Proxy-Authenticate", &ch);
+try_next:
+ h = parse_http_header(ch,
+ !proxy ? (unsigned char *)"WWW-Authenticate"
+ : (unsigned char *)"Proxy-Authenticate",
+ &ch);
if (!h) {
- if (unknown && !known) return NULL;
+ if (unknown && !known)
+ return NULL;
if (proxy) {
unsigned char *p = get_proxy_string(url);
- if (!p) p = cast_uchar "";
+ if (!p)
+ p = cast_uchar "";
return stracpy(p);
} else {
unsigned char *u = get_host_name(url);
- if (u) return u;
+ if (u)
+ return u;
return stracpy(cast_uchar "");
}
}
@@ -102,14 +113,16 @@ unsigned char *get_auth_realm(unsigned char *url, unsigned char *head, int proxy
r = init_str();
l = 0;
while (*q && *q != '"') {
- if (*q == '\\' && !*++q) break;
+ if (*q == '\\' && !*++q)
+ break;
add_chr_to_str(&r, &l, *q++);
}
free(h);
return r;
}
-static unsigned char *auth_from_url(unsigned char *url, int proxy)
+static unsigned char *
+auth_from_url(unsigned char *url, int proxy)
{
unsigned char *r = NULL;
int l = 0;
@@ -120,7 +133,8 @@ static unsigned char *auth_from_url(unsigned char *url, int proxy)
if (user && *user && password) {
unsigned char *e = basic_encode(user, password);
r = init_str();
- if (proxy) add_to_str(&r, &l, cast_uchar "Proxy-");
+ if (proxy)
+ add_to_str(&r, &l, cast_uchar "Proxy-");
add_to_str(&r, &l, cast_uchar "Authorization: Basic ");
add_to_str(&r, &l, e);
add_to_str(&r, &l, cast_uchar "\r\n");
@@ -134,7 +148,8 @@ static unsigned char *auth_from_url(unsigned char *url, int proxy)
return NULL;
}
-unsigned char *get_auth_string(unsigned char *url, int proxy)
+unsigned char *
+get_auth_string(unsigned char *url, int proxy)
{
struct http_auth *a = NULL;
struct list_head *la;
@@ -142,38 +157,53 @@ unsigned char *get_auth_string(unsigned char *url, int proxy)
int port;
unsigned char *r = NULL;
int l = 0;
- if (proxy && !is_proxy_url(url)) return NULL;
- if (!(host = get_host_name(url))) return NULL;
+ if (proxy && !is_proxy_url(url))
+ return NULL;
+ if (!(host = get_host_name(url)))
+ return NULL;
port = get_port(url);
- if (!proxy && (r = auth_from_url(url, proxy))) goto have_passwd;
+ if (!proxy && (r = auth_from_url(url, proxy)))
+ goto have_passwd;
- foreach(struct http_auth, a, la, auth) if (a->proxy == proxy && !casestrcmp(a->host, host) && a->port == port) {
- unsigned char *d, *data;
- if (proxy) goto skip_dir_check;
- data = get_url_data(url);
- d = cast_uchar strrchr(cast_const_char data, '/');
- if (!d) d = data;
- else d++;
- if ((size_t)(d - data) >= strlen(cast_const_char a->directory) && !memcmp(data, a->directory, strlen(cast_const_char a->directory))) {
- skip_dir_check:
- r = init_str();
- if (proxy) add_to_str(&r, &l, cast_uchar "Proxy-");
- add_to_str(&r, &l, cast_uchar "Authorization: Basic ");
- add_to_str(&r, &l, a->user_password_encoded);
- add_to_str(&r, &l, cast_uchar "\r\n");
- goto have_passwd;
+ foreach (struct http_auth, a, la, auth)
+ if (a->proxy == proxy && !casestrcmp(a->host, host)
+ && a->port == port) {
+ unsigned char *d, *data;
+ if (proxy)
+ goto skip_dir_check;
+ data = get_url_data(url);
+ d = cast_uchar strrchr(cast_const_char data, '/');
+ if (!d)
+ d = data;
+ else
+ d++;
+ if ((size_t)(d - data)
+ >= strlen(cast_const_char a->directory)
+ && !memcmp(data, a->directory,
+ strlen(cast_const_char a->directory))) {
+skip_dir_check:
+ r = init_str();
+ if (proxy)
+ add_to_str(&r, &l, cast_uchar "Proxy-");
+ add_to_str(&r, &l,
+ cast_uchar "Authorization: Basic ");
+ add_to_str(&r, &l, a->user_password_encoded);
+ add_to_str(&r, &l, cast_uchar "\r\n");
+ goto have_passwd;
+ }
}
- }
- if (proxy && (r = auth_from_url(url, proxy))) goto have_passwd;
+ if (proxy && (r = auth_from_url(url, proxy)))
+ goto have_passwd;
- have_passwd:
+have_passwd:
free(host);
return r;
}
-static void free_auth_entry(struct http_auth *a)
+static void
+free_auth_entry(struct http_auth *a)
{
free(a->host);
free(a->realm);
@@ -185,17 +215,21 @@ static void free_auth_entry(struct http_auth *a)
free(a);
}
-void free_auth(void)
+void
+free_auth(void)
{
- while (!list_empty(auth)) free_auth_entry(list_struct(auth.next, struct http_auth));
+ while (!list_empty(auth))
+ free_auth_entry(list_struct(auth.next, struct http_auth));
}
-void add_auth(unsigned char *url, unsigned char *realm, unsigned char *user, unsigned char *password, int proxy)
+void
+add_auth(unsigned char *url, unsigned char *realm, unsigned char *user,
+ unsigned char *password, int proxy)
{
struct http_auth *a = NULL;
struct list_head *la;
unsigned char *host = NULL;
- int port = 0 /* against warning */;
+ int port = 0 /* against warning */;
if (!proxy) {
host = get_host_name(url);
port = get_port(url);
@@ -207,11 +241,16 @@ void add_auth(unsigned char *url, unsigned char *realm, unsigned char *user, uns
}
free(p);
}
- if (!host) return;
- foreach(struct http_auth, a, la, auth) if (a->proxy == proxy && !casestrcmp(a->host, host) && a->port == port && !strcmp(cast_const_char a->realm, cast_const_char realm)) {
- la = la->prev;
- free_auth_entry(a);
- }
+ if (!host)
+ return;
+ foreach (struct http_auth, a, la, auth)
+ if (a->proxy == proxy && !casestrcmp(a->host, host)
+ && a->port == port
+ && !strcmp(cast_const_char a->realm,
+ cast_const_char realm)) {
+ la = la->prev;
+ free_auth_entry(a);
+ }
a = xmalloc(sizeof(struct http_auth));
a->host = host;
a->port = port;
@@ -220,37 +259,47 @@ void add_auth(unsigned char *url, unsigned char *realm, unsigned char *user, uns
a->password = stracpy(password);
if (!proxy) {
unsigned char *data = stracpy(get_url_data(url));
- unsigned char *d = cast_uchar strrchr(cast_const_char data, '/');
- if (d) d[1] = 0;
- else data[0] = 0;
+ unsigned char *d =
+ cast_uchar strrchr(cast_const_char data, '/');
+ if (d)
+ d[1] = 0;
+ else
+ data[0] = 0;
a->directory = data;
- } else a->directory = NULL;
+ } else
+ a->directory = NULL;
a->proxy = proxy;
a->user_password_encoded = basic_encode(a->user, a->password);
add_to_list(auth, a);
}
-int find_auth(unsigned char *url, unsigned char *realm)
+int
+find_auth(unsigned char *url, unsigned char *realm)
{
struct http_auth *a = NULL;
struct list_head *la;
unsigned char *data, *d;
unsigned char *host = get_host_name(url);
int port = get_port(url);
- if (!host) return -1;
+ if (!host)
+ return -1;
data = stracpy(get_url_data(url));
d = cast_uchar strrchr(cast_const_char data, '/');
- if (d) d[1] = 0;
- foreach(struct http_auth, a, la, auth) if (!a->proxy && !casestrcmp(a->host, host) && a->port == port && !strcmp(cast_const_char a->realm, cast_const_char realm) && strcmp(cast_const_char a->directory, cast_const_char data)) {
- free(a->directory);
- a->directory = data;
- free(host);
- del_from_list(a);
- add_to_list(auth, a);
- return 0;
- }
+ if (d)
+ d[1] = 0;
+ foreach (struct http_auth, a, la, auth)
+ if (!a->proxy && !casestrcmp(a->host, host) && a->port == port
+ && !strcmp(cast_const_char a->realm, cast_const_char realm)
+ && strcmp(cast_const_char a->directory,
+ cast_const_char data)) {
+ free(a->directory);
+ a->directory = data;
+ free(host);
+ del_from_list(a);
+ add_to_list(auth, a);
+ return 0;
+ }
free(host);
free(data);
return -1;
}
-
diff --git a/bfu.c b/bfu.c
@@ -10,7 +10,8 @@
static void menu_func(struct window *, struct links_event *, int);
static void mainmenu_func(struct window *, struct links_event *, int);
-struct memory_list *getml(void *p, ...)
+struct memory_list *
+getml(void *p, ...)
{
struct memory_list *ml;
va_list ap;
@@ -23,7 +24,8 @@ struct memory_list *getml(void *p, ...)
n++;
q = va_arg(ap, void *);
}
- if ((unsigned)n > (INT_MAX - sizeof(struct memory_list)) / sizeof(void *))
+ if ((unsigned)n
+ > (INT_MAX - sizeof(struct memory_list)) / sizeof(void *))
overalloc();
ml = xmalloc(sizeof(struct memory_list) + n * sizeof(void *));
ml->n = n;
@@ -39,7 +41,8 @@ struct memory_list *getml(void *p, ...)
return ml;
}
-void add_to_ml(struct memory_list **ml, ...)
+void
+add_to_ml(struct memory_list **ml, ...)
{
struct memory_list *nml;
va_list ap;
@@ -55,41 +58,49 @@ void add_to_ml(struct memory_list **ml, ...)
overalloc();
n++;
}
- if ((unsigned)n + (unsigned)((*ml)->n) > (INT_MAX - sizeof(struct memory_list)) / sizeof(void *))
+ if ((unsigned)n + (unsigned)((*ml)->n)
+ > (INT_MAX - sizeof(struct memory_list)) / sizeof(void *))
overalloc();
nml = xrealloc(*ml, sizeof(struct memory_list)
- + (n + (*ml)->n) * sizeof(void *));
+ + (n + (*ml)->n) * sizeof(void *));
va_end(ap);
va_start(ap, ml);
- while ((q = va_arg(ap, void *))) nml->p[nml->n++] = q;
+ while ((q = va_arg(ap, void *)))
+ nml->p[nml->n++] = q;
*ml = nml;
va_end(ap);
}
-void freeml(struct memory_list *ml)
+void
+freeml(struct memory_list *ml)
{
int i;
- if (!ml) return;
+ if (!ml)
+ return;
for (i = 0; i < ml->n; i++)
free(ml->p[i]);
free(ml);
}
-static inline int is_utf_8(struct terminal *term)
+static inline int
+is_utf_8(struct terminal *term)
{
if (!term_charset(term))
return 1;
return 0;
}
-static inline int txtlen(struct terminal *term, unsigned char *s)
+static inline int
+txtlen(struct terminal *term, unsigned char *s)
{
return strlen((char *)s);
}
unsigned char m_bar = 0;
-static unsigned select_hotkey(struct terminal *term, unsigned char *text, unsigned char *hotkey, unsigned *hotkeys, int n)
+static unsigned
+select_hotkey(struct terminal *term, unsigned char *text, unsigned char *hotkey,
+ unsigned *hotkeys, int n)
{
unsigned c;
if (hotkey == M_BAR)
@@ -115,14 +126,17 @@ static unsigned select_hotkey(struct terminal *term, unsigned char *text, unsign
return c;
}
-void do_menu_selected(struct terminal *term, struct menu_item *items, void *data, int selected, void (*free_function)(void *), void *free_data)
+void
+do_menu_selected(struct terminal *term, struct menu_item *items, void *data,
+ int selected, void (*free_function)(void *), void *free_data)
{
int i;
struct menu *menu;
for (i = 0; items[i].text; i++)
if (i == (INT_MAX - sizeof(struct menu)) / sizeof(unsigned))
overalloc();
- menu = xmalloc(sizeof(struct menu) + (!i ? 0 : i - 1) * sizeof(unsigned));
+ menu =
+ xmalloc(sizeof(struct menu) + (!i ? 0 : i - 1) * sizeof(unsigned));
menu->selected = selected;
menu->view = 0;
menu->ni = i;
@@ -131,17 +145,19 @@ void do_menu_selected(struct terminal *term, struct menu_item *items, void *data
menu->free_function = free_function;
menu->free_data = free_data;
for (i = 0; i < menu->ni; i++)
- menu->hotkeys[i] = select_hotkey(term, items[i].text,
- items[i].hotkey, menu->hotkeys, i);
+ menu->hotkeys[i] = select_hotkey(
+ term, items[i].text, items[i].hotkey, menu->hotkeys, i);
add_window(term, menu_func, menu);
}
-void do_menu(struct terminal *term, struct menu_item *items, void *data)
+void
+do_menu(struct terminal *term, struct menu_item *items, void *data)
{
do_menu_selected(term, items, data, 0, NULL, NULL);
}
-static void select_menu(struct terminal *term, struct menu *menu)
+static void
+select_menu(struct terminal *term, struct menu *menu)
{
struct menu_item *it;
void (*func)(struct terminal *, void *, void *);
@@ -159,8 +175,9 @@ static void select_menu(struct terminal *term, struct menu *menu)
if (!it->in_m) {
struct window *win = NULL;
struct list_head *lwin;
- foreach(struct window, win, lwin, term->windows) {
- if (win->handler != menu_func && win->handler != mainmenu_func)
+ foreach (struct window, win, lwin, term->windows) {
+ if (win->handler != menu_func
+ && win->handler != mainmenu_func)
break;
lwin = lwin->prev;
delete_window(win);
@@ -169,14 +186,16 @@ static void select_menu(struct terminal *term, struct menu *menu)
func(term, data1, data2);
}
-static unsigned char *get_rtext(unsigned char *rtext)
+static unsigned char *
+get_rtext(unsigned char *rtext)
{
if (!strcmp(cast_const_char rtext, ">"))
return MENU_SUBMENU;
return rtext;
}
-static void count_menu_size(struct terminal *term, struct menu *menu)
+static void
+count_menu_size(struct terminal *term, struct menu *menu)
{
int sx = term->x;
int sy = term->y;
@@ -184,29 +203,46 @@ static void count_menu_size(struct terminal *term, struct menu *menu)
int my;
for (my = 0; my < menu->ni; my++) {
int s;
- s = txtlen(term, get_text_translation(menu->items[my].text, term)) + txtlen(term, get_text_translation(get_rtext(menu->items[my].rtext), term)) + MENU_HOTKEY_SPACE * (get_text_translation(get_rtext(menu->items[my].rtext), term)[0] != 0);
+ s = txtlen(term,
+ get_text_translation(menu->items[my].text, term))
+ + txtlen(term, get_text_translation(
+ get_rtext(menu->items[my].rtext), term))
+ + MENU_HOTKEY_SPACE
+ * (get_text_translation(
+ get_rtext(menu->items[my].rtext), term)[0]
+ != 0);
s += 4;
- if (s > mx) mx = s;
+ if (s > mx)
+ mx = s;
}
my += 2;
- if (mx > sx) mx = sx;
- if (my > sy) my = sy;
+ if (mx > sx)
+ mx = sx;
+ if (my > sy)
+ my = sy;
menu->nview = my - 2;
menu->xw = mx;
menu->yw = my;
- if ((menu->x = menu->xp) < 0) menu->x = 0;
- if ((menu->y = menu->yp) < 0) menu->y = 0;
- if (menu->x + mx > sx) menu->x = sx - mx;
- if (menu->y + my > sy) menu->y = sy - my;
+ if ((menu->x = menu->xp) < 0)
+ menu->x = 0;
+ if ((menu->y = menu->yp) < 0)
+ menu->y = 0;
+ if (menu->x + mx > sx)
+ menu->x = sx - mx;
+ if (menu->y + my > sy)
+ menu->y = sy - my;
}
-static void scroll_menu(struct menu *menu, int d)
+static void
+scroll_menu(struct menu *menu, int d)
{
int c = 0;
int w = menu->nview;
- int scr_i = SCROLL_ITEMS > (w-1)/2 ? (w-1)/2 : SCROLL_ITEMS;
- if (scr_i < 0) scr_i = 0;
- if (w < 0) w = 0;
+ int scr_i = SCROLL_ITEMS > (w - 1) / 2 ? (w - 1) / 2 : SCROLL_ITEMS;
+ if (scr_i < 0)
+ scr_i = 0;
+ if (w < 0)
+ w = 0;
menu->selected += d;
while (1) {
if (c++ > menu->ni) {
@@ -214,29 +250,41 @@ static void scroll_menu(struct menu *menu, int d)
menu->view = 0;
return;
}
- if (menu->selected < 0) menu->selected = 0;
- if (menu->selected >= menu->ni) menu->selected = menu->ni - 1;
- if (menu->ni && menu->items[menu->selected].hotkey != M_BAR) break;
+ if (menu->selected < 0)
+ menu->selected = 0;
+ if (menu->selected >= menu->ni)
+ menu->selected = menu->ni - 1;
+ if (menu->ni && menu->items[menu->selected].hotkey != M_BAR)
+ break;
menu->selected += d;
}
- if (menu->selected < menu->view + scr_i) menu->view = menu->selected - scr_i;
- if (menu->selected >= menu->view + w - scr_i - 1) menu->view = menu->selected - w + scr_i + 1;
- if (menu->view > menu->ni - w) menu->view = menu->ni - w;
- if (menu->view < 0) menu->view = 0;
+ if (menu->selected < menu->view + scr_i)
+ menu->view = menu->selected - scr_i;
+ if (menu->selected >= menu->view + w - scr_i - 1)
+ menu->view = menu->selected - w + scr_i + 1;
+ if (menu->view > menu->ni - w)
+ menu->view = menu->ni - w;
+ if (menu->view < 0)
+ menu->view = 0;
}
-static void display_menu_txt(struct terminal *term, void *menu_)
+static void
+display_menu_txt(struct terminal *term, void *menu_)
{
struct menu *menu = (struct menu *)menu_;
int p, s;
- fill_area(term, menu->x+1, menu->y+1, menu->xw-2, menu->yw-2, ' ', COLOR_MENU_TEXT);
- draw_frame(term, menu->x, menu->y, menu->xw, menu->yw, COLOR_MENU_FRAME, 1);
+ fill_area(term, menu->x + 1, menu->y + 1, menu->xw - 2, menu->yw - 2,
+ ' ', COLOR_MENU_TEXT);
+ draw_frame(term, menu->x, menu->y, menu->xw, menu->yw, COLOR_MENU_FRAME,
+ 1);
set_window_ptr(menu->win, menu->x, menu->y);
- for (p = menu->view, s = menu->y + 1; p < menu->ni && p < menu->view + menu->yw - 2; p++, s++) {
+ for (p = menu->view, s = menu->y + 1;
+ p < menu->ni && p < menu->view + menu->yw - 2; p++, s++) {
int x;
int h = 0;
unsigned c;
- unsigned char *tmptext = get_text_translation(menu->items[p].text, term);
+ unsigned char *tmptext =
+ get_text_translation(menu->items[p].text, term);
unsigned char co;
if (p == menu->selected) {
h = 1;
@@ -245,37 +293,46 @@ static void display_menu_txt(struct terminal *term, void *menu_)
co = COLOR_MENU_TEXT;
if (h) {
set_cursor(term, menu->x + 1, s, term->x - 1,
- term->y - 1);
+ term->y - 1);
/*set_window_ptr(menu->win, menu->x+3, s+1);*/
- set_window_ptr(menu->win, menu->x+menu->xw, s);
- fill_area(term, menu->x+1, s, menu->xw-2, 1, ' ', co);
+ set_window_ptr(menu->win, menu->x + menu->xw, s);
+ fill_area(term, menu->x + 1, s, menu->xw - 2, 1, ' ',
+ co);
}
if (menu->items[p].hotkey != M_BAR || (tmptext[0])) {
- unsigned char *rt = get_text_translation(get_rtext(menu->items[p].rtext), term);
+ unsigned char *rt = get_text_translation(
+ get_rtext(menu->items[p].rtext), term);
int l = strlen((char *)rt);
for (x = 0;; x++) {
c = GET_TERM_CHAR(term, &rt);
- if (!c) break;
+ if (!c)
+ break;
if (menu->xw - 4 >= l - x)
set_char(term,
- menu->x + menu->xw - 2 - l + x,
- s, c, co);
+ menu->x + menu->xw - 2 - l + x,
+ s, c, co);
}
for (x = 0; x < menu->xw - 4; x++) {
c = GET_TERM_CHAR(term, &tmptext);
- if (!c) break;
- if (!h && charset_upcase(c, term_charset(term)) == menu->hotkeys[p]) {
+ if (!c)
+ break;
+ if (!h
+ && charset_upcase(c, term_charset(term))
+ == menu->hotkeys[p]) {
h = 1;
set_char(term, menu->x + x + 2, s, c,
- COLOR_MENU_HOTKEY);
+ COLOR_MENU_HOTKEY);
} else
- set_char(term,
- menu->x + x + 2, s, c, co);
+ set_char(term, menu->x + x + 2, s, c,
+ co);
}
} else {
- set_char(term, menu->x, s, 0xc3, COLOR_MENU_FRAME | ATTR_FRAME);
- fill_area(term, menu->x+1, s, menu->xw-2, 1, 0xc4, COLOR_MENU_FRAME | ATTR_FRAME);
- set_char(term, menu->x+menu->xw-1, s, 0xb4, COLOR_MENU_FRAME | ATTR_FRAME);
+ set_char(term, menu->x, s, 0xc3,
+ COLOR_MENU_FRAME | ATTR_FRAME);
+ fill_area(term, menu->x + 1, s, menu->xw - 2, 1, 0xc4,
+ COLOR_MENU_FRAME | ATTR_FRAME);
+ set_char(term, menu->x + menu->xw - 1, s, 0xb4,
+ COLOR_MENU_FRAME | ATTR_FRAME);
}
}
}
@@ -283,7 +340,8 @@ static void display_menu_txt(struct terminal *term, void *menu_)
static int menu_oldview = -1;
static int menu_oldsel = -1;
-static void menu_func(struct window *win, struct links_event *ev, int fwd)
+static void
+menu_func(struct window *win, struct links_event *ev, int fwd)
{
int s = 0;
int xp, yp;
@@ -302,54 +360,63 @@ static void menu_func(struct window *win, struct links_event *ev, int fwd)
menu->yp = yp;
count_menu_size(win->term, menu);
}
- xxx:
+xxx:
menu->selected--;
scroll_menu(menu, 1);
draw_to_window(win, display_menu_txt, menu);
break;
case EV_MOUSE:
- if ((ev->b & BM_ACT) == B_MOVE) break;
+ if ((ev->b & BM_ACT) == B_MOVE)
+ break;
if ((ev->b & BM_BUTT) == B_FOURTH
- || (ev->b & BM_BUTT) == B_FIFTH) {
- if ((ev->b & BM_ACT) == B_DOWN) goto go_lr;
+ || (ev->b & BM_BUTT) == B_FIFTH) {
+ if ((ev->b & BM_ACT) == B_DOWN)
+ goto go_lr;
break;
}
if ((ev->b & BM_BUTT) == B_SIXTH)
break;
- if (ev->x < menu->x || ev->x >= menu->x+menu->xw
- || ev->y < menu->y || ev->y >= menu->y+menu->yw) {
+ if (ev->x < menu->x || ev->x >= menu->x + menu->xw
+ || ev->y < menu->y || ev->y >= menu->y + menu->yw) {
int f = 1;
struct window *w1 = NULL;
struct list_head *w1l;
- foreachfrom(struct window, w1, w1l, win->term->windows, &win->list_entry) {
+ foreachfrom (struct window, w1, w1l, win->term->windows,
+ &win->list_entry) {
struct menu *m1;
if (w1->handler == mainmenu_func) {
if (ev->y < 1)
goto del;
break;
}
- if (w1->handler != menu_func) break;
+ if (w1->handler != menu_func)
+ break;
m1 = w1->data;
- if (ev->x > m1->x && ev->x < m1->x+m1->xw-1
- && ev->y > m1->y && ev->y < m1->y+m1->yw-1)
+ if (ev->x > m1->x && ev->x < m1->x + m1->xw - 1
+ && ev->y > m1->y
+ && ev->y < m1->y + m1->yw - 1)
goto del;
f--;
}
- if ((ev->b & BM_ACT) == B_DOWN) goto del;
+ if ((ev->b & BM_ACT) == B_DOWN)
+ goto del;
if (0)
- del: delete_window_ev(win, ev);
+del:
+ delete_window_ev(win, ev);
} else {
- if (!(ev->x < menu->x || ev->x >= menu->x+menu->xw
- || ev->y < menu->y + 1
- || ev->y >= menu->y + menu->yw - 1)) {
+ if (!(ev->x < menu->x || ev->x >= menu->x + menu->xw
+ || ev->y < menu->y + 1
+ || ev->y >= menu->y + menu->yw - 1)) {
int s = ev->y - menu->y - 1 + menu->view;
- if (s >= 0 && s < menu->ni && menu->items[s].hotkey != M_BAR) {
+ if (s >= 0 && s < menu->ni
+ && menu->items[s].hotkey != M_BAR) {
menu_oldview = menu->view;
menu_oldsel = menu->selected;
menu->selected = s;
scroll_menu(menu, 0);
- draw_to_window(win, display_menu_txt, menu);
+ draw_to_window(win, display_menu_txt,
+ menu);
menu_oldview = menu_oldsel = -1;
if ((ev->b & BM_ACT) == B_UP)
select_menu(win->term, menu);
@@ -358,60 +425,74 @@ static void menu_func(struct window *win, struct links_event *ev, int fwd)
}
break;
case EV_KBD:
- if (ev->y & KBD_PASTING) break;
+ if (ev->y & KBD_PASTING)
+ break;
if (ev->x == KBD_LEFT || ev->x == KBD_RIGHT) {
- go_lr:
+go_lr:
if (win->list_entry.next == &win->term->windows)
goto mm;
- if (list_struct(win->list_entry.next, struct window)->handler == mainmenu_func)
+ if (list_struct(win->list_entry.next, struct window)
+ ->handler
+ == mainmenu_func)
goto mm;
if (ev->ev == EV_MOUSE && (ev->b & BM_BUTT) == B_FIFTH)
goto mm;
- if (ev->ev == EV_KBD && ev->x == KBD_RIGHT) goto enter;
+ if (ev->ev == EV_KBD && ev->x == KBD_RIGHT)
+ goto enter;
delete_window(win);
break;
}
if (ev->x == KBD_ESC) {
if (win->list_entry.next == &win->term->windows)
ev = NULL;
- else if (list_struct(win->list_entry.next, struct window)->handler != mainmenu_func)
+ else if (list_struct(win->list_entry.next,
+ struct window)
+ ->handler
+ != mainmenu_func)
ev = NULL;
delete_window_ev(win, ev);
break;
}
if (KBD_ESCAPE_MENU(ev->x) || ev->y & KBD_ALT) {
- mm:
+mm:
delete_window_ev(win, ev);
break;
}
menu_oldview = menu->view;
menu_oldsel = menu->selected;
- if (ev->x == KBD_UP) scroll_menu(menu, -1);
- else if (ev->x == KBD_DOWN) scroll_menu(menu, 1);
- else if (ev->x == KBD_HOME || (upcase(ev->x) == 'A'
- && ev->y & KBD_CTRL)) {
+ if (ev->x == KBD_UP)
+ scroll_menu(menu, -1);
+ else if (ev->x == KBD_DOWN)
+ scroll_menu(menu, 1);
+ else if (ev->x == KBD_HOME
+ || (upcase(ev->x) == 'A' && ev->y & KBD_CTRL)) {
menu->selected = -1;
scroll_menu(menu, 1);
- } else if (ev->x == KBD_END || (upcase(ev->x) == 'E'
- && ev->y & KBD_CTRL)) {
+ } else if (ev->x == KBD_END
+ || (upcase(ev->x) == 'E' && ev->y & KBD_CTRL)) {
menu->selected = menu->ni;
scroll_menu(menu, -1);
- } else if (ev->x == KBD_PAGE_UP || (upcase(ev->x) == 'B'
- && ev->y & KBD_CTRL)) {
- if ((menu->selected -= menu->yw - 3) < -1) menu->selected = -1;
- if ((menu->view -= menu->yw - 2) < 0) menu->view = 0;
+ } else if (ev->x == KBD_PAGE_UP
+ || (upcase(ev->x) == 'B' && ev->y & KBD_CTRL)) {
+ if ((menu->selected -= menu->yw - 3) < -1)
+ menu->selected = -1;
+ if ((menu->view -= menu->yw - 2) < 0)
+ menu->view = 0;
scroll_menu(menu, -1);
- }
- else if (ev->x == KBD_PAGE_DOWN || (upcase(ev->x) == 'F'
- && ev->y & KBD_CTRL)) {
- if ((menu->selected += menu->yw - 3) > menu->ni) menu->selected = menu->ni;
- if ((menu->view += menu->yw - 2) >= menu->ni - menu->yw + 2) menu->view = menu->ni - menu->yw + 2;
+ } else if (ev->x == KBD_PAGE_DOWN
+ || (upcase(ev->x) == 'F' && ev->y & KBD_CTRL)) {
+ if ((menu->selected += menu->yw - 3) > menu->ni)
+ menu->selected = menu->ni;
+ if ((menu->view += menu->yw - 2)
+ >= menu->ni - menu->yw + 2)
+ menu->view = menu->ni - menu->yw + 2;
scroll_menu(menu, 1);
- }
- else if (ev->x > ' ') {
+ } else if (ev->x > ' ') {
int i;
for (i = 0; i < menu->ni; i++) {
- if (charset_upcase(ev->x, term_charset(win->term)) == menu->hotkeys[i]) {
+ if (charset_upcase(ev->x,
+ term_charset(win->term))
+ == menu->hotkeys[i]) {
menu->selected = i;
scroll_menu(menu, 0);
s = 1;
@@ -420,7 +501,7 @@ static void menu_func(struct window *win, struct links_event *ev, int fwd)
}
draw_to_window(win, display_menu_txt, menu);
if (s || ev->x == KBD_ENTER || ev->x == ' ') {
- enter:
+enter:
menu_oldview = menu_oldsel = -1;
select_menu(win->term, menu);
}
@@ -442,32 +523,39 @@ static void menu_func(struct window *win, struct links_event *ev, int fwd)
}
if (menu->free_function)
register_bottom_half(menu->free_function,
- menu->free_data);
+ menu->free_data);
break;
}
}
-void do_mainmenu(struct terminal *term, struct menu_item *items, void *data, int sel)
+void
+do_mainmenu(struct terminal *term, struct menu_item *items, void *data, int sel)
{
int i;
struct mainmenu *menu;
- for (i = 0; items[i].text; i++) if (i == (INT_MAX - sizeof(struct mainmenu)) / sizeof(unsigned)) overalloc();
- menu = xmalloc(sizeof(struct mainmenu) + (!i ? 0 : i - 1) * sizeof(unsigned));
+ for (i = 0; items[i].text; i++)
+ if (i == (INT_MAX - sizeof(struct mainmenu)) / sizeof(unsigned))
+ overalloc();
+ menu = xmalloc(sizeof(struct mainmenu)
+ + (!i ? 0 : i - 1) * sizeof(unsigned));
menu->selected = sel == -1 ? 0 : sel;
menu->ni = i;
menu->items = items;
menu->data = data;
for (i = 0; i < menu->ni; i++)
- menu->hotkeys[i] = select_hotkey(term, NULL, items[i].hotkey, menu->hotkeys, i);
+ menu->hotkeys[i] = select_hotkey(term, NULL, items[i].hotkey,
+ menu->hotkeys, i);
add_window(term, mainmenu_func, menu);
if (sel != -1) {
- struct links_event ev = {EV_KBD, KBD_ENTER, 0, 0};
- struct window *win = list_struct(term->windows.next, struct window);
+ struct links_event ev = { EV_KBD, KBD_ENTER, 0, 0 };
+ struct window *win =
+ list_struct(term->windows.next, struct window);
win->handler(win, (struct links_event *)&ev, 0);
}
}
-static void display_mainmenu(struct terminal *term, void *menu_)
+static void
+display_mainmenu(struct terminal *term, void *menu_)
{
struct mainmenu *menu = (struct mainmenu *)menu_;
int i;
@@ -476,7 +564,8 @@ static void display_mainmenu(struct terminal *term, void *menu_)
for (i = 0; i < menu->ni; i++) {
int s = 0;
unsigned c;
- unsigned char *tmptext = get_text_translation(menu->items[i].text, term);
+ unsigned char *tmptext =
+ get_text_translation(menu->items[i].text, term);
unsigned char co;
if (i == menu->selected) {
s = 1;
@@ -493,8 +582,11 @@ static void display_mainmenu(struct terminal *term, void *menu_)
p += 2;
for (;; p++) {
c = GET_TERM_CHAR(term, &tmptext);
- if (!c) break;
- if (!s && charset_upcase(c, term_charset(term)) == menu->hotkeys[i]) {
+ if (!c)
+ break;
+ if (!s
+ && charset_upcase(c, term_charset(term))
+ == menu->hotkeys[i]) {
s = 1;
set_char(term, p, 0, c, COLOR_MAINMENU_HOTKEY);
} else {
@@ -507,17 +599,21 @@ static void display_mainmenu(struct terminal *term, void *menu_)
}
}
-static void select_mainmenu(struct terminal *term, struct mainmenu *menu)
+static void
+select_mainmenu(struct terminal *term, struct mainmenu *menu)
{
struct menu_item *it;
- if (menu->selected < 0 || menu->selected >= menu->ni) return;
+ if (menu->selected < 0 || menu->selected >= menu->ni)
+ return;
it = &menu->items[menu->selected];
- if (it->hotkey == M_BAR) return;
+ if (it->hotkey == M_BAR)
+ return;
if (!it->in_m) {
struct window *win = NULL;
struct list_head *lwin;
- foreach(struct window, win, lwin, term->windows) {
- if (win->handler != menu_func && win->handler != mainmenu_func)
+ foreach (struct window, win, lwin, term->windows) {
+ if (win->handler != menu_func
+ && win->handler != mainmenu_func)
break;
lwin = lwin->prev;
delete_window(win);
@@ -526,7 +622,8 @@ static void select_mainmenu(struct terminal *term, struct mainmenu *menu)
it->func(term, it->data, menu->data);
}
-static void mainmenu_func(struct window *win, struct links_event *ev, int fwd)
+static void
+mainmenu_func(struct window *win, struct links_event *ev, int fwd)
{
int s = 0;
int in_menu;
@@ -540,14 +637,18 @@ static void mainmenu_func(struct window *win, struct links_event *ev, int fwd)
draw_to_window(win, display_mainmenu, menu);
break;
case EV_MOUSE:
- in_menu = ev->x >= 0 && ev->x < win->term->x && ev->y >= 0 && ev->y < 1;
- if ((ev->b & BM_ACT) == B_MOVE) break;
+ in_menu = ev->x >= 0 && ev->x < win->term->x && ev->y >= 0
+ && ev->y < 1;
+ if ((ev->b & BM_ACT) == B_MOVE)
+ break;
if ((ev->b & BM_BUTT) == B_FOURTH) {
- if ((ev->b & BM_ACT) == B_DOWN) goto go_left;
+ if ((ev->b & BM_ACT) == B_DOWN)
+ goto go_left;
break;
}
if ((ev->b & BM_BUTT) == B_FIFTH) {
- if ((ev->b & BM_ACT) == B_DOWN) goto go_right;
+ if ((ev->b & BM_ACT) == B_DOWN)
+ goto go_right;
break;
}
if ((ev->b & BM_BUTT) == B_SIXTH) {
@@ -560,69 +661,84 @@ static void mainmenu_func(struct window *win, struct links_event *ev, int fwd)
int p = 2;
for (i = 0; i < menu->ni; i++) {
int o = p;
- unsigned char *tmptext = get_text_translation(menu->items[i].text, win->term);
+ unsigned char *tmptext = get_text_translation(
+ menu->items[i].text, win->term);
p += txtlen(win->term, tmptext) + 4;
if (ev->x >= o && ev->x < p) {
menu->selected = i;
- draw_to_window(win, display_mainmenu, menu);
+ draw_to_window(win, display_mainmenu,
+ menu);
if ((ev->b & BM_ACT) == B_UP
- || menu->items[s].in_m)
- select_mainmenu(win->term, menu);
+ || menu->items[s].in_m)
+ select_mainmenu(win->term,
+ menu);
break;
}
}
}
break;
case EV_KBD:
- if (ev->y & KBD_PASTING) break;
+ if (ev->y & KBD_PASTING)
+ break;
if (ev->x == ' ' || ev->x == KBD_ENTER || ev->x == KBD_DOWN
- || ev->x == KBD_UP || ev->x == KBD_PAGE_DOWN
- || (upcase(ev->x) == 'F' && ev->y & KBD_CTRL)
- || ev->x == KBD_PAGE_UP
- || (upcase(ev->x) == 'B' && ev->y & KBD_CTRL)) {
+ || ev->x == KBD_UP || ev->x == KBD_PAGE_DOWN
+ || (upcase(ev->x) == 'F' && ev->y & KBD_CTRL)
+ || ev->x == KBD_PAGE_UP
+ || (upcase(ev->x) == 'B' && ev->y & KBD_CTRL)) {
select_mainmenu(win->term, menu);
break;
} else if (ev->x == KBD_LEFT) {
- go_left:
- if (!menu->selected--) menu->selected = menu->ni - 1;
+go_left:
+ if (!menu->selected--)
+ menu->selected = menu->ni - 1;
s = 1;
- if (fwd) s = 2;
+ if (fwd)
+ s = 2;
} else if (ev->x == KBD_RIGHT) {
- go_right:
- if (++menu->selected >= menu->ni) menu->selected = 0;
+go_right:
+ if (++menu->selected >= menu->ni)
+ menu->selected = 0;
s = 1;
- if (fwd) s = 2;
- } else if (ev->x == KBD_HOME || (upcase(ev->x) == 'A'
- && ev->y & KBD_CTRL)) {
+ if (fwd)
+ s = 2;
+ } else if (ev->x == KBD_HOME
+ || (upcase(ev->x) == 'A' && ev->y & KBD_CTRL)) {
menu->selected = 0;
s = 1;
- } else if (ev->x == KBD_END || (upcase(ev->x) == 'E'
- && ev->y & KBD_CTRL)) {
+ } else if (ev->x == KBD_END
+ || (upcase(ev->x) == 'E' && ev->y & KBD_CTRL)) {
menu->selected = menu->ni - 1;
s = 1;
} else if (ev->x > ' ') {
int i;
s = 1;
for (i = 0; i < menu->ni; i++) {
- if (charset_upcase(ev->x, term_charset(win->term)) == menu->hotkeys[i]) {
+ if (charset_upcase(ev->x,
+ term_charset(win->term))
+ == menu->hotkeys[i]) {
menu->selected = i;
s = 2;
}
}
}
if (!s) {
- delete_window_ev(win, KBD_ESCAPE_MENU(ev->x) || ev->y & KBD_ALT ? ev : NULL);
+ delete_window_ev(win, KBD_ESCAPE_MENU(ev->x)
+ || ev->y & KBD_ALT
+ ? ev
+ : NULL);
break;
}
draw_to_window(win, display_mainmenu, menu);
- if (s == 2) select_mainmenu(win->term, menu);
+ if (s == 2)
+ select_mainmenu(win->term, menu);
break;
case EV_ABORT:
break;
}
}
-struct menu_item *new_menu(int free_i)
+struct menu_item *
+new_menu(int free_i)
{
struct menu_item *mi;
mi = mem_calloc(sizeof(struct menu_item));
@@ -630,15 +746,22 @@ struct menu_item *new_menu(int free_i)
return mi;
}
-void add_to_menu(struct menu_item **mi, unsigned char *text, unsigned char *rtext, unsigned char *hotkey, void (*func)(struct terminal *, void *, void *), void *data, int in_m, int pos)
+void
+add_to_menu(struct menu_item **mi, unsigned char *text, unsigned char *rtext,
+ unsigned char *hotkey,
+ void (*func)(struct terminal *, void *, void *), void *data,
+ int in_m, int pos)
{
struct menu_item *mii;
int n;
if (pos != -1) {
n = pos;
- if ((*mi)[n].text) internal("invalid menu position %d", n);
+ if ((*mi)[n].text)
+ internal("invalid menu position %d", n);
} else
- for (n = 0; (*mi)[n].text; n++) if (n == INT_MAX) overalloc();
+ for (n = 0; (*mi)[n].text; n++)
+ if (n == INT_MAX)
+ overalloc();
if (((unsigned)n + 2) > INT_MAX / sizeof(struct menu_item))
overalloc();
mii = xrealloc(*mi, (n + 2) * sizeof(struct menu_item));
@@ -652,24 +775,30 @@ void add_to_menu(struct menu_item **mi, unsigned char *text, unsigned char *rtex
mii[n].in_m = in_m;
}
-void do_dialog(struct terminal *term, struct dialog *dlg, struct memory_list *ml)
+void
+do_dialog(struct terminal *term, struct dialog *dlg, struct memory_list *ml)
{
struct dialog_data *dd;
struct dialog_item *d;
int n = 0;
for (d = dlg->items; d->type != D_END; d++) {
- if (n == INT_MAX) overalloc();
+ if (n == INT_MAX)
+ overalloc();
n++;
}
- if ((unsigned)n > (INT_MAX - sizeof(struct dialog_data)) / sizeof(struct dialog_item_data)) overalloc();
- dd = mem_calloc(sizeof(struct dialog_data) + sizeof(struct dialog_item_data) * n);
+ if ((unsigned)n > (INT_MAX - sizeof(struct dialog_data))
+ / sizeof(struct dialog_item_data))
+ overalloc();
+ dd = mem_calloc(sizeof(struct dialog_data)
+ + sizeof(struct dialog_item_data) * n);
dd->dlg = dlg;
dd->n = n;
dd->ml = ml;
add_window(term, dialog_func, dd);
}
-void display_dlg_item(struct dialog_data *dlg, struct dialog_item_data *di, int sel)
+void
+display_dlg_item(struct dialog_data *dlg, struct dialog_item_data *di, int sel)
{
struct terminal *term = dlg->win->term;
unsigned char co;
@@ -680,9 +809,11 @@ void display_dlg_item(struct dialog_data *dlg, struct dialog_item_data *di, int
case D_CHECKBOX:
/* radio or checkbox */
if (di->checked)
- print_text(term, di->x, di->y, 3, cast_uchar "[X]", COLOR_DIALOG_CHECKBOX);
+ print_text(term, di->x, di->y, 3, cast_uchar "[X]",
+ COLOR_DIALOG_CHECKBOX);
else
- print_text(term, di->x, di->y, 3, cast_uchar "[ ]", COLOR_DIALOG_CHECKBOX);
+ print_text(term, di->x, di->y, 3, cast_uchar "[ ]",
+ COLOR_DIALOG_CHECKBOX);
if (sel) {
set_cursor(term, di->x + 1, di->y, di->x + 1, di->y);
set_window_ptr(dlg->win, di->x, di->y);
@@ -690,8 +821,10 @@ void display_dlg_item(struct dialog_data *dlg, struct dialog_item_data *di, int
break;
case D_FIELD:
case D_FIELD_PASS:
- fill_area(term, di->x, di->y, di->l, 1, ' ', COLOR_DIALOG_FIELD);
- if (di->vpos > di->cpos) di->vpos = di->cpos;
+ fill_area(term, di->x, di->y, di->l, 1, ' ',
+ COLOR_DIALOG_FIELD);
+ if (di->vpos > di->cpos)
+ di->vpos = di->cpos;
vposlen = strlen((char *)(di->cdata + di->vpos));
cposlen = strlen((char *)(di->cdata + di->cpos));
if (!di->l) {
@@ -712,12 +845,13 @@ void display_dlg_item(struct dialog_data *dlg, struct dialog_item_data *di, int
} else {
t = di->cdata + di->vpos;
}
- print_text(term, di->x, di->y, di->l, t, COLOR_DIALOG_FIELD_TEXT);
- if (di->item->type == D_FIELD_PASS)
+ print_text(term, di->x, di->y, di->l, t,
+ COLOR_DIALOG_FIELD_TEXT);
+ if (di->item->type == D_FIELD_PASS)
free(t);
if (sel) {
- set_cursor(term, di->x + vposlen - cposlen,
- di->y, di->x + vposlen - cposlen, di->y);
+ set_cursor(term, di->x + vposlen - cposlen, di->y,
+ di->x + vposlen - cposlen, di->y);
set_window_ptr(dlg->win, di->x, di->y);
}
break;
@@ -725,12 +859,12 @@ void display_dlg_item(struct dialog_data *dlg, struct dialog_item_data *di, int
co = sel ? COLOR_DIALOG_BUTTON_SELECTED : COLOR_DIALOG_BUTTON;
text = get_text_translation(di->item->text, term);
print_text(term, di->x, di->y, 2, cast_uchar "[ ", co);
- print_text(term, di->x + 2, di->y, strlen((char *)text), text, co);
- print_text(term, di->x + 2 + strlen((char *)text),
- di->y, 2, cast_uchar " ]", co);
+ print_text(term, di->x + 2, di->y, strlen((char *)text), text,
+ co);
+ print_text(term, di->x + 2 + strlen((char *)text), di->y, 2,
+ cast_uchar " ]", co);
if (sel) {
- set_cursor(term, di->x + 2, di->y, di->x + 2,
- di->y);
+ set_cursor(term, di->x + 2, di->y, di->x + 2, di->y);
set_window_ptr(dlg->win, di->x, di->y);
}
break;
@@ -745,13 +879,16 @@ struct dspd {
int sel;
};
-static void u_display_dlg_item(struct terminal *term, void *p)
+static void
+u_display_dlg_item(struct terminal *term, void *p)
{
struct dspd *d = p;
display_dlg_item(d->dlg, d->di, d->sel);
}
-static void x_display_dlg_item(struct dialog_data *dlg, struct dialog_item_data *di, int sel)
+static void
+x_display_dlg_item(struct dialog_data *dlg, struct dialog_item_data *di,
+ int sel)
{
struct dspd dspd;
dspd.dlg = dlg;
@@ -760,28 +897,34 @@ static void x_display_dlg_item(struct dialog_data *dlg, struct dialog_item_data
draw_to_window(dlg->win, u_display_dlg_item, &dspd);
}
-static void dlg_select_item(struct dialog_data *dlg, struct dialog_item_data *di)
+static void
+dlg_select_item(struct dialog_data *dlg, struct dialog_item_data *di)
{
if (di->item->type == D_CHECKBOX) {
if (!di->item->gid)
- di -> checked = *(int *)di->cdata = !*(int *)di->cdata;
+ di->checked = *(int *)di->cdata = !*(int *)di->cdata;
else {
int i;
for (i = 0; i < dlg->n; i++) {
- if (dlg->items[i].item->type == D_CHECKBOX && dlg->items[i].item->gid == di->item->gid) {
- *(int *)dlg->items[i].cdata = di->item->gnum;
+ if (dlg->items[i].item->type == D_CHECKBOX
+ && dlg->items[i].item->gid
+ == di->item->gid) {
+ *(int *)dlg->items[i].cdata =
+ di->item->gnum;
dlg->items[i].checked = 0;
- x_display_dlg_item(dlg, &dlg->items[i], 0);
+ x_display_dlg_item(dlg, &dlg->items[i],
+ 0);
}
}
di->checked = 1;
}
x_display_dlg_item(dlg, di, 1);
- }
- else if (di->item->type == D_BUTTON) di->item->fn(dlg, di);
+ } else if (di->item->type == D_BUTTON)
+ di->item->fn(dlg, di);
}
-static unsigned char *dlg_get_history_string(struct terminal *term, struct history_item *hi, int l)
+static unsigned char *
+dlg_get_history_string(struct terminal *term, struct history_item *hi, int l)
{
unsigned char *s;
int ch = term_charset(term);
@@ -804,52 +947,65 @@ static unsigned char *dlg_get_history_string(struct terminal *term, struct histo
return s;
}
-static void dlg_set_history(struct terminal *term, struct dialog_item_data *di)
+static void
+dlg_set_history(struct terminal *term, struct dialog_item_data *di)
{
unsigned char *s;
- if (di->cur_hist == &di->history) s = stracpy(cast_uchar "");
- else s = dlg_get_history_string(term, list_struct(di->cur_hist, struct history_item), di->item->dlen);
+ if (di->cur_hist == &di->history)
+ s = stracpy(cast_uchar "");
+ else
+ s = dlg_get_history_string(
+ term, list_struct(di->cur_hist, struct history_item),
+ di->item->dlen);
strcpy(cast_char di->cdata, cast_const_char s);
di->cpos = (int)strlen(cast_const_char s);
di->vpos = 0;
free(s);
}
-static int dlg_mouse(struct dialog_data *dlg, struct dialog_item_data *di, struct links_event *ev)
+static int
+dlg_mouse(struct dialog_data *dlg, struct dialog_item_data *di,
+ struct links_event *ev)
{
switch (di->item->type) {
case D_BUTTON:
- if (ev->y != di->y
- || ev->x < di->x
- || ev->x >= di->x + strlen((char *)get_text_translation(di->item->text, dlg->win->term)) + 4)
+ if (ev->y != di->y || ev->x < di->x
+ || ev->x >= di->x
+ + strlen((char *)get_text_translation(
+ di->item->text, dlg->win->term))
+ + 4)
return 0;
if (dlg->selected != di - dlg->items) {
x_display_dlg_item(dlg, &dlg->items[dlg->selected], 0);
dlg->selected = (int)(di - dlg->items);
x_display_dlg_item(dlg, di, 1);
}
- if ((ev->b & BM_ACT) == B_UP) dlg_select_item(dlg, di);
+ if ((ev->b & BM_ACT) == B_UP)
+ dlg_select_item(dlg, di);
return 1;
case D_FIELD:
case D_FIELD_PASS:
- if (ev->y != di->y
- || ev->x < di->x
- || ev->x >= di->x + di->l)
+ if (ev->y != di->y || ev->x < di->x || ev->x >= di->x + di->l)
return 0;
if (!is_utf_8(dlg->win->term)) {
- if ((size_t)(di->cpos = di->vpos + ev->x - di->x) > strlen(cast_const_char di->cdata))
- di->cpos = (int)strlen(cast_const_char di->cdata);
+ if ((size_t)(di->cpos = di->vpos + ev->x - di->x)
+ > strlen(cast_const_char di->cdata))
+ di->cpos =
+ (int)strlen(cast_const_char di->cdata);
} else {
int p, u;
unsigned char *t = di->cdata;
p = di->x - di->vpos;
while (1) {
di->cpos = (int)(t - di->cdata);
- if (!*t) break;
+ if (!*t)
+ break;
GET_UTF_8(t, u);
- if (!u) continue;
+ if (!u)
+ continue;
p++;
- if (p > ev->x) break;
+ if (p > ev->x)
+ break;
}
}
if (dlg->selected != di - dlg->items) {
@@ -860,22 +1016,22 @@ static int dlg_mouse(struct dialog_data *dlg, struct dialog_item_data *di, struc
x_display_dlg_item(dlg, di, 1);
return 1;
case D_CHECKBOX:
- if (ev->y != di->y
- || ev->x < di->x
- || ev->x >= di->x + 3)
+ if (ev->y != di->y || ev->x < di->x || ev->x >= di->x + 3)
return 0;
if (dlg->selected != di - dlg->items) {
x_display_dlg_item(dlg, &dlg->items[dlg->selected], 0);
dlg->selected = (int)(di - dlg->items);
x_display_dlg_item(dlg, di, 1);
}
- if ((ev->b & BM_ACT) == B_UP) dlg_select_item(dlg, di);
+ if ((ev->b & BM_ACT) == B_UP)
+ dlg_select_item(dlg, di);
return 1;
}
return 0;
}
-static void redraw_dialog_items(struct terminal *term, void *dlg_)
+static void
+redraw_dialog_items(struct terminal *term, void *dlg_)
{
struct dialog_data *dlg = (struct dialog_data *)dlg_;
int i;
@@ -883,19 +1039,23 @@ static void redraw_dialog_items(struct terminal *term, void *dlg_)
display_dlg_item(dlg, &dlg->items[i], i == dlg->selected);
}
-static void redraw_dialog(struct terminal *term, void *dlg_)
+static void
+redraw_dialog(struct terminal *term, void *dlg_)
{
struct dialog_data *dlg = (struct dialog_data *)dlg_;
dlg->dlg->fn(dlg);
redraw_dialog_items(term, dlg);
}
-static void tab_compl(struct terminal *term, void *hi_, void *win_)
+static void
+tab_compl(struct terminal *term, void *hi_, void *win_)
{
struct history_item *hi = (struct history_item *)hi_;
struct window *win = (struct window *)win_;
- struct links_event ev = {EV_REDRAW, 0, 0, 0};
- struct dialog_item_data *di = &((struct dialog_data*)win->data)->items[((struct dialog_data*)win->data)->selected];
+ struct links_event ev = { EV_REDRAW, 0, 0, 0 };
+ struct dialog_item_data *di =
+ &((struct dialog_data *)win->data)
+ ->items[((struct dialog_data *)win->data)->selected];
unsigned char *s = dlg_get_history_string(term, hi, di->item->dlen);
strcpy(cast_char di->cdata, cast_const_char s);
di->cpos = (int)strlen(cast_const_char s);
@@ -906,22 +1066,29 @@ static void tab_compl(struct terminal *term, void *hi_, void *win_)
dialog_func(win, &ev, 0);
}
-static void do_tab_compl(struct terminal *term, struct list_head *history, struct window *win)
+static void
+do_tab_compl(struct terminal *term, struct list_head *history,
+ struct window *win)
{
- unsigned char *cdata = ((struct dialog_data*)win->data)->items[((struct dialog_data*)win->data)->selected].cdata;
+ unsigned char *cdata =
+ ((struct dialog_data *)win->data)
+ ->items[((struct dialog_data *)win->data)->selected]
+ .cdata;
int l = (int)strlen(cast_const_char cdata), n = 0;
struct history_item *hi = NULL;
struct list_head *lhi;
struct menu_item *items = NULL;
- foreach(struct history_item, hi, lhi, *history) {
+ foreach (struct history_item, hi, lhi, *history) {
unsigned char *s = dlg_get_history_string(term, hi, INT_MAX);
if (!strncmp(cast_const_char cdata, cast_const_char s, l)) {
if (!(n & (ALLOC_GR - 1))) {
- if ((unsigned)n > INT_MAX / sizeof(struct menu_item) - ALLOC_GR - 1)
+ if ((unsigned)n
+ > INT_MAX / sizeof(struct menu_item)
+ - ALLOC_GR - 1)
overalloc();
- items = xrealloc(items,
- (n + ALLOC_GR + 1)
- * sizeof(struct menu_item));
+ items = xrealloc(
+ items, (n + ALLOC_GR + 1)
+ * sizeof(struct menu_item));
}
items[n].text = s;
items[n].rtext = cast_uchar "";
@@ -931,7 +1098,8 @@ static void do_tab_compl(struct terminal *term, struct list_head *history, struc
items[n].data = hi;
items[n].in_m = 0;
items[n].free_i = MENU_FREE_ITEMS | MENU_FREE_TEXT;
- if (n == INT_MAX) overalloc();
+ if (n == INT_MAX)
+ overalloc();
n++;
} else
free(s);
@@ -948,7 +1116,8 @@ static void do_tab_compl(struct terminal *term, struct list_head *history, struc
}
}
-void dialog_func(struct window *win, struct links_event *ev, int fwd)
+void
+dialog_func(struct window *win, struct links_event *ev, int fwd)
{
int i;
struct terminal *term = win->term;
@@ -958,7 +1127,8 @@ void dialog_func(struct window *win, struct links_event *ev, int fwd)
dlg->win = win;
/* Use nonstandard event handlers */
- if (dlg->dlg->handle_event && dlg->dlg->handle_event(dlg, ev) == EVENT_PROCESSED) {
+ if (dlg->dlg->handle_event
+ && dlg->dlg->handle_event(dlg, ev) == EVENT_PROCESSED) {
return;
}
@@ -970,28 +1140,42 @@ void dialog_func(struct window *win, struct links_event *ev, int fwd)
di->item = &dlg->dlg->items[i];
di->cdata = xmalloc(di->item->dlen);
if (di->item->dlen)
- memcpy(di->cdata, di->item->data, di->item->dlen);
+ memcpy(di->cdata, di->item->data,
+ di->item->dlen);
if (di->item->type == D_CHECKBOX) {
if (di->item->gid) {
- if (*(int *)di->cdata == di->item->gnum) di->checked = 1;
- } else if (*(int *)di->cdata) di->checked = 1;
+ if (*(int *)di->cdata == di->item->gnum)
+ di->checked = 1;
+ } else if (*(int *)di->cdata)
+ di->checked = 1;
}
init_list(di->history);
di->cur_hist = &di->history;
- if (di->item->type == D_FIELD || di->item->type == D_FIELD_PASS) {
+ if (di->item->type == D_FIELD
+ || di->item->type == D_FIELD_PASS) {
if (di->item->history) {
struct history_item *j = NULL;
struct list_head *lj;
- foreach(struct history_item, j, lj, di->item->history->items) {
+ foreach (struct history_item, j, lj,
+ di->item->history->items) {
struct history_item *hi;
- size_t sl = strlen(cast_const_char j->str);
- if (sl > INT_MAX - sizeof(struct history_item)) overalloc();
- hi = xmalloc(sizeof(struct history_item) + sl);
- strcpy(cast_char hi->str, cast_const_char j->str);
+ size_t sl = strlen(
+ cast_const_char j->str);
+ if (sl > INT_MAX
+ - sizeof(
+ struct
+ history_item))
+ overalloc();
+ hi = xmalloc(
+ sizeof(struct history_item)
+ + sl);
+ strcpy(cast_char hi->str,
+ cast_const_char j->str);
add_to_list(di->history, hi);
}
}
- di->cpos = (int)strlen(cast_const_char di->cdata);
+ di->cpos =
+ (int)strlen(cast_const_char di->cdata);
}
}
dlg->selected = 0;
@@ -1004,36 +1188,49 @@ void dialog_func(struct window *win, struct links_event *ev, int fwd)
draw_to_window(dlg->win, redraw_dialog, dlg);
break;
case EV_MOUSE:
- if ((ev->b & BM_ACT) == B_MOVE) break;
+ if ((ev->b & BM_ACT) == B_MOVE)
+ break;
if ((ev->b & BM_BUTT) == B_FOURTH) {
- if ((ev->b & BM_ACT) == B_DOWN) goto go_prev;
+ if ((ev->b & BM_ACT) == B_DOWN)
+ goto go_prev;
break;
}
if ((ev->b & BM_BUTT) == B_FIFTH) {
- if ((ev->b & BM_ACT) == B_DOWN) goto go_next;
+ if ((ev->b & BM_ACT) == B_DOWN)
+ goto go_next;
break;
}
if ((ev->b & BM_BUTT) == B_SIXTH) {
- if ((ev->b & BM_ACT) == B_DOWN) goto go_enter;
+ if ((ev->b & BM_ACT) == B_DOWN)
+ goto go_enter;
break;
}
- for (i = 0; i < dlg->n; i++) if (dlg_mouse(dlg, &dlg->items[i], ev)) break;
- if ((ev->b & BM_ACT) == B_DOWN && (ev->b & BM_BUTT) == B_MIDDLE) {
- /* don't delete this!!! it's here because of jump from mouse event */
+ for (i = 0; i < dlg->n; i++)
+ if (dlg_mouse(dlg, &dlg->items[i], ev))
+ break;
+ if ((ev->b & BM_ACT) == B_DOWN
+ && (ev->b & BM_BUTT) == B_MIDDLE) {
+ /* don't delete this!!! it's here because of jump from
+ * mouse event */
di = &dlg->items[dlg->selected];
- if (di->item->type == D_FIELD || di->item->type == D_FIELD_PASS) goto clipbd_paste;
+ if (di->item->type == D_FIELD
+ || di->item->type == D_FIELD_PASS)
+ goto clipbd_paste;
}
break;
case EV_KBD:
di = &dlg->items[dlg->selected];
if (ev->y & KBD_PASTING) {
if (!((di->item->type == D_FIELD
- || di->item->type == D_FIELD_PASS)
- && (ev->x >= ' ' && !(ev->y & (KBD_CTRL | KBD_ALT)))))
+ || di->item->type == D_FIELD_PASS)
+ && (ev->x >= ' '
+ && !(ev->y & (KBD_CTRL | KBD_ALT)))))
break;
}
- if (di->item->type == D_FIELD || di->item->type == D_FIELD_PASS) {
- if (ev->x == KBD_UP && di->cur_hist->prev != &di->history) {
+ if (di->item->type == D_FIELD
+ || di->item->type == D_FIELD_PASS) {
+ if (ev->x == KBD_UP
+ && di->cur_hist->prev != &di->history) {
di->cur_hist = di->cur_hist->prev;
dlg_set_history(term, di);
goto dsp_f;
@@ -1044,12 +1241,14 @@ void dialog_func(struct window *win, struct links_event *ev, int fwd)
goto dsp_f;
}
if (ev->x == KBD_RIGHT) {
- if ((size_t)di->cpos < strlen(cast_const_char di->cdata)) {
+ if ((size_t)di->cpos
+ < strlen(cast_const_char di->cdata)) {
if (!is_utf_8(term))
di->cpos++;
else {
int u;
- unsigned char *p = di->cdata + di->cpos;
+ unsigned char *p =
+ di->cdata + di->cpos;
GET_UTF_8(p, u);
di->cpos = (int)(p - di->cdata);
}
@@ -1061,19 +1260,23 @@ void dialog_func(struct window *win, struct links_event *ev, int fwd)
if (!is_utf_8(term))
di->cpos--;
else {
- unsigned char *p = di->cdata + di->cpos;
+ unsigned char *p =
+ di->cdata + di->cpos;
BACK_UTF_8(p, di->cdata);
di->cpos = (int)(p - di->cdata);
}
}
goto dsp_f;
}
- if (ev->x == KBD_HOME || (upcase(ev->x) == 'A' && ev->y & KBD_CTRL)) {
+ if (ev->x == KBD_HOME
+ || (upcase(ev->x) == 'A' && ev->y & KBD_CTRL)) {
di->cpos = 0;
goto dsp_f;
}
- if (ev->x == KBD_END || (upcase(ev->x) == 'E' && ev->y & KBD_CTRL)) {
- di->cpos = (int)strlen(cast_const_char di->cdata);
+ if (ev->x == KBD_END
+ || (upcase(ev->x) == 'E' && ev->y & KBD_CTRL)) {
+ di->cpos =
+ (int)strlen(cast_const_char di->cdata);
goto dsp_f;
}
if (ev->x >= ' ' && !(ev->y & (KBD_CTRL | KBD_ALT))) {
@@ -1085,10 +1288,19 @@ void dialog_func(struct window *win, struct links_event *ev, int fwd)
} else {
u = encode_utf_8(ev->x);
}
- if (strlen(cast_const_char di->cdata) + strlen(cast_const_char u) < (size_t)di->item->dlen) {
- memmove(di->cdata + di->cpos + strlen(cast_const_char u), di->cdata + di->cpos, strlen(cast_const_char di->cdata) - di->cpos + 1);
- memcpy(&di->cdata[di->cpos], u, strlen(cast_const_char u));
- di->cpos += (int)strlen(cast_const_char u);
+ if (strlen(cast_const_char di->cdata)
+ + strlen(cast_const_char u)
+ < (size_t)di->item->dlen) {
+ memmove(
+ di->cdata + di->cpos
+ + strlen(cast_const_char u),
+ di->cdata + di->cpos,
+ strlen(cast_const_char di->cdata)
+ - di->cpos + 1);
+ memcpy(&di->cdata[di->cpos], u,
+ strlen(cast_const_char u));
+ di->cpos +=
+ (int)strlen(cast_const_char u);
}
goto dsp_f;
}
@@ -1099,28 +1311,41 @@ void dialog_func(struct window *win, struct links_event *ev, int fwd)
unsigned u;
unsigned char *p, *pp;
p = di->cdata;
- a:
+a:
pp = p;
GET_UTF_8(p, u);
if (p < di->cdata + di->cpos)
goto a;
s = (int)(p - pp);
}
- memmove(di->cdata + di->cpos - s, di->cdata + di->cpos, strlen(cast_const_char di->cdata) - di->cpos + s);
+ memmove(
+ di->cdata + di->cpos - s,
+ di->cdata + di->cpos,
+ strlen(cast_const_char di->cdata)
+ - di->cpos + s);
di->cpos -= s;
}
goto dsp_f;
}
- if (ev->x == KBD_DEL || (upcase(ev->x) == 'D' && ev->y & KBD_CTRL)) {
- if ((size_t)di->cpos < strlen(cast_const_char di->cdata)) {
+ if (ev->x == KBD_DEL
+ || (upcase(ev->x) == 'D' && ev->y & KBD_CTRL)) {
+ if ((size_t)di->cpos
+ < strlen(cast_const_char di->cdata)) {
int s = 1;
if (is_utf_8(term)) {
unsigned u;
- unsigned char *p = di->cdata + di->cpos;
+ unsigned char *p =
+ di->cdata + di->cpos;
GET_UTF_8(p, u);
- s = (int)(p - (di->cdata + di->cpos));
+ s = (int)(p
+ - (di->cdata
+ + di->cpos));
}
- memmove(di->cdata + di->cpos, di->cdata + di->cpos + s, strlen(cast_const_char di->cdata) - di->cpos + s);
+ memmove(
+ di->cdata + di->cpos,
+ di->cdata + di->cpos + s,
+ strlen(cast_const_char di->cdata)
+ - di->cpos + s);
}
goto dsp_f;
}
@@ -1130,7 +1355,10 @@ void dialog_func(struct window *win, struct links_event *ev, int fwd)
set_clipboard_text(term, a);
free(a);
}
- memmove(di->cdata, di->cdata + di->cpos, strlen(cast_const_char di->cdata + di->cpos) + 1);
+ memmove(
+ di->cdata, di->cdata + di->cpos,
+ strlen(cast_const_char di->cdata + di->cpos)
+ + 1);
di->cpos = 0;
goto dsp_f;
}
@@ -1141,16 +1369,17 @@ void dialog_func(struct window *win, struct links_event *ev, int fwd)
}
/* Copy to clipboard */
if ((ev->x == KBD_INS && ev->y & KBD_CTRL)
- || (upcase(ev->x) == 'B' && ev->y & KBD_CTRL)
- || ev->x == KBD_COPY) {
+ || (upcase(ev->x) == 'B' && ev->y & KBD_CTRL)
+ || ev->x == KBD_COPY) {
set_clipboard_text(term, di->cdata);
- break; /* We don't need to redraw */
+ break; /* We don't need to redraw */
}
- /* FIXME -- why keyboard shortcuts with shift don't works??? */
- /* Cut to clipboard */
+ /* FIXME -- why keyboard shortcuts with shift don't
+ * works??? */
+ /* Cut to clipboard */
if ((ev->x == KBD_DEL && ev->y & KBD_SHIFT)
- || (upcase(ev->x) == 'X' && ev->y & KBD_CTRL)
- || ev->x == KBD_CUT) {
+ || (upcase(ev->x) == 'X' && ev->y & KBD_CTRL)
+ || ev->x == KBD_CUT) {
set_clipboard_text(term, di->cdata);
di->cdata[0] = 0;
di->cpos = 0;
@@ -1158,58 +1387,92 @@ void dialog_func(struct window *win, struct links_event *ev, int fwd)
}
/* Paste from clipboard */
if ((ev->x == KBD_INS && ev->y & KBD_SHIFT)
- || (upcase(ev->x) == 'V' && ev->y & KBD_CTRL)
- || ev->x == KBD_PASTE) {
+ || (upcase(ev->x) == 'V' && ev->y & KBD_CTRL)
+ || ev->x == KBD_PASTE) {
unsigned char *clipboard;
- clipbd_paste:
+clipbd_paste:
clipboard = get_clipboard_text(term);
if (clipboard) {
unsigned char *nl = clipboard;
- while ((nl = cast_uchar strchr(cast_const_char nl, '\n'))) *nl = ' ';
- if (strlen(cast_const_char di->cdata) + strlen(cast_const_char clipboard) < (size_t)di->item->dlen
- || strlen(cast_const_char di->cdata) + strlen(cast_const_char clipboard) < strlen(cast_const_char di->cdata)) {
-
- memmove(di->cdata + di->cpos + strlen(cast_const_char clipboard), di->cdata + di->cpos, strlen(cast_const_char di->cdata) - di->cpos + 1);
- memcpy(&di->cdata[di->cpos], clipboard, strlen(cast_const_char clipboard));
- di->cpos += (int)strlen(cast_const_char clipboard);
+ while ((nl = cast_uchar strchr(
+ cast_const_char nl, '\n')))
+ *nl = ' ';
+ if (strlen(cast_const_char di->cdata)
+ + strlen(cast_const_char
+ clipboard)
+ < (size_t)di->item->dlen
+ || strlen(cast_const_char di->cdata)
+ + strlen(cast_const_char
+ clipboard)
+ < strlen(cast_const_char di
+ ->cdata)) {
+
+ memmove(
+ di->cdata + di->cpos
+ + strlen(cast_const_char
+ clipboard),
+ di->cdata + di->cpos,
+ strlen(cast_const_char di
+ ->cdata)
+ - di->cpos + 1);
+ memcpy(&di->cdata[di->cpos],
+ clipboard,
+ strlen(cast_const_char
+ clipboard));
+ di->cpos += (int)strlen(
+ cast_const_char clipboard);
}
free(clipboard);
}
goto dsp_f;
}
- if ((upcase(ev->x) == 'W' && ev->y & KBD_CTRL) || ev->x == KBD_FIND) {
+ if ((upcase(ev->x) == 'W' && ev->y & KBD_CTRL)
+ || ev->x == KBD_FIND) {
do_tab_compl(term, &di->history, win);
goto dsp_f;
}
goto gh;
- dsp_f:
+dsp_f:
x_display_dlg_item(dlg, di, 1);
break;
}
- if ((ev->x == KBD_ENTER && di->item->type == D_BUTTON) || ev->x == ' ') {
+ if ((ev->x == KBD_ENTER && di->item->type == D_BUTTON)
+ || ev->x == ' ') {
dlg_select_item(dlg, di);
break;
}
- gh:
- if (ev->x > ' ') for (i = 0; i < dlg->n; i++) {
- unsigned char *tx = get_text_translation(dlg->dlg->items[i].text, term);
- if (dlg->dlg->items[i].type == D_BUTTON && charset_upcase(GET_TERM_CHAR(term, &tx), term_charset(term)) == charset_upcase(ev->x, term_charset(term))) goto sel;
- }
+gh:
+ if (ev->x > ' ')
+ for (i = 0; i < dlg->n; i++) {
+ unsigned char *tx = get_text_translation(
+ dlg->dlg->items[i].text, term);
+ if (dlg->dlg->items[i].type == D_BUTTON
+ && charset_upcase(GET_TERM_CHAR(term, &tx),
+ term_charset(term))
+ == charset_upcase(
+ ev->x, term_charset(term)))
+ goto sel;
+ }
if (ev->x == KBD_ENTER) {
- go_enter:
+go_enter:
for (i = 0; i < dlg->n; i++)
- if (dlg->dlg->items[i].type == D_BUTTON && dlg->dlg->items[i].gid & B_ENTER) goto sel;
+ if (dlg->dlg->items[i].type == D_BUTTON
+ && dlg->dlg->items[i].gid & B_ENTER)
+ goto sel;
break;
}
if (ev->x == KBD_ESC) {
for (i = 0; i < dlg->n; i++)
- if (dlg->dlg->items[i].type == D_BUTTON && dlg->dlg->items[i].gid & B_ESC) goto sel;
+ if (dlg->dlg->items[i].type == D_BUTTON
+ && dlg->dlg->items[i].gid & B_ESC)
+ goto sel;
break;
}
if (0) {
- sel:
+sel:
if (dlg->selected != i) {
- x_display_dlg_item(dlg, &dlg->items[dlg->selected], 0);
+ x_display_dlg_item(
+ dlg, &dlg->items[dlg->selected], 0);
x_display_dlg_item(dlg, &dlg->items[i], 1);
dlg->selected = i;
}
@@ -1217,26 +1480,31 @@ void dialog_func(struct window *win, struct links_event *ev, int fwd)
break;
}
if (((ev->x == KBD_TAB && !ev->y) || ev->x == KBD_DOWN
- || ev->x == KBD_RIGHT) && dlg->n > 1) {
- go_next:
+ || ev->x == KBD_RIGHT)
+ && dlg->n > 1) {
+go_next:
x_display_dlg_item(dlg, &dlg->items[dlg->selected], 0);
- if ((++dlg->selected) >= dlg->n) dlg->selected = 0;
+ if ((++dlg->selected) >= dlg->n)
+ dlg->selected = 0;
x_display_dlg_item(dlg, &dlg->items[dlg->selected], 1);
break;
}
if (((ev->x == KBD_TAB && ev->y) || ev->x == KBD_UP
- || ev->x == KBD_LEFT) && dlg->n > 1) {
- go_prev:
+ || ev->x == KBD_LEFT)
+ && dlg->n > 1) {
+go_prev:
x_display_dlg_item(dlg, &dlg->items[dlg->selected], 0);
- if ((--dlg->selected) < 0) dlg->selected = dlg->n - 1;
+ if ((--dlg->selected) < 0)
+ dlg->selected = dlg->n - 1;
x_display_dlg_item(dlg, &dlg->items[dlg->selected], 1);
break;
}
break;
case EV_ABORT:
- /* Moved this line up so that the dlg would have access to its
- member vars before they get freed. */
- if (dlg->dlg->abort) dlg->dlg->abort(dlg);
+ /* Moved this line up so that the dlg would have access to its
+ member vars before they get freed. */
+ if (dlg->dlg->abort)
+ dlg->dlg->abort(dlg);
for (i = 0; i < dlg->n; i++) {
struct dialog_item_data *di = &dlg->items[i];
free(di->cdata);
@@ -1246,78 +1514,87 @@ void dialog_func(struct window *win, struct links_event *ev, int fwd)
}
}
-/* gid and gnum are 100 times greater than boundaries (e.g. if gid==1 boundary is 0.01) */
-int check_float(struct dialog_data *dlg, struct dialog_item_data *di)
+/* gid and gnum are 100 times greater than boundaries (e.g. if gid==1 boundary
+ * is 0.01) */
+int
+check_float(struct dialog_data *dlg, struct dialog_item_data *di)
{
char *end;
double d = strtod(cast_const_char di->cdata, &end);
if (!*di->cdata || *end
- || di->cdata[strspn(cast_const_char di->cdata, "0123456789.")]
- || *di->cdata == (unsigned char)'.') {
+ || di->cdata[strspn(cast_const_char di->cdata, "0123456789.")]
+ || *di->cdata == (unsigned char)'.') {
msg_box(dlg->win->term, NULL, TEXT_(T_BAD_NUMBER), AL_CENTER,
- TEXT_(T_NUMBER_EXPECTED), MSG_BOX_END, NULL, 1,
- TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ TEXT_(T_NUMBER_EXPECTED), MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
return 1;
}
- if (d < 0 || d > di->item->gnum || 100*d < di->item->gid
- || 100*d > di->item->gnum) {
+ if (d < 0 || d > di->item->gnum || 100 * d < di->item->gid
+ || 100 * d > di->item->gnum) {
msg_box(dlg->win->term, NULL, TEXT_(T_BAD_NUMBER), AL_CENTER,
- TEXT_(T_NUMBER_OUT_OF_RANGE), MSG_BOX_END, NULL, 1,
- TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ TEXT_(T_NUMBER_OUT_OF_RANGE), MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
return 1;
}
return 0;
}
-int check_number(struct dialog_data *dlg, struct dialog_item_data *di)
+int
+check_number(struct dialog_data *dlg, struct dialog_item_data *di)
{
char *end;
long l = strtol(cast_const_char di->cdata, &end, 10);
if (!*di->cdata || *end) {
msg_box(dlg->win->term, NULL, TEXT_(T_BAD_NUMBER), AL_CENTER,
- TEXT_(T_NUMBER_EXPECTED), MSG_BOX_END, NULL, 1,
- TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ TEXT_(T_NUMBER_EXPECTED), MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
return 1;
}
if (l < di->item->gid || l > di->item->gnum) {
msg_box(dlg->win->term, NULL, TEXT_(T_BAD_NUMBER), AL_CENTER,
- TEXT_(T_NUMBER_OUT_OF_RANGE), MSG_BOX_END, NULL, 1,
- TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ TEXT_(T_NUMBER_OUT_OF_RANGE), MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
return 1;
}
return 0;
}
-int check_hex_number(struct dialog_data *dlg, struct dialog_item_data *di)
+int
+check_hex_number(struct dialog_data *dlg, struct dialog_item_data *di)
{
char *end;
long l = strtol(cast_const_char di->cdata, &end, 16);
if (!*di->cdata || *end) {
msg_box(dlg->win->term, NULL, TEXT_(T_BAD_NUMBER), AL_CENTER,
- TEXT_(T_NUMBER_EXPECTED), MSG_BOX_END, NULL, 1,
- TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ TEXT_(T_NUMBER_EXPECTED), MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
return 1;
}
if (l < di->item->gid || l > di->item->gnum) {
msg_box(dlg->win->term, NULL, TEXT_(T_BAD_NUMBER), AL_CENTER,
- TEXT_(T_NUMBER_OUT_OF_RANGE), MSG_BOX_END, NULL, 1,
- TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ TEXT_(T_NUMBER_OUT_OF_RANGE), MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
return 1;
}
return 0;
}
-int check_nonempty(struct dialog_data *dlg, struct dialog_item_data *di)
+int
+check_nonempty(struct dialog_data *dlg, struct dialog_item_data *di)
{
unsigned char *p;
- for (p = di->cdata; *p; p++) if (*p > ' ') return 0;
+ for (p = di->cdata; *p; p++)
+ if (*p > ' ')
+ return 0;
msg_box(dlg->win->term, NULL, TEXT_(T_BAD_STRING), AL_CENTER,
- TEXT_(T_EMPTY_STRING_NOT_ALLOWED), MSG_BOX_END, NULL, 1,
- TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ TEXT_(T_EMPTY_STRING_NOT_ALLOWED), MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
return 1;
}
-static int check_local_ip_address_internal(struct dialog_data *dlg, struct dialog_item_data *di, int pf)
+static int
+check_local_ip_address_internal(struct dialog_data *dlg,
+ struct dialog_item_data *di, int pf)
{
int s;
int rs;
@@ -1331,9 +1608,9 @@ static int check_local_ip_address_internal(struct dialog_data *dlg, struct dialo
rs = numeric_ip_address((char *)p, NULL);
if (rs) {
msg_box(dlg->win->term, NULL, TEXT_(T_BAD_IP_ADDRESS),
- AL_CENTER, TEXT_(T_INVALID_IP_ADDRESS_SYNTAX),
- MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null,
- B_ENTER | B_ESC);
+ AL_CENTER, TEXT_(T_INVALID_IP_ADDRESS_SYNTAX),
+ MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null,
+ B_ENTER | B_ESC);
return 1;
}
s = socket_and_bind(pf, p);
@@ -1342,63 +1619,71 @@ static int check_local_ip_address_internal(struct dialog_data *dlg, struct dialo
else {
if (1
#ifdef ENFILE
- && errno != ENFILE
+ && errno != ENFILE
#endif
#ifdef EMFILE
- && errno != EMFILE
+ && errno != EMFILE
#endif
#ifdef ENOBUFS
- && errno != ENOBUFS
+ && errno != ENOBUFS
#endif
#ifdef ENOMEM
- && errno != ENOMEM
+ && errno != ENOMEM
#endif
- ) {
- unsigned char *er = stracpy(cast_uchar strerror(errno));
- unsigned char *ad = stracpy(p);
- msg_box(dlg->win->term, getml(er, ad, NULL),
- TEXT_(T_BAD_IP_ADDRESS), AL_CENTER,
- TEXT_(T_UNABLE_TO_USE_LOCAL_IP_ADDRESS),
- cast_uchar " ", ad, cast_uchar ": ",
- er, MSG_BOX_END, NULL, 1,
- TEXT_(T_CANCEL), msg_box_null,
- B_ENTER | B_ESC);
- return 1;
+ ) {
+ unsigned char *er = stracpy(cast_uchar strerror(errno));
+ unsigned char *ad = stracpy(p);
+ msg_box(dlg->win->term, getml(er, ad, NULL),
+ TEXT_(T_BAD_IP_ADDRESS), AL_CENTER,
+ TEXT_(T_UNABLE_TO_USE_LOCAL_IP_ADDRESS),
+ cast_uchar " ", ad, cast_uchar ": ", er,
+ MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL),
+ msg_box_null, B_ENTER | B_ESC);
+ return 1;
}
}
return 0;
}
-int check_local_ip_address(struct dialog_data *dlg, struct dialog_item_data *di)
+int
+check_local_ip_address(struct dialog_data *dlg, struct dialog_item_data *di)
{
return check_local_ip_address_internal(dlg, di, PF_INET);
}
-int check_local_ipv6_address(struct dialog_data *dlg, struct dialog_item_data *di)
+int
+check_local_ipv6_address(struct dialog_data *dlg, struct dialog_item_data *di)
{
return check_local_ip_address_internal(dlg, di, PF_INET6);
}
-int cancel_dialog(struct dialog_data *dlg, struct dialog_item_data *di)
+int
+cancel_dialog(struct dialog_data *dlg, struct dialog_item_data *di)
{
delete_window(dlg->win);
return 0;
}
-int check_dialog(struct dialog_data *dlg)
+int
+check_dialog(struct dialog_data *dlg)
{
int i;
for (i = 0; i < dlg->n; i++)
- if (dlg->dlg->items[i].type == D_CHECKBOX || dlg->dlg->items[i].type == D_FIELD || dlg->dlg->items[i].type == D_FIELD_PASS)
- if (dlg->dlg->items[i].fn && dlg->dlg->items[i].fn(dlg, &dlg->items[i])) {
+ if (dlg->dlg->items[i].type == D_CHECKBOX
+ || dlg->dlg->items[i].type == D_FIELD
+ || dlg->dlg->items[i].type == D_FIELD_PASS)
+ if (dlg->dlg->items[i].fn
+ && dlg->dlg->items[i].fn(dlg, &dlg->items[i])) {
dlg->selected = i;
- draw_to_window(dlg->win, redraw_dialog_items, dlg);
+ draw_to_window(dlg->win, redraw_dialog_items,
+ dlg);
return 1;
}
return 0;
}
-void get_dialog_data(struct dialog_data *dlg)
+void
+get_dialog_data(struct dialog_data *dlg)
{
int i;
for (i = 0; i < dlg->n; i++) {
@@ -1410,42 +1695,51 @@ void get_dialog_data(struct dialog_data *dlg)
}
}
-int ok_dialog(struct dialog_data *dlg, struct dialog_item_data *di)
+int
+ok_dialog(struct dialog_data *dlg, struct dialog_item_data *di)
{
void (*fn)(void *) = dlg->dlg->refresh;
void *data = dlg->dlg->refresh_data;
- if (check_dialog(dlg)) return 1;
+ if (check_dialog(dlg))
+ return 1;
get_dialog_data(dlg);
- if (fn) fn(data);
+ if (fn)
+ fn(data);
return cancel_dialog(dlg, di);
}
-void center_dlg(struct dialog_data *dlg)
+void
+center_dlg(struct dialog_data *dlg)
{
dlg->x = (dlg->win->term->x - dlg->xw) / 2;
dlg->y = (dlg->win->term->y - dlg->yw) / 2;
}
-void draw_dlg(struct dialog_data *dlg)
+void
+draw_dlg(struct dialog_data *dlg)
{
int i, tpos;
struct terminal *term = dlg->win->term;
- fill_area(term, dlg->x, dlg->y, dlg->xw, dlg->yw, ' ',
- COLOR_DIALOG);
+ fill_area(term, dlg->x, dlg->y, dlg->xw, dlg->yw, ' ', COLOR_DIALOG);
draw_frame(term, dlg->x + DIALOG_LEFT_BORDER,
- dlg->y + DIALOG_TOP_BORDER,
- dlg->xw - 2 * DIALOG_LEFT_BORDER,
- dlg->yw - 2 * DIALOG_TOP_BORDER, COLOR_DIALOG_FRAME,
- DIALOG_FRAME);
+ dlg->y + DIALOG_TOP_BORDER, dlg->xw - 2 * DIALOG_LEFT_BORDER,
+ dlg->yw - 2 * DIALOG_TOP_BORDER, COLOR_DIALOG_FRAME,
+ DIALOG_FRAME);
i = strlen((char *)get_text_translation(dlg->dlg->title, term));
tpos = (dlg->xw - i) / 2;
- print_text(term, tpos + dlg->x - 1, dlg->y + DIALOG_TOP_BORDER, 1, cast_uchar " ", COLOR_DIALOG_TITLE);
- print_text(term, tpos + dlg->x, dlg->y + DIALOG_TOP_BORDER, i, get_text_translation(dlg->dlg->title, term), COLOR_DIALOG_TITLE);
- print_text(term, tpos + dlg->x + i, dlg->y + DIALOG_TOP_BORDER, 1, cast_uchar " ", COLOR_DIALOG_TITLE);
+ print_text(term, tpos + dlg->x - 1, dlg->y + DIALOG_TOP_BORDER, 1,
+ cast_uchar " ", COLOR_DIALOG_TITLE);
+ print_text(term, tpos + dlg->x, dlg->y + DIALOG_TOP_BORDER, i,
+ get_text_translation(dlg->dlg->title, term),
+ COLOR_DIALOG_TITLE);
+ print_text(term, tpos + dlg->x + i, dlg->y + DIALOG_TOP_BORDER, 1,
+ cast_uchar " ", COLOR_DIALOG_TITLE);
}
-void max_text_width(struct terminal *term, unsigned char *text, int *width, int align)
+void
+max_text_width(struct terminal *term, unsigned char *text, int *width,
+ int align)
{
text = get_text_translation(text, term);
do {
@@ -1460,11 +1754,14 @@ void max_text_width(struct terminal *term, unsigned char *text, int *width, int
c++;
}
}
- if (c > *width) *width = c;
+ if (c > *width)
+ *width = c;
} while (*(text++));
}
-void min_text_width(struct terminal *term, unsigned char *text, int *width, int align)
+void
+min_text_width(struct terminal *term, unsigned char *text, int *width,
+ int align)
{
text = get_text_translation(text, term);
do {
@@ -1479,11 +1776,15 @@ void min_text_width(struct terminal *term, unsigned char *text, int *width, int
c++;
}
}
- if (c > *width) *width = c;
+ if (c > *width)
+ *width = c;
} while (*(text++));
}
-int dlg_format_text(struct dialog_data *dlg, struct terminal *term, unsigned char *text, int x, int *y, int w, int *rw, unsigned char co, int align)
+int
+dlg_format_text(struct dialog_data *dlg, struct terminal *term,
+ unsigned char *text, int x, int *y, int w, int *rw,
+ unsigned char co, int align)
{
int xx = x;
text = get_text_translation(text, dlg->win->term);
@@ -1495,14 +1796,15 @@ int dlg_format_text(struct dialog_data *dlg, struct terminal *term, unsigned cha
t1 = text;
cx = 0;
lbr = 0;
- next_chr:
+next_chr:
ch = GET_TERM_CHAR(dlg->win->term, &t1);
if (ch == ' ') {
lbr = cx;
}
if (ch && ch != '\n') {
if (cx == w) {
- if (!lbr) lbr = cx;
+ if (!lbr)
+ lbr = cx;
goto print_line;
}
cx++;
@@ -1511,42 +1813,58 @@ int dlg_format_text(struct dialog_data *dlg, struct terminal *term, unsigned cha
if (!ch && !cx)
break;
lbr = cx;
- print_line:
- if (rw && lbr > *rw) *rw = lbr;
+print_line:
+ if (rw && lbr > *rw)
+ *rw = lbr;
xx = x;
if ((align & AL_MASK) == AL_CENTER) {
xx += (w - lbr) / 2;
}
for (; lbr--; xx++) {
ch = GET_TERM_CHAR(dlg->win->term, &text);
- if (term) set_char(term, xx, *y, ch, co);
+ if (term)
+ set_char(term, xx, *y, ch, co);
}
xx++;
- if (*text == ' ' || *text == '\n') text++;
+ if (*text == ' ' || *text == '\n')
+ text++;
(*y)++;
}
return xx - x;
}
-void max_buttons_width(struct terminal *term, struct dialog_item_data *butt, int n, int *width)
+void
+max_buttons_width(struct terminal *term, struct dialog_item_data *butt, int n,
+ int *width)
{
int w = -2;
int i;
for (i = 0; i < n; i++)
- w += txtlen(term, get_text_translation((butt++)->item->text, term)) + 6;
- if (w > *width) *width = w;
+ w += txtlen(term,
+ get_text_translation((butt++)->item->text, term))
+ + 6;
+ if (w > *width)
+ *width = w;
}
-void min_buttons_width(struct terminal *term, struct dialog_item_data *butt, int n, int *width)
+void
+min_buttons_width(struct terminal *term, struct dialog_item_data *butt, int n,
+ int *width)
{
int i;
for (i = 0; i < n; i++) {
- int w = txtlen(term, get_text_translation((butt++)->item->text, term)) + 4;
- if (w > *width) *width = w;
+ int w = txtlen(term,
+ get_text_translation((butt++)->item->text, term))
+ + 4;
+ if (w > *width)
+ *width = w;
}
}
-void dlg_format_buttons(struct dialog_data *dlg, struct terminal *term, struct dialog_item_data *butt, int n, int x, int *y, int w, int *rw, int align)
+void
+dlg_format_buttons(struct dialog_data *dlg, struct terminal *term,
+ struct dialog_item_data *butt, int n, int x, int *y, int w,
+ int *rw, int align)
{
int i1 = 0;
while (i1 < n) {
@@ -1554,20 +1872,32 @@ void dlg_format_buttons(struct dialog_data *dlg, struct terminal *term, struct d
int mw;
while (i2 < n) {
mw = 0;
- max_buttons_width(dlg->win->term, butt + i1, i2 - i1 + 1, &mw);
- if (mw <= w) i2++;
- else break;
+ max_buttons_width(dlg->win->term, butt + i1,
+ i2 - i1 + 1, &mw);
+ if (mw <= w)
+ i2++;
+ else
+ break;
}
mw = 0;
max_buttons_width(dlg->win->term, butt + i1, i2 - i1, &mw);
- if (rw && mw > *rw) if ((*rw = mw) > w) *rw = w;
+ if (rw && mw > *rw)
+ if ((*rw = mw) > w)
+ *rw = w;
if (term) {
int i;
- int p = x + ((align & AL_MASK) == AL_CENTER ? (w - mw) / 2 : 0);
+ int p = x
+ + ((align & AL_MASK) == AL_CENTER ? (w - mw) / 2
+ : 0);
for (i = i1; i < i2; i++) {
butt[i].x = p;
butt[i].y = *y;
- p += (butt[i].l = txtlen(dlg->win->term, get_text_translation(butt[i].item->text, dlg->win->term)) + 4) + 2;
+ p += (butt[i].l = txtlen(dlg->win->term,
+ get_text_translation(
+ butt[i].item->text,
+ dlg->win->term))
+ + 4)
+ + 2;
}
}
*y += 2;
@@ -1575,27 +1905,41 @@ void dlg_format_buttons(struct dialog_data *dlg, struct terminal *term, struct d
}
}
-void dlg_format_checkbox(struct dialog_data *dlg, struct terminal *term, struct dialog_item_data *chkb, int x, int *y, int w, int *rw, unsigned char *text)
+void
+dlg_format_checkbox(struct dialog_data *dlg, struct terminal *term,
+ struct dialog_item_data *chkb, int x, int *y, int w,
+ int *rw, unsigned char *text)
{
int k = 4;
if (term) {
chkb->x = x;
chkb->y = *y;
}
- if (rw) *rw -= k;
- dlg_format_text(dlg, term, text, x + k, y, w - k, rw, COLOR_DIALOG_CHECKBOX_TEXT, AL_LEFT | AL_NOBRLEXP);
- if (rw) *rw += k;
+ if (rw)
+ *rw -= k;
+ dlg_format_text(dlg, term, text, x + k, y, w - k, rw,
+ COLOR_DIALOG_CHECKBOX_TEXT, AL_LEFT | AL_NOBRLEXP);
+ if (rw)
+ *rw += k;
}
-void dlg_format_checkboxes(struct dialog_data *dlg, struct terminal *term, struct dialog_item_data *chkb, int n, int x, int *y, int w, int *rw, unsigned char * const *texts)
+void
+dlg_format_checkboxes(struct dialog_data *dlg, struct terminal *term,
+ struct dialog_item_data *chkb, int n, int x, int *y,
+ int w, int *rw, unsigned char *const *texts)
{
while (n) {
dlg_format_checkbox(dlg, term, chkb, x, y, w, rw, texts[0]);
- texts++; chkb++; n--;
+ texts++;
+ chkb++;
+ n--;
}
}
-void checkboxes_width(struct terminal *term, unsigned char * const *texts, int n, int *w, void (*fn)(struct terminal *, unsigned char *, int *, int))
+void
+checkboxes_width(struct terminal *term, unsigned char *const *texts, int n,
+ int *w,
+ void (*fn)(struct terminal *, unsigned char *, int *, int))
{
int k = 4;
while (n--) {
@@ -1606,24 +1950,32 @@ void checkboxes_width(struct terminal *term, unsigned char * const *texts, int n
}
}
-void dlg_format_field(struct dialog_data *dlg, struct terminal *term, struct dialog_item_data *item, int x, int *y, int w, int *rw, int align)
+void
+dlg_format_field(struct dialog_data *dlg, struct terminal *term,
+ struct dialog_item_data *item, int x, int *y, int w, int *rw,
+ int align)
{
if (term) {
item->x = x;
item->y = *y;
item->l = w;
- if (rw && item->l > *rw) if ((*rw = item->l) > w) *rw = w;
+ if (rw && item->l > *rw)
+ if ((*rw = item->l) > w)
+ *rw = w;
}
(*y)++;
}
-void dlg_format_text_and_field(struct dialog_data *dlg, struct terminal *term, unsigned char *text, struct dialog_item_data *item, int x, int *y, int w, int *rw, unsigned char co, int align)
+void
+dlg_format_text_and_field(struct dialog_data *dlg, struct terminal *term,
+ unsigned char *text, struct dialog_item_data *item,
+ int x, int *y, int w, int *rw, unsigned char co,
+ int align)
{
dlg_format_text(dlg, term, text, x, y, w, rw, co, align);
dlg_format_field(dlg, term, item, x, y, w, rw, align);
}
-
#if 0
/* Layout for generic boxes */
void dlg_format_box(struct terminal *term, struct terminal *t2, struct dialog_item_data *item, int x, int *y, int w, int *rw, int align) {
@@ -1635,13 +1987,19 @@ void dlg_format_box(struct terminal *term, struct terminal *t2, struct dialog_it
}
#endif
-void max_group_width(struct terminal *term, unsigned char * const *texts, struct dialog_item_data *item, int n, int *w)
+void
+max_group_width(struct terminal *term, unsigned char *const *texts,
+ struct dialog_item_data *item, int n, int *w)
{
int ww = 0;
while (n--) {
- int wx = item->item->type == D_CHECKBOX ? 4 :
- item->item->type == D_BUTTON ? txtlen(term, get_text_translation(item->item->text, term)) + 4 :
- item->item->dlen;
+ int wx =
+ item->item->type == D_CHECKBOX ? 4
+ : item->item->type == D_BUTTON
+ ? txtlen(term,
+ get_text_translation(item->item->text, term))
+ + 4
+ : item->item->dlen;
wx += txtlen(term, get_text_translation(texts[0], term)) + 1;
if (n)
wx++;
@@ -1649,32 +2007,50 @@ void max_group_width(struct terminal *term, unsigned char * const *texts, struct
texts++;
item++;
}
- if (ww > *w) *w = ww;
+ if (ww > *w)
+ *w = ww;
}
-void min_group_width(struct terminal *term, unsigned char * const *texts, struct dialog_item_data *item, int n, int *w)
+void
+min_group_width(struct terminal *term, unsigned char *const *texts,
+ struct dialog_item_data *item, int n, int *w)
{
while (n--) {
- int wx = item->item->type == D_CHECKBOX ? 4 :
- item->item->type == D_BUTTON ? txtlen(term, get_text_translation(item->item->text, term)) + 4 :
- item->item->dlen + 1;
+ int wx =
+ item->item->type == D_CHECKBOX ? 4
+ : item->item->type == D_BUTTON
+ ? txtlen(term,
+ get_text_translation(item->item->text, term))
+ + 4
+ : item->item->dlen + 1;
wx += txtlen(term, get_text_translation(texts[0], term));
- if (wx > *w) *w = wx;
+ if (wx > *w)
+ *w = wx;
texts++;
item++;
}
}
-void dlg_format_group(struct dialog_data *dlg, struct terminal *term, unsigned char * const *texts, struct dialog_item_data *item, int n, int x, int *y, int w, int *rw)
+void
+dlg_format_group(struct dialog_data *dlg, struct terminal *term,
+ unsigned char *const *texts, struct dialog_item_data *item,
+ int n, int x, int *y, int w, int *rw)
{
int nx = 0;
while (n--) {
- int wx = item->item->type == D_CHECKBOX ? 3 :
- item->item->type == D_BUTTON ? txtlen(dlg->win->term, get_text_translation(item->item->text, dlg->win->term)) + 4 :
- item->item->dlen;
+ int wx = item->item->type == D_CHECKBOX ? 3
+ : item->item->type == D_BUTTON
+ ? txtlen(dlg->win->term,
+ get_text_translation(item->item->text,
+ dlg->win->term))
+ + 4
+ : item->item->dlen;
int sl;
if (get_text_translation(texts[0], dlg->win->term)[0])
- sl = txtlen(dlg->win->term, get_text_translation(texts[0], dlg->win->term)) + 1;
+ sl = txtlen(
+ dlg->win->term,
+ get_text_translation(texts[0], dlg->win->term))
+ + 1;
else
sl = 0;
wx += sl;
@@ -1683,13 +2059,23 @@ void dlg_format_group(struct dialog_data *dlg, struct terminal *term, unsigned c
(*y) += 2;
}
if (term) {
- print_text(term, x + nx + 4 * (item->item->type == D_CHECKBOX), *y, strlen((char *)get_text_translation(texts[0], dlg->win->term)), get_text_translation(texts[0], dlg->win->term), COLOR_DIALOG_TEXT);
- item->x = x + nx + sl * (item->item->type != D_CHECKBOX);
+ print_text(
+ term, x + nx + 4 * (item->item->type == D_CHECKBOX),
+ *y,
+ strlen((char *)get_text_translation(
+ texts[0], dlg->win->term)),
+ get_text_translation(texts[0], dlg->win->term),
+ COLOR_DIALOG_TEXT);
+ item->x =
+ x + nx + sl * (item->item->type != D_CHECKBOX);
item->y = *y;
- if (item->item->type == D_FIELD || item->item->type == D_FIELD_PASS)
+ if (item->item->type == D_FIELD
+ || item->item->type == D_FIELD_PASS)
item->l = item->item->dlen;
}
- if (rw && nx + wx > *rw) if ((*rw = nx + wx) > w) *rw = w;
+ if (rw && nx + wx > *rw)
+ if ((*rw = nx + wx) > w)
+ *rw = w;
nx += wx + 1;
texts++;
item++;
@@ -1697,40 +2083,56 @@ void dlg_format_group(struct dialog_data *dlg, struct terminal *term, unsigned c
(*y)++;
}
-void checkbox_list_fn(struct dialog_data *dlg)
+void
+checkbox_list_fn(struct dialog_data *dlg)
{
struct terminal *term = dlg->win->term;
int n_checkboxes;
int max = 0, min = 0;
int w, rw;
int y = 0;
- for (n_checkboxes = 0; ((unsigned char **)dlg->dlg->udata)[n_checkboxes]; n_checkboxes++)
+ for (n_checkboxes = 0;
+ ((unsigned char **)dlg->dlg->udata)[n_checkboxes]; n_checkboxes++)
;
- checkboxes_width(term, dlg->dlg->udata, n_checkboxes, &max, max_text_width);
- checkboxes_width(term, dlg->dlg->udata, n_checkboxes, &min, min_text_width);
- max_buttons_width(term, dlg->items + n_checkboxes, dlg->n - n_checkboxes, &max);
- min_buttons_width(term, dlg->items + n_checkboxes, dlg->n - n_checkboxes, &min);
+ checkboxes_width(term, dlg->dlg->udata, n_checkboxes, &max,
+ max_text_width);
+ checkboxes_width(term, dlg->dlg->udata, n_checkboxes, &min,
+ min_text_width);
+ max_buttons_width(term, dlg->items + n_checkboxes,
+ dlg->n - n_checkboxes, &max);
+ min_buttons_width(term, dlg->items + n_checkboxes,
+ dlg->n - n_checkboxes, &min);
w = term->x * 9 / 10 - 2 * DIALOG_LB;
- if (w > max) w = max;
- if (w < min) w = min;
- if (w > term->x - 2 * DIALOG_LB) w = term->x - 2 * DIALOG_LB;
- if (w < 5) w = 5;
+ if (w > max)
+ w = max;
+ if (w < min)
+ w = min;
+ if (w > term->x - 2 * DIALOG_LB)
+ w = term->x - 2 * DIALOG_LB;
+ if (w < 5)
+ w = 5;
rw = 0;
- dlg_format_checkboxes(dlg, NULL, dlg->items, n_checkboxes, 0, &y, w, &rw, dlg->dlg->udata);
+ dlg_format_checkboxes(dlg, NULL, dlg->items, n_checkboxes, 0, &y, w,
+ &rw, dlg->dlg->udata);
y++;
- dlg_format_buttons(dlg, NULL, dlg->items + n_checkboxes, dlg->n - n_checkboxes, 0, &y, w, &rw, AL_CENTER);
+ dlg_format_buttons(dlg, NULL, dlg->items + n_checkboxes,
+ dlg->n - n_checkboxes, 0, &y, w, &rw, AL_CENTER);
w = rw;
dlg->xw = rw + 2 * DIALOG_LB;
dlg->yw = y + 2 * DIALOG_TB;
center_dlg(dlg);
draw_dlg(dlg);
y = dlg->y + DIALOG_TB + 1;
- dlg_format_checkboxes(dlg, term, dlg->items, n_checkboxes, dlg->x + DIALOG_LB, &y, w, NULL, dlg->dlg->udata);
+ dlg_format_checkboxes(dlg, term, dlg->items, n_checkboxes,
+ dlg->x + DIALOG_LB, &y, w, NULL, dlg->dlg->udata);
y++;
- dlg_format_buttons(dlg, term, dlg->items + n_checkboxes, dlg->n - n_checkboxes, dlg->x + DIALOG_LB, &y, w, &rw, AL_CENTER);
+ dlg_format_buttons(dlg, term, dlg->items + n_checkboxes,
+ dlg->n - n_checkboxes, dlg->x + DIALOG_LB, &y, w,
+ &rw, AL_CENTER);
}
-void group_fn(struct dialog_data *dlg)
+void
+group_fn(struct dialog_data *dlg)
{
struct terminal *term = dlg->win->term;
int max = 0, min = 0;
@@ -1741,26 +2143,35 @@ void group_fn(struct dialog_data *dlg)
max_buttons_width(term, dlg->items + dlg->n - 2, 2, &max);
min_buttons_width(term, dlg->items + dlg->n - 2, 2, &min);
w = term->x * 9 / 10 - 2 * DIALOG_LB;
- if (w > max) w = max;
- if (w < min) w = min;
- if (w > term->x - 2 * DIALOG_LB) w = term->x - 2 * DIALOG_LB;
- if (w < 1) w = 1;
+ if (w > max)
+ w = max;
+ if (w < min)
+ w = min;
+ if (w > term->x - 2 * DIALOG_LB)
+ w = term->x - 2 * DIALOG_LB;
+ if (w < 1)
+ w = 1;
rw = 0;
- dlg_format_group(dlg, NULL, dlg->dlg->udata, dlg->items, dlg->n - 2, 0, &y, w, &rw);
+ dlg_format_group(dlg, NULL, dlg->dlg->udata, dlg->items, dlg->n - 2, 0,
+ &y, w, &rw);
y++;
- dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 2, 2, 0, &y, w, &rw, AL_CENTER);
+ dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 2, 2, 0, &y, w, &rw,
+ AL_CENTER);
w = rw;
dlg->xw = rw + 2 * DIALOG_LB;
dlg->yw = y + 2 * DIALOG_TB;
center_dlg(dlg);
draw_dlg(dlg);
y = dlg->y + DIALOG_TB + 1;
- dlg_format_group(dlg, term, dlg->dlg->udata, dlg->items, dlg->n - 2, dlg->x + DIALOG_LB, &y, w, NULL);
+ dlg_format_group(dlg, term, dlg->dlg->udata, dlg->items, dlg->n - 2,
+ dlg->x + DIALOG_LB, &y, w, NULL);
y++;
- dlg_format_buttons(dlg, term, dlg->items + dlg->n - 2, 2, dlg->x + DIALOG_LB, &y, w, &rw, AL_CENTER);
+ dlg_format_buttons(dlg, term, dlg->items + dlg->n - 2, 2,
+ dlg->x + DIALOG_LB, &y, w, &rw, AL_CENTER);
}
-void msg_box_fn(struct dialog_data *dlg)
+void
+msg_box_fn(struct dialog_data *dlg)
{
struct terminal *term = dlg->win->term;
int max = 0, min = 0;
@@ -1769,33 +2180,43 @@ void msg_box_fn(struct dialog_data *dlg)
unsigned char **ptr;
unsigned char *text = init_str();
int textl = 0;
- for (ptr = dlg->dlg->udata; *ptr; ptr++) add_to_str(&text, &textl, get_text_translation(*ptr, term));
+ for (ptr = dlg->dlg->udata; *ptr; ptr++)
+ add_to_str(&text, &textl, get_text_translation(*ptr, term));
max_text_width(term, text, &max, dlg->dlg->align);
min_text_width(term, text, &min, dlg->dlg->align);
max_buttons_width(term, dlg->items, dlg->n, &max);
min_buttons_width(term, dlg->items, dlg->n, &min);
w = term->x * 9 / 10 - 2 * DIALOG_LB;
- if (w > max) w = max;
- if (w < min) w = min;
- if (w > term->x - 2 * DIALOG_LB) w = term->x - 2 * DIALOG_LB;
- if (w < 1) w = 1;
+ if (w > max)
+ w = max;
+ if (w < min)
+ w = min;
+ if (w > term->x - 2 * DIALOG_LB)
+ w = term->x - 2 * DIALOG_LB;
+ if (w < 1)
+ w = 1;
rw = 0;
- dlg_format_text(dlg, NULL, text, 0, &y, w, &rw, COLOR_DIALOG_TEXT, dlg->dlg->align);
+ dlg_format_text(dlg, NULL, text, 0, &y, w, &rw, COLOR_DIALOG_TEXT,
+ dlg->dlg->align);
y++;
- dlg_format_buttons(dlg, NULL, dlg->items, dlg->n, 0, &y, w, &rw, AL_CENTER);
+ dlg_format_buttons(dlg, NULL, dlg->items, dlg->n, 0, &y, w, &rw,
+ AL_CENTER);
w = rw;
dlg->xw = rw + 2 * DIALOG_LB;
dlg->yw = y + 2 * DIALOG_TB;
center_dlg(dlg);
draw_dlg(dlg);
y = dlg->y + DIALOG_TB + 1;
- dlg_format_text(dlg, term, text, dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, dlg->dlg->align);
+ dlg_format_text(dlg, term, text, dlg->x + DIALOG_LB, &y, w, NULL,
+ COLOR_DIALOG_TEXT, dlg->dlg->align);
y++;
- dlg_format_buttons(dlg, term, dlg->items, dlg->n, dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);
+ dlg_format_buttons(dlg, term, dlg->items, dlg->n, dlg->x + DIALOG_LB,
+ &y, w, NULL, AL_CENTER);
free(text);
}
-static int msg_box_button(struct dialog_data *dlg, struct dialog_item_data *di)
+static int
+msg_box_button(struct dialog_data *dlg, struct dialog_item_data *di)
{
msg_button_fn msg_fn = di->item->u.msg_fn;
void *data = dlg->dlg->udata2;
@@ -1804,12 +2225,15 @@ static int msg_box_button(struct dialog_data *dlg, struct dialog_item_data *di)
return 0;
}
-void msg_box_null(void *data)
+void
+msg_box_null(void *data)
{
}
/* coverity[+free : arg-1] */
-void msg_box(struct terminal *term, struct memory_list *ml, unsigned char *title, int align, /*unsigned char *text, ..., void *data, int n,*/ ...)
+void
+msg_box(struct terminal *term, struct memory_list *ml, unsigned char *title,
+ int align, /*unsigned char *text, ..., void *data, int n,*/...)
{
struct dialog *dlg;
int i;
@@ -1832,8 +2256,12 @@ void msg_box(struct terminal *term, struct memory_list *ml, unsigned char *title
} while (text);
udata2 = va_arg(ap, void *);
n = va_arg(ap, int);
- if ((unsigned)n > (INT_MAX - sizeof(struct dialog)) / sizeof(struct dialog_item) - 1) overalloc();
- dlg = mem_calloc(sizeof(struct dialog) + (n + 1) * sizeof(struct dialog_item));
+ if ((unsigned)n
+ > (INT_MAX - sizeof(struct dialog)) / sizeof(struct dialog_item)
+ - 1)
+ overalloc();
+ dlg = mem_calloc(sizeof(struct dialog)
+ + (n + 1) * sizeof(struct dialog_item));
dlg->title = title;
dlg->fn = msg_box_fn;
dlg->udata = udata;
@@ -1864,29 +2292,35 @@ void msg_box(struct terminal *term, struct memory_list *ml, unsigned char *title
do_dialog(term, dlg, ml);
}
-void add_to_history(struct terminal *term, struct history *h, unsigned char *t)
+void
+add_to_history(struct terminal *term, struct history *h, unsigned char *t)
{
unsigned char *s;
struct history_item *hi, *hs = NULL;
struct list_head *lhs;
size_t l;
- if (!h || !t || !*t) return;
+ if (!h || !t || !*t)
+ return;
if (term)
s = convert(term_charset(term), 0, t, NULL);
else
s = t;
l = strlen(cast_const_char s);
- if (l > INT_MAX - sizeof(struct history_item)) overalloc();
+ if (l > INT_MAX - sizeof(struct history_item))
+ overalloc();
hi = xmalloc(sizeof(struct history_item) + l);
memcpy(hi->str, s, l + 1);
if (term)
free(s);
- if (term) foreach(struct history_item, hs, lhs, h->items) if (!strcmp(cast_const_char hs->str, cast_const_char hi->str)) {
- lhs = lhs->prev;
- del_from_list(hs);
- free(hs);
- h->n--;
- }
+ if (term)
+ foreach (struct history_item, hs, lhs, h->items)
+ if (!strcmp(cast_const_char hs->str,
+ cast_const_char hi->str)) {
+ lhs = lhs->prev;
+ del_from_list(hs);
+ free(hs);
+ h->n--;
+ }
add_to_list(h->items, hi);
h->n++;
while (h->n > MAX_HISTORY_ITEMS) {
@@ -1903,7 +2337,8 @@ void add_to_history(struct terminal *term, struct history *h, unsigned char *t)
}
}
-static int input_field_cancel(struct dialog_data *dlg, struct dialog_item_data *di)
+static int
+input_field_cancel(struct dialog_data *dlg, struct dialog_item_data *di)
{
input_field_button_fn fn = di->item->u.input_fn;
void *data = dlg->dlg->udata2;
@@ -1913,19 +2348,22 @@ static int input_field_cancel(struct dialog_data *dlg, struct dialog_item_data *
return 0;
}
-static int input_field_ok(struct dialog_data *dlg, struct dialog_item_data *di)
+static int
+input_field_ok(struct dialog_data *dlg, struct dialog_item_data *di)
{
input_field_button_fn fn = di->item->u.input_fn;
void *data = dlg->dlg->udata2;
unsigned char *text = dlg->items->cdata;
- if (check_dialog(dlg)) return 1;
+ if (check_dialog(dlg))
+ return 1;
add_to_history(dlg->win->term, dlg->dlg->items->history, text);
fn(data, text);
ok_dialog(dlg, di);
return 0;
}
-static void input_field_fn(struct dialog_data *dlg)
+static void
+input_field_fn(struct dialog_data *dlg)
{
struct terminal *term = dlg->win->term;
int max = 0, min = 0;
@@ -1935,46 +2373,64 @@ static void input_field_fn(struct dialog_data *dlg)
min_text_width(term, dlg->dlg->udata, &min, AL_LEFT);
max_buttons_width(term, dlg->items + 1, dlg->n - 1, &max);
min_buttons_width(term, dlg->items + 1, dlg->n - 1, &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, dlg->dlg->udata, dlg->items, 0,
- &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, NULL, dlg->dlg->udata, dlg->items, 0, &y,
+ w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_buttons(dlg, NULL, dlg->items + 1, dlg->n - 1, 0, &y, w,
- &rw, AL_CENTER);
+ dlg_format_buttons(dlg, NULL, dlg->items + 1, dlg->n - 1, 0, &y, w, &rw,
+ AL_CENTER);
w = rw;
dlg->xw = rw + 2 * DIALOG_LB;
dlg->yw = y + 2 * DIALOG_TB;
center_dlg(dlg);
draw_dlg(dlg);
y = dlg->y + DIALOG_TB;
- dlg_format_text_and_field(dlg, term, dlg->dlg->udata, dlg->items, dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, term, dlg->dlg->udata, dlg->items,
+ dlg->x + DIALOG_LB, &y, w, NULL,
+ COLOR_DIALOG_TEXT, AL_LEFT);
y++;
dlg_format_buttons(dlg, term, dlg->items + 1, dlg->n - 1,
- dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);
+ dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);
}
-void input_field_null(void)
+void
+input_field_null(void)
{
}
/* coverity[+free : arg-1] */
-void input_field(struct terminal *term, struct memory_list *ml, unsigned char *title, unsigned char *text, void *data, struct history *history, int l, unsigned char *def, int min, int max, int (*check)(struct dialog_data *, struct dialog_item_data *), int n, ...)
+void
+input_field(struct terminal *term, struct memory_list *ml, unsigned char *title,
+ unsigned char *text, void *data, struct history *history, int l,
+ unsigned char *def, int min, int max,
+ int (*check)(struct dialog_data *, struct dialog_item_data *),
+ int n, ...)
{
struct dialog *dlg;
unsigned char *field;
va_list va;
int i;
- if ((unsigned)n > INT_MAX / sizeof(struct dialog_item) - 2) overalloc();
- if ((unsigned)l > INT_MAX - sizeof(struct dialog) - (2 + n) * sizeof(struct dialog_item)) overalloc();
- dlg = mem_calloc(sizeof(struct dialog) + (2 + n) * sizeof(struct dialog_item) + l);
- *(field = (unsigned char *)dlg + sizeof(struct dialog) + (2 + n) * sizeof(struct dialog_item)) = 0;
+ if ((unsigned)n > INT_MAX / sizeof(struct dialog_item) - 2)
+ overalloc();
+ if ((unsigned)l > INT_MAX - sizeof(struct dialog)
+ - (2 + n) * sizeof(struct dialog_item))
+ overalloc();
+ dlg = mem_calloc(sizeof(struct dialog)
+ + (2 + n) * sizeof(struct dialog_item) + l);
+ *(field = (unsigned char *)dlg + sizeof(struct dialog)
+ + (2 + n) * sizeof(struct dialog_item)) = 0;
if (def) {
- if (strlen(cast_const_char def) + 1 > (size_t)l) memcpy(field, def, l - 1);
- else strcpy(cast_char field, cast_const_char def);
+ if (strlen(cast_const_char def) + 1 > (size_t)l)
+ memcpy(field, def, l - 1);
+ else
+ strcpy(cast_char field, cast_const_char def);
}
dlg->title = title;
dlg->fn = input_field_fn;
@@ -1991,7 +2447,8 @@ void input_field(struct terminal *term, struct memory_list *ml, unsigned char *t
for (i = 1; i <= n; i++) {
dlg->items[i].type = D_BUTTON;
dlg->items[i].gid = i == 1 ? B_ENTER : i == n ? B_ESC : 0;
- dlg->items[i].fn = i != n || n == 1 ? input_field_ok : input_field_cancel;
+ dlg->items[i].fn =
+ i != n || n == 1 ? input_field_ok : input_field_cancel;
dlg->items[i].dlen = 0;
dlg->items[i].text = va_arg(va, unsigned char *);
dlg->items[i].u.input_fn = va_arg(va, input_field_button_fn);
@@ -2003,20 +2460,23 @@ void input_field(struct terminal *term, struct memory_list *ml, unsigned char *t
do_dialog(term, dlg, ml);
}
-int find_msg_box(struct terminal *term, unsigned char *title, int (*sel)(void *, void *), void *data)
+int
+find_msg_box(struct terminal *term, unsigned char *title,
+ int (*sel)(void *, void *), void *data)
{
struct window *win = NULL;
struct list_head *lwin;
- foreach(struct window, win, lwin, term->windows) if (win->handler == dialog_func) {
- struct dialog_data *dd = win->data;
- struct dialog *d = dd->dlg;
- if (d->fn != msg_box_fn)
- continue;
- if (d->title == title) {
- if (sel && !sel(data, d->udata2))
+ foreach (struct window, win, lwin, term->windows)
+ if (win->handler == dialog_func) {
+ struct dialog_data *dd = win->data;
+ struct dialog *d = dd->dlg;
+ if (d->fn != msg_box_fn)
continue;
- return 1;
+ if (d->title == title) {
+ if (sel && !sel(data, d->udata2))
+ continue;
+ return 1;
+ }
}
- }
return 0;
}
diff --git a/bookmark.c b/bookmark.c
@@ -10,79 +10,92 @@ static struct stat bookmarks_st;
static struct list *bookmark_new_item(void *);
static unsigned char *bookmark_type_item(struct terminal *, struct list *, int);
static void bookmark_delete_item(struct list *);
-static void bookmark_edit_item(struct dialog_data *, struct list *, void (*)(struct dialog_data *, struct list *, struct list *, struct list_description *), struct list *, unsigned char);
+static void bookmark_edit_item(struct dialog_data *, struct list *,
+ void (*)(struct dialog_data *, struct list *,
+ struct list *,
+ struct list_description *),
+ struct list *, unsigned char);
static void bookmark_copy_item(struct list *, struct list *);
static void bookmark_goto_item(struct session *, struct list *);
static void *bookmark_default_value(struct session *, unsigned char);
-static struct list *bookmark_find_item(struct list *start, unsigned char *str, int direction);
+static struct list *bookmark_find_item(struct list *start, unsigned char *str,
+ int direction);
static void save_bookmarks(struct session *ses);
struct list bookmarks = { init_list_1st(&bookmarks.list_entry) 0, -1, NULL };
-static struct history bookmark_search_history = { 0, { &bookmark_search_history.items, &bookmark_search_history.items } };
+static struct history bookmark_search_history = {
+ 0, {&bookmark_search_history.items, &bookmark_search_history.items}
+};
-/* when you change anything, don't forget to change it in reinit_bookmarks too !*/
+/* when you change anything, don't forget to change it in reinit_bookmarks too
+ * !*/
struct bookmark_ok_struct {
- void (*fn)(struct dialog_data *, struct list *, struct list *, struct list_description *);
+ void (*fn)(struct dialog_data *, struct list *, struct list *,
+ struct list_description *);
struct list *data;
struct dialog_data *dlg;
};
-
struct bookmark_list {
list_head_1st
- /* bookmark specific */
- unsigned char *title;
+ /* bookmark specific */
+ unsigned char *title;
unsigned char *url;
list_head_last
};
-
static struct list_description bookmark_ld = {
- 1, /* 0= flat; 1=tree */
- &bookmarks, /* list */
- bookmark_new_item, /* no codepage translations */
- bookmark_edit_item, /* translate when create dialog and translate back when ok is pressed */
- bookmark_default_value, /* codepage translation from current_page_encoding to UTF8 */
- bookmark_delete_item, /* no codepage translations */
- bookmark_copy_item, /* no codepage translations */
- bookmark_type_item, /* no codepage translations (bookmarks are internally in UTF8) */
+ 1, /* 0= flat; 1=tree */
+ &bookmarks, /* list */
+ bookmark_new_item, /* no codepage translations */
+ bookmark_edit_item, /* translate when create dialog and translate back
+ when ok is pressed */
+ bookmark_default_value, /* codepage translation from
+ current_page_encoding to UTF8 */
+ bookmark_delete_item, /* no codepage translations */
+ bookmark_copy_item, /* no codepage translations */
+ bookmark_type_item, /* no codepage translations (bookmarks are
+ internally in UTF8) */
bookmark_find_item,
&bookmark_search_history,
- 0, /* codepage */
- 15, /* # of items in main window */
+ 0, /* codepage */
+ 15, /* # of items in main window */
T_BOOKMARK,
T_BOOKMARKS_ALREADY_IN_USE,
T_BOOKMARK_MANAGER,
T_DELETE_BOOKMARK,
T_GOTO,
- bookmark_goto_item, /* FIXME: should work (URL in UTF8), but who knows? */
+ bookmark_goto_item, /* FIXME: should work (URL in UTF8), but who knows?
+ */
save_bookmarks,
- NULL,NULL,0,0, /* internal vars */
+ NULL,
+ NULL,
+ 0,
+ 0, /* internal vars */
0, /* modified */
NULL,
NULL,
0,
};
-
struct kawasaki {
unsigned char *title;
unsigned char *url;
};
-
/* clears the bookmark list */
-static void free_bookmarks(void)
+static void
+free_bookmarks(void)
{
struct list *b = NULL;
struct list_head *lb;
- foreach(struct list, b, lb, bookmarks.list_entry) {
- struct bookmark_list *bm = get_struct(b, struct bookmark_list,
- head);
+ foreach (struct list, b, lb, bookmarks.list_entry) {
+ struct bookmark_list *bm =
+ get_struct(b, struct bookmark_list, head);
free(bm->title);
free(bm->url);
lb = lb->prev;
@@ -91,9 +104,9 @@ static void free_bookmarks(void)
}
}
-
/* called before exiting the links */
-void finalize_bookmarks(void)
+void
+finalize_bookmarks(void)
{
free_bookmarks();
free_history(bookmark_search_history);
@@ -102,7 +115,8 @@ void finalize_bookmarks(void)
/* allocates struct kawasaki and puts current page title and url */
/* type: 0=item, 1=directory */
/* on error returns NULL */
-static void *bookmark_default_value(struct session *ses, unsigned char type)
+static void *
+bookmark_default_value(struct session *ses, unsigned char type)
{
struct kawasaki *zelena;
unsigned char *txt;
@@ -115,8 +129,8 @@ static void *bookmark_default_value(struct session *ses, unsigned char type)
zelena->title = NULL;
if (get_current_url(ses, txt, MAX_STR_LEN)) {
if (ses->screen->f_data) {
- zelena->url = convert(term_charset(ses->term), 0, txt,
- NULL);
+ zelena->url =
+ convert(term_charset(ses->term), 0, txt, NULL);
clr_white(zelena->url);
} else
zelena->url = stracpy(txt);
@@ -132,12 +146,13 @@ static void *bookmark_default_value(struct session *ses, unsigned char type)
return zelena;
}
-static void bookmark_copy_item(struct list *in, struct list *out)
+static void
+bookmark_copy_item(struct list *in, struct list *out)
{
- struct bookmark_list *item_in = get_struct(in, struct bookmark_list,
- head);
- struct bookmark_list *item_out = get_struct(out, struct bookmark_list,
- head);
+ struct bookmark_list *item_in =
+ get_struct(in, struct bookmark_list, head);
+ struct bookmark_list *item_out =
+ get_struct(out, struct bookmark_list, head);
item_out->head.type = item_in->head.type;
item_out->head.depth = item_in->head.depth;
@@ -148,13 +163,14 @@ static void bookmark_copy_item(struct list *in, struct list *out)
item_out->url = stracpy(item_in->url);
}
-static unsigned char * const bm_add_msg[] = {
+static unsigned char *const bm_add_msg[] = {
TEXT_(T_NNAME),
TEXT_(T_URL),
};
/* Called to setup the add bookmark dialog */
-static void bookmark_edit_item_fn(struct dialog_data *dlg)
+static void
+bookmark_edit_item_fn(struct dialog_data *dlg)
{
int max = 0, min = 0;
int w, rw;
@@ -179,10 +195,10 @@ static void bookmark_edit_item_fn(struct dialog_data *dlg)
for (a = 0; a < dlg->n - 2; a++, y++)
dlg_format_text_and_field(dlg, NULL, bm_add_msg[a],
- &dlg->items[a], 0, &y, w, &rw, COLOR_DIALOG_TEXT,
- AL_LEFT);
- dlg_format_buttons(dlg, NULL, dlg->items+dlg->n-2, 2, 0, &y, w, &rw,
- AL_CENTER);
+ &dlg->items[a], 0, &y, w, &rw,
+ COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 2, 2, 0, &y, w, &rw,
+ AL_CENTER);
w = rw;
dlg->xw = w + 2 * DIALOG_LB;
dlg->yw = y + 2 * DIALOG_TB;
@@ -191,14 +207,16 @@ static void bookmark_edit_item_fn(struct dialog_data *dlg)
y = dlg->y + DIALOG_TB;
for (a = 0; a < dlg->n - 2; a++, y++)
dlg_format_text_and_field(dlg, term, bm_add_msg[a],
- &dlg->items[a], dlg->x + DIALOG_LB, &y, w, NULL,
- COLOR_DIALOG_TEXT, AL_LEFT);
- dlg_format_buttons(dlg, term, &dlg->items[dlg->n-2], 2,
- dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);
+ &dlg->items[a], dlg->x + DIALOG_LB,
+ &y, w, NULL, COLOR_DIALOG_TEXT,
+ AL_LEFT);
+ dlg_format_buttons(dlg, term, &dlg->items[dlg->n - 2], 2,
+ dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);
}
/* Puts url and title into the bookmark item */
-static void bookmark_edit_done(void *data)
+static void
+bookmark_edit_done(void *data)
{
struct dialog *d = (struct dialog *)data;
struct bookmark_list *item = (struct bookmark_list *)d->udata;
@@ -222,11 +240,12 @@ static void bookmark_edit_done(void *data)
clr_white(item->url);
s->fn(s->dlg, s->data, &item->head, &bookmark_ld);
- d->udata = NULL; /* for abort function */
+ d->udata = NULL; /* for abort function */
}
/* destroys an item, this function is called when edit window is aborted */
-static void bookmark_edit_abort(struct dialog_data *data)
+static void
+bookmark_edit_abort(struct dialog_data *data)
{
struct bookmark_list *item = (struct bookmark_list *)data->dlg->udata;
struct dialog *dlg = data->dlg;
@@ -236,13 +255,16 @@ static void bookmark_edit_abort(struct dialog_data *data)
bookmark_delete_item(&item->head);
}
-
/* dlg_title is TITLE_EDIT or TITLE_ADD */
/* edit item function */
-static void bookmark_edit_item(struct dialog_data *dlg, struct list *data, void (*ok_fn)(struct dialog_data *, struct list *, struct list *, struct list_description *), struct list *ok_arg, unsigned char dlg_title)
+static void
+bookmark_edit_item(struct dialog_data *dlg, struct list *data,
+ void (*ok_fn)(struct dialog_data *, struct list *,
+ struct list *, struct list_description *),
+ struct list *ok_arg, unsigned char dlg_title)
{
- struct bookmark_list *item = get_struct(data, struct bookmark_list,
- head);
+ struct bookmark_list *item =
+ get_struct(data, struct bookmark_list, head);
unsigned char *title, *url, *txt;
struct dialog *d;
struct bookmark_ok_struct *s;
@@ -254,9 +276,12 @@ static void bookmark_edit_item(struct dialog_data *dlg, struct list *data, void
s->data = ok_arg;
s->dlg = dlg;
- if (item->head.type & 1) a = 4; /* folder */
- else a = 5;
- d = mem_calloc(sizeof(struct dialog) + a * sizeof(struct dialog_item) + 2 * MAX_STR_LEN);
+ if (item->head.type & 1)
+ a = 4; /* folder */
+ else
+ a = 5;
+ d = mem_calloc(sizeof(struct dialog) + a * sizeof(struct dialog_item)
+ + 2 * MAX_STR_LEN);
title = (unsigned char *)&d->items[a];
url = title + MAX_STR_LEN;
@@ -308,25 +333,25 @@ static void bookmark_edit_item(struct dialog_data *dlg, struct list *data, void
a++;
}
- d->items[a+1].type = D_BUTTON;
- d->items[a+1].gid = B_ENTER;
- d->items[a+1].fn = ok_dialog;
- d->items[a+1].text = TEXT_(T_OK);
+ d->items[a + 1].type = D_BUTTON;
+ d->items[a + 1].gid = B_ENTER;
+ d->items[a + 1].fn = ok_dialog;
+ d->items[a + 1].text = TEXT_(T_OK);
- d->items[a+2].type = D_BUTTON;
- d->items[a+2].gid = B_ESC;
- d->items[a+2].text = TEXT_(T_CANCEL);
- d->items[a+2].fn = cancel_dialog;
+ d->items[a + 2].type = D_BUTTON;
+ d->items[a + 2].gid = B_ESC;
+ d->items[a + 2].text = TEXT_(T_CANCEL);
+ d->items[a + 2].fn = cancel_dialog;
- d->items[a+3].type = D_END;
+ d->items[a + 3].type = D_END;
do_dialog(dlg->win->term, d, getml(d, NULL));
}
-
/* create new bookmark item and returns pointer to it, on error returns 0*/
/* bookmark is filled with given data, data are deallocated afterwards */
-static struct list *bookmark_new_item(void *data)
+static struct list *
+bookmark_new_item(void *data)
{
struct bookmark_list *b;
struct kawasaki *zelena = (struct kawasaki *)data;
@@ -348,15 +373,15 @@ static struct list *bookmark_new_item(void *data)
return &b->head;
}
-
/* allocate string and print bookmark into it */
/* x: 0=type all, 1=type title only */
-static unsigned char *bookmark_type_item(struct terminal *term, struct list *data, int x)
+static unsigned char *
+bookmark_type_item(struct terminal *term, struct list *data, int x)
{
unsigned char *txt, *txt1;
struct bookmark_list *item;
- if (data == &bookmarks) /* head */
+ if (data == &bookmarks) /* head */
return stracpy(get_text_translation(TEXT_(T_BOOKMARKS), term));
item = get_struct(data, struct bookmark_list, head);
@@ -374,29 +399,31 @@ static unsigned char *bookmark_type_item(struct terminal *term, struct list *dat
return txt1;
}
-
/* goto bookmark (called when goto button is pressed) */
-static void bookmark_goto_item(struct session *ses, struct list *i)
+static void
+bookmark_goto_item(struct session *ses, struct list *i)
{
struct bookmark_list *item = get_struct(i, struct bookmark_list, head);
goto_url_utf8(ses, item->url);
}
-
/* delete bookmark from list */
-static void bookmark_delete_item(struct list *data)
+static void
+bookmark_delete_item(struct list *data)
{
- struct bookmark_list *item = get_struct(data, struct bookmark_list,
- head);
+ struct bookmark_list *item =
+ get_struct(data, struct bookmark_list, head);
- if (item->head.list_entry.next) del_from_list(&item->head);
+ if (item->head.list_entry.next)
+ del_from_list(&item->head);
free(item->url);
free(item->title);
free(item);
}
-static int substr_utf8(unsigned char *string, unsigned char *substr)
+static int
+substr_utf8(unsigned char *string, unsigned char *substr)
{
int r;
string = unicode_upcase_string(string);
@@ -407,7 +434,8 @@ static int substr_utf8(unsigned char *string, unsigned char *substr)
return r;
}
-static int test_entry(struct list *e, unsigned char *str)
+static int
+test_entry(struct list *e, unsigned char *str)
{
struct bookmark_list *list = get_struct(e, struct bookmark_list, head);
if (substr_utf8(list->title, str))
@@ -415,7 +443,8 @@ static int test_entry(struct list *e, unsigned char *str)
return casestrstr(list->url, str);
}
-static struct list *bookmark_find_item(struct list *s, unsigned char *str, int direction)
+static struct list *
+bookmark_find_item(struct list *s, unsigned char *str, int direction)
{
struct list *e;
@@ -435,20 +464,24 @@ static struct list *bookmark_find_item(struct list *s, unsigned char *str, int d
return NULL;
}
-/* returns previous item in the same folder and with same the depth, or father if there's no previous item */
+/* returns previous item in the same folder and with same the depth, or father
+ * if there's no previous item */
/* we suppose that previous items have correct pointer fotr */
-static struct list *previous_on_this_level(struct list *item)
+static struct list *
+previous_on_this_level(struct list *item)
{
struct list *p;
- for (p = list_prev(item); p->depth > item->depth; p = p->fotr);
+ for (p = list_prev(item); p->depth > item->depth; p = p->fotr)
+ ;
return p;
}
/* create new bookmark at the end of the list */
/* if url is NULL, create folder */
/* both strings are null terminated */
-static void add_bookmark(unsigned char *title, unsigned char *url, int depth)
+static void
+add_bookmark(unsigned char *title, unsigned char *url, int depth)
{
struct bookmark_list *b;
struct list *p;
@@ -488,7 +521,8 @@ static void add_bookmark(unsigned char *title, unsigned char *url, int depth)
free(dop);
}
-static void load_bookmarks(struct session *ses)
+static void
+load_bookmarks(struct session *ses)
{
unsigned char *buf;
long len;
@@ -528,21 +562,22 @@ static void load_bookmarks(struct session *ses)
p = buf;
end = buf + len;
- status = 0; /* find bookmark */
+ status = 0; /* find bookmark */
depth = 0;
d_opt = &dop;
while (1) {
unsigned char *s;
-
+
/* find start of html tag */
- for (; p < end && *p != '<'; p++);
+ for (; p < end && *p != '<'; p++)
+ ;
if (p >= end)
break;
s = p;
- if (end - p >= 2 && (p[1] == '!' || p[1]== '?')) {
- p = skip_comment(p,end);
+ if (end - p >= 2 && (p[1] == '!' || p[1] == '?')) {
+ p = skip_comment(p, end);
continue;
}
if (parse_element(p, end, &name, &namelen, &attr, &p)) {
@@ -551,29 +586,32 @@ static void load_bookmarks(struct session *ses)
}
switch (status) {
- case 0: /* <dt> or </dl> */
+ case 0: /* <dt> or </dl> */
if (namelen == 2 && !casecmp(name, cast_uchar "dt", 2))
status = 1;
- else if (namelen == 3 && !casecmp(name, cast_uchar "/dl", 3)) {
+ else if (namelen == 3
+ && !casecmp(name, cast_uchar "/dl", 3)) {
depth--;
if (depth == -1)
goto smitec;
}
continue;
- case 1: /* find "a" element */
+ case 1: /* find "a" element */
if (namelen == 1 && !casecmp(name, cast_uchar "a", 1)) {
- if (!(url = get_attr_val(attr, cast_uchar "href")))
+ if (!(url = get_attr_val(attr,
+ cast_uchar "href")))
continue;
status = 2;
title = p;
- } else if (namelen == 2 && !casecmp(name, cast_uchar "h3", 1)) {
+ } else if (namelen == 2
+ && !casecmp(name, cast_uchar "h3", 1)) {
status = 3;
title = p;
}
continue;
- case 2: /* find "/a" element */
+ case 2: /* find "/a" element */
if (namelen != 2 || casecmp(name, cast_uchar "/a", 2))
/* ignore all other elements */
continue;
@@ -583,8 +621,8 @@ static void load_bookmarks(struct session *ses)
status = 0;
continue;
- case 3: /* find "/h3" element */
- if (namelen !=3 || casecmp(name, cast_uchar "/h3", 2))
+ case 3: /* find "/h3" element */
+ if (namelen != 3 || casecmp(name, cast_uchar "/h3", 2))
/* ignore all other elements */
continue;
*s = 0;
@@ -606,23 +644,25 @@ smitec:
memset(&bookmarks_st, -1, sizeof bookmarks_st);
}
-void init_bookmarks(void)
+void
+init_bookmarks(void)
{
memset(&bookmarks_st, -1, sizeof bookmarks_st);
if (!*bookmarks_file) {
unsigned char *e;
safe_strncpy(bookmarks_file,
- links_home ? links_home : (unsigned char*)"",
- MAX_STR_LEN);
- e = cast_uchar strchr((char *) bookmarks_file, 0);
+ links_home ? links_home : (unsigned char *)"",
+ MAX_STR_LEN);
+ e = cast_uchar strchr((char *)bookmarks_file, 0);
safe_strncpy(e, cast_uchar "bookmarks.html",
- MAX_STR_LEN - (e - bookmarks_file));
+ MAX_STR_LEN - (e - bookmarks_file));
}
load_bookmarks(NULL);
}
-void reinit_bookmarks(struct session *ses, unsigned char *new_bookmarks_file)
+void
+reinit_bookmarks(struct session *ses, unsigned char *new_bookmarks_file)
{
unsigned char *buf;
if (test_list_window_in_use(&bookmark_ld, ses->term))
@@ -639,7 +679,7 @@ void reinit_bookmarks(struct session *ses, unsigned char *new_bookmarks_file)
load_bookmarks(ses);
reinit_list_window(&bookmark_ld);
} else {
- save_only:
+save_only:
safe_strncpy(bookmarks_file, new_bookmarks_file, MAX_STR_LEN);
bookmark_ld.modified = 1;
save_bookmarks(ses);
@@ -649,7 +689,8 @@ void reinit_bookmarks(struct session *ses, unsigned char *new_bookmarks_file)
/* gets str, converts all < = > & to appropriate entity
* returns allocated string with result
*/
-static unsigned char *convert_to_entity_string(unsigned char *str)
+static unsigned char *
+convert_to_entity_string(unsigned char *str)
{
unsigned char *dst, *p;
int dstl;
@@ -658,7 +699,7 @@ static unsigned char *convert_to_entity_string(unsigned char *str)
dstl = 0;
for (p = str; *p; p++)
- switch(*p) {
+ switch (*p) {
case '<':
add_to_str(&dst, &dstl, cast_uchar "<");
break;
@@ -685,7 +726,8 @@ static unsigned char *convert_to_entity_string(unsigned char *str)
}
/* writes bookmarks to disk */
-static void save_bookmarks(struct session *ses)
+static void
+save_bookmarks(struct session *ses)
{
struct list *li = NULL;
struct list_head *lli;
@@ -696,23 +738,24 @@ static void save_bookmarks(struct session *ses)
int err;
int rs;
- if (!bookmark_ld.modified)return;
+ if (!bookmark_ld.modified)
+ return;
data = init_str();
l = 0;
- add_to_str(&data, &l, cast_uchar
- "<HTML>\n"
- "<HEAD>\n"
- "<!-- This is an automatically generated file.\n"
- "It will be read and overwritten.\n"
- "Do Not Edit! -->\n"
- "<TITLE>Links bookmarks</TITLE>\n"
- "</HEAD>\n"
- "<H1>Links bookmarks</H1>\n\n"
- "<DL><P>\n");
+ add_to_str(&data, &l,
+ cast_uchar "<HTML>\n"
+ "<HEAD>\n"
+ "<!-- This is an automatically generated file.\n"
+ "It will be read and overwritten.\n"
+ "Do Not Edit! -->\n"
+ "<TITLE>Links bookmarks</TITLE>\n"
+ "</HEAD>\n"
+ "<H1>Links bookmarks</H1>\n\n"
+ "<DL><P>\n");
depth = 0;
- foreach(struct list, li, lli, bookmarks.list_entry) {
- struct bookmark_list *b = get_struct(li, struct bookmark_list,
- head);
+ foreach (struct list, li, lli, bookmarks.list_entry) {
+ struct bookmark_list *b =
+ get_struct(li, struct bookmark_list, head);
for (a = b->head.depth; a < depth; a++)
add_to_str(&data, &l, cast_uchar "</DL>\n");
depth = b->head.depth;
@@ -747,7 +790,9 @@ static void save_bookmarks(struct session *ses)
}
for (a = 0; a < depth; a++)
add_to_str(&data, &l, cast_uchar "</DL>\n");
- add_to_str(&data, &l, cast_uchar "</DL><P>\n" "</HTML>\n");
+ add_to_str(&data, &l,
+ cast_uchar "</DL><P>\n"
+ "</HTML>\n");
err = write_to_config_file(bookmarks_file, data, 1);
free(data);
if (!err)
@@ -755,10 +800,10 @@ static void save_bookmarks(struct session *ses)
else if (ses) {
unsigned char *f = stracpy(bookmarks_file);
msg_box(ses->term, getml(f, NULL), TEXT_(T_BOOKMARK_ERROR),
- AL_CENTER, TEXT_(T_UNABLE_TO_WRITE_TO_BOOKMARK_FILE),
- cast_uchar " ", f, cast_uchar ": ", get_err_msg(err),
- MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null,
- B_ENTER | B_ESC);
+ AL_CENTER, TEXT_(T_UNABLE_TO_WRITE_TO_BOOKMARK_FILE),
+ cast_uchar " ", f, cast_uchar ": ", get_err_msg(err),
+ MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null,
+ B_ENTER | B_ESC);
}
EINTRLOOP(rs, stat(cast_const_char bookmarks_file, &bookmarks_st));
@@ -766,15 +811,17 @@ static void save_bookmarks(struct session *ses)
memset(&bookmarks_st, -1, sizeof bookmarks_st);
}
-void menu_bookmark_manager(struct terminal *term, void *fcp, void *ses_)
+void
+menu_bookmark_manager(struct terminal *term, void *fcp, void *ses_)
{
struct session *ses = (struct session *)ses_;
struct stat st;
int rs;
EINTRLOOP(rs, stat(cast_const_char bookmarks_file, &st));
- if (!rs && (st.st_ctime != bookmarks_st.st_ctime
- || st.st_mtime != bookmarks_st.st_mtime
- || st.st_size != bookmarks_st.st_size)) {
+ if (!rs
+ && (st.st_ctime != bookmarks_st.st_ctime
+ || st.st_mtime != bookmarks_st.st_mtime
+ || st.st_size != bookmarks_st.st_size)) {
if (!test_list_window_in_use(&bookmark_ld, NULL)) {
free_bookmarks();
load_bookmarks(ses);
diff --git a/cache.c b/cache.c
@@ -10,20 +10,22 @@
#include "links.h"
-static struct list_head cache = {&cache, &cache};
+static struct list_head cache = { &cache, &cache };
static int cache_size;
static tcount cache_count = 1;
static void *cache_root;
-static int ce_compare(const void *p1, const void *p2)
+static int
+ce_compare(const void *p1, const void *p2)
{
if (p1 == p2)
return 0;
return strcmp(p1, p2);
}
-static void cache_add_to_tree(struct cache_entry *e)
+static void
+cache_add_to_tree(struct cache_entry *e)
{
void **p;
@@ -33,10 +35,12 @@ static void cache_add_to_tree(struct cache_entry *e)
die("tsearch: %s\n", strerror(errno));
if ((unsigned char *)*p != e->url)
- internal("cache_add_to_tree: url '%s' is already present", e->url);
+ internal("cache_add_to_tree: url '%s' is already present",
+ e->url);
}
-static void cache_delete_from_tree(struct cache_entry *e)
+static void
+cache_delete_from_tree(struct cache_entry *e)
{
if (!e->url[0])
return;
@@ -45,7 +49,8 @@ static void cache_delete_from_tree(struct cache_entry *e)
internal("cache_delete_from_tree: url '%s' not found", e->url);
}
-static struct cache_entry *cache_search_tree(unsigned char *url)
+static struct cache_entry *
+cache_search_tree(unsigned char *url)
{
void **p;
@@ -55,7 +60,8 @@ static struct cache_entry *cache_search_tree(unsigned char *url)
return get_struct(*p, struct cache_entry, url);
}
-int cache_info(int type)
+int
+cache_info(int type)
{
int i = 0;
struct cache_entry *ce = NULL;
@@ -66,11 +72,11 @@ int cache_info(int type)
case CI_FILES:
return list_size(&cache);
case CI_LOCKED:
- foreach(struct cache_entry, ce, lce, cache)
+ foreach (struct cache_entry, ce, lce, cache)
i += !!ce->refcount;
return i;
case CI_LOADING:
- foreach(struct cache_entry, ce, lce, cache)
+ foreach (struct cache_entry, ce, lce, cache)
i += is_entry_used(ce);
return i;
default:
@@ -79,7 +85,8 @@ int cache_info(int type)
return 0;
}
-int decompress_info(int type)
+int
+decompress_info(int type)
{
int i = 0;
struct cache_entry *ce = NULL;
@@ -88,11 +95,11 @@ int decompress_info(int type)
case CI_BYTES:
return decompressed_cache_size;
case CI_FILES:
- foreach(struct cache_entry, ce, lce, cache)
+ foreach (struct cache_entry, ce, lce, cache)
i += !!ce->decompressed;
return i;
case CI_LOCKED:
- foreach(struct cache_entry, ce, lce, cache)
+ foreach (struct cache_entry, ce, lce, cache)
i += ce->decompressed && ce->refcount;
return i;
default:
@@ -101,7 +108,8 @@ int decompress_info(int type)
return 0;
}
-int find_in_cache(unsigned char *url, struct cache_entry **f)
+int
+find_in_cache(unsigned char *url, struct cache_entry **f)
{
struct cache_entry *e;
url = remove_proxy_prefix(url);
@@ -116,14 +124,16 @@ int find_in_cache(unsigned char *url, struct cache_entry **f)
return -1;
}
-static int get_cache_entry(unsigned char *url, struct cache_entry **f)
+static int
+get_cache_entry(unsigned char *url, struct cache_entry **f)
{
if (!find_in_cache(url, f))
return 0;
return new_cache_entry(url, f);
}
-int get_connection_cache_entry(struct connection *c)
+int
+get_connection_cache_entry(struct connection *c)
{
struct cache_entry *e;
if (get_cache_entry(c->url, &c->cache))
@@ -131,11 +141,13 @@ int get_connection_cache_entry(struct connection *c)
e = c->cache;
free(e->ip_address);
e->ip_address = NULL;
- if (!*c->socks_proxy && !is_proxy_url(c->url) && c->last_lookup_state.addr.n) {
+ if (!*c->socks_proxy && !is_proxy_url(c->url)
+ && c->last_lookup_state.addr.n) {
unsigned char *a;
unsigned char *s = init_str();
int l = 0;
- a = print_address(&c->last_lookup_state.addr.a[c->last_lookup_state.addr_index]);
+ a = print_address(&c->last_lookup_state.addr
+ .a[c->last_lookup_state.addr_index]);
if (a)
add_to_str(&s, &l, a);
if (c->last_lookup_state.addr.n > 1) {
@@ -146,10 +158,12 @@ int get_connection_cache_entry(struct connection *c)
for (i = 0; i < c->last_lookup_state.addr.n; i++) {
if (i == c->last_lookup_state.addr_index)
continue;
- a = print_address(&c->last_lookup_state.addr.a[i]);
+ a = print_address(
+ &c->last_lookup_state.addr.a[i]);
if (a) {
if (d)
- add_to_str(&s, &l, cast_uchar ", ");
+ add_to_str(&s, &l,
+ cast_uchar ", ");
add_to_str(&s, &l, a);
d = 1;
}
@@ -161,7 +175,8 @@ int get_connection_cache_entry(struct connection *c)
return 0;
}
-int new_cache_entry(unsigned char *url, struct cache_entry **f)
+int
+new_cache_entry(unsigned char *url, struct cache_entry **f)
{
struct cache_entry *e;
shrink_memory(SH_CHECK_QUOTA);
@@ -184,7 +199,8 @@ int new_cache_entry(unsigned char *url, struct cache_entry **f)
return 0;
}
-void detach_cache_entry(struct cache_entry *e)
+void
+detach_cache_entry(struct cache_entry *e)
{
cache_delete_from_tree(e);
e->url[0] = 0;
@@ -192,9 +208,13 @@ void detach_cache_entry(struct cache_entry *e)
#define sf(x) e->data_size += (x), cache_size += (int)(x)
-#define C_ALIGN(x) ((((x) + sizeof(struct fragment)) | (page_size - 1)) - sizeof(struct fragment))
+#define C_ALIGN(x) \
+ ((((x) + sizeof(struct fragment)) | (page_size - 1)) \
+ - sizeof(struct fragment))
-int add_fragment(struct cache_entry *e, off_t offset, const unsigned char *data, off_t length)
+int
+add_fragment(struct cache_entry *e, off_t offset, const unsigned char *data,
+ off_t length)
{
struct fragment *f = NULL;
struct list_head *lf;
@@ -206,10 +226,10 @@ int add_fragment(struct cache_entry *e, off_t offset, const unsigned char *data,
free_decompressed_data(e);
e->incomplete = 1;
if ((off_t)(0UL + offset + length) < 0
- || (off_t)(0UL + offset + length) < offset)
+ || (off_t)(0UL + offset + length) < offset)
return S_LARGE_FILE;
if ((off_t)(0UL + offset + (off_t)C_ALIGN(length)) < 0
- || (off_t)(0UL + offset + (off_t)C_ALIGN(length)) < offset)
+ || (off_t)(0UL + offset + (off_t)C_ALIGN(length)) < offset)
return S_LARGE_FILE;
if (e->length < offset + length)
e->length = offset + length;
@@ -225,17 +245,20 @@ int add_fragment(struct cache_entry *e, off_t offset, const unsigned char *data,
goto have_f;
}
}
- foreach(struct fragment, f, lf, e->frag) {
+ foreach (struct fragment, f, lf, e->frag) {
have_f:
if (f->offset > offset)
break;
if (f->offset <= offset && f->offset + f->length >= offset) {
- if (offset+length > f->offset + f->length) {
- if (memcmp(f->data + offset - f->offset,
- data, (size_t)(f->offset + f->length - offset)))
+ if (offset + length > f->offset + f->length) {
+ if (memcmp(f->data + offset - f->offset, data,
+ (size_t)(f->offset + f->length
+ - offset)))
trunc = 1;
- if (offset - f->offset + length <= f->real_length) {
- sf((offset + length) - (f->offset + f->length));
+ if (offset - f->offset + length
+ <= f->real_length) {
+ sf((offset + length)
+ - (f->offset + f->length));
f->length = offset - f->offset + length;
} else {
sf(-(f->offset + f->length - offset));
@@ -243,15 +266,17 @@ have_f:
lf = f->list_entry.next;
break;
}
- } else if (memcmp(f->data + offset-f->offset, data, (size_t)length)) {
+ } else if (memcmp(f->data + offset - f->offset, data,
+ (size_t)length)) {
trunc = 1;
}
- memcpy(f->data+offset - f->offset, data, (size_t)length);
+ memcpy(f->data + offset - f->offset, data,
+ (size_t)length);
goto ch_o;
}
}
if (C_ALIGN(length) > INT_MAX - sizeof(struct fragment)
- || C_ALIGN(length) < 0)
+ || C_ALIGN(length) < 0)
overalloc();
ca = C_ALIGN(length);
if (ca > INT_MAX - (int)sizeof(struct fragment) || ca < 0)
@@ -264,24 +289,33 @@ have_f:
memcpy(nf->data, data, (size_t)length);
add_before_list_entry(lf, &nf->list_entry);
f = nf;
- ch_o:
- while (f->list_entry.next != &e->frag
- && f->offset + f->length > list_struct(f->list_entry.next, struct fragment)->offset) {
- struct fragment *next = list_struct(f->list_entry.next, struct fragment);
+ch_o:
+ while (
+ f->list_entry.next != &e->frag
+ && f->offset + f->length
+ > list_struct(f->list_entry.next, struct fragment)->offset) {
+ struct fragment *next =
+ list_struct(f->list_entry.next, struct fragment);
if (f->offset + f->length < next->offset + next->length) {
f = xrealloc(f, sizeof(struct fragment)
- + (size_t)(next->offset - f->offset
- + next->length));
+ + (size_t)(next->offset - f->offset
+ + next->length));
fix_list_after_realloc(f);
- if (memcmp(f->data + next->offset - f->offset,
- next->data, (size_t)(f->offset + f->length - next->offset)))
+ if (memcmp(
+ f->data + next->offset - f->offset, next->data,
+ (size_t)(f->offset + f->length - next->offset)))
trunc = 1;
- memcpy(f->data + f->length, next->data + f->offset + f->length - next->offset, (size_t)(next->offset + next->length - f->offset - f->length));
+ memcpy(f->data + f->length,
+ next->data + f->offset + f->length
+ - next->offset,
+ (size_t)(next->offset + next->length - f->offset
+ - f->length));
sf(next->offset + next->length - f->offset - f->length);
- f->length = f->real_length = next->offset + next->length - f->offset;
+ f->length = f->real_length =
+ next->offset + next->length - f->offset;
} else if (memcmp(f->data + next->offset - f->offset,
- next->data, (size_t)next->length))
- trunc = 1;
+ next->data, (size_t)next->length))
+ trunc = 1;
del_from_list(next);
sf(-next->length);
free(next);
@@ -295,7 +329,8 @@ have_f:
return 0;
}
-int defrag_entry(struct cache_entry *e)
+int
+defrag_entry(struct cache_entry *e)
{
struct fragment *f, *n;
struct list_head *g, *h;
@@ -305,20 +340,22 @@ int defrag_entry(struct cache_entry *e)
f = list_struct(e->frag.next, struct fragment);
if (f->offset)
return 0;
- for (g = f->list_entry.next; g != &e->frag
- && list_struct(g, struct fragment)->offset
- <= list_struct(g->prev, struct fragment)->offset
- + list_struct(g->prev, struct fragment)->length; g = g->next)
- if (list_struct(g, struct fragment)->offset
- < list_struct(g->prev, struct fragment)->offset
- + list_struct(g->prev, struct fragment)->length) {
- internal("fragments overlay");
- return S_INTERNAL;
- }
+ for (g = f->list_entry.next;
+ g != &e->frag
+ && list_struct(g, struct fragment)->offset
+ <= list_struct(g->prev, struct fragment)->offset
+ + list_struct(g->prev, struct fragment)->length;
+ g = g->next)
+ if (list_struct(g, struct fragment)->offset
+ < list_struct(g->prev, struct fragment)->offset
+ + list_struct(g->prev, struct fragment)->length) {
+ internal("fragments overlay");
+ return S_INTERNAL;
+ }
if (g == f->list_entry.next) {
if (f->length != f->real_length) {
f = xrealloc(f, sizeof(struct fragment)
- + (size_t)f->length);
+ + (size_t)f->length);
if (f) {
f->real_length = f->length;
fix_list_after_realloc(f);
@@ -327,8 +364,11 @@ int defrag_entry(struct cache_entry *e)
return 0;
}
for (l = 0, h = &f->list_entry; h != g; h = h->next) {
- if ((off_t)(0UL + l + list_struct(h, struct fragment)->length) < 0
- || (off_t)(0UL + l + list_struct(h, struct fragment)->length) < l)
+ if ((off_t)(0UL + l + list_struct(h, struct fragment)->length)
+ < 0
+ || (off_t)(0UL + l
+ + list_struct(h, struct fragment)->length)
+ < l)
return S_LARGE_FILE;
l += list_struct(h, struct fragment)->length;
}
@@ -350,7 +390,8 @@ int defrag_entry(struct cache_entry *e)
return 0;
}
-void truncate_entry(struct cache_entry *e, off_t off, int final)
+void
+truncate_entry(struct cache_entry *e, off_t off, int final)
{
int modified = final == 2;
struct fragment *f = NULL, *g;
@@ -359,7 +400,7 @@ void truncate_entry(struct cache_entry *e, off_t off, int final)
e->length = off;
e->incomplete = 1;
}
- foreach(struct fragment, f, lf, e->frag) {
+ foreach (struct fragment, f, lf, e->frag) {
if (f->offset >= off) {
modified = 1;
sf(-f->length);
@@ -374,7 +415,7 @@ void truncate_entry(struct cache_entry *e, off_t off, int final)
f->length = off - f->offset;
if (final) {
g = xrealloc(f, sizeof(struct fragment)
- + (size_t)f->length);
+ + (size_t)f->length);
if (g) {
f = g;
fix_list_after_realloc(f);
@@ -391,13 +432,14 @@ void truncate_entry(struct cache_entry *e, off_t off, int final)
}
}
-void free_entry_to(struct cache_entry *e, off_t off)
+void
+free_entry_to(struct cache_entry *e, off_t off)
{
struct fragment *f = NULL;
struct list_head *lf;
e->incomplete = 1;
free_decompressed_data(e);
- foreach(struct fragment, f, lf, e->frag) {
+ foreach (struct fragment, f, lf, e->frag) {
if (f->offset + f->length <= off) {
sf(-f->length);
lf = lf->prev;
@@ -406,28 +448,30 @@ void free_entry_to(struct cache_entry *e, off_t off)
} else if (f->offset < off) {
sf(f->offset - off);
memmove(f->data, f->data + (off - f->offset),
- (size_t)(f->length -= off - f->offset));
+ (size_t)(f->length -= off - f->offset));
f->offset = off;
} else
break;
}
}
-void delete_entry_content(struct cache_entry *e)
+void
+delete_entry_content(struct cache_entry *e)
{
truncate_entry(e, 0, 2);
free(e->last_modified);
e->last_modified = NULL;
}
-void trim_cache_entry(struct cache_entry *e)
+void
+trim_cache_entry(struct cache_entry *e)
{
struct fragment *f = NULL, *nf;
struct list_head *lf;
- foreach(struct fragment, f, lf, e->frag) {
+ foreach (struct fragment, f, lf, e->frag) {
if (f->length != f->real_length) {
nf = xrealloc(f, sizeof(struct fragment)
- + (size_t)f->length);
+ + (size_t)f->length);
if (nf) {
f = nf;
fix_list_after_realloc(f);
@@ -438,7 +482,8 @@ void trim_cache_entry(struct cache_entry *e)
}
}
-void delete_cache_entry(struct cache_entry *e)
+void
+delete_cache_entry(struct cache_entry *e)
{
if (e->refcount)
internal("deleting locked cache entry");
@@ -453,7 +498,8 @@ void delete_cache_entry(struct cache_entry *e)
free(e);
}
-static int shrink_file_cache(int u)
+static int
+shrink_file_cache(int u)
{
int r = 0;
struct cache_entry *e = NULL, *f = NULL;
@@ -462,13 +508,13 @@ static int shrink_file_cache(int u)
int ccs = 0, ccs2 = 0;
if (u == SH_CHECK_QUOTA
- && cache_size + decompressed_cache_size <= memory_cache_size)
+ && cache_size + decompressed_cache_size <= memory_cache_size)
goto ret;
- foreachback(struct cache_entry, e, le, cache) {
+ foreachback (struct cache_entry, e, le, cache) {
if (e->refcount || is_entry_used(e)) {
if (ncs < e->data_size)
internal("cache_size underflow: %d, %d", ncs,
- e->data_size);
+ e->data_size);
ncs -= e->data_size;
} else if (u == SH_FREE_SOMETHING) {
if (e->decompressed_len)
@@ -479,7 +525,8 @@ static int shrink_file_cache(int u)
goto ret;
}
if (!e->refcount && e->decompressed_len
- && cache_size + decompressed_cache_size > memory_cache_size) {
+ && cache_size + decompressed_cache_size
+ > memory_cache_size) {
free_decompressed_data(e);
r = 1;
}
@@ -487,18 +534,20 @@ static int shrink_file_cache(int u)
ccs2 += e->decompressed_len;
}
if (ccs != cache_size) {
- internal("cache size badly computed: %d != %d", cache_size, ccs);
+ internal("cache size badly computed: %d != %d", cache_size,
+ ccs);
cache_size = ccs;
}
if (ccs2 != decompressed_cache_size) {
internal("decompressed cache size badly computed: %d != %d",
- decompressed_cache_size, ccs2);
+ decompressed_cache_size, ccs2);
decompressed_cache_size = ccs2;
}
if (u == SH_CHECK_QUOTA && ncs <= memory_cache_size)
goto ret;
- foreachback(struct cache_entry, e, le, cache) {
- if (u == SH_CHECK_QUOTA && ncs <= memory_cache_size * MEMORY_CACHE_GC_PERCENT)
+ foreachback (struct cache_entry, e, le, cache) {
+ if (u == SH_CHECK_QUOTA
+ && ncs <= memory_cache_size * MEMORY_CACHE_GC_PERCENT)
goto g;
if (e->refcount || is_entry_used(e)) {
e->tgc = 0;
@@ -506,28 +555,31 @@ static int shrink_file_cache(int u)
}
e->tgc = 1;
if (ncs < (int)e->data_size) {
- internal("cache_size underflow: %d, %d", ncs, e->data_size);
+ internal("cache_size underflow: %d, %d", ncs,
+ e->data_size);
}
ncs -= e->data_size;
}
if (ncs)
- internal("cache_size(%d) is larger than size of all objects(%d)",
- cache_size, (cache_size - ncs));
+ internal(
+ "cache_size(%d) is larger than size of all objects(%d)",
+ cache_size, (cache_size - ncs));
g:
if (le->next == &cache)
goto ret;
le = le->next;
if (u == SH_CHECK_QUOTA) {
- foreachfrom(struct cache_entry, f, lf, cache, le) {
+ foreachfrom (struct cache_entry, f, lf, cache, le) {
if (f->data_size
- && ncs + f->data_size
- <= memory_cache_size * MEMORY_CACHE_GC_PERCENT) {
+ && ncs + f->data_size
+ <= memory_cache_size
+ * MEMORY_CACHE_GC_PERCENT) {
ncs += f->data_size;
f->tgc = 0;
}
}
}
- foreachfrom(struct cache_entry, f, lf, cache, le) {
+ foreachfrom (struct cache_entry, f, lf, cache, le) {
if (f->tgc) {
lf = lf->prev;
delete_cache_entry(f);
@@ -538,7 +590,8 @@ ret:
return r | (list_empty(cache) ? ST_CACHE_EMPTY : 0);
}
-void init_cache(void)
+void
+init_cache(void)
{
register_cache_upcall(shrink_file_cache, 0, cast_uchar "file");
}
diff --git a/charsets.c b/charsets.c
@@ -10,7 +10,7 @@
struct codepage_desc {
const char *name;
- const char * const *aliases;
+ const char *const *aliases;
};
#include "codepage.inc"
@@ -18,51 +18,51 @@ struct codepage_desc {
#include "upcase.inc"
static const unsigned char strings[256][2] = {
- "\000", "\001", "\002", "\003", "\004", "\005", "\006", "\007",
- "\010", "\011", "\012", "\013", "\014", "\015", "\016", "\017",
- "\020", "\021", "\022", "\023", "\024", "\025", "\026", "\033",
- "\030", "\031", "\032", "\033", "\034", "\035", "\036", "\033",
- "\040", "\041", "\042", "\043", "\044", "\045", "\046", "\047",
- "\050", "\051", "\052", "\053", "\054", "\055", "\056", "\057",
- "\060", "\061", "\062", "\063", "\064", "\065", "\066", "\067",
- "\070", "\071", "\072", "\073", "\074", "\075", "\076", "\077",
- "\100", "\101", "\102", "\103", "\104", "\105", "\106", "\107",
- "\110", "\111", "\112", "\113", "\114", "\115", "\116", "\117",
- "\120", "\121", "\122", "\123", "\124", "\125", "\126", "\127",
- "\130", "\131", "\132", "\133", "\134", "\135", "\136", "\137",
- "\140", "\141", "\142", "\143", "\144", "\145", "\146", "\147",
- "\150", "\151", "\152", "\153", "\154", "\155", "\156", "\157",
- "\160", "\161", "\162", "\163", "\164", "\165", "\166", "\167",
- "\170", "\171", "\172", "\173", "\174", "\175", "\176", "\177",
- "\200", "\201", "\202", "\203", "\204", "\205", "\206", "\207",
- "\210", "\211", "\212", "\213", "\214", "\215", "\216", "\217",
- "\220", "\221", "\222", "\223", "\224", "\225", "\226", "\227",
- "\230", "\231", "\232", "\233", "\234", "\235", "\236", "\237",
- "\240", "\241", "\242", "\243", "\244", "\245", "\246", "\247",
- "\250", "\251", "\252", "\253", "\254", "\255", "\256", "\257",
- "\260", "\261", "\262", "\263", "\264", "\265", "\266", "\267",
- "\270", "\271", "\272", "\273", "\274", "\275", "\276", "\277",
- "\300", "\301", "\302", "\303", "\304", "\305", "\306", "\307",
- "\310", "\311", "\312", "\313", "\314", "\315", "\316", "\317",
- "\320", "\321", "\322", "\323", "\324", "\325", "\326", "\327",
- "\330", "\331", "\332", "\333", "\334", "\335", "\336", "\337",
- "\340", "\341", "\342", "\343", "\344", "\345", "\346", "\347",
- "\350", "\351", "\352", "\353", "\354", "\355", "\356", "\357",
- "\360", "\361", "\362", "\363", "\364", "\365", "\366", "\367",
- "\370", "\371", "\372", "\373", "\374", "\375", "\376", "\377",
+ "\000", "\001", "\002", "\003", "\004", "\005", "\006", "\007", "\010",
+ "\011", "\012", "\013", "\014", "\015", "\016", "\017", "\020", "\021",
+ "\022", "\023", "\024", "\025", "\026", "\033", "\030", "\031", "\032",
+ "\033", "\034", "\035", "\036", "\033", "\040", "\041", "\042", "\043",
+ "\044", "\045", "\046", "\047", "\050", "\051", "\052", "\053", "\054",
+ "\055", "\056", "\057", "\060", "\061", "\062", "\063", "\064", "\065",
+ "\066", "\067", "\070", "\071", "\072", "\073", "\074", "\075", "\076",
+ "\077", "\100", "\101", "\102", "\103", "\104", "\105", "\106", "\107",
+ "\110", "\111", "\112", "\113", "\114", "\115", "\116", "\117", "\120",
+ "\121", "\122", "\123", "\124", "\125", "\126", "\127", "\130", "\131",
+ "\132", "\133", "\134", "\135", "\136", "\137", "\140", "\141", "\142",
+ "\143", "\144", "\145", "\146", "\147", "\150", "\151", "\152", "\153",
+ "\154", "\155", "\156", "\157", "\160", "\161", "\162", "\163", "\164",
+ "\165", "\166", "\167", "\170", "\171", "\172", "\173", "\174", "\175",
+ "\176", "\177", "\200", "\201", "\202", "\203", "\204", "\205", "\206",
+ "\207", "\210", "\211", "\212", "\213", "\214", "\215", "\216", "\217",
+ "\220", "\221", "\222", "\223", "\224", "\225", "\226", "\227", "\230",
+ "\231", "\232", "\233", "\234", "\235", "\236", "\237", "\240", "\241",
+ "\242", "\243", "\244", "\245", "\246", "\247", "\250", "\251", "\252",
+ "\253", "\254", "\255", "\256", "\257", "\260", "\261", "\262", "\263",
+ "\264", "\265", "\266", "\267", "\270", "\271", "\272", "\273", "\274",
+ "\275", "\276", "\277", "\300", "\301", "\302", "\303", "\304", "\305",
+ "\306", "\307", "\310", "\311", "\312", "\313", "\314", "\315", "\316",
+ "\317", "\320", "\321", "\322", "\323", "\324", "\325", "\326", "\327",
+ "\330", "\331", "\332", "\333", "\334", "\335", "\336", "\337", "\340",
+ "\341", "\342", "\343", "\344", "\345", "\346", "\347", "\350", "\351",
+ "\352", "\353", "\354", "\355", "\356", "\357", "\360", "\361", "\362",
+ "\363", "\364", "\365", "\366", "\367", "\370", "\371", "\372", "\373",
+ "\374", "\375", "\376", "\377",
};
-unsigned char *u2cp(int u)
+unsigned char *
+u2cp(int u)
{
return encode_utf_8(u);
}
static unsigned char utf_buffer[7];
-unsigned char *encode_utf_8(int u)
+unsigned char *
+encode_utf_8(int u)
{
memset(utf_buffer, 0, 7);
- if (u < 0);
+ if (u < 0)
+ ;
else if (u < 0x80)
utf_buffer[0] = (unsigned char)u;
else if (u < 0x800) {
@@ -97,7 +97,8 @@ unsigned char *encode_utf_8(int u)
static struct conv_table utf_table[256];
static int utf_table_init = 1;
-static void free_utf_table(void)
+static void
+free_utf_table(void)
{
int i;
for (i = 128; i < 256; i += 4) {
@@ -108,7 +109,8 @@ static void free_utf_table(void)
}
}
-static struct conv_table *get_translation_table_to_utf_8(int from)
+static struct conv_table *
+get_translation_table_to_utf_8(int from)
{
int i;
static int lfr = -1;
@@ -119,9 +121,12 @@ static struct conv_table *get_translation_table_to_utf_8(int from)
memset(utf_table, 0, sizeof(struct conv_table) * 256);
for (i = 0; i < 128; i += 4) {
utf_table[i].u.str = (unsigned char *)strings[i];
- utf_table[i + 1].u.str = (unsigned char *)strings[i + 1];
- utf_table[i + 2].u.str = (unsigned char *)strings[i + 2];
- utf_table[i + 3].u.str = (unsigned char *)strings[i + 3];
+ utf_table[i + 1].u.str =
+ (unsigned char *)strings[i + 1];
+ utf_table[i + 2].u.str =
+ (unsigned char *)strings[i + 2];
+ utf_table[i + 3].u.str =
+ (unsigned char *)strings[i + 3];
}
utf_table_init = 0;
} else
@@ -136,21 +141,16 @@ static struct conv_table *get_translation_table_to_utf_8(int from)
}
unsigned char utf_8_1[256] = {
- 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 6, 6,
};
@@ -158,7 +158,8 @@ static const unsigned min_utf_8[8] = {
0, 0x4000000, 0x200000, 0x10000, 0x800, 0x80, 0x100, 0x1,
};
-unsigned get_utf_8(unsigned char **s)
+unsigned
+get_utf_8(unsigned char **s)
{
unsigned v, min, c;
int l;
@@ -182,20 +183,23 @@ unsigned get_utf_8(unsigned char **s)
return v;
}
-void free_conv_table(void)
+void
+free_conv_table(void)
{
if (!utf_table_init)
free_utf_table();
}
-struct conv_table *get_translation_table(const int from, const int to)
+struct conv_table *
+get_translation_table(const int from, const int to)
{
if (from == -1 || to == -1)
return NULL;
return get_translation_table_to_utf_8(from);
}
-static inline int xxstrcmp(unsigned char *s1, unsigned char *s2, int l2)
+static inline int
+xxstrcmp(unsigned char *s1, unsigned char *s2, int l2)
{
while (l2) {
if (*s1 > *s2)
@@ -209,7 +213,8 @@ static inline int xxstrcmp(unsigned char *s1, unsigned char *s2, int l2)
return !!*s1;
}
-int get_entity_number(unsigned char *st, int l)
+int
+get_entity_number(unsigned char *st, int l)
{
int n = 0;
unsigned char c;
@@ -245,7 +250,8 @@ int get_entity_number(unsigned char *st, int l)
return n;
}
-unsigned char *get_entity_string(unsigned char *st, int l)
+unsigned char *
+get_entity_string(unsigned char *st, int l)
{
int n, c, m, s, e;
if (l <= 0)
@@ -263,8 +269,10 @@ unsigned char *get_entity_string(unsigned char *st, int l)
n = entities[m].c;
goto f;
}
- if (c > 0) e = m - 1;
- else s = m + 1;
+ if (c > 0)
+ e = m - 1;
+ else
+ s = m + 1;
}
return NULL;
f:;
@@ -273,7 +281,9 @@ f:;
return u2cp(n);
}
-unsigned char *convert_string(struct conv_table *ct, unsigned char *c, int l, struct document_options *dopt)
+unsigned char *
+convert_string(struct conv_table *ct, unsigned char *c, int l,
+ struct document_options *dopt)
{
unsigned char *buffer, *e = NULL;
struct conv_table *t;
@@ -314,8 +324,10 @@ decode:
pp = i + 1;
} else {
i = pp + 1;
- if (!dopt || dopt->plain) goto put_c;
- while (i < l && !is_entity_terminator(c[i])) i++;
+ if (!dopt || dopt->plain)
+ goto put_c;
+ while (i < l && !is_entity_terminator(c[i]))
+ i++;
if (!(e = get_entity_string(&c[pp + 1], i - pp - 1)))
goto put_c;
pp = i + (i < l && c[i] == ';');
@@ -344,7 +356,8 @@ decode:
return buffer;
}
-unsigned char *convert(int from, int to, unsigned char *c, struct document_options *dopt)
+unsigned char *
+convert(int from, int to, unsigned char *c, struct document_options *dopt)
{
unsigned char *cc;
struct conv_table *ct;
@@ -359,21 +372,24 @@ need_table:
return convert_string(ct, c, strlen((char *)c), dopt);
}
-unsigned char *get_cp_name(int index)
+unsigned char *
+get_cp_name(int index)
{
if (index < 0)
return (unsigned char *)"none";
return (unsigned char *)codepages[index].name;
}
-unsigned char *get_cp_mime_name(int index)
+unsigned char *
+get_cp_mime_name(int index)
{
if (!codepages[index].aliases)
return NULL;
return (unsigned char *)codepages[index].aliases[0];
}
-unsigned uni_locase(unsigned ch)
+unsigned
+uni_locase(unsigned ch)
{
return towlower(ch);
}
@@ -381,12 +397,14 @@ unsigned uni_locase(unsigned ch)
#define UP_EQUAL(a, b) unicode_upcase[a].o == (b)
#define UP_ABOVE(a, b) unicode_upcase[a].o > (b)
-unsigned charset_upcase(unsigned ch, int cp)
+unsigned
+charset_upcase(unsigned ch, int cp)
{
return towupper(ch);
}
-void charset_upcase_string(unsigned char **chp, int cp)
+void
+charset_upcase_string(unsigned char **chp, int cp)
{
unsigned char *ch = *chp;
ch = unicode_upcase_string(ch);
@@ -394,7 +412,8 @@ void charset_upcase_string(unsigned char **chp, int cp)
*chp = ch;
}
-unsigned char *unicode_upcase_string(unsigned char *ch)
+unsigned char *
+unicode_upcase_string(unsigned char *ch)
{
unsigned char *r = init_str();
unsigned int c;
@@ -409,7 +428,8 @@ unsigned char *unicode_upcase_string(unsigned char *ch)
return r;
}
-unsigned char *to_utf8_upcase(unsigned char *str, int cp)
+unsigned char *
+to_utf8_upcase(unsigned char *str, int cp)
{
unsigned char *str1, *str2;
str1 = convert(cp, 0, str, NULL);
@@ -418,7 +438,8 @@ unsigned char *to_utf8_upcase(unsigned char *str, int cp)
return str2;
}
-int compare_case_utf8(unsigned char *u1, unsigned char *u2)
+int
+compare_case_utf8(unsigned char *u1, unsigned char *u2)
{
unsigned char *x1, *uu1 = u1;
unsigned c1, c2;
@@ -429,7 +450,8 @@ int compare_case_utf8(unsigned char *u1, unsigned char *u2)
return (int)(u1 - uu1);
skip_discr:
GET_UTF_8(u1, c1);
- BIN_SEARCH(array_elements(unicode_upcase), UP_EQUAL, UP_ABOVE, c1, cc1);
+ BIN_SEARCH(array_elements(unicode_upcase), UP_EQUAL, UP_ABOVE,
+ c1, cc1);
if (cc1 != -1)
c1 = unicode_upcase[cc1].n;
if (c1 == 0xad)
@@ -440,7 +462,8 @@ skip_discr:
do {
x1 = u1;
GET_UTF_8(u1, c1);
- BIN_SEARCH(array_elements(unicode_upcase), UP_EQUAL, UP_ABOVE, c1, cc1);
+ BIN_SEARCH(array_elements(unicode_upcase),
+ UP_EQUAL, UP_ABOVE, c1, cc1);
if (cc1 >= 0)
c1 = unicode_upcase[cc1].n;
} while (c1 == ' ');
diff --git a/compress.c b/compress.c
@@ -4,15 +4,21 @@
int decompressed_cache_size = 0;
-static int display_error(struct terminal *term, unsigned char *msg, int *errp)
+static int
+display_error(struct terminal *term, unsigned char *msg, int *errp)
{
- if (errp) *errp = 1;
- if (!term) return 0;
- if (!errp) if (find_msg_box(term, msg, NULL, NULL)) return 0;
+ if (errp)
+ *errp = 1;
+ if (!term)
+ return 0;
+ if (!errp)
+ if (find_msg_box(term, msg, NULL, NULL))
+ return 0;
return 1;
}
-static void decoder_memory_init(unsigned char **p, size_t *size, off_t init_length)
+static void
+decoder_memory_init(unsigned char **p, size_t *size, off_t init_length)
{
if (init_length > 0 && init_length < INT_MAX)
*size = (int)init_length;
@@ -21,7 +27,8 @@ static void decoder_memory_init(unsigned char **p, size_t *size, off_t init_leng
*p = xmalloc(*size);
}
-static int decoder_memory_expand(unsigned char **p, size_t size, size_t *addsize)
+static int
+decoder_memory_expand(unsigned char **p, size_t size, size_t *addsize)
{
size_t add = size / 4 + 1;
if (size + add < size) {
@@ -35,10 +42,13 @@ static int decoder_memory_expand(unsigned char **p, size_t size, size_t *addsize
return 0;
}
-static void decompress_error(struct terminal *term, struct cache_entry *ce, unsigned char *lib, unsigned char *msg, int *errp)
+static void
+decompress_error(struct terminal *term, struct cache_entry *ce,
+ unsigned char *lib, unsigned char *msg, int *errp)
{
unsigned char *u, *server;
- if ((u = parse_http_header(ce->head, cast_uchar "Content-Encoding", NULL))) {
+ if ((u = parse_http_header(ce->head, cast_uchar "Content-Encoding",
+ NULL))) {
free(u);
if ((server = get_host_name(ce->url))) {
add_blacklist_entry(server, BL_NO_COMPRESSION);
@@ -49,12 +59,13 @@ static void decompress_error(struct terminal *term, struct cache_entry *ce, unsi
return;
u = display_url(term, ce->url, 1);
msg_box(term, getml(u, NULL), TEXT_(T_DECOMPRESSION_ERROR), AL_CENTER,
- TEXT_(T_ERROR_DECOMPRESSING_), u, TEXT_(T__wITH_), lib,
- cast_uchar ": ", msg, MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL),
- msg_box_null, B_ENTER | B_ESC);
+ TEXT_(T_ERROR_DECOMPRESSING_), u, TEXT_(T__wITH_), lib,
+ cast_uchar ": ", msg, MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL),
+ msg_box_null, B_ENTER | B_ESC);
}
-static int decode_gzip(struct terminal *term, struct cache_entry *ce, int defl, int *errp)
+static int
+decode_gzip(struct terminal *term, struct cache_entry *ce, int defl, int *errp)
{
unsigned char err;
unsigned char memory_error;
@@ -105,26 +116,30 @@ init_failed:
goto init_failed;
}
decompress_error(term, ce, cast_uchar "zlib",
- z.msg ? (unsigned char *)z.msg
- : (unsigned char *)"Invalid parameter", errp);
+ z.msg ? (unsigned char *)z.msg
+ : (unsigned char *)"Invalid parameter",
+ errp);
err = 1;
goto after_inflateend;
case Z_VERSION_ERROR:
decompress_error(term, ce, cast_uchar "zlib",
- z.msg ? (unsigned char *)z.msg
- : (unsigned char *)"Bad zlib version", errp);
+ z.msg ? (unsigned char *)z.msg
+ : (unsigned char *)"Bad zlib version",
+ errp);
err = 1;
goto after_inflateend;
default:
- decompress_error(term, ce, cast_uchar "zlib",
- z.msg ? (unsigned char *)z.msg
- : (unsigned char *)"Unknown return value on inflateInit2",
- errp);
+ decompress_error(
+ term, ce, cast_uchar "zlib",
+ z.msg ? (unsigned char *)z.msg
+ : (unsigned char
+ *)"Unknown return value on inflateInit2",
+ errp);
err = 1;
goto after_inflateend;
}
offset = 0;
- foreach(struct fragment, f, lf, ce->frag) {
+ foreach (struct fragment, f, lf, ce->frag) {
if (f->offset != offset)
break;
z.next_in = f->data;
@@ -149,14 +164,15 @@ repeat_frag:
goto finish;
if (head[0] != 0x1f || head[1] != 0x8b) {
decompress_error(term, ce, cast_uchar "zlib",
- TEXT_(T_COMPRESSED_ERROR), errp);
+ TEXT_(T_COMPRESSED_ERROR),
+ errp);
err = 1;
goto finish;
}
if (head[2] != 8 || head[3] & 0xe0) {
- decompress_error(term, ce, cast_uchar "zlib",
- TEXT_(T_UNKNOWN_COMPRESSION_METHOD),
- errp);
+ decompress_error(
+ term, ce, cast_uchar "zlib",
+ TEXT_(T_UNKNOWN_COMPRESSION_METHOD), errp);
err = 1;
goto finish;
}
@@ -168,12 +184,14 @@ repeat_frag:
if (head[3] & 0x08)
do {
headlen++;
- if (headlen >= z.avail_in) goto finish;
+ if (headlen >= z.avail_in)
+ goto finish;
} while (head[headlen - 1]);
if (head[3] & 0x10)
do {
headlen++;
- if (headlen >= z.avail_in) goto finish;
+ if (headlen >= z.avail_in)
+ goto finish;
} while (head[headlen - 1]);
if (head[3] & 0x01) {
headlen += 2;
@@ -185,7 +203,7 @@ repeat_frag:
skip_gzip_header = 0;
}
r = inflate(&z, f->list_entry.next == &ce->frag ? Z_SYNC_FLUSH
- : Z_NO_FLUSH);
+ : Z_NO_FLUSH);
switch (r) {
case Z_OK:
case Z_BUF_ERROR:
@@ -194,7 +212,9 @@ repeat_frag:
r = inflateEnd(&z);
if (r != Z_OK)
goto end_failed;
- r = inflateInit2(&z, old_zlib ? -15 : defl ? 15 : 15 + 16);
+ r = inflateInit2(&z, old_zlib ? -15
+ : defl ? 15
+ : 15 + 16);
if (r != Z_OK) {
old_zlib = 0;
goto init_failed;
@@ -212,15 +232,18 @@ repeat_frag:
goto init_again;
}
decompress_error(term, ce, cast_uchar "zlib",
- z.msg ? (unsigned char *)z.msg
- : TEXT_(T_COMPRESSED_ERROR), errp);
+ z.msg ? (unsigned char *)z.msg
+ : TEXT_(T_COMPRESSED_ERROR),
+ errp);
err = 1;
goto finish;
case Z_STREAM_ERROR:
- decompress_error(term, ce, cast_uchar "zlib",
- z.msg ? (unsigned char *)z.msg
+ decompress_error(
+ term, ce, cast_uchar "zlib",
+ z.msg
+ ? (unsigned char *)z.msg
: (unsigned char *)"Internal error on inflate",
- errp);
+ errp);
err = 1;
goto finish;
case Z_MEM_ERROR:
@@ -228,10 +251,12 @@ repeat_frag:
err = 1;
goto finish;
default:
- decompress_error(term, ce, cast_uchar "zlib",
- z.msg ? (unsigned char *)z.msg
- : (unsigned char *)"Unknown return value on inflate",
- errp);
+ decompress_error(
+ term, ce, cast_uchar "zlib",
+ z.msg ? (unsigned char *)z.msg
+ : (unsigned char
+ *)"Unknown return value on inflate",
+ errp);
err = 1;
break;
}
@@ -259,10 +284,11 @@ end_failed:
case Z_OK:
break;
case Z_STREAM_ERROR:
- decompress_error(term, ce, cast_uchar "zlib",
- z.msg ? (unsigned char *)z.msg
- : (unsigned char *)"Internal error on inflateEnd",
- errp);
+ decompress_error(
+ term, ce, cast_uchar "zlib",
+ z.msg ? (unsigned char *)z.msg
+ : (unsigned char *)"Internal error on inflateEnd",
+ errp);
err = 1;
break;
case Z_MEM_ERROR:
@@ -270,11 +296,14 @@ end_failed:
err = 1;
break;
default:
- decompress_error(term, ce, cast_uchar "zlib",
- z.msg ? (unsigned char *)z.msg
- : (unsigned char *)"Unknown return value on inflateEnd", errp);
- err = 1;
- break;
+ decompress_error(
+ term, ce, cast_uchar "zlib",
+ z.msg
+ ? (unsigned char *)z.msg
+ : (unsigned char *)"Unknown return value on inflateEnd",
+ errp);
+ err = 1;
+ break;
}
after_inflateend:
if (memory_error) {
@@ -282,8 +311,9 @@ after_inflateend:
if (out_of_memory())
goto retry_after_memory_error;
decompress_error(term, ce, cast_uchar "zlib",
- z.msg ? (unsigned char *)z.msg
- : TEXT_(T_OUT_OF_MEMORY), errp);
+ z.msg ? (unsigned char *)z.msg
+ : TEXT_(T_OUT_OF_MEMORY),
+ errp);
return 1;
}
if (err && (unsigned char *)z.next_out == p) {
@@ -297,7 +327,9 @@ after_inflateend:
return 0;
}
-int get_file_by_term(struct terminal *term, struct cache_entry *ce, unsigned char **start, size_t *len, int *errp)
+int
+get_file_by_term(struct terminal *term, struct cache_entry *ce,
+ unsigned char **start, size_t *len, int *errp)
{
unsigned char *enc;
struct fragment *fr;
@@ -317,8 +349,8 @@ return_decompressed:
enc = get_content_encoding(ce->head, ce->url, 0);
if (enc) {
if (!casestrcmp(enc, cast_uchar "gzip")
- || !casestrcmp(enc, cast_uchar "x-gzip")
- || !casestrcmp(enc, cast_uchar "deflate")) {
+ || !casestrcmp(enc, cast_uchar "x-gzip")
+ || !casestrcmp(enc, cast_uchar "deflate")) {
int defl = !casestrcmp(enc, cast_uchar "deflate");
free(enc);
if (decode_gzip(term, ce, defl, errp))
@@ -334,9 +366,9 @@ uncompressed:
if (display_error(term, TEXT_(T_ERROR), errp)) {
unsigned char *u = display_url(term, ce->url, 1);
msg_box(term, getml(u, NULL), TEXT_(T_ERROR), AL_CENTER,
- TEXT_(T_ERROR_LOADING), cast_uchar " ", u,
- cast_uchar ":\n\n", msg, MSG_BOX_END, NULL, 1,
- TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ TEXT_(T_ERROR_LOADING), cast_uchar " ", u,
+ cast_uchar ":\n\n", msg, MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
}
}
if (list_empty(ce->frag))
@@ -349,7 +381,8 @@ uncompressed:
return 0;
}
-int get_file(struct object_request *o, unsigned char **start, size_t *len)
+int
+get_file(struct object_request *o, unsigned char **start, size_t *len)
{
struct terminal *term;
*start = NULL;
@@ -360,13 +393,15 @@ int get_file(struct object_request *o, unsigned char **start, size_t *len)
return get_file_by_term(term, o->ce, start, len, NULL);
}
-void free_decompressed_data(struct cache_entry *e)
+void
+free_decompressed_data(struct cache_entry *e)
{
if (e->decompressed) {
if (decompressed_cache_size < e->decompressed_len)
- internal("free_decompressed_data: decompressed_cache_size underflow %lu, %lu",
- (unsigned long)decompressed_cache_size,
- (unsigned long)e->decompressed_len);
+ internal("free_decompressed_data: "
+ "decompressed_cache_size underflow %lu, %lu",
+ (unsigned long)decompressed_cache_size,
+ (unsigned long)e->decompressed_len);
decompressed_cache_size -= e->decompressed_len;
e->decompressed_len = 0;
free(e->decompressed);
@@ -374,7 +409,8 @@ void free_decompressed_data(struct cache_entry *e)
}
}
-void add_compress_methods(unsigned char **s, int *l)
+void
+add_compress_methods(unsigned char **s, int *l)
{
add_to_str(s, l, cast_uchar "ZLIB");
#ifdef zlib_version
diff --git a/connect.c b/connect.c
@@ -14,7 +14,8 @@ static void dns_found(void *, int);
static void try_connect(struct connection *);
static void handle_socks_reply(void *);
-int socket_and_bind(int pf, unsigned char *address)
+int
+socket_and_bind(int pf, unsigned char *address)
{
int rs, s = c_socket(pf, SOCK_STREAM, IPPROTO_TCP);
@@ -34,7 +35,8 @@ int socket_and_bind(int pf, unsigned char *address)
sa.sin_family = AF_INET;
memcpy(&sa.sin_addr.s_addr, addr, 4);
sa.sin_port = htons(0);
- EINTRLOOP(rs, bind(s, (struct sockaddr *)(void *)&sa, sizeof sa));
+ EINTRLOOP(rs,
+ bind(s, (struct sockaddr *)(void *)&sa, sizeof sa));
if (rs) {
int sv_errno = errno;
EINTRLOOP(rs, close(s));
@@ -47,7 +49,8 @@ int socket_and_bind(int pf, unsigned char *address)
struct sockaddr_in6 sa;
unsigned char addr[16];
unsigned scope;
- if (numeric_ipv6_address((char *)address, (char *)addr, &scope) == -1) {
+ if (numeric_ipv6_address((char *)address, (char *)addr, &scope)
+ == -1) {
EINTRLOOP(rs, close(s));
errno = EINVAL;
return -1;
@@ -57,7 +60,8 @@ int socket_and_bind(int pf, unsigned char *address)
memcpy(&sa.sin6_addr, addr, 16);
sa.sin6_port = htons(0);
sa.sin6_scope_id = scope;
- EINTRLOOP(rs, bind(s, (struct sockaddr *)(void *)&sa, sizeof sa));
+ EINTRLOOP(rs,
+ bind(s, (struct sockaddr *)(void *)&sa, sizeof sa));
if (rs) {
int sv_errno = errno;
EINTRLOOP(rs, close(s));
@@ -75,10 +79,12 @@ int socket_and_bind(int pf, unsigned char *address)
return s;
}
-void close_socket(int *s)
+void
+close_socket(int *s)
{
int rs;
- if (*s == -1) return;
+ if (*s == -1)
+ return;
set_handlers(*s, NULL, NULL, NULL);
EINTRLOOP(rs, close(*s));
*s = -1;
@@ -95,7 +101,9 @@ struct conn_info {
char host[1];
};
-void make_connection(struct connection *c, int port, int *sock, void (*func)(struct connection *))
+void
+make_connection(struct connection *c, int port, int *sock,
+ void (*func)(struct connection *))
{
int socks_port = -1;
int as;
@@ -104,17 +112,20 @@ void make_connection(struct connection *c, int port, int *sock, void (*func)(str
struct conn_info *b;
if (*c->socks_proxy) {
p = strchr(c->socks_proxy, '@');
- if (p) p++;
- else p = c->socks_proxy;
+ if (p)
+ p++;
+ else
+ p = c->socks_proxy;
host = strdup(p);
socks_port = 1080;
if ((p = strchr(host, ':'))) {
long lp;
*p++ = 0;
- if (!*p) goto badu;
+ if (!*p)
+ goto badu;
lp = strtol(p, &p, 10);
if (*p || lp <= 0 || lp >= 65536) {
- badu:
+badu:
free(host);
setcstate(c, S_BAD_URL);
abort_connection(c);
@@ -130,7 +141,8 @@ void make_connection(struct connection *c, int port, int *sock, void (*func)(str
if (c->newconn)
internal("already making a connection");
sl = strlen(host);
- if (sl > INT_MAX - sizeof(struct conn_info)) overalloc();
+ if (sl > INT_MAX - sizeof(struct conn_info))
+ overalloc();
b = mem_calloc(sizeof(struct conn_info) + sl);
b->func = func;
b->sock = sock;
@@ -145,58 +157,62 @@ void make_connection(struct connection *c, int port, int *sock, void (*func)(str
dns_found(c, 0);
as = 0;
} else if (c->no_cache >= NC_RELOAD)
- as = find_host_no_cache(host, &b->l.addr, &c->dnsquery, dns_found, c);
+ as = find_host_no_cache(host, &b->l.addr, &c->dnsquery,
+ dns_found, c);
else
as = find_host(host, &b->l.addr, &c->dnsquery, dns_found, c);
free(host);
- if (as) setcstate(c, S_DNS);
+ if (as)
+ setcstate(c, S_DNS);
}
-static void ssl_setup_downgrade(struct connection *c)
+static void
+ssl_setup_downgrade(struct connection *c)
{
#if !defined(HAVE_NSS)
int dd = c->no_tls;
-#ifdef SSL_OP_NO_TLSv1_3
+ #ifdef SSL_OP_NO_TLSv1_3
if (dd) {
SSL_set_options(c->ssl->ssl, SSL_OP_NO_TLSv1_3);
dd--;
}
-#endif
-#ifdef SSL_OP_NO_TLSv1_2
+ #endif
+ #ifdef SSL_OP_NO_TLSv1_2
if (dd) {
SSL_set_options(c->ssl->ssl, SSL_OP_NO_TLSv1_2);
dd--;
}
-#endif
-#ifdef SSL_OP_NO_TLSv1_1
+ #endif
+ #ifdef SSL_OP_NO_TLSv1_1
if (dd) {
SSL_set_options(c->ssl->ssl, SSL_OP_NO_TLSv1_1);
dd--;
}
-#endif
-#ifdef SSL_OP_NO_TLSv1
+ #endif
+ #ifdef SSL_OP_NO_TLSv1
if (dd) {
SSL_set_options(c->ssl->ssl, SSL_OP_NO_TLSv1);
dd--;
}
-#endif
-#ifdef SSL_MODE_SEND_FALLBACK_SCSV
+ #endif
+ #ifdef SSL_MODE_SEND_FALLBACK_SCSV
if (dd != c->no_tls) {
SSL_set_mode(c->ssl->ssl, SSL_MODE_SEND_FALLBACK_SCSV);
}
-#endif
+ #endif
if (SCRUB_HEADERS) {
-#ifdef SSL_OP_NO_SSLv2
+ #ifdef SSL_OP_NO_SSLv2
SSL_set_options(c->ssl->ssl, SSL_OP_NO_SSLv2);
-#endif
-#ifdef SSL_OP_NO_SSLv3
+ #endif
+ #ifdef SSL_OP_NO_SSLv3
SSL_set_options(c->ssl->ssl, SSL_OP_NO_SSLv3);
-#endif
+ #endif
}
#endif
}
-static void ssl_downgrade_dance(struct connection *c)
+static void
+ssl_downgrade_dance(struct connection *c)
{
#if !defined(HAVE_NSS)
int downgrades = 0;
@@ -205,18 +221,18 @@ static void ssl_downgrade_dance(struct connection *c)
retry_connect(c, S_SSL_ERROR, 1);
return;
}
-#ifdef SSL_OP_NO_TLSv1_3
+ #ifdef SSL_OP_NO_TLSv1_3
downgrades++;
-#endif
-#ifdef SSL_OP_NO_TLSv1_2
+ #endif
+ #ifdef SSL_OP_NO_TLSv1_2
downgrades++;
-#endif
-#ifdef SSL_OP_NO_TLSv1_1
+ #endif
+ #ifdef SSL_OP_NO_TLSv1_1
downgrades++;
-#endif
-#ifdef SSL_OP_NO_TLSv1
+ #endif
+ #ifdef SSL_OP_NO_TLSv1
downgrades++;
-#endif
+ #endif
if (++c->no_tls <= downgrades) {
retry_connect(c, S_SSL_ERROR, 1);
} else {
@@ -228,7 +244,8 @@ static void ssl_downgrade_dance(struct connection *c)
#endif
}
-static void ssl_want_io(void *c_)
+static void
+ssl_want_io(void *c_)
{
struct connection *c = (struct connection *)c_;
struct conn_info *b = c->newconn;
@@ -236,21 +253,22 @@ static void ssl_want_io(void *c_)
set_connection_timeout(c);
switch (SSL_get_error(c->ssl->ssl, SSL_connect(c->ssl->ssl))) {
- case SSL_ERROR_NONE:
- connected_callback(c);
- break;
- case SSL_ERROR_WANT_READ:
- set_handlers(*b->sock, ssl_want_io, NULL, c);
- break;
- case SSL_ERROR_WANT_WRITE:
- set_handlers(*b->sock, NULL, ssl_want_io, c);
- break;
- default:
- ssl_downgrade_dance(c);
+ case SSL_ERROR_NONE:
+ connected_callback(c);
+ break;
+ case SSL_ERROR_WANT_READ:
+ set_handlers(*b->sock, ssl_want_io, NULL, c);
+ break;
+ case SSL_ERROR_WANT_WRITE:
+ set_handlers(*b->sock, NULL, ssl_want_io, c);
+ break;
+ default:
+ ssl_downgrade_dance(c);
}
}
-static void handle_socks(void *c_)
+static void
+handle_socks(void *c_)
{
struct connection *c = (struct connection *)c_;
struct conn_info *b = c->newconn;
@@ -265,7 +283,9 @@ static void handle_socks(void *c_)
add_chr_to_str(&command, &len, b->l.target_port);
add_bytes_to_str(&command, &len, cast_uchar "\000\000\000\001", 4);
if (strchr(c->socks_proxy, '@'))
- add_bytes_to_str(&command, &len, (unsigned char *)c->socks_proxy, strcspn(c->socks_proxy, "@"));
+ add_bytes_to_str(&command, &len,
+ (unsigned char *)c->socks_proxy,
+ strcspn(c->socks_proxy, "@"));
add_chr_to_str(&command, &len, 0);
if (!(host = get_host_name(c->url))) {
free(command);
@@ -283,7 +303,8 @@ static void handle_socks(void *c_)
retry_connection(c);
return;
}
- EINTRLOOP(wr, (int)write(*b->sock, command + b->socks_byte_count, len - b->socks_byte_count));
+ EINTRLOOP(wr, (int)write(*b->sock, command + b->socks_byte_count,
+ len - b->socks_byte_count));
free(command);
if (wr <= 0) {
setcstate(c, wr ? get_error_from_errno(errno) : S_CANT_WRITE);
@@ -301,63 +322,71 @@ static void handle_socks(void *c_)
}
}
-static void handle_socks_reply(void *c_)
+static void
+handle_socks_reply(void *c_)
{
struct connection *c = (struct connection *)c_;
struct conn_info *b = c->newconn;
int rd;
set_connection_timeout(c);
- EINTRLOOP(rd, (int)read(*b->sock, b->socks_reply + b->socks_byte_count, sizeof b->socks_reply - b->socks_byte_count));
+ EINTRLOOP(rd, (int)read(*b->sock, b->socks_reply + b->socks_byte_count,
+ sizeof b->socks_reply - b->socks_byte_count));
if (rd <= 0) {
setcstate(c, rd ? get_error_from_errno(errno) : S_CANT_READ);
retry_connection(c);
return;
}
b->socks_byte_count += rd;
- if (b->socks_byte_count < (int)sizeof b->socks_reply) return;
+ if (b->socks_byte_count < (int)sizeof b->socks_reply)
+ return;
if (b->socks_reply[0]) {
setcstate(c, S_BAD_SOCKS_VERSION);
abort_connection(c);
return;
}
switch (b->socks_reply[1]) {
- case 91:
- setcstate(c, S_SOCKS_REJECTED);
- retry_connection(c);
- return;
- case 92:
- setcstate(c, S_SOCKS_NO_IDENTD);
- abort_connection(c);
- return;
- case 93:
- setcstate(c, S_SOCKS_BAD_USERID);
- abort_connection(c);
- return;
- default:
- setcstate(c, S_SOCKS_UNKNOWN_ERROR);
- retry_connection(c);
- return;
- case 90:
- break;
+ case 91:
+ setcstate(c, S_SOCKS_REJECTED);
+ retry_connection(c);
+ return;
+ case 92:
+ setcstate(c, S_SOCKS_NO_IDENTD);
+ abort_connection(c);
+ return;
+ case 93:
+ setcstate(c, S_SOCKS_BAD_USERID);
+ abort_connection(c);
+ return;
+ default:
+ setcstate(c, S_SOCKS_UNKNOWN_ERROR);
+ retry_connection(c);
+ return;
+ case 90:
+ break;
}
connected(c);
}
-static void dns_found(void *c_, int state)
+static void
+dns_found(void *c_, int state)
{
struct connection *c = (struct connection *)c_;
if (state) {
- setcstate(c, *c->socks_proxy || is_proxy_url(c->url) ? S_NO_PROXY_DNS : S_NO_DNS);
+ setcstate(c, *c->socks_proxy || is_proxy_url(c->url)
+ ? S_NO_PROXY_DNS
+ : S_NO_DNS);
abort_connection(c);
return;
}
try_connect(c);
}
-void retry_connect(struct connection *c, int err, int ssl_downgrade)
+void
+retry_connect(struct connection *c, int err, int ssl_downgrade)
{
struct conn_info *b = c->newconn;
- if (!b->l.addr_index) b->first_error = err;
+ if (!b->l.addr_index)
+ b->first_error = err;
freeSSL(c->ssl);
c->ssl = NULL;
if (ssl_downgrade) {
@@ -381,7 +410,8 @@ void retry_connect(struct connection *c, int err, int ssl_downgrade)
}
}
-static void try_connect(struct connection *c)
+static void
+try_connect(struct connection *c)
{
int s;
int rs;
@@ -412,7 +442,8 @@ static void try_connect(struct connection *c)
sa.sin_family = AF_INET;
memcpy(&sa.sin_addr.s_addr, addr->addr, 4);
sa.sin_port = htons(p);
- EINTRLOOP(rs, connect(s, (struct sockaddr *)(void *)&sa, sizeof sa));
+ EINTRLOOP(
+ rs, connect(s, (struct sockaddr *)(void *)&sa, sizeof sa));
} else if (addr->af == AF_INET6) {
struct sockaddr_in6 sa;
memset(&sa, 0, sizeof sa);
@@ -420,7 +451,8 @@ static void try_connect(struct connection *c)
memcpy(&sa.sin6_addr, addr->addr, 16);
sa.sin6_scope_id = addr->scope_id;
sa.sin6_port = htons(p);
- EINTRLOOP(rs, connect(s, (struct sockaddr *)(void *)&sa, sizeof sa));
+ EINTRLOOP(
+ rs, connect(s, (struct sockaddr *)(void *)&sa, sizeof sa));
} else {
rs = -1;
errno = EINVAL;
@@ -433,7 +465,8 @@ static void try_connect(struct connection *c)
set_handlers(s, NULL, connected, c);
setcstate(c, !b->l.addr_index ? S_CONN : S_CONN_ANOTHER);
#if MAX_ADDRESSES > 1
- if (b->l.addr.n > 1 && (is_connection_restartable(c) || max_tries == 1)) {
+ if (b->l.addr.n > 1
+ && (is_connection_restartable(c) || max_tries == 1)) {
set_connection_timeout(c);
}
#endif
@@ -442,7 +475,9 @@ static void try_connect(struct connection *c)
}
}
-void continue_connection(struct connection *c, int *sock, void (*func)(struct connection *))
+void
+continue_connection(struct connection *c, int *sock,
+ void (*func)(struct connection *))
{
struct conn_info *b;
if (c->newconn)
@@ -456,7 +491,8 @@ void continue_connection(struct connection *c, int *sock, void (*func)(struct co
connected(c);
}
-static void connected(void *c_)
+static void
+connected(void *c_)
{
struct connection *c = (struct connection *)c_;
struct conn_info *b = c->newconn;
@@ -468,9 +504,11 @@ static void connected(void *c_)
clear_connection_timeout(c);
#ifdef SO_ERROR
errno = 0;
- EINTRLOOP(rs, getsockopt(*b->sock, SOL_SOCKET, SO_ERROR, (void *)&err, &len));
+ EINTRLOOP(
+ rs, getsockopt(*b->sock, SOL_SOCKET, SO_ERROR, (void *)&err, &len));
if (!rs) {
- if (err >= 10000) err -= 10000; /* Why does EMX return so large values? */
+ if (err >= 10000)
+ err -= 10000; /* Why does EMX return so large values? */
} else {
if (!(err = errno)) {
retry_connect(c, S_STATE, 0);
@@ -478,10 +516,10 @@ static void connected(void *c_)
}
}
if (err > 0
-#ifdef EISCONN
+ #ifdef EISCONN
&& err != EISCONN
-#endif
- ) {
+ #endif
+ ) {
retry_connect(c, get_error_from_errno(err), 0);
return;
}
@@ -506,7 +544,8 @@ static void connected(void *c_)
if (!proxies.only_proxies && !c->no_ssl_session) {
unsigned char *h = get_host_name(orig_url);
int p = get_port(orig_url);
- SSL_SESSION *ses = get_session_cache_entry(c->ssl->ctx, h, p);
+ SSL_SESSION *ses =
+ get_session_cache_entry(c->ssl->ctx, h, p);
if (ses) {
if (SSL_set_session(c->ssl->ssl, ses) == 1)
c->ssl->session_set = 1;
@@ -516,10 +555,16 @@ static void connected(void *c_)
#if !defined(OPENSSL_NO_STDIO)
if (!proxies.only_proxies) {
if (ssl_options.client_cert_key[0]) {
- SSL_use_PrivateKey_file(c->ssl->ssl, cast_const_char ssl_options.client_cert_key, SSL_FILETYPE_PEM);
+ SSL_use_PrivateKey_file(
+ c->ssl->ssl,
+ cast_const_char ssl_options.client_cert_key,
+ SSL_FILETYPE_PEM);
}
if (ssl_options.client_cert_crt[0]) {
- SSL_use_certificate_file(c->ssl->ssl, cast_const_char ssl_options.client_cert_crt, SSL_FILETYPE_PEM);
+ SSL_use_certificate_file(
+ c->ssl->ssl,
+ cast_const_char ssl_options.client_cert_crt,
+ SSL_FILETYPE_PEM);
}
}
#endif
@@ -527,33 +572,34 @@ static void connected(void *c_)
ssl_setup_downgrade(c);
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
if (h[0] == '[' || !numeric_ip_address((char *)h, NULL)
- || !numeric_ipv6_address((char *)h, NULL, NULL)
- ) goto skip_numeric_address;
+ || !numeric_ipv6_address((char *)h, NULL, NULL))
+ goto skip_numeric_address;
SSL_set_tlsext_host_name(c->ssl->ssl, h);
skip_numeric_address:
#endif
free(h);
switch (SSL_get_error(c->ssl->ssl, SSL_connect(c->ssl->ssl))) {
- case SSL_ERROR_WANT_READ:
- setcstate(c, S_SSL_NEG);
- set_handlers(*b->sock, ssl_want_io, NULL, c);
- return;
- case SSL_ERROR_WANT_WRITE:
- setcstate(c, S_SSL_NEG);
- set_handlers(*b->sock, NULL, ssl_want_io, c);
- return;
- case SSL_ERROR_NONE:
- break;
- default:
- ssl_error:
- ssl_downgrade_dance(c);
- return;
+ case SSL_ERROR_WANT_READ:
+ setcstate(c, S_SSL_NEG);
+ set_handlers(*b->sock, ssl_want_io, NULL, c);
+ return;
+ case SSL_ERROR_WANT_WRITE:
+ setcstate(c, S_SSL_NEG);
+ set_handlers(*b->sock, NULL, ssl_want_io, c);
+ return;
+ case SSL_ERROR_NONE:
+ break;
+ default:
+ssl_error:
+ ssl_downgrade_dance(c);
+ return;
}
}
connected_callback(c);
}
-static void update_dns_priority(struct connection *c)
+static void
+update_dns_priority(struct connection *c)
{
#if MAX_ADDRESSES > 1
struct conn_info *b = c->newconn;
@@ -569,17 +615,21 @@ static void update_dns_priority(struct connection *c)
#endif
}
-static void connected_callback(struct connection *c)
+static void
+connected_callback(struct connection *c)
{
int flags;
struct conn_info *b = c->newconn;
update_dns_priority(c);
if (c->ssl) {
- if (ssl_options.certificates != SSL_ACCEPT_INVALID_CERTIFICATE) {
- unsigned char *h = get_host_name(remove_proxy_prefix(c->url));
+ if (ssl_options.certificates
+ != SSL_ACCEPT_INVALID_CERTIFICATE) {
+ unsigned char *h =
+ get_host_name(remove_proxy_prefix(c->url));
int err = verify_ssl_certificate(c->ssl, h);
if (err) {
- if (ssl_options.certificates == SSL_WARN_ON_INVALID_CERTIFICATE) {
+ if (ssl_options.certificates
+ == SSL_WARN_ON_INVALID_CERTIFICATE) {
flags = get_blacklist_flags(h);
if (flags & BL_IGNORE_CERTIFICATE)
goto ignore_cert;
@@ -589,10 +639,11 @@ static void connected_callback(struct connection *c)
abort_connection(c);
return;
}
- ignore_cert:
+ignore_cert:
if (c->no_tls) {
- if (ssl_options.certificates == SSL_WARN_ON_INVALID_CERTIFICATE) {
+ if (ssl_options.certificates
+ == SSL_WARN_ON_INVALID_CERTIFICATE) {
flags = get_blacklist_flags(h);
if (flags & BL_IGNORE_DOWNGRADE)
goto ignore_downgrade;
@@ -602,11 +653,12 @@ static void connected_callback(struct connection *c)
abort_connection(c);
return;
}
- ignore_downgrade:
+ignore_downgrade:
err = verify_ssl_cipher(c->ssl);
if (err) {
- if (ssl_options.certificates == SSL_WARN_ON_INVALID_CERTIFICATE) {
+ if (ssl_options.certificates
+ == SSL_WARN_ON_INVALID_CERTIFICATE) {
flags = get_blacklist_flags(h);
if (flags & BL_IGNORE_CIPHER)
goto ignore_cipher;
@@ -616,7 +668,7 @@ static void connected_callback(struct connection *c)
abort_connection(c);
return;
}
- ignore_cipher:
+ignore_cipher:
free(h);
}
@@ -636,7 +688,8 @@ struct write_buffer {
unsigned char data[1];
};
-static void write_select(void *c_)
+static void
+write_select(void *c_)
{
struct connection *c = (struct connection *)c_;
struct write_buffer *wb;
@@ -654,7 +707,9 @@ static void write_select(void *c_)
if (c->ssl) {
set_handlers(wb->sock, NULL, write_select, c);
- if ((wr = SSL_write(c->ssl->ssl, (void *)(wb->data + wb->pos), wb->len - wb->pos)) <= 0) {
+ if ((wr = SSL_write(c->ssl->ssl, (void *)(wb->data + wb->pos),
+ wb->len - wb->pos))
+ <= 0) {
int err;
err = SSL_get_error(c->ssl->ssl, wr);
if (err == SSL_ERROR_WANT_WRITE) {
@@ -664,16 +719,23 @@ static void write_select(void *c_)
set_handlers(wb->sock, write_select, NULL, c);
return;
}
- setcstate(c, wr ? (err == SSL_ERROR_SYSCALL ? get_error_from_errno(errno) : S_SSL_ERROR) : S_CANT_WRITE);
- if (!wr || err == SSL_ERROR_SYSCALL) retry_connection(c);
- else abort_connection(c);
+ setcstate(c, wr ? (err == SSL_ERROR_SYSCALL
+ ? get_error_from_errno(errno)
+ : S_SSL_ERROR)
+ : S_CANT_WRITE);
+ if (!wr || err == SSL_ERROR_SYSCALL)
+ retry_connection(c);
+ else
+ abort_connection(c);
return;
}
c->ssl->bytes_written += wr;
} else {
- EINTRLOOP(wr, (int)write(wb->sock, wb->data + wb->pos, wb->len - wb->pos));
+ EINTRLOOP(wr, (int)write(wb->sock, wb->data + wb->pos,
+ wb->len - wb->pos));
if (wr <= 0) {
- setcstate(c, wr ? get_error_from_errno(errno) : S_CANT_WRITE);
+ setcstate(c, wr ? get_error_from_errno(errno)
+ : S_CANT_WRITE);
retry_connection(c);
return;
}
@@ -688,10 +750,13 @@ static void write_select(void *c_)
}
}
-void write_to_socket(struct connection *c, int s, unsigned char *data, int len, void (*write_func)(struct connection *))
+void
+write_to_socket(struct connection *c, int s, unsigned char *data, int len,
+ void (*write_func)(struct connection *))
{
struct write_buffer *wb;
- if ((unsigned)len > INT_MAX - sizeof(struct write_buffer)) overalloc();
+ if ((unsigned)len > INT_MAX - sizeof(struct write_buffer))
+ overalloc();
wb = xmalloc(sizeof(struct write_buffer) + len);
wb->sock = s;
wb->len = len;
@@ -703,10 +768,11 @@ void write_to_socket(struct connection *c, int s, unsigned char *data, int len,
set_handlers(s, NULL, write_select, c);
}
-#define READ_SIZE 64240
-#define TOTAL_READ (4193008 - READ_SIZE)
+#define READ_SIZE 64240
+#define TOTAL_READ (4193008 - READ_SIZE)
-static void read_select(void *c_)
+static void
+read_select(void *c_)
{
struct connection *c = (struct connection *)c_;
int total_read = 0;
@@ -721,15 +787,19 @@ static void read_select(void *c_)
set_handlers(rb->sock, NULL, NULL, NULL);
read_more:
- if ((unsigned)rb->len > INT_MAX - sizeof(struct read_buffer) - READ_SIZE)
+ if ((unsigned)rb->len
+ > INT_MAX - sizeof(struct read_buffer) - READ_SIZE)
overalloc();
rb = xrealloc(rb, sizeof(struct read_buffer) + rb->len + READ_SIZE);
c->buffer = rb;
if (c->ssl) {
- if ((rd = SSL_read(c->ssl->ssl, (void *)(rb->data + rb->len), READ_SIZE)) <= 0) {
+ if ((rd = SSL_read(c->ssl->ssl, (void *)(rb->data + rb->len),
+ READ_SIZE))
+ <= 0) {
int err;
- if (total_read) goto success;
+ if (total_read)
+ goto success;
err = SSL_get_error(c->ssl->ssl, rd);
if (err == SSL_ERROR_WANT_READ) {
set_handlers(rb->sock, read_select, NULL, c);
@@ -744,22 +814,30 @@ read_more:
rb->done(c, rb);
return;
}
- setcstate(c, rd ? (err == SSL_ERROR_SYSCALL ? get_error_from_errno(errno) : S_SSL_ERROR) : S_CANT_READ);
- if (!rd || err == SSL_ERROR_SYSCALL) retry_connection(c);
- else abort_connection(c);
+ setcstate(c, rd ? (err == SSL_ERROR_SYSCALL
+ ? get_error_from_errno(errno)
+ : S_SSL_ERROR)
+ : S_CANT_READ);
+ if (!rd || err == SSL_ERROR_SYSCALL)
+ retry_connection(c);
+ else
+ abort_connection(c);
return;
}
c->ssl->bytes_read += rd;
} else {
- EINTRLOOP(rd, (int)read(rb->sock, rb->data + rb->len, READ_SIZE));
+ EINTRLOOP(rd,
+ (int)read(rb->sock, rb->data + rb->len, READ_SIZE));
if (rd <= 0) {
- if (total_read) goto success;
+ if (total_read)
+ goto success;
if (rb->close && !rd) {
rb->close = 2;
rb->done(c, rb);
return;
}
- setcstate(c, rd ? get_error_from_errno(errno) : S_CANT_READ);
+ setcstate(c, rd ? get_error_from_errno(errno)
+ : S_CANT_READ);
retry_connection(c);
return;
}
@@ -776,7 +854,8 @@ success:
rb->done(c, rb);
}
-struct read_buffer *alloc_read_buffer(void)
+struct read_buffer *
+alloc_read_buffer(void)
{
struct read_buffer *rb;
rb = xmalloc(sizeof(struct read_buffer) + READ_SIZE);
@@ -784,7 +863,9 @@ struct read_buffer *alloc_read_buffer(void)
return rb;
}
-void read_from_socket(struct connection *c, int s, struct read_buffer *buf, void (*read_func)(struct connection *, struct read_buffer *))
+void
+read_from_socket(struct connection *c, int s, struct read_buffer *buf,
+ void (*read_func)(struct connection *, struct read_buffer *))
{
buf->done = read_func;
buf->sock = s;
@@ -794,7 +875,8 @@ void read_from_socket(struct connection *c, int s, struct read_buffer *buf, void
set_handlers(s, read_select, NULL, c);
}
-void kill_buffer_data(struct read_buffer *rb, int n)
+void
+kill_buffer_data(struct read_buffer *rb, int n)
{
if (n > rb->len || n < 0) {
internal("called kill_buffer_data with bad value");
diff --git a/cookies.c b/cookies.c
@@ -8,8 +8,8 @@
#include "links.h"
-#define ACCEPT_NONE 0
-#define ACCEPT_ALL 1
+#define ACCEPT_NONE 0
+#define ACCEPT_ALL 1
static int accept_cookies = ACCEPT_ALL;
@@ -18,8 +18,7 @@ struct list_head all_cookies = { &all_cookies, &all_cookies };
struct list_head c_domains = { &c_domains, &c_domains };
struct c_server {
- list_entry_1st
- int accpt;
+ list_entry_1st int accpt;
unsigned char server[1];
};
@@ -27,7 +26,8 @@ static struct list_head c_servers = { &c_servers, &c_servers };
static void accept_cookie(struct cookie *);
-void free_cookie(struct cookie *c)
+void
+free_cookie(struct cookie *c)
{
free(c->name);
free(c->value);
@@ -37,13 +37,13 @@ void free_cookie(struct cookie *c)
free(c);
}
-
/* sezere 1 cookie z retezce str, na zacatku nesmi byt zadne whitechars
* na konci muze byt strednik nebo 0
* cookie musi byt ve tvaru nazev=hodnota, kolem rovnase nesmi byt zadne mezery
* (respektive mezery se budou pocitat do nazvu a do hodnoty)
*/
-int set_cookie(struct terminal *term, unsigned char *url, unsigned char *str)
+int
+set_cookie(struct terminal *term, unsigned char *url, unsigned char *str)
{
if (!accept_cookies)
return 0;
@@ -52,7 +52,8 @@ int set_cookie(struct terminal *term, unsigned char *url, unsigned char *str)
struct c_server *cs = NULL;
struct list_head *lcs;
unsigned char *p, *q, *s, *server, *date, *dom;
- for (p = str; *p != ';' && *p; p++);
+ for (p = str; *p != ';' && *p; p++)
+ ;
for (q = str; *q != '='; q++)
if (!*q || q >= p) {
noval = 1;
@@ -75,21 +76,23 @@ int set_cookie(struct terminal *term, unsigned char *url, unsigned char *str)
cookie->path = stracpy(cast_uchar "/");
else if (cookie->path[0] != '/') {
add_to_strn(&cookie->path, cast_uchar "x");
- memmove(cookie->path + 1, cookie->path, strlen((const char *)cookie->path) - 1);
+ memmove(cookie->path + 1, cookie->path,
+ strlen((const char *)cookie->path) - 1);
cookie->path[0] = '/';
}
dom = parse_header_param(str, cast_uchar "domain", 0);
if (!dom)
cookie->domain = stracpy(server);
else {
- cookie->domain = idn_encode_host(dom, strlen((const char *)dom), cast_uchar ".", 0);
+ cookie->domain = idn_encode_host(dom, strlen((const char *)dom),
+ cast_uchar ".", 0);
if (!cookie->domain)
cookie->domain = stracpy(server);
free(dom);
}
if (cookie->domain[0] == '.')
memmove(cookie->domain, cookie->domain + 1,
- strlen((const char *)cookie->domain));
+ strlen((const char *)cookie->domain));
if ((s = parse_header_param(str, cast_uchar "secure", 0))) {
cookie->secure = 1;
free(s);
@@ -99,7 +102,7 @@ int set_cookie(struct terminal *term, unsigned char *url, unsigned char *str)
free(cookie->domain);
cookie->domain = stracpy(server);
}
- foreach(struct c_server, cs, lcs, c_servers)
+ foreach (struct c_server, cs, lcs, c_servers)
if (!casestrcmp(cs->server, server)) {
if (cs->accpt)
goto ok;
@@ -120,16 +123,17 @@ ok:
return 0;
}
-static void accept_cookie(struct cookie *c)
+static void
+accept_cookie(struct cookie *c)
{
struct c_domain *cd = NULL;
struct list_head *lcd;
struct cookie *d = NULL;
struct list_head *ld;
size_t sl;
- foreach(struct cookie, d, ld, all_cookies)
+ foreach (struct cookie, d, ld, all_cookies)
if (!casestrcmp(d->name, c->name)
- && !casestrcmp(d->domain, c->domain)) {
+ && !casestrcmp(d->domain, c->domain)) {
ld = ld->prev;
del_from_list(d);
free_cookie(d);
@@ -139,7 +143,7 @@ static void accept_cookie(struct cookie *c)
return;
}
add_to_list(all_cookies, c);
- foreach(struct c_domain, cd, lcd, c_domains)
+ foreach (struct c_domain, cd, lcd, c_domains)
if (!casestrcmp(cd->domain, c->domain))
return;
sl = strlen((const char *)c->domain);
@@ -150,7 +154,8 @@ static void accept_cookie(struct cookie *c)
add_to_list(c_domains, cd);
}
-int is_in_domain(unsigned char *d, unsigned char *s)
+int
+is_in_domain(unsigned char *d, unsigned char *s)
{
const int dl = strlen((const char *)d);
const int sl = strlen((const char *)s);
@@ -163,7 +168,8 @@ int is_in_domain(unsigned char *d, unsigned char *s)
return !casecmp(d, s + sl - dl, dl);
}
-int is_path_prefix(unsigned char *d, unsigned char *s)
+int
+is_path_prefix(unsigned char *d, unsigned char *s)
{
const int dl = strlen((const char *)d);
const int sl = strlen((const char *)s);
@@ -173,10 +179,12 @@ int is_path_prefix(unsigned char *d, unsigned char *s)
return 0;
if (memcmp(d, s, dl))
return 0;
- return d[dl - 1] == '/' || !s[dl] || s[dl] == '/' || s[dl] == POST_CHAR || s[dl] == '?' || s[dl] == '&';
+ return d[dl - 1] == '/' || !s[dl] || s[dl] == '/' || s[dl] == POST_CHAR
+ || s[dl] == '?' || s[dl] == '&';
}
-int cookie_expired(struct cookie *c)
+int
+cookie_expired(struct cookie *c)
{
time_t t;
errno = 0;
@@ -184,7 +192,8 @@ int cookie_expired(struct cookie *c)
return c->expires && c->expires < t;
}
-void add_cookies(unsigned char **s, int *l, unsigned char *url)
+void
+add_cookies(unsigned char **s, int *l, unsigned char *url)
{
int nc = 0;
struct c_domain *cd = NULL;
@@ -195,13 +204,13 @@ void add_cookies(unsigned char **s, int *l, unsigned char *url)
unsigned char *data = get_url_data(url);
if (data > url)
data--;
- foreach(struct c_domain, cd, lcd, c_domains)
+ foreach (struct c_domain, cd, lcd, c_domains)
if (is_in_domain(cd->domain, server))
goto ok;
free(server);
return;
ok:
- foreachback(struct cookie, c, lc, all_cookies)
+ foreachback (struct cookie, c, lc, all_cookies)
if (is_in_domain(c->domain, server))
if (is_path_prefix(c->path, data)) {
if (cookie_expired(c)) {
@@ -211,7 +220,7 @@ ok:
continue;
}
if (c->secure
- && casecmp(url, cast_uchar "https://", 8))
+ && casecmp(url, cast_uchar "https://", 8))
continue;
if (!nc) {
add_to_str(s, l, cast_uchar "Cookie: ");
@@ -229,7 +238,8 @@ ok:
free(server);
}
-void free_cookies(void)
+void
+free_cookies(void)
{
free_list(struct c_domain, c_domains);
/* !!! FIXME: save cookies */
@@ -240,8 +250,8 @@ void free_cookies(void)
}
}
-void init_cookies(void)
+void
+init_cookies(void)
{
/* !!! FIXME: read cookies */
}
-
diff --git a/data.c b/data.c
@@ -1,18 +1,25 @@
#include "links.h"
-static void base64_decode(unsigned char **d, int *dl, unsigned char *s, int sl)
+static void
+base64_decode(unsigned char **d, int *dl, unsigned char *s, int sl)
{
int bits = 0;
unsigned tmp = 0;
for (; sl > 0; s++, sl--) {
unsigned char val;
unsigned char c = *s;
- if (c >= 'A' && c <= 'Z') val = c - 'A';
- else if (c >= 'a' && c <= 'z') val = c - 'a' + 26;
- else if (c >= '0' && c <= '9') val = c - '0' + 52;
- else if (c == '+') val = 62;
- else if (c == '/') val = 63;
- else continue;
+ if (c >= 'A' && c <= 'Z')
+ val = c - 'A';
+ else if (c >= 'a' && c <= 'z')
+ val = c - 'a' + 26;
+ else if (c >= '0' && c <= '9')
+ val = c - '0' + 52;
+ else if (c == '+')
+ val = 62;
+ else if (c == '/')
+ val = 63;
+ else
+ continue;
tmp <<= 6;
tmp |= val;
bits += 6;
@@ -24,7 +31,8 @@ static void base64_decode(unsigned char **d, int *dl, unsigned char *s, int sl)
}
}
-void data_func(struct connection *c)
+void
+data_func(struct connection *c)
{
unsigned char *data, *flags, *mime, *str;
size_t length;
@@ -37,13 +45,14 @@ void data_func(struct connection *c)
flags = cast_uchar strchr(cast_const_char c->url, ':');
if (!flags) {
- bad_url:
+bad_url:
setcstate(c, S_BAD_URL);
abort_connection(c);
return;
}
flags++;
- while (*flags == '/') flags++;
+ while (*flags == '/')
+ flags++;
length = strcspn(cast_const_char flags, ";,");
mime = memacpy(flags, length);
diff --git a/default.c b/default.c
@@ -15,7 +15,8 @@
unsigned char system_name[MAX_STR_LEN];
-static void get_system_name(void)
+static void
+get_system_name(void)
{
{
struct utsname name;
@@ -43,13 +44,15 @@ struct option {
unsigned char *(*rd_cmd)(struct option *, unsigned char ***, int *);
unsigned char *(*rd_cfg)(struct option *, unsigned char *);
void (*wr_cfg)(struct option *, unsigned char **, int *);
- int min, max; /* for double min and max are in 1/100's (e.g. 0.1 is min==10) */
+ int min, max; /* for double min and max are in 1/100's (e.g. 0.1 is
+ min==10) */
void *ptr;
char *cfg_name;
char *cmd_name;
};
-static unsigned char *p_arse_options(int argc, unsigned char *argv[], struct option **opt)
+static unsigned char *
+p_arse_options(int argc, unsigned char *argv[], struct option **opt)
{
unsigned char *e, *u = NULL;
int i;
@@ -65,35 +68,46 @@ static unsigned char *p_arse_options(int argc, unsigned char *argv[], struct opt
if (argv[-1][0] == '-') {
struct option *options;
struct option **op;
- for (op = opt; (options = *op); op++) for (i = 0; options[i].p; i++)
- if (options[i].rd_cmd && options[i].cmd_name &&
- !casestrcmp(cast_uchar options[i].cmd_name, &argv[-1][1])) {
- if ((e = options[i].rd_cmd(&options[i], &argv, &argc))) {
- if (e[0])
- usage();
- return NULL;
+ for (op = opt; (options = *op); op++)
+ for (i = 0; options[i].p; i++)
+ if (options[i].rd_cmd
+ && options[i].cmd_name
+ && !casestrcmp(
+ cast_uchar options[i].cmd_name,
+ &argv[-1][1])) {
+ if ((e = options[i].rd_cmd(
+ &options[i], &argv,
+ &argc))) {
+ if (e[0])
+ usage();
+ return NULL;
+ }
+ goto found;
}
- goto found;
- }
- uu:
+uu:
usage();
return NULL;
- } else if (!u) u = argv[-1];
- else goto uu;
- found:;
+ } else if (!u)
+ u = argv[-1];
+ else
+ goto uu;
+found:;
}
- if (u) return u;
+ if (u)
+ return u;
return cast_uchar "";
}
-static unsigned char *get_token(unsigned char **line)
+static unsigned char *
+get_token(unsigned char **line)
{
unsigned char *s = NULL;
int l = 0;
int escape = 0;
int quote = 0;
- while (**line == ' ' || **line == 9) (*line)++;
+ while (**line == ' ' || **line == 9)
+ (*line)++;
if (**line) {
for (s = init_str(); **line; (*line)++) {
if (escape)
@@ -101,12 +115,10 @@ static unsigned char *get_token(unsigned char **line)
else if (**line == '\\') {
escape = 1;
continue;
- }
- else if (**line == '"') {
+ } else if (**line == '"') {
quote = !quote;
continue;
- }
- else if ((**line == ' ' || **line == 9) && !quote)
+ } else if ((**line == ' ' || **line == 9) && !quote)
break;
add_chr_to_str(&s, &l, **line);
}
@@ -114,7 +126,8 @@ static unsigned char *get_token(unsigned char **line)
return s;
}
-static void parse_config_file(unsigned char *name, unsigned char *file, struct option **opt)
+static void
+parse_config_file(unsigned char *name, unsigned char *file, struct option **opt)
{
struct option *options;
struct option **op;
@@ -127,42 +140,64 @@ static void parse_config_file(unsigned char *name, unsigned char *file, struct o
int nl, pl;
while (file[0]) {
line++;
- while (file[0] && (file[0] == ' ' || file[0] == 9)) file++;
+ while (file[0] && (file[0] == ' ' || file[0] == 9))
+ file++;
n = file;
- while (file[0] && file[0] > ' ') file++;
+ while (file[0] && file[0] > ' ')
+ file++;
if (file == n) {
- if (file[0]) file++;
+ if (file[0])
+ file++;
continue;
}
- while (file[0] == 9 || file[0] == ' ') file++;
+ while (file[0] == 9 || file[0] == ' ')
+ file++;
p = file;
- while (file[0] && file[0] != 10 && file[0] != 13) file++;
+ while (file[0] && file[0] != 10 && file[0] != 13)
+ file++;
pl = (int)(file - p);
if (file[0]) {
- if ((file[1] == 10 || file[1] == 13) && file[0] != file[1]) file++;
+ if ((file[1] == 10 || file[1] == 13)
+ && file[0] != file[1])
+ file++;
file++;
}
tok = NULL;
- if (n[0] == '#') goto f;
- if (!(tok = get_token(&n))) goto f;
+ if (n[0] == '#')
+ goto f;
+ if (!(tok = get_token(&n)))
+ goto f;
nl = (int)strlen(cast_const_char tok);
for (op = opt; (options = *op); op++)
- for (i = 0; options[i].p; i++) if (options[i].cfg_name && (size_t)nl == strlen(cast_const_char options[i].cfg_name) && !casecmp(tok, cast_uchar options[i].cfg_name, nl)) {
- unsigned char *o = memacpy(p, pl);
- if (options[i].rd_cfg && (e = options[i].rd_cfg(&options[i], o))) {
- if (e[0]) {
- fprintf(stderr,
- "Error parsing config file %s, line %d: %s\n",
- name, line, e);
- err = 1;
+ for (i = 0; options[i].p; i++)
+ if (options[i].cfg_name
+ && (size_t)nl
+ == strlen(cast_const_char options[i]
+ .cfg_name)
+ && !casecmp(tok,
+ cast_uchar options[i].cfg_name,
+ nl)) {
+ unsigned char *o = memacpy(p, pl);
+ if (options[i].rd_cfg
+ && (e = options[i].rd_cfg(
+ &options[i], o))) {
+ if (e[0]) {
+ fprintf(
+ stderr,
+ "Error parsing "
+ "config file %s, "
+ "line %d: %s\n",
+ name, line, e);
+ err = 1;
+ }
}
+ free(o);
+ goto f;
}
- free(o);
- goto f;
- }
- fprintf(stderr, "Unknown option in config file %s, line %d\n", name, line);
+ fprintf(stderr, "Unknown option in config file %s, line %d\n",
+ name, line);
err = 1;
- f:
+f:
free(tok);
}
if (err) {
@@ -171,12 +206,15 @@ static void parse_config_file(unsigned char *name, unsigned char *file, struct o
}
}
-static unsigned char *create_config_string(struct option *options)
+static unsigned char *
+create_config_string(struct option *options)
{
unsigned char *s = init_str();
int l = 0;
int i;
- add_to_str(&s, &l, cast_uchar "# This file is automatically generated by Links -- please do not edit.");
+ add_to_str(&s, &l,
+ cast_uchar "# This file is automatically generated by Links "
+ "-- please do not edit.");
for (i = 0; options[i].p; i++) {
if (options[i].wr_cfg)
options[i].wr_cfg(&options[i], &s, &l);
@@ -185,19 +223,23 @@ static unsigned char *create_config_string(struct option *options)
return s;
}
-unsigned char *read_config_file(unsigned char *name)
+unsigned char *
+read_config_file(unsigned char *name)
{
int h, r;
int l = 0;
unsigned char *cfg_buffer, *s;
int rs;
h = c_open(name, O_RDONLY | O_NOCTTY);
- if (h == -1) return NULL;
+ if (h == -1)
+ return NULL;
s = init_str();
cfg_buffer = xmalloc(page_size);
while ((r = hard_read(h, cfg_buffer, page_size)) > 0) {
int i;
- for (i = 0; i < r; i++) if (!cfg_buffer[i]) cfg_buffer[i] = ' ';
+ for (i = 0; i < r; i++)
+ if (!cfg_buffer[i])
+ cfg_buffer[i] = ' ';
add_bytes_to_str(&s, &l, cfg_buffer, r);
}
free(cfg_buffer);
@@ -209,7 +251,8 @@ unsigned char *read_config_file(unsigned char *name)
return s;
}
-int write_to_config_file(unsigned char *name, unsigned char *c, int do_sync)
+int
+write_to_config_file(unsigned char *name, unsigned char *c, int do_sync)
{
int rr;
int h, w;
@@ -233,7 +276,8 @@ try_new_count:
}
}
add_num_to_str(&tmp_name, &tmp_namel, count);
- h = c_open3(tmp_name, O_WRONLY | O_NOCTTY | O_CREAT | O_TRUNC | O_EXCL, 0600);
+ h = c_open3(tmp_name, O_WRONLY | O_NOCTTY | O_CREAT | O_TRUNC | O_EXCL,
+ 0600);
if (h == -1) {
err = errno;
if (err == EEXIST && count < INT_MAX) {
@@ -270,12 +314,17 @@ try_new_count:
unsigned char *e, *le;
tmp_name = stracpy(name);
le = tmp_name;
- for (e = tmp_name; *e; e++) if (dir_sep(*e)) le = e;
- while (le > tmp_name && dir_sep(le[-1])) le--;
- if (le == tmp_name && dir_sep(*le)) le++;
+ for (e = tmp_name; *e; e++)
+ if (dir_sep(*e))
+ le = e;
+ while (le > tmp_name && dir_sep(le[-1]))
+ le--;
+ if (le == tmp_name && dir_sep(*le))
+ le++;
*le = 0;
- h = c_open(*tmp_name ? tmp_name : cast_uchar ".", O_RDONLY | O_NOCTTY);
+ h = c_open(*tmp_name ? tmp_name : cast_uchar ".",
+ O_RDONLY | O_NOCTTY);
if (h != -1) {
EINTRLOOP(rs, fsync(h));
EINTRLOOP(rs, close(h));
@@ -285,16 +334,17 @@ try_new_count:
return 0;
- close_unlink_err:
+close_unlink_err:
EINTRLOOP(rs, close(h));
- unlink_err:
+unlink_err:
EINTRLOOP(rs, unlink(cast_const_char tmp_name));
- free_err:
+free_err:
free(tmp_name);
return get_error_from_errno(err);
}
-static unsigned char *get_home(void)
+static unsigned char *
+get_home(void)
{
struct stat st;
int rs;
@@ -312,69 +362,86 @@ static unsigned char *get_home(void)
if (!home) {
int i;
home = (unsigned char *)argv0;
- for (i = strlen(argv0) - 1; i >= 0; i--) if (dir_sep(home[i])) {
- home[i + 1] = 0;
- goto br;
- }
+ for (i = strlen(argv0) - 1; i >= 0; i--)
+ if (dir_sep(home[i])) {
+ home[i + 1] = 0;
+ goto br;
+ }
home[0] = 0;
- br:;
+br:;
}
- while (home[0] && home[1] && dir_sep(home[strlen(cast_const_char home) - 1])) home[strlen(cast_const_char home) - 1] = 0;
- if (home[0]) add_to_strn(&home, cast_uchar "/");
+ while (home[0] && home[1]
+ && dir_sep(home[strlen(cast_const_char home) - 1]))
+ home[strlen(cast_const_char home) - 1] = 0;
+ if (home[0])
+ add_to_strn(&home, cast_uchar "/");
home_links = stracpy(home);
if (config_dir) {
add_to_strn(&home_links, config_dir);
- while (home_links[0] && dir_sep(home_links[strlen(cast_const_char home_links) - 1])) home_links[strlen(cast_const_char home_links) - 1] = 0;
+ while (home_links[0]
+ && dir_sep(
+ home_links[strlen(cast_const_char home_links) - 1]))
+ home_links[strlen(cast_const_char home_links) - 1] = 0;
EINTRLOOP(rs, stat(cast_const_char home_links, &st));
if (!rs && S_ISDIR(st.st_mode)) {
add_to_strn(&home_links, cast_uchar "/links");
} else {
- fprintf(stderr, "CONFIG_DIR set to %s. But directory %s doesn't exist.\n\007", config_dir, home_links);
+ fprintf(stderr,
+ "CONFIG_DIR set to %s. But directory %s "
+ "doesn't exist.\n\007",
+ config_dir, home_links);
portable_sleep(3000);
free(home_links);
home_links = stracpy(home);
goto add_dot_links;
}
} else {
- add_dot_links:
+add_dot_links:
add_to_strn(&home_links, cast_uchar ".links");
}
EINTRLOOP(rs, stat(cast_const_char home_links, &st));
if (rs) {
EINTRLOOP(rs, mkdir(cast_const_char home_links, 0700));
- if (!rs) goto home_creat;
- if (config_dir) goto failed;
+ if (!rs)
+ goto home_creat;
+ if (config_dir)
+ goto failed;
goto first_failed;
}
- if (S_ISDIR(st.st_mode)) goto home_ok;
+ if (S_ISDIR(st.st_mode))
+ goto home_ok;
/* This is a Cygwin hack! Cygwin reports stat for "links" if no
"links" exists and only "links.exe" does. So try to create directory
anyway. */
EINTRLOOP(rs, mkdir(cast_const_char home_links, 0700));
- if (!rs) goto home_creat;
- first_failed:
+ if (!rs)
+ goto home_creat;
+first_failed:
free(home_links);
home_links = stracpy(home);
add_to_strn(&home_links, cast_uchar "links");
EINTRLOOP(rs, stat(cast_const_char home_links, &st));
if (rs) {
EINTRLOOP(rs, mkdir(cast_const_char home_links, 0700));
- if (!rs) goto home_creat;
+ if (!rs)
+ goto home_creat;
goto failed;
}
- if (S_ISDIR(st.st_mode)) goto home_ok;
+ if (S_ISDIR(st.st_mode))
+ goto home_ok;
EINTRLOOP(rs, mkdir(cast_const_char home_links, 0700));
- if (!rs) goto home_creat;
- failed:
+ if (!rs)
+ goto home_creat;
+failed:
free(home_links);
free(home);
free(config_dir);
return NULL;
- home_ok:
+home_ok:
first_use = 0;
if ((st.st_mode & 07777) != 0700) {
- home_creat:
+home_creat:
EINTRLOOP(rs, chmod(cast_const_char home_links, 0700));
}
add_to_strn(&home_links, cast_uchar "/");
@@ -383,12 +450,17 @@ static unsigned char *get_home(void)
return home_links;
}
-void init_home(void)
+void
+init_home(void)
{
get_system_name();
links_home = get_home();
if (!links_home) {
- fprintf(stderr, "Unable to find or create links config directory. Please check, that you have $HOME variable set correctly and that you have write permission to your home directory.\n\007");
+ fprintf(stderr,
+ "Unable to find or create links config directory. "
+ "Please check, that you have $HOME variable set "
+ "correctly and that you have write permission to your "
+ "home directory.\n\007");
portable_sleep(3000);
return;
}
@@ -397,20 +469,34 @@ void init_home(void)
/* prefix: directory
* name: name of the configuration file (typ. links.cfg)
*/
-static int write_config_data(unsigned char *prefix, unsigned char *name, struct option *o, struct terminal *term)
+static int
+write_config_data(unsigned char *prefix, unsigned char *name, struct option *o,
+ struct terminal *term)
{
int err;
unsigned char *c, *config_file;
- if (!(c = create_config_string(o))) return -1;
+ if (!(c = create_config_string(o)))
+ return -1;
config_file = stracpy(prefix);
if (!config_file) {
free(c);
- if (term) msg_box(term, NULL, TEXT_(T_CONFIG_ERROR), AL_CENTER, TEXT_(T_UNABLE_TO_WRITE_TO_CONFIG_FILE), cast_uchar ": ", TEXT_(T_HOME_DIRECTORY_INACCESSIBLE), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ if (term)
+ msg_box(term, NULL, TEXT_(T_CONFIG_ERROR), AL_CENTER,
+ TEXT_(T_UNABLE_TO_WRITE_TO_CONFIG_FILE),
+ cast_uchar ": ",
+ TEXT_(T_HOME_DIRECTORY_INACCESSIBLE),
+ MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL),
+ msg_box_null, B_ENTER | B_ESC);
return -1;
}
add_to_strn(&config_file, name);
if ((err = write_to_config_file(config_file, c, 1))) {
- if (term) msg_box(term, NULL, TEXT_(T_CONFIG_ERROR), AL_CENTER, TEXT_(T_UNABLE_TO_WRITE_TO_CONFIG_FILE), cast_uchar ": ", get_err_msg(err), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ if (term)
+ msg_box(term, NULL, TEXT_(T_CONFIG_ERROR), AL_CENTER,
+ TEXT_(T_UNABLE_TO_WRITE_TO_CONFIG_FILE),
+ cast_uchar ": ", get_err_msg(err), MSG_BOX_END,
+ NULL, 1, TEXT_(T_CANCEL), msg_box_null,
+ B_ENTER | B_ESC);
free(c);
free(config_file);
return -1;
@@ -420,30 +506,36 @@ static int write_config_data(unsigned char *prefix, unsigned char *name, struct
return 0;
}
-static void add_nm(struct option *o, unsigned char **s, int *l)
+static void
+add_nm(struct option *o, unsigned char **s, int *l)
{
- if (*l) add_to_str(s, l, cast_uchar "\n");
+ if (*l)
+ add_to_str(s, l, cast_uchar "\n");
add_to_str(s, l, cast_uchar o->cfg_name);
add_chr_to_str(s, l, ' ');
}
-static void add_quoted_to_str(unsigned char **s, int *l, unsigned char *q)
+static void
+add_quoted_to_str(unsigned char **s, int *l, unsigned char *q)
{
add_chr_to_str(s, l, '"');
while (*q) {
- if (*q == '"' || *q == '\\') add_chr_to_str(s, l, '\\');
+ if (*q == '"' || *q == '\\')
+ add_chr_to_str(s, l, '\\');
add_chr_to_str(s, l, *q);
q++;
}
add_chr_to_str(s, l, '"');
}
-static unsigned char *num_rd(struct option *o, unsigned char *c)
+static unsigned char *
+num_rd(struct option *o, unsigned char *c)
{
unsigned char *tok = get_token(&c);
unsigned char *end;
long l;
- if (!tok) return cast_uchar "Missing argument";
+ if (!tok)
+ return cast_uchar "Missing argument";
l = strtolx(tok, &end);
if (*end) {
free(tok);
@@ -458,19 +550,22 @@ static unsigned char *num_rd(struct option *o, unsigned char *c)
return NULL;
}
-static void num_wr(struct option *o, unsigned char **s, int *l)
+static void
+num_wr(struct option *o, unsigned char **s, int *l)
{
add_nm(o, s, l);
add_knum_to_str(s, l, *(int *)o->ptr);
}
-static unsigned char *dbl_rd(struct option *o, unsigned char *c)
+static unsigned char *
+dbl_rd(struct option *o, unsigned char *c)
{
unsigned char *tok = get_token(&c);
char *end;
double d;
- if (!tok) return cast_uchar "Missing argument";
+ if (!tok)
+ return cast_uchar "Missing argument";
if (strlen(cast_const_char tok) >= 1000) {
free(tok);
@@ -483,7 +578,7 @@ static unsigned char *dbl_rd(struct option *o, unsigned char *c)
free(tok);
return cast_uchar "Number expected";
}
- if (d < 0 || d > o->max || 100*d < o->min || 100*d > o->max) {
+ if (d < 0 || d > o->max || 100 * d < o->min || 100 * d > o->max) {
free(tok);
return cast_uchar "Out of range";
}
@@ -492,27 +587,33 @@ static unsigned char *dbl_rd(struct option *o, unsigned char *c)
return NULL;
}
-static void dbl_wr(struct option *o, unsigned char **s, int *l)
+static void
+dbl_wr(struct option *o, unsigned char **s, int *l)
{
unsigned char number[80];
- snprintf(cast_char number, sizeof number, "%.6f", *(double*)o->ptr);
+ snprintf(cast_char number, sizeof number, "%.6f", *(double *)o->ptr);
add_nm(o, s, l);
add_to_str(s, l, number);
}
-static unsigned char *str_rd(struct option *o, unsigned char *c)
+static unsigned char *
+str_rd(struct option *o, unsigned char *c)
{
unsigned char *tok = get_token(&c);
unsigned char *e = NULL;
- if (!tok) tok = stracpy(cast_uchar "");
- if (strlen(cast_const_char tok) + 1 > (size_t)o->max) e = cast_uchar "String too long";
- else strcpy(cast_char o->ptr, cast_const_char tok);
+ if (!tok)
+ tok = stracpy(cast_uchar "");
+ if (strlen(cast_const_char tok) + 1 > (size_t)o->max)
+ e = cast_uchar "String too long";
+ else
+ strcpy(cast_char o->ptr, cast_const_char tok);
free(tok);
return e;
}
-static void str_wr(struct option *o, unsigned char **s, int *l)
+static void
+str_wr(struct option *o, unsigned char **s, int *l)
{
add_nm(o, s, l);
if (strlen(cast_const_char o->ptr) + 1 > (size_t)o->max) {
@@ -521,76 +622,94 @@ static void str_wr(struct option *o, unsigned char **s, int *l)
add_bytes_to_str(&s1, &l1, o->ptr, o->max - 1);
add_quoted_to_str(s, l, s1);
free(s1);
- }
- else add_quoted_to_str(s, l, o->ptr);
+ } else
+ add_quoted_to_str(s, l, o->ptr);
}
-static unsigned char *cp_rd(struct option *o, unsigned char *c)
+static unsigned char *
+cp_rd(struct option *o, unsigned char *c)
{
unsigned char *tok = get_token(&c);
- if (!tok) return cast_uchar "Missing argument";
+ if (!tok)
+ return cast_uchar "Missing argument";
*(int *)o->ptr = 0;
free(tok);
return NULL;
}
-static void cp_wr(struct option *o, unsigned char **s, int *l)
+static void
+cp_wr(struct option *o, unsigned char **s, int *l)
{
unsigned char *n = get_cp_mime_name(0);
add_nm(o, s, l);
add_to_str(s, l, n);
}
-static int getnum(unsigned char *s, int *n, int r1, int r2)
+static int
+getnum(unsigned char *s, int *n, int r1, int r2)
{
char *e;
long l = strtol(cast_const_char s, &e, 10);
- if (*e || !*s) return -1;
- if (l < r1 || l >= r2) return -1;
+ if (*e || !*s)
+ return -1;
+ if (l < r1 || l >= r2)
+ return -1;
*n = (int)l;
return 0;
}
-static unsigned char *type_rd(struct option *o, unsigned char *c)
+static unsigned char *
+type_rd(struct option *o, unsigned char *c)
{
- unsigned char *err = cast_uchar "Error reading association specification";
+ unsigned char *err =
+ cast_uchar "Error reading association specification";
struct assoc neww;
unsigned char *w;
- int n = 0; /* against warning */
+ int n = 0; /* against warning */
memset(&neww, 0, sizeof(struct assoc));
- if (!(neww.label = get_token(&c))) goto err;
- if (!(neww.ct = get_token(&c))) goto err;
- if (!(neww.prog = get_token(&c))) goto err;
- if (!(w = get_token(&c))) goto err;
- if (getnum(w, &n, 0, 128)) goto err_f;
+ if (!(neww.label = get_token(&c)))
+ goto err;
+ if (!(neww.ct = get_token(&c)))
+ goto err;
+ if (!(neww.prog = get_token(&c)))
+ goto err;
+ if (!(w = get_token(&c)))
+ goto err;
+ if (getnum(w, &n, 0, 128))
+ goto err_f;
free(w);
neww.cons = !!(n & 1);
neww.xwin = !!(n & 2);
neww.ask = !!(n & 4);
- if ((n & 8) || (n & 16)) neww.block = !!(n & 16);
- else neww.block = !neww.xwin || neww.cons;
+ if ((n & 8) || (n & 16))
+ neww.block = !!(n & 16);
+ else
+ neww.block = !neww.xwin || neww.cons;
neww.accept_http = !!(n & 32);
neww.accept_ftp = !!(n & 64);
- if (!(w = get_token(&c))) goto err;
- if (getnum(w, &neww.system, 0, 256)) goto err_f;
+ if (!(w = get_token(&c)))
+ goto err;
+ if (getnum(w, &neww.system, 0, 256))
+ goto err_f;
free(w);
update_assoc(&neww);
err = NULL;
- err:
+err:
free(neww.label);
free(neww.ct);
free(neww.prog);
return err;
- err_f:
+err_f:
free(w);
goto err;
}
-static void type_wr(struct option *o, unsigned char **s, int *l)
+static void
+type_wr(struct option *o, unsigned char **s, int *l)
{
struct list *a = NULL;
struct list_head *la;
- foreachback(struct list, a, la, assoc.list_entry) {
+ foreachback (struct list, a, la, assoc.list_entry) {
struct assoc *as = get_struct(a, struct assoc, head);
add_nm(o, s, l);
add_quoted_to_str(s, l, as->label);
@@ -599,32 +718,40 @@ static void type_wr(struct option *o, unsigned char **s, int *l)
add_to_str(s, l, cast_uchar " ");
add_quoted_to_str(s, l, as->prog);
add_chr_to_str(s, l, ' ');
- add_num_to_str(s, l, (!!as->cons) + (!!as->xwin) * 2 + (!!as->ask) * 4 + (!as->block) * 8 + (!!as->block) * 16 + (!!as->accept_http) * 32 + (!!as->accept_ftp) * 64);
+ add_num_to_str(s, l,
+ (!!as->cons) + (!!as->xwin) * 2 + (!!as->ask) * 4
+ + (!as->block) * 8 + (!!as->block) * 16
+ + (!!as->accept_http) * 32
+ + (!!as->accept_ftp) * 64);
add_chr_to_str(s, l, ' ');
add_num_to_str(s, l, as->system);
}
}
-static unsigned char *ext_rd(struct option *o, unsigned char *c)
+static unsigned char *
+ext_rd(struct option *o, unsigned char *c)
{
unsigned char *err = cast_uchar "Error reading extension specification";
struct extension neww;
memset(&neww, 0, sizeof(struct extension));
- if (!(neww.ext = get_token(&c))) goto err;
- if (!(neww.ct = get_token(&c))) goto err;
+ if (!(neww.ext = get_token(&c)))
+ goto err;
+ if (!(neww.ct = get_token(&c)))
+ goto err;
update_ext(&neww);
err = NULL;
- err:
+err:
free(neww.ext);
free(neww.ct);
return err;
}
-static void ext_wr(struct option *o, unsigned char **s, int *l)
+static void
+ext_wr(struct option *o, unsigned char **s, int *l)
{
struct list *a = NULL;
struct list_head *la;
- foreachback(struct list, a, la, extensions.list_entry) {
+ foreachback (struct list, a, la, extensions.list_entry) {
struct extension *e = get_struct(a, struct extension, head);
add_nm(o, s, l);
add_quoted_to_str(s, l, e->ext);
@@ -633,28 +760,37 @@ static void ext_wr(struct option *o, unsigned char **s, int *l)
}
}
-static unsigned char *term_rd(struct option *o, unsigned char *c)
+static unsigned char *
+term_rd(struct option *o, unsigned char *c)
{
struct term_spec *ts;
unsigned char *w;
- if (!(w = get_token(&c))) goto err;
+ if (!(w = get_token(&c)))
+ goto err;
ts = new_term_spec(w);
free(w);
- if (!(w = get_token(&c))) goto err;
- if (strlen(cast_const_char w) != 1 || w[0] < '0' || w[0] > '4') goto err_f;
+ if (!(w = get_token(&c)))
+ goto err;
+ if (strlen(cast_const_char w) != 1 || w[0] < '0' || w[0] > '4')
+ goto err_f;
ts->mode = w[0] - '0';
free(w);
- if (!(w = get_token(&c))) goto err;
- if (strlen(cast_const_char w) != 1 || w[0] < '0' || w[0] > '3') goto err_f;
+ if (!(w = get_token(&c)))
+ goto err;
+ if (strlen(cast_const_char w) != 1 || w[0] < '0' || w[0] > '3')
+ goto err_f;
ts->m11_hack = (w[0] - '0') & 1;
free(w);
- if (!(w = get_token(&c))) goto err;
- if (strlen(cast_const_char w) != 1 || w[0] < '0' || w[0] > '7') goto err_f;
+ if (!(w = get_token(&c)))
+ goto err;
+ if (strlen(cast_const_char w) != 1 || w[0] < '0' || w[0] > '7')
+ goto err_f;
ts->col = (w[0] - '0') & 1;
ts->restrict_852 = !!((w[0] - '0') & 2);
ts->block_cursor = !!((w[0] - '0') & 4);
free(w);
- if (!(w = get_token(&c))) goto err;
+ if (!(w = get_token(&c)))
+ goto err;
ts->character_set = 0;
free(w);
ts->left_margin = 0;
@@ -662,50 +798,62 @@ static unsigned char *term_rd(struct option *o, unsigned char *c)
ts->top_margin = 0;
ts->bottom_margin = 0;
return NULL;
- err_f:
+err_f:
free(w);
- err:
+err:
return cast_uchar "Error reading terminal specification";
}
-static unsigned char *term2_rd(struct option *o, unsigned char *c)
+static unsigned char *
+term2_rd(struct option *o, unsigned char *c)
{
struct term_spec *ts;
unsigned char *w;
- if (!(w = get_token(&c))) goto err;
+ if (!(w = get_token(&c)))
+ goto err;
ts = new_term_spec(w);
free(w);
- if (!(w = get_token(&c))) goto err;
- if (strlen(cast_const_char w) != 1 || w[0] < '0' || w[0] > '3') goto err_f;
+ if (!(w = get_token(&c)))
+ goto err;
+ if (strlen(cast_const_char w) != 1 || w[0] < '0' || w[0] > '3')
+ goto err_f;
ts->mode = w[0] - '0';
free(w);
- if (!(w = get_token(&c))) goto err;
- if (strlen(cast_const_char w) != 1 || w[0] < '0' || w[0] > '1') goto err_f;
+ if (!(w = get_token(&c)))
+ goto err;
+ if (strlen(cast_const_char w) != 1 || w[0] < '0' || w[0] > '1')
+ goto err_f;
ts->m11_hack = w[0] - '0';
free(w);
- if (!(w = get_token(&c))) goto err;
- if (strlen(cast_const_char w) != 1 || w[0] < '0' || w[0] > '1') goto err_f;
+ if (!(w = get_token(&c)))
+ goto err;
+ if (strlen(cast_const_char w) != 1 || w[0] < '0' || w[0] > '1')
+ goto err_f;
ts->restrict_852 = w[0] - '0';
free(w);
- if (!(w = get_token(&c))) goto err;
- if (strlen(cast_const_char w) != 1 || w[0] < '0' || w[0] > '1') goto err_f;
+ if (!(w = get_token(&c)))
+ goto err;
+ if (strlen(cast_const_char w) != 1 || w[0] < '0' || w[0] > '1')
+ goto err_f;
ts->col = w[0] - '0';
free(w);
- if (!(w = get_token(&c))) goto err;
+ if (!(w = get_token(&c)))
+ goto err;
ts->character_set = 0;
free(w);
return NULL;
- err_f:
+err_f:
free(w);
- err:
+err:
return cast_uchar "Error reading terminal specification";
}
-static void term_wr(struct option *o, unsigned char **s, int *l)
+static void
+term_wr(struct option *o, unsigned char **s, int *l)
{
struct term_spec *ts = NULL;
struct list_head *lts;
- foreachback(struct term_spec, ts, lts, term_specs) {
+ foreachback (struct term_spec, ts, lts, term_specs) {
add_nm(o, s, l);
add_quoted_to_str(s, l, ts->term);
add_chr_to_str(s, l, ' ');
@@ -713,10 +861,13 @@ static void term_wr(struct option *o, unsigned char **s, int *l)
add_chr_to_str(s, l, ' ');
add_num_to_str(s, l, !!ts->m11_hack);
add_chr_to_str(s, l, ' ');
- add_num_to_str(s, l, !!ts->col + !!ts->restrict_852 * 2 + !!ts->block_cursor * 4);
+ add_num_to_str(s, l,
+ !!ts->col + !!ts->restrict_852 * 2
+ + !!ts->block_cursor * 4);
add_chr_to_str(s, l, ' ');
add_to_str(s, l, get_cp_mime_name(ts->character_set));
- if (ts->left_margin || ts->right_margin || ts->top_margin || ts->bottom_margin) {
+ if (ts->left_margin || ts->right_margin || ts->top_margin
+ || ts->bottom_margin) {
add_chr_to_str(s, l, ' ');
add_num_to_str(s, l, ts->left_margin);
add_chr_to_str(s, l, ' ');
@@ -731,14 +882,18 @@ static void term_wr(struct option *o, unsigned char **s, int *l)
static struct list_head driver_params = { &driver_params, &driver_params };
-struct driver_param *get_driver_param(unsigned char *n)
+struct driver_param *
+get_driver_param(unsigned char *n)
{
struct driver_param *dp = NULL;
size_t sl;
struct list_head *ldp;
- foreach(struct driver_param, dp, ldp, driver_params) if (!casestrcmp(dp->name, n)) return dp;
+ foreach (struct driver_param, dp, ldp, driver_params)
+ if (!casestrcmp(dp->name, n))
+ return dp;
sl = strlen(cast_const_char n);
- if (sl > INT_MAX - sizeof(struct driver_param)) overalloc();
+ if (sl > INT_MAX - sizeof(struct driver_param))
+ overalloc();
dp = mem_calloc(sizeof(struct driver_param) + sl);
strcpy(cast_char dp->name, cast_const_char n);
dp->kbd_codepage = -1;
@@ -748,7 +903,8 @@ struct driver_param *get_driver_param(unsigned char *n)
return dp;
}
-static unsigned char *dp_rd(struct option *o, unsigned char *c)
+static unsigned char *
+dp_rd(struct option *o, unsigned char *c)
{
int cc;
unsigned char *n, *param, *cp;
@@ -775,72 +931,93 @@ static unsigned char *dp_rd(struct option *o, unsigned char *c)
dp->kbd_codepage = cc;
dp->nosave = 0;
return NULL;
- err:
+err:
return cast_uchar "Error reading driver mode specification";
}
-static void dp_wr(struct option *o, unsigned char **s, int *l)
+static void
+dp_wr(struct option *o, unsigned char **s, int *l)
{
struct driver_param *dp = NULL;
struct list_head *ldp;
- foreachback(struct driver_param, dp, ldp, driver_params) {
- if ((!dp->param || !*dp->param) && !*dp->shell_term && dp->kbd_codepage < 0 && !dp->palette_mode)
+ foreachback (struct driver_param, dp, ldp, driver_params) {
+ if ((!dp->param || !*dp->param) && !*dp->shell_term
+ && dp->kbd_codepage < 0 && !dp->palette_mode)
+ continue;
+ if (dp->nosave)
continue;
- if (dp->nosave) continue;
add_nm(o, s, l);
add_quoted_to_str(s, l, dp->name);
add_chr_to_str(s, l, ' ');
- add_quoted_to_str(s, l, dp->param ? dp->param : (unsigned char*)"");
+ add_quoted_to_str(s, l,
+ dp->param ? dp->param : (unsigned char *)"");
add_chr_to_str(s, l, ' ');
add_quoted_to_str(s, l, dp->shell_term);
add_chr_to_str(s, l, ' ');
- if (dp->kbd_codepage == -1) add_to_str(s, l, cast_uchar "default");
- else add_to_str(s, l, get_cp_mime_name(dp->kbd_codepage));
+ if (dp->kbd_codepage == -1)
+ add_to_str(s, l, cast_uchar "default");
+ else
+ add_to_str(s, l, get_cp_mime_name(dp->kbd_codepage));
add_chr_to_str(s, l, ' ');
add_num_to_str(s, l, dp->palette_mode);
/* pokud se sem neco prida, opravit podminku na zacatku cyklu */
}
}
-static unsigned char *ip_rd(struct option *o, unsigned char *c)
+static unsigned char *
+ip_rd(struct option *o, unsigned char *c)
{
unsigned char *e;
e = str_rd(o, c);
- if (e) return e;
- if (*(unsigned char *)o->ptr && numeric_ip_address(o->ptr, NULL) == -1) return cast_uchar "Invalid IP address";
+ if (e)
+ return e;
+ if (*(unsigned char *)o->ptr && numeric_ip_address(o->ptr, NULL) == -1)
+ return cast_uchar "Invalid IP address";
return NULL;
}
-static unsigned char *ipv6_rd(struct option *o, unsigned char *c)
+static unsigned char *
+ipv6_rd(struct option *o, unsigned char *c)
{
unsigned char *e;
e = str_rd(o, c);
- if (e) return e;
- if (*(unsigned char *)o->ptr && numeric_ipv6_address(o->ptr, NULL, NULL) == -1) return cast_uchar "Invalid IPv6 address";
+ if (e)
+ return e;
+ if (*(unsigned char *)o->ptr
+ && numeric_ipv6_address(o->ptr, NULL, NULL) == -1)
+ return cast_uchar "Invalid IPv6 address";
return NULL;
}
-static unsigned char *gen_cmd(struct option *o, unsigned char ***argv, int *argc)
+static unsigned char *
+gen_cmd(struct option *o, unsigned char ***argv, int *argc)
{
unsigned char *e;
int l;
unsigned char *r;
- if (!*argc) return cast_uchar "Parameter expected";
+ if (!*argc)
+ return cast_uchar "Parameter expected";
e = init_str();
l = 0;
add_quoted_to_str(&e, &l, **argv);
r = o->rd_cfg ? o->rd_cfg(o, e) : 0;
free(e);
- if (r) return r;
- (*argv)++; (*argc)--;
+ if (r)
+ return r;
+ (*argv)++;
+ (*argc)--;
return NULL;
}
-static unsigned char *x_proxy_cmd(struct option *o, unsigned char ***argv, int *argc, int (*save)(int, unsigned char *, unsigned char *), unsigned char *err)
+static unsigned char *
+x_proxy_cmd(struct option *o, unsigned char ***argv, int *argc,
+ int (*save)(int, unsigned char *, unsigned char *),
+ unsigned char *err)
{
unsigned char **pass_argv;
unsigned char *result, *ret;
- if (!*argc) return cast_uchar "Parameter expected";
+ if (!*argc)
+ return cast_uchar "Parameter expected";
result = xmalloc(MAX_STR_LEN);
if (save(0, result, **argv)) {
free(result);
@@ -849,62 +1026,76 @@ static unsigned char *x_proxy_cmd(struct option *o, unsigned char ***argv, int *
pass_argv = &result;
ret = gen_cmd(o, &pass_argv, argc);
free(result);
- if (ret) return ret;
+ if (ret)
+ return ret;
(*argv)++;
return NULL;
}
-static unsigned char *proxy_cmd(struct option *o, unsigned char ***argv, int *argc)
+static unsigned char *
+proxy_cmd(struct option *o, unsigned char ***argv, int *argc)
{
- return x_proxy_cmd(o, argv, argc, save_proxy, cast_uchar "Invalid proxy");
+ return x_proxy_cmd(o, argv, argc, save_proxy,
+ cast_uchar "Invalid proxy");
}
-static unsigned char *noproxy_cmd(struct option *o, unsigned char ***argv, int *argc)
+static unsigned char *
+noproxy_cmd(struct option *o, unsigned char ***argv, int *argc)
{
- return x_proxy_cmd(o, argv, argc, save_noproxy_list, cast_uchar "Invalid list of domains");
+ return x_proxy_cmd(o, argv, argc, save_noproxy_list,
+ cast_uchar "Invalid list of domains");
}
-static unsigned char *version_cmd(struct option *o, unsigned char ***argv, int *argc)
+static unsigned char *
+version_cmd(struct option *o, unsigned char ***argv, int *argc)
{
printf("Links " VERSION "\n");
fflush(stdout);
exit(RET_OK);
}
-static unsigned char *set_cmd(struct option *o, unsigned char ***argv, int *argc)
+static unsigned char *
+set_cmd(struct option *o, unsigned char ***argv, int *argc)
{
*(int *)o->ptr = 1;
return NULL;
}
-static unsigned char *setstr_cmd(struct option *o, unsigned char ***argv, int *argc)
+static unsigned char *
+setstr_cmd(struct option *o, unsigned char ***argv, int *argc)
{
- if (!*argc) return cast_uchar "Parameter expected";
+ if (!*argc)
+ return cast_uchar "Parameter expected";
safe_strncpy(o->ptr, **argv, o->max);
- (*argv)++; (*argc)--;
+ (*argv)++;
+ (*argc)--;
return NULL;
}
-static unsigned char *dump_cmd(struct option *o, unsigned char ***argv, int *argc)
+static unsigned char *
+dump_cmd(struct option *o, unsigned char ***argv, int *argc)
{
- if (dmp != o->min && dmp) return cast_uchar "Can't use both -dump and -source";
+ if (dmp != o->min && dmp)
+ return cast_uchar "Can't use both -dump and -source";
dmp = o->min;
no_connect = 1;
return NULL;
}
-static unsigned char *printhelp_cmd(struct option *o, unsigned char ***argv, int *argc)
+static unsigned char *
+printhelp_cmd(struct option *o, unsigned char ***argv, int *argc)
{
usage();
/* FIXME: never reached */
return NULL;
}
-void end_config(void)
+void
+end_config(void)
{
struct driver_param *dp = NULL;
struct list_head *ldp;
- foreach(struct driver_param, dp, ldp, driver_params) {
+ foreach (struct driver_param, dp, ldp, driver_params) {
free(dp->param);
}
free_list(struct driver_param, driver_params);
@@ -913,7 +1104,7 @@ void end_config(void)
int anonymous = 0;
-unsigned char default_target[MAX_STR_LEN] ="";
+unsigned char default_target[MAX_STR_LEN] = "";
unsigned char *links_home = NULL;
int first_use = 0;
@@ -944,165 +1135,258 @@ int aggressive_cache = 1;
struct ipv6_options ipv6_options = { ADDR_PREFERENCE_DEFAULT };
struct proxies proxies = { "", "", "", "", "", 0 };
-struct ssl_options ssl_options = { SSL_WARN_ON_INVALID_CERTIFICATE,
- 0,
- "", "", "" };
-struct http_options http_options = { 0, 1, 0, 0, 0, { 0, "", "" } };
+struct ssl_options ssl_options = { SSL_WARN_ON_INVALID_CERTIFICATE, 0, "", "",
+ "" };
+struct http_options http_options = {
+ 0, 1, 0, 0, 0, {0, "", ""}
+};
unsigned char download_dir[MAX_STR_LEN] = "";
-double display_red_gamma=2.2; /* Red gamma exponent of the display */
-double display_green_gamma=2.2; /* Green gamma exponent of the display */
-double display_blue_gamma=2.2; /* Blue gamma exponent of the display */
-double user_gamma=1.0; /* 1.0 for 64 lx. This is the number user directly changes in the menu */
-double bfu_aspect=1; /* 0.1 to 10.0, 1.0 default. >1 makes circle wider */
-int dither_letters=1;
-int dither_images=1;
-int gamma_bits=2; /*0 --- 8, 1 --- 16, 2 --- auto */
+double display_red_gamma = 2.2; /* Red gamma exponent of the display */
+double display_green_gamma = 2.2; /* Green gamma exponent of the display */
+double display_blue_gamma = 2.2; /* Blue gamma exponent of the display */
+double user_gamma = 1.0; /* 1.0 for 64 lx. This is the number user directly
+ changes in the menu */
+double bfu_aspect = 1; /* 0.1 to 10.0, 1.0 default. >1 makes circle wider */
+int dither_letters = 1;
+int dither_images = 1;
+int gamma_bits = 2; /*0 --- 8, 1 --- 16, 2 --- auto */
int overwrite_instead_of_scroll = 1;
-
-unsigned char bookmarks_file[MAX_STR_LEN]="";
+unsigned char bookmarks_file[MAX_STR_LEN] = "";
int save_history = 1;
struct document_setup dds = {
- 0, /* assumed codepage */
- 0, /* ignore codepage from server */
- 1, /* tables */
- 1, /* frames */
- 0, /* break_long_lines */
- 0, /* images */
- 0, /* image_names */
- 3, /* margin */
- 0, /* num_links */
- 0, /* table_order */
- 0, /* auto_refresh */
- 20, /* font_size */
- 1, /* display images */
- 100, /* image scale */
- 0, /* porn enable */
- 0, /* target in new window */
- 7, /* t text color */
- 15, /* t link color */
- 0, /* t background color */
- 0, /* t ignore document color */
+ 0, /* assumed codepage */
+ 0, /* ignore codepage from server */
+ 1, /* tables */
+ 1, /* frames */
+ 0, /* break_long_lines */
+ 0, /* images */
+ 0, /* image_names */
+ 3, /* margin */
+ 0, /* num_links */
+ 0, /* table_order */
+ 0, /* auto_refresh */
+ 20, /* font_size */
+ 1, /* display images */
+ 100, /* image scale */
+ 0, /* porn enable */
+ 0, /* target in new window */
+ 7, /* t text color */
+ 15, /* t link color */
+ 0, /* t background color */
+ 0, /* t ignore document color */
0x000000, /* g text color */
0x0000ff, /* g link color */
0xc0c0c0, /* g background color */
- 0, /* g ignore document color */
+ 0, /* g ignore document color */
};
static struct option links_options[] = {
- {1, printhelp_cmd, NULL, NULL, 0, 0, NULL, NULL, "?"},
- {1, printhelp_cmd, NULL, NULL, 0, 0, NULL, NULL, "h"},
- {1, printhelp_cmd, NULL, NULL, 0, 0, NULL, NULL, "help"},
- {1, printhelp_cmd, NULL, NULL, 0, 0, NULL, NULL, "-help"},
- {1, version_cmd, NULL, NULL, 0, 0, NULL, NULL, "version"},
- {1, set_cmd, NULL, NULL, 0, 0, &no_connect, NULL, "no-connect"},
- {1, set_cmd, NULL, NULL, 0, 0, &anonymous, NULL, "anonymous"},
- {1, setstr_cmd, NULL, NULL, 0, MAX_STR_LEN, default_target, NULL, "target"},
- {1, gen_cmd, num_rd, NULL, 0, INT_MAX, &base_session, NULL, "base-session"},
- {1, set_cmd, NULL, NULL, 0, 0, &force_html, NULL, "force-html"},
- {1, dump_cmd, NULL, NULL, D_SOURCE, 0, NULL, NULL, "source"},
- {1, dump_cmd, NULL, NULL, D_DUMP, 0, NULL, NULL, "dump"},
- {1, gen_cmd, num_rd, NULL, 10, 512, &screen_width, "dump_width", "width" },
- {1, gen_cmd, cp_rd, NULL, 1, 0, &dump_codepage, "dump_codepage", "codepage" },
- {1, gen_cmd, str_rd, str_wr, 0, MAX_STR_LEN, download_dir, "download_dir", "download-dir"},
- {1, gen_cmd, num_rd, num_wr, 1, 99, &max_connections, "max_connections", "max-connections"},
- {1, gen_cmd, num_rd, num_wr, 1, 99, &max_connections_to_host, "max_connections_to_host", "max-connections-to-host"},
- {1, gen_cmd, num_rd, num_wr, 0, 16, &max_tries, "retries", "retries"},
- {1, gen_cmd, num_rd, num_wr, 1, 9999, &receive_timeout, "receive_timeout", "receive-timeout"},
- {1, gen_cmd, num_rd, num_wr, 1, 9999, &unrestartable_receive_timeout, "unrestartable_receive_timeout", "unrestartable-receive-timeout"},
- {1, gen_cmd, num_rd, num_wr, 1, 999, &timeout_multiple_addresses, "timeout_when_trying_multiple_addresses", "timeout-when-trying-multiple-addresses"},
- {1, gen_cmd, ip_rd, str_wr, 0, 16, bind_ip_address, "bind_address", "bind-address"},
- {1, gen_cmd, ipv6_rd, str_wr, 0, INET6_ADDRSTRLEN, bind_ipv6_address, "bind_address_ipv6", "bind-address-ipv6"},
- {1, set_cmd, NULL, NULL, 0, 0, &disable_libevent, NULL, "no-libevent"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &download_utime, "download_utime", "download-utime"},
- {1, gen_cmd, num_rd, num_wr, 0, 999, &max_format_cache_entries, "format_cache_size", "format-cache-size"},
- {1, gen_cmd, num_rd, num_wr, 0, INT_MAX, &memory_cache_size, "memory_cache_size", "memory-cache-size"},
- {1, gen_cmd, num_rd, num_wr, 0, INT_MAX, &image_cache_size, "image_cache_size", "image-cache-size"},
- {1, gen_cmd, num_rd, num_wr, 0, INT_MAX, &font_cache_size, "font_cache_size", "font-cache-size"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &aggressive_cache, "http_bugs.aggressive_cache", "aggressive-cache"},
- {1, gen_cmd, num_rd, num_wr, 0, 4, &ipv6_options.addr_preference, "ipv6.address_preference", "address-preference"},
- {1, proxy_cmd, str_rd, str_wr, 0, MAX_STR_LEN, proxies.http_proxy, "http_proxy", "http-proxy"},
- {1, proxy_cmd, str_rd, str_wr, 0, MAX_STR_LEN, proxies.https_proxy, "https_proxy", "https-proxy"},
- {1, proxy_cmd, str_rd, str_wr, 0, MAX_STR_LEN, proxies.socks_proxy, "socks_proxy", "socks-proxy"},
- {1, gen_cmd, str_rd, NULL, 0, MAX_STR_LEN, proxies.dns_append, "-append_text_to_dns_lookups", NULL}, /* old version incorrectly saved it with '-' */
- {1, noproxy_cmd, str_rd, str_wr, 0, MAX_STR_LEN, proxies.no_proxy, "no_proxy_domains", "no-proxy-domains"},
- {1, gen_cmd, str_rd, str_wr, 0, MAX_STR_LEN, proxies.dns_append, "append_text_to_dns_lookups", "append-text-to-dns-lookups"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &proxies.only_proxies, "only_proxies", "only-proxies"},
- {1, gen_cmd, num_rd, num_wr, 0, 2, &ssl_options.certificates, "ssl.certificates", "ssl.certificates"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &ssl_options.built_in_certificates, "ssl.builtin_certificates", "ssl.builtin-certificates"},
- {1, gen_cmd, str_rd, str_wr, 0, MAX_STR_LEN, &ssl_options.client_cert_key, "ssl.client_cert_key", "ssl.client-cert-key"},
- {1, gen_cmd, str_rd, str_wr, 0, MAX_STR_LEN, &ssl_options.client_cert_crt, "ssl.client_cert_crt", "ssl.client-cert-crt"},
- {1, gen_cmd, str_rd, NULL, 0, MAX_STR_LEN, &ssl_options.client_cert_password, NULL, "ssl.client-cert-password"},
- {1, gen_cmd, str_rd, NULL, 0, MAX_STR_LEN, &ssl_options.client_cert_key, "client_cert_key", "http.client_cert_key"}, /* backward compatibility with Debian patches */
- {1, gen_cmd, str_rd, NULL, 0, MAX_STR_LEN, &ssl_options.client_cert_crt, "client_cert_crt", "http.client_cert_crt"}, /* backward compatibility with Debian patches */
- {1, gen_cmd, num_rd, num_wr, 0, 1, &http_options.http10, "http_bugs.http10", "http-bugs.http10"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &http_options.allow_blacklist, "http_bugs.allow_blacklist", "http-bugs.allow-blacklist"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &http_options.no_accept_charset, "http_bugs.no_accept_charset", "http-bugs.bug-no-accept-charset"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &http_options.no_compression, "http_bugs.no_compression", "http-bugs.no-compression"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &http_options.retry_internal_errors, "http_bugs.retry_internal_errors", "http-bugs.retry-internal-errors"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &http_options.header.fake_firefox, "fake_firefox", "http.fake-firefox"},
- {1, gen_cmd, str_rd, str_wr, 0, MAX_STR_LEN, &http_options.header.fake_useragent, "fake_useragent", "http.fake-user-agent"},
- {1, gen_cmd, str_rd, str_wr, 0, MAX_STR_LEN, &http_options.header.extra_header, "http.extra_header", "http.extra-header"},
- {1, gen_cmd, str_rd, str_wr, 0, MAX_STR_LEN, bookmarks_file, "bookmarks_file", "bookmarks-file"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &save_history, "save_url_history", "save-url-history"},
- {1, gen_cmd, dbl_rd, dbl_wr, 1, 10000, &display_red_gamma, "display_red_gamma", "display-red-gamma"},
- {1, gen_cmd, dbl_rd, dbl_wr, 1, 10000, &display_green_gamma, "display_green_gamma", "display-green-gamma"},
- {1, gen_cmd, dbl_rd, dbl_wr, 1, 10000, &display_blue_gamma, "display_blue_gamma", "display-blue-gamma"},
- {1, gen_cmd, dbl_rd, dbl_wr, 1, 10000, &user_gamma, "user_gamma", "user-gamma"},
- {1, gen_cmd, dbl_rd, dbl_wr, 25, 400, &bfu_aspect, "bfu_aspect", "bfu-aspect"},
- {1, gen_cmd, NULL, NULL, 0, 1, NULL, "aspect_on", NULL},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &dither_letters, "dither_letters", "dither-letters"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &dither_images, "dither_images", "dither-images"},
- {1, gen_cmd, num_rd, num_wr, 0, 2, &gamma_bits, "gamma_correction", "gamma-correction"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &overwrite_instead_of_scroll, "overwrite_instead_of_scroll", "overwrite-instead-of-scroll"},
- {1, gen_cmd, cp_rd, NULL, 0, 0, &dds.assume_cp, "assume_codepage", NULL},
- {1, NULL, term_rd, term_wr, 0, 0, NULL, "terminal", NULL},
- {1, NULL, term2_rd, NULL, 0, 0, NULL, "terminal2", NULL},
- {1, NULL, type_rd, type_wr, 0, 0, NULL, "association", NULL},
- {1, NULL, ext_rd, ext_wr, 0, 0, NULL, "extension", NULL},
- {1, NULL, dp_rd, dp_wr, 0, 0, NULL, "video_driver", NULL},
- {0, NULL, NULL, NULL, 0, 0, NULL, NULL, NULL},
+ {1, printhelp_cmd, NULL, NULL, 0, 0, NULL, NULL, "?" },
+ { 1, printhelp_cmd, NULL, NULL, 0, 0, NULL, NULL, "h" },
+ { 1, printhelp_cmd, NULL, NULL, 0, 0, NULL, NULL, "help" },
+ { 1, printhelp_cmd, NULL, NULL, 0, 0, NULL, NULL, "-help" },
+ { 1, version_cmd, NULL, NULL, 0, 0, NULL, NULL, "version" },
+ { 1, set_cmd, NULL, NULL, 0, 0, &no_connect, NULL, "no-connect" },
+ { 1, set_cmd, NULL, NULL, 0, 0, &anonymous, NULL, "anonymous" },
+ { 1, setstr_cmd, NULL, NULL, 0, MAX_STR_LEN, default_target, NULL,
+ "target" },
+ { 1, gen_cmd, num_rd, NULL, 0, INT_MAX, &base_session, NULL,
+ "base-session" },
+ { 1, set_cmd, NULL, NULL, 0, 0, &force_html, NULL, "force-html" },
+ { 1, dump_cmd, NULL, NULL, D_SOURCE, 0, NULL, NULL, "source" },
+ { 1, dump_cmd, NULL, NULL, D_DUMP, 0, NULL, NULL, "dump" },
+ { 1, gen_cmd, num_rd, NULL, 10, 512, &screen_width, "dump_width",
+ "width" },
+ { 1, gen_cmd, cp_rd, NULL, 1, 0, &dump_codepage, "dump_codepage",
+ "codepage" },
+ { 1, gen_cmd, str_rd, str_wr, 0, MAX_STR_LEN, download_dir,
+ "download_dir", "download-dir" },
+ { 1, gen_cmd, num_rd, num_wr, 1, 99, &max_connections,
+ "max_connections", "max-connections" },
+ { 1, gen_cmd, num_rd, num_wr, 1, 99, &max_connections_to_host,
+ "max_connections_to_host", "max-connections-to-host" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 16, &max_tries, "retries", "retries" },
+ { 1, gen_cmd, num_rd, num_wr, 1, 9999, &receive_timeout,
+ "receive_timeout", "receive-timeout" },
+ { 1, gen_cmd, num_rd, num_wr, 1, 9999, &unrestartable_receive_timeout,
+ "unrestartable_receive_timeout", "unrestartable-receive-timeout" },
+ { 1, gen_cmd, num_rd, num_wr, 1, 999, &timeout_multiple_addresses,
+ "timeout_when_trying_multiple_addresses", "timeout-when-trying-multiple-addresses"},
+ { 1, gen_cmd, ip_rd, str_wr, 0, 16, bind_ip_address, "bind_address",
+ "bind-address" },
+ { 1, gen_cmd, ipv6_rd, str_wr, 0, INET6_ADDRSTRLEN, bind_ipv6_address,
+ "bind_address_ipv6", "bind-address-ipv6" },
+ { 1, set_cmd, NULL, NULL, 0, 0, &disable_libevent, NULL,
+ "no-libevent" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &download_utime, "download_utime",
+ "download-utime" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 999, &max_format_cache_entries,
+ "format_cache_size", "format-cache-size" },
+ { 1, gen_cmd, num_rd, num_wr, 0, INT_MAX, &memory_cache_size,
+ "memory_cache_size", "memory-cache-size" },
+ { 1, gen_cmd, num_rd, num_wr, 0, INT_MAX, &image_cache_size,
+ "image_cache_size", "image-cache-size" },
+ { 1, gen_cmd, num_rd, num_wr, 0, INT_MAX, &font_cache_size,
+ "font_cache_size", "font-cache-size" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &aggressive_cache,
+ "http_bugs.aggressive_cache", "aggressive-cache" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 4, &ipv6_options.addr_preference,
+ "ipv6.address_preference", "address-preference" },
+ { 1, proxy_cmd, str_rd, str_wr, 0, MAX_STR_LEN, proxies.http_proxy,
+ "http_proxy", "http-proxy" },
+ { 1, proxy_cmd, str_rd, str_wr, 0, MAX_STR_LEN, proxies.https_proxy,
+ "https_proxy", "https-proxy" },
+ { 1, proxy_cmd, str_rd, str_wr, 0, MAX_STR_LEN, proxies.socks_proxy,
+ "socks_proxy", "socks-proxy" },
+ { 1, gen_cmd, str_rd, NULL, 0, MAX_STR_LEN, proxies.dns_append,
+ "-append_text_to_dns_lookups", NULL }, /* old version incorrectly saved it with '-' */
+ { 1, noproxy_cmd, str_rd, str_wr, 0, MAX_STR_LEN, proxies.no_proxy,
+ "no_proxy_domains", "no-proxy-domains" },
+ { 1, gen_cmd, str_rd, str_wr, 0, MAX_STR_LEN, proxies.dns_append,
+ "append_text_to_dns_lookups", "append-text-to-dns-lookups" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &proxies.only_proxies,
+ "only_proxies", "only-proxies" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 2, &ssl_options.certificates,
+ "ssl.certificates", "ssl.certificates" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &ssl_options.built_in_certificates,
+ "ssl.builtin_certificates", "ssl.builtin-certificates" },
+ { 1, gen_cmd, str_rd, str_wr, 0, MAX_STR_LEN,
+ &ssl_options.client_cert_key, "ssl.client_cert_key",
+ "ssl.client-cert-key" },
+ { 1, gen_cmd, str_rd, str_wr, 0, MAX_STR_LEN,
+ &ssl_options.client_cert_crt, "ssl.client_cert_crt",
+ "ssl.client-cert-crt" },
+ { 1, gen_cmd, str_rd, NULL, 0, MAX_STR_LEN,
+ &ssl_options.client_cert_password, NULL, "ssl.client-cert-password" },
+ { 1, gen_cmd, str_rd, NULL, 0, MAX_STR_LEN,
+ &ssl_options.client_cert_key, "client_cert_key",
+ "http.client_cert_key" }, /* backward compatibility with Debian
+ patches */
+ { 1, gen_cmd, str_rd, NULL, 0, MAX_STR_LEN,
+ &ssl_options.client_cert_crt, "client_cert_crt",
+ "http.client_cert_crt" }, /* backward compatibility with Debian
+ patches */
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &http_options.http10,
+ "http_bugs.http10", "http-bugs.http10" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &http_options.allow_blacklist,
+ "http_bugs.allow_blacklist", "http-bugs.allow-blacklist" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &http_options.no_accept_charset,
+ "http_bugs.no_accept_charset", "http-bugs.bug-no-accept-charset" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &http_options.no_compression,
+ "http_bugs.no_compression", "http-bugs.no-compression" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &http_options.retry_internal_errors,
+ "http_bugs.retry_internal_errors", "http-bugs.retry-internal-errors" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &http_options.header.fake_firefox,
+ "fake_firefox", "http.fake-firefox" },
+ { 1, gen_cmd, str_rd, str_wr, 0, MAX_STR_LEN,
+ &http_options.header.fake_useragent, "fake_useragent",
+ "http.fake-user-agent" },
+ { 1, gen_cmd, str_rd, str_wr, 0, MAX_STR_LEN,
+ &http_options.header.extra_header, "http.extra_header",
+ "http.extra-header" },
+ { 1, gen_cmd, str_rd, str_wr, 0, MAX_STR_LEN, bookmarks_file,
+ "bookmarks_file", "bookmarks-file" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &save_history, "save_url_history",
+ "save-url-history" },
+ { 1, gen_cmd, dbl_rd, dbl_wr, 1, 10000, &display_red_gamma,
+ "display_red_gamma", "display-red-gamma" },
+ { 1, gen_cmd, dbl_rd, dbl_wr, 1, 10000, &display_green_gamma,
+ "display_green_gamma", "display-green-gamma" },
+ { 1, gen_cmd, dbl_rd, dbl_wr, 1, 10000, &display_blue_gamma,
+ "display_blue_gamma", "display-blue-gamma" },
+ { 1, gen_cmd, dbl_rd, dbl_wr, 1, 10000, &user_gamma, "user_gamma",
+ "user-gamma" },
+ { 1, gen_cmd, dbl_rd, dbl_wr, 25, 400, &bfu_aspect, "bfu_aspect",
+ "bfu-aspect" },
+ { 1, gen_cmd, NULL, NULL, 0, 1, NULL, "aspect_on", NULL },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &dither_letters, "dither_letters",
+ "dither-letters" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &dither_images, "dither_images",
+ "dither-images" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 2, &gamma_bits, "gamma_correction",
+ "gamma-correction" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &overwrite_instead_of_scroll,
+ "overwrite_instead_of_scroll", "overwrite-instead-of-scroll" },
+ { 1, gen_cmd, cp_rd, NULL, 0, 0, &dds.assume_cp, "assume_codepage",
+ NULL },
+ { 1, NULL, term_rd, term_wr, 0, 0, NULL, "terminal", NULL },
+ { 1, NULL, term2_rd, NULL, 0, 0, NULL, "terminal2", NULL },
+ { 1, NULL, type_rd, type_wr, 0, 0, NULL, "association", NULL },
+ { 1, NULL, ext_rd, ext_wr, 0, 0, NULL, "extension", NULL },
+ { 1, NULL, dp_rd, dp_wr, 0, 0, NULL, "video_driver", NULL },
+ { 0, NULL, NULL, NULL, 0, 0, NULL, NULL, NULL },
};
static struct option html_options[] = {
- {1, gen_cmd, cp_rd, cp_wr, 0, 0, &dds.assume_cp, "html_assume_codepage", "html-assume-codepage"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &dds.hard_assume, "html_hard_assume", "html-hard-assume"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &dds.tables, "html_tables", "html-tables"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &dds.frames, "html_frames", "html-frames"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &dds.break_long_lines, "html_break_long_lines", "html-break-long-lines"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &dds.images, "html_images", "html-images"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &dds.image_names, "html_image_names", "html-image-names"},
- {1, gen_cmd, num_rd, num_wr, 0, 9, &dds.margin, "html_margin", "html-margin"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &dds.num_links, "html_numbered_links", "html-numbered-links"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &dds.table_order, "html_table_order", "html-table-order"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &dds.auto_refresh, "html_auto_refresh", "html-auto-refresh"},
- {1, gen_cmd, num_rd, num_wr, 1, MAX_FONT_SIZE, &dds.font_size, "html_font_size", "html-user-font-size"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &dds.display_images, "html_display_images", "html-display-images"},
- {1, gen_cmd, num_rd, num_wr, 1, 999, &dds.image_scale, "html_image_scale", "html-image-scale"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &dds.porn_enable, "html_bare_image_autoscale", "html-bare-image-autoscale"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &dds.target_in_new_window, "html_target_in_new_window", "html-target-in-new-window"},
- {1, gen_cmd, num_rd, num_wr, 0, 15, &dds.t_text_color, "html_text_color", "html-text-color"},
- {1, gen_cmd, num_rd, num_wr, 0, 15, &dds.t_link_color, "html_link_color", "html-link-color"},
- {1, gen_cmd, num_rd, num_wr, 0, 7, &dds.t_background_color, "html_background_color", "html-background-color"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &dds.t_ignore_document_color, "html_ignore_document_color", "html-ignore-document-color"},
- {1, gen_cmd, num_rd, num_wr, 0, 0xffffff, &dds.g_text_color, "html_g_text_color", "html-g-text-color"},
- {1, gen_cmd, num_rd, num_wr, 0, 0xffffff, &dds.g_link_color, "html_g_link_color", "html-g-link-color"},
- {1, gen_cmd, num_rd, num_wr, 0, 0xffffff, &dds.g_background_color, "html_g_background_color", "html-g-background-color"},
- {1, gen_cmd, num_rd, num_wr, 0, 1, &dds.g_ignore_document_color, "html_g_ignore_document_color", "html-g-ignore-document-color"},
- {0, NULL, NULL, NULL, 0, 0, NULL, NULL, NULL},
+ {1, gen_cmd, cp_rd, cp_wr, 0, 0, &dds.assume_cp,
+ "html_assume_codepage", "html-assume-codepage" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &dds.hard_assume,
+ "html_hard_assume", "html-hard-assume" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &dds.tables, "html_tables",
+ "html-tables" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &dds.frames, "html_frames",
+ "html-frames" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &dds.break_long_lines,
+ "html_break_long_lines", "html-break-long-lines" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &dds.images, "html_images",
+ "html-images" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &dds.image_names,
+ "html_image_names", "html-image-names" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 9, &dds.margin, "html_margin",
+ "html-margin" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &dds.num_links,
+ "html_numbered_links", "html-numbered-links" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &dds.table_order,
+ "html_table_order", "html-table-order" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &dds.auto_refresh,
+ "html_auto_refresh", "html-auto-refresh" },
+ { 1, gen_cmd, num_rd, num_wr, 1, MAX_FONT_SIZE, &dds.font_size,
+ "html_font_size", "html-user-font-size" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &dds.display_images,
+ "html_display_images", "html-display-images" },
+ { 1, gen_cmd, num_rd, num_wr, 1, 999, &dds.image_scale,
+ "html_image_scale", "html-image-scale" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &dds.porn_enable,
+ "html_bare_image_autoscale", "html-bare-image-autoscale" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &dds.target_in_new_window,
+ "html_target_in_new_window", "html-target-in-new-window" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 15, &dds.t_text_color,
+ "html_text_color", "html-text-color" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 15, &dds.t_link_color,
+ "html_link_color", "html-link-color" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 7, &dds.t_background_color,
+ "html_background_color", "html-background-color" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &dds.t_ignore_document_color,
+ "html_ignore_document_color", "html-ignore-document-color" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 0xffffff, &dds.g_text_color,
+ "html_g_text_color", "html-g-text-color" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 0xffffff, &dds.g_link_color,
+ "html_g_link_color", "html-g-link-color" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 0xffffff, &dds.g_background_color,
+ "html_g_background_color", "html-g-background-color" },
+ { 1, gen_cmd, num_rd, num_wr, 0, 1, &dds.g_ignore_document_color,
+ "html_g_ignore_document_color", "html-g-ignore-document-color"},
+ { 0, NULL, NULL, NULL, 0, 0, NULL, NULL, NULL },
};
-static struct option *all_options[] = { links_options, html_options, NULL, };
+static struct option *all_options[] = {
+ links_options,
+ html_options,
+ NULL,
+};
-unsigned char *parse_options(int argc, char *argv[])
+unsigned char *
+parse_options(int argc, char *argv[])
{
int i;
unsigned char **u_argv, *ret;
- if ((argc * sizeof(unsigned char *)) > INT_MAX) overalloc();
+ if ((argc * sizeof(unsigned char *)) > INT_MAX)
+ overalloc();
u_argv = xmalloc(argc * sizeof(unsigned char *));
for (i = 0; i < argc; i++)
u_argv[i] = cast_uchar argv[i];
@@ -1111,28 +1395,34 @@ unsigned char *parse_options(int argc, char *argv[])
return ret;
}
-static void load_config_file(unsigned char *prefix, unsigned char *name)
+static void
+load_config_file(unsigned char *prefix, unsigned char *name)
{
unsigned char *c, *config_file;
config_file = stracpy(prefix);
- if (!config_file) return;
+ if (!config_file)
+ return;
add_to_strn(&config_file, name);
- if ((c = read_config_file(config_file))) goto ok;
+ if ((c = read_config_file(config_file)))
+ goto ok;
free(config_file);
config_file = stracpy(prefix);
- if (!config_file) return;
+ if (!config_file)
+ return;
add_to_strn(&config_file, cast_uchar ".");
add_to_strn(&config_file, name);
- if ((c = read_config_file(config_file))) goto ok;
+ if ((c = read_config_file(config_file)))
+ goto ok;
free(config_file);
return;
- ok:
+ok:
parse_config_file(config_file, c, all_options);
free(c);
free(config_file);
}
-void load_config(void)
+void
+load_config(void)
{
#ifdef SHARED_CONFIG_DIR
load_config_file(cast_uchar SHARED_CONFIG_DIR, cast_uchar "links.cfg");
@@ -1142,30 +1432,38 @@ void load_config(void)
load_config_file(links_home, cast_uchar "user.cfg");
}
-void write_config(struct terminal *term)
+void
+write_config(struct terminal *term)
{
- write_config_data(links_home, cast_uchar "links.cfg", links_options, term);
+ write_config_data(links_home, cast_uchar "links.cfg", links_options,
+ term);
}
-void write_html_config(struct terminal *term)
+void
+write_html_config(struct terminal *term)
{
- write_config_data(links_home, cast_uchar "html.cfg", html_options, term);
+ write_config_data(links_home, cast_uchar "html.cfg", html_options,
+ term);
}
-void load_url_history(void)
+void
+load_url_history(void)
{
unsigned char *history_file, *hs;
unsigned char *hsp;
- if (anonymous) return;
+ if (anonymous)
+ return;
/* Must have been called after init_home */
- if (!links_home) return;
+ if (!links_home)
+ return;
history_file = stracpy(links_home);
add_to_strn(&history_file, cast_uchar "links.his");
hs = read_config_file(history_file);
free(history_file);
- if (!hs) return;
- for (hsp = hs; *hsp; ) {
+ if (!hs)
+ return;
+ for (hsp = hs; *hsp;) {
unsigned char *hsl, *hsc;
for (hsl = hsp; *hsl && *hsl != 10 && *hsl != 13; hsl++)
;
@@ -1173,28 +1471,35 @@ void load_url_history(void)
add_to_history(NULL, &goto_url_history, hsc);
free(hsc);
hsp = hsl;
- while (*hsp == 10 || *hsp == 13) hsp++;
+ while (*hsp == 10 || *hsp == 13)
+ hsp++;
}
free(hs);
}
-void save_url_history(void)
+void
+save_url_history(void)
{
struct history_item *hi = NULL;
struct list_head *lhi;
unsigned char *history_file;
unsigned char *hs;
int hsl = 0;
- if (anonymous || !save_history || proxies.only_proxies) return;
+ if (anonymous || !save_history || proxies.only_proxies)
+ return;
/* Must have been called after init_home */
- if (!links_home) return;
+ if (!links_home)
+ return;
history_file = stracpy(links_home);
add_to_strn(&history_file, cast_uchar "links.his");
hs = init_str();
hsl = 0;
- foreachback(struct history_item, hi, lhi, goto_url_history.items) {
- if (!*hi->str || hi->str[0] == ' ' || strchr(cast_const_char hi->str, 10) || strchr(cast_const_char hi->str, 13)) continue;
+ foreachback (struct history_item, hi, lhi, goto_url_history.items) {
+ if (!*hi->str || hi->str[0] == ' '
+ || strchr(cast_const_char hi->str, 10)
+ || strchr(cast_const_char hi->str, 13))
+ continue;
if (!url_not_saveable(hi->str)) {
add_to_str(&hs, &hsl, hi->str);
add_to_str(&hs, &hsl, cast_uchar "\n");
@@ -1205,4 +1510,3 @@ void save_url_history(void)
free(hs);
return;
}
-
diff --git a/dns.c b/dns.c
@@ -7,8 +7,7 @@
#include "links.h"
struct dnsentry {
- list_entry_1st
- uttime absolute_time;
+ list_entry_1st uttime absolute_time;
struct lookup_result addr;
char name[1];
};
@@ -24,12 +23,13 @@ struct dnsquery {
};
static int dns_cache_addr_preference = -1;
-static struct list_head dns_cache = {&dns_cache, &dns_cache};
+static struct list_head dns_cache = { &dns_cache, &dns_cache };
static void end_dns_lookup(struct dnsquery *q, int a);
static int shrink_dns_cache(int u);
-static int get_addr_byte(const char *p, char *res, const char stp)
+static int
+get_addr_byte(const char *p, char *res, const char stp)
{
char u = 0;
if (!(*p >= '0' && *p <= '9'))
@@ -39,38 +39,44 @@ static int get_addr_byte(const char *p, char *res, const char stp)
return -1;
u = u * 10 + *p - '0';
}
- if (*p != stp) return -1;
+ if (*p != stp)
+ return -1;
p++;
*res = u;
return 0;
}
-int numeric_ip_address(const char *name, char address[4])
+int
+numeric_ip_address(const char *name, char address[4])
{
char dummy[4];
if (!address)
address = dummy;
if (get_addr_byte(name, address + 0, '.')
- || get_addr_byte(name, address + 1, '.')
- || get_addr_byte(name, address + 2, '.')
- || get_addr_byte(name, address + 3, 0))
+ || get_addr_byte(name, address + 1, '.')
+ || get_addr_byte(name, address + 2, '.')
+ || get_addr_byte(name, address + 3, 0))
return -1;
return 0;
}
-static int extract_ipv6_address(struct addrinfo *p, char address[16], unsigned *scope_id)
+static int
+extract_ipv6_address(struct addrinfo *p, char address[16], unsigned *scope_id)
{
if (p->ai_family == AF_INET6
- && (socklen_t)p->ai_addrlen >= (socklen_t)sizeof(struct sockaddr_in6)
- && p->ai_addr->sa_family == AF_INET6) {
- memcpy(address, &((struct sockaddr_in6 *)p->ai_addr)->sin6_addr, 16);
+ && (socklen_t)p->ai_addrlen
+ >= (socklen_t)sizeof(struct sockaddr_in6)
+ && p->ai_addr->sa_family == AF_INET6) {
+ memcpy(address, &((struct sockaddr_in6 *)p->ai_addr)->sin6_addr,
+ 16);
*scope_id = ((struct sockaddr_in6 *)p->ai_addr)->sin6_scope_id;
return 0;
}
return -1;
}
-int numeric_ipv6_address(const char *name, char address[16], unsigned *scope_id)
+int
+numeric_ipv6_address(const char *name, char address[16], unsigned *scope_id)
{
char dummy_a[16];
unsigned dummy_s;
@@ -101,7 +107,8 @@ int numeric_ipv6_address(const char *name, char address[16], unsigned *scope_id)
}
#if MAX_ADDRESSES > 1
-static int memcmp_host_address(struct host_address *a, struct host_address *b)
+static int
+memcmp_host_address(struct host_address *a, struct host_address *b)
{
if (a->af != b->af || a->scope_id != b->scope_id)
return 1;
@@ -109,8 +116,9 @@ static int memcmp_host_address(struct host_address *a, struct host_address *b)
}
#endif
-static void add_address(struct lookup_result *host, int af,
- unsigned char *address, unsigned scope_id, int preference)
+static void
+add_address(struct lookup_result *host, int af, unsigned char *address,
+ unsigned scope_id, int preference)
{
struct host_address neww;
struct host_address *e, *t;
@@ -118,8 +126,8 @@ static void add_address(struct lookup_result *host, int af,
struct host_address *n;
#endif
if ((af != AF_INET && preference == ADDR_PREFERENCE_IPV4_ONLY)
- || (af != AF_INET6 && preference == ADDR_PREFERENCE_IPV6_ONLY)
- || (host->n >= MAX_ADDRESSES))
+ || (af != AF_INET6 && preference == ADDR_PREFERENCE_IPV6_ONLY)
+ || (host->n >= MAX_ADDRESSES))
return;
memset(&neww, 0, sizeof(struct host_address));
neww.af = af;
@@ -132,9 +140,9 @@ static void add_address(struct lookup_result *host, int af,
if (!memcmp_host_address(n, &neww))
return;
if ((preference == ADDR_PREFERENCE_IPV4 && af == AF_INET
- && n->af != AF_INET)
- || (preference == ADDR_PREFERENCE_IPV6 && af == AF_INET6
- && n->af != AF_INET6)) {
+ && n->af != AF_INET)
+ || (preference == ADDR_PREFERENCE_IPV6 && af == AF_INET6
+ && n->af != AF_INET6)) {
t = n;
break;
}
@@ -145,7 +153,9 @@ static void add_address(struct lookup_result *host, int af,
host->n++;
}
-static int use_getaddrinfo(unsigned char *name, struct addrinfo *hints, int preference, struct lookup_result *host)
+static int
+use_getaddrinfo(unsigned char *name, struct addrinfo *hints, int preference,
+ struct lookup_result *host)
{
int gai_err;
struct addrinfo *res, *p;
@@ -154,19 +164,23 @@ static int use_getaddrinfo(unsigned char *name, struct addrinfo *hints, int pref
return gai_err;
for (p = res; p; p = p->ai_next) {
if (p->ai_family == AF_INET
- && (socklen_t)p->ai_addrlen >= (socklen_t)sizeof(struct sockaddr_in)
- && p->ai_addr->sa_family == AF_INET) {
- add_address(host, AF_INET,
- (unsigned char *)&((struct sockaddr_in *)p->ai_addr)->sin_addr.s_addr,
- 0, preference);
+ && (socklen_t)p->ai_addrlen
+ >= (socklen_t)sizeof(struct sockaddr_in)
+ && p->ai_addr->sa_family == AF_INET) {
+ add_address(
+ host, AF_INET,
+ (unsigned char *)&((struct sockaddr_in *)p->ai_addr)
+ ->sin_addr.s_addr,
+ 0, preference);
continue;
}
{
unsigned char address[16];
unsigned scope_id;
- if (!extract_ipv6_address(p, (char *)address, &scope_id)) {
+ if (!extract_ipv6_address(p, (char *)address,
+ &scope_id)) {
add_address(host, AF_INET6, address, scope_id,
- preference);
+ preference);
continue;
}
}
@@ -175,7 +189,8 @@ static int use_getaddrinfo(unsigned char *name, struct addrinfo *hints, int pref
return 0;
}
-void rotate_addresses(struct lookup_result *host)
+void
+rotate_addresses(struct lookup_result *host)
{
#if MAX_ADDRESSES > 1
int first_type, first_different, i;
@@ -196,14 +211,17 @@ void rotate_addresses(struct lookup_result *host)
do_swap:
if (first_different > 1) {
struct host_address ha;
- memcpy(&ha, &host->a[first_different], sizeof(struct host_address));
- memmove(&host->a[2], &host->a[1], (first_different - 1) * sizeof(struct host_address));
+ memcpy(&ha, &host->a[first_different],
+ sizeof(struct host_address));
+ memmove(&host->a[2], &host->a[1],
+ (first_different - 1) * sizeof(struct host_address));
memcpy(&host->a[1], &ha, sizeof(struct host_address));
}
#endif
}
-static void do_real_lookup(unsigned char *name, int preference, struct lookup_result *host)
+static void
+do_real_lookup(unsigned char *name, int preference, struct lookup_result *host)
{
unsigned char address[16];
size_t nl;
@@ -211,8 +229,8 @@ static void do_real_lookup(unsigned char *name, int preference, struct lookup_re
memset(host, 0, sizeof(struct lookup_result));
if (strlen(cast_const_char name) >= 6
- && !casestrcmp(name + strlen(cast_const_char name) - 6,
- cast_uchar ".onion"))
+ && !casestrcmp(name + strlen(cast_const_char name) - 6,
+ cast_uchar ".onion"))
goto ret;
if (!support_ipv6)
@@ -224,30 +242,35 @@ static void do_real_lookup(unsigned char *name, int preference, struct lookup_re
}
nl = strlen(cast_const_char name);
if (name[0] == '[' && name[nl - 1] == ']') {
- unsigned char *n2 = cast_uchar strdup(cast_const_char(name + 1));
+ unsigned char *n2 =
+ cast_uchar strdup(cast_const_char(name + 1));
if (n2) {
unsigned scope_id;
n2[nl - 2] = 0;
- if (!numeric_ipv6_address((char *)n2, (char *)address, &scope_id)) {
+ if (!numeric_ipv6_address((char *)n2, (char *)address,
+ &scope_id)) {
free(n2);
- add_address(host, AF_INET6, address, scope_id, preference);
+ add_address(host, AF_INET6, address, scope_id,
+ preference);
goto ret;
}
free(n2);
}
} else {
unsigned scope_id;
- if (!numeric_ipv6_address((char *)name, (char *)address, &scope_id)) {
- add_address(host, AF_INET6, address, scope_id, preference);
+ if (!numeric_ipv6_address((char *)name, (char *)address,
+ &scope_id)) {
+ add_address(host, AF_INET6, address, scope_id,
+ preference);
goto ret;
}
}
use_getaddrinfo(name, NULL, preference, host);
#if defined(EXTRA_IPV6_LOOKUP)
- if ((preference == ADDR_PREFERENCE_IPV4 && !host->n) ||
- preference == ADDR_PREFERENCE_IPV6 ||
- preference == ADDR_PREFERENCE_IPV6_ONLY) {
+ if ((preference == ADDR_PREFERENCE_IPV4 && !host->n)
+ || preference == ADDR_PREFERENCE_IPV6
+ || preference == ADDR_PREFERENCE_IPV6_ONLY) {
struct addrinfo hints;
int i;
for (i = 0; i < host->n; i++)
@@ -258,20 +281,22 @@ static void do_real_lookup(unsigned char *name, int preference, struct lookup_re
hints.ai_flags = 0;
use_getaddrinfo(name, &hints, preference, host);
}
- already_have_inet6:;
+already_have_inet6:;
#endif
ret:
return;
}
-static int do_lookup(struct dnsquery *q)
+static int
+do_lookup(struct dnsquery *q)
{
do_real_lookup((unsigned char *)q->name, q->addr_preference, q->addr);
end_dns_lookup(q, !q->addr->n);
return 0;
}
-static void check_dns_cache_addr_preference(void)
+static void
+check_dns_cache_addr_preference(void)
{
if (dns_cache_addr_preference != ipv6_options.addr_preference) {
shrink_dns_cache(SH_FREE_ALL);
@@ -279,12 +304,13 @@ static void check_dns_cache_addr_preference(void)
}
}
-static int find_in_dns_cache(char *name, struct dnsentry **dnsentry)
+static int
+find_in_dns_cache(char *name, struct dnsentry **dnsentry)
{
struct dnsentry *e = NULL;
struct list_head *le;
check_dns_cache_addr_preference();
- foreach(struct dnsentry, e, le, dns_cache)
+ foreach (struct dnsentry, e, le, dns_cache)
if (!strcasecmp(e->name, name)) {
del_from_list(e);
add_to_list(dns_cache, e);
@@ -294,13 +320,15 @@ static int find_in_dns_cache(char *name, struct dnsentry **dnsentry)
return -1;
}
-static void free_dns_entry(struct dnsentry *dnsentry)
+static void
+free_dns_entry(struct dnsentry *dnsentry)
{
del_from_list(dnsentry);
free(dnsentry);
}
-static void end_dns_lookup(struct dnsquery *q, int a)
+static void
+end_dns_lookup(struct dnsquery *q, int a)
{
struct dnsentry *dnsentry;
void (*fn)(void *, int);
@@ -311,7 +339,8 @@ static void end_dns_lookup(struct dnsquery *q, int a)
}
if (!find_in_dns_cache(q->name, &dnsentry)) {
if (a) {
- memcpy(q->addr, &dnsentry->addr, sizeof(struct lookup_result));
+ memcpy(q->addr, &dnsentry->addr,
+ sizeof(struct lookup_result));
a = 0;
goto e;
}
@@ -336,7 +365,9 @@ e:
fn(data, a);
}
-int find_host_no_cache(char *name, struct lookup_result *addr, void **qp, void (*fn)(void *, int), void *data)
+int
+find_host_no_cache(char *name, struct lookup_result *addr, void **qp,
+ void (*fn)(void *, int), void *data)
{
struct dnsquery *q;
q = xmalloc(sizeof(struct dnsquery) + strlen(name));
@@ -351,22 +382,26 @@ int find_host_no_cache(char *name, struct lookup_result *addr, void **qp, void (
return do_lookup(q);
}
-int find_host(char *name, struct lookup_result *addr, void **qp, void (*fn)(void *, int), void *data)
+int
+find_host(char *name, struct lookup_result *addr, void **qp,
+ void (*fn)(void *, int), void *data)
{
struct dnsentry *dnsentry;
if (qp)
*qp = NULL;
if (!find_in_dns_cache(name, &dnsentry)) {
- if (get_absolute_time() - dnsentry->absolute_time > DNS_TIMEOUT) goto timeout;
+ if (get_absolute_time() - dnsentry->absolute_time > DNS_TIMEOUT)
+ goto timeout;
memcpy(addr, &dnsentry->addr, sizeof(struct lookup_result));
fn(data, 0);
return 0;
}
- timeout:
+timeout:
return find_host_no_cache(name, addr, qp, fn, data);
}
-void kill_dns_request(void **qp)
+void
+kill_dns_request(void **qp)
{
struct dnsquery *q = *qp;
q->fn = NULL;
@@ -375,7 +410,8 @@ void kill_dns_request(void **qp)
}
#if MAX_ADDRESSES > 1
-void dns_set_priority(char *name, struct host_address *address, int prefer)
+void
+dns_set_priority(char *name, struct host_address *address, int prefer)
{
int i;
struct dnsentry *dnsentry;
@@ -387,18 +423,22 @@ void dns_set_priority(char *name, struct host_address *address, int prefer)
return;
found_it:
if (prefer) {
- memmove(&dnsentry->addr.a[1], &dnsentry->addr.a[0], i * sizeof(struct host_address));
- memcpy(&dnsentry->addr.a[0], address, sizeof(struct host_address));
+ memmove(&dnsentry->addr.a[1], &dnsentry->addr.a[0],
+ i * sizeof(struct host_address));
+ memcpy(&dnsentry->addr.a[0], address,
+ sizeof(struct host_address));
} else {
memmove(&dnsentry->addr.a[i], &dnsentry->addr.a[i + 1],
- (dnsentry->addr.n - i - 1) * sizeof(struct host_address));
+ (dnsentry->addr.n - i - 1)
+ * sizeof(struct host_address));
memcpy(&dnsentry->addr.a[dnsentry->addr.n - 1], address,
- sizeof(struct host_address));
+ sizeof(struct host_address));
}
}
#endif
-void dns_clear_host(char *name)
+void
+dns_clear_host(char *name)
{
struct dnsentry *dnsentry;
if (find_in_dns_cache(name, &dnsentry))
@@ -406,7 +446,8 @@ void dns_clear_host(char *name)
free_dns_entry(dnsentry);
}
-unsigned long dns_info(int type)
+unsigned long
+dns_info(int type)
{
if (type == CI_FILES)
return list_size(&dns_cache);
@@ -416,7 +457,8 @@ unsigned long dns_info(int type)
return 0;
}
-static int shrink_dns_cache(int u)
+static int
+shrink_dns_cache(int u)
{
uttime now = get_absolute_time();
struct dnsentry *d = NULL;
@@ -426,7 +468,7 @@ static int shrink_dns_cache(int u)
d = list_struct(dns_cache.prev, struct dnsentry);
goto delete_last;
}
- foreach(struct dnsentry, d, ld, dns_cache)
+ foreach (struct dnsentry, d, ld, dns_cache)
if (u == SH_FREE_ALL || now - d->absolute_time > DNS_TIMEOUT) {
delete_last:
ld = d->list_entry.prev;
@@ -436,9 +478,10 @@ delete_last:
return f | (list_empty(dns_cache) ? ST_CACHE_EMPTY : 0);
}
-unsigned char *print_address(struct host_address *a)
+unsigned char *
+print_address(struct host_address *a)
{
-#define SCOPE_ID_LEN 11
+#define SCOPE_ID_LEN 11
static char buffer[INET6_ADDRSTRLEN + SCOPE_ID_LEN];
union {
struct in_addr in;
@@ -450,12 +493,14 @@ unsigned char *print_address(struct host_address *a)
return NULL;
if (a->scope_id) {
char *end = strchr(buffer, 0);
- snprintf(end, buffer + sizeof(buffer) - end, "%%%u", a->scope_id);
+ snprintf(end, buffer + sizeof(buffer) - end, "%%%u",
+ a->scope_id);
}
return (unsigned char *)buffer;
}
-int ipv6_full_access(void)
+int
+ipv6_full_access(void)
{
/*
* Test if we can access global IPv6 address space.
@@ -470,7 +515,10 @@ int ipv6_full_access(void)
memset(&sin6, 0, sizeof sin6);
sin6.sin6_family = AF_INET6;
sin6.sin6_port = htons(1024);
- memcpy(&sin6.sin6_addr.s6_addr, "\052\001\004\060\000\015\000\000\002\314\236\377\376\044\176\032", 16);
+ memcpy(
+ &sin6.sin6_addr.s6_addr,
+ "\052\001\004\060\000\015\000\000\002\314\236\377\376\044\176\032",
+ 16);
EINTRLOOP(c, connect(h, (struct sockaddr *)(void *)&sin6, sizeof sin6));
EINTRLOOP(rs, close(h));
if (!c)
@@ -478,7 +526,8 @@ int ipv6_full_access(void)
return 0;
}
-void init_dns(void)
+void
+init_dns(void)
{
register_cache_upcall(shrink_dns_cache, 0, cast_uchar "dns");
}
diff --git a/error.c b/error.c
@@ -5,7 +5,8 @@
#include "links.h"
-void *mem_calloc(size_t size)
+void *
+mem_calloc(size_t size)
{
void *p;
if (!size)
@@ -15,10 +16,12 @@ void *mem_calloc(size_t size)
return p;
}
-unsigned char *memacpy(const unsigned char *src, size_t len)
+unsigned char *
+memacpy(const unsigned char *src, size_t len)
{
unsigned char *m;
- if (!(len + 1)) overalloc();
+ if (!(len + 1))
+ overalloc();
m = xmalloc(len + 1);
if (len)
memcpy(m, src, len);
@@ -26,7 +29,9 @@ unsigned char *memacpy(const unsigned char *src, size_t len)
return m;
}
-unsigned char *stracpy(const unsigned char *src)
+unsigned char *
+stracpy(const unsigned char *src)
{
- return src ? memacpy(src, src != DUMMY ? strlen((char *)src) : 0) : NULL;
+ return src ? memacpy(src, src != DUMMY ? strlen((char *)src) : 0)
+ : NULL;
}
diff --git a/file.c b/file.c
@@ -8,60 +8,78 @@
#include "links.h"
-static void setrwx(unsigned m, unsigned char *p)
+static void
+setrwx(unsigned m, unsigned char *p)
{
- if (m & S_IRUSR) p[0] = 'r';
- if (m & S_IWUSR) p[1] = 'w';
- if (m & S_IXUSR) p[2] = 'x';
+ if (m & S_IRUSR)
+ p[0] = 'r';
+ if (m & S_IWUSR)
+ p[1] = 'w';
+ if (m & S_IXUSR)
+ p[2] = 'x';
}
-static void setst(unsigned m, unsigned char *p)
+static void
+setst(unsigned m, unsigned char *p)
{
#ifdef S_ISUID
if (m & S_ISUID) {
p[2] = 'S';
- if (m & S_IXUSR) p[2] = 's';
+ if (m & S_IXUSR)
+ p[2] = 's';
}
#endif
#ifdef S_ISGID
if (m & S_ISGID) {
p[5] = 'S';
- if (m & S_IXGRP) p[5] = 's';
+ if (m & S_IXGRP)
+ p[5] = 's';
}
#endif
#ifdef S_ISVTX
if (m & S_ISVTX) {
p[8] = 'T';
- if (m & S_IXOTH) p[8] = 't';
+ if (m & S_IXOTH)
+ p[8] = 't';
}
#endif
}
-static void stat_mode(unsigned char **p, int *l, struct stat *stp)
+static void
+stat_mode(unsigned char **p, int *l, struct stat *stp)
{
unsigned char c = '?';
unsigned char rwx[10] = "---------";
if (stp) {
- if (0) {}
+ if (0) {
+ }
#ifdef S_ISBLK
- else if (S_ISBLK(stp->st_mode)) c = 'b';
+ else if (S_ISBLK(stp->st_mode))
+ c = 'b';
#endif
#ifdef S_ISCHR
- else if (S_ISCHR(stp->st_mode)) c = 'c';
+ else if (S_ISCHR(stp->st_mode))
+ c = 'c';
#endif
- else if (S_ISDIR(stp->st_mode)) c = 'd';
- else if (S_ISREG(stp->st_mode)) c = '-';
+ else if (S_ISDIR(stp->st_mode))
+ c = 'd';
+ else if (S_ISREG(stp->st_mode))
+ c = '-';
#ifdef S_ISFIFO
- else if (S_ISFIFO(stp->st_mode)) c = 'p';
+ else if (S_ISFIFO(stp->st_mode))
+ c = 'p';
#endif
#ifdef S_ISLNK
- else if (S_ISLNK(stp->st_mode)) c = 'l';
+ else if (S_ISLNK(stp->st_mode))
+ c = 'l';
#endif
#ifdef S_ISSOCK
- else if (S_ISSOCK(stp->st_mode)) c = 's';
+ else if (S_ISSOCK(stp->st_mode))
+ c = 's';
#endif
#ifdef S_ISNWK
- else if (S_ISNWK(stp->st_mode)) c = 'n';
+ else if (S_ISNWK(stp->st_mode))
+ c = 'n';
#endif
}
add_chr_to_str(p, l, c);
@@ -76,7 +94,8 @@ static void stat_mode(unsigned char **p, int *l, struct stat *stp)
add_chr_to_str(p, l, ' ');
}
-static void stat_links(unsigned char **p, int *l, struct stat *stp)
+static void
+stat_links(unsigned char **p, int *l, struct stat *stp)
{
unsigned char lnk[64];
if (!stp)
@@ -93,7 +112,8 @@ static unsigned char last_user[64];
static int last_gid = -1;
static unsigned char last_group[64];
-static void stat_user(unsigned char **p, int *l, struct stat *stp, int g)
+static void
+stat_user(unsigned char **p, int *l, struct stat *stp, int g)
{
struct passwd *pwd;
struct group *grp;
@@ -106,27 +126,34 @@ static void stat_user(unsigned char **p, int *l, struct stat *stp, int g)
}
id = !g ? stp->st_uid : stp->st_gid;
pp = !g ? last_user : last_group;
- if (!g && id == last_uid && last_uid != -1) goto a;
- if (g && id == last_gid && last_gid != -1) goto a;
+ if (!g && id == last_uid && last_uid != -1)
+ goto a;
+ if (g && id == last_gid && last_gid != -1)
+ goto a;
if (!g) {
ENULLLOOP(pwd, getpwuid(id));
- if (!pwd || !pwd->pw_name) sprintf(cast_char pp, "%d", id);
- else sprintf(cast_char pp, "%.8s", pwd->pw_name);
+ if (!pwd || !pwd->pw_name)
+ sprintf(cast_char pp, "%d", id);
+ else
+ sprintf(cast_char pp, "%.8s", pwd->pw_name);
last_uid = id;
} else {
ENULLLOOP(grp, getgrgid(id));
- if (!grp || !grp->gr_name) sprintf(cast_char pp, "%d", id);
- else sprintf(cast_char pp, "%.8s", grp->gr_name);
+ if (!grp || !grp->gr_name)
+ sprintf(cast_char pp, "%d", id);
+ else
+ sprintf(cast_char pp, "%.8s", grp->gr_name);
last_gid = id;
}
- a:
+a:
add_to_str(p, l, pp);
for (i = strlen(cast_const_char pp); i < 8; i++)
add_chr_to_str(p, l, ' ');
add_chr_to_str(p, l, ' ');
}
-static void stat_size(unsigned char **p, int *l, struct stat *stp)
+static void
+stat_size(unsigned char **p, int *l, struct stat *stp)
{
unsigned char num[64];
const int digits = 8;
@@ -141,7 +168,8 @@ static void stat_size(unsigned char **p, int *l, struct stat *stp)
add_chr_to_str(p, l, ' ');
}
-static void stat_date(unsigned char **p, int *l, struct stat *stp)
+static void
+stat_date(unsigned char **p, int *l, struct stat *stp)
{
time_t current_time;
time_t when;
@@ -158,25 +186,29 @@ static void stat_date(unsigned char **p, int *l, struct stat *stp)
}
when = stp->st_mtime;
when_local = localtime(&when);
- if ((ulonglong)current_time > (ulonglong)when + 6L * 30L * 24L * 60L * 60L
- || (ulonglong)current_time < (ulonglong)when - 60L * 60L)
+ if ((ulonglong)current_time
+ > (ulonglong)when + 6L * 30L * 24L * 60L * 60L
+ || (ulonglong)current_time < (ulonglong)when - 60L * 60L)
fmt = fmt1;
else
fmt = fmt2;
- again:
+again:
wr = strftime(cast_char str, 13, cast_const_char fmt, when_local);
- if (wr && strstr(cast_const_char str, " e ") && ((e = cast_uchar strchr(cast_const_char fmt, 'e')))) {
+ if (wr && strstr(cast_const_char str, " e ")
+ && ((e = cast_uchar strchr(cast_const_char fmt, 'e')))) {
*e = 'd';
goto again;
}
- set_empty:
- while (wr < 12) str[wr++] = ' ';
+set_empty:
+ while (wr < 12)
+ str[wr++] = ' ';
str[12] = 0;
add_to_str(p, l, str);
add_chr_to_str(p, l, ' ');
}
-static unsigned char *get_filename(unsigned char *url)
+static unsigned char *
+get_filename(unsigned char *url)
{
unsigned char *p, *m;
int ml;
@@ -193,18 +225,24 @@ struct dirs {
unsigned char *f;
};
-static int comp_de(const void *d1_, const void *d2_)
+static int
+comp_de(const void *d1_, const void *d2_)
{
const struct dirs *d1 = (const struct dirs *)d1_;
const struct dirs *d2 = (const struct dirs *)d2_;
- if (d1->f[0] == '.' && d1->f[1] == '.' && !d1->f[2]) return -1;
- if (d2->f[0] == '.' && d2->f[1] == '.' && !d2->f[2]) return 1;
- if (d1->s[0] == 'd' && d2->s[0] != 'd') return -1;
- if (d1->s[0] != 'd' && d2->s[0] == 'd') return 1;
+ if (d1->f[0] == '.' && d1->f[1] == '.' && !d1->f[2])
+ return -1;
+ if (d2->f[0] == '.' && d2->f[1] == '.' && !d2->f[2])
+ return 1;
+ if (d1->s[0] == 'd' && d2->s[0] != 'd')
+ return -1;
+ if (d1->s[0] != 'd' && d2->s[0] == 'd')
+ return 1;
return strcmp(cast_const_char d1->f, cast_const_char d2->f);
}
-void file_func(struct connection *c)
+void
+file_func(struct connection *c)
{
struct cache_entry *e;
unsigned char *file, *name, *head = NULL;
@@ -240,7 +278,8 @@ void file_func(struct connection *c)
if (h == -1) {
int er = errno;
d = c_opendir(name);
- if (d) goto dir;
+ if (d)
+ goto dir;
free(name);
setcstate(c, get_error_from_errno(er));
abort_connection(c);
@@ -261,10 +300,11 @@ void file_func(struct connection *c)
abort_connection(c);
return;
}
- dir:
+dir:
dir = NULL;
dirl = 0;
- if (name[0] && !dir_sep(name[strlen(cast_const_char name) - 1])) {
+ if (name[0]
+ && !dir_sep(name[strlen(cast_const_char name) - 1])) {
if (!c->cache) {
if (get_connection_cache_entry(c)) {
free(name);
@@ -289,11 +329,14 @@ void file_func(struct connection *c)
fl = 0;
add_to_str(&file, &fl, cast_uchar "<html><head><title>");
flo = fl;
- add_conv_str(&file, &fl, name, (int)strlen(cast_const_char name), -1);
+ add_conv_str(&file, &fl, name,
+ (int)strlen(cast_const_char name), -1);
convert_file_charset(&file, &fl, flo);
- add_to_str(&file, &fl, cast_uchar "</title></head><body><h2>Directory ");
+ add_to_str(&file, &fl,
+ cast_uchar "</title></head><body><h2>Directory ");
flo = fl;
- add_conv_str(&file, &fl, name, (int)strlen(cast_const_char name), -1);
+ add_conv_str(&file, &fl, name,
+ (int)strlen(cast_const_char name), -1);
convert_file_charset(&file, &fl, flo);
add_to_str(&file, &fl, cast_uchar "</h2>\n<pre>");
while (1) {
@@ -302,11 +345,15 @@ void file_func(struct connection *c)
int l;
unsigned char *n;
ENULLLOOP(de, (void *)readdir(d));
- if (!de) break;
- if (!strcmp(cast_const_char de->d_name, ".")) continue;
+ if (!de)
+ break;
+ if (!strcmp(cast_const_char de->d_name, "."))
+ continue;
if (!strcmp(cast_const_char de->d_name, "..")) {
unsigned char *n = name;
- if (strspn(cast_const_char n, dir_sep('\\') ? "/\\" : "/") == strlen(cast_const_char n))
+ if (strspn(cast_const_char n,
+ dir_sep('\\') ? "/\\" : "/")
+ == strlen(cast_const_char n))
continue;
}
if ((unsigned)dirl > INT_MAX / sizeof(struct dirs) - 1)
@@ -318,8 +365,10 @@ void file_func(struct connection *c)
n = stracpy(name);
add_to_strn(&n, cast_uchar de->d_name);
EINTRLOOP(rs, lstat(cast_const_char n, &stt));
- if (rs) stp = NULL;
- else stp = &stt;
+ if (rs)
+ stp = NULL;
+ else
+ stp = &stt;
free(n);
stat_mode(p, &l, stp);
stat_links(p, &l, stp);
@@ -331,7 +380,7 @@ void file_func(struct connection *c)
closedir(d);
if (dirl)
qsort(dir, dirl, sizeof(struct dirs),
- (int (*)(const void *, const void *))comp_de);
+ (int (*)(const void *, const void *))comp_de);
for (i = 0; i < dirl; i++) {
char *lnk = NULL;
if (dir[i].s[0] == 'l') {
@@ -348,18 +397,20 @@ void file_func(struct connection *c)
buf = xmalloc(size);
EINTRLOOP(r, readlink(n, buf, size));
} while (r == size);
- if (r == -1) goto yyy;
+ if (r == -1)
+ goto yyy;
buf[r] = 0;
lnk = buf;
goto xxx;
- yyy:
+yyy:
free(buf);
- xxx:
+xxx:
free(n);
}
add_to_str(&file, &fl, dir[i].s);
add_to_str(&file, &fl, cast_uchar "<a href=\"./");
- add_conv_str(&file, &fl, dir[i].f, (int)strlen(cast_const_char dir[i].f), 1);
+ add_conv_str(&file, &fl, dir[i].f,
+ (int)strlen(cast_const_char dir[i].f), 1);
if (dir[i].s[0] == 'd')
add_chr_to_str(&file, &fl, '/');
else if (lnk) {
@@ -373,7 +424,8 @@ void file_func(struct connection *c)
}
add_to_str(&file, &fl, cast_uchar "\">");
flo = fl;
- add_conv_str(&file, &fl, dir[i].f, (int)strlen(cast_const_char dir[i].f), 0);
+ add_conv_str(&file, &fl, dir[i].f,
+ (int)strlen(cast_const_char dir[i].f), 0);
convert_file_charset(&file, &fl, flo);
add_to_str(&file, &fl, cast_uchar "</a>");
if (lnk) {
@@ -405,12 +457,14 @@ void file_func(struct connection *c)
if (!file) {
EINTRLOOP(rs, close(h));
setcstate(c, S_OUT_OF_MEM);
- abort_connection(c); return;
+ abort_connection(c);
+ return;
}
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);
+ setcstate(c, r == -1 ? get_error_from_errno(errno)
+ : S_FILE_ERROR);
abort_connection(c);
return;
}
@@ -439,7 +493,7 @@ void file_func(struct connection *c)
}
truncate_entry(e, fl, 1);
free(file);
- end:
+end:
c->cache->incomplete = 0;
setcstate(c, S__OK);
abort_connection(c);
diff --git a/html.c b/html.c
@@ -8,16 +8,18 @@
#include "links.h"
-struct list_head html_stack = {&html_stack, &html_stack};
+struct list_head html_stack = { &html_stack, &html_stack };
int html_format_changed = 0;
-static inline int isA(unsigned char c)
+static inline int
+isA(unsigned char c)
{
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
}
-static inline int atchr(unsigned char c)
+static inline int
+atchr(unsigned char c)
{
return /*isA(c) ||*/ (c > ' ' && c != '=' && c != '<' && c != '>');
}
@@ -30,105 +32,139 @@ static inline int atchr(unsigned char c)
/* end points to first character behind the html element */
/* returns: -1 fail (returned values in pointers are invalid) */
/* 0 success */
-int parse_element(unsigned char *e, unsigned char *eof, unsigned char **name, int *namelen, unsigned char **attr, unsigned char **end)
+int
+parse_element(unsigned char *e, unsigned char *eof, unsigned char **name,
+ int *namelen, unsigned char **attr, unsigned char **end)
{
- if (eof - e < 3 || *(e++) != '<') return -1;
- if (name) *name = e;
+ if (eof - e < 3 || *(e++) != '<')
+ return -1;
+ if (name)
+ *name = e;
if (*e == '/') {
e++;
- if (*e == '>' || *e == '<') goto xx;
+ if (*e == '>' || *e == '<')
+ goto xx;
} else if (!isA(*e)) {
return -1;
}
- while (isA(*e) || (*e >= '0' && *e <= '9') || *e == '_' || *e == '-' || *e == '=') {
+ while (isA(*e) || (*e >= '0' && *e <= '9') || *e == '_' || *e == '-'
+ || *e == '=') {
e++;
- if (e >= eof) return -1;
+ if (e >= eof)
+ return -1;
}
- xx:
- if (name && namelen) *namelen = (int)(e - *name);
+xx:
+ if (name && namelen)
+ *namelen = (int)(e - *name);
while ((WHITECHAR(*e) || *e == '/' || *e == ':')) {
e++;
- if (e >= eof) return -1;
+ if (e >= eof)
+ return -1;
}
- if ((!atchr(*e) && *e != '>' && *e != '<')) return -1;
- if (attr) *attr = e;
- nextattr:
+ if ((!atchr(*e) && *e != '>' && *e != '<'))
+ return -1;
+ if (attr)
+ *attr = e;
+nextattr:
while (WHITECHAR(*e)) {
e++;
- if (e >= eof) return -1;
+ if (e >= eof)
+ return -1;
}
- if ((!atchr(*e) && *e != '>' && *e != '<')) return -1;
- if (*e == '>' || *e == '<') goto en;
+ if ((!atchr(*e) && *e != '>' && *e != '<'))
+ return -1;
+ if (*e == '>' || *e == '<')
+ goto en;
while (atchr(*e)) {
e++;
- if (e >= eof) return -1;
+ if (e >= eof)
+ return -1;
}
while (WHITECHAR(*e)) {
e++;
- if (e >= eof) return -1;
+ if (e >= eof)
+ return -1;
}
- if (*e != '=') goto endattr;
- if (1) goto x2;
+ if (*e != '=')
+ goto endattr;
+ if (1)
+ goto x2;
while (WHITECHAR(*e)) {
- x2:
+x2:
e++;
- if (e >= eof) return -1;
+ if (e >= eof)
+ return -1;
}
if (U(*e)) {
unsigned char uu = *e;
/*u:*/
- if (1) goto x3;
- while (e < eof && *e != uu && *e /*(WHITECHAR(*e) || *e > ' ')*/) {
- x3:
+ if (1)
+ goto x3;
+ while (e < eof && *e != uu
+ && *e /*(WHITECHAR(*e) || *e > ' ')*/) {
+x3:
e++;
- if (e >= eof) return -1;
+ if (e >= eof)
+ return -1;
}
- if (*e < ' ') return -1;
+ if (*e < ' ')
+ return -1;
e++;
- if (e >= eof /*|| (!WHITECHAR(*e) && *e != uu && *e != '>' && *e != '<')*/) return -1;
+ if (e >= eof /*|| (!WHITECHAR(*e) && *e != uu && *e != '>' && *e != '<')*/)
+ return -1;
/*if (*e == uu) goto u;*/
} else {
while (!WHITECHAR(*e) && *e != '>' && *e != '<') {
e++;
- if (e >= eof) return -1;
+ if (e >= eof)
+ return -1;
}
}
while (WHITECHAR(*e)) {
e++;
- if (e >= eof) return -1;
+ if (e >= eof)
+ return -1;
}
- endattr:
- if (*e != '>' && *e != '<') goto nextattr;
- en:
- if (e[-1] == '\\') return -1;
- if (end) *end = e + (*e == '>');
+endattr:
+ if (*e != '>' && *e != '<')
+ goto nextattr;
+en:
+ if (e[-1] == '\\')
+ return -1;
+ if (end)
+ *end = e + (*e == '>');
return 0;
}
-#define add_chr(s, l, c) \
-do { \
- if (!((l) & (32 - 1))) { \
- if ((unsigned)(l) > INT_MAX - 32) overalloc(); \
- (s) = xrealloc((s), (l) + 32); \
- } \
- (s)[(l)++] = (c); \
-} while (0)
+#define add_chr(s, l, c) \
+ do { \
+ if (!((l) & (32 - 1))) { \
+ if ((unsigned)(l) > INT_MAX - 32) \
+ overalloc(); \
+ (s) = xrealloc((s), (l) + 32); \
+ } \
+ (s)[(l)++] = (c); \
+ } while (0)
int get_attr_val_nl = 0;
/* parses html element attributes */
-/* e is attr pointer previously got from parse_element, DON'T PASS HERE ANY OTHER VALUE!!! */
+/* e is attr pointer previously got from parse_element, DON'T PASS HERE ANY
+ * OTHER VALUE!!! */
/* name is searched attribute */
/* returns allocated string containing the attribute, or NULL on unsuccess */
-unsigned char *get_attr_val(unsigned char *e, unsigned char *name)
+unsigned char *
+get_attr_val(unsigned char *e, unsigned char *name)
{
unsigned char *n;
unsigned char *a = NULL;
int l = 0;
int f;
- aa:
- while (WHITECHAR(*e)) e++;
- if (*e == '>' || *e == '<') return NULL;
+aa:
+ while (WHITECHAR(*e))
+ e++;
+ if (*e == '>' || *e == '<')
+ return NULL;
n = name;
while (*n && upcase(*e) == upcase(*n)) {
e++;
@@ -139,13 +175,17 @@ unsigned char *get_attr_val(unsigned char *e, unsigned char *name)
f = 1;
e++;
}
- while (WHITECHAR(*e)) e++;
- if (*e != '=') goto ea;
+ while (WHITECHAR(*e))
+ e++;
+ if (*e != '=')
+ goto ea;
e++;
- while (WHITECHAR(*e)) e++;
+ while (WHITECHAR(*e))
+ e++;
if (!U(*e)) {
while (!WHITECHAR(*e) && *e != '>' && *e != '<') {
- if (!f) add_chr(a, l, *e);
+ if (!f)
+ add_chr(a, l, *e);
e++;
}
} else {
@@ -161,7 +201,7 @@ unsigned char *get_attr_val(unsigned char *e, unsigned char *name)
goto exact;
if (*e != 13) {
if (*e != 9 && *e != 10)
- exact:
+exact:
add_chr(a, l, *e);
else if (!get_attr_val_nl)
add_chr(a, l, ' ');
@@ -171,7 +211,7 @@ unsigned char *get_attr_val(unsigned char *e, unsigned char *name)
}
e++;
}
- ea:
+ea:
if (!f) {
unsigned char *b;
add_chr(a, l, 0);
@@ -190,7 +230,8 @@ unsigned char *get_attr_val(unsigned char *e, unsigned char *name)
;
if (b != a)
memmove(a, b, strlen((char *)b) + 1);
- for (b = a + strlen((char *)a) - 1; b >= a && *b == ' '; b--)
+ for (b = a + strlen((char *)a) - 1; b >= a && *b == ' ';
+ b--)
*b = 0;
}
return a;
@@ -198,7 +239,8 @@ unsigned char *get_attr_val(unsigned char *e, unsigned char *name)
goto aa;
}
-int has_attr(unsigned char *e, unsigned char *name)
+int
+has_attr(unsigned char *e, unsigned char *name)
{
unsigned char *a;
if (!(a = get_attr_val(e, name)))
@@ -207,7 +249,8 @@ int has_attr(unsigned char *e, unsigned char *name)
return 1;
}
-static unsigned char *get_url_val(unsigned char *e, unsigned char *name)
+static unsigned char *
+get_url_val(unsigned char *e, unsigned char *name)
{
unsigned char *a, *p, *c;
int l;
@@ -222,7 +265,7 @@ static unsigned char *get_url_val(unsigned char *e, unsigned char *name)
}
return a;
- need_convert:
+need_convert:
c = init_str();
l = 0;
for (p = a; *p; p++)
@@ -231,7 +274,8 @@ static unsigned char *get_url_val(unsigned char *e, unsigned char *name)
return c;
}
-static unsigned char *get_exact_attr_val(unsigned char *e, unsigned char *name)
+static unsigned char *
+get_exact_attr_val(unsigned char *e, unsigned char *name)
{
unsigned char *a;
get_attr_val_nl = 2;
@@ -242,7 +286,8 @@ static unsigned char *get_exact_attr_val(unsigned char *e, unsigned char *name)
for (x1 = x2 = a; *x1; x1++, x2++)
if (x1[0] == '\r') {
*x2 = '\n';
- if (x1[1] == '\n') x1++;
+ if (x1[1] == '\n')
+ x1++;
} else
*x2 = *x1;
*x2 = 0;
@@ -254,29 +299,30 @@ static struct {
const unsigned short int n;
const char *s;
} roman_tbl[] = {
- {1000, "m"},
- {999, "im"},
- {990, "xm"},
- {900, "cm"},
- {500, "d"},
- {499, "id"},
- {490, "xd"},
- {400, "cd"},
- {100, "c"},
- {99, "ic"},
- {90, "xc"},
- {50, "l"},
- {49, "il"},
- {40, "xl"},
- {10, "x"},
- {9, "ix"},
- {5, "v"},
- {4, "iv"},
- {1, "i"},
- {0, NULL}
+ {1000, "m" },
+ { 999, "im"},
+ { 990, "xm"},
+ { 900, "cm"},
+ { 500, "d" },
+ { 499, "id"},
+ { 490, "xd"},
+ { 400, "cd"},
+ { 100, "c" },
+ { 99, "ic"},
+ { 90, "xc"},
+ { 50, "l" },
+ { 49, "il"},
+ { 40, "xl"},
+ { 10, "x" },
+ { 9, "ix"},
+ { 5, "v" },
+ { 4, "iv"},
+ { 1, "i" },
+ { 0, NULL}
};
-static void roman(char *p, unsigned int n, const size_t psz)
+static void
+roman(char *p, unsigned int n, const size_t psz)
{
int i = 0;
if (!n) {
@@ -309,151 +355,152 @@ struct color_spec {
};
static const struct color_spec color_specs[] = {
- {"aliceblue", 0xF0F8FF},
- {"antiquewhite", 0xFAEBD7},
- {"aqua", 0x00FFFF},
- {"aquamarine", 0x7FFFD4},
- {"azure", 0xF0FFFF},
- {"beige", 0xF5F5DC},
- {"bisque", 0xFFE4C4},
- {"black", 0x000000},
- {"blanchedalmond", 0xFFEBCD},
- {"blue", 0x0000FF},
- {"blueviolet", 0x8A2BE2},
- {"brown", 0xA52A2A},
- {"burlywood", 0xDEB887},
- {"cadetblue", 0x5F9EA0},
- {"chartreuse", 0x7FFF00},
- {"chocolate", 0xD2691E},
- {"coral", 0xFF7F50},
- {"cornflowerblue", 0x6495ED},
- {"cornsilk", 0xFFF8DC},
- {"crimson", 0xDC143C},
- {"cyan", 0x00FFFF},
- {"darkblue", 0x00008B},
- {"darkcyan", 0x008B8B},
- {"darkgoldenrod", 0xB8860B},
- {"darkgray", 0xA9A9A9},
- {"darkgreen", 0x006400},
- {"darkkhaki", 0xBDB76B},
- {"darkmagenta", 0x8B008B},
- {"darkolivegreen", 0x556B2F},
- {"darkorange", 0xFF8C00},
- {"darkorchid", 0x9932CC},
- {"darkred", 0x8B0000},
- {"darksalmon", 0xE9967A},
- {"darkseagreen", 0x8FBC8F},
- {"darkslateblue", 0x483D8B},
- {"darkslategray", 0x2F4F4F},
- {"darkturquoise", 0x00CED1},
- {"darkviolet", 0x9400D3},
- {"deeppink", 0xFF1493},
- {"deepskyblue", 0x00BFFF},
- {"dimgray", 0x696969},
- {"dodgerblue", 0x1E90FF},
- {"firebrick", 0xB22222},
- {"floralwhite", 0xFFFAF0},
- {"forestgreen", 0x228B22},
- {"fuchsia", 0xFF00FF},
- {"gainsboro", 0xDCDCDC},
- {"ghostwhite", 0xF8F8FF},
- {"gold", 0xFFD700},
- {"goldenrod", 0xDAA520},
- {"gray", 0x808080},
- {"green", 0x008000},
- {"greenyellow", 0xADFF2F},
- {"honeydew", 0xF0FFF0},
- {"hotpink", 0xFF69B4},
- {"indianred", 0xCD5C5C},
- {"indigo", 0x4B0082},
- {"ivory", 0xFFFFF0},
- {"khaki", 0xF0E68C},
- {"lavender", 0xE6E6FA},
- {"lavenderblush", 0xFFF0F5},
- {"lawngreen", 0x7CFC00},
- {"lemonchiffon", 0xFFFACD},
- {"lightblue", 0xADD8E6},
- {"lightcoral", 0xF08080},
- {"lightcyan", 0xE0FFFF},
- {"lightgoldenrodyellow", 0xFAFAD2},
- {"lightgreen", 0x90EE90},
- {"lightgrey", 0xD3D3D3},
- {"lightpink", 0xFFB6C1},
- {"lightsalmon", 0xFFA07A},
- {"lightseagreen", 0x20B2AA},
- {"lightskyblue", 0x87CEFA},
- {"lightslategray", 0x778899},
- {"lightsteelblue", 0xB0C4DE},
- {"lightyellow", 0xFFFFE0},
- {"lime", 0x00FF00},
- {"limegreen", 0x32CD32},
- {"linen", 0xFAF0E6},
- {"magenta", 0xFF00FF},
- {"maroon", 0x800000},
- {"mediumaquamarine", 0x66CDAA},
- {"mediumblue", 0x0000CD},
- {"mediumorchid", 0xBA55D3},
- {"mediumpurple", 0x9370DB},
- {"mediumseagreen", 0x3CB371},
- {"mediumslateblue", 0x7B68EE},
- {"mediumspringgreen", 0x00FA9A},
- {"mediumturquoise", 0x48D1CC},
- {"mediumvioletred", 0xC71585},
- {"midnightblue", 0x191970},
- {"mintcream", 0xF5FFFA},
- {"mistyrose", 0xFFE4E1},
- {"moccasin", 0xFFE4B5},
- {"navajowhite", 0xFFDEAD},
- {"navy", 0x000080},
- {"oldlace", 0xFDF5E6},
- {"olive", 0x808000},
- {"olivedrab", 0x6B8E23},
- {"orange", 0xFFA500},
- {"orangered", 0xFF4500},
- {"orchid", 0xDA70D6},
- {"palegoldenrod", 0xEEE8AA},
- {"palegreen", 0x98FB98},
- {"paleturquoise", 0xAFEEEE},
- {"palevioletred", 0xDB7093},
- {"papayawhip", 0xFFEFD5},
- {"peachpuff", 0xFFDAB9},
- {"peru", 0xCD853F},
- {"pink", 0xFFC0CB},
- {"plum", 0xDDA0DD},
- {"powderblue", 0xB0E0E6},
- {"purple", 0x800080},
- {"red", 0xFF0000},
- {"rosybrown", 0xBC8F8F},
- {"royalblue", 0x4169E1},
- {"saddlebrown", 0x8B4513},
- {"salmon", 0xFA8072},
- {"sandybrown", 0xF4A460},
- {"seagreen", 0x2E8B57},
- {"seashell", 0xFFF5EE},
- {"sienna", 0xA0522D},
- {"silver", 0xC0C0C0},
- {"skyblue", 0x87CEEB},
- {"slateblue", 0x6A5ACD},
- {"slategray", 0x708090},
- {"snow", 0xFFFAFA},
- {"springgreen", 0x00FF7F},
- {"steelblue", 0x4682B4},
- {"tan", 0xD2B48C},
- {"teal", 0x008080},
- {"thistle", 0xD8BFD8},
- {"tomato", 0xFF6347},
- {"turquoise", 0x40E0D0},
- {"violet", 0xEE82EE},
- {"wheat", 0xF5DEB3},
- {"white", 0xFFFFFF},
- {"whitesmoke", 0xF5F5F5},
- {"yellow", 0xFFFF00},
- {"yellowgreen", 0x9ACD32},
+ {"aliceblue", 0xF0F8FF},
+ { "antiquewhite", 0xFAEBD7},
+ { "aqua", 0x00FFFF},
+ { "aquamarine", 0x7FFFD4},
+ { "azure", 0xF0FFFF},
+ { "beige", 0xF5F5DC},
+ { "bisque", 0xFFE4C4},
+ { "black", 0x000000},
+ { "blanchedalmond", 0xFFEBCD},
+ { "blue", 0x0000FF},
+ { "blueviolet", 0x8A2BE2},
+ { "brown", 0xA52A2A},
+ { "burlywood", 0xDEB887},
+ { "cadetblue", 0x5F9EA0},
+ { "chartreuse", 0x7FFF00},
+ { "chocolate", 0xD2691E},
+ { "coral", 0xFF7F50},
+ { "cornflowerblue", 0x6495ED},
+ { "cornsilk", 0xFFF8DC},
+ { "crimson", 0xDC143C},
+ { "cyan", 0x00FFFF},
+ { "darkblue", 0x00008B},
+ { "darkcyan", 0x008B8B},
+ { "darkgoldenrod", 0xB8860B},
+ { "darkgray", 0xA9A9A9},
+ { "darkgreen", 0x006400},
+ { "darkkhaki", 0xBDB76B},
+ { "darkmagenta", 0x8B008B},
+ { "darkolivegreen", 0x556B2F},
+ { "darkorange", 0xFF8C00},
+ { "darkorchid", 0x9932CC},
+ { "darkred", 0x8B0000},
+ { "darksalmon", 0xE9967A},
+ { "darkseagreen", 0x8FBC8F},
+ { "darkslateblue", 0x483D8B},
+ { "darkslategray", 0x2F4F4F},
+ { "darkturquoise", 0x00CED1},
+ { "darkviolet", 0x9400D3},
+ { "deeppink", 0xFF1493},
+ { "deepskyblue", 0x00BFFF},
+ { "dimgray", 0x696969},
+ { "dodgerblue", 0x1E90FF},
+ { "firebrick", 0xB22222},
+ { "floralwhite", 0xFFFAF0},
+ { "forestgreen", 0x228B22},
+ { "fuchsia", 0xFF00FF},
+ { "gainsboro", 0xDCDCDC},
+ { "ghostwhite", 0xF8F8FF},
+ { "gold", 0xFFD700},
+ { "goldenrod", 0xDAA520},
+ { "gray", 0x808080},
+ { "green", 0x008000},
+ { "greenyellow", 0xADFF2F},
+ { "honeydew", 0xF0FFF0},
+ { "hotpink", 0xFF69B4},
+ { "indianred", 0xCD5C5C},
+ { "indigo", 0x4B0082},
+ { "ivory", 0xFFFFF0},
+ { "khaki", 0xF0E68C},
+ { "lavender", 0xE6E6FA},
+ { "lavenderblush", 0xFFF0F5},
+ { "lawngreen", 0x7CFC00},
+ { "lemonchiffon", 0xFFFACD},
+ { "lightblue", 0xADD8E6},
+ { "lightcoral", 0xF08080},
+ { "lightcyan", 0xE0FFFF},
+ { "lightgoldenrodyellow", 0xFAFAD2},
+ { "lightgreen", 0x90EE90},
+ { "lightgrey", 0xD3D3D3},
+ { "lightpink", 0xFFB6C1},
+ { "lightsalmon", 0xFFA07A},
+ { "lightseagreen", 0x20B2AA},
+ { "lightskyblue", 0x87CEFA},
+ { "lightslategray", 0x778899},
+ { "lightsteelblue", 0xB0C4DE},
+ { "lightyellow", 0xFFFFE0},
+ { "lime", 0x00FF00},
+ { "limegreen", 0x32CD32},
+ { "linen", 0xFAF0E6},
+ { "magenta", 0xFF00FF},
+ { "maroon", 0x800000},
+ { "mediumaquamarine", 0x66CDAA},
+ { "mediumblue", 0x0000CD},
+ { "mediumorchid", 0xBA55D3},
+ { "mediumpurple", 0x9370DB},
+ { "mediumseagreen", 0x3CB371},
+ { "mediumslateblue", 0x7B68EE},
+ { "mediumspringgreen", 0x00FA9A},
+ { "mediumturquoise", 0x48D1CC},
+ { "mediumvioletred", 0xC71585},
+ { "midnightblue", 0x191970},
+ { "mintcream", 0xF5FFFA},
+ { "mistyrose", 0xFFE4E1},
+ { "moccasin", 0xFFE4B5},
+ { "navajowhite", 0xFFDEAD},
+ { "navy", 0x000080},
+ { "oldlace", 0xFDF5E6},
+ { "olive", 0x808000},
+ { "olivedrab", 0x6B8E23},
+ { "orange", 0xFFA500},
+ { "orangered", 0xFF4500},
+ { "orchid", 0xDA70D6},
+ { "palegoldenrod", 0xEEE8AA},
+ { "palegreen", 0x98FB98},
+ { "paleturquoise", 0xAFEEEE},
+ { "palevioletred", 0xDB7093},
+ { "papayawhip", 0xFFEFD5},
+ { "peachpuff", 0xFFDAB9},
+ { "peru", 0xCD853F},
+ { "pink", 0xFFC0CB},
+ { "plum", 0xDDA0DD},
+ { "powderblue", 0xB0E0E6},
+ { "purple", 0x800080},
+ { "red", 0xFF0000},
+ { "rosybrown", 0xBC8F8F},
+ { "royalblue", 0x4169E1},
+ { "saddlebrown", 0x8B4513},
+ { "salmon", 0xFA8072},
+ { "sandybrown", 0xF4A460},
+ { "seagreen", 0x2E8B57},
+ { "seashell", 0xFFF5EE},
+ { "sienna", 0xA0522D},
+ { "silver", 0xC0C0C0},
+ { "skyblue", 0x87CEEB},
+ { "slateblue", 0x6A5ACD},
+ { "slategray", 0x708090},
+ { "snow", 0xFFFAFA},
+ { "springgreen", 0x00FF7F},
+ { "steelblue", 0x4682B4},
+ { "tan", 0xD2B48C},
+ { "teal", 0x008080},
+ { "thistle", 0xD8BFD8},
+ { "tomato", 0xFF6347},
+ { "turquoise", 0x40E0D0},
+ { "violet", 0xEE82EE},
+ { "wheat", 0xF5DEB3},
+ { "white", 0xFFFFFF},
+ { "whitesmoke", 0xF5F5F5},
+ { "yellow", 0xFFFF00},
+ { "yellowgreen", 0x9ACD32},
};
#define endof(T) ((T) + array_elements(T))
-int decode_color(unsigned char *str, struct rgb *col)
+int
+decode_color(unsigned char *str, struct rgb *col)
{
unsigned long ch;
char *end;
@@ -491,29 +538,35 @@ found:
return -1;
}
-int get_color(unsigned char *a, unsigned char *c, struct rgb *rgb)
+int
+get_color(unsigned char *a, unsigned char *c, struct rgb *rgb)
{
unsigned char *at;
int r = -1;
- if (d_opt->col >= 1) if ((at = get_attr_val(a, c))) {
- r = decode_color(at, rgb);
- free(at);
- }
+ if (d_opt->col >= 1)
+ if ((at = get_attr_val(a, c))) {
+ r = decode_color(at, rgb);
+ free(at);
+ }
return r;
}
-int get_bgcolor(unsigned char *a, struct rgb *rgb)
+int
+get_bgcolor(unsigned char *a, struct rgb *rgb)
{
- if (d_opt->col < 2) return -1;
+ if (d_opt->col < 2)
+ return -1;
return get_color(a, cast_uchar "bgcolor", rgb);
}
-static unsigned char *get_target(unsigned char *a)
+static unsigned char *
+get_target(unsigned char *a)
{
return get_attr_val(a, cast_uchar "target");
}
-void kill_html_stack_item(struct html_element *e)
+void
+kill_html_stack_item(struct html_element *e)
{
if (!e || (void *)e == &html_stack) {
internal("trying to free bad html element");
@@ -535,7 +588,8 @@ void kill_html_stack_item(struct html_element *e)
free(e);
}
-void html_stack_dup(void)
+void
+html_stack_dup(void)
{
struct html_element *e;
struct html_element *ep;
@@ -573,9 +627,11 @@ static int was_br;
int table_level;
int empty_format;
-static void ln_break(const int n)
+static void
+ln_break(const int n)
{
- if (!n || html_top.invisible) return;
+ if (!n || html_top.invisible)
+ return;
while (n > line_breax) {
line_breax++;
line_break_f(ff);
@@ -584,10 +640,11 @@ static void ln_break(const int n)
putsp = -1;
}
-#define CH_BUF 256
-#define BUF_RESERVE 6
+#define CH_BUF 256
+#define BUF_RESERVE 6
-static int put_chars_conv(unsigned char *c, int l)
+static int
+put_chars_conv(unsigned char *c, int l)
{
static unsigned char buffer[CH_BUF];
int bp = 0;
@@ -597,49 +654,63 @@ static int put_chars_conv(unsigned char *c, int l)
put_chars_f(ff, c, l);
return l;
}
- if (!l) put_chars_f(ff, NULL, 0);
+ if (!l)
+ put_chars_f(ff, NULL, 0);
while (pp < l) {
int sl;
- unsigned char *e = NULL; /* against warning */
+ unsigned char *e = NULL; /* against warning */
if (c[pp] < 128 && c[pp] != '&') {
- put_c:
- if (bp > CH_BUF - BUF_RESERVE && c[pp] >= 0xc0) goto flush;
- if (!(buffer[bp++] = c[pp++])) buffer[bp - 1] = ' ';
- if ((buffer[bp - 1] != ' ' || par_format.align == AL_NO || par_format.align == AL_NO_BREAKABLE) && bp < CH_BUF) continue;
+put_c:
+ if (bp > CH_BUF - BUF_RESERVE && c[pp] >= 0xc0)
+ goto flush;
+ if (!(buffer[bp++] = c[pp++]))
+ buffer[bp - 1] = ' ';
+ if ((buffer[bp - 1] != ' ' || par_format.align == AL_NO
+ || par_format.align == AL_NO_BREAKABLE)
+ && bp < CH_BUF)
+ continue;
goto flush;
}
if (c[pp] != '&') {
struct conv_table *t;
int i;
- if (l - pp >= 3 && c[pp] == 0xef && c[pp + 1] == 0xbb && c[pp + 2] == 0xbf && !d_opt->real_cp) {
+ if (l - pp >= 3 && c[pp] == 0xef && c[pp + 1] == 0xbb
+ && c[pp + 2] == 0xbf && !d_opt->real_cp) {
pp += 3;
continue;
}
- if ((d_opt->real_cp == d_opt->cp && !d_opt->real_cp) || !convert_table)
+ if ((d_opt->real_cp == d_opt->cp && !d_opt->real_cp)
+ || !convert_table)
goto put_c;
t = convert_table;
i = pp;
- decode:
+decode:
if (!t[c[i]].t) {
e = t[c[i]].u.str;
} else {
t = t[c[i++]].u.tbl;
- if (i >= l) goto put_c;
+ if (i >= l)
+ goto put_c;
goto decode;
}
pp = i + 1;
} else {
int i = pp + 1;
- if (d_opt->plain & 1) goto put_c;
- while (i < l && !is_entity_terminator(c[i])) i++;
- if (!(e = get_entity_string(&c[pp + 1], i - pp - 1))) goto put_c;
+ if (d_opt->plain & 1)
+ goto put_c;
+ while (i < l && !is_entity_terminator(c[i]))
+ i++;
+ if (!(e = get_entity_string(&c[pp + 1], i - pp - 1)))
+ goto put_c;
pp = i + (i < l && c[i] == ';');
}
- if (!e[0]) continue;
+ if (!e[0])
+ continue;
if (!e[1]) {
buffer[bp++] = e[0];
- if (bp < CH_BUF) continue;
- flush:
+ if (bp < CH_BUF)
+ continue;
+flush:
e = cast_uchar "";
goto flush1;
}
@@ -649,10 +720,12 @@ static int put_chars_conv(unsigned char *c, int l)
sl = 0;
}
if (bp + sl > CH_BUF) {
- flush1:
+flush1:
put_chars_f(ff, buffer, bp);
if (!d_opt->cp) {
- while (bp) if ((buffer[--bp] & 0xc0) != 0x80) total++;
+ while (bp)
+ if ((buffer[--bp] & 0xc0) != 0x80)
+ total++;
} else {
total += bp;
bp = 0;
@@ -661,21 +734,28 @@ static int put_chars_conv(unsigned char *c, int l)
while (*e) {
buffer[bp++] = *(e++);
}
- if (bp == CH_BUF) goto flush;
+ if (bp == CH_BUF)
+ goto flush;
}
- if (bp) put_chars_f(ff, buffer, bp);
+ if (bp)
+ put_chars_f(ff, buffer, bp);
if (!d_opt->cp) {
- while (bp) if ((buffer[--bp] & 0xc0) != 0x80) total++;
+ while (bp)
+ if ((buffer[--bp] & 0xc0) != 0x80)
+ total++;
} else {
total += bp;
}
return total;
}
-static void put_chrs(unsigned char *start, int len)
+static void
+put_chrs(unsigned char *start, int len)
{
- if (par_format.align == AL_NO || par_format.align == AL_NO_BREAKABLE) putsp = 0;
- if (!len || html_top.invisible) return;
+ if (par_format.align == AL_NO || par_format.align == AL_NO_BREAKABLE)
+ putsp = 0;
+ if (!len || html_top.invisible)
+ return;
if (putsp == 1) {
pos += put_chars_conv(cast_uchar " ", 1);
putsp = -1;
@@ -689,21 +769,27 @@ static void put_chrs(unsigned char *start, int len)
}
if (!len) {
putsp = -1;
- if (par_format.align == AL_NO || par_format.align == AL_NO_BREAKABLE) putsp = 0;
+ if (par_format.align == AL_NO
+ || par_format.align == AL_NO_BREAKABLE)
+ putsp = 0;
return;
}
- if (start[len - 1] == ' ') putsp = -1;
- if (par_format.align == AL_NO || par_format.align == AL_NO_BREAKABLE) putsp = 0;
+ if (start[len - 1] == ' ')
+ putsp = -1;
+ if (par_format.align == AL_NO || par_format.align == AL_NO_BREAKABLE)
+ putsp = 0;
was_br = 0;
pos += put_chars_conv(start, len);
line_breax = 0;
}
-static void kill_until(int ls, ...)
+static void
+kill_until(int ls, ...)
{
int l;
struct list_head *e = &html_top.list_entry;
- if (ls) e = e->next;
+ if (ls)
+ e = e->next;
while (e != &html_stack) {
struct html_element *he = list_struct(e, struct html_element);
int sk = 0;
@@ -711,52 +797,70 @@ static void kill_until(int ls, ...)
va_start(arg, ls);
while (1) {
unsigned char *s = va_arg(arg, unsigned char *);
- if (!s) break;
- if (!*s) sk++;
- else if ((size_t)he->namelen == strlen(cast_const_char s) && !casecmp(he->name, s, strlen(cast_const_char s))) {
+ if (!s)
+ break;
+ if (!*s)
+ sk++;
+ else if ((size_t)he->namelen
+ == strlen(cast_const_char s)
+ && !casecmp(he->name, s,
+ strlen(cast_const_char s))) {
if (!sk) {
- if (he->dontkill) break;
+ if (he->dontkill)
+ break;
va_end(arg);
goto killll;
- }
- else if (sk == 1) {
+ } else if (sk == 1) {
va_end(arg);
goto killl;
- } else break;
+ } else
+ break;
}
}
va_end(arg);
- if (he->dontkill || (he->namelen == 5 && !casecmp(he->name, cast_uchar "TABLE", 5))) break;
- if (he->namelen == 2 && upcase(he->name[0]) == 'T' && (upcase(he->name[1]) == 'D' || upcase(he->name[1]) == 'H' || upcase(he->name[1]) == 'R')) break;
+ if (he->dontkill
+ || (he->namelen == 5
+ && !casecmp(he->name, cast_uchar "TABLE", 5)))
+ break;
+ if (he->namelen == 2 && upcase(he->name[0]) == 'T'
+ && (upcase(he->name[1]) == 'D' || upcase(he->name[1]) == 'H'
+ || upcase(he->name[1]) == 'R'))
+ break;
e = e->next;
}
return;
- killl:
+killl:
e = e->prev;
- killll:
+killll:
l = 0;
while (e != &html_stack) {
struct html_element *he = list_struct(e, struct html_element);
- if (ls && e == html_stack.next) break;
- if (he->linebreak > l) l = he->linebreak;
+ if (ls && e == html_stack.next)
+ break;
+ if (he->linebreak > l)
+ l = he->linebreak;
e = e->prev;
kill_html_stack_item(he);
}
ln_break(l);
}
-static inline unsigned char *top_href_base(void)
+static inline unsigned char *
+top_href_base(void)
{
- return list_struct(html_stack.prev, struct html_element)->attr.href_base;
+ return list_struct(html_stack.prev, struct html_element)
+ ->attr.href_base;
}
-int get_num(unsigned char *a, unsigned char *n)
+int
+get_num(unsigned char *a, unsigned char *n)
{
unsigned char *al;
if ((al = get_attr_val(a, n))) {
char *end;
unsigned long s = strtoul(cast_const_char al, &end, 10);
- if (!*al || *end || s > 10000) s = -1;
+ if (!*al || *end || s > 10000)
+ s = -1;
free(al);
return (int)s;
}
@@ -764,51 +868,64 @@ int get_num(unsigned char *a, unsigned char *n)
}
/* trunc somehow clips the maximum values. Use 0 to disable truncastion. */
-static int parse_width(const char *w, const int trunc)
+static int
+parse_width(const char *w, const int trunc)
{
char *end;
int p = 0;
long s;
int l;
- int limit = par_format.width - par_format.leftmargin + par_format.rightmargin;
- while (WHITECHAR(*w)) w++;
+ int limit =
+ par_format.width - par_format.leftmargin + par_format.rightmargin;
+ while (WHITECHAR(*w))
+ w++;
for (l = 0; w[l] && w[l] != ','; l++)
;
- while (l && WHITECHAR(w[l - 1])) l--;
- if (!l) return -1;
+ while (l && WHITECHAR(w[l - 1]))
+ l--;
+ if (!l)
+ return -1;
if (w[l - 1] == '%') {
l--;
p = 1;
}
- while (l && WHITECHAR(w[l - 1])) l--;
- if (!l) return -1;
+ while (l && WHITECHAR(w[l - 1]))
+ l--;
+ if (!l)
+ return -1;
s = strtol(w, &end, 10);
- if (end - w < l || s < 0 || s > 10000) return -1;
+ if (end - w < l || s < 0 || s > 10000)
+ return -1;
if (p) {
if (trunc) {
s = s * limit / 100;
- }
- else return -1;
+ } else
+ return -1;
} else {
s = (s + (HTML_CHAR_WIDTH - 1) / 2) / HTML_CHAR_WIDTH;
}
- if (trunc == 1 && s > limit) s = limit;
- if (s < 0) s = 0;
+ if (trunc == 1 && s > limit)
+ s = limit;
+ if (s < 0)
+ s = 0;
return (int)s;
}
/* trunc somehow clips the maximum values. Use 0 to disable truncastion. */
-int get_width(unsigned char *a, unsigned char *n, int trunc)
+int
+get_width(unsigned char *a, unsigned char *n, int trunc)
{
int r;
char *w;
- if (!(w = (char *)get_attr_val(a, n))) return -1;
+ if (!(w = (char *)get_attr_val(a, n)))
+ return -1;
r = parse_width(w, trunc);
free(w);
return r;
}
-static unsigned char *find_element_end(unsigned char *a)
+static unsigned char *
+find_element_end(unsigned char *a)
{
unsigned char *p;
for (p = a - 1; *p != '<'; p--)
@@ -826,12 +943,16 @@ unsigned char *last_form_tag;
unsigned char *last_form_attr;
unsigned char *last_input_tag;
-static inline void set_link_attr(void)
+static inline void
+set_link_attr(void)
{
- memcpy(!(format_.attr & AT_INVERT) ? &format_.fg : &format_.bg, &format_.clink, sizeof(struct rgb));
+ memcpy(!(format_.attr & AT_INVERT) ? &format_.fg : &format_.bg,
+ &format_.clink, sizeof(struct rgb));
}
-static void put_link_line(unsigned char *prefix, unsigned char *linkname, unsigned char *link, unsigned char *target)
+static void
+put_link_line(unsigned char *prefix, unsigned char *linkname,
+ unsigned char *link, unsigned char *target)
{
if (!casecmp(link, cast_uchar "android-app:", 12))
return;
@@ -852,13 +973,15 @@ static void put_link_line(unsigned char *prefix, unsigned char *linkname, unsign
kill_html_stack_item(&html_top);
}
-static void html_span(unsigned char *a)
+static void
+html_span(unsigned char *a)
{
unsigned char *al;
if ((al = get_attr_val(a, cast_uchar "class"))) {
if (!strcmp(cast_const_char al, "line-number"))
ln_break(1);
- if (!strcmp(cast_const_char al, "blob-code-inner")) { /* github hack */
+ if (!strcmp(cast_const_char al,
+ "blob-code-inner")) { /* github hack */
ln_break(1);
format_.attr |= AT_FIXED;
par_format.align = AL_NO;
@@ -868,27 +991,32 @@ static void html_span(unsigned char *a)
}
}
-static void html_bold(unsigned char *a)
+static void
+html_bold(unsigned char *a)
{
format_.attr |= AT_BOLD;
}
-static void html_italic(unsigned char *a)
+static void
+html_italic(unsigned char *a)
{
format_.attr |= AT_ITALIC;
}
-static void html_underline(unsigned char *a)
+static void
+html_underline(unsigned char *a)
{
format_.attr |= AT_UNDERLINE;
}
-static void html_fixed(unsigned char *a)
+static void
+html_fixed(unsigned char *a)
{
format_.attr |= AT_FIXED;
}
-static void html_invert(unsigned char *a)
+static void
+html_invert(unsigned char *a)
{
struct rgb rgb;
memcpy(&rgb, &format_.fg, sizeof(struct rgb));
@@ -897,14 +1025,17 @@ static void html_invert(unsigned char *a)
format_.attr ^= AT_INVERT;
}
-static void html_a(unsigned char *a)
+static void
+html_a(unsigned char *a)
{
unsigned char *al;
if ((al = get_url_val(a, cast_uchar "href"))) {
unsigned char *all = al;
- while (all[0] == ' ') all++;
- while (all[0] && all[strlen(cast_const_char all) - 1] == ' ') all[strlen(cast_const_char all) - 1] = 0;
+ while (all[0] == ' ')
+ all++;
+ while (all[0] && all[strlen(cast_const_char all) - 1] == ' ')
+ all[strlen(cast_const_char all) - 1] = 0;
free(format_.link);
format_.link = join_urls(format_.href_base, all);
free(al);
@@ -925,41 +1056,50 @@ static void html_a(unsigned char *a)
}
}
-static void html_a_special(unsigned char *a, unsigned char *next, unsigned char *eof)
+static void
+html_a_special(unsigned char *a, unsigned char *next, unsigned char *eof)
{
unsigned char *t;
- if (!format_.link) return;
- while (next < eof && WHITECHAR(*next)) next++;
- if (eof - next >= 4 && next[0] == '<' && next[1] == '/' && upcase(next[2]) == 'A' && next[3] == '>')
+ if (!format_.link)
+ return;
+ while (next < eof && WHITECHAR(*next))
+ next++;
+ if (eof - next >= 4 && next[0] == '<' && next[1] == '/'
+ && upcase(next[2]) == 'A' && next[3] == '>')
goto ok;
- if (strstr(cast_const_char format_.link, "/raw/")) /* gitlab hack */
+ if (strstr(cast_const_char format_.link, "/raw/")) /* gitlab hack */
goto ok;
return;
- ok:
- if (!has_attr(a, cast_uchar "href")) return;
+ok:
+ if (!has_attr(a, cast_uchar "href"))
+ return;
t = get_attr_val(a, cast_uchar "title");
- if (!t) return;
+ if (!t)
+ return;
put_chrs(t, (int)strlen(cast_const_char t));
free(t);
}
-static void html_sub(unsigned char *a)
+static void
+html_sub(unsigned char *a)
{
put_chrs(cast_uchar "_", 1);
format_.fontsize = 1;
format_.baseline = -1;
}
-static void html_sup(unsigned char *a)
+static void
+html_sup(unsigned char *a)
{
put_chrs(cast_uchar "^", 1);
format_.fontsize = 1;
- if (format_.baseline <= 0) format_.baseline = format_.fontsize;
+ if (format_.baseline <= 0)
+ format_.baseline = format_.fontsize;
}
-
-static void html_font(unsigned char *a)
+static void
+html_font(unsigned char *a)
{
unsigned char *al;
if ((al = get_attr_val(a, cast_uchar "size"))) {
@@ -977,18 +1117,24 @@ static void html_font(unsigned char *a)
}
s = strtoul(cast_const_char nn, &end, 10);
if (*nn && !*end) {
- if (s > 7) s = 7;
- if (!p) format_.fontsize = (int)s;
- else format_.fontsize += p * (int)s;
- if (format_.fontsize < 1) format_.fontsize = 1;
- if (format_.fontsize > 7) format_.fontsize = 7;
+ if (s > 7)
+ s = 7;
+ if (!p)
+ format_.fontsize = (int)s;
+ else
+ format_.fontsize += p * (int)s;
+ if (format_.fontsize < 1)
+ format_.fontsize = 1;
+ if (format_.fontsize > 7)
+ format_.fontsize = 7;
}
free(al);
}
get_color(a, cast_uchar "color", &format_.fg);
}
-static unsigned char *get_url_val_img(unsigned char *a, unsigned char *name)
+static unsigned char *
+get_url_val_img(unsigned char *a, unsigned char *name)
{
unsigned char *v = get_url_val(a, name);
if (v && !v[strcspn(cast_const_char v, "./")]) {
@@ -998,7 +1144,8 @@ static unsigned char *get_url_val_img(unsigned char *a, unsigned char *name)
return v;
}
-static void html_img(unsigned char *a)
+static void
+html_img(unsigned char *a)
{
unsigned char *al;
unsigned char *s;
@@ -1010,41 +1157,44 @@ static void html_img(unsigned char *a)
html_stack_dup();
free(format_.link);
format_.form = NULL;
- u = join_urls(*al == '#' ? top_href_base() : format_.href_base, al);
+ u = join_urls(*al == '#' ? top_href_base() : format_.href_base,
+ al);
format_.link = stracpy(cast_uchar "MAP@");
add_to_strn(&format_.link, u);
format_.attr |= AT_BOLD;
free(u);
free(al);
}
- ismap = format_.link && !has_attr(a, cast_uchar "usemap") && has_attr(a, cast_uchar "ismap");
+ ismap = format_.link && !has_attr(a, cast_uchar "usemap")
+ && has_attr(a, cast_uchar "ismap");
free(format_.image);
format_.image = NULL;
if ((s = get_url_val_img(a, cast_uchar "data-defer-src"))
- || (s = get_url_val_img(a, cast_uchar "data-delay-url"))
- || (s = get_url_val_img(a, cast_uchar "data-full"))
- || (s = get_url_val_img(a, cast_uchar "data-lazy"))
- || (s = get_url_val_img(a, cast_uchar "data-lazy-src"))
- || (s = get_url_val_img(a, cast_uchar "data-li-src"))
- || (s = get_url_val_img(a, cast_uchar "data-normal"))
- || (s = get_url_val_img(a, cast_uchar "data-original"))
- || (s = get_url_val_img(a, cast_uchar "data-small"))
- || (s = get_url_val_img(a, cast_uchar "data-source"))
- || (s = get_url_val_img(a, cast_uchar "data-src"))
- || (s = get_url_val_img(a, cast_uchar "data-thumb"))
- || (s = get_url_val_img(a, cast_uchar "src"))
- || (s = get_url_val_img(a, cast_uchar "dynsrc"))
- || (s = get_url_val_img(a, cast_uchar "data"))
- || (s = get_url_val_img(a, cast_uchar "content"))
- || (s = get_url_val(a, cast_uchar "src"))) {
- if (!s[0]) goto skip_img;
- format_.image = join_urls(format_.href_base, s);
- skip_img:
- orig_link = s;
+ || (s = get_url_val_img(a, cast_uchar "data-delay-url"))
+ || (s = get_url_val_img(a, cast_uchar "data-full"))
+ || (s = get_url_val_img(a, cast_uchar "data-lazy"))
+ || (s = get_url_val_img(a, cast_uchar "data-lazy-src"))
+ || (s = get_url_val_img(a, cast_uchar "data-li-src"))
+ || (s = get_url_val_img(a, cast_uchar "data-normal"))
+ || (s = get_url_val_img(a, cast_uchar "data-original"))
+ || (s = get_url_val_img(a, cast_uchar "data-small"))
+ || (s = get_url_val_img(a, cast_uchar "data-source"))
+ || (s = get_url_val_img(a, cast_uchar "data-src"))
+ || (s = get_url_val_img(a, cast_uchar "data-thumb"))
+ || (s = get_url_val_img(a, cast_uchar "src"))
+ || (s = get_url_val_img(a, cast_uchar "dynsrc"))
+ || (s = get_url_val_img(a, cast_uchar "data"))
+ || (s = get_url_val_img(a, cast_uchar "content"))
+ || (s = get_url_val(a, cast_uchar "src"))) {
+ if (!s[0])
+ goto skip_img;
+ format_.image = join_urls(format_.href_base, s);
+skip_img:
+ orig_link = s;
}
if ((!(al = get_attr_val(a, cast_uchar "alt"))
- && !(al = get_attr_val(a, cast_uchar "title")))
- || !*al) {
+ && !(al = get_attr_val(a, cast_uchar "title")))
+ || !*al) {
free(al);
if (!d_opt->images && !format_.link)
goto ret;
@@ -1080,27 +1230,32 @@ static void html_img(unsigned char *a)
}
html_format_changed = 1;
put_chrs(al, (int)strlen(cast_const_char al));
- if (ismap) kill_html_stack_item(&html_top);
+ if (ismap)
+ kill_html_stack_item(&html_top);
}
free(al);
- ret:
+ret:
free(format_.image);
format_.image = NULL;
html_format_changed = 1;
- if (usemap) kill_html_stack_item(&html_top);
+ if (usemap)
+ kill_html_stack_item(&html_top);
free(orig_link);
}
-static void html_obj(unsigned char *a, int obj)
+static void
+html_obj(unsigned char *a, int obj)
{
unsigned char *old_base = format_.href_base;
unsigned char *url;
unsigned char *type = get_attr_val(a, cast_uchar "type");
unsigned char *base;
- if ((base = get_url_val(a, cast_uchar "codebase"))) format_.href_base = join_urls(format_.href_base, base);
+ if ((base = get_url_val(a, cast_uchar "codebase")))
+ format_.href_base = join_urls(format_.href_base, base);
if (!type) {
url = get_url_val(a, cast_uchar "src");
- if (!url) url = get_url_val(a, cast_uchar "data");
+ if (!url)
+ url = get_url_val(a, cast_uchar "data");
if (url) {
unsigned char *ju = join_urls(format_.href_base, url);
type = get_content_type(NULL, ju);
@@ -1109,9 +1264,12 @@ static void html_obj(unsigned char *a, int obj)
}
}
url = get_url_val(a, cast_uchar "src");
- if (!url) url = get_url_val(a, cast_uchar "data");
+ if (!url)
+ url = get_url_val(a, cast_uchar "data");
if (url) {
- put_link_line(cast_uchar "", !obj ? cast_uchar "[EMBED]" : cast_uchar "[OBJ]", url, cast_uchar "");
+ put_link_line(cast_uchar "",
+ !obj ? cast_uchar "[EMBED]" : cast_uchar "[OBJ]",
+ url, cast_uchar "");
free(url);
}
if (base) {
@@ -1122,42 +1280,51 @@ static void html_obj(unsigned char *a, int obj)
free(type);
}
-static void html_embed(unsigned char *a)
+static void
+html_embed(unsigned char *a)
{
html_obj(a, 0);
}
-static void html_object(unsigned char *a)
+static void
+html_object(unsigned char *a)
{
html_obj(a, 1);
}
-static void html_body(unsigned char *a)
+static void
+html_body(unsigned char *a)
{
get_color(a, cast_uchar "text", &format_.fg);
get_color(a, cast_uchar "link", &format_.clink);
- if (has_attr(a, cast_uchar "onload")) special_f(ff, SP_SCRIPT, NULL);
+ if (has_attr(a, cast_uchar "onload"))
+ special_f(ff, SP_SCRIPT, NULL);
}
-static void html_skip(unsigned char *a)
+static void
+html_skip(unsigned char *a)
{
html_top.dontkill = 1;
html_top.invisible = INVISIBLE;
}
-static void html_title(unsigned char *a)
+static void
+html_title(unsigned char *a)
{
- if (a[0] == '>' && a[-1] == '/') return;
+ if (a[0] == '>' && a[-1] == '/')
+ return;
html_top.dontkill = 1;
html_top.invisible = INVISIBLE;
}
-int should_skip_script(unsigned char *a)
+int
+should_skip_script(unsigned char *a)
{
return !has_attr(a, cast_uchar "/");
}
-static void html_script(unsigned char *a)
+static void
+html_script(unsigned char *a)
{
unsigned char *s;
s = get_url_val(a, cast_uchar "src");
@@ -1169,121 +1336,170 @@ static void html_script(unsigned char *a)
}
}
-static void html_style(unsigned char *a)
+static void
+html_style(unsigned char *a)
{
html_top.dontkill = 1;
html_top.invisible = INVISIBLE_STYLE;
}
-static void html_center(unsigned char *a)
+static void
+html_center(unsigned char *a)
{
par_format.align = AL_CENTER;
- if (!table_level) par_format.leftmargin = par_format.rightmargin = 0;
+ if (!table_level)
+ par_format.leftmargin = par_format.rightmargin = 0;
}
-static void html_linebrk(unsigned char *a)
+static void
+html_linebrk(unsigned char *a)
{
unsigned char *al;
if ((al = get_attr_val(a, cast_uchar "align"))) {
- if (!casestrcmp(al, cast_uchar "left")) par_format.align = AL_LEFT;
- if (!casestrcmp(al, cast_uchar "right")) par_format.align = AL_RIGHT;
+ if (!casestrcmp(al, cast_uchar "left"))
+ par_format.align = AL_LEFT;
+ if (!casestrcmp(al, cast_uchar "right"))
+ par_format.align = AL_RIGHT;
if (!casestrcmp(al, cast_uchar "center")) {
par_format.align = AL_CENTER;
- if (!table_level) par_format.leftmargin = par_format.rightmargin = 0;
+ if (!table_level)
+ par_format.leftmargin = par_format.rightmargin =
+ 0;
}
- if (!casestrcmp(al, cast_uchar "justify")) par_format.align = AL_BLOCK;
+ if (!casestrcmp(al, cast_uchar "justify"))
+ par_format.align = AL_BLOCK;
free(al);
}
}
-static void html_br(unsigned char *a)
+static void
+html_br(unsigned char *a)
{
html_linebrk(a);
if (par_format.align != AL_NO && par_format.align != AL_NO_BREAKABLE) {
- if (was_br) ln_break(2);
+ if (was_br)
+ ln_break(2);
was_br = 1;
}
}
-static void html_form(unsigned char *a)
+static void
+html_form(unsigned char *a)
{
was_br = 1;
}
-static void html_p(unsigned char *a)
+static void
+html_p(unsigned char *a)
{
- if (par_format.leftmargin < margin) par_format.leftmargin = margin;
- if (par_format.rightmargin < margin) par_format.rightmargin = margin;
+ if (par_format.leftmargin < margin)
+ par_format.leftmargin = margin;
+ if (par_format.rightmargin < margin)
+ par_format.rightmargin = margin;
/*par_format.align = AL_LEFT;*/
html_linebrk(a);
}
-static void html_address(unsigned char *a)
+static void
+html_address(unsigned char *a)
{
par_format.leftmargin += 1;
par_format.align = AL_LEFT;
}
-static void html_blockquote(unsigned char *a)
+static void
+html_blockquote(unsigned char *a)
{
par_format.leftmargin += 2;
par_format.align = AL_LEFT;
}
-static void html_h(int h, unsigned char *a)
+static void
+html_h(int h, unsigned char *a)
{
par_format.align = AL_LEFT;
if (h == 1)
return;
html_linebrk(a);
switch (par_format.align) {
- case AL_LEFT:
- break;
- case AL_RIGHT:
- par_format.leftmargin = 0;
- par_format.rightmargin = (h - 2) * 2;
- break;
- case AL_CENTER:
- par_format.leftmargin = par_format.rightmargin = 0;
- break;
- case AL_BLOCK:
- par_format.leftmargin = par_format.rightmargin = (h - 2) * 2;
- break;
+ case AL_LEFT:
+ break;
+ case AL_RIGHT:
+ par_format.leftmargin = 0;
+ par_format.rightmargin = (h - 2) * 2;
+ break;
+ case AL_CENTER:
+ par_format.leftmargin = par_format.rightmargin = 0;
+ break;
+ case AL_BLOCK:
+ par_format.leftmargin = par_format.rightmargin = (h - 2) * 2;
+ break;
}
}
-static void html_h1(unsigned char *a) { html_h(1, a); }
-static void html_h2(unsigned char *a) { html_h(2, a); }
-static void html_h3(unsigned char *a) { html_h(3, a); }
-static void html_h4(unsigned char *a) { html_h(4, a); }
-static void html_h5(unsigned char *a) { html_h(5, a); }
-static void html_h6(unsigned char *a) { html_h(6, a); }
+static void
+html_h1(unsigned char *a)
+{
+ html_h(1, a);
+}
+static void
+html_h2(unsigned char *a)
+{
+ html_h(2, a);
+}
+static void
+html_h3(unsigned char *a)
+{
+ html_h(3, a);
+}
+static void
+html_h4(unsigned char *a)
+{
+ html_h(4, a);
+}
+static void
+html_h5(unsigned char *a)
+{
+ html_h(5, a);
+}
+static void
+html_h6(unsigned char *a)
+{
+ html_h(6, a);
+}
-static void html_pre(unsigned char *a)
+static void
+html_pre(unsigned char *a)
{
unsigned char *cl;
format_.attr |= AT_FIXED;
- par_format.align = !par_format.implicit_pre_wrap ? AL_NO : AL_NO_BREAKABLE;
+ par_format.align =
+ !par_format.implicit_pre_wrap ? AL_NO : AL_NO_BREAKABLE;
par_format.leftmargin = par_format.leftmargin > 1;
par_format.rightmargin = par_format.leftmargin;
if ((cl = get_attr_val(a, cast_uchar "class"))) {
- if (strstr(cast_const_char cl, "bz_comment")) /* hack */
+ if (strstr(cast_const_char cl, "bz_comment")) /* hack */
par_format.align = AL_NO_BREAKABLE;
free(cl);
}
}
-static void html_div(unsigned char *a)
+static void
+html_div(unsigned char *a)
{
unsigned char *al;
if ((al = get_attr_val(a, cast_uchar "class"))) {
- if (!strcmp(cast_const_char al, "commit-msg") ||
- !strcmp(cast_const_char al, "pre") /* sourceware hack */ ||
- (!strncmp(cast_const_char al, "diff", 4) && casestrcmp(al, cast_uchar "diff-view") && strncmp(cast_const_char al, "diffbar", 7)) /* gitweb hack, github counter-hacks */ ||
- 0) {
+ if (!strcmp(cast_const_char al, "commit-msg")
+ || !strcmp(cast_const_char al, "pre") /* sourceware hack */
+ || (!strncmp(cast_const_char al, "diff", 4)
+ && casestrcmp(al, cast_uchar "diff-view")
+ && strncmp(cast_const_char al, "diffbar",
+ 7)) /* gitweb hack, github counter-hacks */
+ || 0) {
format_.attr |= AT_FIXED;
par_format.align = AL_NO;
- } else if (strstr(cast_const_char al, "plain-text-white-space")) {
+ } else if (strstr(cast_const_char al,
+ "plain-text-white-space")) {
format_.attr |= AT_FIXED;
par_format.align = AL_NO_BREAKABLE;
}
@@ -1292,7 +1508,8 @@ static void html_div(unsigned char *a)
html_linebrk(a);
}
-static void html_hr(unsigned char *a)
+static void
+html_hr(unsigned char *a)
{
int i;
int q = get_num(a, cast_uchar "size");
@@ -1322,7 +1539,8 @@ static void html_hr(unsigned char *a)
kill_html_stack_item(&html_top);
}
-static void html_table(unsigned char *a)
+static void
+html_table(unsigned char *a)
{
par_format.leftmargin = margin;
par_format.rightmargin = margin;
@@ -1331,28 +1549,34 @@ static void html_table(unsigned char *a)
format_.attr = 0;
}
-static void html_tr(unsigned char *a)
+static void
+html_tr(unsigned char *a)
{
html_linebrk(a);
}
-static void html_th(unsigned char *a)
+static void
+html_th(unsigned char *a)
{
/*html_linebrk(a);*/
- kill_until(1, cast_uchar "TD", cast_uchar "TH", cast_uchar "", cast_uchar "TR", cast_uchar "TABLE", NULL);
+ kill_until(1, cast_uchar "TD", cast_uchar "TH", cast_uchar "",
+ cast_uchar "TR", cast_uchar "TABLE", NULL);
format_.attr |= AT_BOLD;
put_chrs(cast_uchar " ", 1);
}
-static void html_td(unsigned char *a)
+static void
+html_td(unsigned char *a)
{
/*html_linebrk(a);*/
- kill_until(1, cast_uchar "TD", cast_uchar "TH", cast_uchar "", cast_uchar "TR", cast_uchar "TABLE", NULL);
+ kill_until(1, cast_uchar "TD", cast_uchar "TH", cast_uchar "",
+ cast_uchar "TR", cast_uchar "TABLE", NULL);
format_.attr &= ~AT_BOLD;
put_chrs(cast_uchar " ", 1);
}
-static void html_base(unsigned char *a)
+static void
+html_base(unsigned char *a)
{
unsigned char *al;
if ((al = get_url_val(a, cast_uchar "href"))) {
@@ -1367,7 +1591,8 @@ static void html_base(unsigned char *a)
}
}
-static void html_ul(unsigned char *a)
+static void
+html_ul(unsigned char *a)
{
unsigned char *al;
/*debug_stack();*/
@@ -1375,49 +1600,68 @@ static void html_ul(unsigned char *a)
par_format.list_number = 0;
par_format.flags = P_STAR;
if ((al = get_attr_val(a, cast_uchar "type"))) {
- if (!casestrcmp(al, cast_uchar "disc") ||
- !casestrcmp(al, cast_uchar "circle")) par_format.flags = P_O;
- if (!casestrcmp(al, cast_uchar "square")) par_format.flags = P_PLUS;
+ if (!casestrcmp(al, cast_uchar "disc")
+ || !casestrcmp(al, cast_uchar "circle"))
+ par_format.flags = P_O;
+ if (!casestrcmp(al, cast_uchar "square"))
+ par_format.flags = P_PLUS;
free(al);
}
- if ((par_format.leftmargin += 2 + (par_format.list_level > 1)) > par_format.width * 2 / 3 && !table_level)
+ if ((par_format.leftmargin += 2 + (par_format.list_level > 1))
+ > par_format.width * 2 / 3
+ && !table_level)
par_format.leftmargin = par_format.width * 2 / 3;
par_format.align = AL_LEFT;
html_top.dontkill = 1;
}
-static void html_ol(unsigned char *a)
+static void
+html_ol(unsigned char *a)
{
unsigned char *al;
int st;
par_format.list_level++;
st = get_num(a, cast_uchar "start");
- if (st == -1) st = 1;
+ if (st == -1)
+ st = 1;
par_format.list_number = st;
par_format.flags = P_NUMBER;
if ((al = get_attr_val(a, cast_uchar "type"))) {
- if (!strcmp(cast_const_char al, "1")) par_format.flags = P_NUMBER;
- if (!strcmp(cast_const_char al, "a")) par_format.flags = P_alpha;
- if (!strcmp(cast_const_char al, "A")) par_format.flags = P_ALPHA;
- if (!strcmp(cast_const_char al, "r")) par_format.flags = P_roman;
- if (!strcmp(cast_const_char al, "R")) par_format.flags = P_ROMAN;
- if (!strcmp(cast_const_char al, "i")) par_format.flags = P_roman;
- if (!strcmp(cast_const_char al, "I")) par_format.flags = P_ROMAN;
+ if (!strcmp(cast_const_char al, "1"))
+ par_format.flags = P_NUMBER;
+ if (!strcmp(cast_const_char al, "a"))
+ par_format.flags = P_alpha;
+ if (!strcmp(cast_const_char al, "A"))
+ par_format.flags = P_ALPHA;
+ if (!strcmp(cast_const_char al, "r"))
+ par_format.flags = P_roman;
+ if (!strcmp(cast_const_char al, "R"))
+ par_format.flags = P_ROMAN;
+ if (!strcmp(cast_const_char al, "i"))
+ par_format.flags = P_roman;
+ if (!strcmp(cast_const_char al, "I"))
+ par_format.flags = P_ROMAN;
free(al);
}
- if ((par_format.leftmargin += (par_format.list_level > 1)) > par_format.width * 2 / 3 && !table_level)
+ if ((par_format.leftmargin += (par_format.list_level > 1))
+ > par_format.width * 2 / 3
+ && !table_level)
par_format.leftmargin = par_format.width * 2 / 3;
par_format.align = AL_LEFT;
html_top.dontkill = 1;
}
-static void html_li(unsigned char *a)
+static void
+html_li(unsigned char *a)
{
- /*kill_until(0, cast_uchar "", cast_uchar "UL", cast_uchar "OL", NULL);*/
+ /*kill_until(0, cast_uchar "", cast_uchar "UL", cast_uchar "OL",
+ * NULL);*/
if (!par_format.list_number) {
unsigned char x[8] = "* ";
- if ((par_format.flags & P_LISTMASK) == P_O) x[0] = 'o';
- if ((par_format.flags & P_LISTMASK) == P_PLUS) x[0] = '+';
+ if ((par_format.flags & P_LISTMASK) == P_O)
+ x[0] = 'o';
+ if ((par_format.flags & P_LISTMASK) == P_PLUS)
+ x[0] = '+';
put_chrs(x, 7);
par_format.leftmargin += 2;
par_format.align = AL_LEFT;
@@ -1427,15 +1671,19 @@ static void html_li(unsigned char *a)
char n[32];
int t = par_format.flags & P_LISTMASK;
int s = get_num(a, cast_uchar "value");
- if (s != -1) par_format.list_number = s;
+ if (s != -1)
+ par_format.list_number = s;
if ((t != P_roman && t != P_ROMAN
- && par_format.list_number < 10)
- || t == P_alpha || t == P_ALPHA) {
+ && par_format.list_number < 10)
+ || t == P_alpha || t == P_ALPHA) {
put_chrs(cast_uchar " ", 6);
c = 1;
}
if (t == P_ALPHA || t == P_alpha) {
- n[0] = par_format.list_number ? (par_format.list_number - 1) % 26 + (t == P_ALPHA ? 'A' : 'a') : 0;
+ n[0] = par_format.list_number
+ ? (par_format.list_number - 1) % 26
+ + (t == P_ALPHA ? 'A' : 'a')
+ : 0;
n[1] = 0;
} else if (t == P_ROMAN || t == P_roman) {
roman(n, par_format.list_number, sizeof(n));
@@ -1444,23 +1692,28 @@ static void html_li(unsigned char *a)
for (x = n; *x; x++)
*x = upcase(*x);
}
- } else sprintf(cast_char n, "%d", par_format.list_number);
+ } else
+ sprintf(cast_char n, "%d", par_format.list_number);
put_chrs((unsigned char *)n, strlen(n));
put_chrs(cast_uchar ". ", 7);
par_format.leftmargin += (int)strlen(cast_const_char n) + c + 2;
par_format.align = AL_LEFT;
- list_struct(html_top.list_entry.next, struct html_element)->parattr.list_number = par_format.list_number + 1;
+ list_struct(html_top.list_entry.next, struct html_element)
+ ->parattr.list_number = par_format.list_number + 1;
par_format.list_number = 0;
putsp = -1;
}
line_breax = 2;
}
-static void html_dl(unsigned char *a)
+static void
+html_dl(unsigned char *a)
{
par_format.flags &= ~P_COMPACT;
- if (has_attr(a, cast_uchar "compact")) par_format.flags |= P_COMPACT;
- if (par_format.list_level) par_format.leftmargin += 5;
+ if (has_attr(a, cast_uchar "compact"))
+ par_format.flags |= P_COMPACT;
+ if (par_format.list_level)
+ par_format.leftmargin += 5;
par_format.list_level++;
par_format.list_number = 0;
par_format.align = AL_LEFT;
@@ -1472,24 +1725,31 @@ static void html_dl(unsigned char *a)
}
}
-static void html_dt(unsigned char *a)
+static void
+html_dt(unsigned char *a)
{
kill_until(0, cast_uchar "", cast_uchar "DL", NULL);
par_format.align = AL_LEFT;
par_format.leftmargin = par_format.dd_margin;
- if (!(par_format.flags & P_COMPACT) && !has_attr(a, cast_uchar "compact"))
+ if (!(par_format.flags & P_COMPACT)
+ && !has_attr(a, cast_uchar "compact"))
ln_break(2);
}
-static void html_dd(unsigned char *a)
+static void
+html_dd(unsigned char *a)
{
kill_until(0, cast_uchar "", cast_uchar "DL", NULL);
- if ((par_format.leftmargin = par_format.dd_margin + (table_level ? 3 : 8)) > par_format.width * 2 / 3 && !table_level)
+ if ((par_format.leftmargin =
+ par_format.dd_margin + (table_level ? 3 : 8))
+ > par_format.width * 2 / 3
+ && !table_level)
par_format.leftmargin = par_format.width * 2 / 3;
par_format.align = AL_LEFT;
}
-static void get_html_form(unsigned char *a, struct form *form)
+static void
+get_html_form(unsigned char *a, struct form *form)
{
unsigned char *al;
unsigned char *ch;
@@ -1499,7 +1759,8 @@ static void get_html_form(unsigned char *a, struct form *form)
unsigned char *ax;
form->method = FM_POST;
if ((ax = get_attr_val(a, cast_uchar "enctype"))) {
- if (!casestrcmp(ax, cast_uchar "multipart/form-data"))
+ if (!casestrcmp(ax, cast_uchar
+ "multipart/form-data"))
form->method = FM_POST_MP;
free(ax);
}
@@ -1515,23 +1776,29 @@ static void get_html_form(unsigned char *a, struct form *form)
form->action = join_urls(format_.href_base, all);
free(al);
} else {
- if ((ch = cast_uchar strchr(cast_const_char(form->action = stracpy(format_.href_base)), POST_CHAR)))
+ if ((ch = cast_uchar strchr(
+ cast_const_char(form->action =
+ stracpy(format_.href_base)),
+ POST_CHAR)))
*ch = 0;
- if (form->method == FM_GET && (ch = cast_uchar strchr(cast_const_char form->action, '?')))
+ if (form->method == FM_GET
+ && (ch = cast_uchar strchr(cast_const_char form->action,
+ '?')))
*ch = 0;
}
if ((al = get_target(a))) {
form->target = al;
} else
form->target = stracpy(format_.target_base);
- if ((al=get_attr_val(a,cast_uchar "name")))
+ if ((al = get_attr_val(a, cast_uchar "name")))
form->form_name = al;
- if ((al=get_attr_val(a,cast_uchar "onsubmit")))
+ if ((al = get_attr_val(a, cast_uchar "onsubmit")))
form->onsubmit = al;
form->num = (int)(a - startf);
}
-static void find_form_for_input(unsigned char *i)
+static void
+find_form_for_input(unsigned char *i)
{
unsigned char *s, *ss, *name, *attr, *lf, *la;
int namelen;
@@ -1540,8 +1807,10 @@ static void find_form_for_input(unsigned char *i)
free(form.form_name);
free(form.onsubmit);
memset(&form, 0, sizeof(struct form));
- if (!special_f(ff, SP_USED, NULL)) return;
- if (last_form_tag && last_input_tag && i <= last_input_tag && i > last_form_tag) {
+ if (!special_f(ff, SP_USED, NULL))
+ return;
+ if (last_form_tag && last_input_tag && i <= last_input_tag
+ && i > last_form_tag) {
get_html_form(last_form_attr, &form);
return;
}
@@ -1555,21 +1824,26 @@ static void find_form_for_input(unsigned char *i)
la = NULL;
s = startf;
}
- se:
- while (s < i && *s != '<') sp:s++;
- if (s >= i) goto end_parse;
+se:
+ while (s < i && *s != '<')
+sp:
+ s++;
+ if (s >= i)
+ goto end_parse;
if (eofff - s >= 2 && (s[1] == '!' || s[1] == '?')) {
s = skip_comment(s, i);
goto se;
}
ss = s;
- if (parse_element(s, i, &name, &namelen, &attr, &s)) goto sp;
- if (namelen != 4 || casecmp(name, cast_uchar "FORM", 4)) goto se;
+ if (parse_element(s, i, &name, &namelen, &attr, &s))
+ goto sp;
+ if (namelen != 4 || casecmp(name, cast_uchar "FORM", 4))
+ goto se;
lf = ss;
la = attr;
goto se;
- end_parse:
+end_parse:
if (lf) {
last_form_tag = lf;
last_form_attr = la;
@@ -1580,7 +1854,8 @@ static void find_form_for_input(unsigned char *i)
}
}
-static void html_button(unsigned char *a)
+static void
+html_button(unsigned char *a)
{
unsigned char *al;
struct form_control *fc;
@@ -1602,9 +1877,10 @@ static void html_button(unsigned char *a)
return;
}
free(al);
- xxx:
+xxx:
fc->form_num = last_form_tag ? (int)(last_form_tag - startf) : 0;
- fc->ctrl_num = last_form_tag ? (int)(a - last_form_tag) : (int)(a - startf);
+ fc->ctrl_num =
+ last_form_tag ? (int)(a - last_form_tag) : (int)(a - startf);
fc->position = (int)(a - startf);
fc->method = form.method;
fc->action = stracpy(form.action);
@@ -1612,7 +1888,9 @@ static void html_button(unsigned char *a)
fc->onsubmit = stracpy(form.onsubmit);
fc->name = get_attr_val(a, cast_uchar "name");
fc->default_value = get_exact_attr_val(a, cast_uchar "value");
- fc->ro = has_attr(a, cast_uchar "disabled") ? 2 : has_attr(a, cast_uchar "readonly") ? 1 : 0;
+ fc->ro = has_attr(a, cast_uchar "disabled") ? 2
+ : has_attr(a, cast_uchar "readonly") ? 1
+ : 0;
if (fc->type == FC_SUBMIT && !fc->default_value)
fc->default_value = stracpy(cast_uchar "Submit");
if (fc->type == FC_RESET && !fc->default_value)
@@ -1631,7 +1909,8 @@ static void html_button(unsigned char *a)
p = find_element_end(a);
p1:
while (p < eoff && WHITECHAR(*p))
- p2:p++;
+p2:
+ p++;
if (p == eoff)
goto put_text;
if (*p != '<')
@@ -1648,26 +1927,31 @@ p1:
put_text:
put_chrs(cast_uchar "[ ", 7);
- put_chrs(fc->default_value, (int)strlen(cast_const_char fc->default_value));
+ put_chrs(fc->default_value,
+ (int)strlen(cast_const_char fc->default_value));
put_chrs(cast_uchar " ]", 7);
putsp = -1;
}
}
-static void set_max_textarea_width(int *w)
+static void
+set_max_textarea_width(int *w)
{
int limit;
if (!table_level)
- limit = par_format.width - par_format.leftmargin + par_format.rightmargin;
+ limit = par_format.width - par_format.leftmargin
+ + par_format.rightmargin;
else
limit = d_opt->xw - 2;
if (*w > limit) {
*w = limit;
- if (*w < HTML_MINIMAL_TEXTAREA_WIDTH) *w = HTML_MINIMAL_TEXTAREA_WIDTH;
+ if (*w < HTML_MINIMAL_TEXTAREA_WIDTH)
+ *w = HTML_MINIMAL_TEXTAREA_WIDTH;
}
}
-static void html_input(unsigned char *a)
+static void
+html_input(unsigned char *a)
{
int i;
int size;
@@ -1676,25 +1960,39 @@ static void html_input(unsigned char *a)
find_form_for_input(a);
fc = mem_calloc(sizeof(struct form_control));
if (!(al = get_attr_val(a, cast_uchar "type"))) {
- if (has_attr(a, cast_uchar "onclick")) fc->type = FC_BUTTON;
- else fc->type = FC_TEXT;
+ if (has_attr(a, cast_uchar "onclick"))
+ fc->type = FC_BUTTON;
+ else
+ fc->type = FC_TEXT;
goto xxx;
}
- if (!casestrcmp(al, cast_uchar "text")) fc->type = FC_TEXT;
- else if (!casestrcmp(al, cast_uchar "password")) fc->type = FC_PASSWORD;
- else if (!casestrcmp(al, cast_uchar "checkbox")) fc->type = FC_CHECKBOX;
- else if (!casestrcmp(al, cast_uchar "radio")) fc->type = FC_RADIO;
- else if (!casestrcmp(al, cast_uchar "submit")) fc->type = FC_SUBMIT;
- else if (!casestrcmp(al, cast_uchar "reset")) fc->type = FC_RESET;
- else if (!casestrcmp(al, cast_uchar "file")) fc->type = FC_FILE_UPLOAD;
- else if (!casestrcmp(al, cast_uchar "hidden")) fc->type = FC_HIDDEN;
- else if (!casestrcmp(al, cast_uchar "image")) fc->type = FC_IMAGE;
- else if (!casestrcmp(al, cast_uchar "button")) fc->type = FC_BUTTON;
- else fc->type = FC_TEXT;
+ if (!casestrcmp(al, cast_uchar "text"))
+ fc->type = FC_TEXT;
+ else if (!casestrcmp(al, cast_uchar "password"))
+ fc->type = FC_PASSWORD;
+ else if (!casestrcmp(al, cast_uchar "checkbox"))
+ fc->type = FC_CHECKBOX;
+ else if (!casestrcmp(al, cast_uchar "radio"))
+ fc->type = FC_RADIO;
+ else if (!casestrcmp(al, cast_uchar "submit"))
+ fc->type = FC_SUBMIT;
+ else if (!casestrcmp(al, cast_uchar "reset"))
+ fc->type = FC_RESET;
+ else if (!casestrcmp(al, cast_uchar "file"))
+ fc->type = FC_FILE_UPLOAD;
+ else if (!casestrcmp(al, cast_uchar "hidden"))
+ fc->type = FC_HIDDEN;
+ else if (!casestrcmp(al, cast_uchar "image"))
+ fc->type = FC_IMAGE;
+ else if (!casestrcmp(al, cast_uchar "button"))
+ fc->type = FC_BUTTON;
+ else
+ fc->type = FC_TEXT;
free(al);
- xxx:
+xxx:
fc->form_num = last_form_tag ? (int)(last_form_tag - startf) : 0;
- fc->ctrl_num = last_form_tag ? (int)(a - last_form_tag) : (int)(a - startf);
+ fc->ctrl_num =
+ last_form_tag ? (int)(a - last_form_tag) : (int)(a - startf);
fc->position = (int)(a - startf);
fc->method = form.method;
fc->action = stracpy(form.action);
@@ -1702,105 +2000,132 @@ static void html_input(unsigned char *a)
fc->onsubmit = stracpy(form.onsubmit);
fc->target = stracpy(form.target);
fc->name = get_attr_val(a, cast_uchar "name");
- if (fc->type == FC_TEXT || fc->type == FC_PASSWORD) fc->default_value = get_attr_val(a, cast_uchar "value");
- else if (fc->type != FC_FILE_UPLOAD) fc->default_value = get_exact_attr_val(a, cast_uchar "value");
- if (fc->type == FC_CHECKBOX && !fc->default_value) fc->default_value = stracpy(cast_uchar "on");
- if ((size = get_num(a, cast_uchar "size")) <= 1) size = HTML_DEFAULT_INPUT_SIZE;
+ if (fc->type == FC_TEXT || fc->type == FC_PASSWORD)
+ fc->default_value = get_attr_val(a, cast_uchar "value");
+ else if (fc->type != FC_FILE_UPLOAD)
+ fc->default_value = get_exact_attr_val(a, cast_uchar "value");
+ if (fc->type == FC_CHECKBOX && !fc->default_value)
+ fc->default_value = stracpy(cast_uchar "on");
+ if ((size = get_num(a, cast_uchar "size")) <= 1)
+ size = HTML_DEFAULT_INPUT_SIZE;
size++;
if (size > HTML_MINIMAL_TEXTAREA_WIDTH) {
set_max_textarea_width(&size);
}
fc->size = size;
- if ((fc->maxlength = get_num(a, cast_uchar "maxlength")) == -1) fc->maxlength = INT_MAX / 4;
- if (fc->type == FC_CHECKBOX || fc->type == FC_RADIO) fc->default_state = has_attr(a, cast_uchar "checked");
- fc->ro = has_attr(a, cast_uchar "disabled") ? 2 : has_attr(a, cast_uchar "readonly") ? 1 : 0;
+ if ((fc->maxlength = get_num(a, cast_uchar "maxlength")) == -1)
+ fc->maxlength = INT_MAX / 4;
+ if (fc->type == FC_CHECKBOX || fc->type == FC_RADIO)
+ fc->default_state = has_attr(a, cast_uchar "checked");
+ fc->ro = has_attr(a, cast_uchar "disabled") ? 2
+ : has_attr(a, cast_uchar "readonly") ? 1
+ : 0;
if (fc->type == FC_IMAGE) {
fc->alt = get_attr_val(a, cast_uchar "alt");
- if (!fc->alt) fc->alt = get_attr_val(a, cast_uchar "title");
- if (!fc->alt) fc->alt = get_attr_val(a, cast_uchar "name");
+ if (!fc->alt)
+ fc->alt = get_attr_val(a, cast_uchar "title");
+ if (!fc->alt)
+ fc->alt = get_attr_val(a, cast_uchar "name");
}
- if (fc->type == FC_SUBMIT && !fc->default_value) fc->default_value = stracpy(cast_uchar "Submit");
- if (fc->type == FC_RESET && !fc->default_value) fc->default_value = stracpy(cast_uchar "Reset");
- if (!fc->default_value) fc->default_value = stracpy(cast_uchar "");
- if (fc->type == FC_HIDDEN) goto hid;
+ if (fc->type == FC_SUBMIT && !fc->default_value)
+ fc->default_value = stracpy(cast_uchar "Submit");
+ if (fc->type == FC_RESET && !fc->default_value)
+ fc->default_value = stracpy(cast_uchar "Reset");
+ if (!fc->default_value)
+ fc->default_value = stracpy(cast_uchar "");
+ if (fc->type == FC_HIDDEN)
+ goto hid;
put_chrs(cast_uchar " ", 1);
html_stack_dup();
format_.form = fc;
switch (fc->type) {
- case FC_TEXT:
- case FC_PASSWORD:
- case FC_FILE_UPLOAD:
- format_.attr |= AT_BOLD | AT_FIXED;
- format_.fontsize = 3;
- for (i = 0; i < fc->size; i++) put_chrs(cast_uchar "_", 1);
- break;
- case FC_CHECKBOX:
- format_.attr |= AT_BOLD | AT_FIXED;
- format_.fontsize = 3;
- put_chrs(cast_uchar "[ ]", 8);
- break;
- case FC_RADIO:
- format_.attr |= AT_BOLD | AT_FIXED;
- format_.fontsize = 3;
- put_chrs(cast_uchar "[ ]", 8);
- break;
- case FC_IMAGE:
- free(format_.image);
- format_.image = NULL;
- if ((al = get_url_val(a, cast_uchar "src")) || (al = get_url_val(a, cast_uchar "dynsrc"))) {
- format_.image = join_urls(format_.href_base, al);
- free(al);
- }
- format_.attr |= AT_BOLD | AT_FIXED;
- put_chrs(cast_uchar "[ ", 7);
- if (fc->alt)
- put_chrs(fc->alt, (int)strlen(cast_const_char fc->alt));
- else
- put_chrs(cast_uchar "Submit", 6);
- put_chrs(cast_uchar " ]", 7);
- break;
- case FC_SUBMIT:
- case FC_RESET:
- format_.attr |= AT_BOLD | AT_FIXED;
- format_.fontsize = 3;
- put_chrs(cast_uchar "[ ", 7);
- if (fc->default_value) put_chrs(fc->default_value, (int)strlen(cast_const_char fc->default_value));
- put_chrs(cast_uchar " ]", 7);
- break;
- case FC_BUTTON:
- format_.attr |= AT_BOLD | AT_FIXED;
- format_.fontsize = 3;
- put_chrs(cast_uchar "[ ", 7);
- if (fc->default_value) put_chrs(fc->default_value, (int)strlen(cast_const_char fc->default_value));
- else put_chrs(cast_uchar "BUTTON", 6);
- put_chrs(cast_uchar " ]", 7);
- break;
- default:
- internal("bad control type");
+ case FC_TEXT:
+ case FC_PASSWORD:
+ case FC_FILE_UPLOAD:
+ format_.attr |= AT_BOLD | AT_FIXED;
+ format_.fontsize = 3;
+ for (i = 0; i < fc->size; i++)
+ put_chrs(cast_uchar "_", 1);
+ break;
+ case FC_CHECKBOX:
+ format_.attr |= AT_BOLD | AT_FIXED;
+ format_.fontsize = 3;
+ put_chrs(cast_uchar "[ ]", 8);
+ break;
+ case FC_RADIO:
+ format_.attr |= AT_BOLD | AT_FIXED;
+ format_.fontsize = 3;
+ put_chrs(cast_uchar "[ ]", 8);
+ break;
+ case FC_IMAGE:
+ free(format_.image);
+ format_.image = NULL;
+ if ((al = get_url_val(a, cast_uchar "src"))
+ || (al = get_url_val(a, cast_uchar "dynsrc"))) {
+ format_.image = join_urls(format_.href_base, al);
+ free(al);
+ }
+ format_.attr |= AT_BOLD | AT_FIXED;
+ put_chrs(cast_uchar "[ ", 7);
+ if (fc->alt)
+ put_chrs(fc->alt, (int)strlen(cast_const_char fc->alt));
+ else
+ put_chrs(cast_uchar "Submit", 6);
+ put_chrs(cast_uchar " ]", 7);
+ break;
+ case FC_SUBMIT:
+ case FC_RESET:
+ format_.attr |= AT_BOLD | AT_FIXED;
+ format_.fontsize = 3;
+ put_chrs(cast_uchar "[ ", 7);
+ if (fc->default_value)
+ put_chrs(
+ fc->default_value,
+ (int)strlen(cast_const_char fc->default_value));
+ put_chrs(cast_uchar " ]", 7);
+ break;
+ case FC_BUTTON:
+ format_.attr |= AT_BOLD | AT_FIXED;
+ format_.fontsize = 3;
+ put_chrs(cast_uchar "[ ", 7);
+ if (fc->default_value)
+ put_chrs(
+ fc->default_value,
+ (int)strlen(cast_const_char fc->default_value));
+ else
+ put_chrs(cast_uchar "BUTTON", 6);
+ put_chrs(cast_uchar " ]", 7);
+ break;
+ default:
+ internal("bad control type");
}
kill_html_stack_item(&html_top);
put_chrs(cast_uchar " ", 1);
- hid:
+hid:
special_f(ff, SP_CONTROL, fc);
}
-static void html_select(unsigned char *a)
+static void
+html_select(unsigned char *a)
{
unsigned char *al;
- if (!(al = get_attr_val(a, cast_uchar "name"))) return;
+ if (!(al = get_attr_val(a, cast_uchar "name")))
+ return;
html_top.dontkill = 1;
free(format_.select);
format_.select = al;
format_.select_disabled = 2 * has_attr(a, cast_uchar "disabled");
}
-static void html_option(unsigned char *a)
+static void
+html_option(unsigned char *a)
{
struct form_control *fc;
unsigned char *val;
find_form_for_input(a);
- if (!format_.select) return;
+ if (!format_.select)
+ return;
fc = mem_calloc(sizeof(struct form_control));
if (!(val = get_exact_attr_val(a, cast_uchar "value"))) {
unsigned char *p, *r;
@@ -1809,31 +2134,42 @@ static void html_option(unsigned char *a)
int l = 0;
val = init_str();
p = find_element_end(a);
- rrrr:
- while (p < eoff && WHITECHAR(*p)) p++;
+rrrr:
+ while (p < eoff && WHITECHAR(*p))
+ p++;
while (p < eoff && !WHITECHAR(*p) && *p != '<') {
- pppp:
+pppp:
add_chr_to_str(&val, &l, *p);
p++;
}
r = p;
- while (r < eoff && WHITECHAR(*r)) r++;
- if (r >= eoff) goto x;
+ while (r < eoff && WHITECHAR(*r))
+ r++;
+ if (r >= eoff)
+ goto x;
if (eoff - r >= 2 && (r[1] == '!' || r[1] == '?')) {
p = skip_comment(r, eoff);
goto rrrr;
}
- if (parse_element(r, eoff, &name, &namelen, NULL, &p)) goto pppp;
- if (!((namelen == 6 && !casecmp(name, cast_uchar "OPTION", 6)) ||
- (namelen == 7 && !casecmp(name, cast_uchar "/OPTION", 7)) ||
- (namelen == 6 && !casecmp(name, cast_uchar "SELECT", 6)) ||
- (namelen == 7 && !casecmp(name, cast_uchar "/SELECT", 7)) ||
- (namelen == 8 && !casecmp(name, cast_uchar "OPTGROUP", 8)) ||
- (namelen == 9 && !casecmp(name, cast_uchar "/OPTGROUP", 9)))) goto rrrr;
+ if (parse_element(r, eoff, &name, &namelen, NULL, &p))
+ goto pppp;
+ if (!((namelen == 6 && !casecmp(name, cast_uchar "OPTION", 6))
+ || (namelen == 7
+ && !casecmp(name, cast_uchar "/OPTION", 7))
+ || (namelen == 6
+ && !casecmp(name, cast_uchar "SELECT", 6))
+ || (namelen == 7
+ && !casecmp(name, cast_uchar "/SELECT", 7))
+ || (namelen == 8
+ && !casecmp(name, cast_uchar "OPTGROUP", 8))
+ || (namelen == 9
+ && !casecmp(name, cast_uchar "/OPTGROUP", 9))))
+ goto rrrr;
}
- x:
+x:
fc->form_num = last_form_tag ? (int)(last_form_tag - startf) : 0;
- fc->ctrl_num = last_form_tag ? (int)(a - last_form_tag) : (int)(a - startf);
+ fc->ctrl_num =
+ last_form_tag ? (int)(a - last_form_tag) : (int)(a - startf);
fc->position = (int)(a - startf);
fc->method = form.method;
fc->action = stracpy(form.action);
@@ -1844,7 +2180,8 @@ static void html_option(unsigned char *a)
fc->default_value = val;
fc->default_state = has_attr(a, cast_uchar "selected");
fc->ro = format_.select_disabled;
- if (has_attr(a, cast_uchar "disabled")) fc->ro = 2;
+ if (has_attr(a, cast_uchar "disabled"))
+ fc->ro = 2;
put_chrs(cast_uchar " ", 1);
html_stack_dup();
format_.form = fc;
@@ -1856,20 +2193,26 @@ static void html_option(unsigned char *a)
special_f(ff, SP_CONTROL, fc);
}
-void clr_white(unsigned char *name)
+void
+clr_white(unsigned char *name)
{
unsigned char *nm;
for (nm = name; *nm; nm++)
- if (WHITECHAR(*nm) || *nm == 1) *nm = ' ';
+ if (WHITECHAR(*nm) || *nm == 1)
+ *nm = ' ';
}
-void clr_spaces(unsigned char *name, int firstlast)
+void
+clr_spaces(unsigned char *name, int firstlast)
{
unsigned char *n1, *n2;
clr_white(name);
- if (!strchr(cast_const_char name, ' ')) return;
+ if (!strchr(cast_const_char name, ' '))
+ return;
for (n1 = name, n2 = name; *n1; n1++)
- if (!(n1[0] == ' ' && ((firstlast && n2 == name) || n1[1] == ' ' || (firstlast && !n1[1]))))
+ if (!(n1[0] == ' '
+ && ((firstlast && n2 == name) || n1[1] == ' '
+ || (firstlast && !n1[1]))))
*n2++ = *n1;
*n2 = 0;
}
@@ -1877,17 +2220,20 @@ void clr_spaces(unsigned char *name, int firstlast)
static int menu_stack_size;
static struct menu_item **menu_stack;
-static void new_menu_item(unsigned char *name, long data, int fullname)
- /* name == NULL - up; data == -1 - down */
+static void
+new_menu_item(unsigned char *name, long data, int fullname)
+/* name == NULL - up; data == -1 - down */
{
- struct menu_item *top, *item, *nmenu = NULL; /* no uninitialized warnings */
+ struct menu_item *top, *item,
+ *nmenu = NULL; /* no uninitialized warnings */
if (name) {
clr_spaces(name, 1);
if (!name[0]) {
free(name);
name = stracpy(cast_uchar " ");
}
- if (name[0] == 1) name[0] = ' ';
+ if (name[0] == 1)
+ name[0] = ' ';
}
if (name && data == -1) {
nmenu = mem_calloc(sizeof(struct menu_item));
@@ -1895,21 +2241,26 @@ static void new_menu_item(unsigned char *name, long data, int fullname)
}
if (menu_stack_size && name) {
top = item = menu_stack[menu_stack_size - 1];
- while (item->text) item++;
- if ((size_t)((unsigned char *)(item + 2) - (unsigned char *)top) > INT_MAX)
+ while (item->text)
+ item++;
+ if ((size_t)((unsigned char *)(item + 2) - (unsigned char *)top)
+ > INT_MAX)
overalloc();
top = xrealloc(top, (unsigned char *)(item + 2)
- - (unsigned char *)top);
+ - (unsigned char *)top);
item = item - menu_stack[menu_stack_size - 1] + top;
menu_stack[menu_stack_size - 1] = top;
if (menu_stack_size >= 2) {
- struct menu_item *below = menu_stack[menu_stack_size - 2];
- while (below->text) below++;
+ struct menu_item *below =
+ menu_stack[menu_stack_size - 2];
+ while (below->text)
+ below++;
below[-1].data = top;
}
item->text = name;
item->rtext = data == -1 ? cast_uchar ">" : cast_uchar "";
- item->hotkey = fullname ? cast_uchar "\000\001" : cast_uchar "\000\000"; /* dirty */
+ item->hotkey = fullname ? cast_uchar "\000\001"
+ : cast_uchar "\000\000"; /* dirty */
item->func = data == -1 ? do_select_submenu : selected_item;
item->data = data == -1 ? nmenu : (void *)data;
item->in_m = data == -1 ? 1 : 0;
@@ -1920,22 +2271,28 @@ static void new_menu_item(unsigned char *name, long data, int fullname)
} else
free(name);
if (name && data == -1) {
- if ((unsigned)menu_stack_size > INT_MAX / sizeof(struct menu_item *) - 1)
+ if ((unsigned)menu_stack_size
+ > INT_MAX / sizeof(struct menu_item *) - 1)
overalloc();
- menu_stack = xrealloc(menu_stack, (menu_stack_size + 1) * sizeof(struct menu_item *));
+ menu_stack =
+ xrealloc(menu_stack, (menu_stack_size + 1)
+ * sizeof(struct menu_item *));
menu_stack[menu_stack_size++] = nmenu;
}
- if (!name) menu_stack_size--;
+ if (!name)
+ menu_stack_size--;
}
-static void init_menu(void)
+static void
+init_menu(void)
{
menu_stack_size = 0;
menu_stack = NULL;
new_menu_item(stracpy(cast_uchar ""), -1, 0);
}
-void free_menu(struct menu_item *m) /* Grrr. Recursion */
+void
+free_menu(struct menu_item *m) /* Grrr. Recursion */
{
struct menu_item *mm;
for (mm = m; mm->text; mm++) {
@@ -1946,24 +2303,28 @@ void free_menu(struct menu_item *m) /* Grrr. Recursion */
free(m);
}
-static struct menu_item *detach_menu(void)
+static struct menu_item *
+detach_menu(void)
{
struct menu_item *i = NULL;
if (menu_stack) {
- if (menu_stack_size) i = menu_stack[0];
+ if (menu_stack_size)
+ i = menu_stack[0];
free(menu_stack);
}
return i;
}
-static void destroy_menu(void)
+static void
+destroy_menu(void)
{
if (menu_stack)
free_menu(menu_stack[0]);
detach_menu();
}
-static void menu_labels(struct menu_item *m, unsigned char *base, unsigned char **lbls)
+static void
+menu_labels(struct menu_item *m, unsigned char *base, unsigned char **lbls)
{
unsigned char *bs;
for (; m->text; m++) {
@@ -1975,13 +2336,16 @@ static void menu_labels(struct menu_item *m, unsigned char *base, unsigned char
free(bs);
}
} else {
- if ((bs = stracpy(m->hotkey[1] ? (unsigned char *)"" : base))) add_to_strn(&bs, m->text);
+ if ((bs = stracpy(m->hotkey[1] ? (unsigned char *)""
+ : base)))
+ add_to_strn(&bs, m->text);
lbls[(int)(long)m->data] = bs;
}
}
}
-static int menu_contains(struct menu_item *m, int f)
+static int
+menu_contains(struct menu_item *m, int f)
{
if (m->func != do_select_submenu)
return (int)(long)m->data == f;
@@ -1991,21 +2355,27 @@ static int menu_contains(struct menu_item *m, int f)
return 0;
}
-void do_select_submenu(struct terminal *term, void *menu_, void *ses_)
+void
+do_select_submenu(struct terminal *term, void *menu_, void *ses_)
{
struct menu_item *menu = (struct menu_item *)menu_;
struct session *ses = (struct session *)ses_;
struct menu_item *m;
int def = get_current_state(ses);
int sel = 0;
- if (def < 0) def = 0;
- for (m = menu; m->text; m++, sel++) if (menu_contains(m, def)) goto f;
+ if (def < 0)
+ def = 0;
+ for (m = menu; m->text; m++, sel++)
+ if (menu_contains(m, def))
+ goto f;
sel = 0;
- f:
+f:
do_menu_selected(term, menu, ses, sel, NULL, NULL);
}
-static int do_html_select(unsigned char *attr, unsigned char *html, unsigned char *eof, unsigned char **end)
+static int
+do_html_select(unsigned char *attr, unsigned char *html, unsigned char *eof,
+ unsigned char **end)
{
struct form_control *fc;
unsigned char *t_name, *t_attr, *en;
@@ -2019,7 +2389,8 @@ static int do_html_select(unsigned char *attr, unsigned char *html, unsigned cha
unsigned char **val, **lbls;
int order, preselect, group;
int i, mw;
- if (has_attr(attr, cast_uchar "multiple") || dmp) return 1;
+ if (has_attr(attr, cast_uchar "multiple") || dmp)
+ return 1;
find_form_for_input(attr);
lbl = NULL;
lbl_l = 0;
@@ -2030,14 +2401,15 @@ static int do_html_select(unsigned char *attr, unsigned char *html, unsigned cha
group = 0;
preselect = -1;
init_menu();
- se:
+se:
en = html;
- see:
+see:
html = en;
- while (html < eof && *html != '<') html++;
+ while (html < eof && *html != '<')
+ html++;
if (html >= eof) {
int i;
- abort:
+abort:
*end = html;
free(lbl);
free(vlbl);
@@ -2055,7 +2427,8 @@ static int do_html_select(unsigned char *attr, unsigned char *html, unsigned cha
s++;
l--;
}
- while (l && WHITECHAR(s[l-1])) l--;
+ while (l && WHITECHAR(s[l - 1]))
+ l--;
q = convert_string(ct, s, l, d_opt);
if (q) {
add_to_str(&lbl, &lbl_l, q);
@@ -2073,7 +2446,8 @@ static int do_html_select(unsigned char *attr, unsigned char *html, unsigned cha
}
if (t_namelen == 7 && !casecmp(t_name, cast_uchar "/SELECT", 7)) {
if (lbl) {
- if (!val[order - 1]) val[order - 1] = stracpy(vlbl);
+ if (!val[order - 1])
+ val[order - 1] = stracpy(vlbl);
if (!nnmi) {
new_menu_item(lbl, order - 1, 1);
lbl = NULL;
@@ -2088,7 +2462,8 @@ static int do_html_select(unsigned char *attr, unsigned char *html, unsigned cha
}
if (t_namelen == 7 && !casecmp(t_name, cast_uchar "/OPTION", 7)) {
if (lbl) {
- if (!val[order - 1]) val[order - 1] = stracpy(vlbl);
+ if (!val[order - 1])
+ val[order - 1] = stracpy(vlbl);
if (!nnmi) {
new_menu_item(lbl, order - 1, 1);
lbl = NULL;
@@ -2104,7 +2479,8 @@ static int do_html_select(unsigned char *attr, unsigned char *html, unsigned cha
if (t_namelen == 6 && !casecmp(t_name, cast_uchar "OPTION", 6)) {
unsigned char *v, *vx;
if (lbl) {
- if (!val[order - 1]) val[order - 1] = stracpy(vlbl);
+ if (!val[order - 1])
+ val[order - 1] = stracpy(vlbl);
if (!nnmi) {
new_menu_item(lbl, order - 1, 1);
lbl = NULL;
@@ -2115,18 +2491,24 @@ static int do_html_select(unsigned char *attr, unsigned char *html, unsigned cha
free(vlbl);
vlbl = NULL;
}
- if (has_attr(t_attr, cast_uchar "disabled")) goto see;
- if (preselect == -1 && has_attr(t_attr, cast_uchar "selected")) preselect = order;
+ if (has_attr(t_attr, cast_uchar "disabled"))
+ goto see;
+ if (preselect == -1 && has_attr(t_attr, cast_uchar "selected"))
+ preselect = order;
v = get_exact_attr_val(t_attr, cast_uchar "value");
if (!(order & (ALLOC_GR - 1))) {
- if ((unsigned)order > INT_MAX / sizeof(unsigned char *) - ALLOC_GR)
+ if ((unsigned)order
+ > INT_MAX / sizeof(unsigned char *) - ALLOC_GR)
overalloc();
val = xrealloc(val, (order + ALLOC_GR)
- * sizeof(unsigned char *));
+ * sizeof(unsigned char *));
}
val[order++] = v;
if ((vx = get_attr_val(t_attr, cast_uchar "label"))) {
- new_menu_item(convert_string(ct, vx, (int)strlen(cast_const_char vx), d_opt), order - 1, 0);
+ new_menu_item(
+ convert_string(
+ ct, vx, (int)strlen(cast_const_char vx), d_opt),
+ order - 1, 0);
free(vx);
}
if (!v || !vx) {
@@ -2138,9 +2520,12 @@ static int do_html_select(unsigned char *attr, unsigned char *html, unsigned cha
}
goto see;
}
- if ((t_namelen == 8 && !casecmp(t_name, cast_uchar "OPTGROUP", 8)) || (t_namelen == 9 && !casecmp(t_name, cast_uchar "/OPTGROUP", 9))) {
+ if ((t_namelen == 8 && !casecmp(t_name, cast_uchar "OPTGROUP", 8))
+ || (t_namelen == 9
+ && !casecmp(t_name, cast_uchar "/OPTGROUP", 9))) {
if (lbl) {
- if (!val[order - 1]) val[order - 1] = stracpy(vlbl);
+ if (!val[order - 1])
+ val[order - 1] = stracpy(vlbl);
if (!nnmi) {
new_menu_item(lbl, order - 1, 1);
lbl = NULL;
@@ -2158,32 +2543,41 @@ static int do_html_select(unsigned char *attr, unsigned char *html, unsigned cha
}
if (t_namelen == 8 && !casecmp(t_name, cast_uchar "OPTGROUP", 8)) {
unsigned char *la;
- if (!(la = get_attr_val(t_attr, cast_uchar "label"))) la = stracpy(cast_uchar "");
- new_menu_item(convert_string(ct, la, (int)strlen(cast_const_char la), d_opt), -1, 0);
+ if (!(la = get_attr_val(t_attr, cast_uchar "label")))
+ la = stracpy(cast_uchar "");
+ new_menu_item(convert_string(ct, la,
+ (int)strlen(cast_const_char la),
+ d_opt),
+ -1, 0);
free(la);
group = 1;
}
goto see;
- end_parse:
+end_parse:
*end = en;
- if (!order) goto abort;
+ if (!order)
+ goto abort;
fc = mem_calloc(sizeof(struct form_control));
if ((unsigned)order > (unsigned)INT_MAX / sizeof(unsigned char *))
overalloc();
lbls = mem_calloc(order * sizeof(unsigned char *));
fc->form_num = last_form_tag ? (int)(last_form_tag - startf) : 0;
- fc->ctrl_num = last_form_tag ? (int)(attr - last_form_tag) : (int)(attr - startf);
+ fc->ctrl_num =
+ last_form_tag ? (int)(attr - last_form_tag) : (int)(attr - startf);
fc->position = (int)(attr - startf);
fc->method = form.method;
fc->action = stracpy(form.action);
- fc->form_name= stracpy(form.form_name);
- fc->onsubmit= stracpy(form.onsubmit);
+ fc->form_name = stracpy(form.form_name);
+ fc->onsubmit = stracpy(form.onsubmit);
fc->name = get_attr_val(attr, cast_uchar "name");
fc->type = FC_SELECT;
fc->default_state = preselect < 0 ? 0 : preselect;
- fc->default_value = order ? stracpy(val[fc->default_state]) : stracpy(cast_uchar "");
- fc->ro = has_attr(attr, cast_uchar "disabled") ? 2 : has_attr(attr, cast_uchar "readonly") ? 1 : 0;
+ fc->default_value =
+ order ? stracpy(val[fc->default_state]) : stracpy(cast_uchar "");
+ fc->ro = has_attr(attr, cast_uchar "disabled") ? 2
+ : has_attr(attr, cast_uchar "readonly") ? 1
+ : 0;
fc->nvalues = order;
fc->values = val;
fc->menu = detach_menu();
@@ -2198,8 +2592,11 @@ static int do_html_select(unsigned char *attr, unsigned char *html, unsigned cha
format_.attr |= AT_BOLD | AT_FIXED;
format_.fontsize = 3;
mw = 0;
- for (i = 0; i < order; i++) if (lbls[i] && strlen((char *)lbls[i]) > mw) mw = strlen((char *)lbls[i]);
- for (i = 0; i < mw; i++) put_chrs(cast_uchar "_", 1);
+ for (i = 0; i < order; i++)
+ if (lbls[i] && strlen((char *)lbls[i]) > mw)
+ mw = strlen((char *)lbls[i]);
+ for (i = 0; i < mw; i++)
+ put_chrs(cast_uchar "_", 1);
kill_html_stack_item(&html_top);
put_chrs(cast_uchar "]", 1);
kill_html_stack_item(&html_top);
@@ -2207,12 +2604,15 @@ static int do_html_select(unsigned char *attr, unsigned char *html, unsigned cha
return 0;
}
-static void html_textarea(unsigned char *a)
+static void
+html_textarea(unsigned char *a)
{
internal("This should be never called");
}
-static void do_html_textarea(unsigned char *attr, unsigned char *html, unsigned char *eof, unsigned char **end)
+static void
+do_html_textarea(unsigned char *attr, unsigned char *html, unsigned char *eof,
+ unsigned char **end)
{
struct form_control *fc;
unsigned char *p, *t_name, *w;
@@ -2220,34 +2620,44 @@ static void do_html_textarea(unsigned char *attr, unsigned char *html, unsigned
int cols, rows;
int i;
find_form_for_input(attr);
- while (html < eof && (*html == '\n' || *html == '\r')) html++;
+ while (html < eof && (*html == '\n' || *html == '\r'))
+ html++;
p = html;
while (p < eof && *p != '<') {
- pp:
+pp:
p++;
}
if (p >= eof) {
*end = eof;
return;
}
- if (parse_element(p, eof, &t_name, &t_namelen, NULL, end)) goto pp;
- if (t_namelen != 9 || casecmp(t_name, cast_uchar "/TEXTAREA", 9)) goto pp;
+ if (parse_element(p, eof, &t_name, &t_namelen, NULL, end))
+ goto pp;
+ if (t_namelen != 9 || casecmp(t_name, cast_uchar "/TEXTAREA", 9))
+ goto pp;
fc = mem_calloc(sizeof(struct form_control));
fc->form_num = last_form_tag ? (int)(last_form_tag - startf) : 0;
- fc->ctrl_num = last_form_tag ? (int)(attr - last_form_tag) : (int)(attr - startf);
+ fc->ctrl_num =
+ last_form_tag ? (int)(attr - last_form_tag) : (int)(attr - startf);
fc->position = (int)(attr - startf);
fc->method = form.method;
fc->action = stracpy(form.action);
fc->form_name = stracpy(form.form_name);
fc->onsubmit = stracpy(form.onsubmit);
fc->name = get_attr_val(attr, cast_uchar "name");
- fc->type = FC_TEXTAREA;;
- fc->ro = has_attr(attr, cast_uchar "disabled") ? 2 : has_attr(attr, cast_uchar "readonly") ? 1 : 0;
+ fc->type = FC_TEXTAREA;
+ ;
+ fc->ro = has_attr(attr, cast_uchar "disabled") ? 2
+ : has_attr(attr, cast_uchar "readonly") ? 1
+ : 0;
fc->default_value = memacpy(html, p - html);
- if ((cols = get_num(attr, cast_uchar "cols")) < HTML_MINIMAL_TEXTAREA_WIDTH) cols = HTML_DEFAULT_TEXTAREA_WIDTH;
+ if ((cols = get_num(attr, cast_uchar "cols"))
+ < HTML_MINIMAL_TEXTAREA_WIDTH)
+ cols = HTML_DEFAULT_TEXTAREA_WIDTH;
cols++;
set_max_textarea_width(&cols);
- if ((rows = get_num(attr, cast_uchar "rows")) <= 0) rows = HTML_DEFAULT_TEXTAREA_HEIGHT;
+ if ((rows = get_num(attr, cast_uchar "rows")) <= 0)
+ rows = HTML_DEFAULT_TEXTAREA_HEIGHT;
if (rows > d_opt->yw) {
rows = d_opt->yw;
if (rows <= 0)
@@ -2257,47 +2667,68 @@ static void do_html_textarea(unsigned char *attr, unsigned char *html, unsigned
fc->rows = rows;
fc->wrap = 1;
if ((w = get_attr_val(attr, cast_uchar "wrap"))) {
- if (!casestrcmp(w, cast_uchar "hard") || !casestrcmp(w, cast_uchar "physical")) fc->wrap = 2;
- else if (!casestrcmp(w, cast_uchar "off")) fc->wrap = 0;
+ if (!casestrcmp(w, cast_uchar "hard")
+ || !casestrcmp(w, cast_uchar "physical"))
+ fc->wrap = 2;
+ else if (!casestrcmp(w, cast_uchar "off"))
+ fc->wrap = 0;
free(w);
}
- if ((fc->maxlength = get_num(attr, cast_uchar "maxlength")) == -1) fc->maxlength = INT_MAX / 4;
- if (rows > 1) ln_break(1);
- else put_chrs(cast_uchar " ", 1);
+ if ((fc->maxlength = get_num(attr, cast_uchar "maxlength")) == -1)
+ fc->maxlength = INT_MAX / 4;
+ if (rows > 1)
+ ln_break(1);
+ else
+ put_chrs(cast_uchar " ", 1);
html_stack_dup();
format_.form = fc;
format_.attr = AT_BOLD | AT_FIXED;
format_.fontsize = 3;
for (i = 0; i < rows; i++) {
int j;
- for (j = 0; j < cols; j++) put_chrs(cast_uchar "_", 1);
- if (i < rows - 1) ln_break(1);
+ for (j = 0; j < cols; j++)
+ put_chrs(cast_uchar "_", 1);
+ if (i < rows - 1)
+ ln_break(1);
}
kill_html_stack_item(&html_top);
- if (rows > 1) ln_break(1);
- else put_chrs(cast_uchar " ", 1);
+ if (rows > 1)
+ ln_break(1);
+ else
+ put_chrs(cast_uchar " ", 1);
special_f(ff, SP_CONTROL, fc);
}
-static void html_iframe(unsigned char *a)
+static void
+html_iframe(unsigned char *a)
{
unsigned char *name, *url;
- if (!(url = get_url_val(a, cast_uchar "src"))) return;
- if (!*url) goto free_url_ret;
- if (!(name = get_attr_val(a, cast_uchar "name"))) name = stracpy(cast_uchar "");
- if (*name) put_link_line(cast_uchar "IFrame: ", name, url, d_opt->framename);
- else put_link_line(cast_uchar "", cast_uchar "IFrame", url, d_opt->framename);
+ if (!(url = get_url_val(a, cast_uchar "src")))
+ return;
+ if (!*url)
+ goto free_url_ret;
+ if (!(name = get_attr_val(a, cast_uchar "name")))
+ name = stracpy(cast_uchar "");
+ if (*name)
+ put_link_line(cast_uchar "IFrame: ", name, url,
+ d_opt->framename);
+ else
+ put_link_line(cast_uchar "", cast_uchar "IFrame", url,
+ d_opt->framename);
free(name);
- free_url_ret:
+free_url_ret:
free(url);
}
-static void html_noframes(unsigned char *a)
+static void
+html_noframes(unsigned char *a)
{
- if (d_opt->frames) html_skip(a);
+ if (d_opt->frames)
+ html_skip(a);
}
-static void html_frame(unsigned char *a)
+static void
+html_frame(unsigned char *a)
{
unsigned char *name, *u2, *url;
if (!(u2 = get_url_val(a, cast_uchar "src"))) {
@@ -2316,7 +2747,8 @@ static void html_frame(unsigned char *a)
if (!name)
name = stracpy(cast_uchar "Frame");
}
- if (!d_opt->frames || !html_top.frameset) put_link_line(cast_uchar "Frame: ", name, url, cast_uchar "");
+ if (!d_opt->frames || !html_top.frameset)
+ put_link_line(cast_uchar "Frame: ", name, url, cast_uchar "");
else {
struct frame_param fp;
unsigned char *scroll = get_attr_val(a, cast_uchar "scrolling");
@@ -2333,13 +2765,15 @@ static void html_frame(unsigned char *a)
fp.scrolling = SCROLLING_YES;
free(scroll);
}
- if (special_f(ff, SP_USED, NULL)) special_f(ff, SP_FRAME, &fp);
+ if (special_f(ff, SP_USED, NULL))
+ special_f(ff, SP_FRAME, &fp);
}
free(name);
free(url);
}
-static void parse_frame_widths(unsigned char *a, int ww, int www, int **op, int *olp)
+static void
+parse_frame_widths(unsigned char *a, int ww, int www, int **op, int *olp)
{
unsigned char *aa;
char *end;
@@ -2349,15 +2783,20 @@ static void parse_frame_widths(unsigned char *a, int ww, int www, int **op, int
int ol;
ol = 0;
o = NULL;
- new_ch:
- while (WHITECHAR(*a)) a++;
+new_ch:
+ while (WHITECHAR(*a))
+ a++;
n = strtoul(cast_const_char a, &end, 10);
a = cast_uchar end;
- if (n > 10000) n = 10000;
+ if (n > 10000)
+ n = 10000;
q = (int)n;
- if (*a == '%') q = q * ww / 100;
- else if (*a != '*') q = (q + (www - 1) / 2) / (www ? www : 1);
- else if (!(q = -q)) q = -1;
+ if (*a == '%')
+ q = q * ww / 100;
+ else if (*a != '*')
+ q = (q + (www - 1) / 2) / (www ? www : 1);
+ else if (!(q = -q))
+ q = -1;
if ((unsigned)ol > INT_MAX / sizeof(int) - 1)
overalloc();
o = xrealloc(o, (ol + 1) * sizeof(int));
@@ -2369,13 +2808,18 @@ static void parse_frame_widths(unsigned char *a, int ww, int www, int **op, int
*op = o;
*olp = ol;
q = 2 * ol - 1;
- for (i = 0; i < ol; i++) if (o[i] > 0) q += o[i] - 1;
+ for (i = 0; i < ol; i++)
+ if (o[i] > 0)
+ q += o[i] - 1;
if (q >= ww) {
- distribute:
- for (i = 0; i < ol; i++) if (o[i] < 1) o[i] = 1;
+distribute:
+ for (i = 0; i < ol; i++)
+ if (o[i] < 1)
+ o[i] = 1;
q -= ww;
d = 0;
- for (i = 0; i < ol; i++) d += o[i];
+ for (i = 0; i < ol; i++)
+ d += o[i];
qq = q;
for (i = 0; i < ol; i++) {
q -= o[i] - o[i] * (d - qq) / (d ? d : 1);
@@ -2394,69 +2838,87 @@ static void parse_frame_widths(unsigned char *a, int ww, int www, int **op, int
q--;
nn = 1;
}
- if (!q) break;
+ if (!q)
+ break;
}
- if (!nn) break;
+ if (!nn)
+ break;
}
} else {
int nn = 0;
- for (i = 0; i < ol; i++) if (o[i] < 0) nn = 1;
- if (!nn) goto distribute;
+ for (i = 0; i < ol; i++)
+ if (o[i] < 0)
+ nn = 1;
+ if (!nn)
+ goto distribute;
if ((unsigned)ol > INT_MAX / sizeof(int))
overalloc();
oo = xmalloc(ol * sizeof(int));
memcpy(oo, o, ol * sizeof(int));
- for (i = 0; i < ol; i++) if (o[i] < 1) o[i] = 1;
+ for (i = 0; i < ol; i++)
+ if (o[i] < 1)
+ o[i] = 1;
q = ww - q;
d = 0;
- for (i = 0; i < ol; i++) if (oo[i] < 0) d += -oo[i];
+ for (i = 0; i < ol; i++)
+ if (oo[i] < 0)
+ d += -oo[i];
qq = q;
- for (i = 0; i < ol; i++) if (oo[i] < 0) {
- o[i] += (-oo[i] * qq / (d ? d : 1));
- q -= (-oo[i] * qq / (d ? d : 1));
- }
+ for (i = 0; i < ol; i++)
+ if (oo[i] < 0) {
+ o[i] += (-oo[i] * qq / (d ? d : 1));
+ q -= (-oo[i] * qq / (d ? d : 1));
+ }
if (q < 0) {
q = 0;
- /*internal("parse_frame_widths: q < 0"); may happen when page contains too big values */
+ /*internal("parse_frame_widths: q < 0"); may happen when
+ * page contains too big values */
}
- for (i = 0; i < ol; i++) if (oo[i] < 0) {
- if (q) {
- o[i]++;
- q--;
+ for (i = 0; i < ol; i++)
+ if (oo[i] < 0) {
+ if (q) {
+ o[i]++;
+ q--;
+ }
}
- }
free(oo);
}
- for (i = 0; i < ol; i++) if (!o[i]) {
- int j;
- int m = 0;
- int mj = 0;
- for (j = 0; j < ol; j++)
- if (o[j] > m) {
- m = o[j];
- mj = j;
+ for (i = 0; i < ol; i++)
+ if (!o[i]) {
+ int j;
+ int m = 0;
+ int mj = 0;
+ for (j = 0; j < ol; j++)
+ if (o[j] > m) {
+ m = o[j];
+ mj = j;
+ }
+ if (m) {
+ o[i] = 1;
+ o[mj]--;
}
- if (m) {
- o[i] = 1;
- o[mj]--;
}
- }
}
-static void html_frameset(unsigned char *a)
+static void
+html_frameset(unsigned char *a)
{
- int x = 0, y = 0; /* against warning */
+ int x = 0, y = 0; /* against warning */
struct frameset_param fp;
unsigned char *c, *d;
- if (!d_opt->frames || !special_f(ff, SP_USED, NULL)) return;
- if (!(c = get_attr_val(a, cast_uchar "cols"))) c = stracpy(cast_uchar "100%");
- if (!(d = get_attr_val(a, cast_uchar "rows"))) d = stracpy(cast_uchar "100%");
+ if (!d_opt->frames || !special_f(ff, SP_USED, NULL))
+ return;
+ if (!(c = get_attr_val(a, cast_uchar "cols")))
+ c = stracpy(cast_uchar "100%");
+ if (!(d = get_attr_val(a, cast_uchar "rows")))
+ d = stracpy(cast_uchar "100%");
if (!html_top.frameset) {
x = d_opt->xw;
y = d_opt->yw;
} else {
struct frameset_desc *f = html_top.frameset;
- if (f->yp >= f->y) goto free_cd;
+ if (f->yp >= f->y)
+ goto free_cd;
x = f->f[f->xp + f->yp * f->x].xw;
y = f->f[f->xp + f->yp * f->x].yw;
}
@@ -2468,12 +2930,13 @@ static void html_frameset(unsigned char *a)
}
free(fp.xw);
free(fp.yw);
- free_cd:
+free_cd:
free(c);
free(d);
}
-static void html_meta(unsigned char *a)
+static void
+html_meta(unsigned char *a)
{
unsigned char *prop;
if ((prop = get_attr_val(a, cast_uchar "property"))) {
@@ -2481,12 +2944,14 @@ static void html_meta(unsigned char *a)
unsigned char *host = get_host_name(format_.href_base);
if (host) {
if (strstr(cast_const_char host, "facebook.")
- || strstr(cast_const_char host, "flickr.")
- || strstr(cast_const_char host, "imgur.")
- || strstr(cast_const_char host, "instagram.")
- || strstr(cast_const_char host, "mastadon.")
- || strstr(cast_const_char host, "pinterest.")
- || strstr(cast_const_char host, "twitter."))
+ || strstr(cast_const_char host, "flickr.")
+ || strstr(cast_const_char host, "imgur.")
+ || strstr(cast_const_char host,
+ "instagram.")
+ || strstr(cast_const_char host, "mastadon.")
+ || strstr(cast_const_char host,
+ "pinterest.")
+ || strstr(cast_const_char host, "twitter."))
html_img(a);
free(host);
}
@@ -2495,7 +2960,8 @@ static void html_meta(unsigned char *a)
}
}
-static void html_link(unsigned char *a)
+static void
+html_link(unsigned char *a)
{
unsigned char *name, *url, *title;
if ((name = get_attr_val(a, cast_uchar "type"))) {
@@ -2505,7 +2971,8 @@ static void html_link(unsigned char *a)
}
free(name);
}
- if (!(url = get_url_val(a, cast_uchar "href"))) return;
+ if (!(url = get_url_val(a, cast_uchar "href")))
+ return;
if (!(name = get_attr_val(a, cast_uchar "rel")))
if (!(name = get_attr_val(a, cast_uchar "rev")))
name = get_attr_val(a, cast_uchar "ref");
@@ -2526,28 +2993,29 @@ static void html_link(unsigned char *a)
name = stracpy(cast_uchar "Link");
}
}
- if (
- !casecmp(name, cast_uchar "schema", 6) ||
- !casecmp(name, cast_uchar "mw-", 3) ||
- !casestrcmp(name, cast_uchar "Edit-Time-Data") ||
- !casestrcmp(name, cast_uchar "File-List") ||
- !casestrcmp(name, cast_uchar "alternate stylesheet") ||
- !casestrcmp(name, cast_uchar "generator-home") ||
- !casestrcmp(name, cast_uchar "https://api.w.org/") ||
- !casestrcmp(name, cast_uchar "https://github.com/WP-API/WP-API") ||
- !casestrcmp(name, cast_uchar "made") ||
- !casestrcmp(name, cast_uchar "manifest") ||
- !casestrcmp(name, cast_uchar "meta") ||
- !casestrcmp(name, cast_uchar "pingback") ||
- !casestrcmp(name, cast_uchar "preconnect") ||
- !casestrcmp(name, cast_uchar "stylesheet") ||
- casestrstr(name, cast_uchar "icon") ||
- 0) goto skip;
- if (!casestrcmp(name, cast_uchar "prefetch") ||
- !casestrcmp(name, cast_uchar "prerender") ||
- !casestrcmp(name, cast_uchar "preload")) {
+ if (!casecmp(name, cast_uchar "schema", 6)
+ || !casecmp(name, cast_uchar "mw-", 3)
+ || !casestrcmp(name, cast_uchar "Edit-Time-Data")
+ || !casestrcmp(name, cast_uchar "File-List")
+ || !casestrcmp(name, cast_uchar "alternate stylesheet")
+ || !casestrcmp(name, cast_uchar "generator-home")
+ || !casestrcmp(name, cast_uchar "https://api.w.org/")
+ || !casestrcmp(name, cast_uchar "https://github.com/WP-API/WP-API")
+ || !casestrcmp(name, cast_uchar "made")
+ || !casestrcmp(name, cast_uchar "manifest")
+ || !casestrcmp(name, cast_uchar "meta")
+ || !casestrcmp(name, cast_uchar "pingback")
+ || !casestrcmp(name, cast_uchar "preconnect")
+ || !casestrcmp(name, cast_uchar "stylesheet")
+ || casestrstr(name, cast_uchar "icon") || 0)
+ goto skip;
+ if (!casestrcmp(name, cast_uchar "prefetch")
+ || !casestrcmp(name, cast_uchar "prerender")
+ || !casestrcmp(name, cast_uchar "preload")) {
unsigned char *pre_url = join_urls(format_.href_base, url);
- if (!dmp) load_url(pre_url, format_.href_base, NULL, PRI_PRELOAD, NC_ALWAYS_CACHE, 0, 0, 0);
+ if (!dmp)
+ load_url(pre_url, format_.href_base, NULL, PRI_PRELOAD,
+ NC_ALWAYS_CACHE, 0, 0, 0);
free(pre_url);
goto skip;
}
@@ -2566,12 +3034,13 @@ static void html_link(unsigned char *a)
goto skip;
}
if ((title = get_attr_val(a, cast_uchar "title"))) {
- if (*name) add_to_strn(&name, cast_uchar ": ");
+ if (*name)
+ add_to_strn(&name, cast_uchar ": ");
add_to_strn(&name, title);
free(title);
}
put_link_line(cast_uchar "Link: ", name, url, format_.target_base);
- skip:
+skip:
free(name);
free(url);
}
@@ -2584,101 +3053,108 @@ struct element_info {
};
static struct element_info elements[] = {
- {"SPAN", html_span, 0, 0},
- {"B", html_bold, 0, 0},
- {"STRONG", html_bold, 0, 0},
- {"DFN", html_bold, 0, 0},
- {"I", html_italic, 0, 0},
- {"Q", html_italic, 0, 0},
- {"CITE", html_italic, 0, 0},
- {"EM", html_italic, 0, 0},
- {"ABBR", html_italic, 0, 0},
- {"U", html_underline, 0, 0},
- {"S", html_underline, 0, 0},
- {"STRIKE", html_underline, 0, 0},
- {"FIXED", html_fixed, 0, 0},
- {"CODE", html_fixed, 0, 0},
- {"TT", html_fixed, 0, 0},
- {"SAMP", html_fixed, 0, 0},
- {"SUB", html_sub, 0, 0},
- {"SUP", html_sup, 0, 0},
- {"FONT", html_font, 0, 0},
- {"INVERT", html_invert, 0, 0},
- {"A", html_a, 0, 2},
- {"IMG", html_img, 0, 1},
- {"IMAGE", html_img, 0, 1},
- {"OBJECT", html_object, 0, 0},
- {"EMBED", html_embed, 0, 1},
-
- {"BASE", html_base, 0, 1},
- {"BASEFONT", html_font, 0, 1},
-
- {"BODY", html_body, 0, 0},
-
-/* {"HEAD", html_skip, 0, 0},*/
- {"TITLE", html_title, 0, 0},
- {"SCRIPT", html_script, 0, 0},
- {"STYLE", html_style, 0, 0},
- {"NOEMBED", html_skip, 0, 0},
-
- {"BR", html_br, 1, 1},
- {"DIV", html_div, 1, 0},
- {"CENTER", html_center, 1, 0},
- {"CAPTION", html_center, 1, 0},
- {"P", html_p, 2, 2},
- {"HR", html_hr, 2, 1},
- {"H1", html_h1, 2, 2},
- {"H2", html_h2, 2, 2},
- {"H3", html_h3, 2, 2},
- {"H4", html_h4, 2, 2},
- {"H5", html_h5, 2, 2},
- {"H6", html_h6, 2, 2},
- {"BLOCKQUOTE", html_blockquote,2, 0},
- {"ADDRESS", html_address, 2, 0},
- {"PRE", html_pre, 2, 0},
- {"LISTING", html_pre, 2, 0},
-
- {"UL", html_ul, 1, 0},
- {"DIR", html_ul, 1, 0},
- {"MENU", html_ul, 1, 0},
- {"OL", html_ol, 1, 0},
- {"LI", html_li, 1, 3},
- {"DL", html_dl, 1, 0},
- {"DT", html_dt, 1, 1},
- {"DD", html_dd, 1, 1},
-
- {"TABLE", html_table, 2, 0},
- {"TR", html_tr, 1, 0},
- {"TD", html_td, 0, 0},
- {"TH", html_th, 0, 0},
-
- {"FORM", html_form, 1, 0},
- {"INPUT", html_input, 0, 1},
- {"TEXTAREA", html_textarea, 0, 1},
- {"SELECT", html_select, 0, 0},
- {"OPTION", html_option, 1, 1},
- {"BUTTON", html_button, 0, 0},
-
- {"META", html_meta, 0, 1},
- {"LINK", html_link, 0, 1},
- {"IFRAME", html_iframe, 1, 1},
- {"FRAME", html_frame, 1, 1},
- {"FRAMESET", html_frameset, 1, 0},
- {"NOFRAMES", html_noframes, 0, 0},
+ {"SPAN", html_span, 0, 0},
+ { "B", html_bold, 0, 0},
+ { "STRONG", html_bold, 0, 0},
+ { "DFN", html_bold, 0, 0},
+ { "I", html_italic, 0, 0},
+ { "Q", html_italic, 0, 0},
+ { "CITE", html_italic, 0, 0},
+ { "EM", html_italic, 0, 0},
+ { "ABBR", html_italic, 0, 0},
+ { "U", html_underline, 0, 0},
+ { "S", html_underline, 0, 0},
+ { "STRIKE", html_underline, 0, 0},
+ { "FIXED", html_fixed, 0, 0},
+ { "CODE", html_fixed, 0, 0},
+ { "TT", html_fixed, 0, 0},
+ { "SAMP", html_fixed, 0, 0},
+ { "SUB", html_sub, 0, 0},
+ { "SUP", html_sup, 0, 0},
+ { "FONT", html_font, 0, 0},
+ { "INVERT", html_invert, 0, 0},
+ { "A", html_a, 0, 2},
+ { "IMG", html_img, 0, 1},
+ { "IMAGE", html_img, 0, 1},
+ { "OBJECT", html_object, 0, 0},
+ { "EMBED", html_embed, 0, 1},
+
+ { "BASE", html_base, 0, 1},
+ { "BASEFONT", html_font, 0, 1},
+
+ { "BODY", html_body, 0, 0},
+
+ /* {"HEAD", html_skip, 0, 0},*/
+ { "TITLE", html_title, 0, 0},
+ { "SCRIPT", html_script, 0, 0},
+ { "STYLE", html_style, 0, 0},
+ { "NOEMBED", html_skip, 0, 0},
+
+ { "BR", html_br, 1, 1},
+ { "DIV", html_div, 1, 0},
+ { "CENTER", html_center, 1, 0},
+ { "CAPTION", html_center, 1, 0},
+ { "P", html_p, 2, 2},
+ { "HR", html_hr, 2, 1},
+ { "H1", html_h1, 2, 2},
+ { "H2", html_h2, 2, 2},
+ { "H3", html_h3, 2, 2},
+ { "H4", html_h4, 2, 2},
+ { "H5", html_h5, 2, 2},
+ { "H6", html_h6, 2, 2},
+ { "BLOCKQUOTE", html_blockquote, 2, 0},
+ { "ADDRESS", html_address, 2, 0},
+ { "PRE", html_pre, 2, 0},
+ { "LISTING", html_pre, 2, 0},
+
+ { "UL", html_ul, 1, 0},
+ { "DIR", html_ul, 1, 0},
+ { "MENU", html_ul, 1, 0},
+ { "OL", html_ol, 1, 0},
+ { "LI", html_li, 1, 3},
+ { "DL", html_dl, 1, 0},
+ { "DT", html_dt, 1, 1},
+ { "DD", html_dd, 1, 1},
+
+ { "TABLE", html_table, 2, 0},
+ { "TR", html_tr, 1, 0},
+ { "TD", html_td, 0, 0},
+ { "TH", html_th, 0, 0},
+
+ { "FORM", html_form, 1, 0},
+ { "INPUT", html_input, 0, 1},
+ { "TEXTAREA", html_textarea, 0, 1},
+ { "SELECT", html_select, 0, 0},
+ { "OPTION", html_option, 1, 1},
+ { "BUTTON", html_button, 0, 0},
+
+ { "META", html_meta, 0, 1},
+ { "LINK", html_link, 0, 1},
+ { "IFRAME", html_iframe, 1, 1},
+ { "FRAME", html_frame, 1, 1},
+ { "FRAMESET", html_frameset, 1, 0},
+ { "NOFRAMES", html_noframes, 0, 0},
};
-unsigned char *skip_comment(unsigned char *html, unsigned char *eof)
+unsigned char *
+skip_comment(unsigned char *html, unsigned char *eof)
{
int comm = eof - html >= 4 && html[2] == '-' && html[3] == '-';
html += comm ? 4 : 2;
while (html < eof) {
- if (!comm && html[0] == '>') return html + 1;
- if (comm && eof - html >= 2 && html[0] == '-' && html[1] == '-') {
+ if (!comm && html[0] == '>')
+ return html + 1;
+ if (comm && eof - html >= 2 && html[0] == '-'
+ && html[1] == '-') {
html += 2;
- while (html < eof && (*html == '-' || *html == '!')) html++;
- while (html < eof && WHITECHAR(*html)) html++;
- if (html >= eof) return eof;
- if (*html == '>') return html + 1;
+ while (html < eof && (*html == '-' || *html == '!'))
+ html++;
+ while (html < eof && WHITECHAR(*html))
+ html++;
+ if (html >= eof)
+ return eof;
+ if (*html == '>')
+ return html + 1;
continue;
}
html++;
@@ -2686,21 +3162,27 @@ unsigned char *skip_comment(unsigned char *html, unsigned char *eof)
return eof;
}
-static void process_head(unsigned char *head)
+static void
+process_head(unsigned char *head)
{
unsigned char *r, *p;
struct refresh_param rp;
if ((r = parse_http_header(head, cast_uchar "Refresh", NULL))) {
if (!d_opt->auto_refresh) {
- if ((p = parse_header_param(r, cast_uchar "URL", 0)) || (p = parse_header_param(r, cast_uchar "", 0))) {
- put_link_line(cast_uchar "Refresh: ", p, p, d_opt->framename);
+ if ((p = parse_header_param(r, cast_uchar "URL", 0))
+ || (p = parse_header_param(r, cast_uchar "", 0))) {
+ put_link_line(cast_uchar "Refresh: ", p, p,
+ d_opt->framename);
free(p);
}
} else {
rp.url = parse_header_param(r, cast_uchar "URL", 0);
- if (!rp.url) rp.url = parse_header_param(r, cast_uchar "", 0);
+ if (!rp.url)
+ rp.url =
+ parse_header_param(r, cast_uchar "", 0);
rp.time = atoi(cast_const_char r);
- if (rp.time < 1) rp.time = 1;
+ if (rp.time < 1)
+ rp.time = 1;
special_f(ff, SP_REFRESH, &rp);
free(rp.url);
}
@@ -2708,7 +3190,8 @@ static void process_head(unsigned char *head)
}
}
-static int qd(unsigned char *html, unsigned char *eof, int *len)
+static int
+qd(unsigned char *html, unsigned char *eof, int *len)
{
int l;
*len = 1;
@@ -2716,25 +3199,33 @@ static int qd(unsigned char *html, unsigned char *eof, int *len)
internal("qd: out of data, html == %p, eof == %p", html, eof);
return -1;
}
- if (html[0] != '&' || d_opt->plain & 1) return html[0];
+ if (html[0] != '&' || d_opt->plain & 1)
+ return html[0];
if (eof - html >= 5 && !memcmp(html + 1, "Tab;", 4)) {
*len = 5;
return 9;
}
- if (eof - html <= 1) return -1;
- if (html[1] != '#') return -1;
- for (l = 2; l < 10 && eof - html > l; l++) if (html[l] == ';') {
- int n = get_entity_number(html + 2, l - 2);
- if (n >= 0) {
- *len = l + 1;
- return n;
+ if (eof - html <= 1)
+ return -1;
+ if (html[1] != '#')
+ return -1;
+ for (l = 2; l < 10 && eof - html > l; l++)
+ if (html[l] == ';') {
+ int n = get_entity_number(html + 2, l - 2);
+ if (n >= 0) {
+ *len = l + 1;
+ return n;
+ }
+ break;
}
- break;
- }
return -1;
}
-void parse_html(unsigned char *html, unsigned char *eof, void (*put_chars)(void *, unsigned char *, int), void (*line_break)(void *), void *(*special)(void *, int, ...), void *f, unsigned char *head)
+void
+parse_html(unsigned char *html, unsigned char *eof,
+ void (*put_chars)(void *, unsigned char *, int),
+ void (*line_break)(void *), void *(*special)(void *, int, ...),
+ void *f, unsigned char *head)
{
unsigned char *lt;
@@ -2744,20 +3235,21 @@ void parse_html(unsigned char *html, unsigned char *eof, void (*put_chars)(void
pos = 0;
was_br = 0;
-#define set_globals \
-do { \
- put_chars_f = put_chars; \
- line_break_f = line_break; \
- special_f = special; \
- ff = f; \
- eoff = eof; \
-} while (0)
+#define set_globals \
+ do { \
+ put_chars_f = put_chars; \
+ line_break_f = line_break; \
+ special_f = special; \
+ ff = f; \
+ eoff = eof; \
+ } while (0)
set_globals;
- if (head) process_head(head);
+ if (head)
+ process_head(head);
- set_lt:
+set_lt:
/*set_globals;*/
@@ -2768,42 +3260,54 @@ do { \
int namelen;
struct element_info *ei;
int inv;
- if (par_format.align != AL_NO && par_format.align != AL_NO_BREAKABLE && WHITECHAR(*html)) {
+ if (par_format.align != AL_NO
+ && par_format.align != AL_NO_BREAKABLE
+ && WHITECHAR(*html)) {
unsigned char *h = html;
/*if (putsp == -1) {
- while (html < eof && WHITECHAR(*html)) html++;
- goto set_lt;
+ while (html < eof && WHITECHAR(*html)) html++;
+ goto set_lt;
}
putsp = 0;*/
- while (h < eof && WHITECHAR(*h)) h++;
+ while (h < eof && WHITECHAR(*h))
+ h++;
if (eof - h > 1 && h[0] == '<' && h[1] == '/') {
- if (!parse_element(h, eof, &name, &namelen, &attr, &end)) {
+ if (!parse_element(h, eof, &name, &namelen,
+ &attr, &end)) {
put_chrs(lt, (int)(html - lt));
lt = html = h;
- if (!html_top.invisible) putsp = 1;
+ if (!html_top.invisible)
+ putsp = 1;
goto element;
}
}
html++;
- if (!(pos + (html-lt-1))) goto skip_w; /* ??? */
+ if (!(pos + (html - lt - 1)))
+ goto skip_w; /* ??? */
if (*(html - 1) == ' ') {
- if (html < eof && !WHITECHAR(*html)) continue; /* BIG performance win; not sure if it doesn't cause any bug */
+ if (html < eof && !WHITECHAR(*html))
+ continue; /* BIG performance win; not
+ sure if it doesn't cause
+ any bug */
put_chrs(lt, (int)(html - lt));
} else {
put_chrs(lt, (int)(html - 1 - lt));
put_chrs(cast_uchar " ", 1);
}
- skip_w:
- while (html < eof && WHITECHAR(*html)) html++;
+skip_w:
+ while (html < eof && WHITECHAR(*html))
+ html++;
/*putsp = -1;*/
goto set_lt;
}
if (0) {
- put_sp:
+put_sp:
put_chrs(cast_uchar " ", 1);
/*putsp = -1;*/
}
- if ((par_format.align == AL_NO || par_format.align == AL_NO_BREAKABLE) && (*html < 32 || *html == '&')) {
+ if ((par_format.align == AL_NO
+ || par_format.align == AL_NO_BREAKABLE)
+ && (*html < 32 || *html == '&')) {
int l;
int q = qd(html, eof, &l);
putsp = 0;
@@ -2814,11 +3318,14 @@ do { \
goto set_lt;
} else if (q == 13 || q == 10) {
put_chrs(lt, (int)(html - lt));
- next_break:
+next_break:
html += l;
- if (q == 13 && eof - html > 1 && qd(html, eof, &l) == 10) html += l;
+ if (q == 13 && eof - html > 1
+ && qd(html, eof, &l) == 10)
+ html += l;
ln_break(1);
- if (html >= eof) goto set_lt;
+ if (html >= eof)
+ goto set_lt;
q = qd(html, eof, &l);
if (q == 13 || q == 10) {
line_breax = 0;
@@ -2831,88 +3338,133 @@ do { \
int xl;
put_chrs(lt, (int)(html - lt));
xl = 1;
- while (xl < 240 && eof - html > xl + 1 && html[xl + 1] < ' ' && html[xl + 1] != 9 && html[xl + 1] != 10 && html[xl + 1] != 13) xl++;
- put_chrs(cast_uchar "................................................................................................................................................................................................................................................", xl);
+ while (xl < 240 && eof - html > xl + 1
+ && html[xl + 1] < ' ' && html[xl + 1] != 9
+ && html[xl + 1] != 10 && html[xl + 1] != 13)
+ xl++;
+ put_chrs(
+ cast_uchar
+ ".................................................."
+ ".................................................."
+ ".................................................."
+ ".................................................."
+ "........................................",
+ xl);
html += xl;
goto set_lt;
}
- if (eof - html >= 2 && html[0] == '<' && (html[1] == '!' || html[1] == '?') && !(d_opt->plain & 1) && html_top.invisible != INVISIBLE_STYLE) {
+ if (eof - html >= 2 && html[0] == '<'
+ && (html[1] == '!' || html[1] == '?') && !(d_opt->plain & 1)
+ && html_top.invisible != INVISIBLE_STYLE) {
/*if (putsp == 1) goto put_sp;
putsp = 0;*/
put_chrs(lt, (int)(html - lt));
html = skip_comment(html, eof);
goto set_lt;
}
- if (*html != '<' || d_opt->plain & 1 || parse_element(html, eof, &name, &namelen, &attr, &end)) {
+ if (*html != '<' || d_opt->plain & 1
+ || parse_element(html, eof, &name, &namelen, &attr, &end)) {
/*if (putsp == 1) goto put_sp;
putsp = 0;*/
html++;
continue;
}
- element:
+element:
html_format_changed = 1;
- inv = *name == '/'; name += inv; namelen -= inv;
- if (html_top.invisible == INVISIBLE_SCRIPT && !(inv && namelen == 6 && !casecmp(name, cast_uchar "SCRIPT", 6))) {
+ inv = *name == '/';
+ name += inv;
+ namelen -= inv;
+ if (html_top.invisible == INVISIBLE_SCRIPT
+ && !(inv && namelen == 6
+ && !casecmp(name, cast_uchar "SCRIPT", 6))) {
html++;
continue;
}
- if (html_top.invisible == INVISIBLE_STYLE && !(inv && namelen == 5 && !casecmp(name, cast_uchar "STYLE", 5))) {
+ if (html_top.invisible == INVISIBLE_STYLE
+ && !(inv && namelen == 5
+ && !casecmp(name, cast_uchar "STYLE", 5))) {
html++;
continue;
}
- if (!inv && putsp == 1 && !html_top.invisible) goto put_sp;
+ if (!inv && putsp == 1 && !html_top.invisible)
+ goto put_sp;
put_chrs(lt, (int)(html - lt));
- if (par_format.align != AL_NO && par_format.align != AL_NO_BREAKABLE) if (!inv && !putsp) {
- unsigned char *ee = end;
- unsigned char *nm;
- while (!parse_element(ee, eof, &nm, NULL, NULL, &ee))
- if (*nm == '/') goto ng;
- if (ee < eof && WHITECHAR(*ee)) {
- /*putsp = -1;*/
- put_chrs(cast_uchar " ", 1);
+ if (par_format.align != AL_NO
+ && par_format.align != AL_NO_BREAKABLE)
+ if (!inv && !putsp) {
+ unsigned char *ee = end;
+ unsigned char *nm;
+ while (!parse_element(ee, eof, &nm, NULL, NULL,
+ &ee))
+ if (*nm == '/')
+ goto ng;
+ if (ee < eof && WHITECHAR(*ee)) {
+ /*putsp = -1;*/
+ put_chrs(cast_uchar " ", 1);
+ }
+ng:;
}
- ng:;
- }
html = end;
for (ei = elements; ei != endof(elements); ei++) {
- if (strlen(cast_const_char ei->name) != (size_t)namelen || casecmp(cast_uchar ei->name, name, namelen))
+ if (strlen(cast_const_char ei->name) != (size_t)namelen
+ || casecmp(cast_uchar ei->name, name, namelen))
continue;
if (ei - elements > 4) {
struct element_info e = *ei;
- memmove(elements + 1, elements, (ei - elements) * sizeof(struct element_info));
+ memmove(elements + 1, elements,
+ (ei - elements)
+ * sizeof(struct element_info));
elements[0] = e;
ei = &elements[0];
}
if (!inv) {
int display_none = 0;
int noskip = 0;
- /* treat <br> literally in <pre> (fixes source code viewer on github) */
- if ((par_format.align == AL_NO || par_format.align == AL_NO_BREAKABLE) && !casestrcmp(cast_uchar ei->name, cast_uchar "BR"))
+ /* treat <br> literally in <pre> (fixes source
+ * code viewer on github) */
+ if ((par_format.align == AL_NO
+ || par_format.align == AL_NO_BREAKABLE)
+ && !casestrcmp(cast_uchar ei->name,
+ cast_uchar "BR"))
line_breax = 0;
ln_break(ei->linebreak);
if ((a = get_attr_val(attr, cast_uchar "id"))) {
special(f, SP_TAG, a);
free(a);
}
- if ((a = get_attr_val(attr, cast_uchar "style"))) {
+ if ((a = get_attr_val(attr,
+ cast_uchar "style"))) {
unsigned char *d, *s;
- if (!casestrcmp(cast_uchar ei->name, cast_uchar "INPUT")) {
- unsigned char *aa = get_attr_val(attr, cast_uchar "type");
+ if (!casestrcmp(cast_uchar ei->name,
+ cast_uchar "INPUT")) {
+ unsigned char *aa =
+ get_attr_val(attr,
+ cast_uchar
+ "type");
if (aa) {
- if (!casestrcmp(aa, cast_uchar "hidden"))
+ if (!casestrcmp(
+ aa, cast_uchar
+ "hidden"))
noskip = 1;
free(aa);
}
}
- for (d = s = a; *s; s++) if (*s > ' ') *d++ = *s;
+ for (d = s = a; *s; s++)
+ if (*s > ' ')
+ *d++ = *s;
*d = 0;
- display_none |= !casecmp(a, cast_uchar "display:none", 12) && !noskip;
+ display_none |=
+ !casecmp(a,
+ cast_uchar "display:none",
+ 12)
+ && !noskip;
free(a);
}
if (display_none) {
- if (ei->nopair == 1) goto set_lt;
+ if (ei->nopair == 1)
+ goto set_lt;
html_stack_dup();
html_top.name = name;
html_top.namelen = namelen;
@@ -2922,38 +3474,77 @@ do { \
goto set_lt;
}
if (!html_top.invisible) {
- int a = par_format.align == AL_NO || par_format.align == AL_NO_BREAKABLE;
+ int a = par_format.align == AL_NO
+ || par_format.align
+ == AL_NO_BREAKABLE;
struct par_attrib pa = par_format;
- if (ei->func == html_table && d_opt->tables && table_level < HTML_MAX_TABLE_LEVEL) {
- format_table(attr, html, eof, &html, f);
+ if (ei->func == html_table
+ && d_opt->tables
+ && table_level
+ < HTML_MAX_TABLE_LEVEL) {
+ format_table(attr, html, eof,
+ &html, f);
set_globals;
ln_break(2);
goto set_lt;
}
if (ei->func == html_select) {
- if (!do_html_select(attr, html, eof, &html))
+ if (!do_html_select(attr, html,
+ eof, &html))
goto set_lt;
}
if (ei->func == html_textarea) {
- do_html_textarea(attr, html, eof, &html);
+ do_html_textarea(attr, html,
+ eof, &html);
goto set_lt;
}
- if (ei->nopair == 2 || ei->nopair == 3) {
- struct html_element *e = NULL; /* against warning */
+ if (ei->nopair == 2
+ || ei->nopair == 3) {
+ struct html_element *e =
+ NULL; /* against warning */
struct list_head *le;
if (ei->nopair == 2) {
- foreach(struct html_element, e, le, html_stack) {
- if (e->dontkill) break;
- if (e->linebreak || !ei->linebreak) break;
+ foreach (
+ struct html_element,
+ e, le, html_stack) {
+ if (e->dontkill)
+ break;
+ if (e->linebreak
+ || !ei->linebreak)
+ break;
}
- } else foreach(struct html_element, e, le, html_stack) {
- if (e->linebreak && !ei->linebreak) break;
- if (e->dontkill) break;
- if (e->namelen == namelen && !casecmp(e->name, name, e->namelen)) break;
- }
- if (e->namelen == namelen && !casecmp(e->name, name, e->namelen)) {
- while (e->list_entry.prev != &html_stack) kill_html_stack_item(list_struct(e->list_entry.prev, struct html_element));
- if (e->dontkill != 2) kill_html_stack_item(e);
+ } else
+ foreach (
+ struct html_element,
+ e, le, html_stack) {
+ if (e->linebreak
+ && !ei->linebreak)
+ break;
+ if (e->dontkill)
+ break;
+ if (e->namelen
+ == namelen
+ && !casecmp(
+ e->name,
+ name,
+ e->namelen))
+ break;
+ }
+ if (e->namelen == namelen
+ && !casecmp(e->name, name,
+ e->namelen)) {
+ while (
+ e->list_entry.prev
+ != &html_stack)
+ kill_html_stack_item(
+ list_struct(
+ e->list_entry
+ .prev,
+ struct
+ html_element));
+ if (e->dontkill != 2)
+ kill_html_stack_item(
+ e);
}
}
if (ei->nopair != 1) {
@@ -2961,12 +3552,17 @@ do { \
html_top.name = name;
html_top.namelen = namelen;
html_top.options = attr;
- html_top.linebreak = ei->linebreak;
+ html_top.linebreak =
+ ei->linebreak;
}
- if (ei->func) ei->func(attr);
- if (ei->func == html_a) html_a_special(attr, html, eof);
- if (ei->func != html_br) was_br = 0;
- if (a) par_format = pa;
+ if (ei->func)
+ ei->func(attr);
+ if (ei->func == html_a)
+ html_a_special(attr, html, eof);
+ if (ei->func != html_br)
+ was_br = 0;
+ if (a)
+ par_format = pa;
} else {
if (!ei->nopair) {
html_stack_dup();
@@ -2983,23 +3579,41 @@ do { \
int lnb = 0;
int xxx = 0;
was_br = 0;
- if (ei->nopair == 1 || ei->nopair == 3) break;
+ if (ei->nopair == 1 || ei->nopair == 3)
+ break;
/*debug_stack();*/
- foreach(struct html_element, e, le, html_stack) {
- if (e->linebreak && !ei->linebreak) xxx = 1;
- if (e->namelen != namelen || casecmp(e->name, name, e->namelen)) {
- if (e->dontkill) break;
- else continue;
+ foreach (struct html_element, e, le,
+ html_stack) {
+ if (e->linebreak && !ei->linebreak)
+ xxx = 1;
+ if (e->namelen != namelen
+ || casecmp(e->name, name,
+ e->namelen)) {
+ if (e->dontkill)
+ break;
+ else
+ continue;
}
if (xxx) {
kill_html_stack_item(e);
break;
}
- foreachbackfrom(struct html_element, fx, lfx, html_stack, le)
- if (fx->linebreak > lnb) lnb = fx->linebreak;
- format_.fontsize = list_struct(e->list_entry.next, struct html_element)->attr.fontsize;
+ foreachbackfrom (struct html_element,
+ fx, lfx, html_stack,
+ le)
+ if (fx->linebreak > lnb)
+ lnb = fx->linebreak;
+ format_.fontsize =
+ list_struct(e->list_entry.next,
+ struct html_element)
+ ->attr.fontsize;
ln_break(lnb);
- while (e->list_entry.prev != &html_stack) kill_html_stack_item(list_struct(e->list_entry.prev, struct html_element));
+ while (e->list_entry.prev
+ != &html_stack)
+ kill_html_stack_item(
+ list_struct(
+ e->list_entry.prev,
+ struct html_element));
kill_html_stack_item(e);
break;
}
@@ -3024,7 +3638,9 @@ do { \
#undef set_globals
}
-static void scan_area_tag(unsigned char *attr, unsigned char *name, unsigned char **ptr, struct memory_list **ml)
+static void
+scan_area_tag(unsigned char *attr, unsigned char *name, unsigned char **ptr,
+ struct memory_list **ml)
{
unsigned char *v;
if ((v = get_attr_val(attr, name))) {
@@ -3033,7 +3649,11 @@ static void scan_area_tag(unsigned char *attr, unsigned char *name, unsigned cha
}
}
-int get_image_map(unsigned char *head, unsigned char *s, unsigned char *eof, unsigned char *tag, struct menu_item **menu, struct memory_list **ml, unsigned char *href_base, unsigned char *target_base, int to, int def, int hdef, int gfx)
+int
+get_image_map(unsigned char *head, unsigned char *s, unsigned char *eof,
+ unsigned char *tag, struct menu_item **menu,
+ struct memory_list **ml, unsigned char *href_base,
+ unsigned char *target_base, int to, int def, int hdef, int gfx)
{
unsigned char *name, *attr, *al, *label, *href, *target;
int namelen, lblen;
@@ -3044,15 +3664,18 @@ int get_image_map(unsigned char *head, unsigned char *s, unsigned char *eof, uns
unsigned char *hd = init_str();
int hdl = 0;
struct conv_table *ct;
- if (head) add_to_str(&hd, &hdl, head);
+ if (head)
+ add_to_str(&hd, &hdl, head);
scan_http_equiv(s, eof, &hd, &hdl, NULL, NULL, NULL, NULL);
- if (!gfx) ct = get_convert_table(hd, to, def, NULL, NULL, hdef);
- else ct = convert_table;
+ if (!gfx)
+ ct = get_convert_table(hd, to, def, NULL, NULL, hdef);
+ else
+ ct = convert_table;
free(hd);
*menu = mem_calloc(sizeof(struct menu_item));
- se:
+se:
while (s < eof && *s != '<') {
- sp:
+sp:
s++;
}
if (s >= eof) {
@@ -3063,10 +3686,13 @@ int get_image_map(unsigned char *head, unsigned char *s, unsigned char *eof, uns
s = skip_comment(s, eof);
goto se;
}
- if (parse_element(s, eof, &name, &namelen, &attr, &s)) goto sp;
- if (namelen != 3 || casecmp(name, cast_uchar "MAP", 3)) goto se;
+ if (parse_element(s, eof, &name, &namelen, &attr, &s))
+ goto sp;
+ if (namelen != 3 || casecmp(name, cast_uchar "MAP", 3))
+ goto se;
if (tag && *tag) {
- if (!(al = get_attr_val(attr, cast_uchar "name"))) goto se;
+ if (!(al = get_attr_val(attr, cast_uchar "name")))
+ goto se;
if (casestrcmp(al, tag)) {
free(al);
goto se;
@@ -3074,9 +3700,9 @@ int get_image_map(unsigned char *head, unsigned char *s, unsigned char *eof, uns
free(al);
}
*ml = getml(NULL);
- se2:
+se2:
while (s < eof && *s != '<') {
- sp2:
+sp2:
s++;
}
if (s >= eof) {
@@ -3088,15 +3714,17 @@ int get_image_map(unsigned char *head, unsigned char *s, unsigned char *eof, uns
s = skip_comment(s, eof);
goto se2;
}
- if (parse_element(s, eof, &name, &namelen, &attr, &s)) goto sp2;
+ if (parse_element(s, eof, &name, &namelen, &attr, &s))
+ goto sp2;
if (namelen == 1 && !casecmp(name, cast_uchar "A", 1)) {
unsigned char *ss;
label = init_str();
lblen = 0;
- se3:
+se3:
ss = s;
- se4:
- while (ss < eof && *ss != '<') ss++;
+se4:
+ while (ss < eof && *ss != '<')
+ ss++;
if (ss >= eof) {
free(label);
freeml(*ml);
@@ -3113,24 +3741,30 @@ int get_image_map(unsigned char *head, unsigned char *s, unsigned char *eof, uns
ss = s + 1;
goto se4;
}
- if (!((namelen == 1 && !casecmp(name, cast_uchar "A", 1)) ||
- (namelen == 2 && !casecmp(name, cast_uchar "/A", 2)) ||
- (namelen == 3 && !casecmp(name, cast_uchar "MAP", 3)) ||
- (namelen == 4 && !casecmp(name, cast_uchar "/MAP", 4)) ||
- (namelen == 4 && !casecmp(name, cast_uchar "AREA", 4)) ||
- (namelen == 5 && !casecmp(name, cast_uchar "/AREA", 5)))) {
- s = ss;
- goto se3;
+ if (!((namelen == 1 && !casecmp(name, cast_uchar "A", 1))
+ || (namelen == 2 && !casecmp(name, cast_uchar "/A", 2))
+ || (namelen == 3 && !casecmp(name, cast_uchar "MAP", 3))
+ || (namelen == 4 && !casecmp(name, cast_uchar "/MAP", 4))
+ || (namelen == 4 && !casecmp(name, cast_uchar "AREA", 4))
+ || (namelen == 5
+ && !casecmp(name, cast_uchar "/AREA", 5)))) {
+ s = ss;
+ goto se3;
}
} else if (namelen == 4 && !casecmp(name, cast_uchar "AREA", 4)) {
unsigned char *l = get_attr_val(attr, cast_uchar "alt");
if (l) {
- label = !gfx ? convert_string(ct, l, (int)strlen(cast_const_char l), d_opt) : stracpy(l);
+ label =
+ !gfx ? convert_string(
+ ct, l, (int)strlen(cast_const_char l), d_opt)
+ : stracpy(l);
free(l);
} else
label = NULL;
- } else if (namelen == 4 && !casecmp(name, cast_uchar "/MAP", 4)) goto done;
- else goto se2;
+ } else if (namelen == 4 && !casecmp(name, cast_uchar "/MAP", 4))
+ goto done;
+ else
+ goto se2;
href = get_url_val(attr, cast_uchar "href");
if (!(target = get_target(attr)) && !(target = stracpy(target_base)))
target = stracpy(cast_uchar "");
@@ -3215,13 +3849,14 @@ int get_image_map(unsigned char *head, unsigned char *s, unsigned char *eof, uns
goto se2;
add_to_ml(ml, label, NULL);
- if (!gfx) for (i = 0; i < nmenu; i++) {
- struct link_def *ll = (*menu)[i].data;
- if (!xstrcmp(ll->link, ld->link)
- && !xstrcmp(ll->target, ld->target)
- && !xstrcmp(ll->onclick, ld->onclick))
- goto se2;
- }
+ if (!gfx)
+ for (i = 0; i < nmenu; i++) {
+ struct link_def *ll = (*menu)[i].data;
+ if (!xstrcmp(ll->link, ld->link)
+ && !xstrcmp(ll->target, ld->target)
+ && !xstrcmp(ll->onclick, ld->onclick))
+ goto se2;
+ }
if ((unsigned)nmenu > INT_MAX / sizeof(struct menu_item) - 2)
overalloc();
nm = xrealloc(*menu, (nmenu + 2) * sizeof(struct menu_item));
@@ -3234,30 +3869,41 @@ int get_image_map(unsigned char *head, unsigned char *s, unsigned char *eof, uns
nm[nmenu].data = ld;
nm[++nmenu].text = NULL;
goto se2;
- done:
+done:
add_to_ml(ml, *menu, NULL);
return 0;
}
-void scan_http_equiv(unsigned char *s, unsigned char *eof, unsigned char **head, int *hdl, unsigned char **title, unsigned char **background, unsigned char **bgcolor, int *pre_wrap)
+void
+scan_http_equiv(unsigned char *s, unsigned char *eof, unsigned char **head,
+ int *hdl, unsigned char **title, unsigned char **background,
+ unsigned char **bgcolor, int *pre_wrap)
{
unsigned char *name, *attr, *he, *c;
int namelen;
int tlen = 0;
- if (background) *background = NULL;
- if (bgcolor) *bgcolor = NULL;
- if (pre_wrap) *pre_wrap = 0;
- if (title) *title = init_str();
+ if (background)
+ *background = NULL;
+ if (bgcolor)
+ *bgcolor = NULL;
+ if (pre_wrap)
+ *pre_wrap = 0;
+ if (title)
+ *title = init_str();
add_chr_to_str(head, hdl, '\n');
- se:
- while (s < eof && *s != '<') sp:s++;
- if (s >= eof) return;
+se:
+ while (s < eof && *s != '<')
+sp:
+ s++;
+ if (s >= eof)
+ return;
if (eof - s >= 2 && (s[1] == '!' || s[1] == '?')) {
s = skip_comment(s, eof);
goto se;
}
- if (parse_element(s, eof, &name, &namelen, &attr, &s)) goto sp;
- ps:
+ if (parse_element(s, eof, &name, &namelen, &attr, &s))
+ goto sp;
+ps:
if (namelen == 6 && !casecmp(name, cast_uchar "SCRIPT", 6)) {
if (should_skip_script(attr)) {
s = skip_element(s, eof, cast_uchar "SCRIPT", 0);
@@ -3266,7 +3912,8 @@ void scan_http_equiv(unsigned char *s, unsigned char *eof, unsigned char **head,
}
if (namelen == 4 && !casecmp(name, cast_uchar "BODY", 4)) {
if (background) {
- *background = get_attr_val(attr, cast_uchar "background");
+ *background =
+ get_attr_val(attr, cast_uchar "background");
background = NULL;
}
if (bgcolor) {
@@ -3275,13 +3922,17 @@ void scan_http_equiv(unsigned char *s, unsigned char *eof, unsigned char **head,
}
/*return;*/
}
- if (title && !tlen && namelen == 5 && !casecmp(name, cast_uchar "TITLE", 5)) {
+ if (title && !tlen && namelen == 5
+ && !casecmp(name, cast_uchar "TITLE", 5)) {
unsigned char *s1;
- xse:
+xse:
s1 = s;
- while (s < eof && *s != '<') xsp:s++;
+ while (s < eof && *s != '<')
+xsp:
+ s++;
add_bytes_to_str(title, &tlen, s1, s - s1);
- if (s >= eof) goto se;
+ if (s >= eof)
+ goto se;
if (eof - s >= 2 && (s[1] == '!' || s[1] == '?')) {
s = skip_comment(s, eof);
goto xse;
@@ -3295,26 +3946,30 @@ void scan_http_equiv(unsigned char *s, unsigned char *eof, unsigned char **head,
}
if (namelen == 5 && !casecmp(name, cast_uchar "STYLE", 5)) {
while (s < eof && *s != '<') {
- if (*s == 'p' && eof - s >= 8 && !strncmp(cast_const_char s, "pre-wrap", 8)) {
- if (pre_wrap) *pre_wrap = 1;
+ if (*s == 'p' && eof - s >= 8
+ && !strncmp(cast_const_char s, "pre-wrap", 8)) {
+ if (pre_wrap)
+ *pre_wrap = 1;
}
s++;
}
goto se;
}
- if (namelen != 4 || casecmp(name, cast_uchar "META", 4)) goto se;
+ if (namelen != 4 || casecmp(name, cast_uchar "META", 4))
+ goto se;
if ((he = get_attr_val(attr, cast_uchar "charset"))) {
add_to_str(head, hdl, cast_uchar "Charset: ");
add_to_str(head, hdl, he);
add_to_str(head, hdl, cast_uchar "\r\n");
free(he);
}
- if (!(he = get_attr_val(attr, cast_uchar "http-equiv"))) goto se;
+ if (!(he = get_attr_val(attr, cast_uchar "http-equiv")))
+ goto se;
c = get_attr_val(attr, cast_uchar "content");
add_to_str(head, hdl, he);
if (c) {
add_to_str(head, hdl, cast_uchar ": ");
- add_to_str(head, hdl, c);
+ add_to_str(head, hdl, c);
free(c);
}
free(he);
diff --git a/html_r.c b/html_r.c
@@ -7,7 +7,8 @@
#include "links.h"
-struct f_data *init_formatted(struct document_options *opt)
+struct f_data *
+init_formatted(struct document_options *opt)
{
struct f_data *scr;
scr = mem_calloc(sizeof(struct f_data));
@@ -21,7 +22,8 @@ struct f_data *init_formatted(struct document_options *opt)
return scr;
}
-void destroy_fc(struct form_control *fc)
+void
+destroy_fc(struct form_control *fc)
{
int i;
free(fc->action);
@@ -37,51 +39,67 @@ void destroy_fc(struct form_control *fc)
}
free(fc->values);
free(fc->labels);
- if (fc->menu) free_menu(fc->menu);
+ if (fc->menu)
+ free_menu(fc->menu);
}
-void free_frameset_desc(struct frameset_desc *fd)
+void
+free_frameset_desc(struct frameset_desc *fd)
{
int i;
for (i = 0; i < fd->n; i++) {
- if (fd->f[i].subframe) free_frameset_desc(fd->f[i].subframe);
+ if (fd->f[i].subframe)
+ free_frameset_desc(fd->f[i].subframe);
free(fd->f[i].name);
free(fd->f[i].url);
}
free(fd);
}
-struct frameset_desc *copy_frameset_desc(struct frameset_desc *fd)
+struct frameset_desc *
+copy_frameset_desc(struct frameset_desc *fd)
{
int i;
struct frameset_desc *neww;
- if ((unsigned)fd->n > INT_MAX / sizeof(struct frame_desc)) overalloc();
- neww = xmalloc(sizeof(struct frameset_desc) + fd->n * sizeof(struct frame_desc));
- memcpy(neww, fd, sizeof(struct frameset_desc) + fd->n * sizeof(struct frame_desc));
+ if ((unsigned)fd->n > INT_MAX / sizeof(struct frame_desc))
+ overalloc();
+ neww = xmalloc(sizeof(struct frameset_desc)
+ + fd->n * sizeof(struct frame_desc));
+ memcpy(neww, fd,
+ sizeof(struct frameset_desc)
+ + fd->n * sizeof(struct frame_desc));
for (i = 0; i < neww->n; i++) {
- if (neww->f[i].subframe) neww->f[i].subframe = copy_frameset_desc(neww->f[i].subframe);
- if (neww->f[i].name) neww->f[i].name = stracpy(neww->f[i].name);
- if (neww->f[i].url) neww->f[i].url = stracpy(neww->f[i].url);
+ if (neww->f[i].subframe)
+ neww->f[i].subframe =
+ copy_frameset_desc(neww->f[i].subframe);
+ if (neww->f[i].name)
+ neww->f[i].name = stracpy(neww->f[i].name);
+ if (neww->f[i].url)
+ neww->f[i].url = stracpy(neww->f[i].url);
}
return neww;
}
-void free_additional_files(struct additional_files **a)
+void
+free_additional_files(struct additional_files **a)
{
struct additional_file *af = NULL;
struct list_head *laf;
- if (!*a) return;
+ if (!*a)
+ return;
if (--(*a)->refcount) {
*a = NULL;
return;
}
- foreach(struct additional_file, af, laf, (*a)->af) release_object(&af->rq);
+ foreach (struct additional_file, af, laf, (*a)->af)
+ release_object(&af->rq);
free_list(struct additional_file, (*a)->af);
free(*a);
*a = NULL;
}
-static void clear_formatted(struct f_data *scr)
+static void
+clear_formatted(struct f_data *scr)
{
int n;
int y;
@@ -116,7 +134,7 @@ static void clear_formatted(struct f_data *scr)
free(scr->lines1);
free(scr->lines2);
free(scr->opt.framename);
- foreach(struct form_control, fc, lfc, scr->forms) {
+ foreach (struct form_control, fc, lfc, scr->forms) {
destroy_fc(fc);
}
free_list(struct form_control, scr->forms);
@@ -125,7 +143,8 @@ static void clear_formatted(struct f_data *scr)
free(scr->refresh);
}
-void destroy_formatted(struct f_data *scr)
+void
+destroy_formatted(struct f_data *scr)
{
if (scr->fd) {
internal("trying to free locked formatted data");
@@ -135,31 +154,31 @@ void destroy_formatted(struct f_data *scr)
free(scr);
}
-static inline int color_distance(struct rgb *c1, struct rgb *c2)
+static inline int
+color_distance(struct rgb *c1, struct rgb *c2)
{
- return
- 3 * (c1->r - c2->r) * (c1->r - c2->r) +
- 4 * (c1->g - c2->g) * (c1->g - c2->g) +
- 2 * (c1->b - c2->b) * (c1->b - c2->b);
+ return 3 * (c1->r - c2->r) * (c1->r - c2->r)
+ + 4 * (c1->g - c2->g) * (c1->g - c2->g)
+ + 2 * (c1->b - c2->b) * (c1->b - c2->b);
}
struct rgb palette_16_colors[16] = {
- {0x00, 0x00, 0x00, 0},
- {0x80, 0x00, 0x00, 0},
- {0x00, 0x80, 0x00, 0},
- {0xaa, 0x55, 0x00, 0},
- {0x00, 0x00, 0x80, 0},
- {0x80, 0x00, 0x80, 0},
- {0x00, 0x80, 0x80, 0},
- {0xaa, 0xaa, 0xaa, 0},
- {0x55, 0x55, 0x55, 0},
- {0xff, 0x55, 0x55, 0},
- {0x55, 0xff, 0x55, 0},
- {0xff, 0xff, 0x55, 0},
- {0x55, 0x55, 0xff, 0},
- {0xff, 0x55, 0xff, 0},
- {0x55, 0xff, 0xff, 0},
- {0xff, 0xff, 0xff, 0},
+ {0x00, 0x00, 0x00, 0},
+ { 0x80, 0x00, 0x00, 0},
+ { 0x00, 0x80, 0x00, 0},
+ { 0xaa, 0x55, 0x00, 0},
+ { 0x00, 0x00, 0x80, 0},
+ { 0x80, 0x00, 0x80, 0},
+ { 0x00, 0x80, 0x80, 0},
+ { 0xaa, 0xaa, 0xaa, 0},
+ { 0x55, 0x55, 0x55, 0},
+ { 0xff, 0x55, 0x55, 0},
+ { 0x55, 0xff, 0x55, 0},
+ { 0xff, 0xff, 0x55, 0},
+ { 0x55, 0x55, 0xff, 0},
+ { 0xff, 0x55, 0xff, 0},
+ { 0x55, 0xff, 0xff, 0},
+ { 0xff, 0xff, 0xff, 0},
};
struct rgb_cache_entry {
@@ -170,9 +189,11 @@ struct rgb_cache_entry {
#define RGB_HASH_SIZE 4096
-#define HASH_RGB(r, l) ((((r)->r << 3) + ((r)->g << 2) + (r)->b + (l)) & (RGB_HASH_SIZE - 1))
+#define HASH_RGB(r, l) \
+ ((((r)->r << 3) + ((r)->g << 2) + (r)->b + (l)) & (RGB_HASH_SIZE - 1))
-int find_nearest_color(struct rgb *r, int l)
+int
+find_nearest_color(struct rgb *r, int l)
{
int dist, dst, min, i;
static struct rgb_cache_entry rgb_cache[RGB_HASH_SIZE];
@@ -180,10 +201,14 @@ int find_nearest_color(struct rgb *r, int l)
int h;
if ((size_t)l > array_elements(palette_16_colors))
internal("invalid length %d", l);
- if (!cache_init) goto initialize;
- back:
+ if (!cache_init)
+ goto initialize;
+back:
h = HASH_RGB(r, l);
- if (rgb_cache[h].color != -1 && rgb_cache[h].l == l && rgb_cache[h].rgb.r == r->r && rgb_cache[h].rgb.g == r->g && rgb_cache[h].rgb.b == r->b) return rgb_cache[h].color;
+ if (rgb_cache[h].color != -1 && rgb_cache[h].l == l
+ && rgb_cache[h].rgb.r == r->r && rgb_cache[h].rgb.g == r->g
+ && rgb_cache[h].rgb.b == r->b)
+ return rgb_cache[h].color;
dist = 0xffffff;
min = 0;
for (i = 0; i < l; i++)
@@ -198,30 +223,38 @@ int find_nearest_color(struct rgb *r, int l)
rgb_cache[h].rgb.b = r->b;
return min;
- initialize:
- for (h = 0; h < RGB_HASH_SIZE; h++) rgb_cache[h].color = -1;
+initialize:
+ for (h = 0; h < RGB_HASH_SIZE; h++)
+ rgb_cache[h].color = -1;
cache_init = 1;
goto back;
}
-int fg_color(int fg, int bg)
+int
+fg_color(int fg, int bg)
{
int l = bg < fg ? bg : fg;
int h = bg < fg ? fg : bg;
- if (l == h || (!l && (h == 4 || h == 8 || h == 12)) ||
- (l == 1 && (h == 3 || h == 5 || h == 8 || h == 12)) ||
- (l == 2 && h == 6) || (l == 3 && (h == 5 || h == 12)) ||
- (l == 4 && (h == 8 || h == 12)) || (l == 5 && (h == 8 || h == 12)))
- return (fg == 4 || fg == 12) && (bg == 0 || bg == 8) ? 6 : (7 - 7 * (bg == 2 || bg == 6 || bg == 7));
+ if (l == h || (!l && (h == 4 || h == 8 || h == 12))
+ || (l == 1 && (h == 3 || h == 5 || h == 8 || h == 12))
+ || (l == 2 && h == 6) || (l == 3 && (h == 5 || h == 12))
+ || (l == 4 && (h == 8 || h == 12))
+ || (l == 5 && (h == 8 || h == 12)))
+ return (fg == 4 || fg == 12) && (bg == 0 || bg == 8)
+ ? 6
+ : (7 - 7 * (bg == 2 || bg == 6 || bg == 7));
return fg;
}
static int nowrap = 0;
-static void xpand_lines(struct part *p, int y)
+static void
+xpand_lines(struct part *p, int y)
{
- if (!p->data) return;
- if (y < 0) return;
+ if (!p->data)
+ return;
+ if (y < 0)
+ return;
y = safe_add(y, safe_add(p->yp, 1));
if (y > p->data->y) {
int i;
@@ -231,8 +264,8 @@ static void xpand_lines(struct part *p, int y)
if (s > INT_MAX / sizeof(struct line))
overalloc();
}
- p->data->data = xrealloc(p->data->data,
- s * sizeof(struct line));
+ p->data->data =
+ xrealloc(p->data->data, s * sizeof(struct line));
}
for (i = p->data->y; i < y; i++) {
p->data->data[i].l = 0;
@@ -243,21 +276,25 @@ static void xpand_lines(struct part *p, int y)
}
}
-static void xpand_line(struct part *p, int y, int x)
+static void
+xpand_line(struct part *p, int y, int x)
{
struct line *ln;
- if (!p->data) return;
+ if (!p->data)
+ return;
x = safe_add(x, p->xp);
y = safe_add(y, p->yp);
ln = &p->data->data[y];
if (x >= ln->l) {
int i;
if (x >= ln->allocated) {
- if (x >= 0x4000) ln->allocated = safe_add(x, x);
- else ln->allocated = safe_add(x, 0x10) & ~0xf;
+ if (x >= 0x4000)
+ ln->allocated = safe_add(x, x);
+ else
+ ln->allocated = safe_add(x, 0x10) & ~0xf;
if ((unsigned)ln->allocated > INT_MAX / sizeof(chr))
overalloc();
- ln->d = xrealloc(ln->d, ln->allocated*sizeof(chr));
+ ln->d = xrealloc(ln->d, ln->allocated * sizeof(chr));
}
for (i = ln->l; i <= x; i++) {
ln->d[i].at = p->attribute;
@@ -267,7 +304,8 @@ static void xpand_line(struct part *p, int y, int x)
}
}
-static void r_xpand_spaces(struct part *p, int l)
+static void
+r_xpand_spaces(struct part *p, int l)
{
unsigned char *c;
if ((unsigned)l >= INT_MAX)
@@ -278,18 +316,24 @@ static void r_xpand_spaces(struct part *p, int l)
p->spaces = c;
}
-static inline void xpand_spaces(struct part *p, int l)
+static inline void
+xpand_spaces(struct part *p, int l)
{
- if ((unsigned)l >= (unsigned)p->spl) r_xpand_spaces(p, l);
+ if ((unsigned)l >= (unsigned)p->spl)
+ r_xpand_spaces(p, l);
}
#define POS(x, y) (p->data->data[safe_add(p->yp, (y))].d[safe_add(p->xp, (x))])
-#define LEN(y) (p->data->data[safe_add(p->yp, (y))].l - p->xp < 0 ? 0 : p->data->data[p->yp + (y)].l - p->xp)
+#define LEN(y) \
+ (p->data->data[safe_add(p->yp, (y))].l - p->xp < 0 \
+ ? 0 \
+ : p->data->data[p->yp + (y)].l - p->xp)
#define SLEN(y, x) p->data->data[safe_add(p->yp, (y))].l = safe_add(p->xp, x)
-#define X(x) safe_add(p->xp, (x))
-#define Y(y) safe_add(p->yp, (y))
+#define X(x) safe_add(p->xp, (x))
+#define Y(y) safe_add(p->yp, (y))
-static inline void set_hchar(struct part *p, int x, int y, unsigned ch, unsigned char at)
+static inline void
+set_hchar(struct part *p, int x, int y, unsigned ch, unsigned char at)
{
chr *cc;
xpand_lines(p, y);
@@ -299,11 +343,12 @@ static inline void set_hchar(struct part *p, int x, int y, unsigned ch, unsigned
cc->at = at;
}
-static inline void set_hchars(struct part *p, int x, int y, int xl, unsigned ch, unsigned char at)
+static inline void
+set_hchars(struct part *p, int x, int y, int xl, unsigned ch, unsigned char at)
{
chr *cc;
xpand_lines(p, y);
- xpand_line(p, y, safe_add(x,xl)-1);
+ xpand_line(p, y, safe_add(x, xl) - 1);
cc = &POS(x, y);
for (; xl; xl--) {
cc->ch = ch;
@@ -312,38 +357,47 @@ static inline void set_hchars(struct part *p, int x, int y, int xl, unsigned ch,
}
}
-void xset_hchar(struct part *p, int x, int y, unsigned ch, unsigned char at)
+void
+xset_hchar(struct part *p, int x, int y, unsigned ch, unsigned char at)
{
set_hchar(p, x, y, ch, at);
}
-void xset_hchars(struct part *p, int x, int y, int xl, unsigned ch, unsigned char at)
+void
+xset_hchars(struct part *p, int x, int y, int xl, unsigned ch, unsigned char at)
{
set_hchars(p, x, y, xl, ch, at);
}
-void xxpand_lines(struct part *p, int y)
+void
+xxpand_lines(struct part *p, int y)
{
xpand_lines(p, y);
}
-void xxpand_line(struct part *p, int y, int x)
+void
+xxpand_line(struct part *p, int y, int x)
{
xpand_line(p, y, x);
}
-static inline void set_hline(struct part *p, int x, int y, int xl, unsigned char *d, unsigned char at)
+static inline void
+set_hline(struct part *p, int x, int y, int xl, unsigned char *d,
+ unsigned char at)
{
chr *cc;
int xp;
xpand_lines(p, y);
- xpand_line(p, y, safe_add(x,xl)-1);
+ xpand_line(p, y, safe_add(x, xl) - 1);
xp = par_format.align != AL_NO;
- if (xp) xpand_spaces(p, safe_add(x,xl)-1);
+ if (xp)
+ xpand_spaces(p, safe_add(x, xl) - 1);
cc = NULL;
- if (p->data) cc = &POS(x, y);
+ if (p->data)
+ cc = &POS(x, y);
for (; xl; xl--, x++, d++) {
- if (xp) p->spaces[x] = *d == ' ';
+ if (xp)
+ p->spaces[x] = *d == ' ';
if (p->data) {
cc->ch = *d;
cc->at = at;
@@ -352,18 +406,22 @@ static inline void set_hline(struct part *p, int x, int y, int xl, unsigned char
}
}
-static inline void set_hline_uni(struct part *p, int x, int y, int xl, char_t *d, unsigned char at)
+static inline void
+set_hline_uni(struct part *p, int x, int y, int xl, char_t *d, unsigned char at)
{
chr *cc;
int xp;
xpand_lines(p, y);
- xpand_line(p, y, safe_add(x,xl)-1);
+ xpand_line(p, y, safe_add(x, xl) - 1);
xp = par_format.align != AL_NO;
- if (xp) xpand_spaces(p, safe_add(x,xl)-1);
+ if (xp)
+ xpand_spaces(p, safe_add(x, xl) - 1);
cc = NULL;
- if (p->data) cc = &POS(x, y);
+ if (p->data)
+ cc = &POS(x, y);
for (; xl; xl--, x++, d++) {
- if (xp) p->spaces[x] = *d == ' ';
+ if (xp)
+ p->spaces[x] = *d == ' ';
if (p->data) {
cc->ch = *d;
cc->at = at;
@@ -376,76 +434,100 @@ static int last_link_to_move;
static struct list_head *last_tag_to_move;
static struct list_head *last_tag_for_newline;
-static inline void move_links(struct part *p, int xf, int yf, int xt, int yt)
+static inline void
+move_links(struct part *p, int xf, int yf, int xt, int yt)
{
int n;
struct tag *t = NULL;
struct list_head *lt;
int w = 0;
- if (!p->data) return;
+ if (!p->data)
+ return;
xpand_lines(p, yt);
for (n = last_link_to_move; n < p->data->nlinks; n++) {
int i;
struct link *link = &p->data->links[n];
- /*printf("ml: %d %d %d %d",link->pos[0].x,link->pos[0].y,X(xf),Y(yf));fflush(stdout);portable_sleep(1000);*/
- for (i = link->first_point_to_move; i < link->n; i++) if (link->pos[i].y >= Y(yf)) {
- w = 1;
- if (link->pos[i].y == Y(yf) && link->pos[i].x >= X(xf)) {
- if (yt >= 0) {
- link->pos[i].y = Y(yt);
- if (xt > xf)
- link->pos[i].x = safe_add(link->pos[i].x, -xf + xt);
- else
- link->pos[i].x = link->pos[i].x -xf + xt;
- } else {
- memmove(&link->pos[i], &link->pos[i+1],
- (link->n-i-1) * sizeof(struct point));
- link->n--;
- i--;
+ /*printf("ml: %d %d %d
+ * %d",link->pos[0].x,link->pos[0].y,X(xf),Y(yf));fflush(stdout);portable_sleep(1000);*/
+ for (i = link->first_point_to_move; i < link->n; i++)
+ if (link->pos[i].y >= Y(yf)) {
+ w = 1;
+ if (link->pos[i].y == Y(yf)
+ && link->pos[i].x >= X(xf)) {
+ if (yt >= 0) {
+ link->pos[i].y = Y(yt);
+ if (xt > xf)
+ link->pos[i].x =
+ safe_add(
+ link->pos[i].x,
+ -xf + xt);
+ else
+ link->pos[i].x =
+ link->pos[i].x - xf
+ + xt;
+ } else {
+ memmove(
+ &link->pos[i],
+ &link->pos[i + 1],
+ (link->n - i - 1)
+ * sizeof(struct point));
+ link->n--;
+ i--;
+ }
}
+ } else {
+ link->first_point_to_move = safe_add(i, 1);
}
- } else {
- link->first_point_to_move = safe_add(i, 1);
- }
- if (!w) last_link_to_move = n;
+ if (!w)
+ last_link_to_move = n;
}
w = 0;
- if (yt >= 0) foreachfrom(struct tag, t, lt, p->data->tags, last_tag_to_move->next) {
- if (t->y == Y(yf)) {
- w = 1;
- if (t->x >= X(xf)) {
- t->y = Y(yt);
- if (xt > xf)
- t->x = safe_add(t->x, -xf + xt);
- else
- t->x += -xf + xt;
+ if (yt >= 0)
+ foreachfrom (struct tag, t, lt, p->data->tags,
+ last_tag_to_move->next) {
+ if (t->y == Y(yf)) {
+ w = 1;
+ if (t->x >= X(xf)) {
+ t->y = Y(yt);
+ if (xt > xf)
+ t->x = safe_add(t->x, -xf + xt);
+ else
+ t->x += -xf + xt;
+ }
}
+ if (!w)
+ last_tag_to_move = &t->list_entry;
}
- if (!w) last_tag_to_move = &t->list_entry;
- }
}
-static inline void copy_chars(struct part *p, int x, int y, int xl, chr *d)
+static inline void
+copy_chars(struct part *p, int x, int y, int xl, chr *d)
{
- if (xl <= 0) return;
+ if (xl <= 0)
+ return;
xpand_lines(p, y);
- xpand_line(p, y, safe_add(x,xl)-1);
- for (; xl; xl--, x++, d++) POS(x, y) = *d;
+ xpand_line(p, y, safe_add(x, xl) - 1);
+ for (; xl; xl--, x++, d++)
+ POS(x, y) = *d;
}
-static inline void move_chars(struct part *p, int x, int y, int nx, int ny)
+static inline void
+move_chars(struct part *p, int x, int y, int nx, int ny)
{
- if (LEN(y) - x <= 0) return;
+ if (LEN(y) - x <= 0)
+ return;
copy_chars(p, nx, ny, LEN(y) - x, &POS(x, y));
SLEN(y, x);
move_links(p, x, y, nx, ny);
}
-static inline void shift_chars(struct part *p, int y, int s)
+static inline void
+shift_chars(struct part *p, int y, int s)
{
chr *a;
int l = LEN(y);
- if ((unsigned)l > INT_MAX / sizeof(chr)) overalloc();
+ if ((unsigned)l > INT_MAX / sizeof(chr))
+ overalloc();
a = xmalloc(l * sizeof(chr));
memcpy(a, &POS(0, y), l * sizeof(chr));
set_hchars(p, 0, y, s, ' ', p->attribute);
@@ -454,90 +536,116 @@ static inline void shift_chars(struct part *p, int y, int s)
move_links(p, 0, y, s, y);
}
-static inline void del_chars(struct part *p, int x, int y)
+static inline void
+del_chars(struct part *p, int x, int y)
{
SLEN(y, x);
move_links(p, x, y, -1, -1);
}
-#define rm(x) ((x).width - (x).rightmargin > 0 ? (x).width - (x).rightmargin : 0)
+#define rm(x) \
+ ((x).width - (x).rightmargin > 0 ? (x).width - (x).rightmargin : 0)
static void line_break(void *);
-static int split_line(struct part *p)
+static int
+split_line(struct part *p)
{
int i;
if (rm(par_format) >= p->z_spaces) {
for (i = rm(par_format); i >= par_format.leftmargin; i--)
- if (i < p->spl && p->spaces[i]) goto split;
+ if (i < p->spl && p->spaces[i])
+ goto split;
}
i = rm(par_format) + 1;
- if (i < p->z_spaces) i = p->z_spaces;
- if (i < par_format.leftmargin) i = par_format.leftmargin;
- for (; i < p->cx ; i++)
- if (i < p->spl && p->spaces[i]) goto split;
+ if (i < p->z_spaces)
+ i = p->z_spaces;
+ if (i < par_format.leftmargin)
+ i = par_format.leftmargin;
+ for (; i < p->cx; i++)
+ if (i < p->spl && p->spaces[i])
+ goto split;
p->z_spaces = i;
- if (p->cx >= 0 && safe_add(p->cx, par_format.rightmargin) > p->x) p->x = p->cx + par_format.rightmargin;
+ if (p->cx >= 0 && safe_add(p->cx, par_format.rightmargin) > p->x)
+ p->x = p->cx + par_format.rightmargin;
return 0;
- split:
- if (safe_add(i, par_format.rightmargin) > p->x) p->x = i + par_format.rightmargin;
+split:
+ if (safe_add(i, par_format.rightmargin) > p->x)
+ p->x = i + par_format.rightmargin;
if (p->data) {
- move_chars(p, safe_add(i,1), p->cy, par_format.leftmargin, safe_add(p->cy,1));
+ move_chars(p, safe_add(i, 1), p->cy, par_format.leftmargin,
+ safe_add(p->cy, 1));
del_chars(p, i, p->cy);
}
memmove(p->spaces, p->spaces + safe_add(i, 1), p->spl - i - 1);
memset(p->spaces + p->spl - i - 1, 0, i + 1);
- memmove(p->spaces + par_format.leftmargin, p->spaces, p->spl - par_format.leftmargin);
+ memmove(p->spaces + par_format.leftmargin, p->spaces,
+ p->spl - par_format.leftmargin);
p->z_spaces = 0;
p->cy = safe_add(p->cy, 1);
p->cx -= i - par_format.leftmargin + 1;
- if (p->cx == par_format.leftmargin) p->cx = -1;
- if (p->y < safe_add(p->cy, (p->cx != -1))) p->y = p->cy + (p->cx != -1);
+ if (p->cx == par_format.leftmargin)
+ p->cx = -1;
+ if (p->y < safe_add(p->cy, (p->cx != -1)))
+ p->y = p->cy + (p->cx != -1);
return 1 + (p->cx == -1);
}
-static void align_line(struct part *p, int y)
+static void
+align_line(struct part *p, int y)
{
int na;
- if (!p->data) return;
- if (!LEN(y) || par_format.align == AL_LEFT || par_format.align == AL_NO || par_format.align == AL_NO_BREAKABLE || par_format.align == AL_BLOCK /* !!! fixme! */) return;
+ if (!p->data)
+ return;
+ if (!LEN(y) || par_format.align == AL_LEFT || par_format.align == AL_NO
+ || par_format.align == AL_NO_BREAKABLE
+ || par_format.align == AL_BLOCK /* !!! fixme! */)
+ return;
na = rm(par_format) - LEN(y);
- if (par_format.align == AL_CENTER) na /= 2;
- if (na > 0) shift_chars(p, y, na);
+ if (par_format.align == AL_CENTER)
+ na /= 2;
+ if (na > 0)
+ shift_chars(p, y, na);
}
-struct link *new_link(struct f_data *f)
+struct link *
+new_link(struct f_data *f)
{
if (!f)
return NULL;
if (!(f->nlinks & (ALLOC_GR - 1))) {
- if ((unsigned)f->nlinks > INT_MAX / sizeof(struct link) - ALLOC_GR)
+ if ((unsigned)f->nlinks
+ > INT_MAX / sizeof(struct link) - ALLOC_GR)
overalloc();
- f->links = xrealloc(f->links,
- (f->nlinks + ALLOC_GR) * sizeof(struct link));
+ f->links = xrealloc(f->links, (f->nlinks + ALLOC_GR)
+ * sizeof(struct link));
}
memset(&f->links[f->nlinks], 0, sizeof(struct link));
return &f->links[f->nlinks++];
}
-void html_tag(struct f_data *f, unsigned char *t, int x, int y)
+void
+html_tag(struct f_data *f, unsigned char *t, int x, int y)
{
struct tag *tag;
size_t sl;
unsigned char *tt;
int ll;
- if (!f) return;
+ if (!f)
+ return;
tt = init_str();
ll = 0;
add_conv_str(&tt, &ll, t, (int)strlen(cast_const_char t), -2);
sl = strlen(cast_const_char tt);
- if (sl > INT_MAX - sizeof(struct tag)) overalloc();
+ if (sl > INT_MAX - sizeof(struct tag))
+ overalloc();
tag = xmalloc(sizeof(struct tag) + sl);
tag->x = x;
tag->y = y;
strcpy(cast_char tag->name, cast_const_char tt);
add_to_list(f->tags, tag);
- if (last_tag_for_newline == &f->tags) last_tag_for_newline = &tag->list_entry;
+ if (last_tag_for_newline == &f->tags)
+ last_tag_for_newline = &tag->list_entry;
free(tt);
}
@@ -550,11 +658,16 @@ static int nobreak;
struct conv_table *convert_table;
-static void put_chars(void *p_, unsigned char *c, int l)
+static void
+put_chars(void *p_, unsigned char *c, int l)
{
struct part *p = p_;
- static struct text_attrib_beginning ta_cache = { -1, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, 0, 0 };
+ static struct text_attrib_beginning ta_cache = {
+ -1, {0, 0, 0, 0},
+ { 0, 0, 0, 0},
+ 0, 0
+ };
static int bg_cache;
static int fg_cache;
char_t *uni_c = NULL;
@@ -565,16 +678,21 @@ static void put_chars(void *p_, unsigned char *c, int l)
struct point *pt;
int ll;
- if (l < 0) overalloc();
+ if (l < 0)
+ overalloc();
- /*printf("%d-", p->cx);for (i=0; i<l; i++) printf("%c", c[i]); printf("-\n");portable_sleep(1000);*/
+ /*printf("%d-", p->cx);for (i=0; i<l; i++) printf("%c", c[i]);
+ * printf("-\n");portable_sleep(1000);*/
while (p->cx <= par_format.leftmargin && l && *c == ' '
- && par_format.align != AL_NO && par_format.align != AL_NO_BREAKABLE) {
+ && par_format.align != AL_NO
+ && par_format.align != AL_NO_BREAKABLE) {
c++;
l--;
}
- if (!l) return;
- if (p->cx < par_format.leftmargin) p->cx = par_format.leftmargin;
+ if (!l)
+ return;
+ if (p->cx < par_format.leftmargin)
+ p->cx = par_format.leftmargin;
if (c[0] != ' ' || (c[1] && c[1] != ' ')) {
if (p->data)
last_tag_for_newline = &p->data->tags;
@@ -585,7 +703,7 @@ static void put_chars(void *p_, unsigned char *c, int l)
if (p->utf8_part_len) {
unsigned char new_part[7];
unsigned char *q;
- next_utf_byte:
+next_utf_byte:
if ((*c & 0xc0) != 0x80)
goto bad_utf;
p->utf8_part[p->utf8_part_len++] = *c;
@@ -594,27 +712,33 @@ static void put_chars(void *p_, unsigned char *c, int l)
l--;
q = p->utf8_part;
if (!get_utf_8(&q)) {
- if (p->utf8_part_len == sizeof(p->utf8_part) - 1)
+ if (p->utf8_part_len
+ == sizeof(p->utf8_part) - 1)
goto bad_utf;
- if (l) goto next_utf_byte;
+ if (l)
+ goto next_utf_byte;
return;
}
pl = p->utf8_part_len;
p->utf8_part_len = 0;
- strcpy(cast_char new_part, cast_const_char p->utf8_part);
+ strcpy(cast_char new_part,
+ cast_const_char p->utf8_part);
put_chars(p, new_part, pl);
}
- bad_utf:
+bad_utf:
p->utf8_part_len = 0;
- if (!l) return;
- if ((unsigned)l > (unsigned)INT_MAX / sizeof(char_t)) overalloc();
+ if (!l)
+ return;
+ if ((unsigned)l > (unsigned)INT_MAX / sizeof(char_t))
+ overalloc();
uni_c = xmalloc(l * sizeof(char_t));
ll = 0;
cc = c;
- next_utf_char:
+next_utf_char:
pl = utf8chrlen(*cc);
if (safe_add((int)(cc - c), pl) > l) {
- memcpy(p->utf8_part, cc, p->utf8_part_len = l - (int)(cc - c));
+ memcpy(p->utf8_part, cc,
+ p->utf8_part_len = l - (int)(cc - c));
goto utf_done;
} else {
if (!pl) {
@@ -627,75 +751,92 @@ static void put_chars(void *p_, unsigned char *c, int l)
ll = safe_add(ll, 1);
}
}
- if (cc < c + l) goto next_utf_char;
+ if (cc < c + l)
+ goto next_utf_char;
}
- utf_done:
+utf_done:
if (!ll) {
free(uni_c);
return;
}
- } else
- {
+ } else {
ll = l;
}
if (last_link || last_image || last_form || format_.link
- || format_.image || format_.form)
+ || format_.image || format_.form)
goto process_link;
- no_l:
+no_l:
/*printf("%d %d\n",p->cx, p->cy);*/
- if (memcmp(&ta_cache, &format_, sizeof(struct text_attrib_beginning))) goto format_change;
+ if (memcmp(&ta_cache, &format_, sizeof(struct text_attrib_beginning)))
+ goto format_change;
bg = bg_cache;
fg = fg_cache;
- end_format_change:
- if (p->y < safe_add(p->cy, 1)) p->y = p->cy + 1;
+end_format_change:
+ if (p->y < safe_add(p->cy, 1))
+ p->y = p->cy + 1;
if (nowrap && safe_add(p->cx, ll) > rm(par_format)) {
free(uni_c);
return;
}
if (!d_opt->cp && !(format_.attr & AT_GRAPHICS)) {
- set_hline_uni(p, p->cx, p->cy, ll, uni_c, ((fg&0x08)<<3)|(bg<<3)|(fg&0x07));
+ set_hline_uni(p, p->cx, p->cy, ll, uni_c,
+ ((fg & 0x08) << 3) | (bg << 3) | (fg & 0x07));
} else
- set_hline(p, p->cx, p->cy, l, c, ((fg&0x08)<<3)|(bg<<3)|(fg&0x07));
+ set_hline(p, p->cx, p->cy, l, c,
+ ((fg & 0x08) << 3) | (bg << 3) | (fg & 0x07));
p->cx += ll;
nobreak = 0;
if (par_format.align != AL_NO)
- while (p->cx > rm(par_format) && p->cx > par_format.leftmargin) {
+ while (p->cx > rm(par_format)
+ && p->cx > par_format.leftmargin) {
int x;
- if (!(x = split_line(p))) break;
+ if (!(x = split_line(p)))
+ break;
align_line(p, p->cy - 1);
nobreak = x - 1;
}
p->xa = safe_add(p->xa, ll);
- if (safe_add(p->xa - (c[l-1] == ' ' && par_format.align != AL_NO && par_format.align != AL_NO_BREAKABLE), safe_add(par_format.leftmargin, par_format.rightmargin)) > p->xmax) p->xmax = p->xa - (c[l-1] == ' ' && par_format.align != AL_NO && par_format.align != AL_NO_BREAKABLE) + par_format.leftmargin + par_format.rightmargin;
+ if (safe_add(p->xa
+ - (c[l - 1] == ' ' && par_format.align != AL_NO
+ && par_format.align != AL_NO_BREAKABLE),
+ safe_add(par_format.leftmargin, par_format.rightmargin))
+ > p->xmax)
+ p->xmax = p->xa
+ - (c[l - 1] == ' ' && par_format.align != AL_NO
+ && par_format.align != AL_NO_BREAKABLE)
+ + par_format.leftmargin + par_format.rightmargin;
free(uni_c);
return;
/* !!! WARNING: THE FOLLOWING CODE IS SHADOWED IN HTML_GR.C */
- process_link:
+process_link:
if ((last_link || last_image || last_form)
- && !xstrcmp(format_.link, last_link)
- && !xstrcmp(format_.target, last_target)
- && !xstrcmp(format_.image, last_image)
- && format_.form == last_form) {
- if (!p->data) goto x;
+ && !xstrcmp(format_.link, last_link)
+ && !xstrcmp(format_.target, last_target)
+ && !xstrcmp(format_.image, last_image)
+ && format_.form == last_form) {
+ if (!p->data)
+ goto x;
link = &p->data->links[p->data->nlinks - 1];
if (!p->data->nlinks) {
internal("no link");
goto no_l;
}
goto set_link;
- x:;
+x:;
} else {
free(last_link);
free(last_target);
free(last_image);
last_link = last_target = last_image = NULL;
last_form = NULL;
- if (!(format_.link || format_.image || format_.form)) goto no_l;
+ if (!(format_.link || format_.image || format_.form))
+ goto no_l;
if (d_opt->num_links) {
unsigned char s[64];
- unsigned char *fl = format_.link, *ft = format_.target, *fi = format_.image;
+ unsigned char *fl = format_.link, *ft = format_.target,
+ *fi = format_.image;
struct form_control *ff = format_.form;
format_.link = format_.target = format_.image = NULL;
format_.form = NULL;
@@ -704,17 +845,26 @@ static void put_chars(void *p_, unsigned char *c, int l)
snzprint(s + 1, 62, p->link_num);
strcat(cast_char s, "]");
} else {
- if (ff && (ff->type == FC_TEXT || ff->type == FC_PASSWORD || ff->type == FC_FILE_UPLOAD || ff->type == FC_TEXTAREA)) {
+ if (ff
+ && (ff->type == FC_TEXT
+ || ff->type == FC_PASSWORD
+ || ff->type == FC_FILE_UPLOAD
+ || ff->type == FC_TEXTAREA)) {
strcpy(cast_char s, ">");
- } else if (ff && (ff->type == FC_CHECKBOX || ff->type == FC_RADIO || ff->type == FC_SELECT)) {
+ } else if (ff
+ && (ff->type == FC_CHECKBOX
+ || ff->type == FC_RADIO
+ || ff->type == FC_SELECT)) {
strcpy(cast_char s, "");
} else {
strcpy(cast_char s, "~");
}
}
put_chars(p, s, (int)strlen(cast_const_char s));
- if (ff && ff->type == FC_TEXTAREA) line_break(p);
- if (p->cx < par_format.leftmargin) p->cx = par_format.leftmargin;
+ if (ff && ff->type == FC_TEXTAREA)
+ line_break(p);
+ if (p->cx < par_format.leftmargin)
+ p->cx = par_format.leftmargin;
format_.link = fl;
format_.target = ft;
format_.image = fi;
@@ -725,8 +875,10 @@ static void put_chars(void *p_, unsigned char *c, int l)
last_target = stracpy(format_.target);
last_image = stracpy(format_.image);
last_form = format_.form;
- if (!p->data) goto no_l;
- if (!(link = new_link(p->data))) goto no_l;
+ if (!p->data)
+ goto no_l;
+ if (!(link = new_link(p->data)))
+ goto no_l;
link->num = p->link_num - 1;
link->pos = NULL;
if (!last_form) {
@@ -734,7 +886,17 @@ static void put_chars(void *p_, unsigned char *c, int l)
link->where = stracpy(last_link);
link->target = stracpy(last_target);
} else {
- link->type = last_form->type == FC_TEXT || last_form->type == FC_PASSWORD || last_form->type == FC_FILE_UPLOAD ? L_FIELD : last_form->type == FC_TEXTAREA ? L_AREA : last_form->type == FC_CHECKBOX || last_form->type == FC_RADIO ? L_CHECKBOX : last_form->type == FC_SELECT ? L_SELECT : L_BUTTON;
+ link->type =
+ last_form->type == FC_TEXT
+ || last_form->type == FC_PASSWORD
+ || last_form->type == FC_FILE_UPLOAD
+ ? L_FIELD
+ : last_form->type == FC_TEXTAREA ? L_AREA
+ : last_form->type == FC_CHECKBOX
+ || last_form->type == FC_RADIO
+ ? L_CHECKBOX
+ : last_form->type == FC_SELECT ? L_SELECT
+ : L_BUTTON;
link->form = last_form;
link->target = stracpy(last_form->target);
}
@@ -750,8 +912,9 @@ static void put_chars(void *p_, unsigned char *c, int l)
}
link->sel_color = get_attribute(fg, bg);
link->n = 0;
- set_link:
- if ((unsigned)link->n + (unsigned)ll > INT_MAX / sizeof(struct point))
+set_link:
+ if ((unsigned)link->n + (unsigned)ll
+ > INT_MAX / sizeof(struct point))
overalloc();
pt = xrealloc(link->pos, (link->n + ll) * sizeof(struct point));
link->pos = pt;
@@ -763,48 +926,61 @@ static void put_chars(void *p_, unsigned char *c, int l)
}
goto no_l;
- format_change:
- bg = find_nearest_color(&format_.bg, 8);
- fg = find_nearest_color(&format_.fg, 16);
- fg = fg_color(fg, bg);
- if (format_.attr & AT_ITALIC) fg = fg ^ 0x01;
- if (format_.attr & AT_UNDERLINE) fg = (fg ^ 0x04) | 0x08;
- if (format_.attr & AT_BOLD) fg = fg | 0x08;
- fg = fg_color(fg, bg);
- if (format_.attr & AT_GRAPHICS) bg = bg | 0x10;
- memcpy(&ta_cache, &format_, sizeof(struct text_attrib_beginning));
- fg_cache = fg; bg_cache = bg;
- goto end_format_change;
+format_change:
+ bg = find_nearest_color(&format_.bg, 8);
+ fg = find_nearest_color(&format_.fg, 16);
+ fg = fg_color(fg, bg);
+ if (format_.attr & AT_ITALIC)
+ fg = fg ^ 0x01;
+ if (format_.attr & AT_UNDERLINE)
+ fg = (fg ^ 0x04) | 0x08;
+ if (format_.attr & AT_BOLD)
+ fg = fg | 0x08;
+ fg = fg_color(fg, bg);
+ if (format_.attr & AT_GRAPHICS)
+ bg = bg | 0x10;
+ memcpy(&ta_cache, &format_, sizeof(struct text_attrib_beginning));
+ fg_cache = fg;
+ bg_cache = bg;
+ goto end_format_change;
}
-static void line_break(void *p_)
+static void
+line_break(void *p_)
{
struct part *p = p_;
struct tag *t = NULL;
struct list_head *lt;
- if (p->cx >= 0 && safe_add(p->cx, par_format.rightmargin) > p->x) p->x = p->cx + par_format.rightmargin;
+ if (p->cx >= 0 && safe_add(p->cx, par_format.rightmargin) > p->x)
+ p->x = p->cx + par_format.rightmargin;
if (nobreak) {
nobreak = 0;
p->cx = -1;
p->xa = 0;
return;
}
- if (!p->data) goto e;
+ if (!p->data)
+ goto e;
xpand_lines(p, safe_add(p->cy, 1));
- if (p->cx > par_format.leftmargin
- && LEN(p->cy) > p->cx - 1
- && POS(p->cx-1, p->cy).ch == ' ') {
- del_chars(p, p->cx-1, p->cy);
+ if (p->cx > par_format.leftmargin && LEN(p->cy) > p->cx - 1
+ && POS(p->cx - 1, p->cy).ch == ' ') {
+ del_chars(p, p->cx - 1, p->cy);
p->cx--;
}
- if (p->cx > 0) align_line(p, p->cy);
- if (p->data) foreachbackfrom(struct tag, t, lt, p->data->tags, last_tag_for_newline) {
- t->x = X(0);
- t->y = Y(p->cy + 1);
- }
- e:
- p->cy++; p->cx = -1; p->xa = 0;
- if (p->spl > d_opt->xw) p->spl = d_opt->xw;
+ if (p->cx > 0)
+ align_line(p, p->cy);
+ if (p->data)
+ foreachbackfrom (struct tag, t, lt, p->data->tags,
+ last_tag_for_newline) {
+ t->x = X(0);
+ t->y = Y(p->cy + 1);
+ }
+e:
+ p->cy++;
+ p->cx = -1;
+ p->xa = 0;
+ if (p->spl > d_opt->xw)
+ p->spl = d_opt->xw;
memset(p->spaces, 0, p->spl);
p->z_spaces = 0;
}
@@ -812,7 +988,8 @@ static void line_break(void *p_)
int g_ctrl_num;
/* SHADOWED IN g_html_form_control */
-static void html_form_control(struct part *p, struct form_control *fc)
+static void
+html_form_control(struct part *p, struct form_control *fc)
{
if (!p->data) {
add_to_list(p->uf, fc);
@@ -820,8 +997,11 @@ static void html_form_control(struct part *p, struct form_control *fc)
}
fc->g_ctrl_num = g_ctrl_num;
g_ctrl_num = safe_add(g_ctrl_num, 1);
- if (fc->type == FC_TEXT || fc->type == FC_PASSWORD || fc->type == FC_TEXTAREA) {
- unsigned char *dv = convert_string(convert_table, fc->default_value, (int)strlen(cast_const_char fc->default_value), d_opt);
+ if (fc->type == FC_TEXT || fc->type == FC_PASSWORD
+ || fc->type == FC_TEXTAREA) {
+ unsigned char *dv = convert_string(
+ convert_table, fc->default_value,
+ (int)strlen(cast_const_char fc->default_value), d_opt);
if (dv) {
free(fc->default_value);
fc->default_value = dv;
@@ -829,20 +1009,26 @@ static void html_form_control(struct part *p, struct form_control *fc)
}
if (fc->type == FC_TEXTAREA) {
unsigned char *p;
- for (p = fc->default_value; p[0]; p++) if (p[0] == '\r') {
- if (p[1] == '\n') {
- memmove(p, p + 1, strlen(cast_const_char p));
- p--;
- } else
- p[0] = '\n';
- }
+ for (p = fc->default_value; p[0]; p++)
+ if (p[0] == '\r') {
+ if (p[1] == '\n') {
+ memmove(p, p + 1,
+ strlen(cast_const_char p));
+ p--;
+ } else
+ p[0] = '\n';
+ }
}
add_to_list(p->data->forms, fc);
}
-static void add_frameset_entry(struct frameset_desc *fsd, struct frameset_desc *subframe, unsigned char *name, unsigned char *url, int marginwidth, int marginheight, unsigned char scrolling)
+static void
+add_frameset_entry(struct frameset_desc *fsd, struct frameset_desc *subframe,
+ unsigned char *name, unsigned char *url, int marginwidth,
+ int marginheight, unsigned char scrolling)
{
- if (fsd->yp >= fsd->y) return;
+ if (fsd->yp >= fsd->y)
+ return;
fsd->f[fsd->xp + fsd->yp * fsd->x].subframe = subframe;
fsd->f[fsd->xp + fsd->yp * fsd->x].name = stracpy(name);
fsd->f[fsd->xp + fsd->yp * fsd->x].url = stracpy(url);
@@ -855,7 +1041,8 @@ static void add_frameset_entry(struct frameset_desc *fsd, struct frameset_desc *
}
}
-struct frameset_desc *create_frameset(struct f_data *fda, struct frameset_param *fp)
+struct frameset_desc *
+create_frameset(struct f_data *fda, struct frameset_param *fp)
{
int i;
struct frameset_desc *fd;
@@ -863,9 +1050,16 @@ struct frameset_desc *create_frameset(struct f_data *fda, struct frameset_param
internal("zero size of frameset");
return NULL;
}
- if (fp->x && (unsigned)fp->x * (unsigned)fp->y / (unsigned)fp->x != (unsigned)fp->y) overalloc();
- if ((unsigned)fp->x * (unsigned)fp->y > (INT_MAX - sizeof(struct frameset_desc)) / sizeof(struct frame_desc)) overalloc();
- fd = mem_calloc(sizeof(struct frameset_desc) + fp->x * fp->y * sizeof(struct frame_desc));
+ if (fp->x
+ && (unsigned)fp->x * (unsigned)fp->y / (unsigned)fp->x
+ != (unsigned)fp->y)
+ overalloc();
+ if ((unsigned)fp->x * (unsigned)fp->y
+ > (INT_MAX - sizeof(struct frameset_desc))
+ / sizeof(struct frame_desc))
+ overalloc();
+ fd = mem_calloc(sizeof(struct frameset_desc)
+ + fp->x * fp->y * sizeof(struct frame_desc));
fd->n = fp->x * fp->y;
fd->x = fp->x;
fd->y = fp->y;
@@ -873,8 +1067,11 @@ struct frameset_desc *create_frameset(struct f_data *fda, struct frameset_param
fd->f[i].xw = fp->xw[i % fp->x];
fd->f[i].yw = fp->yw[i / fp->x];
}
- if (fp->parent) add_frameset_entry(fp->parent, fd, NULL, NULL, -1, -1, SCROLLING_AUTO);
- else if (!fda->frame_desc) fda->frame_desc = fd;
+ if (fp->parent)
+ add_frameset_entry(fp->parent, fd, NULL, NULL, -1, -1,
+ SCROLLING_AUTO);
+ else if (!fda->frame_desc)
+ fda->frame_desc = fd;
else {
free(fd);
fd = NULL;
@@ -882,29 +1079,39 @@ struct frameset_desc *create_frameset(struct f_data *fda, struct frameset_param
return fd;
}
-void create_frame(struct frame_param *fp)
+void
+create_frame(struct frame_param *fp)
{
- add_frameset_entry(fp->parent, NULL, fp->name, fp->url, fp->marginwidth, fp->marginheight, fp->scrolling);
+ add_frameset_entry(fp->parent, NULL, fp->name, fp->url, fp->marginwidth,
+ fp->marginheight, fp->scrolling);
}
-void process_script(struct f_data *f, unsigned char *t)
+void
+process_script(struct f_data *f, unsigned char *t)
{
}
-void set_base(struct f_data *f, unsigned char *t)
+void
+set_base(struct f_data *f, unsigned char *t)
{
}
-void html_process_refresh(struct f_data *f, unsigned char *url, int time)
+void
+html_process_refresh(struct f_data *f, unsigned char *url, int time)
{
- if (!f) return;
- if (f->refresh) return;
- if (!url) f->refresh = stracpy(f->rq->url);
- else f->refresh = join_urls(f->rq->url, url);
+ if (!f)
+ return;
+ if (f->refresh)
+ return;
+ if (!url)
+ f->refresh = stracpy(f->rq->url);
+ else
+ f->refresh = join_urls(f->rq->url, url);
f->refresh_seconds = time;
}
-static void *html_special(void *p_, int c, ...)
+static void *
+html_special(void *p_, int c, ...)
{
struct part *p = p_;
va_list l;
@@ -915,67 +1122,73 @@ static void *html_special(void *p_, int c, ...)
struct refresh_param *rp;
va_start(l, c);
switch (c) {
- case SP_TAG:
- t = va_arg(l, unsigned char *);
- va_end(l);
- html_tag(p->data, t, X(p->cx >= 0 ? p->cx : 0), Y(p->cy));
- break;
- case SP_CONTROL:
- fc = va_arg(l, struct form_control *);
- va_end(l);
- html_form_control(p, fc);
- break;
- case SP_TABLE:
- va_end(l);
- return convert_table;
- case SP_USED:
- va_end(l);
- return (void *)(long)!!p->data;
- case SP_FRAMESET:
- fsp = va_arg(l, struct frameset_param *);
- va_end(l);
- return create_frameset(p->data, fsp);
- case SP_FRAME:
- fp = va_arg(l, struct frame_param *);
- va_end(l);
- create_frame(fp);
- break;
- case SP_NOWRAP:
- nowrap = va_arg(l, int);
- va_end(l);
- break;
- case SP_SCRIPT:
- t = va_arg(l, unsigned char *);
- va_end(l);
- if (p->data) process_script(p->data, t);
- break;
- case SP_REFRESH:
- rp = va_arg(l, struct refresh_param *);
- va_end(l);
- html_process_refresh(p->data, rp->url, rp->time);
- break;
- case SP_SET_BASE:
- t = va_arg(l, unsigned char *);
- va_end(l);
- if (p->data) set_base(p->data, t);
- break;
- default:
- va_end(l);
- internal("html_special: unknown code %d", c);
+ case SP_TAG:
+ t = va_arg(l, unsigned char *);
+ va_end(l);
+ html_tag(p->data, t, X(p->cx >= 0 ? p->cx : 0), Y(p->cy));
+ break;
+ case SP_CONTROL:
+ fc = va_arg(l, struct form_control *);
+ va_end(l);
+ html_form_control(p, fc);
+ break;
+ case SP_TABLE:
+ va_end(l);
+ return convert_table;
+ case SP_USED:
+ va_end(l);
+ return (void *)(long)!!p->data;
+ case SP_FRAMESET:
+ fsp = va_arg(l, struct frameset_param *);
+ va_end(l);
+ return create_frameset(p->data, fsp);
+ case SP_FRAME:
+ fp = va_arg(l, struct frame_param *);
+ va_end(l);
+ create_frame(fp);
+ break;
+ case SP_NOWRAP:
+ nowrap = va_arg(l, int);
+ va_end(l);
+ break;
+ case SP_SCRIPT:
+ t = va_arg(l, unsigned char *);
+ va_end(l);
+ if (p->data)
+ process_script(p->data, t);
+ break;
+ case SP_REFRESH:
+ rp = va_arg(l, struct refresh_param *);
+ va_end(l);
+ html_process_refresh(p->data, rp->url, rp->time);
+ break;
+ case SP_SET_BASE:
+ t = va_arg(l, unsigned char *);
+ va_end(l);
+ if (p->data)
+ set_base(p->data, t);
+ break;
+ default:
+ va_end(l);
+ internal("html_special: unknown code %d", c);
}
return NULL;
}
-static void do_format(unsigned char *start, unsigned char *end, struct part *part, unsigned char *head)
+static void
+do_format(unsigned char *start, unsigned char *end, struct part *part,
+ unsigned char *head)
{
- pr(
- parse_html(start, end, put_chars, line_break, html_special, part, head);
- ) {};
+ pr(parse_html(start, end, put_chars, line_break, html_special, part,
+ head);){};
}
int margin;
-struct part *format_html_part(unsigned char *start, unsigned char *end, int align, int m, int width, struct f_data *data, int xs, int ys, unsigned char *head, int link_num)
+struct part *
+format_html_part(unsigned char *start, unsigned char *end, int align, int m,
+ int width, struct f_data *data, int xs, int ys,
+ unsigned char *head, int link_num)
{
struct part *p;
struct html_element *e;
@@ -992,8 +1205,10 @@ struct part *format_html_part(unsigned char *start, unsigned char *end, int alig
}
if (!data) {
- p = find_table_cache_entry(start, end, align, m, width, xs, link_num);
- if (p) return p;
+ p = find_table_cache_entry(start, end, align, m, width, xs,
+ link_num);
+ if (p)
+ return p;
}
if (ys < 0) {
internal("format_html_part: ys == %d", ys);
@@ -1021,9 +1236,12 @@ struct part *format_html_part(unsigned char *start, unsigned char *end, int alig
p = mem_calloc(sizeof(struct part));
/*p->x = p->y = 0;*/
p->data = data;
- p->xp = xs; p->yp = ys;
+ p->xp = xs;
+ p->yp = ys;
/*p->xmax = p->xa = 0;*/
- p->attribute = get_attribute(find_nearest_color(&format_.fg, 16), find_nearest_color(&par_format.bgcolor, 8));
+ p->attribute =
+ get_attribute(find_nearest_color(&format_.fg, 16),
+ find_nearest_color(&par_format.bgcolor, 8));
p->spaces = NULL;
/*p->z_spaces = 0;*/
/*p->spl = 0;*/
@@ -1045,7 +1263,8 @@ struct part *format_html_part(unsigned char *start, unsigned char *end, int alig
p->cx = -1;
p->cy = 0;
do_format(start, end, p, head);
- if (p->xmax < p->x) p->xmax = p->x;
+ if (p->xmax < p->x)
+ p->xmax = p->x;
if (align == AL_NO || align == AL_NO_BREAKABLE) {
if (p->cy > p->y)
p->y = p->cy;
@@ -1069,7 +1288,8 @@ struct part *format_html_part(unsigned char *start, unsigned char *end, int alig
struct node *n = list_struct(data->nodes.next, struct node);
n->yw = ys - n->y + p->y;
}
- foreach(struct form_control, fc, lfc, p->uf) destroy_fc(fc);
+ foreach (struct form_control, fc, lfc, p->uf)
+ destroy_fc(fc);
free_list(struct form_control, p->uf);
last_link_to_move = llm;
last_tag_to_move = ltm;
@@ -1079,12 +1299,15 @@ struct part *format_html_part(unsigned char *start, unsigned char *end, int alig
last_form = NULL;
if (table_level > 1 && !data) {
- add_table_cache_entry(start, end, align, m, width, xs, link_num, p);
+ add_table_cache_entry(start, end, align, m, width, xs, link_num,
+ p);
}
return p;
}
-static void push_base_format(unsigned char *url, struct document_options *opt, int frame, int implicit_pre_wrap)
+static void
+push_base_format(unsigned char *url, struct document_options *opt, int frame,
+ int implicit_pre_wrap)
{
struct html_element *e;
if (!list_empty(html_stack)) {
@@ -1102,11 +1325,15 @@ static void push_base_format(unsigned char *url, struct document_options *opt, i
memcpy(&format_.clink, &opt->default_link, sizeof(struct rgb));
format_.href_base = stracpy(url);
format_.target_base = stracpy(opt->framename);
- par_format.align = !(opt->plain & 1) ? AL_LEFT : !implicit_pre_wrap ? AL_NO : AL_NO_BREAKABLE;
+ par_format.align = !(opt->plain & 1) ? AL_LEFT
+ : !implicit_pre_wrap ? AL_NO
+ : AL_NO_BREAKABLE;
par_format.leftmargin = opt->plain & 1 ? 0 : opt->margin;
par_format.rightmargin = opt->plain & 1 ? 0 : opt->margin;
- if (frame && par_format.leftmargin) par_format.leftmargin = 1;
- if (frame && par_format.rightmargin) par_format.rightmargin = 1;
+ if (frame && par_format.leftmargin)
+ par_format.leftmargin = 1;
+ if (frame && par_format.rightmargin)
+ par_format.rightmargin = 1;
par_format.width = opt->xw;
par_format.list_level = par_format.list_number = 0;
par_format.dd_margin = opt->margin;
@@ -1114,17 +1341,22 @@ static void push_base_format(unsigned char *url, struct document_options *opt, i
memcpy(&par_format.bgcolor, &opt->default_bg, sizeof(struct rgb));
par_format.implicit_pre_wrap = implicit_pre_wrap;
html_top.invisible = 0;
- html_top.name = NULL; html_top.namelen = 0; html_top.options = NULL;
+ html_top.name = NULL;
+ html_top.namelen = 0;
+ html_top.options = NULL;
html_top.linebreak = 1;
html_top.dontkill = 1;
}
-struct conv_table *get_convert_table(unsigned char *head, int to, int def, int *frm, int *aa, int hard)
+struct conv_table *
+get_convert_table(unsigned char *head, int to, int def, int *frm, int *aa,
+ int hard)
{
int from = -1;
unsigned char *a, *b;
unsigned char *p = head;
- while (from == -1 && (a = parse_http_header(p, cast_uchar "Content-Type", &p))) {
+ while (from == -1
+ && (a = parse_http_header(p, cast_uchar "Content-Type", &p))) {
if ((b = parse_header_param(a, cast_uchar "charset", 0))) {
from = 0;
free(b);
@@ -1133,10 +1365,13 @@ struct conv_table *get_convert_table(unsigned char *head, int to, int def, int *
}
if (aa) {
*aa = from == -1;
- if (hard && !*aa) *aa = 2;
+ if (hard && !*aa)
+ *aa = 2;
}
- if (hard || from == -1) from = def;
- if (frm) *frm = from;
+ if (hard || from == -1)
+ from = def;
+ if (frm)
+ *frm = from;
return get_translation_table(from, to);
}
@@ -1146,7 +1381,9 @@ struct document_options *d_opt = &dd_opt;
struct f_data *current_f_data = NULL;
-void really_format_html(struct cache_entry *ce, unsigned char *start, unsigned char *end, struct f_data *screen, int frame)
+void
+really_format_html(struct cache_entry *ce, unsigned char *start,
+ unsigned char *end, struct f_data *screen, int frame)
{
unsigned char *url = ce->url;
unsigned char *head, *t;
@@ -1164,20 +1401,29 @@ void really_format_html(struct cache_entry *ce, unsigned char *start, unsigned c
eofff = end;
head = init_str();
hdl = 0;
- if (ce->head) add_to_str(&head, &hdl, ce->head);
- scan_http_equiv(start, end, &head, &hdl, &t, d_opt->plain ? NULL : &bg, d_opt->plain || d_opt->col < 2 ? NULL : &bgcolor, &implicit_pre_wrap);
- if (d_opt->break_long_lines) implicit_pre_wrap = 1;
- if (d_opt->plain) *t = 0;
+ if (ce->head)
+ add_to_str(&head, &hdl, ce->head);
+ scan_http_equiv(start, end, &head, &hdl, &t, d_opt->plain ? NULL : &bg,
+ d_opt->plain || d_opt->col < 2 ? NULL : &bgcolor,
+ &implicit_pre_wrap);
+ if (d_opt->break_long_lines)
+ implicit_pre_wrap = 1;
+ if (d_opt->plain)
+ *t = 0;
if (screen->opt.plain == 2) {
screen->cp = 0;
screen->ass = -1;
convert_table = get_translation_table(0, screen->opt.cp);
} else {
- convert_table = get_convert_table(head, screen->opt.cp, screen->opt.assume_cp, &screen->cp, &screen->ass, screen->opt.hard_assume);
+ convert_table = get_convert_table(
+ head, screen->opt.cp, screen->opt.assume_cp, &screen->cp,
+ &screen->ass, screen->opt.hard_assume);
}
screen->opt.real_cp = screen->cp;
- i = d_opt->plain; d_opt->plain = 0;
- screen->title = convert_string(convert_table, t, (int)strlen(cast_const_char t), d_opt);
+ i = d_opt->plain;
+ d_opt->plain = 0;
+ screen->title = convert_string(convert_table, t,
+ (int)strlen(cast_const_char t), d_opt);
d_opt->plain = i;
free(t);
push_base_format(url, &screen->opt, frame, implicit_pre_wrap);
@@ -1186,7 +1432,9 @@ void really_format_html(struct cache_entry *ce, unsigned char *start, unsigned c
last_form_tag = NULL;
last_form_attr = NULL;
last_input_tag = NULL;
- if ((rp = format_html_part(start, end, par_format.align, par_format.leftmargin, screen->opt.xw, screen, 0, 0, head, 1)))
+ if ((rp = format_html_part(start, end, par_format.align,
+ par_format.leftmargin, screen->opt.xw,
+ screen, 0, 0, head, 1)))
free(rp);
free(head);
free(bg);
@@ -1225,65 +1473,71 @@ void really_format_html(struct cache_entry *ce, unsigned char *start, unsigned c
d_opt = &dd_opt;
}
-int compare_opt(struct document_options *o1, struct document_options *o2)
+int
+compare_opt(struct document_options *o1, struct document_options *o2)
{
- if (o1->xw == o2->xw &&
- o1->yw == o2->yw &&
- o1->xp == o2->xp &&
- o1->yp == o2->yp &&
- o1->scrolling == o2->scrolling &&
- o1->col == o2->col &&
- o1->cp == o2->cp &&
- o1->assume_cp == o2->assume_cp &&
- o1->hard_assume == o2->hard_assume &&
- o1->tables == o2->tables &&
- o1->frames == o2->frames &&
- o1->break_long_lines == o2->break_long_lines &&
- o1->images == o2->images &&
- o1->image_names == o2->image_names &&
- o1->margin == o2->margin &&
- o1->plain == o2->plain &&
- o1->num_links == o2->num_links &&
- o1->table_order == o2->table_order &&
- o1->auto_refresh == o2->auto_refresh &&
- o1->font_size == o2->font_size &&
- o1->display_images == o2->display_images &&
- o1->image_scale == o2->image_scale &&
- o1->porn_enable == o2->porn_enable &&
- o1->gamma_stamp == o2->gamma_stamp &&
- !memcmp(&o1->default_fg, &o2->default_fg, sizeof(struct rgb)) &&
- !memcmp(&o1->default_bg, &o2->default_bg, sizeof(struct rgb)) &&
- !memcmp(&o1->default_link, &o2->default_link, sizeof(struct rgb)) &&
- ((o1->framename && o2->framename && !casestrcmp(o1->framename, o2->framename)) || (!o1->framename && !o2->framename))) return 0;
+ if (o1->xw == o2->xw && o1->yw == o2->yw && o1->xp == o2->xp
+ && o1->yp == o2->yp && o1->scrolling == o2->scrolling
+ && o1->col == o2->col && o1->cp == o2->cp
+ && o1->assume_cp == o2->assume_cp
+ && o1->hard_assume == o2->hard_assume && o1->tables == o2->tables
+ && o1->frames == o2->frames
+ && o1->break_long_lines == o2->break_long_lines
+ && o1->images == o2->images && o1->image_names == o2->image_names
+ && o1->margin == o2->margin && o1->plain == o2->plain
+ && o1->num_links == o2->num_links
+ && o1->table_order == o2->table_order
+ && o1->auto_refresh == o2->auto_refresh
+ && o1->font_size == o2->font_size
+ && o1->display_images == o2->display_images
+ && o1->image_scale == o2->image_scale
+ && o1->porn_enable == o2->porn_enable
+ && o1->gamma_stamp == o2->gamma_stamp
+ && !memcmp(&o1->default_fg, &o2->default_fg, sizeof(struct rgb))
+ && !memcmp(&o1->default_bg, &o2->default_bg, sizeof(struct rgb))
+ && !memcmp(&o1->default_link, &o2->default_link, sizeof(struct rgb))
+ && ((o1->framename && o2->framename
+ && !casestrcmp(o1->framename, o2->framename))
+ || (!o1->framename && !o2->framename)))
+ return 0;
return 1;
}
-void copy_opt(struct document_options *o1, struct document_options *o2)
+void
+copy_opt(struct document_options *o1, struct document_options *o2)
{
memcpy(o1, o2, sizeof(struct document_options));
o1->framename = stracpy(o2->framename);
}
-struct link *get_link_at_location(struct f_data *f, int x, int y)
+struct link *
+get_link_at_location(struct f_data *f, int x, int y)
{
struct link *l1, *l2, *l;
- if (y < 0 || y >= f->y) return NULL;
+ if (y < 0 || y >= f->y)
+ return NULL;
l1 = f->lines1[y];
l2 = f->lines2[y];
- if (!l1 || !l2) return NULL;
+ if (!l1 || !l2)
+ return NULL;
for (l = l1; l <= l2; l++) {
int i;
- for (i = 0; i < l->n; i++) if (l->pos[i].x == x && l->pos[i].y == y) return l;
+ for (i = 0; i < l->n; i++)
+ if (l->pos[i].x == x && l->pos[i].y == y)
+ return l;
}
return NULL;
}
-static int sort_srch(struct f_data *f)
+static int
+sort_srch(struct f_data *f)
{
int i;
int *min, *max;
- if ((unsigned)f->y > INT_MAX / sizeof(struct search *)) overalloc();
- if ((unsigned)f->y > INT_MAX / sizeof(int)) overalloc();
+ if ((unsigned)f->y > INT_MAX / sizeof(struct search *))
+ overalloc();
+ if ((unsigned)f->y > INT_MAX / sizeof(int))
+ overalloc();
f->slines1 = xmalloc(f->y * sizeof(int));
f->slines2 = xmalloc(f->y * sizeof(int));
min = xmalloc(f->y * sizeof(int));
@@ -1310,8 +1564,10 @@ static int sort_srch(struct f_data *f)
min[s->y] = s->x;
f->slines1[s->y] = s->idx;
}
- if (s->n == 1) xe = safe_add(s->x, s->co);
- else xe = safe_add(s->x, s->n);
+ if (s->n == 1)
+ xe = safe_add(s->x, s->co);
+ else
+ xe = safe_add(s->x, s->n);
if (xe > max[s->y]) {
max[s->y] = xe;
f->slines2[s->y] = s->idx + s->co - 1;
@@ -1322,7 +1578,8 @@ static int sort_srch(struct f_data *f)
return 0;
}
-static inline int is_spc(chr *cc)
+static inline int
+is_spc(chr *cc)
{
return cc->ch <= ' ' || cc->at & ATTR_FRAME;
}
@@ -1332,7 +1589,8 @@ static char_t srch_last_chr;
static int srch_last_x, srch_last_y;
static int srch_cont;
-static void get_srch_reset(void)
+static void
+get_srch_reset(void)
{
n_chr = n_pos = 0;
srch_last_chr = ' ';
@@ -1340,19 +1598,26 @@ static void get_srch_reset(void)
srch_cont = 0;
}
-static int add_srch_chr(struct f_data *f, unsigned c, int x, int y, int nn)
+static int
+add_srch_chr(struct f_data *f, unsigned c, int x, int y, int nn)
{
- if (c == ' ' && srch_last_chr == ' ') return 0;
+ if (c == ' ' && srch_last_chr == ' ')
+ return 0;
if (c == '_') {
struct link *l = get_link_at_location(f, x, y);
- if (l && (l->type == L_SELECT || l->type == L_FIELD || l->type == L_AREA))
+ if (l
+ && (l->type == L_SELECT || l->type == L_FIELD
+ || l->type == L_AREA))
return 0;
}
srch_last_chr = c;
- if (f->search_chr) f->search_chr[n_chr] = c;
- if (n_chr == INT_MAX) return -1;
+ if (f->search_chr)
+ f->search_chr[n_chr] = c;
+ if (n_chr == INT_MAX)
+ return -1;
n_chr++;
- if (srch_cont < 0xffff && x == srch_last_x + 1 && y == srch_last_y && nn == 1) {
+ if (srch_cont < 0xffff && x == srch_last_x + 1 && y == srch_last_y
+ && nn == 1) {
srch_cont++;
if (f->search_pos)
f->search_pos[n_pos - 1].co = (unsigned short)srch_cont;
@@ -1367,7 +1632,8 @@ static int add_srch_chr(struct f_data *f, unsigned c, int x, int y, int nn)
f->search_pos[n_pos].co = 1;
}
srch_cont = 1;
- if (n_pos == INT_MAX) return -1;
+ if (n_pos == INT_MAX)
+ return -1;
n_pos++;
}
if (nn == 1) {
@@ -1380,17 +1646,18 @@ static int add_srch_chr(struct f_data *f, unsigned c, int x, int y, int nn)
return 0;
}
-static int get_srch(struct f_data *f)
+static int
+get_srch(struct f_data *f)
{
struct node *n = NULL;
struct list_head *ln;
get_srch_reset();
-#define add_srch(c_, x_, y_, n_) \
-do { \
- if (add_srch_chr(f, c_, x_, y_, n_)) \
- return -1; \
-} while (0)
- foreachback(struct node, n, ln, f->nodes) {
+#define add_srch(c_, x_, y_, n_) \
+ do { \
+ if (add_srch_chr(f, c_, x_, y_, n_)) \
+ return -1; \
+ } while (0)
+ foreachback (struct node, n, ln, f->nodes) {
int x, y;
int xm = safe_add(n->x, n->xw), ym = safe_add(n->y, n->yw);
/*printf("%d %d - %d %d\n", n->x, n->y, xm, ym);
@@ -1399,8 +1666,10 @@ do { \
int ns = 1;
for (x = n->x; x < xm && x < f->data[y].l; x++) {
unsigned c = f->data[y].d[x].ch;
- if (is_spc(&f->data[y].d[x])) c = ' ';
- if (c == ' ' && ns) continue;
+ if (is_spc(&f->data[y].d[x]))
+ c = ' ';
+ if (c == ' ' && ns)
+ continue;
c = charset_upcase(c, f->opt.cp);
if (ns) {
add_srch(c, x, y, 1);
@@ -1411,16 +1680,21 @@ do { \
add_srch(c, x, y, 1);
} else {
int xx;
- for (xx = safe_add(x, 1); xx < xm && xx < f->data[y].l; xx++) if (!is_spc(&f->data[y].d[xx])) goto ja_uz_z_toho_programovani_asi_zcvoknu;
+ for (xx = safe_add(x, 1);
+ xx < xm && xx < f->data[y].l; xx++)
+ if (!is_spc(&f->data[y].d[xx]))
+ goto ja_uz_z_toho_programovani_asi_zcvoknu;
xx = x;
- ja_uz_z_toho_programovani_asi_zcvoknu:
- /* uz jsem zcvoknul, trpim poruchou osobnosti */
+ja_uz_z_toho_programovani_asi_zcvoknu:
+ /* uz jsem zcvoknul, trpim poruchou
+ * osobnosti */
add_srch(' ', x, y, xx - x);
- if (xx == x) goto uz_jsem_zcvoknul__jsem_psychopat__trpim_poruchou_osobnosti;
+ if (xx == x)
+ goto uz_jsem_zcvoknul__jsem_psychopat__trpim_poruchou_osobnosti;
x = xx - 1;
}
}
- uz_jsem_zcvoknul__jsem_psychopat__trpim_poruchou_osobnosti:
+uz_jsem_zcvoknul__jsem_psychopat__trpim_poruchou_osobnosti:
add_srch(' ', x, y, 0);
}
}
@@ -1428,21 +1702,30 @@ do { \
return 0;
}
-int get_search_data(struct f_data *f)
+int
+get_search_data(struct f_data *f)
{
- if (f->search_pos) return 0;
- if (get_srch(f)) return -1;
- if ((size_t)n_chr > ((size_t) - 1) / sizeof(char_t) || (size_t)n_pos > ((size_t) - 1) / sizeof(struct search)) return -1;
+ if (f->search_pos)
+ return 0;
+ if (get_srch(f))
+ return -1;
+ if ((size_t)n_chr > ((size_t)-1) / sizeof(char_t)
+ || (size_t)n_pos > ((size_t)-1) / sizeof(struct search))
+ return -1;
f->search_chr = xmalloc(n_chr * sizeof(char_t));
- if (!f->search_chr) return -1;
+ if (!f->search_chr)
+ return -1;
f->search_pos = xmalloc(n_pos * sizeof(struct search));
if (!f->search_pos) {
free(f->search_chr);
f->search_chr = NULL;
return -1;
}
- if (get_srch(f)) internal("get_search_data: get_srch should not fail second time");
- while (n_chr && f->search_chr[n_chr - 1] == ' ') n_chr--;
+ if (get_srch(f))
+ internal(
+ "get_search_data: get_srch should not fail second time");
+ while (n_chr && f->search_chr[n_chr - 1] == ' ')
+ n_chr--;
f->nsearch_chr = n_chr;
f->nsearch_pos = n_pos;
if (sort_srch(f)) {
diff --git a/html_tbl.c b/html_tbl.c
@@ -10,59 +10,71 @@
static void free_table_cache(void);
-#define RECT_BOUND_BITS 10 /* --- bound at 1024 pixels */
-
-#define AL_TR -1
-
-#define VAL_TR -1
-#define VAL_TOP 0
-#define VAL_MIDDLE 1
-#define VAL_BOTTOM 2
-
-#define W_AUTO -1
-#define W_REL -2
-
-#define F_VOID 0
-#define F_ABOVE 1
-#define F_BELOW 2
-#define F_HSIDES 3
-#define F_LHS 4
-#define F_RHS 8
-#define F_VSIDES 12
-#define F_BOX 15
-
-#define R_NONE 0
-#define R_ROWS 1
-#define R_COLS 2
-#define R_ALL 3
-#define R_GROUPS 4
-
-static void get_align(unsigned char *attr, int *a)
+#define RECT_BOUND_BITS 10 /* --- bound at 1024 pixels */
+
+#define AL_TR -1
+
+#define VAL_TR -1
+#define VAL_TOP 0
+#define VAL_MIDDLE 1
+#define VAL_BOTTOM 2
+
+#define W_AUTO -1
+#define W_REL -2
+
+#define F_VOID 0
+#define F_ABOVE 1
+#define F_BELOW 2
+#define F_HSIDES 3
+#define F_LHS 4
+#define F_RHS 8
+#define F_VSIDES 12
+#define F_BOX 15
+
+#define R_NONE 0
+#define R_ROWS 1
+#define R_COLS 2
+#define R_ALL 3
+#define R_GROUPS 4
+
+static void
+get_align(unsigned char *attr, int *a)
{
unsigned char *al;
if ((al = get_attr_val(attr, cast_uchar "align"))) {
- if (!(casestrcmp(al, cast_uchar "left"))) *a = AL_LEFT;
- if (!(casestrcmp(al, cast_uchar "right"))) *a = AL_RIGHT;
- if (!(casestrcmp(al, cast_uchar "center"))) *a = AL_CENTER;
- if (!(casestrcmp(al, cast_uchar "justify"))) *a = AL_BLOCK;
- if (!(casestrcmp(al, cast_uchar "char"))) *a = AL_RIGHT; /* NOT IMPLEMENTED */
+ if (!(casestrcmp(al, cast_uchar "left")))
+ *a = AL_LEFT;
+ if (!(casestrcmp(al, cast_uchar "right")))
+ *a = AL_RIGHT;
+ if (!(casestrcmp(al, cast_uchar "center")))
+ *a = AL_CENTER;
+ if (!(casestrcmp(al, cast_uchar "justify")))
+ *a = AL_BLOCK;
+ if (!(casestrcmp(al, cast_uchar "char")))
+ *a = AL_RIGHT; /* NOT IMPLEMENTED */
free(al);
}
}
-static void get_valign(unsigned char *attr, int *a)
+static void
+get_valign(unsigned char *attr, int *a)
{
unsigned char *al;
if ((al = get_attr_val(attr, cast_uchar "valign"))) {
- if (!(casestrcmp(al, cast_uchar "top"))) *a = VAL_TOP;
- if (!(casestrcmp(al, cast_uchar "middle"))) *a = VAL_MIDDLE;
- if (!(casestrcmp(al, cast_uchar "bottom"))) *a = VAL_BOTTOM;
- if (!(casestrcmp(al, cast_uchar "baseline"))) *a = VAL_TOP; /* NOT IMPLEMENTED */
+ if (!(casestrcmp(al, cast_uchar "top")))
+ *a = VAL_TOP;
+ if (!(casestrcmp(al, cast_uchar "middle")))
+ *a = VAL_MIDDLE;
+ if (!(casestrcmp(al, cast_uchar "bottom")))
+ *a = VAL_BOTTOM;
+ if (!(casestrcmp(al, cast_uchar "baseline")))
+ *a = VAL_TOP; /* NOT IMPLEMENTED */
free(al);
}
}
-static void get_c_width(unsigned char *attr, int *w, int sh)
+static void
+get_c_width(unsigned char *attr, int *w, int sh)
{
unsigned char *al;
if ((al = get_attr_val(attr, cast_uchar "width"))) {
@@ -71,17 +83,19 @@ static void get_c_width(unsigned char *attr, int *w, int sh)
unsigned long n;
al[strlen(cast_const_char al) - 1] = 0;
n = strtoul(cast_const_char al, &end, 10);
- if (n < 10000 && !*end) *w = W_REL - (int)n;
+ if (n < 10000 && !*end)
+ *w = W_REL - (int)n;
} else {
int p = get_width(attr, cast_uchar "width", sh);
- if (p >= 0) *w = p;
+ if (p >= 0)
+ *w = p;
}
free(al);
}
}
-#define INIT_X 8
-#define INIT_Y 8
+#define INIT_X 8
+#define INIT_Y 8
struct table_cell {
int used;
@@ -135,27 +149,27 @@ struct table {
struct rgb bgcolor;
};
-
#define CELL(t, x, y) (&(t)->cells[(y) * (t)->rx + (x)])
static unsigned char frame_table[81] = {
- 0x00, 0xb3, 0xba, 0xc4, 0xc0, 0xd3, 0xcd, 0xd4, 0xc8,
- 0xc4, 0xd9, 0xbd, 0xc4, 0xc1, 0xd0, 0xcd, 0xd4, 0xc8,
- 0xcd, 0xbe, 0xbc, 0xcd, 0xbe, 0xbc, 0xcd, 0xcf, 0xca,
+ 0x00, 0xb3, 0xba, 0xc4, 0xc0, 0xd3, 0xcd, 0xd4, 0xc8,
+ 0xc4, 0xd9, 0xbd, 0xc4, 0xc1, 0xd0, 0xcd, 0xd4, 0xc8,
+ 0xcd, 0xbe, 0xbc, 0xcd, 0xbe, 0xbc, 0xcd, 0xcf, 0xca,
- 0xb3, 0xb3, 0xba, 0xda, 0xc3, 0xd3, 0xd5, 0xc6, 0xc8,
- 0xbf, 0xb4, 0xbd, 0xc2, 0xc5, 0xd0, 0xd5, 0xc6, 0xc8,
- 0xb8, 0xb5, 0xbc, 0xb8, 0xb5, 0xbc, 0xd1, 0xd8, 0xca,
+ 0xb3, 0xb3, 0xba, 0xda, 0xc3, 0xd3, 0xd5, 0xc6, 0xc8,
+ 0xbf, 0xb4, 0xbd, 0xc2, 0xc5, 0xd0, 0xd5, 0xc6, 0xc8,
+ 0xb8, 0xb5, 0xbc, 0xb8, 0xb5, 0xbc, 0xd1, 0xd8, 0xca,
- 0xba, 0xba, 0xba, 0xd6, 0xd6, 0xc7, 0xc9, 0xc9, 0xcc,
- 0xb7, 0xb7, 0xb6, 0xd2, 0xd2, 0xd7, 0xc9, 0xc9, 0xcc,
- 0xbb, 0xbb, 0xb9, 0xbb, 0xbb, 0xb9, 0xcb, 0xcb, 0xce,
+ 0xba, 0xba, 0xba, 0xd6, 0xd6, 0xc7, 0xc9, 0xc9, 0xcc,
+ 0xb7, 0xb7, 0xb6, 0xd2, 0xd2, 0xd7, 0xc9, 0xc9, 0xcc,
+ 0xbb, 0xbb, 0xb9, 0xbb, 0xbb, 0xb9, 0xcb, 0xcb, 0xce,
};
static unsigned char hline_table[3] = { 0x20, 0xc4, 0xcd };
static unsigned char vline_table[3] = { 0x20, 0xb3, 0xba };
-static struct table *new_table(void)
+static struct table *
+new_table(void)
{
struct table *t;
t = mem_calloc(sizeof(struct table));
@@ -173,13 +187,15 @@ static struct table *new_table(void)
return t;
}
-static void free_table(struct table *t)
+static void
+free_table(struct table *t)
{
int i, j;
- for (j = 0; j < t->y; j++) for (i = 0; i < t->x; i++) {
- struct table_cell *c = CELL(t, i, j);
- free(c->tag);
- }
+ for (j = 0; j < t->y; j++)
+ for (i = 0; i < t->x; i++) {
+ struct table_cell *c = CELL(t, i, j);
+ free(c->tag);
+ }
free(t->bordercolor);
free(t->min_c);
free(t->max_c);
@@ -191,47 +207,60 @@ static void free_table(struct table *t)
free(t);
}
-static void expand_cells(struct table *t, int x, int y)
+static void
+expand_cells(struct table *t, int x, int y)
{
int i, j;
if (x >= t->x) {
if (t->x) {
- for (i = 0; i < t->y; i++) if (CELL(t, t->x - 1, i)->colspan == -1) {
- for (j = t->x; j <= x; j++) {
- CELL(t, j, i)->used = 1;
- CELL(t, j, i)->spanned = 1;
- CELL(t, j, i)->rowspan = CELL(t, t->x - 1, i)->rowspan;
- CELL(t, j, i)->colspan = -1;
- CELL(t, j, i)->mx = CELL(t, t->x - 1, i)->mx;
- CELL(t, j, i)->my = CELL(t, t->x - 1, i)->my;
+ for (i = 0; i < t->y; i++)
+ if (CELL(t, t->x - 1, i)->colspan == -1) {
+ for (j = t->x; j <= x; j++) {
+ CELL(t, j, i)->used = 1;
+ CELL(t, j, i)->spanned = 1;
+ CELL(t, j, i)->rowspan =
+ CELL(t, t->x - 1, i)
+ ->rowspan;
+ CELL(t, j, i)->colspan = -1;
+ CELL(t, j, i)->mx =
+ CELL(t, t->x - 1, i)->mx;
+ CELL(t, j, i)->my =
+ CELL(t, t->x - 1, i)->my;
+ }
}
- }
}
t->x = safe_add(x, 1);
}
if (y >= t->y) {
if (t->y) {
- for (i = 0; i < t->x; i++) if (CELL(t, i, t->y - 1)->rowspan == -1) {
- for (j = t->y; j <= y; j++) {
- CELL(t, i, j)->used = 1;
- CELL(t, i, j)->spanned = 1;
- CELL(t, i, j)->rowspan = -1;
- CELL(t, i, j)->colspan = CELL(t, i, t->y - 1)->colspan;
- CELL(t, i, j)->mx = CELL(t, i, t->y - 1)->mx;
- CELL(t, i, j)->my = CELL(t, i, t->y - 1)->my;
+ for (i = 0; i < t->x; i++)
+ if (CELL(t, i, t->y - 1)->rowspan == -1) {
+ for (j = t->y; j <= y; j++) {
+ CELL(t, i, j)->used = 1;
+ CELL(t, i, j)->spanned = 1;
+ CELL(t, i, j)->rowspan = -1;
+ CELL(t, i, j)->colspan =
+ CELL(t, i, t->y - 1)
+ ->colspan;
+ CELL(t, i, j)->mx =
+ CELL(t, i, t->y - 1)->mx;
+ CELL(t, i, j)->my =
+ CELL(t, i, t->y - 1)->my;
+ }
}
- }
}
t->y = safe_add(y, 1);
}
}
-static struct table_cell *new_cell(struct table *t, int x, int y)
+static struct table_cell *
+new_cell(struct table *t, int x, int y)
{
struct table nt;
int i, j;
- if (x < t->x && y < t->y) goto ret;
- rep:
+ if (x < t->x && y < t->y)
+ goto ret;
+rep:
if (x < t->rx && y < t->ry) {
expand_cells(t, x, y);
goto ret;
@@ -239,36 +268,46 @@ static struct table_cell *new_cell(struct table *t, int x, int y)
nt.rx = t->rx;
nt.ry = t->ry;
while (x >= nt.rx) {
- if ((unsigned)nt.rx > INT_MAX / 2) overalloc();
+ if ((unsigned)nt.rx > INT_MAX / 2)
+ overalloc();
nt.rx *= 2;
}
while (y >= nt.ry) {
- if ((unsigned)nt.ry > INT_MAX / 2) overalloc();
+ if ((unsigned)nt.ry > INT_MAX / 2)
+ overalloc();
nt.ry *= 2;
}
- if ((unsigned)nt.rx * (unsigned)nt.ry / (unsigned)nt.rx != (unsigned)nt.ry) overalloc();
- if ((unsigned)nt.rx * (unsigned)nt.ry > INT_MAX / sizeof(struct table_cell)) overalloc();
+ if ((unsigned)nt.rx * (unsigned)nt.ry / (unsigned)nt.rx
+ != (unsigned)nt.ry)
+ overalloc();
+ if ((unsigned)nt.rx * (unsigned)nt.ry
+ > INT_MAX / sizeof(struct table_cell))
+ overalloc();
nt.cells = mem_calloc(nt.rx * nt.ry * sizeof(struct table_cell));
for (i = 0; i < t->x; i++)
for (j = 0; j < t->y; j++)
- memcpy(CELL(&nt, i, j), CELL(t, i, j), sizeof(struct table_cell));
+ memcpy(CELL(&nt, i, j), CELL(t, i, j),
+ sizeof(struct table_cell));
free(t->cells);
t->cells = nt.cells;
t->rx = nt.rx;
t->ry = nt.ry;
goto rep;
- ret:
+ret:
return CELL(t, x, y);
}
-static void new_columns(struct table *t, int span, int width, int align, int valign, int group)
+static void
+new_columns(struct table *t, int span, int width, int align, int valign,
+ int group)
{
if (safe_add(t->c, span) > t->rc) {
int n = t->rc;
struct table_column *nc;
while (t->c + span > n) {
- if ((unsigned)n > INT_MAX / 2) overalloc();
+ if ((unsigned)n > INT_MAX / 2)
+ overalloc();
n *= 2;
}
if ((unsigned)n > INT_MAX / sizeof(struct table_column))
@@ -286,14 +325,16 @@ static void new_columns(struct table *t, int span, int width, int align, int val
}
}
-static void set_td_width(struct table *t, int x, int width, int f)
+static void
+set_td_width(struct table *t, int x, int width, int f)
{
if (x >= t->xc) {
int n = t->xc ? t->xc : 1;
int i;
int *nc;
while (x >= n) {
- if ((unsigned)n > INT_MAX / 2) overalloc();
+ if ((unsigned)n > INT_MAX / 2)
+ overalloc();
n *= 2;
}
if ((unsigned)n > INT_MAX / sizeof(int))
@@ -305,32 +346,44 @@ static void set_td_width(struct table *t, int x, int width, int f)
t->xcols = nc;
}
if (t->xcols[x] == W_AUTO || f) {
- set:
+set:
t->xcols[x] = width;
return;
}
- if (width == W_AUTO) return;
- if (width < 0 && t->xcols[x] >= 0) goto set;
- if (width >= 0 && t->xcols[x] < 0) return;
+ if (width == W_AUTO)
+ return;
+ if (width < 0 && t->xcols[x] >= 0)
+ goto set;
+ if (width >= 0 && t->xcols[x] < 0)
+ return;
t->xcols[x] = safe_add(t->xcols[x], width) / 2;
}
-unsigned char *skip_element(unsigned char *html, unsigned char *eof, unsigned char *what, int sub)
+unsigned char *
+skip_element(unsigned char *html, unsigned char *eof, unsigned char *what,
+ int sub)
{
int l = (int)strlen(cast_const_char what);
int level = 1;
unsigned char *name;
int namelen;
- r:
- while (html < eof && (*html != '<')) rr:html++;
+r:
+ while (html < eof && (*html != '<'))
+rr:
+ html++;
if (eof - html >= 2 && (html[1] == '!' || html[1] == '?')) {
html = skip_comment(html, eof);
goto r;
}
- if (html >= eof) return eof;
- if (parse_element(html, eof, &name, &namelen, NULL, &html)) goto rr;
- if (namelen == l && !casecmp(name, what, l) && sub) level = safe_add(level, 1);
- if (namelen == l + 1 && name[0] == '/' && !casecmp(name + 1, what, l)) if (!--level) return html;
+ if (html >= eof)
+ return eof;
+ if (parse_element(html, eof, &name, &namelen, NULL, &html))
+ goto rr;
+ if (namelen == l && !casecmp(name, what, l) && sub)
+ level = safe_add(level, 1);
+ if (namelen == l + 1 && name[0] == '/' && !casecmp(name + 1, what, l))
+ if (!--level)
+ return html;
goto r;
}
@@ -338,12 +391,17 @@ struct s_e {
unsigned char *s, *e;
};
-static int default_line_align(void)
+static int
+default_line_align(void)
{
- return par_format.align == AL_NO || par_format.align == AL_NO_BREAKABLE ? par_format.align : AL_LEFT;
+ return par_format.align == AL_NO || par_format.align == AL_NO_BREAKABLE
+ ? par_format.align
+ : AL_LEFT;
}
-static struct table *parse_table(unsigned char *html, unsigned char *eof, unsigned char **end, struct rgb *bgcolor, int sh, struct s_e **bad_html, int *bhp)
+static struct table *
+parse_table(unsigned char *html, unsigned char *eof, unsigned char **end,
+ struct rgb *bgcolor, int sh, struct s_e **bad_html, int *bhp)
{
int qqq;
struct table *t;
@@ -368,23 +426,27 @@ static struct table *parse_table(unsigned char *html, unsigned char *eof, unsign
}
t = new_table();
memcpy(&t->bgcolor, bgcolor, sizeof(struct rgb));
- se:
+se:
en = html;
- see:
+see:
html = en;
if (bad_html && !p && !lbhp) {
- if (!(*bhp & (ALLOC_GR-1))) {
- if ((unsigned)*bhp > INT_MAX / sizeof(struct s_e) - ALLOC_GR)
+ if (!(*bhp & (ALLOC_GR - 1))) {
+ if ((unsigned)*bhp
+ > INT_MAX / sizeof(struct s_e) - ALLOC_GR)
overalloc();
- *bad_html = xrealloc(*bad_html,
- (*bhp + ALLOC_GR) * sizeof(struct s_e));
+ *bad_html = xrealloc(
+ *bad_html, (*bhp + ALLOC_GR) * sizeof(struct s_e));
}
lbhp = (*bad_html)[(*bhp)++].s = html;
}
- while (html < eof && *html != '<') html++;
+ while (html < eof && *html != '<')
+ html++;
if (html >= eof) {
- if (p) CELL(t, x, y)->end = html;
- if (lbhp) (*bad_html)[*bhp-1].e = html;
+ if (p)
+ CELL(t, x, y)->end = html;
+ if (lbhp)
+ (*bad_html)[*bhp - 1].e = html;
goto scan_done;
}
if (eof - html >= 2 && (html[1] == '!' || html[1] == '?')) {
@@ -406,15 +468,19 @@ static struct table *parse_table(unsigned char *html, unsigned char *eof, unsign
}
}
if (t_namelen == 6 && !casecmp(t_name, cast_uchar "/TABLE", 6)) {
- if (c_span) new_columns(t, c_span, c_width, c_al, c_val, 1);
- if (p) CELL(t, x, y)->end = html;
- if (lbhp) (*bad_html)[*bhp-1].e = html;
+ if (c_span)
+ new_columns(t, c_span, c_width, c_al, c_val, 1);
+ if (p)
+ CELL(t, x, y)->end = html;
+ if (lbhp)
+ (*bad_html)[*bhp - 1].e = html;
goto scan_done;
}
if (t_namelen == 8 && !casecmp(t_name, cast_uchar "COLGROUP", 8)) {
- if (c_span) new_columns(t, c_span, c_width, c_al, c_val, 1);
+ if (c_span)
+ new_columns(t, c_span, c_width, c_al, c_val, 1);
if (lbhp) {
- (*bad_html)[*bhp-1].e = html;
+ (*bad_html)[*bhp - 1].e = html;
lbhp = NULL;
}
c_al = AL_TR;
@@ -423,13 +489,15 @@ static struct table *parse_table(unsigned char *html, unsigned char *eof, unsign
get_align(t_attr, &c_al);
get_valign(t_attr, &c_val);
get_c_width(t_attr, &c_width, sh);
- if ((c_span = get_num(t_attr, cast_uchar "span")) == -1) c_span = 1;
+ if ((c_span = get_num(t_attr, cast_uchar "span")) == -1)
+ c_span = 1;
goto see;
}
if (t_namelen == 9 && !casecmp(t_name, cast_uchar "/COLGROUP", 9)) {
- if (c_span) new_columns(t, c_span, c_width, c_al, c_val, 1);
+ if (c_span)
+ new_columns(t, c_span, c_width, c_al, c_val, 1);
if (lbhp) {
- (*bad_html)[*bhp-1].e = html;
+ (*bad_html)[*bhp - 1].e = html;
lbhp = NULL;
}
c_span = 0;
@@ -441,10 +509,11 @@ static struct table *parse_table(unsigned char *html, unsigned char *eof, unsign
if (t_namelen == 3 && !casecmp(t_name, cast_uchar "COL", 3)) {
int sp, wi, al, val;
if (lbhp) {
- (*bad_html)[*bhp-1].e = html;
+ (*bad_html)[*bhp - 1].e = html;
lbhp = NULL;
}
- if ((sp = get_num(t_attr, cast_uchar "span")) == -1) sp = 1;
+ if ((sp = get_num(t_attr, cast_uchar "span")) == -1)
+ sp = 1;
wi = c_width;
al = c_al;
val = c_val;
@@ -455,28 +524,34 @@ static struct table *parse_table(unsigned char *html, unsigned char *eof, unsign
c_span = 0;
goto see;
}
- if (t_namelen == 3 && (!casecmp(t_name, cast_uchar "/TR", 3) || !casecmp(t_name, cast_uchar "/TD", 3) || !casecmp(t_name, cast_uchar "/TH", 3))) {
- if (c_span) new_columns(t, c_span, c_width, c_al, c_val, 1);
+ if (t_namelen == 3
+ && (!casecmp(t_name, cast_uchar "/TR", 3)
+ || !casecmp(t_name, cast_uchar "/TD", 3)
+ || !casecmp(t_name, cast_uchar "/TH", 3))) {
+ if (c_span)
+ new_columns(t, c_span, c_width, c_al, c_val, 1);
if (p) {
CELL(t, x, y)->end = html;
p = 0;
}
if (lbhp) {
- (*bad_html)[*bhp-1].e = html;
+ (*bad_html)[*bhp - 1].e = html;
lbhp = NULL;
}
}
if (t_namelen == 2 && !casecmp(t_name, cast_uchar "TR", 2)) {
- if (c_span) new_columns(t, c_span, c_width, c_al, c_val, 1);
+ if (c_span)
+ new_columns(t, c_span, c_width, c_al, c_val, 1);
if (p) {
CELL(t, x, y)->end = html;
p = 0;
}
if (lbhp) {
- (*bad_html)[*bhp-1].e = html;
+ (*bad_html)[*bhp - 1].e = html;
lbhp = NULL;
}
- if (group) group--;
+ if (group)
+ group--;
l_al = default_line_align();
l_val = VAL_MIDDLE;
memcpy(&l_col, bgcolor, sizeof(struct rgb));
@@ -487,18 +562,26 @@ static struct table *parse_table(unsigned char *html, unsigned char *eof, unsign
x = 0;
goto see;
}
- if (t_namelen == 5 && ((!casecmp(t_name, cast_uchar "THEAD", 5)) || (!casecmp(t_name, cast_uchar "TBODY", 5)) || (!casecmp(t_name, cast_uchar "TFOOT", 5)))) {
- if (c_span) new_columns(t, c_span, c_width, c_al, c_val, 1);
+ if (t_namelen == 5
+ && ((!casecmp(t_name, cast_uchar "THEAD", 5))
+ || (!casecmp(t_name, cast_uchar "TBODY", 5))
+ || (!casecmp(t_name, cast_uchar "TFOOT", 5)))) {
+ if (c_span)
+ new_columns(t, c_span, c_width, c_al, c_val, 1);
if (lbhp) {
- (*bad_html)[*bhp-1].e = html;
+ (*bad_html)[*bhp - 1].e = html;
lbhp = NULL;
}
group = 2;
}
- if (t_namelen != 2 || (casecmp(t_name, cast_uchar "TD", 2) && casecmp(t_name, cast_uchar "TH", 2))) goto see;
- if (c_span) new_columns(t, c_span, c_width, c_al, c_val, 1);
+ if (t_namelen != 2
+ || (casecmp(t_name, cast_uchar "TD", 2)
+ && casecmp(t_name, cast_uchar "TH", 2)))
+ goto see;
+ if (c_span)
+ new_columns(t, c_span, c_width, c_al, c_val, 1);
if (lbhp) {
- (*bad_html)[*bhp-1].e = html;
+ (*bad_html)[*bhp - 1].e = html;
lbhp = NULL;
}
if (p) {
@@ -509,10 +592,12 @@ static struct table *parse_table(unsigned char *html, unsigned char *eof, unsign
y = 0;
x = 0;
}
- nc:
- if (!(cell = new_cell(t, x, y))) goto see;
+nc:
+ if (!(cell = new_cell(t, x, y)))
+ goto see;
if (cell->used) {
- if (cell->colspan == -1) goto see;
+ if (cell->colspan == -1)
+ goto see;
x++;
goto nc;
}
@@ -534,10 +619,13 @@ static struct table *parse_table(unsigned char *html, unsigned char *eof, unsign
no_th:;
}
#endif
- if (group == 1) cell->group = 1;
+ if (group == 1)
+ cell->group = 1;
if (x < t->c) {
- if (t->cols[x].align != AL_TR) cell->align = t->cols[x].align;
- if (t->cols[x].valign != VAL_TR) cell->valign = t->cols[x].valign;
+ if (t->cols[x].align != AL_TR)
+ cell->align = t->cols[x].align;
+ if (t->cols[x].valign != VAL_TR)
+ cell->valign = t->cols[x].valign;
}
memcpy(&cell->bgcolor, &l_col, sizeof(struct rgb));
get_align(t_attr, &cell->align);
@@ -546,36 +634,50 @@ static struct table *parse_table(unsigned char *html, unsigned char *eof, unsign
if ((a = get_attr_val(t_attr, cast_uchar "id")))
cell->tag = a;
if ((a = get_attr_val(t_attr, cast_uchar "class"))) {
- if (strstr(cast_const_char a, "blob-code-inner") || /* github hack */
- !strcmp(cast_const_char a, "changelog") ||
- !strcmp(cast_const_char a, "vc_file_line_text") || /* https://gcc.gnu.org/viewcvs/gcc/trunk/gcc/opts.c?view=markup */
- !strcmp(cast_const_char a, "FileContents-lineContents") || /* https://android.googlesource.com/ */
+ if (strstr(cast_const_char a, "blob-code-inner")
+ || /* github hack */
+ !strcmp(cast_const_char a, "changelog")
+ || !strcmp(cast_const_char a, "vc_file_line_text")
+ || /* https://gcc.gnu.org/viewcvs/gcc/trunk/gcc/opts.c?view=markup
+ */
+ !strcmp(cast_const_char a, "FileContents-lineContents")
+ || /* https://android.googlesource.com/ */
0) {
- cell->align = !par_format.implicit_pre_wrap ? AL_NO : AL_NO_BREAKABLE;
+ cell->align = !par_format.implicit_pre_wrap
+ ? AL_NO
+ : AL_NO_BREAKABLE;
}
free(a);
}
- if ((csp = get_num(t_attr, cast_uchar "colspan")) == -1) csp = 1;
- if (!csp) csp = -1;
- if ((rsp = get_num(t_attr, cast_uchar "rowspan")) == -1) rsp = 1;
- if (!rsp) rsp = -1;
+ if ((csp = get_num(t_attr, cast_uchar "colspan")) == -1)
+ csp = 1;
+ if (!csp)
+ csp = -1;
+ if ((rsp = get_num(t_attr, cast_uchar "rowspan")) == -1)
+ rsp = 1;
+ if (!rsp)
+ rsp = -1;
if (csp >= 0 && rsp >= 0 && csp * rsp > 100000) {
- if (csp > 10) csp = -1;
- if (rsp > 10) rsp = -1;
+ if (csp > 10)
+ csp = -1;
+ if (rsp > 10)
+ rsp = -1;
}
cell->colspan = csp;
cell->rowspan = rsp;
if (csp == 1) {
int w = W_AUTO;
get_c_width(t_attr, &w, sh);
- if (w != W_AUTO) set_td_width(t, x, w, 0);
+ if (w != W_AUTO)
+ set_td_width(t, x, w, 0);
}
qqq = t->x;
for (i = 1; csp != -1 ? i < csp : x + i < qqq; i++) {
struct table_cell *sc;
if (!(sc = new_cell(t, x + i, y)) || sc->used) {
csp = i;
- for (k = 0; k < i; k++) CELL(t, x + k, y)->colspan = csp;
+ for (k = 0; k < i; k++)
+ CELL(t, x + k, y)->colspan = csp;
break;
}
sc->used = sc->spanned = 1;
@@ -590,9 +692,15 @@ static struct table *parse_table(unsigned char *html, unsigned char *eof, unsign
struct table_cell *sc;
if (!(sc = new_cell(t, x + k, y + j)) || sc->used) {
int l, m;
- if (sc->mx == x && sc->my == y) continue;
- for (l = 0; l < k; l++) memset(CELL(t, x + l, y + j), 0, sizeof(struct table_cell));
- for (l = 0; l < i; l++) for (m = 0; m < j; m++) CELL(t, x + l, y + m)->rowspan = j;
+ if (sc->mx == x && sc->my == y)
+ continue;
+ for (l = 0; l < k; l++)
+ memset(CELL(t, x + l, y + j), 0,
+ sizeof(struct table_cell));
+ for (l = 0; l < i; l++)
+ for (m = 0; m < j; m++)
+ CELL(t, x + l, y + m)->rowspan =
+ j;
goto brk;
}
sc->used = sc->spanned = 1;
@@ -602,30 +710,38 @@ static struct table *parse_table(unsigned char *html, unsigned char *eof, unsign
sc->my = y;
}
}
- brk:
+brk:
goto see;
- scan_done:
+scan_done:
*end = html;
- for (x = 0; x < t->x; x++) for (y = 0; y < t->y; y++) {
- struct table_cell *c = CELL(t, x, y);
- if (!c->spanned) {
- if (c->colspan == -1) c->colspan = t->x - x;
- if (c->rowspan == -1) c->rowspan = t->y - y;
+ for (x = 0; x < t->x; x++)
+ for (y = 0; y < t->y; y++) {
+ struct table_cell *c = CELL(t, x, y);
+ if (!c->spanned) {
+ if (c->colspan == -1)
+ c->colspan = t->x - x;
+ if (c->rowspan == -1)
+ c->rowspan = t->y - y;
+ }
}
- }
- if ((unsigned)t->y > INT_MAX / sizeof(int)) overalloc();
+ if ((unsigned)t->y > INT_MAX / sizeof(int))
+ overalloc();
t->r_heights = mem_calloc(t->y * sizeof(int));
- for (x = 0; x < t->c; x++) if (t->cols[x].width != W_AUTO) set_td_width(t, x, t->cols[x].width, 1);
+ for (x = 0; x < t->c; x++)
+ if (t->cols[x].width != W_AUTO)
+ set_td_width(t, x, t->cols[x].width, 1);
set_td_width(t, t->x, W_AUTO, 0);
return t;
}
-static void get_cell_width(struct table *t, struct table_cell *c, int w, int a, int *min, int *max, int *n_links)
+static void
+get_cell_width(struct table *t, struct table_cell *c, int w, int a, int *min,
+ int *max, int *n_links)
{
struct part *p;
@@ -635,7 +751,11 @@ static void get_cell_width(struct table *t, struct table_cell *c, int w, int a,
*max = -1;
if (n_links)
*n_links = c->link_num;
- if (!(p = format_html_part(c->start, c->end, c->align == AL_NO || c->align == AL_NO_BREAKABLE ? c->align : AL_LEFT, t->cellpd, w, NULL, !!a, !!a, NULL, c->link_num)))
+ if (!(p = format_html_part(
+ c->start, c->end,
+ c->align == AL_NO || c->align == AL_NO_BREAKABLE ? c->align
+ : AL_LEFT,
+ t->cellpd, w, NULL, !!a, !!a, NULL, c->link_num)))
return;
if (min)
*min = p->x;
@@ -646,32 +766,42 @@ static void get_cell_width(struct table *t, struct table_cell *c, int w, int a,
free(p);
}
-#define g_c_w(cc) \
-do { \
- struct table_cell *c = cc; \
- if (!c->start) continue; \
- c->link_num = nl; \
- get_cell_width(t, c, 0, 0, &c->min_width, &c->max_width, &nl);\
-} while (0)
-
-static void get_cell_widths(struct table *t)
+#define g_c_w(cc) \
+ do { \
+ struct table_cell *c = cc; \
+ if (!c->start) \
+ continue; \
+ c->link_num = nl; \
+ get_cell_width(t, c, 0, 0, &c->min_width, &c->max_width, &nl); \
+ } while (0)
+
+static void
+get_cell_widths(struct table *t)
{
int nl = t->p->link_num;
int i, j;
if (!d_opt->table_order)
- for (j = 0; j < t->y; j++) for (i = 0; i < t->x; i++) g_c_w(CELL(t, i, j));
+ for (j = 0; j < t->y; j++)
+ for (i = 0; i < t->x; i++)
+ g_c_w(CELL(t, i, j));
else
- for (i = 0; i < t->x; i++) for (j = 0; j < t->y; j++) g_c_w(CELL(t, i, j));
+ for (i = 0; i < t->x; i++)
+ for (j = 0; j < t->y; j++)
+ g_c_w(CELL(t, i, j));
t->link_num = nl;
}
-static void dst_width(int *p, int n, int w, int *lim)
+static void
+dst_width(int *p, int n, int w, int *lim)
{
int i, s = 0, d, r;
- for (i = 0; i < n; i++) s = safe_add(s, p[i]);
- if (s >= w) return;
- if (!n) return;
- again:
+ for (i = 0; i < n; i++)
+ s = safe_add(s, p[i]);
+ if (s >= w)
+ return;
+ if (!n)
+ return;
+again:
d = (w - s) / n;
r = (w - s) % n;
w = 0;
@@ -689,38 +819,50 @@ static void dst_width(int *p, int n, int w, int *lim)
}
}
-static int get_vline_width(struct table *t, int col)
-{ /* return: -1 none, 0, space, 1 line, 2 double */
+static int
+get_vline_width(struct table *t, int col)
+{ /* return: -1 none, 0, space, 1 line, 2 double */
int w = 0;
- if (!col) return -1;
- if (t->rules == R_COLS || t->rules == R_ALL) w = t->cellsp;
- else if (t->rules == R_GROUPS) w = col < t->c && t->cols[col].group;
- if (!w && t->cellpd) w = -1;
+ if (!col)
+ return -1;
+ if (t->rules == R_COLS || t->rules == R_ALL)
+ w = t->cellsp;
+ else if (t->rules == R_GROUPS)
+ w = col < t->c && t->cols[col].group;
+ if (!w && t->cellpd)
+ w = -1;
return w;
}
-static int get_hline_width(struct table *t, int row)
+static int
+get_hline_width(struct table *t, int row)
{
int w = 0;
- if (!row) return -1;
+ if (!row)
+ return -1;
if (t->rules == R_ROWS || t->rules == R_ALL) {
- x:
- if (t->cellsp || t->vcellpd) return t->cellsp;
+x:
+ if (t->cellsp || t->vcellpd)
+ return t->cellsp;
return -1;
- }
- else if (t->rules == R_GROUPS) {
+ } else if (t->rules == R_GROUPS) {
int q;
- for (q = 0; q < t->x; q++) if (CELL(t, q, row)->group) goto x;
+ for (q = 0; q < t->x; q++)
+ if (CELL(t, q, row)->group)
+ goto x;
return t->vcellpd ? 0 : -1;
}
- if (!w && !t->vcellpd) w = -1;
+ if (!w && !t->vcellpd)
+ w = -1;
return w;
}
-static int get_column_widths(struct table *t)
+static int
+get_column_widths(struct table *t)
{
int i, j, s, ns;
- if ((unsigned)t->x > INT_MAX / sizeof(int)) overalloc();
+ if ((unsigned)t->x > INT_MAX / sizeof(int))
+ overalloc();
if (!t->min_c)
t->min_c = xmalloc(t->x * sizeof(int));
if (!t->max_c)
@@ -732,32 +874,44 @@ static int get_column_widths(struct table *t)
s = 1;
do {
ns = INT_MAX;
- for (i = 0; i < t->x; i++) for (j = 0; j < t->y; j++) {
- struct table_cell *c = CELL(t, i, j);
- if (c->spanned || !c->used) continue;
- if (c->colspan + i > t->x) {
- /*internal("colspan out of table");
- return -1;*/
- continue;
- }
- if (c->colspan == s) {
- int k, p = 0;
- /*int pp = t->max_c[i];*/
- int m = 0;
- for (k = 1; k < s; k++) {
- if (get_vline_width(t, i + k) >= 0)
- p = safe_add(p, 1);
+ for (i = 0; i < t->x; i++)
+ for (j = 0; j < t->y; j++) {
+ struct table_cell *c = CELL(t, i, j);
+ if (c->spanned || !c->used)
+ continue;
+ if (c->colspan + i > t->x) {
+ /*internal("colspan out of table");
+ return -1;*/
+ continue;
}
- dst_width(t->min_c + i, s, c->min_width - p, t->max_c + i);
- dst_width(t->max_c + i, s, c->max_width - p - m, NULL);
- for (k = 0; k < s; k++) if (t->min_c[i + k] > t->max_c[i + k]) t->max_c[i + k] = t->min_c[i + k];
- } else if (c->colspan > s && c->colspan < ns) ns = c->colspan;
- }
+ if (c->colspan == s) {
+ int k, p = 0;
+ /*int pp = t->max_c[i];*/
+ int m = 0;
+ for (k = 1; k < s; k++) {
+ if (get_vline_width(t, i + k)
+ >= 0)
+ p = safe_add(p, 1);
+ }
+ dst_width(t->min_c + i, s,
+ c->min_width - p,
+ t->max_c + i);
+ dst_width(t->max_c + i, s,
+ c->max_width - p - m, NULL);
+ for (k = 0; k < s; k++)
+ if (t->min_c[i + k]
+ > t->max_c[i + k])
+ t->max_c[i + k] =
+ t->min_c[i + k];
+ } else if (c->colspan > s && c->colspan < ns)
+ ns = c->colspan;
+ }
} while ((s = ns) != INT_MAX);
return 0;
}
-static void get_table_width(struct table *t)
+static void
+get_table_width(struct table *t)
{
int i, vl;
int min = 0, max = 0;
@@ -766,7 +920,8 @@ static void get_table_width(struct table *t)
min = safe_add(min, vl);
max = safe_add(max, vl);
min = safe_add(min, t->min_c[i]);
- if (t->xcols[i] > t->max_c[i]) max = safe_add(max, t->xcols[i]);
+ if (t->xcols[i] > t->max_c[i])
+ max = safe_add(max, t->xcols[i]);
max = safe_add(max, t->max_c[i]);
}
vl = (!!(t->frame & F_LHS) + !!(t->frame & F_RHS)) * !!t->border;
@@ -776,7 +931,8 @@ static void get_table_width(struct table *t)
t->max_t = max;
}
-static void distribute_widths(struct table *t, int width)
+static void
+distribute_widths(struct table *t, int width)
{
int i;
int d = width - t->min_t;
@@ -785,15 +941,20 @@ static void distribute_widths(struct table *t, int width)
int *w, *mx;
int mmax_c = 0;
t->rw = 0;
- if (!t->x) return;
+ if (!t->x)
+ return;
if (d < 0) {
- /*internal("too small width %d, required %d", width, t->min_t);*/
+ /*internal("too small width %d, required %d", width,
+ * t->min_t);*/
return;
}
- for (i = 0; i < t->x; i++) if (t->max_c[i] > mmax_c) mmax_c = t->max_c[i];
+ for (i = 0; i < t->x; i++)
+ if (t->max_c[i] > mmax_c)
+ mmax_c = t->max_c[i];
memcpy(t->w_c, t->min_c, t->x * sizeof(int));
t->rw = width;
- if ((unsigned)t->x > INT_MAX / sizeof(int)) overalloc();
+ if ((unsigned)t->x > INT_MAX / sizeof(int))
+ overalloc();
u = xmalloc(t->x);
w = xmalloc(t->x * sizeof(int));
mx = xmalloc(t->x * sizeof(int));
@@ -806,50 +967,63 @@ static void distribute_widths(struct table *t, int width)
memset(mx, 0, t->x * sizeof(int));
for (i = 0; i < t->x; i++) {
switch (om) {
- case 0:
- if (t->w_c[i] < t->xcols[i]) {
- w[i] = 1;
- mx[i] = (t->xcols[i] > t->max_c[i] ? t->max_c[i]
- : t->xcols[i]) - t->w_c[i];
- if (mx[i] <= 0) w[i] = 0;
- }
- break;
- case 1:
- if (t->xcols[i] < -1 && t->xcols[i] != -2) {
- w[i] = t->xcols[i] <= -2 ? -2 - t->xcols[i] : 1;
- mx[i] = t->max_c[i] - t->w_c[i];
- if (mx[i] <= 0) w[i] = 0;
- }
- break;
- case 2:
- case 3:
- if (t->w_c[i] < t->max_c[i] && (om == 3 || t->xcols[i] == W_AUTO)) {
- mx[i] = t->max_c[i] - t->w_c[i];
- if (mmax_c)
- w[i] = safe_add(5, t->max_c[i] * 10 / mmax_c);
- else w[i] = 1;
- }
- break;
- case 4:
- if (t->xcols[i] >= 0) {
+ case 0:
+ if (t->w_c[i] < t->xcols[i]) {
+ w[i] = 1;
+ mx[i] = (t->xcols[i] > t->max_c[i]
+ ? t->max_c[i]
+ : t->xcols[i])
+ - t->w_c[i];
+ if (mx[i] <= 0)
+ w[i] = 0;
+ }
+ break;
+ case 1:
+ if (t->xcols[i] < -1 && t->xcols[i] != -2) {
+ w[i] = t->xcols[i] <= -2
+ ? -2 - t->xcols[i]
+ : 1;
+ mx[i] = t->max_c[i] - t->w_c[i];
+ if (mx[i] <= 0)
+ w[i] = 0;
+ }
+ break;
+ case 2:
+ case 3:
+ if (t->w_c[i] < t->max_c[i]
+ && (om == 3 || t->xcols[i] == W_AUTO)) {
+ mx[i] = t->max_c[i] - t->w_c[i];
+ if (mmax_c)
+ w[i] =
+ safe_add(5, t->max_c[i] * 10
+ / mmax_c);
+ else
w[i] = 1;
- mx[i] = t->xcols[i] - t->w_c[i];
- if (mx[i] <= 0) w[i] = 0;
- }
- break;
- case 5:
- if (t->xcols[i] < 0) {
- w[i] = t->xcols[i] <= -2 ? -2 - t->xcols[i] : 1;
- mx[i] = INT_MAX;
- }
- break;
- case 6:
+ }
+ break;
+ case 4:
+ if (t->xcols[i] >= 0) {
w[i] = 1;
+ mx[i] = t->xcols[i] - t->w_c[i];
+ if (mx[i] <= 0)
+ w[i] = 0;
+ }
+ break;
+ case 5:
+ if (t->xcols[i] < 0) {
+ w[i] = t->xcols[i] <= -2
+ ? -2 - t->xcols[i]
+ : 1;
mx[i] = INT_MAX;
- break;
- default:
- /*internal("could not expand table");*/
- goto end2;
+ }
+ break;
+ case 6:
+ w[i] = 1;
+ mx[i] = INT_MAX;
+ break;
+ default:
+ /*internal("could not expand table");*/
+ goto end2;
}
p = safe_add(p, w[i]);
}
@@ -858,23 +1032,30 @@ static void distribute_widths(struct table *t, int width)
continue;
}
wq = 0;
- if (u) memset(u, 0, t->x);
+ if (u)
+ memset(u, 0, t->x);
dd = d;
- a:
- mss = 0; mii = -1;
- for (i = 0; i < t->x; i++) if (w[i]) {
- int ss;
- if (u && u[i]) continue;
- if (!(ss = dd * w[i] / p)) ss = 1;
- if (ss > mx[i]) ss = mx[i];
- if (ss > mss) {
- mss = ss;
- mii = i;
+a:
+ mss = 0;
+ mii = -1;
+ for (i = 0; i < t->x; i++)
+ if (w[i]) {
+ int ss;
+ if (u && u[i])
+ continue;
+ if (!(ss = dd * w[i] / p))
+ ss = 1;
+ if (ss > mx[i])
+ ss = mx[i];
+ if (ss > mss) {
+ mss = ss;
+ mii = i;
+ }
}
- }
if (mii != -1) {
int q = t->w_c[mii];
- if (u) u[mii] = 1;
+ if (u)
+ u[mii] = 1;
t->w_c[mii] = safe_add(t->w_c[mii], mss);
d -= t->w_c[mii] - q;
while (d < 0) {
@@ -886,87 +1067,110 @@ static void distribute_widths(struct table *t, int width)
t->w_c[mii] = q;
}
wq = 1;
- if (d) goto a;
- } else if (!wq) om++;
+ if (d)
+ goto a;
+ } else if (!wq)
+ om++;
}
- end2:
+end2:
free(mx);
free(w);
free(u);
}
#ifdef HTML_TABLE_2ND_PASS
-static void check_table_widths(struct table *t)
+static void
+check_table_widths(struct table *t)
{
int *w;
int i, j;
int s, ns;
int m, mi = 0; /* go away, warning! */
- if ((unsigned)t->x > INT_MAX / sizeof(int)) overalloc();
+ if ((unsigned)t->x > INT_MAX / sizeof(int))
+ overalloc();
w = mem_calloc(t->x * sizeof(int));
- for (j = 0; j < t->y; j++) for (i = 0; i < t->x; i++) {
- struct table_cell *c = CELL(t, i, j);
- int k, p = 0;
- if (!c->start) continue;
- for (k = 1; k < c->colspan; k++) if (get_vline_width(t, i + k) >= 0) p = safe_add(p, 1);
- for (k = 0; k < c->colspan; k++) p = safe_add(p, t->w_c[i + k]);
- get_cell_width(t, c, p, 1, &c->x_width, NULL, NULL);
- if (c->x_width > p) {
- /*int min, max;
- get_cell_width(t, c, 0, 0, &min, &max, NULL);
- internal("cell is now wider (%d > %d) min = %d, max = %d, now_min = %d, now_max = %d", c->x_width, p, t->min_c[i], t->max_c[i], min, max);*/
- /* sbohem, internale. chytl jsi mi spoustu chyb v tabulkovaci, ale ted je proste cas jit ... ;-( */
- c->x_width = p;
+ for (j = 0; j < t->y; j++)
+ for (i = 0; i < t->x; i++) {
+ struct table_cell *c = CELL(t, i, j);
+ int k, p = 0;
+ if (!c->start)
+ continue;
+ for (k = 1; k < c->colspan; k++)
+ if (get_vline_width(t, i + k) >= 0)
+ p = safe_add(p, 1);
+ for (k = 0; k < c->colspan; k++)
+ p = safe_add(p, t->w_c[i + k]);
+ get_cell_width(t, c, p, 1, &c->x_width, NULL, NULL);
+ if (c->x_width > p) {
+ /*int min, max;
+ get_cell_width(t, c, 0, 0, &min, &max, NULL);
+ internal("cell is now wider (%d > %d) min = %d,
+ max = %d, now_min = %d, now_max = %d",
+ c->x_width, p, t->min_c[i], t->max_c[i], min,
+ max);*/
+ /* sbohem, internale. chytl jsi mi spoustu chyb
+ * v tabulkovaci, ale ted je proste cas jit ...
+ * ;-( */
+ c->x_width = p;
+ }
}
- }
s = 1;
do {
ns = INT_MAX;
- for (i = 0; i < t->x; i++) for (j = 0; j < t->y; j++) {
- struct table_cell *c = CELL(t, i, j);
- if (!c->start) continue;
- if (c->colspan + i > t->x) {
- /*internal("colspan out of table");*/
- free(w);
- return;
+ for (i = 0; i < t->x; i++)
+ for (j = 0; j < t->y; j++) {
+ struct table_cell *c = CELL(t, i, j);
+ if (!c->start)
+ continue;
+ if (c->colspan + i > t->x) {
+ /*internal("colspan out of table");*/
+ free(w);
+ return;
+ }
+ if (c->colspan == s) {
+ int k, p = 0;
+ for (k = 1; k < s; k++)
+ if (get_vline_width(t, i + k)
+ >= 0)
+ p = safe_add(p, 1);
+ dst_width(w + i, s, c->x_width - p,
+ t->max_c + i);
+ /*for (k = i; k < i + s; k++) if (w[k] >
+ t->w_c[k]) { int l; int c; ag: c = 0;
+ for (l = i; l < i + s; l++) if
+ (w[l] < t->w_c[k]) w[l] = safe_add(w[l],
+ 1), w[k]--, c = 1; if (w[k] > t->w_c[k])
+ { if (!c) internal("can't shrink cell");
+ else goto ag;
+ }
+ }*/
+ } else if (c->colspan > s && c->colspan < ns)
+ ns = c->colspan;
}
- if (c->colspan == s) {
- int k, p = 0;
- for (k = 1; k < s; k++) if (get_vline_width(t, i + k) >= 0) p = safe_add(p, 1);
- dst_width(w + i, s, c->x_width - p, t->max_c + i);
- /*for (k = i; k < i + s; k++) if (w[k] > t->w_c[k]) {
- int l;
- int c;
- ag:
- c = 0;
- for (l = i; l < i + s; l++) if (w[l] < t->w_c[k]) w[l] = safe_add(w[l], 1), w[k]--, c = 1;
- if (w[k] > t->w_c[k]) {
- if (!c) internal("can't shrink cell");
- else goto ag;
- }
- }*/
- } else if (c->colspan > s && c->colspan < ns) ns = c->colspan;
- }
} while ((s = ns) != INT_MAX);
- s = 0; ns = 0;
+ s = 0;
+ ns = 0;
for (i = 0; i < t->x; i++) {
s = safe_add(s, t->w_c[i]);
ns = safe_add(ns, w[i]);
/*if (w[i] > t->w_c[i]) {
- int k;
- for (k = 0; k < t->x; k++) debug("%d, %d", t->w_c[k], w[k]);
- debug("column %d: new width(%d) is larger than previous(%d)", i, w[i], t->w_c[i]);
+ int k;
+ for (k = 0; k < t->x; k++) debug("%d, %d", t->w_c[k],
+ w[k]); debug("column %d: new width(%d) is larger than
+ previous(%d)", i, w[i], t->w_c[i]);
}*/
}
if (ns > s) {
- /*internal("new width(%d) is larger than previous(%d)", ns, s);*/
+ /*internal("new width(%d) is larger than previous(%d)", ns,
+ * s);*/
free(w);
return;
}
m = -1;
for (i = 0; i < t->x; i++) {
- /*if (table_level == 1) debug("%d: %d %d %d %d", i, t->max_c[i], t->min_c[i], t->w_c[i], w[i]);*/
+ /*if (table_level == 1) debug("%d: %d %d %d %d", i, t->max_c[i],
+ * t->min_c[i], t->w_c[i], w[i]);*/
if (t->max_c[i] > m) {
m = t->max_c[i];
mi = i;
@@ -985,7 +1189,8 @@ static void check_table_widths(struct table *t)
}
#endif
-static void get_table_heights(struct table *t)
+static void
+get_table_heights(struct table *t)
{
int s, ns;
int i, j;
@@ -994,7 +1199,8 @@ static void get_table_heights(struct table *t)
struct table_cell *cell = CELL(t, i, j);
struct part *p;
int xw = 0, sp;
- if (!cell->used || cell->spanned) continue;
+ if (!cell->used || cell->spanned)
+ continue;
for (sp = 0; sp < cell->colspan; sp++) {
xw = safe_add(xw, t->w_c[i + sp]);
if (sp < cell->colspan - 1) {
@@ -1002,7 +1208,10 @@ static void get_table_heights(struct table *t)
xw = safe_add(xw, 1);
}
}
- if (!(p = format_html_part(cell->start, cell->end, cell->align, t->cellpd, xw, NULL, 2, 2, NULL, cell->link_num)))
+ if (!(p = format_html_part(cell->start, cell->end,
+ cell->align, t->cellpd, xw,
+ NULL, 2, 2, NULL,
+ cell->link_num)))
return;
cell->height = p->y;
free(p);
@@ -1014,15 +1223,20 @@ static void get_table_heights(struct table *t)
for (j = 0; j < t->y; j++) {
for (i = 0; i < t->x; i++) {
struct table_cell *cell = CELL(t, i, j);
- if (!cell->used || cell->spanned) continue;
+ if (!cell->used || cell->spanned)
+ continue;
if (cell->rowspan == s) {
int k, p = 0;
for (k = 1; k < s; k++) {
- if (get_hline_width(t, j + k) >= 0)
+ if (get_hline_width(t, j + k)
+ >= 0)
p = safe_add(p, 1);
}
- dst_width(t->r_heights + j, s, cell->height - p, NULL);
- } else if (cell->rowspan > s && cell->rowspan < ns) ns = cell->rowspan;
+ dst_width(t->r_heights + j, s,
+ cell->height - p, NULL);
+ } else if (cell->rowspan > s
+ && cell->rowspan < ns)
+ ns = cell->rowspan;
}
}
} while ((s = ns) != INT_MAX);
@@ -1034,7 +1248,8 @@ static void get_table_heights(struct table *t)
}
}
-static void display_complicated_table(struct table *t, int x, int y, int *yy)
+static void
+display_complicated_table(struct table *t, int x, int y, int *yy)
{
int i, j;
struct f_data *f = t->p->data;
@@ -1050,33 +1265,57 @@ static void display_complicated_table(struct table *t, int x, int y, int *yy)
for (s = 0; s < cell->colspan; s++) {
xw = safe_add(xw, t->w_c[i + s]);
if (s < cell->colspan - 1) {
- if (get_vline_width(t, i + s + 1) >= 0)
+ if (get_vline_width(t,
+ i + s + 1)
+ >= 0)
xw = safe_add(xw, 1);
}
}
for (s = 0; s < cell->rowspan; s++) {
yw += t->r_heights[j + s];
if (s < cell->rowspan - 1) {
- if (get_hline_width(t, j + s + 1) >= 0)
+ if (get_hline_width(t,
+ j + s + 1)
+ >= 0)
yw = safe_add(yw, 1);
}
}
html_stack_dup();
html_top.dontkill = 1;
- if (cell->b) format_.attr |= AT_BOLD;
- memcpy(&format_.bg, &cell->bgcolor, sizeof(struct rgb));
- memcpy(&par_format.bgcolor, &cell->bgcolor, sizeof(struct rgb));
+ if (cell->b)
+ format_.attr |= AT_BOLD;
+ memcpy(&format_.bg, &cell->bgcolor,
+ sizeof(struct rgb));
+ memcpy(&par_format.bgcolor, &cell->bgcolor,
+ sizeof(struct rgb));
if (cell->tag) {
- if (f) html_tag(f, cell->tag, safe_add(t->p->xp, xp), safe_add(t->p->yp, yp));
+ if (f)
+ html_tag(
+ f, cell->tag,
+ safe_add(t->p->xp, xp),
+ safe_add(t->p->yp, yp));
}
- p = format_html_part(cell->start, cell->end, cell->align, t->cellpd, xw, f, safe_add(t->p->xp, xp), safe_add(safe_add(t->p->yp, yp), cell->valign != VAL_MIDDLE && cell->valign != VAL_BOTTOM ? 0 : (yw - cell->height) / (cell->valign == VAL_MIDDLE ? 2 : 1)), NULL, cell->link_num);
+ p = format_html_part(
+ cell->start, cell->end, cell->align,
+ t->cellpd, xw, f, safe_add(t->p->xp, xp),
+ safe_add(
+ safe_add(t->p->yp, yp),
+ cell->valign != VAL_MIDDLE
+ && cell->valign != VAL_BOTTOM
+ ? 0
+ : (yw - cell->height)
+ / (cell->valign == VAL_MIDDLE
+ ? 2
+ : 1)),
+ NULL, cell->link_num);
cell->xpos = xp;
cell->ypos = yp;
cell->xw = xw;
cell->yw = yw;
for (yt = 0; yt < p->y; yt++) {
xxpand_lines(t->p, safe_add(yp, yt));
- xxpand_line(t->p, yp + yt, safe_add(xp, t->w_c[i]));
+ xxpand_line(t->p, yp + yt,
+ safe_add(xp, t->w_c[i]));
}
kill_html_stack_item(&html_top);
free(p);
@@ -1085,7 +1324,9 @@ static void display_complicated_table(struct table *t, int x, int y, int *yy)
cell->ypos = yp;
cell->xw = t->w_c[i];
yp = safe_add(yp, t->r_heights[j]);
- if (j < t->y - 1) if (get_hline_width(t, j + 1) >= 0) yp = safe_add(yp, 1);
+ if (j < t->y - 1)
+ if (get_hline_width(t, j + 1) >= 0)
+ yp = safe_add(yp, 1);
}
if (i < t->x - 1) {
if (get_vline_width(t, i + 1) >= 0)
@@ -1096,53 +1337,86 @@ static void display_complicated_table(struct table *t, int x, int y, int *yy)
yp = y;
for (j = 0; j < t->y; j++) {
yp = safe_add(yp, t->r_heights[j]);
- if (j < t->y - 1) if (get_hline_width(t, j + 1) >= 0) yp = safe_add(yp, 1);
+ if (j < t->y - 1)
+ if (get_hline_width(t, j + 1) >= 0)
+ yp = safe_add(yp, 1);
}
- *yy = safe_add(yp, (!!(t->frame & F_ABOVE) + !!(t->frame & F_BELOW)) * !!t->border);
+ *yy = safe_add(yp, (!!(t->frame & F_ABOVE) + !!(t->frame & F_BELOW))
+ * !!t->border);
}
static unsigned char AF;
-#define draw_frame_point(xx, yy, ii, jj) \
-if (H_LINE_X((ii-1), (jj)) >= 0 || H_LINE_X((ii), (jj)) >= 0 || V_LINE_X((ii), (jj-1)) >= 0 || V_LINE_X((ii), (jj)) >= 0) xset_hchar(t->p, (xx), (yy), frame_table[V_LINE((ii),(jj)-1)+3*H_LINE((ii),(jj))+9*H_LINE((ii)-1,(jj))+27*V_LINE((ii),(jj))], AF)
-
-#define draw_frame_hline(xx, yy, ll, ii, jj) \
-if (H_LINE_X((ii), (jj)) >= 0) xset_hchars(t->p, (xx), (yy), (ll), hline_table[H_LINE((ii), (jj))], AF)
-
-#define draw_frame_vline(xx, yy, ll, ii, jj) \
-{ \
- int qq; \
- if (V_LINE_X((ii), (jj)) >= 0) for (qq = 0; qq < (ll); qq++) xset_hchar(t->p, (xx), safe_add((yy), qq), vline_table[V_LINE((ii), (jj))], AF); }
+#define draw_frame_point(xx, yy, ii, jj) \
+ if (H_LINE_X((ii - 1), (jj)) >= 0 || H_LINE_X((ii), (jj)) >= 0 \
+ || V_LINE_X((ii), (jj - 1)) >= 0 || V_LINE_X((ii), (jj)) >= 0) \
+ xset_hchar( \
+ t->p, (xx), (yy), \
+ frame_table[V_LINE((ii), (jj)-1) + 3 * H_LINE((ii), (jj)) \
+ + 9 * H_LINE((ii)-1, (jj)) + 27 * V_LINE((ii), (jj))], \
+ AF)
+
+#define draw_frame_hline(xx, yy, ll, ii, jj) \
+ if (H_LINE_X((ii), (jj)) >= 0) \
+ xset_hchars(t->p, (xx), (yy), (ll), hline_table[H_LINE((ii), (jj))], AF)
+
+#define draw_frame_vline(xx, yy, ll, ii, jj) \
+ { \
+ int qq; \
+ if (V_LINE_X((ii), (jj)) >= 0) \
+ for (qq = 0; qq < (ll); qq++) \
+ xset_hchar(t->p, (xx), safe_add((yy), qq), \
+ vline_table[V_LINE((ii), (jj))], \
+ AF); \
+ }
#define H_LINE_X(xx, yy) fh[(xx) + 1 + (t->x + 2) * (yy)]
#define V_LINE_X(xx, yy) fv[(yy) + 1 + (t->y + 2) * (xx)]
-#define H_LINE(xx, yy) (H_LINE_X((xx), (yy)) < 0 ? 0 : H_LINE_X((xx), (yy)))
-#define V_LINE(xx, yy) (V_LINE_X((xx), (yy)) < 0 ? 0 : V_LINE_X((xx), (yy)))
+#define H_LINE(xx, yy) (H_LINE_X((xx), (yy)) < 0 ? 0 : H_LINE_X((xx), (yy)))
+#define V_LINE(xx, yy) (V_LINE_X((xx), (yy)) < 0 ? 0 : V_LINE_X((xx), (yy)))
-static void get_table_frame(struct table *t, short *fv, short *fh)
+static void
+get_table_frame(struct table *t, short *fv, short *fh)
{
int i, j;
memset(fh, -1, (t->x + 2) * (t->y + 1) * sizeof(short));
memset(fv, -1, (t->x + 1) * (t->y + 2) * sizeof(short));
- for (j = 0; j < t->y; j++) for (i = 0; i < t->x; i++) {
- int x, y;
- int xsp, ysp;
- struct table_cell *cell = CELL(t, i, j);
- if (!cell->used || cell->spanned) continue;
- if ((xsp = cell->colspan) == 0) xsp = t->x - i;
- if ((ysp = cell->rowspan) == 0) ysp = t->y - j;
- if (t->rules != R_NONE && t->rules != R_COLS) for (x = 0; x < xsp; x++) {H_LINE_X(i + x, j) = t->cellsp; H_LINE_X(i + x, j + ysp) = t->cellsp;}
- if (t->rules != R_NONE && t->rules != R_ROWS) for (y = 0; y < ysp; y++) {V_LINE_X(i, j + y) = t->cellsp; V_LINE_X(i + xsp, j + y) = t->cellsp;}
- }
+ for (j = 0; j < t->y; j++)
+ for (i = 0; i < t->x; i++) {
+ int x, y;
+ int xsp, ysp;
+ struct table_cell *cell = CELL(t, i, j);
+ if (!cell->used || cell->spanned)
+ continue;
+ if ((xsp = cell->colspan) == 0)
+ xsp = t->x - i;
+ if ((ysp = cell->rowspan) == 0)
+ ysp = t->y - j;
+ if (t->rules != R_NONE && t->rules != R_COLS)
+ for (x = 0; x < xsp; x++) {
+ H_LINE_X(i + x, j) = t->cellsp;
+ H_LINE_X(i + x, j + ysp) = t->cellsp;
+ }
+ if (t->rules != R_NONE && t->rules != R_ROWS)
+ for (y = 0; y < ysp; y++) {
+ V_LINE_X(i, j + y) = t->cellsp;
+ V_LINE_X(i + xsp, j + y) = t->cellsp;
+ }
+ }
if (t->rules == R_GROUPS) {
for (i = 1; i < t->x; i++) {
- if (/*i < t->xc &&*/ t->xcols[i]) continue;
- for (j = 0; j < t->y; j++) V_LINE_X(i, j) = 0;
+ if (/*i < t->xc &&*/ t->xcols[i])
+ continue;
+ for (j = 0; j < t->y; j++)
+ V_LINE_X(i, j) = 0;
}
for (j = 1; j < t->y; j++) {
- for (i = 0; i < t->x; i++) if (CELL(t, i, j)->group) goto c;
- for (i = 0; i < t->x; i++) H_LINE_X(i, j) = 0;
- c:;
+ for (i = 0; i < t->x; i++)
+ if (CELL(t, i, j)->group)
+ goto c;
+ for (i = 0; i < t->x; i++)
+ H_LINE_X(i, j) = 0;
+c:;
}
}
for (i = 0; i < t->x; i++) {
@@ -1155,15 +1429,21 @@ static void get_table_frame(struct table *t, short *fv, short *fh)
}
}
-static void display_table_frames(struct table *t, int x, int y)
+static void
+display_table_frames(struct table *t, int x, int y)
{
short *fh, *fv;
int i, j;
int cx, cy;
- if ((unsigned)t->x > INT_MAX) overalloc();
- if ((unsigned)t->y > INT_MAX) overalloc();
- if (((unsigned)t->x + 2) * ((unsigned)t->y + 2) / ((unsigned)t->x + 2) != ((unsigned)t->y + 2)) overalloc();
- if (((unsigned)t->x + 2) * ((unsigned)t->y + 2) > INT_MAX) overalloc();
+ if ((unsigned)t->x > INT_MAX)
+ overalloc();
+ if ((unsigned)t->y > INT_MAX)
+ overalloc();
+ if (((unsigned)t->x + 2) * ((unsigned)t->y + 2) / ((unsigned)t->x + 2)
+ != ((unsigned)t->y + 2))
+ overalloc();
+ if (((unsigned)t->x + 2) * ((unsigned)t->y + 2) > INT_MAX)
+ overalloc();
fh = xmalloc((t->x + 2) * (t->y + 1) * sizeof(short));
fv = xmalloc((t->x + 1) * (t->y + 2) * sizeof(short));
get_table_frame(t, fv, fh);
@@ -1171,14 +1451,23 @@ static void display_table_frames(struct table *t, int x, int y)
cy = y;
for (j = 0; j <= t->y; j++) {
cx = x;
- if ((j > 0 && j < t->y && get_hline_width(t, j) >= 0) || (j == 0 && t->border && (t->frame & F_ABOVE)) || (j == t->y && t->border && (t->frame & F_BELOW))) {
+ if ((j > 0 && j < t->y && get_hline_width(t, j) >= 0)
+ || (j == 0 && t->border && (t->frame & F_ABOVE))
+ || (j == t->y && t->border && (t->frame & F_BELOW))) {
for (i = 0; i < t->x; i++) {
int w;
- if (i > 0) w = get_vline_width(t, i);
- else w = t->border && (t->frame & F_LHS) ? t->border : -1;
+ if (i > 0)
+ w = get_vline_width(t, i);
+ else
+ w = t->border && (t->frame & F_LHS)
+ ? t->border
+ : -1;
if (w >= 0) {
draw_frame_point(cx, cy, i, j);
- if (j < t->y) draw_frame_vline(cx, safe_add(cy, 1), t->r_heights[j], i, j);
+ if (j < t->y)
+ draw_frame_vline(
+ cx, safe_add(cy, 1),
+ t->r_heights[j], i, j);
cx = safe_add(cx, 1);
}
w = t->w_c[i];
@@ -1187,26 +1476,39 @@ static void display_table_frames(struct table *t, int x, int y)
}
if (t->border && (t->frame & F_RHS)) {
draw_frame_point(cx, cy, i, j);
- if (j < t->y) draw_frame_vline(cx, safe_add(cy, 1), t->r_heights[j], i, j);
+ if (j < t->y)
+ draw_frame_vline(cx, safe_add(cy, 1),
+ t->r_heights[j], i, j);
}
cy = safe_add(cy, 1);
} else if (j < t->y) {
for (i = 0; i <= t->x; i++) {
- if ((i > 0 && i < t->x && get_vline_width(t, i) >= 0) || (i == 0 && t->border && (t->frame & F_LHS)) || (i == t->x && t->border && (t->frame & F_RHS))) {
- draw_frame_vline(cx, cy, t->r_heights[j], i, j);
+ if ((i > 0 && i < t->x
+ && get_vline_width(t, i) >= 0)
+ || (i == 0 && t->border
+ && (t->frame & F_LHS))
+ || (i == t->x && t->border
+ && (t->frame & F_RHS))) {
+ draw_frame_vline(cx, cy,
+ t->r_heights[j], i, j);
cx = safe_add(cx, 1);
}
- if (i < t->x) cx = safe_add(cx, t->w_c[i]);
+ if (i < t->x)
+ cx = safe_add(cx, t->w_c[i]);
}
}
- if (j < t->y) cy = safe_add(cy, t->r_heights[j]);
- /*for (cyy = cy1; cyy < cy; cyy++) xxpand_line(t->p, cyy, cx - 1);*/
+ if (j < t->y)
+ cy = safe_add(cy, t->r_heights[j]);
+ /*for (cyy = cy1; cyy < cy; cyy++) xxpand_line(t->p, cyy, cx -
+ * 1);*/
}
free(fh);
free(fv);
}
-void format_table(unsigned char *attr, unsigned char *html, unsigned char *eof, unsigned char **end, void *f)
+void
+format_table(unsigned char *attr, unsigned char *html, unsigned char *eof,
+ unsigned char **end, void *f)
{
struct part *p = f;
int bg, fg;
@@ -1232,7 +1534,10 @@ void format_table(unsigned char *attr, unsigned char *html, unsigned char *eof,
html_stack_dup();
html_top.dontkill = 1;
par_format.align = AL_LEFT;
- if ((border = get_num(attr, cast_uchar "border")) == -1) border = has_attr(attr, cast_uchar "border") || has_attr(attr, cast_uchar "rules") || has_attr(attr, cast_uchar "frame");
+ if ((border = get_num(attr, cast_uchar "border")) == -1)
+ border = has_attr(attr, cast_uchar "border")
+ || has_attr(attr, cast_uchar "rules")
+ || has_attr(attr, cast_uchar "frame");
if ((cellsp = get_num(attr, cast_uchar "cellspacing")) == -1)
cellsp = 1;
if ((cellpd = get_num(attr, cast_uchar "cellpadding")) == -1) {
@@ -1251,7 +1556,8 @@ void format_table(unsigned char *attr, unsigned char *html, unsigned char *eof,
if (cellsp > 2)
cellsp = 2;
align = par_format.align;
- if (align == AL_NO || align == AL_NO_BREAKABLE || align == AL_BLOCK) align = AL_LEFT;
+ if (align == AL_NO || align == AL_NO_BREAKABLE || align == AL_BLOCK)
+ align = AL_LEFT;
if ((al = get_attr_val(attr, cast_uchar "summary"))) {
if (!strcmp(cast_const_char al, "diff")) {
free(al);
@@ -1266,46 +1572,74 @@ void format_table(unsigned char *attr, unsigned char *html, unsigned char *eof,
free(al);
}
if ((al = get_attr_val(attr, cast_uchar "align"))) {
- if (!casestrcmp(al, cast_uchar "left")) align = AL_LEFT;
- if (!casestrcmp(al, cast_uchar "center")) align = AL_CENTER;
- if (!casestrcmp(al, cast_uchar "right")) align = AL_RIGHT;
+ if (!casestrcmp(al, cast_uchar "left"))
+ align = AL_LEFT;
+ if (!casestrcmp(al, cast_uchar "center"))
+ align = AL_CENTER;
+ if (!casestrcmp(al, cast_uchar "right"))
+ align = AL_RIGHT;
free(al);
}
frame = F_BOX;
if ((al = get_attr_val(attr, cast_uchar "frame"))) {
- if (!casestrcmp(al, cast_uchar "void")) frame = F_VOID;
- if (!casestrcmp(al, cast_uchar "above")) frame = F_ABOVE;
- if (!casestrcmp(al, cast_uchar "below")) frame = F_BELOW;
- if (!casestrcmp(al, cast_uchar "hsides")) frame = F_HSIDES;
- if (!casestrcmp(al, cast_uchar "vsides")) frame = F_VSIDES;
- if (!casestrcmp(al, cast_uchar "lhs")) frame = F_LHS;
- if (!casestrcmp(al, cast_uchar "rhs")) frame = F_RHS;
- if (!casestrcmp(al, cast_uchar "box")) frame = F_BOX;
- if (!casestrcmp(al, cast_uchar "border")) frame = F_BOX;
+ if (!casestrcmp(al, cast_uchar "void"))
+ frame = F_VOID;
+ if (!casestrcmp(al, cast_uchar "above"))
+ frame = F_ABOVE;
+ if (!casestrcmp(al, cast_uchar "below"))
+ frame = F_BELOW;
+ if (!casestrcmp(al, cast_uchar "hsides"))
+ frame = F_HSIDES;
+ if (!casestrcmp(al, cast_uchar "vsides"))
+ frame = F_VSIDES;
+ if (!casestrcmp(al, cast_uchar "lhs"))
+ frame = F_LHS;
+ if (!casestrcmp(al, cast_uchar "rhs"))
+ frame = F_RHS;
+ if (!casestrcmp(al, cast_uchar "box"))
+ frame = F_BOX;
+ if (!casestrcmp(al, cast_uchar "border"))
+ frame = F_BOX;
free(al);
}
rules = border ? R_ALL : R_NONE;
if ((al = get_attr_val(attr, cast_uchar "rules"))) {
- if (!casestrcmp(al, cast_uchar "none")) rules = R_NONE;
- if (!casestrcmp(al, cast_uchar "groups")) rules = R_GROUPS;
- if (!casestrcmp(al, cast_uchar "rows")) rules = R_ROWS;
- if (!casestrcmp(al, cast_uchar "cols")) rules = R_COLS;
- if (!casestrcmp(al, cast_uchar "all")) rules = R_ALL;
+ if (!casestrcmp(al, cast_uchar "none"))
+ rules = R_NONE;
+ if (!casestrcmp(al, cast_uchar "groups"))
+ rules = R_GROUPS;
+ if (!casestrcmp(al, cast_uchar "rows"))
+ rules = R_ROWS;
+ if (!casestrcmp(al, cast_uchar "cols"))
+ rules = R_COLS;
+ if (!casestrcmp(al, cast_uchar "all"))
+ rules = R_ALL;
free(al);
}
- if (!border) frame = F_VOID;
+ if (!border)
+ frame = F_VOID;
wf = 0;
- if ((width = get_width(attr, cast_uchar "width", (p->data || p->xp))) == -1) {
- width = par_format.width - safe_add(par_format.leftmargin, par_format.rightmargin);
- if (width < 0) width = 0;
+ if ((width = get_width(attr, cast_uchar "width", (p->data || p->xp)))
+ == -1) {
+ width =
+ par_format.width
+ - safe_add(par_format.leftmargin, par_format.rightmargin);
+ if (width < 0)
+ width = 0;
wf = 1;
}
- t = parse_table(html, eof, end, &bgcolor, (p->data || p->xp), &bad_html, &bad_html_n);
+ t = parse_table(html, eof, end, &bgcolor, (p->data || p->xp), &bad_html,
+ &bad_html_n);
for (i = 0; i < bad_html_n; i++) {
- while (bad_html[i].s < bad_html[i].e && WHITECHAR(*bad_html[i].s)) bad_html[i].s++;
- while (bad_html[i].s < bad_html[i].e && WHITECHAR(bad_html[i].e[-1])) bad_html[i].e--;
+ while (bad_html[i].s < bad_html[i].e
+ && WHITECHAR(*bad_html[i].s))
+ bad_html[i].s++;
+ while (bad_html[i].s < bad_html[i].e
+ && WHITECHAR(bad_html[i].e[-1]))
+ bad_html[i].e--;
if (bad_html[i].s < bad_html[i].e)
- parse_html(bad_html[i].s, bad_html[i].e, put_chars_f, line_break_f, special_f, (void *)p, NULL);
+ parse_html(bad_html[i].s, bad_html[i].e, put_chars_f,
+ line_break_f, special_f, (void *)p, NULL);
}
free(bad_html);
t->p = p;
@@ -1321,18 +1655,27 @@ void format_table(unsigned char *attr, unsigned char *html, unsigned char *eof,
t->wf = wf;
cpd_pass = 0;
cpd_last = t->cellpd;
- cpd_width = 0; /* not needed, but let the warning go away */
- again:
+ cpd_width = 0; /* not needed, but let the warning go away */
+again:
get_cell_widths(t);
- if (get_column_widths(t)) goto ret2;
+ if (get_column_widths(t))
+ goto ret2;
get_table_width(t);
if ((!p->data && !p->xp)) {
- if (!wf && t->max_t > width) t->max_t = width;
- if (t->max_t < t->min_t) t->max_t = t->min_t;
- if (safe_add(t->max_t, safe_add(par_format.leftmargin, par_format.rightmargin)) > p->xmax)
- p->xmax = t->max_t + par_format.leftmargin + par_format.rightmargin;
- if (safe_add(t->min_t, safe_add(par_format.leftmargin, par_format.rightmargin)) > p->x)
- p->x = t->min_t + par_format.leftmargin + par_format.rightmargin;
+ if (!wf && t->max_t > width)
+ t->max_t = width;
+ if (t->max_t < t->min_t)
+ t->max_t = t->min_t;
+ if (safe_add(t->max_t, safe_add(par_format.leftmargin,
+ par_format.rightmargin))
+ > p->xmax)
+ p->xmax = t->max_t + par_format.leftmargin
+ + par_format.rightmargin;
+ if (safe_add(t->min_t, safe_add(par_format.leftmargin,
+ par_format.rightmargin))
+ > p->x)
+ p->x = t->min_t + par_format.leftmargin
+ + par_format.rightmargin;
goto ret2;
}
if (!cpd_pass && t->min_t > width && t->cellpd) {
@@ -1346,14 +1689,21 @@ void format_table(unsigned char *attr, unsigned char *html, unsigned char *eof,
cpd_pass = 2;
goto again;
}
- if (t->min_t >= width) distribute_widths(t, t->min_t);
- else if (t->max_t < width && wf) distribute_widths(t, t->max_t);
- else distribute_widths(t, width);
+ if (t->min_t >= width)
+ distribute_widths(t, t->min_t);
+ else if (t->max_t < width && wf)
+ distribute_widths(t, t->max_t);
+ else
+ distribute_widths(t, width);
if (!p->data && p->xp == 1) {
- int ww = safe_add(t->rw, safe_add(par_format.leftmargin, par_format.rightmargin));
- if (ww > par_format.width) ww = par_format.width;
- if (ww < t->rw) ww = t->rw;
- if (ww > p->x) p->x = ww;
+ int ww = safe_add(t->rw, safe_add(par_format.leftmargin,
+ par_format.rightmargin));
+ if (ww > par_format.width)
+ ww = par_format.width;
+ if (ww < t->rw)
+ ww = t->rw;
+ if (ww > p->x)
+ p->x = ww;
p->cy = safe_add(p->cy, t->rh);
goto ret2;
}
@@ -1363,13 +1713,23 @@ void format_table(unsigned char *attr, unsigned char *html, unsigned char *eof,
get_table_heights(t);
x = par_format.leftmargin;
- if (align == AL_CENTER) x = (safe_add(par_format.width, par_format.leftmargin) - par_format.rightmargin - t->rw) / 2;
- if (align == AL_RIGHT) x = par_format.width - par_format.rightmargin - t->rw;
- if (safe_add(x, t->rw) > par_format.width) x = par_format.width - t->rw;
- if (x < 0) x = 0;
+ if (align == AL_CENTER)
+ x = (safe_add(par_format.width, par_format.leftmargin)
+ - par_format.rightmargin - t->rw)
+ / 2;
+ if (align == AL_RIGHT)
+ x = par_format.width - par_format.rightmargin - t->rw;
+ if (safe_add(x, t->rw) > par_format.width)
+ x = par_format.width - t->rw;
+ if (x < 0)
+ x = 0;
/*display_table(t, x, p->cy, &cye);*/
if (!p->data) {
- if (safe_add(t->rw, safe_add(par_format.leftmargin, par_format.rightmargin)) > p->x) p->x = t->rw + par_format.leftmargin + par_format.rightmargin;
+ if (safe_add(t->rw, safe_add(par_format.leftmargin,
+ par_format.rightmargin))
+ > p->x)
+ p->x = t->rw + par_format.leftmargin
+ + par_format.rightmargin;
p->cy = safe_add(p->cy, t->rh);
goto ret2;
}
@@ -1385,11 +1745,12 @@ void format_table(unsigned char *attr, unsigned char *html, unsigned char *eof,
add_to_list(p->data->nodes, nn);
p->cy = cye;
- ret2:
+ret2:
p->link_num = t->link_num;
if (p->cy > p->y)
p->y = p->cy;
- if (t) free_table(t);
+ if (t)
+ free_table(t);
kill_html_stack_item(&html_top);
table_level--;
if (!table_level) {
@@ -1399,8 +1760,7 @@ void format_table(unsigned char *attr, unsigned char *html, unsigned char *eof,
}
struct table_cache_entry {
- list_entry_1st
- struct table_cache_entry *hash_next;
+ list_entry_1st struct table_cache_entry *hash_next;
unsigned char *start;
unsigned char *end;
int align;
@@ -1415,21 +1775,26 @@ struct table_cache_entry {
static struct list_head table_cache = { &table_cache, &table_cache };
-#define TC_HASH_SIZE 8192
+#define TC_HASH_SIZE 8192
static struct table_cache_entry *table_cache_hash[TC_HASH_SIZE] = { NULL };
-static inline int make_hash(unsigned char *start, int xs)
+static inline int
+make_hash(unsigned char *start, int xs)
{
return ((int)(unsigned long)start + xs) & (TC_HASH_SIZE - 1);
}
-void *find_table_cache_entry(unsigned char *start, unsigned char *end, int align, int m, int width, int xs, int link_num)
+void *
+find_table_cache_entry(unsigned char *start, unsigned char *end, int align,
+ int m, int width, int xs, int link_num)
{
int hash = make_hash(start, xs);
struct table_cache_entry *tce;
for (tce = table_cache_hash[hash]; tce; tce = tce->hash_next) {
- if (tce->start == start && tce->end == end && tce->align == align && tce->m == m && tce->width == width && tce->xs == xs && tce->link_num == link_num) {
+ if (tce->start == start && tce->end == end
+ && tce->align == align && tce->m == m && tce->width == width
+ && tce->xs == xs && tce->link_num == link_num) {
struct part *p = xmalloc(sizeof(struct part));
memcpy(p, &tce->u.p, sizeof(struct part));
return p;
@@ -1438,10 +1803,13 @@ void *find_table_cache_entry(unsigned char *start, unsigned char *end, int align
return NULL;
}
-void add_table_cache_entry(unsigned char *start, unsigned char *end, int align, int m, int width, int xs, int link_num, void *p)
+void
+add_table_cache_entry(unsigned char *start, unsigned char *end, int align,
+ int m, int width, int xs, int link_num, void *p)
{
int hash;
- struct table_cache_entry *tce = xmalloc(sizeof(struct table_cache_entry));
+ struct table_cache_entry *tce =
+ xmalloc(sizeof(struct table_cache_entry));
tce->start = start;
tce->end = end;
tce->align = align;
@@ -1456,11 +1824,12 @@ void add_table_cache_entry(unsigned char *start, unsigned char *end, int align,
add_to_list(table_cache, tce);
}
-static void free_table_cache(void)
+static void
+free_table_cache(void)
{
struct table_cache_entry *tce = NULL;
struct list_head *ltce;
- foreach(struct table_cache_entry, tce, ltce, table_cache) {
+ foreach (struct table_cache_entry, tce, ltce, table_cache) {
int hash = make_hash(tce->start, tce->xs);
table_cache_hash[hash] = NULL;
}
diff --git a/http.c b/http.c
@@ -26,25 +26,31 @@ static void http_send_header(struct connection *c);
static void http_get_header(struct connection *c);
static void test_restart(struct connection *c);
static void add_user_agent(unsigned char **hdr, int *l, const char *url);
-static void add_referer(unsigned char **hdr, int *l, unsigned char *url, unsigned char *prev_url);
+static void add_referer(unsigned char **hdr, int *l, unsigned char *url,
+ unsigned char *prev_url);
static void add_accept(unsigned char **hdr, int *l);
-static void add_accept_encoding(unsigned char **hdr, int *l, unsigned char *url, struct connection *c);
-static void add_accept_charset(unsigned char **hdr, int *l, struct http_connection_info *info);
-static void add_connection(unsigned char **hdr, int *l, int http10, int proxy, int post);
+static void add_accept_encoding(unsigned char **hdr, int *l, unsigned char *url,
+ struct connection *c);
+static void add_accept_charset(unsigned char **hdr, int *l,
+ struct http_connection_info *info);
+static void add_connection(unsigned char **hdr, int *l, int http10, int proxy,
+ int post);
static void add_upgrade(unsigned char **hdr, int *l);
static void add_if_modified(unsigned char **hdr, int *l, struct connection *c);
-static void add_range(unsigned char **hdr, int *l, unsigned char *url, struct connection *c);
+static void add_range(unsigned char **hdr, int *l, unsigned char *url,
+ struct connection *c);
static void add_pragma_no_cache(unsigned char **hdr, int *l, int no_cache);
-static void add_proxy_auth_string(unsigned char **hdr, int *l, unsigned char *url);
+static void add_proxy_auth_string(unsigned char **hdr, int *l,
+ unsigned char *url);
static void add_auth_string(unsigned char **hdr, int *l, unsigned char *url);
static void add_post_header(unsigned char **hdr, int *l, unsigned char **post);
static void add_extra_options(unsigned char **hdr, int *l);
-
/* Returns a string pointer with value of the item.
* The string must be destroyed after usage with mem_free.
*/
-unsigned char *parse_http_header(unsigned char *head, unsigned char *item, unsigned char **ptr)
+unsigned char *
+parse_http_header(unsigned char *head, unsigned char *item, unsigned char **ptr)
{
unsigned char *i, *f, *g, *h;
if (!head)
@@ -76,7 +82,8 @@ cont:
return NULL;
}
-unsigned char *parse_header_param(unsigned char *x, unsigned char *e, int all)
+unsigned char *
+parse_header_param(unsigned char *x, unsigned char *e, int all)
{
unsigned char u;
size_t le = strlen((char *)e);
@@ -87,7 +94,8 @@ a:
if (!(y = cast_uchar strchr((char *)y, ';')))
return NULL;
}
- while (*y && (*y == ';' || *y <= ' ')) y++;
+ while (*y && (*y == ';' || *y <= ' '))
+ y++;
if (strlen((char *)y) < le)
return NULL;
if (casecmp(y, e, le))
@@ -107,16 +115,18 @@ a:
return memacpy(y, lp);
}
-int get_http_code(unsigned char *head, int *code, int *version)
+int
+get_http_code(unsigned char *head, int *code, int *version)
{
if (!head)
return -1;
while (head[0] == ' ')
head++;
- if (upcase(head[0]) != 'H' || upcase(head[1]) != 'T' || upcase(head[2]) != 'T'
- || upcase(head[3]) != 'P') return -1;
- if (head[4] == '/' && head[5] >= '0' && head[5] <= '9'
- && head[6] == '.' && head[7] >= '0' && head[7] <= '9' && head[8] <= ' ') {
+ if (upcase(head[0]) != 'H' || upcase(head[1]) != 'T'
+ || upcase(head[2]) != 'T' || upcase(head[3]) != 'P')
+ return -1;
+ if (head[4] == '/' && head[5] >= '0' && head[5] <= '9' && head[6] == '.'
+ && head[7] >= '0' && head[7] <= '9' && head[8] <= ' ') {
if (version)
*version = (head[5] - '0') * 10 + head[7] - '0';
} else if (version)
@@ -125,14 +135,15 @@ int get_http_code(unsigned char *head, int *code, int *version)
;
if (*head++ != ' ')
return -1;
- if (head[0] < '1' || head [0] > '9' || head[1] < '0' || head[1] > '9'
- || head[2] < '0' || head [2] > '9') {
+ if (head[0] < '1' || head[0] > '9' || head[1] < '0' || head[1] > '9'
+ || head[2] < '0' || head[2] > '9') {
if (code)
*code = 200;
return 0;
}
if (code)
- *code = (head[0]-'0')*100 + (head[1]-'0')*10 + head[2]-'0';
+ *code = (head[0] - '0') * 100 + (head[1] - '0') * 10 + head[2]
+ - '0';
return 0;
}
@@ -140,17 +151,19 @@ static struct {
const char *name;
int bugs;
} buggy_servers[] = {
- { "mod_czech/3.1.0", BL_HTTP10 },
- { "Purveyor", BL_HTTP10 },
- { "Netscape-Enterprise", BL_HTTP10 | BL_NO_ACCEPT_LANGUAGE },
- { "Apache Coyote", BL_HTTP10 },
- { "lighttpd", BL_HTTP10 },
- { "FORPSI", BL_NO_RANGE },
- { "Sausalito", BL_HTTP10 },
- { NULL, 0 }
+ {"mod_czech/3.1.0", BL_HTTP10 },
+ { "Purveyor", BL_HTTP10 },
+ { "Netscape-Enterprise", BL_HTTP10 | BL_NO_ACCEPT_LANGUAGE},
+ { "Apache Coyote", BL_HTTP10 },
+ { "lighttpd", BL_HTTP10 },
+ { "FORPSI", BL_NO_RANGE },
+ { "Sausalito", BL_HTTP10 },
+ { NULL, 0 }
};
-static int check_http_server_bugs(unsigned char *url, struct http_connection_info *info, unsigned char *head)
+static int
+check_http_server_bugs(unsigned char *url, struct http_connection_info *info,
+ unsigned char *head)
{
unsigned char *server;
int i, bugs;
@@ -171,7 +184,8 @@ static int check_http_server_bugs(unsigned char *url, struct http_connection_inf
return 0;
}
-static void http_end_request(struct connection *c, int notrunc, int nokeepalive, int state)
+static void
+http_end_request(struct connection *c, int notrunc, int nokeepalive, int state)
{
struct http_connection_info *info = c->info;
if (state == S__OK && c->cache) {
@@ -180,16 +194,14 @@ static void http_end_request(struct connection *c, int notrunc, int nokeepalive,
c->cache->incomplete = 0;
}
setcstate(c, state);
- if (c->info
- && !info->close
- && !info->send_close
- && !nokeepalive) {
+ if (c->info && !info->close && !info->send_close && !nokeepalive) {
add_keepalive_socket(c, HTTP_KEEPALIVE_TIMEOUT, 0);
} else
abort_connection(c);
}
-void http_func(struct connection *c)
+void
+http_func(struct connection *c)
{
/*setcstate(c, S_CONN);*/
/*set_connection_timeout(c);*/
@@ -205,12 +217,14 @@ void http_func(struct connection *c)
http_send_header(c);
}
-void proxy_func(struct connection *c)
+void
+proxy_func(struct connection *c)
{
http_func(c);
}
-static void add_url_to_str(unsigned char **str, int *l, unsigned char *url)
+static void
+add_url_to_str(unsigned char **str, int *l, unsigned char *url)
{
unsigned char *sp;
for (sp = url; *sp && *sp != POST_CHAR; sp++) {
@@ -223,7 +237,8 @@ static void add_url_to_str(unsigned char **str, int *l, unsigned char *url)
}
}
-static void http_send_header(struct connection *c)
+static void
+http_send_header(struct connection *c)
{
struct http_connection_info *info;
int http10 = http_options.http10;
@@ -244,7 +259,8 @@ static void http_send_header(struct connection *c)
set_connection_timeout_keepal(c);
info = mem_calloc(sizeof(struct http_connection_info));
c->info = info;
- info->https_forward = !c->ssl && proxy && host && !casecmp(host, cast_uchar "https://", 8);
+ info->https_forward = !c->ssl && proxy && host
+ && !casecmp(host, cast_uchar "https://", 8);
if (c->ssl)
proxy = 0;
hdr = init_str();
@@ -263,7 +279,8 @@ http_bad_url:
info->http10 = http10;
if (!info->https_forward) {
post = cast_uchar strchr((char *)host, POST_CHAR);
- if (post) post++;
+ if (post)
+ post++;
}
info->send_close = info->https_forward || http10;
if (info->https_forward) {
@@ -301,7 +318,7 @@ http_bad_url:
int u_host_len;
int u2_len = 0;
if (parse_url(u, NULL, NULL, NULL, NULL, NULL, &u_host,
- &u_host_len, NULL, NULL, NULL, NULL, NULL))
+ &u_host_len, NULL, NULL, NULL, NULL, NULL))
goto http_bad_url;
u2 = init_str();
add_bytes_to_str(&u2, &u2_len, u, u_host + u_host_len - u);
@@ -362,10 +379,14 @@ added_connect:
if (post) {
while (post[0] && post[1]) {
int h1, h2;
- h1 = post[0] <= '9' ? (unsigned)post[0] - '0' : post[0] >= 'A' ? upcase(post[0]) - 'A' + 10 : 0;
+ h1 = post[0] <= '9' ? (unsigned)post[0] - '0'
+ : post[0] >= 'A' ? upcase(post[0]) - 'A' + 10
+ : 0;
if (h1 < 0 || h1 >= 16)
h1 = 0;
- h2 = post[1] <= '9' ? (unsigned)post[1] - '0' : post[1] >= 'A' ? upcase(post[1]) - 'A' + 10 : 0;
+ h2 = post[1] <= '9' ? (unsigned)post[1] - '0'
+ : post[1] >= 'A' ? upcase(post[1]) - 'A' + 10
+ : 0;
if (h2 < 0 || h2 >= 16)
h2 = 0;
add_chr_to_str(&hdr, &l, h1 * 16 + h2);
@@ -377,19 +398,24 @@ added_connect:
setcstate(c, S_SENT);
}
-static void test_restart(struct connection *c)
+static void
+test_restart(struct connection *c)
{
-/* If the cached entity is compressed, request the whole file and turn off compression */
+ /* If the cached entity is compressed, request the whole file and turn
+ * off compression */
if (c->cache && c->from) {
unsigned char *d;
- if ((d = parse_http_header(c->cache->head, cast_uchar "Content-Encoding", NULL))) {
+ if ((d = parse_http_header(c->cache->head,
+ cast_uchar "Content-Encoding",
+ NULL))) {
free(d);
c->from = 0;
c->no_compress = 1;
if (c->tries >= 1) {
unsigned char *h;
if ((h = get_host_name(c->url))) {
- add_blacklist_entry(h, BL_NO_COMPRESSION);
+ add_blacklist_entry(h,
+ BL_NO_COMPRESSION);
free(h);
}
}
@@ -397,23 +423,25 @@ static void test_restart(struct connection *c)
}
}
-static void add_user_agent(unsigned char **hdr, int *l, const char *url)
+static void
+add_user_agent(unsigned char **hdr, int *l, const char *url)
{
add_to_str(hdr, l, cast_uchar "User-Agent: ");
if (SCRUB_HEADERS)
- add_to_str(hdr, l, cast_uchar "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0\r\n");
+ add_to_str(hdr, l,
+ cast_uchar "Mozilla/5.0 (Windows NT 6.1; rv:60.0) "
+ "Gecko/20100101 Firefox/60.0\r\n");
else if (!(*http_options.header.fake_useragent)) {
/*
* Google started to return css-styled page for searches.
* It returns non-css page if the user agent begins with Lynx.
*/
- if (url && (casestrstr(cast_uchar url, cast_uchar "/www.google.")
- || casestrstr(cast_uchar url, cast_uchar "/google."))
- && strstr(url, "/search?")
- && (strstr(url, "?q=")
- || strstr(url, "&q="))
- && !strstr(url, "?tbm=isch")
- && !strstr(url, "&tbm=isch"))
+ if (url
+ && (casestrstr(cast_uchar url, cast_uchar "/www.google.")
+ || casestrstr(cast_uchar url, cast_uchar "/google."))
+ && strstr(url, "/search?")
+ && (strstr(url, "?q=") || strstr(url, "&q="))
+ && !strstr(url, "?tbm=isch") && !strstr(url, "&tbm=isch"))
add_to_str(hdr, l, cast_uchar("Lynx/"));
add_to_str(hdr, l, cast_uchar("Links (" VERSION "; "));
@@ -432,28 +460,35 @@ static void add_user_agent(unsigned char **hdr, int *l, const char *url)
}
}
-static void add_referer(unsigned char **hdr, int *l, unsigned char *url, unsigned char *prev_url)
+static void
+add_referer(unsigned char **hdr, int *l, unsigned char *url,
+ unsigned char *prev_url)
{
add_to_str(hdr, l, cast_uchar "Referer: ");
add_url_to_str(hdr, l, url);
add_to_str(hdr, l, cast_uchar "\r\n");
}
-static void add_accept(unsigned char **hdr, int *l)
+static void
+add_accept(unsigned char **hdr, int *l)
{
if (SCRUB_HEADERS)
add_to_str(hdr, l,
- cast_uchar "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n");
+ cast_uchar
+ "Accept: "
+ "text/html,application/xhtml+xml,application/"
+ "xml;q=0.9,*/*;q=0.8\r\n");
else
add_to_str(hdr, l, cast_uchar "Accept: */*\r\n");
}
-static int advertise_compression(unsigned char *url, struct connection *c)
+static int
+advertise_compression(unsigned char *url, struct connection *c)
{
struct http_connection_info *info = c->info;
char *extd;
if (c->no_compress || http_options.no_compression
- || info->bl_flags & BL_NO_COMPRESSION)
+ || info->bl_flags & BL_NO_COMPRESSION)
return 0;
/* Fix for bugzilla. The attachment may be compressed and if the server
@@ -467,7 +502,9 @@ static int advertise_compression(unsigned char *url, struct connection *c)
return 1;
}
-static void add_accept_encoding(unsigned char **hdr, int *l, unsigned char *url, struct connection *c)
+static void
+add_accept_encoding(unsigned char **hdr, int *l, unsigned char *url,
+ struct connection *c)
{
if (advertise_compression(url, c)) {
int orig_l = *l;
@@ -484,13 +521,14 @@ static void add_accept_encoding(unsigned char **hdr, int *l, unsigned char *url,
}
}
-static void add_accept_charset(unsigned char **hdr, int *l, struct http_connection_info *info)
+static void
+add_accept_charset(unsigned char **hdr, int *l,
+ struct http_connection_info *info)
{
static unsigned char *accept_charset = NULL;
- if (SCRUB_HEADERS
- || info->bl_flags & BL_NO_CHARSET
- || http_options.no_accept_charset)
+ if (SCRUB_HEADERS || info->bl_flags & BL_NO_CHARSET
+ || http_options.no_accept_charset)
return;
if (!accept_charset) {
@@ -515,7 +553,8 @@ static void add_accept_charset(unsigned char **hdr, int *l, struct http_connecti
add_to_str(hdr, l, accept_charset);
}
-static void add_connection(unsigned char **hdr, int *l, int http10, int proxy, int alive)
+static void
+add_connection(unsigned char **hdr, int *l, int http10, int proxy, int alive)
{
if (!http10) {
if (!proxy)
@@ -529,13 +568,16 @@ static void add_connection(unsigned char **hdr, int *l, int http10, int proxy, i
}
}
-static void add_upgrade(unsigned char **hdr, int *l)
+static void
+add_upgrade(unsigned char **hdr, int *l)
{
if (proxies.only_proxies)
- add_to_str(hdr, l, cast_uchar "Upgrade-Insecure-Requests: 1\r\n");
+ add_to_str(hdr, l,
+ cast_uchar "Upgrade-Insecure-Requests: 1\r\n");
}
-static void add_if_modified(unsigned char **hdr, int *l, struct connection *c)
+static void
+add_if_modified(unsigned char **hdr, int *l, struct connection *c)
{
struct cache_entry *e;
if ((e = c->cache)) {
@@ -546,9 +588,11 @@ static void add_if_modified(unsigned char **hdr, int *l, struct connection *c)
unsigned char *m;
if (e->last_modified)
m = stracpy(e->last_modified);
- else if ((m = parse_http_header(e->head, cast_uchar "Date", NULL)))
+ else if ((m = parse_http_header(
+ e->head, cast_uchar "Date", NULL)))
;
- else if ((m = parse_http_header(e->head, cast_uchar "Expires", NULL)))
+ else if ((m = parse_http_header(
+ e->head, cast_uchar "Expires", NULL)))
;
else
return;
@@ -560,7 +604,8 @@ static void add_if_modified(unsigned char **hdr, int *l, struct connection *c)
}
}
-static void add_range(unsigned char **hdr, int *l, unsigned char *url, struct connection *c)
+static void
+add_range(unsigned char **hdr, int *l, unsigned char *url, struct connection *c)
{
struct cache_entry *e;
struct http_connection_info *info = c->info;
@@ -569,21 +614,25 @@ static void add_range(unsigned char **hdr, int *l, unsigned char *url, struct co
if (!get_http_code(e->head, &code, NULL) && code >= 300)
return;
}
- if (c->from && c->no_cache < NC_IF_MOD && !(info->bl_flags & BL_NO_RANGE)) {
+ if (c->from && c->no_cache < NC_IF_MOD
+ && !(info->bl_flags & BL_NO_RANGE)) {
add_to_str(hdr, l, cast_uchar "Range: bytes=");
add_num_to_str(hdr, l, c->from);
add_to_str(hdr, l, cast_uchar "-\r\n");
}
}
-static void add_pragma_no_cache(unsigned char **hdr, int *l, int no_cache)
+static void
+add_pragma_no_cache(unsigned char **hdr, int *l, int no_cache)
{
if (no_cache >= NC_PR_NO_CACHE)
add_to_str(hdr, l,
- cast_uchar "Pragma: no-cache\r\nCache-Control: no-cache\r\n");
+ cast_uchar
+ "Pragma: no-cache\r\nCache-Control: no-cache\r\n");
}
-static void add_proxy_auth_string(unsigned char **hdr, int *l, unsigned char *url)
+static void
+add_proxy_auth_string(unsigned char **hdr, int *l, unsigned char *url)
{
unsigned char *h;
if ((h = get_auth_string(url, 1))) {
@@ -592,7 +641,8 @@ static void add_proxy_auth_string(unsigned char **hdr, int *l, unsigned char *ur
}
}
-static void add_auth_string(unsigned char **hdr, int *l, unsigned char *url)
+static void
+add_auth_string(unsigned char **hdr, int *l, unsigned char *url)
{
unsigned char *h;
if ((h = get_auth_string(url, 0))) {
@@ -601,7 +651,8 @@ static void add_auth_string(unsigned char **hdr, int *l, unsigned char *url)
}
}
-static void add_post_header(unsigned char **hdr, int *l, unsigned char **post)
+static void
+add_post_header(unsigned char **hdr, int *l, unsigned char **post)
{
if (*post) {
unsigned char *pd = cast_uchar strchr((char *)*post, '\n');
@@ -617,7 +668,8 @@ static void add_post_header(unsigned char **hdr, int *l, unsigned char **post)
}
}
-static void add_extra_options(unsigned char **hdr, int *l)
+static void
+add_extra_options(unsigned char **hdr, int *l)
{
unsigned char *p = http_options.header.extra_header;
while (1) {
@@ -629,7 +681,8 @@ static void add_extra_options(unsigned char **hdr, int *l)
if (c && casecmp(s, cast_uchar "Cookie:", 7)) {
unsigned char *v = NULL;
unsigned char *cc = memacpy(s, c - s);
- unsigned char *x = parse_http_header(*hdr, cc, &v);
+ unsigned char *x =
+ parse_http_header(*hdr, cc, &v);
free(cc);
if (x) {
unsigned char *new_hdr;
@@ -637,11 +690,14 @@ static void add_extra_options(unsigned char **hdr, int *l)
free(x);
new_hdr = init_str();
new_l = 0;
- add_bytes_to_str(&new_hdr, &new_l, *hdr, v - *hdr);
+ add_bytes_to_str(&new_hdr, &new_l, *hdr,
+ v - *hdr);
while (*++c == ' ')
;
add_to_str(&new_hdr, &new_l, c);
- add_to_str(&new_hdr, &new_l, v + strcspn((char *)v, "\r\n"));
+ add_to_str(
+ &new_hdr, &new_l,
+ v + strcspn((char *)v, "\r\n"));
free(*hdr);
*hdr = new_hdr;
*l = new_l;
@@ -659,13 +715,15 @@ already_added:
}
}
-static int is_line_in_buffer(struct read_buffer *rb)
+static int
+is_line_in_buffer(struct read_buffer *rb)
{
int l;
for (l = 0; l < rb->len; l++) {
if (rb->data[l] == 10)
return l + 1;
- if (l < rb->len - 1 && rb->data[l] == 13 && rb->data[l + 1] == 10)
+ if (l < rb->len - 1 && rb->data[l] == 13
+ && rb->data[l + 1] == 10)
return l + 2;
if (l == rb->len - 1 && rb->data[l] == 13)
return 0;
@@ -675,7 +733,8 @@ static int is_line_in_buffer(struct read_buffer *rb)
return 0;
}
-static void read_http_data(struct connection *c, struct read_buffer *rb)
+static void
+read_http_data(struct connection *c, struct read_buffer *rb)
{
struct http_connection_info *info = c->info;
int a;
@@ -733,8 +792,10 @@ next_chunk:
char *end;
long n = 0;
if (l != -1)
- n = strtol(cast_const_char rb->data, &end, 16);
- if (l == -1 || n < 0 || n >= INT_MAX || cast_uchar end == rb->data) {
+ n = strtol(cast_const_char rb->data,
+ &end, 16);
+ if (l == -1 || n < 0 || n >= INT_MAX
+ || cast_uchar end == rb->data) {
setcstate(c, S_HTTP_ERROR);
abort_connection(c);
return;
@@ -769,8 +830,11 @@ next_chunk:
if (rb->data[0] == 10)
kill_buffer_data(rb, 1);
else {
- if (rb->data[0] != 13 || (rb->len >= 2
- && ((unsigned char *)rb->data)[1] != 10)) {
+ if (rb->data[0] != 13
+ || (rb->len >= 2
+ && ((unsigned char *)
+ rb->data)[1]
+ != 10)) {
setcstate(c, S_HTTP_ERROR);
abort_connection(c);
return;
@@ -789,7 +853,8 @@ read_more:
setcstate(c, S_TRANS);
}
-static int get_header(struct read_buffer *rb)
+static int
+get_header(struct read_buffer *rb)
{
int i;
if (rb->len <= 0)
@@ -827,7 +892,8 @@ static int get_header(struct read_buffer *rb)
return 0;
}
-static void http_got_header(struct connection *c, struct read_buffer *rb)
+static void
+http_got_header(struct connection *c, struct read_buffer *rb)
{
off_t cf;
int state = c->state != S_PROC ? S_GETH : S_PROC;
@@ -871,14 +937,17 @@ again:
head = memacpy(rb->data, a);
kill_buffer_data(rb, a);
} else
- head = stracpy(cast_uchar "HTTP/0.9 200 OK\r\nContent-Type: text/html\r\n\r\n");
+ head = stracpy(
+ cast_uchar
+ "HTTP/0.9 200 OK\r\nContent-Type: text/html\r\n\r\n");
if (get_http_code(head, &h, &version) || h == 101) {
free(head);
setcstate(c, S_HTTP_ERROR);
abort_connection(c);
return;
}
- if (check_http_server_bugs(host, c->info, head) && is_connection_restartable(c)) {
+ if (check_http_server_bugs(host, c->info, head)
+ && is_connection_restartable(c)) {
free(head);
setcstate(c, S_RESTART);
retry_connection(c);
@@ -912,7 +981,8 @@ again:
if (h != 401 && h != 407) {
unsigned char *cookie;
unsigned char *ch = head;
- while ((cookie = parse_http_header(ch, cast_uchar "Set-Cookie", &ch))) {
+ while ((cookie = parse_http_header(ch, cast_uchar "Set-Cookie",
+ &ch))) {
set_cookie(NULL, host, cookie);
free(cookie);
}
@@ -934,7 +1004,8 @@ again:
}
if (h == 431) {
unsigned char *hs;
- if (!(info->bl_flags & BL_NO_CHARSET) && (hs = get_host_name(host))) {
+ if (!(info->bl_flags & BL_NO_CHARSET)
+ && (hs = get_host_name(host))) {
free(head);
add_blacklist_entry(hs, BL_NO_CHARSET);
free(hs);
@@ -945,7 +1016,8 @@ again:
}
}
if ((h == 500 || h == 502 || h == 503 || h == 504)
- && http_options.retry_internal_errors && is_connection_restartable(c)) {
+ && http_options.retry_internal_errors
+ && is_connection_restartable(c)) {
/* !!! FIXME: wait some time ... */
if (is_last_try(c)) {
unsigned char *h;
@@ -987,16 +1059,18 @@ again:
if ((d = parse_http_header(head, cast_uchar "Cache-Control", NULL))) {
unsigned char *f = d;
while (1) {
- while (*f && (*f == ' ' || *f == ',')) f++;
+ while (*f && (*f == ' ' || *f == ','))
+ f++;
if (!*f)
break;
if (!casecmp(f, cast_uchar "no-cache", 8)
- || !casecmp(f, cast_uchar "must-revalidate", 15))
+ || !casecmp(f, cast_uchar "must-revalidate", 15))
e->expire_time = 1;
if (!casecmp(f, cast_uchar "max-age=", 8)) {
if (e->expire_time != 1) {
errno = 0;
- EINTRLOOPX(e->expire_time, time(NULL), (time_t)-1);
+ EINTRLOOPX(e->expire_time, time(NULL),
+ (time_t)-1);
e->expire_time += atoi((char *)(f + 8));
}
}
@@ -1016,24 +1090,29 @@ again:
if ((h == 302 || h == 303 || h == 307 || h == 511) && !e->expire_time)
e->expire_time = 1;
if (h == 301 || h == 302 || h == 303 || h == 307 || h == 308) {
- if ((d = parse_http_header(e->head, cast_uchar "Location", NULL))) {
+ if ((d = parse_http_header(e->head, cast_uchar "Location",
+ NULL))) {
unsigned char *user, *ins;
unsigned char *newuser, *newpassword;
if (!parse_url(d, NULL, &user, NULL, NULL, NULL, &ins,
- NULL, NULL, NULL, NULL, NULL, NULL)
- && !user && ins && (newuser = get_user_name(host))) {
+ NULL, NULL, NULL, NULL, NULL, NULL)
+ && !user && ins
+ && (newuser = get_user_name(host))) {
if (*newuser) {
int ins_off = (int)(ins - d);
newpassword = get_pass(host);
if (!newpassword)
- newpassword = stracpy(cast_uchar "");
+ newpassword =
+ stracpy(cast_uchar "");
add_to_strn(&newuser, cast_uchar ":");
add_to_strn(&newuser, newpassword);
add_to_strn(&newuser, cast_uchar "@");
extend_str(&d, strlen((char *)newuser));
ins = d + ins_off;
- memmove(ins + strlen((char *)newuser), ins, strlen((char *)ins) + 1);
- memcpy(ins, newuser, strlen((char *)newuser));
+ memmove(ins + strlen((char *)newuser),
+ ins, strlen((char *)ins) + 1);
+ memcpy(ins, newuser,
+ strlen((char *)newuser));
free(newpassword);
}
free(newuser);
@@ -1042,7 +1121,8 @@ again:
e->redirect = d;
if (h == 307 || h == 308) {
unsigned char *p;
- if ((p = cast_uchar strchr(cast_const_char host, POST_CHAR)))
+ if ((p = cast_uchar strchr(cast_const_char host,
+ POST_CHAR)))
add_to_strn(&e->redirect, p);
}
}
@@ -1053,7 +1133,8 @@ again:
info->length = -1;
info->version = version;
if ((d = parse_http_header(e->head, cast_uchar "Connection", NULL))
- || (d = parse_http_header(e->head, cast_uchar "Proxy-Connection", NULL))) {
+ || (d = parse_http_header(e->head, cast_uchar "Proxy-Connection",
+ NULL))) {
if (!casestrcmp(d, cast_uchar "close"))
info->close = 1;
free(d);
@@ -1061,10 +1142,12 @@ again:
info->close = 1;
cf = c->from;
c->from = 0;
- if ((d = parse_http_header(e->head, cast_uchar "Content-Range", NULL))) {
+ if ((d = parse_http_header(e->head, cast_uchar "Content-Range",
+ NULL))) {
if (strlen((char *)d) > 6) {
d[5] = 0;
- if (!(casestrcmp(d, cast_uchar "bytes")) && d[6] >= '0' && d[6] <= '9') {
+ if (!(casestrcmp(d, cast_uchar "bytes")) && d[6] >= '0'
+ && d[6] <= '9') {
long f = strtol((char *)(d + 6), NULL, 10);
if (f >= 0 && (off_t)f >= 0 && (off_t)f == f)
c->from = f;
@@ -1072,7 +1155,8 @@ again:
}
free(d);
} else if (h == 206) {
-/* Hmm ... some servers send 206 partial but don't send Content-Range */
+ /* Hmm ... some servers send 206 partial but don't send
+ * Content-Range */
c->from = cf;
}
if (cf && !c->from && !c->unrestartable)
@@ -1082,7 +1166,8 @@ again:
abort_connection(c);
return;
}
- if ((d = parse_http_header(e->head, cast_uchar "Content-Length", NULL))) {
+ if ((d = parse_http_header(e->head, cast_uchar "Content-Length",
+ NULL))) {
char *ep;
long l = strtol((char *)d, &ep, 10);
if (!*ep && l >= 0 && (off_t)l >= 0 && (off_t)l == l) {
@@ -1093,7 +1178,8 @@ again:
}
free(d);
}
- if ((d = parse_http_header(e->head, cast_uchar "Accept-Ranges", NULL))) {
+ if ((d = parse_http_header(e->head, cast_uchar "Accept-Ranges",
+ NULL))) {
if (!casestrcmp(d, cast_uchar "none") && !c->unrestartable)
c->unrestartable = 1;
free(d);
@@ -1101,7 +1187,8 @@ again:
c->unrestartable = 1;
if (info->bl_flags & BL_NO_RANGE && !c->unrestartable)
c->unrestartable = 1;
- if ((d = parse_http_header(e->head, cast_uchar "Transfer-Encoding", NULL))) {
+ if ((d = parse_http_header(e->head, cast_uchar "Transfer-Encoding",
+ NULL))) {
if (!casestrcmp(d, cast_uchar "chunked")) {
info->length = -2;
info->chunk_remaining = -1;
@@ -1110,7 +1197,8 @@ again:
}
if (!info->close && info->length == -1)
info->close = 1;
- if ((d = parse_http_header(e->head, cast_uchar "Last-Modified", NULL))) {
+ if ((d = parse_http_header(e->head, cast_uchar "Last-Modified",
+ NULL))) {
if (e->last_modified && casestrcmp(e->last_modified, d)) {
delete_entry_content(e);
if (c->from) {
@@ -1127,12 +1215,11 @@ again:
free(d);
}
if (!e->last_modified
- && (d = parse_http_header(e->head, cast_uchar "Date", NULL)))
+ && (d = parse_http_header(e->head, cast_uchar "Date", NULL)))
e->last_modified = d;
if (info->length == -1 || (version < 11 && info->close))
rb->close = 1;
-
/*
* Truncate entry if:
* - it is compressed (the mix of an old and new document
@@ -1140,7 +1227,8 @@ again:
* - it was http authentication (the user doesn't need to see the
* authentication message).
*/
- if ((d = parse_http_header(e->head, cast_uchar "Content-Encoding", NULL))) {
+ if ((d = parse_http_header(e->head, cast_uchar "Content-Encoding",
+ NULL))) {
free(d);
truncate_entry(e, c->from, 0);
} else if (previous_http_code == 401 || previous_http_code == 407)
@@ -1154,7 +1242,8 @@ again:
read_http_data(c, rb);
}
-static void http_get_header(struct connection *c)
+static void
+http_get_header(struct connection *c)
{
struct read_buffer *rb;
set_connection_timeout_keepal(c);
diff --git a/https.c b/https.c
@@ -27,8 +27,7 @@
static SSL_CTX *contexts = NULL;
struct session_cache_entry {
- list_entry_1st
- uttime absolute_time;
+ list_entry_1st uttime absolute_time;
SSL_CTX *ctx;
SSL_SESSION *session;
int port;
@@ -37,7 +36,8 @@ struct session_cache_entry {
static struct list_head session_cache = { &session_cache, &session_cache };
-static int ssl_password_callback(char *buf, int size, int rwflag, void *userdata)
+static int
+ssl_password_callback(char *buf, int size, int rwflag, void *userdata)
{
const size_t sl = strlen((char *)ssl_options.client_cert_password);
if (size > sl)
@@ -46,7 +46,8 @@ static int ssl_password_callback(char *buf, int size, int rwflag, void *userdata
return size;
}
-links_ssl *getSSL(void)
+links_ssl *
+getSSL(void)
{
links_ssl *ssl;
@@ -77,7 +78,8 @@ links_ssl *getSSL(void)
return ssl;
}
-void freeSSL(links_ssl *ssl)
+void
+freeSSL(links_ssl *ssl)
{
if (!ssl || ssl == DUMMY)
return;
@@ -88,35 +90,41 @@ void freeSSL(links_ssl *ssl)
free(ssl);
}
-void ssl_finish(void)
+void
+ssl_finish(void)
{
SSL_CTX_free(contexts);
contexts = NULL;
}
-void https_func(struct connection *c)
+void
+https_func(struct connection *c)
{
c->ssl = DUMMY;
http_func(c);
}
-static int verify_ssl_host_name(X509 *server_cert, char *host)
+static int
+verify_ssl_host_name(X509 *server_cert, char *host)
{
int v;
char ipv4_address[4];
char ipv6_address[16];
if (!numeric_ip_address(host, ipv4_address))
- v = X509_check_ip(server_cert, (unsigned char *)ipv4_address, 4, 0);
+ v = X509_check_ip(server_cert, (unsigned char *)ipv4_address, 4,
+ 0);
else if (!numeric_ipv6_address(host, ipv6_address, NULL))
- v = X509_check_ip(server_cert, (unsigned char *)ipv6_address, 16, 0);
+ v = X509_check_ip(server_cert, (unsigned char *)ipv6_address,
+ 16, 0);
else
v = X509_check_host(server_cert, host, strlen(host), 0, NULL);
return v == 1 ? 0 : S_INVALID_CERTIFICATE;
}
-static unsigned char *extract_field(const char *str, const char *field)
+static unsigned char *
+extract_field(const char *str, const char *field)
{
size_t len;
char *f = strstr(str, field);
@@ -127,7 +135,8 @@ static unsigned char *extract_field(const char *str, const char *field)
return memacpy(cast_uchar f, len);
}
-static char *extract_ca(const char *str)
+static char *
+extract_ca(const char *str)
{
unsigned char *c, *o;
c = extract_field(str, "/C=");
@@ -147,7 +156,8 @@ static char *extract_ca(const char *str)
return (char *)o;
}
-int verify_ssl_certificate(links_ssl *ssl, unsigned char *host)
+int
+verify_ssl_certificate(links_ssl *ssl, unsigned char *host)
{
X509 *server_cert;
int ret;
@@ -177,13 +187,17 @@ int verify_ssl_certificate(links_ssl *ssl, unsigned char *host)
X509 *cert = sk_X509_value(certs, i);
X509_NAME *name;
name = X509_get_issuer_name(cert);
- n = X509_NAME_oneline(name, space, sizeof(space));
+ n = X509_NAME_oneline(name, space,
+ sizeof(space));
if (n) {
char *ca = extract_ca(n);
if (!last_ca || strcmp(ca, last_ca)) {
if (casl)
- add_to_str(&cas, &casl, CERT_RIGHT_ARROW);
- add_to_str(&cas, &casl, cast_uchar ca);
+ add_to_str(
+ &cas, &casl,
+ CERT_RIGHT_ARROW);
+ add_to_str(&cas, &casl,
+ cast_uchar ca);
free(last_ca);
last_ca = ca;
} else {
@@ -202,7 +216,8 @@ int verify_ssl_certificate(links_ssl *ssl, unsigned char *host)
return ret;
}
-int verify_ssl_cipher(links_ssl *ssl)
+int
+verify_ssl_cipher(links_ssl *ssl)
{
const char *cipher;
if (SSL_get_cipher_bits(ssl->ssl, NULL) < 112)
@@ -213,7 +228,8 @@ int verify_ssl_cipher(links_ssl *ssl)
return 0;
}
-int ssl_not_reusable(links_ssl *ssl)
+int
+ssl_not_reusable(links_ssl *ssl)
{
const char *cipher;
if (!ssl || ssl == DUMMY)
@@ -221,16 +237,15 @@ int ssl_not_reusable(links_ssl *ssl)
ssl->bytes_read = (ssl->bytes_read + 4095) & ~4095;
ssl->bytes_written = (ssl->bytes_written + 4095) & ~4095;
if ((cipher = SSL_get_cipher_name(ssl->ssl)))
- if (strstr(cipher, "RC4-")
- || strstr(cipher, "DES-")
- || strstr(cipher, "RC2-")
- || strstr(cipher, "IDEA-")
- || strstr(cipher, "GOST-"))
+ if (strstr(cipher, "RC4-") || strstr(cipher, "DES-")
+ || strstr(cipher, "RC2-") || strstr(cipher, "IDEA-")
+ || strstr(cipher, "GOST-"))
return ssl->bytes_read + ssl->bytes_written >= 1 << 20;
return 0;
}
-unsigned char *get_cipher_string(links_ssl *ssl)
+unsigned char *
+get_cipher_string(links_ssl *ssl)
{
const char *version, *cipher;
unsigned char *s = init_str();
@@ -250,19 +265,22 @@ unsigned char *get_cipher_string(links_ssl *ssl)
return s;
}
-static struct session_cache_entry *find_session_cache_entry(SSL_CTX *ctx, char *host, int port)
+static struct session_cache_entry *
+find_session_cache_entry(SSL_CTX *ctx, char *host, int port)
{
struct session_cache_entry *sce = NULL;
struct list_head *lsce;
- foreach(struct session_cache_entry, sce, lsce, session_cache)
+ foreach (struct session_cache_entry, sce, lsce, session_cache)
if (sce->ctx == ctx && !strcmp(&sce->host, host))
return sce;
return NULL;
}
-SSL_SESSION *get_session_cache_entry(SSL_CTX *ctx, unsigned char *host, int port)
+SSL_SESSION *
+get_session_cache_entry(SSL_CTX *ctx, unsigned char *host, int port)
{
- struct session_cache_entry *sce = find_session_cache_entry(ctx, (char *)host, port);
+ struct session_cache_entry *sce =
+ find_session_cache_entry(ctx, (char *)host, port);
if (!sce)
return NULL;
if (get_absolute_time() - sce->absolute_time > SESSION_TIMEOUT)
@@ -270,9 +288,11 @@ SSL_SESSION *get_session_cache_entry(SSL_CTX *ctx, unsigned char *host, int port
return sce->session;
}
-static void set_session_cache_entry(SSL_CTX *ctx, char *host, int port, SSL_SESSION *s)
+static void
+set_session_cache_entry(SSL_CTX *ctx, char *host, int port, SSL_SESSION *s)
{
- struct session_cache_entry *sce = find_session_cache_entry(ctx, host, port);
+ struct session_cache_entry *sce =
+ find_session_cache_entry(ctx, host, port);
size_t sl;
if (sce) {
SSL_SESSION_free(sce->session);
@@ -287,7 +307,8 @@ static void set_session_cache_entry(SSL_CTX *ctx, char *host, int port, SSL_SESS
if (!s)
return;
sl = strlen(host);
- if (sl > INT_MAX - sizeof(struct session_cache_entry)) return;
+ if (sl > INT_MAX - sizeof(struct session_cache_entry))
+ return;
sce = xmalloc(sizeof(struct session_cache_entry) + sl);
sce->absolute_time = get_absolute_time();
sce->ctx = ctx;
@@ -297,7 +318,8 @@ static void set_session_cache_entry(SSL_CTX *ctx, char *host, int port, SSL_SESS
add_to_list(session_cache, sce);
}
-void retrieve_ssl_session(struct connection *c)
+void
+retrieve_ssl_session(struct connection *c)
{
if (c->ssl && !c->ssl->session_retrieved && !proxies.only_proxies) {
SSL_SESSION *s;
@@ -318,7 +340,8 @@ void retrieve_ssl_session(struct connection *c)
}
}
-static int shrink_session_cache(int u)
+static int
+shrink_session_cache(int u)
{
uttime now = get_absolute_time();
struct session_cache_entry *d = NULL;
@@ -328,8 +351,9 @@ static int shrink_session_cache(int u)
d = list_struct(session_cache.prev, struct session_cache_entry);
goto delete_last;
}
- foreach(struct session_cache_entry, d, ld, session_cache)
- if (u == SH_FREE_ALL || now - d->absolute_time > SESSION_TIMEOUT) {
+ foreach (struct session_cache_entry, d, ld, session_cache)
+ if (u == SH_FREE_ALL
+ || now - d->absolute_time > SESSION_TIMEOUT) {
delete_last:
ld = d->list_entry.prev;
del_from_list(d);
@@ -340,7 +364,8 @@ delete_last:
return f | (list_empty(session_cache) ? ST_CACHE_EMPTY : 0);
}
-unsigned long session_info(int type)
+unsigned long
+session_info(int type)
{
switch (type) {
case CI_FILES:
@@ -351,7 +376,9 @@ unsigned long session_info(int type)
return 0;
}
-void init_session_cache(void)
+void
+init_session_cache(void)
{
- register_cache_upcall(shrink_session_cache, 0, (unsigned char *)"session");
+ register_cache_upcall(shrink_session_cache, 0,
+ (unsigned char *)"session");
}
diff --git a/kbd.c b/kbd.c
@@ -7,15 +7,15 @@
#include "links.h"
-#define OUT_BUF_SIZE 10240
-#define IN_BUF_SIZE 64
+#define OUT_BUF_SIZE 10240
+#define IN_BUF_SIZE 64
-#define USE_TWIN_MOUSE 1
-#define BRACKETED_PASTE 2
+#define USE_TWIN_MOUSE 1
+#define BRACKETED_PASTE 2
-#define TW_BUTT_LEFT 1
-#define TW_BUTT_MIDDLE 2
-#define TW_BUTT_RIGHT 4
+#define TW_BUTT_LEFT 1
+#define TW_BUTT_MIDDLE 2
+#define TW_BUTT_RIGHT 4
struct itrm {
int std_in;
@@ -41,29 +41,34 @@ static void in_kbd(void *);
static struct itrm *ditrm = NULL;
-
-int is_blocked(void)
+int
+is_blocked(void)
{
return ditrm && ditrm->blocked;
}
-void free_all_itrms(void)
+void
+free_all_itrms(void)
{
- if (ditrm) ditrm->free_trm(ditrm);
+ if (ditrm)
+ ditrm->free_trm(ditrm);
}
-static void itrm_error(void *itrm_)
+static void
+itrm_error(void *itrm_)
{
struct itrm *itrm = (struct itrm *)itrm_;
itrm->free_trm(itrm);
terminate_loop = 1;
}
-static void write_ev_queue(void *itrm_)
+static void
+write_ev_queue(void *itrm_)
{
struct itrm *itrm = (struct itrm *)itrm_;
int l, to_write;
- if (!itrm->eqlen) internal("event queue empty");
+ if (!itrm->eqlen)
+ internal("event queue empty");
to_write = itrm->eqlen;
retry:
EINTRLOOP(l, (int)write(itrm->sock_out, itrm->ev_queue, to_write));
@@ -75,13 +80,18 @@ retry:
itrm_error(itrm);
}
memmove(itrm->ev_queue, itrm->ev_queue + l, itrm->eqlen -= l);
- if (!itrm->eqlen) set_handlers(itrm->sock_out, get_handler(itrm->sock_out, H_READ), NULL, get_handler_data(itrm->sock_out));
+ if (!itrm->eqlen)
+ set_handlers(itrm->sock_out,
+ get_handler(itrm->sock_out, H_READ), NULL,
+ get_handler_data(itrm->sock_out));
}
-static void queue_event(struct itrm *itrm, unsigned char *data, int len)
+static void
+queue_event(struct itrm *itrm, unsigned char *data, int len)
{
int w = 0;
- if (!len) return;
+ if (!len)
+ return;
if (!itrm->eqlen && can_write(itrm->sock_out)) {
int to_write = len;
retry:
@@ -98,45 +108,61 @@ retry:
if (w < len) {
if ((unsigned)itrm->eqlen + (unsigned)(len - w) > INT_MAX)
overalloc();
- itrm->ev_queue = xrealloc(itrm->ev_queue, itrm->eqlen + len - w);
+ itrm->ev_queue =
+ xrealloc(itrm->ev_queue, itrm->eqlen + len - w);
memcpy(itrm->ev_queue + itrm->eqlen, data + w, len - w);
itrm->eqlen += len - w;
- set_handlers(itrm->sock_out, get_handler(itrm->sock_out, H_READ), write_ev_queue, itrm);
+ set_handlers(itrm->sock_out,
+ get_handler(itrm->sock_out, H_READ),
+ write_ev_queue, itrm);
}
}
-void kbd_ctrl_c(void)
+void
+kbd_ctrl_c(void)
{
struct links_event ev = { EV_KBD, KBD_CTRL_C, 0, 0 };
- if (ditrm) ditrm->queue_event(ditrm, (unsigned char *)&ev, sizeof(struct links_event));
+ if (ditrm)
+ ditrm->queue_event(ditrm, (unsigned char *)&ev,
+ sizeof(struct links_event));
}
unsigned char init_seq[] = "\033)0\0337";
-unsigned char init_seq_x_mouse[] = "\033[?1000h\033[?1002h\033[?1005l\033[?1015l\033[?1006h\033[?2004h";
+unsigned char init_seq_x_mouse[] =
+ "\033[?1000h\033[?1002h\033[?1005l\033[?1015l\033[?1006h\033[?2004h";
unsigned char init_seq_tw_mouse[] = "\033[?9h";
unsigned char term_seq[] = "\033[2J\0338\r \b";
-unsigned char term_seq_x_mouse[] = "\033[?1000l\r \r\033[?1002l\r \r\033[?1006l\r \r\033[?2004l\r \r";
+unsigned char term_seq_x_mouse[] =
+ "\033[?1000l\r \r\033[?1002l\r \r\033[?1006l\r "
+ "\r\033[?2004l\r \r";
unsigned char term_seq_tw_mouse[] = "\033[?9l";
-static void send_init_sequence(int h, int flags)
+static void
+send_init_sequence(int h, int flags)
{
hard_write(h, init_seq, (int)strlen(cast_const_char init_seq));
if (flags & USE_TWIN_MOUSE)
- hard_write(h, init_seq_tw_mouse, (int)strlen(cast_const_char init_seq_tw_mouse));
+ hard_write(h, init_seq_tw_mouse,
+ (int)strlen(cast_const_char init_seq_tw_mouse));
else
- hard_write(h, init_seq_x_mouse, (int)strlen(cast_const_char init_seq_x_mouse));
+ hard_write(h, init_seq_x_mouse,
+ (int)strlen(cast_const_char init_seq_x_mouse));
}
-static void send_term_sequence(int h, int flags)
+static void
+send_term_sequence(int h, int flags)
{
hard_write(h, term_seq, (int)strlen(cast_const_char term_seq));
if (flags & USE_TWIN_MOUSE)
- hard_write(h, term_seq_tw_mouse, (int)strlen(cast_const_char term_seq_tw_mouse));
+ hard_write(h, term_seq_tw_mouse,
+ (int)strlen(cast_const_char term_seq_tw_mouse));
else
- hard_write(h, term_seq_x_mouse, (int)strlen(cast_const_char term_seq_x_mouse));
+ hard_write(h, term_seq_x_mouse,
+ (int)strlen(cast_const_char term_seq_x_mouse));
}
-static void resize_terminal(int x, int y)
+static void
+resize_terminal(int x, int y)
{
struct links_event ev = { EV_RESIZE, 0, 0, 0 };
ev.x = x;
@@ -144,7 +170,8 @@ static void resize_terminal(int x, int y)
queue_event(ditrm, (unsigned char *)&ev, sizeof(struct links_event));
}
-static void os_cfmakeraw(struct termios *t)
+static void
+os_cfmakeraw(struct termios *t)
{
cfmakeraw(t);
#ifdef VMIN
@@ -155,22 +182,23 @@ static void os_cfmakeraw(struct termios *t)
#endif
}
-static int ttcgetattr(int fd, struct termios *t)
+static int
+ttcgetattr(int fd, struct termios *t)
{
int r;
block_signals(
#ifdef SIGTTOU
- SIGTTOU
+ SIGTTOU
#else
- 0
+ 0
#endif
- ,
+ ,
#ifdef SIGTTIN
- SIGTTIN
+ SIGTTIN
#else
- 0
+ 0
#endif
- );
+ );
#ifdef SIGTTOU
interruptible_signal(SIGTTOU, 1);
#endif
@@ -188,22 +216,23 @@ static int ttcgetattr(int fd, struct termios *t)
return r;
}
-static int ttcsetattr(int fd, int a, struct termios *t)
+static int
+ttcsetattr(int fd, int a, struct termios *t)
{
int r;
block_signals(
#ifdef SIGTTOU
- SIGTTOU
+ SIGTTOU
#else
- 0
+ 0
#endif
- ,
+ ,
#ifdef SIGTTIN
- SIGTTIN
+ SIGTTIN
#else
- 0
+ 0
#endif
- );
+ );
#ifdef SIGTTOU
interruptible_signal(SIGTTOU, 1);
#endif
@@ -223,10 +252,12 @@ static int ttcsetattr(int fd, int a, struct termios *t)
static struct termios saved_termios;
-static int setraw(int ctl, int save)
+static int
+setraw(int ctl, int save)
{
struct termios t;
- if (ctl < 0) return 0;
+ if (ctl < 0)
+ return 0;
memset(&t, 0, sizeof(struct termios));
if (ttcgetattr(ctl, &t)) {
/*fprintf(stderr, "getattr result %s\n", strerror(errno));*/
@@ -237,10 +268,12 @@ static int setraw(int ctl, int save)
* Linux returns EIO
* FreeBSD returns ENXIO
*/
- if (errno == EIO || errno == ENXIO) return 0;
+ if (errno == EIO || errno == ENXIO)
+ return 0;
return -1;
}
- if (save) memcpy(&saved_termios, &t, sizeof(struct termios));
+ if (save)
+ memcpy(&saved_termios, &t, sizeof(struct termios));
os_cfmakeraw(&t);
t.c_lflag |= ISIG;
#ifdef TOSTOP
@@ -253,13 +286,16 @@ static int setraw(int ctl, int save)
return 0;
}
-static void setcooked(int ctl)
+static void
+setcooked(int ctl)
{
- if (ctl < 0) return;
+ if (ctl < 0)
+ return;
ttcsetattr(ctl, TCSANOW, &saved_termios);
}
-void handle_trm(int sock_out, void *init_string, int init_len)
+void
+handle_trm(int sock_out, void *init_string, int init_len)
{
struct itrm *itrm;
struct links_event ev = { EV_INIT, 0, 0, 0 };
@@ -285,8 +321,10 @@ void handle_trm(int sock_out, void *init_string, int init_len)
queue_event(itrm, (unsigned char *)&ev, sizeof(struct links_event));
xwin = is_xterm() * ENV_XWIN + is_screen() * ENV_SCREEN;
itrm->flags = 0;
- if (!(ts = cast_uchar getenv("TERM"))) ts = cast_uchar "";
- if (strlen(cast_const_char ts) >= MAX_TERM_LEN) queue_event(itrm, ts, MAX_TERM_LEN);
+ if (!(ts = cast_uchar getenv("TERM")))
+ ts = cast_uchar "";
+ if (strlen(cast_const_char ts) >= MAX_TERM_LEN)
+ queue_event(itrm, ts, MAX_TERM_LEN);
else {
unsigned char *mm;
int ll = MAX_TERM_LEN - (int)strlen(cast_const_char ts);
@@ -295,8 +333,10 @@ void handle_trm(int sock_out, void *init_string, int init_len)
queue_event(itrm, mm, ll);
free(mm);
}
- if (!(ts = get_cwd())) ts = stracpy(cast_uchar "");
- if (strlen(cast_const_char ts) >= MAX_CWD_LEN) queue_event(itrm, ts, MAX_CWD_LEN);
+ if (!(ts = get_cwd()))
+ ts = stracpy(cast_uchar "");
+ if (strlen(cast_const_char ts) >= MAX_CWD_LEN)
+ queue_event(itrm, ts, MAX_CWD_LEN);
else {
unsigned char *mm;
int ll = MAX_CWD_LEN - (int)strlen(cast_const_char ts);
@@ -317,13 +357,17 @@ void handle_trm(int sock_out, void *init_string, int init_len)
send_init_sequence(1, itrm->flags);
}
-int unblock_itrm(int fd)
+int
+unblock_itrm(int fd)
{
struct itrm *itrm = ditrm;
int x, y;
- if (!itrm) return -1;
- if (setraw(itrm->ctl_in, 0)) return -1;
- if (itrm->blocked != fd + 1) return -2;
+ if (!itrm)
+ return -1;
+ if (setraw(itrm->ctl_in, 0))
+ return -1;
+ if (itrm->blocked != fd + 1)
+ return -2;
itrm->blocked = 0;
send_init_sequence(itrm->std_out, itrm->flags);
set_handlers(itrm->std_in, in_kbd, NULL, itrm);
@@ -333,11 +377,14 @@ int unblock_itrm(int fd)
return 0;
}
-void block_itrm(int fd)
+void
+block_itrm(int fd)
{
struct itrm *itrm = ditrm;
- if (!itrm) return;
- if (itrm->blocked) return;
+ if (!itrm)
+ return;
+ if (itrm->blocked)
+ return;
itrm->blocked = fd + 1;
unhandle_terminal_resize();
itrm->mouse_h = NULL;
@@ -346,9 +393,11 @@ void block_itrm(int fd)
set_handlers(itrm->std_in, NULL, NULL, itrm);
}
-static void free_trm(struct itrm *itrm)
+static void
+free_trm(struct itrm *itrm)
{
- if (!itrm) return;
+ if (!itrm)
+ return;
set_window_title(itrm->orig_title);
free(itrm->orig_title);
itrm->orig_title = NULL;
@@ -360,13 +409,16 @@ static void free_trm(struct itrm *itrm)
set_handlers(itrm->std_out, NULL, NULL, NULL);
set_handlers(itrm->sock_out, NULL, NULL, NULL);
unregister_bottom_half(itrm_error, itrm);
- if (itrm->tm != NULL) kill_timer(itrm->tm);
+ if (itrm->tm != NULL)
+ kill_timer(itrm->tm);
free(itrm->ev_queue);
free(itrm);
- if (itrm == ditrm) ditrm = NULL;
+ if (itrm == ditrm)
+ ditrm = NULL;
}
-static void refresh_terminal_size(void)
+static void
+refresh_terminal_size(void)
{
int new_x, new_y;
if (!ditrm->blocked) {
@@ -376,36 +428,40 @@ static void refresh_terminal_size(void)
}
}
-static void resize_terminal_x(unsigned char *text)
+static void
+resize_terminal_x(unsigned char *text)
{
unsigned char *p;
- if (!(p = cast_uchar strchr(cast_const_char text, ','))) return;
+ if (!(p = cast_uchar strchr(cast_const_char text, ',')))
+ return;
*p++ = 0;
refresh_terminal_size();
}
-void dispatch_special(unsigned char *text)
+void
+dispatch_special(unsigned char *text)
{
switch (text[0]) {
- case TERM_FN_TITLE:
- set_window_title(text + 1);
- break;
- case TERM_FN_RESIZE:
- resize_terminal_x(text + 1);
- break;
+ case TERM_FN_TITLE:
+ set_window_title(text + 1);
+ break;
+ case TERM_FN_RESIZE:
+ resize_terminal_x(text + 1);
+ break;
}
}
static int process_queue(struct itrm *);
static int get_esc_code(unsigned char *, int, unsigned char *, int *, int *);
-static void kbd_timeout(void *itrm_)
+static void
+kbd_timeout(void *itrm_)
{
struct itrm *itrm = (struct itrm *)itrm_;
struct links_event ev = { EV_KBD, KBD_ESC, 0, 0 };
unsigned char code;
int num;
- int len = 0; /* against warning */
+ int len = 0; /* against warning */
itrm->tm = NULL;
if (can_read(itrm->std_in)) {
in_kbd(itrm);
@@ -419,16 +475,20 @@ static void kbd_timeout(void *itrm_)
len = 1;
goto skip_esc;
}
- itrm->queue_event(itrm, (unsigned char *)&ev, sizeof(struct links_event));
- if (get_esc_code(itrm->kqueue, itrm->qlen, &code, &num, &len)) len = 1;
- skip_esc:
+ itrm->queue_event(itrm, (unsigned char *)&ev,
+ sizeof(struct links_event));
+ if (get_esc_code(itrm->kqueue, itrm->qlen, &code, &num, &len))
+ len = 1;
+skip_esc:
itrm->qlen -= len;
memmove(itrm->kqueue, itrm->kqueue + len, itrm->qlen);
while (process_queue(itrm))
;
}
-static int get_esc_code(unsigned char *str, int len, unsigned char *code, int *num, int *el)
+static int
+get_esc_code(unsigned char *str, int len, unsigned char *code, int *num,
+ int *el)
{
int pos;
*num = 0;
@@ -445,155 +505,358 @@ static int get_esc_code(unsigned char *str, int len, unsigned char *code, int *n
static int xterm_button = -1;
-static int process_queue(struct itrm *itrm)
+static int
+process_queue(struct itrm *itrm)
{
struct links_event ev = { EV_KBD, -1, 0, 0 };
int el = 0;
- if (!itrm->qlen) goto end;
+ if (!itrm->qlen)
+ goto end;
if (itrm->kqueue[0] == '\033') {
- if (itrm->qlen < 2) goto ret;
+ if (itrm->qlen < 2)
+ goto ret;
if (itrm->kqueue[1] == '[' || itrm->kqueue[1] == 'O') {
unsigned char c = 0;
int v;
if (itrm->qlen >= 4 && itrm->kqueue[2] == '[') {
- if (itrm->kqueue[3] < 'A' || itrm->kqueue[3] > 'L') goto ret;
+ if (itrm->kqueue[3] < 'A'
+ || itrm->kqueue[3] > 'L')
+ goto ret;
ev.x = KBD_F1 - (itrm->kqueue[3] - 'A');
el = 4;
- } else if (get_esc_code(itrm->kqueue, itrm->qlen, &c, &v, &el)) goto ret;
- else switch (c) {
+ } else if (get_esc_code(itrm->kqueue, itrm->qlen, &c,
+ &v, &el))
+ goto ret;
+ else
+ switch (c) {
case 'L':
- case '@': ev.x = KBD_INS; break;
- case 'A': ev.x = KBD_UP; break;
- case 'B': ev.x = KBD_DOWN; break;
- case 'C': ev.x = KBD_RIGHT; break;
- case 'D': ev.x = KBD_LEFT; break;
+ case '@':
+ ev.x = KBD_INS;
+ break;
+ case 'A':
+ ev.x = KBD_UP;
+ break;
+ case 'B':
+ ev.x = KBD_DOWN;
+ break;
+ case 'C':
+ ev.x = KBD_RIGHT;
+ break;
+ case 'D':
+ ev.x = KBD_LEFT;
+ break;
case 'F':
case 'K':
- case 'e': ev.x = KBD_END; break;
+ case 'e':
+ ev.x = KBD_END;
+ break;
case 'H':
- case 0: ev.x = KBD_HOME; break;
+ case 0:
+ ev.x = KBD_HOME;
+ break;
case 'V':
- case 'I': ev.x = KBD_PAGE_UP; break;
+ case 'I':
+ ev.x = KBD_PAGE_UP;
+ break;
case 'U':
- case 'G': ev.x = KBD_PAGE_DOWN; break;
+ case 'G':
+ ev.x = KBD_PAGE_DOWN;
+ break;
case 'P':
- ev.x = KBD_F1; break;
- case 'Q': ev.x = KBD_F2; break;
+ ev.x = KBD_F1;
+ break;
+ case 'Q':
+ ev.x = KBD_F2;
+ break;
case 'S':
- ev.x = KBD_F4; break;
+ ev.x = KBD_F4;
+ break;
case 'T':
- ev.x = KBD_F5; break;
- case 'W': ev.x = KBD_F8; break;
- case 'X': ev.x = KBD_F9; break;
+ ev.x = KBD_F5;
+ break;
+ case 'W':
+ ev.x = KBD_F8;
+ break;
+ case 'X':
+ ev.x = KBD_F9;
+ break;
case 'Y':
ev.x = KBD_F11;
break;
- case 'q': switch (v) {
- case 139: ev.x = KBD_INS; break;
- case 146: ev.x = KBD_END; break;
- case 150: ev.x = KBD_PAGE_UP; break;
- case 154: ev.x = KBD_PAGE_DOWN; break;
- default: if (v >= 1 && v <= 48) {
+ case 'q':
+ switch (v) {
+ case 139:
+ ev.x = KBD_INS;
+ break;
+ case 146:
+ ev.x = KBD_END;
+ break;
+ case 150:
+ ev.x = KBD_PAGE_UP;
+ break;
+ case 154:
+ ev.x = KBD_PAGE_DOWN;
+ break;
+ default:
+ if (v >= 1 && v <= 48) {
int fn = (v - 1) % 12;
int mod = (v - 1) / 12;
ev.x = KBD_F1 - fn;
if (mod == 1)
- ev.y |= KBD_SHIFT;
+ ev.y |=
+ KBD_SHIFT;
if (mod == 2)
- ev.y |= KBD_CTRL;
+ ev.y |=
+ KBD_CTRL;
if (mod == 3)
ev.y |= KBD_ALT;
- } break;
- } break;
- case 'z': switch (v) {
- case 247: ev.x = KBD_INS; break;
- case 214: ev.x = KBD_HOME; break;
- case 220: ev.x = KBD_END; break;
- case 216: ev.x = KBD_PAGE_UP; break;
- case 222: ev.x = KBD_PAGE_DOWN; break;
- case 249: ev.x = KBD_DEL; break;
- } break;
- case '~': switch (v) {
- case 1: ev.x = KBD_HOME; break;
- case 2: ev.x = KBD_INS; break;
- case 3: ev.x = KBD_DEL; break;
- case 4: ev.x = KBD_END; break;
- case 5: ev.x = KBD_PAGE_UP; break;
- case 6: ev.x = KBD_PAGE_DOWN; break;
- case 7: ev.x = KBD_HOME; break;
- case 8: ev.x = KBD_END; break;
- case 17: ev.x = KBD_F6; break;
- case 18: ev.x = KBD_F7; break;
- case 19: ev.x = KBD_F8; break;
- case 20: ev.x = KBD_F9; break;
- case 21: ev.x = KBD_F10; break;
- case 23: ev.x = KBD_F11; break;
- case 24: ev.x = KBD_F12; break;
- case 200: itrm->flags |= BRACKETED_PASTE; break;
- case 201: itrm->flags &= ~BRACKETED_PASTE; break;
- } break;
+ }
+ break;
+ }
+ break;
+ case 'z':
+ switch (v) {
+ case 247:
+ ev.x = KBD_INS;
+ break;
+ case 214:
+ ev.x = KBD_HOME;
+ break;
+ case 220:
+ ev.x = KBD_END;
+ break;
+ case 216:
+ ev.x = KBD_PAGE_UP;
+ break;
+ case 222:
+ ev.x = KBD_PAGE_DOWN;
+ break;
+ case 249:
+ ev.x = KBD_DEL;
+ break;
+ }
+ break;
+ case '~':
+ switch (v) {
+ case 1:
+ ev.x = KBD_HOME;
+ break;
+ case 2:
+ ev.x = KBD_INS;
+ break;
+ case 3:
+ ev.x = KBD_DEL;
+ break;
+ case 4:
+ ev.x = KBD_END;
+ break;
+ case 5:
+ ev.x = KBD_PAGE_UP;
+ break;
+ case 6:
+ ev.x = KBD_PAGE_DOWN;
+ break;
+ case 7:
+ ev.x = KBD_HOME;
+ break;
+ case 8:
+ ev.x = KBD_END;
+ break;
+ case 17:
+ ev.x = KBD_F6;
+ break;
+ case 18:
+ ev.x = KBD_F7;
+ break;
+ case 19:
+ ev.x = KBD_F8;
+ break;
+ case 20:
+ ev.x = KBD_F9;
+ break;
+ case 21:
+ ev.x = KBD_F10;
+ break;
+ case 23:
+ ev.x = KBD_F11;
+ break;
+ case 24:
+ ev.x = KBD_F12;
+ break;
+ case 200:
+ itrm->flags |= BRACKETED_PASTE;
+ break;
+ case 201:
+ itrm->flags &= ~BRACKETED_PASTE;
+ break;
+ }
+ break;
case 'R':
refresh_terminal_size();
break;
case 'M':
case '<':
if (c == 'M' && v == 5) {
- if (xterm_button == -1) xterm_button = 0;
- if (itrm->qlen - el < 5) goto ret;
- ev.x = (unsigned char)(itrm->kqueue[el+1]) - ' ' - 1 + ((int)((unsigned char)(itrm->kqueue[el+2]) - ' ' - 1) << 7);
- if ( ev.x & (1 << 13)) ev.x = 0;
- ev.y = (unsigned char)(itrm->kqueue[el+3]) - ' ' - 1 + ((int)((unsigned char)(itrm->kqueue[el+4]) - ' ' - 1) << 7);
- if ( ev.y & (1 << 13)) ev.y = 0;
- switch ((itrm->kqueue[el] - ' ') ^ xterm_button) { /* Every event changhes only one bit */
- case TW_BUTT_LEFT: ev.b = B_LEFT | ( (xterm_button & TW_BUTT_LEFT) ? B_UP : B_DOWN ); break;
- case TW_BUTT_MIDDLE: ev.b = B_MIDDLE | ( (xterm_button & TW_BUTT_MIDDLE) ? B_UP : B_DOWN ); break;
- case TW_BUTT_RIGHT: ev.b = B_RIGHT | ( (xterm_button & TW_BUTT_RIGHT) ? B_UP : B_DOWN ); break;
- case 0: ev.b = B_DRAG;
- /* default : Twin protocol error */
+ if (xterm_button == -1)
+ xterm_button = 0;
+ if (itrm->qlen - el < 5)
+ goto ret;
+ ev.x =
+ (unsigned char)(itrm->kqueue
+ [el
+ + 1])
+ - ' ' - 1
+ + ((int)((unsigned char)(itrm->kqueue
+ [el
+ + 2])
+ - ' ' - 1)
+ << 7);
+ if (ev.x & (1 << 13))
+ ev.x = 0;
+ ev.y =
+ (unsigned char)(itrm->kqueue
+ [el
+ + 3])
+ - ' ' - 1
+ + ((int)((unsigned char)(itrm->kqueue
+ [el
+ + 4])
+ - ' ' - 1)
+ << 7);
+ if (ev.y & (1 << 13))
+ ev.y = 0;
+ switch (
+ (itrm->kqueue[el] - ' ')
+ ^ xterm_button) { /* Every
+ event
+ changhes
+ only
+ one bit
+ */
+ case TW_BUTT_LEFT:
+ ev.b =
+ B_LEFT
+ | ((xterm_button
+ & TW_BUTT_LEFT)
+ ? B_UP
+ : B_DOWN);
+ break;
+ case TW_BUTT_MIDDLE:
+ ev.b =
+ B_MIDDLE
+ | ((xterm_button
+ & TW_BUTT_MIDDLE)
+ ? B_UP
+ : B_DOWN);
+ break;
+ case TW_BUTT_RIGHT:
+ ev.b =
+ B_RIGHT
+ | ((xterm_button
+ & TW_BUTT_RIGHT)
+ ? B_UP
+ : B_DOWN);
+ break;
+ case 0:
+ ev.b = B_DRAG;
+ /* default : Twin
+ * protocol error */
}
- xterm_button = itrm->kqueue[el] - ' ';
+ xterm_button =
+ itrm->kqueue[el] - ' ';
el += 5;
} else {
- int x = 0, y = 0, b = 0;
+ int x = 0, y = 0, b = 0;
int button;
unsigned char ch;
if (c == 'M') {
- /* Legacy mouse protocol: \e[Mbxy whereas b, x and y are raw bytes, offset by 32. */
- if (itrm->qlen - el < 3) goto ret;
- b = itrm->kqueue[el++] - ' ';
- x = itrm->kqueue[el++] - ' ';
- y = itrm->kqueue[el++] - ' ';
+ /* Legacy mouse
+ * protocol: \e[Mbxy
+ * whereas b, x and y
+ * are raw bytes, offset
+ * by 32. */
+ if (itrm->qlen - el < 3)
+ goto ret;
+ b = itrm->kqueue[el++]
+ - ' ';
+ x = itrm->kqueue[el++]
+ - ' ';
+ y = itrm->kqueue[el++]
+ - ' ';
} else if (c == '<') {
- /* SGR 1006 mouse extension: \e[<b;x;yM where b, x and y are in decimal, no longer offset by 32,
- and the trailing letter is 'm' instead of 'M' for mouse release so that the released button is reported. */
- int eel;
- eel = el;
+ /* SGR 1006 mouse
+ extension: \e[<b;x;yM
+ where b, x and y are
+ in decimal, no longer
+ offset by 32, and the
+ trailing letter is
+ 'm' instead of 'M'
+ for mouse release so
+ that the released
+ button is reported.
+ */
+ int eel;
+ eel = el;
while (1) {
- if (el == itrm->qlen) goto ret;
- if (el - eel >= 9) goto l1;
- ch = itrm->kqueue[el++];
- if (ch == ';') break;
- if (ch < '0' || ch > '9') goto l1;
- b = 10 * b + (ch - '0');
+ if (el
+ == itrm->qlen)
+ goto ret;
+ if (el - eel
+ >= 9)
+ goto l1;
+ ch =
+ itrm->kqueue
+ [el++];
+ if (ch == ';')
+ break;
+ if (ch < '0'
+ || ch > '9')
+ goto l1;
+ b = 10 * b
+ + (ch
+ - '0');
}
eel = el;
while (1) {
- if (el == itrm->qlen) goto ret;
- if (el - eel >= 9) goto l1;
- ch = itrm->kqueue[el++];
- if (ch == ';') break;
- if (ch < '0' || ch > '9') goto l1;
- x = 10 * x + (ch - '0');
+ if (el
+ == itrm->qlen)
+ goto ret;
+ if (el - eel
+ >= 9)
+ goto l1;
+ ch =
+ itrm->kqueue
+ [el++];
+ if (ch == ';')
+ break;
+ if (ch < '0'
+ || ch > '9')
+ goto l1;
+ x = 10 * x
+ + (ch
+ - '0');
}
eel = el;
while (1) {
- if (el == itrm->qlen) goto ret;
- if (el - eel >= 9) goto l1;
- ch = itrm->kqueue[el++];
- if (ch == 'M' || ch == 'm') break;
- if (ch < '0' || ch > '9') goto l1;
- y = 10 * y + (ch - '0');
+ if (el
+ == itrm->qlen)
+ goto ret;
+ if (el - eel
+ >= 9)
+ goto l1;
+ ch =
+ itrm->kqueue
+ [el++];
+ if (ch == 'M'
+ || ch == 'm')
+ break;
+ if (ch < '0'
+ || ch > '9')
+ goto l1;
+ y = 10 * y
+ + (ch
+ - '0');
}
} else {
break;
@@ -602,29 +865,57 @@ static int process_queue(struct itrm *itrm)
y--;
if (x < 0 || y < 0 || b < 0)
break;
- if (c == 'M' && b == 3) button = B_UP;
- else if (c == '<' && ch == 'm') button = B_UP;
- else if ((b & 0x20) == 0x20) button = B_DRAG, b &= ~0x20;
- else button = B_DOWN;
- if (b == 0) button |= B_LEFT;
- else if (b == 1) button |= B_MIDDLE;
- else if (b == 2) button |= B_RIGHT;
- else if (b == 3 && xterm_button >= 0) button |= xterm_button;
- else if (b == 0x40) button |= B_WHEELUP;
- else if (b == 0x41) button |= B_WHEELDOWN;
- else if (b == 0x42) button |= B_WHEELLEFT;
- else if (b == 0x43) button |= B_WHEELRIGHT;
- else if (b == 0x80) button |= B_FOURTH;
- else if (b == 0x81) button |= B_FIFTH;
- else if (b == 0x82) button |= B_SIXTH;
- else break;
- if ((b == 0x80 || b == 0x81 || b == 0x82) && (button & BM_ACT) == B_DOWN && xterm_button == (button & BM_BUTT)) {
- /* xterm has a bug that it reports down events for both click and release */
+ if (c == 'M' && b == 3)
+ button = B_UP;
+ else if (c == '<' && ch == 'm')
+ button = B_UP;
+ else if ((b & 0x20) == 0x20)
+ button = B_DRAG,
+ b &= ~0x20;
+ else
+ button = B_DOWN;
+ if (b == 0)
+ button |= B_LEFT;
+ else if (b == 1)
+ button |= B_MIDDLE;
+ else if (b == 2)
+ button |= B_RIGHT;
+ else if (b == 3
+ && xterm_button >= 0)
+ button |= xterm_button;
+ else if (b == 0x40)
+ button |= B_WHEELUP;
+ else if (b == 0x41)
+ button |= B_WHEELDOWN;
+ else if (b == 0x42)
+ button |= B_WHEELLEFT;
+ else if (b == 0x43)
+ button |= B_WHEELRIGHT;
+ else if (b == 0x80)
+ button |= B_FOURTH;
+ else if (b == 0x81)
+ button |= B_FIFTH;
+ else if (b == 0x82)
+ button |= B_SIXTH;
+ else
+ break;
+ if ((b == 0x80 || b == 0x81
+ || b == 0x82)
+ && (button & BM_ACT)
+ == B_DOWN
+ && xterm_button
+ == (button
+ & BM_BUTT)) {
+ /* xterm has a bug that
+ * it reports down
+ * events for both click
+ * and release */
button &= ~BM_ACT;
button |= B_UP;
}
if ((button & BM_ACT) == B_DOWN)
- xterm_button = button & BM_BUTT;
+ xterm_button =
+ button & BM_BUTT;
if ((button & BM_ACT) == B_UP)
xterm_button = -1;
ev.b = button;
@@ -633,11 +924,14 @@ static int process_queue(struct itrm *itrm)
}
ev.ev = EV_MOUSE;
break;
- }
+ }
} else {
el = 2;
if (itrm->kqueue[1] == '\033') {
- if (itrm->qlen >= 3 && (itrm->kqueue[2] == '[' || itrm->kqueue[2] == 'O')) el = 1;
+ if (itrm->qlen >= 3
+ && (itrm->kqueue[2] == '['
+ || itrm->kqueue[2] == 'O'))
+ el = 1;
ev.x = KBD_ESC;
goto l2;
} else if (itrm->kqueue[1] == 127) {
@@ -657,18 +951,24 @@ static int process_queue(struct itrm *itrm)
}
el = 1;
ev.x = itrm->kqueue[0];
- l2:
- if (ev.x == 3) ev.x = KBD_CTRL_C;
- if (ev.x == 8) ev.x = KBD_BS;
- if (ev.x == 9) ev.x = KBD_TAB;
- if (ev.x == 10) ev.x = KBD_ENTER;
- if (ev.x == 13) ev.x = KBD_ENTER;
- if (ev.x == 127) ev.x = KBD_BS;
+l2:
+ if (ev.x == 3)
+ ev.x = KBD_CTRL_C;
+ if (ev.x == 8)
+ ev.x = KBD_BS;
+ if (ev.x == 9)
+ ev.x = KBD_TAB;
+ if (ev.x == 10)
+ ev.x = KBD_ENTER;
+ if (ev.x == 13)
+ ev.x = KBD_ENTER;
+ if (ev.x == 127)
+ ev.x = KBD_BS;
if (ev.x >= 0 && ev.x < ' ') {
ev.x += 'A' - 1;
ev.y |= KBD_CTRL;
}
- l1:
+l1:
if (itrm->qlen < el) {
internal("event queue underflow");
itrm->qlen = el;
@@ -676,22 +976,26 @@ static int process_queue(struct itrm *itrm)
if (ev.x != -1) {
if (itrm->flags & BRACKETED_PASTE && ev.ev == EV_KBD)
ev.y |= KBD_PASTING;
- itrm->queue_event(itrm, (unsigned char *)&ev, sizeof(struct links_event));
+ itrm->queue_event(itrm, (unsigned char *)&ev,
+ sizeof(struct links_event));
}
memmove(itrm->kqueue, itrm->kqueue + el, itrm->qlen -= el);
- end:
- if (itrm->qlen < IN_BUF_SIZE && !itrm->blocked) set_handlers(itrm->std_in, in_kbd, NULL, itrm);
+end:
+ if (itrm->qlen < IN_BUF_SIZE && !itrm->blocked)
+ set_handlers(itrm->std_in, in_kbd, NULL, itrm);
return el;
- ret:
+ret:
itrm->tm = install_timer(ESC_TIMEOUT, kbd_timeout, itrm);
return 0;
}
-static void in_kbd(void *itrm_)
+static void
+in_kbd(void *itrm_)
{
struct itrm *itrm = (struct itrm *)itrm_;
int r;
- if (!can_read(itrm->std_in)) return;
+ if (!can_read(itrm->std_in))
+ return;
if (itrm->tm != NULL) {
kill_timer(itrm->tm);
itrm->tm = NULL;
@@ -702,21 +1006,25 @@ static void in_kbd(void *itrm_)
;
return;
}
- EINTRLOOP(r, (int)read(itrm->std_in, itrm->kqueue + itrm->qlen, IN_BUF_SIZE - itrm->qlen));
+ EINTRLOOP(r, (int)read(itrm->std_in, itrm->kqueue + itrm->qlen,
+ IN_BUF_SIZE - itrm->qlen));
if (r <= 0) {
struct links_event ev = { EV_ABORT, 0, 0, 0 };
set_handlers(itrm->std_in, NULL, NULL, itrm);
- itrm->queue_event(itrm, (unsigned char *)&ev, sizeof(struct links_event));
+ itrm->queue_event(itrm, (unsigned char *)&ev,
+ sizeof(struct links_event));
return;
}
- more_data:
+more_data:
if ((itrm->qlen += r) > IN_BUF_SIZE) {
error("ERROR: too many bytes read");
itrm->qlen = IN_BUF_SIZE;
}
if (itrm->qlen < IN_BUF_SIZE && can_read(itrm->std_in)) {
- EINTRLOOP(r, (int)read(itrm->std_in, itrm->kqueue + itrm->qlen, IN_BUF_SIZE - itrm->qlen));
- if (r > 0) goto more_data;
+ EINTRLOOP(r, (int)read(itrm->std_in, itrm->kqueue + itrm->qlen,
+ IN_BUF_SIZE - itrm->qlen));
+ if (r > 0)
+ goto more_data;
}
while (process_queue(itrm))
;
diff --git a/language.c b/language.c
@@ -2,14 +2,15 @@
* (c) 2002 Mikulas Patocka
* This file is a part of the Links program, released under GPL.
*/
-
#include "links.h"
+
#include "language.h"
#include "language.inc"
unsigned char dummyarray[T__N_TEXTS];
-unsigned char *get_text_translation(unsigned char *text, struct terminal *term)
+unsigned char *
+get_text_translation(unsigned char *text, struct terminal *term)
{
if (!(text >= dummyarray && text < (dummyarray + T__N_TEXTS)))
return text;
diff --git a/links.h b/links.h
@@ -4,7 +4,9 @@
* This file is a part of the Links program, released under GPL.
*/
-#define LINKS_COPYRIGHT "(C) 1999 - 2019 Mikulas Patocka\n(C) 2000 - 2019 Petr Kulhavy, Karel Kulhavy, Martin Pergel"
+#define LINKS_COPYRIGHT \
+ "(C) 1999 - 2019 Mikulas Patocka\n(C) 2000 - 2019 Petr Kulhavy, " \
+ "Karel Kulhavy, Martin Pergel"
#include <dirent.h>
#include <errno.h>
@@ -35,138 +37,188 @@
#include <openssl/ssl.h>
-#define longlong long long
+#define longlong long long
#define ulonglong unsigned long long
-#define stringify_internal(arg) #arg
-#define stringify(arg) stringify_internal(arg)
+#define stringify_internal(arg) #arg
+#define stringify(arg) stringify_internal(arg)
-#define array_elements(a) (sizeof(a) / sizeof(*a))
+#define array_elements(a) (sizeof(a) / sizeof(*a))
#ifdef HAVE_POINTER_COMPARISON_BUG
-#define DUMMY ((void *)1L)
+ #define DUMMY ((void *)1L)
#else
-#define DUMMY ((void *)-1L)
+ #define DUMMY ((void *)-1L)
#endif
-#define cast_const_char (const char *)
-#define cast_char (char *)
-#define cast_uchar (unsigned char *)
-
-enum ret {
- RET_OK,
- RET_ERROR,
- RET_SYNTAX
-};
-
-#define EINTRLOOPX(ret_, call_, x_) \
-do { \
- (ret_) = (call_); \
-} while ((ret_) == (x_) && errno == EINTR)
-
-#define EINTRLOOP(ret_, call_) EINTRLOOPX(ret_, call_, -1)
-
-#define ENULLLOOP(ret_, call_) \
-do { \
- errno = 0; \
- (ret_) = (call_); \
-} while (!(ret_) && errno == EINTR)
-
-#define MAX_STR_LEN 1024
-
-#define BIN_SEARCH(entries, eq, ab, key, result) \
-{ \
- int s_ = 0, e_ = (entries) - 1; \
- (result) = -1; \
- while (s_ <= e_) { \
- int m_ = (int)(((unsigned)s_ + (unsigned)e_) / 2); \
- if (eq((m_), (key))) { \
- (result) = m_; \
- break; \
- } \
- if (ab((m_), (key))) e_ = m_ - 1; \
- else s_ = m_ + 1; \
- } \
-} \
+#define cast_const_char (const char *)
+#define cast_char (char *)
+#define cast_uchar (unsigned char *)
+
+enum ret { RET_OK, RET_ERROR, RET_SYNTAX };
+
+#define EINTRLOOPX(ret_, call_, x_) \
+ do { \
+ (ret_) = (call_); \
+ } while ((ret_) == (x_) && errno == EINTR)
+
+#define EINTRLOOP(ret_, call_) EINTRLOOPX(ret_, call_, -1)
+
+#define ENULLLOOP(ret_, call_) \
+ do { \
+ errno = 0; \
+ (ret_) = (call_); \
+ } while (!(ret_) && errno == EINTR)
+
+#define MAX_STR_LEN 1024
+
+#define BIN_SEARCH(entries, eq, ab, key, result) \
+ { \
+ int s_ = 0, e_ = (entries)-1; \
+ (result) = -1; \
+ while (s_ <= e_) { \
+ int m_ = (int)(((unsigned)s_ + (unsigned)e_) / 2); \
+ if (eq((m_), (key))) { \
+ (result) = m_; \
+ break; \
+ } \
+ if (ab((m_), (key))) \
+ e_ = m_ - 1; \
+ else \
+ s_ = m_ + 1; \
+ } \
+ }
void die(const char *, ...);
void usage(void);
void *xmalloc(size_t);
void *xrealloc(void *, size_t);
-#define internal die
-#define error die
+#define internal die
+#define error die
#define fatal_exit die
/* error.c */
-#define overalloc_at(f, l) \
-do { \
- fatal_exit("ERROR: attempting to allocate too large block at %s:%d", f, l);\
-} while (1) /* while (1) is not a typo --- it's here to allow the compiler
- that doesn't know that fatal_exit doesn't return to do better
- optimizations */
-
-#define overalloc() overalloc_at(__FILE__, __LINE__)
-
-#define overflow() \
-do { \
- fatal_exit("ERROR: arithmetic overflow at %s:%d", __FILE__, __LINE__);\
-} while (1)
-
-static inline int test_int_overflow(int x, int y, int *result)
+#define overalloc_at(f, l) \
+ do { \
+ fatal_exit( \
+ "ERROR: attempting to allocate too large block at %s:%d", \
+ f, l); \
+ } while (1) /* while (1) is not a typo --- it's here to allow the \
+ compiler that doesn't know that fatal_exit doesn't return to do \
+ better optimizations */
+
+#define overalloc() overalloc_at(__FILE__, __LINE__)
+
+#define overflow() \
+ do { \
+ fatal_exit("ERROR: arithmetic overflow at %s:%d", __FILE__, \
+ __LINE__); \
+ } while (1)
+
+static inline int
+test_int_overflow(int x, int y, int *result)
{
int z = *result = x + y;
return ~(x ^ y) & (x ^ z) & (int)(1U << (sizeof(unsigned int) * 8 - 1));
}
-static inline int safe_add_function(int x, int y, unsigned char *file, int line)
+static inline int
+safe_add_function(int x, int y, unsigned char *file, int line)
{
int ret;
if (test_int_overflow(x, y, &ret))
- fatal_exit("ERROR: arithmetic overflow at %s:%d: %d + %d", file, line, (x), (y));
+ fatal_exit("ERROR: arithmetic overflow at %s:%d: %d + %d", file,
+ line, (x), (y));
return ret;
}
-#define safe_add(x, y) safe_add_function(x, y, (unsigned char *)__FILE__, __LINE__)
+#define safe_add(x, y) \
+ safe_add_function(x, y, (unsigned char *)__FILE__, __LINE__)
void *mem_calloc(size_t size);
unsigned char *memacpy(const unsigned char *src, size_t len);
unsigned char *stracpy(const unsigned char *src);
-#define pr(code) if (1) {code;} else
+#define pr(code) \
+ if (1) { \
+ code; \
+ } else
/* inline */
-#define ALLOC_GR 0x040 /* must be power of 2 */
+#define ALLOC_GR 0x040 /* must be power of 2 */
-#define get_struct_(ptr, struc, entry) ((struc *)((char *)(ptr) - offsetof(struc, entry)))
-#define get_struct(ptr, struc, entry) ((void)(&get_struct_(ptr, struc, entry)->entry == (ptr)), get_struct_(ptr, struc, entry))
+#define get_struct_(ptr, struc, entry) \
+ ((struc *)((char *)(ptr)-offsetof(struc, entry)))
+#define get_struct(ptr, struc, entry) \
+ ((void)(&get_struct_(ptr, struc, entry)->entry == (ptr)), \
+ get_struct_(ptr, struc, entry))
struct list_head {
struct list_head *next;
struct list_head *prev;
};
-#define list_struct(ptr, struc) get_struct(ptr, struc, list_entry)
-#define init_list(x) do { (x).next = &(x); (x).prev = &(x); } while (0)
-#define list_empty(x) ((x).next == &(x))
-#define del_list_entry(x) do { (x)->next->prev = (x)->prev; (x)->prev->next = (x)->next; (x)->prev = (x)->next = NULL; } while (0)
-#define del_from_list(x) del_list_entry(&(x)->list_entry)
-#define add_after_list_entry(p, x) do { (x)->next = (p)->next; (x)->prev = (p); (p)->next = (x); (x)->next->prev = (x); } while (0)
-#define add_before_list_entry(p, x) do { (x)->prev = (p)->prev; (x)->next = (p); (p)->prev = (x); (x)->prev->next = (x); } while (0)
-#define add_to_list(l, x) add_after_list_entry(&(l), &(x)->list_entry)
-#define add_to_list_end(l, x) add_before_list_entry(&(l), &(x)->list_entry)
-#define add_after_pos(p, x) add_after_list_entry(&(p)->list_entry, &(x)->list_entry)
-#define add_before_pos(p, x) add_before_list_entry(&(p)->list_entry, &(x)->list_entry)
-#define fix_list_after_realloc(x) do { (x)->list_entry.prev->next = &(x)->list_entry; (x)->list_entry.next->prev = &(x)->list_entry; } while (0)
-#define foreachfrom(struc, e, h, l, s) for ((h) = (s); (h) == &(l) ? 0 : ((e) = list_struct(h, struc), 1); (h) = (h)->next)
-#define foreach(struc, e, h, l) foreachfrom(struc, e, h, l, (l).next)
-#define foreachbackfrom(struc, e, h, l, s) for ((h) = (s); (h) == &(l) ? 0 : ((e) = list_struct(h, struc), 1); (h) = (h)->prev)
-#define foreachback(struc, e, h, l) foreachbackfrom(struc, e, h, l, (l).prev)
-#define free_list(struc, l) do { while (!list_empty(l)) { struc *a__ = list_struct((l).next, struc); del_from_list(a__); free(a__); } } while (0)
-
-static inline int list_size(struct list_head *l)
+#define list_struct(ptr, struc) get_struct(ptr, struc, list_entry)
+#define init_list(x) \
+ do { \
+ (x).next = &(x); \
+ (x).prev = &(x); \
+ } while (0)
+#define list_empty(x) ((x).next == &(x))
+#define del_list_entry(x) \
+ do { \
+ (x)->next->prev = (x)->prev; \
+ (x)->prev->next = (x)->next; \
+ (x)->prev = (x)->next = NULL; \
+ } while (0)
+#define del_from_list(x) del_list_entry(&(x)->list_entry)
+#define add_after_list_entry(p, x) \
+ do { \
+ (x)->next = (p)->next; \
+ (x)->prev = (p); \
+ (p)->next = (x); \
+ (x)->next->prev = (x); \
+ } while (0)
+#define add_before_list_entry(p, x) \
+ do { \
+ (x)->prev = (p)->prev; \
+ (x)->next = (p); \
+ (p)->prev = (x); \
+ (x)->prev->next = (x); \
+ } while (0)
+#define add_to_list(l, x) add_after_list_entry(&(l), &(x)->list_entry)
+#define add_to_list_end(l, x) add_before_list_entry(&(l), &(x)->list_entry)
+#define add_after_pos(p, x) \
+ add_after_list_entry(&(p)->list_entry, &(x)->list_entry)
+#define add_before_pos(p, x) \
+ add_before_list_entry(&(p)->list_entry, &(x)->list_entry)
+#define fix_list_after_realloc(x) \
+ do { \
+ (x)->list_entry.prev->next = &(x)->list_entry; \
+ (x)->list_entry.next->prev = &(x)->list_entry; \
+ } while (0)
+#define foreachfrom(struc, e, h, l, s) \
+ for ((h) = (s); (h) == &(l) ? 0 : ((e) = list_struct(h, struc), 1); \
+ (h) = (h)->next)
+#define foreach(struc, e, h, l) foreachfrom (struc, e, h, l, (l).next)
+#define foreachbackfrom(struc, e, h, l, s) \
+ for ((h) = (s); (h) == &(l) ? 0 : ((e) = list_struct(h, struc), 1); \
+ (h) = (h)->prev)
+#define foreachback(struc, e, h, l) foreachbackfrom (struc, e, h, l, (l).prev)
+#define free_list(struc, l) \
+ do { \
+ while (!list_empty(l)) { \
+ struc *a__ = list_struct((l).next, struc); \
+ del_from_list(a__); \
+ free(a__); \
+ } \
+ } while (0)
+
+static inline int
+list_size(struct list_head *l)
{
struct list_head *e;
int n = 0;
@@ -175,10 +227,11 @@ static inline int list_size(struct list_head *l)
return n;
}
-#define list_entry_1st struct list_head list_entry;
-#define init_list_1st(x) { (x), (x) },
+#define list_entry_1st struct list_head list_entry;
+#define init_list_1st(x) { (x), (x) },
-#define WHITECHAR(x) ((x) == 9 || (x) == 10 || (x) == 12 || (x) == 13 || (x) == ' ')
+#define WHITECHAR(x) \
+ ((x) == 9 || (x) == 10 || (x) == 12 || (x) == 13 || (x) == ' ')
#define U(x) ((x) == '"' || (x) == '\'')
enum ci {
@@ -199,7 +252,8 @@ int snzprint(unsigned char *s, int n, off_t num);
void add_to_strn(unsigned char **s, unsigned char *a);
void extend_str(unsigned char **s, int n);
-static inline unsigned char *init_str()
+static inline unsigned char *
+init_str()
{
unsigned char *p;
@@ -216,38 +270,47 @@ void add_num_to_str(unsigned char **s, int *l, off_t n);
void add_knum_to_str(unsigned char **s, int *l, off_t n);
long strtolx(unsigned char *c, unsigned char **end);
-void safe_strncpy(unsigned char *dst, const unsigned char *src, size_t dst_size);
+void safe_strncpy(unsigned char *dst, const unsigned char *src,
+ size_t dst_size);
/* case insensitive compare of 2 strings */
/* comparison ends after len (or less) characters */
/* return value: 1=strings differ, 0=strings are same */
-static inline unsigned upcase(unsigned a)
+static inline unsigned
+upcase(unsigned a)
{
if (a >= 'a' && a <= 'z')
a -= 0x20;
return a;
}
-static inline unsigned locase(unsigned a)
+static inline unsigned
+locase(unsigned a)
{
if (a >= 'A' && a <= 'Z')
a += 0x20;
return a;
}
-static inline int srch_cmp(unsigned char c1, unsigned char c2)
+static inline int
+srch_cmp(unsigned char c1, unsigned char c2)
{
return upcase(c1) != upcase(c2);
}
int casestrcmp(const unsigned char *s1, const unsigned char *s2);
int casecmp(const unsigned char *c1, const unsigned char *c2, size_t len);
int casestrstr(const unsigned char *h, const unsigned char *n);
-static inline int xstrcmp(const unsigned char *s1, const unsigned char *s2)
+static inline int
+xstrcmp(const unsigned char *s1, const unsigned char *s2)
{
- if (!s1 && !s2) return 0;
- if (!s1) return -1;
- if (!s2) return 1;
+ if (!s1 && !s2)
+ return 0;
+ if (!s1)
+ return -1;
+ if (!s2)
+ return 1;
return strcmp(cast_const_char s1, cast_const_char s2);
}
-static inline int cmpbeg(const unsigned char *str, const unsigned char *b)
+static inline int
+cmpbeg(const unsigned char *str, const unsigned char *b)
{
while (*str && upcase(*str) == upcase(*b)) {
str++;
@@ -256,7 +319,6 @@ static inline int cmpbeg(const unsigned char *str, const unsigned char *b)
return !!*b;
}
-
/* os_dep.c */
typedef unsigned long long uttime;
@@ -269,7 +331,8 @@ struct terminal;
struct open_in_new {
unsigned char *text;
unsigned char *hk;
- int (* const *open_window_fn)(struct terminal *, unsigned char *, unsigned char *);
+ int (*const *open_window_fn)(struct terminal *, unsigned char *,
+ unsigned char *);
};
void close_fork_tty(void);
@@ -279,7 +342,7 @@ void get_terminal_size(int *, int *);
void handle_terminal_resize(void (*)(int, int), int *x, int *y);
void unhandle_terminal_resize(void);
void set_nonblock(int);
-int c_pipe(int [2]);
+int c_pipe(int[2]);
int c_dup(int oh);
int c_socket(int, int, int);
int c_accept(int, struct sockaddr *, socklen_t *);
@@ -317,16 +380,12 @@ void os_detach_console(void);
/* memory.c */
-enum mem_sh {
- SH_CHECK_QUOTA,
- SH_FREE_SOMETHING,
- SH_FREE_ALL
-};
+enum mem_sh { SH_CHECK_QUOTA, SH_FREE_SOMETHING, SH_FREE_ALL };
-#define ST_SOMETHING_FREED 1
-#define ST_CACHE_EMPTY 2
+#define ST_SOMETHING_FREED 1
+#define ST_CACHE_EMPTY 2
-#define MF_GPI 1
+#define MF_GPI 1
int shrink_memory(int);
void register_cache_upcall(int (*)(int), int, unsigned char *);
@@ -336,25 +395,27 @@ int out_of_memory(void);
/* select.c */
#ifndef FD_SETSIZE
-#define FD_SETSIZE (sizeof(fd_set) * 8)
+ #define FD_SETSIZE (sizeof(fd_set) * 8)
#endif
-#define NBIT(p) (sizeof((p)->fds_bits[0]) * 8)
+#define NBIT(p) (sizeof((p)->fds_bits[0]) * 8)
#ifndef FD_SET
-#define FD_SET(n, p) ((p)->fds_bits[(n)/NBIT(p)] |= (1 << ((n) % NBIT(p))))
+ #define FD_SET(n, p) \
+ ((p)->fds_bits[(n) / NBIT(p)] |= (1 << ((n) % NBIT(p))))
#endif
#ifndef FD_CLR
-#define FD_CLR(n, p) ((p)->fds_bits[(n)/NBIT(p)] &= ~(1 << ((n) % NBIT(p))))
+ #define FD_CLR(n, p) \
+ ((p)->fds_bits[(n) / NBIT(p)] &= ~(1 << ((n) % NBIT(p))))
#endif
#ifndef FD_ISSET
-#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NBIT(p)] & (1 << ((n) % NBIT(p))))
+ #define FD_ISSET(n, p) \
+ ((p)->fds_bits[(n) / NBIT(p)] & (1 << ((n) % NBIT(p))))
#endif
#ifndef FD_ZERO
-#define FD_ZERO(p) memset((void *)(p), 0, sizeof(*(p)))
+ #define FD_ZERO(p) memset((void *)(p), 0, sizeof(*(p)))
#endif
-
extern int terminate_loop;
int can_write(int fd);
@@ -375,15 +436,17 @@ struct timer *install_timer(uttime, void (*)(void *), void *);
void kill_timer(struct timer *);
void portable_sleep(unsigned msec);
-#define H_READ 0
-#define H_WRITE 1
+#define H_READ 0
+#define H_WRITE 1
void (*get_handler(int, int))(void *);
void *get_handler_data(int);
extern unsigned char *sh_file;
extern int sh_line;
void set_handlers_file_line(int, void (*)(void *), void (*)(void *), void *);
-#define set_handlers(a, b, c, d) (sh_file = (unsigned char *)__FILE__, sh_line = __LINE__, set_handlers_file_line(a, b, c, d))
+#define set_handlers(a, b, c, d) \
+ (sh_file = (unsigned char *)__FILE__, sh_line = __LINE__, \
+ set_handlers_file_line(a, b, c, d))
void clear_events(int, int);
extern int signal_pipe[2];
void install_signal_handler(int, void (*)(void *), void *, int);
@@ -394,7 +457,7 @@ void set_sigcld(void);
/* dns.c */
-#define MAX_ADDRESSES 64
+#define MAX_ADDRESSES 64
struct host_address {
int af;
@@ -416,10 +479,13 @@ struct lookup_state {
};
int numeric_ip_address(const char *name, char address[4]);
-int numeric_ipv6_address(const char *name, char address[16], unsigned *scope_id);
+int numeric_ipv6_address(const char *name, char address[16],
+ unsigned *scope_id);
void rotate_addresses(struct lookup_result *);
-int find_host(char *, struct lookup_result *, void **, void (*)(void *, int), void *);
-int find_host_no_cache(char *, struct lookup_result *, void **, void (*)(void *, int), void *);
+int find_host(char *, struct lookup_result *, void **, void (*)(void *, int),
+ void *);
+int find_host_no_cache(char *, struct lookup_result *, void **,
+ void (*)(void *, int), void *);
void kill_dns_request(void **);
#if MAX_ADDRESSES > 1
void dns_set_priority(char *, struct host_address *, int);
@@ -433,8 +499,7 @@ void init_dns(void);
/* cache.c */
struct cache_entry {
- list_entry_1st
- unsigned char *head;
+ list_entry_1st unsigned char *head;
int http_code;
unsigned char *redirect;
off_t length;
@@ -442,9 +507,9 @@ struct cache_entry {
int incomplete;
int tgc;
unsigned char *last_modified;
- time_t expire_time; /* 0 never, 1 always */
+ time_t expire_time; /* 0 never, 1 always */
off_t data_size;
- struct list_head frag; /* struct fragment */
+ struct list_head frag; /* struct fragment */
tcount count;
tcount count2;
int refcount;
@@ -457,8 +522,7 @@ struct cache_entry {
};
struct fragment {
- list_entry_1st
- off_t offset;
+ list_entry_1st off_t offset;
off_t length;
off_t real_length;
unsigned char data[1];
@@ -518,10 +582,9 @@ struct remaining_info {
struct conn_info;
struct connection {
- list_entry_1st
- tcount count;
+ list_entry_1st tcount count;
unsigned char *url;
- unsigned char *prev_url; /* allocated string with referrer or NULL */
+ unsigned char *prev_url; /* allocated string with referrer or NULL */
int running;
int state;
int prev_error;
@@ -561,8 +624,7 @@ extern tcount netcfg_stamp;
extern struct list_head queue;
struct k_conn {
- list_entry_1st
- void (*protocol)(struct connection *);
+ list_entry_1st void (*protocol)(struct connection *);
unsigned char *host;
int port;
int conn;
@@ -575,13 +637,7 @@ struct k_conn {
extern struct list_head keepalive_connections;
-enum nc {
- NC_ALWAYS_CACHE,
- NC_CACHE,
- NC_IF_MOD,
- NC_RELOAD,
- NC_PR_NO_CACHE
-};
+enum nc { NC_ALWAYS_CACHE, NC_CACHE, NC_IF_MOD, NC_RELOAD, NC_PR_NO_CACHE };
enum ses {
S_WAIT,
@@ -643,8 +699,7 @@ enum ses_sig {
};
struct status {
- list_entry_1st
- struct connection *c;
+ list_entry_1st struct connection *c;
struct cache_entry *ce;
int state;
int prev_error;
@@ -665,15 +720,17 @@ void check_queue(void *dummy);
unsigned long connect_info(int);
void setcstate(struct connection *c, int);
int get_keepalive_socket(struct connection *c, int *protocol_data);
-void add_keepalive_socket(struct connection *c, uttime timeout, int protocol_data);
+void add_keepalive_socket(struct connection *c, uttime timeout,
+ int protocol_data);
int is_connection_restartable(struct connection *c);
int is_last_try(struct connection *c);
void retry_connection(struct connection *c);
void abort_connection(struct connection *c);
-#define ALLOW_SMB 1
-#define ALLOW_FILE 2
-#define ALLOW_ALL (ALLOW_SMB | ALLOW_FILE)
-void load_url(unsigned char *, unsigned char *, struct status *, int, int, int, int, off_t);
+#define ALLOW_SMB 1
+#define ALLOW_FILE 2
+#define ALLOW_ALL (ALLOW_SMB | ALLOW_FILE)
+void load_url(unsigned char *, unsigned char *, struct status *, int, int, int,
+ int, off_t);
void change_connection(struct status *, struct status *, int);
void detach_connection(struct status *, off_t, int, int);
void abort_all_connections(void);
@@ -709,15 +766,20 @@ int allow_cookie_domain(unsigned char *server, unsigned char *domain);
struct session;
-#define POST_CHAR 1
-#define POST_CHAR_STRING "\001"
+#define POST_CHAR 1
+#define POST_CHAR_STRING "\001"
-static inline int end_of_dir(unsigned char *url, unsigned char c)
+static inline int
+end_of_dir(unsigned char *url, unsigned char c)
{
- return c == POST_CHAR || c == '#' || ((c == ';' || c == '?') && (!url || !casecmp(url, (unsigned char *)"http", 4)));
+ return c == POST_CHAR || c == '#'
+ || ((c == ';' || c == '?')
+ && (!url || !casecmp(url, (unsigned char *)"http", 4)));
}
-int parse_url(unsigned char *, int *, unsigned char **, int *, unsigned char **, int *, unsigned char **, int *, unsigned char **, int *, unsigned char **, int *, unsigned char **);
+int parse_url(unsigned char *, int *, unsigned char **, int *, unsigned char **,
+ int *, unsigned char **, int *, unsigned char **, int *,
+ unsigned char **, int *, unsigned char **);
unsigned char *get_protocol_name(unsigned char *);
unsigned char *get_host_name(unsigned char *);
unsigned char *get_keepalive_id(unsigned char *);
@@ -726,7 +788,8 @@ unsigned char *get_pass(unsigned char *);
int get_port(unsigned char *);
unsigned char *get_port_str(unsigned char *);
void (*get_protocol_handle(unsigned char *))(struct connection *);
-void (*get_external_protocol_function(unsigned char *))(struct session *, unsigned char *);
+void (*get_external_protocol_function(unsigned char *))(struct session *,
+ unsigned char *);
int url_bypasses_socks(unsigned char *);
unsigned char *get_url_data(unsigned char *);
int url_non_ascii(unsigned char *url);
@@ -734,11 +797,14 @@ unsigned char *join_urls(unsigned char *, unsigned char *);
unsigned char *translate_url(unsigned char *, unsigned char *);
unsigned char *extract_position(unsigned char *);
int url_not_saveable(unsigned char *);
-void add_conv_str(unsigned char **s, int *l, unsigned char *b, int ll, int encode_special);
+void add_conv_str(unsigned char **s, int *l, unsigned char *b, int ll,
+ int encode_special);
void convert_file_charset(unsigned char **s, int *l, int start_l);
-unsigned char *idn_encode_host(unsigned char *host, int len, unsigned char *separator, int decode);
+unsigned char *idn_encode_host(unsigned char *host, int len,
+ unsigned char *separator, int decode);
unsigned char *idn_encode_url(unsigned char *url, int decode);
-unsigned char *display_url(struct terminal *term, unsigned char *url, int warn_idn);
+unsigned char *display_url(struct terminal *term, unsigned char *url,
+ int warn_idn);
unsigned char *display_host(struct terminal *term, unsigned char *host);
unsigned char *display_host_list(struct terminal *term, unsigned char *host);
@@ -754,19 +820,22 @@ struct read_buffer {
int socket_and_bind(int pf, unsigned char *address);
void close_socket(int *);
-void make_connection(struct connection *, int, int *, void (*)(struct connection *));
+void make_connection(struct connection *, int, int *,
+ void (*)(struct connection *));
void retry_connect(struct connection *, int, int);
-void continue_connection(struct connection *, int *, void (*)(struct connection *));
-void write_to_socket(struct connection *, int, unsigned char *, int, void (*)(struct connection *));
+void continue_connection(struct connection *, int *,
+ void (*)(struct connection *));
+void write_to_socket(struct connection *, int, unsigned char *, int,
+ void (*)(struct connection *));
struct read_buffer *alloc_read_buffer(void);
-void read_from_socket(struct connection *, int, struct read_buffer *, void (*)(struct connection *, struct read_buffer *));
+void read_from_socket(struct connection *, int, struct read_buffer *,
+ void (*)(struct connection *, struct read_buffer *));
void kill_buffer_data(struct read_buffer *, int);
/* cookies.c */
struct cookie {
- list_entry_1st
- unsigned char *name, *value;
+ list_entry_1st unsigned char *name, *value;
unsigned char *server;
unsigned char *path, *domain;
time_t expires; /* zero means undefined */
@@ -774,11 +843,9 @@ struct cookie {
};
struct c_domain {
- list_entry_1st
- unsigned char domain[1];
+ list_entry_1st unsigned char domain[1];
};
-
extern struct list_head all_cookies;
extern struct list_head c_domains;
@@ -793,16 +860,19 @@ void free_cookie(struct cookie *c);
/* auth.c */
-unsigned char *get_auth_realm(unsigned char *url, unsigned char *head, int proxy);
+unsigned char *get_auth_realm(unsigned char *url, unsigned char *head,
+ int proxy);
unsigned char *get_auth_string(unsigned char *url, int proxy);
void free_auth(void);
-void add_auth(unsigned char *url, unsigned char *realm, unsigned char *user, unsigned char *password, int proxy);
+void add_auth(unsigned char *url, unsigned char *realm, unsigned char *user,
+ unsigned char *password, int proxy);
int find_auth(unsigned char *url, unsigned char *realm);
/* http.c */
int get_http_code(unsigned char *head, int *code, int *version);
-unsigned char *parse_http_header(unsigned char *, unsigned char *, unsigned char **);
+unsigned char *parse_http_header(unsigned char *, unsigned char *,
+ unsigned char **);
unsigned char *parse_header_param(unsigned char *, unsigned char *, int);
void http_func(struct connection *);
void proxy_func(struct connection *);
@@ -818,7 +888,8 @@ int verify_ssl_cipher(links_ssl *ssl);
int ssl_not_reusable(links_ssl *ssl);
unsigned char *get_cipher_string(links_ssl *ssl);
-SSL_SESSION *get_session_cache_entry(SSL_CTX *ctx, unsigned char *host, int port);
+SSL_SESSION *get_session_cache_entry(SSL_CTX *ctx, unsigned char *host,
+ int port);
void retrieve_ssl_session(struct connection *c);
unsigned long session_info(int type);
void init_session_cache(void);
@@ -849,21 +920,21 @@ enum bm {
B_WHEELLEFT1,
B_WHEELRIGHT1
};
-#define BM_BUTT B_WHEELRIGHT1
+#define BM_BUTT B_WHEELRIGHT1
-#define BM_IS_WHEEL(b) ((b) & 8)
+#define BM_IS_WHEEL(b) ((b)&8)
-#define BM_ACT 48
-#define B_DOWN 0
-#define B_UP 16
-#define B_DRAG 32
-#define B_MOVE 48
+#define BM_ACT 48
+#define B_DOWN 0
+#define B_UP 16
+#define B_DRAG 32
+#define B_MOVE 48
enum kbd {
- KBD_SHIFT = (0 << 1),
- KBD_CTRL = (0 << 2),
- KBD_ALT = (0 << 3),
- KBD_PASTING = (0 << 4),
+ KBD_SHIFT = (0 << 1),
+ KBD_CTRL = (0 << 2),
+ KBD_ALT = (0 << 3),
+ KBD_PASTING = (0 << 4),
KBD_ENTER = -0x100,
KBD_BS,
@@ -915,7 +986,7 @@ enum kbd {
KBD_CLOSE
};
-#define KBD_ESCAPE_MENU(x) ((x) <= KBD_F1 && (x) > KBD_CTRL_C)
+#define KBD_ESCAPE_MENU(x) ((x) <= KBD_F1 && (x) > KBD_CTRL_C)
void handle_trm(int, void *, int);
void free_all_itrms(void);
@@ -933,8 +1004,8 @@ extern unsigned char term_seq_x_mouse[];
extern unsigned char term_seq_tw_mouse[];
struct rgb {
- unsigned char r, g, b; /* This is 3*8 bits with sRGB gamma (in sRGB space)
- * This is not rounded. */
+ unsigned char r, g, b; /* This is 3*8 bits with sRGB gamma (in sRGB
+ * space) This is not rounded. */
unsigned char pad;
};
@@ -945,11 +1016,11 @@ extern unsigned char frame_dumb[];
typedef unsigned char_t;
typedef struct {
- char_t ch :24;
+ char_t ch : 24;
unsigned char at;
} chr;
-#define chr_has_padding (sizeof(chr) != 4)
+#define chr_has_padding (sizeof(chr) != 4)
struct links_event {
int ev;
@@ -958,15 +1029,7 @@ struct links_event {
long b;
};
-enum ev {
- EV_INIT,
- EV_KBD,
- EV_MOUSE,
- EV_EXTRA,
- EV_REDRAW,
- EV_RESIZE,
- EV_ABORT
-};
+enum ev { EV_INIT, EV_KBD, EV_MOUSE, EV_EXTRA, EV_REDRAW, EV_RESIZE, EV_ABORT };
#define EV_EXTRA_OPEN_URL EV_INIT
enum evh {
@@ -978,25 +1041,26 @@ enum evh {
};
struct window {
- list_entry_1st
- void (*handler)(struct window *, struct links_event *, int fwd);
+ list_entry_1st void (*handler)(struct window *, struct links_event *,
+ int fwd);
void *data;
int xp, yp;
struct terminal *term;
};
-#define MAX_TERM_LEN 32 /* this must be multiple of 8! (alignment problems) */
+#define MAX_TERM_LEN 32 /* this must be multiple of 8! (alignment problems) */
-#define MAX_CWD_LEN 4096 /* this must be multiple of 8! (alignment problems) */
+#define MAX_CWD_LEN \
+ 4096 /* this must be multiple of 8! (alignment problems) \
+ */
-#define ENV_XWIN 1
-#define ENV_SCREEN 2
+#define ENV_XWIN 1
+#define ENV_SCREEN 2
struct term_spec;
struct terminal {
- list_entry_1st
- tcount count;
+ list_entry_1st tcount count;
int x;
int y;
@@ -1034,8 +1098,7 @@ struct terminal {
};
struct term_spec {
- list_entry_1st
- unsigned char term[MAX_TERM_LEN];
+ list_entry_1st unsigned char term[MAX_TERM_LEN];
int mode;
int m11_hack;
int restrict_852;
@@ -1048,15 +1111,16 @@ struct term_spec {
int bottom_margin;
};
-#define TERM_DUMB 0
-#define TERM_VT100 1
+#define TERM_DUMB 0
+#define TERM_VT100 1
-#define ATTR_FRAME 0x80
+#define ATTR_FRAME 0x80
extern struct list_head term_specs;
extern struct list_head terminals;
-static inline int term_charset(struct terminal *term)
+static inline int
+term_charset(struct terminal *term)
{
return 0;
}
@@ -1066,19 +1130,22 @@ int hard_read(int, unsigned char *, int);
unsigned char *get_cwd(void);
void set_cwd(unsigned char *);
unsigned char get_attribute(int, int);
-struct terminal *init_term(int, int, void (*)(struct window *, struct links_event *, int));
+struct terminal *
+init_term(int, int, void (*)(struct window *, struct links_event *, int));
struct term_spec *new_term_spec(unsigned char *);
void free_term_specs(void);
void destroy_terminal(void *);
void cls_redraw_all_terminals(void);
void redraw_below_window(struct window *);
-void add_window(struct terminal *, void (*)(struct window *, struct links_event *, int), void *);
+void add_window(struct terminal *,
+ void (*)(struct window *, struct links_event *, int), void *);
void delete_window(struct window *);
void delete_window_ev(struct window *, struct links_event *ev);
void set_window_ptr(struct window *, int, int);
void get_parent_ptr(struct window *, int *, int *);
void add_empty_window(struct terminal *, void (*)(void *), void *);
-void draw_to_window(struct window *, void (*)(struct terminal *, void *), void *);
+void draw_to_window(struct window *, void (*)(struct terminal *, void *),
+ void *);
void redraw_all_terminals(void);
void flush_terminal(struct terminal *);
@@ -1091,17 +1158,19 @@ void set_line(struct terminal *, int, int, int, chr *);
void set_line_color(struct terminal *, int, int, int, unsigned char);
void fill_area(struct terminal *, int, int, int, int, unsigned, unsigned char);
void draw_frame(struct terminal *, int, int, int, int, unsigned char, int);
-void print_text(struct terminal *, int, int, int, unsigned char *, unsigned char);
+void print_text(struct terminal *, int, int, int, unsigned char *,
+ unsigned char);
void set_cursor(struct terminal *, int, int, int, int);
void destroy_all_terminals(void);
void block_itrm(int);
int unblock_itrm(int);
-#define TERM_FN_TITLE 1
-#define TERM_FN_RESIZE 2
+#define TERM_FN_TITLE 1
+#define TERM_FN_RESIZE 2
-void exec_on_terminal(struct terminal *, unsigned char *, unsigned char *, unsigned char);
+void exec_on_terminal(struct terminal *, unsigned char *, unsigned char *,
+ unsigned char);
void do_terminal_function(struct terminal *, unsigned char, unsigned char *);
void set_terminal_title(struct terminal *, unsigned char *);
struct terminal *find_terminal(tcount count);
@@ -1136,15 +1205,14 @@ int attach_terminal(void *, int);
/* objreq.c */
-#define O_WAITING 0
-#define O_LOADING 1
-#define O_FAILED -1
-#define O_INCOMPLETE -2
-#define O_OK -3
+#define O_WAITING 0
+#define O_LOADING 1
+#define O_FAILED -1
+#define O_INCOMPLETE -2
+#define O_OK -3
struct object_request {
- list_entry_1st
- int refcount;
+ list_entry_1st int refcount;
tcount count;
tcount term;
struct status stat;
@@ -1152,7 +1220,7 @@ struct object_request {
struct cache_entry *ce;
unsigned char *orig_url;
unsigned char *url;
- unsigned char *prev_url; /* allocated string with referrer or NULL */
+ unsigned char *prev_url; /* allocated string with referrer or NULL */
unsigned char *goto_position;
int pri;
int cache;
@@ -1160,8 +1228,8 @@ struct object_request {
void *data;
int redirect_cnt;
int state;
-#define HOLD_AUTH 1
-#define HOLD_CERT 2
+#define HOLD_AUTH 1
+#define HOLD_CERT 2
int hold;
int dont_print_error;
struct timer *timer;
@@ -1171,7 +1239,9 @@ struct object_request {
uttime last_update;
};
-void request_object(struct terminal *, unsigned char *, unsigned char *, int, int, int, void (*)(struct object_request *, void *), void *, struct object_request **);
+void request_object(struct terminal *, unsigned char *, unsigned char *, int,
+ int, int, void (*)(struct object_request *, void *), void *,
+ struct object_request **);
void clone_object(struct object_request *, struct object_request **);
void release_object(struct object_request **);
void release_object_get_stat(struct object_request **, struct status *, int);
@@ -1181,7 +1251,8 @@ void detach_object_connection(struct object_request *, off_t);
extern int decompressed_cache_size;
-int get_file_by_term(struct terminal *term, struct cache_entry *ce, unsigned char **start, size_t *len, int *errp);
+int get_file_by_term(struct terminal *term, struct cache_entry *ce,
+ unsigned char **start, size_t *len, int *errp);
int get_file(struct object_request *o, unsigned char **start, size_t *len);
void free_decompressed_data(struct cache_entry *e);
void add_compress_methods(unsigned char **s, int *l);
@@ -1192,7 +1263,7 @@ struct link_def {
unsigned char *link;
unsigned char *target;
- unsigned char *label; /* only for image maps */
+ unsigned char *label; /* only for image maps */
unsigned char *shape;
unsigned char *coords;
@@ -1225,14 +1296,10 @@ struct form {
int num;
};
-enum fm {
- FM_GET,
- FM_POST,
- FM_POST_MP
-};
+enum fm { FM_GET, FM_POST, FM_POST_MP };
enum fc {
- FC_TEXT = 1,
+ FC_TEXT = 1,
FC_PASSWORD,
FC_FILE_UPLOAD,
FC_TEXTAREA,
@@ -1249,10 +1316,10 @@ enum fc {
struct menu_item;
struct form_control {
- list_entry_1st
- int form_num; /* cislo formulare */
- int ctrl_num; /* identifikace polozky v ramci formulare */
- int g_ctrl_num; /* identifikace polozky mezi vsemi polozkami (poradi v poli form_info) */
+ list_entry_1st int form_num; /* cislo formulare */
+ int ctrl_num; /* identifikace polozky v ramci formulare */
+ int g_ctrl_num; /* identifikace polozky mezi vsemi polozkami (poradi v
+ poli form_info) */
int position;
int method;
unsigned char *action;
@@ -1268,7 +1335,7 @@ struct form_control {
int size;
int cols, rows, wrap;
int maxlength;
- int nvalues; /* number of values in a select item */
+ int nvalues; /* number of values in a select item */
unsigned char **values; /* values of a select item */
unsigned char **labels; /* labels (shown text) of a select item */
struct menu_item *menu;
@@ -1293,41 +1360,36 @@ struct format_text_cache_entry {
};
struct form_state {
- int form_num; /* cislo formulare */
- int ctrl_num; /* identifikace polozky v ramci formulare */
- int g_ctrl_num; /* identifikace polozky mezi vsemi polozkami (poradi v poli form_info) */
+ int form_num; /* cislo formulare */
+ int ctrl_num; /* identifikace polozky v ramci formulare */
+ int g_ctrl_num; /* identifikace polozky mezi vsemi polozkami (poradi v
+ poli form_info) */
int position;
int type;
unsigned char *string; /* selected value of a select item */
- int state; /* index of selected item of a select item */
+ int state; /* index of selected item of a select item */
int vpos;
int vypos;
struct format_text_cache_entry *ftce;
};
struct link {
- int type; /* one of L_XXX constants */
- int num; /* link number (used when user turns on link numbering) */
- unsigned char *where; /* URL of the link */
- unsigned char *target; /* name of target frame where to open the link */
- unsigned char *where_img; /* URL of image (if any) */
- unsigned char *img_alt; /* alt of image (if any) - valid only when link is an image */
- struct form_control *form; /* form info, usually NULL */
- unsigned sel_color; /* link color */
- int n; /* number of points */
+ int type; /* one of L_XXX constants */
+ int num; /* link number (used when user turns on link numbering) */
+ unsigned char *where; /* URL of the link */
+ unsigned char *target; /* name of target frame where to open the link */
+ unsigned char *where_img; /* URL of image (if any) */
+ unsigned char *img_alt; /* alt of image (if any) - valid only when link
+ is an image */
+ struct form_control *form; /* form info, usually NULL */
+ unsigned sel_color; /* link color */
+ int n; /* number of points */
int first_point_to_move;
struct point *pos;
int obj_order;
};
-enum l_link {
- L_LINK,
- L_BUTTON,
- L_CHECKBOX,
- L_SELECT,
- L_FIELD,
- L_AREA
-};
+enum l_link { L_LINK, L_BUTTON, L_CHECKBOX, L_SELECT, L_FIELD, L_AREA };
struct link_bg {
int x, y;
@@ -1335,8 +1397,7 @@ struct link_bg {
};
struct tag {
- list_entry_1st
- int x;
+ list_entry_1st int x;
int y;
unsigned char name[1];
};
@@ -1373,7 +1434,6 @@ struct document_setup {
int g_ignore_document_color;
};
-
/* IMPORTANT!!!!!
* if you add anything, fix it in compare_opt and if you add it into
* document_setup, fix it in ds2do too
@@ -1397,10 +1457,12 @@ struct document_options {
int image_scale;
int porn_enable;
tcount gamma_stamp;
- int real_cp; /* codepage of document. Does not really belong here. Must not be compared. Used only in get_attr_val */
+ int real_cp; /* codepage of document. Does not really belong here. Must
+ not be compared. Used only in get_attr_val */
};
-static inline void color2rgb(struct rgb *rgb, int color)
+static inline void
+color2rgb(struct rgb *rgb, int color)
{
memset(rgb, 0, sizeof(struct rgb));
rgb->r = (color >> 16) & 0xff;
@@ -1408,7 +1470,8 @@ static inline void color2rgb(struct rgb *rgb, int color)
rgb->b = color & 0xff;
}
-static inline void ds2do(struct document_setup *ds, struct document_options *doo, int col)
+static inline void
+ds2do(struct document_setup *ds, struct document_options *doo, int col)
{
doo->assume_cp = ds->assume_cp;
doo->hard_assume = ds->hard_assume;
@@ -1437,8 +1500,7 @@ static inline void ds2do(struct document_setup *ds, struct document_options *doo
}
struct node {
- list_entry_1st
- int x, y;
+ list_entry_1st int x, y;
int xw, yw;
};
@@ -1463,15 +1525,16 @@ struct frame_desc {
};
struct frameset_desc {
- int n; /* = x * y */
- int x, y; /* velikost */
- int xp, yp; /* pozice pri pridavani */
+ int n; /* = x * y */
+ int x, y; /* velikost */
+ int xp, yp; /* pozice pri pridavani */
struct frame_desc f[1];
};
struct f_data;
-struct additional_file *request_additional_file(struct f_data *f, unsigned char *url);
+struct additional_file *request_additional_file(struct f_data *f,
+ unsigned char *url);
/*
* warning: if you add more additional file stuctures, you must
@@ -1480,12 +1543,11 @@ struct additional_file *request_additional_file(struct f_data *f, unsigned char
struct additional_files {
int refcount;
- struct list_head af; /* struct additional_file */
+ struct list_head af; /* struct additional_file */
};
struct additional_file {
- list_entry_1st
- struct object_request *rq;
+ list_entry_1st struct object_request *rq;
tcount use_tag;
tcount use_tag2;
int need_reparse;
@@ -1494,8 +1556,7 @@ struct additional_file {
};
struct f_data {
- list_entry_1st
- struct session *ses;
+ list_entry_1st struct session *ses;
struct f_data_c *fd;
struct object_request *rq;
tcount use_tag;
@@ -1507,7 +1568,8 @@ struct f_data {
uttime time_to_get;
uttime time_to_draw;
struct frameset_desc *frame_desc;
- int frame_desc_link; /* if != 0, do not free frame_desc because it is link */
+ int frame_desc_link; /* if != 0, do not free frame_desc because it is
+ link */
/* text only */
int bg;
@@ -1516,7 +1578,7 @@ struct f_data {
int nlinks;
struct link **lines1;
struct link **lines2;
- struct list_head nodes; /* struct node */
+ struct list_head nodes; /* struct node */
struct search *search_pos;
char_t *search_chr;
int nsearch_chr;
@@ -1524,14 +1586,15 @@ struct f_data {
int *slines1;
int *slines2;
- struct list_head forms; /* struct form_control */
- struct list_head tags; /* struct tag */
-
+ struct list_head forms; /* struct form_control */
+ struct list_head tags; /* struct tag */
unsigned char *refresh;
int refresh_seconds;
- int uncacheable; /* cannot be cached - either created from source modified by document.write or modified by javascript */
+ int uncacheable; /* cannot be cached - either created from source
+ modified by document.write or modified by javascript
+ */
};
struct view_state {
@@ -1541,7 +1604,7 @@ struct view_state {
int view_posx;
int orig_view_pos;
int orig_view_posx;
- int current_link; /* platny jen kdyz je <f_data->n_links */
+ int current_link; /* platny jen kdyz je <f_data->n_links */
int orig_link;
int frame_pos;
int plain;
@@ -1557,8 +1620,7 @@ struct view_state {
struct location;
struct f_data_c {
- list_entry_1st
- struct f_data_c *parent;
+ list_entry_1st struct f_data_c *parent;
struct session *ses;
struct location *loc;
struct view_state *vs;
@@ -1579,15 +1641,15 @@ struct f_data_c {
unsigned char *went_to_position;
struct additional_files *af;
- struct list_head subframes; /* struct f_data_c */
+ struct list_head subframes; /* struct f_data_c */
uttime last_update;
uttime next_update_interval;
int done;
int parsed_done;
- int script_t; /* offset of next script to execute */
+ int script_t; /* offset of next script to execute */
- int active; /* temporary, for draw_doc */
+ int active; /* temporary, for draw_doc */
int marginwidth, marginheight;
@@ -1600,17 +1662,16 @@ struct f_data_c {
};
struct location {
- list_entry_1st
- struct location *parent;
- unsigned char *name; /* frame name */
+ list_entry_1st struct location *parent;
+ unsigned char *name; /* frame name */
unsigned char *url;
- unsigned char *prev_url; /* allocated string with referrer */
- struct list_head subframes; /* struct location */
+ unsigned char *prev_url; /* allocated string with referrer */
+ struct list_head subframes; /* struct location */
struct view_state *vs;
unsigned location_id;
};
-#define cur_loc(x) list_struct((x)->history.next, struct location)
+#define cur_loc(x) list_struct((x)->history.next, struct location)
struct kbdprefix {
int rep;
@@ -1619,8 +1680,7 @@ struct kbdprefix {
};
struct download {
- list_entry_1st
- unsigned char *url;
+ list_entry_1st unsigned char *url;
struct status stat;
unsigned char decompress;
unsigned char *cwd;
@@ -1642,15 +1702,15 @@ struct download {
extern struct list_head downloads;
struct session {
- list_entry_1st
- struct list_head history; /* struct location */
+ list_entry_1st struct list_head history; /* struct location */
struct list_head forward_history;
struct terminal *term;
struct window *win;
int id;
- unsigned char *st; /* status line string */
- unsigned char *st_old; /* old status line --- compared with st to prevent cursor flicker */
- unsigned char *default_status; /* default value of the status line */
+ unsigned char *st; /* status line string */
+ unsigned char *st_old; /* old status line --- compared with st to
+ prevent cursor flicker */
+ unsigned char *default_status; /* default value of the status line */
struct f_data_c *screen;
struct object_request *rq;
void (*wtd)(struct session *);
@@ -1673,7 +1733,7 @@ struct session {
unsigned char *last_search_word;
int search_direction;
int exit_query;
- struct list_head format_cache; /* struct f_data */
+ struct list_head format_cache; /* struct f_data */
unsigned char *imgmap_href_base;
unsigned char *imgmap_target_base;
@@ -1713,40 +1773,50 @@ void abort_all_downloads(void);
unsigned char *download_percentage(struct download *down, int pad);
void download_window_function(struct dialog_data *dlg);
void display_download(struct terminal *, void *, void *);
-struct f_data *cached_format_html(struct f_data_c *fd, struct object_request *rq, unsigned char *url, struct document_options *opt, int *cch, int report_status);
+struct f_data *cached_format_html(struct f_data_c *fd,
+ struct object_request *rq, unsigned char *url,
+ struct document_options *opt, int *cch,
+ int report_status);
struct f_data_c *create_f_data_c(struct session *, struct f_data_c *);
void reinit_f_data_c(struct f_data_c *);
int f_data_c_allow_flags(struct f_data_c *fd);
-#define CDF_RESTRICT_PERMISSION 1
-#define CDF_EXCL 2
-#define CDF_NOTRUNC 4
-#define CDF_NO_POPUP_ON_EEXIST 8
-int create_download_file(struct session *, unsigned char *, unsigned char *, int, off_t);
+#define CDF_RESTRICT_PERMISSION 1
+#define CDF_EXCL 2
+#define CDF_NOTRUNC 4
+#define CDF_NO_POPUP_ON_EEXIST 8
+int create_download_file(struct session *, unsigned char *, unsigned char *,
+ int, off_t);
void *create_session_info(int, unsigned char *, unsigned char *, int *);
void win_func(struct window *, struct links_event *, int);
-void goto_url_f(struct session *, void (*)(struct session *), unsigned char *, unsigned char *, struct f_data_c *, int, int, int, int);
+void goto_url_f(struct session *, void (*)(struct session *), unsigned char *,
+ unsigned char *, struct f_data_c *, int, int, int, int);
void goto_url(void *, unsigned char *);
void goto_url_utf8(struct session *, unsigned char *);
-void goto_url_not_from_dialog(struct session *, unsigned char *, struct f_data_c *);
-void goto_imgmap(struct session *ses, struct f_data_c *fd, unsigned char *url, unsigned char *href, unsigned char *target);
+void goto_url_not_from_dialog(struct session *, unsigned char *,
+ struct f_data_c *);
+void goto_imgmap(struct session *ses, struct f_data_c *fd, unsigned char *url,
+ unsigned char *href, unsigned char *target);
void map_selected(struct terminal *term, void *ld, void *ses_);
void go_back(struct session *, int);
void go_backwards(struct terminal *term, void *psteps, void *ses_);
void reload(struct session *, int);
void cleanup_session(struct session *);
void destroy_session(struct session *);
-struct f_data_c *find_frame(struct session *ses, unsigned char *target, struct f_data_c *base);
-
+struct f_data_c *find_frame(struct session *ses, unsigned char *target,
+ struct f_data_c *base);
/* Information about the current document */
unsigned char *get_current_url(struct session *, unsigned char *, size_t);
unsigned char *get_current_title(struct f_data_c *, unsigned char *, size_t);
-unsigned char *get_form_url(struct session *ses, struct f_data_c *f, struct form_control *form, int *onsubmit);
+unsigned char *get_form_url(struct session *ses, struct f_data_c *f,
+ struct form_control *form, int *onsubmit);
/* bfu.c */
-extern struct style *bfu_style_wb, *bfu_style_bw, *bfu_style_wb_b, *bfu_style_bw_u, *bfu_style_bw_mono, *bfu_style_wb_mono, *bfu_style_wb_mono_u;
+extern struct style *bfu_style_wb, *bfu_style_bw, *bfu_style_wb_b,
+ *bfu_style_bw_u, *bfu_style_bw_mono, *bfu_style_wb_mono,
+ *bfu_style_wb_mono_u;
extern long bfu_bg_color, bfu_fg_color;
struct memory_list {
@@ -1758,12 +1828,12 @@ struct memory_list *getml(void *, ...);
void add_to_ml(struct memory_list **, ...);
void freeml(struct memory_list *);
-#define DIALOG_LB (DIALOG_LEFT_BORDER + DIALOG_LEFT_INNER_BORDER + 1)
-#define DIALOG_TB (DIALOG_TOP_BORDER + DIALOG_TOP_INNER_BORDER + 1)
+#define DIALOG_LB (DIALOG_LEFT_BORDER + DIALOG_LEFT_INNER_BORDER + 1)
+#define DIALOG_TB (DIALOG_TOP_BORDER + DIALOG_TOP_INNER_BORDER + 1)
extern unsigned char m_bar;
-#define M_BAR (&m_bar)
+#define M_BAR (&m_bar)
struct menu_item {
unsigned char *text;
@@ -1776,10 +1846,10 @@ struct menu_item {
};
enum menu_items {
- MENU_FREE_ITEMS = 1,
- MENU_FREE_TEXT = 2,
- MENU_FREE_RTEXT = 4,
- MENU_FREE_HOTKEY = 8
+ MENU_FREE_ITEMS = 1,
+ MENU_FREE_TEXT = 2,
+ MENU_FREE_RTEXT = 4,
+ MENU_FREE_HOTKEY = 8
};
struct menu {
@@ -1808,8 +1878,7 @@ struct mainmenu {
};
struct history_item {
- list_entry_1st
- unsigned char str[1];
+ list_entry_1st unsigned char str[1];
};
struct history {
@@ -1817,20 +1886,11 @@ struct history {
struct list_head items;
};
-#define free_history(h) free_list(struct history_item, (h).items)
+#define free_history(h) free_list(struct history_item, (h).items)
-enum dlog {
- D_END,
- D_CHECKBOX,
- D_FIELD,
- D_FIELD_PASS,
- D_BUTTON
-};
+enum dlog { D_END, D_CHECKBOX, D_FIELD, D_FIELD_PASS, D_BUTTON };
-enum bfu {
- B_ENTER = 1,
- B_ESC
-};
+enum bfu { B_ENTER = 1, B_ESC };
struct dialog_item_data;
@@ -1839,7 +1899,8 @@ typedef void (*input_field_button_fn)(void *, unsigned char *);
struct dialog_item {
int type;
- int gid, gnum; /* for buttons: gid - flags B_XXX */ /* for fields: min/max */ /* for box: gid is box height */
+ int gid, gnum; /* for buttons: gid - flags B_XXX */
+ /* for fields: min/max */ /* for box: gid is box height */
int (*fn)(struct dialog_data *, struct dialog_item_data *);
struct history *history;
int dlen;
@@ -1862,10 +1923,7 @@ struct dialog_item_data {
unsigned char *cdata;
};
-enum even {
- EVENT_PROCESSED,
- EVENT_NOT_PROCESSED
-};
+enum even { EVENT_PROCESSED, EVENT_NOT_PROCESSED };
struct dialog {
unsigned char *title;
@@ -1892,9 +1950,12 @@ struct dialog_data {
};
struct menu_item *new_menu(int);
-void add_to_menu(struct menu_item **, unsigned char *, unsigned char *, unsigned char *, void (*)(struct terminal *, void *, void *), void *, int, int);
+void add_to_menu(struct menu_item **, unsigned char *, unsigned char *,
+ unsigned char *, void (*)(struct terminal *, void *, void *),
+ void *, int, int);
void do_menu(struct terminal *, struct menu_item *, void *);
-void do_menu_selected(struct terminal *, struct menu_item *, void *, int, void (*)(void *), void *);
+void do_menu_selected(struct terminal *, struct menu_item *, void *, int,
+ void (*)(void *), void *);
void do_mainmenu(struct terminal *, struct menu_item *, void *, int);
void do_dialog(struct terminal *, struct dialog *, struct memory_list *);
void dialog_func(struct window *, struct links_event *, int);
@@ -1906,19 +1967,37 @@ int check_local_ip_address(struct dialog_data *, struct dialog_item_data *);
int check_local_ipv6_address(struct dialog_data *, struct dialog_item_data *);
void max_text_width(struct terminal *, unsigned char *, int *, int);
void min_text_width(struct terminal *, unsigned char *, int *, int);
-int dlg_format_text(struct dialog_data *, struct terminal *, unsigned char *, int, int *, int, int *, unsigned char, int);
-void dlg_format_text_and_field(struct dialog_data *, struct terminal *, unsigned char *, struct dialog_item_data *, int, int *, int, int *, unsigned char, int);
-void max_buttons_width(struct terminal *, struct dialog_item_data *, int, int *);
-void min_buttons_width(struct terminal *, struct dialog_item_data *, int, int *);
-void dlg_format_buttons(struct dialog_data *, struct terminal *, struct dialog_item_data *, int, int, int *, int, int *, int);
-void checkboxes_width(struct terminal *, unsigned char * const *, int, int *, void (*)(struct terminal *, unsigned char *, int *, int));
-void dlg_format_checkbox(struct dialog_data *, struct terminal *, struct dialog_item_data *, int, int *, int, int *, unsigned char *);
-void dlg_format_checkboxes(struct dialog_data *, struct terminal *, struct dialog_item_data *, int, int, int *, int, int *, unsigned char * const *);
-void dlg_format_field(struct dialog_data *, struct terminal *, struct dialog_item_data *, int, int *, int, int *, int);
-void max_group_width(struct terminal *, unsigned char * const *, struct dialog_item_data *, int, int *);
-void min_group_width(struct terminal *, unsigned char * const *, struct dialog_item_data *, int, int *);
-void dlg_format_group(struct dialog_data *, struct terminal *, unsigned char * const *, struct dialog_item_data *, int, int, int *, int, int *);
-/*void dlg_format_box(struct terminal *, struct terminal *, struct dialog_item_data *, int, int *, int, int *, int);*/
+int dlg_format_text(struct dialog_data *, struct terminal *, unsigned char *,
+ int, int *, int, int *, unsigned char, int);
+void dlg_format_text_and_field(struct dialog_data *, struct terminal *,
+ unsigned char *, struct dialog_item_data *, int,
+ int *, int, int *, unsigned char, int);
+void max_buttons_width(struct terminal *, struct dialog_item_data *, int,
+ int *);
+void min_buttons_width(struct terminal *, struct dialog_item_data *, int,
+ int *);
+void dlg_format_buttons(struct dialog_data *, struct terminal *,
+ struct dialog_item_data *, int, int, int *, int, int *,
+ int);
+void checkboxes_width(struct terminal *, unsigned char *const *, int, int *,
+ void (*)(struct terminal *, unsigned char *, int *, int));
+void dlg_format_checkbox(struct dialog_data *, struct terminal *,
+ struct dialog_item_data *, int, int *, int, int *,
+ unsigned char *);
+void dlg_format_checkboxes(struct dialog_data *, struct terminal *,
+ struct dialog_item_data *, int, int, int *, int,
+ int *, unsigned char *const *);
+void dlg_format_field(struct dialog_data *, struct terminal *,
+ struct dialog_item_data *, int, int *, int, int *, int);
+void max_group_width(struct terminal *, unsigned char *const *,
+ struct dialog_item_data *, int, int *);
+void min_group_width(struct terminal *, unsigned char *const *,
+ struct dialog_item_data *, int, int *);
+void dlg_format_group(struct dialog_data *, struct terminal *,
+ unsigned char *const *, struct dialog_item_data *, int,
+ int, int *, int, int *);
+/*void dlg_format_box(struct terminal *, struct terminal *, struct
+ * dialog_item_data *, int, int *, int, int *, int);*/
void checkbox_list_fn(struct dialog_data *);
void group_fn(struct dialog_data *);
void center_dlg(struct dialog_data *);
@@ -1931,8 +2010,9 @@ int cancel_dialog(struct dialog_data *, struct dialog_item_data *);
void msg_box_fn(struct dialog_data *dlg);
void msg_box_null(void *);
-#define MSG_BOX_END ((unsigned char *)NULL)
-void msg_box(struct terminal *, struct memory_list *, unsigned char *, int, /*unsigned char *, void *, int,*/ ...);
+#define MSG_BOX_END ((unsigned char *)NULL)
+void msg_box(struct terminal *, struct memory_list *, unsigned char *, int,
+ /*unsigned char *, void *, int,*/...);
/* msg_box arguments:
* terminal,
* blocks to free,
@@ -1946,7 +2026,11 @@ void msg_box(struct terminal *, struct memory_list *, unsigned char *, int, /*un
*/
void input_field_null(void);
-void input_field(struct terminal *, struct memory_list *, unsigned char *, unsigned char *, void *, struct history *, int, unsigned char *, int, int, int (*)(struct dialog_data *, struct dialog_item_data *), int n, ...);
+void input_field(struct terminal *, struct memory_list *, unsigned char *,
+ unsigned char *, void *, struct history *, int,
+ unsigned char *, int, int,
+ int (*)(struct dialog_data *, struct dialog_item_data *),
+ int n, ...);
/* input_field arguments:
* terminal,
* blocks to free,
@@ -1973,7 +2057,8 @@ void input_field(struct terminal *, struct memory_list *, unsigned char *, unsig
*/
void add_to_history(struct terminal *, struct history *, unsigned char *);
-int find_msg_box(struct terminal *term, unsigned char *title, int (*sel)(void *, void *), void *data);
+int find_msg_box(struct terminal *term, unsigned char *title,
+ int (*sel)(void *, void *), void *data);
/* menu.c */
@@ -1982,16 +2067,19 @@ extern struct history goto_url_history;
void activate_keys(struct session *ses);
void reset_settings_for_tor(void);
int save_proxy(int charset, unsigned char *result, unsigned char *proxy);
-int save_noproxy_list(int charset, unsigned char *result, unsigned char *noproxy_list);
+int save_noproxy_list(int charset, unsigned char *result,
+ unsigned char *noproxy_list);
void dialog_html_options(struct session *ses);
void activate_bfu_technology(struct session *, int);
void dialog_goto_url(struct session *ses, unsigned char *url);
void dialog_save_url(struct session *ses);
void free_history_lists(void);
-void query_file(struct session *, unsigned char *, unsigned char *, void (*)(struct session *, unsigned char *, int), void (*)(void *), int);
-#define DOWNLOAD_DEFAULT 0
-#define DOWNLOAD_OVERWRITE 1
-#define DOWNLOAD_CONTINUE 2
+void query_file(struct session *, unsigned char *, unsigned char *,
+ void (*)(struct session *, unsigned char *, int),
+ void (*)(void *), int);
+#define DOWNLOAD_DEFAULT 0
+#define DOWNLOAD_OVERWRITE 1
+#define DOWNLOAD_CONTINUE 2
void search_dlg(struct session *, struct f_data_c *, int);
void search_back_dlg(struct session *, struct f_data_c *, int);
void exit_prog(struct terminal *, void *, void *);
@@ -2009,11 +2097,17 @@ struct conv_table {
};
struct conv_table *get_translation_table(const int, const int);
-static inline int is_entity_terminator(unsigned char c) { return c <= ' ' || c == ';' || c == '&' || c == '/' || c == '?'; }
+static inline int
+is_entity_terminator(unsigned char c)
+{
+ return c <= ' ' || c == ';' || c == '&' || c == '/' || c == '?';
+}
int get_entity_number(unsigned char *st, int l);
unsigned char *get_entity_string(unsigned char *, int);
-unsigned char *convert_string(struct conv_table *, unsigned char *, int, struct document_options *);
-unsigned char *convert(int from, int to, unsigned char *c, struct document_options *dopt);
+unsigned char *convert_string(struct conv_table *, unsigned char *, int,
+ struct document_options *);
+unsigned char *convert(int from, int to, unsigned char *c,
+ struct document_options *dopt);
unsigned char *get_cp_name(int);
unsigned char *get_cp_mime_name(int);
void free_conv_table(void);
@@ -2028,42 +2122,48 @@ unsigned char *to_utf8_upcase(unsigned char *str, int cp);
int compare_case_utf8(unsigned char *u1, unsigned char *u2);
unsigned get_utf_8(unsigned char **p);
-#define GET_UTF_8(s, c) \
-do { \
- if ((unsigned char)(s)[0] < 0x80) \
- (c) = (s)++[0]; \
- else if ((unsigned char)(s)[0] >= 0xc2 && (unsigned char)(s)[0] < 0xe0 &&\
- ((unsigned char)(s)[1] & 0xc0) == 0x80) { \
- (c) = (unsigned char)(s)[0] * 0x40 + (unsigned char)(s)[1], (c) -= 0x3080, (s) += 2;\
- } else \
- (c) = get_utf_8(&(s)); \
-} while (0)
-#define FWD_UTF_8(s) \
-do { \
- if ((unsigned char)(s)[0] < 0x80) \
- (s)++; \
- else \
- get_utf_8(&(s)); \
-} while (0)
-#define BACK_UTF_8(p, b) \
-do { \
- while ((p) > (b)) { \
- (p)--; \
- if ((*(p) & 0xc0) != 0x80) \
- break; \
- } \
-} while (0)
+#define GET_UTF_8(s, c) \
+ do { \
+ if ((unsigned char)(s)[0] < 0x80) \
+ (c) = (s)++[0]; \
+ else if ((unsigned char)(s)[0] >= 0xc2 \
+ && (unsigned char)(s)[0] < 0xe0 \
+ && ((unsigned char)(s)[1] & 0xc0) == 0x80) { \
+ (c) = (unsigned char)(s)[0] * 0x40 \
+ + (unsigned char)(s)[1], \
+ (c) -= 0x3080, (s) += 2; \
+ } else \
+ (c) = get_utf_8(&(s)); \
+ } while (0)
+#define FWD_UTF_8(s) \
+ do { \
+ if ((unsigned char)(s)[0] < 0x80) \
+ (s)++; \
+ else \
+ get_utf_8(&(s)); \
+ } while (0)
+#define BACK_UTF_8(p, b) \
+ do { \
+ while ((p) > (b)) { \
+ (p)--; \
+ if ((*(p)&0xc0) != 0x80) \
+ break; \
+ } \
+ } while (0)
extern unsigned char utf_8_1[256];
-static inline int utf8chrlen(unsigned char c)
+static inline int
+utf8chrlen(unsigned char c)
{
unsigned char l = utf_8_1[c];
- if (l == 7) return 1;
+ if (l == 7)
+ return 1;
return 7 - l;
}
-static inline unsigned GET_TERM_CHAR(struct terminal *term, unsigned char **str)
+static inline unsigned
+GET_TERM_CHAR(struct terminal *term, unsigned char **str)
{
unsigned ch;
GET_UTF_8(*str, ch);
@@ -2080,16 +2180,21 @@ extern int ismap_link, ismap_x, ismap_y;
void frm_download(struct session *, struct f_data_c *);
void frm_download_image(struct session *, struct f_data_c *);
void frm_view_image(struct session *, struct f_data_c *);
-struct format_text_cache_entry *format_text(struct f_data_c *fd, struct form_control *fc, struct form_state *fs);
-int area_cursor(struct f_data_c *f, struct form_control *fc, struct form_state *fs);
+struct format_text_cache_entry *format_text(struct f_data_c *fd,
+ struct form_control *fc,
+ struct form_state *fs);
+int area_cursor(struct f_data_c *f, struct form_control *fc,
+ struct form_state *fs);
struct form_state *find_form_state(struct f_data_c *, struct form_control *);
void fixup_select_state(struct form_control *fc, struct form_state *fs);
int enter(struct session *ses, struct f_data_c *f, int a);
-int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct links_event *ev);
+int field_op(struct session *ses, struct f_data_c *f, struct link *l,
+ struct links_event *ev);
int can_open_in_new(struct terminal *);
void open_in_new_window(struct terminal *, void *fn_, void *ses_);
-extern void (* const send_open_new_xterm_ptr)(struct terminal *, void *fn_, void *ses_);
+extern void (*const send_open_new_xterm_ptr)(struct terminal *, void *fn_,
+ void *ses_);
void destroy_fc(struct form_control *);
void sort_links(struct f_data *);
struct view_state *create_vs(void);
@@ -2108,7 +2213,8 @@ void menu_save_formatted(struct terminal *, void *, void *);
void copy_url_location(struct terminal *, void *, void *);
void selected_item(struct terminal *, void *, void *);
void toggle(struct session *, struct f_data_c *, int);
-void do_for_frame(struct session *, void (*)(struct session *, struct f_data_c *, int), int);
+void do_for_frame(struct session *,
+ void (*)(struct session *, struct f_data_c *, int), int);
int get_current_state(struct session *);
unsigned char *print_current_link(struct session *);
unsigned char *print_current_title(struct session *);
@@ -2127,12 +2233,12 @@ void set_textarea(struct session *, struct f_data_c *, int);
/* html.c */
enum html_attr {
- AT_BOLD = 1,
- AT_ITALIC = 2,
- AT_UNDERLINE = 4,
- AT_FIXED = 8,
- AT_GRAPHICS = 16,
- AT_INVERT = 32
+ AT_BOLD = 1,
+ AT_ITALIC = 2,
+ AT_UNDERLINE = 4,
+ AT_FIXED = 8,
+ AT_GRAPHICS = 16,
+ AT_INVERT = 32
};
enum html_al {
@@ -2177,21 +2283,9 @@ struct text_attrib {
int select_disabled;
};
-enum par_t {
- P_NUMBER = 1,
- P_alpha,
- P_ALPHA,
- P_roman,
- P_ROMAN
-};
+enum par_t { P_NUMBER = 1, P_alpha, P_ALPHA, P_roman, P_ROMAN };
-enum par_s {
- P_STAR = 1,
- P_O,
- P_PLUS,
- P_LISTMASK = 7,
- P_COMPACT
-};
+enum par_s { P_STAR = 1, P_O, P_PLUS, P_LISTMASK = 7, P_COMPACT };
struct par_attrib {
int align;
@@ -2207,12 +2301,11 @@ struct par_attrib {
};
struct html_element {
- list_entry_1st
- struct text_attrib attr;
+ list_entry_1st struct text_attrib attr;
struct par_attrib parattr;
-#define INVISIBLE 1
-#define INVISIBLE_SCRIPT 2
-#define INVISIBLE_STYLE 3
+#define INVISIBLE 1
+#define INVISIBLE_SCRIPT 2
+#define INVISIBLE_STYLE 3
int invisible;
unsigned char *name;
int namelen;
@@ -2232,10 +2325,10 @@ extern int html_format_changed;
extern unsigned char *startf;
extern unsigned char *eofff;
-#define html_top_ list_struct(html_stack.next, struct html_element)
-#define html_top (*html_top_)
-#define format_ (html_top.attr)
-#define par_format (html_top.parattr)
+#define html_top_ list_struct(html_stack.next, struct html_element)
+#define html_top (*html_top_)
+#define format_ (html_top.attr)
+#define par_format (html_top.parattr)
extern void *ff;
extern void (*put_chars_f)(void *, unsigned char *, int);
@@ -2255,7 +2348,8 @@ extern unsigned char *last_image;
extern unsigned char *last_target;
extern struct form_control *last_form;
-int parse_element(unsigned char *, unsigned char *, unsigned char **, int *, unsigned char **, unsigned char **);
+int parse_element(unsigned char *, unsigned char *, unsigned char **, int *,
+ unsigned char **, unsigned char **);
unsigned char *get_attr_val(unsigned char *, unsigned char *);
int has_attr(unsigned char *, unsigned char *);
int get_num(unsigned char *, unsigned char *);
@@ -2266,9 +2360,15 @@ void html_stack_dup(void);
void kill_html_stack_item(struct html_element *);
int should_skip_script(unsigned char *);
unsigned char *skip_comment(unsigned char *, unsigned char *);
-void parse_html(unsigned char *, unsigned char *, void (*)(void *, unsigned char *, int), void (*)(void *), void *(*)(void *, int, ...), void *, unsigned char *);
-int get_image_map(unsigned char *, unsigned char *, unsigned char *, unsigned char *a, struct menu_item **, struct memory_list **, unsigned char *, unsigned char *, int, int, int, int gfx);
-void scan_http_equiv(unsigned char *, unsigned char *, unsigned char **, int *, unsigned char **, unsigned char **, unsigned char **, int *);
+void parse_html(unsigned char *, unsigned char *,
+ void (*)(void *, unsigned char *, int), void (*)(void *),
+ void *(*)(void *, int, ...), void *, unsigned char *);
+int get_image_map(unsigned char *, unsigned char *, unsigned char *,
+ unsigned char *a, struct menu_item **, struct memory_list **,
+ unsigned char *, unsigned char *, int, int, int, int gfx);
+void scan_http_equiv(unsigned char *, unsigned char *, unsigned char **, int *,
+ unsigned char **, unsigned char **, unsigned char **,
+ int *);
int decode_color(unsigned char *, struct rgb *);
@@ -2293,11 +2393,7 @@ struct frameset_param {
int *xw, *yw;
};
-enum scroll {
- SCROLLING_NO,
- SCROLLING_YES,
- SCROLLING_AUTO
-};
+enum scroll { SCROLLING_NO, SCROLLING_YES, SCROLLING_AUTO };
struct frame_param {
struct frameset_desc *parent;
@@ -2360,7 +2456,8 @@ struct frameset_desc *copy_frameset_desc(struct frameset_desc *);
struct f_data *init_formatted(struct document_options *);
void destroy_formatted(struct f_data *);
-/* d_opt je podle Mikulase nedefinovany mimo html parser, tak to jinde nepouzivejte
+/* d_opt je podle Mikulase nedefinovany mimo html parser, tak to jinde
+ * nepouzivejte
*
* -- Brain
*/
@@ -2378,29 +2475,37 @@ void xset_hchars(struct part *, int, int, int, unsigned, unsigned char);
void html_tag(struct f_data *, unsigned char *, int, int);
void process_script(struct f_data *, unsigned char *);
void set_base(struct f_data *, unsigned char *);
-void html_process_refresh(struct f_data *, unsigned char *, int );
+void html_process_refresh(struct f_data *, unsigned char *, int);
int compare_opt(struct document_options *, struct document_options *);
void copy_opt(struct document_options *, struct document_options *);
struct link *new_link(struct f_data *);
-struct conv_table *get_convert_table(unsigned char *, int, int, int *, int *, int);
-struct part *format_html_part(unsigned char *, unsigned char *, int, int, int, struct f_data *, int, int, unsigned char *, int);
-void really_format_html(struct cache_entry *, unsigned char *, unsigned char *, struct f_data *, int frame);
+struct conv_table *get_convert_table(unsigned char *, int, int, int *, int *,
+ int);
+struct part *format_html_part(unsigned char *, unsigned char *, int, int, int,
+ struct f_data *, int, int, unsigned char *, int);
+void really_format_html(struct cache_entry *, unsigned char *, unsigned char *,
+ struct f_data *, int frame);
struct link *get_link_at_location(struct f_data *f, int x, int y);
int get_search_data(struct f_data *);
-struct frameset_desc *create_frameset(struct f_data *fda, struct frameset_param *fp);
+struct frameset_desc *create_frameset(struct f_data *fda,
+ struct frameset_param *fp);
void create_frame(struct frame_param *fp);
/* html_tbl.c */
-unsigned char *skip_element(unsigned char *, unsigned char *, unsigned char *, int);
-void format_table(unsigned char *, unsigned char *, unsigned char *, unsigned char **, void *);
+unsigned char *skip_element(unsigned char *, unsigned char *, unsigned char *,
+ int);
+void format_table(unsigned char *, unsigned char *, unsigned char *,
+ unsigned char **, void *);
void table_bg(struct text_attrib *ta, unsigned char bgstr[8]);
-void *find_table_cache_entry(unsigned char *start, unsigned char *end, int align, int m, int width, int xs, int link_num);
-void add_table_cache_entry(unsigned char *start, unsigned char *end, int align, int m, int width, int xs, int link_num, void *p);
+void *find_table_cache_entry(unsigned char *start, unsigned char *end,
+ int align, int m, int width, int xs, int link_num);
+void add_table_cache_entry(unsigned char *start, unsigned char *end, int align,
+ int m, int width, int xs, int link_num, void *p);
/* default.c */
@@ -2419,21 +2524,20 @@ void load_url_history(void);
void save_url_history(void);
struct driver_param {
- list_entry_1st
- int kbd_codepage;
+ list_entry_1st int kbd_codepage;
int palette_mode;
unsigned char *param;
unsigned char shell_term[MAX_STR_LEN];
int nosave;
unsigned char name[1];
};
- /* -if exec is NULL, shell_term is unused
- -otherwise this string describes shell to be executed by the
- exec function, the '%' char means string to be executed
- -shell cannot be NULL
- -if exec is !NULL and shell is empty, exec should use some
- default shell (e.g. "xterm -e %")
- */
+/* -if exec is NULL, shell_term is unused
+ -otherwise this string describes shell to be executed by the
+ exec function, the '%' char means string to be executed
+ -shell cannot be NULL
+ -if exec is !NULL and shell is empty, exec should use some
+ default shell (e.g. "xterm -e %")
+*/
struct driver_param *get_driver_param(unsigned char *);
@@ -2447,8 +2551,8 @@ extern int first_use;
extern int disable_libevent;
extern int no_connect;
extern int base_session;
-#define D_DUMP 1
-#define D_SOURCE 2
+#define D_DUMP 1
+#define D_SOURCE 2
extern int dmp;
extern int screen_width;
extern int dump_codepage;
@@ -2530,9 +2634,9 @@ extern struct http_options http_options;
extern unsigned char download_dir[];
-#define SCRUB_HEADERS (proxies.only_proxies || http_options.header.fake_firefox)
+#define SCRUB_HEADERS (proxies.only_proxies || http_options.header.fake_firefox)
-extern double display_red_gamma,display_green_gamma,display_blue_gamma;
+extern double display_red_gamma, display_green_gamma, display_blue_gamma;
extern double user_gamma;
extern double bfu_aspect;
extern int dither_letters;
@@ -2548,76 +2652,102 @@ extern struct document_setup dds;
/* listedit.c */
-enum title {
- TITLE_EDIT,
- TITLE_ADD
-};
+enum title { TITLE_EDIT, TITLE_ADD };
struct list {
- list_entry_1st
- unsigned char type;
+ list_entry_1st unsigned char type;
/*
* bit 0: 0=item, 1=directory
* bit 1: directory is open (1)/closed (0); for item unused
* bit 2: 1=item is selected 0=item is not selected
*/
int depth;
- struct list *fotr; /* ignored when list is flat */
+ struct list *fotr; /* ignored when list is flat */
};
-#define list_next(l) (list_struct((l)->list_entry.next, struct list))
-#define list_prev(l) (list_struct((l)->list_entry.prev, struct list))
+#define list_next(l) (list_struct((l)->list_entry.next, struct list))
+#define list_prev(l) (list_struct((l)->list_entry.prev, struct list))
-#define list_head_1st struct list head;
+#define list_head_1st struct list head;
#define list_head_last
struct list_description {
- unsigned char type; /* 0=flat, 1=tree */
- struct list *list; /* head of the list */
- struct list *(*new_item)(void * /* data in internal format */); /* creates new item, does NOT add to the list */
- void (*edit_item)(struct dialog_data *, struct list *, void (*)(struct dialog_data *, struct list *, struct list *, struct list_description *) /* ok function */, struct list * /* parameter for the ok_function */, unsigned char); /* must call call delete_item on the item after all */
- void *(*default_value)(struct session *, unsigned char /* 0=item, 1=directory */); /* called when add button is pressed, allocates memory, return value is passed to the new_item function, new_item fills the item with this data */
- void (*delete_item)(struct list *); /* delete item, if next and prev are not NULL adjusts pointers in the list */
- void (*copy_item)(struct list * /* old */, struct list * /* new */); /* gets 2 allocated items, copies all item data except pointers from first item to second one, old data (in second item) will be destroyed */
+ unsigned char type; /* 0=flat, 1=tree */
+ struct list *list; /* head of the list */
+ struct list *(*new_item)(
+ void * /* data in internal format */); /* creates new item, does NOT
+ add to the list */
+ void (*edit_item)(struct dialog_data *, struct list *,
+ void (*)(struct dialog_data *, struct list *,
+ struct list *,
+ struct list_description *) /* ok function */,
+ struct list * /* parameter for the ok_function */,
+ unsigned char); /* must call call delete_item on the
+ item after all */
+ void *(*default_value)(
+ struct session *,
+ unsigned char /* 0=item, 1=directory */); /* called when add button
+ is pressed, allocates
+ memory, return value is
+ passed to the new_item
+ function, new_item
+ fills the item with
+ this data */
+ void (*delete_item)(
+ struct list *); /* delete item, if next and prev are not NULL
+ adjusts pointers in the list */
+ void (*copy_item)(
+ struct list * /* old */,
+ struct list
+ * /* new */); /* gets 2 allocated items, copies all item data
+ except pointers from first item to second one,
+ old data (in second item) will be destroyed */
unsigned char *(*type_item)(struct terminal *, struct list *, int /* 0=type whole item (e.g. when deleting item), 1=type only e.g title (in list window )*/); /* alllocates buffer and writes item into it */
- struct list *(*find_item)(struct list *start_item, unsigned char *string, int direction /* 1 or -1 */); /* returns pointer to the first item matching given string or NULL if failed. Search starts at start_item including. */
+ struct list *(*find_item)(
+ struct list *start_item, unsigned char *string,
+ int direction /* 1 or -1 */); /* returns pointer to the first item
+ matching given string or NULL if
+ failed. Search starts at start_item
+ including. */
struct history *search_history;
- int codepage; /* codepage of all string */
- int n_items; /* number of items in main window */
+ int codepage; /* codepage of all string */
+ int n_items; /* number of items in main window */
/* following items are string codes */
- int item_description; /* e.g. "bookmark" or "extension" ... */
- int already_in_use; /* e.g. "Bookmarks window is already open" */
- int window_title; /* main window title */
- int delete_dialog_title; /* e.g. "Delete bookmark dialog" */
- int button; /* when there's no button button_fn is NULL */
-
- void (*button_fn)(struct session *, struct list *); /* gets pointer to the item */
+ int item_description; /* e.g. "bookmark" or "extension" ... */
+ int already_in_use; /* e.g. "Bookmarks window is already open" */
+ int window_title; /* main window title */
+ int delete_dialog_title; /* e.g. "Delete bookmark dialog" */
+ int button; /* when there's no button button_fn is NULL */
+
+ void (*button_fn)(struct session *,
+ struct list *); /* gets pointer to the item */
void (*save)(struct session *);
/* internal variables, should not be modified, initially set to 0 */
struct list *current_pos;
struct list *win_offset;
int win_pos;
- int open; /* 0=closed, 1=open */
- int modified; /* listedit reports 1 when the list was modified by user (and should be e.g. saved) */
- struct dialog_data *dlg; /* current dialog, valid only when open==1 */
+ int open; /* 0=closed, 1=open */
+ int modified; /* listedit reports 1 when the list was modified by user
+ (and should be e.g. saved) */
+ struct dialog_data *dlg; /* current dialog, valid only when open==1 */
unsigned char *search_word;
int search_direction;
};
int test_list_window_in_use(struct list_description *ld, struct terminal *term);
-int create_list_window(struct list_description *, struct list *, struct terminal *, struct session *);
-void reinit_list_window(struct list_description *ld); /* reinitializes list window */
-
+int create_list_window(struct list_description *, struct list *,
+ struct terminal *, struct session *);
+void
+reinit_list_window(struct list_description *ld); /* reinitializes list window */
/* types.c */
struct list;
struct assoc {
- list_head_1st
- unsigned char *label;
+ list_head_1st unsigned char *label;
unsigned char *ct;
unsigned char *prog;
int cons;
@@ -2631,15 +2761,13 @@ struct assoc {
};
struct extension {
- list_head_1st
- unsigned char *ext;
+ list_head_1st unsigned char *ext;
unsigned char *ct;
list_head_last
};
struct protocol_program {
- list_entry_1st
- unsigned char *prog;
+ list_entry_1st unsigned char *prog;
int system;
};
@@ -2649,7 +2777,8 @@ extern struct list extensions;
unsigned char *get_compress_by_extension(char *, char *);
unsigned char *get_content_type_by_extension(unsigned char *url);
unsigned char *get_content_type(unsigned char *, unsigned char *);
-unsigned char *get_content_encoding(unsigned char *head, unsigned char *url, int just_ce);
+unsigned char *get_content_encoding(unsigned char *head, unsigned char *url,
+ int just_ce);
unsigned char *encoding_2_extension(unsigned char *);
struct assoc *get_type_assoc(struct terminal *term, unsigned char *, int *);
int is_html_type(unsigned char *ct);
@@ -2671,8 +2800,8 @@ void free_types(void);
/* Where all bookmarks are kept */
extern struct list bookmarks;
-void finalize_bookmarks(void); /* called, when exiting links */
-void init_bookmarks(void); /* called at start */
+void finalize_bookmarks(void); /* called, when exiting links */
+void init_bookmarks(void); /* called at start */
void reinit_bookmarks(struct session *ses, unsigned char *new_bookmarks_file);
/* Launches bookmark manager */
diff --git a/listedit.c b/listedit.c
@@ -5,7 +5,6 @@
#include "links.h"
-
/*
(#####)
(#########)
@@ -58,7 +57,8 @@
* - zavri adresar
* mezera toggle adresar
* ins, *, 8, i toggle oznacit
- * ?, /, N, n hledani nahoru, dolu, znova, znova na druhou stranu
+ * ?, /, N, n hledani nahoru, dolu, znova,
+ * znova na druhou stranu
*/
/*
@@ -160,26 +160,26 @@
* type_item vraci text prekodovany do kodovani terminalu, ktery dostane.
*/
-
/* struct list *current_pos; current cursor position in the list */
/* struct list *win_offset; item at the top of the window */
/* int win_pos; current y position in the window */
#define BOHNICE "+420-2-84016111"
-#define BFU_ELEMENT_EMPTY 0
-#define BFU_ELEMENT_PIPE 1
-#define BFU_ELEMENT_L 2
-#define BFU_ELEMENT_TEE 3
-#define BFU_ELEMENT_CLOSED 4
-#define BFU_ELEMENT_CLOSED_DOWN 5
-#define BFU_ELEMENT_OPEN 6
-#define BFU_ELEMENT_OPEN_DOWN 7
+#define BFU_ELEMENT_EMPTY 0
+#define BFU_ELEMENT_PIPE 1
+#define BFU_ELEMENT_L 2
+#define BFU_ELEMENT_TEE 3
+#define BFU_ELEMENT_CLOSED 4
+#define BFU_ELEMENT_CLOSED_DOWN 5
+#define BFU_ELEMENT_OPEN 6
+#define BFU_ELEMENT_OPEN_DOWN 7
/* for mouse scrolling */
static long last_mouse_y;
-static void list_edit_toggle(struct dialog_data *dlg, struct list_description *ld);
+static void list_edit_toggle(struct dialog_data *dlg,
+ struct list_description *ld);
#define sirka_scrollovadla 0
@@ -191,95 +191,97 @@ static void list_edit_toggle(struct dialog_data *dlg, struct list_description *l
/* draws one of BFU elements: | |- [-] [+] */
/* BFU elements are used in the list window */
/* this function also defines shape and size of the elements */
-/* returns width of the BFU element (all elements have the same size, but sizes differ if we're in text mode or in graphics mode) */
-static int draw_bfu_element(struct terminal * term, int x, int y, unsigned char c, long b, long f, unsigned char type, unsigned char selected)
+/* returns width of the BFU element (all elements have the same size, but sizes
+ * differ if we're in text mode or in graphics mode) */
+static int
+draw_bfu_element(struct terminal *term, int x, int y, unsigned char c, long b,
+ long f, unsigned char type, unsigned char selected)
{
- unsigned char vertical=179;
- unsigned char horizontal=196;
- unsigned char tee=195;
- unsigned char l=192;
-
- switch (type)
- {
- case BFU_ELEMENT_EMPTY:
- c|=ATTR_FRAME;
- set_char(term,x,y,' ',c);
- set_char(term,x+1,y,' ',c);
- set_char(term,x+2,y,' ',c);
- set_char(term,x+3,y,' ',c);
- set_char(term,x+4,y,' ',c);
- break;
+ unsigned char vertical = 179;
+ unsigned char horizontal = 196;
+ unsigned char tee = 195;
+ unsigned char l = 192;
+
+ switch (type) {
+ case BFU_ELEMENT_EMPTY:
+ c |= ATTR_FRAME;
+ set_char(term, x, y, ' ', c);
+ set_char(term, x + 1, y, ' ', c);
+ set_char(term, x + 2, y, ' ', c);
+ set_char(term, x + 3, y, ' ', c);
+ set_char(term, x + 4, y, ' ', c);
+ break;
- case BFU_ELEMENT_PIPE:
- c|=ATTR_FRAME;
- set_char(term,x,y,' ',c);
- set_char(term,x+1,y,vertical,c);
- set_char(term,x+2,y,' ',c);
- set_char(term,x+3,y,' ',c);
- set_char(term,x+4,y,' ',c);
- break;
+ case BFU_ELEMENT_PIPE:
+ c |= ATTR_FRAME;
+ set_char(term, x, y, ' ', c);
+ set_char(term, x + 1, y, vertical, c);
+ set_char(term, x + 2, y, ' ', c);
+ set_char(term, x + 3, y, ' ', c);
+ set_char(term, x + 4, y, ' ', c);
+ break;
- case BFU_ELEMENT_L:
- c|=ATTR_FRAME;
- set_char(term,x,y,' ',c);
- set_char(term,x+1,y,l,c);
- set_char(term,x+2,y,horizontal,c);
- set_char(term,x+3,y,horizontal,c);
- set_char(term,x+4,y,' ',c);
- break;
+ case BFU_ELEMENT_L:
+ c |= ATTR_FRAME;
+ set_char(term, x, y, ' ', c);
+ set_char(term, x + 1, y, l, c);
+ set_char(term, x + 2, y, horizontal, c);
+ set_char(term, x + 3, y, horizontal, c);
+ set_char(term, x + 4, y, ' ', c);
+ break;
- case BFU_ELEMENT_TEE:
- c|=ATTR_FRAME;
- set_char(term,x,y,' ',c);
- set_char(term,x+1,y,tee,c);
- set_char(term,x+2,y,horizontal,c);
- set_char(term,x+3,y,horizontal,c);
- set_char(term,x+4,y,' ',c);
- break;
+ case BFU_ELEMENT_TEE:
+ c |= ATTR_FRAME;
+ set_char(term, x, y, ' ', c);
+ set_char(term, x + 1, y, tee, c);
+ set_char(term, x + 2, y, horizontal, c);
+ set_char(term, x + 3, y, horizontal, c);
+ set_char(term, x + 4, y, ' ', c);
+ break;
- case BFU_ELEMENT_CLOSED:
- case BFU_ELEMENT_CLOSED_DOWN:
- set_char(term,x,y,'[',c);
- set_char(term,x+1,y,'+',c);
- set_char(term,x+2,y,']',c);
- c|=ATTR_FRAME;
- set_char(term,x+3,y,horizontal,c);
- set_char(term,x+4,y,' ',c);
- break;
+ case BFU_ELEMENT_CLOSED:
+ case BFU_ELEMENT_CLOSED_DOWN:
+ set_char(term, x, y, '[', c);
+ set_char(term, x + 1, y, '+', c);
+ set_char(term, x + 2, y, ']', c);
+ c |= ATTR_FRAME;
+ set_char(term, x + 3, y, horizontal, c);
+ set_char(term, x + 4, y, ' ', c);
+ break;
- case BFU_ELEMENT_OPEN:
- case BFU_ELEMENT_OPEN_DOWN:
- set_char(term,x,y,'[',c);
- set_char(term,x+1,y,'-',c);
- set_char(term,x+2,y,']',c);
- c|=ATTR_FRAME;
- set_char(term,x+3,y,horizontal,c);
- set_char(term,x+4,y,' ',c);
- break;
+ case BFU_ELEMENT_OPEN:
+ case BFU_ELEMENT_OPEN_DOWN:
+ set_char(term, x, y, '[', c);
+ set_char(term, x + 1, y, '-', c);
+ set_char(term, x + 2, y, ']', c);
+ c |= ATTR_FRAME;
+ set_char(term, x + 3, y, horizontal, c);
+ set_char(term, x + 4, y, ' ', c);
+ break;
- default:
- internal("draw_bfu_element: unknown BFU element type %d.\n",type);
- }
- if (selected)set_char(term,x+4,y,'*',c);
- return BFU_ELEMENT_WIDTH; /* BFU element size in text mode */
+ default:
+ internal("draw_bfu_element: unknown BFU element type %d.\n",
+ type);
+ }
+ if (selected)
+ set_char(term, x + 4, y, '*', c);
+ return BFU_ELEMENT_WIDTH; /* BFU element size in text mode */
}
-
/* aux structure for parameter exchange for redrawing list window */
-struct redraw_data
-{
+struct redraw_data {
struct list_description *ld;
struct dialog_data *dlg;
int n;
};
-
static void redraw_list(struct terminal *term, void *bla);
/* returns next visible item in tree list */
/* works only with visible items (head or any item returned by this function) */
/* when list is flat returns next item */
-static struct list *next_in_tree(struct list_description *ld, struct list *item)
+static struct list *
+next_in_tree(struct list_description *ld, struct list *item)
{
int depth = item->depth;
@@ -287,18 +289,21 @@ static struct list *next_in_tree(struct list_description *ld, struct list *item)
if (!ld->type)
return list_next(item);
- if (!(item->type & 1) || (item->type & 2)) /* item or opened folder */
+ if (!(item->type & 1) || (item->type & 2)) /* item or opened folder */
return list_next(item);
/* skip content of this folder */
- do item = list_next(item); while (item->depth > depth); /* must stop on head 'cause it's depth is -1 */
+ do
+ item = list_next(item);
+ while (item->depth
+ > depth); /* must stop on head 'cause it's depth is -1 */
return item;
}
-
/* returns previous visible item in tree list */
/* works only with visible items (head or any item returned by this function) */
/* when list is flat returns previous item */
-static struct list *prev_in_tree(struct list_description *ld, struct list *item)
+static struct list *
+prev_in_tree(struct list_description *ld, struct list *item)
{
struct list *last_closed;
int depth = item->depth;
@@ -308,18 +313,20 @@ static struct list *prev_in_tree(struct list_description *ld, struct list *item)
return list_prev(item);
if (item == ld->list)
- depth=0;
+ depth = 0;
- /* items with same or lower depth must be visible, because current item is visible */
+ /* items with same or lower depth must be visible, because current item
+ * is visible */
if (list_prev(item)->depth <= item->depth)
return list_prev(item);
/* find item followed with opened fotr's only */
- /* searched item is last closed folder (going up from item) or item->prev */
+ /* searched item is last closed folder (going up from item) or
+ * item->prev */
last_closed = list_prev(item);
item = list_prev(item);
while (1) {
- if ((item->type & 3) == 1) /* closed folder */
+ if ((item->type & 3) == 1) /* closed folder */
last_closed = item;
if (item->depth <= depth)
break;
@@ -328,7 +335,8 @@ static struct list *prev_in_tree(struct list_description *ld, struct list *item)
return last_closed;
}
-static int get_win_pos(struct list_description *ld)
+static int
+get_win_pos(struct list_description *ld)
{
struct list *l;
int count = 0;
@@ -339,36 +347,48 @@ static int get_win_pos(struct list_description *ld)
return count;
}
-
-static void unselect_in_folder(struct list_description *ld, struct list *l)
+static void
+unselect_in_folder(struct list_description *ld, struct list *l)
{
int depth;
depth = l->depth;
- for (l = list_next(l); l != ld->list && l->depth > depth; l = list_next(l))
+ for (l = list_next(l); l != ld->list && l->depth > depth;
+ l = list_next(l))
l->type &= ~4;
}
-
/* aux function for list_item_add */
-static void list_insert_behind_item(struct dialog_data *dlg, struct list *pos, struct list *item, struct list_description *ld)
+static void
+list_insert_behind_item(struct dialog_data *dlg, struct list *pos,
+ struct list *item, struct list_description *ld)
{
struct list *a;
struct redraw_data rd;
-/* BEFORE: ... <----> pos <--(possible invisible items)--> a <----> ... */
-/* AFTER: ... <----> pos <--(possible invisible items)--> item <----> a <----> ... */
+ /* BEFORE: ... <----> pos <--(possible invisible items)--> a <---->
+ * ... */
+ /* AFTER: ... <----> pos <--(possible invisible items)--> item <---->
+ * a <----> ... */
- a = next_in_tree(ld,pos);
+ a = next_in_tree(ld, pos);
add_before_pos(a, item);
- /* if list is flat a->fotr will contain nosenses, but it won't crash ;-) */
- if ((pos->type & 3) == 3 || pos->depth == -1) { item->fotr=pos; item->depth=pos->depth+1; } /* open directory or head */
- else { item->fotr = pos->fotr; item->depth = pos->depth; }
+ /* if list is flat a->fotr will contain nosenses, but it won't crash ;-)
+ */
+ if ((pos->type & 3) == 3 || pos->depth == -1) {
+ item->fotr = pos;
+ item->depth = pos->depth + 1;
+ } /* open directory or head */
+ else {
+ item->fotr = pos->fotr;
+ item->depth = pos->depth;
+ }
- ld->current_pos = next_in_tree(ld, ld->current_pos); /* ld->current_pos->next==item */
+ ld->current_pos =
+ next_in_tree(ld, ld->current_pos); /* ld->current_pos->next==item */
ld->win_pos++;
- if (ld->win_pos > ld->n_items - 1) { /* scroll down */
+ if (ld->win_pos > ld->n_items - 1) { /* scroll down */
ld->win_pos = ld->n_items - 1;
ld->win_offset = next_in_tree(ld, ld->win_offset);
}
@@ -382,18 +402,19 @@ static void list_insert_behind_item(struct dialog_data *dlg, struct list *pos, s
draw_to_window(dlg->win, redraw_list, &rd);
}
-
/* aux function for list_item_edit */
/* copies data of src to dest and calls free on the src */
/* first argument is argument passed to user function */
-static void list_copy_item(struct dialog_data *dlg, struct list *dest, struct list *src, struct list_description *ld)
+static void
+list_copy_item(struct dialog_data *dlg, struct list *dest, struct list *src,
+ struct list_description *ld)
{
struct redraw_data rd;
ld->copy_item(src, dest);
ld->delete_item(src);
- ld->modified = 1; /* called after an successful edit */
+ ld->modified = 1; /* called after an successful edit */
rd.ld = ld;
rd.dlg = dlg;
rd.n = 0;
@@ -401,30 +422,34 @@ static void list_copy_item(struct dialog_data *dlg, struct list *dest, struct li
draw_to_window(dlg->win, redraw_list, &rd);
}
-
/* creates new item (calling new_item function) and calls edit_item function */
-static int list_item_add(struct dialog_data *dlg, struct dialog_item_data *useless)
+static int
+list_item_add(struct dialog_data *dlg, struct dialog_item_data *useless)
{
- struct list_description *ld = (struct list_description *)dlg->dlg->udata2;
+ struct list_description *ld =
+ (struct list_description *)dlg->dlg->udata2;
struct list *item = ld->current_pos;
struct list *new_item;
- if (!(new_item = ld->new_item(ld->default_value ? ld->default_value((struct session *)dlg->dlg->udata, 0) : NULL)))
+ if (!(new_item = ld->new_item(ld->default_value ? ld->default_value(
+ (struct session *)dlg->dlg->udata, 0)
+ : NULL)))
return 1;
new_item->list_entry.prev = NULL;
new_item->list_entry.next = NULL;
new_item->type = 0;
new_item->depth = 0;
- ld->edit_item(dlg,new_item, list_insert_behind_item, item, TITLE_ADD);
+ ld->edit_item(dlg, new_item, list_insert_behind_item, item, TITLE_ADD);
return 0;
}
-
/* like list_item_add but creates folder */
-static int list_folder_add(struct dialog_data *dlg, struct dialog_item_data *useless)
+static int
+list_folder_add(struct dialog_data *dlg, struct dialog_item_data *useless)
{
- struct list_description *ld = (struct list_description *)dlg->dlg->udata2;
+ struct list_description *ld =
+ (struct list_description *)dlg->dlg->udata2;
struct list *item = ld->current_pos;
struct list *new_item;
@@ -439,15 +464,18 @@ static int list_folder_add(struct dialog_data *dlg, struct dialog_item_data *use
return 0;
}
-
-static int list_item_edit(struct dialog_data *dlg,struct dialog_item_data *useless)
+static int
+list_item_edit(struct dialog_data *dlg, struct dialog_item_data *useless)
{
- struct list_description *ld = (struct list_description *)dlg->dlg->udata2;
+ struct list_description *ld =
+ (struct list_description *)dlg->dlg->udata2;
struct list *item = ld->current_pos;
struct list *new_item;
- if (item == ld->list) return 0; /* head */
- if (!(new_item = ld->new_item(NULL))) return 1;
+ if (item == ld->list)
+ return 0; /* head */
+ if (!(new_item = ld->new_item(NULL)))
+ return 1;
new_item->list_entry.prev = NULL;
new_item->list_entry.next = NULL;
@@ -457,39 +485,52 @@ static int list_item_edit(struct dialog_data *dlg,struct dialog_item_data *usele
return 0;
}
-
-static inline int is_parent(struct list_description *ld, struct list *item, struct list *parent)
+static inline int
+is_parent(struct list_description *ld, struct list *item, struct list *parent)
{
struct list *l;
if (ld->type)
- for (l=item;l->depth>=0;l=l->fotr)
- if (l==parent) return 1;
+ for (l = item; l->depth >= 0; l = l->fotr)
+ if (l == parent)
+ return 1;
return 0;
}
-static int list_item_move(struct dialog_data *dlg, struct dialog_item_data *useless)
+static int
+list_item_move(struct dialog_data *dlg, struct dialog_item_data *useless)
{
- struct list_description *ld = (struct list_description *)dlg->dlg->udata2;
+ struct list_description *ld =
+ (struct list_description *)dlg->dlg->udata2;
struct list *i;
struct list *behind = ld->current_pos;
struct redraw_data rd;
int window_moved = 0;
int count = 0;
- if (ld->current_pos->type & 4) { /* odznacime current_pos, kdyby nahodou byla oznacena */
+ if (ld->current_pos->type
+ & 4) { /* odznacime current_pos, kdyby nahodou byla oznacena */
count++;
ld->current_pos->type &= ~4;
}
- for (i = list_next(ld->list); i != ld->list; ) {
+ for (i = list_next(ld->list); i != ld->list;) {
struct list *next = next_in_tree(ld, i);
struct list *prev = list_prev(i);
- struct list *behind_next = next_in_tree(ld, behind); /* to se musi pocitat pokazdy, protoze by se nam mohlo stat, ze to je taky oznaceny */
- struct list *item_last = list_prev(next); /* last item of moved block */
+ struct list *behind_next = next_in_tree(
+ ld, behind); /* to se musi pocitat pokazdy, protoze by se
+ nam mohlo stat, ze to je taky oznaceny */
+ struct list *item_last =
+ list_prev(next); /* last item of moved block */
- if (!(i->type & 4)) { i = next; continue; }
- if (is_parent(ld, ld->current_pos, i)) { /* we're moving directory into itself - let's behave like item was not selected */
+ if (!(i->type & 4)) {
+ i = next;
+ continue;
+ }
+ if (is_parent(
+ ld, ld->current_pos,
+ i)) { /* we're moving directory into itself - let's
+ behave like item was not selected */
i->type &= ~4;
i = next;
count++;
@@ -506,7 +547,8 @@ static int list_item_move(struct dialog_data *dlg, struct dialog_item_data *usel
if (i == ld->win_offset) {
window_moved = 1;
- if (next != ld->list) ld->win_offset = next;
+ if (next != ld->list)
+ ld->win_offset = next;
}
/* upravime fotrisko a hloubku */
@@ -514,7 +556,8 @@ static int list_item_move(struct dialog_data *dlg, struct dialog_item_data *usel
int a = i->depth;
struct list *l = i;
- if ((behind->type & 3) == 3 || behind == ld->list) { /* open folder or head */
+ if ((behind->type & 3) == 3
+ || behind == ld->list) { /* open folder or head */
i->fotr = behind;
i->depth = behind->depth + 1;
} else {
@@ -530,7 +573,9 @@ static int list_item_move(struct dialog_data *dlg, struct dialog_item_data *usel
}
}
- if (behind_next == i) goto predratovano; /* to uz je vsechno, akorat menime hloubku */
+ if (behind_next == i)
+ goto predratovano; /* to uz je vsechno, akorat menime
+ hloubku */
/* predratujeme ukazatele kolem bloku na stare pozici */
prev->list_entry.next = &next->list_entry;
@@ -560,15 +605,15 @@ predratovano:
ld->win_pos = get_win_pos(ld);
if (!count) {
- msg_box(
- dlg->win->term, /* terminal */
- NULL, /* blocks to free */
- TEXT_(T_MOVE), /* title */
- AL_CENTER, /* alignment */
- TEXT_(T_NO_ITEMS_SELECTED),MSG_BOX_END, /* text */
- NULL, /* data */
- 1, /* # of buttons */
- TEXT_(T_CANCEL), msg_box_null, B_ESC|B_ENTER /* button1 */
+ msg_box(dlg->win->term, /* terminal */
+ NULL, /* blocks to free */
+ TEXT_(T_MOVE), /* title */
+ AL_CENTER, /* alignment */
+ TEXT_(T_NO_ITEMS_SELECTED), MSG_BOX_END, /* text */
+ NULL, /* data */
+ 1, /* # of buttons */
+ TEXT_(T_CANCEL), msg_box_null,
+ B_ESC | B_ENTER /* button1 */
);
} else {
ld->modified = 1;
@@ -580,11 +625,12 @@ predratovano:
return 0;
}
-
/* unselect all items */
-static int list_item_unselect(struct dialog_data *dlg, struct dialog_item_data *useless)
+static int
+list_item_unselect(struct dialog_data *dlg, struct dialog_item_data *useless)
{
- struct list_description *ld = (struct list_description *)dlg->dlg->udata2;
+ struct list_description *ld =
+ (struct list_description *)dlg->dlg->udata2;
struct list *item;
struct redraw_data rd;
@@ -602,40 +648,43 @@ static int list_item_unselect(struct dialog_data *dlg, struct dialog_item_data *
return 0;
}
-
/* user button function - calls button_fn with current item */
-static int list_item_button(struct dialog_data *dlg, struct dialog_item_data *useless)
+static int
+list_item_button(struct dialog_data *dlg, struct dialog_item_data *useless)
{
- struct list_description *ld = (struct list_description *)dlg->dlg->udata2;
+ struct list_description *ld =
+ (struct list_description *)dlg->dlg->udata2;
struct list *item = ld->current_pos;
struct session *ses = (struct session *)dlg->dlg->udata;
- if (!ld->button_fn) internal("Links got schizophrenia! Call "BOHNICE".\n");
+ if (!ld->button_fn)
+ internal("Links got schizophrenia! Call " BOHNICE ".\n");
- if (item == ld->list || list_empty(item->list_entry)) return 0; /* head or empty list */
+ if (item == ld->list || list_empty(item->list_entry))
+ return 0; /* head or empty list */
if (ld->type && (item->type & 1)) {
list_edit_toggle(dlg, ld);
- return 0; /* this is tree list and item is directory */
+ return 0; /* this is tree list and item is directory */
}
- ld->button_fn(ses,item);
+ ld->button_fn(ses, item);
cancel_dialog(dlg, useless);
return 0;
}
-
struct ve_skodarne_je_jeste_vetsi_narez {
struct list_description *ld;
struct dialog_data *dlg;
struct list *item;
};
-
/* when delete is confirmed adjusts current_pos and calls delete function */
-static void delete_ok(void *data)
+static void
+delete_ok(void *data)
{
- struct ve_skodarne_je_jeste_vetsi_narez *skd = (struct ve_skodarne_je_jeste_vetsi_narez *)data;
+ struct ve_skodarne_je_jeste_vetsi_narez *skd =
+ (struct ve_skodarne_je_jeste_vetsi_narez *)data;
struct list_description *ld = skd->ld;
struct list *item = skd->item;
struct dialog_data *dlg = skd->dlg;
@@ -643,10 +692,11 @@ static void delete_ok(void *data)
/* strong premise: we can't delete head of the list */
if (list_next(ld->current_pos) != ld->list) {
- if (ld->current_pos == ld->win_offset) ld->win_offset = list_next(ld->current_pos);
+ if (ld->current_pos == ld->win_offset)
+ ld->win_offset = list_next(ld->current_pos);
ld->current_pos = list_next(ld->current_pos);
- } else { /* last item */
- if (!ld->win_pos) /* only one line on the screen */
+ } else { /* last item */
+ if (!ld->win_pos) /* only one line on the screen */
ld->win_offset = prev_in_tree(ld, ld->win_offset);
else
ld->win_pos--;
@@ -663,11 +713,13 @@ static void delete_ok(void *data)
draw_to_window(dlg->win, redraw_list, &rd);
}
-
-/* when delete folder is confirmed adjusts current_pos and calls delete function */
-static void delete_folder_recursively(void *data)
+/* when delete folder is confirmed adjusts current_pos and calls delete function
+ */
+static void
+delete_folder_recursively(void *data)
{
- struct ve_skodarne_je_jeste_vetsi_narez *skd = (struct ve_skodarne_je_jeste_vetsi_narez *)data;
+ struct ve_skodarne_je_jeste_vetsi_narez *skd =
+ (struct ve_skodarne_je_jeste_vetsi_narez *)data;
struct list_description *ld = skd->ld;
struct list *item = skd->item;
struct dialog_data *dlg = skd->dlg;
@@ -675,7 +727,8 @@ static void delete_folder_recursively(void *data)
struct list *i, *j;
int depth;
- for (i = list_next(item), depth = item->depth; i != ld->list && i->depth > depth; ) {
+ for (i = list_next(item), depth = item->depth;
+ i != ld->list && i->depth > depth;) {
j = i;
i = list_next(i);
ld->delete_item(j);
@@ -683,10 +736,11 @@ static void delete_folder_recursively(void *data)
/* strong premise: we can't delete head of the list */
if (list_next(ld->current_pos) != ld->list) {
- if (ld->current_pos == ld->win_offset) ld->win_offset = list_next(ld->current_pos);
+ if (ld->current_pos == ld->win_offset)
+ ld->win_offset = list_next(ld->current_pos);
ld->current_pos = list_next(ld->current_pos);
- } else { /* last item */
- if (!ld->win_pos) /* only one line on the screen */
+ } else { /* last item */
+ if (!ld->win_pos) /* only one line on the screen */
ld->win_offset = prev_in_tree(ld, ld->win_offset);
else
ld->win_pos--;
@@ -703,86 +757,99 @@ static void delete_folder_recursively(void *data)
draw_to_window(dlg->win, redraw_list, &rd);
}
-
/* tests if directory is emty */
-static int is_empty_dir(struct list_description *ld, struct list *dir)
+static int
+is_empty_dir(struct list_description *ld, struct list *dir)
{
- if (!ld->type) return 1; /* flat list */
- if (!(dir->type & 1)) return 1; /* not a directory */
+ if (!ld->type)
+ return 1; /* flat list */
+ if (!(dir->type & 1))
+ return 1; /* not a directory */
- return list_next(dir)->depth <= dir->depth; /* head depth is -1 */
+ return list_next(dir)->depth <= dir->depth; /* head depth is -1 */
}
-
/* delete dialog */
-static int list_item_delete(struct dialog_data *dlg,struct dialog_item_data *useless)
+static int
+list_item_delete(struct dialog_data *dlg, struct dialog_item_data *useless)
{
- struct terminal *term=dlg->win->term;
- struct list_description *ld=(struct list_description*)(dlg->dlg->udata2);
- struct list *item=ld->current_pos;
+ struct terminal *term = dlg->win->term;
+ struct list_description *ld =
+ (struct list_description *)(dlg->dlg->udata2);
+ struct list *item = ld->current_pos;
unsigned char *txt;
struct ve_skodarne_je_jeste_vetsi_narez *narez;
- if (item==ld->list||list_empty(item->list_entry))return 0; /* head or empty list */
+ if (item == ld->list || list_empty(item->list_entry))
+ return 0; /* head or empty list */
narez = xmalloc(sizeof(struct ve_skodarne_je_jeste_vetsi_narez));
- narez->ld=ld;narez->item=item;narez->dlg=dlg;
+ narez->ld = ld;
+ narez->item = item;
+ narez->dlg = dlg;
- txt=ld->type_item(term, item,0);
- if (!txt)
- {
+ txt = ld->type_item(term, item, 0);
+ if (!txt) {
txt = stracpy(cast_uchar "");
}
- if ((item->type)&1) /* folder */
+ if ((item->type) & 1) /* folder */
{
- if (!is_empty_dir(ld,item))
- msg_box(
- term, /* terminal */
- getml(txt,narez,NULL), /* blocks to free */
- TEXT_(T_DELETE_FOLDER), /* title */
- AL_CENTER, /* alignment */
- TEXT_(T_FOLDER),cast_uchar " \"",txt,cast_uchar "\" ",TEXT_(T_NOT_EMPTY_SURE_DELETE),MSG_BOX_END, /* text */
- (void *)narez, /* data for ld->delete_item */
- 2, /* # of buttons */
- TEXT_(T_NO),msg_box_null,B_ESC, /* button1 */
- TEXT_(T_YES),delete_folder_recursively,B_ENTER /* button2 */
+ if (!is_empty_dir(ld, item))
+ msg_box(term, /* terminal */
+ getml(txt, narez, NULL), /* blocks to free */
+ TEXT_(T_DELETE_FOLDER), /* title */
+ AL_CENTER, /* alignment */
+ TEXT_(T_FOLDER), cast_uchar " \"", txt,
+ cast_uchar "\" ",
+ TEXT_(T_NOT_EMPTY_SURE_DELETE),
+ MSG_BOX_END, /* text */
+ (void *)narez, /* data for ld->delete_item */
+ 2, /* # of buttons */
+ TEXT_(T_NO), msg_box_null, B_ESC, /* button1 */
+ TEXT_(T_YES), delete_folder_recursively,
+ B_ENTER /* button2 */
);
else
- msg_box(
- term, /* terminal */
- getml(txt,narez,NULL), /* blocks to free */
- TEXT_(T_DELETE_FOLDER), /* title */
- AL_CENTER, /* alignment */
- TEXT_(T_SURE_DELETE),cast_uchar " ",TEXT_(T_fOLDER),cast_uchar " \"",txt,cast_uchar "\"?",MSG_BOX_END, /* null-terminated text */
- (void *)narez, /* data for ld->delete_item */
- 2, /* # of buttons */
- TEXT_(T_YES),delete_ok,B_ENTER, /* button1 */
- TEXT_(T_NO),msg_box_null,B_ESC /* button2 */
+ msg_box(term, /* terminal */
+ getml(txt, narez, NULL), /* blocks to free */
+ TEXT_(T_DELETE_FOLDER), /* title */
+ AL_CENTER, /* alignment */
+ TEXT_(T_SURE_DELETE), cast_uchar " ",
+ TEXT_(T_fOLDER), cast_uchar " \"", txt,
+ cast_uchar "\"?",
+ MSG_BOX_END, /* null-terminated text */
+ (void *)narez, /* data for ld->delete_item */
+ 2, /* # of buttons */
+ TEXT_(T_YES), delete_ok, B_ENTER, /* button1 */
+ TEXT_(T_NO), msg_box_null, B_ESC /* button2 */
);
- }
- else /* item */
- msg_box(
- term, /* terminal */
- getml(txt,narez,NULL), /* blocks to free */
- TEXT_(ld->delete_dialog_title), /* title */
- AL_CENTER, /* alignment */
- TEXT_(T_SURE_DELETE),cast_uchar " ",TEXT_(ld->item_description),cast_uchar " \"",txt,cast_uchar "\"?",MSG_BOX_END, /* null-terminated text */
- (void *)narez, /* data for ld->delete_item */
- 2, /* # of buttons */
- TEXT_(T_YES),delete_ok,B_ENTER, /* button1 */
- TEXT_(T_NO),msg_box_null,B_ESC /* button2 */
+ } else /* item */
+ msg_box(term, /* terminal */
+ getml(txt, narez, NULL), /* blocks to free */
+ TEXT_(ld->delete_dialog_title), /* title */
+ AL_CENTER, /* alignment */
+ TEXT_(T_SURE_DELETE), cast_uchar " ",
+ TEXT_(ld->item_description), cast_uchar " \"", txt,
+ cast_uchar "\"?",
+ MSG_BOX_END, /* null-terminated text */
+ (void *)narez, /* data for ld->delete_item */
+ 2, /* # of buttons */
+ TEXT_(T_YES), delete_ok, B_ENTER, /* button1 */
+ TEXT_(T_NO), msg_box_null, B_ESC /* button2 */
);
return 0;
}
-static void redraw_list_element(struct terminal *term, struct dialog_data *dlg, int y, int w, struct list_description *ld, struct list *l)
+static void
+redraw_list_element(struct terminal *term, struct dialog_data *dlg, int y,
+ int w, struct list_description *ld, struct list *l)
{
struct list *lx;
unsigned char *xp;
int xd;
unsigned char *txt;
- int x=0;
+ int x = 0;
unsigned char color = 0;
long bgcolor = 0, fgcolor = 0;
int b;
@@ -803,66 +870,82 @@ static void redraw_list_element(struct terminal *term, struct dialog_data *dlg,
element = BFU_ELEMENT_TEE;
if (list_next(l) == ld->list)
element = BFU_ELEMENT_L;
- x += draw_bfu_element(term, dlg->x + DIALOG_LB, y, color, bgcolor, fgcolor, element, l->type & 4);
+ x += draw_bfu_element(term, dlg->x + DIALOG_LB, y,
+ color, bgcolor, fgcolor, element,
+ l->type & 4);
break;
case 1:
xp = xmalloc(l->depth + 1);
memset(xp, 0, l->depth + 1);
xd = l->depth + 1;
- for (lx = list_next(l); lx != ld->list; lx = list_next(lx)) {
+ for (lx = list_next(l); lx != ld->list;
+ lx = list_next(lx)) {
if (lx->depth < xd) {
xd = lx->depth;
xp[xd] = 1;
- if (!xd) break;
+ if (!xd)
+ break;
}
}
for (b = 0; b < l->depth; b++)
- x += draw_bfu_element(term, dlg->x + DIALOG_LB+x, y, color, bgcolor, fgcolor, xp[b] ? BFU_ELEMENT_PIPE : BFU_ELEMENT_EMPTY, 0);
- if (l->depth >= 0) { /* everything except head */
+ x += draw_bfu_element(term,
+ dlg->x + DIALOG_LB + x, y,
+ color, bgcolor, fgcolor,
+ xp[b] ? BFU_ELEMENT_PIPE
+ : BFU_ELEMENT_EMPTY,
+ 0);
+ if (l->depth >= 0) { /* everything except head */
int o = xp[l->depth];
switch (l->type & 1) {
- case 0: /* item */
- element = o ? BFU_ELEMENT_TEE : BFU_ELEMENT_L;
- break;
-
- case 1: /* directory */
- if (l->type & 2) {
- element = o ? BFU_ELEMENT_OPEN_DOWN : BFU_ELEMENT_OPEN;
- } else {
- element = o ? BFU_ELEMENT_CLOSED_DOWN : BFU_ELEMENT_CLOSED;
- }
- break;
+ case 0: /* item */
+ element =
+ o ? BFU_ELEMENT_TEE : BFU_ELEMENT_L;
+ break;
- default: /* this should never happen */
- internal("=8-Q lunacy level too high! Call "BOHNICE".\n");
- element = BFU_ELEMENT_EMPTY;
+ case 1: /* directory */
+ if (l->type & 2) {
+ element =
+ o ? BFU_ELEMENT_OPEN_DOWN
+ : BFU_ELEMENT_OPEN;
+ } else {
+ element =
+ o ? BFU_ELEMENT_CLOSED_DOWN
+ : BFU_ELEMENT_CLOSED;
+ }
+ break;
+ default: /* this should never happen */
+ internal("=8-Q lunacy level too high! "
+ "Call " BOHNICE ".\n");
+ element = BFU_ELEMENT_EMPTY;
}
- x += draw_bfu_element(term, dlg->x + DIALOG_LB + x, y, color, bgcolor, fgcolor, element, l->type & 4);
+ x += draw_bfu_element(
+ term, dlg->x + DIALOG_LB + x, y, color,
+ bgcolor, fgcolor, element, l->type & 4);
}
free(xp);
break;
default:
- internal(
- "Invalid list description type.\n"
- "Somebody's probably shooting into memory.\n"
- "_______________\n"
- "`--|_____|--|___ `\\\n"
- " \" \\___\\\n");
+ internal("Invalid list description type.\n"
+ "Somebody's probably shooting into memory.\n"
+ "_______________\n"
+ "`--|_____|--|___ `\\\n"
+ " \" \\___\\\n");
}
}
- print_text(term, dlg->x + x + DIALOG_LB, y, w-x, txt, color);
+ print_text(term, dlg->x + x + DIALOG_LB, y, w - x, txt, color);
x += strlen((char *)txt);
- fill_area(term, dlg->x+DIALOG_LB+x, y, w-x, 1, ' ', 0);
- set_line_color(term, dlg->x + DIALOG_LB + x, y, w-x, color);
+ fill_area(term, dlg->x + DIALOG_LB + x, y, w - x, 1, ' ', 0);
+ set_line_color(term, dlg->x + DIALOG_LB + x, y, w - x, color);
free(txt);
}
/* redraws list */
-static void redraw_list(struct terminal *term, void *bla)
+static void
+redraw_list(struct terminal *term, void *bla)
{
- struct redraw_data* rd = (struct redraw_data *)bla;
+ struct redraw_data *rd = (struct redraw_data *)bla;
struct list_description *ld = rd->ld;
struct dialog_data *dlg = rd->dlg;
int y, a;
@@ -870,20 +953,22 @@ static void redraw_list(struct terminal *term, void *bla)
int w = dlg->xw - 2 * DIALOG_LB;
y = dlg->y + DIALOG_TB;
- for (a = 0, l = ld->win_offset; a < ld->n_items; ) {
+ for (a = 0, l = ld->win_offset; a < ld->n_items;) {
redraw_list_element(term, dlg, y, w, ld, l);
l = next_in_tree(ld, l);
a++;
y++;
- if (l == ld->list) break;
+ if (l == ld->list)
+ break;
}
- fill_area(term, dlg->x + DIALOG_LB, y, w, ld->n_items-a, ' ', COLOR_MENU_TEXT);
+ fill_area(term, dlg->x + DIALOG_LB, y, w, ld->n_items - a, ' ',
+ COLOR_MENU_TEXT);
}
-
/* moves cursor from old position to a new one */
/* direction: -1=old is previous, +1=old is next */
-static void redraw_list_line(struct terminal *term, void *bla)
+static void
+redraw_list_line(struct terminal *term, void *bla)
{
struct redraw_data *rd = (struct redraw_data *)bla;
struct list_description *ld = rd->ld;
@@ -899,70 +984,81 @@ static void redraw_list_line(struct terminal *term, void *bla)
}
y += direction;
switch (direction) {
- case 0:
- l = NULL;
- break;
- case 1:
- l = next_in_tree(ld, ld->current_pos);
- break;
- case -1:
- l = prev_in_tree(ld, ld->current_pos);
- break;
- default:
- internal("redraw_list_line: invalid direction %d", direction);
- l = NULL;
- break;
+ case 0:
+ l = NULL;
+ break;
+ case 1:
+ l = next_in_tree(ld, ld->current_pos);
+ break;
+ case -1:
+ l = prev_in_tree(ld, ld->current_pos);
+ break;
+ default:
+ internal("redraw_list_line: invalid direction %d", direction);
+ l = NULL;
+ break;
}
- if (l) redraw_list_element(term, dlg, y, w, ld, l);
+ if (l)
+ redraw_list_element(term, dlg, y, w, ld, l);
}
-
/* like redraw_list, but scrolls window, prints new line to top/bottom */
/* in text mode calls redraw list */
/* direction: -1=up, 1=down */
-static void scroll_list(struct terminal *term, void *bla)
+static void
+scroll_list(struct terminal *term, void *bla)
{
redraw_list(term, bla);
}
-
-static void list_find_next(struct redraw_data *rd, int direction)
+static void
+list_find_next(struct redraw_data *rd, int direction)
{
- struct list_description *ld=rd->ld;
- struct dialog_data *dlg=rd->dlg;
- struct session *ses=(struct session *)(dlg->dlg->udata);
- struct list* item;
+ struct list_description *ld = rd->ld;
+ struct dialog_data *dlg = rd->dlg;
+ struct session *ses = (struct session *)(dlg->dlg->udata);
+ struct list *item;
- if (!ld->search_word) {msg_box(ses->term, NULL, TEXT_(T_SEARCH), AL_CENTER, TEXT_(T_NO_PREVIOUS_SEARCH), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC); return;}
+ if (!ld->search_word) {
+ msg_box(ses->term, NULL, TEXT_(T_SEARCH), AL_CENTER,
+ TEXT_(T_NO_PREVIOUS_SEARCH), MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ return;
+ }
- if ((item=ld->find_item(ld->current_pos,ld->search_word,direction)))
- {
+ if ((item =
+ ld->find_item(ld->current_pos, ld->search_word, direction))) {
struct list *l;
- ld->current_pos=item;
- ld->win_offset=item;
- ld->win_pos=0;
+ ld->current_pos = item;
+ ld->win_offset = item;
+ ld->win_pos = 0;
if (ld->type)
- for (l=item;l->depth>=0;l=l->fotr)
- if (l!=item) l->type|=2;
+ for (l = item; l->depth >= 0; l = l->fotr)
+ if (l != item)
+ l->type |= 2;
- draw_to_window(dlg->win,redraw_list,rd);
+ draw_to_window(dlg->win, redraw_list, rd);
if (!ses->term->spec->block_cursor)
set_cursor(ses->term, dlg->x + DIALOG_LB,
- dlg->y + DIALOG_TB + ld->win_pos,
- dlg->x + DIALOG_LB,
- dlg->y + DIALOG_TB + ld->win_pos);
- }
- else
- msg_box(ses->term, NULL, TEXT_(T_SEARCH), AL_CENTER, TEXT_(T_SEARCH_STRING_NOT_FOUND), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ dlg->y + DIALOG_TB + ld->win_pos,
+ dlg->x + DIALOG_LB,
+ dlg->y + DIALOG_TB + ld->win_pos);
+ } else
+ msg_box(ses->term, NULL, TEXT_(T_SEARCH), AL_CENTER,
+ TEXT_(T_SEARCH_STRING_NOT_FOUND), MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
}
-static void list_search_for_back(void *rd_, unsigned char *str)
+static void
+list_search_for_back(void *rd_, unsigned char *str)
{
struct redraw_data *rd = (struct redraw_data *)rd_;
struct list_description *ld = rd->ld;
- if (!*str) return;
- if (!ld->open) return;
+ if (!*str)
+ return;
+ if (!ld->open)
+ return;
free(ld->search_word);
ld->search_word = to_utf8_upcase(str, term_charset(rd->dlg->win->term));
@@ -971,13 +1067,16 @@ static void list_search_for_back(void *rd_, unsigned char *str)
list_find_next(rd, ld->search_direction);
}
-static void list_search_for(void *rd_, unsigned char *str)
+static void
+list_search_for(void *rd_, unsigned char *str)
{
struct redraw_data *rd = (struct redraw_data *)rd_;
struct list_description *ld = rd->ld;
- if (!*str) return;
- if (!ld->open) return;
+ if (!*str)
+ return;
+ if (!ld->open)
+ return;
free(ld->search_word);
ld->search_word = to_utf8_upcase(str, term_charset(rd->dlg->win->term));
@@ -986,463 +1085,572 @@ static void list_search_for(void *rd_, unsigned char *str)
list_find_next(rd, ld->search_direction);
}
-static void list_edit_toggle(struct dialog_data *dlg, struct list_description *ld)
+static void
+list_edit_toggle(struct dialog_data *dlg, struct list_description *ld)
{
static struct redraw_data rd;
- ld->current_pos->type^=2;
- if (!(ld->current_pos->type&2))unselect_in_folder(ld, ld->current_pos);
- rd.ld=ld;
- rd.dlg=dlg;
- rd.n=0;
- draw_to_window(dlg->win,redraw_list,&rd);
- draw_to_window(dlg->win,redraw_list_line,&rd); /* set cursor */
+ ld->current_pos->type ^= 2;
+ if (!(ld->current_pos->type & 2))
+ unselect_in_folder(ld, ld->current_pos);
+ rd.ld = ld;
+ rd.dlg = dlg;
+ rd.n = 0;
+ draw_to_window(dlg->win, redraw_list, &rd);
+ draw_to_window(dlg->win, redraw_list_line, &rd); /* set cursor */
}
-static int list_event_handler(struct dialog_data *dlg, struct links_event *ev)
+static int
+list_event_handler(struct dialog_data *dlg, struct links_event *ev)
{
- struct list_description *ld=(struct list_description*)(dlg->dlg->udata2);
+ struct list_description *ld =
+ (struct list_description *)(dlg->dlg->udata2);
static struct redraw_data rd;
- struct session *ses=(struct session *)(dlg->dlg->udata);
+ struct session *ses = (struct session *)(dlg->dlg->udata);
- rd.ld=ld;
- rd.dlg=dlg;
- rd.n=0;
+ rd.ld = ld;
+ rd.dlg = dlg;
+ rd.n = 0;
- switch ((int)ev->ev)
- {
- case EV_KBD:
- if (ev->y & KBD_PASTING) break;
- if (ld->type==1) /* tree list */
+ switch ((int)ev->ev) {
+ case EV_KBD:
+ if (ev->y & KBD_PASTING)
+ break;
+ if (ld->type == 1) /* tree list */
{
- if (ev->x==' ') /* toggle folder */
+ if (ev->x == ' ') /* toggle folder */
{
- if (!((ld->current_pos->type)&1))return EVENT_PROCESSED; /* item */
+ if (!((ld->current_pos->type) & 1))
+ return EVENT_PROCESSED; /* item */
list_edit_toggle(dlg, ld);
return EVENT_PROCESSED;
}
- if (ev->x=='+'||ev->x=='=') /* open folder */
+ if (ev->x == '+' || ev->x == '=') /* open folder */
{
- if (!((ld->current_pos->type)&1))return EVENT_PROCESSED; /* item */
- if ((ld->current_pos->type)&2)return EVENT_PROCESSED; /* already open */
+ if (!((ld->current_pos->type) & 1))
+ return EVENT_PROCESSED; /* item */
+ if ((ld->current_pos->type) & 2)
+ return EVENT_PROCESSED; /* already open
+ */
list_edit_toggle(dlg, ld);
return EVENT_PROCESSED;
}
- if (ev->x=='-') /* close folder */
+ if (ev->x == '-') /* close folder */
{
- if (!((ld->current_pos->type)&1))return EVENT_PROCESSED; /* item */
- if (!((ld->current_pos->type)&2))return EVENT_PROCESSED; /* already closed */
+ if (!((ld->current_pos->type) & 1))
+ return EVENT_PROCESSED; /* item */
+ if (!((ld->current_pos->type) & 2))
+ return EVENT_PROCESSED; /* already
+ closed */
list_edit_toggle(dlg, ld);
return EVENT_PROCESSED;
}
}
- if (ev->x == '/' || (ev->x == KBD_FIND && !(ev->y & (KBD_SHIFT | KBD_CTRL | KBD_ALT)))) /* search forward */
+ if (ev->x == '/'
+ || (ev->x == KBD_FIND
+ && !(ev->y
+ & (KBD_SHIFT | KBD_CTRL
+ | KBD_ALT)))) /* search forward */
{
struct redraw_data *r;
r = xmalloc(sizeof(struct redraw_data));
- r->ld=ld;
- r->dlg=dlg;
-
- input_field(ses->term, getml(r,NULL), TEXT_(T_SEARCH), TEXT_(T_SEARCH_FOR_TEXT), r, ld->search_history, MAX_INPUT_URL_LEN, cast_uchar "", 0, 0, NULL, 2, TEXT_(T_OK), list_search_for, TEXT_(T_CANCEL), input_field_null);
+ r->ld = ld;
+ r->dlg = dlg;
+
+ input_field(ses->term, getml(r, NULL), TEXT_(T_SEARCH),
+ TEXT_(T_SEARCH_FOR_TEXT), r,
+ ld->search_history, MAX_INPUT_URL_LEN,
+ cast_uchar "", 0, 0, NULL, 2, TEXT_(T_OK),
+ list_search_for, TEXT_(T_CANCEL),
+ input_field_null);
return EVENT_PROCESSED;
}
- if (ev->x == '?' || (ev->x == KBD_FIND && ev->y & (KBD_SHIFT | KBD_CTRL | KBD_ALT))) /* search back */
+ if (ev->x == '?'
+ || (ev->x == KBD_FIND
+ && ev->y
+ & (KBD_SHIFT | KBD_CTRL
+ | KBD_ALT))) /* search back */
{
struct redraw_data *r;
r = xmalloc(sizeof(struct redraw_data));
- r->ld=ld;
- r->dlg=dlg;
-
- input_field(ses->term, getml(r,NULL), TEXT_(T_SEARCH_BACK), TEXT_(T_SEARCH_FOR_TEXT), r, ld->search_history, MAX_INPUT_URL_LEN, cast_uchar "", 0, 0, NULL, 2, TEXT_(T_OK), list_search_for_back, TEXT_(T_CANCEL), input_field_null);
+ r->ld = ld;
+ r->dlg = dlg;
+
+ input_field(
+ ses->term, getml(r, NULL), TEXT_(T_SEARCH_BACK),
+ TEXT_(T_SEARCH_FOR_TEXT), r, ld->search_history,
+ MAX_INPUT_URL_LEN, cast_uchar "", 0, 0, NULL, 2,
+ TEXT_(T_OK), list_search_for_back, TEXT_(T_CANCEL),
+ input_field_null);
return EVENT_PROCESSED;
}
- if ((ev->x == 'n' && !(ev->y & KBD_ALT)) || ev->x == KBD_REDO) /* find next */
+ if ((ev->x == 'n' && !(ev->y & KBD_ALT))
+ || ev->x == KBD_REDO) /* find next */
{
list_find_next(&rd, ld->search_direction);
return EVENT_PROCESSED;
}
- if ((ev->x == 'N' && !(ev->y & KBD_ALT)) || ev->x == KBD_UNDO) /* find prev */
+ if ((ev->x == 'N' && !(ev->y & KBD_ALT))
+ || ev->x == KBD_UNDO) /* find prev */
{
- list_find_next(&rd, - ld->search_direction);
+ list_find_next(&rd, -ld->search_direction);
return EVENT_PROCESSED;
}
- if (ev->x == KBD_UP)
- {
- if (ld->current_pos==ld->list) goto kbd_up_redraw_exit; /* already on the top */
- ld->current_pos=prev_in_tree(ld,ld->current_pos);
+ if (ev->x == KBD_UP) {
+ if (ld->current_pos == ld->list)
+ goto kbd_up_redraw_exit; /* already on the top
+ */
+ ld->current_pos = prev_in_tree(ld, ld->current_pos);
ld->win_pos--;
- rd.n=1;
- if (ld->win_pos<0) /* scroll up */
+ rd.n = 1;
+ if (ld->win_pos < 0) /* scroll up */
{
- ld->win_pos=0;
- ld->win_offset=prev_in_tree(ld,ld->win_offset);
- draw_to_window(dlg->win,scroll_list,&rd);
+ ld->win_pos = 0;
+ ld->win_offset =
+ prev_in_tree(ld, ld->win_offset);
+ draw_to_window(dlg->win, scroll_list, &rd);
}
- kbd_up_redraw_exit:
- draw_to_window(dlg->win,redraw_list_line,&rd);
+kbd_up_redraw_exit:
+ draw_to_window(dlg->win, redraw_list_line, &rd);
return EVENT_PROCESSED;
}
- if (ev->x == 'i' || ev->x == '*' || ev->x == '8' || ev->x == KBD_INS || ev->x == KBD_SELECT)
- {
- if (ld->current_pos!=ld->list)ld->current_pos->type^=4;
- rd.n=-1;
- if (next_in_tree(ld,ld->current_pos)==ld->list) /* already at the bottom */
+ if (ev->x == 'i' || ev->x == '*' || ev->x == '8'
+ || ev->x == KBD_INS || ev->x == KBD_SELECT) {
+ if (ld->current_pos != ld->list)
+ ld->current_pos->type ^= 4;
+ rd.n = -1;
+ if (next_in_tree(ld, ld->current_pos)
+ == ld->list) /* already at the bottom */
{
- draw_to_window(dlg->win,redraw_list_line,&rd);
+ draw_to_window(dlg->win, redraw_list_line, &rd);
return EVENT_PROCESSED;
}
- ld->current_pos=next_in_tree(ld,ld->current_pos);
+ ld->current_pos = next_in_tree(ld, ld->current_pos);
ld->win_pos++;
- if (ld->win_pos>ld->n_items-1) /* scroll down */
+ if (ld->win_pos > ld->n_items - 1) /* scroll down */
{
- ld->win_pos=ld->n_items-1;
- ld->win_offset=next_in_tree(ld,ld->win_offset);
- draw_to_window(dlg->win,scroll_list,&rd);
+ ld->win_pos = ld->n_items - 1;
+ ld->win_offset =
+ next_in_tree(ld, ld->win_offset);
+ draw_to_window(dlg->win, scroll_list, &rd);
}
- draw_to_window(dlg->win,redraw_list_line,&rd);
+ draw_to_window(dlg->win, redraw_list_line, &rd);
return EVENT_PROCESSED;
}
- if (ev->x == KBD_DOWN)
- {
- if (next_in_tree(ld,ld->current_pos)==ld->list) goto kbd_down_redraw_exit; /* already at the bottom */
- ld->current_pos=next_in_tree(ld,ld->current_pos);
+ if (ev->x == KBD_DOWN) {
+ if (next_in_tree(ld, ld->current_pos) == ld->list)
+ goto kbd_down_redraw_exit; /* already at the
+ bottom */
+ ld->current_pos = next_in_tree(ld, ld->current_pos);
ld->win_pos++;
- rd.n=-1;
- if (ld->win_pos>ld->n_items-1) /* scroll down */
+ rd.n = -1;
+ if (ld->win_pos > ld->n_items - 1) /* scroll down */
{
- ld->win_pos=ld->n_items-1;
- ld->win_offset=next_in_tree(ld,ld->win_offset);
- draw_to_window(dlg->win,scroll_list,&rd);
+ ld->win_pos = ld->n_items - 1;
+ ld->win_offset =
+ next_in_tree(ld, ld->win_offset);
+ draw_to_window(dlg->win, scroll_list, &rd);
}
- kbd_down_redraw_exit:
- draw_to_window(dlg->win,redraw_list_line,&rd);
+kbd_down_redraw_exit:
+ draw_to_window(dlg->win, redraw_list_line, &rd);
return EVENT_PROCESSED;
}
- if (ev->x == KBD_HOME || (upcase(ev->x) == 'A' && ev->y & KBD_CTRL))
- {
- if (ld->current_pos==ld->list) goto kbd_home_redraw_exit; /* already on the top */
- ld->win_offset=ld->list;
- ld->current_pos=ld->win_offset;
- ld->win_pos=0;
- rd.n=0;
- draw_to_window(dlg->win,redraw_list,&rd);
- kbd_home_redraw_exit:
- draw_to_window(dlg->win,redraw_list_line,&rd); /* set cursor */
+ if (ev->x == KBD_HOME
+ || (upcase(ev->x) == 'A' && ev->y & KBD_CTRL)) {
+ if (ld->current_pos == ld->list)
+ goto kbd_home_redraw_exit; /* already on the top
+ */
+ ld->win_offset = ld->list;
+ ld->current_pos = ld->win_offset;
+ ld->win_pos = 0;
+ rd.n = 0;
+ draw_to_window(dlg->win, redraw_list, &rd);
+kbd_home_redraw_exit:
+ draw_to_window(dlg->win, redraw_list_line,
+ &rd); /* set cursor */
return EVENT_PROCESSED;
}
- if (ev->x == KBD_END || (upcase(ev->x) == 'E' && ev->y & KBD_CTRL))
- {
+ if (ev->x == KBD_END
+ || (upcase(ev->x) == 'E' && ev->y & KBD_CTRL)) {
int a;
- if (ld->current_pos==prev_in_tree(ld,ld->list)) goto kbd_end_redraw_exit; /* already on the top */
- ld->win_offset=prev_in_tree(ld,ld->list);
- for (a=1;a<ld->n_items&&ld->win_offset!=ld->list;a++)
- ld->win_offset=prev_in_tree(ld,ld->win_offset);
- ld->current_pos=prev_in_tree(ld,ld->list);
- ld->win_pos=a-1;
- rd.n=0;
- draw_to_window(dlg->win,redraw_list,&rd);
- kbd_end_redraw_exit:
- draw_to_window(dlg->win,redraw_list_line,&rd); /* set cursor */
+ if (ld->current_pos == prev_in_tree(ld, ld->list))
+ goto kbd_end_redraw_exit; /* already on the top
+ */
+ ld->win_offset = prev_in_tree(ld, ld->list);
+ for (a = 1;
+ a < ld->n_items && ld->win_offset != ld->list; a++)
+ ld->win_offset =
+ prev_in_tree(ld, ld->win_offset);
+ ld->current_pos = prev_in_tree(ld, ld->list);
+ ld->win_pos = a - 1;
+ rd.n = 0;
+ draw_to_window(dlg->win, redraw_list, &rd);
+kbd_end_redraw_exit:
+ draw_to_window(dlg->win, redraw_list_line,
+ &rd); /* set cursor */
return EVENT_PROCESSED;
}
- if (ev->x == KBD_PAGE_UP || (upcase(ev->x) == 'B' && ev->y & KBD_CTRL))
- {
+ if (ev->x == KBD_PAGE_UP
+ || (upcase(ev->x) == 'B' && ev->y & KBD_CTRL)) {
int a;
- if (ld->current_pos==ld->list) goto kbd_page_up_redraw_exit; /* already on the top */
- for (a=0;a<ld->n_items&&ld->win_offset!=ld->list;a++)
- {
- ld->win_offset=prev_in_tree(ld,ld->win_offset);
- ld->current_pos=prev_in_tree(ld,ld->current_pos);
+ if (ld->current_pos == ld->list)
+ goto kbd_page_up_redraw_exit; /* already on the
+ top */
+ for (a = 0;
+ a < ld->n_items && ld->win_offset != ld->list;
+ a++) {
+ ld->win_offset =
+ prev_in_tree(ld, ld->win_offset);
+ ld->current_pos =
+ prev_in_tree(ld, ld->current_pos);
+ }
+ if (a < ld->n_items) {
+ ld->current_pos = ld->win_offset;
+ ld->win_pos = 0;
}
- if (a<ld->n_items){ld->current_pos=ld->win_offset;ld->win_pos=0;}
- rd.n=0;
- draw_to_window(dlg->win,redraw_list,&rd);
- kbd_page_up_redraw_exit:
- draw_to_window(dlg->win,redraw_list_line,&rd); /* set cursor */
+ rd.n = 0;
+ draw_to_window(dlg->win, redraw_list, &rd);
+kbd_page_up_redraw_exit:
+ draw_to_window(dlg->win, redraw_list_line,
+ &rd); /* set cursor */
return EVENT_PROCESSED;
}
- if (ev->x == KBD_PAGE_DOWN || (upcase(ev->x) == 'F' && ev->y & KBD_CTRL))
- {
+ if (ev->x == KBD_PAGE_DOWN
+ || (upcase(ev->x) == 'F' && ev->y & KBD_CTRL)) {
int a;
- struct list*p=ld->win_offset;
-
- if (ld->current_pos==prev_in_tree(ld,ld->list)) goto kbd_page_down_redraw_exit; /* already on the bottom */
- for (a=0;a<ld->n_items&&ld->list!=next_in_tree(ld,p);a++)
- p=next_in_tree(ld,p);
- if (a<ld->n_items) /* already last screen */
+ struct list *p = ld->win_offset;
+
+ if (ld->current_pos == prev_in_tree(ld, ld->list))
+ goto kbd_page_down_redraw_exit; /* already on
+ the bottom */
+ for (a = 0;
+ a < ld->n_items && ld->list != next_in_tree(ld, p);
+ a++)
+ p = next_in_tree(ld, p);
+ if (a < ld->n_items) /* already last screen */
{
- ld->current_pos=p;
- ld->win_pos=a;
- rd.n=0;
- draw_to_window(dlg->win,redraw_list,&rd);
- draw_to_window(dlg->win,redraw_list_line,&rd); /* set cursor */
+ ld->current_pos = p;
+ ld->win_pos = a;
+ rd.n = 0;
+ draw_to_window(dlg->win, redraw_list, &rd);
+ draw_to_window(dlg->win, redraw_list_line,
+ &rd); /* set cursor */
return EVENT_PROCESSED;
}
- /* here is whole screen only - the window was full before pressing the page-down key */
- /* p is pointing behind last item of the window (behind last visible item in the window) */
- for (a=0;a<ld->n_items&&p!=ld->list;a++)
- {
- ld->win_offset=next_in_tree(ld,ld->win_offset);
- ld->current_pos=next_in_tree(ld,ld->current_pos);
- p=next_in_tree(ld,p);
+ /* here is whole screen only - the window was full
+ * before pressing the page-down key */
+ /* p is pointing behind last item of the window (behind
+ * last visible item in the window) */
+ for (a = 0; a < ld->n_items && p != ld->list; a++) {
+ ld->win_offset =
+ next_in_tree(ld, ld->win_offset);
+ ld->current_pos =
+ next_in_tree(ld, ld->current_pos);
+ p = next_in_tree(ld, p);
}
- if (a<ld->n_items){ld->current_pos=prev_in_tree(ld,ld->list);ld->win_pos=ld->n_items-1;}
- rd.n=0;
- draw_to_window(dlg->win,redraw_list,&rd);
- kbd_page_down_redraw_exit:
- draw_to_window(dlg->win,redraw_list_line,&rd); /* set cursor */
+ if (a < ld->n_items) {
+ ld->current_pos = prev_in_tree(ld, ld->list);
+ ld->win_pos = ld->n_items - 1;
+ }
+ rd.n = 0;
+ draw_to_window(dlg->win, redraw_list, &rd);
+kbd_page_down_redraw_exit:
+ draw_to_window(dlg->win, redraw_list_line,
+ &rd); /* set cursor */
return EVENT_PROCESSED;
}
break;
- case EV_MOUSE:
+ case EV_MOUSE:
/* toggle select item */
- if ((ev->b & BM_ACT) == B_DOWN && (ev->b & BM_BUTT) == B_RIGHT) {
- int n,a;
- struct list *l=ld->win_offset;
+ if ((ev->b & BM_ACT) == B_DOWN
+ && (ev->b & BM_BUTT) == B_RIGHT) {
+ int n, a;
+ struct list *l = ld->win_offset;
- last_mouse_y=ev->y;
+ last_mouse_y = ev->y;
- if (
- (ev->y)<(dlg->y+DIALOG_TB)||
- ev->y >= (dlg->y + DIALOG_TB + ld->n_items) ||
- (ev->x)<(dlg->x+DIALOG_LB)||
- (ev->x)>(dlg->x+dlg->xw-DIALOG_LB)
- )break; /* out of the dialog */
+ if ((ev->y) < (dlg->y + DIALOG_TB)
+ || ev->y >= (dlg->y + DIALOG_TB + ld->n_items)
+ || (ev->x) < (dlg->x + DIALOG_LB)
+ || (ev->x) > (dlg->x + dlg->xw - DIALOG_LB))
+ break; /* out of the dialog */
n = ev->y - dlg->y - DIALOG_TB;
- for (a=0;a<n;a++)
- {
+ for (a = 0; a < n; a++) {
struct list *l1;
- l1=next_in_tree(ld,l); /* current item under the mouse pointer */
- if (l1==ld->list)goto break2;
- else l=l1;
+ l1 =
+ next_in_tree(ld, l); /* current item under
+ the mouse pointer */
+ if (l1 == ld->list)
+ goto break2;
+ else
+ l = l1;
}
- l->type^=4;
- ld->current_pos=l;
- ld->win_pos=n;
- rd.n=0;
- draw_to_window(dlg->win,redraw_list,&rd);
- draw_to_window(dlg->win,redraw_list_line,&rd); /* set cursor */
+ l->type ^= 4;
+ ld->current_pos = l;
+ ld->win_pos = n;
+ rd.n = 0;
+ draw_to_window(dlg->win, redraw_list, &rd);
+ draw_to_window(dlg->win, redraw_list_line,
+ &rd); /* set cursor */
return EVENT_PROCESSED;
}
/* click on item */
- if (((ev->b & BM_ACT) == B_DOWN || (ev->b & BM_ACT) == B_DRAG) && (ev->b & BM_BUTT) == B_LEFT) {
- int n,a;
- struct list *l=ld->win_offset;
+ if (((ev->b & BM_ACT) == B_DOWN || (ev->b & BM_ACT) == B_DRAG)
+ && (ev->b & BM_BUTT) == B_LEFT) {
+ int n, a;
+ struct list *l = ld->win_offset;
- last_mouse_y=ev->y;
+ last_mouse_y = ev->y;
- if (
- (ev->y)<(dlg->y+DIALOG_TB)||
- ev->y >= (dlg->y + DIALOG_TB + ld->n_items) ||
- (ev->x)<(dlg->x+DIALOG_LB)||
- (ev->x)>(dlg->x+dlg->xw-DIALOG_LB)
- )goto skip_item_click; /* out of the dialog */
+ if ((ev->y) < (dlg->y + DIALOG_TB)
+ || ev->y >= (dlg->y + DIALOG_TB + ld->n_items)
+ || (ev->x) < (dlg->x + DIALOG_LB)
+ || (ev->x) > (dlg->x + dlg->xw - DIALOG_LB))
+ goto skip_item_click; /* out of the dialog */
n = ev->y - dlg->y - DIALOG_TB;
- for (a=0;a<n;a++)
- {
+ for (a = 0; a < n; a++) {
struct list *l1;
- l1=next_in_tree(ld,l); /* current item under the mouse pointer */
- if (l1==ld->list) {
- n=a;
+ l1 =
+ next_in_tree(ld, l); /* current item under
+ the mouse pointer */
+ if (l1 == ld->list) {
+ n = a;
break;
- }
- else l=l1;
+ } else
+ l = l1;
}
- a=ld->type?((l->depth)>=0?(l->depth)+1:0):(l->depth>=0);
+ a = ld->type ? ((l->depth) >= 0 ? (l->depth) + 1 : 0)
+ : (l->depth >= 0);
- ld->current_pos=l;
+ ld->current_pos = l;
/* clicked on directory graphical stuff */
- if ((ev->b & BM_ACT) == B_DOWN && ld->type && ev->x < (dlg->x + DIALOG_LB + a * BFU_ELEMENT_WIDTH) && (l->type & 1)) {
- l->type^=2;
- if (!(l->type&2))unselect_in_folder(ld, ld->current_pos);
+ if ((ev->b & BM_ACT) == B_DOWN && ld->type
+ && ev->x < (dlg->x + DIALOG_LB
+ + a * BFU_ELEMENT_WIDTH)
+ && (l->type & 1)) {
+ l->type ^= 2;
+ if (!(l->type & 2))
+ unselect_in_folder(ld, ld->current_pos);
}
- ld->win_pos=n;
- rd.n=0;
- draw_to_window(dlg->win,redraw_list,&rd);
- draw_to_window(dlg->win,redraw_list_line,&rd); /* set cursor */
+ ld->win_pos = n;
+ rd.n = 0;
+ draw_to_window(dlg->win, redraw_list, &rd);
+ draw_to_window(dlg->win, redraw_list_line,
+ &rd); /* set cursor */
return EVENT_PROCESSED;
}
/* scroll with the bar */
- skip_item_click:
- if ((ev->b & BM_ACT) == B_DRAG && (ev->b & BM_BUTT) == B_MIDDLE) {
- long delta = ev->y-last_mouse_y;
+skip_item_click:
+ if ((ev->b & BM_ACT) == B_DRAG
+ && (ev->b & BM_BUTT) == B_MIDDLE) {
+ long delta = ev->y - last_mouse_y;
- last_mouse_y=ev->y;
- if (delta>0) /* scroll down */
+ last_mouse_y = ev->y;
+ if (delta > 0) /* scroll down */
{
- if (next_in_tree(ld,ld->current_pos)==ld->list)return EVENT_PROCESSED; /* already at the bottom */
- ld->current_pos=next_in_tree(ld,ld->current_pos);
+ if (next_in_tree(ld, ld->current_pos)
+ == ld->list)
+ return EVENT_PROCESSED; /* already at
+ the bottom */
+ ld->current_pos =
+ next_in_tree(ld, ld->current_pos);
ld->win_pos++;
- rd.n=-1;
- if (ld->win_pos>ld->n_items-1) /* scroll down */
+ rd.n = -1;
+ if (ld->win_pos
+ > ld->n_items - 1) /* scroll down */
{
- ld->win_pos=ld->n_items-1;
- ld->win_offset=next_in_tree(ld,ld->win_offset);
- draw_to_window(dlg->win,scroll_list,&rd);
+ ld->win_pos = ld->n_items - 1;
+ ld->win_offset =
+ next_in_tree(ld, ld->win_offset);
+ draw_to_window(dlg->win, scroll_list,
+ &rd);
}
- draw_to_window(dlg->win,redraw_list_line,&rd);
+ draw_to_window(dlg->win, redraw_list_line, &rd);
}
- if (delta<0) /* scroll up */
+ if (delta < 0) /* scroll up */
{
- if (ld->current_pos==ld->list)return EVENT_PROCESSED; /* already on the top */
- ld->current_pos=prev_in_tree(ld,ld->current_pos);
+ if (ld->current_pos == ld->list)
+ return EVENT_PROCESSED; /* already on
+ the top */
+ ld->current_pos =
+ prev_in_tree(ld, ld->current_pos);
ld->win_pos--;
- rd.n=+1;
- if (ld->win_pos<0) /* scroll up */
+ rd.n = +1;
+ if (ld->win_pos < 0) /* scroll up */
{
- ld->win_pos=0;
- ld->win_offset=prev_in_tree(ld,ld->win_offset);
- draw_to_window(dlg->win,scroll_list,&rd);
+ ld->win_pos = 0;
+ ld->win_offset =
+ prev_in_tree(ld, ld->win_offset);
+ draw_to_window(dlg->win, scroll_list,
+ &rd);
}
- draw_to_window(dlg->win,redraw_list_line,&rd);
+ draw_to_window(dlg->win, redraw_list_line, &rd);
}
return EVENT_PROCESSED;
-
}
/* mouse wheel */
- if ((ev->b & BM_ACT) == B_MOVE && ((ev->b & BM_BUTT) == B_WHEELUP || (ev->b & BM_BUTT) == B_WHEELDOWN || (ev->b & BM_BUTT) == B_WHEELDOWN1 || (ev->b & BM_BUTT) == B_WHEELUP1)) {
- int button=(int)ev->b&BM_BUTT;
- last_mouse_y=ev->y;
-
- if (button==B_WHEELDOWN||button==B_WHEELDOWN1) /* scroll down */
+ if ((ev->b & BM_ACT) == B_MOVE
+ && ((ev->b & BM_BUTT) == B_WHEELUP
+ || (ev->b & BM_BUTT) == B_WHEELDOWN
+ || (ev->b & BM_BUTT) == B_WHEELDOWN1
+ || (ev->b & BM_BUTT) == B_WHEELUP1)) {
+ int button = (int)ev->b & BM_BUTT;
+ last_mouse_y = ev->y;
+
+ if (button == B_WHEELDOWN
+ || button == B_WHEELDOWN1) /* scroll down */
{
- if (next_in_tree(ld,ld->current_pos)==ld->list)return EVENT_PROCESSED; /* already at the bottom */
- ld->current_pos=next_in_tree(ld,ld->current_pos);
+ if (next_in_tree(ld, ld->current_pos)
+ == ld->list)
+ return EVENT_PROCESSED; /* already at
+ the bottom */
+ ld->current_pos =
+ next_in_tree(ld, ld->current_pos);
ld->win_pos++;
- rd.n=-1;
- if (ld->win_pos>ld->n_items-1) /* scroll down */
+ rd.n = -1;
+ if (ld->win_pos
+ > ld->n_items - 1) /* scroll down */
{
- ld->win_pos=ld->n_items-1;
- ld->win_offset=next_in_tree(ld,ld->win_offset);
- draw_to_window(dlg->win,scroll_list,&rd);
+ ld->win_pos = ld->n_items - 1;
+ ld->win_offset =
+ next_in_tree(ld, ld->win_offset);
+ draw_to_window(dlg->win, scroll_list,
+ &rd);
}
- draw_to_window(dlg->win,redraw_list_line,&rd);
+ draw_to_window(dlg->win, redraw_list_line, &rd);
}
- if (button==B_WHEELUP||button==B_WHEELUP1) /* scroll up */
+ if (button == B_WHEELUP
+ || button == B_WHEELUP1) /* scroll up */
{
- if (ld->current_pos==ld->list)return EVENT_PROCESSED; /* already on the top */
- ld->current_pos=prev_in_tree(ld,ld->current_pos);
+ if (ld->current_pos == ld->list)
+ return EVENT_PROCESSED; /* already on
+ the top */
+ ld->current_pos =
+ prev_in_tree(ld, ld->current_pos);
ld->win_pos--;
- rd.n=+1;
- if (ld->win_pos<0) /* scroll up */
+ rd.n = +1;
+ if (ld->win_pos < 0) /* scroll up */
{
- ld->win_pos=0;
- ld->win_offset=prev_in_tree(ld,ld->win_offset);
- draw_to_window(dlg->win,scroll_list,&rd);
+ ld->win_pos = 0;
+ ld->win_offset =
+ prev_in_tree(ld, ld->win_offset);
+ draw_to_window(dlg->win, scroll_list,
+ &rd);
}
- draw_to_window(dlg->win,redraw_list_line,&rd);
+ draw_to_window(dlg->win, redraw_list_line, &rd);
}
return EVENT_PROCESSED;
-
}
- break2:
+break2:
break;
- case EV_INIT:
- case EV_RESIZE:
- case EV_REDRAW:
- case EV_ABORT:
+ case EV_INIT:
+ case EV_RESIZE:
+ case EV_REDRAW:
+ case EV_ABORT:
break;
- default:
+ default:
break;
-
}
return EVENT_NOT_PROCESSED;
}
-
/* display function for the list window */
-static void create_list_window_fn(struct dialog_data *dlg)
+static void
+create_list_window_fn(struct dialog_data *dlg)
{
- struct terminal *term=dlg->win->term;
- struct list_description *ld=(struct list_description*)(dlg->dlg->udata2);
- int min=0;
- int w,rw,y;
+ struct terminal *term = dlg->win->term;
+ struct list_description *ld =
+ (struct list_description *)(dlg->dlg->udata2);
+ int min = 0;
+ int w, rw, y;
int n_items;
struct redraw_data rd;
- int a=6;
+ int a = 6;
- ld->dlg=dlg;
- if (ld->button_fn)a++; /* user button */
- if (ld->type==1)a++; /* add directory button */
+ ld->dlg = dlg;
+ if (ld->button_fn)
+ a++; /* user button */
+ if (ld->type == 1)
+ a++; /* add directory button */
y = 0;
min_buttons_width(term, dlg->items, a, &min);
w = term->x * 19 / 20 - 2 * DIALOG_LB;
- if (w<min)w=min;
- if (w>term->x-2*DIALOG_LB)w=term->x-2*DIALOG_LB;
- if (w<5)w=5;
-
- rw=0;
+ if (w < min)
+ w = min;
+ if (w > term->x - 2 * DIALOG_LB)
+ w = term->x - 2 * DIALOG_LB;
+ if (w < 5)
+ w = 5;
+
+ rw = 0;
dlg_format_buttons(dlg, NULL, dlg->items, a, 0, &y, w, &rw, AL_CENTER);
n_items = term->y - y;
n_items -= 2 * DIALOG_TB + 2;
- if (n_items < 2) n_items = 2;
+ if (n_items < 2)
+ n_items = 2;
ld->n_items = n_items;
while (ld->win_pos > ld->n_items - 1) {
- ld->current_pos=prev_in_tree(ld,ld->current_pos);
+ ld->current_pos = prev_in_tree(ld, ld->current_pos);
ld->win_pos--;
}
y += ld->n_items;
- rw=w;
- dlg->xw=rw+2*DIALOG_LB;
- dlg->yw=y+2*DIALOG_TB;
+ rw = w;
+ dlg->xw = rw + 2 * DIALOG_LB;
+ dlg->yw = y + 2 * DIALOG_TB;
center_dlg(dlg);
draw_dlg(dlg);
- rd.ld=ld;
- rd.dlg=dlg;
- rd.n=0;
+ rd.ld = ld;
+ rd.dlg = dlg;
+ rd.n = 0;
- draw_to_window(dlg->win,redraw_list,&rd);
+ draw_to_window(dlg->win, redraw_list, &rd);
y = dlg->y + DIALOG_TB + ld->n_items + 1;
- dlg_format_buttons(dlg, term, dlg->items, a, dlg->x+DIALOG_LB, &y, w, &rw, AL_CENTER);
+ dlg_format_buttons(dlg, term, dlg->items, a, dlg->x + DIALOG_LB, &y, w,
+ &rw, AL_CENTER);
}
-
-static void close_list_window(struct dialog_data *dlg)
+static void
+close_list_window(struct dialog_data *dlg)
{
- struct dialog *d=dlg->dlg;
- struct list_description *ld=(struct list_description*)(d->udata2);
+ struct dialog *d = dlg->dlg;
+ struct list_description *ld = (struct list_description *)(d->udata2);
- ld->open=0;
- ld->dlg=NULL;
+ ld->open = 0;
+ ld->dlg = NULL;
free(ld->search_word);
- ld->search_word=NULL;
- if (ld->save) ld->save(d->udata);
+ ld->search_word = NULL;
+ if (ld->save)
+ ld->save(d->udata);
}
-int test_list_window_in_use(struct list_description *ld, struct terminal *term)
+int
+test_list_window_in_use(struct list_description *ld, struct terminal *term)
{
if (ld->open) {
if (term)
- msg_box(
- term,
- NULL,
- TEXT_(T_INFO),
- AL_CENTER,
- TEXT_(ld->already_in_use),MSG_BOX_END,
- NULL,
- 1,
- TEXT_(T_CANCEL),msg_box_null,B_ENTER|B_ESC
- );
+ msg_box(term, NULL, TEXT_(T_INFO), AL_CENTER,
+ TEXT_(ld->already_in_use), MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
return 1;
}
return 0;
@@ -1450,12 +1658,9 @@ int test_list_window_in_use(struct list_description *ld, struct terminal *term)
/* dialog->udata2 ... list_description */
/* dialog->udata ... session */
-int create_list_window(
- struct list_description *ld,
- struct list *list,
- struct terminal *term,
- struct session *ses
- )
+int
+create_list_window(struct list_description *ld, struct list *list,
+ struct terminal *term, struct session *ses)
{
struct dialog *d;
int a;
@@ -1463,85 +1668,83 @@ int create_list_window(
/* zavodime, zavodime... */
if (test_list_window_in_use(ld, term))
return 1;
- ld->open=1;
+ ld->open = 1;
- if (!ld->current_pos)
- {
- ld->current_pos=list;
- ld->win_offset=list;
- ld->win_pos=0;
- ld->dlg=NULL;
+ if (!ld->current_pos) {
+ ld->current_pos = list;
+ ld->win_offset = list;
+ ld->win_pos = 0;
+ ld->dlg = NULL;
}
- a=7;
- if (ld->button_fn)a++;
- if (ld->type==1)a++;
+ a = 7;
+ if (ld->button_fn)
+ a++;
+ if (ld->type == 1)
+ a++;
d = mem_calloc(sizeof(struct dialog) + a * sizeof(struct dialog_item));
- d->title=TEXT_(ld->window_title);
- d->fn=create_list_window_fn;
- d->abort=close_list_window;
- d->handle_event=list_event_handler;
- d->udata=ses;
- d->udata2=ld;
+ d->title = TEXT_(ld->window_title);
+ d->fn = create_list_window_fn;
+ d->abort = close_list_window;
+ d->handle_event = list_event_handler;
+ d->udata = ses;
+ d->udata2 = ld;
- a=0;
+ a = 0;
- if (ld->button_fn)
- {
- d->items[a].type=D_BUTTON;
- d->items[a].fn=list_item_button;
- d->items[a].text=TEXT_(ld->button);
+ if (ld->button_fn) {
+ d->items[a].type = D_BUTTON;
+ d->items[a].fn = list_item_button;
+ d->items[a].text = TEXT_(ld->button);
a++;
}
- if (ld->type==1)
- {
- d->items[a].type=D_BUTTON;
- d->items[a].text=TEXT_(T_FOLDER);
- d->items[a].fn=list_folder_add;
+ if (ld->type == 1) {
+ d->items[a].type = D_BUTTON;
+ d->items[a].text = TEXT_(T_FOLDER);
+ d->items[a].fn = list_folder_add;
a++;
}
- d->items[a].type=D_BUTTON;
- d->items[a].text=TEXT_(T_ADD);
- d->items[a].fn=list_item_add;
+ d->items[a].type = D_BUTTON;
+ d->items[a].text = TEXT_(T_ADD);
+ d->items[a].fn = list_item_add;
- d->items[a+1].type=D_BUTTON;
- d->items[a+1].text=TEXT_(T_DELETE);
- d->items[a+1].fn=list_item_delete;
+ d->items[a + 1].type = D_BUTTON;
+ d->items[a + 1].text = TEXT_(T_DELETE);
+ d->items[a + 1].fn = list_item_delete;
- d->items[a+2].type=D_BUTTON;
- d->items[a+2].text=TEXT_(T_EDIT);
- d->items[a+2].fn=list_item_edit;
+ d->items[a + 2].type = D_BUTTON;
+ d->items[a + 2].text = TEXT_(T_EDIT);
+ d->items[a + 2].fn = list_item_edit;
- d->items[a+3].type=D_BUTTON;
- d->items[a+3].text=TEXT_(T_MOVE);
- d->items[a+3].fn=list_item_move;
+ d->items[a + 3].type = D_BUTTON;
+ d->items[a + 3].text = TEXT_(T_MOVE);
+ d->items[a + 3].fn = list_item_move;
- d->items[a+4].type=D_BUTTON;
- d->items[a+4].text=TEXT_(T_UNSELECT_ALL);
- d->items[a+4].fn=list_item_unselect;
+ d->items[a + 4].type = D_BUTTON;
+ d->items[a + 4].text = TEXT_(T_UNSELECT_ALL);
+ d->items[a + 4].fn = list_item_unselect;
- d->items[a+5].type=D_BUTTON;
- d->items[a+5].gid=B_ESC;
- d->items[a+5].fn=cancel_dialog;
- d->items[a+5].text=TEXT_(T_CLOSE);
+ d->items[a + 5].type = D_BUTTON;
+ d->items[a + 5].gid = B_ESC;
+ d->items[a + 5].fn = cancel_dialog;
+ d->items[a + 5].text = TEXT_(T_CLOSE);
- d->items[a+6].type=D_END;
+ d->items[a + 6].type = D_END;
do_dialog(term, d, getml(d, NULL));
return 0;
}
-
-void reinit_list_window(struct list_description *ld)
+void
+reinit_list_window(struct list_description *ld)
{
- ld->current_pos=ld->list;
- ld->win_offset=ld->list;
- ld->win_pos=0;
+ ld->current_pos = ld->list;
+ ld->win_offset = ld->list;
+ ld->win_pos = 0;
- if (ld->open) internal("reinit_list_window: calling reinit while open");
+ if (ld->open)
+ internal("reinit_list_window: calling reinit while open");
}
-
-
diff --git a/main.c b/main.c
@@ -12,9 +12,9 @@
#include <string.h>
#ifdef __OpenBSD__
-#include <unistd.h>
+ #include <unistd.h>
#else
-#define pledge(a,b) 0
+ #define pledge(a, b) 0
#endif
#include "links.h"
@@ -68,7 +68,8 @@ xrealloc(void *p, size_t len)
return p;
}
-static void sig_intr(void *t_)
+static void
+sig_intr(void *t_)
{
struct terminal *t = (struct terminal *)t_;
if (!t) {
@@ -80,19 +81,22 @@ static void sig_intr(void *t_)
}
}
-static void sig_ctrl_c(void *t_)
+static void
+sig_ctrl_c(void *t_)
{
if (!is_blocked())
kbd_ctrl_c();
}
-static void sig_ign(void *x)
+static void
+sig_ign(void *x)
{
}
static struct timer *fg_poll_timer = NULL;
-void sig_tstp(void *t_)
+void
+sig_tstp(void *t_)
{
struct terminal *t = (struct terminal *)t_;
pid_t pid, newpid;
@@ -114,11 +118,13 @@ void sig_tstp(void *t_)
int rr;
EINTRLOOP(rr, kill(newpid, SIGKILL));
}
- if (fg_poll_timer != NULL) kill_timer(fg_poll_timer);
+ if (fg_poll_timer != NULL)
+ kill_timer(fg_poll_timer);
fg_poll_timer = install_timer(FG_POLL_TIME, poll_fg, t);
}
-static void poll_fg(void *t_)
+static void
+poll_fg(void *t_)
{
struct terminal *t = (struct terminal *)t_;
int r;
@@ -132,12 +138,14 @@ static void poll_fg(void *t_)
}
}
-void sig_cont(void *t_)
+void
+sig_cont(void *t_)
{
unblock_itrm(1);
}
-static void handle_basic_signals(struct terminal *term)
+static void
+handle_basic_signals(struct terminal *term)
{
install_signal_handler(SIGHUP, sig_intr, term, 0);
install_signal_handler(SIGINT, sig_ctrl_c, term, 0);
@@ -147,7 +155,8 @@ static void handle_basic_signals(struct terminal *term)
install_signal_handler(SIGCONT, sig_cont, term, 0);
}
-void unhandle_terminal_signals(struct terminal *term)
+void
+unhandle_terminal_signals(struct terminal *term)
{
install_signal_handler(SIGHUP, NULL, NULL, 0);
install_signal_handler(SIGINT, NULL, NULL, 0);
@@ -161,7 +170,8 @@ void unhandle_terminal_signals(struct terminal *term)
}
}
-static void unhandle_basic_signals(struct terminal *term)
+static void
+unhandle_basic_signals(struct terminal *term)
{
install_signal_handler(SIGHUP, NULL, NULL, 0);
install_signal_handler(SIGINT, NULL, NULL, 0);
@@ -177,7 +187,8 @@ static void unhandle_basic_signals(struct terminal *term)
int terminal_pipe[2] = { -1, -1 };
-int attach_terminal(void *info, int len)
+int
+attach_terminal(void *info, int len)
{
struct terminal *term;
set_nonblock(terminal_pipe[0]);
@@ -185,7 +196,9 @@ int attach_terminal(void *info, int len)
handle_trm(terminal_pipe[1], info, len);
free(info);
if ((term = init_term(terminal_pipe[0], 1, win_func))) {
- handle_basic_signals(term); /* OK, this is race condition, but it must be so; GPM installs it's own buggy TSTP handler */
+ handle_basic_signals(
+ term); /* OK, this is race condition, but it must be so; GPM
+ installs it's own buggy TSTP handler */
return terminal_pipe[1];
}
close_socket(&terminal_pipe[0]);
@@ -196,36 +209,51 @@ int attach_terminal(void *info, int len)
static struct object_request *dump_obj;
static off_t dump_pos;
-static void end_dump(struct object_request *r, void *p)
+static void
+end_dump(struct object_request *r, void *p)
{
struct cache_entry *ce;
- if (!r->state || (r->state == 1 && dmp != D_SOURCE)) return;
+ if (!r->state || (r->state == 1 && dmp != D_SOURCE))
+ return;
ce = r->ce;
if (dmp == D_SOURCE) {
if (ce) {
struct fragment *frag = NULL;
struct list_head *lfrag;
- nextfrag:
- foreach(struct fragment, frag, lfrag, ce->frag) if (frag->offset <= dump_pos && frag->offset + frag->length > dump_pos) {
- off_t l;
- int w;
- l = frag->length - (dump_pos - frag->offset);
- if (l >= INT_MAX)
- l = INT_MAX;
- w = hard_write(1, frag->data + dump_pos - frag->offset, (int)l);
- if (w != l) {
+nextfrag:
+ foreach (struct fragment, frag, lfrag, ce->frag)
+ if (frag->offset <= dump_pos
+ && frag->offset + frag->length > dump_pos) {
+ off_t l;
+ int w;
+ l = frag->length
+ - (dump_pos - frag->offset);
+ if (l >= INT_MAX)
+ l = INT_MAX;
+ w = hard_write(1,
+ frag->data + dump_pos
+ - frag->offset,
+ (int)l);
+ if (w != l) {
+ detach_object_connection(
+ r, dump_pos);
+ if (w < 0)
+ fprintf(
+ stderr,
+ "Error writing to "
+ "stdout: %s.\n",
+ strerror(errno));
+ else
+ fprintf(stderr,
+ "Can't write "
+ "to stdout.\n");
+ retval = RET_ERROR;
+ goto terminate;
+ }
+ dump_pos += w;
detach_object_connection(r, dump_pos);
- if (w < 0)
- fprintf(stderr, "Error writing to stdout: %s.\n", strerror(errno));
- else
- fprintf(stderr, "Can't write to stdout.\n");
- retval = RET_ERROR;
- goto terminate;
+ goto nextfrag;
}
- dump_pos += w;
- detach_object_connection(r, dump_pos);
- goto nextfrag;
- }
}
if (r->state >= 0)
return;
@@ -245,15 +273,19 @@ static void end_dump(struct object_request *r, void *p)
o.plain = 0;
o.frames = 0;
o.framename = cast_uchar "";
- if (!casecmp(r->url, cast_uchar "file://", 7) && !o.hard_assume) {
+ if (!casecmp(r->url, cast_uchar "file://", 7)
+ && !o.hard_assume) {
o.assume_cp = 0;
}
- if (!(fd->f_data = cached_format_html(fd, r, r->url, &o, NULL, 0))) goto term_1;
+ if (!(fd->f_data =
+ cached_format_html(fd, r, r->url, &o, NULL, 0)))
+ goto term_1;
if ((err = dump_to_file(fd->f_data, 1))) {
- fprintf(stderr, "Error writing to stdout: %s.\n", get_err_msg(err));
+ fprintf(stderr, "Error writing to stdout: %s.\n",
+ get_err_msg(err));
retval = RET_ERROR;
}
- term_1:
+term_1:
reinit_f_data_c(fd);
free(fd);
}
@@ -263,11 +295,12 @@ static void end_dump(struct object_request *r, void *p)
retval = RET_ERROR;
goto terminate;
}
- terminate:
+terminate:
terminate_loop = 1;
}
-static void init(void)
+static void
+init(void)
{
void *info;
int len;
@@ -275,9 +308,11 @@ static void init(void)
initialize_all_subsystems();
-/* OS/2 has some stupid bug and the pipe must be created before socket :-/ */
+ /* OS/2 has some stupid bug and the pipe must be created before socket
+ * :-/ */
if (c_pipe(terminal_pipe)) {
- fatal_exit("ERROR: can't create pipe for internal communication");
+ fatal_exit(
+ "ERROR: can't create pipe for internal communication");
}
if (!(u = parse_options(g_argc - 1, g_argv + 1))) {
retval = RET_SYNTAX;
@@ -288,9 +323,9 @@ static void init(void)
if (proxies.only_proxies)
reset_settings_for_tor();
if (!u) {
- ttt:
+ttt:
initialize_all_subsystems_2();
- tttt:
+tttt:
terminate_loop = 1;
return;
}
@@ -301,7 +336,8 @@ static void init(void)
create_initial_extensions();
load_url_history();
initialize_all_subsystems_2();
- info = create_session_info(base_session, u, default_target, &len);
+ info =
+ create_session_info(base_session, u, default_target, &len);
if (attach_terminal(info, len) < 0)
fatal_exit("Could not open initial session");
} else {
@@ -310,21 +346,25 @@ static void init(void)
close_socket(&terminal_pipe[0]);
close_socket(&terminal_pipe[1]);
if (!*u) {
- fprintf(stderr, "URL expected after %s\n", dmp == D_DUMP ? "-dump" : "-source");
+ fprintf(stderr, "URL expected after %s\n",
+ dmp == D_DUMP ? "-dump" : "-source");
retval = RET_SYNTAX;
goto tttt;
}
uu = stracpy(u);
- if (!(uuu = translate_url(uu, wd = get_cwd()))) uuu = stracpy(uu);
+ if (!(uuu = translate_url(uu, wd = get_cwd())))
+ uuu = stracpy(uu);
free(uu);
- request_object(NULL, uuu, NULL, PRI_MAIN, NC_RELOAD, ALLOW_ALL, end_dump, NULL, &dump_obj);
+ request_object(NULL, uuu, NULL, PRI_MAIN, NC_RELOAD, ALLOW_ALL,
+ end_dump, NULL, &dump_obj);
free(uuu);
free(wd);
}
}
/* Is called before gaphics driver init */
-static void initialize_all_subsystems(void)
+static void
+initialize_all_subsystems(void)
{
set_sigcld();
init_home();
@@ -335,12 +375,14 @@ static void initialize_all_subsystems(void)
}
/* Is called sometimes after and sometimes before graphics driver init */
-static void initialize_all_subsystems_2(void)
+static void
+initialize_all_subsystems_2(void)
{
init_fcache();
}
-static void terminate_all_subsystems(void)
+static void
+terminate_all_subsystems(void)
{
check_bottom_halves();
abort_all_downloads();
diff --git a/memory.c b/memory.c
@@ -6,26 +6,28 @@
#include "links.h"
struct cache_upcall {
- list_entry_1st
- int (*upcall)(int);
+ list_entry_1st int (*upcall)(int);
unsigned char flags;
unsigned char name[1];
};
-static struct list_head cache_upcalls = { &cache_upcalls, &cache_upcalls }; /* cache_upcall */
+static struct list_head cache_upcalls = { &cache_upcalls,
+ &cache_upcalls }; /* cache_upcall */
-int shrink_memory(int type)
+int
+shrink_memory(int type)
{
struct cache_upcall *c = NULL;
struct list_head *lc;
int a = 0;
- foreach(struct cache_upcall, c, lc, cache_upcalls) {
+ foreach (struct cache_upcall, c, lc, cache_upcalls) {
a |= c->upcall(type);
}
return a;
}
-void register_cache_upcall(int (*upcall)(int), int flags, unsigned char *name)
+void
+register_cache_upcall(int (*upcall)(int), int flags, unsigned char *name)
{
struct cache_upcall *c;
c = xmalloc(sizeof(struct cache_upcall) + strlen(cast_const_char name));
@@ -35,7 +37,8 @@ void register_cache_upcall(int (*upcall)(int), int flags, unsigned char *name)
add_to_list(cache_upcalls, c);
}
-void free_all_caches(void)
+void
+free_all_caches(void)
{
struct cache_upcall *c = NULL;
struct list_head *lc;
@@ -43,7 +46,7 @@ void free_all_caches(void)
do {
a = 0;
b = ~0;
- foreach(struct cache_upcall, c, lc, cache_upcalls) {
+ foreach (struct cache_upcall, c, lc, cache_upcalls) {
int x = c->upcall(SH_FREE_ALL);
a |= x;
b &= x;
@@ -52,17 +55,20 @@ void free_all_caches(void)
if (!(b & ST_CACHE_EMPTY)) {
unsigned char *m = init_str();
int l = 0;
- foreach(struct cache_upcall, c, lc, cache_upcalls) if (!(c->upcall(SH_FREE_ALL) & ST_CACHE_EMPTY)) {
- if (l) add_to_str(&m, &l, cast_uchar ", ");
- add_to_str(&m, &l, c->name);
- }
+ foreach (struct cache_upcall, c, lc, cache_upcalls)
+ if (!(c->upcall(SH_FREE_ALL) & ST_CACHE_EMPTY)) {
+ if (l)
+ add_to_str(&m, &l, cast_uchar ", ");
+ add_to_str(&m, &l, c->name);
+ }
internal("could not release entries from caches: %s", m);
free(m);
}
free_list(struct cache_upcall, cache_upcalls);
}
-int out_of_memory(void)
+int
+out_of_memory(void)
{
if (shrink_memory(SH_FREE_SOMETHING))
return 1;
diff --git a/menu.c b/menu.c
@@ -8,9 +8,11 @@
#include "config.h"
#include "links.h"
-static struct history file_history = { 0, { &file_history.items, &file_history.items } };
+static struct history file_history = {
+ 0, {&file_history.items, &file_history.items}
+};
-static unsigned char * const version_texts[] = {
+static unsigned char *const version_texts[] = {
TEXT_(T_LINKS_VERSION),
TEXT_(T_OPERATING_SYSTEM_VERSION),
TEXT_(T_WORD_SIZE),
@@ -24,23 +26,27 @@ static unsigned char * const version_texts[] = {
NULL,
};
-static void add_and_pad(unsigned char **s, int *l, struct terminal *term, unsigned char *str, int maxlen)
+static void
+add_and_pad(unsigned char **s, int *l, struct terminal *term,
+ unsigned char *str, int maxlen)
{
unsigned char *x = get_text_translation(str, term);
int len = strlen((char *)x);
add_to_str(s, l, x);
add_to_str(s, l, cast_uchar ": ");
- while (len++ < maxlen) add_chr_to_str(s, l, ' ');
+ while (len++ < maxlen)
+ add_chr_to_str(s, l, ' ');
}
-static void menu_version(void *term_)
+static void
+menu_version(void *term_)
{
struct terminal *term = (struct terminal *)term_;
int i;
int maxlen = 0;
unsigned char *s;
int l;
- unsigned char * const *text_ptr;
+ unsigned char *const *text_ptr;
for (i = 0; version_texts[i]; i++) {
unsigned char *t = get_text_translation(version_texts[i], term);
int tl = strlen((char *)t);
@@ -76,9 +82,16 @@ static void menu_version(void *term_)
add_to_str(&s, &l, cast_uchar "\n");
add_and_pad(&s, &l, term, *text_ptr++, maxlen);
- if (!support_ipv6) add_to_str(&s, &l, get_text_translation(TEXT_(T_NOT_ENABLED_IN_SYSTEM), term));
- else if (!ipv6_full_access()) add_to_str(&s, &l, get_text_translation(TEXT_(T_LOCAL_NETWORK_ONLY), term));
- else add_to_str(&s, &l, get_text_translation(TEXT_(T_YES), term));
+ if (!support_ipv6)
+ add_to_str(
+ &s, &l,
+ get_text_translation(TEXT_(T_NOT_ENABLED_IN_SYSTEM), term));
+ else if (!ipv6_full_access())
+ add_to_str(
+ &s, &l,
+ get_text_translation(TEXT_(T_LOCAL_NETWORK_ONLY), term));
+ else
+ add_to_str(&s, &l, get_text_translation(TEXT_(T_YES), term));
add_to_str(&s, &l, cast_uchar "\n");
add_and_pad(&s, &l, term, *text_ptr++, maxlen);
@@ -102,7 +115,8 @@ static void menu_version(void *term_)
add_and_pad(&s, &l, term, *text_ptr++, maxlen);
if (links_home) {
- unsigned char *native_home = os_conv_to_external_path(links_home, NULL);
+ unsigned char *native_home =
+ os_conv_to_external_path(links_home, NULL);
add_to_str(&s, &l, native_home);
free(native_home);
} else
@@ -113,100 +127,126 @@ static void menu_version(void *term_)
if (*text_ptr)
internal("menu_version: text mismatched");
- msg_box(term, getml(s, NULL), TEXT_(T_VERSION_INFORMATION), AL_LEFT | AL_MONO, s, MSG_BOX_END, NULL, 1, TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
+ msg_box(term, getml(s, NULL), TEXT_(T_VERSION_INFORMATION),
+ AL_LEFT | AL_MONO, s, MSG_BOX_END, NULL, 1, TEXT_(T_OK),
+ msg_box_null, B_ENTER | B_ESC);
}
-static void menu_about(struct terminal *term, void *d, void *ses_)
+static void
+menu_about(struct terminal *term, void *d, void *ses_)
{
- msg_box(term, NULL, TEXT_(T_ABOUT), AL_CENTER, TEXT_(T_LINKS__LYNX_LIKE), MSG_BOX_END, (void *)term, 2, TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC, TEXT_(T_VERSION), menu_version, 0);
+ msg_box(term, NULL, TEXT_(T_ABOUT), AL_CENTER,
+ TEXT_(T_LINKS__LYNX_LIKE), MSG_BOX_END, (void *)term, 2,
+ TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC, TEXT_(T_VERSION),
+ menu_version, 0);
}
-static void menu_keys(struct terminal *term, void *d, void *ses_)
+static void
+menu_keys(struct terminal *term, void *d, void *ses_)
{
msg_box(term, NULL, TEXT_(T_KEYS), AL_LEFT | AL_MONO,
- TEXT_(T_KEYS_DESC), MSG_BOX_END, NULL, 1, TEXT_(T_OK),
- msg_box_null, B_ENTER | B_ESC);
+ TEXT_(T_KEYS_DESC), MSG_BOX_END, NULL, 1, TEXT_(T_OK),
+ msg_box_null, B_ENTER | B_ESC);
}
-void activate_keys(struct session *ses)
+void
+activate_keys(struct session *ses)
{
menu_keys(ses->term, NULL, ses);
}
-static void menu_copying(struct terminal *term, void *d, void *ses_)
+static void
+menu_copying(struct terminal *term, void *d, void *ses_)
{
- msg_box(term, NULL, TEXT_(T_COPYING), AL_CENTER, TEXT_(T_COPYING_DESC), MSG_BOX_END, NULL, 1, TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
+ msg_box(term, NULL, TEXT_(T_COPYING), AL_CENTER, TEXT_(T_COPYING_DESC),
+ MSG_BOX_END, NULL, 1, TEXT_(T_OK), msg_box_null,
+ B_ENTER | B_ESC);
}
-static void menu_url(struct terminal *term, void *url_, void *ses_)
+static void
+menu_url(struct terminal *term, void *url_, void *ses_)
{
struct session *ses = (struct session *)ses_;
unsigned char *url = get_text_translation((unsigned char *)url_, term);
goto_url_utf8(ses, url);
}
-static void menu_for_frame(struct terminal *term, void *f_, void *ses_)
+static void
+menu_for_frame(struct terminal *term, void *f_, void *ses_)
{
struct session *ses = (struct session *)ses_;
- void (*f)(struct session *, struct f_data_c *, int) = *(void (* const *)(struct session *, struct f_data_c *, int))f_;
+ void (*f)(struct session *, struct f_data_c *, int) =
+ *(void (*const *)(struct session *, struct f_data_c *, int))f_;
do_for_frame(ses, f, 0);
}
-static void menu_goto_url(struct terminal *term, void *d, void *ses_)
+static void
+menu_goto_url(struct terminal *term, void *d, void *ses_)
{
struct session *ses = (struct session *)ses_;
dialog_goto_url(ses, cast_uchar "");
}
-static void menu_save_url_as(struct terminal *term, void *d, void *ses_)
+static void
+menu_save_url_as(struct terminal *term, void *d, void *ses_)
{
struct session *ses = (struct session *)ses_;
dialog_save_url(ses);
}
-static void menu_go_back(struct terminal *term, void *d, void *ses_)
+static void
+menu_go_back(struct terminal *term, void *d, void *ses_)
{
struct session *ses = (struct session *)ses_;
go_back(ses, 1);
}
-static void menu_go_forward(struct terminal *term, void *d, void *ses_)
+static void
+menu_go_forward(struct terminal *term, void *d, void *ses_)
{
struct session *ses = (struct session *)ses_;
go_back(ses, -1);
}
-static void menu_reload(struct terminal *term, void *d, void *ses_)
+static void
+menu_reload(struct terminal *term, void *d, void *ses_)
{
struct session *ses = (struct session *)ses_;
reload(ses, -1);
}
-void really_exit_prog(void *ses_)
+void
+really_exit_prog(void *ses_)
{
struct session *ses = (struct session *)ses_;
register_bottom_half(destroy_terminal, ses->term);
}
-static void dont_exit_prog(void *ses_)
+static void
+dont_exit_prog(void *ses_)
{
struct session *ses = (struct session *)ses_;
ses->exit_query = 0;
}
-void query_exit(struct session *ses)
+void
+query_exit(struct session *ses)
{
- int only_one_term = ses->term->list_entry.next == ses->term->list_entry.prev;
+ int only_one_term =
+ ses->term->list_entry.next == ses->term->list_entry.prev;
ses->exit_query = 1;
- msg_box(ses->term, NULL, TEXT_(T_EXIT_LINKS), AL_CENTER,
- only_one_term && are_there_downloads() ? TEXT_(T_DO_YOU_REALLY_WANT_TO_EXIT_LINKS_AND_TERMINATE_ALL_DOWNLOADS) :
- 1 || only_one_term ? TEXT_(T_DO_YOU_REALLY_WANT_TO_EXIT_LINKS) :
- TEXT_(T_DO_YOU_REALLY_WANT_TO_CLOSE_WINDOW),
- MSG_BOX_END,
- (void *)ses, 2, TEXT_(T_YES), really_exit_prog, B_ENTER, TEXT_(T_NO), dont_exit_prog, B_ESC);
+ msg_box(
+ ses->term, NULL, TEXT_(T_EXIT_LINKS), AL_CENTER,
+ only_one_term && are_there_downloads() ? TEXT_(
+ T_DO_YOU_REALLY_WANT_TO_EXIT_LINKS_AND_TERMINATE_ALL_DOWNLOADS)
+ : 1 || only_one_term ? TEXT_(T_DO_YOU_REALLY_WANT_TO_EXIT_LINKS)
+ : TEXT_(T_DO_YOU_REALLY_WANT_TO_CLOSE_WINDOW),
+ MSG_BOX_END, (void *)ses, 2, TEXT_(T_YES), really_exit_prog,
+ B_ENTER, TEXT_(T_NO), dont_exit_prog, B_ESC);
}
-void exit_prog(struct terminal *term, void *d, void *ses_)
+void
+exit_prog(struct terminal *term, void *d, void *ses_)
{
struct session *ses = (struct session *)ses_;
int only_one_term;
@@ -214,8 +254,10 @@ void exit_prog(struct terminal *term, void *d, void *ses_)
register_bottom_half(destroy_terminal, term);
return;
}
- only_one_term = ses->term->list_entry.next == ses->term->list_entry.prev;
- if (!ses->exit_query && (!d || (only_one_term && are_there_downloads()))) {
+ only_one_term =
+ ses->term->list_entry.next == ses->term->list_entry.prev;
+ if (!ses->exit_query
+ && (!d || (only_one_term && are_there_downloads()))) {
query_exit(ses);
return;
}
@@ -231,7 +273,8 @@ struct refresh {
struct timer *timer;
};
-static void refresh(void *r_)
+static void
+refresh(void *r_)
{
struct refresh *r = (struct refresh *)r_;
r->timer = NULL;
@@ -240,18 +283,22 @@ static void refresh(void *r_)
delete_window(r->win);
}
-static void end_refresh(struct refresh *r)
+static void
+end_refresh(struct refresh *r)
{
- if (r->timer != NULL) kill_timer(r->timer);
+ if (r->timer != NULL)
+ kill_timer(r->timer);
free(r);
}
-static void refresh_abort(struct dialog_data *dlg)
+static void
+refresh_abort(struct dialog_data *dlg)
{
end_refresh(dlg->dlg->udata2);
}
-static int resource_info(struct terminal *term, struct refresh *r2)
+static int
+resource_info(struct terminal *term, struct refresh *r2)
{
unsigned char *a;
int l;
@@ -278,7 +325,10 @@ static int resource_info(struct terminal *term, struct refresh *r2)
add_to_str(&a, &l, get_text_translation(TEXT_(T_CONNECTIONS), term));
add_to_str(&a, &l, cast_uchar ": ");
- add_unsigned_long_num_to_str(&a, &l, connect_info(CI_FILES) - connect_info(CI_CONNECTING) - connect_info(CI_TRANSFER));
+ add_unsigned_long_num_to_str(&a, &l,
+ connect_info(CI_FILES)
+ - connect_info(CI_CONNECTING)
+ - connect_info(CI_TRANSFER));
add_chr_to_str(&a, &l, ' ');
add_to_str(&a, &l, get_text_translation(TEXT_(T_WAITING), term));
add_to_str(&a, &l, cast_uchar ", ");
@@ -314,7 +364,8 @@ static int resource_info(struct terminal *term, struct refresh *r2)
add_to_str(&a, &l, get_text_translation(TEXT_(T_LOADING), term));
add_to_str(&a, &l, cast_uchar ".\n");
- add_to_str(&a, &l, get_text_translation(TEXT_(T_DECOMPRESSED_CACHE), term));
+ add_to_str(&a, &l,
+ get_text_translation(TEXT_(T_DECOMPRESSED_CACHE), term));
add_to_str(&a, &l, cast_uchar ": ");
add_unsigned_long_num_to_str(&a, &l, decompress_info(CI_BYTES));
add_chr_to_str(&a, &l, ' ');
@@ -329,7 +380,9 @@ static int resource_info(struct terminal *term, struct refresh *r2)
add_to_str(&a, &l, get_text_translation(TEXT_(T_LOCKED), term));
add_to_str(&a, &l, cast_uchar ".\n");
- add_to_str(&a, &l, get_text_translation(TEXT_(T_FORMATTED_DOCUMENT_CACHE), term));
+ add_to_str(
+ &a, &l,
+ get_text_translation(TEXT_(T_FORMATTED_DOCUMENT_CACHE), term));
add_to_str(&a, &l, cast_uchar ": ");
add_unsigned_long_num_to_str(&a, &l, formatted_info(CI_FILES));
add_chr_to_str(&a, &l, ' ');
@@ -346,54 +399,65 @@ static int resource_info(struct terminal *term, struct refresh *r2)
add_chr_to_str(&a, &l, ' ');
add_to_str(&a, &l, get_text_translation(TEXT_(T_SERVERS), term));
add_to_str(&a, &l, cast_uchar ", ");
- add_to_str(&a, &l, get_text_translation(TEXT_(T_TLS_SESSION_CACHE), term));
+ add_to_str(&a, &l,
+ get_text_translation(TEXT_(T_TLS_SESSION_CACHE), term));
add_to_str(&a, &l, cast_uchar ": ");
add_unsigned_long_num_to_str(&a, &l, session_info(CI_FILES));
add_chr_to_str(&a, &l, ' ');
add_to_str(&a, &l, get_text_translation(TEXT_(T_SERVERS), term));
add_chr_to_str(&a, &l, '.');
- if (r2 && !strcmp(cast_const_char a, cast_const_char *(unsigned char **)((struct dialog_data *)r2->win->data)->dlg->udata)) {
+ if (r2
+ && !strcmp(
+ cast_const_char a,
+ cast_const_char
+ * (unsigned char **)((struct dialog_data *)r2->win->data)
+ ->dlg->udata)) {
free(a);
free(r);
r2->timer = install_timer(RESOURCE_INFO_REFRESH, refresh, r2);
return 1;
}
- msg_box(term, getml(a, NULL), TEXT_(T_RESOURCES), AL_LEFT, a, MSG_BOX_END, (void *)r, 1, TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
+ msg_box(term, getml(a, NULL), TEXT_(T_RESOURCES), AL_LEFT, a,
+ MSG_BOX_END, (void *)r, 1, TEXT_(T_OK), msg_box_null,
+ B_ENTER | B_ESC);
r->win = list_struct(term->windows.next, struct window);
((struct dialog_data *)r->win->data)->dlg->abort = refresh_abort;
r->timer = install_timer(RESOURCE_INFO_REFRESH, refresh, r);
return 0;
}
-static void resource_info_menu(struct terminal *term, void *d, void *ses_)
+static void
+resource_info_menu(struct terminal *term, void *d, void *ses_)
{
resource_info(term, NULL);
}
-static void flush_caches(struct terminal *term, void *d, void *e)
+static void
+flush_caches(struct terminal *term, void *d, void *e)
{
abort_background_connections();
shrink_memory(SH_FREE_ALL);
}
/* jde v historii na polozku id_ptr */
-void go_backwards(struct terminal *term, void *id_ptr, void *ses_)
+void
+go_backwards(struct terminal *term, void *id_ptr, void *ses_)
{
struct session *ses = (struct session *)ses_;
unsigned want_id = (unsigned)(long)id_ptr;
struct location *l = NULL;
struct list_head *ll;
int n = 0;
- foreach(struct location, l, ll, ses->history) {
+ foreach (struct location, l, ll, ses->history) {
if (l->location_id == want_id) {
goto have_it;
}
n++;
}
n = -1;
- foreach(struct location, l, ll, ses->forward_history) {
+ foreach (struct location, l, ll, ses->forward_history) {
if (l->location_id == want_id) {
goto have_it;
}
@@ -401,29 +465,32 @@ void go_backwards(struct terminal *term, void *id_ptr, void *ses_)
}
return;
- have_it:
+have_it:
go_back(ses, n);
}
static const struct menu_item no_hist_menu[] = {
- { TEXT_(T_NO_HISTORY), cast_uchar "", M_BAR, NULL, NULL, 0, 0 },
- { NULL, NULL, 0, NULL, NULL, 0, 0 }
+ {TEXT_(T_NO_HISTORY), cast_uchar "", M_BAR, NULL, NULL, 0, 0},
+ { NULL, NULL, 0, NULL, NULL, 0, 0}
};
-static void add_history_menu_entry(struct terminal *term, struct menu_item **mi, int *n, struct location *l)
+static void
+add_history_menu_entry(struct terminal *term, struct menu_item **mi, int *n,
+ struct location *l)
{
unsigned char *url;
if (!*mi)
*mi = new_menu(MENU_FREE_ITEMS | MENU_FREE_TEXT);
url = display_url(term, l->url, 1);
add_to_menu(mi, url, cast_uchar "", cast_uchar "", go_backwards,
- (void *)(long)l->location_id, 0, *n);
+ (void *)(long)l->location_id, 0, *n);
(*n)++;
if (*n == INT_MAX)
overalloc();
}
-static void history_menu(struct terminal *term, void *ddd, void *ses_)
+static void
+history_menu(struct terminal *term, void *ddd, void *ses_)
{
struct session *ses = (struct session *)ses_;
struct location *l = NULL;
@@ -431,79 +498,99 @@ static void history_menu(struct terminal *term, void *ddd, void *ses_)
struct menu_item *mi = NULL;
int n = 0;
int selected = 0;
- foreachback(struct location, l, ll, ses->forward_history) {
+ foreachback (struct location, l, ll, ses->forward_history) {
add_history_menu_entry(term, &mi, &n, l);
}
selected = n;
- foreach(struct location, l, ll, ses->history) {
+ foreach (struct location, l, ll, ses->history) {
add_history_menu_entry(term, &mi, &n, l);
}
- if (!mi) do_menu(term, (struct menu_item *)no_hist_menu, ses);
- else do_menu_selected(term, mi, ses, selected, NULL, NULL);
+ if (!mi)
+ do_menu(term, (struct menu_item *)no_hist_menu, ses);
+ else
+ do_menu_selected(term, mi, ses, selected, NULL, NULL);
}
static const struct menu_item no_downloads_menu[] = {
- { TEXT_(T_NO_DOWNLOADS), cast_uchar "", M_BAR, NULL, NULL, 0, 0 },
- { NULL, NULL, 0, NULL, NULL, 0, 0 }
+ {TEXT_(T_NO_DOWNLOADS), cast_uchar "", M_BAR, NULL, NULL, 0, 0},
+ { NULL, NULL, 0, NULL, NULL, 0, 0}
};
-static void downloads_menu(struct terminal *term, void *ddd, void *ses_)
+static void
+downloads_menu(struct terminal *term, void *ddd, void *ses_)
{
struct session *ses = (struct session *)ses_;
struct download *d = NULL;
struct list_head *ld;
struct menu_item *mi = NULL;
int n = 0;
- foreachback(struct download, d, ld, downloads) {
+ foreachback (struct download, d, ld, downloads) {
unsigned char *f, *ff;
- if (!mi) mi = new_menu(MENU_FREE_ITEMS | MENU_FREE_TEXT | MENU_FREE_RTEXT);
+ if (!mi)
+ mi = new_menu(MENU_FREE_ITEMS | MENU_FREE_TEXT
+ | MENU_FREE_RTEXT);
f = !d->prog ? d->orig_file : d->url;
for (ff = f; *ff; ff++)
- if ((dir_sep(ff[0])
- ) && ff[1])
+ if ((dir_sep(ff[0])) && ff[1])
f = ff + 1;
if (!d->prog)
f = stracpy(f);
else
f = display_url(term, f, 1);
- add_to_menu(&mi, f, download_percentage(d, 0), cast_uchar "", display_download, d, 0, n);
+ add_to_menu(&mi, f, download_percentage(d, 0), cast_uchar "",
+ display_download, d, 0, n);
n++;
}
- if (!n) do_menu(term, (struct menu_item *)no_downloads_menu, ses);
- else do_menu(term, mi, ses);
+ if (!n)
+ do_menu(term, (struct menu_item *)no_downloads_menu, ses);
+ else
+ do_menu(term, mi, ses);
}
-static void menu_doc_info(struct terminal *term, void *ddd, void *ses_)
+static void
+menu_doc_info(struct terminal *term, void *ddd, void *ses_)
{
struct session *ses = (struct session *)ses_;
state_msg(ses);
}
-static void menu_head_info(struct terminal *term, void *ddd, void *ses_)
+static void
+menu_head_info(struct terminal *term, void *ddd, void *ses_)
{
struct session *ses = (struct session *)ses_;
head_msg(ses);
}
-static void menu_toggle(struct terminal *term, void *ddd, void *ses_)
+static void
+menu_toggle(struct terminal *term, void *ddd, void *ses_)
{
struct session *ses = (struct session *)ses_;
toggle(ses, ses->screen, 0);
}
-static void set_val(struct terminal *term, void *ip, void *d)
+static void
+set_val(struct terminal *term, void *ip, void *d)
{
*(int *)d = (int)(long)ip;
}
-static void terminal_options_ok(void *p)
+static void
+terminal_options_ok(void *p)
{
cls_redraw_all_terminals();
}
-static unsigned char * const td_labels[] = { TEXT_(T_NO_FRAMES), TEXT_(T_VT_100_FRAMES), TEXT_(T_USE_11M), TEXT_(T_RESTRICT_FRAMES_IN_CP850_852), TEXT_(T_BLOCK_CURSOR), TEXT_(T_COLOR), NULL };
+static unsigned char *const td_labels[] = { TEXT_(T_NO_FRAMES),
+ TEXT_(T_VT_100_FRAMES),
+ TEXT_(T_USE_11M),
+ TEXT_(
+ T_RESTRICT_FRAMES_IN_CP850_852),
+ TEXT_(T_BLOCK_CURSOR),
+ TEXT_(T_COLOR),
+ NULL };
-static void terminal_options(struct terminal *term, void *xxx, void *ses_)
+static void
+terminal_options(struct terminal *term, void *xxx, void *ses_)
{
struct dialog *d;
struct term_spec *ts = new_term_spec(term->term);
@@ -550,7 +637,8 @@ static void terminal_options(struct terminal *term, void *xxx, void *ses_)
do_dialog(term, d, getml(d, NULL));
}
-static void refresh_network(void *xxx)
+static void
+refresh_network(void *xxx)
{
abort_background_connections();
register_bottom_half(check_queue, NULL);
@@ -563,7 +651,8 @@ static unsigned char time_str[5];
static unsigned char unrtime_str[5];
static unsigned char addrtime_str[4];
-static void refresh_connections(void *xxx)
+static void
+refresh_connections(void *xxx)
{
netcfg_stamp++;
max_connections = atoi(cast_const_char max_c_str);
@@ -577,7 +666,8 @@ static void refresh_connections(void *xxx)
static unsigned char *net_msg[10];
-static void dlg_net_options(struct terminal *term, void *xxx, void *yyy)
+static void
+dlg_net_options(struct terminal *term, void *xxx, void *yyy)
{
struct dialog *d;
int a;
@@ -663,9 +753,14 @@ static void dlg_net_options(struct terminal *term, void *xxx, void *yyy)
do_dialog(term, d, getml(d, NULL));
}
-static unsigned char * const ipv6_labels[] = { TEXT_(T_IPV6_DEFAULT), TEXT_(T_IPV6_PREFER_IPV4), TEXT_(T_IPV6_PREFER_IPV6), TEXT_(T_IPV6_USE_ONLY_IPV4), TEXT_(T_IPV6_USE_ONLY_IPV6), NULL };
+static unsigned char *const ipv6_labels[] = {
+ TEXT_(T_IPV6_DEFAULT), TEXT_(T_IPV6_PREFER_IPV4),
+ TEXT_(T_IPV6_PREFER_IPV6), TEXT_(T_IPV6_USE_ONLY_IPV4),
+ TEXT_(T_IPV6_USE_ONLY_IPV6), NULL
+};
-static void dlg_ipv6_options(struct terminal *term, void *xxx, void *yyy)
+static void
+dlg_ipv6_options(struct terminal *term, void *xxx, void *yyy)
{
struct dialog *d;
d = mem_calloc(sizeof(struct dialog) + 7 * sizeof(struct dialog_item));
@@ -710,9 +805,9 @@ static void dlg_ipv6_options(struct terminal *term, void *xxx, void *yyy)
do_dialog(term, d, getml(d, NULL));
}
-#define N_N 6
+#define N_N 6
-static unsigned char * const proxy_msg[] = {
+static unsigned char *const proxy_msg[] = {
TEXT_(T_HTTP_PROXY__HOST_PORT),
TEXT_(T_HTTPS_PROXY__HOST_PORT),
TEXT_(T_SOCKS_4A_PROXY__USER_HOST_PORT),
@@ -721,7 +816,8 @@ static unsigned char * const proxy_msg[] = {
TEXT_(T_ONLY_PROXIES),
};
-static void proxy_fn(struct dialog_data *dlg)
+static void
+proxy_fn(struct dialog_data *dlg)
{
struct terminal *term = dlg->win->term;
int max = 0, min = 0;
@@ -732,23 +828,33 @@ static void proxy_fn(struct dialog_data *dlg)
max_text_width(term, proxy_msg[i], &max, AL_LEFT);
min_text_width(term, proxy_msg[i], &min, AL_LEFT);
}
- max_group_width(term, proxy_msg + N_N, dlg->items + N_N, dlg->n - 2 - N_N, &max);
- min_group_width(term, proxy_msg + N_N, dlg->items + N_N, dlg->n - 2 - N_N, &min);
+ max_group_width(term, proxy_msg + N_N, dlg->items + N_N,
+ dlg->n - 2 - N_N, &max);
+ min_group_width(term, proxy_msg + N_N, dlg->items + N_N,
+ dlg->n - 2 - N_N, &min);
max_buttons_width(term, dlg->items + dlg->n - 2, 2, &max);
min_buttons_width(term, dlg->items + dlg->n - 2, 2, &min);
w = dlg->win->term->x * 9 / 10 - 2 * DIALOG_LB;
- if (w > max) w = max;
- if (w < min) w = min;
- if (w > dlg->win->term->x - 2 * DIALOG_LB) w = dlg->win->term->x - 2 * DIALOG_LB;
- if (w < 1) w = 1;
+ if (w > max)
+ w = max;
+ if (w < min)
+ w = min;
+ if (w > dlg->win->term->x - 2 * DIALOG_LB)
+ w = dlg->win->term->x - 2 * DIALOG_LB;
+ if (w < 1)
+ w = 1;
rw = 0;
for (i = 0; i < N_N; i++) {
- dlg_format_text_and_field(dlg, NULL, proxy_msg[i], &dlg->items[i], 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, NULL, proxy_msg[i],
+ &dlg->items[i], 0, &y, w, &rw,
+ COLOR_DIALOG_TEXT, AL_LEFT);
y++;
}
- dlg_format_group(dlg, NULL, proxy_msg + N_N, dlg->items + N_N, dlg->n - 2 - N_N, 0, &y, w, &rw);
+ dlg_format_group(dlg, NULL, proxy_msg + N_N, dlg->items + N_N,
+ dlg->n - 2 - N_N, 0, &y, w, &rw);
y++;
- dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 2, 2, 0, &y, w, &rw, AL_CENTER);
+ dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 2, 2, 0, &y, w, &rw,
+ AL_CENTER);
w = rw;
dlg->xw = w + 2 * DIALOG_LB;
dlg->yw = y + 2 * DIALOG_TB;
@@ -756,15 +862,20 @@ static void proxy_fn(struct dialog_data *dlg)
draw_dlg(dlg);
y = dlg->y + DIALOG_TB;
for (i = 0; i < N_N; i++) {
- dlg_format_text_and_field(dlg, term, proxy_msg[i], &dlg->items[i], dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(
+ dlg, term, proxy_msg[i], &dlg->items[i], dlg->x + DIALOG_LB,
+ &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
y++;
}
- dlg_format_group(dlg, term, proxy_msg + N_N, &dlg->items[N_N], dlg->n - 2 - N_N, dlg->x + DIALOG_LB, &y, w, NULL);
+ dlg_format_group(dlg, term, proxy_msg + N_N, &dlg->items[N_N],
+ dlg->n - 2 - N_N, dlg->x + DIALOG_LB, &y, w, NULL);
y++;
- dlg_format_buttons(dlg, term, &dlg->items[dlg->n - 2], 2, dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);
+ dlg_format_buttons(dlg, term, &dlg->items[dlg->n - 2], 2,
+ dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);
}
-void reset_settings_for_tor(void)
+void
+reset_settings_for_tor(void)
{
max_connections = 10;
max_connections_to_host = 8;
@@ -794,12 +905,13 @@ void reset_settings_for_tor(void)
dds.display_images = 1;
}
-static void data_cleanup(void)
+static void
+data_cleanup(void)
{
struct session *ses = NULL;
struct list_head *lses;
reset_settings_for_tor();
- foreach(struct session, ses, lses, sessions) {
+ foreach (struct session, ses, lses, sessions) {
ses->ds.tables = dds.tables;
ses->ds.frames = dds.frames;
ses->ds.auto_refresh = dds.auto_refresh;
@@ -819,7 +931,9 @@ static unsigned char https_proxy[MAX_STR_LEN];
static unsigned char socks_proxy[MAX_STR_LEN];
static unsigned char no_proxy[MAX_STR_LEN];
-static void display_proxy(struct terminal *term, unsigned char *result, unsigned char *proxy)
+static void
+display_proxy(struct terminal *term, unsigned char *result,
+ unsigned char *proxy)
{
unsigned char *url, *res;
int sl;
@@ -836,7 +950,8 @@ static void display_proxy(struct terminal *term, unsigned char *result, unsigned
res = display_url(term, url, 0);
sl = (int)strlen(cast_const_char res);
- if (sl < 9 || strncmp(cast_const_char res, "proxy://", 8) || res[sl - 1] != '/') {
+ if (sl < 9 || strncmp(cast_const_char res, "proxy://", 8)
+ || res[sl - 1] != '/') {
result[0] = 0;
} else {
res[sl - 1] = 0;
@@ -847,7 +962,9 @@ static void display_proxy(struct terminal *term, unsigned char *result, unsigned
free(res);
}
-static void display_noproxy_list(struct terminal *term, unsigned char *result, unsigned char *noproxy_list)
+static void
+display_noproxy_list(struct terminal *term, unsigned char *result,
+ unsigned char *noproxy_list)
{
unsigned char *res;
res = display_host_list(term, noproxy_list);
@@ -858,7 +975,8 @@ static void display_noproxy_list(struct terminal *term, unsigned char *result, u
free(res);
}
-int save_proxy(int charset, unsigned char *result, unsigned char *proxy)
+int
+save_proxy(int charset, unsigned char *result, unsigned char *proxy)
{
unsigned char *url, *res;
int sl;
@@ -877,7 +995,8 @@ int save_proxy(int charset, unsigned char *result, unsigned char *proxy)
free(proxy);
- if (parse_url(url, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) {
+ if (parse_url(url, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL)) {
free(url);
result[0] = 0;
return -1;
@@ -892,13 +1011,15 @@ int save_proxy(int charset, unsigned char *result, unsigned char *proxy)
return -1;
}
sl = (int)strlen(cast_const_char res);
- if (sl < 9 || strncmp(cast_const_char res, "proxy://", 8) || res[sl - 1] != '/') {
+ if (sl < 9 || strncmp(cast_const_char res, "proxy://", 8)
+ || res[sl - 1] != '/') {
result[0] = 0;
retval = -1;
} else {
res[sl - 1] = 0;
safe_strncpy(result, res + 8, MAX_STR_LEN);
- retval = strlen(cast_const_char (res + 8)) >= MAX_STR_LEN ? -1 : 0;
+ retval =
+ strlen(cast_const_char(res + 8)) >= MAX_STR_LEN ? -1 : 0;
}
free(res);
@@ -906,12 +1027,16 @@ int save_proxy(int charset, unsigned char *result, unsigned char *proxy)
return retval;
}
-int save_noproxy_list(int charset, unsigned char *result, unsigned char *noproxy_list)
+int
+save_noproxy_list(int charset, unsigned char *result,
+ unsigned char *noproxy_list)
{
unsigned char *res;
noproxy_list = convert(charset, 0, noproxy_list, NULL);
- res = idn_encode_host(noproxy_list, (int)strlen(cast_const_char noproxy_list), cast_uchar ".,", 0);
+ res = idn_encode_host(noproxy_list,
+ (int)strlen(cast_const_char noproxy_list),
+ cast_uchar ".,", 0);
free(noproxy_list);
if (!res) {
result[0] = 0;
@@ -924,35 +1049,43 @@ int save_noproxy_list(int charset, unsigned char *result, unsigned char *noproxy
return retval;
}
-static int check_proxy_noproxy(struct dialog_data *dlg, struct dialog_item_data *di, int (*save)(int, unsigned char *, unsigned char *))
+static int
+check_proxy_noproxy(struct dialog_data *dlg, struct dialog_item_data *di,
+ int (*save)(int, unsigned char *, unsigned char *))
{
unsigned char *result = xmalloc(MAX_STR_LEN);
if (save(term_charset(dlg->win->term), result, di->cdata)) {
free(result);
- msg_box(dlg->win->term, NULL, TEXT_(T_BAD_STRING), AL_CENTER, TEXT_(T_BAD_PROXY_SYNTAX), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ msg_box(dlg->win->term, NULL, TEXT_(T_BAD_STRING), AL_CENTER,
+ TEXT_(T_BAD_PROXY_SYNTAX), MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
return 1;
}
free(result);
return 0;
}
-static int check_proxy(struct dialog_data *dlg, struct dialog_item_data *di)
+static int
+check_proxy(struct dialog_data *dlg, struct dialog_item_data *di)
{
return check_proxy_noproxy(dlg, di, save_proxy);
}
-static int check_noproxy_list(struct dialog_data *dlg, struct dialog_item_data *di)
+static int
+check_noproxy_list(struct dialog_data *dlg, struct dialog_item_data *di)
{
return check_proxy_noproxy(dlg, di, save_noproxy_list);
}
-static int proxy_ok_dialog(struct dialog_data *dlg, struct dialog_item_data *di)
+static int
+proxy_ok_dialog(struct dialog_data *dlg, struct dialog_item_data *di)
{
struct terminal *term = dlg->win->term;
int charset = term_charset(term);
int op = proxies.only_proxies;
int r = ok_dialog(dlg, di);
- if (r) return r;
+ if (r)
+ return r;
save_proxy(charset, proxies.http_proxy, http_proxy);
save_proxy(charset, proxies.https_proxy, https_proxy);
save_proxy(charset, proxies.socks_proxy, socks_proxy);
@@ -962,16 +1095,22 @@ static int proxy_ok_dialog(struct dialog_data *dlg, struct dialog_item_data *di)
/* parsing duplicated in make_connection */
long lp;
char *end;
- unsigned char *p = cast_uchar strchr(cast_const_char proxies.socks_proxy, '@');
- if (!p) p = proxies.socks_proxy;
- else p++;
+ unsigned char *p =
+ cast_uchar strchr(cast_const_char proxies.socks_proxy, '@');
+ if (!p)
+ p = proxies.socks_proxy;
+ else
+ p++;
p = cast_uchar strchr(cast_const_char p, ':');
if (p) {
p++;
lp = strtol(cast_const_char p, &end, 10);
if (!*end && lp == 9050) {
proxies.only_proxies = 1;
- msg_box(term, NULL, TEXT_(T_PROXIES), AL_LEFT, TEXT_(T_TOR_MODE_ENABLED), MSG_BOX_END, NULL, 1, TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
+ msg_box(term, NULL, TEXT_(T_PROXIES), AL_LEFT,
+ TEXT_(T_TOR_MODE_ENABLED), MSG_BOX_END,
+ NULL, 1, TEXT_(T_OK), msg_box_null,
+ B_ENTER | B_ESC);
}
}
}
@@ -983,7 +1122,8 @@ static int proxy_ok_dialog(struct dialog_data *dlg, struct dialog_item_data *di)
return 0;
}
-static void dlg_proxy_options(struct terminal *term, void *xxx, void *yyy)
+static void
+dlg_proxy_options(struct terminal *term, void *xxx, void *yyy)
{
struct dialog *d;
int a = 0;
@@ -991,7 +1131,8 @@ static void dlg_proxy_options(struct terminal *term, void *xxx, void *yyy)
display_proxy(term, https_proxy, proxies.https_proxy);
display_proxy(term, socks_proxy, proxies.socks_proxy);
display_noproxy_list(term, no_proxy, proxies.no_proxy);
- d = mem_calloc(sizeof(struct dialog) + (N_N + 2) * sizeof(struct dialog_item));
+ d = mem_calloc(sizeof(struct dialog)
+ + (N_N + 2) * sizeof(struct dialog_item));
d->title = TEXT_(T_PROXIES);
d->fn = proxy_fn;
d->items[a].type = D_FIELD;
@@ -1038,16 +1179,20 @@ static void dlg_proxy_options(struct terminal *term, void *xxx, void *yyy)
#undef N_N
-static int check_file(struct dialog_data *dlg, struct dialog_item_data *di, int type)
+static int
+check_file(struct dialog_data *dlg, struct dialog_item_data *di, int type)
{
unsigned char *p = di->cdata;
int r;
struct stat st;
links_ssl *ssl;
- if (!p[0]) return 0;
+ if (!p[0])
+ return 0;
EINTRLOOP(r, stat(cast_const_char p, &st));
if (r || !S_ISREG(st.st_mode)) {
- msg_box(dlg->win->term, NULL, TEXT_(T_BAD_FILE), AL_CENTER, TEXT_(T_THE_FILE_DOES_NOT_EXIST), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ msg_box(dlg->win->term, NULL, TEXT_(T_BAD_FILE), AL_CENTER,
+ TEXT_(T_THE_FILE_DOES_NOT_EXIST), MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
return 1;
}
ssl = getSSL();
@@ -1055,32 +1200,38 @@ static int check_file(struct dialog_data *dlg, struct dialog_item_data *di, int
return 0;
#if !defined(OPENSSL_NO_STDIO)
if (!type) {
- r = SSL_use_PrivateKey_file(ssl->ssl, cast_const_char p, SSL_FILETYPE_PEM);
+ r = SSL_use_PrivateKey_file(ssl->ssl, cast_const_char p,
+ SSL_FILETYPE_PEM);
r = r != 1;
} else {
- r = SSL_use_certificate_file(ssl->ssl, cast_const_char p, SSL_FILETYPE_PEM);
+ r = SSL_use_certificate_file(ssl->ssl, cast_const_char p,
+ SSL_FILETYPE_PEM);
r = r != 1;
}
#else
r = 0;
#endif
if (r)
- msg_box(dlg->win->term, NULL, TEXT_(T_BAD_FILE), AL_CENTER, TEXT_(T_THE_FILE_HAS_INVALID_FORMAT), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ msg_box(dlg->win->term, NULL, TEXT_(T_BAD_FILE), AL_CENTER,
+ TEXT_(T_THE_FILE_HAS_INVALID_FORMAT), MSG_BOX_END, NULL,
+ 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
freeSSL(ssl);
return r;
}
-static int check_file_key(struct dialog_data *dlg, struct dialog_item_data *di)
+static int
+check_file_key(struct dialog_data *dlg, struct dialog_item_data *di)
{
return check_file(dlg, di, 0);
}
-static int check_file_crt(struct dialog_data *dlg, struct dialog_item_data *di)
+static int
+check_file_crt(struct dialog_data *dlg, struct dialog_item_data *di)
{
return check_file(dlg, di, 1);
}
-static unsigned char * const ssl_labels[] = {
+static unsigned char *const ssl_labels[] = {
TEXT_(T_ACCEPT_INVALID_CERTIFICATES),
TEXT_(T_WARN_ON_INVALID_CERTIFICATES),
TEXT_(T_REJECT_INVALID_CERTIFICATES),
@@ -1090,14 +1241,17 @@ static unsigned char * const ssl_labels[] = {
NULL
};
-static void ssl_options_fn(struct dialog_data *dlg)
+static void
+ssl_options_fn(struct dialog_data *dlg)
{
struct terminal *term = dlg->win->term;
int max = 0, min = 0;
int w, rw;
int y = 0;
- checkboxes_width(term, dlg->dlg->udata, dlg->n - 4, &max, max_text_width);
- checkboxes_width(term, dlg->dlg->udata, dlg->n - 4, &min, min_text_width);
+ checkboxes_width(term, dlg->dlg->udata, dlg->n - 4, &max,
+ max_text_width);
+ checkboxes_width(term, dlg->dlg->udata, dlg->n - 4, &min,
+ min_text_width);
max_text_width(term, ssl_labels[dlg->n - 4], &max, AL_LEFT);
min_text_width(term, ssl_labels[dlg->n - 4], &min, AL_LEFT);
max_text_width(term, ssl_labels[dlg->n - 3], &max, AL_LEFT);
@@ -1105,44 +1259,65 @@ static void ssl_options_fn(struct dialog_data *dlg)
max_buttons_width(term, dlg->items + dlg->n - 2, 2, &max);
min_buttons_width(term, dlg->items + dlg->n - 2, 2, &min);
w = term->x * 9 / 10 - 2 * DIALOG_LB;
- if (w > max) w = max;
- if (w < min) w = min;
- if (w > term->x - 2 * DIALOG_LB) w = term->x - 2 * DIALOG_LB;
- if (w < 5) w = 5;
+ if (w > max)
+ w = max;
+ if (w < min)
+ w = min;
+ if (w > term->x - 2 * DIALOG_LB)
+ w = term->x - 2 * DIALOG_LB;
+ if (w < 5)
+ w = 5;
rw = 0;
- dlg_format_checkboxes(dlg, NULL, dlg->items, dlg->n - 5, 0, &y, w, &rw, dlg->dlg->udata);
+ dlg_format_checkboxes(dlg, NULL, dlg->items, dlg->n - 5, 0, &y, w, &rw,
+ dlg->dlg->udata);
y++;
- dlg_format_text_and_field(dlg, NULL, ssl_labels[dlg->n - 5], dlg->items + dlg->n - 5, 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, NULL, ssl_labels[dlg->n - 5],
+ dlg->items + dlg->n - 5, 0, &y, w, &rw,
+ COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_text_and_field(dlg, NULL, ssl_labels[dlg->n - 4], dlg->items + dlg->n - 4, 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, NULL, ssl_labels[dlg->n - 4],
+ dlg->items + dlg->n - 4, 0, &y, w, &rw,
+ COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_text_and_field(dlg, NULL, ssl_labels[dlg->n - 3], dlg->items + dlg->n - 3, 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, NULL, ssl_labels[dlg->n - 3],
+ dlg->items + dlg->n - 3, 0, &y, w, &rw,
+ COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 2, 2, 0, &y, w, &rw, AL_CENTER);
+ dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 2, 2, 0, &y, w, &rw,
+ AL_CENTER);
w = rw;
dlg->xw = rw + 2 * DIALOG_LB;
dlg->yw = y + 2 * DIALOG_TB;
center_dlg(dlg);
draw_dlg(dlg);
y = dlg->y + DIALOG_TB + 1;
- dlg_format_checkboxes(dlg, term, dlg->items, dlg->n - 5, dlg->x + DIALOG_LB, &y, w, NULL, dlg->dlg->udata);
+ dlg_format_checkboxes(dlg, term, dlg->items, dlg->n - 5,
+ dlg->x + DIALOG_LB, &y, w, NULL, dlg->dlg->udata);
y++;
- dlg_format_text_and_field(dlg, term, ssl_labels[dlg->n - 5], dlg->items + dlg->n - 5, dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, term, ssl_labels[dlg->n - 5],
+ dlg->items + dlg->n - 5, dlg->x + DIALOG_LB,
+ &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_text_and_field(dlg, term, ssl_labels[dlg->n - 4], dlg->items + dlg->n - 4, dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, term, ssl_labels[dlg->n - 4],
+ dlg->items + dlg->n - 4, dlg->x + DIALOG_LB,
+ &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_text_and_field(dlg, term, ssl_labels[dlg->n - 3], dlg->items + dlg->n - 3, dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, term, ssl_labels[dlg->n - 3],
+ dlg->items + dlg->n - 3, dlg->x + DIALOG_LB,
+ &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_buttons(dlg, term, dlg->items + dlg->n - 2, 2, dlg->x + DIALOG_LB, &y, w, &rw, AL_CENTER);
+ dlg_format_buttons(dlg, term, dlg->items + dlg->n - 2, 2,
+ dlg->x + DIALOG_LB, &y, w, &rw, AL_CENTER);
}
-static void dlg_ssl_options(struct terminal *term, void *xxx, void *yyy)
+static void
+dlg_ssl_options(struct terminal *term, void *xxx, void *yyy)
{
struct dialog *d;
int a = 0;
- const int items = 8
- ;
- d = mem_calloc(sizeof(struct dialog) + items * sizeof(struct dialog_item));
+ const int items = 8;
+ d = mem_calloc(sizeof(struct dialog)
+ + items * sizeof(struct dialog_item));
d->title = TEXT_(T_SSL_OPTIONS);
d->fn = ssl_options_fn;
d->udata = (void *)ssl_labels;
@@ -1193,20 +1368,31 @@ static void dlg_ssl_options(struct terminal *term, void *xxx, void *yyy)
do_dialog(term, d, getml(d, NULL));
}
-static unsigned char * const http_labels[] = { TEXT_(T_USE_HTTP_10), TEXT_(T_ALLOW_SERVER_BLACKLIST), TEXT_(T_DO_NOT_SEND_ACCEPT_CHARSET),
+static unsigned char *const http_labels[] = {
+ TEXT_(T_USE_HTTP_10),
+ TEXT_(T_ALLOW_SERVER_BLACKLIST),
+ TEXT_(T_DO_NOT_SEND_ACCEPT_CHARSET),
TEXT_(T_DO_NOT_ADVERTISE_COMPRESSION_SUPPORT),
- TEXT_(T_RETRY_ON_INTERNAL_ERRORS), NULL };
+ TEXT_(T_RETRY_ON_INTERNAL_ERRORS),
+ NULL
+};
-static unsigned char * const http_header_labels[] = { TEXT_(T_FAKE_FIREFOX), TEXT_(T_FAKE_USERAGENT), TEXT_(T_EXTRA_HEADER), NULL };
+static unsigned char *const http_header_labels[] = { TEXT_(T_FAKE_FIREFOX),
+ TEXT_(T_FAKE_USERAGENT),
+ TEXT_(T_EXTRA_HEADER),
+ NULL };
-static void httpheadopt_fn(struct dialog_data *dlg)
+static void
+httpheadopt_fn(struct dialog_data *dlg)
{
struct terminal *term = dlg->win->term;
int max = 0, min = 0;
int w, rw;
int y = 0;
- checkboxes_width(term, dlg->dlg->udata, dlg->n - 5, &max, max_text_width);
- checkboxes_width(term, dlg->dlg->udata, dlg->n - 5, &min, min_text_width);
+ checkboxes_width(term, dlg->dlg->udata, dlg->n - 5, &max,
+ max_text_width);
+ checkboxes_width(term, dlg->dlg->udata, dlg->n - 5, &min,
+ min_text_width);
max_text_width(term, http_header_labels[dlg->n - 5], &max, AL_LEFT);
min_text_width(term, http_header_labels[dlg->n - 5], &min, AL_LEFT);
max_text_width(term, http_header_labels[dlg->n - 4], &max, AL_LEFT);
@@ -1216,40 +1402,62 @@ static void httpheadopt_fn(struct dialog_data *dlg)
max_buttons_width(term, dlg->items + dlg->n - 2, 2, &max);
min_buttons_width(term, dlg->items + dlg->n - 2, 2, &min);
w = term->x * 9 / 10 - 2 * DIALOG_LB;
- if (w > max) w = max;
- if (w < min) w = min;
- if (w > term->x - 2 * DIALOG_LB) w = term->x - 2 * DIALOG_LB;
- if (w < 5) w = 5;
+ if (w > max)
+ w = max;
+ if (w < min)
+ w = min;
+ if (w > term->x - 2 * DIALOG_LB)
+ w = term->x - 2 * DIALOG_LB;
+ if (w < 5)
+ w = 5;
rw = 0;
- dlg_format_checkboxes(dlg, NULL, dlg->items, dlg->n - 5, 0, &y, w, &rw, dlg->dlg->udata);
+ dlg_format_checkboxes(dlg, NULL, dlg->items, dlg->n - 5, 0, &y, w, &rw,
+ dlg->dlg->udata);
y++;
- dlg_format_text_and_field(dlg, NULL, http_header_labels[dlg->n - 5], dlg->items + dlg->n - 5, 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, NULL, http_header_labels[dlg->n - 5],
+ dlg->items + dlg->n - 5, 0, &y, w, &rw,
+ COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_text_and_field(dlg, NULL, http_header_labels[dlg->n - 4], dlg->items + dlg->n - 4, 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, NULL, http_header_labels[dlg->n - 4],
+ dlg->items + dlg->n - 4, 0, &y, w, &rw,
+ COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_text_and_field(dlg, NULL, http_header_labels[dlg->n - 3], dlg->items + dlg->n - 3, 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, NULL, http_header_labels[dlg->n - 3],
+ dlg->items + dlg->n - 3, 0, &y, w, &rw,
+ COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 2, 2, 0, &y, w, &rw, AL_CENTER);
+ dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 2, 2, 0, &y, w, &rw,
+ AL_CENTER);
w = rw;
dlg->xw = rw + 2 * DIALOG_LB;
dlg->yw = y + 2 * DIALOG_TB;
center_dlg(dlg);
draw_dlg(dlg);
y = dlg->y + DIALOG_TB + 1;
- dlg_format_checkboxes(dlg, term, dlg->items, dlg->n - 5, dlg->x + DIALOG_LB, &y, w, NULL, dlg->dlg->udata);
+ dlg_format_checkboxes(dlg, term, dlg->items, dlg->n - 5,
+ dlg->x + DIALOG_LB, &y, w, NULL, dlg->dlg->udata);
y++;
- dlg_format_text_and_field(dlg, term, http_header_labels[dlg->n - 5], dlg->items + dlg->n - 5, dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, term, http_header_labels[dlg->n - 5],
+ dlg->items + dlg->n - 5, dlg->x + DIALOG_LB,
+ &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_text_and_field(dlg, term, http_header_labels[dlg->n - 4], dlg->items + dlg->n - 4, dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, term, http_header_labels[dlg->n - 4],
+ dlg->items + dlg->n - 4, dlg->x + DIALOG_LB,
+ &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_text_and_field(dlg, term, http_header_labels[dlg->n - 3], dlg->items + dlg->n - 3, dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, term, http_header_labels[dlg->n - 3],
+ dlg->items + dlg->n - 3, dlg->x + DIALOG_LB,
+ &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_buttons(dlg, term, dlg->items + dlg->n - 2, 2, dlg->x + DIALOG_LB, &y, w, &rw, AL_CENTER);
+ dlg_format_buttons(dlg, term, dlg->items + dlg->n - 2, 2,
+ dlg->x + DIALOG_LB, &y, w, &rw, AL_CENTER);
}
-static int dlg_http_header_options(struct dialog_data *dlg, struct dialog_item_data *di)
+static int
+dlg_http_header_options(struct dialog_data *dlg, struct dialog_item_data *di)
{
- struct http_header_options *header = (struct http_header_options *)di->cdata;
+ struct http_header_options *header =
+ (struct http_header_options *)di->cdata;
struct dialog *d;
d = mem_calloc(sizeof(struct dialog) + 12 * sizeof(struct dialog_item));
d->title = TEXT_(T_HTTP_HEADER_OPTIONS);
@@ -1278,7 +1486,8 @@ static int dlg_http_header_options(struct dialog_data *dlg, struct dialog_item_d
return 0;
}
-static void dlg_http_options(struct terminal *term, void *xxx, void *yyy)
+static void
+dlg_http_options(struct terminal *term, void *xxx, void *yyy)
{
struct dialog *d;
int a = 0;
@@ -1337,23 +1546,28 @@ static void dlg_http_options(struct terminal *term, void *xxx, void *yyy)
static unsigned char mc_str[8];
static unsigned char doc_str[4];
-static void cache_refresh(void *xxx)
+static void
+cache_refresh(void *xxx)
{
memory_cache_size = atoi(cast_const_char mc_str) * 1024;
max_format_cache_entries = atoi(cast_const_char doc_str);
shrink_memory(SH_CHECK_QUOTA);
}
-static unsigned char * const cache_texts[] = { TEXT_(T_MEMORY_CACHE_SIZE__KB), TEXT_(T_NUMBER_OF_FORMATTED_DOCUMENTS), TEXT_(T_AGGRESSIVE_CACHE) };
+static unsigned char *const cache_texts[] = {
+ TEXT_(T_MEMORY_CACHE_SIZE__KB), TEXT_(T_NUMBER_OF_FORMATTED_DOCUMENTS),
+ TEXT_(T_AGGRESSIVE_CACHE)
+};
-static void cache_opt(struct terminal *term, void *xxx, void *yyy)
+static void
+cache_opt(struct terminal *term, void *xxx, void *yyy)
{
struct dialog *d;
int a;
snprint(mc_str, 8, memory_cache_size / 1024);
snprint(doc_str, 4, max_format_cache_entries);
d = mem_calloc(sizeof(struct dialog) + 5 * sizeof(struct dialog_item));
- a=0;
+ a = 0;
d->title = TEXT_(T_CACHE_OPTIONS);
d->fn = group_fn;
d->udata = (void *)cache_texts;
@@ -1391,17 +1605,20 @@ static void cache_opt(struct terminal *term, void *xxx, void *yyy)
do_dialog(term, d, getml(d, NULL));
}
-static void menu_kill_background_connections(struct terminal *term, void *xxx, void *yyy)
+static void
+menu_kill_background_connections(struct terminal *term, void *xxx, void *yyy)
{
abort_background_connections();
}
-static void menu_kill_all_connections(struct terminal *term, void *xxx, void *yyy)
+static void
+menu_kill_all_connections(struct terminal *term, void *xxx, void *yyy)
{
abort_all_connections();
}
-static void menu_save_html_options(struct terminal *term, void *xxx, void *ses_)
+static void
+menu_save_html_options(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = (struct session *)ses_;
memcpy(&dds, &ses->ds, sizeof(struct document_setup));
@@ -1410,20 +1627,22 @@ static void menu_save_html_options(struct terminal *term, void *xxx, void *ses_)
static unsigned char marg_str[2];
-static void session_refresh(struct session *ses)
+static void
+session_refresh(struct session *ses)
{
html_interpret_recursive(ses->screen);
draw_formatted(ses);
}
-static void html_refresh(void *ses_)
+static void
+html_refresh(void *ses_)
{
struct session *ses = (struct session *)ses_;
ses->ds.margin = atoi(cast_const_char marg_str);
session_refresh(ses);
}
-static unsigned char * const html_texts[] = {
+static unsigned char *const html_texts[] = {
TEXT_(T_DISPLAY_TABLES),
TEXT_(T_DISPLAY_FRAMES),
TEXT_(T_BREAK_LONG_LINES),
@@ -1438,12 +1657,14 @@ static unsigned char * const html_texts[] = {
TEXT_(T_IGNORE_CHARSET_INFO_SENT_BY_SERVER)
};
-static int dlg_assume_cp(struct dialog_data *dlg, struct dialog_item_data *di)
+static int
+dlg_assume_cp(struct dialog_data *dlg, struct dialog_item_data *di)
{
return 0;
}
-void dialog_html_options(struct session *ses)
+void
+dialog_html_options(struct session *ses)
{
struct dialog *d;
int a;
@@ -1456,41 +1677,41 @@ void dialog_html_options(struct session *ses)
d->udata2 = ses;
d->refresh = html_refresh;
d->refresh_data = ses;
- a=0;
+ a = 0;
d->items[a].type = D_CHECKBOX;
- d->items[a].data = (unsigned char *) &ses->ds.tables;
+ d->items[a].data = (unsigned char *)&ses->ds.tables;
d->items[a].dlen = sizeof(int);
a++;
d->items[a].type = D_CHECKBOX;
- d->items[a].data = (unsigned char *) &ses->ds.frames;
+ d->items[a].data = (unsigned char *)&ses->ds.frames;
d->items[a].dlen = sizeof(int);
a++;
d->items[a].type = D_CHECKBOX;
- d->items[a].data = (unsigned char *) &ses->ds.break_long_lines;
+ d->items[a].data = (unsigned char *)&ses->ds.break_long_lines;
d->items[a].dlen = sizeof(int);
a++;
d->items[a].type = D_CHECKBOX;
- d->items[a].data = (unsigned char *) &ses->ds.images;
+ d->items[a].data = (unsigned char *)&ses->ds.images;
d->items[a].dlen = sizeof(int);
a++;
d->items[a].type = D_CHECKBOX;
- d->items[a].data = (unsigned char *) &ses->ds.image_names;
+ d->items[a].data = (unsigned char *)&ses->ds.image_names;
d->items[a].dlen = sizeof(int);
a++;
d->items[a].type = D_CHECKBOX;
- d->items[a].data = (unsigned char *) &ses->ds.table_order;
+ d->items[a].data = (unsigned char *)&ses->ds.table_order;
d->items[a].dlen = sizeof(int);
a++;
d->items[a].type = D_CHECKBOX;
- d->items[a].data = (unsigned char *) &ses->ds.num_links;
+ d->items[a].data = (unsigned char *)&ses->ds.num_links;
d->items[a].dlen = sizeof(int);
a++;
d->items[a].type = D_CHECKBOX;
- d->items[a].data = (unsigned char *) &ses->ds.auto_refresh;
+ d->items[a].data = (unsigned char *)&ses->ds.auto_refresh;
d->items[a].dlen = sizeof(int);
a++;
d->items[a].type = D_CHECKBOX;
- d->items[a].data = (unsigned char *) &ses->ds.target_in_new_window;
+ d->items[a].data = (unsigned char *)&ses->ds.target_in_new_window;
d->items[a].dlen = sizeof(int);
a++;
d->items[a].type = D_FIELD;
@@ -1504,11 +1725,11 @@ void dialog_html_options(struct session *ses)
d->items[a].gid = 0;
d->items[a].fn = dlg_assume_cp;
d->items[a].text = TEXT_(T_DEFAULT_CODEPAGE);
- d->items[a].data = (unsigned char *) &ses->ds.assume_cp;
+ d->items[a].data = (unsigned char *)&ses->ds.assume_cp;
d->items[a].dlen = sizeof(int);
a++;
d->items[a].type = D_CHECKBOX;
- d->items[a].data = (unsigned char *) &ses->ds.hard_assume;
+ d->items[a].data = (unsigned char *)&ses->ds.hard_assume;
d->items[a].dlen = sizeof(int);
a++;
d->items[a].type = D_BUTTON;
@@ -1525,45 +1746,55 @@ void dialog_html_options(struct session *ses)
do_dialog(ses->term, d, getml(d, NULL));
}
-static void menu_html_options(struct terminal *term, void *xxx, void *ses_)
+static void
+menu_html_options(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = (struct session *)ses_;
dialog_html_options(ses);
}
-static unsigned char * const color_texts[] = { cast_uchar "", cast_uchar "", cast_uchar "", TEXT_(T_IGNORE_DOCUMENT_COLOR) };
+static unsigned char *const color_texts[] = { cast_uchar "", cast_uchar "",
+ cast_uchar "",
+ TEXT_(T_IGNORE_DOCUMENT_COLOR) };
-static void html_color_refresh(void *ses_)
+static void
+html_color_refresh(void *ses_)
{
struct session *ses = (struct session *)ses_;
html_interpret_recursive(ses->screen);
draw_formatted(ses);
}
-static void select_color(struct terminal *term, int n, int *ptr)
+static void
+select_color(struct terminal *term, int n, int *ptr)
{
int i;
struct menu_item *mi;
mi = new_menu(MENU_FREE_ITEMS);
for (i = 0; i < n; i++) {
- add_to_menu(&mi, TEXT_(T_COLOR_0 + i), cast_uchar "", cast_uchar "", set_val, (void *)(unsigned long)i, 0, i);
+ add_to_menu(&mi, TEXT_(T_COLOR_0 + i), cast_uchar "",
+ cast_uchar "", set_val, (void *)(unsigned long)i, 0,
+ i);
}
do_menu_selected(term, mi, ptr, *ptr, NULL, NULL);
}
-static int select_color_8(struct dialog_data *dlg, struct dialog_item_data *di)
+static int
+select_color_8(struct dialog_data *dlg, struct dialog_item_data *di)
{
select_color(dlg->win->term, 8, (int *)di->cdata);
return 0;
}
-static int select_color_16(struct dialog_data *dlg, struct dialog_item_data *di)
+static int
+select_color_16(struct dialog_data *dlg, struct dialog_item_data *di)
{
select_color(dlg->win->term, 16, (int *)di->cdata);
return 0;
}
-static void menu_color(struct terminal *term, void *xxx, void *ses_)
+static void
+menu_color(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = (struct session *)ses_;
struct dialog *d;
@@ -1619,62 +1850,81 @@ static void menu_color(struct terminal *term, void *xxx, void *ses_)
static unsigned char new_bookmarks_file[MAX_STR_LEN];
static int new_bookmarks_codepage = 0;
-static void refresh_misc(void *ses_)
+static void
+refresh_misc(void *ses_)
{
struct session *ses = (struct session *)ses_;
if (strcmp((char *)new_bookmarks_file, (char *)bookmarks_file))
reinit_bookmarks(ses, new_bookmarks_file);
}
-static unsigned char * const miscopt_labels[] = { TEXT_(T_BOOKMARKS_FILE), NULL };
-static unsigned char * const miscopt_checkbox_labels[] = { TEXT_(T_SAVE_URL_HISTORY_ON_EXIT), NULL };
+static unsigned char *const miscopt_labels[] = { TEXT_(T_BOOKMARKS_FILE),
+ NULL };
+static unsigned char *const miscopt_checkbox_labels[] = {
+ TEXT_(T_SAVE_URL_HISTORY_ON_EXIT), NULL
+};
-static void miscopt_fn(struct dialog_data *dlg)
+static void
+miscopt_fn(struct dialog_data *dlg)
{
struct terminal *term = dlg->win->term;
- unsigned char **labels=dlg->dlg->udata;
+ unsigned char **labels = dlg->dlg->udata;
int max = 0, min = 0;
int w, rw;
int y = 0;
- int a=0;
- int bmk=!anonymous;
+ int a = 0;
+ int bmk = !anonymous;
max_text_width(term, labels[0], &max, AL_LEFT);
min_text_width(term, labels[0], &min, AL_LEFT);
- if (bmk)
- {
- max_buttons_width(term, dlg->items + dlg->n - 3 - a - bmk, 1, &max);
- min_buttons_width(term, dlg->items + dlg->n - 3 - a - bmk, 1, &min);
+ if (bmk) {
+ max_buttons_width(term, dlg->items + dlg->n - 3 - a - bmk, 1,
+ &max);
+ min_buttons_width(term, dlg->items + dlg->n - 3 - a - bmk, 1,
+ &min);
}
- if (a)
- {
+ if (a) {
max_buttons_width(term, dlg->items + dlg->n - 3 - bmk, 1, &max);
min_buttons_width(term, dlg->items + dlg->n - 3 - bmk, 1, &min);
}
if (bmk) {
- checkboxes_width(term, miscopt_checkbox_labels, 1, &max, max_text_width);
- checkboxes_width(term, miscopt_checkbox_labels, 1, &min, min_text_width);
+ checkboxes_width(term, miscopt_checkbox_labels, 1, &max,
+ max_text_width);
+ checkboxes_width(term, miscopt_checkbox_labels, 1, &min,
+ min_text_width);
}
max_buttons_width(term, dlg->items + dlg->n - 2, 2, &max);
min_buttons_width(term, dlg->items + dlg->n - 2, 2, &min);
w = term->x * 9 / 10 - 2 * DIALOG_LB;
- if (w > max) w = max;
- if (w < min) w = min;
- if (w > term->x - 2 * DIALOG_LB) w = term->x - 2 * DIALOG_LB;
- if (w < 5) w = 5;
+ if (w > max)
+ w = max;
+ if (w < min)
+ w = min;
+ if (w > term->x - 2 * DIALOG_LB)
+ w = term->x - 2 * DIALOG_LB;
+ if (w < 5)
+ w = 5;
rw = 0;
if (bmk) {
- dlg_format_text_and_field(dlg, NULL, labels[0], dlg->items + dlg->n - 4 - a - bmk, 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(
+ dlg, NULL, labels[0], dlg->items + dlg->n - 4 - a - bmk, 0,
+ &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
y++;
}
if (bmk) {
y++;
- dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 3 - a - bmk, 1, 0, &y, w, &rw, AL_LEFT);
+ dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 3 - a - bmk,
+ 1, 0, &y, w, &rw, AL_LEFT);
}
- if (a) dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 3 - bmk, 1, 0, &y, w, &rw, AL_LEFT);
- if (bmk) dlg_format_checkboxes(dlg, NULL, dlg->items + dlg->n - 3, 1, 0, &y, w, &rw, miscopt_checkbox_labels);
- dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 2, 2, 0, &y, w, &rw, AL_CENTER);
+ if (a)
+ dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 3 - bmk, 1,
+ 0, &y, w, &rw, AL_LEFT);
+ if (bmk)
+ dlg_format_checkboxes(dlg, NULL, dlg->items + dlg->n - 3, 1, 0,
+ &y, w, &rw, miscopt_checkbox_labels);
+ dlg_format_buttons(dlg, NULL, dlg->items + dlg->n - 2, 2, 0, &y, w, &rw,
+ AL_CENTER);
w = rw;
dlg->xw = w + 2 * DIALOG_LB;
dlg->yw = y + 2 * DIALOG_TB;
@@ -1683,35 +1933,47 @@ static void miscopt_fn(struct dialog_data *dlg)
y = dlg->y + DIALOG_TB;
y++;
if (bmk) {
- dlg_format_text_and_field(dlg, term, labels[0], dlg->items + dlg->n - 4 - a - bmk, dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, term, labels[0],
+ dlg->items + dlg->n - 4 - a - bmk,
+ dlg->x + DIALOG_LB, &y, w, NULL,
+ COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_buttons(dlg, term, dlg->items + dlg->n - 3 - a - bmk, 1, dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);
+ dlg_format_buttons(dlg, term, dlg->items + dlg->n - 3 - a - bmk,
+ 1, dlg->x + DIALOG_LB, &y, w, NULL,
+ AL_CENTER);
}
- if (a) dlg_format_buttons(dlg, term, dlg->items + dlg->n - 3 - bmk, 1, dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);
+ if (a)
+ dlg_format_buttons(dlg, term, dlg->items + dlg->n - 3 - bmk, 1,
+ dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);
if (bmk) {
- dlg_format_checkboxes(dlg, term, dlg->items + dlg->n - 3, 1, dlg->x + DIALOG_LB, &y, w, NULL, miscopt_checkbox_labels);
+ dlg_format_checkboxes(dlg, term, dlg->items + dlg->n - 3, 1,
+ dlg->x + DIALOG_LB, &y, w, NULL,
+ miscopt_checkbox_labels);
y++;
}
- dlg_format_buttons(dlg, term, dlg->items+dlg->n-2, 2, dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);
+ dlg_format_buttons(dlg, term, dlg->items + dlg->n - 2, 2,
+ dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);
}
-
-static void miscelaneous_options(struct terminal *term, void *xxx, void *ses_)
+static void
+miscelaneous_options(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = (struct session *)ses_;
struct dialog *d;
- int a=0;
+ int a = 0;
- /* if you add something into text mode (or both text and graphics), remove this (and enable also miscelaneous_options in do_setup_menu) */
+ /* if you add something into text mode (or both text and graphics),
+ * remove this (and enable also miscelaneous_options in do_setup_menu)
+ */
if (anonymous)
return;
- safe_strncpy(new_bookmarks_file,bookmarks_file,MAX_STR_LEN);
+ safe_strncpy(new_bookmarks_file, bookmarks_file, MAX_STR_LEN);
d = mem_calloc(sizeof(struct dialog) + 5 * sizeof(struct dialog_item));
d->title = TEXT_(T_MISCELANEOUS_OPTIONS);
d->refresh = refresh_misc;
d->refresh_data = ses;
- d->fn=miscopt_fn;
+ d->fn = miscopt_fn;
d->udata = (void *)miscopt_labels;
d->udata2 = ses;
if (!anonymous) {
@@ -1723,7 +1985,7 @@ static void miscelaneous_options(struct terminal *term, void *xxx, void *ses_)
d->items[a].gid = 0;
d->items[a].fn = dlg_assume_cp;
d->items[a].text = TEXT_(T_BOOKMARKS_ENCODING);
- d->items[a].data = (unsigned char *) &new_bookmarks_codepage;
+ d->items[a].data = (unsigned char *)&new_bookmarks_codepage;
d->items[a].dlen = sizeof(int);
a++;
}
@@ -1749,46 +2011,67 @@ static void miscelaneous_options(struct terminal *term, void *xxx, void *ses_)
}
static const struct menu_item file_menu11[] = {
- { TEXT_(T_GOTO_URL), cast_uchar "g", TEXT_(T_HK_GOTO_URL), menu_goto_url, NULL, 0, 1 },
- { TEXT_(T_GO_BACK), cast_uchar "z", TEXT_(T_HK_GO_BACK), menu_go_back, NULL, 0, 1 },
- { TEXT_(T_GO_FORWARD), cast_uchar "x", TEXT_(T_HK_GO_FORWARD), menu_go_forward, NULL, 0, 1 },
- { TEXT_(T_HISTORY), cast_uchar ">", TEXT_(T_HK_HISTORY), history_menu, NULL, 1, 1 },
- { TEXT_(T_RELOAD), cast_uchar "Ctrl-R", TEXT_(T_HK_RELOAD), menu_reload, NULL, 0, 1 },
+ {TEXT_(T_GOTO_URL), cast_uchar "g", TEXT_(T_HK_GOTO_URL),
+ menu_goto_url, NULL, 0, 1},
+ { TEXT_(T_GO_BACK), cast_uchar "z", TEXT_(T_HK_GO_BACK), menu_go_back,
+ NULL, 0, 1},
+ { TEXT_(T_GO_FORWARD), cast_uchar "x", TEXT_(T_HK_GO_FORWARD),
+ menu_go_forward, NULL, 0, 1},
+ { TEXT_(T_HISTORY), cast_uchar ">", TEXT_(T_HK_HISTORY), history_menu,
+ NULL, 1, 1},
+ { TEXT_(T_RELOAD), cast_uchar "Ctrl-R", TEXT_(T_HK_RELOAD), menu_reload,
+ NULL, 0, 1},
};
static const struct menu_item file_menu12[] = {
- { TEXT_(T_BOOKMARKS), cast_uchar "s", TEXT_(T_HK_BOOKMARKS), menu_bookmark_manager, NULL, 0, 1 },
+ {TEXT_(T_BOOKMARKS), cast_uchar "s", TEXT_(T_HK_BOOKMARKS),
+ menu_bookmark_manager, NULL, 0, 1},
};
static const struct menu_item file_menu21[] = {
- { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 1 },
- { TEXT_(T_SAVE_AS), cast_uchar "", TEXT_(T_HK_SAVE_AS), save_as, NULL, 0, 1 },
- { TEXT_(T_SAVE_URL_AS), cast_uchar "", TEXT_(T_HK_SAVE_URL_AS), menu_save_url_as, NULL, 0, 1 },
- { TEXT_(T_SAVE_FORMATTED_DOCUMENT), cast_uchar "", TEXT_(T_HK_SAVE_FORMATTED_DOCUMENT), menu_save_formatted, NULL, 0, 1 },
+ {cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 1},
+ { TEXT_(T_SAVE_AS), cast_uchar "", TEXT_(T_HK_SAVE_AS), save_as, NULL,
+ 0, 1},
+ { TEXT_(T_SAVE_URL_AS), cast_uchar "", TEXT_(T_HK_SAVE_URL_AS),
+ menu_save_url_as, NULL, 0, 1},
+ { TEXT_(T_SAVE_FORMATTED_DOCUMENT), cast_uchar "",
+ TEXT_(T_HK_SAVE_FORMATTED_DOCUMENT), menu_save_formatted, NULL, 0,
+ 1 },
};
static const struct menu_item file_menu22[] = {
- { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 1},
- { TEXT_(T_KILL_BACKGROUND_CONNECTIONS), cast_uchar "", TEXT_(T_HK_KILL_BACKGROUND_CONNECTIONS), menu_kill_background_connections, NULL, 0, 1 },
- { TEXT_(T_KILL_ALL_CONNECTIONS), cast_uchar "", TEXT_(T_HK_KILL_ALL_CONNECTIONS), menu_kill_all_connections, NULL, 0, 1 },
- { TEXT_(T_FLUSH_ALL_CACHES), cast_uchar "", TEXT_(T_HK_FLUSH_ALL_CACHES), flush_caches, NULL, 0, 1 },
- { TEXT_(T_RESOURCE_INFO), cast_uchar "", TEXT_(T_HK_RESOURCE_INFO), resource_info_menu, NULL, 0, 1 },
- { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 1 },
+ {cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 1},
+ { TEXT_(T_KILL_BACKGROUND_CONNECTIONS), cast_uchar "",
+ TEXT_(T_HK_KILL_BACKGROUND_CONNECTIONS),
+ menu_kill_background_connections, NULL, 0, 1},
+ { TEXT_(T_KILL_ALL_CONNECTIONS), cast_uchar "",
+ TEXT_(T_HK_KILL_ALL_CONNECTIONS), menu_kill_all_connections, NULL, 0,
+ 1 },
+ { TEXT_(T_FLUSH_ALL_CACHES), cast_uchar "",
+ TEXT_(T_HK_FLUSH_ALL_CACHES), flush_caches, NULL, 0, 1},
+ { TEXT_(T_RESOURCE_INFO), cast_uchar "", TEXT_(T_HK_RESOURCE_INFO),
+ resource_info_menu, NULL, 0, 1},
+ { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 1},
};
static const struct menu_item file_menu3[] = {
- { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 1 },
- { TEXT_(T_EXIT), cast_uchar "q", TEXT_(T_HK_EXIT), exit_prog, NULL, 0, 1 },
- { NULL, NULL, 0, NULL, NULL, 0, 0 }
+ {cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 1},
+ { TEXT_(T_EXIT), cast_uchar "q", TEXT_(T_HK_EXIT), exit_prog, NULL, 0,
+ 1 },
+ { NULL, NULL, 0, NULL, NULL, 0, 0}
};
-static void do_file_menu(struct terminal *term, void *xxx, void *ses_)
+static void
+do_file_menu(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = (struct session *)ses_;
int x;
int o;
struct menu_item *file_menu, *e;
- file_menu = xmalloc(sizeof(file_menu11) + sizeof(file_menu12) + sizeof(file_menu21) + sizeof(file_menu22) + sizeof(file_menu3) + 3 * sizeof(struct menu_item));
+ file_menu =
+ xmalloc(sizeof(file_menu11) + sizeof(file_menu12)
+ + sizeof(file_menu21) + sizeof(file_menu22)
+ + sizeof(file_menu3) + 3 * sizeof(struct menu_item));
e = file_menu;
memcpy(e, file_menu11, sizeof(file_menu11));
e += sizeof(file_menu11) / sizeof(struct menu_item);
@@ -1813,118 +2096,187 @@ static void do_file_menu(struct terminal *term, void *xxx, void *ses_)
memcpy(e, file_menu22, sizeof(file_menu22));
e += sizeof(file_menu22) / sizeof(struct menu_item);
x = 1;
- memcpy(e, file_menu3 + x, sizeof(file_menu3) - x * sizeof(struct menu_item));
+ memcpy(e, file_menu3 + x,
+ sizeof(file_menu3) - x * sizeof(struct menu_item));
do_menu(term, file_menu, ses);
}
-static void (* const search_dlg_ptr)(struct session *ses, struct f_data_c *f, int a) = search_dlg;
-static void (* const search_back_dlg_ptr)(struct session *ses, struct f_data_c *f, int a) = search_back_dlg;
-static void (* const find_next_ptr)(struct session *ses, struct f_data_c *f, int a) = find_next;
-static void (* const find_next_back_ptr)(struct session *ses, struct f_data_c *f, int a) = find_next_back;
-static void (* const set_frame_ptr)(struct session *ses, struct f_data_c *f, int a) = set_frame;
+static void (*const search_dlg_ptr)(struct session *ses, struct f_data_c *f,
+ int a) = search_dlg;
+static void (*const search_back_dlg_ptr)(struct session *ses,
+ struct f_data_c *f,
+ int a) = search_back_dlg;
+static void (*const find_next_ptr)(struct session *ses, struct f_data_c *f,
+ int a) = find_next;
+static void (*const find_next_back_ptr)(struct session *ses, struct f_data_c *f,
+ int a) = find_next_back;
+static void (*const set_frame_ptr)(struct session *ses, struct f_data_c *f,
+ int a) = set_frame;
static const struct menu_item view_menu[] = {
- { TEXT_(T_SEARCH), cast_uchar "/", TEXT_(T_HK_SEARCH), menu_for_frame, (void *)&search_dlg_ptr, 0, 0 },
- { TEXT_(T_SEARCH_BACK), cast_uchar "?", TEXT_(T_HK_SEARCH_BACK), menu_for_frame, (void *)&search_back_dlg_ptr, 0, 0 },
- { TEXT_(T_FIND_NEXT), cast_uchar "n", TEXT_(T_HK_FIND_NEXT), menu_for_frame, (void *)&find_next_ptr, 0, 0 },
- { TEXT_(T_FIND_PREVIOUS), cast_uchar "N", TEXT_(T_HK_FIND_PREVIOUS), menu_for_frame, (void *)&find_next_back_ptr, 0, 0 },
- { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0 },
- { TEXT_(T_TOGGLE_HTML_PLAIN), cast_uchar "\\", TEXT_(T_HK_TOGGLE_HTML_PLAIN), menu_toggle, NULL, 0, 0 },
- { TEXT_(T_DOCUMENT_INFO), cast_uchar "=", TEXT_(T_HK_DOCUMENT_INFO), menu_doc_info, NULL, 0, 0 },
- { TEXT_(T_HEADER_INFO), cast_uchar "|", TEXT_(T_HK_HEADER_INFO), menu_head_info, NULL, 0, 0 },
- { TEXT_(T_FRAME_AT_FULL_SCREEN), cast_uchar "f", TEXT_(T_HK_FRAME_AT_FULL_SCREEN), menu_for_frame, (void *)&set_frame_ptr, 0, 0 },
- { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0 },
- { TEXT_(T_HTML_OPTIONS), cast_uchar "", TEXT_(T_HK_HTML_OPTIONS), menu_html_options, NULL, 0, 0 },
- { TEXT_(T_SAVE_HTML_OPTIONS), cast_uchar "", TEXT_(T_HK_SAVE_HTML_OPTIONS), menu_save_html_options, NULL, 0, 0 },
- { NULL, NULL, 0, NULL, NULL, 0, 0 }
+ {TEXT_(T_SEARCH), cast_uchar "/", TEXT_(T_HK_SEARCH), menu_for_frame,
+ (void *)&search_dlg_ptr, 0, 0},
+ { TEXT_(T_SEARCH_BACK), cast_uchar "?", TEXT_(T_HK_SEARCH_BACK),
+ menu_for_frame, (void *)&search_back_dlg_ptr, 0, 0},
+ { TEXT_(T_FIND_NEXT), cast_uchar "n", TEXT_(T_HK_FIND_NEXT),
+ menu_for_frame, (void *)&find_next_ptr, 0, 0},
+ { TEXT_(T_FIND_PREVIOUS), cast_uchar "N", TEXT_(T_HK_FIND_PREVIOUS),
+ menu_for_frame, (void *)&find_next_back_ptr, 0, 0},
+ { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0},
+ { TEXT_(T_TOGGLE_HTML_PLAIN), cast_uchar "\\",
+ TEXT_(T_HK_TOGGLE_HTML_PLAIN), menu_toggle, NULL, 0, 0},
+ { TEXT_(T_DOCUMENT_INFO), cast_uchar "=", TEXT_(T_HK_DOCUMENT_INFO),
+ menu_doc_info, NULL, 0, 0},
+ { TEXT_(T_HEADER_INFO), cast_uchar "|", TEXT_(T_HK_HEADER_INFO),
+ menu_head_info, NULL, 0, 0},
+ { TEXT_(T_FRAME_AT_FULL_SCREEN), cast_uchar "f",
+ TEXT_(T_HK_FRAME_AT_FULL_SCREEN), menu_for_frame,
+ (void *)&set_frame_ptr, 0, 0},
+ { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0},
+ { TEXT_(T_HTML_OPTIONS), cast_uchar "", TEXT_(T_HK_HTML_OPTIONS),
+ menu_html_options, NULL, 0, 0},
+ { TEXT_(T_SAVE_HTML_OPTIONS), cast_uchar "",
+ TEXT_(T_HK_SAVE_HTML_OPTIONS), menu_save_html_options, NULL, 0, 0},
+ { NULL, NULL, 0, NULL, NULL, 0, 0}
};
static const struct menu_item view_menu_anon[] = {
- { TEXT_(T_SEARCH), cast_uchar "/", TEXT_(T_HK_SEARCH), menu_for_frame, (void *)&search_dlg_ptr, 0, 0 },
- { TEXT_(T_SEARCH_BACK), cast_uchar "?", TEXT_(T_HK_SEARCH_BACK), menu_for_frame, (void *)&search_back_dlg_ptr, 0, 0 },
- { TEXT_(T_FIND_NEXT), cast_uchar "n", TEXT_(T_HK_FIND_NEXT), menu_for_frame, (void *)&find_next_ptr, 0, 0 },
- { TEXT_(T_FIND_PREVIOUS), cast_uchar "N", TEXT_(T_HK_FIND_PREVIOUS), menu_for_frame, (void *)&find_next_back_ptr, 0, 0 },
- { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0 },
- { TEXT_(T_TOGGLE_HTML_PLAIN), cast_uchar "\\", TEXT_(T_HK_TOGGLE_HTML_PLAIN), menu_toggle, NULL, 0, 0 },
- { TEXT_(T_DOCUMENT_INFO), cast_uchar "=", TEXT_(T_HK_DOCUMENT_INFO), menu_doc_info, NULL, 0, 0 },
- { TEXT_(T_FRAME_AT_FULL_SCREEN), cast_uchar "f", TEXT_(T_HK_FRAME_AT_FULL_SCREEN), menu_for_frame, (void *)&set_frame_ptr, 0, 0 },
- { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0 },
- { TEXT_(T_HTML_OPTIONS), cast_uchar "", TEXT_(T_HK_HTML_OPTIONS), menu_html_options, NULL, 0, 0 },
- { NULL, NULL, 0, NULL, NULL, 0, 0 }
+ {TEXT_(T_SEARCH), cast_uchar "/", TEXT_(T_HK_SEARCH), menu_for_frame,
+ (void *)&search_dlg_ptr, 0, 0},
+ { TEXT_(T_SEARCH_BACK), cast_uchar "?", TEXT_(T_HK_SEARCH_BACK),
+ menu_for_frame, (void *)&search_back_dlg_ptr, 0, 0},
+ { TEXT_(T_FIND_NEXT), cast_uchar "n", TEXT_(T_HK_FIND_NEXT),
+ menu_for_frame, (void *)&find_next_ptr, 0, 0},
+ { TEXT_(T_FIND_PREVIOUS), cast_uchar "N", TEXT_(T_HK_FIND_PREVIOUS),
+ menu_for_frame, (void *)&find_next_back_ptr, 0, 0},
+ { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0},
+ { TEXT_(T_TOGGLE_HTML_PLAIN), cast_uchar "\\",
+ TEXT_(T_HK_TOGGLE_HTML_PLAIN), menu_toggle, NULL, 0, 0},
+ { TEXT_(T_DOCUMENT_INFO), cast_uchar "=", TEXT_(T_HK_DOCUMENT_INFO),
+ menu_doc_info, NULL, 0, 0},
+ { TEXT_(T_FRAME_AT_FULL_SCREEN), cast_uchar "f",
+ TEXT_(T_HK_FRAME_AT_FULL_SCREEN), menu_for_frame,
+ (void *)&set_frame_ptr, 0, 0},
+ { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0},
+ { TEXT_(T_HTML_OPTIONS), cast_uchar "", TEXT_(T_HK_HTML_OPTIONS),
+ menu_html_options, NULL, 0, 0},
+ { NULL, NULL, 0, NULL, NULL, 0, 0}
};
static const struct menu_item view_menu_color[] = {
- { TEXT_(T_SEARCH), cast_uchar "/", TEXT_(T_HK_SEARCH), menu_for_frame, (void *)&search_dlg_ptr, 0, 0 },
- { TEXT_(T_SEARCH_BACK), cast_uchar "?", TEXT_(T_HK_SEARCH_BACK), menu_for_frame, (void *)&search_back_dlg_ptr, 0, 0 },
- { TEXT_(T_FIND_NEXT), cast_uchar "n", TEXT_(T_HK_FIND_NEXT), menu_for_frame, (void *)&find_next_ptr, 0, 0 },
- { TEXT_(T_FIND_PREVIOUS), cast_uchar "N", TEXT_(T_HK_FIND_PREVIOUS), menu_for_frame, (void *)&find_next_back_ptr, 0, 0 },
- { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0 },
- { TEXT_(T_TOGGLE_HTML_PLAIN), cast_uchar "\\", TEXT_(T_HK_TOGGLE_HTML_PLAIN), menu_toggle, NULL, 0, 0 },
- { TEXT_(T_DOCUMENT_INFO), cast_uchar "=", TEXT_(T_HK_DOCUMENT_INFO), menu_doc_info, NULL, 0, 0 },
- { TEXT_(T_HEADER_INFO), cast_uchar "|", TEXT_(T_HK_HEADER_INFO), menu_head_info, NULL, 0, 0 },
- { TEXT_(T_FRAME_AT_FULL_SCREEN), cast_uchar "f", TEXT_(T_HK_FRAME_AT_FULL_SCREEN), menu_for_frame, (void *)&set_frame_ptr, 0, 0 },
- { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0 },
- { TEXT_(T_HTML_OPTIONS), cast_uchar "", TEXT_(T_HK_HTML_OPTIONS), menu_html_options, NULL, 0, 0 },
- { TEXT_(T_COLOR), cast_uchar "", TEXT_(T_HK_COLOR), menu_color, NULL, 0, 0 },
- { TEXT_(T_SAVE_HTML_OPTIONS), cast_uchar "", TEXT_(T_HK_SAVE_HTML_OPTIONS), menu_save_html_options, NULL, 0, 0 },
- { NULL, NULL, 0, NULL, NULL, 0, 0 }
+ {TEXT_(T_SEARCH), cast_uchar "/", TEXT_(T_HK_SEARCH), menu_for_frame,
+ (void *)&search_dlg_ptr, 0, 0},
+ { TEXT_(T_SEARCH_BACK), cast_uchar "?", TEXT_(T_HK_SEARCH_BACK),
+ menu_for_frame, (void *)&search_back_dlg_ptr, 0, 0},
+ { TEXT_(T_FIND_NEXT), cast_uchar "n", TEXT_(T_HK_FIND_NEXT),
+ menu_for_frame, (void *)&find_next_ptr, 0, 0},
+ { TEXT_(T_FIND_PREVIOUS), cast_uchar "N", TEXT_(T_HK_FIND_PREVIOUS),
+ menu_for_frame, (void *)&find_next_back_ptr, 0, 0},
+ { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0},
+ { TEXT_(T_TOGGLE_HTML_PLAIN), cast_uchar "\\",
+ TEXT_(T_HK_TOGGLE_HTML_PLAIN), menu_toggle, NULL, 0, 0},
+ { TEXT_(T_DOCUMENT_INFO), cast_uchar "=", TEXT_(T_HK_DOCUMENT_INFO),
+ menu_doc_info, NULL, 0, 0},
+ { TEXT_(T_HEADER_INFO), cast_uchar "|", TEXT_(T_HK_HEADER_INFO),
+ menu_head_info, NULL, 0, 0},
+ { TEXT_(T_FRAME_AT_FULL_SCREEN), cast_uchar "f",
+ TEXT_(T_HK_FRAME_AT_FULL_SCREEN), menu_for_frame,
+ (void *)&set_frame_ptr, 0, 0},
+ { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0},
+ { TEXT_(T_HTML_OPTIONS), cast_uchar "", TEXT_(T_HK_HTML_OPTIONS),
+ menu_html_options, NULL, 0, 0},
+ { TEXT_(T_COLOR), cast_uchar "", TEXT_(T_HK_COLOR), menu_color, NULL, 0,
+ 0 },
+ { TEXT_(T_SAVE_HTML_OPTIONS), cast_uchar "",
+ TEXT_(T_HK_SAVE_HTML_OPTIONS), menu_save_html_options, NULL, 0, 0},
+ { NULL, NULL, 0, NULL, NULL, 0, 0}
};
static const struct menu_item view_menu_anon_color[] = {
- { TEXT_(T_SEARCH), cast_uchar "/", TEXT_(T_HK_SEARCH), menu_for_frame, (void *)&search_dlg_ptr, 0, 0 },
- { TEXT_(T_SEARCH_BACK), cast_uchar "?", TEXT_(T_HK_SEARCH_BACK), menu_for_frame, (void *)&search_back_dlg_ptr, 0, 0 },
- { TEXT_(T_FIND_NEXT), cast_uchar "n", TEXT_(T_HK_FIND_NEXT), menu_for_frame, (void *)&find_next_ptr, 0, 0 },
- { TEXT_(T_FIND_PREVIOUS), cast_uchar "N", TEXT_(T_HK_FIND_PREVIOUS), menu_for_frame, (void *)&find_next_back_ptr, 0, 0 },
- { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0 },
- { TEXT_(T_TOGGLE_HTML_PLAIN), cast_uchar "\\", TEXT_(T_HK_TOGGLE_HTML_PLAIN), menu_toggle, NULL, 0, 0 },
- { TEXT_(T_DOCUMENT_INFO), cast_uchar "=", TEXT_(T_HK_DOCUMENT_INFO), menu_doc_info, NULL, 0, 0 },
- { TEXT_(T_FRAME_AT_FULL_SCREEN), cast_uchar "f", TEXT_(T_HK_FRAME_AT_FULL_SCREEN), menu_for_frame, (void *)&set_frame_ptr, 0, 0 },
- { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0 },
- { TEXT_(T_HTML_OPTIONS), cast_uchar "", TEXT_(T_HK_HTML_OPTIONS), menu_html_options, NULL, 0, 0 },
- { TEXT_(T_COLOR), cast_uchar "", TEXT_(T_HK_COLOR), menu_color, NULL, 0, 0 },
- { NULL, NULL, 0, NULL, NULL, 0, 0 }
+ {TEXT_(T_SEARCH), cast_uchar "/", TEXT_(T_HK_SEARCH), menu_for_frame,
+ (void *)&search_dlg_ptr, 0, 0},
+ { TEXT_(T_SEARCH_BACK), cast_uchar "?", TEXT_(T_HK_SEARCH_BACK),
+ menu_for_frame, (void *)&search_back_dlg_ptr, 0, 0},
+ { TEXT_(T_FIND_NEXT), cast_uchar "n", TEXT_(T_HK_FIND_NEXT),
+ menu_for_frame, (void *)&find_next_ptr, 0, 0},
+ { TEXT_(T_FIND_PREVIOUS), cast_uchar "N", TEXT_(T_HK_FIND_PREVIOUS),
+ menu_for_frame, (void *)&find_next_back_ptr, 0, 0},
+ { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0},
+ { TEXT_(T_TOGGLE_HTML_PLAIN), cast_uchar "\\",
+ TEXT_(T_HK_TOGGLE_HTML_PLAIN), menu_toggle, NULL, 0, 0},
+ { TEXT_(T_DOCUMENT_INFO), cast_uchar "=", TEXT_(T_HK_DOCUMENT_INFO),
+ menu_doc_info, NULL, 0, 0},
+ { TEXT_(T_FRAME_AT_FULL_SCREEN), cast_uchar "f",
+ TEXT_(T_HK_FRAME_AT_FULL_SCREEN), menu_for_frame,
+ (void *)&set_frame_ptr, 0, 0},
+ { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 0},
+ { TEXT_(T_HTML_OPTIONS), cast_uchar "", TEXT_(T_HK_HTML_OPTIONS),
+ menu_html_options, NULL, 0, 0},
+ { TEXT_(T_COLOR), cast_uchar "", TEXT_(T_HK_COLOR), menu_color, NULL, 0,
+ 0 },
+ { NULL, NULL, 0, NULL, NULL, 0, 0}
};
-static void do_view_menu(struct terminal *term, void *xxx, void *ses_)
+static void
+do_view_menu(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = (struct session *)ses_;
if (term->spec->col) {
- if (!anonymous) do_menu(term, (struct menu_item *)view_menu_color, ses);
- else do_menu(term, (struct menu_item *)view_menu_anon_color, ses);
+ if (!anonymous)
+ do_menu(term, (struct menu_item *)view_menu_color, ses);
+ else
+ do_menu(term, (struct menu_item *)view_menu_anon_color,
+ ses);
} else {
- if (!anonymous) do_menu(term, (struct menu_item *)view_menu, ses);
- else do_menu(term, (struct menu_item *)view_menu_anon, ses);
+ if (!anonymous)
+ do_menu(term, (struct menu_item *)view_menu, ses);
+ else
+ do_menu(term, (struct menu_item *)view_menu_anon, ses);
}
}
-
static const struct menu_item help_menu[] = {
- { TEXT_(T_ABOUT), cast_uchar "", TEXT_(T_HK_ABOUT), menu_about, NULL, 0, 0 },
- { TEXT_(T_KEYS), cast_uchar "F1", TEXT_(T_HK_KEYS), menu_keys, NULL, 0, 0 },
- { TEXT_(T_MANUAL), cast_uchar "", TEXT_(T_HK_MANUAL), menu_url, TEXT_(T_URL_MANUAL), 0, 0 },
- { TEXT_(T_HOMEPAGE), cast_uchar "", TEXT_(T_HK_HOMEPAGE), menu_url, TEXT_(T_URL_HOMEPAGE), 0, 0 },
- { TEXT_(T_COPYING), cast_uchar "", TEXT_(T_HK_COPYING), menu_copying, NULL, 0, 0 },
- { NULL, NULL, 0, NULL, NULL, 0, 0 }
+ {TEXT_(T_ABOUT), cast_uchar "", TEXT_(T_HK_ABOUT), menu_about, NULL, 0,
+ 0 },
+ { TEXT_(T_KEYS), cast_uchar "F1", TEXT_(T_HK_KEYS), menu_keys, NULL, 0,
+ 0 },
+ { TEXT_(T_MANUAL), cast_uchar "", TEXT_(T_HK_MANUAL), menu_url,
+ TEXT_(T_URL_MANUAL), 0, 0},
+ { TEXT_(T_HOMEPAGE), cast_uchar "", TEXT_(T_HK_HOMEPAGE), menu_url,
+ TEXT_(T_URL_HOMEPAGE), 0, 0},
+ { TEXT_(T_COPYING), cast_uchar "", TEXT_(T_HK_COPYING), menu_copying,
+ NULL, 0, 0},
+ { NULL, NULL, 0, NULL, NULL, 0, 0}
};
static const struct menu_item net_options_menu[] = {
- { TEXT_(T_CONNECTIONS), cast_uchar "", TEXT_(T_HK_CONNECTIONS), dlg_net_options, NULL, 0, 0 },
- { TEXT_(T_PROXIES), cast_uchar "", TEXT_(T_HK_PROXIES), dlg_proxy_options, NULL, 0, 0 },
- { TEXT_(T_SSL_OPTIONS), cast_uchar "", TEXT_(T_HK_SSL_OPTIONS), dlg_ssl_options, NULL, 0, 0 },
- { TEXT_(T_HTTP_OPTIONS), cast_uchar "", TEXT_(T_HK_HTTP_OPTIONS), dlg_http_options, NULL, 0, 0 },
- { NULL, NULL, 0, NULL, NULL, 0, 0 }
+ {TEXT_(T_CONNECTIONS), cast_uchar "", TEXT_(T_HK_CONNECTIONS),
+ dlg_net_options, NULL, 0, 0},
+ { TEXT_(T_PROXIES), cast_uchar "", TEXT_(T_HK_PROXIES),
+ dlg_proxy_options, NULL, 0, 0},
+ { TEXT_(T_SSL_OPTIONS), cast_uchar "", TEXT_(T_HK_SSL_OPTIONS),
+ dlg_ssl_options, NULL, 0, 0},
+ { TEXT_(T_HTTP_OPTIONS), cast_uchar "", TEXT_(T_HK_HTTP_OPTIONS),
+ dlg_http_options, NULL, 0, 0},
+ { NULL, NULL, 0, NULL, NULL, 0, 0}
};
static const struct menu_item net_options_ipv6_menu[] = {
- { TEXT_(T_CONNECTIONS), cast_uchar "", TEXT_(T_HK_CONNECTIONS), dlg_net_options, NULL, 0, 0 },
- { TEXT_(T_IPV6_OPTIONS), cast_uchar "", TEXT_(T_HK_IPV6_OPTIONS), dlg_ipv6_options, NULL, 0, 0 },
- { TEXT_(T_PROXIES), cast_uchar "", TEXT_(T_HK_PROXIES), dlg_proxy_options, NULL, 0, 0 },
- { TEXT_(T_SSL_OPTIONS), cast_uchar "", TEXT_(T_HK_SSL_OPTIONS), dlg_ssl_options, NULL, 0, 0 },
- { TEXT_(T_HTTP_OPTIONS), cast_uchar "", TEXT_(T_HK_HTTP_OPTIONS), dlg_http_options, NULL, 0, 0 },
- { NULL, NULL, 0, NULL, NULL, 0, 0 }
+ {TEXT_(T_CONNECTIONS), cast_uchar "", TEXT_(T_HK_CONNECTIONS),
+ dlg_net_options, NULL, 0, 0},
+ { TEXT_(T_IPV6_OPTIONS), cast_uchar "", TEXT_(T_HK_IPV6_OPTIONS),
+ dlg_ipv6_options, NULL, 0, 0},
+ { TEXT_(T_PROXIES), cast_uchar "", TEXT_(T_HK_PROXIES),
+ dlg_proxy_options, NULL, 0, 0},
+ { TEXT_(T_SSL_OPTIONS), cast_uchar "", TEXT_(T_HK_SSL_OPTIONS),
+ dlg_ssl_options, NULL, 0, 0},
+ { TEXT_(T_HTTP_OPTIONS), cast_uchar "", TEXT_(T_HK_HTTP_OPTIONS),
+ dlg_http_options, NULL, 0, 0},
+ { NULL, NULL, 0, NULL, NULL, 0, 0}
};
-static void network_menu(struct terminal *term, void *xxx, void *yyy)
+static void
+network_menu(struct terminal *term, void *xxx, void *yyy)
{
if (support_ipv6)
do_menu(term, (struct menu_item *)net_options_ipv6_menu, NULL);
@@ -1932,45 +2284,51 @@ static void network_menu(struct terminal *term, void *xxx, void *yyy)
do_menu(term, (struct menu_item *)net_options_menu, NULL);
}
-static void menu_write_config(struct terminal *term, void *xxx, void *yyy)
+static void
+menu_write_config(struct terminal *term, void *xxx, void *yyy)
{
write_config(term);
}
static const struct menu_item setup_menu_2[] = {
- { TEXT_(T_TERMINAL_OPTIONS), cast_uchar "", TEXT_(T_HK_TERMINAL_OPTIONS), terminal_options, NULL, 0, 1 },
+ {TEXT_(T_TERMINAL_OPTIONS), cast_uchar "",
+ TEXT_(T_HK_TERMINAL_OPTIONS), terminal_options, NULL, 0, 1},
};
static const struct menu_item setup_menu_5[] = {
- { TEXT_(T_NETWORK_OPTIONS), cast_uchar ">", TEXT_(T_HK_NETWORK_OPTIONS), network_menu, NULL, 1, 1 },
+ {TEXT_(T_NETWORK_OPTIONS), cast_uchar ">", TEXT_(T_HK_NETWORK_OPTIONS),
+ network_menu, NULL, 1, 1},
};
static const struct menu_item setup_menu_6[] = {
- { TEXT_(T_MISCELANEOUS_OPTIONS), cast_uchar "", TEXT_(T_HK_MISCELANEOUS_OPTIONS), miscelaneous_options, NULL, 0, 1 },
+ {TEXT_(T_MISCELANEOUS_OPTIONS), cast_uchar "",
+ TEXT_(T_HK_MISCELANEOUS_OPTIONS), miscelaneous_options, NULL, 0, 1},
};
static const struct menu_item setup_menu_7[] = {
- { TEXT_(T_CACHE), cast_uchar "", TEXT_(T_HK_CACHE), cache_opt, NULL, 0, 1 },
- { TEXT_(T_ASSOCIATIONS), cast_uchar "", TEXT_(T_HK_ASSOCIATIONS), menu_assoc_manager, NULL, 0, 1 },
- { TEXT_(T_FILE_EXTENSIONS), cast_uchar "", TEXT_(T_HK_FILE_EXTENSIONS), menu_ext_manager, NULL, 0, 1 },
- { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 1 },
- { TEXT_(T_SAVE_OPTIONS), cast_uchar "", TEXT_(T_HK_SAVE_OPTIONS), menu_write_config, NULL, 0, 1 },
+ {TEXT_(T_CACHE), cast_uchar "", TEXT_(T_HK_CACHE), cache_opt, NULL, 0,
+ 1 },
+ { TEXT_(T_ASSOCIATIONS), cast_uchar "", TEXT_(T_HK_ASSOCIATIONS),
+ menu_assoc_manager, NULL, 0, 1},
+ { TEXT_(T_FILE_EXTENSIONS), cast_uchar "", TEXT_(T_HK_FILE_EXTENSIONS),
+ menu_ext_manager, NULL, 0, 1},
+ { cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 1},
+ { TEXT_(T_SAVE_OPTIONS), cast_uchar "", TEXT_(T_HK_SAVE_OPTIONS),
+ menu_write_config, NULL, 0, 1},
};
static const struct menu_item setup_menu_8[] = {
- { NULL, NULL, 0, NULL, NULL, 0, 0 }
+ {NULL, NULL, 0, NULL, NULL, 0, 0}
};
-static void do_setup_menu(struct terminal *term, void *xxx, void *ses_)
+static void
+do_setup_menu(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = (struct session *)ses_;
struct menu_item *setup_menu, *e;
- int size =
- sizeof(setup_menu_2) +
- sizeof(setup_menu_5) +
- sizeof(setup_menu_6) +
- sizeof(setup_menu_7) +
- sizeof(setup_menu_8);
+ int size = sizeof(setup_menu_2) + sizeof(setup_menu_5)
+ + sizeof(setup_menu_6) + sizeof(setup_menu_7)
+ + sizeof(setup_menu_8);
setup_menu = xmalloc(size);
e = setup_menu;
memcpy(e, setup_menu_2, sizeof(setup_menu_2));
@@ -1991,45 +2349,60 @@ static void do_setup_menu(struct terminal *term, void *xxx, void *ses_)
do_menu(term, setup_menu, ses);
}
-static void do_help_menu(struct terminal *term, void *xxx, void *ses_)
+static void
+do_help_menu(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = (struct session *)ses_;
do_menu(term, (struct menu_item *)help_menu, ses);
}
-
static const struct menu_item main_menu[] = {
- { TEXT_(T_FILE), cast_uchar "", TEXT_(T_HK_FILE), do_file_menu, NULL, 1, 1 },
- { TEXT_(T_VIEW), cast_uchar "", TEXT_(T_HK_VIEW), do_view_menu, NULL, 1, 1 },
- { TEXT_(T_LINK), cast_uchar "", TEXT_(T_HK_LINK), link_menu, NULL, 1, 1 },
- { TEXT_(T_DOWNLOADS), cast_uchar "", TEXT_(T_HK_DOWNLOADS), downloads_menu, NULL, 1, 1 },
- { TEXT_(T_SETUP), cast_uchar "", TEXT_(T_HK_SETUP), do_setup_menu, NULL, 1, 1 },
- { TEXT_(T_HELP), cast_uchar "", TEXT_(T_HK_HELP), do_help_menu, NULL, 1, 1 },
- { NULL, NULL, 0, NULL, NULL, 0, 0 }
+ {TEXT_(T_FILE), cast_uchar "", TEXT_(T_HK_FILE), do_file_menu, NULL, 1,
+ 1 },
+ { TEXT_(T_VIEW), cast_uchar "", TEXT_(T_HK_VIEW), do_view_menu, NULL, 1,
+ 1 },
+ { TEXT_(T_LINK), cast_uchar "", TEXT_(T_HK_LINK), link_menu, NULL, 1,
+ 1 },
+ { TEXT_(T_DOWNLOADS), cast_uchar "", TEXT_(T_HK_DOWNLOADS),
+ downloads_menu, NULL, 1, 1},
+ { TEXT_(T_SETUP), cast_uchar "", TEXT_(T_HK_SETUP), do_setup_menu, NULL,
+ 1, 1},
+ { TEXT_(T_HELP), cast_uchar "", TEXT_(T_HK_HELP), do_help_menu, NULL, 1,
+ 1 },
+ { NULL, NULL, 0, NULL, NULL, 0, 0}
};
/* lame technology rulez ! */
-void activate_bfu_technology(struct session *ses, int item)
+void
+activate_bfu_technology(struct session *ses, int item)
{
struct terminal *term = ses->term;
struct menu_item *m = (struct menu_item *)main_menu;
do_mainmenu(term, m, ses, item);
}
-struct history goto_url_history = { 0, { &goto_url_history.items, &goto_url_history.items } };
+struct history goto_url_history = {
+ 0, {&goto_url_history.items, &goto_url_history.items}
+};
-void dialog_goto_url(struct session *ses, unsigned char *url)
+void
+dialog_goto_url(struct session *ses, unsigned char *url)
{
- input_field(ses->term, NULL, TEXT_(T_GOTO_URL), TEXT_(T_ENTER_URL), ses, &goto_url_history, MAX_INPUT_URL_LEN, url, 0, 0, NULL, 2, TEXT_(T_OK), goto_url, TEXT_(T_CANCEL), input_field_null);
+ input_field(ses->term, NULL, TEXT_(T_GOTO_URL), TEXT_(T_ENTER_URL), ses,
+ &goto_url_history, MAX_INPUT_URL_LEN, url, 0, 0, NULL, 2,
+ TEXT_(T_OK), goto_url, TEXT_(T_CANCEL), input_field_null);
}
-void dialog_save_url(struct session *ses)
+void
+dialog_save_url(struct session *ses)
{
- input_field(ses->term, NULL, TEXT_(T_SAVE_URL), TEXT_(T_ENTER_URL), ses, &goto_url_history, MAX_INPUT_URL_LEN, cast_uchar "", 0, 0, NULL, 2, TEXT_(T_OK), save_url, TEXT_(T_CANCEL), input_field_null);
+ input_field(ses->term, NULL, TEXT_(T_SAVE_URL), TEXT_(T_ENTER_URL), ses,
+ &goto_url_history, MAX_INPUT_URL_LEN, cast_uchar "", 0, 0,
+ NULL, 2, TEXT_(T_OK), save_url, TEXT_(T_CANCEL),
+ input_field_null);
}
-
struct does_file_exist_s {
void (*fn)(struct session *, unsigned char *, int);
void (*cancel)(void *);
@@ -2040,12 +2413,15 @@ struct does_file_exist_s {
unsigned char *head;
};
-static void does_file_exist_ok(struct does_file_exist_s *h, int mode)
+static void
+does_file_exist_ok(struct does_file_exist_s *h, int mode)
{
if (h->fn) {
unsigned char *d = h->file;
unsigned char *dd;
- for (dd = h->file; *dd; dd++) if (dir_sep(*dd)) d = dd + 1;
+ for (dd = h->file; *dd; dd++)
+ if (dir_sep(*dd))
+ d = dd + 1;
if (d - h->file < MAX_STR_LEN) {
memcpy(download_dir, h->file, d - h->file);
download_dir[d - h->file] = 0;
@@ -2054,30 +2430,35 @@ static void does_file_exist_ok(struct does_file_exist_s *h, int mode)
}
}
-
-static void does_file_exist_continue(void *data)
+static void
+does_file_exist_continue(void *data)
{
does_file_exist_ok(data, DOWNLOAD_CONTINUE);
}
-static void does_file_exist_overwrite(void *data)
+static void
+does_file_exist_overwrite(void *data)
{
does_file_exist_ok(data, DOWNLOAD_OVERWRITE);
}
-static void does_file_exist_cancel(void *data)
+static void
+does_file_exist_cancel(void *data)
{
- struct does_file_exist_s *h=(struct does_file_exist_s *)data;
- if (h->cancel) h->cancel(h->ses);
+ struct does_file_exist_s *h = (struct does_file_exist_s *)data;
+ if (h->cancel)
+ h->cancel(h->ses);
}
-static void does_file_exist_rename(void *data)
+static void
+does_file_exist_rename(void *data)
{
- struct does_file_exist_s *h=(struct does_file_exist_s *)data;
+ struct does_file_exist_s *h = (struct does_file_exist_s *)data;
query_file(h->ses, h->url, h->head, h->fn, h->cancel, h->flags);
}
-static void does_file_exist(void *d_, unsigned char *file)
+static void
+does_file_exist(void *d_, unsigned char *file)
{
struct does_file_exist_s *d = (struct does_file_exist_s *)d_;
unsigned char *f;
@@ -2135,58 +2516,49 @@ free_h_ret:
}
msg = TEXT_(T_ALREADY_EXISTS);
- display_msgbox:
+display_msgbox:
if (file_type == 2) {
- msg_box(
- ses->term,
- getml(h, h->file, h->url, h->head, NULL),
- TEXT_(T_FILE_ALREADY_EXISTS),
- AL_CENTER,
- TEXT_(T_DIRECTORY), cast_uchar " ", h->file, cast_uchar " ", TEXT_(T_ALREADY_EXISTS), MSG_BOX_END,
- (void *)h,
- 2,
- TEXT_(T_RENAME), does_file_exist_rename, B_ENTER,
- TEXT_(T_CANCEL), does_file_exist_cancel, B_ESC
- );
+ msg_box(ses->term, getml(h, h->file, h->url, h->head, NULL),
+ TEXT_(T_FILE_ALREADY_EXISTS), AL_CENTER,
+ TEXT_(T_DIRECTORY), cast_uchar " ", h->file,
+ cast_uchar " ", TEXT_(T_ALREADY_EXISTS), MSG_BOX_END,
+ (void *)h, 2, TEXT_(T_RENAME), does_file_exist_rename,
+ B_ENTER, TEXT_(T_CANCEL), does_file_exist_cancel,
+ B_ESC);
} else if (file_type || h->flags != DOWNLOAD_CONTINUE) {
- msg_box(
- ses->term,
- getml(h, h->file, h->url, h->head, NULL),
- TEXT_(T_FILE_ALREADY_EXISTS),
- AL_CENTER,
- TEXT_(T_FILE), cast_uchar " ", h->file, cast_uchar " ", msg, cast_uchar " ", TEXT_(T_DO_YOU_WISH_TO_OVERWRITE), MSG_BOX_END,
- (void *)h,
- 3,
- TEXT_(T_OVERWRITE), does_file_exist_overwrite, B_ENTER,
- TEXT_(T_RENAME), does_file_exist_rename, 0,
- TEXT_(T_CANCEL), does_file_exist_cancel, B_ESC
- );
+ msg_box(ses->term, getml(h, h->file, h->url, h->head, NULL),
+ TEXT_(T_FILE_ALREADY_EXISTS), AL_CENTER, TEXT_(T_FILE),
+ cast_uchar " ", h->file, cast_uchar " ", msg,
+ cast_uchar " ", TEXT_(T_DO_YOU_WISH_TO_OVERWRITE),
+ MSG_BOX_END, (void *)h, 3, TEXT_(T_OVERWRITE),
+ does_file_exist_overwrite, B_ENTER, TEXT_(T_RENAME),
+ does_file_exist_rename, 0, TEXT_(T_CANCEL),
+ does_file_exist_cancel, B_ESC);
} else {
- msg_box(
- ses->term,
- getml(h, h->file, h->url, h->head, NULL),
- TEXT_(T_FILE_ALREADY_EXISTS),
- AL_CENTER,
- TEXT_(T_FILE), cast_uchar " ", h->file, cast_uchar " ", msg, cast_uchar " ", TEXT_(T_DO_YOU_WISH_TO_CONTINUE), MSG_BOX_END,
- (void *)h,
- 4,
- TEXT_(T_CONTINUE), does_file_exist_continue, B_ENTER,
- TEXT_(T_OVERWRITE), does_file_exist_overwrite, 0,
- TEXT_(T_RENAME), does_file_exist_rename, 0,
- TEXT_(T_CANCEL), does_file_exist_cancel, B_ESC
- );
+ msg_box(ses->term, getml(h, h->file, h->url, h->head, NULL),
+ TEXT_(T_FILE_ALREADY_EXISTS), AL_CENTER, TEXT_(T_FILE),
+ cast_uchar " ", h->file, cast_uchar " ", msg,
+ cast_uchar " ", TEXT_(T_DO_YOU_WISH_TO_CONTINUE),
+ MSG_BOX_END, (void *)h, 4, TEXT_(T_CONTINUE),
+ does_file_exist_continue, B_ENTER, TEXT_(T_OVERWRITE),
+ does_file_exist_overwrite, 0, TEXT_(T_RENAME),
+ does_file_exist_rename, 0, TEXT_(T_CANCEL),
+ does_file_exist_cancel, B_ESC);
}
}
-
-static void query_file_cancel(void *d_, unsigned char *s_)
+static void
+query_file_cancel(void *d_, unsigned char *s_)
{
struct does_file_exist_s *d = (struct does_file_exist_s *)d_;
- if (d->cancel) d->cancel(d->ses);
+ if (d->cancel)
+ d->cancel(d->ses);
}
-
-void query_file(struct session *ses, unsigned char *url, unsigned char *head, void (*fn)(struct session *, unsigned char *, int), void (*cancel)(void *), int flags)
+void
+query_file(struct session *ses, unsigned char *url, unsigned char *head,
+ void (*fn)(struct session *, unsigned char *, int),
+ void (*cancel)(void *), int flags)
{
unsigned char *fc, *file, *def;
int dfl = 0;
@@ -2201,7 +2573,8 @@ void query_file(struct session *ses, unsigned char *url, unsigned char *head, vo
def = init_str();
add_to_str(&def, &dfl, download_dir);
- if (*def && !dir_sep(def[strlen(cast_const_char def) - 1])) add_chr_to_str(&def, &dfl, '/');
+ if (*def && !dir_sep(def[strlen(cast_const_char def) - 1]))
+ add_chr_to_str(&def, &dfl, '/');
add_to_str(&def, &dfl, file);
free(file);
@@ -2213,31 +2586,49 @@ void query_file(struct session *ses, unsigned char *url, unsigned char *head, vo
h->url = stracpy(url);
h->head = stracpy(head);
- input_field(ses->term, getml(h, h->url, h->head, NULL), TEXT_(T_DOWNLOAD), TEXT_(T_SAVE_TO_FILE), h, &file_history, MAX_INPUT_URL_LEN, def, 0, 0, NULL, 2, TEXT_(T_OK), does_file_exist, TEXT_(T_CANCEL), query_file_cancel);
+ input_field(ses->term, getml(h, h->url, h->head, NULL),
+ TEXT_(T_DOWNLOAD), TEXT_(T_SAVE_TO_FILE), h, &file_history,
+ MAX_INPUT_URL_LEN, def, 0, 0, NULL, 2, TEXT_(T_OK),
+ does_file_exist, TEXT_(T_CANCEL), query_file_cancel);
free(def);
}
-static struct history search_history = { 0, { &search_history.items, &search_history.items } };
+static struct history search_history = {
+ 0, {&search_history.items, &search_history.items}
+};
-void search_back_dlg(struct session *ses, struct f_data_c *f, int a)
+void
+search_back_dlg(struct session *ses, struct f_data_c *f, int a)
{
if (list_empty(ses->history) || !f->f_data || !f->vs) {
- msg_box(ses->term, NULL, TEXT_(T_SEARCH), AL_LEFT, TEXT_(T_YOU_ARE_NOWHERE), MSG_BOX_END, NULL, 1, TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
+ msg_box(ses->term, NULL, TEXT_(T_SEARCH), AL_LEFT,
+ TEXT_(T_YOU_ARE_NOWHERE), MSG_BOX_END, NULL, 1,
+ TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
return;
}
- input_field(ses->term, NULL, TEXT_(T_SEARCH_BACK), TEXT_(T_SEARCH_FOR_TEXT), ses, &search_history, MAX_INPUT_URL_LEN, cast_uchar "", 0, 0, NULL, 2, TEXT_(T_OK), search_for_back, TEXT_(T_CANCEL), input_field_null);
+ input_field(
+ ses->term, NULL, TEXT_(T_SEARCH_BACK), TEXT_(T_SEARCH_FOR_TEXT),
+ ses, &search_history, MAX_INPUT_URL_LEN, cast_uchar "", 0, 0, NULL,
+ 2, TEXT_(T_OK), search_for_back, TEXT_(T_CANCEL), input_field_null);
}
-void search_dlg(struct session *ses, struct f_data_c *f, int a)
+void
+search_dlg(struct session *ses, struct f_data_c *f, int a)
{
if (list_empty(ses->history) || !f->f_data || !f->vs) {
- msg_box(ses->term, NULL, TEXT_(T_SEARCH_FOR_TEXT), AL_LEFT, TEXT_(T_YOU_ARE_NOWHERE), MSG_BOX_END, NULL, 1, TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
+ msg_box(ses->term, NULL, TEXT_(T_SEARCH_FOR_TEXT), AL_LEFT,
+ TEXT_(T_YOU_ARE_NOWHERE), MSG_BOX_END, NULL, 1,
+ TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
return;
}
- input_field(ses->term, NULL, TEXT_(T_SEARCH), TEXT_(T_SEARCH_FOR_TEXT), ses, &search_history, MAX_INPUT_URL_LEN, cast_uchar "", 0, 0, NULL, 2, TEXT_(T_OK), search_for, TEXT_(T_CANCEL), input_field_null);
+ input_field(ses->term, NULL, TEXT_(T_SEARCH), TEXT_(T_SEARCH_FOR_TEXT),
+ ses, &search_history, MAX_INPUT_URL_LEN, cast_uchar "", 0,
+ 0, NULL, 2, TEXT_(T_OK), search_for, TEXT_(T_CANCEL),
+ input_field_null);
}
-void free_history_lists(void)
+void
+free_history_lists(void)
{
free_history(goto_url_history);
free_history(file_history);
diff --git a/objreq.c b/objreq.c
@@ -9,8 +9,7 @@
static void objreq_end(struct status *, void *);
static void object_timer(void *);
-
-static struct list_head requests = {&requests, &requests};
+static struct list_head requests = { &requests, &requests };
static tcount obj_req_count = 1;
#define MAX_UID_LEN 256
@@ -24,15 +23,19 @@ struct auth_dialog {
unsigned char msg[1];
};
-static inline struct object_request *find_rq(tcount c)
+static inline struct object_request *
+find_rq(tcount c)
{
struct object_request *rq = NULL;
struct list_head *lrq;
- foreach(struct object_request, rq, lrq, requests) if (rq->count == c) return rq;
+ foreach (struct object_request, rq, lrq, requests)
+ if (rq->count == c)
+ return rq;
return NULL;
}
-static void auth_fn(struct dialog_data *dlg)
+static void
+auth_fn(struct dialog_data *dlg)
{
struct terminal *term = dlg->win->term;
struct auth_dialog *a = dlg->dlg->udata;
@@ -48,16 +51,22 @@ static void auth_fn(struct dialog_data *dlg)
max_buttons_width(term, dlg->items + 2, 2, &max);
min_buttons_width(term, dlg->items + 2, 2, &min);
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(dlg, NULL, a->msg, 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text(dlg, NULL, a->msg, 0, &y, w, &rw, COLOR_DIALOG_TEXT,
+ AL_LEFT);
y++;
- dlg_format_text_and_field(dlg, NULL, TEXT_(T_USERID), dlg->items, 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, NULL, TEXT_(T_USERID), dlg->items, 0, &y,
+ w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_text_and_field(dlg, NULL, TEXT_(T_PASSWORD), dlg->items + 1, 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, NULL, TEXT_(T_PASSWORD), dlg->items + 1,
+ 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_buttons(dlg, NULL, dlg->items + 2, 2, 0, &y, w, &rw, AL_CENTER);
+ dlg_format_buttons(dlg, NULL, dlg->items + 2, 2, 0, &y, w, &rw,
+ AL_CENTER);
w = rw;
dlg->xw = rw + 2 * DIALOG_LB;
dlg->yw = y + 2 * DIALOG_TB;
@@ -65,16 +74,23 @@ static void auth_fn(struct dialog_data *dlg)
draw_dlg(dlg);
y = dlg->y + DIALOG_TB;
y++;
- dlg_format_text(dlg, term, a->msg, dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text(dlg, term, a->msg, dlg->x + DIALOG_LB, &y, w, NULL,
+ COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_text_and_field(dlg, term, TEXT_(T_USERID), dlg->items, dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, term, TEXT_(T_USERID), dlg->items,
+ dlg->x + DIALOG_LB, &y, w, NULL,
+ COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_text_and_field(dlg, term, TEXT_(T_PASSWORD), dlg->items + 1, dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, term, TEXT_(T_PASSWORD), dlg->items + 1,
+ dlg->x + DIALOG_LB, &y, w, NULL,
+ COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_buttons(dlg, term, dlg->items + 2, 2, dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);
+ dlg_format_buttons(dlg, term, dlg->items + 2, 2, dlg->x + DIALOG_LB, &y,
+ w, NULL, AL_CENTER);
}
-static int auth_cancel(struct dialog_data *dlg, struct dialog_item_data *item)
+static int
+auth_cancel(struct dialog_data *dlg, struct dialog_item_data *item)
{
struct auth_dialog *a = dlg->dlg->udata;
struct object_request *rq = find_rq(a->count);
@@ -91,7 +107,8 @@ static int auth_cancel(struct dialog_data *dlg, struct dialog_item_data *item)
return 0;
}
-static int auth_ok(struct dialog_data *dlg, struct dialog_item_data *item)
+static int
+auth_ok(struct dialog_data *dlg, struct dialog_item_data *item)
{
struct auth_dialog *a = dlg->dlg->udata;
struct object_request *rq = find_rq(a->count);
@@ -100,22 +117,29 @@ static int auth_ok(struct dialog_data *dlg, struct dialog_item_data *item)
int net_cp;
unsigned char *uid, *passwd;
get_dialog_data(dlg);
- ses = list_struct(dlg->win->term->windows.prev, struct window)->data;
- get_convert_table(rq->ce_internal->head, term_charset(dlg->win->term), ses->ds.assume_cp, &net_cp, NULL, ses->ds.hard_assume);
- uid = convert(term_charset(dlg->win->term), net_cp, a->uid, NULL);
- passwd = convert(term_charset(dlg->win->term), net_cp, a->passwd, NULL);
+ ses = list_struct(dlg->win->term->windows.prev, struct window)
+ ->data;
+ get_convert_table(
+ rq->ce_internal->head, term_charset(dlg->win->term),
+ ses->ds.assume_cp, &net_cp, NULL, ses->ds.hard_assume);
+ uid =
+ convert(term_charset(dlg->win->term), net_cp, a->uid, NULL);
+ passwd = convert(term_charset(dlg->win->term), net_cp,
+ a->passwd, NULL);
add_auth(rq->url, a->realm, uid, passwd, a->proxy);
free(uid);
free(passwd);
rq->hold = 0;
change_connection(&rq->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);
}
cancel_dialog(dlg, item);
return 0;
}
-static int auth_window(struct object_request *rq, unsigned char *realm)
+static int
+auth_window(struct object_request *rq, unsigned char *realm)
{
unsigned char *host, *port;
struct dialog *d;
@@ -124,16 +148,21 @@ static int auth_window(struct object_request *rq, unsigned char *realm)
unsigned char *urealm;
struct session *ses;
int net_cp;
- if (!(term = find_terminal(rq->term))) return -1;
+ if (!(term = find_terminal(rq->term)))
+ return -1;
ses = list_struct(term->windows.prev, struct window)->data;
- get_convert_table(rq->ce_internal->head, term_charset(term), ses->ds.assume_cp, &net_cp, NULL, ses->ds.hard_assume);
+ get_convert_table(rq->ce_internal->head, term_charset(term),
+ ses->ds.assume_cp, &net_cp, NULL,
+ ses->ds.hard_assume);
if (rq->ce_internal->http_code == 407) {
unsigned char *h = get_proxy_string(rq->url);
- if (!h) h = cast_uchar "";
+ if (!h)
+ h = cast_uchar "";
host = display_host(term, h);
} else {
unsigned char *h = get_host_name(rq->url);
- if (!h) return -1;
+ if (!h)
+ return -1;
host = display_host(term, h);
free(h);
if ((port = get_port_str(rq->url))) {
@@ -143,14 +172,26 @@ static int auth_window(struct object_request *rq, unsigned char *realm)
}
}
urealm = convert(term_charset(term), net_cp, realm, NULL);
- d = xmalloc(sizeof(struct dialog) + 5 * sizeof(struct dialog_item) + sizeof(struct auth_dialog) + strlen(cast_const_char get_text_translation(TEXT_(T_ENTER_USERNAME), term)) + strlen(cast_const_char urealm) + 1 + strlen(cast_const_char get_text_translation(TEXT_(T_AT), term)) + strlen(cast_const_char host));
- memset(d, 0, sizeof(struct dialog) + 5 * sizeof(struct dialog_item) + sizeof(struct auth_dialog));
- a = (struct auth_dialog *)((unsigned char *)d + sizeof(struct dialog) + 5 * sizeof(struct dialog_item));
- strcpy(cast_char a->msg, cast_const_char get_text_translation(TEXT_(T_ENTER_USERNAME), term));
+ d = xmalloc(
+ sizeof(struct dialog) + 5 * sizeof(struct dialog_item)
+ + sizeof(struct auth_dialog)
+ + strlen(cast_const_char get_text_translation(
+ TEXT_(T_ENTER_USERNAME), term))
+ + strlen(cast_const_char urealm) + 1
+ + strlen(cast_const_char get_text_translation(TEXT_(T_AT), term))
+ + strlen(cast_const_char host));
+ memset(d, 0,
+ sizeof(struct dialog) + 5 * sizeof(struct dialog_item)
+ + sizeof(struct auth_dialog));
+ a = (struct auth_dialog *)((unsigned char *)d + sizeof(struct dialog)
+ + 5 * sizeof(struct dialog_item));
+ strcpy(cast_char a->msg, cast_const_char get_text_translation(
+ TEXT_(T_ENTER_USERNAME), term));
strcat(cast_char a->msg, cast_const_char urealm);
if (*host) {
strcat(cast_char a->msg, "\n");
- strcat(cast_char a->msg, cast_const_char get_text_translation(TEXT_(T_AT), term));
+ strcat(cast_char a->msg,
+ cast_const_char get_text_translation(TEXT_(T_AT), term));
strcat(cast_char a->msg, cast_const_char host);
}
free(host);
@@ -159,8 +200,10 @@ static int auth_window(struct object_request *rq, unsigned char *realm)
a->realm = stracpy(realm);
a->count = rq->count;
d->udata = a;
- if (rq->ce_internal->http_code == 401) d->title = TEXT_(T_AUTHORIZATION_REQUIRED);
- else d->title = TEXT_(T_PROXY_AUTHORIZATION_REQUIRED);
+ if (rq->ce_internal->http_code == 401)
+ d->title = TEXT_(T_AUTHORIZATION_REQUIRED);
+ else
+ d->title = TEXT_(T_PROXY_AUTHORIZATION_REQUIRED);
d->fn = auth_fn;
d->items[0].type = D_FIELD;
d->items[0].dlen = MAX_UID_LEN;
@@ -191,22 +234,26 @@ struct cert_dialog {
int state;
};
-static void cert_action(struct object_request *rq, int yes)
+static void
+cert_action(struct object_request *rq, int yes)
{
if (yes > 0) {
rq->hold = 0;
change_connection(&rq->stat, NULL, PRI_CANCEL);
- load_url(rq->url, rq->prev_url, &rq->stat, rq->pri, NC_CACHE, 0, 0, 0);
+ load_url(rq->url, rq->prev_url, &rq->stat, rq->pri, NC_CACHE, 0,
+ 0, 0);
} else {
rq->hold = 0;
rq->dont_print_error = 1;
rq->state = O_FAILED;
- if (rq->timer != NULL) kill_timer(rq->timer);
+ if (rq->timer != NULL)
+ kill_timer(rq->timer);
rq->timer = install_timer(0, object_timer, rq);
}
}
-static void cert_forall(struct cert_dialog *cs, int yes)
+static void
+cert_forall(struct cert_dialog *cs, int yes)
{
struct object_request *rq = NULL;
struct list_head *lrq;
@@ -220,42 +267,53 @@ static void cert_forall(struct cert_dialog *cs, int yes)
del_blacklist_entry(cs->host, BL_IGNORE_DOWNGRADE);
del_blacklist_entry(cs->host, BL_IGNORE_CIPHER);
}
- foreach(struct object_request, rq, lrq, requests) if (rq->term == cs->term && rq->hold == HOLD_CERT && rq->stat.state == cs->state) {
- unsigned char *host = get_host_name(rq->url);
- if (!strcmp(cast_const_char host, cast_const_char cs->host)) cert_action(rq, yes);
- free(host);
- }
+ foreach (struct object_request, rq, lrq, requests)
+ if (rq->term == cs->term && rq->hold == HOLD_CERT
+ && rq->stat.state == cs->state) {
+ unsigned char *host = get_host_name(rq->url);
+ if (!strcmp(cast_const_char host,
+ cast_const_char cs->host))
+ cert_action(rq, yes);
+ free(host);
+ }
}
-static void cert_yes(void *data)
+static void
+cert_yes(void *data)
{
cert_forall((struct cert_dialog *)data, 1);
}
-static void cert_no(void *data)
+static void
+cert_no(void *data)
{
cert_forall((struct cert_dialog *)data, 0);
}
-static void cert_never(void *data)
+static void
+cert_never(void *data)
{
cert_forall((struct cert_dialog *)data, -1);
}
-static int cert_compare(void *data1, void *data2)
+static int
+cert_compare(void *data1, void *data2)
{
struct cert_dialog *cs1 = (struct cert_dialog *)data1;
struct cert_dialog *cs2 = (struct cert_dialog *)data2;
- return !strcmp(cast_const_char cs1->host, cast_const_char cs2->host) && cs1->state == cs2->state;
+ return !strcmp(cast_const_char cs1->host, cast_const_char cs2->host)
+ && cs1->state == cs2->state;
}
-static int cert_window(struct object_request *rq)
+static int
+cert_window(struct object_request *rq)
{
struct terminal *term;
unsigned char *h, *host, *title, *text;
struct cert_dialog *cs;
struct memory_list *ml;
- if (!(term = find_terminal(rq->term))) return -1;
+ if (!(term = find_terminal(rq->term)))
+ return -1;
h = get_host_name(rq->url);
if (get_blacklist_flags(h) & BL_AVOID_INSECURE) {
free(h);
@@ -284,16 +342,19 @@ static int cert_window(struct object_request *rq)
freeml(ml);
return 0;
}
- msg_box(term, ml,
- title,
- AL_CENTER, TEXT_(T_THE_SERVER_), host, text, MSG_BOX_END,
- (void *)cs, 3, TEXT_(T_NO), cert_no, B_ESC, TEXT_(T_YES), cert_yes, B_ENTER, TEXT_(T_NEVER), cert_never, 0);
+ msg_box(term, ml, title, AL_CENTER, TEXT_(T_THE_SERVER_), host, text,
+ MSG_BOX_END, (void *)cs, 3, TEXT_(T_NO), cert_no, B_ESC,
+ TEXT_(T_YES), cert_yes, B_ENTER, TEXT_(T_NEVER), cert_never, 0);
return 0;
}
/* prev_url is a pointer to previous url or NULL */
/* prev_url will NOT be deallocated */
-void request_object(struct terminal *term, unsigned char *url, unsigned char *prev_url, int pri, int cache, int allow_flags, void (*upcall)(struct object_request *, void *), void *data, struct object_request **rqp)
+void
+request_object(struct terminal *term, unsigned char *url,
+ unsigned char *prev_url, int pri, int cache, int allow_flags,
+ void (*upcall)(struct object_request *, void *), void *data,
+ struct object_request **rqp)
{
struct object_request *rq;
rq = mem_calloc(sizeof(struct object_request));
@@ -312,13 +373,15 @@ void request_object(struct terminal *term, unsigned char *url, unsigned char *pr
rq->last_update = get_time() - STAT_UPDATE_MAX;
free(rq->prev_url);
rq->prev_url = stracpy(prev_url);
- if (rqp) *rqp = rq;
+ if (rqp)
+ *rqp = rq;
rq->count = obj_req_count++;
add_to_list(requests, rq);
load_url(url, prev_url, &rq->stat, pri, cache, 0, allow_flags, 0);
}
-static void set_ce_internal(struct object_request *rq)
+static void
+set_ce_internal(struct object_request *rq)
{
if (rq->stat.ce != rq->ce_internal) {
if (!rq->stat.ce) {
@@ -333,7 +396,8 @@ static void set_ce_internal(struct object_request *rq)
}
}
-static void objreq_end(struct status *stat, void *data)
+static void
+objreq_end(struct status *stat, void *data)
{
struct object_request *rq = (struct object_request *)data;
@@ -341,10 +405,11 @@ static void objreq_end(struct status *stat, void *data)
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) {
+ && (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;
@@ -363,36 +428,41 @@ static void objreq_end(struct status *stat, void *data)
}
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))
+ && (!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;
- load_url(u, rq->prev_url, &rq->stat, rq->pri, cache, 0, allow_flags, 0);
+ load_url(u, rq->prev_url, &rq->stat, rq->pri,
+ cache, 0, allow_flags, 0);
return;
} else {
- maxrd:
+maxrd:
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);
+ && (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)) {
+ && !find_auth(rq->url, realm)) {
free(realm);
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);
+ rq->pri, NC_RELOAD, 0, 0, 0);
return;
}
user = get_user_name(rq->url);
@@ -412,25 +482,25 @@ 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:
+xx:
rq->state = O_OK;
}
if (!rq->ce)
(rq->ce = stat->ce)->refcount++;
}
- tm:
+tm:
if (rq->timer != NULL)
kill_timer(rq->timer);
rq->timer = install_timer(0, object_timer, rq);
}
-static void object_timer(void *rq_)
+static void
+object_timer(void *rq_)
{
struct object_request *rq = (struct object_request *)rq_;
off_t last;
@@ -443,16 +513,18 @@ static void object_timer(void *rq_)
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)) {
+ && (!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;
+ rq->state =
+ rq->stat.state != S__OK ? O_INCOMPLETE : O_OK;
} 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->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);
@@ -460,17 +532,23 @@ static void object_timer(void *rq_)
uttime ct = get_time();
uttime t = ct - rq->last_update;
rq->timer = install_timer(STAT_UPDATE_MIN, object_timer, rq);
- if (t >= STAT_UPDATE_MAX || (t >= STAT_UPDATE_MIN && rq->ce && rq->last_bytes > last)) {
+ if (t >= STAT_UPDATE_MAX
+ || (t >= STAT_UPDATE_MIN && rq->ce
+ && rq->last_bytes > last)) {
rq->last_update = ct;
- if (rq->upcall) rq->upcall(rq, rq->data);
+ if (rq->upcall)
+ rq->upcall(rq, rq->data);
}
}
}
-void release_object_get_stat(struct object_request **rqq, struct status *news, int pri)
+void
+release_object_get_stat(struct object_request **rqq, struct status *news,
+ int pri)
{
struct object_request *rq = *rqq;
- if (!rq) return;
+ if (!rq)
+ return;
*rqq = NULL;
if (--rq->refcount)
return;
@@ -489,12 +567,14 @@ void release_object_get_stat(struct object_request **rqq, struct status *news, i
free(rq);
}
-void release_object(struct object_request **rqq)
+void
+release_object(struct object_request **rqq)
{
release_object_get_stat(rqq, NULL, PRI_CANCEL);
}
-void detach_object_connection(struct object_request *rq, off_t pos)
+void
+detach_object_connection(struct object_request *rq, off_t pos)
{
if (rq->state == O_WAITING || rq->state == O_FAILED) {
internal("detach_object_connection: no data received");
@@ -505,7 +585,8 @@ void detach_object_connection(struct object_request *rq, off_t pos)
}
}
-void clone_object(struct object_request *rq, struct object_request **rqq)
+void
+clone_object(struct object_request *rq, struct object_request **rqq)
{
(*rqq = rq)->refcount++;
}
diff --git a/os_dep.c b/os_dep.c
@@ -13,63 +13,80 @@
int page_size = 4096;
-int is_safe_in_shell(unsigned char c)
+int
+is_safe_in_shell(unsigned char c)
{
- return c == '@' || c == '+' || c == '-' || c == '.' || c == ',' || c == '=' || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || c == '_' || (c >= 'a' && c <= 'z');
+ return c == '@' || c == '+' || c == '-' || c == '.' || c == ','
+ || c == '=' || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z')
+ || c == '_' || (c >= 'a' && c <= 'z');
}
-static inline int is_safe_in_file(unsigned char c)
+static inline int
+is_safe_in_file(unsigned char c)
{
- return !(c < ' ' || c == '"' || c == '*' || c == '/' || c == ':' || c == '<' || c == '>' || c == '\\' || c == '|' || c >= 0x80);
+ return !(c < ' ' || c == '"' || c == '*' || c == '/' || c == ':'
+ || c == '<' || c == '>' || c == '\\' || c == '|' || c >= 0x80);
}
-static inline int is_safe_in_url(unsigned char c)
+static inline int
+is_safe_in_url(unsigned char c)
{
return is_safe_in_shell(c) || c == ':' || c == '/' || c >= 0x80;
}
-void check_shell_security(unsigned char **cmd)
+void
+check_shell_security(unsigned char **cmd)
{
unsigned char *c = *cmd;
while (*c) {
- if (!is_safe_in_shell(*c)) *c = '_';
+ if (!is_safe_in_shell(*c))
+ *c = '_';
c++;
}
}
-void check_filename(unsigned char **file)
+void
+check_filename(unsigned char **file)
{
unsigned char *c = *file;
while (*c) {
- if (!is_safe_in_file(*c)) *c = '_';
+ if (!is_safe_in_file(*c))
+ *c = '_';
c++;
}
}
-int check_shell_url(unsigned char *url)
+int
+check_shell_url(unsigned char *url)
{
while (*url) {
- if (!is_safe_in_url(*url)) return -1;
+ if (!is_safe_in_url(*url))
+ return -1;
url++;
}
return 0;
}
-unsigned char *escape_path(char *path)
+unsigned char *
+escape_path(char *path)
{
unsigned char *result;
size_t i;
- if (strchr(path, '"')) return stracpy(cast_uchar path);
- for (i = 0; path[i]; i++) if (!is_safe_in_url(path[i])) goto do_esc;
+ if (strchr(path, '"'))
+ return stracpy(cast_uchar path);
+ for (i = 0; path[i]; i++)
+ if (!is_safe_in_url(path[i]))
+ goto do_esc;
return stracpy(cast_uchar path);
- do_esc:
+do_esc:
result = stracpy(cast_uchar "\"");
add_to_strn(&result, cast_uchar path);
add_to_strn(&result, cast_uchar "\"");
return result;
}
-static int get_e(const char *env)
+static int
+get_e(const char *env)
{
const char *v;
if ((v = getenv(env)))
@@ -77,20 +94,26 @@ static int get_e(const char *env)
return 0;
}
-void init_page_size(void) {
+void
+init_page_size(void)
+{
long getpg = -1;
if (getpg < 0)
getpg = getpagesize();
- if (getpg > 0 && !(getpg & (getpg - 1))) page_size = (int)getpg;
+ if (getpg > 0 && !(getpg & (getpg - 1)))
+ page_size = (int)getpg;
}
-void do_signal(int sig, void (*handler)(int))
+void
+do_signal(int sig, void (*handler)(int))
{
errno = 0;
- while (signal(sig, handler) == SIG_ERR && errno == EINTR) errno = 0;
+ while (signal(sig, handler) == SIG_ERR && errno == EINTR)
+ errno = 0;
}
-void ignore_signals(void)
+void
+ignore_signals(void)
{
do_signal(SIGPIPE, SIG_IGN);
#ifdef SIGXFSZ
@@ -98,35 +121,43 @@ void ignore_signals(void)
#endif
}
-uttime get_absolute_time(void)
+uttime
+get_absolute_time(void)
{
struct timeval tv;
int rs;
EINTRLOOP(rs, gettimeofday(&tv, NULL));
- if (rs) fatal_exit("gettimeofday failed: %d", errno);
+ if (rs)
+ fatal_exit("gettimeofday failed: %d", errno);
return (uttime)tv.tv_sec * 1000 + (unsigned)tv.tv_usec / 1000;
}
-uttime get_time(void)
+uttime
+get_time(void)
{
#if defined(CLOCK_MONOTONIC_RAW) || defined(CLOCK_MONOTONIC)
struct timespec ts;
int rs;
-#if defined(CLOCK_MONOTONIC_RAW)
+ #if defined(CLOCK_MONOTONIC_RAW)
EINTRLOOP(rs, clock_gettime(CLOCK_MONOTONIC_RAW, &ts));
- if (!rs) return (uttime)ts.tv_sec * 1000 + (unsigned)ts.tv_nsec / 1000000;
-#endif
-#if defined(CLOCK_MONOTONIC)
+ if (!rs)
+ return (uttime)ts.tv_sec * 1000
+ + (unsigned)ts.tv_nsec / 1000000;
+ #endif
+ #if defined(CLOCK_MONOTONIC)
EINTRLOOP(rs, clock_gettime(CLOCK_MONOTONIC, &ts));
- if (!rs) return (uttime)ts.tv_sec * 1000 + (unsigned)ts.tv_nsec / 1000000;
-#endif
+ if (!rs)
+ return (uttime)ts.tv_sec * 1000
+ + (unsigned)ts.tv_nsec / 1000000;
+ #endif
#endif
return get_absolute_time();
}
static unsigned char *clipboard = NULL;
-void os_free_clipboard(void)
+void
+os_free_clipboard(void)
{
free(clipboard);
clipboard = NULL;
@@ -137,7 +168,8 @@ void os_free_clipboard(void)
static void (*terminal_resize_callback)(int, int);
#ifdef SIGWINCH
-static void sigwinch(void *s)
+static void
+sigwinch(void *s)
{
int cur_xsize, cur_ysize;
get_terminal_size(&cur_xsize, &cur_ysize);
@@ -145,7 +177,8 @@ static void sigwinch(void *s)
}
#endif
-void handle_terminal_resize(void (*fn)(int, int), int *x, int *y)
+void
+handle_terminal_resize(void (*fn)(int, int), int *x, int *y)
{
terminal_resize_callback = fn;
get_terminal_size(x, y);
@@ -154,14 +187,16 @@ void handle_terminal_resize(void (*fn)(int, int), int *x, int *y)
#endif
}
-void unhandle_terminal_resize(void)
+void
+unhandle_terminal_resize(void)
{
#if defined(SIGWINCH)
install_signal_handler(SIGWINCH, NULL, NULL, 0);
#endif
}
-void get_terminal_size(int *x, int *y)
+void
+get_terminal_size(int *x, int *y)
{
int rs = -1;
#ifdef TIOCGWINSZ
@@ -170,34 +205,39 @@ void get_terminal_size(int *x, int *y)
#endif
if ((rs == -1
#ifdef TIOCGWINSZ
- || !(*x = ws.ws_col)
+ || !(*x = ws.ws_col)
#endif
- ) && !(*x = get_e("COLUMNS"))) {
+ )
+ && !(*x = get_e("COLUMNS"))) {
*x = 80;
}
if ((rs == -1
#ifdef TIOCGWINSZ
- || !(*y = ws.ws_row)
+ || !(*y = ws.ws_row)
#endif
- ) && !(*y = get_e("LINES"))) {
+ )
+ && !(*y = get_e("LINES"))) {
*y = 24;
}
}
-static void new_fd_cloexec(int fd)
+static void
+new_fd_cloexec(int fd)
{
int rs;
EINTRLOOP(rs, fcntl(fd, F_SETFD, FD_CLOEXEC));
}
-static void new_fd_bin(int fd)
+static void
+new_fd_bin(int fd)
{
new_fd_cloexec(fd);
}
/* Pipe */
-void set_nonblock(int fd)
+void
+set_nonblock(int fd)
{
#ifdef O_NONBLOCK
int rs;
@@ -209,38 +249,46 @@ void set_nonblock(int fd)
#endif
}
-static int cleanup_fds(void)
+static int
+cleanup_fds(void)
{
#ifdef ENFILE
- if (errno == ENFILE) return abort_background_connections();
+ if (errno == ENFILE)
+ return abort_background_connections();
#endif
#ifdef EMFILE
- if (errno == EMFILE) return abort_background_connections();
+ if (errno == EMFILE)
+ return abort_background_connections();
#endif
return 0;
}
-int c_pipe(int fd[2])
+int
+c_pipe(int fd[2])
{
int r;
do {
EINTRLOOP(r, pipe(fd));
- if (!r) new_fd_bin(fd[0]), new_fd_bin(fd[1]);
+ if (!r)
+ new_fd_bin(fd[0]), new_fd_bin(fd[1]);
} while (r == -1 && cleanup_fds());
return r;
}
-int c_dup(int oh)
+int
+c_dup(int oh)
{
int h;
do {
EINTRLOOP(h, dup(oh));
- if (h != -1) new_fd_cloexec(h);
+ if (h != -1)
+ new_fd_cloexec(h);
} while (h == -1 && cleanup_fds());
return h;
}
-int c_socket(int d, int t, int p)
+int
+c_socket(int d, int t, int p)
{
int h = socket(d, t, p);
@@ -253,37 +301,44 @@ int c_socket(int d, int t, int p)
return h;
}
-int c_accept(int sh, struct sockaddr *addr, socklen_t *addrlen)
+int
+c_accept(int sh, struct sockaddr *addr, socklen_t *addrlen)
{
int h;
do {
EINTRLOOP(h, accept(sh, addr, addrlen));
- if (h != -1) new_fd_cloexec(h);
+ if (h != -1)
+ new_fd_cloexec(h);
} while (h == -1 && cleanup_fds());
return h;
}
-int c_open(unsigned char *path, int flags)
+int
+c_open(unsigned char *path, int flags)
{
int h;
do {
EINTRLOOP(h, open(cast_const_char path, flags));
- if (h != -1) new_fd_bin(h);
+ if (h != -1)
+ new_fd_bin(h);
} while (h == -1 && cleanup_fds());
return h;
}
-int c_open3(unsigned char *path, int flags, int mode)
+int
+c_open3(unsigned char *path, int flags, int mode)
{
int h;
do {
EINTRLOOP(h, open(cast_const_char path, flags, mode));
- if (h != -1) new_fd_bin(h);
+ if (h != -1)
+ new_fd_bin(h);
} while (h == -1 && cleanup_fds());
return h;
}
-DIR *c_opendir(unsigned char *path)
+DIR *
+c_opendir(unsigned char *path)
{
DIR *d;
do {
@@ -291,7 +346,8 @@ DIR *c_opendir(unsigned char *path)
if (d) {
int h;
EINTRLOOP(h, dirfd(d));
- if (h != -1) new_fd_cloexec(h);
+ if (h != -1)
+ new_fd_cloexec(h);
}
} while (!d && cleanup_fds());
return d;
@@ -299,21 +355,26 @@ DIR *c_opendir(unsigned char *path)
/* Exec */
-int is_screen(void)
+int
+is_screen(void)
{
static int xt = -1;
- if (xt == -1) xt = !!getenv("STY");
+ if (xt == -1)
+ xt = !!getenv("STY");
return xt;
}
-int is_xterm(void)
+int
+is_xterm(void)
{
static int xt = -1;
- if (xt == -1) xt = getenv("DISPLAY") && *(char *)getenv("DISPLAY");
+ if (xt == -1)
+ xt = getenv("DISPLAY") && *(char *)getenv("DISPLAY");
return xt;
}
-void close_fork_tty(void)
+void
+close_fork_tty(void)
{
struct terminal *t = NULL;
struct list_head *lt;
@@ -326,35 +387,42 @@ void close_fork_tty(void)
int rs;
EINTRLOOP(rs, close(signal_pipe[0]));
EINTRLOOP(rs, close(signal_pipe[1]));
- if (terminal_pipe[1] != -1) EINTRLOOP(rs, close(terminal_pipe[1]));
- foreach(struct terminal, t, lt, terminals) {
+ if (terminal_pipe[1] != -1)
+ EINTRLOOP(rs, close(terminal_pipe[1]));
+ foreach (struct terminal, t, lt, terminals) {
if (t->fdin > 0)
EINTRLOOP(rs, close(t->fdin));
if (t->handle_to_close >= 0)
EINTRLOOP(rs, close(t->handle_to_close));
}
- foreach(struct download, d, ld, downloads) if (d->handle > 0)
- EINTRLOOP(rs, close(d->handle));
- foreach(struct connection, c, lc, queue) {
- if (c->sock1 >= 0) EINTRLOOP(rs, close(c->sock1));
- if (c->sock2 >= 0) EINTRLOOP(rs, close(c->sock2));
+ foreach (struct download, d, ld, downloads)
+ if (d->handle > 0)
+ EINTRLOOP(rs, close(d->handle));
+ foreach (struct connection, c, lc, queue) {
+ if (c->sock1 >= 0)
+ EINTRLOOP(rs, close(c->sock1));
+ if (c->sock2 >= 0)
+ EINTRLOOP(rs, close(c->sock2));
}
- foreach(struct k_conn, k, lk, keepalive_connections)
+ foreach (struct k_conn, k, lk, keepalive_connections)
EINTRLOOP(rs, close(k->conn));
}
-unsigned char *os_conv_to_external_path(unsigned char *file, unsigned char *prog)
+unsigned char *
+os_conv_to_external_path(unsigned char *file, unsigned char *prog)
{
return stracpy(file);
}
-unsigned char *os_fixup_external_program(unsigned char *prog)
+unsigned char *
+os_fixup_external_program(unsigned char *prog)
{
return stracpy(prog);
}
/* UNIX */
-int exe(char *path, int fg)
+int
+exe(char *path, int fg)
{
#ifdef SIGCHLD
do_signal(SIGCHLD, SIG_DFL);
@@ -376,7 +444,8 @@ int exe(char *path, int fg)
}
/* clipboard -> links */
-unsigned char *get_clipboard_text(struct terminal *term)
+unsigned char *
+get_clipboard_text(struct terminal *term)
{
if (!clipboard)
return NULL;
@@ -384,23 +453,27 @@ unsigned char *get_clipboard_text(struct terminal *term)
}
/* links -> clipboard */
-void set_clipboard_text(struct terminal *term, unsigned char *data)
+void
+set_clipboard_text(struct terminal *term, unsigned char *data)
{
free(clipboard);
clipboard = convert(term_charset(term), 0, data, NULL);
}
-int clipboard_support(struct terminal *term)
+int
+clipboard_support(struct terminal *term)
{
return 0;
}
-void set_window_title(unsigned char *title)
+void
+set_window_title(unsigned char *title)
{
/* !!! FIXME */
}
-unsigned char *get_window_title(void)
+unsigned char *
+get_window_title(void)
{
/* !!! FIXME */
return NULL;
@@ -408,12 +481,14 @@ unsigned char *get_window_title(void)
/* Threads */
-int start_thread(void (*fn)(void *, int), void *ptr, int l, int counted)
+int
+start_thread(void (*fn)(void *, int), void *ptr, int l, int counted)
{
int p[2];
pid_t f;
int rs;
- if (c_pipe(p) < 0) return -1;
+ if (c_pipe(p) < 0)
+ return -1;
EINTRLOOP(f, fork());
if (!f) {
close_fork_tty();
@@ -432,7 +507,9 @@ int start_thread(void (*fn)(void *, int), void *ptr, int l, int counted)
return p[0];
}
-static void exec_new_links(struct terminal *term, unsigned char *xterm, unsigned char *exe, unsigned char *param)
+static void
+exec_new_links(struct terminal *term, unsigned char *xterm, unsigned char *exe,
+ unsigned char *param)
{
unsigned char *str;
str = stracpy(cast_uchar "");
@@ -447,7 +524,8 @@ static void exec_new_links(struct terminal *term, unsigned char *xterm, unsigned
free(str);
}
-static unsigned char *links_xterm(void)
+static unsigned char *
+links_xterm(void)
{
unsigned char *xterm;
if (!(xterm = cast_uchar getenv("LINKS_XTERM"))) {
@@ -456,13 +534,17 @@ static unsigned char *links_xterm(void)
return xterm;
}
-static int open_in_new_xterm(struct terminal *term, unsigned char *exe, unsigned char *param)
+static int
+open_in_new_xterm(struct terminal *term, unsigned char *exe,
+ unsigned char *param)
{
exec_new_links(term, links_xterm(), exe, param);
return 0;
}
-static int open_in_new_screen(struct terminal *term, unsigned char *exe, unsigned char *param)
+static int
+open_in_new_screen(struct terminal *term, unsigned char *exe,
+ unsigned char *param)
{
exec_new_links(term, cast_uchar "screen", exe, param);
return 0;
@@ -470,15 +552,17 @@ static int open_in_new_screen(struct terminal *term, unsigned char *exe, unsigne
static const struct {
int env;
- int (*open_window_fn)(struct terminal *term, unsigned char *, unsigned char *);
+ int (*open_window_fn)(struct terminal *term, unsigned char *,
+ unsigned char *);
unsigned char *text;
unsigned char *hk;
} oinw[] = {
- {ENV_XWIN, open_in_new_xterm, TEXT_(T_XTERM), TEXT_(T_HK_XTERM)},
- {ENV_SCREEN, open_in_new_screen, TEXT_(T_SCREEN), TEXT_(T_HK_SCREEN)},
+ {ENV_XWIN, open_in_new_xterm, TEXT_(T_XTERM), TEXT_(T_HK_XTERM) },
+ { ENV_SCREEN, open_in_new_screen, TEXT_(T_SCREEN), TEXT_(T_HK_SCREEN)},
};
-struct open_in_new *get_open_in_new(int environment)
+struct open_in_new *
+get_open_in_new(int environment)
{
int i;
struct open_in_new *oin = NULL;
@@ -487,9 +571,11 @@ struct open_in_new *get_open_in_new(int environment)
return NULL;
for (i = 0; i < (int)array_elements(oinw); i++)
if ((environment & oinw[i].env) == oinw[i].env) {
- if ((unsigned)noin > INT_MAX / sizeof(struct open_in_new) - 2)
+ if ((unsigned)noin
+ > INT_MAX / sizeof(struct open_in_new) - 2)
overalloc();
- oin = xrealloc(oin, (noin + 2) * sizeof(struct open_in_new));
+ oin = xrealloc(oin,
+ (noin + 2) * sizeof(struct open_in_new));
oin[noin].text = oinw[i].text;
oin[noin].hk = oinw[i].hk;
oin[noin].open_window_fn = &oinw[i].open_window_fn;
@@ -501,7 +587,8 @@ struct open_in_new *get_open_in_new(int environment)
return oin;
}
-void os_detach_console(void)
+void
+os_detach_console(void)
{
#if !defined(NO_FORK_ON_EXIT)
pid_t rp;
diff --git a/os_dep.h b/os_dep.h
@@ -3,7 +3,11 @@
* This file is a part of the Links program, released under GPL.
*/
-static inline int dir_sep(unsigned char x) { return x == '/'; }
-#define SYSTEM_ID 1
-#define SYSTEM_NAME "Unix"
+static inline int
+dir_sep(unsigned char x)
+{
+ return x == '/';
+}
+#define SYSTEM_ID 1
+#define SYSTEM_NAME "Unix"
#define SHARED_CONFIG_DIR "/etc/"
diff --git a/sched.c b/sched.c
@@ -14,24 +14,25 @@ static int active_connections = 0;
tcount netcfg_stamp = 0;
-struct list_head queue = {&queue, &queue};
+struct list_head queue = { &queue, &queue };
struct h_conn {
- list_entry_1st
- unsigned char *host;
+ list_entry_1st unsigned char *host;
int conn;
};
-static struct list_head h_conns = {&h_conns, &h_conns};
+static struct list_head h_conns = { &h_conns, &h_conns };
-struct list_head keepalive_connections = {&keepalive_connections, &keepalive_connections};
+struct list_head keepalive_connections = { &keepalive_connections,
+ &keepalive_connections };
/* prototypes */
static void send_connection_info(struct connection *c);
static void del_keepalive_socket(struct k_conn *kc);
static void check_keepalive_connections(void);
-unsigned long connect_info(int type)
+unsigned long
+connect_info(int type)
{
int i = 0;
struct connection *ce = NULL;
@@ -40,11 +41,11 @@ unsigned long connect_info(int type)
case CI_FILES:
return list_size(&queue);
case CI_CONNECTING:
- foreach(struct connection, ce, lce, queue)
+ foreach (struct connection, ce, lce, queue)
i += ce->state > S_WAIT && ce->state < S_TRANS;
return i;
case CI_TRANSFER:
- foreach(struct connection, ce, lce, queue)
+ foreach (struct connection, ce, lce, queue)
i += ce->state == S_TRANS;
return i;
case CI_KEEP:
@@ -56,7 +57,8 @@ unsigned long connect_info(int type)
return 0;
}
-static int getpri(struct connection *c)
+static int
+getpri(struct connection *c)
{
int i;
for (i = 0; i < N_PRI; i++)
@@ -66,22 +68,26 @@ static int getpri(struct connection *c)
return N_PRI;
}
-static int connection_disappeared(struct connection *c, tcount count)
+static int
+connection_disappeared(struct connection *c, tcount count)
{
struct connection *d = NULL;
struct list_head *ld;
- foreach(struct connection, d, ld, queue) if (c == d && count == d->count) return 0;
+ foreach (struct connection, d, ld, queue)
+ if (c == d && count == d->count)
+ return 0;
return 1;
}
-static struct h_conn *is_host_on_list(struct connection *c)
+static struct h_conn *
+is_host_on_list(struct connection *c)
{
char *ho = (char *)get_host_name(c->url);
struct h_conn *h = NULL;
struct list_head *lh;
if (!ho)
return NULL;
- foreach(struct h_conn, h, lh, h_conns)
+ foreach (struct h_conn, h, lh, h_conns)
if (!strcmp((const char *)h->host, ho)) {
free(ho);
return h;
@@ -92,7 +98,8 @@ static struct h_conn *is_host_on_list(struct connection *c)
static int st_r = 0;
-static void stat_timer(void *c_)
+static void
+stat_timer(void *c_)
{
struct connection *c = (struct connection *)c_;
struct remaining_info *r = &c->prg;
@@ -101,21 +108,24 @@ static void stat_timer(void *c_)
if (a > SPD_DISP_TIME * 100)
a = SPD_DISP_TIME * 100;
if (getpri(c) == PRI_CANCEL
- && (c->est_length > (long)memory_cache_size * MAX_CACHED_OBJECT
- || c->from > (long)memory_cache_size * MAX_CACHED_OBJECT))
+ && (c->est_length > (long)memory_cache_size * MAX_CACHED_OBJECT
+ || c->from > (long)memory_cache_size * MAX_CACHED_OBJECT))
register_bottom_half(check_queue, NULL);
if (c->state > S_WAIT) {
r->loaded = c->received;
- if ((r->size = c->est_length) < (r->pos = c->from) && r->size != -1)
+ if ((r->size = c->est_length) < (r->pos = c->from)
+ && r->size != -1)
r->size = c->from;
r->dis_b += a;
while (r->dis_b >= SPD_DISP_TIME * CURRENT_SPD_SEC) {
r->cur_loaded -= r->data_in_secs[0];
- memmove(r->data_in_secs, r->data_in_secs + 1, sizeof(off_t) * (CURRENT_SPD_SEC - 1));
+ memmove(r->data_in_secs, r->data_in_secs + 1,
+ sizeof(off_t) * (CURRENT_SPD_SEC - 1));
r->data_in_secs[CURRENT_SPD_SEC - 1] = 0;
r->dis_b -= SPD_DISP_TIME;
}
- r->data_in_secs[CURRENT_SPD_SEC - 1] += r->loaded - r->last_loaded;
+ r->data_in_secs[CURRENT_SPD_SEC - 1] +=
+ r->loaded - r->last_loaded;
r->cur_loaded += r->loaded - r->last_loaded;
r->last_loaded = r->loaded;
r->elapsed += a;
@@ -126,7 +136,8 @@ static void stat_timer(void *c_)
send_connection_info(c);
}
-void setcstate(struct connection *c, int state)
+void
+setcstate(struct connection *c, int state)
{
struct status *stat = NULL;
struct list_head *lstat;
@@ -145,7 +156,8 @@ void setcstate(struct connection *c, int state)
st_r = 1;
stat_timer(c);
st_r = 0;
- if (connection_disappeared(c, count)) return;
+ if (connection_disappeared(c, count))
+ return;
}
} else {
struct remaining_info *r = &c->prg;
@@ -154,7 +166,7 @@ void setcstate(struct connection *c, int state)
r->timer = NULL;
}
}
- foreach(struct status, stat, lstat, c->statuss) {
+ foreach (struct status, stat, lstat, c->statuss) {
stat->state = state;
stat->prev_error = c->prev_error;
}
@@ -162,7 +174,8 @@ void setcstate(struct connection *c, int state)
send_connection_info(c);
}
-static struct k_conn *is_host_on_keepalive_list(struct connection *c)
+static struct k_conn *
+is_host_on_keepalive_list(struct connection *c)
{
char *ho = (char *)get_keepalive_id(c->url);
const int po = get_port(c->url);
@@ -173,9 +186,9 @@ static struct k_conn *is_host_on_keepalive_list(struct connection *c)
return NULL;
if (!ho || po < 0)
return NULL;
- foreach(struct k_conn, h, lh, keepalive_connections)
+ foreach (struct k_conn, h, lh, keepalive_connections)
if (h->protocol == ph && h->port == po
- && !strcmp((char *)h->host, ho)) {
+ && !strcmp((char *)h->host, ho)) {
free(ho);
return h;
}
@@ -183,7 +196,8 @@ static struct k_conn *is_host_on_keepalive_list(struct connection *c)
return NULL;
}
-int get_keepalive_socket(struct connection *c, int *protocol_data)
+int
+get_keepalive_socket(struct connection *c, int *protocol_data)
{
struct k_conn *k;
int cc;
@@ -196,7 +210,8 @@ int get_keepalive_socket(struct connection *c, int *protocol_data)
*protocol_data = k->protocol_data;
freeSSL(c->ssl);
c->ssl = k->ssl;
- memcpy(&c->last_lookup_state, &k->last_lookup_state, sizeof(struct lookup_state));
+ memcpy(&c->last_lookup_state, &k->last_lookup_state,
+ sizeof(struct lookup_state));
del_from_list(k);
free(k->host);
free(k);
@@ -207,19 +222,21 @@ int get_keepalive_socket(struct connection *c, int *protocol_data)
return 0;
}
-static int abort_all_keepalive_connections(void)
+static int
+abort_all_keepalive_connections(void)
{
int did_something = 0;
while (!list_empty(keepalive_connections)) {
- del_keepalive_socket(list_struct(keepalive_connections.next,
- struct k_conn));
+ del_keepalive_socket(
+ list_struct(keepalive_connections.next, struct k_conn));
did_something = 1;
}
check_keepalive_connections();
return did_something;
}
-static void free_connection_data(struct connection *c)
+static void
+free_connection_data(struct connection *c)
{
struct h_conn *h;
int rs;
@@ -256,11 +273,14 @@ static void free_connection_data(struct connection *c)
free(h);
}
} else
- internal("suspending connection that is not on the list (state %d)", c->state);
+ internal("suspending connection that is not on the "
+ "list (state %d)",
+ c->state);
}
}
-static void send_connection_info(struct connection *c)
+static void
+send_connection_info(struct connection *c)
{
if (!list_empty(c->statuss)) {
const int st = c->state;
@@ -268,7 +288,8 @@ static void send_connection_info(struct connection *c)
struct list_head *lstat = c->statuss.next;
while (1) {
int e;
- struct status *xstat = list_struct(lstat, struct status);
+ struct status *xstat =
+ list_struct(lstat, struct status);
xstat->ce = c->cache;
lstat = lstat->next;
e = lstat == &c->statuss;
@@ -280,7 +301,8 @@ static void send_connection_info(struct connection *c)
}
}
-static void del_connection(struct connection *c)
+static void
+del_connection(struct connection *c)
{
struct cache_entry *ce = c->cache;
if (ce)
@@ -300,7 +322,8 @@ static void del_connection(struct connection *c)
free(c);
}
-void add_keepalive_socket(struct connection *c, uttime timeout, int protocol_data)
+void
+add_keepalive_socket(struct connection *c, uttime timeout, int protocol_data)
{
struct k_conn *k;
int rs;
@@ -310,11 +333,10 @@ void add_keepalive_socket(struct connection *c, uttime timeout, int protocol_dat
goto del;
}
k = xmalloc(sizeof(struct k_conn));
- if (c->netcfg_stamp != netcfg_stamp
- || ssl_not_reusable(c->ssl)
- || (k->port = get_port(c->url)) == -1
- || !(k->protocol = get_protocol_handle(c->url))
- || !(k->host = get_keepalive_id(c->url))) {
+ if (c->netcfg_stamp != netcfg_stamp || ssl_not_reusable(c->ssl)
+ || (k->port = get_port(c->url)) == -1
+ || !(k->protocol = get_protocol_handle(c->url))
+ || !(k->host = get_keepalive_id(c->url))) {
free(k);
del_connection(c);
goto clos;
@@ -325,7 +347,8 @@ void add_keepalive_socket(struct connection *c, uttime timeout, int protocol_dat
k->protocol_data = protocol_data;
k->ssl = c->ssl;
c->ssl = NULL;
- memcpy(&k->last_lookup_state, &c->last_lookup_state, sizeof(struct lookup_state));
+ memcpy(&k->last_lookup_state, &c->last_lookup_state,
+ sizeof(struct lookup_state));
add_to_list(keepalive_connections, k);
del:
del_connection(c);
@@ -336,7 +359,8 @@ clos:
register_bottom_half(check_queue, NULL);
}
-static void del_keepalive_socket(struct k_conn *kc)
+static void
+del_keepalive_socket(struct k_conn *kc)
{
int rs;
del_from_list(kc);
@@ -348,13 +372,15 @@ static void del_keepalive_socket(struct k_conn *kc)
static struct timer *keepalive_timeout = NULL;
-static void keepalive_timer(void *x)
+static void
+keepalive_timer(void *x)
{
keepalive_timeout = NULL;
check_keepalive_connections();
}
-static void check_keepalive_connections(void)
+static void
+check_keepalive_connections(void)
{
struct k_conn *kc = NULL;
struct list_head *lkc;
@@ -364,7 +390,7 @@ static void check_keepalive_connections(void)
kill_timer(keepalive_timeout);
keepalive_timeout = NULL;
}
- foreach(struct k_conn, kc, lkc, keepalive_connections) {
+ foreach (struct k_conn, kc, lkc, keepalive_connections) {
if (can_read(kc->conn) || ct - kc->add_time > kc->timeout) {
lkc = lkc->prev;
del_keepalive_socket(kc);
@@ -373,33 +399,39 @@ static void check_keepalive_connections(void)
}
for (; p > MAX_KEEPALIVE_CONNECTIONS; p--)
if (!list_empty(keepalive_connections))
- del_keepalive_socket(list_struct(keepalive_connections.prev, struct k_conn));
+ del_keepalive_socket(list_struct(
+ keepalive_connections.prev, struct k_conn));
else
internal("keepalive list empty");
if (!list_empty(keepalive_connections))
- keepalive_timeout = install_timer(KEEPALIVE_CHECK_TIME, keepalive_timer, NULL);
+ keepalive_timeout =
+ install_timer(KEEPALIVE_CHECK_TIME, keepalive_timer, NULL);
}
-static void add_to_queue(struct connection *c)
+static void
+add_to_queue(struct connection *c)
{
struct connection *cc = NULL;
struct list_head *lcc;
int pri = getpri(c);
- foreach(struct connection, cc, lcc, queue) if (getpri(cc) > pri) break;
+ foreach (struct connection, cc, lcc, queue)
+ if (getpri(cc) > pri)
+ break;
add_before_list_entry(lcc, &c->list_entry);
}
-static void sort_queue(void)
+static void
+sort_queue(void)
{
struct connection *c = NULL, *n;
struct list_head *lc;
int swp;
do {
swp = 0;
- foreach(struct connection, c, lc, queue)
+ foreach (struct connection, c, lc, queue)
if (c->list_entry.next != &queue) {
n = list_struct(c->list_entry.next,
- struct connection);
+ struct connection);
if (getpri(n) < getpri(c)) {
del_from_list(c);
add_after_pos(n, c);
@@ -409,7 +441,8 @@ static void sort_queue(void)
} while (swp);
}
-static void interrupt_connection(struct connection *c)
+static void
+interrupt_connection(struct connection *c)
{
freeSSL(c->ssl);
c->ssl = NULL;
@@ -417,18 +450,20 @@ static void interrupt_connection(struct connection *c)
free_connection_data(c);
}
-static void suspend_connection(struct connection *c)
+static void
+suspend_connection(struct connection *c)
{
interrupt_connection(c);
setcstate(c, S_WAIT);
}
-static int try_to_suspend_connection(struct connection *c, unsigned char *ho)
+static int
+try_to_suspend_connection(struct connection *c, unsigned char *ho)
{
int pri = getpri(c);
struct connection *d = NULL;
struct list_head *ld;
- foreachback(struct connection, d, ld, queue) {
+ foreachback (struct connection, d, ld, queue) {
if (getpri(d) <= pri)
return -1;
if (d->state == S_WAIT)
@@ -451,33 +486,36 @@ static int try_to_suspend_connection(struct connection *c, unsigned char *ho)
return -1;
}
-int is_noproxy_url(unsigned char *url)
+int
+is_noproxy_url(unsigned char *url)
{
unsigned char *host = get_host_name(url);
if (!proxies.only_proxies) {
unsigned char *np = proxies.no_proxy;
int host_l = (int)strlen(cast_const_char host);
- if (*np) while (1) {
- int l = (int)strcspn(cast_const_char np, ",");
- if (l > host_l)
- goto no_match;
- if (l < host_l && host[host_l - l - 1] != '.')
- goto no_match;
- if (casecmp(np, host + (host_l - l), l))
- goto no_match;
- free(host);
- return 1;
+ if (*np)
+ while (1) {
+ int l = (int)strcspn(cast_const_char np, ",");
+ if (l > host_l)
+ goto no_match;
+ if (l < host_l && host[host_l - l - 1] != '.')
+ goto no_match;
+ if (casecmp(np, host + (host_l - l), l))
+ goto no_match;
+ free(host);
+ return 1;
no_match:
- if (!np[l])
- break;
- np += l + 1;
- }
+ if (!np[l])
+ break;
+ np += l + 1;
+ }
}
free(host);
return 0;
}
-static void run_connection(struct connection *c)
+static void
+run_connection(struct connection *c)
{
struct h_conn *hc;
void (*func)(struct connection *);
@@ -492,22 +530,22 @@ static void run_connection(struct connection *c)
c->socks_proxy[0] = 0;
c->dns_append[0] = 0;
} else {
- safe_strncpy((unsigned char *)c->socks_proxy, proxies.socks_proxy,
- sizeof(c->socks_proxy));
+ safe_strncpy((unsigned char *)c->socks_proxy,
+ proxies.socks_proxy, sizeof(c->socks_proxy));
safe_strncpy(c->dns_append, proxies.dns_append,
- sizeof(c->dns_append));
+ sizeof(c->dns_append));
}
if (proxies.only_proxies && !is_proxy_url(c->url)
- && casecmp(c->url, cast_uchar "data:", 5)
- && (!*c->socks_proxy || url_bypasses_socks(c->url))) {
+ && casecmp(c->url, cast_uchar "data:", 5)
+ && (!*c->socks_proxy || url_bypasses_socks(c->url))) {
setcstate(c, S_NO_PROXY);
del_connection(c);
return;
}
if (!(func = get_protocol_handle(c->url))) {
- s_bad_url:
+s_bad_url:
if (is_proxy_url(c->url))
setcstate(c, S_BAD_PROXY);
else
@@ -531,17 +569,19 @@ static void run_connection(struct connection *c)
func(c);
}
-static int is_connection_seekable(struct connection *c)
+static int
+is_connection_seekable(struct connection *c)
{
unsigned char *protocol = get_protocol_name(c->url);
if (!casestrcmp(protocol, cast_uchar "http")
- || !casestrcmp(protocol, cast_uchar "https")
- || !casestrcmp(protocol, cast_uchar "proxy")) {
+ || !casestrcmp(protocol, cast_uchar "https")
+ || !casestrcmp(protocol, cast_uchar "proxy")) {
unsigned char *d;
free(protocol);
if (!c->cache || !c->cache->head)
return 1;
- d = parse_http_header(c->cache->head, cast_uchar "Accept-Ranges", NULL);
+ d = parse_http_header(c->cache->head,
+ cast_uchar "Accept-Ranges", NULL);
if (d) {
free(d);
return 1;
@@ -556,12 +596,15 @@ static int is_connection_seekable(struct connection *c)
return 0;
}
-int is_connection_restartable(struct connection *c)
+int
+is_connection_restartable(struct connection *c)
{
- return !(c->unrestartable >= 2 || (c->tries + 1 >= (max_tries ? max_tries : 1000)));
+ return !(c->unrestartable >= 2
+ || (c->tries + 1 >= (max_tries ? max_tries : 1000)));
}
-int is_last_try(struct connection *c)
+int
+is_last_try(struct connection *c)
{
int is_restartable;
c->tries++;
@@ -570,7 +613,8 @@ int is_last_try(struct connection *c)
return !is_restartable;
}
-void retry_connection(struct connection *c)
+void
+retry_connection(struct connection *c)
{
interrupt_connection(c);
if (!is_connection_restartable(c)) {
@@ -583,7 +627,8 @@ void retry_connection(struct connection *c)
}
}
-void abort_connection(struct connection *c)
+void
+abort_connection(struct connection *c)
{
if (c->running)
interrupt_connection(c);
@@ -591,7 +636,8 @@ void abort_connection(struct connection *c)
register_bottom_half(check_queue, NULL);
}
-static int try_connection(struct connection *c)
+static int
+try_connection(struct connection *c)
{
struct h_conn *hc = NULL;
if ((hc = is_host_on_list(c))) {
@@ -612,24 +658,25 @@ static int try_connection(struct connection *c)
return 1;
}
-void check_queue(void *dummy)
+void
+check_queue(void *dummy)
{
struct connection *c = NULL;
struct list_head *lc;
again:
check_keepalive_connections();
- foreach(struct connection, c, lc, queue) {
+ foreach (struct connection, c, lc, queue) {
struct connection *d = NULL;
struct list_head *ld;
const int cp = getpri(c);
- foreachfrom(struct connection, d, ld, queue, &c->list_entry) {
+ foreachfrom (struct connection, d, ld, queue, &c->list_entry) {
if (getpri(d) != cp)
break;
if (!d->state && is_host_on_keepalive_list(d))
if (try_connection(d))
goto again;
}
- foreachfrom(struct connection, d, ld, queue, &c->list_entry) {
+ foreachfrom (struct connection, d, ld, queue, &c->list_entry) {
if (getpri(d) != cp)
break;
if (!d->state)
@@ -639,15 +686,17 @@ again:
lc = ld->prev;
}
again2:
- foreachback(struct connection, c, lc, queue) {
+ foreachback (struct connection, c, lc, queue) {
if (getpri(c) < PRI_CANCEL)
break;
if (c->state == S_WAIT) {
setcstate(c, S_INTERRUPTED);
del_connection(c);
goto again2;
- } else if (c->est_length > (long)memory_cache_size * MAX_CACHED_OBJECT
- || c->from > (long)memory_cache_size * MAX_CACHED_OBJECT) {
+ } else if (c->est_length
+ > (long)memory_cache_size * MAX_CACHED_OBJECT
+ || c->from > (long)memory_cache_size
+ * MAX_CACHED_OBJECT) {
setcstate(c, S_INTERRUPTED);
abort_connection(c);
goto again2;
@@ -655,7 +704,8 @@ again2:
}
}
-unsigned char *get_proxy_string(unsigned char *url)
+unsigned char *
+get_proxy_string(unsigned char *url)
{
if (is_noproxy_url(url))
return NULL;
@@ -666,7 +716,8 @@ unsigned char *get_proxy_string(unsigned char *url)
return NULL;
}
-unsigned char *get_proxy(unsigned char *url)
+unsigned char *
+get_proxy(unsigned char *url)
{
unsigned char *proxy = get_proxy_string(url);
unsigned char *u;
@@ -680,12 +731,14 @@ unsigned char *get_proxy(unsigned char *url)
return u;
}
-int is_proxy_url(unsigned char *url)
+int
+is_proxy_url(unsigned char *url)
{
return !casecmp(url, cast_uchar "proxy://", 8);
}
-unsigned char *remove_proxy_prefix(unsigned char *url)
+unsigned char *
+remove_proxy_prefix(unsigned char *url)
{
unsigned char *x = NULL;
if (is_proxy_url(url))
@@ -695,26 +748,31 @@ unsigned char *remove_proxy_prefix(unsigned char *url)
return x;
}
-int get_allow_flags(unsigned char *url)
+int
+get_allow_flags(unsigned char *url)
{
- return !casecmp(url, cast_uchar "smb://", 6) ? ALLOW_SMB :
- !casecmp(url, cast_uchar "file://", 7) ? ALLOW_FILE : 0;
+ return !casecmp(url, cast_uchar "smb://", 6) ? ALLOW_SMB
+ : !casecmp(url, cast_uchar "file://", 7) ? ALLOW_FILE
+ : 0;
}
-int disallow_url(unsigned char *url, int allow_flags)
+int
+disallow_url(unsigned char *url, int allow_flags)
{
if (!casecmp(url, cast_uchar "smb://", 6) && !(allow_flags & ALLOW_SMB))
return S_SMB_NOT_ALLOWED;
if (!casecmp(url, cast_uchar "file://", 7)
- && !(allow_flags & ALLOW_FILE))
+ && !(allow_flags & ALLOW_FILE))
return S_FILE_NOT_ALLOWED;
return 0;
}
/* prev_url is a pointer to previous url or NULL */
/* prev_url will NOT be deallocated */
-void load_url(unsigned char *url, unsigned char *prev_url, struct status *stat,
- int pri, int no_cache, int no_compress, int allow_flags, off_t position)
+void
+load_url(unsigned char *url, unsigned char *prev_url, struct status *stat,
+ int pri, int no_cache, int no_compress, int allow_flags,
+ off_t position)
{
struct cache_entry *e = NULL;
struct connection *c = NULL;
@@ -733,7 +791,8 @@ void load_url(unsigned char *url, unsigned char *prev_url, struct status *stat,
if (err) {
if (stat) {
stat->state = err;
- if (stat->end) stat->end(stat, stat->data);
+ if (stat->end)
+ stat->end(stat, stat->data);
}
goto ret;
}
@@ -752,8 +811,8 @@ void load_url(unsigned char *url, unsigned char *prev_url, struct status *stat,
}
if (no_compress) {
unsigned char *enc;
- enc = parse_http_header(e->head,
- cast_uchar "Content-Encoding", NULL);
+ enc = parse_http_header(
+ e->head, cast_uchar "Content-Encoding", NULL);
if (enc) {
free(enc);
e->refcount--;
@@ -780,20 +839,21 @@ skip_cache:
goto ret;
}
u = get_proxy(url);
- foreach(struct connection, c, lc, queue)
- if (!c->detached && !strcmp((const char *)c->url, (const char *)u)) {
+ foreach (struct connection, c, lc, queue)
+ if (!c->detached
+ && !strcmp((const char *)c->url, (const char *)u)) {
if (c->from < position)
continue;
if (no_compress && !c->no_compress) {
unsigned char *enc;
if ((c->state >= S_WAIT && c->state < S_TRANS)
- || !c->cache) {
+ || !c->cache) {
must_detach = 1;
break;
}
- enc = parse_http_header(c->cache->head,
- cast_uchar "Content-Encoding",
- NULL);
+ enc = parse_http_header(
+ c->cache->head,
+ cast_uchar "Content-Encoding", NULL);
if (enc) {
free(enc);
must_detach = 1;
@@ -831,7 +891,7 @@ skip_cache:
struct fragment *frag = NULL;
struct list_head *lfrag;
c->from = 0;
- foreach(struct fragment, frag, lfrag, e->frag) {
+ foreach (struct fragment, frag, lfrag, e->frag) {
if (frag->offset != c->from)
break;
c->from += frag->length;
@@ -851,7 +911,8 @@ skip_cache:
c->cache = NULL;
c->est_length = -1;
c->unrestartable = 0;
- c->no_compress = http_options.no_compression || no_compress || dmp == D_SOURCE;
+ c->no_compress =
+ http_options.no_compression || no_compress || dmp == D_SOURCE;
c->prg.timer = NULL;
c->timer = NULL;
if (position || must_detach) {
@@ -884,7 +945,8 @@ ret:
return;
}
-void change_connection(struct status *oldstat, struct status *newstat, int newpri)
+void
+change_connection(struct status *oldstat, struct status *newstat, int newpri)
{
struct connection *c;
const int oldpri = oldstat->pri;
@@ -928,7 +990,9 @@ void change_connection(struct status *oldstat, struct status *newstat, int newpr
register_bottom_half(check_queue, NULL);
}
-void detach_connection(struct status *stat, off_t pos, int want_to_restart, int dont_check_refcount)
+void
+detach_connection(struct status *stat, off_t pos, int want_to_restart,
+ int dont_check_refcount)
{
struct connection *c;
int i, n_users;
@@ -948,7 +1012,8 @@ void detach_connection(struct status *stat, off_t pos, int want_to_restart, int
else
l = c->est_length;
if (!dont_check_refcount
- && l < (long)memory_cache_size * MAX_CACHED_OBJECT && !want_to_restart)
+ && l < (long)memory_cache_size * MAX_CACHED_OBJECT
+ && !want_to_restart)
return;
n_users = 0;
for (i = 0; i < PRI_CANCEL; i++)
@@ -975,11 +1040,13 @@ detach_done:
}
}
-static uttime get_timeout_value(struct connection *c)
+static uttime
+get_timeout_value(struct connection *c)
{
uttime t;
if (c->state == S_CONN || c->state == S_CONN_ANOTHER)
- t = timeout_multiple_addresses * (c->tries < 1 ? 1 : c->tries + 1);
+ t = timeout_multiple_addresses
+ * (c->tries < 1 ? 1 : c->tries + 1);
else if (c->unrestartable)
t = unrestartable_receive_timeout;
else
@@ -988,7 +1055,8 @@ static uttime get_timeout_value(struct connection *c)
return t;
}
-static void connection_timeout(void *c_)
+static void
+connection_timeout(void *c_)
{
struct connection *c = (struct connection *)c_;
c->timer = NULL;
@@ -1000,13 +1068,15 @@ static void connection_timeout(void *c_)
retry_connection(c);
}
-static void connection_timeout_1(void *c_)
+static void
+connection_timeout_1(void *c_)
{
struct connection *c = (struct connection *)c_;
c->timer = install_timer(get_timeout_value(c), connection_timeout, c);
}
-void clear_connection_timeout(struct connection *c)
+void
+clear_connection_timeout(struct connection *c)
{
if (c->timer) {
kill_timer(c->timer);
@@ -1014,39 +1084,45 @@ void clear_connection_timeout(struct connection *c)
}
}
-void set_connection_timeout(struct connection *c)
+void
+set_connection_timeout(struct connection *c)
{
clear_connection_timeout(c);
c->timer = install_timer(get_timeout_value(c), connection_timeout_1, c);
}
-void set_connection_timeout_keepal(struct connection *c)
+void
+set_connection_timeout_keepal(struct connection *c)
{
if (c->keepalive && !c->unrestartable) {
clear_connection_timeout(c);
- c->timer = install_timer(timeout_multiple_addresses * 1000, connection_timeout, c);
+ c->timer = install_timer(timeout_multiple_addresses * 1000,
+ connection_timeout, c);
return;
}
set_connection_timeout(c);
}
-void abort_all_connections(void)
+void
+abort_all_connections(void)
{
while (!list_empty(queue)) {
- struct connection *c = list_struct(queue.next, struct connection);
+ struct connection *c =
+ list_struct(queue.next, struct connection);
setcstate(c, S_INTERRUPTED);
abort_connection(c);
}
abort_all_keepalive_connections();
}
-int abort_background_connections(void)
+int
+abort_background_connections(void)
{
int did_something = 0;
struct connection *c = NULL;
struct list_head *lc;
again:
- foreach(struct connection, c, lc, queue) {
+ foreach (struct connection, c, lc, queue) {
if (getpri(c) >= PRI_CANCEL) {
setcstate(c, S_INTERRUPTED);
abort_connection(c);
@@ -1057,30 +1133,31 @@ again:
return did_something | abort_all_keepalive_connections();
}
-int is_entry_used(struct cache_entry *e)
+int
+is_entry_used(struct cache_entry *e)
{
struct connection *c = NULL;
struct list_head *lc;
- foreach(struct connection, c, lc, queue)
+ foreach (struct connection, c, lc, queue)
if (c->cache == e)
return 1;
return 0;
}
struct blacklist_entry {
- list_entry_1st
- int flags;
+ list_entry_1st int flags;
unsigned char host[1];
};
static struct list_head blacklist = { &blacklist, &blacklist };
-void add_blacklist_entry(unsigned char *host, int flags)
+void
+add_blacklist_entry(unsigned char *host, int flags)
{
struct blacklist_entry *b = NULL;
struct list_head *lb;
size_t sl;
- foreach(struct blacklist_entry, b, lb, blacklist)
+ foreach (struct blacklist_entry, b, lb, blacklist)
if (!casestrcmp(host, b->host)) {
b->flags |= flags;
return;
@@ -1094,11 +1171,12 @@ void add_blacklist_entry(unsigned char *host, int flags)
add_to_list(blacklist, b);
}
-void del_blacklist_entry(unsigned char *host, int flags)
+void
+del_blacklist_entry(unsigned char *host, int flags)
{
struct blacklist_entry *b = NULL;
struct list_head *lb;
- foreach(struct blacklist_entry, b, lb, blacklist)
+ foreach (struct blacklist_entry, b, lb, blacklist)
if (!casestrcmp(host, b->host)) {
b->flags &= ~flags;
if (!b->flags) {
@@ -1109,17 +1187,19 @@ void del_blacklist_entry(unsigned char *host, int flags)
}
}
-int get_blacklist_flags(unsigned char *host)
+int
+get_blacklist_flags(unsigned char *host)
{
struct blacklist_entry *b = NULL;
struct list_head *lb;
- foreach(struct blacklist_entry, b, lb, blacklist)
+ foreach (struct blacklist_entry, b, lb, blacklist)
if (!casestrcmp(host, b->host))
return b->flags;
return 0;
}
-void free_blacklist(void)
+void
+free_blacklist(void)
{
free_list(struct blacklist_entry, blacklist);
}
diff --git a/select.c b/select.c
@@ -9,13 +9,13 @@
#include "links.h"
#if defined(evtimer_set) && !defined(timeout_set)
-#define timeout_set evtimer_set
+ #define timeout_set evtimer_set
#endif
#if defined(evtimer_add) && !defined(timeout_add)
-#define timeout_add evtimer_add
+ #define timeout_add evtimer_add
#endif
#if defined(evtimer_del) && !defined(timeout_del)
-#define timeout_del evtimer_del
+ #define timeout_del evtimer_del
#endif
struct thread {
@@ -38,16 +38,15 @@ static fd_set x_write;
static int w_max;
struct timer {
- list_entry_1st
- uttime interval;
+ list_entry_1st uttime interval;
void (*func)(void *);
void *data;
};
static struct list_head timers = { &timers, &timers };
-
-void portable_sleep(unsigned msec)
+void
+portable_sleep(unsigned msec)
{
struct timeval tv;
int rs;
@@ -58,7 +57,8 @@ void portable_sleep(unsigned msec)
unblock_signals();
}
-static int can_do_io(int fd, int wr, int sec)
+static int
+can_do_io(int fd, int wr, int sec)
{
fd_set fds;
struct timeval tv, *tvp;
@@ -72,13 +72,14 @@ static int can_do_io(int fd, int wr, int sec)
p.events = !wr ? POLLIN : POLLOUT;
EINTRLOOP(rs, poll(&p, 1, sec < 0 ? -1 : sec * 1000));
if (rs < 0)
- die("poll for %s (%d) failed: %s", !wr ? "read" : "write", fd, strerror(errno));
+ die("poll for %s (%d) failed: %s", !wr ? "read" : "write", fd,
+ strerror(errno));
if (!rs)
return 0;
if (p.revents & POLLNVAL)
goto fallback;
return 1;
- fallback:
+fallback:
if (sec >= 0) {
tv.tv_sec = sec;
tv.tv_usec = 0;
@@ -94,27 +95,31 @@ static int can_do_io(int fd, int wr, int sec)
else
EINTRLOOP(rs, select(fd + 1, NULL, &fds, NULL, tvp));
if (rs < 0)
- die("select for %s (%d) failed: %s\n", !wr ? "read" : "write", fd, strerror(errno));
+ die("select for %s (%d) failed: %s\n", !wr ? "read" : "write",
+ fd, strerror(errno));
return rs;
}
-int can_write(int fd)
+int
+can_write(int fd)
{
return can_do_io(fd, 1, 0);
}
-int can_read_timeout(int fd, int sec)
+int
+can_read_timeout(int fd, int sec)
{
return can_do_io(fd, 0, sec);
}
-int can_read(int fd)
+int
+can_read(int fd)
{
return can_do_io(fd, 0, 0);
}
-
-int close_stderr(void)
+int
+close_stderr(void)
{
int n, h, rs;
fflush(stderr);
@@ -138,7 +143,8 @@ fail1:
return -1;
}
-void restore_stderr(int h)
+void
+restore_stderr(int h)
{
int rs;
fflush(stderr);
@@ -148,8 +154,8 @@ void restore_stderr(int h)
EINTRLOOP(rs, close(h));
}
-
-unsigned long select_info(int type)
+unsigned long
+select_info(int type)
{
int i, j;
switch (type) {
@@ -168,18 +174,18 @@ unsigned long select_info(int type)
}
struct bottom_half {
- list_entry_1st
- void (*fn)(void *);
+ list_entry_1st void (*fn)(void *);
void *data;
};
static struct list_head bottom_halves = { &bottom_halves, &bottom_halves };
-void register_bottom_half(void (*fn)(void *), void *data)
+void
+register_bottom_half(void (*fn)(void *), void *data)
{
struct bottom_half *bh = NULL;
struct list_head *lbh;
- foreach(struct bottom_half, bh, lbh, bottom_halves)
+ foreach (struct bottom_half, bh, lbh, bottom_halves)
if (bh->fn == fn && bh->data == data)
return;
bh = xmalloc(sizeof(struct bottom_half));
@@ -188,11 +194,12 @@ void register_bottom_half(void (*fn)(void *), void *data)
add_to_list(bottom_halves, bh);
}
-void unregister_bottom_half(void (*fn)(void *), void *data)
+void
+unregister_bottom_half(void (*fn)(void *), void *data)
{
struct bottom_half *bh = NULL;
struct list_head *lbh;
- foreach(struct bottom_half, bh, lbh, bottom_halves)
+ foreach (struct bottom_half, bh, lbh, bottom_halves)
if (bh->fn == fn && bh->data == data) {
del_from_list(bh);
free(bh);
@@ -200,30 +207,33 @@ void unregister_bottom_half(void (*fn)(void *), void *data)
}
}
-void check_bottom_halves(void)
+void
+check_bottom_halves(void)
{
struct bottom_half *bh;
void (*fn)(void *);
void *data;
- rep:
- if (list_empty(bottom_halves)) return;
+rep:
+ if (list_empty(bottom_halves))
+ return;
bh = list_struct(bottom_halves.prev, struct bottom_half);
fn = bh->fn;
data = bh->data;
del_from_list(bh);
free(bh);
- pr(fn(data)) {
- };
+ pr(fn(data)){};
goto rep;
}
-#define CHK_BH if (!list_empty(bottom_halves)) check_bottom_halves()
+#define CHK_BH \
+ if (!list_empty(bottom_halves)) \
+ check_bottom_halves()
-
-static void restrict_fds(void)
+static void
+restrict_fds(void)
{
#if defined(RLIMIT_OFILE) && !defined(RLIMIT_NOFILE)
-#define RLIMIT_NOFILE RLIMIT_OFILE
+ #define RLIMIT_NOFILE RLIMIT_OFILE
#endif
#if defined(RLIMIT_NOFILE)
struct rlimit limit;
@@ -245,26 +255,29 @@ int sh_line;
static int event_enabled = 0;
#ifndef HAVE_EVENT_GET_STRUCT_EVENT_SIZE
-#define sizeof_struct_event sizeof(struct event)
+ #define sizeof_struct_event sizeof(struct event)
#else
-#define sizeof_struct_event (event_get_struct_event_size())
+ #define sizeof_struct_event (event_get_struct_event_size())
#endif
-static inline struct event *timer_event(struct timer *tm)
+static inline struct event *
+timer_event(struct timer *tm)
{
return (struct event *)((unsigned char *)tm - sizeof_struct_event);
}
static struct event_base *event_base;
-static void event_callback(int h, short ev, void *data)
+static void
+event_callback(int h, short ev, void *data)
{
#ifndef EV_PERSIST
if (event_add((struct event *)data, NULL) == -1)
die("event_add: %s\n", strerror(errno));
#endif
if (!(ev & EV_READ) == !(ev & EV_WRITE))
- die("event_callback: invalid flags %d on handle %d\n", (int)ev, h);
+ die("event_callback: invalid flags %d on handle %d\n", (int)ev,
+ h);
if (ev & EV_READ) {
#if defined(HAVE_LIBEV)
/* Old versions of libev badly interact with fork and fire
@@ -272,7 +285,9 @@ static void event_callback(int h, short ev, void *data)
if (ev_version_major() < 4 && !can_read(h))
return;
#endif
- pr(threads[h].read_func(threads[h].data)) { }
+ pr(threads[h].read_func(threads[h].data))
+ {
+ }
} else {
#if defined(HAVE_LIBEV)
/* Old versions of libev badly interact with fork and fire
@@ -280,20 +295,27 @@ static void event_callback(int h, short ev, void *data)
if (ev_version_major() < 4 && !can_write(h))
return;
#endif
- pr(threads[h].write_func(threads[h].data)) { }
+ pr(threads[h].write_func(threads[h].data))
+ {
+ }
}
CHK_BH;
}
-static void timer_callback(int h, short ev, void *data)
+static void
+timer_callback(int h, short ev, void *data)
{
struct timer *tm = data;
- pr(tm->func(tm->data)) { }
+ pr(tm->func(tm->data))
+ {
+ }
kill_timer(tm);
CHK_BH;
}
-static void set_event_for_action(int h, void (*func)(void *), struct event **evptr, short evtype)
+static void
+set_event_for_action(int h, void (*func)(void *), struct event **evptr,
+ short evtype)
{
if (func) {
if (!*evptr) {
@@ -303,25 +325,32 @@ static void set_event_for_action(int h, void (*func)(void *), struct event **evp
*evptr = xmalloc(sizeof_struct_event);
event_set(*evptr, h, evtype, event_callback, *evptr);
if (event_base_set(event_base, *evptr) == -1)
- die("event_base_set: %s at %s:%d, handle %d\n", strerror(errno), sh_file, sh_line, h);
+ die("event_base_set: %s at %s:%d, handle %d\n",
+ strerror(errno), sh_file, sh_line, h);
}
if (event_add(*evptr, NULL) == -1)
- die("event_add: %s at %s:%d, handle %d\n", strerror(errno), sh_file, sh_line, h);
+ die("event_add: %s at %s:%d, handle %d\n",
+ strerror(errno), sh_file, sh_line, h);
} else {
if (*evptr) {
if (event_del(*evptr) == -1)
- die("event_del: %s at %s:%d, handle %d\n", strerror(errno), sh_file, sh_line, h);
+ die("event_del: %s at %s:%d, handle %d\n",
+ strerror(errno), sh_file, sh_line, h);
}
}
}
-static void set_events_for_handle(int h)
+static void
+set_events_for_handle(int h)
{
- set_event_for_action(h, threads[h].read_func, &threads[h].read_event, EV_READ);
- set_event_for_action(h, threads[h].write_func, &threads[h].write_event, EV_WRITE);
+ set_event_for_action(h, threads[h].read_func, &threads[h].read_event,
+ EV_READ);
+ set_event_for_action(h, threads[h].write_func, &threads[h].write_event,
+ EV_WRITE);
}
-static void set_event_for_timer(struct timer *tm)
+static void
+set_event_for_timer(struct timer *tm)
{
struct timeval tv;
struct event *ev = timer_event(tm);
@@ -340,7 +369,8 @@ static void set_event_for_timer(struct timer *tm)
die("timeout_add: %s\n", strerror(errno));
}
-static void enable_libevent(void)
+static void
+enable_libevent(void)
{
int i;
struct timer *tm = NULL;
@@ -359,18 +389,21 @@ static void enable_libevent(void)
for (i = 0; i < w_max; i++)
set_events_for_handle(i);
- foreach(struct timer, tm, ltm, timers)
+ foreach (struct timer, tm, ltm, timers)
set_event_for_timer(tm);
}
-static void terminate_libevent(void)
+static void
+terminate_libevent(void)
{
int i;
if (event_enabled) {
for (i = 0; i < n_threads; i++) {
- set_event_for_action(i, NULL, &threads[i].read_event, EV_READ);
+ set_event_for_action(i, NULL, &threads[i].read_event,
+ EV_READ);
free(threads[i].read_event);
- set_event_for_action(i, NULL, &threads[i].write_event, EV_WRITE);
+ set_event_for_action(i, NULL, &threads[i].write_event,
+ EV_WRITE);
free(threads[i].write_event);
}
event_base_free(event_base);
@@ -378,7 +411,8 @@ static void terminate_libevent(void)
}
}
-static void do_event_loop(int flags)
+static void
+do_event_loop(int flags)
{
int e;
e = event_base_loop(event_base, flags);
@@ -386,10 +420,12 @@ static void do_event_loop(int flags)
die("event_base_loop: %s\n", strerror(errno));
}
-void add_event_string(unsigned char **s, int *l, struct terminal *term)
+void
+add_event_string(unsigned char **s, int *l, struct terminal *term)
{
if (!event_enabled)
- add_to_str(s, l, get_text_translation(TEXT_(T_SELECT_SYSCALL), term));
+ add_to_str(s, l,
+ get_text_translation(TEXT_(T_SELECT_SYSCALL), term));
if (!event_enabled)
add_to_str(s, l, cast_uchar " (");
#if defined(HAVE_LIBEV)
@@ -400,14 +436,15 @@ void add_event_string(unsigned char **s, int *l, struct terminal *term)
add_chr_to_str(s, l, ' ');
{
#if defined(HAVE_LIBEV)
- /* old libev report bogus version */
- if (!casestrcmp(cast_uchar event_get_version(), cast_uchar "EV_VERSION_MAJOR.EV_VERSION_MINOR")) {
+ /* old libev report bogus version */
+ if (!casestrcmp(cast_uchar event_get_version(), cast_uchar
+ "EV_VERSION_MAJOR.EV_VERSION_MINOR")) {
add_num_to_str(s, l, ev_version_major());
add_chr_to_str(s, l, '.');
add_num_to_str(s, l, ev_version_minor());
} else
#endif
- add_to_str(s, l, cast_uchar event_get_version());
+ add_to_str(s, l, cast_uchar event_get_version());
}
if (!event_enabled) {
add_chr_to_str(s, l, ' ');
@@ -419,15 +456,15 @@ void add_event_string(unsigned char **s, int *l, struct terminal *term)
}
}
-
static uttime last_time;
-static void check_timers(void)
+static void
+check_timers(void)
{
uttime interval = get_time() - last_time;
struct timer *t = NULL;
struct list_head *lt;
- foreach(struct timer, t, lt, timers) {
+ foreach (struct timer, t, lt, timers) {
if (t->interval < interval)
t->interval = 0;
else
@@ -444,7 +481,8 @@ static void check_timers(void)
last_time += interval;
}
-struct timer *install_timer(uttime t, void (*func)(void *), void *data)
+struct timer *
+install_timer(uttime t, void (*func)(void *), void *data)
{
struct timer *tm;
unsigned char *q = xmalloc(sizeof_struct_event + sizeof(struct timer));
@@ -458,13 +496,16 @@ struct timer *install_timer(uttime t, void (*func)(void *), void *data)
} else {
struct timer *tt = NULL;
struct list_head *ltt;
- foreach(struct timer, tt, ltt, timers) if (tt->interval >= t) break;
+ foreach (struct timer, tt, ltt, timers)
+ if (tt->interval >= t)
+ break;
add_before_list_entry(ltt, &tm->list_entry);
}
return tm;
}
-void kill_timer(struct timer *tm)
+void
+kill_timer(struct timer *tm)
{
del_from_list(tm);
if (event_enabled)
@@ -479,14 +520,17 @@ void (*get_handler(int fd, int tp))(void *)
if (fd >= w_max)
return NULL;
switch (tp) {
- case H_READ: return threads[fd].read_func;
- case H_WRITE: return threads[fd].write_func;
+ case H_READ:
+ return threads[fd].read_func;
+ case H_WRITE:
+ return threads[fd].write_func;
}
die("get_handler: bad type %d\n", tp);
return NULL;
}
-void *get_handler_data(int fd)
+void *
+get_handler_data(int fd)
{
if (fd < 0)
die("get_handler: handle %d\n", fd);
@@ -495,29 +539,36 @@ void *get_handler_data(int fd)
return threads[fd].data;
}
-void set_handlers_file_line(int fd, void (*read_func)(void *), void (*write_func)(void *), void *data)
+void
+set_handlers_file_line(int fd, void (*read_func)(void *),
+ void (*write_func)(void *), void *data)
{
if (fd < 0)
goto invl;
if (!event_enabled)
if (fd >= (int)FD_SETSIZE) {
- die("too big handle %d at %s:%d\n", fd, sh_file, sh_line);
+ die("too big handle %d at %s:%d\n", fd, sh_file,
+ sh_line);
return;
}
if (fd >= n_threads) {
- if ((unsigned)fd > (unsigned)INT_MAX / sizeof(struct thread) - 1)
+ if ((unsigned)fd
+ > (unsigned)INT_MAX / sizeof(struct thread) - 1)
overalloc();
threads = xrealloc(threads, (fd + 1) * sizeof(struct thread));
- memset(threads + n_threads, 0, (fd + 1 - n_threads) * sizeof(struct thread));
+ memset(threads + n_threads, 0,
+ (fd + 1 - n_threads) * sizeof(struct thread));
n_threads = fd + 1;
}
- if (threads[fd].read_func == read_func && threads[fd].write_func == write_func && threads[fd].data == data)
+ if (threads[fd].read_func == read_func
+ && threads[fd].write_func == write_func && threads[fd].data == data)
return;
threads[fd].read_func = read_func;
threads[fd].write_func = write_func;
threads[fd].data = data;
if (read_func || write_func) {
- if (fd >= w_max) w_max = fd + 1;
+ if (fd >= w_max)
+ w_max = fd + 1;
} else if (fd == w_max - 1) {
int i;
for (i = fd - 1; i >= 0; i--)
@@ -529,12 +580,14 @@ void set_handlers_file_line(int fd, void (*read_func)(void *), void (*write_func
set_events_for_handle(fd);
return;
}
- if (read_func) FD_SET(fd, &w_read);
+ if (read_func)
+ FD_SET(fd, &w_read);
else {
FD_CLR(fd, &w_read);
FD_CLR(fd, &x_read);
}
- if (write_func) FD_SET(fd, &w_write);
+ if (write_func)
+ FD_SET(fd, &w_write);
else {
FD_CLR(fd, &w_write);
FD_CLR(fd, &x_write);
@@ -542,10 +595,12 @@ void set_handlers_file_line(int fd, void (*read_func)(void *), void (*write_func
return;
invl:
- die("invalid set_handlers call at %s:%d: %d, %p, %p, %p\n", sh_file, sh_line, fd, read_func, write_func, data);
+ die("invalid set_handlers call at %s:%d: %d, %p, %p, %p\n", sh_file,
+ sh_line, fd, read_func, write_func, data);
}
-void clear_events(int h, int blocking)
+void
+clear_events(int h, int blocking)
{
#if !defined(O_NONBLOCK) && !defined(FIONBIO)
blocking = 1;
@@ -554,17 +609,19 @@ void clear_events(int h, int blocking)
unsigned char c[64];
int rd;
EINTRLOOP(rd, (int)read(h, c, sizeof c));
- if (rd != sizeof c) break;
+ if (rd != sizeof c)
+ break;
}
}
#if defined(NSIG) && NSIG > 32
-#define NUM_SIGNALS NSIG
+ #define NUM_SIGNALS NSIG
#else
-#define NUM_SIGNALS 32
+ #define NUM_SIGNALS 32
#endif
-static void clear_events_ptr(void *handle)
+static void
+clear_events_ptr(void *handle)
{
clear_events((int)(long)handle, 0);
}
@@ -581,19 +638,22 @@ static volatile struct signal_handler signal_handlers[NUM_SIGNALS];
static pid_t signal_pid;
int signal_pipe[2];
-static void got_signal(int sig)
+static void
+got_signal(int sig)
{
void (*fn)(void *);
int sv_errno = errno;
- /*fprintf(stderr, "ERROR: signal number: %d\n", sig);*/
+ /*fprintf(stderr, "ERROR: signal number: %d\n", sig);*/
/* if we get signal from a forked child, don't do anything */
- if (getpid() != signal_pid) goto ret;
+ if (getpid() != signal_pid)
+ goto ret;
if (sig >= NUM_SIGNALS || sig < 0)
goto ret;
fn = signal_handlers[sig].fn;
- if (!fn) goto ret;
+ if (!fn)
+ goto ret;
if (signal_handlers[sig].critical) {
fn(signal_handlers[sig].data);
goto ret;
@@ -603,13 +663,14 @@ static void got_signal(int sig)
int wr;
EINTRLOOP(wr, (int)write(signal_pipe[1], "", 1));
}
- ret:
+ret:
errno = sv_errno;
}
static struct sigaction sa_zero;
-void install_signal_handler(int sig, void (*fn)(void *), void *data, int critical)
+void
+install_signal_handler(int sig, void (*fn)(void *), void *data, int critical)
{
int rs;
struct sigaction sa = sa_zero;
@@ -617,8 +678,10 @@ void install_signal_handler(int sig, void (*fn)(void *), void *data, int critica
die("bad signal number: %d\n", sig);
return;
}
- if (!fn) sa.sa_handler = SIG_IGN;
- else sa.sa_handler = (void (*)(int))got_signal;
+ if (!fn)
+ sa.sa_handler = SIG_IGN;
+ else
+ sa.sa_handler = (void (*)(int))got_signal;
sigfillset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
if (!fn)
@@ -630,7 +693,8 @@ void install_signal_handler(int sig, void (*fn)(void *), void *data, int critica
EINTRLOOP(rs, sigaction(sig, &sa, NULL));
}
-void interruptible_signal(int sig, int in)
+void
+interruptible_signal(int sig, int in)
{
struct sigaction sa = sa_zero;
int rs;
@@ -638,23 +702,28 @@ void interruptible_signal(int sig, int in)
die("bad signal number: %d\n", sig);
return;
}
- if (!signal_handlers[sig].fn) return;
+ if (!signal_handlers[sig].fn)
+ return;
sa.sa_handler = (void (*)(int))got_signal;
sigfillset(&sa.sa_mask);
- if (!in) sa.sa_flags = SA_RESTART;
+ if (!in)
+ sa.sa_flags = SA_RESTART;
EINTRLOOP(rs, sigaction(sig, &sa, NULL));
}
static sigset_t sig_old_mask;
static int sig_unblock = 0;
-void block_signals(int except1, int except2)
+void
+block_signals(int except1, int except2)
{
int rs;
sigset_t mask;
sigfillset(&mask);
- if (except1) sigdelset(&mask, except1);
- if (except2) sigdelset(&mask, except2);
+ if (except1)
+ sigdelset(&mask, except1);
+ if (except2)
+ sigdelset(&mask, except2);
#ifdef SIGILL
sigdelset(&mask, SIGILL);
#endif
@@ -671,10 +740,12 @@ void block_signals(int except1, int except2)
sigdelset(&mask, SIGBUS);
#endif
EINTRLOOP(rs, sigprocmask(SIG_BLOCK, &mask, &sig_old_mask));
- if (!rs) sig_unblock = 1;
+ if (!rs)
+ sig_unblock = 1;
}
-void unblock_signals(void)
+void
+unblock_signals(void)
{
int rs;
if (sig_unblock) {
@@ -683,7 +754,8 @@ void unblock_signals(void)
}
}
-static int check_signals(void)
+static int
+check_signals(void)
{
int r = 0;
int i;
@@ -691,8 +763,10 @@ static int check_signals(void)
if (signal_mask[i]) {
signal_mask[i] = 0;
if (signal_handlers[i].fn) {
- pr(signal_handlers[i].fn(signal_handlers[i].data)) {
-}
+ pr(signal_handlers[i].fn(
+ signal_handlers[i].data))
+ {
+ }
}
CHK_BH;
r = 1;
@@ -701,29 +775,33 @@ static int check_signals(void)
}
#ifdef SIGCHLD
-static void sigchld(void *p)
+static void
+sigchld(void *p)
{
pid_t pid;
-#ifndef WNOHANG
+ #ifndef WNOHANG
EINTRLOOP(pid, wait(NULL));
-#else
+ #else
do {
EINTRLOOP(pid, waitpid(-1, NULL, WNOHANG));
} while (pid > 0);
-#endif
+ #endif
}
-void set_sigcld(void)
+void
+set_sigcld(void)
{
install_signal_handler(SIGCHLD, sigchld, NULL, 1);
}
#else
-void set_sigcld(void)
+void
+set_sigcld(void)
{
}
#endif
-void reinit_child(void)
+void
+reinit_child(void)
{
signal_pid = getpid();
if (event_enabled) {
@@ -734,7 +812,8 @@ void reinit_child(void)
int terminate_loop = 0;
-void select_loop(void (*init)(void))
+void
+select_loop(void (*init)(void))
{
memset(&sa_zero, 0, sizeof sa_zero);
@@ -750,7 +829,8 @@ void select_loop(void (*init)(void))
die("can't create pipe for signal handling\n");
set_nonblock(signal_pipe[0]);
set_nonblock(signal_pipe[1]);
- set_handlers(signal_pipe[0], clear_events_ptr, NULL, (void *)(long)signal_pipe[0]);
+ set_handlers(signal_pipe[0], clear_events_ptr, NULL,
+ (void *)(long)signal_pipe[0]);
init();
CHK_BH;
enable_libevent();
@@ -763,58 +843,69 @@ void select_loop(void (*init)(void))
do_event_loop(EVLOOP_NONBLOCK);
check_signals();
redraw_all_terminals();
- if (terminate_loop) break;
+ if (terminate_loop)
+ break;
do_event_loop(EVLOOP_ONCE);
}
} else
- while (!terminate_loop) {
- volatile int n; /* volatile because of setjmp */
- int i;
- struct timeval tv;
- struct timeval *tm = NULL;
- check_signals();
- check_timers();
- redraw_all_terminals();
- if (!list_empty(timers)) {
- uttime tt = list_struct(timers.next, struct timer)->interval + 1;
- tv.tv_sec = tt / 1000 < INT_MAX ? (int)(tt / 1000) : INT_MAX;
+ while (!terminate_loop) {
+ volatile int n; /* volatile because of setjmp */
+ int i;
+ struct timeval tv;
+ struct timeval *tm = NULL;
+ check_signals();
+ check_timers();
+ redraw_all_terminals();
+ if (!list_empty(timers)) {
+ uttime tt =
+ list_struct(timers.next, struct timer)
+ ->interval
+ + 1;
+ tv.tv_sec = tt / 1000 < INT_MAX
+ ? (int)(tt / 1000)
+ : INT_MAX;
tv.tv_usec = (tt % 1000) * 1000;
tm = &tv;
- }
- memcpy(&x_read, &w_read, sizeof(fd_set));
- memcpy(&x_write, &w_write, sizeof(fd_set));
- if (terminate_loop) break;
- if ((n = select(w_max, &x_read, &x_write, NULL, tm)) < 0) {
- if (errno != EINTR)
- die("select: %s\n", strerror(errno));
- continue;
- }
- check_signals();
- check_timers();
- i = -1;
- while (n > 0 && ++i < w_max) {
- int k = 0;
- if (FD_ISSET(i, &x_read)) {
- if (threads[i].read_func) {
- pr(threads[i].read_func(threads[i].data)) continue;
- CHK_BH;
- }
- k = 1;
}
- if (FD_ISSET(i, &x_write)) {
- if (threads[i].write_func) {
- pr(threads[i].write_func(threads[i].data)) continue;
- CHK_BH;
+ memcpy(&x_read, &w_read, sizeof(fd_set));
+ memcpy(&x_write, &w_write, sizeof(fd_set));
+ if (terminate_loop)
+ break;
+ if ((n = select(w_max, &x_read, &x_write, NULL, tm))
+ < 0) {
+ if (errno != EINTR)
+ die("select: %s\n", strerror(errno));
+ continue;
+ }
+ check_signals();
+ check_timers();
+ i = -1;
+ while (n > 0 && ++i < w_max) {
+ int k = 0;
+ if (FD_ISSET(i, &x_read)) {
+ if (threads[i].read_func) {
+ pr(threads[i].read_func(
+ threads[i].data)) continue;
+ CHK_BH;
+ }
+ k = 1;
}
- k = 1;
+ if (FD_ISSET(i, &x_write)) {
+ if (threads[i].write_func) {
+ pr(threads[i].write_func(
+ threads[i].data)) continue;
+ CHK_BH;
+ }
+ k = 1;
+ }
+ n -= k;
}
- n -= k;
}
- }
}
-void terminate_select(void)
+void
+terminate_select(void)
{
terminate_libevent();
free(threads);
diff --git a/session.c b/session.c
@@ -7,7 +7,7 @@
#include "links.h"
-struct list_head downloads = {&downloads, &downloads};
+struct list_head downloads = { &downloads, &downloads };
/* prototypes */
static void abort_and_delete_download(void *);
@@ -17,17 +17,20 @@ static void copy_additional_files(struct additional_files **a);
static struct location *new_location(void);
static void destroy_location(struct location *loc);
-
-int are_there_downloads(void)
+int
+are_there_downloads(void)
{
struct download *down = NULL;
struct list_head *ldown;
- foreach(struct download, down, ldown, downloads) if (!down->prog) return 1;
+ foreach (struct download, down, ldown, downloads)
+ if (!down->prog)
+ return 1;
return 0;
}
-struct list_head sessions = {&sessions, &sessions};
-unsigned char get_session_attribute(struct session *ses, int reverse)
+struct list_head sessions = { &sessions, &sessions };
+unsigned char
+get_session_attribute(struct session *ses, int reverse)
{
if (!ses->term->spec->col) {
if (!reverse)
@@ -36,9 +39,11 @@ unsigned char get_session_attribute(struct session *ses, int reverse)
return COLOR_STATUS;
} else {
if (!reverse)
- return get_attribute(ses->ds.t_text_color, ses->ds.t_background_color);
+ return get_attribute(ses->ds.t_text_color,
+ ses->ds.t_background_color);
else
- return get_attribute(ses->ds.t_background_color, ses->ds.t_text_color);
+ return get_attribute(ses->ds.t_background_color,
+ ses->ds.t_text_color);
}
}
@@ -48,84 +53,87 @@ struct s_msg_dsc {
};
static const struct s_msg_dsc msg_dsc[] = {
- {S_WAIT, TEXT_(T_WAITING_IN_QUEUE)},
- {S_DNS, TEXT_(T_LOOKING_UP_HOST)},
- {S_CONN, TEXT_(T_MAKING_CONNECTION)},
- {S_CONN_ANOTHER, TEXT_(T_MAKING_CONNECTION_TO_ANOTHER_ADDRESS)},
- {S_SOCKS_NEG, TEXT_(T_SOCKS_NEGOTIATION)},
- {S_SSL_NEG, TEXT_(T_SSL_NEGOTIATION)},
- {S_SENT, TEXT_(T_REQUEST_SENT)},
- {S_LOGIN, TEXT_(T_LOGGING_IN)},
- {S_GETH, TEXT_(T_GETTING_HEADERS)},
- {S_PROC, TEXT_(T_SERVER_IS_PROCESSING_REQUEST)},
- {S_TRANS, TEXT_(T_TRANSFERRING)},
-
- {S__OK, TEXT_(T_OK)},
- {S_INTERRUPTED, TEXT_(T_INTERRUPTED)},
- {S_INTERNAL, TEXT_(T_INTERNAL_ERROR)},
- {S_OUT_OF_MEM, TEXT_(T_OUT_OF_MEMORY)},
- {S_NO_DNS, TEXT_(T_HOST_NOT_FOUND)},
- {S_NO_PROXY_DNS, TEXT_(T_PROXY_NOT_FOUND)},
- {S_CANT_WRITE, TEXT_(T_ERROR_WRITING_TO_SOCKET)},
- {S_CANT_READ, TEXT_(T_ERROR_READING_FROM_SOCKET)},
- {S_MODIFIED, TEXT_(T_DATA_MODIFIED)},
- {S_BAD_URL, TEXT_(T_BAD_URL_SYNTAX)},
- {S_BAD_PROXY, TEXT_(T_BAD_PROXY_SYNTAX)},
- {S_TIMEOUT, TEXT_(T_RECEIVE_TIMEOUT)},
- {S_RESTART, TEXT_(T_REQUEST_MUST_BE_RESTARTED)},
- {S_STATE, TEXT_(T_CANT_GET_SOCKET_STATE)},
- {S_CYCLIC_REDIRECT, TEXT_(T_CYCLIC_REDIRECT)},
- {S_LARGE_FILE, TEXT_(T_TOO_LARGE_FILE)},
-
- {S_HTTP_ERROR, TEXT_(T_BAD_HTTP_RESPONSE)},
- {S_HTTP_204, TEXT_(T_NO_CONTENT)},
- {S_HTTPS_FWD_ERROR, TEXT_(T_HTTPS_FWD_ERROR)},
- {S_INVALID_CERTIFICATE, TEXT_(T_INVALID_CERTIFICATE)},
- {S_DOWNGRADED_METHOD, TEXT_(T_DOWNGRADED_METHOD)},
- {S_INSECURE_CIPHER, TEXT_(T_INSECURE_CIPHER)},
-
- {S_FILE_TYPE, TEXT_(T_UNKNOWN_FILE_TYPE)},
- {S_FILE_ERROR, TEXT_(T_ERROR_OPENING_FILE)},
-
- {S_SSL_ERROR, TEXT_(T_SSL_ERROR)},
- {S_NO_SSL, TEXT_(T_NO_SSL)},
- {S_BAD_SOCKS_VERSION, TEXT_(T_BAD_SOCKS_VERSION)},
- {S_SOCKS_REJECTED, TEXT_(T_SOCKS_REJECTED_OR_FAILED)},
- {S_SOCKS_NO_IDENTD, TEXT_(T_SOCKS_NO_IDENTD)},
- {S_SOCKS_BAD_USERID, TEXT_(T_SOCKS_BAD_USERID)},
- {S_SOCKS_UNKNOWN_ERROR, TEXT_(T_SOCKS_UNKNOWN_ERROR)},
-
- {S_NO_PROXY, TEXT_(T_NO_PROXY)},
- {S_SMB_NOT_ALLOWED, TEXT_(T_SMB_NOT_ALLOWED)},
- {S_FILE_NOT_ALLOWED, TEXT_(T_FILE_NOT_ALLOWED)},
-
- {S_WAIT_REDIR, TEXT_(T_WAITING_FOR_REDIRECT_CONFIRMATION)},
- {0, NULL}
+ {S_WAIT, TEXT_(T_WAITING_IN_QUEUE) },
+ { S_DNS, TEXT_(T_LOOKING_UP_HOST) },
+ { S_CONN, TEXT_(T_MAKING_CONNECTION) },
+ { S_CONN_ANOTHER, TEXT_(T_MAKING_CONNECTION_TO_ANOTHER_ADDRESS)},
+ { S_SOCKS_NEG, TEXT_(T_SOCKS_NEGOTIATION) },
+ { S_SSL_NEG, TEXT_(T_SSL_NEGOTIATION) },
+ { S_SENT, TEXT_(T_REQUEST_SENT) },
+ { S_LOGIN, TEXT_(T_LOGGING_IN) },
+ { S_GETH, TEXT_(T_GETTING_HEADERS) },
+ { S_PROC, TEXT_(T_SERVER_IS_PROCESSING_REQUEST) },
+ { S_TRANS, TEXT_(T_TRANSFERRING) },
+
+ { S__OK, TEXT_(T_OK) },
+ { S_INTERRUPTED, TEXT_(T_INTERRUPTED) },
+ { S_INTERNAL, TEXT_(T_INTERNAL_ERROR) },
+ { S_OUT_OF_MEM, TEXT_(T_OUT_OF_MEMORY) },
+ { S_NO_DNS, TEXT_(T_HOST_NOT_FOUND) },
+ { S_NO_PROXY_DNS, TEXT_(T_PROXY_NOT_FOUND) },
+ { S_CANT_WRITE, TEXT_(T_ERROR_WRITING_TO_SOCKET) },
+ { S_CANT_READ, TEXT_(T_ERROR_READING_FROM_SOCKET) },
+ { S_MODIFIED, TEXT_(T_DATA_MODIFIED) },
+ { S_BAD_URL, TEXT_(T_BAD_URL_SYNTAX) },
+ { S_BAD_PROXY, TEXT_(T_BAD_PROXY_SYNTAX) },
+ { S_TIMEOUT, TEXT_(T_RECEIVE_TIMEOUT) },
+ { S_RESTART, TEXT_(T_REQUEST_MUST_BE_RESTARTED) },
+ { S_STATE, TEXT_(T_CANT_GET_SOCKET_STATE) },
+ { S_CYCLIC_REDIRECT, TEXT_(T_CYCLIC_REDIRECT) },
+ { S_LARGE_FILE, TEXT_(T_TOO_LARGE_FILE) },
+
+ { S_HTTP_ERROR, TEXT_(T_BAD_HTTP_RESPONSE) },
+ { S_HTTP_204, TEXT_(T_NO_CONTENT) },
+ { S_HTTPS_FWD_ERROR, TEXT_(T_HTTPS_FWD_ERROR) },
+ { S_INVALID_CERTIFICATE, TEXT_(T_INVALID_CERTIFICATE) },
+ { S_DOWNGRADED_METHOD, TEXT_(T_DOWNGRADED_METHOD) },
+ { S_INSECURE_CIPHER, TEXT_(T_INSECURE_CIPHER) },
+
+ { S_FILE_TYPE, TEXT_(T_UNKNOWN_FILE_TYPE) },
+ { S_FILE_ERROR, TEXT_(T_ERROR_OPENING_FILE) },
+
+ { S_SSL_ERROR, TEXT_(T_SSL_ERROR) },
+ { S_NO_SSL, TEXT_(T_NO_SSL) },
+ { S_BAD_SOCKS_VERSION, TEXT_(T_BAD_SOCKS_VERSION) },
+ { S_SOCKS_REJECTED, TEXT_(T_SOCKS_REJECTED_OR_FAILED) },
+ { S_SOCKS_NO_IDENTD, TEXT_(T_SOCKS_NO_IDENTD) },
+ { S_SOCKS_BAD_USERID, TEXT_(T_SOCKS_BAD_USERID) },
+ { S_SOCKS_UNKNOWN_ERROR, TEXT_(T_SOCKS_UNKNOWN_ERROR) },
+
+ { S_NO_PROXY, TEXT_(T_NO_PROXY) },
+ { S_SMB_NOT_ALLOWED, TEXT_(T_SMB_NOT_ALLOWED) },
+ { S_FILE_NOT_ALLOWED, TEXT_(T_FILE_NOT_ALLOWED) },
+
+ { S_WAIT_REDIR, TEXT_(T_WAITING_FOR_REDIRECT_CONFIRMATION) },
+ { 0, NULL }
};
struct strerror_val {
list_entry_1st
#ifdef REORDER_LIST_ENTRIES
- unsigned char pad;
+ unsigned char pad;
#endif
unsigned char msg[1];
};
static struct list_head strerror_buf = { &strerror_buf, &strerror_buf };
-void free_strerror_buf(void)
+void
+free_strerror_buf(void)
{
free_list(struct strerror_val, strerror_buf);
}
-int get_error_from_errno(int errn)
+int
+get_error_from_errno(int errn)
{
if (errn > 0 && (errn < -S__OK || errn > -S_MAX))
return -errn;
return S_UNKNOWN_ERROR;
}
-unsigned char *get_err_msg(int state)
+unsigned char *
+get_err_msg(int state)
{
unsigned char *e;
size_t sl;
@@ -134,25 +142,30 @@ unsigned char *get_err_msg(int state)
if ((state >= S_MAX && state <= S__OK) || state >= S_WAIT) {
int i;
for (i = 0; msg_dsc[i].msg; i++)
- if (msg_dsc[i].n == state) return msg_dsc[i].msg;
- unk:
+ if (msg_dsc[i].n == state)
+ return msg_dsc[i].msg;
+unk:
return TEXT_(T_UNKNOWN_ERROR);
}
- if ((e = cast_uchar strerror(-state)) && *e) goto have_error;
+ if ((e = cast_uchar strerror(-state)) && *e)
+ goto have_error;
goto unk;
have_error:
- foreach(struct strerror_val, s, ls, strerror_buf) if (!strcmp(cast_const_char s->msg, cast_const_char e)) {
- return s->msg;
- }
+ foreach (struct strerror_val, s, ls, strerror_buf)
+ if (!strcmp(cast_const_char s->msg, cast_const_char e)) {
+ return s->msg;
+ }
sl = strlen(cast_const_char e);
- if (sl > INT_MAX - sizeof(struct strerror_val)) overalloc();
+ if (sl > INT_MAX - sizeof(struct strerror_val))
+ overalloc();
s = xmalloc(sizeof(struct strerror_val) + sl);
strcpy(cast_char s->msg, cast_const_char e);
add_to_list(strerror_buf, s);
return s->msg;
}
-static void add_xnum_to_str(unsigned char **s, int *l, off_t n)
+static void
+add_xnum_to_str(unsigned char **s, int *l, off_t n)
{
unsigned char suff = 0;
int d = -1;
@@ -175,11 +188,13 @@ static void add_xnum_to_str(unsigned char **s, int *l, off_t n)
add_num_to_str(s, l, d);
}
add_chr_to_str(s, l, ' ');
- if (suff) add_chr_to_str(s, l, suff);
+ if (suff)
+ add_chr_to_str(s, l, suff);
add_chr_to_str(s, l, 'B');
}
-static void add_time_to_str(unsigned char **s, int *l, uttime t)
+static void
+add_time_to_str(unsigned char **s, int *l, uttime t)
{
unsigned char q[64];
if (t >= 86400) {
@@ -188,7 +203,8 @@ static void add_time_to_str(unsigned char **s, int *l, uttime t)
}
if (t >= 3600) {
t %= 86400;
- sprintf(cast_char q, "%d:%02d", (int)(t / 3600), (int)(t / 60 % 60));
+ sprintf(cast_char q, "%d:%02d", (int)(t / 3600),
+ (int)(t / 60 % 60));
add_to_str(s, l, q);
} else {
sprintf(cast_char q, "%d", (int)(t / 60));
@@ -198,32 +214,42 @@ static void add_time_to_str(unsigned char **s, int *l, uttime t)
add_to_str(s, l, q);
}
-static unsigned char *get_stat_msg(struct status *stat, struct terminal *term)
+static unsigned char *
+get_stat_msg(struct status *stat, struct terminal *term)
{
if (stat->state == S_TRANS && stat->prg->elapsed / 100) {
unsigned char *m = init_str();
int l = 0;
- add_to_str(&m, &l, get_text_translation(TEXT_(T_RECEIVED), term));
+ add_to_str(&m, &l,
+ get_text_translation(TEXT_(T_RECEIVED), term));
add_chr_to_str(&m, &l, ' ');
add_xnum_to_str(&m, &l, stat->prg->pos);
if (stat->prg->size >= 0) {
add_chr_to_str(&m, &l, ' ');
- add_to_str(&m, &l, get_text_translation(TEXT_(T_OF), term));
+ add_to_str(&m, &l,
+ get_text_translation(TEXT_(T_OF), term));
add_chr_to_str(&m, &l, ' ');
add_xnum_to_str(&m, &l, stat->prg->size);
}
add_to_str(&m, &l, cast_uchar ", ");
if (stat->prg->elapsed >= CURRENT_SPD_AFTER * SPD_DISP_TIME) {
- add_to_str(&m, &l, get_text_translation(TEXT_(T_AVG), term));
+ add_to_str(&m, &l,
+ get_text_translation(TEXT_(T_AVG), term));
add_chr_to_str(&m, &l, ' ');
}
- add_xnum_to_str(&m, &l, stat->prg->loaded * 10 / (stat->prg->elapsed / 100));
+ add_xnum_to_str(&m, &l,
+ stat->prg->loaded * 10
+ / (stat->prg->elapsed / 100));
add_to_str(&m, &l, cast_uchar "/s");
if (stat->prg->elapsed >= CURRENT_SPD_AFTER * SPD_DISP_TIME) {
add_to_str(&m, &l, cast_uchar ", ");
- add_to_str(&m, &l, get_text_translation(TEXT_(T_CUR), term));
+ add_to_str(&m, &l,
+ get_text_translation(TEXT_(T_CUR), term));
add_chr_to_str(&m, &l, ' ');
- add_xnum_to_str(&m, &l, stat->prg->cur_loaded / (CURRENT_SPD_SEC * SPD_DISP_TIME / 1000));
+ add_xnum_to_str(
+ &m, &l,
+ stat->prg->cur_loaded
+ / (CURRENT_SPD_SEC * SPD_DISP_TIME / 1000));
add_to_str(&m, &l, cast_uchar "/s");
}
return m;
@@ -231,30 +257,34 @@ static unsigned char *get_stat_msg(struct status *stat, struct terminal *term)
return stracpy(get_text_translation(get_err_msg(stat->state), term));
}
-void change_screen_status(struct session *ses)
+void
+change_screen_status(struct session *ses)
{
struct status *stat = NULL;
if (ses->rq) {
stat = &ses->rq->stat;
} else {
struct f_data_c *fd = current_frame(ses);
- if (fd->rq) stat = &fd->rq->stat;
+ if (fd->rq)
+ stat = &fd->rq->stat;
if (stat && stat->state == S__OK && fd->af) {
unsigned count = 0;
struct additional_file *af = NULL;
struct list_head *laf;
- foreachback(struct additional_file, af, laf, fd->af->af) {
+ foreachback (struct additional_file, af, laf,
+ fd->af->af) {
if (af->rq && af->rq->stat.state >= 0) {
- if (af->rq->stat.state > stat->state ||
- (af->rq->stat.state == S_TRANS &&
- stat->state == S_TRANS &&
- af->rq->stat.prg->pos >
- stat->prg->pos))
+ if (af->rq->stat.state > stat->state
+ || (af->rq->stat.state == S_TRANS
+ && stat->state == S_TRANS
+ && af->rq->stat.prg->pos
+ > stat->prg->pos))
stat = &af->rq->stat;
}
count++;
/* avoid too high cpu consumption */
- if (count >= 100 && stat->state >= 0 && stat->state != S_WAIT)
+ if (count >= 100 && stat->state >= 0
+ && stat->state != S_WAIT)
break;
}
}
@@ -267,43 +297,55 @@ void change_screen_status(struct session *ses)
*/
ses->st = NULL;
if (stat) {
- if (stat->state == S__OK) ses->st = print_current_link(ses);
- if (!ses->st) ses->st = ses->default_status ? stracpy(ses->default_status) : get_stat_msg(stat, ses->term);
+ if (stat->state == S__OK)
+ ses->st = print_current_link(ses);
+ if (!ses->st)
+ ses->st = ses->default_status
+ ? stracpy(ses->default_status)
+ : get_stat_msg(stat, ses->term);
} else {
ses->st = stracpy(ses->default_status);
}
}
-static void x_print_screen_status(struct terminal *term, void *ses_)
+static void
+x_print_screen_status(struct terminal *term, void *ses_)
{
struct session *ses = (struct session *)ses_;
unsigned char color = get_session_attribute(ses, proxies.only_proxies);
fill_area(term, 0, term->y - 1, term->x, 1, ' ', color);
if (ses->st)
- print_text(term, 0, term->y - 1, (int)strlen(cast_const_char ses->st), ses->st, COLOR_STATUS);
+ print_text(term, 0, term->y - 1,
+ (int)strlen(cast_const_char ses->st), ses->st,
+ COLOR_STATUS);
}
-static void x_print_screen_title(struct terminal *term, void *ses_)
+static void
+x_print_screen_title(struct terminal *term, void *ses_)
{
struct session *ses = (struct session *)ses_;
unsigned char *m;
unsigned char color = get_session_attribute(ses, proxies.only_proxies);
- if (!term->spec->col) color = COLOR_TITLE;
+ if (!term->spec->col)
+ color = COLOR_TITLE;
fill_area(term, 0, 0, term->x, 1, ' ', color);
if ((m = print_current_title(ses))) {
int p = term->x - 1 - strlen((char *)m);
- if (p < 0) p = 0;
+ if (p < 0)
+ p = 0;
print_text(term, p, 0, strlen((char *)m), m, color);
free(m);
}
}
-static void print_only_screen_status(struct session *ses)
+static void
+print_only_screen_status(struct session *ses)
{
draw_to_window(ses->win, x_print_screen_status, ses);
}
-void print_screen_status(struct session *ses)
+void
+print_screen_status(struct session *ses)
{
unsigned char *m;
@@ -311,22 +353,24 @@ void print_screen_status(struct session *ses)
draw_to_window(ses->win, x_print_screen_title, ses);
m = stracpy(cast_uchar "Links");
- if (ses->screen
- && ses->screen->f_data
- && ses->screen->f_data->title
- && ses->screen->f_data->title[0]) {
+ if (ses->screen && ses->screen->f_data && ses->screen->f_data->title
+ && ses->screen->f_data->title[0]) {
add_to_strn(&m, cast_uchar " - ");
add_to_strn(&m, ses->screen->f_data->title);
}
set_terminal_title(ses->term, m);
if (ses->brl_cursor_mode) {
- if (ses->brl_cursor_mode == 1) set_cursor(ses->term, 0, 0, 0, 0);
- if (ses->brl_cursor_mode == 2) set_cursor(ses->term, 0, ses->term->y - 1, 0, ses->term->y - 1);
+ if (ses->brl_cursor_mode == 1)
+ set_cursor(ses->term, 0, 0, 0, 0);
+ if (ses->brl_cursor_mode == 2)
+ set_cursor(ses->term, 0, ses->term->y - 1, 0,
+ ses->term->y - 1);
}
}
-void print_progress(struct session *ses, unsigned char *msg)
+void
+print_progress(struct session *ses, unsigned char *msg)
{
free(ses->st);
ses->st = stracpy(get_text_translation(msg, ses->term));
@@ -334,33 +378,44 @@ void print_progress(struct session *ses, unsigned char *msg)
flush_terminal(ses->term);
}
-void print_error_dialog(struct session *ses, struct status *stat, unsigned char *url)
+void
+print_error_dialog(struct session *ses, struct status *stat, unsigned char *url)
{
unsigned char *t = get_err_msg(stat->state);
unsigned char *u = display_url(ses->term, url, 1);
- msg_box(ses->term, getml(u, NULL), TEXT_(T_ERROR), AL_CENTER, TEXT_(T_ERROR_LOADING), cast_uchar " ", u, cast_uchar ":\n\n", t, MSG_BOX_END, (void *)ses, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC /*, get_text_translation("Retry"), NULL, 0 !!! FIXME: retry */);
+ msg_box(ses->term, getml(u, NULL), TEXT_(T_ERROR), AL_CENTER,
+ TEXT_(T_ERROR_LOADING), cast_uchar " ", u, cast_uchar ":\n\n",
+ t, MSG_BOX_END,
+ (void *)ses, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC /*, get_text_translation("Retry"), NULL, 0 !!! FIXME: retry */);
}
-static inline unsigned char hx(int a)
+static inline unsigned char
+hx(int a)
{
return a >= 10 ? a + 'A' - 10 : a + '0';
}
-static inline int unhx(unsigned char a)
+static inline int
+unhx(unsigned char a)
{
- if (a >= '0' && a <= '9') return a - '0';
- if (a >= 'A' && a <= 'F') return a - 'A' + 10;
- if (a >= 'a' && a <= 'f') return a - 'a' + 10;
+ if (a >= '0' && a <= '9')
+ return a - '0';
+ if (a >= 'A' && a <= 'F')
+ return a - 'A' + 10;
+ if (a >= 'a' && a <= 'f')
+ return a - 'a' + 10;
return -1;
}
-unsigned char *encode_url(unsigned char *url)
+unsigned char *
+encode_url(unsigned char *url)
{
unsigned char *u = init_str();
int l = 0;
add_to_str(&u, &l, cast_uchar "+++");
for (; *url; url++) {
- if (is_safe_in_shell(*url) && *url != '+') add_chr_to_str(&u, &l, *url);
+ if (is_safe_in_shell(*url) && *url != '+')
+ add_chr_to_str(&u, &l, *url);
else {
add_chr_to_str(&u, &l, '+');
add_chr_to_str(&u, &l, hx(*url >> 4));
@@ -370,46 +425,59 @@ unsigned char *encode_url(unsigned char *url)
return u;
}
-unsigned char *decode_url(unsigned char *url)
+unsigned char *
+decode_url(unsigned char *url)
{
unsigned char *u;
int l;
- if (casecmp(url, cast_uchar "+++", 3)) return stracpy(url);
+ if (casecmp(url, cast_uchar "+++", 3))
+ return stracpy(url);
url += 3;
u = init_str();
l = 0;
for (; *url; url++) {
- if (*url != '+' || unhx(url[1]) == -1 || unhx(url[2]) == -1) add_chr_to_str(&u, &l, *url);
+ if (*url != '+' || unhx(url[1]) == -1 || unhx(url[2]) == -1)
+ add_chr_to_str(&u, &l, *url);
else {
- add_chr_to_str(&u, &l, (unhx(url[1]) << 4) + unhx(url[2]));
+ add_chr_to_str(&u, &l,
+ (unhx(url[1]) << 4) + unhx(url[2]));
url += 2;
}
}
return u;
}
-struct session *get_download_ses(struct download *down)
+struct session *
+get_download_ses(struct download *down)
{
struct session *ses = NULL;
struct list_head *lses;
- if (down) foreach(struct session, ses, lses, sessions) if (ses == down->ses) return ses;
- if (!list_empty(sessions)) return list_struct(sessions.next, struct session);
+ if (down)
+ foreach (struct session, ses, lses, sessions)
+ if (ses == down->ses)
+ return ses;
+ if (!list_empty(sessions))
+ return list_struct(sessions.next, struct session);
return NULL;
}
-static int close_download_file(struct download *down)
+static int
+close_download_file(struct download *down)
{
int rs;
if (down->handle != -1) {
- EINTRLOOP(rs, ftruncate(down->handle, down->last_pos - down->file_shift));
+ EINTRLOOP(rs, ftruncate(down->handle,
+ down->last_pos - down->file_shift));
EINTRLOOP(rs, close(down->handle));
down->handle = -1;
- if (rs) return -1;
+ if (rs)
+ return -1;
}
return 0;
}
-static void delete_download_file(struct download *down)
+static void
+delete_download_file(struct download *down)
{
int rs;
unsigned char *file = stracpy(down->orig_file);
@@ -419,7 +487,8 @@ static void delete_download_file(struct download *down)
unsigned char *f = translate_download_file(file);
EINTRLOOP(rs, unlink(cast_const_char f));
free(f);
- if (!strcmp(cast_const_char file, cast_const_char down->file)) break;
+ if (!strcmp(cast_const_char file, cast_const_char down->file))
+ break;
increase_download_file(&file);
}
free(file);
@@ -429,16 +498,20 @@ static void delete_download_file(struct download *down)
}
}
-static void abort_download(void *down_)
+static void
+abort_download(void *down_)
{
struct download *down = (struct download *)down_;
unregister_bottom_half(abort_download, down);
unregister_bottom_half(abort_and_delete_download, down);
unregister_bottom_half(undisplay_download, down);
- if (down->win) delete_window(down->win);
- if (down->ask) delete_window(down->ask);
- if (down->stat.state >= 0) change_connection(&down->stat, NULL, PRI_CANCEL);
+ if (down->win)
+ delete_window(down->win);
+ if (down->ask)
+ delete_window(down->ask);
+ if (down->stat.state >= 0)
+ change_connection(&down->stat, NULL, PRI_CANCEL);
free(down->url);
close_download_file(down);
if (down->prog) {
@@ -452,26 +525,33 @@ static void abort_download(void *down_)
free(down);
}
-static void abort_and_delete_download(void *down_)
+static void
+abort_and_delete_download(void *down_)
{
struct download *down = (struct download *)down_;
abort_download(down);
}
-int test_abort_downloads_to_file(unsigned char *file, unsigned char *cwd, int abort_downloads)
+int
+test_abort_downloads_to_file(unsigned char *file, unsigned char *cwd,
+ int abort_downloads)
{
int ret = 0;
struct download *down = NULL;
struct list_head *ldown;
- foreach(struct download, down, ldown, downloads) {
+ foreach (struct download, down, ldown, downloads) {
if (strcmp(cast_const_char down->cwd, cast_const_char cwd)) {
- if (file[0] == '/') goto abs;
+ if (file[0] == '/')
+ goto abs;
continue;
}
- abs:
- if (!strcmp(cast_const_char down->file, cast_const_char file) || !strcmp(cast_const_char down->orig_file, cast_const_char file)) {
+abs:
+ if (!strcmp(cast_const_char down->file, cast_const_char file)
+ || !strcmp(cast_const_char down->orig_file,
+ cast_const_char file)) {
ret = 1;
- if (!abort_downloads) break;
+ if (!abort_downloads)
+ break;
ldown = ldown->prev;
abort_download(down);
}
@@ -479,71 +559,89 @@ int test_abort_downloads_to_file(unsigned char *file, unsigned char *cwd, int ab
return ret;
}
-static void undisplay_download(void *down_)
+static void
+undisplay_download(void *down_)
{
struct download *down = (struct download *)down_;
- if (down->win) delete_window(down->win);
+ if (down->win)
+ delete_window(down->win);
}
-static int dlg_abort_download(struct dialog_data *dlg, struct dialog_item_data *di)
+static int
+dlg_abort_download(struct dialog_data *dlg, struct dialog_item_data *di)
{
register_bottom_half(abort_download, dlg->dlg->udata);
return 0;
}
-static int dlg_abort_and_delete_download(struct dialog_data *dlg, struct dialog_item_data *di)
+static int
+dlg_abort_and_delete_download(struct dialog_data *dlg,
+ struct dialog_item_data *di)
{
register_bottom_half(abort_and_delete_download, dlg->dlg->udata);
return 0;
}
-static int dlg_undisplay_download(struct dialog_data *dlg, struct dialog_item_data *di)
+static int
+dlg_undisplay_download(struct dialog_data *dlg, struct dialog_item_data *di)
{
register_bottom_half(undisplay_download, dlg->dlg->udata);
return 0;
}
-static void download_abort_function(struct dialog_data *dlg)
+static void
+download_abort_function(struct dialog_data *dlg)
{
struct download *down = dlg->dlg->udata;
down->win = NULL;
}
-static int test_percentage(struct status *stat)
+static int
+test_percentage(struct status *stat)
{
return stat->prg->size > 0;
}
-static int download_meter(int size, struct status *stat)
+static int
+download_meter(int size, struct status *stat)
{
int m;
- if (!stat->prg->size) return 0;
- m = (int)((double)size * (double)stat->prg->pos / (double)stat->prg->size);
- if (m < 0) m = 0;
- if (m > size) m = size;
+ if (!stat->prg->size)
+ return 0;
+ m = (int)((double)size * (double)stat->prg->pos
+ / (double)stat->prg->size);
+ if (m < 0)
+ m = 0;
+ if (m > size)
+ m = size;
return m;
}
-unsigned char *download_percentage(struct download *down, int pad)
+unsigned char *
+download_percentage(struct download *down, int pad)
{
unsigned char *s;
int l;
int perc;
struct status *stat = &down->stat;
- if (stat->state != S_TRANS || !test_percentage(stat)) return stracpy(cast_uchar "");
+ if (stat->state != S_TRANS || !test_percentage(stat))
+ return stracpy(cast_uchar "");
s = init_str();
l = 0;
perc = download_meter(100, stat);
if (pad) {
- if (perc < 10) add_chr_to_str(&s, &l, ' ');
- if (perc < 100) add_chr_to_str(&s, &l, ' ');
+ if (perc < 10)
+ add_chr_to_str(&s, &l, ' ');
+ if (perc < 100)
+ add_chr_to_str(&s, &l, ' ');
}
add_num_to_str(&s, &l, perc);
add_chr_to_str(&s, &l, '%');
return s;
}
-void download_window_function(struct dialog_data *dlg)
+void
+download_window_function(struct dialog_data *dlg)
{
struct download *down = dlg->dlg->udata;
struct terminal *term = dlg->win->term;
@@ -559,44 +657,69 @@ void download_window_function(struct dialog_data *dlg)
int l = 0;
m = init_str();
t = 1;
- add_to_str(&m, &l, get_text_translation(TEXT_(T_RECEIVED), term));
+ add_to_str(&m, &l,
+ get_text_translation(TEXT_(T_RECEIVED), term));
add_chr_to_str(&m, &l, ' ');
add_xnum_to_str(&m, &l, stat->prg->pos);
if (stat->prg->size >= 0) {
add_chr_to_str(&m, &l, ' ');
- add_to_str(&m, &l, get_text_translation(TEXT_(T_OF),term));
+ add_to_str(&m, &l,
+ get_text_translation(TEXT_(T_OF), term));
add_chr_to_str(&m, &l, ' ');
add_xnum_to_str(&m, &l, stat->prg->size);
add_chr_to_str(&m, &l, ' ');
}
add_to_str(&m, &l, cast_uchar "\n");
if (stat->prg->elapsed >= CURRENT_SPD_AFTER * SPD_DISP_TIME)
- add_to_str(&m, &l, get_text_translation(TEXT_(T_AVERAGE_SPEED), term));
+ add_to_str(
+ &m, &l,
+ get_text_translation(TEXT_(T_AVERAGE_SPEED), term));
else
- add_to_str(&m, &l, get_text_translation(TEXT_(T_SPEED), term));
+ add_to_str(&m, &l,
+ get_text_translation(TEXT_(T_SPEED), term));
add_chr_to_str(&m, &l, ' ');
- add_xnum_to_str(&m, &l, (long long)stat->prg->loaded * 10 / (stat->prg->elapsed / 100));
+ add_xnum_to_str(&m, &l,
+ (long long)stat->prg->loaded * 10
+ / (stat->prg->elapsed / 100));
add_to_str(&m, &l, cast_uchar "/s");
if (stat->prg->elapsed >= CURRENT_SPD_AFTER * SPD_DISP_TIME) {
add_to_str(&m, &l, cast_uchar ", ");
- add_to_str(&m, &l, get_text_translation(TEXT_(T_CURRENT_SPEED), term));
+ add_to_str(
+ &m, &l,
+ get_text_translation(TEXT_(T_CURRENT_SPEED), term));
add_chr_to_str(&m, &l, ' ');
- add_xnum_to_str(&m, &l, stat->prg->cur_loaded / (CURRENT_SPD_SEC * SPD_DISP_TIME / 1000));
+ add_xnum_to_str(
+ &m, &l,
+ stat->prg->cur_loaded
+ / (CURRENT_SPD_SEC * SPD_DISP_TIME / 1000));
add_to_str(&m, &l, cast_uchar "/s");
}
add_to_str(&m, &l, cast_uchar "\n");
- add_to_str(&m, &l, get_text_translation(TEXT_(T_ELAPSED_TIME), term));
+ add_to_str(&m, &l,
+ get_text_translation(TEXT_(T_ELAPSED_TIME), term));
add_chr_to_str(&m, &l, ' ');
add_time_to_str(&m, &l, stat->prg->elapsed / 1000);
if (stat->prg->size >= 0 && stat->prg->loaded > 0) {
add_to_str(&m, &l, cast_uchar ", ");
- add_to_str(&m, &l, get_text_translation(TEXT_(T_ESTIMATED_TIME), term));
+ add_to_str(&m, &l,
+ get_text_translation(TEXT_(T_ESTIMATED_TIME),
+ term));
add_chr_to_str(&m, &l, ' ');
- /*add_time_to_str(&m, &l, stat->prg->elapsed / 1000 * stat->prg->size / stat->prg->loaded * 1000 - stat->prg->elapsed);*/
- /*add_time_to_str(&m, &l, (stat->prg->size - stat->prg->pos) / ((longlong)stat->prg->loaded * 10 / (stat->prg->elapsed / 100)));*/
- add_time_to_str(&m, &l, (uttime)((stat->prg->size - stat->prg->pos) / ((double)stat->prg->loaded * 1000 / stat->prg->elapsed)));
+ /*add_time_to_str(&m, &l, stat->prg->elapsed / 1000 *
+ * stat->prg->size / stat->prg->loaded * 1000 -
+ * stat->prg->elapsed);*/
+ /*add_time_to_str(&m, &l, (stat->prg->size -
+ * stat->prg->pos) / ((longlong)stat->prg->loaded * 10 /
+ * (stat->prg->elapsed / 100)));*/
+ add_time_to_str(
+ &m, &l,
+ (uttime)((stat->prg->size - stat->prg->pos)
+ / ((double)stat->prg->loaded * 1000
+ / stat->prg->elapsed)));
}
- } else m = stracpy(get_text_translation(get_err_msg(stat->state), term));
+ } else
+ m = stracpy(
+ get_text_translation(get_err_msg(stat->state), term));
show_percentage = t && test_percentage(stat);
u = display_url(term, down->url, 1);
max_text_width(term, u, &max, AL_LEFT);
@@ -606,61 +729,77 @@ void download_window_function(struct dialog_data *dlg)
max_buttons_width(term, dlg->items, dlg->n, &max);
min_buttons_width(term, dlg->items, dlg->n, &min);
w = dlg->win->term->x * 9 / 10 - 2 * DIALOG_LB;
- if (w < min) w = min;
+ if (w < min)
+ w = min;
if (w > dlg->win->term->x - 2 * DIALOG_LB)
w = dlg->win->term->x - 2 * DIALOG_LB;
if (show_percentage) {
- if (w < DOWN_DLG_MIN) w = DOWN_DLG_MIN;
+ if (w < DOWN_DLG_MIN)
+ w = DOWN_DLG_MIN;
} else {
- if (w > max) w = max;
+ if (w > max)
+ w = max;
}
- if (w < 1) w = 1;
+ if (w < 1)
+ w = 1;
y = 0;
- dlg_format_text(dlg, NULL, u, 0, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text(dlg, NULL, u, 0, &y, w, NULL, COLOR_DIALOG_TEXT,
+ AL_LEFT);
y++;
if (show_percentage)
y += 2;
- dlg_format_text(dlg, NULL, m, 0, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text(dlg, NULL, m, 0, &y, w, NULL, COLOR_DIALOG_TEXT,
+ AL_LEFT);
y++;
- dlg_format_buttons(dlg, NULL, dlg->items, dlg->n, 0, &y, w, NULL, AL_CENTER);
+ dlg_format_buttons(dlg, NULL, dlg->items, dlg->n, 0, &y, w, NULL,
+ AL_CENTER);
dlg->xw = w + 2 * DIALOG_LB;
dlg->yw = y + 2 * DIALOG_TB;
center_dlg(dlg);
draw_dlg(dlg);
y = dlg->y + DIALOG_TB + 1;
x = dlg->x + DIALOG_LB;
- dlg_format_text(dlg, term, u, x, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text(dlg, term, u, x, &y, w, NULL, COLOR_DIALOG_TEXT,
+ AL_LEFT);
if (show_percentage) {
unsigned char *q;
int p = w - 6;
y++;
set_only_char(term, x, y, '[', 0);
set_only_char(term, x + p + 1, y, ']', 0);
- fill_area(term, x + 1, y, download_meter(p, stat), 1, CHAR_DIALOG_METER, COLOR_DIALOG_METER);
+ fill_area(term, x + 1, y, download_meter(p, stat), 1,
+ CHAR_DIALOG_METER, COLOR_DIALOG_METER);
q = download_percentage(down, 1);
- print_text(term, x + p + 2, y, (int)strlen(cast_const_char q), q, COLOR_DIALOG_TEXT);
+ print_text(term, x + p + 2, y, (int)strlen(cast_const_char q),
+ q, COLOR_DIALOG_TEXT);
free(q);
y++;
}
y++;
- dlg_format_text(dlg, term, m, x, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text(dlg, term, m, x, &y, w, NULL, COLOR_DIALOG_TEXT,
+ AL_LEFT);
y++;
- dlg_format_buttons(dlg, term, dlg->items, dlg->n, x, &y, w, NULL, AL_CENTER);
+ dlg_format_buttons(dlg, term, dlg->items, dlg->n, x, &y, w, NULL,
+ AL_CENTER);
free(u);
free(m);
}
-void display_download(struct terminal *term, void *down_, void *ses_)
+void
+display_download(struct terminal *term, void *down_, void *ses_)
{
struct download *down = (struct download *)down_;
struct session *ses = (struct session *)ses_;
struct dialog *dlg;
struct download *dd = NULL;
struct list_head *ldd;
- foreach(struct download, dd, ldd, downloads) if (dd == down) goto found;
+ foreach (struct download, dd, ldd, downloads)
+ if (dd == down)
+ goto found;
return;
found:
- dlg = mem_calloc(sizeof(struct dialog) + 4 * sizeof(struct dialog_item));
+ dlg =
+ mem_calloc(sizeof(struct dialog) + 4 * sizeof(struct dialog_item));
undisplay_download(down);
down->ses = ses;
dlg->title = TEXT_(T_DOWNLOAD);
@@ -688,21 +827,14 @@ found:
do_dialog(term, dlg, getml(dlg, NULL));
}
-time_t parse_http_date(unsigned char *date) /* this functions is bad !!! */
+time_t
+parse_http_date(unsigned char *date) /* this functions is bad !!! */
{
static unsigned char *months[12] = {
- cast_uchar "Jan",
- cast_uchar "Feb",
- cast_uchar "Mar",
- cast_uchar "Apr",
- cast_uchar "May",
- cast_uchar "Jun",
- cast_uchar "Jul",
- cast_uchar "Aug",
- cast_uchar "Sep",
- cast_uchar "Oct",
- cast_uchar "Nov",
- cast_uchar "Dec"
+ cast_uchar "Jan", cast_uchar "Feb", cast_uchar "Mar",
+ cast_uchar "Apr", cast_uchar "May", cast_uchar "Jun",
+ cast_uchar "Jul", cast_uchar "Aug", cast_uchar "Sep",
+ cast_uchar "Oct", cast_uchar "Nov", cast_uchar "Dec"
};
time_t t = 0;
@@ -712,116 +844,163 @@ time_t parse_http_date(unsigned char *date) /* this functions is bad !!! */
memset(&tm, 0, sizeof(struct tm));
date = cast_uchar strchr(cast_const_char date, ' ');
- if (!date) return 0;
+ if (!date)
+ return 0;
date++;
if (*date >= '0' && *date <= '9') {
- /* Sun, 06 Nov 1994 08:49:37 GMT */
- /* Sunday, 06-Nov-94 08:49:37 GMT */
+ /* Sun, 06 Nov 1994 08:49:37 GMT */
+ /* Sunday, 06-Nov-94 08:49:37 GMT */
y = 0;
- if (date[0] < '0' || date[0] > '9') return 0;
- if (date[1] < '0' || date[1] > '9') return 0;
+ if (date[0] < '0' || date[0] > '9')
+ return 0;
+ if (date[1] < '0' || date[1] > '9')
+ return 0;
tm.tm_mday = (date[0] - '0') * 10 + date[1] - '0';
date += 2;
- if (*date != ' ' && *date != '-') return 0;
+ if (*date != ' ' && *date != '-')
+ return 0;
date += 1;
for (tm.tm_mon = 0; tm.tm_mon < 12; tm.tm_mon++)
- if (!casecmp(date, months[tm.tm_mon], 3)) goto f1;
+ if (!casecmp(date, months[tm.tm_mon], 3))
+ goto f1;
return 0;
- f1:
+f1:
date += 3;
if (*date == ' ') {
- /* Sun, 06 Nov 1994 08:49:37 GMT */
+ /* Sun, 06 Nov 1994 08:49:37 GMT */
date++;
- if (date[0] < '0' || date[0] > '9') return 0;
- if (date[1] < '0' || date[1] > '9') return 0;
- if (date[2] < '0' || date[2] > '9') return 0;
- if (date[3] < '0' || date[3] > '9') return 0;
- tm.tm_year = (date[0] - '0') * 1000 + (date[1] - '0') * 100 + (date[2] - '0') * 10 + date[3] - '0' - 1900;
+ if (date[0] < '0' || date[0] > '9')
+ return 0;
+ if (date[1] < '0' || date[1] > '9')
+ return 0;
+ if (date[2] < '0' || date[2] > '9')
+ return 0;
+ if (date[3] < '0' || date[3] > '9')
+ return 0;
+ tm.tm_year =
+ (date[0] - '0') * 1000 + (date[1] - '0') * 100
+ + (date[2] - '0') * 10 + date[3] - '0' - 1900;
date += 4;
} else if (*date == '-') {
- /* Sunday, 06-Nov-94 08:49:37 GMT */
+ /* Sunday, 06-Nov-94 08:49:37 GMT */
date++;
- if (date[0] < '0' || date[0] > '9') return 0;
- if (date[1] < '0' || date[1] > '9') return 0;
- tm.tm_year = (date[0] >= '7' ? 1900 : 2000) + (date[0] - '0') * 10 + date[1] - '0' - 1900;
+ if (date[0] < '0' || date[0] > '9')
+ return 0;
+ if (date[1] < '0' || date[1] > '9')
+ return 0;
+ tm.tm_year = (date[0] >= '7' ? 1900 : 2000)
+ + (date[0] - '0') * 10 + date[1] - '0'
+ - 1900;
date += 2;
- } else return 0;
- if (*date != ' ') return 0;
+ } else
+ return 0;
+ if (*date != ' ')
+ return 0;
date++;
} else {
- /* Sun Nov 6 08:49:37 1994 */
+ /* Sun Nov 6 08:49:37 1994 */
y = 1;
for (tm.tm_mon = 0; tm.tm_mon < 12; tm.tm_mon++)
- if (!casecmp(date, months[tm.tm_mon], 3)) goto f2;
+ if (!casecmp(date, months[tm.tm_mon], 3))
+ goto f2;
return 0;
- f2:
+f2:
date += 3;
- while (*date == ' ') date++;
- if (date[0] < '0' || date[0] > '9') return 0;
+ while (*date == ' ')
+ date++;
+ if (date[0] < '0' || date[0] > '9')
+ return 0;
tm.tm_mday = date[0] - '0';
date++;
if (*date != ' ') {
- if (date[0] < '0' || date[0] > '9') return 0;
+ if (date[0] < '0' || date[0] > '9')
+ return 0;
tm.tm_mday = tm.tm_mday * 10 + date[0] - '0';
date++;
}
- if (*date != ' ') return 0;
+ if (*date != ' ')
+ return 0;
date++;
}
- if (date[0] < '0' || date[0] > '9') return 0;
- if (date[1] < '0' || date[1] > '9') return 0;
+ if (date[0] < '0' || date[0] > '9')
+ return 0;
+ if (date[1] < '0' || date[1] > '9')
+ return 0;
tm.tm_hour = (date[0] - '0') * 10 + date[1] - '0';
date += 2;
- if (*date != ':') return 0;
+ if (*date != ':')
+ return 0;
date++;
- if (date[0] < '0' || date[0] > '9') return 0;
- if (date[1] < '0' || date[1] > '9') return 0;
+ if (date[0] < '0' || date[0] > '9')
+ return 0;
+ if (date[1] < '0' || date[1] > '9')
+ return 0;
tm.tm_min = (date[0] - '0') * 10 + date[1] - '0';
date += 2;
- if (*date != ':') return 0;
+ if (*date != ':')
+ return 0;
date++;
- if (date[0] < '0' || date[0] > '9') return 0;
- if (date[1] < '0' || date[1] > '9') return 0;
+ if (date[0] < '0' || date[0] > '9')
+ return 0;
+ if (date[1] < '0' || date[1] > '9')
+ return 0;
tm.tm_sec = (date[0] - '0') * 10 + date[1] - '0';
date += 2;
if (y) {
- if (*date != ' ') return 0;
+ if (*date != ' ')
+ return 0;
date++;
- if (date[0] < '0' || date[0] > '9') return 0;
- if (date[1] < '0' || date[1] > '9') return 0;
- if (date[2] < '0' || date[2] > '9') return 0;
- if (date[3] < '0' || date[3] > '9') return 0;
- tm.tm_year = (date[0] - '0') * 1000 + (date[1] - '0') * 100 + (date[2] - '0') * 10 + date[3] - '0' - 1900;
+ if (date[0] < '0' || date[0] > '9')
+ return 0;
+ if (date[1] < '0' || date[1] > '9')
+ return 0;
+ if (date[2] < '0' || date[2] > '9')
+ return 0;
+ if (date[3] < '0' || date[3] > '9')
+ return 0;
+ tm.tm_year = (date[0] - '0') * 1000 + (date[1] - '0') * 100
+ + (date[2] - '0') * 10 + date[3] - '0' - 1900;
date += 4;
}
- if (*date != ' ' && *date) return 0;
+ if (*date != ' ' && *date)
+ return 0;
t = mktime(&tm);
- if (t == (time_t) -1) return 0;
+ if (t == (time_t)-1)
+ return 0;
return t;
}
-
-static void download_file_error(struct download *down, int err)
+static void
+download_file_error(struct download *down, int err)
{
struct session *ses = get_download_ses(down);
if (ses) {
- unsigned char *emsg = stracpy(err ? cast_uchar strerror(err) : cast_uchar "Zero returned");
+ unsigned char *emsg = stracpy(err ? cast_uchar strerror(err)
+ : cast_uchar "Zero returned");
unsigned char *msg = stracpy(down->file);
- msg_box(ses->term, getml(msg, emsg, NULL), TEXT_(T_DOWNLOAD_ERROR), AL_CENTER, TEXT_(T_COULD_NOT_WRITE_TO_FILE), cast_uchar " ", msg, cast_uchar ": ", emsg, MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ msg_box(ses->term, getml(msg, emsg, NULL),
+ TEXT_(T_DOWNLOAD_ERROR), AL_CENTER,
+ TEXT_(T_COULD_NOT_WRITE_TO_FILE), cast_uchar " ", msg,
+ cast_uchar ": ", emsg, MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
}
}
-static int download_write(struct download *down, void *ptr, off_t to_write)
+static int
+download_write(struct download *down, void *ptr, off_t to_write)
{
int w;
int err;
- if (to_write != (int)to_write || (int)to_write < 0) to_write = INT_MAX;
- try_write_again:
+ if (to_write != (int)to_write || (int)to_write < 0)
+ to_write = INT_MAX;
+try_write_again:
w = hard_write(down->handle, ptr, (int)to_write);
- if (w >= 0) err = 0;
- else err = errno;
+ if (w >= 0)
+ err = 0;
+ else
+ err = errno;
if (w <= -!to_write) {
#ifdef EFBIG
if (err == EFBIG && !down->prog) {
@@ -829,16 +1008,21 @@ static int download_write(struct download *down, void *ptr, off_t to_write)
to_write >>= 1;
goto try_write_again;
}
- if (down->last_pos == down->file_shift) goto no_e2big;
+ if (down->last_pos == down->file_shift)
+ goto no_e2big;
if (close_download_file(down)) {
download_file_error(down, errno);
return -1;
}
increase_download_file(&down->file);
- if ((down->handle = create_download_file(get_download_ses(down), down->cwd, down->file, 0, down->last_pos - down->file_shift)) < 0) return -1;
+ if ((down->handle = create_download_file(
+ get_download_ses(down), down->cwd, down->file,
+ 0, down->last_pos - down->file_shift))
+ < 0)
+ return -1;
down->file_shift = down->last_pos;
goto try_write_again;
- no_e2big:;
+no_e2big:;
}
#endif
download_file_error(down, err);
@@ -849,16 +1033,20 @@ static int download_write(struct download *down, void *ptr, off_t to_write)
return 0;
}
-static void download_data(struct status *stat, void *down_)
+static void
+download_data(struct status *stat, void *down_)
{
struct download *down = (struct download *)down_;
struct cache_entry *ce;
struct fragment *frag = NULL;
struct list_head *lfrag;
int rs;
- if (!(ce = stat->ce)) goto end_store;
- if (stat->state >= S_WAIT && stat->state < S_TRANS) goto end_store;
- if (!down->remotetime && ce->last_modified) down->remotetime = parse_http_date(ce->last_modified);
+ if (!(ce = stat->ce))
+ goto end_store;
+ if (stat->state >= S_WAIT && stat->state < S_TRANS)
+ goto end_store;
+ if (!down->remotetime && ce->last_modified)
+ down->remotetime = parse_http_date(ce->last_modified);
if (!down->downloaded_something) {
unsigned char *enc;
if (ce->redirect) {
@@ -866,26 +1054,37 @@ static void download_data(struct status *stat, void *down_)
unsigned char *u;
unsigned char *prev_down_url;
int cache, allow_flags;
- if (stat->state >= 0) change_connection(&down->stat, NULL, PRI_CANCEL);
+ if (stat->state >= 0)
+ change_connection(&down->stat, NULL,
+ PRI_CANCEL);
u = join_urls(down->url, ce->redirect);
extract_position(u);
prev_down_url = down->url;
down->url = u;
down->stat.state = S_WAIT_REDIR;
if (down->win) {
- struct links_event ev = { EV_REDRAW, 0, 0, 0 };
+ struct links_event ev = { EV_REDRAW, 0,
+ 0, 0 };
ev.x = down->win->term->x;
ev.y = down->win->term->y;
down->win->handler(down->win, &ev, 0);
}
cache = NC_CACHE;
- if (!strcmp(cast_const_char down->url, cast_const_char prev_down_url) || down->redirect_cnt >= MAX_CACHED_REDIRECTS) cache = NC_RELOAD;
+ if (!strcmp(cast_const_char down->url,
+ cast_const_char prev_down_url)
+ || down->redirect_cnt
+ >= MAX_CACHED_REDIRECTS)
+ cache = NC_RELOAD;
allow_flags = get_allow_flags(prev_down_url);
free(prev_down_url);
- load_url(down->url, NULL, &down->stat, PRI_DOWNLOAD, cache, 1, allow_flags, down->last_pos);
+ load_url(down->url, NULL, &down->stat,
+ PRI_DOWNLOAD, cache, 1, allow_flags,
+ down->last_pos);
return;
} else {
- if (stat->state >= 0) change_connection(&down->stat, NULL, PRI_CANCEL);
+ if (stat->state >= 0)
+ change_connection(&down->stat, NULL,
+ PRI_CANCEL);
stat->state = S_CYCLIC_REDIRECT;
goto end_store;
}
@@ -904,44 +1103,67 @@ static void download_data(struct status *stat, void *down_)
}
}
if (!down->decompress) {
- foreachback(struct fragment, frag, lfrag, ce->frag)
+ foreachback (struct fragment, frag, lfrag, ce->frag)
if (frag->offset <= down->last_pos)
goto have_frag;
- foreach(struct fragment, frag, lfrag, ce->frag) {
+ foreach (struct fragment, frag, lfrag, ce->frag) {
have_frag:
- while (frag->offset <= down->last_pos && frag->offset + frag->length > down->last_pos) {
- if (download_write(down, frag->data + (down->last_pos - frag->offset), frag->length - (down->last_pos - frag->offset))) {
- det_abt:
- detach_connection(stat, down->last_pos, 0, 0);
+ while (frag->offset <= down->last_pos
+ && frag->offset + frag->length
+ > down->last_pos) {
+ if (download_write(
+ down,
+ frag->data
+ + (down->last_pos - frag->offset),
+ frag->length
+ - (down->last_pos
+ - frag->offset))) {
+det_abt:
+ detach_connection(stat, down->last_pos,
+ 0, 0);
abort_download(down);
return;
}
}
}
}
- if (!down->decompress) detach_connection(stat, down->last_pos, 0, 0);
- end_store:
+ if (!down->decompress)
+ detach_connection(stat, down->last_pos, 0, 0);
+end_store:
if (stat->state < 0) {
if (down->decompress) {
struct session *ses = get_download_ses(down);
unsigned char *start;
size_t len;
int err;
- get_file_by_term(ses ? ses->term : NULL, ce, &start, &len, &err);
- if (err) goto det_abt;
+ get_file_by_term(ses ? ses->term : NULL, ce, &start,
+ &len, &err);
+ if (err)
+ goto det_abt;
while (down->last_pos < len) {
- if (download_write(down, start + down->last_pos, len - down->last_pos)) goto det_abt;
+ if (download_write(down, start + down->last_pos,
+ len - down->last_pos))
+ goto det_abt;
}
}
if (stat->state != S__OK) {
unsigned char *t = get_err_msg(stat->state);
- unsigned char *tt = display_url(get_download_ses(down)->term, down->url, 1);
- msg_box(get_download_ses(down)->term, getml(tt, NULL), TEXT_(T_DOWNLOAD_ERROR), AL_CENTER, TEXT_(T_ERROR_DOWNLOADING), cast_uchar " ", tt, cast_uchar ":\n\n", t, MSG_BOX_END, (void *)get_download_ses(down), 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC /*, TEXT_(T_RETRY), NULL, 0 !!! FIXME: retry */);
+ unsigned char *tt = display_url(
+ get_download_ses(down)->term, down->url, 1);
+ msg_box(
+ get_download_ses(down)->term, getml(tt, NULL),
+ TEXT_(T_DOWNLOAD_ERROR), AL_CENTER,
+ TEXT_(T_ERROR_DOWNLOADING), cast_uchar " ", tt,
+ cast_uchar ":\n\n", t, MSG_BOX_END,
+ (void *)get_download_ses(down),
+ 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC /*, TEXT_(T_RETRY), NULL, 0 !!! FIXME: retry */);
} else {
if (close_download_file(down)) {
download_file_error(down, errno);
} else if (down->prog) {
- exec_on_terminal(get_download_ses(down)->term, down->prog, down->orig_file, !!down->prog_flag_block);
+ exec_on_terminal(get_download_ses(down)->term,
+ down->prog, down->orig_file,
+ !!down->prog_flag_block);
free(down->prog);
down->prog = NULL;
} else if (down->remotetime && download_utime) {
@@ -950,12 +1172,16 @@ have_frag:
unsigned char *wd = get_cwd();
set_cwd(down->cwd);
utv[0].tv_usec = utv[1].tv_usec = 0;
- utv[0].tv_sec = utv[1].tv_sec = down->remotetime;
+ utv[0].tv_sec = utv[1].tv_sec =
+ down->remotetime;
while (1) {
- unsigned char *f = translate_download_file(file);
+ unsigned char *f =
+ translate_download_file(file);
EINTRLOOP(rs, utimes(cast_char f, utv));
free(f);
- if (!strcmp(cast_const_char file, cast_const_char down->file)) break;
+ if (!strcmp(cast_const_char file,
+ cast_const_char down->file))
+ break;
increase_download_file(&file);
}
free(file);
@@ -976,7 +1202,8 @@ have_frag:
}
}
-unsigned char *translate_download_file(unsigned char *fi)
+unsigned char *
+translate_download_file(unsigned char *fi)
{
unsigned char *file = stracpy(cast_uchar "");
unsigned char *h;
@@ -988,7 +1215,9 @@ unsigned char *translate_download_file(unsigned char *fi)
return file;
}
-int create_download_file(struct session *ses, unsigned char *cwd, unsigned char *fi, int mode, off_t siz)
+int
+create_download_file(struct session *ses, unsigned char *cwd, unsigned char *fi,
+ int mode, off_t siz)
{
unsigned char *wd;
unsigned char *file;
@@ -1001,7 +1230,11 @@ int create_download_file(struct session *ses, unsigned char *cwd, unsigned char
wd = get_cwd();
set_cwd(cwd);
file = translate_download_file(fi);
- h = c_open3(file, O_CREAT | O_NOCTTY | O_WRONLY | (mode & CDF_NOTRUNC ? 0 : O_TRUNC) | (mode & CDF_EXCL ? O_EXCL : 0), perm);
+ h = c_open3(file,
+ O_CREAT | O_NOCTTY | O_WRONLY
+ | (mode & CDF_NOTRUNC ? 0 : O_TRUNC)
+ | (mode & CDF_EXCL ? O_EXCL : 0),
+ perm);
if (h == -1) {
unsigned char *msg, *msge;
int errn = errno;
@@ -1009,13 +1242,18 @@ int create_download_file(struct session *ses, unsigned char *cwd, unsigned char
h = -2;
goto x;
}
- if (!ses) goto x;
+ if (!ses)
+ goto x;
msg = stracpy(file);
msge = stracpy(cast_uchar strerror(errn));
- msg_box(ses->term, getml(msg, msge, NULL), TEXT_(T_DOWNLOAD_ERROR), AL_CENTER, TEXT_(T_COULD_NOT_CREATE_FILE), cast_uchar " ", msg, cast_uchar ": ", msge, MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ msg_box(ses->term, getml(msg, msge, NULL),
+ TEXT_(T_DOWNLOAD_ERROR), AL_CENTER,
+ TEXT_(T_COULD_NOT_CREATE_FILE), cast_uchar " ", msg,
+ cast_uchar ": ", msge, MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
goto x;
}
- x:
+x:
free(file);
if (wd) {
set_cwd(wd);
@@ -1024,19 +1262,27 @@ int create_download_file(struct session *ses, unsigned char *cwd, unsigned char
return h;
}
-static int create_or_append_download_file(struct session *ses, unsigned char *cwd, unsigned char *fi, int mode, int *hp, unsigned char **xl_file, off_t *last_pos, off_t *file_shift)
+static int
+create_or_append_download_file(struct session *ses, unsigned char *cwd,
+ unsigned char *fi, int mode, int *hp,
+ unsigned char **xl_file, off_t *last_pos,
+ off_t *file_shift)
{
int rs;
- int down_flags = mode == DOWNLOAD_CONTINUE ? CDF_NOTRUNC : mode == DOWNLOAD_OVERWRITE ? 0 : CDF_EXCL;
+ int down_flags = mode == DOWNLOAD_CONTINUE ? CDF_NOTRUNC
+ : mode == DOWNLOAD_OVERWRITE ? 0
+ : CDF_EXCL;
*xl_file = stracpy(fi);
*last_pos = 0;
*file_shift = 0;
- retry_next_file:
+retry_next_file:
test_abort_downloads_to_file(*xl_file, ses->term->cwd, 1);
- if ((*hp = create_download_file(ses, ses->term->cwd, *xl_file, down_flags, 0)) < 0)
+ if ((*hp = create_download_file(ses, ses->term->cwd, *xl_file,
+ down_flags, 0))
+ < 0)
goto err_free;
if (mode == DOWNLOAD_CONTINUE) {
@@ -1050,16 +1296,27 @@ static int create_or_append_download_file(struct session *ses, unsigned char *cw
EINTRLOOP(ls, lseek(*hp, 0, SEEK_END));
if (ls == (off_t)-1) {
- unsigned char *emsg = stracpy(cast_uchar strerror(errno));
+ unsigned char *emsg =
+ stracpy(cast_uchar strerror(errno));
unsigned char *msg = stracpy(*xl_file);
- msg_box(ses->term, getml(msg, emsg, NULL), TEXT_(T_DOWNLOAD_ERROR), AL_CENTER, TEXT_(T_ERROR_CALLING_LSEEK_ON_FILE), cast_uchar " ", msg, cast_uchar ": ", emsg, MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ msg_box(ses->term, getml(msg, emsg, NULL),
+ TEXT_(T_DOWNLOAD_ERROR), AL_CENTER,
+ TEXT_(T_ERROR_CALLING_LSEEK_ON_FILE),
+ cast_uchar " ", msg, cast_uchar ": ", emsg,
+ MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL),
+ msg_box_null, B_ENTER | B_ESC);
goto err_close;
}
- if ((off_t)(0UL + *last_pos + ls) < 0 ||
- (off_t)(0UL + *last_pos + ls) < *last_pos) {
+ if ((off_t)(0UL + *last_pos + ls) < 0
+ || (off_t)(0UL + *last_pos + ls) < *last_pos) {
unsigned char *msg1 = stracpy(fi);
unsigned char *msg2 = stracpy(*xl_file);
- msg_box(ses->term, getml(msg1, msg2, NULL), TEXT_(T_DOWNLOAD_ERROR), AL_CENTER, TEXT_(T_TOO_LARGE_FILE_SEQUENCE), cast_uchar " ", msg1, cast_uchar " - ", msg2, MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ msg_box(ses->term, getml(msg1, msg2, NULL),
+ TEXT_(T_DOWNLOAD_ERROR), AL_CENTER,
+ TEXT_(T_TOO_LARGE_FILE_SEQUENCE),
+ cast_uchar " ", msg1, cast_uchar " - ", msg2,
+ MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL),
+ msg_box_null, B_ENTER | B_ESC);
goto err_close;
}
*last_pos += ls;
@@ -1078,27 +1335,31 @@ static int create_or_append_download_file(struct session *ses, unsigned char *cw
goto retry_next_file;
}
- ret_0:
+ret_0:
return 0;
- err_close:
+err_close:
EINTRLOOP(rs, close(*hp));
- err_free:
+err_free:
free(*xl_file);
return -1;
}
-static void increase_download_file(unsigned char **f)
+static void
+increase_download_file(unsigned char **f)
{
unsigned char *p = NULL, *pp = *f;
unsigned char *q;
- while ((pp = cast_uchar strstr(cast_const_char pp, ".part-"))) p = pp += 6;
+ while ((pp = cast_uchar strstr(cast_const_char pp, ".part-")))
+ p = pp += 6;
if (!p || !*p) {
- no_suffix:
+no_suffix:
add_to_strn(f, cast_uchar ".part-2");
return;
}
- for (q = p; *q; q++) if (*q < '0' || *q > '9') goto no_suffix;
+ for (q = p; *q; q++)
+ if (*q < '0' || *q > '9')
+ goto no_suffix;
for (q--; q >= p; q--) {
if (*q < '9') {
(*q)++;
@@ -1110,14 +1371,16 @@ static void increase_download_file(unsigned char **f)
add_to_strn(f, cast_uchar "0");
}
-static unsigned char *get_temp_name(unsigned char *url, unsigned char *head)
+static unsigned char *
+get_temp_name(unsigned char *url, unsigned char *head)
{
int nl;
unsigned char *name, *fn, *fnx;
unsigned char *nm;
unsigned char *directory = NULL;
nm = cast_uchar tempnam(cast_const_char directory, "links");
- if (!nm) return NULL;
+ if (!nm)
+ return NULL;
name = init_str();
nl = 0;
add_to_str(&name, &nl, nm);
@@ -1135,7 +1398,8 @@ static unsigned char *get_temp_name(unsigned char *url, unsigned char *head)
return name;
}
-unsigned char *subst_file(unsigned char *prog, unsigned char *file, int cyg_subst)
+unsigned char *
+subst_file(unsigned char *prog, unsigned char *file, int cyg_subst)
{
unsigned char *orig_prog = prog;
unsigned char *nn;
@@ -1143,12 +1407,14 @@ unsigned char *subst_file(unsigned char *prog, unsigned char *file, int cyg_subs
int l = 0;
while (*prog) {
int p;
- for (p = 0; prog[p] && prog[p] != '%'; p++);
+ for (p = 0; prog[p] && prog[p] != '%'; p++)
+ ;
add_bytes_to_str(&n, &l, prog, p);
prog += p;
if (*prog == '%') {
if (cyg_subst) {
- unsigned char *conv = os_conv_to_external_path(file, orig_prog);
+ unsigned char *conv =
+ os_conv_to_external_path(file, orig_prog);
add_to_str(&n, &l, conv);
free(conv);
} else
@@ -1161,7 +1427,8 @@ unsigned char *subst_file(unsigned char *prog, unsigned char *file, int cyg_subs
return nn;
}
-void start_download(struct session *ses, unsigned char *file, int mode)
+void
+start_download(struct session *ses, unsigned char *file, int mode)
{
struct download *down;
int h;
@@ -1173,7 +1440,10 @@ void start_download(struct session *ses, unsigned char *file, int mode)
return;
extract_position(url);
- if (create_or_append_download_file(ses, ses->term->cwd, file, mode, &h, &xl_file, &last_pos, &file_shift) < 0) return;
+ if (create_or_append_download_file(ses, ses->term->cwd, file, mode, &h,
+ &xl_file, &last_pos, &file_shift)
+ < 0)
+ return;
down = mem_calloc(sizeof(struct download));
down->url = stracpy(url);
@@ -1189,123 +1459,150 @@ void start_download(struct session *ses, unsigned char *file, int mode)
down->ses = ses;
down->remotetime = 0;
add_to_list(downloads, down);
- load_url(url, NULL, &down->stat, PRI_DOWNLOAD, NC_CACHE, 1, ses->dn_allow_flags, down->last_pos);
+ load_url(url, NULL, &down->stat, PRI_DOWNLOAD, NC_CACHE, 1,
+ ses->dn_allow_flags, down->last_pos);
display_download(ses->term, down, ses);
}
-void abort_all_downloads(void)
+void
+abort_all_downloads(void)
{
while (!list_empty(downloads)) {
- struct download *down = list_struct(downloads.next, struct download);
+ struct download *down =
+ list_struct(downloads.next, struct download);
abort_download(down);
}
}
-int f_is_finished(struct f_data *f)
+int
+f_is_finished(struct f_data *f)
{
struct additional_file *af = NULL;
struct list_head *laf;
- if (!f || f->rq->state >= 0) return 0;
- if (f->fd && f->fd->rq && f->fd->rq->state >= 0) return 0;
- if (f->af) foreach(struct additional_file, af, laf, f->af->af) if (!af->rq || af->rq->state >= 0) return 0;
+ if (!f || f->rq->state >= 0)
+ return 0;
+ if (f->fd && f->fd->rq && f->fd->rq->state >= 0)
+ return 0;
+ if (f->af)
+ foreach (struct additional_file, af, laf, f->af->af)
+ if (!af->rq || af->rq->state >= 0)
+ return 0;
return 1;
}
-static int f_is_cacheable(struct f_data *f)
+static int
+f_is_cacheable(struct f_data *f)
{
- if (!f || f->rq->state >= 0) return 0;
- if (f->fd && f->fd->rq && f->fd->rq->state >= 0) return 0;
+ if (!f || f->rq->state >= 0)
+ return 0;
+ if (f->fd && f->fd->rq && f->fd->rq->state >= 0)
+ return 0;
return 1;
}
-static int f_need_reparse(struct f_data *f)
+static int
+f_need_reparse(struct f_data *f)
{
struct additional_file *af = NULL;
struct list_head *laf;
- if (!f || f->rq->state >= 0) return 1;
- if (f->af) foreach(struct additional_file, af, laf, f->af->af) if (af->need_reparse > 0) return 1;
+ if (!f || f->rq->state >= 0)
+ return 1;
+ if (f->af)
+ foreach (struct additional_file, af, laf, f->af->af)
+ if (af->need_reparse > 0)
+ return 1;
return 0;
}
-static struct f_data *format_html(struct f_data_c *fd, struct object_request *rq, unsigned char *url, struct document_options *opt, int *cch)
+static struct f_data *
+format_html(struct f_data_c *fd, struct object_request *rq, unsigned char *url,
+ struct document_options *opt, int *cch)
{
struct f_data *f;
- pr(
- if (cch) *cch = 0;
- if (!rq->ce || !(f = init_formatted(opt))) goto nul;
- f->fd = fd;
- f->ses = fd->ses;
- f->time_to_get = -get_time();
- clone_object(rq, &f->rq);
- if (f->rq->ce) {
- unsigned char *start;
- size_t len;
- int stl = -1;
- struct additional_file *af = NULL;
- struct list_head *laf;
-
- if (fd->af) foreach(struct additional_file, af, laf, fd->af->af) if (af->need_reparse > 0) af->need_reparse = 0;
-
- get_file(rq, &start, &len);
- if (len > INT_MAX) len = INT_MAX;
- f->uncacheable = 1;
- if (opt->plain == 2) {
- start = init_str();
- stl = 0;
- add_to_str(&start, &stl, cast_uchar "<img src=\"");
- add_to_str(&start, &stl, f->rq->ce->url);
- add_to_str(&start, &stl, cast_uchar "\">");
- len = stl;
- }
- really_format_html(f->rq->ce, start, start + len, f, fd->ses ? fd != fd->ses->screen : 0);
- if (stl != -1)
- free(start);
- f->use_tag = f->rq->ce->count;
- if (f->af) foreach(struct additional_file, af, laf, f->af->af) {
- if (af->rq && af->rq->ce) {
- af->use_tag = af->rq->ce->count;
- af->use_tag2 = af->rq->ce->count2;
- } else {
- af->use_tag = 0;
- af->use_tag2 = 0;
- }
- }
- } else f->use_tag = 0;
- f->time_to_get += get_time();
- ) nul:return NULL;
+ pr(if (cch) *cch = 0;
+ if (!rq->ce || !(f = init_formatted(opt))) goto nul; f->fd = fd;
+ f->ses = fd->ses; f->time_to_get = -get_time();
+ clone_object(rq, &f->rq); if (f->rq->ce) {
+ unsigned char *start;
+ size_t len;
+ int stl = -1;
+ struct additional_file *af = NULL;
+ struct list_head *laf;
+
+ if (fd->af)
+ foreach (struct additional_file, af, laf, fd->af->af)
+ if (af->need_reparse > 0)
+ af->need_reparse = 0;
+
+ get_file(rq, &start, &len);
+ if (len > INT_MAX)
+ len = INT_MAX;
+ f->uncacheable = 1;
+ if (opt->plain == 2) {
+ start = init_str();
+ stl = 0;
+ add_to_str(&start, &stl, cast_uchar "<img src=\"");
+ add_to_str(&start, &stl, f->rq->ce->url);
+ add_to_str(&start, &stl, cast_uchar "\">");
+ len = stl;
+ }
+ really_format_html(f->rq->ce, start, start + len, f,
+ fd->ses ? fd != fd->ses->screen : 0);
+ if (stl != -1)
+ free(start);
+ f->use_tag = f->rq->ce->count;
+ if (f->af)
+ foreach (struct additional_file, af, laf,
+ f->af->af) {
+ if (af->rq && af->rq->ce) {
+ af->use_tag = af->rq->ce->count;
+ af->use_tag2 = af->rq->ce->count2;
+ } else {
+ af->use_tag = 0;
+ af->use_tag2 = 0;
+ }
+ }
+ } else f->use_tag = 0;
+ f->time_to_get += get_time();) nul : return NULL;
return f;
}
-static void count_frames(struct f_data_c *fd, unsigned long *i)
+static void
+count_frames(struct f_data_c *fd, unsigned long *i)
{
struct f_data_c *sub = NULL;
struct list_head *lsub;
- if (!fd) return;
- if (fd->f_data) (*i)++;
- foreach(struct f_data_c, sub, lsub, fd->subframes) count_frames(sub, i);
+ if (!fd)
+ return;
+ if (fd->f_data)
+ (*i)++;
+ foreach (struct f_data_c, sub, lsub, fd->subframes)
+ count_frames(sub, i);
}
-unsigned long formatted_info(int type)
+unsigned long
+formatted_info(int type)
{
unsigned long i = 0;
struct session *ses = NULL;
struct list_head *lses;
switch (type) {
- case CI_FILES:
- foreach(struct session, ses, lses, sessions)
- i += list_size(&ses->format_cache);
- /*-fallthrough*/
- case CI_LOCKED:
- foreach(struct session, ses, lses, sessions)
- count_frames(ses->screen, &i);
- return i;
- default:
- internal("formatted_info: bad request");
+ case CI_FILES:
+ foreach (struct session, ses, lses, sessions)
+ i += list_size(&ses->format_cache);
+ /*-fallthrough*/
+ case CI_LOCKED:
+ foreach (struct session, ses, lses, sessions)
+ count_frames(ses->screen, &i);
+ return i;
+ default:
+ internal("formatted_info: bad request");
}
return 0;
}
-static void f_data_attach(struct f_data_c *fd, struct f_data *f)
+static void
+f_data_attach(struct f_data_c *fd, struct f_data *f)
{
struct additional_file *af = NULL;
struct list_head *laf;
@@ -1315,51 +1612,65 @@ static void f_data_attach(struct f_data_c *fd, struct f_data *f)
fd->af = f->af;
if (f->af) {
f->af->refcount++;
- foreachback(struct additional_file, af, laf, f->af->af) {
+ foreachback (struct additional_file, af, laf, f->af->af) {
if (af->rq) {
af->rq->upcall = fd_loaded;
af->rq->data = fd;
} else {
- request_object(fd->ses->term, af->url, f->rq->url, PRI_IMG, NC_CACHE, get_allow_flags(f->rq->url), f->rq->upcall, f->rq->data, &af->rq);
+ request_object(
+ fd->ses->term, af->url, f->rq->url, PRI_IMG,
+ NC_CACHE, get_allow_flags(f->rq->url),
+ f->rq->upcall, f->rq->data, &af->rq);
}
}
}
}
-static inline int is_format_cache_entry_uptodate(struct f_data *f)
+static inline int
+is_format_cache_entry_uptodate(struct f_data *f)
{
struct cache_entry *ce = f->rq->ce;
struct additional_file *af = NULL;
struct list_head *laf;
- if (!ce || ce->count != f->use_tag) return 0;
- if (f->af) foreach(struct additional_file, af, laf, f->af->af) {
- struct cache_entry *ce = af->rq ? af->rq->ce : NULL;
- tcount tag = ce ? ce->count : 0;
- tcount tag2 = ce ? ce->count2 : 0;
- if (af->need_reparse > 0) if (tag != af->use_tag) return 0;
- if (af->unknown_image_size) if (tag2 != af->use_tag2) return 0;
- }
+ if (!ce || ce->count != f->use_tag)
+ return 0;
+ if (f->af)
+ foreach (struct additional_file, af, laf, f->af->af) {
+ struct cache_entry *ce = af->rq ? af->rq->ce : NULL;
+ tcount tag = ce ? ce->count : 0;
+ tcount tag2 = ce ? ce->count2 : 0;
+ if (af->need_reparse > 0)
+ if (tag != af->use_tag)
+ return 0;
+ if (af->unknown_image_size)
+ if (tag2 != af->use_tag2)
+ return 0;
+ }
return 1;
}
-static void detach_f_data(struct f_data **ff)
+static void
+detach_f_data(struct f_data **ff)
{
struct f_data *f = *ff;
struct f_data_c *fd;
- if (!f) return;
+ if (!f)
+ return;
fd = f->fd;
*ff = NULL;
f->fd = NULL;
- if (f->frame_desc_link || f->uncacheable || !f_is_cacheable(f) || !is_format_cache_entry_uptodate(f) || !f->ses) {
+ if (f->frame_desc_link || f->uncacheable || !f_is_cacheable(f)
+ || !is_format_cache_entry_uptodate(f) || !f->ses) {
destroy_formatted(f);
} else {
add_to_list(f->ses->format_cache, f);
- copy_additional_files(&fd->af); /* break structure sharing */
+ copy_additional_files(&fd->af); /* break structure sharing */
}
}
-int shrink_format_cache(int u)
+int
+shrink_format_cache(int u)
{
static int sc = 0;
int scc;
@@ -1367,35 +1678,41 @@ int shrink_format_cache(int u)
int c = 0;
struct session *ses = NULL;
struct list_head *lses;
- foreach(struct session, ses, lses, sessions) {
+ foreach (struct session, ses, lses, sessions) {
struct f_data *f = NULL;
struct list_head *lf;
- foreach(struct f_data, f, lf, ses->format_cache) {
- if (u == SH_FREE_ALL || !is_format_cache_entry_uptodate(f)) {
+ foreach (struct f_data, f, lf, ses->format_cache) {
+ if (u == SH_FREE_ALL
+ || !is_format_cache_entry_uptodate(f)) {
lf = lf->prev;
del_from_list(f);
destroy_formatted(f);
r |= ST_SOMETHING_FREED;
- } else c++;
+ } else
+ c++;
}
}
if (c > max_format_cache_entries || (c && u == SH_FREE_SOMETHING)) {
int sc_cycle = 0;
unsigned char freed_in_cycle = 0;
- a:
+a:
scc = sc++;
- foreach (struct session, ses, lses, sessions) if (!scc--) {
- if (!list_empty(ses->format_cache)) {
- struct f_data *ff = list_struct(ses->format_cache.prev, struct f_data);
- del_from_list(ff);
- destroy_formatted(ff);
- r |= ST_SOMETHING_FREED;
- if (--c <= max_format_cache_entries ||
- u == SH_FREE_SOMETHING) goto ret;
- freed_in_cycle = 1;
+ foreach (struct session, ses, lses, sessions)
+ if (!scc--) {
+ if (!list_empty(ses->format_cache)) {
+ struct f_data *ff =
+ list_struct(ses->format_cache.prev,
+ struct f_data);
+ del_from_list(ff);
+ destroy_formatted(ff);
+ r |= ST_SOMETHING_FREED;
+ if (--c <= max_format_cache_entries
+ || u == SH_FREE_SOMETHING)
+ goto ret;
+ freed_in_cycle = 1;
+ }
+ goto a;
}
- goto a;
- }
sc = 0;
sc_cycle++;
if (sc_cycle >= 2 && !freed_in_cycle)
@@ -1403,16 +1720,18 @@ int shrink_format_cache(int u)
freed_in_cycle = 0;
goto a;
}
- ret:
+ret:
return r | (!c ? ST_CACHE_EMPTY : 0);
}
-void init_fcache(void)
+void
+init_fcache(void)
{
register_cache_upcall(shrink_format_cache, MF_GPI, cast_uchar "format");
}
-static void calculate_scrollbars(struct f_data_c *fd, struct f_data *f)
+static void
+calculate_scrollbars(struct f_data_c *fd, struct f_data *f)
{
fd->hsb = 0;
fd->vsb = 0;
@@ -1424,7 +1743,7 @@ static void calculate_scrollbars(struct f_data_c *fd, struct f_data *f)
fd->hsb = 1;
fd->vsb = 1;
} else if (f->opt.scrolling == SCROLLING_AUTO) {
- x:
+x:
if (!fd->hsb && f->x > fd->xw - fd->vsb * G_SCROLL_BAR_WIDTH) {
fd->hsb = 1;
goto x;
@@ -1434,33 +1753,47 @@ static void calculate_scrollbars(struct f_data_c *fd, struct f_data *f)
goto x;
}
}
- if (fd->hsb) fd->hsbsize = fd->xw - fd->vsb * G_SCROLL_BAR_WIDTH;
- if (fd->vsb) fd->vsbsize = fd->yw - fd->hsb * G_SCROLL_BAR_WIDTH;
- if (fd->hsbsize < 0) fd->hsb = 0;
- if (fd->vsbsize < 0) fd->vsb = 0;
+ if (fd->hsb)
+ fd->hsbsize = fd->xw - fd->vsb * G_SCROLL_BAR_WIDTH;
+ if (fd->vsb)
+ fd->vsbsize = fd->yw - fd->hsb * G_SCROLL_BAR_WIDTH;
+ if (fd->hsbsize < 0)
+ fd->hsb = 0;
+ if (fd->vsbsize < 0)
+ fd->vsb = 0;
}
-struct f_data *cached_format_html(struct f_data_c *fd, struct object_request *rq, unsigned char *url, struct document_options *opt, int *cch, int report_status)
+struct f_data *
+cached_format_html(struct f_data_c *fd, struct object_request *rq,
+ unsigned char *url, struct document_options *opt, int *cch,
+ int report_status)
{
struct session *ses = fd->ses;
struct f_data *f = NULL;
struct list_head *lf;
if (fd->marginwidth != -1) {
- int marg = (fd->marginwidth + G_HTML_MARGIN - 1) / G_HTML_MARGIN;
- if (marg >= 0 && marg < 9) opt->margin = marg;
+ int marg =
+ (fd->marginwidth + G_HTML_MARGIN - 1) / G_HTML_MARGIN;
+ if (marg >= 0 && marg < 9)
+ opt->margin = marg;
}
if (opt->plain == 2) {
opt->margin = 0;
opt->display_images = 1;
}
- pr(
- if (ses) {
- if (fd->f_data && !strcmp(cast_const_char fd->f_data->rq->url, cast_const_char url) && !compare_opt(&fd->f_data->opt, opt) && is_format_cache_entry_uptodate(fd->f_data)) {
+ pr(if (ses) {
+ if (fd->f_data
+ && !strcmp(cast_const_char fd->f_data->rq->url,
+ cast_const_char url)
+ && !compare_opt(&fd->f_data->opt, opt)
+ && is_format_cache_entry_uptodate(fd->f_data)) {
f = fd->f_data;
goto ret_f;
}
- foreach(struct f_data, f, lf, ses->format_cache) {
- if (!strcmp(cast_const_char f->rq->url, cast_const_char url) && !compare_opt(&f->opt, opt)) {
+ foreach (struct f_data, f, lf, ses->format_cache) {
+ if (!strcmp(cast_const_char f->rq->url,
+ cast_const_char url)
+ && !compare_opt(&f->opt, opt)) {
if (!is_format_cache_entry_uptodate(f)) {
lf = lf->prev;
del_from_list(f);
@@ -1470,26 +1803,32 @@ struct f_data *cached_format_html(struct f_data_c *fd, struct object_request *rq
detach_f_data(&fd->f_data);
del_from_list(f);
f->fd = fd;
- if (cch) *cch = 1;
+ if (cch)
+ *cch = 1;
f_data_attach(fd, f);
goto ret_f;
}
}
- }) {};
+ }){};
if (ses) {
- if (report_status || !fd->f_data || fd->f_data->time_to_get >= DISPLAY_FORMATTING_STATUS || (rq->ce && rq->ce->length >= 1000000))
+ if (report_status || !fd->f_data
+ || fd->f_data->time_to_get >= DISPLAY_FORMATTING_STATUS
+ || (rq->ce && rq->ce->length >= 1000000))
print_progress(ses, TEXT_(T_FORMATTING_DOCUMENT));
}
detach_f_data(&fd->f_data);
f = format_html(fd, rq, url, opt, cch);
- if (f) f->fd = fd;
+ if (f)
+ f->fd = fd;
shrink_memory(SH_CHECK_QUOTA);
ret_f:
calculate_scrollbars(fd, f);
return f;
}
-static void create_new_frames(struct f_data_c *fd, struct frameset_desc *fs, struct document_options *o)
+static void
+create_new_frames(struct f_data_c *fd, struct frameset_desc *fs,
+ struct document_options *o)
{
struct list_head *lloc;
struct frame_desc *frm;
@@ -1499,9 +1838,10 @@ static void create_new_frames(struct f_data_c *fd, struct frameset_desc *fs, str
if (list_size(&fd->loc->subframes) != (unsigned long)fs->n) {
while (!list_empty(fd->loc->subframes))
- destroy_location(list_struct(fd->loc->subframes.next, struct location));
+ destroy_location(list_struct(fd->loc->subframes.next,
+ struct location));
c_loc = 1;
- lloc = NULL; /* against warning */
+ lloc = NULL; /* against warning */
} else {
c_loc = 0;
lloc = fd->loc->subframes.next;
@@ -1521,51 +1861,74 @@ static void create_new_frames(struct f_data_c *fd, struct frameset_desc *fs, str
loc->parent = fd->loc;
loc->name = stracpy(frm->name);
if ((loc->url = stracpy(frm->url)))
- nfdc->goto_position = extract_position(loc->url);
+ nfdc->goto_position =
+ extract_position(loc->url);
} else {
loc = list_struct(lloc, struct location);
}
- nfdc->xp = xp; nfdc->yp = yp;
+ nfdc->xp = xp;
+ nfdc->yp = yp;
nfdc->xw = frm->xw;
nfdc->yw = frm->yw;
nfdc->scrolling = frm->scrolling;
nfdc->loc = loc;
nfdc->vs = loc->vs;
- if (frm->marginwidth != -1) nfdc->marginwidth = frm->marginwidth;
- else nfdc->marginwidth = fd->marginwidth;
- if (frm->marginheight != -1) nfdc->marginheight = frm->marginheight;
- else nfdc->marginheight = fd->marginheight;
+ if (frm->marginwidth != -1)
+ nfdc->marginwidth = frm->marginwidth;
+ else
+ nfdc->marginwidth = fd->marginwidth;
+ if (frm->marginheight != -1)
+ nfdc->marginheight = frm->marginheight;
+ else
+ nfdc->marginheight = fd->marginheight;
add_to_list_end(fd->subframes, nfdc);
if (frm->subframe) {
create_new_frames(nfdc, frm->subframe, o);
- /*nfdc->f_data = init_formatted(&fd->f_data->opt);*/
+ /*nfdc->f_data =
+ * init_formatted(&fd->f_data->opt);*/
nfdc->f_data = init_formatted(o);
- nfdc->f_data->frame_desc = copy_frameset_desc(frm->subframe);
+ nfdc->f_data->frame_desc =
+ copy_frameset_desc(frm->subframe);
nfdc->f_data->frame_desc_link = 1;
} else {
- if (fd->depth < HTML_MAX_FRAME_DEPTH && loc->url && *loc->url) {
+ if (fd->depth < HTML_MAX_FRAME_DEPTH && loc->url
+ && *loc->url) {
struct f_data_c *rel = fd;
- while (rel->parent && !rel->rq) rel = rel->parent;
- request_object(fd->ses->term, loc->url, rel->rq ? rel->rq->url : NULL, PRI_FRAME, NC_CACHE, rel->rq ? get_allow_flags(rel->rq->url) : 0, fd_loaded, nfdc, &nfdc->rq);
+ while (rel->parent && !rel->rq)
+ rel = rel->parent;
+ request_object(
+ fd->ses->term, loc->url,
+ rel->rq ? rel->rq->url : NULL,
+ PRI_FRAME, NC_CACHE,
+ rel->rq
+ ? get_allow_flags(rel->rq->url)
+ : 0,
+ fd_loaded, nfdc, &nfdc->rq);
}
}
xp += frm->xw + 1;
frm++;
- if (!c_loc) lloc = lloc->next;
+ if (!c_loc)
+ lloc = lloc->next;
}
yp += (frm - 1)->yw + 1;
}
}
-static void html_interpret(struct f_data_c *fd, int report_status)
+static void
+html_interpret(struct f_data_c *fd, int report_status)
{
int i;
- int oxw; int oyw; int oxp; int oyp;
+ int oxw;
+ int oyw;
+ int oxp;
+ int oyp;
struct f_data_c *sf = NULL;
struct list_head *lsf;
int cch;
struct document_options o;
- if (!fd->loc) goto d;
+ if (!fd->loc)
+ goto d;
if (fd->f_data) {
oxw = fd->f_data->opt.xw;
oyw = fd->f_data->opt.yw;
@@ -1606,44 +1969,55 @@ static void html_interpret(struct f_data_c *fd, int report_status)
o.col = 3;
o.cp = 0;
}
- if (!(o.framename = fd->loc->name)) o.framename = NULL;
- if (!(fd->f_data = cached_format_html(fd, fd->rq, fd->rq->url, &o, &cch, report_status))) {
+ if (!(o.framename = fd->loc->name))
+ o.framename = NULL;
+ if (!(fd->f_data = cached_format_html(fd, fd->rq, fd->rq->url, &o, &cch,
+ report_status))) {
goto d;
}
/* erase frames if changed */
i = (int)list_size(&fd->subframes);
- if (i != (fd->f_data->frame_desc ? fd->f_data->frame_desc->n : 0) && (f_is_finished(fd->f_data) || !f_need_reparse(fd->f_data))) {
- rd:
- foreach(struct f_data_c, sf, lsf, fd->subframes) reinit_f_data_c(sf);
+ if (i != (fd->f_data->frame_desc ? fd->f_data->frame_desc->n : 0)
+ && (f_is_finished(fd->f_data) || !f_need_reparse(fd->f_data))) {
+rd:
+ foreach (struct f_data_c, sf, lsf, fd->subframes)
+ reinit_f_data_c(sf);
free_list(struct f_data_c, fd->subframes);
/* create new frames */
- if (fd->f_data->frame_desc) create_new_frames(fd, fd->f_data->frame_desc, &fd->f_data->opt);
+ if (fd->f_data->frame_desc)
+ create_new_frames(fd, fd->f_data->frame_desc,
+ &fd->f_data->opt);
} else {
if (fd->f_data->frame_desc && fd->f_data->rq->state < 0) {
- if (fd->f_data->opt.xw != oxw ||
- fd->f_data->opt.yw != oyw ||
- fd->f_data->opt.xp != oxp ||
- fd->f_data->opt.yp != oyp) goto rd;
+ if (fd->f_data->opt.xw != oxw
+ || fd->f_data->opt.yw != oyw
+ || fd->f_data->opt.xp != oxp
+ || fd->f_data->opt.yp != oyp)
+ goto rd;
}
}
- d:;
+d:;
}
-void html_interpret_recursive(struct f_data_c *f)
+void
+html_interpret_recursive(struct f_data_c *f)
{
struct f_data_c *fd = NULL;
struct list_head *lfd;
- if (f->rq) html_interpret(f, 1);
- foreach(struct f_data_c, fd, lfd, f->subframes) html_interpret_recursive(fd);
+ if (f->rq)
+ html_interpret(f, 1);
+ foreach (struct f_data_c, fd, lfd, f->subframes)
+ html_interpret_recursive(fd);
}
/* You get a struct_additionl_file. never mem_free it. When you stop
* using it, just forget the pointer.
*/
-struct additional_file *request_additional_file(struct f_data *f, unsigned char *url_)
+struct additional_file *
+request_additional_file(struct f_data *f, unsigned char *url_)
{
size_t sl;
struct additional_file *af = NULL;
@@ -1653,18 +2027,21 @@ struct additional_file *request_additional_file(struct f_data *f, unsigned char
extract_position(url);
if (!f->af) {
if (!(f->af = f->fd->af)) {
- f->af = f->fd->af = xmalloc(sizeof(struct additional_files));
+ f->af = f->fd->af =
+ xmalloc(sizeof(struct additional_files));
f->af->refcount = 1;
init_list(f->af->af);
}
f->af->refcount++;
}
- foreach(struct additional_file, af, laf, f->af->af) if (!strcmp(cast_const_char af->url, cast_const_char url)) {
- free(url);
- return af;
- }
+ foreach (struct additional_file, af, laf, f->af->af)
+ if (!strcmp(cast_const_char af->url, cast_const_char url)) {
+ free(url);
+ return af;
+ }
sl = strlen(cast_const_char url);
- if (sl > INT_MAX - sizeof(struct additional_file)) overalloc();
+ if (sl > INT_MAX - sizeof(struct additional_file))
+ overalloc();
af = xmalloc(sizeof(struct additional_file) + sl);
af->use_tag = 0;
af->use_tag2 = 0;
@@ -1672,7 +2049,9 @@ struct additional_file *request_additional_file(struct f_data *f, unsigned char
if (!strcmp(cast_const_char url, cast_const_char f->rq->url))
clone_object(f->rq, &af->rq);
else
- request_object(f->ses->term, url, f->rq->url, PRI_IMG, NC_CACHE, get_allow_flags(f->rq->url), f->rq->upcall, f->rq->data, &af->rq);
+ request_object(f->ses->term, url, f->rq->url, PRI_IMG, NC_CACHE,
+ get_allow_flags(f->rq->url), f->rq->upcall,
+ f->rq->data, &af->rq);
af->need_reparse = 0;
af->unknown_image_size = 0;
add_to_list(f->af->af, af);
@@ -1680,48 +2059,62 @@ struct additional_file *request_additional_file(struct f_data *f, unsigned char
return af;
}
-static void copy_additional_files(struct additional_files **a)
+static void
+copy_additional_files(struct additional_files **a)
{
struct additional_files *afs;
struct additional_file *af = NULL;
struct list_head *laf;
- if (!*a || (*a)->refcount == 1) return;
+ if (!*a || (*a)->refcount == 1)
+ return;
(*a)->refcount--;
afs = xmalloc(sizeof(struct additional_files));
afs->refcount = 1;
init_list(afs->af);
- foreachback(struct additional_file, af, laf, (*a)->af) {
+ foreachback (struct additional_file, af, laf, (*a)->af) {
struct additional_file *afc;
size_t sl = strlen(cast_const_char af->url);
- if (sl > INT_MAX - sizeof(struct additional_file)) overalloc();
+ if (sl > INT_MAX - sizeof(struct additional_file))
+ overalloc();
afc = xmalloc(sizeof(struct additional_file) + sl);
memcpy(afc, af, sizeof(struct additional_file) + sl);
- if (af->rq) clone_object(af->rq, &afc->rq);
+ if (af->rq)
+ clone_object(af->rq, &afc->rq);
add_to_list(afs->af, afc);
}
*a = afs;
}
-void reinit_f_data_c(struct f_data_c *fd)
+void
+reinit_f_data_c(struct f_data_c *fd)
{
struct additional_file *af = NULL;
struct list_head *laf;
struct f_data_c *fd1 = NULL;
struct list_head *lfd1;
- foreach(struct f_data_c, fd1, lfd1, fd->subframes) {
- if (fd->ses->wtd_target_base == fd1) fd->ses->wtd_target_base = NULL;
+ foreach (struct f_data_c, fd1, lfd1, fd->subframes) {
+ if (fd->ses->wtd_target_base == fd1)
+ fd->ses->wtd_target_base = NULL;
reinit_f_data_c(fd1);
- if (fd->ses->wtd_target_base == fd1) fd->ses->wtd_target_base = fd;
+ if (fd->ses->wtd_target_base == fd1)
+ fd->ses->wtd_target_base = fd;
}
free_list(struct f_data_c, fd->subframes);
fd->loc = NULL;
- if (fd->f_data && fd->f_data->rq) fd->f_data->rq->upcall = NULL;
- if (fd->f_data && fd->f_data->af) foreach(struct additional_file, af, laf, fd->f_data->af->af) if (af->rq) {
- af->rq->upcall = NULL;
- if (af->rq->state != O_OK) release_object(&af->rq);
- }
- if (fd->af) foreach(struct additional_file, af, laf, fd->af->af) if (af->rq) af->rq->upcall = NULL;
+ if (fd->f_data && fd->f_data->rq)
+ fd->f_data->rq->upcall = NULL;
+ if (fd->f_data && fd->f_data->af)
+ foreach (struct additional_file, af, laf, fd->f_data->af->af)
+ if (af->rq) {
+ af->rq->upcall = NULL;
+ if (af->rq->state != O_OK)
+ release_object(&af->rq);
+ }
+ if (fd->af)
+ foreach (struct additional_file, af, laf, fd->af->af)
+ if (af->rq)
+ af->rq->upcall = NULL;
free_additional_files(&fd->af);
detach_f_data(&fd->f_data);
release_object(&fd->rq);
@@ -1746,7 +2139,8 @@ void reinit_f_data_c(struct f_data_c *fd)
}
}
-struct f_data_c *create_f_data_c(struct session *ses, struct f_data_c *parent)
+struct f_data_c *
+create_f_data_c(struct session *ses, struct f_data_c *parent)
{
struct f_data_c *fd;
fd = mem_calloc(sizeof(struct f_data_c));
@@ -1766,13 +2160,16 @@ struct f_data_c *create_f_data_c(struct session *ses, struct f_data_c *parent)
return fd;
}
-int f_data_c_allow_flags(struct f_data_c *fd)
+int
+f_data_c_allow_flags(struct f_data_c *fd)
{
- if (fd->rq) return get_allow_flags(fd->rq->url);
+ if (fd->rq)
+ return get_allow_flags(fd->rq->url);
return 0;
}
-static int is_forced_download(struct object_request *rq)
+static int
+is_forced_download(struct object_request *rq)
{
struct cache_entry *ce;
unsigned char *cd;
@@ -1781,40 +2178,49 @@ static int is_forced_download(struct object_request *rq)
if (!rq || !(ce = rq->ce))
return ret;
- if ((cd = parse_http_header(ce->head, cast_uchar "Content-Disposition", NULL))) {
- if ((s = strchr(cast_const_char cd, ';'))) *s = 0;
+ if ((cd = parse_http_header(ce->head, cast_uchar "Content-Disposition",
+ NULL))) {
+ if ((s = strchr(cast_const_char cd, ';')))
+ *s = 0;
ret = !casestrcmp(cd, cast_uchar "attachment");
free(cd);
}
return ret;
}
-static int plain_type(struct object_request *rq, unsigned char **p)
+static int
+plain_type(struct object_request *rq, unsigned char **p)
{
struct cache_entry *ce;
unsigned char *ct;
int r = 0;
- if (p) *p = NULL;
+ if (p)
+ *p = NULL;
if (!rq || !(ce = rq->ce)) {
r = 1;
goto f;
}
- if (!(ct = get_content_type(ce->head, ce->url))) goto f;
- if (is_html_type(ct)) goto ff;
+ if (!(ct = get_content_type(ce->head, ce->url)))
+ goto f;
+ if (is_html_type(ct))
+ goto ff;
r = 1;
- if (!casestrcmp(ct, cast_uchar "text/plain") ||
- !casestrcmp(ct, cast_uchar "file/txt")) goto ff;
+ if (!casestrcmp(ct, cast_uchar "text/plain")
+ || !casestrcmp(ct, cast_uchar "file/txt"))
+ goto ff;
r = -1;
- ff:
+ff:
if (!p)
free(ct);
- else *p = ct;
- f:
+ else
+ *p = ct;
+f:
return r;
}
-static void refresh_timer(void *fd_)
+static void
+refresh_timer(void *fd_)
{
struct f_data_c *fd = (struct f_data_c *)fd_;
if (fd->ses->rq) {
@@ -1823,23 +2229,28 @@ static void refresh_timer(void *fd_)
}
fd->refresh_timer = NULL;
if (fd->f_data && fd->f_data->refresh) {
- fd->refresh_timer = install_timer(fd->f_data->refresh_seconds * 1000, refresh_timer, fd);
- goto_url_f(fd->ses, NULL, fd->f_data->refresh, cast_uchar "_self", fd, -1, 0, 0, 1);
+ fd->refresh_timer = install_timer(
+ fd->f_data->refresh_seconds * 1000, refresh_timer, fd);
+ goto_url_f(fd->ses, NULL, fd->f_data->refresh,
+ cast_uchar "_self", fd, -1, 0, 0, 1);
}
}
-void fd_loaded(struct object_request *rq, void *fd_)
+void
+fd_loaded(struct object_request *rq, void *fd_)
{
struct f_data_c *fd = (struct f_data_c *)fd_;
int first = !fd->f_data;
if (fd->done) {
- if (f_is_finished(fd->f_data)) goto priint;
+ if (f_is_finished(fd->f_data))
+ goto priint;
else {
fd->done = 0;
fd->parsed_done = 1;
}
}
- if (fd->parsed_done && f_need_reparse(fd->f_data)) fd->parsed_done = 0;
+ if (fd->parsed_done && f_need_reparse(fd->f_data))
+ fd->parsed_done = 0;
if (fd->vs->plain == -1 && rq->state != O_WAITING) {
fd->vs->plain = plain_type(fd->rq, NULL);
}
@@ -1848,7 +2259,8 @@ void fd_loaded(struct object_request *rq, void *fd_)
html_interpret(fd, 1);
if (fd->went_to_position) {
if (!fd->goto_position) {
- fd->goto_position = fd->went_to_position;
+ fd->goto_position =
+ fd->went_to_position;
fd->went_to_position = NULL;
} else {
free(fd->went_to_position);
@@ -1857,23 +2269,30 @@ void fd_loaded(struct object_request *rq, void *fd_)
}
}
draw_fd(fd);
- /* it may happen that html_interpret requests load of additional file */
- if (!f_is_finished(fd->f_data)) goto more_data;
+ /* it may happen that html_interpret requests load of additional
+ * file */
+ if (!f_is_finished(fd->f_data))
+ goto more_data;
fn:
fd->done = 1;
fd->parsed_done = 0;
if (fd->f_data->refresh) {
- if (fd->refresh_timer != NULL) kill_timer(fd->refresh_timer);
- fd->refresh_timer = install_timer(fd->f_data->refresh_seconds * 1000, refresh_timer, fd);
+ if (fd->refresh_timer != NULL)
+ kill_timer(fd->refresh_timer);
+ fd->refresh_timer =
+ install_timer(fd->f_data->refresh_seconds * 1000,
+ refresh_timer, fd);
}
- } else if (get_time() - fd->last_update >= fd->next_update_interval || (rq == fd->rq && rq->state < 0)) {
+ } else if (get_time() - fd->last_update >= fd->next_update_interval
+ || (rq == fd->rq && rq->state < 0)) {
uttime t;
if (!fd->parsed_done) {
html_interpret(fd, rq == fd->rq && rq->state < 0);
if (fd->rq->state < 0 && !f_need_reparse(fd->f_data)) {
if (fd->went_to_position) {
if (!fd->goto_position) {
- fd->goto_position = fd->went_to_position;
+ fd->goto_position =
+ fd->went_to_position;
fd->went_to_position = NULL;
} else {
free(fd->went_to_position);
@@ -1884,11 +2303,18 @@ fn:
}
}
draw_fd(fd);
- if (fd->rq->state < 0 && f_is_finished(fd->f_data)) goto fn;
+ if (fd->rq->state < 0 && f_is_finished(fd->f_data))
+ goto fn;
more_data:
- t = fd->f_data ? ((fd->parsed_done ? 0 : fd->f_data->time_to_get * DISPLAY_TIME) + fd->f_data->time_to_draw * IMG_DISPLAY_TIME) : 0;
- if (t < DISPLAY_TIME_MIN) t = DISPLAY_TIME_MIN;
- if (first && t > DISPLAY_TIME_MAX_FIRST) t = DISPLAY_TIME_MAX_FIRST;
+ t = fd->f_data ? ((fd->parsed_done
+ ? 0
+ : fd->f_data->time_to_get * DISPLAY_TIME)
+ + fd->f_data->time_to_draw * IMG_DISPLAY_TIME)
+ : 0;
+ if (t < DISPLAY_TIME_MIN)
+ t = DISPLAY_TIME_MIN;
+ if (first && t > DISPLAY_TIME_MAX_FIRST)
+ t = DISPLAY_TIME_MAX_FIRST;
fd->last_update = get_time();
fd->next_update_interval = t;
} else {
@@ -1897,12 +2323,15 @@ more_data:
}
priint:
/* process onload handler of a frameset */
- if (rq && (rq->state == O_FAILED || rq->state == O_INCOMPLETE) && (fd->rq == rq || fd->ses->rq == rq) && !rq->dont_print_error) print_error_dialog(fd->ses, &rq->stat, rq->url);
+ if (rq && (rq->state == O_FAILED || rq->state == O_INCOMPLETE)
+ && (fd->rq == rq || fd->ses->rq == rq) && !rq->dont_print_error)
+ print_error_dialog(fd->ses, &rq->stat, rq->url);
}
static unsigned location_id = 0;
-static struct location *new_location(void)
+static struct location *
+new_location(void)
{
struct location *loc;
loc = mem_calloc(sizeof(struct location));
@@ -1912,7 +2341,8 @@ static struct location *new_location(void)
return loc;
}
-static struct location *alloc_ses_location(struct session *ses)
+static struct location *
+alloc_ses_location(struct session *ses)
{
struct location *loc;
loc = new_location();
@@ -1920,49 +2350,61 @@ static struct location *alloc_ses_location(struct session *ses)
return loc;
}
-static void subst_location(struct f_data_c *fd, struct location *old, struct location *neww)
+static void
+subst_location(struct f_data_c *fd, struct location *old, struct location *neww)
{
struct f_data_c *f = NULL;
struct list_head *lf;
- foreach(struct f_data_c, f, lf, fd->subframes) subst_location(f, old, neww);
- if (fd->loc == old) fd->loc = neww;
+ foreach (struct f_data_c, f, lf, fd->subframes)
+ subst_location(f, old, neww);
+ if (fd->loc == old)
+ fd->loc = neww;
}
-static struct location *copy_sublocations(struct session *ses, struct location *d, struct location *s, struct location *x)
+static struct location *
+copy_sublocations(struct session *ses, struct location *d, struct location *s,
+ struct location *x)
{
struct location *sl = NULL, *y;
struct list_head *lsl;
d->name = stracpy(s->name);
- if (s == x) return d;
+ if (s == x)
+ return d;
d->url = stracpy(s->url);
d->prev_url = stracpy(s->prev_url);
destroy_vs(d->vs);
- d->vs = s->vs; s->vs->refcount++;
+ d->vs = s->vs;
+ s->vs->refcount++;
subst_location(ses->screen, s, d);
y = NULL;
- foreach(struct location, sl, lsl, s->subframes) {
+ foreach (struct location, sl, lsl, s->subframes) {
struct location *dl, *z;
dl = new_location();
add_to_list_end(d->subframes, dl);
dl->parent = d;
z = copy_sublocations(ses, dl, sl, x);
- if (z && y) internal("copy_sublocations: crossed references");
- if (z) y = z;
+ if (z && y)
+ internal("copy_sublocations: crossed references");
+ if (z)
+ y = z;
}
return y;
}
-static struct location *copy_location(struct session *ses, struct location *loc)
+static struct location *
+copy_location(struct session *ses, struct location *loc)
{
struct location *l2, *l1, *nl;
l1 = cur_loc(ses);
l2 = alloc_ses_location(ses);
- if (!(nl = copy_sublocations(ses, l2, l1, loc))) internal("copy_location: sublocation not found");
+ if (!(nl = copy_sublocations(ses, l2, l1, loc)))
+ internal("copy_location: sublocation not found");
return nl;
}
-static struct f_data_c *new_main_location(struct session *ses)
+static struct f_data_c *
+new_main_location(struct session *ses)
{
struct location *loc;
loc = alloc_ses_location(ses);
@@ -1970,13 +2412,14 @@ static struct f_data_c *new_main_location(struct session *ses)
ses->screen->loc = loc;
ses->screen->vs = loc->vs;
if (ses->wanted_framename) {
- loc->name=ses->wanted_framename;
- ses->wanted_framename=NULL;
+ loc->name = ses->wanted_framename;
+ ses->wanted_framename = NULL;
}
return ses->screen;
}
-static struct f_data_c *copy_location_and_replace_frame(struct session *ses, struct f_data_c *fd)
+static struct f_data_c *
+copy_location_and_replace_frame(struct session *ses, struct f_data_c *fd)
{
struct location *loc;
loc = copy_location(ses, fd->loc);
@@ -1989,32 +2432,41 @@ static struct f_data_c *copy_location_and_replace_frame(struct session *ses, str
/* vrati frame prislusici danemu targetu
pokud takovy frame nenajde, vraci NULL
*/
-struct f_data_c *find_frame(struct session *ses, unsigned char *target, struct f_data_c *base)
+struct f_data_c *
+find_frame(struct session *ses, unsigned char *target, struct f_data_c *base)
{
struct f_data_c *f, *ff = NULL;
struct list_head *lff;
- if (!base) base = ses->screen;
- if (!target || !*target) return base;
+ if (!base)
+ base = ses->screen;
+ if (!target || !*target)
+ return base;
if (!casestrcmp(target, cast_uchar "_blank"))
- return NULL; /* open in new window */
+ return NULL; /* open in new window */
if (!casestrcmp(target, cast_uchar "_top"))
return ses->screen;
- if (!casestrcmp(target, cast_uchar "_self")) return base;
+ if (!casestrcmp(target, cast_uchar "_self"))
+ return base;
if (!casestrcmp(target, cast_uchar "_parent")) {
for (ff = base->parent; ff && !ff->rq; ff = ff->parent)
;
return ff ? ff : ses->screen;
}
f = ses->screen;
- if (f->loc && f->loc->name && !casestrcmp(f->loc->name, target)) return f;
- d:
- foreach(struct f_data_c, ff, lff, f->subframes) if (ff->loc && ff->loc->name && !casestrcmp(ff->loc->name, target)) return ff;
+ if (f->loc && f->loc->name && !casestrcmp(f->loc->name, target))
+ return f;
+d:
+ foreach (struct f_data_c, ff, lff, f->subframes)
+ if (ff->loc && ff->loc->name
+ && !casestrcmp(ff->loc->name, target))
+ return ff;
if (!list_empty(f->subframes)) {
f = list_struct(f->subframes.next, struct f_data_c);
goto d;
}
- u:
- if (!f->parent) return NULL;
+u:
+ if (!f->parent)
+ return NULL;
if (f->list_entry.next == &f->parent->subframes) {
f = f->parent;
goto u;
@@ -2023,10 +2475,12 @@ struct f_data_c *find_frame(struct session *ses, unsigned char *target, struct f
goto d;
}
-static void destroy_location(struct location *loc)
+static void
+destroy_location(struct location *loc)
{
while (!list_empty(loc->subframes))
- destroy_location(list_struct(loc->subframes.next, struct location));
+ destroy_location(
+ list_struct(loc->subframes.next, struct location));
del_from_list(loc);
free(loc->name);
free(loc->url);
@@ -2035,13 +2489,16 @@ static void destroy_location(struct location *loc)
free(loc);
}
-static void clear_forward_history(struct session *ses)
+static void
+clear_forward_history(struct session *ses)
{
while (!list_empty(ses->forward_history))
- destroy_location(list_struct(ses->forward_history.next, struct location));
+ destroy_location(
+ list_struct(ses->forward_history.next, struct location));
}
-static void ses_go_forward(struct session *ses, int plain, int refresh)
+static void
+ses_go_forward(struct session *ses, int plain, int refresh)
{
struct location *cl;
struct f_data_c *fd;
@@ -2049,17 +2506,26 @@ static void ses_go_forward(struct session *ses, int plain, int refresh)
free(ses->search_word);
ses->search_word = NULL;
free(ses->default_status);
- ses->default_status = NULL; /* smazeme default status, aby neopruzoval na jinych strankach */
- if ((fd = find_frame(ses, ses->wtd_target, ses->wtd_target_base))&&fd!=ses->screen) {
+ ses->default_status = NULL; /* smazeme default status, aby neopruzoval
+ na jinych strankach */
+ if ((fd = find_frame(ses, ses->wtd_target, ses->wtd_target_base))
+ && fd != ses->screen) {
cl = NULL;
- if (refresh && fd->loc && !strcmp(cast_const_char fd->loc->url, cast_const_char ses->rq->url)) cl = cur_loc(ses);
+ if (refresh && fd->loc
+ && !strcmp(cast_const_char fd->loc->url,
+ cast_const_char ses->rq->url))
+ cl = cur_loc(ses);
fd = copy_location_and_replace_frame(ses, fd);
- if (cl) destroy_location(cl);
- } else fd = new_main_location(ses);
+ if (cl)
+ destroy_location(cl);
+ } else
+ fd = new_main_location(ses);
fd->vs->plain = plain;
ses->wtd = NULL;
- fd->rq = ses->rq; ses->rq = NULL;
- fd->goto_position = ses->goto_position; ses->goto_position = NULL;
+ fd->rq = ses->rq;
+ ses->rq = NULL;
+ fd->goto_position = ses->goto_position;
+ ses->goto_position = NULL;
fd->loc->url = stracpy(fd->rq->url);
fd->loc->prev_url = stracpy(fd->rq->prev_url);
fd->rq->upcall = fd_loaded;
@@ -2069,7 +2535,8 @@ static void ses_go_forward(struct session *ses, int plain, int refresh)
draw_formatted(ses);
}
-static void ses_go_backward(struct session *ses)
+static void
+ses_go_backward(struct session *ses)
{
int n;
struct location *loc;
@@ -2077,17 +2544,20 @@ static void ses_go_backward(struct session *ses)
free(ses->search_word);
ses->search_word = NULL;
free(ses->default_status);
- ses->default_status = NULL; /* smazeme default status, aby neopruzoval na jinych strankach */
+ ses->default_status = NULL; /* smazeme default status, aby neopruzoval
+ na jinych strankach */
reinit_f_data_c(ses->screen);
- if (!ses->wtd_num_steps) internal("ses_go_backward: wtd_num_steps is zero");
+ if (!ses->wtd_num_steps)
+ internal("ses_go_backward: wtd_num_steps is zero");
if (ses->wtd_num_steps > 0) {
n = ses->wtd_num_steps;
- foreach(struct location, loc, lloc, ses->history) {
- if (!n--) goto have_back_loc;
+ foreach (struct location, loc, lloc, ses->history) {
+ if (!n--)
+ goto have_back_loc;
}
internal("ses_go_backward: session history disappeared");
return;
- have_back_loc:
+have_back_loc:
for (n = 0; n < ses->wtd_num_steps; n++) {
loc = cur_loc(ses);
del_from_list(loc);
@@ -2095,14 +2565,17 @@ static void ses_go_backward(struct session *ses)
}
} else {
n = ses->wtd_num_steps;
- foreach(struct location, loc, lloc, ses->forward_history) {
- if (!++n) goto have_fwd_loc;
+ foreach (struct location, loc, lloc, ses->forward_history) {
+ if (!++n)
+ goto have_fwd_loc;
}
- internal("ses_go_backward: session forward history disappeared");
+ internal(
+ "ses_go_backward: session forward history disappeared");
return;
- have_fwd_loc:
+have_fwd_loc:
for (n = 0; n < -ses->wtd_num_steps; n++) {
- loc = list_struct(ses->forward_history.next, struct location);
+ loc = list_struct(ses->forward_history.next,
+ struct location);
del_from_list(loc);
add_to_list(ses->history, loc);
}
@@ -2110,19 +2583,22 @@ static void ses_go_backward(struct session *ses)
ses->screen->loc = cur_loc(ses);
ses->screen->vs = ses->screen->loc->vs;
ses->wtd = NULL;
- ses->screen->rq = ses->rq; ses->rq = NULL;
+ ses->screen->rq = ses->rq;
+ ses->rq = NULL;
ses->screen->rq->upcall = fd_loaded;
ses->screen->rq->data = ses->screen;
ses->screen->rq->upcall(ses->screen->rq, ses->screen);
}
-static void tp_cancel(void *ses_)
+static void
+tp_cancel(void *ses_)
{
struct session *ses = (struct session *)ses_;
release_object(&ses->tq);
}
-static void continue_download(struct session *ses, unsigned char *file, int mode)
+static void
+continue_download(struct session *ses, unsigned char *file, int mode)
{
struct download *down;
int h;
@@ -2132,26 +2608,39 @@ static void continue_download(struct session *ses, unsigned char *file, int mode
off_t last_pos = 0, file_shift = 0;
if (ses->tq_prog) {
- if (ses->tq_prog_flag_direct && ses->tq->state != O_OK && !strchr(cast_const_char url, POST_CHAR) && !check_shell_url(url)) {
+ if (ses->tq_prog_flag_direct && ses->tq->state != O_OK
+ && !strchr(cast_const_char url, POST_CHAR)
+ && !check_shell_url(url)) {
unsigned char *prog = subst_file(ses->tq_prog, url, 0);
- exec_on_terminal(ses->term, prog, cast_uchar "", !!ses->tq_prog_flag_block);
+ exec_on_terminal(ses->term, prog, cast_uchar "",
+ !!ses->tq_prog_flag_block);
free(prog);
tp_cancel(ses);
abort_background_connections();
return;
}
- new_name:
- if (!(file = get_temp_name(url, ses->tq->ce ? ses->tq->ce->head : NULL))) {
+new_name:
+ if (!(file = get_temp_name(url, ses->tq->ce ? ses->tq->ce->head
+ : NULL))) {
tp_cancel(ses);
return;
}
- if ((h = create_download_file(ses, ses->term->cwd, file, CDF_RESTRICT_PERMISSION | CDF_EXCL | CDF_NO_POPUP_ON_EEXIST, 0)) < 0) {
+ if ((h = create_download_file(ses, ses->term->cwd, file,
+ CDF_RESTRICT_PERMISSION | CDF_EXCL
+ | CDF_NO_POPUP_ON_EEXIST,
+ 0))
+ < 0) {
if (h == -2 && ses->tq_prog) {
if (++namecount < DOWNLOAD_NAME_TRIES) {
free(file);
goto new_name;
}
- msg_box(ses->term, NULL, TEXT_(T_DOWNLOAD_ERROR), AL_CENTER, TEXT_(T_COULD_NOT_CREATE_TEMPORARY_FILE), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ msg_box(
+ ses->term, NULL, TEXT_(T_DOWNLOAD_ERROR),
+ AL_CENTER,
+ TEXT_(T_COULD_NOT_CREATE_TEMPORARY_FILE),
+ MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL),
+ msg_box_null, B_ENTER | B_ESC);
}
free(file);
tp_cancel(ses);
@@ -2159,7 +2648,9 @@ static void continue_download(struct session *ses, unsigned char *file, int mode
}
xl_file = stracpy(file);
} else {
- if (create_or_append_download_file(ses, ses->term->cwd, file, mode, &h, &xl_file, &last_pos, &file_shift)) {
+ if (create_or_append_download_file(ses, ses->term->cwd, file,
+ mode, &h, &xl_file,
+ &last_pos, &file_shift)) {
tp_cancel(ses);
return;
}
@@ -2189,22 +2680,25 @@ static void continue_download(struct session *ses, unsigned char *file, int mode
display_download(ses->term, down, ses);
}
-
-static void tp_save(void *ses_)
+static void
+tp_save(void *ses_)
{
struct session *ses = (struct session *)ses_;
free(ses->tq_prog);
ses->tq_prog = NULL;
- query_file(ses, ses->tq->url, ses->tq->ce ? ses->tq->ce->head : NULL, &continue_download, tp_cancel, DOWNLOAD_CONTINUE);
+ query_file(ses, ses->tq->url, ses->tq->ce ? ses->tq->ce->head : NULL,
+ &continue_download, tp_cancel, DOWNLOAD_CONTINUE);
}
-static void tp_open(void *ses_)
+static void
+tp_open(void *ses_)
{
struct session *ses = (struct session *)ses_;
continue_download(ses, cast_uchar "", DOWNLOAD_DEFAULT);
}
-static int ses_abort_1st_state_loading(struct session *ses)
+static int
+ses_abort_1st_state_loading(struct session *ses)
{
int r = !!ses->rq;
release_object(&ses->rq);
@@ -2219,7 +2713,8 @@ static int ses_abort_1st_state_loading(struct session *ses)
return r;
}
-static void tp_display(void *ses_)
+static void
+tp_display(void *ses_)
{
int plain = 1;
struct session *ses = (struct session *)ses_;
@@ -2231,19 +2726,25 @@ static void tp_display(void *ses_)
ses_go_forward(ses, plain, 0);
}
-static int direct_download_possible(struct object_request *rq, struct assoc *a)
+static int
+direct_download_possible(struct object_request *rq, struct assoc *a)
{
unsigned char *proto = get_protocol_name(rq->url);
int ret = 0;
- if (!proto) return 0;
- if (a->accept_http && !casestrcmp(proto, cast_uchar "http")) ret = 1;
- if (a->accept_ftp && !casestrcmp(proto, cast_uchar "ftp")) ret = 1;
+ if (!proto)
+ return 0;
+ if (a->accept_http && !casestrcmp(proto, cast_uchar "http"))
+ ret = 1;
+ if (a->accept_ftp && !casestrcmp(proto, cast_uchar "ftp"))
+ ret = 1;
free(proto);
- if (proxies.only_proxies) ret = 0;
+ if (proxies.only_proxies)
+ ret = 0;
return ret;
}
-static int prog_sel_save(struct dialog_data *dlg, struct dialog_item_data *idata)
+static int
+prog_sel_save(struct dialog_data *dlg, struct dialog_item_data *idata)
{
struct session *ses = (struct session *)dlg->dlg->udata2;
@@ -2253,7 +2754,8 @@ static int prog_sel_save(struct dialog_data *dlg, struct dialog_item_data *idata
return 0;
}
-static int prog_sel_display(struct dialog_data *dlg, struct dialog_item_data *idata)
+static int
+prog_sel_display(struct dialog_data *dlg, struct dialog_item_data *idata)
{
struct session *ses = (struct session *)dlg->dlg->udata2;
@@ -2263,7 +2765,8 @@ static int prog_sel_display(struct dialog_data *dlg, struct dialog_item_data *id
return 0;
}
-static int prog_sel_cancel(struct dialog_data *dlg, struct dialog_item_data *idata)
+static int
+prog_sel_cancel(struct dialog_data *dlg, struct dialog_item_data *idata)
{
struct session *ses = (struct session *)dlg->dlg->udata2;
@@ -2273,21 +2776,25 @@ static int prog_sel_cancel(struct dialog_data *dlg, struct dialog_item_data *ida
return 0;
}
-static int prog_sel_open(struct dialog_data *dlg, struct dialog_item_data *idata)
+static int
+prog_sel_open(struct dialog_data *dlg, struct dialog_item_data *idata)
{
- struct assoc *a = (struct assoc*)idata->item->udata;
+ struct assoc *a = (struct assoc *)idata->item->udata;
struct session *ses = (struct session *)dlg->dlg->udata2;
- if (!a) internal("This should not happen.\n");
+ if (!a)
+ internal("This should not happen.\n");
ses->tq_prog = stracpy(a->prog);
ses->tq_prog_flag_block = a->block;
ses->tq_prog_flag_direct = direct_download_possible(ses->tq, a);
tp_open(ses);
- cancel_dialog(dlg,idata);
+ cancel_dialog(dlg, idata);
return 0;
}
-static void type_query_multiple_programs(struct session *ses, unsigned char *ct, struct assoc *a, int n)
+static void
+type_query_multiple_programs(struct session *ses, unsigned char *ct,
+ struct assoc *a, int n)
{
int i;
struct dialog *d;
@@ -2299,11 +2806,17 @@ static void type_query_multiple_programs(struct session *ses, unsigned char *ct,
text_array[1] = cast_uchar " ";
text_array[2] = ct;
text_array[3] = cast_uchar ".\n";
- text_array[4] = !anonymous ? TEXT_(T_DO_YOU_WANT_TO_OPEN_SAVE_OR_DISPLAY_THIS_FILE) : TEXT_(T_DO_YOU_WANT_TO_OPEN_OR_DISPLAY_THIS_FILE);
+ text_array[4] =
+ !anonymous ? TEXT_(T_DO_YOU_WANT_TO_OPEN_SAVE_OR_DISPLAY_THIS_FILE)
+ : TEXT_(T_DO_YOU_WANT_TO_OPEN_OR_DISPLAY_THIS_FILE);
text_array[5] = NULL;
- if ((unsigned)n > (INT_MAX - sizeof(struct dialog)) / sizeof(struct dialog_item) - 4) overalloc();
- d = mem_calloc(sizeof(struct dialog) + (n + 2 + (!anonymous)) * sizeof(struct dialog_item));
+ if ((unsigned)n
+ > (INT_MAX - sizeof(struct dialog)) / sizeof(struct dialog_item)
+ - 4)
+ overalloc();
+ d = mem_calloc(sizeof(struct dialog)
+ + (n + 2 + (!anonymous)) * sizeof(struct dialog_item));
d->title = TEXT_(T_WHAT_TO_DO);
d->fn = msg_box_fn;
d->udata = text_array;
@@ -2312,7 +2825,8 @@ static void type_query_multiple_programs(struct session *ses, unsigned char *ct,
ml = getml(d, a, ct, text_array, NULL);
for (i = 0; i < n; i++) {
- unsigned char *bla = stracpy(get_text_translation(TEXT_(T_OPEN_WITH),ses->term));
+ unsigned char *bla = stracpy(
+ get_text_translation(TEXT_(T_OPEN_WITH), ses->term));
add_to_strn(&bla, cast_uchar " ");
add_to_strn(&bla, a[i].label);
@@ -2342,14 +2856,14 @@ static void type_query_multiple_programs(struct session *ses, unsigned char *ct,
do_dialog(ses->term, d, ml);
}
-
-
/* deallocates a */
-static void type_query(struct session *ses, unsigned char *ct, struct assoc *a, int n)
+static void
+type_query(struct session *ses, unsigned char *ct, struct assoc *a, int n)
{
unsigned char *m1;
unsigned char *m2;
- if (!ct) ct = stracpy(cast_uchar "unknown");
+ if (!ct)
+ ct = stracpy(cast_uchar "unknown");
free(ses->tq_prog);
ses->tq_prog = NULL;
@@ -2372,27 +2886,67 @@ static void type_query(struct session *ses, unsigned char *ct, struct assoc *a,
}
m1 = stracpy(ct);
if (!a) {
- if (!anonymous) msg_box(ses->term, getml(m1, NULL), TEXT_(T_UNKNOWN_TYPE), AL_CENTER, TEXT_(T_CONTENT_TYPE_IS), cast_uchar " ", m1, cast_uchar ".\n", TEXT_(T_DO_YOU_WANT_TO_SAVE_OR_DISLPAY_THIS_FILE), MSG_BOX_END, (void *)ses, 3, TEXT_(T_SAVE), tp_save, B_ENTER, TEXT_(T_DISPLAY), tp_display, 0, TEXT_(T_CANCEL), tp_cancel, B_ESC);
- else msg_box(ses->term, getml(m1, NULL), TEXT_(T_UNKNOWN_TYPE), AL_CENTER, TEXT_(T_CONTENT_TYPE_IS), cast_uchar " ", m1, cast_uchar ".\n", TEXT_(T_DO_YOU_WANT_TO_SAVE_OR_DISLPAY_THIS_FILE), MSG_BOX_END, (void *)ses, 2, TEXT_(T_DISPLAY), tp_display, B_ENTER, TEXT_(T_CANCEL), tp_cancel, B_ESC);
+ if (!anonymous)
+ msg_box(
+ ses->term, getml(m1, NULL), TEXT_(T_UNKNOWN_TYPE),
+ AL_CENTER, TEXT_(T_CONTENT_TYPE_IS), cast_uchar " ",
+ m1, cast_uchar ".\n",
+ TEXT_(T_DO_YOU_WANT_TO_SAVE_OR_DISLPAY_THIS_FILE),
+ MSG_BOX_END, (void *)ses, 3, TEXT_(T_SAVE), tp_save,
+ B_ENTER, TEXT_(T_DISPLAY), tp_display, 0,
+ TEXT_(T_CANCEL), tp_cancel, B_ESC);
+ else
+ msg_box(
+ ses->term, getml(m1, NULL), TEXT_(T_UNKNOWN_TYPE),
+ AL_CENTER, TEXT_(T_CONTENT_TYPE_IS), cast_uchar " ",
+ m1, cast_uchar ".\n",
+ TEXT_(T_DO_YOU_WANT_TO_SAVE_OR_DISLPAY_THIS_FILE),
+ MSG_BOX_END, (void *)ses, 2, TEXT_(T_DISPLAY),
+ tp_display, B_ENTER, TEXT_(T_CANCEL), tp_cancel,
+ B_ESC);
} else {
m2 = stracpy(a[0].label ? a[0].label : (unsigned char *)"");
- if (!anonymous) msg_box(ses->term, getml(m1, m2, NULL), TEXT_(T_WHAT_TO_DO), AL_CENTER, TEXT_(T_CONTENT_TYPE_IS), cast_uchar " ", m1, cast_uchar ".\n", TEXT_(T_DO_YOU_WANT_TO_OPEN_FILE_WITH), cast_uchar " ", m2, cast_uchar ", ", TEXT_(T_SAVE_IT_OR_DISPLAY_IT), MSG_BOX_END, (void *)ses, 4, TEXT_(T_OPEN), tp_open, B_ENTER, TEXT_(T_SAVE), tp_save, 0, TEXT_(T_DISPLAY), tp_display, 0, TEXT_(T_CANCEL), tp_cancel, B_ESC);
- else msg_box(ses->term, getml(m1, m2, NULL), TEXT_(T_WHAT_TO_DO), AL_CENTER, TEXT_(T_CONTENT_TYPE_IS), cast_uchar " ", m1, cast_uchar ".\n", TEXT_(T_DO_YOU_WANT_TO_OPEN_FILE_WITH), cast_uchar " ", m2, cast_uchar ", ", TEXT_(T_SAVE_IT_OR_DISPLAY_IT), MSG_BOX_END, (void *)ses, 3, TEXT_(T_OPEN), tp_open, B_ENTER, TEXT_(T_DISPLAY), tp_display, 0, TEXT_(T_CANCEL), tp_cancel, B_ESC);
+ if (!anonymous)
+ msg_box(
+ ses->term, getml(m1, m2, NULL), TEXT_(T_WHAT_TO_DO),
+ AL_CENTER, TEXT_(T_CONTENT_TYPE_IS), cast_uchar " ",
+ m1, cast_uchar ".\n",
+ TEXT_(T_DO_YOU_WANT_TO_OPEN_FILE_WITH),
+ cast_uchar " ", m2, cast_uchar ", ",
+ TEXT_(T_SAVE_IT_OR_DISPLAY_IT), MSG_BOX_END,
+ (void *)ses, 4, TEXT_(T_OPEN), tp_open, B_ENTER,
+ TEXT_(T_SAVE), tp_save, 0, TEXT_(T_DISPLAY),
+ tp_display, 0, TEXT_(T_CANCEL), tp_cancel, B_ESC);
+ else
+ msg_box(ses->term, getml(m1, m2, NULL),
+ TEXT_(T_WHAT_TO_DO), AL_CENTER,
+ TEXT_(T_CONTENT_TYPE_IS), cast_uchar " ", m1,
+ cast_uchar ".\n",
+ TEXT_(T_DO_YOU_WANT_TO_OPEN_FILE_WITH),
+ cast_uchar " ", m2, cast_uchar ", ",
+ TEXT_(T_SAVE_IT_OR_DISPLAY_IT), MSG_BOX_END,
+ (void *)ses, 3, TEXT_(T_OPEN), tp_open, B_ENTER,
+ TEXT_(T_DISPLAY), tp_display, 0,
+ TEXT_(T_CANCEL), tp_cancel, B_ESC);
}
if (n)
free(a);
free(ct);
}
-static void ses_go_to_2nd_state(struct session *ses)
+static void
+ses_go_to_2nd_state(struct session *ses)
{
struct assoc *a;
int n;
unsigned char *ct = NULL;
int r = plain_type(ses->rq, &ct);
int force_download = is_forced_download(ses->rq);
- if (!force_download && (r == 0 || r == 1 || r == 2)) goto go;
- if (!(a = get_type_assoc(ses->term, ct, &n)) && strlen(cast_const_char ct) >= 4 && !casecmp(ct, cast_uchar "text", 4) && !force_download) {
+ if (!force_download && (r == 0 || r == 1 || r == 2))
+ goto go;
+ if (!(a = get_type_assoc(ses->term, ct, &n))
+ && strlen(cast_const_char ct) >= 4
+ && !casecmp(ct, cast_uchar "text", 4) && !force_download) {
r = 1;
goto go;
}
@@ -2406,9 +2960,11 @@ static void ses_go_to_2nd_state(struct session *ses)
ses->rq = NULL;
ses_abort_1st_state_loading(ses);
if (!a && ses->tq->ce && ses->tq->ce->head) {
- unsigned char *file = get_filename_from_header(ses->tq->ce->head);
+ unsigned char *file =
+ get_filename_from_header(ses->tq->ce->head);
if (file) {
- unsigned char *new_ct = get_content_type_by_extension(file);
+ unsigned char *new_ct =
+ get_content_type_by_extension(file);
free(file);
if (new_ct) {
a = get_type_assoc(ses->term, new_ct, &n);
@@ -2418,22 +2974,24 @@ static void ses_go_to_2nd_state(struct session *ses)
}
type_query(ses, ct, a, n);
return;
- go:
+go:
ses_go_forward(ses, r, ses->wtd_refresh);
free(ct);
}
-static void ses_go_back_to_2nd_state(struct session *ses)
+static void
+ses_go_back_to_2nd_state(struct session *ses)
{
ses_go_backward(ses);
}
-static void ses_finished_1st_state(struct object_request *rq, void *ses_)
+static void
+ses_finished_1st_state(struct object_request *rq, void *ses_)
{
struct session *ses = (struct session *)ses_;
if (rq->state != O_WAITING) {
if (ses->wtd_refresh && ses->wtd_target_base
- && ses->wtd_target_base->refresh_timer != NULL) {
+ && ses->wtd_target_base->refresh_timer != NULL) {
kill_timer(ses->wtd_target_base->refresh_timer);
ses->wtd_target_base->refresh_timer = NULL;
}
@@ -2459,16 +3017,22 @@ static void ses_finished_1st_state(struct object_request *rq, void *ses_)
}
/* if from_goto_dialog is 1, set prev_url to NULL */
-void goto_url_f(struct session *ses, void (*state2)(struct session *), unsigned char *url, unsigned char *target, struct f_data_c *df, int data, int defer, int from_goto_dialog, int refresh)
+void
+goto_url_f(struct session *ses, void (*state2)(struct session *),
+ unsigned char *url, unsigned char *target, struct f_data_c *df,
+ int data, int defer, int from_goto_dialog, int refresh)
{
unsigned char *u, *pos;
unsigned char *prev_url;
void (*fn)(struct session *, unsigned char *);
int reloadlevel, allow_flags;
- if (!state2) state2 = ses_go_to_2nd_state;
+ if (!state2)
+ state2 = ses_go_to_2nd_state;
if ((fn = get_external_protocol_function(url))) {
if (proxies.only_proxies && url_bypasses_socks(url)) {
- msg_box(ses->term, NULL, TEXT_(T_ERROR), AL_CENTER, TEXT_(T_NO_PROXY), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ msg_box(ses->term, NULL, TEXT_(T_ERROR), AL_CENTER,
+ TEXT_(T_NO_PROXY), MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
return;
}
fn(ses, url);
@@ -2476,12 +3040,22 @@ void goto_url_f(struct session *ses, void (*state2)(struct session *), unsigned
}
ses->reloadlevel = NC_CACHE;
if (!(u = translate_url(url, ses->term->cwd))) {
- struct status stat = { init_list_1st(NULL) NULL, NULL, S_BAD_URL, PRI_CANCEL, 0, NULL, NULL, NULL };
+ struct status stat = { init_list_1st(NULL) NULL,
+ NULL,
+ S_BAD_URL,
+ PRI_CANCEL,
+ 0,
+ NULL,
+ NULL,
+ NULL };
print_error_dialog(ses, &stat, url);
return;
}
pos = extract_position(u);
- if (ses->wtd == state2 && !strcmp(cast_const_char ses->rq->orig_url, cast_const_char u) && !xstrcmp(ses->wtd_target, target) && ses->wtd_target_base == df) {
+ if (ses->wtd == state2
+ && !strcmp(cast_const_char ses->rq->orig_url, cast_const_char u)
+ && !xstrcmp(ses->wtd_target, target)
+ && ses->wtd_target_base == df) {
free(u);
free(ses->goto_position);
ses->goto_position = pos;
@@ -2494,30 +3068,45 @@ void goto_url_f(struct session *ses, void (*state2)(struct session *), unsigned
ses->wtd_refresh = refresh;
free(ses->goto_position);
ses->goto_position = pos;
- if (!from_goto_dialog && df && df->rq) prev_url = df->rq->url;
- else prev_url = NULL; /* previous page is empty - this probably never happens, but for sure */
+ if (!from_goto_dialog && df && df->rq)
+ prev_url = df->rq->url;
+ else
+ prev_url = NULL; /* previous page is empty - this probably never
+ happens, but for sure */
if (refresh && ses->wtd == ses_go_to_2nd_state) {
- struct f_data_c *fr = find_frame(ses, ses->wtd_target, ses->wtd_target_base);
- if (fr && fr->loc) if (!strcmp(cast_const_char fr->loc->url, cast_const_char u)) ses->reloadlevel = NC_RELOAD;
+ struct f_data_c *fr =
+ find_frame(ses, ses->wtd_target, ses->wtd_target_base);
+ if (fr && fr->loc)
+ if (!strcmp(cast_const_char fr->loc->url,
+ cast_const_char u))
+ ses->reloadlevel = NC_RELOAD;
}
reloadlevel = ses->reloadlevel;
if (ses->wtd == ses_go_to_2nd_state && !from_goto_dialog && !refresh) {
struct f_data_c *fd;
fd = find_frame(ses, ses->wtd_target, ses->wtd_target_base);
- if (!fd) fd = ses->screen;
- if (fd && fd->rq && !strcmp(cast_const_char fd->rq->url, cast_const_char u)) reloadlevel = NC_ALWAYS_CACHE;
+ if (!fd)
+ fd = ses->screen;
+ if (fd && fd->rq
+ && !strcmp(cast_const_char fd->rq->url, cast_const_char u))
+ reloadlevel = NC_ALWAYS_CACHE;
}
- if (from_goto_dialog) allow_flags = ALLOW_ALL;
- else if (df && df->rq) allow_flags = get_allow_flags(df->rq->url);
- else allow_flags = 0;
+ if (from_goto_dialog)
+ allow_flags = ALLOW_ALL;
+ else if (df && df->rq)
+ allow_flags = get_allow_flags(df->rq->url);
+ else
+ allow_flags = 0;
- request_object(ses->term, u, prev_url, PRI_MAIN, reloadlevel, allow_flags, ses_finished_1st_state, ses, &ses->rq);
+ request_object(ses->term, u, prev_url, PRI_MAIN, reloadlevel,
+ allow_flags, ses_finished_1st_state, ses, &ses->rq);
free(u);
}
/* this doesn't send referer */
-void goto_url(void *ses_, unsigned char *url)
+void
+goto_url(void *ses_, unsigned char *url)
{
struct session *ses = (struct session *)ses_;
unsigned char *u = convert(term_charset(ses->term), 0, url, NULL);
@@ -2525,35 +3114,47 @@ void goto_url(void *ses_, unsigned char *url)
free(u);
}
-void goto_url_utf8(struct session *ses, unsigned char *url)
+void
+goto_url_utf8(struct session *ses, unsigned char *url)
{
goto_url_f(ses, NULL, url, NULL, NULL, -1, 0, 1, 0);
}
/* this one sends referer */
-void goto_url_not_from_dialog(struct session *ses, unsigned char *url, struct f_data_c *df)
+void
+goto_url_not_from_dialog(struct session *ses, unsigned char *url,
+ struct f_data_c *df)
{
goto_url_f(ses, NULL, url, cast_uchar "_top", df, -1, 0, 0, 0);
}
-static void freeml_void(void *ml_)
+static void
+freeml_void(void *ml_)
{
freeml((struct memory_list *)ml_);
}
-static void ses_imgmap(struct session *ses)
+static void
+ses_imgmap(struct session *ses)
{
unsigned char *start;
size_t len;
struct memory_list *ml;
struct menu_item *menu;
struct f_data_c *fd;
- if (ses->rq->state != O_OK && ses->rq->state != O_INCOMPLETE) return;
- if (!(fd = current_frame(ses)) || !fd->f_data) return;
- if (get_file(ses->rq, &start, &len)) return;
- if (len > INT_MAX) len = INT_MAX;
+ if (ses->rq->state != O_OK && ses->rq->state != O_INCOMPLETE)
+ return;
+ if (!(fd = current_frame(ses)) || !fd->f_data)
+ return;
+ if (get_file(ses->rq, &start, &len))
+ return;
+ if (len > INT_MAX)
+ len = INT_MAX;
d_opt = &fd->f_data->opt;
- if (get_image_map(ses->rq->ce->head, start, start + len, ses->goto_position, &menu, &ml, ses->imgmap_href_base, ses->imgmap_target_base, term_charset(ses->term), ses->ds.assume_cp, ses->ds.hard_assume, 0)) {
+ if (get_image_map(ses->rq->ce->head, start, start + len,
+ ses->goto_position, &menu, &ml, ses->imgmap_href_base,
+ ses->imgmap_target_base, term_charset(ses->term),
+ ses->ds.assume_cp, ses->ds.hard_assume, 0)) {
ses_abort_1st_state_loading(ses);
return;
}
@@ -2562,7 +3163,9 @@ static void ses_imgmap(struct session *ses)
ses_abort_1st_state_loading(ses);
}
-void goto_imgmap(struct session *ses, struct f_data_c *fd, unsigned char *url, unsigned char *href, unsigned char *target)
+void
+goto_imgmap(struct session *ses, struct f_data_c *fd, unsigned char *url,
+ unsigned char *href, unsigned char *target)
{
free(ses->imgmap_href_base);
ses->imgmap_href_base = href;
@@ -2571,7 +3174,8 @@ void goto_imgmap(struct session *ses, struct f_data_c *fd, unsigned char *url, u
goto_url_f(ses, ses_imgmap, url, NULL, fd, -1, 0, 0, 0);
}
-void map_selected(struct terminal *term, void *ld_, void *ses_)
+void
+map_selected(struct terminal *term, void *ld_, void *ses_)
{
struct link_def *ld = (struct link_def *)ld_;
struct session *ses = (struct session *)ses_;
@@ -2581,15 +3185,18 @@ void map_selected(struct terminal *term, void *ld_, void *ses_)
x = 1;
}
if (ld->link)
- goto_url_f(ses, NULL, ld->link, ld->target, current_frame(ses), -1, x, 0, 0);
+ goto_url_f(ses, NULL, ld->link, ld->target, current_frame(ses),
+ -1, x, 0, 0);
}
-void go_back(struct session *ses, int num_steps)
+void
+go_back(struct session *ses, int num_steps)
{
struct location *loc = NULL;
struct list_head *lloc;
int n;
- if (!num_steps) return;
+ if (!num_steps)
+ return;
ses->reloadlevel = NC_CACHE;
if (ses_abort_1st_state_loading(ses)) {
change_screen_status(ses);
@@ -2598,41 +3205,48 @@ void go_back(struct session *ses, int num_steps)
}
n = num_steps;
if (num_steps > 0) {
- foreach(struct location, loc, lloc, ses->history) {
- if (!n--) goto have_loc;
+ foreach (struct location, loc, lloc, ses->history) {
+ if (!n--)
+ goto have_loc;
}
return;
} else {
- foreach(struct location, loc, lloc, ses->forward_history) {
- if (!++n) goto have_loc;
+ foreach (struct location, loc, lloc, ses->forward_history) {
+ if (!++n)
+ goto have_loc;
}
return;
}
- have_loc:
+have_loc:
ses->wtd = ses_go_back_to_2nd_state;
ses->wtd_num_steps = num_steps;
- request_object(ses->term, loc->url, loc->prev_url, PRI_MAIN, NC_ALWAYS_CACHE, ALLOW_ALL, ses_finished_1st_state, ses, &ses->rq);
+ request_object(ses->term, loc->url, loc->prev_url, PRI_MAIN,
+ NC_ALWAYS_CACHE, ALLOW_ALL, ses_finished_1st_state, ses,
+ &ses->rq);
}
-static void reload_frame(struct f_data_c *fd, int no_cache)
+static void
+reload_frame(struct f_data_c *fd, int no_cache)
{
unsigned char *u;
if (!list_empty(fd->subframes)) {
struct f_data_c *fdd = NULL;
struct list_head *lfdd;
- foreach(struct f_data_c, fdd, lfdd, fd->subframes) {
+ foreach (struct f_data_c, fdd, lfdd, fd->subframes) {
reload_frame(fdd, no_cache);
}
return;
}
- if (!fd->rq) return;
+ if (!fd->rq)
+ return;
if (fd->f_data && !f_is_finished(fd->f_data))
return;
u = stracpy(fd->rq->url);
release_object(&fd->rq);
if (fd->f_data)
release_object(&fd->f_data->rq);
- request_object(fd->ses->term, u, NULL, PRI_MAIN, no_cache, ALLOW_ALL, fd_loaded, fd, &fd->rq);
+ request_object(fd->ses->term, u, NULL, PRI_MAIN, no_cache, ALLOW_ALL,
+ fd_loaded, fd, &fd->rq);
if (fd->f_data)
clone_object(fd->rq, &fd->f_data->rq);
fd->last_update = get_time();
@@ -2642,7 +3256,8 @@ static void reload_frame(struct f_data_c *fd, int no_cache)
free(u);
}
-void reload(struct session *ses, int no_cache)
+void
+reload(struct session *ses, int no_cache)
{
if (no_cache == -1)
no_cache = ++ses->reloadlevel;
@@ -2651,7 +3266,8 @@ void reload(struct session *ses, int no_cache)
reload_frame(ses->screen, no_cache);
}
-static void set_doc_view(struct session *ses)
+static void
+set_doc_view(struct session *ses)
{
ses->screen->xp = 0;
ses->screen->yp = 1;
@@ -2662,7 +3278,8 @@ static void set_doc_view(struct session *ses)
ses->screen->yw = ses->term->y - 2;
}
-static struct session *create_session(struct window *win)
+static struct session *
+create_session(struct window *win)
{
static int session_id = 1;
struct terminal *term = win->term;
@@ -2674,7 +3291,8 @@ static struct session *create_session(struct window *win)
ses->win = win;
ses->id = session_id++;
ses->screen = create_f_data_c(ses, NULL);
- ses->screen->xp = 0; ses->screen->xw = term->x;
+ ses->screen->xp = 0;
+ ses->screen->xw = term->x;
ses->screen->yp = 1;
ses->screen->yw = term->y - 2;
memcpy(&ses->ds, &dds, sizeof(struct document_setup));
@@ -2682,7 +3300,10 @@ static struct session *create_session(struct window *win)
add_to_list(sessions, ses);
if (first_use) {
first_use = 0;
- msg_box(term, NULL, TEXT_(T_WELCOME), AL_CENTER, TEXT_(T_WELCOME_TO_LINKS), cast_uchar "\n\n", TEXT_(T_BASIC_HELP), MSG_BOX_END, NULL, 1, TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
+ msg_box(term, NULL, TEXT_(T_WELCOME), AL_CENTER,
+ TEXT_(T_WELCOME_TO_LINKS), cast_uchar "\n\n",
+ TEXT_(T_BASIC_HELP), MSG_BOX_END, NULL, 1, TEXT_(T_OK),
+ msg_box_null, B_ENTER | B_ESC);
}
return ses;
}
@@ -2690,12 +3311,15 @@ static struct session *create_session(struct window *win)
/*vyrobi retezec znaku, ktery se posilaj skrz unix domain socket hlavni instanci
prohlizece
cp=cislo session odkud se ma kopirovat (kdyz se klikne na "open new window")
- url=url kam se ma jit (v pripade kliknuti na "open link in new window" nebo pusteni linksu z prikazove radky s url)
- framename=jmeno ramu, ktery se vytvori
+ url=url kam se ma jit (v pripade kliknuti na "open link in new window" nebo
+ pusteni linksu z prikazove radky s url) framename=jmeno ramu, ktery se
+ vytvori
vraci sekvenci bytu a delku
*/
-void *create_session_info(int cp, unsigned char *url, unsigned char *framename, int *ll)
+void *
+create_session_info(int cp, unsigned char *url, unsigned char *framename,
+ int *ll)
{
size_t sl = strlen(cast_const_char url);
size_t sl1 = framename ? strlen(cast_const_char framename) : 0;
@@ -2721,7 +3345,8 @@ void *create_session_info(int cp, unsigned char *url, unsigned char *framename,
vraci -1 pokud jsou data vadna
*/
/* FIXME: this is a disaster */
-static int read_session_info(struct session *ses, void *data, size_t len)
+static int
+read_session_info(struct session *ses, void *data, size_t len)
{
int cpfrom, sz, sz1;
struct session *s = NULL;
@@ -2730,36 +3355,41 @@ static int read_session_info(struct session *ses, void *data, size_t len)
return -1;
cpfrom = *(int *)data;
sz = *((int *)data + 1);
- sz1= *((int *)data + 2);
- foreach(struct session, s, ls, sessions) if (s->id == cpfrom) {
- memcpy(&ses->ds, &s->ds, sizeof(struct document_setup));
- if (!sz) {
- if (!list_empty(s->history)) {
- struct location *loc = list_struct(s->history.next, struct location);
- if (loc->url)
- goto_url_utf8(ses, loc->url);
- }
- return 0;
- } else
- break;
- }
+ sz1 = *((int *)data + 2);
+ foreach (struct session, s, ls, sessions)
+ if (s->id == cpfrom) {
+ memcpy(&ses->ds, &s->ds, sizeof(struct document_setup));
+ if (!sz) {
+ if (!list_empty(s->history)) {
+ struct location *loc = list_struct(
+ s->history.next, struct location);
+ if (loc->url)
+ goto_url_utf8(ses, loc->url);
+ }
+ return 0;
+ } else
+ break;
+ }
if (sz1) {
unsigned char *tgt;
if (len < 3 * sizeof(int) + sz + sz1)
goto bla;
- if ((unsigned)sz1 >= INT_MAX) overalloc();
+ if ((unsigned)sz1 >= INT_MAX)
+ overalloc();
tgt = xmalloc(sz1 + 1);
- memcpy(tgt, (unsigned char*)((int*)data+3)+sz,sz1);
+ memcpy(tgt, (unsigned char *)((int *)data + 3) + sz, sz1);
tgt[sz1] = 0;
free(ses->wanted_framename);
- ses->wanted_framename=NULL;
- ses->wanted_framename=tgt;
+ ses->wanted_framename = NULL;
+ ses->wanted_framename = tgt;
}
- bla:
+bla:
if (sz) {
unsigned char *u, *uu;
- if (len < 3 * sizeof(int) + sz) return -1;
- if ((unsigned)sz >= INT_MAX) overalloc();
+ if (len < 3 * sizeof(int) + sz)
+ return -1;
+ if ((unsigned)sz >= INT_MAX)
+ overalloc();
u = xmalloc(sz + 1);
memcpy(u, (int *)data + 3, sz);
u[sz] = 0;
@@ -2771,24 +3401,28 @@ static int read_session_info(struct session *ses, void *data, size_t len)
return 0;
}
-void cleanup_session(struct session *ses)
+void
+cleanup_session(struct session *ses)
{
struct download *d = NULL;
struct list_head *ld;
- foreach(struct download, d, ld, downloads) if (d->ses == ses && d->prog) {
- ld = ld->prev;
- abort_download(d);
- }
+ foreach (struct download, d, ld, downloads)
+ if (d->ses == ses && d->prog) {
+ ld = ld->prev;
+ abort_download(d);
+ }
ses_abort_1st_state_loading(ses);
reinit_f_data_c(ses->screen);
ses->screen->vs = NULL;
while (!list_empty(ses->format_cache)) {
- struct f_data *f = list_struct(ses->format_cache.next, struct f_data);
+ struct f_data *f =
+ list_struct(ses->format_cache.next, struct f_data);
del_from_list(f);
destroy_formatted(f);
}
while (!list_empty(ses->history))
- destroy_location(list_struct(ses->history.next, struct location));
+ destroy_location(
+ list_struct(ses->history.next, struct location));
clear_forward_history(ses);
free(ses->default_status);
free(ses->search_word);
@@ -2796,7 +3430,8 @@ void cleanup_session(struct session *ses)
ses->search_word = NULL;
}
-void destroy_session(struct session *ses)
+void
+destroy_session(struct session *ses)
{
cleanup_session(ses);
free(ses->screen);
@@ -2816,7 +3451,8 @@ void destroy_session(struct session *ses)
del_from_list(ses);
}
-static void move_session_to_front(struct session *ses)
+static void
+move_session_to_front(struct session *ses)
{
if (sessions.next == &ses->list_entry)
return;
@@ -2824,7 +3460,8 @@ static void move_session_to_front(struct session *ses)
add_to_list(sessions, ses);
}
-void win_func(struct window *win, struct links_event *ev, int fw)
+void
+win_func(struct window *win, struct links_event *ev, int fw)
{
struct session *ses = win->data;
switch ((int)ev->ev) {
@@ -2834,7 +3471,8 @@ void win_func(struct window *win, struct links_event *ev, int fw)
break;
case EV_INIT:
ses = win->data = create_session(win);
- if (read_session_info(ses, (char *)(ev->b + sizeof(int)), ev->b)) {
+ if (read_session_info(ses, (char *)(ev->b + sizeof(int)),
+ ev->b)) {
register_bottom_half(destroy_terminal, win->term);
return;
}
@@ -2855,9 +3493,8 @@ void win_func(struct window *win, struct links_event *ev, int fw)
case EV_MOUSE:
/*FALLTHROUGH*/
case EV_KBD:
- if (ev->ev == EV_KBD
- || (ev->b & BM_ACT) != B_MOVE
- || BM_IS_WHEEL(ev->b))
+ if (ev->ev == EV_KBD || (ev->b & BM_ACT) != B_MOVE
+ || BM_IS_WHEEL(ev->b))
move_session_to_front(ses);
send_event(ses, ev);
break;
@@ -2874,7 +3511,8 @@ void win_func(struct window *win, struct links_event *ev, int fw)
Gets the url being viewed by this session. Writes it into str.
A maximum of str_size bytes (including null) will be written.
*/
-unsigned char *get_current_url(struct session *ses, unsigned char *str, size_t str_size)
+unsigned char *
+get_current_url(struct session *ses, unsigned char *str, size_t str_size)
{
unsigned char *here;
size_t url_len = 0;
@@ -2897,12 +3535,12 @@ unsigned char *get_current_url(struct session *ses, unsigned char *str, size_t s
return str;
}
-
/*
Gets the title of the page being viewed by this session. Writes it into str.
A maximum of str_size bytes (including null) will be written.
*/
-unsigned char *get_current_title(struct f_data_c *fd, unsigned char *str, size_t str_size)
+unsigned char *
+get_current_title(struct f_data_c *fd, unsigned char *str, size_t str_size)
{
/* Ensure that the title is defined */
if (!fd || !fd->f_data)
diff --git a/setup.h b/setup.h
@@ -3,107 +3,108 @@
* This file is a part of the Links program, released under GPL.
*/
-#define FG_POLL_TIME 500
+#define FG_POLL_TIME 500
-#define DNS_TIMEOUT 3600000UL
-#define SESSION_TIMEOUT 14400000UL
+#define DNS_TIMEOUT 3600000UL
+#define SESSION_TIMEOUT 14400000UL
-#define HTTP_KEEPALIVE_TIMEOUT 300000
-#define MAX_KEEPALIVE_CONNECTIONS 30
-#define KEEPALIVE_CHECK_TIME 20000
+#define HTTP_KEEPALIVE_TIMEOUT 300000
+#define MAX_KEEPALIVE_CONNECTIONS 30
+#define KEEPALIVE_CHECK_TIME 20000
-#define MAX_REDIRECTS 15
-#define MAX_CACHED_REDIRECTS 10
+#define MAX_REDIRECTS 15
+#define MAX_CACHED_REDIRECTS 10
-#define DOWNLOAD_NAME_TRIES 10000
+#define DOWNLOAD_NAME_TRIES 10000
-#define MEMORY_CACHE_GC_PERCENT 9/10
-#define MAX_CACHED_OBJECT 1/4
+#define MEMORY_CACHE_GC_PERCENT 9 / 10
+#define MAX_CACHED_OBJECT 1 / 4
-#define MAX_HISTORY_ITEMS 4096
-#define MENU_HOTKEY_SPACE 2
+#define MAX_HISTORY_ITEMS 4096
+#define MENU_HOTKEY_SPACE 2
-#define COL(x) (x)
+#define COL(x) (x)
-#define COLOR_MENU_TEXT (term ? COL(070) : COL(007))
-#define COLOR_MENU_FRAME (term ? COL(070) : COL(007))
-#define COLOR_MENU_SELECTED COL(007)
-#define COLOR_MENU_HOTKEY (term ? COL(007) : COL(0107))
+#define COLOR_MENU_TEXT (term ? COL(070) : COL(007))
+#define COLOR_MENU_FRAME (term ? COL(070) : COL(007))
+#define COLOR_MENU_SELECTED COL(007)
+#define COLOR_MENU_HOTKEY (term ? COL(007) : COL(0107))
-#define COLOR_MAINMENU (term ? COL(070) : COL(007))
-#define COLOR_MAINMENU_SELECTED COL(007)
-#define COLOR_MAINMENU_HOTKEY (term ? COL(070) : COL(0107))
+#define COLOR_MAINMENU (term ? COL(070) : COL(007))
+#define COLOR_MAINMENU_SELECTED COL(007)
+#define COLOR_MAINMENU_HOTKEY (term ? COL(070) : COL(0107))
-#define COLOR_DIALOG (term ? COL(070) : COL(007))
-#define COLOR_DIALOG_FRAME (term ? COL(070) : COL(007))
-#define COLOR_DIALOG_TITLE (term ? COL(007) : COL(007))
-#define COLOR_DIALOG_TEXT (term ? COL(070) : COL(007))
-#define COLOR_DIALOG_CHECKBOX (term ? COL(070) : COL(0107))
-#define COLOR_DIALOG_CHECKBOX_TEXT (term ? COL(070) : COL(007))
-#define COLOR_DIALOG_BUTTON (term ? COL(070) : COL(0107))
-#define COLOR_DIALOG_BUTTON_SELECTED COL(0107)
-#define COLOR_DIALOG_FIELD (term ? COL(007) : COL(0107))
-#define COLOR_DIALOG_FIELD_TEXT (term ? COL(007) : COL(0107))
-#define COLOR_DIALOG_METER (term ? COL(007) : COL(0177))
-#define CHAR_DIALOG_METER (term ? 0 : '*')
+#define COLOR_DIALOG (term ? COL(070) : COL(007))
+#define COLOR_DIALOG_FRAME (term ? COL(070) : COL(007))
+#define COLOR_DIALOG_TITLE (term ? COL(007) : COL(007))
+#define COLOR_DIALOG_TEXT (term ? COL(070) : COL(007))
+#define COLOR_DIALOG_CHECKBOX (term ? COL(070) : COL(0107))
+#define COLOR_DIALOG_CHECKBOX_TEXT (term ? COL(070) : COL(007))
+#define COLOR_DIALOG_BUTTON (term ? COL(070) : COL(0107))
+#define COLOR_DIALOG_BUTTON_SELECTED COL(0107)
+#define COLOR_DIALOG_FIELD (term ? COL(007) : COL(0107))
+#define COLOR_DIALOG_FIELD_TEXT (term ? COL(007) : COL(0107))
+#define COLOR_DIALOG_METER (term ? COL(007) : COL(0177))
+#define CHAR_DIALOG_METER (term ? 0 : '*')
-#define SCROLL_ITEMS 2
+#define SCROLL_ITEMS 2
-#define DIALOG_LEFT_BORDER 3
-#define DIALOG_TOP_BORDER 1
-#define DIALOG_LEFT_INNER_BORDER 2
-#define DIALOG_TOP_INNER_BORDER 0
-#define DIALOG_FRAME 2
+#define DIALOG_LEFT_BORDER 3
+#define DIALOG_TOP_BORDER 1
+#define DIALOG_LEFT_INNER_BORDER 2
+#define DIALOG_TOP_INNER_BORDER 0
+#define DIALOG_FRAME 2
-#define COLOR_TITLE COL(007)
-#define COLOR_STATUS COL(070)
+#define COLOR_TITLE COL(007)
+#define COLOR_STATUS COL(070)
-#define MENU_SUBMENU (cast_uchar ">")
-#define CERT_RIGHT_ARROW (cast_uchar " -> ")
+#define MENU_SUBMENU (cast_uchar ">")
+#define CERT_RIGHT_ARROW (cast_uchar " -> ")
-#define G_SCROLL_BAR_WIDTH 12
-#define G_SCROLL_BAR_MIN_SIZE 20
+#define G_SCROLL_BAR_WIDTH 12
+#define G_SCROLL_BAR_MIN_SIZE 20
-#define G_HTML_MARGIN 8
+#define G_HTML_MARGIN 8
-#define MAX_FONT_SIZE 500
+#define MAX_FONT_SIZE 500
-#define ESC_TIMEOUT 200
+#define ESC_TIMEOUT 200
-#define DISPLAY_TIME_MIN 200
-#define DISPLAY_TIME_MAX_FIRST 1000
-#define DISPLAY_TIME 15
-#define IMG_DISPLAY_TIME 7
-#define DISPLAY_FORMATTING_STATUS 500
+#define DISPLAY_TIME_MIN 200
+#define DISPLAY_TIME_MAX_FIRST 1000
+#define DISPLAY_TIME 15
+#define IMG_DISPLAY_TIME 7
+#define DISPLAY_FORMATTING_STATUS 500
-#define STAT_UPDATE_MIN 100
-#define STAT_UPDATE_MAX 1000
+#define STAT_UPDATE_MIN 100
+#define STAT_UPDATE_MAX 1000
-#define HTML_LEFT_MARGIN 3
-#define HTML_MAX_TABLE_LEVEL 10
-#define HTML_MAX_FRAME_DEPTH 7
-#define HTML_CHAR_WIDTH 7
-#define HTML_CHAR_HEIGHT 12
-#define HTML_FRAME_CHAR_WIDTH 10
-#define HTML_FRAME_CHAR_HEIGHT 16
+#define HTML_LEFT_MARGIN 3
+#define HTML_MAX_TABLE_LEVEL 10
+#define HTML_MAX_FRAME_DEPTH 7
+#define HTML_CHAR_WIDTH 7
+#define HTML_CHAR_HEIGHT 12
+#define HTML_FRAME_CHAR_WIDTH 10
+#define HTML_FRAME_CHAR_HEIGHT 16
#define HTML_TABLE_2ND_PASS
-#define HTML_DEFAULT_INPUT_SIZE 20
-#define HTML_MINIMAL_TEXTAREA_WIDTH 6
-#define HTML_DEFAULT_TEXTAREA_WIDTH 40
-#define HTML_DEFAULT_TEXTAREA_HEIGHT 7
+#define HTML_DEFAULT_INPUT_SIZE 20
+#define HTML_MINIMAL_TEXTAREA_WIDTH 6
+#define HTML_DEFAULT_TEXTAREA_WIDTH 40
+#define HTML_DEFAULT_TEXTAREA_HEIGHT 7
-#define MAX_INPUT_URL_LEN 65536
+#define MAX_INPUT_URL_LEN 65536
-#define SPD_DISP_TIME 200
-#define CURRENT_SPD_SEC (10000 / SPD_DISP_TIME)
-#define CURRENT_SPD_AFTER (20000 / SPD_DISP_TIME)
+#define SPD_DISP_TIME 200
+#define CURRENT_SPD_SEC (10000 / SPD_DISP_TIME)
+#define CURRENT_SPD_AFTER (20000 / SPD_DISP_TIME)
-#define RESOURCE_INFO_REFRESH 100
+#define RESOURCE_INFO_REFRESH 100
-#define DOWN_DLG_MIN 20
+#define DOWN_DLG_MIN 20
/* width and height of BFU element in list window in graphical mode
* (draw_bfu_element function in listedit.c)
- * BFU_ELEMENT_WIDTH is a size of one bfu element (doesn't depend on graphical/text mode)
+ * BFU_ELEMENT_WIDTH is a size of one bfu element (doesn't depend on
+ * graphical/text mode)
*/
-#define BFU_ELEMENT_WIDTH 5
+#define BFU_ELEMENT_WIDTH 5
diff --git a/string.c b/string.c
@@ -7,10 +7,12 @@
#include "links.h"
-int snprint(unsigned char *s, int n, int num)
+int
+snprint(unsigned char *s, int n, int num)
{
int q = 1;
- while (q <= num / 10) q *= 10;
+ while (q <= num / 10)
+ q *= 10;
while (n-- > 1 && q) {
*(s++) = (unsigned char)(num / q + '0');
num %= q;
@@ -20,7 +22,8 @@ int snprint(unsigned char *s, int n, int num)
return !!q;
}
-int snzprint(unsigned char *s, int n, off_t num)
+int
+snzprint(unsigned char *s, int n, off_t num)
{
off_t q = 1;
if (n > 1 && num < 0) {
@@ -28,7 +31,8 @@ int snzprint(unsigned char *s, int n, off_t num)
num = -num;
n--;
}
- while (q <= num / 10) q *= 10;
+ while (q <= num / 10)
+ q *= 10;
while (n-- > 1 && q) {
*(s++) = (unsigned char)(num / q + '0');
num %= q;
@@ -38,10 +42,11 @@ int snzprint(unsigned char *s, int n, off_t num)
return !!q;
}
-void add_to_strn(unsigned char **s, unsigned char *a)
+void
+add_to_strn(unsigned char **s, unsigned char *a)
{
unsigned char *p;
- size_t l1 = strlen(cast_const_char *s), l2 = strlen(cast_const_char a);
+ size_t l1 = strlen(cast_const_char * s), l2 = strlen(cast_const_char a);
if (((l1 | l2) | (l1 + l2 + 1)) > INT_MAX)
overalloc();
p = xrealloc(*s, l1 + l2 + 1);
@@ -49,15 +54,17 @@ void add_to_strn(unsigned char **s, unsigned char *a)
*s = p;
}
-void extend_str(unsigned char **s, int n)
+void
+extend_str(unsigned char **s, int n)
{
- size_t l = strlen(cast_const_char *s);
+ size_t l = strlen(cast_const_char * s);
if (((l | n) | (l + n + 1)) > INT_MAX)
overalloc();
*s = xrealloc(*s, l + n + 1);
}
-void add_bytes_to_str(unsigned char **s, int *l, unsigned char *a, size_t ll)
+void
+add_bytes_to_str(unsigned char **s, int *l, unsigned char *a, size_t ll)
{
unsigned char *p;
size_t old_length;
@@ -69,7 +76,8 @@ void add_bytes_to_str(unsigned char **s, int *l, unsigned char *a, size_t ll)
p = *s;
old_length = (unsigned)*l;
- if (ll + old_length >= (unsigned)INT_MAX / 2 || ll + old_length < ll) overalloc();
+ if (ll + old_length >= (unsigned)INT_MAX / 2 || ll + old_length < ll)
+ overalloc();
new_length = old_length + ll;
*l = (int)new_length;
x = old_length ^ new_length;
@@ -90,24 +98,28 @@ void add_bytes_to_str(unsigned char **s, int *l, unsigned char *a, size_t ll)
memcpy(p + old_length, a, ll);
}
-void add_to_str(unsigned char **s, int *l, unsigned char *a)
+void
+add_to_str(unsigned char **s, int *l, unsigned char *a)
{
add_bytes_to_str(s, l, a, strlen(cast_const_char a));
}
-void add_chr_to_str(unsigned char **s, int *l, unsigned char a)
+void
+add_chr_to_str(unsigned char **s, int *l, unsigned char a)
{
add_bytes_to_str(s, l, &a, 1);
}
-void add_unsigned_long_num_to_str(unsigned char **s, int *l, unsigned long n)
+void
+add_unsigned_long_num_to_str(unsigned char **s, int *l, unsigned long n)
{
unsigned char a[64];
snprint(a, 64, n);
add_to_str(s, l, a);
}
-void add_num_to_str(unsigned char **s, int *l, off_t n)
+void
+add_num_to_str(unsigned char **s, int *l, off_t n)
{
unsigned char a[64];
if (n >= 0 && n < 1000) {
@@ -119,7 +131,7 @@ void add_num_to_str(unsigned char **s, int *l, off_t n)
goto d10;
}
if (sn >= 10) {
- d10:
+d10:
*p++ = '0' + sn / 10;
sn %= 10;
}
@@ -131,7 +143,8 @@ void add_num_to_str(unsigned char **s, int *l, off_t n)
}
}
-void add_knum_to_str(unsigned char **s, int *l, off_t n)
+void
+add_knum_to_str(unsigned char **s, int *l, off_t n)
{
unsigned char a[13];
if (n && n / (1024 * 1024) * (1024 * 1024) == n) {
@@ -147,37 +160,46 @@ void add_knum_to_str(unsigned char **s, int *l, off_t n)
add_to_str(s, l, a);
}
-long strtolx(unsigned char *c, unsigned char **end)
+long
+strtolx(unsigned char *c, unsigned char **end)
{
char *end_c;
long l;
- if (c[0] == '0' && upcase(c[1]) == 'X' && c[2]) l = strtol(cast_const_char(c + 2), &end_c, 16);
- else l = strtol(cast_const_char c, &end_c, 10);
+ if (c[0] == '0' && upcase(c[1]) == 'X' && c[2])
+ l = strtol(cast_const_char(c + 2), &end_c, 16);
+ else
+ l = strtol(cast_const_char c, &end_c, 10);
*end = cast_uchar end_c;
if (upcase(**end) == 'K') {
(*end)++;
- if (l < -INT_MAX / 1024) return -INT_MAX;
- if (l > INT_MAX / 1024) return INT_MAX;
+ if (l < -INT_MAX / 1024)
+ return -INT_MAX;
+ if (l > INT_MAX / 1024)
+ return INT_MAX;
return l * 1024;
}
if (upcase(**end) == 'M') {
(*end)++;
- if (l < -INT_MAX / (1024 * 1024)) return -INT_MAX;
- if (l > INT_MAX / (1024 * 1024)) return INT_MAX;
+ if (l < -INT_MAX / (1024 * 1024))
+ return -INT_MAX;
+ if (l > INT_MAX / (1024 * 1024))
+ return INT_MAX;
return l * (1024 * 1024);
}
return l;
}
/* Copies at most dst_size chars into dst. Ensures null termination of dst. */
-void safe_strncpy(unsigned char *dst, const unsigned char *src, size_t dst_size)
+void
+safe_strncpy(unsigned char *dst, const unsigned char *src, size_t dst_size)
{
dst[dst_size - 1] = 0;
strncpy(cast_char dst, cast_const_char src, dst_size - 1);
}
/* don't use strcasecmp because it depends on locale */
-int casestrcmp(const unsigned char *s1, const unsigned char *s2)
+int
+casestrcmp(const unsigned char *s1, const unsigned char *s2)
{
while (1) {
unsigned char c1 = *s1;
@@ -187,7 +209,8 @@ int casestrcmp(const unsigned char *s1, const unsigned char *s2)
if (c1 != c2) {
return (int)c1 - (int)c2;
}
- if (!*s1) break;
+ if (!*s1)
+ break;
s1++;
s2++;
}
@@ -197,35 +220,36 @@ int casestrcmp(const unsigned char *s1, const unsigned char *s2)
/* case insensitive compare of 2 strings */
/* comparison ends after len (or less) characters */
/* return value: 1=strings differ, 0=strings are same */
-int casecmp(const unsigned char *c1, const unsigned char *c2, size_t len)
+int
+casecmp(const unsigned char *c1, const unsigned char *c2, size_t len)
{
size_t i;
- for (i = 0; i < len; i++) if (srch_cmp(c1[i], c2[i])) return 1;
+ for (i = 0; i < len; i++)
+ if (srch_cmp(c1[i], c2[i]))
+ return 1;
return 0;
}
-int casestrstr(const unsigned char *h, const unsigned char *n)
+int
+casestrstr(const unsigned char *h, const unsigned char *n)
{
const unsigned char *p;
- for (p=h;*p;p++)
- {
- if (!srch_cmp(*p,*n)) /* same */
+ for (p = h; *p; p++) {
+ if (!srch_cmp(*p, *n)) /* same */
{
const unsigned char *q, *r;
- for (q=n, r=p;*r&&*q;)
- {
- if (!srch_cmp(*q,*r)) {
+ for (q = n, r = p; *r && *q;) {
+ if (!srch_cmp(*q, *r)) {
r++;
- q++; /* same */
+ q++; /* same */
} else
break;
}
- if (!*q) return 1;
+ if (!*q)
+ return 1;
}
}
return 0;
}
-
-
diff --git a/suffix.c b/suffix.c
@@ -4,30 +4,35 @@
#include "suffix_x.inc"
-static int search_list(const char *const *list, int len, unsigned char *name)
+static int
+search_list(const char *const *list, int len, unsigned char *name)
{
int result;
-#define T_EQUAL(n, k) !casestrcmp(cast_uchar list[n], k)
-#define T_ABOVE(n, k) casestrcmp(cast_uchar list[n], k) > 0
+#define T_EQUAL(n, k) !casestrcmp(cast_uchar list[n], k)
+#define T_ABOVE(n, k) casestrcmp(cast_uchar list[n], k) > 0
BIN_SEARCH(len, T_EQUAL, T_ABOVE, name, result);
return result != -1;
}
-static int search_list_and_wildcards(const char *const *list, int len, unsigned char *name)
+static int
+search_list_and_wildcards(const char *const *list, int len, unsigned char *name)
{
unsigned char *dot, *x;
int sl;
- if (search_list(list, len, name)) return 1;
+ if (search_list(list, len, name))
+ return 1;
x = stracpy(cast_uchar "*.");
add_to_strn(&x, name);
sl = search_list(list, len, x);
free(x);
- if (sl) return 1;
+ if (sl)
+ return 1;
dot = cast_uchar strchr(cast_const_char name, '.');
- if (!dot) return 0;
+ if (!dot)
+ return 0;
x = stracpy(cast_uchar "*");
add_to_strn(&x, dot);
sl = search_list(list, len, x);
@@ -35,14 +40,15 @@ static int search_list_and_wildcards(const char *const *list, int len, unsigned
return sl;
}
-int is_tld(unsigned char *name)
+int
+is_tld(unsigned char *name)
{
char *end;
unsigned long l;
if (strlen((char *)name) == 2 && upcase(name[0]) >= 'A'
- && upcase(name[0]) <= 'Z' && upcase(name[1]) >= 'A'
- && upcase(name[1]) <= 'Z' && casestrcmp(name, cast_uchar "gz")
- && casestrcmp(name, cast_uchar "xz"))
+ && upcase(name[0]) <= 'Z' && upcase(name[1]) >= 'A'
+ && upcase(name[1]) <= 'Z' && casestrcmp(name, cast_uchar "gz")
+ && casestrcmp(name, cast_uchar "xz"))
return 1;
l = strtoul(cast_const_char name, &end, 10);
if (!*end && l <= 255)
@@ -50,7 +56,8 @@ int is_tld(unsigned char *name)
return search_list(domain_suffix, array_elements(domain_suffix), name);
}
-int allow_cookie_domain(unsigned char *server, unsigned char *domain)
+int
+allow_cookie_domain(unsigned char *server, unsigned char *domain)
{
int sl = strlen((char *)server);
int dl = strlen((char *)domain);
@@ -67,12 +74,12 @@ int allow_cookie_domain(unsigned char *server, unsigned char *domain)
if (server[sl - dl - 1] != '.')
return 0;
if (search_list_and_wildcards(domain_suffix_x,
- array_elements(domain_suffix_x), domain))
+ array_elements(domain_suffix_x), domain))
return 1;
if (!strchr(cast_const_char domain, '.'))
return 0;
if (search_list_and_wildcards(domain_suffix,
- array_elements(domain_suffix), domain))
+ array_elements(domain_suffix), domain))
return 0;
return 1;
}
diff --git a/terminal.c b/terminal.c
@@ -10,7 +10,8 @@
static void in_term(void *);
static void check_if_no_terminal(void);
-int hard_write(int fd, const unsigned char *p, int l)
+int
+hard_write(int fd, const unsigned char *p, int l)
{
int t = 0;
while (l > 0) {
@@ -29,7 +30,8 @@ int hard_write(int fd, const unsigned char *p, int l)
return t;
}
-int hard_read(int fd, unsigned char *p, int l)
+int
+hard_read(int fd, unsigned char *p, int l)
{
int r = 1;
int t = 0;
@@ -44,7 +46,8 @@ int hard_read(int fd, unsigned char *p, int l)
return t;
}
-unsigned char *get_cwd(void)
+unsigned char *
+get_cwd(void)
{
int bufsize = 128;
unsigned char *buf;
@@ -52,30 +55,36 @@ unsigned char *get_cwd(void)
while (1) {
buf = xmalloc(bufsize);
ENULLLOOP(gcr, cast_uchar getcwd(cast_char buf, bufsize));
- if (gcr) return buf;
+ if (gcr)
+ return buf;
free(buf);
- if (errno != ERANGE) break;
- if ((unsigned)bufsize > INT_MAX - 128) overalloc();
+ if (errno != ERANGE)
+ break;
+ if ((unsigned)bufsize > INT_MAX - 128)
+ overalloc();
bufsize += 128;
}
return NULL;
}
-void set_cwd(unsigned char *path)
+void
+set_cwd(unsigned char *path)
{
int rs;
if (path)
EINTRLOOP(rs, chdir(cast_const_char path));
}
-unsigned char get_attribute(int fg, int bg)
+unsigned char
+get_attribute(int fg, int bg)
{
return ((bg & 7) << 3) | (fg & 7) | ((fg & 8) << 3);
}
-struct list_head terminals = {&terminals, &terminals};
+struct list_head terminals = { &terminals, &terminals };
-static void set_margin(struct terminal *term)
+static void
+set_margin(struct terminal *term)
{
term->left_margin = 0;
term->x = term->real_x;
@@ -83,8 +92,8 @@ static void set_margin(struct terminal *term)
term->y = term->real_y;
}
-
-static void alloc_term_screen(struct terminal *term)
+static void
+alloc_term_screen(struct terminal *term)
{
chr *s, *t;
if (term->x < 0)
@@ -92,11 +101,11 @@ static void alloc_term_screen(struct terminal *term)
if (term->y < 0)
term->y = 1;
if ((term->x && term->x * term->y / term->x != term->y)
- || term->x * term->y > INT_MAX / sizeof(*term->screen))
+ || term->x * term->y > INT_MAX / sizeof(*term->screen))
overalloc();
s = xrealloc(term->screen, term->x * term->y * sizeof(*term->screen));
t = xrealloc(term->last_screen,
- term->x * term->y * sizeof(*term->screen));
+ term->x * term->y * sizeof(*term->screen));
memset(t, -1, term->x * term->y * sizeof(*term->screen));
term->last_screen = t;
memset(s, 0, term->x * term->y * sizeof(*term->screen));
@@ -106,13 +115,15 @@ static void alloc_term_screen(struct terminal *term)
term->lcy = -1;
}
-static void clear_terminal(struct terminal *term)
+static void
+clear_terminal(struct terminal *term)
{
fill_area(term, 0, 0, term->x, term->y, ' ', 0);
set_cursor(term, 0, 0, 0, 0);
}
-void redraw_below_window(struct window *win)
+void
+redraw_below_window(struct window *win)
{
int tr;
struct terminal *term = win->term;
@@ -121,10 +132,11 @@ void redraw_below_window(struct window *win)
struct links_event ev = { EV_REDRAW, 0, 0, 0 };
ev.x = term->x;
ev.y = term->y;
- if (term->redrawing >= 2) return;
+ if (term->redrawing >= 2)
+ return;
tr = term->redrawing;
win->term->redrawing = 2;
- foreachback(struct window, w, lw, term->windows) {
+ foreachback (struct window, w, lw, term->windows) {
if (w == win)
break;
w->handler(w, &ev, 0);
@@ -132,37 +144,43 @@ void redraw_below_window(struct window *win)
term->redrawing = tr;
}
-static void redraw_terminal_ev(struct terminal *term, int e)
+static void
+redraw_terminal_ev(struct terminal *term, int e)
{
struct window *win = NULL;
struct list_head *lwin;
- struct links_event ev = {0, 0, 0, 0};
+ struct links_event ev = { 0, 0, 0, 0 };
ev.ev = e;
ev.x = term->x;
ev.y = term->y;
clear_terminal(term);
term->redrawing = 2;
- foreachback(struct window, win, lwin, term->windows) win->handler(win, &ev, 0);
+ foreachback (struct window, win, lwin, term->windows)
+ win->handler(win, &ev, 0);
term->redrawing = 0;
}
-static void redraw_terminal(struct terminal *term)
+static void
+redraw_terminal(struct terminal *term)
{
redraw_terminal_ev(term, EV_REDRAW);
}
-static void redraw_terminal_all(struct terminal *term)
+static void
+redraw_terminal_all(struct terminal *term)
{
redraw_terminal_ev(term, EV_RESIZE);
}
-static void erase_screen(struct terminal *term)
+static void
+erase_screen(struct terminal *term)
{
if (!term->master || !is_blocked())
hard_write(term->fdout, cast_uchar "\033[2J\033[1;1H", 10);
}
-static void redraw_terminal_cls(struct terminal *term)
+static void
+redraw_terminal_cls(struct terminal *term)
{
erase_screen(term);
set_margin(term);
@@ -170,35 +188,42 @@ static void redraw_terminal_cls(struct terminal *term)
redraw_terminal_all(term);
}
-void cls_redraw_all_terminals(void)
+void
+cls_redraw_all_terminals(void)
{
struct terminal *term = NULL;
struct list_head *lterm;
- foreach(struct terminal, term, lterm, terminals) {
+ foreach (struct terminal, term, lterm, terminals) {
redraw_terminal_cls(term);
}
}
-void draw_to_window(struct window *win, void (*fn)(struct terminal *term, void *), void *data)
+void
+draw_to_window(struct window *win, void (*fn)(struct terminal *term, void *),
+ void *data)
{
struct terminal *term = win->term;
struct window *w = NULL;
struct list_head *lw;
struct links_event ev = { EV_REDRAW, 0, 0, 0 };
- pr(fn(term, data)) {};
+ pr(fn(term, data)){};
term = win->term;
if (win->list_entry.prev == &term->windows || term->redrawing)
return;
term->redrawing = 1;
ev.x = term->x;
ev.y = term->y;
- foreachbackfrom(struct window, w, lw, term->windows, win->list_entry.prev)
+ foreachbackfrom (struct window, w, lw, term->windows,
+ win->list_entry.prev)
w->handler(w, &ev, 0);
term->redrawing = 0;
}
-void add_window(struct terminal *term, void (*handler)(struct window *, struct links_event *, int), void *data)
+void
+add_window(struct terminal *term,
+ void (*handler)(struct window *, struct links_event *, int),
+ void *data)
{
struct links_event ev = { EV_INIT, 0, 0, 0 };
struct window *win;
@@ -213,7 +238,8 @@ void add_window(struct terminal *term, void (*handler)(struct window *, struct l
win->handler(win, &ev, 0);
}
-void delete_window(struct window *win)
+void
+delete_window(struct window *win)
{
struct terminal *term = win->term;
struct links_event ev = { EV_ABORT, 0, 0, 0 };
@@ -224,7 +250,8 @@ void delete_window(struct window *win)
free(win);
}
-void delete_window_ev(struct window *win, struct links_event *ev)
+void
+delete_window_ev(struct window *win, struct links_event *ev)
{
struct terminal *term = win->term;
struct list_head *lw = win->list_entry.next;
@@ -235,17 +262,21 @@ void delete_window_ev(struct window *win, struct links_event *ev)
}
}
-void set_window_ptr(struct window *win, int x, int y)
+void
+set_window_ptr(struct window *win, int x, int y)
{
- if (win->xp == x && win->yp == y) return;
+ if (win->xp == x && win->yp == y)
+ return;
win->xp = x;
win->yp = y;
}
-void get_parent_ptr(struct window *win, int *x, int *y)
+void
+get_parent_ptr(struct window *win, int *x, int *y)
{
if (win->list_entry.next != &win->term->windows) {
- struct window *next = list_struct(win->list_entry.next, struct window);
+ struct window *next =
+ list_struct(win->list_entry.next, struct window);
*x = next->xp;
*y = next->yp;
} else {
@@ -259,7 +290,8 @@ struct ewd {
int b;
};
-static void empty_window_handler(struct window *win, struct links_event *ev, int fwd)
+static void
+empty_window_handler(struct window *win, struct links_event *ev, int fwd)
{
struct terminal *term = win->term;
struct list_head *ln;
@@ -290,7 +322,8 @@ static void empty_window_handler(struct window *win, struct links_event *ev, int
}
}
-void add_empty_window(struct terminal *term, void (*fn)(void *), void *data)
+void
+add_empty_window(struct terminal *term, void (*fn)(void *), void *data)
{
struct ewd *ewd;
ewd = xmalloc(sizeof(struct ewd));
@@ -302,41 +335,54 @@ void add_empty_window(struct terminal *term, void (*fn)(void *), void *data)
struct list_head term_specs = { &term_specs, &term_specs };
-void free_term_specs(void)
+void
+free_term_specs(void)
{
free_list(struct term_spec, term_specs);
}
-static struct term_spec dumb_term = { init_list_1st(NULL) "", 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 };
+static struct term_spec dumb_term = {
+ init_list_1st(NULL) "", 0, 1, 0, 0, 0, 0, 0, 0, 0, 0
+};
-static struct term_spec *default_term_spec(unsigned char *term)
+static struct term_spec *
+default_term_spec(unsigned char *term)
{
return &dumb_term;
}
-static struct term_spec *get_term_spec(unsigned char *term)
+static struct term_spec *
+get_term_spec(unsigned char *term)
{
struct term_spec *t = NULL;
struct list_head *lt;
- foreach(struct term_spec, t, lt, term_specs) if (!casestrcmp(t->term, term)) return t;
+ foreach (struct term_spec, t, lt, term_specs)
+ if (!casestrcmp(t->term, term))
+ return t;
return default_term_spec(term);
}
-static void sync_term_specs(void)
+static void
+sync_term_specs(void)
{
struct terminal *term = NULL;
struct list_head *lterm;
- foreach(struct terminal, term, lterm, terminals) term->spec = get_term_spec(term->term);
+ foreach (struct terminal, term, lterm, terminals)
+ term->spec = get_term_spec(term->term);
}
-struct term_spec *new_term_spec(unsigned char *term)
+struct term_spec *
+new_term_spec(unsigned char *term)
{
struct term_spec *t = NULL;
struct list_head *lt;
- foreach(struct term_spec, t, lt, term_specs) if (!casestrcmp(t->term, term)) return t;
+ foreach (struct term_spec, t, lt, term_specs)
+ if (!casestrcmp(t->term, term))
+ return t;
t = xmalloc(sizeof(struct term_spec));
memcpy(t, default_term_spec(term), sizeof(struct term_spec));
- if (strlen(cast_const_char term) < MAX_TERM_LEN) strcpy(cast_char t->term, cast_const_char term);
+ if (strlen(cast_const_char term) < MAX_TERM_LEN)
+ strcpy(cast_char t->term, cast_const_char term);
else {
memcpy(t->term, term, MAX_TERM_LEN - 1);
t->term[MAX_TERM_LEN - 1] = 0;
@@ -346,7 +392,9 @@ struct term_spec *new_term_spec(unsigned char *term)
return t;
}
-struct terminal *init_term(int fdin, int fdout, void (*root_window)(struct window *, struct links_event *, int))
+struct terminal *
+init_term(int fdin, int fdout,
+ void (*root_window)(struct window *, struct links_event *, int))
{
static tcount terminal_count = 0;
struct terminal *term;
@@ -375,20 +423,22 @@ struct terminal *init_term(int fdin, int fdout, void (*root_window)(struct windo
return term;
}
-static int process_utf_8(struct terminal *term, struct links_event *ev)
+static int
+process_utf_8(struct terminal *term, struct links_event *ev)
{
size_t l;
unsigned char *p;
unsigned c;
if (ev->ev == EV_KBD) {
- if (ev->x <= 0 || ev->x >= 0x100) goto direct;
+ if (ev->x <= 0 || ev->x >= 0x100)
+ goto direct;
if ((term->utf8_paste_mode ^ ev->y) & KBD_PASTING) {
term->utf8_paste_mode = ev->y & KBD_PASTING;
term->utf8_buffer[0] = 0;
}
if ((l = strlen(cast_const_char term->utf8_buffer))
- >= sizeof(term->utf8_buffer) - 1
- || ev->x < 0x80 || ev->x >= 0xc0) {
+ >= sizeof(term->utf8_buffer) - 1
+ || ev->x < 0x80 || ev->x >= 0xc0) {
term->utf8_buffer[0] = 0;
l = 0;
}
@@ -396,7 +446,8 @@ static int process_utf_8(struct terminal *term, struct links_event *ev)
term->utf8_buffer[l + 1] = 0;
p = term->utf8_buffer;
GET_UTF_8(p, c);
- if (!c) return 0;
+ if (!c)
+ return 0;
ev->x = c;
direct:
term->utf8_buffer[0] = 0;
@@ -404,7 +455,8 @@ direct:
return 1;
}
-static void in_term(void *term_)
+static void
+in_term(void *term_)
{
struct terminal *term = (struct terminal *)term_;
struct links_event *ev;
@@ -416,31 +468,50 @@ static void in_term(void *term_)
term->input_queue = iq;
EINTRLOOP(r, (int)read(term->fdin, iq + term->qlen, ALLOC_GR));
if (r <= 0) {
- if (r == -1 && errno != ECONNRESET) error("ERROR: error %d on terminal: could not read event", errno);
+ if (r == -1 && errno != ECONNRESET)
+ error(
+ "ERROR: error %d on terminal: could not read event",
+ errno);
destroy_terminal(term);
return;
}
term->qlen += r;
- test_queue:
- if ((size_t)term->qlen < sizeof(struct links_event)) return;
+test_queue:
+ if ((size_t)term->qlen < sizeof(struct links_event))
+ return;
ev = (struct links_event *)iq;
r = sizeof(struct links_event);
- if (ev->ev != EV_INIT && ev->ev != EV_RESIZE && ev->ev != EV_REDRAW && ev->ev != EV_KBD && ev->ev != EV_MOUSE && ev->ev != EV_ABORT) {
+ if (ev->ev != EV_INIT && ev->ev != EV_RESIZE && ev->ev != EV_REDRAW
+ && ev->ev != EV_KBD && ev->ev != EV_MOUSE && ev->ev != EV_ABORT) {
error("ERROR: error on terminal: bad event %d", ev->ev);
goto mm;
}
if (ev->ev == EV_INIT) {
int init_len;
- if ((size_t)term->qlen < sizeof(struct links_event) + MAX_TERM_LEN + MAX_CWD_LEN + 3 * sizeof(int)) return;
- init_len = *(int *)(iq + sizeof(struct links_event) + MAX_TERM_LEN + MAX_CWD_LEN + 2 * sizeof(int));
- if ((size_t)term->qlen < sizeof(struct links_event) + MAX_TERM_LEN + MAX_CWD_LEN + 3 * sizeof(int) + init_len) return;
- memcpy(term->term, iq + sizeof(struct links_event), MAX_TERM_LEN);
+ if ((size_t)term->qlen < sizeof(struct links_event)
+ + MAX_TERM_LEN + MAX_CWD_LEN
+ + 3 * sizeof(int))
+ return;
+ init_len =
+ *(int *)(iq + sizeof(struct links_event) + MAX_TERM_LEN
+ + MAX_CWD_LEN + 2 * sizeof(int));
+ if ((size_t)term->qlen < sizeof(struct links_event)
+ + MAX_TERM_LEN + MAX_CWD_LEN
+ + 3 * sizeof(int) + init_len)
+ return;
+ memcpy(term->term, iq + sizeof(struct links_event),
+ MAX_TERM_LEN);
term->term[MAX_TERM_LEN - 1] = 0;
- memcpy(term->cwd, iq + sizeof(struct links_event) + MAX_TERM_LEN, MAX_CWD_LEN);
+ memcpy(term->cwd,
+ iq + sizeof(struct links_event) + MAX_TERM_LEN,
+ MAX_CWD_LEN);
term->cwd[MAX_CWD_LEN - 1] = 0;
- term->environment = *(int *)(iq + sizeof(struct links_event) + MAX_TERM_LEN + MAX_CWD_LEN);
- ev->b = (long)(iq + sizeof(struct links_event) + MAX_TERM_LEN + MAX_CWD_LEN + 2 * sizeof(int));
- r = (int)sizeof(struct links_event) + MAX_TERM_LEN + MAX_CWD_LEN + 3 * (int)sizeof(int) + init_len;
+ term->environment = *(int *)(iq + sizeof(struct links_event)
+ + MAX_TERM_LEN + MAX_CWD_LEN);
+ ev->b = (long)(iq + sizeof(struct links_event) + MAX_TERM_LEN
+ + MAX_CWD_LEN + 2 * sizeof(int));
+ r = (int)sizeof(struct links_event) + MAX_TERM_LEN + MAX_CWD_LEN
+ + 3 * (int)sizeof(int) + init_len;
sync_term_specs();
}
if (ev->ev == EV_REDRAW || ev->ev == EV_RESIZE || ev->ev == EV_INIT) {
@@ -452,17 +523,18 @@ static void in_term(void *term_)
set_margin(term);
- send_redraw:
+send_redraw:
if (ev->x < 0 || ev->y < 0) {
- error("ERROR: bad terminal size: %d, %d", (int)ev->x, (int)ev->y);
+ error("ERROR: bad terminal size: %d, %d", (int)ev->x,
+ (int)ev->y);
goto mm;
}
alloc_term_screen(term);
clear_terminal(term);
erase_screen(term);
term->redrawing = 1;
- foreachback(struct window, win, lwin, term->windows)
- win->handler(win, ev, 0);
+ foreachback (struct window, win, lwin, term->windows)
+ win->handler(win, ev, 0);
term->redrawing = 0;
}
if (ev->ev == EV_MOUSE) {
@@ -470,7 +542,8 @@ static void in_term(void *term_)
ev->y -= term->top_margin;
}
if (ev->ev == EV_KBD || ev->ev == EV_MOUSE) {
- if (ev->ev == EV_KBD && upcase(ev->x) == 'L' && !(ev->y & KBD_PASTING) && ev->y & KBD_CTRL) {
+ if (ev->ev == EV_KBD && upcase(ev->x) == 'L'
+ && !(ev->y & KBD_PASTING) && ev->y & KBD_CTRL) {
ev->ev = EV_REDRAW;
ev->x = term->x;
ev->y = term->y;
@@ -480,12 +553,15 @@ static void in_term(void *term_)
abort_background_connections();
}
if (!list_empty(term->windows)) {
- if (ev->ev == EV_KBD && ev->x == KBD_CTRL_C && !(ev->y & KBD_PASTING)) {
- struct window *prev = list_struct(term->windows.prev, struct window);
+ if (ev->ev == EV_KBD && ev->x == KBD_CTRL_C
+ && !(ev->y & KBD_PASTING)) {
+ struct window *prev = list_struct(
+ term->windows.prev, struct window);
prev->handler(prev, ev, 0);
} else {
if (process_utf_8(term, ev)) {
- struct window *next = list_struct(term->windows.next, struct window);
+ struct window *next = list_struct(
+ term->windows.next, struct window);
next->handler(next, ev, 0);
}
}
@@ -495,89 +571,107 @@ static void in_term(void *term_)
destroy_terminal(term);
return;
}
- mm:
- if (term->qlen == r) term->qlen = 0;
- else memmove(iq, iq + r, term->qlen -= r);
+mm:
+ if (term->qlen == r)
+ term->qlen = 0;
+ else
+ memmove(iq, iq + r, term->qlen -= r);
goto test_queue;
}
-static inline int getcompcode(int c)
-{
- return (c<<1 | (c&4)>>2) & 7;
-}
-
-unsigned char frame_dumb[49] = " ||||++||++++++--|-+||++--|-+----++++++++ ";
-static unsigned char frame_vt100[49] = "aaaxuuukkuxkjjjkmvwtqnttmlvwtqnvvwwmmllnnjla ";
-
-#define SETPOS(x, y) \
-{ \
- add_to_str(&a, &l, cast_uchar "\033["); \
- add_num_to_str(&a, &l, (y) + 1 + term->top_margin); \
- add_chr_to_str(&a, &l, ';'); \
- add_num_to_str(&a, &l, (x) + 1 + term->left_margin); \
- add_chr_to_str(&a, &l, 'H'); \
- n_chars = 0; \
-}
-
-#define PRINT_CHAR(p) \
-{ \
- char_t c = term->screen[p].ch; \
- unsigned char A = term->screen[p].at & 0x7f; \
- unsigned char frm = !!(term->screen[p].at & ATTR_FRAME); \
- if (s->mode == TERM_VT100) { \
- if (frm != mode) { \
- if (!(mode = frm)) add_to_str(&a, &l, cast_uchar "\017");\
- else add_to_str(&a, &l, cast_uchar "\016"); \
- } \
- if (frm && c >= 176 && c < 224) c = frame_vt100[c - 176];\
- } else if (s->mode == TERM_DUMB && frm && c >= 176 && c < 224) c = frame_dumb[c - 176];\
- if (!(A & 0100) && (A >> 3) == (A & 7)) A = (A & 070) | 7 * !(A & 020);\
- if (A != attrib) { \
- attrib = A; \
- add_to_str(&a, &l, cast_uchar "\033[0"); \
- if (s->col) { \
- unsigned char m[4]; \
- m[0] = ';'; m[1] = '3'; m[3] = 0; \
- m[2] = (attrib & 7) + '0'; \
- add_to_str(&a, &l, m); \
- m[1] = '4'; \
- m[2] = ((attrib >> 3) & 7) + '0'; \
- add_to_str(&a, &l, m); \
- } else if (getcompcode(attrib & 7) < getcompcode(attrib >> 3 & 7))\
- add_to_str(&a, &l, cast_uchar ";7"); \
- if (attrib & 0100) add_to_str(&a, &l, cast_uchar ";1"); \
- add_chr_to_str(&a, &l, 'm'); \
- } \
- if (c >= ' ' && c != 127 && c != 155) { \
- if (c < 128 || frm) { \
- add_chr_to_str(&a, &l, (unsigned char)c); \
- } else { \
- /* \
- * Linux UTF-8 console is broken and doesn't advance cursor\
- * on some characters. So we first print an one-byte \
- * replacement, then set the cursor back, then print \
- * the UTF-8 character and finally set the cursor again.\
- */ \
- unsigned char *r; \
- r = u2cp(c); \
- if (!(r && r[0] >= 32 && r[0] < 127 && !r[1])) r = cast_uchar "*";\
- add_chr_to_str(&a, &l, r[0]); \
- if (cx + 1 < term->x) \
- add_chr_to_str(&a, &l, 8); \
- else \
- SETPOS(cx, y); \
- add_to_str(&a, &l, encode_utf_8(c)); \
- SETPOS(cx + 1, y); \
- print_next = 1; \
- } \
- } \
- else if (!c || c == 1) add_chr_to_str(&a, &l, ' '); \
- else add_chr_to_str(&a, &l, '.'); \
- cx++; \
- n_chars++; \
-}
-
-static void redraw_screen(struct terminal *term)
+static inline int
+getcompcode(int c)
+{
+ return (c << 1 | (c & 4) >> 2) & 7;
+}
+
+unsigned char frame_dumb[49] =
+ " ||||++||++++++--|-+||++--|-+----++++++++ ";
+static unsigned char frame_vt100[49] =
+ "aaaxuuukkuxkjjjkmvwtqnttmlvwtqnvvwwmmllnnjla ";
+
+#define SETPOS(x, y) \
+ { \
+ add_to_str(&a, &l, cast_uchar "\033["); \
+ add_num_to_str(&a, &l, (y) + 1 + term->top_margin); \
+ add_chr_to_str(&a, &l, ';'); \
+ add_num_to_str(&a, &l, (x) + 1 + term->left_margin); \
+ add_chr_to_str(&a, &l, 'H'); \
+ n_chars = 0; \
+ }
+
+#define PRINT_CHAR(p) \
+ { \
+ char_t c = term->screen[p].ch; \
+ unsigned char A = term->screen[p].at & 0x7f; \
+ unsigned char frm = !!(term->screen[p].at & ATTR_FRAME); \
+ if (s->mode == TERM_VT100) { \
+ if (frm != mode) { \
+ if (!(mode = frm)) \
+ add_to_str(&a, &l, cast_uchar "\017"); \
+ else \
+ add_to_str(&a, &l, cast_uchar "\016"); \
+ } \
+ if (frm && c >= 176 && c < 224) \
+ c = frame_vt100[c - 176]; \
+ } else if (s->mode == TERM_DUMB && frm && c >= 176 && c < 224) \
+ c = frame_dumb[c - 176]; \
+ if (!(A & 0100) && (A >> 3) == (A & 7)) \
+ A = (A & 070) | 7 * !(A & 020); \
+ if (A != attrib) { \
+ attrib = A; \
+ add_to_str(&a, &l, cast_uchar "\033[0"); \
+ if (s->col) { \
+ unsigned char m[4]; \
+ m[0] = ';'; \
+ m[1] = '3'; \
+ m[3] = 0; \
+ m[2] = (attrib & 7) + '0'; \
+ add_to_str(&a, &l, m); \
+ m[1] = '4'; \
+ m[2] = ((attrib >> 3) & 7) + '0'; \
+ add_to_str(&a, &l, m); \
+ } else if (getcompcode(attrib & 7) \
+ < getcompcode(attrib >> 3 & 7)) \
+ add_to_str(&a, &l, cast_uchar ";7"); \
+ if (attrib & 0100) \
+ add_to_str(&a, &l, cast_uchar ";1"); \
+ add_chr_to_str(&a, &l, 'm'); \
+ } \
+ if (c >= ' ' && c != 127 && c != 155) { \
+ if (c < 128 || frm) { \
+ add_chr_to_str(&a, &l, (unsigned char)c); \
+ } else { \
+ /* \
+ * Linux UTF-8 console is broken and doesn't \
+ * advance cursor on some characters. So we \
+ * first print an one-byte replacement, then \
+ * set the cursor back, then print the UTF-8 \
+ * character and finally set the cursor again. \
+ */ \
+ unsigned char *r; \
+ r = u2cp(c); \
+ if (!(r && r[0] >= 32 && r[0] < 127 && !r[1])) \
+ r = cast_uchar "*"; \
+ add_chr_to_str(&a, &l, r[0]); \
+ if (cx + 1 < term->x) \
+ add_chr_to_str(&a, &l, 8); \
+ else \
+ SETPOS(cx, y); \
+ add_to_str(&a, &l, encode_utf_8(c)); \
+ SETPOS(cx + 1, y); \
+ print_next = 1; \
+ } \
+ } else if (!c || c == 1) \
+ add_chr_to_str(&a, &l, ' '); \
+ else \
+ add_chr_to_str(&a, &l, '.'); \
+ cx++; \
+ n_chars++; \
+ }
+
+static void
+redraw_screen(struct terminal *term)
{
int x, y, p = 0;
int cx = term->lcx, cy = term->lcy;
@@ -588,40 +682,49 @@ static void redraw_screen(struct terminal *term)
int l = 0;
int print_next = 0;
struct term_spec *s;
- if (!term->dirty || (term->master && is_blocked())) return;
+ if (!term->dirty || (term->master && is_blocked()))
+ return;
a = init_str();
s = term->spec;
for (y = 0; y < term->y; y++) {
- if (!memcmp(&term->screen[p], &term->last_screen[p], sizeof(chr) * term->x)) {
+ if (!memcmp(&term->screen[p], &term->last_screen[p],
+ sizeof(chr) * term->x)) {
p += term->x;
continue;
}
for (x = 0; x < term->x; x++, p++) {
int i;
- if (y == term->y - 1 && x == term->x - 1 && term->left_margin + term->x == term->real_x && term->top_margin + term->y == term->real_y) break;
- if (term->screen[p].ch == term->last_screen[p].ch && term->screen[p].at == term->last_screen[p].at) {
+ if (y == term->y - 1 && x == term->x - 1
+ && term->left_margin + term->x == term->real_x
+ && term->top_margin + term->y == term->real_y)
+ break;
+ if (term->screen[p].ch == term->last_screen[p].ch
+ && term->screen[p].at == term->last_screen[p].at) {
/* make sure that padding is identical */
if (chr_has_padding)
- memcpy(&term->last_screen[p], &term->screen[p], sizeof(chr));
+ memcpy(&term->last_screen[p],
+ &term->screen[p], sizeof(chr));
if (print_next) {
print_next = 0;
goto must_print_next;
}
continue;
}
- memcpy(&term->last_screen[p], &term->screen[p], sizeof(chr));
- must_print_next:
+ memcpy(&term->last_screen[p], &term->screen[p],
+ sizeof(chr));
+must_print_next:
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:
+ppc:
PRINT_CHAR(p - i);
}
} else {
SETPOS(x, y);
- cx = x; cy = y;
- pc:
+ cx = x;
+ cy = y;
+pc:
i = 0;
goto ppc;
}
@@ -633,9 +736,11 @@ static void redraw_screen(struct terminal *term)
}
}
if (l) {
- if (s->col) add_to_str(&a, &l, cast_uchar "\033[37;40m");
+ if (s->col)
+ add_to_str(&a, &l, cast_uchar "\033[37;40m");
add_to_str(&a, &l, cast_uchar "\033[0m");
- if (s->mode == TERM_VT100) add_to_str(&a, &l, cast_uchar "\017");
+ if (s->mode == TERM_VT100)
+ add_to_str(&a, &l, cast_uchar "\017");
}
term->lcx = cx;
term->lcy = cy;
@@ -653,19 +758,23 @@ static void redraw_screen(struct terminal *term)
term->dirty = 0;
}
-void redraw_all_terminals(void)
+void
+redraw_all_terminals(void)
{
struct terminal *term = NULL;
struct list_head *lterm;
- foreach(struct terminal, term, lterm, terminals) redraw_screen(term);
+ foreach (struct terminal, term, lterm, terminals)
+ redraw_screen(term);
}
-void flush_terminal(struct terminal *term)
+void
+flush_terminal(struct terminal *term)
{
redraw_screen(term);
}
-void destroy_terminal(void *term_)
+void
+destroy_terminal(void *term_)
{
struct terminal *term = (struct terminal *)term_;
int rs;
@@ -699,20 +808,24 @@ void destroy_terminal(void *term_)
check_if_no_terminal();
}
-void destroy_all_terminals(void)
+void
+destroy_all_terminals(void)
{
while (!list_empty(terminals)) {
destroy_terminal(list_struct(terminals.next, struct terminal));
}
}
-static void check_if_no_terminal(void)
+static void
+check_if_no_terminal(void)
{
- if (!list_empty(terminals)) return;
+ if (!list_empty(terminals))
+ return;
terminate_loop = 1;
}
-void set_char(struct terminal *t, int x, int y, unsigned ch, unsigned char at)
+void
+set_char(struct terminal *t, int x, int y, unsigned ch, unsigned char at)
{
t->dirty = 1;
if (x >= 0 && x < t->x && y >= 0 && y < t->y) {
@@ -722,12 +835,13 @@ void set_char(struct terminal *t, int x, int y, unsigned ch, unsigned char at)
}
}
-const chr *get_char(struct terminal *t, int x, int y)
+const chr *
+get_char(struct terminal *t, int x, int y)
{
int lx, ly;
lx = t->x - 1;
ly = t->y - 1;
- if((lx | ly) < 0) {
+ if ((lx | ly) < 0) {
static const chr empty = { ' ', 070 };
return ∅
}
@@ -742,13 +856,18 @@ const chr *get_char(struct terminal *t, int x, int y)
return &t->screen[x + t->x * y];
}
-void set_color(struct terminal *t, int x, int y, unsigned char c)
+void
+set_color(struct terminal *t, int x, int y, unsigned char c)
{
t->dirty = 1;
- if (x >= 0 && x < t->x && y >= 0 && y < t->y) t->screen[x + t->x * y].at = (t->screen[x + t->x * y].at & ATTR_FRAME) | (c & ~ATTR_FRAME);
+ if (x >= 0 && x < t->x && y >= 0 && y < t->y)
+ t->screen[x + t->x * y].at =
+ (t->screen[x + t->x * y].at & ATTR_FRAME)
+ | (c & ~ATTR_FRAME);
}
-void set_only_char(struct terminal *t, int x, int y, unsigned ch, unsigned char at)
+void
+set_only_char(struct terminal *t, int x, int y, unsigned ch, unsigned char at)
{
const chr *cc;
t->dirty = 1;
@@ -757,30 +876,39 @@ void set_only_char(struct terminal *t, int x, int y, unsigned ch, unsigned char
set_char(t, x, y, ch, at);
}
-void set_line(struct terminal *t, int x, int y, int l, chr *line)
+void
+set_line(struct terminal *t, int x, int y, int l, chr *line)
{
int i;
chr *cc;
t->dirty = 1;
- if (y < 0 || y >= t->y) return;
+ if (y < 0 || y >= t->y)
+ return;
i = x >= 0 ? 0 : -x;
- cc = &t->screen[x+i + t->x * y];
+ cc = &t->screen[x + i + t->x * y];
line = &line[i];
- i = (x+l <= t->x ? l : t->x-x) - i;
- if (i <= 0) return;
+ i = (x + l <= t->x ? l : t->x - x) - i;
+ if (i <= 0)
+ return;
memcpy(cc, line, i * sizeof(chr));
}
-void set_line_color(struct terminal *t, int x, int y, int l, unsigned char c)
+void
+set_line_color(struct terminal *t, int x, int y, int l, unsigned char c)
{
int i;
t->dirty = 1;
- if (y < 0 || y >= t->y) return;
- for (i = x >= 0 ? 0 : -x; i < (x+l <= t->x ? l : t->x-x); i++)
- t->screen[x+i + t->x * y].at = (t->screen[x+i + t->x * y].at & ATTR_FRAME) | (c & ~ATTR_FRAME);
+ if (y < 0 || y >= t->y)
+ return;
+ for (i = x >= 0 ? 0 : -x; i < (x + l <= t->x ? l : t->x - x); i++)
+ t->screen[x + i + t->x * y].at =
+ (t->screen[x + i + t->x * y].at & ATTR_FRAME)
+ | (c & ~ATTR_FRAME);
}
-void fill_area(struct terminal *t, int x, int y, int xw, int yw, unsigned ch, unsigned char at)
+void
+fill_area(struct terminal *t, int x, int y, int xw, int yw, unsigned ch,
+ unsigned char at)
{
int i;
chr *p, *ps;
@@ -788,14 +916,18 @@ void fill_area(struct terminal *t, int x, int y, int xw, int yw, unsigned ch, un
xw += x;
x = 0;
}
- if (x + xw > t->x) xw = t->x - x;
- if (xw <= 0) return;
+ if (x + xw > t->x)
+ xw = t->x - x;
+ if (xw <= 0)
+ return;
if (y < 0) {
yw += y;
y = 0;
}
- if (y + yw > t->y) yw = t->y - y;
- if (yw <= 0) return;
+ if (y + yw > t->y)
+ yw = t->y - y;
+ if (yw <= 0)
+ return;
t->dirty = 1;
p = ps = &t->screen[x + t->x * y];
for (i = 0; i < xw; i++) {
@@ -813,45 +945,56 @@ void fill_area(struct terminal *t, int x, int y, int xw, int yw, unsigned ch, un
static int p1[] = { 218, 191, 192, 217, 179, 196 };
static int p2[] = { 201, 187, 200, 188, 186, 205 };
-void draw_frame(struct terminal *t, int x, int y, int xw, int yw, unsigned char c, int w)
+void
+draw_frame(struct terminal *t, int x, int y, int xw, int yw, unsigned char c,
+ int w)
{
int *p = w > 1 ? p2 : p1;
c |= ATTR_FRAME;
set_char(t, x, y, p[0], c);
- set_char(t, x+xw-1, y, p[1], c);
- set_char(t, x, y+yw-1, p[2], c);
- set_char(t, x+xw-1, y+yw-1, p[3], c);
- fill_area(t, x, y+1, 1, yw-2, p[4], c);
- fill_area(t, x+xw-1, y+1, 1, yw-2, p[4], c);
- fill_area(t, x+1, y, xw-2, 1, p[5], c);
- fill_area(t, x+1, y+yw-1, xw-2, 1, p[5], c);
+ set_char(t, x + xw - 1, y, p[1], c);
+ set_char(t, x, y + yw - 1, p[2], c);
+ set_char(t, x + xw - 1, y + yw - 1, p[3], c);
+ fill_area(t, x, y + 1, 1, yw - 2, p[4], c);
+ fill_area(t, x + xw - 1, y + 1, 1, yw - 2, p[4], c);
+ fill_area(t, x + 1, y, xw - 2, 1, p[5], c);
+ fill_area(t, x + 1, y + yw - 1, xw - 2, 1, p[5], c);
}
-void print_text(struct terminal *t, int x, int y, int l, unsigned char *text, unsigned char c)
+void
+print_text(struct terminal *t, int x, int y, int l, unsigned char *text,
+ unsigned char c)
{
for (; l--; x++) {
unsigned u = GET_TERM_CHAR(t, &text);
- if (!u) break;
+ if (!u)
+ break;
set_char(t, x, y, u, c);
}
}
-void set_cursor(struct terminal *term, int x, int y, int altx, int alty)
+void
+set_cursor(struct terminal *term, int x, int y, int altx, int alty)
{
term->dirty = 1;
if (term->spec->block_cursor) {
x = altx;
y = alty;
}
- if (x >= term->x) x = term->x - 1;
- if (y >= term->y) y = term->y - 1;
- if (x < 0) x = 0;
- if (y < 0) y = 0;
+ if (x >= term->x)
+ x = term->x - 1;
+ if (y >= term->y)
+ y = term->y - 1;
+ if (x < 0)
+ x = 0;
+ if (y < 0)
+ y = 0;
term->cx = x;
term->cy = y;
}
-static void exec_thread(void *path_, int p)
+static void
+exec_thread(void *path_, int p)
{
char *path = path_;
int rs;
@@ -862,13 +1005,15 @@ static void exec_thread(void *path_, int p)
EINTRLOOP(rs, unlink(path + 1 + strlen(path + 1) + 1));
}
-static void close_handle(void *p)
+static void
+close_handle(void *p)
{
int *h = p;
close_socket(h);
}
-static void unblock_terminal(void *term_)
+static void
+unblock_terminal(void *term_)
{
struct terminal *term = (struct terminal *)term_;
close_handle(&term->blocked);
@@ -880,11 +1025,15 @@ static void unblock_terminal(void *term_)
term->dirty = 0;
}
-void exec_on_terminal(struct terminal *term, unsigned char *path, unsigned char *delet, unsigned char fg)
+void
+exec_on_terminal(struct terminal *term, unsigned char *path,
+ unsigned char *delet, unsigned char fg)
{
int rs;
- if (path && !*path) return;
- if (!path) path = cast_uchar "";
+ if (path && !*path)
+ return;
+ if (!path)
+ path = cast_uchar "";
if (term->master) {
if (!*path) {
dispatch_special(delet);
@@ -894,7 +1043,8 @@ void exec_on_terminal(struct terminal *term, unsigned char *path, unsigned char
int paraml;
if (is_blocked() && fg) {
if (*delet)
- EINTRLOOP(rs, unlink(cast_const_char delet));
+ EINTRLOOP(
+ rs, unlink(cast_const_char delet));
return;
}
param = init_str();
@@ -905,7 +1055,9 @@ void exec_on_terminal(struct terminal *term, unsigned char *path, unsigned char
add_to_str(¶m, ¶ml, delet);
if (fg == 1)
block_itrm(term->fdin);
- if ((blockh = start_thread(exec_thread, param, paraml + 1, *delet != 0)) == -1) {
+ if ((blockh = start_thread(exec_thread, param,
+ paraml + 1, *delet != 0))
+ == -1) {
if (fg == 1)
unblock_itrm(term->fdin);
free(param);
@@ -914,10 +1066,12 @@ void exec_on_terminal(struct terminal *term, unsigned char *path, unsigned char
free(param);
if (fg == 1) {
term->blocked = blockh;
- set_handlers(blockh, unblock_terminal, NULL, term);
+ set_handlers(blockh, unblock_terminal, NULL,
+ term);
set_handlers(term->fdin, NULL, NULL, term);
} else {
- set_handlers(blockh, close_handle, NULL, &blockh);
+ set_handlers(blockh, close_handle, NULL,
+ &blockh);
}
}
} else {
@@ -935,7 +1089,9 @@ void exec_on_terminal(struct terminal *term, unsigned char *path, unsigned char
}
}
-void do_terminal_function(struct terminal *term, unsigned char code, unsigned char *data)
+void
+do_terminal_function(struct terminal *term, unsigned char code,
+ unsigned char *data)
{
unsigned char *x_data;
int x_datal;
@@ -947,26 +1103,35 @@ void do_terminal_function(struct terminal *term, unsigned char code, unsigned ch
free(x_data);
}
-void set_terminal_title(struct terminal *term, unsigned char *title)
+void
+set_terminal_title(struct terminal *term, unsigned char *title)
{
- if (strlen(cast_const_char title) > 10000) title[10000] = 0;
+ if (strlen(cast_const_char title) > 10000)
+ title[10000] = 0;
if (strchr(cast_const_char title, 1)) {
unsigned char *a, *b;
- for (a = title, b = title; *a; a++) if (*a != 1) *b++ = *a;
+ for (a = title, b = title; *a; a++)
+ if (*a != 1)
+ *b++ = *a;
*b = 0;
}
- if (term->title && !strcmp(cast_const_char title, cast_const_char term->title)) goto ret;
+ if (term->title
+ && !strcmp(cast_const_char title, cast_const_char term->title))
+ goto ret;
free(term->title);
term->title = stracpy(title);
do_terminal_function(term, TERM_FN_TITLE, title);
- ret:
+ret:
free(title);
}
-struct terminal *find_terminal(tcount count)
+struct terminal *
+find_terminal(tcount count)
{
struct terminal *term = NULL;
struct list_head *lterm;
- foreach(struct terminal, term, lterm, terminals) if (term->count == count) return term;
+ foreach (struct terminal, term, lterm, terminals)
+ if (term->count == count)
+ return term;
return NULL;
}
diff --git a/types.c b/types.c
@@ -11,28 +11,33 @@
/* DECLARATIONS */
-static void assoc_edit_item(struct dialog_data *, struct list *, void (*)(struct dialog_data *, struct list *, struct list *, struct list_description *), struct list *, unsigned char);
+static void assoc_edit_item(struct dialog_data *, struct list *,
+ void (*)(struct dialog_data *, struct list *,
+ struct list *, struct list_description *),
+ struct list *, unsigned char);
static void assoc_copy_item(struct list *, struct list *);
static struct list *assoc_new_item(void *);
static void assoc_delete_item(struct list *);
-static struct list *assoc_find_item(struct list *start, unsigned char *str, int direction);
+static struct list *assoc_find_item(struct list *start, unsigned char *str,
+ int direction);
static unsigned char *assoc_type_item(struct terminal *, struct list *, int);
-
struct list assoc = { init_list_1st(&assoc.list_entry) 0, -1, NULL };
-static struct history assoc_search_history = { 0, { &assoc_search_history.items, &assoc_search_history.items } };
+static struct history assoc_search_history = {
+ 0, {&assoc_search_history.items, &assoc_search_history.items}
+};
struct assoc_ok_struct {
- void (*fn)(struct dialog_data *, struct list *, struct list *, struct list_description *);
+ void (*fn)(struct dialog_data *, struct list *, struct list *,
+ struct list_description *);
struct list *data;
struct dialog_data *dlg;
};
-
-static struct list_description assoc_ld={
- 0, /* 0= flat; 1=tree */
- &assoc, /* list */
+static struct list_description assoc_ld = {
+ 0, /* 0= flat; 1=tree */
+ &assoc, /* list */
assoc_new_item,
assoc_edit_item,
NULL,
@@ -41,24 +46,28 @@ static struct list_description assoc_ld={
assoc_type_item,
assoc_find_item,
&assoc_search_history,
- 0, /* this is set in init_assoc function */
- 15, /* # of items in main window */
+ 0, /* this is set in init_assoc function */
+ 15, /* # of items in main window */
T_ASSOCIATION,
T_ASSOCIATIONS_ALREADY_IN_USE,
T_ASSOCIATIONS_MANAGER,
T_DELETE_ASSOCIATION,
- 0, /* no button */
- NULL, /* no button */
- NULL, /* no save*/
+ 0, /* no button */
+ NULL, /* no button */
+ NULL, /* no save*/
- NULL,NULL,0,0, /* internal vars */
+ NULL,
+ NULL,
+ 0,
+ 0, /* internal vars */
0, /* modified */
NULL,
NULL,
1,
};
-static struct list *assoc_new_item(void *ignore)
+static struct list *
+assoc_new_item(void *ignore)
{
struct assoc *neww;
@@ -75,7 +84,8 @@ static struct list *assoc_new_item(void *ignore)
return &neww->head;
}
-static void assoc_delete_item(struct list *data)
+static void
+assoc_delete_item(struct list *data)
{
struct assoc *del = get_struct(data, struct assoc, head);
@@ -87,7 +97,8 @@ static void assoc_delete_item(struct list *data)
free(del);
}
-static void assoc_copy_item(struct list *in, struct list *out)
+static void
+assoc_copy_item(struct list *in, struct list *out)
{
struct assoc *item_in = get_struct(in, struct assoc, head);
struct assoc *item_out = get_struct(out, struct assoc, head);
@@ -111,22 +122,27 @@ static void assoc_copy_item(struct list *in, struct list *out)
/* allocate string and print association into it */
/* x: 0=type all, 1=type title only */
-static unsigned char *assoc_type_item(struct terminal *term, struct list *data, int x)
+static unsigned char *
+assoc_type_item(struct terminal *term, struct list *data, int x)
{
unsigned char *txt, *txt1;
struct assoc *item;
- if (data == &assoc) return stracpy(get_text_translation(TEXT_(T_ASSOCIATIONS), term));
+ if (data == &assoc)
+ return stracpy(
+ get_text_translation(TEXT_(T_ASSOCIATIONS), term));
item = get_struct(data, struct assoc, head);
txt = stracpy(cast_uchar "");
- if (item->system != SYSTEM_ID) add_to_strn(&txt, cast_uchar "XX ");
+ if (item->system != SYSTEM_ID)
+ add_to_strn(&txt, cast_uchar "XX ");
add_to_strn(&txt, item->label);
add_to_strn(&txt, cast_uchar ": ");
add_to_strn(&txt, item->ct);
if (!x) {
add_to_strn(&txt, cast_uchar " -> ");
- if (item->prog) add_to_strn(&txt, item->prog);
+ if (item->prog)
+ add_to_strn(&txt, item->prog);
}
txt1 = convert(assoc_ld.codepage, term_charset(term), txt, NULL);
free(txt);
@@ -134,13 +150,14 @@ static unsigned char *assoc_type_item(struct terminal *term, struct list *data,
return txt1;
}
-void menu_assoc_manager(struct terminal *term, void *fcp, void *ses_)
+void
+menu_assoc_manager(struct terminal *term, void *fcp, void *ses_)
{
struct session *ses = (struct session *)ses_;
- create_list_window(&assoc_ld,&assoc, term, ses);
+ create_list_window(&assoc_ld, &assoc, term, ses);
}
-static unsigned char * const ct_msg[] = {
+static unsigned char *const ct_msg[] = {
TEXT_(T_LABEL),
TEXT_(T_CONTENT_TYPES),
TEXT_(T_PROGRAM__IS_REPLACED_WITH_FILE_NAME),
@@ -152,7 +169,8 @@ static unsigned char * const ct_msg[] = {
TEXT_(T_ACCEPT_FTP),
};
-static void assoc_edit_item_fn(struct dialog_data *dlg)
+static void
+assoc_edit_item_fn(struct dialog_data *dlg)
{
struct terminal *term = dlg->win->term;
int max = 0, min = 0;
@@ -172,39 +190,60 @@ static void assoc_edit_item_fn(struct dialog_data *dlg)
max_buttons_width(term, dlg->items + 3 + p, 2, &max);
min_buttons_width(term, dlg->items + 3 + p, 2, &min);
w = term->x * 9 / 10 - 2 * DIALOG_LB;
- if (w > max) w = max;
- if (w < min) w = min;
- if (w > term->x - 2 * DIALOG_LB) w = term->x - 2 * DIALOG_LB;
- if (w < 1) w = 1;
+ if (w > max)
+ w = max;
+ if (w < min)
+ w = min;
+ if (w > term->x - 2 * DIALOG_LB)
+ w = term->x - 2 * DIALOG_LB;
+ if (w < 1)
+ w = 1;
rw = 0;
- dlg_format_text_and_field(dlg, NULL, get_text_translation(ct_msg[0], term), &dlg->items[0], 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(
+ dlg, NULL, get_text_translation(ct_msg[0], term), &dlg->items[0], 0,
+ &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_text_and_field(dlg, NULL, get_text_translation(ct_msg[1], term), &dlg->items[1], 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(
+ dlg, NULL, get_text_translation(ct_msg[1], term), &dlg->items[1], 0,
+ &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_text_and_field(dlg, NULL, get_text_translation(ct_msg[2], term), &dlg->items[2], 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(
+ dlg, NULL, get_text_translation(ct_msg[2], term), &dlg->items[2], 0,
+ &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_group(dlg, NULL, ct_msg + 3, dlg->items + 3, p, 0, &y, w, &rw);
+ dlg_format_group(dlg, NULL, ct_msg + 3, dlg->items + 3, p, 0, &y, w,
+ &rw);
y++;
- dlg_format_buttons(dlg, NULL, dlg->items + 3 + p, 2, 0, &y, w, &rw, AL_CENTER);
+ dlg_format_buttons(dlg, NULL, dlg->items + 3 + p, 2, 0, &y, w, &rw,
+ AL_CENTER);
w = rw;
dlg->xw = w + 2 * DIALOG_LB;
dlg->yw = y + 2 * DIALOG_TB;
center_dlg(dlg);
draw_dlg(dlg);
y = dlg->y + DIALOG_TB;
- dlg_format_text_and_field(dlg, term, ct_msg[0], &dlg->items[0], dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, term, ct_msg[0], &dlg->items[0],
+ dlg->x + DIALOG_LB, &y, w, NULL,
+ COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_text_and_field(dlg, term, ct_msg[1], &dlg->items[1], dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, term, ct_msg[1], &dlg->items[1],
+ dlg->x + DIALOG_LB, &y, w, NULL,
+ COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_text_and_field(dlg, term, ct_msg[2], &dlg->items[2], dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, term, ct_msg[2], &dlg->items[2],
+ dlg->x + DIALOG_LB, &y, w, NULL,
+ COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_group(dlg, term, ct_msg + 3, &dlg->items[3], p, dlg->x + DIALOG_LB, &y, w, NULL);
+ dlg_format_group(dlg, term, ct_msg + 3, &dlg->items[3], p,
+ dlg->x + DIALOG_LB, &y, w, NULL);
y++;
- dlg_format_buttons(dlg, term, &dlg->items[3 + p], 2, dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);
+ dlg_format_buttons(dlg, term, &dlg->items[3 + p], 2, dlg->x + DIALOG_LB,
+ &y, w, NULL, AL_CENTER);
}
/* Puts url and title into the bookmark item */
-static void assoc_edit_done(void *data)
+static void
+assoc_edit_done(void *data)
{
struct dialog *d = (struct dialog *)data;
struct assoc *item = (struct assoc *)d->udata;
@@ -216,24 +255,28 @@ static void assoc_edit_done(void *data)
ct = label + MAX_STR_LEN;
prog = ct + MAX_STR_LEN;
- txt = convert(term_charset(s->dlg->win->term), assoc_ld.codepage, label, NULL);
+ txt = convert(term_charset(s->dlg->win->term), assoc_ld.codepage, label,
+ NULL);
free(item->label);
item->label = txt;
- txt = convert(term_charset(s->dlg->win->term), assoc_ld.codepage, ct, NULL);
+ txt = convert(term_charset(s->dlg->win->term), assoc_ld.codepage, ct,
+ NULL);
free(item->ct);
item->ct = txt;
- txt = convert(term_charset(s->dlg->win->term), assoc_ld.codepage, prog, NULL);
+ txt = convert(term_charset(s->dlg->win->term), assoc_ld.codepage, prog,
+ NULL);
free(item->prog);
item->prog = txt;
s->fn(s->dlg, s->data, &item->head, &assoc_ld);
- d->udata = NULL; /* for abort function */
+ d->udata = NULL; /* for abort function */
}
/* destroys an item, this function is called when edit window is aborted */
-static void assoc_edit_abort(struct dialog_data *data)
+static void
+assoc_edit_abort(struct dialog_data *data)
{
struct dialog *dlg = data->dlg;
struct assoc *item = (struct assoc *)dlg->udata;
@@ -243,7 +286,11 @@ static void assoc_edit_abort(struct dialog_data *data)
assoc_delete_item(&item->head);
}
-static void assoc_edit_item(struct dialog_data *dlg, struct list *data, void (*ok_fn)(struct dialog_data *, struct list *, struct list *, struct list_description *), struct list *ok_arg, unsigned char dlg_title)
+static void
+assoc_edit_item(struct dialog_data *dlg, struct list *data,
+ void (*ok_fn)(struct dialog_data *, struct list *,
+ struct list *, struct list_description *),
+ struct list *ok_arg, unsigned char dlg_title)
{
int p;
struct assoc *neww = get_struct(data, struct assoc, head);
@@ -252,7 +299,8 @@ static void assoc_edit_item(struct dialog_data *dlg, struct list *data, void (*o
struct assoc_ok_struct *s;
unsigned char *ct, *prog, *label;
- d = mem_calloc(sizeof(struct dialog) + 11 * sizeof(struct dialog_item) + 3 * MAX_STR_LEN);
+ d = mem_calloc(sizeof(struct dialog) + 11 * sizeof(struct dialog_item)
+ + 3 * MAX_STR_LEN);
label = (unsigned char *)&d->items[12];
ct = label + MAX_STR_LEN;
@@ -269,16 +317,16 @@ static void assoc_edit_item(struct dialog_data *dlg, struct list *data, void (*o
s->dlg = dlg;
switch (dlg_title) {
- case TITLE_EDIT:
- d->title = TEXT_(T_EDIT_ASSOCIATION);
- break;
+ case TITLE_EDIT:
+ d->title = TEXT_(T_EDIT_ASSOCIATION);
+ break;
- case TITLE_ADD:
- d->title = TEXT_(T_ADD_ASSOCIATION);
- break;
+ case TITLE_ADD:
+ d->title = TEXT_(T_ADD_ASSOCIATION);
+ break;
- default:
- internal("Unsupported dialog title.\n");
+ default:
+ internal("Unsupported dialog title.\n");
}
d->udata = neww;
@@ -330,13 +378,15 @@ static void assoc_edit_item(struct dialog_data *dlg, struct list *data, void (*o
do_dialog(term, d, getml(d, NULL));
}
-static int assoc_test_entry(struct list *e, unsigned char *str)
+static int
+assoc_test_entry(struct list *e, unsigned char *str)
{
struct assoc *a = get_struct(e, struct assoc, head);
return casestrstr(a->label, str) || casestrstr(a->ct, str);
}
-static struct list *assoc_find_item(struct list *s, unsigned char *str, int direction)
+static struct list *
+assoc_find_item(struct list *s, unsigned char *str, int direction)
{
struct list *e;
@@ -357,26 +407,27 @@ static struct list *assoc_find_item(struct list *s, unsigned char *str, int dire
return NULL;
}
-
-void update_assoc(struct assoc *neww)
+void
+update_assoc(struct assoc *neww)
{
struct assoc *repl;
struct list *r = NULL;
struct list_head *lr;
if (!neww->label[0] || !neww->ct[0] || !neww->prog[0])
return;
- foreach(struct list, r, lr, assoc.list_entry) {
+ foreach (struct list, r, lr, assoc.list_entry) {
repl = get_struct(r, struct assoc, head);
- if (!strcmp(cast_const_char repl->label, cast_const_char neww->label)
- && !strcmp(cast_const_char repl->ct, cast_const_char neww->ct)
- && !strcmp(cast_const_char repl->prog, cast_const_char neww->prog)
- && repl->block == neww->block
- && repl->cons == neww->cons
- && repl->xwin == neww->xwin
- && repl->ask == neww->ask
- && repl->accept_http == neww->accept_http
- && repl->accept_ftp == neww->accept_ftp
- && repl->system == neww->system) {
+ if (!strcmp(cast_const_char repl->label,
+ cast_const_char neww->label)
+ && !strcmp(cast_const_char repl->ct,
+ cast_const_char neww->ct)
+ && !strcmp(cast_const_char repl->prog,
+ cast_const_char neww->prog)
+ && repl->block == neww->block && repl->cons == neww->cons
+ && repl->xwin == neww->xwin && repl->ask == neww->ask
+ && repl->accept_http == neww->accept_http
+ && repl->accept_ftp == neww->accept_ftp
+ && repl->system == neww->system) {
del_from_list(&repl->head);
add_to_list(assoc.list_entry, &repl->head);
return;
@@ -400,21 +451,26 @@ void update_assoc(struct assoc *neww)
/*------------------------ EXTENSIONS -----------------------*/
/* DECLARATIONS */
-static void ext_edit_item(struct dialog_data *, struct list *, void (*)(struct dialog_data *, struct list *, struct list *, struct list_description *), struct list *, unsigned char);
+static void ext_edit_item(struct dialog_data *, struct list *,
+ void (*)(struct dialog_data *, struct list *,
+ struct list *, struct list_description *),
+ struct list *, unsigned char);
static void ext_copy_item(struct list *, struct list *);
static struct list *ext_new_item(void *);
static void ext_delete_item(struct list *);
-static struct list *ext_find_item(struct list *start, unsigned char *str, int direction);
+static struct list *ext_find_item(struct list *start, unsigned char *str,
+ int direction);
static unsigned char *ext_type_item(struct terminal *, struct list *, int);
struct list extensions = { init_list_1st(&extensions.list_entry) 0, -1, NULL };
-static struct history ext_search_history = { 0, { &ext_search_history.items, &ext_search_history.items } };
-
+static struct history ext_search_history = {
+ 0, {&ext_search_history.items, &ext_search_history.items}
+};
-static struct list_description ext_ld={
- 0, /* 0= flat; 1=tree */
- &extensions, /* list */
+static struct list_description ext_ld = {
+ 0, /* 0= flat; 1=tree */
+ &extensions, /* list */
ext_new_item,
ext_edit_item,
NULL,
@@ -423,28 +479,28 @@ static struct list_description ext_ld={
ext_type_item,
ext_find_item,
&ext_search_history,
- 0, /* this is set in init_assoc function */
- 15, /* # of items in main window */
+ 0, /* this is set in init_assoc function */
+ 15, /* # of items in main window */
T_eXTENSION,
T_EXTENSIONS_ALREADY_IN_USE,
T_EXTENSIONS_MANAGER,
T_DELETE_EXTENSION,
- 0, /* no button */
- NULL, /* no button */
- NULL, /* no save*/
+ 0, /* no button */
+ NULL, /* no button */
+ NULL, /* no save*/
- NULL,NULL,0,0, /* internal vars */
+ NULL,
+ NULL,
+ 0,
+ 0, /* internal vars */
0, /* modified */
NULL,
NULL,
0,
};
-
-
-
-
-static struct list *ext_new_item(void *ignore)
+static struct list *
+ext_new_item(void *ignore)
{
struct extension *neww;
@@ -455,8 +511,8 @@ static struct list *ext_new_item(void *ignore)
return &neww->head;
}
-
-static void ext_delete_item(struct list *data)
+static void
+ext_delete_item(struct list *data)
{
struct extension *del = get_struct(data, struct extension, head);
@@ -467,8 +523,8 @@ static void ext_delete_item(struct list *data)
free(del);
}
-
-static void ext_copy_item(struct list *in, struct list *out)
+static void
+ext_copy_item(struct list *in, struct list *out)
{
struct extension *item_in = get_struct(in, struct extension, head);
struct extension *item_out = get_struct(out, struct extension, head);
@@ -480,16 +536,17 @@ static void ext_copy_item(struct list *in, struct list *out)
item_out->ct = stracpy(item_in->ct);
}
-
/* allocate string and print extension into it */
/* x: 0=type all, 1=type title only */
-static unsigned char *ext_type_item(struct terminal *term, struct list *data, int x)
+static unsigned char *
+ext_type_item(struct terminal *term, struct list *data, int x)
{
unsigned char *txt, *txt1;
struct extension *item;
if (data == &extensions)
- return stracpy(get_text_translation(TEXT_(T_FILE_EXTENSIONS), term));
+ return stracpy(
+ get_text_translation(TEXT_(T_FILE_EXTENSIONS), term));
item = get_struct(data, struct extension, head);
txt = stracpy(item->ext);
@@ -501,19 +558,20 @@ static unsigned char *ext_type_item(struct terminal *term, struct list *data, in
return txt1;
}
-
-void menu_ext_manager(struct terminal *term, void *fcp, void *ses_)
+void
+menu_ext_manager(struct terminal *term, void *fcp, void *ses_)
{
struct session *ses = (struct session *)ses_;
create_list_window(&ext_ld, &extensions, term, ses);
}
-static unsigned char * const ext_msg[] = {
+static unsigned char *const ext_msg[] = {
TEXT_(T_EXTENSION_S),
TEXT_(T_CONTENT_TYPE),
};
-static void ext_edit_item_fn(struct dialog_data *dlg)
+static void
+ext_edit_item_fn(struct dialog_data *dlg)
{
struct terminal *term = dlg->win->term;
int max = 0, min = 0;
@@ -535,29 +593,37 @@ static void ext_edit_item_fn(struct dialog_data *dlg)
if (w < 1)
w = 1;
rw = 0;
- dlg_format_text_and_field(dlg, NULL, ext_msg[0], &dlg->items[0], 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, NULL, ext_msg[0], &dlg->items[0], 0, &y,
+ w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_text_and_field(dlg, NULL, ext_msg[1], &dlg->items[1], 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, NULL, ext_msg[1], &dlg->items[1], 0, &y,
+ w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_buttons(dlg, NULL, dlg->items + 2, 2, 0, &y, w, &rw, AL_CENTER);
+ dlg_format_buttons(dlg, NULL, dlg->items + 2, 2, 0, &y, w, &rw,
+ AL_CENTER);
w = rw;
dlg->xw = w + 2 * DIALOG_LB;
dlg->yw = y + 2 * DIALOG_TB;
center_dlg(dlg);
draw_dlg(dlg);
y = dlg->y + DIALOG_TB;
- dlg_format_text_and_field(dlg, term, ext_msg[0], &dlg->items[0], dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, term, ext_msg[0], &dlg->items[0],
+ dlg->x + DIALOG_LB, &y, w, NULL,
+ COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_text_and_field(dlg, term, ext_msg[1], &dlg->items[1], dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+ dlg_format_text_and_field(dlg, term, ext_msg[1], &dlg->items[1],
+ dlg->x + DIALOG_LB, &y, w, NULL,
+ COLOR_DIALOG_TEXT, AL_LEFT);
y++;
- dlg_format_buttons(dlg, term, &dlg->items[2], 2, dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);
+ dlg_format_buttons(dlg, term, &dlg->items[2], 2, dlg->x + DIALOG_LB, &y,
+ w, NULL, AL_CENTER);
}
-
/* Puts url and title into the bookmark item */
-static void ext_edit_done(void *data)
+static void
+ext_edit_done(void *data)
{
- struct dialog *d = (struct dialog*)data;
+ struct dialog *d = (struct dialog *)data;
struct extension *item = (struct extension *)d->udata;
struct assoc_ok_struct *s = (struct assoc_ok_struct *)d->udata2;
unsigned char *txt;
@@ -566,21 +632,23 @@ static void ext_edit_done(void *data)
ext = (unsigned char *)&d->items[5];
ct = ext + MAX_STR_LEN;
- txt = convert(term_charset(s->dlg->win->term), ext_ld.codepage,ext, NULL);
+ txt = convert(term_charset(s->dlg->win->term), ext_ld.codepage, ext,
+ NULL);
free(item->ext);
item->ext = txt;
- txt = convert(term_charset(s->dlg->win->term), ext_ld.codepage,ct, NULL);
+ txt =
+ convert(term_charset(s->dlg->win->term), ext_ld.codepage, ct, NULL);
free(item->ct);
- item->ct=txt;
+ item->ct = txt;
s->fn(s->dlg, s->data, &item->head, &ext_ld);
- d->udata = NULL; /* for abort function */
+ d->udata = NULL; /* for abort function */
}
-
/* destroys an item, this function is called when edit window is aborted */
-static void ext_edit_abort(struct dialog_data *data)
+static void
+ext_edit_abort(struct dialog_data *data)
{
struct dialog *dlg = data->dlg;
struct extension *item = (struct extension *)dlg->udata;
@@ -590,8 +658,11 @@ static void ext_edit_abort(struct dialog_data *data)
ext_delete_item(&item->head);
}
-
-static void ext_edit_item(struct dialog_data *dlg, struct list *data, void (*ok_fn)(struct dialog_data *, struct list *, struct list *, struct list_description *), struct list *ok_arg, unsigned char dlg_title)
+static void
+ext_edit_item(struct dialog_data *dlg, struct list *data,
+ void (*ok_fn)(struct dialog_data *, struct list *, struct list *,
+ struct list_description *),
+ struct list *ok_arg, unsigned char dlg_title)
{
struct extension *neww = get_struct(data, struct extension, head);
struct terminal *term = dlg->win->term;
@@ -600,7 +671,8 @@ static void ext_edit_item(struct dialog_data *dlg, struct list *data, void (*ok_
unsigned char *ext;
unsigned char *ct;
- d = mem_calloc(sizeof(struct dialog) + 4 * sizeof(struct dialog_item) + 2 * MAX_STR_LEN);
+ d = mem_calloc(sizeof(struct dialog) + 4 * sizeof(struct dialog_item)
+ + 2 * MAX_STR_LEN);
ext = (unsigned char *)&d->items[5];
ct = ext + MAX_STR_LEN;
@@ -653,14 +725,15 @@ static void ext_edit_item(struct dialog_data *dlg, struct list *data, void (*ok_
do_dialog(term, d, getml(d, NULL));
}
-
-static int ext_test_entry(struct list *e, unsigned char *str)
+static int
+ext_test_entry(struct list *e, unsigned char *str)
{
struct extension *ext = get_struct(e, struct extension, head);
return casestrstr(ext->ext, str) || casestrstr(ext->ct, str);
}
-static struct list *ext_find_item(struct list *s, unsigned char *str, int direction)
+static struct list *
+ext_find_item(struct list *s, unsigned char *str, int direction)
{
struct list *e;
@@ -681,18 +754,20 @@ static struct list *ext_find_item(struct list *s, unsigned char *str, int direct
return NULL;
}
-
-void update_ext(struct extension *neww)
+void
+update_ext(struct extension *neww)
{
struct extension *repl;
struct list *r = NULL;
struct list_head *lr;
if (!neww->ext[0] || !neww->ct[0])
return;
- foreach(struct list, r, lr, extensions.list_entry) {
+ foreach (struct list, r, lr, extensions.list_entry) {
repl = get_struct(r, struct extension, head);
- if (!strcmp(cast_const_char repl->ext, cast_const_char neww->ext)
- && !strcmp(cast_const_char repl->ct, cast_const_char neww->ct)) {
+ if (!strcmp(cast_const_char repl->ext,
+ cast_const_char neww->ext)
+ && !strcmp(cast_const_char repl->ct,
+ cast_const_char neww->ct)) {
del_from_list(&repl->head);
add_to_list(extensions.list_entry, &repl->head);
return;
@@ -705,14 +780,16 @@ void update_ext(struct extension *neww)
add_to_list(extensions.list_entry, &repl->head);
}
-void update_prog(struct list_head *l, unsigned char *p, int s)
+void
+update_prog(struct list_head *l, unsigned char *p, int s)
{
struct protocol_program *repl = NULL;
struct list_head *lrepl;
- foreach(struct protocol_program, repl, lrepl, *l) if (repl->system == s) {
- free(repl->prog);
- goto ss;
- }
+ foreach (struct protocol_program, repl, lrepl, *l)
+ if (repl->system == s) {
+ free(repl->prog);
+ goto ss;
+ }
repl = xmalloc(sizeof(struct protocol_program));
add_to_list(*l, repl);
repl->system = s;
@@ -721,24 +798,31 @@ ss:
safe_strncpy(repl->prog, p, MAX_STR_LEN);
}
-unsigned char *get_prog(struct list_head *l)
+unsigned char *
+get_prog(struct list_head *l)
{
struct protocol_program *repl = NULL;
struct list_head *lrepl;
- foreach(struct protocol_program, repl, lrepl, *l) if (repl->system == SYSTEM_ID) return repl->prog;
+ foreach (struct protocol_program, repl, lrepl, *l)
+ if (repl->system == SYSTEM_ID)
+ return repl->prog;
update_prog(l, cast_uchar "", SYSTEM_ID);
- foreach(struct protocol_program, repl, lrepl, *l) if (repl->system == SYSTEM_ID) return repl->prog;
+ foreach (struct protocol_program, repl, lrepl, *l)
+ if (repl->system == SYSTEM_ID)
+ return repl->prog;
internal("get_prog: program was not added");
- return cast_uchar "";;
+ return cast_uchar "";
+ ;
}
-
/* creates default extensions if extension list is empty */
-void create_initial_extensions(void)
+void
+create_initial_extensions(void)
{
struct extension ext;
- if (!list_empty(extensions.list_entry)) return;
+ if (!list_empty(extensions.list_entry))
+ return;
/* here you can add any default extension you want */
ext.ext = cast_uchar "xpm";
@@ -865,7 +949,8 @@ void create_initial_extensions(void)
/* --------------------------- PROG -----------------------------*/
-static int is_in_list(unsigned char *list, unsigned char *str, int l)
+static int
+is_in_list(unsigned char *list, unsigned char *str, int l)
{
unsigned char *l2, *l3;
if (!l)
@@ -875,8 +960,10 @@ rep:
list++;
if (!*list)
return 0;
- for (l2 = list; *l2 && *l2 != ','; l2++);
- for (l3 = l2 - 1; l3 >= list && *l3 <= ' '; l3--);
+ for (l2 = list; *l2 && *l2 != ','; l2++)
+ ;
+ for (l3 = l2 - 1; l3 >= list && *l3 <= ' '; l3--)
+ ;
l3++;
if (l3 - list == l && !casecmp(str, list, l))
return 1;
@@ -887,7 +974,8 @@ rep:
}
/* FIXME */
-static char *canonical_compressed_ext(char *ext, char *ext_end)
+static char *
+canonical_compressed_ext(char *ext, char *ext_end)
{
size_t len;
if (!ext_end)
@@ -919,7 +1007,8 @@ static char *canonical_compressed_ext(char *ext, char *ext_end)
}
/* FIXME */
-unsigned char *get_compress_by_extension(char *ext, char *ext_end)
+unsigned char *
+get_compress_by_extension(char *ext, char *ext_end)
{
size_t len;
char *x;
@@ -957,7 +1046,8 @@ unsigned char *get_compress_by_extension(char *ext, char *ext_end)
return NULL;
}
-unsigned char *get_content_type_by_extension(unsigned char *url)
+unsigned char *
+get_content_type_by_extension(unsigned char *url)
{
struct list *l = NULL;
struct list_head *ll;
@@ -967,24 +1057,26 @@ unsigned char *get_content_type_by_extension(unsigned char *url)
extl = 0;
if (!(ct = get_url_data(url)))
ct = url;
- for (eod = ct; *eod && !end_of_dir(url, *eod); eod++);
+ for (eod = ct; *eod && !end_of_dir(url, *eod); eod++)
+ ;
for (; ct < eod; ct++)
if (*ct == '.') {
if (ext)
- if (get_compress_by_extension((char *)(ct + 1), (char *)eod))
+ if (get_compress_by_extension((char *)(ct + 1),
+ (char *)eod))
break;
ext = ct + 1;
} else if (dir_sep(*ct))
ext = NULL;
if (ext)
while (ext[extl] && ext[extl] != '.' && !dir_sep(ext[extl])
- && !end_of_dir(url, ext[extl]))
+ && !end_of_dir(url, ext[extl]))
extl++;
if ((extl == 3 && !casecmp(ext, cast_uchar "htm", 3))
- || (extl == 4 && !casecmp(ext, cast_uchar "html", 4))
- || (extl == 5 && !casecmp(ext, cast_uchar "xhtml", 5)))
+ || (extl == 4 && !casecmp(ext, cast_uchar "html", 4))
+ || (extl == 5 && !casecmp(ext, cast_uchar "xhtml", 5)))
return stracpy(cast_uchar "text/html");
- foreach(struct list, l, ll, extensions.list_entry) {
+ foreach (struct list, l, ll, extensions.list_entry) {
struct extension *e = get_struct(l, struct extension, head);
unsigned char *fname = NULL;
if (!(ct = get_url_data(url)))
@@ -998,18 +1090,20 @@ unsigned char *get_content_type_by_extension(unsigned char *url)
} else {
int fnlen = 0;
int x;
- while (fname[fnlen] && !end_of_dir(url, fname[fnlen])) fnlen++;
+ while (fname[fnlen] && !end_of_dir(url, fname[fnlen]))
+ fnlen++;
for (x = 0; x < fnlen; x++)
if (fname[x] == '.')
- if (is_in_list(e->ext, fname + x + 1, fnlen - x - 1))
+ if (is_in_list(e->ext, fname + x + 1,
+ fnlen - x - 1))
return stracpy(e->ct);
}
}
if ((extl == 3 && !casecmp(ext, cast_uchar "jpg", 3))
- || (extl == 4 && !casecmp(ext, cast_uchar "pjpg", 4))
- || (extl == 4 && !casecmp(ext, cast_uchar "jpeg", 4))
- || (extl == 5 && !casecmp(ext, cast_uchar "pjpeg", 5)))
+ || (extl == 4 && !casecmp(ext, cast_uchar "pjpg", 4))
+ || (extl == 4 && !casecmp(ext, cast_uchar "jpeg", 4))
+ || (extl == 5 && !casecmp(ext, cast_uchar "pjpeg", 5)))
return stracpy(cast_uchar "image/jpeg");
if ((extl == 3 && !casecmp(ext, cast_uchar "png", 3)))
return stracpy(cast_uchar "image/png");
@@ -1018,13 +1112,13 @@ unsigned char *get_content_type_by_extension(unsigned char *url)
if ((extl == 3 && !casecmp(ext, cast_uchar "xbm", 3)))
return stracpy(cast_uchar "image/x-xbitmap");
if ((extl == 3 && !casecmp(ext, cast_uchar "tif", 3))
- || (extl == 4 && !casecmp(ext, cast_uchar "tiff", 4)))
+ || (extl == 4 && !casecmp(ext, cast_uchar "tiff", 4)))
return stracpy(cast_uchar "image/tiff");
exxt = init_str();
el = 0;
add_to_str(&exxt, &el, cast_uchar "application/x-");
add_bytes_to_str(&exxt, &el, ext, extl);
- foreach(struct list, l, ll, assoc.list_entry) {
+ foreach (struct list, l, ll, assoc.list_entry) {
struct assoc *a = get_struct(l, struct assoc, head);
if (is_in_list(a->ct, exxt, el))
return exxt;
@@ -1033,7 +1127,9 @@ unsigned char *get_content_type_by_extension(unsigned char *url)
return NULL;
}
-static unsigned char *get_content_type_by_header_and_extension(unsigned char *head, unsigned char *url)
+static unsigned char *
+get_content_type_by_header_and_extension(unsigned char *head,
+ unsigned char *url)
{
unsigned char *ct, *file;
ct = get_content_type_by_extension(url);
@@ -1049,14 +1145,15 @@ static unsigned char *get_content_type_by_header_and_extension(unsigned char *he
return NULL;
}
-static unsigned char *get_extension_by_content_type(unsigned char *ct)
+static unsigned char *
+get_extension_by_content_type(unsigned char *ct)
{
struct list *l = NULL;
struct list_head *ll;
unsigned char *x, *y;
if (is_html_type(ct))
return stracpy(cast_uchar "html");
- foreach(struct list, l, ll, extensions.list_entry) {
+ foreach (struct list, l, ll, extensions.list_entry) {
struct extension *e = get_struct(l, struct extension, head);
if (!casestrcmp(e->ct, ct)) {
x = stracpy(e->ext);
@@ -1066,67 +1163,69 @@ static unsigned char *get_extension_by_content_type(unsigned char *ct)
}
}
if (!casestrcmp(ct, cast_uchar "image/jpeg")
- || !casestrcmp(ct, cast_uchar "image/jpg")
- || !casestrcmp(ct, cast_uchar "image/jpe")
- || !casestrcmp(ct, cast_uchar "image/pjpe")
- || !casestrcmp(ct, cast_uchar "image/pjpeg")
- || !casestrcmp(ct, cast_uchar "image/pjpg"))
+ || !casestrcmp(ct, cast_uchar "image/jpg")
+ || !casestrcmp(ct, cast_uchar "image/jpe")
+ || !casestrcmp(ct, cast_uchar "image/pjpe")
+ || !casestrcmp(ct, cast_uchar "image/pjpeg")
+ || !casestrcmp(ct, cast_uchar "image/pjpg"))
return stracpy(cast_uchar "jpg");
if (!casestrcmp(ct, cast_uchar "image/png")
- || !casestrcmp(ct, cast_uchar "image/x-png"))
+ || !casestrcmp(ct, cast_uchar "image/x-png"))
return stracpy(cast_uchar "png");
if (!casestrcmp(ct, cast_uchar "image/gif"))
return stracpy(cast_uchar "gif");
if (!casestrcmp(ct, cast_uchar "image/x-bitmap"))
return stracpy(cast_uchar "xbm");
if (!casestrcmp(ct, cast_uchar "image/tiff")
- || !casestrcmp(ct, cast_uchar "image/tif"))
+ || !casestrcmp(ct, cast_uchar "image/tif"))
return stracpy(cast_uchar "tiff");
- if (!casestrcmp(ct, cast_uchar "image/svg")
- || !casestrcmp(ct, cast_uchar "image/svg+xml"))
+ if (!casestrcmp(ct, cast_uchar "image/svg")
+ || !casestrcmp(ct, cast_uchar "image/svg+xml"))
return stracpy(cast_uchar "svg");
if (!cmpbeg(ct, cast_uchar "application/x-")) {
x = ct + strlen("application/x-");
if (casestrcmp(x, cast_uchar "z")
- && casestrcmp(x, cast_uchar "gz")
- && casestrcmp(x, cast_uchar "gzip")
- && casestrcmp(x, cast_uchar "br")
- && casestrcmp(x, cast_uchar "bz2")
- && casestrcmp(x, cast_uchar "bzip2")
- && casestrcmp(x, cast_uchar "lzma")
- && casestrcmp(x, cast_uchar "lzma2")
- && casestrcmp(x, cast_uchar "xz")
- && casestrcmp(x, cast_uchar "lz")
- && !strchr(cast_const_char x, '-')
- && strlen(cast_const_char x) <= 4)
+ && casestrcmp(x, cast_uchar "gz")
+ && casestrcmp(x, cast_uchar "gzip")
+ && casestrcmp(x, cast_uchar "br")
+ && casestrcmp(x, cast_uchar "bz2")
+ && casestrcmp(x, cast_uchar "bzip2")
+ && casestrcmp(x, cast_uchar "lzma")
+ && casestrcmp(x, cast_uchar "lzma2")
+ && casestrcmp(x, cast_uchar "xz")
+ && casestrcmp(x, cast_uchar "lz")
+ && !strchr(cast_const_char x, '-')
+ && strlen(cast_const_char x) <= 4)
return stracpy(x);
}
return NULL;
}
-static unsigned char *get_content_encoding_from_content_type(unsigned char *ct)
+static unsigned char *
+get_content_encoding_from_content_type(unsigned char *ct)
{
if (!casestrcmp(ct, cast_uchar "application/x-gzip")
- || !casestrcmp(ct, cast_uchar "application/x-tgz")
- || !casestrcmp(ct, cast_uchar "application/x-gtar"))
+ || !casestrcmp(ct, cast_uchar "application/x-tgz")
+ || !casestrcmp(ct, cast_uchar "application/x-gtar"))
return cast_uchar "gzip";
if (!casestrcmp(ct, cast_uchar "application/x-br"))
return cast_uchar "br";
if (!casestrcmp(ct, cast_uchar "application/x-bzip2")
- || !casestrcmp(ct, cast_uchar "application/x-bzip"))
+ || !casestrcmp(ct, cast_uchar "application/x-bzip"))
return cast_uchar "bzip2";
if (!casestrcmp(ct, cast_uchar "application/x-lzma"))
return cast_uchar "lzma";
if (!casestrcmp(ct, cast_uchar "application/x-lzma2")
- || !casestrcmp(ct, cast_uchar "application/x-xz"))
+ || !casestrcmp(ct, cast_uchar "application/x-xz"))
return cast_uchar "lzma2";
if (!casestrcmp(ct, cast_uchar "application/x-lz")
- || !casestrcmp(ct, cast_uchar "application/x-lzip"))
+ || !casestrcmp(ct, cast_uchar "application/x-lzip"))
return cast_uchar "lzip";
return NULL;
}
-unsigned char *get_content_type(unsigned char *head, unsigned char *url)
+unsigned char *
+get_content_type(unsigned char *head, unsigned char *url)
{
unsigned char *ct;
int code;
@@ -1136,21 +1235,24 @@ unsigned char *get_content_type(unsigned char *head, unsigned char *url)
*s = 0;
while (*ct && ct[strlen(cast_const_char ct) - 1] <= ' ')
ct[strlen(cast_const_char ct) - 1] = 0;
- if (*ct == '"' && ct[1] && ct[strlen(cast_const_char ct) - 1] == '"') {
+ if (*ct == '"' && ct[1]
+ && ct[strlen(cast_const_char ct) - 1] == '"') {
memmove(ct, ct + 1, strlen(cast_const_char ct));
ct[strlen(cast_const_char ct) - 1] = 0;
}
if (!casestrcmp(ct, cast_uchar "text/plain")
- || !casestrcmp(ct, cast_uchar "application/octet-stream")
- || !casestrcmp(ct, cast_uchar "application/octetstream")
- || !casestrcmp(ct, cast_uchar "application/octet_stream")
- || !casestrcmp(ct, cast_uchar "application/binary")
- || !casestrcmp(ct, cast_uchar "application/x-www-form-urlencoded")
- || get_content_encoding_from_content_type(ct)) {
+ || !casestrcmp(ct, cast_uchar "application/octet-stream")
+ || !casestrcmp(ct, cast_uchar "application/octetstream")
+ || !casestrcmp(ct, cast_uchar "application/octet_stream")
+ || !casestrcmp(ct, cast_uchar "application/binary")
+ || !casestrcmp(ct, cast_uchar
+ "application/x-www-form-urlencoded")
+ || get_content_encoding_from_content_type(ct)) {
unsigned char *ctt;
if (!get_http_code(head, &code, NULL) && code >= 300)
goto no_code_by_extension;
- ctt = get_content_type_by_header_and_extension(head, url);
+ ctt =
+ get_content_type_by_header_and_extension(head, url);
if (ctt) {
free(ct);
return ctt;
@@ -1167,10 +1269,12 @@ no_code_by_extension:
ct = get_content_type_by_header_and_extension(head, url);
if (ct)
return ct;
- return !force_html ? stracpy(cast_uchar "text/plain") : stracpy(cast_uchar "text/html");
+ return !force_html ? stracpy(cast_uchar "text/plain")
+ : stracpy(cast_uchar "text/html");
}
-unsigned char *get_content_encoding(unsigned char *head, unsigned char *url, int just_ce)
+unsigned char *
+get_content_encoding(unsigned char *head, unsigned char *url, int just_ce)
{
unsigned char *ce, *ct, *ext;
char *extd;
@@ -1199,19 +1303,21 @@ unsigned char *get_content_encoding(unsigned char *head, unsigned char *url, int
return NULL;
if (!(ext = get_url_data(url)))
ext = url;
- for (u = ext; *u; u++) if (end_of_dir(url, *u))
- goto skip_ext;
+ for (u = ext; *u; u++)
+ if (end_of_dir(url, *u))
+ goto skip_ext;
extd = strrchr((char *)ext, '.');
if (extd) {
ce = get_compress_by_extension(extd + 1, strchr(extd + 1, 0));
if (ce)
return stracpy(ce);
}
- skip_ext:
+skip_ext:
if ((ext = get_filename_from_header(head))) {
extd = strrchr((char *)ext, '.');
if (extd) {
- ce = get_compress_by_extension(extd + 1, strchr(extd + 1, 0));
+ ce = get_compress_by_extension(extd + 1,
+ strchr(extd + 1, 0));
if (ce) {
free(ext);
return stracpy(ce);
@@ -1222,13 +1328,14 @@ unsigned char *get_content_encoding(unsigned char *head, unsigned char *url, int
return NULL;
}
-unsigned char *encoding_2_extension(unsigned char *encoding)
+unsigned char *
+encoding_2_extension(unsigned char *encoding)
{
if (!casestrcmp(encoding, cast_uchar "gzip")
- || !casestrcmp(encoding, cast_uchar "x-gzip"))
+ || !casestrcmp(encoding, cast_uchar "x-gzip"))
return cast_uchar "gz";
if (!casestrcmp(encoding, cast_uchar "compress")
- || !casestrcmp(encoding, cast_uchar "x-compress"))
+ || !casestrcmp(encoding, cast_uchar "x-compress"))
return cast_uchar "Z";
if (!casestrcmp(encoding, cast_uchar "bzip2"))
return cast_uchar "bz2";
@@ -1242,17 +1349,19 @@ unsigned char *encoding_2_extension(unsigned char *encoding)
}
/* returns field with associations */
-struct assoc *get_type_assoc(struct terminal *term, unsigned char *type, int *n)
+struct assoc *
+get_type_assoc(struct terminal *term, unsigned char *type, int *n)
{
struct assoc *assoc_array;
struct list *l = NULL;
struct list_head *ll;
int count = 0;
- foreach(struct list, l, ll, assoc.list_entry) {
+ foreach (struct list, l, ll, assoc.list_entry) {
struct assoc *a = get_struct(l, struct assoc, head);
if (a->system == SYSTEM_ID
- && (term->environment & ENV_XWIN ? a->xwin : a->cons)
- && is_in_list(a->ct, type, (int)strlen(cast_const_char type))) {
+ && (term->environment & ENV_XWIN ? a->xwin : a->cons)
+ && is_in_list(a->ct, type,
+ (int)strlen(cast_const_char type))) {
if (count == INT_MAX)
overalloc();
count++;
@@ -1265,31 +1374,36 @@ struct assoc *get_type_assoc(struct terminal *term, unsigned char *type, int *n)
overalloc();
assoc_array = xmalloc(count * sizeof(struct assoc));
count = 0;
- foreach(struct list, l, ll, assoc.list_entry) {
+ foreach (struct list, l, ll, assoc.list_entry) {
struct assoc *a = get_struct(l, struct assoc, head);
if (a->system == SYSTEM_ID
- && (term->environment & ENV_XWIN ? a->xwin : a->cons)
- && is_in_list(a->ct, type, (int)strlen(cast_const_char type)))
+ && (term->environment & ENV_XWIN ? a->xwin : a->cons)
+ && is_in_list(a->ct, type,
+ (int)strlen(cast_const_char type)))
assoc_array[count++] = *a;
}
return assoc_array;
}
-int is_html_type(unsigned char *ct)
+int
+is_html_type(unsigned char *ct)
{
- return !casestrcmp(ct, cast_uchar "text/html") ||
- !casestrcmp(ct, cast_uchar "text-html") ||
- !casestrcmp(ct, cast_uchar "text/x-server-parsed-html") ||
- !casestrcmp(ct, cast_uchar "text/xml") ||
- !casecmp(ct, cast_uchar "application/xhtml", strlen("application/xhtml"));
+ return !casestrcmp(ct, cast_uchar "text/html")
+ || !casestrcmp(ct, cast_uchar "text-html")
+ || !casestrcmp(ct, cast_uchar "text/x-server-parsed-html")
+ || !casestrcmp(ct, cast_uchar "text/xml")
+ || !casecmp(ct, cast_uchar "application/xhtml",
+ strlen("application/xhtml"));
}
-unsigned char *get_filename_from_header(unsigned char *head)
+unsigned char *
+get_filename_from_header(unsigned char *head)
{
int extended = 0;
unsigned char *ct, *x, *y, *codepage;
int ly;
- if ((ct = parse_http_header(head, cast_uchar "Content-Disposition", NULL))) {
+ if ((ct = parse_http_header(head, cast_uchar "Content-Disposition",
+ NULL))) {
x = parse_header_param(ct, cast_uchar "filename*", 1);
if (x)
extended = 1;
@@ -1323,7 +1437,7 @@ ret_x:
ap1 = cast_uchar strchr(cast_const_char x, '\'');
if (!ap1)
goto no_extended;
- ap2 = cast_uchar strchr(cast_const_char (ap1 + 1), '\'');
+ ap2 = cast_uchar strchr(cast_const_char(ap1 + 1), '\'');
if (ap2)
ap2++;
else
@@ -1351,7 +1465,8 @@ no_extended:
return x;
}
-unsigned char *get_filename_from_url(unsigned char *url, unsigned char *head, int tmp)
+unsigned char *
+get_filename_from_url(unsigned char *url, unsigned char *head, int tmp)
{
int ll = 0;
unsigned char *u, *s, *e, *f, *x, *ww;
@@ -1383,7 +1498,7 @@ unsigned char *get_filename_from_url(unsigned char *url, unsigned char *head, in
}
free(ct);
}
- no_ct:
+no_ct:
if (!*want_ext) {
x = cast_uchar strrchr(cast_const_char f, '.');
if (x) {
@@ -1400,45 +1515,59 @@ unsigned char *get_filename_from_url(unsigned char *url, unsigned char *head, in
if (ct1)
free(ct1);
else if (x) {
- unsigned char *w = cast_uchar strrchr(cast_const_char want_ext, '.');
- if (w && (ww = (unsigned char *)canonical_compressed_ext((char *)(w + 1), NULL)) && !casestrcmp(x, ww))
+ unsigned char *w = cast_uchar strrchr(
+ cast_const_char want_ext, '.');
+ if (w
+ && (ww = (unsigned char *)
+ canonical_compressed_ext(
+ (char *)(w + 1), NULL))
+ && !casestrcmp(x, ww))
goto skip_want_ext;
if (w && !casestrcmp(w + 1, x))
goto skip_want_ext;
add_to_strn(&want_ext, cast_uchar ".");
add_to_strn(&want_ext, x);
- skip_want_ext:;
+skip_want_ext:;
}
- } else
- if (x) {
- if (strlen(cast_const_char x) + 1 < strlen(cast_const_char f)
- && f[strlen(cast_const_char f) - strlen(cast_const_char x) - 1] == '.'
- && !casestrcmp(f + strlen(cast_const_char f) - strlen(cast_const_char x), x)) {
- f[strlen(cast_const_char f) - strlen(cast_const_char x) - 1] = 0;
- }
+ } else if (x) {
+ if (strlen(cast_const_char x) + 1
+ < strlen(cast_const_char f)
+ && f[strlen(cast_const_char f)
+ - strlen(cast_const_char x) - 1]
+ == '.'
+ && !casestrcmp(f + strlen(cast_const_char f)
+ - strlen(cast_const_char x),
+ x)) {
+ f[strlen(cast_const_char f)
+ - strlen(cast_const_char x) - 1] = 0;
}
+ }
free(ct);
}
if (strlen(cast_const_char want_ext) > strlen(cast_const_char f)
- || casestrcmp(want_ext, f + strlen(cast_const_char f) - strlen(cast_const_char want_ext))) {
+ || casestrcmp(want_ext, f + strlen(cast_const_char f)
+ - strlen(cast_const_char want_ext))) {
x = cast_uchar strrchr(cast_const_char f, '.');
- if (x && (ww = (unsigned char *)canonical_compressed_ext((char *)(x + 1), NULL)) && want_ext[0] == '.'
- && !casestrcmp(want_ext + 1, ww))
+ if (x
+ && (ww = (unsigned char *)canonical_compressed_ext(
+ (char *)(x + 1), NULL))
+ && want_ext[0] == '.' && !casestrcmp(want_ext + 1, ww))
goto skip_tgz_2;
if (x)
*x = 0;
add_to_strn(&f, want_ext);
- skip_tgz_2:;
+skip_tgz_2:;
}
free(want_ext);
return f;
}
-void free_types(void)
+void
+free_types(void)
{
struct list *l = NULL;
struct list_head *ll;
- foreach(struct list, l, ll, assoc.list_entry) {
+ foreach (struct list, l, ll, assoc.list_entry) {
struct assoc *a = get_struct(l, struct assoc, head);
free(a->ct);
free(a->prog);
@@ -1447,7 +1576,7 @@ void free_types(void)
del_from_list(&a->head);
free(a);
}
- foreach(struct list, l, ll, extensions.list_entry) {
+ foreach (struct list, l, ll, extensions.list_entry) {
struct extension *e = get_struct(l, struct extension, head);
free(e->ext);
free(e->ct);
@@ -1459,4 +1588,3 @@ void free_types(void)
free_history(ext_search_history);
free_history(assoc_search_history);
}
-
diff --git a/url.c b/url.c
@@ -17,28 +17,31 @@ static const struct {
int need_slash_after_host;
int allow_post;
int bypasses_socks;
-} protocols[]= {
- {"data", 0, data_func, NULL, 1, 0, 0, 0, 0},
- {"file", 0, file_func, NULL, 1, 1, 0, 0, 1},
- {"https", 443, https_func, NULL, 0, 1, 1, 1, 0},
- {"http", 80, http_func, NULL, 0, 1, 1, 1, 0},
- {"proxy", 3128, proxy_func, NULL, 0, 1, 1, 1, 0},
- {NULL, 0, NULL, NULL, 0, 0, 0, 0, 0}
+} protocols[] = {
+ {"data", 0, data_func, NULL, 1, 0, 0, 0, 0},
+ { "file", 0, file_func, NULL, 1, 1, 0, 0, 1},
+ { "https", 443, https_func, NULL, 0, 1, 1, 1, 0},
+ { "http", 80, http_func, NULL, 0, 1, 1, 1, 0},
+ { "proxy", 3128, proxy_func, NULL, 0, 1, 1, 1, 0},
+ { NULL, 0, NULL, NULL, 0, 0, 0, 0, 0}
};
-
-
-static int check_protocol(unsigned char *p, size_t l)
+static int
+check_protocol(unsigned char *p, size_t l)
{
int i;
for (i = 0; protocols[i].prot; i++)
if (!casecmp(cast_uchar protocols[i].prot, p, l)
- && strlen(protocols[i].prot) == l)
+ && strlen(protocols[i].prot) == l)
return i;
return -1;
}
-static int get_prot_info(unsigned char *prot, int *port, void (**func)(struct connection *), void (**nc_func)(struct session *ses, unsigned char *), int *allow_post, int *bypasses_socks)
+static int
+get_prot_info(unsigned char *prot, int *port,
+ void (**func)(struct connection *),
+ void (**nc_func)(struct session *ses, unsigned char *),
+ int *allow_post, int *bypasses_socks)
{
int i;
for (i = 0; protocols[i].prot; i++)
@@ -58,7 +61,11 @@ static int get_prot_info(unsigned char *prot, int *port, void (**func)(struct co
return -1;
}
-int parse_url(unsigned char *url, int *prlen, unsigned char **user, int *uslen, unsigned char **pass, int *palen, unsigned char **host, int *holen, unsigned char **port, int *polen, unsigned char **data, int *dalen, unsigned char **post)
+int
+parse_url(unsigned char *url, int *prlen, unsigned char **user, int *uslen,
+ unsigned char **pass, int *palen, unsigned char **host, int *holen,
+ unsigned char **port, int *polen, unsigned char **data, int *dalen,
+ unsigned char **post)
{
unsigned char *p, *q;
unsigned char p_c[2];
@@ -107,10 +114,12 @@ int parse_url(unsigned char *url, int *prlen, unsigned char **user, int *uslen,
}
p += 3;
q = p + strcspn(cast_const_char p, "@/?");
- if (!*q && protocols[a].need_slash_after_host) return -1;
+ if (!*q && protocols[a].need_slash_after_host)
+ return -1;
if (*q == '@') {
unsigned char *pp;
- while (strcspn(cast_const_char(q + 1), "@") < strcspn(cast_const_char(q + 1), "/?"))
+ while (strcspn(cast_const_char(q + 1), "@")
+ < strcspn(cast_const_char(q + 1), "/?"))
q = q + 1 + strcspn(cast_const_char(q + 1), "@");
pp = cast_uchar strchr(cast_const_char p, ':');
if (!pp || pp > q) {
@@ -138,7 +147,7 @@ int parse_url(unsigned char *url, int *prlen, unsigned char **user, int *uslen,
}
}
q = p + strcspn((char *)p, ":/?");
- have_host:
+have_host:
if (!*q && protocols[a].need_slash_after_host)
return -1;
if (host)
@@ -155,7 +164,7 @@ int parse_url(unsigned char *url, int *prlen, unsigned char **user, int *uslen,
if (polen)
*polen = (int)(pp - q - 1);
for (cc = 0; cc < pp - q - 1; cc++)
- if (q[cc+1] < '0' || q[cc+1] > '9')
+ if (q[cc + 1] < '0' || q[cc + 1] > '9')
return -1;
q = pp;
}
@@ -174,25 +183,27 @@ int parse_url(unsigned char *url, int *prlen, unsigned char **user, int *uslen,
return 0;
}
-unsigned char *get_protocol_name(unsigned char *url)
+unsigned char *
+get_protocol_name(unsigned char *url)
{
int l;
if (parse_url(url, &l, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL))
+ NULL, NULL, NULL))
return NULL;
return memacpy(url, l);
}
-unsigned char *get_keepalive_id(unsigned char *url)
+unsigned char *
+get_keepalive_id(unsigned char *url)
{
unsigned char *h, *p, *k, *d;
int hl, pl;
if (parse_url(url, NULL, NULL, NULL, NULL, NULL, &h, &hl, &p, &pl, &d,
- NULL, NULL))
+ NULL, NULL))
return NULL;
if (is_proxy_url(url) && !casecmp(d, cast_uchar "https://", 8)) {
if (parse_url(d, NULL, NULL, NULL, NULL, NULL, &h, &hl, &p, &pl,
- NULL, NULL, NULL))
+ NULL, NULL, NULL))
return NULL;
}
k = p ? p + pl : h ? h + hl : NULL;
@@ -201,53 +212,58 @@ unsigned char *get_keepalive_id(unsigned char *url)
return memacpy(url, k - url);
}
-unsigned char *get_host_name(unsigned char *url)
+unsigned char *
+get_host_name(unsigned char *url)
{
unsigned char *h;
int hl;
if (parse_url(url, NULL, NULL, NULL, NULL, NULL, &h, &hl, NULL, NULL,
- NULL, NULL, NULL))
+ NULL, NULL, NULL))
return stracpy(cast_uchar "");
return memacpy(h, hl);
}
-unsigned char *get_user_name(unsigned char *url)
+unsigned char *
+get_user_name(unsigned char *url)
{
unsigned char *h;
int hl;
if (parse_url(url, NULL, &h, &hl, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL))
+ NULL, NULL, NULL))
return NULL;
return memacpy(h, hl);
}
-unsigned char *get_pass(unsigned char *url)
+unsigned char *
+get_pass(unsigned char *url)
{
unsigned char *h;
int hl;
- if (parse_url(url, NULL,NULL, NULL, &h, &hl, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL))
+ if (parse_url(url, NULL, NULL, NULL, &h, &hl, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL))
return NULL;
return memacpy(h, hl);
}
-unsigned char *get_port_str(unsigned char *url)
+unsigned char *
+get_port_str(unsigned char *url)
{
unsigned char *h;
int hl;
if (parse_url(url, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &h, &hl,
- NULL, NULL, NULL))
+ NULL, NULL, NULL))
return NULL;
return hl ? memacpy(h, hl) : NULL;
}
-int get_port(unsigned char *url)
+int
+get_port(unsigned char *url)
{
unsigned char *h;
int hl;
long n = -1;
if (parse_url(url, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &h, &hl,
- NULL, NULL, NULL))
+ NULL, NULL, NULL))
return -1;
if (h) {
n = strtol((char *)h, NULL, 10);
@@ -278,7 +294,8 @@ void (*get_protocol_handle(unsigned char *url))(struct connection *)
return f;
}
-void (*get_external_protocol_function(unsigned char *url))(struct session *, unsigned char *)
+void (*get_external_protocol_function(unsigned char *url))(struct session *,
+ unsigned char *)
{
unsigned char *p;
void (*f)(struct session *, unsigned char *) = NULL;
@@ -292,7 +309,8 @@ void (*get_external_protocol_function(unsigned char *url))(struct session *, uns
return f;
}
-int url_bypasses_socks(unsigned char *url)
+int
+url_bypasses_socks(unsigned char *url)
{
int ret = 0;
unsigned char *p;
@@ -303,18 +321,20 @@ int url_bypasses_socks(unsigned char *url)
return ret;
}
-unsigned char *get_url_data(unsigned char *url)
+unsigned char *
+get_url_data(unsigned char *url)
{
unsigned char *d;
if (parse_url(url, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- &d, NULL, NULL))
+ &d, NULL, NULL))
return NULL;
return d;
}
#define dsep(x) (lo ? dir_sep(x) : (x) == '/')
-static void translate_directories(unsigned char *url)
+static void
+translate_directories(unsigned char *url)
{
unsigned char *dd = get_url_data(url);
unsigned char *s, *d;
@@ -340,15 +360,15 @@ r:
memmove(d, s, strlen((char *)s) + 1);
return;
}
- if (dsep(s[0]) && s[1] == '.' && (dsep(s[2]) || !s[2]
- || end_of_dir(url, s[2]))) {
+ if (dsep(s[0]) && s[1] == '.'
+ && (dsep(s[2]) || !s[2] || end_of_dir(url, s[2]))) {
if (!dsep(s[2]))
*d++ = *s;
s += 2;
goto r;
}
- if (dsep(s[0]) && s[1] == '.' && s[2] == '.' && (dsep(s[3]) || !s[3]
- || end_of_dir(url, s[3]))) {
+ if (dsep(s[0]) && s[1] == '.' && s[2] == '.'
+ && (dsep(s[3]) || !s[3] || end_of_dir(url, s[3]))) {
while (d > dd) {
d--;
if (dsep(*d))
@@ -364,7 +384,8 @@ b:
goto r;
}
-static unsigned char *translate_hashbang(unsigned char *up)
+static unsigned char *
+translate_hashbang(unsigned char *up)
{
unsigned char *u, *p, *dp, *data, *post_seq;
int q;
@@ -375,7 +396,7 @@ static unsigned char *translate_hashbang(unsigned char *up)
u = stracpy(up);
p = extract_position(u);
if (!p) {
- free_u_ret_up:
+free_u_ret_up:
free(u);
return up;
}
@@ -406,7 +427,7 @@ static unsigned char *translate_hashbang(unsigned char *up)
for (; *dp; dp++) {
unsigned char c = *dp;
if (c <= 0x20 || c == 0x23 || c == 0x25 || c == 0x26
- || c == 0x2b || c >= 0x7f) {
+ || c == 0x2b || c >= 0x7f) {
unsigned char h[4];
sprintf((char *)h, "%%%02X", c);
add_to_str(&r, &rl, h);
@@ -420,7 +441,8 @@ static unsigned char *translate_hashbang(unsigned char *up)
return r;
}
-static unsigned char *rewrite_url_google_docs(unsigned char *n)
+static unsigned char *
+rewrite_url_google_docs(unsigned char *n)
{
int i;
unsigned char *id, *id_end, *url_end;
@@ -431,14 +453,22 @@ static unsigned char *rewrite_url_google_docs(unsigned char *n)
const char *result1;
const char *result2;
} const patterns[] = {
- { "https://docs.google.com/document/d/", "https://docs.google.com/document/d/", "/export?format=pdf" },
- { "https://docs.google.com/document/u/", "https://docs.google.com/document/u/", "/export?format=pdf" },
- { "https://docs.google.com/spreadsheets/d/", "https://docs.google.com/spreadsheets/d/", "/export?format=pdf" },
- { "https://docs.google.com/spreadsheets/u/", "https://docs.google.com/spreadsheets/u/", "/export?format=pdf" },
- { "https://docs.google.com/presentation/d/", "https://docs.google.com/presentation/d/", "/export/pdf" },
- { "https://docs.google.com/presentation/u/", "https://docs.google.com/presentation/u/", "/export/pdf" },
- { "https://drive.google.com/file/d/", "https://drive.google.com/uc?export=download&id=", "" },
- { "https://drive.google.com/file/u/", "https://drive.google.com/uc?export=download&id=", "" }
+ {"https://docs.google.com/document/d/",
+ "https://docs.google.com/document/d/", "/export?format=pdf"},
+ { "https://docs.google.com/document/u/",
+ "https://docs.google.com/document/u/", "/export?format=pdf"},
+ { "https://docs.google.com/spreadsheets/d/",
+ "https://docs.google.com/spreadsheets/d/", "/export?format=pdf"},
+ { "https://docs.google.com/spreadsheets/u/",
+ "https://docs.google.com/spreadsheets/u/", "/export?format=pdf"},
+ { "https://docs.google.com/presentation/d/",
+ "https://docs.google.com/presentation/d/", "/export/pdf" },
+ { "https://docs.google.com/presentation/u/",
+ "https://docs.google.com/presentation/u/", "/export/pdf" },
+ { "https://drive.google.com/file/d/",
+ "https://drive.google.com/uc?export=download&id=", "" },
+ { "https://drive.google.com/file/u/",
+ "https://drive.google.com/uc?export=download&id=", "" }
};
for (i = 0; i < array_elements(patterns); i++)
if (!cmpbeg(n, cast_uchar patterns[i].beginning))
@@ -466,7 +496,8 @@ match:
return res;
}
-static unsigned char *rewrite_url_mediawiki_svg(unsigned char *n)
+static unsigned char *
+rewrite_url_mediawiki_svg(unsigned char *n)
{
const char u1[] = "/media/math/render/svg/";
const char u2[] = "/media/math/render/png/";
@@ -481,7 +512,8 @@ static unsigned char *rewrite_url_mediawiki_svg(unsigned char *n)
return n;
}
-static unsigned char *rewrite_url(unsigned char *n)
+static unsigned char *
+rewrite_url(unsigned char *n)
{
extend_str(&n, 1);
translate_directories(n);
@@ -491,7 +523,8 @@ static unsigned char *rewrite_url(unsigned char *n)
return n;
}
-static int test_qualified_name(char *host, char *hostname)
+static int
+test_qualified_name(char *host, char *hostname)
{
char *c;
if (!strcasecmp(host, hostname))
@@ -505,7 +538,8 @@ static int test_qualified_name(char *host, char *hostname)
return 0;
}
-static int is_local_host(char *host)
+static int
+is_local_host(char *host)
{
if (!*host)
return 1;
@@ -523,10 +557,10 @@ static int is_local_host(char *host)
}
}
return 0;
-
}
-static void insert_wd(unsigned char **up, unsigned char *cwd)
+static void
+insert_wd(unsigned char **up, unsigned char *cwd)
{
unsigned char *u = *up;
unsigned char *cw;
@@ -538,11 +572,12 @@ static void insert_wd(unsigned char **up, unsigned char *cwd)
return;
if (casecmp(u, cast_uchar "file://", 7))
return;
- for (i = 7; u[i] && !dir_sep(u[i]); i++);
+ for (i = 7; u[i] && !dir_sep(u[i]); i++)
+ ;
host = cast_char memacpy(u + 7, i - 7);
if (is_local_host(host)) {
free(host);
- memmove(u + 7, u + i, strlen(cast_const_char (u + i)) + 1);
+ memmove(u + 7, u + i, strlen(cast_const_char(u + i)) + 1);
return;
}
free(host);
@@ -565,7 +600,8 @@ static void insert_wd(unsigned char **up, unsigned char *cwd)
*up = url;
}
-int url_non_ascii(unsigned char *url)
+int
+url_non_ascii(unsigned char *url)
{
unsigned char *ch;
for (ch = url; *ch; ch++)
@@ -574,7 +610,8 @@ int url_non_ascii(unsigned char *url)
return 0;
}
-static unsigned char *translate_idn(unsigned char *nu, int canfail)
+static unsigned char *
+translate_idn(unsigned char *nu, int canfail)
{
if (url_non_ascii(nu)) {
unsigned char *id = idn_encode_url(nu, 0);
@@ -597,7 +634,8 @@ static unsigned char *translate_idn(unsigned char *nu, int canfail)
* druhe url absolutni, vrati se to; pokud je relativni, tak se spoji prvni a
* druhe url.
*/
-unsigned char *join_urls(unsigned char *base, unsigned char *rel)
+unsigned char *
+join_urls(unsigned char *base, unsigned char *rel)
{
unsigned char *p, *n, *pp, *ch;
int l;
@@ -627,7 +665,8 @@ unsigned char *join_urls(unsigned char *base, unsigned char *rel)
if (rel[0] == '/' && rel[1] == '/' && !data) {
unsigned char *s;
if (!(s = cast_uchar strstr(cast_const_char base, "//"))) {
- if (!(s = cast_uchar strchr(cast_const_char base, ':'))) {
+ if (!(s = cast_uchar strchr(cast_const_char base,
+ ':'))) {
bad_base:
internal("bad base url: %s", base);
return NULL;
@@ -637,23 +676,24 @@ bad_base:
n = memacpy(base, s - base);
add_to_strn(&n, rel);
if (!parse_url(n, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL))
+ NULL, NULL, NULL, NULL, NULL))
goto return_n;
add_to_strn(&n, cast_uchar "/");
if (!parse_url(n, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL))
+ NULL, NULL, NULL, NULL, NULL))
goto return_n;
free(n);
}
if (is_proxy_url(rel))
goto prx;
if (!parse_url(rel, &l, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL)) {
+ NULL, NULL, NULL)) {
n = stracpy(rel);
goto return_n;
}
n = stracpy(rel);
- while (n[0] && n[strlen((char *)n) - 1] <= ' ') n[strlen((char *)n) - 1] = 0;
+ while (n[0] && n[strlen((char *)n) - 1] <= ' ')
+ n[strlen((char *)n) - 1] = 0;
extend_str(&n, 1);
ch = cast_uchar strrchr((char *)n, '#');
if (!ch || strchr((char *)ch, '/'))
@@ -661,12 +701,13 @@ bad_base:
memmove(ch + 1, ch, strlen((char *)ch) + 1);
*ch = '/';
if (!parse_url(n, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL))
+ NULL, NULL, NULL))
goto return_n;
free(n);
prx:
if (parse_url(base, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, &p, NULL, NULL) || !p) {
+ NULL, &p, NULL, NULL)
+ || !p) {
goto bad_base;
}
if (!dsep(*p))
@@ -676,13 +717,14 @@ prx:
for (; *p; p++) {
if (end_of_dir(base, *p))
break;
- } else if (!dsep(rel[0]))
+ }
+ else if (!dsep(rel[0]))
for (pp = p; *pp; pp++) {
if (end_of_dir(base, *pp))
break;
if (dsep(*pp))
p = pp + 1;
- }
+ }
}
n = memacpy(base, p - base);
add_to_strn(&n, rel);
@@ -694,7 +736,8 @@ return_n:
return n;
}
-unsigned char *translate_url(unsigned char *url, unsigned char *cwd)
+unsigned char *
+translate_url(unsigned char *url, unsigned char *cwd)
{
unsigned char *ch;
unsigned char *nu, *da;
@@ -713,7 +756,7 @@ unsigned char *translate_url(unsigned char *url, unsigned char *cwd)
if (is_proxy_url(url))
return NULL;
if (!parse_url(url, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, &da, NULL, NULL)) {
+ NULL, &da, NULL, NULL)) {
nu = stracpy(url);
goto return_nu;
}
@@ -728,7 +771,7 @@ unsigned char *translate_url(unsigned char *url, unsigned char *cwd)
memmove(ch + 1, ch, strlen((char *)ch) + 1);
*ch = '/';
if (!parse_url(nu, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL))
+ NULL, NULL, NULL, NULL, NULL))
goto return_nu;
free(nu);
}
@@ -743,7 +786,9 @@ unsigned char *translate_url(unsigned char *url, unsigned char *cwd)
if (*url != '.' && *ch == '.') {
unsigned char *e, *f, *g;
int tl;
- for (e = ch + 1; *(f = e + strcspn((char *)e, ".:/")) == '.'; e = f + 1)
+ for (e = ch + 1;
+ *(f = e + strcspn((char *)e, ".:/")) == '.';
+ e = f + 1)
;
g = memacpy(e, f - e);
tl = is_tld(g);
@@ -754,15 +799,17 @@ http:
sl = 1;
}
}
- if (*ch == '@' || *ch == ':' || !cmpbeg(url, cast_uchar "ftp.")) {
+ if (*ch == '@' || *ch == ':'
+ || !cmpbeg(url, cast_uchar "ftp.")) {
prefix = cast_uchar "ftp://";
sl = 1;
}
nu = stracpy(prefix);
add_to_strn(&nu, url);
- if (sl && !strchr((char *)url, '/')) add_to_strn(&nu, cast_uchar "/");
+ if (sl && !strchr((char *)url, '/'))
+ add_to_strn(&nu, cast_uchar "/");
if (parse_url(nu, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL)) {
+ NULL, NULL, NULL, NULL, NULL)) {
free(nu);
return NULL;
}
@@ -772,11 +819,11 @@ http:
add_to_strn(&nu, cast_uchar "//");
add_to_strn(&nu, ch + 1);
if (!parse_url(nu, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL))
+ NULL, NULL, NULL))
goto return_nu;
add_to_strn(&nu, cast_uchar "/");
if (!parse_url(nu, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL))
+ NULL, NULL, NULL))
goto return_nu;
free(nu);
return NULL;
@@ -790,7 +837,8 @@ return_nu:
return nu;
}
-unsigned char *extract_position(unsigned char *url)
+unsigned char *
+extract_position(unsigned char *url)
{
unsigned char *u, *uu, *r;
if ((u = get_url_data(url)))
@@ -804,20 +852,23 @@ unsigned char *extract_position(unsigned char *url)
return r;
}
-int url_not_saveable(unsigned char *url)
+int
+url_not_saveable(unsigned char *url)
{
int p, palen;
unsigned char *u = translate_url(url, cast_uchar "/");
if (!u)
return 1;
p = parse_url(u, NULL, NULL, NULL, NULL, &palen, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL);
+ NULL, NULL, NULL);
free(u);
return p || palen;
}
-#define accept_char(x) ((x) != 10 && (x) != 13 && (x) != '"' && (x) != '\'' && (x) != '&' && (x) != '<' && (x) != '>')
-#define special_char(x) ((x) < ' ' || (x) == '%' || (x) == '#' || (x) >= 127)
+#define accept_char(x) \
+ ((x) != 10 && (x) != 13 && (x) != '"' && (x) != '\'' && (x) != '&' \
+ && (x) != '<' && (x) != '>')
+#define special_char(x) ((x) < ' ' || (x) == '%' || (x) == '#' || (x) >= 127)
/*
* -2 percent to raw
@@ -826,7 +877,9 @@ int url_not_saveable(unsigned char *url)
* 1 raw to percent
*/
-void add_conv_str(unsigned char **s, int *l, unsigned char *b, int ll, int encode_special)
+void
+add_conv_str(unsigned char **s, int *l, unsigned char *b, int ll,
+ int encode_special)
{
for (; ll > 0; ll--, b++) {
unsigned char chr = *b;
@@ -839,8 +892,12 @@ void add_conv_str(unsigned char **s, int *l, unsigned char *b, int ll, int encod
continue;
}
if (chr == '%' && encode_special <= -1 && ll > 2
- && ((b[1] >= '0' && b[1] <= '9') || (b[1] >= 'A' && b[1] <= 'F') || (b[1] >= 'a' && b[1] <= 'f'))
- && ((b[2] >= '0' && b[2] <= '9') || (b[2] >= 'A' && b[2] <= 'F') || (b[2] >= 'a' && b[2] <= 'f'))) {
+ && ((b[1] >= '0' && b[1] <= '9')
+ || (b[1] >= 'A' && b[1] <= 'F')
+ || (b[1] >= 'a' && b[1] <= 'f'))
+ && ((b[2] >= '0' && b[2] <= '9')
+ || (b[2] >= 'A' && b[2] <= 'F')
+ || (b[2] >= 'a' && b[2] <= 'f'))) {
int i;
chr = 0;
for (i = 1; i < 3; i++) {
@@ -870,35 +927,37 @@ void add_conv_str(unsigned char **s, int *l, unsigned char *b, int ll, int encod
}
}
-void convert_file_charset(unsigned char **s, int *l, int start_l)
+void
+convert_file_charset(unsigned char **s, int *l, int start_l)
{
}
static const char xn[] = "xn--";
static const size_t xn_l = sizeof(xn) - 1;
-#define puny_max_length 63
-#define puny_base 36
-#define puny_tmin 1
-#define puny_tmax 26
-#define puny_skew 38
-#define puny_damp 700
-#define puny_init_bias 72
+#define puny_max_length 63
+#define puny_base 36
+#define puny_tmin 1
+#define puny_tmax 26
+#define puny_skew 38
+#define puny_damp 700
+#define puny_init_bias 72
-static int ascii_allowed(unsigned c)
+static int
+ascii_allowed(unsigned c)
{
- return c == '-'
- || (c >= '0' && c <= '9')
- || (c >= 'A' && c <= 'Z')
- || (c >= 'a' && c <= 'z');
+ return c == '-' || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z')
+ || (c >= 'a' && c <= 'z');
}
-static unsigned char puny_chrenc(unsigned n)
+static unsigned char
+puny_chrenc(unsigned n)
{
return n + (n < 26 ? 'a' : '0' - 26);
}
-static unsigned puny_chrdec(unsigned char c)
+static unsigned
+puny_chrdec(unsigned char c)
{
if (c <= '9')
return c - '0' + 26;
@@ -914,7 +973,8 @@ struct puny_state {
unsigned k;
};
-static void puny_init(struct puny_state *st, unsigned numpoints)
+static void
+puny_init(struct puny_state *st, unsigned numpoints)
{
st->ascii_numpoints = numpoints;
st->numpoints = numpoints;
@@ -922,7 +982,8 @@ static void puny_init(struct puny_state *st, unsigned numpoints)
st->k = puny_base;
}
-static unsigned puny_threshold(struct puny_state *st)
+static unsigned
+puny_threshold(struct puny_state *st)
{
unsigned k = st->k;
st->k += puny_base;
@@ -933,7 +994,8 @@ static unsigned puny_threshold(struct puny_state *st)
return k - st->bias;
}
-static void puny_adapt(struct puny_state *st, unsigned val)
+static void
+puny_adapt(struct puny_state *st, unsigned val)
{
unsigned k;
val = st->ascii_numpoints == st->numpoints ? val / puny_damp : val / 2;
@@ -944,11 +1006,13 @@ static void puny_adapt(struct puny_state *st, unsigned val)
val /= puny_base - puny_tmin;
k += puny_base;
}
- st->bias = k + (((puny_base - puny_tmin + 1) * val) / (val + puny_skew));
+ st->bias =
+ k + (((puny_base - puny_tmin + 1) * val) / (val + puny_skew));
st->k = puny_base;
}
-static unsigned char *puny_encode(unsigned char *s, int len)
+static unsigned char *
+puny_encode(unsigned char *s, int len)
{
unsigned char *p;
unsigned *uni;
@@ -963,7 +1027,7 @@ static unsigned char *puny_encode(unsigned char *s, int len)
goto err;
uni = xmalloc(len * sizeof(unsigned));
uni_l = 0;
- for (p = s; p < s + len; ) {
+ for (p = s; p < s + len;) {
unsigned c;
GET_UTF_8(p, c);
c = uni_locase(c);
@@ -1024,12 +1088,16 @@ static unsigned char *puny_encode(unsigned char *s, int len)
while (1) {
unsigned t = puny_threshold(&st);
if (n < t) {
- add_chr_to_str(&res, &res_l, puny_chrenc(n));
+ add_chr_to_str(&res, &res_l,
+ puny_chrenc(n));
break;
} else {
- unsigned d = (n - t) % (puny_base - t);
+ unsigned d =
+ (n - t) % (puny_base - t);
n = (n - t) / (puny_base - t);
- add_chr_to_str(&res, &res_l, puny_chrenc(d + t));
+ add_chr_to_str(
+ &res, &res_l,
+ puny_chrenc(d + t));
}
}
puny_adapt(&st, skip);
@@ -1054,7 +1122,8 @@ err:
return NULL;
}
-static unsigned char *puny_decode(unsigned char *s, int len)
+static unsigned char *
+puny_decode(unsigned char *s, int len)
{
unsigned char *p, *last_dash;
unsigned *uni;
@@ -1135,7 +1204,8 @@ static unsigned char *puny_decode(unsigned char *s, int len)
goto err_free_uni;
}
pos += val;
- memmove(uni + pos + 1, uni + pos, (uni_l - pos) * sizeof(unsigned));
+ memmove(uni + pos + 1, uni + pos,
+ (uni_l - pos) * sizeof(unsigned));
uni[pos++] = cchar;
uni_l++;
}
@@ -1158,7 +1228,9 @@ err:
return NULL;
}
-unsigned char *idn_encode_host(unsigned char *host, int len, unsigned char *separator, int decode)
+unsigned char *
+idn_encode_host(unsigned char *host, int len, unsigned char *separator,
+ int decode)
{
unsigned char *p, *s;
int pl, l, i;
@@ -1208,12 +1280,14 @@ err:
return NULL;
}
-unsigned char *idn_encode_url(unsigned char *url, int decode)
+unsigned char *
+idn_encode_url(unsigned char *url, int decode)
{
unsigned char *host, *p, *h;
int holen, pl;
if (parse_url(url, NULL, NULL, NULL, NULL, NULL, &host, &holen, NULL,
- NULL, NULL, NULL, NULL) || !host) {
+ NULL, NULL, NULL, NULL)
+ || !host) {
host = url;
holen = 0;
}
@@ -1231,7 +1305,9 @@ unsigned char *idn_encode_url(unsigned char *url, int decode)
return p;
}
-static unsigned char *display_url_or_host(struct terminal *term, unsigned char *url, int warn_idn, int just_host, unsigned char *separator)
+static unsigned char *
+display_url_or_host(struct terminal *term, unsigned char *url, int warn_idn,
+ int just_host, unsigned char *separator)
{
unsigned char *uu, *url_dec, *url_conv, *url_conv2, *url_enc, *ret;
int is_idn;
@@ -1250,7 +1326,8 @@ static unsigned char *display_url_or_host(struct terminal *term, unsigned char *
if (!just_host)
url_dec = idn_encode_url(url, 1);
else
- url_dec = idn_encode_host(url, (int)strlen((char *)url), separator, 1);
+ url_dec = idn_encode_host(url, (int)strlen((char *)url),
+ separator, 1);
is_idn = strcmp((char *)url_dec, (char *)url);
url_conv = convert(0, term_charset(term), url_dec, NULL);
free(url_dec);
@@ -1258,7 +1335,8 @@ static unsigned char *display_url_or_host(struct terminal *term, unsigned char *
if (!just_host)
url_enc = idn_encode_url(url_conv2, 0);
else
- url_enc = idn_encode_host(url_conv2, (int)strlen((char *)url_conv2), separator, 0);
+ url_enc = idn_encode_host(
+ url_conv2, (int)strlen((char *)url_conv2), separator, 0);
if (!url_enc) {
url_enc = stracpy(url_conv2);
is_idn = 1;
@@ -1280,17 +1358,20 @@ static unsigned char *display_url_or_host(struct terminal *term, unsigned char *
return ret;
}
-unsigned char *display_url(struct terminal *term, unsigned char *url, int warn_idn)
+unsigned char *
+display_url(struct terminal *term, unsigned char *url, int warn_idn)
{
return display_url_or_host(term, url, warn_idn, 0, cast_uchar ".");
}
-unsigned char *display_host(struct terminal *term, unsigned char *host)
+unsigned char *
+display_host(struct terminal *term, unsigned char *host)
{
return display_url_or_host(term, host, 1, 1, cast_uchar ".");
}
-unsigned char *display_host_list(struct terminal *term, unsigned char *host)
+unsigned char *
+display_host_list(struct terminal *term, unsigned char *host)
{
return display_url_or_host(term, host, 0, 1, cast_uchar ".,");
}
diff --git a/view.c b/view.c
@@ -17,11 +17,14 @@ static void find_link(struct f_data_c *, int, int);
static int is_active_frame(struct session *ses, struct f_data_c *f);
-static void send_open_in_new_xterm(struct terminal *term, void *open_window_, void *ses_);
-static void (* const send_open_in_new_xterm_ptr)(struct terminal *, void *fn_, void *ses_) = send_open_in_new_xterm;
+static void send_open_in_new_xterm(struct terminal *term, void *open_window_,
+ void *ses_);
+static void (*const send_open_in_new_xterm_ptr)(
+ struct terminal *, void *fn_, void *ses_) = send_open_in_new_xterm;
/* FIXME: remove */
-static void free_format_text_cache_entry(struct form_state *fs)
+static void
+free_format_text_cache_entry(struct form_state *fs)
{
struct format_text_cache_entry *ftce = fs->ftce;
if (!ftce)
@@ -30,7 +33,8 @@ static void free_format_text_cache_entry(struct form_state *fs)
free(ftce);
}
-struct view_state *create_vs(void)
+struct view_state *
+create_vs(void)
{
struct view_state *vs;
vs = mem_calloc(sizeof(struct view_state));
@@ -45,18 +49,21 @@ struct view_state *create_vs(void)
}
/* FIXME: remove */
-static void free_form_state(struct form_state *fs)
+static void
+free_form_state(struct form_state *fs)
{
free_format_text_cache_entry(fs);
if (fs->string)
free(fs->string);
}
-void destroy_vs(struct view_state *vs)
+void
+destroy_vs(struct view_state *vs)
{
int i;
if (--vs->refcount) {
- if (vs->refcount < 0) internal("destroy_vs: view_state refcount underflow");
+ if (vs->refcount < 0)
+ internal("destroy_vs: view_state refcount underflow");
return;
}
for (i = 0; i < vs->form_info_len; i++) {
@@ -68,14 +75,17 @@ void destroy_vs(struct view_state *vs)
free(vs);
}
-void check_vs(struct f_data_c *f)
+void
+check_vs(struct f_data_c *f)
{
struct view_state *vs = f->vs;
int ovx, ovy, ol, obx, oby;
if (f->f_data->frame_desc) {
int n = (int)list_size(&f->subframes);
- if (vs->frame_pos < 0) vs->frame_pos = 0;
- if (vs->frame_pos >= n) vs->frame_pos = n - 1;
+ if (vs->frame_pos < 0)
+ vs->frame_pos = 0;
+ if (vs->frame_pos >= n)
+ vs->frame_pos = n - 1;
return;
}
ovx = f->vs->orig_view_posx;
@@ -83,7 +93,8 @@ void check_vs(struct f_data_c *f)
ol = f->vs->orig_link;
obx = f->vs->orig_brl_x;
oby = f->vs->orig_brl_y;
- if (vs->current_link >= f->f_data->nlinks) vs->current_link = f->f_data->nlinks - 1;
+ if (vs->current_link >= f->f_data->nlinks)
+ vs->current_link = f->f_data->nlinks - 1;
if (vs->current_link != -1 && !c_in_view(f)) {
set_pos_x(f, &f->f_data->links[f->vs->current_link]);
set_pos_y(f, &f->f_data->links[f->vs->current_link]);
@@ -97,13 +108,16 @@ void check_vs(struct f_data_c *f)
f->vs->orig_brl_y = oby;
}
-static void set_link(struct f_data_c *f)
+static void
+set_link(struct f_data_c *f)
{
- if (c_in_view(f)) return;
+ if (c_in_view(f))
+ return;
find_link(f, 1, 0);
}
-static int find_tag(struct f_data *f, unsigned char *name)
+static int
+find_tag(struct f_data *f, unsigned char *name)
{
struct tag *tag = NULL;
struct list_head *ltag;
@@ -112,40 +126,48 @@ static int find_tag(struct f_data *f, unsigned char *name)
tt = init_str();
ll = 0;
add_conv_str(&tt, &ll, name, (int)strlen(cast_const_char name), -2);
- foreachback(struct tag, tag, ltag, f->tags) if (!casestrcmp(tag->name, tt) || (tag->name[0] == '#' && !casestrcmp(tag->name + 1, tt))) {
- free(tt);
- return tag->y;
- }
+ foreachback (struct tag, tag, ltag, f->tags)
+ if (!casestrcmp(tag->name, tt)
+ || (tag->name[0] == '#'
+ && !casestrcmp(tag->name + 1, tt))) {
+ free(tt);
+ return tag->y;
+ }
free(tt);
return -1;
}
-static int comp_links(const void *l1_, const void *l2_)
+static int
+comp_links(const void *l1_, const void *l2_)
{
const struct link *l1 = (const struct link *)l1_;
const struct link *l2 = (const struct link *)l2_;
return l1->num - l2->num;
}
-void sort_links(struct f_data *f)
+void
+sort_links(struct f_data *f)
{
int i;
if (f->nlinks)
qsort(f->links, f->nlinks, sizeof(struct link), comp_links);
- if ((unsigned)f->y > INT_MAX / sizeof(struct link *)) overalloc();
+ if ((unsigned)f->y > INT_MAX / sizeof(struct link *))
+ overalloc();
f->lines1 = mem_calloc(f->y * sizeof(struct link *));
f->lines2 = mem_calloc(f->y * sizeof(struct link *));
for (i = 0; i < f->nlinks; i++) {
int p, q, j;
struct link *link = &f->links[i];
if (!link->n) {
- if (d_opt->num_links) continue;
+ if (d_opt->num_links)
+ continue;
free(link->where);
free(link->target);
free(link->where_img);
free(link->img_alt);
free(link->pos);
- memmove(link, link + 1, (f->nlinks - i - 1) * sizeof(struct link));
+ memmove(link, link + 1,
+ (f->nlinks - i - 1) * sizeof(struct link));
f->nlinks--;
i--;
continue;
@@ -153,8 +175,10 @@ void sort_links(struct f_data *f)
p = f->y - 1;
q = 0;
for (j = 0; j < link->n; j++) {
- if (link->pos[j].y < p) p = link->pos[j].y;
- if (link->pos[j].y > q) q = link->pos[j].y;
+ if (link->pos[j].y < p)
+ p = link->pos[j].y;
+ if (link->pos[j].y > q)
+ q = link->pos[j].y;
}
if (p > q) {
j = p;
@@ -167,23 +191,28 @@ void sort_links(struct f_data *f)
continue;
}
f->lines2[j] = &f->links[i];
- if (!f->lines1[j]) f->lines1[j] = &f->links[i];
+ if (!f->lines1[j])
+ f->lines1[j] = &f->links[i];
}
}
}
-unsigned char *textptr_add(unsigned char *t, int i, int cp)
+unsigned char *
+textptr_add(unsigned char *t, int i, int cp)
{
if (cp) {
- if (i) t += strnlen(cast_const_char t, i);
+ if (i)
+ t += strnlen(cast_const_char t, i);
return t;
} else {
- while (i-- && *t) FWD_UTF_8(t);
+ while (i-- && *t)
+ FWD_UTF_8(t);
return t;
}
}
-int textptr_diff(unsigned char *t2, unsigned char *t1, int cp)
+int
+textptr_diff(unsigned char *t2, unsigned char *t1, int cp)
{
if (cp)
return (int)(t2 - t1);
@@ -197,7 +226,8 @@ int textptr_diff(unsigned char *t2, unsigned char *t1, int cp)
}
}
-static struct format_text_cache_entry *format_text_uncached(unsigned char *text, int width, int wrap, int cp)
+static struct format_text_cache_entry *
+format_text_uncached(unsigned char *text, int width, int wrap, int cp)
{
unsigned char *text_start = text;
struct format_text_cache_entry *ftce;
@@ -209,7 +239,9 @@ static struct format_text_cache_entry *format_text_uncached(unsigned char *text,
unsigned char *last_space = NULL;
int last_space_xpos = 0;
- ftce = xmalloc(sizeof(struct format_text_cache_entry) - sizeof(struct line_info) + lnn_allocated * sizeof(struct line_info));
+ ftce = xmalloc(sizeof(struct format_text_cache_entry)
+ - sizeof(struct line_info)
+ + lnn_allocated * sizeof(struct line_info));
ftce->width = width;
ftce->wrap = wrap;
@@ -219,11 +251,17 @@ static struct format_text_cache_entry *format_text_uncached(unsigned char *text,
while (*text) {
if (*text == '\n') {
sk = 1;
- put:
+put:
if (lnn == lnn_allocated) {
- if ((unsigned)lnn_allocated > INT_MAX / sizeof(struct line_info) - ALLOC_GR)
+ if ((unsigned)lnn_allocated
+ > INT_MAX / sizeof(struct line_info)
+ - ALLOC_GR)
overalloc();
- ftce = xrealloc(ftce, sizeof(struct format_text_cache_entry) - sizeof(struct line_info) + lnn_allocated * sizeof(struct line_info));
+ ftce = xrealloc(
+ ftce, sizeof(struct format_text_cache_entry)
+ - sizeof(struct line_info)
+ + lnn_allocated
+ * sizeof(struct line_info));
}
ftce->ln[lnn].st_offs = (int)(b - text_start);
ftce->ln[lnn].en_offs = (int)(text - text_start);
@@ -240,7 +278,8 @@ static struct format_text_cache_entry *format_text_uncached(unsigned char *text,
if (!wrap || xpos < width) {
if (cp)
text++;
- else FWD_UTF_8(text);
+ else
+ FWD_UTF_8(text);
xpos++;
continue;
}
@@ -250,10 +289,12 @@ static struct format_text_cache_entry *format_text_uncached(unsigned char *text,
if (wrap == 2) {
unsigned char *s = last_space;
*s = '\n';
- for (s++; *s; s++) if (*s == '\n') {
- if (s[1] != '\n') *s = ' ';
- break;
- }
+ for (s++; *s; s++)
+ if (*s == '\n') {
+ if (s[1] != '\n')
+ *s = ' ';
+ break;
+ }
}
sk = 1;
goto put;
@@ -270,16 +311,18 @@ static struct format_text_cache_entry *format_text_uncached(unsigned char *text,
return ftce;
}
-struct format_text_cache_entry *format_text(struct f_data_c *fd, struct form_control *fc, struct form_state *fs)
+struct format_text_cache_entry *
+format_text(struct f_data_c *fd, struct form_control *fc, struct form_state *fs)
{
int width = fc->cols;
int wrap = fc->wrap;
int cp = fd->f_data->opt.cp;
struct format_text_cache_entry *ftce = fs->ftce;
- if (ftce && ftce->width == width && ftce->wrap == wrap && ftce->cp == cp)
+ if (ftce && ftce->width == width && ftce->wrap == wrap
+ && ftce->cp == cp)
return fs->ftce;
-
+
free_format_text_cache_entry(fs);
ftce = format_text_uncached(fs->string, width, wrap, cp);
@@ -287,10 +330,13 @@ struct format_text_cache_entry *format_text(struct f_data_c *fd, struct form_con
return ftce;
}
-static int find_cursor_line(struct format_text_cache_entry *ftce, int state)
+static int
+find_cursor_line(struct format_text_cache_entry *ftce, int state)
{
int res;
-#define LINE_EQ(x, key) (key >= ftce->ln[x].st_offs && (x >= ftce->n_lines - 1 || key < ftce->ln[x + 1].st_offs))
+#define LINE_EQ(x, key) \
+ (key >= ftce->ln[x].st_offs \
+ && (x >= ftce->n_lines - 1 || key < ftce->ln[x + 1].st_offs))
#define LINE_ABOVE(x, key) (key < ftce->ln[x].st_offs)
BIN_SEARCH(ftce->n_lines, LINE_EQ, LINE_ABOVE, state, res);
#undef LINE_EQ
@@ -298,28 +344,37 @@ static int find_cursor_line(struct format_text_cache_entry *ftce, int state)
return res;
}
-int area_cursor(struct f_data_c *f, struct form_control *fc, struct form_state *fs)
+int
+area_cursor(struct f_data_c *f, struct form_control *fc, struct form_state *fs)
{
struct format_text_cache_entry *ftce;
int q = 0;
int x, y;
ftce = format_text(f, fc, fs);
- if (ftce->last_state == fs->state && ftce->last_vpos == fs->vpos && ftce->last_vypos == fs->vypos)
+ if (ftce->last_state == fs->state && ftce->last_vpos == fs->vpos
+ && ftce->last_vypos == fs->vypos)
return fs->ftce->last_cursor;
y = find_cursor_line(ftce, fs->state);
if (y >= 0) {
- x = textptr_diff(fs->string + fs->state, fs->string + ftce->ln[y].st_offs, f->f_data->opt.cp);
- if (fc->wrap && x == fc->cols) x--;
+ x = textptr_diff(fs->string + fs->state,
+ fs->string + ftce->ln[y].st_offs,
+ f->f_data->opt.cp);
+ if (fc->wrap && x == fc->cols)
+ x--;
- if (x >= fc->cols + fs->vpos) fs->vpos = x - fc->cols + 1;
- if (x < fs->vpos) fs->vpos = x;
+ if (x >= fc->cols + fs->vpos)
+ fs->vpos = x - fc->cols + 1;
+ if (x < fs->vpos)
+ fs->vpos = x;
if (fs->vypos > ftce->n_lines - fc->rows) {
fs->vypos = ftce->n_lines - fc->rows;
- if (fs->vypos < 0) fs->vypos = 0;
+ if (fs->vypos < 0)
+ fs->vypos = 0;
}
- if (y < fs->vypos) fs->vypos = y;
+ if (y < fs->vypos)
+ fs->vypos = y;
x -= fs->vpos;
y -= fs->vypos;
q = y * fc->cols + x;
@@ -331,7 +386,8 @@ int area_cursor(struct f_data_c *f, struct form_control *fc, struct form_state *
return q;
}
-static void draw_link(struct terminal *t, struct f_data_c *scr, int l)
+static void
+draw_link(struct terminal *t, struct f_data_c *scr, int l)
{
struct link *link = &scr->f_data->links[l];
int xp = scr->xp;
@@ -347,85 +403,106 @@ static void draw_link(struct terminal *t, struct f_data_c *scr, int l)
internal("link background not empty");
free(scr->link_bg);
}
- if (l == -1) return;
+ if (l == -1)
+ return;
switch (link->type) {
int i;
int q;
- case L_LINK:
- case L_CHECKBOX:
- case L_BUTTON:
- case L_SELECT:
- case L_FIELD:
- case L_AREA:
- q = 0;
- if (link->type == L_FIELD) {
- struct form_state *fs = find_form_state(scr, link->form);
- q = textptr_diff(fs->string + fs->state, fs->string + fs->vpos, scr->f_data->opt.cp);
- } else if (link->type == L_AREA) {
- struct form_state *fs = find_form_state(scr, link->form);
- q = area_cursor(scr, link->form, fs);
- }
- if ((unsigned)link->n > INT_MAX / sizeof(struct link_bg)) overalloc();
- scr->link_bg = xmalloc(link->n * sizeof(struct link_bg));
- scr->link_bg_n = link->n;
- for (i = 0; i < link->n; i++) {
- int x = link->pos[i].x + xp - vx;
- int y = link->pos[i].y + yp - vy;
- if (x >= xp && y >= yp && x < xp+xw && y < yp+yw) {
- const chr *co;
- co = get_char(t, x, y);
- scr->link_bg[i].x = x;
- scr->link_bg[i].y = y;
- scr->link_bg[i].c = co->at;
- if (!f || (link->type == L_CHECKBOX && i == 1) || (link->type == L_BUTTON && i == 2) || ((link->type == L_FIELD || link->type == L_AREA) && i == q)) {
- int xx = x, yy = y;
- if (link->type != L_FIELD && link->type != L_AREA) {
- if ((unsigned)(co->at & 0x38) != (link->sel_color & 0x38)) {
- xx = xp + xw - 1;
- yy = yp + yw - 1;
- }
+ case L_LINK:
+ case L_CHECKBOX:
+ case L_BUTTON:
+ case L_SELECT:
+ case L_FIELD:
+ case L_AREA:
+ q = 0;
+ if (link->type == L_FIELD) {
+ struct form_state *fs =
+ find_form_state(scr, link->form);
+ q = textptr_diff(fs->string + fs->state,
+ fs->string + fs->vpos,
+ scr->f_data->opt.cp);
+ } else if (link->type == L_AREA) {
+ struct form_state *fs =
+ find_form_state(scr, link->form);
+ q = area_cursor(scr, link->form, fs);
+ }
+ if ((unsigned)link->n > INT_MAX / sizeof(struct link_bg))
+ overalloc();
+ scr->link_bg = xmalloc(link->n * sizeof(struct link_bg));
+ scr->link_bg_n = link->n;
+ for (i = 0; i < link->n; i++) {
+ int x = link->pos[i].x + xp - vx;
+ int y = link->pos[i].y + yp - vy;
+ if (x >= xp && y >= yp && x < xp + xw && y < yp + yw) {
+ const chr *co;
+ co = get_char(t, x, y);
+ scr->link_bg[i].x = x;
+ scr->link_bg[i].y = y;
+ scr->link_bg[i].c = co->at;
+ if (!f || (link->type == L_CHECKBOX && i == 1)
+ || (link->type == L_BUTTON && i == 2)
+ || ((link->type == L_FIELD
+ || link->type == L_AREA)
+ && i == q)) {
+ int xx = x, yy = y;
+ if (link->type != L_FIELD
+ && link->type != L_AREA) {
+ if ((unsigned)(co->at & 0x38)
+ != (link->sel_color
+ & 0x38)) {
+ xx = xp + xw - 1;
+ yy = yp + yw - 1;
}
- set_cursor(t, x, y, xx, yy);
- set_window_ptr(scr->ses->win, x, y);
- f = 1;
}
- set_color(t, x, y, link->sel_color);
- } else {
- scr->link_bg[i].x = scr->link_bg[i].y = -1;
- scr->link_bg[i].c = 0;
+ set_cursor(t, x, y, xx, yy);
+ set_window_ptr(scr->ses->win, x, y);
+ f = 1;
}
+ set_color(t, x, y, link->sel_color);
+ } else {
+ scr->link_bg[i].x = scr->link_bg[i].y = -1;
+ scr->link_bg[i].c = 0;
}
- break;
- default: internal("bad link type");
+ }
+ break;
+ default:
+ internal("bad link type");
}
}
-static void free_link(struct f_data_c *scr)
+static void
+free_link(struct f_data_c *scr)
{
free(scr->link_bg);
scr->link_bg = NULL;
scr->link_bg_n = 0;
}
-static void clear_link(struct terminal *t, struct f_data_c *scr)
+static void
+clear_link(struct terminal *t, struct f_data_c *scr)
{
if (scr->link_bg) {
int i;
for (i = scr->link_bg_n - 1; i >= 0; i--)
- set_color(t, scr->link_bg[i].x, scr->link_bg[i].y, scr->link_bg[i].c);
+ set_color(t, scr->link_bg[i].x, scr->link_bg[i].y,
+ scr->link_bg[i].c);
free_link(scr);
}
}
-static struct search *search_lookup(struct f_data *f, int idx)
+static struct search *
+search_lookup(struct f_data *f, int idx)
{
static struct search sr;
int result;
-#define S_EQUAL(i, id) (f->search_pos[i].idx <= id && f->search_pos[i].idx + f->search_pos[i].co > id)
+#define S_EQUAL(i, id) \
+ (f->search_pos[i].idx <= id \
+ && f->search_pos[i].idx + f->search_pos[i].co > id)
#define S_ABOVE(i, id) (f->search_pos[i].idx > id)
BIN_SEARCH(f->nsearch_pos, S_EQUAL, S_ABOVE, idx, result)
if (result == -1)
- internal("search_lookup: invalid index: %d, %d", idx, f->nsearch_chr);
+ internal("search_lookup: invalid index: %d, %d", idx,
+ f->nsearch_chr);
if (idx == f->search_pos[result].idx)
return &f->search_pos[result];
memcpy(&sr, &f->search_pos[result], sizeof(struct search));
@@ -433,30 +510,42 @@ static struct search *search_lookup(struct f_data *f, int idx)
return &sr;
}
-static int get_range(struct f_data *f, int y, int yw, int l, int *s1, int *s2)
+static int
+get_range(struct f_data *f, int y, int yw, int l, int *s1, int *s2)
{
int i;
*s1 = *s2 = -1;
for (i = y < 0 ? 0 : y; i < y + yw && i < f->y; i++) {
- if (f->slines1[i] >= 0 && (*s1 < 0 || f->slines1[i] < *s1)) *s1 = f->slines1[i];
- if (f->slines2[i] >= 0 && (*s2 < 0 || f->slines2[i] > *s2)) *s2 = f->slines2[i];
+ if (f->slines1[i] >= 0 && (*s1 < 0 || f->slines1[i] < *s1))
+ *s1 = f->slines1[i];
+ if (f->slines2[i] >= 0 && (*s2 < 0 || f->slines2[i] > *s2))
+ *s2 = f->slines2[i];
}
- if (l > f->nsearch_chr) *s1 = *s2 = -1;
- if (*s1 < 0 || *s2 < 0) return -1;
+ if (l > f->nsearch_chr)
+ *s1 = *s2 = -1;
+ if (*s1 < 0 || *s2 < 0)
+ return -1;
- if (*s1 < l) *s1 = 0;
- else *s1 -= l;
+ if (*s1 < l)
+ *s1 = 0;
+ else
+ *s1 -= l;
- if (f->nsearch_chr - *s2 < l) *s2 = f->nsearch_chr - l;
+ if (f->nsearch_chr - *s2 < l)
+ *s2 = f->nsearch_chr - l;
- if (*s1 > *s2) *s1 = *s2 = -1;
- if (*s1 < 0 || *s2 < 0) return -1;
+ if (*s1 > *s2)
+ *s1 = *s2 = -1;
+ if (*s1 < 0 || *s2 < 0)
+ return -1;
return 0;
}
-static int is_in_range(struct f_data *f, int y, int yw, unsigned char *txt, int *min, int *max)
+static int
+is_in_range(struct f_data *f, int y, int yw, unsigned char *txt, int *min,
+ int *max)
{
int utf8 = f->opt.cp == 0;
int found = 0;
@@ -488,7 +577,8 @@ static int is_in_range(struct f_data *f, int y, int yw, unsigned char *txt, int
}
for (i = 0; i < l; i++) {
struct search *sr = search_lookup(f, s1 + i);
- if (sr->y >= y && sr->y < y + yw && sr->n) goto in_view;
+ if (sr->y >= y && sr->y < y + yw && sr->n)
+ goto in_view;
}
continue;
in_view:
@@ -507,7 +597,8 @@ cont:;
return found;
}
-static int get_searched(struct f_data_c *scr, struct point **pt, int *pl)
+static int
+get_searched(struct f_data_c *scr, struct point **pt, int *pl)
{
int utf8 = term_charset(scr->ses->term) == 0;
struct f_data *f = scr->f_data;
@@ -560,13 +651,20 @@ c:
for (j = 0; j < sr->n; j++) {
int x = sr->x + j + xp - vx;
int y = sr->y + yp - vy;
- if (x >= xp && y >= yp && x < xp + xw && y < yp + yw) {
+ if (x >= xp && y >= yp && x < xp + xw
+ && y < yp + yw) {
if (!(len & (ALLOC_GR - 1))) {
struct point *points2;
- if ((unsigned)len > INT_MAX / sizeof(struct point) - ALLOC_GR)
+ if ((unsigned)len
+ > INT_MAX
+ / sizeof(
+ struct point)
+ - ALLOC_GR)
goto ret;
- points2 = xrealloc(points,
- sizeof(struct point) * (len + ALLOC_GR));
+ points2 = xrealloc(
+ points,
+ sizeof(struct point)
+ * (len + ALLOC_GR));
if (!points2)
goto ret;
points = points2;
@@ -583,7 +681,8 @@ ret:
return 0;
}
-static void draw_searched(struct terminal *t, struct f_data_c *scr)
+static void
+draw_searched(struct terminal *t, struct f_data_c *scr)
{
int xp = scr->xp;
int yp = scr->yp;
@@ -591,7 +690,8 @@ static void draw_searched(struct terminal *t, struct f_data_c *scr)
int vy = scr->vs->view_pos;
struct point *pt;
int len, i;
- if (get_searched(scr, &pt, &len) < 0) return;
+ if (get_searched(scr, &pt, &len) < 0)
+ return;
for (i = 0; i < len; i++) {
int x = pt[i].x + xp - vx, y = pt[i].y + yp - vy;
const chr *co;
@@ -603,41 +703,52 @@ static void draw_searched(struct terminal *t, struct f_data_c *scr)
free(pt);
}
-static void draw_current_link(struct terminal *t, struct f_data_c *scr)
+static void
+draw_current_link(struct terminal *t, struct f_data_c *scr)
{
draw_link(t, scr, scr->vs->current_link);
draw_searched(t, scr);
}
-static struct link *get_first_link(struct f_data_c *f)
+static struct link *
+get_first_link(struct f_data_c *f)
{
int i;
struct link *l = f->f_data->links + f->f_data->nlinks;
for (i = f->vs->view_pos; i < f->vs->view_pos + f->yw; i++)
- if (i >= 0 && i < f->f_data->y && f->f_data->lines1[i] && f->f_data->lines1[i] < l)
+ if (i >= 0 && i < f->f_data->y && f->f_data->lines1[i]
+ && f->f_data->lines1[i] < l)
l = f->f_data->lines1[i];
- if (l == f->f_data->links + f->f_data->nlinks) l = NULL;
+ if (l == f->f_data->links + f->f_data->nlinks)
+ l = NULL;
return l;
}
-static struct link *get_last_link(struct f_data_c *f)
+static struct link *
+get_last_link(struct f_data_c *f)
{
int i;
struct link *l = NULL;
for (i = f->vs->view_pos; i < f->vs->view_pos + f->yw; i++)
- if (i >= 0 && i < f->f_data->y && f->f_data->lines2[i] && (!l || f->f_data->lines2[i] > l))
+ if (i >= 0 && i < f->f_data->y && f->f_data->lines2[i]
+ && (!l || f->f_data->lines2[i] > l))
l = f->f_data->lines2[i];
return l;
}
-void fixup_select_state(struct form_control *fc, struct form_state *fs)
+void
+fixup_select_state(struct form_control *fc, struct form_state *fs)
{
int inited = 0;
int i;
- retry:
- if (fs->state >= 0 && fs->state < fc->nvalues && !strcmp(cast_const_char fc->values[fs->state], cast_const_char fs->string)) return;
+retry:
+ if (fs->state >= 0 && fs->state < fc->nvalues
+ && !strcmp(cast_const_char fc->values[fs->state],
+ cast_const_char fs->string))
+ return;
for (i = 0; i < fc->nvalues; i++) {
- if (!strcmp(cast_const_char fc->values[i], cast_const_char fs->string)) {
+ if (!strcmp(cast_const_char fc->values[i],
+ cast_const_char fs->string)) {
fs->state = i;
return;
}
@@ -649,40 +760,44 @@ void fixup_select_state(struct form_control *fc, struct form_state *fs)
}
fs->state = 0;
free(fs->string);
- if (fc->nvalues) fs->string = stracpy(fc->values[0]);
- else fs->string = stracpy(cast_uchar "");
+ if (fc->nvalues)
+ fs->string = stracpy(fc->values[0]);
+ else
+ fs->string = stracpy(cast_uchar "");
}
-static void init_ctrl(struct form_control *form, struct form_state *fs)
+static void
+init_ctrl(struct form_control *form, struct form_state *fs)
{
free(fs->string);
fs->string = NULL;
switch (form->type) {
- case FC_TEXT:
- case FC_PASSWORD:
- case FC_TEXTAREA:
- fs->string = stracpy(form->default_value);
- fs->state = (int)strlen(cast_const_char form->default_value);
- fs->vpos = 0;
- break;
- case FC_FILE_UPLOAD:
- fs->string = stracpy(cast_uchar "");
- fs->state = 0;
- fs->vpos = 0;
- break;
- case FC_CHECKBOX:
- case FC_RADIO:
- fs->state = form->default_state;
- break;
- case FC_SELECT:
- fs->string = stracpy(form->default_value);
- fs->state = form->default_state;
- fixup_select_state(form, fs);
- break;
+ case FC_TEXT:
+ case FC_PASSWORD:
+ case FC_TEXTAREA:
+ fs->string = stracpy(form->default_value);
+ fs->state = (int)strlen(cast_const_char form->default_value);
+ fs->vpos = 0;
+ break;
+ case FC_FILE_UPLOAD:
+ fs->string = stracpy(cast_uchar "");
+ fs->state = 0;
+ fs->vpos = 0;
+ break;
+ case FC_CHECKBOX:
+ case FC_RADIO:
+ fs->state = form->default_state;
+ break;
+ case FC_SELECT:
+ fs->string = stracpy(form->default_value);
+ fs->state = form->default_state;
+ fixup_select_state(form, fs);
+ break;
}
}
-struct form_state *find_form_state(struct f_data_c *f, struct form_control *form)
+struct form_state *
+find_form_state(struct f_data_c *f, struct form_control *form)
{
struct view_state *vs = f->vs;
struct form_state *fs;
@@ -692,13 +807,18 @@ struct form_state *find_form_state(struct f_data_c *f, struct form_control *form
else {
if ((unsigned)n > INT_MAX / sizeof(struct form_state) - 1)
overalloc();
- fs = xrealloc(vs->form_info, (n + 1) * sizeof(struct form_state));
+ fs = xrealloc(vs->form_info,
+ (n + 1) * sizeof(struct form_state));
vs->form_info = fs;
- memset(fs + vs->form_info_len, 0, (n + 1 - vs->form_info_len) * sizeof(struct form_state));
+ memset(fs + vs->form_info_len, 0,
+ (n + 1 - vs->form_info_len) * sizeof(struct form_state));
vs->form_info_len = n + 1;
fs = &vs->form_info[n];
}
- if (fs->form_num == form->form_num && fs->ctrl_num == form->ctrl_num && fs->g_ctrl_num == form->g_ctrl_num && /*fs->position == form->position &&*/ fs->type == form->type) return fs;
+ if (fs->form_num == form->form_num && fs->ctrl_num == form->ctrl_num
+ && fs->g_ctrl_num == form->g_ctrl_num
+ && /*fs->position == form->position &&*/ fs->type == form->type)
+ return fs;
free_form_state(fs);
memset(fs, 0, sizeof(struct form_state));
fs->form_num = form->form_num;
@@ -710,7 +830,8 @@ struct form_state *find_form_state(struct f_data_c *f, struct form_control *form
return fs;
}
-static void draw_form_entry(struct terminal *t, struct f_data_c *f, struct link *l)
+static void
+draw_form_entry(struct terminal *t, struct f_data_c *f, struct link *l)
{
int xp = f->xp;
int yp = f->yp;
@@ -734,30 +855,66 @@ static void draw_form_entry(struct terminal *t, struct f_data_c *f, struct link
struct format_text_cache_entry *ftce;
int lid;
- case FC_TEXT:
- case FC_PASSWORD:
- case FC_FILE_UPLOAD:
- if ((size_t)fs->vpos > strlen(cast_const_char fs->string)) fs->vpos = (int)strlen(cast_const_char fs->string);
- sl = strlen((char *)fs->string);
- td = textptr_diff(fs->string + fs->state, fs->string + fs->vpos, f->f_data->opt.cp);
-
- while (fs->vpos < sl && td >= form->size) {
- unsigned char *p = fs->string + fs->vpos;
- FWD_UTF_8(p);
- fs->vpos = (int)(p - fs->string);
- td--;
+ case FC_TEXT:
+ case FC_PASSWORD:
+ case FC_FILE_UPLOAD:
+ if ((size_t)fs->vpos > strlen(cast_const_char fs->string))
+ fs->vpos = (int)strlen(cast_const_char fs->string);
+ sl = strlen((char *)fs->string);
+ td = textptr_diff(fs->string + fs->state, fs->string + fs->vpos,
+ f->f_data->opt.cp);
+
+ while (fs->vpos < sl && td >= form->size) {
+ unsigned char *p = fs->string + fs->vpos;
+ FWD_UTF_8(p);
+ fs->vpos = (int)(p - fs->string);
+ td--;
+ }
+ while (fs->vpos > fs->state) {
+ unsigned char *p = fs->string + fs->vpos;
+ BACK_UTF_8(p, fs->string);
+ fs->vpos = (int)(p - fs->string);
+ }
+ if (!l->n)
+ break;
+ x = l->pos[0].x + xp - vx;
+ y = l->pos[0].y + yp - vy;
+ s = fs->string + fs->vpos;
+ for (i = 0; i < form->size; i++, x++) {
+ unsigned ch;
+ if (!*s) {
+ ch = '_';
+ } else {
+ if (f->f_data->opt.cp) {
+ ch = *s++;
+ } else {
+ GET_UTF_8(s, ch);
+ }
+ if (form->type == FC_PASSWORD) {
+ ch = '*';
+ }
}
- while (fs->vpos > fs->state) {
- unsigned char *p = fs->string + fs->vpos;
- BACK_UTF_8(p, fs->string);
- fs->vpos = (int)(p - fs->string);
+ if (x >= xp && y >= yp && x < xp + xw && y < yp + yw) {
+ set_only_char(t, x, y, ch, 0);
}
- if (!l->n) break;
- x = l->pos[0].x + xp - vx; y = l->pos[0].y + yp - vy;
- s = fs->string + fs->vpos;
- for (i = 0; i < form->size; i++, x++) {
+ }
+ break;
+ case FC_TEXTAREA:
+ if (!l->n)
+ break;
+ x = l->pos[0].x + xp - vx;
+ y = l->pos[0].y + yp - vy;
+ area_cursor(f, form, fs);
+ ftce = format_text(f, form, fs);
+ lid = fs->vypos;
+ for (; lid < ftce->n_lines
+ && y < l->pos[0].y + yp - vy + form->rows;
+ lid++, y++) {
+ s = textptr_add(fs->string, ftce->ln[lid].st_offs,
+ f->f_data->opt.cp);
+ for (i = 0; i < form->cols; i++) {
unsigned ch;
- if (!*s) {
+ if (s >= fs->string + ftce->ln[lid].en_offs) {
ch = '_';
} else {
if (f->f_data->opt.cp) {
@@ -765,87 +922,65 @@ static void draw_form_entry(struct terminal *t, struct f_data_c *f, struct link
} else {
GET_UTF_8(s, ch);
}
- if (form->type == FC_PASSWORD) {
- ch = '*';
- }
}
- if (x >= xp && y >= yp && x < xp+xw && y < yp+yw) {
- set_only_char(t, x, y, ch, 0);
- }
- }
- break;
- case FC_TEXTAREA:
- if (!l->n) break;
- x = l->pos[0].x + xp - vx; y = l->pos[0].y + yp - vy;
- area_cursor(f, form, fs);
- ftce = format_text(f, form, fs);
- lid = fs->vypos;
- for (; lid < ftce->n_lines && y < l->pos[0].y + yp - vy + form->rows; lid++, y++) {
- s = textptr_add(fs->string, ftce->ln[lid].st_offs, f->f_data->opt.cp);
- for (i = 0; i < form->cols; i++) {
- unsigned ch;
- if (s >= fs->string + ftce->ln[lid].en_offs) {
- ch = '_';
- } else {
- if (f->f_data->opt.cp) {
- ch = *s++;
- } else {
- GET_UTF_8(s, ch);
- }
- }
- if (x+i >= xp && y >= yp && x+i < xp+xw && y < yp+yw) {
- set_only_char(t, x+i, y, ch, 0);
- }
+ if (x + i >= xp && y >= yp && x + i < xp + xw
+ && y < yp + yw) {
+ set_only_char(t, x + i, y, ch, 0);
}
}
- for (; y < l->pos[0].y + yp - vy + form->rows; y++) {
- for (i = 0; i < form->cols; i++) {
- if (x+i >= xp && y >= yp && x+i < xp+xw && y < yp+yw)
- set_only_char(t, x+i, y, '_', 0);
- }
+ }
+ for (; y < l->pos[0].y + yp - vy + form->rows; y++) {
+ for (i = 0; i < form->cols; i++) {
+ if (x + i >= xp && y >= yp && x + i < xp + xw
+ && y < yp + yw)
+ set_only_char(t, x + i, y, '_', 0);
}
+ }
+ break;
+ case FC_CHECKBOX:
+ if (l->n < 2)
break;
- case FC_CHECKBOX:
- if (l->n < 2) break;
- x = l->pos[1].x + xp - vx;
- y = l->pos[1].y + yp - vy;
- if (x >= xp && y >= yp && x < xp+xw && y < yp+yw)
- set_only_char(t, x, y, fs->state ? 'X' : ' ', 0);
- break;
- case FC_RADIO:
- if (l->n < 2) break;
- x = l->pos[1].x + xp - vx;
- y = l->pos[1].y + yp - vy;
- if (x >= xp && y >= yp && x < xp+xw && y < yp+yw)
- set_only_char(t, x, y, fs->state ? 'X' : ' ', 0);
+ x = l->pos[1].x + xp - vx;
+ y = l->pos[1].y + yp - vy;
+ if (x >= xp && y >= yp && x < xp + xw && y < yp + yw)
+ set_only_char(t, x, y, fs->state ? 'X' : ' ', 0);
+ break;
+ case FC_RADIO:
+ if (l->n < 2)
break;
- case FC_SELECT:
- fixup_select_state(form, fs);
- s = fs->state < form->nvalues ? form->labels[fs->state] : NULL;
- if (!s) s = cast_uchar "";
- for (i = 0; i < l->n; i++) {
- unsigned chr;
- if (!*s) {
- chr = '_';
- } else {
- if (!term_charset(t)) {
- GET_UTF_8(s, chr);
- } else
+ x = l->pos[1].x + xp - vx;
+ y = l->pos[1].y + yp - vy;
+ if (x >= xp && y >= yp && x < xp + xw && y < yp + yw)
+ set_only_char(t, x, y, fs->state ? 'X' : ' ', 0);
+ break;
+ case FC_SELECT:
+ fixup_select_state(form, fs);
+ s = fs->state < form->nvalues ? form->labels[fs->state] : NULL;
+ if (!s)
+ s = cast_uchar "";
+ for (i = 0; i < l->n; i++) {
+ unsigned chr;
+ if (!*s) {
+ chr = '_';
+ } else {
+ if (!term_charset(t)) {
+ GET_UTF_8(s, chr);
+ } else
chr = *s++;
- }
- x = l->pos[i].x + xp - vx;
- y = l->pos[i].y + yp - vy;
- if (x >= xp && y >= yp && x < xp+xw && y < yp+yw)
- set_only_char(t, x, y, chr, 0);
}
- break;
- case FC_SUBMIT:
- case FC_IMAGE:
- case FC_RESET:
- case FC_HIDDEN:
- case FC_BUTTON:
- break;
+ x = l->pos[i].x + xp - vx;
+ y = l->pos[i].y + yp - vy;
+ if (x >= xp && y >= yp && x < xp + xw && y < yp + yw)
+ set_only_char(t, x, y, chr, 0);
+ }
+ break;
+ case FC_SUBMIT:
+ case FC_IMAGE:
+ case FC_RESET:
+ case FC_HIDDEN:
+ case FC_BUTTON:
+ break;
}
}
@@ -854,13 +989,15 @@ struct xdfe {
struct link *l;
};
-static void y_draw_form_entry(struct terminal *t, void *x_)
+static void
+y_draw_form_entry(struct terminal *t, void *x_)
{
struct xdfe *x = (struct xdfe *)x_;
draw_form_entry(t, x->f, x->l);
}
-static void x_draw_form_entry(struct session *ses, struct f_data_c *f, struct link *l)
+static void
+x_draw_form_entry(struct session *ses, struct f_data_c *f, struct link *l)
{
struct xdfe x;
x.f = f;
@@ -868,39 +1005,54 @@ static void x_draw_form_entry(struct session *ses, struct f_data_c *f, struct li
draw_to_window(ses->win, y_draw_form_entry, &x);
}
-static void draw_forms(struct terminal *t, struct f_data_c *f)
+static void
+draw_forms(struct terminal *t, struct f_data_c *f)
{
struct link *l1 = get_first_link(f);
struct link *l2 = get_last_link(f);
if (!l1 || !l2) {
- if (l1 || l2) internal("get_first_link == %p, get_last_link == %p", (void *)l1, (void *)l2);
+ if (l1 || l2)
+ internal("get_first_link == %p, get_last_link == %p",
+ (void *)l1, (void *)l2);
return;
}
do {
- if (l1->type != L_LINK) draw_form_entry(t, f, l1);
+ if (l1->type != L_LINK)
+ draw_form_entry(t, f, l1);
} while (l1++ < l2);
}
/* 0 -> 1 <- 2 v 3 ^ */
-static unsigned char fr_trans[2][4] = {{0xb3, 0xc3, 0xb4, 0xc5}, {0xc4, 0xc2, 0xc1, 0xc5}};
+static unsigned char fr_trans[2][4] = {
+ {0xb3, 0xc3, 0xb4, 0xc5},
+ { 0xc4, 0xc2, 0xc1, 0xc5}
+};
-static void set_xchar(struct terminal *t, int x, int y, unsigned dir)
+static void
+set_xchar(struct terminal *t, int x, int y, unsigned dir)
{
const chr *co;
- if (x < 0 || x >= t->x || y < 0 || y >= t->y) return;
+ if (x < 0 || x >= t->x || y < 0 || y >= t->y)
+ return;
co = get_char(t, x, y);
- if (!(co->at & ATTR_FRAME)) return;
- if (co->ch == fr_trans[dir / 2][0]) set_only_char(t, x, y, fr_trans[dir / 2][1 + (dir & 1)], ATTR_FRAME);
- else if (co->ch == fr_trans[dir / 2][2 - (dir & 1)]) set_only_char(t, x, y, fr_trans[dir / 2][3], ATTR_FRAME);
+ if (!(co->at & ATTR_FRAME))
+ return;
+ if (co->ch == fr_trans[dir / 2][0])
+ set_only_char(t, x, y, fr_trans[dir / 2][1 + (dir & 1)],
+ ATTR_FRAME);
+ else if (co->ch == fr_trans[dir / 2][2 - (dir & 1)])
+ set_only_char(t, x, y, fr_trans[dir / 2][3], ATTR_FRAME);
}
-static void draw_frame_lines(struct session *ses, struct frameset_desc *fsd, int xp, int yp)
+static void
+draw_frame_lines(struct session *ses, struct frameset_desc *fsd, int xp, int yp)
{
struct terminal *t = ses->term;
int i, j;
int x, y;
- if (!fsd) return;
+ if (!fsd)
+ return;
y = yp - 1;
for (j = 0; j < fsd->y; j++) {
int wwy = fsd->f[j * fsd->x].yw;
@@ -908,16 +1060,28 @@ static void draw_frame_lines(struct session *ses, struct frameset_desc *fsd, int
for (i = 0; i < fsd->x; i++) {
int wwx = fsd->f[i].xw;
if (i) {
- fill_area(t, x, y + 1, 1, wwy, 179, ATTR_FRAME | get_session_attribute(ses, 0));
- if (j == fsd->y - 1) set_xchar(t, x, y + wwy + 1, 3);
- } else if (j) set_xchar(t, x, y, 0);
+ fill_area(t, x, y + 1, 1, wwy, 179,
+ ATTR_FRAME
+ | get_session_attribute(ses, 0));
+ if (j == fsd->y - 1)
+ set_xchar(t, x, y + wwy + 1, 3);
+ } else if (j)
+ set_xchar(t, x, y, 0);
if (j) {
- fill_area(t, x + 1, y, wwx, 1, 196, ATTR_FRAME | get_session_attribute(ses, 0));
- if (i == fsd->x - 1) set_xchar(t, x + wwx + 1, y, 1);
- } else if (i) set_xchar(t, x, y, 2);
- if (i && j) set_char(t, x, y, 197, ATTR_FRAME | get_session_attribute(ses, 0));
+ fill_area(t, x + 1, y, wwx, 1, 196,
+ ATTR_FRAME
+ | get_session_attribute(ses, 0));
+ if (i == fsd->x - 1)
+ set_xchar(t, x + wwx + 1, y, 1);
+ } else if (i)
+ set_xchar(t, x, y, 2);
+ if (i && j)
+ set_char(t, x, y, 197,
+ ATTR_FRAME
+ | get_session_attribute(ses, 0));
/*if (fsd->f[j * fsd->x + i].subframe) {
- draw_frame_lines(ses, fsd->f[j * fsd->x + i].subframe, x + 1, y + 1);
+ draw_frame_lines(ses, fsd->f[j * fsd->x +
+ i].subframe, x + 1, y + 1);
}*/
x += wwx + 1;
}
@@ -925,7 +1089,8 @@ static void draw_frame_lines(struct session *ses, struct frameset_desc *fsd, int
}
}
-void draw_doc(struct terminal *t, void *scr_)
+void
+draw_doc(struct terminal *t, void *scr_)
{
struct f_data_c *scr = (struct f_data_c *)scr_;
struct session *ses = scr->ses;
@@ -944,31 +1109,38 @@ void draw_doc(struct terminal *t, void *scr_)
else
set_cursor(t, xp, yp, xp, yp);
}
- fill_area(t, xp, yp, xw, yw, ' ', get_session_attribute(ses, 0));
- if (active) set_window_ptr(ses->win, xp, yp);
+ fill_area(t, xp, yp, xw, yw, ' ',
+ get_session_attribute(ses, 0));
+ if (active)
+ set_window_ptr(ses->win, xp, yp);
return;
}
if (active) {
- set_cursor(t, xp + xw - 1, yp + yw - 1, xp + xw - 1, yp + yw - 1);
- set_window_ptr(ses->win, xp, yp);
+ set_cursor(t, xp + xw - 1, yp + yw - 1, xp + xw - 1,
+ yp + yw - 1);
+ set_window_ptr(ses->win, xp, yp);
}
check_vs(scr);
if (scr->f_data->frame_desc) {
struct f_data_c *f = NULL;
struct list_head *lf;
- fill_area(t, xp, yp, xw, yw, ' ', scr->f_data->y ? scr->f_data->bg : 0);
+ fill_area(t, xp, yp, xw, yw, ' ',
+ scr->f_data->y ? scr->f_data->bg : 0);
draw_frame_lines(ses, scr->f_data->frame_desc, xp, yp);
n = 0;
- foreach(struct f_data_c, f, lf, scr->subframes) {
+ foreach (struct f_data_c, f, lf, scr->subframes) {
f->active = active && n++ == scr->vs->frame_pos;
draw_doc(t, f);
}
return;
}
vs = scr->vs;
- if (scr->goto_position && (vy = find_tag(scr->f_data, scr->goto_position)) != -1) {
- if (vy > scr->f_data->y) vy = scr->f_data->y - 1;
- if (vy < 0) vy = 0;
+ if (scr->goto_position
+ && (vy = find_tag(scr->f_data, scr->goto_position)) != -1) {
+ if (vy > scr->f_data->y)
+ vy = scr->f_data->y - 1;
+ if (vy < 0)
+ vy = 0;
vs->view_pos = vy;
vs->orig_view_pos = vy;
vs->view_posx = 0;
@@ -979,15 +1151,16 @@ void draw_doc(struct terminal *t, void *scr_)
scr->goto_position = NULL;
}
if (vs->view_pos != vs->orig_view_pos
- || vs->view_posx != vs->orig_view_posx
- || vs->current_link != vs->orig_link) {
+ || vs->view_posx != vs->orig_view_posx
+ || vs->current_link != vs->orig_link) {
int ol;
vs->view_pos = vs->orig_view_pos;
vs->view_posx = vs->orig_view_posx;
vs->brl_x = vs->orig_brl_x;
vs->brl_y = vs->orig_brl_y;
ol = vs->orig_link;
- if (ol < scr->f_data->nlinks) vs->current_link = ol;
+ if (ol < scr->f_data->nlinks)
+ vs->current_link = ol;
while (vs->view_pos >= scr->f_data->y)
vs->view_pos -= yw ? yw : 1;
if (vs->view_pos < 0)
@@ -998,7 +1171,8 @@ void draw_doc(struct terminal *t, void *scr_)
}
vx = vs->view_posx;
vy = vs->view_pos;
- if (scr->xl == vx && scr->yl == vy && scr->xl != -1 && !ses->search_word) {
+ if (scr->xl == vx && scr->yl == vy && scr->xl != -1
+ && !ses->search_word) {
clear_link(t, scr);
draw_forms(t, scr);
if (active)
@@ -1008,7 +1182,9 @@ void draw_doc(struct terminal *t, void *scr_)
free_link(scr);
scr->xl = vx;
scr->yl = vy;
- fill_area(t, xp, yp, xw, yw, ' ', scr->f_data->y ? scr->f_data->bg : get_session_attribute(ses, 0));
+ fill_area(t, xp, yp, xw, yw, ' ',
+ scr->f_data->y ? scr->f_data->bg
+ : get_session_attribute(ses, 0));
if (!scr->f_data->y)
return;
while (vs->view_pos >= scr->f_data->y)
@@ -1019,10 +1195,14 @@ void draw_doc(struct terminal *t, void *scr_)
vy = vs->view_pos;
check_vs(scr);
}
- for (y = vy <= 0 ? 0 : vy; y < (-vy + scr->f_data->y <= yw ? scr->f_data->y : yw + vy); y++) {
+ for (y = vy <= 0 ? 0 : vy;
+ y < (-vy + scr->f_data->y <= yw ? scr->f_data->y : yw + vy); y++) {
int st = vx <= 0 ? 0 : vx;
- int en = -vx + scr->f_data->data[y].l <= xw ? scr->f_data->data[y].l : xw + vx;
- set_line(t, xp + st - vx, yp + y - vy, en - st, &scr->f_data->data[y].d[st]);
+ int en = -vx + scr->f_data->data[y].l <= xw
+ ? scr->f_data->data[y].l
+ : xw + vx;
+ set_line(t, xp + st - vx, yp + y - vy, en - st,
+ &scr->f_data->data[y].d[st]);
}
draw_forms(t, scr);
if (active)
@@ -1031,22 +1211,26 @@ void draw_doc(struct terminal *t, void *scr_)
scr->xl = scr->yl = -1;
}
-static void clr_xl(struct f_data_c *fd)
+static void
+clr_xl(struct f_data_c *fd)
{
struct f_data_c *fdd = NULL;
struct list_head *lfdd;
fd->xl = fd->yl = -1;
- foreach(struct f_data_c, fdd, lfdd, fd->subframes) clr_xl(fdd);
+ foreach (struct f_data_c, fdd, lfdd, fd->subframes)
+ clr_xl(fdd);
}
-static void draw_doc_c(struct terminal *t, void *scr_)
+static void
+draw_doc_c(struct terminal *t, void *scr_)
{
struct f_data_c *scr = (struct f_data_c *)scr_;
clr_xl(scr);
draw_doc(t, scr);
}
-void draw_formatted(struct session *ses)
+void
+draw_formatted(struct session *ses)
{
/*clr_xl(ses->screen);*/
ses->screen->active = 1;
@@ -1055,17 +1239,21 @@ void draw_formatted(struct session *ses)
print_screen_status(ses);
}
-void draw_fd(struct f_data_c *f)
+void
+draw_fd(struct f_data_c *f)
{
- if (f->f_data) f->f_data->time_to_draw = -get_time();
+ if (f->f_data)
+ f->f_data->time_to_draw = -get_time();
f->active = is_active_frame(f->ses, f);
draw_to_window(f->ses->win, draw_doc_c, f);
change_screen_status(f->ses);
print_screen_status(f->ses);
- if (f->f_data) f->f_data->time_to_draw += get_time();
+ if (f->f_data)
+ f->f_data->time_to_draw += get_time();
}
-static void draw_fd_nrd(struct f_data_c *f)
+static void
+draw_fd_nrd(struct f_data_c *f)
{
f->active = is_active_frame(f->ses, f);
draw_to_window(f->ses->win, draw_doc, f);
@@ -1073,37 +1261,45 @@ static void draw_fd_nrd(struct f_data_c *f)
print_screen_status(f->ses);
}
-#define D_BUF 65536
+#define D_BUF 65536
-int dump_to_file(struct f_data *fd, int h)
+int
+dump_to_file(struct f_data *fd, int h)
{
int x, y;
unsigned char *buf;
int bptr = 0;
int retval;
buf = xmalloc(D_BUF);
- for (y = 0; y < fd->y; y++) for (x = 0; x <= fd->data[y].l; x++) {
- unsigned c;
- if (x == fd->data[y].l) c = '\n';
- else {
- c = fd->data[y].d[x].ch;
- if (c == 1) c = ' ';
- if (fd->data[y].d[x].at & ATTR_FRAME && c >= 176 && c < 224) c = frame_dumb[c - 176];
- }
- if (!fd->opt.cp && c >= 0x80) {
- unsigned char *enc = encode_utf_8(c);
- strcpy(cast_char(buf + bptr), cast_const_char enc);
- bptr += (int)strlen(cast_const_char enc);
- } else
- buf[bptr++] = (unsigned char)c;
- if (bptr >= D_BUF - 7) {
- if ((retval = hard_write(h, buf, bptr)) != bptr) {
- free(buf);
- goto fail;
+ for (y = 0; y < fd->y; y++)
+ for (x = 0; x <= fd->data[y].l; x++) {
+ unsigned c;
+ if (x == fd->data[y].l)
+ c = '\n';
+ else {
+ c = fd->data[y].d[x].ch;
+ if (c == 1)
+ c = ' ';
+ if (fd->data[y].d[x].at & ATTR_FRAME && c >= 176
+ && c < 224)
+ c = frame_dumb[c - 176];
+ }
+ if (!fd->opt.cp && c >= 0x80) {
+ unsigned char *enc = encode_utf_8(c);
+ strcpy(cast_char(buf + bptr),
+ cast_const_char enc);
+ bptr += (int)strlen(cast_const_char enc);
+ } else
+ buf[bptr++] = (unsigned char)c;
+ if (bptr >= D_BUF - 7) {
+ if ((retval = hard_write(h, buf, bptr))
+ != bptr) {
+ free(buf);
+ goto fail;
+ }
+ bptr = 0;
}
- bptr = 0;
}
- }
if ((retval = hard_write(h, buf, bptr)) != bptr) {
free(buf);
goto fail;
@@ -1112,7 +1308,9 @@ int dump_to_file(struct f_data *fd, int h)
if (fd->opt.num_links && fd->nlinks) {
static const unsigned char head[] = "\nLinks:\n";
int i;
- if ((retval = hard_write(h, head, (int)strlen(cast_const_char head))) != (int)strlen(cast_const_char head))
+ if ((retval =
+ hard_write(h, head, (int)strlen(cast_const_char head)))
+ != (int)strlen(cast_const_char head))
goto fail;
for (i = 0; i < fd->nlinks; i++) {
struct form_control *fc;
@@ -1128,52 +1326,74 @@ int dump_to_file(struct f_data *fd, int h)
add_to_str(&s, &l, lnk->where_img);
} else if (lnk->type == L_BUTTON) {
fc = lnk->form;
- if (fc->type == FC_RESET) add_to_str(&s, &l, cast_uchar "Reset form");
- else if (fc->type == FC_BUTTON || !fc->action) add_to_str(&s, &l, cast_uchar "Button");
+ if (fc->type == FC_RESET)
+ add_to_str(&s, &l,
+ cast_uchar "Reset form");
+ else if (fc->type == FC_BUTTON || !fc->action)
+ add_to_str(&s, &l, cast_uchar "Button");
else {
- if (fc->method == FM_GET) add_to_str(&s, &l, cast_uchar "Submit form: ");
- else add_to_str(&s, &l, cast_uchar "Post form: ");
+ if (fc->method == FM_GET)
+ add_to_str(&s, &l,
+ cast_uchar
+ "Submit form: ");
+ else
+ add_to_str(&s, &l,
+ cast_uchar
+ "Post form: ");
add_to_str(&s, &l, fc->action);
}
- } else if (lnk->type == L_CHECKBOX || lnk->type == L_SELECT || lnk->type == L_FIELD || lnk->type == L_AREA) {
+ } else if (lnk->type == L_CHECKBOX
+ || lnk->type == L_SELECT
+ || lnk->type == L_FIELD
+ || lnk->type == L_AREA) {
fc = lnk->form;
switch (fc->type) {
case FC_RADIO:
- add_to_str(&s, &l, cast_uchar "Radio button");
+ add_to_str(&s, &l,
+ cast_uchar "Radio button");
break;
case FC_CHECKBOX:
- add_to_str(&s, &l, cast_uchar "Checkbox");
+ add_to_str(&s, &l,
+ cast_uchar "Checkbox");
break;
case FC_SELECT:
- add_to_str(&s, &l, cast_uchar "Select field");
+ add_to_str(&s, &l,
+ cast_uchar "Select field");
break;
case FC_TEXT:
- add_to_str(&s, &l, cast_uchar "Text field");
+ add_to_str(&s, &l,
+ cast_uchar "Text field");
break;
case FC_TEXTAREA:
- add_to_str(&s, &l, cast_uchar "Text area");
+ add_to_str(&s, &l,
+ cast_uchar "Text area");
break;
case FC_FILE_UPLOAD:
- add_to_str(&s, &l, cast_uchar "File upload");
+ add_to_str(&s, &l,
+ cast_uchar "File upload");
break;
case FC_PASSWORD:
- add_to_str(&s, &l, cast_uchar "Password field");
+ add_to_str(&s, &l,
+ cast_uchar "Password field");
break;
default:
goto unknown;
}
if (fc->name && fc->name[0]) {
- add_to_str(&s, &l, cast_uchar ", Name ");
+ add_to_str(&s, &l,
+ cast_uchar ", Name ");
add_to_str(&s, &l, fc->name);
}
- if ((fc->type == FC_CHECKBOX || fc->type == FC_RADIO)
- && fc->default_value
- && fc->default_value[0]) {
- add_to_str(&s, &l, cast_uchar ", Value ");
+ if ((fc->type == FC_CHECKBOX
+ || fc->type == FC_RADIO)
+ && fc->default_value
+ && fc->default_value[0]) {
+ add_to_str(&s, &l,
+ cast_uchar ", Value ");
add_to_str(&s, &l, fc->default_value);
}
}
- unknown:
+unknown:
add_to_str(&s, &l, cast_uchar "\n");
if ((retval = hard_write(h, s, l)) != l) {
free(s);
@@ -1184,61 +1404,75 @@ int dump_to_file(struct f_data *fd, int h)
}
return 0;
- fail:
+fail:
if (retval < 0)
return get_error_from_errno(errno);
else
return S_CANT_WRITE;
}
-static int in_viewx(struct f_data_c *f, struct link *l)
+static int
+in_viewx(struct f_data_c *f, struct link *l)
{
int i;
for (i = 0; i < l->n; i++) {
- if (l->pos[i].x >= f->vs->view_posx && l->pos[i].x < f->vs->view_posx + f->xw)
+ if (l->pos[i].x >= f->vs->view_posx
+ && l->pos[i].x < f->vs->view_posx + f->xw)
return 1;
}
return 0;
}
-static int in_viewy(struct f_data_c *f, struct link *l)
+static int
+in_viewy(struct f_data_c *f, struct link *l)
{
int i;
for (i = 0; i < l->n; i++) {
- if (l->pos[i].y >= f->vs->view_pos && l->pos[i].y < f->vs->view_pos + f->yw)
+ if (l->pos[i].y >= f->vs->view_pos
+ && l->pos[i].y < f->vs->view_pos + f->yw)
return 1;
}
return 0;
}
-static int in_view(struct f_data_c *f, struct link *l)
+static int
+in_view(struct f_data_c *f, struct link *l)
{
return in_viewy(f, l) && in_viewx(f, l);
}
-static int c_in_view(struct f_data_c *f)
+static int
+c_in_view(struct f_data_c *f)
{
- return f->vs->current_link != -1 && in_view(f, &f->f_data->links[f->vs->current_link]);
+ return f->vs->current_link != -1
+ && in_view(f, &f->f_data->links[f->vs->current_link]);
}
-static int next_in_view(struct f_data_c *f, int p, int d, int (*fn)(struct f_data_c *, struct link *), void (*cntr)(struct f_data_c *, struct link *))
+static int
+next_in_view(struct f_data_c *f, int p, int d,
+ int (*fn)(struct f_data_c *, struct link *),
+ void (*cntr)(struct f_data_c *, struct link *))
{
int p1 = f->f_data->nlinks - 1;
int p2 = 0;
int y;
int yl = f->vs->view_pos + f->yw;
- if (yl > f->f_data->y) yl = f->f_data->y;
+ if (yl > f->f_data->y)
+ yl = f->f_data->y;
for (y = f->vs->view_pos < 0 ? 0 : f->vs->view_pos; y < yl; y++) {
- if (f->f_data->lines1[y] && f->f_data->lines1[y] - f->f_data->links < p1)
+ if (f->f_data->lines1[y]
+ && f->f_data->lines1[y] - f->f_data->links < p1)
p1 = (int)(f->f_data->lines1[y] - f->f_data->links);
- if (f->f_data->lines2[y] && f->f_data->lines2[y] - f->f_data->links > p2)
+ if (f->f_data->lines2[y]
+ && f->f_data->lines2[y] - f->f_data->links > p2)
p2 = (int)(f->f_data->lines2[y] - f->f_data->links);
}
while (p >= p1 && p <= p2) {
if (fn(f, &f->f_data->links[p])) {
f->vs->current_link = p;
f->vs->orig_link = f->vs->current_link;
- if (cntr) cntr(f, &f->f_data->links[p]);
+ if (cntr)
+ cntr(f, &f->f_data->links[p]);
return 1;
}
p += d;
@@ -1248,39 +1482,52 @@ static int next_in_view(struct f_data_c *f, int p, int d, int (*fn)(struct f_dat
return 0;
}
-static void set_pos_x(struct f_data_c *f, struct link *l)
+static void
+set_pos_x(struct f_data_c *f, struct link *l)
{
int i;
int xm = 0;
int xl = INT_MAX;
for (i = 0; i < l->n; i++) {
- if (l->pos[i].y >= f->vs->view_pos && l->pos[i].y < f->vs->view_pos + f->yw) {
- if (l->pos[i].x >= xm) xm = l->pos[i].x + 1;
- if (l->pos[i].x < xl) xl = l->pos[i].x;
+ if (l->pos[i].y >= f->vs->view_pos
+ && l->pos[i].y < f->vs->view_pos + f->yw) {
+ if (l->pos[i].x >= xm)
+ xm = l->pos[i].x + 1;
+ if (l->pos[i].x < xl)
+ xl = l->pos[i].x;
}
}
- if (xl == INT_MAX) return;
- if (f->vs->view_posx + f->xw < xm) f->vs->view_posx = xm - f->xw;
- if (f->vs->view_posx > xl) f->vs->view_posx = xl;
+ if (xl == INT_MAX)
+ return;
+ if (f->vs->view_posx + f->xw < xm)
+ f->vs->view_posx = xm - f->xw;
+ if (f->vs->view_posx > xl)
+ f->vs->view_posx = xl;
f->vs->orig_view_posx = f->vs->view_posx;
}
-static void set_pos_y(struct f_data_c *f, struct link *l)
+static void
+set_pos_y(struct f_data_c *f, struct link *l)
{
int i;
int ym = 0;
int yl = f->f_data->y;
for (i = 0; i < l->n; i++) {
- if (l->pos[i].y >= ym) ym = l->pos[i].y + 1;
- if (l->pos[i].y < yl) yl = l->pos[i].y;
+ if (l->pos[i].y >= ym)
+ ym = l->pos[i].y + 1;
+ if (l->pos[i].y < yl)
+ yl = l->pos[i].y;
}
- if ((f->vs->view_pos = (ym + yl) / 2 - f->yw / 2) > f->f_data->y - f->yw)
+ if ((f->vs->view_pos = (ym + yl) / 2 - f->yw / 2)
+ > f->f_data->y - f->yw)
f->vs->view_pos = f->f_data->y - f->yw;
- if (f->vs->view_pos < 0) f->vs->view_pos = 0;
+ if (f->vs->view_pos < 0)
+ f->vs->view_pos = 0;
f->vs->orig_view_pos = f->vs->view_pos;
}
-static void find_link(struct f_data_c *f, int p, int s)
+static void
+find_link(struct f_data_c *f, int p, int s)
{ /* p=1 - top, p=-1 - bottom, s=0 - pgdn, s=1 - down */
int y;
int l;
@@ -1289,19 +1536,25 @@ static void find_link(struct f_data_c *f, int p, int s)
line = p == -1 ? f->f_data->lines2 : f->f_data->lines1;
if (p == -1) {
y = f->vs->view_pos + f->yw - 1;
- if (y >= f->f_data->y) y = f->f_data->y - 1;
+ if (y >= f->f_data->y)
+ y = f->f_data->y - 1;
} else {
y = f->vs->view_pos;
- if (y < 0) y = 0;
+ if (y < 0)
+ y = 0;
}
- if (y < 0 || y >= f->f_data->y) goto nolink;
+ if (y < 0 || y >= f->f_data->y)
+ goto nolink;
link = NULL;
do {
- if (line[y] && (!link || (p > 0 ? line[y] < link : line[y] > link)))
+ if (line[y]
+ && (!link || (p > 0 ? line[y] < link : line[y] > link)))
link = line[y];
y += p;
- } while (!(y < 0 || y < f->vs->view_pos || y >= f->vs->view_pos + f->yw || y >= f->f_data->y));
- if (!link) goto nolink;
+ } while (!(y < 0 || y < f->vs->view_pos || y >= f->vs->view_pos + f->yw
+ || y >= f->f_data->y));
+ if (!link)
+ goto nolink;
l = (int)(link - f->f_data->links);
if (s == 0) {
next_in_view(f, l, p, in_view, NULL);
@@ -1311,12 +1564,13 @@ static void find_link(struct f_data_c *f, int p, int s)
f->vs->orig_link = f->vs->current_link;
set_pos_x(f, link);
return;
- nolink:
+nolink:
f->vs->current_link = -1;
f->vs->orig_link = f->vs->current_link;
}
-static void page_down(struct session *ses, struct f_data_c *f, int a)
+static void
+page_down(struct session *ses, struct f_data_c *f, int a)
{
if (f->vs->view_pos + f->yw < f->f_data->y) {
f->vs->view_pos += f->yw;
@@ -1326,7 +1580,8 @@ static void page_down(struct session *ses, struct f_data_c *f, int a)
find_link(f, -1, a);
}
-static void page_up(struct session *ses, struct f_data_c *f, int a)
+static void
+page_up(struct session *ses, struct f_data_c *f, int a)
{
f->vs->view_pos -= f->yw;
find_link(f, -1, a);
@@ -1336,43 +1591,63 @@ static void page_up(struct session *ses, struct f_data_c *f, int a)
f->vs->orig_view_pos = f->vs->view_pos;
}
-static void down(struct session *ses, struct f_data_c *f, int a)
+static void
+down(struct session *ses, struct f_data_c *f, int a)
{
int l = f->vs->current_link;
- if (f->vs->current_link == -1 || !next_in_view(f, f->vs->current_link+1, 1, in_viewy, set_pos_x)) page_down(ses, f, 1);
- if (l != f->vs->current_link) set_textarea(ses, f, -1);
+ if (f->vs->current_link == -1
+ || !next_in_view(f, f->vs->current_link + 1, 1, in_viewy,
+ set_pos_x))
+ page_down(ses, f, 1);
+ if (l != f->vs->current_link)
+ set_textarea(ses, f, -1);
}
-static void up(struct session *ses, struct f_data_c *f, int a)
+static void
+up(struct session *ses, struct f_data_c *f, int a)
{
int l = f->vs->current_link;
- if (f->vs->current_link == -1 || !next_in_view(f, f->vs->current_link-1, -1, in_viewy, set_pos_x)) page_up(ses, f, 1);
- if (l != f->vs->current_link) set_textarea(ses, f, 1);
+ if (f->vs->current_link == -1
+ || !next_in_view(f, f->vs->current_link - 1, -1, in_viewy,
+ set_pos_x))
+ page_up(ses, f, 1);
+ if (l != f->vs->current_link)
+ set_textarea(ses, f, 1);
}
-static void scroll(struct session *ses, struct f_data_c *f, int a)
+static void
+scroll(struct session *ses, struct f_data_c *f, int a)
{
- if (f->vs->view_pos + f->yw >= f->f_data->y && a > 0) return;
+ if (f->vs->view_pos + f->yw >= f->f_data->y && a > 0)
+ return;
f->vs->view_pos += a;
- if (f->vs->view_pos > f->f_data->y - f->yw && a > 0) f->vs->view_pos = f->f_data->y - f->yw;
- if (f->vs->view_pos < 0) f->vs->view_pos = 0;
+ if (f->vs->view_pos > f->f_data->y - f->yw && a > 0)
+ f->vs->view_pos = f->f_data->y - f->yw;
+ if (f->vs->view_pos < 0)
+ f->vs->view_pos = 0;
f->vs->orig_view_pos = f->vs->view_pos;
- if (c_in_view(f)) return;
+ if (c_in_view(f))
+ return;
find_link(f, a < 0 ? -1 : 1, 0);
}
-static void hscroll(struct session *ses, struct f_data_c *f, int a)
+static void
+hscroll(struct session *ses, struct f_data_c *f, int a)
{
f->vs->view_posx += a;
- if (f->vs->view_posx >= f->f_data->x) f->vs->view_posx = f->f_data->x - 1;
- if (f->vs->view_posx < 0) f->vs->view_posx = 0;
+ if (f->vs->view_posx >= f->f_data->x)
+ f->vs->view_posx = f->f_data->x - 1;
+ if (f->vs->view_posx < 0)
+ f->vs->view_posx = 0;
f->vs->orig_view_posx = f->vs->view_posx;
- if (c_in_view(f)) return;
+ if (c_in_view(f))
+ return;
find_link(f, 1, 0);
/* !!! FIXME: check right margin */
}
-static void home(struct session *ses, struct f_data_c *f, int a)
+static void
+home(struct session *ses, struct f_data_c *f, int a)
{
f->vs->view_pos = f->vs->view_posx = 0;
f->vs->orig_view_pos = f->vs->view_pos;
@@ -1380,32 +1655,38 @@ static void home(struct session *ses, struct f_data_c *f, int a)
find_link(f, 1, 0);
}
-static void x_end(struct session *ses, struct f_data_c *f, int a)
+static void
+x_end(struct session *ses, struct f_data_c *f, int a)
{
f->vs->view_posx = 0;
- if (f->vs->view_pos < f->f_data->y - f->yw) f->vs->view_pos = f->f_data->y - f->yw;
- if (f->vs->view_pos < 0) f->vs->view_pos = 0;
+ if (f->vs->view_pos < f->f_data->y - f->yw)
+ f->vs->view_pos = f->f_data->y - f->yw;
+ if (f->vs->view_pos < 0)
+ f->vs->view_pos = 0;
f->vs->orig_view_pos = f->vs->view_pos;
f->vs->orig_view_posx = f->vs->view_posx;
find_link(f, -1, 0);
}
-static int has_form_submit(struct f_data *f, struct form_control *form)
+static int
+has_form_submit(struct f_data *f, struct form_control *form)
{
struct form_control *i = NULL;
struct list_head *li;
int q = 0;
- foreach (struct form_control, i, li, f->forms) if (i->form_num == form->form_num) {
- if ((i->type == FC_SUBMIT || i->type == FC_IMAGE)) return 1;
- q = 1;
- }
- if (!q) internal("form is not on list");
+ foreach (struct form_control, i, li, f->forms)
+ if (i->form_num == form->form_num) {
+ if ((i->type == FC_SUBMIT || i->type == FC_IMAGE))
+ return 1;
+ q = 1;
+ }
+ if (!q)
+ internal("form is not on list");
return 0;
}
struct submitted_value {
- list_entry_1st
- int type;
+ list_entry_1st int type;
unsigned char *name;
unsigned char *value;
void *file_content;
@@ -1413,11 +1694,12 @@ struct submitted_value {
int position;
};
-static void free_succesful_controls(struct list_head *submit)
+static void
+free_succesful_controls(struct list_head *submit)
{
struct submitted_value *v = NULL;
struct list_head *lv;
- foreach(struct submitted_value, v, lv, *submit) {
+ foreach (struct submitted_value, v, lv, *submit) {
free(v->name);
free(v->value);
free(v->file_content);
@@ -1425,39 +1707,57 @@ static void free_succesful_controls(struct list_head *submit)
free_list(struct submitted_value, *submit);
}
-static unsigned char *encode_textarea(unsigned char *t)
+static unsigned char *
+encode_textarea(unsigned char *t)
{
int len = 0;
unsigned char *o = init_str();
for (; *t; t++) {
- if (*t != '\n') add_chr_to_str(&o, &len, *t);
- else add_to_str(&o, &len, cast_uchar "\r\n");
+ if (*t != '\n')
+ add_chr_to_str(&o, &len, *t);
+ else
+ add_to_str(&o, &len, cast_uchar "\r\n");
}
return o;
}
-static int compare_submitted(struct submitted_value *sub1, struct submitted_value *sub2)
+static int
+compare_submitted(struct submitted_value *sub1, struct submitted_value *sub2)
{
return sub1->position - sub2->position;
}
-static void get_succesful_controls(struct f_data_c *f, struct form_control *fc, struct list_head *subm)
+static void
+get_succesful_controls(struct f_data_c *f, struct form_control *fc,
+ struct list_head *subm)
{
int ch;
struct form_control *form = NULL;
struct list_head *lform;
init_list(*subm);
- foreach(struct form_control, form, lform, f->f_data->forms) {
- if (form->form_num == fc->form_num && ((form->type != FC_SUBMIT && form->type != FC_IMAGE && form->type != FC_RESET && form->type != FC_BUTTON) || form == fc) && form->name && form->name[0] && form->ro != 2) {
+ foreach (struct form_control, form, lform, f->f_data->forms) {
+ if (form->form_num == fc->form_num
+ && ((form->type != FC_SUBMIT && form->type != FC_IMAGE
+ && form->type != FC_RESET && form->type != FC_BUTTON)
+ || form == fc)
+ && form->name && form->name[0] && form->ro != 2) {
struct submitted_value *sub;
struct form_state *fs;
- int fi = form->type == FC_IMAGE && form->default_value && *form->default_value ? -1 : 0;
+ int fi = form->type == FC_IMAGE && form->default_value
+ && *form->default_value
+ ? -1
+ : 0;
int svl;
fs = find_form_state(f, form);
- if ((form->type == FC_CHECKBOX || form->type == FC_RADIO) && !fs->state) continue;
- if (form->type == FC_BUTTON) continue;
- if (form->type == FC_SELECT && !form->nvalues) continue;
- fi_rep:
+ if ((form->type == FC_CHECKBOX
+ || form->type == FC_RADIO)
+ && !fs->state)
+ continue;
+ if (form->type == FC_BUTTON)
+ continue;
+ if (form->type == FC_SELECT && !form->nvalues)
+ continue;
+fi_rep:
sub = mem_calloc(sizeof(struct submitted_value));
sub->type = form->type;
sub->name = stracpy(form->name);
@@ -1474,7 +1774,8 @@ static void get_succesful_controls(struct f_data_c *f, struct form_control *fc,
case FC_RADIO:
case FC_SUBMIT:
case FC_HIDDEN:
- sub->value = encode_textarea(form->default_value);
+ sub->value =
+ encode_textarea(form->default_value);
break;
case FC_SELECT:
fixup_select_state(form, fs);
@@ -1482,13 +1783,16 @@ static void get_succesful_controls(struct f_data_c *f, struct form_control *fc,
break;
case FC_IMAGE:
if (fi == -1) {
- sub->value = encode_textarea(form->default_value);
+ sub->value = encode_textarea(
+ form->default_value);
break;
}
- add_to_strn(&sub->name, fi ? cast_uchar ".x" : cast_uchar ".y");
+ add_to_strn(&sub->name, fi ? cast_uchar ".x"
+ : cast_uchar ".y");
sub->value = init_str();
svl = 0;
- add_num_to_str(&sub->value, &svl, fi ? ismap_x : ismap_y);
+ add_num_to_str(&sub->value, &svl,
+ fi ? ismap_x : ismap_y);
break;
default:
internal("bad form control type");
@@ -1505,46 +1809,58 @@ static void get_succesful_controls(struct f_data_c *f, struct form_control *fc,
struct submitted_value *sub = NULL, *nx;
struct list_head *lsub;
ch = 0;
- foreach(struct submitted_value, sub, lsub, *subm) if (sub->list_entry.next != subm) {
- nx = list_struct(sub->list_entry.next, struct submitted_value);
- if (compare_submitted(nx, sub) < 0) {
- del_from_list(sub);
- add_after_pos(nx, sub);
- lsub = &nx->list_entry;
- ch = 1;
+ foreach (struct submitted_value, sub, lsub, *subm)
+ if (sub->list_entry.next != subm) {
+ nx = list_struct(sub->list_entry.next,
+ struct submitted_value);
+ if (compare_submitted(nx, sub) < 0) {
+ del_from_list(sub);
+ add_after_pos(nx, sub);
+ lsub = &nx->list_entry;
+ ch = 1;
+ }
}
- }
- foreachback(struct submitted_value, sub, lsub, *subm) if (sub->list_entry.next != subm) {
- nx = list_struct(sub->list_entry.next, struct submitted_value);
- if (compare_submitted(nx, sub) < 0) {
- del_from_list(sub);
- add_after_pos(nx, sub);
- sub = nx;
- lsub = &nx->list_entry;
- ch = 1;
+ foreachback (struct submitted_value, sub, lsub, *subm)
+ if (sub->list_entry.next != subm) {
+ nx = list_struct(sub->list_entry.next,
+ struct submitted_value);
+ if (compare_submitted(nx, sub) < 0) {
+ del_from_list(sub);
+ add_after_pos(nx, sub);
+ sub = nx;
+ lsub = &nx->list_entry;
+ ch = 1;
+ }
}
- }
} while (ch);
}
-static unsigned char *strip_file_name(unsigned char *f)
+static unsigned char *
+strip_file_name(unsigned char *f)
{
unsigned char *n;
unsigned char *l = f - 1;
- for (n = f; *n; n++) if (dir_sep(*n)) l = n;
+ for (n = f; *n; n++)
+ if (dir_sep(*n))
+ l = n;
return l + 1;
}
-static inline int safe_char(unsigned char c)
+static inline int
+safe_char(unsigned char c)
{
- return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c== '.' || c == '-' || c == '_';
+ return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z')
+ || (c >= 'a' && c <= 'z') || c == '.' || c == '-' || c == '_';
}
-static void encode_string(unsigned char *name, unsigned char **data, int *len)
+static void
+encode_string(unsigned char *name, unsigned char **data, int *len)
{
for (; *name; name++) {
- if (*name == ' ') add_chr_to_str(data, len, '+');
- else if (safe_char(*name)) add_chr_to_str(data, len, *name);
+ if (*name == ' ')
+ add_chr_to_str(data, len, '+');
+ else if (safe_char(*name))
+ add_chr_to_str(data, len, *name);
else {
unsigned char n[4];
sprintf(cast_char n, "%%%02X", *name);
@@ -1553,8 +1869,9 @@ static void encode_string(unsigned char *name, unsigned char **data, int *len)
}
}
-static void encode_controls(struct list_head *l, unsigned char **data, int *len,
- int cp_from, int cp_to)
+static void
+encode_controls(struct list_head *l, unsigned char **data, int *len,
+ int cp_from, int cp_to)
{
struct submitted_value *sv = NULL;
struct list_head *lsv;
@@ -1562,7 +1879,7 @@ static void encode_controls(struct list_head *l, unsigned char **data, int *len,
unsigned char *p2;
*len = 0;
*data = init_str();
- foreach(struct submitted_value, sv, lsv, *l) {
+ foreach (struct submitted_value, sv, lsv, *l) {
unsigned char *p = sv->value;
if (lst)
add_chr_to_str(data, len, '&');
@@ -1570,7 +1887,8 @@ static void encode_controls(struct list_head *l, unsigned char **data, int *len,
lst = 1;
encode_string(sv->name, data, len);
add_chr_to_str(data, len, '=');
- if (sv->type == FC_TEXT || sv->type == FC_PASSWORD || sv->type == FC_TEXTAREA)
+ if (sv->type == FC_TEXT || sv->type == FC_PASSWORD
+ || sv->type == FC_TEXTAREA)
p2 = convert(cp_from, cp_to, p, NULL);
else
p2 = stracpy(p);
@@ -1579,17 +1897,18 @@ static void encode_controls(struct list_head *l, unsigned char **data, int *len,
}
}
-#define BL 56
-#define BL1 27
+#define BL 56
+#define BL1 27
-static void encode_multipart(struct session *ses, struct list_head *l, unsigned char **data, int *len,
- unsigned char *bound, int cp_from, int cp_to)
+static void
+encode_multipart(struct session *ses, struct list_head *l, unsigned char **data,
+ int *len, unsigned char *bound, int cp_from, int cp_to)
{
int errn;
int *bound_ptrs = NULL;
int nbound_ptrs = 0;
unsigned char *m1, *m2;
- struct submitted_value *sv = NULL; /* against warning */
+ struct submitted_value *sv = NULL; /* against warning */
struct list_head *lsv;
int i, j;
int flg = 0;
@@ -1598,43 +1917,59 @@ static void encode_multipart(struct session *ses, struct list_head *l, unsigned
memset(bound, 'x', BL);
*len = 0;
*data = init_str();
- foreach(struct submitted_value, sv, lsv, *l) {
+ foreach (struct submitted_value, sv, lsv, *l) {
unsigned char *ct;
- bnd:
+bnd:
add_to_str(data, len, cast_uchar "--");
- if (!(nbound_ptrs & (ALLOC_GR-1))) {
- if ((unsigned)nbound_ptrs > INT_MAX / sizeof(int) - ALLOC_GR)
+ if (!(nbound_ptrs & (ALLOC_GR - 1))) {
+ if ((unsigned)nbound_ptrs
+ > INT_MAX / sizeof(int) - ALLOC_GR)
overalloc();
- bound_ptrs = xrealloc(bound_ptrs,
- (nbound_ptrs + ALLOC_GR) * sizeof(int));
+ bound_ptrs = xrealloc(
+ bound_ptrs, (nbound_ptrs + ALLOC_GR) * sizeof(int));
}
bound_ptrs[nbound_ptrs++] = *len;
add_bytes_to_str(data, len, bound, BL);
- if (flg) break;
- add_to_str(data, len, cast_uchar "\r\nContent-Disposition: form-data; name=\"");
+ if (flg)
+ break;
+ add_to_str(data, len,
+ cast_uchar
+ "\r\nContent-Disposition: form-data; name=\"");
add_to_str(data, len, sv->name);
add_to_str(data, len, cast_uchar "\"");
if (sv->type == FC_FILE_UPLOAD) {
add_to_str(data, len, cast_uchar "; filename=\"");
add_to_str(data, len, strip_file_name(sv->value));
- /* It sends bad data if the file name contains ", but
- Netscape does the same */
+ /* It sends bad data if the file name contains ", but
+ Netscape does the same */
add_to_str(data, len, cast_uchar "\"");
- if (*sv->value) if ((ct = get_content_type(NULL, sv->value))) {
- add_to_str(data, len, cast_uchar "\r\nContent-Type: ");
- add_to_str(data, len, ct);
- if (strlen(cast_const_char ct) >= 4 && !casecmp(ct, cast_uchar "text", 4)) {
- add_to_str(data, len, cast_uchar "; charset=");
- add_to_str(data, len, get_cp_mime_name(term_charset(ses->term)));
+ if (*sv->value)
+ if ((ct = get_content_type(NULL, sv->value))) {
+ add_to_str(data, len,
+ cast_uchar
+ "\r\nContent-Type: ");
+ add_to_str(data, len, ct);
+ if (strlen(cast_const_char ct) >= 4
+ && !casecmp(ct, cast_uchar "text",
+ 4)) {
+ add_to_str(data, len,
+ cast_uchar
+ "; charset=");
+ add_to_str(data, len,
+ get_cp_mime_name(
+ term_charset(
+ ses->term)));
+ }
+ free(ct);
}
- free(ct);
- }
}
add_to_str(data, len, cast_uchar "\r\n\r\n");
if (sv->type != FC_FILE_UPLOAD) {
- if (sv->type == FC_TEXT || sv->type == FC_PASSWORD || sv->type == FC_TEXTAREA)
+ if (sv->type == FC_TEXT || sv->type == FC_PASSWORD
+ || sv->type == FC_TEXTAREA)
p = convert(cp_from, cp_to, sv->value, NULL);
- else p = stracpy(sv->value);
+ else
+ p = stracpy(sv->value);
add_to_str(data, len, p);
free(p);
} else {
@@ -1662,12 +1997,16 @@ static void encode_multipart(struct session *ses, struct list_head *l, unsigned
free(wd);
}
do {
- if ((rd = hard_read(fh, buffer, F_BUFLEN)) == -1) {
+ if ((rd = hard_read(fh, buffer,
+ F_BUFLEN))
+ == -1) {
errn = errno;
EINTRLOOP(rs, close(fh));
goto error;
}
- if (rd) add_bytes_to_str(data, len, buffer, rd);
+ if (rd)
+ add_bytes_to_str(data, len,
+ buffer, rd);
} while (rd);
EINTRLOOP(rs, close(fh));
}
@@ -1681,49 +2020,65 @@ static void encode_multipart(struct session *ses, struct list_head *l, unsigned
add_to_str(data, len, cast_uchar "--\r\n");
memset(bound, '-', BL1);
memset(bound + BL1, '0', BL - BL1);
- again:
+again:
for (i = 0; i <= *len - BL; i++) {
- for (j = 0; j < BL; j++) if ((*data)[i + j] != bound[j]) goto nb;
+ for (j = 0; j < BL; j++)
+ if ((*data)[i + j] != bound[j])
+ goto nb;
for (j = BL - 1; j >= 0; j--) {
- if (bound[j] < '0') bound[j] = '0' - 1;
- if (bound[j]++ >= '9') bound[j] = '0';
- else goto again;
+ if (bound[j] < '0')
+ bound[j] = '0' - 1;
+ if (bound[j]++ >= '9')
+ bound[j] = '0';
+ else
+ goto again;
}
internal("Could not assign boundary");
- nb:;
+nb:;
}
- for (i = 0; i < nbound_ptrs; i++) memcpy(*data + bound_ptrs[i], bound, BL);
+ for (i = 0; i < nbound_ptrs; i++)
+ memcpy(*data + bound_ptrs[i], bound, BL);
free(bound_ptrs);
return;
- error:
+error:
free(bound_ptrs);
free(*data);
*data = NULL;
m1 = stracpy(sv->value);
m2 = stracpy(cast_uchar strerror(errn));
- msg_box(ses->term, getml(m1, m2, NULL), TEXT_(T_ERROR_WHILE_POSTING_FORM), AL_CENTER, TEXT_(T_COULD_NOT_GET_FILE), cast_uchar " ", m1, cast_uchar ": ", m2, MSG_BOX_END, (void *)ses, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ msg_box(ses->term, getml(m1, m2, NULL),
+ TEXT_(T_ERROR_WHILE_POSTING_FORM), AL_CENTER,
+ TEXT_(T_COULD_NOT_GET_FILE), cast_uchar " ", m1,
+ cast_uchar ": ", m2, MSG_BOX_END, (void *)ses, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
return;
- not_allowed:
+not_allowed:
free(bound_ptrs);
free(*data);
*data = NULL;
- msg_box(ses->term, NULL, TEXT_(T_ERROR_WHILE_POSTING_FORM), AL_CENTER, TEXT_(T_READING_FILES_IS_NOT_ALLOWED), MSG_BOX_END, (void *)ses, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ msg_box(ses->term, NULL, TEXT_(T_ERROR_WHILE_POSTING_FORM), AL_CENTER,
+ TEXT_(T_READING_FILES_IS_NOT_ALLOWED), MSG_BOX_END, (void *)ses,
+ 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
}
-void reset_form(struct f_data_c *f, int form_num)
+void
+reset_form(struct f_data_c *f, int form_num)
{
struct form_control *form = NULL;
struct list_head *lform;
- foreach(struct form_control, form, lform, f->f_data->forms) if (form->form_num == form_num) {
- struct form_state *fs;
- fs = find_form_state(f, form);
- init_ctrl(form, fs);
- }
+ foreach (struct form_control, form, lform, f->f_data->forms)
+ if (form->form_num == form_num) {
+ struct form_state *fs;
+ fs = find_form_state(f, form);
+ init_ctrl(form, fs);
+ }
}
-unsigned char *get_form_url(struct session *ses, struct f_data_c *f, struct form_control *form, int *onsubmit)
+unsigned char *
+get_form_url(struct session *ses, struct f_data_c *f, struct form_control *form,
+ int *onsubmit)
{
struct list_head submit;
unsigned char *data;
@@ -1731,24 +2086,28 @@ unsigned char *get_form_url(struct session *ses, struct f_data_c *f, struct form
int len;
unsigned char *go = NULL;
int cp_from, cp_to;
- if (!form) return NULL;
+ if (!form)
+ return NULL;
if (form->type == FC_RESET) {
reset_form(f, form->form_num);
return NULL;
}
- if (onsubmit)*onsubmit=0;
- if (!form->action) return NULL;
+ if (onsubmit)
+ *onsubmit = 0;
+ if (!form->action)
+ return NULL;
get_succesful_controls(f, form, &submit);
cp_from = term_charset(ses->term);
cp_to = f->f_data->cp;
if (form->method == FM_GET || form->method == FM_POST)
encode_controls(&submit, &data, &len, cp_from, cp_to);
else
- encode_multipart(ses, &submit, &data, &len, bound, cp_from, cp_to);
- if (!data) goto ff;
- if (!casecmp(form->action, cast_uchar "javascript:", 11))
- {
- go=stracpy(form->action);
+ encode_multipart(ses, &submit, &data, &len, bound, cp_from,
+ cp_to);
+ if (!data)
+ goto ff;
+ if (!casecmp(form->action, cast_uchar "javascript:", 11)) {
+ go = stracpy(form->action);
goto x;
}
if (form->method == FM_GET) {
@@ -1756,12 +2115,15 @@ unsigned char *get_form_url(struct session *ses, struct f_data_c *f, struct form
size_t q;
go = stracpy(form->action);
pos = extract_position(go);
- if (!(da = get_url_data(go))) da = go;
+ if (!(da = get_url_data(go)))
+ da = go;
q = strlen(cast_const_char da);
if (q && (da[q - 1] == '&' || da[q - 1] == '?'))
;
- else if (strchr(cast_const_char da, '?')) add_to_strn(&go, cast_uchar "&");
- else add_to_strn(&go, cast_uchar "?");
+ else if (strchr(cast_const_char da, '?'))
+ add_to_strn(&go, cast_uchar "&");
+ else
+ add_to_strn(&go, cast_uchar "?");
add_to_strn(&go, data);
if (pos) {
add_to_strn(&go, pos);
@@ -1773,9 +2135,13 @@ unsigned char *get_form_url(struct session *ses, struct f_data_c *f, struct form
go = init_str();
add_to_str(&go, &l, form->action);
add_chr_to_str(&go, &l, POST_CHAR);
- if (form->method == FM_POST) add_to_str(&go, &l, cast_uchar "application/x-www-form-urlencoded\n");
+ if (form->method == FM_POST)
+ add_to_str(&go, &l,
+ cast_uchar
+ "application/x-www-form-urlencoded\n");
else {
- add_to_str(&go, &l, cast_uchar "multipart/form-data; boundary=");
+ add_to_str(&go, &l,
+ cast_uchar "multipart/form-data; boundary=");
add_bytes_to_str(&go, &l, bound, BL);
add_to_str(&go, &l, cast_uchar "\n");
}
@@ -1785,17 +2151,20 @@ unsigned char *get_form_url(struct session *ses, struct f_data_c *f, struct form
add_to_str(&go, &l, p);
}
}
- x:
+x:
free(data);
- ff:
+ff:
free_succesful_controls(&submit);
return go;
}
int ismap_link = 0, ismap_x = 1, ismap_y = 1;
-/* if onsubmit is not NULL it will contain 1 if link is submit and the form has an onsubmit handler */
-static unsigned char *get_link_url(struct session *ses, struct f_data_c *f, struct link *l, int *onsubmit)
+/* if onsubmit is not NULL it will contain 1 if link is submit and the form has
+ * an onsubmit handler */
+static unsigned char *
+get_link_url(struct session *ses, struct f_data_c *f, struct link *l,
+ int *onsubmit)
{
if (l->type == L_LINK) {
if (!l->where) {
@@ -1803,10 +2172,15 @@ static unsigned char *get_link_url(struct session *ses, struct f_data_c *f, stru
return stracpy(l->where_img);
return NULL;
}
- if (ismap_link && strlen(cast_const_char l->where) >= 4 && !strcmp(cast_const_char(l->where + strlen(cast_const_char l->where) - 4), "?0,0")) {
+ if (ismap_link && strlen(cast_const_char l->where) >= 4
+ && !strcmp(
+ cast_const_char(l->where
+ + strlen(cast_const_char l->where) - 4),
+ "?0,0")) {
unsigned char *nu = init_str();
int ll = 0;
- add_bytes_to_str(&nu, &ll, l->where, strlen(cast_const_char l->where) - 3);
+ add_bytes_to_str(&nu, &ll, l->where,
+ strlen(cast_const_char l->where) - 3);
add_num_to_str(&nu, &ll, ismap_x);
add_chr_to_str(&nu, &ll, ',');
add_num_to_str(&nu, &ll, ismap_y);
@@ -1814,11 +2188,13 @@ static unsigned char *get_link_url(struct session *ses, struct f_data_c *f, stru
}
return stracpy(l->where);
}
- if (l->type != L_BUTTON && l->type != L_FIELD) return NULL;
+ if (l->type != L_BUTTON && l->type != L_FIELD)
+ return NULL;
return get_form_url(ses, f, l->form, onsubmit);
}
-static struct menu_item *clone_select_menu(struct menu_item *m)
+static struct menu_item *
+clone_select_menu(struct menu_item *m)
{
struct menu_item *n = NULL;
int i = 0;
@@ -1833,13 +2209,15 @@ static struct menu_item *clone_select_menu(struct menu_item *m)
n[i].free_i = 0;
if ((n[i].func = m->func) != do_select_submenu) {
n[i].data = m->data;
- } else n[i].data = clone_select_menu(m->data);
+ } else
+ n[i].data = clone_select_menu(m->data);
i++;
} while (m++->text);
return n;
}
-static void free_select_menu(void *m_)
+static void
+free_select_menu(void *m_)
{
struct menu_item *m = (struct menu_item *)m_;
struct menu_item *om = m;
@@ -1847,57 +2225,71 @@ static void free_select_menu(void *m_)
free(m->text);
free(m->rtext);
free(m->hotkey);
- if (m->func == do_select_submenu) free_select_menu(m->data);
+ if (m->func == do_select_submenu)
+ free_select_menu(m->data);
} while (m++->text);
free(om);
}
-void set_frame(struct session *ses, struct f_data_c *f, int a)
+void
+set_frame(struct session *ses, struct f_data_c *f, int a)
{
- if (f == ses->screen) return;
- if (!f->loc->url) return;
+ if (f == ses->screen)
+ return;
+ if (!f->loc->url)
+ return;
goto_url_not_from_dialog(ses, f->loc->url, ses->screen);
}
-static struct link *get_current_link(struct f_data_c *f)
+static struct link *
+get_current_link(struct f_data_c *f)
{
- if (!f || !f->f_data || !f->vs) return NULL;
+ if (!f || !f->f_data || !f->vs)
+ return NULL;
if (f->vs->current_link >= 0 && f->vs->current_link < f->f_data->nlinks)
return &f->f_data->links[f->vs->current_link];
return NULL;
}
-/* pokud je a==1, tak se nebude submitovat formular, kdyz kliknu na input field a formular nema submit */
-int enter(struct session *ses, struct f_data_c *f, int a)
+/* pokud je a==1, tak se nebude submitovat formular, kdyz kliknu na input field
+ * a formular nema submit */
+int
+enter(struct session *ses, struct f_data_c *f, int a)
{
struct link *link;
unsigned char *u;
link = get_current_link(f);
- if (!link) return 1;
+ if (!link)
+ return 1;
if (link->type == L_LINK || link->type == L_BUTTON) {
int has_onsubmit;
- if (link->type==L_BUTTON&&link->form->type==FC_BUTTON)return 1;
- submit:
+ if (link->type == L_BUTTON && link->form->type == FC_BUTTON)
+ return 1;
+submit:
if ((u = get_link_url(ses, f, link, &has_onsubmit))) {
- if (strlen(cast_const_char u) >= 4 && !casecmp(u, cast_uchar "MAP@", 4)) {
- goto_imgmap(ses, f, u + 4, stracpy(u + 4), stracpy(link->target));
- } else if (ses->ds.target_in_new_window && link->target && *link->target && !find_frame(ses, link->target, f) && can_open_in_new(ses->term)) { /* open in new window */
+ if (strlen(cast_const_char u) >= 4
+ && !casecmp(u, cast_uchar "MAP@", 4)) {
+ goto_imgmap(ses, f, u + 4, stracpy(u + 4),
+ stracpy(link->target));
+ } else if (ses->ds.target_in_new_window && link->target
+ && *link->target
+ && !find_frame(ses, link->target, f)
+ && can_open_in_new(
+ ses->term)) { /* open in new window */
free(ses->wtd_target);
ses->wtd_target = stracpy(link->target);
- open_in_new_window(ses->term, (void *)&send_open_in_new_xterm_ptr, ses);
+ open_in_new_window(
+ ses->term,
+ (void *)&send_open_in_new_xterm_ptr, ses);
free(ses->wtd_target);
- ses->wtd_target=NULL;
+ ses->wtd_target = NULL;
} else {
- goto_url_f(
- ses,
- NULL,
- u,
- link->target,
- f,
- (link->type==L_BUTTON&&link->form&&link->form->type==FC_SUBMIT)?link->form->form_num:-1,
- 0
- ,0,0
- );
+ goto_url_f(ses, NULL, u, link->target, f,
+ (link->type == L_BUTTON && link->form
+ && link->form->type == FC_SUBMIT)
+ ? link->form->form_num
+ : -1,
+ 0, 0, 0);
}
free(u);
return 2;
@@ -1906,14 +2298,19 @@ int enter(struct session *ses, struct f_data_c *f, int a)
}
if (link->type == L_CHECKBOX) {
struct form_state *fs = find_form_state(f, link->form);
- if (link->form->ro) return 1;
- if (link->form->type == FC_CHECKBOX) fs->state = !fs->state;
+ if (link->form->ro)
+ return 1;
+ if (link->form->type == FC_CHECKBOX)
+ fs->state = !fs->state;
else {
struct form_control *fc = NULL;
struct list_head *lfc;
- foreach(struct form_control, fc, lfc, f->f_data->forms)
- if (fc->form_num == link->form->form_num && fc->type == FC_RADIO && !xstrcmp(fc->name, link->form->name)) {
- struct form_state *fffs = find_form_state(f, fc);
+ foreach (struct form_control, fc, lfc, f->f_data->forms)
+ if (fc->form_num == link->form->form_num
+ && fc->type == FC_RADIO
+ && !xstrcmp(fc->name, link->form->name)) {
+ struct form_state *fffs =
+ find_form_state(f, fc);
fffs->state = 0;
}
fs = find_form_state(f, link->form);
@@ -1923,16 +2320,19 @@ int enter(struct session *ses, struct f_data_c *f, int a)
}
if (link->type == L_SELECT) {
struct menu_item *m;
- if (link->form->ro) return 1;
+ if (link->form->ro)
+ return 1;
m = clone_select_menu(link->form->menu);
- if (!m) return 1;
+ if (!m)
+ return 1;
/* execute onfocus code of the select object */
add_empty_window(ses->term, free_select_menu, m);
do_select_submenu(ses->term, m, ses);
return 1;
}
if (link->type == L_FIELD || link->type == L_AREA) {
- /* pri enteru v textovem policku se bude posilat vzdycky -- Brain */
+ /* pri enteru v textovem policku se bude posilat vzdycky --
+ * Brain */
if (!has_form_submit(f->f_data, link->form) && !a)
goto submit;
down(ses, f, 0);
@@ -1942,19 +2342,25 @@ int enter(struct session *ses, struct f_data_c *f, int a)
return 1;
}
-void toggle(struct session *ses, struct f_data_c *f, int a)
+void
+toggle(struct session *ses, struct f_data_c *f, int a)
{
if (!f || !f->vs) {
- msg_box(ses->term, NULL, TEXT_(T_TOGGLE_HTML_PLAIN), AL_LEFT, TEXT_(T_YOU_ARE_NOWHERE), MSG_BOX_END, NULL, 1, TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
+ msg_box(ses->term, NULL, TEXT_(T_TOGGLE_HTML_PLAIN), AL_LEFT,
+ TEXT_(T_YOU_ARE_NOWHERE), MSG_BOX_END, NULL, 1,
+ TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
return;
}
- if (f->vs->plain == -1) f->vs->plain = 1;
- else f->vs->plain = f->vs->plain ^ 1;
+ if (f->vs->plain == -1)
+ f->vs->plain = 1;
+ else
+ f->vs->plain = f->vs->plain ^ 1;
html_interpret_recursive(f);
draw_formatted(ses);
}
-void selected_item(struct terminal *term, void *pitem, void *ses_)
+void
+selected_item(struct terminal *term, void *pitem, void *ses_)
{
struct session *ses = (struct session *)ses_;
int item = (int)(long)pitem;
@@ -1963,8 +2369,10 @@ void selected_item(struct terminal *term, void *pitem, void *ses_)
struct form_state *fs;
struct form_control *form;
l = get_current_link(f);
- if (!l) return;
- if (l->type != L_SELECT) return;
+ if (!l)
+ return;
+ if (l->type != L_SELECT)
+ return;
form = l->form;
fs = find_form_state(f, form);
if (item >= 0 && item < form->nvalues) {
@@ -1980,25 +2388,30 @@ void selected_item(struct terminal *term, void *pitem, void *ses_)
print_screen_status(ses);
}
-int get_current_state(struct session *ses)
+int
+get_current_state(struct session *ses)
{
struct f_data_c *f = current_frame(ses);
struct link *l;
struct form_state *fs;
l = get_current_link(f);
- if (!l) return -1;
- if (l->type != L_SELECT) return -1;
+ if (!l)
+ return -1;
+ if (l->type != L_SELECT)
+ return -1;
fs = find_form_state(f, l->form);
return fs->state;
}
-static int find_pos_in_link(struct f_data_c *fd,struct link *l,struct links_event *ev,int *xx,int *yy);
+static int find_pos_in_link(struct f_data_c *fd, struct link *l,
+ struct links_event *ev, int *xx, int *yy);
-static void set_form_position(struct f_data_c *fd, struct link *l, struct links_event *ev)
+static void
+set_form_position(struct f_data_c *fd, struct link *l, struct links_event *ev)
{
/* if links is a field, set cursor position */
if (l->form && (l->type == L_AREA || l->type == L_FIELD)) {
- struct form_state *fs = find_form_state(fd,l->form);
+ struct form_state *fs = find_form_state(fd, l->form);
int xx = 0, yy = 0; /* against uninitialized warning */
if (l->type == L_AREA) {
@@ -2013,19 +2426,25 @@ static void set_form_position(struct f_data_c *fd, struct link *l, struct links_
if (yy >= 0) {
unsigned char *ptr;
fs->state = ftce->ln[yy].st_offs;
- ptr = textptr_add(fs->string + fs->state, xx, fd->f_data->opt.cp);
- if (ptr > fs->string + ftce->ln[yy].en_offs)
- ptr = fs->string + ftce->ln[yy].en_offs;
+ ptr =
+ textptr_add(fs->string + fs->state,
+ xx, fd->f_data->opt.cp);
+ if (ptr
+ > fs->string + ftce->ln[yy].en_offs)
+ ptr = fs->string
+ + ftce->ln[yy].en_offs;
fs->state = (int)(ptr - fs->string);
goto br;
}
- fs->state = (int)strlen(cast_const_char fs->string);
- br:;
+ fs->state =
+ (int)strlen(cast_const_char fs->string);
+br:;
}
} else if (l->type == L_FIELD) {
if (!find_pos_in_link(fd, l, ev, &xx, &yy)) {
unsigned char *ptr;
- ptr = textptr_add(fs->string + fs->vpos, xx, fd->f_data->opt.cp);
+ ptr = textptr_add(fs->string + fs->vpos, xx,
+ fd->f_data->opt.cp);
fs->state = (int)(ptr - fs->string);
}
}
@@ -2034,7 +2453,8 @@ static void set_form_position(struct f_data_c *fd, struct link *l, struct links_
}
}
-static int textarea_adjust_viewport(struct f_data_c *fd, struct link *l)
+static int
+textarea_adjust_viewport(struct f_data_c *fd, struct link *l)
{
struct form_control *fc = l->form;
struct view_state *vs = fd->vs;
@@ -2060,7 +2480,9 @@ static int textarea_adjust_viewport(struct f_data_c *fd, struct link *l)
return r;
}
-int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct links_event *ev)
+int
+field_op(struct session *ses, struct f_data_c *f, struct link *l,
+ struct links_event *ev)
{
struct form_control *form = l->form;
struct form_state *fs;
@@ -2072,19 +2494,23 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
internal("link has no form control");
return 0;
}
- if (form->ro == 2) return 0;
+ if (form->ro == 2)
+ return 0;
fs = find_form_state(f, form);
- if (!fs->string) return 0;
+ if (!fs->string)
+ return 0;
if (ev->ev == EV_KBD) {
if (!(ev->y & (KBD_CTRL | KBD_ALT)) && ev->x >= ' ') {
- if (!form->ro && strlen((char *)fs->string) < form->maxlength) {
+ if (!form->ro
+ && strlen((char *)fs->string) < form->maxlength) {
unsigned char *v;
unsigned char a_[2];
unsigned char *nw;
int ll;
free_format_text_cache_entry(fs);
- v = fs->string = xrealloc(fs->string,
- strlen(cast_const_char fs->string) + 12);
+ v = fs->string = xrealloc(
+ fs->string,
+ strlen(cast_const_char fs->string) + 12);
if (f->f_data->opt.cp) {
nw = a_;
a_[0] = (unsigned char)ev->x;
@@ -2093,23 +2519,29 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
nw = encode_utf_8(ev->x);
}
ll = (int)strlen(cast_const_char nw);
- if (ll > 10) goto done;
- memmove(v + fs->state + ll, v + fs->state, strlen(cast_const_char(v + fs->state)) + 1);
+ if (ll > 10)
+ goto done;
+ memmove(v + fs->state + ll, v + fs->state,
+ strlen(cast_const_char(v + fs->state))
+ + 1);
memcpy(&v[fs->state], nw, ll);
fs->state += ll;
}
goto done;
} else if (!(ev->y & (KBD_SHIFT | KBD_CTRL | KBD_ALT))
- && ev->x == KBD_ENTER
- && form->type == FC_TEXTAREA) {
+ && ev->x == KBD_ENTER && form->type == FC_TEXTAREA) {
if (!form->ro
- && strlen(cast_const_char fs->string) < (size_t)form->maxlength) {
+ && strlen(cast_const_char fs->string)
+ < (size_t)form->maxlength) {
unsigned char *v;
free_format_text_cache_entry(fs);
v = xrealloc(fs->string,
- strlen(cast_const_char fs->string) + 2);
+ strlen(cast_const_char fs->string)
+ + 2);
fs->string = v;
- memmove(v + fs->state + 1, v + fs->state, strlen(cast_const_char(v + fs->state)) + 1);
+ memmove(v + fs->state + 1, v + fs->state,
+ strlen(cast_const_char(v + fs->state))
+ + 1);
v[fs->state++] = '\n';
}
goto done;
@@ -2127,16 +2559,21 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
fs->state = (int)(p - fs->string);
}
} else if (ev->x == KBD_RIGHT) {
- if ((size_t)fs->state < strlen(cast_const_char fs->string)) {
+ if ((size_t)fs->state
+ < strlen(cast_const_char fs->string)) {
if (f->f_data->opt.cp)
fs->state = fs->state + 1;
else {
- unsigned char *p = fs->string + fs->state;
+ unsigned char *p =
+ fs->string + fs->state;
FWD_UTF_8(p);
fs->state = (int)(p - fs->string);
}
- } else fs->state = (int)strlen(cast_const_char fs->string);
- } else if ((ev->x == KBD_HOME || (upcase(ev->x) == 'A' && ev->y & KBD_CTRL))) {
+ } else
+ fs->state =
+ (int)strlen(cast_const_char fs->string);
+ } else if ((ev->x == KBD_HOME
+ || (upcase(ev->x) == 'A' && ev->y & KBD_CTRL))) {
if (form->type == FC_TEXTAREA) {
ftce = format_text(f, form, fs);
y = find_cursor_line(ftce, fs->state);
@@ -2145,26 +2582,48 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
goto done;
}
fs->state = 0;
- } else fs->state = 0;
- } else if (ev->x == KBD_END || (upcase(ev->x) == 'E' && ev->y & KBD_CTRL)) {
+ } else
+ fs->state = 0;
+ } else if (ev->x == KBD_END
+ || (upcase(ev->x) == 'E' && ev->y & KBD_CTRL)) {
if (form->type == FC_TEXTAREA) {
ftce = format_text(f, form, fs);
y = find_cursor_line(ftce, fs->state);
if (y >= 0) {
fs->state = ftce->ln[y].en_offs;
- if (fs->state && y < ftce->n_lines - 1 && ftce->ln[y + 1].st_offs == ftce->ln[y].en_offs)
+ if (fs->state && y < ftce->n_lines - 1
+ && ftce->ln[y + 1].st_offs
+ == ftce->ln[y].en_offs)
fs->state--;
goto done;
}
- fs->state = (int)strlen(cast_const_char fs->string);
- } else fs->state = (int)strlen(cast_const_char fs->string);
+ fs->state =
+ (int)strlen(cast_const_char fs->string);
+ } else
+ fs->state =
+ (int)strlen(cast_const_char fs->string);
} else if (ev->x == KBD_UP) {
if (form->type == FC_TEXTAREA) {
ftce = format_text(f, form, fs);
y = find_cursor_line(ftce, fs->state);
if (y > 0) {
- fs->state = (int)(textptr_add(fs->string + ftce->ln[y - 1].st_offs, textptr_diff(fs->string + fs->state, fs->string + ftce->ln[y].st_offs, f->f_data->opt.cp), f->f_data->opt.cp) - fs->string);
- if (fs->state > ftce->ln[y - 1].en_offs) fs->state = ftce->ln[y - 1].en_offs;
+ fs->state =
+ (int)(textptr_add(
+ fs->string
+ + ftce->ln[y - 1]
+ .st_offs,
+ textptr_diff(
+ fs->string
+ + fs->state,
+ fs->string
+ + ftce->ln[y]
+ .st_offs,
+ f->f_data->opt.cp),
+ f->f_data->opt.cp)
+ - fs->string);
+ if (fs->state > ftce->ln[y - 1].en_offs)
+ fs->state =
+ ftce->ln[y - 1].en_offs;
} else
goto b;
} else {
@@ -2178,41 +2637,76 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
if (y >= 0) {
if (y >= ftce->n_lines - 1)
goto b;
- fs->state = (int)(textptr_add(fs->string + ftce->ln[y + 1].st_offs, textptr_diff(fs->string + fs->state, fs->string + ftce->ln[y].st_offs, f->f_data->opt.cp), f->f_data->opt.cp) - fs->string);
+ fs->state =
+ (int)(textptr_add(
+ fs->string
+ + ftce->ln[y + 1]
+ .st_offs,
+ textptr_diff(
+ fs->string
+ + fs->state,
+ fs->string
+ + ftce->ln[y]
+ .st_offs,
+ f->f_data->opt.cp),
+ f->f_data->opt.cp)
+ - fs->string);
if (fs->state > ftce->ln[y + 1].en_offs)
- fs->state = ftce->ln[y + 1].en_offs;
- } else
+ fs->state =
+ ftce->ln[y + 1].en_offs;
+ } else
goto b;
} else {
r = 0;
f->vs->brl_in_field = 0;
}
- } else if ((ev->x == KBD_INS && ev->y & KBD_CTRL) || (upcase(ev->x) == 'B' && ev->y & KBD_CTRL) || ev->x == KBD_COPY) {
+ } else if ((ev->x == KBD_INS && ev->y & KBD_CTRL)
+ || (upcase(ev->x) == 'B' && ev->y & KBD_CTRL)
+ || ev->x == KBD_COPY) {
set_clipboard_text(ses->term, fs->string);
- } else if ((ev->x == KBD_DEL && ev->y & KBD_SHIFT) || (upcase(ev->x) == 'X' && ev->y & KBD_CTRL) || ev->x == KBD_CUT) {
+ } else if ((ev->x == KBD_DEL && ev->y & KBD_SHIFT)
+ || (upcase(ev->x) == 'X' && ev->y & KBD_CTRL)
+ || ev->x == KBD_CUT) {
set_clipboard_text(ses->term, fs->string);
if (!form->ro) {
free_format_text_cache_entry(fs);
fs->string[0] = 0;
}
fs->state = 0;
- } else if ((ev->x == KBD_INS && ev->y & KBD_SHIFT) || (upcase(ev->x) == 'V' && ev->y & KBD_CTRL) || ev->x == KBD_PASTE) {
+ } else if ((ev->x == KBD_INS && ev->y & KBD_SHIFT)
+ || (upcase(ev->x) == 'V' && ev->y & KBD_CTRL)
+ || ev->x == KBD_PASTE) {
unsigned char *clipboard;
clipboard = get_clipboard_text(ses->term);
- if (!clipboard) goto done;
+ if (!clipboard)
+ goto done;
if (form->type != FC_TEXTAREA) {
unsigned char *nl = clipboard;
- while ((nl = cast_uchar strchr(cast_const_char nl, '\n'))) *nl = ' ';
+ while ((nl = cast_uchar strchr(
+ cast_const_char nl, '\n')))
+ *nl = ' ';
}
- if (!form->ro && strlen(cast_const_char fs->string) + strlen(cast_const_char clipboard) <= form->maxlength) {
+ if (!form->ro
+ && strlen(cast_const_char fs->string)
+ + strlen(cast_const_char clipboard)
+ <= form->maxlength) {
unsigned char *v;
free_format_text_cache_entry(fs);
- v = xrealloc(fs->string,
- strlen(cast_const_char fs->string) + strlen(cast_const_char clipboard) + 1);
+ v = xrealloc(
+ fs->string,
+ strlen(cast_const_char fs->string)
+ + strlen(cast_const_char clipboard)
+ + 1);
fs->string = v;
- memmove(v + fs->state + strlen(cast_const_char clipboard), v + fs->state, strlen(cast_const_char v) - fs->state + 1);
- memcpy(v + fs->state, clipboard, strlen(cast_const_char clipboard));
- fs->state += (int)strlen(cast_const_char clipboard);
+ memmove(v + fs->state
+ + strlen(cast_const_char clipboard),
+ v + fs->state,
+ strlen(cast_const_char v) - fs->state
+ + 1);
+ memcpy(v + fs->state, clipboard,
+ strlen(cast_const_char clipboard));
+ fs->state +=
+ (int)strlen(cast_const_char clipboard);
}
free(clipboard);
} else if (ev->x == KBD_ENTER)
@@ -2222,25 +2716,37 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
int ll = 1;
free_format_text_cache_entry(fs);
if (!f->f_data->opt.cp) {
- unsigned char *p = fs->string + fs->state;
+ unsigned char *p =
+ fs->string + fs->state;
BACK_UTF_8(p, fs->string);
ll = (int)(fs->string + fs->state - p);
}
- memmove(fs->string + fs->state - ll, fs->string + fs->state, strlen(cast_const_char(fs->string + fs->state)) + 1);
+ memmove(fs->string + fs->state - ll,
+ fs->string + fs->state,
+ strlen(cast_const_char(fs->string
+ + fs->state))
+ + 1);
fs->state -= ll;
}
- } else if (ev->x == KBD_DEL || (upcase(ev->x) == 'D' && ev->y & KBD_CTRL)) {
+ } else if (ev->x == KBD_DEL
+ || (upcase(ev->x) == 'D' && ev->y & KBD_CTRL)) {
int ll = 1;
if (ev->x == KBD_DEL && !f->last_captured)
return 0;
if (!f->f_data->opt.cp) {
- unsigned char *p = fs->string+ fs->state;
+ unsigned char *p = fs->string + fs->state;
FWD_UTF_8(p);
- ll = (int)(p - (fs->string+ fs->state));
+ ll = (int)(p - (fs->string + fs->state));
}
- if (!form->ro && (size_t)fs->state < strlen(cast_const_char fs->string)) {
+ if (!form->ro
+ && (size_t)fs->state
+ < strlen(cast_const_char fs->string)) {
free_format_text_cache_entry(fs);
- memmove(fs->string + fs->state, fs->string + fs->state + ll, strlen(cast_const_char(fs->string + fs->state + ll)) + 1);
+ memmove(fs->string + fs->state,
+ fs->string + fs->state + ll,
+ strlen(cast_const_char(
+ fs->string + fs->state + ll))
+ + 1);
}
} else if (upcase(ev->x) == 'U' && ev->y & KBD_CTRL) {
unsigned char *a;
@@ -2249,7 +2755,10 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
free(a);
if (!form->ro) {
free_format_text_cache_entry(fs);
- memmove(fs->string, fs->string + fs->state, strlen(cast_const_char(fs->string + fs->state)) + 1);
+ memmove(fs->string, fs->string + fs->state,
+ strlen(cast_const_char(fs->string
+ + fs->state))
+ + 1);
}
fs->state = 0;
} else if (upcase(ev->x) == 'K' && ev->y & KBD_CTRL) {
@@ -2258,27 +2767,49 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
ftce = format_text(f, form, fs);
y = find_cursor_line(ftce, fs->state);
if (y >= 0) {
- int l = ftce->ln[y].en_offs - ftce->ln[y].st_offs;
- unsigned char *start_line = fs->string + ftce->ln[y].st_offs;
- unsigned char *cp = memacpy(start_line, ftce->ln[y].en_offs - ftce->ln[y].st_offs);
- set_clipboard_text(ses->term, cp);
+ int l = ftce->ln[y].en_offs
+ - ftce->ln[y].st_offs;
+ unsigned char *start_line =
+ fs->string
+ + ftce->ln[y].st_offs;
+ unsigned char *cp = memacpy(
+ start_line,
+ ftce->ln[y].en_offs
+ - ftce->ln[y].st_offs);
+ set_clipboard_text(ses->term,
+ cp);
free(cp);
- l += y < ftce->n_lines - 1 && ftce->ln[y + 1].st_offs > ftce->ln[y].en_offs;
- memmove(fs->string + ftce->ln[y].st_offs, fs->string + ftce->ln[y].st_offs + l, strlen(cast_const_char(fs->string + ftce->ln[y].st_offs + l)) + 1);
+ l += y < ftce->n_lines - 1
+ && ftce->ln[y + 1].st_offs
+ > ftce->ln[y]
+ .en_offs;
+ memmove(
+ fs->string
+ + ftce->ln[y].st_offs,
+ fs->string
+ + ftce->ln[y].st_offs
+ + l,
+ strlen(cast_const_char(
+ fs->string
+ + ftce->ln[y].st_offs
+ + l))
+ + 1);
fs->state = ftce->ln[y].st_offs;
}
} else {
- set_clipboard_text(ses->term, fs->state + fs->string);
+ set_clipboard_text(
+ ses->term, fs->state + fs->string);
fs->string[fs->state] = 0;
}
free_format_text_cache_entry(fs);
}
} else {
- b:
+b:
f->vs->brl_in_field = 0;
r = 0;
}
- } else if (ev->ev == EV_MOUSE && BM_IS_WHEEL(ev->b) && form->type == FC_TEXTAREA) {
+ } else if (ev->ev == EV_MOUSE && BM_IS_WHEEL(ev->b)
+ && form->type == FC_TEXTAREA) {
int xdiff = 0, ydiff = 0;
int x;
unsigned char *ap;
@@ -2286,12 +2817,14 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
ftce = format_text(f, form, fs);
y = find_cursor_line(ftce, fs->state);
if (y >= 0)
- x = textptr_diff(fs->string + fs->state, fs->string + ftce->ln[y].st_offs, f->f_data->opt.cp);
+ x = textptr_diff(fs->string + fs->state,
+ fs->string + ftce->ln[y].st_offs,
+ f->f_data->opt.cp);
else {
x = 0;
y = 0;
}
-
+
if ((ev->b & BM_BUTT) == B_WHEELUP)
ydiff = form->rows >= 5 ? -5 : -form->rows;
else if ((ev->b & BM_BUTT) == B_WHEELUP1)
@@ -2312,8 +2845,10 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
if (ydiff) {
int target_y = -1;
fs->vypos += ydiff;
- if (fs->vypos > ftce->n_lines - form->rows) fs->vypos = ftce->n_lines - form->rows;
- if (fs->vypos < 0) fs->vypos = 0;
+ if (fs->vypos > ftce->n_lines - form->rows)
+ fs->vypos = ftce->n_lines - form->rows;
+ if (fs->vypos < 0)
+ fs->vypos = 0;
if (y >= form->rows + fs->vypos) {
target_y = form->rows + fs->vypos - 1;
if (target_y < 0)
@@ -2328,31 +2863,47 @@ int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct lin
fs->state = ftce->ln[target_y].st_offs;
if (x > ftce->ln[target_y].chars)
x = ftce->ln[target_y].chars;
- ap = textptr_add(fs->string + fs->state, x, f->f_data->opt.cp);
+ ap = textptr_add(fs->string + fs->state, x,
+ f->f_data->opt.cp);
fs->state = (int)(ap - fs->string);
}
} else if (xdiff) {
int j;
int maxx = 0;
int longest = y;
- for (j = fs->vypos; j < fs->vypos + form->rows && j < ftce->n_lines; j++) {
+ for (j = fs->vypos;
+ j < fs->vypos + form->rows && j < ftce->n_lines;
+ j++) {
if (ftce->ln[j].chars > maxx) {
maxx = ftce->ln[j].chars;
longest = j;
}
}
maxx -= form->cols - 1;
- if (maxx < 0) maxx = 0;
+ if (maxx < 0)
+ maxx = 0;
fs->vpos += xdiff;
- if (fs->vpos < 0) fs->vpos = 0;
- if (fs->vpos > maxx) fs->vpos = maxx;
+ if (fs->vpos < 0)
+ fs->vpos = 0;
+ if (fs->vpos > maxx)
+ fs->vpos = maxx;
if (x > fs->vpos + form->cols - 1) {
- ap = textptr_add(fs->string + ftce->ln[y].st_offs, fs->vpos + form->cols - 1, f->f_data->opt.cp);
+ ap = textptr_add(fs->string
+ + ftce->ln[y].st_offs,
+ fs->vpos + form->cols - 1,
+ f->f_data->opt.cp);
fs->state = (int)(ap - fs->string);
} else if (x < fs->vpos) {
- ap = textptr_add(fs->string + ftce->ln[y].st_offs, fs->vpos, f->f_data->opt.cp);
- if (y < ftce->n_lines - 1 && ap >= fs->string + ftce->ln[y + 1].st_offs)
- ap = textptr_add(fs->string + ftce->ln[longest].st_offs, fs->vpos, f->f_data->opt.cp);
+ ap = textptr_add(fs->string
+ + ftce->ln[y].st_offs,
+ fs->vpos, f->f_data->opt.cp);
+ if (y < ftce->n_lines - 1
+ && ap >= fs->string
+ + ftce->ln[y + 1].st_offs)
+ ap = textptr_add(
+ fs->string
+ + ftce->ln[longest].st_offs,
+ fs->vpos, f->f_data->opt.cp);
fs->state = (int)(ap - fs->string);
}
}
@@ -2363,13 +2914,15 @@ done:
if (r) {
/* FIXME: test might be broken */
if ((ev->ev == EV_KBD && (ev->x == KBD_UP || ev->x == KBD_DOWN))
- || form->type != FC_TEXTAREA || textarea_adjust_viewport(f, l))
+ || form->type != FC_TEXTAREA
+ || textarea_adjust_viewport(f, l))
x_draw_form_entry(ses, f, l);
}
return r;
}
-void set_textarea(struct session *ses, struct f_data_c *f, int dir)
+void
+set_textarea(struct session *ses, struct f_data_c *f, int dir)
{
struct link *l = get_current_link(f);
if (l && l->type == L_AREA) {
@@ -2378,27 +2931,41 @@ void set_textarea(struct session *ses, struct f_data_c *f, int dir)
struct format_text_cache_entry *ftce;
int y;
- if (form->ro == 2) return;
+ if (form->ro == 2)
+ return;
fs = find_form_state(f, form);
- if (!fs->string) return;
+ if (!fs->string)
+ return;
ftce = format_text(f, form, fs);
y = find_cursor_line(ftce, fs->state);
if (y >= 0) {
int ty = dir < 0 ? 0 : ftce->n_lines - 1;
- if (ty < 0) return;
-
- fs->state = (int)(textptr_add(fs->string + ftce->ln[ty].st_offs, textptr_diff(fs->string + fs->state, fs->string + ftce->ln[y].st_offs, f->f_data->opt.cp), f->f_data->opt.cp) - fs->string);
- if (fs->state > ftce->ln[ty].en_offs) fs->state = ftce->ln[ty].en_offs;
+ if (ty < 0)
+ return;
+
+ fs->state =
+ (int)(textptr_add(
+ fs->string + ftce->ln[ty].st_offs,
+ textptr_diff(fs->string + fs->state,
+ fs->string
+ + ftce->ln[y].st_offs,
+ f->f_data->opt.cp),
+ f->f_data->opt.cp)
+ - fs->string);
+ if (fs->state > ftce->ln[ty].en_offs)
+ fs->state = ftce->ln[ty].en_offs;
}
}
}
-void search_for_back(void *ses_, unsigned char *str)
+void
+search_for_back(void *ses_, unsigned char *str)
{
struct session *ses = (struct session *)ses_;
struct f_data_c *f = current_frame(ses);
- if (!f || !str || !str[0]) return;
+ if (!f || !str || !str[0])
+ return;
free(ses->search_word);
ses->search_word = stracpy(str);
clr_spaces(ses->search_word, 0);
@@ -2409,11 +2976,13 @@ void search_for_back(void *ses_, unsigned char *str)
find_next(ses, f, 1);
}
-void search_for(void *ses_, unsigned char *str)
+void
+search_for(void *ses_, unsigned char *str)
{
struct session *ses = (struct session *)ses_;
struct f_data_c *f = current_frame(ses);
- if (!f || !f->vs || !f->f_data || !str || !str[0]) return;
+ if (!f || !f->vs || !f->f_data || !str || !str[0])
+ return;
free(ses->search_word);
ses->search_word = stracpy(str);
clr_spaces(ses->search_word, 0);
@@ -2424,11 +2993,12 @@ void search_for(void *ses_, unsigned char *str)
find_next(ses, f, 1);
}
-#define HASH_SIZE 4096
+#define HASH_SIZE 4096
#define HASH(p) (((p.y << 6) + p.x) & (HASH_SIZE - 1))
-static int point_intersect(struct point *p1, int l1, struct point *p2, int l2)
+static int
+point_intersect(struct point *p1, int l1, struct point *p2, int l2)
{
int i, j;
static unsigned char hash[HASH_SIZE];
@@ -2437,18 +3007,24 @@ static int point_intersect(struct point *p1, int l1, struct point *p2, int l2)
memset(hash, 0, HASH_SIZE);
init = 1;
}
- for (i = 0; i < l1; i++) hash[HASH(p1[i])] = 1;
- for (j = 0; j < l2; j++) if (hash[HASH(p2[j])]) {
- for (i = 0; i < l1; i++) if (p1[i].x == p2[j].x && p1[i].y == p2[j].y) {
- for (i = 0; i < l1; i++) hash[HASH(p1[i])] = 0;
- return 1;
+ for (i = 0; i < l1; i++)
+ hash[HASH(p1[i])] = 1;
+ for (j = 0; j < l2; j++)
+ if (hash[HASH(p2[j])]) {
+ for (i = 0; i < l1; i++)
+ if (p1[i].x == p2[j].x && p1[i].y == p2[j].y) {
+ for (i = 0; i < l1; i++)
+ hash[HASH(p1[i])] = 0;
+ return 1;
+ }
}
- }
- for (i = 0; i < l1; i++) hash[HASH(p1[i])] = 0;
+ for (i = 0; i < l1; i++)
+ hash[HASH(p1[i])] = 0;
return 0;
}
-static int find_next_link_in_search(struct f_data_c *f, int d)
+static int
+find_next_link_in_search(struct f_data_c *f, int d)
{
struct point *pt;
int len;
@@ -2456,11 +3032,16 @@ static int find_next_link_in_search(struct f_data_c *f, int d)
if (d == -2 || d == 2) {
d /= 2;
find_link(f, d, 0);
- if (f->vs->current_link == -1) return 1;
- } else nx:if (f->vs->current_link == -1 || !(next_in_view(f, f->vs->current_link + d, d, in_view, NULL))) {
- find_link(f, d, 0);
- return 1;
- }
+ if (f->vs->current_link == -1)
+ return 1;
+ } else
+nx:
+ if (f->vs->current_link == -1
+ || !(next_in_view(f, f->vs->current_link + d, d, in_view,
+ NULL))) {
+ find_link(f, d, 0);
+ return 1;
+ }
link = &f->f_data->links[f->vs->current_link];
if (get_searched(f, &pt, &len) < 0)
return 1;
@@ -2472,23 +3053,30 @@ static int find_next_link_in_search(struct f_data_c *f, int d)
goto nx;
}
-void find_next(struct session *ses, struct f_data_c *f, int a)
+void
+find_next(struct session *ses, struct f_data_c *f, int a)
{
int min, max;
int c = 0;
int p;
if (!f->f_data || !f->vs) {
- msg_box(ses->term, NULL, TEXT_(T_SEARCH), AL_CENTER, TEXT_(T_YOU_ARE_NOWHERE), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ msg_box(ses->term, NULL, TEXT_(T_SEARCH), AL_CENTER,
+ TEXT_(T_YOU_ARE_NOWHERE), MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
return;
}
p = f->vs->view_pos;
if (!a && ses->search_word) {
- if (!(find_next_link_in_search(f, ses->search_direction))) return;
+ if (!(find_next_link_in_search(f, ses->search_direction)))
+ return;
p += ses->search_direction * f->yw;
}
if (!ses->search_word) {
if (!ses->last_search_word) {
- msg_box(ses->term, NULL, TEXT_(T_SEARCH), AL_CENTER, TEXT_(T_NO_PREVIOUS_SEARCH), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ msg_box(ses->term, NULL, TEXT_(T_SEARCH), AL_CENTER,
+ TEXT_(T_NO_PREVIOUS_SEARCH), MSG_BOX_END, NULL,
+ 1, TEXT_(T_CANCEL), msg_box_null,
+ B_ENTER | B_ESC);
return;
}
ses->search_word = stracpy(ses->last_search_word);
@@ -2497,15 +3085,20 @@ void find_next(struct session *ses, struct f_data_c *f, int a)
if (get_search_data(f->f_data) < 0) {
free(ses->search_word);
ses->search_word = NULL;
- msg_box(ses->term, NULL, TEXT_(T_SEARCH), AL_CENTER, TEXT_(T_OUT_OF_MEMORY), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ msg_box(ses->term, NULL, TEXT_(T_SEARCH), AL_CENTER,
+ TEXT_(T_OUT_OF_MEMORY), MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
return;
}
do {
- if (is_in_range(f->f_data, p, f->yw, ses->search_word, &min, &max)) {
+ if (is_in_range(f->f_data, p, f->yw, ses->search_word, &min,
+ &max)) {
f->vs->view_pos = p;
if (max >= min) {
- if (max > f->vs->view_posx + f->xw) f->vs->view_posx = max - f->xw;
- if (min < f->vs->view_posx) f->vs->view_posx = min;
+ if (max > f->vs->view_posx + f->xw)
+ f->vs->view_posx = max - f->xw;
+ if (min < f->vs->view_posx)
+ f->vs->view_posx = min;
}
f->vs->orig_view_pos = f->vs->view_pos;
f->vs->orig_view_posx = f->vs->view_posx;
@@ -2513,84 +3106,109 @@ void find_next(struct session *ses, struct f_data_c *f, int a)
find_next_link_in_search(f, ses->search_direction * 2);
return;
}
- if ((p += ses->search_direction * f->yw) > f->f_data->y) p = 0;
+ if ((p += ses->search_direction * f->yw) > f->f_data->y)
+ p = 0;
if (p < 0) {
p = 0;
- while (p < f->f_data->y) p += f->yw ? f->yw : 1;
+ while (p < f->f_data->y)
+ p += f->yw ? f->yw : 1;
p -= f->yw;
}
} while ((c += f->yw ? f->yw : 1) < f->f_data->y + f->yw);
- msg_box(ses->term, NULL, TEXT_(T_SEARCH), AL_CENTER, TEXT_(T_SEARCH_STRING_NOT_FOUND), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ msg_box(ses->term, NULL, TEXT_(T_SEARCH), AL_CENTER,
+ TEXT_(T_SEARCH_STRING_NOT_FOUND), MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
}
-void find_next_back(struct session *ses, struct f_data_c *f, int a)
+void
+find_next_back(struct session *ses, struct f_data_c *f, int a)
{
- ses->search_direction = - ses->search_direction;
+ ses->search_direction = -ses->search_direction;
find_next(ses, f, a);
- ses->search_direction = - ses->search_direction;
+ ses->search_direction = -ses->search_direction;
}
-static void rep_ev(struct session *ses, struct f_data_c *fd, void (*f)(struct session *, struct f_data_c *, int), int a)
+static void
+rep_ev(struct session *ses, struct f_data_c *fd,
+ void (*f)(struct session *, struct f_data_c *, int), int a)
{
int i = ses->kbdprefix.rep ? ses->kbdprefix.rep_num : 1;
- while (i--) f(ses, fd, a);
+ while (i--)
+ f(ses, fd, a);
}
-static struct link *choose_mouse_link(struct f_data_c *f, struct links_event *ev)
+static struct link *
+choose_mouse_link(struct f_data_c *f, struct links_event *ev)
{
- return get_link_at_location(f->f_data, ev->x + f->vs->view_posx, ev->y + f->vs->view_pos);
+ return get_link_at_location(f->f_data, ev->x + f->vs->view_posx,
+ ev->y + f->vs->view_pos);
}
-static void goto_link_number(void *ses_, unsigned char *num)
+static void
+goto_link_number(void *ses_, unsigned char *num)
{
struct session *ses = (struct session *)ses_;
int n = atoi(cast_const_char num);
struct f_data_c *f = current_frame(ses);
struct link *link;
- if (!f || !f->vs) return;
- if (n < 0 || n > f->f_data->nlinks) return;
+ if (!f || !f->vs)
+ return;
+ if (n < 0 || n > f->f_data->nlinks)
+ return;
f->vs->current_link = n - 1;
f->vs->orig_link = f->vs->current_link;
link = &f->f_data->links[f->vs->current_link];
check_vs(f);
f->vs->orig_view_pos = f->vs->view_pos;
f->vs->orig_view_posx = f->vs->view_posx;
- if (link->type != L_AREA && link->type != L_FIELD) enter(ses, f, 0);
+ if (link->type != L_AREA && link->type != L_FIELD)
+ enter(ses, f, 0);
}
/* l must be a valid link, ev must be a mouse event */
-static int find_pos_in_link(struct f_data_c *fd, struct link *l, struct links_event *ev, int *xx, int *yy)
+static int
+find_pos_in_link(struct f_data_c *fd, struct link *l, struct links_event *ev,
+ int *xx, int *yy)
{
int a;
int minx, miny;
int found = 0;
- if (!l->n) return 1;
+ if (!l->n)
+ return 1;
minx = l->pos[0].x;
miny = l->pos[0].y;
for (a = 0; a < l->n; a++) {
- if (l->pos[a].x < minx) minx = l->pos[a].x;
- if (l->pos[a].y < miny) miny = l->pos[a].y;
+ if (l->pos[a].x < minx)
+ minx = l->pos[a].x;
+ if (l->pos[a].y < miny)
+ miny = l->pos[a].y;
if (l->pos[a].x - fd->vs->view_posx == ev->x
- && l->pos[a].y - fd->vs->view_pos == ev->y) {
+ && l->pos[a].y - fd->vs->view_pos == ev->y) {
(*xx = l->pos[a].x);
(*yy = l->pos[a].y);
found = 1;
}
}
- if (!found) return 1;
+ if (!found)
+ return 1;
*xx -= minx;
*yy -= miny;
return 0;
}
-static int frame_ev(struct session *ses, struct f_data_c *fd, struct links_event *ev)
+static int
+frame_ev(struct session *ses, struct f_data_c *fd, struct links_event *ev)
{
int x = 1;
- if (!fd || !fd->vs || !fd->f_data) return 0;
- if (fd->vs->current_link >= 0 && (fd->f_data->links[fd->vs->current_link].type == L_FIELD || fd->f_data->links[fd->vs->current_link].type == L_AREA)) {
- if (field_op(ses, fd, &fd->f_data->links[fd->vs->current_link], ev)) {
+ if (!fd || !fd->vs || !fd->f_data)
+ return 0;
+ if (fd->vs->current_link >= 0
+ && (fd->f_data->links[fd->vs->current_link].type == L_FIELD
+ || fd->f_data->links[fd->vs->current_link].type == L_AREA)) {
+ if (field_op(ses, fd, &fd->f_data->links[fd->vs->current_link],
+ ev)) {
fd->last_captured = 1;
fd->vs->brl_in_field = 1;
return 1;
@@ -2598,30 +3216,55 @@ static int frame_ev(struct session *ses, struct f_data_c *fd, struct links_event
}
fd->last_captured = 0;
if (ev->ev == EV_KBD && !(ev->y & KBD_PASTING)) {
- if (ev->x >= '0'+!ses->kbdprefix.rep && ev->x <= '9' && (!fd->f_data->opt.num_links || (ev->y & (KBD_CTRL | KBD_ALT)))) {
- if (!ses->kbdprefix.rep) ses->kbdprefix.rep_num = 0;
- if ((ses->kbdprefix.rep_num = ses->kbdprefix.rep_num * 10 + ev->x - '0') > 65536) ses->kbdprefix.rep_num = 65536;
+ if (ev->x >= '0' + !ses->kbdprefix.rep && ev->x <= '9'
+ && (!fd->f_data->opt.num_links
+ || (ev->y & (KBD_CTRL | KBD_ALT)))) {
+ if (!ses->kbdprefix.rep)
+ ses->kbdprefix.rep_num = 0;
+ if ((ses->kbdprefix.rep_num =
+ ses->kbdprefix.rep_num * 10 + ev->x - '0')
+ > 65536)
+ ses->kbdprefix.rep_num = 65536;
ses->kbdprefix.rep = 1;
return 1;
}
- if (ev->x == KBD_PAGE_DOWN || (ev->x == ' ' && (!(ev->y & KBD_ALT))) || (upcase(ev->x) == 'F' && ev->y & KBD_CTRL)) rep_ev(ses, fd, page_down, 0);
- else if (ev->x == KBD_PAGE_UP || (upcase(ev->x) == 'B' && (!(ev->y & KBD_ALT)))) rep_ev(ses, fd, page_up, 0);
- else if (ev->x == KBD_DOWN) rep_ev(ses, fd, down, 0);
- else if (ev->x == KBD_UP) rep_ev(ses, fd, up, 0);
+ if (ev->x == KBD_PAGE_DOWN
+ || (ev->x == ' ' && (!(ev->y & KBD_ALT)))
+ || (upcase(ev->x) == 'F' && ev->y & KBD_CTRL))
+ rep_ev(ses, fd, page_down, 0);
+ else if (ev->x == KBD_PAGE_UP
+ || (upcase(ev->x) == 'B' && (!(ev->y & KBD_ALT))))
+ rep_ev(ses, fd, page_up, 0);
+ else if (ev->x == KBD_DOWN)
+ rep_ev(ses, fd, down, 0);
+ else if (ev->x == KBD_UP)
+ rep_ev(ses, fd, up, 0);
/* Copy current link to clipboard */
- else if ((ev->x == KBD_INS && ev->y & KBD_CTRL) || (upcase(ev->x) == 'C' && ev->y & KBD_CTRL)) {
+ else if ((ev->x == KBD_INS && ev->y & KBD_CTRL)
+ || (upcase(ev->x) == 'C' && ev->y & KBD_CTRL)) {
unsigned char *current_link = print_current_link(ses);
if (current_link) {
set_clipboard_text(ses->term, current_link);
free(current_link);
}
- }
- else if (ev->x == KBD_INS || (upcase(ev->x) == 'P' && ev->y & KBD_CTRL) || (ev->x == 'p' && !(ev->y & (KBD_CTRL | KBD_ALT)))) rep_ev(ses, fd, scroll, -1 - !ses->kbdprefix.rep);
- else if (ev->x == KBD_DEL || (upcase(ev->x) == 'N' && ev->y & KBD_CTRL) || (ev->x == 'l' && !(ev->y & (KBD_CTRL | KBD_ALT)))) rep_ev(ses, fd, scroll, 1 + !ses->kbdprefix.rep);
- else if (ev->x == '[') rep_ev(ses, fd, hscroll, -1 - 7 * !ses->kbdprefix.rep);
- else if (ev->x == ']') rep_ev(ses, fd, hscroll, 1 + 7 * !ses->kbdprefix.rep);
- else if (ev->x == KBD_HOME || (upcase(ev->x) == 'A' && ev->y & KBD_CTRL)) rep_ev(ses, fd, home, 0);
- else if (ev->x == KBD_END || (upcase(ev->x) == 'E' && ev->y & KBD_CTRL)) rep_ev(ses, fd, x_end, 0);
+ } else if (ev->x == KBD_INS
+ || (upcase(ev->x) == 'P' && ev->y & KBD_CTRL)
+ || (ev->x == 'p' && !(ev->y & (KBD_CTRL | KBD_ALT))))
+ rep_ev(ses, fd, scroll, -1 - !ses->kbdprefix.rep);
+ else if (ev->x == KBD_DEL
+ || (upcase(ev->x) == 'N' && ev->y & KBD_CTRL)
+ || (ev->x == 'l' && !(ev->y & (KBD_CTRL | KBD_ALT))))
+ rep_ev(ses, fd, scroll, 1 + !ses->kbdprefix.rep);
+ else if (ev->x == '[')
+ rep_ev(ses, fd, hscroll, -1 - 7 * !ses->kbdprefix.rep);
+ else if (ev->x == ']')
+ rep_ev(ses, fd, hscroll, 1 + 7 * !ses->kbdprefix.rep);
+ else if (ev->x == KBD_HOME
+ || (upcase(ev->x) == 'A' && ev->y & KBD_CTRL))
+ rep_ev(ses, fd, home, 0);
+ else if (ev->x == KBD_END
+ || (upcase(ev->x) == 'E' && ev->y & KBD_CTRL))
+ rep_ev(ses, fd, x_end, 0);
else if (ev->x == KBD_RIGHT || ev->x == KBD_ENTER) {
x = enter(ses, fd, 0);
} else if (ev->x == '*') {
@@ -2631,17 +3274,35 @@ static int frame_ev(struct session *ses, struct f_data_c *fd, struct links_event
} else if (ev->x == 'i' && !(ev->y & KBD_ALT)) {
frm_view_image(ses, fd);
} else if (ev->x == 'I' && !(ev->y & KBD_ALT)) {
- if (!anonymous) frm_download_image(ses, fd);
+ if (!anonymous)
+ frm_download_image(ses, fd);
} else if (upcase(ev->x) == 'D' && !(ev->y & KBD_ALT)) {
- if (!anonymous) frm_download(ses, fd);
- } else if (ev->x == '/' || (ev->x == KBD_FIND && !(ev->y & (KBD_SHIFT | KBD_CTRL | KBD_ALT)))) search_dlg(ses, fd, 0);
- else if (ev->x == '?' || (ev->x == KBD_FIND && ev->y & (KBD_SHIFT | KBD_CTRL | KBD_ALT))) search_back_dlg(ses, fd, 0);
- else if ((ev->x == 'n' && !(ev->y & KBD_ALT)) || ev->x == KBD_REDO) find_next(ses, fd, 0);
- else if ((ev->x == 'N' && !(ev->y & KBD_ALT)) || ev->x == KBD_UNDO) find_next_back(ses, fd, 0);
- else if ((upcase(ev->x) == 'F' && !(ev->y & (KBD_ALT | KBD_CTRL))) || ev->x == KBD_FRONT) set_frame(ses, fd, 0);
- else if (ev->x == 'H' && !(ev->y & (KBD_CTRL | KBD_ALT))) find_link(fd, 1, 1);
- else if (ev->x == 'L' && !(ev->y & (KBD_CTRL | KBD_ALT))) find_link(fd, -1, 1);
- else if (ev->x >= '1' && ev->x <= '9' && !(ev->y & (KBD_CTRL | KBD_ALT))) {
+ if (!anonymous)
+ frm_download(ses, fd);
+ } else if (ev->x == '/'
+ || (ev->x == KBD_FIND
+ && !(ev->y & (KBD_SHIFT | KBD_CTRL | KBD_ALT))))
+ search_dlg(ses, fd, 0);
+ else if (ev->x == '?'
+ || (ev->x == KBD_FIND
+ && ev->y & (KBD_SHIFT | KBD_CTRL | KBD_ALT)))
+ search_back_dlg(ses, fd, 0);
+ else if ((ev->x == 'n' && !(ev->y & KBD_ALT))
+ || ev->x == KBD_REDO)
+ find_next(ses, fd, 0);
+ else if ((ev->x == 'N' && !(ev->y & KBD_ALT))
+ || ev->x == KBD_UNDO)
+ find_next_back(ses, fd, 0);
+ else if ((upcase(ev->x) == 'F'
+ && !(ev->y & (KBD_ALT | KBD_CTRL)))
+ || ev->x == KBD_FRONT)
+ set_frame(ses, fd, 0);
+ else if (ev->x == 'H' && !(ev->y & (KBD_CTRL | KBD_ALT)))
+ find_link(fd, 1, 1);
+ else if (ev->x == 'L' && !(ev->y & (KBD_CTRL | KBD_ALT)))
+ find_link(fd, -1, 1);
+ else if (ev->x >= '1' && ev->x <= '9'
+ && !(ev->y & (KBD_CTRL | KBD_ALT))) {
struct f_data *f_data = fd->f_data;
int nl, lnl;
unsigned char d[2];
@@ -2653,74 +3314,99 @@ static int frame_ev(struct session *ses, struct f_data_c *fd, struct links_event
nl /= 10;
lnl++;
}
- if (lnl > 1) input_field(ses->term, NULL, TEXT_(T_GO_TO_LINK), TEXT_(T_ENTER_LINK_NUMBER), ses, NULL, lnl, d, 1, f_data->nlinks, check_number, 2, TEXT_(T_OK), goto_link_number, TEXT_(T_CANCEL), input_field_null);
- }
- else x = 0;
- } else if (ev->ev == EV_MOUSE && (ev->b & BM_BUTT) == B_WHEELUP) rep_ev(ses, fd, scroll, -1 - 5 * !ses->kbdprefix.rep);
- else if (ev->ev == EV_MOUSE && (ev->b & BM_BUTT) == B_WHEELDOWN) rep_ev(ses, fd, scroll, 1 + 5 * !ses->kbdprefix.rep);
- else if (ev->ev == EV_MOUSE && (ev->b & BM_BUTT) == B_WHEELLEFT) rep_ev(ses, fd, hscroll, -1 - 3 * !ses->kbdprefix.rep);
- else if (ev->ev == EV_MOUSE && (ev->b & BM_BUTT) == B_WHEELRIGHT) rep_ev(ses, fd, hscroll, 1 + 3 * !ses->kbdprefix.rep);
+ if (lnl > 1)
+ input_field(
+ ses->term, NULL, TEXT_(T_GO_TO_LINK),
+ TEXT_(T_ENTER_LINK_NUMBER), ses, NULL, lnl,
+ d, 1, f_data->nlinks, check_number, 2,
+ TEXT_(T_OK), goto_link_number,
+ TEXT_(T_CANCEL), input_field_null);
+ } else
+ x = 0;
+ } else if (ev->ev == EV_MOUSE && (ev->b & BM_BUTT) == B_WHEELUP)
+ rep_ev(ses, fd, scroll, -1 - 5 * !ses->kbdprefix.rep);
+ else if (ev->ev == EV_MOUSE && (ev->b & BM_BUTT) == B_WHEELDOWN)
+ rep_ev(ses, fd, scroll, 1 + 5 * !ses->kbdprefix.rep);
+ else if (ev->ev == EV_MOUSE && (ev->b & BM_BUTT) == B_WHEELLEFT)
+ rep_ev(ses, fd, hscroll, -1 - 3 * !ses->kbdprefix.rep);
+ else if (ev->ev == EV_MOUSE && (ev->b & BM_BUTT) == B_WHEELRIGHT)
+ rep_ev(ses, fd, hscroll, 1 + 3 * !ses->kbdprefix.rep);
else if (ev->ev == EV_MOUSE && (ev->b & BM_BUTT) <= B_RIGHT) {
struct link *l = choose_mouse_link(fd, ev);
if (l) {
x = 1;
fd->vs->current_link = (int)(l - fd->f_data->links);
fd->vs->orig_link = fd->vs->current_link;
- if (l->type == L_LINK || l->type == L_BUTTON || l->type == L_CHECKBOX || l->type == L_SELECT) if ((ev->b & BM_ACT) == B_UP) {
- fd->active = 1;
- draw_to_window(ses->win, draw_doc_c, fd);
- change_screen_status(ses);
- print_screen_status(ses);
- if ((ev->b & BM_BUTT) == B_LEFT) x = enter(ses, fd, 0);
- else link_menu(ses->term, NULL, ses);
- }
+ if (l->type == L_LINK || l->type == L_BUTTON
+ || l->type == L_CHECKBOX || l->type == L_SELECT)
+ if ((ev->b & BM_ACT) == B_UP) {
+ fd->active = 1;
+ draw_to_window(ses->win, draw_doc_c,
+ fd);
+ change_screen_status(ses);
+ print_screen_status(ses);
+ if ((ev->b & BM_BUTT) == B_LEFT)
+ x = enter(ses, fd, 0);
+ else
+ link_menu(ses->term, NULL, ses);
+ }
set_form_position(fd, l, ev);
}
- } else x = 0;
+ } else
+ x = 0;
ses->kbdprefix.rep = 0;
return x;
}
-struct f_data_c *current_frame(struct session *ses)
+struct f_data_c *
+current_frame(struct session *ses)
{
struct f_data_c *fd, *fdd = NULL;
struct list_head *lfdd;
fd = ses->screen;
while (!list_empty(fd->subframes)) {
int n = fd->vs->frame_pos;
- if (n == -1) break;
- foreach(struct f_data_c, fdd, lfdd, fd->subframes) if (!n--) {
- fd = fdd;
- goto r;
- }
+ if (n == -1)
+ break;
+ foreach (struct f_data_c, fdd, lfdd, fd->subframes)
+ if (!n--) {
+ fd = fdd;
+ goto r;
+ }
fd = list_struct(fd->subframes.next, struct f_data_c);
- r:;
+r:;
}
return fd;
}
-static int is_active_frame(struct session *ses, struct f_data_c *f)
+static int
+is_active_frame(struct session *ses, struct f_data_c *f)
{
struct f_data_c *fd, *fdd = NULL;
struct list_head *lfdd;
fd = ses->screen;
- if (f == fd) return 1;
+ if (f == fd)
+ return 1;
while (!list_empty(fd->subframes)) {
int n = fd->vs->frame_pos;
- if (n == -1) break;
- foreach(struct f_data_c, fdd, lfdd, fd->subframes) if (!n--) {
- fd = fdd;
- goto r;
- }
+ if (n == -1)
+ break;
+ foreach (struct f_data_c, fdd, lfdd, fd->subframes)
+ if (!n--) {
+ fd = fdd;
+ goto r;
+ }
fd = list_struct(fd->subframes.next, struct f_data_c);
- r:
- if (f == fd) return 1;
+r:
+ if (f == fd)
+ return 1;
}
return 0;
}
-static int send_to_frame(struct session *ses, struct links_event *ev)
+static int
+send_to_frame(struct session *ses, struct links_event *ev)
{
int r;
struct f_data_c *fd;
@@ -2735,11 +3421,13 @@ static int send_to_frame(struct session *ses, struct links_event *ev)
change_screen_status(ses);
print_screen_status(ses);
}
- if (r == 3) draw_fd_nrd(fd);
+ if (r == 3)
+ draw_fd_nrd(fd);
return r;
}
-void next_frame(struct session *ses, int p)
+void
+next_frame(struct session *ses, int p)
{
int n;
struct view_state *vs;
@@ -2752,28 +3440,44 @@ void next_frame(struct session *ses, int p)
n = (int)list_size(&fd->subframes);
vs = fd->vs;
vs->frame_pos += p;
- if (vs->frame_pos < -!fd->f_data->frame_desc) { vs->frame_pos = n - 1; continue; }
- if (vs->frame_pos >= n) { vs->frame_pos = -!fd->f_data->frame_desc; continue; }
+ if (vs->frame_pos < -!fd->f_data->frame_desc) {
+ vs->frame_pos = n - 1;
+ continue;
+ }
+ if (vs->frame_pos >= n) {
+ vs->frame_pos = -!fd->f_data->frame_desc;
+ continue;
+ }
break;
}
- if (!fd) fd = ses->screen;
+ if (!fd)
+ fd = ses->screen;
vs = fd->vs;
n = 0;
- foreach(struct f_data_c, fdd, lfdd, fd->subframes) if (n++ == vs->frame_pos) {
- fd = fdd;
- next_sub:
- if (list_empty(fd->subframes)) break;
- fd = list_struct(p < 0 ? fd->subframes.prev : fd->subframes.next, struct f_data_c);
- vs = fd->vs;
- vs->frame_pos = -1;
- if (!fd->f_data || (!fd->f_data->frame_desc && p > 0)) break;
- if (p < 0) vs->frame_pos += (int)list_size(&fd->subframes);
- else vs->frame_pos = 0;
- goto next_sub;
- }
+ foreach (struct f_data_c, fdd, lfdd, fd->subframes)
+ if (n++ == vs->frame_pos) {
+ fd = fdd;
+next_sub:
+ if (list_empty(fd->subframes))
+ break;
+ fd = list_struct(p < 0 ? fd->subframes.prev
+ : fd->subframes.next,
+ struct f_data_c);
+ vs = fd->vs;
+ vs->frame_pos = -1;
+ if (!fd->f_data || (!fd->f_data->frame_desc && p > 0))
+ break;
+ if (p < 0)
+ vs->frame_pos += (int)list_size(&fd->subframes);
+ else
+ vs->frame_pos = 0;
+ goto next_sub;
+ }
}
-void do_for_frame(struct session *ses, void (*f)(struct session *, struct f_data_c *, int), int a)
+void
+do_for_frame(struct session *ses,
+ void (*f)(struct session *, struct f_data_c *, int), int a)
{
struct f_data_c *fd = current_frame(ses);
if (!fd)
@@ -2785,42 +3489,50 @@ void do_for_frame(struct session *ses, void (*f)(struct session *, struct f_data
print_screen_status(ses);
}
-static void do_mouse_event(struct session *ses, struct links_event *ev)
+static void
+do_mouse_event(struct session *ses, struct links_event *ev)
{
struct links_event evv;
struct f_data_c *fdd, *fd = current_frame(ses);
- if (!fd) return;
- if (ev->x >= fd->xp && ev->x < fd->xp + fd->xw &&
- ev->y >= fd->yp && ev->y < fd->yp + fd->yw) goto ok;
- r:
+ if (!fd)
+ return;
+ if (ev->x >= fd->xp && ev->x < fd->xp + fd->xw && ev->y >= fd->yp
+ && ev->y < fd->yp + fd->yw)
+ goto ok;
+r:
next_frame(ses, 1);
fdd = current_frame(ses);
/*o = &fdd->f_data->opt;*/
- if (ev->x >= fdd->xp && ev->x < fdd->xp + fdd->xw &&
- ev->y >= fdd->yp && ev->y < fdd->yp + fdd->yw) {
+ if (ev->x >= fdd->xp && ev->x < fdd->xp + fdd->xw && ev->y >= fdd->yp
+ && ev->y < fdd->yp + fdd->yw) {
draw_formatted(ses);
fd = fdd;
goto ok;
}
- if (fdd != fd) goto r;
+ if (fdd != fd)
+ goto r;
return;
- ok:
+ok:
memcpy(&evv, ev, sizeof(struct links_event));
evv.x -= fd->xp;
evv.y -= fd->yp;
send_to_frame(ses, &evv);
}
-void send_event(struct session *ses, struct links_event *ev)
+void
+send_event(struct session *ses, struct links_event *ev)
{
if (ses->brl_cursor_mode) {
ses->brl_cursor_mode = 0;
print_screen_status(ses);
}
if (ev->ev == EV_KBD) {
- if (send_to_frame(ses, ev)) return;
- if (ev->y & KBD_PASTING) goto x;
- if (ev->y & KBD_ALT && ev->x != KBD_TAB && !KBD_ESCAPE_MENU(ev->x)) {
+ if (send_to_frame(ses, ev))
+ return;
+ if (ev->y & KBD_PASTING)
+ goto x;
+ if (ev->y & KBD_ALT && ev->x != KBD_TAB
+ && !KBD_ESCAPE_MENU(ev->x)) {
struct window *m;
ev->y &= ~KBD_ALT;
activate_bfu_technology(ses, -1);
@@ -2828,7 +3540,8 @@ void send_event(struct session *ses, struct links_event *ev)
m->handler(m, ev, 0);
if (ses->term->windows.next == &m->list_entry) {
delete_window(m);
- } else goto x;
+ } else
+ goto x;
ev->y |= KBD_ALT;
}
if (ev->x == KBD_F1 || ev->x == KBD_HELP) {
@@ -2851,36 +3564,48 @@ void send_event(struct session *ses, struct links_event *ev)
go_back(ses, 1);
goto x;
}
- if ((upcase(ev->x) == 'Z' && !(ev->y & (KBD_CTRL | KBD_ALT))) || ev->x == KBD_BS || ev->x == KBD_BACK) {
+ if ((upcase(ev->x) == 'Z' && !(ev->y & (KBD_CTRL | KBD_ALT)))
+ || ev->x == KBD_BS || ev->x == KBD_BACK) {
go_back(ses, 1);
goto x;
}
- if ((upcase(ev->x) == 'X' && !(ev->y & (KBD_CTRL | KBD_ALT))) || ev->x == '\'' || ev->x == KBD_FORWARD) {
+ if ((upcase(ev->x) == 'X' && !(ev->y & (KBD_CTRL | KBD_ALT)))
+ || ev->x == '\'' || ev->x == KBD_FORWARD) {
go_back(ses, -1);
goto x;
}
- if ((upcase(ev->x) == 'R' && ev->y & KBD_CTRL) || ev->x == KBD_RELOAD) {
+ if ((upcase(ev->x) == 'R' && ev->y & KBD_CTRL)
+ || ev->x == KBD_RELOAD) {
reload(ses, -1);
goto x;
}
- if ((ev->x == 'g' && !(ev->y & (KBD_CTRL | KBD_ALT))) || (ev->x == KBD_OPEN && !(ev->y & (KBD_SHIFT | KBD_CTRL)))) {
- quak:
+ if ((ev->x == 'g' && !(ev->y & (KBD_CTRL | KBD_ALT)))
+ || (ev->x == KBD_OPEN
+ && !(ev->y & (KBD_SHIFT | KBD_CTRL)))) {
+quak:
dialog_goto_url(ses, cast_uchar "");
goto x;
}
- if ((ev->x == 'G' && !(ev->y & (KBD_CTRL | KBD_ALT))) || (ev->x == KBD_OPEN && ev->y & KBD_SHIFT)) {
+ if ((ev->x == 'G' && !(ev->y & (KBD_CTRL | KBD_ALT)))
+ || (ev->x == KBD_OPEN && ev->y & KBD_SHIFT)) {
unsigned char *s;
- if (list_empty(ses->history) || !ses->screen->rq->url) goto quak;
+ if (list_empty(ses->history) || !ses->screen->rq->url)
+ goto quak;
s = display_url(ses->term, ses->screen->rq->url, 0);
dialog_goto_url(ses, s);
free(s);
goto x;
}
- if ((upcase(ev->x) == 'G' && ev->y & KBD_CTRL) || (ev->x == KBD_OPEN && ev->y & KBD_CTRL)) {
+ if ((upcase(ev->x) == 'G' && ev->y & KBD_CTRL)
+ || (ev->x == KBD_OPEN && ev->y & KBD_CTRL)) {
struct f_data_c *fd = current_frame(ses);
unsigned char *s;
- if (!fd->vs || !fd->f_data || fd->vs->current_link < 0 || fd->vs->current_link >= fd->f_data->nlinks) goto quak;
- s = display_url(ses->term, fd->f_data->links[fd->vs->current_link].where, 0);
+ if (!fd->vs || !fd->f_data || fd->vs->current_link < 0
+ || fd->vs->current_link >= fd->f_data->nlinks)
+ goto quak;
+ s = display_url(
+ ses->term,
+ fd->f_data->links[fd->vs->current_link].where, 0);
dialog_goto_url(ses, s);
free(s);
goto x;
@@ -2889,12 +3614,18 @@ void send_event(struct session *ses, struct links_event *ev)
dialog_html_options(ses);
goto x;
}
- if ((upcase(ev->x) == 'S' && !(ev->y & (KBD_CTRL | KBD_ALT))) || ev->x == KBD_BOOKMARKS) {
- if (!anonymous) menu_bookmark_manager(ses->term, NULL, ses);
+ if ((upcase(ev->x) == 'S' && !(ev->y & (KBD_CTRL | KBD_ALT)))
+ || ev->x == KBD_BOOKMARKS) {
+ if (!anonymous)
+ menu_bookmark_manager(ses->term, NULL, ses);
goto x;
}
- if ((upcase(ev->x) == 'Q' && !(ev->y & (KBD_CTRL | KBD_ALT))) || ev->x == KBD_CTRL_C) {
- exit_prog(ses->term, (int *)(long)(ev->x == KBD_CTRL_C || ev->x == 'Q'), ses);
+ if ((upcase(ev->x) == 'Q' && !(ev->y & (KBD_CTRL | KBD_ALT)))
+ || ev->x == KBD_CTRL_C) {
+ exit_prog(
+ ses->term,
+ (int *)(long)(ev->x == KBD_CTRL_C || ev->x == 'Q'),
+ ses);
goto x;
}
if (ev->x == KBD_CLOSE) {
@@ -2923,7 +3654,8 @@ void send_event(struct session *ses, struct links_event *ev)
go_back(ses, -1);
goto x;
}
- if (ev->y >= 0 && ev->y < 1 && ev->x >=0 && ev->x < ses->term->x && (ev->b & BM_ACT) == B_DOWN) {
+ if (ev->y >= 0 && ev->y < 1 && ev->x >= 0
+ && ev->x < ses->term->x && (ev->b & BM_ACT) == B_DOWN) {
struct window *m;
activate_bfu_technology(ses, -1);
m = list_struct(ses->term->windows.next, struct window);
@@ -2933,24 +3665,28 @@ void send_event(struct session *ses, struct links_event *ev)
do_mouse_event(ses, ev);
}
return;
- x:
+x:
ses->kbdprefix.rep = 0;
}
-static void send_enter(struct terminal *term, void *xxx, void *ses_)
+static void
+send_enter(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = (struct session *)ses_;
struct links_event ev = { EV_KBD, KBD_ENTER, 0, 0 };
send_event(ses, &ev);
}
-void frm_download(struct session *ses, struct f_data_c *fd)
+void
+frm_download(struct session *ses, struct f_data_c *fd)
{
struct link *link = get_current_link(fd);
- if (!link) return;
+ if (!link)
+ return;
free(ses->dn_url);
ses->dn_url = NULL;
- if (link->type != L_LINK && link->type != L_BUTTON) return;
+ if (link->type != L_LINK && link->type != L_BUTTON)
+ return;
if ((ses->dn_url = get_link_url(ses, fd, link, NULL))) {
ses->dn_allow_flags = f_data_c_allow_flags(fd);
if (!casecmp(ses->dn_url, cast_uchar "MAP@", 4)) {
@@ -2958,27 +3694,36 @@ void frm_download(struct session *ses, struct f_data_c *fd)
ses->dn_url = NULL;
return;
}
- query_file(ses, ses->dn_url, NULL, start_download, NULL, DOWNLOAD_CONTINUE);
+ query_file(ses, ses->dn_url, NULL, start_download, NULL,
+ DOWNLOAD_CONTINUE);
}
}
-void frm_view_image(struct session *ses, struct f_data_c *fd)
+void
+frm_view_image(struct session *ses, struct f_data_c *fd)
{
struct link *link = get_current_link(fd);
- if (!link) return;
- if (link->type != L_LINK && link->type != L_BUTTON) return;
- if (!link->where_img) return;
+ if (!link)
+ return;
+ if (link->type != L_LINK && link->type != L_BUTTON)
+ return;
+ if (!link->where_img)
+ return;
goto_url_not_from_dialog(ses, link->where_img, fd);
}
-void frm_download_image(struct session *ses, struct f_data_c *fd)
+void
+frm_download_image(struct session *ses, struct f_data_c *fd)
{
struct link *link = get_current_link(fd);
- if (!link) return;
+ if (!link)
+ return;
free(ses->dn_url);
ses->dn_url = NULL;
- if (link->type != L_LINK && link->type != L_BUTTON) return;
- if (!link->where_img) return;
+ if (link->type != L_LINK && link->type != L_BUTTON)
+ return;
+ if (!link->where_img)
+ return;
if ((ses->dn_url = stracpy(link->where_img))) {
ses->dn_allow_flags = f_data_c_allow_flags(fd);
if (!casecmp(ses->dn_url, cast_uchar "MAP@", 4)) {
@@ -2986,37 +3731,45 @@ void frm_download_image(struct session *ses, struct f_data_c *fd)
ses->dn_url = NULL;
return;
}
- query_file(ses, ses->dn_url, NULL, start_download, NULL, DOWNLOAD_CONTINUE);
+ query_file(ses, ses->dn_url, NULL, start_download, NULL,
+ DOWNLOAD_CONTINUE);
}
}
-static void send_download_image(struct terminal *term, void *xxx, void *ses_)
+static void
+send_download_image(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = (struct session *)ses_;
struct f_data_c *fd = current_frame(ses);
struct link *link = get_current_link(fd);
- if (!link) return;
+ if (!link)
+ return;
free(ses->dn_url);
if ((ses->dn_url = stracpy(link->where_img))) {
ses->dn_allow_flags = f_data_c_allow_flags(fd);
- query_file(ses, ses->dn_url, NULL, start_download, NULL, DOWNLOAD_CONTINUE);
+ query_file(ses, ses->dn_url, NULL, start_download, NULL,
+ DOWNLOAD_CONTINUE);
}
}
-static void send_download(struct terminal *term, void *xxx, void *ses_)
+static void
+send_download(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = (struct session *)ses_;
struct f_data_c *fd = current_frame(ses);
struct link *link = get_current_link(fd);
- if (!link) return;
+ if (!link)
+ return;
free(ses->dn_url);
if ((ses->dn_url = get_link_url(ses, fd, link, NULL))) {
ses->dn_allow_flags = f_data_c_allow_flags(fd);
- query_file(ses, ses->dn_url, NULL, start_download, NULL, DOWNLOAD_CONTINUE);
+ query_file(ses, ses->dn_url, NULL, start_download, NULL,
+ DOWNLOAD_CONTINUE);
}
}
-static void send_submit(struct terminal *term, void *xxx, void *ses_)
+static void
+send_submit(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = (struct session *)ses_;
int has_onsubmit;
@@ -3025,30 +3778,37 @@ static void send_submit(struct terminal *term, void *xxx, void *ses_)
struct link *link = get_current_link(fd);
unsigned char *u;
- if (!link) return;
- if (!(form = link->form)) return;
+ if (!link)
+ return;
+ if (!(form = link->form))
+ return;
u = get_form_url(ses, fd, form, &has_onsubmit);
if (u) {
- goto_url_f(fd->ses, NULL, u, NULL, fd, form->form_num, has_onsubmit, 0, 0);
+ goto_url_f(fd->ses, NULL, u, NULL, fd, form->form_num,
+ has_onsubmit, 0, 0);
free(u);
}
draw_fd(fd);
}
-static void send_reset(struct terminal *term, void *xxx, void *ses_)
+static void
+send_reset(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = ses_;
struct form_control *form;
struct f_data_c *fd = current_frame(ses);
struct link *link = get_current_link(fd);
- if (!link) return;
- if (!(form = link->form)) return;
+ if (!link)
+ return;
+ if (!(form = link->form))
+ return;
reset_form(fd, form->form_num);
draw_fd(fd);
}
-static void copy_link_location(struct terminal *term, void *xxx, void *ses_)
+static void
+copy_link_location(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = ses_;
unsigned char *current_link = print_current_link(ses);
@@ -3057,16 +3817,17 @@ static void copy_link_location(struct terminal *term, void *xxx, void *ses_)
set_clipboard_text(term, current_link);
free(current_link);
}
-
}
-void copy_url_location(struct terminal *term, void *xxx, void *ses_)
+void
+copy_url_location(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = ses_;
struct location *current_location;
unsigned char *url;
- if (list_empty(ses->history)) return;
+ if (list_empty(ses->history))
+ return;
current_location = cur_loc(ses);
@@ -3075,20 +3836,28 @@ void copy_url_location(struct terminal *term, void *xxx, void *ses_)
free(url);
}
-static void cant_open_new_window(struct terminal *term)
+static void
+cant_open_new_window(struct terminal *term)
{
- msg_box(term, NULL, TEXT_(T_NEW_WINDOW), AL_CENTER, TEXT_(T_UNABLE_TO_OPEN_NEW_WINDOW), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ msg_box(term, NULL, TEXT_(T_NEW_WINDOW), AL_CENTER,
+ TEXT_(T_UNABLE_TO_OPEN_NEW_WINDOW), MSG_BOX_END, NULL, 1,
+ TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
}
/* open a link in a new xterm, pass target frame name */
-static void send_open_in_new_xterm(struct terminal *term, void *open_window_, void *ses_)
+static void
+send_open_in_new_xterm(struct terminal *term, void *open_window_, void *ses_)
{
- int (*open_window)(struct terminal *, unsigned char *, unsigned char *) = *(int (* const *)(struct terminal *, unsigned char *, unsigned char *))open_window_;
+ int (*open_window)(struct terminal *, unsigned char *,
+ unsigned char *) =
+ *(int (*const *)(struct terminal *, unsigned char *,
+ unsigned char *))open_window_;
struct session *ses = (struct session *)ses_;
struct f_data_c *fd = current_frame(ses);
struct link *l;
l = get_current_link(fd);
- if (!l) return;
+ if (!l)
+ return;
free(ses->dn_url);
if ((ses->dn_url = get_link_url(ses, fd, l, NULL))) {
unsigned char *p;
@@ -3130,9 +3899,13 @@ static void send_open_in_new_xterm(struct terminal *term, void *open_window_, vo
}
}
-static void send_open_new_xterm(struct terminal *term, void *open_window_, void *ses_)
+static void
+send_open_new_xterm(struct terminal *term, void *open_window_, void *ses_)
{
- int (*open_window)(struct terminal *, unsigned char *, unsigned char *) = *(int (* const *)(struct terminal *, unsigned char *, unsigned char *))open_window_;
+ int (*open_window)(struct terminal *, unsigned char *,
+ unsigned char *) =
+ *(int (*const *)(struct terminal *, unsigned char *,
+ unsigned char *))open_window_;
struct session *ses = ses_;
unsigned char *p = init_str();
int pl = 0;
@@ -3146,15 +3919,19 @@ static void send_open_new_xterm(struct terminal *term, void *open_window_, void
free(p);
}
-void (* const send_open_new_xterm_ptr)(struct terminal *, void *fn_, void *ses_) = send_open_new_xterm;
+void (*const send_open_new_xterm_ptr)(struct terminal *, void *fn_,
+ void *ses_) = send_open_new_xterm;
-void open_in_new_window(struct terminal *term, void *fn_, void *ses_)
+void
+open_in_new_window(struct terminal *term, void *fn_, void *ses_)
{
struct session *ses = ses_;
- void (*fn)(struct terminal *, void *, void *) = *(void (* const *)(struct terminal *, void *, void *))fn_;
+ void (*fn)(struct terminal *, void *, void *) =
+ *(void (*const *)(struct terminal *, void *, void *))fn_;
struct menu_item *mi;
struct open_in_new *oin, *oi;
- if (!(oin = get_open_in_new(term->environment))) return;
+ if (!(oin = get_open_in_new(term->environment)))
+ return;
if (!oin[1].text) {
fn(term, (void *)oin[0].open_window_fn, ses);
free(oin);
@@ -3162,15 +3939,18 @@ void open_in_new_window(struct terminal *term, void *fn_, void *ses_)
}
mi = new_menu(MENU_FREE_ITEMS);
for (oi = oin; oi->text; oi++)
- add_to_menu(&mi, oi->text, cast_uchar "", oi->hk, fn, (void *)oi->open_window_fn, 0, -1);
+ add_to_menu(&mi, oi->text, cast_uchar "", oi->hk, fn,
+ (void *)oi->open_window_fn, 0, -1);
free(oin);
do_menu(term, mi, ses);
}
-int can_open_in_new(struct terminal *term)
+int
+can_open_in_new(struct terminal *term)
{
struct open_in_new *oin = get_open_in_new(term->environment);
- if (!oin) return 0;
+ if (!oin)
+ return 0;
if (!oin[1].text) {
free(oin);
return 1;
@@ -3179,7 +3959,8 @@ int can_open_in_new(struct terminal *term)
return 2;
}
-void save_url(void *ses_, unsigned char *url)
+void
+save_url(void *ses_, unsigned char *url)
{
struct session *ses = (struct session *)ses_;
unsigned char *u1, *u2;
@@ -3187,37 +3968,51 @@ void save_url(void *ses_, unsigned char *url)
u2 = translate_url(u1, ses->term->cwd);
free(u1);
if (!u2) {
- struct status stat = { init_list_1st(NULL) NULL, NULL, S_BAD_URL, PRI_CANCEL, 0, NULL, NULL, NULL };
+ struct status stat = { init_list_1st(NULL) NULL,
+ NULL,
+ S_BAD_URL,
+ PRI_CANCEL,
+ 0,
+ NULL,
+ NULL,
+ NULL };
print_error_dialog(ses, &stat, url);
return;
}
free(ses->dn_url);
ses->dn_url = u2;
ses->dn_allow_flags = ALLOW_ALL;
- query_file(ses, ses->dn_url, NULL, start_download, NULL, DOWNLOAD_CONTINUE);
+ query_file(ses, ses->dn_url, NULL, start_download, NULL,
+ DOWNLOAD_CONTINUE);
}
-static void send_image(struct terminal *term, void *xxx, void *ses_)
+static void
+send_image(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = ses_;
unsigned char *u;
struct f_data_c *fd = current_frame(ses);
struct link *l;
l = get_current_link(fd);
- if (!l) return;
- if (!(u = l->where_img)) return;
+ if (!l)
+ return;
+ if (!(u = l->where_img))
+ return;
goto_url_not_from_dialog(ses, u, fd);
}
-void save_as(struct terminal *term, void *xxx, void *ses_)
+void
+save_as(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = ses_;
unsigned char *head;
- if (list_empty(ses->history)) return;
+ if (list_empty(ses->history))
+ return;
free(ses->dn_url);
ses->dn_url = stracpy(ses->screen->rq->url);
ses->dn_allow_flags = ALLOW_ALL;
- if (!ses->dn_url) return;
+ if (!ses->dn_url)
+ return;
head = stracpy(ses->screen->rq->ce ? ses->screen->rq->ce->head : NULL);
if (head) {
unsigned char *p, *q;
@@ -3225,40 +4020,55 @@ void save_as(struct terminal *term, void *xxx, void *ses_)
q = parse_http_header(head, cast_uchar "Content-Encoding", &p);
if (q) {
free(q);
- if (p > head && p < (unsigned char *)strchr(cast_const_char head, 0)) {
+ if (p > head
+ && p < (unsigned char *)strchr(cast_const_char head,
+ 0)) {
for (q = p - 1; q > head && *q != 10; q--)
;
q[1] = 'X';
}
}
}
- query_file(ses, ses->dn_url, head, start_download, NULL, DOWNLOAD_CONTINUE);
+ query_file(ses, ses->dn_url, head, start_download, NULL,
+ DOWNLOAD_CONTINUE);
if (head)
free(head);
}
-static void save_formatted(struct session *ses, unsigned char *file, int mode)
+static void
+save_formatted(struct session *ses, unsigned char *file, int mode)
{
int h, rs, err;
struct f_data_c *f;
int download_mode = mode == DOWNLOAD_DEFAULT ? CDF_EXCL : 0;
- if (!(f = current_frame(ses)) || !f->f_data) return;
- if ((h = create_download_file(ses, ses->term->cwd, file, download_mode, 0)) < 0) return;
+ if (!(f = current_frame(ses)) || !f->f_data)
+ return;
+ if ((h = create_download_file(ses, ses->term->cwd, file, download_mode,
+ 0))
+ < 0)
+ return;
if ((err = dump_to_file(f->f_data, h))) {
- msg_box(ses->term, NULL, TEXT_(T_SAVE_ERROR), AL_CENTER, TEXT_(T_ERROR_WRITING_TO_FILE), cast_uchar ": ", get_err_msg(err), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
+ msg_box(ses->term, NULL, TEXT_(T_SAVE_ERROR), AL_CENTER,
+ TEXT_(T_ERROR_WRITING_TO_FILE), cast_uchar ": ",
+ get_err_msg(err), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL),
+ msg_box_null, B_ENTER | B_ESC);
}
EINTRLOOP(rs, close(h));
}
-void menu_save_formatted(struct terminal *term, void *xxx, void *ses_)
+void
+menu_save_formatted(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = ses_;
struct f_data_c *f;
- if (!(f = current_frame(ses)) || !f->f_data) return;
- query_file(ses, f->rq->url, NULL, save_formatted, NULL, DOWNLOAD_OVERWRITE);
+ if (!(f = current_frame(ses)) || !f->f_data)
+ return;
+ query_file(ses, f->rq->url, NULL, save_formatted, NULL,
+ DOWNLOAD_OVERWRITE);
}
-void link_menu(struct terminal *term, void *xxx, void *ses_)
+void
+link_menu(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = ses_;
struct f_data_c *f = current_frame(ses);
@@ -3268,53 +4078,113 @@ void link_menu(struct terminal *term, void *xxx, void *ses_)
ses->wtd_target = NULL;
mi = new_menu(MENU_FREE_ITEMS);
link = get_current_link(f);
- if (!link) goto no_l;
+ if (!link)
+ goto no_l;
if (link->type == L_LINK && link->where) {
- if (strlen(cast_const_char link->where) >= 4 && !casecmp(link->where, cast_uchar "MAP@", 4)) {
- add_to_menu(&mi, TEXT_(T_DISPLAY_USEMAP), cast_uchar ">", TEXT_(T_HK_DISPLAY_USEMAP), send_enter, NULL, 1, -1);
+ if (strlen(cast_const_char link->where) >= 4
+ && !casecmp(link->where, cast_uchar "MAP@", 4)) {
+ add_to_menu(&mi, TEXT_(T_DISPLAY_USEMAP),
+ cast_uchar ">", TEXT_(T_HK_DISPLAY_USEMAP),
+ send_enter, NULL, 1, -1);
} else {
int c = can_open_in_new(term);
- add_to_menu(&mi, TEXT_(T_FOLLOW_LINK), cast_uchar "Enter", TEXT_(T_HK_FOLLOW_LINK), send_enter, NULL, 0, -1);
- if (c) add_to_menu(&mi, TEXT_(T_OPEN_IN_NEW_WINDOW), c - 1 ? cast_uchar ">" : cast_uchar "", TEXT_(T_HK_OPEN_IN_NEW_WINDOW), open_in_new_window, (void *)&send_open_in_new_xterm_ptr, c - 1, -1);
- if (!anonymous) add_to_menu(&mi, TEXT_(T_DOWNLOAD_LINK), cast_uchar "d", TEXT_(T_HK_DOWNLOAD_LINK), send_download, NULL, 0, -1);
+ add_to_menu(&mi, TEXT_(T_FOLLOW_LINK),
+ cast_uchar "Enter", TEXT_(T_HK_FOLLOW_LINK),
+ send_enter, NULL, 0, -1);
+ if (c)
+ add_to_menu(&mi, TEXT_(T_OPEN_IN_NEW_WINDOW),
+ c - 1 ? cast_uchar ">"
+ : cast_uchar "",
+ TEXT_(T_HK_OPEN_IN_NEW_WINDOW),
+ open_in_new_window,
+ (void *)&send_open_in_new_xterm_ptr,
+ c - 1, -1);
+ if (!anonymous)
+ add_to_menu(&mi, TEXT_(T_DOWNLOAD_LINK),
+ cast_uchar "d",
+ TEXT_(T_HK_DOWNLOAD_LINK),
+ send_download, NULL, 0, -1);
if (clipboard_support(term))
- add_to_menu(&mi, TEXT_(T_COPY_LINK_LOCATION), cast_uchar "", TEXT_(T_HK_COPY_LINK_LOCATION), copy_link_location, NULL, 0, -1);
+ add_to_menu(&mi, TEXT_(T_COPY_LINK_LOCATION),
+ cast_uchar "",
+ TEXT_(T_HK_COPY_LINK_LOCATION),
+ copy_link_location, NULL, 0, -1);
}
}
- if ((link->type == L_CHECKBOX || link->type == L_SELECT || link->type == L_FIELD || link->type == L_AREA) && link->form) {
+ if ((link->type == L_CHECKBOX || link->type == L_SELECT
+ || link->type == L_FIELD || link->type == L_AREA)
+ && link->form) {
int c = can_open_in_new(term);
- add_to_menu(&mi, TEXT_(T_SUBMIT_FORM), cast_uchar "", TEXT_(T_HK_SUBMIT_FORM), send_submit, NULL, 0, -1);
- if (c && link->form->method == FM_GET) add_to_menu(&mi, TEXT_(T_SUBMIT_FORM_AND_OPEN_IN_NEW_WINDOW), c - 1 ? cast_uchar ">" : cast_uchar "", TEXT_(T_HK_SUBMIT_FORM_AND_OPEN_IN_NEW_WINDOW), open_in_new_window, (void *)&send_open_in_new_xterm_ptr, c - 1, -1);
- /*if (!anonymous) add_to_menu(&mi, TEXT_(T_SUBMIT_FORM_AND_DOWNLOAD), cast_uchar "d", TEXT_(T_HK_SUBMIT_FORM_AND_DOWNLOAD), send_download, NULL, 0, -1);*/
- add_to_menu(&mi, TEXT_(T_RESET_FORM), cast_uchar "", TEXT_(T_HK_RESET_FORM), send_reset, NULL, 0, -1);
+ add_to_menu(&mi, TEXT_(T_SUBMIT_FORM), cast_uchar "",
+ TEXT_(T_HK_SUBMIT_FORM), send_submit, NULL, 0, -1);
+ if (c && link->form->method == FM_GET)
+ add_to_menu(
+ &mi, TEXT_(T_SUBMIT_FORM_AND_OPEN_IN_NEW_WINDOW),
+ c - 1 ? cast_uchar ">" : cast_uchar "",
+ TEXT_(T_HK_SUBMIT_FORM_AND_OPEN_IN_NEW_WINDOW),
+ open_in_new_window,
+ (void *)&send_open_in_new_xterm_ptr, c - 1, -1);
+ /*if (!anonymous) add_to_menu(&mi,
+ * TEXT_(T_SUBMIT_FORM_AND_DOWNLOAD), cast_uchar "d",
+ * TEXT_(T_HK_SUBMIT_FORM_AND_DOWNLOAD), send_download, NULL, 0,
+ * -1);*/
+ add_to_menu(&mi, TEXT_(T_RESET_FORM), cast_uchar "",
+ TEXT_(T_HK_RESET_FORM), send_reset, NULL, 0, -1);
}
if (link->type == L_BUTTON && link->form) {
- if (link->form->type == FC_RESET) add_to_menu(&mi, TEXT_(T_RESET_FORM), cast_uchar "", TEXT_(T_HK_RESET_FORM), send_enter, NULL, 0, -1);
- else if (link->form->type==FC_BUTTON)
+ if (link->form->type == FC_RESET)
+ add_to_menu(&mi, TEXT_(T_RESET_FORM), cast_uchar "",
+ TEXT_(T_HK_RESET_FORM), send_enter, NULL, 0,
+ -1);
+ else if (link->form->type == FC_BUTTON)
;
- else if (link->form->type == FC_SUBMIT || link->form->type == FC_IMAGE) {
+ else if (link->form->type == FC_SUBMIT
+ || link->form->type == FC_IMAGE) {
int c = can_open_in_new(term);
- add_to_menu(&mi, TEXT_(T_SUBMIT_FORM), cast_uchar "", TEXT_(T_HK_SUBMIT_FORM), send_enter, NULL, 0, -1);
- if (c && link->form->method == FM_GET) add_to_menu(&mi, TEXT_(T_SUBMIT_FORM_AND_OPEN_IN_NEW_WINDOW), c - 1 ? cast_uchar ">" : cast_uchar "", TEXT_(T_HK_SUBMIT_FORM_AND_OPEN_IN_NEW_WINDOW), open_in_new_window, (void *)&send_open_in_new_xterm_ptr, c - 1, -1);
- if (!anonymous) add_to_menu(&mi, TEXT_(T_SUBMIT_FORM_AND_DOWNLOAD), cast_uchar "d", TEXT_(T_HK_SUBMIT_FORM_AND_DOWNLOAD), send_download, NULL, 0, -1);
+ add_to_menu(&mi, TEXT_(T_SUBMIT_FORM), cast_uchar "",
+ TEXT_(T_HK_SUBMIT_FORM), send_enter, NULL,
+ 0, -1);
+ if (c && link->form->method == FM_GET)
+ add_to_menu(
+ &mi,
+ TEXT_(T_SUBMIT_FORM_AND_OPEN_IN_NEW_WINDOW),
+ c - 1 ? cast_uchar ">" : cast_uchar "",
+ TEXT_(
+ T_HK_SUBMIT_FORM_AND_OPEN_IN_NEW_WINDOW),
+ open_in_new_window,
+ (void *)&send_open_in_new_xterm_ptr, c - 1,
+ -1);
+ if (!anonymous)
+ add_to_menu(
+ &mi, TEXT_(T_SUBMIT_FORM_AND_DOWNLOAD),
+ cast_uchar "d",
+ TEXT_(T_HK_SUBMIT_FORM_AND_DOWNLOAD),
+ send_download, NULL, 0, -1);
}
}
if (link->where_img) {
- add_to_menu(&mi, TEXT_(T_VIEW_IMAGE), cast_uchar "i", TEXT_(T_HK_VIEW_IMAGE), send_image, NULL, 0, -1);
+ add_to_menu(&mi, TEXT_(T_VIEW_IMAGE), cast_uchar "i",
+ TEXT_(T_HK_VIEW_IMAGE), send_image, NULL, 0, -1);
if (!anonymous)
- add_to_menu(&mi, TEXT_(T_DOWNLOAD_IMAGE), cast_uchar "I", TEXT_(T_HK_DOWNLOAD_IMAGE), send_download_image, NULL, 0, -1);
+ add_to_menu(&mi, TEXT_(T_DOWNLOAD_IMAGE),
+ cast_uchar "I", TEXT_(T_HK_DOWNLOAD_IMAGE),
+ send_download_image, NULL, 0, -1);
}
- no_l:
- if (!mi->text) add_to_menu(&mi, TEXT_(T_NO_LINK_SELECTED), cast_uchar "", M_BAR, NULL, NULL, 0, -1);
+no_l:
+ if (!mi->text)
+ add_to_menu(&mi, TEXT_(T_NO_LINK_SELECTED), cast_uchar "",
+ M_BAR, NULL, NULL, 0, -1);
do_menu(term, mi, ses);
}
-static unsigned char *print_current_titlex(struct f_data_c *fd, int w)
+static unsigned char *
+print_current_titlex(struct f_data_c *fd, int w)
{
int mul, pul;
int ml = 0, pl = 0;
unsigned char *m, *p;
- if (!fd || !fd->vs || !fd->f_data) return NULL;
+ if (!fd || !fd->vs || !fd->f_data)
+ return NULL;
w -= 1;
p = init_str();
if (fd->yw < fd->f_data->y) {
@@ -3322,25 +4192,36 @@ static unsigned char *print_current_titlex(struct f_data_c *fd, int w)
if (fd->yw) {
pp = (fd->vs->view_pos + fd->yw / 2) / fd->yw + 1;
pe = (fd->f_data->y + fd->yw - 1) / fd->yw;
- } else pp = pe = 1;
- if (pp > pe) pp = pe;
- if (fd->vs->view_pos + fd->yw >= fd->f_data->y) pp = pe;
+ } else
+ pp = pe = 1;
+ if (pp > pe)
+ pp = pe;
+ if (fd->vs->view_pos + fd->yw >= fd->f_data->y)
+ pp = pe;
if (fd->f_data->title)
add_chr_to_str(&p, &pl, ' ');
- add_to_str(&p, &pl, get_text_translation(TEXT_(T_PAGE_P), fd->ses->term));
+ add_to_str(
+ &p, &pl,
+ get_text_translation(TEXT_(T_PAGE_P), fd->ses->term));
add_num_to_str(&p, &pl, pp);
- add_to_str(&p, &pl, get_text_translation(TEXT_(T_PAGE_OF), fd->ses->term));
+ add_to_str(
+ &p, &pl,
+ get_text_translation(TEXT_(T_PAGE_OF), fd->ses->term));
add_num_to_str(&p, &pl, pe);
- add_to_str(&p, &pl, get_text_translation(TEXT_(T_PAGE_CL), fd->ses->term));
+ add_to_str(
+ &p, &pl,
+ get_text_translation(TEXT_(T_PAGE_CL), fd->ses->term));
}
- if (!fd->f_data->title) return p;
+ if (!fd->f_data->title)
+ return p;
m = init_str();
add_to_str(&m, &ml, fd->f_data->title);
mul = strlen((char *)m);
pul = strlen((char *)p);
if (mul + pul > w) {
unsigned char *mm;
- if ((mul = w - pul) < 0) mul = 0;
+ if ((mul = w - pul) < 0)
+ mul = 0;
for (mm = m; mul--; GET_TERM_CHAR(fd->ses->term, &mm))
;
ml = (int)(mm - m);
@@ -3350,14 +4231,19 @@ static unsigned char *print_current_titlex(struct f_data_c *fd, int w)
return m;
}
-static unsigned char *print_current_linkx(struct f_data_c *fd, struct terminal *term)
+static unsigned char *
+print_current_linkx(struct f_data_c *fd, struct terminal *term)
{
int ll = 0;
struct link *l;
unsigned char *d;
unsigned char *m = NULL;
- if (!fd || !fd->vs || !fd->f_data) return NULL;
- if (fd->vs->current_link == -1 || fd->vs->current_link >= fd->f_data->nlinks || fd->f_data->frame_desc) return NULL;
+ if (!fd || !fd->vs || !fd->f_data)
+ return NULL;
+ if (fd->vs->current_link == -1
+ || fd->vs->current_link >= fd->f_data->nlinks
+ || fd->f_data->frame_desc)
+ return NULL;
l = &fd->f_data->links[fd->vs->current_link];
if (l->type == L_LINK) {
if (!l->where && l->where_img) {
@@ -3366,11 +4252,15 @@ static unsigned char *print_current_linkx(struct f_data_c *fd, struct terminal *
if (l->img_alt) {
unsigned char *txt;
- txt = convert(fd->f_data->cp, fd->f_data->opt.cp, l->img_alt, &fd->f_data->opt);
+ txt =
+ convert(fd->f_data->cp, fd->f_data->opt.cp,
+ l->img_alt, &fd->f_data->opt);
add_to_str(&m, &ll, txt);
free(txt);
} else {
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_IMAGE), term));
+ add_to_str(
+ &m, &ll,
+ get_text_translation(TEXT_(T_IMAGE), term));
add_chr_to_str(&m, &ll, ' ');
d = display_url(term, l->where_img, 1);
add_to_str(&m, &ll, d);
@@ -3378,10 +4268,12 @@ static unsigned char *print_current_linkx(struct f_data_c *fd, struct terminal *
}
goto p;
}
- if (l->where && strlen(cast_const_char l->where) >= 4 && !casecmp(l->where, cast_uchar "MAP@", 4)) {
+ if (l->where && strlen(cast_const_char l->where) >= 4
+ && !casecmp(l->where, cast_uchar "MAP@", 4)) {
m = init_str();
ll = 0;
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_USEMAP), term));
+ add_to_str(&m, &ll,
+ get_text_translation(TEXT_(T_USEMAP), term));
add_chr_to_str(&m, &ll, ' ');
d = display_url(term, l->where + 4, 1);
add_to_str(&m, &ll, d);
@@ -3395,51 +4287,76 @@ static unsigned char *print_current_linkx(struct f_data_c *fd, struct terminal *
m = stracpy((unsigned char *)"");
goto p;
}
- if (!l->form) return NULL;
+ if (!l->form)
+ return NULL;
if (l->type == L_BUTTON) {
if (l->form->type == FC_BUTTON) {
m = init_str();
ll = 0;
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_BUTTON), term));
+ add_to_str(&m, &ll,
+ get_text_translation(TEXT_(T_BUTTON), term));
goto p;
}
if (l->form->type == FC_RESET) {
- m = stracpy(get_text_translation(TEXT_(T_RESET_FORM), term));
+ m = stracpy(
+ get_text_translation(TEXT_(T_RESET_FORM), term));
goto p;
}
- if (!l->form->action) return NULL;
+ if (!l->form->action)
+ return NULL;
m = init_str();
ll = 0;
- if (l->form->method == FM_GET) add_to_str(&m, &ll, get_text_translation(TEXT_(T_SUBMIT_FORM_TO), term));
- else add_to_str(&m, &ll, get_text_translation(TEXT_(T_POST_FORM_TO), term));
+ if (l->form->method == FM_GET)
+ add_to_str(&m, &ll,
+ get_text_translation(TEXT_(T_SUBMIT_FORM_TO),
+ term));
+ else
+ add_to_str(
+ &m, &ll,
+ get_text_translation(TEXT_(T_POST_FORM_TO), term));
add_chr_to_str(&m, &ll, ' ');
add_to_str(&m, &ll, l->form->action);
goto p;
}
- if (l->type == L_CHECKBOX || l->type == L_SELECT || l->type == L_FIELD || l->type == L_AREA) {
+ if (l->type == L_CHECKBOX || l->type == L_SELECT || l->type == L_FIELD
+ || l->type == L_AREA) {
m = init_str();
ll = 0;
switch (l->form->type) {
case FC_RADIO:
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_RADIO_BUTTON), term));
+ add_to_str(
+ &m, &ll,
+ get_text_translation(TEXT_(T_RADIO_BUTTON), term));
break;
case FC_CHECKBOX:
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_CHECKBOX), term));
+ add_to_str(
+ &m, &ll,
+ get_text_translation(TEXT_(T_CHECKBOX), term));
break;
case FC_SELECT:
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_SELECT_FIELD), term));
+ add_to_str(
+ &m, &ll,
+ get_text_translation(TEXT_(T_SELECT_FIELD), term));
break;
case FC_TEXT:
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_TEXT_FIELD), term));
+ add_to_str(
+ &m, &ll,
+ get_text_translation(TEXT_(T_TEXT_FIELD), term));
break;
case FC_TEXTAREA:
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_TEXT_AREA), term));
+ add_to_str(
+ &m, &ll,
+ get_text_translation(TEXT_(T_TEXT_AREA), term));
break;
case FC_FILE_UPLOAD:
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_FILE_UPLOAD), term));
+ add_to_str(
+ &m, &ll,
+ get_text_translation(TEXT_(T_FILE_UPLOAD), term));
break;
case FC_PASSWORD:
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_PASSWORD_FIELD), term));
+ add_to_str(&m, &ll,
+ get_text_translation(TEXT_(T_PASSWORD_FIELD),
+ term));
break;
default:
free(m);
@@ -3447,33 +4364,41 @@ static unsigned char *print_current_linkx(struct f_data_c *fd, struct terminal *
}
if (l->form->name && l->form->name[0]) {
add_to_str(&m, &ll, cast_uchar ", ");
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_NAME),
- term));
+ add_to_str(&m, &ll,
+ get_text_translation(TEXT_(T_NAME), term));
add_chr_to_str(&m, &ll, ' ');
add_to_str(&m, &ll, l->form->name);
}
if ((l->form->type == FC_CHECKBOX || l->form->type == FC_RADIO)
- && l->form->default_value
- && l->form->default_value[0]) {
+ && l->form->default_value && l->form->default_value[0]) {
add_to_str(&m, &ll, cast_uchar ", ");
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_VALUE),
- term));
+ add_to_str(&m, &ll,
+ get_text_translation(TEXT_(T_VALUE), term));
add_chr_to_str(&m, &ll, ' ');
add_to_str(&m, &ll, l->form->default_value);
}
- /* pri enteru se bude posilat vzdycky -- Brain */
- if (l->type == L_FIELD && !has_form_submit(fd->f_data, l->form) && l->form->action) {
+ /* pri enteru se bude posilat vzdycky -- Brain */
+ if (l->type == L_FIELD && !has_form_submit(fd->f_data, l->form)
+ && l->form->action) {
add_to_str(&m, &ll, cast_uchar ", ");
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_HIT_ENTER_TO), term));
+ add_to_str(
+ &m, &ll,
+ get_text_translation(TEXT_(T_HIT_ENTER_TO), term));
add_chr_to_str(&m, &ll, ' ');
- if (l->form->method == FM_GET) add_to_str(&m, &ll, get_text_translation(TEXT_(T_SUBMIT_TO), term));
- else add_to_str(&m, &ll, get_text_translation(TEXT_(T_POST_TO), term));
+ if (l->form->method == FM_GET)
+ add_to_str(&m, &ll,
+ get_text_translation(
+ TEXT_(T_SUBMIT_TO), term));
+ else
+ add_to_str(&m, &ll,
+ get_text_translation(
+ TEXT_(T_POST_TO), term));
add_chr_to_str(&m, &ll, ' ');
add_to_str(&m, &ll, l->form->action);
}
goto p;
}
- p:
+p:
return m;
}
@@ -3483,43 +4408,51 @@ static unsigned char *print_current_linkx(struct f_data_c *fd, struct terminal *
Ach jo, to Brain kopiroval kod, snad to nedela i v ty firme,
kde ted pracuje... -- mikulas
*/
-static unsigned char *print_current_linkx_plus(struct f_data_c *fd, struct terminal *term)
+static unsigned char *
+print_current_linkx_plus(struct f_data_c *fd, struct terminal *term)
{
int ll = 0;
struct link *l;
unsigned char *d;
unsigned char *m = NULL;
- if (!fd || !fd->vs || !fd->f_data) return NULL;
- if (fd->vs->current_link == -1 || fd->vs->current_link >= fd->f_data->nlinks || fd->f_data->frame_desc) return NULL;
+ if (!fd || !fd->vs || !fd->f_data)
+ return NULL;
+ if (fd->vs->current_link == -1
+ || fd->vs->current_link >= fd->f_data->nlinks
+ || fd->f_data->frame_desc)
+ return NULL;
l = &fd->f_data->links[fd->vs->current_link];
if (l->type == L_LINK) {
unsigned char *spc;
m = init_str();
ll = 0;
- if (l->where && strlen(cast_const_char l->where) >= 4 && !casecmp(l->where, cast_uchar "MAP@", 4)) {
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_USEMAP), term));
+ if (l->where && strlen(cast_const_char l->where) >= 4
+ && !casecmp(l->where, cast_uchar "MAP@", 4)) {
+ add_to_str(&m, &ll,
+ get_text_translation(TEXT_(T_USEMAP), term));
add_chr_to_str(&m, &ll, ' ');
d = display_url(term, l->where + 4, 1);
add_to_str(&m, &ll, d);
free(d);
- }
- else if (l->where) {
+ } else if (l->where) {
d = display_url(term, l->where, 1);
add_to_str(&m, &ll, d);
free(d);
}
spc = stracpy((unsigned char *)"");
- if (spc&&*spc)
- {
+ if (spc && *spc) {
add_to_str(&m, &ll, cast_uchar "\n");
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_JAVASCRIPT), term));
+ add_to_str(
+ &m, &ll,
+ get_text_translation(TEXT_(T_JAVASCRIPT), term));
add_to_str(&m, &ll, cast_uchar ": ");
add_to_str(&m, &ll, spc);
}
free(spc);
if (l->where_img) {
add_to_str(&m, &ll, cast_uchar "\n");
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_IMAGE), term));
+ add_to_str(&m, &ll,
+ get_text_translation(TEXT_(T_IMAGE), term));
add_to_str(&m, &ll, cast_uchar ": src='");
d = display_url(term, l->where_img, 1);
add_to_str(&m, &ll, d);
@@ -3530,7 +4463,9 @@ static unsigned char *print_current_linkx_plus(struct f_data_c *fd, struct termi
unsigned char *txt;
add_to_str(&m, &ll, cast_uchar " alt='");
- txt = convert(fd->f_data->cp, fd->f_data->opt.cp, l->img_alt, &fd->f_data->opt);
+ txt =
+ convert(fd->f_data->cp, fd->f_data->opt.cp,
+ l->img_alt, &fd->f_data->opt);
add_to_str(&m, &ll, txt);
add_chr_to_str(&m, &ll, '\'');
free(txt);
@@ -3539,51 +4474,76 @@ static unsigned char *print_current_linkx_plus(struct f_data_c *fd, struct termi
}
goto p;
}
- if (!l->form) return NULL;
+ if (!l->form)
+ return NULL;
if (l->type == L_BUTTON) {
if (l->form->type == FC_BUTTON) {
m = init_str();
ll = 0;
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_BUTTON), term));
+ add_to_str(&m, &ll,
+ get_text_translation(TEXT_(T_BUTTON), term));
goto p;
}
if (l->form->type == FC_RESET) {
- m = stracpy(get_text_translation(TEXT_(T_RESET_FORM), term));
+ m = stracpy(
+ get_text_translation(TEXT_(T_RESET_FORM), term));
goto p;
}
- if (!l->form->action) return NULL;
+ if (!l->form->action)
+ return NULL;
m = init_str();
ll = 0;
- if (l->form->method == FM_GET) add_to_str(&m, &ll, get_text_translation(TEXT_(T_SUBMIT_FORM_TO), term));
- else add_to_str(&m, &ll, get_text_translation(TEXT_(T_POST_FORM_TO), term));
+ if (l->form->method == FM_GET)
+ add_to_str(&m, &ll,
+ get_text_translation(TEXT_(T_SUBMIT_FORM_TO),
+ term));
+ else
+ add_to_str(
+ &m, &ll,
+ get_text_translation(TEXT_(T_POST_FORM_TO), term));
add_chr_to_str(&m, &ll, ' ');
add_to_str(&m, &ll, l->form->action);
goto p;
}
- if (l->type == L_CHECKBOX || l->type == L_SELECT || l->type == L_FIELD || l->type == L_AREA) {
+ if (l->type == L_CHECKBOX || l->type == L_SELECT || l->type == L_FIELD
+ || l->type == L_AREA) {
m = init_str();
ll = 0;
switch (l->form->type) {
case FC_RADIO:
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_RADIO_BUTTON), term));
+ add_to_str(
+ &m, &ll,
+ get_text_translation(TEXT_(T_RADIO_BUTTON), term));
break;
case FC_CHECKBOX:
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_CHECKBOX), term));
+ add_to_str(
+ &m, &ll,
+ get_text_translation(TEXT_(T_CHECKBOX), term));
break;
case FC_SELECT:
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_SELECT_FIELD), term));
+ add_to_str(
+ &m, &ll,
+ get_text_translation(TEXT_(T_SELECT_FIELD), term));
break;
case FC_TEXT:
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_TEXT_FIELD), term));
+ add_to_str(
+ &m, &ll,
+ get_text_translation(TEXT_(T_TEXT_FIELD), term));
break;
case FC_TEXTAREA:
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_TEXT_AREA), term));
+ add_to_str(
+ &m, &ll,
+ get_text_translation(TEXT_(T_TEXT_AREA), term));
break;
case FC_FILE_UPLOAD:
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_FILE_UPLOAD), term));
+ add_to_str(
+ &m, &ll,
+ get_text_translation(TEXT_(T_FILE_UPLOAD), term));
break;
case FC_PASSWORD:
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_PASSWORD_FIELD), term));
+ add_to_str(&m, &ll,
+ get_text_translation(TEXT_(T_PASSWORD_FIELD),
+ term));
break;
default:
free(m);
@@ -3591,27 +4551,35 @@ static unsigned char *print_current_linkx_plus(struct f_data_c *fd, struct termi
}
if (l->form->name && l->form->name[0]) {
add_to_str(&m, &ll, cast_uchar ", ");
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_NAME),
- term));
+ add_to_str(&m, &ll,
+ get_text_translation(TEXT_(T_NAME), term));
add_chr_to_str(&m, &ll, ' ');
add_to_str(&m, &ll, l->form->name);
}
if ((l->form->type == FC_CHECKBOX || l->form->type == FC_RADIO)
- && l->form->default_value
- && l->form->default_value[0]) {
+ && l->form->default_value && l->form->default_value[0]) {
add_to_str(&m, &ll, cast_uchar ", ");
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_VALUE),
- term));
+ add_to_str(&m, &ll,
+ get_text_translation(TEXT_(T_VALUE), term));
add_chr_to_str(&m, &ll, ' ');
add_to_str(&m, &ll, l->form->default_value);
}
- /* pri enteru se bude posilat vzdycky -- Brain */
- if (l->type == L_FIELD && !has_form_submit(fd->f_data, l->form) && l->form->action) {
+ /* pri enteru se bude posilat vzdycky -- Brain */
+ if (l->type == L_FIELD && !has_form_submit(fd->f_data, l->form)
+ && l->form->action) {
add_to_str(&m, &ll, cast_uchar ", ");
- add_to_str(&m, &ll, get_text_translation(TEXT_(T_HIT_ENTER_TO), term));
+ add_to_str(
+ &m, &ll,
+ get_text_translation(TEXT_(T_HIT_ENTER_TO), term));
add_chr_to_str(&m, &ll, ' ');
- if (l->form->method == FM_GET) add_to_str(&m, &ll, get_text_translation(TEXT_(T_SUBMIT_TO), term));
- else add_to_str(&m, &ll, get_text_translation(TEXT_(T_POST_TO), term));
+ if (l->form->method == FM_GET)
+ add_to_str(&m, &ll,
+ get_text_translation(
+ TEXT_(T_SUBMIT_TO), term));
+ else
+ add_to_str(&m, &ll,
+ get_text_translation(
+ TEXT_(T_POST_TO), term));
add_chr_to_str(&m, &ll, ' ');
add_to_str(&m, &ll, l->form->action);
}
@@ -3621,24 +4589,29 @@ p:
return m;
}
-unsigned char *print_current_link(struct session *ses)
+unsigned char *
+print_current_link(struct session *ses)
{
return print_current_linkx(current_frame(ses), ses->term);
}
-unsigned char *print_current_title(struct session *ses)
+unsigned char *
+print_current_title(struct session *ses)
{
return print_current_titlex(current_frame(ses), ses->term->x);
}
-void loc_msg(struct terminal *term, struct location *lo, struct f_data_c *frame)
+void
+loc_msg(struct terminal *term, struct location *lo, struct f_data_c *frame)
{
struct cache_entry *ce;
unsigned char *s;
int l = 0;
unsigned char *a;
if (!lo || !frame || !frame->vs || !frame->f_data) {
- msg_box(term, NULL, TEXT_(T_INFO), AL_LEFT, TEXT_(T_YOU_ARE_NOWHERE), MSG_BOX_END, NULL, 1, TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
+ msg_box(term, NULL, TEXT_(T_INFO), AL_LEFT,
+ TEXT_(T_YOU_ARE_NOWHERE), MSG_BOX_END, NULL, 1,
+ TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
return;
}
s = init_str();
@@ -3653,9 +4626,13 @@ void loc_msg(struct terminal *term, struct location *lo, struct f_data_c *frame)
if (ce->ip_address) {
add_to_str(&s, &l, cast_uchar "\n");
if (!strchr(cast_const_char ce->ip_address, ' '))
- add_to_str(&s, &l, get_text_translation(TEXT_(T_IP_ADDRESS), term));
+ add_to_str(&s, &l,
+ get_text_translation(
+ TEXT_(T_IP_ADDRESS), term));
else
- add_to_str(&s, &l, get_text_translation(TEXT_(T_IP_ADDRESSES), term));
+ add_to_str(&s, &l,
+ get_text_translation(
+ TEXT_(T_IP_ADDRESSES), term));
add_to_str(&s, &l, cast_uchar ": ");
add_to_str(&s, &l, ce->ip_address);
}
@@ -3671,7 +4648,9 @@ void loc_msg(struct terminal *term, struct location *lo, struct f_data_c *frame)
add_to_str(&s, &l, cast_uchar " (");
add_num_to_str(&s, &l, ce->length);
add_chr_to_str(&s, &l, ' ');
- add_to_str(&s, &l, get_text_translation(TEXT_(T_COMPRESSED_WITH), term));
+ add_to_str(&s, &l,
+ get_text_translation(
+ TEXT_(T_COMPRESSED_WITH), term));
add_chr_to_str(&s, &l, ' ');
add_to_str(&s, &l, enc);
add_chr_to_str(&s, &l, ')');
@@ -3682,65 +4661,94 @@ void loc_msg(struct terminal *term, struct location *lo, struct f_data_c *frame)
}
if (ce->incomplete) {
add_to_str(&s, &l, cast_uchar " (");
- add_to_str(&s, &l, get_text_translation(TEXT_(T_INCOMPLETE), term));
+ add_to_str(
+ &s, &l,
+ get_text_translation(TEXT_(T_INCOMPLETE), term));
add_chr_to_str(&s, &l, ')');
}
if (frame->f_data->ass >= 0) {
add_to_str(&s, &l, cast_uchar "\n");
- add_to_str(&s, &l, get_text_translation(TEXT_(T_CODEPAGE), term));
+ add_to_str(
+ &s, &l,
+ get_text_translation(TEXT_(T_CODEPAGE), term));
add_to_str(&s, &l, cast_uchar ": ");
add_to_str(&s, &l, get_cp_name(frame->f_data->cp));
if (frame->f_data->ass == 1) {
add_to_str(&s, &l, cast_uchar " (");
- add_to_str(&s, &l, get_text_translation(TEXT_(T_ASSUMED), term));
+ add_to_str(&s, &l,
+ get_text_translation(
+ TEXT_(T_ASSUMED), term));
add_chr_to_str(&s, &l, ')');
}
if (frame->f_data->ass == 2) {
add_to_str(&s, &l, cast_uchar " (");
- add_to_str(&s, &l, get_text_translation(TEXT_(T_IGNORING_SERVER_SETTING), term));
+ add_to_str(&s, &l,
+ get_text_translation(
+ TEXT_(T_IGNORING_SERVER_SETTING),
+ term));
add_chr_to_str(&s, &l, ')');
}
}
- if (ce->head && ce->head[0] != '\n' && ce->head[0] != '\r' && (a = parse_http_header(ce->head, cast_uchar "Content-Type", NULL))) {
+ if (ce->head && ce->head[0] != '\n' && ce->head[0] != '\r'
+ && (a = parse_http_header(
+ ce->head, cast_uchar "Content-Type", NULL))) {
add_to_str(&s, &l, cast_uchar "\n");
- add_to_str(&s, &l, get_text_translation(TEXT_(T_CONTENT_TYPE), term));
+ add_to_str(
+ &s, &l,
+ get_text_translation(TEXT_(T_CONTENT_TYPE), term));
add_to_str(&s, &l, cast_uchar ": ");
add_to_str(&s, &l, a);
free(a);
}
- if ((a = parse_http_header(ce->head, cast_uchar "Server", NULL))) {
+ if ((a = parse_http_header(ce->head, cast_uchar "Server",
+ NULL))) {
add_to_str(&s, &l, cast_uchar "\n");
- add_to_str(&s, &l, get_text_translation(TEXT_(T_SERVER), term));
+ add_to_str(&s, &l,
+ get_text_translation(TEXT_(T_SERVER), term));
add_to_str(&s, &l, cast_uchar ": ");
add_to_str(&s, &l, a);
free(a);
}
- if ((a = parse_http_header(ce->head, cast_uchar "Date", NULL))) {
+ if ((a = parse_http_header(ce->head, cast_uchar "Date",
+ NULL))) {
add_to_str(&s, &l, cast_uchar "\n");
- add_to_str(&s, &l, get_text_translation(TEXT_(T_DATE), term));
+ add_to_str(&s, &l,
+ get_text_translation(TEXT_(T_DATE), term));
add_to_str(&s, &l, cast_uchar ": ");
add_to_str(&s, &l, a);
free(a);
}
- if ((a = parse_http_header(ce->head, cast_uchar "Last-Modified", NULL))) {
+ if ((a = parse_http_header(ce->head, cast_uchar "Last-Modified",
+ NULL))) {
add_to_str(&s, &l, cast_uchar "\n");
- add_to_str(&s, &l, get_text_translation(TEXT_(T_LAST_MODIFIED), term));
+ add_to_str(
+ &s, &l,
+ get_text_translation(TEXT_(T_LAST_MODIFIED), term));
add_to_str(&s, &l, cast_uchar ": ");
add_to_str(&s, &l, a);
free(a);
}
if (ce->ssl_info) {
add_to_str(&s, &l, cast_uchar "\n");
- add_to_str(&s, &l, get_text_translation(TEXT_(T_SSL_CIPHER), term));
+ add_to_str(
+ &s, &l,
+ get_text_translation(TEXT_(T_SSL_CIPHER), term));
add_to_str(&s, &l, cast_uchar ": ");
add_to_str(&s, &l, ce->ssl_info);
}
if (ce->ssl_authority) {
add_to_str(&s, &l, cast_uchar "\n");
- if (strstr(cast_const_char ce->ssl_authority, cast_const_char CERT_RIGHT_ARROW))
- add_to_str(&s, &l, get_text_translation(TEXT_(T_CERTIFICATE_AUTHORITIES), term));
+ if (strstr(cast_const_char ce->ssl_authority,
+ cast_const_char CERT_RIGHT_ARROW))
+ add_to_str(&s, &l,
+ get_text_translation(
+ TEXT_(T_CERTIFICATE_AUTHORITIES),
+ term));
else
- add_to_str(&s, &l, get_text_translation(TEXT_(T_CERTIFICATE_AUTHORITY), term));
+ add_to_str(
+ &s, &l,
+ get_text_translation(
+ TEXT_(T_CERTIFICATE_AUTHORITY), term));
add_to_str(&s, &l, cast_uchar ": ");
add_to_str(&s, &l, ce->ssl_authority);
}
@@ -3749,43 +4757,61 @@ void loc_msg(struct terminal *term, struct location *lo, struct f_data_c *frame)
if ((a = print_current_linkx_plus(frame, term))) {
add_to_str(&s, &l, cast_uchar "\n\n");
if (*a != '\n') {
- add_to_str(&s, &l, get_text_translation(TEXT_(T_LINK), term));
+ add_to_str(&s, &l,
+ get_text_translation(TEXT_(T_LINK), term));
add_to_str(&s, &l, cast_uchar ": ");
add_to_str(&s, &l, a);
} else
add_to_str(&s, &l, a + 1);
free(a);
}
- msg_box(term, getml(s, NULL), TEXT_(T_INFO), AL_LEFT, s, MSG_BOX_END, NULL, 1, TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
+ msg_box(term, getml(s, NULL), TEXT_(T_INFO), AL_LEFT, s, MSG_BOX_END,
+ NULL, 1, TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
}
-void state_msg(struct session *ses)
+void
+state_msg(struct session *ses)
{
- if (list_empty(ses->history)) loc_msg(ses->term, NULL, NULL);
- else loc_msg(ses->term, cur_loc(ses), current_frame(ses));
+ if (list_empty(ses->history))
+ loc_msg(ses->term, NULL, NULL);
+ else
+ loc_msg(ses->term, cur_loc(ses), current_frame(ses));
}
-void head_msg(struct session *ses)
+void
+head_msg(struct session *ses)
{
struct cache_entry *ce;
unsigned char *s, *ss;
int len;
if (list_empty(ses->history)) {
- msg_box(ses->term, NULL, TEXT_(T_HEADER_INFO), AL_LEFT, TEXT_(T_YOU_ARE_NOWHERE), MSG_BOX_END, NULL, 1, TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
+ msg_box(ses->term, NULL, TEXT_(T_HEADER_INFO), AL_LEFT,
+ TEXT_(T_YOU_ARE_NOWHERE), MSG_BOX_END, NULL, 1,
+ TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
return;
}
if (!find_in_cache(cur_loc(ses)->url, &ce)) {
- if (ce->head) s = stracpy(ce->head);
- else s = stracpy(cast_uchar "");
+ if (ce->head)
+ s = stracpy(ce->head);
+ else
+ s = stracpy(cast_uchar "");
len = (int)strlen(cast_const_char s) - 1;
if (len > 0) {
- while ((ss = cast_uchar strstr(cast_const_char s, "\r\n"))) memmove(ss, ss + 1, strlen(cast_const_char ss));
- while (*s && s[strlen(cast_const_char s) - 1] == '\n') s[strlen(cast_const_char s) - 1] = 0;
+ while (
+ (ss = cast_uchar strstr(cast_const_char s, "\r\n")))
+ memmove(ss, ss + 1, strlen(cast_const_char ss));
+ while (*s && s[strlen(cast_const_char s) - 1] == '\n')
+ s[strlen(cast_const_char s) - 1] = 0;
}
if (*s && *s != '\n') {
- msg_box(ses->term, getml(s, NULL), TEXT_(T_HEADER_INFO), AL_LEFT, s, MSG_BOX_END, NULL, 1, TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
+ msg_box(ses->term, getml(s, NULL), TEXT_(T_HEADER_INFO),
+ AL_LEFT, s, MSG_BOX_END, NULL, 1, TEXT_(T_OK),
+ msg_box_null, B_ENTER | B_ESC);
} else {
- msg_box(ses->term, getml(s, NULL), TEXT_(T_HEADER_INFO), AL_CENTER, TEXT_(T_NO_HEADER), MSG_BOX_END, NULL, 1, TEXT_(T_OK), msg_box_null, B_ENTER | B_ESC);
+ msg_box(ses->term, getml(s, NULL), TEXT_(T_HEADER_INFO),
+ AL_CENTER, TEXT_(T_NO_HEADER), MSG_BOX_END,
+ NULL, 1, TEXT_(T_OK), msg_box_null,
+ B_ENTER | B_ESC);
}
ce->refcount--;
}