watch: add gettext support
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
76841eda26
commit
f90e436b88
63
watch.c
63
watch.c
@ -13,7 +13,9 @@
|
|||||||
* Unicode Support added by Jarrod Lowe <procps@rrod.net> in 2009.
|
* Unicode Support added by Jarrod Lowe <procps@rrod.net> in 2009.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "c.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "nls.h"
|
||||||
#include "proc/procps.h"
|
#include "proc/procps.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -32,15 +34,15 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#ifdef WITH_WATCH8BIT
|
#ifdef WITH_WATCH8BIT
|
||||||
#include <wchar.h>
|
# include <wchar.h>
|
||||||
#include <ncursesw/ncurses.h>
|
# include <ncursesw/ncurses.h>
|
||||||
#else
|
#else
|
||||||
#include <ncurses.h>
|
# include <ncurses.h>
|
||||||
#endif /* WITH_WATCH8BIT */
|
#endif /* WITH_WATCH8BIT */
|
||||||
|
|
||||||
#ifdef FORCE_8BIT
|
#ifdef FORCE_8BIT
|
||||||
#undef isprint
|
# undef isprint
|
||||||
#define isprint(x) ( (x>=' '&&x<='~') || (x>=0xa0) )
|
# define isprint(x) ( (x>=' '&&x<='~') || (x>=0xa0) )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int curses_started = 0;
|
static int curses_started = 0;
|
||||||
@ -56,21 +58,24 @@ static int precise_timekeeping = 0;
|
|||||||
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] command\n"
|
" %s [options] command\n", program_invocation_short_name);
|
||||||
"\nOptions:\n", program_invocation_short_name);
|
fputs(USAGE_OPTIONS, out);
|
||||||
fprintf(out,
|
fputs(_(" -b, --beep beep if command has a non-zero exit\n"), out);
|
||||||
" -b, --beep beep if command has a non-zero exit\n"
|
fputs(_(" -c, --color interpret ANSI color sequences\n"), out);
|
||||||
" -c, --color interpret ANSI color sequences\n"
|
fputs(_(" -e, --errexit exit if command has a non-zero exit\n"), out);
|
||||||
" -e, --errexit exit if command has a non-zero exit\n"
|
fputs(_(" -f, --differences highlight changes between updates\n"), out);
|
||||||
" -f, --differences highlight changes between updates\n"
|
fputs(_(" -n, --interval <secs> seconds to wait between updates\n"), out);
|
||||||
" -n, --interval <secs> seconds to wait between updates\n"
|
fputs(_(" -p, --precise attempt run command in precise intervals\n"), out);
|
||||||
" -p, --precise attempt run command in precise intervals\n"
|
fputs(_(" -t, --no-title turn off header\n"), out);
|
||||||
" -t, --no-title turn off header\n"
|
fputs(_(" -x, --exec pass command to exec instead of \"sh -c\"\n"), out);
|
||||||
" -x, --exec pass command to exec instead of \"sh -c\"\n"
|
fputs(_(" -h, --help display this help text\n"), out);
|
||||||
" -h, --help display this help text\n"
|
fputs(_(" -v, --version display version information and exit\n"), out);
|
||||||
" -v, --version display version information and exit\n");
|
fputs(USAGE_SEPARATOR, out);
|
||||||
fprintf(out, "\nFor more information see watch(1).\n");
|
fputs(USAGE_HELP, out);
|
||||||
|
fputs(_(" -v, --version output version information and exit\n"), out);
|
||||||
|
fprintf(out, USAGE_MAN_TAIL("watch(1)"));
|
||||||
|
|
||||||
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
|
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
@ -347,7 +352,7 @@ int main(int argc, char *argv[])
|
|||||||
usage(stdout);
|
usage(stdout);
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
display_version();
|
printf(PROCPS_NG_VERSION);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
default:
|
default:
|
||||||
usage(stderr);
|
usage(stderr);
|
||||||
@ -381,13 +386,13 @@ int main(int argc, char *argv[])
|
|||||||
/*mbstowcs(NULL, NULL, 0); */
|
/*mbstowcs(NULL, NULL, 0); */
|
||||||
wcommand_characters = mbstowcs(NULL, command, 0);
|
wcommand_characters = mbstowcs(NULL, command, 0);
|
||||||
if (wcommand_characters < 0) {
|
if (wcommand_characters < 0) {
|
||||||
fprintf(stderr, "Unicode Handling Error\n");
|
fprintf(stderr, _("Unicode Handling Error\n"));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
wcommand =
|
wcommand =
|
||||||
(wchar_t *) malloc((wcommand_characters + 1) * sizeof(wcommand));
|
(wchar_t *) malloc((wcommand_characters + 1) * sizeof(wcommand));
|
||||||
if (wcommand == NULL) {
|
if (wcommand == NULL) {
|
||||||
fprintf(stderr, "Unicode Handling Error (malloc)\n");
|
fprintf(stderr, _("Unicode Handling Error (malloc)\n"));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
mbstowcs(wcommand, command, wcommand_characters + 1);
|
mbstowcs(wcommand, command, wcommand_characters + 1);
|
||||||
@ -445,7 +450,7 @@ int main(int argc, char *argv[])
|
|||||||
* justify time, clipping all to fit window
|
* justify time, clipping all to fit window
|
||||||
* width
|
* width
|
||||||
*/
|
*/
|
||||||
int hlen = asprintf(&header, "Every %.1fs: ", interval);
|
int hlen = asprintf(&header, _("Every %.1fs: "), interval);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the rules:
|
* the rules:
|
||||||
@ -515,7 +520,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* allocate pipes */
|
/* allocate pipes */
|
||||||
if (pipe(pipefd) < 0)
|
if (pipe(pipefd) < 0)
|
||||||
err(7, "pipe");
|
err(7, _("pipe"));
|
||||||
|
|
||||||
/* flush stdout and stderr, since we're about to do fd stuff */
|
/* flush stdout and stderr, since we're about to do fd stuff */
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@ -525,18 +530,18 @@ int main(int argc, char *argv[])
|
|||||||
child = fork();
|
child = fork();
|
||||||
|
|
||||||
if (child < 0) { /* fork error */
|
if (child < 0) { /* fork error */
|
||||||
err(2, "fork");
|
err(2, _("fork"));
|
||||||
} else if (child == 0) { /* in child */
|
} else if (child == 0) { /* in child */
|
||||||
close(pipefd[0]); /* child doesn't need read side of pipe */
|
close(pipefd[0]); /* child doesn't need read side of pipe */
|
||||||
close(1); /* prepare to replace stdout with pipe */
|
close(1); /* prepare to replace stdout with pipe */
|
||||||
if (dup2(pipefd[1], 1) < 0) { /* replace stdout with write side of pipe */
|
if (dup2(pipefd[1], 1) < 0) { /* replace stdout with write side of pipe */
|
||||||
err(3, "dup2");
|
err(3, _("dup2"));
|
||||||
}
|
}
|
||||||
dup2(1, 2); /* stderr should default to stdout */
|
dup2(1, 2); /* stderr should default to stdout */
|
||||||
|
|
||||||
if (option_exec) { /* pass command to exec instead of system */
|
if (option_exec) { /* pass command to exec instead of system */
|
||||||
if (execvp(command_argv[0], command_argv) == -1) {
|
if (execvp(command_argv[0], command_argv) == -1) {
|
||||||
err(4, "exec");
|
err(4, _("exec"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
status = system(command); /* watch manpage promises sh quoting */
|
status = system(command); /* watch manpage promises sh quoting */
|
||||||
@ -554,7 +559,7 @@ int main(int argc, char *argv[])
|
|||||||
/* otherwise, we're in parent */
|
/* otherwise, we're in parent */
|
||||||
close(pipefd[1]); /* close write side of pipe */
|
close(pipefd[1]); /* close write side of pipe */
|
||||||
if ((p = fdopen(pipefd[0], "r")) == NULL)
|
if ((p = fdopen(pipefd[0], "r")) == NULL)
|
||||||
err(5, "fdopen");
|
err(5, _("fdopen"));
|
||||||
|
|
||||||
for (y = show_title; y < height; y++) {
|
for (y = show_title; y < height; y++) {
|
||||||
int eolseen = 0, tabpending = 0;
|
int eolseen = 0, tabpending = 0;
|
||||||
@ -677,7 +682,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* harvest child process and get status, propagated from command */
|
/* harvest child process and get status, propagated from command */
|
||||||
if (waitpid(child, &status, 0) < 0)
|
if (waitpid(child, &status, 0) < 0)
|
||||||
err(8, "waitpid");
|
err(8, _("waitpid"));
|
||||||
|
|
||||||
/* if child process exited in error, beep if option_beep is set */
|
/* if child process exited in error, beep if option_beep is set */
|
||||||
if ((!WIFEXITED(status) || WEXITSTATUS(status))) {
|
if ((!WIFEXITED(status) || WEXITSTATUS(status))) {
|
||||||
|
Loading…
Reference in New Issue
Block a user