/* ARGSUSED */ int replstr(int f, int n) { char news[NPAT]; int s, plen, rcnt = 0; char *r; if ((s = readpattern("Replace string")) != TRUE) return s; r = eread("Replace string %s with: ", news, NPAT, EFNUL | EFNEW | EFCR, pat); if (r == NULL) return (ABORT); plen = strlen(pat); while (forwsrch() == TRUE) { update(); if (lreplace((RSIZE)plen, news) == FALSE) return (FALSE); rcnt++; } curwp->w_rflag |= WFFULL; update(); if (rcnt == 1) ewprintf("Replaced 1 occurrence"); else ewprintf("Replaced %d occurrences", rcnt); return (TRUE); }
static int empty( gdcm::Tag const &t, gdcm::DataSet &ds ) { return lreplace(t, "", 0, ds); }
static int replaceTag( gdcm::Tag const &t, const char *value, gdcm::DataSet &ds ) { gdcm::VL::Type len = (value == NULL) ? 0 : (gdcm::VL::Type)std::strlen( value ); return lreplace( t, value, len, ds ); }
/* ARGSUSED */ int queryrepl(int f, int n) { int s; int rcnt = 0; /* replacements made so far */ int plen; /* length of found string */ char news[NPAT], *rep; /* replacement string */ #ifndef NO_MACRO if (macrodef) { ewprintf("Can't query replace in macro"); return (FALSE); } #endif /* !NO_MACRO */ if ((s = readpattern("Query replace")) != TRUE) return (s); if ((rep = eread("Query replace %s with: ", news, NPAT, EFNUL | EFNEW | EFCR, pat)) == NULL) return (ABORT); else if (rep[0] == '\0') news[0] = '\0'; ewprintf("Query replacing %s with %s:", pat, news); plen = strlen(pat); /* * Search forward repeatedly, checking each time whether to insert * or not. The "!" case makes the check always true, so it gets put * into a tighter loop for efficiency. */ while (forwsrch() == TRUE) { retry: update(); switch (getkey(FALSE)) { case 'y': case ' ': if (lreplace((RSIZE)plen, news) == FALSE) return (FALSE); rcnt++; break; case '.': if (lreplace((RSIZE)plen, news) == FALSE) return (FALSE); rcnt++; goto stopsearch; /* ^G, CR or ESC */ case CCHR('G'): (void)ctrlg(FFRAND, 0); goto stopsearch; case CCHR('['): case CCHR('M'): goto stopsearch; case '!': do { if (lreplace((RSIZE)plen, news) == FALSE) return (FALSE); rcnt++; } while (forwsrch() == TRUE); goto stopsearch; case 'n': case CCHR('H'): /* To not replace */ case CCHR('?'): break; default: ewprintf("y/n or <SP>/<DEL>: replace/don't, [.] repl-end, [!] repl-rest, <CR>/<ESC> quit"); goto retry; } } stopsearch: curwp->w_rflag |= WFFULL; update(); if (rcnt == 1) ewprintf("Replaced 1 occurrence"); else ewprintf("Replaced %d occurrences", rcnt); return (TRUE); }
/* * Routine re_doreplace calls lreplace to make replacements needed by * re_query replace. Its reason for existence is to deal with \1, \2. etc. * plen: length to remove * st: replacement string */ static int re_doreplace(RSIZE plen, char *st) { int j, k, s, more, num, state; struct line *clp; char repstr[REPLEN]; clp = curwp->w_dotp; more = TRUE; j = 0; state = 0; num = 0; /* The following FSA parses the replacement string */ while (more) { switch (state) { case 0: if (*st == '\\') { st++; state = 1; } else if (*st == '\0') more = FALSE; else { repstr[j] = *st; j++; if (j >= REPLEN) return (FALSE); st++; } break; case 1: if (*st >= '0' && *st <= '9') { num = *st - '0'; st++; state = 2; } else if (*st == '\0') more = FALSE; else { repstr[j] = *st; j++; if (j >= REPLEN) return (FALSE); st++; state = 0; } break; case 2: if (*st >= '0' && *st <= '9') { num = 10 * num + *st - '0'; st++; } else { if (num >= RE_NMATCH) return (FALSE); k = regex_match[num].rm_eo - regex_match[num].rm_so; if (j + k >= REPLEN) return (FALSE); bcopy(&(clp->l_text[regex_match[num].rm_so]), &repstr[j], k); j += k; if (*st == '\0') more = FALSE; if (*st == '\\') { st++; state = 1; } else { repstr[j] = *st; j++; if (j >= REPLEN) return (FALSE); st++; state = 0; } } break; } /* switch (state) */ } /* while (more) */ repstr[j] = '\0'; s = lreplace(plen, repstr); return (s); }