From c5cd2b5716b999c32b120b220846e57a3f67e260 Mon Sep 17 00:00:00 2001 From: bptato Date: Tue, 2 Feb 2021 15:06:53 +0100 Subject: sixel and osc5379 image display protocols can be chosen in options --- fm.h | 4 ++++ image.c | 51 +++++++++++++++++++++++++++------------------------ main.c | 8 ++++---- rc.c | 14 +++++++++++++- 4 files changed, 48 insertions(+), 29 deletions(-) diff --git a/fm.h b/fm.h index 0cd8235..a80e5f9 100644 --- a/fm.h +++ b/fm.h @@ -312,6 +312,10 @@ extern int REV_LB[]; #define EOL(l) (&(l)->ptr[(l)->length]) #define IS_EOL(p,l) ((p)==&(l)->ptr[(l)->length]) +#define INLINE_IMG_NONE 0 +#define INLINE_IMG_OSC5379 1 +#define INLINE_IMG_SIXEL 2 + /* * Types. */ diff --git a/image.c b/image.c index 91034ee..7fa3d43 100644 --- a/image.c +++ b/image.c @@ -224,31 +224,34 @@ drawImage() i->sx, i->sy, i->width, i->height, pixel_per_char_i, pixel_per_line_i); #endif - (enable_inline_image == 2 ? put_image_sixel : put_image_osc5379)( - ((enable_inline_image == 2 /* sixel */ || getenv("WINDOWID")) && + char *url = ((enable_inline_image == INLINE_IMG_SIXEL || getenv("WINDOWID")) && /* XXX I don't know why but sometimes i->cache->file doesn't exist. */ i->cache->touch && stat(i->cache->file,&st) == 0) ? - /* local */ i->cache->file : /* remote */ i->cache->url, - i->x / pixel_per_char_i, - i->y / pixel_per_line_i, - #if 1 - i->cache->a_width > 0 ? - (i->cache->width + i->x % pixel_per_char_i + pixel_per_char_i - 1) / - pixel_per_char_i : - #endif - 0, - - #if 1 - i->cache->a_height > 0 ? - (i->cache->height + i->y % pixel_per_line_i + pixel_per_line_i - 1) / - pixel_per_line_i : - #endif - 0, - i->sx / pixel_per_char_i, - i->sy / pixel_per_line_i, - (i->width + i->sx % pixel_per_char_i + pixel_per_char_i - 1) / pixel_per_char_i, - (i->height + i->sy % pixel_per_line_i + pixel_per_line_i - 1) / pixel_per_line_i, - n_terminal_image); + /* local */ i->cache->file : /* remote */ i->cache->url; + + int x = i->x / pixel_per_char_i; + int y = i->y / pixel_per_line_i; + + int w = i->cache->a_width > 0 ? ( + (i->cache->width + i->x % pixel_per_char_i + pixel_per_char_i - 1) / + pixel_per_char_i) : 0; + int h = i->cache->a_height > 0 ? ( + (i->cache->height + i->y % pixel_per_line_i + pixel_per_line_i - 1) / + pixel_per_line_i) : 0; + + int sx = i->sx / pixel_per_char_i; + int sy = i->sy / pixel_per_line_i; + + int sw = (i->width + i->sx % pixel_per_char_i + pixel_per_char_i - 1) / + pixel_per_char_i; + int sh = (i->height + i->sy % pixel_per_line_i + pixel_per_line_i - 1) / + pixel_per_line_i; + + if (enable_inline_image == INLINE_IMG_SIXEL) { + put_image_sixel(url, x, y, w, h, sx, sy, sw, sh, n_terminal_image); + } else { + put_image_osc5379(url, x, y, w, h, sx, sy, sw, sh, n_terminal_image); + } continue ; } @@ -599,7 +602,7 @@ getImage(Image * image, ParsedURL *current, int flag) cache->pid = 0; cache->index = 0; cache->loaded = IMG_FLAG_UNLOADED; - if (enable_inline_image == 1) { + if (enable_inline_image == INLINE_IMG_OSC5379) { if (image->width > 0 && image->width % pixel_per_char_i > 0) image->width += (pixel_per_char_i - image->width % pixel_per_char_i); diff --git a/main.c b/main.c index 7bcf898..bbdf3c3 100644 --- a/main.c +++ b/main.c @@ -123,7 +123,7 @@ static int searchKeyNum(void); #define help() fusage(stdout, 0) #define usage() fusage(stderr, 1) -int enable_inline_image; /* 1 == mlterm OSC 5379, 2 == sixel */ +int enable_inline_image; static void fversion(FILE * f) @@ -692,10 +692,10 @@ main(int argc, char **argv, char **envp) } #endif else if (!strcmp("-ri", argv[i])) { - enable_inline_image = 1; + enable_inline_image = INLINE_IMG_OSC5379; } else if (!strcmp("-sixel", argv[i])) { - enable_inline_image = 2; + enable_inline_image = INLINE_IMG_SIXEL; } else if (!strcmp("-num", argv[i])) showLineNum = TRUE; @@ -5961,7 +5961,7 @@ deleteFiles() } while ((f = popText(fileToDelete)) != NULL) { unlink(f); - if (enable_inline_image == 2 && strcmp(f+strlen(f)-4, ".gif") == 0) { + if (enable_inline_image == INLINE_IMG_SIXEL && strcmp(f+strlen(f)-4, ".gif") == 0) { Str firstframe = Strnew_charp(f); Strcat_charp(firstframe, "-1"); unlink(firstframe->ptr); diff --git a/rc.c b/rc.c index 423e008..656f83a 100644 --- a/rc.c +++ b/rc.c @@ -86,6 +86,7 @@ static int OptionEncode = FALSE; #define CMT_IMAGE_SCALE N_("Scale of image (%)") #define CMT_IMGDISPLAY N_("External command to display image") #define CMT_IMAGE_MAP_LIST N_("Use link list of image map") +#define CMT_INLINE_IMG_PROTOCOL N_("Inline image protocol") #endif #define CMT_MULTICOL N_("Display file names in multi-column format") #define CMT_ALT_ENTITY N_("Use ASCII equivalents to display entities") @@ -363,6 +364,15 @@ static struct sel_c graphic_char_str[] = { {0, NULL, NULL} }; +#ifdef USE_IMAGE +static struct sel_c inlineimgstr[] = { + {N_S(INLINE_IMG_NONE), N_("none")}, + {N_S(INLINE_IMG_OSC5379), N_("mlterm osc 5379")}, + {N_S(INLINE_IMG_SIXEL), N_("sixel")}, + {0, NULL, NULL} +}; +#endif /* USE_IMAGE */ + struct param_ptr params1[] = { {"tabstop", P_NZINT, PI_TEXT, (void *)&Tabstop, CMT_TABSTOP, NULL}, {"indent_incr", P_NZINT, PI_TEXT, (void *)&IndentIncr, CMT_INDENT_INCR, @@ -428,6 +438,8 @@ struct param_ptr params1[] = { NULL}, {"image_map_list", P_INT, PI_ONOFF, (void *)&image_map_list, CMT_IMAGE_MAP_LIST, NULL}, + {"inline_img_protocol", P_INT, PI_SEL_C, (void *)&enable_inline_image, + CMT_INLINE_IMG_PROTOCOL, (void *)inlineimgstr}, #endif {"fold_line", P_INT, PI_ONOFF, (void *)&FoldLine, CMT_FOLD_LINE, NULL}, {"show_lnum", P_INT, PI_ONOFF, (void *)&showLineNum, CMT_SHOW_NUM, NULL}, @@ -1223,7 +1235,7 @@ sync_with_option(void) init_migemo(); #endif #ifdef USE_IMAGE - if (fmInitialized && displayImage) + if (fmInitialized && (displayImage || enable_inline_image)) initImage(); #else displayImage = FALSE; /* XXX */ -- cgit v1.2.3 From f88e49826dc45f5852d678cb268fc595cd848b1b Mon Sep 17 00:00:00 2001 From: bptato Date: Tue, 2 Feb 2021 16:40:27 +0100 Subject: Avoid having external programs download images --- image.c | 41 +++++++++++++++++++++++++++-------------- rc.c | 2 +- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/image.c b/image.c index 7fa3d43..6fc79a6 100644 --- a/image.c +++ b/image.c @@ -214,20 +214,27 @@ drawImage() i = &terminal_image[j]; if (enable_inline_image) { - #if 0 - fprintf(stderr,"file %s x %d y %d w %d h %d sx %d sy %d sw %d sh %d (ppc %d ppl %d)\n", - ((enable_inline_image == 2 || getenv("WINDOWID")) && - i->cache->touch) ? i->cache->file : i->cache->url, - i->x, i->y, - i->cache->width > 0 ? i->cache->width : 0, - i->cache->height > 0 ? i->cache->height : 0, - i->sx, i->sy, i->width, i->height, - pixel_per_char_i, pixel_per_line_i); - #endif - char *url = ((enable_inline_image == INLINE_IMG_SIXEL || getenv("WINDOWID")) && - /* XXX I don't know why but sometimes i->cache->file doesn't exist. */ - i->cache->touch && stat(i->cache->file,&st) == 0) ? - /* local */ i->cache->file : /* remote */ i->cache->url; +#if 0 + if(stat(i->cache->file, &st)) { + fprintf(stderr,"file %s x %d y %d w %d h %d sx %d sy %d sw %d sh %d (ppc %d ppl %d)\n", + ((enable_inline_image == 2 || getenv("WINDOWID")) && + i->cache->touch) ? i->cache->file : i->cache->url, + i->x, i->y, + i->cache->width > 0 ? i->cache->width : 0, + i->cache->height > 0 ? i->cache->height : 0, + i->sx, i->sy, i->width, i->height, + pixel_per_char_i, pixel_per_line_i); + } +#endif + + /* + * So this shouldn't ever happen, but if it does then at least let's + * not have external programs fetch images from the Internet... + */ + if (!i->cache->touch || stat(i->cache->file,&st)) + return; + + char *url = i->cache->file; int x = i->x / pixel_per_char_i; int y = i->y / pixel_per_line_i; @@ -474,7 +481,10 @@ loadImage(Buffer *buf, int flag) */ cache->pid = 0; } + /*TODO I'm pretty sure this can be accessed again when the buffer isn't + * discarded. not sure though unlink(cache->touch); + */ image_cache[i] = NULL; } @@ -547,8 +557,11 @@ loadImage(Buffer *buf, int flag) setup_child(FALSE, 0, -1); image_source = cache->file; b = loadGeneralFile(cache->url, cache->current, NULL, 0, NULL); + /* TODO this apparently messes up stuff but why? */ +#if 0 if (!b || !b->real_type || strncasecmp(b->real_type, "image/", 6)) unlink(cache->file); +#endif #if defined(HAVE_SYMLINK) && defined(HAVE_LSTAT) symlink(cache->file, cache->touch); #else diff --git a/rc.c b/rc.c index 656f83a..d015d31 100644 --- a/rc.c +++ b/rc.c @@ -367,7 +367,7 @@ static struct sel_c graphic_char_str[] = { #ifdef USE_IMAGE static struct sel_c inlineimgstr[] = { {N_S(INLINE_IMG_NONE), N_("none")}, - {N_S(INLINE_IMG_OSC5379), N_("mlterm osc 5379")}, + {N_S(INLINE_IMG_OSC5379), N_("mlterm")}, {N_S(INLINE_IMG_SIXEL), N_("sixel")}, {0, NULL, NULL} }; -- cgit v1.2.3 From e4570e8b6e17382e1cc4984684f861524d5b02f4 Mon Sep 17 00:00:00 2001 From: bptato Date: Tue, 2 Feb 2021 22:14:46 +0100 Subject: Support iTerm2 graphics protocol, replace encodeB with base64_encode --- etc.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ file.c | 2 +- fm.h | 1 + image.c | 38 +++++++++++++++++--------------------- mimehead.c | 48 ------------------------------------------------ proto.h | 2 ++ rc.c | 1 + terms.c | 33 ++++++++++++++++++++++++++++++++- 8 files changed, 113 insertions(+), 71 deletions(-) diff --git a/etc.c b/etc.c index 801b098..aa8b61d 100644 --- a/etc.c +++ b/etc.c @@ -2004,3 +2004,62 @@ void (*mySignal(int signal_number, void (*action) (int))) (int) { return (signal(signal_number, action)); #endif } + +static char Base64Table[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + +const char * +base64_encode(const unsigned char *src, int len) +{ + unsigned char *w, *at; + const unsigned char *in, *endw; + int j, k; + + k = len; + if (k % 3) + k += 3 - (k % 3); + k = k / 3 * 4; + + if (k < len) + return ""; + + w = GC_MALLOC_ATOMIC(k); + w[k] = 0; + + at = w; + in = src; + + endw = src + len - 2; + + while (in < endw) { + j = *in++; + j = j << 8 | *in++; + j = j << 8 | *in++; + + *at++ = Base64Table[(j >> 18) & 0x3f]; + *at++ = Base64Table[(j >> 12) & 0x3f]; + *at++ = Base64Table[(j >> 6) & 0x3f]; + *at++ = Base64Table[j & 0x3f]; + } + + if (in - src - len) { + if (in - src - len == 1) { + j = *in++; + j = j << 8; + j = j << 8; + *at++ = Base64Table[(j >> 18) & 0x3f]; + *at++ = Base64Table[(j >> 12) & 0x3f]; + *at++ = '='; + *at++ = '='; + } else { + j = *in++; + j = j << 8 | *in++; + j = j << 8; + *at++ = Base64Table[(j >> 18) & 0x3f]; + *at++ = Base64Table[(j >> 12) & 0x3f]; + *at++ = Base64Table[(j >> 6) & 0x3f]; + *at++ = '='; + } + } + return w; +} diff --git a/file.c b/file.c index 1ab1c55..0e6a79a 100644 --- a/file.c +++ b/file.c @@ -1175,7 +1175,7 @@ AuthBasicCred(struct http_auth *ha, Str uname, Str pw, ParsedURL *pu, Str s = Strdup(uname); Strcat_char(s, ':'); Strcat(s, pw); - return Strnew_m_charp("Basic ", encodeB(s->ptr)->ptr, NULL); + return Strnew_m_charp("Basic ", base64_encode(s->ptr, s->length), NULL); } #ifdef USE_DIGEST_AUTH diff --git a/fm.h b/fm.h index a80e5f9..216cd53 100644 --- a/fm.h +++ b/fm.h @@ -315,6 +315,7 @@ extern int REV_LB[]; #define INLINE_IMG_NONE 0 #define INLINE_IMG_OSC5379 1 #define INLINE_IMG_SIXEL 2 +#define INLINE_IMG_ITERM2 3 /* * Types. diff --git a/image.c b/image.c index 6fc79a6..6e4e9b4 100644 --- a/image.c +++ b/image.c @@ -195,8 +195,9 @@ syncImage(void) n_terminal_image = 0; } -void put_image_osc5379(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh, int n_terminal_image); +void put_image_osc5379(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh); void put_image_sixel(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh, int n_terminal_image); +void put_image_iterm2(char *url, int x, int y, int w, int h); void drawImage() @@ -214,19 +215,6 @@ drawImage() i = &terminal_image[j]; if (enable_inline_image) { -#if 0 - if(stat(i->cache->file, &st)) { - fprintf(stderr,"file %s x %d y %d w %d h %d sx %d sy %d sw %d sh %d (ppc %d ppl %d)\n", - ((enable_inline_image == 2 || getenv("WINDOWID")) && - i->cache->touch) ? i->cache->file : i->cache->url, - i->x, i->y, - i->cache->width > 0 ? i->cache->width : 0, - i->cache->height > 0 ? i->cache->height : 0, - i->sx, i->sy, i->width, i->height, - pixel_per_char_i, pixel_per_line_i); - } -#endif - /* * So this shouldn't ever happen, but if it does then at least let's * not have external programs fetch images from the Internet... @@ -254,10 +242,20 @@ drawImage() int sh = (i->height + i->sy % pixel_per_line_i + pixel_per_line_i - 1) / pixel_per_line_i; +#if 0 + fprintf(stderr,"file %s x %d y %d w %d h %d sx %d sy %d sw %d sh %d (ppc %d ppl %d)\n", + i->cache->file, + x, y, w, h, sx, sy, sw, sh, + pixel_per_char_i, pixel_per_line_i); +#endif + + if (enable_inline_image == INLINE_IMG_SIXEL) { put_image_sixel(url, x, y, w, h, sx, sy, sw, sh, n_terminal_image); - } else { - put_image_osc5379(url, x, y, w, h, sx, sy, sw, sh, n_terminal_image); + } else if (enable_inline_image == INLINE_IMG_OSC5379) { + put_image_osc5379(url, x, y, w, h, sx, sy, sw, sh); + } else if (enable_inline_image == INLINE_IMG_ITERM2) { + put_image_iterm2(url, x, y, sw, sh); } continue ; @@ -481,8 +479,7 @@ loadImage(Buffer *buf, int flag) */ cache->pid = 0; } - /*TODO I'm pretty sure this can be accessed again when the buffer isn't - * discarded. not sure though + /*TODO make sure removing this didn't break anything unlink(cache->touch); */ image_cache[i] = NULL; @@ -557,11 +554,10 @@ loadImage(Buffer *buf, int flag) setup_child(FALSE, 0, -1); image_source = cache->file; b = loadGeneralFile(cache->url, cache->current, NULL, 0, NULL); - /* TODO this apparently messes up stuff but why? */ -#if 0 + /* TODO make sure removing this didn't break anything if (!b || !b->real_type || strncasecmp(b->real_type, "image/", 6)) unlink(cache->file); -#endif + */ #if defined(HAVE_SYMLINK) && defined(HAVE_LSTAT) symlink(cache->file, cache->touch); #else diff --git a/mimehead.c b/mimehead.c index d16270c..2479137 100644 --- a/mimehead.c +++ b/mimehead.c @@ -350,51 +350,3 @@ decodeMIME0(Str orgstr) return cnv; } -/* encoding */ - -static char Base64Table[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; - -Str -encodeB(char *a) -{ - unsigned char d[3]; - unsigned char c1, c2, c3, c4; - int i, n_pad; - Str w = Strnew(); - - while (1) { - if (*a == '\0') - break; - n_pad = 0; - d[1] = d[2] = 0; - for (i = 0; i < 3; i++) { - d[i] = a[i]; - if (a[i] == '\0') { - n_pad = 3 - i; - break; - } - } - c1 = d[0] >> 2; - c2 = (((d[0] << 4) | (d[1] >> 4)) & 0x3f); - if (n_pad == 2) { - c3 = c4 = 64; - } - else if (n_pad == 1) { - c3 = ((d[1] << 2) & 0x3f); - c4 = 64; - } - else { - c3 = (((d[1] << 2) | (d[2] >> 6)) & 0x3f); - c4 = (d[2] & 0x3f); - } - Strcat_char(w, Base64Table[c1]); - Strcat_char(w, Base64Table[c2]); - Strcat_char(w, Base64Table[c3]); - Strcat_char(w, Base64Table[c4]); - if (n_pad) - break; - a += 3; - } - return w; -} diff --git a/proto.h b/proto.h index 0c6483d..1f8e7d2 100644 --- a/proto.h +++ b/proto.h @@ -828,3 +828,5 @@ extern void dispVer(void); void srand48(long); long lrand48(void); #endif + +extern const char *base64_encode(const unsigned char *src, int len); diff --git a/rc.c b/rc.c index d015d31..b9a849f 100644 --- a/rc.c +++ b/rc.c @@ -369,6 +369,7 @@ static struct sel_c inlineimgstr[] = { {N_S(INLINE_IMG_NONE), N_("none")}, {N_S(INLINE_IMG_OSC5379), N_("mlterm")}, {N_S(INLINE_IMG_SIXEL), N_("sixel")}, + {N_S(INLINE_IMG_ITERM2), N_("iterm2")}, {0, NULL, NULL} }; #endif /* USE_IMAGE */ diff --git a/terms.c b/terms.c index a636ac0..966006a 100644 --- a/terms.c +++ b/terms.c @@ -469,7 +469,7 @@ writestr(char *s) #ifdef USE_IMAGE void -put_image_osc5379(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh, int n_terminal_image) +put_image_osc5379(char *url, int x, int y, int w, int h, int sx, int sy, int sw, int sh) { Str buf; char *size ; @@ -485,6 +485,37 @@ put_image_osc5379(char *url, int x, int y, int w, int h, int sx, int sy, int sw, MOVE(Currentbuf->cursorY,Currentbuf->cursorX); } + +void +put_image_iterm2(char *url, int x, int y, int w, int h) +{ + Str buf, filecontent; + const char *base64; + FILE *fp; + + fp = fopen(url, "r"); + if (!fp) + return; + filecontent = Strfgetall(fp); + + base64 = base64_encode(filecontent->ptr, filecontent->length); + if (!base64) + return; + + MOVE(y,x); + buf = Sprintf("\x1b]1337;" + "File=" + "name=%s;" + "size=%d;" + "width=%d;" + "height=%d;" + "preserveAspectRatio=0;" + "inline=1" + ":%s\a", url, filecontent->length, w, h, base64); + writestr(buf->ptr); + MOVE(Currentbuf->cursorY,Currentbuf->cursorX); +} + static void save_gif(const char *path, u_char *header, size_t header_size, u_char *body, size_t body_size) { -- cgit v1.2.3 From d277e80771a1a5cae19d21bfd895b4e16b3ca959 Mon Sep 17 00:00:00 2001 From: bptato Date: Tue, 2 Feb 2021 23:59:42 +0100 Subject: Some cleanup for base64_encode --- etc.c | 8 ++++---- file.c | 6 +++++- proto.h | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/etc.c b/etc.c index aa8b61d..7fabd03 100644 --- a/etc.c +++ b/etc.c @@ -2008,7 +2008,7 @@ void (*mySignal(int signal_number, void (*action) (int))) (int) { static char Base64Table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -const char * +char * base64_encode(const unsigned char *src, int len) { unsigned char *w, *at; @@ -2021,9 +2021,9 @@ base64_encode(const unsigned char *src, int len) k = k / 3 * 4; if (k < len) - return ""; + return NULL; - w = GC_MALLOC_ATOMIC(k); + w = GC_MALLOC_ATOMIC(k + 1); w[k] = 0; at = w; @@ -2061,5 +2061,5 @@ base64_encode(const unsigned char *src, int len) *at++ = '='; } } - return w; + return (char *)w; } diff --git a/file.c b/file.c index 0e6a79a..04d7c8f 100644 --- a/file.c +++ b/file.c @@ -1175,7 +1175,11 @@ AuthBasicCred(struct http_auth *ha, Str uname, Str pw, ParsedURL *pu, Str s = Strdup(uname); Strcat_char(s, ':'); Strcat(s, pw); - return Strnew_m_charp("Basic ", base64_encode(s->ptr, s->length), NULL); + char *base64 = base64_encode(s->ptr, s->length); + if (!base64) + return Strnew_charp("Basic "); + else + return Strnew_m_charp("Basic ", base64, NULL); } #ifdef USE_DIGEST_AUTH diff --git a/proto.h b/proto.h index 1f8e7d2..6aafbb4 100644 --- a/proto.h +++ b/proto.h @@ -829,4 +829,4 @@ void srand48(long); long lrand48(void); #endif -extern const char *base64_encode(const unsigned char *src, int len); +extern char *base64_encode(const unsigned char *src, int len); -- cgit v1.2.3 From 5cd5a1735af6a5c649c2d6699f8022e722fff170 Mon Sep 17 00:00:00 2001 From: bptato Date: Wed, 3 Feb 2021 10:41:20 +0100 Subject: base64_encode: fix input and output length types --- etc.c | 7 ++++--- proto.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/etc.c b/etc.c index 7fabd03..0c3a004 100644 --- a/etc.c +++ b/etc.c @@ -2009,18 +2009,19 @@ static char Base64Table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; char * -base64_encode(const unsigned char *src, int len) +base64_encode(const unsigned char *src, size_t len) { unsigned char *w, *at; const unsigned char *in, *endw; - int j, k; + int j; + size_t k; k = len; if (k % 3) k += 3 - (k % 3); k = k / 3 * 4; - if (k < len) + if (k + 1 < len) return NULL; w = GC_MALLOC_ATOMIC(k + 1); diff --git a/proto.h b/proto.h index 6aafbb4..899eec8 100644 --- a/proto.h +++ b/proto.h @@ -829,4 +829,4 @@ void srand48(long); long lrand48(void); #endif -extern char *base64_encode(const unsigned char *src, int len); +extern char *base64_encode(const unsigned char *src, size_t len); -- cgit v1.2.3 From 1a47d07d665dff4f24005c1f03e97610ecfa2713 Mon Sep 17 00:00:00 2001 From: bptato Date: Wed, 3 Feb 2021 13:03:52 +0100 Subject: Use GC_MALLOC_ATOMIC_IGNORE_OFF_PAGE for allocating memory for base64 encoding --- etc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc.c b/etc.c index 0c3a004..4e662e4 100644 --- a/etc.c +++ b/etc.c @@ -2024,7 +2024,7 @@ base64_encode(const unsigned char *src, size_t len) if (k + 1 < len) return NULL; - w = GC_MALLOC_ATOMIC(k + 1); + w = GC_MALLOC_ATOMIC_IGNORE_OFF_PAGE(k + 1); w[k] = 0; at = w; -- cgit v1.2.3 From 61b5182dbde04700951263529bca508a0a88aa46 Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 6 Feb 2021 00:18:29 +0100 Subject: Clarify inline image setting's wording --- rc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rc.c b/rc.c index b9a849f..a265fdc 100644 --- a/rc.c +++ b/rc.c @@ -86,7 +86,7 @@ static int OptionEncode = FALSE; #define CMT_IMAGE_SCALE N_("Scale of image (%)") #define CMT_IMGDISPLAY N_("External command to display image") #define CMT_IMAGE_MAP_LIST N_("Use link list of image map") -#define CMT_INLINE_IMG_PROTOCOL N_("Inline image protocol") +#define CMT_INLINE_IMG_PROTOCOL N_("Inline image display method") #endif #define CMT_MULTICOL N_("Display file names in multi-column format") #define CMT_ALT_ENTITY N_("Use ASCII equivalents to display entities") @@ -366,7 +366,7 @@ static struct sel_c graphic_char_str[] = { #ifdef USE_IMAGE static struct sel_c inlineimgstr[] = { - {N_S(INLINE_IMG_NONE), N_("none")}, + {N_S(INLINE_IMG_NONE), N_("external command")}, {N_S(INLINE_IMG_OSC5379), N_("mlterm")}, {N_S(INLINE_IMG_SIXEL), N_("sixel")}, {N_S(INLINE_IMG_ITERM2), N_("iterm2")}, @@ -435,12 +435,12 @@ struct param_ptr params1[] = { CMT_EXT_IMAGE_VIEWER, NULL}, {"image_scale", P_SCALE, PI_TEXT, (void *)&image_scale, CMT_IMAGE_SCALE, NULL}, + {"inline_img_protocol", P_INT, PI_SEL_C, (void *)&enable_inline_image, + CMT_INLINE_IMG_PROTOCOL, (void *)inlineimgstr}, {"imgdisplay", P_STRING, PI_TEXT, (void *)&Imgdisplay, CMT_IMGDISPLAY, NULL}, {"image_map_list", P_INT, PI_ONOFF, (void *)&image_map_list, CMT_IMAGE_MAP_LIST, NULL}, - {"inline_img_protocol", P_INT, PI_SEL_C, (void *)&enable_inline_image, - CMT_INLINE_IMG_PROTOCOL, (void *)inlineimgstr}, #endif {"fold_line", P_INT, PI_ONOFF, (void *)&FoldLine, CMT_FOLD_LINE, NULL}, {"show_lnum", P_INT, PI_ONOFF, (void *)&showLineNum, CMT_SHOW_NUM, NULL}, -- cgit v1.2.3