home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / SmallEiffel 0.3.3 / SmallEiffel PPC / lib_std / std_file.e < prev    next >
Encoding:
Text File  |  1996-06-13  |  2.2 KB  |  89 lines  |  [TEXT/EDIT]

  1. -- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C) 
  2. -- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
  3. --
  4. deferred class STD_FILE
  5. --
  6. -- Root class of : 
  7. --   - STD_INPUT to read on the keyboard (known as `std_input').
  8. --   - STD_OUTPUT to write on the screen (known as `std_output').
  9. --   - STD_INPUT_OUTPUT to read/write on the keyboard/screen (known as `io').
  10. --   - STD_FILE_READ to read a named file on disk. 
  11. --   - STD_FILE_WRITE to write a named file on disk.
  12. --   - CURSES interactive screen/cursor handling.
  13. --   - STD_ERROR to write on the error file (default is screen).
  14. --
  15. -- Note : a common list of feature (such as `put_character',  
  16. --        `put_string', etc.) are shared by all classes so you can 
  17. --        exchanges objects.
  18. --        For example, it easy to test writing on the screen (using 
  19. --        `std_output') and then to use a named file (using 
  20. --        STD_FILE_WRITE or `connect_to').
  21. --
  22.  
  23. feature {ANY}
  24.    
  25.    path: STRING;
  26.      -- Not Void when connected to the corresponding file on the disk.
  27.    
  28.    connect_to(new_path: STRING) is
  29.       require
  30.      not is_connected;
  31.      path = Void;
  32.      not new_path.empty;
  33.       deferred
  34.       end;
  35.    
  36.    disconnect is
  37.       require
  38.      is_connected;
  39.       deferred
  40.       end;
  41.    
  42.    is_connected: BOOLEAN is
  43.       do
  44.      Result := path /= Void;
  45.       end;
  46.    
  47. feature {NONE}
  48.    --
  49.    -- NOTE: use only a few basic external C calls.
  50.    --
  51.    
  52.    mode: STRING; 
  53.  
  54.    fopen(f: STRING; m: STRING): POINTER is
  55.       require
  56.      f /= Void;
  57.      m /= Void
  58.       local
  59.      pf, pm: POINTER;
  60.       do
  61.      pf := f.to_external;
  62.      pm := m.to_external;
  63.      c_inline_c("R=(void*)fopen(((char*)_pf),((char*)_pm));");
  64.       end;
  65.    
  66.    fclose(stream_pointer : POINTER): INTEGER is
  67.       external "C"
  68.       end;
  69.  
  70.    fputc(c: CHARACTER; stream_pointer: POINTER): CHARACTER is
  71.       external "C"
  72.       end;
  73.    
  74.    fgetc(stream_pointer : POINTER): CHARACTER is
  75.      -- Result is of type CHARACTER because a int is a char !
  76.       external "C"
  77.       end;
  78.  
  79.    feof(stream_ptr: POINTER): BOOLEAN is
  80.       do
  81.      c_inline_c("R=feof((FILE*)C->_input_stream);");
  82.       end;
  83.  
  84.    fflush(stream_pointer: POINTER): INTEGER is
  85.       external "C"
  86.       end;
  87.  
  88. end -- STD_FILE
  89.