static void global(int sense, int query) { register char* s; register int c; register Line_t* a1; if (ed.global) error(2, "recursive global not allowed"); setwide(); squeeze(ed.dol > ed.zero); compile(); if (query) newline(); else { s = getrec(ed.buffer.global, '\n', REC_SPLICE|REC_TERMINATE); if (s[0] == '\n' && !s[1]) sfputr(ed.buffer.global, "p\n", 0); } for (a1 = ed.zero; a1 <= ed.dol; a1++) { a1->offset &= ~LINE_GLOBAL; if (a1 >= ed.addr1 && a1 <= ed.addr2 && execute(a1, 0) == sense) a1->offset |= LINE_GLOBAL; } /* special case: g/.../d (avoid n^2 algorithm) */ if (!query && s[0] == 'd' && s[1] == '\n' && !s[2]) gdelete(); else { for (a1 = ed.zero; a1 <= ed.dol; a1++) { if (a1->offset & LINE_GLOBAL) { a1->offset &= ~LINE_GLOBAL; ed.dot = a1; if (query) { putrec(lineget(a1->offset)); if ((c = getchr()) == EOF) break; else if (c == '\n') continue; else if (c == '&') { newline(); if (!*(ed.global = sfstrbase(ed.buffer.query))) error(2, "no saved command"); } else { ed.peekc = c; ed.global = getrec(ed.buffer.query, '\n', REC_TERMINATE); } } else ed.global = s; commands(); a1 = ed.zero; } } } }
void global(int k) { Rune *gp, globuf[GBSIZE]; int c, *a1; if(globp) error(Q); setwide(); squeeze(dol > zero); c = getchr(); if(c == '\n') error(Q); compile(c); gp = globuf; while((c=getchr()) != '\n') { if(c == EOF) error(Q); if(c == '\\') { c = getchr(); if(c != '\n') *gp++ = '\\'; } *gp++ = c; if(gp >= &globuf[GBSIZE-2]) error(Q); } if(gp == globuf) *gp++ = 'p'; *gp++ = '\n'; *gp = 0; for(a1=zero; a1<=dol; a1++) { *a1 &= ~01; if(a1 >= addr1 && a1 <= addr2 && match(a1) == k) *a1 |= 01; } /* * Special case: g/.../d (avoid n^2 algorithm) */ if(globuf[0] == 'd' && globuf[1] == '\n' && globuf[2] == 0) { gdelete(); return; } for(a1=zero; a1<=dol; a1++) { if(*a1 & 01) { *a1 &= ~01; dot = a1; globp = globuf; commands(); a1 = zero; } } }