1 /* util.c -- functions for initializing new tree elements, and other things.
2 Copyright (C) 1990, 91, 92, 93, 94 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
19 #include <sys/types.h>
24 /* Return the last component of pathname FNAME, with leading slashes
25 compressed into one slash. */
34 /* For "/", "//", etc., return "/". */
35 for (p
= fname
; *p
== '/'; ++p
)
39 p
= strrchr (fname
, '/');
40 return (p
== NULL
? fname
: p
+ 1);
42 #endif /* not __linux__ */
44 /* Return a pointer to a new predicate structure, which has been
45 linked in as the last one in the predicates list.
47 Set `predicates' to point to the start of the predicates list.
48 Set `last_pred' to point to the new last predicate in the list.
50 Set all cells in the new structure to the default values. */
55 register struct predicate
*new_pred
;
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
->pred_func
= NULL
;
71 last_pred
->p_name
= NULL
;
73 last_pred
->p_type
= NO_TYPE
;
74 last_pred
->p_prec
= NO_PREC
;
75 last_pred
->side_effects
= false;
76 last_pred
->need_stat
= true;
77 last_pred
->args
.str
= NULL
;
78 last_pred
->pred_next
= NULL
;
79 last_pred
->pred_left
= NULL
;
80 last_pred
->pred_right
= NULL
;
84 /* Return a pointer to a new predicate, with operator check.
85 Like get_new_pred, but it checks to make sure that the previous
86 predicate is an operator. If it isn't, the AND operator is inserted. */
89 get_new_pred_chk_op ()
91 struct predicate
*new_pred
;
94 switch (last_pred
->p_type
)
97 error (1, 0, "oops -- invalid default insertion of and!");
102 new_pred
= get_new_pred ();
103 new_pred
->pred_func
= pred_and
;
105 new_pred
->p_name
= find_pred_name (pred_and
);
107 new_pred
->p_type
= BI_OP
;
108 new_pred
->p_prec
= AND_PREC
;
109 new_pred
->need_stat
= false;
110 new_pred
->args
.str
= NULL
;
115 return (get_new_pred ());
118 /* Add a primary of predicate type PRED_FUNC to the predicate input list.
120 Return a pointer to the predicate node just inserted.
122 Fills in the following cells of the new predicate node:
129 Other cells that need to be filled in are defaulted by
130 get_new_pred_chk_op, which is used to insure that the prior node is
131 either not there at all (we are the very first node) or is an
135 insert_primary (pred_func
)
136 boolean (*pred_func
) ();
138 struct predicate
*new_pred
;
140 new_pred
= get_new_pred_chk_op ();
141 new_pred
->pred_func
= pred_func
;
143 new_pred
->p_name
= find_pred_name (pred_func
);
145 new_pred
->args
.str
= NULL
;
146 new_pred
->p_type
= PRIMARY_TYPE
;
147 new_pred
->p_prec
= NO_PREC
;
156 fprintf (stderr
, "%s: %s\n", program_name
, msg
);
158 Usage: %s [path...] [expression]\n", program_name
);