ast@cs.vu.nl (Andy Tanenbaum) (09/28/88)
: This is a shar archive. Extract with sh, not csh. : This archive ends with exit, so do not worry about trailing junk. : --------------------------- cut here -------------------------- PATH=/bin:/usr/bin:/usr/ucb echo Extracting 'more.c' sed 's/^X//' > 'more.c' << '+ END-OF-FILE ''more.c' X/* more - terminal pager Author: Brandon S. Allbery */ X X/* Temporary fixes: efth 1988-Aug-16 X - don't display directories and special files X - don't die on files with '\0' in them X - don't print non-ASCII characters X - use termcap for #lines, normal, reverse, clear-line X */ X X X/* Pager commands: X * <space> display next page X * <return> scroll up 1 line X * q quit X*/ X Xchar *SO, *SE, *CD; X X#define reverse() write(1, SO, strlen(SO)) /* reverse video */ X#define normal() write(1, SE, strlen(SE)) /* undo reverse() */ X#define clearln() write(1,"\r",1); \ X write(1, CD, strlen(CD)) /* clear line */ X Xint lines; /* lines/screen (- 2 to retain last line) */ X X#define COLS 80 /* columns/line */ X#define TABSTOP 8 /* tabstop expansion */ X X#include <sys/types.h> X#include <sys/stat.h> X#include <sgtty.h> X#include <signal.h> X Xextern int byebye(); Xextern char *index(); X Xint line = 0; /* current terminal line */ Xint col = 0; /* current terminal column */ Xint fd = -1; /* terminal file descriptor (/dev/tty) */ Xstruct sgttyb ttymode; /* and the terminal modes */ Xchar ibuf[1024]; /* input buffer */ Xchar obuf[1024]; /* output buffer */ Xint ibl = 0; /* chars in input buffer */ Xint ibc = 0; /* position in input buffer */ Xint obc = 0; /* position in output buffer (== chars in) */ Xint isrewind = 0; /* flag: ' command -- next input() rewind */ Xint isdone = 0; /* flag: return EOF next read even if not */ X Xmain(argc, argv) Xchar **argv; { X int ch; X int fd, arg; X struct stat s; X X get_termcap(); X X signal(SIGINT, byebye); X fd = 0; X cbreak(); X if (argc < 2) X while ((ch = input(fd)) != -1) X output(ch); X else X for (arg = 1; argv[arg] != (char *) 0; arg++) { X if ((fd = open(argv[arg], 0)) == -1) { X write(1, "more: cannot open ", 18); X write(1, argv[arg], strlen(argv[arg])); X write(1, "\n", 1); X nocbreak(); X exit(1); X } X X if ( fstat(fd,&s) < 0 ) { X write( 1, "more: can not fstat file\n", 25 ); X nocbreak(); X exit(1); X } X X if ( (s.st_mode & S_IFMT) == S_IFREG ) X while ((ch = input(fd)) != -1) X output(ch); X else X write(1, "not file\n", 9 ); X X close(fd); X if (argv[arg + 1] != (char *) 0) { X oflush(); X if (isdone) { /* 'n' command */ X reverse(); X write(1, "*** Skipping to next file ***\n", 30); X normal(); X isdone = 0; X } X reverse(); X write(1, "--More-- (Next file: ", 21); X write(1, argv[arg + 1], strlen(argv[arg + 1])); X write(1, ")", 1); X normal(); X switch (wtch()) { X case ' ': X case '\'': X case 'n': X case 'N': X line = 0; X break; X case '\r': X case '\n': X line = lines - 1; X break; X case 'q': X case 'Q': X clearln(); X byebye(); X } X clearln(); X } X } X oflush(); X byebye(); X} X Xinput(fd) { X if (isdone) { X ibl = 0; X ibc = 0; X return -1; X } X if (isrewind) { X lseek(fd, 0L, 0); X ibl = 0; X ibc = 0; X isrewind = 0; X } X if (ibc == ibl) { X ibc = 0; X if ((ibl = read(fd, ibuf, sizeof ibuf)) <= 0) X return -1; X } X return ibuf[ibc++] & 0xff; X} X Xoutput(c) Xchar c; { X if (obc == sizeof obuf) { X lwrite(1, obuf, sizeof obuf); X obc = 0; X } X if (!isrewind) X obuf[obc++] = c; X} X Xoflush() { X if (!isdone) X lwrite(1, obuf, obc); X obc = 0; X} X Xlwrite(fd, buf, len) Xchar *buf; Xunsigned len; { X unsigned here, start; X char cmd; X X start = 0; X here = 0; X while (here != len) { X cmd = '\0'; X switch (buf[here++]) { X case '\n': X col = 0; X if (++line == lines) { X write(fd, buf + start, here - start); X reverse(); X write(1, "--More--", 8); X normal(); X cmd = wtch(); X clearln(); X line = 0; X start = here; X } X break; X case '\r': X col = 0; X break; X case '\b': X if (col != 0) X col--; X else { X line--; X col = COLS - 1; X } X break; X case '\t': X do { X col++; X } while (col % TABSTOP != 0); X break; X default: X if ( buf[here-1] < ' ' || (buf[here-1] & 0x80) ) X buf[here-1] = '?'; X if (++col == COLS) { X col = 0; X if (++line == lines) { X write(fd, buf + start, here - start); X reverse(); X write(1, "--More--", 8); X normal(); X cmd = wtch(); X clearln(); X line = 0; X start = here; X } X } X } X switch (cmd) { X case '\0': X break; X case ' ': X line = 0; X break; X case '\r': X case '\n': X line = lines - 1; X break; X case 'q': X case 'Q': X byebye(); X case '\'': X isrewind = 1; X reverse(); X write(1, "*** Back ***\n", 13); X normal(); X return; X case 'n': X case 'N': X isdone = 1; X return; X default: X break; X } X } X if (here != start) X write(fd, buf + start, here - start); X} X Xwtch() { X char ch; X X do { X read(fd, &ch, 1); X } while (index(" \r\nqQ'nN", ch) == (char *) 0); X return ch; X} X Xcbreak() { X if (fd != -1) X return; X if ((fd = open("/dev/tty", 0)) == -1) { X write(2, "OOPS -- can't open /dev/tty\n", 28); X exit(1); X } X ioctl(fd, TIOCGETP, &ttymode); X ttymode.sg_flags |= CBREAK; X ttymode.sg_flags &= ~ECHO; X ioctl(fd, TIOCSETP, &ttymode); /* NB: add TIOCSETN! */ X} X Xnocbreak() { X if (fd == -1) X return; X ttymode.sg_flags &= ~CBREAK; X ttymode.sg_flags |= ECHO; X ioctl(fd, TIOCSETP, &ttymode); X close(fd); X fd = -1; X} X Xbyebye() { X nocbreak(); X exit(0); X} X X X Xget_termcap() X { X static char termbuf[50]; X extern char *tgetstr(), *getenv(); X char *loc = termbuf; X char entry[1024]; X X if (tgetent(entry, getenv("TERM")) <= 0) { X printf("Unknown terminal.\n"); X exit(1); X } X X lines = tgetnum("li" ) - 2; X X SO = tgetstr("so", &loc); X SE = tgetstr("se", &loc); X CD = tgetstr("cd", &loc); X X if ( CD == (char *) 0 ) X CD = " \r"; X } + END-OF-FILE more.c chmod 'u=rw,g=r,o=r' 'more.c' set `wc -c 'more.c'` count=$1 case $count in 5582) :;; *) echo 'Bad character count in ''more.c' >&2 echo 'Count should be 5582' >&2 esac echo Extracting 'mount.c.cdif' sed 's/^X//' > 'mount.c.cdif' << '+ END-OF-FILE ''mount.c.cdif' X*** /local/ast/minix/tape3b/commands/mount.c Wed Jul 13 13:11:08 1988 X--- mount.c Sun Sep 25 15:25:07 1988 X*************** X*** 30,36 **** X } X std_err(argv[1]); X std_err(" mounted\n"); X! if ((fd = open("/etc/mtab", 2)) < 0) exit(1); X lseek(fd, 0L, 2); /* seek to EOF */ X write(fd, argv[1], strlen(argv[1])); X write(fd, " is mounted on ", 15); X--- 30,36 ---- X } X std_err(argv[1]); X std_err(" mounted\n"); X! if ((fd = open(mounttable, 2)) < 0) exit(1); X lseek(fd, 0L, 2); /* seek to EOF */ X write(fd, argv[1], strlen(argv[1])); X write(fd, " is mounted on ", 15); + END-OF-FILE mount.c.cdif chmod 'u=rw,g=r,o=r' 'mount.c.cdif' set `wc -c 'mount.c.cdif'` count=$1 case $count in 602) :;; *) echo 'Bad character count in ''mount.c.cdif' >&2 echo 'Count should be 602' >&2 esac echo Extracting 'mv.c.cdif' sed 's/^X//' > 'mv.c.cdif' << '+ END-OF-FILE ''mv.c.cdif' X*** /local/ast/minix/tape3b/commands/mv.c Wed Jul 13 13:11:08 1988 X--- mv.c Sun Sep 25 15:25:07 1988 X*************** X*** 1,13 **** X /* mv - move files Author: Adri Koppes X * X * 4/25/87 - J. Paradis Bug fixes for directory handling X */ X X #include <signal.h> X- #include <sys/types.h> X #include <sys/stat.h> X X! int error = 0; X struct stat st, st1; X X main (argc, argv) X--- 1,14 ---- X /* mv - move files Author: Adri Koppes X * X * 4/25/87 - J. Paradis Bug fixes for directory handling X+ * 3/15/88 - P. Housel More directory bug fixes X */ X X #include <signal.h> X #include <sys/stat.h> X X! extern char *rindex(); X! X struct stat st, st1; X X main (argc, argv) X*************** X*** 47,53 **** X while (--argc) X move (*++argv, destdir); X } X- if (error) exit (1); X exit(0); X } X X--- 48,53 ---- X*************** X*** 57,65 **** X { X int retval; X char name[64]; X X /* It's too dangerous to fool with "." or ".." ! */ X! if((strcmp(old, ".") == 0) || (strcmp(old, "..") == 0)) { X cant(old); X } X X--- 57,73 ---- X { X int retval; X char name[64]; X+ char parent[64]; X+ char *oldbase; X+ int i; X X+ if((oldbase = rindex(old, '/')) == 0) X+ oldbase = old; X+ else X+ ++oldbase; X+ X /* It's too dangerous to fool with "." or ".." ! */ X! if((strcmp(oldbase, ".") == 0) || (strcmp(oldbase, "..") == 0)) { X cant(old); X } X X*************** X*** 68,91 **** X st.st_ino == st1.st_ino) X cant(old); X X! if (!stat (new, &st)) X! if((st.st_mode & S_IFMT) != S_IFDIR) X unlink (new); X else { X! char *p, *rindex(); X X! if ((strlen(old) + strlen(new) + 2) > 64) { X cant(old); X! error++; X! return; X } X- strcpy(name, new); X- strcat(name, "/"); X- p = rindex(old, '/'); X- strcat(name, p ? p : old); X- new = name; X } X! stat (old, &st); X if (link (old, new)) X if ((st.st_mode & S_IFMT) != S_IFDIR) { X switch (fork ()) { X--- 76,137 ---- X st.st_ino == st1.st_ino) X cant(old); X X! /* If source is not writeable, don't move it. */ X! if (access(old, 2) != 0) cant(old); X! X! if (stat (new, &st1) == 0) X! if((st1.st_mode & S_IFMT) != S_IFDIR) X unlink (new); X+ else { X+ if ((strlen(oldbase) + strlen(new) + 2) > 64) { X+ cant(old); X+ } X+ strcpy(name, new); X+ strcat(name, "/"); X+ strcat(name, oldbase); X+ new = name; X+ X+ /* do the 'move-to-itself' check again for the new name */ X+ if (stat(new, &st1)==0 && st.st_dev == st1.st_dev X+ && st.st_ino == st1.st_ino) X+ cant(old); X+ } X+ X+ strcpy(parent, new); X+ X+ for(i = (strlen(parent) - 1); i > 0; i--) { X+ if(parent[i] == '/') break; X+ } X+ X+ if(i == 0) { X+ strcpy(parent, "."); X+ } X else { X! /* null-terminate name at last slash */ X! parent[i] = '\0'; X! } X X! /* prevent moving a directory into its own subdirectory */ X! if((st.st_mode & S_IFMT) == S_IFDIR) { X! char lower[128]; X! short int prevdev = -1; X! unsigned short previno; X! X! strcpy(lower, parent); X! while(1) { X! if(stat(lower, &st1) || (st1.st_dev == st.st_dev X! && st1.st_ino == st.st_ino)) X cant(old); X! X! /* stop at root */ X! if(st1.st_dev == prevdev && st1.st_ino == previno) X! break; X! prevdev = st1.st_dev; X! previno = st1.st_ino; X! strcat(lower, "/.."); X } X } X! X if (link (old, new)) X if ((st.st_mode & S_IFMT) != S_IFDIR) { X switch (fork ()) { X*************** X*** 110,141 **** X ** where else in the tree...) X */ X if ((st.st_mode & S_IFMT) == S_IFDIR) { X! int i; X! char parent[64], dotdot[64]; X! X! strcpy(parent, new); X! X! /* Determine the name for the parent of X! ** the new name by counting back until we X! ** hit a '/' or the begining of the string X! */ X! X! for(i = (strlen(parent) - 1); i > 0; i--) { X! if(parent[i] == '/') break; X! } X! X! /* If there are no slashes, then the name is X! ** in the current directory, so its parent X! ** is ".". Otherwise, the parent is the name X! ** up to the last slash. X! */ X! if(i == 0) { X! strcpy(parent, "."); X! } X! else { X! /* null-terminate name at last slash */ X! parent[i] = '\0'; X! } X X /* Unlink the ".." entry */ X strcpy(dotdot, new); X--- 156,162 ---- X ** where else in the tree...) X */ X if ((st.st_mode & S_IFMT) == S_IFDIR) { X! char dotdot[64]; X X /* Unlink the ".." entry */ X strcpy(dotdot, new); + END-OF-FILE mv.c.cdif chmod 'u=rw,g=r,o=r' 'mv.c.cdif' set `wc -c 'mv.c.cdif'` count=$1 case $count in 4523) :;; *) echo 'Bad character count in ''mv.c.cdif' >&2 echo 'Count should be 4523' >&2 esac echo Extracting 'nm.c.cdif' sed 's/^X//' > 'nm.c.cdif' << '+ END-OF-FILE ''nm.c.cdif' X*** /local/ast/minix/tape3b/commands/nm.c Wed Jul 13 13:11:09 1988 X--- nm.c Sun Sep 25 15:25:09 1988 X*************** X*** 15,21 **** X * -g print only external symbols. X * -n sort numerically rather than alphabetically. X * -o prepend file name to each line rather than only once. X! * -p don't sort, print in symbol-table order. X * -r sort in reverse order. X * -u print only undefined symbols. X * X--- 15,21 ---- X * -g print only external symbols. X * -n sort numerically rather than alphabetically. X * -o prepend file name to each line rather than only once. X! * -p don't sort, pint n symbol-table order. X * -r sort in reverse order. X * -u print only undefined symbols. X * X*************** X*** 68,74 **** X break; X default: X fprintf(stderr, "illegal flag: -%c\n", **argv); X! Exit(-1); X } X *argv += 1; X } X--- 68,74 ---- X break; X default: X fprintf(stderr, "illegal flag: -%c\n", **argv); X! exit(-1); X } X *argv += 1; X } X*************** X*** 80,95 **** X nm(*argv); X argv++; X } X! Exit(0); X } X X- Exit(val) X- int val; X- { X- _cleanup(); X- exit(val); X- } X- X nm_sort(stbl1, stbl2) X struct nlist *stbl1, *stbl2; X { X--- 80,88 ---- X nm(*argv); X argv++; X } X! exit(0); X } X X nm_sort(stbl1, stbl2) X struct nlist *stbl1, *stbl2; X { X*************** X*** 175,182 **** X name[8] = '\0'; X if (!o_flag) printf("%s:\n", file); X for (last = &stbl[stbl_elems]; stbl != last; stbl++) { X! if (g_flag && !(stbl->n_sclass & C_EXT)) continue; X! if (u_flag && stbl->n_sclass & N_SECT != N_UNDF) continue; X X n_sclass = stbl->n_sclass & N_SECT; X if (n_sclass == N_ABS) type = 'a'; X--- 168,175 ---- X name[8] = '\0'; X if (!o_flag) printf("%s:\n", file); X for (last = &stbl[stbl_elems]; stbl != last; stbl++) { X! if (g_flag && (stbl->n_sclass & N_CLASS) != C_EXT) continue; X! if (u_flag && (stbl->n_sclass & N_SECT) != N_UNDF) continue; X X n_sclass = stbl->n_sclass & N_SECT; X if (n_sclass == N_ABS) type = 'a'; X*************** X*** 184,193 **** X else if (n_sclass == N_DATA) type = 'd'; X else if (n_sclass == N_BSS) type = 'b'; X else type = 'u'; X! if (stbl->n_sclass & C_EXT) type += 'A' -'a'; X strncpy(name, stbl->n_name, 8); X! if (o_flag) printf("%s:%04X %c %s\n", file, X stbl->n_value, type, name); X! else printf("%04X %c %s\n", stbl->n_value, type, name); X } X } X--- 177,186 ---- X else if (n_sclass == N_DATA) type = 'd'; X else if (n_sclass == N_BSS) type = 'b'; X else type = 'u'; X! if ((stbl->n_sclass & N_CLASS) == C_EXT) type += 'A' -'a'; X strncpy(name, stbl->n_name, 8); X! if (o_flag) printf("%s:%08X %c %s\n", file, X stbl->n_value, type, name); X! else printf("%08X %c %s\n", stbl->n_value, type, name); X } X } + END-OF-FILE nm.c.cdif chmod 'u=rw,g=r,o=r' 'nm.c.cdif' set `wc -c 'nm.c.cdif'` count=$1 case $count in 2777) :;; *) echo 'Bad character count in ''nm.c.cdif' >&2 echo 'Count should be 2777' >&2 esac echo Extracting 'paste.c.cdif' sed 's/^X//' > 'paste.c.cdif' << '+ END-OF-FILE ''paste.c.cdif' X*** /local/ast/minix/tape3b/commands/paste.c Wed Jul 13 13:11:10 1988 X--- paste.c Sun Sep 25 15:25:10 1988 X*************** X*** 1,3 **** X--- 1,5 ---- X+ /* paste - laminate files Author: David Ihnat */ X+ X /* X * paste - a recreation of the Unix(Tm) paste(1) command. X * + END-OF-FILE paste.c.cdif chmod 'u=rw,g=r,o=r' 'paste.c.cdif' set `wc -c 'paste.c.cdif'` count=$1 case $count in 274) :;; *) echo 'Bad character count in ''paste.c.cdif' >&2 echo 'Count should be 274' >&2 esac echo Extracting 'pr.c.cdif' sed 's/^X//' > 'pr.c.cdif' << '+ END-OF-FILE ''pr.c.cdif' X*** /local/ast/minix/tape3b/commands/pr.c Wed Jul 13 13:11:10 1988 X--- pr.c Sun Sep 25 15:25:10 1988 X*************** X*** 16,25 **** X * header can be given and used. X * format changed may occur between printing of several files: X * pr -l30 file1 -w75 file2 X * X! * Usage: pr [+page] [-columns] [-h header] [-w with] [-l length] [-nt] [files] X * -t : Do not print the 5 line header and trailer at the page. X! * -n : Turn on line numbering. X * +page : Start printing at page n. X * -columns : Print files in n-columns. X * -l length: Take the length of the page to be n instead of 66 X--- 16,32 ---- X * header can be given and used. X * format changed may occur between printing of several files: X * pr -l30 file1 -w75 file2 X+ * X+ * Modified: Rick Thomas. (Sept 12, 1988) X+ * added "-M" option to cover functionality of old "-n" option, X+ * and made "-n" option behavior compatible with system V. X * X! * Usage: pr [+page] [-columns] [-h header] [-wwidth] [-llength] [-ntm] [files] X * -t : Do not print the 5 line header and trailer at the page. X! * -n : Turn on line numbering. X! * -M : Use "Minix" style line numbering -- Each page begins at X! * a line number that is an even multiple of the page length. X! * Like the listings in Appendix E of the book. X * +page : Start printing at page n. X * -columns : Print files in n-columns. X * -l length: Take the length of the page to be n instead of 66 X*************** X*** 54,60 **** X X char *header; X BOOL no_header; X! BOOL number; X BOOL ext_header_set = FALSE; /* external header given */ X BOOL back_space = TRUE; /* back space correction in line width */ X BOOL dont_fold = FALSE; /* original. If the line does not fit X--- 61,68 ---- X X char *header; X BOOL no_header; X! BOOL number = FALSE; X! BOOL minix_number = FALSE; X BOOL ext_header_set = FALSE; /* external header given */ X BOOL back_space = TRUE; /* back space correction in line width */ X BOOL dont_fold = FALSE; /* original. If the line does not fit X*************** X*** 64,69 **** X--- 72,78 ---- X short start_page = 1; X short width = DEF_WIDTH; X short length = DEF_LENGTH; X+ short linenr; X char *line_buf; /* used in format for multi-column output */ X X char output[1024]; X*************** X*** 105,111 **** X--- 114,125 ---- X break; X case 'n': X number = TRUE; X+ minix_number = FALSE; X break; X+ case 'M': X+ number = TRUE; X+ minix_number = TRUE; X+ break; X case 'h': X header = argv[index++]; X ext_header_set = TRUE; X*************** X*** 127,133 **** X dont_fold = TRUE; X break; X default: X! fprintf(stderr, "Usage: %s [+page] [-columns] [-h header] [-w<with>] [-l<length>] [-nt] [files]\n", argv[0]); X exit(1); X } X continue; /* Scan for next flags */ X--- 141,147 ---- X dont_fold = TRUE; X break; X default: X! fprintf(stderr, "Usage: %s [+page] [-columns] [-h header] [-w<width>] [-l<length>] [-nMt] [files]\n", argv[0]); X exit(1); X } X continue; /* Scan for next flags */ X*************** X*** 229,234 **** X--- 243,249 ---- X if (dont_fold && c!='\n' && c!=EOF) X EAT(filep); X lines--; X+ if (c == '\n') linenr++; X } while (lines > 0 && c != EOF); X X return c; /* last char read */ X*************** X*** 328,338 **** X print_page(pagenr, maxcol) X short pagenr, maxcol; X { X- short linenr = (pagenr - 1) * length + 1; X short pad, i, j, start; X short width; X char *p; X X if (!no_header) X out_header(pagenr); X X--- 343,355 ---- X print_page(pagenr, maxcol) X short pagenr, maxcol; X { X short pad, i, j, start; X short width; X char *p; X X+ if (minix_number) linenr = (pagenr -1 ) * length + 1; X+ else linenr = 1; X+ X if (!no_header) X out_header(pagenr); X X*************** X*** 340,346 **** X for (j = 0; j < maxcol; j++) { X width = cwidth; X if (number && j == 0) { /* first columns */ X! printf("%*.*d ", NUM_WIDTH-1, NUM_WIDTH-1, linenr++); X width -= NUM_WIDTH; X } X pad = 0; X--- 357,363 ---- X for (j = 0; j < maxcol; j++) { X width = cwidth; X if (number && j == 0) { /* first columns */ X! printf("%7.7d ", linenr++); /* 7 == NUM_WIDTH-1 */ X width -= NUM_WIDTH; X } X pad = 0; X*************** X*** 362,373 **** X { X short c = '\0'; X short page_number = 0; X- short linenr = 1; X short lines; X short cnt, i, max; X short w = width; X BOOL pr_number = TRUE; /* only real lines are numbered, not folded parts */ X X if (number) X width -= NUM_WIDTH; X X--- 379,390 ---- X { X short c = '\0'; X short page_number = 0; X short lines; X short cnt, i, max; X short w = width; X BOOL pr_number = TRUE; /* only real lines are numbered, not folded parts */ X X+ linenr = 1; X if (number) X width -= NUM_WIDTH; X X*************** X*** 386,394 **** X if (c == EOF) X return; X X! linenr = (page_number -1 ) * length + 1; X! if (!no_header) X! out_header(page_number); X X if (page_number == start_page) X c = getc(filep); X--- 403,409 ---- X if (c == EOF) X return; X X! if (minix_number) linenr = (page_number -1 ) * length + 1; X X if (page_number == start_page) X c = getc(filep); X*************** X*** 396,407 **** X /* Print the page */ X lines = length; X while (lines && c != EOF) { X if (number ) X if (pr_number) X! printf("%*.*d ", NUM_WIDTH-1, X! NUM_WIDTH-1, linenr++); X else X! printf("%*c ", NUM_WIDTH-1, ' '); X pr_number = FALSE; X cnt = 0; X while (c != '\n' && c != EOF && cnt < width) { X--- 411,423 ---- X /* Print the page */ X lines = length; X while (lines && c != EOF) { X+ if (lines == length && !no_header) X+ out_header(page_number); X if (number ) X if (pr_number) X! printf("%7.7d ", linenr++); /* 7 == NUM_WIDTH-1 */ X else X! printf("%7c ", ' '); /* 7 == NUM_WIDTH-1 */ X pr_number = FALSE; X cnt = 0; X while (c != '\n' && c != EOF && cnt < width) { X*************** X*** 429,437 **** X pr_number = TRUE; X } X } X! if (lines == length) X! return; X! if (!no_header) X printf("\n\n\n\n\n"); X } while (c != EOF); X X--- 445,453 ---- X pr_number = TRUE; X } X } X! if (lines == length) /* We never printed anything on this page -- */ X! return; /* even the header, so dont try to fill it up */ X! if (!no_header) /* print the trailer -- 5 blank lines */ X printf("\n\n\n\n\n"); X } while (c != EOF); X + END-OF-FILE pr.c.cdif chmod 'u=rw,g=r,o=r' 'pr.c.cdif' set `wc -c 'pr.c.cdif'` count=$1 case $count in 6596) :;; *) echo 'Bad character count in ''pr.c.cdif' >&2 echo 'Count should be 6596' >&2 esac echo Extracting 'readall.c.cdif' sed 's/^X//' > 'readall.c.cdif' << '+ END-OF-FILE ''readall.c.cdif' X*** /local/ast/minix/tape3b/commands/readall.c Wed Jul 13 13:11:11 1988 X--- readall.c Mon Sep 26 15:01:14 1988 X*************** X*** 1,3 **** X--- 1,5 ---- X+ /* readall - read a whole device fast Author: Andy Tanenbaum */ X+ X #define BLK 30 X X char a[32000]; + END-OF-FILE readall.c.cdif chmod 'u=rw,g=r,o=r' 'readall.c.cdif' set `wc -c 'readall.c.cdif'` count=$1 case $count in 260) :;; *) echo 'Bad character count in ''readall.c.cdif' >&2 echo 'Count should be 260' >&2 esac echo Extracting 'readclock.c.new' sed 's/^X//' > 'readclock.c.new' << '+ END-OF-FILE ''readclock.c.new' X/* readclock - read the AT real time clock Authors: T. Holm & E. Froese */ X X/************************************************************************/ X/* */ X/* readclock.c */ X/* */ X/* Read the AT real time clock, write the time to */ X/* standard output in a form usable by date(1). */ X/* If the system is an AT then the time is read */ X/* from the built-in clock, and written to standard */ X/* output in the form: */ X/* */ X/* mmddyyhhmmss */ X/* */ X/* If the system is not an AT then ``-q'' is written */ X/* to standard output. This is useful for placement in */ X/* the ``/etc/rc'' script: */ X/* */ X/* /usr/bin/date `/usr/bin/readclock` </dev/tty */ X/* */ X/************************************************************************/ X/* origination 1987-Dec-29 efth */ X/************************************************************************/ X X X X#define CPU_TYPE_SEGMENT 0xFFFF /* BIOS segment for CPU type */ X#define CPU_TYPE_OFFSET 0x000E /* BIOS offset for CPU type */ X#define PC_AT 0xFC /* IBM code for PC-AT (0xFFFFE) */ X X X#define CLK_ELE 0x70 /* ptr corresponding to element of time to be */ X#define CLK_IO 0x71 /* read or written is written to port clk_ele */ X /* the element can then be read or written by */ X /* reading or writing port clk_io. */ X X#define YEAR 9 /* Clock register addresses */ X#define MONTH 8 X#define DAY 7 X#define HOUR 4 X#define MINUTE 2 X#define SECOND 0 X#define STATUS 0x0b X X#define BCD_TO_DEC(x) ( (x>>4) * 10 + (x & 0x0f) ) X X Xstruct time X{ unsigned year; X unsigned month; X unsigned day; X unsigned hour; X unsigned minute; X unsigned second; X}; X X X Xmain() X{ X struct time time1; X struct time time2; X int i; X X if ( peek( CPU_TYPE_SEGMENT, CPU_TYPE_OFFSET ) != PC_AT ) { X printf( "-q\n" ); X exit( 1 ); X } X X for ( i=0; i<10; i++ ) { X get_time( &time1 ); X get_time( &time2 ); X X if ( time1.year == time2.year && X time1.month == time2.month && X time1.day == time2.day && X time1.hour == time2.hour && X time1.minute == time2.minute && X time1.second == time2.second ) X { X printf( "%02d%02d%02d%02d%02d%02d\n", X time1.month, time1.day, time1.year, X time1.hour, time1.minute, time1.second ); X exit( 0 ); X } X } X X printf( "-q\n" ); X exit( 1 ); X} X X X X/***********************************************************************/ X/* */ X/* get_time( time ) */ X/* */ X/* Update the structure pointed to by time with the current time */ X/* as read from the hardware real-time clock of the AT. */ X/* If necessary, the time is converted into a binary format before */ X/* being stored in the structure. */ X/* */ X/***********************************************************************/ X Xget_time( t ) X struct time *t; { X t->year = read_register( YEAR ); X t->month = read_register( MONTH ); X t->day = read_register( DAY ); X t->hour = read_register( HOUR ); X t->minute = read_register( MINUTE ); X t->second = read_register( SECOND ); X X X X if ( (read_register(STATUS) & 0x04) == 0) { X /* convert BCD to binary if necessary */ X t->year = BCD_TO_DEC( t->year ); X t->month = BCD_TO_DEC( t->month ); X t->day = BCD_TO_DEC( t->day ); X t->hour = BCD_TO_DEC( t->hour ); X t->minute = BCD_TO_DEC( t->minute ); X t->second = BCD_TO_DEC( t->second ); X } X} X X Xread_register( reg_addr ) Xchar reg_addr; X{ X int val; X X port_out( CLK_ELE, reg_addr ); X port_in(CLK_IO, &val); X return( val ); X} + END-OF-FILE readclock.c.new chmod 'u=rw,g=r,o=r' 'readclock.c.new' set `wc -c 'readclock.c.new'` count=$1 case $count in 4113) :;; *) echo 'Bad character count in ''readclock.c.new' >&2 echo 'Count should be 4113' >&2 esac echo Extracting 'readfs.c.cdif' sed 's/^X//' > 'readfs.c.cdif' << '+ END-OF-FILE ''readfs.c.cdif' X*** /local/ast/minix/tape3b/commands/readfs.c Wed Jul 13 13:11:12 1988 X--- readfs.c Mon Sep 26 15:01:15 1988 X*************** X*** 236,242 **** X X /* Read next block of the directory */ X if (get_fileblock(special, ip, b, &bp) < 0) X! return(-1); X dp = &bp.b_dir[0]; X if (b++ == (block_nr) 0) { X dp += 2; /* Skip "." and ".." */ X--- 236,242 ---- X X /* Read next block of the directory */ X if (get_fileblock(special, ip, b, &bp) < 0) X! return; X dp = &bp.b_dir[0]; X if (b++ == (block_nr) 0) { X dp += 2; /* Skip "." and ".." */ + END-OF-FILE readfs.c.cdif chmod 'u=rw,g=r,o=r' 'readfs.c.cdif' set `wc -c 'readfs.c.cdif'` count=$1 case $count in 561) :;; *) echo 'Bad character count in ''readfs.c.cdif' >&2 echo 'Count should be 561' >&2 esac echo Extracting 'sed.c.cdif' sed 's/^X//' > 'sed.c.cdif' << '+ END-OF-FILE ''sed.c.cdif' X*** /local/ast/minix/tape3b/commands/sed.c Wed Jul 13 13:11:14 1988 X--- sed.c Mon Sep 26 15:01:22 1988 X*************** X*** 98,103 **** X--- 98,105 ---- X X /* sed.h ends here */ X X+ #define CMASK 0xFF /* some char type should have been unsigned char? */ X+ X /*+++++++++++++++*/ X X /* sed - stream editor Author: Eric S. Raymond */ + END-OF-FILE sed.c.cdif chmod 'u=rw,g=r,o=r' 'sed.c.cdif' set `wc -c 'sed.c.cdif'` count=$1 case $count in 337) :;; *) echo 'Bad character count in ''sed.c.cdif' >&2 echo 'Count should be 337' >&2 esac echo Extracting 'strip.c.cdif' sed 's/^X//' > 'strip.c.cdif' << '+ END-OF-FILE ''strip.c.cdif' X*** /local/ast/minix/tape3b/commands/strip.c Wed Jul 13 13:11:18 1988 X--- strip.c Mon Sep 26 15:01:26 1988 X*************** X*** 1,4 **** X! /* strip - remove symbols. Author: Dick van Veen, veench@cs.vu.nl */ X X #include <a.out.h> X #include <stdio.h> X--- 1,4 ---- X! /* strip - remove symbols. Author: Dick van Veen */ X X #include <a.out.h> X #include <stdio.h> X*************** X*** 129,146 **** X int fd1, fd2; X long size; X { X- long count; X int length; X X! count = 0; X! while (count < size) { X! length = (int) (size - count); X! if (length > sizeof(buffer)) length = sizeof(buffer); X! length = read(fd1, buffer, length); X! if (length == 0) break; X if (write(fd2, buffer, length) != length) return(1); X! count += length; X } X- if (count < size) return(1); X return(0); X } X--- 129,143 ---- X int fd1, fd2; X long size; X { X int length; X X! while (size > 0) { X! if (size < sizeof(buffer)) X! length = size; X! else length = sizeof(buffer); X! if (read(fd1, buffer, length) != length) return(1); X if (write(fd2, buffer, length) != length) return(1); X! size -= length; X } X return(0); X } + END-OF-FILE strip.c.cdif chmod 'u=rw,g=r,o=r' 'strip.c.cdif' set `wc -c 'strip.c.cdif'` count=$1 case $count in 1129) :;; *) echo 'Bad character count in ''strip.c.cdif' >&2 echo 'Count should be 1129' >&2 esac echo Extracting 'stty.c.cdif' sed 's/^X//' > 'stty.c.cdif' << '+ END-OF-FILE ''stty.c.cdif' X*** /local/ast/minix/tape3b/commands/stty.c Wed Jul 13 13:11:18 1988 X--- stty.c Mon Sep 26 15:01:26 1988 X*************** X*** 64,69 **** X--- 64,79 ---- X prints("\nint = "); prctl(tch.t_intrc); X prints("\nquit = "); prctl(tch.t_quitc); X if (ispeed > 0) { X+ /* Print # bits/char and parity */ X+ if ( (mode & BITS8) == BITS8) prints("\n8 bits/char, "); X+ if ( (mode & BITS8) == BITS7) prints("\n7 bits/char, "); X+ if ( (mode & BITS8) == BITS6) prints("\n6 bits/char, "); X+ if ( (mode & BITS8) == BITS5) prints("\n5 bits/char, "); X+ if (mode & EVENP) prints("even parity"); X+ else if (mode & ODDP) prints("odd parity"); X+ else prints("no parity"); X+ X+ /* Print line speed. */ X prints("\nspeed = "); X switch(ispeed) { X case 100: prints("110"); break; + END-OF-FILE stty.c.cdif chmod 'u=rw,g=r,o=r' 'stty.c.cdif' set `wc -c 'stty.c.cdif'` count=$1 case $count in 778) :;; *) echo 'Bad character count in ''stty.c.cdif' >&2 echo 'Count should be 778' >&2 esac echo Extracting 'su.c.cdif' sed 's/^X//' > 'su.c.cdif' << '+ END-OF-FILE ''su.c.cdif' X*** /local/ast/minix/tape3b/commands/su.c Wed Jul 13 13:11:20 1988 X--- su.c Mon Sep 26 15:01:26 1988 X*************** X*** 48,54 **** X setuid (pwd->pw_uid); X if (pwd->pw_shell[0]) X shell = pwd->pw_shell; X! execl (shell, "-i", 0); X std_err("No shell\n"); X exit (3); X } X--- 48,54 ---- X setuid (pwd->pw_uid); X if (pwd->pw_shell[0]) X shell = pwd->pw_shell; X! execl (shell, shell, "-i", 0); X std_err("No shell\n"); X exit (3); X } + END-OF-FILE su.c.cdif chmod 'u=rw,g=r,o=r' 'su.c.cdif' set `wc -c 'su.c.cdif'` count=$1 case $count in 448) :;; *) echo 'Bad character count in ''su.c.cdif' >&2 echo 'Count should be 448' >&2 esac echo Extracting 'tar.c.cdif' sed 's/^X//' > 'tar.c.cdif' << '+ END-OF-FILE ''tar.c.cdif' X*** /local/ast/minix/tape3b/commands/tar.c Wed Jul 13 13:11:21 1988 X--- tar.c Mon Sep 26 15:01:28 1988 X*************** X*** 43,48 **** X--- 43,49 ---- X #define LONG_TYPE (sizeof(header.member.m_size)) X X #define MKDIR "/bin/mkdir" X+ #define MKDIR2 "/usr/bin/mkdir" X X #define NIL_HEADER ((HEADER *) 0) X #define NIL_PTR ((char *) 0) X*************** X*** 252,257 **** X--- 253,259 ---- X X if (pid == 0) { X execl(MKDIR, "mkdir", dir_name, (char *) 0); X+ execl(MKDIR2, "mkdir", dir_name, (char *) 0); X error("Cannot find mkdir.", NIL_PTR); X } X + END-OF-FILE tar.c.cdif chmod 'u=rw,g=r,o=r' 'tar.c.cdif' set `wc -c 'tar.c.cdif'` count=$1 case $count in 561) :;; *) echo 'Bad character count in ''tar.c.cdif' >&2 echo 'Count should be 561' >&2 esac echo Extracting 'term.c.cdif' sed 's/^X//' > 'term.c.cdif' << '+ END-OF-FILE ''term.c.cdif' X*** /local/ast/minix/tape3b/commands/term.c Sat Jul 16 23:59:42 1988 X--- term.c Mon Sep 26 15:01:29 1988 X*************** X*** 102,108 **** X /* Fetch the keyboard parameters, save them, and set new ones. */ X ioctl(0, TIOCGETP, &sgtty); X sgsave2 = sgtty; /* modem parameters */ X! sgtty.sg_flags = RAW; X ioctl(0, TIOCSETP, &sgtty); X } X X--- 102,108 ---- X /* Fetch the keyboard parameters, save them, and set new ones. */ X ioctl(0, TIOCGETP, &sgtty); X sgsave2 = sgtty; /* modem parameters */ X! sgtty.sg_flags = (sgtty.sg_flags & 01700) + RAW; X ioctl(0, TIOCSETP, &sgtty); X } X + END-OF-FILE term.c.cdif chmod 'u=rw,g=r,o=r' 'term.c.cdif' set `wc -c 'term.c.cdif'` count=$1 case $count in 606) :;; *) echo 'Bad character count in ''term.c.cdif' >&2 echo 'Count should be 606' >&2 esac echo Extracting 'tset.c.new' sed 's/^X//' > 'tset.c.new' << '+ END-OF-FILE ''tset.c.new' X/* tset - set the TERM variable Author: Terrence Holm */ X X#include <stdio.h> X X X#define LINE_LENGTH 40 /* Max length in /etc/ttytype */ X#define TC_BUFFER 1024 /* Size of termcap(3) buffer */ X X XFILE *fopen(); Xchar *ttyname(); Xchar *index(); Xchar *getenv(); X X/****************************************************************/ X/* */ X/* eval `tset [ device_type ]` */ X/* */ X/* "device_type" is the new name for $TERM. If no */ X/* type is supplied then /etc/ttytype is scanned for */ X/* the current port. */ X/* */ X/* This program returns the string: */ X/* */ X/* TERM= . . . */ X/* */ X/****************************************************************/ X/* */ X/* Login(1) sets a default for $TERM, so for logging-in */ X/* to any terminal place the following in ".profile": */ X/* */ X/* eval `tset` */ X/* */ X/* To change $TERM during a session: */ X/* */ X/* eval `tset device_type` */ X/* */ X/****************************************************************/ X X X Xmain( argc, argv ) X int argc; X char *argv[]; X X { X char *name; X FILE *f; X char line[ LINE_LENGTH ]; X X X if ( argc > 2 ) X { X fprintf( stderr, "Usage: %s [ device_type ]\n", argv[0] ); X exit( 1 ); X } X X if ( argc == 2 ) X { X Find_Termcap( argv[1] ); X exit( 0 ); X } X X X /* No terminal name supplied, so use the current device */ X X if ( (name = ttyname( 0 )) == NULL ) X Error( "Can not determine the user's terminal" ); X X name += 5; /* Chop off "/dev/" part */ X X X /* Look up the default terminal type in /etc/ttytype */ X X if ( (f = fopen( "/etc/ttytype", "r" )) == NULL ) X Error( "Can not open /etc/ttytype" ); X X while ( fgets( line, LINE_LENGTH, f ) != NULL ) X { X char *space = index( line, ' ' ); X X line[ strlen(line) - 1 ] = '\0'; /* Remove '\n' */ X X if ( strcmp( space+1, name ) == 0 ) X { X *space = '\0'; X Find_Termcap( line ); X exit( 0 ); X } X } X X Error( "Can not find your terminal in /etc/ttytype" ); X } X X X XFind_Termcap( terminal ) X char *terminal; X X { X char termcap[ TC_BUFFER ]; X X if ( tgetent( termcap, terminal ) != 1 ) X Error( "No termcap for your terminal type" ); X X /* In real Unix the $TERMCAP would also be returned here */ X X printf( "TERM=%s;\n", terminal ); X } X X X XError( msg ) X char *msg; X X { X fprintf( stderr, "tset: %s\n", msg ); X exit( 1 ); X } + END-OF-FILE tset.c.new chmod 'u=rw,g=r,o=r' 'tset.c.new' set `wc -c 'tset.c.new'` count=$1 case $count in 2431) :;; *) echo 'Bad character count in ''tset.c.new' >&2 echo 'Count should be 2431' >&2 esac echo Extracting 'tty.c.cdif' sed 's/^X//' > 'tty.c.cdif' << '+ END-OF-FILE ''tty.c.cdif' X*** /local/ast/minix/tape3b/commands/tty.c Wed Jul 13 13:11:24 1988 X--- tty.c Mon Sep 26 15:01:34 1988 X*************** X*** 1,14 **** X! /* X! * tty.c - Return tty name X! * X! * Freename P. Pascal IV X! * X! */ X! /* X! * History: X! * X! * 31 July 87 fpp Creation X! */ X #include <stdio.h> X X char *ttyname(); X--- 1,5 ---- X! /* tty.c - Return tty name Author: Freeman P. Pascal IV */ X! X #include <stdio.h> X X char *ttyname(); + END-OF-FILE tty.c.cdif chmod 'u=rw,g=r,o=r' 'tty.c.cdif' set `wc -c 'tty.c.cdif'` count=$1 case $count in 435) :;; *) echo 'Bad character count in ''tty.c.cdif' >&2 echo 'Count should be 435' >&2 esac echo Extracting 'vol.c.cdif' sed 's/^X//' > 'vol.c.cdif' << '+ END-OF-FILE ''vol.c.cdif' X*** /local/ast/minix/tape3b/commands/vol.c Wed Jul 13 13:11:26 1988 X--- vol.c Mon Sep 26 15:01:36 1988 X*************** X*** 117,123 **** X out[1] += n; X } else { X out[1] += (n%10); X! out[2] = '0' + (n/10); X } X std_err(out); X } X--- 117,123 ---- X out[1] += n; X } else { X out[1] += (n%10); X! out[0] = '0' + (n/10); X } X std_err(out); X } + END-OF-FILE vol.c.cdif chmod 'u=rw,g=r,o=r' 'vol.c.cdif' set `wc -c 'vol.c.cdif'` count=$1 case $count in 361) :;; *) echo 'Bad character count in ''vol.c.cdif' >&2 echo 'Count should be 361' >&2 esac exit 0