Repository navigation
Expand file tree
/
Copy pathdialog.c
More file actions
122 lines (108 loc) · 2.53 KB
/
Copy pathdialog.c
File metadata and controls
122 lines (108 loc) · 2.53 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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dialog.h"
int validate_hasParam(DialogRec *d) {
if(strcmp(d->param, "") != 0 && strlen(d->param) > 0) {
return 1;
} else {
printf("hasparam error\n");
return 0;
}
}
int validate_digitempty(DialogRec *d) {
int len = strlen(d->param);
int result = 0;
char copy[strlen(d->param)];
strcpy(copy, d->param);
/* Leer ! */
if(d->param[0] == '\n') {
d->param[0] = '\0';
d->param[1] = '\0';
return 1;
}
if(strlen(d->param) == 0) {
return 1;
}
if(strlen(d->param) > 0) {
d->param[len-1] = '\0';
d->param[len-2] = '\0';
len = atoi(d->param);
strcpy(d->param, copy);
return 1;
}
return 0;
}
int validate_noparam(DialogRec *d) {
d->param[0] = '\0';
printf("%s", d->param);
if(strlen(d->param) == 0) {
return 1;
} else {
printf("noparam error\n");
return 0;
}
}
int validate_digit(DialogRec *d) {
return 1;
if(strlen(d->param) > 0 && isdigit(d->param)) {
return 1;
} else {
printf("digit error");
return 0;
}
}
DialogRec *findDialogRec(char *command, DialogRec dialogspec[]) {
DialogRec *result = NULL;
int i = 0;
while(strcmp(dialogspec[i].command, "") != 0) {
if(strstr(command, dialogspec[i].command) != NULL) {
result = &dialogspec[i];
break;
}
i=i+1;
}
return result;
}
ProlResult processLine(char line[LINEMAX], int state, DialogRec dialogspec[]) {
ProlResult result;
DialogRec *found = findDialogRec(line, dialogspec);
/* char infoText[GRMSGMAX] = "Leider konnte kein entsprechendes Dialogrec gefunden werden :/"; */
if(found == NULL) {
result.failed = 1;
result.dialogrec = NULL;
} else if(found != NULL && found->state != state) {
result.failed = 1;
result.dialogrec = found;
} else {
result.failed = 0;
strcpy(found->param, line+strlen(found->command)+1);
if(found->validator != NULL) {
found->is_valid = found->validator(found);
} else {
found->is_valid = 1;
}
result.dialogrec = found;
}
memset(line, 0, strlen(line));
return result;
}
/*
int main(void) {
DialogRec dialog[] = {
/* command, param, state, nextstate, validator
{ "BEGIN", "", 0, 1, },
{ "kuehlschrank", "", 1, 1, },
{ "fernseher", "", 1, 1, },
{ "toaster", "", 1, 1},
{ "END", "", 1, 2, },
{ "" }
};
DialogRec *find = findDialogRec("toaster", dialog);
printf("DialogRec: %s\n", find->command);
ProlResult result = processLine("BEGIN off", 0, dialog);
find = result.dialogrec;
printf("DialogRec: %s, Param: %s\n", find->command, find->param);
return 0;
}
*/