mem_file.c
1.12 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
#include <stdio.h>
#include "acc_user.h"
#include "vcsuser.h"
#define TAB_LINE_SIZE 2048
static s_setval_value value_s = { accHexStrVal };
static s_setval_delay delay_s = { { accRealTime, 0, 0, 0 }, accNoDelay };
void
open_mem_file(void)
{
FILE *f;
char *tab_file;
acc_initialize();
acc_configure(accDevelopmentVersion, "1.6");
if (((tab_file = tf_getcstringp(1)) == NULL) ||
((f = fopen(tab_file, "r")) == NULL)) {
fprintf(stderr,"tab_file = %s\n",tab_file);
tf_putp(0, NULL);
} else
tf_putp(0, f);
}
void
read_mem_file(void)
{
FILE *f;
handle mem_word;
char *tp, *cp;
char tab_line[TAB_LINE_SIZE];
char clean_tab_line[TAB_LINE_SIZE];
if(tf_nump() != 2)
{
tf_error("illegal number of arguments: %d", tf_nump());
tf_putp(0, -1);
}
f = (FILE *) tf_getp(1);
mem_word = acc_handle_tfarg(2);
if (fgets(tab_line, TAB_LINE_SIZE, f) == NULL) {
tf_putp(0, -1);
} else {
tp = tab_line;
cp = clean_tab_line;
while (*tp != '\n') {
if (*tp != '_')
*cp++ = *tp;
tp++;
}
*cp = '\0';
value_s.value.str = clean_tab_line;
acc_set_value(mem_word, &value_s, &delay_s);
tf_putp(0, 0);
}
}