forked from mclumd/alma-2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalma.c
81 lines (70 loc) · 1.9 KB
/
alma.c
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "alma_command.h"
#include "alma_kb.h"
#define LINELEN 1000
// Initialize global variable (declared in alma_formula header) to count up variable IDs
long long variable_id_count = 0;
int main(int argc, char **argv) {
if (argc <= 1) {
printf("Please run with an input file argument.\n");
return 0;
}
int run = 0;
if (argc > 2 && strcmp(argv[2], "run") == 0)
run = 1;
kb *alma_kb;
kb_init(&alma_kb, argv[1]);
kb_print(alma_kb);
if (run) {
while (!alma_kb->idling) {
kb_step(alma_kb);
kb_print(alma_kb);
}
kb_halt(alma_kb);
}
else {
char line[LINELEN];
while (1) {
printf("alma: ");
if (fgets(line, LINELEN, stdin) != NULL) {
int len = strlen(line);
line[len-1] = '\0';
char *pos;
if (strcmp(line, "step") == 0) {
kb_step(alma_kb);
}
else if (strcmp(line, "print") == 0) {
kb_print(alma_kb);
}
else if (strcmp(line, "halt") == 0) {
kb_halt(alma_kb);
break;
}
else if ((pos = strstr(line, "add ")) != NULL && pos == line) {
char *assertion = malloc(len - 4);
strncpy(assertion, line+4, len-4);
kb_assert(alma_kb, assertion);
free(assertion);
}
else if ((pos = strstr(line, "del ")) != NULL && pos == line) {
char *assertion = malloc(len - 4);
strncpy(assertion, line+4, len-4);
kb_remove(alma_kb, assertion);
free(assertion);
}
else if ((pos = strstr(line, "bs ")) != NULL && pos == line) {
char *assertion = malloc(len - 3);
strncpy(assertion, line+3, len-3);
kb_backsearch(alma_kb, assertion);
free(assertion);
}
else {
printf("Command not recognized\n");
}
}
}
}
return 0;
}