Deleted Added
full compact
compile.c (86193) compile.c (87766)
1/*-
2 * Copyright (c) 1992 Diomidis Spinellis.
3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Diomidis Spinellis of Imperial College, University of London.
8 *

--- 21 unchanged lines hidden (view full) ---

30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
1/*-
2 * Copyright (c) 1992 Diomidis Spinellis.
3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Diomidis Spinellis of Imperial College, University of London.
8 *

--- 21 unchanged lines hidden (view full) ---

30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: head/usr.bin/sed/compile.c 87766 2001-12-12 23:20:16Z markm $");
40
38#ifndef lint
41#ifndef lint
39#if 0
40static char sccsid[] = "@(#)compile.c 8.1 (Berkeley) 6/6/93";
42static const char sccsid[] = "@(#)compile.c 8.1 (Berkeley) 6/6/93";
41#endif
43#endif
42static const char rcsid[] =
43 "$FreeBSD: head/usr.bin/sed/compile.c 86193 2001-11-08 16:47:05Z mikeh $";
44#endif /* not lint */
45
46#include <sys/types.h>
47#include <sys/stat.h>
48
49#include <ctype.h>
50#include <err.h>
51#include <fcntl.h>
52#include <limits.h>

--- 19 unchanged lines hidden (view full) ---

72static char *compile_delimited __P((char *, char *));
73static char *compile_flags __P((char *, struct s_subst *));
74static char *compile_re __P((char *, regex_t **));
75static char *compile_subst __P((char *, struct s_subst *));
76static char *compile_text __P((void));
77static char *compile_tr __P((char *, char **));
78static struct s_command
79 **compile_stream __P((struct s_command **));
44
45#include <sys/types.h>
46#include <sys/stat.h>
47
48#include <ctype.h>
49#include <err.h>
50#include <fcntl.h>
51#include <limits.h>

--- 19 unchanged lines hidden (view full) ---

