4 * Revision 1.1 2001/04/04 05:43:39 wang
5 * First commit: compiles on Linux, Amiga, Windows, Windows CE, generic gcc
7 * Revision 1.2 1999/11/26 13:13:47 bnv
8 * Changed: To use the new macros.
10 * Revision 1.1 1998/07/02 17:34:50 bnv
32 /* ----------- Function prototypes ------------ */
33 void Rerror(int,int,...);
34 void RxInitFiles(void);
35 void RxDoneFiles(void);
36 void RxRegFunctionDone(void);
38 /* ----------- External variables ------------- */
41 /* ---------------- RxInitProc ---------------- */
46 _Proc_size
= PROC_INC
;
47 _Proc
= (RxProc
*) MALLOC( _Proc_size
* sizeof(RxProc
), "RxProc" );
48 MEMSET(_Proc
,0,_Proc_size
*sizeof(RxProc
));
51 /* ----------------- RxInitialize ----------------- */
53 RxInitialize( char *prorgram_name
)
57 _prgname
= prorgram_name
;
58 #if defined(WIN32) || defined(WCE)
59 _szRxAppKey
= REGAPPKEY
;
64 /* do the basic initialisation */
65 Linit(Rerror
); /* initialise with Lstderr as error function */
67 Lfx(&symbolstr
,250); /* create symbol string */
69 Lfx(&errmsg
,250); /* create error message string */
71 /* --- first locate configuration file --- */
72 /* rexx.rc for DOS in the executable program directory */
73 /* .rexxrc for unix in the HOME directory */
75 _procidcnt
= 1; /* Program id counter */
77 DQINIT(StackList
); /* initialise stacks */
78 CreateStack(); /* create first stack */
79 rxfile
= NULL
; /* intialise rexx files */
83 RxInitProc(); /* initialize prg list */
84 RxInitInterpret(); /* initialise interpreter*/
85 RxInitFiles(); /* initialise files */
86 RxInitVariables(); /* initialise hash table for variables */
88 BINTREEINIT(_labels
); /* initialise labels */
89 BINTREEINIT(Litterals
); /* initialise litterals */
91 Lscpy(&str
,"HALT"); HaltStr
= _Add2Lits( &str
, FALSE
);
93 Lscpy(&str
,"1"); OneStr
= _Add2Lits( &str
, FALSE
);
94 Lscpy(&str
,""); NullStr
= _Add2Lits( &str
, FALSE
);
95 Lscpy(&str
,"0"); ZeroStr
= _Add2Lits( &str
, FALSE
);
96 Lscpy(&str
,"ERROR"); ErrorStr
= _Add2Lits( &str
, FALSE
);
98 Lscpy(&str
,"RESULT"); ResultStr
= _Add2Lits( &str
, FALSE
);
99 Lscpy(&str
,"NOVALUE"); NoValueStr
= _Add2Lits( &str
, FALSE
);
100 Lscpy(&str
,"NOTREADY");NotReadyStr
= _Add2Lits( &str
, FALSE
);
101 Lscpy(&str
,"SIGL"); SiglStr
= _Add2Lits( &str
, FALSE
);
102 Lscpy(&str
,"RC"); RCStr
= _Add2Lits( &str
, FALSE
);
103 Lscpy(&str
,"SYNTAX"); SyntaxStr
= _Add2Lits( &str
, FALSE
);
104 Lscpy(&str
,"SYSTEM"); SystemStr
= _Add2Lits( &str
, FALSE
);
109 /* ----------------- RxFinalize ----------------- */
113 LFREESTR(symbolstr
); /* delete symbol string */
114 LFREESTR(errmsg
); /* delete error msg str */
116 FREE(_Proc
); /* free prg list */
117 while (StackList
.items
>0) DeleteStack();
118 LPFREE(_code
); _code
= NULL
;
120 RxDoneFiles(); /* close all files */
122 /* will free also NullStr, Zero and OneStr */
123 BinDisposeLeaf(&Litterals
,Litterals
.parent
,FREE
);
124 BinDisposeLeaf(&_labels
,_labels
.parent
,FREE
);
126 RxRegFunctionDone(); /* initialise register functions */
129 /* ----------------- RxLoadFile ------------------- */
131 RxLoadFile( RxFile
*rxf
)
135 if ((f
=FOPEN(LSTR(rxf
->filename
),"r"))==NULL
)
137 Lread(f
,&(rxf
->file
), LREADFILE
);
142 /* ----------------- RxRun ------------------ */
144 RxRun( char *filename
, PLstr programstr
,
145 PLstr arguments
, PLstr tracestr
, char *environment
)
152 /* --- set exit jmp position --- */
153 if ((i
=setjmp(_exit_trap
))!=0)
155 /* --- set temporary error trap --- */
156 if (setjmp(_error_trap
)!=0)
159 /* ====== first load the file ====== */
160 rxfile
= (RxFile
*)MALLOC(sizeof(RxFile
),"RxFile");
161 MEMSET(rxfile
,0,sizeof(RxFile
));
164 /* --- copy the filename --- */
165 Lscpy(&(rxfile
->filename
), filename
);
166 LASCIIZ(rxfile
->filename
);
169 rxfile
->filetype
= NULL
;
170 c
= LSTR(rxfile
->filename
)+LLEN(rxfile
->filename
);
171 for (;c
>LSTR(rxfile
->filename
) && *c
!='.';c
--) ;;
173 rxfile
->filetype
= c
+1;
175 /* --- Load file --- */
176 if (!RxLoadFile( rxfile
)) {
178 fprintf(STDERR
,"Error %d running \"%s\": File not found\n",
179 ERR_FILE_NOT_FOUND
, LSTR(rxfile
->filename
));
181 PUTS("Error: File not found.");
183 LFREESTR(rxfile
->filename
);
188 Lscpy(&(rxfile
->filename
), "<STDIN>");
189 rxfile
->filetype
= NULL
;
190 LASCIIZ(rxfile
->filename
);
191 Lstrcpy(&(rxfile
->file
), programstr
);
193 LASCIIZ(rxfile
->file
);
197 printf("File is:\n%s\n",LSTR(rxfile
->file
));
202 /* ====== setup procedure ====== */
203 _rx_proc
++; /* increase program items */
204 pr
= _Proc
+_rx_proc
; /* pr = Proc pointer */
206 /* set program id counter */
207 pr
->id
= _procidcnt
++;
209 /* --- initialise Proc structure --- */
212 for (i
=0; i
<MAXARGS
; i
++)
215 if (LLEN(*arguments
)) {
217 pr
->arg
.a
[0] = arguments
;
221 pr
->calltype
= CT_PROGRAM
; /* call type... */
222 pr
->ip
= 0; /* procedure ip */
223 pr
->stack
= -1; /* prg stck, will be set in interpret */
224 pr
->stacktop
= -1; /* no arguments */
226 pr
->scope
= RxScopeMalloc();
229 Lscpy(pr
->env
,environment
);
231 Lstrcpy(pr
->env
,&(SystemStr
->key
));
232 pr
->digits
= LMAXNUMERICDIGITS
;
234 pr
->form
= SCIENTIFIC
;
236 pr
->lbl_error
= &(ErrorStr
->key
);
237 pr
->lbl_halt
= &(HaltStr
->key
);
238 pr
->lbl_novalue
= &(NoValueStr
->key
);
239 pr
->lbl_notready
= &(NotReadyStr
->key
);
240 pr
->lbl_syntax
= &(SyntaxStr
->key
);
242 pr
->trace
= normal_trace
;
243 pr
->interactive_trace
= FALSE
;
244 if (tracestr
&& LLEN(*tracestr
)) TraceSet(tracestr
);
246 /* ======= Compile file ====== */
247 RxInitCompile(rxfile
,NULL
);
252 printf("Litterals are:\n");
253 BinPrint(Litterals
.parent
);
256 printf("Labels(&functions) are:\n");
257 BinPrint(_labels
.parent
);
258 printf("Code Size: %d\n\n",LLEN(*_code
));
263 /* ======= Execute code ======== */
268 /* pr pointer might have changed if Proc was resized */
272 printf("Return Code = %d\n",RxReturnCode
);
275 /* ======== free up memory ======== */
278 rxfile
= rxfile
->next
;
279 LFREESTR(rxf
->filename
);
287 CompileClause
= NULL
;
290 RxScopeFree(pr
->scope
);