Edinburgh Speech Tools  2.1-release
slib_file.cc
Go to the documentation of this file.
1 /*
2  * COPYRIGHT (c) 1988-1994 BY *
3  * PARADIGM ASSOCIATES INCORPORATED, CAMBRIDGE, MASSACHUSETTS. *
4  * See the source file SLIB.C for more information. *
5 
6  * Reorganization of files (Mar 1999) by Alan W Black <awb@cstr.ed.ac.uk>
7 
8  * File functions
9 
10 */
11 #include <cstdio>
12 #include "siod.h"
13 #include "siodp.h"
14 #include "EST_Pathname.h"
15 #include "EST_File.h"
16 
17 static void siod_string_print(LISP exp, EST_String &sd);
18 
19 LISP open_files = NIL;
20 
21 void pprintf(FILE *fd,LISP exp,int indent,int width, int depth,int length)
22 {
23  // A pretty printer for expressions
24  // indent is the number of spaces to indent by
25  // width is the maximum column we're allow to print to
26  // depth is the we should print before ignoring it
27  // length is the number of items in a list we should print
28  int i,ll;
29  LISP l;
30 
31  if (exp == NIL)
32  fprintf(fd,"nil");
33  else if (!consp(exp))
34  fprintf(fd,"%s",(const char *)siod_sprint(exp));
35  else
36  {
37  EST_String p = siod_sprint(exp);
38  if (p.length() < (size_t) width-indent)
39  fprintf(fd,"%s",(const char *)p);
40  else
41  {
42  fprintf(fd,"(");
43  indent += 1;
44  if (depth == 0)
45  fprintf(fd,"...");
46  else
47  {
48  pprintf(fd,car(exp),indent,width,depth-1,length);
49  for (ll=length,l=cdr(exp); l != NIL; l=cdr(l),ll--)
50  {
51  fprintf(fd,"\n");
52  for (i=0; i<indent; i++)
53  fprintf(fd," ");
54  if (ll == 0)
55  {
56  pprintf(fd,rintern("..."),indent,width,
57  depth-1,length);
58  break;
59  }
60  else if (!consp(l)) // a dotted pair
61  {
62  fprintf(fd," . %s",(const char *)siod_sprint(l));
63  break;
64  }
65  else
66  pprintf(fd,car(l),indent,width,depth-1,length);
67  }
68  }
69  fprintf(fd,")");
70  }
71  }
72 }
73 
74 void pprint_to_fd(FILE *fd,LISP exp)
75 {
76  pprintf(fd,exp,0,72,-1,-1);
77  fprintf(fd,"\n");
78 }
79 
80 static LISP siod_pprintf(LISP exp, LISP file)
81 {
82  // Pretty printer
83 
84  if ((file == NIL) ||
85  (equal(file,rintern("t"))))
86  pprint(exp);
87  else
88  {
89  pprintf(get_c_file(file,stdout),exp,0,72,-1,-1);
90  fprintf(get_c_file(file,stdout),"\n");
91  }
92  return NIL;
93 }
94 
95 void pprint(LISP exp)
96 {
97  // Pretty print this expression to stdout
98 
99  pprint_to_fd(stdout,exp);
100 }
101 
102 static LISP fflush_l(LISP p)
103 {
104  if (p == NIL)
105  fflush(stdout);
106  else if NTYPEP(p,tc_c_file)
107  err("not a file",p);
108  else
109  fflush(p->storage_as.c_file.f);
110  return NIL;
111 }
112 
113 static void siod_string_print(LISP exp, EST_String &sd)
114 {
115  LISP tmp;
116  int i;
117 
118  switch TYPE(exp)
119  {
120  case tc_nil:
121  sd += "nil";
122  break;
123  case tc_cons:
124  sd += "(";
125  siod_string_print(car(exp),sd);
126  for(tmp=cdr(exp);CONSP(tmp);tmp=cdr(tmp))
127  {
128  sd += " ";
129  siod_string_print(car(tmp),sd);
130  }
131  if NNULLP(tmp)
132  {
133  sd += " . ";
134  siod_string_print(tmp,sd);
135  }
136  sd += ")";
137  break;
138  case tc_flonum:
139  if (FLONMPNAME(exp) == NULL)
140  {
141  sprintf(tkbuffer,"%.8g",FLONM(exp));
142  FLONMPNAME(exp) = (char *)must_malloc(strlen(tkbuffer)+1);
143  sprintf(FLONMPNAME(exp),"%s",tkbuffer);
144  }
145  sprintf(tkbuffer,"%s",FLONMPNAME(exp));
146  sd += tkbuffer;
147  break;
148  case tc_string:
149  sd += "\"";
150  for (i=0; exp->storage_as.string.data[i] != '\0'; i++)
151  {
152  if (exp->storage_as.string.data[i] == '"')
153  sd += "\\";
154  if (exp->storage_as.string.data[i] == '\\')
155  sd += "\\";
156  sprintf(tkbuffer,"%c",exp->storage_as.string.data[i]);
157  sd += tkbuffer;
158  }
159  sd += "\"";
160  break;
161  case tc_symbol:
162  sd += PNAME(exp);
163  break;
164  case tc_subr_0:
165  case tc_subr_1:
166  case tc_subr_2:
167  case tc_subr_3:
168  case tc_subr_4:
169  case tc_lsubr:
170  case tc_fsubr:
171  case tc_msubr:
172  sprintf(tkbuffer,"#<SUBR(%d) ",TYPE(exp));
173  sd += tkbuffer;
174  sd += (*exp).storage_as.subr.name;
175  sd += ">";
176  break;
177  case tc_c_file:
178  sprintf(tkbuffer,"#<FILE %p ",(void *)exp->storage_as.c_file.f);
179  sd += tkbuffer;
180  if (exp->storage_as.c_file.name)
181  sd += exp->storage_as.c_file.name;
182  sd += ">";
183  break;
184  case tc_closure:
185  sd += "#<CLOSURE ";
186  siod_string_print(car((*exp).storage_as.closure.code),sd);
187  sd += " ";
188  siod_string_print(cdr((*exp).storage_as.closure.code),sd);
189  sd += ">";
190  break;
191  default:
192  struct user_type_hooks *p;
193  p = get_user_type_hooks(TYPE(exp));
194  if (p->print_string)
195  (*p->print_string)(exp, tkbuffer);
196  else
197  {
198  if (p->name)
199  sprintf(tkbuffer,"#<%s %p>",p->name,(void *)exp);
200  else
201  sprintf(tkbuffer,"#<UNKNOWN %d %p>",TYPE(exp),(void *)exp);
202  }
203  sd += tkbuffer;
204  }
205  return;
206 }
207 
209 {
210  EST_String r;
211 
212  r = "";
213  siod_string_print(exp,r);
214 
215  return r;
216 }
217 
218 
219 static LISP fd_to_scheme_file(int fd,
220  const char *name,
221  const char *how,
222  int close_on_error)
223 {
224  LISP sym;
225  long flag;
226  flag = no_interrupt(1);
227  sym = newcell(tc_c_file);
228  sym->storage_as.c_file.f = (FILE *)NULL;
229  sym->storage_as.c_file.name = (char *)NULL;
230 
231  if (name == NULL) name = "";
232  if (fd != fileno(stderr))
233  open_files = cons(sym,open_files);
234  sym->storage_as.c_file.name = (char *) must_malloc(strlen(name)+1);
235  if (fd == fileno(stdin))
236  sym->storage_as.c_file.f = stdin;
237  else if (fd == fileno(stdout))
238  sym->storage_as.c_file.f = stdout;
239  else if (fd == fileno(stderr))
240  sym->storage_as.c_file.f = stderr;
241  else if (!(sym->storage_as.c_file.f = fdopen(fd ,how)))
242  {
243  if (close_on_error)
244  close(fd);
245  perror(name);
246  put_st("\n");
247  err("could not open file", name);
248  }
249  strcpy(sym->storage_as.c_file.name,name);
250  no_interrupt(flag);
251  return(sym);
252 }
253 
254 LISP fopen_c(const char *name, const char *how)
255 {
256  LISP sym;
257  int fd;
258 
259  fd = fd_open_file(name, how);
260 
261  if (fd < 0)
262  err("could not open file", name);
263 
264  sym = fd_to_scheme_file(fd, name, how, 1);
265 
266  return(sym);
267 }
268 
269 LISP siod_fdopen_c(int fd, const char *name, char *how)
270 {
271  return fd_to_scheme_file(fd, name, how, 0);
272 }
273 
274 LISP fopen_l(LISP what, const char *r_or_w)
275 {
276  int fd = -1;
277  const char *filename = NULL;
278 
279  if (NULLP(what))
280  {
281  filename = "-";
282  fd = fd_open_stdinout(r_or_w);
283  }
284  else if (SYMBOLP(what) || STRINGP(what))
285  {
286  fd = fd_open_file((filename = get_c_string(what)), r_or_w);
287  }
288  else if (LIST1P(what))
289  {
290  fd = fd_open_file((filename = get_c_string(CAR(what))), r_or_w);
291  }
292  else if (CONSP(what) && !CONSP(CDR(what)))
293  {
294  filename = "[tcp connection]";
295  fd = fd_open_url("tcp",
296  get_c_string(CAR(what)),
297  get_c_string(CDR(what)),
298  NULL,
299  r_or_w);
300  }
301  else if (LIST4P(what))
302  {
303  filename = "[url]";
304  fd = fd_open_url(get_c_string(CAR1(what)),
305  get_c_string(CAR2(what)),
306  get_c_string(CAR3(what)),
307  get_c_string(CAR4(what)),
308  r_or_w);
309  }
310  else
311  err("not openable", what);
312 
313  if (fd<0)
314  err("can't open", what);
315 
316  return fd_to_scheme_file(fd, filename, r_or_w, 1);
317 }
318 
319 static void file_gc_free(LISP ptr)
320 {if ((ptr->storage_as.c_file.f) &&
321  (ptr->storage_as.c_file.f != stdin) &&
322  (ptr->storage_as.c_file.f != stdout))
323  {fclose(ptr->storage_as.c_file.f);
324  ptr->storage_as.c_file.f = (FILE *) NULL;}
325  if (ptr->storage_as.c_file.name)
326  {wfree(ptr->storage_as.c_file.name);
327  ptr->storage_as.c_file.name = NULL;}}
328 
329 LISP fclose_l(LISP p)
330 {long flag;
331  flag = no_interrupt(1);
332  if NTYPEP(p,tc_c_file) err("not a file",p);
333  file_gc_free(p);
335  no_interrupt(flag);
336  return(NIL);}
337 
338 static void file_prin1(LISP ptr,FILE *f)
339 {char *name;
340  name = ptr->storage_as.c_file.name;
341  fput_st(f,"#<FILE ");
342  sprintf(tkbuffer," %p",(void *)ptr->storage_as.c_file.f);
343  fput_st(f,tkbuffer);
344  if (name)
345  {fput_st(f," ");
346  fput_st(f,name);}
347  fput_st(f,">");}
348 
349 FILE *get_c_file(LISP p,FILE *deflt)
350 {if (NULLP(p) && deflt) return(deflt);
351  if NTYPEP(p,tc_c_file) err("not a file",p);
352  if (!p->storage_as.c_file.f) err("file is closed",p);
353  return(p->storage_as.c_file.f);}
354 
355 LISP lgetc(LISP p)
356 {int i;
357  i = f_getc(get_c_file(p,stdin));
358  return((i == EOF) ? NIL : flocons((double)i));}
359 
360 LISP lputc(LISP c,LISP p)
361 {long flag;
362  int i;
363  FILE *f;
364  f = get_c_file(p,stdout);
365  if FLONUMP(c)
366  i = (int)FLONM(c);
367  else
368  i = *get_c_string(c);
369  flag = no_interrupt(1);
370  putc(i,f);
371  no_interrupt(flag);
372  return(NIL);}
373 
374 LISP lputs(LISP str,LISP p)
375 {fput_st(get_c_file(p,stdout),get_c_string(str));
376  return(NIL);}
377 
378 LISP lftell(LISP file)
379 {return(flocons((double)EST_ftell(get_c_file(file,NULL))));}
380 
381 LISP lfseek(LISP file,LISP offset,LISP direction)
382 {return((EST_fseek(get_c_file(file,NULL),get_c_int(offset),get_c_int(direction)))
383  ? NIL : truth);}
384 
385 static LISP directory_entries(LISP ldir, LISP lnoflagdir)
386 {
387  LISP lentries=NIL;
388  EST_Pathname dir(get_c_string(ldir));
389 
390  if (dir == "")
391  return NIL;
392 
393  dir = dir.as_directory();
394 
395  EST_StrList entries(dir.entries(lnoflagdir!=NIL?0:1));
396  EST_Litem *item;
397 
398  for(item=entries.head(); item; item = item->next())
399  {
400  EST_String entry(entries(item));
401  if (entry != "../" && entry != "./" && entry != ".." && entry != ".")
402  {
403  LISP litem = strintern(entry);
404  lentries = cons(litem, lentries);
405  }
406  }
407 
408  return lentries;
409 }
410 
411 static LISP fopen_l(LISP what,LISP how)
412 {
413  const char *r_or_w = NULLP(how) ? "rb" : get_c_string(how);
414 
415  return fopen_l(what, r_or_w);
416 
417 }
418 
419 static LISP lfread(LISP size,LISP file)
420 {long flag,n,ret,m;
421  char *buffer;
422  LISP s;
423  FILE *f;
424  f = get_c_file(file,NULL);
425  flag = no_interrupt(1);
426  if TYPEP(size,tc_string)
427  {s = size;
428  buffer = s->storage_as.string.data;
429  n = s->storage_as.string.dim;
430  m = 0;}
431  else
432  {n = get_c_int(size);
433  buffer = (char *) must_malloc(n+1);
434  buffer[n] = 0;
435  m = 1;}
436  ret = fread(buffer,1,n,f);
437  if (ret == 0)
438  {if (m)
439  wfree(buffer);
440  no_interrupt(flag);
441  return(NIL);}
442  if (m)
443  {if (ret == n)
444  {s = cons(NIL,NIL);
445  s->type = tc_string;
446  s->storage_as.string.data = buffer;
447  s->storage_as.string.dim = n;}
448  else
449  {s = strcons(ret,NULL);
450  memcpy(s->storage_as.string.data,buffer,ret);
451  wfree(buffer);}
452  no_interrupt(flag);
453  return(s);}
454  no_interrupt(flag);
455  return(flocons((double)ret));}
456 
457 static LISP lfwrite(LISP string,LISP file)
458 {FILE *f;
459  long flag;
460  char *data;
461  long dim;
462  f = get_c_file(file,NULL);
463  if NTYPEP(string,tc_string) err("not a string",string);
464  data = string->storage_as.string.data;
465  dim = string->storage_as.string.dim;
466  flag = no_interrupt(1);
467  fwrite(data,dim,1,f);
468  no_interrupt(flag);
469  return(NIL);}
470 
471 LISP lprin1f(LISP exp,FILE *f)
472 {LISP tmp;
473  struct user_type_hooks *p;
474  STACK_CHECK(&exp);
475  INTERRUPT_CHECK();
476  switch TYPE(exp)
477  {case tc_nil:
478  fput_st(f,"nil");
479  break;
480  case tc_cons:
481  fput_st(f,"(");
482  lprin1f(car(exp),f);
483  for(tmp=cdr(exp);CONSP(tmp);tmp=cdr(tmp))
484  {fput_st(f," ");lprin1f(car(tmp),f);}
485  if NNULLP(tmp) {fput_st(f," . ");lprin1f(tmp,f);}
486  fput_st(f,")");
487  break;
488  case tc_flonum:
489  if (FLONMPNAME(exp) == NULL)
490  {
491  sprintf(tkbuffer,"%.8g",FLONM(exp));
492  FLONMPNAME(exp) = (char *)must_malloc(strlen(tkbuffer)+1);
493  sprintf(FLONMPNAME(exp),"%s",tkbuffer);
494  }
495  sprintf(tkbuffer,"%s",FLONMPNAME(exp));
496  fput_st(f,tkbuffer);
497  break;
498  case tc_symbol:
499  fput_st(f,PNAME(exp));
500  break;
501  case tc_subr_0:
502  case tc_subr_1:
503  case tc_subr_2:
504  case tc_subr_3:
505  case tc_subr_4:
506  case tc_lsubr:
507  case tc_fsubr:
508  case tc_msubr:
509  sprintf(tkbuffer,"#<SUBR(%d) ",TYPE(exp));
510  fput_st(f,tkbuffer);
511  fput_st(f,(*exp).storage_as.subr.name);
512  fput_st(f,">");
513  break;
514  case tc_closure:
515  fput_st(f,"#<CLOSURE ");
516  lprin1f(car((*exp).storage_as.closure.code),f);
517  fput_st(f," ");
518  lprin1f(cdr((*exp).storage_as.closure.code),f);
519  fput_st(f,">");
520  break;
521  default:
522  p = get_user_type_hooks(TYPE(exp));
523  if (p->prin1)
524  (*p->prin1)(exp,f);
525  else
526  {
527  if (p->name)
528  sprintf(tkbuffer,"#<%s %p>",p->name,USERVAL(exp));
529  else
530  sprintf(tkbuffer,"#<UNKNOWN %d %p>",TYPE(exp),(void *)exp);
531  fput_st(f,tkbuffer);}}
532  return(NIL);}
533 
534 static LISP lprintfp(LISP exp,LISP file)
535 {lprin1f(exp,get_c_file(file,stdout));
536  return(NIL);}
537 
538 static LISP terpri(LISP file)
539 {fput_st(get_c_file(file,stdout),"\n");
540  return(NIL);}
541 
542 static LISP lreadfp(LISP file)
543 {return lreadf(get_c_file(file,stdout));}
544 
545 LISP load(LISP fname,LISP cflag)
546 {return(vload(get_c_string(fname),NULLP(cflag) ? 0 : 1));}
547 
548 LISP lprint(LISP exp)
549 {lprin1f(exp,stdout);
550  put_st("\n");
551  return(NIL);}
552 
553 LISP lread(void)
554 {return(lreadf(stdin));}
555 
556 LISP get_eof_val(void)
557 {return(eof_val);}
558 
559 static LISP probe_file(LISP fname)
560 {
561  // return t if file exists, nil otherwise
562  const char *filename;
563 
564  filename = get_c_string(fname);
565  if (access(filename,R_OK) == 0)
566  return truth;
567  else
568  return NIL;
569 }
570 
571 static LISP lunlink(LISP name)
572 {
573  unlink(get_c_string(name));
574  return NIL;
575 }
576 
577 static LISP save_forms(LISP fname,LISP forms,LISP how)
578 {const char *cname;
579  const char *chow = NULL;
580  LISP l,lf;
581  FILE *f;
582  cname = get_c_string(fname);
583  if EQ(how,NIL) chow = "wb";
584  else if EQ(how,cintern("a")) chow = "a";
585  else err("bad argument to save-forms",how);
586  fput_st(fwarn,(*chow == 'a') ? "appending" : "saving");
587  fput_st(fwarn," forms to ");
588  fput_st(fwarn,cname);
589  fput_st(fwarn,"\n");
590  lf = fopen_c(cname,chow);
591  f = lf->storage_as.c_file.f;
592  for(l=forms;NNULLP(l);l=cdr(l))
593  {lprin1f(car(l),f);
594  putc('\n',f);}
595  fclose_l(lf);
596  fput_st(fwarn,"done.\n");
597  return(truth);}
598 
600 {LISP l,p;
601  for(l=open_files;((l!=end)&&(l!=NIL));l=cdr(l))
602  {p = car(l);
603  if (p->storage_as.c_file.f)
604  {fprintf(stderr,"closing a file left open: %s\n",
605  (p->storage_as.c_file.name) ? p->storage_as.c_file.name : "");
606  fflush(stderr);
607  file_gc_free(p);}}
608  open_files = l;}
609 
611 {
613 }
614 
615 static void check_first_line(FILE *lf)
616 { /* If this line starts #! skip it -- this is for scripts */
617  int c0,c1,c2;
618  if ((c0=getc(lf)) == '#')
619  {
620  if ((c1 = getc(lf)) == '!')
621  while (((c2=getc(lf)) != '\n') && (c2 != EOF)); /* skip to EOLN */
622  else
623  {
624  ungetc(c1,lf);
625  ungetc(c0,lf); /* possibly something don't support 2 ungets */
626  }
627  }
628  else
629  ungetc(c0,lf);
630 }
631 
632 LISP vload(const char *fname_raw, long cflag)
633 {
634  LISP form,result,tail,lf;
635  FILE *f;
636  EST_Pathname fname(fname_raw);
637  fput_st(fwarn,"loading ");
638  fput_st(fwarn,fname);
639  fput_st(fwarn,"\n");
640  lf = fopen_c(fname,"rb");
641  f = lf->storage_as.c_file.f;
642  if (!cflag)
643  check_first_line(f);
644  result = NIL;
645  tail = NIL;
646  while(1)
647  {form = lreadf(f);
648  if EQ(form,eof_val) break;
649  if (cflag)
650  {form = cons(form,NIL);
651  if NULLP(result)
652  result = tail = form;
653  else
654  tail = setcdr(tail,form);}
655  else
656  leval(form,NIL);}
657  fclose_l(lf);
658  fput_st(fwarn,"done.\n");
659  return(result);}
660 
661 void init_subrs_file(void)
662 {
663  long j;
664  set_gc_hooks(tc_c_file,FALSE,NULL,NULL,NULL,file_gc_free,NULL,&j);
665  set_print_hooks(tc_c_file,file_prin1, NULL);
666  setvar(cintern("stderr"),
667  fd_to_scheme_file(fileno(stderr),"stderr","w",FALSE),NIL);
668 
669  init_subr_2("fread",lfread,
670  "(fread BUFFER FILE)\n\
671  BUFFER is a string of length N, N bytes are read from FILE into\n\
672  BUFFER.");
673  init_subr_2("fwrite",lfwrite,
674  "(fwrite BUFFER FILE)\n\
675  Write BUFFER into FILE.");
676 
677  init_subr_0("read",lread,
678  "(read)\n\
679  Read next s-expression from stdin and return it.");
680  init_subr_0("eof-val",get_eof_val,
681  "(eof_val)\n\
682  Returns symbol used to indicate end of file. May be used (with eq?)\n\
683  to determine when end of file occurs while reading files.");
684  init_subr_1("print",lprint,
685  "(print DATA)\n\
686  Print DATA to stdout if textual form. Not a pretty printer.");
687  init_subr_2("pprintf",siod_pprintf,
688  "(pprintf EXP [FD])\n\
689  Pretty print EXP to FD, if FD is nil print to the screen.");
690  init_subr_2("printfp",lprintfp,
691  "(printfp DATA FILEP)\n\
692  Print DATA to file indicated by file pointer FILEP. File pointers are\n\
693  are created by fopen.");
694  init_subr_1("readfp",lreadfp,
695  "(readfp FILEP)\n\
696  Read and return next s-expression from file indicated by file pointer\n\
697  FILEP. File pointers are created by fopen.");
698  init_subr_1("terpri",terpri,
699  "(terpri FILEP)\n\
700  Print newline to FILEP, is FILEP is nil or not specified a newline it\n\
701  is printed to stdout.");
702  init_subr_1("fflush",fflush_l,
703  "(fflush FILEP)\n\
704  Flush FILEP. If FILEP is nil, then flush stdout.");
705  init_subr_2("fopen",fopen_l,
706  "(fopen FILENAME HOW)\n\
707  Return file pointer for FILENAME opened in mode HOW.");
708  init_subr_1("fclose",fclose_l,
709  "(fclose FILEP)\n\
710  Close filepoint FILEP.");
711  init_subr_1("getc",lgetc,
712  "(getc FILEP)\n\
713  Get next character from FILEP. Character is returned as a number. If\n\
714  FILEP is nil, or not specified input comes from stdin.");
715  init_subr_2("putc",lputc,
716  "(putc ECHAR FILEP)\n\
717  Put ECHAR (a number) as a character to FILEP. If FILEP is nil or not\n\
718  specified output goes to stdout.");
719  init_subr_2("puts",lputs,
720  "(puts STRING FILEP)\n\
721  Write STRING (print name of symbol) to FILEP. If FILEP is nil or not\n\
722  specified output goes to stdout.");
723  init_subr_1("ftell",lftell,
724  "(ftell FILEP)\n\
725  Returns position in file FILEP is currently pointing at.");
726  init_subr_3("fseek",lfseek,
727  "(fseek FILEP OFFSET DIRECTION)\n\
728  Position FILEP to OFFSET. If DIRECTION is 0 offset is from start of file.\n\
729  If DIRECTION is 1, offset is from current position. If DIRECTION is\n\
730  2 offset is from end of file.");
731  init_subr_1("probe_file",probe_file,
732  "(probe_file FILENAME)\n\
733  Returns t if FILENAME exists and is readable, nil otherwise.");
734  init_subr_1("delete-file",lunlink,
735  "(delete-file FILENAME)\n\
736  Delete named file.");
737  init_subr_2("load",load,
738  "(load FILENAME OPTION)\n\
739  Load s-expressions in FILENAME. If OPTION is nil or unspecified evaluate\n\
740  each s-expression in FILENAME as it is read, if OPTION is t, return them\n\
741  unevaluated in a list.");
742 
743  init_subr_2("directory-entries", directory_entries,
744  "(directory-entries DIRECTORY &opt NOFLAGDIR)\n\
745  Return a list of the entries in the directory. If NOFLAGDIR is non-null\n\
746  don't check to see which are directories.");
747 
748  init_subr_3("save-forms",save_forms,
749  "(save-forms FILENAME FORMS HOW)\n\
750  Save FORMS in FILENAME. If HOW is a appending FORMS to FILENAME,\n\
751  or if HOW is w start from the beginning of FILENAME.");
752 }
#define CAR1(x)
Definition: siod_defs.h:165
void pprint_to_fd(FILE *fd, LISP exp)
Definition: slib_file.cc:74
LISP lgetc(LISP p)
Definition: slib_file.cc:355
float end(const EST_Item &item)
Definition: EST_item_aux.cc:96
#define tc_fsubr
Definition: siod_defs.h:112
#define NTYPEP(x, y)
Definition: siod_defs.h:101
void pprint(LISP exp)
Definition: slib_file.cc:95
#define INTERRUPT_CHECK()
Definition: siodp.h:87
LISP lread(void)
Definition: slib_file.cc:553
EST_FilePos EST_ftell(FILE *fp)
Definition: EST_File.h:71
LISP fopen_l(LISP what, const char *r_or_w)
Definition: slib_file.cc:274
#define tc_symbol
Definition: siod_defs.h:106
#define NULLP(x)
Definition: siod_defs.h:95
LISP lprint(LISP exp)
Definition: slib_file.cc:548
long int get_c_int(LISP x)
Definition: slib.cc:1850
void pprintf(FILE *fd, LISP exp, int indent, int width, int depth, int length)
Definition: slib_file.cc:21
#define NIL
Definition: siod_defs.h:92
#define STACK_CHECK(_ptr)
Definition: siodp.h:94
LISP strintern(const char *data)
Definition: slib_str.cc:22
void init_subr_2(const char *name, LISP(*fcn)(LISP, LISP), const char *doc)
Definition: slib.cc:900
LISP strcons(long length, const char *data)
Definition: slib_str.cc:27
int fd_open_url(const char *protocol, const char *host, const char *port, const char *path, const char *r_or_w)
Definition: io.cc:354
#define EQ(x, y)
Definition: siod_defs.h:93
#define SYMBOLP(x)
Definition: siod_defs.h:155
LISP newcell(long type)
Definition: slib.cc:668
EST_TList< EST_String > entries(int check_for_directories=1) const
#define tc_flonum
Definition: siod_defs.h:105
LISP vload(const char *fname_raw, long cflag)
Definition: slib_file.cc:632
void set_print_hooks(long type, void(*prin1)(LISP, FILE *), void(*print_string)(LISP, char *))
Definition: slib.cc:1486
LISP setcdr(LISP cell, LISP value)
Definition: slib_list.cc:58
#define TYPE(x)
Definition: siod_defs.h:98
LISP equal(LISP, LISP)
Definition: slib_list.cc:133
int f_getc(FILE *f)
Definition: slib.cc:1517
#define tc_c_file
Definition: siod_defs.h:120
void(* prin1)(LISP, FILE *)
Definition: siodp.h:50
void(* print_string)(LISP, char *)
Definition: siodp.h:51
#define PNAME(x)
Definition: siod_defs.h:78
void err(const char *message, LISP x) EST_NORETURN
Definition: slib.cc:608
LISP lreadf(FILE *f)
Definition: slib.cc:1582
int fd_open_file(const char *name, const char *r_or_w)
Definition: io.cc:209
const char * get_c_string(LISP x)
Definition: slib.cc:638
LISP siod_fdopen_c(int fd, const char *name, char *how)
Definition: slib_file.cc:269
void init_subrs_file(void)
Definition: slib_file.cc:661
#define tc_lsubr
Definition: siod_defs.h:111
EST_String siod_sprint(LISP exp)
Definition: slib_file.cc:208
#define tc_msubr
Definition: siod_defs.h:113
LISP cintern(const char *name)
Definition: slib.cc:728
LISP cons(LISP x, LISP y)
Definition: slib_list.cc:97
void fput_st(FILE *f, const char *st)
Definition: slib.cc:450
#define LIST1P(x)
Definition: siod_defs.h:177
LISP fclose_l(LISP p)
Definition: slib_file.cc:329
LISP setvar(LISP var, LISP val, LISP env)
Definition: slib_core.cc:18
#define tc_nil
Definition: siod_defs.h:103
#define CAR4(x)
Definition: siod_defs.h:171
LISP open_files
Definition: slib_file.cc:19
#define STRINGP(x)
Definition: siod_defs.h:156
#define tc_cons
Definition: siod_defs.h:104
#define FLONUMP(x)
Definition: siod_defs.h:154
#define FALSE
Definition: EST_bool.h:119
#define tc_subr_0
Definition: siod_defs.h:107
NULL
Definition: EST_WFST.cc:55
LISP consp(LISP x)
Definition: slib_list.cc:112
LISP eof_val
Definition: slib.cc:136
f
Definition: EST_item_aux.cc:48
void init_subr_1(const char *name, LISP(*fcn)(LISP), const char *doc)
Definition: slib.cc:898
int EST_fseek(FILE *fp, EST_FilePos offset, int whence)
Definition: EST_File.h:75
long no_interrupt(long n)
Definition: slib.cc:275
#define CAR3(x)
Definition: siod_defs.h:169
LISP fopen_c(const char *name, const char *how)
Definition: slib_file.cc:254
#define tc_subr_3
Definition: siod_defs.h:110
getString int
Definition: EST_item_aux.cc:50
LISP lprin1f(LISP exp, FILE *f)
Definition: slib_file.cc:471
#define tc_closure
Definition: siod_defs.h:114
#define CAR2(x)
Definition: siod_defs.h:167
#define TYPEP(x, y)
Definition: siod_defs.h:100
#define CAR(x)
Definition: siod_defs.h:76
char * name
Definition: siodp.h:43
LISP lftell(LISP file)
Definition: slib_file.cc:378
#define tc_string
Definition: siod_defs.h:116
void init_subr_3(const char *name, LISP(*fcn)(LISP, LISP, LISP), const char *doc)
Definition: slib.cc:902
FILE * fwarn
Definition: slib.cc:163
size_t length(void) const
Length of string ({not} length of underlying chunk)
Definition: EST_String.h:231
LISP rintern(const char *name)
Definition: slib.cc:734
#define tc_subr_2
Definition: siod_defs.h:109
LISP leval(LISP x, LISP env)
Definition: slib.cc:1378
#define tc_subr_4
Definition: siod_defs.h:122
char * must_malloc(unsigned long size)
Definition: slib.cc:693
LISP get_eof_val(void)
Definition: slib_file.cc:556
#define LIST4P(x)
Definition: siod_defs.h:180
void close_open_files_upto(LISP end)
Definition: slib_file.cc:599
char * tkbuffer
Definition: slib.cc:122
struct user_type_hooks * get_user_type_hooks(long type)
Definition: slib.cc:913
void init_subr_0(const char *name, LISP(*fcn)(void), const char *doc)
Definition: slib.cc:896
LISP flocons(double x)
Definition: slib.cc:673
FILE * get_c_file(LISP p, FILE *deflt)
Definition: slib_file.cc:349
LISP load(LISP fname, LISP cflag)
Definition: slib_file.cc:545
#define tc_subr_1
Definition: siod_defs.h:108
int fd_open_stdinout(const char *r_or_w)
Definition: io.cc:191
LISP car(LISP x)
Definition: slib_list.cc:115
#define USERVAL(x)
Definition: siod_defs.h:89
LISP delq(LISP elem, LISP l)
Definition: slib_list.cc:62
LISP lfseek(LISP file, LISP offset, LISP direction)
Definition: slib_file.cc:381
LISP truth
Definition: slib.cc:135
EST_Pathname as_directory(void) const
void wfree(void *p)
Definition: walloc.c:131
#define FLONMPNAME(x)
Definition: siod_defs.h:88
void set_gc_hooks(long type, int gc_free_once, LISP(*rel)(LISP), LISP(*mark)(LISP), void(*scan)(LISP), void(*free)(LISP), void(*clear)(LISP), long *kind)
Definition: slib.cc:946
void close_open_files(void)
Definition: slib_file.cc:610
LISP lputs(LISP str, LISP p)
Definition: slib_file.cc:374
#define CONSP(x)
Definition: siod_defs.h:153
LISP lputc(LISP c, LISP p)
Definition: slib_file.cc:360
LISP cdr(LISP x)
Definition: slib_list.cc:124
#define CDR(x)
Definition: siod_defs.h:77
void put_st(const char *st)
Definition: slib.cc:460
#define FLONM(x)
Definition: siod_defs.h:87
#define NNULLP(x)
Definition: siod_defs.h:96