home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / UNIFLEX / UNIFLEX / UniFLEX_Std.Utils1.tar.Z / UniFLEX_Std.Utils1.tar / utils1 / shell < prev    next >
Text File  |  1985-08-19  |  47KB  |  2,495 lines

  1.  opt pag,nol
  2.  ttl UniFLEX Shell
  3.  pag
  4.  lib sysdef
  5.  lib sysstat
  6.  opt lis
  7.  pag
  8.  
  9.  info UniFLEX shell
  10.  info Version 1.08, Released August 19, 1985
  11.  info Copyright, (C) 1983, by
  12.  info Technical Systems Consultants, Inc.
  13.  info All rights reserved.
  14.  
  15.  ifc &a,"notext"
  16.  org 0
  17.  else
  18.  text
  19.  endif
  20.  
  21. *
  22. * Program parameters
  23. *
  24.  
  25. ENTTY equ 29 device not terminal
  26. ENOFL equ 8 no file
  27. ENOTB equ 21 not binary
  28. NFILES equ 16 number of files (max)
  29. ASSIZ equ 5 number of async tasks
  30. BUFSIZ equ 256 input line buffer size
  31. SPACE equ $20 ascii space character
  32. COMMA equ ', ascii comma
  33. TAB equ $9 tab character
  34. BHDBT equ $8a basic header byte
  35. BHDBT2 equ $9a new basic header byte (v2.0)
  36. PHDBT0 equ $8B Pascal (normal) header byte ***GDT
  37. PHDBT1 equ $8c pascal (system) ***GDT
  38. LTS equ '<
  39. GTS equ '>
  40. TPCH equ '~ time prompt character
  41.  
  42.  
  43. *
  44. * Program starts here
  45. *
  46.  
  47. sh lbsr sinit do init
  48.  sts sp save sp
  49.  tst bgop background?
  50.  bne sh00
  51. * tst intflg interactive?
  52. * beq sh0
  53. sh00 sys cpint,2,1 if so, ignore ints
  54.  sys cpint,3,1
  55. sh0 lds sp reset stack ptr
  56.  ldd ctrm check term status
  57.  bne sh05
  58.  tst termc still more line?
  59.  bne sh12
  60. sh05 tst pipmod in pipe?
  61.  beq sh07
  62.  clr pipmod clear out mode
  63.  ldd pprdf close pipe files
  64.  sys close
  65.  ldd ppwrf
  66.  sys close
  67. sh07 clr pipmod clear out pipe
  68.  clr ctrm clear exit status
  69.  clr ctrm+1
  70.  tst intflg interactive?
  71.  beq sh1 if not, skip prompt
  72.  ldd #0 set file desc
  73.  sys ttyget,ttgbuf get tty params
  74.  lda ttgbuf get stat flags
  75.  anda #%10111110 clear schar mode (also raw)
  76.  sta ttgbuf
  77.  ldd #0 set file desc
  78.  sys ttyset,ttgbuf set tty status
  79. sh08 lbsr wrtpr output prompt
  80. sh1 lbsr getlin get an input line
  81.  bne sh11
  82.  tst supf doing startup?
  83.  lbeq sexit if so, terminate
  84.  clr supf clear mode
  85.  bra sh0 re-prompt
  86. sh11 cmpb #1 only c.r.??
  87.  beq sh0 if so, go to start
  88.  ldx #buffer
  89.  stx bufpt set buffer start
  90. sh12 lbsr pars parse the line
  91.  beq sh0 error?
  92. sh13 lbsr scmnd check for shell command
  93.  bne sh6
  94.  clr execf clear "exec" flag
  95.  jmp 0,x go do command
  96. sh6 ldd #0 clear command
  97.  std comnd
  98.  ldx arglst point to command name
  99.  beq sh9 null args?
  100.  tst prflg paren command?
  101.  bne sh92
  102.  ldy #comnd point to command buffer
  103. sh62 lda 0,x+ get a character
  104.  sta 0,y+ xfr to command buffer
  105.  bne sh62 end?
  106.  leax -1,x back up to term
  107. sh8 cmpx arglst back to beginning?
  108.  beq sh9
  109.  lda 0,-x get previous character
  110.  cmpa #'/ is it /?
  111.  bne sh8
  112.  leax 1,x eat slash
  113. sh9 stx arglst set first arg (cmnd name)
  114.  lda comnd check for null command
  115.  lbeq sh0
  116. sh92 lda termc get term char
  117.  cmpa #'| is it pipe?
  118.  lbeq cpipe
  119.  cmpa #'^
  120.  lbeq cpipe if so, create pipe
  121. sh95 lda termc check terminator
  122.  cmpa #';
  123.  beq sh96 if more commands follow
  124.  cmpa #'&
  125.  beq sh96 if background, possibly more follow
  126.  tst execf check fork flag
  127.  bne doit if no fork, act as child
  128. sh96 sys fork do system fork call
  129.  bra doit this is new task here
  130.  lbes frkerr fork error?
  131.  pshs d old task, save new ones id
  132.  lda termc get term character
  133.  cmpa #'| is it pipe?
  134.  lbeq dpipe
  135.  cmpa #'^ is it pipe?
  136.  lbeq dpipe
  137.  tst pipmod pipe active?
  138.  beq sh97
  139.  clr pipmod clear pipe mode
  140.  ldd apprdf get read file
  141.  sys close close it
  142. sh97 lda termc get term character
  143.  cmpa #'& is it async mode?
  144.  lbeq async
  145. pwait puls d get task id
  146.  std syntid save it
  147. pwait1 sys wait wait for task to die
  148.  cmpd syntid is it the child?
  149.  beq pwait2
  150.  lbsr chasy check for async job termination
  151.  bra pwait1 go wait some more
  152. pwait2 stx ctrm save command term status
  153.  beq pwait3 errors?
  154.  tst intflg interactive mode?
  155.  bne pwait3
  156.  tst supf doing startup?
  157.  beq pwai25
  158.  ldd #linbuf
  159.  std linpt
  160.  std linend
  161.  ldd ifd
  162.  sys seek,0,0,2 seek to end of file
  163.  bra pwait3
  164. pwai25 tfr x,d get status
  165.  sys term exit!
  166. pwait3 lbsr abtrm report any abnormal terminations
  167.  lbra rprt go report termd tasks
  168.  
  169.  pag
  170.  
  171. * execute command
  172.  
  173. doit sys cpint,11,0 enable "terminate" interrupt
  174.  lda termc check for async
  175.  cmpa #'&
  176.  bne doit0
  177.  ldd #5 lower priority by 5
  178.  sys setpr
  179.  bra doi12
  180. doit0 cmpa #'| doing pipe?
  181.  beq doi12
  182.  cmpa #'^
  183.  beq doi12
  184.  tst bgop background option set?
  185.  bne doi12
  186. doit1 sys cpint,2,0
  187.  sys cpint,3,0
  188. doi12 ldd sifil test input redirection
  189.  beq doi14
  190.  lbsr opsi open new input
  191.  lbes bdfil error?
  192. doi14 tst sofil test for output redirection
  193.  beq doi15
  194.  lbsr opso open new output
  195.  lbes bdfil error?
  196. doi15 tst safil output append?
  197.  beq doi16
  198.  lbsr opsa open append file
  199.  lbes bdfil error?
  200. doi16 lbsr spipe set up pipe
  201.  lda termc check for async
  202.  cmpa #'&
  203.  bne doi17
  204.  tst pipmod in pipe?
  205.  bne doi17
  206.  ldd sifil new input file?
  207.  bne doi17 if so, ok
  208.  ldd #nldst set up null device
  209.  std sifil
  210.  lbsr opsi open as input
  211. doi17 tst prflg check for paren string
  212.  lbne dosub if so, do subshell
  213.  clr rtcnt clear out retry counter
  214.  sys exec,comnd,arglst exec program
  215.  cmpd #ENOTB file not binary?
  216.  beq trya
  217. doitx1 lda comnd check first char
  218.  cmpa #'/ is it path head?
  219.  beq doit3
  220.  inc rtcnt bump retry count
  221.  sys exec,retry1,arglst try 'bin/...'
  222.  cmpd #ENOTB not binary?
  223.  beq trya
  224. doitx2 inc rtcnt bump counter
  225.  sys exec,retry2,arglst try '/bin/...'
  226.  cmpd #ENOTB not binary?
  227.  beq trya
  228. doitx3 inc rtcnt bump retry count
  229.  sys exec,retry3,arglst try '/usr/bin/...'
  230.  cmpd #ENOTB
  231.  beq trya
  232. doit3 ldd #1 if here, error!
  233.  sys write,ermsg1,ERSIZ1
  234.  ldx #comnd
  235.  ldd #0
  236. doit4 lda 0,x+
  237.  beq doit5
  238.  incb
  239.  bra doit4
  240. doit5 tst b
  241.  beq doit7
  242.  std doit6+5 save as arg
  243.  ldd #1 set file desc
  244. doit6 sys write,comnd,0
  245. doit7 ldd #1
  246.  sys write,ermsg2,ERSIZ2
  247.  ldd #$ff set error status
  248.  sys term terminate this guy!
  249.  
  250. *
  251. * trya
  252. *
  253. * Try to execute ascii file.
  254. *
  255.  
  256. trya ldx #rtclst point to list
  257.  lda rtcnt get retry count
  258.  asla
  259.  leax a,x point to retry number
  260.  ldd 0,x get pointer
  261.  std iopn2 set in open call
  262.  std arglst
  263.  std istata store in status call
  264.  sys ind,istat status the file
  265.  bes trya6 if cannot status the file
  266.  lda statbuf+st_mod get mode flags
  267.  bita #FSBLK+FSCHR check special files
  268.  bne trya6 if a special file
  269.  bita #FSDIR check for a directory
  270.  bne trya7 if a directory resume retries
  271.  sys ind,iopn open file
  272.  bes trya6
  273.  pshs d save file desc
  274.  clr smbuf
  275.  sys read,smbuf,2 read 1st 2 characters
  276.  puls d get fd
  277.  sys close close the file
  278.  lda smbuf get 1st char
  279.  bmi trybas basic file?
  280.  cmpa #$20 is it ascii?
  281.  blo trya6
  282.  lda termc check term char
  283.  cmpa #'& background?
  284.  bne trya4
  285.  ldd #plbst get '+b' string
  286.  std sargls
  287.  sys exec,cshell,bsrgls exec shell with '+b'
  288.  lbra doit3
  289. trya4 sys exec,cshell,sargls execute a shell
  290. trya6 lbra doit3 report error
  291.  
  292. trya7 lda rtcnt go to retry address
  293.  lsla
  294.  ldx #rtnlst
  295.  ldx a,x
  296.  jmp 0,x
  297.  
  298. rtclst fdb comnd,retry1,retry2,retry3
  299. rtnlst fdb doitx1,doitx2,doitx3,doit3
  300.  
  301. trybas cmpa #BHDBT is it basic file?
  302.  beq trybs2
  303.  cmpa #BHDBT2 new type?
  304. trybs2 bne tryP try Pascal program ***GDT
  305.  sys exec,cbasic,sargls try basic execution
  306.  lbra doit3 error?
  307.  
  308. tryP cmpa #PHDBT0 normal Pascal program? ***GDT
  309.  bne tryP1 no - try system ***GDT
  310.  sys exec,Pscl0,sargls try Pascal execution ***GDT
  311.  lbra doit3 error ***GDT
  312.  
  313. tryP1 cmpa #PHDBT1 system Pascal program? ***GDT
  314.  lbne doit3 no - error ***GDT
  315.  sys exec,Pscl1,sargls try to execute Pascal program ***GDT
  316.  lbra doit3 error ***GDT
  317.  
  318. *
  319. * Report fork error
  320. *
  321.  
  322. frkerr ldd #1 set file desc
  323.  sys write,frkmsg,FRKSIZ
  324.  lbra rprt
  325.  
  326.  pag
  327.  
  328. * exit shell
  329.  
  330. sexit ldd ctrm get term cond
  331. sexit4 sys term terminate this task!
  332.  pag
  333.  
  334. *
  335. * pars
  336. *
  337. * Parse the command line.  Return 'eq' if error.
  338. *
  339.  
  340. pars ldd #0 zero out data
  341.  std sifil
  342.  std sofil
  343.  std safil
  344.  sta prflg
  345.  deca set non zero
  346.  sta soft
  347.  ldd #fstlst set string pointer
  348.  std fstpt
  349.  ldd #arglst init pointers
  350.  std argpt
  351.  ldx bufpt point to command line
  352. pars1 lda 0,x+ sjip leading spaces
  353.  beq pars9 eol?
  354.  cmpa #SPACE
  355.  beq pars1
  356.  cmpa #TAB is it tab?
  357.  beq pars1
  358.  leax -1,x back up to prev char
  359.  stx bufpt save new pos
  360. pars2 lda soft last term a soft one?
  361.  beq pars7 if not, exit
  362.  lbsr gword get a word
  363.  tst quote quoted string?
  364.  bne pars6
  365.  lda 0,y get first chars of word
  366.  ldx #sifil point to list
  367.  cmpa #LTS is it '<'?
  368.  beq pars4
  369.  leax 2,x bump to next
  370.  cmpa #GTS is it '>'?
  371.  bne pars5
  372.  ldd 2,x is it ok?
  373.  bne pars8 error?
  374.  ldd 0,x
  375.  bne pars8
  376.  ldb 1,y get 2nd char
  377.  cmpb #GTS is it '>>'?
  378.  bne pars4
  379.  leax 2,x
  380. pars4 ldd 0,x already defined?
  381.  bne pars8 if so, error
  382.  leay 1,y move past '>'
  383.  cmpx #safil is it append?
  384.  bne pars45
  385.  leay 1,y
  386. pars45 sty 0,x save file pointer
  387.  tst 0,y null file name??
  388.  beq pars8
  389.  bra pars2 repeat
  390. pars5 lbsr subst check for substitution
  391.  beq pars2 null arg?
  392. pars6 ldx argpt get arg pos
  393.  sty 0,x++ save new arg
  394.  stx argpt
  395.  lbsr marg do arg matching
  396.  bcc pars2 repeat
  397.  bra pars10
  398. pars7 ldx argpt get arg pos
  399.  ldd #0 set null arg
  400.  std 0,x set null term
  401.  clz set status
  402.  rts return
  403. pars8 bsr synerr report error
  404.  sez set error
  405.  rts return
  406. pars9 clr termc set eol
  407.  rts return
  408. pars10 clr termc clear out term
  409.  tst intflg
  410.  beq syner4 interactive?
  411.  ldd #2 set st err
  412.  sys write,argms,ARGMS output error message
  413.  sez
  414.  rts return
  415.  
  416.  pag
  417.  
  418. *
  419. * synerr
  420. *
  421. * Report syntax error
  422. *
  423.  
  424. synerr clr termc clear out term
  425.  tst intflg interractive?
  426.  beq syner4
  427.  ldd #2 set file desc
  428.  sys write,syrms,SYSIZ write error message
  429. syner2 rts return
  430. syner4 ldd #$ff set error status
  431.  sys term exit!
  432.  
  433.  
  434. *
  435. * gword
  436. *
  437. * Parse a word and return pointer in Y.
  438. *
  439.  
  440. gword ldx bufpt get buffer pos
  441.  clr quote
  442.  lda 0,x get 1st char
  443.  cmpa #'( is it paren?
  444.  lbeq bldpr
  445.  cmpa #'" is it quote?
  446.  beq gword1
  447.  cmpa #'' is it quote?
  448.  bne gword2
  449. gword1 sta quote set quote mode
  450.  leax 1,x skip the '
  451.  stx bufpt save new start
  452. gword2 lda 0,x+ get a character
  453.  clr soft clear soft term flag
  454.  bsr tsttrm test for term
  455.  bne gword2 repeat til term
  456.  ldy bufpt get start of word
  457.  stx bufpt save new pos
  458.  rts return
  459.  
  460.  pag
  461.  
  462. *
  463. * tsttrm
  464. *
  465. * Test if char in A is term char.
  466. *
  467.  
  468. tsttrm tst quote quoted arg?
  469.  bne tsttr8
  470.  cmpa #SPACE is it space?
  471.  beq tsttr6
  472.  cmpa #TAB is it tab?
  473.  beq tsttr6
  474.  inc soft set soft term flag
  475.  cmpa #COMMA is it comma?
  476.  beq tsttr4
  477. tsttr1 clr soft
  478.  tsta is it null term?
  479.  bne tsttr2
  480.  clr termc set term char to null
  481.  rts return
  482. tsttr2 bsr chktrm check for hard term
  483.  beq tsttr4
  484.  rts no term
  485. tsttr4 sta termc save term character
  486.  clr -1,x set null word term
  487. tstt45 lda 0,x+ skip trailing spaces
  488.  cmpa #SPACE
  489.  beq tstt45
  490.  cmpa #TAB is it tab?
  491.  beq tstt45
  492.  leax -1,x
  493.  sez set term status
  494. tsttr5 rts return
  495. tsttr6 sta termc save term char
  496.  clr -1,x set null word term
  497. tsttr7 lda 0,x+ get next
  498.  beq tsttr1
  499.  cmpa #SPACE more spaces?
  500.  beq tsttr7
  501.  cmpa #TAB is it tab?
  502.  beq tsttr7
  503.  bsr chktrm check for hard term
  504.  beq tsttr4
  505.  leax -1,x
  506.  inc soft set soft term flag
  507.  sez set term status
  508.  rts return
  509. tsttr8 tsta term?
  510.  beq tsttr1
  511.  cmpa quote is it '?
  512.  bne tsttr5
  513.  lda #SPACE set up space term
  514.  bra tsttr6
  515.  
  516.  pag
  517.  
  518. *
  519. * chktrm
  520. *
  521. * Check if character in A is a hard term.
  522. *
  523.  
  524. chktrm ldy #trmtab point to table
  525. chktr2 cmpa 0,y+ look for char
  526.  beq chktr4
  527.  cmpy #trmend end of table?
  528.  bne chktr2
  529.  clz set no term
  530. chktr4 rts return
  531.  
  532. trmtab fcb ';,'|,'^,'&
  533. trmend equ *
  534.  
  535.  
  536. *
  537. * opsi
  538. *
  539. * Open new input file.
  540. *
  541.  
  542. opsi ldd sifil get file name
  543.  std iopn2 save in ind call
  544.  sys ind,iopn open file for read
  545.  bes opsi4 error?
  546.  bsr opchk check for block device
  547.  pshs d save file desc
  548. opsi2 ldd #0 get input file desc
  549.  sys close close it
  550.  ldd 0,s get new fd
  551.  sys dup dup this file
  552.  puls d
  553.  sys close close the file
  554.  clc set status
  555. opsi4 rts return
  556.  
  557. *
  558. * opso
  559. *
  560. * Open new output file.
  561. *
  562.  
  563. opso ldd sofil get file name
  564. opso1 std icrt2 set in ind call
  565.  sys ind,icrt creat file
  566.  bes opso4 error?
  567.  bsr opchk check for block device
  568.  pshs d save file desc
  569. opso2 ldd #1 get output file fd
  570.  sys close close the file
  571.  ldd 0,s get new fd
  572.  sys dup dup this file
  573.  puls d
  574.  sys close now close it
  575.  clc set status
  576. opso4 rts return
  577.  
  578.  pag
  579.  
  580. *
  581. * opsa
  582. *
  583.  
  584. opsa ldd safil get file name
  585.  std iopnw2 set up call
  586.  sys ind,iopnw open for write
  587.  bes opsa2
  588.  bsr opchk check for block device
  589.  pshs d save file desc
  590. opsa1 ldd 0,s get file desc
  591.  sys seek,0,0,2 seek to eof
  592.  bra opso2
  593. opsa2 cmpb #ENOFL is it no file error?
  594.  bne opsa4
  595.  ldd safil get file name
  596.  bra opso1 go create it
  597. opsa4 sec set error
  598.  rts return
  599.  
  600. *
  601. * opchk
  602. *
  603. * Check for block device
  604. *
  605.  
  606. opchk pshs d save file desc
  607.  sys ofstat,mfsb get status
  608.  lda mfsb+4 get modes
  609.  bita #2 is it block device?
  610.  beq opchk2
  611.  leas 4,s
  612.  ldd #0 set status
  613.  sec
  614.  rts return
  615. opchk2 puls d get file desc
  616.  rts
  617.  
  618.  
  619. *
  620. * getlin
  621. *
  622. * Get an input line and put it in the buffer.
  623. *
  624.  
  625. getlin ldx #buffer point to buffer
  626.  clr 0,-s set count
  627. getli2 bsr gtch get a character
  628.  beq getli6 eof?
  629.  sta 0,x+ save char in buffer
  630.  inc 0,s bump count
  631.  cmpa #$d is it cr?
  632.  bne getli2
  633.  clr -1,x set null term
  634.  clz set status
  635. getli4 puls b,pc return
  636. getli6 tst supf doing startup?
  637.  beq getli4 if not - exit
  638.  inc intflg set interactive
  639.  ldd ifd get file desc
  640.  sys close close the input file
  641.  ldd #0 reset input file to 0
  642.  std ifd
  643.  ldd #linbuf reset pointers
  644.  std linpt
  645.  std linend
  646.  sez set status
  647.  puls b,pc return
  648.  
  649.  pag
  650.  
  651. *
  652. * gtch
  653. *
  654. * Get a character from linbuf
  655. *
  656.  
  657. gtch pshs x save pointer
  658.  tst coptf check c opt flag
  659.  bne gctc
  660. gtch2 ldx linpt get line pointer
  661.  cmpx linend end of current?
  662.  bne gtch4
  663.  ldd ifd set file desc
  664.  sys read,linbuf,512 read in data
  665.  bes gtch6 error?
  666.  cmpd #0 eof?
  667.  beq gtch6
  668.  ldx #linbuf set start pointer
  669.  stx linpt
  670.  leax d,x mark end of buffer
  671.  stx linend set end
  672.  ldx linpt reset to start
  673. gtch4 lda 0,x+ get a character
  674.  stx linpt save pointer
  675.  clz set status
  676.  puls x,pc return
  677. gtch6 sez set eof status
  678.  puls x,pc return
  679.  
  680.  
  681. *
  682. * gctc
  683. *
  684.  
  685. gctc ldx cbpt get command pointer
  686.  beq gctc6
  687.  lda 0,x+ get a character
  688.  beq gctc4
  689.  cmpa #$d end of line?
  690.  bne gctc5
  691.  tst 0,x check for term
  692.  bne gctc5
  693. gctc4 lda #$d set end of line
  694.  ldx #0 null out pointer
  695. gctc5 stx cbpt set new pointer
  696.  clz set ok status
  697. gctc6 puls x,pc return
  698.  
  699.  pag
  700.  
  701. *
  702. * bdfil
  703. *
  704. * Report bad redirection file
  705. *
  706.  
  707. bdfil clr termc clear out term char
  708.  tst intflg interactive?
  709.  beq bdfil2
  710.  pshs d
  711.  ldd #2
  712.  sys write,bdfms,BDSIZ output error
  713.  puls d get status back
  714. bdfil2 sys term term this task
  715.  
  716.  
  717. *
  718. * rprt
  719. *
  720. * Report any tasks which have terminated.
  721. *
  722.  
  723. rprt ldx #attab point to async table
  724. rprt2 tst 2,x check its activity
  725.  bne rprt4
  726. rprt3 leax 9,x move to next entry
  727.  cmpx #atend end of table?
  728.  bne rprt2
  729.  lbra sh0 go to main loop
  730. rprt4 pshs x save entry
  731.  ldd 0,x get task id
  732.  bsr prtid
  733.  ldd #1 output message
  734.  sys write,ttmsg,TTMSZ
  735.  ldx 0,s get table pointer
  736.  lda 3,x get term status
  737.  lbsr ptmsg print term message
  738.  puls x get entry
  739.  ldd #0 zero out entry
  740.  std 0,x
  741.  std 2,x
  742.  sta 4,x
  743.  bra rprt3
  744.  
  745.  pag
  746.  
  747. *
  748. * async
  749. *
  750. * Run a job async.
  751. *
  752.  
  753. async ldx #attab point to async table
  754. async2 ldd 0,x look for empty slot
  755.  beq async4
  756.  leax 9,x move to next entry
  757.  cmpx #atend
  758.  bne async2
  759.  ldd #2 set file desc
  760.  sys write,tmtms,TMTSZ output error
  761.  lbra pwait wait for task
  762. async4 puls d get task id
  763.  std 0,x save in table
  764.  clr 2,x set activity
  765.  pshs d,x save pos
  766.  sys time,asytim get current time
  767.  ldx 2,s reset pos
  768.  ldu #asytim point to time
  769.  ldd 0,u xfr time
  770.  std 5,x
  771.  ldd 2,u
  772.  std 7,x
  773.  puls d,x
  774.  bsr prtid print task id
  775.  ldd #1 set file desc
  776.  sys write,rtmsg,RTSZ
  777.  lbra sh0 goto main loop
  778.  
  779. *
  780. * prtid
  781. *
  782.  
  783. prtid ldx #idbuf+3 point to buffer
  784.  lbsr decstn convert to string
  785.  addd #3
  786.  std wrid2 save length
  787.  ldx #idbuf point to buffer
  788.  ldd #('*<<8)|'*
  789.  std 0,x
  790.  ldd #$2000|'T
  791.  std 2,x
  792.  ldd #1 set file desc
  793.  sys ind,wrid write out id
  794.  rts return
  795.  
  796. *
  797. * chasy
  798. *
  799. * Check for terminated async job.
  800. *
  801.  
  802. chasy ldy #attab point to async table
  803. chasy2 cmpd 0,y look for this guy
  804.  beq chasy4
  805.  leay 9,y move to next entry
  806.  cmpy #atend end of table?
  807.  bne chasy2
  808.  rts non found
  809. chasy4 stx 3,y save term status
  810.  inc 2,y set term stat
  811.  rts return
  812.  
  813.  pag
  814.  
  815. *
  816. * dpipe
  817. *
  818. * Create job as part of pipe
  819. *
  820.  
  821. dpipe tst pipmod in pipe?
  822.  beq dpipe2 if not, go ahead
  823.  ldd apprdf get read file
  824.  sys close close it
  825. dpipe2 inc pipmod set pipe mode
  826.  ldd pprdf get read file
  827.  std apprdf save it
  828.  ldd ppwrf get write file
  829.  sys close it
  830.  puls d get task id
  831.  lbra sh0 goto main
  832.  
  833. *
  834. * cpipe
  835. *
  836. * Create a pipe
  837. *
  838.  
  839. cpipe sys crpipe create it
  840.  bes cpipe2 error?
  841.  std pprdf save read file
  842.  stx ppwrf save write file
  843.  lbra sh96 go continue
  844.  
  845. cpipe2 clr termc set null term
  846.  ldd #2 set error chan
  847.  sys write,nopms,NPSZ
  848.  lbra sh0 goto main
  849.  
  850.  pag
  851.  
  852. *
  853. * spipe
  854. *
  855. * Setup pipe io.
  856. *
  857.  
  858. spipe lda termc check for pipe
  859.  cmpa #'|
  860.  beq spipe2
  861.  cmpa #'^
  862.  bne spipe4
  863. spipe2 ldd #1 close standard output
  864.  sys close
  865.  ldd ppwrf get write file
  866.  sys dup make file 1
  867.  ldd ppwrf get write file
  868.  sys close close it
  869.  ldd pprdf get read file
  870.  sys close close it
  871. spipe4 tst pipmod in pipe mode?
  872.  beq spipe6
  873.  ldd #0 close standard input
  874.  sys close
  875.  ldd apprdf get read file
  876.  sys dup dup it
  877.  ldd apprdf get read file
  878.  sys close close it
  879. spipe6 rts return
  880.  
  881.  
  882.  pag
  883.  
  884. *
  885. * scmnd
  886. *
  887. * Check for shell command.  If it is, return
  888. * 'eq' and address of command in X.
  889. *
  890.  
  891. scmnd ldy #sctab point to command table
  892. scmnd1 ldx arglst point to arg
  893. scmnd2 lda 0,x+ get a character
  894.  beq scmnd6 term char?
  895.  tst 0,y end of command?
  896.  beq scmnd4
  897.  cmpa 0,y+ does it match?
  898.  beq scmnd2 if so, do next char
  899. scmnd4 tst 0,y+ find end of name
  900.  bne scmnd4
  901.  leay 2,y skip command address
  902.  cmpy #scend end of table?
  903.  bne scmnd1 if not, repeat
  904.  clz set no find status
  905.  rts return
  906. scmnd6 tst 0,y end of command?
  907.  bne scmnd4 if so, match!
  908.  ldx 1,y get address
  909.  sez set find status
  910.  rts return
  911.  
  912. *
  913. * chd
  914. *
  915. * Change dir command
  916. *
  917.  
  918. chd ldd arglst+2 get 2nd arg
  919.  bne chd1 default arg?
  920.  ldd #defdir point to home
  921. chd1 pshs d
  922.  lda #chdir set up command
  923.  pshs a
  924.  leax 0,s point to call data
  925.  sys indx do sys call
  926.  lbec rprt error?
  927.  ldd #2 set file desc
  928.  sys write,ccdrms,CCDSZ output error
  929.  lbra rprt goto main loop
  930.  
  931. *
  932. * login
  933. *
  934. * Log in command.
  935. *
  936.  
  937. login sys defacc,0 set default to 0
  938.  sys status,utnam,mfsb get status
  939.  ldd mfsb+11 get file size
  940.  beq login2 if 0 - single user mode
  941.  sys exec,logn,arglst exec login
  942. login2 sys term term if error
  943.  
  944.  pag
  945.  
  946. *
  947. * log
  948. *
  949. * log out command
  950. *
  951.  
  952. log ldd #0 set term status
  953.  sys term term shell
  954.  
  955. *
  956. * wait
  957. *
  958. * Wait on asynch tasks.
  959. *
  960.  
  961. cwait ldd #0
  962.  std wtid set id to 0
  963.  ldx arglst+2 get arg
  964.  bne cwait6 is there one?
  965.  ldx #attab point to task table
  966. cwait1 ldd 0,x look for active tasks
  967.  bne cwait2 found one?
  968.  leax 9,x get next entry
  969.  cmpx #atend end of table?
  970.  bne cwait1
  971.  ldd #1 set file desc
  972.  sys write,nchms,NCHSZ output error meg
  973.  lbra sh0 go to main loop
  974. cwait2 sys cpint,2,ctwait set int trap
  975.  ldx #attab point to task table
  976. cwait3 ldd 0,x check for task
  977.  beq cwait4
  978.  tst 2,x has it termed?
  979.  beq cwait5
  980. cwait4 leax 9,x get next entry
  981.  cmpx #atend end of table?
  982.  bne cwait3
  983. cwai45 sys cpint,2,1 ignore ints
  984.  lbra rprt go report tasks termed
  985. cwait5 sys wait wait for task
  986.  lbsr chasy update task table
  987.  ldx #attab point to table
  988.  bra cwait3 repeat loop
  989. cwait6 lbsr decvt convert task id
  990.  bne cwai75 error?
  991.  std wtid set id
  992.  sys cpint,2,ctwait set ints
  993.  ldd wtid get task id
  994.  ldx #attab point to task table
  995. cwait7 cmpd 0,x look for task id
  996.  beq cwait8
  997.  leax 9,x get next entry
  998.  cmpx #atend end of table?
  999.  bne cwait7
  1000. cwai75 ldd #1 set file desc
  1001.  sys write,ntfms,NTSZ output error
  1002.  lbra sh0
  1003. cwait8 tst 2,x task active?
  1004.  bne cwai45
  1005.  sys wait wait for it
  1006.  lbsr chasy update info
  1007.  ldx #attab point to task table
  1008.  ldd wtid get task id
  1009.  bra cwait7
  1010.  
  1011. *
  1012. * ctwait
  1013. *
  1014.  
  1015. ctwait sys cpint,2,1 ignore ints
  1016.  ldd #rprt set new pc
  1017.  std 10,s
  1018.  rti return (exit 'wait')
  1019.  
  1020.  pag
  1021.  
  1022. *
  1023. * jobs
  1024. *
  1025. * Output list of running tasks.
  1026. *
  1027.  
  1028. jobs clr 0,-s set counter to 0
  1029.  ldx #attab point to task table
  1030. jobs1 ldd 0,x get task number
  1031.  bne jobs4
  1032. jobs2 leax 9,x bump to next entry
  1033.  cmpx #atend end of table?
  1034.  bne jobs1
  1035.  ldb 0,s+ get task count
  1036.  bne jobs3
  1037.  ldd #1 output error
  1038.  sys write,nchms,NCHSZ
  1039. jobs3 lbra rprt goto main loop
  1040. jobs4 inc 0,s bump count
  1041.  pshs x save index
  1042.  lbsr prtid print task id
  1043.  ldd #1 set file desc
  1044.  sys write,ttmsg,TTMSZ output message
  1045.  ldx 0,s get table entry
  1046.  ldd 5,x get time
  1047.  std asytim save in block
  1048.  ldd 7,x
  1049.  std asytim+2
  1050.  ldx #asytim point to time block
  1051.  lbsr tmloc convert time
  1052.  lbsr tasc
  1053.  ldd #1 set file desc
  1054.  sys write,tstr,25 output time
  1055.  puls x
  1056.  bra jobs2 repeat
  1057.  
  1058. *
  1059. * dprm
  1060. *
  1061. * Set default permissions (command)
  1062. *
  1063.  
  1064. dprm clr slot clear out value
  1065.  ldu #arglst+2 set arg ptr
  1066. dprm2 ldx 0,u++ get an arg
  1067.  beq dprm5 end of args?
  1068.  ldd 0,x++ get 1st 2 chars of arg
  1069.  cmpb #'- check if valid
  1070.  bne dprm4
  1071.  bsr setp set up perms
  1072.  bne dprm2 error?
  1073. dprm4 lbsr synerr report syntax error
  1074.  lbra rprt go to main loop
  1075. dprm5 ldb slot get value
  1076.  stb isdp2 set in os call
  1077.  sys ind,isdp set perms
  1078.  lbra rprt exit
  1079.  
  1080. *
  1081. * setp
  1082. *
  1083. * Get the permission value
  1084. *
  1085.  
  1086. setp pshs a save type
  1087.  bsr getp get rwx bits
  1088.  puls a get type
  1089.  beq setp6 error?
  1090.  cmpa #'u is it user?
  1091.  beq setp3
  1092.  cmpa #'o is it other?
  1093.  bne setp6 if not - error
  1094. setp2 aslb shift bits to other pos
  1095.  aslb
  1096.  aslb
  1097. setp3 orb slot or in with others
  1098.  stb slot save new
  1099.  clz set status
  1100.  rts return
  1101. setp6 sez set error
  1102.  rts return
  1103.  
  1104. *
  1105. * getp
  1106. *
  1107. * Process the rwx args
  1108. *
  1109.  
  1110. getp clr 0,-s save mask
  1111. getp2 clrb set count
  1112.  lda 0,x+ get char of arg
  1113.  beq getp6 end of arg?
  1114.  incb set for r
  1115.  cmpa #'r is it r?
  1116.  beq getp4
  1117.  aslb set for w
  1118.  cmpa #'w is it w?
  1119.  beq getp4
  1120.  aslb set for x
  1121.  cmpa #'x is it x?
  1122.  bne getp7
  1123. getp4 orb 0,s or in new mask bit
  1124.  stb 0,s save it
  1125.  bra getp2
  1126. getp6 clz set status
  1127.  puls b,pc return
  1128. getp7 sez set error
  1129.  puls b,pc return
  1130.  
  1131. *
  1132. * wrtpr
  1133. *
  1134. * Output prompt line.
  1135. *
  1136.  
  1137. wrtpr tst tprfl time prompt?
  1138.  beq wrtpr2
  1139.  sys time,shtime get current time
  1140.  ldx #shtime point to time
  1141.  lbsr tmloc convert time
  1142.  lbsr tasc
  1143.  ldd #1 set file desc
  1144.  sys write,tstr,5 output time
  1145. wrtpr2 ldd #1 set file desc
  1146.  ldu iwrtp3 null string?
  1147.  beq wrtpr4
  1148.  sys ind,iwrtp output prompt
  1149. wrtpr4 rts return
  1150.  
  1151.  pag
  1152.  
  1153. *
  1154. * stprm
  1155. *
  1156. * Set prompt command.
  1157. *
  1158.  
  1159. stprm clr tprfl clear time mode
  1160.  ldx arglst+2 get arg
  1161.  beq stprm2 is it null?
  1162.  lda 0,x get 1st char
  1163.  cmpa #TPCH requesting time prompt?
  1164.  bne stprm4
  1165.  sta tprfl set flag
  1166.  leax 1,x eat the +
  1167.  bra stprm4
  1168. stprm1 std iwrtp3 set in call
  1169.  lbra rprt go to main loop
  1170. stprm2 ldd #prompt set up default prompt
  1171.  std iwrtp2
  1172.  ldd #3 set length
  1173.  bra stprm1
  1174. stprm4 clrb set count to 0
  1175.  ldy #prmbuf point to prompt buffer
  1176.  sty iwrtp2 set in call
  1177. stprm5 lda 0,x+ xfr new prompt
  1178.  sta 0,y+
  1179.  beq stprm6 end?
  1180.  incb bump count
  1181.  cmpb #24 max yet?
  1182.  bne stprm5
  1183.  decb
  1184. stprm6 clra
  1185.  bra stprm1
  1186.  
  1187.  pag
  1188.  
  1189. *
  1190. * bldpr
  1191. *
  1192. * Build the paren string for sub shell.
  1193. *
  1194.  
  1195. bldpr leax 1,x skip paren
  1196.  ldb #1 set flags
  1197.  stb prflg
  1198. bldpr2 lda 0,x+ get a character
  1199.  beq bldpr8 error?
  1200.  cmpa #$d is it cr?
  1201.  beq bldpr8 error?
  1202.  cmpa #') end of list?
  1203.  beq bldpr4
  1204.  cmpa #'( nesting parens?
  1205.  bne bldpr2
  1206.  incb bump nest count
  1207.  bra bldpr2 repeat
  1208. bldpr4 decb dec the nest count
  1209.  bne bldpr2 zero level?
  1210.  clr soft
  1211.  lda #SPACE set space term
  1212.  sta -1,x
  1213.  lbsr tsttrm test term char
  1214.  ldy bufpt get buffer start
  1215.  leay 1,y skip ')'
  1216.  sty subrg2 save arg ptr
  1217.  sty bsbrg2
  1218.  stx bufpt save new buf ptr
  1219.  rts return
  1220. bldpr8 lbsr synerr set error
  1221.  lbra sh0 goto main loop
  1222.  
  1223. *
  1224. * dosub
  1225. *
  1226. * Do the sub shell execution.
  1227. *
  1228.  
  1229. dosub lda termc check for background
  1230.  cmpa #'&
  1231.  bne dosub4
  1232.  sys exec,cshell,bsubrg exec the shell
  1233.  sys term error terminate
  1234. dosub4 sys exec,cshell,subrg exec the shell
  1235.  sys term
  1236.  
  1237.  pag
  1238.  
  1239. *
  1240. * cfile
  1241. *
  1242. * Close all files
  1243. *
  1244.  
  1245. cfile ldd #3 start with file 3
  1246.  pshs d save file desc
  1247. cfile2 sys close close the file
  1248.  ldd 0,s get fd
  1249.  addd #1 bump by 1
  1250.  std 0,s
  1251.  cmpd #NFILES end of files?
  1252.  bne cfile2
  1253.  puls d,pc return
  1254.  
  1255. *
  1256. * subst
  1257. *
  1258. * Substitute arguments
  1259. *
  1260.  
  1261. subst pshs y save arg pointer
  1262.  lda 0,y get character
  1263.  cmpa #'$ is it param?
  1264.  beq subst2
  1265. subst1 puls y,pc return
  1266. subst2 lda 1,y check 2nd char
  1267.  beq subst7 if null, exit
  1268.  leax 1,y point to number
  1269.  bsr decvt convert to binary
  1270.  bne subst1
  1271.  cmpd #255 is it greater than 255?
  1272.  bhi subst1
  1273.  bra subst4
  1274. subst3 leas 2,s clean up stack
  1275.  rts return
  1276. subst4 ldx subpt get sub pointer
  1277.  beq subst3 is it null?
  1278.  pshs b
  1279. subst5 ldd 0,x check for null arg
  1280.  puls b
  1281.  beq subst3
  1282.  tstb found it?
  1283.  beq subst6 is this the one?
  1284.  leax 2,x bump to next
  1285.  decb dec the count
  1286.  pshs b
  1287.  bra subst5
  1288. subst6 ldy 0,x get arg pointer
  1289. subst7 leas 2,s fix stack
  1290.  clz set status
  1291.  rts return
  1292.  
  1293. *
  1294. * abtrm
  1295. *
  1296. * Report abnormal termination of tasks.
  1297. *
  1298.  
  1299. abtrm lda ctrm get term status
  1300.  bne abtrm2 is it abnormal
  1301.  rts if not - return
  1302. abtrm2 ldy #comnd point to buffer
  1303.  ldb #$d set up cr
  1304.  stb 0,y+ set in buffer
  1305.  ldb #1 set count to 1
  1306.  bra ptmsg1
  1307.  
  1308. *
  1309. * ptmsg
  1310. *
  1311. * Print termination message.
  1312. *
  1313.  
  1314. ptmsg ldy #comnd point to out buffer
  1315.  clrb set count to 0
  1316. ptmsg1 pshs a save status
  1317.  asla
  1318.  ldx #tmstb point to message table
  1319.  ldx a,x get message pointer
  1320. ptmsg2 lda 0,x+ get a char
  1321.  incb bump the count
  1322.  sta 0,y+ save the char
  1323.  bne ptmsg2 repeat til null
  1324.  lda 0,s+ get status
  1325.  bpl ptmsg6 core dumped?
  1326.  decb back up count
  1327.  leay -1,y
  1328.  ldx #crdms point to 'core dump' message
  1329. ptmsg4 lda 0,x+ move the string
  1330.  incb
  1331.  sta 0,y+
  1332.  bne ptmsg4
  1333. ptmsg6 lda #$d get cr
  1334.  sta -1,y set at end of list
  1335.  clra
  1336.  std iwrt2 set write count
  1337.  ldd #1 set file desc
  1338.  sys ind,iwrt output string
  1339.  rts return
  1340.  
  1341.  pag
  1342.  
  1343. *
  1344. * decvt
  1345. *
  1346. * Decimal convert routine.  Convert ascii string
  1347. * pointed at by x and null terminated.
  1348. * Return number in D and ne if error.
  1349. *
  1350.  
  1351. decvt ldd #0 set up zero
  1352.  pshs d
  1353. decvt2 lda 0,x+ get character
  1354.  beq decvt4 end of list?
  1355.  cmpa #'0 check for valid number
  1356.  blo decvt3 error?
  1357.  cmpa #'9
  1358.  bhi decvt3
  1359.  anda #$F mask character
  1360.  pshs a save digit
  1361.  ldd 1,s get number
  1362.  aslb multiply by 8
  1363.  rola
  1364.  aslb
  1365.  rola
  1366.  aslb
  1367.  rola
  1368.  addd 1,s add in original twice
  1369.  addd 1,s
  1370.  addb 0,s+ add in new digit
  1371.  adca #0
  1372.  std 0,s save result
  1373.  bra decvt2 repeat
  1374. decvt3 clz set error
  1375. decvt4 puls d,pc return
  1376.  
  1377.  pag
  1378.  
  1379. *
  1380. * decst
  1381. *
  1382. * Convert the number in D into an ascii string
  1383. * representing a decimal number.  The string
  1384. * is pointed at by X (X should be set on entry!)
  1385. * Also on exit, D has the length of the string.
  1386. * The second entry point, 'decstn' will not print
  1387. * leading spaces for leading zeroes, but will
  1388. * suppress all leading zero info.  All strings
  1389. * start with a space.
  1390. *
  1391.  
  1392. decst pshs x save user pointer
  1393.  clr 0,-s set suppression flag
  1394.  bra decst2
  1395. *
  1396. decstn pshs x save user pointer
  1397.  clr 0,-s
  1398.  inc 0,s set for no fielding
  1399. decst2 pshs a
  1400.  lda #$20 setup leading space
  1401.  sta 0,x+ save in buffer
  1402.  puls a
  1403.  clr 0,-s set up bookkeeping
  1404.  clr 0,-s
  1405.  ldy #conlst point to constants
  1406. decst4 cmpd 0,y compare number to constant
  1407.  blo decst5
  1408.  subd 0,y do subtraction of constant
  1409.  inc 1,s bump digits counter
  1410.  bra decst4
  1411. decst5 pshs a save number
  1412.  tst 2,s zero digit?
  1413.  bne decst6
  1414.  tst 1,s any numbers output yet?
  1415.  bne decst6
  1416.  tst 3,s doing suppression?
  1417.  bne decst8
  1418.  lda #$20 set up space
  1419.  bra decst7
  1420. decst6 lda 2,s get digit count
  1421.  inc 1,s set 'got one' flag
  1422.  ora #$30 make ascii
  1423. decst7 sta 0,x+ save in buffer
  1424. decst8 puls a reset number
  1425.  clr 1,s clear out digit
  1426.  leay 2,y bump constant ptr
  1427.  cmpy #conend end of list?
  1428.  bne decst4
  1429.  leas 3,s clean up stack
  1430.  orb #$30 make last digit
  1431.  stb 0,x+ save in buffer
  1432.  clr 0,x null terminate string
  1433.  tfr x,d
  1434.  subd 0,s calculate string length
  1435.  puls x,pc return
  1436.  
  1437.  pag
  1438.  
  1439. *
  1440. * marg
  1441. *
  1442. * Check dor match list processing
  1443. *
  1444.  
  1445. marg tfr y,x get arg pointer
  1446.  tst quote quotes arg?
  1447.  bne marg9 if so - skip
  1448.  tst prflg paren command?
  1449.  bne marg9
  1450.  bsr sum do set up for match
  1451.  bes marg9 error?
  1452.  ldx argpt get arg pointer
  1453.  leax -2,x back up
  1454.  stx argpt
  1455.  stx starg save start arg
  1456.  lbsr opnmf open match file
  1457.  bes marg8 error?
  1458. marg4 lbsr cmntr compare names
  1459.  bes marg7 end of lists?
  1460.  bne marg4 match?
  1461.  inc mone set matched one flag
  1462.  ldx fstpt get string pointer
  1463.  ldu argpt get arg pointer
  1464.  stx 0,u++ save new arg
  1465.  stu argpt
  1466.  ldu #front get front part
  1467.  ldy #tstbuf+2 point to string
  1468. marg6 lda 0,u+ get char
  1469.  beq marg65 null?
  1470.  sta 0,x+ move it
  1471.  cmpx #fstlst+4096
  1472.  bhs marg10 overflow?
  1473.  bra marg6
  1474. marg65 cmpx #fstlst+4096
  1475.  bhs marg10
  1476.  lda 0,y+ get a character
  1477.  sta 0,x+ move the character
  1478.  bne marg65 end of arg?
  1479.  stx fstpt save string pointer
  1480.  bra marg4 repeat
  1481. marg7 ldd mffd get file desc
  1482.  sys close close the file
  1483.  tst mone any matches?
  1484.  beq marg8
  1485.  ldd #0 set null arg pointer
  1486.  std [argpt]
  1487.  ldx starg get starting arg pos
  1488.  lbra sort go sort args & return
  1489. marg8 ldx argpt fix up arg ptr
  1490.  leax 2,x
  1491.  stx argpt
  1492. marg9 clc clear error
  1493.  rts return
  1494. marg10 ldd mffd get file desc
  1495.  sys close close it
  1496.  sec set error
  1497.  rts
  1498.  
  1499.  pag
  1500.  
  1501. *
  1502. * sum
  1503. *
  1504. * Setup for match tests.
  1505. *
  1506.  
  1507. sum clr mone
  1508.  ldy #front point to front name buffer
  1509. sum2 lda 0,x+ get a character
  1510.  sta 0,y+ move to front buf
  1511.  beq sum6 end of string?
  1512.  cmpa #'* check for match char
  1513.  beq sum3
  1514.  cmpa #'?
  1515.  beq sum3
  1516.  cmpa #'[
  1517.  bne sum2
  1518. sum3 lda -1,y move back thru string
  1519.  cmpa #'/ look for '/'
  1520.  beq sum4
  1521.  leay -1,y
  1522.  leax -1,x
  1523.  cmpy #front or beginning of string
  1524.  bne sum3
  1525. sum4 clr 0,y set term char
  1526.  stx mtpt set match pointer
  1527. sum5 lda 0,x+ look at rest of string
  1528.  beq sum7 end?
  1529.  cmpa #'/ is it '/'?
  1530.  bne sum5
  1531. sum6 sec set error
  1532.  rts return
  1533. sum7 clc set ok status
  1534.  rts return
  1535.  
  1536.  pag
  1537.  
  1538. *
  1539. * opnmf
  1540. *
  1541. * Open match file.
  1542. *
  1543.  
  1544. opnmf sys open,front,0 open the file for read
  1545.  bes opnmf4 error?
  1546.  std mffd save file desc
  1547.  sys ofstat,mfsb get status
  1548.  lda mfsb+4 get mode byte
  1549.  bita #$8 is it dir?
  1550.  beq opnmf2 if not - error
  1551.  clc
  1552.  rts return
  1553. opnmf2 ldd mffd get fd
  1554.  sys close close the file
  1555. opnmf4 sec set error
  1556.  rts return
  1557.  
  1558. *
  1559. * cmntr
  1560. *
  1561. * Compare names for match test.  Return 'eq'
  1562. * if match, 'cs' if error or no more names.
  1563. *
  1564.  
  1565. cmntr ldd mffd get file desc
  1566.  sys read,tstbuf,16 read entry
  1567.  bes cmntr4 error?
  1568.  cmpd #0 eof?
  1569.  beq cmntr4
  1570.  clr tstbuf+16 set null term
  1571.  ldd tstbuf check for deleted entry
  1572.  beq cmntr repeat
  1573.  ldx mtpt get match string
  1574.  ldy #tstbuf+2 point to test name
  1575.  lda 0,y get 1st char
  1576.  cmpa #'. is it '.'?
  1577.  bne cmntr2
  1578.  leay 1,y skip char
  1579.  cmpa 0,x+ must match!
  1580.  bne cmntr3
  1581. cmntr2 bsr match do match test
  1582. cmntr3 clc set ok status
  1583.  rts return
  1584. cmntr4 sec set error
  1585.  rts return
  1586.  
  1587.  pag
  1588.  
  1589. *
  1590. * match
  1591. *
  1592. * See if the match string pointed at by X matches
  1593. * the string pointed at by Y.  Return 'eq' if
  1594. * they match.  This routine handles the following
  1595. * special match characters: *, ?, [...].
  1596. *
  1597.  
  1598. match pshs x,y save pointers
  1599. match1 lda 0,x+ get character
  1600.  beq match2 end of string?
  1601.  cmpa #'* is it star?
  1602.  beq mstar
  1603.  tst 0,y end of test string?
  1604.  beq match3
  1605.  cmpa #'? is it '?'
  1606.  beq mqust
  1607.  cmpa #'[ is it '[...]' ?
  1608.  beq mspcl
  1609.  cmpa 0,y+ compare characters
  1610.  beq match1 if match, repeat!
  1611.  puls x,y,pc return - no match
  1612. match2 tst 0,y end of test string?
  1613.  puls x,y,pc if so - match!
  1614. match3 clz set no match
  1615. match4 puls x,y,pc return
  1616.  
  1617. * match question mark
  1618.  
  1619. mqust leay 1,y anything matches!
  1620.  bra match1 repeat
  1621.  
  1622. * match start ('*')
  1623.  
  1624. mstar tst 0,x end of match string?
  1625.  beq match4 if so - match!
  1626. mstar2 tst 0,y end of string?
  1627.  beq match3 if so - no match
  1628.  bsr match check reset of string
  1629.  beq match4 if 'eq' - match!
  1630.  leay 1,y skip a character
  1631.  bra mstar2 repeat
  1632.  
  1633.  pag
  1634.  
  1635. * match special list '[...]'
  1636.  
  1637. mspcl ldb 0,y+ get a character
  1638. mspcl2 lda 0,x+ get match char
  1639.  beq match3 if end - no match
  1640.  cmpa #'] end of special?
  1641.  beq match3 if so - no match
  1642.  cmpa #'- is it sep char?
  1643.  beq mspcl5
  1644.  cmpb -1,x compare the characters
  1645.  bne mspcl2 if no match - repeat
  1646. mspcl4 lda 0,x+ look for ']'
  1647.  beq match3 if null - no match!
  1648.  cmpa #']
  1649.  bne mspcl4
  1650.  bra match1 we have a match!
  1651. mspcl5 cmpb -2,x check 1st char in range (1-2)
  1652.  blo mspcl6 if lower, not here
  1653.  cmpb 0,x check 2nd char of range
  1654.  bls mspcl4 if 'ls' - match!
  1655. mspcl6 leax 1,x skip range char
  1656.  bra mspcl2 repeat
  1657.  
  1658.  pag
  1659.  
  1660. *
  1661. * sort routine
  1662. *
  1663. * General sort routine should be called with pointer
  1664. * to a list of pointers stored in X.  List is terminated
  1665. * by two zero bytes.  Each pointer in list points to
  1666. * a string which is terminated by a zero byte.
  1667. * On return, pointers in list are rearranged and all
  1668. * registers are destroyed.
  1669. *
  1670.  
  1671. sort ldd 0,x check first entry
  1672.  beq sort9 exit if null list
  1673.  ldd #$FFFF default end of list
  1674.  pshs x,d save begin and end
  1675.  leas -1,s did an exchange flag
  1676. sort1 ldx 3,s get begin of list
  1677.  clr 0,s show no exchange
  1678. sort2 ldd 2,x another entry?
  1679.  beq sort6 finished pass if not
  1680.  leay 2,x end of pass?
  1681.  cmpy 1,s
  1682.  beq sort6 skip if so
  1683. * compare current and next entry
  1684.  ldy 0,x get pointer to 1st
  1685.  ldu 2,x get pointer to 2nd
  1686. sort3 lda 0,y+ get char. from 1st
  1687.  beq sort5 no exchange if terminator
  1688.  ldb 0,u get char. from 2nd
  1689.  beq sort4 do exchange if terminator
  1690.  cmpa 0,u+ else, compare characters
  1691.  beq sort3 loop if equal
  1692.  blo sort5 skip if no exchange
  1693. * exchange two entries
  1694. sort4 ldy 2,x get 2nd entry
  1695.  ldd 0,x get 1st entry
  1696.  std 2,x swap them
  1697.  sty 0,x
  1698.  lda #1
  1699.  sta 0,s show exchange done
  1700. * do next two entries
  1701. sort5 leax 2,x bump current pointer
  1702.  bra sort2
  1703. * finished pass, see if another required
  1704. sort6 stx 1,s save new end pointer
  1705.  tst 0,s any exchanges in pass?
  1706.  bne sort1 another pass required
  1707. sort8 leas 5,s fix stack
  1708. sort9 clc
  1709.  rts
  1710.  
  1711.  pag
  1712.  
  1713. *
  1714. * tmloc
  1715. *
  1716. * Convert time pointed at by x to vector time (local).
  1717. *
  1718.  
  1719. tmloc ldd 0,x get time
  1720.  std ltime
  1721.  ldd 2,x
  1722.  std ltime+2
  1723.  lda 7,x get day light savings flag
  1724.  sta dlflg
  1725.  clr eutc init flag
  1726.  ldd 5,x get time zone
  1727.  bpl tmloc2 west of GMT?
  1728.  inc eutc if not - set flag
  1729.  coma and make pos number
  1730.  comb
  1731.  addd #1
  1732. tmloc2 std r0+2 save time zone
  1733.  ldd #60 calculate zone seconds
  1734.  std r1+2
  1735.  ldd #0 set hi bytes to 0
  1736.  std r0
  1737.  std r1
  1738.  lbsr lmul calculate time zone seconds
  1739.  ldd r0 get result
  1740.  std tzn save it
  1741.  ldd r0+2
  1742.  std tzn+2
  1743.  lbsr adjtim adjust time for zone
  1744.  ldx #ltime point to time
  1745.  lbsr tmutc convert to vector
  1746.  tst dlflg do dlst?
  1747.  beq tmloc6
  1748.  lbsr chkdl in dlst?
  1749.  bne tmloc6
  1750. tmloc5 ldd #3600 adjust for dlst
  1751.  addd ltime+2
  1752.  std ltime+2
  1753.  ldd ltime
  1754.  adcb #0
  1755.  adca #0
  1756.  std ltime
  1757.  ldx #ltime point to time
  1758.  lbsr tmutc convert to vector
  1759.  inc daylit set daylit flag
  1760. tmloc6 ldx #second point to vector
  1761.  rts return
  1762.  
  1763.  pag
  1764.  
  1765. *
  1766. * tmutc
  1767. *
  1768. * Convert the internal system time (4 bytes
  1769. * pointed at by X on entry) to an 18 byte
  1770. * vector representing the broken down time.
  1771. * The time in this form is UTC (Universal
  1772. * Coordinated Time).
  1773. *
  1774.  
  1775. tmutc ldd #0 set daylight savings word
  1776.  std daylit
  1777.  ldd 0,x get hi word of time
  1778.  std r0 save ir divide register
  1779.  ldd 2,x get lo word of time
  1780.  std r0+2
  1781.  ldd #60*60 seconds*minutes constant
  1782.  std r1 set up for divide
  1783.  lbsr ldiv min*sec=time % 3600
  1784.  ldd work hour*day=time / 3600
  1785.  pshs d save min*sec
  1786.  ldd #24 set up hours per day constant
  1787.  std r1
  1788.  lbsr ldiv hours= (hour*day) % 24
  1789.  ldd work day= (hour*day) / 24
  1790.  std hours set hours word
  1791.  ldd r0+2 get day number
  1792.  std day save the day
  1793.  addd #2 add in day bias (Jan 1 80 => Tue)
  1794.  std r0 set up for divide
  1795.  ldb #7 days per week constant
  1796.  stb r1
  1797.  lbsr div wday=(day+2) % 7
  1798.  ldb work get result
  1799.  clra make into word
  1800.  std wday set week day
  1801.  puls d get min*sec
  1802.  std r0 set up for divide
  1803.  ldb #60 seconds per minute
  1804.  stb r1
  1805.  lbsr div seconds= (min*sec) % 60
  1806.  ldb work minutes= (min*sec) / 60
  1807.  clra
  1808.  std second set seconds word
  1809.  ldd r0 get minutes
  1810.  std minute save it
  1811.  
  1812.  pag
  1813.  
  1814. * continue tutc for year and month data
  1815.  
  1816.  clr 0,-s clear year counter
  1817. tutc2 ldx #ylen point to year length table
  1818.  lda 0,s get year number
  1819.  bita #$3 is it leap year?
  1820.  bne tutc3
  1821.  leax 2,x if so, move to long year value
  1822. tutc3 ldd day get day number
  1823.  cmpd 0,x day in current year?
  1824.  blo tutc4 if 'lt' - we got the year!
  1825.  subd 0,x subtract off years days
  1826.  std day save new day count
  1827.  inc 0,s bump the year count
  1828.  bra tutc2 repeat
  1829. tutc4 std yday set day of year word
  1830.  puls b get year count
  1831.  addb #80 add to '1980'
  1832.  clra make 16 bits long
  1833.  std year save the year
  1834.  bitb #$3 is it leap year?
  1835.  bne tutc5
  1836.  ldd #29 if so, set Feb day count to 29
  1837.  std mdays+2
  1838. tutc5 ldx #mdays point to month-day table
  1839.  clr 0,-s set month count to zero
  1840.  ldd yday get day of the year
  1841. tutc6 cmpd 0,x in the month?
  1842.  blo tutc7 if 'lt' - we got the month!
  1843.  inc 0,s bump the month counter
  1844.  subd 0,x++ subtract of this month's days
  1845.  bra tutc6
  1846. tutc7 addd #1 add 1 to month day (day 1 is 1 - not 0!)
  1847.  std mday save the month day
  1848.  puls b get the month
  1849.  std month save it
  1850.  ldd #28 reset month - day table
  1851.  std mdays+2
  1852.  rts return
  1853.  
  1854.  pag
  1855.  
  1856. *
  1857. * chkdl
  1858. *
  1859. * Check if in dlst - return 'eq' if so.
  1860. *
  1861.  
  1862. chkdl ldd #119 check for last Sun in Apr
  1863.  bsr fixtim
  1864.  std fstdl first day of dlst
  1865.  ldd #303 last Sun in Oct
  1866.  bsr fixtim
  1867.  std lstdl last day of dlst
  1868.  ldd yday get day of year
  1869.  cmpd fstdl up to 1st day yet?
  1870.  blo chkdl6
  1871.  bhi chkdl4
  1872.  ldd hours on the 1st day - so
  1873.  cmpd #2 is it 2:00 AM yet?
  1874.  blo chkdl6
  1875.  bra chkdl5
  1876. chkdl4 ldd yday get day of year
  1877.  cmpd lstdl past last day of dlst?
  1878.  bhi chkdl6
  1879.  blo chkdl5
  1880.  ldd hours on the last day - so
  1881.  cmpd #1 is it 1:00 AM yet?
  1882.  bhs chkdl6
  1883. chkdl5 sez we are in dlst!
  1884.  rts return
  1885. chkdl6 clz not in dlst
  1886.  rts return
  1887.  
  1888.  pag
  1889.  
  1890. *
  1891. * adjtim
  1892. *
  1893. * Adjust time for time zone.
  1894. *
  1895.  
  1896. adjtim ldd ltime+2 get time
  1897.  tst eutc east of UTC?
  1898.  bne adjti2
  1899.  subd r0+2 subtract time zone minutes
  1900.  std ltime+2
  1901.  ldd ltime get hi part
  1902.  sbcb r0+1
  1903.  sbca r0
  1904.  bra adjti4
  1905. adjti2 addd r0+2 add in minutes
  1906.  std ltime+2
  1907.  ldd ltime
  1908.  adcb r0+1
  1909.  adca r0
  1910. adjti4 std ltime save new time
  1911. adjti5 rts return
  1912.  
  1913. *
  1914. * fixtim
  1915. *
  1916. * Return the closest day to the date in D
  1917. * which is a Sunday.
  1918. *
  1919.  
  1920. fixtim pshs d save day number
  1921.  ldd year get year
  1922.  bitb #$3 is it leap year?
  1923.  puls d
  1924.  bne fixti2
  1925.  addd #1 if so - bump day number
  1926. fixti2 pshs d save day number
  1927.  addd #420 add in 420 so no negatives result
  1928.  addd wday add in day of week
  1929.  subd yday subtract day of year
  1930.  std r0 save result
  1931.  ldb #7
  1932.  stb r1 set up for divide
  1933.  bsr div do: (day+420+wday-yday) % 7
  1934.  puls d get day number
  1935.  subb work
  1936.  sbca #0
  1937.  rts return day in d
  1938.  
  1939.  pag
  1940.  
  1941. *
  1942. * Divide routines for time conversion use.  'Ldiv'
  1943. * divides a 32 bit number (r0 -> r0+3) by a 16 bit
  1944. * number (r1 -> r1+1) and produces a 32 bit result
  1945. * in r0 and a 16 bit remainder in 'work'.  'Div'
  1946. * divides a 16 bit number (r0 -> r0+1) by an 8 bit
  1947. * number (r1) and produces a 16 bit result (r0)
  1948. * and an 8 bit remainder (work).
  1949. *
  1950.  
  1951. div lda #17 set up loop counter
  1952.  clrb do initialize
  1953.  stb work
  1954.  bra div2
  1955. div1 ldb work
  1956.  subb r1 do subtraction
  1957.  bcs div2 s3et new work?
  1958.  stb work yes!
  1959. div2 rol r0+1 do shift left
  1960.  rol r0
  1961.  rol work
  1962.  deca dec the loop count
  1963.  bne div1 repeat?
  1964.  com r0 fix up result
  1965.  com r0+1
  1966.  lsr work fix remainder
  1967.  rts
  1968.  
  1969.  
  1970.  pag
  1971.  
  1972. *
  1973. * Long divide
  1974. *
  1975.  
  1976. ldiv ldb #33 set loop counter
  1977.  pshs b
  1978.  ldd #0 do init
  1979.  std work
  1980.  bra ldiv2
  1981. ldiv1 ldd work do subtraction
  1982.  subd r1
  1983.  bcs ldiv2 work > r1 ?
  1984.  std work set new work value
  1985. ldiv2 rol r0+3 do shifting
  1986.  rol r0+2
  1987.  rol r0+1
  1988.  rol r0
  1989.  rol work+1
  1990.  rol work
  1991.  dec 0,s dec the loop count
  1992.  bne ldiv1
  1993.  com r0 compliment the result
  1994.  com r0+1
  1995.  com r0+2
  1996.  com r0+3
  1997.  lsr work adjust the remainder
  1998.  ror work+1
  1999.  puls b,pc return
  2000.  
  2001.  pag
  2002.  
  2003. *
  2004. * lmul
  2005. *
  2006. * Long multiply - 32 bits (r0) X 32 bits (r1).
  2007. * Result is in r0.
  2008. *
  2009.  
  2010. lmul ldb #32 set loop count
  2011.  pshs b
  2012.  ldd #0 init variables
  2013.  std work
  2014.  std work+2
  2015.  lsr r0 do initial shift
  2016.  ror r0+1
  2017.  ror r0+2
  2018.  ror r0+3
  2019. lmul1 bcc lmul2 need to add?
  2020.  ldd work+2
  2021.  addd r1+2
  2022.  std work+2
  2023.  ldd work
  2024.  adcb r1+1
  2025.  adca r1
  2026.  std work save result
  2027. lmul2 ror work do shifting
  2028.  ror work+1
  2029.  ror work+2
  2030.  ror work+3
  2031.  ror r0
  2032.  ror r0+1
  2033.  ror r0+2
  2034.  ror r0+3
  2035.  dec 0,s dec the loop count
  2036.  bne lmul1 repeat?
  2037.  puls b,pc return
  2038.  
  2039.  pag
  2040.  
  2041. *
  2042. * tasc
  2043. *
  2044. * Convert the time vector data (18 bytes) pointed
  2045. * at by x into an ascii string.  Return x pointing
  2046. * to the string.
  2047. *
  2048.  
  2049. tasc tfr x,u save vector pointer
  2050.  ldx #tstr point to string
  2051.  ldd 4,u get hours
  2052.  bsr cvt convert to ascii
  2053.  leax 1,x skip the ':'
  2054.  ldd 2,u get minutes
  2055.  bsr cvt convert to ascii
  2056.  leax 1,x skip the ':'
  2057.  ldd 0,u get seconds
  2058.  bsr cvt convert to ascii
  2059.  leax 1,x skip space
  2060.  ldd 6,u get day of week
  2061.  ldy #dtab point to day table
  2062.  bsr tasxfr xfr to string
  2063.  ldd 10,u get month
  2064.  ldy #mtab point to month table
  2065.  bsr tasxfr xfr to string
  2066.  ldd 8,u get month day
  2067.  bsr cvt convert to ascii
  2068.  leax 1,x
  2069.  ldd #('1<<8)|'9 set up '19'
  2070.  std 0,x save in string
  2071.  ldd 12,u get year
  2072.  cmpd #100 >100 (year 2000 yet?)
  2073.  blo tasc4
  2074.  subd #100 remove bias
  2075.  pshs d save year
  2076.  ldd #('2<<8)|'0 set up '20'
  2077.  std 0,x set in string
  2078.  puls d reset year
  2079. tasc4 leax 2,x
  2080.  bsr cvt convert year to ascii
  2081.  ldx #tstr point to string
  2082.  rts return
  2083.  
  2084.  pag
  2085.  
  2086. *
  2087. * tasxfr
  2088. *
  2089. * Transfer the 3 bytes of ascii indexed by b
  2090. * at y to location pointed at by x.
  2091. *
  2092.  
  2093. tasxfr pshs b index * 3
  2094.  aslb
  2095.  addb 0,s+
  2096.  leay b,y point to indexed data
  2097.  ldd 0,y xfr the data to x
  2098.  std 0,x++
  2099.  lda 2,y
  2100.  sta 0,x
  2101.  leax 2,x bump string pointer
  2102.  rts return
  2103.  
  2104. *
  2105. * cvt
  2106. *
  2107. * Convert number in b to ascii at x.
  2108. *
  2109.  
  2110. cvt lda #'0 set ascii 0
  2111. cvt2 cmpb #10 >10?
  2112.  blo cvt4
  2113.  subb #10 subtract off 10
  2114.  inca bump ascii
  2115.  bra cvt2 repeat
  2116. cvt4 addb #'0 make 1's ascii
  2117.  std 0,x++ save ascii at x
  2118.  rts return
  2119.  
  2120.  pag
  2121.  
  2122.  if *>$1000
  2123.  err Text Overflow into Data!
  2124.  endif
  2125.  
  2126.  ifc &a,"notext"
  2127.  org $1000
  2128.  else
  2129.  data $1000
  2130.  endif
  2131.  
  2132. *
  2133. * Shell data section
  2134. *
  2135.  
  2136. prompt fcc '++ '
  2137. PRSIZ equ *-prompt size of prompt
  2138. bdfms fcc "Can't open I/O file.",$d
  2139. BDSIZ equ *-bdfms
  2140. ermsg1 fcc "Can't execute '"
  2141. ERSIZ1 equ *-ermsg1
  2142. ermsg2 fcc "'",$d
  2143. ERSIZ2 equ *-ermsg2
  2144. syrms fcc 'Syntax error.',$d
  2145. SYSIZ equ *-syrms
  2146. ccdrms fcc "Can't change directories.",$d
  2147. CCDSZ equ *-ccdrms
  2148. ntfms fcc 'No such task.',$d
  2149. NTSZ equ *-ntfms
  2150. rtmsg fcc ' running.',$d
  2151. RTSZ equ *-rtmsg
  2152. ttmsg fcc ' - '
  2153. TTMSZ equ *-ttmsg
  2154. tmtms fcc 'Too many tasks ... waiting!',$d
  2155. TMTSZ equ *-tmtms
  2156. nopms fcc "Can't create pipe",$d
  2157. NPSZ equ *-nopms
  2158. nchms fcc 'No tasks active.',$d
  2159. NCHSZ equ *-nchms
  2160. frkmsg fcc "Can't fork task.",$d
  2161. FRKSIZ equ *-frkmsg
  2162. argms fcc "Match list overflow.",$d
  2163. ARGMS equ *-argms
  2164. crdms fcc ' (Core dumped)',0
  2165. utnam fcc '/act/utmp',0
  2166. nldst fcc '/dev/null',0
  2167. hmfl fcc '.home?',0
  2168. cshell fcc '/bin/shell',0
  2169. carg fdb cshln,cstrt,0
  2170. cshln fcc 'shell',0
  2171. cstrt fcc '.startup',0
  2172. cptst fcc '+c',0
  2173. bcptst fcc '+bc',0
  2174. cbasic fcc '/bin/basic',0
  2175. Pscl0 fcc '/bin/nrun',0 ***GDT
  2176. Pscl1 fcc '/bin/sys_rt',0 ***GDT
  2177. logn fcc '/etc/login',0
  2178. logr fdb 0
  2179. plbst fcc '+b',0
  2180. tmstb fdb tm0,tm1,tm2,tm3,tm4,tm5
  2181.  fdb tm6,tm7,tm8,tm9,tm10,tm11,tm12
  2182. tm0 fcc 'Ended.',0
  2183. tm1 fcc 'Hangup.',0
  2184. tm2 fcc 'INTERRUPT!',0
  2185. tm3 fcc 'Quit.',0
  2186. tm4 fcc 'EMT trap.',0
  2187. tm5 fcc 'Killed.',0
  2188. tm6 fcc 'Pipe.',0
  2189. tm7 fcc 'Argument.',0
  2190. tm8 fcc 'Trace.',0
  2191. tm7xx fcc 'Memory Fault.',0
  2192. tm8xx fcc 'EMT2 Trap.',0
  2193. tm9 fcc 'Time limit.',0
  2194. tm10 fcc 'Alarm.',0
  2195. tm11 fcc 'Terminated.',0
  2196. tm12 fcc 'Interrupt #12.',0
  2197.  
  2198. ylen fdb 365 year length
  2199.  fdb 366 leap year
  2200.  
  2201. mdays fdb 31,28,31,30,31,30,31,31,30,31,30,31
  2202.  
  2203.  
  2204. tstr fcc 'xx:xx:xx xxx xxx xx xxxx',$d,0
  2205.  
  2206. dtab fcc 'SunMonTueWedThuFriSat'
  2207.  
  2208. mtab fcc 'JanFebMarAprMayJunJulAugSepOctNovDec'
  2209.  
  2210. second fdb 0 seconds (0-59)
  2211. minute fdb 0 minutes (0-59)
  2212. hours fdb 0 hours (0-23)
  2213. wday fdb 0 week day (0-6) 0=Sunday
  2214. mday fdb 0 month day (1-31)
  2215. month fdb 0 month (0-11)
  2216. year fdb 0 year (80+)
  2217. yday fdb 0 day of year (0-355)
  2218. daylit fdb 0 daylight savings flag
  2219.  
  2220. * constants for convert
  2221.  
  2222. conlst fdb 10000
  2223.  fdb 1000
  2224.  fdb 100
  2225.  fdb 10
  2226. conend equ * end of list
  2227.  
  2228.  
  2229. r0 fdb 0,0 regs for div and mul
  2230. r1 fdb 0,0
  2231. work fdb 0,0
  2232. day fdb 0 day temp
  2233. ntime fdb 0,0 new time
  2234. eutc fcb 0 east of utc flag
  2235. fstdl fdb 0 1st day of dlst
  2236. lstdl fdb 0 last day of dlst
  2237. dlflg fcb 0 dlst flag
  2238. ltime fdb 0,0 local time
  2239. tzn fdb 0,0 time zone seconds
  2240.  
  2241.  
  2242. * command table
  2243.  
  2244. sctab fcc 'chd',0
  2245.  fdb chd
  2246.  fcc 'login',0
  2247.  fdb login
  2248.  fcc 'log',0
  2249.  fdb log
  2250.  fcc 'logout',0
  2251.  fdb log
  2252.  fcc 'wait',0
  2253.  fdb cwait
  2254.  fcc 'prompt',0
  2255.  fdb stprm
  2256.  fcc 'jobs',0
  2257.  fdb jobs
  2258.  fcc 'dperm',0
  2259.  fdb dprm
  2260. scend equ * end of table
  2261.  
  2262. execf fcb 0 no fork flag
  2263. subrg fdb cshln,cptst
  2264. subrg2 fdb 0,0
  2265. bsubrg fdb cshln,bcptst
  2266. bsbrg2 fdb 0,0
  2267. syntid fdb 0 sync task id
  2268. termc fcb 0 term character
  2269. soft fcb 0 soft term flag
  2270. ctrm fdb 0 termination status
  2271. intflg fcb 0 interactive mode flag
  2272. coptf fcb 0 c option flag
  2273. rtcnt fcb 0 retry counter
  2274. sp fdb 0 stack pointer
  2275. subpt fdb 0 subs pointer
  2276. prflg fcb 0 paren flag
  2277. pipmod fcb 0 pipe mode flag
  2278. pprdf fdb 0 pipe read file
  2279. ppwrf fdb 0 pipe write file
  2280. apprdf fdb 0 actual pipe read file
  2281. starg fdb 0 starting arg for sort
  2282. quote fcb 0 quoted string flag
  2283. slot fcb 0 default perm value
  2284. mone fcb 0 match flag
  2285. mffd fdb 0 match file desc
  2286. mtpt fdb 0 match pointer
  2287. fstpt fdb 0 final arg pointer
  2288. cbpt fdb 0 command line pointer
  2289. smbuf fdb 0 small buffer
  2290. tprfl fcb 0 time prompt flag
  2291. linpt fdb 0 line pointer
  2292. linend fdb 0 buffer end
  2293. bufpt fdb 0 buffer pointer
  2294. argpt fdb 0 argument pointer
  2295. sifil fdb 0 input file
  2296. sofil fdb 0 output file
  2297. safil fdb 0 append file
  2298. ttgbuf fdb 0,0,0 ttyget buffer
  2299. shtime fdb 0,0,0,0 shell time buffer
  2300. asytim fdb 0,0,0,0 task time
  2301. tmpfd fdb 0 temp file desc
  2302. bgop fcb 0 background option flag
  2303. supf fcb 0 startup flag
  2304. wtid fdb 0 wait task id
  2305. ifd fdb 0 input file desc
  2306.  
  2307. iopn fcb open ind open call
  2308. iopn2 fdb 0,0
  2309.  
  2310. icrt fcb create ind create call
  2311. icrt2 fdb 0,$1B
  2312.  
  2313. iopnw fcb open ind open write call
  2314. iopnw2 fdb 0,1
  2315.  
  2316. wrid fcb write
  2317.  fdb idbuf
  2318. wrid2 fdb 0
  2319.  
  2320. iwrt fcb write
  2321.  fdb comnd
  2322. iwrt2 fdb 0
  2323.  
  2324. iwrtp fcb write
  2325. iwrtp2 fdb prompt
  2326. iwrtp3 fdb 3
  2327.  
  2328. isdp fcb defacc,0
  2329. isdp2 fcb 0
  2330.  
  2331. istat fcb status
  2332. istata fdb 0 pointer to name
  2333.  fdb statbuf
  2334.  
  2335. statbuf rzb ST_SIZ
  2336.  
  2337. defdir fcc '/' default dir for chd
  2338.  rzb 47
  2339.  
  2340. retry3 fcc '/usr'
  2341. retry2 fcc '/'
  2342. retry1 fcc 'bin/'
  2343. comnd rzb 128 command name buffer
  2344.  
  2345. attab rzb 9*ASSIZ async table
  2346. atend equ *
  2347.  
  2348. idbuf rzb 8 output buffer for task id
  2349. tstbuf rzb 17 match test buffer
  2350.  
  2351. mfsb rzb 24 status buffer
  2352. prmbuf rzb 24 prompt buffer
  2353.  
  2354. front rzb 128 path name front for match
  2355.  
  2356. buffer rzb BUFSIZ input line buffer
  2357.  
  2358. bsrgls rzb 2
  2359. sargls rzb 2 shell arg start
  2360. arglst rzb 0 argument list for exec (overlays initialization)
  2361.  
  2362. *
  2363. * sinit
  2364. *
  2365. * Shell initialization
  2366. *
  2367.  
  2368. sinit sys systat,fstlst get system version
  2369.  lda fstlst+6 get system type
  2370.  bpl sini00 if not protected cpu
  2371.  ldx #tm7xx change error message table
  2372.  stx tmstb+2*7
  2373. sini00 lsla
  2374.  bpl sini01 if EMT2 not present
  2375.  ldx #tm8xx
  2376.  stx tmstb+2*8
  2377. sini01 clr coptf reset 'c' opt flag
  2378.  clr termc
  2379.  clr pipmod
  2380.  ldd #0 set input fd
  2381.  std ifd
  2382.  ldb #ASSIZ*9
  2383.  ldx #attab clear out async table
  2384. sini05 clr 0,x+
  2385.  decb
  2386.  bne sini05
  2387.  lbsr cfile close all files
  2388.  ldd #cshln get shell name
  2389.  std sargls save as arg
  2390.  std bsrgls
  2391.  ldx #linbuf set initial pointers
  2392.  stx linpt
  2393.  stx linend
  2394.  lda #1 set interactive mode
  2395.  sta intflg
  2396.  ldd #0 set file desc 0
  2397.  sys ttyget,ttgbuf
  2398.  bec sinit0 error?
  2399.  cmpb #ENTTY is it not a tty?
  2400.  bne sinit0
  2401.  clr intflg clear interactive mode
  2402. sinit0 ldd 2,s get arg count
  2403.  cmpd #1 any args?
  2404.  bhi sinit2
  2405.  lda [4,s] get 1st char of arg 1
  2406.  cmpa #'+ is it '+'?
  2407.  beq sinit4
  2408. sinit1 rts return
  2409. sinit2 bsr opts process options
  2410.  tst coptf 'c' option set?
  2411.  beq sinit3
  2412. sini25 rts return
  2413. sinit3 ldx subpt get arg pointer
  2414.  beq sini25 any left?
  2415.  ldd 0,x get arg
  2416.  beq sini25 null?
  2417.  clr intflg set non-interactive mode
  2418.  ldd [subpt] get file name pointer
  2419. sini35 std iopn2 set up sys call
  2420.  sys ind,iopn open file for read
  2421.  bes sini37 errors?
  2422.  std ifd save file desc
  2423.  bra sini25
  2424. sini37 tst supf startup?
  2425.  bne sinit6
  2426.  sys term exit
  2427. sinit4 sys open,hmfl,0 get home file
  2428.  bes sinit5 ignore errors
  2429.  pshs d save file desc
  2430.  sys read,defdir,48 read in dir name
  2431.  puls d get file desc
  2432.  sys close the file
  2433.  sys unlink,hmfl delete home file
  2434. sinit5 lda #1 set startup mode
  2435.  sta supf
  2436.  clr intflg clear interactive mode
  2437.  sys cpint,11,1 ignore TERMI ** version 5 ** DS
  2438.  ldd #cstrt get startup name
  2439.  bra sini35 go open & run it
  2440. sinit6 clr supf clear out startup mode
  2441.  inc intflg set interactive
  2442.  rts return
  2443.  
  2444. *
  2445. * opts
  2446. *
  2447. * Process options for shell call.
  2448. *
  2449.  
  2450. opts leax 8,s point to arg list
  2451.  stx subpt save it
  2452.  ldx 0,x get arg
  2453.  beq opts9 null?
  2454.  lda 0,x+ get 1st char
  2455.  cmpa #'+ is it '+'?
  2456.  bne opts9
  2457. opts2 lda 0,x+ get next char of arg
  2458.  beq opts8
  2459.  cmpa #'c is it c option?
  2460.  bne opts4
  2461.  sta coptf set option flag
  2462.  clr intflg set non-interactive
  2463.  ldd 10,s get string pointer
  2464.  std cbpt
  2465.  bra opts2
  2466.  
  2467. opts4 cmpa #'b is it b option?
  2468.  bne opts6
  2469.  stb bgop set option flag
  2470.  bra opts2
  2471.  
  2472. opts6 cmpa #'x is it "no fork"
  2473.  bne opts2 if not
  2474.  sta execf set "no fork"
  2475.  bra opts2
  2476.  
  2477. opts8 leax 10,s point to arg
  2478.  stx subpt set pointer
  2479. opts9 ldd [subpt] check for null args
  2480.  bne opts10
  2481.  std subpt
  2482. opts10 rts return
  2483.  
  2484.  ifc &a,"notext"
  2485.  org $1E00
  2486.  else
  2487.  bss $1E00
  2488.  endif
  2489.  
  2490. linbuf rmb 512 input buffer
  2491. fstlst rmb 4096
  2492.  
  2493.  
  2494.  end sh
  2495.