top: provide extensive, generalized nls support

Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2011-10-11 14:02:59 -05:00 committed by Craig Small
parent 35cf8a4adc
commit 32a9adbc13
11 changed files with 925 additions and 363 deletions

4
.gitignore vendored
View File

@ -46,7 +46,9 @@ snice
stamp-h1
sysctl
tload
top
top/Makefile
top/Makefile.in
top/top
uptime
vmstat
w

View File

@ -7,7 +7,8 @@ SUBDIRS = \
po \
proc \
ps \
testsuite
testsuite \
top
AM_CFLAGS = -Iproc
AM_LDFLAGS = ./proc/libprocfs.la
@ -51,16 +52,12 @@ endif
if WITH_NCURSES
usrbin_exec_PROGRAMS += \
slabtop \
top \
watch
top_SOURCES = top.c top.h
dist_man_MANS += \
slabtop.1 \
top.1 \
watch.1
slabtop_SOURCES = slabtop.c $(top_srcdir)/lib/strutils.c
slabtop_LDADD = @NCURSES_LIBS@
top_LDADD = @NCURSES_LIBS@
watch_SOURCES = watch.c $(top_srcdir)/lib/strutils.c
watch_LDADD = @NCURSES_LIBS@
endif
@ -84,5 +81,4 @@ EXTRA_DIST = \
procpsngdir = $(docdir)
dist_procpsng_DATA = \
BUGS \
FAQ \
README.top
FAQ

View File

