home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / BATUTL / EXT_BAT.ZIP / SETERROR.ASM < prev    next >
Encoding:
Assembly Source File  |  1984-04-26  |  6.6 KB  |  178 lines

  1.  
  2.  
  3.        page    64,132
  4.        title   SETERROR-sets the ERRORLEVEL for DOS batch file processing
  5.        subttl  by Tony Alan Rhea 10/24/83
  6. ;
  7. ;
  8. comment *
  9.  
  10.        This program accepts one command line argument and sets the
  11.        DOS ERRORLEVEL to that argument.  Currently, this program has
  12.        a limit of 9 for the errorlevel, but apparently DOS has a a
  13.        much higher limit (FFh -- the code is returned in a half-reg).
  14.        An invalid or missing argument gives an error message and an
  15.        errorlevel 0.  This program requires DOS 2.0.
  16.  
  17.        Usage:
  18.              SETERROR n
  19.        where n is between 0 and 9.
  20.  
  21.  
  22.        Copyright (C) 1983  Tony Alan Rhea
  23.        This program may be copied and distributed for personal use
  24.        but not for profit provided this notice is included.  Author makes
  25.        no warranty, expressed or implied, as to the correct nature and
  26.        operation of this software.
  27.  
  28.        You may make and distribute as many copies of this program as you wish
  29.        for your PERSONAL use only ( NOT for business purposes, please! ).
  30.        Feel free to modify, mutilate, or adulterate this program.  If you come
  31.        up with an bug or improvement, please let me know by writing me at this
  32.        address:
  33.                Tony A. Rhea
  34.                1030 Ivy Lane
  35.                Cary, NC  27511
  36.        If you do modify it, please give me credit in the program.  This helps
  37.        to preserve my ego and increase my fame (but, unfortunately, NOT my
  38.        financial status).  Also, I would appreciate a copy of the modified
  39.        version, preferably on disk (I'll be happy to return your diskette).
  40.  
  41.        If you like this program ( or HATE it ), please let me know.  Drop me
  42.        a line at the address given above.
  43.  
  44.        This program has been submitted for publication in PC-WORLD magazine.
  45.  
  46.  
  47.          Revision history:
  48.             rev 1.0  10/24/83                         { original release }
  49.  
  50.        *
  51. ;
  52. ;
  53. ; Equates
  54. ;
  55. ;
  56. space  equ     ' '
  57. zero   equ     '0'
  58. nine   equ     '9'
  59. cr     equ     0dh
  60. lf     equ     0ah
  61. dollar equ     '$'
  62.        page
  63. ;
  64. ;
  65. ; Program entry point
  66. ;
  67. ;
  68. cseg   segment para 'code'
  69.        assume  cs:cseg, ds:cseg, ss:nothing, es:cseg
  70.        org     100h            ;for .COM file
  71. entry  proc    near
  72.        mov     ah,30h          ;set function code -- get DOS version number
  73.        int     21h             ;and request DOS service
  74.        cmp     al,0            ;is it pre-DOS 2.0?
  75.        jne     entry10         ;if not, continue
  76.        jmp     dosexit         ;else tell user & quit
  77. ;
  78. ;
  79. ; At this point we have DOS 2.0 or better.  Check the length of
  80. ; the command line parameter.  The number of characters on the command
  81. ; line is at PSP+80h and the parms themselves start at PSP+81h.
  82. ;
  83. ;
  84. entry10 label  near
  85.        mov     si,80h          ;set up address of parm length in PSP
  86.        mov     cl,[si]         ;and get length into CX
  87.        cmp     cl,2            ;look for two chars (space+digit)
  88.        je      entry20         ;if not, continue
  89.        jmp     errorexit       ;else bad parms -- exit
  90. ;
  91. ;
  92. ; At this point, we have two characters - make sure the
  93. ; first one is a space and the second is a digit.
  94. ;
  95. ;
  96. entry20 label  near
  97.        inc     si              ;get address of parm in PSP
  98.        mov     bl,[si]         ;and get the first char in BL
  99.        cmp     bl,space        ;is it a space?
  100.        je      entry30         ;if so, continue
  101.        jmp     errorexit       ;else bad parm -- exit
  102. entry30 label  near
  103.        inc     si              ;point to next (second) parm char
  104.        mov     bl,[si]         ;and get second char into BL
  105.        cmp     bl,zero         ;is it greater than or equal to a zero?
  106.        jae     entry40         ;if so, continue
  107.        jmp     errorexit       ;else not digit -- exit
  108. entry40 label  near
  109.        cmp     bl,nine         ;is it less than or equal to a nine?
  110.        jbe     entry50         ;if so, continue
  111.        jmp     errorexit       ;else not digit -- exit
  112.        page
  113. ;
  114. ;
  115. ; At this point we have a valid digit as a parameter in BL.
  116. ; Convert the digit to binary and exit, setting the DOS ERRORLEVEL.
  117. ;
  118. ;
  119. entry50 label  near
  120.        sub     bl,zero         ;convert '0' to 0, '1' to 1, etc...
  121.        mov     al,bl           ;and put requested errorlevel in AL
  122.        mov     ah,4ch          ;set DOS function code -- terminate with errorlevel
  123.        int     21h             ;and request DOS service (requested errorlevel returned)
  124. ;
  125. ;
  126. ; If we get here we don't have DOS 2.0.  Tell user about it and terminate via
  127. ; function 0 (which works for all DOS versions).
  128. ;
  129. ;
  130. dosexit label near
  131.        lea     dx,errmsg1      ;point DX to DOS error msg
  132.        mov     ah,9            ;set function code -- print string
  133.        int     21h             ;and request DOS service
  134.        xor     ax,ax           ;set function code to zero -- program terminate
  135.        int     21h             ;and request DOS service (no errorlevel returned)
  136. ;
  137. ;
  138. ; If we get here the user entered an invalid command line parameter.  Show him
  139. ; the syntax and exit, returning errorlevel 0.
  140. ;
  141. ;
  142. errorexit label near
  143.        lea     dx,errmsg2      ;point DX to syntax error msg
  144.        mov     ah,9            ;set function code -- print string
  145.        int     21h             ;and request DOS service
  146.        mov     ax,4c00h        ;set DOS function code -- terminate with errorlevel
  147.        int     21h             ;and request DOS service (errorlevel 0 returned)
  148. entry  endp
  149.        page
  150. ;
  151. ;
  152. ; Error messages
  153. ;
  154. ;
  155. errmsg1 db     'SETERROR requires DOS 2.0 or greater.', cr, lf, dollar
  156. errmsg2 equ    $
  157.         db     'SETERROR -- sets the DOS ERRORLEVEL for batch file processing', cr, lf
  158.         db     'Usage:', cr, lf
  159.         db     '      SETERROR n', cr,lf
  160.         db     'where n is between 0 and 9.', cr, lf, dollar
  161. copyright db   'SETERROR -- Copyright (C) 1983 Tony Alan Rhea'
  162. ;
  163. ;
  164. cseg   ends
  165.        end     entry
  166.  
  167. Press <ENTER> 
  168.  
  169. Directory # 11 --  Time left 33 minute(s) 
  170. Enter File #, <L>ist, <Q>uit or <C>hg Dir. SAM : 
  171.  
  172.  
  173.         This disk copy was originally provided by "The Public Library",
  174.         the software library of the Houston Area League of PC Users.
  175.         Disks in the Public Libray are updated monthly.  Check with us
  176.         for the latest versions of all programs.
  177.  
  178.         Programs are available from the Public Library at $2 per disk
  179.         on user-provided disks.  To get a listing of the disks in the
  180.         Public Library, send a self-addressed, stamped envelope to
  181.  
  182.              Nelson Ford,  P.O.Box 61565,  Houston, TX 77208.
  183.