Deleted Added
full compact
testmain.c (40843) testmain.c (40883)
1/*
1/*
2** stub main for testing FICL under Win32
2** stub main for testing FICL
3**
4*/
5
6#include <stdlib.h>
7#include <stdio.h>
8#include <string.h>
3**
4*/
5
6#include <stdlib.h>
7#include <stdio.h>
8#include <string.h>
9#ifdef WIN32
10#include <direct.h>
11#endif
12#include <sys/types.h>
13#include <sys/stat.h>
9#include <sys/types.h>
10#include <sys/stat.h>
14#ifdef linux
15#include <unistd.h>
11#include <unistd.h>
16#endif
17
18#include "ficl.h"
19
20/*
12
13#include "ficl.h"
14
15/*
21** Ficl interface to _getcwd (Win32)
16** Ficl interface to getcwd
22** Prints the current working directory using the VM's
23** textOut method...
24*/
25static void ficlGetCWD(FICL_VM *pVM)
26{
27 char *cp;
28
17** Prints the current working directory using the VM's
18** textOut method...
19*/
20static void ficlGetCWD(FICL_VM *pVM)
21{
22 char *cp;
23
29#ifdef WIN32
30 cp = _getcwd(NULL, 80);
31#else
32 cp = getcwd(NULL, 80);
24 cp = getcwd(NULL, 80);
33#endif
34 vmTextOut(pVM, cp, 1);
35 free(cp);
36 return;
37}
38
39/*
25 vmTextOut(pVM, cp, 1);
26 free(cp);
27 return;
28}
29
30/*
40** Ficl interface to _chdir (Win32)
31** Ficl interface to chdir
41** Gets a newline (or NULL) delimited string from the input
32** Gets a newline (or NULL) delimited string from the input
42** and feeds it to the Win32 chdir function...
33** and feeds it to chdir()
43** Example:
44** cd c:\tmp
45*/
46static void ficlChDir(FICL_VM *pVM)
47{
48 FICL_STRING *pFS = (FICL_STRING *)pVM->pad;
49 vmGetString(pVM, pFS, '\n');
50 if (pFS->count > 0)
51 {
34** Example:
35** cd c:\tmp
36*/
37static void ficlChDir(FICL_VM *pVM)
38{
39 FICL_STRING *pFS = (FICL_STRING *)pVM->pad;
40 vmGetString(pVM, pFS, '\n');
41 if (pFS->count > 0)
42 {
52#ifdef WIN32
53 int err = _chdir(pFS->text);
54#else
55 int err = chdir(pFS->text);
43 int err = chdir(pFS->text);
56#endif
57 if (err)
58 {
59 vmTextOut(pVM, "Error: path not found", 1);
60 vmThrow(pVM, VM_QUIT);
61 }
62 }
63 else
64 {
65 vmTextOut(pVM, "Warning (chdir): nothing happened", 1);
66 }
67 return;
68}
69
70/*
71** Ficl interface to system (ANSI)
72** Gets a newline (or NULL) delimited string from the input
44 if (err)
45 {
46 vmTextOut(pVM, "Error: path not found", 1);
47 vmThrow(pVM, VM_QUIT);
48 }
49 }
50 else
51 {
52 vmTextOut(pVM, "Warning (chdir): nothing happened", 1);
53 }
54 return;
55}
56
57/*
58** Ficl interface to system (ANSI)
59** Gets a newline (or NULL) delimited string from the input
73** and feeds it to the Win32 system function...
60** and feeds it to system()
74** Example:
75** system del *.*
76** \ ouch!
77*/
78static void ficlSystem(FICL_VM *pVM)
79{
80 FICL_STRING *pFS = (FICL_STRING *)pVM->pad;
81

--- 27 unchanged lines hidden (view full) ---

109{
110 char cp[nLINEBUF];
111 char filename[nLINEBUF];
112 FICL_STRING *pFilename = (FICL_STRING *)filename;
113 int nLine = 0;
114 FILE *fp;
115 int result;
116 CELL id;
61** Example:
62** system del *.*
63** \ ouch!
64*/
65static void ficlSystem(FICL_VM *pVM)
66{
67 FICL_STRING *pFS = (FICL_STRING *)pVM->pad;
68

--- 27 unchanged lines hidden (view full) ---

96{
97 char cp[nLINEBUF];
98 char filename[nLINEBUF];
99 FICL_STRING *pFilename = (FICL_STRING *)filename;
100 int nLine = 0;
101 FILE *fp;
102 int result;
103 CELL id;
117#ifdef WIN32
118 struct _stat buf;
119#else
120 struct stat buf;
104 struct stat buf;
121#endif
122
123
124 vmGetString(pVM, pFilename, '\n');
125
126 if (pFilename->count <= 0)
127 {
128 vmTextOut(pVM, "Warning (load): nothing happened", 1);
129 return;
130 }
131
132 /*
133 ** get the file's size and make sure it exists
134 */
105
106
107 vmGetString(pVM, pFilename, '\n');
108
109 if (pFilename->count <= 0)
110 {
111 vmTextOut(pVM, "Warning (load): nothing happened", 1);
112 return;
113 }
114
115 /*
116 ** get the file's size and make sure it exists
117 */
135#ifdef WIN32
136 result = _stat( pFilename->text, &buf );
137#else
138 result = stat( pFilename->text, &buf );
118 result = stat( pFilename->text, &buf );
139#endif
140
141 if (result != 0)
142 {
143 vmTextOut(pVM, "Unable to stat file: ", 0);
144 vmTextOut(pVM, pFilename->text, 1);
145 vmThrow(pVM, VM_QUIT);
146 }
147

--- 105 unchanged lines hidden (view full) ---

253 ficlBuild("pwd", ficlGetCWD, FW_DEFAULT);
254 ficlBuild("system", ficlSystem, FW_DEFAULT);
255 ficlBuild("spewhash", spewHash, FW_DEFAULT);
256
257 return;
258}
259
260
119
120 if (result != 0)
121 {
122 vmTextOut(pVM, "Unable to stat file: ", 0);
123 vmTextOut(pVM, pFilename->text, 1);
124 vmThrow(pVM, VM_QUIT);
125 }
126

--- 105 unchanged lines hidden (view full) ---

232 ficlBuild("pwd", ficlGetCWD, FW_DEFAULT);
233 ficlBuild("system", ficlSystem, FW_DEFAULT);
234 ficlBuild("spewhash", spewHash, FW_DEFAULT);
235
236 return;
237}
238
239
261#if !defined (_WINDOWS)
262
263int main(int argc, char **argv)
264{
265 char in[256];
266 FICL_VM *pVM;
267
268 ficlInitSystem(10000);
269 buildTestInterface();
270 pVM = ficlNewVM();

--- 7 unchanged lines hidden (view full) ---

278 {
279 sprintf(in, ".( loading %s ) cr load %s\n cr", argv[1], argv[1]);
280 ficlExec(pVM, in);
281 }
282
283 for (;;)
284 {
285 int ret;
240int main(int argc, char **argv)
241{
242 char in[256];
243 FICL_VM *pVM;
244
245 ficlInitSystem(10000);
246 buildTestInterface();
247 pVM = ficlNewVM();

--- 7 unchanged lines hidden (view full) ---

255 {
256 sprintf(in, ".( loading %s ) cr load %s\n cr", argv[1], argv[1]);
257 ficlExec(pVM, in);
258 }
259
260 for (;;)
261 {
262 int ret;
286 gets(in);
263 if (fgets(in, sizeof(in) - 1, stdin) == NULL)
264 break;
287 ret = ficlExec(pVM, in);
288 if (ret == VM_USEREXIT)
289 {
290 ficlTermSystem();
291 break;
292 }
293 }
294
295 return 0;
296}
297
265 ret = ficlExec(pVM, in);
266 if (ret == VM_USEREXIT)
267 {
268 ficlTermSystem();
269 break;
270 }
271 }
272
273 return 0;
274}
275
298#endif
299