Lines Matching refs:sp

53 ex_s(SCR *sp, EXCMD *cmdp)
80 subagain: return (ex_subagain(sp, cmdp));
84 return (s(sp, cmdp, p, &sp->subre_c, SUB_MUSTSETR));
91 sp->c_suffix = sp->g_suffix = 0;
138 if (sp->re == NULL) {
139 ex_emsg(sp, NULL, EXM_NOPREVRE);
144 if (!F_ISSET(sp, SC_RE_SEARCH) &&
145 re_compile(sp, sp->re, sp->re_len,
146 NULL, NULL, &sp->re_c, SEARCH_CSEARCH | SEARCH_MSG))
157 if (re_compile(sp, ptrn, t - ptrn, &sp->re,
158 &sp->re_len, &sp->re_c, SEARCH_CSEARCH | SEARCH_MSG))
160 if (re_compile(sp, ptrn, t - ptrn, &sp->subre,
161 &sp->subre_len, &sp->subre_c, SEARCH_CSUBST | SEARCH_MSG))
165 sp->searchdir = FORWARD;
167 re = &sp->re_c;
196 if (sp->repl != NULL)
197 free(sp->repl);
198 sp->repl = NULL;
199 sp->repl_len = 0;
206 len += sp->repl_len;
207 GET_SPACE_RETW(sp, bp, blen, len);
222 if (!O_ISSET(sp, O_MAGIC))
225 } else if (p[0] == L('~') && O_ISSET(sp, O_MAGIC)) {
227 MEMCPYW(t, sp->repl, sp->repl_len);
228 t += sp->repl_len;
229 len += sp->repl_len;
235 if ((sp->repl_len = len) != 0) {
236 if (sp->repl != NULL)
237 free(sp->repl);
238 if ((sp->repl = malloc(len * sizeof(CHAR_T))) == NULL) {
239 msgq(sp, M_SYSERR, NULL);
240 FREE_SPACEW(sp, bp, blen);
243 MEMCPYW(sp->repl, bp, len);
245 FREE_SPACEW(sp, bp, blen);
247 return (s(sp, cmdp, p, re, flags));
259 ex_subagain(SCR *sp, EXCMD *cmdp)
261 if (sp->subre == NULL) {
262 ex_emsg(sp, NULL, EXM_NOPREVRE);
265 if (!F_ISSET(sp, SC_RE_SUBST) &&
266 re_compile(sp, sp->subre, sp->subre_len,
267 NULL, NULL, &sp->subre_c, SEARCH_CSUBST | SEARCH_MSG))
269 return (s(sp,
270 cmdp, cmdp->argc ? cmdp->argv[0]->bp : NULL, &sp->subre_c, 0));
282 ex_subtilde(SCR *sp, EXCMD *cmdp)
284 if (sp->re == NULL) {
285 ex_emsg(sp, NULL, EXM_NOPREVRE);
288 if (!F_ISSET(sp, SC_RE_SEARCH) && re_compile(sp, sp->re,
289 sp->re_len, NULL, NULL, &sp->re_c, SEARCH_CSEARCH | SEARCH_MSG))
291 return (s(sp,
292 cmdp, cmdp->argc ? cmdp->argv[0]->bp : NULL, &sp->re_c, 0));
308 #define NEEDNEWLINE(sp) { \
309 if (sp->newl_len == sp->newl_cnt) { \
310 sp->newl_len += 25; \
311 REALLOC(sp, sp->newl, size_t *, \
312 sp->newl_len * sizeof(size_t)); \
313 if (sp->newl == NULL) { \
314 sp->newl_len = 0; \
320 #define BUILD(sp, l, len) { \
323 REALLOC(sp, lb, CHAR_T *, lblen * sizeof(CHAR_T)); \
333 #define NEEDSP(sp, len, pnt) { \
336 REALLOC(sp, lb, CHAR_T *, lblen * sizeof(CHAR_T)); \
346 s(SCR *sp, EXCMD *cmdp, CHAR_T *st, regex_t *re, u_int flags)
362 NEEDFILE(sp, cmdp);
364 slno = sp->lno;
365 scno = sp->cno;
375 if (!O_ISSET(sp, O_EDCOMPATIBLE))
376 sp->c_suffix = sp->g_suffix = 0;
413 nret = nget_uslong(sp, &ul, st, &st, 10);
419 msgq(sp, M_ERR, "153|Count overflow");
421 msgq(sp, M_ERR, "154|Count underflow");
423 msgq(sp, M_SYSERR, NULL);
432 if (!db_exist(sp, cmdp->addr2.lno) &&
433 db_last(sp, &cmdp->addr2.lno))
440 sp->c_suffix = !sp->c_suffix;
443 if (F_ISSET(sp, SC_EX)) {
449 sp->g_suffix = !sp->g_suffix;
459 msgq(sp, M_ERR,
463 if (!F_ISSET(sp, SC_RE_SEARCH)) {
464 ex_emsg(sp, NULL, EXM_NOPREVRE);
468 re = &sp->re_c;
475 usage: ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
479 noargs: if (F_ISSET(sp, SC_VI) && sp->c_suffix && (lflag || nflag || pflag)) {
480 msgq(sp, M_ERR,
501 if (INTERRUPTED(sp))
505 if (db_get(sp, lno, DBG_FATAL, &st, &llen))
512 if (sp->c_suffix) {
514 GET_SPACE_RETW(sp, bp, blen, llen);
516 ADD_SPACE_RETW(sp, bp, blen, llen);
566 re_error(sp, eval, re);
598 BUILD(sp, st + offset, 1)
605 if (sp->c_suffix) {
620 if (F_ISSET(sp, SC_VI)) {
634 sp->lno = from.lno;
635 sp->cno = from.cno;
636 if (vs_refresh(sp, 1))
639 vs_update(sp, msg_cat(sp,
642 if (v_event_get(sp, &ev, 0, 0))
652 v_event_err(sp, &ev);
656 if (ex_print(sp, cmdp, &from, &to, 0) ||
657 ex_scprint(sp, &from, &to))
659 if (ex_txt(sp, &tiq, 0, TXT_CR))
670 BUILD(sp, st + offset, match[0].rm_eo);
675 F_SET(sp->gp, G_INTERRUPTED);
689 sp->lno = lno;
690 sp->cno = match[0].rm_so;
693 BUILD(sp, st + offset, match[0].rm_so);
697 if (re_sub(sp, st + offset, &lb, &lbclen, &lblen, match))
715 if (didsub && sp->c_suffix && sp->g_suffix) {
724 BUILD(sp, st + offset, len)
731 if (sp->newl_cnt) {
733 cnt < sp->newl_cnt; ++cnt, ++lno, ++elno) {
734 if (db_insert(sp, lno,
735 lb + last, sp->newl[cnt] - last))
737 last = sp->newl[cnt] + 1;
738 ++sp->rptlines[L_ADDED];
742 sp->newl_cnt = 0;
746 if (db_set(sp, lno, lb + last, lbclen))
748 if (db_get(sp, lno, DBG_FATAL, &st, &llen))
750 ADD_SPACE_RETW(sp, bp, blen, llen)
757 BUILD(sp, st, offset);
780 if (sp->g_suffix && do_eol_match) {
793 BUILD(sp, st + offset, len)
797 if (sp->newl_cnt) {
799 cnt < sp->newl_cnt; ++cnt, ++lno, ++elno) {
800 if (db_insert(sp,
801 lno, lb + last, sp->newl[cnt] - last))
803 last = sp->newl[cnt] + 1;
804 ++sp->rptlines[L_ADDED];
807 sp->newl_cnt = 0;
811 if (db_set(sp, lno, lb + last, lbclen))
815 if (sp->rptlchange != lno) {
816 sp->rptlchange = lno;
817 ++sp->rptlines[L_CHANGED];
830 (void)ex_print(sp, cmdp, &from, &to, E_C_LIST);
832 (void)ex_print(sp, cmdp, &from, &to, E_C_HASH);
834 (void)ex_print(sp, cmdp, &from, &to, E_C_PRINT);
854 if (!sp->c_suffix && (sp->lno != slno || sp->cno != scno)) {
855 sp->cno = 0;
856 (void)nonblank(sp, sp->lno, &sp->cno);
865 if (!F_ISSET(sp, SC_EX_GLOBAL)) {
866 msgq(sp, M_ERR, "157|No match found");
877 FREE_SPACEW(sp, bp, blen);
891 re_compile(SCR *sp, CHAR_T *ptrn, size_t plen, CHAR_T **ptrnp, size_t *lenp, regex_t *rep, u_int flags)
906 if (O_ISSET(sp, O_EXTENDED))
908 if (O_ISSET(sp, O_IGNORECASE))
910 if (O_ISSET(sp, O_ICLOWER))
922 if (LF_ISSET(SEARCH_CSEARCH) && F_ISSET(sp, SC_RE_SEARCH)) {
923 regfree(&sp->re_c);
924 F_CLR(sp, SC_RE_SEARCH);
926 if (LF_ISSET(SEARCH_CSUBST) && F_ISSET(sp, SC_RE_SUBST)) {
927 regfree(&sp->subre_c);
928 F_CLR(sp, SC_RE_SUBST);
939 if (re_cscope_conv(sp, &ptrn, &plen, &replaced))
949 if (re_tag_conv(sp, &ptrn, &plen, &replaced))
952 if (re_conv(sp, &ptrn, &plen, &replaced))
970 MALLOC(sp, *ptrnp, CHAR_T *, (plen + 1) * sizeof(CHAR_T));
978 FREE_SPACEW(sp, ptrn, 0);
993 re_error(sp, rval, rep);
998 F_SET(sp, SC_RE_SEARCH);
1000 F_SET(sp, SC_RE_SUBST);
1028 re_conv(SCR *sp, CHAR_T **ptrnp, size_t *plenp, int *replacedp)
1056 if (!O_ISSET(sp, O_MAGIC)) {
1058 needlen += sp->repl_len;
1064 if (!O_ISSET(sp, O_MAGIC)) {
1076 if (O_ISSET(sp, O_MAGIC)) {
1078 needlen += sp->repl_len;
1084 if (!O_ISSET(sp, O_MAGIC)) {
1101 GET_SPACE_RETW(sp, bp, blen, needlen);
1120 if (O_ISSET(sp, O_MAGIC))
1124 sp->repl, sp->repl_len);
1125 t += sp->repl_len;
1131 if (O_ISSET(sp, O_MAGIC))
1143 if (O_ISSET(sp, O_MAGIC)) {
1144 MEMCPYW(t, sp->repl, sp->repl_len);
1145 t += sp->repl_len;
1152 if (!O_ISSET(sp, O_MAGIC))
1172 re_tag_conv(SCR *sp, CHAR_T **ptrnp, size_t *plenp, int *replacedp)
1182 GET_SPACE_RETW(sp, bp, blen, len * 2);
1237 re_cscope_conv(SCR *sp, CHAR_T **ptrnp, size_t *plenp, int *replacedp)
1251 CHAR2INT(sp, CSCOPE_RE_SPACE, CSCOPE_LEN, wp, wlen);
1264 GET_SPACE_RETW(sp, bp, blen, len);
1299 re_error(SCR *sp, int errcode, regex_t *preg)
1306 msgq(sp, M_SYSERR, NULL);
1309 msgq(sp, M_ERR, "RE error: %s", oe);
1319 re_sub(SCR *sp, CHAR_T *ip, CHAR_T **lbp, size_t *lbclenp, size_t *lblenp, regmatch_t *match)
1359 e_key_t __value = KEY_VAL(sp, __ch); \
1361 NEEDNEWLINE(sp); \
1362 sp->newl[sp->newl_cnt++] = lbclen; \
1383 NEEDSP(sp, 1, p); \
1388 for (rp = sp->repl, rpl = sp->repl_len, p = lb + lbclen; rpl--;) {
1391 if (O_ISSET(sp, O_MAGIC)) {
1403 if (!O_ISSET(sp, O_MAGIC)) {