home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_std / std_file_read_write.e < prev    next >
Text File  |  1999-06-05  |  3KB  |  126 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_FILE_READ_WRITE
  13.    --
  14.    -- Originally written by Emmanuel CECCHET --
  15.    --
  16. inherit 
  17.    INPUT_STREAM;
  18.    OUTPUT_STREAM;
  19.    
  20. creation connect_to
  21.    
  22. feature 
  23.    
  24.    path: STRING;
  25.  
  26.    last_character: CHARACTER;
  27.  
  28. feature {NONE}
  29.  
  30.    stream: POINTER;
  31.    
  32. feature
  33.  
  34.    connect_to(new_path: STRING) is
  35.       local
  36.          s, p: POINTER;
  37.          sfw: STD_FILE_WRITE;
  38.       do
  39.          if not file_exists(new_path) then
  40.             !!sfw.connect_to(new_path);
  41.             sfw.disconnect;
  42.          end;
  43.          check
  44.             file_exists(new_path)
  45.          end;
  46.          p := new_path.to_external;
  47.          c_inline_c("_s=fopen(_p,%"r+%");");
  48.          if s.is_not_null then
  49.             stream := s;
  50.             path := new_path;
  51.          end;
  52.       end;
  53.  
  54. feature
  55.  
  56.    disconnect is
  57.       require
  58.          is_connected
  59.       do
  60.          fclose(stream);
  61.          path := Void;
  62.       end;
  63.  
  64.    read_character is
  65.       do
  66.          flush_stream(stream);
  67.          last_character := read_byte(stream).to_character;
  68.          push_back_flag := false;
  69.       end;
  70.  
  71.    put_character(c: CHARACTER) is
  72.       do
  73.          flush_stream(stream);
  74.          write_byte(stream,c);
  75.       end;
  76.    
  77.    unread_character is
  78.       local
  79.          p: POINTER;
  80.          c: CHARACTER;
  81.       do
  82.          p := stream;
  83.          c := last_character;
  84.          c_inline_c("ungetc(_c,_p);");
  85.          push_back_flag := true;
  86.       end;
  87.  
  88.    end_of_input: BOOLEAN is
  89.       do
  90.          flush_stream(stream);
  91.          Result := feof(stream)
  92.       end;
  93.  
  94.    is_connected: BOOLEAN is
  95.       do
  96.          Result := path /= Void;
  97.       end;
  98.  
  99.    read_line_in(str: STRING) is
  100.       do
  101.          read_character;
  102.          if last_character /= '%N' then
  103.             from  
  104.                str.extend(last_character);
  105.             until
  106.                end_of_input or else last_character = '%N'
  107.             loop
  108.                read_character;
  109.                str.extend(last_character);
  110.             end;
  111.          end;
  112.       end;
  113.  
  114. feature {NONE}
  115.  
  116.    fclose(stream_pointer : POINTER) is
  117.       external "C_InlineWithoutCurrent"
  118.       end;
  119.  
  120.    feof(stream_ptr: POINTER): BOOLEAN is
  121.       external "SmallEiffel"
  122.       end;
  123.  
  124. end -- STD_FILE_READ_WRITE
  125.  
  126.