home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / t / tm400-3.zip / TOOLBOX.EXE / TOOLBOX2.SCR < prev    next >
Text File  |  1993-01-01  |  5KB  |  181 lines

  1. ;
  2. ; TOOLBOX2.SCR (c) Copyright 1990-1992 by White River Software.
  3. ; All right reserved.
  4. ;
  5. ; Date written: 10 May 1990
  6. ;
  7. ;
  8. ; This toolbox defines three I/O procedures and four 'is' type
  9. ; procedures.
  10. ;
  11. ; To use this toolbox, you should add the line
  12. ;    #include "toolbox2.scr"
  13. ; at the beginning of your script file.  This will increase the file
  14. ; size of the compiled script file .TMS by about 2K.  To minimum the
  15. ; overhead, you should cut and paste the procedures that you used
  16. ; into your script file.  For example, the <InputN> and <ReadN>
  17. ; procedures may be excluded.
  18. ;
  19. ; Summary:
  20. ;
  21. ;   GetN s,n
  22. ;   ; get <n> characters from remote system or until CR is detected
  23. ;
  24. ;   InputN s,n
  25. ;   ; get <n> characters from keyboard or until [Enter] is detected,
  26. ;   ; the characters are printed to the local screen
  27. ;
  28. ;   ReadN s,n
  29. ;   ; read <n> characters from file or until end-if-line is detected
  30. ;
  31. ;   isalpha ch,result    ; check if <ch> is a letter
  32. ;   isdigit ch,result    ; check if <ch> is a digit
  33. ;   isalnum ch,result    ; check if <ch> is a letter or a digit
  34. ;   iscntl  ch,result    ; check if <ch> is a control character
  35. ;
  36.  
  37.  
  38. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  39. ;
  40. ; GetN s,n
  41. ; function: get <n> characters into <s> from remote system or until CR
  42. ;           is detected
  43. ; remark:   This procedure can be used to wait for one character
  44. ;           input by using  GetN ch,1
  45. ;           CR is discarded
  46. ;           BackSpace deletes the last character and the length of
  47. ;           the string is recalcuated
  48. ;
  49. Procedure GetN string s,integer n
  50. integer i
  51. string ch
  52. s = ""
  53. ch = ""
  54. i = 0
  55. While i<n and ch<>"^M"
  56.    repeat
  57.       GetCh ch
  58.    until success
  59.    concat s,ch
  60.    if ch="^H"           ; BackSpace is displayed to screen
  61.       if i=0
  62.          print " ",     ; move back the correct position
  63.       else
  64.          i = i-1;
  65.       endif
  66.    else
  67.       i = i+1
  68.    endif
  69. EndWhile
  70. EndProc
  71.  
  72.  
  73. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  74. ;
  75. ; InputN s,n
  76. ; function: get <n> characters into <s> from keyboard or until [Enter]
  77. ;           is pressed
  78. ; remark:   This procedure can be used to wait for one character
  79. ;           input by using  InputN ch,1
  80. ;           [Enter] is discarded
  81. ;           BackSpace deletes the last character and the length of
  82. ;           the string is recalcuated
  83. ;           The characters are printed to the local screen but are not
  84. ;           sent to the remote system.
  85. ;           A line feed is supplied when [Enter] is pressed.
  86. ; caution:  Once you do not need keyboard input any more, you should
  87. ;           use the
  88. ;               Clear Key
  89. ;           statement to give up keyboard control
  90. ;
  91. Procedure InputN string s,integer n
  92. integer i
  93. string ch
  94. s = ""
  95. ch = ""
  96. i = 0
  97. While i<n and ch<>"^M"
  98.    repeat
  99.       InputCh ch
  100.    until success
  101.    concat s,ch
  102.    if ch="^H"
  103.       if i>0
  104.          i = i-1
  105.          print ch,
  106.       endif
  107.    else
  108.       i = i+1
  109.       print ch,
  110.    endif
  111. EndWhile
  112. if ch="^M"
  113.    print
  114. endif
  115. EndProc
  116.  
  117.  
  118. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  119. ;
  120. ; ReadN s,n
  121. ; function: read <n> characters into <s> from file or until CR-LF
  122. ;           end-of-line sequence is detected
  123. ; remark:   CR-LF sequence is discarded
  124. ;
  125. Procedure ReadN string s,integer n
  126. integer i
  127. string ch
  128. s = ""
  129. ch = ""
  130. i = 0
  131. while i<n and ch<>"^M"
  132.    ReadCh ch
  133.    concat s,ch
  134.    i = i+1
  135. EndWhile
  136. if ch="^M"
  137.    Readch ch                   ; discard CR-LF sequence
  138. endif
  139. EndProc
  140.  
  141.  
  142. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  143. ;
  144. ; isalpha ch,result
  145. ; function: <result> is non-zero if <ch> is a character
  146. ;
  147. Procedure isalpha string ch,integer result
  148. strpos "ABCDEFGHIJKLMNOPQRSTUVWXYZ",ch,result
  149. EndProc
  150.  
  151.  
  152. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  153. ;
  154. ; isdigit ch,result
  155. ; function: <result> is non-zero if <ch> is a digit
  156. ;
  157. Procedure isdigit string ch,integer result
  158. strpos "1234567890",ch,result
  159. EndProc
  160.  
  161. ; isalnum ch,result
  162. ; function: <result> is non-zero if <ch> is a digit or character
  163. ;
  164. Procedure isalnum string ch,integer result
  165. isdigit ch,result
  166. if not result
  167.    isalpha ch,result
  168. endif
  169. EndProc
  170.  
  171.  
  172. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  173. ;
  174. ; iscntl ch,result
  175. ; function: <result> is non-zero if <ch> is a control character
  176. ;
  177. Procedure iscntl string ch,integer result
  178. strpos "^A^B^C^D^E^F^G^H^I^J^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z",ch,result
  179. EndProc
  180.  
  181.