1ca987d46SWarner Losh
2ca987d46SWarner Losh #include <errno.h>
3ca987d46SWarner Losh #include <stdlib.h>
4ca987d46SWarner Losh #include <stdio.h>
5ca987d46SWarner Losh #include <string.h>
6ca987d46SWarner Losh #include <ctype.h>
7ca987d46SWarner Losh #include <sys/stat.h>
8ca987d46SWarner Losh #include "ficl.h"
9ca987d46SWarner Losh
10ca987d46SWarner Losh #if FICL_WANT_FILE
11ca987d46SWarner Losh /*
12ca987d46SWarner Losh **
13ca987d46SWarner Losh ** fileaccess.c
14ca987d46SWarner Losh **
15ca987d46SWarner Losh ** Implements all of the File Access word set that can be implemented in portable C.
16ca987d46SWarner Losh **
17ca987d46SWarner Losh */
18ca987d46SWarner Losh
pushIor(FICL_VM * pVM,int success)19ca987d46SWarner Losh static void pushIor(FICL_VM *pVM, int success)
20ca987d46SWarner Losh {
21ca987d46SWarner Losh int ior;
22ca987d46SWarner Losh if (success)
23ca987d46SWarner Losh ior = 0;
24ca987d46SWarner Losh else
25ca987d46SWarner Losh ior = errno;
26ca987d46SWarner Losh stackPushINT(pVM->pStack, ior);
27ca987d46SWarner Losh }
28ca987d46SWarner Losh
29ca987d46SWarner Losh
30ca987d46SWarner Losh
ficlFopen(FICL_VM * pVM,char * writeMode)31ca987d46SWarner Losh static void ficlFopen(FICL_VM *pVM, char *writeMode) /* ( c-addr u fam -- fileid ior ) */
32ca987d46SWarner Losh {
33ca987d46SWarner Losh int fam = stackPopINT(pVM->pStack);
34ca987d46SWarner Losh int length = stackPopINT(pVM->pStack);
35ca987d46SWarner Losh void *address = (void *)stackPopPtr(pVM->pStack);
36ca987d46SWarner Losh char mode[4];
37ca987d46SWarner Losh FILE *f;
38ca987d46SWarner Losh
39ca987d46SWarner Losh char *filename = (char *)alloca(length + 1);
40ca987d46SWarner Losh memcpy(filename, address, length);
41ca987d46SWarner Losh filename[length] = 0;
42ca987d46SWarner Losh
43ca987d46SWarner Losh *mode = 0;
44ca987d46SWarner Losh
45ca987d46SWarner Losh switch (FICL_FAM_OPEN_MODE(fam))
46ca987d46SWarner Losh {
47ca987d46SWarner Losh case 0:
48ca987d46SWarner Losh stackPushPtr(pVM->pStack, NULL);
49ca987d46SWarner Losh stackPushINT(pVM->pStack, EINVAL);
50ca987d46SWarner Losh return;
51ca987d46SWarner Losh case FICL_FAM_READ:
52ca987d46SWarner Losh strcat(mode, "r");
53ca987d46SWarner Losh break;
54ca987d46SWarner Losh case FICL_FAM_WRITE:
55ca987d46SWarner Losh strcat(mode, writeMode);
56ca987d46SWarner Losh break;
57ca987d46SWarner Losh case FICL_FAM_READ | FICL_FAM_WRITE:
58ca987d46SWarner Losh strcat(mode, writeMode);
59ca987d46SWarner Losh strcat(mode, "+");
60ca987d46SWarner Losh break;
61ca987d46SWarner Losh }
62ca987d46SWarner Losh
63ca987d46SWarner Losh strcat(mode, (fam & FICL_FAM_BINARY) ? "b" : "t");
64ca987d46SWarner Losh
65ca987d46SWarner Losh f = fopen(filename, mode);
66ca987d46SWarner Losh if (f == NULL)
67ca987d46SWarner Losh stackPushPtr(pVM->pStack, NULL);
68ca987d46SWarner Losh else
698df8b2d3SSimon J. Gerraty #ifdef LOADER_VERIEXEC
708df8b2d3SSimon J. Gerraty if (*mode == 'r' &&
71*91cd69eeSSimon J. Gerraty verify_file(fileno(f), filename, 0, VE_GUESS, __func__) < 0) {
728df8b2d3SSimon J. Gerraty fclose(f);
738df8b2d3SSimon J. Gerraty stackPushPtr(pVM->pStack, NULL);
748df8b2d3SSimon J. Gerraty } else
758df8b2d3SSimon J. Gerraty #endif
76ca987d46SWarner Losh {
77ca987d46SWarner Losh ficlFILE *ff = (ficlFILE *)malloc(sizeof(ficlFILE));
78ca987d46SWarner Losh strcpy(ff->filename, filename);
79ca987d46SWarner Losh ff->f = f;
80ca987d46SWarner Losh stackPushPtr(pVM->pStack, ff);
81ca987d46SWarner Losh
82ca987d46SWarner Losh fseek(f, 0, SEEK_SET);
83ca987d46SWarner Losh }
84ca987d46SWarner Losh pushIor(pVM, f != NULL);
85ca987d46SWarner Losh }
86ca987d46SWarner Losh
87ca987d46SWarner Losh
88ca987d46SWarner Losh
ficlOpenFile(FICL_VM * pVM)89ca987d46SWarner Losh static void ficlOpenFile(FICL_VM *pVM) /* ( c-addr u fam -- fileid ior ) */
90ca987d46SWarner Losh {
91ca987d46SWarner Losh ficlFopen(pVM, "a");
92ca987d46SWarner Losh }
93ca987d46SWarner Losh
94ca987d46SWarner Losh
ficlCreateFile(FICL_VM * pVM)95ca987d46SWarner Losh static void ficlCreateFile(FICL_VM *pVM) /* ( c-addr u fam -- fileid ior ) */
96ca987d46SWarner Losh {
97ca987d46SWarner Losh ficlFopen(pVM, "w");
98ca987d46SWarner Losh }
99ca987d46SWarner Losh
100ca987d46SWarner Losh
closeFiclFILE(ficlFILE * ff)101ca987d46SWarner Losh static int closeFiclFILE(ficlFILE *ff) /* ( fileid -- ior ) */
102ca987d46SWarner Losh {
103ca987d46SWarner Losh FILE *f = ff->f;
104ca987d46SWarner Losh free(ff);
105ca987d46SWarner Losh return !fclose(f);
106ca987d46SWarner Losh }
107ca987d46SWarner Losh
ficlCloseFile(FICL_VM * pVM)108ca987d46SWarner Losh static void ficlCloseFile(FICL_VM *pVM) /* ( fileid -- ior ) */
109ca987d46SWarner Losh {
110ca987d46SWarner Losh ficlFILE *ff = (ficlFILE *)stackPopPtr(pVM->pStack);
111ca987d46SWarner Losh pushIor(pVM, closeFiclFILE(ff));
112ca987d46SWarner Losh }
113ca987d46SWarner Losh
ficlDeleteFile(FICL_VM * pVM)114ca987d46SWarner Losh static void ficlDeleteFile(FICL_VM *pVM) /* ( c-addr u -- ior ) */
115ca987d46SWarner Losh {
116ca987d46SWarner Losh int length = stackPopINT(pVM->pStack);
117ca987d46SWarner Losh void *address = (void *)stackPopPtr(pVM->pStack);
118ca987d46SWarner Losh
119ca987d46SWarner Losh char *filename = (char *)alloca(length + 1);
120ca987d46SWarner Losh memcpy(filename, address, length);
121ca987d46SWarner Losh filename[length] = 0;
122ca987d46SWarner Losh
123ca987d46SWarner Losh pushIor(pVM, !unlink(filename));
124ca987d46SWarner Losh }
125ca987d46SWarner Losh
ficlRenameFile(FICL_VM * pVM)126ca987d46SWarner Losh static void ficlRenameFile(FICL_VM *pVM) /* ( c-addr1 u1 c-addr2 u2 -- ior ) */
127ca987d46SWarner Losh {
128ca987d46SWarner Losh int length;
129ca987d46SWarner Losh void *address;
130ca987d46SWarner Losh char *from;
131ca987d46SWarner Losh char *to;
132ca987d46SWarner Losh
133ca987d46SWarner Losh length = stackPopINT(pVM->pStack);
134ca987d46SWarner Losh address = (void *)stackPopPtr(pVM->pStack);
135ca987d46SWarner Losh to = (char *)alloca(length + 1);
136ca987d46SWarner Losh memcpy(to, address, length);
137ca987d46SWarner Losh to[length] = 0;
138ca987d46SWarner Losh
139ca987d46SWarner Losh length = stackPopINT(pVM->pStack);
140ca987d46SWarner Losh address = (void *)stackPopPtr(pVM->pStack);
141ca987d46SWarner Losh
142ca987d46SWarner Losh from = (char *)alloca(length + 1);
143ca987d46SWarner Losh memcpy(from, address, length);
144ca987d46SWarner Losh from[length] = 0;
145ca987d46SWarner Losh
146ca987d46SWarner Losh pushIor(pVM, !rename(from, to));
147ca987d46SWarner Losh }
148ca987d46SWarner Losh
ficlFileStatus(FICL_VM * pVM)149ca987d46SWarner Losh static void ficlFileStatus(FICL_VM *pVM) /* ( c-addr u -- x ior ) */
150ca987d46SWarner Losh {
151ca987d46SWarner Losh struct stat statbuf;
152ca987d46SWarner Losh
153ca987d46SWarner Losh int length = stackPopINT(pVM->pStack);
154ca987d46SWarner Losh void *address = (void *)stackPopPtr(pVM->pStack);
155ca987d46SWarner Losh
156ca987d46SWarner Losh char *filename = (char *)alloca(length + 1);
157ca987d46SWarner Losh memcpy(filename, address, length);
158ca987d46SWarner Losh filename[length] = 0;
159ca987d46SWarner Losh
160ca987d46SWarner Losh if (stat(filename, &statbuf) == 0)
161ca987d46SWarner Losh {
162ca987d46SWarner Losh /*
163ca987d46SWarner Losh ** the "x" left on the stack is implementation-defined.
164ca987d46SWarner Losh ** I push the file's access mode (readable, writeable, is directory, etc)
165ca987d46SWarner Losh ** as defined by ANSI C.
166ca987d46SWarner Losh */
167ca987d46SWarner Losh stackPushINT(pVM->pStack, statbuf.st_mode);
168ca987d46SWarner Losh stackPushINT(pVM->pStack, 0);
169ca987d46SWarner Losh }
170ca987d46SWarner Losh else
171ca987d46SWarner Losh {
172ca987d46SWarner Losh stackPushINT(pVM->pStack, -1);
173ca987d46SWarner Losh stackPushINT(pVM->pStack, ENOENT);
174ca987d46SWarner Losh }
175ca987d46SWarner Losh }
176ca987d46SWarner Losh
177ca987d46SWarner Losh
ficlFilePosition(FICL_VM * pVM)178ca987d46SWarner Losh static void ficlFilePosition(FICL_VM *pVM) /* ( fileid -- ud ior ) */
179ca987d46SWarner Losh {
180ca987d46SWarner Losh ficlFILE *ff = (ficlFILE *)stackPopPtr(pVM->pStack);
181ca987d46SWarner Losh long ud = ftell(ff->f);
182ca987d46SWarner Losh stackPushINT(pVM->pStack, ud);
183ca987d46SWarner Losh pushIor(pVM, ud != -1);
184ca987d46SWarner Losh }
185ca987d46SWarner Losh
186ca987d46SWarner Losh
187ca987d46SWarner Losh
fileSize(FILE * f)188ca987d46SWarner Losh static long fileSize(FILE *f)
189ca987d46SWarner Losh {
190ca987d46SWarner Losh struct stat statbuf;
191ca987d46SWarner Losh statbuf.st_size = -1;
192ca987d46SWarner Losh if (fstat(fileno(f), &statbuf) != 0)
193ca987d46SWarner Losh return -1;
194ca987d46SWarner Losh return statbuf.st_size;
195ca987d46SWarner Losh }
196ca987d46SWarner Losh
197ca987d46SWarner Losh
198ca987d46SWarner Losh
ficlFileSize(FICL_VM * pVM)199ca987d46SWarner Losh static void ficlFileSize(FICL_VM *pVM) /* ( fileid -- ud ior ) */
200ca987d46SWarner Losh {
201ca987d46SWarner Losh ficlFILE *ff = (ficlFILE *)stackPopPtr(pVM->pStack);
202ca987d46SWarner Losh long ud = fileSize(ff->f);
203ca987d46SWarner Losh stackPushINT(pVM->pStack, ud);
204ca987d46SWarner Losh pushIor(pVM, ud != -1);
205ca987d46SWarner Losh }
206ca987d46SWarner Losh
207ca987d46SWarner Losh
208ca987d46SWarner Losh
209ca987d46SWarner Losh #define nLINEBUF 256
ficlIncludeFile(FICL_VM * pVM)210ca987d46SWarner Losh static void ficlIncludeFile(FICL_VM *pVM) /* ( i*x fileid -- j*x ) */
211ca987d46SWarner Losh {
212ca987d46SWarner Losh ficlFILE *ff = (ficlFILE *)stackPopPtr(pVM->pStack);
213ca987d46SWarner Losh CELL id = pVM->sourceID;
214ca987d46SWarner Losh int result = VM_OUTOFTEXT;
215ca987d46SWarner Losh long currentPosition, totalSize;
216ca987d46SWarner Losh long size;
217ca987d46SWarner Losh pVM->sourceID.p = (void *)ff;
218ca987d46SWarner Losh
219ca987d46SWarner Losh currentPosition = ftell(ff->f);
220ca987d46SWarner Losh totalSize = fileSize(ff->f);
221ca987d46SWarner Losh size = totalSize - currentPosition;
222ca987d46SWarner Losh
223ca987d46SWarner Losh if ((totalSize != -1) && (currentPosition != -1) && (size > 0))
224ca987d46SWarner Losh {
225ca987d46SWarner Losh char *buffer = (char *)malloc(size);
226ca987d46SWarner Losh long got = fread(buffer, 1, size, ff->f);
227ca987d46SWarner Losh if (got == size)
228ca987d46SWarner Losh result = ficlExecC(pVM, buffer, size);
229ca987d46SWarner Losh }
230ca987d46SWarner Losh
231ca987d46SWarner Losh #if 0
232ca987d46SWarner Losh ficlFILE *ff = (ficlFILE *)stackPopPtr(pVM->pStack);
233ca987d46SWarner Losh CELL id = pVM->sourceID;
234ca987d46SWarner Losh char cp[nLINEBUF];
235ca987d46SWarner Losh int nLine = 0;
236ca987d46SWarner Losh int keepGoing;
237ca987d46SWarner Losh int result;
238ca987d46SWarner Losh pVM->sourceID.p = (void *)ff;
239ca987d46SWarner Losh
240ca987d46SWarner Losh /* feed each line to ficlExec */
241ca987d46SWarner Losh keepGoing = TRUE;
242ca987d46SWarner Losh while (keepGoing && fgets(cp, nLINEBUF, ff->f))
243ca987d46SWarner Losh {
244ca987d46SWarner Losh int len = strlen(cp) - 1;
245ca987d46SWarner Losh
246ca987d46SWarner Losh nLine++;
247ca987d46SWarner Losh if (len <= 0)
248ca987d46SWarner Losh continue;
249ca987d46SWarner Losh
250ca987d46SWarner Losh if (cp[len] == '\n')
251ca987d46SWarner Losh cp[len] = '\0';
252ca987d46SWarner Losh
253ca987d46SWarner Losh result = ficlExec(pVM, cp);
254ca987d46SWarner Losh
255ca987d46SWarner Losh switch (result)
256ca987d46SWarner Losh {
257ca987d46SWarner Losh case VM_OUTOFTEXT:
258ca987d46SWarner Losh case VM_USEREXIT:
259ca987d46SWarner Losh break;
260ca987d46SWarner Losh
261ca987d46SWarner Losh default:
262ca987d46SWarner Losh pVM->sourceID = id;
263ca987d46SWarner Losh keepGoing = FALSE;
264ca987d46SWarner Losh break;
265ca987d46SWarner Losh }
266ca987d46SWarner Losh }
267ca987d46SWarner Losh #endif /* 0 */
268ca987d46SWarner Losh /*
269ca987d46SWarner Losh ** Pass an empty line with SOURCE-ID == -1 to flush
270ca987d46SWarner Losh ** any pending REFILLs (as required by FILE wordset)
271ca987d46SWarner Losh */
272ca987d46SWarner Losh pVM->sourceID.i = -1;
273ca987d46SWarner Losh ficlExec(pVM, "");
274ca987d46SWarner Losh
275ca987d46SWarner Losh pVM->sourceID = id;
276ca987d46SWarner Losh closeFiclFILE(ff);
277ca987d46SWarner Losh }
278ca987d46SWarner Losh
279ca987d46SWarner Losh
280ca987d46SWarner Losh
ficlReadFile(FICL_VM * pVM)281ca987d46SWarner Losh static void ficlReadFile(FICL_VM *pVM) /* ( c-addr u1 fileid -- u2 ior ) */
282ca987d46SWarner Losh {
283ca987d46SWarner Losh ficlFILE *ff = (ficlFILE *)stackPopPtr(pVM->pStack);
284ca987d46SWarner Losh int length = stackPopINT(pVM->pStack);
285ca987d46SWarner Losh void *address = (void *)stackPopPtr(pVM->pStack);
286ca987d46SWarner Losh int result;
287ca987d46SWarner Losh
288ca987d46SWarner Losh clearerr(ff->f);
289ca987d46SWarner Losh result = fread(address, 1, length, ff->f);
290ca987d46SWarner Losh
291ca987d46SWarner Losh stackPushINT(pVM->pStack, result);
292ca987d46SWarner Losh pushIor(pVM, ferror(ff->f) == 0);
293ca987d46SWarner Losh }
294ca987d46SWarner Losh
295ca987d46SWarner Losh
296ca987d46SWarner Losh
ficlReadLine(FICL_VM * pVM)297ca987d46SWarner Losh static void ficlReadLine(FICL_VM *pVM) /* ( c-addr u1 fileid -- u2 flag ior ) */
298ca987d46SWarner Losh {
299ca987d46SWarner Losh ficlFILE *ff = (ficlFILE *)stackPopPtr(pVM->pStack);
300ca987d46SWarner Losh int length = stackPopINT(pVM->pStack);
301ca987d46SWarner Losh char *address = (char *)stackPopPtr(pVM->pStack);
302ca987d46SWarner Losh int error;
303ca987d46SWarner Losh int flag;
304ca987d46SWarner Losh
305ca987d46SWarner Losh if (feof(ff->f))
306ca987d46SWarner Losh {
307ca987d46SWarner Losh stackPushINT(pVM->pStack, -1);
308ca987d46SWarner Losh stackPushINT(pVM->pStack, 0);
309ca987d46SWarner Losh stackPushINT(pVM->pStack, 0);
310ca987d46SWarner Losh return;
311ca987d46SWarner Losh }
312ca987d46SWarner Losh
313ca987d46SWarner Losh clearerr(ff->f);
314ca987d46SWarner Losh *address = 0;
315ca987d46SWarner Losh fgets(address, length, ff->f);
316ca987d46SWarner Losh
317ca987d46SWarner Losh error = ferror(ff->f);
318ca987d46SWarner Losh if (error != 0)
319ca987d46SWarner Losh {
320ca987d46SWarner Losh stackPushINT(pVM->pStack, -1);
321ca987d46SWarner Losh stackPushINT(pVM->pStack, 0);
322ca987d46SWarner Losh stackPushINT(pVM->pStack, error);
323ca987d46SWarner Losh return;
324ca987d46SWarner Losh }
325ca987d46SWarner Losh
326ca987d46SWarner Losh length = strlen(address);
327ca987d46SWarner Losh flag = (length > 0);
328ca987d46SWarner Losh if (length && ((address[length - 1] == '\r') || (address[length - 1] == '\n')))
329ca987d46SWarner Losh length--;
330ca987d46SWarner Losh
331ca987d46SWarner Losh stackPushINT(pVM->pStack, length);
332ca987d46SWarner Losh stackPushINT(pVM->pStack, flag);
333ca987d46SWarner Losh stackPushINT(pVM->pStack, 0); /* ior */
334ca987d46SWarner Losh }
335ca987d46SWarner Losh
336ca987d46SWarner Losh
337ca987d46SWarner Losh
ficlWriteFile(FICL_VM * pVM)338ca987d46SWarner Losh static void ficlWriteFile(FICL_VM *pVM) /* ( c-addr u1 fileid -- ior ) */
339ca987d46SWarner Losh {
340ca987d46SWarner Losh ficlFILE *ff = (ficlFILE *)stackPopPtr(pVM->pStack);
341ca987d46SWarner Losh int length = stackPopINT(pVM->pStack);
342ca987d46SWarner Losh void *address = (void *)stackPopPtr(pVM->pStack);
343ca987d46SWarner Losh
344ca987d46SWarner Losh clearerr(ff->f);
345ca987d46SWarner Losh fwrite(address, 1, length, ff->f);
346ca987d46SWarner Losh pushIor(pVM, ferror(ff->f) == 0);
347ca987d46SWarner Losh }
348ca987d46SWarner Losh
349ca987d46SWarner Losh
350ca987d46SWarner Losh
ficlWriteLine(FICL_VM * pVM)351ca987d46SWarner Losh static void ficlWriteLine(FICL_VM *pVM) /* ( c-addr u1 fileid -- ior ) */
352ca987d46SWarner Losh {
353ca987d46SWarner Losh ficlFILE *ff = (ficlFILE *)stackPopPtr(pVM->pStack);
354ca987d46SWarner Losh size_t length = (size_t)stackPopINT(pVM->pStack);
355ca987d46SWarner Losh void *address = (void *)stackPopPtr(pVM->pStack);
356ca987d46SWarner Losh
357ca987d46SWarner Losh clearerr(ff->f);
358ca987d46SWarner Losh if (fwrite(address, 1, length, ff->f) == length)
359ca987d46SWarner Losh fwrite("\n", 1, 1, ff->f);
360ca987d46SWarner Losh pushIor(pVM, ferror(ff->f) == 0);
361ca987d46SWarner Losh }
362ca987d46SWarner Losh
363ca987d46SWarner Losh
364ca987d46SWarner Losh
ficlRepositionFile(FICL_VM * pVM)365ca987d46SWarner Losh static void ficlRepositionFile(FICL_VM *pVM) /* ( ud fileid -- ior ) */
366ca987d46SWarner Losh {
367ca987d46SWarner Losh ficlFILE *ff = (ficlFILE *)stackPopPtr(pVM->pStack);
368ca987d46SWarner Losh size_t ud = (size_t)stackPopINT(pVM->pStack);
369ca987d46SWarner Losh
370ca987d46SWarner Losh pushIor(pVM, fseek(ff->f, ud, SEEK_SET) == 0);
371ca987d46SWarner Losh }
372ca987d46SWarner Losh
373ca987d46SWarner Losh
374ca987d46SWarner Losh
ficlFlushFile(FICL_VM * pVM)375ca987d46SWarner Losh static void ficlFlushFile(FICL_VM *pVM) /* ( fileid -- ior ) */
376ca987d46SWarner Losh {
377ca987d46SWarner Losh ficlFILE *ff = (ficlFILE *)stackPopPtr(pVM->pStack);
378ca987d46SWarner Losh pushIor(pVM, fflush(ff->f) == 0);
379ca987d46SWarner Losh }
380ca987d46SWarner Losh
381ca987d46SWarner Losh
382ca987d46SWarner Losh
383ca987d46SWarner Losh #if FICL_HAVE_FTRUNCATE
384ca987d46SWarner Losh
ficlResizeFile(FICL_VM * pVM)385ca987d46SWarner Losh static void ficlResizeFile(FICL_VM *pVM) /* ( ud fileid -- ior ) */
386ca987d46SWarner Losh {
387ca987d46SWarner Losh ficlFILE *ff = (ficlFILE *)stackPopPtr(pVM->pStack);
388ca987d46SWarner Losh size_t ud = (size_t)stackPopINT(pVM->pStack);
389ca987d46SWarner Losh
390ca987d46SWarner Losh pushIor(pVM, ftruncate(fileno(ff->f), ud) == 0);
391ca987d46SWarner Losh }
392ca987d46SWarner Losh
393ca987d46SWarner Losh #endif /* FICL_HAVE_FTRUNCATE */
394ca987d46SWarner Losh
395ca987d46SWarner Losh #endif /* FICL_WANT_FILE */
396ca987d46SWarner Losh
397ca987d46SWarner Losh
398ca987d46SWarner Losh
ficlCompileFile(FICL_SYSTEM * pSys)399ca987d46SWarner Losh void ficlCompileFile(FICL_SYSTEM *pSys)
400ca987d46SWarner Losh {
401ca987d46SWarner Losh #if FICL_WANT_FILE
402ca987d46SWarner Losh FICL_DICT *dp = pSys->dp;
403ca987d46SWarner Losh assert(dp);
404ca987d46SWarner Losh
405ca987d46SWarner Losh dictAppendWord(dp, "create-file", ficlCreateFile, FW_DEFAULT);
406ca987d46SWarner Losh dictAppendWord(dp, "open-file", ficlOpenFile, FW_DEFAULT);
407ca987d46SWarner Losh dictAppendWord(dp, "close-file", ficlCloseFile, FW_DEFAULT);
408ca987d46SWarner Losh dictAppendWord(dp, "include-file", ficlIncludeFile, FW_DEFAULT);
409ca987d46SWarner Losh dictAppendWord(dp, "read-file", ficlReadFile, FW_DEFAULT);
410ca987d46SWarner Losh dictAppendWord(dp, "read-line", ficlReadLine, FW_DEFAULT);
411ca987d46SWarner Losh dictAppendWord(dp, "write-file", ficlWriteFile, FW_DEFAULT);
412ca987d46SWarner Losh dictAppendWord(dp, "write-line", ficlWriteLine, FW_DEFAULT);
413ca987d46SWarner Losh dictAppendWord(dp, "file-position", ficlFilePosition, FW_DEFAULT);
414ca987d46SWarner Losh dictAppendWord(dp, "file-size", ficlFileSize, FW_DEFAULT);
415ca987d46SWarner Losh dictAppendWord(dp, "reposition-file", ficlRepositionFile, FW_DEFAULT);
416ca987d46SWarner Losh dictAppendWord(dp, "file-status", ficlFileStatus, FW_DEFAULT);
417ca987d46SWarner Losh dictAppendWord(dp, "flush-file", ficlFlushFile, FW_DEFAULT);
418ca987d46SWarner Losh
419ca987d46SWarner Losh dictAppendWord(dp, "delete-file", ficlDeleteFile, FW_DEFAULT);
420ca987d46SWarner Losh dictAppendWord(dp, "rename-file", ficlRenameFile, FW_DEFAULT);
421ca987d46SWarner Losh
422ca987d46SWarner Losh #ifdef FICL_HAVE_FTRUNCATE
423ca987d46SWarner Losh dictAppendWord(dp, "resize-file", ficlResizeFile, FW_DEFAULT);
424ca987d46SWarner Losh
425ca987d46SWarner Losh ficlSetEnv(pSys, "file", FICL_TRUE);
426ca987d46SWarner Losh ficlSetEnv(pSys, "file-ext", FICL_TRUE);
427ca987d46SWarner Losh #endif /* FICL_HAVE_FTRUNCATE */
428ca987d46SWarner Losh #else
429ca987d46SWarner Losh (void)pSys;
430ca987d46SWarner Losh #endif /* FICL_WANT_FILE */
431ca987d46SWarner Losh }
432