/* ARGSUSED */ int upperword(int f, int n) { int c, s; RSIZE size; if ((s = checkdirty(curbp)) != TRUE) return (s); if (curbp->b_flag & BFREADONLY) { ewprintf("Buffer is read-only"); return (FALSE); } if (n < 0) return (FALSE); while (n--) { while (inword() == FALSE) { if (forwchar(FFRAND, 1) == FALSE) return (TRUE); } size = countfword(); undo_add_change(curwp->w_dotp, curwp->w_doto, size); while (inword() != FALSE) { c = lgetc(curwp->w_dotp, curwp->w_doto); #ifndef MRUBY if (ISLOWER(c) != FALSE) { c = TOUPPER(c); #else if (MG_ISLOWER(c) != FALSE) { c = MG_TOUPPER(c); #endif /* !MRUBY */ lputc(curwp->w_dotp, curwp->w_doto, c); lchange(WFFULL); } if (forwchar(FFRAND, 1) == FALSE) return (TRUE); } } return (TRUE); } /* * Move the cursor forward by the specified number of words. As you move * convert characters to lower case. */ /* ARGSUSED */ int lowerword(int f, int n) { int c, s; RSIZE size; if ((s = checkdirty(curbp)) != TRUE) return (s); if (curbp->b_flag & BFREADONLY) { ewprintf("Buffer is read-only"); return (FALSE); } if (n < 0) return (FALSE); while (n--) { while (inword() == FALSE) { if (forwchar(FFRAND, 1) == FALSE) return (TRUE); } size = countfword(); undo_add_change(curwp->w_dotp, curwp->w_doto, size); while (inword() != FALSE) { c = lgetc(curwp->w_dotp, curwp->w_doto); #ifndef MRUBY if (ISUPPER(c) != FALSE) { c = TOLOWER(c); #else if (MG_ISUPPER(c) != FALSE) { c = MG_TOLOWER(c); #endif /* !MRUBY */ lputc(curwp->w_dotp, curwp->w_doto, c); lchange(WFFULL); } if (forwchar(FFRAND, 1) == FALSE) return (TRUE); } } return (TRUE); } /* * Move the cursor forward by the specified number of words. As you move * convert the first character of the word to upper case, and subsequent * characters to lower case. Error if you try to move past the end of the * buffer. */ /* ARGSUSED */ int capword(int f, int n) { int c, s; RSIZE size; if ((s = checkdirty(curbp)) != TRUE) return (s); if (curbp->b_flag & BFREADONLY) { ewprintf("Buffer is read-only"); return (FALSE); } if (n < 0) return (FALSE); while (n--) { while (inword() == FALSE) { if (forwchar(FFRAND, 1) == FALSE) return (TRUE); } size = countfword(); undo_add_change(curwp->w_dotp, curwp->w_doto, size); if (inword() != FALSE) { c = lgetc(curwp->w_dotp, curwp->w_doto); #ifndef MRUBY if (ISLOWER(c) != FALSE) { c = TOUPPER(c); #else if (MG_ISLOWER(c) != FALSE) { c = MG_TOUPPER(c); #endif /* !MRUBY */ lputc(curwp->w_dotp, curwp->w_doto, c); lchange(WFFULL); } if (forwchar(FFRAND, 1) == FALSE) return (TRUE); while (inword() != FALSE) { c = lgetc(curwp->w_dotp, curwp->w_doto); #ifndef MRUBY if (ISUPPER(c) != FALSE) { c = TOLOWER(c); #else if (MG_ISUPPER(c) != FALSE) { c = MG_TOLOWER(c); #endif /* !MRUBY */ lputc(curwp->w_dotp, curwp->w_doto, c); lchange(WFFULL); } if (forwchar(FFRAND, 1) == FALSE) return (TRUE); } } } return (TRUE); } /* * Count characters in word, from current position */ RSIZE countfword() { RSIZE size; struct line *dotp; int doto; dotp = curwp->w_dotp; doto = curwp->w_doto; size = 0; while (inword() != FALSE) { if (forwchar(FFRAND, 1) == FALSE) /* hit the end of the buffer */ goto out; ++size; } out: curwp->w_dotp = dotp; curwp->w_doto = doto; return (size); } /* * Kill forward by "n" words. */ /* ARGSUSED */ int delfword(int f, int n) { RSIZE size; struct line *dotp; int doto; int s; if ((s = checkdirty(curbp)) != TRUE) return (s); if (curbp->b_flag & BFREADONLY) { ewprintf("Buffer is read-only"); return (FALSE); } if (n < 0) return (FALSE); /* purge kill buffer */ if ((lastflag & CFKILL) == 0) kdelete(); thisflag |= CFKILL; dotp = curwp->w_dotp; doto = curwp->w_doto; size = 0; while (n--) { while (inword() == FALSE) { if (forwchar(FFRAND, 1) == FALSE) /* hit the end of the buffer */ goto out; ++size; } while (inword() != FALSE) { if (forwchar(FFRAND, 1) == FALSE) /* hit the end of the buffer */ goto out; ++size; } } out: curwp->w_dotp = dotp; curwp->w_doto = doto; return (ldelete(size, KFORW)); } /* * Kill backwards by "n" words. The rules for success and failure are now * different, to prevent strange behavior at the start of the buffer. The * command only fails if something goes wrong with the actual delete of the * characters. It is successful even if no characters are deleted, or if you * say delete 5 words, and there are only 4 words left. I considered making * the first call to "backchar" special, but decided that that would just be * weird. Normally this is bound to "M-Rubout" and to "M-Backspace". */ /* ARGSUSED */ int delbword(int f, int n) { RSIZE size; int s; if ((s = checkdirty(curbp)) != TRUE) return (s); if (curbp->b_flag & BFREADONLY) { ewprintf("Buffer is read-only"); return (FALSE); } if (n < 0) return (FALSE); /* purge kill buffer */ if ((lastflag & CFKILL) == 0) kdelete(); thisflag |= CFKILL; if (backchar(FFRAND, 1) == FALSE) /* hit buffer start */ return (TRUE); /* one deleted */ size = 1; while (n--) { while (inword() == FALSE) { if (backchar(FFRAND, 1) == FALSE) /* hit buffer start */ goto out; ++size; } while (inword() != FALSE) { if (backchar(FFRAND, 1) == FALSE) /* hit buffer start */ goto out; ++size; } } if (forwchar(FFRAND, 1) == FALSE) return (FALSE); /* undo assumed delete */ --size; out: return (ldelete(size, KBACK)); }
/* ARGSUSED */ int fillpara(int f, int n) { int c; /* current char during scan */ int wordlen; /* length of current word */ int clength; /* position on line during fill */ int i; /* index during word copy */ int eopflag; /* Are we at the End-Of-Paragraph? */ int firstflag; /* first word? (needs no space) */ int newlength; /* tentative new line length */ int eolflag; /* was at end of line */ int retval; /* return value */ struct line *eopline; /* pointer to line just past EOP */ char wbuf[MAXWORD]; /* buffer for current word */ if (n == 0) return (TRUE); undo_boundary_enable(FFRAND, 0); /* record the pointer to the line just past the EOP */ (void)gotoeop(FFRAND, 1); if (curwp->w_doto != 0) { /* paragraph ends at end of buffer */ (void)lnewline(); eopline = lforw(curwp->w_dotp); } else eopline = curwp->w_dotp; /* and back top the beginning of the paragraph */ (void)gotobop(FFRAND, 1); /* initialize various info */ while (inword() == 0 && forwchar(FFRAND, 1)); clength = curwp->w_doto; wordlen = 0; /* scan through lines, filling words */ firstflag = TRUE; eopflag = FALSE; while (!eopflag) { /* get the next character in the paragraph */ if ((eolflag = (curwp->w_doto == llength(curwp->w_dotp)))) { c = ' '; if (lforw(curwp->w_dotp) == eopline) eopflag = TRUE; } else c = lgetc(curwp->w_dotp, curwp->w_doto); /* and then delete it */ if (ldelete((RSIZE) 1, KNONE) == FALSE && !eopflag) { retval = FALSE; goto cleanup; } /* if not a separator, just add it in */ if (c != ' ' && c != '\t') { if (wordlen < MAXWORD - 1) wbuf[wordlen++] = c; else { /* * You lose chars beyond MAXWORD if the word * is too long. I'm too lazy to fix it now; it * just silently truncated the word before, * so I get to feel smug. */ ewprintf("Word too long!"); } } else if (wordlen) { /* calculate tentative new length with word added */ newlength = clength + 1 + wordlen; /* * if at end of line or at doublespace and previous * character was one of '.','?','!' doublespace here. * behave the same way if a ')' is preceded by a * [.?!] and followed by a doublespace. */ if (dblspace && (!eopflag && ((eolflag || curwp->w_doto == llength(curwp->w_dotp) || (c = lgetc(curwp->w_dotp, curwp->w_doto)) == ' ' || c == '\t') && (ISEOSP(wbuf[wordlen - 1]) || (wbuf[wordlen - 1] == ')' && wordlen >= 2 && ISEOSP(wbuf[wordlen - 2])))) && wordlen < MAXWORD - 1)) wbuf[wordlen++] = ' '; /* at a word break with a word waiting */ if (newlength <= fillcol) { /* add word to current line */ if (!firstflag) { (void)linsert(1, ' '); ++clength; } firstflag = FALSE; } else { if (curwp->w_doto > 0 && lgetc(curwp->w_dotp, curwp->w_doto - 1) == ' ') { curwp->w_doto -= 1; (void)ldelete((RSIZE) 1, KNONE); } /* start a new line */ (void)lnewline(); clength = 0; } /* and add the word in in either case */ for (i = 0; i < wordlen; i++) { (void)linsert(1, wbuf[i]); ++clength; } wordlen = 0; } } /* and add a last newline for the end of our new paragraph */ (void)lnewline(); /* * We really should wind up where we started, (which is hard to keep * track of) but I think the end of the last line is better than the * beginning of the blank line. */ (void)backchar(FFRAND, 1); retval = TRUE; cleanup: undo_boundary_enable(FFRAND, 1); return (retval); }
int forwsearch(int f, int n) { int status; int wrapt = FALSE, wrapt2 = FALSE; int repl_mode = FALSE; UCS defpat[NPAT]; int search = FALSE; EML eml; /* resolve the repeat count */ if (n == 0) n = 1; if (n < 1) /* search backwards */ FWS_RETURN(0); defpat[0] = '\0'; /* ask the user for the text of a pattern */ while(1){ if (gmode & MDREPLACE) status = srpat("Search", defpat, NPAT, repl_mode); else status = readpattern("Search", TRUE); switch(status){ case TRUE: /* user typed something */ search = TRUE; break; case HELPCH: /* help requested */ if(Pmaster){ VARS_TO_SAVE *saved_state; saved_state = save_pico_state(); (*Pmaster->helper)(Pmaster->search_help, _("Help for Searching"), 1); if(saved_state){ restore_pico_state(saved_state); free_pico_state(saved_state); } } else pico_help(SearchHelpText, _("Help for Searching"), 1); case (CTRL|'L'): /* redraw requested */ pico_refresh(FALSE, 1); update(); break; case (CTRL|'V'): gotoeob(0, 1); mlerase(); FWS_RETURN(TRUE); case (CTRL|'Y'): gotobob(0, 1); mlerase(); FWS_RETURN(TRUE); case (CTRL|'T') : switch(status = readnumpat(_("Search to Line Number : "))){ case -1 : emlwrite(_("Search to Line Number Cancelled"), NULL); FWS_RETURN(FALSE); case 0 : emlwrite(_("Line number must be greater than zero"), NULL); FWS_RETURN(FALSE); case -2 : emlwrite(_("Line number must contain only digits"), NULL); FWS_RETURN(FALSE); case -3 : continue; default : gotoline(0, status); mlerase(); FWS_RETURN(TRUE); } break; case (CTRL|'W'): { LINE *linep = curwp->w_dotp; int offset = curwp->w_doto; gotobop(0, 1); gotobol(0, 1); /* * if we're asked to backup and we're already * */ if((lastflag & CFSRCH) && linep == curwp->w_dotp && offset == curwp->w_doto && !(offset == 0 && lback(linep) == curbp->b_linep)){ backchar(0, 1); gotobop(0, 1); gotobol(0, 1); } } mlerase(); FWS_RETURN(TRUE); case (CTRL|'O'): if(curwp->w_dotp != curbp->b_linep){ gotoeop(0, 1); forwchar(0, 1); } mlerase(); FWS_RETURN(TRUE); case (CTRL|'U'): fillbuf(0, 1); mlerase(); FWS_RETURN(TRUE); case (CTRL|'R'): /* toggle replacement option */ repl_mode = !repl_mode; break; default: if(status == ABORT) emlwrite(_("Search Cancelled"), NULL); else mlerase(); FWS_RETURN(FALSE); } /* replace option is disabled */ if (!(gmode & MDREPLACE)){ ucs4_strncpy(defpat, pat, NPAT); defpat[NPAT-1] = '\0'; break; } else if (search){ /* search now */ ucs4_strncpy(pat, defpat, NPAT); /* remember this search for the future */ pat[NPAT-1] = '\0'; break; } } /* * This code is kind of dumb. What I want is successive C-W 's to * move dot to successive occurences of the pattern. So, if dot is * already sitting at the beginning of the pattern, then we'll move * forward a char before beginning the search. We'll let the * automatic wrapping handle putting the dot back in the right * place... */ status = 0; /* using "status" as int temporarily! */ while(1){ if(defpat[status] == '\0'){ forwchar(0, 1); break; /* find next occurence! */ } if(status + curwp->w_doto >= llength(curwp->w_dotp) || !eq(defpat[status],lgetc(curwp->w_dotp, curwp->w_doto + status).c)) break; /* do nothing! */ status++; } /* search for the pattern */ while (n-- > 0) { if((status = forscan(&wrapt,defpat,NULL,0,PTBEG)) == FALSE) break; } /* and complain if not there */ if (status == FALSE){ char *utf8; UCS x[1]; x[0] = '\0'; utf8 = ucs4_to_utf8_cpystr(defpat ? defpat : x); /* TRANSLATORS: reporting the result of a failed search */ eml.s = utf8; emlwrite(_("\"%s\" not found"), &eml); if(utf8) fs_give((void **) &utf8); } else if((gmode & MDREPLACE) && repl_mode == TRUE){ status = replace_pat(defpat, &wrapt2); /* replace pattern */ if (wrapt == TRUE || wrapt2 == TRUE){ eml.s = (status == ABORT) ? "cancelled but wrapped" : "Wrapped"; emlwrite("Replacement %s", &eml); } } else if(wrapt == TRUE){ emlwrite("Search Wrapped", NULL); } else if(status == TRUE){ emlwrite("", NULL); } FWS_RETURN(status); }
/* search forward for a <patrn> */ int forscan(int *wrapt, /* boolean indicating search wrapped */ UCS *patrn, /* string to scan for */ LINE *limitp, /* stop searching if reached */ int limito, /* stop searching if reached */ int leavep) /* place to leave point PTBEG = begining of match PTEND = at end of match */ { LINE *curline; /* current line during scan */ int curoff; /* position within current line */ LINE *lastline; /* last line position during scan */ int lastoff; /* position within last line */ UCS c; /* character at current position */ LINE *matchline; /* current line during matching */ int matchoff; /* position in matching line */ UCS *patptr; /* pointer into pattern */ int stopoff; /* offset to stop search */ LINE *stopline; /* line to stop search */ *wrapt = FALSE; /* * the idea is to set the character to end the search at the * next character in the buffer. thus, let the search wrap * completely around the buffer. * * first, test to see if we are at the end of the line, * otherwise start searching on the next character. */ if(curwp->w_doto == llength(curwp->w_dotp)){ /* * dot is not on end of a line * start at 0 offset of the next line */ stopoff = curoff = 0; stopline = curline = lforw(curwp->w_dotp); if (curwp->w_dotp == curbp->b_linep) *wrapt = TRUE; } else{ stopoff = curoff = curwp->w_doto; stopline = curline = curwp->w_dotp; } /* scan each character until we hit the head link record */ /* * maybe wrapping is a good idea */ while (curline){ if (curline == curbp->b_linep) *wrapt = TRUE; /* save the current position in case we need to restore it on a match */ lastline = curline; lastoff = curoff; /* get the current character resolving EOLs */ if (curoff == llength(curline)) { /* if at EOL */ curline = lforw(curline); /* skip to next line */ curoff = 0; c = '\n'; /* and return a <NL> */ } else c = lgetc(curline, curoff++).c; /* get the char */ /* test it against first char in pattern */ if (eq(c, patrn[0]) != FALSE) { /* if we find it..*/ /* setup match pointers */ matchline = curline; matchoff = curoff; patptr = &patrn[0]; /* scan through patrn for a match */ while (*++patptr != '\0') { /* advance all the pointers */ if (matchoff == llength(matchline)) { /* advance past EOL */ matchline = lforw(matchline); matchoff = 0; c = '\n'; } else c = lgetc(matchline, matchoff++).c; if(matchline == limitp && matchoff == limito) return(FALSE); /* and test it against the pattern */ if (eq(*patptr, c) == FALSE) goto fail; } /* A SUCCESSFULL MATCH!!! */ /* reset the global "." pointers */ if (leavep == PTEND) { /* at end of string */ curwp->w_dotp = matchline; curwp->w_doto = matchoff; } else { /* at begining of string */ curwp->w_dotp = lastline; curwp->w_doto = lastoff; } curwp->w_flag |= WFMOVE; /* flag that we have moved */ return(TRUE); } fail:; /* continue to search */ if(((curline == stopline) && (curoff == stopoff)) || (curline == limitp && curoff == limito)) break; /* searched everywhere... */ } /* we could not find a match */ return(FALSE); }
/* * This function serves two purposes, 1) to strip white space when * Pmaster asks that the composition have its trailing white space * stripped, or 2) to prepare the text as flowed text, as Pmaster * is telling us that we're working with flowed text. * * What flowed currently means to us is stripping all trailing white * space, except for one space if the following line is a continuation * of the paragraph. Also, we space-stuff all lines beginning * with white-space, and leave siglines alone. */ int cleanwhitespace(void) { LINE *cursor_dotp = NULL, **lp = NULL; int i = 0, cursor_doto = 0, is_cursor_line = 0; int do_space_stuffing = 0; if(Pmaster && Pmaster->allow_flowed_text && !(*Pmaster->user_says_noflow)()) do_space_stuffing++; cursor_dotp = curwp->w_dotp; cursor_doto = curwp->w_doto; gotobob(FALSE, 1); for(lp = &curwp->w_dotp; (*lp) != curbp->b_linep; (*lp) = lforw(*lp)){ if(!(llength(*lp) == 3 && lgetc(*lp, 0).c == '-' && lgetc(*lp, 1).c == '-' && lgetc(*lp, 2).c == ' ') && llength(*lp)){ is_cursor_line = (cursor_dotp == (*lp)); /* trim trailing whitespace, to be added back if flowing */ for(i = llength(*lp); i; i--) if(!ucs4_isspace(lgetc(*lp, i - 1).c)) break; if(i != llength(*lp)){ int flow_line = 0; if(Pmaster && !Pmaster->strip_ws_before_send && lforw(*lp) != curbp->b_linep && llength(lforw(*lp)) && !(ucs4_isspace(lgetc(lforw(*lp), 0).c) || isquotedspace(lforw(*lp))) && !(llength(lforw(*lp)) == 3 && lgetc(lforw(*lp), 0).c == '-' && lgetc(lforw(*lp), 1).c == '-' && lgetc(lforw(*lp), 2).c == ' ')) flow_line = 1; if(flow_line && i && lgetc(*lp, i).c == ' '){ /* flowed line ending with space */ i++; if(i != llength(*lp)){ curwp->w_doto = i; ldelete(llength(*lp) - i, NULL); } } else if(flow_line && i && ucs4_isspace(lgetc(*lp, i).c)){ /* flowed line ending with whitespace other than space*/ curwp->w_doto = i; ldelete(llength(*lp) - i, NULL); linsert(1, ' '); } else{ curwp->w_doto = i; ldelete(llength(*lp) - i, NULL); } } if(do_space_stuffing && llength(*lp) && ucs4_isspace(lgetc(*lp, 0).c)){ /* space-stuff only if flowed */ if(Pmaster) Pmaster->space_stuffed = 1; curwp->w_doto = 0; if(is_cursor_line && cursor_doto) cursor_doto++; linsert(1, ' '); } if(is_cursor_line) cursor_dotp = (*lp); } } /* put the cursor back where we found it */ gotobob(FALSE, 1); curwp->w_dotp = cursor_dotp; curwp->w_doto = (cursor_doto < llength(curwp->w_dotp)) ? cursor_doto : llength(curwp->w_dotp) - 1; return(0); }
/* * This is the general command execution routine. It handles the fake binding * of all the keys to "self-insert". It also clears out the "thisflag" word, * and arranges to move it to the "lastflag", so that the next command can * look at it. Return the status of command. */ int execute(UCS c, int f, int n) { KEYTAB *ktp; int status, ww; ktp = (Pmaster) ? &keytab[0] : &pkeytab[0]; while (ktp->k_fp != NULL) { if (ktp->k_code == c) { if(lastflag&CFFILL){ curwp->w_flag |= WFMODE; if(Pmaster == NULL) sgarbk = TRUE; } thisflag = 0; status = (*ktp->k_fp)(f, n); if((lastflag & CFFILL) && !(thisflag & CFFILL)) fdelete(); if((lastflag & CFFLBF) && !(thisflag & CFFLBF)) kdelete(); lastflag = thisflag; /* * Reset flag saying wrap should open a new line whenever * we execute a command (as opposed to just typing in text). * However, if that command leaves us in the same line on the * screen, then don't reset. */ if(curwp->w_flag & (WFMOVE | WFHARD)) curbp->b_flag |= BFWRAPOPEN; /* wrap should open new line */ return (status); } ++ktp; } if(lastflag & CFFILL) /* blat unusable fill data */ fdelete(); if(lastflag & CFFLBF) kdelete(); if (VALID_KEY(c)) { /* Self inserting. */ if (n <= 0) { /* Fenceposts. */ lastflag = 0; return (n<0 ? FALSE : TRUE); } thisflag = 0; /* For the future. */ /* do the appropriate insertion */ /* pico never does C mode, this is simple */ status = linsert(n, c); /* * Check to make sure we didn't go off of the screen * with that character. Take into account tab expansion. * If so wrap the line... */ if(curwp->w_bufp->b_mode & MDWRAP){ int j, wid; wid = 0; for(j = 0; j < llength(curwp->w_dotp); j++) if(ucs4_isspace(lgetc(curwp->w_dotp, j).c)){ if(lgetc(curwp->w_dotp, j).c == TAB){ ++wid; while(wid & 0x07) ++wid; } else ++wid; } else{ ww = wcellwidth((UCS) lgetc(curwp->w_dotp, j).c); wid += (ww >= 0 ? ww : 1); if(wid > fillcol){ wrapword(); break; } } } lastflag = thisflag; return (status); } unknown_command(c); lastflag = 0; /* Fake last flags. */ return (FALSE); }
/* * pico_readc - return char at current point. Up to calling routines * to keep cumulative count of chars. * The characters in PT are UCS-4 characters. The caller * of pico_readc is expecting UTF-8 chars. We convert * each UCS-4 character to a string of UTF-8 characters * and return them one at a time. */ int pico_readc(void *w, unsigned char *c, int flags) { int rv = 0; UCS ucs; static unsigned char obuf[6]; static unsigned char *obufpend = obuf; static unsigned char *obufpnext = obuf; if(!(flags & PICOREADC_NOUCS)){ if(obufpend > obuf){ *c = *obufpnext++; rv++; if(obufpnext >= obufpend){ obufpend = obuf; obufpnext = obuf; } return(rv); } } if(PT(w)->crinread){ *c = '\012'; /* return LF */ PT(w)->crinread = 0; rv++; } else if(PT(w)->doto < llength(PT(w)->dotp)){ /* normal char to return */ if(flags & PICOREADC_NOUCS){ *c = (unsigned char) lgetc(PT(w)->dotp, (PT(w)->doto)++).c; rv++; } else{ rv++; ucs = lgetc(PT(w)->dotp, (PT(w)->doto)++).c; obufpend = utf8_put(obuf, (unsigned long) ucs); obufpnext = obuf; if(obufpend > obuf){ *c = *obufpnext++; if(obufpnext >= obufpend){ obufpend = obuf; obufpnext = obuf; } } else *c = '?'; } } else if(PT(w)->dotp != PT(w)->linep){ /* return line break */ PT(w)->dotp = lforw(PT(w)->dotp); PT(w)->doto = 0; #if defined(DOS) || defined(OS2) *c = '\015'; PT(w)->crinread++; #else *c = '\012'; /* return local eol! */ #endif rv++; } /* else no chars to return */ return(rv); }
/* * gtenv() * * char *vname; name of environment variable to retrieve */ char *gtenv(char *vname) { int vnum; /* ordinal number of var refrenced */ /* scan the list, looking for the referenced name */ for (vnum = 0; vnum < ARRAY_SIZE(envars); vnum++) if (strcmp(vname, envars[vnum]) == 0) break; /* return errorm on a bad reference */ if (vnum == ARRAY_SIZE(envars)) #if ENVFUNC { char *ename = getenv(vname); if (ename != NULL) return ename; else return errorm; } #else return errorm; #endif /* otherwise, fetch the appropriate value */ switch (vnum) { case EVFILLCOL: return itoa(fillcol); case EVPAGELEN: return itoa(term.t_nrow + 1); case EVCURCOL: return itoa(getccol(FALSE)); case EVCURLINE: return itoa(getcline()); case EVRAM: return itoa((int) (envram / 1024l)); case EVFLICKER: return ltos(flickcode); case EVCURWIDTH: return itoa(term.t_ncol); case EVCBUFNAME: return curbp->b_bname; case EVCFNAME: return curbp->b_fname; case EVSRES: return sres; case EVDEBUG: return ltos(macbug); case EVSTATUS: return ltos(cmdstatus); case EVPALETTE: return palstr; case EVASAVE: return itoa(gasave); case EVACOUNT: return itoa(gacount); case EVLASTKEY: return itoa(lastkey); case EVCURCHAR: return (curwp->w_dotp->l_used == curwp->w_doto ? itoa('\n') : itoa(lgetc(curwp->w_dotp, curwp->w_doto))); case EVDISCMD: return ltos(discmd); case EVVERSION: return VERSION; case EVPROGNAME: return PROGRAM_NAME_LONG; case EVSEED: return itoa(seed); case EVDISINP: return ltos(disinp); case EVWLINE: return itoa(curwp->w_ntrows); case EVCWLINE: return itoa(getwpos()); case EVTARGET: saveflag = lastflag; return itoa(curgoal); case EVSEARCH: return pat; case EVREPLACE: return rpat; case EVMATCH: return (patmatch == NULL) ? "" : patmatch; case EVKILL: return getkill(); case EVCMODE: return itoa(curbp->b_mode); case EVGMODE: return itoa(gmode); case EVTPAUSE: return itoa(term.t_pause); case EVPENDING: #if TYPEAH return ltos(typahead()); #else return falsem; #endif case EVLWIDTH: return itoa(llength(curwp->w_dotp)); case EVLINE: return getctext(); case EVGFLAGS: return itoa(gflags); case EVRVAL: return itoa(rval); case EVTAB: return itoa(tabmask + 1); case EVOVERLAP: return itoa(overlap); case EVSCROLLCOUNT: return itoa(scrollcount); #if SCROLLCODE case EVSCROLL: return ltos(term.t_scroll != NULL); #else case EVSCROLL: return ltos(0); #endif } exit(-12); /* again, we should never get here */ }
/* Word wrap on n-spaces. Back-over whatever precedes the point on the current * line and stop on the first word-break or the beginning of the line. If we * reach the beginning of the line, jump back to the end of the word and start * a new line. Otherwise, break the line at the word-break, eat it, and jump * back to the end of the word. * Returns TRUE on success, FALSE on errors. */ int wrapword(void) { register int cnt; /* size of word wrapped to next line */ register int bp; /* index to wrap on */ register int first = -1; int wid, ww; if(curwp->w_doto <= 0) /* no line to wrap? */ return(FALSE); wid = 0; for(bp = cnt = 0; cnt < llength(curwp->w_dotp) && !bp; cnt++){ if(ucs4_isspace(lgetc(curwp->w_dotp, cnt).c)){ first = 0; if(lgetc(curwp->w_dotp, cnt).c == TAB){ ++wid; while(wid & 0x07) ++wid; } else ++wid; } else{ ww = wcellwidth((UCS) lgetc(curwp->w_dotp, cnt).c); wid += (ww >= 0 ? ww : 1); if(!first) first = cnt; } if(first > 0 && wid > fillcol) bp = first; } if(!bp) return(FALSE); /* bp now points to the first character of the next line */ cnt = curwp->w_doto - bp; curwp->w_doto = bp; if(!lnewline()) /* break the line */ return(FALSE); /* * if there's a line below, it doesn't start with whitespace * and there's room for this line... */ if(!(curbp->b_flag & BFWRAPOPEN) && lforw(curwp->w_dotp) != curbp->b_linep && llength(lforw(curwp->w_dotp)) && !ucs4_isspace(lgetc(lforw(curwp->w_dotp), 0).c) && (llength(curwp->w_dotp) + llength(lforw(curwp->w_dotp)) < fillcol)){ gotoeol(0, 1); /* then pull text up from below */ if(lgetc(curwp->w_dotp, curwp->w_doto - 1).c != ' ') linsert(1, ' '); forwdel(0, 1); gotobol(0, 1); } curbp->b_flag &= ~BFWRAPOPEN; /* don't open new line next wrap */ /* restore dot (account for NL) */ if(cnt && !forwchar(0, cnt < 0 ? cnt-1 : cnt)) return(FALSE); return(TRUE); }