[hackers] [st] Remove the cruft of the user to have to define the different font styles. || Christoph Lohmann

From: <hg_AT_suckless.org>
Date: Sun, 30 Sep 2012 20:25:41 +0200 (CEST)

changeset: 342:12d23b72ffb0
user: Christoph Lohmann <20h_AT_r-36.net>
date: Sun Sep 30 20:10:58 2012 +0200
files: st.c
description:
Remove the cruft of the user to have to define the different font styles.


diff -r 3dec6776a61b -r 12d23b72ffb0 st.c
--- a/st.c Sat Sep 29 11:23:34 2012 +0200
+++ b/st.c Sun Sep 30 20:10:58 2012 +0200
_AT_@ -336,6 +336,7 @@
 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,
_AT_@ -393,6 +394,44 @@
         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;
_AT_@ -2017,11 +2056,22 @@
 }
 
 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
_AT_@ -2037,7 +2087,7 @@
         xw.vis = XDefaultVisual(xw.dpy, xw.scr);
 
         /* font */
- initfonts(FONT, BOLDFONT, ITALICFONT, ITALICBOLDFONT);
+ initfonts(FONT);
 
         /* XXX: Assuming same size for bold font */
         xw.cw = dc.font.rbearing - dc.font.lbearing;
Received on Sun Sep 30 2012 - 20:25:41 CEST

This archive was generated by hypermail 2.3.0 : Sun Sep 30 2012 - 20:36:05 CEST