diff options
Diffstat (limited to 'misc-utils')
-rw-r--r-- | misc-utils/Makefile | 20 | ||||
-rw-r--r-- | misc-utils/cal.c | 40 | ||||
-rw-r--r-- | misc-utils/ddate.c | 12 | ||||
-rw-r--r-- | misc-utils/kill.c | 19 | ||||
-rw-r--r-- | misc-utils/logger.1 | 5 | ||||
-rw-r--r-- | misc-utils/logger.c | 124 | ||||
-rw-r--r-- | misc-utils/look.c | 13 | ||||
-rw-r--r-- | misc-utils/mcookie.c | 91 | ||||
-rw-r--r-- | misc-utils/namei.c | 26 | ||||
-rw-r--r-- | misc-utils/script.c | 38 | ||||
-rw-r--r-- | misc-utils/setterm.c | 135 | ||||
-rw-r--r-- | misc-utils/tsort.c | 17 | ||||
-rw-r--r-- | misc-utils/whereis.c | 14 | ||||
-rw-r--r-- | misc-utils/write.c | 37 |
14 files changed, 412 insertions, 179 deletions
diff --git a/misc-utils/Makefile b/misc-utils/Makefile index 9ccf489b1..eeaf56764 100644 --- a/misc-utils/Makefile +++ b/misc-utils/Makefile @@ -4,14 +4,14 @@ # Copyright 1992, 1993, 1994, 1995 Rickard E. Faith (faith@cs.unc.edu) # May be distirbuted under the GPL # - +include ../make_include include ../MCONFIG # Where to put man pages? MAN1= cal.1 chkdupexe.1 ddate.1 kill.1 \ logger.1 look.1 mcookie.1 namei.1 script.1 \ - setterm.1 tsort.1 whereis.1 write.1 + tsort.1 whereis.1 write.1 # Where to put binaries? # See the "install" rule for the links. . . @@ -19,7 +19,7 @@ MAN1= cal.1 chkdupexe.1 ddate.1 kill.1 \ BIN= kill USRBIN= cal chkdupexe ddate logger look mcookie \ - namei script setterm tsort whereis write + namei script tsort whereis write ifeq "$(HAVE_CLEAR)" "no" USRBIN:=$(USRBIN) clear @@ -31,14 +31,21 @@ USRBIN:=$(USRBIN) reset MAN1:=$(MAN1) reset.1 endif +ifeq "$(HAVE_NCURSES)" "yes" +USRBIN:=$(USRBIN) setterm +MAN1:=$(MAN1) setterm.1 +endif + # For script only +LIBPTY= ifeq "$(HAVE_OPENPTY)" "yes" -CFLAGS:=$(CFLAGS) -DHAVE_OPENPTY +LIBPTY:=$(LIBPTY) -lutil endif # Programs requiring special compilation NEEDS_CURSES= setterm +NEEDS_OPENPTY= script all: $(BIN) $(USRBIN) $(USRBIN.NONSHADOW) $(USRGAMES) @@ -49,6 +56,9 @@ else @echo $@ not made since it requires ncurses endif +$(NEEDS_OPENPTY): + $(CC) $(LDFLAGS) $^ -o $@ $(LIBPTY) + %: %.sh cp $@.sh $@ chmod 755 $@ @@ -68,12 +78,12 @@ mcookie: mcookie.o md5.o mcookie.o: mcookie.c md5.h md5.o: md5.c md5.h reset: reset.sh +script: script.o ifeq "$(HAVE_NCURSES)" "yes" setterm: setterm.o endif - install: all $(INSTALLDIR) $(BINDIR) $(USRBINDIR) $(INSTALLBIN) $(BIN) $(BINDIR) diff --git a/misc-utils/cal.c b/misc-utils/cal.c index ab6420140..e3acf74b1 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -36,15 +36,11 @@ /* 1999-02-01 Jean-Francois Bignolles: added option '-m' to display * monday as the first day of the week. + * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + * - added Native Language Support + * */ -/* This defines _LINUX_C_LIB_VERSION_MAJOR, dunno about gnulibc. We - don't want it to read /usr/i586-unknown-linux/include/_G_config.h - so we specify fill path. Were we got /usr/i586-unknown-linux from? - Dunno. */ - -#include "/usr/include/_G_config.h" - #include <sys/types.h> #include <ctype.h> @@ -55,19 +51,13 @@ #include <time.h> #include <unistd.h> #include <locale.h> +#include "nls.h" +#include "../defines.h" -/* Test changes to deal with gnulibc, Linux libc 5. */ -/* #if defined(__linux__) && _LINUX_C_LIB_VERSION_MAJOR > 4 */ -#if _LINUX_C_LIB_VERSION_MAJOR - 0 > 4 || __GNU_LIBRARY__ - 0 >= 5 -# define LANGINFO 1 -#else -# define LANGINFO 0 -#endif - -#if LANGINFO +#ifdef HAVE_langinfo_h # include <langinfo.h> #else -# include <localeinfo.h> +# include <localeinfo.h> /* libc4 only */ #endif #define THURSDAY 4 /* for reformation */ @@ -162,7 +152,11 @@ main(argc, argv) extern char *__progname; __progname = argv[0]; #endif - + + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + setlocale(LC_ALL,""); yflag = 0; while ((ch = getopt(argc, argv, "mjy")) != EOF) @@ -187,11 +181,11 @@ main(argc, argv) switch(argc) { case 2: if ((month = atoi(*argv++)) < 1 || month > 12) - errx(1, "illegal month value: use 1-12"); + errx(1, _("illegal month value: use 1-12")); /* FALLTHROUGH */ case 1: if ((year = atoi(*argv)) < 1 || year > 9999) - errx(1, "illegal year value: use 1-9999"); + errx(1, _("illegal year value: use 1-9999")); break; case 0: (void)time(&now); @@ -228,7 +222,7 @@ void headers_init(void) strcpy(day_headings,""); strcpy(j_day_headings,""); -#if defined(__linux__) && (_LINUX_C_LIB_VERSION_MAJOR > 4 || __GNU_LIBRARY__ > 1) +#ifdef HAVE_langinfo_h # define weekday(wd) nl_langinfo(ABDAY_1+wd) #else # define weekday(wd) _time_info->abbrev_wkday[wd] @@ -247,7 +241,7 @@ void headers_init(void) #undef weekday for (i = 0; i < 12; i++) { -#if defined(__linux__) && (_LINUX_C_LIB_VERSION_MAJOR > 4 || __GNU_LIBRARY__ > 1) +#ifdef HAVE_langinfo_h full_month[i] = nl_langinfo(MON_1+i); #else full_month[i] = _time_info->full_month[i]; @@ -487,6 +481,6 @@ void usage() { - (void)fprintf(stderr, "usage: cal [-mjy] [[month] year]\n"); + (void)fprintf(stderr, _("usage: cal [-mjy] [[month] year]\n")); exit(1); } diff --git a/misc-utils/ddate.c b/misc-utils/ddate.c index 09704e0b4..7f12e86fd 100644 --- a/misc-utils/ddate.c +++ b/misc-utils/ddate.c @@ -26,6 +26,9 @@ 59 Bcy, 3161: PRAISE_BOB and KILL_BOB options split, other minor changes. + 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + - added Native Language Support + */ @@ -57,6 +60,7 @@ #include <string.h> #include <time.h> #include <stdio.h> +#include "nls.h" #ifndef __GNUC__ #define inline /* foo */ @@ -147,6 +151,10 @@ main (int argc, char *argv[]) char schwa[23*17], *fnord=0; int pi; + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + srandom(time(NULL)); /* do args here */ for(pi=1; pi<argc; pi++) { @@ -173,7 +181,7 @@ main (int argc, char *argv[]) fnord=fnord?fnord:default_fmt; } else if (argc!=pi) { usage: - fprintf(stderr,"usage: %s [+format] [day month year]\n", argv[0]); + fprintf(stderr,_("usage: %s [+format] [day month year]\n"), argv[0]); exit(1); } else { t= time(NULL); @@ -219,7 +227,7 @@ void format(char *buf, const char* fmt, struct disc_time dt) for(i=0; i<fmtlen; i++) { if((i==tib_start) && (dt.day==-1)) { /* handle St. Tib's Day */ - strcpy(bufptr, "St. Tib's Day"); bufptr += 13; + strcpy(bufptr, _("St. Tib's Day")); bufptr += 13; i=tib_end; } else { if(fmt[i]=='%') { diff --git a/misc-utils/kill.c b/misc-utils/kill.c index 629938137..768f5deab 100644 --- a/misc-utils/kill.c +++ b/misc-utils/kill.c @@ -34,6 +34,10 @@ * oct 5 1994 -- almost entirely re-written to allow for process names. * modifications (c) salvatore valente <svalente@mit.edu> * may be used / modified / distributed under the same terms as the original. + * + * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + * - added Native Language Support + * */ #include <stdio.h> @@ -42,6 +46,7 @@ #include <ctype.h> #include <unistd.h> #include <signal.h> +#include "nls.h" #define SIZE(a) (sizeof(a)/sizeof(a[0])) @@ -151,6 +156,10 @@ int main (int argc, char *argv[]) int do_pid, do_kill, check_all; int *pids, *ip; + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + whoami = mybasename (*argv); numsig = SIGTERM; do_pid = (! strcmp (whoami, "pid")); @@ -187,7 +196,7 @@ int main (int argc, char *argv[]) /* argc == 2 */ arg = argv[1]; if ((numsig = arg_to_signum (arg)) < 0) { - fprintf (stderr, "%s: unknown signal %s\n", whoami, arg); + fprintf (stderr, _("%s: unknown signal %s\n"), whoami, arg); return 1; } printsig (numsig); @@ -249,7 +258,7 @@ int main (int argc, char *argv[]) pids = get_pids (arg, check_all); if (! pids) { errors++; - fprintf (stderr, "%s: can't find process \"%s\"\n", + fprintf (stderr, _("%s: can't find process \"%s\"\n"), whoami, arg); continue; } @@ -291,7 +300,7 @@ int arg_to_signum (char *arg) void nosig (char *name) { - fprintf (stderr, "%s: unknown signal %s; valid signals:\n", whoami, name); + fprintf (stderr, _("%s: unknown signal %s; valid signals:\n"), whoami, name); printsignals (stderr); } @@ -331,8 +340,8 @@ int usage (int status) FILE *fp; fp = (status == 0 ? stdout : stderr); - fprintf (fp, "usage: %s [ -s signal | -p ] [ -a ] pid ...\n", whoami); - fprintf (fp, " %s -l [ signal ]\n", whoami); + fprintf (fp, _("usage: %s [ -s signal | -p ] [ -a ] pid ...\n"), whoami); + fprintf (fp, _(" %s -l [ signal ]\n"), whoami); return status; } diff --git a/misc-utils/logger.1 b/misc-utils/logger.1 index 0621dba10..82df6be7a 100644 --- a/misc-utils/logger.1 +++ b/misc-utils/logger.1 @@ -43,6 +43,7 @@ .Op Fl f Ar file .Op Fl p Ar pri .Op Fl t Ar tag +.Op Fl u Ar socket .Op Ar message ... .Sh DESCRIPTION .Nm Logger @@ -73,6 +74,10 @@ The default is ``user.notice.'' .It Fl t Ar tag Mark every line in the log with the specified .Ar tag . +.It Fl u Ar sock +Write to socket as specified with +.Ar socket +instead of builtin syslog routines. .It Ar message Write the message to log; if not specified, and the .Fl f diff --git a/misc-utils/logger.c b/misc-utils/logger.c index e59fe12bf..4c881c968 100644 --- a/misc-utils/logger.c +++ b/misc-utils/logger.c @@ -29,14 +29,23 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + * - added Native Language Support + * Sun Mar 21 1999 - Arnaldo Carvalho de Melo <acme@conectiva.com.br> + * - fixed strerr(errno) in gettext calls */ #include <errno.h> #include <unistd.h> #include <stdlib.h> +#include <time.h> #include <stdio.h> #include <ctype.h> #include <string.h> +#include <sys/types.h> +#include <sys/socket.h> +#include "nls.h" #define SYSLOG_NAMES #include <syslog.h> @@ -45,6 +54,65 @@ int decode __P((char *, CODE *)); int pencode __P((char *)); void usage __P((void)); +int +myopenlog(sock) + const char *sock; +{ + int fd; + static struct sockaddr s_addr; /* AF_UNIX address of local logger */ + + s_addr.sa_family = AF_UNIX; + (void)strncpy(s_addr.sa_data, sock, sizeof(s_addr.sa_data)); + + if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { + printf ("socket: %s.\n", strerror(errno)); + exit (1); + } + + if (connect(fd, &s_addr, sizeof(s_addr.sa_family)+strlen(s_addr.sa_data)) == -1) { + printf ("connect: %s.\n", strerror(errno)); + exit (1); + } + return fd; +} + +void +mysyslog(fd, logflags, pri, tag, msg) + int fd; + int logflags; + int pri; + char *tag; + char *msg; +{ + char buf[1000], pid[30], *cp, *tp; + time_t now; + + if (fd > -1) { + /* there was a gethostname call here, but its output was not used */ + /* avoid snprintf - it does not exist on ancient systems */ + if (logflags & LOG_PID) + sprintf (pid, "[%d]", getpid()); + else + pid[0] = 0; + if (tag) + cp = tag; + else { + cp = getlogin(); + if (!cp) + cp = "<someone>"; + } + (void)time(&now); + tp = ctime(&now)+4; + + /* do snprintf by hand - ugly, but for once... */ + sprintf(buf, "<%d>%.15s %.200s%s: %.400s", + pri, tp, cp, pid, msg); + + if (write(fd, buf, strlen(buf)+1) < 0) + return; /* error */ + } +} + /* * logger -- read and log utility * @@ -58,16 +126,23 @@ main(argc, argv) { int ch, logflags, pri; char *tag, buf[1024]; + char *usock = NULL; + int LogSock = -1; + + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); tag = NULL; pri = LOG_NOTICE; logflags = 0; - while ((ch = getopt(argc, argv, "f:ip:st:")) != EOF) + while ((ch = getopt(argc, argv, "f:ip:st:u:")) != EOF) switch((char)ch) { case 'f': /* file to log */ if (freopen(optarg, "r", stdin) == NULL) { - (void)fprintf(stderr, "logger: %s: %s.\n", - optarg, strerror(errno)); + int errsv = errno; + (void)fprintf(stderr, _("logger: %s: %s.\n"), + optarg, strerror(errsv)); exit(1); } break; @@ -83,6 +158,9 @@ main(argc, argv) case 't': /* tag */ tag = optarg; break; + case 'u': /* unix socket */ + usock = optarg; + break; case '?': default: usage(); @@ -91,7 +169,11 @@ main(argc, argv) argv += optind; /* setup for logging */ - openlog(tag ? tag : getlogin(), logflags, 0); + if (!usock) + openlog(tag ? tag : getlogin(), logflags, 0); + else + LogSock = myopenlog(usock); + (void) fclose(stdout); /* log input line if appropriate */ @@ -102,23 +184,41 @@ main(argc, argv) for (p = buf, endp = buf + sizeof(buf) - 2; *argv;) { len = strlen(*argv); if (p + len > endp && p > buf) { + if (!usock) syslog(pri, "%s", buf); + else + mysyslog(LogSock, logflags, pri, tag, buf); p = buf; } - if (len > sizeof(buf) - 1) + if (len > sizeof(buf) - 1) { + if (!usock) syslog(pri, "%s", *argv++); - else { + else + mysyslog(LogSock, logflags, pri, tag, *argv++); + } else { if (p != buf) *p++ = ' '; bcopy(*argv++, p, len); *(p += len) = '\0'; } } - if (p != buf) + if (p != buf) { + if (!usock) syslog(pri, "%s", buf); + else + mysyslog(LogSock, logflags, pri, tag, buf); + } } else - while (fgets(buf, sizeof(buf), stdin) != NULL) + while (fgets(buf, sizeof(buf), stdin) != NULL) { + if (!usock) syslog(pri, "%s", buf); + else + mysyslog(LogSock, logflags, pri, tag, buf); + } + if (!usock) + closelog(); + else + close(LogSock); exit(0); } @@ -138,19 +238,19 @@ pencode(s) fac = decode(save, facilitynames); if (fac < 0) { (void)fprintf(stderr, - "logger: unknown facility name: %s.\n", save); + _("logger: unknown facility name: %s.\n"), save); exit(1); } *s++ = '.'; } else { - fac = 0; + fac = LOG_USER; s = save; } lev = decode(s, prioritynames); if (lev < 0) { (void)fprintf(stderr, - "logger: unknown priority name: %s.\n", save); + _("logger: unknown priority name: %s.\n"), save); exit(1); } return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK)); @@ -177,6 +277,6 @@ void usage() { (void)fprintf(stderr, - "logger: [-is] [-f file] [-p pri] [-t tag] [ message ... ]\n"); + _("usage: logger [-is] [-f file] [-p pri] [-t tag] [-u socket] [ message ... ]\n")); exit(1); } diff --git a/misc-utils/look.c b/misc-utils/look.c index 72256c197..9e6c15bf8 100644 --- a/misc-utils/look.c +++ b/misc-utils/look.c @@ -34,6 +34,10 @@ * SUCH DAMAGE. */ + /* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + * - added Native Language Support + */ + /* * look -- find lines in a sorted list. * @@ -56,6 +60,7 @@ #include <getopt.h> #include <locale.h> #include "pathnames.h" +#include "nls.h" #define EQUAL 0 #define GREATER 1 @@ -84,6 +89,10 @@ main(int argc, char *argv[]) char *back, *file, *front, *p; setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + + setlocale(LC_ALL, ""); file = _PATH_WORDS; termchar = '\0'; @@ -158,7 +167,7 @@ look(char *front, char *back) comparbuf = malloc(stringlen+1); if (comparbuf == NULL) - err("Out of memory"); + err(_("Out of memory")); front = binary_search(front, back); front = linear_search(front, back); @@ -328,7 +337,7 @@ compare(char *s2, char *s2end, int nocase) { static void usage() { - (void)fprintf(stderr, "usage: look [-dfa] [-t char] string [file]\n"); + (void)fprintf(stderr, _("usage: look [-dfa] [-t char] string [file]\n")); exit(2); } diff --git a/misc-utils/mcookie.c b/misc-utils/mcookie.c index 33ae7630e..9f13b49d1 100644 --- a/misc-utils/mcookie.c +++ b/misc-utils/mcookie.c @@ -1,7 +1,7 @@ /* mcookie.c -- Generates random numbers for xauth * Created: Fri Feb 3 10:42:48 1995 by faith@cs.unc.edu - * Revised: Mon Sep 25 23:44:43 1995 by r.faith@ieee.org - * Public Domain 1995 Rickard E. Faith (faith@cs.unc.edu) + * Revised: Fri Mar 19 07:48:01 1999 by faith@acm.org + * Public Domain 1995, 1999 Rickard E. Faith (faith@acm.org) * This program comes with ABSOLUTELY NO WARRANTY. * * $Id: mcookie.c,v 1.5 1997/07/06 00:13:06 aebr Exp $ @@ -13,6 +13,11 @@ * NOTE: Unless /dev/random is available, this program does not actually * gather 128 bits of random information, so the magic cookie generated * will be considerably easier to guess than one might expect. + * + * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + * - added Native Language Support + * 1999-03-21 aeb: Added some fragments of code from Colin Plumb. + * */ #ifdef __linux__ @@ -27,29 +32,48 @@ #include <sys/time.h> #include <unistd.h> #endif +#include "nls.h" -#define MAXBUFFERSIZE 512 +#define BUFFERSIZE 4096 struct rngs { const char *path; - int length; + int minlength, maxlength; } rngs[] = { - { "/dev/random", 16 }, - { "/dev/urandom", 128 }, - { "/proc/stat", MAXBUFFERSIZE }, - { "/proc/loadavg", MAXBUFFERSIZE }, - { "/dev/audio", MAXBUFFERSIZE }, + { "/dev/random", 16, 16 }, /* 16 bytes = 128 bits suffice */ + { "/proc/interrupts", 0, 0 }, + { "/proc/slabinfo", 0, 0 }, + { "/proc/stat", 0, 0 }, + { "/dev/urandom", 32, 64 }, }; #define RNGS (sizeof(rngs)/sizeof(struct rngs)) int Verbose = 0; +/* The basic function to hash a file */ +static off_t +hash_file(struct MD5Context *ctx, int fd) +{ + off_t count = 0; + ssize_t r; + unsigned char buf[BUFFERSIZE]; + + while ((r = read(fd, buf, sizeof(buf))) > 0) { + MD5Update(ctx, buf, r); + count += r; + } + /* Separate files with a null byte */ + buf[0] = 0; + MD5Update(ctx, buf, 1); + return count; +} + int main( int argc, char **argv ) { int i; struct MD5Context ctx; unsigned char digest[16]; - unsigned char buf[MAXBUFFERSIZE]; + unsigned char buf[BUFFERSIZE]; int fd; int c; pid_t pid; @@ -62,6 +86,10 @@ int main( int argc, char **argv ) long int t; #endif + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + while ((c = getopt( argc, argv, "vf:" )) != EOF) switch (c) { case 'v': ++Verbose; break; @@ -85,39 +113,52 @@ int main( int argc, char **argv ) if (file) { int count = 0; - if (file[0] == '-' && !file[1]) fd = fileno(stdin); - else if ((fd = open( file, O_RDONLY )) <0) { - fprintf( stderr, "Could not open %s\n", file ); - } + if (file[0] == '-' && !file[1]) + fd = fileno(stdin); + else + fd = open( file, O_RDONLY ); + + if (fd < 0) { + fprintf( stderr, _("Could not open %s\n"), file ); + } else { + count = hash_file( &ctx, fd ); + if (Verbose) + fprintf( stderr, _("Got %d bytes from %s\n"), count, file ); - while ((r = read( fd, buf, sizeof( buf ) )) > 0) { - MD5Update( &ctx, buf, r ); - count += r; + if (file[0] != '-' || file[1]) close( fd ); } - if (Verbose) - fprintf( stderr, "Got %d bytes from %s\n", count, file ); - - if (file[0] != '-' || file[1]) close( fd ); } for (i = 0; i < RNGS; i++) { if ((fd = open( rngs[i].path, O_RDONLY|O_NONBLOCK )) >= 0) { - r = read( fd, buf, sizeof( buf ) ); + int count = sizeof(buf); + + if (rngs[i].maxlength && count > rngs[i].maxlength) + count = rngs[i].maxlength; + r = read( fd, buf, count ); if (r > 0) MD5Update( &ctx, buf, r ); else r = 0; close( fd ); if (Verbose) - fprintf( stderr, "Got %d bytes from %s\n", r, rngs[i].path ); - if (r >= rngs[i].length) break; + fprintf( stderr, _("Got %d bytes from %s\n"), r, rngs[i].path ); + if (rngs[i].minlength && r >= rngs[i].minlength) + break; } else if (Verbose) - fprintf( stderr, "Could not open %s\n", rngs[i].path ); + fprintf( stderr, _("Could not open %s\n"), rngs[i].path ); } MD5Final( digest, &ctx ); for (i = 0; i < 16; i++) printf( "%02x", digest[i] ); putchar ( '\n' ); + /* + * The following is important for cases like disk full, so shell scripts + * can bomb out properly rather than think they succeeded. + */ + if (fflush(stdout) < 0 || fclose(stdout) < 0) + return 1; + return 0; } diff --git a/misc-utils/namei.c b/misc-utils/namei.c index 36a17dfd6..f110e6385 100644 --- a/misc-utils/namei.c +++ b/misc-utils/namei.c @@ -39,6 +39,9 @@ the maximum number of symbolic links this system can have. The program exits with a 1 status ONLY if it finds it cannot chdir to /, or if it encounters an unknown file type. +1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> +- added Native Language Support + -------------------------------------------------------------*/ #include <stdio.h> @@ -47,6 +50,7 @@ chdir to /, or if it encounters an unknown file type. #include <sys/types.h> #include <sys/stat.h> #include <sys/param.h> +#include "nls.h" #ifndef __GNU_LIBRARY__ extern char *sys_errlist[]; @@ -76,6 +80,10 @@ char *argv[]; register int c; char curdir[MAXPATHLEN]; + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + if(argc < 2) usage(); @@ -96,7 +104,7 @@ char *argv[]; } if(getcwd(curdir, sizeof(curdir)) == NULL){ - (void)fprintf(stderr, "namei: unable to get current directory - %s\n", curdir); + (void)fprintf(stderr, _("namei: unable to get current directory - %s\n"), curdir); exit(1); } @@ -107,7 +115,7 @@ char *argv[]; namei(argv[optind], 0); if(chdir(curdir) == -1){ - (void)fprintf(stderr, "namei: unable to chdir to %s - %s (%d)\n", curdir, ERR); + (void)fprintf(stderr, _("namei: unable to chdir to %s - %s (%d)\n"), curdir, ERR); exit(1); } } @@ -117,7 +125,7 @@ char *argv[]; void usage() { - (void)fprintf(stderr,"usage: namei [-mx] pathname [pathname ...]\n"); + (void)fprintf(stderr,_("usage: namei [-mx] pathname [pathname ...]\n")); exit(1); } @@ -146,14 +154,14 @@ register int lev; file++; if(chdir("/") == -1){ - (void)fprintf(stderr,"namei: could not chdir to root!\n"); + (void)fprintf(stderr,_("namei: could not chdir to root!\n")); exit(1); } for(i = 0; i < lev; i++) (void)printf(" "); if(stat("/", &stb) == -1){ - (void)fprintf(stderr, "namei: could not stat root!\n"); + (void)fprintf(stderr, _("namei: could not stat root!\n")); exit(1); } lastdev = stb.st_dev; @@ -208,7 +216,7 @@ register int lev; */ if(chdir(buf) == -1){ - (void)printf(" ? could not chdir into %s - %s (%d)\n", buf, ERR ); + (void)printf(_(" ? could not chdir into %s - %s (%d)\n"), buf, ERR ); return; } if(xflag && lastdev != stb.st_dev && lastdev != NODEV){ @@ -237,7 +245,7 @@ register int lev; bzero(sym, BUFSIZ); if(readlink(buf, sym, BUFSIZ) == -1){ - (void)printf(" ? problems reading symlink %s - %s (%d)\n", buf, ERR); + (void)printf(_(" ? problems reading symlink %s - %s (%d)\n"), buf, ERR); return; } @@ -247,7 +255,7 @@ register int lev; (void)printf(" l %s -> %s", buf, sym); if(symcount > 0 && symcount++ > MAXSYMLINKS){ - (void)printf(" *** EXCEEDED UNIX LIMIT OF SYMLINKS ***"); + (void)printf(_(" *** EXCEEDED UNIX LIMIT OF SYMLINKS ***")); symcount = -1; } (void)printf("\n"); @@ -283,7 +291,7 @@ register int lev; break; default: - (void)fprintf(stderr,"namei: unknown file type 0%06o on file %s\n", stb.st_mode, buf ); + (void)fprintf(stderr,_("namei: unknown file type 0%06o on file %s\n"), stb.st_mode, buf ); exit(1); } diff --git a/misc-utils/script.c b/misc-utils/script.c index 23c48ea6b..283bc8fcb 100644 --- a/misc-utils/script.c +++ b/misc-utils/script.c @@ -31,6 +31,10 @@ * SUCH DAMAGE. */ +/* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + * - added Native Language Support + */ + /* * script */ @@ -43,13 +47,15 @@ #include <sys/signal.h> #include <stdio.h> #include <paths.h> +#include "nls.h" #ifdef __linux__ #include <unistd.h> #include <string.h> #endif -#ifdef HAVE_OPENPTY +#include "../defines.h" +#ifdef HAVE_openpty #include <pty.h> #endif @@ -74,7 +80,7 @@ struct termios tt; struct winsize win; int lb; int l; -#ifndef HAVE_OPENPTY +#ifndef HAVE_openpty char line[] = "/dev/ptyXX"; #endif int aflg; @@ -89,6 +95,10 @@ main(argc, argv) void finish(); char *getenv(); + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + while ((ch = getopt(argc, argv, "a")) != EOF) switch((char)ch) { case 'a': @@ -96,7 +106,7 @@ main(argc, argv) break; case '?': default: - fprintf(stderr, "usage: script [-a] [file]\n"); + fprintf(stderr, _("usage: script [-a] [file]\n")); exit(1); } argc -= optind; @@ -116,7 +126,7 @@ main(argc, argv) shell = _PATH_BSHELL; getmaster(); - printf("Script started, file is %s\n", fname); + printf(_("Script started, file is %s\n"), fname); fixtty(); (void) signal(SIGCHLD, finish); @@ -148,7 +158,7 @@ doinput() char ibuf[BUFSIZ]; (void) fclose(fscript); -#ifdef HAVE_OPENPTY +#ifdef HAVE_openpty (void) close(slave); #endif while ((cc = read(0, ibuf, BUFSIZ)) > 0) @@ -181,11 +191,11 @@ dooutput() char obuf[BUFSIZ], *ctime(); (void) close(0); -#ifdef HAVE_OPENPTY +#ifdef HAVE_openpty (void) close(slave); #endif tvec = time((time_t *)NULL); - fprintf(fscript, "Script started on %s", ctime(&tvec)); + fprintf(fscript, _("Script started on %s"), ctime(&tvec)); for (;;) { cc = read(master, obuf, sizeof (obuf)); if (cc <= 0) @@ -251,12 +261,12 @@ done() if (subchild) { tvec = time((time_t *)NULL); - fprintf(fscript,"\nScript done on %s", ctime(&tvec)); + fprintf(fscript,_("\nScript done on %s"), ctime(&tvec)); (void) fclose(fscript); (void) close(master); } else { (void) tcsetattr(0, TCSAFLUSH, &tt); - printf("Script done, file is %s\n", fname); + printf(_("Script done, file is %s\n"), fname); } exit(0); } @@ -264,11 +274,11 @@ done() void getmaster() { -#ifdef HAVE_OPENPTY +#ifdef HAVE_openpty (void) tcgetattr(0, &tt); (void) ioctl(0, TIOCGWINSZ, (char *)&win); if (openpty(&master, &slave, NULL, &tt, &win) < 0) { - fprintf(stderr, "openpty failed\n"); + fprintf(stderr, _("openpty failed\n")); fail(); } #else @@ -302,15 +312,15 @@ getmaster() } } } - fprintf(stderr, "Out of pty's\n"); + fprintf(stderr, _("Out of pty's\n")); fail(); -#endif /* not HAVE_OPENPTY */ +#endif /* not HAVE_openpty */ } void getslave() { -#ifndef HAVE_OPENPTY +#ifndef HAVE_openpty line[strlen("/dev/")] = 't'; slave = open(line, O_RDWR); if (slave < 0) { diff --git a/misc-utils/setterm.c b/misc-utils/setterm.c index 3b3e6c24f..b9e4c0dad 100644 --- a/misc-utils/setterm.c +++ b/misc-utils/setterm.c @@ -16,6 +16,10 @@ * * Converted to terminfo by Kars de Jong (jongk@cs.utwente.nl) * + * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + * - added Native Language Support + * + * * Syntax: * * setterm @@ -106,6 +110,7 @@ #endif #include <sys/ioctl.h> #include <sys/time.h> +#include "nls.h" #ifndef TCGETS /* TCGETS is either defined in termios.h, or here: */ @@ -737,58 +742,58 @@ char *prog_name; /* Name of this program. */ { /* Print error message about arguments, and the command's syntax. */ - fprintf(stderr, "%s: Argument error, usage\n", prog_name); + fprintf(stderr, _("%s: Argument error, usage\n"), prog_name); fprintf(stderr, "\n"); fprintf(stderr, "%s\n", prog_name); - fprintf(stderr, " [ -term terminal_name ]\n"); - fprintf(stderr, " [ -reset ]\n"); - fprintf(stderr, " [ -initialize ]\n"); - fprintf(stderr, " [ -cursor [on|off] ]\n"); + fprintf(stderr, _(" [ -term terminal_name ]\n")); + fprintf(stderr, _(" [ -reset ]\n")); + fprintf(stderr, _(" [ -initialize ]\n")); + fprintf(stderr, _(" [ -cursor [on|off] ]\n")); #if 0 - fprintf(stderr, " [ -snow [on|off] ]\n"); - fprintf(stderr, " [ -softscroll [on|off] ]\n"); - fprintf(stderr, " [ -keyboard pc|olivetti|dutch|extended ]\n"); + fprintf(stderr, _(" [ -snow [on|off] ]\n")); + fprintf(stderr, _(" [ -softscroll [on|off] ]\n")); + fprintf(stderr, _(" [ -keyboard pc|olivetti|dutch|extended ]\n")); #endif - fprintf(stderr, " [ -repeat [on|off] ]\n"); - fprintf(stderr, " [ -appcursorkeys [on|off] ]\n"); - fprintf(stderr, " [ -linewrap [on|off] ]\n"); - fprintf(stderr, " [ -default ]\n"); - fprintf(stderr, " [ -foreground black|blue|green|cyan"); - fprintf(stderr, "|red|magenta|yellow|white|default ]\n"); - fprintf(stderr, " [ -background black|blue|green|cyan"); - fprintf(stderr, "|red|magenta|yellow|white|default ]\n"); - fprintf(stderr, " [ -ulcolor black|grey|blue|green|cyan"); - fprintf(stderr, "|red|magenta|yellow|white ]\n"); - fprintf(stderr, " [ -ulcolor bright blue|green|cyan"); - fprintf(stderr, "|red|magenta|yellow|white ]\n"); - fprintf(stderr, " [ -hbcolor black|grey|blue|green|cyan"); - fprintf(stderr, "|red|magenta|yellow|white ]\n"); - fprintf(stderr, " [ -hbcolor bright blue|green|cyan"); - fprintf(stderr, "|red|magenta|yellow|white ]\n"); + fprintf(stderr, _(" [ -repeat [on|off] ]\n")); + fprintf(stderr, _(" [ -appcursorkeys [on|off] ]\n")); + fprintf(stderr, _(" [ -linewrap [on|off] ]\n")); + fprintf(stderr, _(" [ -default ]\n")); + fprintf(stderr, _(" [ -foreground black|blue|green|cyan")); + fprintf(stderr, _("|red|magenta|yellow|white|default ]\n")); + fprintf(stderr, _(" [ -background black|blue|green|cyan")); + fprintf(stderr, _("|red|magenta|yellow|white|default ]\n")); + fprintf(stderr, _(" [ -ulcolor black|grey|blue|green|cyan")); + fprintf(stderr, _("|red|magenta|yellow|white ]\n")); + fprintf(stderr, _(" [ -ulcolor bright blue|green|cyan")); + fprintf(stderr, _("|red|magenta|yellow|white ]\n")); + fprintf(stderr, _(" [ -hbcolor black|grey|blue|green|cyan")); + fprintf(stderr, _("|red|magenta|yellow|white ]\n")); + fprintf(stderr, _(" [ -hbcolor bright blue|green|cyan")); + fprintf(stderr, _("|red|magenta|yellow|white ]\n")); #if 0 - fprintf(stderr, " [ -standout [ attr ] ]\n"); + fprintf(stderr, _(" [ -standout [ attr ] ]\n")); #endif - fprintf(stderr, " [ -inversescreen [on|off] ]\n"); - fprintf(stderr, " [ -bold [on|off] ]\n"); - fprintf(stderr, " [ -half-bright [on|off] ]\n"); - fprintf(stderr, " [ -blink [on|off] ]\n"); - fprintf(stderr, " [ -reverse [on|off] ]\n"); - fprintf(stderr, " [ -underline [on|off] ]\n"); - fprintf(stderr, " [ -store ]\n"); - fprintf(stderr, " [ -clear [all|rest] ]\n"); - fprintf(stderr, " [ -tabs [ tab1 tab2 tab3 ... ] ] (tabn = 1-160)\n"); - fprintf(stderr, " [ -clrtabs [ tab1 tab2 tab3 ... ] ] (tabn = 1-160)\n"); - fprintf(stderr, " [ -regtabs [1-160] ]\n"); - fprintf(stderr, " [ -blank [0-60] ]\n"); - fprintf(stderr, " [ -dump [1-NR_CONSOLES] ]\n"); - fprintf(stderr, " [ -append [1-NR_CONSOLES] ]\n"); - fprintf(stderr, " [ -file dumpfilename ]\n"); - fprintf(stderr, " [ -msg [on|off] ]\n"); - fprintf(stderr, " [ -msglevel [0-8] ]\n"); - fprintf(stderr, " [ -powersave [on|vsync|hsync|powerdown|off] ]\n"); - fprintf(stderr, " [ -powerdown [0-60] ]\n"); - fprintf(stderr, " [ -blength [0-2000] ]\n"); - fprintf(stderr, " [ -bfreq freqnumber ]\n"); + fprintf(stderr, _(" [ -inversescreen [on|off] ]\n")); + fprintf(stderr, _(" [ -bold [on|off] ]\n")); + fprintf(stderr, _(" [ -half-bright [on|off] ]\n")); + fprintf(stderr, _(" [ -blink [on|off] ]\n")); + fprintf(stderr, _(" [ -reverse [on|off] ]\n")); + fprintf(stderr, _(" [ -underline [on|off] ]\n")); + fprintf(stderr, _(" [ -store ]\n")); + fprintf(stderr, _(" [ -clear [all|rest] ]\n")); + fprintf(stderr, _(" [ -tabs [ tab1 tab2 tab3 ... ] ] (tabn = 1-160)\n")); + fprintf(stderr, _(" [ -clrtabs [ tab1 tab2 tab3 ... ] ] (tabn = 1-160)\n")); + fprintf(stderr, _(" [ -regtabs [1-160] ]\n")); + fprintf(stderr, _(" [ -blank [0-60] ]\n")); + fprintf(stderr, _(" [ -dump [1-NR_CONSOLES] ]\n")); + fprintf(stderr, _(" [ -append [1-NR_CONSOLES] ]\n")); + fprintf(stderr, _(" [ -file dumpfilename ]\n")); + fprintf(stderr, _(" [ -msg [on|off] ]\n")); + fprintf(stderr, _(" [ -msglevel [0-8] ]\n")); + fprintf(stderr, _(" [ -powersave [on|vsync|hsync|powerdown|off] ]\n")); + fprintf(stderr, _(" [ -powerdown [0-60] ]\n")); + fprintf(stderr, _(" [ -blength [0-2000] ]\n")); + fprintf(stderr, _(" [ -bfreq freqnumber ]\n")); } char *ti_entry(name) @@ -833,16 +838,16 @@ int vcterm; /* Set if terminal is a virtual console. */ if (opt_keyboard && vcterm) { switch (opt_ke_type) { case PC: - printf("%s%s%s", DCS, "keyboard.pc", ST); + printf("%s%s%s", DCS, _("keyboard.pc"), ST); break; case OLIVETTI: - printf("%s%s%s", DCS, "keyboard.olivetti", ST); + printf("%s%s%s", DCS, _("keyboard.olivetti"), ST); break; case DUTCH: - printf("%s%s%s", DCS, "keyboard.dutch", ST); + printf("%s%s%s", DCS, _("keyboard.dutch"), ST); break; case EXTENDED: - printf("%s%s%s", DCS, "keyboard.extended", ST); + printf("%s%s%s", DCS, _("keyboard.extended"), ST); break; } } @@ -876,17 +881,17 @@ int vcterm; /* Set if terminal is a virtual console. */ /* -snow [on|off]. Vc only. */ if (opt_snow && vcterm) { if (opt_sn_on) - printf("%s%s%s", DCS, "snow.on", ST); + printf("%s%s%s", DCS, _("snow.on"), ST); else - printf("%s%s%s", DCS, "snow.off", ST); + printf("%s%s%s", DCS, _("snow.off"), ST); } /* -softscroll [on|off]. Vc only. */ if (opt_softscroll && vcterm) { if (opt_so_on) - printf("%s%s%s", DCS, "softscroll.on", ST); + printf("%s%s%s", DCS, _("softscroll.on"), ST); else - printf("%s%s%s", DCS, "softscroll.off", ST); + printf("%s%s%s", DCS, _("softscroll.off"), ST); } #endif @@ -1061,7 +1066,7 @@ int vcterm; /* Set if terminal is a virtual console. */ ioctlarg[0] = 10; /* powersave */ ioctlarg[1] = opt_ps_mode; if (ioctl(0,TIOCLINUX,ioctlarg)) - fprintf(stderr,"cannot (un)set powersave mode\n"); + fprintf(stderr,_("cannot (un)set powersave mode\n")); } /* -powerdown [0-60]. */ @@ -1082,7 +1087,7 @@ int vcterm; /* Set if terminal is a virtual console. */ F = fopen(opt_sn_name, opt_snap ? "w" : "a"); if (!F) { perror(opt_sn_name); - fprintf(stderr,"setterm: can not open dump file %s for output\n", + fprintf(stderr,("setterm: can not open dump file %s for output\n"), opt_sn_name); exit(-1); } @@ -1100,7 +1105,7 @@ int vcterm; /* Set if terminal is a virtual console. */ result = klogctl(6, NULL, 0); if (result != 0) - printf("klogctl error: %s\n", strerror(result)); + printf(_("klogctl error: %s\n"), strerror(result)); } /* -msglevel [0-8] */ @@ -1108,7 +1113,7 @@ int vcterm; /* Set if terminal is a virtual console. */ /* 8 -- Set level of messages printed to console */ result = klogctl(8, NULL, opt_msglevel_num); if (result != 0) - printf("klogctl error: %s\n", strerror(result)); + printf(_("klogctl error: %s\n"), strerror(result)); } /* -blength [0-2000] */ @@ -1145,11 +1150,11 @@ screendump(int vcnum, FILE *F){ inbuf = malloc(rows*cols*2); outbuf = malloc(rows*(cols+1)); if(!inbuf || !outbuf) { - fprintf(stderr, "Out of memory\n"); + fputs(_("Out of memory"), stderr); exit(1); } if (read(fd, inbuf, rows*cols*2) != rows*cols*2) { - fprintf(stderr, "Error reading %s\n", infile); + fprintf(stderr, _("Error reading %s\n"), infile); exit(1); } p = inbuf; @@ -1164,7 +1169,7 @@ screendump(int vcnum, FILE *F){ *q++ = '\n'; } if (fwrite(outbuf, 1, q-outbuf, F) != q-outbuf) { - fprintf(stderr, "Error writing screendump\n"); + fprintf(stderr, _("Error writing screendump\n")); exit(1); } return; @@ -1178,7 +1183,7 @@ try_ioctl: screenbuf[0] = 0; screenbuf[1] = (unsigned char) vcnum; if (ioctl(0,TIOCLINUX,screenbuf) < 0) { - fprintf(stderr,"couldn't read %s, and cannot ioctl dump\n", + fprintf(stderr,_("couldn't read %s, and cannot ioctl dump\n"), infile); exit(1); } @@ -1203,6 +1208,10 @@ int main(int argc, char **argv) char *term; /* Terminal type. */ int vcterm; /* Set if terminal is a virtual console. */ + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + if (argc < 2) bad_arg = TRUE; /* Parse arguments. */ @@ -1239,7 +1248,7 @@ int main(int argc, char **argv) } else { term = getenv("TERM"); if (term == NULL) { - fprintf(stderr, "%s: $TERM is not defined.\n", argv[0]); + fprintf(stderr, _("%s: $TERM is not defined.\n"), argv[0]); exit(1); } } diff --git a/misc-utils/tsort.c b/misc-utils/tsort.c index 61e9e8442..627897667 100644 --- a/misc-utils/tsort.c +++ b/misc-utils/tsort.c @@ -34,11 +34,16 @@ * SUCH DAMAGE. */ + /* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + * - added Native Language Support + */ + #include <sys/types.h> #include <errno.h> #include <stdio.h> #include <ctype.h> #include <string.h> +#include "nls.h" /* * Topological sort. Input is a list of pairs of strings seperated by @@ -102,12 +107,16 @@ main(argc, argv) int bsize, nused; BUF bufs[2]; + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + if (argc < 2) fp = stdin; /* == becomes > in next line per Volker Meyer_zu_Bexten <vmzb@ims.fhg.de> -- faith@cs.unc.edu, Sat Feb 4 21:25:09 1995 */ else if (argc > 2) { - (void)fprintf(stderr, "usage: tsort [ inputfile ]\n"); + (void)fprintf(stderr, _("usage: tsort [ inputfile ]\n")); exit(1); } else if (!(fp = fopen(argv[1], "r"))) { (void)fprintf(stderr, "tsort: %s.\n", strerror(errno)); @@ -144,7 +153,7 @@ main(argc, argv) } (void)fclose(fp); if (n) { - (void)fprintf(stderr, "tsort: odd data count.\n"); + (void)fprintf(stderr, _("tsort: odd data count.\n")); exit(1); } @@ -309,7 +318,7 @@ tsort() register int i; (void)fprintf(stderr, - "tsort: cycle in data.\n"); + _("tsort: cycle in data.\n")); for (i = 0; i < cnt; i++) (void)fprintf(stderr, "tsort: %s.\n", longest_cycle[i]->n_name); @@ -322,7 +331,7 @@ tsort() if (!n) { (void)fprintf(stderr, - "tsort: internal error -- could not find cycle.\n"); + _("tsort: internal error -- could not find cycle.\n")); exit(1); } } diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c index 494192417..cb07bc685 100644 --- a/misc-utils/whereis.c +++ b/misc-utils/whereis.c @@ -33,12 +33,17 @@ /* *:aeb */ +/* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + * - added Native Language Support + */ + #include <sys/param.h> #include <sys/dir.h> #include <sys/stat.h> #include <stdio.h> #include <string.h> #include <ctype.h> +#include "nls.h" void zerof(void); void getlist(int *, char ***, char ***, int *); @@ -142,11 +147,15 @@ main(argc, argv) int argc; char *argv[]; { + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + argc--, argv++; if (argc == 0) { usage: - fprintf(stderr, "whereis [ -sbmu ] [ -SBM dir ... -f ] name...\n"); + fprintf(stderr, _("whereis [ -sbmu ] [ -SBM dir ... -f ] name...\n")); exit(1); } do @@ -328,6 +337,9 @@ findin(char *dir, char *cp) { if (dirp == NULL) return; while ((dp = readdir(dirp)) != NULL) { + if (!strcmp(dp->d_name, ".") || + !strcmp(dp->d_name, "..")) + continue; if (strlen(dp->d_name) + l > sizeof(dirbuf)) continue; sprintf(d, "%s", dp->d_name); diff --git a/misc-utils/write.c b/misc-utils/write.c index 07a113ea7..cac26239e 100644 --- a/misc-utils/write.c +++ b/misc-utils/write.c @@ -40,6 +40,9 @@ * - Added fix from David.Chapell@mail.trincoll.edu enabeling daemons * to use write. * - ANSIed it since I was working on it anyway. + * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> + * - added Native Language Support + * */ #include <unistd.h> @@ -58,7 +61,8 @@ #include <paths.h> #include "pathnames.h" #endif - +#include "nls.h" + void search_utmp(char *, char *, char *, uid_t); void do_write(char *, char *, uid_t); void wr_fputs(char *); @@ -70,14 +74,15 @@ extern int errno; int main(int argc, char **argv) { - register char *cp; time_t atime; uid_t myuid; int msgsok, myttyfd; char tty[MAXPATHLEN], *mytty, *ttyname(); void done(); - setlocale(LC_CTYPE,""); + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); /* check that sender has write enabled */ if (isatty(fileno(stdin))) @@ -91,16 +96,18 @@ main(int argc, char **argv) } if (myttyfd != -1) { if (!(mytty = ttyname(myttyfd))) { - (void)fprintf(stderr, "write: can't find your tty's name\n"); + (void)fprintf(stderr, _("write: can't find your tty's name\n")); exit(1); } - if ((cp = rindex(mytty, '/')) != NULL) - mytty = cp + 1; + /* We may have /dev/ttyN but also /dev/pts/xx. + Below, term_chk() will put "/dev/" in front, so remove that part. */ + if (!strncmp(mytty, "/dev/", 5)) + mytty += 5; if (term_chk(mytty, &msgsok, &atime, 1)) exit(1); if (!msgsok) { (void)fprintf(stderr, - "write: you have write permission turned off.\n"); + _("write: you have write permission turned off.\n")); exit(1); } @@ -121,7 +128,7 @@ main(int argc, char **argv) argv[2] += 5; if (utmp_chk(argv[1], argv[2])) { (void)fprintf(stderr, - "write: %s is not logged in on %s.\n", + _("write: %s is not logged in on %s.\n"), argv[1], argv[2]); exit(1); } @@ -129,14 +136,14 @@ main(int argc, char **argv) exit(1); if (myuid && !msgsok) { (void)fprintf(stderr, - "write: %s has messages disabled on %s\n", + _("write: %s has messages disabled on %s\n"), argv[1], argv[2]); exit(1); } do_write(argv[2], mytty, myuid); break; default: - (void)fprintf(stderr, "usage: write user [tty]\n"); + (void)fprintf(stderr, _("usage: write user [tty]\n")); exit(1); } done(); @@ -235,7 +242,7 @@ void search_utmp(char *user, char *tty, char *mytty, uid_t myuid) endutent(); if (nloggedttys == 0) { - (void)fprintf(stderr, "write: %s is not logged in\n", user); + (void)fprintf(stderr, _("write: %s is not logged in\n"), user); exit(1); } if (nttys == 0) { @@ -244,11 +251,11 @@ void search_utmp(char *user, char *tty, char *mytty, uid_t myuid) return; } (void)fprintf(stderr, - "write: %s has messages disabled\n", user); + _("write: %s has messages disabled\n"), user); exit(1); } else if (nttys > 1) { (void)fprintf(stderr, - "write: %s is logged in more than once; writing to %s\n", + _("write: %s is logged in more than once; writing to %s\n"), user, tty); } } @@ -314,8 +321,10 @@ void do_write(char *tty, char *mytty, uid_t myuid) now = time((time_t *)NULL); nows = ctime(&now); nows[16] = '\0'; - (void)printf("\r\n\007\007\007Message from %s@%s on %s at %s ...\r\n", + printf("\r\n\007\007\007"); + (void)printf(_("Message from %s@%s on %s at %s ..."), login, host, mytty, nows + 11); + printf("\r\n"); while (fgets(line, sizeof(line), stdin) != NULL) wr_fputs(line); |