home *** CD-ROM | disk | FTP | other *** search
- page 58,132
-
- ; dosdir.asm
- ; contains: doschdir(),dosmkdir(),dosrmdir(),dosgetdir(),dosfirst(),
- ; contains: dosnext()
- ;
-
- include model.h
- include prologue.h
- include equ.h
-
- name dosdir
- dseg dsdirdat
-
- ;==>-- Find first/find next static data area
- ;
- fffndta db 21 dup(?) ;reserved
- xattr db 1 dup(?) ;attribute byte
- xfiltim dw 1 dup(?) ;Files time
- xfildat dw 1 dup(?) ;Files date
- xfilsiz dd 1 dup(?) ;Files size
- xnamext db 13 dup(?) ;null terminated name & extension of file name
- svdtaof dw 1 dup(?) ;saved dta offset
- svdtasg dw 1 dup(?) ;saved dta segment
-
- endds
-
- pseg dosdir
-
- ;==>-- int doschdir(string)
- ;
- ;; ARGUMENTS:
- ; (char *) string - Pointer to string with new
- ; directory name.
- ;
- ;; DESCRIPTION:
- ; Change the current directory.
- ;
- ;; RETURNS:
- ; 0 = success or dos error code
- ;
- ;; AUTHOR:
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;;;
- cproc doschdir
- if _LDATA
- push ds
- lds dx,parm1_
- else
- mov dx,parm1_
- endif
- mov ah,3Bh
- int 21h ;do the operation
- if _LDATA
- pop ds
- endif
- jc chdxit ;if error return code
- xor ax,ax ;else return success
- chdxit:
- cproce
-
- ;==>-- int dosmkdir(string)
- ;
- ;; ARGUMENTS:
- ; (char *) string - Pointer to string with directory name
- ;
- ;; DESCRIPTION:
- ; create directory
- ;
- ;; RETURNS:
- ; 0 = success or dos error code
- ;
- ;; AUTHOR:
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;;;
- cproc dosmkdir
- if _LDATA
- push ds
- lds dx,parm1_
- else
- mov dx,parm1_
- endif
- mov ah,39h
- int 21h ;do the operation
- if _LDATA
- pop ds
- endif
- jc mkdxit ;if error return it
- xor ax,ax ;else return 0
- mkdxit:
- cproce
-
- ;==>-- int dosrmdir(string)
- ;
- ;; ARGUMENTS:
- ; (char *) string - pointer to string containing
- ; directory name
- ;
- ;; DESCRIPTION:
- ; remove directory
- ;
- ;; RETURNS:
- ; 0 if successful, else dos error code
- ;
- ;; AUTHOR:
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;;;
- cproc dosrmdir
- if _LDATA
- push ds
- lds dx,parm1_
- else
- mov dx,parm1_
- endif
- mov ah,3Ah ;fn to RMDIR
- int 21h ;do the operation
- if _LDATA
- pop ds
- endif
- jc rmdxit ;if error return it
- xor ax,ax ;else return 0
- rmdxit:
- cproce
-
- ;==>-- int dosgetdir(drive,string)
- ;
- ;; ARGUMENTS:
- ; (int) drive - drive number 0 == default
- ; 1 == A: etc
- ; (char *) string - pointer to string to receive
- ; the full path name
- ;; DESCRIPTION:
- ; Get current directory.
- ;
- ;; RETURNS:
- ; 00=successful, or dos error code
- ;
- ;; AUTHOR:
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;;;
- cproc dosgetdir,,dosgetdi
- if _LDATA
- push ds
- lds si,parm2_
- else
- mov si,parm2_
- endif
- mov dl,parm1_
- mov ah,47h ;fn to get dir
- int 21h
- if _LDATA
- pop ds
- endif
- jc dgetxit ;if error, return code
- xor ax,ax ;success return
- dgetxit:
- cproce
-
- ;==>-- int dosfirst(string,attribute,deststring)
- ;
- ;; ARGUMENTS:
- ; (char *) string - string to search for
- ; (int) attribute - attributes used in search
- ; (char *) deststring - string to receive filename
- ;
- ;; DESCRIPTION:
- ; Search for first directory entry
- ;
- ;; RETURNS:
- ; 00=successful or dos error code, 18=no more files
- ;
- ;; AUTHOR:
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;;;
- cproc dosfirst
- push es
- call setdta
- if _LDATA
- push ds
- lds dx,parm1_
- mov cx,parm3_
- else
- mov dx,parm1_
- mov cx,parm2_
- endif
- mov ah,4eh ;find first function
- int 21h
- if _LDATA
- pop ds ;restore ds
- endif
- jc dfstex ;if error reset dta & return error
- if _LDATA
- les di,parm4_ ;point es:di to destination string
- else
- mov ax,ds
- mov es,ax
- mov di,parm3_ ;point es:di to destination string
- endif
- lea si,xnamext ;point ds:si to source string
- mov ax,es ;check for NULL destination pointer
- or ax,di
- jz dfstex ;if so don't do copy
- call stgcpy ;copy ds:si to es:di
- xor ax,ax ;return success
- dfstex: pop es
- call resdta ;set dta back where it was
- cproce
-
- ;==>-- int dosnext(string,attribute,deststring)
- ;
- ;; ARGUMENTS:
- ; (char *) string - string to search for
- ; (int) attribute - attributes used in search
- ; (char *) deststring - string to receive filename
- ;
- ;; DESCRIPTION:
- ; Search for next directory entry
- ;
- ;; RETURNS:
- ; 00=successful or dos error code, 18=no more files
- ;
- ;; AUTHOR:
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;;;
- cproc dosnext
- push es
- call setdta ;set dta to our data area
- mov ah,4fh ;find next function
- int 21h
- jc dnxtex ;if error exit with it
- if _LDATA
- les di,parm4_ ;point es:di to destination string
- else
- mov ax,ds
- mov es,ax
- mov di,parm3_ ;point es:di to destination string
- endif
- lea si,xnamext ;point ds:si to source string
- mov ax,es ;check for NULL destination pointer
- or ax,di
- jz dnxtex ;if so don't do copy
- call stgcpy ;copy ds:si to es:di
- xor ax,ax
- dnxtex: call resdta ;reset dta to previous setting
- pop es
- cproce
-
- ;==>-- stgcpy - used by functions in this module only
- ;
- ; Copies null terminated string from DS:SI to ES:DI
- ;
- stgcpy proc near
- cld ;do auto increment
- dfslop: lodsb ;read ds:si to al & ++si
- stosb ;store al to es:di & ++di
- or al,al ;copy till AFTER null has been copied
- jnz dfslop
- ret
- stgcpy endp
-
- ;==>-- resdta - used by functions in this module only
- ;
- ; restores dta to previous value
- ;
- resdta proc near
- push ds
- push ax
- lds dx,dword ptr svdtaof ;ds:dx has old value
- mov ah,1ah
- int 21h
- pop ax
- pop ds
- ret
- resdta endp
-
- ;==>-- setdta - used by functions in this module only
- ;
- ; get's the current dta and saves it in local variables, then sets
- ; new dta to point to extended fcb
- ;
- setdta proc near
- mov ah,2fh
- int 21h
- mov svdtaof,bx ;save current in variables
- mov svdtasg,es
- lea dx,fffndta ;and point it to our data area
- mov ah,1ah
- int 21h
- ret
- setdta endp
- endps
- end
-