Changed the err and warns to macros

err and warn are BSD format but they are not recommended by library
developers.  However their consiseness is useful!

The solution is to use some macros that create xerr etc which then
just map to the error() function.  The next problem is error() uses
program_invocation_name so we set this to program_invovation_short_name

This is a global set but seems to be the convention (or at least errors
are on the short name only) used everywhere else.
This commit is contained in:
Craig Small 2012-01-03 18:48:43 +11:00
parent 76b3e91e6a
commit fb11e1fe0a
15 changed files with 100 additions and 147 deletions

7
free.c
View File

@ -206,6 +206,7 @@ int main(int argc, char **argv)
args.repeat_interval = 1000000; args.repeat_interval = 1000000;
args.repeat_counter = 0; args.repeat_counter = 0;
program_invocation_name = program_invocation_short_name;
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR); bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE); textdomain(PACKAGE);
@ -246,9 +247,9 @@ int main(int argc, char **argv)
flags |= FREE_REPEAT; flags |= FREE_REPEAT;
args.repeat_interval = (1000000 * strtof(optarg, &endptr)); args.repeat_interval = (1000000 * strtof(optarg, &endptr));
if (errno || optarg == endptr || (endptr && *endptr)) if (errno || optarg == endptr || (endptr && *endptr))
errx(EXIT_FAILURE, _("seconds argument `%s' failed"), optarg); xerrx(EXIT_FAILURE, _("seconds argument `%s' failed"), optarg);
if (args.repeat_interval < 1) if (args.repeat_interval < 1)
errx(EXIT_FAILURE, xerrx(EXIT_FAILURE,
_("seconds argument `%s' is not positive number"), optarg); _("seconds argument `%s' is not positive number"), optarg);
break; break;
case 'c': case 'c':
@ -256,7 +257,7 @@ int main(int argc, char **argv)
flags |= FREE_REPEATCOUNT; flags |= FREE_REPEATCOUNT;
args.repeat_counter = strtoul(optarg, &endptr, 10); args.repeat_counter = strtoul(optarg, &endptr, 10);
if (errno || optarg == endptr || (endptr && *endptr)) if (errno || optarg == endptr || (endptr && *endptr))
errx(EXIT_FAILURE, _("count argument `%s' failed"), optarg); xerrx(EXIT_FAILURE, _("count argument `%s' failed"), optarg);
break; break;
case HELP_OPTION: case HELP_OPTION:

View File

