home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / intercal.zip / lib / numio.doc < prev    next >
Text File  |  1996-06-20  |  3KB  |  71 lines

  1. Summary of routines in numio.i:
  2.  
  3. (3000)   .1 <- character from input
  4. (3001)   Prints .2 as a character
  5. (3080)   .1 <- a 16-bit number from the user
  6. (3089)   .1 <- a 16-bit number from the user, with an error message if
  7.          non-digits are encountered
  8. (3090)   Displays the value in .1
  9. (3099)   Displays the value in .1 and prints a newline
  10. (3080)   :1 <- a 32-bit number from the user
  11. (3089)   :1 <- a 32-bit number from the user, with an error message if
  12.          non-digits are encountered
  13. (3090)   Displays the value in :1
  14. (3099)   Displays the value in :1 and prints a newline
  15. (3990)   Initializes internal arrays.
  16.  
  17. The file numio.i contains routines for doing "wimpmode"-style I/O - or
  18. in other words, the C-INTERCAL equivalent of atoi and itoa. (3080) and
  19. (3090) translate the ASCII input as a number (yes, a number as in
  20. [0-9]*), and (3090) and (3190) do the same for displaying numbers in
  21. ASCII. (By the way, the routines can also be made to support EBCDIC:
  22. simply replace #3 with #15 on lines 41, 81, and 107.)
  23.  
  24. Each routine also has a "niner" variation. For itoa, (3099) and (3190)
  25. print a newline at the end of the number. In the case of atoi, (3089)
  26. and (3189) make sure that the number ends with a newline. In other
  27. words, they ensure there are no other non-numeric characters in the
  28. input line. If there are, a typically snide INTERCAL error message is
  29. displayed. (The regular versions work like C's atoi in that they
  30. return as soon as they see any non-digit.)
  31.  
  32. There's not too much to note about these routines. The atoi versions
  33. use the shift-and-add trick to avoid multiplying by 10, so they should
  34. be pretty efficient (snort). itoa has no such shortcuts, and the
  35. routines use the modified division routine which also returns the
  36. remainder. The 16-bit version is at (2030), and is the familiar one
  37. created by Louis Howell, copied from syslib2.i. The 32-bit version is
  38. at (2530), and is just a copy of the standard library routine without
  39. the lines that throw away the remainder at the end.
  40.  
  41. The library reserves the use of two arrays - ,3000 and ,3001 - for
  42. input and output respectively. Each array has one dimension of one
  43. element, and they are used to provide a getchar and putchar: routines
  44. (3000) and (3001).
  45.  
  46. The arrays are initialized by routine (3990); this should be called
  47. before using any other routines in this file.
  48.  
  49. Note also that for these routines to work properly, they must be used
  50. more or less exclusively in regards to other array I/O. Otherwise, the
  51. getchar and putchar subroutines will get out of synch with the
  52. Turing-text character loop. If you do want to do other I/O while using
  53. these routines, you can use (3000) and (3001) as a getchar and putchar
  54. (note that the latter expects that the character values have already
  55. been reversed). Or, you can simply re-initialize the ,3000 and/or
  56. ,3001 values after you are done, by storing in them the ASCII value of
  57. the last character that you wrote in and/or read out. For example,
  58. if you have displayed some strings and the last thing to be printed
  59. was a newline, then:
  60.  
  61.     DO ,3001SUB#1 <- #80
  62.  
  63. would allow you to safely call the itoa routines, since 80 is the
  64. bit-reversal of 10.
  65.  
  66.  
  67. It is my earnest hope that C-INTERCAL programmers everywhere will
  68. flock to these handy routines, and C-INTERCAL users will thus no
  69. longer need to fear that they might succumb to the foul and awful
  70. temptation to use the dastardly +wimpmode option.
  71.