BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / pascal / pmerge / pmerge.c
index 4cef289..004288b 100644 (file)
@@ -1,9 +1,51 @@
-/* Copyright (c) 1979 Regents of the University of California */
+/*-
+ * Copyright (c) 1980 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1980 The Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
 
 
-static char sccsid[] = "@(#)pmerge.c 1.3 %G%";
+#ifndef lint
+static char sccsid[] = "@(#)pmerge.c   5.3 (Berkeley) 4/16/91";
+#endif /* not lint */
 
 #include <ctype.h>
 #include <stdio.h>
 
 #include <ctype.h>
 #include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
 #include <signal.h>
 
 #define PRGFILE 0
 #include <signal.h>
 
 #define PRGFILE 0
@@ -24,15 +66,13 @@ static char sccsid[] = "@(#)pmerge.c 1.3 %G%";
 FILE   *files[NUMFILES];
 char   *names[NUMFILES];
 FILE   *curfile;               /* current output file */
 FILE   *files[NUMFILES];
 char   *names[NUMFILES];
 FILE   *curfile;               /* current output file */
-FILE   *fopen();
 char   labelopen = FALSE, constopen = FALSE, typeopen = FALSE, varopen = FALSE;
 char   labelopen = FALSE, constopen = FALSE, typeopen = FALSE, varopen = FALSE;
-char   *mktemp();
-char   *malloc();
 
 /*
  * Remove temporary files if interrupted
  */
 
 /*
  * Remove temporary files if interrupted
  */
-onintr()
+void
+onintr(unused)
 {
        int i;
 
 {
        int i;
 
@@ -67,13 +107,16 @@ main(argc, argv)
 
        signal(SIGINT, onintr);
 
 
        signal(SIGINT, onintr);
 
-       curfile = files[PRGFILE] = fopen(names[PRGFILE] = mktemp(TMPNAME), "w");
-       files[LABELFILE] = fopen(names[LABELFILE] = mktemp(TMPNAME), "w");
-       files[CONSTFILE] = fopen(names[CONSTFILE] = mktemp(TMPNAME), "w");
-       files[TYPEFILE] = fopen(names[TYPEFILE] = mktemp(TMPNAME), "w");
-       files[VARFILE] = fopen(names[VARFILE] = mktemp(TMPNAME), "w");
-       files[RTNFILE] = fopen(names[RTNFILE] = mktemp(TMPNAME), "w");
-       files[BODYFILE] = fopen(names[BODYFILE] = mktemp(TMPNAME), "w");
+       curfile = files[PRGFILE] =
+               fopen(names[PRGFILE] = mktemp(strdup(TMPNAME)), "w");
+       files[LABELFILE] =
+               fopen(names[LABELFILE] = mktemp(strdup(TMPNAME)), "w");
+       files[CONSTFILE] =
+               fopen(names[CONSTFILE] = mktemp(strdup(TMPNAME)), "w");
+       files[TYPEFILE] = fopen(names[TYPEFILE] = mktemp(strdup(TMPNAME)), "w");
+       files[VARFILE] = fopen(names[VARFILE] = mktemp(strdup(TMPNAME)), "w");
+       files[RTNFILE] = fopen(names[RTNFILE] = mktemp(strdup(TMPNAME)), "w");
+       files[BODYFILE] = fopen(names[BODYFILE] = mktemp(strdup(TMPNAME)), "w");
 
        for (i = 0; i < NUMFILES; i++)
                if (files[i] == NULL)
 
        for (i = 0; i < NUMFILES; i++)
                if (files[i] == NULL)
@@ -95,7 +138,7 @@ main(argc, argv)
                                quit(argv[ac]);
                } else {
                        printout();
                                quit(argv[ac]);
                } else {
                        printout();
-                       onintr();
+                       onintr(0);
                        exit(0);
                }
                fgets(line, BUFSIZ, input);
                        exit(0);
                }
                fgets(line, BUFSIZ, input);
@@ -107,7 +150,7 @@ main(argc, argv)
                        }
                        for (cp = &line[1]; isspace(*cp); cp++)
                                /* void */;
                        }
                        for (cp = &line[1]; isspace(*cp); cp++)
                                /* void */;
-                       if (strcmpn("include", cp, 7))
+                       if (strncmp("include", cp, 7))
                                goto bad;
                        for (cp += 7; isspace(*cp); cp++)
                                /* void */;
                                goto bad;
                        for (cp += 7; isspace(*cp); cp++)
                                /* void */;
