bug 764: Initialize the right member of union option_value
[elinks.git] / src / config / cmdline.c
blobba53a6804e52d73229e9bf6dfe3dbb9f9d3def31
1 /* Command line processing */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include <stdio.h>
8 #include <string.h>
9 #include <sys/types.h>
10 #ifdef HAVE_SYS_SOCKET_H
11 #include <sys/socket.h> /* OS/2 needs this after sys/types.h */
12 #endif
13 #include <sys/stat.h> /* OS/2 needs this after sys/types.h */
14 #ifdef HAVE_NETDB_H
15 #include <netdb.h>
16 #endif
18 /* We need to have it here. Stupid BSD. */
19 #ifdef HAVE_NETINET_IN_H
20 #include <netinet/in.h>
21 #endif
22 #ifdef HAVE_ARPA_INET_H
23 #include <arpa/inet.h>
24 #endif
26 #include "elinks.h"
28 #include "config/cmdline.h"
29 #include "config/conf.h"
30 #include "config/options.h"
31 #include "config/opttypes.h"
32 #include "intl/gettext/libintl.h"
33 #include "network/dns.h"
34 #include "protocol/uri.h"
35 #include "session/session.h"
36 #include "util/error.h"
37 #include "util/file.h"
38 #include "util/lists.h"
39 #include "util/memory.h"
40 #include "util/string.h"
43 /* Hack to handle URL extraction for -remote commands */
44 static unsigned char *remote_url;
46 static enum retval
47 parse_options_(int argc, unsigned char *argv[], struct option *opt,
48 LIST_OF(struct string_list_item) *url_list)
50 while (argc) {
51 argv++, argc--;
53 if (argv[-1][0] == '-' && argv[-1][1]) {
54 struct option *option;
55 unsigned char *argname = &argv[-1][1];
56 unsigned char *oname = stracpy(argname);
57 unsigned char *err;
59 if (!oname) continue;
61 /* Treat --foo same as -foo. */
62 if (argname[0] == '-') argname++;
64 option = get_opt_rec(opt, argname);
65 if (!option) option = get_opt_rec(opt, oname);
66 if (!option) {
67 unsigned char *pos;
69 oname++; /* the '-' */
70 /* Substitute '-' by '_'. This helps
71 * compatibility with that very wicked browser
72 * called 'lynx'. */
73 for (pos = strchr(oname, '_'); pos;
74 pos = strchr(pos, '_'))
75 *pos = '-';
76 option = get_opt_rec(opt, oname);
77 oname--;
80 mem_free(oname);
82 if (!option) goto unknown_option;
84 if (!option_types[option->type].cmdline)
85 goto unknown_option;
87 err = option_types[option->type].cmdline(option, &argv, &argc);
89 if (err) {
90 if (err[0]) {
91 usrerror(gettext("Cannot parse option %s: %s"), argv[-1], err);
93 return RET_SYNTAX;
96 /* XXX: Empty strings means all is well and have
97 * a cup of shut the fsck up. */
98 return RET_COMMAND;
100 } else if (remote_url) {
101 if (url_list) add_to_string_list(url_list, remote_url, -1);
102 mem_free(remote_url);
103 remote_url = NULL;
106 } else if (url_list) {
107 add_to_string_list(url_list, argv[-1], -1);
111 return RET_OK;
113 unknown_option:
114 usrerror(gettext("Unknown option %s"), argv[-1]);
115 return RET_SYNTAX;
118 enum retval
119 parse_options(int argc, unsigned char *argv[],
120 LIST_OF(struct string_list_item) *url_list)
122 return parse_options_(argc, argv, cmdline_options, url_list);
126 /**********************************************************************
127 Options handlers
128 **********************************************************************/
130 static unsigned char *
131 eval_cmd(struct option *o, unsigned char ***argv, int *argc)
133 if (*argc < 1) return gettext("Parameter expected");
135 (*argv)++; (*argc)--; /* Consume next argument */
137 parse_config_file(config_options, "-eval", *(*argv - 1), NULL, 0);
139 fflush(stdout);
141 return NULL;
144 static unsigned char *
145 forcehtml_cmd(struct option *o, unsigned char ***argv, int *argc)
147 safe_strncpy(get_opt_str("mime.default_type"), "text/html", MAX_STR_LEN);
148 return NULL;
151 static unsigned char *
152 lookup_cmd(struct option *o, unsigned char ***argv, int *argc)
154 struct sockaddr_storage *addrs = NULL;
155 int addrno, i;
157 if (!*argc) return gettext("Parameter expected");
158 if (*argc > 1) return gettext("Too many parameters");
160 (*argv)++; (*argc)--;
161 if (do_real_lookup(*(*argv - 1), &addrs, &addrno, 0) == DNS_ERROR) {
162 #ifdef HAVE_HERROR
163 herror(gettext("error"));
164 #else
165 usrerror(gettext("Host not found"));
166 #endif
167 return "";
170 for (i = 0; i < addrno; i++) {
171 #ifdef CONFIG_IPV6
172 struct sockaddr_in6 addr = *((struct sockaddr_in6 *) &(addrs)[i]);
173 unsigned char p[INET6_ADDRSTRLEN];
175 if (! inet_ntop(addr.sin6_family,
176 (addr.sin6_family == AF_INET6 ? (void *) &addr.sin6_addr
177 : (void *) &((struct sockaddr_in *) &addr)->sin_addr),
178 p, INET6_ADDRSTRLEN))
179 ERROR(gettext("Resolver error"));
180 else
181 printf("%s\n", p);
182 #else
183 struct sockaddr_in addr = *((struct sockaddr_in *) &(addrs)[i]);
184 unsigned char *p = (unsigned char *) &addr.sin_addr.s_addr;
186 printf("%d.%d.%d.%d\n", (int) p[0], (int) p[1],
187 (int) p[2], (int) p[3]);
188 #endif
191 mem_free_if(addrs);
193 fflush(stdout);
195 return "";
198 #define skipback_whitespace(start, S) \
199 while ((start) < (S) && isspace((S)[-1])) (S)--;
201 static unsigned char *
202 remote_cmd(struct option *o, unsigned char ***argv, int *argc)
204 struct {
205 unsigned char *name;
206 enum {
207 REMOTE_METHOD_OPENURL,
208 REMOTE_METHOD_PING,
209 REMOTE_METHOD_XFEDOCOMMAND,
210 REMOTE_METHOD_ADDBOOKMARK,
211 REMOTE_METHOD_INFOBOX,
212 REMOTE_METHOD_NOT_SUPPORTED,
213 } type;
214 } remote_methods[] = {
215 { "openURL", REMOTE_METHOD_OPENURL },
216 { "ping", REMOTE_METHOD_PING },
217 { "addBookmark", REMOTE_METHOD_ADDBOOKMARK },
218 { "infoBox", REMOTE_METHOD_INFOBOX },
219 { "xfeDoCommand", REMOTE_METHOD_XFEDOCOMMAND },
220 { NULL, REMOTE_METHOD_NOT_SUPPORTED },
222 unsigned char *command, *arg, *argend, *argstring;
223 int method, len = 0;
224 unsigned char *remote_argv[10];
225 int remote_argc;
227 if (*argc < 1) return gettext("Parameter expected");
229 command = *(*argv);
231 while (isasciialpha(command[len]))
232 len++;
234 /* Find the begining and end of the argument list. */
236 arg = command + len;
237 skip_space(arg);
239 argend = arg + strlen(arg);
240 skipback_whitespace(arg, argend);
241 if (argend > arg)
242 argend--;
244 /* Decide whether to use the "extended" --remote format where
245 * all URLs following should be opened in tabs. */
246 if (len == 0 || *arg != '(' || *argend != ')') {
247 /* Just open any passed URLs in new tabs */
248 remote_session_flags |= SES_REMOTE_NEW_TAB;
249 return NULL;
252 arg++;
254 arg = argstring = memacpy(arg, argend - arg);
255 if (!argstring)
256 return gettext("Out of memory");
258 remote_argc = 0;
259 do {
260 unsigned char *start, *end;
262 if (remote_argc > sizeof_array(remote_argv)) {
263 mem_free(argstring);
264 return gettext("Too many arguments");
267 /* Skip parenthesis, comma, and surrounding whitespace. */
268 skip_space(arg);
269 start = arg;
271 if (*start == '"') {
272 end = ++start;
273 while ((end = strchr(end, '"'))) {
274 /* Treat "" inside quoted arg as ". */
275 if (end[1] != '"')
276 break;
278 end += 2;
281 if (!end)
282 return gettext("Mismatched ending argument quoting");
284 arg = end + 1;
285 skip_space(arg);
286 if (*arg && *arg != ',')
287 return gettext("Garbage after quoted argument");
289 remote_argv[remote_argc++] = start;
290 *end = 0;
292 /* Unescape "" to ". */
293 for (end = start; *end; start++, end++) {
294 *start = *end;
295 if (*end == '"')
296 end++;
298 *start = 0;
300 } else {
301 end = strchr(start, ',');
302 if (!end) {
303 end = start + strlen(start);
304 arg = end;
305 } else {
306 arg = end + 1;
308 skipback_whitespace(start, end);
310 if (start != end)
311 remote_argv[remote_argc++] = start;
312 *end = 0;
315 if (*arg == ',')
316 arg++;
317 } while (*arg);
319 for (method = 0; remote_methods[method].name; method++) {
320 unsigned char *name = remote_methods[method].name;
322 if (!c_strlcasecmp(command, len, name, -1))
323 break;
326 switch (remote_methods[method].type) {
327 case REMOTE_METHOD_OPENURL:
328 if (remote_argc < 1) {
329 /* Prompt for a URL with a dialog box */
330 remote_session_flags |= SES_REMOTE_PROMPT_URL;
331 break;
334 if (remote_argc == 2) {
335 unsigned char *where = remote_argv[1];
337 if (strstr(where, "new-window")) {
338 remote_session_flags |= SES_REMOTE_NEW_WINDOW;
340 } else if (strstr(where, "new-tab")) {
341 remote_session_flags |= SES_REMOTE_NEW_TAB;
343 } else {
344 /* Bail out when getting unknown parameter */
345 /* TODO: new-screen */
346 break;
349 } else {
350 remote_session_flags |= SES_REMOTE_CURRENT_TAB;
353 remote_url = stracpy(remote_argv[0]);
354 break;
356 case REMOTE_METHOD_XFEDOCOMMAND:
357 if (remote_argc < 1)
358 break;
360 if (!c_strcasecmp(remote_argv[0], "openBrowser")) {
361 remote_session_flags = SES_REMOTE_NEW_WINDOW;
363 break;
365 case REMOTE_METHOD_PING:
366 remote_session_flags = SES_REMOTE_PING;
367 break;
369 case REMOTE_METHOD_ADDBOOKMARK:
370 if (remote_argc < 1)
371 break;
372 remote_url = stracpy(remote_argv[0]);
373 remote_session_flags = SES_REMOTE_ADD_BOOKMARK;
374 break;
376 case REMOTE_METHOD_INFOBOX:
377 if (remote_argc < 1)
378 break;
379 remote_url = stracpy(remote_argv[0]);
380 if (remote_url)
381 insert_in_string(&remote_url, 0, "about:", 6);
382 remote_session_flags = SES_REMOTE_INFO_BOX;
383 break;
385 case REMOTE_METHOD_NOT_SUPPORTED:
386 break;
389 mem_free(argstring);
391 /* If no flags was applied it can only mean we are dealing with
392 * unknown method. */
393 if (!remote_session_flags)
394 return gettext("Remote method not supported");
396 (*argv)++; (*argc)--; /* Consume next argument */
398 return NULL;
401 static unsigned char *
402 version_cmd(struct option *o, unsigned char ***argv, int *argc)
404 printf("%s\n", full_static_version);
405 fflush(stdout);
406 return "";
410 /* Below we handle help usage printing.
412 * We're trying to achieve several goals here:
414 * - Genericly define a function to print option trees iteratively.
415 * - Make output parsable for various doc tools (to make manpages).
416 * - Do some non generic fancy stuff like printing semi-aliased
417 * options (like: -?, -h and -help) on one line when printing
418 * short help. */
420 #define gettext_nonempty(x) (*(x) ? gettext(x) : (x))
422 static void print_option_desc(const unsigned char *desc)
424 struct string wrapped;
425 static const struct string indent = INIT_STRING(" ", 12);
427 if (init_string(&wrapped)
428 && wrap_option_desc(&wrapped, desc, &indent, 79 - indent.length)) {
429 /* struct string could in principle contain null
430 * characters, so don't use printf() or fputs(). */
431 fwrite(wrapped.source, 1, wrapped.length, stdout);
432 } else {
433 /* Write the error to stderr so it appears on the
434 * screen even if stdout is being parsed by a script
435 * that reformats it to HTML or such. */
436 fprintf(stderr, "%12s%s\n", "",
437 gettext("Out of memory formatting option documentation"));
440 /* done_string() is safe even if init_string() failed. */
441 done_string(&wrapped);
444 static void print_full_help_outer(struct option *tree, unsigned char *path);
446 static void
447 print_full_help_inner(struct option *tree, unsigned char *path,
448 int trees)
450 struct option *option;
451 unsigned char saved[MAX_STR_LEN];
452 unsigned char *savedpos = saved;
454 *savedpos = 0;
456 foreach (option, *tree->value.tree) {
457 enum option_type type = option->type;
458 unsigned char *help;
459 unsigned char *capt = option->capt;
460 unsigned char *desc = (option->desc && *option->desc)
461 ? (unsigned char *) gettext(option->desc)
462 : (unsigned char *) "N/A";
464 if (trees != (type == OPT_TREE))
465 continue;
467 /* Don't print deprecated aliases (if we don't walk command
468 * line options which use aliases for legitimate options). */
469 if ((type == OPT_ALIAS && tree != cmdline_options)
470 || (option->flags & OPT_HIDDEN))
471 continue;
473 if (!capt && !c_strncasecmp(option->name, "_template_", 10))
474 capt = (unsigned char *) N_("Template option folder");
476 if (!capt) {
477 int len = strlen(option->name);
478 int max = MAX_STR_LEN - (savedpos - saved);
480 safe_strncpy(savedpos, option->name, max);
481 safe_strncpy(savedpos + len, ", -", max - len);
482 savedpos += len + 3;
483 continue;
486 help = gettext_nonempty(option_types[option->type].help_str);
488 if (type != OPT_TREE)
489 printf(" %s%s%s %s ",
490 path, saved, option->name, help);
492 /* Print the 'title' of each option type. */
493 switch (type) {
494 case OPT_BOOL:
495 case OPT_INT:
496 case OPT_LONG:
497 printf(gettext("(default: %ld)"),
498 type == OPT_LONG
499 ? option->value.big_number
500 : (long) option->value.number);
501 break;
503 case OPT_STRING:
504 printf(gettext("(default: \"%s\")"),
505 option->value.string);
506 break;
508 case OPT_ALIAS:
509 printf(gettext("(alias for %s)"),
510 option->value.string);
511 break;
513 case OPT_CODEPAGE:
514 printf(gettext("(default: %s)"),
515 get_cp_name(option->value.number));
516 break;
518 case OPT_COLOR:
520 color_T color = option->value.color;
521 unsigned char hexcolor[8];
523 printf(gettext("(default: %s)"),
524 get_color_string(color, hexcolor));
525 break;
528 case OPT_COMMAND:
529 break;
531 case OPT_LANGUAGE:
532 #ifdef CONFIG_NLS
533 printf(gettext("(default: \"%s\")"),
534 language_to_name(option->value.number));
535 #endif
536 break;
538 case OPT_TREE:
540 int pathlen = strlen(path);
541 int namelen = strlen(option->name);
543 if (pathlen + namelen + 2 > MAX_STR_LEN)
544 continue;
546 /* Append option name to path */
547 if (pathlen > 0) {
548 memcpy(saved, path, pathlen);
549 savedpos = saved + pathlen;
550 } else {
551 savedpos = saved;
553 memcpy(savedpos, option->name, namelen + 1);
554 savedpos += namelen;
556 capt = gettext_nonempty(capt);
557 printf(" %s: (%s)", capt, saved);
558 break;
562 putchar('\n');
563 print_option_desc(desc);
564 putchar('\n');
566 if (option->type == OPT_TREE) {
567 memcpy(savedpos, ".", 2);
568 print_full_help_outer(option, saved);
571 savedpos = saved;
572 *savedpos = 0;
576 static void
577 print_full_help_outer(struct option *tree, unsigned char *path)
579 print_full_help_inner(tree, path, 0);
580 print_full_help_inner(tree, path, 1);
583 static void
584 print_short_help(void)
586 #define ALIGN_WIDTH 20
587 struct option *option;
588 struct string string = NULL_STRING;
589 struct string *saved = NULL;
590 unsigned char align[ALIGN_WIDTH];
592 /* Initialize @space used to align captions. */
593 memset(align, ' ', sizeof(align) - 1);
594 align[sizeof(align) - 1] = 0;
596 foreach (option, *cmdline_options->value.tree) {
597 unsigned char *capt;
598 unsigned char *help;
599 unsigned char *info = saved ? saved->source
600 : (unsigned char *) "";
601 int len = strlen(option->name);
603 /* Avoid printing compatibility options */
604 if (option->flags & OPT_HIDDEN)
605 continue;
607 /* When no caption is available the option name is 'stacked'
608 * and the caption is shared with next options that has one. */
609 if (!option->capt) {
610 if (!saved) {
611 if (!init_string(&string))
612 continue;
614 saved = &string;
617 add_to_string(saved, option->name);
618 add_to_string(saved, ", -");
619 continue;
622 capt = gettext_nonempty(option->capt);
623 help = gettext_nonempty(option_types[option->type].help_str);
625 /* When @help string is non empty align at least one space. */
626 len = ALIGN_WIDTH - len - strlen(help);
627 len -= (saved ? saved->length : 0);
628 len = (len < 0) ? !!(*help) : len;
630 align[len] = '\0';
631 printf(" -%s%s %s%s%s\n",
632 info, option->name, help, align, capt);
633 align[len] = ' ';
634 if (saved) {
635 done_string(saved);
636 saved = NULL;
639 #undef ALIGN_WIDTH
642 #undef gettext_nonempty
644 static unsigned char *
645 printhelp_cmd(struct option *option, unsigned char ***argv, int *argc)
647 unsigned char *lineend = strchr(full_static_version, '\n');
649 if (lineend) *lineend = '\0';
651 printf("%s\n\n", full_static_version);
653 if (!strcmp(option->name, "config-help")) {
654 printf("%s:\n", gettext("Configuration options"));
655 print_full_help_outer(config_options, "");
656 } else {
657 printf("%s\n\n%s:\n",
658 gettext("Usage: elinks [OPTION]... [URL]..."),
659 gettext("Options"));
660 if (!strcmp(option->name, "long-help")) {
661 print_full_help_outer(cmdline_options, "-");
662 } else {
663 print_short_help();
667 fflush(stdout);
668 return "";
671 static unsigned char *
672 redir_cmd(struct option *option, unsigned char ***argv, int *argc)
674 unsigned char *target;
676 /* I can't get any dirtier. --pasky */
678 if (!strcmp(option->name, "confdir")) {
679 target = "config-dir";
680 } else if (!strcmp(option->name, "conffile")) {
681 target = "config-file";
682 } else if (!strcmp(option->name, "stdin")) {
683 static int complained;
685 if (complained)
686 return NULL;
687 complained = 1;
689 /* Emulate bool option, possibly eating following 0/1. */
690 if ((*argv)[0]
691 && ((*argv)[0][0] == '0' || (*argv)[0][0] == '1')
692 && !(*argv)[0][1])
693 (*argv)++, (*argc)--;
694 fprintf(stderr, "Warning: Deprecated option -stdin used!\n");
695 fprintf(stderr, "ELinks now determines the -stdin option value automatically.\n");
696 fprintf(stderr, "In the future versions ELinks will report error when you will\n");
697 fprintf(stderr, "continue to use this option.\a\n");
698 return NULL;
700 } else {
701 return gettext("Internal consistency error");
704 option = get_opt_rec(cmdline_options, target);
705 assert(option);
706 option_types[option->type].cmdline(option, argv, argc);
707 return NULL;
710 static unsigned char *
711 printconfigdump_cmd(struct option *option, unsigned char ***argv, int *argc)
713 unsigned char *config_string;
715 /* Print all. */
716 get_opt_int("config.saving_style") = 2;
718 config_string = create_config_string("", "", config_options);
719 if (config_string) {
720 printf("%s", config_string);
721 mem_free(config_string);
724 fflush(stdout);
725 return "";
729 /**********************************************************************
730 Options values
731 **********************************************************************/
733 /* Keep options in alphabetical order. */
735 union option_info cmdline_options_info[] = {
736 /* [gettext_accelerator_context(IGNORE)] */
737 INIT_OPT_BOOL("", N_("Restrict to anonymous mode"),
738 "anonymous", 0, 0,
739 N_("Restricts ELinks so it can run on an anonymous account. "
740 "Local file browsing, downloads, and modification of options "
741 "will be disabled. Execution of viewers is allowed, but "
742 "entries in the association table can't be added or "
743 "modified.")),
745 INIT_OPT_BOOL("", N_("Autosubmit first form"),
746 "auto-submit", 0, 0,
747 N_("Automatically submit the first form in the given URLs.")),
749 INIT_OPT_INT("", N_("Clone internal session with given ID"),
750 "base-session", 0, 0, INT_MAX, 0,
751 N_("Used internally when opening ELinks instances in new "
752 "windows. The ID maps to information that will be used when "
753 "creating the new instance. You don't want to use it.")),
755 INIT_OPT_COMMAND("", NULL, "confdir", OPT_HIDDEN, redir_cmd, NULL),
757 INIT_OPT_STRING("", N_("Name of directory with configuration file"),
758 "config-dir", 0, "",
759 N_("Path of the directory ELinks will read and write its "
760 "config and runtime state files to instead of ~/.elinks. "
761 "If the path does not begin with a '/' it is assumed to be "
762 "relative to your HOME directory.")),
764 INIT_OPT_COMMAND("", N_("Print default configuration file to stdout"),
765 "config-dump", 0, printconfigdump_cmd,
766 N_("Print a configuration file with options set to the "
767 "built-in defaults to stdout.")),
769 INIT_OPT_COMMAND("", NULL, "conffile", OPT_HIDDEN, redir_cmd, NULL),
771 INIT_OPT_STRING("", N_("Name of configuration file"),
772 "config-file", 0, "elinks.conf",
773 N_("Name of the configuration file that all configuration "
774 "options will be read from and written to. It should be "
775 "relative to config-dir.")),
777 INIT_OPT_COMMAND("", N_("Print help for configuration options"),
778 "config-help", 0, printhelp_cmd,
779 N_("Print help for configuration options and exit.")),
781 INIT_OPT_CMDALIAS("", N_("MIME type assumed for unknown document types"),
782 "default-mime-type", 0, "mime.default_type",
783 N_("The default MIME type used for documents of unknown "
784 "type.")),
786 INIT_OPT_BOOL("", N_("Ignore user-defined keybindings"),
787 "default-keys", 0, 0,
788 N_("When set, all keybindings from configuration files will "
789 "be ignored. It forces use of default keybindings and will "
790 "reset user-defined ones on save.")),
792 INIT_OPT_BOOL("", N_("Print formatted versions of given URLs to stdout"),
793 "dump", 0, 0,
794 N_("Print formatted plain-text versions of given URLs to "
795 "stdout.")),
797 INIT_OPT_CMDALIAS("", N_("Codepage to use with -dump"),
798 "dump-charset", 0, "document.dump.codepage",
799 N_("Codepage used when formatting dump output.")),
801 INIT_OPT_CMDALIAS("", N_("Color mode used with -dump"),
802 "dump-color-mode", 0, "document.dump.color_mode",
803 N_("Color mode used with -dump.")),
805 INIT_OPT_CMDALIAS("", N_("Width of document formatted with -dump"),
806 "dump-width", 0, "document.dump.width",
807 N_("Width of the dump output.")),
809 INIT_OPT_COMMAND("", N_("Evaluate configuration file directive"),
810 "eval", 0, eval_cmd,
811 N_("Specify configuration file directives on the command-line "
812 "which will be evaluated after all configuration files has "
813 "been read. Example usage:\n"
814 "\t-eval 'set protocol.file.allow_special_files = 1'")),
816 /* lynx compatibility */
817 INIT_OPT_COMMAND("", N_("Interpret documents of unknown types as HTML"),
818 "force-html", 0, forcehtml_cmd,
819 N_("Makes ELinks assume documents of unknown types are HTML. "
820 "Useful when using ELinks as an external viewer from MUAs. "
821 "This is equivalent to -default-mime-type text/html.")),
823 /* XXX: -?, -h and -help share the same caption and should be kept in
824 * the current order for usage help printing to be ok */
825 INIT_OPT_COMMAND("", NULL, "?", 0, printhelp_cmd, NULL),
827 INIT_OPT_COMMAND("", NULL, "h", 0, printhelp_cmd, NULL),
829 INIT_OPT_COMMAND("", N_("Print usage help and exit"),
830 "help", 0, printhelp_cmd,
831 N_("Print usage help and exit.")),
833 INIT_OPT_BOOL("", N_("Only permit local connections"),
834 "localhost", 0, 0,
835 N_("Restricts ELinks to work offline and only connect to "
836 "servers with local addresses (ie. 127.0.0.1). No connections "
837 "to remote servers will be permitted.")),
839 INIT_OPT_COMMAND("", N_("Print detailed usage help and exit"),
840 "long-help", 0, printhelp_cmd,
841 N_("Print detailed usage help and exit.")),
843 INIT_OPT_COMMAND("", N_("Look up specified host"),
844 "lookup", 0, lookup_cmd,
845 N_("Look up specified host and print all DNS resolved IP "
846 "addresses.")),
848 INIT_OPT_BOOL("", N_("Run as separate instance"),
849 "no-connect", 0, 0,
850 N_("Run ELinks as a separate instance instead of connecting "
851 "to an existing instance. Note that normally no runtime state "
852 "files (bookmarks, history, etc.) are written to the disk "
853 "when this option is used. See also -touch-files.")),
855 INIT_OPT_BOOL("", N_("Disable use of files in ~/.elinks"),
856 "no-home", 0, 0,
857 N_("Disables creation and use of files in the user specific "
858 "home configuration directory (~/.elinks). It forces default "
859 "configuration values to be used and disables saving of "
860 "runtime state files.")),
862 INIT_OPT_CMDALIAS("", N_("Disable link numbering in dump output"),
863 "no-numbering", OPT_ALIAS_NEGATE, "document.dump.numbering",
864 N_("Prevents printing of link number in dump output.\n"
865 "\n"
866 "Note that this really affects only -dump, nothing else.")),
868 INIT_OPT_CMDALIAS("", N_("Disable printing of link references in dump output"),
869 "no-references", OPT_ALIAS_NEGATE, "document.dump.references",
870 N_("Prevents printing of references (URIs) of document links "
871 "in dump output.\n"
872 "\n"
873 "Note that this really affects only -dump, nothing else.")),
875 INIT_OPT_COMMAND("", N_("Control an already running ELinks"),
876 "remote", 0, remote_cmd,
877 N_("Control a remote ELinks instance by passing commands to "
878 "it. The option takes an additional argument containing the "
879 "method which should be invoked and any parameters that "
880 "should be passed to it. For ease of use, the additional "
881 "method argument can be omitted in which case any URL "
882 "arguments will be opened in new tabs in the remote "
883 "instance.\n"
884 "\n"
885 "Following is a list of the supported methods:\n"
886 "\tping() : look for a remote instance\n"
887 "\topenURL() : prompt URL in current tab\n"
888 "\topenURL(URL) : open URL in current tab\n"
889 "\topenURL(URL, new-tab) : open URL in new tab\n"
890 "\topenURL(URL, new-window) : open URL in new window\n"
891 "\taddBookmark(URL) : bookmark URL\n"
892 "\tinfoBox(text) : show text in a message box\n"
893 "\txfeDoCommand(openBrowser) : open new window")),
895 INIT_OPT_INT("", N_("Connect to session ring with given ID"),
896 "session-ring", 0, 0, INT_MAX, 0,
897 N_("ID of session ring this ELinks session should connect to. "
898 "ELinks works in so-called session rings, whereby all "
899 "instances of ELinks are interconnected and share state "
900 "(cache, bookmarks, cookies, and so on). By default, all "
901 "ELinks instances connect to session ring 0. You can change "
902 "that behaviour with this switch and form as many session "
903 "rings as you want. Obviously, if the session-ring with this "
904 "number doesn't exist yet, it's created and this ELinks "
905 "instance will become the master instance (that usually "
906 "doesn't matter for you as a user much).\n"
907 "\n"
908 "Note that you usually don't want to use this unless you're a "
909 "developer and you want to do some testing - if you want the "
910 "ELinks instances each running standalone, rather use the "
911 "-no-connect command-line option. Also note that normally no "
912 "runtime state files are written to the disk when this option "
913 "is used. See also -touch-files.")),
915 INIT_OPT_BOOL("", N_("Print the source of given URLs to stdout"),
916 "source", 0, 0,
917 N_("Print given URLs in source form to stdout.")),
919 INIT_OPT_COMMAND("", NULL, "stdin", OPT_HIDDEN, redir_cmd, NULL),
921 INIT_OPT_BOOL("", N_("Touch files in ~/.elinks when running with -no-connect/-session-ring"),
922 "touch-files", 0, 0,
923 N_("When enabled, runtime state files (bookmarks, history, "
924 "etc.) are written to disk, even when -no-connect or "
925 "-session-ring is used. The option has no effect if not used "
926 "in conjunction with any of these options.")),
928 INIT_OPT_INT("", N_("Verbose level"),
929 "verbose", 0, 0, VERBOSE_LEVELS - 1, VERBOSE_WARNINGS,
930 N_("The verbose level controls what messages are shown at "
931 "start up and while running:\n"
932 "\t0 means only show serious errors\n"
933 "\t1 means show serious errors and warnings\n"
934 "\t2 means show all messages")),
936 INIT_OPT_COMMAND("", N_("Print version information and exit"),
937 "version", 0, version_cmd,
938 N_("Print ELinks version information and exit.")),
940 NULL_OPTION_INFO,