home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / tnylib.lzh / FINFO.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-12-02  |  2.5 KB  |  168 lines

  1. include compiler.inc
  2.  
  3.     ttl    FINFO, 1.01, 8-22-86, clr
  4.  
  5. ; multiple entry point --
  6. ;    fstat(filename,&s_stat) -- return structure as defined in stat.h
  7. ;    fsize(filename) - file size in bytes
  8. ;    fdate(filename) - file date in 2 bytes (encoded)
  9. ;    ftime(filename) - file time in 2 bytes (encoded)
  10. ;        jim --     we probably should also write a function
  11. ;            to convert from packed format to normal format
  12. ;
  13. ;    findfirst(pathname,filename,attribute) - find first matching file
  14. ;    findnext(filename) - find next matching file
  15. ;
  16. ;    these functions use DOS Functions 4E and 4F
  17. ;
  18. ;
  19.  
  20.     dseg
  21.     exterr
  22.  
  23.     dtaptr    equ    this byte
  24.     rsvd    db    21 dup(0)
  25.     attrf    db    0
  26.     timef    dw    0
  27.     datef    dw    0
  28.     sizef    dd    0
  29.     namef    db    13 dup(0)
  30.  
  31.     cseg
  32.     flag    db    0
  33.  
  34. ;    flag value is:    0 for file size
  35. ;            1 for file time
  36. ;            2 for file date
  37.  
  38.     procdef fstat <<filename,ptr>,<status,ptr>>
  39.     mov    flag,3
  40.     jmp    finfo
  41.  
  42.     entrdef fsize
  43.     mov    flag,0
  44.     jmp    finfo
  45.  
  46.     entrdef    ftime
  47.     mov    flag,1
  48.     jmp    finfo
  49.  
  50.     entrdef    fdate
  51.     mov    flag,2
  52.  
  53. finfo:
  54.     pushds
  55.     call    setdta        ;local procedure
  56.     push    ds
  57.     ldptr    dx,filename,ds
  58.     xor    cx,cx
  59.     call    dofirst
  60.     pop    ds
  61.     or    ax,ax
  62.     jnz    errexit
  63.     mov    al,flag
  64.     caseb    0,siz
  65.     caseb    1,tim
  66.     caseb    2,dat
  67. stat:
  68.     push    es
  69.     push    bx
  70.     ldptr    bx,status,es
  71.     mov    al,byte ptr attrf
  72.     mov    es:[bx],al
  73.     mov    ax,word ptr timef
  74.     mov    es:[bx+1],ax
  75.     mov    ax,word ptr datef
  76.     mov    es:[bx+3],ax
  77.     mov    ax,word ptr sizef
  78.     mov    es:[bx+5],ax
  79.     mov    ax,word ptr sizef+2
  80.     mov    es:[bx+7],ax
  81.     pop    bx
  82.     pop    es
  83.     xor    ax,ax
  84.     jmp    exit
  85.  
  86. dat:
  87.     mov    ax,word ptr datef
  88.     xor    dx,dx
  89.     jmp    exit
  90. tim:
  91.     mov    ax,word ptr timef
  92.     xor    dx,dx
  93.     jmp    exit
  94. siz:
  95.     mov    ax,word ptr sizef
  96.     mov    dx,word ptr sizef+2
  97.     jmp    exit
  98.  
  99. errexit:
  100.     mov    ax,-1
  101. exit:
  102.     pret
  103.     pend    fstat
  104.  
  105.     internal setdta
  106.  
  107.     mov    dx,offset dtaptr
  108.     mov    ax,1a00h
  109.     int    21h
  110.     ret
  111.     iend    setdta
  112.  
  113.     internal dofirst
  114.  
  115.     mov    ax,4e00h
  116.     int    21h
  117.     moverr    ax
  118.     ret
  119.     iend    dofirst
  120.  
  121.  
  122. ;    at least 13 bytes must be allocated to fname -- value not checked!
  123.  
  124.     procdef findfirst <<pname,ptr>,<fname,ptr>,<attr,word>>
  125.     pushreg
  126.     pushds
  127.  
  128.     call    setdta
  129.     ldptr    dx,pname,ds
  130.     mov    cx,attr
  131.     call    dofirst
  132.     or    ax,ax
  133.     jnz    errout
  134.     mov    si,offset namef
  135.     ldptr    di,fname
  136.     mov    cx,0dh
  137.     rep movsb
  138.     jmp    out1
  139.  
  140. errout:
  141.     mov    ax,-1
  142. out1:
  143.     pret
  144.     pend    findfirst
  145.  
  146.     procdef findnext <<retname,ptr>>
  147.     pushreg
  148.     pushds
  149.  
  150.     mov    ax,4f00h
  151.     int    21h
  152.     or    ax,ax
  153.     jnz    err
  154.  
  155.     mov    si,offset namef
  156.     ldptr    di,retname
  157.     mov    cx,0dh
  158.     rep movsb
  159.     jmp    ok
  160.  
  161. err:
  162.     moverr    ax
  163.     mov    ax,-1
  164. ok:
  165.     pret
  166.     pend    findnext
  167.  
  168.     finish