move entry/exit debugging to 21.1
[unix-history] / usr / src / usr.bin / make / compat.c
index 3d08f66..85f21da 100644 (file)
@@ -1,27 +1,17 @@
 /*
 /*
- * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
- * Copyright (c) 1988, 1989 by Adam de Boor
+ * Copyright (c) 1988, 1989, 1990, 1993
+ *     The Regents of the University of California.  All rights reserved.
  * Copyright (c) 1989 by Berkeley Softworks
  * All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * Adam de Boor.
  *
  * Copyright (c) 1989 by Berkeley Softworks
  * All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * Adam de Boor.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)compat.c   5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)compat.c   8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 /*-
 #endif /* not lint */
 
 /*-
@@ -37,13 +27,19 @@ static char sccsid[] = "@(#)compat.c        5.4 (Berkeley) %G%";
  *                         thems as need creatin'
  */
 
  *                         thems as need creatin'
  */
 
-#include    <stdio.h>
 #include    <sys/types.h>
 #include    <sys/types.h>
-#include    <sys/signal.h>
+#include    <sys/stat.h>
 #include    <sys/wait.h>
 #include    <sys/wait.h>
-#include    <sys/errno.h>
+
 #include    <ctype.h>
 #include    <ctype.h>
+#include    <errno.h>
+#include    <signal.h>
+#include    <stdio.h>
+
 #include    "make.h"
 #include    "make.h"
+#include    "hash.h"
+#include    "dir.h"
+#include    "job.h"
 extern int errno;
 
 /*
 extern int errno;
 
 /*
@@ -57,7 +53,9 @@ static char       meta[256];
 
 static GNode       *curTarg = NILGNODE;
 static GNode       *ENDNode;
 
 static GNode       *curTarg = NILGNODE;
 static GNode       *ENDNode;
-static int         CompatRunCommand();
+static void CompatInterrupt __P((int));
+static int CompatRunCommand __P((char *, GNode *));
+static int CompatMake __P((GNode *, GNode *));
 
 /*-
  *-----------------------------------------------------------------------
 
 /*-
  *-----------------------------------------------------------------------
@@ -74,16 +72,18 @@ static int              CompatRunCommand();
  *
  *-----------------------------------------------------------------------
  */
  *
  *-----------------------------------------------------------------------
  */
-static int
+static void
 CompatInterrupt (signo)
     int            signo;
 {
 CompatInterrupt (signo)
     int            signo;
 {
+    struct stat sb;
     GNode   *gn;
     
     if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) {
        char      *file = Var_Value (TARGET, curTarg);
 
     GNode   *gn;
     
     if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) {
        char      *file = Var_Value (TARGET, curTarg);
 
-       if (unlink (file) == SUCCESS) {
+       if (!stat(file, &sb) && S_ISREG(sb.st_mode) &&
+           unlink (file) == SUCCESS) {
            printf ("*** %s removed\n", file);
        }
 
            printf ("*** %s removed\n", file);
        }
 
@@ -126,7 +126,6 @@ CompatRunCommand (cmd, gn)
     union wait           reason;       /* Reason for child's death */
     int                  status;       /* Description of child's death */
     int                  cpid;         /* Child actually found */
     union wait           reason;       /* Reason for child's death */
     int                  status;       /* Description of child's death */
     int                  cpid;         /* Child actually found */
-    int                  numWritten;   /* Number of bytes written for error message */
     ReturnStatus  stat;                /* Status of fork */
     LstNode      cmdNode;      /* Node where current command is located */
     char         **av;         /* Argument vector for thing to exec */
     ReturnStatus  stat;                /* Status of fork */
     LstNode      cmdNode;      /* Node where current command is located */
     char         **av;         /* Argument vector for thing to exec */
@@ -135,11 +134,20 @@ CompatRunCommand (cmd, gn)
     Boolean      local;        /* TRUE if command should be executed
                                 * locally */
 
     Boolean      local;        /* TRUE if command should be executed
                                 * locally */
 
+    /*  
+     * Avoid clobbered variable warnings by forcing the compiler
+     * to ``unregister'' variables
+     */ 
+#if __GNUC__
+    (void) &av; 
+    (void) &errCheck;
+#endif 
+
     silent = gn->type & OP_SILENT;
     errCheck = !(gn->type & OP_IGNORE);
 
     cmdNode = Lst_Member (gn->commands, (ClientData)cmd);
     silent = gn->type & OP_SILENT;
     errCheck = !(gn->type & OP_IGNORE);
 
     cmdNode = Lst_Member (gn->commands, (ClientData)cmd);
-    cmdStart = Var_Subst (cmd, gn, FALSE);
+    cmdStart = Var_Subst (NULL, cmd, gn, FALSE);
 
     /*
      * brk_string will return an argv with a NULL in av[1], thus causing
 
     /*
      * brk_string will return an argv with a NULL in av[1], thus causing
@@ -149,9 +157,7 @@ CompatRunCommand (cmd, gn)
      */
      
     if (*cmdStart == '\0') {
      */
      
     if (*cmdStart == '\0') {
-       if (!noWarnings) {
-           Error("%s expands to empty string", cmd);
-       }
+       Error("%s expands to empty string", cmd);
        return(0);
     } else {
        cmd = cmdStart;
        return(0);
     } else {
        cmd = cmdStart;
@@ -174,13 +180,16 @@ CompatRunCommand (cmd, gn)
        }
        cmd++;
     }
        }
        cmd++;
     }