@@ -237,7 +280,7 @@ split(line)
                len = cp - word;
                switch (*word) {
                case 'b':
                len = cp - word;
                switch (*word) {
                case 'b':
-                       if (len == 5 && !strcmpn(word, "begin", 5)) {
+                       if (len == 5 && !strncmp(word, "begin", 5)) {
                                if (nest == 0 && beginnest == 0) {
                                        if (inprog != 1) {
                                                fprintf(stderr,
                                if (nest == 0 && beginnest == 0) {
                                        if (inprog != 1) {
                                                fprintf(stderr,
@@ -251,13 +294,13 @@ split(line)
                        }
                        break;
                case 'c':
                        }
                        break;
                case 'c':
-                       if (len == 4 && !strcmpn(word, "case", 4)) {
+                       if (len == 4 && !strncmp(word, "case", 4)) {
                                if (beginnest > 0) {
                                        beginnest++;
                                }
                                break;
                        }
                                if (beginnest > 0) {
                                        beginnest++;
                                }
                                break;
                        }
-                       if (len == 5 && !strcmpn(word, "const", 5)) {
+                       if (len == 5 && !strncmp(word, "const", 5)) {
                                if (nest == 0) {
                                        prt = FALSE;
                                        if (!constopen) {
                                if (nest == 0) {
                                        prt = FALSE;
                                        if (!constopen) {
@@ -269,7 +312,7 @@ split(line)
                        }
                        break;
                case 'e':
                        }
                        break;
                case 'e':
-                       if (len == 3 && !strcmpn(word, "end", 3)) {
+                       if (len == 3 && !strncmp(word, "end", 3)) {
                                if (beginnest == 1) {
                                        nest--;
                                }
                                if (beginnest == 1) {
                                        nest--;
                                }
@@ -287,7 +330,7 @@ split(line)
                                }
                                break;
                        }
                                }
                                break;
                        }
-                       if (len == 8 && !strcmpn(word, "external", 8)) {
+                       if (len == 8 && !strncmp(word, "external", 8)) {
                                fputs("forward", curfile);
                                prt = FALSE;
                                if (paren_level == 0) {
                                fputs("forward", curfile);
                                prt = FALSE;
                                if (paren_level == 0) {
@@ -296,7 +339,7 @@ split(line)
                        }
                        break;
                case 'f':
                        }
                        break;
                case 'f':
-                       if (len == 8 && !strcmpn(word, "function", 8)) {
+                       if (len == 8 && !strncmp(word, "function", 8)) {
                                if (nest == 0) {
                                        curfile = files[RTNFILE];
                                }
                                if (nest == 0) {
                                        curfile = files[RTNFILE];
                                }
@@ -305,14 +348,14 @@ split(line)
                                }
                                break;
                        }
                                }
                                break;
                        }
-                       if (len == 7 && !strcmpn(word, "forward", 7)) {
+                       if (len == 7 && !strncmp(word, "forward", 7)) {
                                if (paren_level == 0) {
                                        nest--;
                                }
                        }
                        break;
                case 'l':
                                if (paren_level == 0) {
                                        nest--;
                                }
                        }
                        break;
                case 'l':
-                       if (len == 5 && !strcmpn(word, "label", 5)) {
+                       if (len == 5 && !strncmp(word, "label", 5)) {
                                if (nest == 0) {
                                        prt = FALSE;
                                        if (!labelopen) {
                                if (nest == 0) {
                                        prt = FALSE;
                                        if (!labelopen) {
@@ -324,7 +367,7 @@ split(line)
                        }
                        break;
                case 'p':
                        }
                        break;
                case 'p':
-                       if (len == 9 && !strcmpn(word, "procedure", 9)) {
+                       if (len == 9 && !strncmp(word, "procedure", 9)) {
                                if (nest == 0) {
                                        curfile = files[RTNFILE];
                                }
                                if (nest == 0) {
                                        curfile = files[RTNFILE];
                                }
@@ -333,7 +376,7 @@ split(line)
                                }
                                break;
                        }
                                }
                                break;
                        }
-                       if (len == 7 && !strcmpn(word, "program", 7)) {
+                       if (len == 7 && !strncmp(word, "program", 7)) {
                                if (nest != 0) {
                                        fprintf(stderr, "improper program nesting");
                                        quit(NULL);
                                if (nest != 0) {
                                        fprintf(stderr, "improper program nesting");
                                        quit(NULL);
@@ -343,7 +386,7 @@ split(line)
                        }
                        break;
                case 't':
                        }
                        break;
                case 't':
-                       if (len == 4 && !strcmpn(word, "type", 4)) {
+                       if (len == 4 && !strncmp(word, "type", 4)) {
                                if (nest == 0) {
                                        prt = FALSE;
                                        if (!typeopen) {
                                if (nest == 0) {
                                        prt = FALSE;
                                        if (!typeopen) {
@@ -355,7 +398,7 @@ split(line)
                        }
                        break;
                case 'v':
                        }
                        break;
                case 'v':
-                       if (len == 3 && !strcmpn(word, "var", 3)) {
+                       if (len == 3 && !strncmp(word, "var", 3)) {
                                if (nest == 0) {
                                        prt = FALSE;
                                        if (!varopen) {
                                if (nest == 0) {
                                        prt = FALSE;
                                        if (!varopen) {
@@ -403,6 +446,6 @@ quit(fp)
 {
        if (fp != NULL)
                perror(fp);
 {
        if (fp != NULL)
                perror(fp);
-       onintr();
+       onintr(0);
        exit(1);
 }
        exit(1);
 }