home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / io / io_23 / io23demo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-02-11  |  19.0 KB  |  603 lines

  1. {$R-}    {Range checking off}
  2. {$B-}    {Boolean short circuiting off}
  3. {$S+}    {Stack checking on}
  4. {$I+}    {I/O checking on}
  5. {$N-}    {No numeric coprocessor}
  6. {$M 16384,0,16384}
  7.  
  8. program IO23DEMO ;
  9.   { This program demonstrates Turbo Pascal console I/O routines for an
  10.     elegant user interface.
  11.       Original version          --  4/18/86.
  12.       Added day of week display -- 10/ 9/86.
  13.       Version 2.2 enhancements  --  5/24/87.
  14.       Ver. 2.3 -- Add screen stuff, set colors -- IBM only, not CP/M.
  15.       Converted to Turbo Pascal 4.0 -- 12/2/87
  16.  
  17.     PUBLIC DOMAIN, NO COPYRIGHT
  18.       William Meacham
  19.       1004 Elm Street
  20.       Austin, Tx  78703 }
  21.  
  22. {$v-}
  23.  
  24. Uses
  25.   Crt, printer, Dos, io23unit, date23, dos23 ;
  26.  
  27. const
  28.     config_fname     = 'IO23.CFG' ;            { Config file name }
  29.  
  30. type
  31.     config_rec = record
  32.       { Configuration record }
  33.         bgc,                                   { 0 -- background color }
  34.         txc    : integer ;                     { 1 -- text color }
  35.         cfgint : array [2..63] of integer ;    { reserved for future use }
  36.       end ;
  37.  
  38. var
  39.     today       : datestring ;
  40.     choice      : integer ;                    { to get menu choice }
  41.     quitnow     : boolean ;                    { to get user Y/N input }
  42.     config      : config_rec ;                 { Configuration record }
  43.     config_file : file of config_rec ;         { Configuration file }
  44.  
  45. { ------------------------------------------------------------ }
  46.  
  47. procedure title_screen ;
  48.  
  49. var
  50.     ch : char ;
  51.     i  : integer ;
  52.  
  53.     begin
  54.         clrscr;
  55.         write_str ('------------------',31,6) ;
  56.         write_str ('                  ',31,7) ;
  57.         rvson ;
  58.         write_str ('   Demonstration  ',31,8) ;
  59.         write_str ('        of        ',31,9) ;
  60.         write_str ('   Turbo Pascal   ',31,10) ;
  61.         write_str ('  User Interface  ',31,11) ;
  62.         rvsoff ;
  63.         write_str ('                  ',31,12) ;
  64.         write_str ('------------------',31,13) ;
  65.         write_str ('    Reliance Software Services',23,18) ;
  66.         write_str ('1004 Elm Street, Austin, Tx  78703',23,19) ;
  67.         write_str ('   Public Domain - No Copyright',23,21) ;
  68.         fld := 0 ;
  69.         hard_pause ;
  70.         if fld = maxint then
  71.           begin
  72.             gotoxy (1,23) ;
  73.             halt
  74.           end
  75.     end ; { proc title_screen }
  76.  
  77. { ------------------------------------------------------------ }
  78.  
  79. procedure display_menu ;
  80. begin
  81.     clrscr ;
  82.     write_str(today,35,1) ;
  83.     write_str('USER INTERFACE DEMONSTRATION',26,3) ;
  84.     write_str('MAIN MENU',36,4) ;
  85.     write_str('Please select:',26,6) ;
  86.     write_str('1    Display instructions',26,8) ;
  87.     write_str('2    Data entry and display demo for',26,10) ;
  88.     write_str('Strings, Integers, Reals and Booleans',31,11) ;
  89.     write_str('3    Data entry and display demo for Dates',26,13) ;
  90.     write_str('4    Change colors',26,15) ;
  91.     write_str('ESC  Exit the program',26,17) ;
  92.     write_str('==>',26,19)
  93. end ; { proc display_menu }
  94.  
  95. { ------------------------------------------------------------ }
  96.  
  97. procedure display_instructions ;
  98. begin
  99.     clrscr;
  100.     rvson ;
  101.     write_str('                              Labelled     Arrow   Ctrl     Function ',6,1) ;
  102.     write_str('COMMAND                         key         key    key      key (IBM)',6,2) ;
  103.     rvsoff ;
  104.     writeln ;
  105.     writeln('     --------------------------    --------     -----   ----     ---------') ;
  106.     writeln('  *  DELETE character at cursor      Del                  G         F1') ;
  107.     writeln('  *  DELETE character to left      Backspace') ;
  108.     writeln('  *  DELETE entire entry                                  Y         F2') ;
  109.     writeln ;
  110.     writeln('  *  MOVE LEFT one character                    left      S         F5') ;
  111.     writeln('  *  MOVE RIGHT one character                   right     D         F6') ;
  112.     writeln ;
  113.     writeln('  *  MOVE FORWARD to next field     Enter       down      X         F4') ;
  114.     writeln('  *  MOVE BACK to previous field                 up       E         F3') ;
  115.     writeln ;
  116.     writeln('  *  PAGE FORWARD to next screen                PgDn      C         F8') ;
  117.     writeln('  *  PAGE BACK to previous screen               PgUp      R         F7') ;
  118.     writeln ;
  119.     writeln('  *  CANCEL data entry               Esc') ;
  120.     writeln ;
  121.     writeln('  *  TO ENTER DATA:   Type the data & press Enter or a field or page key.') ;
  122.     writeln('  *  TO ENTER YES/NO: Type "Y" or "N;" don''t press Enter.') ;
  123.     writeln('  *  TO ENTER A DATE: Type the month, 2 digits, the day, 2 digits,') ;
  124.     writeln('                      and the year, 2 or 4 digits, and press Enter.') ;
  125.     hard_pause ;
  126.     fld := 1 { reset FLD for calling proc }
  127. end ; { proc display_instructions }
  128.  
  129. { ------------------------------------------------------------ }
  130.  
  131. procedure io_demo ;
  132.   { demonstrate I/O of strings, integers, reals and booleans }
  133.  
  134. var
  135.     first, last, addr1, addr2, city,
  136.           state, zip : str_type ;   { for string demo }
  137.     i1, i2, i3, itot : integer ;    { for integer demo }
  138.     r1, r2, r3, rtot : real ;       { for real demo }
  139.     b1, b2, b3, b4   : boolean ;    { for boolean demo }
  140.  
  141. { ==================== }
  142.  
  143. procedure init_io_vars ;
  144.   { Initializes global variables }
  145.     begin
  146.         first := '' ;
  147.         last  := '' ;
  148.         addr1 := '' ;
  149.         addr2 := '' ;
  150.         city  := '' ;
  151.         state := '' ;
  152.         zip   := '' ;
  153.         i1 := 0 ;
  154.         i2 := 0 ;
  155.         i3 := 0 ;
  156.         itot := 0 ;
  157.         r1 := 0 ;
  158.         r2 := 0 ;
  159.         r3 := 0 ;
  160.         rtot := 0 ;
  161.         b1 := false ;
  162.         b2 := false ;
  163.         b3 := false ;
  164.         b4 := false
  165.     end ; { proc init_io_vars }
  166.  
  167. { ==================== }
  168.  
  169. procedure strings ;
  170.   { This procedure demonstrates reading and writing strings. }
  171.  
  172.     var
  173.         i  : integer ; { For loop control }
  174.         ok : boolean ; { Whether zip code is numeric }
  175.  
  176.     begin
  177.         clrscr ;
  178.         rvson ;
  179.         write ('SCREEN ', scrn, ' -- STRINGS') ;
  180.         rvsoff ;
  181.         write_str ('First name:',9,8) ;
  182.         write_str (first,21,8 ) ;
  183.         write_str ('Last name:',9,9) ;
  184.         write_str (last,21,9) ;
  185.         write_str ('Address 1:',9,10) ;
  186.         write_str (addr1,21,10) ;
  187.         write_str ('Address 2:',9,11) ;
  188.         write_str (addr2,21,11) ;
  189.         write_str ('City:',9,12) ;
  190.         write_str (city,21,12) ;
  191.         write_str ('State:',9,13) ;
  192.         write_str (state,21,13) ;
  193.         write_str ('Zip:',9,14) ;
  194.         write_str (zip,21,14) ;
  195.         fld := 1 ;
  196.         repeat
  197.                 case fld of
  198.                   1: read_str (first, 15, 21, 8) ;
  199.                   2: read_str (last, 10, 21, 9) ;
  200.                   3: read_str (addr1, 15, 21, 10) ;
  201.                   4: read_str (addr2, 15, 21, 11) ;
  202.                   5: read_str (city, 15, 21, 12) ;
  203.                   6: read_str (state, 2, 21, 13) ;
  204.                   7: begin
  205.                        repeat
  206.                            read_str (zip, 5, 21, 14) ;
  207.                            ok := true ;
  208.                            if not (zip = '') then
  209.                                begin
  210.                                    if length (zip) < 5 then
  211.                                            ok := false
  212.                                    else
  213.                                            for i:= 1 to 5 do
  214.                                                if (zip[i] <'0')
  215.                                                or (zip[i] >'9') then
  216.                                                    ok := false
  217.                                end ;
  218.                            if not ok then
  219.                              begin
  220.                                show_msg ('MUST BE NUMERIC OR NOT ENTERED') ;
  221.                                zip := '' ;
  222.                                fld := 7
  223.                              end
  224.                        until ok ;
  225.                      end ; { 7: }
  226.                 end ; { case }
  227.         until (fld < 1) or (fld > 7) ;
  228.         do_scrn_ctl
  229.     end ; { proc strings }
  230.  
  231. { ==================== }
  232.  
  233. procedure integers ;
  234.   { This procedure demonstrates reading & writing integers. }
  235.  
  236.     procedure sum_int ;
  237.         begin
  238.             itot := i1 + i2 + i3 ;
  239.             write_int (itot, 5, 13, 12)
  240.         end ;
  241.  
  242.     begin { integers }
  243.         clrscr ;
  244.         rvson ;
  245.         write ('SCREEN ', scrn, ' -- INTEGERS') ;
  246.         rvsoff ;
  247.         write_str ('==>', 9, 8) ;
  248.         write_int (i1,4,14,8) ;
  249.         write_str ('==>', 9, 9) ;
  250.         write_int (i2,4,14,9) ;
  251.         write_str ('==>', 9, 10) ;
  252.         write_int (i3,4,14,10) ;
  253.         write_str ('TOTAL', 7, 12) ;
  254.         write_int (itot,5,13,12) ;
  255.         fld := 1 ;
  256.         repeat
  257.                 case fld of
  258.                   1: begin
  259.                        read_int (i1, 4, 14, 8) ;
  260.                        sum_int ;
  261.                      end ;
  262.                   2: begin
  263.                        read_int (i2, 4, 14, 9) ;
  264.                        sum_int ;
  265.                      end ;
  266.                   3: begin
  267.                        read_int (i3, 4, 14, 10) ;
  268.                        sum_int ;
  269.                      end ;
  270.                   4: pause ;
  271.                 end ; { case }
  272.         until (fld < 1) or (fld > 4 ) ;
  273.         do_scrn_ctl
  274.     end ; { proc integers }
  275.  
  276. { ==================== }
  277.  
  278. procedure reals ;
  279.   { This procedure demonstrates reading & writing reals. }
  280.  
  281.     const
  282.         tot  = 11 ;
  283.         frac = 3  ;
  284.  
  285.     procedure sum_real ;
  286.         begin
  287.             rtot := r1 + r2 + r3 ;
  288.             write_real (rtot, tot+1, frac, 13, 12)
  289.         end ;
  290.  
  291.     begin { proc reals }
  292.         clrscr ;
  293.         rvson ;
  294.         write ('SCREEN ', scrn, ' -- REALS') ;
  295.         rvsoff ;
  296.         write_str ('==>', 9, 8) ;
  297.         write_real (r1,tot,frac,14,8) ;
  298.         write_str ('==>', 9, 9) ;
  299.         write_real (r2,tot,frac,14,9) ;
  300.         write_str ('==>', 9, 10) ;
  301.         write_real (r3,tot,frac,14,10) ;
  302.         write_str ('TOTAL', 7, 12) ;
  303.         write_real (rtot,12,3,13,12) ;
  304.         fld := 1 ;
  305.         repeat
  306.                 case fld of
  307.                   1: begin
  308.                        read_real (r1, tot,frac, 14, 8) ;
  309.                        sum_real ;
  310.                      end ;
  311.                   2: begin
  312.                        read_real (r2, tot,frac, 14, 9) ;
  313.                        sum_real ;
  314.                      end ;
  315.                   3: begin
  316.                        read_real (r3, tot,frac, 14, 10) ;
  317.                        sum_real ;
  318.                      end ;
  319.                   4: pause ;
  320.                 end ; { CASE }
  321.         until (fld < 1) or (fld > 4 ) ;
  322.         do_scrn_ctl
  323.     end ; { proc reals }
  324.  
  325. { ==================== }
  326.  
  327. procedure booleans ;
  328.   { This procedure demonstrates reading & writing booleans }
  329.     begin
  330.         clrscr;
  331.         rvson ;
  332.         write ('SCREEN ', scrn, ' -- BOOLEANS') ;
  333.         rvsoff ;
  334.         write_str ('TYPE OF CO-BORROWER.  Type "Y" for all that apply.',3,8) ;
  335.         write_str ('"No" will be assumed if you just press <RETURN>.',3,9) ;
  336.         write_str ('1 - Another person will be jointly obligated with borrower',5,10) ;
  337.         write_str ('2 - Borrower is relying on income of another person',5,11) ;
  338.         write_str ('3 - Married, living in a community property state',5,12) ;
  339.         write_bool (b1, 71, 10) ;
  340.         write_bool (b2, 71, 11) ;
  341.         write_bool (b3, 71, 12) ;
  342.         write_str ('Epimenides the Cretan says, "All Cretans are liars!"  Is he lying?',3,14) ;
  343.         write_bool (b4, 71, 14) ;
  344.         fld := 1 ;
  345.         repeat
  346.             case fld of
  347.               1: read_bool (b1, 71, 10) ;
  348.               2: read_bool (b2, 71, 11) ;
  349.               3: read_bool (b3, 71, 12) ;
  350.               4: read_bool (b4, 71, 14) ;
  351.               5: pause ;
  352.             end ; { case }
  353.         until (fld <1) or (fld > 5) ;
  354.         do_scrn_ctl
  355.     end ; { booleans }
  356.  
  357. { ==================== }
  358.  
  359. procedure final_screen ;
  360.   { The final screen -- demonstrates proc Read_YN }
  361.     var
  362.         more : boolean ;
  363.     begin
  364.         clrscr ;
  365.         write_str ('End of demonstration.',20, 10) ;
  366.         write_str ('Do it again?',20, 12) ;
  367.         read_yn (more, 34, 12) ;
  368.         if more then
  369.             scrn := 1
  370.         else
  371.             scrn := succ(scrn)
  372.     end ; { proc final_screen }
  373.  
  374. { ==================== }
  375.  
  376. begin { ----- proc io_demo ----- }
  377.     scrn := 1 ;
  378.     init_io_vars ;
  379.     repeat
  380.         case scrn of
  381.           1 : strings  ;
  382.           2 : integers ;
  383.           3 : reals ;
  384.           4 : booleans ;
  385.           5 : final_screen
  386.         end ; { case }
  387.         if scrn < 1 then
  388.               scrn := 1           { no going backward from first screen }
  389.         else if scrn > 6 then
  390.               scrn := 5           { trap ESC }
  391.     until scrn > 5 ;
  392.     fld := 1 ;                    { reset FLD for calling proc }
  393. end ; { proc io_demo }
  394.  
  395. { ------------------------------------------------------------ }
  396.  
  397. {$i datedemo.inc -- procedure date_demo }
  398.  
  399. { ------------------------------------------------------------ }
  400.  
  401. function exists (filename : str14) : boolean ;
  402.   { test to see if file exists }
  403. var
  404.     infile : file ;
  405. begin
  406.     assign (infile,filename) ;
  407.     {$i-} reset(infile) {$i+} ;
  408.     if ioresult = 0 then
  409.       begin
  410.         exists := true ;
  411.         close (infile)
  412.       end
  413.     else
  414.         exists := false
  415. end ; { function exists }
  416.  
  417. {------------------------------------------------------------- }
  418.  
  419. procedure set_colors ;
  420.  
  421. label 99 ;   { for ESC exit }
  422.  
  423. var
  424.     n,
  425.     savebgcolor,
  426.     savetxcolor : integer ;
  427.     color_ok    : boolean ;
  428.  
  429. { -------------------- }
  430.  
  431. procedure paint_color_screen ;
  432.   begin
  433.     clrscr ;
  434.     write_str ('CHANGE COLORS',34,1) ;
  435.     write_str ('Please enter your choice of colors or',22,3) ;
  436.     write_str ('press ESC to cancel.',22,4) ;
  437.     write_str ('DARK COLORS       BRIGHT COLORS',22,6) ;
  438.     write_str ('--------------    -------------------',22,7) ;
  439.     write_str ('0 - Black         8  - Dark Grey',22,8) ;
  440.     write_str ('1 - Blue          9  - Bright Blue',22,9) ;
  441.     write_str ('2 - Green         10 - Bright Green',22,10) ;
  442.     write_str ('3 - Cyan          11 - Bright Cyan',22,11) ;
  443.     write_str ('4 - Red           12 - Bright Red',22,12) ;
  444.     write_str ('5 - Magenta       13 - Bright Magenta',22,13) ;
  445.     write_str ('6 - Brown         14 - Yellow',22,14) ;
  446.     write_str ('7 - Light Grey    15 - White',22,15) ;
  447.     rvson ;
  448.     write_str ('This is reverse video',22,17) ;
  449.     rvsoff ;
  450.     emphon ;
  451.     write_str ('This is emphasized',22,18) ;
  452.     emphoff ;
  453.     write_str ('Background color (0-7):',28,20) ;
  454.     write_int (bgcolor,1,52,20) ;
  455.     write_str ('Text color (0-15):',28,21) ;
  456.     write_int (txcolor,2,51,21)
  457.   end ;
  458.  
  459. { -------------------- }
  460.  
  461. begin { proc set_colors }
  462.     paint_color_screen ;
  463.     if is_mono then
  464.       begin
  465.         show_msg ('YOU CANNOT CHANGE COLORS ON A MONOCHROME MONITOR') ;
  466.         exit
  467.       end ;
  468.  
  469.     savebgcolor := bgcolor ;                 { save entry values }
  470.     savetxcolor := txcolor ;
  471.     fld := 1 ;
  472.     repeat
  473.         case fld of
  474.           1: read_int (bgcolor,1,52,20) ;
  475.           2: read_int (txcolor,2,51,21) ;
  476.           3: begin
  477.                assigncolors ;
  478.                paint_color_screen ;
  479.                write_str ('Is this OK? (Y/N)',28,23) ;
  480.                color_ok := false ;
  481.                read_bool (color_ok,50,23) ;
  482.                if not (fld = maxint) then
  483.                    if fld > 3 then
  484.                      begin
  485.                        if color_ok then
  486.                            fld := 4       { normal exit }
  487.                        else
  488.                            fld := 1
  489.                      end ;
  490.                clrline(28,23)
  491.              end { 3 }
  492.         end ; { case }
  493.         if fld = maxint then goto 99 ;    { ESC exits }
  494.         if fld < 1 then
  495.             fld := 1
  496.         else if not (bgcolor in [0..7]) then
  497.           begin
  498.             beep ;
  499.             fld := 1
  500.           end
  501.         else if (not (txcolor in [0..15])) and (fld > 2) then
  502.           begin
  503.             beep ;
  504.             fld := 2
  505.           end
  506.         else if (fld > 4) then
  507.             fld := 3 ;
  508. 99:
  509.     until fld > 3 ;
  510.     if fld = maxint then                     { restore entry values }
  511.       begin
  512.         bgcolor := savebgcolor ;
  513.         txcolor := savetxcolor ;
  514.         assigncolors
  515.       end
  516.     else if not ((bgcolor = savebgcolor) and (txcolor = savetxcolor)) then
  517.       begin
  518.         config.bgc := bgcolor ;              { store defaults in config file }
  519.         config.txc := txcolor ;
  520.         for n := 2 to 63 do
  521.             config.cfgint[n] := 0 ;
  522.         rewrite (config_file) ;
  523.         write (config_file,config) ;
  524.         close (config_file)
  525.       end ;
  526.     fld := 1
  527.   end ; { proc set_colors }
  528.  
  529. { ------------------------------------------------------------ }
  530.  
  531. procedure initialize ;
  532.  
  533. var
  534.     dosdate : date ;
  535.  
  536. begin  { proc initialize }
  537.     assign (config_file, config_fname) ;
  538.     if (exists (config_fname)) and (not is_mono) then
  539.       begin
  540.         reset (config_file) ;
  541.         read  (config_file,config) ;
  542.         close (config_file) ;
  543.         bgcolor := config.bgc ;
  544.         txcolor := config.txc
  545.       end
  546.     else
  547.       begin
  548.         bgcolor := 0 ;
  549.         txcolor := 7
  550.       end ;
  551.     assigncolors ;
  552.     getdate(dosdate) ;
  553.     today := mk_dt_st(dosdate)
  554.   end ; { proc initialize }
  555.  
  556. { ------------------------------------------------------------ }
  557.  
  558. begin { --- program IO23DEMO --- }
  559. (*  directvideo := false { uncomment this to avoid conflicts with Fansi-Console, etc. }
  560. *)
  561.     checkbreak := false ;
  562.     initialize ;
  563.     title_screen ;
  564.     repeat
  565.         display_menu ;
  566.         repeat
  567.             fld := 1 ;
  568.             choice := 0 ;
  569.             read_int (choice,1, 31,19) ;
  570.             if fld < 1 then choice := 0 ;
  571.             if fld = maxint then
  572.               begin
  573.                 write_str (' ',31,19) ;
  574.                 write_str ('QUIT NOW? (Y/N)',26,21) ;
  575.                 read_yn (quitnow,42,21) ;
  576.                 if not quitnow then
  577.                   begin
  578.                     fld := 1 ;
  579.                     choice := 0 ;
  580.                     clrline (26,21)
  581.                   end
  582.               end ;
  583.         until (choice in [1 .. 4]) or (fld = maxint) ;
  584.         if not (fld = maxint) then
  585.             case choice of
  586.               1: display_instructions ;
  587.               2: io_demo ;
  588.               3: date_demo ;
  589.               4: set_colors
  590.             else
  591.                  beep
  592.             end  { case }
  593.     until fld = maxint ;
  594.     clrscr ;
  595.     write_str ('Thank you for trying the Reliance User Interface Demonstration',12,5) ;
  596.     write_str ('Program.  Please send me your comments and suggestions.',12,6) ;
  597.     write_str ('Bill Meacham',30,10) ;
  598.     write_str ('Reliance Software Services',24,11) ;
  599.     write_str ('1004 Elm Street',29,12) ;
  600.     write_str ('Austin, Tx  78703',28,13) ;
  601.     writeln ; writeln
  602. end.
  603.