Research V5 development
authorKen Thompson <ken@research.uucp>
Tue, 26 Nov 1974 23:13:21 +0000 (18:13 -0500)
committerKen Thompson <ken@research.uucp>
Tue, 26 Nov 1974 23:13:21 +0000 (18:13 -0500)
Work on file usr/source/s1/glob.c
Work on file usr/sys/conf/flrc
Work on file usr/source/s4/open.s
Work on file usr/source/s1/df.c
Work on file usr/source/s4/gtty.s
Work on file usr/source/s4/hmul.s
Work on file usr/source/s4/execl.s
Work on file usr/source/s4/write.s

Co-Authored-By: Dennis Ritchie <dmr@research.uucp>
Synthesized-from: v5

usr/source/s1/df.c [new file with mode: 0644]
usr/source/s1/glob.c [new file with mode: 0644]
usr/source/s4/execl.s [new file with mode: 0644]
usr/source/s4/gtty.s [new file with mode: 0644]
usr/source/s4/hmul.s [new file with mode: 0644]
usr/source/s4/open.s [new file with mode: 0644]
usr/source/s4/write.s [new file with mode: 0644]
usr/sys/conf/flrc [new file with mode: 0644]

diff --git a/usr/source/s1/df.c b/usr/source/s1/df.c
new file mode 100644 (file)
index 0000000..97302a4
--- /dev/null
@@ -0,0 +1,97 @@
+char   *dargv[]
+{
+       0,
+       "/dev/rk2",
+       "/dev/rp0",
+       0
+};
+struct
+{
+       char    *s_isize;
+       char    *s_fsize;
+       int     s_nfree;
+       int     s_free[100];
+       int     s_ninode;
+       int     s_inode[100];
+       char    s_flock;
+       char    s_ilock;
+       char    s_fmod;
+       int     time[2];
+       int     pad[50];
+} sblock;
+
+int    fi;
+
+main(argc, argv)
+char **argv;
+{
+       int i;
+
+       if(argc <= 1) {
+               for(argc = 1; dargv[argc]; argc++);
+               argv = dargv;
+       }
+
+       for(i=1; i<argc; i++) {
+               if(argc > 1)
+                       printf("%s ", argv[i]);
+               dfree(argv[i]);
+       }
+}
+
+dfree(file)
+char *file;
+{
+       int i;
+
+       fi = open(file, 0);
+       if(fi < 0) {
+               printf("cannot open %s\n", file);
+               return;
+       }
+       sync();
+       bread(1, &sblock);
+       i = 0;
+       while(alloc())
+               i++;
+       printf("%l\n", i);
+       close(fi);
+}
+
+alloc()
+{
+       int b, i, buf[256];
+
+       i = --sblock.s_nfree;
+       if(i<0 || i>=100) {
+               printf("bad free count\n");
+               return(0);
+       }
+       b = sblock.s_free[i];
+       if(b == 0)
+               return(0);
+       if(b<sblock.s_isize+2 || b>=sblock.s_fsize) {
+               printf("bad free block (%l)\n", b);
+               return(0);
+       }
+       if(sblock.s_nfree <= 0) {
+               bread(b, buf);
+               sblock.s_nfree = buf[0];
+               for(i=0; i<100; i++)
+                       sblock.s_free[i] = buf[i+1];
+       }
+       return(b);
+}
+
+bread(bno, buf)
+{
+       int n;
+       extern errno;
+
+       seek(fi, bno, 3);
+       if((n=read(fi, buf, 512)) != 512) {
+               printf("read error %d\n", bno);
+               printf("count = %d; errno = %d\n", n, errno);
+               exit();
+       }
+}
diff --git a/usr/source/s1/glob.c b/usr/source/s1/glob.c
new file mode 100644 (file)
index 0000000..a4ef186
--- /dev/null
@@ -0,0 +1,256 @@
+#
+/* global command --
+
+   glob params
+
+   "*" in params matches r.e ".*"
+   "?" in params matches r.e. "."
+   "[...]" in params matches character class
+   "[...a-z...]" in params matches a through z.
+
+   perform command with argument list
+  constructed as follows:
+     if param does not contain "*", "[", or "?", use it as is
+     if it does, find all files in current directory
+     which match the param, sort them, and use them
+
+   prepend the command name with "/bin" or "/usr/bin"
+   as required.
+*/
+
+#define        E2BIG   7
+#define        ENOEXEC 8
+#define        ENOENT  2
+
+#define        STRSIZ  522
+char   ab[STRSIZ];             /* generated characters */
+char   *ava[200];              /* generated arguments */
+char   **av &ava[1];
+char   *string ab;
+int    errno;
+int    ncoll;
+
+main(argc, argv)
+char *argv[];
+{
+       register char *cp;
+
+       if (argc < 3) {
+               write(2, "Arg count\n", 10);
+               return;
+       }
+       argv++;
+       *av++ = *argv;
+       while (--argc >= 2)
+               expand(*++argv);
+       if (ncoll==0) {
+               write(2, "No match\n", 9);
+               return;
+       }
+       execute(ava[1], &ava[1]);
+       cp = cat("/usr/bin/", ava[1]);
+       execute(cp+4, &ava[1]);
+       execute(cp, &ava[1]);
+       write(2, "Command not found.\n", 19);
+}
+
+expand(as)
+char *as;
+{
+       register char *s, *cs;
+       register int dirf;
+       char **oav;
+       static struct {
+               int     ino;
+               char    name[16];
+       } entry;
+
+       s = cs = as;
+       while (*cs!='*' && *cs!='?' && *cs!='[') {
+               if (*cs++ == 0) {
+                       *av++ = cat(s, "");
+                       return;
+               }
+       }
+       for (;;) {
+               if (cs==s) {
+                       dirf = open(".", 0);
+                       s = "";
+                       break;
+               }
+               if (*--cs == '/') {
+                       *cs = 0;
+                       dirf = open(s==cs? "/": s, 0);
+                       *cs++ = 0200;
+                       break;
+               }
+       }
+       if (dirf<0) {
+               write(2, "No directory\n", 13);
+               exit();
+       }
+       oav = av;
+       while (read(dirf, &entry, 16) == 16) {
+               if (entry.ino==0)
+                       continue;
+               if (match(entry.name, cs)) {
+                       *av++ = cat(s, entry.name);
+                       ncoll++;
+               }
+       }
+       close(dirf);
+       sort(oav);
+}
+
+sort(oav)
+char **oav;
+{
+       register char **p1, **p2, **c;
+
+       p1 = oav;
+       while (p1 < av-1) {
+               p2 = p1;
+               while(++p2 < av) {
+                       if (compar(*p1, *p2) > 0) {
+                               c = *p1;
+                               *p1 = *p2;
+                               *p2 = c;
+                       }
+               }
+               p1++;
+       }
+}
+
+execute(afile, aarg)
+char *afile;
+char **aarg;
+{
+       register char *file, **arg;
+
+       arg = aarg;
+       file = afile;
+       execv(file, arg);
+       if (errno==ENOEXEC) {
+               arg[0] = file;
+               *--arg = "/bin/sh";
+               execv(*arg, arg);
+       }
+       if (errno==E2BIG)
+               toolong();
+}
+
+toolong()
+{
+       write(2, "Arg list too long\n", 18);
+       exit();
+}
+
+match(s, p)
+char *s, *p;
+{
+       if (*s=='.' && *p!='.')
+               return(0);
+       return(amatch(s, p));
+}
+
+amatch(as, ap)
+char *as, *ap;
+{
+       register char *s, *p;
+       register scc;
+       int c, cc, ok, lc;
+
+       s = as;
+       p = ap;
+       if (scc = *s++)
+               if ((scc =& 0177) == 0)
+                       scc = 0200;
+       switch (c = *p++) {
+
+       case '[':
+               ok = 0;
+               lc = 077777;
+               while (cc = *p++) {
+                       if (cc==']') {
+                               if (ok)
+                                       return(amatch(s, p));
+                               else
+                                       return(0);
+                       } else if (cc=='-') {
+                               if (lc<=scc && scc<=(c = *p++))
+                                       ok++;
+                       } else
+                               if (scc == (lc=cc))
+                                       ok++;
+               }
+               return(0);
+
+       default:
+               if (c!=scc)
+                       return(0);
+
+       case '?':
+               if (scc)
+                       return(amatch(s, p));
+               return(0);
+
+       case '*':
+               return(umatch(--s, p));
+
+       case '\0':
+               return(!scc);
+       }
+}
+
+umatch(s, p)
+char *s, *p;
+{
+       if(*p==0)
+               return(1);
+       while(*s)
+               if (amatch(s++,p))
+                       return(1);
+       return(0);
+}
+
+compar(as1, as2)
+char *as1, *as2;
+{
+       register char *s1, *s2;
+
+       s1 = as1;
+       s2 = as2;
+       while (*s1++ ==  *s2)
+               if (*s2++ == 0)
+                       return(0);
+       return (*--s1 - *s2);
+}
+
+cat(as1, as2)
+char *as1, *as2;
+{
+       register char *s1, *s2;
+       register int c;
+
+       s2 = string;
+       s1 = as1;
+       while (c = *s1++) {
+               if (s2 > &ab[STRSIZ])
+                       toolong();
+               c =& 0177;
+               if (c==0) {
+                       *s2++ = '/';
+                       break;
+               }
+               *s2++ = c;
+       }
+       s1 = as2;
+       do {
+               if (s2 > &ab[STRSIZ])
+                       toolong();
+               *s2++ = c = *s1++;
+       } while (c);
+       s1 = string;
+       string = s2;
+       return(s1);
+}
diff --git a/usr/source/s4/execl.s b/usr/source/s4/execl.s
new file mode 100644 (file)
index 0000000..75bd05e
--- /dev/null
@@ -0,0 +1,19 @@
+/ C library -- execl
+
+/ execl(file, arg1, arg2, ... , 0);
+/
+
+.globl _execl, cerror
+
+_execl:
+       mov     r5,-(sp)
+       mov     sp,r5
+       mov     4(r5),0f
+       mov     r5,r0
+       add     $6,r0
+       mov     r0,0f+2
+       sys     0; 9f
+       jmp     cerror
+.data
+9:
+       sys     exec; 0:..; ..
diff --git a/usr/source/s4/gtty.s b/usr/source/s4/gtty.s
new file mode 100644 (file)
index 0000000..de3db86
--- /dev/null
@@ -0,0 +1,23 @@
+/ C library -- gtty
+
+/ error = gtty(filep, ttyvec);
+
+/ filep is descriptor of open tty
+/ ttyvec[0, 1, 2] correspond to args of gtty
+
+.globl _gtty, retrn, cerror
+
+_gtty:
+       mov     r5,-(sp)
+       mov     sp,r5
+       mov     4(r5),r0
+       mov     6(r5),0f
+       sys     0; 9f
+       bec     1f
+       jmp     cerror
+1:
+       clr     r0
+       jmp     retrn
+.data
+9:
+       sys     gtty; 0:..
diff --git a/usr/source/s4/hmul.s b/usr/source/s4/hmul.s
new file mode 100644 (file)
index 0000000..e1081d9
--- /dev/null
@@ -0,0 +1,6 @@
+.globl _hmul
+
+_hmul:
+       mov     2(sp),r0
+       mul     4(sp),r0
+       rts     pc
diff --git a/usr/source/s4/open.s b/usr/source/s4/open.s
new file mode 100644 (file)
index 0000000..512b12e
--- /dev/null
@@ -0,0 +1,21 @@
+/ C library -- open
+
+/ file = open(string, mode)
+/
+/ file == -1 means error
+
+.globl _open, retrn, cerror
+
+_open:
+       mov     r5,-(sp)
+       mov     sp,r5
+       mov     4(r5),0f
+       mov     6(r5),0f+2
+       sys     0; 9f
+       bec     1f
+       jmp     cerror
+1:
+       jmp     retrn
+.data
+9:
+       sys     open; 0:..; ..
diff --git a/usr/source/s4/write.s b/usr/source/s4/write.s
new file mode 100644 (file)
index 0000000..5bfe3a9
--- /dev/null
@@ -0,0 +1,22 @@
+/ C library -- write
+
+/ nwritten = write(file, buffer, count);
+/
+/ nwritten == -1 means error
+
+.globl _write, retrn, cerror
+
+_write:
+       mov     r5,-(sp)
+       mov     sp,r5
+       mov     4(r5),r0
+       mov     6(r5),0f
+       mov     8(r5),0f+2
+       sys     0; 9f
+       bec     1f
+       jmp     cerror
+1:
+       jmp     retrn
+.data
+9:
+       sys     write; 0:..; ..
diff --git a/usr/sys/conf/flrc b/usr/sys/conf/flrc
new file mode 100644 (file)
index 0000000..0fb927d
--- /dev/null
@@ -0,0 +1,34 @@
+chdir /usr/c
+ed c0t.s
+/fpp/g/1/s//0/
+w
+q
+as c0t.s
+mv a.out c0t.o
+cc -s -n c0?.o
+cp a.out /lib/c0
+rm a.out c0t.o
+chdir /usr/source/s1
+ed db1.s
+/fpp/g/1/s//0/
+w
+q
+as db?.s
+strip a.out
+cp a.out /bin/db
+rm a.out
+chdir /usr/source/s3
+as fp?.s
+mv a.out fp.o
+ar r /lib/liba.a fp.o
+rm fp.o
+chdir /usr/fort
+ld -s -u pass1 -u pass2 -u pass3 -u pass4\
+f1o.a f2o.a f3o.a f4o.a fxo.a -l
+cp a.out fc1
+rm a.out
+chdir /usr/source/s1
+as bas?.s
+ld -s a.out -l
+cp a.out /bin/bas
+rm a.out