cleanup
d066975e
3 file(s) · +10 −30
| 66 | 66 | Bool fast = False; |
|
| 67 | 67 | int i; |
|
| 68 | 68 | ||
| 69 | - | progname = "dmenu"; |
|
| 70 | 69 | for(i = 1; i < argc; i++) |
|
| 71 | 70 | /* single flags */ |
|
| 72 | 71 | if(!strcmp(argv[i], "-v")) { |
|
| 383 | 382 | ||
| 384 | 383 | void |
|
| 385 | 384 | match(void) { |
|
| 386 | - | size_t len; |
|
| 385 | + | size_t len = strlen(text); |
|
| 387 | 386 | Item *item, *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend; |
|
| 388 | 387 | ||
| 389 | - | len = strlen(text); |
|
| 390 | 388 | matches = lexact = lprefix = lsubstr = matchend = exactend = prefixend = substrend = NULL; |
|
| 391 | 389 | for(item = items; item && item->text; item++) |
|
| 392 | 390 | if(!fstrncmp(text, item->text, len + 1)) |
|
| 424 | 422 | ||
| 425 | 423 | size_t |
|
| 426 | 424 | nextrune(int incr) { |
|
| 427 | - | size_t n, len; |
|
| 425 | + | size_t n, len = strlen(text); |
|
| 428 | 426 | ||
| 429 | - | len = strlen(text); |
|
| 430 | 427 | for(n = cursor + incr; n >= 0 && n < len && (text[n] & 0xc0) == 0x80; n += incr); |
|
| 431 | 428 | return n; |
|
| 432 | 429 | } |
|
| 29 | 29 | void |
|
| 30 | 30 | drawtext(DC *dc, const char *text, unsigned long col[ColLast]) { |
|
| 31 | 31 | char buf[256]; |
|
| 32 | - | size_t n, mn; |
|
| 32 | + | size_t mn, n = strlen(text); |
|
| 33 | 33 | ||
| 34 | 34 | /* shorten text if necessary */ |
|
| 35 | - | n = strlen(text); |
|
| 36 | 35 | for(mn = MIN(n, sizeof buf); textnw(dc, text, mn) > dc->w - dc->font.height/2; mn--) |
|
| 37 | 36 | if(mn == 0) |
|
| 38 | 37 | return; |
|
| 46 | 45 | ||
| 47 | 46 | void |
|
| 48 | 47 | drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]) { |
|
| 49 | - | int x, y; |
|
| 50 | - | ||
| 51 | - | x = dc->x + dc->font.height/2; |
|
| 52 | - | y = dc->y + dc->font.ascent+1; |
|
| 48 | + | int x = dc->x + dc->font.height/2; |
|
| 49 | + | int y = dc->y + dc->font.ascent+1; |
|
| 53 | 50 | ||
| 54 | 51 | XSetForeground(dc->dpy, dc->gc, FG(dc, col)); |
|
| 55 | 52 | if(dc->font.set) |
|
| 64 | 61 | eprintf(const char *fmt, ...) { |
|
| 65 | 62 | va_list ap; |
|
| 66 | 63 | ||
| 67 | - | fprintf(stderr, "%s: ", progname); |
|
| 68 | 64 | va_start(ap, fmt); |
|
| 69 | 65 | vfprintf(stderr, fmt, ap); |
|
| 70 | 66 | va_end(ap); |
|
| 104 | 100 | DC *dc; |
|
| 105 | 101 | ||
| 106 | 102 | if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) |
|
| 107 | - | weprintf("no locale support\n"); |
|
| 103 | + | fprintf(stderr, "no locale support\n"); |
|
| 108 | 104 | if(!(dc = calloc(1, sizeof *dc))) |
|
| 109 | 105 | eprintf("cannot malloc %u bytes:", sizeof *dc); |
|
| 110 | 106 | if(!(dc->dpy = XOpenDisplay(NULL))) |
|
| 119 | 115 | initfont(DC *dc, const char *fontstr) { |
|
| 120 | 116 | if(!loadfont(dc, fontstr ? fontstr : DEFFONT)) { |
|
| 121 | 117 | if(fontstr != NULL) |
|
| 122 | - | weprintf("cannot load font '%s'\n", fontstr); |
|
| 118 | + | fprintf(stderr, "cannot load font '%s'\n", fontstr); |
|
| 123 | 119 | if(fontstr == NULL || !loadfont(dc, DEFFONT)) |
|
| 124 | 120 | eprintf("cannot load font '%s'\n", DEFFONT); |
|
| 125 | 121 | } |
|
| 184 | 180 | textw(DC *dc, const char *text) { |
|
| 185 | 181 | return textnw(dc, text, strlen(text)) + dc->font.height; |
|
| 186 | 182 | } |
|
| 187 | - | ||
| 188 | - | void |
|
| 189 | - | weprintf(const char *fmt, ...) { |
|
| 190 | - | va_list ap; |
|
| 191 | - | ||
| 192 | - | fprintf(stderr, "%s: ", progname); |
|
| 193 | - | va_start(ap, fmt); |
|
| 194 | - | vfprintf(stderr, fmt, ap); |
|
| 195 | - | va_end(ap); |
|
| 196 | - | } |
|
| 20 | 20 | } font; |
|
| 21 | 21 | } DC; /* draw context */ |
|
| 22 | 22 | ||
| 23 | - | unsigned long getcolor(DC *dc, const char *colstr); |
|
| 24 | 23 | void drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color); |
|
| 25 | 24 | void drawtext(DC *dc, const char *text, unsigned long col[ColLast]); |
|
| 26 | 25 | void drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]); |
|
| 27 | - | void initfont(DC *dc, const char *fontstr); |
|
| 26 | + | void eprintf(const char *fmt, ...); |
|
| 28 | 27 | void freedc(DC *dc); |
|
| 28 | + | unsigned long getcolor(DC *dc, const char *colstr); |
|
| 29 | 29 | DC *initdc(void); |
|
| 30 | + | void initfont(DC *dc, const char *fontstr); |
|
| 30 | 31 | void mapdc(DC *dc, Window win, unsigned int w, unsigned int h); |
|
| 31 | 32 | void resizedc(DC *dc, unsigned int w, unsigned int h); |
|
| 32 | 33 | int textnw(DC *dc, const char *text, size_t len); |
|
| 33 | 34 | int textw(DC *dc, const char *text); |
|
| 34 | - | void eprintf(const char *fmt, ...); |
|
| 35 | - | void weprintf(const char *fmt, ...); |
|
| 36 | - | ||
| 37 | - | const char *progname; |