void load_yank(FILE *f) { UNDOREC *rec; unsigned char buf[SMALL*4+80]; unsigned char bf[SMALL+1]; while(fgets((char *)buf,sizeof(buf)-1,f) && strcmp(buf,"done\n")) { unsigned char *p = buf; int len; parse_ws(&p,'#'); len = parse_string(&p,bf,sizeof(bf)); if (len>0 && len<=SMALL) { if (++nyanked == MAX_YANK) { frrec(deque_f(UNDOREC, link, yanked.link.next)); --nyanked; } rec = alrec(); rec->small = (unsigned char *) joe_malloc(len); memcpy(rec->small,bf,len); rec->where = -1; rec->len = len; rec->del = 1; enqueb(UNDOREC, link, &yanked, rec); } } }
static int parseit(struct charmap *map,unsigned char *s, long int row, void (*parseone)(struct charmap *map, unsigned char *s, unsigned char **rtn_name, long *rtn_line)) { unsigned char *name = NULL; /* VS */ long line = -1; ERROR *err; parseone(map,s,&name,&line); if (name) { if (line != -1) { /* We have an error */ err = (ERROR *) alitem(&errnodes, sizeof(ERROR)); err->file = name; err->org = err->line = line; err->src = row; err->msg = vsncpy(NULL, 0, sc("\\i")); err->msg = vsncpy(sv(err->msg), sv(s)); enqueb(ERROR, link, &errors, err); return 1; } else vsrm(name); } return 0; }
void undoins(UNDO *undo, P *p, long size) { UNDOREC *rec; if (inredo) return; if (!inundo) if (undo->ptr && undo->ptr != &undo->recs) undoover(undo); rec = undo->recs.link.prev; if (rec != &undo->recs && rec->min && !rec->del && (p->byte == rec->where + rec->len || p->byte == rec->where)) rec->len += size; else { rec = alrec(); rec->del = 0; if (!undo->first) undo->first = rec; undo->last = rec; rec->where = p->byte; rec->min = 1; rec->unit = NULL; rec->len = size; rec->changed = undo->b->changed; enqueb(UNDOREC, link, &undo->recs, rec); } }
static void markpos(W *w, P *p) { POS *newpos = (POS *)alitem(&frpos, SIZEOF(POS)); newpos->p = NULL; pdupown(p, &newpos->p, "markpos"); poffline(newpos->p); newpos->w = w; enqueb(POS, link, &pos, newpos); if (npos == 20) { newpos = pos.link.next; prm(newpos->p); demote(POS, link, &frpos, newpos); } else { ++npos; } }
int uyankpop(BW *bw) { if (bw->b == yankbuf && bw->cursor->byte == yankwhere) { P *q; UNDOREC *ptr = yanked.link.prev; deque(UNDOREC, link, &yanked); enqueb(UNDOREC, link, ptr, &yanked); q = pdup(bw->cursor, "uyankpop"); pbkwd(q, ptr->len); inyank = 1; bdel(q, bw->cursor); inyank = 0; prm(q); return uyank(bw); } else return uyank(bw); }
static void iappend(BW *bw, struct isrch *isrch, char *s, ptrdiff_t len) { /* Append text and search */ /* Append char and search */ IREC *i = alirec(); SRCH *srch; i->what = len; i->disp = bw->cursor->byte; isrch->pattern = vsncpy(sv(isrch->pattern), s, len); if (!qempty(IREC, link, &isrch->irecs)) { pgoto(bw->cursor, isrch->irecs.link.prev->start); if (globalsrch) globalsrch->wrap_flag = isrch->irecs.link.prev->wrap_flag; } i->start = bw->cursor->byte; if (!globalsrch) srch = mksrch(NULL,NULL,opt_icase,isrch->dir,-1,0,0,0,0); else { srch = globalsrch; globalsrch = 0; } srch->addr = bw->cursor->byte; if (!srch->wrap_p || srch->wrap_p->b!=bw->b) { prm(srch->wrap_p); srch->wrap_p = pdup(bw->cursor, "iappend"); srch->wrap_p->owner = &srch->wrap_p; srch->wrap_flag = 0; } i->wrap_flag = srch->wrap_flag; setpat(srch, vsncpy(NULL, 0, isrch->pattern, sLen(isrch->pattern))); srch->backwards = isrch->dir; if (dopfnext(bw, srch, NULL)) { if(joe_beep) ttputc(7); } enqueb(IREC, link, &isrch->irecs, i); }
/* When called with c==-1, it just creates the prompt */ static int itype(W *w, int c, void *obj, int *notify) { IREC *i; int omid; BW *bw; struct isrch *isrch = (struct isrch *)obj; WIND_BW(bw,w); if (isrch->quote) { goto in; } if (c == 8 || c == 127) { /* Backup */ if ((i = isrch->irecs.link.prev) != &isrch->irecs) { pgoto(bw->cursor, i->disp); if (globalsrch) globalsrch->wrap_flag = i->wrap_flag; omid = opt_mid; opt_mid = 1; dofollows(); opt_mid = omid; isrch->pattern = vstrunc(isrch->pattern, sLEN(isrch->pattern) - i->what); frirec(deque_f(IREC, link, i)); } else { if(joe_beep) ttputc(7); } } else if (c == 'Q' - '@' /* || c == '`' */) { isrch->quote = 1; } else if (c == 'S' - '@' || c == '\\' - '@' || c == 'L' - '@' || c == 'R' - '@') { /* Repeat */ if (c == 'R' - '@') { isrch->dir = 1; } else { isrch->dir = 0; } if (qempty(IREC, link, &isrch->irecs)) { if (lastpat && lastpat[0]) { iappend(bw, isrch, sv(lastpat)); } } else { SRCH *srch; i = alirec(); i->disp = i->start = bw->cursor->byte; i->what = 0; if (!globalsrch) srch = mksrch(NULL,NULL,opt_icase,isrch->dir,-1,0,0,0,0); else { srch = globalsrch; globalsrch = 0; } srch->addr = bw->cursor->byte; if (!srch->wrap_p || srch->wrap_p->b!=bw->b) { prm(srch->wrap_p); srch->wrap_p = pdup(bw->cursor, "itype"); srch->wrap_p->owner = &srch->wrap_p; srch->wrap_flag = 0; } i->wrap_flag = srch->wrap_flag; setpat(srch, vsncpy(NULL, 0, isrch->pattern, sLen(isrch->pattern))); srch->backwards = isrch->dir; if (dopfnext(bw, srch, NULL)) { if(joe_beep) ttputc(7); frirec(i); } else { enqueb(IREC, link, &isrch->irecs, i); } } } else if (c >= 0 && c < 32) { /* Done when a control character is received */ nungetc(c); if (notify) { *notify = 1; } smode = 2; if (lastisrch) { lastpat = vstrunc(lastpat, 0); lastpat = vsncpy(lastpat, 0, lastisrch->pattern, sLen(lastisrch->pattern)); rmisrch(lastisrch); } lastisrch = isrch; return 0; } else if (c != -1) { char buf[16]; ptrdiff_t buf_len; /* Search */ in: if (bw->b->o.charmap->type) { buf_len = utf8_encode(buf, c); } else { buf[0] = TO_CHAR_OK(from_uni(bw->b->o.charmap, c)); buf_len = 1; } isrch->quote = 0; iappend(bw, isrch, buf, buf_len); } omid = opt_mid; opt_mid = 1; bw->cursor->xcol = piscol(bw->cursor); dofollows(); opt_mid = omid; isrch->prompt = vstrunc(isrch->prompt, isrch->ofst); if (locale_map->type && !bw->b->o.charmap->type) { /* Translate bytes to utf-8 */ char buf[16]; int x; for (x=0; x!=sLEN(isrch->pattern); ++x) { int tc = to_uni(bw->b->o.charmap, isrch->pattern[x]); utf8_encode(buf, tc); isrch->prompt = vsncpy(sv(isrch->prompt),sz(buf)); } } else if (!locale_map->type && bw->b->o.charmap->type) { /* Translate utf-8 to bytes */ const char *p = isrch->pattern; ptrdiff_t len = sLEN(isrch->pattern); while (len) { int tc = utf8_decode_fwrd(&p, &len); if (tc >= 0) { tc = from_uni(locale_map, tc); isrch->prompt = vsadd(isrch->prompt, TO_CHAR_OK(tc)); } } } else { /* FIXME: translate when charmaps do not match */ isrch->prompt = vsncpy(sv(isrch->prompt),sv(isrch->pattern)); } if (mkqwnsr(bw->parent, sv(isrch->prompt), itype, iabrt, isrch, notify)) { return 0; } else { rmisrch(isrch); return -1; } }
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); 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); 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); memmove(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); } }
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); 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); 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); memmove(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) { 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); } } }