int ujump(BW *bw) { int rtn = -1; P *p = pdup(bw->cursor, USTR "ujump"); P *q = pdup(p, USTR "ujump"); unsigned char *s; p_goto_bol(p); p_goto_eol(q); s = brvs(p, (int) (q->byte - p->byte)); prm(p); prm(q); if (s) { unsigned char *name = NULL; long line = -1; if (bw->b->parseone) bw->b->parseone(bw->b->o.charmap,s,&name,&line); else parseone(bw->b->o.charmap,s,&name,&line); if (name && line != -1) { ERROR *p = srcherr(name, line); if (p != NULL) { errptr = p; setline(errbuf, errptr->src); name = p->file; line = p->line; } uprevvw((BASE *)bw); rtn = jump_to_file_line(maint->curwin->object, name, line, NULL /* errptr->msg */); vsrm(name); } vsrm(s); } return rtn; }
static long parserr(B *b) { P *p = pdup(b->bof, USTR "parserr"); P *q = pdup(p, USTR "parserr"); long nerrs = 0; if (b->scratch && b->name[0] == '*') { /* "* Build Log *", "* Grep Log *" */ b->changed = 0; } freeall(); if (errbuf != b) { if (errp != NULL) { prm(errp); errp = NULL; } errbuf = b; } do { unsigned char *s; pset(q, p); p_goto_eol(p); s = brvs(q, (int) (p->byte - q->byte)); if (s) { nerrs += parseit(b->o.charmap, s, q->line, (b->parseone ? b->parseone : parseone)); vsrm(s); } } while (pgetc(p) != NO_MORE_DATA); prm(p); prm(q); return nerrs; }
static int rtnpw(BW *bw) { W *w = bw->parent; PW *pw = (PW *) bw->object; unsigned char *s; W *win; int *notify; int (*pfunc) (); void *object; long byte; /* Extract entered text from buffer */ p_goto_eol(bw->cursor); byte = bw->cursor->byte; p_goto_bol(bw->cursor); s = brvs(bw->cursor, (int) (byte - bw->cursor->byte)); /* Save text into history buffer */ if (pw->hist) { if (bw->b->changed) { append_history(pw->hist, sv(s)); } else { promote_history(pw->hist, bw->cursor->line); } } /* Do ~ expansion and set new current directory */ if (pw->file_prompt&2) { set_current_dir(s,1); } if (pw->file_prompt) { s = canonical(s); } win = w->win; pfunc = pw->pfunc; object = pw->object; bwrm(bw); joe_free(pw->prompt); joe_free(pw); w->object = NULL; notify = w->notify; w->notify = 0; wabort(w); dostaupd = 1; /* Call callback function */ if (pfunc) { return pfunc(win->object, s, object, notify); } else { return -1; } }
int ucenter(BW *bw) { P *p = bw->cursor, *q; long endcol, begcol, x; int c; p_goto_eol(p); while (joe_isblank(bw->b->o.charmap, (c = prgetc(p)))) /* do nothing */; if (c == '\n') { pgetc(p); goto done; } if (c == NO_MORE_DATA) goto done; pgetc(p); endcol = piscol(p); p_goto_bol(p); while (joe_isblank(bw->b->o.charmap, (c = pgetc(p)))) /* do nothing */; if (c == '\n') { prgetc(p); goto done; } if (c == NO_MORE_DATA) goto done; prgetc(p); begcol = piscol(p); if (endcol - begcol > bw->o.rmargin + bw->o.lmargin) goto done; q = pdup(p, USTR "ucenter"); p_goto_bol(q); bdel(q, p); prm(q); for (x = 0; x != (bw->o.lmargin + bw->o.rmargin) / 2 - (endcol - begcol) / 2; ++x) binsc(p, ' '); done: if (!pnextl(p)) { binsc(p, '\n'); pgetc(p); return -1; } else return 0; }
void wrapword(BW *bw, P *p, long int indent, int french, int no_over, unsigned char *indents) { P *q; P *r; P *s; int rmf = 0; int c; long to = p->byte; int my_indents = 0; /* autoindent when called by utype */ if (!indents) { /* Get indentation prefix from beginning of line */ s = pdup(p, USTR "wrapword"); p_goto_bol(s); pbop(bw, s); /* Record indentation of second line of paragraph, of first * line if there is only one line */ q = pdup(s, USTR "wrapword"); pnextl(q); if (q->line < p->line) { /* Second line */ P *r = pdup(q, USTR "wrapword"); indent = nindent(bw, q, 0); pcol(r, indent); indents = brs(q, r->byte - q->byte); prm(r); } else { /* First line */ P *r = pdup(s, USTR "uformat"); int x, y; indent = nindent(bw, s, 1); pcol(r, indent); indents = brs(s, r->byte - s->byte); prm(r); if (!bw->o.autoindent) { /* Don't indent second line of single-line paragraphs if autoindent is off */ int x = zlen(indents); while (x && (indents[x - 1] == ' ' || indents[x - 1] == '\t')) indents[--x] = 0; if (x) { indents[x++] = ' '; indents[x] = 0; } indent = txtwidth1(bw->o.charmap, bw->o.tab, indents, x); } for (x = 0; indents[x] && (indents[x] == ' ' || indents[x] == '\t'); ++x); y = zlen(indents); while (y && (indents[y - 1] == ' ' || indents[y - 1] == '\t')) --y; /* Don't duplicate bullet */ /* if (y && (indents[y - 1] == '*' || indents[y - 1] == '-') && (y == 1 || indents[y - 2] == ' ' || indents[y - 2] == '\t')) indents[y - 1] = ' '; */ /* Fix C comment */ if (indents[x] == '/' && indents[x + 1] == '*') indents[x] = ' '; } if (bw->o.lmargin > indent) { int x; for (x = 0; indents[x] == ' ' || indents[x] == '\t'; ++x); if (!indents[x]) { joe_free(indents); indent = bw->o.lmargin; indents = joe_malloc(indent+1); for (x = 0; x != indent; ++x) indents[x] = ' '; indents[x] = 0; } } my_indents = 1; prm(q); prm(s); } /* if(!indents) { int f = 0; P *r = pdup(p); p_goto_bol(r); q = pdup(r); while(cpara(c = brc(q))) { if(!joe_isblank(c)) f = 1; pgetc(q); } if(f) { indents = brs(r, q->byte-r->byte); rmf = 1; if(indents[0] == '/' && indents[1] == '*') indents[0] = ' '; } prm(r); prm(q); } */ /* Get to beginning of word */ while (!pisbol(p) && piscol(p) > indent && !joe_isblank(p->b->o.charmap, prgetc(p))) /* do nothing */; /* If we found the beginning of a word... */ if (!pisbol(p) && piscol(p) > indent) { /* Move q to two (or one if 'french' is set) spaces after end of previous word */ q = pdup(p, USTR "wrapword"); while (!pisbol(q)) if (!joe_isblank(p->b->o.charmap, (c = prgetc(q)))) { pgetc(q); if ((c == '.' || c == '?' || c == '!') && q->byte != p->byte && !french) pgetc(q); break; } pgetc(p); /* Delete space between start of word and end of previous word */ to -= p->byte - q->byte; bdel(q, p); prm(q); if (bw->o.flowed) { binsc(p, ' '); pgetc(p); ++to; } /* Move word to beginning of next line */ binsc(p, '\n'); /* When overtype is on, do not insert lines */ if (!no_over && p->b->o.overtype){ /* delete the next line break which is unnecessary */ r = pdup(p, USTR "wrapword"); /* p_goto_eol(r); */ pgetc(r); p_goto_eol(r); s = pdup(r, USTR "wrapword"); pgetc(r); bdel(s,r); binsc(r, ' '); /* Now we got to take care that all subsequent lines are not longer than the right margin */ /* Move cursor to right margin */ pfwrd(r, r->b->o.rmargin - r->col); /* Make a copy of the cursor and move the copied cursor to the end of the line */ prm(s); s = pdup(r, USTR "wrapword"); p_goto_eol(s); /* If s is located behind r then the line goes beyond the right margin and we need to call wordwrap() for that line. */ /* if (r->byte < s->byte){ wrapword(bw, r, indent, french, 1, indents); } */ prm(r); prm(s); } ++to; if (p->b->o.crlf) ++to; pgetc(p); /* Indent to left margin */ if (indents) { binss(p, indents); to += zlen(indents); } else while (indent--) { binsc(p, ' '); ++to; } if (rmf) joe_free(indents); } /* Move cursor back to original position */ pfwrd(p, to - p->byte); if (my_indents) joe_free(indents); }