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 / DOSSRCH.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-05-30  |  5.5 KB  |  233 lines

  1.         page    58,132
  2.  
  3. ; dossrch.asm
  4. ; contains:   dossrch()
  5. ;
  6.  
  7.         include    model.h
  8.         include    prologue.h
  9.         include equ.h
  10.         name    dossrch
  11.         dseg    dossearch
  12.  
  13. ;==>--    dossrch() static data area
  14. ;
  15. fffndta    db    21 dup(?)    ;reserved
  16. xattr    db    1 dup(?)    ;attribute byte
  17. xfiltim    dw    1 dup(?)    ;Files time
  18. xfildat    dw    1 dup(?)    ;Files date
  19. xfilsiz    dd    1 dup(?)    ;Files size
  20. xnamext    db    13 dup(?)    ;null terminated name & extension of file name
  21. svdtaof    dw    1 dup(?)    ;saved dta offset
  22. svdtasg    dw    1 dup(?)    ;saved dta segment
  23.  
  24.         endds
  25.  
  26.         pseg    dossearch
  27.  
  28. ;==>--    int dossrch(searchname,searchattribute,filename,filetimedate,
  29. ;        filesize,fileattr)
  30. ;
  31. ;;    ARGUMENTS:
  32. ;      (char *)    searchname    -    points to string to do find
  33. ;                        first for, if NULL does find
  34. ;                        next.
  35. ;      (int)        searchattribute -    attribute to use for when
  36. ;                        searching
  37. ;      (char *)    filename    -    pointer to string to receive
  38. ;                        filename
  39. ;      (struct TIMEDATE *) filetimedate -    pointer to TIMEDATE structure
  40. ;                        that receives files time/date
  41. ;                        information.
  42. ;      (long *)    filesize    -    pointer to long that receives
  43. ;                        files size
  44. ;      (unsigned *)    fileattr    -    pointer to unsigned (16bit)
  45. ;                        value that receives files
  46. ;                        attribute.
  47. ;      Note: filename or filetimedate or filesize or fileattr can be
  48. ;      NULL pointers if you do not want any of the information returned.
  49. ;
  50. ;;    DESCRIPTION:
  51. ;      This function does search first/search next returning information
  52. ;      via pointers passed to the function as parameters.
  53. ;
  54. ;;    RETURNS:
  55. ;      00 if successful or dos error code.      
  56. ;
  57. ;;    AUTHOR:
  58. ;     ""   27-MAR-1987  16:21:33.38
  59. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  60. ;;;
  61.     cproc    dossrch
  62.     push    es
  63.     mov    ah,2fh
  64.     int    21h
  65.     mov    svdtaof,bx    ;save current in variables
  66.     mov    svdtasg,es
  67.     lea    dx,fffndta    ;and point it to our data area
  68.     mov    ah,1ah
  69.     int    21h
  70.     if    _LDATA
  71.      push    ds
  72.      lds    dx,dword ptr @ab[bp]
  73.      mov    cx,@ab+4[bp]
  74.      mov    ax,ds        ;check for null
  75.      or    ax,dx
  76.      mov    ah,4fh        ;assume find next needed
  77.      jz    donext        ;check assumption
  78.      dec    ah        ;else do find first (4E)
  79. donext:     int    21h
  80.      pop    ds        ;restore ds
  81.      jnc    srok
  82.      jmp    srchex        ;if error leave with it
  83. srok:     cld
  84.      les    di,dword ptr @ab+6[bp]    ;see if he wants file name
  85.      mov    ax,es
  86.      or    ax,di        ;if == NULL, skip output
  87.      jz    ckftim        ;and check file time
  88.      lea    si,xnamext    ;si=source
  89.      cld            ;do auto increment
  90. dfslop:     lodsb            ;read ds:si to al & ++si
  91.      stosb            ;store al to es:di & ++di
  92.      or    al,al        ;copy till AFTER null has been copied
  93.      jnz    dfslop
  94. ckftim:     les    di,dword ptr @ab+0ah[bp]    ;see if he wants time/date
  95.      mov    ax,es
  96.      or    ax,di        ;if==NULL, skip output
  97.      jz    ckfsiz        ;and check file date
  98.      mov    ax,xfildat    ;date to ax
  99.      mov    bx,ax        ;save here
  100.      mov    cl,9        ;shift to year
  101.      shr    ax,cl
  102.      and    ax,7fh        ;mask all but year
  103.      add    ax,1980        ;adjust year
  104.      stosw            ;and save in structure
  105.      mov    ax,bx        ;refresh
  106.      mov    cl,5
  107.      shr    ax,cl
  108.      and    ax,0fh
  109.      stosw
  110.      mov    ax,bx        ;now do day
  111.      and    ax,1fh
  112.      stosw
  113.      mov    ax,xfiltim    ;get time
  114.      mov    cl,11
  115.      mov    bx,ax
  116.      shr    ax,cl
  117.      and    ax,1fh
  118.      stosw            ;save hours
  119.      mov    ax,bx
  120.      mov    cl,5
  121.      shr    ax,cl        ;shift down minutes
  122.      and    ax,3fh
  123.      stosw            ;save minutes
  124.      mov    ax,bx
  125.      and    ax,1fh
  126.      shl    ax,1        ;*2
  127.      stosw            ;save seconds
  128.      xor    ax,ax        ;save hundredths = 0
  129.      stosw
  130. ckfsiz:     les    di,dword ptr @ab+0eh[bp]    ;see if he wants size
  131.      mov    ax,es
  132.      or    ax,di        ;if==NULL, skip output
  133.      jz    ckfatr        ;and check file attribute
  134.      lea    si,xfilsiz
  135.      lodsw
  136.      stosw
  137.      lodsw
  138.      stosw
  139. ckfatr:     les    di,dword ptr @ab+12h[bp]    ;see if he wants attribute
  140.      mov    ax,es
  141.      or    ax,di        ;if==NULL, skip output
  142.      jz    srchex        ;and exit
  143.      mov    al,xattr
  144.      xor    ah,ah
  145.      stosw
  146.  
  147.     else
  148.  
  149.      mov    dx,@ab[bp]
  150.      mov    cx,@ab+2[bp]
  151.      or    dx,dx        ;check for null
  152.      mov    ah,4fh        ;assume find next needed
  153.      jz    donext        ;check assumption
  154.      dec    ah        ;else do find first (4E)
  155. donext:     int    21h
  156.      jnc    srok
  157.      jmp    srchex        ;if error leave with it
  158. srok:     cld
  159.      mov    ax,ds
  160.      mov    es,ax        ;es=ds
  161.      mov    di,@ab+4[bp]    ;see if he wants file name
  162.      or    di,di        ;if == NULL, skip output
  163.      jz    ckftim        ;and check file time
  164.      lea    si,xnamext    ;si=source
  165.      cld            ;do auto increment
  166. dfslop:     lodsb            ;read ds:si to al & ++si
  167.      stosb            ;store al to es:di & ++di
  168.      or    al,al        ;copy till AFTER null has been copied
  169.      jnz    dfslop
  170. ckftim:     mov    di,@ab+6[bp]    ;see if he wants time/date
  171.      or    di,di        ;if==NULL, skip output
  172.      jz    ckfsiz        ;and check file size
  173.      mov    ax,xfildat    ;date to ax
  174.      mov    bx,ax        ;save here
  175.      mov    cl,9        ;shift to year
  176.      shr    ax,cl
  177.      and    ax,7fh        ;mask all but year
  178.      add    ax,1980        ;adjust year
  179.      stosw            ;and save in structure
  180.      mov    ax,bx        ;refresh
  181.      mov    cl,5
  182.      shr    ax,cl
  183.      and    ax,0fh
  184.      stosw
  185.      mov    ax,bx        ;now do day
  186.      and    ax,1fh
  187.      stosw
  188.      mov    ax,xfiltim    ;get time
  189.      mov    cl,11
  190.      mov    bx,ax
  191.      shr    ax,cl
  192.      and    ax,1fh
  193.      stosw            ;save hours
  194.      mov    ax,bx
  195.      mov    cl,5
  196.      shr    ax,cl        ;shift down minutes
  197.      and    ax,3fh
  198.      stosw            ;save minutes
  199.      mov    ax,bx
  200.      and    ax,1fh
  201.      shl    ax,1        ;*2
  202.      stosw            ;save seconds
  203.      xor    ax,ax        ;save hundredths = 0
  204.      stosw
  205. ckfsiz:     mov    di,@ab+08h[bp]    ;see if he wants size
  206.      or    di,di        ;if==NULL, skip output
  207.      jz    ckfatr        ;and check file attribute
  208.      lea    si,xfilsiz
  209.      lodsw
  210.      stosw
  211.      lodsw
  212.      stosw
  213. ckfatr:     mov    di,@ab+0ah[bp]    ;see if he wants attribute
  214.      or    di,di        ;if==NULL, skip output
  215.      mov    ax,0
  216.      jz    srchex        ;and exit
  217.      mov    al,xattr
  218.      xor    ah,ah
  219.      stosw
  220.     endif
  221.     xor    ax,ax
  222. srchex:    push    ds
  223.     push    ax
  224.     lds    dx,dword ptr svdtaof    ;ds:dx has old value
  225.     mov    ah,1ah
  226.     int    21h
  227.     pop    ax
  228.     pop    ds
  229.     pop    es
  230.     cproce
  231.     endps
  232.     end
  233.