home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug171.arc / TURBO-IO.LBR / IO20DEMO.DZC / IO20DEMO.DOC
Text File  |  1979-12-31  |  10KB  |  262 lines

  1. DOCUMENTATION FOR IO20DEMO.PAS/COM -- 5/2/86
  2.  
  3. Bill Meacham
  4. 1004 Elm Street
  5. Austin, Tx  78703
  6.  
  7. PUBLIC DOMAIN -- NO COPYRIGHT
  8.  
  9. This program demonstrates a sophisticated method of controlling
  10. console data entry in Turbo Pascal.  It allows you precise
  11. control over where data entry occurs on the screen and makes your
  12. programs crash-proof from user input.  All the I/O (input/output)
  13. routines except for dates are in the Include file IO20.INC.
  14.  
  15. It also demonstrates a number of ways to manipulate and perform
  16. calculations with dates.  All the date routines are in the
  17. Include file DATE20.INC.  If you use this file, you must include
  18. IO20.INC first.
  19.  
  20. Put the compiler toggles {$C-,V-} at the top of your program,
  21. before the Include files.  $C- disables checking for control-C
  22. and makes the program run a bit faster.  $V- allows you to use
  23. strings of varying lengths.
  24.  
  25. The rest of this document describes the two Include files.
  26.  
  27.  
  28. DOCUMENTATION FOR IO20.INC --------------------------------------------
  29.  
  30. The functions and procedures in this Include module allow you to
  31. control console I/O with great precision.  You can read and write
  32. strings, integers, reals and booleans at any place on the screen
  33. and prevent the user from entering garbage.  User input cannot
  34. crash your program!  You can easily control cursor movement
  35. through data entry forms displayed on the screen, not only from
  36. field to field but from screen to screen.
  37.  
  38. The data input procedures, READ_STR, READ_INT, etc., have an
  39. intentional side-effect on the global variable FLD, which
  40. controls which field the cursor goes to.  Study the code in
  41. procedures STRINGS, INTEGERS, REALS and BOOLEANS in the
  42. demonstration program to see how a case statement within a
  43. repeat-until loop uses this variable.  Study the code in
  44. procedure IO_DEMO in the demonstration program to see how a
  45. similar case statement within a repeat-until loop uses the global
  46. variable SCRN to control which screen is displayed.
  47.  
  48. The rest of this section describes the global types, variables,
  49. procedures and functions that you can call from your program. 
  50. (There are a few more that are used by these procedures and
  51. functions, but are not intended to be called by themselves.)
  52.  
  53.  
  54. GLOBAL TYPES AND VARS
  55.  
  56. type
  57.     STR_TYPE = string[80] ;
  58.  
  59. var
  60.     FLD, SCRN   : integer ; { For field & screen cursor control. }
  61.  
  62.  
  63. PROCEDURES AND FUNCTIONS
  64.  
  65. procedure BEEP ;
  66.     Sounds the console bell.
  67.  
  68. function CHOPCH (instr:str_type ; inchar:char) : str_type ;
  69.     Chops trailing instances of the character from the string.
  70.  
  71. procedure CLREOL ;
  72.     Built-in proc in Turbo to clear screen to end of line.
  73.  
  74. procedure CLRLINE (col,row : integer) ;
  75.     Clears screen to end of line starting at column and row specified.
  76.  
  77. procedure CLRSCR ;
  78.     Built-in procedure in Turbo to clear screen and place cursor at
  79.     upper left.
  80.  
  81. procedure DO_SCRN_CTL ;
  82.     Checks value of FLD and adjusts value of SCRN accordingly.  Upon
  83.     exit SCRN is either one less than it used to be, one more, or
  84.     maxint.  If it is maxint you should exit from the series of screens.
  85.  
  86. function EQUAL (r1,r2 : real) : boolean ;
  87.     Tests functional equality of two real numbers (floating point, not
  88.     BCD).  Returns true if r1 equals r2 to a tolerance of 1/100,000.
  89.  
  90. procedure GOTOXY (col,row:integer) ;
  91.     Built-in procedure in Turbo to place cursor on screen at column
  92.     (horizontal) and row (vertical) position specified.  Upper left is
  93.     (1,1) not (0,0).
  94.  
  95. function GREATER (r1,r2 : real) : boolean ;
  96.     Tests functional inequality of two real numbers (floating point, not
  97.     BCD).  Returns True of r1 is greater than r2 to a tolerance of
  98.     1/100,000.
  99.  
  100. procedure HARD_PAUSE ;
  101.     Displays message on line 24, "PRESS SPACE BAR TO CONTINUE OR UP-ARROW
  102.     TO GO BACK."  Cursor can go forward only if user presses space bar. 
  103.     Cursor movement back and ESC key are enabled as well.
  104.  
  105. procedure KEYIN (var ch:char) ;
  106.     Accepts one character from the keyboard without echoing it back. 
  107.     Translates certain control characters and function keys to cursor
  108.     control keys recognized by the read_xxx procedures.
  109.  
  110. procedure PAUSE ;
  111.     Displays message on line 24, "PRESS SPACE BAR TO CONTINUE."  Cursor
  112.     goes forward only if user presses space bar.  Cursor movement back
  113.     is disabled, but ESC is recognized.
  114.  
  115. function PURGECH (instr : str_type ; inchar : char) : str_type ;
  116.     Purges all instances of the character from the string.
  117.  
  118. procedure READ_BOOL (var bool:boolean; col,row:integer) ;
  119.     Displays boolean at column and row specified, inputs "Y"
  120.     or "N" to set new value of boolean, prints "YES" or "NO."
  121.       Note -- use this when the screen control may return to the
  122.     question and the boolean IS defined before the user answers
  123.     the question.  Does affect global FLD.
  124.  
  125. procedure READ_INT (var int:integer ; maxlen, col, row:integer) ;
  126.     Reads an integer from the keyboard, rejects invalid data.  COL and
  127.     ROW tell where to begin the data input field, and MAXLEN is the
  128.     maximum length of the character representation of the integer,
  129.  
  130. procedure READ_REAL (var r:real ; maxlen,frac,col,row:integer) ;
  131.     Reads a real number from the keyboard, rejects invalid data.  COL
  132.     and ROW tell where to begin the data input field; MAXLEN is the
  133.     maximum length of the string representation of the real number,
  134.     including sign and decimal point; FRAC is the fractional part, the
  135.     number of digits to right of the decimal point.  Designed to work
  136.     with floating point (not BCD) reals, but could work with BCDs as
  137.     well.  Note -- In Turbo the maximum number of significant digits in
  138.     a floating point real is 11.  It is the programmer's responsibility
  139.     to limit input and computed output to 11 significant digits. 
  140.  
  141. procedure READ_STR (var st:str_type ; maxlen, col, row:integer) ;
  142.     Reads a string from the keyboard, rejects invalid data.  COL and ROW
  143.     tell where to begin the data input field, and MAXLEN is the maximum
  144.     length of the string.
  145.  
  146. procedure READ_YN (var bool:boolean; col,row:integer) ;
  147.     Inputs "Y" OR "N" to boolean at column and row specified,
  148.     prints "YES" or "NO."
  149.       Note -- use this when the screen control will not return
  150.     to the question and the boolean IS NOT defined before the
  151.     user answers the question.  Does not affect global FLD.
  152.  
  153. procedure SHOW_MSG (msg : str_type) ;
  154.     Beeps, displays message centered on line 23, pauses (calls proc
  155.     Pause).
  156.  
  157. function STRIPCH (instr:str_type ; inchar:char) : str_type ;
  158.     Strips leading instances of the character from the string.
  159.  
  160. procedure WRITE_BOOL (bool:boolean ; col, row:integer) ;
  161.     Writes "YES" or "NO " at the column and row specified, depending on
  162.     value of the boolean.
  163.  
  164. procedure WRITE_INT (int:integer ; width,col,row:integer) ;
  165.     Writes the integer, right-justified in a field WIDTH characters
  166.     wide, at the column and row specified.
  167.  
  168. procedure WRITE_REAL (r:real ; width,frac,col,row:integer) ;
  169.     Writes the real, right-justified in decimal format with FRAC digits
  170.     to the right of the decimal point in a field WIDTH wide, at the
  171.     column and row specified.
  172.  
  173. procedure WRITE_STR (st:str_type ; col,row:integer) ;
  174.     Writes the string at the column and row specified.
  175.  
  176.  
  177. DOCUMENTATION FOR DATE20.INC ------------------------------------------
  178.  
  179. The functions and procedures in this Include file allow you to
  180. read and write dates in a fashion similar to reading and writing
  181. strings, integers, reals and booleans.  You can also perform
  182. number of other functions on dates, such as count the number of
  183. days between two dates, test for leapyear, compute the previous
  184. and next day, etc.  If you include this file, include IO20.INC
  185. first.
  186.  
  187.  
  188. GLOBAL TYPES AND CONSTANTS
  189.  
  190. type
  191.     DATE = record
  192.         yr : integer ; { 0 .. 9999 }
  193.         mo : integer ; { 1 .. 12 }
  194.         dy : integer ; { 1 .. 31 }
  195.       end ;
  196.  
  197.     DATESTRING = string[10] ;  { 'MM/DD/YYYY' }
  198.  
  199.     JULDATE = record
  200.         yr  : integer ; { 0 .. 9999 }
  201.         day : integer ; { 1 .. 366 }
  202.       end ;
  203.  
  204.     JULDATESTRING = string[8] ; { 'YYYY/DDD' }
  205.  
  206. const
  207.     NULL_DATE     : date       = (yr:0 ; mo:0 ; dy:0) ;
  208.     NULL_DATE_STR : datestring = 'MM/DD/YYYY' ;
  209.  
  210.  
  211. PROCEDURES AND FUNCTIONS
  212.  
  213. function DATE_DIFF (dt1, dt2 : date) : real ;
  214.     Computes the number of days between two dates.
  215.  
  216. function EQUAL_DATE (dt1, dt2 : date) : boolean ;
  217.     Returns True if dt1 is equal to dt2, else False.
  218.  
  219. function GREATER_DATE (dt1, dt2 : date) : integer ;
  220.     Compares two dates, returns 0 if both equal, 1 if first is
  221.     greater, 2 if second is greater.
  222.  
  223. procedure GREG_TO_JUL (dt : date ; var jdt : juldate) ;
  224.     Converts a gregorian date to a julian date.
  225.  
  226. procedure JUL_TO_GREG (jdt : juldate ; var dt : date) ;
  227.     Converts a julian date to a gregorian date.
  228.  
  229. function LEAPYEAR (yr : integer) : boolean ;
  230.     Returns True if the year is a leap year, else False.  The
  231.     year is year and century, e.g. year 1984 is '1984,' not '84.'
  232.  
  233. function MK_DT_ST (dt : date) : datestring ;
  234.     Makes a string out of a date -- used for printing dates.
  235.  
  236. function MK_JUL_DT_ST (jdt : juldate) : juldatestring ;
  237.     Makes a string out of a julian date.
  238.  
  239. function MONTH_DIFF (dt1, dt2 : date ) : integer ;
  240.     Computes number of months between two dates, rounded.
  241.  
  242. procedure NEXT_DAY (var dt : date) ;
  243.     Adds one day to the date.
  244.  
  245. procedure PREV_DAY (var dt : date) ;
  246.     Subtracts one day from the date.
  247.  
  248. procedure READ_DATE (var dt: date ; col, row: integer) ;
  249.     Read date at column and row specified.  If the user enters
  250.     only two digits for the year, the procedure plugs the century
  251.     as 1900 for years from 80 to 99 or 2000 for years from 00 to
  252.     79, but the user can enter all four digits to override the
  253.     plug.
  254.  
  255. function VALID_DATE (dt:date) : boolean ;
  256.     Returns True if the date is a valid date, else False.
  257.  
  258. procedure WRITE_DATE (dt: date ; col, row: integer) ;
  259.     Writes date at column and row specified.
  260. not '84.'
  261.  
  262. function MK_DT_ST (dt : date) : datestring