File: main.c

package info (click to toggle)
gwm 1.8d-2
  • links: PTS
  • area: main
  • in suites: potato, woody
  • size: 5,120 kB
  • ctags: 3,030
  • sloc: ansic: 19,617; makefile: 1,763; lisp: 437; sh: 321; ml: 21
file content (200 lines) | stat: -rw-r--r-- 4,565 bytes parent folder | download | duplicates (2)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/**************************************\
* 				       *
*  main routines for wool interpreter  *
* 				       *
\**************************************/

#define WLPROFILE_USER_VARIABLE "WOOLPROFILE"
#define WLPATH_SHELL_VARIABLE   "WOOLPATH"

#include <signal.h>
#include <stdio.h>
#include "EXTERN.h"
#include "wool.h"
#include "wl_atom.h"
#include "wl_coll.h"
#include "wl_func.h"
#include "wl_list.h"
#include "wl_number.h"
#include "wl_string.h"
#include "wl_pointer.h"
#include "wl_active.h"
#include "wl_name.h"
#include "yacc.h"

char    *RCS_Header =	/* the version */
"$Id: main.c,v 1.1.1.1 1996/02/09 01:43:19 kevin Exp $";
char            buffer[8192];	/* input buffer */

WOOL_OBJECT wool_eval_expr;
DECLARE_strchr;

timeout_handler();		/* alarm handler */
#define MAX_DURATION 0		/* max time of an eval in seconds */
WOOL_Atom       timeout;	/* the wool atom "timeout" */
void wool_types_init();

main_init();

main(argc, argv)
int             argc;
char           *argv[];

{
    char *s;
    extern char    *wool_fix_path();
    /* option parsing */

    wool_user_profile_name = ".woolrc";
    wool_text_extension = ".wl";

    print_banner();
    /* initialize paths (put .:$HOME before built-ins) */
    wool_path = wool_fix_path(DEFAULT_WLPATH);
    if ((s = (char *) getenv(WLPROFILE_USER_VARIABLE)) && (s[0] != '\0'))
	wool_user_profile_name = s;	     
    if ((s = (char *) getenv(WLPATH_SHELL_VARIABLE)) && (s[0] != '\0'))
	wool_path = s;

    /* first, initialize wool */
    wool_init(wool_types_init);
    /* get the atoms we want */
    timeout = wool_atom("timeout");
    /* then tell it to go back here after an error */
    set_wool_error_resume_point();	/* wool_error will jump here */

    /* main routine: read/eval/print */
    do {
	/* initialize the input "pool" of wool */
	wool_pool(NULL);

	/*
	 * then we prompt the user until we think we have a complete
	 * expression (as we are told by the return code of wool_pool) 
	 */
	do {
	    int             i;

	    wool_puts("? ");
	    for (i = 0; i < 2 * wool_pool_parentheses_level; i++)
		wool_putchar(' ');
	    if (!gets(buffer)) {

		/*
		 * as we use wool_pool, we must take care of the end_of_file
		 * ourselves. 
		 */
		wool_puts("Bye.\n");
		exit(0);
	    }
	} while (wool_pool(buffer));

	/* so, now we can read/eval/print this pooled text 
	 * add newline at the end for lex problems
	 */
	strcat(wool_pool_buffer, "\n");
	wool_input_redirect(1, wool_pool_buffer, NULL, NULL);
	

	/*
	 * we read all the expressions of this line, the NULL returned by
	 * wool_read meaning the end of the input (here the pool) 
	 */
	while (wool_read()) {
	    /* we set the timeout for an eval to timeout */
	    alarm(timeout -> c_val ?
		  ((WOOL_Number) (timeout -> c_val)) -> number
		  : MAX_DURATION);
	    if (wool_eval_expr = wool_eval(wool_read_expr)) {
		wool_puts(" = ");
		wool_print(wool_eval_expr);
		wool_putchar('\n');
	    }
	}
    } while (1);
}

/*
 * Test initialisations
 */

int variable = 8;

print_var()
{
    printf("Var is %d\n", variable);
    return NULL;
}

int (*fp)();

/* what to do when a wool-error occurs?
 */

wool_error_handler()
{
}

/* wool_end is exiting */
wool_end(n)
int n;
{
#ifdef MONITOR
    moncontrol(0);			/* do not trace ending code */
#endif /* MONITOR */
    exit(n);
}


/* handler called by wool before execing a son after a fork
 */

wool_clean_before_exec()
{
}

char *
strchr_nth(s, c, n)
char *s, c;
int n;
{
    while (s && n) {
	s = strchr(s + 1, c);
	n--;
    }
    return s;
}

print_banner()
{
    char banner[128];
    int banner_len = strchr_nth(RCS_Header, ' ', 4)
	- strchr_nth(RCS_Header, ' ', 2) - 1;

    strncpy(banner, strchr_nth(RCS_Header, ' ', 2) + 1, banner_len);
    banner[banner_len] = '\0';
    wool_printf("WOOL toplevel %s\n", banner);
}

/* you must initialize here all the used wool types in your application */

void
wool_types_init()
{
#define init_wool_type(type, name) type[0]=(WOOL_METHOD)wool_atom(name)
    init_wool_type(WLActive, "active");
    init_wool_type(WLAtom, "atom");
    init_wool_type(WLCollection, "collection");
    init_wool_type(WLQuotedExpr, "quoted-expr");
    init_wool_type(WLSubr, "subr");
    init_wool_type(WLFSubr, "fsubr");
    init_wool_type(WLExpr, "expr");
    init_wool_type(WLFExpr, "fexpr");
    init_wool_type(WLList, "list");
    init_wool_type(WLName, "name");
    init_wool_type(WLNamespace, "namespace");
    init_wool_type(WLNumber, "number");
    init_wool_type(WLPointer, "pointer");
    init_wool_type(WLString, "string");
#undef init_wool_type
}