home *** CD-ROM | disk | FTP | other *** search
/ Frostbyte's 1980s DOS Shareware Collection / floppyshareware.zip / floppyshareware / USCX / DOSUT-17.ZIP / SIZER.ASM < prev    next >
Assembly Source File  |  1983-12-13  |  10KB  |  246 lines

  1.  
  2.        page    64,132
  3.        title   SIZER - test the size of a file for PASCAL batch files
  4.        subttl  by Tony Alan Rhea 11/14/83
  5. ;
  6. ;
  7. comment *
  8.  
  9.        This program tests the size of a file and sets an errorlevel
  10.        based on it's findings.  Currently, it is set up for the file
  11.        ERRLOG and expects it to be 115 bytes long.  If it does not find
  12.        the file or it is not 115 bytes big, an errorlevel 1 is returned
  13.        (the file is assumed to be in the current working directory).
  14.        Otherwise, errorlevel 0 is returned.  This program requires DOS
  15.        2.0.
  16.  
  17.        This program is currently set up for the PASCAL compiler.  If PAS1
  18.        goes OK, the following output is generated:
  19.  
  20.          IBM Personal Computer Pascal Compiler
  21.          Version 1.00 (C)Copyright IBM Corp 1981
  22.           Pass One    No Errors Detected.
  23.  
  24.        which is exactly 115 bytes big when redirected to a disk file.  To use
  25.        this program with the other compilers/assemblers, follow these steps.
  26.           1. Run the compiler/assembler on a known good program and redirect
  27.              the output to the disk file ERRLOG.
  28.           2. Do a "DIR ERRLOG" and look at the size of the file.
  29.           3. Put the file size in the EQUATE section below in SIZELO (SIZEHI
  30.              should always be zero unless your compiler generates more than
  31.              64k of messages!).
  32.           4. If you like, change the FILENAME DB statement near the end of
  33.              this program to a filename of your liking.
  34.           5. Assemble and link as follows:
  35.                 MASM SIZER,,;
  36.                 LINK SIZER;                   (Ignore "NO STACK" message)
  37.                 EXE2BIN SIZER.EXE SIZER.COM
  38.           6. Have fun!
  39.  
  40.        One note for you PASCAL fans: PAS2 does not like to have his output
  41.        redirected -- it hangs the system.  I haven't investigated it so I
  42.        don't know the reason why.  If someone figures out why, please pass
  43.        it along.
  44.  
  45.        Usage:
  46.              echo off
  47.              cls
  48.              echo Compiling %1 .....
  49.              pas1 %1,,; > errlog
  50.              SIZER
  51.              if errorlevel 1 goto error
  52.              echo PAS1 ok.  Starting PAS2....
  53.              pas2
  54.              goto end
  55.              :error
  56.              edit %1.pas
  57.              :end
  58.              echo on
  59.  
  60.        Copyright (C) 1983  Tony Alan Rhea
  61.        This program may be copied and distributed for personal use
  62.        but not for profit provided this notice is included.  Author makes
  63.        no warranty, expressed or implied, as to the correct nature and
  64.        operation of this software.
  65.  
  66.  
  67.        You may make and distribute as many copies of this program as you wish
  68.        for your PERSONAL use only ( NOT for business purposes, please! ).
  69.        Feel free to modify, mutilate, or adulterate this program.  If you come
  70.        up with an bug or improvement, please let me know by writing me at this
  71.        address:
  72.                Tony A. Rhea
  73.                1030 Ivy Lane
  74.                Cary, NC  27511
  75.        If you do modify it, please give me credit in the program.  This helps
  76.        to preserve my ego and increase my fame (but, unfortunately, NOT my
  77.        financial status).  Also, I would appreciate a copy of the modified
  78.        version, preferably on disk (I'll be happy to return your diskette).
  79.  
  80.        If you like this program ( or HATE it ), please let me know.  Drop me
  81.        a line at the address given above.
  82.  
  83.        This program has been submitted for publication in PC-WORLD magazine.
  84.  
  85.  
  86.          Revision history:
  87.             rev 1.0  11/14/83                         { original release }
  88.  
  89.  
  90.        *
  91. ;
  92. ;
  93. ; Equates
  94. ;
  95. ;
  96. one    equ     '1'
  97. zero   equ     '0'
  98. cr     equ     0dh
  99. lf     equ     0ah
  100. dollar equ     '$'
  101. sizelo equ    115d             ;expected file size in bytes -- low portion
  102. sizehi equ    0                ;expected file size in bytes -- hi  portion
  103.        page
  104. ;
  105. ;
  106. ; Program entry point
  107. ;
  108. ;
  109. cseg   segment para 'code'
  110.        assume  cs:cseg, ds:cseg, ss:nothing, es:cseg
  111.        org     100h            ;for .COM file
  112. entry  proc    near
  113.        mov     ah,30h          ;set function code -- get DOS version number
  114.        int     21h             ;and request DOS service
  115.        cmp     al,0            ;is it pre-DOS 2.0?
  116.        jne     entry10         ;if not, continue
  117.        jmp     dosexit         ;else tell user & quit
  118. ;
  119. ;
  120. ; At this point we have DOS 2.0 or better.  Try to open the file.
  121. ;
  122. ;
  123. entry10 label  near
  124.        push    cs              ;save CS and
  125.        pop     ds              ;get into DS for addressability
  126.        lea     dx,filename     ;point DS:DX to filename
  127.        mov     ax,3d00h        ;function = open file for read-only
  128.        int     21h             ;request DOS service
  129.        jnc     entry20         ;if no carry flag, continue
  130.        jmp     fileerror10     ;else cannot open file -- error ID in AX
  131. ;
  132. ;
  133. ; At this point we have opened the file.  Now let's get it's size.
  134. ; The file handle is in AX.
  135. ;
  136. ;
  137. entry20 label  near
  138.        mov     bx,ax           ;put file handle in BX
  139.        mov     ax,4202h        ;function code -- LSEEK to EOF
  140.        xor     cx,cx           ;set CX and
  141.        xor     dx,dx           ;DX to zero -- no offset desired
  142.        int     21h             ;request DOS service
  143.        jnc     entry30         ;if no carry flag then continue
  144.        jmp     fileerror10     ;else access error -- ID in AX, handle in BX
  145. ;
  146. ;
  147. ; Now the read/write pointer is at the end-of-file.  DX:AX contains the
  148. ; new location of the pointer (DX contains the most significant part).
  149. ;
  150. ;
  151. entry30 label  near
  152.        cmp     dx,sizehi       ;is high portion of file size same?
  153.        je      entry40         ;if so, continue
  154.        jmp     sizediff        ;else file is a different size
  155. entry40 label  near
  156.        cmp     ax,sizelo       ;is low portion of file size same?
  157.        je      entry50         ;if so, continue
  158.        jmp     sizediff        ;else file is a different size
  159.        page
  160. ;
  161. ;
  162. ; At this point we have determined that the file exists and is the desired
  163. ; size.  Set errorlevel 0 and exit, closing the file.
  164. ;
  165. ;
  166. entry50 label  near
  167.        mov     ah,3eh          ;set function code = close file -- handle in BX
  168.        int     21h             ;request DOS service
  169.        jnc     entry60         ;if no carry flag, continue
  170.        jmp     fileerror       ;else error closing file
  171. entry60 label  near
  172.        mov     ax,4c00h        ;set DOS function -- terminate with errorlevel 0
  173.        int     21h             ;and request DOS service -- end of program
  174. ;
  175. ;
  176. ; If we get here we don't have DOS 2.0.  Tell user about it and terminate via
  177. ; function 0 (which works for all DOS versions).
  178. ;
  179. ;
  180. dosexit label near
  181.        lea     dx,errmsg1      ;point DX to DOS error msg
  182.        mov     ah,9            ;set function code -- print string
  183.        int     21h             ;and request DOS service
  184.        xor     ax,ax           ;set function code to zero -- program terminate
  185.        int     21h             ;and request DOS service (no errorlevel returned)
  186. ;
  187. ;
  188. ; If we get here we encountered a file error after we successfully opened the
  189. ; file.  We must close it in order to release the handle for other programs to
  190. ; use.
  191. ;
  192. ;
  193. fileerror label near
  194.        push    ax              ;save the error code for a moment
  195.        mov     ah,3eh          ;set function code = close file -- handle in BX
  196.        int     21h             ;request DOS service
  197.        pop     ax              ;get error code back -- ignore errors in closing file
  198. ;
  199. ;
  200. ; If we get here we encountered a file error of some sort.  Display the error.
  201. ; The error code is in AX.
  202. ;
  203. ;
  204. fileerror10 label near
  205.        push    ax              ;save error code for a moment
  206.        lea     dx,errmsg2      ;point DX to syntax error msg
  207.        mov     ah,9            ;set function code -- print string
  208.        int     21h             ;and request DOS service
  209.        pop     dx              ;get error code into DX
  210.        cmp     dl,9            ;is it greater than nine?
  211.        jle     fileerror20     ;if so, then only a one digit error code
  212.        push    dx              ;else save a copy of error code
  213.        mov     dl,one          ;and put a '1' in DL -- tens digit
  214.        mov     ah,02           ;set function code -- display char in DL
  215.        int     21h             ;and request DOS service
  216.        pop     dx              ;restore old error code and
  217.        sub     dl,10d          ;subtract ten -- tens digit now displayed
  218. fileerror20 label near
  219.        add     dl,zero         ;convert from binary to ASCII code
  220.        mov     ah,02           ;set function code -- display char in DL
  221.        int     21h             ;and request DOS service
  222.        mov     dl,cr           ;send
  223.        mov     ah,02           ;    a
  224.        int     21h             ;    carriage return
  225.        mov     dl,lf           ;and a
  226.        mov     ah,02           ;    line feed
  227.        int     21h             ;to the console to keep things pretty
  228. sizediff label near
  229.        mov     ax,4c01h        ;set DOS function -- terminate with errorlevel 1
  230.        int     21h             ;and request DOS service -- end of program
  231. entry  endp
  232.        page
  233. ;
  234. ;
  235. ; Messages/other stuff
  236. ;
  237. ;
  238. filename db    'ERRLOG', 0                     ;filename to look for
  239. errmsg1 db     'SIZER requires DOS 2.0 or greater.', cr, lf, dollar
  240. errmsg2 db     'File access error -- status: ', dollar
  241. copyright db   'SIZER -- Copyright (C) 1983 Tony Alan Rhea'
  242. ;
  243. ;
  244. cseg   ends
  245.        end     entry
  246.