summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Marc Horowitz <marc@mit.edu>1989-11-15 18:48:25 +0000
committerGravatar Marc Horowitz <marc@mit.edu>1989-11-15 18:48:25 +0000
commite3c199c0b9fdefc41442f5d43c16acb9dc132377 (patch)
treef2a032bd0f773bb70f091c9bb52702ecf79e8f55
parent59297ccb0216c8092a73f0bfe82236ac75dd605f (diff)
final check-in: bug fixes & code clean-up
-rw-r--r--zwgc/X_driver.c61
-rw-r--r--zwgc/X_fonts.c9
-rw-r--r--zwgc/X_gram.c94
-rw-r--r--zwgc/X_gram.h3
-rw-r--r--zwgc/formatter.c36
-rw-r--r--zwgc/xcut.c5
-rw-r--r--zwgc/xshow.c160
7 files changed, 272 insertions, 96 deletions
diff --git a/zwgc/X_driver.c b/zwgc/X_driver.c
index fd42179..e4a33fe 100644
--- a/zwgc/X_driver.c
+++ b/zwgc/X_driver.c
@@ -13,7 +13,7 @@
*/
#if (!defined(lint) && !defined(SABER))
-static char rcsid_X_driver_c[] = "$Header$";
+static char rcsid_X_driver_c[] = "$Id$";
#endif
#include <zephyr/mit-copyright.h>
@@ -34,6 +34,7 @@ static char rcsid_X_driver_c[] = "$Header$";
#include "error.h"
#include "X_gram.h"
#include "xselect.h"
+#include "ulong_dictionary.h"
char *app_instance;
@@ -54,7 +55,7 @@ Display *dpy = NULL;
*/
#ifndef APPDEFDATABASE
-#define APPDEFDATABASE "/afs/athena.mit.edu/astaff/project/zephyr/src/zwgc/zwgc.dev/misc/zwgc_resources"
+#define APPDEFDATABASE "/usr/athena/lib/zephyr/zwgc_resources"
#endif
/*
@@ -157,6 +158,56 @@ int get_bool_resource(name, class, default_value)
return(result);
}
+static ulong_dictionary color_dict = NULL;
+
+/* Requires: name points to color name or hex string. name must be free'd
+ * eventually by the caller.
+ * Effects: returns unsigned long pixel value, or default if the
+ * color is not known by the server. If name is NULL, returns
+ * default;
+ *
+ * comment: caches return values from X server round trips. If name does
+ * not resolve, this fact is NOT cached, and will result in a round
+ * trip each time.
+ */
+
+unsigned long x_string_to_color(name,def)
+ char *name;
+ unsigned long def;
+{
+ ulong_dictionary_binding *binding;
+ int exists;
+ XColor xc;
+
+ if (name == NULL)
+ return(def);
+
+ binding = ulong_dictionary_Define(color_dict,name,&exists);
+
+ if (exists) {
+ return((unsigned long) binding->value);
+ } else {
+ if (XParseColor(dpy,DefaultColormapOfScreen(DefaultScreenOfDisplay(dpy)),
+ name,&xc)) {
+ if (XAllocColor(dpy,
+ DefaultColormapOfScreen(DefaultScreenOfDisplay(dpy)),
+ &xc)) {
+ binding->value = (ulong) xc.pixel;
+ return(xc.pixel);
+ } else {
+ ERROR2("Error in XAllocColor on \"%s\": using default color\n",
+ name);
+ }
+ } else {
+ ERROR2("Error in XParseColor on \"%s\": using default color\n",
+ name);
+ }
+ ulong_dictionary_Delete(color_dict,binding);
+ return(def);
+ }
+ /*NOTREACHED*/
+}
+
/*
* Standard X Toolkit command line options:
*/
@@ -244,7 +295,9 @@ int open_display_and_load_resources(pargc, argv)
extern void x_get_input();
-int X_driver_init(pargc, argv)
+/*ARGSUSED*/
+int X_driver_init(drivername, pargc, argv)
+ char *drivername;
int *pargc;
char **argv;
{
@@ -273,6 +326,8 @@ int X_driver_init(pargc, argv)
app_instance=string_Copy(temp?temp+1:argv[0]);
+ color_dict = ulong_dictionary_Create(37);
+
xshowinit();
x_gram_init(dpy);
xselInitAtoms(dpy);
diff --git a/zwgc/X_fonts.c b/zwgc/X_fonts.c
index 96427cd..c1fc804 100644
--- a/zwgc/X_fonts.c
+++ b/zwgc/X_fonts.c
@@ -13,7 +13,7 @@
*/
#if (!defined(lint) && !defined(SABER))
-static char rcsid_X_fonts_c[] = "$Header$";
+static char rcsid_X_fonts_c[] = "$Id$";
#endif
#include <zephyr/mit-copyright.h>
@@ -61,8 +61,9 @@ static char *get_family(style,substyle)
char *family;
desc=string_Concat("style.",style);
- desc=string_Concat2(desc,".fontfamily.");
+ desc=string_Concat2(desc,".substyle.");
desc=string_Concat2(desc,substyle);
+ desc=string_Concat2(desc,".fontfamily");
if (!family_dict)
family_dict = pointer_dictionary_Create(37);
@@ -72,7 +73,7 @@ static char *get_family(style,substyle)
free(desc);
return((string) binding->value);
} else {
-#define STYLE_CLASS "Style.Style1.Style2.Style3.Fontfamily.Substyle"
+#define STYLE_CLASS "StyleKey.Style1.Style2.Style3.SubstyleKey.Substyle.FontfamilyKey"
family=get_string_resource(desc,STYLE_CLASS);
#undef STYLE_CLASS
free(desc);
@@ -108,7 +109,7 @@ static char *get_specific_fontname(family,size,face)
free(desc);
return((string) binding->value);
} else {
-#define FAMILY_CLASS "Fontfamily.FontfamilyName.Size.Face"
+#define FAMILY_CLASS "FontfamilyKey.Fontfamily.Size.Face"
fontname=get_string_resource(desc,FAMILY_CLASS);
free(desc);
if (fontname==NULL)
diff --git a/zwgc/X_gram.c b/zwgc/X_gram.c
index 3b5d806..46e6af6 100644
--- a/zwgc/X_gram.c
+++ b/zwgc/X_gram.c
@@ -32,6 +32,8 @@ static char rcsid_X_gram_c[] = "$Id$";
extern XContext desc_context;
extern char *app_instance;
+extern unsigned long x_string_to_color();
+extern char *getenv();
/*
*
@@ -39,7 +41,9 @@ extern char *app_instance;
int internal_border_width = 2;
-static int reverse_video = 0;
+unsigned long default_fgcolor;
+unsigned long default_bgcolor;
+unsigned long default_bordercolor;
static int border_width = 1;
static int cursor_code = XC_sailboat;
static char *title_name,*icon_name;
@@ -91,8 +95,24 @@ void x_gram_init(dpy)
char *temp;
XSizeHints sizehints;
XWMHints wmhints;
+ unsigned long rv,tc;
+
+ default_fgcolor = BlackPixelOfScreen(DefaultScreenOfDisplay(dpy));
+ default_bgcolor = WhitePixelOfScreen(DefaultScreenOfDisplay(dpy));
+ rv = get_bool_resource("reverseVideo", "ReverseVideo", 0);
+ if (rv) {
+ tc = default_fgcolor;
+ default_fgcolor = default_bgcolor;
+ default_bgcolor = tc;
+ }
+ if (temp = get_string_resource("foreground","Foreground"))
+ default_fgcolor = x_string_to_color(temp,default_fgcolor);
+ if (temp = get_string_resource("background","Background"))
+ default_bgcolor = x_string_to_color(temp,default_bgcolor);
+ default_bordercolor = default_fgcolor;
+ if (temp = get_string_resource("borderColor","BorderColor"))
+ default_bordercolor = x_string_to_color(temp,default_bordercolor);
- reverse_video = get_bool_resource("reverseVideo", "ReverseVideo", 0);
reverse_stack = get_bool_resource("reverseStack", "ReverseStack", 0);
temp = get_string_resource("borderWidth", "BorderWidth");
@@ -129,8 +149,7 @@ void x_gram_init(dpy)
classhint.res_class="Zwgc";
group_leader=XCreateSimpleWindow(dpy,DefaultRootWindow(dpy),0,0,100,100,0,
- BlackPixel(dpy,DefaultScreen(dpy)),
- WhitePixel(dpy,DefaultScreen(dpy)));
+ default_bordercolor,default_bgcolor);
sizehints.x = 0;
sizehints.y = 0;
sizehints.width = 100;
@@ -145,19 +164,18 @@ void x_gram_init(dpy)
&wmhints,0);
}
-void x_gram_create(dpy, gram, xalign, yalign, xpos, ypos, xsize, ysize)
+void x_gram_create(dpy, gram, xalign, yalign, xpos, ypos, xsize, ysize,
+ beepcount)
Display *dpy;
x_gram *gram;
int xalign, yalign;
int xpos, ypos;
int xsize, ysize;
+ int beepcount;
{
- int i;
Window w;
XSizeHints sizehints;
XWMHints wmhints;
- int foreground_color = BlackPixel(dpy, DefaultScreen(dpy));
- int background_color = WhitePixel(dpy, DefaultScreen(dpy));
/*
* Adjust xpos, ypos based on the alignments xalign, yalign and the sizes:
@@ -177,21 +195,11 @@ void x_gram_create(dpy, gram, xalign, yalign, xpos, ypos, xsize, ysize)
- 2*border_width)>>1 + ypos;
/*
- * Deal with reverse video:
- */
- if (reverse_video) {
- int temp;
- temp = foreground_color;
- foreground_color = background_color;
- background_color = temp;
- }
-
- /*
* Create the window:
*/
w = XCreateSimpleWindow(dpy,DefaultRootWindow(dpy),xpos,ypos,xsize,
- ysize,border_width,foreground_color,
- background_color);
+ ysize,border_width,default_bordercolor,
+ gram->bgcolor);
gram->w=w;
XDefineCursor(dpy, w, cursor);
@@ -221,6 +229,9 @@ void x_gram_create(dpy, gram, xalign, yalign, xpos, ypos, xsize, ysize)
XMapWindow(dpy, w);
+ while (beepcount--)
+ XBell(dpy, 0);
+
if (reverse_stack) {
if (bottom_gram) {
XWindowChanges winchanges;
@@ -269,41 +280,29 @@ void x_gram_draw(dpy, w, gram, region)
x_gram *gram;
Region region;
{
- int i,bcsize,ecsize;
+ int i;
GC gc;
XGCValues gcvals;
xblock *xb;
XTextItem text;
- unsigned long fg,bg;
- int startblock,endblock,startchar,endchar,startpixel,endpixel;
+ int startblock,endblock,startpixel,endpixel;
#define SetFG(fg) \
gcvals.foreground=fg; \
XChangeGC(dpy,gc,GCForeground,&gcvals)
- if (!reverse_video) {
- fg = BlackPixel(dpy, DefaultScreen(dpy));
- bg = WhitePixel(dpy, DefaultScreen(dpy));
- } else {
- fg = WhitePixel(dpy, DefaultScreen(dpy));
- bg = BlackPixel(dpy, DefaultScreen(dpy));
- }
gc = XCreateGC(dpy, w, 0, &gcvals);
XSetRegion(dpy,gc,region);
- if (markgram == gram) {
+ if ((markgram == gram) && (STARTBLOCK != -1) && (ENDBLOCK != -1)) {
if (xmarkSecond() == XMARK_END_BOUND) {
startblock=STARTBLOCK;
endblock=ENDBLOCK;
- startchar=STARTCHAR;
- endchar=ENDCHAR;
startpixel=STARTPIXEL;
endpixel=ENDPIXEL;
} else {
startblock=ENDBLOCK;
endblock=STARTBLOCK;
- startchar=ENDCHAR;
- endchar=STARTCHAR;
startpixel=ENDPIXEL;
endpixel=STARTPIXEL;
}
@@ -312,43 +311,44 @@ void x_gram_draw(dpy, w, gram, region)
endblock = -1;
}
- SetFG(bg);
for (i=0,xb=gram->blocks ; i<gram->numblocks ; i++,xb++) {
if (XRectInRegion(region,xb->x1,xb->y1,xb->x2-xb->x1,
xb->y2-xb->y1) != RectangleOut) {
if (i==startblock) {
if (i==endblock) {
+ SetFG(gram->bgcolor);
XFillRectangle(dpy,w,gc,xb->x1,xb->y1,startpixel,
(xb->y2-xb->y1));
- SetFG(fg);
+ SetFG(xb->fgcolor);
XFillRectangle(dpy,w,gc,xb->x1+startpixel,xb->y1,
(endpixel-startpixel),(xb->y2-xb->y1));
- SetFG(bg);
+ SetFG(gram->bgcolor);
XFillRectangle(dpy,w,gc,xb->x1+endpixel,xb->y1,
(xb->x2-xb->x1-endpixel),(xb->y2-xb->y1));
} else {
+ SetFG(gram->bgcolor);
XFillRectangle(dpy,w,gc,xb->x1,xb->y1,startpixel,
(xb->y2-xb->y1));
- SetFG(fg);
+ SetFG(xb->fgcolor);
XFillRectangle(dpy,w,gc,xb->x1+startpixel,xb->y1,
(xb->x2-xb->x1-startpixel),(xb->y2-xb->y1));
}
} else if (i==endblock) {
+ SetFG(xb->fgcolor);
XFillRectangle(dpy,w,gc,xb->x1,xb->y1,endpixel,
(xb->y2-xb->y1));
- SetFG(bg);
+ SetFG(gram->bgcolor);
XFillRectangle(dpy,w,gc,xb->x1+endpixel,xb->y1,
(xb->x2-xb->x1-endpixel),(xb->y2-xb->y1));
} else {
+ if ((startblock < i) && (i < endblock)) {
+ SetFG(xb->fgcolor);
+ } else {
+ SetFG(gram->bgcolor);
+ }
XFillRectangle(dpy,w,gc,xb->x1,xb->y1,(xb->x2-xb->x1),
(xb->y2-xb->y1));
}
- } else {
- if (i==startblock) {
- if (i != endblock) SetFG(fg);
- } else if (i==endblock) {
- SetFG(bg);
- }
}
}
@@ -358,7 +358,7 @@ void x_gram_draw(dpy, w, gram, region)
for (i=0,xb=gram->blocks ; i<gram->numblocks ; i++,xb++) {
if (XRectInRegion(region,xb->x1,xb->y1,xb->x2-xb->x1,
xb->y2-xb->y1) != RectangleOut) {
- SetFG(fg^bg);
+ SetFG(gram->bgcolor^xb->fgcolor);
text.chars=gram->text+xb->strindex;
text.nchars=xb->strlen;
text.delta=0;
diff --git a/zwgc/X_gram.h b/zwgc/X_gram.h
index 97388d0..362de73 100644
--- a/zwgc/X_gram.h
+++ b/zwgc/X_gram.h
@@ -52,7 +52,10 @@ typedef struct _xmode {
int italic;
int size;
int align;
+ int expcolor;
+ unsigned long color;
char *substyle;
+ char *font;
} xmode;
typedef struct _xlinedesc {
diff --git a/zwgc/formatter.c b/zwgc/formatter.c
index c4aea52..ce7dfad 100644
--- a/zwgc/formatter.c
+++ b/zwgc/formatter.c
@@ -315,43 +315,41 @@ int length_of_block(str)
* or \0 if there are no open environments.
*/
-int close_bracket(str,terminator)
+char close_bracket(str)
string str;
- char terminator;
{
int len=0,temp;
- char ch;
+ char ch,close;
- while (str[len]) {
- if (temp=pure_text_length(str+len,terminator)) {
- if (str[len+temp])
- len+=temp;
- else
- return(terminator);
- } else if (str[len+temp] == terminator) {
- len++;
- terminator=0;
+ while (*str) {
+ if (temp=pure_text_length(str,0)) {
+ str+=temp;
} else {
- temp=env_length(str+len+1);
- if (ch=close_bracket(str+len+temp+2,otherside(str[len+temp+1])))
+ temp = env_length(str+1)+2;
+ close = otherside(str[temp-1]);
+ if (ch=close_bracket(str+temp))
return(ch);
+ temp = length_of_block(str);
+ if (str[temp-1] != close)
+ return(close);
else
- len+=length_of_block(str+len);
+ str+=temp;
}
}
-
- return(str[len]?'\0':terminator);
+ return('\0');
}
string protect(str)
string str;
{
string temp,temp2,temp3;
- int len,len2,ch;
+ int len,len2;
+ char ch;
/* verbatim all top-level strings */
temp=string_Copy("");
+ len = 0;
while(*str) {
if ((len=length_of_block(str)) == -1) {
temp2=string_CreateFromData(str,len=pure_text_length(str,0));
@@ -369,7 +367,7 @@ string protect(str)
len2=string_Length(temp);
len=len2-len;
temp2=temp+len;
- while (ch=close_bracket(temp2,0)>0) {
+ while (ch=close_bracket(temp2)>0) {
temp=(char *) realloc(temp,++len2);
temp[len2-2]=ch;
temp[len2-1]='\0';
diff --git a/zwgc/xcut.c b/zwgc/xcut.c
index 8f2d46f..ce698b6 100644
--- a/zwgc/xcut.c
+++ b/zwgc/xcut.c
@@ -50,6 +50,7 @@ char *getSelectedText()
return(selected_text);
}
+#ifdef notdef
static string x_gram_to_string(gram)
x_gram *gram;
{
@@ -74,6 +75,7 @@ static string x_gram_to_string(gram)
text_so_far = string_Concat2(text_so_far, "\n");
return(text_so_far);
}
+#endif
/*
*
@@ -176,7 +178,8 @@ void xcut(dpy,event,desc_context)
case ButtonPress:
if ( (event->xbutton.state)&ShiftMask ) {
if (event->xbutton.button==Button1) {
- xunmark(dpy,selecting_in,NULL,desc_context);
+ if (selecting_in)
+ xunmark(dpy,selecting_in,NULL,desc_context);
if (selected_text) free(selected_text);
selected_text = NULL;
if (! xselGetOwnership(dpy,w,event->xbutton.time)) {
diff --git a/zwgc/xshow.c b/zwgc/xshow.c
index 5597975..87a0266 100644
--- a/zwgc/xshow.c
+++ b/zwgc/xshow.c
@@ -13,7 +13,7 @@
*/
#if (!defined(lint) && !defined(SABER))
-static char rcsid_xshow_c[] = "$Header$";
+static char rcsid_xshow_c[] = "$Id$";
#endif
#include <zephyr/mit-copyright.h>
@@ -33,22 +33,64 @@ static char rcsid_xshow_c[] = "$Header$";
#define max(a,b) ((a)>(b)?(a):(b))
XContext desc_context;
-static pointer_dictionary geometry_dict;
+static pointer_dictionary geometry_dict = NULL;
+static pointer_dictionary bgcolor_dict = NULL;
+static pointer_dictionary colorname_dict = NULL;
extern int internal_border_width;
+extern unsigned long default_bgcolor;
+extern unsigned long default_fgcolor;
+extern unsigned long x_string_to_color();
xshowinit()
{
desc_context = XUniqueContext();
}
+/*ARGSUSED*/
+char *mode_to_colorname(dpy,style,mode)
+ Display *dpy;
+ char *style;
+ xmode *mode;
+{
+ char *desc;
+ int exists;
+ char *name;
+ pointer_dictionary_binding *binding;
+
+ desc = string_Concat("style.",style);
+ desc = string_Concat2(desc,"style");
+ desc = string_Concat2(desc,".substyle.");
+ desc = string_Concat2(desc,mode->substyle);
+ desc = string_Concat2(desc,".foreground");
+
+ if (!colorname_dict)
+ colorname_dict = pointer_dictionary_Create(37);
+ binding = pointer_dictionary_Define(colorname_dict,desc,&exists);
+
+ if (exists) {
+ free(desc);
+ return((char *) binding->value);
+ } else {
+#define COLNAME_CLASS "StyleKey.Style1.Style2.Style3.SubstyleKey.Substyle.ForegroundKey"
+ name=get_string_resource(desc,COLNAME_CLASS);
+#undef COLNAME_CLASS
+ free(desc);
+ if (name==NULL)
+ pointer_dictionary_Delete(colorname_dict,binding);
+ else
+ binding->value=(pointer) name;
+ return(name); /* If resource returns NULL, return NULL also */
+ }
+}
+
static char *xres_get_geometry(style)
char *style;
{
char *desc;
pointer_dictionary_binding *binding;
int exists;
- char *family;
+ char *spec;
desc=string_Concat("style.",style);
desc=string_Concat2(desc,".geometry");
@@ -61,19 +103,51 @@ static char *xres_get_geometry(style)
free(desc);
return((string) binding->value);
} else {
-#define STYLE_CLASS "Style.Style1.Style2.Style3.Geometry"
- family=get_string_resource(desc,STYLE_CLASS);
-#undef STYLE_CLASS
+#define GEOM_CLASS "StyleKey.Style1.Style2.Style3.GeometryKey"
+ spec=get_string_resource(desc,GEOM_CLASS);
+#undef GEOM_CLASS
free(desc);
- if (family==NULL)
+ if (spec==NULL)
pointer_dictionary_Delete(geometry_dict,binding);
else
- binding->value=(pointer) family;
- return(family); /* If resource returns NULL, return NULL also */
+ binding->value=(pointer) spec;
+ return(spec); /* If resource returns NULL, return NULL also */
+ }
+}
+
+static char *xres_get_bgcolor(style)
+ char *style;
+{
+ char *desc;
+ pointer_dictionary_binding *binding;
+ int exists;
+ char *color;
+
+ desc=string_Concat("style.",style);
+ desc=string_Concat2(desc,".background");
+
+ if (!bgcolor_dict)
+ bgcolor_dict = pointer_dictionary_Create(37);
+ binding = pointer_dictionary_Define(bgcolor_dict,desc,&exists);
+
+ if (exists) {
+ free(desc);
+ return((string) binding->value);
+ } else {
+#define BG_CLASS "StyleKey.Style1.Style2.Style3.BackgroundKey"
+ color=get_string_resource(desc,BG_CLASS);
+#undef BG_CLASS
+ free(desc);
+ if (color==NULL)
+ pointer_dictionary_Delete(bgcolor_dict,binding);
+ else
+ binding->value=(pointer) color;
+ return(color); /* If resource returns NULL, return NULL also */
}
}
-void fixup_and_draw(dpy, style, auxblocks, blocks, num, lines, numlines)
+void fixup_and_draw(dpy, style, auxblocks, blocks, num, lines, numlines,
+ beepcount)
Display *dpy;
char *style;
xblock *blocks;
@@ -81,6 +155,7 @@ void fixup_and_draw(dpy, style, auxblocks, blocks, num, lines, numlines)
int num;
xlinedesc *lines;
int numlines;
+ int beepcount;
{
int gram_xalign = 1;
int gram_yalign = 1;
@@ -98,7 +173,7 @@ void fixup_and_draw(dpy, style, auxblocks, blocks, num, lines, numlines)
int lofs, cofs, rofs;
int ystart,yend;
- char *geometry,xpos[10], ypos[10], xfrom, yfrom;
+ char *bgstr, *geometry, xpos[10], ypos[10], xfrom, yfrom;
gram = (x_gram *)malloc(sizeof(x_gram));
@@ -266,6 +341,15 @@ void fixup_and_draw(dpy, style, auxblocks, blocks, num, lines, numlines)
gram_ypos = atoi(ypos);
if (yfrom=='-')
gram_yalign *= -1;
+
+ if ((bgstr = var_get_variable("X_background")),(bgstr[0]=='\0'))
+ if ((bgstr = xres_get_bgcolor(style))==NULL)
+ if ((bgstr = var_get_variable("default_X_background")),
+ (bgstr[0]=='\0'))
+ gram->bgcolor = default_bgcolor;
+ if (bgstr && bgstr[0])
+ gram->bgcolor = x_string_to_color(bgstr,default_bgcolor);
+
gram_xsize = maxwidth+(internal_border_width<<1);
gram_ysize = yofs+internal_border_width;
@@ -273,12 +357,12 @@ void fixup_and_draw(dpy, style, auxblocks, blocks, num, lines, numlines)
gram->blocks = blocks;
x_gram_create(dpy, gram, gram_xalign, gram_yalign, gram_xpos,
- gram_ypos, gram_xsize, gram_ysize);
+ gram_ypos, gram_xsize, gram_ysize, beepcount);
}
#define MODE_TO_FONT(dpy,style,mode) \
- get_font((dpy),(style),(mode)->substyle,(mode)->size, \
- (mode)->bold+(mode)->italic*2)
+ get_font((dpy),(style),(mode)->font?(mode)->font:(mode)->substyle, \
+ (mode)->size, (mode)->bold+(mode)->italic*2)
void xshow(dpy, desc, numstr, numnl)
Display *dpy;
desctype *desc;
@@ -294,6 +378,7 @@ void xshow(dpy, desc, numstr, numnl)
int nextblock=0;
int line=0,linestart=0;
char *style;
+ int beepcount = 0;
lines = (xlinedesc *)malloc(sizeof(xlinedesc)*(numnl+1));
@@ -304,7 +389,9 @@ void xshow(dpy, desc, numstr, numnl)
curmode.italic = 0;
curmode.size = MEDIUM_SIZE;
curmode.align = LEFTALIGN;
+ curmode.expcolor = 0;
curmode.substyle = string_Copy("default");
+ curmode.font = NULL;
style = var_get_variable("style");
if (style[0] == '\0') {
@@ -319,6 +406,8 @@ void xshow(dpy, desc, numstr, numnl)
case DT_ENV:
xmode_stack_push(modes, curmode);
curmode.substyle = string_Copy(curmode.substyle);
+ if (curmode.font)
+ curmode.font = string_Copy(curmode.font);
#define envmatch(string,length) ((desc->len==(length)) && (strncasecmp(desc->str,(string),(length))==0))
@@ -341,10 +430,9 @@ void xshow(dpy, desc, numstr, numnl)
curmode.align = CENTERALIGN;
else if (envmatch("right",5)||envmatch("r",1))
curmode.align = RIGHTALIGN;
- else if (envmatch("default",7)) {
- free(curmode.substyle);
- curmode.substyle = string_Copy("default");
- } else if (envmatch("font",4)) {
+ else if (envmatch("beep",4))
+ beepcount++;
+ else if (envmatch("font",4)) {
/* lookahead needed. desc->next->str should be the
font name, and desc->next->next->code should be
a DT_END*/
@@ -353,14 +441,35 @@ void xshow(dpy, desc, numstr, numnl)
(desc->next->code == DT_STR) &&
(desc->next->next->code==DT_END)) {
curmode.size=SPECIAL_SIZE; /* This is an @font() */
- free(curmode.substyle);
- curmode.substyle=string_CreateFromData(desc->next->str,
- desc->next->len);
+ curmode.font=string_CreateFromData(desc->next->str,
+ desc->next->len);
+ /* skip over the rest of the @font */
+ desc=desc->next->next;
+ }
+ } else if (envmatch("color",5)) {
+ /* lookahead needed. desc->next->str should be the
+ font name, and desc->next->next->code should be
+ a DT_END*/
+ if ((desc->next) &&
+ (desc->next->next) &&
+ (desc->next->code == DT_STR) &&
+ (desc->next->next->code==DT_END)) {
+ char *colorname;
+
+ colorname=string_CreateFromData(desc->next->str,
+ desc->next->len);
+ curmode.color = x_string_to_color(colorname,default_fgcolor);
+ free(colorname);
+ curmode.expcolor = 1;
/* skip over the rest of the @font */
desc=desc->next->next;
}
} else if (desc->len > 0) { /* avoid @{...} */
free(curmode.substyle);
+ if (curmode.font) {
+ free(curmode.font);
+ curmode.font = NULL;
+ }
curmode.substyle = string_CreateFromData(desc->str, desc->len);
}
break;
@@ -370,6 +479,12 @@ void xshow(dpy, desc, numstr, numnl)
auxblocks[nextblock].font = MODE_TO_FONT(dpy,style,&curmode);
auxblocks[nextblock].str = desc->str;
auxblocks[nextblock].len = desc->len;
+ if (curmode.expcolor)
+ blocks[nextblock].fgcolor = curmode.color;
+ else
+ blocks[nextblock].fgcolor =
+ x_string_to_color(mode_to_colorname(dpy,style,&curmode),
+ default_fgcolor);
nextblock++;
break;
@@ -403,7 +518,8 @@ void xshow(dpy, desc, numstr, numnl)
}
free(curmode.substyle);
- fixup_and_draw(dpy, style, auxblocks, blocks, nextblock, lines, line);
+ fixup_and_draw(dpy, style, auxblocks, blocks, nextblock, lines, line,
+ beepcount);
free(lines);
free(auxblocks);
}