free: add gettext support

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2011-10-08 22:24:06 +02:00
parent 43318fd0c2
commit 10db451038

68
free.c
View File

@ -13,8 +13,10 @@
*/ */
#include "proc/sysinfo.h" #include "proc/sysinfo.h"
#include "proc/version.h" #include "proc/version.h"
#include "c.h"
#include "nls.h"
#include <errno.h> #include <errno.h>
#include <err.h>
#include <limits.h> #include <limits.h>
#include <ctype.h> #include <ctype.h>
#include <getopt.h> #include <getopt.h>
@ -48,24 +50,26 @@ static const char *scale_size(unsigned long size, int flags, struct commandline_
static void __attribute__ ((__noreturn__)) static void __attribute__ ((__noreturn__))
usage(FILE * out) usage(FILE * out)
{ {
fprintf(out, "\nUsage: %s [options]\n" "\nOptions:\n", program_invocation_short_name); fputs(USAGE_HEADER, out);
fprintf(out, fprintf(out,
" -b, --bytes show output in bytes\n" _(" %s [options]\n"), program_invocation_short_name);
" -k, --kilo show output in kilobytes\n" fputs(USAGE_OPTIONS, out);
" -m, --mega show output in megabytes\n" fputs(_(" -b, --bytes show output in bytes\n"), out);
" -g, --giga show output in gigabytes\n" fputs(_(" -k, --kilo show output in kilobytes\n"), out);
" --tera show output in terabytes\n" fputs(_(" -m, --mega show output in megabytes\n"), out);
" -h, --human show human readable output\n" fputs(_(" -g, --giga show output in gigabytes\n"), out);
" --si use powers of 1000 not 1024\n" fputs(_(" --tera show output in terabytes\n"), out);
" -l, --lohi show detailed low and high memory statistics\n" fputs(_(" -h, --human show human readable output\n"), out);
" -o, --old use old format (no -/+buffers/cache line)\n" fputs(_(" --si use powers of 1000 not 1024\n"), out);
" -t, --total show total for RAM + swap\n" fputs(_(" -l, --lohi show detailed low and high memory statistics\n"), out);
" -s N, --seconds N repeat printing every N seconds\n" fputs(_(" -o, --old use old format (no -/+buffers/cache line)\n"), out);
" -c N, --count N repeat printing N times\n"); fputs(_(" -t, --total show total for RAM + swap\n"), out);
fprintf(out, fputs(_(" -s N, --seconds N repeat printing every N seconds\n"), out);
" --help display this help text\n" fputs(_(" -c N, --count N repeat printing N times\n"), out);
" -V, --version display version information and exit\n"); fputs(USAGE_SEPARATOR, out);
fprintf(out, "\nFor more information see free(1).\n"); fputs(_(" --help display this help text\n"), out);
fputs(USAGE_VERSION, out);
fprintf(out, USAGE_MAN_TAIL("free(1)"));
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS); exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
} }
@ -79,7 +83,7 @@ double power(unsigned int base, unsigned int expo)
static const char *scale_size(unsigned long size, int flags, struct commandline_arguments args) static const char *scale_size(unsigned long size, int flags, struct commandline_arguments args)
{ {
static char nextup[] = { 'B', 'K', 'M', 'G', 'T', 0 }; static char nextup[] = { 'B', 'K', 'M', 'G', 'T', 0 };
static char buf[SIZE_MAX]; static char buf[BUFSIZ];
int i; int i;
char *up; char *up;
float base; float base;
@ -236,23 +240,23 @@ 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); errx(EXIT_FAILURE, _("seconds argument `%s' failed"), optarg);
if (args.repeat_interval < 1) if (args.repeat_interval < 1)
errx(EXIT_FAILURE, errx(EXIT_FAILURE,
"seconds argument `%s' is not positive number", optarg); _("seconds argument `%s' is not positive number"), optarg);
break; break;
case 'c': case 'c':
flags |= FREE_REPEAT; flags |= FREE_REPEAT;
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); errx(EXIT_FAILURE, _("count argument `%s' failed"), optarg);
break; break;
case HELP_OPTION: case HELP_OPTION:
usage(stdout); usage(stdout);
case 'V': case 'V':
display_version(); printf(PROCPS_NG_VERSION);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
default: default:
usage(stderr); usage(stderr);
@ -261,10 +265,10 @@ int main(int argc, char **argv)
do { do {
meminfo(); meminfo();
printf("%7s %10s %10s %10s %10s %10s %10s\n",
printf "", _("total"), _("used"), _("free"), _("shared"),
(" total used free shared buffers cached\n"); _("buffers"), _("cached"));
printf("%-7s", "Mem:"); printf("%-7s", _("Mem:"));
printf(" %10s", scale_size(kb_main_total, flags, args)); printf(" %10s", scale_size(kb_main_total, flags, args));
printf(" %10s", scale_size(kb_main_used, flags, args)); printf(" %10s", scale_size(kb_main_used, flags, args));
printf(" %10s", scale_size(kb_main_free, flags, args)); printf(" %10s", scale_size(kb_main_free, flags, args));
@ -279,13 +283,13 @@ int main(int argc, char **argv)
* to print the high info, even if it is zero. * to print the high info, even if it is zero.
*/ */
if (flags & FREE_LOHI) { if (flags & FREE_LOHI) {
printf("%-7s", "Low:"); printf("%-7s", _("Low:"));
printf(" %10s", scale_size(kb_low_total, flags, args)); printf(" %10s", scale_size(kb_low_total, flags, args));
printf(" %10s", scale_size(kb_low_total - kb_low_free, flags, args)); printf(" %10s", scale_size(kb_low_total - kb_low_free, flags, args));
printf(" %10s", scale_size(kb_low_free, flags, args)); printf(" %10s", scale_size(kb_low_free, flags, args));
printf("\n"); printf("\n");
printf("%-7s", "High:"); printf("%-7s", _("High:"));
printf(" %10s", scale_size(kb_high_total, flags, args)); printf(" %10s", scale_size(kb_high_total, flags, args));
printf(" %10s", scale_size(kb_high_total - kb_high_free, flags, args)); printf(" %10s", scale_size(kb_high_total - kb_high_free, flags, args));
printf(" %10s", scale_size(kb_high_free, flags, args)); printf(" %10s", scale_size(kb_high_free, flags, args));
@ -294,21 +298,21 @@ int main(int argc, char **argv)
if (!(flags & FREE_OLDFMT)) { if (!(flags & FREE_OLDFMT)) {
unsigned KLONG buffers_plus_cached = kb_main_buffers + kb_main_cached; unsigned KLONG buffers_plus_cached = kb_main_buffers + kb_main_cached;
printf("-/+ buffers/cache:"); printf(_("-/+ buffers/cache:"));
printf(" %10s", printf(" %10s",
scale_size(kb_main_used - buffers_plus_cached, flags, args)); scale_size(kb_main_used - buffers_plus_cached, flags, args));
printf(" %10s", printf(" %10s",
scale_size(kb_main_free + buffers_plus_cached, flags, args)); scale_size(kb_main_free + buffers_plus_cached, flags, args));
printf("\n"); printf("\n");
} }
printf("%-7s", "Swap:"); printf("%-7s", _("Swap:"));
printf(" %10s", scale_size(kb_swap_total, flags, args)); printf(" %10s", scale_size(kb_swap_total, flags, args));
printf(" %10s", scale_size(kb_swap_used, flags, args)); printf(" %10s", scale_size(kb_swap_used, flags, args));
printf(" %10s", scale_size(kb_swap_free, flags, args)); printf(" %10s", scale_size(kb_swap_free, flags, args));
printf("\n"); printf("\n");
if (flags & FREE_TOTAL) { if (flags & FREE_TOTAL) {
printf("%-7s", "Total:"); printf("%-7s", _("Total:"));
printf(" %10s", scale_size(kb_main_total + kb_swap_total, flags, args)); printf(" %10s", scale_size(kb_main_total + kb_swap_total, flags, args));
printf(" %10s", scale_size(kb_main_used + kb_swap_used, flags, args)); printf(" %10s", scale_size(kb_main_used + kb_swap_used, flags, args));
printf(" %10s", scale_size(kb_main_free + kb_swap_free, flags, args)); printf(" %10s", scale_size(kb_main_free + kb_swap_free, flags, args));