pgrep: add gettext support

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2011-10-09 01:29:43 +02:00
parent 10db451038
commit ad6054b372

79
pgrep.c
View File

@ -28,6 +28,8 @@
#include <errno.h> #include <errno.h>
#include <getopt.h> #include <getopt.h>
#include "c.h"
#include "nls.h"
#include "proc/readproc.h" #include "proc/readproc.h"
#include "proc/sig.h" #include "proc/sig.h"
#include "proc/devname.h" #include "proc/devname.h"
@ -77,36 +79,35 @@ static int __attribute__ ((__noreturn__)) usage(int opt)
int err = (opt == '?'); int err = (opt == '?');
FILE *fp = err ? stderr : stdout; FILE *fp = err ? stderr : stdout;
fprintf(fp, fputs(USAGE_HEADER, fp);
"\nUsage: %s [options] <pattern>\n" "\nOptions:\n", progname); fprintf(fp, _(" %s [options] <pattern>\n"), progname);
fputs(USAGE_OPTIONS, fp);
if (i_am_pkill == 0) if (i_am_pkill == 0) {
fprintf(fp, fputs(_(" -c, --count count of matching processes\n"), fp);
" -c, --count count of matching processes\n" fputs(_(" -d, --delimeter <string> update delay in seconds\n"), fp);
" -d, --delimeter <string> update delay in seconds\n" fputs(_(" -l, --list-name list PID and process name\n"), fp);
" -l, --list-name list PID and process name\n"); }
if (i_am_pkill == 1) if (i_am_pkill == 1) {
fprintf(fp, fputs(_(" -<sig>, --signal <sig> signal to send (either number or name)\n"), fp);
" -<sig>, --signal <sig> signal to send (either number or name)\n"); }
fputs(_(" -f, --full use full process name to match\n"), fp);
fprintf(fp, fputs(_(" -g, --pgroup <id,...> match listed process group IDs\n"), fp);
" -f, --full use full process name to match\n" fputs(_(" -G, --group <gid,...> match real group IDs\n"), fp);
" -g, --pgroup <id,...> match listed process group IDs\n" fputs(_(" -n, --newest select most recently started\n"), fp);
" -G, --group <gid,...> match real group IDs\n" fputs(_(" -o, --oldest select least recently started\n"), fp);
" -n, --newest select most recently started\n" fputs(_(" -P, --parent <ppid,...> match only childs of given parent\n"), fp);
" -o, --oldest select least recently started\n" fputs(_(" -s, --session <sid,...> match session IDs\n"), fp);
" -P, --parent <ppid,...> match only childs of given parent\n" fputs(_(" -t, --terminal <tty,...> match by controlling terminal\n"), fp);
" -s, --session <sid,...> match session IDs\n" fputs(_(" -u, --euid <id,...> match by effective IDs\n"), fp);
" -t, --terminal <tty,...> match by controlling terminal\n" fputs(_(" -U, --uid <id,...> match by real IDs\n"), fp);
" -u, --euid <id,...> match by effective IDs\n" fputs(_(" -v, --inverse negates the matching\n"), fp);
" -U, --uid <id,...> match by real IDs\n" fputs(_(" -x, --exact match exectly with command name\n"), fp);
" -v, --inverse negates the matching\n" fputs(_(" -F, --pidfile <file> read PIDs from file\n"), fp);
" -x, --exact match exectly with command name\n" fputs(_(" -L, --logpidfile fail if PID file is not locked\n"), fp);
" -F, --pidfile <file> read PIDs from file\n" fputs(USAGE_SEPARATOR, fp);
" -L, --logpidfile fail if PID file is not locked\n" fputs(USAGE_HELP, fp);
" -h, --help display this help text\n" fputs(USAGE_VERSION, fp);
" -V, --version display version information and exit\n"); fprintf(fp, USAGE_MAN_TAIL("pgrep(1)"));
fprintf(fp, "\nFor more information see %s(1).\n", progname);
exit(fp == stderr ? EXIT_FAILURE : EXIT_SUCCESS); 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); pwd = getpwnam (name);
if (pwd == NULL) { if (pwd == NULL) {
fprintf (stderr, "%s: invalid user name: %s\n", fprintf (stderr, _("%s: invalid user name: %s\n"),
progname, name); progname, name);
return 0; return 0;
} }
@ -273,7 +274,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) {
fprintf (stderr, "%s: invalid group name: %s\n", fprintf (stderr, _("%s: invalid group name: %s\n"),
progname, name); progname, name);
return 0; 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) static int conv_pgrp (const char *restrict name, union el *restrict e)
{ {
if (! strict_atol (name, &e->num)) { if (! strict_atol (name, &e->num)) {
fprintf (stderr, "%s: invalid process group: %s\n", fprintf (stderr, _("%s: invalid process group: %s\n"),
progname, name); progname, name);
return 0; 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) static int conv_sid (const char *restrict name, union el *restrict e)
{ {
if (! strict_atol (name, &e->num)) { if (! strict_atol (name, &e->num)) {
fprintf (stderr, "%s: invalid session id: %s\n", fprintf (stderr, _("%s: invalid session id: %s\n"),
progname, name); progname, name);
return 0; 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) static int conv_num (const char *restrict name, union el *restrict e)
{ {
if (! strict_atol (name, &e->num)) { if (! strict_atol (name, &e->num)) {
fprintf (stderr, "%s: not a number: %s\n", fprintf (stderr, _("%s: not a number: %s\n"),
progname, name); progname, name);
return 0; return 0;
} }
@ -667,7 +668,7 @@ static void parse_opts (int argc, char **argv)
++criteria_count; ++criteria_count;
break; break;
case 'V': case 'V':
fprintf(stdout, "%s (%s)\n", progname, procps_version); printf(PROCPS_NG_VERSION);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
// case 'c': // Solaris: match by contract ID // case 'c': // Solaris: match by contract ID
// break; // break;
@ -747,14 +748,14 @@ static void parse_opts (int argc, char **argv)
} }
if(opt_lock && !opt_pidfile){ 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); usage(0);
} }
if(opt_pidfile){ if(opt_pidfile){
opt_pid = read_pidfile(); opt_pid = read_pidfile();
if(!opt_pid){ if(!opt_pid){
fprintf(stderr, "%s: pidfile not valid\n",progname); fprintf(stderr, _("%s: pidfile not valid\n"),progname);
usage(0); usage(0);
} }
} }
@ -764,7 +765,7 @@ static void parse_opts (int argc, char **argv)
else if (argc - optind > 1) else if (argc - optind > 1)
usage (0); usage (0);
else if (criteria_count == 0) { else if (criteria_count == 0) {
fprintf (stderr, "%s: No matching criteria specified\n", fprintf (stderr, _("%s: No matching criteria specified\n"),
progname); progname);
usage (0); usage (0);
} }