X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=st.c;h=59fb06c5df552d7286bff8429d1f4fc5413b172b;hb=5dfd5df4fe566beb17069e6390236854f6ace58f;hp=ab8540c26a871e585cfb4a8d05e9c9ed75770f88;hpb=d7b1e31eec9a87c666334006de25a7f8102c55a9;p=st.git diff --git a/st.c b/st.c index ab8540c..59fb06c 100644 --- a/st.c +++ b/st.c @@ -39,8 +39,8 @@ #define USAGE \ "st " VERSION " (c) 2010-2012 st engineers\n" \ - "usage: st [-t title] [-c class] [-g geometry]" \ - " [-w windowid] [-v] [-f file] [-e command...]\n" + "usage: st [-v] [-c class] [-f font] [-g geometry] [-o file]" \ + " [-t title] [-w windowid] [-e command ...]\n" /* XEMBED messages */ #define XEMBED_FOCUS_IN 4 @@ -336,6 +336,7 @@ static int isfullutf8(char *, int); static void *xmalloc(size_t); static void *xrealloc(void *, size_t); static void *xcalloc(size_t nmemb, size_t size); +static char *smstrcat(char *, ...); static void (*handler[LASTEvent])(XEvent *) = { [KeyPress] = kpress, @@ -364,11 +365,12 @@ static int cmdfd; static pid_t pid; static Selection sel; static int iofd = -1; -static char **opt_cmd = NULL; -static char *opt_io = NULL; +static char **opt_cmd = NULL; +static char *opt_io = NULL; static char *opt_title = NULL; static char *opt_embed = NULL; static char *opt_class = NULL; +static char *opt_font = NULL; void * xmalloc(size_t len) { @@ -393,6 +395,44 @@ xcalloc(size_t nmemb, size_t size) { return p; } +char * +smstrcat(char *src, ...) +{ + va_list fmtargs; + char *ret, *p, *v; + int len, slen, flen; + + len = slen = strlen(src); + + va_start(fmtargs, src); + for(;;) { + v = va_arg(fmtargs, char *); + if(v == NULL) + break; + len += strlen(v); + } + va_end(fmtargs); + + p = ret = xmalloc(len+1); + memmove(p, src, slen); + p += slen; + + va_start(fmtargs, src); + for(;;) { + v = va_arg(fmtargs, char *); + if(v == NULL) + break; + flen = strlen(v); + memmove(p, v, flen); + p += flen; + } + va_end(fmtargs); + + ret[len] = '\0'; + + return ret; +} + int utf8decode(char *s, long *u) { uchar c; @@ -1915,17 +1955,12 @@ xloadcols(void) { int i, r, g, b; XRenderColor xft_color = { .alpha = 0 }; - /* load default white color */ - if(!XftColorAllocName(xw.dpy, xw.vis, xw.cmap, colorname[256], &dc.xft_col[256])) - die("Could not allocate color '%s'\n", colorname[256]); - /* load colors [0-15] colors and [256-LEN(colorname)[ (config.h) */ for(i = 0; i < LEN(colorname); i++) { if(!colorname[i]) continue; if(!XftColorAllocName(xw.dpy, xw.vis, xw.cmap, colorname[i], &dc.xft_col[i])) { - dc.xft_col[i] = dc.xft_col[256]; - fprintf(stderr, "Could not allocate color '%s'\n", colorname[i]); + die("Could not allocate color '%s'\n", colorname[i]); } } @@ -1937,8 +1972,7 @@ xloadcols(void) { xft_color.green = g == 0 ? 0 : 0x3737 + 0x2828 * g; xft_color.blue = b == 0 ? 0 : 0x3737 + 0x2828 * b; if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &xft_color, &dc.xft_col[i])) { - dc.xft_col[i] = dc.xft_col[256]; - fprintf(stderr, "Could not allocate color %d\n", i); + die("Could not allocate color %d\n", i); } i++; } @@ -2023,11 +2057,22 @@ xinitfont(Font *f, char *fontstr) { } void -initfonts(char *fontstr, char *bfontstr, char *ifontstr, char *ibfontstr) { +initfonts(char *fontstr) { + char *fstr; + xinitfont(&dc.font, fontstr); - xinitfont(&dc.bfont, bfontstr); - xinitfont(&dc.ifont, ifontstr); - xinitfont(&dc.ibfont, ibfontstr); + + fstr = smstrcat(fontstr, ":weight=bold", NULL); + xinitfont(&dc.bfont, fstr); + free(fstr); + + fstr = smstrcat(fontstr, ":slant=italic,oblique", NULL); + xinitfont(&dc.ifont, fstr); + free(fstr); + + fstr = smstrcat(fontstr, ":weight=bold:slant=italic,oblique", NULL); + xinitfont(&dc.ibfont, fstr); + free(fstr); } void @@ -2043,7 +2088,7 @@ xinit(void) { xw.vis = XDefaultVisual(xw.dpy, xw.scr); /* font */ - initfonts(FONT, BOLDFONT, ITALICFONT, ITALICBOLDFONT); + initfonts((opt_font != NULL)? opt_font : FONT); /* XXX: Assuming same size for bold font */ xw.cw = dc.font.rbearing - dc.font.lbearing; @@ -2459,22 +2504,19 @@ main(int argc, char *argv[]) { for(i = 1; i < argc; i++) { switch(argv[i][0] != '-' || argv[i][2] ? -1 : argv[i][1]) { - case 't': - if(++i < argc) opt_title = argv[i]; - break; case 'c': - if(++i < argc) opt_class = argv[i]; - break; - case 'w': - if(++i < argc) opt_embed = argv[i]; - break; - case 'f': - if(++i < argc) opt_io = argv[i]; + if(++i < argc) + opt_class = argv[i]; break; case 'e': /* eat every remaining arguments */ - if(++i < argc) opt_cmd = &argv[i]; + if(++i < argc) + opt_cmd = &argv[i]; goto run; + case 'f': + if(++i < argc) + opt_font = argv[i]; + break; case 'g': if(++i >= argc) break; @@ -2496,9 +2538,21 @@ main(int argc, char *argv[]) { if(xw.fh != 0 && xw.fw != 0) xw.isfixed = True; break; + case 'o': + if(++i < argc) + opt_io = argv[i]; + break; + case 't': + if(++i < argc) + opt_title = argv[i]; + break; case 'v': default: die(USAGE); + case 'w': + if(++i < argc) + opt_embed = argv[i]; + break; } }