71static char *compile_delimited __P((char *, char *));
72static char *compile_flags __P((char *, struct s_subst *));
73static char *compile_re __P((char *, regex_t **));
74static char *compile_subst __P((char *, struct s_subst *));
75static char *compile_text __P((void));
76static char *compile_tr __P((char *, char **));
77static struct s_command
78 **compile_stream __P((struct s_command **));
80static char *duptoeol __P((char *, char *));
79static char *duptoeol __P((char *, const char *));
81static void enterlabel __P((struct s_command *));
82static struct s_command
83 *findlabel __P((char *));
84static void fixuplabel __P((struct s_command *, struct s_command *));
85static void uselabel __P((void));
86
87/*
88 * Command specification. This is used to drive the command parser.

--- 63 unchanged lines hidden (view full) ---

152 while (*p && isspace((unsigned char)*p)) \
153 p++; \
154 } while (0)
155
156static struct s_command **
157compile_stream(link)
158 struct s_command **link;
159{
80static void enterlabel __P((struct s_command *));
81static struct s_command
82 *findlabel __P((char *));
83static void fixuplabel __P((struct s_command *, struct s_command *));
84static void uselabel __P((void));
85
86/*
87 * Command specification. This is used to drive the command parser.

--- 63 unchanged lines hidden (view full) ---

151 while (*p && isspace((unsigned char)*p)) \
152 p++; \
153 } while (0)
154
155static struct s_command **
156compile_stream(link)
157 struct s_command **link;
158{
160 register char *p;
159 char *p;
161 static char lbuf[_POSIX2_LINE_MAX + 1]; /* To save stack */
162 struct s_command *cmd, *cmd2, *stack;
163 struct s_format *fp;
164 int naddr; /* Number of addresses */
165
166 stack = 0;
167 for (;;) {
168 if ((p = cu_fgets(lbuf, sizeof(lbuf), NULL)) == NULL) {

--- 291 unchanged lines hidden (view full) ---

460 * expressions.
461 */
462static char *
463compile_subst(p, s)
464 char *p;
465 struct s_subst *s;
466{
467 static char lbuf[_POSIX2_LINE_MAX + 1];
160 static char lbuf[_POSIX2_LINE_MAX + 1]; /* To save stack */
161 struct s_command *cmd, *cmd2, *stack;
162 struct s_format *fp;
163 int naddr; /* Number of addresses */
164
165 stack = 0;
166 for (;;) {
167 if ((p = cu_fgets(lbuf, sizeof(lbuf), NULL)) == NULL) {

--- 291 unchanged lines hidden (view full) ---

459 * expressions.
460 */
461static char *
462compile_subst(p, s)
463 char *p;
464 struct s_subst *s;
465{
466 static char lbuf[_POSIX2_LINE_MAX + 1];
468 int asize, ref, size;
467 int asize, size;
468 u_char ref;
469 char c, *text, *op, *sp;
470 int more = 0;
471
472 c = *p++; /* Terminator character */
473 if (c == '\0')
474 return (NULL);
475
476 s->maxbref = 0;

--- 240 unchanged lines hidden (view full) ---

717}
718
719/*
720 * duptoeol --
721 * Return a copy of all the characters up to \n or \0.
722 */
723static char *
724duptoeol(s, ctype)
469 char c, *text, *op, *sp;
470 int more = 0;
471
472 c = *p++; /* Terminator character */
473 if (c == '\0')
474 return (NULL);
475
476 s->maxbref = 0;

--- 240 unchanged lines hidden (view full) ---

717}
718
719/*
720 * duptoeol --
721 * Return a copy of all the characters up to \n or \0.
722 */
723static char *
724duptoeol(s, ctype)
725 register char *s;
726 char *ctype;
725 char *s;
726 const char *ctype;
727{
728 size_t len;
729 int ws;
730 char *p, *start;
731
732 ws = 0;
733 for (start = s; *s != '\0' && *s != '\n'; ++s)
734 ws = isspace((unsigned char)*s);

--- 44 unchanged lines hidden (view full) ---

779
780/*
781 * Associate the given command label for later lookup.
782 */
783static void
784enterlabel(cp)
785 struct s_command *cp;
786{
727{
728 size_t len;
729 int ws;
730 char *p, *start;
731
732 ws = 0;
733 for (start = s; *s != '\0' && *s != '\n'; ++s)
734 ws = isspace((unsigned char)*s);

--- 44 unchanged lines hidden (view full) ---

779
780/*
781 * Associate the given command label for later lookup.
782 */
783static void
784enterlabel(cp)
785 struct s_command *cp;
786{
787 register struct labhash **lhp, *lh;
788 register u_char *p;
789 register u_int h, c;
787 struct labhash **lhp, *lh;
788 u_char *p;
789 u_int h, c;
790
791 for (h = 0, p = (u_char *)cp->t; (c = *p) != 0; p++)
792 h = (h << 5) + h + c;
793 lhp = &labels[h & LHMASK];
794 for (lh = *lhp; lh != NULL; lh = lh->lh_next)
795 if (lh->lh_hash == h && strcmp(cp->t, lh->lh_cmd->t) == 0)
796 errx(1, "%lu: %s: duplicate label '%s'", linenum, fname, cp->t);
797 if ((lh = malloc(sizeof *lh)) == NULL)

--- 8 unchanged lines hidden (view full) ---

806/*
807 * Find the label contained in the command l in the command linked
808 * list cp. L is excluded from the search. Return NULL if not found.
809 */
810static struct s_command *
811findlabel(name)
812 char *name;
813{
790
791 for (h = 0, p = (u_char *)cp->t; (c = *p) != 0; p++)
792 h = (h << 5) + h + c;
793 lhp = &labels[h & LHMASK];
794 for (lh = *lhp; lh != NULL; lh = lh->lh_next)
795 if (lh->lh_hash == h && strcmp(cp->t, lh->lh_cmd->t) == 0)
796 errx(1, "%lu: %s: duplicate label '%s'", linenum, fname, cp->t);
797 if ((lh = malloc(sizeof *lh)) == NULL)

--- 8 unchanged lines hidden (view full) ---

806/*
807 * Find the label contained in the command l in the command linked
808 * list cp. L is excluded from the search. Return NULL if not found.
809 */
810static struct s_command *
811findlabel(name)
812 char *name;
813{
814 register struct labhash *lh;
815 register u_char *p;
816 register u_int h, c;
814 struct labhash *lh;
815 u_char *p;
816 u_int h, c;
817
818 for (h = 0, p = (u_char *)name; (c = *p) != 0; p++)
819 h = (h << 5) + h + c;
820 for (lh = labels[h & LHMASK]; lh != NULL; lh = lh->lh_next) {
821 if (lh->lh_hash == h && strcmp(name, lh->lh_cmd->t) == 0) {
822 lh->lh_ref = 1;
823 return (lh->lh_cmd);
824 }
825 }
826 return (NULL);
827}
828
829/*
830 * Warn about any unused labels. As a side effect, release the label hash
831 * table space.
832 */
833static void
834uselabel()
835{
817
818 for (h = 0, p = (u_char *)name; (c = *p) != 0; p++)
819 h = (h << 5) + h + c;
820 for (lh = labels[h & LHMASK]; lh != NULL; lh = lh->lh_next) {
821 if (lh->lh_hash == h && strcmp(name, lh->lh_cmd->t) == 0) {
822 lh->lh_ref = 1;
823 return (lh->lh_cmd);
824 }
825 }
826 return (NULL);
827}
828
829/*
830 * Warn about any unused labels. As a side effect, release the label hash
831 * table space.
832 */
833static void
834uselabel()
835{
836 register struct labhash *lh, *next;
837 register int i;
836 struct labhash *lh, *next;
837 int i;
838
839 for (i = 0; i < LHSZ; i++) {
840 for (lh = labels[i]; lh != NULL; lh = next) {
841 next = lh->lh_next;
842 if (!lh->lh_ref)
843 warnx("%lu: %s: unused label '%s'",
844 linenum, fname, lh->lh_cmd->t);
845 free(lh);
846 }
847 }
848}
838
839 for (i = 0; i < LHSZ; i++) {
840 for (lh = labels[i]; lh != NULL; lh = next) {
841 next = lh->lh_next;
842 if (!lh->lh_ref)
843 warnx("%lu: %s: unused label '%s'",
844 linenum, fname, lh->lh_cmd->t);
845 free(lh);
846 }
847 }
848}