Main Page ? Class Hierarchy ? Compound List ? File List ? Compound Members ? File Members ?

cmt_awk.h

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

Generated on Thu Jul 1 15:25:30 2004 for CMT by 1.2.18