* sv.po, ru.po, pt_BR.po, pl.po, nl.po, ko.po, it.po, gl.po,
[findutils.git] / find / util.c
bloba830b873b73e1cc09b33187c5423e29f90a627c4
1 /* util.c -- functions for initializing new tree elements, and other things.
2 Copyright (C) 1990, 91, 92, 93, 94, 2000 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)
7 any later version.
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. */
18 #include "defs.h"
20 #if ENABLE_NLS
21 # include <libintl.h>
22 # define _(Text) gettext (Text)
23 #else
24 # define _(Text) Text
25 #endif
26 #ifdef gettext_noop
27 # define N_(String) gettext_noop (String)
28 #else
29 # define N_(String) (String)
30 #endif
33 /* Return a pointer to a new predicate structure, which has been
34 linked in as the last one in the predicates list.
36 Set `predicates' to point to the start of the predicates list.
37 Set `last_pred' to point to the new last predicate in the list.
39 Set all cells in the new structure to the default values. */
41 struct predicate *
42 get_new_pred (void)
44 register struct predicate *new_pred;
46 if (predicates == NULL)
48 predicates = (struct predicate *)
49 xmalloc (sizeof (struct predicate));
50 last_pred = predicates;
52 else
54 new_pred = (struct predicate *) xmalloc (sizeof (struct predicate));
55 last_pred->pred_next = new_pred;
56 last_pred = new_pred;
58 last_pred->pred_func = NULL;
59 #ifdef DEBUG
60 last_pred->p_name = NULL;
61 #endif /* DEBUG */
62 last_pred->p_type = NO_TYPE;
63 last_pred->p_prec = NO_PREC;
64 last_pred->side_effects = false;
65 last_pred->need_stat = true;
66 last_pred->args.str = NULL;
67 last_pred->pred_next = NULL;
68 last_pred->pred_left = NULL;
69 last_pred->pred_right = NULL;
70 return (last_pred);
73 /* Return a pointer to a new predicate, with operator check.
74 Like get_new_pred, but it checks to make sure that the previous
75 predicate is an operator. If it isn't, the AND operator is inserted. */
77 struct predicate *
78 get_new_pred_chk_op (void)
80 struct predicate *new_pred;
82 if (last_pred)
83 switch (last_pred->p_type)
85 case NO_TYPE:
86 error (1, 0, _("oops -- invalid default insertion of and!"));
87 break;
89 case PRIMARY_TYPE:
90 case CLOSE_PAREN:
91 new_pred = get_new_pred ();
92 new_pred->pred_func = pred_and;
93 #ifdef DEBUG
94 new_pred->p_name = find_pred_name (pred_and);
95 #endif /* DEBUG */
96 new_pred->p_type = BI_OP;
97 new_pred->p_prec = AND_PREC;
98 new_pred->need_stat = false;
99 new_pred->args.str = NULL;
101 default:
102 break;
104 return (get_new_pred ());
107 /* Add a primary of predicate type PRED_FUNC to the predicate input list.
109 Return a pointer to the predicate node just inserted.
111 Fills in the following cells of the new predicate node:
113 pred_func PRED_FUNC
114 args(.str) NULL
115 p_type PRIMARY_TYPE
116 p_prec NO_PREC
118 Other cells that need to be filled in are defaulted by
119 get_new_pred_chk_op, which is used to insure that the prior node is
120 either not there at all (we are the very first node) or is an
121 operator. */
123 struct predicate *
124 insert_primary (boolean (*pred_func) (/* ??? */))
126 struct predicate *new_pred;
128 new_pred = get_new_pred_chk_op ();
129 new_pred->pred_func = pred_func;
130 #ifdef DEBUG
131 new_pred->p_name = find_pred_name (pred_func);
132 #endif /* DEBUG */
133 new_pred->args.str = NULL;
134 new_pred->p_type = PRIMARY_TYPE;
135 new_pred->p_prec = NO_PREC;
136 return (new_pred);
139 void
140 usage (char *msg)
142 if (msg)
143 fprintf (stderr, "%s: %s\n", program_name, msg);
144 fprintf (stderr, _("\
145 Usage: %s [path...] [expression]\n"), program_name);
146 exit (1);