@CH-FOR18p  )|NO NAME FAT12 3м|PPPPPiP:3S|Sr &>}Uu˾t223 uV^FDBOOT Version 1.8 No Systemdisk. Booting from harddisk. Cannot load from harddisk. Insert Systemdisk and press any key. U./usr/src/cmd/ar/pdp11/ar.c 664 2 2 32354 3172123723 10437 continue; default: fprintf(stderr, "ar: bad option `%c'\n", *cp); usage(); } if(flg['l'-'a']) { tmp0nam = "vXXXXX"; tmp1nam = "v1XXXXX"; tmp2nam = "v2XXXXX"; } if(flg['i'-'a']) flg['b'-'a']++; if(flg['a'-'a'] || flg['b'-'a']) { bastate = 1; ponam = trim(argv[2]); argv++; argc--; if(argc < 3) usage(); } arnam = argv[2]; namv = argv+3; namc = argc-3; if(comfun == 0) { if(flg['u'-'a'] == 0) { fprintf(stderr, "ar: one of [%s] must be specified\n", man); usage(); /* @(#)ar.c 2.1 */ #include #include #include #include #include struct stat stbuf; struct ar_hdr arbuf; union {long l; short s[2]; char c[4]; } U; struct { char p_name[14]; unsigned short p_date1; unsigned short p_date2; char p_uid; char p_gid; unsigned short p_mode; unsigned short p_siz1; unsigned short p_siz2; } pbuf; struct { char v_name[14]; unsigned short v_pad1; unsigned short v_date1; unsigned short v_date2; char v_uid; char v_gid} setcom(rcmd); } (*comfun)(); done(notfound()); } setcom(fun) int (*fun)(); { if(comfun != 0) { fprintf(stderr, "ar: only one of [%s] allowed\n", man); usage(); } comfun = fun; } rcmd() { register f; getaf(); putmagic(); while(!getdir()) { bamatch(); if(namc == 0 || match()) { f = stats(); if(f < 0) { if(namc) fprintf(stderr, "ar: cannot open %s\n", file); goto cp; } if(flg['u'-'a']) if(stbuf.st_mtime <= arbuf.ar_date) { close(f); goto cp; ; unsigned short v_pad2; unsigned short v_mode; unsigned short v_pad3; unsigned short v_siz1; unsigned short v_siz2; } vbuf; #define SKIP 1 #define IODD 2 #define OODD 4 #define HEAD 8 #define ARMAGIC 0177545 #define PDP11 1 #define VAX11 0 char *man = { "mrxtdpq" }; char *opt = { "cuvnbail" }; int signum[] = {SIGHUP, SIGINT, SIGQUIT, 0}; int sigdone(); long lseek(); int rcmd(); int dcmd(); int xcmd(); int tcmd(); int pcmd(); int mcmd(); int qcmd(); int (*comfun)(); char flg[26]; char **namv; int n} mesg('r'); copyfil(af, -1, IODD+SKIP); movefil(f); continue; } cp: mesg('c'); copyfil(af, tf, IODD+OODD+HEAD); } cleanup(); } dcmd() { if(getaf()) noar(); putmagic(); while(!getdir()) { if(match()) { mesg('d'); copyfil(af, -1, IODD+SKIP); continue; } mesg('c'); copyfil(af, tf, IODD+OODD+HEAD); } install(); } xcmd() { register f; if(getaf()) noar(); while(!getdir()) { if(namc == 0 || match()) { f = creat(file, arbuf.ar_mode & 0777); if(f < 0) { amc; char *arnam; char *ponam; char *tmp0nam = { "/tmp/vXXXXX" }; char *tmp1nam = { "/tmp/v1XXXXX" }; char *tmp2nam = { "/tmp/v2XXXXX" }; char *tfnam; char *tf1nam; char *tf2nam; char *file; char name[16]; int artype; int af; int tf; int tf1; int tf2; int qf; int bastate; char buf[512]; char *trim(); char *mktemp(); char *ctime(); main(argc, argv) char *argv[]; { register i; register char *cp; for(i=0; signum[i]; i++) if(signal(signum[i], SIG_IGN) != SIG_IGN) signal(signum[i], sigdone); if(argc fprintf(stderr, "ar: %s cannot create\n", file); goto sk; } mesg('x'); copyfil(af, f, IODD); close(f); continue; } sk: mesg('c'); copyfil(af, -1, IODD+SKIP); if (namc > 0 && !morefil()) done(0); } } pcmd() { if(getaf()) noar(); while(!getdir()) { if(namc == 0 || match()) { if(flg['v'-'a']) { printf("\n<%s>\n\n", file); fflush(stdout); } copyfil(af, 1, IODD); continue; } copyfil(af, -1, IODD+SKIP); } } mcmd() { if(getaf()) noar(); p < 3) usage(); cp = argv[1]; U.l = 1L; if(U.c[0] == 0) artype = PDP11; for(cp = argv[1]; *cp; cp++) switch(*cp) { case 'l': case 'v': case 'u': case 'n': case 'a': case 'b': case 'c': case 'i': flg[*cp - 'a']++; continue; case 'r': setcom(rcmd); continue; case 'd': setcom(dcmd); continue; case 'x': setcom(xcmd); continue; case 't': setcom(tcmd); continue; case 'p': setcom(pcmd); continue; case 'm': setcom(mcmd); continue; case 'q': setcom(qcmd); utmagic(); tf2nam = mktemp(tmp2nam); close(creat(tf2nam, 0600)); tf2 = open(tf2nam, 2); if(tf2 < 0) { fprintf(stderr, "ar: cannot create third temp\n"); done(2); } while(!getdir()) { bamatch(); if(match()) { mesg('m'); copyfil(af, tf2, IODD+OODD+HEAD); continue; } mesg('c'); copyfil(af, tf, IODD+OODD+HEAD); } install(); } tcmd() { if(getaf()) noar(); while(!getdir()) { if(namc == 0 || match()) { if(flg['v'-'a']) longt(); printf("%s\n", trim(file)); } copynk(tfnam); if(tf1nam) unlink(tf1nam); if(tf2nam) unlink(tf2nam); exit(c); } notfound() { register i, n; n = 0; for(i=0; i 0) if (write(af, buf, i) != i) wrerr(); } if(tf2nam) { lseek(tf2, 0L, 0)/* PDP-11 Magic number is 0177545 VAX Magic number is 0177545 0000000 */ artype = VAX11; if(read(fd,(char *)&mbuf,sizeof(short)) != sizeof(short) || (unsigned short) mbuf != ARMAGIC){ fprintf(stderr, "ar: %s not in archive format\n", arnam); done(2); } read(fd,(char *)&mbuf,sizeof(short)); if(mbuf != 0){ artype = PDP11; lseek(fd, -2L, 1); /* back over good data */ } } putmagic(fd) { short mbuf; tfnam = mktemp(tmp0nam); close(creat(tfnam, 0600)); tf = open(tfnam, 2); if(tf < 0) { ; while((i = read(tf2, buf, 512)) > 0) if (write(af, buf, i) != i) wrerr(); } if(tf1nam) { lseek(tf1, 0L, 0); while((i = read(tf1, buf, 512)) > 0) if (write(af, buf, i) != i) wrerr(); } } /* * insert the file 'file' * into the temporary file */ movefil(f) { register char *cp; register i; cp = trim(file); for(i=0; i<14; i++) if(arbuf.ar_name[i] = *cp) cp++; arbuf.ar_size = stbuf.st_size; arbuf.ar_date = stbuf.st_mtime; arbuf.ar_uid = stbuf.st_uid; arbuf.ar_gid = stbuf fprintf(stderr, "ar: cannot create temp file\n"); done(2); } mbuf = ARMAGIC; if(write(tf,(char *)&mbuf,sizeof(short)) != sizeof(short)) wrerr(); mbuf = 0; if(artype == VAX11) if(write(tf,(char *)&mbuf,sizeof(short)) != sizeof(short)) wrerr(); return(0); } getaf() { short mbuf; af = open(arnam, 0); if(af < 0) return(1); getmagic(af); return(0); } getqf() { short mbuf; int sbuf; if ((qf = open(arnam, 2)) < 0) { if(!flg['c'-'a']) fprintf(stderr, "ar: creating %s\n", arnam); .st_gid; arbuf.ar_mode = stbuf.st_mode; copyfil(f, tf, OODD+HEAD); close(f); } stats() { register f; f = open(file, 0); if(f < 0) return(f); if(fstat(f, &stbuf) < 0) { close(f); return(-1); } return(f); } /* * copy next file * size given in arbuf */ copyfil(fi, fo, flag) { register i, o; int pe; if(flag & HEAD) puthead(fo); pe = 0; while(arbuf.ar_size > 0) { i = o = 512; if(arbuf.ar_size < i) { i = o = arbuf.ar_size; if(i&1) { if(flag & IODD) i++; if(flag close(creat(arnam, 0666)); if ((qf = open(arnam, 2)) < 0) { fprintf(stderr, "ar: cannot create %s\n", arnam); done(2); } sbuf = ARMAG; if (write(qf, (char *)&sbuf, sizeof(int)) != sizeof(int)) wrerr(); lseek(qf, 0L, 0); getmagic(qf); } else { getmagic(qf); } } usage() { fprintf(stderr,"usage: ar [%s][%s] archive files ...\n", man, opt); done(2); } noar() { fprintf(stderr, "ar: %s does not exist\n", arnam); done(2); } sigdone() { done(100); } done(c) { if(tfnam) unli& OODD) o++; } } if(read(fi, buf, i) != i) pe++; if((flag & SKIP) == 0) if (write(fo, buf, o) != o) wrerr(); arbuf.ar_size -= 512; } if(pe) phserr(); } getdir() { register i; i = gethead(af); if(i != sizeof arbuf) { if(tf1nam) { i = tf; tf = tf1; tf1 = i; } return(1); } for(i=0; i<14; i++) name[i] = arbuf.ar_name[i]; file = name; return(0); } gethead(fd) { register i; U.l = 1L; switch (artype) { case VAX11: if(U.c[0]) /* VAX ar on VAX */ 6); if(write(fd, (char*)&pbuf, sizeof pbuf) != sizeof pbuf) wrerr(); } else /* PDP-11 ar on PDP-11 */ if(write(fd, (char *)&arbuf, sizeof arbuf) != sizeof arbuf) wrerr(); } return(0); } match() { register i; for(i=0; i 1) printf("%c - %s\n", c, file); } char * trim(s) char *s; { register char *p1, *p2; for(p1 = s; *p1; p1++) ; while(p1 > s) {# @(#)makefile 2.2 #*************************************************************************** # * # UNIX pdp-11 Archive (ar) makefile * # * #*************************************************************************** # * # Source Code Files * # * # ar.c main program for pdp11 version of ar * # * #*****ad(fd, (char *)&pbuf, sizeof(pbuf))) != sizeof(pbuf)) return(i); for(i=0; i<14; i++) arbuf.ar_name[i] = pbuf.p_name[i]; arbuf.ar_size = (long)pbuf.p_siz1<<16 | pbuf.p_siz2; arbuf.ar_uid = pbuf.p_uid; arbuf.ar_gid = pbuf.p_gid; arbuf.ar_mode = pbuf.p_mode; arbuf.ar_date = pbuf.p_date1<<16 | pbuf.p_date2; }else /* PDP-11 ar on PDP-11 */ return(read(fd, (char *)&arbuf, sizeof(arbuf))); } return(sizeof(arbuf)); } puthead(fd) { register i; U.l = 1L; switch(artype){ cas if(*--p1 != '/') break; *p1 = 0; } p2 = s; for(p1 = s; *p1; p1++) if(*p1 == '/') p2 = p1+1; return(p2); } #define IFMT 060000 #define ISARG 01000 #define LARGE 010000 #define SUID 04000 #define SGID 02000 #define ROWN 0400 #define WOWN 0200 #define XOWN 0100 #define RGRP 040 #define WGRP 020 #define XGRP 010 #define ROTH 04 #define WOTH 02 #define XOTH 01 #define STXT 01000 longt() { register char *cp; pmode(); printf("%3d/%1d", arbuf.ar_uid, arbuf.ar_gid); printf("%7ld", arbuf.ar_sie VAX11: if(U.c[0]){ /*VAX ar on VAX */ if(write(fd, (char *)&arbuf, sizeof arbuf) != sizeof arbuf) wrerr(); } else { /* VAX ar on PDP-11 */ for(i=0; i<14; i++) vbuf.v_name[i] = arbuf.ar_name[i]; vbuf.v_siz1 = (short) (arbuf.ar_size & 0177777); vbuf.v_siz2 = (short) (arbuf.ar_size >> 16); vbuf.v_uid = arbuf.ar_uid; vbuf.v_gid = arbuf.ar_gid; vbuf.v_mode = (short) arbuf.ar_mode; vbuf.v_date1 = (short) (arbuf.ar_date & 0177777); vbuf.v_date2 = (short) (arbuf.ar_datze); cp = ctime(&arbuf.ar_date); printf(" %-12.12s %-4.4s ", cp+4, cp+20); } int m1[] = { 1, ROWN, 'r', '-' }; int m2[] = { 1, WOWN, 'w', '-' }; int m3[] = { 2, SUID, 's', XOWN, 'x', '-' }; int m4[] = { 1, RGRP, 'r', '-' }; int m5[] = { 1, WGRP, 'w', '-' }; int m6[] = { 2, SGID, 's', XGRP, 'x', '-' }; int m7[] = { 1, ROTH, 'r', '-' }; int m8[] = { 1, WOTH, 'w', '-' }; int m9[] = { 2, STXT, 't', XOTH, 'x', '-' }; int *m[] = { m1, m2, m3, m4, m5, m6, m7, m8, m9}; pmode() { register int **mp; for (mp =e >> 16); if(write(fd, (char *)&vbuf, sizeof vbuf) != sizeof vbuf) wrerr(); } break; case PDP11: if(U.c[0]) { /* PDP-11 ar on VAX */ for(i=0; i<14; i++) pbuf.p_name[i] = arbuf.ar_name[i]; pbuf.p_siz2 = (short) (arbuf.ar_size & 0177777); pbuf.p_siz1 = (short) (arbuf.ar_size >> 16); pbuf.p_uid = arbuf.ar_uid; pbuf.p_gid = arbuf.ar_gid; pbuf.p_mode = (short) arbuf.ar_mode; pbuf.p_date2 = (short) (arbuf.ar_date & 0177777); pbuf.p_date1 = (short) (arbuf.ar_date >> 1 &m[0]; mp < &m[9];) select(*mp++); } select(pairp) int *pairp; { register int n, *ap; ap = pairp; n = *ap++; while (--n>=0 && (arbuf.ar_mode&*ap++)==0) ap++; putchar(*ap); } wrerr() { perror("ar write error"); done(2); } = { 1, WGRP, 'w', '-' }; int m6[] = { 2, SGID, 's', XGRP, 'x', '-' }; int m7[] = { 1, ROTH, 'r', '-' }; int m8[] = { 1, WOTH, 'w', '-' }; int m9[] = { 2, STXT, 't', XOTH, 'x', '-' }; int *m[] = { m1, m2, m3, m4, m5, m6, m7, m8, m9}; pmode() { register int **mp; for (mp =# @(#)ar.mk 2.4 # ar.mk ar makefile INSDIR = /bin CURDIR = .. ar: -if vax; \ then \ cd vax; \ $(MAKE) INSDIR=$(CURDIR); \ elif pdp11; \ then \ cd pdp11; \ $(MAKE) INSDIR=$(CURDIR); \ elif u3b; \ then \ cd u3b; \ $(MAKE) INSDIR=$(CURDIR); \ else \ echo 'Cannot make ar command: unknown target procesor.'; \ fi clean: -if vax; \ then \ cd vax; \ $(MAKE) clean; \ elif pdp11; \ then \ cd pdp11; \ $(MAKE) clean; \ elif u3b; \ then \ cd u3b; \ $(MAKE) clean; \ fi ins___ |__________ARCHIVE_HEADER_DATA________________| | | | Archive Header "ar_hdr" | |.............................................| | | | Symbol Directory "ar_sym" | | | |_____________________________________________| |________ARCHIVE_FILE_MEMBER_1________________| | | | Archive File Header "arf_hdr" | |.............................................| | | | Member Contents (either a.out.h | | format or text file) | |_tall: ar cp ar $(INSDIR)/ar clobber: clean -rm -f ar IR = .. ar: -if vax; \ then \ cd vax; \ $(MAKE) INSDIR=$(CURDIR); \ elif pdp11; \ then \ cd pdp11; \ $(MAKE) INSDIR=$(CURDIR); \ elif u3b; \ then \ cd u3b; \ $(MAKE) INSDIR=$(CURDIR); \ else \ echo 'Cannot make ar command: unknown target procesor.'; \ fi clean: -if vax; \ then \ cd vax; \ $(MAKE) clean; \ elif pdp11; \ then \ cd pdp11; \ $(MAKE) clean; \ elif u3b; \ then \ cd u3b; \ $(MAKE) clean; \ fi ins____________________________________________| | | | . . . | | . . . | | . . . | |_____________________________________________| |________ARCHIVE_FILE_MEMBER_n________________| | | | Archive File Header "arf_hdr" | |.............................................| | | | Member Contents (either a.out.h | | format or text file) | |_____________________________________________| */ #define ARMAG "" #define SARMAG 4 str./usr/src/cmd/arcv.c 664 2 2 25314 3172123720 7434 uct ar_hdr { /* archive header */ char ar_magic[SARMAG]; /* magic number */ char ar_name[16]; /* archive name */ char ar_date[4]; /* date of last archive modification */ char ar_syms[4]; /* number of ar_sym entries */ }; struct ar_sym { /* archive symbol table entry */ char sym_name[8]; /* symbol name, recognized by ld */ char sym_ptr[4]; /* archive position of symbol */ }; struct arf_hdr { /* archive file member header */ char arf_name[16]; /* file member name */ char arf_date[4]; /*********************************************************************** LPT = dpr -mx INSDIR = . CFILES = ar.c CFLAGS = -O -s -i all: ar ar: $(CFILES) $(CC) $(CFLAGS) ar.c -o ar cp ar $(INSDIR)/ar listing: pr -n makefile $(CFILES) | $(LPT) @echo "files sent to lineprinter" clean: -rm -f ar ar.o # * # Source Code Files * # * # ar.c main program for pdp11 version of ar * # * #*****/* @(#)arcv.c 2.1 */ #include #include abort(); /* interrupt handler, defined below */ char *tempnam();/* C library routine for creating temp file name */ long time(); /* C library routine which gives you the time of day */ long genarc(); /* routine for converting archives and their member files. the routine returns the number of bytes in the converted file. the converted file is assumed to be in tmpfil. a returned value of 0 implies that something has gotten s./usr/src/cmd/ar/ar.mk 664 2 2 1070 3172123722 7645 crewed up */ long gencpy(); /* routine for copying a file which does not (or can not) need to be converted. the tmpfil file is made a copy of the infil input file. */ /* input/output/temporary files */ char *infilname, *outfilname, *tmpfilname, *nm_newarc, *nm_member; FILE *infil, *outfil, *tmpfil, *newarc, *member; char buffer[BUFSIZ]; /* file copy buffer */ /* archive file header format */ /* COMMON ARCHIVE FORMAT ARCHIVE File Organization: ____________________________________________Processor Requirements Specification", R.M. Klein, Memorandum for File Case 12143-116, October 7, 1981. */ main ( argc, argv ) int argc; char * argv[]; { unsigned int in_magic; /* magic number of input file */ long bytes_out; int bytes_in; /* trap for interrupts */ if ((signal(SIGINT, SIG_IGN)) == SIG_DFL) signal(SIGINT, abort); if ((signal(SIGHUP, SIG_IGN)) == SIG_DFL) signal(SIGHUP, abort); if ((signal(SIGQUIT, SIG_IGN)) == SIG_DFL) signal(SIGQUIT, abort); if ((me,outfilname)) unlink(outfilname); unlink(nm_newarc); unlink(nm_member); exit(1); /* bug out! */ } readerr(filname) /* input read error, give the user a reason and bug out */ char *filname; { fprintf(stderr,"arcv: input error on file %s ",filname); perror(" "); abort(); } writerr(filname) /* output write error, give the user a reason and bug out */ char *filname; { fprintf(stderr,"arcv: output error on file %s ",filname); perror(" "); abort(); } long genarc (arcfile) /* procedure tosignal(SIGTERM, SIG_IGN)) == SIG_DFL) signal(SIGTERM, abort); if (argc != 3) { /* usage is 'arcv inargument outargument' */ fprintf(stderr,"usage: arcv infile outfile\n"); exit(1); } infilname = argv[1]; /* get input file name from command line */ outfilname = argv[2];/* get output file name from command line*/ if ((infil = fopen(infilname,"r")) == NULL) /* can't get the input file */ readerr(infilname); tmpfilname = tempnam("","arcv"); if ((tmpfil = fopen(tmpfilname,"w")) == NULL) convert a pdp11 archive into a 5.0+ archive format. the converted file is written onto the temp file tmpfil. the genarc function returns the number of bytes in the arcved file tmpfil. */ FILE *arcfile; { long arc_size; /* size of arcved archive file on output */ int mem_size; /* size of an archive member file */ short incr; struct ar_hdr new_header; struct oar_hdr oldf_header; struct arf_hdr newf_header; /* set up temporary files */ nm_newarc = tempnam("","arcv"); nm_me/* can't write onto the temporary file */ writerr(tmpfilname); /* let's get down to business: are we dealing with an archive or some other kind of file? answer: look at the 'magic number' */ if (fread(&in_magic,1,sizeof(in_magic),infil) != sizeof(in_magic)) readerr(infilname); in_magic &= 0177777; fseek(infil,0L,0); switch (in_magic) { case OARMAG: /* archive input */ bytes_out = genarc(infil); break; default: /* questionable input */ bytes_out = gencpy(infil, infilname)mber = tempnam("","arcv"); if ((newarc = fopen(nm_newarc,"w")) == NULL) writerr(nm_newarc); /* skip past the magic number in the input file: arcfile */ fseek(arcfile,(long)sizeof(int),0); /* set up the new archive header */ strncpy(new_header.ar_magic,ARMAG,SARMAG); strncpy(new_header.ar_name,infilname,sizeof(new_header.ar_name)); sputl(time(NULL),new_header.ar_date); sputl(0L,new_header.ar_syms); /* recreate archive without symbols */ if ((arc_size = (long)fwrite(&new_header,1,sizeof(new_; fprintf(stderr,"arcv: warning, contents of file %s not modified\n", infilname); break; }; /* copy converted output, which resides in the tmpfil file to the outfil file */ fclose(infil); if ((outfil = fopen(outfilname,"w")) == NULL) /* can't write onto the output file */ writerr(outfilname); /* always begin at the beginning */ fclose(tmpfil); if ((tmpfil = fopen(tmpfilname,"r")) == NULL) /* can't read the temporary file */ readerr(tmpfilname); while (bytes_out) { byteheader),newarc)) != sizeof(new_header)) writerr(nm_newarc); /* now process each archive member in turn */ while (fread(&oldf_header,1,sizeof(oldf_header),arcfile) == sizeof(oldf_header)) { /* if the member has a name of "__.SYMDEF" then we can delete it from the new archive. this special member was used with earlier versions of random access libraries. it has no application or use in the new archive format. */ if (strcmp(oldf_header.ar_name,"__.SYMDEF") == 0) { fs file member date */ char arf_uid[4]; /* file member user identification */ char arf_gid[4]; /* file member group identification */ char arf_mode[4]; /* file member mode */ char arf_size[4]; /* file member size */ }; /* old pdp11 format */ #define OARMAG 0177545 struct oar_hdr { char ar_name[14]; long ar_date; char ar_uid; char ar_gid; int ar_mode; long ar_size; }; /* main program for arcv usage is 'arcv infile outfile' Reference: "UNIX 5.0 Machine Language Processors: VAX and 3B s_in = fread(buffer,1,BUFSIZ,tmpfil); bytes_out -= (long)fwrite(buffer,1,bytes_in,outfil); }; /* we are all done, so clean up! */ fclose(outfil); fclose(tmpfil); unlink(tmpfilname); exit(0); } /* interrupt handler: delete all the temp files, unlink the output and then bug out with an error code of 1 */ abort () { fclose(infil); /* close all files */ fclose(outfil); fclose(tmpfil); fclose(newarc); fclose(member); unlink(tmpfilname); /* delete temp file and output */ if (strcmp(infilnaeek(arcfile,oldf_header.ar_size,1); /* skip */ continue; /* and go on to the next archive member */ }; /* translate header data for each member */ strncpy(newf_header.arf_name,oldf_header.ar_name, sizeof(oldf_header.ar_name)); sputl(oldf_header.ar_date,newf_header.arf_date); sputl((long)oldf_header.ar_uid,newf_header.arf_uid); sputl((long)oldf_header.ar_gid,newf_header.arf_gid); sputl((long)oldf_header.ar_mode,newf_header.arf_mode); /* prepare the member for conversion */ if ((ize = 0; fclose(tmpfil); /* start with a clean file */ if ((tmpfil = fopen(tmpfilname,"w")) == NULL) writerr(tmpfilname); while (bytes_in = fread(buffer,1,BUFSIZ,cpyfile)) { fwrite(buffer,1,bytes_in,tmpfil); cpy_size = cpy_size + bytes_in; } return(cpy_size); } /* * The intent here is to provide a means to make the value of * bytes in an io-stream correspond to the value of the long * in the memory while doing the io a `long' at a time. * Files written and read in this way are machine-imember = fopen(nm_member,"w")) == NULL) writerr(nm_member); mem_size = oldf_header.ar_size; if (mem_size & 1) { /* ar expects members to be evenly sized */ mem_size++; incr = 1; } else incr = 0; while (mem_size >= BUFSIZ) { if (fread(buffer,1,BUFSIZ,arcfile) != BUFSIZ) readerr(infilname); if (fwrite(buffer,1,BUFSIZ,member) != BUFSIZ) writerr(nm_member); mem_size -= BUFSIZ; }; if (mem_size) { if ((long)fread(buffer,1,(int)mem_size,arcfile) != mem_size) reandependent. * */ #include sputl(w, buffer) long w; register char *buffer; { register int i = BITSPERBYTE * sizeof(long); while ((i -= BITSPERBYTE) >= 0) *buffer++ = (char) (w >> i); } s_in,tmpfil); cpy_size = cpy_size + bytes_in; } return(cpy_size); } /* * The intent here is to provide a means to make the value of * bytes in an io-stream correspond to the value of the long * in the memory while doing the io a `long' at a time. * Files written and read in this way are machine-iderr(infilname); if ((long)fwrite(buffer,1,(int)mem_size,member) != mem_size) writerr(nm_member); }; /* now perform the actual conversion */ fclose(member); if ((member = fopen(nm_member,"r")) == NULL) readerr(nm_member); mem_size = gencpy(member,newf_header.arf_name); fclose(member); /* now let's put the sucker back into the new archive */ sputl((long)(mem_size-(long)incr),newf_header.arf_size); /* finish up */ if (fwrite(&newf_header,1,sizeof(newf_header),newarc) != ./usr/src/cmd/asa.c 664 2 2 7423 3172123724 7232 sizeof(newf_header)) writerr(nm_newarc); arc_size += mem_size + sizeof(newf_header); /* put the new member into the new archive */ fclose(tmpfil); if ((tmpfil = fopen(tmpfilname,"r")) == NULL) readerr(tmpfilname); while (mem_size = (long)fread(buffer,1,BUFSIZ,tmpfil)) fwrite(buffer,1,(int)mem_size,newarc); }; /* copy new archive file to tmpfil */ fclose(newarc); fclose(tmpfil); if ((newarc = fopen(nm_newarc,"r")) == NULL) readerr(nm_newarc); if ((tmpfil = fopen(tmpfilname,"w"/* @(#)asa.c 1.2 */ /* * asa - interpret asa carriage control characters * * This program is designed to make sense out of the output * of fortran programs whose authors have used asa carriage * control characters. It processes either the files * whose names are given as arguments or the standard input * if no file names are given. The first character of each * line is assumed to be a control character: the meanings * of the control characters are: * * ' ' single-space before printing * '0' do)) == NULL) writerr(tmpfilname); while (mem_size = (long)fread(buffer,1,BUFSIZ,newarc)) fwrite(buffer,1,(int)mem_size,tmpfil); /* time to clean up */ fclose(newarc); unlink(nm_newarc); fclose(member); unlink(nm_member); return(arc_size); } long gencpy(cpyfile, cpyname) /* routine for copying a file which does not need to be converted. the tmpfil file is made a copy of the infil input file. */ FILE *cpyfile; char *cpyname; { long cpy_size; int bytes_in; cpy_suble-space before printing * '1' new page before printing * '+' do not space at all before printing * * A line beginning with '+' will overprint the previous line. * * Lines beginning with other than the above characters are * treated as if they began with ' '; if any such lines appear, * an appropriate diagnostic will appear on the standard error * file before termination. The return code will be zero unless * one or more input files could not be opened. * * The program forces the first line o/* double space */ case '0': if (!firstline) putchar ('\n'); putchar ('\n'); break; /* single space and invalid characters */ default: badlines++; /* no break */ case '\n': case ' ': if (!firstline) putchar ('\n'); break; /* no space at all */ case '+': if (!firstline) putchar ('\r'); break; } firstline = false; firstout = false; if (c != '\n') firstchar = false; } else { /* not the first character of an input line./usr/src/cmd/bs/bs.c 664 2 2 130766 3172123772 7550 f each input file to * start on a new page. */ #include typedef char bool; #define true 1 #define false 0 /* program name, for diagnostics */ char *pgmname; /* count of lines with bad control characters */ long badlines = 0; /* buffer for the standard output */ char stdbuf[BUFSIZ]; /* number of errors detected */ int retcode = 0; main (c, v) int c; char **v; { setbuf (stdout, stdbuf); pgmname = v[0]; /* were any files given, or do we process stdin? */ if (c <= 1) /* process stand */ if (c == '\n') firstchar = true; else putchar (c); } } /* end the file with a newline if any output appeared */ if (!firstline) putchar ('\n'); if (ferror (stdin)) { fprintf (stderr, "%s: input error on %s\n", pgmname, fname); retcode++; } } /* no space at all */ case '+': if (!firstline) putchar ('\r'); break; } firstline = false; firstout = false; if (c != '\n') firstchar = false; } else { /* not the first character of an input lineard input */ dofile ("standard input"); else { register int i; /* one iteration per input file */ for (i = 1; i < c; i++) { if (freopen (v[i], "r", stdin) == NULL) { fprintf (stderr, "%s: cannot open %s\n", pgmname, v[i]); retcode++; } else dofile (v[i]); } } /* report invalid input lines -- dofile increments badlines */ if (badlines) fprintf (stderr, "%s: %ld invalid input line%s\n", pgmname, badlines, badlines>1? "s": ""); if (ferror (stdout)) { fprintf (std./usr/src/cmd/basename.sh 664 2 2 122 3172123742 10376 err, "%s: output error\n", pgmname); retcode++; } return retcode; } /* * dofile - process the standard input. * * This program is called once for each input file, with stdin * redirected to the file. The "fname" argument is used * for writing diagnostic messages only. */ /* true only when the first output character has not been written */ bool firstout = true; dofile (fname) char *fname; { register int c; /* true if we are about to read the first character in a line */ bool firstchar = t# @(#)basename.sh 1.3 a=`expr //${1-.} : '.*/\(.*\)'` expr $a : "\(.*\)$2$" \| $a nd the file with a newline if any output appeared */ if (!firstline) putchar ('\n'); if (ferror (stdin)) { fprintf (stderr, "%s: input error on %s\n", pgmname, fname); retcode++; } } /* no space at all */ case '+': if (!firstline) putchar ('\r'); break; } firstline = false; firstout = false; if (c != '\n') firstchar = false; } else { /* not the first character of an input linerue; /* true if we are about to write the first line for the file */ bool firstline = true; while ((c = getchar()) != EOF) { /* separate input files by formfeeds */ if (firstline && !firstout) putchar ('\f'); if (firstchar) { switch (c) { /* new page */ case '1': if (!firstline) putchar ('\f'); break; /* triple space */ /* this is not in the spec! */ /* case '-': if (!firstline) putchar ('\n'); putchar ('\n'); putchar ('\n'); break; */ ./usr/src/cmd/bs/ 40775 2 2 0 5555206543 6707 N */ /* Binary operators operate as: (S-1) op S -> --S arithmetic operators convert both operands to double. comparison operators do string compare iff both operands are strings. AND and OR treat non-null strings as true. */ #define AND 4 #define OR 5 #define EQ 6 #define NEQ 7 #define GT 8 #define LT 9 #define GEQ 10 #define LEQ 11 #define ADD 12 #define SUBT 13 #define MULT 14 #define DIV 15 #define EXPO 16 #define MOD 17 #define CAT 18 /* Unary Operators: op S -> S */ #define NOT 19 #define NEG e MSTRING 14 #define TRANSLATE 15 #define GRAPH 16 #define TABLE 17 #define ITEM 18 #define KEY 19 #define ISKEY 20 #define MKDOUBLE(x) if((x)->t!=DOUBLE)mkdouble(x) #define DBLSIZE sizeof (double) #define INTSIZE sizeof (int) #define INTBITS (INTSIZE*8-2) char *Resnames[] = { "if", "else", "elif", "fi", "goto", "exit", "q", "return", "freturn", "for", "next", "while", "dump", "trace", "onintr", "run", "clear", "break", "continue", "fun", "nuf", "compile", "execute", "stop", "include", "ibase", "obas20 #define LINE 21 /* LINE, int statement number */ #define DUMP 22 #define TRACE 23 #define ONINTR 24 /* ONINTR, int subscr in Label */ #define EXTR 25 /* Dup top of stack: S -> ++S */ /* Primaries: primary -> ++S */ #define DBLCONS 26 /* DBLCONS, 64 bits of double constant */ #define INTCONS 27 /* INTCONS, int-sized constant */ #define STRING 28 /* STRING, pointer to null-term string */ #define NAME 29 /* NAME, int subscr in N */ #define SUBSCR 30 /* SUBSCR, dimensions, subscr in N */ #define LNAME 31 /*e", "edit", 0 }; char Rescode[] = { IF, ELSE, ELIF, FI, GOTO, EXIT, EXIT, RETURN, FRETURN, FOR, NEXT, WHILE, DUMP, TRACE, ONINTR, RUN, CLEAR, BREAK, CONTINUE, FUNCDEF, NUF, COMPILE, EXECUTE, STOP, INCLUDE, IBASE, OBASE, EDIT }; char *Fnames[] = { "arg", "narg", "rand", "eval", "format", "last", "substr", "index", "trans", "size", "open", "close", "access", "ftype", "match", "mstring", "plot", "table", "item", "key", "iskey", 0 }; short Fargct[] = { /* >=0 is exact arg count, <0 is -(N+1) minimum/* @(#)bs.c 1.3 */ /* 3.0 SID # 1.3 */ /* To compile: cc -i -O atof.c bs.c string.c -lm BS is a compiler/interpreter Source is converted to reverse Polish in comp() and executed in execute(). The Polish string is stored as an array of int's (a weakness since all kinds of pointers and doubles are stored in it). `Instruction' format is given below in the #define's. Definitions: S stands for the execute stack (estack) op is any operator , separates polish syllables in the instruction string LNAME, int subscr in S relative to function */ #define FUNCCALL 32 /* FUNCCALL, int subscr in Label, int arg count */ #define FUNCDEF 33 /* FUNCDEF, int decl args, int args+local var */ #define BUILTIN 34 /* BUILTIN, builtin #, # of args */ #define LIBRTN 45 /* LIBRTN, func pointer */ #define BREAK 35 /* BREAK, pointer to pointer to next instr */ #define GOTO 36 /* GOTO, pointer to next instr */ #define JUMP 37 /* JUMP, pointer */ #define IF 38 /* IF, pointer for false */ #define EXIT 39 #define RETURN 40 Syllables may be ints(operators, short const...), character/function pointers(for jumps...), string constants, or double constants-- all int alligned. N the internal array of named variables */ #include #include #include #include #include #include #include #define DIGIT isdigit(*Lp) #define LETTER isalpha(*Lp) #define LETNUM isalnum(*Lp) #define NUMBER (isdigit(*Lp)||*Lp=='.') #define EOL (*Lp == '\n' || *Lp == '\0' ||#define FRETURN 41 #define INTSET 42 /* INTSET, expression..., INTERROGATE */ #define INTERROGATE 43 #define SELECT 44 /* SELECT, maximum -- as in ``(0,1,2)[i]'' */ /* the following do not appear in the execute() switch */ #define IBASE 46 /* IBASE, input base (o,d,x) */ #define OBASE 47 /* OBASE, output base (o,d,x) */ #define INCR 60 /* INCR/DECR change variable values */ #define DECR 58 #define FI 62 #define CONTINUE 63 /* generates a JUMP */ #define COMPILE 48 #define EXECUTE 49 #define FOR 50 #define R *Lp == '#') #define SKIP while(*Lp==' '||*Lp=='\t')++Lp #define EQL(a,b) !strncmp((a),(b),6) #define EQS(a,b) !strcmp((a),(b)) /* Table sizes */ #define NAMES 50 #define NAMEGRPS 20 #define INSTRUCTIONS 3000 #define F_STACK 50 #define E_STACK 200 #define LABELS 100 #define STRTEMPS 50 #define J_STACK 5 /* Operators & statement keywords */ #define ASG 1 /* ASG, int subscript in N */ #define LASG 2 /* LASG, int subscript of local var in S */ #define ASGSUBS 3 /* ASGSUBS, int # dimensions, int subscr in UN 51 #define WHILE 52 #define STOP 53 /* uses zero for op */ #define CLEAR 54 #define NEXT 55 #define ELSE 56 #define NUF 57 #define INCLUDE 59 #define ELIF 61 #define EDIT 64 /* Misc */ #define INPUT 80 #define OUTPUT 81 #define ALLOC 127 #define ARRAY 126 #define DOUBLE 0 /* Builtin `builtins' */ #define ARG 1 #define EVAL 2 #define FORMAT 3 #define LAST 4 #define RAND 5 #define SUBSTR 6 #define INDEX 7 #define SIZE 8 #define NARG 9 #define IO 10 #define ACCESS 11 #define FTYPE 12 #define MATCH 13 #defin_item[1]; }; struct fstack { int *fip; struct estack *estk, *estkp; char callargs, tot_var, dclargs, fname; } Fstack[F_STACK], *Fstackp = Fstack, *Ftrace = Fstack; struct label { int *l_instr; char l_name[6]; } Label[LABELS]; char Locname[10][6]; int Lnames; struct jump { int *fail; jmp_buf save; struct fstack *f_stackp; struct estack *e_stackp; } Jmp[J_STACK], *J = Jmp; struct jump Intr; jmp_buf Reset, Afterr, Remain; short State; short Cerrs = 0; short Trace = 0; short Expr = 0; int Instr[GINT, SIG_IGN) != SIG_IGN) (void)signal(SIGINT, intr); (void)signal(SIGFPE, fpe); (void)signal(SIGPIPE, sigpipe); Lnames = 0; if(Sinput) Lnum = 0; else Lnum = Savelnum, Savelnum = 0; lc = 0; (void)setjmp(Afterr); while(fgets(&Line[lc], 512-lc, Input) != NULL) { lc = strlen(Line) - 2; if(Line[lc] == '\\') { ++Cont; continue; } lc = 0; Lp = Line; if(State == COMPILE) statement(); else singstat(); } Filename = 0; if(Input != stdin) { fclose(Input); if(Sinput) { INSTRUCTIONS]; int Sinstr[256]; int *Ip = Instr; int *Oip = 0; short Namegrps = 0, LastN = 0; short LastS = 0; short Nest = 0; int Token; char *Lp; short Last_op = 0; struct estack Last; int Lnum, Savelnum; char *Filename; short Cont; FILE *Input, *Output, *Sinput; FILE *Graphout; int Gio = 0; /* Any output on plotter */ int Ibase = 10, Obase = 10; char Line[512]; char *Key; short Iskey; char *Temps[STRTEMPS]; int Ti = -1; long Time; double mkdouble(); char *to_str(), *calloc(), *malloc(), *salloc(), *subst Input = Sinput; Sinput = 0; } else { Input = stdin; State = EXECUTE; } goto again; } exit(0); } statement() { register char *lp; char tname[16]; ++Lnum; /* TEMP check for exec of this file */ if(Lnum==1 && !strncmp(Line, "bs ", 3) && !strncmp((Line+strlen(Line)-5), "exit", 4)) return; SKIP; if(EOL || *Lp == '#') return; lp = Lp; if(aname(tname)) { SKIP; if(*Lp++ == ':') (void)cklabel(tname, Ip); else Lp = lp; } if(Ip > (Instr+INSTRUCTIONS-100)) cerror("Out r(), *trans(); struct estack *execute(); double atof(); extern char *Atof; struct names *getar(), *lookup(), *nextname(); int Argc; char **Argv; struct stat Statb; extern char *Mstring[]; extern int nbra; union gen { int i; int *ip; char *cp; struct names *np; struct estack *esp; struct fstack *fp; struct htab *htbl; struct htitem *ht; }; intr() { putchar('\n'); (void)signal(SIGINT, intr); if(Intr.e_stackp) longjmp(Intr.save, 1); clearstk(Estack+E_STACK-1, Estack); fstat(fileno(stdout), &of code space"); op(LINE); push(Lnum); comp(); if(!EOL) cerror("Invalid expression"); Lnum += Cont, Cont = 0; } singstat() { register * saveip = Ip; register v; register struct estack *ep; if(!Oip) Oip = Ip; if(*Lp == '!') { ++Lp; fexec(Lp); puts("!"); return; } if(*Lp == '#') return; Ip = Sinstr; Nest = 0; *Ip = 0; v = comp(); if(!EOL) cerror("Invalid expression"); push(0); ep = execute(Sinstr, Estack); if(v && Last_op!=ASG && Last_op!=ASGSUBS && *to_str(ep)) fputs(to args */ 1, 0, 0, 1, 2, 0, 3, 2, 3, 1, 3, 1, 2, 1, 2, 1, -2, 2, 2, 0, 2 }; double intpow(); char Fcode[] = { ARG, NARG, RAND, EVAL, FORMAT, LAST, SUBSTR, INDEX, TRANSLATE, SIZE, IO, IO, ACCESS, FTYPE, MATCH, MSTRING, GRAPH, TABLE, ITEM, KEY, ISKEY }; char *Libnames[] = { "atan", "ceil", "cos", "exp", "abs", "floor", "log", "sin", "sqrt", 0 }; double (*Libcode[])() = { atan, ceil, cos, exp, fabs, floor, log, sin, sqrt }; union value { double d; char *sp; struct { FILE *file; char ffunc, f_oStatb); if((Statb.st_mode & S_IFMT) == S_IFIFO) exit(2); fstat(fileno(stdin), &Statb); if((Statb.st_mode & S_IFMT) == S_IFIFO) exit(2); fprintf(stderr, "\nready\n"); fclose(Input), fclose(stdin); Input = fopen("/dev/tty", "r"); setbuf(Input, NULL); if(Sinput) fclose(Sinput), Sinput = 0; setup(); } setup() { LastS = Lnum; State = EXECUTE; Ftrace = Fstackp; Fstackp = Fstack; longjmp(Reset, 1); } fpe() { error("Floating exception"); } sigpipe() { error(Gio ? "Bad graph output" : "Pipe clr_p; } io; char ch[DBLSIZE]; int intg[DBLSIZE/INTSIZE]; struct { struct names *head, *lastref; } ar_hdr; int *htabl; /* really a `struct htab' */ }; struct names { union value v; char t, set; union { char sname[6]; struct { int subscr; /* stored as a complement */ struct names *next; } ar; } u; } *Np[NAMEGRPS]; struct estack { union value v; char t, set; } Estack[E_STACK]; struct htitem { char *ht_key; struct estack ht_v; }; struct htab { short ht_size; struct htitem htosed"); } main(argc, argv) char **argv; { register lc; (void)setjmp(Remain); Ip = Instr; Argc = argc; Argv = argv; time(&Time); srand((unsigned)Time); Output = stdout; if(argc > 1) { Input = fopen(argv[1], "r"); if(Input == NULL) { fprintf(stderr, "Cannot open %s\n", argv[1]); exit(1); } State = COMPILE; } else Input = stdin, State = EXECUTE; again: (void)setjmp(Reset); io(3, "get", 0.0, "\0", "r"); io(3, "put", 1.0, "\0", "w"); io(3, "puterr", 2.0, "\0", "w"); if(signal(SIvelp; static *savefun; static struct { int tp, *loc; } s[20]; register i; register union gen save1, save2, save3; char tname[20]; savelp = Lp; save2.ip = 0; if(!aname(tname)) { return expr(0); } if((ns = ckname(tname, Resnames)) == -1) { Lp = savelp; return expr(0); } switch(Rescode[ns]) { case IF: elseif: s[Nest].tp = IF; elif: expr(1); op(IF); s[Nest++].loc = Ip++; SKIP; if(!EOL) { comp(); *(s[--Nest].loc) = (int)Ip; } break; case ELSE: case ELIF: if(s[--Nest] s[Nest].tp = FOR; /* loc for jump from `next' */ s[Nest++].loc = Ip; Lp = save1.cp; /* re-parse left side of 1st expr for incr */ e9(1); Lp = save3.cp; op(INCR); *save2.ip = (int)Ip; /* fill in jump around init */ save3.cp = Lp; /* re-do init */ Lp = save1.cp; e9(1); Lp = save3.cp; expr(1); op(LEQ); } forop: op(IF); s[Nest].loc = Ip++; /* setup for jump out of loop */ s[Nest++].tp = NEXT; SKIP; if(!EOL) { comp(); goto next; } break; case NEXT: Ip .tp != IF && s[Nest].tp != ELIF) cerror("Else: no if"); save1.ip = s[Nest].loc; op(JUMP); s[Nest].tp = Rescode[ns]; s[Nest++].loc = Ip++; *save1.ip = (int)Ip; if(Rescode[ns] == ELIF) { s[Nest].tp = ELIF; goto elif; } SKIP; if(*Lp == 'i' && *(Lp+1) == 'f') { Lp += 2; goto elseif; } break; case FI: Ip -= 2; /* get rid of LINE */ fifi: if(s[--Nest].tp != IF && s[Nest].tp != ELSE && s[Nest].tp != ELIF) cerror("Fi: no if"); *(s[Nest].loc) = (int)Ip; if((s[Nest].tp-= 2; /* get rid of LINE */ next: if(s[--Nest].tp != NEXT) cerror("Next: no for"); save1.ip = s[Nest].loc; op(JUMP); /* jump back to incr & test */ *Ip++ = (int)s[--Nest].loc; *save1.ip = (int)Ip; /* fill in jump out of loop */ break; case BREAK: for(i = Nest-1; i>=0; --i) if(s[i].tp == NEXT) { op(BREAK); *Ip++ = (int)s[i].loc; break; } if(i < 0) brkerr: cerror("No for"); break; case CONTINUE: for(i = Nest-1; i>=0; --i) if(s[i].tp == FOR) { op(JUMP); * == ELIF || s[Nest-1].tp == ELIF) && (s[Nest-1].tp == IF || s[Nest-1].tp == ELIF)) goto fifi; SKIP; if(*Lp == 'f' && *(Lp+1) == 'i') { Lp += 2; goto fifi; } break; case GOTO: if(aname(tname)) { op(GOTO); push(cklabel(tname, (int *)0)); break; } else cerror("?"); case EDIT: sprintf(tname, "ed %s", Argv[1]); fexec(tname); longjmp(Remain, 1); case IBASE: case OBASE: SKIP; i = atof(Lp); Lp = Atof; if(i != 10 && i!= 8 && i != 16) cerror("ibase/obase must beIp++ = (int)s[i].loc; break; } if(i < 0) goto brkerr; break; case FUNCDEF: if(!aname(tname)) funerr: cerror("Func def."); (void)cklabel(tname, Ip); op(FUNCDEF); savefun = Ip++; save1.ip = Ip; Ip += 2; SKIP; i = Lnames = 0; if(!*Lp++ == '(') goto funerr; while(aname(tname)) { strncpy(Locname[Lnames++], tname, 6); ++i; SKIP; if(*Lp == ',') { ++Lp; continue; } else if(*Lp == ')') break; else goto funerr; } ++Lp; while(!EOL) { if(aname(tname)) { 8, 10, or 16"); if(Rescode[ns] == IBASE) Ibase = i; else Obase = i; break; case EXIT: case RETURN: case TRACE: if(!expr(0)) op(INTCONS), push(0); op(Rescode[ns]); break; case FRETURN: op(FRETURN); break; case WHILE: s[Nest].tp = FOR; s[Nest++].loc = Ip; expr(0); goto forop; case FOR: /* 1st expr */ save1.cp = Lp; expr(0); if(*Lp == ',') { /* for init,test,incr */ ++Lp; op(JUMP); save2.ip = Ip++; /* for JUMP around incr */ s[Nest].tp = FOR; s[Nes strncpy(Locname[Lnames++], tname, 6); SKIP; if(*Lp ==',') ++Lp; } else goto funerr; } if(Lnames >= 10) goto funerr; *save1.ip = i; *(save1.ip+1) = Lnames; break; case NUF: op(INTCONS); push(0); op(RETURN); *savefun = (int)Ip; Lnames = 0; break; case DUMP: op(DUMP); if(aname(tname)) { savelp = salloc(sizeof tname + 2, ALLOC); strcpy(savelp, tname); push(savelp); } else push((char *)0); break; case ONINTR: i = aname(tname)? cklabel(tname, (int *)0): _str(ep), Output), putc('\n', Output), fflush(Output); Lnum = 0; if(State == EXECUTE) grio(); if(State == COMPILE && saveip >= Sinstr) Ip = Instr; else Ip = saveip; } fexec(s) char * s; { register v; static sts; if((v = fork()) == 0) { /* child */ (void)signal(SIGINT, SIG_DFL); execl("/bin/sh", "sh", "-c", s, 0); exit(0); } else if(v == -1) { cerror("Cannot fork"); } else { (void)signal(SIGINT, SIG_IGN); wait(&sts); (void)signal(SIGINT, intr); } } comp() { int ns; char *sat++].loc = Ip; save3.cp = Lp; /* to rescan test */ save1.ip = Ip; expr(0); /* throw away to get incr */ Ip = save1.ip; if(*Lp != ',') goto forerr; ++Lp; expr(0); /* incr */ *save2.ip = (int)Ip; save2.cp = Lp; Lp = save3.cp; /* do test for real */ expr(0); Lp = save2.cp; } else { /* for init limit */ if(Last_op!=ASG && Last_op != LASG && Last_op!=ASGSUBS) forerr: cerror("For"); op(JUMP); /* setup jump around incr */ save2.ip = Ip++; save3.cp = Lp; ALLOC; op(ONINTR); push(i); break; case RUN: push(0); if(Cerrs) Cerrs = 0, intr(); srand((unsigned)(Time >> 16)); (void)execute(Instr, Estack); if(Graphout) { pclose(Graphout); Graphout = 0; } setup(); case STOP: op(0); break; case CLEAR: clear(); setup(); case INCLUDE: Savelnum = Lnum; if(Sinput) cerror("Nested `include's"); if(Input != stdin) Sinput = Input; Ip = Sinstr; case COMPILE: State = COMPILE; Lnum = 1; if(expr(0)) { save1.cp = t ++Lp; e5(1); op(SUBT); } else break; } } e5(a) { e6(a); for(; Token;) { if(*Lp == '*') { ++Lp; e6(1); op(MULT); } else if(*Lp == '/') { ++Lp; e6(1); op(DIV); } else if(*Lp == '%') { ++Lp; e6(1); op(MOD); } else break; } } e6(a) { e7(a); while(Token && *Lp == '^') { ++Lp; e7(1); op(EXPO); } } e7(a) { register *saveip; SKIP; if(*Lp == '?') { ++Lp; op(INTSET); saveip = Ip++; e8(1); op(INTERROGATE); *saveip = (int)Ip; return; } o_str(execute(Sinstr, Estack)); Filename = malloc((unsigned)strlen(save1.cp+1)); strcpy(Filename, save1.cp); Input = fopen(Filename, "r"); if(Input == NULL) { Input = stdin; free(Filename); Filename = 0; cerror("Cannot open file"); } *Sinstr = '\0'; if(Rescode[ns] == INCLUDE) if(Ip >= Sinstr) Ip = Instr; longjmp(Reset, 1); } if(Rescode[ns] == INCLUDE) cerror("Missing filename"); if(Ip < Instr || Ip > (Instr+INSTRUCTIONS-100)) Ip = Instr; break; case8(a); } e8(a) { register opr; SKIP; while((*Lp == '-' && *(Lp+1) != '-') || *Lp == '!') { opr = *Lp == '-'? NEG: NOT; ++Lp; e8(1); op(opr); return; } e9(a); } e9(a) { long cvbase(); register i, j; union { double db; int intg[DBLSIZE/INTSIZE]; } dbl; char *cp, *cp2; register builtin = -1; register incrflg = 0; char tname[16]; Token = 0; SKIP; if(*Lp == '#') /* comment */ *Lp = '\0'; if(EOL) if(a) goto e9err; else goto ret_false; if(*Lp == '(') { ++Lp; if((i = rlie EXECUTE: State = EXECUTE; break; } return 0; } expr(a) { register *saveip = Ip; register namei, subs; register saveop; e1(a); if(*Lp == '=') { ++Lp; namei = *(Ip - 1); if(Last_op == NAME || Last_op == LNAME) { Ip -= 2; saveop = Last_op; expr(1); op(saveop==NAME? ASG: LASG); push(namei); } else if(Last_op == SUBSCR) { subs = *(Ip - 2); Ip -= 3; expr(1); op(ASGSUBS); push(subs), push(namei); } else Lp -= 2, cerror("Name Required"); } return saveip !st(')')) > 1) { SKIP; if(*Lp++ != '[') cerror("?"); expr(1); SKIP; if(*Lp++ != ']') cerror("?"); op(SELECT); push(i); } ret: Token = 1; ret_false: SKIP; return; } if(NUMBER) { dbl.db = Ibase==10? atof(Lp): cvbase(Ibase, Lp); if(Lp != Atof) /* atof succeeded */ { Lp = Atof; if(dbl.db > -(1<': if(*Lp == '=') { ++Lp; return GEQ; } else { return GT; } case '<': if(*Lp == '=') { ++Lp; return LEQ; } else { return LT; } case '=': if(*Lp == '=') { ++Lp; return EQ; } case '!': if(*Lp == '=') { ++Lp; return NEQ; } } --Lp; return 0; } e4(a) { e5(a); for(; Token;) { if(*Lp == '+' && Lp[1] != '+') { ++Lp; e5(1); op(ADD); } else if(*Lp == '-' && Lp[1] != '-') { trlen(cp2), ALLOC); strcpy(cp, cp2); free(cp2); push((int)cp); ++Lp; goto ret; } if(*Lp=='+' && *(Lp+1)=='+') Lp += 2, incrflg = 1; else if(*Lp=='-' && *(Lp+1)=='-') Lp += 2, incrflg = -1; if(!aname(tname)) { if(a || incrflg) e9err: cerror("Expression"); else goto ret_false; } if(ckname(tname, Resnames) != -1) cerror("Reserved Name in Expression"); SKIP; if(*Lp == '(') { ++Lp; i = rlist(')'); if((builtin = ckname(tname, Fnames)) != -1) { j = Fargct[builtin]; if( 0; i < LABELS; ++i) { if(EQL(tname, Label[i].l_name)) { if(s && Label[i].l_instr) cerror("Dup. label"); if(s) Label[i].l_instr = s; return i; } else { if(Label[i].l_name[0]) continue; strncpy(Label[i].l_name, tname, 6); Label[i].l_instr = s; return i; } } cerror("Too many labels"); } struct names *lookup(namep) register char *namep; { register i; register struct names *np; for(i = 0; i < LastN; ++i) { np = nextname(i); if(EQL(namep, np->u.sname)) return nnames || Nest) error("Open function, if, or for"); for(;;) { switch(opr = *instr++) { case 0: /* end-of-instr */ Last = *estack; return estack; case DBLCONS: ++estack; for(r.i = 0; r.i < (DBLSIZE/INTSIZE); ) estack->v.intg[r.i++] = *instr++; estack->t = DOUBLE; break; case INTCONS: ++estack; estack->v.d = *instr++; estack->t = DOUBLE; break; case STRING: ++estack; estack->v.sp = (char *)*instr++; estack->t = STRING; break; case LNAME: ++estack;(j>=0 && j!=i) || (i < -(j+1))) argerr: cerror("Arg. count"); op(BUILTIN); push(Fcode[builtin]); push(i); } else if((builtin = ckname(tname, Libnames)) != -1) { if(i != 1) goto argerr; op(LIBRTN); *Ip++ = (int)Libcode[builtin]; } else { op(FUNCCALL); push(i); push(cklabel(tname, (int *)0)); } goto ret; } i = 0; while(*Lp == '[') { ++Lp; i += rlist(']'); SKIP; } if(i) { op(SUBSCR); push(i); if(local(tname) != -1) cerror("Subscript on local namep; } np = nextname(LastN++); strncpy(np->u.sname, namep, 6); np->v.d = 0; np->t = DOUBLE; np->set = 0; return np; } struct names *nextname(i) register i; { register nn; Namegrps = i / NAMES; nn = i % NAMES; if(Namegrps >= NAMEGRPS) symerr: error("Symbol table overflow"); if(!Np[Namegrps]) { Np[Namegrps] = (struct names *)malloc((unsigned)sizeof(struct names)*NAMES); if(!(int)Np[Namegrps]) goto symerr; } return &(Np[Namegrps][nn]); } rlist(delim) char delim; { register int args = 0; "); push((int)lookup(tname)); } else { if((i = local(tname)) != -1) { op(LNAME); push(i); } else { op(NAME); push((int)lookup(tname)); } } if(incrflg) op(incrflg == 1? INCR: DECR); goto ret; } op(a) register a; { Last_op = a; *Ip++ = a; *Ip = 0; } push(v) register v; { *Ip++ = v; *Ip = 0; } cerror(s) char *s; { register i ; char eline[128]; if(Expr) { Expr = 0; longjmp(J->save, 1); } if(State == COMPILE) Ip = Instr; if((Lp-Line) > 80) { Line[0] = eline[0] = '\0' for(;;) { SKIP; if(*Lp == delim) { ++Lp; return args; } expr(0); ++args; SKIP; if(*Lp == ',') { ++Lp; continue; } if(*Lp != delim) cerror("Wrong delimiter"); } } short ht_sizes[] = { 61, 113, 229, 317, 421, 521, 761, 1049 }; struct htab *htable(sz) { register i; register struct htab *rv; for(i = 0; i < 8; ++i) { if(sz < ht_sizes[i]) { rv = (struct htab *)calloc(1, sizeof (short) + ht_sizes[i] * sizeof(struct htitem)); rv->ht_size = ht_sizes[i]; return r; goto pskip; } for(i = 0; &Line[i] < Lp; ++i) eline[i] = Line[i]=='\t'? '\t': ' '; eline[i] = '\0'; pskip: if(Lnum) { if(Filename) { fprintf(stderr, "%s: ", Filename); Filename = 0; } fprintf(stderr, "Source line %d: ", Lnum); } fprintf(stderr, "%s\n%s%s^\b|\n", s, Line, eline); if(Lnum) Cerrs++, longjmp(Afterr, 1); else intr(); } aname(np) register char *np; { register i; SKIP; if(!LETTER) return 0; for(i = 1; LETNUM; ++i) if(i < 16) *np++ = *Lp++; else ++Lp; *v; } } error("Table too big"); } struct htitem *htitem(h, key) struct htab *h; register char *key; { register struct htitem *hp; register s, r, q; int first; for(s = r = 0; *key; ++s) r += *key++; key -= s; /* quadratic quotient--see CACM Feb '70, p107 */ q = r; first = r = q % h->ht_size; q = q / h->ht_size; s += q; do { hp = &(h->ht_item[r]); if(hp->ht_key == (char *)0) { if(Iskey) return (struct htitem *)0; hp->ht_key = salloc(s, ALLOC); strcpy(hp->ht_key, key); renp = '\0'; return 1; } ckname(np, table) register char *np, **table; { register i; for(i = 0; *table; ++i,++table) if(EQL(*table, np)) return i; return -1; } long cvbase(b, s) register char *s; { register n, c; register long ans = 0; while(c = *s++) { if(c >= '0' && c <= '9') n = c - '0'; else if(c >= 'a' && c <= 'f') n = c - 'a' + 10; else break; ans *= b; ans += n; } Atof = --s; return ans; } cklabel(tname, s) register char *tname; register *s; { register i; for(i =turn hp; } if(EQS(key, hp->ht_key)) return hp; r = (r + s) % h->ht_size; } while(r != first); error("Table overflow"); } struct estack *execute(instr, estackp) register *instr; struct estack *estackp; { register struct estack *estack = estackp; register union gen r; register char *s1; register ct; register char *s2; int x; double (*func)(); double dbl; char *tstr; int opr; struct estack *ep; static struct estack *sv_estack; int args; /* A bad spot for these tests, but ... */ if(Lv.d = r.i&&true(estack); estack->t = DOUBLE; break; case OR: r.i = true(estack--), estack->v.d = r.i||true(estack); estack->t = DOUBLE; break; case ADD: case MULT: case SUBT: case DIV: case EXPO: case MOD: MKDOUBLE(estack); dbl = estack->v.d; --estack; MKDOUBLE(estack); r.i = opr; estack->v.d = r.i==ADD? estack->v.d + dbl: r.i==MULT? estack->v.d * dbl: r.i==SUBT? estack->v.d - dbl: r.i==DIV? estack->v.d / dbl: r.i==MOD? fmod(estack->v.d, dblackp = J->e_stackp; estack->v.d = 0; estack->t = DOUBLE; Fstackp = J->f_stackp; instr = (int *)J->fail; --J; } else { J->f_stackp = Fstackp; J->fail = (int *)*instr++; J->e_stackp = estackp; } break; case INTERROGATE: --J; estack->v.d = 1; estack->t = DOUBLE; break; case ASGSUBS: case SUBSCR: args = *instr++; r.np = (struct names *)*instr++; estack -= (opr == SUBSCR? args-1: args); if(r.np->t == TABLE) { if(args != 1) error("Onl): /* EXPO--take care of pow() */ dbl==0? 1: dbl>0 && (double)(int)dbl==dbl? intpow(estack->v.d, (int)dbl): pow(estack->v.d, dbl); break; case CAT: estack -= *instr; for(r.i = x = 0; r.i <= *instr; ++r.i) x += strlen(to_str(estack+r.i)); s1 = s2 = salloc(x, 0); for(ct = 0; ct <= *instr; ++ct) { r.cp = to_str(estack+ct); while(*r.cp) *s1++ = *r.cp++; } ++instr; *s1 = '\0'; estack->v.sp = s2; estack->t = STRING; break; case EXTR: +y single dim. tables"); r.ht = htitem((struct htab *)r.np->v.htabl, to_str(estack)); r.esp = &(r.ht->ht_v); goto subsc; } for(ct = 0; ct < args; ++ct) { if(r.np->set == ALLOC) error("Subscript"); r.np->t = ARRAY; x = mkdouble(estack+ct); if(x < 0) error("Subscr. range"); r.np = getar(r.np, x); } subsc: if(opr == SUBSCR) goto nameck; *estack = *(estack+args); goto asgn; case SELECT: r.i = mkdouble(estack); if(r.i >= *instr || r.i < 0) r.esp = Fstackp->estk + *instr++; goto nameck; case NAME: ++estack; r.np = (struct names *)*instr++; nameck: if(r.np->t==DOUBLE || r.np->t==STRING) { if(*instr==INCR || *instr==DECR) { MKDOUBLE(r.np); r.np->v.d += *instr++==INCR? 1: -1; r.np->set = ALLOC; } nameset: estack->v = r.np->v; estack->t = r.np->t; } else if(r.np->t == INPUT) { if(fgets(Line,512,r.np->v.io.file)==NULL) { if(J != &Jmp[0]) { sv_estack = estack; longjmp(+estack; break; case NEG: estack->v.d = -mkdouble(estack); break; case NOT: estack->v.d = !true(estack); estack->t = DOUBLE; break; case LASG: r.esp = Fstackp->estk + *instr++; if(r.np->t==STRING && r.np->set==ALLOC) free(r.np->v.sp); goto asgn2; case ASG: r.np = (struct names *)*instr++; asgn: switch(r.np->t) { case DOUBLE: break; case STRING: free(r.np->v.sp); break; case OUTPUT: grio(); fputs(to_str(estack), r.np->v.io.file); J->save, 1); } estack->v.sp = "\0"; estack->t = STRING; } else { ct = strlen(Line); Line[--ct] = '\0'; estack->v.sp = salloc(ct, 0); strcpy(estack->v.sp, Line); estack->t = STRING; } } else if(r.np->t == TABLE) { goto nameset; } else { namerr: fprintf(stderr,"<%.6s>",r.np->u.sname); error(" name context"); } break; case GT: case LT: case GEQ: case LEQ: case EQ: case NEQ: if((estack--)->t==STRING && estack->t==STRING) if(r.np->v.io.ffunc != 'W') putc('\n', r.np->v.io.file); goto brk; default: goto namerr; } asgn2: r.np->t = estack->t; if(estack->t == STRING) { if(estack->v.sp==Temps[Ti]) { Temps[Ti] = 0; r.np->v.sp = estack->v.sp; } else { r.np->v.sp = salloc( strlen(estack->v.sp), ALLOC); strcpy(r.np->v.sp, estack->v.sp); } } else r.np->v.d = estack->v.d; r.np->set = ALLOC; brk: break; case ONINTR: if(setjmp(Intr.save)) { clearstk(estackr.i = strcmp(estack->v.sp, (estack+1)->v.sp); else { MKDOUBLE(estack); MKDOUBLE(estack+1); r.i = (estack->v.d==(estack+1)->v.d)? 0: estack->v.d>(estack+1)->v.d? 1: -1; } r.i = ( (opr==LEQ)? r.i<=0: (opr==EQ)? r.i==0: (opr==GT)? r.i>0: (opr==GEQ)? r.i>=0: (opr==LT)? r.i<0: r.i!=0); if(*instr == IF) { /* often follows RELs */ ++instr; goto ckif; } estack->v.d = r.i; estack->t = DOUBLE; break; case AND: r.i = true(estack--), estack->, Intr.e_stackp); estack = estackp = Intr.e_stackp; Intr.e_stackp = 0; Fstackp = Intr.f_stackp; if((instr = (int *)Intr.fail)==0) exit(1); break; } else { Intr.e_stackp = estackp; if(*instr == ALLOC) { ++instr; Intr.fail = 0; break; } Intr.f_stackp = Fstackp; if(!(Intr.fail = (int *)Label[*instr].l_instr)) error("No label"); } break; case INTSET: ++J; if(setjmp(J->save)) { clearstk(sv_estack, J->e_stackp); estack = est); printf("Return: "); Lp = salloc(128, 0); (void)fgets(Lp, 128, Input); Ip = (int *)(tstr = salloc(128, ALLOC)); comp(); (void)execute((int *)tstr, estack-1); free(tstr); goto ret; } ++instr; r.fp->dclargs = ct = *instr++; r.fp->tot_var = x = *instr++; if(r.fp->callargs > ct) error("Too many args"); estack = Fstackp->estk + ct; for(r.i = ct; r.i < x; ++r.i, ++estack, ++ep) { if(r.i < Fstackp->callargs) { continue; } estack->v.d = 0;_str(estack), to_int(estack+1))==0? 1: 0; estack->t = DOUBLE; break; case FTYPE: if(stat(to_str(estack), &Statb) == -1) { estack->v.d = 0; estack->t = DOUBLE; break; } r.i = Statb.st_mode & S_IFMT; estack->v.sp = r.i&S_IFDIR? "d": r.i&S_IFCHR? "c": r.i&S_IFIFO? "p": r.i&S_IFBLK? "b": "f"; estack->t = STRING; break; case LAST: *estack = Last; break; case SUBSTR: estack->v.sp = substr(to_str(estack), to_int(estack+1), estack->t = DOUBLE; } estack = estackp = ep; if(Trace) prtrace(Fstackp); break; case RETURN: ret: Last = *estack; if(estack->t == STRING) { Last.v.sp = salloc(strlen(estack->v.sp), 0); strcpy(Last.v.sp, estack->v.sp); } retn: clearstk(estack, Fstackp->estkp); instr = Fstackp->fip; estackp = Fstackp->estkp; estack = Fstackp->estk; *estack = Last; if(Trace) { --Trace; printf("%d: %.16s\n", (int)(Fstackp - Fstack), to_str(estack)); } to_int(estack+2)); estack->t = STRING; break; case MATCH: estack->v.d = ematch(to_str(estack), to_str(estack+1)); estack->t = DOUBLE; break; case MSTRING: r.i = to_int(estack); if(r.i<1 || r.i>10) goto argerr; estack->v.sp = r.i<=nbra? Mstring[r.i - 1]: "\0"; estack->t = STRING; break; case INDEX: estack->v.d = sindex(to_str(estack), to_str(estack+1)); estack->t = DOUBLE; break; case TRANSLATE: estack->v.sp = trans(to_str(es--Fstackp; if(Fstackp < Fstack) error("Return"); break; case FRETURN: if(J != &Jmp[0]) { sv_estack = estack; longjmp(J->save, 1); } Last.t = DOUBLE; Last.v.d = 0; goto retn; case BREAK: estack = estackp; instr = (int *)*instr; instr = (int *)*instr; break; case LIBRTN: func = (double (*)())*instr++; estack->v.d = (*func)(mkdouble(estack)); estack->t = DOUBLE; break; case BUILTIN: r.i = *instr++; args = *instr++; estack -= (args - 1); tack), to_str(estack+1), to_str(estack+2)); estack->t = STRING; break; case SIZE: estack->v.d = (double)strlen(to_str(estack)); estack->t = DOUBLE; break; case FORMAT: sprintf((tstr=salloc(64,0)), to_str(estack), *(estack+1)); estack->v.sp = tstr; estack->t = STRING; break; case GRAPH: graph(args, estack); estack->v.sp = "\0"; estack->t = STRING; break; case TABLE: r.np = lookup(to_str(estack)); x = mkdouble(estack+1); if( error("Range"); estack -= *instr; *estack = *(estack + r.i); ++instr; break; case IF: r.i = true(estack); ckif: if(r.i) ++instr; else instr = (int *)*instr; estack = estackp; break; case JUMP: case FUNCDEF: /* jump around func body */ instr = (int *)*instr; break; case GOTO: instr = (int *)Label[*instr].l_instr; if(instr == 0) error("No label"); break; case EXIT: if(Graphout) pclose(Graphout); exit(to_int(estack)); case LINE: e/* adj. stack */ switch(r.i) { case RAND: dbl = rand(); dbl /= 32768.; estack->v.d = dbl; estack->t = DOUBLE; break; case ARG: r.i = to_int(estack); if(Fstackp == Fstack) { /* main func */ if(r.i >= Argc || r.i < 0) argerr: error("Arg"); estack->v.sp = Argv[r.i]; estack->t = STRING; break; } if(r.i > Fstackp->callargs || r.i < 1) goto argerr; --r.i; *estack = *(Fstackp->estk + r.i); break; case NARG: estack->v.d = stack = estackp; if(estack > (Estack+E_STACK-15)) error("Stack over"); Lnum = *instr++; break; case FUNCCALL: ep = ++estack; r.fp = ++Fstackp; if(r.fp >= (Fstack+F_STACK-1)) --Fstackp, error("Recursion"); r.fp->estk = estack - *instr; /* less args */ r.fp->estkp = estackp; r.fp->callargs = *instr++; r.fp->fip = (instr + 1); r.fp->fname = *instr; instr = (int *)Label[*instr].l_instr; if(*instr++ != FUNCDEF) { printf("Undefined function "); prtrace(r.fpFstackp==Fstack? Argc: Fstackp->callargs; estack->t = DOUBLE; break; case IO: /* open and close */ io(args, to_str(estack), ((estack+1)->t==DOUBLE? (estack+1)->v.d: 99.9), to_str(estack+1), to_str(estack+2)); break; case EVAL: Expr = *instr == INTERROGATE; Lp = to_str(estack); Ip = (int *)(tstr = salloc(512, ALLOC)); comp(); (void)execute((int *)tstr, estack-1); free(tstr); Expr = 0; break; case ACCESS: estack->v.d = access(to r.htbl->ht_item[x].ht_key; } break; case ISKEY: if(estack->t != TABLE) goto nottab; ++Iskey; s1 = to_str(estack+1); r.htbl = (struct htab *)estack->v.htabl; x = (int)htitem(r.htbl, s1); Iskey = 0; estack->t = DOUBLE; estack->v.d = x? 1: 0; break; case KEY: estack->v.sp = Key; estack->t = STRING; break; } break; case TRACE: Trace = to_int(estack); break; case DUMP: s1 = (char *)*instr++; if(LastS) printf("Statement:ntf(stderr, " in source line %d", Lnum); fprintf(stderr, "\n"); intr(); } prtsubs(ps, np) register char *ps; register struct names *np; { register char *lc; lc = ps + strlen(ps); for(;;) { *lc = '\0'; sprintf(ps, "%s[%d]", ps, -(np->u.ar.subscr)); if(np->set == ALLOC) printf("%s=%s\n", ps, to_str(np)); else if(np->t == ARRAY) prtsubs(ps, np->v.ar_hdr.head); if(!np->u.ar.next) return; np = np->u.ar.next; } } double mkdouble(estack) register struct estack *estack; { if(estack->t = %d\n", LastS); if(Ftrace > Fstack) { printf("Function stack:\n"); for(; Ftrace > Fstack; --Ftrace) prtrace(Ftrace); } for(ct = 0; ct < LastN; ++ct) { r.np = nextname(ct); if(s1) if(!EQS(s1, r.np->u.sname)) continue; if(r.np->u.ar.subscr < 0) continue; if(r.np->t == ARRAY) { sprintf(Line, "%.6s", r.np->u.sname); prtsubs(Line, r.np->v.ar_hdr.head); continue; } if(r.np->t == TABLE) { s1 = r.np->u.sname; r.htbl = (struct ht= DOUBLE) return estack->v.d; if(estack->t==INPUT || estack->t==OUTPUT) goto conv; else if(estack->t == STRING) { register char *s = estack->v.sp, *strend; strend = strlen(s) + s; estack->v.d = Ibase==10? atof(s): cvbase(Ibase, s); if(estack->set == ALLOC) free(s); if(Atof != strend) conv: error("Conversion"); estack->t = DOUBLE; return estack->v.d; } } to_int(estack) register struct estack *estack; { return (int)(estack->t==DOUBLE? estack->v.d: mkdouble(estack)); } char *to_str(ab *)r.np->v.htabl; for(x=0; xht_size; ++x) if(*r.htbl->ht_item[x].ht_key) printf("%s[%s]=%s\n", s1, r.htbl->ht_item[x].ht_key, to_str(&(r.htbl->ht_item[x].ht_v))); continue; } if(r.np->set==ALLOC) { printf("%.6s=%s\n", r.np->u.sname, to_str(r.np)); } } break; default: error("Compiler"); } Last_op = opr; } } true(estack) register struct estack *estack; { if(estack->t == STRING) if(estack->v.sp[0]) return 1; else returestack) register struct estack *estack; { register char *s, *st; static char rv[3][42]; static which = 0; st = rv[which = which==2? 0: ++which]; if(estack->t == DOUBLE) { if(Obase == 10) sprintf(st, "%.10f", estack->v.d); else { sprintf(st, (Obase==8? "%lo": "%lx"), (long)estack->v.d); return st; } s = st + strlen(st); while(*--s != '.') if(*s == '0') { *s = '\0'; continue; } else return st; *s = '\0'; return st; } else if(estack->t==INPUT || estack->t==OUTPUn 0; else if(estack->v.d) return 1; else return 0; } struct names *getar(np, val) struct names *np; register val; { register struct names *np1, *np2; val = -val; /* subscripts are stored as complements */ if(np1 = np->v.ar_hdr.head) { /* shortcut for equal or +1 subscripts (didn't help) if((np2 = np->v.ar_hdr.lastref)->ar.subscr == val) return np2; if((np2 = np2->u.ar.next)->subscr == val) return np->v.ar_hdr.lastref = np2; */ loop: if(np1->u.ar.subscr == val) { np->v.ar_hdr.lasT) return "I/O"; else return estack->v.sp; } char *salloc(ct, t) register ct, t; { register char *rv; if(rv = malloc((unsigned)(ct+1))) { if(t != ALLOC) { /* temp */ if(!(++Ti < STRTEMPS)) Ti = 0; if(Temps[Ti]) { free(Temps[Ti]); } Temps[Ti] = rv; } return rv; } error("Out of string space"); } /*VARARGS2*/ io(args, ns, fd, flname, func) char *ns; double fd; register char *flname, *func; { FILE *fl; int i; register struct names *np; np = lookup(ns); if(np->t==INPUT |r.np->t) error("Table: allocated name"); r.np->v.htabl = (int *)htable(x); r.np->t = TABLE; break; case ITEM: if(estack->t != TABLE) nottab: error("arg not table"); r.htbl = (struct htab *)estack->v.htabl; x = mkdouble(estack+1); if(x >= r.htbl->ht_size) { if(J != &Jmp[0]) { sv_estack = estack; longjmp(J->save, 1); } else { estack->v.sp = "\0"; estack->t = STRING; } } else { *estack = r.htbl->ht_item[x].ht_v; Key =tref = np1; return np1; } if(np2 = np1->u.ar.next ) { np1 = np2; goto loop; } np2 = nextname(LastN++); np1->u.ar.next = np2; set: np2->u.ar.next = (struct names *)0; np2->u.ar.subscr = val; np2->v.d = 0.0; np2->set = 0; np2->t = DOUBLE; np->v.ar_hdr.lastref = np2; return np2; } np2 = np->v.ar_hdr.head = nextname(LastN++); goto set; } error(s) register char *s; { if(Expr) { Expr = 0; longjmp(J->save, 1); } fprintf(stderr, "%s - execution error", s); if(Lnum) fpri| np->t==OUTPUT) { fl = np->v.io.file; if(fl!=stdin && fl!=stdout && fl!=stderr) fclose(fl); if(np->v.io.f_or_p == '!') wait(&i); np->v.d = np->set = 0; np->t = DOUBLE; } if(args == 1) return; switch(np->v.io.ffunc = *func) { case 'r': if(*flname == '!') np->v.io.file = popen(&flname[1], func); else if (fd == 0) np->v.io.file = stdin, *flname = 0; else np->v.io.file = fopen(flname, func); if(np->v.io.file == NULL) accerr: error("Cannot access file"); np->t = INPUT;ment. */ struct gr { char nargs; char code; } gr[] = { 2, 0, /* Open plotter */ 1, 'e', /* Erase */ 2, 't', /* Label */ 5, 'l', /* Line */ 4, 'c', /* Circle */ 7, 'a', /* Arc */ 6, 0, /* Dot - not implemented */ 3, 'm', /* Move */ 3, 'n', /* Cont */ 3, 'p', /* Point */ 2, 'f', /* Linemod */ 5, 's', /* Space */ 5, 0, /* Scale and shift */ }; #define NGRAPH 14 double xscale = 1.0; double yscale = 1.0; double xshift = 0.0; double yshift = 0.0; char *Plot = "tplot -TXXXXXXXXXXX"; graph(args break; case 'W': /* no CR */ *func = 'w'; case 'w': case 'a': if(fd == 1) np->v.io.file = stdout, *flname = 0; else if(fd == 2) np->v.io.file = stderr, *flname = 0; else if(*flname == '!') np->v.io.file = popen(&flname[1], func); else np->v.io.file = fopen(flname, func); if(np->v.io.file == NULL) goto accerr; np->t = OUTPUT; break; default: error("Last arg to open() must be r, w, or a"); } np->v.io.f_or_p = *flname; np->set = ALLOC; } clear() { register i, j; reg, estack) register struct estack *estack; { register fcn; register char *stp; fcn = to_int(estack); if(fcn >= NGRAPH || fcn < 0) error("Illegal graph function"); if(args != gr[fcn].nargs) error("graph: arg count"); if(fcn && Graphout==0) error("Graphic output never specified"); estack++; Gio++; if(fcn == 0) { /* pipe output through plot(I) */ Plot[7] = '\0'; if(strlen(stp = to_str(estack)) > 10) error("graph: Bad dest."); strcat(Plot, stp); grio(); return; } if(gr[fcn].codeister struct names *np; Fstackp = Fstack; for(i = 0; i < LABELS; ++i) { Label[i].l_instr = 0; for(j = 0; j < 6; ++j) Label[i].l_name[j] = '\0'; } for(i = 0; i < LastN; ++i) { np = nextname(i); if(np->t==INPUT || np->t==OUTPUT) { io(1, np->u.sname); } else if(np->t == STRING) free(np->v.sp); np->v.d = 0; np->t = DOUBLE; np->u.sname[0] = '\0'; } Instr[0] = '\0'; Ip = Instr; Trace = Namegrps = LastN = Lnum = 0; } local(tname) register char *tname; { register i; for(i = 0; i) putgr(fcn, estack); else switch(fcn) { case 6: /* Dot */ error("Dot not implemented"); return; case 12: /* Scale*/ xscale = mkdouble(estack++); yscale = mkdouble(estack++); xshift = mkdouble(estack++); yshift = mkdouble(estack); return; } } putgr(n, estack) register struct estack *estack; { register narg, i; double loc; narg = gr[n].nargs; putc(gr[n].code, Graphout); if(narg == 2) { fputs(to_str(estack), Graphout); putc('\n', Graphout); return; } for(i = < Lnames; ++i) { if(EQL(tname, Locname[i])) return i; } return -1; } prtrace(fs) register struct fstack *fs; { register struct estack *estack; register i; printf("%d: ", (int)(fs - Fstack)); printf("%.6s(", Label[fs->fname].l_name); estack = fs->estk; for(i = 0; i < fs->callargs; ++i) { if(i) fputs(", ", stdout); printf("%.20s", to_str(estack+i)); } fputs(") ", stdout); for(i = fs->dclargs; i < fs->tot_var; ++i) { if(i > fs->dclargs) fputs(", ", stdout); printf("%.20s", to_st0, narg -= 2; i <= narg; i++) { loc = mkdouble(estack++); if(i & 01) putwd((int)(loc * xscale + xshift)); else if(i == narg) putwd((int)(loc * xscale)); else putwd((int)(loc * yscale + yshift)); } } grio() { if(!Gio) return; if(Graphout) pclose(Graphout); Graphout = popen(Plot, "w"); if(Graphout == NULL) error("No plot!"); Gio = 0; } putwd(a) { union { struct { char lo, hi; } chs; int wd; } w; w.wd = a; putc(w.chs.lo, Graphout); putc(w.chs.hi, Graphout); } for(i = r(estack+i)); } fputs("\n", stdout); } double intpow(a, b) register double a; register int b; { register double t = a; while(--b > 0) t *= a; return t; } clearstk(top, bottom) register struct estack *top, *bottom; { while(bottom <= top) { if(bottom->set == ALLOC) { if(bottom->t == STRING) free(bottom->v.sp); bottom->set = 0; } ++bottom; } } /* * Graphic function table - argcount is number of * args in the user program. Arg count of 2 * (label, linemod) have only a string argu./usr/src/cmd/bs/bs.mk 664 2 2 646 3172123772 7646 ; } /* * The following computation is done in two stages, * first accumulating powers of 5, then jamming powers of 2, * to avoid underflow in situations like the following (for * the DEC representation): 1.2345678901234567890e-37, * where exp would be about (-37 + -18) = -55, and the * value 10^(-55) can't be represented, but 5^(-55) can * be represented, and then 2^(-55) jammed via ldexp(). */ flexp = 1; exp5 = 5; bexp = exp; while(1) { if(exp&01) flexp *= exp5; exp >>= 1; i387420489^(1/3))!=729 put="pow" if 0.29552!=format("%.6f", sin(.3)) put="sin" if 15/32!=.46875 put="fraction" if .955336!=format("%.6f", cos(.3)) put="cos" if (1/5+1/5+1/5+1/5+1/5)!=1 put="fractions" if 2.718282!=format("%.6f", exp(1)) put="exp" # Test string functions: a="123" b=123 if a!=b put = a_"!="_b if size(a) != size(b) put = "size "_size(a)_"!="_size(b) c="Now is the time for all good men to come to the aid of the party." if index(c, "cmn")==0 put = "index fail" if substr(c, index(c,"p"), 25)!= "p# @(#)bs.mk 1.2 TESTDIR = . FRC = INS = /etc/install -n /bin INSDIR = CFLAGS = -O FFLAG = OFILES = atof.o bs.o string.o IFLAG = -i all: bs bs: $(OFILES) $(CC) $(LDFLAGS) $(FFLAG) -s $(IFLAG) -o $(TESTDIR)/bs $(OFILES) -lm atof.o: atof.c $(FRC) bs.o: bs.c $(FRC) string.o: string.c $(FRC) test: bs testall install: all $(INS) $(TESTDIR)/bs $(INSDIR) clean: -rm -f *.o clobber: clean -rm -f $(TESTDIR)/bs FRC: t wd; } w; w.wd = a; putc(w.chs.lo, Graphout); putc(w.chs.hi, Graphout); } for(i = f(exp == 0) break; exp5 *= exp5; } if(negexp < 0) fl /= flexp; else fl *= flexp; fl = ldexp(fl, negexp*bexp); if(neg < 0) fl = -fl; Atof = p - 1; /* ADDED for bs only */ return(fl); } esentation): 1.2345678901234567890e-37, * where exp would be about (-37 + -18) = -55, and the * value 10^(-55) can't be represented, but 5^(-55) can * be represented, and then 2^(-55) jammed via ldexp(). */ flexp = 1; exp5 = 5; bexp = exp; while(1) { if(exp&01) flexp *= exp5; exp >>= 1; i./usr/src/cmd/bs/atof.c 664 2 2 3312 3172123767 10023 ./usr/src/cmd/bs/testall 664 2 2 4763 3172123773 10331 /* @(#)atof.c 1.3 */ /* @(#)atof.c 1.3 */ /* 3.0 SID # 1.2 */ /*LINTLIBRARY*/ /* * C library - ascii to floating */ #include #include extern double ldexp(); char *Atof; /* ADDED for bs only */ double atof(p) register char *p; { register int c, eexp, exp, neg, negexp, bexp; double fl, flexp, exp5; Atof = p; /* ADDED for bs only */ neg = 1; while(isspace(*p)) ++p; if(*p == '-') { ++p; neg = -1; } else if(*p == '+') ++p; exp = 0; fl = 0; while((c = *p++), isdigi# @(#)testall 1.2 # Test everything (almost) j=2 k=4 if ++j!=--k put="inc/dec" eval("goto "_arg(1)) fun func(a)b for b=1,b4) != 1 put="comp" if (222==222) != 1 put="comp" if (3!=2) != 1 put="comp" a=5 if !(0<=a<=9) put = "comp extr" if -(-1) != 1 put="neg" if !0 != 1 put="not" # Test builtin functions if 1!=format("%.6f", floor(1.99999999)) put="int" if 25!=sqrt(625) put="sqrt" if narg()!=2 put="narg" if "c"!=ftype("/dev/null") put="ftype" if 1!=access("/dev/null",2) put="access" if 144!=eval("12*12") put="expr" if 123!=abs(-123) put="abs" if format("%.6f", /* @(#)string.c 1.3 */ #define ALLOC 127 #define ESIZE 256 #define PATSIZE 100 char *salloc(); sindex(p, s) char *p, *s; { register i, j; for(i = 0; p[i]; ++i) for(j = 0; s[j]; ++j) if(p[i] == s[j]) return ++i; return 0; } char *trans(s, f, t) char *s, *f, *t; { char *ret; register char *tmp; register i, j; int t_len = strlen(t); ret = tmp = salloc(strlen(s), 0); for(i = 0; s[i]; i++) { for(j = 0; f[j]; ++j) { if(s[i] == f[j]) { if(j < t_len) *tmp++ = t[j]; goto brk;/* ** Concatenate files. */ static char catvers[] = "@(#)cat.c 1.4"; #include #include #include char stdbuf[BUFSIZ]; main(argc, argv) char **argv; { register FILE *fi; register int c; int fflg = 0; int silent = 0; int status = 0; int dev, ino = -1; struct stat statb; #ifdef STANDALONE if (argv[0][0] == '\0') argc = getargv ("cat", &argv, 0); #endif #ifndef STANDALONE setbuf(stdout, stdbuf); #endif for( ; argc>1 && argv[1][0]=='-'; argc--,argv++) { swit } } *tmp++ = s[i]; brk: ; } *tmp = '\0'; return ret; } char *substr(s, f, w) register char *s; register w; { register char *sc; int sz = strlen(s); char *sr; if(f <= 0 || f > sz) return "\0"; --f; w = w > (sz - f)? sz - f: w; s += f; sr = sc = salloc(w, 0); do *sc++ = *s++; while(--w); *sc = '\0'; return sr; } char *Mstring[10]; extern int nbra; #define INIT register char *sp = instring; #define GETC() (*sp++) #define PEEKC() (*sp) #define UNGETC(c) (--sp) #define RETURN(c)ch(argv[1][1]) { case 0: break; case 'u': #ifndef STANDALONE setbuf(stdout, (char *)NULL); #endif continue; case 's': silent++; continue; } break; } if(fstat(fileno(stdout), &statb) < 0) { if(!silent) fprintf(stderr, "cat: Cannot stat stdout\n"); exit(2); } statb.st_mode &= S_IFMT; if (statb.st_mode!=S_IFCHR && statb.st_mode!=S_IFBLK) { dev = statb.st_dev; ino = statb.st_ino; } if (argc < 2) { argc = 2; fflg++; } while (--argc > 0 && !ferror (stdout)) { if arty." put = "substr err" d="catcatcatcat" if d!=("cat"_"cat"_"cat"_"cat") put = "cat err" if "abc" > "defghi" put = "compare err" if (186000*5280*12/1000000000)!=("186000"*"12"*"5280"/"1000000000") put="err" if index(12345,99) put = "index conv err" if 3!= match("123", "[1-3]*") put = "match err" if 7!= match("123.123xxx", "\([1-3]*\.[1-3]*\)") put = "match err" if mstring(1) != "123.123" put = "mstring()" aaa[1]=1 aaa[2,aaa[1]]=21 if aaa[2,1]!=21 put="subscr" j=0 for i=1 4 (++j) if j!=4 put="for" ar[1,1]= return #define ERROR(c) errxx(c) extern char *loc2; ematch(s, p) char *s; register char *p; { static char expbuf[ESIZE], last[PATSIZE]; char *compile(), *salloc(); register int i, num; extern char *braslist[], *braelist[]; if(strcmp(p, last) != 0) { compile(p, expbuf, &expbuf[512], 0); strcpy(last, p); } if(advance(s, expbuf)) { for(i = nbra; i-- > 0;) { p = braslist[i]; num = braelist[i] - p; strncpy(Mstring[i] = salloc(num + 1, 0), p, num); Mstring[i][num] = '\0'; } return1 ++ar[1,1] ++ar[1,1] if ar[1,1]!=3 put="subscr incr" # test IF for i=1 3 if i==1 ++i1 if !i1 put = "if-if err" else if i==2 ++i2 if i2 i2 else put = "if2 err" fi else if i==3 ++i3 else put = "bad if" fi fi fi next if (i1+i2+i3)!=3 put="if err" for i=1 5 if i>3 continue j=i next if j!=3 put="continue" for i=1 5 if i==3 break next if i!=3 put="break" array[1,2,3,4]=1234 if trans("ABC ","ABC ","abc")!="abc" put="trans() err" put = "Ok if nothing printed" exit run for" ar[1,1]=(loc2-s); } return(0); } errxx(c) { error("RE error"); } #include er char *p; { static char expbuf[ESIZE], last[PATSIZE]; char *compile(), *salloc(); register int i, num; extern char *braslist[], *braelist[]; if(strcmp(p, last) != 0) { compile(p, expbuf, &expbuf[512], 0); strcpy(last, p); } if(advance(s, expbuf)) { for(i = nbra; i-- > 0;) { p = braslist[i]; num = braelist[i] - p; strncpy(Mstring[i] = salloc(num + 1, 0), p, num); Mstring[i][num] = '\0'; } return./usr/src/cmd/bs/string.c 664 2 2 3123 3172123772 10374 ./usr/src/cmd/cat.c 664 2 2 3770 3172123764 7242 ./usr/src/cmd/chgrp.c 664 2 2 1446 3172124066 7570 t */ char *ms; struct stat st; main(argc,argv) char **argv; { register i; register char *p; int status = 0; if (argc < 3) { fprintf(stderr, "Usage: chmod [ugoa][+-=][rwxstugo] file ...\n"); exit(255); } ms = argv[1]; newmode(0); for (i = 2; i < argc; i++) { p = argv[i]; if (stat(p, &st) < 0) { fprintf(stderr, "chmod: can't access %s\n", p); ++status; continue; } ms = argv[1]; if (chmod(p, newmode(st.st_mode)) < 0) { fprintf(stderr, "chmod: can't change %s\n", p); ++st/* @(#)chgrp.c 1.1 */ /* * chgrp gid file ... */ #include #include #include #include #include struct group *gr,*getgrnam(); struct stat stbuf; int gid; int status; main(argc, argv) char *argv[]; { register c; if(argc < 3) { fprintf(stderr,"chgrp: usage: chgrp gid file ...\n"); exit(4); } if(isnumber(argv[1])) { gid = atoi(argv[1]); } else { if((gr=getgrnam(argv[1])) == NULL) { fprintf(stderr,"chgrp: unknown group: %s\n",argv[1]); atus; continue; } } exit(status); } newmode(nm) unsigned nm; { register o, m, b; m = abs(); if (!*ms) return(m); do { m = who(); while (o = what()) { b = where(nm); switch (o) { case '+': nm |= b & m; break; case '-': nm &= ~(b & m); break; case '=': nm &= ~m; nm |= b & m; break; } } } while (*ms++ == ','); if (*--ms) { fprintf(stderr, "chmod: invalid mode\n"); exit(255); } return(nm); } abs() { register c, i; i = 0; while ((c = exit(4); } gid = gr->gr_gid; } for(c=2; c= '0' && c <= '7') i = (i << 3) + (c - '0'); ms--; return(i); } who() { register m; m = 0; for (;;) switch (*ms++) { case 'u': m |= USER; continue; case 'g': m |= GROUP; continue; case 'o': m |= OTHER; continue; case 'a': m |= ALL; continue; default: ms--; if (m == 0) m = ALL; return m; } } what() { switch (*ms) { case '+': case '-': case '=': return *ms++; } return(0); } where(om) register om; { register m; m = 0; switch (*ms) { case 'u': m ((*++argv)[0]=='-' && (*argv)[1]=='\0' || fflg) fi = stdin; else { if ((fi = fopen(*argv, "r")) == NULL) { if (!silent) fprintf(stderr, "cat: cannot open %s\n", *argv); status = 2; continue; } } if(fstat(fileno(fi), &statb) < 0) { if(!silent) fprintf(stderr, "cat: cannot stat %s\n", *argv); status = 2; continue; } if (statb.st_dev==dev && statb.st_ino==ino) { if(!silent) fprintf(stderr, "cat: input %s is output\n", fflg?"-": *argv); if (fclos./usr/src/cmd/chmod.c 664 2 2 4670 3172124066 7561 e(fi) != 0 ) fprintf(stderr, "cat: close error\n"); status = 2; continue; } while ((c = getc(fi)) != EOF) if (putchar (c) == EOF && ferror (stdout)) { if (!silent) fprintf (stderr, "cat: output error\n"); status = 2; break; } if (fi!=stdin) fflush(stdout); if (fclose(fi) != 0) fprintf(stderr, "cat: close error\n"); } fflush(stdout); if (ferror(stdout)) { if (!silent) fprintf (stderr, "cat: output error\n"); status = 2; } exit(status); } f (fclos/* @(#)chmod.c 1.1 */ /* * chmod [ugoa][+-=][rwxstugo] files * change mode of files */ #include #include #include #define USER 05700 /* user's bits */ #define GROUP 02070 /* group's bits */ #define OTHER 00007 /* other's bits */ #define ALL 01777 /* all (note absence of setuid, etc) */ #define READ 00444 /* read permit */ #define WRITE 00222 /* write permit */ #define EXEC 00111 /* exec permit */ #define SETID 06000 /* set[ug]id */ #define STICKY 01000 /* sticky bi./usr/src/cmd/chown.c 664 2 2 1451 3172124067 7600 ( arg[0]=='-' && arg[1]==0 ) file1 = stdin; else if((file1 = fopen(arg, "r")) == NULL) barg(); arg = argv[2]; if((file2 = fopen(arg, "r")) == NULL) barg(); if (argc>3) skip1 = otoi(argv[3]); if (argc>4) skip2 = otoi(argv[4]); while (skip1) { if ((c1 = getc(file1)) == EOF) { arg = argv[1]; earg(); } skip1--; } while (skip2) { if ((c2 = getc(file2)) == EOF) { arg = argv[2]; earg(); } skip2--; } while(1) { chr++; c1 = getc(file1); c2 = getc(file2); if(c1 == /* @(#)chown.c 1.1 */ /* * chown uid file ... */ #include #include #include #include #include struct passwd *pwd,*getpwnam(); struct stat stbuf; int uid; int status; main(argc, argv) char *argv[]; { register c; if(argc < 3) { fprintf(stderr, "usage: chown uid file ...\n"); exit(4); } if(isnumber(argv[1])) { uid = atoi(argv[1]); goto cho; } if((pwd=getpwnam(argv[1])) == NULL) { fprintf(stderr, "chown: unknown user id %s\n",argv[1]);c2) { if (c1 == '\n') line++; if(c1 == EOF) { if(eflg) exit(1); exit(0); } continue; } if(lflg == 0) exit(1); if(c1 == EOF) { arg = argv[1]; earg(); } if(c2 == EOF) earg(); if(lflg == 1) { printf("%s %s differ: char %ld, line %ld\n", argv[1], arg, chr, line); exit(1); } eflg = 1; printf("%6ld %3o %3o\n", chr, c1, c2); } } otoi(s) char *s; { long v; int base; v = 0; base = 10; if (*s == '0') base = 8; while(isdigit(*s)) v = v*b exit(4); } uid = pwd->pw_uid; cho: for(c=2; c> 6; goto dup; case 'g': m = (om & GROUP) >> 3; goto dup; case 'o': m = (om & OTHER); dup: m &= (READ|WRITE|EXEC); m |= (m << 3) | (m << 6); ++ms; return m; } for (;;) switch (*ms++) { case 'r': m |= READ; continue; case 'w': m |= WRITE; continue; case 'x': m |= EXEC; continue; case 's': m |= SETID; continue; case 't': m |= STICKY; continue; default: ms--; return m; } } om) register om; { register m; m = 0; switch (*ms) { case 'u': m static char sccsid[] = "@(#)cmp.c 1.3"; /* ** compare two files */ #include #include FILE *file1,*file2; char *arg; int eflg; int lflg = 1; long line = 1; long chr = 0; long skip1; long skip2; main(argc, argv) char **argv; { register c1, c2; if(argc < 3) narg(); arg = argv[1]; if(arg[0] == '-' && arg[1] == 's') { lflg--; argv++; argc--; } arg = argv[1]; if(arg[0] == '-' && arg[1] == 'l') { lflg++; argv++; argc--; } if(argc != 3) narg(); arg = argv[1]; ifstatic char sccsid[] = "@(#)crypt.c 1.1"; /* * A one-rotor machine designed along the lines of Enigma * but considerably trivialized. */ #define ECHO 010 #include #define ROTORSZ 256 #define MASK 0377 char t1[ROTORSZ]; char t2[ROTORSZ]; char t3[ROTORSZ]; char *getpass(); setup(pw) char *pw; { int ic, i, k, temp, pf[2]; unsigned random; char buf[13]; long seed; strncpy(buf, pw, 8); while (*pw) *pw++ = '\0'; buf[8] = buf[0]; buf[9] = buf[1]; pipe(pf); if (fork()==0) { close(0); /* @(#)dd.c 1.2 */ /* ** convert and copy */ #include #include #include #include #include #define LCASE 01 #define UCASE 02 #define SWAB 04 #define NERR 010 #define SYNC 020 unsigned ibs = BSIZE; unsigned obs = BSIZE; unsigned bs; unsigned cbs; unsigned ibc; unsigned obc; unsigned cbc; int fflag; int cflag; int nifr; int nipr; int nofr; int nopr; int ntrunc; int ibf; int obf; int skip; int seekn; int count; int nspace; char *string; cha close(1); dup(pf[0]); dup(pf[1]); execl("/usr/lib/makekey", "-", 0); execl("/lib/makekey", "-", 0); exit(1); } write(pf[1], buf, 10); wait((int *)NULL); if (read(pf[0], buf, 13) != 13) { fprintf(stderr, "crypt: cannot generate key\n"); exit(1); } seed = 123; for (i=0; i<13; i++) seed = seed*buf[i] + i; for(i=0;i>= 8; temp = t1[k]; t1[k] = t1[ic]; t1[ic] = temp; if(t3[k]!=0) continue; ic = (random&MASK) % k; while(t3[ic]!=0) ic = (ic+1) % k; t3[k] = ic; t3[ic] = k; } for(i=0;i=0) { i = t2[(t3[(t1[(i+n1)&MASK]+n2)&MASK]-n2)&MASK]-n1; putchar(i); n1++; if(n1==ROTORSZ) { n246, 0247,0250,0325,0056,0074,0050,0053,0174, 0046,0251,0252,0253,0254,0255,0256,0257, 0260,0261,0041,0044,0052,0051,0073,0176, 0055,0057,0262,0263,0264,0265,0266,0267, 0270,0271,0313,0054,0045,0137,0076,0077, 0272,0273,0274,0275,0276,0277,0300,0301, 0302,0140,0072,0043,0100,0047,0075,0042, 0303,0141,0142,0143,0144,0145,0146,0147, 0150,0151,0304,0305,0306,0307,0310,0311, 0312,0152,0153,0154,0155,0156,0157,0160, 0161,0162,0136,0314,0315,0316,0317,0320, 0321,0345,0163,0164,0165,0166,0167,0170, 011 = 0; n2++; if(n2==ROTORSZ) n2 = 0; } } exit(0); } emp; if(t3[k]!=0) continue; ic = (random&MASK) % k; while(t3[ic]!=0) ic = (ic+1) % k; t3[k] = ic; t3[ic] = k; } for(i=0;i=0) { i = t2[(t3[(t1[(i+n1)&MASK]+n2)&MASK]-n2)&MASK]-n1; putchar(i); n1++; if(n1==ROTORSZ) { n71,0172,0322,0323,0324,0133,0326,0327, 0330,0331,0332,0333,0334,0335,0336,0337, 0340,0341,0342,0343,0344,0135,0346,0347, 0173,0101,0102,0103,0104,0105,0106,0107, 0110,0111,0350,0351,0352,0353,0354,0355, 0175,0112,0113,0114,0115,0116,0117,0120, 0121,0122,0356,0357,0360,0361,0362,0363, 0134,0237,0123,0124,0125,0126,0127,0130, 0131,0132,0364,0365,0366,0367,0370,0371, 0060,0061,0062,0063,0064,0065,0066,0067, 0070,0071,0372,0373,0374,0375,0376,0377, }; /* This is an ASCII to EBCDIC conversion table */ ./usr/src/cmd/dd.c 664 2 2 23730 3172124130 7064 char atoe [] = { 0000,0001,0002,0003,0067,0055,0056,0057, 0026,0005,0045,0013,0014,0015,0016,0017, 0020,0021,0022,0023,0074,0075,0062,0046, 0030,0031,0077,0047,0034,0035,0036,0037, 0100,0132,0177,0173,0133,0154,0120,0175, 0115,0135,0134,0116,0153,0140,0113,0141, 0360,0361,0362,0363,0364,0365,0366,0367, 0370,0371,0172,0136,0114,0176,0156,0157, 0174,0301,0302,0303,0304,0305,0306,0307, 0310,0311,0321,0322,0323,0324,0325,0326, 0327,0330,0331,0342,0343,0344,0345,0346, 0347,0350,0351,0255,0340,0275,0232,0155, 0176,0277, 0312,0313,0314,0315,0316,0317,0332,0333, 0334,0335,0336,0337,0352,0353,0354,0355, 0356,0357,0372,0373,0374,0375,0376,0377, }; int (*signal())(); main(argc, argv) char **argv; { register char *ip; register c; int (*conv)(); int ebcdic(), ibm(), ascii(), null(), cnull(), term(); int a; conv = null; for(c=1; c='a' && c<='z') c += 'A'-'a'; if(cflag&LCASE && c>='A' && c<='Z') c += 'a'-'A'; c = atoe[c] & 0377; if(cbs == 0) { null(c); return; } if(cc == '\n') { while(cbc < cbs) { null(atoe[' ']); cbc++; } cbc = 0; return; } if(cbc == cbs) ntrunc++; cbc++; if(cbc <= cbs) null(c); } ibm(cc) { register c; c = cc; if(cflag&UCASE && c>='a' && c<='z') c += 'A'-'a'; if(cflag&LCASE && c>='tderr,"df: cannot open /etc/mnttab\n"); exit(1); } i = read(fi, M, sizeof M); close(fi); for(i /= sizeof M[0]; --i >= 0;) { if(!M[i].mt_dev[0]) /* it's been umount'ed */ continue; sprintf(dev, "/dev/%.10s", M[i].mt_dev); if(argc > j) { for(k=j;k < argc; ++k) { if(EQ(argv[k], dev, 14) || EQ(argv[k], M[i].mt_dev, 10) || EQ(argv[k], M[i].mt_filsys, 10)) { printit(dev, M[i].mt_filsys); argv[k][0] = '\0'; } } } else printit(dev, M[i].mt_filsys); } for(i = j;A' && c<='Z') c += 'a'-'A'; c = atoibm[c] & 0377; if(cbs == 0) { null(c); return; } if(cc == '\n') { while(cbc < cbs) { null(atoibm[' ']); cbc++; } cbc = 0; return; } if(cbc == cbs) ntrunc++; cbc++; if(cbc <= cbs) null(c); } term(c) { stats(); exit(c); } stats() { fprintf(stderr,"%u+%u records in\n", nifr, nipr); fprintf(stderr,"%u+%u records out\n", nofr, nopr); if(ntrunc) fprintf(stderr,"%u truncated records\n", ntrunc); } c += 'A'-'a'; if(cflag&LCASE && c>=' i < argc; ++i) { if(argv[i][0]) printit(argv[i], "\0"); } exit(0); } printit(dev, fs_name) char *dev, *fs_name; { if((fd = open(dev, 0)) < 0) { fprintf(stderr,"df: cannot open %s\n",dev); return; } if(!Flg) { Fs = &Fs_info; if(stat(dev, &S) < 0) { fprintf(stderr, "df: cannot stat %s\n", dev); return; } if((S.st_mode & S_IFMT) != S_IFBLK || ustat(S.st_rdev, Fs) < 0) { Fs = (struct ustat *)&sblock.s_tfree; } } else { Fs = (struct ustat *)&sblock.s_tfree; sync(); } if( ibc = ibs; } else nifr++; ip = ibuf; if (ibc % 2) ibuf[ibc] = 0; c = (ibc + 1) >> 1; if(cflag&SWAB && c) do { a = *ip++; ip[-1] = *ip; *ip++ = a; } while(--c); ip = ibuf; if (fflag) { obc = ibc; flsh(); ibc = 0; } continue; } c = 0; c |= *ip++; (*conv)(c); } } flsh() { register c; if(obc) { if(obc == obs) nofr++; else nopr++; c = write(obf, obuf, obc); if(c != obc) { perror("dd write error"); term(2); } o./usr/src/cmd/df.c 664 2 2 10262 3172124132 7064 bc = 0; } } match(s) char *s; { register char *cs; cs = string; while(*cs++ == *s) if(*s++ == '\0') goto true; if(*s != '\0') return(0); true: cs--; string = cs; return(1); } number() { register char *cs; register n; cs = string; n = 0; while(*cs >= '0' && *cs <= '9') n = n*10 + *cs++ - '0'; for(;;) switch(*cs++) { case 'k': n *= 1024; continue; case 'w': n *= 2; continue; case 'b': n *= BSIZE; continue; case '*': case 'x': string = cs; n *= number(); /* @(#)df.c 1.7 */ #include #include #include #include #include #include #include #include #include #include #include #define EQ(x,y,z) (strncmp(x,y,z)==0) struct mnttab M[NMOUNT]; struct stat S; struct filsys sblock; struct ustat Fs_info, *Fs; int physblks; long bsize; int bshift; int Flg, tflag; int fd; daddr_t blkno = 1; daddr_t alloc(); char nfsmes[] = " case '\0': return(n); } /* never gets here */ } cnull(cc) { register c; c = cc; if(cflag&UCASE && c>='a' && c<='z') c += 'A'-'a'; if(cflag&LCASE && c>='A' && c<='Z') c += 'a'-'A'; null(c); } null(c) { *op = c; op++; if(++obc >= obs) { flsh(); op = obuf; } } ascii(cc) { register c; c = 0; c |= etoa[0377 & cc]; if(cbs == 0) { cnull(c); return; } if(c == ' ') nspace++; else { while(nspace > 0) { null(' '); nspace--; } cnull(c); } if(++cbc >= cbs) { null(' (%-10.10s): is not a file system\n"; main(argc, argv) char **argv; { register fi, i; register char c; char dev[32]; int j, k; for(j=1;j < argc;j++) { if(argv[j][0] != '-') { break; } for(k=1;argv[j][k] != '\0';k++) { switch(c = argv[j][k]) { case 'f': Flg++; break; case 'q': break; case 't': tflag=1; break; default: fprintf(stderr,"df: illegal arg -%c\n",c); exit(1); } } } if((fi = open("/etc/mnttab", 0)) < 0) { fprintf(sock.s_fname); }else { printf("%-10s", fs_name); } printf("(%-10s): %8ld blocks %7u i-nodes\n", dev, Fs->f_tfree*physblks, Fs->f_tinode); } else { daddr_t i; i = 0; while(alloc()) i++; printf("%-10s(%-10s): %8ld blocks\n",fs_name, dev, i*physblks); } if(tflag) { printf(" total: %8ld blocks %7u i-nodes\n", sblock.s_fsize*physblks, (unsigned)((sblock.s_isize - 2)*bsize/sizeof(struct dinode))); } close(fd); } daddr_t alloc() { int i; daddr_t b; structyi, ttyo; int sigcatch(); int sigalrm(); unsigned alarm(); main(argc, argv) char **argv; { extern int sys_nerr, errno; extern char *sys_errlist[]; int pid, pid1, pid2; char *save; int i, j; int status = 0, stat; char buf2, c = '0'; int bd1flg = 0, bd2flg = 0; int exit1 = 0, exit2 = 0; int one, two, ans = 0, ans1 = 0, ans2 = 0; int arg1 = 0, opt2 = 0, arg2 = 0, optsame = 0; for (i = 3; i < MAXFDS; i++) close(i); if((ttyio = open("/dev/tty",O_RDWR )) == -1) { printf("Cannot open tty\n"); fblk buf; i = --sblock.s_nfree; if(i<0 || i>=NICFREE) { printf("bad free count, b=%ld\n", blkno); return(0); } b = sblock.s_free[i]; if(b == 0) return(0); if(b=sblock.s_fsize) { printf("bad free block (%ld)\n", b); return(0); } if(sblock.s_nfree <= 0) { bread(b, &buf, sizeof(buf)); blkno = b; sblock.s_nfree = buf.df_nfree; for(i=0; i=sblock.s_fsize) { printf("bad free block (%ld)\n", b); return(0); } if(sblock.s_nfree <= 0) { bread(b, &buf, sizeof(buf)); blkno = b; sblock.s_nfree = buf.df_nfree; for(i=0; if_tfree /= physblks; /* file system sanity test */ if(sblock.s_fsize <= sblock.s_isize || sblock.s_fsize < Fs->f_tfree || sblock.s_isize < Fs->f_tinode*sizeof(struct dinode)/bsize || (long)sblock.s_isize*bsize/sizeof(struct dinode) > 0xffffL) { /* inodes are assumed to be valid up to the largest unsigned short */ printf(nfsmes, dev); return; } if(!Flg) { if(*fs_name == '\0') { printf(" %-6.6s ", sbl /* @(#)dfsck.c 1.2 */ #include #include #include #include #include #include #define MAXFDS 20 /* max open files */ #define MAXBUF 512 /* pipe buffer size */ #define WAITIME 2 /* # of secs. to wait for death of child in loop */ char *use = "Usage: %s [-options] FileSysA [FSA...] [-[options] FSB [FSB...]]\n"; int p1fs1[2], p2fs1[2], p1fs2[2], p2fs2[2]; int fsout1, fsin1, fsout2, fsin2; int ftendi1,ftendo1,ftendi2,ftendo2; int ttyio, tt /* child */ fcntl(fsin1,F_SETFL,fcntl(fsin1,F_GETFL) & ~O_NDELAY); fcntl(fsout1,F_SETFL,fcntl(fsout1,F_GETFL) & ~O_NDELAY); chgfd(fsin1,0); chgfd(fsout1,1); close(ftendi1); close(ftendo1); for(i = 3; i < MAXFDS; i++) close(i); execvp( "/etc/fsck", argv); printf("Can't exec 'fsck' on %s\n",argv[arg1]); exit(2); case -1: /* unsuccessful fork */ printf("Couldn't fork on %s\n",argv[arg1]); exit(2); default: /* parent */ close(fsin1); close(fsout1); break; } if(!bd2flg) { g && !one) one++; if((!bd2flg && !two) && (!bd1flg && !one) && !ans) { write(ttyio,"which filesystem? answer '1' or '2'\n",36); c = buf2; ans++; } if(one) { if(buf2 == '\n' && (c == 'y' || c == 'n')) { write(ftendo1,&c,1); c = '0'; } write(ftendo1,&buf2,1); } if(two) { if(buf2 == '\n' && (c == 'y' || c == 'n')) { write(ftendo2,&c,1); c = '0'; } write(ftendo2,&buf2,1); } if(buf2 == '\n') { if (one) one = 0; if (two) argv[0] = "2fsck"; argv[opt2] = save; if ( optsame ) { for ( i = arg2; i < argc; i++ ) argv[arg1 - arg2 + i] = argv[i]; argv[arg1 - arg2 + i] = 0; } else { for ( i = opt2; i < argc; i++ ) argv[1 - opt2 + i] = argv[i]; argv[1 - opt2 + i] = 0; } switch(pid2 = fork()) { case 0: /* child */ fcntl(fsin2,F_SETFL,fcntl(fsin2,F_GETFL) & ~O_NDELAY); fcntl(fsout2,F_SETFL,fcntl(fsout2,F_GETFL) & ~O_NDELAY); chgfd(fsin2,0); chgfd(fsout2,1); close(ftendi2); close(ftendtwo = 0; ans = 0; break; } } if(exit1) pread(ftendi1); if(exit2) pread(ftendi2); if((exit1 && exit2) || (bd2flg && exit1)) { printf(">>> DFSCK DONE <<<\n"); break; } } } pread(fd) int fd; { unsigned sz; struct stat statb; char buf1[MAXBUF]; fstat(fd,&statb); if((sz = statb.st_size) > 0) { statb.st_size = 0; while(sz >= MAXBUF) { read(fd,buf1,MAXBUF); write(ttyo,buf1,MAXBUF); sz -= MAXBUF; } if(sz) { read(fd,buf1,sz); write(ttyo,buf1,sz); } }o2); for(i = 3; i > 8) & 0377) >= 0) { /* child exit */ status = 0; pid == pid1? exit1++: exit2++; } } else { printf("Unknown child fdes\n"); exit(2); } } if(pid == -1 && errno != EINTR) { if(!bd2flg && !exit2 && errno != ECHILD) { if(errno <= sys_nerr) { for(i=0; s"); exit(2); } close(1); if((ttyo = fcntl(ttyio,F_DUPFD,1)) == -1) { printf("Cannot dup tty fdes\n"); exit(2); } if((fcntl(ttyi,F_SETFL,O_NDELAY)) == -1) { printf("Couldn't set O_NDELAY on ttyi\n"); exit(2); } fcntl(ftendo1,F_SETFL,fcntl(ftendo1,F_GETFL) & ~O_NDELAY); fcntl(ftendi1,F_SETFL,fcntl(ftendi1,F_GETFL) | O_NDELAY); fcntl(ftendo2,F_SETFL,fcntl(ftendo2,F_GETFL) & ~O_NDELAY); fcntl(ftendi2,F_SETFL,fcntl(ftendi2,F_GETFL) | O_NDELAY); } -1) { printf("Cannot dup tty fdes for ttyi\n"); if(pipe(p2fs1) == -1) printf("Cannot open pipes for first fsck\n"); ftendi1 = p1fs1[0]; ftendo1 = p2fs1[1]; fsout1= p1fs1[1]; fsin1 = p2fs1[0]; if(pipe(p1fs2) == -1) printf("Cannot open pipe for second fsck\n"); if(pipe(p2fs2) == -1) printf("Cannot open pipes for second fsck\n"); ftendi2 = p1fs2[0]; ftendo2 = p2fs2[1]; fsout2 = p1fs2[1]; fsin2 = p2fs2[0]; argv[0] = "fsck"; if(!bd2flg) { argv[0] = "1fsck"; save = argv[opt2]; argv[opt2] = 0; } switch(pid1 = fork()) { case 0:ys_errlist[errno][i] != '\0'; i++); write(ttyio, sys_errlist[errno], i); write(ttyio, "\n", 1); } else perror("dfsck"); exit(2); } } pread(ftendi1); pread(ftendi2); #ifdef RT /* Correct for RT TTY package not seeing O_NDELAY */ alarm ( WAITIME ); while ((read(ttyi,&buf2,1)) > 0 ) { alarm ( 0 ); #else while(read(ttyi,&buf2,1)) { #endif if(buf2 =='1' && !one) { one++; continue; } if(buf2 == '2' && !two) { two++; continue; } if(bd2fl./usr/src/cmd/diff/ 40775 2 2 0 5555214606 7212 ./usr/src/cmd/diff/diffh.c 664 2 2 10037 3172124141 10463 ./usr/src/cmd/diff/diff.mk 664 2 2 2272 3172124140 10461 /* @(#)diffh.c 1.1 */ #include #include #include #include #define C 3 #define RANGE 30 #define LEN 255 #define INF 16384 char *text[2][RANGE]; long lineno[2] = {1, 1}; /*no. of 1st stored line in each file*/ int ntext[2]; /*number of stored lines in each*/ long n0,n1; /*scan pointer in each*/ int bflag; int debug = 0; FILE *file[2]; /* return pointer to line n of file f*/ char *getl(f,n) long n; { register char *t; char *malloc(); register delta, nt; # diff make file # SCCS: @(#)diff.mk 1.5 OL = / SL = /usr/src/cmd RDIR = $(SL)/diff INS = : REL = current CSID = -r`gsid diff $(REL)` MKSID = -r`gsid diff.mk $(REL)` LIST = lp INSDIR = $(OL)bin INSLIB = $(OL)usr/lib IFLAG = -i CFLAGS = -O LDFLAGS = -s $(IFLAG) SOURCE = diff.c diffh.c MAKE = make compile all: diff diffh : diff: $(CC) $(CFLAGS) $(LDFLAGS) -o diff diff.c $(INS) diff $(INSDIR) chmod 775 $(INSDIR)/diff @if [ "$(OL)" = "/" ]; \ then cd $(INSDIR); chown bin diff; chgrp bin diff; \ fi again: delta = n - lineno[f]; nt = ntext[f]; if(delta<0) progerr("1"); if(deltant) progerr("2"); if(nt>=RANGE) progerr("3"); if(feof(file[f])) return(NULL); t = text[f][nt]; if(t==0) { t = text[f][nt] = malloc(LEN+1); if(t==NULL) if(hardsynch()) goto again; else progerr("5"); } t = fgets(t,LEN,file[f]); if(t!=NULL) ntext[f]++; return(t); } /*remove thru line n of file f from storage*/ clrl(f,n) long n; { register i,j; j = ndiffh: $(CC) $(CFLAGS) $(LDFLAGS) -o diffh diffh.c $(INS) diffh $(INSLIB) chmod 775 $(INSLIB)/diffh @if [ "$(OL)" = "/" ]; \ then cd $(INSLIB); chown bin diffh; chgrp bin diffh; \ fi install: $(MAKE) -f diff.mk INS=cp OL=$(OL) IFLAG=$(IFLAG) build: bldmk get -p $(CSID) s.diff.src $(REWIRE) | ntar -d $(RDIR) -g bldmk: ; get -p $(MKSID) s.diff.mk > $(RDIR)/diff.mk listing: pr diff.mk $(SOURCE) | $(LIST) listmk: ; pr diff.mk | $(LIST) edit: get -e -p s.diff.src | ntar -g delta: ntar -p $(S-lineno[f]+1; for(i=0;i+j diff.src delta s.diff.src rm -f $(SOURCE) mkedit: ; get -e s.diff.mk mkdelta: ; delta s.diff.mk clean: : clobber: rm -f diff diffh delete: clobber rm -f $(SOURCE) fi install: $(MAKE) -f diff.mk INS=cp OL=$(OL) IFLAG=$(IFLAG) build: bldmk get -p $(CSID) s.diff.src $(REWIRE) | ntar -d $(RDIR) -g bldmk: ; get -p $(MKSID) s.diff.mk > $(RDIR)/diff.mk listing: pr diff.mk $(SOURCE) | $(LIST) listmk: ; pr diff.mk | $(LIST) edit: get -e -p s.diff.src | ntar -g delta: ntar -p $(S1,++n1); if(s0==NULL||s1==NULL) break; if(cmp(s0,s1)!=0) { if(!easysynch()&&!hardsynch()) progerr("5"); } else { clrl(0,n0); clrl(1,n1); } } if(s0==NULL&&s1==NULL) return; if(s0==NULL) output(-1,INF); if(s1==NULL) output(INF,-1); } /* synch on C successive matches*/ easysynch() { int i,j; register k,m; char *s0,*s1; for(i=j=1;i=0&&b>=0) printf("---\n"); for(i=0;i<=b;i++) { s = getl(1,n1+i); if(s==NULL) break; printf("> %s",s); clrl(1,n1+i); } n1 += i-1; return(1); } change(a,b,c,d,s) long a,c; char *s; { range(a,b); printf("%s",s); range(c,d); printf("\n"); } range(a,b) long a; { if(b==INF) printf("%ld,$",a); else if(b==0) printf("%ld",a); else printf("%ld,%ld",a,a+b); } cmp(s,t) char *s,*t; { if(debug/* @(#)diff.c 1.4 */ # /* diff - differential file comparison * * Uses an algorithm which finds * a pair of longest identical subsequences in the two * files. * * The major goal is to generate the match vector J. * J[i] is the index of the line in file1 corresponding * to line i file0. J[i] = 0 if there is no * such line in file1. * * Lines are hashed so as to work in core. All potential * matches are located by sorting the lines of each file * on the hash (called value_____). In particular, this * c) printf("%s:%s\n",s,t); for(;;){ if(bflag&&isspace(*s)&&isspace(*t)) { while(isspace(*++s)) ; while(isspace(*++t)) ; } if(*s!=*t||*s==0) break; s++; t++; } return(*s-*t); } FILE *dopen(f1,f2) char *f1,*f2; { FILE *f; char b[100],*bptr,*eptr; struct stat statbuf; if(cmp(f1,"-")==0) if(cmp(f2,"-")==0) error("can't do - -",""); else return(stdin); if(stat(f1,&statbuf)==-1) error("can't access ",f1); if((statbuf.st_mode&S_IFMT)==S_IFDIR) { for(bptr=b;*bptr= *f1++;bpollects the equivalence classes in file1 together. * Subroutine equiv____ replaces the value of each line in * file0 by the index of the first element of its * matching equivalence in (the reordered) file1. * To save space equiv_____ squeezes file1 into a single * array member______ in which the equivalence classes * are simply concatenated, except that their first * members are flagged by changing sign. * * Next the indices that point into member______ are unsorted_______ itr++) ; *bptr++ = '/'; for(eptr=f2;*eptr;eptr++) if(*eptr=='/'&&eptr[1]!=0&&eptr[1]!='/') f2 = eptr+1; while(*bptr++= *f2++) ; f1 = b; } f = fopen(f1,"r"); if(f==NULL) error("can't open",f1); return(f); } progerr(s) char *s; { error("program error ",s); } error(s,t) char *s,*t; { fprintf(stderr,"diffh: %s%s\n",s,t); exit(1); } /*stub for resychronization beyond limits of text buf*/ hardsynch() { change(n0,INF,n1,INF,"c"); printf("---change record omitted\n"); error("can't resnto * array class_____ according to the original order of file0. * * The cleverness lies in routine stone______. This marches * through the lines of file0, developing a vector klist_____ * of "k-candidates". At step i a k-candidate is a matched * pair of lines x,y (x in file0 y in file1) such that * there is a common subsequence of lenght k * between the first i lines of file0 and the first y * lines of file1, but there is no such subsequence for * any smaller y. x is the earliest possible mstorage pot for candidates */ int clen = 0; int *J; /*will be overlaid on class*/ long *ixold; /*will be overlaid on klist*/ long *ixnew; /*will be overlaid on file[1]*/ int opt; /* -1,0,1 = -e,normal,-f */ int status = 2; int anychange = 0; char *empty = ""; int bflag; char *tempfile; /*used when comparing against std input*/ char *mktemp(); char *dummy; /*used in resetting storage search ptr*/ done() { unlink(tempfile); exit(status); } char *talloc(n) { extern char *malloc(); register char *p; p p = (struct line *)talloc(3*sizeof(line)); for(j=0; h=readhash(input[i]);) { p = (struct line *)ralloc((char *)p,(++j+3)*sizeof(line)); p[j].value = h; } len[i] = j; file[i] = p; fclose(input[i]); } prune() { register i,j; for(pref=0;pref a; ai -= m) { aim = &ai[m]; if(aim < ai) break; /*wraparound*/ if(aim->value > ai[0].value || aim->value == ai[0].value && aim->serial > ai[0].serial) break; w.value = ai[0].value; ai[0].value = aim->value; aim->value = w.value; w.serial = ai[0].serial; ai[0].serial = aim->serial; aim->serial = w.serial; } } } } unsort(f, l, b) struct line *f; int *b; { registerre utilization and * maximize the range of doable problems by dynamically * allocating what is needed and reusing what is not. * The core requirements for problems larger than somewhat * are (in words) 2*length(file0) + length(file1) + * 3*(number of k-candidates installed), typically about * 6n words for files of length n. */ #include #include #include #include #include #define prints(s) fputs(s,stdout) #define HALFLONG 16 #define low(x) (x&((1L< int *a; register int i; a = (int *)talloc((l+1)*sizeof(int)); for(i=1;i<=l;i++) a[f[i].serial] = f[i].value; for(i=1;i<=l;i++) b[i] = a[i]; free((char *)a); } filename(pa1, pa2) char **pa1, **pa2; { register char *a1, *b1, *a2; char buf[512]; struct stat stbuf; int i, f; a1 = *pa1; a2 = *pa2; if(stat(a1,&stbuf)!=-1 && ((stbuf.st_mode&S_IFMT)==S_IFDIR)) { b1 = *pa1 = malloc(100); while(*b1++ = *a1++) ; b1[-1] = '/'; a1 = b1; while(*a1++ = *a2++) if(*a2 && *a2!='/' && a2[-1]=='/>HALFLONG) FILE *input[2]; FILE *fopen(); struct cand { int x; int y; int pred; } cand; struct line { int serial; int value; } *file[2], line; int len[2]; struct line *sfile[2]; /*shortened by pruning common prefix and suffix*/ int slen[2]; int pref, suff; /*length of prefix and suffix*/ int *class; /*will be overlaid on file[0]*/ int *member; /*will be overlaid on file[1]*/ int *klist; /*will be overlaid on file[0] after class*/ struct cand *clist; /* merely a free ') a1 = b1; } else if(a1[0]=='-'&&a1[1]==0&&tempfile==0) { signal(SIGHUP,done); signal(SIGINT,done); signal(SIGPIPE,done); signal(SIGTERM,done); *pa1 = tempfile = mktemp("/tmp/dXXXXX"); if((f=creat(tempfile,0600)) < 0) { mesg("cannot create ",tempfile); done(); } while((i=read(0,buf,512))>0) write(f,buf,i); close(f); } } prepare(i, arg) char *arg; { register struct line *p; register j,h; if((input[i] = fopen(arg,"r")) == NULL){ mesg("cannot open ", arg); done(); } , member, klist); free((char *)member); free((char *)class); J = (int *)talloc((len[0]+2)*sizeof(int)); unravel(klist[k]); free((char *)clist); free((char *)klist); ixold = (long *)talloc((len[0]+2)*sizeof(long)); ixnew = (long *)talloc((len[1]+2)*sizeof(long)); check(argv); output(argv); status = anychange; done(); } stone(a,n,b,c) int *a; int *b; int *c; { register int i, k,y; int j, l; int oldc, tc; int oldl; k = 0; c[0] = newcand(0,0,0); for(i=1; i<=n; i++) { j = a[i]; if(j==0)ne(0); if(d!='\n') ctnew += skipline(1); break; } if(c=='\n') break; } ixold[i] = ctold; ixnew[j] = ctnew; j++; } for(;j<=len[1];j++) { ixnew[j] = ctnew += skipline(1); } fclose(input[0]); fclose(input[1]); /* if(jackpot) mesg("jackpot",empty); */ } skipline(f) { register i; for(i=1;getc(input[f])!='\n';i++) ; return(i); } output(argv) char **argv; { int m; register int i0, i1, j1; int j0; input[0] = fopen(argv[1],"r"); input[1] = fopen(argv[2],"r"); m = l continue; y = -b[j]; oldl = 0; oldc = c[0]; do { if(y <= clist[oldc].y) continue; l = search(c, k, y); if(l!=oldl+1) oldc = c[l-1]; if(l<=k) { if(clist[c[l]].y <= y) continue; tc = c[l]; c[l] = newcand(i,y,oldc); oldc = tc; oldl = l; } else { c[l] = newcand(i,y,oldc); k++; break; } } while((y=b[++j]) > 0); } return(k); } newcand(x,y,pred) { register struct cand *q; clist = (struct cand *)ralloc((char *)clist,++clen*sizeof(canden[0]; J[0] = 0; J[m+1] = len[1]+1; if(opt!=-1) for(i0=1;i0<=m;i0=i1+1) { while(i0<=m&&J[i0]==J[i0-1]+1) i0++; j0 = J[i0-1]+1; i1 = i0-1; while(i1=1;i0=i1-1) { while(i0>=1&&J[i0]==J[i0+1]-1&&J[i0]!=0) i0--; j0 = J[i0+1]-1; i1 = i0+1; while(i1>1&&J[i1-1]==0) i1--; j1 = J[i1-1]+1; J[i1] = j1; change(i1,i0,j1,j0); } if(m==0) change(1,0,1,len[1]); } change(a,b,c,d) { if(a>b&&c>d) retur)); q = clist + clen -1; q->x = x; q->y = y; q->pred = pred; return(clen-1); } search(c, k, y) int *c; { register int i, j, l; int t; if(clist[c[k]].y i) { t = clist[c[l]].y; if(t > y) j = l; else if(t < y) i = l; else return(l); } return(l+1); } unravel(p) { register int i; register struct cand *q; for(i=0; i<=len[0]; i++) J[i] = i<=pref ? i: i>len[0]-suff ? i+len[1]-len[0]: 0; n; anychange = 1; if(opt!=1) { range(a,b,","); putchar(a>b?'a':c>d?'d':'c'); if(opt!=-1) range(c,d,","); } else { putchar(a>b?'a':c>d?'d':'c'); range(a,b," "); } putchar('\n'); if(opt==0) { fetch(ixold,a,b,input[0],"< "); if(a<=b&&c<=d) prints("---\n"); } fetch(ixnew,c,d,input[1],opt==0?"> ":empty); if(opt!=0&&c<=d) prints(".\n"); } range(a,b,separator) char *separator; { printf("%d", a>b?b:a); if(a3 && *argv[1]=='-') { argc--; argv++; for(k=1;argv[0][k];k++) { switch(argv[0][k]) { case 'e': opt = -1; break; case 'f': opt = 1; break; case 'b': bflag = 1; break; case 'h': execv("/usr/lib/diffh",args); mesg("cannot find diffh",empty); done(); } } } if(argc!=3) { mesg("arg count",empty); done(); } dummy = malloc(1); filename(&argv[1], &argv[2]); filename(&argfor(q=clist+p;q->y!=0;q=clist+q->pred) J[q->x+pref] = q->y+pref; } /* check does double duty: 1. ferret out any fortuitous correspondences due to confounding by hashing (which result in "jackpot") 2. collect random access indexes to the two files */ check(argv) char **argv; { register int i, j; int jackpot; long ctold, ctnew; char c,d; input[0] = fopen(argv[1],"r"); input[1] = fopen(argv[2],"r"); j = 1; ixold[0] = ixnew[0] = 0; jackpot = 0; ctold = ctnew = 0; for(i=1;i<=len[0];i++) { if(Jv[2], &argv[1]); prepare(0, argv[1]); prepare(1, argv[2]); prune(); sort(sfile[0],slen[0]); sort(sfile[1],slen[1]); member = (int *)file[1]; equiv(sfile[0], slen[0], sfile[1], slen[1], member); member = (int *)ralloc((char *)member,(slen[1]+2)*sizeof(int)); class = (int *)file[0]; unsort(sfile[0], slen[0], class); class = (int *)ralloc((char *)class,(slen[0]+2)*sizeof(int)); klist = (int *)talloc((slen[0]+2)*sizeof(int)); clist = (struct cand *)talloc(sizeof(cand)); k = stone(class, slen[0][i]==0) { ixold[i] = ctold += skipline(0); continue; } while(j #include #include #include #include #define EQ(x,y) (strcmp(x,y)==0) #define ML 500 #define DIRECT 10 /* Number of direct blocks */ #ifdef u370 #define INDIR 1024 #define INSHFT 10 #else #define INDIR 128 /* Number of pointers in an indirect block */ #define INSHFT 7 /* Number of right shifts to divide by INDIR # sccs: @(#)diffmk.sh 1.2 if test -z "$3" -o "$3" = "$1" -o "$3" = "$2"; then echo "usage: name1 name2 name3 -- name3 must be different" exit fi diff -e $1 $2 | (sed -n -e ' /[ac]$/{ p a\ .mc | : loop n /^\.$/b done1 p b loop : done1 a\ .mc\ . b } /d$/{ s/d/c/p a\ .mc *\ .mc\ . b }'; echo '1,$p') | ed - $1| sed -e ' /^\.TS/,/.*\. *$/b pos /^\.T&/,/.*\. *$/b pos p d :pos /^\.mc/d ' > $3 ; fcntl(ftendi2,F_SETFL,fcntl(ftendi2,F_GETFL) | O_NDELAY); } -1) { printf("Cannot dup tty fdes for ttyi\n*/ #endif struct { dev_t dev; ino_t ino; } ml[ML]; int linkc = 0; struct stat Statb; char path[256]; int aflag = 0; int rflag = 0; int sflag = 0; long descend(); main(argc, argv) char **argv; { long blocks = 0; #ifdef STANDALONE if (argv[0][0] == '\0') argc = getargv("du", &argv, 0); #endif if(--argc && argv[1][0] == '-' && argv[1][1] != '\0') { argv++; while(*++*argv) switch(**argv) { case 'a': aflag++; continue; case 'r': rflag++; continue; case 's': sfl./usr/src/cmd/dirname.sh 664 2 2 162 3172124143 10242 ag++; continue; default: fprintf(stderr, "usage: du [-ars] [name ...]\n"); exit(2); } argc--; } if(argc == 0) { argc = 1; argv[1] = "."; } while(argc--) { strcpy(path, *++argv); blocks = descend(path); if(sflag) printf("%ld %s\n", blocks, path); } exit(0); } long descend(name) char *name; { register struct direct *dp; register char *c1, *c2; long blocks = 0; struct direct dentry[32]; int dir = 0; /* open directory */ long offset, dirsize; int dsize, entries,r *s; { register int i, j; register int nc; for(i=a;i<=b;i++) { fseek(lb,f[i-1],0); nc = f[i]-f[i-1]; prints(s); for(j=0;j $3 ; fcntl(ftendi2,F_SETFL,fcntl(ftendi2,F_GETFL) | O_NDELAY); } -1) { printf("Cannot dup tty fdes for ttyi\n i; char *endofname; long nblock(); if(stat(name,&Statb)<0) { if(rflag) fprintf(stderr, "du: bad status < %s >\n", name); return(0); } if(Statb.st_nlink>1 && (Statb.st_mode&S_IFMT)!=S_IFDIR && linkc 32000) fprintf(stderr, "Huge directory < %s >--call administrator\n", name); dirsize = Statb.st_size; for(offset=0 ; offset < dirsize ; offset += 512) { /* each block */ dsize = 512<(dirsize-offset)? 512: (dirsize-offset); if(!dir) { if((dir=open(name,0))<0) { if(rflag) fprintf(stderr, "du: cannot open < %s >\n", name); return(0); } if(offset) lseek(dir, (long)offset, 0); /* @(#)echo.c 1.1 */ main(argc, argv) char **argv; { register char *cp; register int i, wd; int j; if(--argc == 0) { putchar('\n'); exit(0); } for(i = 1; i <= argc; i++) { for(cp = argv[i]; *cp; cp++) { if(*cp == '\\') switch(*++cp) { case 'b': putchar('\b'); continue; case 'c': exit(0); case 'f': putchar('\f'); continue; case 'n': putchar('\n'); continue; case 'r': putchar('\r'); continue; case 't': putchar('\ if(read(dir, dentry, dsize)<0) { if(rflag) fprintf(stderr, "du: cannot read < %s >\n", name); close(dir); return(0); } if(dir > 10) { close(dir); dir = 0; } } else if(read(dir, dentry,dsize)<0) { if(rflag) fprintf(stderr, "du: cannot read < %s >\n", name); close(dir); return(0); } for(dp=dentry, entries=dsize>>4; entries; --entries, ++dp) { /* each directory entry */ if(dp->d_ino==0 || EQ(dp->d_name, ".") || EQ(dp->d_name, "..")) t'); continue; case '\\': putchar('\\'); continue; case '0': j = wd = 0; while ((*++cp >= '0' && *cp <= '7') && j++ < 3) { wd <<= 3; wd |= (*cp - '0'); } putchar(wd); --cp; continue; default: cp--; } putchar(*cp); } putchar(i == argc? '\n': ' '); } exit(0); } putchar('\f'); continue; case 'n': putchar('\n'); continue; case 'r': putchar('\r'); continue; case 't': putchar('\ continue; if (dp->d_ino == -1) continue; c1 = endofname; *c1++ = '/'; c2 = dp->d_name; for(i=0; i\n",dp->d_name); return(0); } blocks += descend(name); } } if(dir) close(dir); *endofname = '\0'; if(!sflag) printf("%ld %s\n", blocks, name); return(blocks); } long nblock(size) long size; { long blocks, tot; ./usr/src/cmd/expr.c 664 2 2 12777 3172124173 7473 blocks = tot = (size + (BSIZE - 1)) / BSIZE; if(blocks > DIRECT) tot += ((blocks - DIRECT - 1) >> INSHFT) + 1; if(blocks > DIRECT + INDIR) tot += ((blocks - DIRECT - INDIR - 1) >> (INSHFT * 2)) + 1; if(blocks > DIRECT + INDIR + INDIR*INDIR) tot++; return(tot); } <%s>\n",dp->d_name); return(0); } blocks += descend(name); } } if(dir) close(dir); *endofname = '\0'; if(!sflag) printf("%ld %s\n", blocks, name); return(blocks); } long nblock(size) long size; { long blocks, tot; static char sccsid[] = "@(#)expr.c 1.10"; # define A_STRING 258 # define NOARG 259 # define OR 260 # define AND 261 # define EQ 262 # define LT 263 # define GT 264 # define GEQ 265 # define LEQ 266 # define NEQ 267 # define ADD 268 # define SUBT 269 # define MULT 270 # define DIV 271 # define REM 272 # define MCH 273 # define MATCH 274 #define ESIZE 256 #define error(c) errxx() #define EQL(x,y) !strcmp(x,y) #define INIT register char *sp = instring; #define GETC() (*sp++) #define PEEKC() (*sp) #define Uv = "0"; else rv = r1; break; } return rv; } char *match(s, p) char *s, *p; { register char *rv; (void) strcpy(rv=malloc(8), ltoa((long)ematch(s, p))); if(nbra) { rv = malloc((unsigned) strlen(Mstring[0]) + 1); (void) strcpy(rv, Mstring[0]); } return rv; } ematch(s, p) char *s; register char *p; { static char expbuf[ESIZE]; char *compile(); register num; extern char *braslist[], *braelist[], *loc2; compile(p, expbuf, &expbuf[512], 0); if(nbra > 1) yyerror("Too many '\\('s"); i[op1-OR],0); } switch(op1) { case MATCH: r1 = match(rb,ra); break; } if(noarg == 1) { return r1; } Argi--; goto lop; } ylex = yylex(); if (ylex == NOARG) { noarg = 1; } return r1; } main(argc, argv) char **argv; { Ac = argc; Argi = 1; noarg = 0; paren = 0; Av = argv; buf = expres(0,1); if(Ac != Argi || paren != 0) { yyerror("syntax error"); } (void) write(1, buf, (unsigned) strlen(buf)); (void) write(1, "\n", 1); exit((!strcmp(buf, "0") || !buf[0])? 1: 0); } iNGETC(c) (--sp) #define RETURN(c) return #define ERROR(c) errxx() #include "regexp.h" long atol(); char *ltoa(), *strcpy(), *strncpy(); void exit(); char **Av; char *buf; int Ac; int Argi; int noarg; int paren; char Mstring[1][128]; char *malloc(); char *operators[] = { "|", "&", "+", "-", "*", "/", "%", ":", "=", "==", "<", "<=", ">", ">=", "!=", "match", "\0" }; int op[] = { OR, AND, ADD, SUBT, MULT, DIV, REM, MCH, EQ, EQ, LT, LEQ, GT, GEQ, NEQ, MATCH }; int pri[] = { 1,2,3,3,3,3,3,3,4,4,5,f(advance(s, expbuf)) { if(nbra == 1) { p = braslist[0]; num = braelist[0] - p; if ((num > 127) || (num < 0)) yyerror("Paren problem"); (void) strncpy(Mstring[0], p, num); Mstring[0][num] = '\0'; } return(loc2-s); } return(0); } errxx() { yyerror("RE error"); } yyerror(s) char *s; { (void) write(2, "expr: ", 6); (void) write(2, s, (unsigned) strlen(s)); (void) write(2, "\n", 1); exit(2); } char *ltoa(l) long l; { static str[20]; register char *sp = (char *) &str[18]; /*u370*5,5,6,7}; yylex() { register char *p; register i; if(Argi >= Ac) return NOARG; p = Av[Argi]; if((*p == '(' || *p == ')') && p[1] == '\0' ) return (int)*p; for(i = 0; *operator[i]; ++i) if(EQL(operator[i], p)) return op[i]; return A_STRING; } char *rel(oper, r1, r2) register char *r1, *r2; { long i; if(ematch(r1, "-\\{0,1\\}[0-9]*$") && ematch(r2, "-\\{0,1\\}[0-9]*$")) i = atol(r1) - atol(r2); else i = strcmp(r1, r2); switch(oper) { case EQ: i = i==0; break; case GT: / register i; register neg = 0; if(l == 0x80000000L) return "-2147483648"; if(l < 0) ++neg, l = -l; str[19] = '\0'; do { i = l % 10; *sp-- = '0' + i; l /= 10; } while(l); if(neg) *sp-- = '-'; return ++sp; } char *expres(prior,par) int prior, par; { int ylex, temp, op1; char *r1, *ra, *rb; ylex = yylex(); if (ylex >= NOARG && ylex < MATCH) { yyerror("syntax error"); } if (ylex == A_STRING) { r1 = Av[Argi++]; temp = Argi; } else { if (ylex == '(') { paren++; Argi = i>0; break; case GEQ: i = i>=0; break; case LT: i = i<0; break; case LEQ: i = i<=0; break; case NEQ: i = i!=0; break; } return i? "1": "0"; } char *arith(oper, r1, r2) char *r1, *r2; { long i1, i2; register char *rv; if(!(ematch(r1, "-\\{0,1\\}[0-9]*$") && ematch(r2, "-\\{0,1\\}[0-9]*$"))) yyerror("non-numeric argument"); i1 = atol(r1); i2 = atol(r2); switch(oper) { case ADD: i1 = i1 + i2; break; case SUBT: i1 = i1 - i2; break; case MULT: i1i++; r1 = expres(0,Argi); Argi--; } } lop: ylex = yylex(); if (ylex > NOARG && ylex < MATCH) { op1 = ylex; Argi++; if (pri[op1-OR] <= prior ) return r1; else { switch(op1) { case OR: case AND: r1 = conj(op1,r1,expres(pri[op1-OR],0)); break; case EQ: case LT: case GT: case LEQ: case GEQ: case NEQ: r1=rel(op1,r1,expres(pri[op1-OR],0)); break; case ADD: case SUBT: case MULT: case DIV: case REM: r1=arith(op1,r1,expres(pri[op1-O = i1 * i2; break; case DIV: i1 = i1 / i2; break; case REM: i1 = i1 % i2; break; } rv = malloc(16); (void) strcpy(rv, ltoa(i1)); return rv; } char *conj(oper, r1, r2) char *r1, *r2; { register char *rv; switch(oper) { case OR: if(EQL(r1, "0") || EQL(r1, "")) if(EQL(r2, "0") || EQL(r2, "")) rv = "0"; else rv = r2; else rv = r1; break; case AND: if(EQL(r1, "0") || EQL(r1, "")) rv = "0"; else if(EQL(r2, "0") || EQL(r2, "")) rR],0)); break; case MCH: r1=match(r1,expres(pri[op1-OR],0)); break; } if(noarg == 1) { return r1; } Argi--; goto lop; } } ylex = yylex(); if(ylex == ')') { if(par == Argi) { yyerror("syntax error"); } if(par != 0) { paren--; Argi++; } Argi++; return r1; } ylex = yylex(); if(ylex > MCH && ylex <= MATCH) { if (Argi == temp) { return r1; } op1 = ylex; Argi++; switch(op1) { case MATCH: rb = expres(pri[op1-OR],0); ra = expres(priy */ struct entry { char e_level; /* 0 or 1 */ long e_off; /* in bytes */ char e_type; char e_opcode; union { long num; char *str; } e_value; char *e_str; }; typedef struct entry Entry; Entry *mtab; char fbuf[FBSZ]; char *mfile = "/etc/magic"; char *fort[] = { "function","subroutine","common","dimension","block","integer", "real","data","double",0}; char *asc[] = { "sys","mov","tst","clr","jmp",0}; char *c[] = { "int","char","float","double","struct","extern",0}; char *as[] = { "globl","f(ifd < 0) { printf("cannot open for reading\n"); return; } fbsz = read(ifd, fbuf, FBSZ); if(fbsz == 0) { printf("empty\n"); goto out; } if(ckmtab()) goto out; i = 0; if(ccom() == 0) goto notc; while(fbuf[i] == '#') { j = i; while(fbuf[i++] != '\n') { if(i - j > 255) { printf("data\n"); goto out; } if(i >= fbsz) goto notc; } if(ccom() == 0) goto notc; } check: if(lookup(c) == 1) { while((ch = fbuf[i++]) != ';' && ch != '{') if(i >= fbsz) goto nbyte","even","text","data","bss","comm",0}; char *strchr(); char *malloc(); long atolo(); int i = 0; int fbsz; int ifd; #define prf(x) printf("%s:%s", x, strlen(x)>6 ? "\t" : "\t\t"); main(argc, argv) char **argv; { reg char *p; reg int ch; reg FILE *fl; reg int cflg = 0, eflg = 0, fflg = 0; auto char ap[128]; extern int optind; extern char *optarg; while((ch = getopt(argc, argv, "cf:m:")) != EOF) switch(ch) { case 'c': cflg++; break; case 'f': fflg++; if ((fl = fopen(optarg, "r")) ==otc; printf("c program text"); goto outa; } nl = 0; while(fbuf[i] != '(') { if(fbuf[i] <= 0) goto notas; if(fbuf[i] == ';'){ i++; goto check; } if(fbuf[i++] == '\n') if(nl++ > 6)goto notc; if(i >= fbsz)goto notc; } while(fbuf[i] != ')') { if(fbuf[i++] == '\n') if(nl++ > 6) goto notc; if(i >= fbsz) goto notc; } while(fbuf[i] != '{') { if(fbuf[i++] == '\n') if(nl++ > 6) goto notc; if(i >= fbsz) goto notc; } printf("c program text"); goto outa; ./usr/src/cmd/file/ 40775 2 2 0 3505657276 7230 NULL) { fprintf(stderr, "cannot open %s\n", optarg); goto use; } break; case 'm': mfile = optarg; break; case '?': eflg++; break; } if(!cflg && !fflg && (eflg || optind == argc)) { use: fprintf(stderr, "usage: file [-c] [-f ffile] [-m mfile] file...\n"); exit(2); } if(cflg) { reg Entry *ep; mkmtab(1); printf("level off type opcode value string\n"); for(ep = mtab; ep->e_off != -1L; ep++) { printf("%d\t%d\t%d\t%d\t", ep->e_level, ep->e_off, ep->e_type, ep->e_o./usr/src/cmd/file/file.c 664 2 2 25352 3172123655 10350 pcode); if(ep->e_type == STR) printf("%s\t", ep->e_value.str); else printf("%d\t", ep->e_value.num); printf("%s", ep->e_str); if(ep->e_opcode & SUB) printf("\tsubst"); printf("\n"); } exit(0); } for(; fflg || optind < argc; optind += !fflg) { reg int l; if(fflg) { if((p = fgets(ap, 128, fl)) == NULL) { fflg = 0; optind--; continue; } l = strlen(p); if(l > 0) p[l - 1] = '\0'; } else p = argv[optind]; prf(p); type(p); if(ifd) clos/* @(#)file.c 1.5 */ #include #include #include #include #include #include #include /* ** Types */ #define BYTE 0 #define SHORT 2 #define LONG 4 #define STR 8 /* ** Opcodes */ #define EQ 0 #define GT 1 #define LT 2 #define STRC 3 /* string compare */ #define ANY 4 #define SUB 64 /* or'ed in */ /* ** Misc */ #define NENT 200 #define BSZ 128 #define FBSZ 512 #define reg register /* ** Structure of magic file entre(ifd); } exit(0); } type(file) char *file; { int j,nl; char ch; struct stat mbuf; ifd = -1; if(stat(file, &mbuf) < 0) { printf("cannot open\n"); return; } switch (mbuf.st_mode & S_IFMT) { case S_IFCHR: printf("character"); goto spcl; case S_IFDIR: printf("directory\n"); return; case S_IFIFO: printf("fifo\n"); return; case S_IFBLK: printf("block"); spcl: printf(" special (%d/%d)\n", major(mbuf.st_rdev), minor(mbuf.st_rdev)); return; } ifd = open(file, 0); iouta; notas: for(i=0; i < fbsz; i++) if(fbuf[i]&0200) { if (fbuf[0]=='\100' && fbuf[1]=='\357') { printf("troff output\n"); goto out; } printf("data\n"); goto out; } if (mbuf.st_mode&((S_IEXEC)|(S_IEXEC>>3)|(S_IEXEC>>6))) printf("commands text"); else if(english(fbuf, fbsz)) printf("English text"); else printf("ascii text"); outa: while(i < fbsz) if((fbuf[i++]&0377) > 127) { printf(" with garbage\n"); goto out; } printf("\n"); out: utime(file, &mbuf.st_atime)ULL; ep++; if(ep >= mend) { fprintf(stderr, "file: magic tab overflow - increase NENT in file.c.\n"); exit(2); } } ep->e_off = -1L; } long atolo(s) reg char *s; { reg char c; reg char *fmt = "%ld"; auto long j = 0L; if(*s == '0') { s++; if(*s == 'x') { s++; fmt = "%lx"; } else fmt = "%lo"; } sscanf(s, fmt, &j); return(j); } ckmtab() { reg Entry *ep; reg char *p; reg int lev1 = 0; auto long val; static char init = 0; if(!init) { mkmtab(0); init = 1; } for(; } mkmtab(cflg) reg int cflg; { reg Entry *ep; reg FILE *fp; reg int lcnt = 0; auto char buf[BSZ]; auto Entry *mend; ep = (Entry *) calloc(sizeof(Entry), NENT); if(ep == NULL) { fprintf(stderr, "no memory for magic table\n"); exit(2); } mtab = ep; mend = &mtab[NENT]; fp = fopen(mfile, "r"); if(fp == NULL) { fprintf(stderr, "cannot open magic file <%s>.\n", mfile); exit(2); } while(fgets(buf, BSZ, fp) != NULL) { reg char *p = buf; reg char *p2; reg char opc; if(*p == '\n' ||ep = mtab; ep->e_off != -1L; ep++) { if(lev1) { if(ep->e_level != 1) break; putchar(' '); } else if(ep->e_level == 1) continue; p = &fbuf[ep->e_off]; switch(ep->e_type) { case STR: { if(strncmp(p,ep->e_value.str,strlen(ep->e_value.str))) continue; if(ep->e_opcode & SUB) printf(ep->e_str, ep->e_value.str); else printf(ep->e_str); lev1 = 1; } case BYTE: val = (long)(*(char *) p); break; case SHORT: val = (long)(*(short *) p); break; case *p == '#') continue; lcnt++; /* LEVEL */ if(*p == '>') { ep->e_level = 1; p++; } /* OFFSET */ p2 = strchr(p, '\t'); if(p2 == NULL) { if(cflg) fprintf(stderr, "fmt error, no tab after %son line %d\n", p, lcnt); continue; } *p2++ = NULL; ep->e_off = atolo(p); while(*p2 == '\t') p2++; /* TYPE */ p = p2; p2 = strchr(p, '\t'); if(p2 == NULL) { if(cflg) fprintf(stderr, "fmt error, no tab after %son line %d\n", p, lcnt); continue; } *p2++ =LONG: val = (*(long *) p); break; } switch(ep->e_opcode & ~SUB) { case EQ: if(val != ep->e_value.num) continue; break; case GT: if(val <= ep->e_value.num) continue; break; case LT: if(val >= ep->e_value.num) continue; break; } if(ep->e_opcode & SUB) printf(ep->e_str, val); else printf(ep->e_str); lev1 = 1; } if(lev1) { putchar('\n'); return(1); } return(0); } lookup(tab) reg char **tab; { reg char r; reg int k,j,l; while(fbuf[i] == ' notc: i = 0; while(fbuf[i] == 'c' || fbuf[i] == '#') { while(fbuf[i++] != '\n') if(i >= fbsz) goto notfort; } if(lookup(fort) == 1){ printf("fortran program text"); goto outa; } notfort: i = 0; if(ascom() == 0) goto notas; j = i-1; if(fbuf[i] == '.') { i++; if(lookup(as) == 1){ printf("assembler program text"); goto outa; } else if(j != -1 && fbuf[j] == '\n' && isalpha(fbuf[j+2])){ printf("[nt]roff, tbl, or eqn input text"); goto outa; } } while(lookup(asc) = NULL; if(*p == 's') { if(*(p+1) == 'h') ep->e_type = SHORT; else ep->e_type = STR; } else if (*p == 'l') ep->e_type = LONG; while(*p2 == '\t') *p2++; /* OP-VALUE */ p = p2; p2 = strchr(p, '\t'); if(p2 == NULL) { if(cflg) fprintf(stderr, "fmt error, no tab after %son line %d\n", p, lcnt); continue; } *p2++ = NULL; if(ep->e_type != STR) { opc = *p++; switch(opc) { case '=': ep->e_opcode = EQ; break; case '>': ep->e_opcode = GT; b= 0) { if(ascom() == 0) goto notas; while(fbuf[i] != '\n' && fbuf[i++] != ':') if(i >= fbsz) goto notas; while(fbuf[i] == '\n' || fbuf[i] == ' ' || fbuf[i] == '\t') if(i++ >= fbsz) goto notas; j = i - 1; if(fbuf[i] == '.'){ i++; if(lookup(as) == 1) { printf("assembler program text"); goto outa; } else if(fbuf[j] == '\n' && isalpha(fbuf[j+2])) { printf("[nt]roff, tbl, or eqn input text"); goto outa; } } } printf("assembler program text"); goto reak; case '<': ep->e_opcode = LT; break; case 'x': ep->e_opcode = ANY; break; default: p--; } } if(ep->e_opcode != ANY) { if(ep->e_type != STR) ep->e_value.num = atolo(p); else { ep->e_value.str = malloc(strlen(p) + 1); strcpy(ep->e_value.str, p); } } while(*p2 == '\t') *p2++; /* STRING */ ep->e_str = malloc(strlen(p2) + 1); p = ep->e_str; while(*p2 != '\n') { if(*p2 == '%') ep->e_opcode |= SUB; *p++ = *p2++; } *p = N+1] != '/') { if(fbuf[i] == '\\') i += 2; else i++; if(i >= fbsz) return(0); } if((i += 2) >= fbsz) return(0); } if(fbuf[i] == '\n') if(ccom() == 0) return(0); return(1); } ascom() { while(fbuf[i] == '/') { i++; while(fbuf[i++] != '\n') if(i >= fbsz) return(0); while(fbuf[i] == '\n') if(i++ >= fbsz) return(0); } return(1); } english (bp, n) char *bp; { # define NASC 128 reg int j, vow, freq, rare; reg int badpun = 0, punct = 0; auto int ct[NASC./usr/src/cmd/file/magic 664 2 2 3336 3172123655 10246 ]; if (n<50) return(0); /* no point in statistics on squibs */ for(j=0; j punct) return(0); vow = ct['a'] + ct['e'] + ct['i'] + ct['o'] + ct['u']; freq = ct['e'] + ct['t'] + ct['a'] + ct['i'] + ct['o'] + ct['n# # @(#)magic 1.1 # # file cmd's magic file # # # Basically, the fields of this file are as follows: # byte offset, value type, optional operator (= by default), value # to match (numeric or string), and string to be printed. Numeric # values may be decimal, octal, or hex. Also note that the last # string may have 1 printf format spec. # The '>' in occassional column 1's is magic: it forces file to # continue scanning and matching additional lines. The first line # afterwards not so marked terminates ']; rare = ct['v'] + ct['j'] + ct['k'] + ct['q'] + ct['x'] + ct['z']; if(2*ct[';'] > ct['e']) return(0); if((ct['>']+ct['<']+ct['/'])>ct['e']) return(0); /* shell file test */ return (vow*5 >= n-ct[' '] && freq >= 10*rare); } case ';': case ':': case '?': punct++; if(j < n-1 && bp[j+1] != ' ' && bp[j+1] != '\n') badpun++; } } if (badpun*5 > punct) return(0); vow = ct['a'] + ct['e'] + ct['i'] + ct['o'] + ct['u']; freq = ct['e'] + ct['t'] + ct['a'] + ct['i'] + ct['o'] + ct['nthe search. # 0 short 070707 cpio archive 0 string 070707 ASCII cpio archive 0 long 0177555 old archive 0 long 0177545 4.0 archive 0 long 0100554 apl workspace 0 short 017037 packed text 0 string 5.0 archive 0 short 0407 4.0 executable >16 long >0 not stripped >2 short >0 - version %ld 0 short 0401 unix-rt ldp 0 short 0405 old overlay 0 short 0410 4.0 pure executable >16 long >0 not stripped >2 short >0 - version %ld 0 short 0411 4.0 separate I&D >16 long >0 not stripp./usr/src/cmd/file/file.mk 664 2 2 600 3172123656 10463 ed >2 short >0 - version %ld 0 short 0437 pdp11 kernel overlay 0 short 0570 5.0 executable >12 long >0 not stripped >22 short >0 - version %ld 0 short 0575 5.0 pure executable >12 long >0 not stripped >22 short >0 - version %ld 0 short 0502 basic-16 executable >12 long >0 not stripped 0 short 0503 basic-16 executable (TV) >12 long >0 not stripped 0 short 0510 x86 executable >12 long >0 not stripped 0 short 0511 x86 executable (TV) >12 long >0 not stripped 0 short 0550 3b20d' || fbuf[i] == '\t' || fbuf[i] == '\n') i++; for(j=0; tab[j] != 0; j++) { l = 0; for(k=i; ((r=tab[j][l++]) == fbuf[k] && r != '\0');k++); if(r == '\0') if(fbuf[k] == ' ' || fbuf[k] == '\n' || fbuf[k] == '\t' || fbuf[k] == '{' || fbuf[k] == '/') { i=k; return(1); } } return(0); } ccom() { reg char cc; while((cc = fbuf[i]) == ' ' || cc == '\t' || cc == '\n') if(i++ >= fbsz) return(0); if(fbuf[i] == '/' && fbuf[i+1] == '*') { i += 2; while(fbuf[i] != '*' || fbuf[i# @(#)makefile 1.1 # # Makefile for file command -- necessary to install /etc/magic # TESTDIR=. CFLAGS= -O INS= /etc/install INSDIR= /usr/lbin MINSDIR=/etc all: file file: file.c $(CC) $(CFLAGS) $(LDFLAGS) file.c mv a.out $(TESTDIR)/file install: all $(INS) -n $(INSDIR) $(TESTDIR)/file $(INS) -n $(MINSDIR) magic clean: -rm -f file.o clobber: clean -rm -f $(TESTDIR)/file turn(0); vow = ct['a'] + ct['e'] + ct['i'] + ct['o'] + ct['u']; freq = ct['e'] + ct['t'] + ct['a'] + ct['i'] + ct['o'] + ct['n executable >12 long >0 not stripped 0 short 0551 3b20d executable (TV) >12 long >0 not stripped 0 short 0560 3b5 executable >12 long >0 not stripped 0 short 0561 3b5 executable (TV) >12 long >0 not stripped rt >0 - version %ld 0 short 0502 basic-16 executable >12 long >0 not stripped 0 short 0503 basic-16 executable (TV) >12 long >0 not stripped 0 short 0510 x86 executable >12 long >0 not stripped 0 short 0511 x86 executable (TV) >12 long >0 not stripped 0 short 0550 3b20d); } Home[strlen(Home) - 1] = '\0'; Argc = argc; Argv = argv; if(argc<3) { usage: fprintf(stderr,"Usage: find path-list predicate-list\n"); exit(1); } for(Ai = paths = 1; Ai < (argc-1); ++Ai, ++paths) if(*Argv[Ai] == '-' || EQ(Argv[Ai], "(") || EQ(Argv[Ai], "!")) break; if(paths == 1) /* no path-list */ goto usage; if(!(exlist = exp())) { /* parse and compile the arguments */ fprintf(stderr,"find: parsing error\n"); exit(1); } if(Ai #include #include #define UID 1 #define GID 2 #ifdef RT #include "rt/types.h" #include "rt/dir.h" #include "rt/stat.h" #else #include "sys/types.h" #include "sys/dir.h" #include "sys/stat.h" #endif #define PATHLEN 256 #define A_DAY 86400L /* a day full of seconds */ #define EQ(x, y) (strcmp(x, y)==0) #define BUFSIZE 512 /* In u370 I can't use BUFSIZ nor BSIZE */ #define CPIOBSZ 4096 #define Bufsize 5(); } exit(0); } /* compile time functions: priority is exp()sz, p->s)); } perm(p) register struct { int f, per, s; } *p; { register i; i = (p->s=='-') ? p->per : 07777; /* '-' means only arg bits */ return((Statb.st_mode & i & 07777) == p->per); } type(p) register struct { int f, per, s; } *p; { return((Statb.st_mode&S_IFMT)==p->per); } exeq(p) register struct { int f, com; } *p; { fflush(stdout); /* to flush possible `-print' */ return(doex(p->com)); } ok(p) struct { int f, com; } *p; { int c, yes=0; fflush(stdout); b; if(s=='+') b++; if(EQ(a, "-name")) return(mk(glob, (struct anode *)b, (struct anode *)0)); else if(EQ(a, "-mtime")) return(mk(mtime, (struct anode *)atoi(b), (struct anode *)s)); else if(EQ(a, "-atime")) return(mk(atime, (struct anode *)atoi(b), (struct anode *)s)); else if(EQ(a, "-ctime")) return(mk(ctime, (struct anode *)atoi(b), (struct anode *)s)); else if(EQ(a, "-user")) { if((i=getunum(UID, b)) == -1) { if(gmatch(b, "[0-9][0-9][0-9]*") || gmatch(b, "[0-9][0-9]") || gmatch(bsbrk(CPIOBSZ); Cp = Cbuf = (char *)sbrk(Bufsize); #ifdef RT setio(-1,1); /* turn on physio */ #endif Cflag++; depthf = 1; return(mk(cpio, (struct anode *)0, (struct anode *)0)); } else if(EQ(a, "-newer")) { if(stat(b, &Statb) < 0) { fprintf(stderr,"find: cannot access %s\n", b); exit(1); } Newer = Statb.st_mtime; return mk(newer, (struct anode *)0, (struct anode *)0); } err: fprintf(stderr,"find: bad option %s\n", a); exit(1); } struct anode *mk(f, l, r) int (*f)(); struct anode , "[0-9]")) return mk(user, (struct anode *)atoi(b), (struct anode *)s); fprintf(stderr,"find: cannot find -user name\n"); exit(1); } return(mk(user, (struct anode *)i, (struct anode *)s)); } else if(EQ(a, "-inum")) return(mk(ino, (struct anode *)atoi(b), (struct anode *)s)); else if(EQ(a, "-group")) { if((i=getunum(GID, b)) == -1) { if(gmatch(b, "[0-9][0-9][0-9]*") || gmatch(b, "[0-9][0-9]") || gmatch(b, "[0-9]")) return mk(group, (struct anode *)atoi(b), (struct anode *)s*l, *r; { Node[Nn].F = f; Node[Nn].L = l; Node[Nn].R = r; return(&(Node[Nn++])); } char *nxtarg() { /* get next arg from command line */ static strikes = 0; if(strikes==3) { fprintf(stderr,"find: incomplete statement\n"); exit(1); } if(Ai>=Argc) { strikes++; Ai = Argc + 1; return(""); } return(Argv[Ai++]); } /* execution time functions */ and(p) register struct anode *p; { return(((*p->L->F)(p->L)) && ((*p->R->F)(p->R))?1:0); } or(p) register struct anode *p; { return(((*p->L->F)(p); fprintf(stderr,"find: cannot find -group name\n"); exit(1); } return(mk(group, (struct anode *)i, (struct anode *)s)); } else if(EQ(a, "-size")) return(mk(size, (struct anode *)atoi(b), (struct anode *)s)); else if(EQ(a, "-links")) return(mk(links, (struct anode *)atoi(b), (struct anode *)s)); else if(EQ(a, "-perm")) { for(i=0; *b ; ++b) { if(*b=='-') continue; i <<= 3; i = i + (*b - '0'); } return(mk(perm, (struct anode *)i, (struct anode *)s)); } else if(EQ(a, "-type")->L)) || ((*p->R->F)(p->R))?1:0); } not(p) register struct anode *p; { return( !((*p->L->F)(p->L))); } glob(p) register struct { int f; char *pat; } *p; { return(gmatch(Fname, p->pat)); } print() { puts(Pathname); return(1); } mtime(p) register struct { int f, t, s; } *p; { return(scomp((int)((Now - Statb.st_mtime) / A_DAY), p->t, p->s)); } atime(p) register struct { int f, t, s; } *p; { return(scomp((int)((Now - Statb.st_atime) / A_DAY), p->t, p->s)); } ctime(p) register struct { int f, t, s; } *p) { i = s=='d' ? S_IFDIR : s=='b' ? S_IFBLK : s=='c' ? S_IFCHR : s=='p' ? S_IFIFO : s=='f' ? S_IFREG : #ifdef RT s=='r' ? S_IFREC : s=='m' ? S_IFEXT : s=='1' ? S_IF1EXT: #endif 0; return(mk(type, (struct anode *)i, (struct anode *)0)); } else if (EQ(a, "-exec")) { i = Ai - 1; while(!EQ(nxtarg(), ";")); return(mk(exeq, (struct anode *)i, (struct anode *)0)); } else if (EQ(a, "-ok")) { i = Ai - 1; while(!EQ(nxtarg(), ";")); return(mk(ok, (str; { return(scomp((int)((Now - Statb.st_ctime) / A_DAY), p->t, p->s)); } user(p) register struct { int f, u, s; } *p; { return(scomp(Statb.st_uid, p->u, p->s)); } ino(p) register struct { int f, u, s; } *p; { return(scomp((int)Statb.st_ino, p->u, p->s)); } group(p) register struct { int f, u; } *p; { return(p->u == Statb.st_gid); } links(p) register struct { int f, link, s; } *p; { return(scomp(Statb.st_nlink, p->link, p->s)); } size(p) register struct { int f, sz, s; } *p; { return(scomp((int)((Sitehdr(Buf, BUFSIZE): bwrite(SBuf, BUFSIZE); return; } if(!mklong(hdr.h_filesize)) { Cflag? writehdr(Chdr, CHARS + hdr.h_namesize): bwrite((short *)&hdr, HDRSIZE + hdr.h_namesize); #ifdef RT if (Extend) Cflag? writehdr(Chdr, CHARS + hdr.h_namesize): bwrite((short *)&hdr, HDRSIZE + hdr.h_namesize); #endif return; } if((ifile = open(Fname, 0)) < 0) { cerror: fprintf(stderr,"find: cannot copy %s\n", hdr.h_name); return; } Cflag? writehdr(Chdr, CHARS + hdr.h_namesize): bwrite((shor direct dentry[32]; register struct direct *dp; register char *c1, *c2; register long offset, dirsize; register i; char *endofname; if(stat(fname, &Statb)<0) { fprintf(stderr,"find: bad status-- %s\n", name); return(0); } if(!depthf) (*exlist->F)(exlist); if((Statb.st_mode&S_IFMT)!=S_IFDIR) { if(depthf) (*exlist->F)(exlist); return(1); } for(c1 = name; *c1; ++c1); if((int)(c1-name) >= PATHLEN-sizeof dentry[0].d_name) { fprintf(stderr,"Pathname too long"); exit(2); } if(*(c1-t *)&hdr, HDRSIZE+hdr.h_namesize); #ifdef RT if (Extend) Cflag? writehdr(Chdr, CHARS + hdr.h_namesize): bwrite((short *)&hdr, HDRSIZE + hdr.h_namesize); #endif for(fsz = mklong(hdr.h_filesize); fsz > 0; fsz -= CPIOBSZ) { ct = fsz>CPIOBSZ? CPIOBSZ: fsz; if(read(ifile, Cflag? Buf: (char *)SBuf, ct) < 0) { fprintf(stderr,"Cannot read %s\n", hdr.h_name); continue; } Cflag? writehdr(Buf, ct): bwrite(SBuf, ct); } close(ifile); return 1; } bintochar(t) long t; { #ifdef u370 sprintf(Chdr,1) == '/') --c1; endofname = c1; if(Statb.st_size > 32000) fprintf(stderr,"Huge directory %s --call administrator\n", name); dirsize = Statb.st_size; if((cdval=chdir(fname)) == -1) { fprintf(stderr,"find: cannot chdir to %s\n", name); } else { for(offset=0 ; offset < dirsize;) { /* each block */ dsize = BUFSIZE<(dirsize-offset)? BUFSIZE: (dirsize-offset); if(!dir) { if((dir=open(".", 0))<0) { fprintf(stderr,"find: cannot open %s\n", name); break; } if(offset) lseek(/* to flush possible `-print' */ fprintf(stderr,"< %s ... %s >? ", Argv[p->com], Pathname); fflush(stderr); if((c=getchar())=='y') yes = 1; while(c!='\n') if(c==EOF) exit(2); else c = getchar(); return(yes? doex(p->com): 0); } #define MKSHORT(v, lv) {U.l=1L;if(U.c[0]) U.l=lv, v[0]=U.s[1], v[1]=U.s[0]; else U.l=lv, v[0]=U.s[0], v[1]=U.s[1];} union { long l; short s[2]; char c[4]; } U; long mklong(v) short v[]; { U.l = 1; if(U.c[0] /* VAX */) U.s[0] = v[1], U.s[1] = v[0]; else U.s[0] "%06ho%06ho%06ho%06ho%06ho%06ho%06ho%06ho%011lo%06ho%011lo%s", #else sprintf(Chdr, "%.6ho%.6ho%.6ho%.6ho%.6ho%.6ho%.6ho%.6ho%.11lo%.6ho%.11lo%s", #endif MAGIC,Statb.st_dev,Statb.st_ino,Statb.st_mode,Statb.st_uid, Statb.st_gid,Statb.st_nlink,Statb.st_rdev & 00000177777, Statb.st_mtime,(short)strlen(hdr.h_name)+1,t,hdr.h_name); } newer() { return Statb.st_mtime > Newer; } /* support functions */ scomp(a, b, s) /* funny signed compare */ register a, b; register char s; { if(s == '+') return(a > b)= v[0], U.s[1] = v[1]; return U.l; } depth() { return(1); } cpio() { #define MAGIC 070707 #define HDRSIZE (sizeof hdr - 256) #define CHARS 76 register ifile, ct; static long fsz; register i; strcpy(hdr.h_name, !strncmp(Pathname, "./", 2)? Pathname+2: Pathname); hdr.h_magic = MAGIC; hdr.h_namesize = strlen(hdr.h_name) + 1; hdr.h_uid = Statb.st_uid; hdr.h_gid = Statb.st_gid; hdr.h_dev = Statb.st_dev; hdr.h_ino = Statb.st_ino; hdr.h_mode = Statb.st_mode; hdr.h_nlink = Statb.st_nlink; hdr.h_rd; if(s == '-') return(a < (b * -1)); return(a == b); } doex(com) { register np; register char *na; static char *nargv[50]; static ccode; static pid; ccode = np = 0; while (na=Argv[com++]) { if(strcmp(na, ";")==0) break; if(strcmp(na, "{}")==0) nargv[np++] = Pathname; else nargv[np++] = na; } nargv[np] = 0; if (np==0) return(9); if(pid = fork()) while(wait(&ccode) != pid); else { /*child*/ chdir(Home); execvp(nargv[0], nargv, np); exit(1); } return(ccode ? 0:1); } getunum(tev = Statb.st_rdev; MKSHORT(hdr.h_mtime, Statb.st_mtime); fsz = (hdr.h_mode & S_IFMT) == S_IFREG? Statb.st_size: 0L; #ifdef RT if ((hdr.h_mode & S_IFMT) == S_IFEXT || (hdr.h_mode & S_IFMT) == S_IF1EXT) { Extend = 1; fsz = Statb.st_size; } else Extend = 0; #endif MKSHORT(hdr.h_filesize, fsz); if (Cflag) bintochar(fsz); if(EQ(hdr.h_name, "TRAILER!!!")) { Cflag? writehdr(Chdr, CHARS + hdr.h_namesize): bwrite((short *)&hdr, HDRSIZE + hdr.h_namesize); for (i = 0; i < 10; ++i) Cflag? wr, s) int t; char *s; { register i; struct passwd *getpwnam(), *pw; struct group *getgrnam(), *gr; i = -1; if( t == UID ){ if( ((pw = getpwnam( s )) != (struct passwd *)NULL) && pw != (struct passwd *)EOF ) i = pw->pw_uid; } else { if( ((gr = getgrnam( s )) != (struct group *)NULL) && gr != (struct group *)EOF ) i = gr->gr_gid; } return(i); } descend(name, fname, exlist) struct anode *exlist; char *name, *fname; { int dir = 0, /* open directory */ dsize, entries, cdval = 0; structame) == -1) { fprintf(stderr,"find: bad directory tree\n"); exit(1); } if(endofname != NULL) *endofname = '/'; } } if(depthf) { if(stat(fname, &Statb) < 0) { fprintf(stderr,"cannot stat %s\n", fname); } (*exlist->F)(exlist); } /* *c1 = '/'; */ return; } gmatch(s, p) register char *s, *p; { register int scc; char c; if(scc = *s++) { if((scc &= 0177) == 0) { scc = 0200; } } switch(c = *p++) { case '[': { int ok; int lc; int notflag = 0; ok = 0./usr/src/cmd/grep.c 664 2 2 5066 3172124244 7422 ; lc = 077777; if( *p == '!' ) { notflag = 1; p++; } while( c = *p++ ) { if(c == ']') { return(ok?gmatch(s,p):0); } else if (c == '-') { if(notflag) { if(lc > scc || scc > *(p++)) { ok++; } else { return(0); } } else { if( lc <= scc && scc <= (*p++)) { ok++; } } } else { if(notflag) { if(scc != (lc = (c&0177))) { ok++; } else { return(0); } } else { if(static char sccsid[] = "@(#)grep.c 1.6"; /* * grep -- print lines matching (or not matching) a pattern * * status returns: * 0 - ok, and some matches * 1 - ok, but no matches * 2 - some error */ #include /* * define some macros for rexexp.h */ #define INIT register char *sp = instring; /* First arg points to RE string */ #define GETC() (*sp++) #define PEEKC() (*sp) #define UNGETC(c) (--sp) #define RETURN(c) return; #define ERROR(c) regerr() #include #define LBSIZE 512scc == (lc = (c&0177))) { ok++; } } } } return(0); } case '?': return(scc?gmatch(s,p):0); case '*': if(*p == 0) { return(1); } --s; while(*s) { if(gmatch(s++,p)) { return(1); } } return(0); case 0: return(scc == 0); default: if((c&0177) != scc) { return(0); } } return(gmatch(s,p)?1:0); } bwrite(rp, c) register short *rp; register c; { register short *wp = Wp; c = (c+1) >> 1; while(c--) { if(!Wct) { again: if(write(Cpio, #define ESIZE 256 #define BSIZE 512 #ifdef u370 int sed, nbra; #endif char *strchr(); long lnum; char linebuf[LBSIZE+1]; char expbuf[ESIZE]; int nflag; int bflag; int lflag; int cflag; int vflag; int sflag; int nfile; long tln; int nsucc; main(argc, argv) char **argv; { register c; int errflg = 0; extern int optind; while((c=getopt(argc, argv, "blcnsv")) != EOF) switch(c) { case 'v': vflag++; break; case 'c': cflag++; break; case 'n': nflag++; break; case 'b': bflagdir, (long)offset, 0); } if((i = read(dir, (char *)dentry, dsize)) <= 0) { fprintf(stderr,"find: cannot read %s\n", name); break; } offset += i; if(dir > 10 || offset == dirsize) { close(dir); dir = 0; } for(dp=dentry, entries=dsize>>4; entries; --entries, ++dp) { /* each directory entry */ if(dp->d_ino==0 || (dp->d_name[0]=='.' && dp->d_name[1]=='\0') || (dp->d_name[0]=='.' && dp->d_name[1]=='.' && dp->d_name[2]=='\0')) continue; c1 = endofname; (char *)Dbuf, Bufsize)<0) { Cpio = chgreel(1, Cpio); goto again; } Wct = Bufsize >> 1; wp = Dbuf; ++Blocks; } *wp++ = *rp++; --Wct; } Wp = wp; } writehdr(rp, c) register char *rp; register c; { register char *cp = Cp; while (c--) { if (!Cct) { again: if(write(Cpio, Cbuf, Bufsize) < 0) { Cpio = chgreel(1, Cpio); goto again; } Cct = Bufsize; cp = Cbuf; ++Blocks; } *cp++ = *rp++; --Cct; } Cp = cp; } chgreel(x, fl) { register f; char str[22] *c1++ = '/'; c2 = dp->d_name; for(i=0; i<14; ++i) if(*c2) *c1++ = *c2++; else break; *c1 = '\0'; if(c1 == (endofname + 1)) { /* ?? */ break; } Fname = endofname+1; descend(name, Fname, exlist); } } } if(dir) close(dir); c1 = endofname; *c1 = '\0'; if(cdval == -1 || chdir("..") == -1) { if((endofname=strrchr(Pathname,'/')) == Pathname) chdir("/"); else { if(endofname != NULL) *endofname = '\0'; chdir(Home); if(chdir(Pathn; FILE *devtty; struct stat statb; fprintf(stderr,"find: can't %s\n", (x? "write output": "read input")); fstat(fl, &statb); if((statb.st_mode&S_IFMT) != S_IFCHR) exit(1); again: fprintf(stderr,"If you want to go on, type device/file name when ready\n"); devtty = fopen("/dev/tty", "r"); fgets(str, 20, devtty); str[strlen(str) - 1] = '\0'; if(!*str) exit(1); close(fl); if((f = open(str, x? 1: 0)) < 0) { fprintf(stderr,"That didn't work"); fclose(devtty); goto again; } return f; } 22] register char *p1; register c; FILE *temp; if (file) { if ( (temp = fopen(file, "r")) == NULL) { if (!sflag) fprintf(stderr,"grep: can't open %s\n", file); nsucc = 2; return; } else { fclose(temp); freopen(file, "r", stdin); } } lnum = 0; tln = 0; for (;;) { lnum++; p1 = linebuf; while ((c = getchar()) != '\n') { if (c == EOF) { if (cflag) { if (nfile>1) printf("%s:", file); printf("%ld\n", tln); } return; } *p1++ = c; if# @(#)fsck.mk 1.1 TESTDIR = . INSDIR = /etc INCRT = /usr/include INS = : CFLAGS = -O FRC = all: fsck fsck1b fsck::\ $(INCRT)/stdio.h\ $(INCRT)/ctype.h\ $(INCRT)/sys/param.h\ $(INCRT)/signal.h\ $(INCRT)/sys/types.h\ $(INCRT)/sys/sysmacros.h\ $(INCRT)/sys/filsys.h\ $(INCRT)/sys/dir.h\ $(INCRT)/sys/fblk.h\ $(INCRT)/sys/ino.h\ $(INCRT)/sys/inode.h\ $(INCRT)/sys/stat.h\ fsck.c\ $(FRC) $(CC) $(CFLAGS) -DFsTYPE=2 -o $(TESTDIR)/fsck fsck.c fsck:: $(INS) -n $(INSDIR) $(TESTDIR)/fsck fsck1b::\ $(I (p1 >= &linebuf[LBSIZE-1]) break; } *p1++ = '\0'; if(step(linebuf, expbuf) ^ vflag) succeed(file); } } succeed(f) char *f; { long tell(); nsucc = (nsucc == 2) ? 2 : 1; if (cflag) { tln++; return; } if (lflag) { printf("%s\n", f); fseek(stdin, 0l, 2); return; } if (nfile > 1) printf("%s:", f); if (bflag) printf("%ld:", (ftell(stdin)-1)/BSIZE); if (nflag) printf("%ld:", lnum); printf("%s\n", linebuf); } regerr() { errexit("RE error\n", (char *)NULL); } errexit(s, fNCRT)/stdio.h\ $(INCRT)/ctype.h\ $(INCRT)/sys/param.h\ $(INCRT)/signal.h\ $(INCRT)/sys/types.h\ $(INCRT)/sys/sysmacros.h\ $(INCRT)/sys/filsys.h\ $(INCRT)/sys/dir.h\ $(INCRT)/sys/fblk.h\ $(INCRT)/sys/ino.h\ $(INCRT)/sys/inode.h\ $(INCRT)/sys/stat.h\ fsck.c\ $(FRC) $(CC) $(CFLAGS) -DFsTYPE=1 -o $(TESTDIR)/fsck1b fsck.c fsck1b:: -if pdp11 ; then ln $(TESTDIR)/fsck1b $(TESTDIR)/fsck ; \ $(INS) -n $(INSDIR) $(TESTDIR)/fsck ; \ else $(INS) -n $(INSDIR) $(TESTDIR)/fsck1b ; fi FRC : install: -i) char *s, *f; { fprintf(stderr, s, f); exit(2); } \0'; if(step(linebuf, expbuf) ^ vflag) succeed(file); } } succeed(f) char *f; { long tell(); nsucc = (nsucc == 2) ? 2 : 1; if (cflag) { tln++; return; } if (lflag) { printf("%s\n", f); fseek(stdin, 0l, 2); return; } if (nfile > 1) printf("%s:", f); if (bflag) printf("%ld:", (ftell(stdin)-1)/BSIZE); if (nflag) printf("%ld:", lnum); printf("%s\n", linebuf); } regerr() { errexit("RE error\n", (char *)NULL); } errexit(s, ff pdp11 ; then make -f fsck.mk fsck1b INS=/etc/install\ TESTDIR="$(TESTDIR)" INSDIR="$(INSDIR)"\ INCRT="$(INCRT)" CFLAGS="$(CFLAGS)" ; \ else make -f fsck.mk all INS=/etc/install FRC=$(FRC)\ TESTDIR="$(TESTDIR)" INSDIR="$(INSDIR)"\ INCRT="$(INCRT)" CFLAGS="$(CFLAGS)" ; fi clean: rm -f *.o clobber : clean rm -f $(TESTDIR)/fsck $(TESTDIR)/fsck1b n ln $(TESTDIR)/fsck1b $(TESTDIR)/fsck ; \ $(INS) -n $(INSDIR) $(TESTDIR)/fsck ; \ else $(INS) -n $(INSDIR) $(TESTDIR)/fsck1b ; fi FRC : install: -i./usr/src/cmd/fsck/ 40775 2 2 0 5555176715 7240 ./usr/src/cmd/fsck/fsck.c 664 2 2 150442 3172124167 10404 ++; break; case 's': sflag++; break; case 'l': lflag++; break; case '?': errflg++; } argc -= optind; if(errflg || (argc<=0)) errexit("usage: grep -blcnsv pattern file . . .\n", (char *)NULL); argv = &argv[optind]; if (strchr(*argv,'\n')) regerr(); compile(*argv, expbuf, &expbuf[ESIZE], '\0'); nfile = --argc; if (argc<=0) execute((char *)NULL); else while (--argc >= 0) { argv++; execute(*argv); } exit(nsucc == 2 ? 2 : nsucc == 0); } execute(file) char *file; {./usr/src/cmd/fsck/fsck.mk 664 2 2 2547 3172124167 10533 /* @(#)fsck.c 1.16 */ #include #include #ifdef RT #include #include #include #include #include #include #include #include #include #else #ifdef STANDALONE #include #else #include #include #include #endif #include #ifndef u370 #include #endif #include #inclu /* blk num of first in raw area */ unsigned niblk; /* num of blks in raw area */ #ifndef u370 struct bufarea { struct bufarea *b_next; /* must be first */ daddr_t b_bno; union { char b_buf[BSIZE]; /* buffer space */ short b_lnks[SPERB]; /* link counts */ daddr_t b_indir[NINDIR]; /* indirect block */ struct filsys b_fs; /* super block */ struct fblk b_fb; /* free block */ struct dinode b_dinode[INOPB]; /* inode block */ DIRECT b_dir[NDIRECT]; /* directory */ } b_un; char b_dirty;de #include #include #include #endif #ifdef RT /* The following constants should be added to */ /* inumber to disk offset */ #define itoo(x) (int)((x+15)&07) /* inumber to disk address */ #define itod(x) (daddr_t)(((x+15)>>3)&017777) #endif #define SBSIZE 512 #define NDIRECT (BSIZE/sizeof(struct direct)) #define SPERB (BSIZE/sizeof(short)) #define NO 0 #define YES 1 #define MAXDUP 10 /* limit on dup blks (per inode) */ #define MAXBAD 10 }; #else /* For u370, arrange bufarea structure such that * buffer is on page boundary, thus permitting raw block i/o. */ struct bufarea { struct bufarea *b_next; /* must be first */ daddr_t b_bno; char b_dirty; char b_fill[BSIZE-sizeof(char *)-sizeof(daddr_t)-sizeof(char)]; union { char b_buf[BSIZE]; /* buffer space */ short b_lnks[SPERB]; /* link counts */ daddr_t b_indir[NINDIR]; /* indirect block */ struct filsys b_fs; /* super block */ struct fblk b_fb; /* free block */ str /* limit on bad blks (per inode) */ #define STEPSIZE 7 /* default step for freelist spacing */ #define CYLSIZE 400 /* default cyl size for spacing */ #define MAXCYL 1000 /* maximum cylinder size */ #define BITSPB 8 /* number bits per byte */ #define BITSHIFT 3 /* log2(BITSPB) */ #define BITMASK 07 /* BITSPB-1 */ #define LSTATE 2 /* bits per inode state */ #define STATEPB (BITSPB/LSTATE) /* inode states per byte */ #define USTATE 0 /* inode not allocated */ #define FSTATE 01 /* inode is file */ #deuct dinode b_dinode[INOPB]; /* inode block */ DIRECT b_dir[NDIRECT]; /* directory */ } b_un; }; #endif typedef struct bufarea BUFAREA; #ifdef u370 /* For u370, main BUFAREAs must be allocated via sbrk * to avoid base register problems. The following defines * cause all references to these BUFAREAs to be indirect. */ #define inoblk (*inoblkp) #define fileblk (*fileblkp) #define sblk (*sblkp) #endif BUFAREA inoblk; /* inode blocks */ BUFAREA fileblk; /* other blks in filesys */ BUFAREA sblk; fine DSTATE 02 /* inode is directory */ #define CLEAR 03 /* inode is to be cleared */ #define EMPT 32 /* empty directory? */ #define SMASK 03 /* mask for inode state */ typedef struct dinode DINODE; typedef struct direct DIRECT; #define ALLOC ((dp->di_mode & IFMT) != 0) #define DIR ((dp->di_mode & IFMT) == IFDIR) #define REG ((dp->di_mode & IFMT) == IFREG) #define BLK ((dp->di_mode & IFMT) == IFBLK) #define CHR ((dp->di_mode & IFMT) == IFCHR) #define FIFO ((dp->di_mode & IFMT) == IFIFO) #ifdef RT #def /* file system superblock */ #ifdef RT #define ftypeok(dp) (REG||DIR||CHR||BLK||FIFO||REC||SEXT||MEXT) #else #define ftypeok(dp) (REG||DIR||BLK||CHR||FIFO) #endif BUFAREA *poolhead; /* ptr to first buffer in pool */ #define initbarea(x) (x)->b_dirty = 0;(x)->b_bno = (daddr_t)-1 #define dirty(x) (x)->b_dirty = 1 #define inodirty() inoblk.b_dirty = 1 #define fbdirty() fileblk.b_dirty = 1 #define sbdirty() sblk.b_dirty = 1 #define freeblk fileblk.b_un.b_fb #define dirblk fileblk.b_un.b_dir #define superine REC ((dp->di_mode & IFMT) == IFREC) #define SEXT ((dp->di_mode & IFMT) == IF1EXT) #define MEXT ((dp->di_mode & IFMT) == IFEXT) #define SPECIAL (BLK || CHR || REC) #else #define SPECIAL (BLK || CHR) #endif #if STANDALONE && pdp11 #define MAXPATH 200 #else #define MAXPATH 1500 /* max size for pathname string. * Increase and recompile if pathname * overflows. */ #endif #define NINOBLK 11 /* num blks for raw reading */ #define MAXRAW 110 /* largest raw read (in blks) */ daddr_t startib; blk sblk.b_un.b_fs struct filecntl { int rfdes; int wfdes; int mod; }; struct filecntl dfile; /* file descriptors for filesys */ struct filecntl sfile; /* file descriptors for scratch file */ typedef unsigned MEMSIZE; MEMSIZE memsize; /* amt of memory we got */ #ifdef pdp11 #define MAXDATA ((MEMSIZE)54*1024) #endif #ifdef u3b #define MAXDATA ((MEMSIZE)350*1024) #endif #ifdef vax #ifdef STANDALONE #define MAXDATA ((MEMSIZE)256*1024) #else #define MAXDATA ((MEMSIZE)350*1024) #endif #endif #ifdef u37t inum; /* inode we are currently working on */ ino_t imax; /* number of inodes */ ino_t parentdir; /* i number of parent directory */ ino_t lastino; /* hiwater mark of inodes */ ino_t lfdir; /* lost & found directory */ ino_t orphan; /* orphaned inode */ off_t filsize; /* num blks seen in file */ off_t bmapsz; /* num chars in blkmap */ daddr_t smapblk; /* starting blk of state map */ daddr_t lncntblk; /* starting blk of link cnt table */ daddr_t fmapblk; /* starting blk of free map */ dadn",id); strcpy(scrfile,argv[i]); if( (stat(scrfile,&statbuf) >= 0) && ((statbuf.st_mode & S_IFMT) != S_IFREG) ) errexit("%c Illegal scratch file <%s>\n", id,scrfile); break; case 's': /* salvage flag */ stype(argv[i]+2); sflag++; break; case 'S': /* conditional salvage */ stype(argv[i]+2); csflag++; break; case 'n': /* default no answer flag */ case 'N': nflag++; yflag = 0; break; case 'y': /* default yes answer flag */ case '0 #define MAXDATA ((MEMSIZE)8*16*4096) #endif #define DUPTBLSIZE 100 /* num of dup blocks to remember */ daddr_t duplist[DUPTBLSIZE]; /* dup block table */ daddr_t *enddup; /* next entry in dup table */ daddr_t *muldup; /* multiple dups part of table */ #define MAXLNCNT 20 /* num zero link cnts to remember */ ino_t badlncnt[MAXLNCNT]; /* table of inos with zero link cnts */ ino_t *badlnp; /* next entry in table */ char sflag; /* salvage free block list */ char csflag; /* salvage free block list (cdr_t n_free; /* number of free blocks */ daddr_t n_blks; /* number of blocks used */ daddr_t n_files; /* number of files seen */ #ifdef RT daddr_t fbmap; /* block number of the first bit map block */ #endif daddr_t fmin; /* block number of the first data block */ daddr_t fmax; /* number of blocks in the volume */ #define minsz(x,y) (x>y ? y : x) #define howmany(x,y) (((x)+((y)-1))/(y)) #define roundup(x,y) ((((x)+((y)-1))/(y))*(y)) #define outrange(x) (x < fmin || x >= fmax) #define zapino(x) clonditional) */ char nflag; /* assume a no response */ char yflag; /* assume a yes response */ char tflag; /* scratch file specified */ char rplyflag; /* any questions asked? */ char qflag; /* less verbose flag */ char Dirc; /* extensive directory check */ char fast; /* fast check- dup blks and free list check */ char hotroot; /* checking root device */ #ifdef u370 char bflag; /* reboot if root was modified (automatically) */ #endif char rawflg; /* read raw device */ char rmscr; /* removeear((x),sizeof(DINODE)) #define setlncnt(x) dolncnt(x,0) #define getlncnt() dolncnt(0,1) #define declncnt() dolncnt(0,2) #define setbmap(x) domap(x,0) #define getbmap(x) domap(x,1) #define clrbmap(x) domap(x,2) #define setfmap(x) domap(x,0+4) #define getfmap(x) domap(x,1+4) #define clrfmap(x) domap(x,2+4) #define setstate(x) dostate(x,0) #define getstate() dostate(0,1) #define DATA 1 #define ADDR 0 #define BBLK 2 #define ALTERD 010 #define KEEPON 04 #define SKIP 02 #define STOP 01 #define REM 07 DINOD scratch file when done */ char fixfree; /* corrupted free list */ char *membase; /* base of memory we get */ char *blkmap; /* ptr to primary blk allocation map */ char *freemap; /* ptr to secondary blk allocation map */ char *statemap; /* ptr to inode state table */ char *pathp; /* pointer to pathname position */ char *thisname; /* ptr to current pathname component */ char *srchname; /* name being searched for in dir */ /*char *savep;*/ /* save block position */ /*unsigned saven;*/ /* save bytE *ginode(); BUFAREA *getblk(); BUFAREA *search(); int dirscan(); int chkblk(); int findino(); int catch(); int mkentry(); int chgdd(); int pass1(); int pass1b(); int pass2(); int pass3(); int pass4(); int pass5(); char id = ' '; dev_t pipedev = -1; /* is pipedev (and != -1) iff the standard input * is a pipe, which means we can't check pipedev! */ main(argc,argv) int argc; char *argv[]; { register FILE *fp; register i; char filename[50]; int ret; int n; int svargc, argvix; int ix; char **argx;e number */ char pss2done; /* do not check dir blks anymore */ char initdone; char pathname[MAXPATH]; char scrfile[80]; char devname[25]; char *lfname = "lost+found"; char *checklist = "/etc/checklist"; short *lncntp; /* ptr to link count table */ int cylsize; /* num blocks per cylinder */ int stepsize; /* num blocks for spacing purposes */ int badblk; /* num of bad blks seen (per inode) */ int dupblk; /* num of dup blks seen (per inode) */ int (*pfunc)(); /* function to call to chk blk */ ino_ struct stat statbuf; if ( argv[0][0] >= '0' && argv[0][0] <= '9' ) id = argv[0][0]; #ifndef STANDALONE setbuf(stdin,NULL); setbuf(stdout,NULL); #endif #ifdef RT setio(-1,1); /* use physical io */ #endif #ifdef STANDALONE if (argv[0][0] == '\0') argc = getargv ("fsck", &argv, 0); #else sync(); #endif svargc = argc; for(i = 1; --argc < 0, *argv[i] == '-'; i++) { switch(*(argv[i]+1)) { case 't': case 'T': tflag++; if(*argv[++i] == '-' || --argc <= 0) errexit("%c Bad -t option\n = 0; n < argc; n++) argv[argvix + n] = argv[svargc - argc + n]; argv[argvix + n] = NULL; } #if FsTYPE==2 if(execvp("/etc/fsck1b",argv) == -1) errexit("%c %sCannot exec /etc/fsck1b\n", id,devname); #else if(execvp("/etc/fsck",argv) == -1) errexit("%c %sCannot exec /etc/fsck\n", id,devname); #endif } if(!initdone) { initmem(); initdone++; } check(argv[ix++]); argc--; } #else initmem(); ix = svargc - argc; if(argc) { while (argc-- > 0) { initbarea( register n; register ino_t *blp; ino_t savino; daddr_t blk; BUFAREA *bp1, *bp2; if(pipedev != -1) { strcpy(devname,dev); strcat(devname,"\t"); } else devname[0] = '\0'; if(setup(dev) == NO) return; printf("%c %s** Phase 1 - Check Blocks and Sizes\n",id,devname); pfunc = pass1; for(inum = 1; inum <= imax; inum++) { if((dp = ginode()) == NULL) continue; if(ALLOC) { lastino = inum; if(ftypeok(dp) == NO) { printf("%c %sUNKNOWN FILE TYPE I=%u",id,devname,inum); if(dp-&sblk); if(checksb(argv[ix]) == NO) { ix++; continue; } #if FsTYPE==2 if(superblk.s_magic != FsMAGIC || (superblk.s_magic == FsMAGIC && superblk.s_type == Fs1b)) { error("%c %s not a 1k file system\n", id,argv[ix]); ix++; continue; } #endif check(argv[ix++]); } } else { /* use checklist */ if((fp = fopen(checklist,"r")) == NULL) errexit("%c Can't open checklist file: %s\n", id,checklist); while(getline(fp,filename,sizeof(filename)) != EOF) { init>di_size) printf(" (NOT EMPTY)"); if(reply("CLEAR") == YES) { zapino(dp); inodirty(); } continue; } n_files++; if(setlncnt(dp->di_nlink) <= 0) { if(badlnp < &badlncnt[MAXLNCNT]) *badlnp++ = inum; else { printf("%c %sLINK COUNT TABLE OVERFLOW",id,devname); if(reply("CONTINUE") == NO) errexit(""); } } setstate(DIR ? DSTATE : FSTATE); badblk = dupblk = 0; filsize = 0; ckinode(dp,ADDR); if((n = getstate()) == DSTATE || n == FY': yflag++; nflag = 0; break; #ifdef u370 case 'b': /* Automatic reboot flag (u370 only) */ case 'B': bflag++; break; #endif case 'q': qflag++; break; case 'D': Dirc++; break; case 'F': case 'f': fast++; break; default: errexit("%c %c option?\n",id,*(argv[i]+1)); } } if(nflag && sflag) errexit("%c Incompatible options: -n and -s\n",id); if(nflag && qflag) errexit("%c Incompatible options: -n and -q\n",id); if(sflag && csflag) barea(&sblk); if(checksb(filename) == NO) continue; #if FsTYPE==2 if(superblk.s_magic != FsMAGIC || (superblk.s_magic == FsMAGIC && superblk.s_type == Fs1b)) { error("%c %s not a 1k file system\n", id,filename); continue; } #endif check(filename); } fclose(fp); } #endif exit(0); } error(s1,s2,s3,s4) char *s1, *s2, *s3, *s4; { printf(s1,s2,s3,s4); } errexit(s1,s2,s3,s4) char *s1, *s2, *s3, *s4; { error(s1,s2,s3,s4); exit(8); } initmem() { register n; #ifdef u370sflag = 0; if(csflag) nflag++; #if !STANDALONE && !pdp11 if(!argc) { /* use default checklist */ if((fp = fopen(checklist,"r")) == NULL) errexit("%c Can't open checklist file: %s\n",id,checklist); ret = getno(fp); argx = (char **)calloc(svargc + ret + 1,sizeof(char *)); for(n = 0; n < svargc; n++) argx[n] = argv[n]; rewind(fp); while(getline(fp,filename,sizeof(filename)) != EOF && n < svargc + ret) { argx[n] = (char *)calloc(strlen(filename)+1, 1); strcpy(&argx[n++][0], filen int base; #endif struct stat statbuf; int (*sg)(); char *sbrk(); #ifdef u370 inoblkp = (BUFAREA *)sbrk(sizeof(BUFAREA)); fileblkp = (BUFAREA *)sbrk(sizeof(BUFAREA)); sblkp = (BUFAREA *)sbrk(sizeof(BUFAREA)); #endif memsize = (MEMSIZE)sbrk(sizeof(int)); memsize = MAXDATA - memsize - sizeof(int); while(memsize >= 2*sizeof(BUFAREA) && (membase = sbrk(memsize)) == (char *)-1) memsize -= 1024; if(memsize < 2*sizeof(BUFAREA)) errexit("%c Can't get memory\n",id); #ifdef u370 if((base = (int)memame); argc++; } argx[n] = NULL; argv = argx; svargc += argc; fclose(fp); } ix = argvix = svargc - argc; /* position of first fs argument */ while(argc > 0) { initbarea(&sblk); if(checksb(argv[ix]) == NO) { argc--; ix++; continue; } #if FsTYPE==2 if(superblk.s_magic != FsMAGIC || (superblk.s_magic == FsMAGIC && superblk.s_type == Fs1b)) { #else if(superblk.s_magic == FsMAGIC && superblk.s_type == Fs2b) { #endif close(dfile.rfdes); if(argvix < svargc - argc) { for(base % BSIZE) != 0) membase -= base; #endif #ifndef STANDALONE for(n = 1; n < NSIG; n++) { if(n == SIGCLD || n == SIGPWR) continue; sg = signal(n,catch); if(sg != SIG_DFL) signal(n,sg); } #endif /* Check if standard input is a pipe. If it is, record pipedev so * we won't ever check it */ if ( fstat( 0, &statbuf) == -1 ) errexit("%c Can't fstat standard input\n", id); if ( (statbuf.st_mode & S_IFMT) == S_IFIFO ) pipedev = statbuf.st_dev; } check(dev) char *dev; { register DINODE *dp;thp = pathname; pfunc = pass2; switch(getstate()) { case USTATE: errexit("%c %sROOT INODE UNALLOCATED. TERMINATING.\n",id,devname); case FSTATE: printf("%c %sROOT INODE NOT DIRECTORY",id,devname); if(reply("FIX") == NO || (dp = ginode()) == NULL) errexit(""); dp->di_mode &= ~IFMT; dp->di_mode |= IFDIR; inodirty(); setstate(DSTATE); case DSTATE: descend(); break; case CLEAR: printf("%c %sDUPS/BAD IN ROOT INODE\n",id,devname); if(reply("CONTINUE") == NO) erre dirty(bp2); } } badblk = dupblk = 0; freeblk.df_nfree = superblk.s_nfree; for(n = 0; n < NICFREE; n++) freeblk.df_free[n] = superblk.s_free[n]; freechk(); if(badblk) printf("%c %s%d BAD BLKS IN FREE LIST\n",id,devname,badblk); if(dupblk) printf("%c %s%d DUP BLKS IN FREE LIST\n",id,devname,dupblk); #ifdef RT chkmn(); n_free = fmax - fmin - n_blks; if(fixfree == 0) { printf("%c %s** Phase 5a - Check Bit Map \n",id,devname); fixfree = chkmap(); if(!fixfree) { if(nxit(""); setstate(DSTATE); descend(); } pss2done++; printf("%c %s** Phase 3 - Check Connectivity\n",id,devname); for(inum = ROOTINO; inum <= lastino; inum++) { if(getstate() == DSTATE) { pfunc = findino; srchname = ".."; savino = inum; do { orphan = inum; if((dp = ginode()) == NULL) break; filsize = dp->di_size; parentdir = 0; ckinode(dp,DATA); if((inum = parentdir) == 0) break; } while(getstate() == DSTATE); inum = orphan; if(linkup() == _free != superblk.s_tfree) { printf("%c %sFREE BLK COUNT WRONG IN SUPERBLK",id,devname); if (qflag) { superblk.s_tfree = n_free; sbdirty(); printf("\n%c %sFIXED\n",id,devname); } else if(reply("FIX") == YES) { superblk.s_tfree = n_free; sbdirty(); } } } } if(fixfree) { switch(fixfree){ case 1: printf("%c %sBAD FREE LIST",id,devname); break; case 2: printf("%c %sBAD BIT MAP",id,devname); break; } if(qflag YES) { thisname = pathp = pathname; *pathp++ = '?'; pfunc = pass2; descend(); } inum = savino; } } printf("%c %s** Phase 4 - Check Reference Counts\n",id,devname); pfunc = pass4; for(inum = ROOTINO; inum <= lastino; inum++) { switch(getstate()) { case FSTATE: if(n = getlncnt()) adjust((short)n); else { for(blp = badlncnt;blp < badlnp; blp++) if(*blp == inum) { if((dp = ginode()) && dp->di_size) { if((n = linkup()) == NO) && !sflag) { fixfree = 1; printf("\n%c %sSALVAGED\n",id,devname); } else if(reply("SALVAGE") == NO) fixfree = 0; } } #else if(fixfree == 0) { if((n_blks+n_free) != (fmax-fmin)) { printf("%c %s%ld BLK(S) MISSING\n",id,devname, fmax-fmin-n_blks-n_free); fixfree = 1; } else if(n_free != superblk.s_tfree) { printf("%c %sFREE BLK COUNT WRONG IN SUPERBLK",id,devname); if(qflag) { superblk.s_tfree = n_free; sbdirty(); printf("\n%c %sFIXED\n",id,dSTATE) sizechk(dp); } else if(dp->di_mode != 0) { printf("%c %sPARTIALLY ALLOCATED INODE I=%u",id,devname,inum); if(dp->di_size) printf(" (NOT EMPTY)"); if(reply("CLEAR") == YES) { zapino(dp); inodirty(); } } } if(enddup != &duplist[0]) { printf("%c %s** Phase 1b - Rescan For More DUPS\n",id,devname); pfunc = pass1b; for(inum = 1; inum <= lastino; inum++) { if(getstate() != USTATE && (dp = ginode()) != NULL) if(ckinode(dp,ADDR) & STOP) break; } } i clri("UNREF",NO); if (n == REM) clri("UNREF",REM); } else clri("UNREF",YES); break; } } break; case DSTATE: clri("UNREF",YES); break; case CLEAR: clri("BAD/DUP",YES); } } if(imax - n_files != superblk.s_tinode) { printf("%c %sFREE INODE COUNT WRONG IN SUPERBLK",id,devname); if (qflag) { superblk.s_tinode = imax - n_files; sbdirty(); printf("\n%c %sFIXED\n",id,devname); } else if(reply("FIX") == YES) { f(rawflg) { if(inoblk.b_dirty) bwrite(&dfile,membase,startib,niblk*BSIZE); inoblk.b_dirty = 0; if(poolhead) { clear(membase,niblk*BSIZE); for(bp1 = poolhead;bp1->b_next;bp1 = bp1->b_next); bp2 = &((BUFAREA *)membase)[(niblk*BSIZE)/sizeof(BUFAREA)]; while(--bp2 >= (BUFAREA *)membase) { initbarea(bp2); bp2->b_next = bp1->b_next; bp1->b_next = bp2; } } rawflg = 0; } if(!fast) { printf("%c %s** Phase 2 - Check Pathnames\n",id,devname); inum = ROOTINO; thisname = pa superblk.s_tinode = imax - n_files; sbdirty(); } } flush(&dfile,&fileblk); } /* if fast check, skip to phase 5 */ printf("%c %s** Phase 5 - Check Free List ",id,devname); if(sflag || (csflag && rplyflag == 0)) { printf("(Ignored)\n"); fixfree = 1; } else { printf("\n"); if(freemap) copy(blkmap,freemap,(MEMSIZE)bmapsz); else { for(blk = 0; blk < fmapblk; blk++) { bp1 = getblk(NULL,blk); bp2 = getblk(NULL,blk+fmapblk); copy(bp1->b_un.b_buf,bp2->b_un.b_buf,BSIZE); e, #if FsTYPE==2 n_files,n_blks*2,n_free*2); #else n_files,n_blks,n_free); #endif #ifndef STANDALONE if(dfile.mod) { time(&superblk.s_time); sbdirty(); } #endif ckfini(); #ifndef STANDALONE sync(); if(dfile.mod && hotroot) { printf("%c %s***** BOOT UNIX (NO SYNC!) *****\n",id,devname); #ifdef u370 if (bflag) reboot(); #endif for(;;); } #endif if(dfile.mod) printf("%c %s***** FILE SYSTEM WAS MODIFIED *****\n",id,devname); } ckinode(dp,flg) register DINODE *dp; register flg; { regn(SKIP); #ifdef u370 ilevel--; if(ibp[ilevel]==NULL) ibp[ilevel] = (BUFAREA *)sbrk(sizeof(BUFAREA)); #endif initbarea(&ib); if(getblk(&ib,blk) == NULL) return(SKIP); #ifndef u370 ilevel--; #endif for(ap = ib.b_un.b_indir; ap < &ib.b_un.b_indir[NINDIR]; ap++) { if(*ap) { if(ilevel > 0) n = iblock(*ap,ilevel,flg); else n = (*func)(*ap,0); if(n & STOP && flg != BBLK) return(n); } } return(KEEPON); } #ifdef u370 #undef ib #endif chkblk(blk,flg) register daddr_t blk; { register daddr_t *ap; register ret; int (*func)(), n; daddr_t iaddrs[NADDR]; #ifdef RT register struct i_extent *bp; struct i_extent *sbp; daddr_t blk,eblk; #endif if(SPECIAL) return(KEEPON); l3tol(iaddrs,dp->di_addr,NADDR); switch(flg) { case ADDR: func = pfunc; break; case DATA: func = dirscan; break; case BBLK: func = chkblk; } #ifdef RT if (SEXT || MEXT) { for(bp = sbp = (struct i_extent *)&iaddrs[0]; bp < (struct i_extent *)&iaddrs[2 * N_VEXT]; bp++) { if(bp-ister DIRECT *dirp; register char *ptr; int zerobyte, baddir = 0, dotcnt = 0; if(outrange(blk)) return(SKIP); if(getblk(&fileblk, blk) == NULL) return(SKIP); for(dirp = dirblk; dirp <&dirblk[NDIRECT]; dirp++) { ptr = dirp->d_name; zerobyte = 0; while(ptr <&dirp->d_name[DIRSIZ]) { if(zerobyte && *ptr) { baddir++; break; } if(flg) { if(ptr == &dirp->d_name[0] && *ptr == '.' && *(ptr + 1) == '\0') { dotcnt++; if(inum != dirp->d_ino) { printf("%c %sNO VA>stblk == 0) continue; if(outrange(bp->stblk)) { printf("%c %sCONTIG FILE ERROR EXTENT %d SBLK OUT OF RANGE %ld.\n",id, devname,bp-sbp,sbp->stblk); return(STOP); } if(outrange(bp->stblk + bp->ncblks - 1)) { printf("%c %sCONTIG FILE ERROR EXTENT %d SBLK OUT OF RANGE %ld.\n",id, devname,bp-sbp,bp->stblk+bp->ncblks); return(STOP); } if(bp->stblk > 0){ for(blk = bp->stblk,eblk = blk + bp->ncblks; blk < eblk;blk++) { if((ret = (*func)(blk)) & STOP){ return(reLID '.' in DIR I = %u\n", id,devname,inum); baddir++; } break; } if(ptr == &dirp->d_name[0] && *ptr == '.' && *(ptr + 1) == '.' && *(ptr + 2) == '\0') { dotcnt++; if(!dirp->d_ino) { printf("%c %sNO VALID '..' in DIR I = %u\n", id,devname,inum); baddir++; } break; } } if(*ptr == '/') { baddir++; break; } if(*ptr == NULL) { if(dirp->d_ino && ptr == &dirp->d_name[0]) { baddir++; break; } elst); } } } return(KEEPON); } } #endif for(ap = iaddrs; ap < &iaddrs[NADDR-3]; ap++) { if(*ap && (ret = (*func)(*ap,((ap == &iaddrs[0]) ? 1 : 0))) & STOP) if(flg != BBLK) return(ret); } for(n = 1; n < 4; n++) { if(*ap && (ret = iblock(*ap,n,flg)) & STOP) { if(flg != BBLK) return(ret); } ap++; } return(KEEPON); } iblock(blk,ilevel,flg) daddr_t blk; register ilevel; { register daddr_t *ap; register n; int (*func)(); #ifdef u370 /* For u370, this function's prive zerobyte++; } ptr++; } } if(flg && dotcnt < 2) { printf("%c %sMISSING '.' or '..' in DIR I = %u\n",id,devname,inum); printf("%c %sBLK %ld ",id,devname,blk); pinode(); printf("\n%c %sDIR=%s\n\n",id,devname,pathname); return(YES); } if(baddir) { printf("%c %sBAD DIR ENTRY I = %u\n",id,devname,inum); printf("%c %sBLK %ld ",id,devname,blk); pinode(); printf("\n%c %sDIR=%s\n\n",id,devname,pathname); return(YES); } return(KEEPON); } pass1(blk) register daddr_t blk; { regevname); } else if(reply("FIX") == YES) { superblk.s_tfree = n_free; sbdirty(); } } } if(fixfree) { printf("%c %sBAD FREE LIST",id,devname); if(qflag && !sflag) { fixfree = 1; printf("\n%c %sSALVAGED\n",id,devname); } else if(reply("SALVAGE") == NO) fixfree = 0; } } #endif if(fixfree) { printf("%c %s** Phase 6 - Salvage Free List\n",id,devname); makefree(); n_free = superblk.s_tfree; } printf("%c %s%ld files %ld blocks %ld free\n",id,devnamate BUFAREA must be * allocated via sbrk to avoid base register problems. * To prevent multiple allocations, but to allow * 3-level recursive calls, a static array of BUFAREA * pointers is defined. */ #define ib (*ibp[ilevel]) static BUFAREA *ibp[3] = {NULL,NULL,NULL}; #else BUFAREA ib; #endif if(flg == BBLK) func = chkblk; else if(flg == ADDR) { func = pfunc; if(((n = (*func)(blk)) & KEEPON) == 0) return(n); } else func = dirscan; if(outrange(blk)) /* protect thyself */ returister daddr_t *dlp; if(outrange(blk)) { blkerr("BAD",blk); if(++badblk >= MAXBAD) { printf("%c %sEXCESSIVE BAD BLKS I=%u",id,devname,inum); if(reply("CONTINUE") == NO) errexit(""); return(STOP); } return(SKIP); } if(getbmap(blk)) { blkerr("DUP",blk); if(++dupblk >= MAXDUP) { printf("%c %sEXCESSIVE DUP BLKS I=%u",id,devname,inum); if(reply("CONTINUE") == NO) errexit(""); return(STOP); } if(enddup >= &duplist[DUPTBLSIZE]) { printf("%c %sDUP TABLE OVERFLOW.",id,EEPON); } pass5(blk) register daddr_t blk; { if(outrange(blk)) { fixfree = 1; if(++badblk >= MAXBAD) { printf("%c %sEXCESSIVE BAD BLKS IN FREE LIST.",id,devname); if(reply("CONTINUE") == NO) errexit(""); return(STOP); } return(SKIP); } if(getfmap(blk)) { fixfree = 1; if(++dupblk >= DUPTBLSIZE) { printf("%c %sEXCESSIVE DUP BLKS IN FREE LIST.",id,devname); if(reply("CONTINUE") == NO) errexit(""); return(STOP); } } else { n_free++; setfmap(blk); /* *savep |=devname); if(reply("CONTINUE") == NO) errexit(""); return(STOP); } for(dlp = duplist; dlp < muldup; dlp++) { if(*dlp == blk) { *enddup++ = blk; break; } } if(dlp >= muldup) { *enddup++ = *muldup; *muldup++ = blk; } } else { n_blks++; setbmap(blk); /* *savep |= saven;*/ } filsize++; return(KEEPON); } pass1b(blk) register daddr_t blk; { register daddr_t *dlp; if(outrange(blk)) return(SKIP); for(dlp = duplist; dlp < muldup; dlp++) { if(*dlp == blk) { saven;*/ } return(KEEPON); } blkerr(s,blk) daddr_t blk; char *s; { printf("%c %s%ld %s I=%u\n",id,devname,blk,s,inum); setstate(CLEAR); /* mark for possible clearing */ } descend() { register DINODE *dp; register char *savname; off_t savsize; setstate(FSTATE); if((dp = ginode()) == NULL) return; if(Dirc && !pss2done) ckinode(dp,BBLK); savname = thisname; *pathp++ = '/'; savsize = filsize; filsize = dp->di_size; ckinode(dp,DATA); thisname = savname; *--pathp = 0; filsize = savsize blkerr("DUP",blk); *dlp = *--muldup; *muldup = blk; return(muldup == duplist ? STOP : KEEPON); } } return(KEEPON); } pass2(dirp) register DIRECT *dirp; { register char *p; register n; register DINODE *dp; if((inum = dirp->d_ino) == 0) return(KEEPON); thisname = pathp; if((&pathname[MAXPATH] - pathp) < DIRSIZ) { if((&pathname[MAXPATH] - pathp) < strlen(dirp->d_name)) { printf("%c %sDIR pathname too deep\n",id,devname); printf("%c %sIncrease MAXPATH and recompile.\n", id,; } dirscan(blk) register daddr_t blk; { register DIRECT *dirp; register char *p1, *p2; register n; DIRECT direntry; if(outrange(blk)) { filsize -= BSIZE; return(SKIP); } for(dirp = dirblk; dirp < &dirblk[NDIRECT] && filsize > 0; dirp++, filsize -= sizeof(DIRECT)) { if(getblk(&fileblk,blk) == NULL) { filsize -= (&dirblk[NDIRECT]-dirp)*sizeof(DIRECT); return(SKIP); } p1 = &dirp->d_name[DIRSIZ]; p2 = &direntry.d_name[DIRSIZ]; while(p1 > (char *)dirp) *--p2 = *--p1; if((n =devname); printf("%c %sDIR pathname is <%s>\n", id,devname,pathname); ckfini(); exit(4); } } for(p = dirp->d_name; p < &dirp->d_name[DIRSIZ]; ) if((*pathp++ = *p++) == 0) { --pathp; break; } *pathp = 0; n = NO; if(inum > imax || inum < ROOTINO) n = direrr("I OUT OF RANGE"); else { again: switch(getstate()) { case USTATE: n = direrr("UNALLOCATED"); break; case CLEAR: if((n = direrr("DUP/BAD")) == YES) break; if((dp = ginode()) == NULL) break; (*pfunc)(&direntry)) & ALTERD) { if(getblk(&fileblk,blk) != NULL) { p1 = &dirp->d_name[DIRSIZ]; p2 = &direntry.d_name[DIRSIZ]; while(p1 > (char *)dirp) *--p1 = *--p2; fbdirty(); } else n &= ~ALTERD; } if(n & STOP) return(n); } return(filsize > 0 ? KEEPON : STOP); } direrr(s) char *s; { register DINODE *dp; int n; printf("%c %s%s ",id,devname,s); pinode(); if((dp = ginode()) != NULL && ftypeok(dp)) { printf("\n%c %s%s=%s",id,devname,DIR?"DIR":"FILE",pathn setstate(DIR ? DSTATE : FSTATE); goto again; case FSTATE: declncnt(); break; case DSTATE: declncnt(); descend(); } } pathp = thisname; if(n == NO) return(KEEPON); dirp->d_ino = 0; return(KEEPON|ALTERD); } pass4(blk) register daddr_t blk; { register daddr_t *dlp; if(outrange(blk)) return(SKIP); if(getbmap(blk)) { for(dlp = duplist; dlp < enddup; dlp++) if(*dlp == blk) { *dlp = *--enddup; return(KEEPON); } clrbmap(blk); n_blks--; } return(Kame); if(DIR) { if(dp->di_size > EMPT) { if((n = chkempt(dp)) == NO) { printf(" (NOT EMPTY)\n"); } else if(n != SKIP) { printf(" (EMPTY)"); if(!nflag) { printf(" -- REMOVED\n"); return(YES); } else printf("\n"); } } else { printf(" (EMPTY)"); if(!nflag) { printf(" -- REMOVED\n"); return(YES); } else printf("\n"); } } else if(REG) if(!dp->di_size) { printf(" (EMPTY)"); if(!nflag) { prinnodirty(); } chkempt(dp) register DINODE *dp; { register daddr_t *ap; register DIRECT *dirp; daddr_t blk[NADDR]; int size; size = minsz(dp->di_size, (NADDR - 3) * BSIZE); l3tol(blk,dp->di_addr,NADDR); for(ap = blk; ap < &blk[NADDR - 3], size > 0; ap++) { if(*ap) { if(outrange(*ap)) { printf("chkempt: blk %d out of range\n",*ap); return(SKIP); } if(getblk(&fileblk,*ap) == NULL) { printf("chkempt: Can't find blk %d\n",*ap); return(SKIP); } for(dirp=dirblk; dirp < &dir invalid blk num */ #ifdef RT fbmap = (daddr_t)superblk.s_isize; bmapsz = roundup(howmany((fmax - fbmap),BITSPB),BSIZE); fmin = (daddr_t)superblk.s_isize + howmany(roundup((daddr_t)bmapsz,BSIZE),BSIZE); #else fmin = (daddr_t)superblk.s_isize; bmapsz = roundup(howmany(fmax,BITSPB),sizeof(*lncntp)); #endif if(fmin >= fmax || (imax/INOPB) != ((ino_t)superblk.s_isize-(SUPERB+1))) { error("%c %sSize check: fsize %ld isize %d\n",id,devname, superblk.s_fsize,superblk.s_isize); ckfini(); retutf(" -- REMOVED\n"); return(YES); } else printf("\n"); } } else { printf("\n%c %sNAME=%s",id,devname,pathname); if(!dp->di_size) { printf(" (EMPTY)"); if(!nflag) { printf(" -- REMOVED\n"); return(YES); } else printf("\n"); } else printf(" (NOT EMPTY)\n"); } return(reply("REMOVE")); } adjust(lcnt) register short lcnt; { register DINODE *dp; register n; if((dp = ginode()) == NULL) return; if(dp->di_nlink == lcnt) { if((n = linkup()) == NO)blk[NDIRECT], size > 0; dirp++) { if(dirp->d_name[0] == '.' && (dirp->d_name[1] == '\0' || ( dirp->d_name[1] == '.' && dirp->d_name[2] == '\0'))) { size -= sizeof(DIRECT); continue; } if(dirp->d_ino) return(NO); size -= sizeof(DIRECT); } } } if(size <= 0) return(YES); else return(NO); } setup(dev) char *dev; { register n; register BUFAREA *bp; register MEMSIZE msize; char *mbase; daddr_t bcnt, nscrblk; dev_t rootdev; extern dev_t pipedev; /* non- clri("UNREF",NO); if(n == REM) clri("UNREF",REM); } else { printf("%c %sLINK COUNT %s",id,devname, (lfdir==inum)?lfname:(DIR?"DIR":"FILE")); pinode(); printf("\n%c %sCOUNT %d SHOULD BE %d",id,devname, dp->di_nlink,dp->di_nlink-lcnt); if(reply("ADJUST") == YES) { dp->di_nlink -= lcnt; inodirty(); } } } clri(s,flg) char *s; { register DINODE *dp; int n; if((dp = ginode()) == NULL) return; if(flg == YES) { if(!FIFO || !qflag || nflag) { printf("%c %s%s %s",id,devzero iff standard input is a pipe, * which means we can't check pipedev */ off_t smapsz, lncntsz, totsz; struct { daddr_t tfree; ino_t tinode; char fname[6]; char fpack[6]; } ustatarea; struct stat statarea; if(stat("/",&statarea) < 0) errexit("%c %sCan't stat root\n",id,devname); rootdev = statarea.st_dev; if(stat(dev,&statarea) < 0) { error("%c %sCan't stat %s\n",id,devname,dev); return(NO); } hotroot = 0; rawflg = 0; if((statarea.st_mode & S_IFMT) == S_IFBLK) { if(rootdevname,s,DIR?"DIR":"FILE"); pinode(); } if(DIR) { if(dp->di_size > EMPT) { if((n = chkempt(dp)) == NO) { printf(" (NOT EMPTY)\n"); } else if(n != SKIP) { printf(" (EMPTY)"); if(!nflag) { printf(" -- REMOVED\n"); clrinode(dp); return; } else printf("\n"); } } else { printf(" (EMPTY)"); if(!nflag) { printf(" -- REMOVED\n"); clrinode(dp); return; } else printf("\n"); } } if(REG) if(!dp-> == statarea.st_rdev) hotroot++; else if(ustat(statarea.st_rdev,&ustatarea) >= 0) { if(!nflag) { error("%c %s%s is a mounted file system, ignored\n", id,devname,dev); return(NO); } hotroot++; } if ( pipedev == statarea.st_rdev ) { error( "%c %s%s is pipedev, ignored", id, devname, dev); return(NO); } } else if((statarea.st_mode & S_IFMT) == S_IFCHR) rawflg++; else { error("%c %s%s is not a block or character device\n",id,devname,dev); return(NO); } printdi_size) { printf(" (EMPTY)"); if(!nflag) { printf(" -- REMOVED\n"); clrinode(dp); return; } else printf("\n"); } else printf(" (NOT EMPTY)\n"); if (FIFO && !nflag) { if(!qflag) printf(" -- CLEARED"); printf("\n"); clrinode(dp); return; } } if(flg == REM) clrinode(dp); else if(reply("CLEAR") == YES) clrinode(dp); } clrinode(dp) /* quietly clear inode */ register DINODE *dp; { n_files--; pfunc = pass4; ckinode(dp,ADDR); zapino(dp); if("\n%c %s",id,dev); if((nflag && !csflag) || (dfile.wfdes == -1)) printf(" (NO WRITE)"); printf("\n"); pss2done = 0; fixfree = 0; dfile.mod = 0; n_files = n_blks = n_free = 0; muldup = enddup = &duplist[0]; badlnp = &badlncnt[0]; lfdir = 0; rplyflag = 0; initbarea(&fileblk); initbarea(&inoblk); sfile.wfdes = sfile.rfdes = -1; rmscr = 0; if(getblk(&sblk,SUPERB) == NULL) { ckfini(); return(NO); } imax = ((ino_t)superblk.s_isize - (SUPERB+1)) * INOPB; fmax = superblk.s_fsize; /* first dirty(bp); flush(&sfile,bp); } blkmap = freemap = statemap = (char *) NULL; lncntp = (short *) NULL; smapblk = bmapsz / BSIZE; lncntblk = smapblk + smapsz / BSIZE; fmapblk = smapblk; } else { if(rawflg && (off_t)msize > totsz+BSIZE) { niblk += (unsigned)((off_t)msize-totsz)>>BSHIFT; #if FsTYPE==2 if(niblk > MAXRAW / 2) niblk = MAXRAW / 2; #else if(niblk > MAXRAW) niblk = MAXRAW; #endif msize = memsize - (niblk*BSIZE); mbase = membase + (niblk*BSIZE); } poolhea*p == 0) return; if (*(p+1) == 0) { if (*p == '3') { cylsize = 200; stepsize = 5; return; } if (*p == '4') { cylsize = 418; stepsize = 7; return; } } cylsize = atoi(p); while(*p && *p != ':') p++; if(*p) p++; stepsize = atoi(p); if(stepsize <= 0 || stepsize > cylsize || cylsize <= 0 || cylsize > MAXCYL) { error("%c %sInvalid -s argument, defaults assumed\n",id,devname); cylsize = stepsize = 0; } } dostate(s,flg) { register char *p; register unsigned byte, shid = NULL; blkmap = mbase; statemap = &mbase[(MEMSIZE)bmapsz]; freemap = statemap; lncntp = (short *)&statemap[(MEMSIZE)smapsz]; } return(YES); } checksb(dev) char *dev; { if((dfile.rfdes = open(dev,0)) < 0) { error("%c %sCan't open %s\n",id,devname,dev); return(NO); } if((dfile.wfdes = open(dev,1)) < 0) dfile.wfdes = -1; if(getblk(&sblk,SUPERB) == NULL) { ckfini(); return(NO); } return(YES); } DINODE * ginode() { register DINODE *dp; register char *mbase; register daddr_t iblk;ft; BUFAREA *bp; byte = ((unsigned)inum)/STATEPB; shift = LSTATE * (((unsigned)inum)%STATEPB); if(statemap != NULL) { bp = NULL; p = &statemap[byte]; } else if((bp = getblk(NULL,smapblk+(byte/BSIZE))) == NULL) errexit("%c %sFatal I/O error\n",id,devname); else p = &bp->b_un.b_buf[byte%BSIZE]; switch(flg) { case 0: *p &= ~(SMASK<<(shift)); *p |= s<<(shift); if(bp != NULL) dirty(bp); return(s); case 1: return((*p>>(shift)) & SMASK); } return(USTATE); } domap(blk,flgrn(NO); } printf("%c %sFile System: %.6s Volume: %.6s\n\n",id,devname, superblk.s_fname,superblk.s_fpack); smapsz = roundup(howmany((long)(imax+1),STATEPB),sizeof(*lncntp)); lncntsz = (long)(imax+1) * sizeof(*lncntp); if(bmapsz > smapsz+lncntsz) smapsz = bmapsz-lncntsz; totsz = bmapsz+smapsz+lncntsz; msize = memsize; mbase = membase; if(rawflg) { if(msize < (MEMSIZE)(NINOBLK*BSIZE) + 2*sizeof(BUFAREA)) rawflg = 0; else { msize -= (MEMSIZE)NINOBLK*BSIZE; mbase += (MEMSIZE)NINOBLK*B if(inum > imax) return(NULL); iblk = itod(inum); if(rawflg) { mbase = membase; if(iblk < startib || iblk >= startib+niblk) { if(inoblk.b_dirty) bwrite(&dfile,mbase,startib,niblk*BSIZE); inoblk.b_dirty = 0; if(bread(&dfile,mbase,iblk,niblk*BSIZE) == NO) { startib = fmax; return(NULL); } startib = iblk; } dp = (DINODE *)&mbase[(unsigned)((iblk-startib)<>BSHIFT; if(tflag == 0) { printf("\n%c %sNEED SCRATCH FILE (%ld BLKS)\n",id,devname,nscrblk); do { printf("%c %sENTER FILENAME:\n",id,devname); if((n = getline(stdin,scrfile,sizeof(scrfile))) == EOF) errexit("\n"); } while(n == 0); } if(stat(sitoo(inum)); } reply(s) char *s; { char line[80]; rplyflag = 1; line[0] = '\0'; printf("\n%c %s%s? ",id,devname,s); if(nflag || dfile.wfdes < 0) { printf(" no\n\n"); return(NO); } if(yflag) { printf(" yes\n\n"); return(YES); } while (line[0] == '\0') { if(getline(stdin,line,sizeof(line)) == EOF) errexit("\n"); printf("\n"); if(line[0] == 'y' || line[0] == 'Y') return(YES); if(line[0] == 'n' || line[0] == 'N') return(NO); printf("%c %sAnswer 'y' or 'n' (yes or no)\n",id,crfile,&statarea) < 0 || (statarea.st_mode & S_IFMT) == S_IFREG) rmscr++; if((sfile.wfdes = creat(scrfile,0666)) < 0 || (sfile.rfdes = open(scrfile,0)) < 0) { error("%c %sCan't create %s\n",id,devname,scrfile); ckfini(); return(NO); } bp = &((BUFAREA *)mbase)[(msize/sizeof(BUFAREA))]; poolhead = NULL; while(--bp >= (BUFAREA *)mbase) { initbarea(bp); bp->b_next = poolhead; poolhead = bp; } bp = poolhead; for(bcnt = 0; bcnt < nscrblk; bcnt++) { bp->b_bno = bcnt; devname); line[0] = '\0'; } return(NO); } getline(fp,loc,maxlen) FILE *fp; char *loc; { register n; register char *p, *lastloc; p = loc; lastloc = &p[maxlen-1]; while((n = getc(fp)) != '\n') { if(n == EOF) return(EOF); if(!isspace(n) && p < lastloc) *p++ = n; } *p = 0; return(p - loc); } #ifndef STANDALONE getno(fp) FILE *fp; { register n; register cnt; cnt = 0; while((n = getc(fp)) != EOF) { if(n == '\n') cnt++; } return(cnt); } #endif stype(p) register char *p; { if(it("%c %sFatal I/O error\n",id,devname); else sp = &bp->b_un.b_lnks[(unsigned)inum%SPERB]; switch(flg) { case 0: *sp = val; break; case 1: bp = NULL; break; case 2: (*sp)--; } if(bp != NULL) dirty(bp); return(*sp); } BUFAREA * getblk(bp,blk) register daddr_t blk; register BUFAREA *bp; { register struct filecntl *fcp; if(bp == NULL) { bp = search(blk); fcp = &sfile; } else fcp = &dfile; if(bp->b_bno == blk) return(bp); if(blk == SUPERB) { flush(fcp,bp); if(lf; *p != ':'; p++); *p = 0; printf("%s ",uidbuf); } else { printf("%d ",dp->di_uid); } printf("MODE=%o\n",dp->di_mode); printf("%c %sSIZE=%ld ",id,devname,dp->di_size); p = ctime(&dp->di_mtime); printf("MTIME=%12.12s %4.4s ",p+4,p+20); } copy(fp,tp,size) register char *tp, *fp; MEMSIZE size; { while(size--) *tp++ = *fp++; } freechk() { register daddr_t *ap; if(freeblk.df_nfree == 0) return; do { if(freeblk.df_nfree <= 0 || freeblk.df_nfree > NICFREE) { printf("%c %sBAD FREEBLKseek(fcp->rfdes,(long)SUPERBOFF,0) < 0) rwerr("SEEK",blk); else if(read(fcp->rfdes,bp->b_un.b_buf,SBSIZE) == SBSIZE) { bp->b_bno = blk; return(bp); } rwerr("READ",blk); bp->b_bno = (daddr_t)-1; return(NULL); } flush(fcp,bp); if(bread(fcp,bp->b_un.b_buf,blk,BSIZE) != NO) { bp->b_bno = blk; return(bp); } bp->b_bno = (daddr_t)-1; return(NULL); } flush(fcp,bp) struct filecntl *fcp; register BUFAREA *bp; { if(bp->b_dirty) { if(bp->b_bno == SUPERB) { if(fcp->wfdes < 0) { b COUNT\n",id,devname); fixfree = 1; return; } ap = &freeblk.df_free[freeblk.df_nfree]; while(--ap > &freeblk.df_free[0]) { if(pass5(*ap) == STOP) return; } if(*ap == (daddr_t)0 || pass5(*ap) != KEEPON) return; } while(getblk(&fileblk,*ap) != NULL); } #ifdef RT makefree() { daddr_t blk; BUFAREA *bp1; BUFAREA *bp2; superblk.s_nfree = 0; superblk.s_flock = 0; superblk.s_fmod = 0; superblk.s_ninode = 0; superblk.s_tfree = fmax - fmin - n_blks; superblk.s_ilock = 0; superbp->b_dirty = 0; return; } if(lseek(fcp->wfdes,(long)SUPERBOFF,0) < 0) rwerr("SEEK",bp->b_bno); else if(write(fcp->wfdes,bp->b_un.b_buf,SBSIZE) == SBSIZE) { fcp->mod = 1; bp->b_dirty = 0; return; } rwerr("WRITE",SUPERB); bp->b_dirty = 0; return; } bwrite(fcp,bp->b_un.b_buf,bp->b_bno,BSIZE); } bp->b_dirty = 0; } rwerr(s,blk) char *s; daddr_t blk; { printf("\n%c %sCAN NOT %s: BLK %ld",id,devname,s,blk); if(reply("CONTINUE") == NO) errexit("%c %sProgram terminlk.s_ronly = 0; superblk.s_cfree = 0; superblk.s_nxtblk = fmin; superblk.s_nxtcon = fmin; chkmn(); superblk.s_dinfo[0] = superblk.s_m; superblk.s_dinfo[1] = superblk.s_n; if(imax - n_files != superblk.s_tinode){ superblk.s_tinode = imax - n_files; } sbdirty(); for(blk = 0; blk < (fmin - fbmap); blk++) { bp1 = getblk(&fileblk,blk + fbmap); if(blkmap) { copy( blkmap + (blk * BSIZE), bp1->b_un.b_buf,BSIZE); }else{ bp2 = getblk(NULL,blk); copy(bp2->b_un.b_buf,bp1->b_un.b_buf,BSIZE);) register daddr_t blk; { register char *p; register unsigned n; register BUFAREA *bp; off_t byte; #ifdef RT /* RT bitmap does not include the boot, super or inode blks */ blk -= superblk.s_isize; #endif byte = blk >> BITSHIFT; n = 1<<((unsigned)(blk & BITMASK)); if(flg & 04) { p = freemap; blk = fmapblk; } else { p = blkmap; blk = 0; } if(p != NULL) { bp = NULL; p += (unsigned)byte; } else if((bp = getblk(NULL,blk+(byte>>BSHIFT))) == NULL) errexit("%c %sFatal I/O error\n",id,ated\n",id,devname); } sizechk(dp) register DINODE *dp; { off_t size, nblks; #ifdef RT if( SEXT || MEXT ) nblks = howmany(dp->di_size,BSIZE); else #endif { size = howmany(dp->di_size,BSIZE); nblks = size; size -= NADDR-3; while(size > 0) { nblks += howmany(size,NINDIR); size--; size /= NINDIR; } } if(!qflag) { if(nblks != filsize) printf("%c %sPOSSIBLE %s SIZE ERROR I=%u\n\n", id,devname,DIR?"DIR":"FILE",inum); if(DIR && (dp->di_size % sizeof(DIRECT)) != 0) printf("%c %sDIRdevname); else p = &bp->b_un.b_buf[(unsigned)(byte&BMASK)]; /* saven = n; savep = p;*/ switch(flg&03) { case 0: /* set */ *p |= n; break; case 1: /* get */ n &= *p; bp = NULL; break; case 2: /* clear */ *p &= ~n; } if(bp != NULL) dirty(bp); return(n); } dolncnt(val,flg) short val; { register short *sp; register BUFAREA *bp; if(lncntp != NULL) { bp = NULL; sp = &lncntp[(unsigned)inum]; } else if((bp = getblk(NULL,lncntblk+((unsigned)inum/SPERB))) == NULL) errexECTORY MISALIGNED I=%u\n\n",id,devname,inum); } } ckfini() { flush(&dfile,&fileblk); flush(&dfile,&sblk); flush(&dfile,&inoblk); close(dfile.rfdes); close(dfile.wfdes); close(sfile.rfdes); close(sfile.wfdes); #ifndef STANDALONE if(rmscr) { unlink(scrfile); } #endif } pinode() { register DINODE *dp; register char *p; char uidbuf[200]; char *ctime(); printf(" I=%u ",inum); if((dp = ginode()) == NULL) return; printf(" OWNER="); if(getpw((int)dp->di_uid,uidbuf) == 0) { for(p = uidbu]; } else { step = stepsize; cyl = cylsize; } if(step > cyl || step <= 0 || cyl <= 0 || cyl > MAXCYL) { error("%c %sDefault free list spacing assumed\n",id,devname); step = STEPSIZE; cyl = CYLSIZE; } superblk.s_dinfo[0] = step; superblk.s_dinfo[1] = cyl; clear(flg,sizeof(flg)); #if FsTYPE==2 step /= 2; cyl /= 2; #endif i = 0; for(j = 0; j < cyl; j++) { while(flg[i]) i = (i + 1) % cyl; addr[j] = i + 1; flg[i]++; i = (i + step) % cyl; } baseblk = (daddr_t)roundup(fmax,cyl); ) { if(dp->di_size > EMPT) { if((n = chkempt(dp)) == NO) { printf(" (NOT EMPTY)"); if(!nflag) { printf(" MUST reconnect\n"); goto connect; } else printf("\n"); } else if(n != SKIP) { printf(" (EMPTY)"); if(!nflag) { printf(" Cleared\n"); return(REM); } else printf("\n"); } } else { printf(" (EMPTY)"); if(!nflag) { printf(" Cleared\n"); return(REM); } else printf("\n"); } } if(REG) if(!dp->di_size) { clear(&freeblk,BSIZE); freeblk.df_nfree++; for( ; baseblk > 0; baseblk -= cyl) for(i = 0; i < cyl; i++) { blk = baseblk - addr[i]; if(!outrange(blk) && !getbmap(blk)) { superblk.s_tfree++; if(freeblk.df_nfree >= NICFREE) { fbdirty(); fileblk.b_bno = blk; flush(&dfile,&fileblk); clear(&freeblk,BSIZE); } freeblk.df_free[freeblk.df_nfree] = blk; freeblk.df_nfree++; } } superblk.s_nfree = freeblk.df_nfree; for(i = 0; i < NICFREE; i++) superblk.s_free[i printf(" (EMPTY)"); if(!nflag) { printf(" Cleared\n"); return(REM); } else printf("\n"); } else printf(" (NOT EMPTY)\n"); if(FIFO && !nflag) { if(!qflag) printf(" -- REMOVED"); printf("\n"); return(REM); } if(FIFO && nflag) return(NO); if(reply("RECONNECT") == NO) return(NO); connect: orphan = inum; if(lfdir == 0) { inum = ROOTINO; if((dp = ginode()) == NULL) { inum = orphan; return(NO); } pfunc = findino; srchname = lfname; filsize = dp->di_] = freeblk.df_free[i]; sbdirty(); } #endif clear(p,cnt) register char *p; MEMSIZE cnt; { while(cnt--) *p++ = 0; } BUFAREA * search(blk) daddr_t blk; { register BUFAREA *pbp, *bp; for(bp = (BUFAREA *) &poolhead; bp->b_next; ) { pbp = bp; bp = pbp->b_next; if(bp->b_bno == blk) break; } pbp->b_next = bp->b_next; bp->b_next = poolhead; poolhead = bp; return(bp); } findino(dirp) register DIRECT *dirp; { register char *p1, *p2; if(dirp->d_ino == 0) return(KEEPON); for(p1 = dirp->size; parentdir = 0; ckinode(dp,DATA); inum = orphan; if((lfdir = parentdir) == 0) { printf("%c %sSORRY. NO lost+found DIRECTORY\n\n",id,devname); return(NO); } } inum = lfdir; if((dp = ginode()) == NULL || !DIR || getstate() != FSTATE) { inum = orphan; printf("%c %sSORRY. NO lost+found DIRECTORY\n\n",id,devname); return(NO); } if(dp->di_size & BMASK) { dp->di_size = roundup(dp->di_size,BSIZE); inodirty(); } filsize = dp->di_size; inum = orphan; pfunc = mkentry; if((ckinod_name,p2 = srchname;*p2++ == *p1; p1++) { if(*p1 == 0 || p1 == &dirp->d_name[DIRSIZ-1]) { if(dirp->d_ino >= ROOTINO && dirp->d_ino <= imax) parentdir = dirp->d_ino; return(STOP); } } return(KEEPON); } mkentry(dirp) register DIRECT *dirp; { register ino_t in; register char *p; if(dirp->d_ino) return(KEEPON); dirp->d_ino = orphan; in = orphan; p = &dirp->d_name[DIRSIZ]; while(p != &dirp->d_name[6]) *--p = 0; while(p > dirp->d_name) { *--p = (in % 10) + '0'; in /= 10; } rede(dp,DATA) & ALTERD) == 0) { printf("%c %sSORRY. NO SPACE IN lost+found DIRECTORY\n\n",id,devname); return(NO); } declncnt(); if((dp = ginode()) && !dp->di_nlink) { dp->di_nlink++; inodirty(); setlncnt(getlncnt()+1); if(lostdir) { for(blp = badlncnt; blp < badlnp; blp++) if(*blp == inum) { *blp = 0L; break; } } } if(lostdir) { pfunc = chgdd; filsize = dp->di_size; ckinode(dp,DATA); inum = lfdir; if((dp = ginode()) != NULL) { dp->di_nlink++; inodirty() } dirty(bp1); } } #else makefree() { register i, cyl, step; int j; char flg[MAXCYL]; short addr[MAXCYL]; daddr_t blk, baseblk; superblk.s_nfree = 0; #ifdef u370 superblk.s_flock.sema_align = 0; #else superblk.s_flock = 0; #endif superblk.s_fmod = 0; superblk.s_tfree = 0; superblk.s_ninode = 0; #ifdef u370 superblk.s_ilock.sema_align = 0; #else superblk.s_ilock = 0; #endif superblk.s_ronly = 0; if(cylsize == 0 || stepsize == 0) { step = superblk.s_dinfo[0]; cyl = superblk.s_dinfo[1turn(ALTERD|STOP); } chgdd(dirp) register DIRECT *dirp; { if(dirp->d_name[0] == '.' && dirp->d_name[1] == '.' && dirp->d_name[2] == 0) { dirp->d_ino = lfdir; return(ALTERD|STOP); } return(KEEPON); } linkup() { register DINODE *dp; register lostdir; register ino_t pdir; register ino_t *blp; int n; if((dp = ginode()) == NULL) return(NO); lostdir = DIR; pdir = parentdir; if(!FIFO || !qflag || nflag) { printf("%c %sUNREF %s ",id,devname,lostdir ? "DIR" : "FILE"); pinode(); } if(DIR; setlncnt(getlncnt()+1); } inum = orphan; printf("%c %sDIR I=%u CONNECTED. ",id,devname,orphan); printf("%c %sPARENT WAS I=%u\n\n",id,devname,pdir); } return(YES); } bread(fcp,buf,blk,size) daddr_t blk; register struct filecntl *fcp; register MEMSIZE size; char *buf; { if(lseek(fcp->rfdes,blk<rfdes,buf,size) == size) return(YES); rwerr("READ",blk); return(NO); } bwrite(fcp,buf,blk,size) daddr_t blk; register struct filecntl *fcp;./usr/src/cmd/stty.c 664 2 2 36030 5555202605 7510 register MEMSIZE size; char *buf; { if(fcp->wfdes < 0) return(NO); if(lseek(fcp->wfdes,blk<wfdes,buf,size) == size) { fcp->mod = 1; return(YES); } rwerr("WRITE",blk); return(NO); } #ifndef STANDALONE catch() { ckfini(); exit(4); } #endif #ifdef RT chkmap() { BUFAREA *bp1,*bp2; register char *ap; register char *bp; daddr_t blk; register i; for(blk = 0 ;blk < (fmin - fbmap);blk++ ) { bp1 = getblk(&fileblk,blk + fbmap);/* ******************************************************************************** * Copyright (c) 1985 AT&T * * All Rights Reserved * * * * * * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T * * The copyright ap = bp1->b_un.b_buf; if(freemap) { bp = freemap + (blk * BSIZE); }else{ bp2 = getblk(NULL,blk+fmapblk); bp = &bp2->b_un.b_buf[0]; } for(i = 0; i < BSIZE; i++) { if(*ap++ != *bp++) { return(2); } } } return(0); } chkmn() { if(superblk.s_m == 0) { error("s_m = 0: reset to %d\n",S_M); superblk.s_m = S_M; sbdirty(); } if(superblk.s_n == 0) { error("s_n = 0: reset to %d\n",S_N); superblk.s_n = S_N; sbdirty(); } } #endif #ifdef u370 #include #notice above does not evidence any actual * * or intended publication of such source code. * ******************************************************************************** */ /* @(#)stty.c 1.6 */ #include "stdio.h" #include "sys/types.h" #include "sys/termio.h" #include "sys/stermio.h" #define ASYNC 0 #define SYNC 1 extern char *getenv(); struct { char *string; int speed; } speeds[] = { "0", B0, "50", B50, "75", B75, "110", B110, "134", B134, "134.5define TSS "/dev/tss" #define CONSOLE "/dev/console" reboot() { struct utsname utsname; char *ssn, *name, *ttyname(), *strchr(), *strrchr(); char *bootarg, bootstr[100], *s; FILE *f, *fopen(); printf("%c %sOK -- I am rebooting the system...\n",id,devname); sleep(5); uname(&utsname); ssn = utsname.sysname; if ((s = strchr(ssn, ' ')) != NULL) *s = '\0'; name = ttyname(0); if (!strcmp(name, CONSOLE)) bootarg = NULL; else bootarg = name; sprintf(bootstr, "TERMSUB %s; INITSUB %s%c%s\n", s",B134, "150", B150, "200", B200, "300", B300, "600", B600, "1200", B1200, "1800", B1800, "2400", B2400, "4800", B4800, "9600", B9600, "exta", EXTA, "extb", EXTB, 0, }; struct mds { char *string; int set; int reset; }; struct mds cmodes[] = { "-parity", CS8, PARENB|CSIZE, "-evenp", CS8, PARENB|CSIZE, "-oddp", CS8, PARENB|PARODD|CSIZE, "parity", PARENB|CS7, PARODD|CSIZE, "evenp", PARENB|CS7, PARODD|CSIZE, "oddp", PARENB|PARODD|CS7, CSIZE, "parenb", PARENB, 0, "-parenb", 0, PARENB, "psn, ssn, bootarg==NULL?'\0':',',strrchr(bootarg, '/')+1); if (fputs(bootstr, stdout) == EOF) abort("Could not write to stdout!?!"); if ((f = fopen(TSS, "w")) <= (FILE *)0) abort("Cannot open TSS!"); if (fputs(bootstr, f) == EOF) abort("Write error to TSS!"); fclose(f); } #endif ); ssn = utsname.sysname; if ((s = strchr(ssn, ' ')) != NULL) *s = '\0'; name = ttyname(0); if (!strcmp(name, CONSOLE)) bootarg = NULL; else bootarg = name; sprintf(bootstr, "TERMSUB %s; INITSUB %s%c%s\n", sarodd", PARODD, 0, "-parodd", 0, PARODD, "cs8", CS8, CSIZE, "cs7", CS7, CSIZE, "cs6", CS6, CSIZE, "cs5", CS5, CSIZE, "cstopb", CSTOPB, 0, "-cstopb", 0, CSTOPB, "hupcl", HUPCL, 0, "hup", HUPCL, 0, "-hupcl", 0, HUPCL, "-hup", 0, HUPCL, "clocal", CLOCAL, 0, "-clocal", 0, CLOCAL, #ifndef pdp11 "loblk", LOBLK, 0, "-loblk", 0, LOBLK, #endif "cread", CREAD, 0, "-cread", 0, CREAD, "raw", CS8, (CSIZE|PARENB), "-raw", (CS7|PARENB), CSIZE, "cooked", (CS7|PARENB), CSIZE, "sane", (CS7|PARENB|CREAD),",0, OCRNL, "onocr", ONOCR, 0, "-onocr", 0, ONOCR, "onlret", ONLRET, 0, "-onlret", 0, ONLRET, "fill", OFILL, OFDEL, "-fill", 0, OFILL|OFDEL, "nul-fill", OFILL, OFDEL, "del-fill", OFILL|OFDEL, 0, "ofill", OFILL, 0, "-ofill", 0, OFILL, "ofdel", OFDEL, 0, "-ofdel", 0, OFDEL, "cr0", CR0, CRDLY, "cr1", CR1, CRDLY, "cr2", CR2, CRDLY, "cr3", CR3, CRDLY, "tab0", TAB0, TABDLY, "tabs", TAB0, TABDLY, "tab1", TAB1, TABDLY, "tab2", TAB2, TABDLY, "tab3", TAB3, TABDLY, "-tabs", TAB3, TABDLY, "nl0", "swtch") && --argc) cb.c_cc[VSWTCH] = gct(*++argv); #endif else if (eq("ek")) { cb.c_cc[VERASE] = CERASE; cb.c_cc[VKILL] = CKILL; } else if (eq("line") && --argc) cb.c_line = atoi(*++argv); else if (eq("raw")) { cb.c_cc[VMIN] = 1; cb.c_cc[VTIME] = 1; } else if (eq("-raw") | eq("cooked")) { cb.c_cc[VEOF] = CEOF; cb.c_cc[VEOL] = CNUL; } else if(eq("sane")) { cb.c_cc[VERASE] = CERASE; cb.c_cc[VKILL] = CKILL; cb.c_cc[VQUIT] = CQUIT; cb.c_cc (CSIZE|PARODD|CLOCAL), 0 }; struct mds imodes[] = { "ignbrk", IGNBRK, 0, "-ignbrk", 0, IGNBRK, "brkint", BRKINT, 0, "-brkint", 0, BRKINT, "ignpar", IGNPAR, 0, "-ignpar", 0, IGNPAR, "parmrk", PARMRK, 0, "-parmrk", 0, PARMRK, "inpck", INPCK, 0, "-inpck", 0,INPCK, "istrip", ISTRIP, 0, "-istrip", 0, ISTRIP, "inlcr", INLCR, 0, "-inlcr", 0, INLCR, "igncr", IGNCR, 0, "-igncr", 0, IGNCR, "icrnl", ICRNL, 0, "-icrnl", 0, ICRNL, "-nl", ICRNL, (INLCR|IGNCR), "nl", 0, ICRNL, "iuclc", IUCLC, 0, "NL0, NLDLY, "nl1", NL1, NLDLY, "ff0", FF0, FFDLY, "ff1", FF1, FFDLY, "vt0", VT0, VTDLY, "vt1", VT1, VTDLY, "bs0", BS0, BSDLY, "bs1", BS1, BSDLY, "raw", 0, OPOST, "-raw", OPOST, 0, "cooked", OPOST, 0, "tty33", CR1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY), "tn300", CR1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY), "ti700", CR2, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY), "vt05", NL1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY), "tek", FF1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY), "tty37", (FF1|VT1|CR2|TAB1|NL-iuclc", 0, IUCLC, "lcase", IUCLC, 0, "-lcase", 0, IUCLC, "LCASE", IUCLC, 0, "-LCASE", 0, IUCLC, "ixon", IXON, 0, "-ixon", 0, IXON, "ixany", IXANY, 0, "-ixany", 0, IXANY, "ixoff", IXOFF, 0, "-ixoff", 0, IXOFF, "raw", 0, -1, "-raw", (BRKINT|IGNPAR|ISTRIP|ICRNL|IXON), 0, "cooked", (BRKINT|IGNPAR|ISTRIP|ICRNL|IXON), 0, "sane", (BRKINT|IGNPAR|ISTRIP|ICRNL|IXON), (IGNBRK|PARMRK|INPCK|INLCR|IGNCR|IUCLC|IXOFF), 0 }; struct mds lmodes[] = { "isig", ISIG, 0, "-isig", 0, ISIG, "icanon", ICANON, 01), (NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY), "sane", (OPOST|ONLCR), (OLCUC|OCRNL|ONOCR|ONLRET|OFILL|OFDEL| NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY), 0, }; char *arg; int match; char *STTY="stty: "; char *USAGE="usage: stty [-ag] [modes]\n"; int pitt = 0; struct termio cb; struct stio stio; int term; main(argc, argv) char *argv[]; { register i; char *ptr; if(ioctl(0, STGET, &stio) == -1) { term = ASYNC; if(ioctl(0, TCGETA, &cb) == -1) { perror(STTY); exit(2); } } else { term = SYNC; , "-icanon", 0, ICANON, "xcase", XCASE, 0, "-xcase", 0, XCASE, "lcase", XCASE, 0, "-lcase", 0, XCASE, "LCASE", XCASE, 0, "-LCASE", 0, XCASE, "echo", ECHO, 0, "-echo", 0, ECHO, "echoe", ECHOE, 0, "-echoe", 0, ECHOE, "echok", ECHOK, 0, "-echok", 0, ECHOK, "lfkc", ECHOK, 0, "-lfkc", 0, ECHOK, "echonl", ECHONL, 0, "-echonl", 0, ECHONL, "noflsh", NOFLSH, 0, "-noflsh", 0, NOFLSH, "raw", 0, (ISIG|ICANON|XCASE), "-raw", (ISIG|ICANON), 0, "cooked", (ISIG|ICANON), 0, "sane", (ISIG|ICANON|ECHO|Ecb.c_cc[7] = stio.tab; cb.c_lflag = stio.lmode; cb.c_oflag = stio.omode; cb.c_iflag = stio.imode; } if (argc == 1) { prmodes(); exit(0); } if ((argc == 2) && (argv[1][0] == '-') && (argv[1][2] == '\0')) switch(argv[1][1]) { case 'a': pramodes(); exit(0); case 'g': prencode(); exit(0); default: fprintf(stderr, "%s", USAGE); exit(2); } while(--argc > 0) { arg = *++argv; match = 0; if (term == ASYNC) { if (eq("erase") && --argc) cb.c_cc[VERASE] = gct(*++aCHOK), (XCASE|ECHOE|ECHONL|NOFLSH|STFLUSH|STWRAP|STAPPL), "stflush", STFLUSH, 0, "-stflush", 0, STFLUSH, "stwrap", STWRAP, 0, "-stwrap", 0, STWRAP, "stappl", STAPPL, 0, "-stappl", 0, STAPPL, 0, }; struct mds omodes[] = { "opost", OPOST, 0, "-opost", 0, OPOST, "olcuc", OLCUC, 0, "-olcuc", 0, OLCUC, "lcase", OLCUC, 0, "-lcase", 0, OLCUC, "LCASE", OLCUC, 0, "-LCASE", 0, OLCUC, "onlcr", ONLCR, 0, "-onlcr", 0, ONLCR, "-nl", ONLCR, (OCRNL|ONLRET), "nl", 0, ONLCR, "ocrnl", OCRNL, 0, "-ocrnlrgv); else if (eq("intr") && --argc) cb.c_cc[VINTR] = gct(*++argv); else if (eq("quit") && --argc) cb.c_cc[VQUIT] = gct(*++argv); else if (eq("eof") && --argc) cb.c_cc[VEOF] = gct(*++argv); else if (eq("min") && --argc) cb.c_cc[VMIN] = gct(*++argv); else if (eq("eol") && --argc) cb.c_cc[VEOL] = gct(*++argv); else if (eq("time") && --argc) cb.c_cc[VTIME] = gct(*++argv); else if (eq("kill") && --argc) cb.c_cc[VKILL] = gct(*++argv); #ifndef pdp11 else if (eq({ register m; if (term == SYNC) { m = stio.imode; if (m & IUCLC) printf ("iuclc "); else printf ("-iuclc "); m = stio.omode; if (m & OLCUC) printf ("olcuc "); else printf ("-olcuc "); if (m & TAB3) printf ("tab3 "); m = stio.lmode; if (m & XCASE) printf ("xcase "); else printf ("-xcase "); if (m & STFLUSH) printf ("stflush "); else printf ("-stflush "); if (m & STWRAP) printf ("stwrap "); else printf ("-stwrap "); if (m & STAPPL) printf ("stappl "); else printf ("-stappl ")/TAB1, "tab"); delay((m&BSDLY)/BS1, "bs"); delay((m&VTDLY)/VT1, "vt"); delay((m&FFDLY)/FF1, "ff"); } printf("\n"); m = cb.c_lflag; if (!(m&ISIG)) printf("-isig "); if (!(m&ICANON)) printf("-icanon "); if (m&XCASE) printf("xcase "); printf("-echo "+((m&ECHO)!=0)); printf("-echoe "+((m&ECHOE)!=0)); printf("-echok "+((m&ECHOK)!=0)); if (m&ECHONL) printf("echonl "); if (m&NOFLSH) printf("noflsh "); printf("\n"); } } pramodes() { register m; if(term == ASYNC) { ); printf ("\n"); } if (term == ASYNC) { m = cb.c_cflag; prspeed("speed ", m&CBAUD); if (m&PARENB) if (m&PARODD) printf("oddp "); else printf("evenp "); else printf("-parity "); if(((m&PARENB) && !(m&CS7)) || (!(m&PARENB) && !(m&CS8))) printf("cs%c ",'5'+(m&CSIZE)/CS6); if (m&CSTOPB) printf("cstopb "); if (m&HUPCL) printf("hupcl "); if (!(m&CREAD)) printf("cread "); if (m&CLOCAL) printf("clocal "); #ifndef pdp11 if (m&LOBLK) printf("loblk"); #endif prspeed("speed ", cb.c_cflag&CBAUD); printf("line = %d; ", cb.c_line); pit(cb.c_cc[VINTR], "intr", "; "); pit(cb.c_cc[VQUIT], "quit", "; "); pit(cb.c_cc[VERASE], "erase", "; "); pit(cb.c_cc[VKILL], "kill", "; "); pit(cb.c_cc[VEOF], "eof", "; "); pit(cb.c_cc[VEOL], "eol", "; "); #ifndef pdp11 pit(cb.c_cc[VSWTCH], "swtch", "\n"); #endif } else pit(stio.tab, "ctab", "\n"); m = cb.c_cflag; printf("-parenb "+((m&PARENB)!=0)); printf("-parodd "+((m&PARODD)!=0)); printf("cs%c ",'5'+(m&CSIZ[VINTR] = CINTR; cb.c_cc[VEOF] = CEOF; cb.c_cc[VEOL] = CNUL; #ifndef pdp11 cb.c_cc[VSWTCH] = CNUL; #endif } for(i=0; speeds[i].string; i++) if(eq(speeds[i].string)) { cb.c_cflag &= ~CBAUD; cb.c_cflag |= speeds[i].speed&CBAUD; } } if (term == SYNC && eq("ctab") && --argc) cb.c_cc[7] = gct(*++argv); for(i=0; imodes[i].string; i++) if(eq(imodes[i].string)) { cb.c_iflag &= ~imodes[i].reset; cb.c_iflag |= imodes[i].set; } for(i=0; omodes[i].string; i++ printf("\n"); if(cb.c_line != 0) printf("line = %d; ", cb.c_line); if(cb.c_cc[VINTR] != CINTR) pit(cb.c_cc[VINTR], "intr", "; "); if(cb.c_cc[VQUIT] != CQUIT) pit(cb.c_cc[VQUIT], "quit", "; "); if(cb.c_cc[VERASE] != CERASE) pit(cb.c_cc[VERASE], "erase", "; "); if(cb.c_cc[VKILL] != CKILL) pit(cb.c_cc[VKILL], "kill", "; "); if(cb.c_cc[VEOF] != CEOF) pit(cb.c_cc[VEOF], "eof", "; "); if(cb.c_cc[VEOL] != CNUL) pit(cb.c_cc[VEOL], "eol", "; "); #ifndef pdp11 if(cb.c_cc[VSWTCH]) if(eq(omodes[i].string)) { cb.c_oflag &= ~omodes[i].reset; cb.c_oflag |= omodes[i].set; } if(term == SYNC && eq("sane")) cb.c_oflag |= TAB3; for(i=0; cmodes[i].string; i++) if(eq(cmodes[i].string)) { cb.c_cflag &= ~cmodes[i].reset; cb.c_cflag |= cmodes[i].set; } for(i=0; lmodes[i].string; i++) if(eq(lmodes[i].string)) { cb.c_lflag &= ~lmodes[i].reset; cb.c_lflag |= lmodes[i].set; } if(!match) if(!encode(arg)) { fprintf(stderr, "unknown mode: %s\n != CSWTCH) pit(cb.c_cc[VSWTCH], "swtch", "; "); #endif if(pitt) printf("\n"); m = cb.c_iflag; if (m&IGNBRK) printf("ignbrk "); else if (m&BRKINT) printf("brkint "); if (!(m&INPCK)) printf("-inpck "); else if (m&IGNPAR) printf("ignpar "); if (m&PARMRK) printf("parmrk "); if (!(m&ISTRIP)) printf("-istrip "); if (m&INLCR) printf("inlcr "); if (m&IGNCR) printf("igncr "); if (m&ICRNL) printf("icrnl "); if (m&IUCLC) printf("iuclc "); if (!(m&IXON)) pr", arg); exit(2); } } if (term == ASYNC) { if(ioctl(0, TCSETAW, &cb) == -1) { perror(STTY); exit(2); } } else { stio.imode = cb.c_iflag; stio.omode = cb.c_oflag; stio.lmode = cb.c_lflag; stio.tab = cb.c_cc[7]; if (ioctl(0, STSET, &stio) == -1) { perror (STTY); exit(2); } } exit(0); } eq(string) char *string; { register i; if(!arg) return(0); i = 0; loop: if(arg[i] != string[i]) return(0); if(arg[i++] != '\0') goto loop; match++; return(1); } prmodes() intf("-ixon "); else if (!(m&IXANY)) printf("-ixany "); if (m&IXOFF) printf("ixoff "); m = cb.c_oflag; if (!(m&OPOST)) printf("-opost "); else { if (m&OLCUC) printf("olcuc "); if (m&ONLCR) printf("onlcr "); if (m&OCRNL) printf("ocrnl "); if (m&ONOCR) printf("onocr "); if (m&ONLRET) printf("onlret "); if (m&OFILL) if (m&OFDEL) printf("del-fill "); else printf("nul-fill "); delay((m&CRDLY)/CR1, "cr"); delay((m&NLDLY)/NL1, "nl"); delay((m&TABDLYLSH)!=0)); if(term == SYNC) { printf("-stflush "+((m&STFLUSH)!=0)); printf("-stwrap "+((m&STWRAP)!=0)); printf("-stappl "+((m&STAPPL)!=0)); } printf("\n"); m = cb.c_oflag; printf("-opost "+((m&OPOST)!=0)); printf("-olcuc "+((m&OLCUC)!=0)); printf("-onlcr "+((m&ONLCR)!=0)); printf("-ocrnl "+((m&OCRNL)!=0)); printf("-onocr "+((m&ONOCR)!=0)); printf("-onlret "+((m&ONLRET)!=0)); printf("-ofill "+((m&OFILL)!=0)); printf("-ofdel "+((m&OFDEL)!=0)); delay((m&CRDLY)/CR1, "cr"); delay((m&NLDLY)/NL./usr/src/:mk 664 2 2 17 5555212415 6136 1, "nl"); delay((m&TABDLY)/TAB1, "tab"); delay((m&BSDLY)/BS1, "bs"); delay((m&VTDLY)/VT1, "vt"); delay((m&FFDLY)/FF1, "ff"); printf("\n"); } gct(cp) register char *cp; { register c; c = *cp++; if (c == '^') { c = *cp; if (c == '?') c = 0177; else if (c == '-') c = 0377; else c &= 037; } return(c); } pit(what, itsname, sep) unsigned char what; char *itsname, *sep; { pitt++; printf("%s", itsname); if (what == 0377) { printf(" %s", sep); return; } printf(" = ");./:mkcmd $* \* tty.c ${i}.rc ] then sh -x ${i}.rc else echo XXXXXXXX Do Not Know How to MAKE $B fi $CLEAN else echo "XXXXXXXX Cannot make $B" fi esac : Install binary just made in appropriate bin case $NAME in "") : ;; *) cd $TEST if [ $source = $LSRC ] then echo /etc/install -n ${LBIN} $NAME /etc/install -n ${LBIN} $NAME else echo /etc/install -n ${UBIN} $NAME /etc/install -n ${UBIN} $NAME fi rm -f $NAME ;; esac );done ccrm clobber else echo M if (what & 0200) { printf("-"); what &= ~ 0200; } if (what == 0177) { printf("DEL%s", sep); return; } else if (what < ' ') { printf("^"); what += '`'; } printf("%c%s", what, sep); } delay(m, s) char *s; { if(m) printf("%s%d ", s, m); } int speed[] = { 0,50,75,110,134,150,200,300,600,1200,1800,2400,4800,9600,0,0 }; prspeed(c, s) char *c; { printf("%s%d baud; ", c, speed[s]); } prencode() { printf("%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x\n", cb.c_iflag,cb.c_oflag,cb.c_cflag,cb.c_lfl./usr/src/bin/ 40775 2 2 0 5555220156 6304 E)/CS6); printf("-cstopb "+((m&CSTOPB)!=0)); printf("-hupcl "+((m&HUPCL)!=0)); printf("-cread "+((m&CREAD)!=0)); printf("-clocal "+((m&CLOCAL)!=0)); #ifndef pdp11 printf("-loblk "+((m&LOBLK)!=0)); #endif printf("\n"); m = cb.c_iflag; printf("-ignbrk "+((m&IGNBRK)!=0)); printf("-brkint "+((m&BRKINT)!=0)); printf("-ignpar "+((m&IGNPAR)!=0)); printf("-parmrk "+((m&PARMRK)!=0)); printf("-inpck "+((m&INPCK)!=0)); printf("-istrip "+((m&ISTRIP)!=0)); printf("-inlcr "+((m&INLCR)!=0)); printf("-igncag,cb.c_cc[0], cb.c_cc[1],cb.c_cc[2],cb.c_cc[3],cb.c_cc[4],cb.c_cc[5], cb.c_cc[6],cb.c_cc[7]); } encode(arg) char *arg; { int grab[12], i; i = sscanf(arg, "%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x", &grab[0],&grab[1],&grab[2],&grab[3],&grab[4],&grab[5],&grab[6], &grab[7],&grab[8],&grab[9],&grab[10],&grab[11]); if(i != 12) return(0); cb.c_iflag = (ushort) grab[0]; cb.c_oflag = (ushort) grab[1]; cb.c_cflag = (ushort) grab[2]; cb.c_lflag = (ushort) grab[3]; for(i=0; i<8; i++) cb.c_cc[i] = (char) gr "+((m&IGNCR)!=0)); printf("-icrnl "+((m&ICRNL)!=0)); printf("-iuclc "+((m&IUCLC)!=0)); printf("\n"); printf("-ixon "+((m&IXON)!=0)); printf("-ixany "+((m&IXANY)!=0)); printf("-ixoff "+((m&IXOFF)!=0)); printf("\n"); m = cb.c_lflag; printf("-isig "+((m&ISIG)!=0)); printf("-icanon "+((m&ICANON)!=0)); printf("-xcase "+((m&XCASE)!=0)); printf("-echo "+((m&ECHO)!=0)); printf("-echoe "+((m&ECHOE)!=0)); printf("-echok "+((m&ECHOK)!=0)); printf("-echonl "+((m&ECHONL)!=0)); printf("-noflsh "+((m&NOFrab[i+4]; return(1); } 1],cb.c_cc[2],cb.c_cc[3],cb.c_cc[4],cb.c_cc[5], cb.c_cc[6],cb.c_cc[7]); } encode(arg) char *arg; { int grab[12], i; i = sscanf(arg, "%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x", &grab[0],&grab[1],&grab[2],&grab[3],&grab[4],&grab[5],&grab[6], &grab[7],&grab[8],&grab[9],&grab[10],&grab[11]); if(i != 12) return(0); cb.c_iflag = (ushort) grab[0]; cb.c_oflag = (ushort) grab[1]; cb.c_cflag = (ushort) grab[2]; cb.c_lflag = (ushort) grab[3]; for(i=0; i<8; i++) cb.c_cc[i] = (char) g& B 0  6 >  67I % Z"7&7 "C 5555 @ 5 5@ #N 7DNe 7D 6D  /f  5@7zD@ 0 EN A 1E@7PD|?JD7DDw-nB1 .D7 ,D.D D mC5BD C D DEBD D CJBC C_C_o@ff %5 r y>@ C CCvCrC 5%c%oZC@   tC pC lC `C RC RCw-@C @fC_ @ m&;A m ;H ;_ 5 @ m:55 @ m:A m:H -:@ m:5 5' :s@ m:& X 7|55@ m~:f5 :@ mj:V5 @ mT:85@ mB:(5 J: @ m*:B ,: @ m:B@ m: PE9: % _ 4l5 @ m945 @ m9A m9H -9@ m9v4@ m9f4 |9s@ mN9& X 7H45@ mJ924 P9@ m >#e  C mC C mCȕ-C mBpB mB0CB mB& % B_ B @  BBB_@B_ B @  BBBAB7B_B_X=_A>D _|BSA_{A7J=`BA5RB_HB, A8B Z 5-*B$BA_A@5&  5% _NA  A& Z 5_@ p-E@ EB E E @`HAfA % A_A >#e 5-@p69"4@ m&9 QE969 % _ 9P5 @ m835 @ m8A m8H -8@ m83@ m83@ m8 RE88 % d3 "`3X3 " d8_ 5 @ mH8T35 @ m08A m8H -8@ m 8B@ m7Bo@ m7& X A m7 @ m7H@ m7 2 :2 :2 :TE77 % _ _77t2 t7B,@B %& % A m@7  @0XAf %  5-@4A@0w-@ N $  B_@ @m@H_ ? @m5 >N 5%c%s @@ mr@Hof X 5N`@  _w-X@ B_H@ B@m2@HN %o_ _ _ _ _ __ __ _ __ _  _ _ __ _^ _ _ __ _ _ _ _Z_ _ _ @ m*7HB,@B %& % A m6 @ m6 UE67 %7P6%%  6 o6 X  : w7ed6 w7 6n1 :h1 : z6\1 :V1 :P1 :`6 Z"wh7rNff>D e H5 >5 :5>D x 6 6w 7*C %/ ”% %ӥ.w 7N ԥ/̋tw70_NB " u NB " e B " [Nf   N >#e_ _ _ __ _ _ _ __QB@&  5%>f P @> pPE >9>95 @ DE%@$@f P @PE % ^>  V>TB]B7J9 @>eB<9 _ >RnBmB j 78tBsB j 78zByB j 78BB j 78 = BB j 78 8 8 8 8 8 = t8  f8B  x=  r % r  r % 5Bf % Nf % Nf  NfB %, Z"Ne P@-@E5%N#C  e4 @tEw 5% C 7D >#  % wt7~N `# 5C  wL7VC %o  w(@e” ̋C7 N "w7@ 0@-@ 0@ >#&f  e A 1DEN@ &DE % @ 0@@ &DE % w7@ 0 1 2 a l p@./usr/src/bin/cc 775 2 2 25634 5555220150 6664  r 5 _ % @ m<B " @ m< %s @ m<5_ 7 < i@ m<& X 777<#@m 5A m; Bf % 6f % ;@@m;f # @@m/ J;@ mV;B@ mD;$;-:;fBC %w:@e7( @e56Dff *% 1w7 7@ N& B aˋN  7 x7 n7wfw0w0R70bCw7~D LԋwX7b%|0)w-r0l0 @mȥ- Z0 @mW B0pC80 @m&  "0 @mm071%:f  3 />Df  >DsC  >D&  >D  // @mm/ȋ //?wh ˥:K/ @mm~/7 77777 777f& & J fw 7- fw }7 5 5 C >#5D  >#5 N >#5u-@@@-@ u-@@e `#0_ f& %& # -D& %& # D& %& # A & z%& # D& %  >#a0f& t%R&& % D& % :&ӕA˥Z "ȋ wl7r Nf %r/ l/@mmd/ 7F1. V/w-P/ H/>Df  >DC  >D&  >D   / /@m70. .. @mm.ȋ. .7 07DLwԋ 7D  @E<EE w\fE x 7TD E%    -  D !  w 5D  %`@u@& ff e5B ` D  @  ("` D %7jD  N >#@m 5/=@w(72D+  & F w 7DC ԥ==̋ w7DCB 5ԋ Ԕ $@w7.D e-&w7D wj  , & & $4 44  7D4  w   -  7D E%B8 0#D\@E<EE % @EC@E5fe& h"%%  $Lt!%  A*DtepD WteZEte epD % @ 4 w7DC  ԋ@wfw,w,Cw7 @e5Nff *%@ wD7JDCB  w 7 5 uDC5 5 5  % _ @w e@-U +U U  #U 0U  Zu5 U5  .) %"E%E%    -  D ! wD  @EE< @EE& x 7DD  D4 D  @  (" & h"%  w, 72DE%wEU4  ! -D D4 D  @  (" 7D%  A*Dt e `#4 8u5 u-u @  A ZU5CBw JU5   5 5  5     U &  C xCB5W-o0ʋW-x ʋ x5ʕX05-eW-da5+Z5V S v r@ r ! f e0 9e'5e= !ACӋC~ @ AB 5w WteZEtepD  % @w7"D D D-wf @@f@w!w! Dwfw!&Dw 7D N >#`  r e0@  r X ̋̕a f # ̥z  f # =@w"fw!w!Dw$ 7 D ԋwf7 &DJU7&BJU7&DJ&BJ&Ae vB&7 & 7&  &%& 55 a  a!LE -Z&NBA 5u`u` u`ff` Hew5  @0   Wp ` e0eӕ?7 DCB@ @ ȕ N  x @ EH@ N E& x @ @ ȕ N  x w* 74 DC ʋ ʋw ԋ 7 DB  ˋˋ ʋ@w fAW @wd( fJ1J7X(5 ewF(C 5w 7L7H7D7@7<7874707,7(7$%BJ wDe vWt w<& \%0& `e  &  \%%&&e U?%% `e 7%BJU?% a7% %%?%%U e7D%E w7C5 $ 5N `# wF5A vBB-  }ee@  ۃ a ւ a a$fwmEwwmfwrEwwd 7DCԔw7DCԋ Ԕwd7nNeTf w'  B(B_AAAw ~  >D e@    w ? u &7 ԋ 7. w4 &Dԋ X  r e0LD7`: 7\@   zw f?  @as: Write error on temp file. @&f@ B &B? Bw  B7L  r e0H~F  @% B! ?e-(D (BL@(B  >w JB! [ ^  ! + , : P .!]w ] 9T # Y}+ - * /  &   % ! ^ =   w tt3w jf rB*w XB`%w NB w DA B@w 8BPw .BpBw "f rw A B`+w`&PEEE &     U.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~>D  " % u /lib/as2--oa.out-g &%  w>f@wD f@wwEw BFN& 7F@(#)C rel 5.0/lib///bin//-lR@U@X@[@_@b@e@2@Xc0c1c2cppasldcrt0.occSo:OpcfEPD:I:U:Ct:B:#gZ:W:0:1:2:A:L:d:l:V:'-o %s': Illegal name for output of ldToo many EPDIUC options-t overwrites earlier option012p-B overwrites earlier option/lib/o'-g' option not supported on the pdp11 cc compiler '-Z' needs one-letter subargu 8B .B& p!=<!:7 B W!!w x̵w m݂A n* fAbA7AX ?:D_  W w xW E  E бw x.!;!  LA! DAw Nxw Fx  tw w (f ! !;!ef&B" " " " & &  ~ 7> Z> ` Ґ7> <*r ve*7 W *er P w BD $$$$ B&e7!ej ment: -Z%scrt2.o-l2,Invalid subargument: -W%s-W,Too many arguments for pass -W%cThe cc option '-%c%s' is no longer supported.Please use '-Wc,arg'Too many ld optionsToo many ld arguments-I/usr/Xinclude012p/lib/n-tfmcrt0.ofcrt0.omcrt0.octm1ctm2ctm3ctm4ctm5cc: cannot create temporaries: %s%s: --P-Xg-u-o/lib///lib//-o-lXgg-lXcccallsys %s: '%s' . /usrCan't find %s, %sCan't fork; Try againFatal error in %sout of spaceUnrecognized pass name: '%s%c';  7& >D >D re  re h f  dw >09 0Wq `Wt` b f  .A 7=@@ lea be e`=7Z= b?`? \?E:=( 7:?(8?=7=*? ?w $iw:? 7H7?<n 6w ,? w7<>&f H>D < 2>7 >   (> !y:&B ыD//<>%7> >    w g< X7 = $ U B = 4< >    \  &ҋ  > w <wn s t e0r apw  <w re w & p xlllll   l*BH  rn e^ !,  e> !,  e   !, mt< E | w XU  ><./usr/src/bin/as 775 2 2 13142 5555220153 6674 ! x!, n *7r* 7! U >!, 4 w x!('!-6!$G!*M !(  e@  e( p!+  !(7`;- t \ 8 `e p!*w ,* :7`w a    w e!)w ) f+7 :  w "]!a!k 1*  Ow fK  H D$   v: x y+ - * / &    %df movie moveildfps @stfps fr0fr1fr2fr3fr4fr5alstalscvmpypmulpdivrashtashcvdvdrxorxsxt mark sob~.byte.even.if.endif.globl.text.data.bss.comm0 0X W-Q WugDg6Wo<w5w6ы BW +cs%."wK(q ( et ( N t ww      -  5 B5.t55  d B5 B5@ B5@  B@ Bw%% %% %; %;%5 %7 7 el   7`w`w   %n%ehw b LA 7`Rw`Pw Jf  <6 Deee@ 7$w"f <   eJ( as: output would overwrite 7 w 2u 7w (؅ 7 wr  fDa~ r ve* *er Ke W 'ᇇee@ 7wf <  eee@ 7w _ A 7`w`w @wğe e   %  % Wp a@w 0  5 h% w ( t U5L@4@4@ 4 @4@ 4@4 EEww  h%  ( t 5 ( t 555555555555%F%(B$f xxxx as: symbol table overflow bD/tmp/atm1aXXXXX/tmp/atm2aXXXXX/tmp/atm3aXXXXX(B>D...r0r1r2r3r4r5sppcmov movb cmp cmpb bit 0bitb bic @bicb bis Pbisb add `sub brbnebeqbgebltbgtblebplbmi  fDa~ r ve* *er Ke W 'ᇇbhiblosbvcbvsbhisbecbccblobcsbesjbrjnejeqjgejltjgtjlejpljmijhijlosjvcjvsjhisjecjccjlojcsjesclr clrb com @ comb @inc incb dec decb neg negb adc @ adcb @sbc sbcb./usr/src/bin/date 775 2 2 15004 5555220156 7210 tst tstb ror rorb rol @ rolb @asr asrb asl aslb jmp @swab jsrrtssys clcclvclzclnsecsevsezsencfccsetfsetd setisetl clrf negf absf tstf @movf movif movfimovof movfoaddf subf mulf divf cmpf mo` 0  6 >  67 % t w 5  %@- l  %@- u e \%n@7D ` . ( t  " "<  e7`w`w       D (' ^Y J 5* & f e(f %N    f   Z7Lg 5 Z70@2  k ( r@A r  f  e0 9e' E,* Aҋ D~@B @  p5w*A  fff Fe w5  @ 0   Wp `e0eӕ?w DCB &E z f  #̥-%0  E: E:  &E  z f  w w  DuL fwwww& f@www wfwwwfwlwhwdw fwNmJFw:wm4fw$wrw f@AwR f BRfwf@www7Fw C  5!#BA  D & r@&rr @`    w8& BAN   C 5 N B A @ A-  A Nfe& %4 ;#%      & %S  wB @w , DE%& %  w w   e-B w w D@     4 4 wj f x@w L N  ZwF w 6 Ne < f Lef&@ 5uNe w    ww B A@ C@ppC`pww C  5!BAD  r@frr `  wbBA  C 5 B A @ A-  A    w @& BF|{date: bad conversion date: no permission /usr/adm/wtmpGMT%.20s%s%sdate: no permission date: no permission date: invalid time in perpetual clock; set date manually date: no permission /%J %K  t@ t5B  N  5   %D-D-% eu Ne  wZw JDC%: e`m e rfww Q@f& He5uQ@f& Be5u eeQu  6< ff eR< ff eC r<R r< A@epe@ f& ew F  5 $u   5u F  $,(,h048<@DHLASTADTESTEDTCSTCDTMSTMDTPSTPDTJSTGMT+-GMT%s%d:%02d d o xb fp eR g, c> sb lb L u r D O X U(null)NM:/Day Mon 00 00:00:00 1900 SunMonTueWedThuFriSatJanFebMarAprMayJunJulAugSepOctNovDec64T#% %% % %; %;7 7 elN  7`w`w  u-N %n %elw f uA 7`Tw`Rw Lf  >8 Feee@ 7&w$f <  eee@ 7wf <  eee@ 7w<  e7`w`w      ( t w`A A 7`fw`d_w 8 L-     w e%  @ 5P 5`u`u 2D7. %n*   P  0!P  7 6ww tpԔAA WpCeԔԔԔ BeWpCeԔԔԔ& : ed& : ed& : ed& : @%d 20e@ ed& : ww A r nwmw D % A r  r e0@ԕ A r e0@wZw J JU7 HU7 J H Ae vB 7 55 a  a!RRA r<NA r<&fT Tew fef % vw w zBuNefef % = Ne& @w4w $uDAB %u f& & e w 5 5  W- W00u5  .ubBwF J@B _ @  o x d u        ӕ- f&@Ew ӕ0 S E -N %H w @ %: e rt 7$   `e   %  e U?  `e 7 HU?  a7   ?  U ew D| E ww D5 @ r5N !w5A vBB-  }ee@ !ۃ `!ւ `@ r ` w HNef   w6w N tf %ww Ntf %wf@w$,(,h048<@DHLASTADTESTEDTCSTCDTMSTMDTPSTPDTJSTGMT+-GMT%s%d:%02d d o xb fp eR g, c> sb lb L u r D O X U(null)NM:/Day Mon 00 00:00:00 1900 SunMonTueWedThuFriSatJanFebMarAprMayJunJulAugSepOctNovDec64T#