All: Use err(x) warn(x) instead of fprintf for formated error messages

with additional information from errno.
This commit is contained in:
Philippe Pepiot 2009-10-14 00:15:24 +02:00
parent 7917654281
commit e723c03fe3
7 changed files with 27 additions and 32 deletions

View File

@ -136,7 +136,7 @@ conf_misc_section(char *src)
if(pad > 24 || pad < 1)
{
fprintf(stderr, "WMFS Configuration: pad value (%d) incorrect.\n", pad);
warnx("configuration : pad value (%d) incorrect.", pad);
pad = 12;
}
@ -288,7 +288,7 @@ conf_layout_section(char *src)
if(conf.nlayout > NUM_OF_LAYOUT || !(conf.nlayout))
{
fprintf(stderr, "WMFS Configuration: Too many or no layouts (%d)\n", conf.nlayout);
warnx("configuration : Too many or no layouts (%d).", conf.nlayout);
conf.nlayout = 1;
conf.layout[0].symbol = _strdup("TILE");
conf.layout[0].func = tile;
@ -312,7 +312,7 @@ conf_layout_section(char *src)
tmp = get_nsec(src, "layout", i);
if(!name_to_func((p = get_opt(tmp, "tile", "type").str), layout_list))
fprintf(stderr, "WMFS Configuration: Unknow Layout type: \"%s\"\n", p);
warnx("configuration : Unknown Layout type : \"%s\".", p);
else
{
if(conf.layout_system && conf.nlayout > 1)
@ -412,9 +412,7 @@ conf_tag_section(char *src)
for(i = 0; i < sc; ++i)
if(!conf.ntag[i] || conf.ntag[i] > MAXTAG)
{
fprintf(stderr, "WMFS Configuration: Too many or no tag"
" (%d) in the screen %d\n", conf.ntag[i], i);
warnx("configuration : Too many or no tag (%d) in the screen %d.", conf.ntag[i], i);
conf.ntag[i] = 1;
tags[i][1] = default_tag;
}
@ -511,7 +509,7 @@ conf_keybind_section(char *src)
if(keys[i].func == NULL)
{
fprintf(stderr, "WMFS Configuration warning: Unknow Function \"%s\"\n", get_opt(tmp, "", "func").str);
warnx("configuration : Unknown Function \"%s\".", get_opt(tmp, "", "func").str);
keys[i].func = uicb_spawn;
}
@ -530,9 +528,9 @@ init_conf(void)
if(!(file = file_to_str(conf.confpath)))
{
fprintf(stderr, "WMFS: parsing configuration file (%s) failed\n", conf.confpath);
warnx("parsing configuration file (%s) failed.", conf.confpath);
sprintf(conf.confpath, "%s/wmfs/wmfsrc", XDG_CONFIG_DIR);
fprintf(stderr, "Use the default configuration (%s).\n", conf.confpath);
warnx("Use the default configuration (%s).", conf.confpath);
file = file_to_str(conf.confpath);
}

View File

@ -40,9 +40,15 @@ file_to_str(char *path)
struct stat st;
Bool is_char = False;
if(!path || !(fd = open(path, O_RDONLY)))
if (!path)
return NULL;
if (!(fd = open(path, O_RDONLY)))
{
warn("%s", path);
return NULL;
}
/* Get the file size */
stat(path, &st);
@ -75,7 +81,7 @@ file_to_str(char *path)
munmap(buf, st.st_size);
close(fd);
fprintf(stderr, "WMFS Configuration info: '%s' read.\n", path);
warnx("%s read.", path);
return ret;
}
@ -212,7 +218,7 @@ get_opt(char *src, char *def, char *name)
for(i = 0; i < strlen(p2); ++i)
if(p2[i] != ' ')
{
fprintf(stderr, "WMFS Configuration warning: Missing '=' after option: '%s'"
warnx("Configuration warning: Missing '=' after option: '%s'"
" and before expression: '%s'\n", name, p2);
return str_to_opt(def);
}

View File

@ -200,7 +200,7 @@ getinfo(char *info)
" mwfact Show mwfact of current tag.\n"
" nmaster Show nmaster of current tag.\n");
else
fprintf(stderr, "Unknow info argument '%s'\nTry 'wmfs -g help'\n", info);
warnx("Unknow info argument '%s'\nTry 'wmfs -g help'", info);
return;
}

