📄 ublock.c
字号:
if (!pprevl(p)) goto done; else p_goto_bol(p); } while (pisindent(p) >= indent || pisblank(p)); pnextl(p); /* Maybe skip blank lines at beginning */ done: p_goto_bol(p); p->xcol = piscol(p); if (markb) prm(markb); markb = p; p->owner = &markb; do { if (!pnextl(q)) break; } while (pisindent(q) >= indent || pisblank(q)); /* Maybe skip blank lines at end */ if (markk) prm(markk); q->xcol = piscol(q); markk = q; q->owner = &markk; updall();}/* Purity check *//* Verifies that at least n indentation characters (for non-blank lines) match c *//* If n is 0 (for urindent), this fails if c is space but indentation begins with tab */int purity_check(int c, int n){ P *p = pdup(markb, USTR "purity_check"); while (p->byte < markk->byte) { int x; p_goto_bol(p); if (!n && c==' ' && brc(p)=='\t') { prm(p); return 0; } else if (!piseol(p)) for (x=0; x!=n; ++x) if (pgetc(p)!=c) { prm(p); return 0; } pnextl(p); } prm(p); return 1;}/* Left indent check *//* Verify that there is enough whitespace to do the left indent */int lindent_check(int c, int n){ P *p = pdup(markb, USTR "lindent_check"); int indwid; if (c=='\t') indwid = n * p->b->o.tab; else indwid = n; while (p->byte < markk->byte) { p_goto_bol(p); if (!piseol(p) && pisindent(p)<indwid) { prm(p); return 0; } pnextl(p); } prm(p); return 1;}/* Indent more */int urindent(BW *bw){ if (square) { if (markb && markk && markb->b == markk->b && markb->byte <= markk->byte && markb->xcol <= markk->xcol) { P *p = pdup(markb, USTR "urindent"); do { pcol(p, markb->xcol); pfill(p, markb->xcol + bw->o.istep, bw->o.indentc); } while (pnextl(p) && p->line <= markk->line); prm(p); } } else { if (!markb || !markk || markb->b != markk->b || bw->cursor->byte < markb->byte || bw->cursor->byte > markk->byte || markb->byte == markk->byte) { setindent(bw); } else if ( 1 /* bw->o.purify */) { P *p = pdup(markb, USTR "urindent"); P *q = pdup(markb, USTR "urindent"); int indwid; if (bw->o.indentc=='\t') indwid = bw->o.tab * bw->o.istep; else indwid = bw->o.istep; while (p->byte < markk->byte) { p_goto_bol(p); if (!piseol(p)) { int col; pset(q, p); p_goto_indent(q, bw->o.indentc); col = piscol(q); bdel(p,q); pfill(p,col+indwid,bw->o.indentc); } pnextl(p); } prm(p); prm(q); } else if (purity_check(bw->o.indentc,0)) { P *p = pdup(markb, USTR "urindent"); while (p->byte < markk->byte) { p_goto_bol(p); if (!piseol(p)) while (piscol(p) < bw->o.istep) { binsc(p, bw->o.indentc); pgetc(p); } pnextl(p); } prm(p); } else { /* Purity failure */ msgnw(bw->parent,joe_gettext(_("Selected lines not properly indented"))); return 1; } } return 0;}/* Indent less */int ulindent(BW *bw){ if (square) { if (markb && markk && markb->b == markk->b && markb->byte <= markk->byte && markb->xcol <= markk->xcol) { P *p = pdup(markb, USTR "ulindent"); P *q = pdup(p, USTR "ulindent"); do { pcol(p, markb->xcol); while (piscol(p) < markb->xcol + bw->o.istep) { int c = pgetc(p); if (c != ' ' && c != '\t' && c != bw->o.indentc) { prm(p); prm(q); return -1; } } } while (pnextl(p) && p->line <= markk->line); pset(p, markb); do { pcol(p, markb->xcol); pset(q, p); pcol(q, markb->xcol + bw->o.istep); bdel(p, q); } while (pnextl(p) && p->line <= markk->line); prm(p); prm(q); } } else { if (!markb || !markk || markb->b != markk->b || bw->cursor->byte < markb->byte || bw->cursor->byte > markk->byte || markb->byte == markk->byte) { setindent(bw); } else if (1 /* bw->o.purify */ && lindent_check(bw->o.indentc,bw->o.istep)) { P *p = pdup(markb, USTR "ulindent"); P *q = pdup(markb, USTR "ulindent"); int indwid; if (bw->o.indentc=='\t') indwid = bw->o.tab * bw->o.istep; else indwid = bw->o.istep; while (p->byte < markk->byte) { p_goto_bol(p); if (!piseol(p)) { int col; pset(q, p); p_goto_indent(q, bw->o.indentc); col = piscol(q); bdel(p,q); pfill(p,col-indwid,bw->o.indentc); } pnextl(p); } prm(p); prm(q); } else if (purity_check(bw->o.indentc,bw->o.istep)) { P *p = pdup(markb, USTR "ulindent"); P *q = pdup(p, USTR "ulindent"); p_goto_bol(p); while (p->byte < markk->byte) { if (!piseol(p)) { pset(q, p); while (piscol(q) < bw->o.istep) pgetc(q); bdel(p, q); } pnextl(p); } prm(p); prm(q); } else { /* Purity failure */ msgnw(bw->parent,joe_gettext(_("Selected lines not properly indented"))); return 1; } } return 0;}/* Insert a file */int doinsf(BW *bw, unsigned char *s, void *object, int *notify){ if (notify) *notify = 1; if (square) if (markv(1)) { B *tmp; long width = markk->xcol - markb->xcol; long height; int usetabs = ptabrect(markb, markk->line - markb->line + 1, markk->xcol); tmp = bload(s); if (berror) { msgnw(bw->parent, joe_gettext(msgs[-berror])); brm(tmp); return -1; } if (piscol(tmp->eof)) height = tmp->eof->line + 1; else height = tmp->eof->line; if (bw->o.overtype) { pclrrect(markb, long_max(markk->line - markb->line + 1, height), markk->xcol, usetabs); pdelrect(markb, height, width + markb->xcol); } pinsrect(markb, tmp, width, usetabs); pdupown(markb, &markk, USTR "doinsf"); markk->xcol = markb->xcol; if (height) { pline(markk, markk->line + height - 1); pcol(markk, markb->xcol + width); markk->xcol = markb->xcol + width; } brm(tmp); updall(); return 0; } else { msgnw(bw->parent, joe_gettext(_("No block"))); return -1; } else { int ret = 0; B *tmp = bload(s); if (berror) { msgnw(bw->parent, joe_gettext(msgs[-berror])), brm(tmp); ret = -1; } else binsb(bw->cursor, tmp); vsrm(s); bw->cursor->xcol = piscol(bw->cursor); return ret; }}/* Filter highlighted block through a UNIX command */static int filtflg = 0;static int dofilt(BW *bw, unsigned char *s, void *object, int *notify){ int fr[2]; int fw[2]; int flg = 0; if (notify) *notify = 1; if (markb && markk && !square && markb->b == bw->b && markk->b == bw->b && markb->byte == markk->byte) { flg = 1; goto ok; } if (!markv(1)) { msgnw(bw->parent, joe_gettext(_("No block"))); return -1; } ok: pipe(fr); pipe(fw); npartial(bw->parent->t->t); ttclsn();#ifdef HAVE_FORK if (!fork()) {#else if (!vfork()) { /* For AMIGA only */#endif#ifdef HAVE_PUTENV unsigned char *fname, *name; unsigned len;#endif signrm(); close(0); close(1); close(2); dup(fw[0]); dup(fr[1]); dup(fr[1]); close(fw[0]); close(fr[1]); close(fw[1]); close(fr[0]);#ifdef HAVE_PUTENV fname = vsncpy(NULL, 0, sc("JOE_FILENAME=")); name = bw->b->name ? bw->b->name : (unsigned char *)"Unnamed"; if((len = slen(name)) >= 512) /* limit filename length */ len = 512; fname = vsncpy(sv(fname), name, len); putenv((char *)fname); vsrm(fname);#endif execl("/bin/sh", "/bin/sh", "-c", s, NULL); _exit(0); } close(fr[1]); close(fw[0]);#ifdef HAVE_FORK if (fork()) {#else if (vfork()) { /* For AMIGA only */#endif close(fw[1]); if (square) { B *tmp; long width = markk->xcol - markb->xcol; long height; int usetabs = ptabrect(markb, markk->line - markb->line + 1, markk->xcol); tmp = bread(fr[0], MAXLONG); if (piscol(tmp->eof)) height = tmp->eof->line + 1; else height = tmp->eof->line; if (bw->o.overtype) { pclrrect(markb, markk->line - markb->line + 1, markk->xcol, usetabs); pdelrect(markb, long_max(height, markk->line - markb->line + 1), width + markb->xcol); } else pdelrect(markb, markk->line - markb->line + 1, markk->xcol); pinsrect(markb, tmp, width, usetabs); pdupown(markb, &markk, USTR "dofilt"); markk->xcol = markb->xcol; if (height) { pline(markk, markk->line + height - 1); pcol(markk, markb->xcol + width); markk->xcol = markb->xcol + width; } if (lightoff) unmark(bw); brm(tmp); updall(); } else { P *p = pdup(markk, USTR "dofilt"); if (!flg) prgetc(p); bdel(markb, p); binsb(p, bread(fr[0], MAXLONG)); if (!flg) { pset(p,markk); prgetc(p); bdel(p,markk); } prm(p); if (lightoff) unmark(bw); } close(fr[0]); wait(NULL); wait(NULL); } else { if (square) { B *tmp = pextrect(markb, markk->line - markb->line + 1, markk->xcol); bsavefd(tmp->bof, fw[1], tmp->eof->byte); } else bsavefd(markb, fw[1], markk->byte - markb->byte); close(fw[1]); _exit(0); } vsrm(s); ttopnn(); if (filtflg) unmark(bw); bw->cursor->xcol = piscol(bw->cursor); return 0;}static B *filthist = NULL;static void markall(BW *bw){ pdupown(bw->cursor->b->bof, &markb, USTR "markall"); markb->xcol = 0; pdupown(bw->cursor->b->eof, &markk, USTR "markall"); markk->xcol = piscol(markk); updall();}static int checkmark(BW *bw){ if (!markv(1)) if (square) return 2; else { markall(bw); filtflg = 1; return 1; } else { filtflg = 0; return 0; }}int ufilt(BW *bw){#ifdef __MSDOS__ msgnw(bw->parent, joe_gettext(_("Sorry, no sub-processes in DOS (yet)"))); return -1;#else switch (checkmark(bw)) { case 0: if (wmkpw(bw->parent, joe_gettext(_("Command to filter block through (^C to abort): ")), &filthist, dofilt, NULL, NULL, utypebw, NULL, NULL, locale_map, 1)) return 0; else return -1; case 1: if (wmkpw(bw->parent, joe_gettext(_("Command to filter file through (^C to abort): ")), &filthist, dofilt, NULL, NULL, utypebw, NULL, NULL, locale_map, 1)) return 0; else return -1; case 2: default: msgnw(bw->parent, joe_gettext(_("No block"))); return -1; }#endif}/* Force region to lower case */int ulower(BW *bw){ if (markv(1)) { P *q; P *p; int c; B *b = bcpy(markb,markk); /* Leave one character in buffer to keep pointers set properly... */ q = pdup(markk, USTR "ulower"); prgetc(q); bdel(markb,q); b->o.charmap = markb->b->o.charmap; p=pdup(b->bof, USTR "ulower"); while ((c=pgetc(p))!=NO_MORE_DATA) { c = joe_tolower(b->o.charmap,c); binsc(q,c); pgetc(q); } prm(p); bdel(q,markk); prm(q); brm(b); bw->cursor->xcol = piscol(bw->cursor); return 0; } else return -1;}/* Force region to upper case */int uupper(BW *bw){ if (markv(1)) { P *q; P *p; int c; B *b = bcpy(markb,markk); q = pdup(markk, USTR "uupper"); prgetc(q); bdel(markb,q); b->o.charmap = markb->b->o.charmap; p=pdup(b->bof, USTR "uupper"); while ((c=pgetc(p))!=NO_MORE_DATA) { c = joe_toupper(b->o.charmap,c); binsc(q,c); pgetc(q); } prm(p); bdel(q,markk); prm(q); brm(b); bw->cursor->xcol = piscol(bw->cursor); return 0; } else return -1;}/* Get sum, sum of squares, and return count of * a block of numbers. * * avg = sum/count * * stddev = sqrt( (a-avg)^2 + (b-avg)^2 + (c-avg)^2 ) * = sqrt( a^2-2*a*avg+avg^2 + b^2-2*b*avg+avg^2 +燾^2-2*c*avg+avg^2 ) * = sqrt( a^2+b^2+c^2 + 3*avg^2 - 2*avg*(a+b+c) ) * = sqrt( sumsq + count*avg^2 - 2*avg*sum ) * */int blksum(double *sum, double *sumsq){ unsigned char buf[80]; if (markv(1)) { P *q = pdup(markb, USTR "blksum"); int x; int c; double accu = 0.0; double accusq = 0.0; double v; int count = 0; long left = markb->xcol; long right = markk->xcol; while (q->byte < markk->byte) { /* Skip until we're within columns */ while (q->byte < markk->byte && square && (piscol(q) < left || piscol(q) >= right)) pgetc(q); /* Skip to first number */ while (q->byte < markk->byte && (!square || (piscol(q) >= left && piscol(q) < right))) { c=pgetc(q); if ((c >= '0' && c <= '9') || c == '.' || c == '-') { /* Copy number into buffer */ buf[0]=c; x=1; while (q->byte < markk->byte && (!square || (piscol(q) >= left && piscol(q) < right))) { c=pgetc(q); if ((c >= '0' && c <= '9') || c == 'e' || c == 'E' || c == 'p' || c == 'P' || c == 'x' || c == 'X' || c == '.' || c == '-' || c == '+' || (c >= 'a' && c <= 'f') || (c >= 'A' && c<='F')) { if(x != 79) buf[x++]=c; } else break; } /* Convert number to floating point, add it to total */ buf[x] = 0; v = strtod((char *)buf,NULL); ++count; accu += v; accusq += v*v; break; } } } prm(q); *sum = accu; *sumsq = accusq; return count; } else return -1;}/* Get a (possibly square) block into a buffer */unsigned char *blkget(){ if (markv(1)) { P *q; unsigned char *buf=joe_malloc(markk->byte-markb->byte+1); unsigned char *s=buf; long left = markb->xcol; long right = markk->xcol; q = pdup(markb, USTR "blkget"); while (q->byte < markk->byte) { /* Skip until we're within columns */ while (q->byte < markk->byte && square && (piscol(q) < left || piscol(q) >= right)) pgetc(q); /* Copy text into buffer */ while (q->byte < markk->byte && (!square || (piscol(q) >= left && piscol(q) < right))) { *s++ = pgetc(q); } /* Add a new line if we went past right edge of column */ if (square && q->byte<markk->byte && piscol(q) >= right) *s++ = '\n'; } prm(q); *s = 0; return buf; } else return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -