don't access entries multiple times; from Diomidis
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 31 Aug 1992 03:07:10 +0000 (19:07 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 31 Aug 1992 03:07:10 +0000 (19:07 -0800)
SCCS-vsn: usr.bin/sed/compile.c 5.5
SCCS-vsn: usr.bin/sed/extern.h 5.5
SCCS-vsn: usr.bin/sed/main.c 5.6
SCCS-vsn: usr.bin/sed/process.c 5.8

usr/src/usr.bin/sed/compile.c
usr/src/usr.bin/sed/extern.h
usr/src/usr.bin/sed/main.c
usr/src/usr.bin/sed/process.c

index 3e274c6..9f513ef 100644 (file)
@@ -10,7 +10,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)compile.c  5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)compile.c  5.5 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -40,7 +40,8 @@ static struct s_command
 static char     *duptoeol __P((char *));
 static struct s_command
                 *findlabel __P((struct s_command *, struct s_command *));
 static char     *duptoeol __P((char *));
 static struct s_command
                 *findlabel __P((struct s_command *, struct s_command *));
-static void      fixuplabel __P((struct s_command *, struct s_command *));
+static void      fixuplabel __P((struct s_command *, struct s_command *,
+                       struct s_command *));
 
 /*
  * Command specification.  This is used to drive the command parser.
 
 /*
  * Command specification.  This is used to drive the command parser.
@@ -93,7 +94,7 @@ void
 compile()
 {
        *compile_stream(NULL, &prog, NULL) = NULL;
 compile()
 {
        *compile_stream(NULL, &prog, NULL) = NULL;
-       fixuplabel(prog, prog);
+       fixuplabel(prog, prog, NULL);
        appends = xmalloc(sizeof(struct s_appends) * appendnum);
        match = xmalloc((maxnsub + 1) * sizeof(regmatch_t));
 }
        appends = xmalloc(sizeof(struct s_appends) * appendnum);
        match = xmalloc((maxnsub + 1) * sizeof(regmatch_t));
 }
@@ -645,12 +646,12 @@ findlabel(l, cp)
  * TODO: Remove } nodes
  */
 static void
  * TODO: Remove } nodes
  */
 static void
-fixuplabel(root, cp)
-       struct s_command *root, *cp;
+fixuplabel(root, cp, end)
+       struct s_command *root, *cp, *end;
 {
        struct s_command *cp2;
 
 {
        struct s_command *cp2;
 
-       for (; cp; cp = cp->next)
+       for (; cp != end; cp = cp->next)
                switch (cp->code) {
                case ':':
                        if (findlabel(cp, root))
                switch (cp->code) {
                case ':':
                        if (findlabel(cp, root))
@@ -672,7 +673,7 @@ fixuplabel(root, cp)
                        cp->u.c = cp2;
                        break;
                case '{':
                        cp->u.c = cp2;
                        break;
                case '{':
-                       fixuplabel(root, cp->u.c);
+                       fixuplabel(root, cp->u.c, cp->next);
                        break;
                }
 }
                        break;
                }
 }
index 82a5eb3..cc058f8 100644 (file)
@@ -8,7 +8,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)extern.h    5.4 (Berkeley) %G%
+ *     @(#)extern.h    5.5 (Berkeley) %G%
  */
 
 extern struct s_command *prog;
  */
 
 extern struct s_command *prog;
@@ -29,5 +29,5 @@ void   process __P((void));
 char   *strregerror __P((int, regex_t *));
 void   *xmalloc __P((u_int));
 void   *xrealloc __P((void *, u_int));
 char   *strregerror __P((int, regex_t *));
 void   *xmalloc __P((u_int));
 void   *xrealloc __P((void *, u_int));
-void    cfclose __P((struct s_command *));
+void    cfclose __P((struct s_command *, struct s_command *));
 void    cspace __P((SPACE *, char *, size_t, enum e_spflag));
 void    cspace __P((SPACE *, char *, size_t, enum e_spflag));
index 63543ba..bae5d61 100644 (file)
@@ -16,7 +16,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     5.6 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -124,7 +124,7 @@ main(argc, argv)
        else
                add_file(NULL);
        process();
        else
                add_file(NULL);
        process();
-       cfclose(prog);
+       cfclose(prog, NULL);
        if (fclose(stdout))
                err(FATAL, "stdout: %s", strerror(errno));
        exit (0);
        if (fclose(stdout))
                err(FATAL, "stdout: %s", strerror(errno));
        exit (0);
index 1433fc4..6505e69 100644 (file)
@@ -10,7 +10,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)process.c  5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)process.c  5.8 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -560,11 +560,11 @@ cspace(sp, p, len, spflag)
  * Close all cached opened files and report any errors
  */
 void
  * Close all cached opened files and report any errors
  */
 void
-cfclose(cp)
-       register struct s_command *cp;
+cfclose(cp, end)
+       register struct s_command *cp, *end;
 {
 
 {
 
-       for (; cp != NULL; cp = cp->next)
+       for (; cp != end; cp = cp->next)
                switch(cp->code) {
                case 's':
                        if (cp->u.s->wfd != -1 && close(cp->u.s->wfd))
                switch(cp->code) {
                case 's':
                        if (cp->u.s->wfd != -1 && close(cp->u.s->wfd))
@@ -578,7 +578,7 @@ cfclose(cp)
                        cp->u.fd = -1;
                        break;
                case '{':
                        cp->u.fd = -1;
                        break;
                case '{':
-                       cfclose(cp->u.c);
+                       cfclose(cp->u.c, cp->next);
                        break;
                }
 }
                        break;
                }
 }