home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_std / std_input.e < prev    next >
Text File  |  1999-06-05  |  2KB  |  98 lines

  1. -- This file is  free  software, which  comes  along  with  SmallEiffel. This
  2. -- software  is  distributed  in the hope that it will be useful, but WITHOUT 
  3. -- ANY  WARRANTY;  without  even  the  implied warranty of MERCHANTABILITY or
  4. -- FITNESS  FOR A PARTICULAR PURPOSE. You can modify it as you want, provided
  5. -- this header is kept unaltered, and a notification of the changes is added.
  6. -- You  are  allowed  to  redistribute  it and sell it, alone or as a part of 
  7. -- another product.
  8. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  9. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  10. --                       http://SmallEiffel.loria.fr
  11. --
  12. class STD_INPUT
  13. --
  14. -- To use the standard input file. As for UNIX, the default standard 
  15. -- input is the keyboard.
  16. --
  17. -- Notes : - the predefined `std_input' should be use to have only 
  18. --         one instance of the class STD_INPUT. 
  19. --         - to do reading or writing at the same time on the screen, 
  20. --         see STD_INPUT_OUTPUT,
  21. --         - to handle cursor of the screen, see CURSES.
  22. --
  23.    
  24. inherit INPUT_STREAM;
  25.    
  26. creation make
  27.  
  28. feature {NONE}
  29.  
  30.    memory: INTEGER;
  31.          -- Memory of the last available user's value.
  32.  
  33. feature
  34.  
  35.    is_connected: BOOLEAN is true;
  36.  
  37. feature 
  38.    
  39.    make is
  40.       do
  41.       end;
  42.    
  43. feature
  44.  
  45.    read_character is
  46.       do
  47.          if push_back_flag then
  48.             push_back_flag := false;
  49.          else
  50.             memory := read_byte(stdin);
  51.          end;
  52.       end;
  53.  
  54.    unread_character is
  55.       do
  56.          push_back_flag := true;
  57.       end;
  58.  
  59.    last_character: CHARACTER is
  60.       do
  61.          Result := memory.to_character;
  62.       end;
  63.  
  64.    end_of_input: BOOLEAN is
  65.       do
  66.          if not push_back_flag then
  67.             Result := memory = eof_code;
  68.          end;
  69.       end;
  70.  
  71.    read_line_in(str: STRING) is
  72.       local
  73.          mem: INTEGER;
  74.       do
  75.          read_character;
  76.          if last_character /= '%N' then
  77.             from  
  78.                str.extend(memory.to_character);
  79.                mem := read_byte(stdin);
  80.             until
  81.                mem = eof_code or else mem = ('%N').code
  82.             loop
  83.                str.extend(mem.to_character);
  84.                mem := read_byte(stdin);
  85.             end;
  86.             memory := mem;
  87.          end;
  88.       end;
  89.  
  90. feature {NONE} 
  91.    
  92.    stdin: POINTER is
  93.       external "SmallEiffel"
  94.       end;
  95.  
  96. end -- STD_INPUT
  97.  
  98.