home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / echo.e < prev    next >
Text File  |  1999-06-05  |  6KB  |  219 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 ECHO
  17.    --
  18.    -- Unique Global Object in charge of ECHOing some information
  19.    -- messages during compilation for example.
  20.    -- This object is used to implement the flag "-verbose".
  21.    --
  22.    --
  23.  
  24. inherit GLOBALS;
  25.  
  26. creation make
  27.  
  28. feature
  29.  
  30.    verbose: BOOLEAN;
  31.          -- Is `echo' verbose (default is false).
  32.  
  33. feature
  34.  
  35.    make is
  36.       do
  37.       end;
  38.  
  39. feature  -- To echo some additional information (echo is only done
  40.          -- when `verbose' is true).
  41.  
  42.    put_string(msg: STRING) is
  43.       do
  44.          if verbose then
  45.             std_output.put_string(msg);
  46.             std_output.flush;
  47.          end;
  48.       end;
  49.  
  50.    put_character(c: CHARACTER) is
  51.       do
  52.          if verbose then
  53.             std_output.put_character(c);
  54.             std_output.flush;
  55.          end;
  56.       end;
  57.  
  58.    put_new_line is
  59.       do
  60.          if verbose then
  61.             std_output.put_new_line;
  62.          end;
  63.       end;
  64.  
  65.    put_integer(i: INTEGER) is
  66.       do
  67.          if verbose then
  68.             std_output.put_integer(i);
  69.             std_output.flush;
  70.          end;
  71.       end;
  72.  
  73.    put_double_format(d: DOUBLE; f: INTEGER) is
  74.       do
  75.          if verbose then
  76.             std_output.put_double_format(d,f);
  77.             std_output.flush;
  78.          end;
  79.       end;
  80.  
  81.    file_removing(path: STRING) is
  82.          -- If `path' is an existing file, echo a message on `std_output'
  83.          -- while removing the file.
  84.          -- Otherwise, do nothing.
  85.       require
  86.          path /= Void
  87.       do
  88.          if file_exists(path) then
  89.             put_string("Removing %"");
  90.             put_string(path);
  91.             put_string(fz_b0);
  92.             remove_file(path);
  93.          end;
  94.       ensure
  95.          not file_exists(path)
  96.       end;
  97.  
  98.    file_renaming(old_path, new_path: STRING) is
  99.       require
  100.          old_path /= Void;
  101.          new_path /= Void
  102.       do
  103.          put_string("Renaming %"");
  104.          put_string(old_path);
  105.          put_string("%" as %"");
  106.          put_string(new_path);
  107.          put_string(fz_b0);
  108.          rename_file(old_path,new_path);
  109.       end;
  110.  
  111.    sfr_connect(sfr: STD_FILE_READ; path: STRING) is
  112.       require
  113.          not sfr.is_connected;
  114.          path /= Void
  115.       do
  116.          put_string("Trying to read file %"");
  117.          put_string(path);
  118.          put_string(fz_b0);
  119.          sfr.connect_to(path);
  120.       end;
  121.  
  122.    sfr_connect_or_exit(sfr: STD_FILE_READ; path: STRING) is
  123.       require
  124.          not sfr.is_connected;
  125.          path /= Void
  126.       do
  127.          sfr_connect(sfr,path);
  128.          if not sfr.is_connected then
  129.             w_put_string(fz_01);
  130.             w_put_string(path);
  131.             w_put_string("%" not found.%N");
  132.             die_with_code(exit_failure_code);
  133.          end;
  134.       ensure
  135.          sfr.is_connected
  136.       end;
  137.  
  138.    read_word_in(sfr: STD_FILE_READ): STRING is
  139.       require
  140.          sfr.is_connected
  141.       do
  142.          put_string("Reading one word in %"");
  143.          put_string(sfr.path);
  144.          put_string(fz_b0);
  145.          if sfr.end_of_input then
  146.             w_put_string("Unexpected end_of_input while reading %"");
  147.             w_put_string(sfr.path);
  148.             w_put_string(fz_b0);
  149.             die_with_code(exit_failure_code);
  150.          else
  151.             sfr.read_word;
  152.             Result := sfr.last_string.twin;
  153.          end;
  154.       ensure
  155.          sfr.is_connected
  156.       end;
  157.  
  158.    call_system(cmd: STRING) is
  159.       require
  160.          cmd.count > 0
  161.       do
  162.          put_string("System call %"");
  163.          put_string(cmd);
  164.          put_string(fz_b0);
  165.          system(cmd);
  166.       end;
  167.  
  168.    print_count(msg: STRING; count: INTEGER) is
  169.       require
  170.          count >= 0;
  171.       do
  172.          if verbose then
  173.             if count > 0 then
  174.                put_string("Total ");
  175.                put_string(msg);
  176.                if count > 1 then
  177.                   put_character('s');
  178.                end;
  179.                put_string(": ");
  180.                put_integer(count);
  181.                put_string(fz_b6);
  182.             else
  183.                put_string("No ");
  184.                put_string(msg);
  185.                put_string(fz_b6);
  186.             end;
  187.          end;
  188.       end;
  189.  
  190. feature  -- To echo some warning or some problem (echo is done whathever
  191.          -- the value of `verbose').
  192.  
  193.    w_put_string(msg: STRING) is
  194.       do
  195.          std_error.put_string(msg);
  196.          std_error.flush;
  197.       end;
  198.  
  199.    w_put_character(c: CHARACTER) is
  200.       do
  201.          std_error.put_character(c);
  202.          std_error.flush;
  203.       end;
  204.  
  205.    w_put_integer(i: INTEGER) is
  206.       do
  207.          std_error.put_integer(i);
  208.          std_error.flush;
  209.       end;
  210.  
  211. feature {COMMAND_FLAGS}
  212.  
  213.    set_verbose is
  214.       do
  215.          verbose := true;
  216.       end;
  217.  
  218. end -- ECHO
  219.