7c36bb7dc4d39e5fa4b1b655fcdaf9003db85c94
3 * $Id: set.c,v 1.1 1997/07/21 13:47:44 mdw Exp $
5 * Management of sets (for the use of the class expression handler)
10 /*----- Licencing 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
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.1 1997/07/21 13:47:44 mdw
37 /*----- Header files ------------------------------------------------------*/
39 /* --- ANSI headers --- */
45 /* --- Local headers --- */
51 /*----- Main code ---------------------------------------------------------*/
53 /* --- @set_subtract@ --- *
55 * Arguments: @sym_table *a@ = pointer to table @A@
56 * @sym_table *b@ = pointer to table @B@
58 * Returns: A symbol table containing all the elements in @A@ which don't
61 * Use: Subtracts a symbol table from another symbol table. Assumes
62 * that there's no data following the actual @sym_base@ block
63 * for each item in the table.
66 sym_table
*set_subtract(sym_table
*a
, sym_table
*b
)
68 sym_table
*c
= xmalloc(sizeof(*c
));
74 for (sym_createIter(&i
, a
); (s
= sym_next(&i
)) != 0; ) {
75 if (!sym_find(b
, s
->name
, s
->len
, 0, &f
))
76 sym_find(c
, s
->name
, s
->len
, sizeof(sym_base
), 0);
82 /* --- @set_intersect@ --- *
84 * Arguments: @sym_table *a@ = pointer to table @A@
85 * @sym_table *b@ = pointer to table @B@
87 * Returns: A symbol table containing all the elements in @A@ which also
90 * Use: Constructs the intersection of two symbol tables. Assumes
91 * that there's no data following the actual @sym_base@ block
92 * for each item in the table.
95 sym_table
*set_intersect(sym_table
*a
, sym_table
*b
)
97 sym_table
*c
= xmalloc(sizeof(*c
));
103 for (sym_createIter(&i
, a
); (s
= sym_next(&i
)) != 0; ) {
104 if (sym_find(b
, s
->name
, s
->len
, 0, &f
))
105 sym_find(c
, s
->name
, s
->len
, sizeof(sym_base
), 0);
111 /* --- @set_union@ --- *
113 * Arguments: @sym_table *a@ = pointer to table @A@
114 * @sym_table *b@ = pointer to table @B@
116 * Returns: A symbol table containing all the elements in @A@ and those
119 * Use: Constructs the union of two symbol tables. Assumes that
120 * there's no data following the actual @sym_base@ block for
121 * each item in the table.
124 sym_table
*set_union(sym_table
*a
, sym_table
*b
)
126 sym_table
*c
= xmalloc(sizeof(*c
));
131 for (sym_createIter(&i
, a
); (s
= sym_next(&i
)) != 0; )
132 sym_find(c
, s
->name
, s
->len
, sizeof(sym_base
), 0);
134 for (sym_createIter(&i
, b
); (s
= sym_next(&i
)) != 0; )
135 sym_find(c
, s
->name
, s
->len
, sizeof(sym_base
), 0);
140 /* --- @set_copy@ --- *
142 * Arguments: @sym_table *a@ = pointer to table
144 * Returns: A copy of the symbol table.
146 * Use: Copies a symbol table. Same assumptions again...
149 sym_table
*set_copy(sym_table
*a
)
151 sym_table
*c
= xmalloc(sizeof(*c
));
155 for (sym_createIter(&i
, a
); (s
= sym_next(&i
)) != 0; )
156 sym_find(c
, s
->name
, s
->len
, sizeof(sym_base
), 0);
161 /*----- That's all, folks -------------------------------------------------*/