forked from arminbiere/aiger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshrinkaigerwitness.c
More file actions
45 lines (43 loc) · 1.01 KB
/
Copy pathshrinkaigerwitness.c
File metadata and controls
45 lines (43 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
static char * start, * top, * end;
int main (void) {
unsigned char uch;
size_t i, size;
int ch;
NEXT:
ch = getc (stdin);
if (ch == EOF) return;
if (ch == '0' || ch == '1') {
top = buffer;
while ((ch = getc (stdin)) != '\n') {
if (ch == EOF) {
fprintf (stderr, "*** shrinkaigerwitness: unexpected EOF\n");
exit (1);
}
if (ch != '0' && ch != '1') {
fprintf (stderr, "*** shrinkaigerwitness: expected '0' or '1'\n");
exit (1);
}
if (top == end) {
size_t oldsz = top - bufer, newsz = oldsz ? 2 * oldsz : 8192;
start = realloc (start, newsz);
top = start + oldsz;
end = start + newsz;
}
*top++ = ch;
}
size = top - start;
printf ("z%lld\n", size);
uch = 0;
for (i = 0; i < size; i++) {
unsigned s = i & 7;
uch |= ((unsigned char)(start[i] == '1')) << (s);
if (s) continue;
putc (uch, stdout);
uch = 0;
}
if (i & 7) putc (uch, stdout);
putc ('\n', stdout);
}
}