diff --git a/src/dom/test/dom-select.c b/src/dom/test/dom-select.c index e4cc6f238..52b4a6a3e 100644 --- a/src/dom/test/dom-select.c +++ b/src/dom/test/dom-select.c @@ -15,21 +15,7 @@ #include "dom/select.h" #include "dom/sgml/parser.h" #include "dom/stack.h" - - -void die(const char *msg, ...) -{ - va_list args; - - if (msg) { - va_start(args, msg); - vfprintf(stderr, msg, args); - fputs("\n", stderr); - va_end(args); - } - - exit(!!NULL); -} +#include "util/test.h" int main(int argc, char *argv[]) @@ -51,41 +37,14 @@ main(int argc, char *argv[]) arg += 2; - if (!strncmp(arg, "uri", 3)) { - arg += 3; - if (*arg == '=') { - arg++; - set_dom_string(&uri, arg, strlen(arg)); - } else { - i++; - if (i >= argc) - die("--uri expects a URI"); - set_dom_string(&uri, argv[i], strlen(argv[i])); - } + if (get_test_opt(&arg, "uri", &i, argc, argv, "a URI")) { + set_dom_string(&uri, arg, strlen(arg)); - } else if (!strncmp(arg, "src", 3)) { - arg += 3; - if (*arg == '=') { - arg++; - set_dom_string(&source, arg, strlen(arg)); - } else { - i++; - if (i >= argc) - die("--src expects a string"); - set_dom_string(&source, argv[i], strlen(argv[i])); - } + } else if (get_test_opt(&arg, "src", &i, argc, argv, "a string")) { + set_dom_string(&source, arg, strlen(arg)); - } else if (!strncmp(arg, "selector", 3)) { - arg += 8; - if (*arg == '=') { - arg++; - set_dom_string(&selector, arg, strlen(arg)); - } else { - i++; - if (i >= argc) - die("--selector expects a string"); - set_dom_string(&selector, argv[i], strlen(argv[i])); - } + } else if (get_test_opt(&arg, "selector", &i, argc, argv, "a string")) { + set_dom_string(&selector, arg, strlen(arg)); } else if (!strcmp(arg, "help")) { die(NULL); diff --git a/src/dom/test/sgml-parser.c b/src/dom/test/sgml-parser.c index 5446ccd7a..eee862aed 100644 --- a/src/dom/test/sgml-parser.c +++ b/src/dom/test/sgml-parser.c @@ -16,6 +16,7 @@ #include "dom/sgml/dump.h" #include "dom/sgml/parser.h" #include "dom/stack.h" +#include "util/test.h" unsigned int number_of_lines = 0; @@ -242,44 +243,6 @@ sgml_error_function(struct sgml_parser *parser, struct dom_string *string, return DOM_CODE_OK; } -static void -die(const char *msg, ...) -{ - va_list args; - - if (msg) { - va_start(args, msg); - vfprintf(stderr, msg, args); - fputs("\n", stderr); - va_end(args); - } - - exit(!!NULL); -} - -static int -get_opt(char **argref, const char *name, int *argi, int argc, char *argv[], - const char *expect_msg) -{ - char *arg = *argref; - int namelen = strlen(name); - - if (strncmp(arg, name, namelen)) - return 0; - - arg += namelen; - if (*arg == '=') { - (*argref) = arg + 1; - } else { - (*argi)++; - if ((*argi) >= argc) - die("--%s expects %s", name, expect_msg); - (*argref) = argv[(*argi)]; - } - - return 1; -} - int main(int argc, char *argv[]) { @@ -305,17 +268,17 @@ main(int argc, char *argv[]) arg += 2; - if (get_opt(&arg, "uri", &i, argc, argv, "a URI")) { + if (get_test_opt(&arg, "uri", &i, argc, argv, "a URI")) { set_dom_string(&uri, arg, strlen(arg)); - } else if (get_opt(&arg, "src", &i, argc, argv, "a string")) { + } else if (get_test_opt(&arg, "src", &i, argc, argv, "a string")) { set_dom_string(&source, arg, strlen(arg)); - } else if (get_opt(&arg, "stdin", &i, argc, argv, "a number")) { + } else if (get_test_opt(&arg, "stdin", &i, argc, argv, "a number")) { read_stdin = atoi(arg); flags |= SGML_PARSER_INCREMENTAL; - } else if (get_opt(&arg, "normalize", &i, argc, argv, "a string")) { + } else if (get_test_opt(&arg, "normalize", &i, argc, argv, "a string")) { normalize = 1; normalize_flags = parse_dom_config(arg, ','); type = SGML_PARSER_TREE; diff --git a/src/main/event.c b/src/main/event.c index 91e1c0c9f..9b3bc5dca 100644 --- a/src/main/event.c +++ b/src/main/event.c @@ -177,6 +177,7 @@ trigger_event(int id, ...) va_start(ap, id); trigger_event_va(id, ap); + va_end(ap); } void @@ -187,6 +188,7 @@ trigger_event_name(unsigned char *name, ...) va_start(ap, name); trigger_event_va(id, ap); + va_end(ap); } static inline void diff --git a/src/mime/backend/mailcap.c b/src/mime/backend/mailcap.c index 1ca637a61..752c626c6 100644 --- a/src/mime/backend/mailcap.c +++ b/src/mime/backend/mailcap.c @@ -678,6 +678,9 @@ struct module mailcap_mime_module = struct_module( ); #ifdef TEST_MAILCAP + +#include "util/test.h" + /* Some ugly shortcuts for getting defined symbols to work. */ int default_mime_backend, install_signal_handler, @@ -685,20 +688,6 @@ int default_mime_backend, program; LIST_OF(struct terminal) terminals; -void die(const char *msg, ...) -{ - va_list args; - - if (msg) { - va_start(args, msg); - vfprintf(stderr, msg, args); - fputs("\n", stderr); - va_end(args); - } - - exit(1); -} - int main(int argc, char *argv[]) { @@ -714,44 +703,16 @@ main(int argc, char *argv[]) arg += 2; - if (!strncmp(arg, "path", 4)) { - arg += 4; - if (*arg == '=') { - arg++; - get_mailcap_path() = arg; - } else { - i++; - if (i >= argc) - die("--path expects a parameter"); - get_mailcap_path() = argv[i]; - } + if (get_test_opt(&arg, "path", &i, argc, argv, "a string")) { + get_mailcap_path() = arg; done_mailcap(NULL); - } else if (!strncmp(arg, "format", 6)) { - arg += 6; - if (*arg == '=') { - arg++; - format = arg; - } else { - i++; - if (i >= argc) - die("--format expects a parameter"); - format = argv[i]; - } + } else if (get_test_opt(&arg, "format", &i, argc, argv, "a string")) { + format = arg; - } else if (!strncmp(arg, "get", 3)) { + } else if (get_test_opt(&arg, "get", &i, argc, argv, "a string")) { struct mime_handler *handler; - arg += 3; - if (*arg == '=') { - arg++; - } else { - i++; - if (i >= argc) - die("--get expects a parameter"); - arg = argv[i]; - } - if (has_gotten) printf("\n"); has_gotten = 1; diff --git a/src/protocol/ftp/ftp-parser.c b/src/protocol/ftp/ftp-parser.c index 197466a59..b2b7fbf9c 100644 --- a/src/protocol/ftp/ftp-parser.c +++ b/src/protocol/ftp/ftp-parser.c @@ -13,21 +13,7 @@ #include "osdep/stat.h" #include "protocol/ftp/parse.h" - - -void die(const char *msg, ...) -{ - va_list args; - - if (msg) { - va_start(args, msg); - vfprintf(stderr, msg, args); - fputs("\n", stderr); - va_end(args); - } - - exit(!!NULL); -} +#include "util/test.h" int main(int argc, char *argv[]) @@ -45,17 +31,8 @@ main(int argc, char *argv[]) arg += 2; - if (!strncmp(arg, "response", 8)) { - arg += 8; - if (*arg == '=') { - arg++; - response = arg; - } else { - i++; - if (i >= argc) - die("--response expects a string"); - response = argv[i]; - } + if (get_test_opt(&arg, "response", &i, argc, argv, "a string")) { + response = arg; responselen = strlen(response); } else { diff --git a/src/protocol/test/.gitignore b/src/protocol/test/.gitignore index 6656e2d01..6b153e585 100644 --- a/src/protocol/test/.gitignore +++ b/src/protocol/test/.gitignore @@ -1 +1 @@ -uri-parser +uri-test diff --git a/src/protocol/test/stub.c b/src/protocol/test/stub.c index 4ed9b6724..8b66e34a1 100644 --- a/src/protocol/test/stub.c +++ b/src/protocol/test/stub.c @@ -13,6 +13,7 @@ #include "main/module.h" #include "protocol/user.h" #include "session/session.h" +#include "util/test.h" #define STUB_MODULE(name) \ struct module name = struct_module( \ @@ -38,21 +39,6 @@ STUB_MODULE(smb_protocol_module); STUB_MODULE(uri_rewrite_module); STUB_MODULE(user_protocol_module); -static void -die(const char *msg, ...) -{ - va_list args; - - if (msg) { - va_start(args, msg); - vfprintf(stderr, msg, args); - fputs("\n", stderr); - va_end(args); - } - - exit(!!NULL); -} - static void stub_called(const unsigned char *fun) { diff --git a/src/protocol/uri.c b/src/protocol/uri.c index 8a64aedea..5ea4fa856 100644 --- a/src/protocol/uri.c +++ b/src/protocol/uri.c @@ -785,6 +785,11 @@ normalize_uri(struct uri *uri, unsigned char *uristring) continue; } + } else if (is_uri_dir_sep(uri, src[1]) && + uri->protocol == PROTOCOL_FILE) { + /* // - ignore first '/'. */ + src += 1; + continue; } /* We don't want to access memory past the NUL char. */ diff --git a/src/terminal/screen.c b/src/terminal/screen.c index 3cbc7d272..4ac6dc69a 100644 --- a/src/terminal/screen.c +++ b/src/terminal/screen.c @@ -27,7 +27,8 @@ #include "util/string.h" -/* TODO: We must use termcap/terminfo if available! --pasky */ +/* TODO: We must use termcap/terminfo if available! --pasky + * Please mention ELinks bug 96 in commit logs. --KON */ /** Mapping from (enum ::border_char - 0xB0) to ASCII characters. */ const unsigned char frame_dumb[48] = " ||||++||++++++--|-+||++--|-+----++++++++ "; @@ -74,11 +75,11 @@ static const unsigned char frame_vt100_u[48] = { * 0x8D U+250C 'l' ACS_ULCORNER * 0x8E U+2514 'm' ACS_LLCORNER * 0x8F U+253C 'n' ACS_PLUS - * 0x90 - 'o' ACS_S1 - * 0x91 - 'p' ACS_S3 + * 0x90 U+23BA 'o' ACS_S1 + * 0x91 U+23BB 'p' ACS_S3 * 0x92 U+2500 'q' ACS_HLINE - * 0x93 - 'r' ACS_S7 - * 0x94 - 's' ACS_S9 + * 0x93 U+23BC 'r' ACS_S7 + * 0x94 U+23BD 's' ACS_S9 * 0x95 U+251C 't' ACS_LTEE * 0x96 U+2524 'u' ACS_RTEE * 0x97 U+2534 'v' ACS_BTEE diff --git a/src/terminal/window.h b/src/terminal/window.h index 1d47d2707..e94da64b9 100644 --- a/src/terminal/window.h +++ b/src/terminal/window.h @@ -47,8 +47,20 @@ struct window { /** The terminal (and screen) that hosts the window */ struct terminal *term; - /** Used for tabs focus detection. */ + /** For ::WINDOW_TAB, the position and size in the tab bar. + * Updated while the tab bar is being drawn, and read if the + * user clicks there with the mouse. */ int xpos, width; + + /** The position of something that has focus in the window. + * Any popup menus are drawn near this position. + * In tab windows, during ::NAVIGATE_CURSOR_ROUTING, this is + * also the position of the cursor that the user can move; + * there is no separate cursor position for each frame. + * In dialog boxes, this is typically the top left corner of + * the focused widget, while the cursor is somewhere within + * the widget. + * @see set_window_ptr, get_parent_ptr, set_cursor */ int x, y; /** For delayed tab resizing */ diff --git a/src/util/string.c b/src/util/string.c index c3c953fad..076c491b8 100644 --- a/src/util/string.c +++ b/src/util/string.c @@ -445,7 +445,6 @@ add_format_to_string(struct string *string, const unsigned char *format, ...) int newlength; int width; va_list ap; - va_list ap2; assertm(string && format, "[add_format_to_string]"); if_assert_failed { return NULL; } @@ -453,17 +452,16 @@ add_format_to_string(struct string *string, const unsigned char *format, ...) check_string_magic(string); va_start(ap, format); - VA_COPY(ap2, ap); - - width = vsnprintf(NULL, 0, format, ap2); + width = vsnprintf(NULL, 0, format, ap); + va_end(ap); if (width <= 0) return NULL; newlength = string->length + width; if (!realloc_string(string, newlength)) return NULL; + va_start(ap, format); vsnprintf(&string->source[string->length], width + 1, format, ap); - va_end(ap); string->length = newlength; diff --git a/src/util/test.h b/src/util/test.h new file mode 100644 index 000000000..152a943ed --- /dev/null +++ b/src/util/test.h @@ -0,0 +1,50 @@ +/* Test library */ + +#ifndef EL__UTIL_TEST_H +#define EL__UTIL_TEST_H + +#include + +static inline void +die(const char *msg, ...) +{ + va_list args; + + if (msg) { + va_start(args, msg); + vfprintf(stderr, msg, args); + fputs("\n", stderr); + va_end(args); + } + + exit(EXIT_FAILURE); +} + +static inline int +get_test_opt(char **argref, const char *name, int *argi, int argc, char *argv[], + const char *expect_msg) +{ + char *arg = *argref; + int namelen = strlen(name); + + if (strncmp(arg, name, namelen)) + return 0; + + arg += namelen; + if (*arg == '=') { + (*argref) = arg + 1; + + } else if (!*arg) { + (*argi)++; + if ((*argi) >= argc) + die("--%s expects %s", name, expect_msg); + (*argref) = argv[(*argi)]; + + } else { + return 0; + } + + return 1; +} + +#endif diff --git a/src/viewer/text/link.c b/src/viewer/text/link.c index ffc3819e5..b51697731 100644 --- a/src/viewer/text/link.c +++ b/src/viewer/text/link.c @@ -1078,6 +1078,11 @@ enter(struct session *ses, struct document_view *doc_view, int do_reload) return activate_link(ses, doc_view, link, do_reload); } +/** Get the link at the coordinates @a x and @a y, or NULL if none. + * The coordinates are relative to the document view; not to the + * terminal, nor to the document. So (0, 0) means whatever part of + * the document has been scrolled to the top left corner of the + * document view. */ struct link * get_link_at_coordinates(struct document_view *doc_view, int x, int y) { diff --git a/src/viewer/text/vs.h b/src/viewer/text/vs.h index 873434110..1de9e5839 100644 --- a/src/viewer/text/vs.h +++ b/src/viewer/text/vs.h @@ -28,6 +28,8 @@ struct view_state { * should never be negative. */ int y; + /** The index of the focused link in the document.links array, + * or -1 of none. */ int current_link; int old_current_link;