w: add gettext support

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2011-10-09 13:05:02 +02:00
parent 3465901ffb
commit 76841eda26

49
w.c
View File

@ -8,6 +8,9 @@
* *
* Changes by Albert Cahalan, 2002. * Changes by Albert Cahalan, 2002.
*/ */
#include "c.h"
#include "nls.h"
#include "proc/devname.h" #include "proc/devname.h"
#include "proc/escape.h" #include "proc/escape.h"
#include "proc/procps.h" #include "proc/procps.h"
@ -15,8 +18,8 @@
#include "proc/sysinfo.h" #include "proc/sysinfo.h"
#include "proc/version.h" #include "proc/version.h"
#include "proc/whattime.h" #include "proc/whattime.h"
#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>
@ -98,29 +101,29 @@ static void print_time_ival7(time_t t, int centi_sec, FILE * fout)
if (oldstyle) { if (oldstyle) {
if (t >= 48 * 60 * 60) if (t >= 48 * 60 * 60)
/* > 2 days */ /* > 2 days */
fprintf(fout, " %2ludays", t / (24 * 60 * 60)); fprintf(fout, _(" %2ludays"), t / (24 * 60 * 60));
else if (t >= 60 * 60) else if (t >= 60 * 60)
/* > 1 hour */ /* > 1 hour */
fprintf(fout, " %2lu:%02u ", t / (60 * 60), fprintf(fout, " %2lu:%02u ", t / (60 * 60),
(unsigned)((t / 60) % 60)); (unsigned)((t / 60) % 60));
else if (t > 60) else if (t > 60)
/* > 1 minute */ /* > 1 minute */
fprintf(fout, " %2lu:%02um", t / 60, (unsigned)t % 60); fprintf(fout, _(" %2lu:%02um"), t / 60, (unsigned)t % 60);
else else
fprintf(fout, " "); fprintf(fout, " ");
} else { } else {
if (t >= 48 * 60 * 60) if (t >= 48 * 60 * 60)
/* 2 days or more */ /* 2 days or more */
fprintf(fout, " %2ludays", t / (24 * 60 * 60)); fprintf(fout, _(" %2ludays"), t / (24 * 60 * 60));
else if (t >= 60 * 60) else if (t >= 60 * 60)
/* 1 hour or more */ /* 1 hour or more */
fprintf(fout, " %2lu:%02um", t / (60 * 60), fprintf(fout, _(" %2lu:%02um"), t / (60 * 60),
(unsigned)((t / 60) % 60)); (unsigned)((t / 60) % 60));
else if (t > 60) else if (t > 60)
/* 1 minute or more */ /* 1 minute or more */
fprintf(fout, " %2lu:%02u ", t / 60, (unsigned)t % 60); fprintf(fout, " %2lu:%02u ", t / 60, (unsigned)t % 60);
else else
fprintf(fout, " %2lu.%02us", t, centi_sec); fprintf(fout, _(" %2lu.%02us"), t, centi_sec);
} }
} }
@ -137,6 +140,7 @@ static time_t idletime(const char *restrict const tty)
static void print_logintime(time_t logt, FILE * fout) static void print_logintime(time_t logt, FILE * fout)
{ {
/* FIXME: make use of locale, remember strftime() */
char weekday[][4] = { char weekday[][4] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
}; };
@ -297,18 +301,19 @@ static void showinfo(utmp_t * u, int formtype, int maxcmd, int from,
static void __attribute__ ((__noreturn__)) static void __attribute__ ((__noreturn__))
usage(FILE * out) usage(FILE * out)
{ {
fputs(USAGE_HEADER, out);
fprintf(out, fprintf(out,
"\nUsage: %s [options]\n" " %s [options]\n", program_invocation_short_name);
"\nOptions:\n", program_invocation_short_name); fputs(USAGE_OPTIONS, out);
fprintf(out, fputs(_(" -h, --no-header do not print header\n"), out);
" -h, --no-header do not print header\n" fputs(_(" -u, --no-current ignore current process username\n"), out);
" -u, --no-current ignore current process username\n" fputs(_(" -s, --short short format\n"), out);
" -s, --short short format\n" fputs(_(" -f, --from show remote hostname field\n"), out);
" -f, --from show remote hostname field\n" fputs(_(" -o, --old-style old style output\n"), out);
" -o, --old-style old style output\n" fputs(USAGE_SEPARATOR, out);
" --help display this help text\n" fputs(_(" --help display this help and exit\n"), out);
" -V, --version display version information and exit\n"); fputs(USAGE_VERSION, out);
fprintf(out, "\nFor more information see w(1).\n"); fprintf(out, USAGE_MAN_TAIL("w(1)"));
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS); exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
} }
@ -358,7 +363,7 @@ int main(int argc, char **argv)
from = !from; from = !from;
break; break;
case 'V': case 'V':
display_version(); printf(PROCPS_NG_VERSION);
exit(0); exit(0);
case 'u': case 'u':
ignoreuser = 1; ignoreuser = 1;
@ -380,7 +385,7 @@ int main(int argc, char **argv)
userlen = atoi(env_var); userlen = atoi(env_var);
if (userlen < 8 || userlen > USERSZ) { if (userlen < 8 || userlen > USERSZ) {
warnx warnx
("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;
} }
@ -390,7 +395,7 @@ int main(int argc, char **argv)
fromlen = atoi(env_var); fromlen = atoi(env_var);
if (fromlen < 8 || fromlen > HOSTSZ) { if (fromlen < 8 || fromlen > HOSTSZ) {
warnx warnx
("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;
} }
@ -402,11 +407,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); errx(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); warnx(_("warning: screen width %d suboptimal"), win.ws_col);
procs = readproctab(PROC_FILLCOM | PROC_FILLUSR | PROC_FILLSTAT); procs = readproctab(PROC_FILLCOM | PROC_FILLUSR | PROC_FILLSTAT);