static int utypeqw(QW *qw, int c) { W *win; W *w = qw->parent; int *notify = w->notify; int (*func) (); void *object = qw->object; if (locale_map->type) { c = utf8_decode(&qw_sm, c); if (c<0) return 0; } win = qw->parent->win; func = qw->func; vsrm(qw->prompt); joe_free(qw); w->object = NULL; w->notify = NULL; wabort(w); if (func) return func(win->object, c, object, notify); return -1; }
static int abortpw(BW *b) { PW *pw = b->object; void *object = pw->object; int (*abrt) () = pw->abrt; W *win = b->parent->win; bwrm(b); joe_free(pw->prompt); joe_free(pw); if (abrt) { return abrt(win->object, object); } else { return -1; } }
int jfclose(JFILE *f) { int rtn = 0; if (f->f) rtn = fclose(f->f); joe_free(f); return rtn; }
static void rmisrch(struct isrch *isrch) { /* Eliminate a struct isrch */ if (isrch) { vsrm(isrch->pattern); vsrm(isrch->prompt); frchn(&fri, &isrch->irecs); joe_free(isrch); } }
void rmkmap(KMAP *kmap) { int x; if (!kmap) return; for (x = 0; x != KEYS; ++x) if (kmap->keys[x].k == 1) rmkmap(kmap->keys[x].value.submap); joe_free(kmap); }
static int abortqw(QW *qw) { W *win = qw->parent->win; void *object = qw->object; int (*abrt) () = qw->abrt; vsrm(qw->prompt); joe_free(qw); if (abrt) return abrt(win->object, object); else return -1; }
static void frrec(UNDOREC *rec) { if (rec->del) { if (rec->len < SMALL) joe_free(rec->small); else { B *b = rec->big; bonline(b); brm(b); } } enquef(UNDOREC, link, &frrecs, rec); }
void *joe_realloc(void *ptr, size_t size) { struct mcheck *n; unsigned char *np; struct mcheck *m = (struct mcheck *)((char *)ptr-sizeof(struct mcheck)); if(!size) { printf("0 passed to realloc\n"); *(int *)0=0; } np = joe_malloc(size); n = (struct mcheck *)(np-sizeof(struct mcheck)); if(m->size>size) memcpy(np,ptr,size); else memcpy(np,ptr,m->size); joe_free(ptr); return np; }
void ttopnn(void) { int x, bbaud; #ifdef HAVE_POSIX_TERMIOS struct termios newterm; #else #ifdef HAVE_SYSV_TERMIO struct termio newterm; #else struct sgttyb arg; struct tchars targ; struct ltchars ltarg; #endif #endif if (!termin) { if (idleout ? (!(termin = stdin) || !(termout = stdout)) : (!(termin = fopen("/dev/tty", "r")) || !(termout = fopen("/dev/tty", "w")))) { fprintf(stderr, (char *)joe_gettext(_("Couldn\'t open /dev/tty\n"))); exit(1); } else { #ifdef SIGWINCH joe_set_signal(SIGWINCH, winchd); #endif } } if (ttymode) return; ttymode = 1; fflush(termout); #ifdef HAVE_POSIX_TERMIOS tcgetattr(fileno(termin), &oldterm); newterm = oldterm; newterm.c_lflag = 0; if (noxon) newterm.c_iflag &= ~(ICRNL | IGNCR | INLCR | IXON | IXOFF); else newterm.c_iflag &= ~(ICRNL | IGNCR | INLCR); newterm.c_oflag = 0; newterm.c_cc[VMIN] = 1; newterm.c_cc[VTIME] = 0; tcsetattr(fileno(termin), TCSADRAIN, &newterm); bbaud = cfgetospeed(&newterm); #else #ifdef HAVE_SYSV_TERMIO joe_ioctl(fileno(termin), TCGETA, &oldterm); newterm = oldterm; newterm.c_lflag = 0; if (noxon) newterm.c_iflag &= ~(ICRNL | IGNCR | INLCR | IXON | IXOFF); else newterm.c_iflag &= ~(ICRNL | IGNCR | INLCR); newterm.c_oflag = 0; newterm.c_cc[VMIN] = 1; newterm.c_cc[VTIME] = 0; joe_ioctl(fileno(termin), TCSETAW, &newterm); bbaud = (newterm.c_cflag & CBAUD); #else joe_ioctl(fileno(termin), TIOCGETP, &arg); joe_ioctl(fileno(termin), TIOCGETC, &targ); joe_ioctl(fileno(termin), TIOCGLTC, <arg); oarg = arg; otarg = targ; oltarg = ltarg; arg.sg_flags = ((arg.sg_flags & ~(ECHO | CRMOD | XTABS | ALLDELAY | TILDE)) | CBREAK); if (noxon) { targ.t_startc = -1; targ.t_stopc = -1; } targ.t_intrc = -1; targ.t_quitc = -1; targ.t_eofc = -1; targ.t_brkc = -1; ltarg.t_suspc = -1; ltarg.t_dsuspc = -1; ltarg.t_rprntc = -1; ltarg.t_flushc = -1; ltarg.t_werasc = -1; ltarg.t_lnextc = -1; joe_ioctl(fileno(termin), TIOCSETN, &arg); joe_ioctl(fileno(termin), TIOCSETC, &targ); joe_ioctl(fileno(termin), TIOCSLTC, <arg); bbaud = arg.sg_ospeed; #endif #endif baud = 9600; upc = 0; for (x = 0; x != 30; x += 2) if (bbaud == speeds[x]) { baud = speeds[x + 1]; break; } if (Baud) baud = Baud; upc = DIVIDEND / baud; if (obuf) joe_free(obuf); if (!(TIMES * upc)) obufsiz = 4096; else { obufsiz = 1000000 / (TIMES * upc); if (obufsiz > 4096) obufsiz = 4096; } if (!obufsiz) obufsiz = 1; obuf = (unsigned char *) joe_malloc(obufsiz); }
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); }
struct high_param *parse_params(struct high_param *current_params, unsigned char **ptr, unsigned char *name, int line) { unsigned char *p = *ptr; unsigned char bf[256]; struct high_param *params; struct high_param **param_ptr; /* Propagate currently defined parameters */ param_ptr = ¶ms; while (current_params) { *param_ptr = joe_malloc(sizeof(struct high_param)); (*param_ptr)->name = zdup(current_params->name); param_ptr = &(*param_ptr)->next; current_params = current_params->next; } *param_ptr = 0; parse_ws(&p, '#'); if (!parse_char(&p, '(')) { for (;;) { parse_ws(&p, '#'); if (!parse_char(&p, ')')) { break; } else if (!parse_char(&p, '-')) { if (!parse_ident(&p, bf, sizeof(bf))) { int cmp = 0; param_ptr = ¶ms; /* Parameters are sorted */ while (*param_ptr && (cmp = zcmp(bf, (*param_ptr)->name)) > 0) { param_ptr = &(*param_ptr)->next; } if (*param_ptr && !cmp) { /* Remove this parameter */ struct high_param *param = *param_ptr; *param_ptr = param->next; joe_free(param); } } else { i_printf_2((char *)joe_gettext(_("%s %d: Missing parameter name\n")), name, line); } } else if (!parse_ident(&p, bf, sizeof(bf))) { int cmp = 0; param_ptr = ¶ms; /* Keep parameters sorted */ while (*param_ptr && (cmp = zcmp(bf, (*param_ptr)->name)) > 0) { param_ptr = &(*param_ptr)->next; } /* Discard duplicates */ if (!*param_ptr || cmp) { struct high_param *param = joe_malloc(sizeof(struct high_param)); param->name = zdup(bf); param->next = *param_ptr; *param_ptr = param; } } else { i_printf_2((char *)joe_gettext(_("%s %d: Missing )\n")), name, line); break; } } } *ptr = p; return params; }
struct high_state *load_dfa(struct high_syntax *syntax) { unsigned char name[1024]; unsigned char buf[1024]; unsigned char bf[256]; int clist[256]; unsigned char *p; int c; FILE *f = NULL; struct ifstack *stack = 0; struct high_state *state = 0; /* Current state */ struct high_state *first = 0; /* First state */ int line = 0; int this_one = 0; int inside_subr = 0; /* Load it */ if ((p = (unsigned char *)exists_prefs_dir()) && strlen((const char *)p) + 2 + strlen(SYNTAX_DIR) + strlen(SYNTAX_EXT) + strlen((const char *)syntax->name) < sizeof name) { strcat(strcat(strcat(strcat(strcpy((char *)name, (const char *)p), SYNTAX_DIR), "/"), (const char *)syntax->name), SYNTAX_EXT); f = fopen((char *)name, "r"); } if (!f && (p = (unsigned char *)exists_gprefs_dir()) && strlen((const char *)p) + 2 + strlen(SYNTAX_DIR) + strlen(SYNTAX_EXT) + strlen((const char *)syntax->name) < sizeof name) { strcat(strcat(strcat(strcat(strcpy((char *)name, (const char *)p), SYNTAX_DIR), "/"), (const char *)syntax->name), SYNTAX_EXT); f = fopen((char *)name, "r"); } if (!f) { return 0; } /* Parse file */ while (fgets((char *)buf, 1023, f)) { ++line; p = buf; c = parse_ws(&p, '#'); if (!parse_char(&p, '.')) { if (!parse_ident(&p, bf, sizeof(bf))) { if (!zcmp(bf, USTR "ifdef")) { struct ifstack *st = joe_malloc(sizeof(struct ifstack)); st->next = stack; st->else_part = 0; st->ignore = 1; st->skip = 1; st->line = line; if (!stack || !stack->ignore) { parse_ws(&p, '#'); if (!parse_ident(&p, bf, sizeof(bf))) { struct high_param *param; for (param = syntax->params; param; param = param->next) if (!zcmp(param->name, bf)) { st->ignore = 0; break; } st->skip = 0; } else { i_printf_2((char *)joe_gettext(_("%s %d: missing parameter for ifdef\n")), name, line); } } stack = st; } else if (!zcmp(bf, USTR "else")) { if (stack && !stack->else_part) { stack->else_part = 1; if (!stack->skip) { stack->ignore = !stack->ignore; } } else { i_printf_2((char *)joe_gettext(_("%s %d: else with no matching if\n")), name, line); } } else if (!zcmp(bf, USTR "endif")) { if (stack) { struct ifstack *st = stack; stack = st->next; joe_free(st); } else { i_printf_2((char *)joe_gettext(_("%s %d: endif with no matching if\n")), name, line); } } else if (!zcmp(bf, USTR "subr")) { parse_ws(&p, '#'); if (parse_ident(&p, bf, sizeof(bf))) { i_printf_2((char *)joe_gettext(_("%s %d: Missing subroutine name\n")), name, line); } else { if (!stack || !stack->ignore) { inside_subr = 1; this_one = 0; if (syntax->subr && !zcmp(bf, syntax->subr)) { this_one = 1; } } } } else if (!zcmp(bf, USTR "end")) { if (!stack || !stack->ignore) { this_one = 0; inside_subr = 0; } } else { i_printf_2((char *)joe_gettext(_("%s %d: Unknown control statement\n")), name, line); } } else { i_printf_2((char *)joe_gettext(_("%s %d: Missing control statement name\n")), name, line); } } else if (stack && stack->ignore) { /* Ignore this line because of ifdef */ } else if (!parse_char(&p, '=')) { /* Parse color */ parse_color_def(&syntax->color, p, name, line); } else if ((syntax->subr && !this_one) || (!syntax->subr && inside_subr)) { /* Ignore this line because it's not the code we want */ } else if (!parse_char(&p, ':')) { if (!parse_ident(&p, bf, sizeof(bf))) { state = find_state(syntax, bf); if (!first) { first = state; } parse_ws(&p, '#'); if (!parse_tows(&p, bf)) { struct high_color *color; for (color = syntax->color; color; color = color->next) if (!zcmp(color->name, bf)) { break; } if (color) { state->color = color->color; } else { state->color = 0; i_printf_2((char *)joe_gettext(_("%s %d: Unknown class\n")), name, line); } } else { i_printf_2((char *)joe_gettext(_("%s %d: Missing color for state definition\n")), name, line); } } else { i_printf_2((char *)joe_gettext(_("%s %d: Missing state name\n")), name, line); } } else if (!parse_char(&p, '-')) { /* No. sync lines ignored */ } else { c = parse_ws(&p, '#'); if (!c) { } else if (c == '"' || c == '*' || c == '&') { if (state) { struct high_cmd *cmd; int delim = 0; if (!parse_field(&p, USTR "*")) { int z; for (z = 0; z != 256; ++z) { clist[z] = 1; } } else if (!parse_field(&p, USTR "&")) { delim = 1; } else { c = parse_string(&p, bf, sizeof(bf)); if (c < 0) { i_printf_2((char *)joe_gettext(_("%s %d: Bad string\n")), name, line); } else { int z; int first, second; unsigned char *t = bf; for (z = 0; z != 256; ++z) { clist[z] = 0; } while (!parse_range(&t, &first, &second)) { if (first > second) { second = first; } while (first <= second) { clist[first++] = 1; } } } } /* Create command */ cmd = mkcmd(); parse_ws(&p, '#'); if (!parse_ident(&p, bf, sizeof(bf))) { int z; cmd->new_state = find_state(syntax, bf); parse_options(syntax, cmd, f, p, 0, name, line); /* Install command */ if (delim) { state->delim = cmd; } else for (z = 0; z != 256; ++z) if (clist[z]) { state->cmd[z] = cmd; } } else { i_printf_2((char *)joe_gettext(_("%s %d: Missing jump\n")), name, line); } } else { i_printf_2((char *)joe_gettext(_("%s %d: No state\n")), name, line); } } else { i_printf_2((char *)joe_gettext(_("%s %d: Unknown character\n")), name, line); } } } while (stack) { struct ifstack *st = stack; stack = st->next; i_printf_2((char *)joe_gettext(_("%s %d: ifdef with no matching endif\n")), name, st->line); joe_free(st); } fclose(f); return first; }
static void yankdel(long where, B *b) { UNDOREC *rec; long size = b->eof->byte; /* Store in yank buffer */ rec = yanked.link.prev; if (!inyank) { if (rec != &yanked && where == rec->where && justkilled) { if (rec->len + size >= SMALL) { if (rec->len < SMALL) { rec->big = bmk(NULL); binsm(rec->big->bof, rec->small, (int) rec->len); boffline(rec->big); joe_free(rec->small); } bonline(rec->big); binsb(rec->big->eof, bcpy(b->bof, b->eof)); boffline(rec->big); } else { rec->small = (unsigned char *) joe_realloc(rec->small, rec->len + size); brmem(b->bof, rec->small + rec->len, (int) size); } rec->len += size; } else if (rec != &yanked && where + size == rec->where && justkilled) { if (rec->len + size >= SMALL) { if (rec->len < SMALL) { rec->big = bmk(NULL); binsm(rec->big->bof, rec->small, (int) rec->len); boffline(rec->big); joe_free(rec->small); } bonline(rec->big); binsb(rec->big->bof, bcpy(b->bof, b->eof)); boffline(rec->big); } else { rec->small = (unsigned char *) joe_realloc(rec->small, rec->len + size); mmove(rec->small + size, rec->small, (int) rec->len); brmem(b->bof, rec->small, (int) size); } rec->len += size; rec->where = where; } else { if (++nyanked == MAX_YANK) { frrec(deque_f(UNDOREC, link, yanked.link.next)); --nyanked; } rec = alrec(); if (size < SMALL && size > 0) { rec->small = (unsigned char *) joe_malloc(size); brmem(b->bof, rec->small, (int) b->eof->byte); } else { rec->big = bcpy(b->bof, b->eof); boffline(rec->big); } rec->where = where; rec->len = size; rec->del = 1; enqueb(UNDOREC, link, &yanked, rec); } } }
void undodel(UNDO *undo, long where, B *b) { UNDOREC *rec; long size = b->eof->byte; if (inredo) { brm(b); return; } if (!inundo) if (undo->ptr && undo->ptr != &undo->recs) undoover(undo); yankdel(where, b); /* Store in undo buffer */ rec = undo->recs.link.prev; if (rec != &undo->recs && rec->min && rec->del && where == rec->where) { if (rec->len + size >= SMALL) { if (rec->len < SMALL) { rec->big = bmk(NULL); binsm(rec->big->bof, rec->small, (int) rec->len); boffline(rec->big); joe_free(rec->small); } bonline(rec->big); binsb(rec->big->eof, b); boffline(rec->big); } else { rec->small = (unsigned char *) joe_realloc(rec->small, rec->len + size); brmem(b->bof, rec->small + rec->len, (int) size); brm(b); } rec->len += size; } else if (rec != &undo->recs && rec->min && rec->del && where + size == rec->where) { if (rec->len + size >= SMALL) { if (rec->len < SMALL) { rec->big = bmk(NULL); binsm(rec->big->bof, rec->small, (int) rec->len); boffline(rec->big); joe_free(rec->small); } bonline(rec->big); binsb(rec->big->bof, b); boffline(rec->big); } else { rec->small = (unsigned char *) joe_realloc(rec->small, rec->len + size); mmove(rec->small + size, rec->small, (int) rec->len); brmem(b->bof, rec->small, (int) size); brm(b); } rec->len += size; rec->where = where; } else { rec = alrec(); if (size < SMALL) { rec->small = (unsigned char *) joe_malloc(size); brmem(b->bof, rec->small, (int) b->eof->byte); brm(b); } else { rec->big = b; boffline(b); } if (!undo->first) undo->first = rec; undo->last = rec; rec->where = where; rec->min = 1; rec->unit = NULL; rec->len = size; rec->del = 1; rec->changed = undo->b->changed; enqueb(UNDOREC, link, &undo->recs, rec); } }
void rm_zs(ZS z) { joe_free(z.s); }
int uformat(BW *bw) { long indent; unsigned char *indents; B *buf; P *b; long curoff; int c; P *p, *q; p = pdup(bw->cursor, USTR "uformat"); p_goto_bol(p); /* Do nothing if we're not on a paragraph line */ if (pisnpara(bw, p)) { prm(p); return 0; } /* Move p to beginning of paragraph, bw->cursor to end of paragraph and * set curoff to original cursor offset within the paragraph */ pbop(bw, p); curoff = bw->cursor->byte - p->byte; pset(bw->cursor, p); peop(bw, bw->cursor); /* Ensure that paragraph ends on a beginning of a line */ if (!pisbol(bw->cursor)) binsc(bw->cursor, '\n'), pgetc(bw->cursor); /* Record indentation of second line of paragraph, of first line if there * is only one line */ q = pdup(p, USTR "uformat"); pnextl(q); if (q->line != bw->cursor->line) { P *r = pdup(q, USTR "uformat"); indent = nindent(bw, q, 0); pcol(r, indent); indents = brs(q, r->byte - q->byte); prm(r); } else { P *r = pdup(p, USTR "uformat"); int x, y; indent = nindent(bw, p, 1); /* allowing * and - here */ pcol(r, indent); indents = brs(p, r->byte - p->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 if it looks like a 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] = ' '; } prm(q); /* But if the left margin is greater, we use that instead */ 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; } } /* Cut paragraph into new buffer */ /* New buffer needs to inherit UTF-8 and CR-LF options */ buf = bcpy(p, bw->cursor); buf->o.crlf = p->b->o.crlf; buf->o.charmap = p->b->o.charmap; bdel(p, bw->cursor); /* text is in buffer. insert it at cursor */ /* Do first line */ b = pdup(buf->bof, USTR "uformat"); while (!piseof(b)) { /* Set cursor position if we're at original offset */ if (b->byte == curoff) pset(bw->cursor, p); /* Get character from buffer */ c = pgetc(b); /* Stop if we found end of line */ if (c == '\n') { prgetc(b); break; } /* Stop if we found white-space followed by end of line */ if (joe_isblank(b->b->o.charmap, c) && piseolblank(b)) { prgetc(b); break; } /* Insert character, advance pointer */ binsc(p, c); pgetc(p); /* Do word wrap if we reach right margin */ if (piscol(p) > bw->o.rmargin && !joe_isblank(p->b->o.charmap,c)) { wrapword(bw, p, indent, bw->o.french, 1, indents); break; } } /* Do rest */ while (!piseof(b)) { c = brch(b); if (joe_isblank(b->b->o.charmap,c) || c == '\n') { int f = 0; P *d; int g; /* Set f if there are two spaces after . ? or ! instead of one */ /* (What is c was '\n'?) */ d=pdup(b, USTR "uformat"); g=prgetc(d); if (g=='.' || g=='?' || g=='!') { f = 1; /* pset(d,b); pgetc(d); if (c == '\n' || piseol(d) || joe_isspace(bw->b->o.charmap,brch(d))) { f = 1; } */ } prm(d); /* Skip past the whitespace. Skip over indentations */ loop: c = brch(b); if (c == '\n') { if (b->byte == curoff) pset(bw->cursor, p); pgetc(b); while (cpara(bw, (c=brch(b)))) { if (b->byte == curoff) pset(bw->cursor, p); pgetc(b); } } if (joe_isblank(b->b->o.charmap,c)) { if(b->byte == curoff) pset(bw->cursor, p); pgetc(b); goto loop; } /* Insert proper amount of whitespace */ if (!piseof(b)) { if (f && !bw->o.french) binsc(p, ' '), pgetc(p); binsc(p, ' '); pgetc(p); } } else { /* Insert characters of word and wrap if necessary */ if (b->byte == curoff) pset(bw->cursor, p); binsc(p, pgetc(b)); pgetc(p); if (piscol(p) > bw->o.rmargin) wrapword(bw, p, indent, bw->o.french, 1, indents); } } binsc(p, '\n'); prm(p); brm(buf); joe_free(indents); return 0; }
void rmkbd(KBD *k) { joe_free(k); }