LCOV - code coverage report
Current view: top level - soltools/mkdepend - main.c (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 295 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 14 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /* $XConsortium: main.c,v 1.84 94/11/30 16:10:44 kaleb Exp $ */
       3             : /* $XFree86: xc/config/makedepend/main.c,v 3.4 1995/07/15 14:53:49 dawes Exp $ */
       4             : /*
       5             : 
       6             : Copyright (c) 1993, 1994  X Consortium
       7             : 
       8             : Permission is hereby granted, free of charge, to any person obtaining a copy
       9             : of this software and associated documentation files (the "Software"), to deal
      10             : in the Software without restriction, including without limitation the rights
      11             : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      12             : copies of the Software, and to permit persons to whom the Software is
      13             : furnished to do so, subject to the following conditions:
      14             : 
      15             : The above copyright notice and this permission notice shall be included in
      16             : all copies or substantial portions of the Software.
      17             : 
      18             : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      19             : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      20             : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
      21             : X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
      22             : AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
      23             : CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      24             : 
      25             : Except as contained in this notice, the name of the X Consortium shall not be
      26             : used in advertising or otherwise to promote the sale, use or other dealings
      27             : in this Software without prior written authorization from the X Consortium.
      28             : 
      29             : */
      30             : 
      31             : #if defined(FREEBSD) || defined(MACOSX)
      32             : #include <sys/types.h>
      33             : #include <sys/stat.h>
      34             : #endif
      35             : 
      36             : #ifdef _WIN32
      37             : #include <io.h>
      38             : #endif
      39             : 
      40             : #ifdef _MSC_VER     /* Define ssize_t */
      41             : 
      42             : #if !defined(_W64)
      43             : #if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
      44             : #define _W64 __w64
      45             : #else
      46             : #define _W64
      47             : #endif
      48             : #endif
      49             : 
      50             : #ifdef  _WIN64
      51             : typedef __int64    ssize_t;
      52             : #else
      53             : typedef _W64 int   ssize_t;
      54             : #endif
      55             : 
      56             : #endif
      57             : 
      58             : #include "def.h"
      59             : #include <string.h>
      60             : #ifdef hpux
      61             : #define sigvec sigvector
      62             : #endif /* hpux */
      63             : 
      64             : #ifdef X_POSIX_C_SOURCE
      65             : #define _POSIX_C_SOURCE X_POSIX_C_SOURCE
      66             : #include <signal.h>
      67             : #undef _POSIX_C_SOURCE
      68             : #else
      69             : #if defined(X_NOT_POSIX) || defined(_POSIX_SOURCE)
      70             : #include <signal.h>
      71             : #else
      72             : #define _POSIX_SOURCE
      73             : #include <signal.h>
      74             : #undef _POSIX_SOURCE
      75             : #endif
      76             : #endif
      77             : 
      78             : #include <stdarg.h>
      79             : 
      80             : #ifdef MINIX
      81             : #define USE_CHMOD   1
      82             : #endif
      83             : 
      84             : #ifdef DEBUG
      85             : int _debugmask;
      86             : #endif
      87             : 
      88             : char *ProgramName;
      89             : 
      90             : #define OBJSUFFIX ".obj"
      91             : #define INCLUDEDIR "."
      92             : 
      93             : char    *directives[] = {
      94             :     "if",
      95             :     "ifdef",
      96             :     "ifndef",
      97             :     "else",
      98             :     "endif",
      99             :     "define",
     100             :     "undef",
     101             :     "include",
     102             :     "line",
     103             :     "pragma",
     104             :     "error",
     105             :     "ident",
     106             :     "sccs",
     107             :     "elif",
     108             :     "eject",
     109             :     NULL
     110             : };
     111             : 
     112             : #define MAKEDEPEND
     113             : #include "imakemdep.h"  /* from config sources */
     114             : #undef MAKEDEPEND
     115             : 
     116             : /*******   function declarations ********/
     117             : /*******   added by -Wall project *******/
     118             : void redirect(char * makefile);
     119             : 
     120             : struct  inclist inclist[ MAXFILES ],
     121             :                 *inclistp = inclist;
     122             : 
     123             : struct symhash *maininclist = NULL;
     124             : 
     125             : char    *filelist[ MAXFILES ];
     126             : char    *includedirs[ MAXDIRS + 1 ];
     127             : char    *notdotdot[ MAXDIRS ];
     128             : char    *objprefix = "";
     129             : char    *objsuffix = OBJSUFFIX;
     130             : char    *startat = "# DO NOT DELETE";
     131             : int width = 78;
     132             : boolean append = FALSE;
     133             : boolean printed = FALSE;
     134             : boolean verbose = FALSE;
     135             : boolean show_where_not = FALSE;
     136             : boolean warn_multiple = FALSE;  /* Warn on multiple includes of same file */
     137             : 
     138             : static
     139             : #ifdef SIGNALRETURNSINT
     140             : int
     141             : #else
     142             : void
     143             : #endif
     144           0 : catch (int sig)
     145             : {
     146           0 :     fflush (stdout);
     147           0 :     fatalerr ("got signal %d\n", sig);
     148           0 : }
     149             : 
     150             : #if (defined(i386) && defined(SYSV)) || defined(WIN32)
     151             : #define USGISH
     152             : #endif
     153             : 
     154             : #ifndef USGISH
     155             : #ifndef _POSIX_SOURCE
     156             : #define sigaction sigvec
     157             : #define sa_handler sv_handler
     158             : #define sa_mask sv_mask
     159             : #define sa_flags sv_flags
     160             : #endif
     161             : struct sigaction sig_act;
     162             : #endif /* USGISH */
     163             : 
     164             : boolean native_win_slashes = FALSE;
     165             : 
     166           0 : int main(int argc, char    **argv)
     167             : {
     168           0 :     char   **fp = filelist;
     169           0 :     char   **incp = includedirs;
     170             :     char   *p;
     171             :     struct inclist *ip;
     172           0 :     char    *makefile = NULL;
     173             :     struct filepointer  *filecontent;
     174           0 :     struct pair *psymp = predefs;
     175           0 :     char *endmarker = NULL;
     176           0 :     char *defincdir = NULL;
     177             :     struct IncludesCollection* incCollection;
     178             : 
     179           0 :     ProgramName = argv[0];
     180             : 
     181           0 :     while (psymp->p_name)
     182             :     {
     183           0 :         hash_define(psymp->p_name, psymp->p_value, &maininclist);
     184           0 :         psymp++;
     185             :     }
     186           0 :     if (argc == 2 && argv[1][0] == '@') {
     187             :         struct stat ast;
     188             :         int afd;
     189             :         char *args;
     190             :         char **nargv;
     191             :         int nargc;
     192           0 :         char quotechar = '\0';
     193             : 
     194           0 :         nargc = 1;
     195           0 :         if ((afd = open(argv[1]+1, O_RDONLY)) < 0)
     196           0 :             fatalerr("cannot open \"%s\"\n", argv[1]+1);
     197           0 :         (void)fstat(afd, &ast);
     198           0 :         args = (char *)malloc(ast.st_size + 1);
     199           0 :         if ((ast.st_size = read(afd, args, (size_t) ast.st_size)) < 0)
     200           0 :             fatalerr("failed to read %s\n", argv[1]+1);
     201           0 :         args[ast.st_size] = '\0';
     202           0 :         close(afd);
     203           0 :         for (p = args; *p; p++) {
     204           0 :         if (quotechar) {
     205           0 :             if (quotechar == '\\'
     206           0 :                 || (*p == quotechar && p[-1] != '\\'))
     207           0 :                 quotechar = '\0';
     208           0 :             continue;
     209             :         }
     210           0 :         switch (*p) {
     211             :         case '\\':
     212             :         case '"':
     213             :         case '\'':
     214           0 :             quotechar = *p;
     215           0 :             break;
     216             :         case ' ':
     217             :         case '\n':
     218           0 :             *p = '\0';
     219           0 :             if (p > args && p[-1])
     220           0 :                 nargc++;
     221           0 :             break;
     222             :         }
     223             :         }
     224           0 :         if (p[-1])
     225           0 :             nargc++;
     226           0 :         nargv = (char **)malloc(nargc * sizeof(char *));
     227           0 :         nargv[0] = argv[0];
     228           0 :         argc = 1;
     229           0 :         for (p = args; argc < nargc; p += strlen(p) + 1)
     230           0 :             if (*p) nargv[argc++] = p;
     231           0 :                 argv = nargv;
     232             :     }
     233           0 :     for(argc--, argv++; argc; argc--, argv++) {
     234             :             /* if looking for endmarker then check before parsing */
     235           0 :         if (endmarker && strcmp (endmarker, *argv) == 0) {
     236           0 :             endmarker = NULL;
     237           0 :             continue;
     238             :         }
     239           0 :         if (**argv != '-') {
     240             :             /* treat +thing as an option for C++ */
     241           0 :             if (endmarker && **argv == '+')
     242           0 :                 continue;
     243           0 :             *fp++ = argv[0];
     244           0 :             continue;
     245             :         }
     246           0 :         switch(argv[0][1]) {
     247             :         case '-':
     248           0 :             endmarker = &argv[0][2];
     249           0 :             if (endmarker[0] == '\0') endmarker = "--";
     250           0 :             break;
     251             :         case 'D':
     252           0 :             if (argv[0][2] == '\0') {
     253           0 :                 argv++;
     254           0 :                 argc--;
     255             :             }
     256           0 :             for (p=argv[0] + 2; *p ; p++)
     257           0 :                 if (*p == '=') {
     258           0 :                     *p = ' ';
     259           0 :                     break;
     260             :                 }
     261           0 :             define(argv[0] + 2, &maininclist);
     262           0 :             break;
     263             :         case 'I':
     264           0 :             if (incp >= includedirs + MAXDIRS)
     265           0 :                 fatalerr("Too many -I flags.\n");
     266           0 :             *incp++ = argv[0]+2;
     267           0 :             if (**(incp-1) == '\0') {
     268           0 :                 *(incp-1) = *(++argv);
     269           0 :                 argc--;
     270             :             }
     271           0 :             break;
     272             :         case 'Y':
     273           0 :             defincdir = argv[0]+2;
     274           0 :             break;
     275             :         /* do not use if endmarker processing */
     276             :         case 'a':
     277           0 :             if (endmarker) break;
     278           0 :             append = TRUE;
     279           0 :             break;
     280             :         case 'w':
     281           0 :             if (endmarker) break;
     282           0 :             if (argv[0][2] == '\0') {
     283           0 :                 argv++;
     284           0 :                 argc--;
     285           0 :                 width = atoi(argv[0]);
     286             :             } else
     287           0 :                 width = atoi(argv[0]+2);
     288           0 :             break;
     289             :         case 'n':
     290             :             // Use "-n" switch to generate dependencies with windows-native slash style
     291           0 :             native_win_slashes = TRUE;
     292           0 :             break;
     293             :         case 'o':
     294           0 :             if (endmarker) break;
     295           0 :             if (argv[0][2] == '\0') {
     296           0 :                 argv++;
     297           0 :                 argc--;
     298           0 :                 objsuffix = argv[0];
     299             :             } else
     300           0 :                 objsuffix = argv[0]+2;
     301           0 :             break;
     302             :         case 'p':
     303           0 :             if (endmarker) break;
     304           0 :             if (argv[0][2] == '\0') {
     305           0 :                 argv++;
     306           0 :                 argc--;
     307           0 :                 objprefix = argv[0];
     308             :             } else
     309           0 :                 objprefix = argv[0]+2;
     310           0 :             break;
     311             :         case 'v':
     312           0 :             if (endmarker) break;
     313           0 :             verbose = TRUE;
     314             : #ifdef DEBUG
     315             :             if (argv[0][2])
     316             :                 _debugmask = atoi(argv[0]+2);
     317             : #endif
     318           0 :             break;
     319             :         case 's':
     320           0 :             if (endmarker) break;
     321           0 :             startat = argv[0]+2;
     322           0 :             if (*startat == '\0') {
     323           0 :                 startat = *(++argv);
     324           0 :                 argc--;
     325             :             }
     326           0 :             if (*startat != '#')
     327           0 :                 fatalerr("-s flag's value should start %s\n",
     328             :                     "with '#'.");
     329           0 :             break;
     330             :         case 'f':
     331           0 :             if (endmarker) break;
     332           0 :             makefile = argv[0]+2;
     333           0 :             if (*makefile == '\0') {
     334           0 :                 makefile = *(++argv);
     335           0 :                 argc--;
     336             :             }
     337           0 :             break;
     338             : 
     339             :         case 'm':
     340           0 :             warn_multiple = TRUE;
     341           0 :             break;
     342             : 
     343             :         /* Ignore -O, -g so we can just pass ${CFLAGS} to
     344             :            makedepend
     345             :          */
     346             :         case 'O':
     347             :         case 'g':
     348           0 :             break;
     349             :         default:
     350           0 :             if (endmarker) break;
     351           0 :             warning("ignoring option %s\n", argv[0]);
     352             :         }
     353             :     }
     354             : 
     355           0 :     convert_slashes(objprefix);
     356           0 :     objprefix = append_slash(objprefix);
     357             : 
     358           0 :     if (!defincdir) {
     359             : #ifdef PREINCDIR
     360             :         if (incp >= includedirs + MAXDIRS)
     361             :         fatalerr("Too many -I flags.\n");
     362             :         *incp++ = PREINCDIR;
     363             : #endif
     364           0 :         if (incp >= includedirs + MAXDIRS)
     365           0 :             fatalerr("Too many -I flags.\n");
     366           0 :         *incp++ = INCLUDEDIR;
     367             : #ifdef POSTINCDIR
     368             :         if (incp >= includedirs + MAXDIRS)
     369             :             fatalerr("Too many -I flags.\n");
     370             :         *incp++ = POSTINCDIR;
     371             : #endif
     372           0 :     } else if (*defincdir) {
     373           0 :         if (incp >= includedirs + MAXDIRS)
     374           0 :             fatalerr("Too many -I flags.\n");
     375           0 :         *incp++ = defincdir;
     376             :     }
     377             : 
     378           0 :     redirect(makefile);
     379             : 
     380             :     /*
     381             :      * catch signals.
     382             :      */
     383             : #ifdef USGISH
     384             : /*  should really reset SIGINT to SIG_IGN if it was.  */
     385             : #ifdef SIGHUP
     386             :     signal (SIGHUP, catch);
     387             : #endif
     388             :     signal (SIGINT, catch);
     389             : #ifdef SIGQUIT
     390             :     signal (SIGQUIT, catch);
     391             : #endif
     392             :     signal (SIGILL, catch);
     393             : #ifdef SIGBUS
     394             :     signal (SIGBUS, catch);
     395             : #endif
     396             :     signal (SIGSEGV, catch);
     397             : #ifdef SIGSYS
     398             :     signal (SIGSYS, catch);
     399             : #endif
     400             :     signal (SIGFPE, catch);
     401             : #else
     402           0 :     sig_act.sa_handler = catch;
     403             : #ifdef _POSIX_SOURCE
     404           0 :     sigemptyset(&sig_act.sa_mask);
     405           0 :     sigaddset(&sig_act.sa_mask, SIGINT);
     406           0 :     sigaddset(&sig_act.sa_mask, SIGQUIT);
     407             : #ifdef SIGBUS
     408           0 :     sigaddset(&sig_act.sa_mask, SIGBUS);
     409             : #endif
     410           0 :     sigaddset(&sig_act.sa_mask, SIGILL);
     411           0 :     sigaddset(&sig_act.sa_mask, SIGSEGV);
     412           0 :     sigaddset(&sig_act.sa_mask, SIGHUP);
     413           0 :     sigaddset(&sig_act.sa_mask, SIGPIPE);
     414             : #ifdef SIGSYS
     415           0 :     sigaddset(&sig_act.sa_mask, SIGSYS);
     416             : #endif
     417             : #else
     418             :     sig_act.sa_mask = ((1<<(SIGINT -1))
     419             :                |(1<<(SIGQUIT-1))
     420             : #ifdef SIGBUS
     421             :                |(1<<(SIGBUS-1))
     422             : #endif
     423             :                |(1<<(SIGILL-1))
     424             :                |(1<<(SIGSEGV-1))
     425             :                |(1<<(SIGHUP-1))
     426             :                |(1<<(SIGPIPE-1))
     427             : #ifdef SIGSYS
     428             :                |(1<<(SIGSYS-1))
     429             : #endif
     430             :                );
     431             : #endif /* _POSIX_SOURCE */
     432           0 :     sig_act.sa_flags = 0;
     433           0 :     sigaction(SIGHUP, &sig_act, (struct sigaction *)0);
     434           0 :     sigaction(SIGINT, &sig_act, (struct sigaction *)0);
     435           0 :     sigaction(SIGQUIT, &sig_act, (struct sigaction *)0);
     436           0 :     sigaction(SIGILL, &sig_act, (struct sigaction *)0);
     437             : #ifdef SIGBUS
     438           0 :     sigaction(SIGBUS, &sig_act, (struct sigaction *)0);
     439             : #endif
     440           0 :     sigaction(SIGSEGV, &sig_act, (struct sigaction *)0);
     441             : #ifdef SIGSYS
     442           0 :     sigaction(SIGSYS, &sig_act, (struct sigaction *)0);
     443             : #endif
     444             : #endif /* USGISH */
     445             : 
     446             :     /*
     447             :      * now peruse through the list of files.
     448             :      */
     449           0 :     incCollection = create_IncludesCollection();
     450             : 
     451           0 :     for(fp=filelist; *fp; fp++) {
     452             :         struct symhash *includes;
     453           0 :         filecontent = getfile(*fp);
     454           0 :         ip = newinclude(*fp, (char *)NULL);
     455             : 
     456           0 :         includes = hash_copy( maininclist );
     457           0 :         find_includes(filecontent, ip, ip, 0, FALSE, incCollection, includes);
     458           0 :         hash_free( includes );
     459             : 
     460           0 :         freefile(filecontent);
     461           0 :         recursive_pr_include(ip, ip->i_file, base_name(*fp));
     462           0 :         if (printed)
     463           0 :             fwrite("\n\n", 2, 1, stdout);
     464           0 :         recursive_pr_dummy(ip, ip->i_file);
     465           0 :         inc_clean();
     466             :     }
     467           0 :     if (printed)
     468           0 :         printf("\n");
     469             : 
     470           0 :     delete_IncludesCollection(incCollection);
     471             : 
     472           0 :     exit(0);
     473             : }
     474             : 
     475           0 : struct filepointer *getfile(char *file)
     476             : {
     477             :     int    fd;
     478             :     struct filepointer  *content;
     479             :     struct stat st;
     480             :     off_t       size_backup;
     481             :     ssize_t     bytes_read;
     482             :     unsigned    malloc_size;
     483             : 
     484           0 :     content = (struct filepointer *)malloc(sizeof(struct filepointer));
     485           0 :     if ((fd = open(file, O_RDONLY)) < 0) {
     486           0 :         warning("makedepend:  Cannot open file \"%s\"\n", file);
     487           0 :         content->f_p = content->f_base = content->f_end = (char *)malloc(1);
     488           0 :         *content->f_p = '\0';
     489           0 :         return content;
     490             :     }
     491           0 :     (void)fstat(fd, &st);
     492             : 
     493           0 :     size_backup = st.st_size;
     494           0 :     malloc_size = size_backup;
     495             :     /* Since off_t usually is larger than unsigned, need to test for
     496             :      * truncation.
     497             :      */
     498           0 :     if ( (off_t)malloc_size != size_backup )
     499             :     {
     500           0 :         close( fd );
     501           0 :         warning("makedepend:  File \"%s\" is too large.\n", file);
     502           0 :         content->f_p = content->f_base = content->f_end = (char *)malloc(1);
     503           0 :         *content->f_p = '\0';
     504           0 :         return content;
     505             :     }
     506             : 
     507           0 :     content->f_base = (char *)malloc(malloc_size+1);
     508           0 :     if (content->f_base == NULL)
     509           0 :         fatalerr("makedepend:  Cannot allocate memory to process file \"%s\"\n", file);
     510           0 :     if ((bytes_read = read(fd, content->f_base, malloc_size)) < 0)
     511           0 :         if ( st.st_mode & S_IFREG )
     512           0 :             fatalerr("makedepend:  Failed to read file \"%s\"\n", file);
     513             : 
     514           0 :     close(fd);
     515           0 :     content->f_len = bytes_read+1;
     516           0 :     content->f_p = content->f_base;
     517           0 :     content->f_end = content->f_base + bytes_read;
     518           0 :     *content->f_end = '\0';
     519           0 :     content->f_line = 0;
     520           0 :     return content;
     521             : }
     522             : 
     523           0 : void freefile(struct filepointer *fp)
     524             : {
     525           0 :     free(fp->f_base);
     526           0 :     free(fp);
     527           0 : }
     528             : 
     529           0 : char *copy(char *str)
     530             : {
     531           0 :     char   *p = (char *)malloc(strlen(str) + 1);
     532             : 
     533           0 :     strcpy(p, str);
     534           0 :     return p;
     535             : }
     536             : 
     537           0 : int match(char *str, char **list)
     538             : {
     539             :     int    i;
     540             : 
     541           0 :     for (i=0; *list; i++, list++)
     542           0 :         if (strcmp(str, *list) == 0)
     543           0 :             return i;
     544           0 :     return -1;
     545             : }
     546             : 
     547             : /*
     548             :  * Get the next line.  We only return lines beginning with '#' since that
     549             :  * is all this program is ever interested in.
     550             :  */
     551           0 : char *get_line(struct filepointer *filep)
     552             : {
     553             :     char   *p, /* walking pointer */
     554             :            *eof,   /* end of file pointer */
     555             :            *bol;   /* beginning of line pointer */
     556             :     int    lineno; /* line number */
     557             : 
     558           0 :     p = filep->f_p;
     559           0 :     eof = filep->f_end;
     560           0 :     if (p >= eof)
     561           0 :         return (char *)NULL;
     562           0 :     lineno = filep->f_line;
     563             : 
     564           0 :     for(bol = p--; ++p < eof; ) {
     565           0 :         if (*p == '/' && *(p+1) == '*') { /* consume comments */
     566           0 :             *p++ = ' ', *p++ = ' ';
     567           0 :             while (*p) {
     568           0 :                 if (*p == '*' && *(p+1) == '/') {
     569           0 :                     *p++ = ' ', *p = ' ';
     570           0 :                     break;
     571             :                 }
     572           0 :                 else if (*p == '\n')
     573           0 :                     lineno++;
     574           0 :                 *p++ = ' ';
     575             :             }
     576           0 :             continue;
     577             :         }
     578           0 :         else if (*p == '/' && *(p+1) == '/') { /* consume comments */
     579           0 :             *p++ = ' ', *p++ = ' ';
     580           0 :             while (*p && *p != '\n')
     581           0 :                 *p++ = ' ';
     582           0 :             if ( *p == '\n' )
     583           0 :                 p--;
     584           0 :             lineno++;
     585           0 :             continue;
     586             :         }
     587           0 :         else if (*p == '\\') {
     588           0 :             if (*(p+1) == '\n') {
     589           0 :                 *p = ' ';
     590           0 :                 *(p+1) = ' ';
     591           0 :                 lineno++;
     592             :             }
     593             :         }
     594           0 :         else if (*p == '\n') {
     595           0 :             lineno++;
     596           0 :             if (*bol == '#') {
     597             :                 char *cp;
     598             : 
     599           0 :                 *p++ = '\0';
     600             :                 /* punt lines with just # (yacc generated) */
     601           0 :                 for (cp = bol+1;
     602           0 :                      *cp && (*cp == ' ' || *cp == '\t'); cp++);
     603           0 :                 if (*cp) goto done;
     604             :             }
     605           0 :             bol = p+1;
     606             :         }
     607             :     }
     608           0 :     if (*bol != '#')
     609           0 :         bol = NULL;
     610             : done:
     611           0 :     filep->f_p = p;
     612           0 :     filep->f_line = lineno;
     613           0 :     return bol;
     614             : }
     615             : 
     616             : /*
     617             :  * Strip the file name down to what we want to see in the Makefile.
     618             :  * It will have objprefix and objsuffix around it.
     619             :  */
     620           0 : char *base_name(char *file)
     621             : {
     622             :     char   *p;
     623             : 
     624           0 :     file = copy(file);
     625           0 :     for(p=file+strlen(file); p>file && *p != '.'; p--) ;
     626             : 
     627           0 :     if (*p == '.')
     628           0 :         *p = '\0';
     629             : 
     630           0 :     while (p > file) {
     631           0 :         if ( *p == '/' ||  *p == '\\') {
     632           0 :             file = p + 1;
     633           0 :             break;
     634             :         };
     635           0 :         p--;
     636             :     };
     637           0 :     return file;
     638             : }
     639             : 
     640             : #if defined(USG) && !defined(CRAY) && !defined(SVR4)
     641             : int rename (char *from, char *to)
     642             : {
     643             :     (void) unlink (to);
     644             :     if (link (from, to) == 0) {
     645             :     unlink (from);
     646             :     return 0;
     647             :     } else {
     648             :     return -1;
     649             :     }
     650             : }
     651             : #endif /* USGISH */
     652             : 
     653           0 : void redirect(char *makefile)
     654             : {
     655             :     FILE    *fdout;
     656           0 :     fdout = makefile ? freopen(makefile, "wb", stdout) : NULL; // binary mode please
     657           0 :     if (fdout == NULL)
     658           0 :         fatalerr("cannot open \"%s\"\n", makefile ? makefile : "<NULL>");
     659           0 : }
     660             : 
     661           0 : void fatalerr(char *msg, ...)
     662             : {
     663             :     va_list args;
     664           0 :     fprintf(stderr, "%s: error:  ", ProgramName);
     665           0 :     va_start(args, msg);
     666           0 :     vfprintf(stderr, msg, args);
     667           0 :     va_end(args);
     668           0 :     exit (1);
     669             : }
     670             : 
     671           0 : void warning(char *msg, ...)
     672             : {
     673             : #ifdef DEBUG_MKDEPEND
     674             :     va_list args;
     675             :     fprintf(stderr, "%s: warning:  ", ProgramName);
     676             :     va_start(args, msg);
     677             :     vfprintf(stderr, msg, args);
     678             :     va_end(args);
     679             : #else
     680             :     (void)msg;
     681             : #endif /* DEBUG_MKDEPEND */
     682           0 : }
     683             : 
     684           0 : void warning1(char *msg, ...)
     685             : {
     686             : #ifdef DEBUG_MKDEPEND
     687             :     va_list args;
     688             :     va_start(args, msg);
     689             :     vfprintf(stderr, msg, args);
     690             :     va_end(args);
     691             : #else
     692             :     (void)msg;
     693             : #endif /* DEBUG_MKDEPEND */
     694           0 : }
     695             : 
     696           0 : void convert_slashes(char *path)
     697             : {
     698             : #if defined (WNT)
     699             :     /*
     700             :      * Convert backslashes to slashes
     701             :      */
     702             :     char *ptr;
     703             :     if (native_win_slashes) {
     704             :         for (ptr = (char*)path; *ptr; ++ptr)
     705             :             if (*ptr == '/')
     706             :                 *ptr = '\\';
     707             :     } else {
     708             :         for (ptr = (char*)path; *ptr; ++ptr)
     709             :             if (*ptr == '\\')
     710             :                 *ptr = '/';
     711             :     };
     712             : #else
     713             :     (void)path;
     714             : #endif
     715           0 : }
     716             : 
     717           0 : char* append_slash(char *path)
     718             : {
     719             :     char *new_string;
     720           0 :     const char cLastChar = path[strlen(path) - 1];
     721           0 :     if (cLastChar == '/' || cLastChar == '\\') {
     722           0 :         new_string = path;
     723             :     } else {
     724           0 :         new_string = (char*)malloc(sizeof(char) * (strlen(path) + 2));
     725           0 :         strcpy(new_string, path);
     726           0 :         if (native_win_slashes)
     727           0 :             strcat(new_string, "\\");
     728             :         else
     729           0 :             strcat(new_string, "/");
     730             :     };
     731           0 :     return new_string;
     732             : }
     733             : 
     734             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11