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 / PATH.MAC < prev    next >
Text File  |  2000-06-30  |  9KB  |  460 lines

  1. ;
  2. ;  PROGRAM:  PATH
  3. ;  VERSION:  3.0
  4. ;  AUTHOR:  RICHARD CONN
  5. ;  DATE:  12 Apr 84
  6. ;  PREVIOUS VERSIONS:  NONE
  7. ;  DERIVATION:  PATH, Version 1.0 (for ZCPR2) of 12 Jan 83
  8. ;
  9. VERS    EQU    30
  10. z3env    SET    0f400h
  11.  
  12. ;
  13. ;    PATH allows the user to do two things -- display the current path
  14. ; and set a new path.  Named directories may be used in the definition of
  15. ; the new path.
  16. ;
  17. ;    PATH is invoked by the following forms:
  18. ;        PATH            <-- Display Path
  19. ;        PATH path-expression    <-- Set Path
  20. ;        PATH //            <-- Print Help
  21. ;
  22.  
  23. ;
  24. ;  CP/M Constants
  25. ;
  26. cpm    equ    0    ;base
  27. fcb    equ    cpm+5ch
  28. tbuff    equ    cpm+80h
  29. cr    equ    0dh
  30. lf    equ    0ah
  31.  
  32. ;
  33. ;  SYSLIB Routines
  34. ;
  35.     ext    z3init,eprint,codend,dirtdu,dutdir
  36.     ext    cout,epstr,pafdc,retud
  37.     ext    getpath,getmdisk,getmuser,getwhl
  38.  
  39. ;
  40. ; Environment Definition
  41. ;
  42.     if    z3env ne 0
  43. ;
  44. ; External ZCPR3 Environment Descriptor
  45. ;
  46.     jmp    start
  47.     db    'Z3ENV'    ;This is a ZCPR3 Utility
  48.     db    1    ;External Environment Descriptor
  49. z3eadr:
  50.     dw    z3env
  51. start:
  52.     lhld    z3eadr    ;pt to ZCPR3 environment
  53. ;
  54.     else
  55. ;
  56. ; Internal ZCPR3 Environment Descriptor
  57. ;
  58.     MACLIB    Z3BASE.LIB
  59.     MACLIB    SYSENV.LIB
  60. z3eadr:
  61.     jmp    start
  62.     SYSENV
  63. start:
  64.     lxi    h,z3eadr    ;pt to ZCPR3 environment
  65.     endif
  66.  
  67. ;
  68. ; Start of Program -- Initialize ZCPR3 Environment
  69. ;
  70.     call    z3init    ;initialize the ZCPR3 Env and the VLIB Env
  71.     lxi    h,0    ;save stack ptr
  72.     dad    sp
  73.     shld    strtstack    ; save ptr to original stack
  74.     lxi    h,tbuff+1    ; pt to command line input
  75.     shld    cmdline    ; save ptr to command line
  76.     call    retud    ; get current disk and user
  77. ;
  78. ;  Print Banner
  79. ;
  80.     call    eprint
  81.     db    'PATH  Version '
  82.     db    vers/10+'0','.',(vers mod 10)+'0',0
  83.  
  84. ;
  85. ;  Check for Help
  86. ;
  87.     lda    fcb+1    ; get first char
  88.     cpi    '/'    ; help?
  89.     jnz    start1
  90.     call    eprint
  91.     db    cr,lf,'Syntax:'
  92.     db    cr,lf,'  PATH       <-- Display Path'
  93.     db    cr,lf,'  PATH expr  <-- Set Path'
  94.     db    0
  95.     ret
  96.  
  97. ;
  98. ;  Check for Error and Continue if not
  99. ;
  100. start1:
  101.     call    getpath    ; external path available?
  102.     mov    a,h    ; HL=0 if none
  103.     ora    l
  104.     jnz    start2
  105.     call    eprint
  106.     db    ' - Abort: No Path',0
  107.     ret
  108. start2:
  109.     call    getwhl    ; check for wheel
  110.     jnz    start3
  111.     call    eprint
  112.     db    ' - Abort: No Wheel',0
  113.     ret
  114. start3:
  115.     lhld    cmdline    ; check command line for text
  116.     call    sblank    ; skip to non-blank
  117.     shld    cmdline    ; set ptr to next element
  118.     ora    a    ; EOL=display function
  119.     jz    pdisp
  120.     call    codend    ; set temporary path
  121.     shld    pathptr    ; point to it
  122.  
  123. ;
  124. ;  **** Set New Path ****
  125. ;    CMDLINE pts to next element
  126. ;
  127. pbuild:
  128.     lhld    cmdline    ; pt to next element
  129.     call    sblank    ; skip to non-blank
  130.     mov    a,m    ; get first char of next element
  131.     ora    a    ; EOL?
  132.     jz    pbdone    ; done if so, store path and display
  133.     shld    token    ; save ptr to first byte
  134.     mov    a,m    ; get first char
  135.     cpi    '$'    ; is it current?
  136.     jz    pbdu    ; DU: form
  137.     sui    'A'    ; convert to number
  138.     jc    pbdir    ; DIR: form
  139.     mov    b,a    ; save number
  140.     call    getmdisk    ; get max disk number
  141.     mov    c,a
  142.     mov    a,b
  143.     cmp    c    ; in range?
  144.     jnc    pbdir    ; DIR: form if not
  145.     inx    h    ; pt to next char -- may be DU or DIR
  146.     mov    a,m    ; get next part of element
  147.     cpi    '$'    ; current?
  148.     jz    pbdu    ; is a DU: form
  149. digtst:
  150.     cpi    ':'    ; colon ends it
  151.     jz    pbdu    ; is a DU: form
  152.     cpi    ' '    ; space ends it
  153.     jz    pbdu
  154.     ora    a    ; EOL ends it
  155.     jz    pbdu
  156.     cpi    '0'    ; must be a digit
  157.     jc    pbdir    ; DIR: form if not in range
  158.     cpi    '9'+1
  159.     jnc    pbdir
  160.     inx    h    ; pt to next
  161.     mov    a,m    ; get it
  162.     jmp    digtst
  163. ;
  164. ;  It is a DU: form
  165. ;
  166. pbdu:
  167.     lhld    pathptr    ; pt to path entry
  168.     xchg        ; ... in DE
  169.     lhld    token    ; pt to token
  170.     mov    a,m    ; current?
  171.     cpi    '$'
  172.     jz    pbdu1
  173.     sui    'A'-1    ; convert to number from 1 to n
  174. pbdu1:
  175.     stax    d    ; save disk element
  176.     inx    h    ; pt to next
  177.     inx    d
  178.     mov    a,m    ; current user?
  179.     inx    h    ; pt to after user in case of match to current
  180.     cpi    '$'    ; current?
  181.     jz    pbdu2
  182.     dcx    h    ; pt to first digit
  183.     push    d    ; save ptr to path
  184.     call    eval10    ; convert to number in C
  185.     jc    rangerr
  186.     call    getmuser    ; check for max user
  187.     inr    a
  188.     mov    b,a    ; place max in B
  189.     mov    a,c    ; value in A
  190.     cmp    b
  191.     jnc    rangerr
  192.     pop    d    ; get ptr to path
  193. pbdu2:
  194.     stax    d    ; store user number
  195.     inx    d
  196.     mov    a,m    ; ending with colon?
  197.     cpi    ':'
  198.     jnz    pbdu3
  199.     inx    h    ; skip over colon
  200. pbdu3:
  201.     shld    cmdline    ; save ptr to next command line entry
  202.     xchg
  203.     shld    pathptr    ; save ptr to next path entry
  204.     jmp    pbuild    ; continue processing
  205. ;
  206. ;  Build DIR: form
  207. ;
  208. pbdir:
  209.     lhld    token    ; pt to name
  210.     call    dirtdu    ; convert to DU in BC
  211.     jnz    gotud    ; process new DU
  212. ;
  213. ;  Entry not found
  214. ;
  215. rangerr:
  216.     call    eprint
  217.     db    cr,lf,'Bad Expression at ',0
  218.     lhld    token    ; print string starting at token
  219.     call    epstr
  220.     lhld    strtstack    ; get original stack
  221.     sphl            ; set stack ptr
  222.     ret
  223. ;
  224. ;  Got User and Disk -- Store in Path
  225. ;
  226. gotud:
  227.     lhld    pathptr    ; get ptr to path
  228.     inr    b    ; disk A = 1
  229.     mov    m,b    ; store disk
  230.     inx    h
  231.     mov    m,c    ; store user
  232.     inx    h    ; pt to next
  233.     shld    pathptr
  234.     lhld    token    ; skip over token
  235. gotud1:
  236.     mov    a,m    ; skip to space or EOL
  237.     inx    h    ; pt to next
  238.     ora    a    ; EOL?
  239.     jz    gotud2
  240.     cpi    ' '    ; space?
  241.     jnz    gotud1
  242. gotud2:
  243.     dcx    h    ; pt to EOL or space
  244.     shld    cmdline    ; set ptr to next element
  245.     jmp    pbuild    ; continue building
  246. ;
  247. ;  Path Building is Done -- CODEND contains new path
  248. ;
  249. pbdone:
  250.     lhld    pathptr    ; store ending zero in path
  251.     mvi    m,0
  252.     call    getpath    ; pt to path
  253.     xchg        ; ... in DE
  254.     call    codend    ; copy temp path into external path
  255. pcopy:
  256.     mov    a,m    ; get disk
  257.     stax    d    ; put disk
  258.     ora    a    ; end of path?
  259.     jz    pdisp    ; done if so and display
  260.     inx    h    ; pt to user
  261.     inx    d
  262.     mov    a,m    ; get user
  263.     stax    d    ; put user
  264.     inx    h    ; pt to next disk
  265.     inx    d
  266.     jmp    pcopy
  267.  
  268. ;
  269. ;  **** Display Path Function ****
  270. ;
  271. pdisp:
  272.     call    eprint
  273.     db    cr,lf,' Symbolic Form: ',0
  274.     call    getpath    ; pt to external path
  275. pdisp1:
  276.     mov    a,m    ; get disk
  277.     ora    a    ; done?
  278.     jz    adisp
  279.     cpi    '$'    ; current?
  280.     jz    pdisp2
  281.     adi    '@'    ; convert to letter
  282. pdisp2:
  283.     call    cout    ; print disk letter
  284.     inx    h    ; pt to user
  285.     mov    a,m    ; get user number
  286.     cpi    '$'    ; current?
  287.     jnz    pdisp3
  288.     call    cout    ; print current indicator
  289.     jmp    pdisp4
  290. pdisp3:
  291.     call    pafdc    ; print user number
  292. pdisp4:
  293.     call    colon
  294.     inx    h    ; pt to next element
  295.     mov    a,m    ; done?
  296.     ora    a    ; 0=yes
  297.     cnz    arrow
  298.     jmp    pdisp1
  299. ;
  300. ;  Print Absolute Path
  301. ;
  302. adisp:
  303.     call    eprint
  304.     db    cr,lf,' DU Form:       ',0
  305.     call    retud    ; get current user/disk
  306.     call    getpath    ; pt to path
  307. adisp1:
  308.     mov    a,m    ; get disk
  309.     ora    a    ; done?
  310.     jz    ndisp
  311.     cpi    '$'    ; current?
  312.     jnz    adisp2
  313.     mov    a,b    ; get current disk
  314.     inr    a    ; adjust to 1 to n
  315. adisp2:
  316.     adi    '@'    ; convert to letter
  317.     call    cout    ; print disk letter
  318.     inx    h    ; pt to user
  319.     mov    a,m    ; get user
  320.     cpi    '$'    ; current?
  321.     jnz    adisp3
  322.     mov    a,c    ; get current user
  323. adisp3:
  324.     call    pafdc    ; print user
  325.     call    colon
  326.     inx    h    ; pt to next
  327.     mov    a,m    ; done?
  328.     ora    a
  329.     cnz    arrow
  330.     jmp    adisp1
  331. ;
  332. ;  Print Named Path
  333. ;
  334. ndisp:
  335.     call    eprint
  336.     db    cr,lf,' DIR Form:      ',0
  337.     call    getpath    ; pt to external path
  338. ndisp1:
  339.     call    retud    ; get current user and disk in C and B
  340.     mov    a,m    ; get disk
  341.     ora    a    ; done?
  342.     rz
  343.     cpi    '$'    ; current?
  344.     jz    ndisp2
  345.     mov    b,a    ; disk in B
  346.     dcr    b    ; adjust to 0 to n-1
  347. ndisp2:
  348.     inx    h    ; pt to user
  349.     mov    a,m    ; get it
  350.     cpi    '$'    ; current?
  351.     jz    ndisp3
  352.     mov    c,a    ; user in C
  353. ndisp3:
  354.     inx    h    ; pt to next
  355.     push    h    ; save ptr
  356.     call    udscan    ; scan dirs for user/disk and print its name
  357.     pop    h    ; get ptr
  358.     call    colon
  359.     mov    a,m    ; done?
  360.     ora    a
  361.     cnz    arrow
  362.     jmp    ndisp1
  363.  
  364. ;
  365. ;  **** Utilities ****
  366. ;
  367.  
  368. ;
  369. ;  Convert Chars pted to by HL to Number in C
  370. ;    Return with Carry Set if Overflow
  371. ;    If OK, Value in C and HL pts to character after last digit
  372. ;
  373. eval10:
  374.     mvi    c,0    ; set value
  375. eval1:
  376.     mov    a,m    ; get first digit
  377.     sui    '0'    ; convert to binary
  378.     jc    evalx    ; done with value in C
  379.     cpi    10    ; range?
  380.     jnc    evalx    ; done with value in C
  381.     mov    b,a    ; digit in B
  382.     mov    a,c    ; multiply by 10
  383.     add    a    ; *2
  384.     rc        ; error abort
  385.     add    a    ; *4
  386.     rc
  387.     add    c    ; *5
  388.     rc
  389.     add    a    ; *10
  390.     rc
  391.     add    b    ; add value
  392.     rc
  393.     mov    c,a    ; value in C
  394.     inx    h    ; pt to next
  395.     jmp    eval1
  396. evalx:
  397.     ora    a    ; clear carry flag
  398.     ret
  399.  
  400. ;
  401. ;  Print Colon
  402. ;
  403. colon:
  404.     mvi    a,':'    ; print colon
  405.     jmp    cout
  406.  
  407. ;
  408. ;  Print Arrow
  409. ;
  410. arrow:
  411.     call    eprint
  412.     db    ' --> ',0
  413.     ret
  414.  
  415. ;
  416. ;  Skip to non-blank
  417. ;
  418. sblank:
  419.     mov    a,m    ; get char
  420.     inx    h    ; pt to next
  421.     cpi    ' '    ; space?
  422.     jz    sblank
  423.     dcx    h    ; pt to non-blank
  424.     ret
  425. ;
  426. ;  Scan directories for user and disk in C and B
  427. ;    Print name if found or "Noname" if not
  428. ;
  429. udscan:
  430.     call    dutdir    ; convert to name
  431.     jz    udscan1    ; error return if no name
  432.     mvi    b,8    ; 8 chars max
  433. udsprn:
  434.     mov    a,m    ; get name char
  435.     cpi    ' '    ; done?
  436.     rz
  437.     call    cout    ; print char
  438.     inx    h    ; pt to next
  439.     dcr    b    ; count down
  440.     jnz    udsprn
  441.     ret
  442. udscan1:
  443.     call    eprint
  444.     db    'Noname',0
  445.     ret
  446.  
  447. ;
  448. ;  Buffers
  449. ;
  450. cmdline:
  451.     ds    2    ; ptr to next char in command line
  452. token:
  453.     ds    2    ; ptr to current token
  454. pathptr:
  455.     ds    2    ; ptr to next path entry
  456. strtstack:
  457.     ds    2    ; ptr to original stack
  458.  
  459.     end
  460.