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

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr
  4. --                       http://SmallEiffel.loria.fr
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License
  11. -- for  more  details.  You  should  have  received a copy of the GNU General
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class BINARY_FILE_READ
  17.  
  18. creation connect_to
  19.  
  20. feature
  21.  
  22.    path: STRING;
  23.  
  24.    last_byte: INTEGER;
  25.  
  26. feature {NONE}
  27.  
  28.    output_stream: POINTER;
  29.  
  30.    eof_code: INTEGER is
  31.       external "SmallEiffel"
  32.       end;
  33.  
  34. feature
  35.  
  36.    connect_to(new_path: STRING) is
  37.       require
  38.          not is_connected;
  39.          not new_path.empty
  40.       do
  41.          output_stream := bfr_open(new_path.count,new_path.to_external);
  42.          if output_stream.is_not_null then
  43.             path := new_path;
  44.          end;
  45.       end;
  46.  
  47.    is_connected: BOOLEAN is
  48.       do
  49.          Result := path /= Void;
  50.       end;
  51.  
  52.    end_of_input: BOOLEAN is
  53.          -- Has end-of-input been reached ?
  54.          -- True when the last character has been read.
  55.       require
  56.          is_connected
  57.       do
  58.          Result := last_byte = eof_code;
  59.       end;
  60.  
  61.    read_byte is
  62.       require
  63.          is_connected;
  64.          not end_of_input
  65.       do
  66.          last_byte := fgetc(output_stream);
  67.       end;
  68.  
  69.    disconnect is
  70.       require
  71.          is_connected
  72.       do
  73.          c_inline_c("fclose(C->_output_stream);");
  74.          path := Void;
  75.       end;
  76.  
  77. feature {NONE}
  78.  
  79.    fgetc(stream_pointer: POINTER): INTEGER is
  80.       external "C_InlineWithoutCurrent"
  81.       end;
  82.  
  83.    bfr_open(path_count: INTEGER; path_pointer: POINTER): POINTER is
  84.       do
  85.          c_inline_c("R=fopen(a2,%"rb%");");
  86.       end;
  87.  
  88. end -- BINARY_FILE_READ
  89.  
  90.