Don't forget to clear out the hold space for each subsequent file

when in -i mode so that each file gets a clean context of its own.

Add a regression test for the bug.

Tested with:	regression tests
This commit is contained in:
Yaroslav Tykhiy 2007-06-12 12:05:24 +00:00
parent 7cd3f6159b
commit 26a5710c40
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=170608
4 changed files with 20 additions and 5 deletions

View File

@ -2,7 +2,7 @@
REGRESSION_START($1)
echo '1..20'
echo '1..21'
REGRESSION_TEST(`G', `sed G < regress.in')
REGRESSION_TEST(`P', `sed P < regress.in')
@ -61,6 +61,7 @@ REGRESSION_TEST_FREEFORM(`inplace1', `inplace_test 3,6d')
REGRESSION_TEST_FREEFORM(`inplace2', `inplace_test 8,30d')
REGRESSION_TEST_FREEFORM(`inplace3', `inplace_test 20,99d')
REGRESSION_TEST_FREEFORM(`inplace4', `inplace_test "{;{;8,30d;};}"')
REGRESSION_TEST_FREEFORM(`inplace5', `inplace_test "3x;6G"')
REGRESSION_TEST(`hanoi', `echo ":abcd: : :" | sed -f hanoi.sed')
REGRESSION_TEST(`math', `echo "4+7*3+2^7/3" | sed -f math.sed')

View File

@ -52,5 +52,5 @@ char *cu_fgets(char *, int, int *);
int mf_fgets(SPACE *, enum e_spflag);
int lastline(void);
void process(void);
void resetranges(void);
void resetstate(void);
char *strregerror(int, regex_t *);

View File

@ -390,7 +390,7 @@ mf_fgets(SPACE *sp, enum e_spflag spflag)
outfname = tmpfname;
if (!ispan) {
linenum = 0;
resetranges();
resetstate();
}
} else {
outfile = stdout;

View File

@ -234,6 +234,12 @@ process(void)
err(1, "%s", cp->t);
break;
case 'x':
/*
* If the hold space is null, make it empty
* but not null. Otherwise the pattern space
* will become null after the swap, which is
* an abnormal condition.
*/
if (hs == NULL)
cspace(&HS, "", 0, REPLACE);
tspace = PS;
@ -317,16 +323,24 @@ applies(struct s_command *cp)
}
/*
* Reset all inrange markers.
* Reset the sed processor to its initial state.
*/
void
resetranges(void)
resetstate(void)
{
struct s_command *cp;
/*
* Reset all inrange markers.
*/
for (cp = prog; cp; cp = cp->code == '{' ? cp->u.c : cp->next)
if (cp->a2)
cp->inrange = 0;
/*
* Clear out the hold space.
*/
cspace(&HS, "", 0, REPLACE);
}
/*