Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

cmt_awk.h

Go to the documentation of this file.
00001 //-----------------------------------------------------------
00002 // Copyright Christian Arnault LAL-Orsay CNRS
00003 // arnault@lal.in2p3.fr
00004 // See the complete license in cmt_license.txt "http://www.cecill.info". 
00005 //-----------------------------------------------------------
00006 
00007 #ifndef __cmt_awk_h__
00008 #define __cmt_awk_h__
00009 
00010 #include "cmt_std.h"
00011 #include "cmt_string.h"
00012 #include "cmt_regexp.h"
00013 
00014 //------------------------------------------------
00015 //
00016 //  Emulation of the awk program.
00017 //
00018 //  The run method reads the specified file, and applies the
00019 // <filter> virtual method onto each selected line. It returns
00020 // a condition (see below)
00021 //
00022 //  o empty lines are ignored
00023 //  o when the optional pattern is specified, only lines matching it
00024 //    are considered.
00025 //
00026 //  The virtual <begin> method is applied before any filter
00027 //  The virtual <filter> method is applied onto each line
00028 //  The virtual <end> method is applied after all filters
00029 //
00030 //  The condition (one of "ok", "stopped" or "failed") will be
00031 //  generated if :
00032 //    o everything run well (ok)
00033 //    o the <stop> method is called (stopped)
00034 //    o an error occurred or the <abort> method is called (failed)
00035 //
00036 //  State variables are maintained for derived awk filters
00037 //
00038 //    m_line_number  the current line number (empty lines
00039 //                   are counted)
00040 //
00041 //    m_continuation_allowed when true, take into account the
00042 //                           trailing backslashes, so as to
00043 //                           first accumulate continued lines 
00044 //                           into one
00045 //
00046 //  Derived classes:
00047 //  ----------------
00048 //
00049 //  FAwk : scans a file
00050 //
00051 //    State variables:
00052 //
00053 //    m_dir_name     the path of the currently read file
00054 //    m_file_name    the name of the currently read file
00055 //
00056 //  PAwk : execute a command and scans its output
00057 //
00058 //------------------------------------------------
00059 class Awk
00060 {
00061 public:
00062   typedef enum {ok, stopped, failed} condition;
00063   Awk ();
00064   virtual ~Awk ();
00065   condition run (const cmt_string& text, const cmt_string& pattern = "");
00066   condition run (const cmt_string& text, const cmt_regexp& expression);
00067   void stop ();
00068   void abort ();
00069   void allow_continuation ();
00070   condition get_last_condition () const;
00071 
00072   virtual void begin ();
00073   virtual void filter (const cmt_string& line);
00074   virtual void end ();
00075 
00076   void inc_line_number ();
00077   
00078 protected:
00079   int m_line_number;
00080   condition m_condition;
00081   bool m_continuation_allowed;
00082 };
00083 
00084 class FAwk : public Awk
00085 {
00086 public:
00087   condition run (const cmt_string& file_name, const cmt_string& pattern = "");
00088   condition run (const cmt_string& text, const cmt_regexp& expression);
00089 protected:
00090   cmt_string m_dir_name;
00091   cmt_string m_file_name;
00092 };
00093 
00094 class PAwk : public Awk
00095 {
00096 public:
00097   condition run (const cmt_string& command, const cmt_string& pattern = "");
00098   condition run (const cmt_string& text, const cmt_regexp& expression);
00099 };
00100 
00105 class PathScanner
00106 {
00107 public:
00108   class actor
00109   {
00110   public:
00111     virtual void run (const cmt_string& package,
00112                       const cmt_string& version,
00113                       const cmt_string& path)
00114     {
00115     }
00116   };
00117   
00118   PathScanner ();
00119   bool scan_path (const cmt_string& path, actor& a);
00120   bool scan_package (const cmt_string& path, const cmt_string& package);
00121   
00122 private:
00123   void scan_path (const cmt_string& path, int level, actor& a);
00124   
00125   bool _running;
00126   int _level;
00127 };
00128 
00129 
00130 #endif

Generated on Mon May 2 10:25:04 2005 for CMT by doxygen 1.3.5