home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / DOSDIR.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-05-30  |  5.9 KB  |  293 lines

  1.         page    58,132
  2.  
  3. ; dosdir.asm
  4. ; contains: doschdir(),dosmkdir(),dosrmdir(),dosgetdir(),dosfirst(),
  5. ; contains: dosnext()
  6. ;
  7.  
  8.         include    model.h
  9.         include    prologue.h
  10.         include equ.h
  11.  
  12.         name    dosdir
  13.         dseg    dsdirdat
  14.  
  15. ;==>--    Find first/find next static data area
  16. ;
  17. fffndta    db    21 dup(?)    ;reserved
  18. xattr    db    1 dup(?)    ;attribute byte
  19. xfiltim    dw    1 dup(?)    ;Files time
  20. xfildat    dw    1 dup(?)    ;Files date
  21. xfilsiz    dd    1 dup(?)    ;Files size
  22. xnamext    db    13 dup(?)    ;null terminated name & extension of file name
  23. svdtaof    dw    1 dup(?)    ;saved dta offset
  24. svdtasg    dw    1 dup(?)    ;saved dta segment
  25.  
  26.         endds
  27.  
  28.         pseg    dosdir
  29.  
  30. ;==>--    int doschdir(string)
  31. ;
  32. ;;    ARGUMENTS:
  33. ;      (char *) string    -    Pointer to string with new
  34. ;                    directory name.
  35. ;
  36. ;;    DESCRIPTION:
  37. ;      Change the current directory.
  38. ;
  39. ;;    RETURNS:
  40. ;      0 = success or dos error code
  41. ;
  42. ;;    AUTHOR:
  43. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  44. ;;;
  45.     cproc    doschdir
  46.     if    _LDATA
  47.      push    ds
  48.      lds    dx,parm1_
  49.     else
  50.      mov    dx,parm1_
  51.     endif
  52.     mov    ah,3Bh
  53.     int    21h        ;do the operation
  54.     if    _LDATA
  55.      pop    ds
  56.     endif
  57.     jc    chdxit        ;if error return code
  58.     xor    ax,ax        ;else return success
  59. chdxit:
  60.     cproce
  61.  
  62. ;==>--    int dosmkdir(string)
  63. ;
  64. ;;    ARGUMENTS:
  65. ;      (char *)    string    -    Pointer to string with directory name
  66. ;
  67. ;;    DESCRIPTION:
  68. ;      create directory
  69. ;
  70. ;;    RETURNS:
  71. ;      0 = success or dos error code
  72. ;
  73. ;;    AUTHOR:
  74. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  75. ;;;
  76.     cproc    dosmkdir
  77.     if    _LDATA
  78.      push    ds
  79.      lds    dx,parm1_
  80.     else
  81.      mov    dx,parm1_
  82.     endif
  83.     mov    ah,39h
  84.     int    21h            ;do the operation
  85.     if    _LDATA
  86.      pop    ds
  87.     endif
  88.     jc    mkdxit            ;if error return it
  89.     xor    ax,ax            ;else return 0
  90. mkdxit:
  91.     cproce
  92.  
  93. ;==>--    int dosrmdir(string)
  94. ;
  95. ;;    ARGUMENTS:
  96. ;      (char *)    string    -    pointer to string containing
  97. ;                    directory name
  98. ;
  99. ;;    DESCRIPTION:
  100. ;      remove directory
  101. ;
  102. ;;    RETURNS:
  103. ;      0 if successful, else dos error code
  104. ;
  105. ;;    AUTHOR:
  106. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  107. ;;;
  108.     cproc    dosrmdir
  109.     if    _LDATA
  110.      push    ds
  111.      lds    dx,parm1_
  112.     else
  113.      mov    dx,parm1_
  114.     endif
  115.     mov    ah,3Ah            ;fn to RMDIR
  116.     int    21h            ;do the operation
  117.     if    _LDATA    
  118.      pop    ds
  119.     endif
  120.     jc    rmdxit            ;if error return it
  121.     xor    ax,ax            ;else return 0
  122. rmdxit:
  123.     cproce
  124.  
  125. ;==>--    int dosgetdir(drive,string)
  126. ;
  127. ;;    ARGUMENTS:
  128. ;      (int)        drive    -    drive number 0 == default
  129. ;                             1 == A: etc
  130. ;      (char *)    string    -    pointer to string to receive
  131. ;                    the full path name
  132. ;;    DESCRIPTION:
  133. ;      Get current directory.
  134. ;
  135. ;;    RETURNS:
  136. ;      00=successful, or dos error code
  137. ;
  138. ;;    AUTHOR:
  139. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  140. ;;;
  141.     cproc    dosgetdir,,dosgetdi
  142.     if    _LDATA
  143.      push    ds
  144.      lds    si,parm2_
  145.     else
  146.      mov    si,parm2_
  147.     endif
  148.     mov    dl,parm1_
  149.     mov    ah,47h            ;fn to get dir
  150.     int    21h
  151.     if    _LDATA
  152.      pop    ds
  153.     endif
  154.     jc    dgetxit            ;if error, return code
  155.     xor    ax,ax            ;success return
  156. dgetxit:
  157.     cproce
  158.  
  159. ;==>--    int dosfirst(string,attribute,deststring)
  160. ;
  161. ;;    ARGUMENTS:
  162. ;      (char *)    string        -    string to search for
  163. ;      (int)        attribute    -    attributes used in search
  164. ;      (char *)    deststring    -    string to receive filename
  165. ;
  166. ;;    DESCRIPTION:
  167. ;      Search for first directory entry
  168. ;
  169. ;;    RETURNS:
  170. ;      00=successful or dos error code, 18=no more files
  171. ;
  172. ;;    AUTHOR:
  173. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  174. ;;;
  175.     cproc    dosfirst
  176.     push    es
  177.     call    setdta
  178.     if    _LDATA
  179.      push    ds
  180.      lds    dx,parm1_
  181.      mov    cx,parm3_
  182.     else
  183.      mov    dx,parm1_
  184.      mov    cx,parm2_
  185.     endif
  186.     mov    ah,4eh            ;find first function
  187.     int    21h
  188.     if    _LDATA
  189.      pop    ds            ;restore ds
  190.     endif
  191.     jc    dfstex            ;if error reset dta & return error
  192.     if    _LDATA
  193.      les    di,parm4_        ;point es:di to destination string
  194.     else
  195.      mov    ax,ds
  196.      mov    es,ax
  197.      mov    di,parm3_        ;point es:di to destination string
  198.     endif
  199.     lea    si,xnamext        ;point ds:si to source string
  200.     mov    ax,es            ;check for NULL destination pointer
  201.     or    ax,di
  202.     jz    dfstex            ;if so don't do copy
  203.     call    stgcpy            ;copy ds:si to es:di
  204.     xor    ax,ax            ;return success
  205. dfstex:    pop    es
  206.     call    resdta            ;set dta back where it was
  207.     cproce
  208.  
  209. ;==>--    int dosnext(string,attribute,deststring)
  210. ;
  211. ;;    ARGUMENTS:
  212. ;      (char *)    string        -    string to search for
  213. ;      (int)        attribute    -    attributes used in search
  214. ;      (char *)    deststring    -    string to receive filename
  215. ;
  216. ;;    DESCRIPTION:
  217. ;      Search for next directory entry
  218. ;
  219. ;;    RETURNS:
  220. ;      00=successful or dos error code, 18=no more files
  221. ;
  222. ;;    AUTHOR:
  223. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  224. ;;;
  225.     cproc    dosnext
  226.     push    es
  227.     call    setdta        ;set dta to our data area
  228.     mov    ah,4fh        ;find next function
  229.     int    21h
  230.     jc    dnxtex        ;if error exit with it
  231.     if    _LDATA
  232.      les    di,parm4_    ;point es:di to destination string
  233.     else
  234.      mov    ax,ds
  235.      mov    es,ax
  236.      mov    di,parm3_    ;point es:di to destination string
  237.     endif
  238.     lea    si,xnamext    ;point ds:si to source string
  239.     mov    ax,es        ;check for NULL destination pointer
  240.     or    ax,di
  241.     jz    dnxtex        ;if so don't do copy
  242.     call    stgcpy        ;copy ds:si to es:di
  243.     xor    ax,ax
  244. dnxtex:    call    resdta        ;reset dta to previous setting
  245.     pop    es
  246.     cproce
  247.  
  248. ;==>--    stgcpy    - used by functions in this module only
  249. ;
  250. ;    Copies null terminated string from DS:SI to ES:DI
  251. ;
  252. stgcpy    proc    near
  253.     cld                ;do auto increment
  254. dfslop:    lodsb                ;read ds:si to al & ++si
  255.     stosb                ;store al to es:di & ++di
  256.     or    al,al            ;copy till AFTER null has been copied
  257.     jnz    dfslop
  258.     ret
  259. stgcpy    endp
  260.  
  261. ;==>--    resdta    - used by functions in this module only
  262. ;
  263. ;  restores dta to previous value
  264. ;
  265. resdta    proc    near
  266.     push    ds
  267.     push    ax
  268.     lds    dx,dword ptr svdtaof    ;ds:dx has old value
  269.     mov    ah,1ah
  270.     int    21h
  271.     pop    ax
  272.     pop    ds
  273.     ret
  274. resdta    endp
  275.  
  276. ;==>--    setdta    - used by functions in this module only
  277. ;
  278. ;  get's the current dta and saves it in local variables, then sets
  279. ;  new dta to point to extended fcb
  280. ;
  281. setdta    proc    near
  282.     mov    ah,2fh
  283.     int    21h
  284.     mov    svdtaof,bx    ;save current in variables
  285.     mov    svdtasg,es
  286.     lea    dx,fffndta    ;and point it to our data area
  287.     mov    ah,1ah
  288.     int    21h
  289.     ret
  290. setdta    endp
  291.     endps
  292.     end
  293.