LCOV - code coverage report
Current view: top level - soltools/mkdepend - main.c (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 294 0.0 %
Date: 2014-04-11 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 * line, 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(argc, argv)
     167             :     int argc;
     168             :     char    **argv;
     169             : {
     170           0 :     register char   **fp = filelist;
     171           0 :     register char   **incp = includedirs;
     172             :     register char   *p;
     173             :     register struct inclist *ip;
     174           0 :     char    *makefile = NULL;
     175             :     struct filepointer  *filecontent;
     176           0 :     struct pair *psymp = predefs;
     177           0 :     char *endmarker = NULL;
     178           0 :     char *defincdir = NULL;
     179             :     struct IncludesCollection* incCollection;
     180             : 
     181           0 :     ProgramName = argv[0];
     182             : 
     183           0 :     while (psymp->p_name)
     184             :     {
     185           0 :         hash_define(psymp->p_name, psymp->p_value, &maininclist);
     186           0 :         psymp++;
     187             :     }
     188           0 :     if (argc == 2 && argv[1][0] == '@') {
     189             :         struct stat ast;
     190             :         int afd;
     191             :         char *args;
     192             :         char **nargv;
     193             :         int nargc;
     194           0 :         char quotechar = '\0';
     195             : 
     196           0 :         nargc = 1;
     197           0 :         if ((afd = open(argv[1]+1, O_RDONLY)) < 0)
     198           0 :             fatalerr("cannot open \"%s\"\n", argv[1]+1);
     199           0 :         fstat(afd, &ast);
     200           0 :         args = (char *)malloc(ast.st_size + 1);
     201           0 :         if ((ast.st_size = read(afd, args, (size_t) ast.st_size)) < 0)
     202           0 :             fatalerr("failed to read %s\n", argv[1]+1);
     203           0 :         args[ast.st_size] = '\0';
     204           0 :         close(afd);
     205           0 :         for (p = args; *p; p++) {
     206           0 :         if (quotechar) {
     207           0 :             if (quotechar == '\\'
     208           0 :                 || (*p == quotechar && p[-1] != '\\'))
     209           0 :                 quotechar = '\0';
     210           0 :             continue;
     211             :         }
     212           0 :         switch (*p) {
     213             :         case '\\':
     214             :         case '"':
     215             :         case '\'':
     216           0 :             quotechar = *p;
     217           0 :             break;
     218             :         case ' ':
     219             :         case '\n':
     220           0 :             *p = '\0';
     221           0 :             if (p > args && p[-1])
     222           0 :                 nargc++;
     223           0 :             break;
     224             :         }
     225             :         }
     226           0 :         if (p[-1])
     227           0 :             nargc++;
     228           0 :         nargv = (char **)malloc(nargc * sizeof(char *));
     229           0 :         nargv[0] = argv[0];
     230           0 :         argc = 1;
     231           0 :         for (p = args; argc < nargc; p += strlen(p) + 1)
     232           0 :             if (*p) nargv[argc++] = p;
     233           0 :                 argv = nargv;
     234             :     }
     235           0 :     for(argc--, argv++; argc; argc--, argv++) {
     236             :             /* if looking for endmarker then check before parsing */
     237           0 :         if (endmarker && strcmp (endmarker, *argv) == 0) {
     238           0 :             endmarker = NULL;
     239           0 :             continue;
     240             :         }
     241           0 :         if (**argv != '-') {
     242             :             /* treat +thing as an option for C++ */
     243           0 :             if (endmarker && **argv == '+')
     244           0 :                 continue;
     245           0 :             *fp++ = argv[0];
     246           0 :             continue;
     247             :         }
     248           0 :         switch(argv[0][1]) {
     249             :         case '-':
     250           0 :             endmarker = &argv[0][2];
     251           0 :             if (endmarker[0] == '\0') endmarker = "--";
     252           0 :             break;
     253             :         case 'D':
     254           0 :             if (argv[0][2] == '\0') {
     255           0 :                 argv++;
     256           0 :                 argc--;
     257             :             }
     258           0 :             for (p=argv[0] + 2; *p ; p++)
     259           0 :                 if (*p == '=') {
     260           0 :                     *p = ' ';
     261           0 :                     break;
     262             :                 }
     263           0 :             define(argv[0] + 2, &maininclist);
     264           0 :             break;
     265             :         case 'I':
     266           0 :             if (incp >= includedirs + MAXDIRS)
     267           0 :                 fatalerr("Too many -I flags.\n");
     268           0 :             *incp++ = argv[0]+2;
     269           0 :             if (**(incp-1) == '\0') {
     270           0 :                 *(incp-1) = *(++argv);
     271           0 :                 argc--;
     272             :             }
     273           0 :             break;
     274             :         case 'Y':
     275           0 :             defincdir = argv[0]+2;
     276           0 :             break;
     277             :         /* do not use if endmarker processing */
     278             :         case 'a':
     279           0 :             if (endmarker) break;
     280           0 :             append = TRUE;
     281           0 :             break;
     282             :         case 'w':
     283           0 :             if (endmarker) break;
     284           0 :             if (argv[0][2] == '\0') {
     285           0 :                 argv++;
     286           0 :                 argc--;
     287           0 :                 width = atoi(argv[0]);
     288             :             } else
     289           0 :                 width = atoi(argv[0]+2);
     290           0 :             break;
     291             :         case 'n':
     292             :             // Use "-n" switch to generate dependencies with windows-native slash style
     293           0 :             native_win_slashes = TRUE;
     294           0 :             break;
     295             :         case 'o':
     296           0 :             if (endmarker) break;
     297           0 :             if (argv[0][2] == '\0') {
     298           0 :                 argv++;
     299           0 :                 argc--;
     300           0 :                 objsuffix = argv[0];
     301             :             } else
     302           0 :                 objsuffix = argv[0]+2;
     303           0 :             break;
     304             :         case 'p':
     305           0 :             if (endmarker) break;
     306           0 :             if (argv[0][2] == '\0') {
     307           0 :                 argv++;
     308           0 :                 argc--;
     309           0 :                 objprefix = argv[0];
     310             :             } else
     311           0 :                 objprefix = argv[0]+2;
     312           0 :             break;
     313             :         case 'v':
     314           0 :             if (endmarker) break;
     315           0 :             verbose = TRUE;
     316             : #ifdef DEBUG
     317             :             if (argv[0][2])
     318             :                 _debugmask = atoi(argv[0]+2);
     319             : #endif
     320           0 :             break;
     321             :         case 's':
     322           0 :             if (endmarker) break;
     323           0 :             startat = argv[0]+2;
     324           0 :             if (*startat == '\0') {
     325           0 :                 startat = *(++argv);
     326           0 :                 argc--;
     327             :             }
     328           0 :             if (*startat != '#')
     329           0 :                 fatalerr("-s flag's value should start %s\n",
     330             :                     "with '#'.");
     331           0 :             break;
     332             :         case 'f':
     333           0 :             if (endmarker) break;
     334           0 :             makefile = argv[0]+2;
     335           0 :             if (*makefile == '\0') {
     336           0 :                 makefile = *(++argv);
     337           0 :                 argc--;
     338             :             }
     339           0 :             break;
     340             : 
     341             :         case 'm':
     342           0 :             warn_multiple = TRUE;
     343           0 :             break;
     344             : 
     345             :         /* Ignore -O, -g so we can just pass ${CFLAGS} to
     346             :            makedepend
     347             :          */
     348             :         case 'O':
     349             :         case 'g':
     350           0 :             break;
     351             :         default:
     352           0 :             if (endmarker) break;
     353           0 :             warning("ignoring option %s\n", argv[0]);
     354             :         }
     355             :     }
     356             : 
     357           0 :     convert_slashes(objprefix);
     358           0 :     objprefix = append_slash(objprefix);
     359             : 
     360           0 :     if (!defincdir) {
     361             : #ifdef PREINCDIR
     362             :         if (incp >= includedirs + MAXDIRS)
     363             :         fatalerr("Too many -I flags.\n");
     364             :         *incp++ = PREINCDIR;
     365             : #endif
     366           0 :         if (incp >= includedirs + MAXDIRS)
     367           0 :             fatalerr("Too many -I flags.\n");
     368           0 :         *incp++ = INCLUDEDIR;
     369             : #ifdef POSTINCDIR
     370             :         if (incp >= includedirs + MAXDIRS)
     371             :             fatalerr("Too many -I flags.\n");
     372             :         *incp++ = POSTINCDIR;
     373             : #endif
     374           0 :     } else if (*defincdir) {
     375           0 :         if (incp >= includedirs + MAXDIRS)
     376           0 :             fatalerr("Too many -I flags.\n");
     377           0 :         *incp++ = defincdir;
     378             :     }
     379             : 
     380           0 :     redirect(startat, makefile);
     381             : 
     382             :     /*
     383             :      * catch signals.
     384             :      */
     385             : #ifdef USGISH
     386             : /*  should really reset SIGINT to SIG_IGN if it was.  */
     387             : #ifdef SIGHUP
     388             :     signal (SIGHUP, catch);
     389             : #endif
     390             :     signal (SIGINT, catch);
     391             : #ifdef SIGQUIT
     392             :     signal (SIGQUIT, catch);
     393             : #endif
     394             :     signal (SIGILL, catch);
     395             : #ifdef SIGBUS
     396             :     signal (SIGBUS, catch);
     397             : #endif
     398             :     signal (SIGSEGV, catch);
     399             : #ifdef SIGSYS
     400             :     signal (SIGSYS, catch);
     401             : #endif
     402             :     signal (SIGFPE, catch);
     403             : #else
     404           0 :     sig_act.sa_handler = catch;
     405             : #ifdef _POSIX_SOURCE
     406           0 :     sigemptyset(&sig_act.sa_mask);
     407           0 :     sigaddset(&sig_act.sa_mask, SIGINT);
     408           0 :     sigaddset(&sig_act.sa_mask, SIGQUIT);
     409             : #ifdef SIGBUS
     410           0 :     sigaddset(&sig_act.sa_mask, SIGBUS);
     411             : #endif
     412           0 :     sigaddset(&sig_act.sa_mask, SIGILL);
     413           0 :     sigaddset(&sig_act.sa_mask, SIGSEGV);
     414           0 :     sigaddset(&sig_act.sa_mask, SIGHUP);
     415           0 :     sigaddset(&sig_act.sa_mask, SIGPIPE);
     416             : #ifdef SIGSYS
     417           0 :     sigaddset(&sig_act.sa_mask, SIGSYS);
     418             : #endif
     419             : #else
     420             :     sig_act.sa_mask = ((1<<(SIGINT -1))
     421             :                |(1<<(SIGQUIT-1))
     422             : #ifdef SIGBUS
     423             :                |(1<<(SIGBUS-1))
     424             : #endif
     425             :                |(1<<(SIGILL-1))
     426             :                |(1<<(SIGSEGV-1))
     427             :                |(1<<(SIGHUP-1))
     428             :                |(1<<(SIGPIPE-1))
     429             : #ifdef SIGSYS
     430             :                |(1<<(SIGSYS-1))
     431             : #endif
     432             :                );
     433             : #endif /* _POSIX_SOURCE */
     434           0 :     sig_act.sa_flags = 0;
     435           0 :     sigaction(SIGHUP, &sig_act, (struct sigaction *)0);
     436           0 :     sigaction(SIGINT, &sig_act, (struct sigaction *)0);
     437           0 :     sigaction(SIGQUIT, &sig_act, (struct sigaction *)0);
     438           0 :     sigaction(SIGILL, &sig_act, (struct sigaction *)0);
     439             : #ifdef SIGBUS
     440           0 :     sigaction(SIGBUS, &sig_act, (struct sigaction *)0);
     441             : #endif
     442           0 :     sigaction(SIGSEGV, &sig_act, (struct sigaction *)0);
     443             : #ifdef SIGSYS
     444           0 :     sigaction(SIGSYS, &sig_act, (struct sigaction *)0);
     445             : #endif
     446             : #endif /* USGISH */
     447             : 
     448             :     /*
     449             :      * now peruse through the list of files.
     450             :      */
     451           0 :     incCollection = create_IncludesCollection();
     452             : 
     453           0 :     for(fp=filelist; *fp; fp++) {
     454             :         struct symhash *includes;
     455           0 :         filecontent = getfile(*fp);
     456           0 :         ip = newinclude(*fp, (char *)NULL);
     457             : 
     458           0 :         includes = hash_copy( maininclist );
     459           0 :         find_includes(filecontent, ip, ip, 0, FALSE, incCollection, includes);
     460           0 :         hash_free( includes );
     461             : 
     462           0 :         freefile(filecontent);
     463           0 :         recursive_pr_include(ip, ip->i_file, base_name(*fp));
     464           0 :         if (printed)
     465           0 :             fwrite("\n\n", 2, 1, stdout);
     466           0 :         recursive_pr_dummy(ip, ip->i_file);
     467           0 :         inc_clean();
     468             :     }
     469           0 :     if (printed)
     470           0 :         printf("\n");
     471             : 
     472           0 :     delete_IncludesCollection(incCollection);
     473             : 
     474           0 :     exit(0);
     475             : }
     476             : 
     477           0 : struct filepointer *getfile(file)
     478             :     char    *file;
     479             : {
     480             :     register int    fd;
     481             :     struct filepointer  *content;
     482             :     struct stat st;
     483             :     off_t       size_backup;
     484             :     ssize_t     bytes_read;
     485             :     unsigned    malloc_size;
     486             : 
     487           0 :     content = (struct filepointer *)malloc(sizeof(struct filepointer));
     488           0 :     if ((fd = open(file, O_RDONLY)) < 0) {
     489           0 :         warning("makedepend:  Cannot open file \"%s\"\n", file);
     490           0 :         content->f_p = content->f_base = content->f_end = (char *)malloc(1);
     491           0 :         *content->f_p = '\0';
     492           0 :         return(content);
     493             :     }
     494           0 :     fstat(fd, &st);
     495             : 
     496           0 :     size_backup = st.st_size;
     497           0 :     malloc_size = size_backup;
     498             :     /* Since off_t usually is larger than unsigned, need to test for
     499             :      * truncation.
     500             :      */
     501           0 :     if ( (off_t)malloc_size != size_backup )
     502             :     {
     503           0 :         close( fd );
     504           0 :         warning("makedepend:  File \"%s\" is too large.\n", file);
     505           0 :         content->f_p = content->f_base = content->f_end = (char *)malloc(1);
     506           0 :         *content->f_p = '\0';
     507           0 :         return(content);
     508             :     }
     509             : 
     510           0 :     content->f_base = (char *)malloc(malloc_size+1);
     511           0 :     if (content->f_base == NULL)
     512           0 :         fatalerr("makedepend:  Cannot allocate memory to process file \"%s\"\n", file);
     513           0 :     if ((bytes_read = read(fd, content->f_base, malloc_size)) < 0)
     514           0 :         if ( st.st_mode & S_IFREG )
     515           0 :             fatalerr("makedepend:  Failed to read file \"%s\"\n", file);
     516             : 
     517           0 :     close(fd);
     518           0 :     content->f_len = bytes_read+1;
     519           0 :     content->f_p = content->f_base;
     520           0 :     content->f_end = content->f_base + bytes_read;
     521           0 :     *content->f_end = '\0';
     522           0 :     content->f_line = 0;
     523           0 :     return(content);
     524             : }
     525             : 
     526           0 : void freefile(fp)
     527             :     struct filepointer  *fp;
     528             : {
     529           0 :     free(fp->f_base);
     530           0 :     free(fp);
     531           0 : }
     532             : 
     533           0 : char *copy(str)
     534             :     register char   *str;
     535             : {
     536           0 :     register char   *p = (char *)malloc(strlen(str) + 1);
     537             : 
     538           0 :     strcpy(p, str);
     539           0 :     return(p);
     540             : }
     541             : 
     542           0 : int match(str, list)
     543             :     register char   *str, **list;
     544             : {
     545             :     register int    i;
     546             : 
     547           0 :     for (i=0; *list; i++, list++)
     548           0 :         if (strcmp(str, *list) == 0)
     549           0 :             return(i);
     550           0 :     return(-1);
     551             : }
     552             : 
     553             : /*
     554             :  * Get the next line.  We only return lines beginning with '#' since that
     555             :  * is all this program is ever interested in.
     556             :  */
     557           0 : char *get_line(filep)
     558             :     register struct filepointer *filep;
     559             : {
     560             :     register char   *p, /* walking pointer */
     561             :             *eof,   /* end of file pointer */
     562             :             *bol;   /* beginning of line pointer */
     563             :     register int    lineno; /* line number */
     564             : 
     565           0 :     p = filep->f_p;
     566           0 :     eof = filep->f_end;
     567           0 :     if (p >= eof)
     568           0 :         return((char *)NULL);
     569           0 :     lineno = filep->f_line;
     570             : 
     571           0 :     for(bol = p--; ++p < eof; ) {
     572           0 :         if (*p == '/' && *(p+1) == '*') { /* consume comments */
     573           0 :             *p++ = ' ', *p++ = ' ';
     574           0 :             while (*p) {
     575           0 :                 if (*p == '*' && *(p+1) == '/') {
     576           0 :                     *p++ = ' ', *p = ' ';
     577           0 :                     break;
     578             :                 }
     579           0 :                 else if (*p == '\n')
     580           0 :                     lineno++;
     581           0 :                 *p++ = ' ';
     582             :             }
     583           0 :             continue;
     584             :         }
     585           0 :         else if (*p == '/' && *(p+1) == '/') { /* consume comments */
     586           0 :             *p++ = ' ', *p++ = ' ';
     587           0 :             while (*p && *p != '\n')
     588           0 :                 *p++ = ' ';
     589           0 :             if ( *p == '\n' )
     590           0 :                 p--;
     591           0 :             lineno++;
     592           0 :             continue;
     593             :         }
     594           0 :         else if (*p == '\\') {
     595           0 :             if (*(p+1) == '\n') {
     596           0 :                 *p = ' ';
     597           0 :                 *(p+1) = ' ';
     598           0 :                 lineno++;
     599             :             }
     600             :         }
     601           0 :         else if (*p == '\n') {
     602           0 :             lineno++;
     603           0 :             if (*bol == '#') {
     604             :                 register char *cp;
     605             : 
     606           0 :                 *p++ = '\0';
     607             :                 /* punt lines with just # (yacc generated) */
     608           0 :                 for (cp = bol+1;
     609           0 :                      *cp && (*cp == ' ' || *cp == '\t'); cp++);
     610           0 :                 if (*cp) goto done;
     611             :             }
     612           0 :             bol = p+1;
     613             :         }
     614             :     }
     615           0 :     if (*bol != '#')
     616           0 :         bol = NULL;
     617             : done:
     618           0 :     filep->f_p = p;
     619           0 :     filep->f_line = lineno;
     620           0 :     return(bol);
     621             : }
     622             : 
     623             : /*
     624             :  * Strip the file name down to what we want to see in the Makefile.
     625             :  * It will have objprefix and objsuffix around it.
     626             :  */
     627           0 : char *base_name(file)
     628             :     register char   *file;
     629             : {
     630             :     register char   *p;
     631             : 
     632           0 :     file = copy(file);
     633           0 :     for(p=file+strlen(file); p>file && *p != '.'; p--) ;
     634             : 
     635           0 :     if (*p == '.')
     636           0 :         *p = '\0';
     637             : 
     638           0 :     while (p > file) {
     639           0 :         if ( *p == '/' ||  *p == '\\') {
     640           0 :             file = p + 1;
     641           0 :             break;
     642             :         };
     643           0 :         p--;
     644             :     };
     645           0 :     return(file);
     646             : }
     647             : 
     648             : #if defined(USG) && !defined(CRAY) && !defined(SVR4)
     649             : int rename (from, to)
     650             :     char *from, *to;
     651             : {
     652             :     (void) unlink (to);
     653             :     if (link (from, to) == 0) {
     654             :     unlink (from);
     655             :     return 0;
     656             :     } else {
     657             :     return -1;
     658             :     }
     659             : }
     660             : #endif /* USGISH */
     661             : 
     662           0 : void redirect(line, makefile)
     663             :     char    *line,
     664             :         *makefile;
     665             : {
     666             :     FILE    *fdout;
     667           0 :     fdout = freopen(makefile, "wb", stdout); // binary mode please
     668           0 :     if (fdout == NULL)
     669           0 :         fatalerr("cannot open \"%s\"\n", makefile);
     670             :     (void) line;
     671             : 
     672             :     // don't need any of that nonsense
     673             : #if 0
     674             :     struct stat st;
     675             :     FILE    *fdin, *fdout;
     676             :     char    backup[ BUFSIZ ],
     677             :         buf[ BUFSIZ ];
     678             :     boolean found = FALSE;
     679             :     int len;
     680             : 
     681             :     /*
     682             :      * if makefile is "-" then let it pour onto stdout.
     683             :      */
     684             :     if (makefile && *makefile == '-' && *(makefile+1) == '\0')
     685             :         return;
     686             : 
     687             :     /*
     688             :      * use a default makefile is not specified.
     689             :      */
     690             :     if (!makefile) {
     691             :         if (stat("Makefile", &st) == 0)
     692             :             makefile = "Makefile";
     693             :         else if (stat("makefile", &st) == 0)
     694             :             makefile = "makefile";
     695             :         else
     696             :             fatalerr("[mM]akefile is not present\n");
     697             :     }
     698             :     else
     699             :         stat(makefile, &st);
     700             :     if ((fdin = fopen(makefile, "r")) == NULL)
     701             :         fatalerr("cannot open \"%s\"\n", makefile);
     702             :     sprintf(backup, "%s.bak", makefile);
     703             :     unlink(backup);
     704             : #if defined(WIN32)
     705             :     fclose(fdin);
     706             : #endif
     707             :     if (rename(makefile, backup) < 0)
     708             :         fatalerr("cannot rename %s to %s\n", makefile, backup);
     709             : #if defined(WIN32)
     710             :     if ((fdin = fopen(backup, "r")) == NULL)
     711             :         fatalerr("cannot open \"%s\"\n", backup);
     712             : #endif
     713             :     if ((fdout = freopen(makefile, "w", stdout)) == NULL)
     714             :         fatalerr("cannot open \"%s\"\n", backup);
     715             :     len = strlen(line);
     716             :     while (!found && fgets(buf, BUFSIZ, fdin)) {
     717             :         if (*buf == '#' && strncmp(line, buf, len) == 0)
     718             :             found = TRUE;
     719             :         fputs(buf, fdout);
     720             :     }
     721             :     if (!found) {
     722             :         if (verbose)
     723             :             warning("Adding new delimiting line \"%s\" and dependencies...\n",
     724             :                 line);
     725             :         puts(line); /* same as fputs(fdout); but with newline */
     726             :     } else if (append) {
     727             :         while (fgets(buf, BUFSIZ, fdin)) {
     728             :         fputs(buf, fdout);
     729             :         }
     730             :     }
     731             :     fflush(fdout);
     732             : #if defined(USGISH) || defined(USE_CHMOD)
     733             :     chmod(makefile, st.st_mode);
     734             : #else
     735             :     fchmod(fileno(fdout), st.st_mode);
     736             : #endif /* USGISH */
     737             :     fclose(fdin);
     738             : #endif
     739           0 : }
     740             : 
     741           0 : void fatalerr(char *msg, ...)
     742             : {
     743             :     va_list args;
     744           0 :     fprintf(stderr, "%s: error:  ", ProgramName);
     745           0 :     va_start(args, msg);
     746           0 :     vfprintf(stderr, msg, args);
     747           0 :     va_end(args);
     748           0 :     exit (1);
     749             : }
     750             : 
     751           0 : void warning(char *msg, ...)
     752             : {
     753             : #ifdef DEBUG_MKDEPEND
     754             :     va_list args;
     755             :     fprintf(stderr, "%s: warning:  ", ProgramName);
     756             :     va_start(args, msg);
     757             :     vfprintf(stderr, msg, args);
     758             :     va_end(args);
     759             : #else
     760             :     (void)msg;
     761             : #endif /* DEBUG_MKDEPEND */
     762           0 : }
     763             : 
     764           0 : void warning1(char *msg, ...)
     765             : {
     766             : #ifdef DEBUG_MKDEPEND
     767             :     va_list args;
     768             :     va_start(args, msg);
     769             :     vfprintf(stderr, msg, args);
     770             :     va_end(args);
     771             : #else
     772             :     (void)msg;
     773             : #endif /* DEBUG_MKDEPEND */
     774           0 : }
     775             : 
     776           0 : void convert_slashes(path)
     777             :     char* path;
     778             : {
     779             : #if defined (WNT)
     780             :     /*
     781             :      * Convert backslashes to slashes
     782             :      */
     783             :     char *ptr;
     784             :     if (native_win_slashes) {
     785             :         for (ptr = (char*)path; *ptr; ++ptr)
     786             :             if (*ptr == '/')
     787             :                 *ptr = '\\';
     788             :     } else {
     789             :         for (ptr = (char*)path; *ptr; ++ptr)
     790             :             if (*ptr == '\\')
     791             :                 *ptr = '/';
     792             :     };
     793             : #else
     794             :     (void)path;
     795             : #endif
     796           0 : }
     797             : 
     798           0 : char* append_slash(path)
     799             :     char* path;
     800             : {
     801             :     char *new_string;
     802           0 :     if ((path[strlen(path) - 1] == '/') || (path[strlen(path) - 1] == '\\')) {
     803           0 :         new_string = path;
     804             :     } else {
     805           0 :         new_string = (char*)malloc(sizeof(char) * (strlen(path) + 2));
     806           0 :         strcpy(new_string, path);
     807           0 :         if (native_win_slashes)
     808           0 :             strcat(new_string, "\\");
     809             :         else
     810           0 :             strcat(new_string, "/");
     811             :     };
     812           0 :     return new_string;
     813             : }
     814             : 
     815             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10