diff options
Diffstat (limited to 'misc-utils')
-rw-r--r-- | misc-utils/Makefile | 6 | ||||
-rw-r--r-- | misc-utils/cal.1 | 8 | ||||
-rw-r--r-- | misc-utils/cal.c | 113 | ||||
-rw-r--r-- | misc-utils/ddate.c | 3 | ||||
-rw-r--r-- | misc-utils/logger.1 | 7 | ||||
-rw-r--r-- | misc-utils/logger.c | 24 | ||||
-rw-r--r-- | misc-utils/look.c | 24 | ||||
-rw-r--r-- | misc-utils/namei.c | 1 | ||||
-rw-r--r-- | misc-utils/procs.c | 4 | ||||
-rw-r--r-- | misc-utils/script.1 | 14 | ||||
-rw-r--r-- | misc-utils/script.c | 74 | ||||
-rw-r--r-- | misc-utils/whereis.c | 2 | ||||
-rw-r--r-- | misc-utils/write.c | 64 |
13 files changed, 264 insertions, 80 deletions
diff --git a/misc-utils/Makefile b/misc-utils/Makefile index 088d2ccee..5b74dd39e 100644 --- a/misc-utils/Makefile +++ b/misc-utils/Makefile @@ -21,6 +21,8 @@ BIN= kill USRBIN= cal chkdupexe ddate logger look mcookie \ namei rename script whereis write +MAYBE= reset setterm tsort + ifeq "$(HAVE_RESET)" "no" USRBIN:=$(USRBIN) reset MAN1:=$(MAN1) reset.1 @@ -79,6 +81,8 @@ mcookie.o: mcookie.c md5.h md5.o: md5.c md5.h reset: reset.sh script: script.o +write.o: $(LIB)/carefulputc.h +write: write.o $(LIB)/carefulputc.o ifeq "$(HAVE_NCURSES)" "yes" setterm: setterm.o @@ -97,4 +101,4 @@ endif .PHONY: clean clean: - -rm -f *.o *~ core $(BIN) $(USRBIN) + -rm -f *.o *~ core $(BIN) $(USRBIN) $(MAYBE) diff --git a/misc-utils/cal.1 b/misc-utils/cal.1 index 6a5ec5ae5..9bade9d0b 100644 --- a/misc-utils/cal.1 +++ b/misc-utils/cal.1 @@ -42,7 +42,7 @@ .Nd displays a calendar .Sh SYNOPSIS .Nm cal -.Op Fl mjy +.Op Fl mjy13 .Op Ar month Op Ar year .Sh DESCRIPTION .Nm Cal @@ -51,6 +51,12 @@ If arguments are not specified, the current month is displayed. The options are as follows: .Bl -tag -width Ds +.It Fl 1 +Display single month output (use if cal was built with -3 as default to get +older traditional output) +.It Fl 3 +Display prev/current/next month output (use if cal was built with traditional +-1 as default to get newer improved output) .It Fl m Display Monday as the first day of the week. (The default is Sunday.) diff --git a/misc-utils/cal.c b/misc-utils/cal.c index bc0c1eff5..aba1b6f06 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -39,6 +39,12 @@ * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> * - added Native Language Support * + * 2000-09-01 Michael Charles Pruznick <dummy@netwiz.net> + * Added "-3" option to print prev/next month with current. + * Added over-ridable default NUM_MONTHS and "-1" option to + * get traditional output when -3 is the default. I hope that + * enough people will like -3 as the default that one day the + * product can be shipped that way. */ #include <sys/types.h> @@ -60,6 +66,15 @@ # include <localeinfo.h> /* libc4 only */ #endif +/* allow compile-time define to over-ride default */ +#ifndef NUM_MONTHS +#define NUM_MONTHS 1 +#endif + +#if ( NUM_MONTHS != 1 && NUM_MONTHS !=3 ) +#error NUM_MONTHS must be 1 or 3 +#endif + #define THURSDAY 4 /* for reformation */ #define SATURDAY 6 /* 1 Jan 1 was a Saturday */ @@ -102,7 +117,7 @@ int sep1752[MAXDAYS] = { char day_headings[] = " S M Tu W Th F S "; /* week1stday = 1 => " M Tu W Th F S S " */ -char j_day_headings[] = " S M Tu W Th F S "; +char j_day_headings[] = "Sun Mon Tue Wed Thu Fri Sat "; /* week1stday = 1 => " M Tu W Th F S S " */ const char *full_month[12]; @@ -127,13 +142,22 @@ const char *full_month[12]; int week1stday; int julian; +#define FMT_ST_LINES 8 +#define FMT_ST_CHARS 300 /* 90 suffices in most locales */ +struct fmt_st +{ + char s[FMT_ST_LINES][FMT_ST_CHARS]; +}; + void ascii_day __P((char *, int)); void center __P((const char *, int, int)); void day_array __P((int, int, int *)); int day_in_week __P((int, int, int)); int day_in_year __P((int, int, int)); void j_yearly __P((int)); +void do_monthly __P((int, int, struct fmt_st*)); void monthly __P((int, int)); +void monthly3 __P((int, int)); void trim_trailing_spaces __P((char *)); void usage __P((void)); void yearly __P((int)); @@ -146,6 +170,7 @@ main(int argc, char **argv) { time_t now; int ch, month, year, yflag; char *progname, *p; + int num_months = NUM_MONTHS; progname = argv[0]; if ((p = strrchr(progname, '/')) != NULL) @@ -157,8 +182,14 @@ main(int argc, char **argv) { textdomain(PACKAGE); yflag = 0; - while ((ch = getopt(argc, argv, "mjy")) != EOF) + while ((ch = getopt(argc, argv, "13mjyV")) != EOF) switch(ch) { + case '1': + num_months = 1; + break; + case '3': + num_months = 3; + break; case 'm': week1stday = 1; break; @@ -201,8 +232,10 @@ main(int argc, char **argv) { } headers_init(); - if (month) + if (month && num_months == 1) monthly(month, year); + else if (month && num_months == 3) + monthly3(month, year); else if (julian) j_yearly(year); else @@ -233,7 +266,7 @@ void headers_init(void) for(i = 0 ; i < 7 ; i++ ) { wd = (i + week1stday) % 7; strncat(day_headings,weekday(wd),2); - strcat(j_day_headings,weekday(wd)); + strncat(j_day_headings,weekday(wd),3); if (strlen(weekday(wd)) == 2) strcat(j_day_headings," "); strcat(day_headings," "); @@ -252,24 +285,86 @@ void headers_init(void) } void -monthly(month, year) +do_monthly(month, year, out) int month, year; + struct fmt_st* out; { int col, row, len, days[MAXDAYS]; char *p, lineout[300]; day_array(month, year, days); len = sprintf(lineout, "%s %d", full_month[month - 1], year); - (void)printf("%*s%s\n%s\n", - ((julian ? J_WEEK_LEN : WEEK_LEN) - len) / 2, "", - lineout, julian ? j_day_headings : day_headings); + (void)sprintf(out->s[0],"%*s%s", + ((julian ? J_WEEK_LEN : WEEK_LEN) - len) / 2, "", lineout ); + (void)sprintf(out->s[1],"%s", + julian ? j_day_headings : day_headings); for (row = 0; row < 6; row++) { for (col = 0, p = lineout; col < 7; col++, p += julian ? J_DAY_LEN : DAY_LEN) ascii_day(p, days[row * 7 + col]); *p = '\0'; trim_trailing_spaces(lineout); - (void)printf("%s\n", lineout); + (void)sprintf(out->s[row+2],"%s", lineout); + } +} + +void +monthly(month, year) + int month, year; +{ + int i; + struct fmt_st out; + + do_monthly(month, year, &out); + for ( i = 0; i < FMT_ST_LINES; i++ ) + { + printf("%s\n", out.s[i]); + } +} + +void +monthly3(month, year) + int month, year; +{ + int i; + int width; + struct fmt_st out_prev; + struct fmt_st out_curm; + struct fmt_st out_next; + int prev_month, prev_year; + int next_month, next_year; + + if ( month == 1 ) + { + prev_month = 12; + prev_year = year - 1; + } + else + { + prev_month = month - 1; + prev_year = year; + } + if ( month == 12 ) + { + next_month = 1; + next_year = year + 1; + } + else + { + next_month = month + 1; + next_year = year; + } + + do_monthly(prev_month, prev_year, &out_prev); + do_monthly(month, year, &out_curm); + do_monthly(next_month, next_year, &out_next); + width = (julian ? J_WEEK_LEN : WEEK_LEN); + for ( i = 0; i < FMT_ST_LINES; i++ ) + { + printf("%-*.*s %-*.*s %-*.*s\n", + width, width, out_prev.s[i], + width, width, out_curm.s[i], + width, width, out_next.s[i] ); } } diff --git a/misc-utils/ddate.c b/misc-utils/ddate.c index 304c31c60..bf7a37f28 100644 --- a/misc-utils/ddate.c +++ b/misc-utils/ddate.c @@ -153,8 +153,7 @@ struct disc_time convert(int,int); struct disc_time makeday(int,int,int); int -main (int argc, char *argv[]) -{ +main (int argc, char *argv[]) { long t; struct tm *eris; int bob,raw; diff --git a/misc-utils/logger.1 b/misc-utils/logger.1 index b5459ed4c..2c154ec09 100644 --- a/misc-utils/logger.1 +++ b/misc-utils/logger.1 @@ -41,7 +41,7 @@ .Nd make entries in the system log .Sh SYNOPSIS .Nm logger -.Op Fl is +.Op Fl isd .Op Fl f Ar file .Op Fl p Ar pri .Op Fl t Ar tag @@ -80,11 +80,12 @@ Mark every line in the log with the specified Write to socket as specified with .Ar socket instead of builtin syslog routines. +.It Fl d +Use a datagram instead of a stream connection to this socket. .It -- End the argument list. This is to allow the .Ar message -to start with a hyphen (\-). This feature was not present in the -original BSD logger command; it is a GNU-specific extra. +to start with a hyphen (\-). .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 372fe1ece..ae0ebec00 100644 --- a/misc-utils/logger.c +++ b/misc-utils/logger.c @@ -45,6 +45,7 @@ #include <string.h> #include <sys/types.h> #include <sys/socket.h> +#include <sys/un.h> #include "nls.h" #define SYSLOG_NAMES @@ -54,20 +55,27 @@ int decode __P((char *, CODE *)); int pencode __P((char *)); void usage __P((void)); +static int optd = 0; + static int myopenlog(const char *sock) { int fd; - static struct sockaddr s_addr; /* AF_UNIX address of local logger */ + static struct sockaddr_un s_addr; /* AF_UNIX address of local logger */ + + if (strlen(sock) >= sizeof(s_addr.sun_path)) { + printf ("logger: openlog: pathname too long\n"); + exit(1); + } - s_addr.sa_family = AF_UNIX; - (void)strncpy(s_addr.sa_data, sock, sizeof(s_addr.sa_data)); + s_addr.sun_family = AF_UNIX; + (void)strcpy(s_addr.sun_path, sock); - if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { + if ((fd = socket(AF_UNIX, optd ? SOCK_DGRAM : 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) { + if (connect(fd, (struct sockaddr *) &s_addr, sizeof(s_addr)) == -1) { printf ("connect: %s.\n", strerror(errno)); exit (1); } @@ -80,7 +88,6 @@ mysyslog(int fd, int logflags, int pri, char *tag, char *msg) { 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()); @@ -125,7 +132,7 @@ main(int argc, char **argv) { tag = NULL; pri = LOG_NOTICE; logflags = 0; - while ((ch = getopt(argc, argv, "f:ip:st:u:")) != EOF) + while ((ch = getopt(argc, argv, "f:ip:st:u:d")) != EOF) switch((char)ch) { case 'f': /* file to log */ if (freopen(optarg, "r", stdin) == NULL) { @@ -150,6 +157,9 @@ main(int argc, char **argv) { case 'u': /* unix socket */ usock = optarg; break; + case 'd': + optd = 1; /* use datagrams */ + break; case '?': default: usage(); diff --git a/misc-utils/look.c b/misc-utils/look.c index a8e826fa4..d601e1c97 100644 --- a/misc-utils/look.c +++ b/misc-utils/look.c @@ -137,13 +137,25 @@ main(int argc, char *argv[]) if ((fd = open(file, O_RDONLY, 0)) < 0 || fstat(fd, &sb)) err("%s: %s", file, strerror(errno)); - if ((void *)(front = mmap(NULL, - (size_t)sb.st_size, - PROT_READ, - MAP_FILE|MAP_SHARED, - fd, - (off_t)0)) <= (void *)0) + front = mmap(NULL, (size_t) sb.st_size, PROT_READ, +#ifdef MAP_FILE + MAP_FILE | +#endif + MAP_SHARED, fd, (off_t) 0); + if +#ifdef MAP_FAILED + (front == MAP_FAILED) +#else + ((void *)(front) <= (void *)0) +#endif err("%s: %s", file, strerror(errno)); + +#if 0 + /* workaround for mmap problem (rmiller@duskglow.com) */ + if (front == (void *)0) + return 1; +#endif + back = front + sb.st_size; return look(front, back); } diff --git a/misc-utils/namei.c b/misc-utils/namei.c index 65faad4f3..f77d501c4 100644 --- a/misc-utils/namei.c +++ b/misc-utils/namei.c @@ -47,6 +47,7 @@ chdir to /, or if it encounters an unknown file type. #include <stdio.h> #include <unistd.h> #include <string.h> +#include <stdlib.h> #include <errno.h> #include <sys/types.h> #include <sys/stat.h> diff --git a/misc-utils/procs.c b/misc-utils/procs.c index 715d9fb09..3f52387de 100644 --- a/misc-utils/procs.c +++ b/misc-utils/procs.c @@ -14,14 +14,14 @@ #define _POSIX_SOURCE 1 +#include <sys/types.h> +#include <sys/stat.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <dirent.h> #include <ctype.h> #include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> #include "kill.h" extern char *mybasename (char *); diff --git a/misc-utils/script.1 b/misc-utils/script.1 index ddc35223d..3edd82d4b 100644 --- a/misc-utils/script.1 +++ b/misc-utils/script.1 @@ -31,15 +31,17 @@ .\" .\" @(#)script.1 6.5 (Berkeley) 7/27/91 .\" -.Dd July 27, 1991 +.Dd July 30, 2000 .Dt SCRIPT 1 -.Os BSD 4 +.Os Linux .Sh NAME .Nm script .Nd make typescript of terminal session .Sh SYNOPSIS .Nm script .Op Fl a +.Op Fl f +.Op Fl q .Op Ar file .Sh DESCRIPTION .Nm Script @@ -58,7 +60,7 @@ saves all dialogue in If no file name is given, the typescript is saved in the file .Pa typescript . .Pp -Option: +Options: .Bl -tag -width Ds .It Fl a Append the output to @@ -66,6 +68,12 @@ Append the output to or .Pa typescript , retaining the prior contents. +.It Fl f +Flush output after each write. This is nice for telecooperation: +One person does `mkfifo foo; script -f foo' and another can +supervise real-time what is being done using `cat foo'. +.It Fl q +Be quiet. .El .Pp The script ends when the forked shell exits (a diff --git a/misc-utils/script.c b/misc-utils/script.c index cb7ae1a96..c3bf142e6 100644 --- a/misc-utils/script.c +++ b/misc-utils/script.c @@ -31,8 +31,11 @@ * SUCH DAMAGE. */ -/* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> +/* + * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> * - added Native Language Support + * + * 2000-07-30 Per Andreas Buer <per@linpro.no> - added "q"-option */ /* @@ -86,25 +89,65 @@ int l; #ifndef HAVE_openpty char line[] = "/dev/ptyXX"; #endif -int aflg; +int aflg = 0; +int fflg = 0; +int qflg = 0; + +static char *progname; + +static void +die_if_symlink(char *fn) { + struct stat s; + + if (lstat(fn, &s) == 0 && S_ISLNK(s.st_mode)) { + fprintf(stderr, + _("Warning: `%s' is a symlink.\n" + "Use `%s [options] %s' if you really " + "want to use it.\n" + "Script not started.\n"), + fn, progname, fn); + exit(1); + } +} int main(int argc, char **argv) { extern int optind; + char *p; int ch; + progname = argv[0]; + if ((p = strrchr(progname, '/')) != NULL) + progname = p+1; + + setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - while ((ch = getopt(argc, argv, "a")) != EOF) + if (argc == 2) { + if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) { + printf(_("%s from %s\n"), + progname, util_linux_version); + return 0; + } + } + + while ((ch = getopt(argc, argv, "afq")) != EOF) switch((char)ch) { case 'a': aflg++; break; + case 'f': + fflg++; + break; + case 'q': + qflg++; + break; case '?': default: - fprintf(stderr, _("usage: script [-a] [file]\n")); + fprintf(stderr, + _("usage: script [-a] [-f] [-q] [file]\n")); exit(1); } argc -= optind; @@ -112,8 +155,10 @@ main(int argc, char **argv) { if (argc > 0) fname = argv[0]; - else + else { fname = "typescript"; + die_if_symlink(fname); + } if ((fscript = fopen(fname, aflg ? "a" : "w")) == NULL) { perror(fname); fail(); @@ -124,7 +169,8 @@ main(int argc, char **argv) { shell = _PATH_BSHELL; getmaster(); - printf(_("Script started, file is %s\n"), fname); + if (!qflg) + printf(_("Script started, file is %s\n"), fname); fixtty(); (void) signal(SIGCHLD, finish); @@ -167,11 +213,11 @@ doinput() { void finish(int dummy) { - union wait status; + int status; register int pid; register int die = 0; - while ((pid = wait3((int *)&status, WNOHANG, 0)) > 0) + while ((pid = wait3(&status, WNOHANG, 0)) > 0) if (pid == child) die = 1; @@ -197,6 +243,8 @@ dooutput() { break; (void) write(1, obuf, cc); (void) fwrite(obuf, 1, cc, fscript); + if (fflg) + (void) fflush(fscript); } done(); } @@ -250,13 +298,17 @@ done() { time_t tvec; if (subchild) { - tvec = time((time_t *)NULL); - fprintf(fscript,_("\nScript done on %s"), ctime(&tvec)); + if (!qflg) { + tvec = time((time_t *)NULL); + 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); + if (!qflg) + printf(_("Script done, file is %s\n"), fname); } exit(0); } diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c index bc505c54f..239b1f4ae 100644 --- a/misc-utils/whereis.c +++ b/misc-utils/whereis.c @@ -41,6 +41,7 @@ #include <sys/dir.h> #include <sys/stat.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <ctype.h> #include "nls.h" @@ -111,6 +112,7 @@ static char *bindirs[] = { static char *mandirs[] = { "/usr/man/*", + "/usr/share/man/*", "/usr/X386/man/*", "/usr/X11/man/*", "/usr/TeX/man/*", diff --git a/misc-utils/write.c b/misc-utils/write.c index 1cf99c7f0..e794a4eee 100644 --- a/misc-utils/write.c +++ b/misc-utils/write.c @@ -53,6 +53,7 @@ #include <time.h> #include <pwd.h> #include <string.h> +#include <stdlib.h> #include <locale.h> #include <signal.h> #include <sys/param.h> @@ -60,10 +61,9 @@ #include <sys/stat.h> #include <sys/file.h> #include <sys/time.h> -#ifdef __linux__ #include <paths.h> #include "pathnames.h" -#endif +#include "carefulputc.h" #include "nls.h" void search_utmp(char *, char *, char *, uid_t); @@ -73,7 +73,6 @@ static void done(int); int term_chk(char *, int *, time_t *, int); int utmp_chk(char *, char *); - int main(int argc, char **argv) { time_t atime; @@ -289,24 +288,25 @@ int term_chk(char *tty, int *msgsokP, time_t *atimeP, int showerror) * do_write - actually make the connection */ void do_write(char *tty, char *mytty, uid_t myuid) { - register char *login, *nows; - register struct passwd *pwd; + char *login, *pwuid, *nows; + struct passwd *pwd; time_t now; char path[MAXPATHLEN], host[MAXHOSTNAMELEN], line[512]; - /* Determine our login name before the we reopen() stdout */ - if ((login = getlogin()) == NULL) { - if ((pwd = getpwuid(myuid)) != NULL) - login = pwd->pw_name; - else - login = "???"; - } + /* Determine our login name(s) before the we reopen() stdout */ + if ((pwd = getpwuid(myuid)) != NULL) + pwuid = pwd->pw_name; + else + pwuid = "???"; + if ((login = getlogin()) == NULL) + login = pwuid; if (strlen(tty) + 6 > sizeof(path)) exit(1); (void)sprintf(path, "/dev/%s", tty); if ((freopen(path, "w", stdout)) == NULL) { - (void)fprintf(stderr, "write: %s: %s\n", path, strerror(errno)); + (void)fprintf(stderr, "write: %s: %s\n", + path, strerror(errno)); exit(1); } @@ -320,8 +320,12 @@ void do_write(char *tty, char *mytty, uid_t myuid) { nows = ctime(&now); nows[16] = '\0'; printf("\r\n\007\007\007"); - (void)printf(_("Message from %s@%s on %s at %s ..."), - login, host, mytty, nows + 11); + if (strcmp(login, pwuid)) + (void)printf(_("Message from %s@%s (as %s) on %s at %s ..."), + login, host, pwuid, mytty, nows + 11); + else + (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) @@ -339,34 +343,24 @@ done(int dummy) { /* * wr_fputs - like fputs(), but makes control characters visible and - * turns \n into \r\n + * turns \n into \r\n. */ -void wr_fputs(char *s) - -{ +void +wr_fputs(char *s) { char c; -#define PUTC(c) if (putchar(c) == EOF) goto err; +#define PUTC(c) if (carefulputc(c,stdout) == EOF) goto err; - for (; *s != '\0'; ++s) { - c = *s; - if (c == '\n') { + while(*s) { + c = *s++; + if (c == '\n') PUTC('\r'); - PUTC('\n'); - } else if (!isprint(c) && !isspace(c) && c != '\007') { - if (c & 0x80) { - /* use some fallback? */ - (void)printf("\\%3o", (unsigned char) c); - } else { - PUTC('^'); - PUTC(c^0x40); /* DEL to ?, others to alpha */ - } - } else - PUTC(c); + PUTC(c); } return; -err: (void)fprintf(stderr, "write: %s\n", strerror(errno)); +err: + fprintf(stderr, "write: %s\n", strerror(errno)); exit(1); #undef PUTC } |