/* * NAME: kfun->compile_object() * DESCRIPTION: compile an object */ int kf_compile_object(frame *f, int nargs) { char file[STRINGSZ]; value *v; object *obj; string **strs; int i; v = &f->sp[nargs - 1]; if (path_string(file, v->u.string->text, v->u.string->len) == (char *) NULL) { return 1; } obj = o_find(file, OACC_MODIFY); if (obj != (object *) NULL) { if (!(obj->flags & O_MASTER)) { error("Cannot recompile cloned object"); } if (O_UPGRADING(obj)) { error("Object is already being upgraded"); } if (O_INHERITED(obj)) { error("Cannot recompile inherited object"); } } if (--nargs != 0) { strs = ALLOCA(string*, nargs); for (i = nargs, v = f->sp; i > 0; --i) { *strs++ = (v++)->u.string; } if (ec_push((ec_ftn) NULL)) { AFREE(strs - nargs); error((char *) NULL); } } else {
/* * NAME: io_save() * DESCRIPTION: write a range of lines to a file */ bool io_save(editbuf *eb, char *fname, Int first, Int last, int append, io *iobuf) { char buf[BUF_SIZE]; struct stat sbuf; if (path_ed_write(filename, fname) == (char *) NULL || (P_stat(filename, &sbuf) >= 0 && (sbuf.st_mode & S_IFMT) != S_IFREG)) { return FALSE; } /* create file */ ffd = P_open(filename, (append) ? O_CREAT | O_APPEND | O_WRONLY | O_BINARY : O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0664); if (ffd < 0) { return FALSE; } /* initialize buffer */ buffer = buf; inbuf = 0; /* initialize statistics */ iostat = iobuf; iostat->lines = 0; iostat->chars = 0; iostat->zero = 0; iostat->split = 0; iostat->ill = FALSE; /* write range */ if (ec_push((ec_ftn) NULL)) { P_close(ffd); error((char *) NULL); /* pass on error */ } eb_range(eb, first, last, put_line, FALSE); if (P_write(ffd, buffer, inbuf) != inbuf) { error("error while writing file \"/%s\"", filename); } ec_pop(); P_close(ffd); return TRUE; }
void ec_push(const char *fcn, const char *file, int line, const char *str, int errno_arg, EC_ERRTYPE type) { struct ec_node node, *p; size_t len; static bool attexit_called = false; ec_mutex(true); node.ec_errno = errno_arg; node.ec_type = type; if (str == NULL) str = ""; len = strlen(fcn) + strlen(SEP1) + strlen(file) + strlen(SEP2) + 6 + strlen(SEP3) + strlen(str) + 1; node.ec_context = (char *)calloc(1, len); if (node.ec_context == NULL) { if (ec_s_emergency[0] == '\0') node.ec_context = ec_s_emergency; else node.ec_context = "?"; len = sizeof(ec_s_emergency); } if (node.ec_context != NULL) snprintf(node.ec_context, len, "%s%s%s%s%d%s%s", fcn, SEP1, file, SEP2, line, SEP3, str); p = (struct ec_node *)calloc(1, sizeof(struct ec_node)); if (p == NULL && ec_node_emergency.ec_context == NULL) p = &ec_node_emergency; /* use just once */ if (p != NULL) { node.ec_next = ec_head; ec_head = p; *ec_head = node; } if (!attexit_called) { attexit_called = true; ec_mutex(false); if (atexit(ec_atexit_fcn) != 0) { ec_push(fcn, file, line, "atexit failed", errno, EC_ERRNO); ec_print(); /* so at least the error gets shown */ } } else ec_mutex(false); }
/* * NAME: io_load() * DESCRIPTION: append block read from file after a line */ bool io_load(editbuf *eb, char *fname, Int l, io *iobuf) { char b[MAX_LINE_SIZE], buf[BUF_SIZE]; struct stat sbuf; /* open file */ if (path_ed_read(filename, fname) == (char *) NULL || P_stat(filename, &sbuf) < 0 || (sbuf.st_mode & S_IFMT) != S_IFREG) { return FALSE; } ffd = P_open(filename, O_RDONLY | O_BINARY, 0); if (ffd < 0) { return FALSE; } /* initialize buffers */ buffer = buf; inbuf = 0; lbuf = b; lbuflast = &b[MAX_LINE_SIZE - 1]; /* initialize statistics */ iostat = iobuf; iostat->lines = 0; iostat->chars = 0; iostat->zero = 0; iostat->split = 0; iostat->ill = FALSE; /* add the block to the edit buffer */ if (ec_push((ec_ftn) NULL)) { P_close(ffd); error((char *) NULL); /* pass on error */ } eb_add(eb, l, get_line); ec_pop(); P_close(ffd); return TRUE; }