source: CMT/v1r14p20031120/src/cmt_awk.h @ 1

Last change on this file since 1 was 1, checked in by arnault, 19 years ago

Import all tags

File size: 2.6 KB
Line 
1#ifndef __cmt_awk_h__
2#define __cmt_awk_h__
3
4#include "cmt_std.h"
5#include "cmt_string.h"
6#include "cmt_regexp.h"
7
8//------------------------------------------------
9//
10//  Emulation of the awk program.
11//
12//  The run method reads the specified file, and applies the
13// <filter> virtual method onto each selected line. It returns
14// a condition (see below)
15//
16//  o empty lines are ignored
17//  o when the optional pattern is specified, only lines matching it
18//    are considered.
19//
20//  The virtual <begin> method is applied before any filter
21//  The virtual <filter> method is applied onto each line
22//  The virtual <end> method is applied after all filters
23//
24//  The condition (one of "ok", "stopped" or "failed") will be
25//  generated if :
26//    o everything run well (ok)
27//    o the <stop> method is called (stopped)
28//    o an error occurred or the <abort> method is called (failed)
29//
30//  State variables are maintained for derived awk filters
31//
32//    m_line_number  the current line number (empty lines
33//                   are counted)
34//
35//    m_continuation_allowed when true, take into account the
36//                           trailing backslashes, so as to
37//                           first accumulate continued lines
38//                           into one
39//
40//  Derived classes:
41//  ----------------
42//
43//  FAwk : scans a file
44//
45//    State variables:
46//
47//    m_dir_name     the path of the currently read file
48//    m_file_name    the name of the currently read file
49//
50//  PAwk : execute a command and scans its output
51//
52//------------------------------------------------
53class Awk
54{
55public:
56  typedef enum {ok, stopped, failed} condition;
57  Awk ();
58  virtual ~Awk ();
59  condition run (const cmt_string& text, const cmt_string& pattern = "");
60  condition run (const cmt_string& text, const cmt_regexp& expression);
61  void stop ();
62  void abort ();
63  void allow_continuation ();
64  condition get_last_condition () const;
65
66  virtual void begin ();
67  virtual void filter (const cmt_string& line);
68  virtual void end ();
69
70  void inc_line_number ();
71 
72protected:
73  int m_line_number;
74  condition m_condition;
75  bool m_continuation_allowed;
76};
77
78class FAwk : public Awk
79{
80public:
81  condition run (const cmt_string& file_name, const cmt_string& pattern = "");
82  condition run (const cmt_string& text, const cmt_regexp& expression);
83protected:
84  cmt_string m_dir_name;
85  cmt_string m_file_name;
86};
87
88class PAwk : public Awk
89{
90public:
91  condition run (const cmt_string& command, const cmt_string& pattern = "");
92  condition run (const cmt_string& text, const cmt_regexp& expression);
93};
94
95#endif
Note: See TracBrowser for help on using the repository browser.