View File

@ -63,7 +63,7 @@ init_font(void)
if(!font)
{
fprintf(stderr, "WMFS Error: Cannot initialize font\n");
warnx("WMFS Error: Cannot initialize font");
font = XftFontOpenName(dpy, SCREEN, "sans-10");
}

View File

@ -308,7 +308,7 @@ complete_on_files(char *start, size_t hits)
ret = _strdup(content->d_name + strlen(p));
}
else
warnx("%s", filepath);
warn("%s", filepath);
IFREE(filepath);

View File

@ -43,7 +43,7 @@ emalloc(uint element, uint size)
void *ret = calloc(element, size);
if(!ret)
fprintf(stderr,"WMFS Error: could not malloc() %u bytes\n", size);
warn("calloc()");
return ret;
}
@ -58,7 +58,7 @@ getcolor(char *color)
XColor xcolor;
if(!XAllocNamedColor(dpy, DefaultColormap(dpy, SCREEN), color, &xcolor, &xcolor))
fprintf(stderr,"WMFS Error: cannot allocate color \"%s\"\n", color);
warnx("Error: cannot allocate color \"%s\".", color);
return xcolor.pixel;
}
@ -210,7 +210,7 @@ spawn(const char *format, ...)
if(strlen(format) > 511)
{
fprintf(stderr, "WMFS spawn(): Error, command too long.\n");
warnx("spawn(): Error, command too long.");
return;
}

View File

@ -41,10 +41,7 @@ errorhandler(Display *d, XErrorEvent *event)
/* Check if there is another WM running */
if(BadAccess == event->error_code
&& ROOT == event->resourceid)
{
fprintf(stderr, "WMFS Error: Another Window Manager is already running.\n");
exit(EXIT_FAILURE);
}
errx(EXIT_FAILURE, "Another Window Manager is already running.");
/* Ignore focus change error for unmapped client */
/* Too lazy to add Xproto.h so:
@ -59,7 +56,7 @@ errorhandler(Display *d, XErrorEvent *event)
XGetErrorText(d, event->error_code, mess, 128);
fprintf(stderr, "WMFS error: %s(%d) opcodes %d/%d\n resource #%lx\n", mess,
warnx("%s(%d) opcodes %d/%d\n resource #%lx\n", mess,
event->error_code,
event->request_code,
event->minor_code,
@ -269,7 +266,7 @@ check_wmfs_running(void)
{
XFree(ret);
fprintf(stderr, "Wmfs is not running. (_WMFS_RUNNING not present)\n");
warnx("Wmfs is not running. (_WMFS_RUNNING not present)");
return False;
}
@ -381,10 +378,7 @@ main(int argc, char **argv)
/* For options who need WMFS running */
if(strchr(ol, i) && !(dpy = XOpenDisplay(NULL)))
{
fprintf(stderr, "WMFS: cannot open X server.\n");
exit(EXIT_FAILURE);
}
errx(EXIT_FAILURE, "cannot open X server.");
switch(i)
{
@ -450,10 +444,7 @@ main(int argc, char **argv)
/* Check if WMFS can open X server */
if(!(dpy = XOpenDisplay(NULL)))
{
fprintf(stderr, "WMFS: cannot open X server.\n");
exit(EXIT_FAILURE);
}
errx(EXIT_FAILURE, "cannot open X server.");
/* Set signal handler */
(void)signal(SIGTERM, &signal_handle);