+
+    while (isspace((unsigned char)*cmd))
+       cmd++;
     
     /*
      * Search for meta characters in the command. If there are no meta
      * characters, there's no need to execute a shell to execute the
      * command.
      */
     
     /*
      * Search for meta characters in the command. If there are no meta
      * characters, there's no need to execute a shell to execute the
      * command.
      */
-    for (cp = cmd; !meta[*cp]; cp++) {
+    for (cp = cmd; !meta[(unsigned char)*cp]; cp++) {
        continue;
     }
 
        continue;
     }
 
@@ -238,8 +247,8 @@ CompatRunCommand (cmd, gn)
     if (cpid == 0) {
        if (local) {
            execvp(av[0], av);
     if (cpid == 0) {
        if (local) {
            execvp(av[0], av);
-           numWritten = write (2, av[0], strlen (av[0]));
-           numWritten = write (2, ": not found\n", sizeof(": not found"));
+           (void) write (2, av[0], strlen (av[0]));
+           (void) write (2, ": not found\n", sizeof(": not found"));
        } else {
            (void)execv(av[0], av);
        }
        } else {
            (void)execv(av[0], av);
        }
@@ -256,7 +265,7 @@ CompatRunCommand (cmd, gn)
            id = 0;
        }
 
            id = 0;
        }
 
-       while ((stat = wait(&reason)) != cpid) {
+       while ((stat = wait((int *)&reason)) != cpid) {
            if (stat == -1 && errno != EINTR) {
                break;
            }
            if (stat == -1 && errno != EINTR) {
                break;
            }
@@ -469,6 +478,8 @@ CompatMake (gn, pgn)
            if (noExecute || Dir_MTime(gn) == 0) {
                gn->mtime = now;
            }
            if (noExecute || Dir_MTime(gn) == 0) {
                gn->mtime = now;
            }
+           if (gn->cmtime > gn->mtime)
+               gn->mtime = gn->cmtime;
            if (DEBUG(MAKE)) {
                printf("update time: %s\n", Targ_FmtTime(gn->mtime));
            }
            if (DEBUG(MAKE)) {
                printf("update time: %s\n", Targ_FmtTime(gn->mtime));
            }
@@ -510,6 +521,8 @@ CompatMake (gn, pgn)
                    Make_TimeStamp(pgn, gn);
                }
                break;
                    Make_TimeStamp(pgn, gn);
                }
                break;
+           default:
+               break;
        }
     }
 
        }
     }
 
@@ -534,7 +547,7 @@ Compat_Run(targs)
     Lst                  targs;    /* List of target nodes to re-create */
 {
     char         *cp;      /* Pointer to string of shell meta-characters */
     Lst                  targs;    /* List of target nodes to re-create */
 {
     char         *cp;      /* Pointer to string of shell meta-characters */
-    GNode        *gn;      /* Current root target */
+    GNode        *gn = NULL;/* Current root target */
     int                  errors;   /* Number of targets not remade due to errors */
 
     if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
     int                  errors;   /* Number of targets not remade due to errors */
 
     if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
@@ -551,7 +564,7 @@ Compat_Run(targs)
     }
 
     for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
     }
 
     for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
-       meta[*cp] = 1;
+       meta[(unsigned char) *cp] = 1;
     }
     /*
      * The null character serves as a sentinel in the string.
     }
     /*
      * The null character serves as a sentinel in the string.