From aa234d7de4f8e44088dbab0894506e103060d12a Mon Sep 17 00:00:00 2001 From: Phil Budne Date: Wed, 23 Mar 2016 15:55:07 -0400 Subject: [PATCH] Add phil's simple "ls": "lsd dir" lists a directory in dd, "lsl dir": long list (lsl should be a hard link to lsd!) --- build/Makefile | 8 +- build/proto | 2 + src/other/pblsd.s | 267 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 276 insertions(+), 1 deletion(-) create mode 100644 src/other/pblsd.s diff --git a/build/Makefile b/build/Makefile index 2b9cda8..08c8b40 100644 --- a/build/Makefile +++ b/build/Makefile @@ -143,7 +143,7 @@ $(BINDIR)/altmkdir: $(ALTSRC)/wktmkdir.s # The commands that did not come from the scans others: dirs $(BINDIR)/sh $(BINDIR)/wktcat $(BINDIR)/wktcp $(BINDIR)/date \ $(BINDIR)/ln $(BINDIR)/ls $(BINDIR)/mv $(BINDIR)/stat $(BINDIR)/od \ - $(BINDIR)/bc + $(BINDIR)/bc $(BINDIR)/lsd # Alternative other commands: no dd, but . and .. altothers: dirs $(BINDIR)/sh $(BINDIR)/wktcat $(BINDIR)/wktcp $(BINDIR)/date \ @@ -168,9 +168,15 @@ $(BINDIR)/ln: $(OTHERSRC)/wktln.s $(BINDIR)/ls: $(OTHERSRC)/wktls.s $(AS) $(ASARGS) -o $(BINDIR)/ls $(OTHERSRC)/wktls.s +$(BINDIR)/lsd: $(OTHERSRC)/pblsd.s + $(AS) $(ASARGS) -o $(BINDIR)/lsd $(OTHERSRC)/pblsd.s + $(BINDIR)/altls: $(ALTSRC)/wktls.s $(AS) $(ASARGS) -o $(BINDIR)/altls $(ALTSRC)/wktls.s +$(BINDIR)/lsd: $(OTHERSRC)/pblsd.s + $(AS) $(ASARGS) -o $(BINDIR)/lsd $(OTHERSRC)/pblsd.s + $(BINDIR)/mv: $(OTHERSRC)/wktmv.s $(AS) $(ASARGS) -o $(BINDIR)/mv $(OTHERSRC)/wktmv.s diff --git a/build/proto b/build/proto index 5270b45..6ea7cfd 100644 --- a/build/proto +++ b/build/proto @@ -36,6 +36,8 @@ dd drwr- -1 4 init frwr- -1 bin/init ln frwr- -1 bin/ln ls frwr- -1 bin/ls + lsd frwr- -1 bin/lsd + lsl frwr- -1 bin/lsd od frwr- -1 bin/od mv frwr- -1 bin/mv password frw-- -1 fs/password diff --git a/src/other/pblsd.s b/src/other/pblsd.s new file mode 100644 index 0000000..e0ceb50 --- /dev/null +++ b/src/other/pblsd.s @@ -0,0 +1,267 @@ +" "lsd" -- phil's (minimal) "ls directory" +" for UNIX-7 without "." links (requires a dirname argument) +" adapted from warren's "historic version of ls" + +" Usage: lsd dirname +" lsl dirname +" +" with "lsl" displays long listing: +" inum [dcl-][r-][w-][r-][w-] nlink uid size name +" with numbers in octal + +argptr=017777 " pointer to argc, argv +argc=argptr i + +main: + lac argptr " get pointer to argc, names + tad d2 " point to second word of command name + dac nextarg + lac nextarg i " fetch it + dac longopt " save (for long check) + + -4 " check for second arg + tad argc + spa + jmp nodir " no second arg + + lac nextarg + tad d3 " skip rest of argv[0] + + dac dirname " save for dir status + dac dirname2 " save for dir open + dac dirname3 " save for file status + + lac statbufptr " stat the dir + sys status; dd; dirname: 0 + spa + jmp error + lac s.flags + and dirflg " get dir bit + sna " a directory? + jmp error " no: not a dir + + sys chdir; dd " chdir to "dd" so we can open directory + spa + jmp error + sys open; dirname2:0; 0 " open the directory + spa + jmp error + dac dirfd " save the fd + +" loop reading blocks from directory file +blkloop: + lac dirfd; sys read; dbuf; 64 " read block from directory + spa sna " OK? + jmp fileend " no: EOF or error + dac dcount " save word count + + lac idirptr " reset dirptr + dac dirptr + +" loop reading 8-word directory entries: +" word 0 is i-number, words 1-4 are the file name +dentloop: + lac dirptr i " get i-number + sna " i-num non-zero (in use)? + jmp nextdent " no, skip to the next directory entry + + lac lbufp " get line buffer pointer + dac 8 " save in index register + + lac longopt + sad deesp " short output? + jmp prname " yes: just print name + +" long output: "stat(us)" the file: + lac dirptr " get pointer to name + tad d1 + dac fname " save for status call + + lac statbufptr " stat the file + sys status; dirname3: 0; fname: 0 + spa + jms fileend " exit if the status call fails + + lac s.inum; jms octal; -5 " format i-number + +" loop for file types: output one char or dash + law types-1 + dac 9 + lac mntypes + dac c +tloop: + lac s.flags " get mode bits + and 9 i " check bit + sna + jmp 1f " not set + lac 9 i " bit set: get char + jmp foundtype +1: isz 9 " skip char + isz c " more bits? + jmp tloop " yes, loop and check + lac dash " no type found ("small" file) output '-' +foundtype: + dac 8 i " save in buffer + +" loop for permission bits. for each bit, output either char or dash + law perms-1 + dac 9 + lac mnperms + dac c +ploop: + lac s.flags " get flags + and 9 i " bit set? + sna + jmp 1f " no: output dash + lac 9 i " yes: get char + jmp 2f +1: lac dash + isz 9 " skip char +2: dac 8 i " put char or dash in buffer + isz c " more bits? + jmp ploop " yes, loop + +putsp: + lac o40 " put space + dac 8 i + + lac s.nlks " format link count + cma " negate + tad d1 + jms octal; -2 + + lac s.uid " format owner + jms octal; -3 + + lac s.size " format size + jms octal; -5 + +prname: + lac dirptr " get pointer to "dnode" (one before name) + dac 9 + -4 " get word count + dac c " in c +1: lac 9 i " copy name + dac 8 i + isz c + jmp 1b + + lac o12 " add newline + dac 8 i + +wr: " breakpoint + lac lbufp " negate starting pointer + cma + tad d1 + tad 8 " add ending pointer + dac 1f + lac d1; sys write; lbuf; 1: 0 " output line + +nextdent: + lac dirptr " advance to next "dnode" + tad d8 + dac dirptr + -8 + tad dcount " Decrement the count of words in the buffer by 8 + dac dcount + sza " Anything left in the buffer? + jmp dentloop " yes: keep going + jmp blkloop " no: try reading some more + +fileend: + nop + lac dirfd + sys close " close dir fd + sys exit + +" octal print from ds.s +octal: 0 + lmq " get number to print in MQ + lac d5 " get octal "digits" (oits) to lose: + tad octal i " 5-oits + cma " get -(6-oits) + dac c " save as loop count +1: llss 3 " Lose top 3 bits of the MQ + isz c " nothing left to lose? + jmp 1b " no: lose some more + + lac octal i " get negative oit count + dac c " save as loop count +1: cla " clear AC + llss 3 " slide an oit's worth up into AC + tad o60 " make ASCII + dac 8 i " output + isz c " more? + jmp 1b " yes, loop + + lac o40 " output space + dac 8 i + isz octal " skip the oits argument + jmp octal i " and return + +nodir: + lac d1; sys write; nodirs; 5 + sys exit + +error: + lac dirname + dac 1f + lac d1; sys write; 1:0; 4 " Write out the bad dirname + lac d1; sys write; qnl; 1 " write ? NL + sys exit + +" constants + +nodirs: ; ; +qnl: ; 040040; 040040; 040040 +deesp: