Skip to content

Commit 8a0c5ec

Browse files
committed
break up complement.c into bfun.c, bfun.h, and main.c
1 parent 32939eb commit 8a0c5ec

File tree

3 files changed

+87
-85
lines changed

3 files changed

+87
-85
lines changed

complement.c renamed to bfun.c

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,4 @@
1-
#include <stdio.h>
2-
#include <stdlib.h>
3-
#include <stdbool.h>
4-
#include <limits.h>
5-
6-
#include "utils.h"
7-
#include "cubelist.h"
8-
9-
10-
// bfun* constructors
11-
bfun* bf_new_var (int v);
12-
bfun* bool_to_bf (bfun* b, bool bl);
13-
bfun* empty_bf(bfun* b);
14-
15-
// single bfun* functions
16-
bfun* complement(bfun* b);
17-
bfun* try_simplify(bfun* b);
18-
bool has_all_dc(bfun* b);
19-
20-
// combining bfun*s
21-
void append_cubes(bfun* b, bfun* g);
22-
bfun* or(bfun* b, bfun* g);
23-
24-
// bfun*s & variables
25-
void and_var(bfun* b, int var);
26-
int best_split(bfun* b);
27-
bfun* pos_co(bfun* b, int x);
28-
bfun* neg_co(bfun* b, int x);
29-
30-
31-
int main(int argc, char* argv[]) {
32-
char* filename;
33-
if (argc > 1) filename = argv[1];
34-
else filename = "foo";
35-
char* out_file = "out.txt";
36-
37-
int vs = 4;
38-
39-
/*
40-
cube* plain = new_cube(vs);
41-
cube* one_false = new_cube(vs);
42-
set_false(one_false, 1);
43-
*/
44-
cube* one_true = new_cube(vs);
45-
set_true(one_true, 1);
46-
cube* one_each = new_cube(vs);
47-
set_false(one_each, 1);
48-
set_true(one_each, 2);
49-
50-
cube_list* test1 = new_cube_list(vs);
51-
add_cube(test1, one_each);
52-
add_cube(test1, one_true);
53-
54-
printf("\nComplementing...\n");
55-
print_bfun(test1);
56-
57-
bfun* result = complement(test1);
58-
printf("\n************************************\n");
59-
printf("\nResult is:\n");
60-
print_bfun(result);
61-
printf("\n************************************\n");
62-
63-
del_bfun(test1);
64-
del_bfun(result);
65-
/*
66-
del_cube(plain, vs);
67-
del_cube(one_true, vs);
68-
del_cube(one_false, vs);
69-
del_cube(one_each, vs);
70-
*/
71-
72-
bfun* b = read_file(filename);
73-
bfun* cb = complement(b);
74-
75-
printf("\n************************************\n");
76-
printf("\nResult is:\n");
77-
print_bfun(cb);
78-
printf("\n************************************\n");
79-
80-
write_file(out_file, cb);
81-
82-
del_bfun(b);
83-
del_bfun(cb);
84-
}
85-
1+
#include "bfun.h"
862

873
bfun* complement (bfun* b_initial) {
884
// does not free argument.

bfun.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef _BFUN_H
2+
#define _BFUN_H
3+
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
#include <stdbool.h>
7+
#include <limits.h>
8+
9+
#include "utils.h"
10+
#include "cubelist.h"
11+
12+
13+
// single bfun* functions
14+
bfun* complement(bfun* b);
15+
bfun* try_simplify(bfun* b);
16+
bool has_all_dc(bfun* b);
17+
18+
// combining bfun*s
19+
void append_cubes(bfun* b, bfun* g);
20+
bfun* or(bfun* b, bfun* g);
21+
22+
// bfun*s & variables
23+
void and_var(bfun* b, int var);
24+
int best_split(bfun* b);
25+
bfun* pos_co(bfun* b, int x);
26+
bfun* neg_co(bfun* b, int x);
27+
28+
#endif // _BFUN_H
29+

main.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include "bfun.h"
2+
3+
int main(int argc, char* argv[]) {
4+
char* filename;
5+
if (argc > 1) filename = argv[1];
6+
else filename = "foo";
7+
char* out_file = "out.txt";
8+
9+
int vs = 4;
10+
11+
/*
12+
cube* plain = new_cube(vs);
13+
cube* one_false = new_cube(vs);
14+
set_false(one_false, 1);
15+
*/
16+
cube* one_true = new_cube(vs);
17+
set_true(one_true, 1);
18+
cube* one_each = new_cube(vs);
19+
set_false(one_each, 1);
20+
set_true(one_each, 2);
21+
22+
cube_list* test1 = new_cube_list(vs);
23+
add_cube(test1, one_each);
24+
add_cube(test1, one_true);
25+
26+
printf("\nComplementing...\n");
27+
print_bfun(test1);
28+
29+
bfun* result = complement(test1);
30+
printf("\n************************************\n");
31+
printf("\nResult is:\n");
32+
print_bfun(result);
33+
printf("\n************************************\n");
34+
35+
del_bfun(test1);
36+
del_bfun(result);
37+
/*
38+
del_cube(plain, vs);
39+
del_cube(one_true, vs);
40+
del_cube(one_false, vs);
41+
del_cube(one_each, vs);
42+
*/
43+
44+
bfun* b = read_file(filename);
45+
bfun* cb = complement(b);
46+
47+
printf("\n************************************\n");
48+
printf("\nResult is:\n");
49+
print_bfun(cb);
50+
printf("\n************************************\n");
51+
52+
write_file(out_file, cb);
53+
54+
del_bfun(b);
55+
del_bfun(cb);
56+
}
57+

0 commit comments

Comments
 (0)