@ -10,7 +10,7 @@ THEDIR=$(pwd)
cd ${SRCDIR}
DIE=0
test -f top.c || {
test -f free.c || {
echo "You must run this script in the top-level procps-ng directory"
DIE=1
}

View File

@ -7,7 +7,7 @@ AC_INIT([procps-ng],
[3.3.2],
[procps@freelists.org],,[http://gitorious.org/procps])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([top.c])
AC_CONFIG_SRCDIR([free.c])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
@ -196,6 +196,7 @@ AC_CONFIG_FILES([
proc/libprocfs.pc
ps/Makefile
testsuite/Makefile
top/Makefile
])
AC_OUTPUT

26
top/Makefile.am Normal file
View File

@ -0,0 +1,26 @@
AM_CPPFLAGS = -include $(top_builddir)/config.h
AM_CFLAGS = -I../proc -I../include
AM_LDFLAGS = ../proc/libprocfs.la
if WITH_NCURSES
usrbin_exec_PROGRAMS = \
top
top_SOURCES = \
top.h \
top.c \
top_nls.h \
top_nls.c
dist_man_MANS = \
top.1
top_LDADD = @NCURSES_LIBS@
endif
EXTRA_DIST =
procpsngdir = $(docdir)
dist_procpsng_DATA = \
README.top

View File

@ -325,4 +325,3 @@ notes:
displayed due to limited screen width
c only in a full screen xterm window could all common fields
actually be displayed

View File

File diff suppressed because it is too large Load Diff

View File

@ -15,6 +15,7 @@
/* For contributions to this program, the author wishes to thank:
* Craig Small, <csmall@small.dropbear.id.au>
* Albert D. Cahalan, <albert@users.sf.net>
* Sami Kerola, <kerolasa@iki.fi>
*/
#ifndef _Itop
#define _Itop
@ -47,14 +48,20 @@
/* The following convention is used to identify those areas where
adaptations for hotplugging are to be found ...
*** hotplug_acclimated ***
( hopefully libproc will also be supportive of our efforts ) */
( hopefully libproc will also be supportive of our efforts ) */
/* And there are still some of these lurking here and there...
FIXME - blah, blah... */
FIXME - blah, blah... */
/* For introducing inaugural cgroup support, thanks to:
Jan Gorig <jgorig@redhat.com> - April, 2011 */
Jan Gorig <jgorig@redhat.com> - April, 2011 */
/* For the motivation and path to nls support, thanks to:
Sami Kerola, <kerolasa@iki.fi> */
/* There are still some short strings that may yet be candidates
for nls support inclusion. They're identified with:
// nls_maybe */
#ifdef PRETEND2_5_X
#define linux_version_code LINUX_VERSION(2,5,43)
@ -436,6 +443,8 @@ typedef struct WIN_t {
/*###### Display Support *Data* ########################################*/
/*###### Some Display Support *Data* ###################################*/
/* ( see module top_nls.c for the nls translatable data ) */
/* Configuration files support */
#define SYS_RCFILESPEC "/etc/toprc"
@ -481,124 +490,7 @@ typedef struct WIN_t {
/* Summary Lines specially formatted string(s) --
see 'show_special' for syntax details + other cautions. */
#define LOADAV_line "%s -%s\n"
#define LOADAV_line_alt "%s~6 -%s\n"
#define STATES_line1 "%s:~3" \
" %3u ~2total,~3 %3u ~2running,~3 %3u ~2sleeping,~3 %3u ~2stopped,~3 %3u ~2zombie~3\n"
#define STATES_line2x4 "%%%s~3" \
" %#5.1f ~2user,~3 %#5.1f ~2system,~3 %#5.1f ~2nice,~3 %#5.1f ~2idle~3\n"
/* These are the STATES_line evolutions
lnx 2.5.x, procps-3.0.5 : IO-wait = i/o wait time
lnx 2.6.x, procps-3.1.12 : IO-wait now wa, hi = hard irq, si = soft irq
lnx 2.7.x, procps-3.2.7 : st = steal time */
#define STATES_line2x5 "%%%s~3" \
" %#5.1f ~2user,~3 %#5.1f ~2system,~3 %#5.1f ~2nice,~3 %#5.1f ~2idle,~3 %#5.1f ~2IO-wait~3\n"
#define STATES_line2x6 "%%%s~3" \
" %#5.1f ~2us,~3 %#5.1f ~2sy,~3 %#5.1f ~2ni,~3 %#5.1f ~2id,~3 %#5.1f ~2wa,~3 %#5.1f ~2hi,~3 %#5.1f ~2si~3\n"
#define STATES_line2x7 "%%%s~3" \
"%#5.1f ~2us,~3%#5.1f ~2sy,~3%#5.1f ~2ni,~3%#5.1f ~2id,~3%#5.1f ~2wa,~3%#5.1f ~2hi,~3%#5.1f ~2si,~3%#5.1f ~2st~3\n"
#define MEMORY_twolines \
"%s Mem: ~3 %8lu ~2total,~3 %8lu ~2used,~3 %8lu ~2free,~3 %8lu ~2buffers~3\n" \
"%s Swap:~3 %8lu ~2total,~3 %8lu ~2used,~3 %8lu ~2free,~3 %8lu ~2cached~3\n"
/* Keyboard Help specially formatted string(s) --
see 'show_special' for syntax details + other cautions. */
#define KEYS_help \
"Help for Interactive Commands~2 - %s\n" \
"Window ~1%s~6: ~1Cumulative mode ~3%s~2. ~1System~6: ~1Delay ~3%.1f secs~2; ~1Secure mode ~3%s~2.\n" \
"\n" \
" Z~5,~1B~5 Global: '~1Z~2' change color mappings; '~1B~2' disable/enable bold\n" \
" l,t,m Toggle Summaries: '~1l~2' load avg; '~1t~2' task/cpu stats; '~1m~2' mem info\n" \
" 1,I Toggle SMP view: '~11~2' single/separate states; '~1I~2' Irix/Solaris mode\n" \
" f,F Manage Fields: add/remove; change order; select sort field\n" \
"\n" \
" L,&,<,> . Locate: '~1L~2'/'~1&~2' find/again; Move sort column: '~1<~2'/'~1>~2' left/right\n" \
" R,H,V . Toggle: '~1R~2' norm/rev sort; '~1H~2' show threads; '~1V~2' forest view\n" \
" c,i,S . Toggle: '~1c~2' cmd name/line; '~1i~2' idle tasks; '~1S~2' cumulative time\n" \
" x~5,~1y~5 . Toggle highlights: '~1x~2' sort field; '~1y~2' running tasks\n" \
" z~5,~1b~5 . Toggle: '~1z~2' color/mono; '~1b~2' bold/reverse (only if 'x' or 'y')\n" \
" u,U . Show: '~1u~2' effective user; '~1U~2' real, saved, file or effective user\n" \
" n or # . Set maximum tasks displayed\n" \
" C,... . Toggle scroll coordinates msg for: ~1up~2,~1down~2,~1left~2,right~2,~1home~2,~1end~2\n" \
"\n" \
"%s" \
" W Write configuration file\n" \
" q Quit\n" \
" ( commands shown with '.' require a ~1visible~2 task display ~1window~2 ) \n" \
"Press '~1h~2' or '~1?~2' for help with ~1Windows~2,\n" \
"any other key to continue " \
""
/* This guy goes into the help text (maybe) */
#define KEYS_help_unsecured \
" k,r Manipulate tasks: '~1k~2' kill; '~1r~2' renice\n" \
" d or s Set update interval\n" \
""
/* Fields Management specially formatted string(s) --
see 'show_special' for syntax details + other cautions */
#define FIELDS_heading \
"Fields Management~2 for window ~1%s~6, whose current sort field is ~1%s~2\n" \
" Navigate with Up/Dn, Right selects for move then <Enter> or Left commits,\n" \
" 'd' or <Space> toggles display, 's' sets sort. Use 'q' or <Esc> to end! " \
""
/* Colors Help specially formatted string(s) --
see 'show_special' for syntax details + other cautions. */
#define COLOR_help \
"Help for color mapping~2 - %s\n" \
"current window: ~1%s~6\n" \
"\n" \
" color - 04:25:44 up 8 days, 50 min, 7 users, load average:\n" \
" Tasks:~3 64 ~2total,~3 2 ~3running,~3 62 ~2sleeping,~3 0 ~2stopped,~3\n" \
" %%Cpu(s):~3 76.5 ~2user,~3 11.2 ~2system,~3 0.0 ~2nice,~3 12.3 ~2idle~3\n" \
" ~1 Nasty Message! ~4 -or- ~1Input Prompt~5\n" \
" ~1 PID TTY PR NI %%CPU TIME+ VIRT SWAP S COMMAND ~6\n" \
" 17284 ~8pts/2 ~7 8 0 0.0 0:00.75 1380 0 S /bin/bash ~8\n" \
" ~1 8601 pts/1 7 -10 0.4 0:00.03 916 0 R color -b -z~7\n" \
" 11005 ~8? ~7 9 0 0.0 0:02.50 2852 1008 S amor -sessi~8\n" \
" available toggles: ~1B~2 =disable bold globally (~1%s~2),\n" \
" ~1z~2 =color/mono (~1%s~2), ~1b~2 =tasks \"bold\"/reverse (~1%s~2)\n" \
"\n" \
"Select ~1target~2 as upper case letter:\n" \
" S~2 = Summary Data,~1 M~2 = Messages/Prompts,\n" \
" H~2 = Column Heads,~1 T~2 = Task Information\n" \
"Select ~1color~2 as number:\n" \
" 0~2 = black,~1 1~2 = red, ~1 2~2 = green,~1 3~2 = yellow,\n" \
" 4~2 = blue, ~1 5~2 = magenta,~1 6~2 = cyan, ~1 7~2 = white\n" \
"\n" \
"Selected: ~1target~2 ~1 %c ~4; ~1color~2 ~1 %d ~4\n" \
" press 'q' to abort changes to window '~1%s~2'\n" \
" press 'a' or 'w' to commit & change another, <Enter> to commit and end " \
""
/* Windows/Field Group Help specially formatted string(s) --
see 'show_special' for syntax details + other cautions. */
#define WINDOWS_help \
"Help for Windows / Field Groups~2 - \"Current Window\" = ~1 %s ~6\n" \
"\n" \
". Use multiple ~1windows~2, each with separate config opts (color,fields,sort,etc)\n" \
". The 'current' window controls the ~1Summary Area~2 and responds to your ~1Commands~2\n" \
" . that window's ~1task display~2 can be turned ~1Off~2 & ~1On~2, growing/shrinking others\n" \
" . with ~1NO~2 task display, some commands will be ~1disabled~2 ('i','R','n','c', etc)\n" \
" until a ~1different window~2 has been activated, making it the 'current' window\n" \
". You ~1change~2 the 'current' window by: ~1 1~2) cycling forward/backward;~1 2~2) choosing\n" \
" a specific field group; or~1 3~2) exiting the color mapping or fields screens\n" \
". Commands ~1available anytime -------------~2\n" \
" A . Alternate display mode toggle, show ~1Single~2 / ~1Multiple~2 windows\n" \
" g . Choose another field group and make it 'current', or change now\n" \
" by selecting a number from: ~1 1~2 =%s;~1 2~2 =%s;~1 3~2 =%s; or~1 4~2 =%s\n" \
". Commands ~1requiring~2 '~1A~2' mode~1 -------------~2\n" \
" G . Change the ~1Name~5 of the 'current' window/field group\n" \
" ~1*~4 a , w . Cycle through all four windows: '~1a~5' Forward; '~1w~5' Backward\n" \
" ~1*~4 - , _ . Show/Hide: '~1-~5' ~1Current~2 window; '~1_~5' all ~1Visible~2/~1Invisible~2\n" \
" The screen will be divided evenly between task displays. But you can make\n" \
" some ~1larger~2 or ~1smaller~2, using '~1n~2' and '~1i~2' commands. Then later you could:\n" \
" ~1*~4 = , + . Rebalance tasks: '~1=~5' ~1Current~2 window; '~1+~5' ~1Every~2 window\n" \
" (this also forces the ~1current~2 or ~1every~2 window to become visible)\n" \
"\n" \
"In '~1A~2' mode, '~1*~4' keys are your ~1essential~2 commands. Please try the '~1a~2' and '~1w~2'\n" \
"commands plus the 'g' sub-commands NOW. Press <Enter> to make 'Current' " \
""
#define LOADAV_line_alt "%s\06 -%s\n"
/*###### For Piece of mind #############################################*/

558
top/top_nls.c Normal file
View File

@ -0,0 +1,558 @@
/* top_nls.c - provide the basis for future nls translations */
/*
* Copyright (c) 2011, by: James C. Warner
* All rights reserved. 8921 Hilloway Road
* Eden Prairie, Minnesota 55347 USA
*
* This file may be used subject to the terms and conditions of the
* GNU Library General Public License Version 2, or any later version
* at your option, as published by the Free Software Foundation.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*/
/* For contributions to this program, the author wishes to thank:
* Craig Small, <csmall@small.dropbear.id.au>
* Sami Kerola, <kerolasa@iki.fi>
*/
#include <stdio.h>
#include <string.h>
#include "top.h"
#include "top_nls.h"
/*
* These are our three string tables with the following contents:
* Desc : fields descriptions not to exceed 20 screen positions
* Norm : regular text possibly also containing c-format specifiers
* Uniq : show_special specially formatted strings
*
* The latter table presents the greates translation challenge !
*/
const char *Desc_nlstab[P_MAXPFLGS];
const char *Norm_nlstab[norm_MAX];
const char *Uniq_nlstab[uniq_MAX];
/*
* This routine builds the nls table containing plain text only
* used as the field descriptions. Each translated line MUST be
* kept to a maximum of 20 characters or less! */
static void build_desc_nlstab (void) {
char buf[SMLBUFSIZ];
snprintf(buf, sizeof(buf), "%s", _(
"-------------------------------------------------------------------------------\n"
"Note for Translators:\n"
" This group of single lines contains plain text only used as the\n"
" field descriptions. Each translated line MUST be kept to a length\n"
" of 20 characters or less.\n"
"\n"
"( this text is for information only and need never be translated )\n"
""));
snprintf(buf, sizeof(buf), "%s", _("Process Id"));
Desc_nlstab[P_PID] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Parent Process pid"));
Desc_nlstab[P_PPD] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Effective User Id"));
Desc_nlstab[P_UED] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Effective User Name"));
Desc_nlstab[P_UEN] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Real User Id"));
Desc_nlstab[P_URD] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Real User Name"));
Desc_nlstab[P_URN] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Saved User Id"));
Desc_nlstab[P_USD] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Saved User Name"));
Desc_nlstab[P_USN] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Group Id"));
Desc_nlstab[P_GID] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Group Name"));
Desc_nlstab[P_GRP] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Process Group Id"));
Desc_nlstab[P_PGD] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Controlling Tty"));
Desc_nlstab[P_TTY] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Tty Process Grp Id"));
Desc_nlstab[P_TPG] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Session Id"));
Desc_nlstab[P_SID] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Priority"));
Desc_nlstab[P_PRI] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Nice Value"));
Desc_nlstab[P_NCE] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Number of Threads"));
Desc_nlstab[P_THD] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Last Used Cpu (SMP)"));
Desc_nlstab[P_CPN] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("CPU Usage"));
Desc_nlstab[P_CPU] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("CPU Time"));
Desc_nlstab[P_TME] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("CPU Time, hundredths"));
Desc_nlstab[P_TM2] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Memory Usage (RES)"));
Desc_nlstab[P_MEM] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Virtual Image (kb)"));
Desc_nlstab[P_VRT] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Swapped Size (kb)"));
Desc_nlstab[P_SWP] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Resident Size (kb)"));
Desc_nlstab[P_RES] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Code Size (kb)"));
Desc_nlstab[P_COD] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Data+Stack Size (kb)"));
Desc_nlstab[P_DAT] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Shared Mem Size (kb)"));
Desc_nlstab[P_SHR] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Major Page Faults"));
Desc_nlstab[P_FL1] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Minor Page Faults"));
Desc_nlstab[P_FL2] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Dirty Pages Count"));
Desc_nlstab[P_DRT] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Process Status"));
Desc_nlstab[P_STA] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Command Name/Line"));
Desc_nlstab[P_CMD] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Sleeping in Function"));
Desc_nlstab[P_WCH] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Task Flags <sched.h>"));
Desc_nlstab[P_FLG] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Control Groups"));
Desc_nlstab[P_CGR] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Supp Groups IDs"));
Desc_nlstab[P_SGD] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Supp Groups Names"));
Desc_nlstab[P_SGN] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Thread Group Id"));
#ifdef OOMEM_ENABLE
Desc_nlstab[P_TGD] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("oom_adjustment (2^X)"));
Desc_nlstab[P_OOA] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("oom_score (badness)"));
Desc_nlstab[P_OOM] = strdup(buf);
#endif
}
/*
* This routine builds the nls table containing both plain text
* and regular c-format strings. */
static void build_norm_nlstab (void) {
char buf[MEDBUFSIZ];
snprintf(buf, sizeof(buf), "%s", _(
"-------------------------------------------------------------------------------\n"
"Note for Translators:\n"
" This group of lines contains both plain text and c-format strings.\n"
" Some strings reflect switches used to affect the running program\n"
" and should not be translated without also making corresponding\n"
" c-code logic changes.\n"
"\n"
"( this text is for information only and need never be translated )\n"
""));
snprintf(buf, sizeof(buf), "%s", _(
"\n"
"\tsignal %d (%s) was caught by %s, please\n"
"\tsee http://www.debian.org/Bugs/Reporting\n"
""));
Norm_nlstab[EXIT_signals_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _(
"inappropriate '%s'\n"
"usage:\t%s%s"
""));
Norm_nlstab[WRONG_switch_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _(
"\t%s\n"
"usage:\t%s%s"
""));
Norm_nlstab[HELP_cmdline_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("failed /proc/stat open: %s"));
Norm_nlstab[FAIL_statopn_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("failed openproc: %s"));
Norm_nlstab[FAIL_openlib_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("bad delay interval '%s'"));
Norm_nlstab[BAD_delayint_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("bad iterations argument '%s'"));
Norm_nlstab[BAD_niterate_arg] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("pid limit (%d) exceeded"));
Norm_nlstab[LIMIT_exceed_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("bad pid '%s'"));
Norm_nlstab[BAD_mon_pids_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("-%c requires argument"));
Norm_nlstab[MISSING_args_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("bad width arg '%s', must > %d"));
Norm_nlstab[BAD_widtharg_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _(
"unknown option '%c'\n"
"usage:\t%s%s"
""));
Norm_nlstab[UNKNOWN_opts_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("-d disallowed in \"secure\" mode"));
Norm_nlstab[DELAY_secure_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("-d requires positive argument"));
Norm_nlstab[DELAY_badarg_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("On"));
Norm_nlstab[ON_word_only_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Off"));
Norm_nlstab[OFF_one_word_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _(" -hv | -bcHiSs -d delay -n limit -u|U user | -p pid[,pid] -w [cols]"));
Norm_nlstab[USAGE_abbrev_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("failed /proc/stat read"));
Norm_nlstab[FAIL_statget_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Forest mode %s"));
Norm_nlstab[FOREST_modes_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("failed tty get"));
Norm_nlstab[FAIL_tty_get_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("failed Tty_tweaked set: %s"));
Norm_nlstab[FAIL_tty_mod_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("failed Tty_raw set: %s"));
Norm_nlstab[FAIL_tty_raw_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Choose field group (1 - 4)"));
Norm_nlstab[CHOOSE_group_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Command disabled, 'A' mode required"));
Norm_nlstab[DISABLED_cmd_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Command disabled, activate %s with '-' or '_'"));
Norm_nlstab[DISABLED_win_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("No colors to map!"));
Norm_nlstab[COLORS_nomap_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Failed '%s' open: %s"));
Norm_nlstab[FAIL_rc_open_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Wrote configuration to '%s'"));
Norm_nlstab[WRITE_rcfile_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Change delay from %.1f to"));
Norm_nlstab[DELAY_change_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Show threads %s"));
Norm_nlstab[THREADS_show_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Irix mode %s"));
Norm_nlstab[IRIX_curmode_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("pid to signal/kill"));
Norm_nlstab[GET_pid2kill_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Send pid %d signal [%d/sigterm]"));
Norm_nlstab[GET_sigs_num_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Failed signal pid '%d' with '%d': %s"));
Norm_nlstab[FAIL_signals_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Invalid signal"));
Norm_nlstab[BAD_signalid_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("PID to renice"));
Norm_nlstab[GET_pid2nice_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Renice PID %d to value"));
Norm_nlstab[GET_nice_num_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Failed renice of PID %d to %d: %s"));
Norm_nlstab[FAIL_re_nice_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Rename window '%s' to (1-3 chars)"));
Norm_nlstab[NAME_windows_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Cumulative time %s"));
Norm_nlstab[TIME_accumed_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Maximum tasks = %d, change to (0 is unlimited)"));
Norm_nlstab[GET_max_task_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Invalid maximum"));
Norm_nlstab[BAD_max_task_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Nothing to highlight!"));
Norm_nlstab[HILIGHT_cant_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Which user (blank for all)"));
Norm_nlstab[GET_user_ids_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Unknown command - try 'h' for help"));
Norm_nlstab[UNKNOWN_cmds_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("scroll coordinates: y = %d/%d (tasks), x = %d/%d (fields)"));
Norm_nlstab[SCROLL_coord_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("failed memory allocate"));
Norm_nlstab[FAIL_alloc_c_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("failed memory re-allocate"));
Norm_nlstab[FAIL_alloc_r_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Unacceptable floating point"));
Norm_nlstab[BAD_numfloat_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Invalid user"));
Norm_nlstab[BAD_username_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("failed sigprocmask, SIG_BLOCK: %s"));
Norm_nlstab[FAIL_sigstop_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("failed sigprocmask, SIG_SETMASK: %s"));
Norm_nlstab[FAIL_sigmask_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("forest view"));
Norm_nlstab[FOREST_views_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("failed pid maximum size test"));
Norm_nlstab[FAIL_widepid_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("failed number of cpus test"));
Norm_nlstab[FAIL_widecpu_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("incompatible rcfile, you should delete '%s'"));
Norm_nlstab[RC_bad_files_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("window entry #%d corrupt, please delete '%s'"));
Norm_nlstab[RC_bad_entry_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Unavailable in secure mode"));
Norm_nlstab[NOT_onsecure_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Only 1 cpu detected"));
Norm_nlstab[NOT_smp_cpus_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Unacceptable integer"));
Norm_nlstab[BAD_integers_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("conflicting process selections (U/p/u)"));
Norm_nlstab[SELECT_clash_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Kb"));
Norm_nlstab[AMT_kilobyte_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Mb"));
Norm_nlstab[AMT_megabyte_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Gb"));
Norm_nlstab[AMT_gigabyte_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Threads"));
Norm_nlstab[WORD_threads_txt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("Tasks"));
Norm_nlstab[WORD_process_txt] = strdup(buf);
}
/*
* This routine builds the nls table containing specially
* formatted strings designed to fit within an 80x24 terminal. */
static void build_uniq_nsltab (void) {
char buf[BIGBUFSIZ];
snprintf(buf, sizeof(buf), "%s", _(
"-------------------------------------------------------------------------------\n"
"Note for Translators:\n"
" The next 11 text groups contain unprintable characters used to\n"
" index a capabilities table at run-time. You may need a special\n"
" editor which can accomodate such data without altering it.\n"
"\n"
" Please see the comments in the source file for additional\n"
" information and guidance regarding these strings.\n"
"\n"
"( this text is for information only and need never be translated )\n"
""));
/*
* These lines contain special formatting elements and are very
* carefully designed to fit within a 80x24 terminal window.
* The special formatting consists of:
* "some text <_delimiter_> some more text <_delimiter_>...\n"
* Where <_delimiter_> is a single byte in the range of:
* \01 through \10 (in decimalizee, 1 - 8)
* and is used to select an 'attribute' from a capabilities table
* which is then applied to the *preceding* substring.
* Once recognized, the delimiter is replaced with a null character
* and viola, we've got a substring ready to output! Strings or
* substrings without delimiters will receive the Cap_norm attribute.
*
* note: the following is an example of the capabilities
* table for which the unprintable characters are
* used as an index.
* +------------------------------------------------------+
* | char *captab[] = { : Cap's/Delim's |
* | Cap_norm, Cap_norm, = \00, \01, |
* | cap_bold, capclr_sum, = \02, \03, |
* | capclr_msg, capclr_pmt, = \04, \05, |
* | capclr_hdr, = \06, |
* | capclr_rowhigh, = \07, |
* | capclr_rownorm }; = \10 [octal!] |
* +------------------------------------------------------+ */
snprintf(buf, sizeof(buf), "%s", _(
"Help for Interactive Commands\02 - %s\n"
"Window \01%s\06: \01Cumulative mode \03%s\02. \01System\06: \01Delay \03%.1f secs\02; \01Secure mode \03%s\02.\n"
"\n"
" Z\05,\01B\05 Global: '\01Z\02' change color mappings; '\01B\02' disable/enable bold\n"
" l,t,m Toggle Summaries: '\01l\02' load avg; '\01t\02' task/cpu stats; '\01m\02' mem info\n"
" 1,I Toggle SMP view: '\0011\02' single/separate states; '\01I\02' Irix/Solaris mode\n"
" f,F Manage Fields: add/remove; change order; select sort field\n"
"\n"
" <,> . Move sort field: '\01<\02' next col left; '\01>\02' next col right\n"
" R,H,V . Toggle: '\01R\02' norm/rev sort; '\01H\02' show threads; '\01V\02' forest view\n"
" c,i,S . Toggle: '\01c\02' cmd name/line; '\01i\02' idle tasks; '\01S\02' cumulative time\n"
" x\05,\01y\05 . Toggle highlights: '\01x\02' sort field; '\01y\02' running tasks\n"
" z\05,\01b\05 . Toggle: '\01z\02' color/mono; '\01b\02' bold/reverse (only if 'x' or 'y')\n"
" u,U . Show: '\01u\02' effective user; '\01U\02' real, saved, file or effective user\n"
" n or # . Set maximum tasks displayed\n"
" C,... . Toggle scroll coordinates msg for: \01up\02,\01down\02,\01left\02,right\02,\01home\02,\01end\02\n"
"\n"
"%s"
" W Write configuration file\n"
" q Quit\n"
" ( commands shown with '.' require a \01visible\02 task display \01window\02 ) \n"
"Press '\01h\02' or '\01?\02' for help with \01Windows\02,\n"
"any other key to continue "
""));
Uniq_nlstab[KEYS_helpbas_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _(
" k,r Manipulate tasks: '\01k\02' kill; '\01r\02' renice\n"
" d or s Set update interval\n"
""));
Uniq_nlstab[KEYS_helpext_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _(
"Help for Windows / Field Groups\02 - \"Current Window\" = \01 %s \06\n"
"\n"
". Use multiple \01windows\02, each with separate config opts (color,fields,sort,etc)\n"
". The 'current' window controls the \01Summary Area\02 and responds to your \01Commands\02\n"
" . that window's \01task display\02 can be turned \01Off\02 & \01On\02, growing/shrinking others\n"
" . with \01NO\02 task display, some commands will be \01disabled\02 ('i','R','n','c', etc)\n"
" until a \01different window\02 has been activated, making it the 'current' window\n"
". You \01change\02 the 'current' window by: \01 1\02) cycling forward/backward;\01 2\02) choosing\n"
" a specific field group; or\01 3\02) exiting the color mapping or fields screens\n"
". Commands \01available anytime -------------\02\n"
" A . Alternate display mode toggle, show \01Single\02 / \01Multiple\02 windows\n"
" g . Choose another field group and make it 'current', or change now\n"
" by selecting a number from: \01 1\02 =%s;\01 2\02 =%s;\01 3\02 =%s; or\01 4\02 =%s\n"
". Commands \01requiring\02 '\01A\02' mode\01 -------------\02\n"
" G . Change the \01Name\05 of the 'current' window/field group\n"
" \01*\04 a , w . Cycle through all four windows: '\01a\05' Forward; '\01w\05' Backward\n"
" \01*\04 - , _ . Show/Hide: '\01-\05' \01Current\02 window; '\01_\05' all \01Visible\02/\01Invisible\02\n"
" The screen will be divided evenly between task displays. But you can make\n"
" some \01larger\02 or \01smaller\02, using '\01n\02' and '\01i\02' commands. Then later you could:\n"
" \01*\04 = , + . Rebalance tasks: '\01=\05' \01Current\02 window; '\01+\05' \01Every\02 window\n"
" (this also forces the \01current\02 or \01every\02 window to become visible)\n"
"\n"
"In '\01A\02' mode, '\01*\04' keys are your \01essential\02 commands. Please try the '\01a\02' and '\01w\02'\n"
"commands plus the 'g' sub-commands NOW. Press <Enter> to make 'Current' "
""));
Uniq_nlstab[WINDOWS_help_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _(
"Help for color mapping\02 - %s\n"
"current window: \01%s\06\n"
"\n"
" color - 04:25:44 up 8 days, 50 min, 7 users, load average:\n"
" Tasks:\03 64 \02total,\03 2 \03running,\03 62 \02sleeping,\03 0 \02stopped,\03\n"
" %%Cpu(s):\03 76.5 \02user,\03 11.2 \02system,\03 0.0 \02nice,\03 12.3 \02idle\03\n"
" \01 Nasty Message! \04 -or- \01Input Prompt\05\n"
" \01 PID TTY PR NI %%CPU TIME+ VIRT SWAP S COMMAND \06\n"
" 17284 \10pts/2 \07 8 0 0.0 0:00.75 1380 0 S /bin/bash \10\n"
" \01 8601 pts/1 7 -10 0.4 0:00.03 916 0 R color -b -z\07\n"
" 11005 \10? \07 9 0 0.0 0:02.50 2852 1008 S amor -sessi\10\n"
" available toggles: \01B\02 =disable bold globally (\01%s\02),\n"
" \01z\02 =color/mono (\01%s\02), \01b\02 =tasks \"bold\"/reverse (\01%s\02)\n"
"\n"
"Select \01target\02 as upper case letter:\n"
" S\02 = Summary Data,\01 M\02 = Messages/Prompts,\n"
" H\02 = Column Heads,\01 T\02 = Task Information\n"
"Select \01color\02 as number:\n"
" 0\02 = black,\01 1\02 = red, \01 2\02 = green,\01 3\02 = yellow,\n"
" 4\02 = blue, \01 5\02 = magenta,\01 6\02 = cyan, \01 7\02 = white\n"
"\n"
"Selected: \01target\02 \01 %c \04; \01color\02 \01 %d \04\n"
" press 'q' to abort changes to window '\01%s\02'\n"
" press 'a' or 'w' to commit & change another, <Enter> to commit and end "
""));
Uniq_nlstab[COLOR_custom_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _(
"Fields Management\02 for window \01%s\06, whose current sort field is \01%s\02\n"
" Navigate with Up/Dn, Right selects for move then <Enter> or Left commits,\n"
" 'd' or <Space> toggles display, 's' sets sort. Use 'q' or <Esc> to end! "
""));
Uniq_nlstab[FIELD_header_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("%s:\03"
" %3u \02total,\03 %3u \02running,\03 %3u \02sleeping,\03 %3u \02stopped,\03 %3u \02zombie\03\n"
""));
Uniq_nlstab[STATE_line_1_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("%%%s\03"
" %#5.1f \02user,\03 %#5.1f \02system,\03 %#5.1f \02nice,\03 %#5.1f \02idle\03\n"
""));
Uniq_nlstab[STATE_lin2x4_fmt] = strdup(buf);
/* These are the meanings for abbreviations used below:
* lnx 2.5.x, procps-3.0.5 : IO-wait = i/o wait time
* lnx 2.6.x, procps-3.1.12 : IO-wait now wa, hi = hard irq, si = soft irq
* lnx 2.7.x, procps-3.2.7 : st = steal time */
snprintf(buf, sizeof(buf), "%s", _("%%%s\03"
" %#5.1f \02user,\03 %#5.1f \02system,\03 %#5.1f \02nice,\03 %#5.1f \02idle,\03 %#5.1f \02IO-wait\03\n"
""));
Uniq_nlstab[STATE_lin2x5_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("%%%s\03"
" %#5.1f \02us,\03 %#5.1f \02sy,\03 %#5.1f \02ni,\03 %#5.1f \02id,\03 %#5.1f \02wa,\03 %#5.1f \02hi,\03 %#5.1f \02si\03\n"
""));
Uniq_nlstab[STATE_lin2x6_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _("%%%s\03"
"%#5.1f \02us,\03%#5.1f \02sy,\03%#5.1f \02ni,\03%#5.1f \02id,\03%#5.1f \02wa,\03%#5.1f \02hi,\03%#5.1f \02si,\03%#5.1f \02st\03\n"
""));
Uniq_nlstab[STATE_lin2x7_fmt] = strdup(buf);
snprintf(buf, sizeof(buf), "%s", _(
"%s Mem: \03 %8lu \02total,\03 %8lu \02used,\03 %8lu \02free,\03 %8lu \02buffers\03\n"
"%s Swap:\03 %8lu \02total,\03 %8lu \02used,\03 %8lu \02free,\03 %8lu \02cached\03\n"
""));
Uniq_nlstab[MEMORY_lines_fmt] = strdup(buf);
}
/*
* Duh... */
void initialize_nsl (void) {
build_desc_nlstab();
build_norm_nlstab();
build_uniq_nsltab();
}

84
top/top_nls.h Normal file
View File

@ -0,0 +1,84 @@
/* top_nls.h - provide the basis for future nls translations */
/*
* Copyright (c) 2011 by: James C. Warner
* All rights reserved. 8921 Hilloway Road
* Eden Prairie, Minnesota 55347 USA
*
* This file may be used subject to the terms and conditions of the
* GNU Library General Public License Version 2, or any later version
* at your option, as published by the Free Software Foundation.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*/
/* For contributions to this program, the author wishes to thank:
* Craig Small, <csmall@small.dropbear.id.au>
* Sami Kerola, <kerolasa@iki.fi>
*/
#ifndef _Itop_nls
#define _Itop_nls
//#include "../include/c.h"
#include "nls.h"
/*
* These are our three string tables with the following contents:
* Desc : field descriptions not to exceed 20 screen positions
* Norm : regular text possibly also containing c-format specifiers
* Uniq : show_special specially formatted strings
* The latter table presents the greatest translation challenge !
*/
extern const char *Desc_nlstab[];
extern const char *Norm_nlstab[];
extern const char *Uniq_nlstab[];
/*
* Simle optional macros to ease table access.
* The N_txt and N_fmt macros are interchangeable but
* highlight the two types of strings found in Norm_nlstable.
*/
#define N_fld(e) Desc_nlstab[e]
#define N_txt(e) Norm_nlstab[e]
#define N_fmt(e) Norm_nlstab[e]
#define N_unq(e) Uniq_nlstab[e]
/*
* These enums are the means to access two of our three tables.
* The Desc_nlstab is accessed with standard top pflag enums.
*
* The norm_nls enums carry a suffix distinguishing plain text
* from any text also containiing c-format specifiers.
*/
enum norm_nls {
AMT_kilobyte_txt, AMT_megabyte_txt, AMT_gigabyte_txt, BAD_delayint_fmt,
BAD_integers_txt, BAD_max_task_txt, BAD_mon_pids_fmt, BAD_niterate_arg,
BAD_numfloat_txt, BAD_signalid_txt, BAD_username_txt, BAD_widtharg_fmt,
CHOOSE_group_txt, COLORS_nomap_txt, DELAY_badarg_txt, DELAY_change_fmt,
DELAY_secure_txt, DISABLED_cmd_fmt, DISABLED_win_fmt, EXIT_signals_fmt,
FAIL_alloc_c_txt, FAIL_alloc_r_txt, FAIL_openlib_txt, FAIL_rc_open_fmt,
FAIL_re_nice_fmt, FAIL_sigmask_fmt, FAIL_signals_fmt, FAIL_sigstop_fmt,
FAIL_statget_txt, FAIL_statopn_fmt, FAIL_tty_get_txt, FAIL_tty_mod_fmt,
FAIL_tty_raw_fmt, FAIL_widecpu_txt, FAIL_widepid_txt, FOREST_modes_fmt,
FOREST_views_txt, GET_max_task_fmt, GET_nice_num_fmt, GET_pid2kill_txt,
GET_pid2nice_txt, GET_sigs_num_fmt, GET_user_ids_txt, HELP_cmdline_fmt,
HILIGHT_cant_txt, IRIX_curmode_fmt, LIMIT_exceed_fmt, MISSING_args_fmt,
NAME_windows_fmt, NOT_onsecure_txt, NOT_smp_cpus_txt, OFF_one_word_txt,
ON_word_only_txt, RC_bad_entry_fmt, RC_bad_files_fmt, SCROLL_coord_fmt,
SELECT_clash_txt, THREADS_show_fmt, TIME_accumed_fmt, UNKNOWN_cmds_txt,
UNKNOWN_opts_fmt, USAGE_abbrev_txt, WORD_process_txt, WORD_threads_txt,
WRITE_rcfile_fmt, WRONG_switch_fmt,
norm_MAX
};
enum uniq_nls {
KEYS_helpbas_fmt, KEYS_helpext_fmt, WINDOWS_help_fmt, COLOR_custom_fmt,
FIELD_header_fmt, MEMORY_lines_fmt, STATE_line_1_fmt, STATE_lin2x4_fmt,
STATE_lin2x5_fmt, STATE_lin2x6_fmt, STATE_lin2x7_fmt,
uniq_MAX
};
void initialize_nsl (void);
#endif /* _Itop_nls */