static void savematch(MARK curpos, size_t matchlen) { tb_init(&tb_matched_pat, EOS); tb_bappend(&tb_matched_pat, &(lvalue(curpos.l)[curpos.o]), matchlen); tb_append(&tb_matched_pat, EOS); }
static char *shell_get_line(void) { if (isatty(fileno(stdin))) { #ifdef HAVE_LIBREADLINE char *buf = readline("% "); if ((buf != NULL) && (*buf != '\0')) add_history(buf); return buf; #else // HAVE_LIBREADLINE printf("%% "); fflush(stdout); #endif // HAVE_LIBREADLINE } LOCAL_TEXT_BUF tb = tb_new(); size_t off = 0; for (;;) { int ch = fgetc(stdin); switch (ch) { case EOF: return (off > 0) ? tb_claim(tb) : NULL; case '\n': return tb_claim(tb); default: tb_append(tb, ch); } } }
static thing_th *read_string(char starting, FILE *src, text_buffer *tb) { int inputChar; while((inputChar=get_character(src))!=starting && inputChar!=EOF) tb_append(tb, (char)inputChar); return read_subcons(String(tb->txt), src, tb); }
static thing_th *read_literals(FILE *src, text_buffer *tb, int inputChar) { while(!literal_terminator_char(inputChar)) { tb_append(tb, inputChar); inputChar=get_character(src); } if(!is_whitespace(inputChar)) ungetc(inputChar, src); if(is_decimal_text(tb->txt)) return read_subcons(Number(tb->txt), src, tb); return read_subcons(Atom(tb->txt), src, tb); }
static thing_th *inner_mktxt(text_buffer *tb, thing_th *args) { while(args) { const char *txt=sym(Car(args)); long i; long m=strlen(txt); for(i=0;i<m;++i) { tb_append(tb, txt[i]); } args=Cdr(args); } return String(tb->txt); }
/* * 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; }
/* * Parse a cntl_a sequence, returning the number of characters processed. * Set videoattribute and hypercmd as side-effects. */ int decode_attribute(char *text, size_t length, size_t offset, int *countp) { int c; /* current char during scan */ int count = 0; int found; #if OPT_HYPERTEXT size_t save_offset; #endif while (text[offset] == CONTROL_A) { found = FALSE; count = 0; offset++; while (offset < length) { c = text[offset]; if (isDigit(c)) { count = count * 10 + c - '0'; offset++; } else break; } if (count == 0) count = 1; videoattribute = VOWN_CTLA; while (offset < length && (c = text[offset]) != CONTROL_A && !found) { switch (c) { case 'C': /* We have color. Get color value */ offset++; c = text[offset]; if (isDigit(c)) videoattribute |= VCOLORATTR(c - '0'); else if ('A' <= c && c <= 'F') videoattribute |= VCOLORATTR(c - 'A' + 10); else if ('a' <= c && c <= 'f') videoattribute |= VCOLORATTR(c - 'a' + 10); else offset--; /* Invalid attribute */ break; case 'U': videoattribute |= VAUL; break; case 'B': videoattribute |= VABOLD; break; case 'R': videoattribute |= VAREV; break; case 'I': videoattribute |= VAITAL; break; #if OPT_HYPERTEXT case 'H': save_offset = offset; offset++; while (offset < length && text[offset] != EOS) offset++; if (offset < length) { tb_init(&hypercmd, EOS); tb_bappend(&hypercmd, &text[save_offset + 1], offset - save_offset); tb_append(&hypercmd, EOS); } else { /* skip bad hypertext string */ offset = save_offset; } break; #endif case ':': found = TRUE; break; default: offset--; found = TRUE; break; } offset++; } if (videoattribute != VOWN_CTLA && count != 0) break; } *countp = count; return (int) offset; }
/* Return comma-delimited list of "interesting" options. */ static char * cfgopts(void) { static const char *opts[] = { #if !OPT_SHELL "noshell", #endif #if SYS_WINNT && defined(VILE_OLE) "oleauto", #endif #if OPT_HYPERTEXT "hypertext", #endif #if OPT_LOCALE "locale", #endif #if OPT_ICONV_FUNCS "iconv", #endif #if OPT_MULTIBYTE "multibyte", #endif #if OPT_PERL "perl", #endif #if DISP_ANSI "ansi", #endif #if DISP_BORLAND "borland", #endif #if DISP_CURSES "curses", #endif #if DISP_NTCONS "ntcons", #endif #if DISP_NTWIN "ntwin", #endif #if DISP_TERMCAP # if USE_TERMINFO "terminfo", # else "termcap", # endif #endif #if DISP_VIO "os2vio", #endif #if DISP_VMSVT "vmsvt", #endif #if DISP_X11 # if MOTIF_WIDGETS "motif", # endif # if ATHENA_WIDGETS "athena", # ifdef HAVE_LIB_XAW "xaw", # endif # ifdef HAVE_LIB_XAW3D "xaw3d", # endif # ifdef HAVE_LIB_NEXTAW "nextaw", # endif # endif #endif NULL /* End of list marker */ }; static TBUFF *optstring; if (optstring == 0) { const char **lclopt; optstring = tb_init(&optstring, EOS); for (lclopt = opts; *lclopt; lclopt++) { if (tb_length(optstring)) optstring = tb_append(&optstring, ','); optstring = tb_sappend(&optstring, *lclopt); } optstring = tb_append(&optstring, EOS); } return tb_values(optstring); }
/* ARGSUSED */ static int isearch(int f GCC_UNUSED, int n) { static TBUFF *pat_save = 0; /* Saved copy of the old pattern str */ int status; /* Search status */ register int cpos; /* character number in search string */ register int c; /* current input character */ MARK curpos, curp; /* Current point on entry */ int init_direction; /* The initial search direction */ /* Initialize starting conditions */ cmd_reexecute = -1; /* We're not re-executing (yet?) */ itb_init(&cmd_buff, EOS); /* Init the command buffer */ /* Save the old pattern string */ (void) tb_copy(&pat_save, searchpat); curpos = DOT; /* Save the current pointer */ init_direction = n; /* Save the initial search direction */ ignorecase = window_b_val(curwp, MDIGNCASE); scanboundry(FALSE, DOT, FORWARD); /* keep scanner() finite */ /* This is a good place to start a re-execution: */ start_over: /* ask the user for the text of a pattern */ promptpattern("ISearch: "); status = TRUE; /* Assume everything's cool */ /* * Get the first character in the pattern. If we get an initial * Control-S or Control-R, re-use the old search string and find the * first occurrence */ c = kcod2key(get_char()); /* Get the first character */ if ((c == IS_FORWARD) || (c == IS_REVERSE)) { /* Reuse old search string? */ for (cpos = 0; cpos < (int) tb_length(searchpat); ++cpos) echochar(tb_values(searchpat)[cpos]); /* and re-echo the string */ curp = DOT; if (c == IS_REVERSE) { /* forward search? */ n = -1; /* No, search in reverse */ last_srch_direc = REVERSE; backchar(TRUE, 1); /* Be defensive about EOB */ } else { n = 1; /* Yes, search forward */ last_srch_direc = FORWARD; forwchar(TRUE, 1); } unget_char(); status = scanmore(searchpat, n); /* Do the search */ if (status != TRUE) DOT = curp; c = kcod2key(get_char()); /* Get another character */ } else { tb_init(&searchpat, EOS); } /* Top of the per character loop */ for_ever { /* ISearch per character loop */ /* Check for special characters, since they might change the * search to be done */ if (ABORTED(c) || c == '\r') /* search aborted? */ return (TRUE); /* end the search */ if (isbackspace(c)) c = '\b'; if (c == quotec) /* quote character? */ c = kcod2key(get_char()); /* Get the next char */ switch (c) { /* dispatch on the input char */ case IS_REVERSE: /* If backward search */ case IS_FORWARD: /* If forward search */ curp = DOT; if (c == IS_REVERSE) { /* forward search? */ last_srch_direc = REVERSE; n = -1; /* No, search in reverse */ backchar(TRUE, 1); /* Be defensive about * EOB */ } else { n = 1; /* Yes, search forward */ last_srch_direc = FORWARD; forwchar(TRUE, 1); } status = scanmore(searchpat, n); /* Do the search */ if (status != TRUE) DOT = curp; c = kcod2key(get_char()); /* Get the next char */ continue; /* Go continue with the search */ case '\t': /* Generically allowed */ case '\n': /* controlled characters */ break; /* Make sure we use it */ case '\b': /* or if a Rubout: */ if (itb_length(cmd_buff) <= 1) /* Anything to delete? */ return (TRUE); /* No, just exit */ unget_char(); DOT = curpos; /* Reset the pointer */ n = init_direction; /* Reset the search direction */ (void) tb_copy(&searchpat, pat_save); /* Restore the old search str */ cmd_reexecute = 0; /* Start the whole mess over */ goto start_over; /* Let it take care of itself */ /* Presumably a quasi-normal character comes here */ default: /* All other chars */ if (!isPrint(c)) { /* Is it printable? */ /* Nope. */ unkeystroke(c); /* Re-eat the char */ return (TRUE); /* And return the last status */ } } /* Switch */ /* I guess we got something to search for, so search for it */ tb_append(&searchpat, c); /* put the char in the buffer */ echochar(c); /* Echo the character */ if (!status) { /* If we lost last time */ kbd_alarm(); /* Feep again */ } else /* Otherwise, we must have won */ status = scanmore(searchpat, n); /* or find the next * match */ c = kcod2key(get_char()); /* Get the next char */ } /* for_ever */ }