home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / INTR_DMO.ZIP / PLS-INP.INC < prev    next >
Encoding:
Text File  |  1985-10-01  |  14.4 KB  |  378 lines

  1. { CDS-INP.INC Input routines for CDS sysem. }
  2.  
  3.    procedure Display_Prompt(line    : Byte;
  4.                             prompt  : Str_10;
  5.                             msg_str : Str_80); forward;
  6.  
  7.  
  8.    procedure Read_Kbd(var inchr,inctl: Char);
  9.       var ms_reg     : RegPack;
  10.  
  11.       begin
  12.         inctl := NULL_CHR;               { Initialize inctl to NULL_CHR.  }
  13.         FillChar(ms_reg,SizeOf(ms_reg),ZERO);
  14.         with ms_reg do
  15.         begin
  16.           ax := ZERO;                    { ah = 0 for read next kbd char.   }
  17.           Intr($16,ms_reg);              { Call keyboard interrupt routine. }
  18.           inchr := Chr(al);              { Convert result to Char.          }
  19.           if (inchr = #00) then          { If function/special key pressed  }
  20.             inctl := Chr(ah)             { put scan code in inctl.          }
  21.           else                                { Otherwise trap conventional }
  22.             if (inchr in [#1..#31,DEL]) then  { control codes as scan codes.}
  23.               inctl := inchr;
  24.         end; {with}
  25.       end; { Read_Kbd }
  26.  
  27.   function Valid_Key(valid_keys: Any_Char): Char;
  28.     var inchr, inctl : Char;
  29.  
  30.      begin
  31.        repeat
  32.          Read_Kbd(inchr,inctl);        { Wait for a key to be pressed. }
  33.          if (inctl = NULL_CHR) then
  34.            begin                       { If it is not a control key    }
  35.              inchr := UpCase(inchr);   { force it to upper case and    }
  36.              Write(inchr,BS);          { display it, restoring cursor. }
  37.            end
  38.          else                          { If it is a control key then   }
  39.            inchr := inctl;             { pass it through for testing.  }
  40.          if (not (inchr in valid_keys)) then
  41.            Beep;                       { Beep if it's not valid.       }
  42.        until (inchr in valid_keys);
  43.        Valid_Key := inchr;             { Return the valid character.   }
  44.      end; { Valid_Key }
  45.  
  46.   procedure Init_Field (init_char : Char;
  47.                         var parms : Fld_Parms;
  48.                         attribute : Byte);
  49.     var  i, hold_attr : Byte;
  50.  
  51.     begin
  52.       with parms do
  53.       begin
  54.         GoTo_XY(xloc,yloc);                 { Position cursor. }
  55.         hold_attr := vid_attr; vid_attr := attribute;
  56.         Repeat_Usr_Char(init_char,fld_len); { Init field with init_char. }
  57.         GoToXY(xloc,yloc); vid_attr := hold_attr;
  58.       end;
  59.     end; { Init_Field }
  60.  
  61.   procedure Get_Field_Input(var parms    : Fld_Parms;
  62.                             var chr_set  : Printable_Char;
  63.                             var ctrl_set : Control_Char);
  64.  
  65.     var   count      : Integer;
  66.           hold_attr  : Byte;
  67.           exit,
  68.           altered    : Boolean;
  69.  
  70.     procedure Clr_Eof;
  71.       begin
  72.         GoTo_XY(parms.xloc + count,parms.yloc);
  73.         Repeat_Usr_Char(SPACE,(parms.fld_len - count));
  74.       end; { Clr_Eof }
  75.  
  76.     procedure Process_Control_Character;
  77.       var i, xpos, ypos  : Byte;
  78.  
  79.       procedure Backspace(fill: Char);
  80.  
  81.         begin
  82.           if (count > ZERO) then
  83.             begin
  84.               Write(BS,fill,BS);      { Destructive backspace to video.     }
  85.               inp_str[count] := SPACE;{ Insert space in input string.       }
  86.               count := Pred(count);   { Decrement characters entered count. }
  87.             end
  88.           else
  89.             Beep;                     { Beep if count = ZERO initially.     }
  90.         end; { Backspace }
  91.  
  92.       procedure Clear_Field;
  93.         var i : Byte;
  94.  
  95.         begin
  96.           Init_Field(SPACE,parms,parms.disp_attr); { Clear video field. }
  97.           with parms do
  98.             FillChar(inp_str,fld_len + 1,ZERO);    { Clear inp_str. }
  99.           count := ZERO;                           { Reset count to ZERO. }
  100.         end; { Clear_Field }
  101.  
  102.       begin { Process_Control_Character }
  103.         with parms do
  104.         case inctl of
  105.           BACKSP     : Backspace(SPACE);
  106.           ENTER      : exit := TRUE;
  107.           QUIT       : begin
  108.                          esc_flag := TRUE;
  109.                          exit := TRUE;
  110.                        end;
  111.           ALT_RIGHT,
  112.           CUR_RIGHT  : if count < fld_len then
  113.                          begin
  114.                            count := count + 1;
  115.                            GoToXY(WhereX + 1,WhereY);
  116.                          end
  117.                        else Beep;
  118.           ALT_LEFT,
  119.           CUR_LEFT   : if count > ZERO then
  120.                          begin
  121.                            GoToXY(WhereX - 1, WhereY); count := count - 1;
  122.                           end
  123.                        else Beep;
  124.           ALT_INS,
  125.           INS_CHAR   : begin
  126.                          Strip_Trailing(fld_len);
  127.                          Insert(SPACE,inp_str,count + 1);
  128.                          if length(inp_str) > fld_len then
  129.                             inp_str[ZERO] := chr(fld_len);
  130.                          GoTo_XY(xloc,yloc); Write_Usr_Str(inp_str);
  131.                          GoToXY(xloc + count,yloc);
  132.                        end;
  133.           ALT_DEL,
  134.           DEL_CHAR   : begin
  135.                          Strip_Trailing(fld_len);
  136.                          if (length(inp_str) > ZERO) and
  137.                             (count <= length(inp_str)) then
  138.                            begin
  139.                              Delete(inp_str,count + 1,1);
  140.                              GoTo_XY(xloc,yloc); Write_Usr_Str(inp_str);
  141.                              Write(Usr,SPACE);
  142.                              inp_str[length(inp_str) + 1] := SPACE;
  143.                              GoToXY(xloc + count,yloc);
  144.                            end;
  145.                        end;
  146.           ALT_PREV,
  147.           PREV_FLD   : begin
  148.                          Clear_Field;
  149.                          direction := DECR;
  150.                          exit := TRUE;
  151.                        end;
  152.           CLEAR_FLD  : begin
  153.                          Clear_Field;
  154.                          exit := TRUE;
  155.                        end;
  156.           MSG_SWITCH : begin
  157.                          xpos := WhereX; ypos := WhereY;
  158.                          hold_attr := vid_attr;
  159.                          vid_attr := DIM_VID;
  160.                          if msg_on then
  161.                            begin
  162.                              GoTo_XY(7,PROMPT_LINE);
  163.                              Repeat_Usr_Char(SPACE,65);
  164.                              msg_on := FALSE;
  165.                            end
  166.                          else
  167.                            begin
  168.                              GoTo_XY(7,PROMPT_LINE);
  169.                              Write_Usr_Str(fld_msg[msg_ptr]);
  170.                              msg_on := TRUE;
  171.                            end;
  172.                          GoToXY(xpos,ypos);
  173.                          vid_attr := hold_attr;
  174.                        end;
  175.           HELP       : begin
  176.                          help_flag := TRUE;
  177.                          exit := TRUE;
  178.                        end;
  179.          ACCEPT      : begin
  180.                          accepted := True;
  181.                          exit := True;
  182.                        end;
  183.              else      Beep;
  184.         end; {case}
  185.       end; { Process_Control_Character }
  186.  
  187.     procedure Accept_Valid_Character;
  188.  
  189.       begin
  190.         with parms do
  191.         begin
  192.           if (fld_type = UC_TEXT) then
  193.             inchr := UpCase(inchr);
  194.           if (inchr in chr_set) and (count < fld_len) then
  195.             begin
  196.               Write(inchr);
  197.               count := Succ(count);
  198.               inp_str[count] := inchr;
  199.               if (exit_type = AUTOMATIC) and (count = fld_len) then
  200.                 begin
  201.                   exit := TRUE; inctl := CR;
  202.                 end;
  203.               if (count = 1) and (not altered) then
  204.                 begin
  205.                   Clr_Eof;
  206.                   FillChar(inp_str,parms.fld_len,SPACE); inp_str[1] := inchr;
  207.                 end;
  208.             end
  209.           else
  210.             Beep;
  211.         end;
  212.       end; { Accept_Valid_Character }
  213.  
  214.     begin { Get_Field_Input }
  215.       count := ZERO;
  216.       esc_flag := FALSE; exit := FALSE;
  217.       direction := INCR;
  218.       TextColor(Fgnd(parms.inp_attr));
  219.       TextBackground(Bgnd(parms.inp_attr));
  220.       FillChar(inp_str,SizeOf(inp_str),SPACE); inp_str[0] := Chr(0);
  221.       if (mode = UPDATE) then
  222.         inp_str := default;
  223.       altered := FALSE;
  224.       if (msg_on and (parms.msg_ptr < 41)) then
  225.         begin
  226.           vid_attr := DIM_VID;
  227.           GoTo_XY(7,PROMPT_LINE);
  228.           Write_Usr_Str(fld_msg[parms.msg_ptr]);
  229.         end;
  230.       vid_attr := REVERSE_VID;
  231.       GoToXY(parms.xloc,parms.yloc);
  232.       repeat
  233.         Read_Kbd(inchr,inctl);
  234.         if (inctl in ctrl_set) then
  235.           Process_Control_Character
  236.         else
  237.           Accept_Valid_Character;
  238.         altered := TRUE;
  239.       until exit;
  240.       Strip_Inp_Str(parms.fld_len);
  241.       vid_attr := BRIGHT_VID;
  242.       Clr_Eof;
  243.       Norm_Video;
  244.     end; { Get_Field_Input }
  245.  
  246.   function Valid_Str(var parms: Fld_Parms): Str_80;
  247.     const ctrl_set    : Control_Char   = [CR,BS,CLEAR_FLD,QUIT,PREV_FLD,
  248.                                           ALT_PREV,CUR_LEFT,ALT_LEFT,
  249.                                           CUR_RIGHT,ALT_RIGHT,HELP,ACCEPT,
  250.                                           ALT_INS,ALT_DEL,INS_CHAR,DEL_CHAR,
  251.                                           MSG_SWITCH];
  252.  
  253.     var chr_set : Printable_Char;
  254.  
  255.     begin
  256.       Valid_Str := default;    { Returns default if no value is entered. }
  257.       case parms.fld_type of
  258.          TEXT_FLD : chr_set := [' '..'~'];
  259.          UC_TEXT  : chr_set := [SPACE,',','-'..'9','A'..'Z'];
  260.          NUMERIC  : chr_set := ['0'..'9','-','.'];
  261.          else       chr_set := [];
  262.       end; {case}
  263.       Get_Field_Input(parms,chr_set,ctrl_set);
  264.       if ((inctl = CR) and (Length(inp_str) > ZERO)) or
  265.          (inctl = CLEAR_FLD) then
  266.         Valid_Str := inp_str;
  267.     end; { Valid_Str }
  268.  
  269.   function Valid_Real(var parms   : Fld_Parms;
  270.                           point   : Byte;
  271.                           min,max : Real): Real;
  272.  
  273.     const chr_set     : Printable_Char = ['0'..'9','-','.'];
  274.           ctrl_set    : Control_Char   = [CR,BS,CLEAR_FLD,QUIT,PREV_FLD,
  275.                                           ALT_PREV,CUR_LEFT,ALT_LEFT,
  276.                                           CUR_RIGHT,ALT_RIGHT,HELP,ACCEPT,
  277.                                           ALT_INS,ALT_DEL,INS_CHAR,DEL_CHAR,
  278.                                           MSG_SWITCH];
  279.  
  280.  
  281.     var   real_val    : Real;
  282.           min_str,
  283.           max_str     : Str_20;
  284.           err_msg     : Str_80;
  285.           temp_str    : Str_255;
  286.  
  287.     begin { Valid_Real }
  288.       inp_str := default; Strip_Inp_Str(Length(inp_str));
  289.       Val(inp_str,real_val,io_status);
  290.       if io_status <> ZERO then  { If default is a bad numeric value      }
  291.         real_val := min;         { then return minimum.                   }
  292.       Valid_Real := real_val;    { Return default if no value is entered. }
  293.       Get_Field_Input(parms,chr_set,ctrl_set);
  294.       if ((inctl = CR) and (Length(inp_str) > ZERO)) or
  295.          (inctl = CLEAR_FLD) then
  296.         begin
  297.           if (inctl = CLEAR_FLD) then
  298.             inp_str := '0.00';
  299.           Val(inp_str,real_val,io_status);
  300.           if (io_status = ZERO) and
  301.              ((real_val >= min) and (real_val <= max)) then
  302.             Valid_Real := real_val
  303.           else
  304.             begin
  305.               Str(min:parms.fld_len:point,min_str); { The point parameter    }
  306.               Str(max:parms.fld_len:point,max_str); { indicates the position }
  307.               err_msg := 'Value must be from '      { of the decimal point.  }
  308.                           + min_str + ' through ' + max_str + SPACE;
  309.               Disp_Error_Msg(err_msg);
  310.               direction := ZERO;            { Force re-entry of field. }
  311.             end;
  312.         end;
  313.     end; { Valid_Real}
  314.  
  315.   function Valid_Int(var parms   : Fld_Parms;
  316.                          min,max : Integer): Integer;
  317.  
  318.     const chr_set     : Printable_Char = ['0'..'9','-'];
  319.           ctrl_set    : Control_Char   = [CR,BS,CLEAR_FLD,QUIT,PREV_FLD,
  320.                                           ALT_PREV,CUR_LEFT,ALT_LEFT,
  321.                                           CUR_RIGHT,ALT_RIGHT,HELP,ACCEPT,
  322.                                           ALT_INS,ALT_DEL,INS_CHAR,DEL_CHAR,
  323.                                           MSG_SWITCH];
  324.  
  325.     var   int_val     : Integer;
  326.           min_str,
  327.           max_str     : Str_20;
  328.           err_msg     : Str_80;
  329.  
  330.     begin { Valid_Int }
  331.       inp_str := default; Strip_Inp_Str(Length(inp_str));
  332.       Val(inp_str,int_val,io_status);
  333.       if io_status <> ZERO then { If default is a bad numeric value      }
  334.         int_val := min;         { then return minimum value.             }
  335.       Valid_Int := int_val;     { Return default if no value is entered. }
  336.       Get_Field_Input(parms,chr_set,ctrl_set);
  337.       if ((inctl = CR) and (Length(inp_str) > ZERO)) or
  338.          (inctl = CLEAR_FLD) then
  339.         begin
  340.           if (inctl = CLEAR_FLD) then
  341.             Valid_Int := ZERO
  342.           else
  343.             begin
  344.               Strip_Inp_Str(Length(inp_str));
  345.               Val(inp_str,int_val,io_status);
  346.               if (io_status = ZERO) and
  347.                  ((int_val >= min) and (int_val <= max)) then
  348.                 Valid_Int := int_val
  349.               else
  350.                 begin
  351.                   Str(min:parms.fld_len,min_str);
  352.                   Str(max:parms.fld_len,max_str);
  353.                   err_msg := 'Value must be from ' + min_str +
  354.                              ' through ' + max_str + SPACE;
  355.                   Disp_Error_Msg(err_msg);
  356.                   direction := ZERO;             { Forces re-entry of field. }
  357.                 end;
  358.             end;
  359.         end;
  360.     end; { Valid_Int }
  361.  
  362.   function Valid_Chr(var parms     : Fld_Parms;
  363.                          valid_set : Printable_Char): Char;
  364.  
  365.     const ctrl_set    : Control_Char   = [CR,BS,CLEAR_FLD,QUIT,PREV_FLD,
  366.                                           ALT_PREV,CUR_LEFT,ALT_LEFT,
  367.                                           CUR_RIGHT,ALT_RIGHT,HELP,ACCEPT,
  368.                                           ALT_INS,ALT_DEL,INS_CHAR,DEL_CHAR,
  369.                                           MSG_SWITCH];
  370.  
  371.     begin  { Valid_Chr }
  372.       Valid_Chr := default[1]; { Returns default if no value is entered. }
  373.       Get_Field_Input(parms,valid_set,ctrl_set);
  374.       if ((inctl = CR) and (Length(inp_str) > ZERO)) or
  375.          (inctl = CLEAR_FLD) then
  376.         Valid_Chr := inp_str[1]
  377.     end; { Valid_Chr }
  378.