home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / cpm68k / msutils.lbr / RENAME.SQ / RENAME.S
Encoding:
Text File  |  1988-02-18  |  8.9 KB  |  337 lines

  1. *#######################################################################
  2. *           PROGRAM RENAME...Rename Utility
  3. *
  4. *            Dr. David C. Wilcox
  5. *            DCW Industries, Inc.
  6. *         5354 Palm Dr., La Canada, CA  91011
  7. *               818/790-3844
  8. *
  9. *             January 26, 1986
  10. *#######################################################################
  11. *  Special registers:
  12. *
  13. *    a6 = address of first parsed FCB
  14. *    d3 = drive designation
  15. *    d7 = number of file matches counter
  16. *#######################################################################
  17. boot    equ    00        *warm boot
  18. outchar    equ    02        *print character
  19. print    equ    09        *print string
  20. sfirst    equ    17        *search for first
  21. snext    equ    18        *Search for Next
  22. setdma    equ    26        *Set DMA Address
  23. rename    equ    23        *rename file
  24. current    equ    25        *return current disk
  25. lf    equ    10        *line feed
  26. cr    equ    13        *carriage return
  27. space    equ    32        *ascii space
  28. bdos    equ    $0002        *BDOS entry point
  29. *#######################################################################
  30. *
  31. *  Locate FCB (for portability)
  32. *
  33.     link    a6,#0        *mark stack frame
  34.     move.l    8(a6),a0    *get base page address
  35.     lea    $5c(a0),a6    *get address of FCB and save it in a6
  36. *
  37. *  Clear data registers and determine drive designation
  38. *
  39.     jsr    clear
  40.     jsr    getdrv
  41. *
  42. *  Check for no file specified
  43. *
  44.     cmpi.b    #space,1(a6)    *is 1st char in filespec a space?
  45.     bne    start
  46.     move.l    #usage,d1    *if no parameters...
  47.     jsr    pstring        *display instructions
  48.     jsr    quit        *and exit to CP/M
  49. *
  50. *  Copy source file to FCB
  51. *
  52. start:    movea.l    a6,a1
  53.     movea.l    #fcb,a0
  54.     move.w    #12,d2
  55.     jsr    movmem
  56. *
  57. *  Copy destination file to FCB
  58. *
  59.     movea.l    a6,a1        *make sure the drive specified
  60.     movea.l    #named-1,a0    *matches...will need it to
  61.     move.b    (a1)+,(a0)+    *prevent renaming to existing name
  62.     movea.l    a6,a1        *point to 1st parsed FCB
  63.     suba.w    #35,a1        *adjust to point to 2nd parsed FCB
  64.     move.w    #11,d2
  65.     jsr    movmem
  66. *
  67. *  Check for wildcards
  68. *
  69.     jsr    examin        *check for wildcards...
  70.     cmpi.b    #1,d7        *return d7=1 for no, d7=0 for yes
  71.     bne    begin        *wildcards found...must search directory
  72.     movea.l    a6,a0        *put original fcb in a0 since no search
  73.     jmp    prelim        *no wildcards...skip directory search
  74. *
  75. *  Begin search for file name matches
  76. *
  77. begin:    move.l    #mydma,d1    *===================
  78.     move.w    #setdma,d0    *Set the DMA Address
  79.     trap    #bdos        *===================
  80.     move.l    a6,d1        *Load the FCB
  81.     move.w    #sfirst,d0    *and search for the first match
  82.     trap    #bdos
  83.     cmpi.b    #$ff,d0        *Is there no match?
  84.     bne    search
  85.     move.l    #nofile,d1    *No match if it's zero so QUIT
  86.     jsr    pstring
  87.     bra    quit
  88. *
  89. *  Search for file name matches
  90. *
  91. search:    mulu    #32,d0        *Adjust for offset in DMA of matching entry
  92.     move.l    #mydma,a1    *Point to mydma
  93.     adda.w    d0,a1        *and add the offset
  94.     movea.l    #bufadr,a4    *Point to buffer
  95.     move.l    (a4),a0
  96.     move.w    #32,d2        *Initialize the counter
  97.     jsr    movmem        *Copy a1 to a0
  98.     move.l    a0,bufadr    *Save buffer address
  99.     addq    #1,d7        *Increment file match counter
  100.     move.l    a6,d1        *=========================
  101.     move.w    #snext,d0    *Search for next occurance
  102.     trap    #bdos        *=========================
  103.     cmpi.b    #$ff,d0        *Is there no match?
  104.     bne    search        *Keep searching until all are found
  105.     movea.l    #buffer,a0    *Point to the original buffer
  106.     move.l    a0,bufadr    *Save buffer address
  107. *
  108. *  Rename Files
  109. *
  110. prep:    jsr    setup        *fill in wildcard bytes
  111. prelim:    movea.l    #named-1,a1    *check for existing file
  112.     movea.l    #xfcb,a0    *with same name as the
  113.     move.w    #12,d2        *proposed destination name
  114.     jsr    movmem
  115.     move.l    #xfcb,d1
  116.     move.w    #sfirst,d0
  117.     trap    #bdos
  118.     cmpi.b    #$ff,d0        *does it exist?
  119.     beq    name
  120.     move.l    #exists,d1    *say so if it does...
  121.     jsr    pstring
  122.     jsr    quit        *and exit to CP/M
  123. *
  124. name:    move.l    #fcb,d1        *do the rename
  125.     move.w    #rename,d0
  126.     trap    #bdos
  127.     cmpi.b    #$ff,d0        *rename successful?
  128.     bne    okay
  129.     move.l    #nofile,d1    *file not found...say so
  130.     jsr    pstring
  131.     jsr    quit        *and return to CP/M
  132. *
  133. okay:    jsr    drivepr        *display drive identifier
  134.     movea.l    #names,a0    *echo the source name
  135.     jsr    filnam
  136.     jsr    filtyp
  137.     move.l    #arrow,d1    *then display an arrow
  138.     jsr    pstring
  139.     jsr    drivepr        *the drive identifier
  140.     movea.l    #named,a0    *and the destination name
  141.     jsr    filnam
  142.     jsr    filtyp
  143.     move.l    #crlf,d1    *conclude with a cr/lf
  144.     jsr    pstring
  145. *
  146. *  Prepare for next file
  147. *
  148. nexfile:
  149.     subq    #1,d7        *Decrement the file match counter
  150.     beq    quit        *If last file...QUIT
  151.     movea.l    #bufadr,a4    *Point to buffer
  152.     move.l    (a4),a0
  153.     adda.l    #32,a0        *Add 32 bytes to point to next match
  154.     move.l    a0,bufadr    *Save buffer address
  155.     jmp    prep        *Loop back for the next file
  156. *#######################################################################
  157. *                           Subroutines
  158. *#######################################################################
  159. *
  160. *  Clear all data registers
  161. *
  162. clear:    
  163.     clr.l    d0
  164.     clr.l    d1
  165.     clr.l    d2
  166.     clr.l    d3
  167.     clr.l    d4
  168.     clr.l    d5
  169.     clr.l    d6
  170.     clr.l    d7
  171.     rts
  172. *
  173. *  Send a character to the console
  174. *
  175. conout:
  176.     move.w    #outchar,d0
  177.     trap    #bdos
  178.     rts
  179. *
  180. *  Display drive identifier
  181. *
  182. drivepr:
  183.     move.b    d3,d1
  184.     jsr    conout
  185.     move.b    #':',d1
  186.     jsr    conout
  187.     rts
  188. *
  189. *  Examine input file names for wildcards
  190. *
  191. examin:    
  192.     move.w    #1,d7        *d7 (file count) will be 1
  193.     movea.l    #named,a3    *if no wildcards
  194.     movea.l    #names,a4
  195.     movea.l    #flags,a5
  196.     move.w    #11,d2
  197. ckwild:    cmpi.b    #'?',(a3)+    *check destination byte for wildcard
  198.     bne    skip
  199.     cmpi.b    #'?',(a4)    *make sure source has matching wildcard
  200.     beq    setflg
  201.     move.l    #illegal,d1    *wildcard mismatch...say so
  202.     jsr    pstring        *and return to CP/M
  203.     jmp    quit
  204. setflg:    move.b    #1,(a5)        *flag the byte
  205.     clr.w    d7        *wildcards => reset d7 to indicate
  206. skip:    adda    #1,a5        *we must search the directory
  207.     adda    #1,a4
  208.     subq    #1,d2
  209.     bne    ckwild
  210.     rts
  211. *
  212. *  Display file name and filetype on the console
  213. *
  214. filnam:    
  215.     move.w    #8,d2        *display file name
  216. more:    move.b    (a0)+,d1
  217.     move.w    #outchar,d0
  218.     trap    #bdos
  219.     subq    #1,d2
  220.     bne    more
  221.     rts
  222. filtyp:    move.b    #'.',d1        *display filetype
  223.     move.w    #outchar,d0
  224.     trap    #bdos
  225.     move.w    #3,d2
  226.     jsr    more        *use code above to avoid redundancy
  227.     rts
  228. *
  229. *  Determine drive number and make it ascii
  230. *
  231. getdrv:
  232.     move.b    (a6),d1        *Get drive number from FCB
  233.     cmpi.b    #0,d1        *Is it the default drive?
  234.     bne    ascii
  235.     jsr    logged        *If so, get physical drive number
  236. ascii:    addi.b    #64,d1        *Make it ascii
  237.     move.b    d1,d3        *and save it in d3
  238.     rts
  239. *
  240. *  Determine which is the logged drive
  241. *
  242. logged:
  243.     move.w    #current,d0    *Get current drive number
  244.     trap    #bdos
  245.     addq.b    #1,d0        *Increment for consistency with getdrv
  246.     move.w    d0,d1        *and save it in d1 for getdrv
  247.     rts
  248. *
  249. *  Copy d2 bytes from a1 to a0
  250. *
  251. movmem:    
  252.     move.b    (a1)+,(a0)+
  253.     subq    #1,d2
  254.     bne    movmem
  255.     rts
  256. *
  257. *  Send a String to the Console
  258. *
  259. pstring:
  260.     move.w    #print,d0
  261.     trap    #bdos
  262.     rts
  263. *
  264. *  Quit to CP/M
  265. *
  266. quit:    
  267.     move.w    #boot,d0
  268.     trap    #bdos
  269. *
  270. *  Setup FCB for rename operation
  271. *
  272. setup:    
  273.     movea.l    #named,a3
  274.     movea.l    #names,a4
  275.     movea.l    #flags,a5
  276.     adda    #1,a0
  277.     move.w    #11,d2
  278. fill:    cmpi.b    #0,(a5)+    *check for wildcard byte
  279.     beq    notset
  280.     move.b    (a0)+,d3    *this is a wildcard byte
  281.     move.b    d3,(a4)+    *fill the source byte
  282.     move.b    d3,(a3)+    *fill the destination byte
  283.     jmp    there
  284. notset:    move.b    (a0)+,(a4)+    *fill the source byte
  285.     adda    #1,a3        *skip the destination byte
  286. there:    subq    #1,d2
  287.     bne    fill
  288.     rts
  289. *#######################################################################
  290. *                 Console Messages
  291. *#######################################################################
  292.     even
  293. fcb:    dc.b    0            *drive specification
  294. names:    dc.b    0,0,0,0,0,0,0,0        *source file name
  295.     dc.b    0,0,0            *source filetype
  296.     dc.b    0,0,0,0            *filler bytes
  297.     dc.b    0            *drive specification
  298. named:    dc.b    0,0,0,0,0,0,0,0        *destination file name
  299.     dc.b    0,0,0            *destination filetype
  300.     dc.b    0,0,0,0,0        *filler bytes
  301.     even
  302. xfcb:   dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  303.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  304.     dc.b    0,0,0,0
  305. exists:    dc.b    lf,cr
  306.     dc.b    'Destination file already exists...RENAME aborted',lf,cr,'$'
  307.     even
  308. illegal:dc.b    lf,cr
  309.     dc.b    'Illegal wildcard specification...RENAME aborted',lf,cr,'$'
  310.     even
  311. arrow:    dc.b    '  -->  $'
  312. crlf:    dc.b    lf,cr,'$'
  313.     even
  314. nofile:    dc.b    lf,cr
  315.     dc.b    'No matching files on this disk',lf,cr,'$'
  316. usage:    dc.b    lf,cr,'Correct usage:    RENAME <d:>oldname newname'
  317.     dc.b    lf,cr
  318.     dc.b    lf,cr,'       ** Wildcards are supported **'
  319.     dc.b    lf,cr,'$'
  320. flags:    dc.b    0,0,0,0,0,0,0,0,0,0,0
  321. *#######################################################################
  322. *                            Storage area
  323. *#######################################################################
  324.     even
  325. bufadr  dc.l    buffer
  326. mydma   dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  327.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  328.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  329.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  330.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  331.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  332.     dc.b    0,0,0,0,0,0,0,0
  333. buffer  dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  334.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  335. *#######################################################################
  336.     end
  337.