Add gettext i18n support for the set_color command

darcs-hash:20060123173720-ac50b-3e7621d28d041042c3bf7424a8210013d7c72b29.gz
This commit is contained in:
axel 2006-01-24 03:37:20 +10:00
parent 89eb80f3a4
commit 64fee9865e

View file

@ -7,6 +7,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <locale.h>
#if HAVE_NCURSES_H
#include <ncurses.h>
@ -30,6 +31,10 @@
#include <getopt.h>
#endif
#if HAVE_LIBINTL_H
#include <libintl.h>
#endif
/*
Small utility for setting the color.
Usage: set_color COLOR
@ -38,6 +43,17 @@
#define COLORS (sizeof(col)/sizeof(char *))
/**
Program name
*/
#define SET_COLOR "set_color"
#if HAVE_GETTEXT
#define _(string) gettext(string)
#else
#define _(string) (string)
#endif
char *col[]=
{
"black",
@ -109,12 +125,25 @@ void print_colors()
}
}
static void locale_init()
{
setlocale( LC_ALL, "" );
#if HAVE_GETTEXT
bindtextdomain( PACKAGE_NAME, LOCALEDIR );
textdomain( PACKAGE_NAME );
#endif
}
int main( int argc, char **argv )
{
char *bgcolor=0;
char *fgcolor=0;
int fg, bg;
int bold=0;
locale_init();
while( 1 )
{
@ -180,7 +209,7 @@ int main( int argc, char **argv )
break;
case 'v':
fprintf( stderr, "set_color, version %s\n", PACKAGE_VERSION );
fprintf( stderr, _("%s, version %s\n"), SET_COLOR, PACKAGE_VERSION );
exit( 0 );
case 'c':
@ -206,13 +235,13 @@ int main( int argc, char **argv )
break;
default:
printf( "set_color: Too many arguments\n" );
printf( _("%s: Too many arguments\n"), SET_COLOR );
return 1;
}
if( !fgcolor && !bgcolor && !bold )
{
fprintf( stderr, "set_color: Expected an argument\n" );
fprintf( stderr, _("%s: Expected an argument\n"), SET_COLOR );
print_help();
return 1;
}
@ -220,14 +249,14 @@ int main( int argc, char **argv )
fg = translate_color(fgcolor);
if( fgcolor && (fg==-1))
{
fprintf( stderr, "set_color: Unknown color %s\n", fgcolor );
fprintf( stderr, _("%s: Unknown color '%s'\n"), SET_COLOR, fgcolor );
return 1;
}
bg = translate_color(bgcolor);
if( bgcolor && (bg==-1))
{
fprintf( stderr, "set_color: Unknown color %s\n", bgcolor );
fprintf( stderr, _("%s: Unknown color '%s'\n"), SET_COLOR, bgcolor );
return 1;
}