Debian Codegraph @

setdiff.c

raw symbols SCIP
1 /*****************************************************************************
2
3 setdiff.c - Example program for the AVL-tree library.
4
5 Copyright (C) 1998 Michael H. Buselli <[email protected]>
6 Copyright (C) 2000-2002 Wessel Dankers <[email protected]>
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 *****************************************************************************/
23
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include "avl.h"
29
30 int depth(avl_node_t *n) {
31 int d;
32 for(d = 0; n; n = n->parent)
33 d++;
34 return d;
35 }
36
37 void readinto(avl_tree_t *t, char *fname) {
38 FILE *f;
39 char *s, *e;
40 int len;
41
42 f = fopen(fname, "r");
43 if(!f) {
44 perror(fname);
45 exit(1);
46 }
47
48 while((e = s = malloc(65536)) && fgets(s, 65536, f)) {
49 len = strlen(s);
50 if(s[len-1] == '\n')
51 s[len-1] = '\0';
52 else
53 len++;
54 e = s = realloc(s, len);
55 if(!s)
56 break;
57 avl_insert(t, s);
58 }
59 if(!e) {
60 perror("malloc()");
61 exit(2);
62 }
63 fclose(f);
64 }
65
66 int main(int argc, char **argv) {
67 avl_tree_t t, u;
68 avl_node_t *c;
69
70 if(argc != 3) {
71 fprintf(stderr, "Requires exactly 2 arguments.\n");
72 exit(2);
73 }
74
75 avl_init_tree(&t, (avl_compare_t)strcmp, NULL);
76 avl_init_tree(&u, (avl_compare_t)strcmp, NULL);
77
78 readinto(&t, argv[1]);
79 readinto(&u, argv[2]);
80
81 for(c = t.head; c; c = c->next)
82 if(!avl_search(&u, c->item))
83 printf("-%s\n", c->item);
84
85 for(c = u.head; c; c = c->next)
86 if(!avl_search(&t, c->item))
87 printf("+%s\n", c->item);
88
89 return 0;
90 }