3 * $Id: set.c,v 1.2 1997/08/04 10:24:25 mdw Exp $
5 * Management of sets (for the use of the class expression handler)
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of `become'
14 * `Become' is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * `Become' is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with `become'; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.2 1997/08/04 10:24:25 mdw
33 * Sources placed under CVS control.
35 * Revision 1.1 1997/07/21 13:47:44 mdw
40 /*----- Header files ------------------------------------------------------*/
42 /* --- ANSI headers --- */
48 /* --- Local headers --- */
54 /*----- Main code ---------------------------------------------------------*/
56 /* --- @set_subtract@ --- *
58 * Arguments: @sym_table *a@ = pointer to table @A@
59 * @sym_table *b@ = pointer to table @B@
61 * Returns: A symbol table containing all the elements in @A@ which don't
64 * Use: Subtracts a symbol table from another symbol table. Assumes
65 * that there's no data following the actual @sym_base@ block
66 * for each item in the table.
69 sym_table *set_subtract(sym_table *a, sym_table *b)
71 sym_table *c = xmalloc(sizeof(*c));
77 for (sym_createIter(&i, a); (s = sym_next(&i)) != 0; ) {
78 if (!sym_find(b, s->name, s->len, 0, &f))
79 sym_find(c, s->name, s->len, sizeof(sym_base), 0);
85 /* --- @set_intersect@ --- *
87 * Arguments: @sym_table *a@ = pointer to table @A@
88 * @sym_table *b@ = pointer to table @B@
90 * Returns: A symbol table containing all the elements in @A@ which also
93 * Use: Constructs the intersection of two symbol tables. Assumes
94 * that there's no data following the actual @sym_base@ block
95 * for each item in the table.
98 sym_table *set_intersect(sym_table *a, sym_table *b)
100 sym_table *c = xmalloc(sizeof(*c));
106 for (sym_createIter(&i, a); (s = sym_next(&i)) != 0; ) {
107 if (sym_find(b, s->name, s->len, 0, &f))
108 sym_find(c, s->name, s->len, sizeof(sym_base), 0);
114 /* --- @set_union@ --- *
116 * Arguments: @sym_table *a@ = pointer to table @A@
117 * @sym_table *b@ = pointer to table @B@
119 * Returns: A symbol table containing all the elements in @A@ and those
122 * Use: Constructs the union of two symbol tables. Assumes that
123 * there's no data following the actual @sym_base@ block for
124 * each item in the table.
127 sym_table *set_union(sym_table *a, sym_table *b)
129 sym_table *c = xmalloc(sizeof(*c));
134 for (sym_createIter(&i, a); (s = sym_next(&i)) != 0; )
135 sym_find(c, s->name, s->len, sizeof(sym_base), 0);
137 for (sym_createIter(&i, b); (s = sym_next(&i)) != 0; )
138 sym_find(c, s->name, s->len, sizeof(sym_base), 0);
143 /* --- @set_copy@ --- *
145 * Arguments: @sym_table *a@ = pointer to table
147 * Returns: A copy of the symbol table.
149 * Use: Copies a symbol table. Same assumptions again...
152 sym_table *set_copy(sym_table *a)
154 sym_table *c = xmalloc(sizeof(*c));
158 for (sym_createIter(&i, a); (s = sym_next(&i)) != 0; )
159 sym_find(c, s->name, s->len, sizeof(sym_base), 0);
164 /*----- That's all, folks -------------------------------------------------*/