diff --git a/src/other/brt.s b/src/other/brt.s index 03ae284..b86b106 100644 --- a/src/other/brt.s +++ b/src/other/brt.s @@ -230,29 +230,23 @@ flush: 0 jmp flush i initio: 0 + law .argv " build argument list + dac 8 " auto-inc pointer argvp = &argv[-1] lac 017777 i -" sad d4 - jmp 2f - sad d8 - jmp 1f + cll rtr + dac 8 i " *++argvp = arg count + cma + tad d1 + dac t1 " count = -argv[0] + lac 017777 + dac lastv " set top of heap + tad d1 " ac = addr of arg0 +1: + dac 8 i " *++argvp = ac + tad d4 " ac += 4 + isz t1 " while ++count != 0 + jmp 1b - law 9 - tad 017777 - dac .+3 - law 017 - sys creat; .. - spa - jmp stop - dac .fout -1: - law 5 - tad 017777 - dac .+2 - sys open; ..; 0 - spa - jmp stop - dac .fin -2: lac lastv dac eibufp dac cibufp @@ -280,7 +274,7 @@ iflg: 0 eobufp: 0 cobufp: 0 oflg: 0 -lastv: 017770 +lastv: 0 o777: 0777 d4:o4: 4 diff --git a/src/other/brtb.b b/src/other/brtb.b index 8439a52..0c48c9a 100644 --- a/src/other/brtb.b +++ b/src/other/brtb.b @@ -2,12 +2,25 @@ char(s, n) { if (n & 1) return(s[n/2] & 0777); - return ((s[n/2]/512) & 0777); + return((s[n/2]/512) & 0777); } lchar(s, n, c) { if (n & 1) s[n/2] = (s[n/2] & 0777000) | c; else s[n/2] = (s[n/2] & 0777) | (c*512); + return(c); +} + +getstr(s) { + auto c, i; + + i = 0; + while ((c = getchr()) != '*n') { + lchar(s,i,c); + i = i+1; + } + lchar(s,i,'*e'); + return(s); } putstr(s) { diff --git a/src/other/ctype.b b/src/other/ctype.b new file mode 100644 index 0000000..8e05611 --- /dev/null +++ b/src/other/ctype.b @@ -0,0 +1,9 @@ +/* ctype.b - character types */ + +isalpha(c) { + return((c >= 'a' & c <= 'z') | (c >= 'A' & c <= 'Z')); +} + +isdigit(c) { + return(c >= '0' & c <= '9'); +} diff --git a/src/other/string.b b/src/other/string.b new file mode 100644 index 0000000..7731be8 --- /dev/null +++ b/src/other/string.b @@ -0,0 +1,58 @@ +/* string.b - B string library + + mostly from: https://www.bell-labs.com/usr/dmr/www/btut.html +*/ + +strcopy(sl, s2) { + auto i; + i = 0; + while (lchar(sl,i,char(s2,i)) != '*e') + i = i+1; + return(s1); +} + +strcat(s1, s2) { + auto i,j; + i = j = 0; + while (char(s1,i) != '*e') + i = i+1; + while(lchar(s1,i,char(s2,j)) != '*e') { + i = i+1; + j = j+1; + } + return(s1); +} + +strlen(s) { + auto i; + i = 0; + while (char(s,i) != '*e') + i = i+1; + return(i); +} + +strcmp(s1, s2) { + auto c,i; + i = 0; + while ((c=char(s1,i)) == char(s2,i)) { + if (c == '*e') + return(0); + i = i+1; + } + return(c - char(s2,i)); +} + +/* convert command line argument into a string */ +strarg(s, a) { + auto i, c; + i = 0; + while (i < 8) { + if ((c = char(a,i)) == ' ') + goto done; + lchar(s,i,c); + i = i+1; + } +done: + lchar(s,i,'*e'); + return(s); +} diff --git a/src/other/test.b b/src/other/test.b index c0259a8..e398c3d 100644 --- a/src/other/test.b +++ b/src/other/test.b @@ -7,14 +7,41 @@ perl a7out test.out */ +/* convert command line argument into a string */ +strarg(s, a) { + auto i, c; + i = 0; + while (i < 8) { + if ((c = char(a,i)) == ' ') + goto done; + lchar(s,i,c); + i = i+1; + } +done: + lchar(s,i,'*e'); + return(s); +} + main { - extrn fname, fin; - auto ch,p; + extrn fname, fin, fout, argv; + auto ch,p,n,str 5; p = 017777; printf("mem[0%o] = 0%o*n",p,*p); printf("mem[0%o] = %d*n",*p,**p); + printf("argv = %d*n",argv); + printf("**argv = %d*n",*argv); + printf("argv[0] = %d*n",argv[0]); + n = 0; + while (n < argv[0]) { + n = n+1; + printf("argv[%d] = 0%o *"%s*"*n",n,argv[n],strarg(str,argv[n])); + } + + printf("array(0) = 0%o*n",array(0)); + printf("array(64) = 0%o*n",array(64)); + printf("array(0) = 0%o*n",array(0)); /* fin = open(fname, 0); */ fin = open("abc ", 0);