svn commit: r269302 - head/usr.bin/sed
Jeremie Le Hen
jlh at FreeBSD.org
Wed Jul 30 14:46:40 UTC 2014
Author: jlh
Date: Wed Jul 30 14:46:39 2014
New Revision: 269302
URL: http://svnweb.freebsd.org/changeset/base/269302
Log:
Fix relative numerical addressing (addr,+N).
As a bonus the patch untangles a bit the logic and makes the code
easier to grasp.
PR: 192108
MFC after: 1 week
Modified:
head/usr.bin/sed/process.c
Modified: head/usr.bin/sed/process.c
==============================================================================
--- head/usr.bin/sed/process.c Wed Jul 30 12:39:49 2014 (r269301)
+++ head/usr.bin/sed/process.c Wed Jul 30 14:46:39 2014 (r269302)
@@ -288,24 +288,32 @@ applies(struct s_command *cp)
r = 1;
else if (cp->a2)
if (cp->startline > 0) {
- if (MATCH(cp->a2)) {
- cp->startline = 0;
- lastaddr = 1;
- r = 1;
- } else if (linenum - cp->startline <= cp->a2->u.l)
- r = 1;
- else if ((cp->a2->type == AT_LINE &&
- linenum > cp->a2->u.l) ||
- (cp->a2->type == AT_RELLINE &&
- linenum - cp->startline > cp->a2->u.l)) {
- /*
- * We missed the 2nd address due to a branch,
- * so just close the range and return false.
- */
- cp->startline = 0;
- r = 0;
- } else
- r = 1;
+ switch (cp->a2->type) {
+ case AT_RELLINE:
+ if (linenum - cp->startline <= cp->a2->u.l)
+ r = 1;
+ else {
+ cp->startline = 0;
+ r = 0;
+ }
+ break;
+ default:
+ if (MATCH(cp->a2)) {
+ cp->startline = 0;
+ lastaddr = 1;
+ r = 1;
+ } else if (cp->a2->type == AT_LINE &&
+ linenum > cp->a2->u.l) {
+ /*
+ * We missed the 2nd address due to a
+ * branch, so just close the range and
+ * return false.
+ */
+ cp->startline = 0;
+ r = 0;
+ } else
+ r = 1;
+ }
} else if (MATCH(cp->a1)) {
/*
* If the second address is a number less than or
More information about the svn-src-all
mailing list