P *pbop(BW *bw, P *p) { long indent; long prelen; P *last; p_goto_bol(p); indent = nindent(bw, p, 0); prelen = prefix(bw, p, 0); last = pdup(p, USTR "pbop"); while (!pisbof(p) && (!within || !markb || p->byte > markb->byte)) { long ind; long len; pprevl(p); p_goto_bol(p); ind = nindent(bw, p, 0); len = prefix(bw, p, 0); if (pisnpara(bw, p) || len != prelen) { pset(p, last); break; } if (ind > indent) { /* int ok = 1; P *q = pdup(p, USTR "pbop"); if (pprevl(q)) { p_goto_bol(q); if (nindent(bw, q, 0) == ind) ok = 0; } prm(q); if (!ok) pnextl(p); */ break; } if (ind < indent) { pset(p, last); break; /* if (pisbof(p)) { break; } pprevl(p); p_goto_bol(p); if (pisnpara(bw, p)) { pnextl(p); break; } else { pnextl(p); pnextl(p); break; } */ } pset(last, p); } prm(last); return p; }
static char *get_context(BW *bw) { P *p = pdup(bw->cursor, "get_context"); static char buf1[stdsiz]; int i, j, spc; buf1[0] = 0; /* Find first line with 0 indentation which is not a comment line */ do { p_goto_bol(p); if (!pisindent(p) && !pisblank(p)) { /* next: */ brzs(p,stdbuf,stdsiz/8); /* To avoid buffer overruns with my_iconv */ /* Ignore comment and block structuring lines */ if (!(stdbuf[0]=='{' || (stdbuf[0]=='/' && stdbuf[1]=='*') || stdbuf[0]=='\f' || (stdbuf[0]=='/' && stdbuf[1]=='/') || stdbuf[0]=='#' || (stdbuf[0]=='b' && stdbuf[1]=='e' && stdbuf[2]=='g' && stdbuf[3]=='i' && stdbuf[4]=='n') || (stdbuf[0]=='B' && stdbuf[1]=='E' && stdbuf[2]=='G' && stdbuf[3]=='I' && stdbuf[4]=='N') || (stdbuf[0]=='-' && stdbuf[1]=='-') || stdbuf[0]==';')) { /* zlcpy(buf1, SIZEOF(buf1), stdbuf); */ /* replace tabs to spaces and remove adjoining spaces */ for (i=0,j=0,spc=0; stdbuf[i]; i++) { if (stdbuf[i]=='\t' || stdbuf[i]==' ') { if (spc) continue; spc = 1; } else spc = 0; if (stdbuf[i]=='\t') buf1[j++] = ' '; else if (stdbuf[i]=='\\') { buf1[j++] = '\\'; buf1[j++] = '\\'; } else buf1[j++] = stdbuf[i]; } buf1[j]= '\0'; /* Uncomment to get the last line instead of the first line (see above) if (pprevl(p)) { p_goto_bol(p); if (!pisindent(p) && !pisblank(p)) goto next; } */ break; } } } while (!buf1[0] && pprevl(p)); prm(p); return buf1; }
int ubop(BW *bw) { P *q = pdup(bw->cursor, USTR "ubop"); up: while (pisnpara(bw, q) && !pisbof(q) && (!within || !markb || q->byte > markb->byte)) pprevl(q); pbop(bw, q); if (q->byte != bw->cursor->byte) { pset(bw->cursor, q); prm(q); return 0; } else if (!pisbof(q)) { prgetc(q); goto up; } else { prm(q); return -1; } }