diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 140 |
1 files changed, 128 insertions, 12 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" @@ -119,6 +122,8 @@ static int searchKeyNum(void); #define help() fusage(stdout, 0) #define usage() fusage(stderr, 1) +int enable_inline_image; /* 1 == mlterm OSC 5379, 2 == sixel */ + static void fversion(FILE * f) { @@ -317,11 +322,7 @@ 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); @@ -382,6 +383,13 @@ make_optional_header_string(char *s) return hs; } +static void * +die_oom(size_t bytes) +{ + fprintf(stderr, "Out of memory: %lu bytes unavailable!\n", (unsigned long)bytes); + exit(1); +} + int main(int argc, char **argv, char **envp) { @@ -407,7 +415,11 @@ 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(); + GC_set_oom_fn(die_oom); #if defined(ENABLE_NLS) || (defined(USE_M17N) && defined(HAVE_LANGINFO_CODESET)) setlocale(LC_ALL, ""); #endif @@ -428,6 +440,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; @@ -672,6 +688,12 @@ main(int argc, char **argv, char **envp) } } #endif + else if (!strcmp("-ri", argv[i])) { + enable_inline_image = 1; + } + else if (!strcmp("-sixel", argv[i])) { + enable_inline_image = 2; + } else if (!strcmp("-num", argv[i])) showLineNum = TRUE; else if (!strcmp("-no-proxy", argv[i])) @@ -751,6 +773,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(); } @@ -839,6 +870,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); @@ -850,6 +905,7 @@ main(int argc, char **argv, char **envp) #endif #if GC_VERSION_MAJOR >= 7 && GC_VERSION_MINOR >= 2 + orig_GC_warn_proc = GC_get_warn_proc(); GC_set_warn_proc(wrap_GC_warn_proc); #else orig_GC_warn_proc = GC_set_warn_proc(wrap_GC_warn_proc); @@ -1269,6 +1325,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) { @@ -1289,15 +1351,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; + 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 (buf->href->anchors[i].slave) + if (in_order[i]->slave) continue; - parseURL2(buf->href->anchors[i].url, &pu, baseURL(buf)); + parseURL2(in_order[i]->url, &pu, baseURL(buf)); url = url_decode2(parsedURL2Str(&pu)->ptr, Currentbuf); - printf("[%d] %s\n", buf->href->anchors[i].hseq + 1, url); + printf("[%d] %s\n", in_order[i]->hseq + 1, url); } } } @@ -1586,6 +1653,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") { @@ -1864,6 +1943,10 @@ srch_nxtprv(int reverse) result = srchcore(SearchString, routine[reverse]); if (result & SR_FOUND) clear_mark(Currentbuf->currentLine); + else { + if (reverse == 0) + Currentbuf->pos -= 1; + } displayBuffer(Currentbuf, B_NORMAL); disp_srchresult(result, (reverse ? "Backward: " : "Forward: "), SearchString); @@ -3591,6 +3674,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") { @@ -5672,7 +5782,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) @@ -5739,7 +5849,7 @@ set_buffer_environ(Buffer *buf) set_environ("W3M_CURRENT_FORM", form2str((FormItemList *)a->url)); else set_environ("W3M_CURRENT_FORM", ""); - set_environ("W3M_CURRENT_LINE", Sprintf("%d", + set_environ("W3M_CURRENT_LINE", Sprintf("%ld", l->real_linenumber)->ptr); set_environ("W3M_CURRENT_COLUMN", Sprintf("%d", buf->currentColumn + @@ -5815,8 +5925,14 @@ deleteFiles() Firstbuf = buf; } } - while ((f = popText(fileToDelete)) != NULL) + while ((f = popText(fileToDelete)) != NULL) { unlink(f); + if (enable_inline_image == 2 && strcmp(f+strlen(f)-4, ".gif") == 0) { + Str firstframe = Strnew_charp(f); + Strcat_charp(firstframe, "-1"); + unlink(firstframe->ptr); + } + } } void |