/* ARGSUSED */ int killline(int f, int n) { struct line *nextp; RSIZE chunk; int i, c; /* clear kill buffer if last wasn't a kill */ if ((lastflag & CFKILL) == 0) kdelete(); thisflag |= CFKILL; if (!(f & FFARG)) { for (i = curwp->w_doto; i < llength(curwp->w_dotp); ++i) if ((c = lgetc(curwp->w_dotp, i)) != ' ' && c != '\t') break; if (i == llength(curwp->w_dotp)) chunk = llength(curwp->w_dotp) - curwp->w_doto + 1; else { chunk = llength(curwp->w_dotp) - curwp->w_doto; if (chunk == 0) chunk = 1; } } else if (n > 0) { chunk = llength(curwp->w_dotp) - curwp->w_doto; nextp = lforw(curwp->w_dotp); if (nextp != curbp->b_headp) chunk++; /* newline */ if (nextp == curbp->b_headp) goto done; /* EOL */ i = n; while (--i) { chunk += llength(nextp); nextp = lforw(nextp); if (nextp != curbp->b_headp) chunk++; /* newline */ if (nextp == curbp->b_headp) break; /* EOL */ } } else { /* n <= 0 */ chunk = curwp->w_doto; curwp->w_doto = 0; i = n; while (i++) { if (lforw(curwp->w_dotp)) chunk++; curwp->w_dotp = lback(curwp->w_dotp); curwp->w_rflag |= WFMOVE; chunk += llength(curwp->w_dotp); } } /* * KFORW here is a bug. Should be KBACK/KFORW, but we need to * rewrite the ldelete code (later)? */ done: if (chunk) return (ldelete(chunk, KFORW)); return (TRUE); }
int isquotedspace(LINE *line) { int i, was_quote = 0; for(i = 0; i < llength(line); i++){ if(lgetc(line, i).c == '>') was_quote = 1; else if(was_quote && lgetc(line, i).c == ' '){ if(i+1 < llength(line) && ucs4_isspace(lgetc(line,i+1).c)) return 1; else return 0; } else return 0; } return 0; }
/* ARGSUSED */ int gotoeol(int f, int n) { if (n == 0) return (TRUE); curwp->w_doto = llength(curwp->w_dotp); return (TRUE); }
/* * Go to the end of the buffer. * Setting WFFULL is conservative, but * almost always the case. */ int gotoeob(int f, int n) { (void) setmark(f, n); curwp->w_dotp = blastlp(curbp); curwp->w_doto = llength(curwp->w_dotp); curwp->w_dotline = curwp->w_bufp->b_lines; curwp->w_flag |= WFFULL; return (TRUE); }
int do_gotoeop(int f, int n, int *i) { int col, nospace, j = 0; /* the other way... */ if (n < 0) return (gotobop(f, -n)); /* for each one asked for */ while (n-- > 0) { *i = ++j; nospace = 0; while (lforw(curwp->w_dotp) != curbp->b_headp) { col = 0; curwp->w_doto = 0; while (col < llength(curwp->w_dotp) && (isspace(lgetc(curwp->w_dotp, col)))) col++; if (col >= llength(curwp->w_dotp)) { if (nospace) break; } else nospace = 1; curwp->w_dotp = lforw(curwp->w_dotp); curwp->w_dotline++; } } /* do not continue after end of buffer */ if (lforw(curwp->w_dotp) == curbp->b_headp) { gotoeol(FFRAND, 1); curwp->w_rflag |= WFMOVE; return (FALSE); } /* force screen update */ curwp->w_rflag |= WFMOVE; return (TRUE); }
static int testit(LINE *lp, regexp * exp, int *end, int srchlim) { char *txt = lvalue(lp); C_NUM col = (C_NUM) (exp->startp[0] - txt) + 1; if (col > llength(lp)) col = llength(lp); if (lregexec(exp, lp, col, srchlim)) { col = (C_NUM) (exp->startp[0] - txt) + 1; if (col > llength(lp) && !*end) { col = llength(lp); *end = TRUE; } if (col <= srchlim) return TRUE; } return FALSE; }
static void show_line(struct line *lp) { int i = 0, len = llength(lp); while (i < len) { unicode_t c; i += utf8_to_unicode(lp->l_text, i, len, &c); vtputc(c); } }
/* return the offset of the next non-white character on the line, or -1 if there are no more non-white characters on the line */ int nextchar(LINE *lp, int off) { while (off < llength(lp)) { if (!isSpace(lgetc(lp, off))) return off; off++; } return -1; }
/* * clear all the attributes of all the characters in the buffer? * this is real dumb. Movement with mark set needs to be smarter! */ void unmarkbuffer(void) { register LINE *linep; register int n; CELL c; linep = curwp->w_linep; while(lforw(linep) != curwp->w_linep){ n = llength(linep); for(n=0; n < llength(linep); n++){ c = lgetc(linep, n); c.a = 0; lputc(linep, n, c); } linep = lforw(linep); } }
/* ARGSUSED */ static int gid(int f, int n) { char command[NFILEN]; char cprompt[NFILEN], *bufp; int c; struct buffer *bp; struct mgwin *wp; int i, j, len; /* catch ([^\s(){}]+)[\s(){}]* */ i = curwp->w_doto; /* Skip backwards over delimiters we are currently on */ while (i > 0) { c = lgetc(curwp->w_dotp, i); if (isalnum(c) || c == '_') break; i--; } /* Skip the symbol itself */ for (; i > 0; i--) { c = lgetc(curwp->w_dotp, i - 1); if (!isalnum(c) && c != '_') break; } /* Fill the symbol in cprompt[] */ for (j = 0; j < sizeof(cprompt) - 1 && i < llength(curwp->w_dotp); j++, i++) { c = lgetc(curwp->w_dotp, i); if (!isalnum(c) && c != '_') break; cprompt[j] = c; } cprompt[j] = '\0'; if ((bufp = eread("Run gid (with args): ", cprompt, NFILEN, (j ? EFDEF : 0) | EFNEW | EFCR)) == NULL) return (ABORT); else if (bufp[0] == '\0') return (FALSE); len = snprintf(command, sizeof(command), "gid %s", cprompt); if (len < 0 || len >= sizeof(command)) return (FALSE); if ((bp = compile_mode("*gid*", command)) == NULL) return (FALSE); if ((wp = popbuf(bp, WNONE)) == NULL) return (FALSE); curbp = bp; compile_win = curwp = wp; return (TRUE); }
/* ARGSUSED */ int evalbuffer(int f, int n) { struct line *lp; struct buffer *bp = curbp; int s; static char excbuf[128]; for (lp = bfirstlp(bp); lp != bp->b_headp; lp = lforw(lp)) { if (llength(lp) >= 128) return (FALSE); (void)strncpy(excbuf, ltext(lp), llength(lp)); /* make sure it's terminated */ excbuf[llength(lp)] = '\0'; if ((s = excline(excbuf)) != TRUE) return (s); } return (TRUE); }
/* * Indent region. Adjust the indentation of the lines * in the region by the number of spaces in the argument. * Call "lchange" to ensure that * redisplay is done in all buffers. */ int indentregion (int f, int n, int k) { register int nicol; register int i; register int c; register int s; REGION region; int llen; if ((s = getregion (®ion)) != TRUE) return (s); if (checkreadonly () == FALSE) return FALSE; lchange (WFHARD); curwp->w_dot.p = region.r_pos.p; curwp->w_dot.o = 0; region.r_size += region.r_pos.o; while (region.r_size > 0) { llen = llength (curwp->w_dot.p); region.r_size -= llen + 1; nicol = 0; /* Find the indentation level of this line. */ for (i = 0; i < llen; ++i) { c = lgetc (curwp->w_dot.p, i); if (c != ' ' && c != '\t') break; if (c == '\t') nicol += (tabsize - nicol % tabsize) - 1; ++nicol; } /* Delete the leading white space in this line, and replace * it with enough tabs and spaces to add the specified * indentation. */ if (llen != 0 && (nicol += n) >= 0) { ldelete (i, FALSE); if ((i = nicol / tabsize) != 0 && linsert (i, '\t', NULLPTR) == FALSE) return (FALSE); if ((i = nicol % tabsize) != 0 && linsert (i, ' ', NULLPTR) == FALSE) return (FALSE); } curwp->w_dot.p = lforw (curwp->w_dot.p); curwp->w_dot.o = 0; } return (TRUE); }
/* * Display the current position of the cursor, in origin 1 X-Y coordinates, * the character that is under the cursor (in hex), and the fraction of the * text that is before the cursor. The displayed column is not the current * column, but the column that would be used on an infinite width display. * Normally this is bound to "C-X =" */ int showcpos (int f, int n) { LINE *clp; long nch, nbc; int cbo, cac, ratio, col; clp = lforw (curbp->b_linep); /* Grovel the data */ cbo = 0; nch = 0; nbc = 0; cac = 0; for (;;) { if (clp == curwp->w_dotp && cbo == curwp->w_doto) { nbc = nch; if (cbo == llength (clp)) cac = '\n'; else cac = lgetc (clp, cbo); } if (cbo == llength (clp)) { if (clp == curbp->b_linep) break; clp = lforw (clp); cbo = 0; } else ++cbo; ++nch; } col = getccol (FALSE); /* Get real column */ ratio = 0; /* Ratio before dot */ if (nch != 0) ratio = (100L * nbc) / nch; mlwrite ("Char: %c (0%o, %d, 0x%x) point=%D of %D(%d%%) column %d", ((cac > 31) && (cac < 128) ? cac : 32), cac, cac, cac, nbc + 1, nch, ratio, col); return (TRUE); }
/* ARGSUSED */ int bufferinsert(int f, int n) { struct buffer *bp; struct line *clp; int clo, nline; char bufn[NBUFN], *bufp; /* Get buffer to use from user */ if (curbp->b_altb != NULL) bufp = eread("Insert buffer: (default %s) ", bufn, NBUFN, EFNUL | EFNEW | EFBUF, curbp->b_altb->b_bname); else bufp = eread("Insert buffer: ", bufn, NBUFN, EFNEW | EFBUF); if (bufp == NULL) return (ABORT); if (bufp[0] == '\0' && curbp->b_altb != NULL) bp = curbp->b_altb; else if ((bp = bfind(bufn, FALSE)) == NULL) return (FALSE); if (bp == curbp) { dobeep(); ewprintf("Cannot insert buffer into self"); return (FALSE); } /* insert the buffer */ nline = 0; clp = bfirstlp(bp); for (;;) { for (clo = 0; clo < llength(clp); clo++) if (linsert(1, lgetc(clp, clo)) == FALSE) return (FALSE); if ((clp = lforw(clp)) == bp->b_headp) break; if (enewline(FFRAND, 1) == FALSE) /* fake newline */ return (FALSE); nline++; } if (nline == 1) ewprintf("[Inserted 1 line]"); else ewprintf("[Inserted %d lines]", nline); clp = curwp->w_linep; /* cosmetic adjustment */ if (curwp->w_dotp == clp) { /* for offscreen insert */ while (nline-- && lback(clp) != curbp->b_headp) clp = lback(clp); curwp->w_linep = clp; /* adjust framing. */ curwp->w_rflag |= WFFULL; } return (TRUE); }
/* * This routine rebuilds the text for the * list buffers command. Return pointer * to new list if everything works. * Return NULL if there is an error (if * there is no memory). */ static struct buffer * makelist(void) { int w = ncol / 2; struct buffer *bp, *blp; struct line *lp; if ((blp = bfind("*Buffer List*", TRUE)) == NULL) return (NULL); if (bclear(blp) != TRUE) return (NULL); blp->b_flag &= ~BFCHG; /* Blow away old. */ blp->b_flag |= BFREADONLY; listbuf_ncol = ncol; /* cache ncol for listbuf_goto_buffer */ if (addlinef(blp, "%-*s%s", w, " MR Buffer", "Size File") == FALSE || addlinef(blp, "%-*s%s", w, " -- ------", "---- ----") == FALSE) return (NULL); for (bp = bheadp; bp != NULL; bp = bp->b_bufp) { RSIZE nbytes; nbytes = 0; /* Count bytes in buf. */ if (bp != blp) { lp = bfirstlp(bp); while (lp != bp->b_headp) { nbytes += llength(lp) + 1; lp = lforw(lp); } if (nbytes) nbytes--; /* no bonus newline */ } if (addlinef(blp, "%c%c%c %-*.*s%c%-6d %-*s", (bp == curbp) ? '.' : ' ', /* current buffer ? */ ((bp->b_flag & BFCHG) != 0) ? '*' : ' ', /* changed ? */ ((bp->b_flag & BFREADONLY) != 0) ? ' ' : '*', w - 5, /* four chars already written */ w - 5, /* four chars already written */ bp->b_bname, /* buffer name */ strlen(bp->b_bname) < w - 5 ? ' ' : '$', /* truncated? */ nbytes, /* buffer size */ w - 7, /* seven chars already written */ bp->b_fname) == FALSE) return (NULL); } blp->b_dotp = bfirstlp(blp); /* put dot at beginning of * buffer */ blp->b_doto = 0; return (blp); /* All done */ }
/* * pico_seek - position dotp and dot at requested location */ int pico_seek(void *w, long offset, int orig) { register LINE *lp; PT(w)->crinread = 0; switch(orig){ case 0 : /* SEEK_SET */ PT(w)->dotp = lforw(PT(w)->linep); PT(w)->doto = 0; case 1 : /* SEEK_CUR */ lp = PT(w)->dotp; while(lp != PT(w)->linep){ if(offset <= llength(lp)){ PT(w)->doto = (int)offset; PT(w)->dotp = lp; break; } offset -= ((long)llength(lp) #if defined(DOS) || defined(OS2) + 2L); #else + 1L); #endif lp = lforw(lp); } break; case 2 : /* SEEK_END */ PT(w)->dotp = lback(PT(w)->linep); PT(w)->doto = llength(PT(w)->dotp); break; default : return(-1); } return(0); }
/* * Count the number of characters from the given offset to the end of the line. */ int chars_to_eol(LINE *lp, int off) { int rc = bytes_to_eol(lp, off); if (b_is_utfXX(curbp)) { rc = 0; while (off < llength(lp)) { off += bytes_at(lp, off); ++rc; } } return rc; }
static jl_value_t *full_list_of_lists(value_t e) { size_t ln = llength(e); if (ln == 0) return jl_an_empty_cell; jl_array_t *ar = jl_alloc_cell_1d(ln); size_t i=0; while (iscons(e)) { jl_cellset(ar, i, full_list(car_(e))); e = cdr_(e); i++; } return (jl_value_t*)ar; }
/* * This function does the work of deleting matching lines. */ static int killmatches(int cond) { int s, error; int count = 0; struct line *clp; clp = curwp->w_dotp; if (curwp->w_doto == llength(clp)) /* Consider dot on next line */ clp = lforw(clp); while (clp != (curbp->b_headp)) { /* see if line matches */ regex_match[0].rm_so = 0; regex_match[0].rm_eo = llength(clp); error = regexec_new(&re_buff, ltext(clp), RE_NMATCH, regex_match, REG_STARTEND); /* Delete line when appropriate */ if ((cond == FALSE && error) || (cond == TRUE && !error)) { curwp->w_doto = 0; curwp->w_dotp = clp; count++; s = ldelete(llength(clp) + 1, KNONE); clp = curwp->w_dotp; curwp->w_rflag |= WFMOVE; if (s == FALSE) return (FALSE); } else clp = lforw(clp); } ewprintf("%d line(s) deleted", count); if (count > 0) curwp->w_rflag |= WFMOVE; return (TRUE); }
/* go forword to the end of the current paragraph here we look for a <NL><NL> * or <NL><TAB> or <NL><SPACE> combination to delimit the begining of a * paragraph */ int gotoeop (int f, int n) { int suc; /* success of last backchar */ if (n < 0) /* the other way.. */ return (gotobop (f, -n)); while (n-- > 0) { /* for each one asked for */ /* first scan forward until we are in a word */ suc = forwchar (FALSE, 1); while (!inword () && suc) suc = forwchar (FALSE, 1); curwp->w_doto = 0; /* and go to the B-O-Line */ if (suc) /* of next line if not at EOF */ curwp->w_dotp = lforw (curwp->w_dotp); /* and scan forword until hit a <NL><NL> or <NL><TAB> or a <NL><SPACE> */ while (curwp->w_dotp != curbp->b_linep) { if (llength (curwp->w_dotp) != 0 && lgetc (curwp->w_dotp, curwp->w_doto) != TAB && lgetc (curwp->w_dotp, curwp->w_doto) != ' ') curwp->w_dotp = lforw (curwp->w_dotp); else break; } /* and then backward until we are in a word */ suc = backchar (FALSE, 1); while (suc && !inword ()) { suc = backchar (FALSE, 1); } curwp->w_doto = llength (curwp->w_dotp); /* and to the EOL */ } curwp->w_flag |= WFMOVE; /* force screen update */ return (TRUE); }
static jl_value_t *full_list(value_t e, int expronly) { size_t ln = llength(e); if (ln == 0) return jl_an_empty_cell; jl_array_t *ar = jl_alloc_cell_1d(ln); size_t i=0; while (iscons(e)) { jl_cellset(ar, i, scm_to_julia_(car_(e), expronly)); e = cdr_(e); i++; } return (jl_value_t*)ar; }
Ddelline(f, n) { register int s = TRUE; kill_setbuffer(DK_LINE); kill_freebuffer(); while( n-- > 0 && s ) { curwp->w_doto = 0; s &= line_delete(llength(curwp->w_dotp) + 1, TRUE); } kill_setbuffer(DK_CUT); return( s ); }
int assemble_options(LISP l, ...) {int result = 0,val,noptions,nmask = 0; LISP lsym,lp = NIL; char *sym; va_list syms; if NULLP(l) return(0); noptions = CONSP(l) ? get_c_long(llength(l)) : -1; va_start(syms,l); while((sym = va_arg(syms,char *))) {val = va_arg(syms,int); lsym = cintern(sym); if (EQ(l,lsym) || (CONSP(l) && NNULLP(lp = memq(lsym,l)))) {result |= val; if (noptions > 0) nmask = nmask | (1 << (noptions - get_c_long(llength(lp)))); else noptions = -2;}} va_end(syms); if ((noptions == -1) || ((noptions > 0) && (nmask != ((1 << noptions) - 1)))) err("contains undefined options",l); return(result);}
/* * Kill text. If called without an argument, it kills from dot to the end of * the line, unless it is at the end of the line, when it kills the newline. * If called with an argument of 0, it kills from the start of the line to * dot. If called with a positive argument, it kills from dot forward over * that number of newlines. If called with a negative argument it kills * backwards that number of newlines. Normally bound to "C-K" */ int killtext(int f, int n) { LINE *nextp; int chunk; if ((lastflag & CFKILL) == 0)/* Clear kill buffer if last wasn't a kill */ kdelete(); thisflag |= CFKILL; if (f == FALSE) { chunk = llength(curwp->w_dotp) - curwp->w_doto; if (chunk == 0) chunk = 1; } else if (n == 0) { chunk = curwp->w_doto; curwp->w_doto = 0; } else if (n > 0) { chunk = llength(curwp->w_dotp) - curwp->w_doto + 1; nextp = lforw(curwp->w_dotp); while (--n) { if (nextp == curbp->b_linep) return (FALSE); chunk += llength(nextp) + 1; nextp = lforw(nextp); } } else { mlwrite("neg kill"); return (FALSE); } return (ldelete(chunk, TRUE)); }
/* ARGSUSED */ int gotoeop(int f, int n) { /* the other way... */ if (n < 0) return (gotobop(f, -n)); /* for each one asked for */ while (n-- > 0) { /* Find the first word on/after the current line */ curwp->w_doto = 0; while (forwchar(FFRAND, 1) && inword() == 0); curwp->w_doto = 0; curwp->w_dotp = lforw(curwp->w_dotp); /* and scan forword until we hit a <NL><SP> or ... */ while (curwp->w_dotp != curbp->b_headp) { if (llength(curwp->w_dotp) && lgetc(curwp->w_dotp, 0) != ' ' && lgetc(curwp->w_dotp, 0) != '.' && lgetc(curwp->w_dotp, 0) != '\t') curwp->w_dotp = lforw(curwp->w_dotp); else break; } if (curwp->w_dotp == curbp->b_headp) { /* beyond end of buffer, cleanup time */ curwp->w_dotp = lback(curwp->w_dotp); curwp->w_doto = llength(curwp->w_dotp); break; } } /* force screen update */ curwp->w_rflag |= WFMOVE; return (TRUE); }
/* * killtext - delete the line that the cursor is currently in. * a greatly pared down version of its former self. */ int killtext(int f, int n) { register int chunk; int opt_scroll = 0; if (curbp->b_mode&MDVIEW) /* don't allow this command if */ return(rdonly()); /* we are in read only mode */ if ((lastflag&CFKILL) == 0) /* Clear kill buffer if */ kdelete(); /* last wasn't a kill. */ if(gmode & MDDTKILL){ /* */ if((chunk = llength(curwp->w_dotp) - curwp->w_doto) == 0){ chunk = 1; if(TERM_OPTIMIZE) opt_scroll = 1; } } else{ gotobol(FALSE, 1); /* wack from bol past newline */ chunk = llength(curwp->w_dotp) + 1; if(TERM_OPTIMIZE) opt_scroll = 1; } /* optimize what motion we can */ if(opt_scroll && (curwp->w_dotp != curwp->w_bufp->b_linep)){ int l; if(worthit(&l)) scrollup(curwp, l, 1); } thisflag |= CFKILL; return(ldelete((long) chunk, kinsert)); }
/* * Implements the vi "$" command. * * Move the cursor to the end of the current line. Trivial. */ int gotoeol(int f, int n) { if (f == TRUE) { if (n > 0) --n; else if (n < 0) ++n; if (forwline(f, n) != TRUE) return FALSE; } DOT.o = llength(DOT.l); curgoal = VL_HUGE; return (TRUE); }
/* * Move back n rows on the screen, staying in the same column. It's ok to * scroll, too. */ int back_row(int f, int n) { int code = TRUE; int col, next; n = need_a_count(f, n, 1); if (n < 0) { code = forw_row(f, -n); } else if (n > 0) { /* set the "goal" column if necessary */ if (curgoal < 0) curgoal = getccol(FALSE); col = curgoal; next = col; while ((n-- > 0) && (code == TRUE)) { next -= term.cols; if (next < 0) { if ((code = backline(TRUE, 1)) == TRUE && llength(DOT.l) >= curgoal) { next = llength(DOT.l) / term.cols; next = (next * term.cols) + curgoal; curgoal = next; } } else { if ((code = gotocol(TRUE, next + 1)) == TRUE) curgoal = next; } } } return code; }
/* * Count the number of bytes in the given number of characters in the line * starting from the given offset. */ int count_bytes(LINE *lp, int off, int chars) { int rc = chars; if (b_is_utfXX(curbp)) { int xx = 0; while (off < llength(lp) && chars-- > 0) { int value = bytes_at(lp, off); off += value; xx += value; } rc = xx; } return rc; }
/* * Return TRUE if the character at dot is a character that is considered to be * part of a word. */ int inword(void) { if(curwp->w_doto < llength(curwp->w_dotp)) { if(ucs4_isalnum(lgetc(curwp->w_dotp, curwp->w_doto).c)) { return(TRUE); } else if(ucs4_ispunct(lgetc(curwp->w_dotp, curwp->w_doto).c) && !is_user_separator(lgetc(curwp->w_dotp, curwp->w_doto).c)) { if((curwp->w_doto > 0) && ucs4_isalnum(lgetc(curwp->w_dotp, curwp->w_doto - 1).c) && (curwp->w_doto + 1 < llength(curwp->w_dotp)) && ucs4_isalnum(lgetc(curwp->w_dotp, curwp->w_doto + 1).c)) { return(TRUE); } } } return(FALSE); }