17 static void siod_string_print(LISP exp,
EST_String &sd);
21 void pprintf(FILE *fd,LISP exp,
int indent,
int width,
int depth,
int length)
38 if (p.
length() < (size_t) width-indent)
39 fprintf(fd,
"%s",(
const char *)p);
48 pprintf(fd,
car(exp),indent,width,depth-1,length);
49 for (ll=length,l=
cdr(exp); l !=
NIL; l=
cdr(l),ll--)
52 for (i=0; i<indent; i++)
66 pprintf(fd,
car(l),indent,width,depth-1,length);
80 static LISP siod_pprintf(LISP exp, LISP file)
102 static LISP fflush_l(LISP p)
109 fflush(p->storage_as.c_file.f);
113 static void siod_string_print(LISP exp,
EST_String &sd)
125 siod_string_print(
car(exp),sd);
129 siod_string_print(
car(tmp),sd);
134 siod_string_print(tmp,sd);
150 for (i=0; exp->storage_as.string.data[i] !=
'\0'; i++)
152 if (exp->storage_as.string.data[i] ==
'"')
154 if (exp->storage_as.string.data[i] ==
'\\')
156 sprintf(
tkbuffer,
"%c",exp->storage_as.string.data[i]);
174 sd += (*exp).storage_as.subr.name;
178 sprintf(
tkbuffer,
"#<FILE %p ",(
void *)exp->storage_as.c_file.f);
180 if (exp->storage_as.c_file.name)
181 sd += exp->storage_as.c_file.name;
186 siod_string_print(
car((*exp).storage_as.closure.code),sd);
188 siod_string_print(
cdr((*exp).storage_as.closure.code),sd);
201 sprintf(
tkbuffer,
"#<UNKNOWN %d %p>",
TYPE(exp),(
void *)exp);
213 siod_string_print(exp,r);
219 static LISP fd_to_scheme_file(
int fd,
228 sym->storage_as.c_file.f = (FILE *)
NULL;
229 sym->storage_as.c_file.name = (
char *)
NULL;
232 if (fd != fileno(stderr))
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)))
247 err(
"could not open file",
name);
249 strcpy(sym->storage_as.c_file.name,
name);
262 err(
"could not open file", name);
264 sym = fd_to_scheme_file(fd, name, how, 1);
271 return fd_to_scheme_file(fd, name, how, 0);
277 const char *filename =
NULL;
294 filename =
"[tcp connection]";
311 err(
"not openable", what);
314 err(
"can't open", what);
316 return fd_to_scheme_file(fd, filename, r_or_w, 1);
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;}}
338 static void file_prin1(LISP ptr,FILE *
f)
340 name = ptr->storage_as.c_file.name;
342 sprintf(
tkbuffer,
" %p",(
void *)ptr->storage_as.c_file.f);
350 {
if (
NULLP(p) && deflt)
return(deflt);
352 if (!p->storage_as.c_file.f)
err(
"file is closed",p);
353 return(p->storage_as.c_file.f);}
358 return((i == EOF) ?
NIL :
flocons((
double)i));}
381 LISP
lfseek(LISP file,LISP offset,LISP direction)
385 static LISP directory_entries(LISP ldir, LISP lnoflagdir)
398 for(item=entries.head(); item; item = item->next())
401 if (entry !=
"../" && entry !=
"./" && entry !=
".." && entry !=
".")
404 lentries =
cons(litem, lentries);
411 static LISP
fopen_l(LISP what,LISP how)
419 static LISP lfread(LISP size,LISP file)
428 buffer = s->storage_as.string.data;
429 n = s->storage_as.string.dim;
436 ret = fread(buffer,1,n,f);
446 s->storage_as.string.data = buffer;
447 s->storage_as.string.dim = n;}
450 memcpy(s->storage_as.string.data,buffer,ret);
457 static LISP lfwrite(LISP
string,LISP file)
464 data =
string->storage_as.string.data;
465 dim =
string->storage_as.string.dim;
467 fwrite(data,dim,1,f);
511 fput_st(f,(*exp).storage_as.subr.name);
516 lprin1f(
car((*exp).storage_as.closure.code),f);
518 lprin1f(
cdr((*exp).storage_as.closure.code),f);
530 sprintf(
tkbuffer,
"#<UNKNOWN %d %p>",
TYPE(exp),(
void *)exp);
534 static LISP lprintfp(LISP exp,LISP file)
538 static LISP terpri(LISP file)
542 static LISP lreadfp(LISP file)
545 LISP
load(LISP fname,LISP cflag)
559 static LISP probe_file(LISP fname)
562 const char *filename;
565 if (access(filename,R_OK) == 0)
571 static LISP lunlink(LISP
name)
577 static LISP save_forms(LISP fname,LISP forms,LISP how)
579 const char *chow =
NULL;
583 if EQ(how,
NIL) chow =
"wb";
585 else err(
"bad argument to save-forms",how);
591 f = lf->storage_as.c_file.f;
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 :
"");
615 static void check_first_line(FILE *lf)
618 if ((c0=getc(lf)) ==
'#')
620 if ((c1 = getc(lf)) ==
'!')
621 while (((c2=getc(lf)) !=
'\n') && (c2 != EOF));
632 LISP
vload(
const char *fname_raw,
long cflag)
634 LISP form,result,tail,lf;
641 f = lf->storage_as.c_file.f;
652 result = tail = form;
654 tail =
setcdr(tail,form);}
667 fd_to_scheme_file(fileno(stderr),
"stderr",
"w",
FALSE),
NIL);
670 "(fread BUFFER FILE)\n\ 671 BUFFER is a string of length N, N bytes are read from FILE into\n\ 674 "(fwrite BUFFER FILE)\n\ 675 Write BUFFER into FILE.");
679 Read next s-expression from stdin and return it.");
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.");
686 Print DATA to stdout if textual form. Not a pretty printer.");
688 "(pprintf EXP [FD])\n\ 689 Pretty print EXP to FD, if FD is nil print to the screen.");
691 "(printfp DATA FILEP)\n\ 692 Print DATA to file indicated by file pointer FILEP. File pointers are\n\ 693 are created by fopen.");
696 Read and return next s-expression from file indicated by file pointer\n\ 697 FILEP. File pointers are created by fopen.");
700 Print newline to FILEP, is FILEP is nil or not specified a newline it\n\ 701 is printed to stdout.");
704 Flush FILEP. If FILEP is nil, then flush stdout.");
706 "(fopen FILENAME HOW)\n\ 707 Return file pointer for FILENAME opened in mode HOW.");
710 Close filepoint FILEP.");
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.");
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.");
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.");
725 Returns position in file FILEP is currently pointing at.");
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.");
732 "(probe_file FILENAME)\n\ 733 Returns t if FILENAME exists and is readable, nil otherwise.");
735 "(delete-file FILENAME)\n\ 736 Delete named file.");
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.");
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.");
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.");
void pprint_to_fd(FILE *fd, LISP exp)
float end(const EST_Item &item)
#define INTERRUPT_CHECK()
EST_FilePos EST_ftell(FILE *fp)
LISP fopen_l(LISP what, const char *r_or_w)
long int get_c_int(LISP x)
void pprintf(FILE *fd, LISP exp, int indent, int width, int depth, int length)
#define STACK_CHECK(_ptr)
LISP strintern(const char *data)
void init_subr_2(const char *name, LISP(*fcn)(LISP, LISP), const char *doc)
LISP strcons(long length, const char *data)
int fd_open_url(const char *protocol, const char *host, const char *port, const char *path, const char *r_or_w)
EST_TList< EST_String > entries(int check_for_directories=1) const
LISP vload(const char *fname_raw, long cflag)
void set_print_hooks(long type, void(*prin1)(LISP, FILE *), void(*print_string)(LISP, char *))
LISP setcdr(LISP cell, LISP value)
void(* prin1)(LISP, FILE *)
void(* print_string)(LISP, char *)
void err(const char *message, LISP x) EST_NORETURN
int fd_open_file(const char *name, const char *r_or_w)
const char * get_c_string(LISP x)
LISP siod_fdopen_c(int fd, const char *name, char *how)
void init_subrs_file(void)
EST_String siod_sprint(LISP exp)
LISP cintern(const char *name)
LISP cons(LISP x, LISP y)
void fput_st(FILE *f, const char *st)
LISP setvar(LISP var, LISP val, LISP env)
void init_subr_1(const char *name, LISP(*fcn)(LISP), const char *doc)
int EST_fseek(FILE *fp, EST_FilePos offset, int whence)
long no_interrupt(long n)
LISP fopen_c(const char *name, const char *how)
LISP lprin1f(LISP exp, FILE *f)
void init_subr_3(const char *name, LISP(*fcn)(LISP, LISP, LISP), const char *doc)
size_t length(void) const
Length of string ({not} length of underlying chunk)
LISP rintern(const char *name)
LISP leval(LISP x, LISP env)
char * must_malloc(unsigned long size)
void close_open_files_upto(LISP end)
struct user_type_hooks * get_user_type_hooks(long type)
void init_subr_0(const char *name, LISP(*fcn)(void), const char *doc)
FILE * get_c_file(LISP p, FILE *deflt)
LISP load(LISP fname, LISP cflag)
int fd_open_stdinout(const char *r_or_w)
LISP delq(LISP elem, LISP l)
LISP lfseek(LISP file, LISP offset, LISP direction)
EST_Pathname as_directory(void) const
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)
void close_open_files(void)
LISP lputs(LISP str, LISP p)
LISP lputc(LISP c, LISP p)
void put_st(const char *st)