fixes: handle blank line, 8 character filenames, semi

This commit is contained in:
Phil Budne
2016-03-22 20:07:20 -04:00
parent 2b4aeb3bab
commit 2d8ee26e03
+81 -67
View File
@@ -39,7 +39,10 @@ newline:
lac d1; sys write; prompt; 1 " output prompt lac d1; sys write; prompt; 1 " output prompt
jms rline " read line into ibuf jms rline " read line into ibuf
lac iipt lac iipt
dac ipt dac ipt " reset input pointer
" parse new command from current input line
" (after ';' or '&')
newcom: newcom:
dzm char " clear saved char dzm char " clear saved char
dzm infile " clear input redirect file name dzm infile " clear input redirect file name
@@ -68,12 +71,12 @@ newarg:
jms blank " skip whitespace jms blank " skip whitespace
jms delim " command sep? jms delim " command sep?
jmp eol " yes jmp eoc " yes
sad lt " input redirect? sad lt " input redirect?
jmp redirin jmp redirin " yes
sad gt " output redirect? sad gt " output redirect?
jmp redirout jmp redirout " yes
jmp 3f jmp savechar " no: save as filename
redirin: " saw < redirin: " saw <
dac redirect " flag redirect dac redirect " flag redirect
@@ -87,40 +90,43 @@ redirout: " saw >
dac opt dac opt
" fall " fall
newchar: newchar: " loop reading a file name
jms getc jms getc
sad o40 " space? sad o40 " space?
jmp eoname " yes jmp eoname " yes
jms delim jms delim " no: end of line?
jmp eoname jmp eoname " yes
3: jms putc " save savechar:
jms putc " no: save
isz bcount " loop unless full isz bcount " loop unless full
jmp newchar jmp newchar
" here after 8 chars: discard until terminator seen " here after 8 chars: discard until terminator seen
discard: 1: jms getc
jms getc
jms delim " end of line? jms delim " end of line?
jmp eoname jmp 2f
sad o40 sad o40
jmp eoname jmp 2f
jmp discard jmp 1b
2:
dac char " save terminator
jmp full
" name ended (short) with whitespace or delim " name ended (short) with whitespace or delim
" pad out last name to 8 with spaces " pad out last name to 8 with spaces
" XXX check if ANYTHING read
eoname: eoname:
dac char " save terminator dac char " save terminator
1: lac o40 1: lac o40
jms putc " no: copy into argv jms putc " copy into argv
isz bcount " loop until full isz bcount " loop until full
jmp 1b jmp 1b
full:
" saw end of name lac redirect
2: lac redirect
sza sza
jmp 2f " last name was a redirect file, skip increment jmp 2f " last name was a redirect file, skip increment
" file was not a redirection:
lac argc " increment argc lac argc " increment argc
tad d4 tad d4
dac argc dac argc
@@ -131,31 +137,31 @@ eoname:
2: 2:
dzm redirect " clear redirect flag dzm redirect " clear redirect flag
lac nextarg lac nextarg
dac opt dac opt " set output pointer
lac char lac char " get terminator
jms delim jms delim " end of command?
jmp eol jmp eoc " yes
lac argc lac argc " another arg
sad maxargwords sad maxargwords " full up?
skp skp " yes
jmp newarg jmp newarg " no: get another
" too many args, (complain?). for now eat rest of line " too many args
4: jms getc 4: jms getc
jms delim jms delim
skp skp
jmp 4b jmp 4b
lac d1; sys write; toomany; ltoomany lac d1; sys write; toomany; ltoomany
jmp newline jmp newline " ignore rest of line
" here at end of line " here at end of command
eol: eoc:
sad delimchar " save eol character dac delimchar " save command delimiter
lac argc " check for empty command line lac argc " check for empty command line
sna " get anything? sna " get anything?
jmp 2f " no, go back for another jmp nextcmd " no, go back for another
" check for built-in "chdir" command " check for built-in "chdir" command
lac argv0 lac argv0
@@ -170,27 +176,24 @@ eol:
sad chdirstr+2 sad chdirstr+2
jmp changedir jmp changedir
1: " here to execute command (not a builtin)
" comment these out to test "exec" w/o fork 1: sys fork
sys fork
jmp parent jmp parent
child: " debug symbol
sys open; argv0; 0 " try cwd (no link required) sys open; argv0; 0 " try cwd (no link required)
sma sma " error?
jmp 1f jmp 1f " no
" jmp cmderr
sys unlink; exectemp " remove old temp file, if any sys link; system; argv0; argv0
sys link; system; argv0; exectemp
spa spa
jmp cmderr jmp cmderr
sys open; exectemp; 0 sys open; argv0; 0
spa spa
jmp cmderr jmp cmderr
dac cmdfd dac cmdfd
sys unlink; exectemp sys unlink; argv0
skp skp
1: dac cmdfd " save command file descriptor 1: dac cmdfd " save command file descriptor
cla " check for input redirection cla " check for input redirection
sad infile " input redirct? sad infile " input redirct?
@@ -248,28 +251,32 @@ error: " error in child: filename pointer in AC
sys exit sys exit
" chdir command: executed in shell process " chdir command: executed in shell process
" takes a series of directory names to chdir to in turn
changedir: changedir:
" XXX check if argc == 4 (no directories) and complain?? lac argc
sad d4
jmp cherr " need at least one arg!
lac argv0p lac argv0p
skp skp
1: lac 0f " increment argvp 1: lac 0f " increment dir pointer
tad d4 tad d4
dac 0f dac 0f
-4 " decrement argc -4 " decrement argc
tad argc tad argc
dac argc dac argc
sna " done? sna " done?
jmp 2f " yes: join parent code jmp nextcmd " yes: join parent code
sys chdir; 0:0 sys chdir; 0:0
sma " error? sma " error?
jmp 1b " no: look for another directory jmp 1b " no: look for another directory
" chdir call failed " chdir call failed
lac 0b lac 0b " get name
dac 0f dac 0f " store for write
lac d1; sys write; 0:0; 4 lac d1; sys write; 0:0; 4
cherr:
lac d1; sys write; qmnl; 1 lac d1; sys write; qmnl; 1
jmp 2f " join parent code jmp nextcmd " join parent code
" here in parent, child pid in AC " here in parent, child pid in AC
parent: parent:
@@ -290,9 +297,11 @@ parent:
jmp newcom " yes: go back without wait jmp newcom " yes: go back without wait
lac pid " no: get pid lac pid " no: get pid
sys smes " hang until child exits sys smes " hang until child exits
2: lac delimchar nop
nextcmd:
lac delimchar
sad o73 " semi? sad o73 " semi?
jmp newcom " yes: look for another command w/o prompt jmp newcom " yes: look for another command on line
jmp newline " no: output prompt jmp newline " no: output prompt
" ================ " ================
@@ -330,6 +339,9 @@ rline: 0
law ibuf-1 " Store ibuf pointer in location 8 law ibuf-1 " Store ibuf pointer in location 8
dac 8 dac 8
1: 1:
" XXX ttyin returns one char per read,
" but redirected stdin would return two!!!
" push read down into an "rchar" routine??
cla; sys read; char; 1 " Read in one character from stdin cla; sys read; char; 1 " Read in one character from stdin
sna " read ok? sna " read ok?
jmp quit " no jmp quit " no
@@ -383,12 +395,13 @@ putc: 0
d1: 1 d1: 1
d2: 2 d2: 2
o4:d4: 4 o4:d4: 4
dm8: -8
o12: 012 " newline o12: 012 " newline
o17: 017 o17: 017
o40: 040 " space o40: 040 " space
o43: 043 " # o43: 043 " #
o46: 046 " ampersand o46: 046 " ampersand
o73: 046 " semi o73: 073 " semi
o74:lt: 074 " < o74:lt: 074 " <
o76:gt: 076 " > o76:gt: 076 " >
o100: 0100 " @ o100: 0100 " @
@@ -401,9 +414,6 @@ qmnl: <? 012 " question mark, newline
system: system:
<sy>;<st>;<em>; 040040 <sy>;<st>;<em>; 040040
exectemp:
<ex>;<ec>;<te>;<mp> " temporary link for file being exec'ed
chdirstr: chdirstr:
<ch>;<di>;<r 040 <ch>;<di>;<r 040
@@ -442,14 +452,18 @@ bootcount: .=.+1 " loop count for "boot" copy
ipt: .=.+1 " input buf pointer ipt: .=.+1 " input buf pointer
ibuf: " input line stored here, one character per word ibuf: " input line stored here, one character per word
" enter addresses into namelist:
.=017777 " last word points to argc + argv data
argptr:
.=argptr-maxargs-maxargs-maxargs-maxargs-1 " argc followed by argv
argc: .=.+1
argv0: " 4 word blocks following argc
" "bootstrap" (reads executable into userbase) copied JUST below argc
.=argc-bootlen
bootloc:
userbase=010000 " user starts at 4K userbase=010000 " user starts at 4K
argptr=017777 " last word points to argc + argv data
argc=argptr-maxargs-maxargs-maxargs-maxargs-1 " argc followed by argv
" arguments in 4 word blocks follow argc
argv0=argc+1
" "bootstrap" (reads executable into userbase) JUST below argc
bootloc=argc-bootlen " location of bootstrap
userlen=bootloc-userbase " max executable userlen=bootloc-userbase " max executable