home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / misc_programming / battutor.l!h / QUERY.ASM < prev    next >
Assembly Source File  |  1990-11-02  |  7KB  |  178 lines

  1.                PAGE 60,132
  2. TITLE  QUERY.COM  VER.2.1  7-AUG-83  21:05
  3. comment *
  4.  
  5.                         QUERY.COM
  6.  
  7.  
  8.         VERSION 2.1     6-AUG-83
  9.  
  10.         Written by      Warren Craycroft
  11.                         6236 Oakdale Ave.
  12.                         Oakland, CA  94605
  13.  
  14.  
  15.         (C)  1983  by Warren Craycroft.  Permission is granted to copy and
  16.         distribute this program, including source code, provided that no
  17.         charge shall be made except for a reasonable charge for the media
  18.         and handling, and that this notice shall remain intact in all copies.
  19.  
  20.  
  21. *
  22. comment *
  23.         This program is a utility that can be used with DOS 2.0
  24.         to allow a yes/no interaction by the user during
  25.         execution of a batch file.  The program does this by
  26.         testing the user's one key response and returning to DOS an
  27.         "errorlevel" code corresponding to that keycode response.
  28.         This errorlevel code can then be tested by the
  29.         batch file program using the IF ERRORLEVEL n  statement.
  30.  
  31.         When QUERY is run in a batch file, an appropriate question
  32.         has been posed to the user via a REM or ECHO statement, or
  33.         the QUERY statment itself.  A reverse video box then prompts.
  34.         The user may answer with a single keystroke denoting
  35.         a yes, no , or escape response.  The errorlevel code is set
  36.         as follows:
  37.  
  38.                 errorlevel = 2          if user typed ESC key
  39.  
  40.                 errorlevel = 1          if user typed Y or y
  41.  
  42.                 errorlevel = 0          if user typed N or n
  43.  
  44.         If any other key is typed, the console is beeped,a message is
  45.         displayed, and this program waits for another keystroke.
  46.  
  47.         Remember that the subsequent IF clauses are "greater than or equal
  48.         to"  and  "less than", so the order of the IF tests is important.
  49.  
  50.                 IF ERRORLEVEL N         means   if errorlevel >= n
  51.  
  52.                 IF NOT ERRORLEVEL N     means   if errorlevel < n
  53.  
  54.  
  55.                 INCLUDE THESE FILES WHEN ASSEMBLING:
  56.  
  57.                         PARSER.INC
  58.                         QDISPLAY.INC
  59.                         QGETKEY.INC
  60.                         Q_CMDS.INC
  61.  
  62.  
  63.  
  64. *
  65. ;
  66. ;               constant equates
  67. ;
  68. ESC_CHAR        EQU     1BH             ;ascii ESC keycode
  69. BEL_CHAR        EQU     07              ;ascii BEL keycode
  70. CR              EQU     0DH             ;ascii carriage return
  71. LF              EQU     0AH             ;ascii line feed
  72. BLANK_CHAR      EQU     20H             ;ascii blank character
  73. ;
  74. ;       equate the return codes to symbols so that this program can be
  75. ;       easily modified to a different choice of returned errorlevel codes.
  76. ;
  77. ESC_RET_CODE    EQU     2
  78. Y_RET_CODE      EQU     1
  79. N_RET_CODE      EQU     0
  80. ;
  81. ;       declare a relocatable segment.  Follow the .COM file requirements
  82. ;       of entry point at 100H and making all seg register references relative
  83. ;       to CS (no relocatable values MOV'ed into segment registers).
  84. ;
  85. ;
  86. COM_CODE      SEGMENT
  87. ;
  88.                 ORG     80H             ;PSP offset 80:  user's command line
  89. PSP_CMD_LINE    LABEL   BYTE            ;define a label for address refs
  90. ;
  91.                 ORG     100H            ;for COM file
  92. ;
  93. ;
  94.                 ASSUME  CS:COM_CODE,DS:COM_CODE    ;tell assembler value of CS
  95.                                                    ; and DS
  96. ;
  97. ;       parse command line in PSP for commands inside slashes
  98. ;
  99. ;       leave CX pointing to first character after leading delimiters if no
  100. ;       slashes, or first char after second slash
  101. ;
  102. START           PROC            FAR     ;FAR is meaningless; no RETS
  103. ;
  104. ;       address of PSP's command line into SI
  105. ;
  106.                 MOV     SI,OFFSET PSP_CMD_LINE
  107. ;
  108. INCLUDE         PARSER.INC              ;bring in parser include file
  109. INCLUDE         QDISPLAY.INC            ;bring in cmd line string display
  110. INCLUDE         QGETKEY.INC             ;bring in reverse prompt
  111. ;
  112. ;       AL = user's answering keystroke.  Test it for extended code
  113. ;
  114.                 OR      AL,AL           ;is the keycode zero?
  115.                 JNZ     TEST_ESC        ;jump if not, test for ESC
  116.                 MOV     AH,1            ;else extended code was typed
  117.                 INT     21H             ;get rest of code, then declare
  118.                                         ;an error
  119. ;
  120. ;       keycode was not one of the allowed codes.  BEEP the console,
  121. ;       display a message, and wait for another keycode from keyboard
  122. ;
  123. ERROR:          MOV     DX,OFFSET ERROR_MESSAGE ;display message string
  124.                 MOV     AH,9            ;DOS fun code to display string
  125.                 INT     21H             ;beep the console
  126.                 JMP     DISPLAY_BOX     ;and wait for another key
  127. ;
  128. ;       test for ESC key, Y, y, N, n. Then exit (through DOS function 4CH)
  129. ;       with appropriate exit code:
  130. ;
  131. ;               exit code 2            if key was ESC
  132. ;
  133. ;               exit code 0            if key was N or n
  134. ;
  135. ;               exit code 1            if key was Y or y
  136. ;
  137. TEST_ESC:       MOV     DL,AL           ;move keycode to DL
  138.                 MOV     AL,ESC_RET_CODE ;return code for ESC
  139.                 MOV     AH,4CH          ;DOS fn call for exit
  140.                                         ;(DOS Manual, p. D-49)
  141. ;
  142.                 CMP     DL,ESC_CHAR     ;is keycode ESC?
  143.                 JNE     TEST_N          ;jump if not, test for N
  144. ;
  145. ;       Exit the program, returning to DOS via DOS 2.0 function call 4EH.
  146. ;       This function call terminates execution of QUERY and sets the DOS
  147. ;       "errorlevel" to the value found in AL.
  148. ;
  149. EXIT:           INT     21H             ;exit with return code in AL
  150. TEST_N:         MOV     AL,N_RET_CODE   ;return code for N, n into AL
  151.                 CMP     DL,'N'          ;is it 'N'?
  152.                 JE      EXIT            ;jump if yes
  153.                 CMP     DL,'n'          ;is it 'n'?
  154.                 JE      EXIT            ;jump if yes and exit
  155. TEST_Y:         MOV     AL,Y_RET_CODE   ;return code for Y, y into AL
  156.                 CMP     DL,'Y'          ;is keycode 'Y'?
  157.                 JE      EXIT            ;jump if yes and exit
  158.                 CMP     DL,'y'          ;else is keycode 'y'?
  159.                 JE      EXIT            ;jump if yes and exit
  160.                 JMP     ERROR           ;else beep the console and
  161.                                         ;get another keycode
  162. START           ENDP
  163. PAGE
  164. INCLUDE         Q_CMDS.INC              ;bring in slash command tables and code
  165. PAGE
  166. ;
  167. ;               variable data area of the COM segment
  168. ;
  169. USERS_ATTRIB    DB      1 DUP(?)        ;temp storage of character attrib
  170. ;
  171. ;               constant data area of the COM segment
  172. ;
  173. ERROR_MESSAGE   DB      CR,LF,BEL_CHAR
  174.                 DB      '        *** Please press one of these keys only:'
  175.                 DB      '  Y   N   Esc    $'
  176. COM_CODE        ENDS
  177.                 END     START
  178.