From ad6054b372c28703e0cf7621da65a855fd1a1ef9 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 9 Oct 2011 01:29:43 +0200 Subject: [PATCH] pgrep: add gettext support Signed-off-by: Sami Kerola --- pgrep.c | 79 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/pgrep.c b/pgrep.c index 68f0edeb..5fea54d8 100644 --- a/pgrep.c +++ b/pgrep.c @@ -28,6 +28,8 @@ #include #include +#include "c.h" +#include "nls.h" #include "proc/readproc.h" #include "proc/sig.h" #include "proc/devname.h" @@ -77,36 +79,35 @@ static int __attribute__ ((__noreturn__)) usage(int opt) int err = (opt == '?'); FILE *fp = err ? stderr : stdout; - fprintf(fp, - "\nUsage: %s [options] \n" "\nOptions:\n", progname); - - if (i_am_pkill == 0) - fprintf(fp, - " -c, --count count of matching processes\n" - " -d, --delimeter update delay in seconds\n" - " -l, --list-name list PID and process name\n"); - if (i_am_pkill == 1) - fprintf(fp, - " -, --signal signal to send (either number or name)\n"); - - fprintf(fp, - " -f, --full use full process name to match\n" - " -g, --pgroup match listed process group IDs\n" - " -G, --group match real group IDs\n" - " -n, --newest select most recently started\n" - " -o, --oldest select least recently started\n" - " -P, --parent match only childs of given parent\n" - " -s, --session match session IDs\n" - " -t, --terminal match by controlling terminal\n" - " -u, --euid match by effective IDs\n" - " -U, --uid match by real IDs\n" - " -v, --inverse negates the matching\n" - " -x, --exact match exectly with command name\n" - " -F, --pidfile read PIDs from file\n" - " -L, --logpidfile fail if PID file is not locked\n" - " -h, --help display this help text\n" - " -V, --version display version information and exit\n"); - fprintf(fp, "\nFor more information see %s(1).\n", progname); + fputs(USAGE_HEADER, fp); + fprintf(fp, _(" %s [options] \n"), progname); + fputs(USAGE_OPTIONS, fp); + if (i_am_pkill == 0) { + fputs(_(" -c, --count count of matching processes\n"), fp); + fputs(_(" -d, --delimeter update delay in seconds\n"), fp); + fputs(_(" -l, --list-name list PID and process name\n"), fp); + } + if (i_am_pkill == 1) { + fputs(_(" -, --signal signal to send (either number or name)\n"), fp); + } + fputs(_(" -f, --full use full process name to match\n"), fp); + fputs(_(" -g, --pgroup match listed process group IDs\n"), fp); + fputs(_(" -G, --group match real group IDs\n"), fp); + fputs(_(" -n, --newest select most recently started\n"), fp); + fputs(_(" -o, --oldest select least recently started\n"), fp); + fputs(_(" -P, --parent match only childs of given parent\n"), fp); + fputs(_(" -s, --session match session IDs\n"), fp); + fputs(_(" -t, --terminal match by controlling terminal\n"), fp); + fputs(_(" -u, --euid match by effective IDs\n"), fp); + fputs(_(" -U, --uid match by real IDs\n"), fp); + fputs(_(" -v, --inverse negates the matching\n"), fp); + fputs(_(" -x, --exact match exectly with command name\n"), fp); + fputs(_(" -F, --pidfile read PIDs from file\n"), fp); + fputs(_(" -L, --logpidfile fail if PID file is not locked\n"), fp); + fputs(USAGE_SEPARATOR, fp); + fputs(USAGE_HELP, fp); + fputs(USAGE_VERSION, fp); + fprintf(fp, USAGE_MAN_TAIL("pgrep(1)")); exit(fp == stderr ? EXIT_FAILURE : EXIT_SUCCESS); } @@ -255,7 +256,7 @@ static int conv_uid (const char *restrict name, union el *restrict e) pwd = getpwnam (name); if (pwd == NULL) { - fprintf (stderr, "%s: invalid user name: %s\n", + fprintf (stderr, _("%s: invalid user name: %s\n"), progname, name); return 0; } @@ -273,7 +274,7 @@ static int conv_gid (const char *restrict name, union el *restrict e) grp = getgrnam (name); if (grp == NULL) { - fprintf (stderr, "%s: invalid group name: %s\n", + fprintf (stderr, _("%s: invalid group name: %s\n"), progname, name); return 0; } @@ -285,7 +286,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) { if (! strict_atol (name, &e->num)) { - fprintf (stderr, "%s: invalid process group: %s\n", + fprintf (stderr, _("%s: invalid process group: %s\n"), progname, name); return 0; } @@ -298,7 +299,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) { if (! strict_atol (name, &e->num)) { - fprintf (stderr, "%s: invalid session id: %s\n", + fprintf (stderr, _("%s: invalid session id: %s\n"), progname, name); return 0; } @@ -311,7 +312,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) { if (! strict_atol (name, &e->num)) { - fprintf (stderr, "%s: not a number: %s\n", + fprintf (stderr, _("%s: not a number: %s\n"), progname, name); return 0; } @@ -667,7 +668,7 @@ static void parse_opts (int argc, char **argv) ++criteria_count; break; case 'V': - fprintf(stdout, "%s (%s)\n", progname, procps_version); + printf(PROCPS_NG_VERSION); exit(EXIT_SUCCESS); // case 'c': // Solaris: match by contract ID // break; @@ -747,14 +748,14 @@ static void parse_opts (int argc, char **argv) } if(opt_lock && !opt_pidfile){ - fprintf(stderr, "%s: -L without -F makes no sense\n",progname); + fprintf(stderr, _("%s: -L without -F makes no sense\n"),progname); usage(0); } if(opt_pidfile){ opt_pid = read_pidfile(); if(!opt_pid){ - fprintf(stderr, "%s: pidfile not valid\n",progname); + fprintf(stderr, _("%s: pidfile not valid\n"),progname); usage(0); } } @@ -764,7 +765,7 @@ static void parse_opts (int argc, char **argv) else if (argc - optind > 1) usage (0); else if (criteria_count == 0) { - fprintf (stderr, "%s: No matching criteria specified\n", + fprintf (stderr, _("%s: No matching criteria specified\n"), progname); usage (0); } -- 2.40.0