NODE *lclose(NODE *arg) { FILE *tmp; NODE *margs; if ((tmp = find_file(car(arg), TRUE)) == NULL) err_logo(NOT_OPEN_ERROR, car(arg)); else if (is_list (car(arg))) { margs = cons(caar(arg), cons(make_strnode((char *)tmp, NULL, strlen((char *)tmp), STRING, strnzcpy), NIL)); lmake(margs); free((char *)tmp); } else fclose(tmp); if ((is_list(car(arg)) && car(arg) == writer_name) || (!is_list(car(arg)) && (compare_node(car(arg), writer_name, FALSE) == 0))) { writer_name = NIL; writestream = stdout; } if ((is_list(car(arg)) && car(arg) == reader_name) || (!is_list(car(arg)) && (compare_node(car(arg), reader_name, FALSE) == 0))) { reader_name = NIL; readstream = stdin; } return(UNBOUND); }
llist *read_mbox(char *fname) { FILE *f; llist *headers; char *buf = (char *) malloc(MAX_FBUFFER_SIZE); f = fopen(fname, "r"); if (!f) return(NULL); headers = lmake(sizeof(msg_header)); if (!headers) return(NULL); while (!feof(f)) { fgets(buf, MAX_FBUFFER_SIZE, f); strchop(buf); if (ishead(buf)) { parse_header(f, headers); /* put_it("found header %d", headers->length);*/ } } fclose(f); return(headers); }
NODE *lsetwrite(NODE *arg) { FILE *tmp; NODE *margs; if (writestream == NULL) { /* Any setwrite finishes earlier write to string */ *print_stringptr = '\0'; writestream = stdout; if (find_file(writer_name, FALSE) == NULL) { /* pre-5.4 compatibility mode, implicitly close string */ margs = cons(car(writer_name), cons(make_strnode(write_buf, NULL, strlen(write_buf), STRING, strnzcpy), NIL)); lmake(margs); free(write_buf); } writer_name = NIL; } if (car(arg) == NIL) { writestream = stdout; writer_name = NIL; } else if (is_list(car(arg))) { /* print to string */ FIXNUM i = int_arg(cdar(arg)); if ((tmp = find_file(car(arg), FALSE)) != NULL) { writestream = NULL; writer_name = car(arg); print_stringptr = (char *)tmp + strlen((char *)tmp); print_stringlen = i - strlen((char *)tmp); } else if (NOT_THROWING && i > 0 && cddr(car(arg)) == NIL) { writestream = NULL; writer_name = copy_list(car(arg)); print_stringptr = write_buf = (char *)malloc(i); print_stringlen = i; } else err_logo(BAD_DATA_UNREC, car(arg)); } else if ((tmp = find_file(car(arg), FALSE)) != NULL) { writestream = tmp; writer_name = car(arg); } else err_logo(NOT_OPEN_ERROR, car(arg)); return(UNBOUND); }