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 / ALIAS1.MQC / ALIAS1.MAC
Text File  |  2000-06-30  |  10KB  |  514 lines

  1. ;
  2. ; Program: ALIAS1
  3. ; Author: Richard Conn
  4. ; Version: 1.1
  5. ; Date: 10 June 84
  6. ; Previous Versions:  1.0 (5 Mar 84)
  7. ;
  8. version    equ    11
  9.  
  10. ;
  11. ;    The purpose of ALIAS1 is to load the Command Line Buffer with
  12. ; a command line stored within ALIAS1, extracting parameters using the
  13. ; SUBMIT file convention ($n) as they are referenced in the new command
  14. ; line.  Upon successful build, ALIAS1 runs the new command line by simply
  15. ; returning to ZCPR3.
  16. ;
  17.  
  18. ;
  19. ; Macros
  20. ;
  21.     MACLIB    Z3BASE.LIB
  22.  
  23. ;
  24. ; Basic Equates
  25. ;
  26. tbuff    equ    80h
  27.  
  28. ;
  29. ; External References
  30. ;
  31.     ext    z3init,getefcb,getcl1,getenv,getfn2
  32.     ext    eprint,codend,sksp,retud,caps
  33.  
  34. ;
  35. ; Environment Definition
  36. ;
  37.     if    z3env ne 0
  38. ;
  39. ; External ZCPR3 Environment Descriptor
  40. ;
  41.     jmp    start
  42.     db    'Z3ENV'    ;This is a ZCPR3 Utility
  43.     db    1    ;External Environment Descriptor
  44. z3eadr:
  45.     dw    z3env
  46. start:
  47.     lhld    z3eadr    ;pt to ZCPR3 environment
  48. ;
  49.     else
  50. ;
  51. ; Internal ZCPR3 Environment Descriptor
  52. ;
  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 Env and the VLIB Env
  65.     jmp    start1    ;skip command line buffer
  66. ;
  67. ; ALIAS ID at START+9
  68. ;
  69.     db    'Z3 ALIAS'
  70. ;
  71. ; Internal Command Line Buffer
  72. ;    This buffer address can be determined from START+17, where the
  73. ; value of START is obtained from the 2nd and 3rd bytes of ALIAS1.
  74. ;
  75. clbuf:
  76.     db    0    ;set to empty
  77.     ds    255    ;allow 256 bytes
  78. ;
  79. ; Resume ALIAS1
  80. ;
  81. start1:
  82.     call    codend    ;pt to free space in which to build new line
  83.     lxi    d,clbuf    ;pt to buffer
  84.     xchg        ;HL pts to target line, DE pts to buffer
  85. ;
  86. ; Process Next Char from Target Command Line
  87. ;
  88. nxtchar:
  89.     mov    a,m    ;get next char
  90.     ora    a    ;end of line?
  91.     jz    done
  92.     cpi    '$'    ;possible passed parameter?
  93.     jz    param
  94.     stax    d    ;store next char
  95.     inx    h    ;pt to next
  96.     inx    d
  97.     jmp    nxtchar
  98. ;
  99. ; Process Possible Parameter
  100. ;
  101. param:
  102.     lxi    b,nxtchar    ;establish return address
  103.     push    b    ;... on stack
  104.     inx    h    ;get parameter char
  105.     mov    a,m
  106.     call    caps    ;capitalize
  107.     cpi    '*'    ;entire tail?
  108.     jz    paraml
  109.     cpi    'D'    ;current disk?
  110.     jz    paramd
  111.     cpi    'U'    ;current user?
  112.     jz    paramu
  113.     cpi    'F'    ;System Filename.Typ?
  114.     jz    paramf
  115.     cpi    'N'    ;System Filename?
  116.     jz    paramn
  117. ;    cpi    'T'    ;System Typ?
  118. ;    jz    paramt
  119.     sui    '0'    ;convert
  120.     jc    noparam
  121.     cpi    10    ;range?
  122.     jnc    noparam
  123.     ora    a    ;parameter 0 = original name
  124.     jz    oname
  125.     mov    b,a    ;count in B (1 or more)
  126.     inx    h    ;pt to next char
  127.     push    h    ;save ptr
  128.     lxi    h,tbuff+1    ;pt to input line
  129. ;
  130. ; Advance to Desired Parameter
  131. ;
  132. param1:
  133.     call    sksp    ;skip to non-blank
  134.     mov    a,m    ;check for done
  135.     ora    a
  136.     jz    paramx
  137.     dcr    b    ;count down
  138.     jz    param3    ;got it
  139. ;
  140. ; Skip Over This Parameter
  141. ;
  142. param2:
  143.     mov    a,m    ;skip to space or EOL
  144.     inx    h    ;pt to next
  145.     cpi    ' '    ;space
  146.     jz    param1
  147.     ora    a    ;EOL
  148.     jz    paramx
  149.     jmp    param2    ;continue
  150. ;
  151. ; Extract Parameter Into Target Buffer
  152. ;
  153. param3:
  154.     mov    a,m    ;get char
  155.     cpi    ' '+1    ;done?
  156.     jc    paramx
  157.     stax    d    ;store char
  158.     inx    h    ;advance
  159.     inx    d
  160.     jmp    param3
  161. ;
  162. ; Resume Processing of Target Command
  163. ;
  164. paramx:
  165.     pop    h    ;restore ptr to next char
  166.     ret        ;resume at next char
  167. ;
  168. ; Parameter is for System Filename.typ
  169. ;
  170. paramf:
  171.     call    getfnum    ;get file number
  172.     rz        ;resume if error
  173.     push    h    ;save ptr to next char
  174.     call    ptfn    ;set ptr to file name
  175.     call    putn    ;put file name
  176.     mvi    a,'.'    ;dot
  177.     stax    d
  178.     inx    d
  179.     call    putt    ;put file type
  180.     pop    h    ;restore ptr
  181.     ret
  182. ;
  183. ; Parameter is for System Filename
  184. ;
  185. paramn:
  186.     call    getfnum    ;get file number
  187.     rz        ;resume if error
  188.     push    h    ;save ptr to next char
  189.     call    ptfn    ;set ptr to file name
  190.     call    putn    ;put file name
  191.     pop    h    ;restore ptr
  192.     ret
  193. ;
  194. ; Parameter is for System Typ
  195. ;
  196. ;paramt:
  197. ;    call    getfnum    ;get file number
  198. ;    jz    nxtchar    ;resume if error
  199. ;    push    h    ;save ptr to next char
  200. ;    call    ptfn    ;set ptr to file name
  201. ;    mvi    a,8    ;add 8 to get to file type
  202. ;    add    l
  203. ;    mov    l,a
  204. ;    mov    a,h
  205. ;    aci    0
  206. ;    mov    h,a
  207. ;    call    putt    ;put file type
  208. ;    pop    h    ;restore ptr
  209. ;    jmp    nxtchar
  210.  
  211. ;
  212. ; Get File Number (1 to 4)
  213. ;    If valid number, return with value in A and HL pting to next char
  214. ;    If not valid, return with Z and HL pting to next char (the number)
  215. ;
  216. getfnum:
  217.     inx    h    ;pt to number
  218.     mov    a,m    ;get char
  219.     sui    '1'    ;convert
  220.     jc    getfne    ;error if less
  221.     cpi    4    ;range?
  222.     jnc    getfne    ;error if more
  223.     inx    h    ;pt to next char
  224.     ret        ;NZ from CPI 4
  225. getfne:
  226.     xra    a    ;return Z
  227.     ret
  228. ;
  229. ; Pt to File Name whose Number (1-4) is in A
  230. ;
  231. ptfn:
  232.     mov    b,a    ;number in B
  233.     call    getfn2    ;pt to file name 2
  234.     push    d    ;save DE
  235.     mov    a,b    ;file 0?
  236.     ora    a
  237.     jz    ptfnx
  238.     lxi    d,11    ;size of file name and type
  239. ptfn1:
  240.     dad    d    ;pt to next
  241.     dcr    b    ;count down
  242.     jnz    ptfn1
  243. ptfnx:
  244.     pop    d    ;restore DE
  245.     ret
  246. ;
  247. ; Put File Name pted to by HL
  248. ;
  249. putn:
  250.     mvi    b,8    ;8 chars
  251.     jmp    putc
  252. ;
  253. ; Put File Type pted to by HL
  254. ;
  255. putt:
  256.     mvi    b,3    ;3 chars
  257. ;
  258. ; Copy chars from HL to DE for up to 8 bytes - flush if space
  259. ;
  260. putc:
  261.     mov    a,m    ;get next char
  262.     cpi    ' '    ;skip spaces
  263.     jz    putc1
  264.     stax    d    ;put next char
  265.     inx    d    ;pt to next
  266. putc1:
  267.     inx    h    ;pt to next
  268.     dcr    b    ;count down
  269.     jnz    putc
  270.     ret
  271. ;
  272. ; Parameter is for Disk Letter
  273. ;
  274. paramd:
  275.     call    retud    ;get DU in BC
  276.     mov    a,b    ;get disk letter
  277.     adi    'A'    ;convert to ASCII
  278.     stax    d    ;store char
  279.     inx    d    ;pt to next
  280.     inx    h    ;pt to next char
  281.     ret
  282. ;
  283. ; Parameter is for User Number
  284. ;
  285. paramu:
  286.     call    retud    ;get DU in BC
  287.     mov    a,c    ;get user number
  288.     mvi    b,10    ;compute 10's
  289.     mvi    c,'0'
  290. pmu1:
  291.     sub    b    ;subtract 10's
  292.     jc    pmu2
  293.     inr    c    ;increment 10's
  294.     jmp    pmu1
  295. pmu2:
  296.     add    b    ;add B back in
  297.     adi    '0'    ;convert to ASCII
  298.     mov    b,a    ;10's in C, 1's in B
  299.     mov    a,c
  300.     cpi    '0'    ;no leading 0's
  301.     jz    pmu3
  302.     stax    d    ;store char
  303.     inx    d    ;pt to next
  304. pmu3:
  305.     mov    a,b    ;get 1's
  306.     stax    d    ;store char
  307.     inx    d    ;pt to next
  308.     inx    h    ;pt to next char
  309.     ret
  310. ;
  311. ; Parameter is command line tail
  312. ;
  313. paraml:
  314.     inx    h    ;pt to char after parameter letter
  315.     push    h    ;save ptr to parameter
  316.     lxi    h,tbuff+1    ;pt to tail
  317. paramt1:
  318.     mov    a,m    ;copy tail into line
  319.     ora    a    ;end of tail?
  320.     jz    paramt2
  321.     stax    d    ;store char
  322.     inx    h    ;pt to next
  323.     inx    d
  324.     jmp    paramt1
  325. paramt2:
  326.     pop    h    ;pt to next char in script
  327.     ret        ;continue processing
  328. ;
  329. ; Form assumed to be $$
  330. ;
  331. noparam:
  332.     mvi    a,'$'    ;store '$'
  333.     stax    d
  334.     inx    d    ;pt to next chars
  335.     inx    h
  336.     ret
  337. ;
  338. ; $0 - ALIAS Command Name
  339. ;
  340. oname:
  341.     inx    h    ;pt to next char
  342.     push    h    ;save ptr
  343.     call    getefcb    ;pt to FCB
  344.     jz    paramx    ;skip if no external FCB
  345.     inx    h    ;pt to first char
  346.     mvi    b,8    ;at most 8 chars
  347. on1:
  348.     mov    a,m    ;copy into output line
  349.     cpi    ' '    ;done if space
  350.     jz    paramx
  351.     stax    d    ;store char
  352.     inx    h    ;pt to next
  353.     inx    d
  354.     dcr    b    ;count down
  355.     jnz    on1
  356.     jmp    paramx
  357.  
  358. ;
  359. ; Done -- Buffer is Loaded
  360. ;
  361. done:
  362.     xra    a    ;store ending 0
  363.     stax    d
  364.     call    codend    ;pt to buffer
  365.     mov    a,m    ;skip if empty line
  366.     ora    a
  367.     rz
  368. ;
  369. ; Determine if ZCPR3 Environment Support is Available for Command Line
  370. ;
  371.     push    h    ;save ptr to line
  372.     call    getenv    ;get environment
  373.     mov    a,h
  374.     ora    l
  375.     jz    done0
  376. ;
  377. ; Get environment from descriptor
  378. ;
  379.     call    getcl1    ;get command line data
  380.     mov    b,a    ;save char count
  381.     mov    a,h    ;check for no command line
  382.     ora    l
  383.     jz    done0
  384.     mov    a,b    ;restore char count
  385.     ora    a    ;check for no chars
  386.     jnz    done1
  387. ;
  388. ; Get environment from MACRO File
  389. ;
  390. done0:
  391.     lxi    h,z3cl    ;pt to command line from macro expansion
  392.     mvi    a,z3cls    ;get size of command line
  393. ;
  394. ; Store Command Line
  395. ;
  396. done1:
  397.     pop    d    ;DE pts to line
  398.     call    putcl    ;store in command line
  399.     rnz        ;return to ZCPR3 for processing if OK
  400.     call    eprint
  401.     db    'Ovfl',0
  402.     ret
  403. ;
  404. ;    PUTCL stores a command line in the ZCPR3 command line buffer.
  405. ; This command line is pted to by DE.  CL Buffer is pted to by HL.
  406. ; Size in A. On return, A=0 and Zero
  407. ; Flag Set if command line overflow is possible (no change to command line).
  408. ;
  409. putcl:
  410.     shld    clbfr    ;save ptr to command line buffer
  411.     ora    a    ;any command line?
  412.     jz    nocl
  413.     mov    b,a    ;char count in B
  414.     xchg        ;HL pts to new line
  415.     push    h    ;save ptr to new line
  416. pcl2:
  417.     mov    a,m    ;go to end of line
  418.     ora    a    ;at end?
  419.     jz    pcl3
  420.     inx    h    ;pt to next
  421.     dcr    b    ;count down
  422.     jnz    pcl2
  423.     pop    h    ;clear stack
  424. ;
  425. ; Command Line Buffer Overflow
  426. ;
  427. nocl:
  428.     xra    a    ;error return
  429.     ret
  430. ;
  431. ; At End of New Command Line (ptr on stack)
  432. ;    Ptr to first char of new command line on stack
  433. ;    HL pts to ending 0 of new command line
  434. ;    B = number of chars remaining before overflow of Z3 command line
  435. ;
  436. pcl3:
  437.     push    h    ;save ptr to last byte in case of error
  438.     lhld    clbfr    ;pt to tail of command line
  439.     mov    e,m
  440.     inx    h
  441.     mov    d,m
  442.     xchg        ;HL pts to command line tail
  443.     pop    d    ;restore ptr to last byte of command line
  444.     push    d
  445.     mov    a,m    ;get first char of tail
  446.     cpi    ';'    ;continuation?
  447.     jz    pcl4
  448.     ora    a    ;done?
  449.     jz    pcl4
  450.     mvi    a,';'    ;set continuation char
  451.     stax    d
  452.     inx    d
  453.     dcr    b    ;count down
  454.     jz    pcl5    ;overflow
  455. ;
  456. ; Copy tail onto end of new command line
  457. ;
  458. pcl4:
  459.     mov    a,m    ;get next char
  460.     stax    d    ;store it
  461.     inx    h    ;pt to next
  462.     inx    d
  463.     ora    a    ;done?
  464.     jz    pcl6
  465.     dcr    b    ;count down
  466.     jnz    pcl4
  467. ;
  468. ; Command Line too Long
  469. ;
  470. pcl5:
  471.     pop    h    ;get ptr to end of old line
  472.     mvi    m,0    ;store ending 0
  473.     pop    psw    ;clear stack
  474.     jmp    nocl
  475. ;
  476. ; New Command Line OK
  477. ;
  478. pcl6:
  479.     pop    psw    ;clear stack
  480.     lhld    clbfr    ;pt to command line buffer
  481.     lxi    d,4    ;pt to first char in buffer
  482.     xchg
  483.     dad    d
  484.     xchg
  485.     mov    m,e    ;store address
  486.     inx    h
  487.     mov    m,d    ;DE pts to first char of buffer
  488.     pop    h    ;HL pts to first char of new line
  489. ;
  490. ; Copy New Command Line into Buffer
  491. ;
  492. pcl7:
  493.     mov    a,m    ;copy
  494.     stax    d
  495.     inx    h
  496.     inx    d
  497.     ora    a    ;EOL?
  498.     jnz    pcl7
  499. ;
  500. ; Exit with OK Code
  501. ;
  502.     xra    a    ;set NZ
  503.     dcr    a
  504.     ret
  505.  
  506. ;
  507. ; Buffers
  508. ;
  509. clbfr:
  510.     ds    2    ;ptr to command line
  511.  
  512.     end
  513.  
  514.