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 / CPM / UTILS / DIRUTL / DUPUSR2.ASM < prev    next >
Assembly Source File  |  2000-06-30  |  7KB  |  272 lines

  1. ;    title    'dupusr - duplicate a directory entry under a new user'
  2. ;    by Bruce R. Ratoff - first version 5/17/80
  3. ;    modified 5/17/80 for wildcard processing
  4. ;    modified 5/18/80 to zero drive number before making file.
  5. ;    modified 5/18/80 to operate from originating user #
  6. ;    modified 6/3/80  to fix problem w/ multi-extent files
  7. ;
  8. ; The purpose of this program is to create extra entries in a CP/M 2.x
  9. ; directory that "point to" files which were actually created in a
  10. ; different directory.  This way, you have access to the file from
  11. ; both user numbers without having to keep multiple copies of the
  12. ; actual file itself.  To create duplicate entries on drive "d" for
  13. ; user "x" from files which currently reside at user "y", type:
  14. ;    A>USER y            ;log in to originating user y
  15. ;    A>DUPUSR d:filename.typ x    ;create files at destination user x
  16. ; Note that this program will totally duplicate the directory entry in
  17. ; all respects (except the user number, of course).  This means that
  18. ; both entries will show the file with the same attributes, such as
  19. ; "read-only" or "system".  The filename.typ may contain "?" and "*".
  20. ;
  21. ; The only known hazard in the use of this program occurs when erasing
  22. ; one of the duplicate entries.  You must type control-c immediately
  23. ; after erasing the entry, so that cp/m is forced to rebuild the allocation
  24. ; vector for that drive.  This is because the erase command frees the
  25. ; blocks shown for the erased file without checking if they are in use
  26. ; elsewhere.  If you didn't type control-c, the next disk write would
  27. ; clobber these blocks, voiding all other pointers to the file.
  28. ; Unfortunately this would only be apparent the next time you tried
  29. ; to read the file from another user number, at which time you would
  30. ; read garbage.
  31. ;
  32. ; Please forward all comments, suggestions and improvements to:
  33. ;    Bruce R. Ratoff
  34. ;    80 Gill Lane, Apt 1B
  35. ;    Iselin, New Jersey 08830
  36. ;
  37. ;
  38. ;
  39. bdos    equ    5        ;cp/m entry point
  40. exit    equ    0        ;cp/m exit point
  41. dfcb    equ    5ch        ;cp/m default fcb
  42. dbuff    equ    80h        ;default disk buffer
  43. ;
  44. pmessg    equ    9        ;print message function
  45. seldsk    equ    14        ;select drive function
  46. open    equ    15        ;open file function
  47. close    equ    16        ;close file function
  48. srchfst    equ    17        ;search for first file match
  49. srchnxt    equ    18        ;search for next file match
  50. delete    equ    19        ;delete file function
  51. make    equ    22        ;make file function
  52. attrib    equ    30        ;set file attributes function
  53. gsuser    equ    32        ;get/set user function
  54. ;
  55. ;
  56.     org    100h
  57. begin:
  58.     lhld    bdos+1        ;set up a stack
  59.     sphl            ;at top of tpa
  60.     mvi    c,gsuser    ;get our user #
  61.     mvi    e,0ffh
  62.     call    bdos
  63.     sta    ourusr        ;save for later
  64.     lda    dfcb        ;check for specific drive
  65.     dcr    a
  66.     mov    e,a        ;set up for select disk call
  67.     mvi    c,seldsk
  68.     inr    a        ;if no specified drive, skip call
  69.     cnz    bdos
  70.     sub    a        ;now zap out drive spec
  71.     sta    dfcb
  72.     mvi    a,'?'        ;force extent number wild
  73.     sta    dfcb+12
  74.     lxi    h,dfcb+17    ;point to originating user # in cmd line
  75.     mvi    e,0
  76. numlup:
  77.     mov    a,m        ;get numeric (i hope) character
  78.     inx    h        ;bump char pointer
  79.     sui    '0'        ;remove ascii bias
  80.     jc    numdone
  81.     cpi    10        ;check if past 9
  82.     jnc    numdone        ;any invalid char ends number
  83.     mov    d,a
  84.     mov    a,e        ;get accumulated number
  85.     add    a        ;times two
  86.     add    a        ;times four
  87.     add    e        ;times five
  88.     add    a        ;times ten
  89.     add    d        ;plus new digit
  90.     mov    e,a        ;save accumulation
  91.     jmp    numlup        ;loop back for next char
  92. numdone:
  93.     lda    ourusr        ;make sure not same as us
  94.     cmp    e
  95.     jz    badusr
  96.     mov    a,e        ;get destination user number
  97.     sta    dstusr        ;save it
  98.     cpi    16        ;legal?
  99.     jc    userok
  100. badusr:
  101.     lxi    d,ilgusr
  102.     mvi    c,pmessg    ;bitch about illegal user #
  103.     call    bdos
  104.     jmp    exit
  105. ilgusr:
  106.     db    'Invalid destination user #$'
  107. userok:
  108.     sub    a        ;zero out file count
  109.     sta    filcnt
  110.     lxi    d,dfcb        ;find the first file and get its block map
  111.     mvi    c,srchfst
  112.     call    bdos
  113.     inr    a        ;search successful?
  114.     jnz    gotfile        ;yes, go process rest
  115.     lxi    d,nofile
  116.     mvi    c,pmessg    ;say "no file"
  117.     call    bdos
  118.     jmp    exit
  119. nofile:
  120.     db    'Originating file not found$'
  121. gotfile:
  122.     dcr    a        ;compensate for inr above
  123.     rrc            ;file offset to bits 5 and 6
  124.     rrc
  125.     rrc
  126.     ani    60h
  127.     lxi    h,dbuff        ;point to base of buffer
  128.     mov    c,a
  129.     mvi    b,0
  130.     dad    b        ;index by file offset
  131.     push    h        ;save for the moment
  132.     lxi    b,filetable
  133.     call    filepoint    ;get table pointer to hl
  134.     xchg            ;de now points to place in table
  135.     lda    filcnt
  136.     inr    a
  137.     sta    filcnt        ;bump file count
  138.     pop    h        ;hl points to directory entry
  139.     mvi    b,32
  140.     call    blkmov        ;copy entry into table
  141.     mvi    c,srchnxt    ;search for another entry
  142.     lxi    d,dfcb
  143.     call    bdos
  144.     inr    a        ;returns 0ffh at end of search
  145.     jnz    gotfile        ;got another one...go save it
  146. ;
  147. ; end of directory encountered, now process them
  148. ;
  149.     lda    dstusr        ;set to dest user
  150.     mov    e,a
  151.     mvi    c,gsuser
  152.     call    bdos
  153. ;
  154. ; main loop to set up one duplicate entry
  155. ;
  156. makefile:
  157.     lxi    b,filetable-32    ;allow for filcnt one greater than desired
  158.     call    filepoint
  159.     push    h        ;save pointer
  160.     lxi    d,dfcb        ;copy next name to default fcb
  161.     mvi    b,32
  162.     call    blkmov
  163.     sub    a
  164.     sta    dfcb        ;clear drive number
  165.     lxi    d,-20        ;point back to extent field
  166.     dad    d
  167.     mvi    m,'$'        ;tag end of print here
  168.     pop    d        ;get back pointer to start of entry
  169.     inx    d        ;bump fwd to name
  170.     mvi    c,pmessg
  171.     call    bdos        ;say what we're working on
  172.     lxi    h,dfcb
  173.     lxi    d,ourfcb    ;copy name data to work fcb
  174.     mvi    b,14
  175.     call    blkmov
  176.     lxi    h,0
  177.     shld    ourfcb+14    ;zap frebyt, extlen
  178.     lda    ourfcb+9
  179.     ani    7fh        ;clear r/o flag for create
  180.     sta    ourfcb+9
  181.     sub    a
  182.     sta    ourfcb        ;clear drive number
  183.     lxi    d,ourfcb
  184.     mvi    c,open
  185.     call    bdos        ;check for existing file of same name
  186.     inr    a
  187.     jnz    makeok        ;skip create if already there
  188.     lxi    d,ourfcb
  189.     mvi    c,make        ;create the file
  190.     call    bdos
  191.     inr    a        ;check for errors
  192.     jnz    makeok
  193.     lxi    d,makerr
  194.     mvi    c,pmessg    ;say can't make file
  195.     call    bdos
  196.     jmp    exit
  197. makerr:
  198.     db    ', Cannot create file$'
  199. makeok:
  200.     lxi    h,dfcb+12    ;copy bookkeeping stuff from orig file
  201.     lxi    d,ourfcb+12
  202.     mvi    b,20
  203.     call    blkmov
  204.     lda    ourfcb+14    ;set update flag so that altered fcb
  205.     ani    1fh        ;gets written by close function
  206.     sta    ourfcb+14    ;(retain module # in low 5 bits)
  207.     lxi    d,ourfcb
  208.     mvi    c,close        ;do a close to set size and block map
  209.     call    bdos
  210.     inr    a
  211.     jnz    closok        ;check for errors
  212.     lxi    d,closerr
  213.     mvi    c,pmessg
  214.     call    bdos        ;say close error
  215.     jmp    exit
  216. closerr:
  217.     db    ', Cannot close file$'
  218. closok:
  219.     lda    dfcb+9        ;was original file r/o?
  220.     ora    a        ;set sign bit if yes
  221.     jp    nextfile    ;done if no
  222.     sta    ourfcb+9    ;make our new file r/o to match
  223.     lxi    d,ourfcb
  224.     mvi    c,attrib    ;do set attributes call
  225.     call    bdos
  226. nextfile:
  227.     lxi    h,filcnt    ;point to file counter
  228.     dcr    m        ;count it down
  229.     jz    exit        ;exit if done
  230.     lxi    d,crlf
  231.     mvi    c,pmessg    ;else do a crlf
  232.     call    bdos
  233.     jmp    makefile    ;and go work on next one
  234. crlf:
  235.     db    13,10,'$'
  236. ;
  237. ;
  238. ; subroutine to do block moves
  239. blkmov:
  240.     mov    a,m        ;copy byte from m(hl) to m(de)
  241.     stax    d
  242.     inx    h        ;bump pointers
  243.     inx    d
  244.     dcr    b        ;loop for count in b
  245.     jnz    blkmov
  246.     ret
  247. ;
  248. ;
  249. ; subroutine to index bc by file counter
  250. filepoint:
  251.     lhld    filcnt        ;get file counter
  252.     mvi    h,0        ;force hi ord to 0
  253.     dad    h        ;multiply by 32
  254.     dad    h
  255.     dad    h
  256.     dad    h
  257.     dad    h
  258.     dad    b        ;use as index to file table
  259.     ret
  260. ;
  261. ;
  262. ;
  263. ;
  264. filcnt:    ds    1        ;count of files in filetable
  265. ourusr:    ds    1        ;storage for our user number
  266. dstusr:    ds    1        ;storage for destination user number
  267. ourfcb:    ds    32        ;file control block for create function
  268. ;
  269. filetable    equ    $    ;start table here, take all avail memory
  270. ;
  271.     end
  272.