File: test.c

package info (click to toggle)
fungw 1.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 2,268 kB
  • sloc: ansic: 24,257; makefile: 500; sh: 32; awk: 9; perl: 8; tcl: 7; javascript: 7; ruby: 7; python: 6
file content (63 lines) | stat: -rw-r--r-- 1,405 bytes parent folder | download | duplicates (3)
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
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "fgw_string.h"
#include <libfungwbind/c/fungw_c.h>

int main()
{
	fgw_ctx_t ctx;
	char line[1024];
	fgw_obj_t *obj;

	string_init();

	fgw_init(&ctx, "host");
	obj = fgw_obj_new(&ctx, "str", "string", NULL, NULL);

	fgw_dump_ctx(&ctx, stdout, "");

	while(fgets(line, sizeof(line), stdin) != NULL) {
		char *fname = line, *args, *next;
		fgw_func_t *fnc;
		int fargc;
		fgw_arg_t fargv[32], res;
		
		while(isspace(*fname)) fname++;
		if ((*fname == '#') || (*fname == '\r') || (*fname == '\n') || (*fname == '\0'))
			continue;
		args = strpbrk(fname, "( \t\r\n");
		if (args != NULL) {
			*args = '\0';
			args++;
		}
		fnc = fgw_func_lookup(&ctx, fname);
		if (fnc == NULL) {
			printf("ERROR: no such function\n");
			continue;
		}

		fargv[0].type = FGW_FUNC;
		fargv[0].val.func = fnc;
		for(fargc = 1; args != NULL; fargc++, args = next) {
			next = strchr(args, ',');
			if (next != NULL) {
				*next = '\0';
				next++;
			}
			while(isspace(*args)) args++;
			fargv[fargc].type = FGW_STR;
			fargv[fargc].val.str = args;
		}

		printf("call %s %p %d\n", fname, fnc, fnc->func(&res, fargc, fargv));
		fgw_arg_conv(&ctx, &res, FGW_STR);
		printf("  res=%s\n", res.val.str);
		fgw_arg_free(&ctx, &res); /* the above convert may have allocated a string so it is an FGW_DYN now */

	}

	fgw_uninit(&ctx);
	fgw_atexit();
	return 0;
}