home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / comm / tm211_1.zip / TOOLBOX2.SCR < prev    next >
Text File  |  1990-05-25  |  5KB  |  187 lines

  1. ;
  2. ; TOOLBOX2.SCR (c) Copyright 1990 by Tsung Hu.  All right reserved.
  3. ; Date written: 10 May 1990
  4. ;
  5. ;
  6. ; This toolbox defines three I/O procedures and four 'is' type
  7. ; procedures.
  8. ;
  9. ; To use this toolbox, you should add the line
  10. ;    #include "toolbox2.scr"
  11. ; at the beginning of your script file.  This will increase the file
  12. ; size of the compiled script file .TMS by about 2K.  To minimum the
  13. ; overhead, you should cut and paste the procedures that you used
  14. ; into your script file.  For example, the <InputN> and <ReadN>
  15. ; procedures may be excluded.
  16. ;
  17. ; Summary:
  18. ;
  19. ;   GetN s,n
  20. ;   ; get <n> characters from remote system or until CR is detected
  21. ;
  22. ;   InputN s,n
  23. ;   ; get <n> characters from keyboard or until [Enter] is detected,
  24. ;   ; the characters are printed to the local screen
  25. ;
  26. ;   ReadN s,n
  27. ;   ; read <n> characters from file or until end-if-line is detected
  28. ;
  29. ;   isalpha ch,result    ; check if <ch> is a letter
  30. ;   isdigit ch,result    ; check if <ch> is a digit
  31. ;   isalnum ch,result    ; check if <ch> is a letter or a digit
  32. ;   iscntl  ch,result    ; check if <ch> is a control character
  33. ;
  34.  
  35.  
  36. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  37. ;
  38. ; GetN s,n
  39. ; function: get <n> characters into <s> from remote system or until CR
  40. ;           is detected
  41. ; remark:   This procedure can be used to wait for one character
  42. ;           input by using  GetN ch,1
  43. ;           CR is discarded
  44. ;           BackSpace deletes the last character and the length of
  45. ;           the string is recalcuated
  46. ;
  47. Procedure GetN string s,integer n
  48. integer i
  49. string ch
  50. s = ""
  51. ch = ""
  52. i = 0
  53. While i<n and ch<>"^M"
  54.    repeat
  55.       GetCh ch
  56.    until success
  57.    concat s,ch
  58.    if ch="^H"           ; BackSpace is displayed to screen
  59.       if i=0
  60.          print " ",     ; move back the correct position
  61.       else
  62.          i = i-1;
  63.       endif
  64.    else
  65.       i = i+1
  66.    endif
  67.    if i<n and ch<>"^M"
  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.    if i<n and ch<>"^M"
  112.       repeat
  113.          InputCh ch
  114.       until success
  115.    endif
  116. EndWhile
  117. if ch="^M"
  118.    print
  119. endif
  120. EndProc
  121.  
  122.  
  123. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  124. ;
  125. ; ReadN s,n
  126. ; function: read <n> characters into <s> from file or until CR-LF
  127. ;           end-of-line sequence is detected
  128. ; remark:   CR-LF sequence is discarded
  129. ;
  130. Procedure ReadN string s,integer n
  131. integer i
  132. string ch
  133. s = ""
  134. ch = ""
  135. i = 0
  136. while i<n and ch<>"^M"
  137.    ReadCh ch
  138.    concat s,ch
  139.    i = i+1
  140. EndWhile
  141. if ch="^M"
  142.    Readch ch                   ; discard CR-LF sequence
  143. endif
  144. EndProc
  145.  
  146.  
  147. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  148. ;
  149. ; isalpha ch,result
  150. ; function: <result> is non-zero if <ch> is a character
  151. ;
  152. Procedure isalpha string ch,integer result
  153. strpos "ABCDEFGHIJKLMNOPQRSTUVWXYZ",ch,result
  154. EndProc
  155.  
  156.  
  157. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  158. ;
  159. ; isdigit ch,result
  160. ; function: <result> is non-zero if <ch> is a digit
  161. ;
  162. Procedure isdigit string ch,integer result
  163. strpos "1234567890",ch,result
  164. EndProc
  165.  
  166. ; isalnum ch,result
  167. ; function: <result> is non-zero if <ch> is a digit or character
  168. ;
  169. Procedure isalnum string ch,integer result
  170. isdigit ch,result
  171. if not result
  172.    isalpha ch,result
  173. endif
  174. EndProc
  175.  
  176.  
  177. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  178. ;
  179. ; iscntl ch,result
  180. ; function: <result> is non-zero if <ch> is a control character
  181. ;
  182. Procedure iscntl string ch,integer result
  183. 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
  184. EndProc
  185.  
  186.  
  187.