@ -17,10 +17,6 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#ifdef HAVE_ERR_H
# include <err.h>
#endif
/* /*
* Compiler specific stuff * Compiler specific stuff
*/ */
@ -106,43 +102,10 @@ static inline char *prog_inv_sh_nm_from_file(char *f, char stripext)
/* /*
* Error printing. * Error printing.
*/ */
#ifndef HAVE_ERR_H #define xwarn(FMT...) error(0, errno, FMT)
static inline void #define xwarnx(FMT...) error(0, 0, FMT)
errmsg(char doexit, int excode, char adderr, const char *fmt, ...) #define xerr(STATUS, FMT...) error(STATUS, errno, FMT)
{ #define xerrx(STATUS, FMT...) error(STATUS, 0, FMT)
fprintf(stderr, "%s: ", program_invocation_short_name);
if (fmt != NULL) {
va_list argp;
va_start(argp, fmt);
vfprintf(stderr, fmt, argp);
va_end(argp);
if (adderr)
fprintf(stderr, ": ");
}
if (adderr)
fprintf(stderr, "%m");
fprintf(stderr, "\n");
if (doexit)
exit(excode);
}
# ifndef HAVE_ERR
# define err(E, FMT...) errmsg(1, E, 1, FMT)
# endif
# ifndef HAVE_ERRX
# define errx(E, FMT...) errmsg(1, E, 0, FMT)
# endif
# ifndef HAVE_WARN
# define warn(FMT...) errmsg(0, 0, 1, FMT)
# endif
# ifndef HAVE_WARNX
# define warnx(FMT...) errmsg(0, 0, 0, FMT)
# endif
#endif /* !HAVE_ERR_H */
/* /*
* Constant strings for usage() functions. * Constant strings for usage() functions.

View File

@ -15,19 +15,14 @@ long strtol_or_err(const char *str, const char *errmesg)
long num; long num;
char *end = NULL; char *end = NULL;
if (str == NULL || *str == '\0') if (str != NULL && *str != '\0') {
goto err; errno = 0;
errno = 0; num = strtol(str, &end, 10);
num = strtol(str, &end, 10); if (errno == 0 && str != end && end != NULL && *end == '\0')
if (errno || str == end || (end && *end)) return num;
goto err; }
error(EXIT_FAILURE, errno, "%s: '%s'", errmesg, str);
return num; return 0;
err:
if (errno)
err(EXIT_FAILURE, "%s: '%s'", errmesg, str);
else
errx(EXIT_FAILURE, "%s: '%s'", errmesg, str);
} }
/* /*
* same as strtod(3) but exit on failure instead of returning crap * same as strtod(3) but exit on failure instead of returning crap
@ -37,20 +32,13 @@ double strtod_or_err(const char *str, const char *errmesg)
double num; double num;
char *end = NULL; char *end = NULL;
if (str == NULL || *str == '\0') if (str != NULL && *str != '\0') {
goto err; errno = 0;
errno = 0; num = strtod(str, &end);
num = strtod(str, &end); if (errno == 0 && str != end && end != NULL && *end == '\0')
return num;
if (errno || str == end || (end && *end)) }
goto err; error(EXIT_FAILURE, errno, "%s: '%s'", errmesg, str);
return num;
err:
if (errno)
err(EXIT_FAILURE, "%s: '%s'", errmesg, str);
else
errx(EXIT_FAILURE, "%s: '%s'", errmesg, str);
return 0; return 0;
} }

21
pgrep.c
View File

@ -255,7 +255,7 @@ static int conv_uid (const char *restrict name, union el *restrict e)
pwd = getpwnam (name); pwd = getpwnam (name);
if (pwd == NULL) { if (pwd == NULL) {
warnx(_("invalid user name: %s"), name); xwarnx(_("invalid user name: %s"), name);
return 0; return 0;
} }
e->num = pwd->pw_uid; e->num = pwd->pw_uid;
@ -272,7 +272,7 @@ static int conv_gid (const char *restrict name, union el *restrict e)
grp = getgrnam (name); grp = getgrnam (name);
if (grp == NULL) { if (grp == NULL) {
warnx(_("invalid group name: %s"), name); xwarnx(_("invalid group name: %s"), name);
return 0; return 0;
} }
e->num = grp->gr_gid; e->num = grp->gr_gid;
@ -283,7 +283,7 @@ static int conv_gid (const char *restrict name, union el *restrict e)
static int conv_pgrp (const char *restrict name, union el *restrict e) static int conv_pgrp (const char *restrict name, union el *restrict e)
{ {
if (! strict_atol (name, &e->num)) { if (! strict_atol (name, &e->num)) {
warnx(_("invalid process group: %s"), name); xwarnx(_("invalid process group: %s"), name);
return 0; return 0;
} }
if (e->num == 0) if (e->num == 0)
@ -295,7 +295,7 @@ static int conv_pgrp (const char *restrict name, union el *restrict e)
static int conv_sid (const char *restrict name, union el *restrict e) static int conv_sid (const char *restrict name, union el *restrict e)
{ {
if (! strict_atol (name, &e->num)) { if (! strict_atol (name, &e->num)) {
warnx(_("invalid session id: %s"), name); xwarnx(_("invalid session id: %s"), name);
return 0; return 0;
} }
if (e->num == 0) if (e->num == 0)
@ -307,7 +307,7 @@ static int conv_sid (const char *restrict name, union el *restrict e)
static int conv_num (const char *restrict name, union el *restrict e) static int conv_num (const char *restrict name, union el *restrict e)
{ {
if (! strict_atol (name, &e->num)) { if (! strict_atol (name, &e->num)) {
warnx(_("not a number: %s"), name); xwarnx(_("not a number: %s"), name);
return 0; return 0;
} }
return 1; return 1;
@ -733,14 +733,14 @@ static void parse_opts (int argc, char **argv)
} }
if(opt_lock && !opt_pidfile) if(opt_lock && !opt_pidfile)
errx(EXIT_FAILURE, _("-L without -F makes no sense\n" xerrx(EXIT_FAILURE, _("-L without -F makes no sense\n"
"Try `%s --help' for more information."), "Try `%s --help' for more information."),
program_invocation_short_name); program_invocation_short_name);
if(opt_pidfile){ if(opt_pidfile){
opt_pid = read_pidfile(); opt_pid = read_pidfile();
if(!opt_pid) if(!opt_pid)
errx(EXIT_FAILURE, _("pidfile not valid\n" xerrx(EXIT_FAILURE, _("pidfile not valid\n"
"Try `%s --help' for more information."), "Try `%s --help' for more information."),
program_invocation_short_name); program_invocation_short_name);
} }
@ -748,11 +748,11 @@ static void parse_opts (int argc, char **argv)
if (argc - optind == 1) if (argc - optind == 1)
opt_pattern = argv[optind]; opt_pattern = argv[optind];
else if (argc - optind > 1) else if (argc - optind > 1)
errx(EXIT_FAILURE, _("only one pattern can be provided\n" xerrx(EXIT_FAILURE, _("only one pattern can be provided\n"
"Try `%s --help' for more information."), "Try `%s --help' for more information."),
program_invocation_short_name); program_invocation_short_name);
else if (criteria_count == 0) else if (criteria_count == 0)
errx(EXIT_FAILURE, _("no matching criteria specified\n" xerrx(EXIT_FAILURE, _("no matching criteria specified\n"
"Try `%s --help' for more information."), "Try `%s --help' for more information."),
program_invocation_short_name); program_invocation_short_name);
} }
@ -763,6 +763,7 @@ int main (int argc, char **argv)
union el *procs; union el *procs;
int num; int num;
program_invocation_name = program_invocation_short_name;
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR); bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE); textdomain(PACKAGE);
@ -778,7 +779,7 @@ int main (int argc, char **argv)
if (errno==ESRCH) if (errno==ESRCH)
// gone now, which is OK // gone now, which is OK
continue; continue;
warn(_("killing pid %ld failed")); xwarn(_("killing pid %ld failed"));
} }
} else { } else {
if (opt_count) { if (opt_count) {

8
pmap.c
View File

@ -10,7 +10,6 @@
*/ */
#include <ctype.h> #include <ctype.h>
#include <err.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <getopt.h> #include <getopt.h>
@ -393,6 +392,7 @@ int main(int argc, char **argv)
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
program_invocation_name = program_invocation_short_name;
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR); bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE); textdomain(PACKAGE);
@ -405,7 +405,7 @@ int main(int argc, char **argv)
x_option = 1; x_option = 1;
break; break;
case 'r': case 'r':
warnx(_("option -r is ignored as SunOS compatibility")); xwarnx(_("option -r is ignored as SunOS compatibility"));
break; break;
case 'd': case 'd':
d_option = 1; d_option = 1;
@ -460,9 +460,9 @@ int main(int argc, char **argv)
argv += optind; argv += optind;
if (argc < 1) if (argc < 1)
errx(EXIT_FAILURE, _("argument missing")); xerrx(EXIT_FAILURE, _("argument missing"));
if (d_option && x_option) if (d_option && x_option)
errx(EXIT_FAILURE, _("options -d and -x cannot coexist")); xerrx(EXIT_FAILURE, _("options -d and -x cannot coexist"));
pidlist = xmalloc(sizeof(unsigned) * argc); pidlist = xmalloc(sizeof(unsigned) * argc);

