ast@cs.vu.nl (Andy Tanenbaum) (07/14/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 'ar.c.cdif'
sed 's/^X//' > 'ar.c.cdif' << '+ END-OF-FILE ''ar.c.cdif'
X*** /local/ast/minix/tape3a/commands/ar.c Mon May 16 15:03:36 1988
X--- ar.c Wed Jul 13 13:10:39 1988
X***************
X*** 132,138 ****
X /* forward declarations and external references */
X extern char *malloc();
X extern char *mktemp(), *rindex();
X! extern int strcmp();
X extern print_date();
X extern user_abort(), usage();
X extern long lseek();
X--- 132,138 ----
X /* forward declarations and external references */
X extern char *malloc();
X extern char *mktemp(), *rindex();
X! extern int strncmp();
X extern print_date();
X extern user_abort(), usage();
X extern long lseek();
X***************
X*** 473,487 ****
X
X if (major & EXTRACT) {
X if ((outfd = creat(member->ar_name,0666)) < 0) {
X! fprintf(stderr,"Error: %s could not creat %s\n",progname, member->ar_name);
X quit(mypid,SIGINT);
X }
X if (verbose)
X! fprintf(stdout,"x - %s\n",member->ar_name);
X }
X else {
X if (verbose) {
X! fprintf(stdout,"p - %s\n",member->ar_name);
X fflush(stdout);
X }
X outfd = fileno(stdout);
X--- 473,487 ----
X
X if (major & EXTRACT) {
X if ((outfd = creat(member->ar_name,0666)) < 0) {
X! fprintf(stderr,"Error: %s could not creat %-14.14s\n",progname, member->ar_name);
X quit(mypid,SIGINT);
X }
X if (verbose)
X! fprintf(stdout,"x - %-14.14s\n",member->ar_name);
X }
X else {
X if (verbose) {
X! fprintf(stdout,"p - %-14.14s\n",member->ar_name);
X fflush(stdout);
X }
X outfd = fileno(stdout);
X***************
X*** 521,527 ****
X for (; m > 0; m -= n) {
X cnt = (m < BUFFERSIZE ? m : BUFFERSIZE);
X if ((n = read(infd, buffer, cnt)) != cnt) {
X! fprintf(stderr,"Error: %s - read error on %s\n",progname, member->ar_name);
X quit(mypid, SIGINT);
X }
X mwrite(outfd, buffer, n);
X--- 521,527 ----
X for (; m > 0; m -= n) {
X cnt = (m < BUFFERSIZE ? m : BUFFERSIZE);
X if ((n = read(infd, buffer, cnt)) != cnt) {
X! fprintf(stderr,"Error: %s - read error on %-14.14s\n",progname, member->ar_name);
X quit(mypid, SIGINT);
X }
X mwrite(outfd, buffer, n);
X***************
X*** 550,556 ****
X fprintf(stderr,"Error: %s cannot open file %s\n",progname,name);
X quit(mypid,SIGINT);
X }
X! strcpy(member.ar_name, basename(name));
X member.ar_uid = status.st_uid;
X member.ar_gid = status.st_gid;
X member.ar_mode = status.st_mode & 07777;
X--- 550,556 ----
X fprintf(stderr,"Error: %s cannot open file %s\n",progname,name);
X quit(mypid,SIGINT);
X }
X! strncpy(member.ar_name, basename(name),14);
X member.ar_uid = status.st_uid;
X member.ar_gid = status.st_gid;
X member.ar_mode = status.st_mode & 07777;
X***************
X*** 560,572 ****
X if (oldmember != (struct ar_hdr *)NULL)
X if (member.ar_date <= oldmember->ar_date) {
X close(in_fd);
X! if (verbose) fprintf(stdout, "not %s - %s\n",mess, name);
X return (-1);
X }
X
X copy_member(in_fd, fd, &member);
X if (verbose)
X! fprintf(stdout, "%s - %s\n",mess, name);
X close(in_fd);
X return (1);
X }
X--- 560,572 ----
X if (oldmember != (struct ar_hdr *)NULL)
X if (member.ar_date <= oldmember->ar_date) {
X close(in_fd);
X! if (verbose) fprintf(stdout, "not %-14.14s - %-14.14s\n",mess, name);
X return (-1);
X }
X
X copy_member(in_fd, fd, &member);
X if (verbose)
X! fprintf(stdout, "%s - %-14.14s\n",mess, name);
X close(in_fd);
X return (1);
X }
X***************
X*** 607,613 ****
X if ((member = get_member(arfd)) != NULL)
X copy_member(arfd, newfd, member);
X mov = mov->next;
X! if (verbose) fprintf(stdout, "m - %s\n", member->ar_name);
X }
X
X /* copy rest of library into new tmp file */
X--- 607,613 ----
X if ((member = get_member(arfd)) != NULL)
X copy_member(arfd, newfd, member);
X mov = mov->next;
X! if (verbose) fprintf(stdout, "m - %-14.14s\n", member->ar_name);
X }
X
X /* copy rest of library into new tmp file */
X***************
X*** 687,693 ****
X did_print = 0;
X if (ac < argc) {
X for (a = ac+1; a <= argc; ++a) {
X! if (strcmp(basename(argv[a-1]),member->ar_name) == 0) {
X if (major & TABLE)
X print_header(member);
X else if (major & (PRINT | EXTRACT)) {
X--- 687,693 ----
X did_print = 0;
X if (ac < argc) {
X for (a = ac+1; a <= argc; ++a) {
X! if (strncmp(basename(argv[a-1]),member->ar_name,14) == 0) {
X if (major & TABLE)
X print_header(member);
X else if (major & (PRINT | EXTRACT)) {
X***************
X*** 729,740 ****
X
X /* if posname specified check for our member */
X /* if our member save his starting pos in our working file*/
X! if (posname && strcmp(posname, member->ar_name) == 0)
X pos_offset = tell(tempfd) - MAGICSIZE;
X
X if (ac < argc) { /* we have a list of members to check */
X for (a = ac+1; a <= argc; ++a)
X! if (strcmp(basename(argv[a-1]),member->ar_name) == 0) {
X if (major & REPLACE) {
X if (insert(tempfd,argv[a-1],"r", member) < 0)
X copy_member(fd, tempfd, member);
X--- 729,740 ----
X
X /* if posname specified check for our member */
X /* if our member save his starting pos in our working file*/
X! if (posname && strncmp(posname, member->ar_name, 14) == 0)
X pos_offset = tell(tempfd) - MAGICSIZE;
X
X if (ac < argc) { /* we have a list of members to check */
X for (a = ac+1; a <= argc; ++a)
X! if (strncmp(basename(argv[a-1]),member->ar_name,14) == 0) {
X if (major & REPLACE) {
X if (insert(tempfd,argv[a-1],"r", member) < 0)
X copy_member(fd, tempfd, member);
X***************
X*** 753,759 ****
X if (ac >= argc || a > argc) /*nomatch on a member name */
X copy_member(fd, tempfd, member);
X else if (major & DELETE) {
X! if (verbose) fprintf(stdout,"d - %s\n",member->ar_name);
X lseek(fd, (long)even(member->ar_size), 1);
X }
X }
X--- 753,759 ----
X if (ac >= argc || a > argc) /*nomatch on a member name */
X copy_member(fd, tempfd, member);
X else if (major & DELETE) {
X! if (verbose) fprintf(stdout,"d - %-14.14s\n",member->ar_name);
X lseek(fd, (long)even(member->ar_size), 1);
X }
X }
X***************
X*** 761,767 ****
X if (posname == NULL)
X pos_offset = lseek(fd, 0l, 2);
X else if (pos_offset == (-1)) {
X! fprintf(stderr,"Error: %s cannot find file %s\n",progname,posname);
X quit(mypid,SIGINT);
X }
X tempfd = ar_move(tempfd, fd, moves);
X--- 761,767 ----
X if (posname == NULL)
X pos_offset = lseek(fd, 0l, 2);
X else if (pos_offset == (-1)) {
X! fprintf(stderr,"Error: %s cannot find file %-14.14s\n",progname,posname);
X quit(mypid,SIGINT);
X }
X tempfd = ar_move(tempfd, fd, moves);
+ END-OF-FILE ar.c.cdif
chmod 'u=rw,g=r,o=r' 'ar.c.cdif'
set `wc -c 'ar.c.cdif'`
count=$1
case $count in
6569) :;;
*) echo 'Bad character count in ''ar.c.cdif' >&2
echo 'Count should be 6569' >&2
esac
echo Extracting 'at.c'
sed 's/^X//' > 'at.c' << '+ END-OF-FILE ''at.c'
X/* at - run commands at a specific time Author: Jan Looyen */
X
X
X/* Examples: at 2315 Jan 31 myfile # myfile executed Jan 31 at 11:15 pm
X * at 0900 # job input read from stdin
X * at 0711 4 29 # read from stdin, exec on April 29
X *
X * To see output, commands must redirect it to e.g., >/dev/tty0.
X */
X
X
X#define DIR "/usr/spool/at/
X#define STARTDAY 0 /* see ctime(3) */
X#define LEAPDAY STARTDAY+59
X#define MAXDAYNR STARTDAY+364
X#define NODAY -2
X
X#include <stdio.h>
X#include <sys/types.h>
X#include <time.h>
X
Xmain(argc, argv, envp)
Xint argc;
Xchar **argv, **envp;
X{
X int i, count, ltim, year, getltim(), getlday();
X int lday = NODAY;
X char c, buf[10], job[30], *dp, *sp;
X struct tm *p, *localtime();
X long clock;
X FILE *fp, *pin, *popen();
X
X/*-------------------------------------------------------------------------*
X * check arguments *
X *-------------------------------------------------------------------------*/
X if (argc < 2 || argc > 5) {
X fprintf(stderr, "Usage: %s time [month day] [file]\n", argv[0]);
X exit(0);
X }
X if ((ltim = getltim(argv[1])) == -1) {
X fprintf(stderr, "%s: wrong time specification\n", argv[0]);
X exit(0);
X }
X if ((argc==4 || argc==5) && (lday = getlday(argv[2], argv[3]))==-1) {
X fprintf(stderr, "%s: wrong date specification\n", argv[0]);
X exit(0);
X }
X if ((argc==3 || argc==5) && open(argv[argc-1], 0) == -1) {
X fprintf(stderr, "%s: cannot find: %s\n", argv[0], argv[argc-1]);
X exit(0);
X }
X/*-------------------------------------------------------------------------*
X * determine execution time and create 'at' job file *
X *-------------------------------------------------------------------------*/
X time(&clock);
X p = localtime(&clock);
X year = p->tm_year;
X if (lday==NODAY) { /* no [month day] given */
X lday = p->tm_yday;
X if (ltim <= (p->tm_hour*100 + p->tm_min)) {
X lday++;
X if (lday==MAXDAYNR && (year%4) || lday==MAXDAYNR+1) {
X lday = STARTDAY;
X year++;
X }
X }
X }
X else
X switch (year%4) {
X case 0: if (lday < p->tm_yday || lday == p->tm_yday &&
X ltim <= (p->tm_hour*100 + p->tm_min) ) {
X year++;
X if (lday > LEAPDAY) lday-- ;
X }
X break;
X case 1:
X case 2: if (lday > LEAPDAY) lday-- ;
X if (lday < p->tm_yday || lday == p->tm_yday &&
X ltim <= (p->tm_hour*100 + p->tm_min) )
X year++;
X break;
X case 3: if (lday < ((lday > LEAPDAY) ? p->tm_yday+1 : p->tm_yday) ||
X lday== ((lday > LEAPDAY) ? p->tm_yday+1 : p->tm_yday) &&
X ltim <= (p->tm_hour*100 + p->tm_min) )
X year++;
X else if (lday > LEAPDAY) lday--;
X break;
X }
X if ((pin = popen("pwd", "r")) == NULL)
X fprintf(stderr, "%s: cannot open pipe to cmd 'pwd'\n", argv[0]);
X sprintf(job, DIR%02d.%03d.%04d.%02d", year%100, lday, ltim, getpid()%100);
X if ((fp = fopen(job, "w")) == NULL) {
X fprintf(stderr, "%s: cannot create %s\n", argv[0], job);
X exit(0);
X }
X/*-------------------------------------------------------------------------*
X * write environment and command(s) to 'at'job file *
X *-------------------------------------------------------------------------*/
X while (envp[i] != NULL) {
X count = 1;
X dp = buf;
X sp = envp[i];
X while ((*dp++ = *sp++) != '=')
X count++;
X *--dp = '\0';
X fprintf(fp, "export %s; %s='%s'\n", buf, buf, &envp[i++][count]);
X }
X fprintf(fp, "cd ");
X while ((c = getc(pin)) != EOF)
X putc(c, fp);
X fprintf(fp, "umask %d\n", umask());
X if (argc==3 || argc==5)
X fprintf(fp, "%s\n", argv[argc-1]);
X else /* read from stdinput */
X while ((c = getchar()) != EOF)
X putc(c, fp);
X fclose(fp);
X
X printf("%s: %s created\n", argv[0], job);
X}
X
X/*-------------------------------------------------------------------------*
X * getltim() *
X *-------------------------------------------------------------------------*/
X
Xgetltim(t) /* return( (time OK) ? daytime : -1) */
Xchar *t;
X{
X if (t[4] == '\0' && t[3] >= '0' && t[3] <= '9' &&
X t[2] >= '0' && t[2] <= '5' && t[1] >= '0' && t[1] <= '9' &&
X (t[0] == '0' || t[0] == '1' || t[1] <= '3' && t[0] == '2') )
X return(atoi(t));
X else
X return(-1);
X}
X
X/*-------------------------------------------------------------------------*
X * getltday() *
X *-------------------------------------------------------------------------*/
X
Xgetlday(m, d) /* return ( (date OK) ? date number : -1 ) */
Xchar *m, *d;
X{
X int month, day;
X
X month = 0;
X if (m[1]=='\0') {
X if ((month = atoi(m)) < 1 || month > 9) month = 0;
X }
X else if (m[2]=='\0') {
X if ((month = atoi(m)) < 10 || month > 12) month = 0;
X }
X else if (m[3]=='\0') {
X if (m[0]=='J' || m[0]=='j') {
X if (m[1]=='a' && m[2]=='n') month = 1;
X else if (m[1]=='u') {
X if (m[2]=='n') month = 6;
X else if (m[2]=='l') month = 7;
X }
X }
X else if (m[0]=='M' || m[0]=='m') {
X if (m[1]=='a') {
X if (m[2]=='r') month = 3;
X else if (m[2]=='y') month = 5;
X }
X }
X else if (m[0]=='A' || m[0]=='a') {
X if (m[1]=='p' && m[2]=='r') month = 4;
X else if (m[1]=='u' && m[2]=='g') month = 8;
X }
X else if ((m[0]=='F' || m[0]=='f') && m[1]=='e' && m[2]=='b')month = 2;
X else if ((m[0]=='S' || m[0]=='s') && m[1]=='e' && m[2]=='p')month = 9;
X else if ((m[0]=='O' || m[0]=='o') && m[1]=='c' && m[2]=='t')month = 10;
X else if ((m[0]=='N' || m[0]=='n') && m[1]=='o' && m[2]=='v')month = 11;
X else if ((m[0]=='D' || m[0]=='d') && m[1]=='e' && m[2]=='c')month = 12;
X }
X if (!month) return (-1);
X
X
X day = 0;
X if (d[1] == '\0') {
X if ((day = atoi(d)) <1 || day > 9) return(-1);
X }
X else if (d[2] == '\0') {
X if ((day = atoi(d)) <10 || day > 31) return(-1);
X else if (month==2 && day > 29) return(-1);
X else if (day==31 && ( month==4 || month==6 || month==9 || month==11))
X return(-1);
X }
X
X if (!STARTDAY)day--;
X switch (month) {
X case 1: return(day);
X case 2: return(day + 31);
X case 3: return(day + 60);
X case 4: return(day + 91);
X case 5: return(day + 121);
X case 6: return(day + 152);
X case 7: return(day + 182);
X case 8: return(day + 213);
X case 9: return(day + 244);
X case 10: return(day + 274);
X case 11: return(day + 305);
X case 12: return(day + 335);
X }
X}
+ END-OF-FILE at.c
chmod 'u=rw,g=r,o=r' 'at.c'
set `wc -c 'at.c'`
count=$1
case $count in
6373) :;;
*) echo 'Bad character count in ''at.c' >&2
echo 'Count should be 6373' >&2
esac
echo Extracting 'atrun.c'
sed 's/^X//' > 'atrun.c' << '+ END-OF-FILE ''atrun.c'
X/* atrun - perform the work 'at' has squirreled away Author: Jan Looyen */
X
X/*-------------------------------------------------------------------------*
X * atrun scans directory DIRNAME for 'at' jobs to be executed *
X * finished jobs have been moved to directory DIRNAME/past *
X *-------------------------------------------------------------------------*/
X#define DIRNAME "/usr/spool/at
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/dir.h>
X#include <time.h>
X
Xmain()
X{
X int fd, nr;
X char realtime[15], procname[35], procpast[35];
X struct direct dirbuf;
X struct tm *p, *localtime();
X long clock;
X
X/*-------------------------------------------------------------------------*
X * compute real time, move 'at' jobs whose filenames < real time to *
X * DIRNAME/past and start a sh for each job *
X *-------------------------------------------------------------------------*/
X time(&clock);
X p = localtime(&clock);
X sprintf(realtime, "%02d.%03d.%02d%02d.00",
X p->tm_year%100, p->tm_yday, p->tm_hour, p->tm_min);
X if ((fd = open(DIRNAME", 0)) > 0)
X while (read(fd, (char *)&dirbuf, sizeof(dirbuf)) > 0)
X if (dirbuf.d_ino > 0 &&
X dirbuf.d_name[0] != '.' &&
X dirbuf.d_name[0] != 'p' &&
X strncmp(dirbuf.d_name, realtime, 11) < 0 ) {
X
X sprintf(procname, DIRNAME/%.14s", dirbuf.d_name);
X sprintf(procpast, DIRNAME/past/%.14s", dirbuf.d_name);
X
X if (fork() == 0) /* code for child */
X if (link(procname, procpast) == 0){ /* link ok? */
X unlink(procname);
X execl("/bin/sh", "sh", procpast, 0);
X fprintf(stderr,"proc %s can't start\n", procpast);
X exit(1);
X }
X }
X
X}
+ END-OF-FILE atrun.c
chmod 'u=rw,g=r,o=r' 'atrun.c'
set `wc -c 'atrun.c'`
count=$1
case $count in
1730) :;;
*) echo 'Bad character count in ''atrun.c' >&2
echo 'Count should be 1730' >&2
esac
echo Extracting 'date.c.cdif'
sed 's/^X//' > 'date.c.cdif' << '+ END-OF-FILE ''date.c.cdif'
X*** /local/ast/minix/tape3a/commands/date.c Mon May 16 15:03:48 1988
X--- date.c Wed Jul 13 13:10:50 1988
X***************
X*** 20,25 ****
X--- 20,26 ----
X long s_p_hour;
X long s_p_day;
X long s_p_year;
X+ char time_buf[15];
X
X main(argc, argv)
X int argc;
X***************
X*** 35,55 ****
X if (argc == 2) {
X if (*argv[1] == '-' && (argv[1][1] | 0x60) == 'q') {
X /* Query option. */
X- char time_buf[15];
X-
X qflag = 1;
X freopen(stdin, "/dev/tty0", "r");
X printf("\nPlease enter date (MMDDYYhhmmss). Then hit RETURN.\n");
X gets(time_buf);
X- set_time(time_buf);
X- exit(0);
X }
X! set_time(argv[1]);
X! } else {
X! time(&t);
X! cv_time(t);
X! printf("%s %s %d %02d:%02d:%02d %d\n", days[(t / s_p_day) % 7], months[tm.month], tm.day, tm.hour, tm.min, tm.sec, tm.year);
X }
X exit(0);
X }
X
X--- 36,55 ----
X if (argc == 2) {
X if (*argv[1] == '-' && (argv[1][1] | 0x60) == 'q') {
X /* Query option. */
X qflag = 1;
X freopen(stdin, "/dev/tty0", "r");
X printf("\nPlease enter date (MMDDYYhhmmss). Then hit RETURN.\n");
X gets(time_buf);
X }
X! if (qflag)
X! set_time(time_buf);
X! else
X! set_time(argv[1]);
X }
X+ time(&t);
X+ cv_time(t);
X+ printf("%s %s %d %02d:%02d:%02d %d\n", days[(int) (t / s_p_day) % 7],
X+ months[tm.month], tm.day, tm.hour, tm.min, tm.sec, tm.year);
X exit(0);
X }
X
X***************
X*** 69,75 ****
X t -= s_p_year;
X }
X if (((tm.year + 2) % 4) == 0)
X! days_per_month[1]++;
X tm.year += 1970;
X while ( t >= (days_per_month[tm.month] * s_p_day))
X t -= days_per_month[tm.month++] * s_p_day;
X--- 69,75 ----
X t -= s_p_year;
X }
X if (((tm.year + 2) % 4) == 0)
X! days_per_month[1] = 29;
X tm.year += 1970;
X while ( t >= (days_per_month[tm.month] * s_p_day))
X t -= days_per_month[tm.month++] * s_p_day;
X***************
X*** 120,126 ****
X ct = tm.year * s_p_year;
X ct += ((tm.year + 1) / 4) * s_p_day;
X if (((tm.year + 2) % 4) == 0)
X! days_per_month[1]++;
X len = 0;
X tm.month--;
X while (len < tm.month)
X--- 120,126 ----
X ct = tm.year * s_p_year;
X ct += ((tm.year + 1) / 4) * s_p_day;
X if (((tm.year + 2) % 4) == 0)
X! days_per_month[1] = 29;
X len = 0;
X tm.month--;
X while (len < tm.month)
+ END-OF-FILE date.c.cdif
chmod 'u=rw,g=r,o=r' 'date.c.cdif'
set `wc -c 'date.c.cdif'`
count=$1
case $count in
2227) :;;
*) echo 'Bad character count in ''date.c.cdif' >&2
echo 'Count should be 2227' >&2
esac
echo Extracting 'fgrep.c.cdif'
sed 's/^X//' > 'fgrep.c.cdif' << '+ END-OF-FILE ''fgrep.c.cdif'
X*** /local/ast/minix/tape3a/commands/fgrep.c Sun May 29 15:13:37 1988
X--- fgrep.c Wed Jul 13 13:10:55 1988
X***************
X*** 272,294 ****
X
X } /* exhausted buffer or found \n */
X
X! if (endline) break; /* don't continue if \n found */
X status=read(infile,mybuf,2048);
X! if (status==0) break;
X
X low=mybuf;
X high= &mybuf[status];
X
X }
X
X- if (endline)
X- {
X- *(p-1)='\0';
X- return (p-buf-1);
X- }
X-
X /* empty line or a bit filled ? */
X *p='\0';
X if (p-buf) return(p-buf);
X return(EOF);
X
X--- 272,298 ----
X
X } /* exhausted buffer or found \n */
X
X! /* don't continue if \n found */
X! if (endline)
X! {
X! *(p-1)='\0';
X! return (p-buf-1);
X! }
X!
X status=read(infile,mybuf,2048);
X! if (status<=0) break;
X
X low=mybuf;
X high= &mybuf[status];
X
X }
X
X /* empty line or a bit filled ? */
X *p='\0';
X+ if (status<0){
X+ perror("read error");
X+ return(EOF);
X+ }
X if (p-buf) return(p-buf);
X return(EOF);
X
+ END-OF-FILE fgrep.c.cdif
chmod 'u=rw,g=r,o=r' 'fgrep.c.cdif'
set `wc -c 'fgrep.c.cdif'`
count=$1
case $count in
1045) :;;
*) echo 'Bad character count in ''fgrep.c.cdif' >&2
echo 'Count should be 1045' >&2
esac
echo Extracting 'libupack.c.cdif'
sed 's/^X//' > 'libupack.c.cdif' << '+ END-OF-FILE ''libupack.c.cdif'
X*** /local/ast/minix/tape3a/commands/libupack.c Mon May 16 15:03:59 1988
X--- libupack.c Wed Jul 13 13:10:58 1988
X***************
X*** 122,140 ****
X
X #define IBUFSIZE 10000
X #define OBUFSIZE 30000
X
X char input[IBUFSIZE+1], output[OBUFSIZE+1];
X
X main()
X {
X! int n, count;
X
X while (1) {
X n = read(0, input,IBUFSIZE);
X if (n <= 0) exit(1);
X input[n] = 0;
X count = unpack88(input, output);
X! n = write(1, output, count);
X }
X }
X
X--- 122,147 ----
X
X #define IBUFSIZE 10000
X #define OBUFSIZE 30000
X+ #define OUTMAX (7*1024)
X
X char input[IBUFSIZE+1], output[OBUFSIZE+1];
X
X main()
X {
X! int n, count, bytes, cum;
X
X while (1) {
X n = read(0, input,IBUFSIZE);
X if (n <= 0) exit(1);
X input[n] = 0;
X count = unpack88(input, output);
X! cum = 0;
X! while (count > 0) {
X! bytes = (count < OUTMAX ? count : OUTMAX);
X! n = write(1, output+cum, bytes);
X! count -= bytes;
X! cum += bytes;
X! }
X }
X }
X
+ END-OF-FILE libupack.c.cdif
chmod 'u=rw,g=r,o=r' 'libupack.c.cdif'
set `wc -c 'libupack.c.cdif'`
count=$1
case $count in
949) :;;
*) echo 'Bad character count in ''libupack.c.cdif' >&2
echo 'Count should be 949' >&2
esac
echo Extracting 'login.c.cdif'
sed 's/^X//' > 'login.c.cdif' << '+ END-OF-FILE ''login.c.cdif'
X*** /local/ast/minix/tape3a/commands/login.c Mon May 16 15:03:59 1988
X--- login.c Wed Jul 13 13:11:00 1988
X***************
X*** 3,27 ****
X #include <signal.h>
X #include <sgtty.h>
X #include <pwd.h>
X
X! char home[100] = "HOME=";
X! char *env[] = { home, 0 };
X
X main()
X {
X! char buf[30],
X! buf1[30],
X! *crypt();
X! int n, n1, bad;
X struct sgttyb args;
X struct passwd *pwd, *getpwnam();
X
X args.sg_kill = '@';
X args.sg_erase = '\b';
X! args.sg_flags = 06030;
X! ioctl (0, TIOCSETP, &args);
X
X-
X /* Get login name and passwd. */
X for (;;) {
X bad = 0;
X--- 3,41 ----
X #include <signal.h>
X #include <sgtty.h>
X #include <pwd.h>
X+ #include <sys/stat.h>
X
X! #define NULL (char *) 0
X! #define WTMPSIZE 8
X! #define DIGIT 3
X
X+ char user[32];
X+ char home[64];
X+ char ttyname[] = {"tty?"};
X+ char *wtmpfile = "/usr/adm/wtmp";
X+ char *env[] = {user, home, "TERM=minix", (char *)0 };
X+
X main()
X {
X! char buf[30], buf1[30], *crypt(), *p, *q;
X! int n, n1, bad, oldflags, ttynr;
X struct sgttyb args;
X+ struct stat statbuf;
X struct passwd *pwd, *getpwnam();
X
X+ /* Look up /dev/tty number. */
X+ fstat(0, &statbuf);
X+ ttynr = statbuf.st_rdev & 0377;
X+ ttyname[DIGIT] = '0' + ttynr;
X+
X+ /* Reset some of the line parameters in case they have been mashed. */
X+ ioctl(0, TIOCGETP, &args);
X args.sg_kill = '@';
X args.sg_erase = '\b';
X! oldflags = args.sg_flags & 01700; /* save char len, parity */
X! args.sg_flags = oldflags | XTABS | CRMOD | ECHO;
X! ioctl(0, TIOCSETP, &args);
X
X /* Get login name and passwd. */
X for (;;) {
X bad = 0;
X***************
X*** 32,65 ****
X buf[n - 1] = 0;
X
X /* Look up login/passwd. */
X! if ((pwd = getpwnam (buf)) == 0)
X! bad++;
X
X if (bad || strlen (pwd->pw_passwd) != 0) {
X! args.sg_flags = 06020;
X! ioctl (0, TIOCSETP, &args);
X write(1,"Password: ",10);
X n1 = read (0, buf1, 30);
X buf1[n1 - 1] = 0;
X write(1,"\n",1);
X! args.sg_flags = 06030;
X! ioctl (0, TIOCSETP, &args);
X! if (bad) crypt(buf1, "*"); /* be as slow */
X! if (bad || strcmp (pwd->pw_passwd, crypt(buf1, pwd->pw_passwd))) {
X write (1,"Login incorrect\n",16);
X continue;
X }
X }
X
X! /* Successful login. */
X setgid (pwd->pw_gid);
X setuid (pwd->pw_uid);
X chdir (pwd->pw_dir);
X! strcpy(pwd->pw_dir, home+5);
X! if (pwd->pw_shell) {
X! execle(pwd->pw_shell, "-", (char *) 0, env);
X! }
X! execle("/bin/sh", "-", (char *) 0, env);
X! write(1,"exec failure\n",13);
X }
X }
X--- 46,115 ----
X buf[n - 1] = 0;
X
X /* Look up login/passwd. */
X! if ((pwd = getpwnam (buf)) == 0) bad++;
X
X+ /* If login name wrong or password exists, ask for pw. */
X if (bad || strlen (pwd->pw_passwd) != 0) {
X! args.sg_flags &= ~ECHO;
X! ioctl(0, TIOCSETP, &args);
X write(1,"Password: ",10);
X n1 = read (0, buf1, 30);
X buf1[n1 - 1] = 0;
X write(1,"\n",1);
X! args.sg_flags |= ECHO;
X! ioctl(0, TIOCSETP, &args);
X! if (bad || strcmp (pwd->pw_passwd,
X! crypt(buf1, pwd->pw_passwd))) {
X write (1,"Login incorrect\n",16);
X continue;
X }
X }
X
X! /* Successful login. Set up environment. */
X setgid (pwd->pw_gid);
X setuid (pwd->pw_uid);
X chdir (pwd->pw_dir);
X! strcpy(home, "HOME=");
X! strcat(home, pwd->pw_dir);
X! strcpy(user, "USER=");
X! strcat(user, pwd->pw_name);
X!
X! /* Reset signals to default values. */
X! for(n = 1; n <= NR_SIGS; ++n) signal(n, SIG_DFL);
X!
X! /* Creat wmtp entry. */
X! wtmp(ttyname, pwd->pw_name);
X!
X! /* If shell has been specified, exec it, else use /bin/sh. */
X! if (pwd->pw_shell)
X! execle(pwd->pw_shell, "-", NULL, env);
X! execle("/bin/sh", "-", NULL, env);
X! write(1,"login can't exec shell\n",23);
X }
X+ }
X+
X+
X+ wtmp(tty, name)
X+ {
X+ /* Make an entry in /usr/adm/wtmp. */
X+
X+ int i, fd;
X+ long t, time();
X+ char ttybuff[WTMPSIZE], namebuff[WTMPSIZE];
X+
X+ fd = open(wtmpfile, 2);
X+ if (fd < 0) return; /* if wtmp does not exist, no accounting */
X+ lseek(fd, 0L, 2); /* append to file */
X+
X+ for (i = 0; i < WTMPSIZE; i++) {
X+ ttybuff[i] = 0;
X+ namebuff[i] = 0;
X+ }
X+ strncpy(ttybuff, tty, 8);
X+ strncpy(namebuff, name, 8);
X+ time(&t);
X+ write(fd, ttybuff, WTMPSIZE);
X+ write(fd, namebuff, WTMPSIZE);
X+ write(fd, &t, sizeof(t));
X+ close(fd);
X }
+ END-OF-FILE login.c.cdif
chmod 'u=rw,g=r,o=r' 'login.c.cdif'
set `wc -c 'login.c.cdif'`
count=$1
case $count in
4326) :;;
*) echo 'Bad character count in ''login.c.cdif' >&2
echo 'Count should be 4326' >&2
esac
echo Extracting 'lorder.c.cdif'
sed 's/^X//' > 'lorder.c.cdif' << '+ END-OF-FILE ''lorder.c.cdif'
X*** /local/ast/minix/tape3a/commands/lorder.c Mon May 16 15:04:00 1988
X--- lorder.c Wed Jul 13 13:11:00 1988
X***************
X*** 18,23 ****
X--- 18,25 ----
X *
X * change log:
X * corrected & rewrote scanner to avoid lex. - 2/22/88 - mrw
X+ * oops reversed output filename order. 3/14/88 - mrw
X+ * progname = argv[0] - should be first. 5/25/88 - mbeck
X */
X
X #include <stdio.h>
X***************
X*** 30,36 ****
X FILE *lexin;
X char *yyfile;
X char *tmpfile;
X! char *progname = "lorder";
X char template[] = "lorder.XXXXXX";
X
X struct filelist {
X--- 32,38 ----
X FILE *lexin;
X char *yyfile;
X char *tmpfile;
X! char *progname;
X char template[] = "lorder.XXXXXX";
X
X struct filelist {
X***************
X*** 59,66 ****
X int i;
X char cmdstr[MAXLINE];
X
X if (argc > 1) {
X- progname = argv[0];
X signal(SIGINT, user_abort);
X for (i = 1; argv[i] && *argv[i]; ++i ) {
X /* the following code is caused by
X--- 61,68 ----
X int i;
X char cmdstr[MAXLINE];
X
X+ progname = argv[0];
X if (argc > 1) {
X signal(SIGINT, user_abort);
X for (i = 1; argv[i] && *argv[i]; ++i ) {
X /* the following code is caused by
X***************
X*** 173,179 ****
X if (t->file) {
X for (fp = t->list; fp && fp->name; fp = fp->next)
X if (t->file != fp->name)
X! fprintf(stdout,"%s %s\n",fp->name,t->file);
X }
X printtree(t->right);
X printtree(t->left);
X--- 175,181 ----
X if (t->file) {
X for (fp = t->list; fp && fp->name; fp = fp->next)
X if (t->file != fp->name)
X! fprintf(stdout,"%s %s\n",fp->name, t->file);
X }
X printtree(t->right);
X printtree(t->left);
X***************
X*** 402,404 ****
X--- 404,407 ----
X */
X return (lastch);
X }
X+
+ END-OF-FILE lorder.c.cdif
chmod 'u=rw,g=r,o=r' 'lorder.c.cdif'
set `wc -c 'lorder.c.cdif'`
count=$1
case $count in
1697) :;;
*) echo 'Bad character count in ''lorder.c.cdif' >&2
echo 'Count should be 1697' >&2
esac
echo Extracting 'ls.c.cdif'
sed 's/^X//' > 'ls.c.cdif' << '+ END-OF-FILE ''ls.c.cdif'
X*** /local/ast/minix/tape3a/commands/ls.c Mon May 16 15:04:03 1988
X--- ls.c Wed Jul 13 13:11:02 1988
X***************
X*** 531,537 ****
X /* At this point, 'year', 'month', 'day', 'hour', 'minute' ok */
X if (curtime == 0) curtime = time( (long*)0); /* approximate current time */
X fprintf(stdout, "%3s %2d ",moname[month], day+1);
X! if (curtime - original >= YEAR/2L) {
X fprintf(stdout, "%5d ",year);
X } else {
X if (hour < 10)
X--- 531,537 ----
X /* At this point, 'year', 'month', 'day', 'hour', 'minute' ok */
X if (curtime == 0) curtime = time( (long*)0); /* approximate current time */
X fprintf(stdout, "%3s %2d ",moname[month], day+1);
X! if (curtime - original >= YEAR/2L || curtime < original) {
X fprintf(stdout, "%5d ",year);
X } else {
X if (hour < 10)
+ END-OF-FILE ls.c.cdif
chmod 'u=rw,g=r,o=r' 'ls.c.cdif'
set `wc -c 'ls.c.cdif'`
count=$1
case $count in
791) :;;
*) echo 'Bad character count in ''ls.c.cdif' >&2
echo 'Count should be 791' >&2
esac
echo Extracting 'mknod.c.cdif'
sed 's/^X//' > 'mknod.c.cdif' << '+ END-OF-FILE ''mknod.c.cdif'
X*** /local/ast/minix/tape3a/commands/mknod.c Mon May 16 15:04:07 1988
X--- mknod.c Wed Jul 13 13:11:07 1988
X***************
X*** 19,38 ****
X exit(0);
X }
X
X- int atoi(p)
X- char *p;
X- {
X- /* Ascii to integer conversion. */
X- int c, n;
X-
X- n = 0;
X- while (c = *p++) {
X- if (c < '0' || c > '9') return (-1);
X- n = 10 * n + (c - '0');
X- }
X- return(n);
X- }
X-
X badcomm()
X {
X std_err("Usage: mknod name b/c major minor\n");
X--- 19,24 ----
+ END-OF-FILE mknod.c.cdif
chmod 'u=rw,g=r,o=r' 'mknod.c.cdif'
set `wc -c 'mknod.c.cdif'`
count=$1
case $count in
453) :;;
*) echo 'Bad character count in ''mknod.c.cdif' >&2
echo 'Count should be 453' >&2
esac
echo Extracting 'pwd.c.cdif'
sed 's/^X//' > 'pwd.c.cdif' << '+ END-OF-FILE ''pwd.c.cdif'
X*** /local/ast/minix/tape3a/commands/pwd.c Mon May 16 15:04:11 1988
X--- pwd.c Wed Jul 13 13:11:11 1988
X***************
X*** 58,63 ****
X--- 58,64 ----
X prints("/");
X else
X while (n = last_index(name, '/')) {
X+ *(n+14) = 0;
X prints(n);
X *n = 0;
X }
+ END-OF-FILE pwd.c.cdif
chmod 'u=rw,g=r,o=r' 'pwd.c.cdif'
set `wc -c 'pwd.c.cdif'`
count=$1
case $count in
267) :;;
*) echo 'Bad character count in ''pwd.c.cdif' >&2
echo 'Count should be 267' >&2
esac
echo Extracting 'shar.c.cdif'
sed 's/^X//' > 'shar.c.cdif' << '+ END-OF-FILE ''shar.c.cdif'
X*** /local/ast/minix/tape3a/commands/shar.c Mon May 16 15:04:20 1988
X--- shar.c Wed Jul 13 13:11:15 1988
X***************
X*** 1,13 ****
X /* shar - make a shell archive Author: Michiel Husijes */
X
X!
X #include <minix/blocksize.h>
X
X #define IO_SIZE (10 * BLOCK_SIZE)
X
X char input[IO_SIZE];
X char output[IO_SIZE];
X! int index = 0;
X
X main(argc, argv)
X int argc;
X--- 1,13 ----
X /* shar - make a shell archive Author: Michiel Husijes */
X
X! #include <stdio.h>
X #include <minix/blocksize.h>
X
X #define IO_SIZE (10 * BLOCK_SIZE)
X
X char input[IO_SIZE];
X char output[IO_SIZE];
X! int ind = 0;
X
X main(argc, argv)
X int argc;
X***************
X*** 25,37 ****
X else {
X print("echo x - ");
X print(argv[i]);
X! print("\ngres '^X' '' > ");
X print(argv[i]);
X print(" << '/'\n");
X cat(fd);
X }
X }
X! if (index) write(1, output, index);
X exit(0);
X }
X
X--- 25,37 ----
X else {
X print("echo x - ");
X print(argv[i]);
X! print("\nsed '/^X/s///' > ");
X print(argv[i]);
X print(" << '/'\n");
X cat(fd);
X }
X }
X! if (ind) write(1, output, ind);
X exit(0);
X }
X
X***************
X*** 64,77 ****
X {
X while (*str)
X putchar(*str++);
X- }
X-
X- putchar(c)
X- register char c;
X- {
X- output[index++] = c;
X- if (index == IO_SIZE) {
X- write(1, output, index);
X- index = 0;
X- }
X }
X--- 64,67 ----
+ END-OF-FILE shar.c.cdif
chmod 'u=rw,g=r,o=r' 'shar.c.cdif'
set `wc -c 'shar.c.cdif'`
count=$1
case $count in
1388) :;;
*) echo 'Bad character count in ''shar.c.cdif' >&2
echo 'Count should be 1388' >&2
esac
echo Extracting 'stty.c.cdif'
sed 's/^X//' > 'stty.c.cdif' << '+ END-OF-FILE ''stty.c.cdif'
X*** /local/ast/minix/tape3a/commands/stty.c Mon Jun 27 22:58:11 1988
X--- stty.c Wed Jul 13 13:11:18 1988
X***************
X*** 13,18 ****
X--- 13,20 ----
X #define QUITC 034 /* CTRL-\ */
X #define EOFC 004 /* CTRL-D */
X #define DELC 0177 /* DEL */
X+ #define BYTE 0377
X+ #define FD 0 /* which file descriptor to use */
X
X #define speed(s) args.sg_ispeed = s; args.sg_ospeed = s
X #define clr1 args.sg_flags &= ~(BITS5 | BITS6 | BITS7 | BITS8)
X***************
X*** 24,31 ****
X {
X
X /* stty with no arguments just reports on current status. */
X! ioctl(0, TIOCGETP, &args);
X! ioctl(0, TIOCGETC, &tch);
X if (argc == 1) {
X report();
X exit(0);
X--- 26,33 ----
X {
X
X /* stty with no arguments just reports on current status. */
X! ioctl(FD, TIOCGETP, &args);
X! ioctl(FD, TIOCGETC, &tch);
X if (argc == 1) {
X report();
X exit(0);
X***************
X*** 37,44 ****
X option(argv[k], k+1 < argc ? argv[k+1] : "");
X k++;
X }
X! ioctl(0, TIOCSETP, &args);
X! ioctl(0, TIOCSETC, &tch);
X exit(0);
X }
X
X--- 39,46 ----
X option(argv[k], k+1 < argc ? argv[k+1] : "");
X k++;
X }
X! ioctl(FD, TIOCSETP, &args);
X! ioctl(FD, TIOCSETC, &tch);
X exit(0);
X }
X
X***************
X*** 46,64 ****
X
X report()
X {
X! int mode;
X
X-
X mode = args.sg_flags;
X pr(mode&XTABS, 0);
X pr(mode&CBREAK, 1);
X pr(mode&RAW, 2);
X pr(mode&CRMOD,3);
X pr(mode&ECHO,4);
X prints("\nkill = "); prctl(args.sg_kill);
X prints("\nerase = "); prctl(args.sg_erase);
X prints("\nint = "); prctl(tch.t_intrc);
X prints("\nquit = "); prctl(tch.t_quitc);
X prints("\n");
X }
X
X--- 48,80 ----
X
X report()
X {
X! int mode, ispeed, ospeed;
X
X mode = args.sg_flags;
X pr(mode&XTABS, 0);
X pr(mode&CBREAK, 1);
X pr(mode&RAW, 2);
X pr(mode&CRMOD,3);
X pr(mode&ECHO,4);
X+
X+ ispeed = 100 * ((int) args.sg_ispeed & BYTE);
X+ ospeed = 100 * ((int) args.sg_ospeed & BYTE);
X prints("\nkill = "); prctl(args.sg_kill);
X prints("\nerase = "); prctl(args.sg_erase);
X prints("\nint = "); prctl(tch.t_intrc);
X prints("\nquit = "); prctl(tch.t_quitc);
X+ if (ispeed > 0) {
X+ prints("\nspeed = ");
X+ switch(ispeed) {
X+ case 100: prints("110"); break;
X+ case 300: prints("300"); break;
X+ case 1200: prints("1200"); break;
X+ case 2400: prints("2400"); break;
X+ case 4800: prints("4800"); break;
X+ case 9600: prints("9600"); break;
X+ default: prints("unknown");
X+ }
X+ }
X prints("\n");
X }
X
+ 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
2474) :;;
*) echo 'Bad character count in ''stty.c.cdif' >&2
echo 'Count should be 2474' >&2
esac
echo Extracting 'su.c.cdif'
sed 's/^X//' > 'su.c.cdif' << '+ END-OF-FILE ''su.c.cdif'
X*** /local/ast/minix/tape3a/commands/su.c Mon May 16 15:04:23 1988
X--- su.c Wed Jul 13 13:11:20 1988
X***************
X*** 48,54 ****
X setuid (pwd->pw_uid);
X if (pwd->pw_shell[0])
X shell = pwd->pw_shell;
X! execl (shell, 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, "-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
435) :;;
*) echo 'Bad character count in ''su.c.cdif' >&2
echo 'Count should be 435' >&2
esac
echo Extracting 'sum.c.cdif'
sed 's/^X//' > 'sum.c.cdif' << '+ END-OF-FILE ''sum.c.cdif'
X*** /local/ast/minix/tape3a/commands/sum.c Mon May 16 15:04:24 1988
X--- sum.c Wed Jul 13 13:11:20 1988
X***************
X*** 21,27 ****
X int argc;
X char *argv[];
X {
X! int fd;
X
X if (*++argv == 0)
X argv = defargv;
X--- 21,27 ----
X int argc;
X char *argv[];
X {
X! register int fd;
X
X if (*++argv == 0)
X argv = defargv;
X***************
X*** 58,64 ****
X char *fname;
X {
X char buf[BUFSIZ];
X! int i,n;
X long size = 0;
X unsigned crc = 0;
X unsigned tmp, blks;
X--- 58,64 ----
X char *fname;
X {
X char buf[BUFSIZ];
X! register int i,n;
X long size = 0;
X unsigned crc = 0;
X unsigned tmp, blks;
+ END-OF-FILE sum.c.cdif
chmod 'u=rw,g=r,o=r' 'sum.c.cdif'
set `wc -c 'sum.c.cdif'`
count=$1
case $count in
627) :;;
*) echo 'Bad character count in ''sum.c.cdif' >&2
echo 'Count should be 627' >&2
esac
echo Extracting 'tar.c.cdif'
sed 's/^X//' > 'tar.c.cdif' << '+ END-OF-FILE ''tar.c.cdif'
X*** /local/ast/minix/tape3a/commands/tar.c Mon May 16 15:04:25 1988
X--- tar.c Wed Jul 13 13:11:21 1988
X***************
X*** 1,6 ****
X /* tar - tape archiver Author: Michiel Huisjes */
X
X! /* Usage: tar [cxt][v] tapefile [files]
X *
X * Bugs:
X * This tape archiver should only be used as a program to read or make
X--- 1,6 ----
X /* tar - tape archiver Author: Michiel Huisjes */
X
X! /* Usage: tar [cxt] tapefile [files]
X *
X * Bugs:
X * This tape archiver should only be used as a program to read or make
X***************
X*** 57,62 ****
X--- 57,63 ----
X char io_buffer[BLOCK_SIZE];
X char path[NAME_SIZE];
X char pathname[NAME_SIZE];
X+ extern printf();
X
X int total_blocks;
X long convert();
X***************
X*** 101,107 ****
X if (creat_fl + ext_fl + show_fl != 1)
X error(usage, NIL_PTR);
X
X! tar_fd = creat_fl ? creat(argv[2], 0644) : open(argv[2], 0);
X
X if (tar_fd < 0)
X error("Cannot open ", argv[2]);
X--- 102,112 ----
X if (creat_fl + ext_fl + show_fl != 1)
X error(usage, NIL_PTR);
X
X! if (strcmp(argv[2], "-") != 0) {
X! tar_fd = creat_fl ? creat(argv[2], 0644) : open(argv[2], 0);
X! } else {
X! tar_fd = (creat_fl ? 1 : 0);
X! }
X
X if (tar_fd < 0)
X error("Cannot open ", argv[2]);
X***************
X*** 424,430 ****
X static int index = 0;
X
X if (str == NIL_PTR) {
X! write(1, output, index);
X index = 0;
X return;
X }
X--- 429,435 ----
X static int index = 0;
X
X if (str == NIL_PTR) {
X! write(2, output, index);
X index = 0;
X return;
X }
X***************
X*** 432,438 ****
X while (*str) {
X output[index++] = *str++;
X if (index == BLOCK_SIZE) {
X! write(1, output, BLOCK_SIZE);
X index = 0;
X }
X }
X--- 437,443 ----
X while (*str) {
X output[index++] = *str++;
X if (index == BLOCK_SIZE) {
X! write(2, output, BLOCK_SIZE);
X index = 0;
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
1841) :;;
*) echo 'Bad character count in ''tar.c.cdif' >&2
echo 'Count should be 1841' >&2
esac
echo Extracting 'term.c'
sed 's/^X//' > 'term.c' << '+ END-OF-FILE ''term.c'
X/* term - terminal simulator Author: Andy Tanenbaum */
X
X/* This program allows the user to turn a MINIX system into a dumb
X * terminal to communicate with a remote computer over a modem. It
X * forks into two processes. The parent sits in a tight loop copying
X * from the keyboard to the modem. The child sits in a tight loop
X * copying from the modem to the screen.
X *
X * Example usage:
X * term : 1200 baud, 8 bits/char, no parity
X * term 9600 7 even : 9600 baud, 7 bits/char, even parity
X * term odd 300 7 : 300 baud, 7 bits/char, odd parity
X */
X
X#include <signal.h>
X#include <sgtty.h>
X
X#define MAXARGS 3 /* maximum number of uart params */
X#define NCHECKS 10
X#define BAD -1
X#define GOOD 1
X#define DEF_SPEED B1200 /* default baudrate */
X#define DEF_BITS BITS8 /* default bits/char */
X#define MODEM "/dev/tty1" /* special file attached to the modem */
X#define ESC 033 /* character to hit to leave simulator */
X#define LIMIT 3 /* how often do you have to hit ESC to exit*/
X
Xint modem, pid; /* file descriptor for modem */
Xchar *pat[NCHECKS] =
X {"5", "6", "7", "8", "110", "300", "1200", "2400", "4800", "9600"};
X
Xint value[NCHECKS] =
X {BITS5, BITS6, BITS7, BITS8, B110, B300, B1200, B2400, B4800, B9600};
X
Xint hold[MAXARGS];
Xstruct sgttyb sgtty, sgsave1, sgsave2;
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X
X sync();
X modem = open(MODEM, 2);
X if (modem < 0) {
X printf("Can't open modem on %s\n", MODEM);
X exit(1);
X }
X set_uart(argc, argv);
X
X /* Main body of the terminal simulator. */
X if ( (pid = fork()))
X copy(0, modem, ESC); /* copy from stdin to modem */
X else
X copy(modem, 1, -1); /* copy from modem to stdout */
X}
X
Xset_uart(argc, argv)
Xint argc;
Xchar *argv[];
X{
X/* Set up the UART parameters. */
X
X int i, k, v, nspeeds = 0, speed, nbits = 0, bits, parity = 0;
X
X if (argc > MAXARGS + 1)
X error("Usage: term [baudrate] [data_bits] [parity]\n");
X
X /* Examine all the parameters and check for validity. */
X speed = DEF_SPEED; /* default line speed */
X bits = DEF_BITS; /* default bits/char */
X for (i = 1; i < argc; i++) {
X if (strcmp(argv[i], "even") == 0) {parity = ODDP; continue;}
X if (strcmp(argv[i], "odd") == 0) {parity = EVENP; continue;}
X v = validity(argv[i]);
X if (v == BAD) {
X printf("Invalid parameter: %s\n", argv[i]);
X exit(1);
X }
X k = atoi(argv[i]);
X if (k > 100) {
X speed = value[v];
X nspeeds++;
X }
X if ( k < 10) {
X bits = value[v];
X nbits++;
X }
X if (nspeeds > 1) error("Too many speeds\n");
X if (nbits > 1) error("Too many character sizes\n");
X
X }
X
X /* Fetch the modem parameters, save them, and set new ones. */
X ioctl(modem, TIOCGETP, &sgtty);
X sgsave1 = sgtty; /* modem parameters */
X sgtty.sg_ispeed = speed;
X sgtty.sg_ospeed = speed;
X sgtty.sg_flags = RAW | parity | bits;
X ioctl(modem, TIOCSETP, &sgtty);
X
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
Xint validity(s)
Xchar *s;
X{
X/* Check parameter for legality. */
X
X int i;
X
X for (i = 0; i < NCHECKS; i++) {
X if (strcmp(s, pat[i]) == 0) return(i);
X }
X return(BAD);
X}
X
X
Xcopy(in, out, end)
Xint in, out, end;
X{
X/* Copy from the keyboard to the modem or vice versa. If the end character
X * is seen LIMIT times in a row, quit. For the traffic from the modem, the
X * end character is -1, which cannot occur since the characters from the
X * modem are unsigned integers in the range 0 to 255.
X */
X
X int t, state = 0;
X char c;
X
X while (1) {
X if (read(in, &c, 1) != 1) {
X printf("Can't read from modem\r\n");
X quit();
X }
X t = c & 0377; /* note: t is unsigned int 0 - 255 */
X if (t == end) {
X state++;
X if (state == LIMIT) quit();
X } else {
X state = 0;
X }
X write(out, &c, 1);
X }
X}
X
X
Xerror(s)
Xchar *s;
X{
X printf("%s", s);
X exit(1);
X}
X
Xquit()
X{
X ioctl(modem, TIOCSETP, &sgsave1);
X ioctl(0, TIOCSETP, &sgsave2);
X if (getpid() != pid) kill(pid, SIGINT);
X exit(0);
X}
+ END-OF-FILE term.c
chmod 'u=rw,g=r,o=r' 'term.c'
set `wc -c 'term.c'`
count=$1
case $count in
3959) :;;
*) echo 'Bad character count in ''term.c' >&2
echo 'Count should be 3959' >&2
esac
echo Extracting 'uudecode.c.cdif'
sed 's/^X//' > 'uudecode.c.cdif' << '+ END-OF-FILE ''uudecode.c.cdif'
X*** /local/ast/minix/tape3a/commands/uudecode.c Mon May 16 15:04:29 1988
X--- uudecode.c Wed Jul 13 13:11:25 1988
X***************
X*** 185,204 ****
X }
X return (cnt);
X }
X-
X- /*
X- * Return the ptr in sp at which the character c appears;
X- * NULL if not found
X- */
X-
X-
X- char *
X- index(sp, c)
X- register char *sp, c;
X- {
X- do {
X- if (*sp == c)
X- return(sp);
X- } while (*sp++);
X- return(NULL);
X- }
X--- 185,187 ----
+ END-OF-FILE uudecode.c.cdif
chmod 'u=rw,g=r,o=r' 'uudecode.c.cdif'
set `wc -c 'uudecode.c.cdif'`
count=$1
case $count in
428) :;;
*) echo 'Bad character count in ''uudecode.c.cdif' >&2
echo 'Count should be 428' >&2
esac
exit 0