home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / soundpot / p / vfiler43.lbr / VFMACRO.LZB / VFMACRO.LIB
Encoding:
Text File  |  1993-10-25  |  11.0 KB  |  500 lines

  1. ;===========================================================================
  2. ;
  3. ; VFMACRO.Z80
  4. ;
  5. ;===========================================================================
  6.  
  7. ;  CMACRO - Process Macro Command
  8.  
  9. noteflag:
  10.     db    0        ; Place to keep track of whether macro help
  11.                 ;   screen has been displayed
  12.  
  13. cmacro:
  14.     push    af
  15.     xor    a        ; Clear macro help screen flag
  16.     ld    (noteflag),a
  17.     pop    af
  18. cmacro1:
  19.     push    af        ; Save macro command
  20.     ld    hl,macfcb    ; Set up name of macro file
  21.     ld    de,s$fcb    ; (typically vfiler.cmd)
  22.     ld    b,12        ; 12 chars
  23.     call    moveb
  24.     call    initfcb        ; Init fcb
  25.     ld    a,0ffh        ; Search current directory
  26.     call    pfind        ; And along path for macro command file
  27.     jr    nz,cmfound    ; Macro command file found!
  28.  
  29. ; Error - Macro command file not found.
  30.  
  31.     call    erclr        ; Position cursor on message line
  32.     ld    hl,macfcb+1
  33.     call    prfnskip    ; Print macro command file name.
  34.     call    vprint
  35.     db    ' NOT Found',0
  36.     jp    loop
  37.  
  38. ; Ok - Found macro command file.
  39. ;    Now find definition of this macro.
  40.  
  41. cmfound:
  42.     call    logud        ; Log in du: where command file was found.
  43.     call    fi0$close    ; Close input file if previously opened
  44.     ld    de,s$fcb    ; Pt to fcb
  45.     call    fi0$open    ; Open for byte-oriented input
  46.     pop    af        ; Get command
  47.     ld    c,a        ; In c
  48.  
  49. ; Search for macro definition
  50.  
  51. cmfl1:
  52.     call    f0$get        ; Get first char of line
  53.     jp    nz,cmflerr    ; Eof encountered - no definition.
  54.     and    7fh        ; Mask char
  55.     call    caps        ; Force upper case
  56.     cp    c        ; Match?
  57.     jr    z,cmfl3        ; Br if so.
  58.  
  59. ; No match. Skip remainder of this line.
  60.  
  61. cmfl2:
  62.     call    f0$get        ; Skip out line
  63.     jp    nz,cmflerr    ; Eof encountered - no definition.
  64.     and    7fh        ; Mask char
  65.     cp    lf        ; Eol?
  66.     jr    nz,cmfl2
  67.     jr    cmfl1        ; Try next line.
  68.  
  69. ; Found command
  70. ;    - If Macro note, print built-in documentation (if any)
  71. ;    - For normal command, build up command and execute it.
  72.  
  73. cmfl3:
  74.     ld    a,mnote        ; Macro note?
  75.     cp    c
  76.     jp    z,cmflnote    ; Br if so.
  77.  
  78. ; Skip leading blanks in command line
  79.  
  80.     ld    hl,(bufstart)    ; Pt to first char of macro command line buffer.
  81. cmfl4:
  82.     call    f0$get        ; Get next char
  83.     jr    nz,cmfl6    ; Eof?    mark end of buffer and go
  84.     and    7fh        ; Mask char
  85.     cp    ' '        ; Skip leading blanks
  86.     jr    z,cmfl4
  87.  
  88. ; Test for shell wait command (!)
  89.  
  90.     cp    fpwait
  91.     jr    nz,cmfl5    ; If not wait command, go on
  92.     ld    a,0ffh
  93.     ld    (shwait),a
  94.     jr    cmfl4        ; Back for next character
  95.  
  96. ; Build command line in buffer
  97.  
  98. cmfl5:
  99.     cp    cr        ; Eol?
  100.     jr    z,cmfl6        ; Mark end of buffer and go
  101.     cp    eof        ; Eof?
  102.     jr    z,cmfl6        ; Mark end of buffer and go
  103.  
  104.     cp    fpesc        ; File-pointed escape char (%)
  105.     jp    z,cmflix    ; Insert parameter info in buffer if so.
  106.  
  107.     cp    uin1        ; Start user input prompt?
  108.     jr    z,cmfl5a    ; Prompt user and get response.
  109.     cp    uin2        ; Alternate start user input prompt?
  110.     jr    z,cmfl5a    ; Prompt user and get response.
  111.  
  112. cmfl50:
  113.     ld    (hl),a        ; Store ordinary command char.
  114.     inc    hl        ; Pt to next
  115. cmfl51:
  116.     call    f0$get        ; Get next char
  117.     jr    nz,cmfl6    ; Eof?    mark end of buffer and go
  118.     and    7fh        ; Mask char
  119.     jr    cmfl5        ; Try next char.
  120.  
  121. ; User input required - print prompt and get it
  122.  
  123. cmfl5a:
  124.     push    hl        ; Save current buffer ptr
  125.     call    atcmd        ; Pos'n cursor at command prompt line
  126.  
  127. cmfl5b:
  128.     call    f0$get        ; Get next char of prompt.
  129.     jr    nz,cmfl5b1    ; Eof? get eof, and then user response.
  130.     and    7fh        ; Mask char
  131.     cp    uin1        ; Input prompt terminated?
  132.     jr    z,cmfl5c    ; Ok. now get response for this one.
  133.     cp    uin2        ; Alternate input prompt terminated?
  134.     jr    z,cmfl5c    ; Ok. now get response for this one.
  135.  
  136.     cp    cr        ; End of line forces end of prompt?
  137.     jr    z,cmfl5c    ; Ok. now get response.
  138.     cp    eof        ; Eof?
  139.     jr    z,cmfl5c    ; Ok. now get response.
  140.     call    cout        ; Display prompt character and continue.
  141.     jr    cmfl5b
  142.  
  143. cmfl5b1:
  144.     ld    a,eof        ; Eof
  145. cmfl5c:
  146.     push    af        ; Save offending char
  147.     call    getzcmd        ; Get command line (up to 253 chars).
  148.     pop    af        ; Restore char
  149.     pop    de        ; De pts to next char pos'n in command buffer
  150.     ld    b,a        ; Save terminating char in b
  151.  
  152. cmfl5d:
  153.     ld    a,(hl)        ; Copy chars until
  154.     or    a        ; Zero string terminator.
  155.     jr    z,cmfl5e
  156.     ld    (de),a        ; Save char
  157.     inc    hl        ; Pt to next
  158.     inc    de
  159.     jr    cmfl5d
  160.  
  161. cmfl5e:
  162.     ex    de,hl        ; Hl pts to next char in buffer
  163.     ld    a,b        ; Check offending char
  164.     cp    uin1        ; End of prompt for user input?
  165.     jr    z,cmfl51    ; Ok. get next char and continue with command.
  166.     cp    uin2        ; Alternate end of prompt for user input?
  167.     jr    z,cmfl51    ; Ok. get next char and continue with command.
  168.     jr    cmfl5        ; No, check it out.
  169.  
  170. ; Terminate command buffer and test for content
  171.  
  172. cmfl6:
  173.     ld    (hl),0        ; Store ending 0
  174.     ld    hl,(bufstart)    ; Pt to first char of macro command.
  175.     ld    a,(hl)        ; Get first char
  176.     or    a        ; Empty?
  177.     jr    z,cmflerr    ; Br if invalid.
  178.  
  179. ; Command line seems ok. Try to chain
  180.  
  181.     ld    bc,(du$req)    ; Get current du
  182.     call    logud        ; And set it up.
  183.     call    chain        ; Chain to command line pted to by hl
  184.     jp    loop
  185.  
  186.  
  187. ; CMFLERR - Error return - null command line <or> command not defined.
  188.  
  189. cmflerr:
  190.     push    bc        ; Save command char.
  191.     ld    bc,(du$req)    ; Get current du
  192.     call    logud        ; And set it up.
  193.     pop    bc
  194.     ld    a,c        ; Get invalid command
  195.     ret
  196.  
  197.  
  198. ; CMFLNOTE - Print documentation built into the macro file
  199.  
  200. cmflnote:
  201.     ld    a,0ffh        ; Set flag to show note screen drawn
  202.     ld    (noteflag),a
  203.     call    vcls        ; New screen
  204.      if    exptab
  205.     ld    c,0        ; Set tab counter
  206.      endif
  207.  
  208. cmfln1:
  209.     call    f0$get        ; Get next char
  210.     jr    nz,cmfln4    ; Eof?    documentation complete.
  211.     and    7fh        ; Mask char
  212.     cp    eof        ; Eof?
  213.     jr    z,cmfln4    ; Documentation complete.
  214.  
  215.      if    exptab
  216.     cp    tab        ; Tab process
  217.     jr    z,cmfln2
  218.     cp    bright        ; Enhanced video indicator?
  219.     jr    nz,cmfln1a
  220.     call    stndout        ; Turn it on
  221.     jr    cmfln1        ; Back for next character
  222. cmfln1a:
  223.     cp    dim        ; Normal video indicator?
  224.     jr    nz,cmfln1b
  225.     call    stndend        ; Turn it off
  226.     jr    cmfln1        ; Back for next character
  227. cmfln1b:
  228.     call    cout        ; Print character.
  229.     cp    cr        ; New line?
  230.     jr    z,cmfln3
  231.     inc    c        ; New pos
  232.     cp    lf
  233.     jr    nz,cmfln1
  234.     dec    c        ; Back up position count
  235.     jr    cmfln1
  236.  
  237. cmfln2:
  238.     ld    a,' '        ; Space over for tab
  239.     call    cout
  240.     inc    c        ; Incr position
  241.     ld    a,c        ; Done?
  242.     and    7        ; Every 8
  243.     jr    nz,cmfln2
  244.     jr    cmfln1
  245.  
  246. cmfln3:
  247.     ld    c,0        ; Beg-of-line for cr
  248.     jr    cmfln1
  249.  
  250.      else            ; No tab expansion
  251.  
  252.     cp    bright        ; Bright video indicator?
  253.     jr    nz,cmfln3a
  254.     call    stndend        ; Turn off dim mode
  255.     jr    cmfln1        ; Back for next character
  256. cmfln3a:
  257.     cp    dim        ; Dim video indicator?
  258.     jr    nz,cmfln3b
  259.     call    stndout        ; Turn it on
  260.     jr    cmfln1        ; Back for next character
  261. cmfln3b:
  262.     call    cout        ; Print character.
  263.     jr    cmfln1        ; Get next..
  264.      endif
  265.  
  266. cmfln4:
  267.     call    vprint
  268.     db    'File Name :  ',0
  269.     ld    bc,(du$req)    ; Get current du
  270.     call    logud        ; And set it up.
  271.     ld    hl,(ringpos)    ; Print current file
  272.     inc    hl
  273.     call    prfnskip
  274.     call    vprint
  275.     db    cr,lf,lf,'Enter Macro Choice or RETURN - ',0
  276.     call    dkeyin
  277.     call    caps
  278.     call    cout        ; Echo choice
  279.     pop    de        ; Get ret address
  280.     cp    ' ' + 1        ; If control character or space, return
  281.     jp    c,runsh4a
  282.     push    de        ; Replace ret address
  283.     jp    cmacro1        ; Try again.
  284.  
  285.  
  286. ; CMFLIX - Insert parameter info for file pted to (% prefix command)
  287.  
  288. cmflix:
  289.     call    f0$get        ; Get next char
  290.     jp    nz,cmfl6    ; Eof?    mark end of buffer and go
  291.     and    7fh        ; Mask char
  292.     call    caps        ; Capitalize
  293.     ld    b,a        ; Save char in B
  294.     ex    de,hl        ; Save buffer pointer in DE
  295.  
  296.     ld    hl,cmfl51    ; Push return address
  297.     push    hl        ;   on stack
  298.     ld    hl,ptable    ; Point to parameter vector table
  299.  
  300. cmflix1:
  301.     ld    a,(hl)        ; Read char from jump table
  302.     inc    hl        ; Point to jump vector
  303.     or    a        ; See if end of table
  304.     jr    z,cmflich    ; If so, store the character
  305.     cp    b        ; Does it match the char from file?
  306.     jr    z,cmflix2    ; If so, jump
  307.     inc    hl        ; Else, point to next entry
  308.     inc    hl
  309.     jr    cmflix1
  310.  
  311. cmflix2:            ; We have a match
  312.     ld    a,(hl)        ; Get low byte of address
  313.     inc    hl
  314.     ld    h,(hl)        ; Get high byte of address
  315.     ld    l,a
  316.     push    hl        ; Push jump address onto stack
  317.     ex    de,hl        ; Restore HL to point to buffer
  318.     ret
  319.  
  320. ptable:                ; Parameter table
  321.  
  322.     db    fpptr        ; Complete file spec (du:fn.ft)
  323.     dw    cmflia
  324.  
  325.     db    fpptr1        ; Complete file spec (alternate)
  326.     dw    cmflia
  327.  
  328.     db    fpdisk        ; Current disk
  329.     dw    cmflifd
  330.  
  331.     db    fpuser        ; Current user
  332.     dw    cmflifu
  333.  
  334.     db    fpfile        ; File name and type
  335.     dw    cmfliff
  336.  
  337.     db    fpname        ; File name
  338.     dw    cmflifn
  339.  
  340.     db    fptype        ; File type
  341.     dw    cmflift
  342.  
  343.     db    fphdu        ; Home directory in DU form
  344.     dw    cmflifh
  345.  
  346.     db    fphdir        ; Home directory in DIR form
  347.     dw    cmflifr
  348.  
  349.     db    fpcdir        ; Current DIR
  350.     dw    cmflifc
  351.  
  352.     db    0        ; End of table marker
  353.  
  354.  
  355. ;---------- Store the character after the '%'
  356.  
  357. cmflich:
  358.     ex    de,hl
  359.     ld    (hl),b
  360.     ret
  361.  
  362. ;---------- Build full file spec (DU:FN.FT)
  363.  
  364. cmflia:
  365.     call    cmflifd        ; Get disk
  366.     call    cmflifu        ; Get user
  367.     ld    (hl),':'    ; Du separator
  368.     inc    hl        ; Fall thru to file name.type
  369.  
  370. ;---------- Build file name and type
  371.  
  372. cmfliff:
  373.     call    ringchk        ; Check for empty ring
  374.     ret    z        ; If empty, write nothing
  375.     call    cmflifn        ; Get file name
  376.     ld    (hl),'.'    ; Name.type separator
  377.     inc    hl        ; Fall thru to file type
  378.  
  379. ;---------- Build file type
  380.  
  381. cmflift:
  382.     call    ringchk        ; Check for empty ring
  383.     ret    z        ; If empty, write nothing
  384.     ex    de,hl        ; Save ptr to next char.
  385.     ld    hl,(ringpos)    ; Pt to current file
  386.     ld    bc,9        ; Type
  387.     add    hl,bc
  388.     ld    b,3        ; 3 chars in filetype
  389.     call    cmfl5x
  390.     ex    de,hl        ; Hl pts to next
  391.     ret
  392.  
  393. ;---------- Build file name
  394.  
  395. cmflifn:
  396.     call    ringchk        ; Check for empty ring
  397.     ret    z        ; If empty, write nothing
  398.     ex    de,hl        ; Save ptr to next char.
  399.     ld    hl,(ringpos)    ; Pt to current file
  400.     inc    hl
  401.     ld    b,8        ; 8 chars in filename
  402.     call    cmfl5x
  403.     ex    de,hl        ; Hl pts to next
  404.     ret
  405.  
  406. ;---------- Build currect directory in DIR form
  407.  
  408. cmflifc:
  409.     ld    bc,(du$req)    ; Get current du:
  410. cmflifc0:
  411.     ex    de,hl        ; Save ptr to next char.
  412.     call    dutdir        ; Scan named directory table.
  413.     jr    nz,cmflc1    ; Br if resolved.
  414.     ld    hl,nodir    ; Use 'noname'.
  415. cmflc1:
  416.     ld    b,8        ; Maximum dir length
  417.     ex    de,hl        ; Hl pts to next
  418. cmflc2:
  419.     ld    a,(de)        ; Get character.
  420.     cp    ' '        ; Done if space encountered.
  421.     ret    z
  422.     ld    (hl),a        ; Save character
  423.     inc    hl        ; Pt to next char
  424.     inc    de
  425.     djnz    cmflc2        ; Loop until end or blank.
  426.     ret
  427.  
  428. ;---------- Build current drive letter
  429.  
  430. cmflifd:
  431.     ld    a,(du$req+1)    ; Get current drive.
  432. cmflifd0:
  433.     add    a,'A'        ; Make it ascii
  434.     ld    (hl),a
  435.     inc    hl        ; Pt to next char
  436.     ret
  437.  
  438. ;---------- Build current user number
  439.  
  440. cmflifu:
  441.     ld    a,(du$req)    ; Get current user.
  442. cmflifu0:
  443.     cp    10        ; Less than 10?
  444.     jr    c,cmflifu3
  445.     ld    b,'0'        ; Compute 10's
  446. cmflifu1:
  447.     sub    10        ; Subtract 10's
  448.     jr    c,cmflifu2
  449.     inc    b
  450.     jr    cmflifu1
  451. cmflifu2:
  452.     add    a,10
  453.     ld    (hl),b        ; Store 10's
  454.     inc    hl
  455. cmflifu3:
  456.     add    a,'0'        ; Store 1's
  457.     ld    (hl),a
  458.     inc    hl
  459.     ret
  460.  
  461. ;---------- Build home directory in DIR form
  462.  
  463. cmflifr:
  464.     ld    bc,(du$orig)
  465.     jr    cmflifc0
  466.  
  467. ;---------- Build home directory in DU form
  468.  
  469. cmflifh:
  470.     ld    a,(du$orig+1)    ; Drive first
  471.     call    cmflifd0
  472.     ld    a,(du$orig)    ; Then user
  473.     jr    cmflifu0
  474.  
  475.  
  476. ringchk:            ; Check for empty ring
  477.     push    hl
  478.     ld    hl,(ringcnt)    ; Get count of files in ring
  479.     ld    a,h
  480.     or    l
  481.     pop    hl
  482.     ret            ; Z if ring empty
  483.  
  484.  
  485. ;  CMFL5X - Copy string into command line until ' '.
  486.  
  487. cmfl5x:    ld    a,(hl)        ; Get char
  488.     cp    ' '
  489.     jr    z,cmfl5x1
  490.     ld    (de),a        ; Put char
  491.     inc    hl        ; Pt to next char
  492.     inc    de
  493.     djnz    cmfl5x
  494.     ret
  495.  
  496. cmfl5x1:
  497.     inc    hl        ; Advance
  498.     djnz    cmfl5x1
  499.     ret
  500.