Deleted Added
sdiff udiff text old ( 40843 ) new ( 40883 )
full compact
1/*
2** stub main for testing FICL
3**
4*/
5
6#include <stdlib.h>
7#include <stdio.h>
8#include <string.h>
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <unistd.h>
12
13#include "ficl.h"
14
15/*
16** Ficl interface to getcwd
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
24 cp = getcwd(NULL, 80);
25 vmTextOut(pVM, cp, 1);
26 free(cp);
27 return;
28}
29
30/*
31** Ficl interface to chdir
32** Gets a newline (or NULL) delimited string from the input
33** and feeds it to chdir()
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 {
43 int err = chdir(pFS->text);
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
60** and feeds it to system()
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;
104 struct stat buf;
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 */
118 result = stat( pFilename->text, &buf );
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
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;
263 if (fgets(in, sizeof(in) - 1, stdin) == NULL)
264 break;
265 ret = ficlExec(pVM, in);
266 if (ret == VM_USEREXIT)
267 {
268 ficlTermSystem();
269 break;
270 }
271 }
272
273 return 0;
274}
275