/* replace_buffer - search the buffer for a string, then replace it with another string. */ unsigned long replace_buffer (unsigned long current_line, unsigned long line1, unsigned long line2, int verify, char *s) { unsigned long line; STRING_T *ds, *ds1, *dc; int q = 0; char *yn; size_t origpos; while (isspace ((unsigned char) *s)) s++; if (*s == '\'' || *s == '\"') q = *s++; else q = ','; ds = DScreate (); DSassign (ds, translate_string (s, q), 0, NPOS); /* pick off second string */ while (*s != q && *s) s += (*s == '\\' ? 2 : 1); while (*s != ',') s++; s++; while (isspace ((unsigned char) *s)) s++; if (*s == '\'' || *s == '\"') q = *s++; else q = 0; ds1 = DScreate (); DSassign (ds1, translate_string (s, q), 0, NPOS); if (DSlength (ds) != 0 && DScompare (ds, ds1, 0, NPOS) != 0) for (line = line1; line <= line2; line++) { origpos = 0; while ((origpos = DSfind (DAS_get_at (buffer, (size_t) line), DScstr (ds), origpos, DSlength (ds))) != NPOS) { dc = DScreate (); DSassign (dc, DAS_get_at (buffer, line), 0, NPOS); DSreplace (dc, origpos, DSlength (ds), ds1, 0, NPOS); printf (G00012, line + 1, DScstr (dc)); if (verify) yn = read_line (G00002); if (!verify || (*yn == 0 || strchr (YES, *yn) != 0)) { current_line = line + 1; origpos += DSlength (ds1); DAS_put_at (buffer, line, dc); } else origpos++; DSdestroy (dc); } } DSdestroy (ds); DSdestroy (ds1); return current_line; }
static STRING_T * get_name_from_nlspath (STRING_T * r, char *name) { char *nlspath = 0; char *lang = 0; size_t pos, oldpos, iter; STRING_T *language = 0, *territory = 0, *codeset = 0, *s = 0; nlspath = getenv ("NLSPATH"); lang = get_language (); DSresize (r, 0, 0); if (nlspath == 0) { DSassigncstr (r, name, NPOS); return r; } DSassigncstr (r, nlspath, NPOS); /* set language, territory, codeset values */ if (*lang != 0) { s = DScreate (); language = DScreate (); territory = DScreate (); codeset = DScreate (); DSassigncstr (s, lang, NPOS); for (iter = 3, oldpos = pos = 0; iter != 0; oldpos = pos, --iter, pos = DSfind (s, "@._", ++pos, iter)) { /* assign values */ if (oldpos == 0) DSassign (language, s, 0, pos); else { switch (DSget_at (s, oldpos)) { case '_': /* territory */ DSassign (territory, s, oldpos + 1, pos - oldpos - 1); break; case '.': /* codeset */ DSassign (codeset, s, oldpos + 1, pos - oldpos - 1); break; default: /*modifier? */ break; } if (pos == NPOS) break; } } } for (pos = 0; (pos = DSfind (r, "%", pos, 1)) != NPOS; ++pos) { switch (DSget_at (r, pos + 1)) { case 'N': /* name */ DSreplacecstr (r, pos, 2, name, NPOS); pos += strlen (name) - 1; break; case 'L': /* language */ DSreplacecstr (r, pos, 2, lang, NPOS); pos += strlen (lang) - 1; break; case 'l': /* language element from %L */ DSreplace (r, pos, 2, language, 0, NPOS); pos += DSlength (language) - 1; break; case 't': /* territory element from %L */ if (territory != 0) { DSreplace (r, pos, 2, territory, 0, NPOS); pos += DSlength (territory) - 1; } break; case 'c': /* codeset element from %L */ if (codeset != 0) { DSreplace (r, pos, 2, codeset, 0, NPOS); pos += DSlength (codeset) - 1; } break; case '%': /* percent sign */ DSremove (r, pos, 1); break; } } if (s != 0) DSdestroy (s); if (language != 0) DSdestroy (language); if (territory != 0) DSdestroy (territory); if (codeset != 0) DSdestroy (codeset); return r; }