home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ZSYS / SIMTEL20 / ZCPR3 / SHDEFINE.MAC < prev    next >
Text File  |  2000-06-30  |  11KB  |  659 lines

  1. ;
  2. ; Program: SHDEFINE
  3. ; Author: Richard Conn
  4. ; Version: 1.0
  5. ; Date: 5 Mar 84
  6. ;
  7. version    equ    10
  8.  
  9. ;
  10. ;    SHDEFINE is used to define shell variables for the Shell SH.
  11. ; It makes entries into the file SH.VAR in the ROOT directory.
  12. ;
  13.  
  14. ;
  15. ; Equates for Key Values
  16. ;
  17. z3env    SET    0f400h    ;address of ZCPR3 environment
  18. backup    equ    0    ;backup old file? 1 for yes, 0 for no
  19. ctrlz    equ    'Z'-'@'    ;^Z for EOF
  20. fcb    equ    5ch
  21. tbuff    equ    80h
  22. cr    equ    0dh
  23. lf    equ    0ah
  24.  
  25. ;
  26. ; External Z3LIB and SYSLIB Routines
  27. ;
  28.     ext    sctlfl,sout,sprint,scrlf,shldc
  29.     ext    bbline,sksp,capine,fillb,cout,moveb,getfn1
  30.     ext    initfcb,f$open,f$read,f$close,f$make,f$delete,f$write,f$rename
  31.     ext    z3init,qprint,codend,hmovb,root,logud,getwhl,print
  32.  
  33. ;
  34. ; Environment Definition
  35. ;
  36.     if    z3env ne 0
  37. ;
  38. ; External ZCPR3 Environment Descriptor
  39. ;
  40.     jmp    start
  41.     db    'Z3ENV'    ;This is a ZCPR3 Utility
  42.     db    1    ;External Environment Descriptor
  43. z3eadr:
  44.     dw    z3env
  45. start:
  46.     lhld    z3eadr    ;pt to ZCPR3 environment
  47. ;
  48.     else
  49. ;
  50. ; Internal ZCPR3 Environment Descriptor
  51. ;
  52.     MACLIB    Z3BASE.LIB
  53.     MACLIB    SYSENV.LIB
  54. z3eadr:
  55.     jmp    start
  56.     SYSENV
  57. start:
  58.     lxi    h,z3eadr    ;pt to ZCPR3 environment
  59.     endif
  60.  
  61. ;
  62. ; Start of Program -- Initialize ZCPR3 Environment
  63. ;
  64.     call    z3init    ;initialize the ZCPR3 Environment
  65.     call    banner    ;print banner
  66. ;
  67. ; Check for Wheel
  68. ;
  69.     call    getwhl    ;get wheel byte
  70.     jnz    start0
  71.     call    print
  72.     db    cr,lf,' Not Wheel - Aborting',0
  73.     ret
  74. ;
  75. ; Try to Load Variables
  76. ;
  77. start0:
  78. ;
  79. ; Define File to Work With
  80. ;
  81.     lxi    h,fcb+1    ;check for file name
  82.     lxi    d,shvfcb+1    ;variable FCB
  83.     mvi    b,11    ;11 chars
  84.     mov    a,m    ;any name given?
  85.     cpi    ' '    ;space if none
  86.     jz    setdef    ;set default shell variable file name
  87. ;
  88. ; Define Passed Name as Shell Variable File
  89. ;
  90.     call    moveb    ;set name
  91.     lxi    h,deftype    ;set default type if none
  92.     lxi    d,shvfcb+9    ;pt to type
  93.     mvi    b,3    ;3 chars
  94.     ldax    d        ;any chars
  95.     cpi    ' '    ;if none, copy
  96.     cz    moveb
  97.     jmp    bakdef
  98. ;
  99. ; Define from Shell Variable File Name
  100. ;
  101. setdef:
  102.     call    getfn1    ;get name
  103.     call    moveb    ;copy it
  104. ;
  105. ; Define $$$ and BAK Files
  106. ;
  107. bakdef:
  108.     lxi    h,shvfcb+1
  109.     lxi    d,shvtmp+1    ;set $$$ name
  110.     mvi    b,8        ;8 chars
  111.     call    moveb
  112. ;
  113.     if    backup
  114.     lxi    d,shvbak+1    ;set BAK name
  115.     call    moveb
  116.     endif        ;backup
  117. ;
  118. ; Load Variables
  119. ;
  120.     call    varload
  121.     jnz    start1
  122. ;
  123. ; Initialize Shell Variables if File Not Found
  124. ;
  125.     call    codend    ;pt to code end
  126.     mvi    m,ctrlz    ;place ^Z
  127. ;
  128. ; Process User Commands
  129. ;
  130. start1:
  131.     call    menu    ;use menu
  132.     rz        ;abort
  133.     call    varsave    ;save new shell variables
  134.     ret
  135.  
  136. ;
  137. ; Input and Process User Commands
  138. ;    Return with Z if Abort
  139. ;
  140. menu:
  141.     call    print
  142.     db    cr,lf
  143.     db    cr,lf,'    ** Shell Variable Editor **'
  144.     db    cr,lf
  145.     db    cr,lf,'Edit:    E. Edit (Add/Delete/Redefine) Shell Variables'
  146.     db    cr,lf,'    L. List Shell Variables on Console'
  147.     db    cr,lf,'    P. Print Shell Variables on Printer'
  148.     db    cr,lf
  149.     db    cr,lf,'Exit:    X. Exit and Update SH.VAR on Disk'
  150.     db    cr,lf,'    Q. Quit without Updating SH.VAR'
  151.     db    cr,lf
  152.     db    cr,lf,'Command: ',0
  153.     call    capine    ;get command
  154.     lxi    h,ctable    ;scan command table
  155.     call    tscan
  156.     call    print
  157.     db    ' Invalid Command: ',0
  158.     call    cout
  159.     jmp    menu
  160. ;
  161. ; Pack and Menu Exit
  162. ;    Return NZ
  163. ;
  164. pack:
  165.     call    codend    ;pack entries in table
  166.     mov    d,h    ;HL=DE
  167.     mov    e,l
  168. ;
  169. ; Check Next Entry
  170. ;
  171. pack1:
  172.     mov    a,m    ;get next char
  173.     stax    d    ;put it
  174.     cpi    ctrlz    ;done?
  175.     jz    packx
  176.     cpi    ' '    ;deleted?
  177.     jz    pack3
  178. ;
  179. ; Copy Entry
  180. ;
  181. pack2:
  182.     mov    a,m    ;get char
  183.     stax    d    ;put it
  184.     inx    h    ;pt to next
  185.     inx    d
  186.     ora    a    ;done?
  187.     jnz    pack2
  188.     jmp    pack1    ;resume
  189. ;
  190. ; Skip Entry
  191. ;
  192. pack3:
  193.     mov    a,m    ;get char
  194.     inx    h    ;pt to next
  195.     ora    a    ;done?
  196.     jnz    pack3
  197.     jmp    pack1    ;resume
  198. ;
  199. ; Pack Complete
  200. ;
  201. packx:
  202.     xra    a    ;NZ
  203.     dcr    a
  204.     ret
  205. ;
  206. ; Menu Quit
  207. ;    Return Z
  208. ;
  209. mquit:
  210.     call    print
  211.     db    cr,lf,' Do you really want to quit (Y/N)? ',0
  212.     call    capine
  213.     cpi    'Y'
  214.     jnz    menu
  215.     xra    a    ;Z
  216.     ret
  217. ;
  218. ; List Names in Table on Printer
  219. ;
  220. nprint:
  221.     mvi    a,80H    ;select print
  222.     jmp    nliste
  223. ;
  224. ; List Names in Table on Console
  225. ;
  226. nlist:
  227.     mvi    a,1    ;select console
  228. nliste:
  229.     sta    sctlfl    ;set flag
  230.     call    pack    ;pack table
  231. nlist0:
  232.     call    sprint
  233.     db    cr,lf,'List of Shell Variables',0
  234.     lxi    d,0    ;set count
  235.     call    codend    ;pt to list
  236. ;
  237. ; Main List Loop
  238. ;
  239. nlist1:
  240.     mov    a,m    ;get next variable
  241.     cpi    ctrlz    ;done?
  242.     jz    nlistx
  243. ;
  244. ; Print Next Element
  245. ;
  246.     xchg        ;print number
  247.     inx    h    ;increment count
  248.     call    scrlf
  249.     call    shldc    ;print
  250.     xchg        ;DE contains count
  251.     call    sprint
  252.     db    ' Name: ',0
  253.     mvi    b,8    ;8 chars in name
  254. nlist2:
  255.     mov    a,m    ;get char
  256.     call    sout    ;print
  257.     inx    h    ;pt to next
  258.     dcr    b    ;count down
  259.     jnz    nlist2
  260.     call    sprint
  261.     db    cr,lf,'      >',0
  262. nlist3:
  263.     mov    a,m    ;get char
  264.     inx    h    ;pt to next
  265.     ora    a    ;done?
  266.     jz    nlist4    ;resume
  267.     call    sout
  268.     jmp    nlist3
  269. nlist4:
  270.     call    sprint
  271.     db    '<',0
  272.     jmp    nlist1
  273. ;
  274. ; Exit Listing
  275. ;
  276. nlistx:
  277.     call    scrlf    ;new line
  278.     mov    a,d    ;check for none
  279.     ora    e
  280.     jnz    menu    ;resume menu
  281.     call    sprint
  282.     db    ' -- No Shell Variables Defined --',cr,lf,0
  283.     jmp    menu
  284.  
  285. ;
  286. ; Add Names to Table
  287. ;
  288. nadd:
  289.     call    print
  290.     db    cr,lf,'Enter Shell Variable Name (RETURN to Quit): ',0
  291.     mvi    a,0ffh    ;capitalize
  292.     call    bbline
  293.     call    sksp    ;skip to first non-blank
  294.     ora    a    ;done?
  295.     jz    menu    ;resume menu
  296. ;
  297. ; Copy Input Name into Shell Buffer SHVAR
  298. ;
  299.     push    h    ;save ptr to name
  300.     lxi    h,shvar    ;init name buffer
  301.     mvi    a,' '    ;space fill
  302.     mvi    b,8    ;8 chars
  303.     call    fillb
  304.     xchg        ;pt to buffer in DE
  305.     pop    h    ;pt to name
  306.     mvi    b,8    ;8 chars max
  307. nadd1:
  308.     mov    a,m    ;get name char
  309.     ora    a    ;done?
  310.     jz    nadd2
  311.     stax    d    ;store char
  312.     inx    h    ;pt to next
  313.     inx    d
  314.     dcr    b    ;count down
  315.     jnz    nadd1
  316. ;
  317. ; Search for Name
  318. ;
  319. nadd2:
  320.     call    codend    ;pt to first element
  321. ;
  322. ; Check for End of Entries
  323. ;
  324. nadd3:
  325.     mov    a,m    ;get first char of next string
  326.     cpi    ctrlz
  327.     jz    addit    ;add name at HL
  328. ;
  329. ; Compare Names
  330. ;
  331.     lxi    d,shvar    ;pt to variable
  332.     mvi    b,8    ;compare
  333.     shld    curname    ;save ptr to current name in case of delete
  334. nadd4:
  335.     ldax    d    ;check for duplicate
  336.     cmp    m
  337.     jnz    nadd5
  338.     inx    h    ;pt to next
  339.     inx    d
  340.     dcr    b    ;count down
  341.     jnz    nadd4
  342.     jmp    nadd6
  343. ;
  344. ; No Match, so Skip Rest of String
  345. ;
  346. nadd5:
  347.     mov    a,m    ;skip to end of string
  348.     inx    h    ;pt to next
  349.     ora    a    ;done?
  350.     jnz    nadd5
  351.     jmp    nadd3    ;resume
  352. ;
  353. ; Match - Determine What User Wants to Do
  354. ;
  355. nadd6:
  356.     call    print
  357.     db    cr,lf,' Shell Variable Name ',0
  358.     call    prname    ;print name
  359.     call    print
  360.     db    ' Found -'
  361.     db    cr,lf,'    Delete It (D)'
  362.     db    cr,lf,'    Redefine It (R)'
  363.     db    cr,lf,'    No Change (anything else)'
  364.     db    cr,lf,'Option: ',0
  365.     call    capine
  366.     cpi    'D'    ;delete?
  367.     jz    delete
  368.     cpi    'R'    ;redefine?
  369.     jnz    nadd    ;restart if not
  370. ;
  371. ; Redefine Name
  372. ;
  373.     lhld    curname    ;pt to name in buffer
  374.     mvi    b,8    ;space fill it
  375.     mvi    a,' '
  376.     call    fillb
  377.     jmp    nadd3    ;resume in case another duplicate
  378. ;
  379. ; Delete Name
  380. ;
  381. delete:
  382.     lhld    curname    ;pt to name in buffer
  383.     mvi    b,8    ;space fill it
  384.     mvi    a,' '
  385.     call    fillb
  386.     jmp    nadd    ;restart
  387. ;
  388. ; Add Name
  389. ;
  390. addit:
  391.     shld    curname    ;save ptr to new name
  392.     xchg        ;dest in DE
  393.     lxi    h,shvar    ;pt to name
  394.     mvi    b,8    ;8 chars
  395.     call    hmovb    ;copy name into buffer
  396.     xchg        ;pt to after name with HL
  397.     push    h    ;save ptr
  398.     mvi    m,0    ;store ending 0 and ^Z in case of abort
  399.     inx    h
  400.     mvi    m,ctrlz    ;store ^Z
  401.     call    print
  402.     db    cr,lf,' Definition of ',0
  403.     call    prname    ;print name
  404.     call    print
  405.     db    ' (RETURN to Abort) -',cr,lf,'--> ',0
  406.     mvi    a,0ffh    ;caps
  407.     call    bbline
  408.     pop    d    ;get destination
  409.     mov    a,m    ;no input?
  410.     ora    a    ;noadd if not
  411.     jz    noadd
  412. ;
  413. ; Copy User Input into Buffer
  414. ;
  415. addit1:
  416.     mov    a,m    ;get char
  417.     stax    d    ;put char
  418.     inx    h    ;pt to next
  419.     inx    d
  420.     ora    a    ;done?
  421.     jnz    addit1
  422.     mvi    a,ctrlz    ;mark end
  423.     stax    d
  424.     jmp    nadd
  425.  
  426. ;
  427. ; Abort Add
  428. ;
  429. noadd:
  430.     lhld    curname    ;pt to first char
  431.     mvi    m,ctrlz    ;mark end
  432.     jmp    nadd
  433.  
  434. ;
  435. ; Print Name of Shell Variable
  436. ;
  437. prname:
  438.     push    h    ;save regs
  439.     push    b
  440.     lxi    h,shvar    ;pt to name
  441.     mvi    b,8    ;8 chars
  442. prn1:
  443.     mov    a,m    ;get char
  444.     call    cout
  445.     inx    h    ;pt to next
  446.     dcr    b    ;count down
  447.     jnz    prn1
  448.     pop    b    ;restore
  449.     pop    h
  450.     ret
  451.  
  452. ;
  453. ; Command Table Scanner
  454. ;
  455. tscan:
  456.     mov    b,a    ;save char in B
  457. tscan1:
  458.     mov    a,m    ;end of table?
  459.     ora    a
  460.     mov    a,b    ;prep for return
  461.     rz
  462.     mov    a,m    ;get table char
  463.     cmp    b    ;match?
  464.     jz    tscan2
  465.     inx    h    ;pt to next entry
  466.     inx    h
  467.     inx    h
  468.     jmp    tscan1
  469. ;
  470. ; Command Found - Run It
  471. ;
  472. tscan2:
  473.     inx    h    ;get address
  474.     mov    e,m
  475.     inx    h
  476.     mov    d,m
  477.     xchg        ;address in HL
  478.     pop    psw    ;clear stack
  479.     pchl        ;"run" command
  480. ;
  481. ; Command Table
  482. ;
  483. ctable:
  484.     db    'E'    ;enter
  485.     dw    nadd
  486.     db    'L'    ;list
  487.     dw    nlist
  488.     db    'P'    ;print
  489.     dw    nprint
  490.     db    'X'    ;exit
  491.     dw    pack
  492.     db    'Q'    ;quit
  493.     dw    mquit
  494.     db    0    ;end of table
  495.  
  496. ;
  497. ; Print Banner
  498. ;
  499. banner:
  500.     call    qprint
  501.     db    'SHDEFINE, Version '
  502.     db    (version/10)+'0','.',(version mod 10)+'0'
  503.     db    0
  504.     ret
  505. ;
  506. ; Save Shell Variable List
  507. ;    Return with Z if Error
  508. ;
  509. varsave:
  510.     call    print
  511.     db    cr,lf,'    Writing Shell Variables to Disk',0
  512.     lxi    d,shvtmp    ;open temp
  513.     call    initfcb
  514.     call    f$delete    ;delete if any exists
  515.     call    f$make        ;create new file
  516.     inr    a        ;error?
  517.     rz
  518.     call    codend        ;pt to scratch area
  519. ;
  520. ; Save Loop
  521. ;
  522. vars1:
  523.     lxi    d,tbuff        ;copy into buffer
  524.     mvi    b,128        ;128 bytes
  525.     call    hmovb
  526.     lxi    d,shvtmp    ;write block
  527.     call    f$write
  528.     jnz    werr        ;write error
  529.     lxi    d,tbuff        ;check for done
  530.     mvi    b,128        ;128 bytes
  531. ;
  532. ; Check for Done
  533. ;
  534. vars2:
  535.     ldax    d        ;look for ^Z
  536.     cpi    ctrlz
  537.     jz    varsx
  538.     inx    d        ;pt to next
  539.     dcr    b        ;count down
  540.     jnz    vars2
  541.     jmp    vars1
  542. ;
  543. ; Done
  544. ;
  545. varsx:
  546.     lxi    d,shvtmp    ;close temp file
  547.     call    f$close
  548. ;
  549. ; Delete Old Backup File SH.BAK
  550. ;
  551.     if    backup
  552. ;
  553.     lxi    d,shvbak    ;delete any old backups
  554.     call    initfcb
  555.     call    f$delete
  556. ;
  557. ; Create New Backup File SH.BAK=SH.VAR
  558. ;
  559.     lxi    h,shvbak    ;new name
  560.     lxi    d,shvfcb    ;old name
  561.     call    f$rename    ;create backup file
  562. ;
  563.     else
  564. ;
  565. ; Erase Original File
  566. ;
  567.     lxi    d,shvfcb    ;delete file
  568.     call    initfcb
  569.     call    f$delete
  570. ;
  571.     endif        ;backup
  572. ;
  573. ; Create New Shell Variable File SH.VAR=SH.$$$
  574. ;
  575.     lxi    h,shvfcb    ;new name
  576.     lxi    d,shvtmp    ;old name
  577.     call    f$rename    ;create new file
  578.     xra    a        ;return OK
  579.     dcr    a        ;NZ
  580.     ret
  581. ;
  582. ; File Write Error
  583. ;
  584. werr:
  585.     call    print
  586.     db    cr,lf,'Error in Writing File - Aborting',0
  587.     xra    a        ;error code
  588.     ret
  589.  
  590. ;
  591. ; Load Shell Variable List
  592. ;    Return with Z if Error
  593. ;
  594. varload:
  595. ;
  596. ; Look for Variable File
  597. ;
  598.     call    root        ;determine DU of root
  599.     call    logud        ;goto root
  600.     call    codend        ;pt to scratch area
  601.     mvi    m,ctrlz        ;prep for no file
  602.     lxi    d,shvfcb    ;try to open file
  603.     call    initfcb        ;init FCB
  604.     call    f$open
  605.     rnz            ;file not found
  606. ;
  607. ; Read in Variable File
  608. ;
  609. varl1:
  610.     lxi    d,shvfcb    ;read in file
  611.     call    f$read
  612.     jnz    varl2
  613.     lxi    d,tbuff        ;pt to data
  614.     xchg            ;copy into memory
  615.     mvi    b,128        ;128 bytes
  616.     call    hmovb
  617.     xchg
  618.     jmp    varl1
  619. varl2:
  620.     lxi    d,shvfcb    ;close file
  621.     call    f$close
  622. ;
  623. ; Say List is Already Loaded
  624. ;
  625.     xra    a        ;return NZ for OK
  626.     dcr    a
  627.     ret
  628.  
  629. ;
  630. ; Buffers
  631. ;
  632. curname:
  633.     ds    2        ;ptr to current variable name
  634. shvar:
  635.     ds    8        ;shell variable name
  636. deftype:
  637.     db    'VAR'        ;default file type
  638. ;
  639.     if    backup
  640. shvbak:
  641.     db    0
  642.     db    'SH      '    ;name of shell variable file
  643.     db    'BAK'
  644.     ds    24        ;36 bytes total
  645.     endif        ;backup
  646. ;
  647. shvtmp:
  648.     db    0
  649.     db    'SH      '    ;name of shell variable file
  650.     db    '$$$'
  651.     ds    24        ;36 bytes total
  652. shvfcb:
  653.     db    0
  654.     db    'SH      '    ;name of shell variable file
  655.     db    'VAR'
  656.     ds    24        ;36 bytes total
  657.  
  658.     end
  659.