1 /* util.c -- functions for initializing new tree elements, and other things.
2 Copyright (C) 1990, 91, 92, 93, 94, 2000, 2003, 2004 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25 # define _(Text) gettext (Text)
30 # define N_(String) gettext_noop (String)
32 /* See locate.c for explanation as to why not use (String) */
33 # define N_(String) String
39 /* Return a pointer to a new predicate structure, which has been
40 linked in as the last one in the predicates list.
42 Set `predicates' to point to the start of the predicates list.
43 Set `last_pred' to point to the new last predicate in the list.
45 Set all cells in the new structure to the default values. */
48 get_new_pred (const struct parser_table
*entry
)
50 register struct predicate
*new_pred
;
53 /* Options should not be turned into predicates. */
54 assert(entry
->type
!= ARG_OPTION
);
55 assert(entry
->type
!= ARG_POSITIONAL_OPTION
);
57 if (predicates
== NULL
)
59 predicates
= (struct predicate
*)
60 xmalloc (sizeof (struct predicate
));
61 last_pred
= predicates
;
65 new_pred
= (struct predicate
*) xmalloc (sizeof (struct predicate
));
66 last_pred
->pred_next
= new_pred
;
69 last_pred
->parser_entry
= entry
;
70 last_pred
->pred_func
= NULL
;
72 last_pred
->p_name
= NULL
;
74 last_pred
->p_type
= NO_TYPE
;
75 last_pred
->p_prec
= NO_PREC
;
76 last_pred
->side_effects
= false;
77 last_pred
->no_default_print
= false;
78 last_pred
->need_stat
= true;
79 last_pred
->need_type
= true;
80 last_pred
->args
.str
= NULL
;
81 last_pred
->pred_next
= NULL
;
82 last_pred
->pred_left
= NULL
;
83 last_pred
->pred_right
= NULL
;
87 /* Return a pointer to a new predicate, with operator check.
88 Like get_new_pred, but it checks to make sure that the previous
89 predicate is an operator. If it isn't, the AND operator is inserted. */
92 get_new_pred_chk_op (const struct parser_table
*entry
)
94 struct predicate
*new_pred
;
95 static const struct parser_table
*entry_and
= NULL
;
97 /* Locate the entry in the parser table for the "and" operator */
98 if (NULL
== entry_and
)
99 entry_and
= find_parser("and");
101 /* Check that it's actually there. If not, that is a bug.*/
102 assert(entry_and
!= NULL
);
105 switch (last_pred
->p_type
)
108 error (1, 0, _("oops -- invalid default insertion of and!"));
113 /* We need to interpose the and operator. */
114 new_pred
= get_new_pred (entry_and
);
115 new_pred
->pred_func
= pred_and
;
117 new_pred
->p_name
= find_pred_name (pred_and
);
119 new_pred
->p_type
= BI_OP
;
120 new_pred
->p_prec
= AND_PREC
;
121 new_pred
->need_stat
= false;
122 new_pred
->need_type
= false;
123 new_pred
->args
.str
= NULL
;
124 new_pred
->side_effects
= false;
125 new_pred
->no_default_print
= false;
132 new_pred
= get_new_pred (entry
);
133 new_pred
->parser_entry
= entry
;
137 /* Add a primary of predicate type PRED_FUNC (described by ENTRY) to the predicate input list.
139 Return a pointer to the predicate node just inserted.
141 Fills in the following cells of the new predicate node:
148 Other cells that need to be filled in are defaulted by
149 get_new_pred_chk_op, which is used to insure that the prior node is
150 either not there at all (we are the very first node) or is an
154 insert_primary_withpred (const struct parser_table
*entry
, PRED_FUNC pred_func
)
156 struct predicate
*new_pred
;
158 new_pred
= get_new_pred_chk_op (entry
);
159 new_pred
->pred_func
= pred_func
;
161 new_pred
->p_name
= entry
->parser_name
;
163 new_pred
->args
.str
= NULL
;
164 new_pred
->p_type
= PRIMARY_TYPE
;
165 new_pred
->p_prec
= NO_PREC
;
169 /* Add a primary described by ENTRY to the predicate input list.
171 Return a pointer to the predicate node just inserted.
173 Fills in the following cells of the new predicate node:
180 Other cells that need to be filled in are defaulted by
181 get_new_pred_chk_op, which is used to insure that the prior node is
182 either not there at all (we are the very first node) or is an
185 insert_primary (const struct parser_table
*entry
)
187 assert(entry
->pred_func
!= NULL
);
188 return insert_primary_withpred(entry
, entry
->pred_func
);
197 fprintf (stderr
, "%s: %s\n", program_name
, msg
);
198 fprintf (stderr
, _("\
199 Usage: %s [-H] [-L] [-P] [path...] [expression]\n"), program_name
);