mem_file.c 1.12 KB
#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);
	}
}