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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
/**** need to handle free image appropriately */
/**** should include toplevel loop */
/**** should not print banner, at least optionally */
/**** think through error handling, system reset */
/* XLSERV.C -- Xlisp server replacement for XLISP.C */
/* Written by Tom Almy */
#include "xlisp.h"
/* define the banner line string */
#define BANNER "XLISP-PLUS version 3.04, Copyright (c) 1988, by David Betz\n\
As modified by Thomas Almy"
jmp_buf sysFailure;
#ifdef SAVERESTORE
jmp_buf top_level;
VOID freeimage _((void));
#endif
LVAL getstroutput _((LVAL stream));
int execXlisp P4H(char *, int, char **, LVAL *);
/* The Xlisp server must be initialized via a call to initXlisp.
Since it could be restoring from a workspace, the name of that workspace
is passed as an argument */
/* The initialization function returns non-zero on initialization failure:
1 - failure during initialization
2 - failure reading init.lsp
3 - OS Failure (typically not enough memory)
*/
int initXlisp P1C(char *, resfile)
{
CONTEXT cntxt;
int i;
/* Operating system initialization code will probably need changing
from the original, non-server version */
osinit(BANNER);
/* setup initialization error handler with phoney, non NIL "true" */
xlbegin(&cntxt,CF_TOPLEVEL|CF_CLEANUP|CF_BRKLEVEL,(LVAL)1);
if (setjmp(cntxt.c_jmpbuf)) return (1);
if (setjmp(sysFailure)) return (3);
/* initialize xlisp */
#ifdef SAVERESTORE
i = xlinit(resfile);
#else
i = xlinit(NULL);
#endif
xlend(&cntxt);
if (i) { /* need to load init.lsp */
xlbegin(&cntxt, CF_TOPLEVEL|CF_CLEANUP|CF_BRKLEVEL, s_true);
if (setjmp(cntxt.c_jmpbuf) != 0) {
xlend(&cntxt);
return (2);
}
else
xlload("init.lsp",TRUE,FALSE);
xlend(&cntxt);
}
return 0;
}
/* execXlisp -- execute an Xlisp expression */
/* Return code: 1 "error failure" 2 "total failure" 3 "restore happened" */
int execXlisp P4C(char *, str, /* string to execute */
int, restype, /* Nonzero for string return,
else value return */
char **, resstr, /* result string will be disposed on next
execXlisp call*/
LVAL *, resval) /* pointer to result LVAL,
disposed on next call */
{
CONTEXT cntxt;
LVAL expr, instream;
unsigned i, len;
xlbegin(&cntxt, CF_TOPLEVEL|CF_CLEANUP|CF_BRKLEVEL, s_true);
if (setjmp(sysFailure)) {
xlend(&cntxt);
xlpopn(2);
return 2;
}
if (setjmp(top_level)) {
xlend(&cntxt);
xlpopn(2);
return 3;
}
/* setup the error return */
if (setjmp(cntxt.c_jmpbuf)) {
xlend(&cntxt);
setvalue(s_evalhook,NIL);
setvalue(s_applyhook,NIL);
xltrcindent = 0;
xldebug = 0;
xlpopn(2);
return 1;
}
/* protect some pointers */
xlstkcheck(2);
xlprotect(instream);
xlsave1(expr);
/* create input stream from input */
instream = newustream();
len = strlen(str);
for (i=0; i < len; i++) xlputc(instream, str[i]);
/* main processing loop */
for (;;) {
if (!xlread(instream, &expr, FALSE, FALSE)) break;
xlrdsave(expr);
expr = xleval(expr);
xlevsave(expr);
/* NO PRINTING! */
}
if (restype) {
expr = getstroutput(expr);
*resstr = getstring(expr);
}
else *resval = expr; /* return expression */
xlend(&cntxt);
xlpopn(2);
return (0);
}
/* wrapupXlisp - clean up -- we are done */
VOID wrapupXlisp(V)
{
if (tfp != CLOSED)
OSCLOSE(tfp);
#ifdef SAVERESTORE /* should really be defined for this */
freeimage();
#endif
osfinish();
}
/* xlfatal - print a fatal error message and exit */
VOID xlfatal P1C(char *, msg)
{
xoserror(msg);
wrapupXlisp();
longjmp(sysFailure,1);
}
/* Terminate execution */
VOID wrapup(V)
{
wrapupXlisp();
longjmp(sysFailure,1);
}
/* xlrdsave - save the last expression returned by the reader */
VOID xlrdsave P1C(LVAL, expr)
{
setvalue(s_3plus,getvalue(s_2plus));
setvalue(s_2plus,getvalue(s_1plus));
setvalue(s_1plus,getvalue(s_minus));
setvalue(s_minus,expr);
}
/* xlevsave - save the last expression returned by the evaluator */
VOID xlevsave P1C(LVAL, expr)
{
setvalue(s_3star,getvalue(s_2star));
setvalue(s_2star,getvalue(s_1star));
setvalue(s_1star,expr);
}
VOID main(V)
{
char *foo, ch;
int i;
if (initXlisp("win.wks")!= 0) {
fprintf(stderr, "Init failure");
return;
}
fprintf(stderr,"Hello there!\n");
if ((i = execXlisp("(room)", 1, &foo, NULL)) != 0)
fprintf(stderr, "Exec failure #%d", i);
else
while ((ch = *foo++) != 0) putchar(ch);
wrapupXlisp();
fprintf(stderr,"Finished!\n");
return;
}
VOID freeimage(V) {}
LVAL xresetsystem() { return NIL; }
LVAL xtoplevelloop() { return NIL; }
|