int main(int argc, char **argv) { char c; const char *p, *browser = NULL, *definition = NULL; STRBUF *arg = strbuf_open(0); STRBUF *URL = strbuf_open(0); while (--argc > 0 && ((c = (++argv)[0][0]) == '-' || c == '+')) { if (argv[0][1] == '-') { if (!strcmp("--help", argv[0])) help(); else if (!strcmp("--version", argv[0])) show_version++; else if (!strcmp("--quiet", argv[0])) { qflag++; vflag = 0; } else if (!strcmp("--verbose", argv[0])) { vflag++; qflag = 0; } else usage(); continue; } if (c == '+') { linenumber = atoi(argv[0] + 1); continue; } p = argv[0] + 1; switch (*p) { case 'b': browser = argv[1]; --argc; ++argv; break; case 'd': definition = argv[1]; --argc; ++argv; break; case 'p': pflag++; break; case 'q': qflag++; setquiet(); break; case 'v': vflag++; setverbose(); break; default: usage(); } } if (show_version) version(progname, vflag); /* * Load aliases from .gozillarc. */ load_alias(); /* * Decide browser. */ if (!browser && getenv("BROWSER")) browser = getenv("BROWSER"); if (!browser && alias("BROWSER")) browser = alias("BROWSER"); /* * In DOS & Windows, let the file: association handle it. */ #if !(_WIN32 || __DJGPP__) if (!browser) browser = "mozilla"; #endif /* * Replace alias name. */ if (definition == NULL) { if (argc == 0) usage(); strbuf_puts(arg, argv[0]); /* * Replace with alias value. */ if ((p = alias(strbuf_value(arg))) != NULL) { strbuf_reset(arg); strbuf_puts(arg, p); } } /* * Get URL. */ { char *argument = strbuf_value(arg); /* * Protocol (xxx://...) */ if (!definition && isprotocol(argument)) { strbuf_puts(URL, argument); } else { const char *HTMLdir = NULL; if (setupdbpath(0) == 0) { cwd = get_cwd(); root = get_root(); dbpath = get_dbpath(); HTMLdir = locate_HTMLdir(); } /* * Make a URL of hypertext from the argument. */ if (HTMLdir != NULL) { if (definition) getdefinitionURL(definition, HTMLdir, URL); else getURL(argument, HTMLdir, URL); } /* * Make a file URL. */ else if (test("fr", argument) || test("dr", argument)) { char cwd[MAXPATHLEN]; char result[MAXPATHLEN]; if (getcwd(cwd, sizeof(cwd)) == NULL) die("cannot get current directory."); if (rel2abs(argument, cwd, result, sizeof(result)) == NULL) die("rel2abs failed."); strbuf_puts(URL, "file://"); strbuf_puts(URL, result); } else { die_with_code(1, "file '%s' not found.", argument); } } } if (pflag) { fprintf(stdout, "%s\n", strbuf_value(URL)); if (vflag) fprintf(stdout, "using browser '%s'.\n", browser); exit(0); } /* * Show URL's page. */ show_page_by_url(browser, strbuf_value(URL)); exit(0); }
int main(int argc, char **argv) { char c; const char *p, *browser = NULL, *definition = NULL; STRBUF *arg = strbuf_open(0); STRBUF *URL = strbuf_open(0); while (--argc > 0 && ((c = (++argv)[0][0]) == '-' || c == '+')) { if (argv[0][1] == '-') { if (!strcmp("--help", argv[0])) help(); else if (!strcmp("--version", argv[0])) show_version++; else if (!strcmp("--quiet", argv[0])) { qflag++; vflag = 0; } else if (!strcmp("--verbose", argv[0])) { vflag++; qflag = 0; } else usage(); continue; } if (c == '+') { linenumber = atoi(argv[0] + 1); continue; } p = argv[0] + 1; switch (*p) { case 'b': browser = argv[1]; --argc; ++argv; break; case 'd': definition = argv[1]; --argc; ++argv; break; case 'p': pflag++; break; case 'q': qflag++; setquiet(); break; case 'v': vflag++; break; default: usage(); } } if (show_version) version(progname, vflag); /* * Load aliases from .gozillarc. */ load_alias(); /* * Decide browser. */ if (!browser && getenv("BROWSER")) browser = getenv("BROWSER"); if (!browser && alias("BROWSER")) browser = alias("BROWSER"); if (!browser) browser = "mozilla"; /* * Replace alias name. */ if (definition == NULL) { if (argc == 0) usage(); strbuf_puts(arg, argv[0]); /* * Replace with alias value. */ if ((p = alias(strbuf_value(arg))) != NULL) { strbuf_reset(arg); strbuf_puts(arg, p); } } /* * Get URL. */ if (!definition && isprotocol(strbuf_value(arg))) { strbuf_puts(URL, strbuf_value(arg)); } else { getdbpath(cwd, root, dbpath, 0); if (definition) getdefinitionURL(definition, URL); else getURL(strbuf_value(arg), URL); } if (pflag) { fprintf(stdout, "%s\n", strbuf_value(URL)); if (vflag) fprintf(stdout, "using browser '%s'.\n", browser); exit(0); } /* * Show URL's page. */ show_page_by_url(browser, strbuf_value(URL)); exit(0); }