1 #ifndef recipenode_h
2 #define	recipenode_h
3 
4 static const char recipenode_h_rcsid[]="$Id: recipenode.h,v 1.9 2004/01/15 03:12:13 mrsam Exp $";
5 
6 #include	"buffer.h"
7 class Recipe;
8 
9 /////////////////////////////////////////////////////////////////////////////
10 //
11 // RecipeNode class - one "clause" in a recipe file, such as an "if"
12 // statement, or an expression.
13 //
14 // All RecipeNodes which represent a single recipe file are linked in a
15 // doubly-linked list anchored in their Recipe object.
16 //
17 // The RecipeNodes are arranged in a hierarchical format:
18 //
19 // prevNode/nextNode is the doubly-linked list anchored in the Recipe
20 // object.  All RecipeNodes dynamically allocated by the Recipe class
21 // are on this list.
22 //
23 // firstChild/lastChild is a doubly-linked list of RecipeNodes that are
24 // considered descendants of this node.  For example, a node that
25 // represents an "||" (logical or operation) will have two descendants,
26 // the left side, and the right side, of the expression.  This RecipeNode
27 // itself is on the descendant list of its parent.  All descendants of
28 // a RecipeNode have the parentNode pointer point to this RecipeNode.
29 // prevSibling/nextSibling is a doubly-linked list of all descendants of
30 // a single RecipeNode.
31 //
32 // This provides a generic linkage that is used to built a hierarchy that
33 // represents the logical layout of a recipe file.  The remaining fields
34 // store information pertaining to each individual kind of a RecipeNode
35 // object.  The nodeType field designates what kind of a RecipeNode object
36 // this is, which remaining fields are used depends on the nodeType field.
37 //
38 // The Recipe class calls the Evaluate() function of the first RecipeNode
39 // that represents that entire recipe file.  The set of Evaluate() functions
40 // are logically involved to actually execute the given recipe file.
41 //
42 /////////////////////////////////////////////////////////////////////////////
43 
44 class RecipeNode {
45 	RecipeNode *prevNode, *nextNode;	// List of all nodes in
46 						// this recipe.
47 
48 	RecipeNode *parentNode;			// Parent of this node.
49 	RecipeNode *prevSibling, *nextSibling;	// Siblings of this node.
50 	RecipeNode *firstChild, *lastChild;	// Its own children.
51 
52 	Buffer	str;
53 	int	linenum;
54 
55 	void dollarexpand(Recipe &, Buffer &);
56 	int dollarexpand(Recipe &, Buffer &, int);
57 
58 public:
59 	friend class Recipe;
60 
61 	enum RecipeNodeType {
62 		statementlist,
63 		assignment,
64 		qstring,
65 		sqstring,
66 		btstring,
67 		regexpr,
68 		add,
69 		subtract,
70 		multiply,
71 		divide,
72 		lessthan,
73 		lessthanoreq,
74 		greaterthan,
75 		greaterthanoreq,
76 		equal,
77 		notequal,
78 		concat,
79 		logicalor,
80 		logicaland,
81 		bitwiseor,
82 		bitwiseand,
83 		logicalnot,
84 		bitwisenot,
85 		strlessthan,
86 		strlessthanoreq,
87 		strgreaterthan,
88 		strgreaterthanoreq,
89 		strequal,
90 		strnotequal,
91 		strlength,
92 		strsubstr,
93 		strregexp,
94 		ifelse,
95 		whileloop,
96 		deliver,
97 		delivercc,
98 		exception,
99 		echo,
100 		xfilter,
101 		dotlock,
102 		flock,
103 		logfile,
104 		log,
105 		include,
106 		exit,
107 		foreach,
108 		getaddr,
109 		lookup,
110 		escape,
111 		to_lower,
112 		to_upper,
113 		hasaddr,
114 		gdbmopen,
115 		gdbmclose,
116 		gdbmfetch,
117 		gdbmstore,
118 		timetoken,
119 		importtoken,
120 		unset
121 		} nodeType;
122 
123 	RecipeNode(RecipeNodeType);
~RecipeNode()124 	~RecipeNode()					{}
125 	void	Evaluate(Recipe &, Buffer &);
126 private:
127 	void	AppendSibling(RecipeNode *);
128 	void	EvaluateString(Recipe &r, Buffer &b);
129 
130 	void EvaluateStrRegExp(Recipe &, Buffer &, Buffer *);
131 	void EvaluateRegExp(Recipe &, Buffer &, Buffer *);
132 static	void	ParseRegExp(const Buffer &, Buffer &, Buffer &);
133 static	int	boolean(const Buffer &);
134 
135 	void rfc822getaddr(Buffer &);
136 	int rfc822hasaddr(Buffer &);
137 	int rfc822hasaddr(const char *, Buffer &);
138 	void SpecialEscape(Buffer &);
139 	int dolookup(Buffer &, Buffer &, Buffer &);
140 	} ;
141 #endif
142