summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gram.y67
-rw-r--r--src/lex.l10
-rw-r--r--src/list.c5
-rw-r--r--src/parse.c60
-rw-r--r--src/twm.c12
-rw-r--r--src/twm.h6
6 files changed, 77 insertions, 83 deletions
diff --git a/src/gram.y b/src/gram.y
index 6c4f4ea..4bf9f4c 100644
--- a/src/gram.y
+++ b/src/gram.y
@@ -281,19 +281,17 @@ stmt : error
noarg : KEYWORD { if (!do_single_keyword ($1)) {
- twmrc_error_prefix();
- fprintf (stderr,
- "unknown singleton keyword %d\n",
- $1);
+ parseWarning (
+ "unknown singleton keyword %d",
+ $1);
ParseError = 1;
}
}
;
sarg : SKEYWORD string { if (!do_string_keyword ($1, $2)) {
- twmrc_error_prefix();
- fprintf (stderr,
- "unknown string keyword %d (value \"%s\")\n",
+ parseWarning (
+ "unknown string keyword %d (value \"%s\")",
$1, $2);
ParseError = 1;
}
@@ -301,9 +299,8 @@ sarg : SKEYWORD string { if (!do_string_keyword ($1, $2)) {
;
narg : NKEYWORD number { if (!do_number_keyword ($1, $2)) {
- twmrc_error_prefix();
- fprintf (stderr,
- "unknown numeric keyword %d (value %d)\n",
+ parseWarning (
+ "unknown numeric keyword %d (value %d)",
$1, $2);
ParseError = 1;
}
@@ -327,9 +324,8 @@ key : META { mods |= Mod1Mask; }
| LOCK { mods |= LockMask; }
| CONTROL { mods |= ControlMask; }
| META number { if ($2 < 1 || $2 > 5) {
- twmrc_error_prefix();
- fprintf (stderr,
- "bad modifier number (%d), must be 1-5\n",
+ parseWarning (
+ "bad modifier number (%d), must be 1-5",
$2);
ParseError = 1;
} else {
@@ -445,9 +441,8 @@ color_entries : /* Empty */
color_entry : CLKEYWORD string { if (!do_colorlist_keyword ($1, color,
$2)) {
- twmrc_error_prefix();
- fprintf (stderr,
- "unhandled list color keyword %d (string \"%s\")\n",
+ parseWarning (
+ "unhandled list color keyword %d (string \"%s\")",
$1, $2);
ParseError = 1;
}
@@ -455,9 +450,8 @@ color_entry : CLKEYWORD string { if (!do_colorlist_keyword ($1, color,
| CLKEYWORD string { list = do_colorlist_keyword($1,color,
$2);
if (!list) {
- twmrc_error_prefix();
- fprintf (stderr,
- "unhandled color list keyword %d (string \"%s\")\n",
+ parseWarning (
+ "unhandled color list keyword %d (string \"%s\")",
$1, $2);
ParseError = 1;
}
@@ -465,9 +459,8 @@ color_entry : CLKEYWORD string { if (!do_colorlist_keyword ($1, color,
win_color_list { /* No action */; }
| CKEYWORD string { if (!do_color_keyword ($1, color,
$2)) {
- twmrc_error_prefix();
- fprintf (stderr,
- "unhandled color keyword %d (string \"%s\")\n",
+ parseWarning (
+ "unhandled color keyword %d (string \"%s\")",
$1, $2);
ParseError = 1;
}
@@ -605,18 +598,16 @@ action : FKEYWORD { $$ = $1; }
break;
case F_WARPRING:
if (!CheckWarpRingArg (Action)) {
- twmrc_error_prefix();
- fprintf (stderr,
- "ignoring invalid f.warptoring argument \"%s\"\n",
+ parseWarning (
+ "ignoring invalid f.warptoring argument \"%s\"",
Action);
$$ = F_NOP;
}
break;
case F_WARPTOSCREEN:
if (!CheckWarpScreenArg (Action)) {
- twmrc_error_prefix();
- fprintf (stderr,
- "ignoring invalid f.warptoscreen argument \"%s\"\n",
+ parseWarning (
+ "ignoring invalid f.warptoscreen argument \"%s\"",
Action);
$$ = F_NOP;
}
@@ -625,9 +616,8 @@ action : FKEYWORD { $$ = $1; }
if (CheckColormapArg (Action)) {
$$ = F_COLORMAP;
} else {
- twmrc_error_prefix();
- fprintf (stderr,
- "ignoring invalid f.colormap argument \"%s\"\n",
+ parseWarning (
+ "ignoring invalid f.colormap argument \"%s\"",
Action);
$$ = F_NOP;
}
@@ -666,8 +656,7 @@ number : NUMBER { $$ = $1; }
static void
yyerror(const char *s)
{
- twmrc_error_prefix();
- fprintf (stderr, "error in input file: %s\n", s ? s : "");
+ parseWarning ("error in input file: %s", s ? s : "");
ParseError = 1;
}
@@ -830,9 +819,8 @@ static void GotKey(char *key, int func)
static void GotTitleButton (char *bitmapname, int func, Bool rightside)
{
if (!CreateTitleButton (bitmapname, func, Action, pull, rightside, True)) {
- twmrc_error_prefix();
- fprintf (stderr,
- "unable to create %s titlebutton \"%s\"\n",
+ parseWarning (
+ "unable to create %s titlebutton \"%s\"",
rightside ? "right" : "left", bitmapname);
}
Action = empty;
@@ -876,10 +864,3 @@ static Bool CheckColormapArg (char *s)
return False;
}
-
-
-void
-twmrc_error_prefix (void)
-{
- fprintf (stderr, "%s: line %d: ", ProgramName, yylineno);
-}
diff --git a/src/lex.l b/src/lex.l
index 320d206..e8453bb 100644
--- a/src/lex.l
+++ b/src/lex.l
@@ -106,9 +106,8 @@ number [0-9]+
[a-zA-Z\.]+ { int token = parse_keyword ((char *)yytext,
&yylval.num);
if (token == ERRORTOKEN) {
- twmrc_error_prefix();
- fprintf (stderr,
- "ignoring unknown keyword: %s\n",
+ parseWarning (
+ "ignoring unknown keyword: %s",
yytext);
ParseError = 1;
} else
@@ -125,9 +124,8 @@ number [0-9]+
\#[^\n]*\n {;}
[\r\n\t ] {;}
. {
- twmrc_error_prefix();
- fprintf (stderr,
- "ignoring character \"%s\"\n",
+ parseWarning (
+ "ignoring character \"%s\"",
yytext);
ParseError = 1;
}
diff --git a/src/list.c b/src/list.c
index 593204f..4422cc9 100644
--- a/src/list.c
+++ b/src/list.c
@@ -92,9 +92,8 @@ AddToList(name_list ** list_head, char *name, char *ptr)
nptr = malloc(sizeof(name_list));
if (nptr == NULL) {
- twmrc_error_prefix();
- fprintf(stderr, "unable to allocate %lu bytes for name_list\n",
- (unsigned long) sizeof(name_list));
+ parseWarning("unable to allocate %lu bytes for name_list",
+ (unsigned long) sizeof(name_list));
Done(NULL, NULL);
}
diff --git a/src/parse.c b/src/parse.c
index 18ed6b0..48430b3 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -58,14 +58,17 @@ in this Software without prior written authorization from The Open Group.
***********************************************************************/
#include <stdio.h>
+#include <stdarg.h>
#include <X11/Xos.h>
#include <X11/Xmu/CharSet.h>
+
#include "twm.h"
#include "screen.h"
#include "menus.h"
#include "util.h"
#include "gram.h"
#include "parse.h"
+
#include <X11/Xatom.h>
#include <X11/extensions/sync.h>
@@ -82,8 +85,6 @@ static unsigned char overflowbuff[20]; /* really only need one */
static int overflowlen;
static unsigned char **stringListSource, *currentString;
-static int doparse(int (*ifunc) (void), const char *srctypename,
- const char *srcname);
static int twmFileInput(void);
static int twmStringListInput(void);
static int ParseUsePPosition(char *s);
@@ -95,6 +96,9 @@ int ConstrainedMoveTime = 400; /* milliseconds, event times */
int (*twmInputFunc) (void);
+static const char *twmInputFile;
+static const char *twmInputType;
+
/**
* parse the .twmrc file
* \param filename the filename to parse. NULL indicates $HOME/.twmrc
@@ -108,6 +112,8 @@ doparse(int (*ifunc) (void), const char *srctypename, const char *srcname)
yylineno = 1;
ParseError = FALSE;
twmInputFunc = ifunc;
+ twmInputFile = srcname;
+ twmInputType = srctypename;
overflowlen = 0;
yyparse();
@@ -284,8 +290,7 @@ twmUnput(int c)
overflowbuff[overflowlen++] = (unsigned char) c;
}
else {
- twmrc_error_prefix();
- fprintf(stderr, "unable to unput character (%d)\n", c);
+ parseWarning("unable to unput character (%d)", c);
}
}
@@ -748,9 +753,7 @@ do_string_keyword(int keyword, char *s)
int ppos = ParseUsePPosition(s);
if (ppos < 0) {
- twmrc_error_prefix();
- fprintf(stderr,
- "ignoring invalid UsePPosition argument \"%s\"\n", s);
+ parseWarning("ignoring invalid UsePPosition argument \"%s\"", s);
}
else {
Scr->UsePPosition = (short) ppos;
@@ -799,13 +802,11 @@ do_string_keyword(int keyword, char *s)
&JunkHeight);
if ((JunkMask & (WidthValue | HeightValue)) !=
(WidthValue | HeightValue)) {
- twmrc_error_prefix();
- fprintf(stderr, "bad MaxWindowSize \"%s\"\n", s);
+ parseWarning("bad MaxWindowSize \"%s\"", s);
return 0;
}
if (JunkWidth <= 0 || JunkHeight <= 0) {
- twmrc_error_prefix();
- fprintf(stderr, "MaxWindowSize \"%s\" must be positive\n", s);
+ parseWarning("MaxWindowSize \"%s\" must be positive", s);
return 0;
}
Scr->MaxWindowWidth = (int) JunkWidth;
@@ -1134,20 +1135,16 @@ do_squeeze_entry(name_list ** list, char *name, int justify, int num, int denom)
int absnum = (num < 0 ? -num : num);
if (denom < 0) {
- twmrc_error_prefix();
- fprintf(stderr, "negative SqueezeTitle denominator %d\n", denom);
+ parseWarning("negative SqueezeTitle denominator %d", denom);
return;
}
if (absnum > denom && denom != 0) {
- twmrc_error_prefix();
- fprintf(stderr, "SqueezeTitle fraction %d/%d outside window\n",
- num, denom);
+ parseWarning("SqueezeTitle fraction %d/%d outside window", num, denom);
return;
}
if (denom == 1) {
- twmrc_error_prefix();
- fprintf(stderr, "useless SqueezeTitle faction %d/%d, assuming 0/0\n",
- num, denom);
+ parseWarning("useless SqueezeTitle faction %d/%d, assuming 0/0",
+ num, denom);
num = 0;
denom = 0;
}
@@ -1158,9 +1155,8 @@ do_squeeze_entry(name_list ** list, char *name, int justify, int num, int denom)
sinfo = malloc(sizeof(SqueezeInfo));
if (!sinfo) {
- twmrc_error_prefix();
- fprintf(stderr, "unable to allocate %lu bytes for squeeze info\n",
- (unsigned long) sizeof(SqueezeInfo));
+ parseWarning("unable to allocate %lu bytes for squeeze info",
+ (unsigned long) sizeof(SqueezeInfo));
return;
}
sinfo->justify = justify;
@@ -1169,3 +1165,23 @@ do_squeeze_entry(name_list ** list, char *name, int justify, int num, int denom)
AddToList(list, name, (char *) sinfo);
}
}
+
+void
+parseWarning(const char *format, ...)
+{
+ if (message_level > 0) {
+ va_list ap;
+
+ va_start(ap, format);
+ if (twmInputFile != NULL) {
+ fprintf(stderr, "%s: line %d: ", twmInputFile, yylineno);
+ }
+ else {
+ fprintf(stderr, "%s[%s]: line %d: ", ProgramName, twmInputType,
+ yylineno);
+ }
+ vfprintf(stderr, format, ap);
+ fputc('\n', stderr);
+ va_end(ap);
+ }
+}
diff --git a/src/twm.c b/src/twm.c
index 12cac5f..2abb603 100644
--- a/src/twm.c
+++ b/src/twm.c
@@ -117,7 +117,7 @@ ScreenInfo **ScreenList; /* structures for each screen */
ScreenInfo *Scr = NULL; /* the cur and prev screens */
int PreviousScreen; /* last screen that we were on */
int FirstScreen; /* TRUE ==> first screen of display */
-static int verbose = 1; /* controls error messages */
+int message_level = 1; /* controls error messages */
static int RedirectError; /* TRUE ==> another window manager running */
static int TwmErrorHandler(Display *dpy, XErrorEvent *event); /* for settting RedirectError */
static int CatchRedirectError(Display *dpy, XErrorEvent *event); /* for everything else */
@@ -306,7 +306,7 @@ main(int argc, char *argv[])
case 'v': /* -verbose */
if (!brief_opt(argv[i], "verbose"))
usage();
- verbose++;
+ message_level++;
continue;
case 'c': /* -clientId */
if (!brief_opt(argv[i], "clientId"))
@@ -325,7 +325,7 @@ main(int argc, char *argv[])
case 'q': /* -quiet */
if (!brief_opt(argv[i], "quiet"))
usage();
- --verbose;
+ --message_level;
continue;
}
}
@@ -987,7 +987,7 @@ TwmErrorHandler(Display *dpy2, XErrorEvent *event)
LastErrorEvent = *event;
ErrorOccurred = True;
- if ((verbose > 1) && /* don't be too obnoxious */
+ if ((message_level > 1) && /* don't be too obnoxious */
event->error_code != BadWindow && /* watch for dead puppies */
(event->request_code != X_GetGeometry && /* of all styles */
event->error_code != BadDrawable))
@@ -1020,7 +1020,7 @@ twmError(const char *format, ...)
void
twmWarning(const char *format, ...)
{
- if (verbose > 0) {
+ if (message_level > 0) {
va_list ap;
va_start(ap, format);
@@ -1034,7 +1034,7 @@ twmWarning(const char *format, ...)
void
twmVerbose(const char *format, ...)
{
- if (verbose > 1) {
+ if (message_level > 1) {
va_list ap;
va_start(ap, format);
diff --git a/src/twm.h b/src/twm.h
index d39abdb..2428391 100644
--- a/src/twm.h
+++ b/src/twm.h
@@ -418,16 +418,16 @@ extern Bool RestartPreviousState;
extern Bool
GetWMState(Window w, int *statep, Window *iwp);
-extern void
-twmrc_error_prefix(void);
-
extern int
yyparse(void);
extern int
yylex(void);
+extern void parseWarning(const char *, ...) GCC_PRINTFLIKE(1,2);
+
extern Atom TwmAtoms[];
+extern int message_level;
extern Bool use_fontset;
extern int ShapeEventBase;