void free_attribs(BUFFER *bp) { AREGION *p, *q; beginDisplay(); p = bp->b_attribs; while (p != NULL) { q = p->ar_next; #if OPT_HYPERTEXT FreeAndNull(p->ar_hypercmd); #endif if (p == &selregion) selbufp = NULL; else if (p == &startregion) startbufp = NULL; else free((char *) p); p = q; } bp->b_attribs = NULL; free_line_attribs(bp); endofDisplay(); }
void free_attrib2(BUFFER *bp, AREGION ** rpp) { AREGION *ap = *rpp; AREGION *next = ap->ar_next; /* The caller already has found the right value for 'rpp', * so there is no need to call detach_attrib() to find it. */ mark_buffers_windows(bp); ap->ar_region.r_attr_id = 0; beginDisplay(); #if OPT_HYPERTEXT FreeAndNull(ap->ar_hypercmd); #endif if (ap == &selregion) selbufp = NULL; else if (ap == &startregion) startbufp = NULL; else free((char *) ap); endofDisplay(); /* finally, delink the region */ *rpp = next; }
static void old_tags(BI_NODE * a) { beginDisplay(); FreeIfNeeded(BI_KEY(a)); FreeIfNeeded(TYPECAST(char, a)); endofDisplay(); }
void Trace(const char *fmt,...) { static int nested; int save_err; va_list ap; static FILE *fp; #if SYS_WINNT HANDLE myMutex = CreateMutex(NULL, FALSE, NULL); WaitForSingleObject(myMutex, INFINITE); #endif if (!nested++) { beginDisplay(); save_err = errno; va_start(ap, fmt); if (fmt != bad_form) { if (fp == NULL) fp = fopen("Trace.out", "w"); if (fp == NULL) abort(); fprintf(fp, "%s", trace_indent(trace_depth, '|')); if (!strncmp(fmt, T_CALLED, T_LENGTH)) { begin_elapsed(fmt); ++trace_depth; } else if (!strncmp(fmt, T_RETURN, T_LENGTH)) { if (trace_depth == 0) { fprintf(fp, "BUG: called/return mismatch\n"); } else { end_elapsed(); --trace_depth; } } vfprintf(fp, fmt, ap); (void) fflush(fp); } else if (fp != 0) { fprintf(fp, "%s", trace_indent(trace_depth, '|')); fprintf(fp, T_RETURN "(close)\n"); (void) fclose(fp); (void) fflush(stdout); (void) fflush(stderr); trace_depth = 0; } va_end(ap); errno = save_err; endofDisplay(); } --nested; #if SYS_WINNT ReleaseMutex(myMutex); CloseHandle(myMutex); #endif }
static void old_elapsed(BI_NODE * a) { beginDisplay(); if (a != 0) { FreeIfNeeded(BI_KEY(a)); FreeIfNeeded(a->value.data); free(a); } endofDisplay(); }
static AREGION * alloc_AREGION(void) { AREGION *arp; beginDisplay(); if ((arp = typealloc(AREGION)) == NULL) { (void) no_memory("AREGION"); } endofDisplay(); return arp; }
int system_SHELL(char *cmd) { int cpid; TRACE(("system_SHELL(%s)\n", NONNULL(cmd))); cpid = softfork(); if (cpid < 0) { IGNORE_RC(write(2, "cannot fork\n", (size_t) 13)); return cpid; } if (cpid) { /* parent */ int child; int status; beginDisplay(); while ((child = wait(&status)) != cpid) { if (child < 0 && errno == EINTR) { (void) kill(SIGKILL, cpid); } } endofDisplay(); #if VILE_SOMEDAY shellstatus = process_exit_status(status); #endif return 0; } else { beginDisplay(); exec_sh_c(cmd); IGNORE_RC(write(2, "cannot exec\n", (size_t) 13)); endofDisplay(); return -1; } }
static void SetEnv(char **namep, const char *value) { char *newvalue; beginDisplay(); if (*namep == 0 || strcmp(*namep, value)) { if ((newvalue = strmalloc(value)) != 0) { #if OPT_EVAL && OPT_SHELL FreeIfNeeded(*namep); #endif *namep = newvalue; } } endofDisplay(); }
static BI_NODE * new_tags(BI_DATA * a) { BI_NODE *p; beginDisplay(); if ((p = typecalloc(BI_NODE)) != 0) { p->value = *a; if ((BI_KEY(p) = strmalloc(a->bi_key)) == 0) { old_tags(p); p = 0; } } endofDisplay(); return p; }
int var_CRYPTKEY(TBUFF **rp, const char *vp) { if (rp) { tb_scopy(rp, WRITE_ONLY); return TRUE; } else if (vp) { beginDisplay(); FreeIfNeeded(cryptkey); cryptkey = typeallocn(char, NKEYLEN); endofDisplay(); if (cryptkey == 0) return no_memory("var_CRYPTKEY"); vl_make_encrypt_key(cryptkey, vp); return TRUE; } else { return FALSE;
static BI_NODE * new_elapsed(BI_DATA * a) { BI_NODE *p; beginDisplay(); if ((p = typecalloc(BI_NODE)) != 0) { BI_DATA *q = &(p->value); if ((BI_KEY(p) = strmalloc(a->bi_key)) == 0 || (q->data = typecalloc(ELAPSED_DATA)) == 0) { old_elapsed(p); p = 0; } } endofDisplay(); return p; }
static int any_rw_EXPR(TBUFF **rp, const char *vp, TBUFF **value) { if (rp) { if (value != 0) { tb_copy(rp, *value); return TRUE; } } else if (vp) { regexp *exp = regcomp(vp, strlen(vp), TRUE); if (exp != 0) { beginDisplay(); free(exp); endofDisplay(); tb_scopy(value, vp); return TRUE; } } return FALSE; }
int inout_popen(FILE **fr, FILE **fw, char *cmd) { int rp[2]; int wp[2]; if (pipe(rp)) return FALSE; if (pipe(wp)) return FALSE; pipe_pid = softfork(); if (pipe_pid < 0) return FALSE; ffstatus = file_is_pipe; fileeof = FALSE; if (pipe_pid) { /* parent */ if (fr) { *fr = fdopen(rp[0], "r"); if (*fr == NULL) { (void) fprintf(stderr, "fdopen r failed\n"); abort(); } } else { (void) close(rp[0]); } (void) close(rp[1]); if (fw) { *fw = fdopen(wp[1], "w"); if (*fw == NULL) { (void) fprintf(stderr, "fdopen w failed\n"); abort(); } } else { (void) close(wp[1]); } (void) close(wp[0]); return TRUE; } else { /* child */ beginDisplay(); append_libdir_to_path(); if (fw) { (void) close(0); if (dup(wp[0]) != 0) { IGNORE_RC(write(2, "dup 0 failed\r\n", (size_t) 15)); exit(-1); } } (void) close(wp[1]); if (fr) { (void) close(1); if (dup(rp[1]) != 1) { IGNORE_RC(write(2, "dup 1 failed\r\n", (size_t) 15)); exit(-1); } (void) close(2); if (dup(rp[1]) != 2) { IGNORE_RC(write(1, "dup 2 failed\r\n", (size_t) 15)); exit(-1); } } else { (void) close(rp[1]); } (void) close(rp[0]); exec_sh_c(cmd); endofDisplay(); } return TRUE; }
/* * readpattern -- read a pattern. if it is the * search string, recompile it. * pattern not updated if the user types in an empty line. */ int readpattern(const char *prompt, TBUFF **apat, regexp ** srchexpp, int c, int fromscreen) { char temp[NPAT]; int status; TRACE((T_CALLED "readpattern(%s, %s, %p, %d, %d)\n", prompt ? prompt : "", tb_visible(*apat), (void *) srchexpp, c, fromscreen)); if (fromscreen) { if ((status = screen_to_ident(temp, sizeof(temp))) == TRUE) { if (tb_init(apat, EOS) == 0 || tb_bappend(apat, temp, strlen(temp)) == 0) { status = FALSE; } } if (status != TRUE) returnCode(status); } else { /* don't expand #, %, :, and never process backslashes since they're handled by regexp directly for the search pattern, and in delins() for the replacement pattern */ hst_glue(c); /* * kbd_reply() expects a trailing null, to simplify calls from * kbd_string(). */ if (tb_values(*apat) != 0) tb_append(apat, EOS); status = kbd_reply(prompt, apat, eol_history, c, KBD_EXPPAT | KBD_0CHAR, no_completion); if (tb_length(*apat) != 0) tb_unput(*apat); /* trim the trailing null */ } if (status == TRUE) { if (srchexpp) { /* compile it */ beginDisplay(); FreeIfNeeded(*srchexpp); endofDisplay(); *srchexpp = regcomp(tb_values(*apat), tb_length(*apat), b_val(curbp, MDMAGIC)); if (!*srchexpp) returnCode(FALSE); } } else if (status == FALSE && tb_length(*apat) != 0) { /* Old one */ status = TRUE; } returnCode(status); }
/* * This is invoked as a wrapper for 'kbd_putc()'. It writes to the Messages * scratch buffer, and also to the message line. If the Messages buffer isn't * visible, it is automatically popped up when a new message line is begun. * Since it's a scratch buffer, popping it down destroys it. */ int msg_putc(int c) { BUFFER *savebp = curbp; WINDOW *savewp = curwp; MARK savemk; int saverow = ttrow; int savecol = ttcol; register BUFFER *bp; register WINDOW *wp; if ((bp = create_msgs()) == 0) return TRUE; savemk = DOT; beginDisplay(); /* * Modify the current-buffer state as unobtrusively as possible (i.e., * don't modify the buffer order, and don't make the buffer visible if * it isn't already!). To use the 'bputc()' logic, though, we've got * to have a window, even if it's not real. */ curbp = bp; if ((wp = bp2any_wp(bp)) == NULL) { static WINDOW dummy; wp = &dummy; wp->w_bufp = bp; } curwp = wp; DOT.l = lback(buf_head(bp)); DOT.o = llength(DOT.l); /* * Write into the [Messages]-buffer */ #if OPT_TRACE if (c == '\n') { static TBUFF *ss; int len = (DOT.o > 0) ? DOT.o : 1; if (tb_init(&ss, EOS) != 0 && tb_bappend(&ss, (DOT.o > 0) ? lvalue(DOT.l) : "?", (size_t) len) != 0 && tb_append(&ss, EOS) != 0) { TRACE(("msg:%s\n", visible_buff(tb_values(ss), (int) tb_length(ss) - 1, TRUE))); } } #endif if ((c != '\n') || (DOT.o > 0)) { bputc(c); b_clr_changed(bp); } /* Finally, restore the original current-buffer and write the character * to the message line. */ curbp = savebp; curwp = savewp; if (savewp) DOT = savemk; movecursor(saverow, savecol); if (c != '\n') { if (sgarbf) { mlsavec(c); } else { kbd_putc(c); } } endofDisplay(); return TRUE; }