diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 258 |
1 files changed, 210 insertions, 48 deletions
@@ -11,6 +11,9 @@ #include <sys/wait.h> #endif #include <time.h> +#if defined(__CYGWIN__) && defined(USE_BINMODE_STREAM) +#include <io.h> +#endif #include "terms.h" #include "myctype.h" #include "regex.h" @@ -200,10 +203,12 @@ fusage(FILE * f, int err) #ifdef USE_M17N fprintf(f, " -I charset document charset\n"); fprintf(f, " -O charset display/output charset\n"); +#if 0 /* use -O{s|j|e} instead */ fprintf(f, " -e EUC-JP\n"); fprintf(f, " -s Shift_JIS\n"); fprintf(f, " -j JIS\n"); #endif +#endif fprintf(f, " -B load bookmark\n"); fprintf(f, " -bookmark file specify bookmark file\n"); fprintf(f, " -T type specify content-type\n"); @@ -248,7 +253,11 @@ fusage(FILE * f, int err) #endif /* USE_COOKIE */ fprintf(f, " -graph use DEC special graphics for border of table and menu\n"); fprintf(f, " -no-graph use ACII character for border of table and menu\n"); +#if 1 /* pager requires -s */ + fprintf(f, " -s squeeze multiple blank lines\n"); +#else fprintf(f, " -S squeeze multiple blank lines\n"); +#endif fprintf(f, " -W toggle wrap search mode\n"); fprintf(f, " -X don't use termcap init/deinit\n"); fprintf(f, @@ -311,7 +320,11 @@ wrap_GC_warn_proc(char *msg, GC_word arg) lock = 0; } } +#if GC_VERSION_MAJOR >= 7 && GC_VERSION_MINOR >= 2 + else if (orig_GC_warn_proc = GC_get_warn_proc()) +#else else if (orig_GC_warn_proc) +#endif orig_GC_warn_proc(msg, arg); else fprintf(stderr, msg, (unsigned long)arg); @@ -397,6 +410,10 @@ main(int argc, char **argv, char **envp) wc_ces CodePage; #endif #endif +#if defined(DONT_CALL_GC_AFTER_FORK) && defined(USE_IMAGE) + char **getimage_args = NULL; +#endif /* defined(DONT_CALL_GC_AFTER_FORK) && defined(USE_IMAGE) */ + GC_INIT(); #if defined(ENABLE_NLS) || (defined(USE_M17N) && defined(HAVE_LANGINFO_CODESET)) setlocale(LC_ALL, ""); @@ -418,6 +435,10 @@ main(int argc, char **argv, char **envp) CurrentDir = currentdir(); CurrentPid = (int)getpid(); +#if defined(DONT_CALL_GC_AFTER_FORK) && defined(USE_IMAGE) + if (argv[0] && *argv[0]) + MyProgramName = argv[0]; +#endif /* defined(DONT_CALL_GC_AFTER_FORK) && defined(USE_IMAGE) */ BookmarkFile = NULL; config_file = NULL; @@ -530,12 +551,14 @@ main(int argc, char **argv, char **envp) PagerMax = atoi(argv[i]); } #ifdef USE_M17N +#if 0 /* use -O{s|j|e} instead */ else if (!strcmp("-s", argv[i])) DisplayCharset = WC_CES_SHIFT_JIS; else if (!strcmp("-j", argv[i])) DisplayCharset = WC_CES_ISO_2022_JP; else if (!strcmp("-e", argv[i])) DisplayCharset = WC_CES_EUC_JP; +#endif else if (!strncmp("-I", argv[i], 2)) { if (argv[i][2] != '\0') p = argv[i] + 2; @@ -703,7 +726,11 @@ main(int argc, char **argv, char **envp) accept_cookie = TRUE; } #endif /* USE_COOKIE */ +#if 1 /* pager requires -s */ + else if (!strcmp("-s", argv[i])) +#else else if (!strcmp("-S", argv[i])) +#endif squeezeBlankLine = TRUE; else if (!strcmp("-X", argv[i])) Do_not_use_ti_te = TRUE; @@ -735,6 +762,15 @@ main(int argc, char **argv, char **envp) else if (!strcmp("-reqlog",argv[i])) { w3m_reqlog=rcFile("request.log"); } +#if defined(DONT_CALL_GC_AFTER_FORK) && defined(USE_IMAGE) + else if (!strcmp("-$$getimage", argv[i])) { + ++i; + getimage_args = argv + i; + i += 4; + if (i > argc) + usage(); + } +#endif /* defined(DONT_CALL_GC_AFTER_FORK) && defined(USE_IMAGE) */ else { usage(); } @@ -823,6 +859,30 @@ main(int argc, char **argv, char **envp) if (w3m_backend) backend(); +#if defined(DONT_CALL_GC_AFTER_FORK) && defined(USE_IMAGE) + if (getimage_args) { + char *image_url = conv_from_system(getimage_args[0]); + char *base_url = conv_from_system(getimage_args[1]); + ParsedURL base_pu; + + parseURL2(base_url, &base_pu, NULL); + image_source = getimage_args[2]; + newbuf = loadGeneralFile(image_url, &base_pu, NULL, 0, NULL); + if (!newbuf || !newbuf->real_type || + strncasecmp(newbuf->real_type, "image/", 6)) + unlink(getimage_args[2]); +#if defined(HAVE_SYMLINK) && defined(HAVE_LSTAT) + symlink(getimage_args[2], getimage_args[3]); +#else + { + FILE *f = fopen(getimage_args[3], "w"); + if (f) + fclose(f); + } +#endif + w3m_exit(0); + } +#endif /* defined(DONT_CALL_GC_AFTER_FORK) && defined(USE_IMAGE) */ if (w3m_dump) mySignal(SIGINT, SIG_IGN); @@ -833,7 +893,11 @@ main(int argc, char **argv, char **envp) mySignal(SIGPIPE, SigPipe); #endif +#if GC_VERSION_MAJOR >= 7 && GC_VERSION_MINOR >= 2 + GC_set_warn_proc(wrap_GC_warn_proc); +#else orig_GC_warn_proc = GC_set_warn_proc(wrap_GC_warn_proc); +#endif err_msg = Strnew(); if (load_argc == 0) { /* no URL specified */ @@ -894,12 +958,17 @@ main(int argc, char **argv, char **envp) if (i >= 0) { SearchHeader = search_header; DefaultType = default_type; + char *url; + + url = load_argv[i]; + if (getURLScheme(&url) == SCM_MISSING && !ArgvIsURL) + url = file_to_url(load_argv[i]); + else + url = url_encode(conv_from_system(load_argv[i]), NULL, 0); if (w3m_dump == DUMP_HEAD) { request = New(FormList); request->method = FORM_METHOD_HEAD; - newbuf = - loadGeneralFile(load_argv[i], NULL, NO_REFERER, 0, - request); + newbuf = loadGeneralFile(url, NULL, NO_REFERER, 0, request); } else { if (post_file && i == 0) { @@ -928,9 +997,7 @@ main(int argc, char **argv, char **envp) else { request = NULL; } - newbuf = - loadGeneralFile(load_argv[i], NULL, NO_REFERER, 0, - request); + newbuf = loadGeneralFile(url, NULL, NO_REFERER, 0, request); } if (newbuf == NULL) { /* FIXME: gettextize? */ @@ -945,7 +1012,7 @@ main(int argc, char **argv, char **envp) break; case SCM_LOCAL: case SCM_LOCAL_CGI: - unshiftHist(LoadHist, conv_from_system(load_argv[i])); + unshiftHist(LoadHist, url); default: pushHashHist(URLHist, parsedURL2Str(&newbuf->currentURL)->ptr); break; @@ -1246,6 +1313,12 @@ dump_extra(Buffer *buf) #endif } +static int +cmp_anchor_hseq(const void *a, const void *b) +{ + return (*((const Anchor **) a))->hseq - (*((const Anchor **) b))->hseq; +} + static void do_dump(Buffer *buf) { @@ -1266,18 +1339,20 @@ do_dump(Buffer *buf) int i; saveBuffer(buf, stdout, FALSE); if (displayLinkNumber && buf->href) { + int nanchor = buf->href->nanchor; printf("\nReferences:\n\n"); - for (i = 0; i < buf->href->nanchor; i++) { - ParsedURL pu; - static Str s = NULL; - if (buf->href->anchors[i].slave) + Anchor **in_order = New_N(Anchor *, buf->href->nanchor); + for (i = 0; i < nanchor; i++) + in_order[i] = buf->href->anchors + i; + qsort(in_order, nanchor, sizeof(Anchor *), cmp_anchor_hseq); + for (i = 0; i < nanchor; i++) { + ParsedURL pu; + char *url; + if (in_order[i]->slave) continue; - parseURL2(buf->href->anchors[i].url, &pu, baseURL(buf)); - s = parsedURL2Str(&pu); - if (DecodeURL) - s = Strnew_charp(url_unquote_conv - (s->ptr, Currentbuf->document_charset)); - printf("[%d] %s\n", buf->href->anchors[i].hseq + 1, s->ptr); + parseURL2(in_order[i]->url, &pu, baseURL(buf)); + url = url_decode2(parsedURL2Str(&pu)->ptr, Currentbuf); + printf("[%d] %s\n", in_order[i]->hseq + 1, url); } } } @@ -1566,6 +1641,18 @@ DEFUN(pgBack, PREV_PAGE, "Move to previous page") * (Currentbuf->LINES - 1)), prec_num ? B_SCROLL : B_NORMAL); } +/* Move half page forward */ +DEFUN(hpgFore, NEXT_HALF_PAGE, "Scroll down half page") +{ + nscroll(searchKeyNum() * (Currentbuf->LINES / 2 - 1), B_NORMAL); +} + +/* Move half page backward */ +DEFUN(hpgBack, PREV_HALF_PAGE, "Scroll up half page") +{ + nscroll(-searchKeyNum() * (Currentbuf->LINES / 2 - 1), B_NORMAL); +} + /* 1 line up */ DEFUN(lup1, UP, "Scroll up one line") { @@ -2261,7 +2348,7 @@ DEFUN(movR1, MOVE_RIGHT1, static wc_uint32 getChar(char *p) { - return wc_any_to_ucs(wtf_parse1(&p)); + return wc_any_to_ucs(wtf_parse1((wc_uchar **)&p)); } static int @@ -2804,12 +2891,15 @@ loadLink(char *url, char *target, char *referer, FormList *request) union frameset_element *f_element = NULL; int flag = 0; ParsedURL *base, pu; + const int *no_referer_ptr; message(Sprintf("loading %s", url)->ptr, 0, 0); refresh(); + no_referer_ptr = query_SCONF_NO_REFERER_FROM(&Currentbuf->currentURL); base = baseURL(Currentbuf); - if (base == NULL || + if ((no_referer_ptr && *no_referer_ptr) || + base == NULL || base->scheme == SCM_LOCAL || base->scheme == SCM_LOCAL_CGI) referer = NO_REFERER; if (referer == NULL) @@ -3568,6 +3658,33 @@ DEFUN(lastA, LINK_END, "Go to the last link") displayBuffer(Currentbuf, B_NORMAL); } +/* go to the nth anchor */ +DEFUN(nthA, LINK_N, "Go to the nth link") +{ + HmarkerList *hl = Currentbuf->hmarklist; + BufferPoint *po; + Anchor *an; + + int n = searchKeyNum(); + if (n < 0 || n > hl->nmark) return; + + if (Currentbuf->firstLine == NULL) + return; + if (!hl || hl->nmark == 0) + return; + + po = hl->marks + n-1; + an = retrieveAnchor(Currentbuf->href, po->line, po->pos); + if (an == NULL) + an = retrieveAnchor(Currentbuf->formitem, po->line, po->pos); + if (an == NULL) return; + + gotoLine(Currentbuf, po->line); + Currentbuf->pos = po->pos; + arrangeCursor(Currentbuf); + displayBuffer(Currentbuf, B_NORMAL); +} + /* go to the next anchor */ DEFUN(nextA, NEXT_LINK, "Move to next link") { @@ -4055,6 +4172,7 @@ goURL0(char *prompt, int relative) char *url, *referer; ParsedURL p_url, *current; Buffer *cur_buf = Currentbuf; + const int *no_referer_ptr; url = searchKeyData(); if (url == NULL) { @@ -4064,11 +4182,8 @@ goURL0(char *prompt, int relative) current = baseURL(Currentbuf); if (current) { char *c_url = parsedURL2Str(current)->ptr; - if (DefaultURLString == DEFAULT_URL_CURRENT) { - url = c_url; - if (DecodeURL) - url = url_unquote_conv(url, 0); - } + if (DefaultURLString == DEFAULT_URL_CURRENT) + url = url_decode2(c_url, NULL); else pushHist(hist, c_url); } @@ -4077,11 +4192,8 @@ goURL0(char *prompt, int relative) char *a_url; parseURL2(a->url, &p_url, current); a_url = parsedURL2Str(&p_url)->ptr; - if (DefaultURLString == DEFAULT_URL_LINK) { - url = a_url; - if (DecodeURL) - url = url_unquote_conv(url, Currentbuf->document_charset); - } + if (DefaultURLString == DEFAULT_URL_LINK) + url = url_decode2(a_url, Currentbuf); else pushHist(hist, a_url); } @@ -4089,15 +4201,22 @@ goURL0(char *prompt, int relative) if (url != NULL) SKIP_BLANKS(url); } -#ifdef USE_M17N - if (url != NULL) { - if ((relative || *url == '#') && Currentbuf->document_charset) - url = wc_conv_strict(url, InnerCharset, - Currentbuf->document_charset)->ptr; + if (relative) { + no_referer_ptr = query_SCONF_NO_REFERER_FROM(&Currentbuf->currentURL); + current = baseURL(Currentbuf); + if ((no_referer_ptr && *no_referer_ptr) || + current == NULL || + current->scheme == SCM_LOCAL || current->scheme == SCM_LOCAL_CGI) + referer = NO_REFERER; else - url = conv_to_system(url); + referer = parsedURL2Str(&Currentbuf->currentURL)->ptr; + url = url_encode(url, current, Currentbuf->document_charset); + } + else { + current = NULL; + referer = NULL; + url = url_encode(url, NULL, 0); } -#endif if (url == NULL || *url == '\0') { displayBuffer(Currentbuf, B_FORCE_REDRAW); return; @@ -4106,14 +4225,6 @@ goURL0(char *prompt, int relative) gotoLabel(url + 1); return; } - if (relative) { - current = baseURL(Currentbuf); - referer = parsedURL2Str(&Currentbuf->currentURL)->ptr; - } - else { - current = NULL; - referer = NULL; - } parseURL2(url, &p_url, current); pushHashHist(URLHist, parsedURL2Str(&p_url)->ptr); cmd_loadURL(url, current, referer, NULL); @@ -4510,8 +4621,7 @@ _peekURL(int only_img) s = parsedURL2Str(&pu); } if (DecodeURL) - s = Strnew_charp(url_unquote_conv - (s->ptr, Currentbuf->document_charset)); + s = Strnew_charp(url_decode2(s->ptr, Currentbuf)); #ifdef USE_M17N s = checkType(s, &pp, NULL); p = NewAtom_N(Lineprop, s->length); @@ -4570,7 +4680,7 @@ DEFUN(curURL, PEEK, "Peek current URL") offset = 0; s = currentURL(); if (DecodeURL) - s = Strnew_charp(url_unquote_conv(s->ptr, 0)); + s = Strnew_charp(url_decode2(s->ptr, NULL)); #ifdef USE_M17N s = checkType(s, &pp, NULL); p = NewAtom_N(Lineprop, s->length); @@ -5398,6 +5508,58 @@ DEFUN(mouse, MOUSE, "mouse operation") process_mouse(btn, x, y); } +DEFUN(sgrmouse, SGRMOUSE, "SGR 1006 mouse operation") +{ + int btn = 0, x = 0, y = 0; + unsigned char c; + + do { + c = getch(); + if (IS_DIGIT(c)) + btn = btn * 10 + c - '0'; + else if (c == ';') + break; + else + return; + } while (1); + +#if defined(__CYGWIN__) && CYGWIN_VERSION_DLL_MAJOR < 1005 + if (cygwin_mouse_btn_swapped) { + if (btn == MOUSE_BTN2_DOWN) + btn = MOUSE_BTN3_DOWN; + else if (btn == MOUSE_BTN3_DOWN) + btn = MOUSE_BTN2_DOWN; + }; +#endif + + do { + c = getch(); + if (IS_DIGIT(c)) + x = x * 10 + c - '0'; + else if (c == ';') + break; + else + return; + } while (1); + + do { + c = getch(); + if (IS_DIGIT(c)) + y = y * 10 + c - '0'; + else if (c == 'M') + break; + else if (c == 'm') { + btn |= 3; + break; + } else + return; + } while (1); + + if (x < 0 || x >= COLS || y < 0 || y > LASTLINE) + return; + process_mouse(btn, x, y); +} + #ifdef USE_GPM int gpm_process_mouse(Gpm_Event * event, void *data) @@ -5604,7 +5766,7 @@ execdict(char *word) disp_message("Execution failed", TRUE); return; } - else { + else if (buf != NO_BUFFER) { buf->filename = w; buf->buffername = Sprintf("%s %s", DICTBUFFERNAME, word)->ptr; if (buf->type == NULL) |