Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/mkdep Split out the findcc() function that tries to ...



details:   https://anonhg.NetBSD.org/src/rev/9578830483ed
branches:  trunk
changeset: 532775:9578830483ed
user:      simonb <simonb%NetBSD.org@localhost>
date:      Fri Jun 14 23:14:18 2002 +0000

description:
Split out the findcc() function that tries to determine the path to
the C compiler so other programs can use it.

diffstat:

 usr.bin/mkdep/Makefile |   3 +-
 usr.bin/mkdep/findcc.c |  97 ++++++++++++++++++++++++++++++++++++++++++++++++++
 usr.bin/mkdep/findcc.h |   3 +
 usr.bin/mkdep/mkdep.c  |  45 ++---------------------
 4 files changed, 106 insertions(+), 42 deletions(-)

diffs (199 lines):

diff -r e5c2de97698f -r 9578830483ed usr.bin/mkdep/Makefile
--- a/usr.bin/mkdep/Makefile    Fri Jun 14 22:43:38 2002 +0000
+++ b/usr.bin/mkdep/Makefile    Fri Jun 14 23:14:18 2002 +0000
@@ -1,8 +1,9 @@
-#      $NetBSD: Makefile,v 1.11 2001/08/14 10:18:28 tv Exp $
+#      $NetBSD: Makefile,v 1.12 2002/06/14 23:14:18 simonb Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/6/93
 
 MAN=   mkdep.1
 PROG=  mkdep
+SRCS=  mkdep.c findcc.c
 
 .ifndef HOSTPROG
 .include <bsd.prog.mk>
diff -r e5c2de97698f -r 9578830483ed usr.bin/mkdep/findcc.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/mkdep/findcc.c    Fri Jun 14 23:14:18 2002 +0000
@@ -0,0 +1,97 @@
+/* $NetBSD: findcc.c,v 1.1 2002/06/14 23:14:18 simonb Exp $ */
+
+/*-
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matthias Scheler.
+ *
+ * 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 NetBSD
+ *     Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+#include <sys/cdefs.h>
+#if defined(__COPYRIGHT) && !defined(lint)
+__COPYRIGHT("@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\n\
+       All rights reserved.\n");
+#endif /* not lint */
+
+#if defined(__RCSID) && !defined(lint)
+__RCSID("$NetBSD: findcc.c,v 1.1 2002/06/14 23:14:18 simonb Exp $");
+#endif /* not lint */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "findcc.h"
+
+char *
+findcc(progname)
+       const char      *progname;
+{
+       char   *path, *dir, *next;
+       char   buffer[MAXPATHLEN];
+
+       if ((next = strchr(progname, ' ')) != NULL) {
+               *next = '\0';
+       }
+
+       if (strchr(progname, '/') != NULL)
+               return access(progname, X_OK) ? NULL : strdup(progname);
+
+       if (((path = getenv("PATH")) == NULL) ||
+           ((path = strdup(path)) == NULL))
+               return NULL;
+
+       dir = path;
+       while (dir != NULL) {
+               if ((next = strchr(dir, ':')) != NULL)
+                       *next++ = '\0';
+
+               if (snprintf(buffer, sizeof(buffer),
+                   "%s/%s", dir, progname) < sizeof(buffer)) {
+                       if (!access(buffer, X_OK)) {
+                               free(path);
+                               return strdup(buffer);
+                       }
+               }
+               dir = next;
+       }
+
+       free(path);
+       return NULL;
+}
+
diff -r e5c2de97698f -r 9578830483ed usr.bin/mkdep/findcc.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/mkdep/findcc.h    Fri Jun 14 23:14:18 2002 +0000
@@ -0,0 +1,3 @@
+#define DEFAULT_CC             "cc"
+
+char *findcc(const char *);
diff -r e5c2de97698f -r 9578830483ed usr.bin/mkdep/mkdep.c
--- a/usr.bin/mkdep/mkdep.c     Fri Jun 14 22:43:38 2002 +0000
+++ b/usr.bin/mkdep/mkdep.c     Fri Jun 14 23:14:18 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mkdep.c,v 1.10 2002/01/31 22:43:55 tv Exp $ */
+/* $NetBSD: mkdep.c,v 1.11 2002/06/14 23:14:18 simonb Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
 #endif /* not lint */
 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: mkdep.c,v 1.10 2002/01/31 22:43:55 tv Exp $");
+__RCSID("$NetBSD: mkdep.c,v 1.11 2002/06/14 23:14:18 simonb Exp $");
 #endif /* not lint */
 
 #if HAVE_CONFIG_H
@@ -61,12 +61,12 @@
 #include <string.h>
 #include <unistd.h>
 
-#define DEFAULT_CC             "cc"
+#include "findcc.h"
+
 #define DEFAULT_PATH           _PATH_DEFPATH
 #define DEFAULT_FILENAME       ".depend"
 
 static void    usage __P((void));
-static char    *findcc __P((const char *));
 int            main __P((int, char **));
 
 static void
@@ -78,43 +78,6 @@
        exit(EXIT_FAILURE);
 }
 
-static char *
-findcc(progname)
-       const char      *progname;
-{
-       char   *path, *dir, *next;
-       char   buffer[MAXPATHLEN];
-
-       if ((next = strchr(progname, ' ')) != NULL) {
-               *next = '\0';
-       }
-
-       if (strchr(progname, '/') != NULL)
-               return access(progname, X_OK) ? NULL : strdup(progname);
-
-       if (((path = getenv("PATH")) == NULL) ||
-           ((path = strdup(path)) == NULL))
-               return NULL;
-
-       dir = path;
-       while (dir != NULL) {
-               if ((next = strchr(dir, ':')) != NULL)
-                       *next++ = '\0';
-
-               if (snprintf(buffer, sizeof(buffer),
-                   "%s/%s", dir, progname) < sizeof(buffer)) {
-                       if (!access(buffer, X_OK)) {
-                               free(path);
-                               return strdup(buffer);
-                       }
-               }
-               dir = next;
-       }
-
-       free(path);
-       return NULL;
-}
-
 int
 main(argc, argv)
        int     argc;



Home | Main Index | Thread Index | Old Index