View File

@ -45,15 +45,6 @@
#define NORETURN __attribute__((__noreturn__)) #define NORETURN __attribute__((__noreturn__))
#define FUNCTION __attribute__((__const__)) // no access to global mem, even via ptr, and no side effect #define FUNCTION __attribute__((__const__)) // no access to global mem, even via ptr, and no side effect
#if !defined(restrict) && __STDC_VERSION__ < 199901
#if __GNUC__ > 2 || __GNUC_MINOR__ >= 92
#define restrict __restrict__
#else
#warning No restrict keyword?
#define restrict
#endif
#endif
#if __GNUC__ > 2 || __GNUC_MINOR__ >= 96 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
// won't alias anything, and aligned enough for anything // won't alias anything, and aligned enough for anything
#define MALLOC __attribute__ ((__malloc__)) #define MALLOC __attribute__ ((__malloc__))

1
pwdx.c
View File

@ -48,6 +48,7 @@ int main(int argc, char *argv[])
{NULL, 0, 0, 0} {NULL, 0, 0, 0}
}; };
program_invocation_name = program_invocation_short_name;
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR); bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE); textdomain(PACKAGE);

15
skill.c
View File

@ -245,7 +245,7 @@ static void iterate(struct run_time_conf_t *run_time)
#endif #endif
d = opendir("/proc"); d = opendir("/proc");
if (!d) if (!d)
err(EXIT_FAILURE, "/proc"); xerr(EXIT_FAILURE, "/proc");
while ((de = readdir(d))) { while ((de = readdir(d))) {
if (de->d_name[0] > '9') if (de->d_name[0] > '9')
continue; continue;
@ -387,7 +387,7 @@ static void __attribute__ ((__noreturn__))
if (s) if (s)
printf("%s\n", s); printf("%s\n", s);
else else
warnx(_("unknown signal name %s"), xwarnx(_("unknown signal name %s"),
optarg); optarg);
free(s); free(s);
} else { } else {
@ -448,7 +448,7 @@ int snice_prio_option(int *argc, char **argv)
prio = strtol_or_err(argv[i], prio = strtol_or_err(argv[i],
_("failed to parse argument")); _("failed to parse argument"));
if (prio < INT_MIN || INT_MAX < prio) if (prio < INT_MIN || INT_MAX < prio)
errx(EXIT_FAILURE, xerrx(EXIT_FAILURE,
_("priority %lu out of range"), prio); _("priority %lu out of range"), prio);
nargs--; nargs--;
if (nargs - i) if (nargs - i)
@ -604,15 +604,15 @@ static void skillsnice_parse(int argc,
/* No more arguments to process. Must sanity check. */ /* No more arguments to process. Must sanity check. */
if (!tty_count && !uid_count && !cmd_count && !pid_count) if (!tty_count && !uid_count && !cmd_count && !pid_count)
errx(EXIT_FAILURE, _("no process selection criteria")); xerrx(EXIT_FAILURE, _("no process selection criteria"));
if ((run_time->fast | run_time->interactive | run_time-> if ((run_time->fast | run_time->interactive | run_time->
verbose | run_time->warnings | run_time->noaction) & ~1) verbose | run_time->warnings | run_time->noaction) & ~1)
errx(EXIT_FAILURE, _("general flags may not be repeated")); xerrx(EXIT_FAILURE, _("general flags may not be repeated"));
if (run_time->interactive if (run_time->interactive
&& (run_time->verbose | run_time->fast | run_time->noaction)) && (run_time->verbose | run_time->fast | run_time->noaction))
errx(EXIT_FAILURE, _("-i makes no sense with -v, -f, and -n")); xerrx(EXIT_FAILURE, _("-i makes no sense with -v, -f, and -n"));
if (run_time->verbose && (run_time->interactive | run_time->fast)) if (run_time->verbose && (run_time->interactive | run_time->fast))
errx(EXIT_FAILURE, _("-v makes no sense with -i and -f")); xerrx(EXIT_FAILURE, _("-v makes no sense with -i and -f"));
if (run_time->noaction) { if (run_time->noaction) {
program = PROG_SKILL; program = PROG_SKILL;
/* harmless */ /* harmless */
@ -627,6 +627,7 @@ static void skillsnice_parse(int argc,
/* main body */ /* main body */
int main(int argc, char ** argv) int main(int argc, char ** argv)
{ {
program_invocation_name = program_invocation_short_name;
struct run_time_conf_t run_time; struct run_time_conf_t run_time;
memset(&run_time, 0, sizeof(struct run_time_conf_t)); memset(&run_time, 0, sizeof(struct run_time_conf_t));
my_pid = getpid(); my_pid = getpid();

View File

@ -276,7 +276,7 @@ int main(int argc, char *argv[])
int o; int o;
unsigned short old_rows; unsigned short old_rows;
struct slab_info *slab_list = NULL; struct slab_info *slab_list = NULL;
int run_once=0; int run_once=0;
static const struct option longopts[] = { static const struct option longopts[] = {
{ "delay", required_argument, NULL, 'd' }, { "delay", required_argument, NULL, 'd' },
@ -287,6 +287,7 @@ int main(int argc, char *argv[])
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
program_invocation_name = program_invocation_short_name;
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR); bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE); textdomain(PACKAGE);
@ -300,7 +301,7 @@ int main(int argc, char *argv[])
errno = 0; errno = 0;
delay = strtol_or_err(optarg, _("illegal delay")); delay = strtol_or_err(optarg, _("illegal delay"));
if (delay < 1) if (delay < 1)
errx(EXIT_FAILURE, xerrx(EXIT_FAILURE,
_("delay must be positive integer")); _("delay must be positive integer"));
break; break;
case 's': case 's':
@ -322,7 +323,7 @@ int main(int argc, char *argv[])
} }
if (tcgetattr(STDIN_FILENO, &saved_tty) == -1) if (tcgetattr(STDIN_FILENO, &saved_tty) == -1)
warn(_("terminal setting retrieval")); xwarn(_("terminal setting retrieval"));
old_rows = rows; old_rows = rows;
term_size(0); term_size(0);

View File

@ -70,7 +70,7 @@ static void slashdot(char *restrict p, char old, char new){
while(p){ while(p){
char c = *p; char c = *p;
if((*(p+1) == '/' || *(p+1) == '.') && warned) { if((*(p+1) == '/' || *(p+1) == '.') && warned) {
warnx(_("separators should not be repeated: %s"), p); xwarnx(_("separators should not be repeated: %s"), p);
warned = 0; warned = 0;
} }
if(c==old) *p=new; if(c==old) *p=new;
@ -156,7 +156,7 @@ static int ReadSetting(const char *restrict const name) {
struct stat ts; struct stat ts;
if (!name || !*name) { if (!name || !*name) {
warnx(_("\"%s\" is an unknown key"), name); xwarnx(_("\"%s\" is an unknown key"), name);
return -1; return -1;
} }
@ -176,7 +176,7 @@ static int ReadSetting(const char *restrict const name) {
if (stat(tmpname, &ts) < 0) { if (stat(tmpname, &ts) < 0) {
if (!IgnoreError) { if (!IgnoreError) {
warn(_("cannot stat %s"), tmpname); xwarn(_("cannot stat %s"), tmpname);
rc = -1; rc = -1;
} }
goto out; goto out;
@ -204,16 +204,16 @@ static int ReadSetting(const char *restrict const name) {
switch(errno) { switch(errno) {
case ENOENT: case ENOENT:
if (!IgnoreError) { if (!IgnoreError) {
warnx(_("\"%s\" is an unknown key"), outname); xwarnx(_("\"%s\" is an unknown key"), outname);
rc = -1; rc = -1;
} }
break; break;
case EACCES: case EACCES:
warnx(_("permission denied on key '%s'"), outname); xwarnx(_("permission denied on key '%s'"), outname);
rc = -1; rc = -1;
break; break;
default: default:
warn(_("reading key \"%s\""), outname); xwarn(_("reading key \"%s\""), outname);
rc = -1; rc = -1;
break; break;
} }
@ -241,7 +241,7 @@ static int ReadSetting(const char *restrict const name) {
} else { } else {
switch(errno) { switch(errno) {
case EACCES: case EACCES:
warnx(_("permission denied on key '%s'"), outname); xwarnx(_("permission denied on key '%s'"), outname);
rc = -1; rc = -1;
break; break;
case EISDIR:{ case EISDIR:{
@ -254,7 +254,7 @@ static int ReadSetting(const char *restrict const name) {
goto out; goto out;
} }
default: default:
warnx(_("reading key \"%s\""), outname); xwarnx(_("reading key \"%s\""), outname);
rc = -1; rc = -1;
case 0: case 0:
break; break;
@ -284,7 +284,7 @@ static int DisplayAll(const char *restrict const path) {
dp = opendir(path); dp = opendir(path);
if (!dp) { if (!dp) {
warnx(_("unable to open directory \"%s\""), path); xwarnx(_("unable to open directory \"%s\""), path);
rc = -1; rc = -1;
} else { } else {
readdir(dp); // skip . readdir(dp); // skip .
@ -295,7 +295,7 @@ static int DisplayAll(const char *restrict const path) {
sprintf(tmpdir, "%s%s", path, de->d_name); sprintf(tmpdir, "%s%s", path, de->d_name);
rc2 = stat(tmpdir, &ts); rc2 = stat(tmpdir, &ts);
if (rc2 != 0) { if (rc2 != 0) {
warn(_("cannot stat %s"), tmpdir); xwarn(_("cannot stat %s"), tmpdir);
} else { } else {
if (S_ISDIR(ts.st_mode)) { if (S_ISDIR(ts.st_mode)) {
strcat(tmpdir, "/"); strcat(tmpdir, "/");
@ -333,14 +333,14 @@ static int WriteSetting(const char *setting) {
equals = strchr(setting, '='); equals = strchr(setting, '=');
if (!equals) { if (!equals) {
warnx(_("\"%s\" must be of the form name=value"), setting); xwarnx(_("\"%s\" must be of the form name=value"), setting);
return -1; return -1;
} }
value = equals + 1; /* point to the value in name=value */ value = equals + 1; /* point to the value in name=value */
if (!*name || !*value || name == equals) { if (!*name || !*value || name == equals) {
warnx(_("Malformed setting \"%s\""), setting); xwarnx(_("Malformed setting \"%s\""), setting);
return -2; return -2;
} }
@ -359,19 +359,19 @@ static int WriteSetting(const char *setting) {
if (stat(tmpname, &ts) < 0) { if (stat(tmpname, &ts) < 0) {
if (!IgnoreError) { if (!IgnoreError) {
warn(_("cannot stat %s"), tmpname); xwarn(_("cannot stat %s"), tmpname);
rc = -1; rc = -1;
} }
goto out; goto out;
} }
if ((ts.st_mode & S_IWUSR) == 0) { if ((ts.st_mode & S_IWUSR) == 0) {
warn(_("setting key \"%s\""), outname); xwarn(_("setting key \"%s\""), outname);
goto out; goto out;
} }
if (S_ISDIR(ts.st_mode)) { if (S_ISDIR(ts.st_mode)) {
warn(_("setting key \"%s\""), outname); xwarn(_("setting key \"%s\""), outname);
goto out; goto out;
} }
@ -381,28 +381,28 @@ static int WriteSetting(const char *setting) {
switch(errno) { switch(errno) {
case ENOENT: case ENOENT:
if (!IgnoreError) { if (!IgnoreError) {
warnx(_("\"%s\" is an unknown key"), outname); xwarnx(_("\"%s\" is an unknown key"), outname);
rc = -1; rc = -1;
} }
break; break;
case EACCES: case EACCES:
warnx(_("permission denied on key '%s'"), outname); xwarnx(_("permission denied on key '%s'"), outname);
rc = -1; rc = -1;
break; break;
default: default:
warn(_("setting key \"%s\""), outname); xwarn(_("setting key \"%s\""), outname);
rc = -1; rc = -1;
break; break;
} }
} else { } else {
rc = fprintf(fp, "%s\n", value); rc = fprintf(fp, "%s\n", value);
if (rc < 0) { if (rc < 0) {
warn(_("setting key \"%s\""), outname); xwarn(_("setting key \"%s\""), outname);
fclose(fp); fclose(fp);
} else { } else {
rc=fclose(fp); rc=fclose(fp);
if (rc != 0) if (rc != 0)
warn(_("setting key \"%s\""), outname); xwarn(_("setting key \"%s\""), outname);
} }
if (rc==0 && !Quiet) { if (rc==0 && !Quiet) {
if (NameOnly) { if (NameOnly) {
@ -461,7 +461,7 @@ static int Preload(const char *restrict const filename) {
; ;
if (!fp) { if (!fp) {
warn(_("cannot open \"%s\""), filename); xwarn(_("cannot open \"%s\""), filename);
return -1; return -1;
} }
@ -477,7 +477,7 @@ static int Preload(const char *restrict const filename) {
name = strtok(t, "="); name = strtok(t, "=");
if (!name || !*name) { if (!name || !*name) {
warnx(_("%s(%d): invalid syntax, continuing..."), filename, n); xwarnx(_("%s(%d): invalid syntax, continuing..."), filename, n);
continue; continue;
} }
@ -489,7 +489,7 @@ static int Preload(const char *restrict const filename) {
value = strtok(NULL, "\n\r"); value = strtok(NULL, "\n\r");
if (!value || !*value) { if (!value || !*value) {
warnx(_("%s(%d): invalid syntax, continuing..."), filename, n); xwarnx(_("%s(%d): invalid syntax, continuing..."), filename, n);
continue; continue;
} }
@ -610,9 +610,10 @@ int main(int argc, char *argv[])
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
setlocale (LC_ALL, ""); program_invocation_name = program_invocation_short_name;
bindtextdomain(PACKAGE, LOCALEDIR); setlocale (LC_ALL, "");
textdomain(PACKAGE); bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
PrintName = true; PrintName = true;
PrintNewline = true; PrintNewline = true;
@ -691,11 +692,11 @@ int main(int argc, char *argv[])
argv += optind; argv += optind;
if (argc < 1) if (argc < 1)
errx(EXIT_FAILURE, _("no variables specified\n" xerrx(EXIT_FAILURE, _("no variables specified\n"
"Try `%s --help' for more information."), "Try `%s --help' for more information."),
program_invocation_short_name); program_invocation_short_name);
if (NameOnly && Quiet) if (NameOnly && Quiet)
errx(EXIT_FAILURE, _("options -N and -q cannot coexist\n" xerrx(EXIT_FAILURE, _("options -N and -q cannot coexist\n"
"Try `%s --help' for more information."), "Try `%s --help' for more information."),
program_invocation_short_name); program_invocation_short_name);

11
tload.c
View File

@ -97,7 +97,8 @@ int main(int argc, char **argv)
{"version", no_argument, NULL, 'V'}, {"version", no_argument, NULL, 'V'},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
program_invocation_name = program_invocation_short_name;
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR); bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE); textdomain(PACKAGE);
@ -108,14 +109,14 @@ int main(int argc, char **argv)
case 's': case 's':
max_scale = strtod_or_err(optarg, _("failed to parse argument")); max_scale = strtod_or_err(optarg, _("failed to parse argument"));
if (max_scale < 0) if (max_scale < 0)
errx(EXIT_FAILURE, _("scale cannot be negative")); xerrx(EXIT_FAILURE, _("scale cannot be negative"));
break; break;
case 'd': case 'd':
tmpdly = strtol_or_err(optarg, _("failed to parse argument")); tmpdly = strtol_or_err(optarg, _("failed to parse argument"));
if (tmpdly < 1) if (tmpdly < 1)
errx(EXIT_FAILURE, _("delay must be positive integer")); xerrx(EXIT_FAILURE, _("delay must be positive integer"));
else if (UINT_MAX < tmpdly) else if (UINT_MAX < tmpdly)
errx(EXIT_FAILURE, _("too large delay value")); xerrx(EXIT_FAILURE, _("too large delay value"));
dly = tmpdly; dly = tmpdly;
break; break;
case 'V': case 'V':
@ -130,7 +131,7 @@ int main(int argc, char **argv)
if (argc > optind) if (argc > optind)
if ((fd = open(argv[optind], 1)) == -1) if ((fd = open(argv[optind], 1)) == -1)
err(EXIT_FAILURE, _("can not open tty")); xerr(EXIT_FAILURE, _("can not open tty"));
setsize(0); setsize(0);

View File

@ -30,6 +30,7 @@ int main(int argc, char **argv)
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
program_invocation_name = program_invocation_short_name;
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR); bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE); textdomain(PACKAGE);

View File

@ -360,7 +360,7 @@ static int diskpartition_format(const char *partition_name)
fDiskstat = fopen("/proc/diskstats", "rb"); fDiskstat = fopen("/proc/diskstats", "rb");
if (!fDiskstat) if (!fDiskstat)
errx(EXIT_FAILURE, xerrx(EXIT_FAILURE,
_("Your kernel doesn't support diskstat. (2.5.70 or above required)")); _("Your kernel doesn't support diskstat. (2.5.70 or above required)"));
fclose(fDiskstat); fclose(fDiskstat);
@ -501,7 +501,7 @@ static void diskformat(void)
free(partitions); free(partitions);
} }
} else } else
errx(EXIT_FAILURE, xerrx(EXIT_FAILURE,
_("Your kernel doesn't support diskstat (2.5.70 or above required)")); _("Your kernel doesn't support diskstat (2.5.70 or above required)"));
} }
@ -532,7 +532,7 @@ static void slabformat(void)
fSlab = fopen("/proc/slabinfo", "rb"); fSlab = fopen("/proc/slabinfo", "rb");
if (!fSlab) { if (!fSlab) {
warnx(_("Your kernel doesn't support slabinfo or your permissions are insufficient.")); xwarnx(_("Your kernel doesn't support slabinfo or your permissions are insufficient."));
return; return;
} }
@ -706,6 +706,7 @@ int main(int argc, char *argv[])
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
program_invocation_name = program_invocation_short_name;
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR); bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE); textdomain(PACKAGE);
@ -765,7 +766,7 @@ int main(int argc, char *argv[])
dataUnit = UNIT_M; dataUnit = UNIT_M;
break; break;
default: default:
errx(EXIT_FAILURE, xerrx(EXIT_FAILURE,
/* Translation Hint: do not change argument characters */ /* Translation Hint: do not change argument characters */
_("-S requires k, K, m or M (default is kb)")); _("-S requires k, K, m or M (default is kb)"));
} }
@ -782,9 +783,9 @@ int main(int argc, char *argv[])
if (optind < argc) { if (optind < argc) {
tmp = strtol_or_err(argv[optind++], _("failed to parse argument")); tmp = strtol_or_err(argv[optind++], _("failed to parse argument"));
if (tmp < 1) if (tmp < 1)
errx(EXIT_FAILURE, _("delay must be positive integer")); xerrx(EXIT_FAILURE, _("delay must be positive integer"));
else if (UINT_MAX < tmp) else if (UINT_MAX < tmp)
errx(EXIT_FAILURE, _("too large delay value")); xerrx(EXIT_FAILURE, _("too large delay value"));
sleep_time = tmp; sleep_time = tmp;
infinite_updates = 1; infinite_updates = 1;
} }

9
w.c
View File

@ -343,6 +343,7 @@ int main(int argc, char **argv)
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
program_invocation_name = program_invocation_short_name;
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR); bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE); textdomain(PACKAGE);
@ -388,7 +389,7 @@ int main(int argc, char **argv)
if ((env_var = getenv("PROCPS_USERLEN")) != NULL) { if ((env_var = getenv("PROCPS_USERLEN")) != NULL) {
userlen = atoi(env_var); userlen = atoi(env_var);
if (userlen < 8 || userlen > USERSZ) { if (userlen < 8 || userlen > USERSZ) {
warnx xwarnx
(_("User length environment PROCPS_USERLEN must be between 8 and %d, ignoring.\n"), (_("User length environment PROCPS_USERLEN must be between 8 and %d, ignoring.\n"),
USERSZ); USERSZ);
userlen = 8; userlen = 8;
@ -398,7 +399,7 @@ int main(int argc, char **argv)
if ((env_var = getenv("PROCPS_FROMLEN")) != NULL) { if ((env_var = getenv("PROCPS_FROMLEN")) != NULL) {
fromlen = atoi(env_var); fromlen = atoi(env_var);
if (fromlen < 8 || fromlen > HOSTSZ) { if (fromlen < 8 || fromlen > HOSTSZ) {
warnx xwarnx
(_("From length environment PROCPS_FROMLEN must be between 8 and %d, ignoring.\n"), (_("From length environment PROCPS_FROMLEN must be between 8 and %d, ignoring.\n"),
HOSTSZ); HOSTSZ);
fromlen = 16; fromlen = 16;
@ -411,11 +412,11 @@ int main(int argc, char **argv)
else else
maxcmd = 80; maxcmd = 80;
if (maxcmd < 71) if (maxcmd < 71)
errx(EXIT_FAILURE, _("%d column window is too narrow"), maxcmd); xerrx(EXIT_FAILURE, _("%d column window is too narrow"), maxcmd);
maxcmd -= 21 + userlen + (from ? fromlen : 0) + (longform ? 20 : 0); maxcmd -= 21 + userlen + (from ? fromlen : 0) + (longform ? 20 : 0);
if (maxcmd < 3) if (maxcmd < 3)
warnx(_("warning: screen width %d suboptimal"), win.ws_col); xwarnx(_("warning: screen width %d suboptimal"), win.ws_col);
procs = readproctab(PROC_FILLCOM | PROC_FILLUSR | PROC_FILLSTAT); procs = readproctab(PROC_FILLCOM | PROC_FILLUSR | PROC_FILLSTAT);

View File

@ -308,6 +308,7 @@ int main(int argc, char *argv[])
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
program_invocation_name = program_invocation_short_name;
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR); bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE); textdomain(PACKAGE);