Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/config/liblist.c

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /config/liblist.c (Version 11.3.0) and /config/liblist.c (Version 10.1.p3)


                                                   >>   1 /* $Id: liblist.c 66368 2012-12-18 09:20:17Z gcosmo $ */
  1                                                     2 
  2 /*                                                  3 /*
  3 Given a "libname.map" file on standard input a      4 Given a "libname.map" file on standard input and a list or directory
  4 of .d dependency files liblist produces:            5 of .d dependency files liblist produces:
  5   a) without -l option, a library list ordered      6   a) without -l option, a library list ordered according to the libname.map,
  6      giving a warning if conflicting dependenc      7      giving a warning if conflicting dependencies are found in the .d files.
  7   b) with -l option, another libname.map, orde      8   b) with -l option, another libname.map, ordered according firstly to the
  8      original libname.map file, then reordered      9      original libname.map file, then reordered according to the dependencies
  9      found in the .d files.  This option is us     10      found in the .d files.  This option is used for compiling the file
 10      libname.map from all the dependencies.        11      libname.map from all the dependencies.
 11   c) with -m <lpath> option, the whole existin     12   c) with -m <lpath> option, the whole existing libraries list ordered
 12      according to the libname.map, where libra     13      according to the libname.map, where libraries are placed in <lpath>.
 13 The .d files are specified in the argument(s).     14 The .d files are specified in the argument(s).
 14 The libname.map is on standard input.              15 The libname.map is on standard input.
 15                                                    16 
 16 Usage:                                             17 Usage:
 17   liblist *.d < libname.map                        18   liblist *.d < libname.map
 18   liblist -d <ddir> < libname.map                  19   liblist -d <ddir> < libname.map
 19   liblist -l *.d < libname.map                     20   liblist -l *.d < libname.map
 20   liblist -ld <ddir> < libname.map                 21   liblist -ld <ddir> < libname.map
 21   liblist -l -d <ddir> < libname.map               22   liblist -l -d <ddir> < libname.map
 22   liblist -m <lpath> < libname.map                 23   liblist -m <lpath> < libname.map
 23 where:                                             24 where:
 24   <ddir>  is a directory name of a directory w     25   <ddir>  is a directory name of a directory which is recursively
 25           searched for dependency files            26           searched for dependency files
 26   <lpath> is the path where libraries are loca     27   <lpath> is the path where libraries are located
 27                                                    28 
 28 Frank Behner, John Allison 13th February 1999.     29 Frank Behner, John Allison 13th February 1999.
 29 */                                                 30 */
 30                                                    31 
 31 #include <stdio.h>                                 32 #include <stdio.h>
 32 #include <string.h>                                33 #include <string.h>
 33 #include <unistd.h>                                34 #include <unistd.h>
 34 #include <dirent.h>                                35 #include <dirent.h>
 35 #include <sys/stat.h>                              36 #include <sys/stat.h>
 36 #include <unistd.h>                                37 #include <unistd.h>
 37 #include <errno.h>                                 38 #include <errno.h>
 38 #include <stdlib.h>                                39 #include <stdlib.h>
 39                                                    40 
 40 #define BUFSIZE 1000000                            41 #define BUFSIZE 1000000
 41 #define TRIGSIZE 1000                              42 #define TRIGSIZE 1000
 42 #define NLIBMAX 200                                43 #define NLIBMAX 200
 43                                                    44 
 44 extern char *optarg;                               45 extern char *optarg;
 45 extern int optind, opterr, optopt;                 46 extern int optind, opterr, optopt;
 46                                                    47 
 47 char** parsedir(char *directory,int *argc)         48 char** parsedir(char *directory,int *argc)
 48 {                                                  49 {
 49   DIR *actualdir;                                  50   DIR *actualdir;
 50   FILE *actualfile;                                51   FILE *actualfile;
 51   struct dirent *entry;                            52   struct dirent *entry; 
 52   char *buffer=0;                                  53   char *buffer=0;
 53   struct stat status;                              54   struct stat status;
 54   char **targv=0,**ptr,**phelp;                    55   char **targv=0,**ptr,**phelp;
 55   int len,targc,s;                                 56   int len,targc,s;
 56                                                    57 
 57   /*Open the actual directory*/                    58   /*Open the actual directory*/
 58   actualdir=opendir(directory);                    59   actualdir=opendir(directory);
 59                                                    60 
 60   if(!actualdir) return targv;                     61   if(!actualdir) return targv;
 61                                                    62 
 62   /*Loop over all entries */                       63   /*Loop over all entries */
 63   for(entry=readdir(actualdir);entry!=NULL;ent     64   for(entry=readdir(actualdir);entry!=NULL;entry=readdir(actualdir))
 64     {                                              65     {
 65       /* Throw away . and .. */                    66       /* Throw away . and .. */
 66       if(strcmp(entry->d_name,".")==0 ||           67       if(strcmp(entry->d_name,".")==0 ||
 67    strcmp(entry->d_name,"..")==0) continue;        68    strcmp(entry->d_name,"..")==0) continue;
 68       /* Obtain the status information of that     69       /* Obtain the status information of that entry */
 69       if(buffer) free(buffer);                     70       if(buffer) free(buffer);
 70       buffer=(char*) malloc((strlen(directory)     71       buffer=(char*) malloc((strlen(directory)+
 71            strlen(entry->d_name)+2)*sizeof(cha     72            strlen(entry->d_name)+2)*sizeof(char));
 72       strcpy(buffer,directory);                    73       strcpy(buffer,directory);
 73       strcat(buffer,"/");                      <<  74       strncat(buffer,"/",1);
 74       strcat(buffer,entry->d_name);            <<  75       strncat(buffer,entry->d_name,strlen(entry->d_name));
 75       s=stat(buffer,&status);                      76       s=stat(buffer,&status);
 76       if(s==0)                                     77       if(s==0)
 77   {                                                78   {
 78     if(S_ISDIR(status.st_mode))                    79     if(S_ISDIR(status.st_mode))
 79       {                                            80       {
 80         /* a directory, so we are going recurs     81         /* a directory, so we are going recursive*/
 81         targc=0;                                   82         targc=0;
 82         ptr=parsedir(buffer,&targc);               83         ptr=parsedir(buffer,&targc);
 83         if(targc)                                  84         if(targc)
 84     {                                              85     {
 85       phelp=targv;                                 86       phelp=targv;
 86       targv=(char**) malloc((*argc+targc)*size     87       targv=(char**) malloc((*argc+targc)*sizeof(char*));
 87       memcpy(targv,phelp,*argc*sizeof(char*));     88       memcpy(targv,phelp,*argc*sizeof(char*));
 88       memcpy(&targv[*argc],ptr,targc*sizeof(ch     89       memcpy(&targv[*argc],ptr,targc*sizeof(char*));
 89       *argc+=targc;                                90       *argc+=targc;
 90       free(phelp);                                 91       free(phelp);
 91       free(ptr);                                   92       free(ptr);
 92     }                                              93     }
 93       }                                            94       }
 94     else if(S_ISREG(status.st_mode))               95     else if(S_ISREG(status.st_mode))
 95       {                                            96       {
 96         /* a regular file is it .d? */             97         /* a regular file is it .d? */
 97         len=strlen(entry->d_name);                 98         len=strlen(entry->d_name);
 98         if(entry->d_name[len-2]=='.' && entry-     99         if(entry->d_name[len-2]=='.' && entry->d_name[len-1]=='d')
 99     {                                             100     {
100       phelp=targv;                                101       phelp=targv;
101       targv=(char**) malloc((*argc+1)*sizeof(c    102       targv=(char**) malloc((*argc+1)*sizeof(char*));
102       memcpy(targv,phelp,*argc*sizeof(char*));    103       memcpy(targv,phelp,*argc*sizeof(char*));
103       targv[*argc]=strdup(buffer);                104       targv[*argc]=strdup(buffer);
104       (*argc)++;                                  105       (*argc)++;
105       free(phelp);                                106       free(phelp);
106     }                                             107     }
107       }                                           108       }
108   }                                               109   }
109       else                                        110       else
110   {                                               111   {
111     fprintf                                       112     fprintf
112       (stderr,                                    113       (stderr,
113        "  No status - perhaps file %s does not    114        "  No status - perhaps file %s does not exist.\n",
114        directory);                                115        directory);
115     exit(1);                                      116     exit(1);
116   }                                               117   }
117     }                                             118     }
118                                                   119 
119   if(buffer) free(buffer);                        120   if(buffer) free(buffer);
120   closedir(actualdir);                            121   closedir(actualdir);
121                                                   122 
122   return targv;                                   123   return targv;
123 }                                                 124 }
124                                                   125     
125                                                   126  
126 int main (int argc, char** argv) {                127 int main (int argc, char** argv) {
127                                                   128 
128   char static buffer[BUFSIZE],*bufferPtr,workb    129   char static buffer[BUFSIZE],*bufferPtr,workbuf[256];
129   char *ptr,*p,**pp,**pp1,**pp2,*directory=0,*    130   char *ptr,*p,**pp,**pp1,**pp2,*directory=0,*libpath=0;
130   char **rargv;                                   131   char **rargv;
131   char *libname=0;                                132   char *libname=0;
132   int i,optl=0,optm=0,swapping,c,rargc;           133   int i,optl=0,optm=0,swapping,c,rargc;
133   FILE *fp;                                       134   FILE *fp;
134                                                   135 
135 #if defined ( _WIN32 ) || defined ( __CYGWIN__    136 #if defined ( _WIN32 ) || defined ( __CYGWIN__ ) || defined ( __CYGWIN32__ )
136   char *ntg4tmp=0,*ntg4tmp1=0;                    137   char *ntg4tmp=0,*ntg4tmp1=0;
137   int nti;                                        138   int nti; 
138 #endif                                            139 #endif
139                                                   140 
140   struct libmap_                                  141   struct libmap_
141     {                                             142     {
142       char *lib;      /* Library name, e.g., G    143       char *lib;      /* Library name, e.g., G4run. */
143       char *trigger;  /* Source directory, e.g    144       char *trigger;  /* Source directory, e.g., source/run/.  */
144       int used;       /* True if used by these    145       int used;       /* True if used by these dependency files.  */
145       char **uses;    /* List of library names    146       char **uses;    /* List of library names which this library uses.  */
146       struct libmap_ *next;                       147       struct libmap_ *next;
147   };                                              148   };
148                                                   149 
149   struct libmap_ *libmap=0,*libmapPtr=0,*libma    150   struct libmap_ *libmap=0,*libmapPtr=0,*libmapPtr1=0,*libmapPtr2=0,
150     *prevPtr1,*prevPtr2,*tmpp,*userLibmapPtr;     151     *prevPtr1,*prevPtr2,*tmpp,*userLibmapPtr;
151                                                   152 
152   while((c=getopt(argc,argv,"ld: m:"))!=EOF)      153   while((c=getopt(argc,argv,"ld: m:"))!=EOF)
153     {                                             154     {
154       switch(c)                                   155       switch(c)
155   {                                               156   {
156   case 'l':                                       157   case 'l':
157     optl=1;                                       158     optl=1;
158     break;                                        159     break;
159   case 'd':                                       160   case 'd':
160     directory=strdup(optarg);                     161     directory=strdup(optarg);
161     break;                                        162     break;
162         case 'm':                                 163         case 'm':
163           optm=1;                                 164           optm=1;
164     libpath=strdup(optarg);                       165     libpath=strdup(optarg);
165           break;                                  166           break;
166   }                                               167   }
167     }                                             168     }
168                                                   169     
169   /*Adjust parameters after parsing options */    170   /*Adjust parameters after parsing options */
170                                                   171 
171   if(optind<argc)                                 172   if(optind<argc)
172     {                                             173     {
173       rargv=&argv[optind];                        174       rargv=&argv[optind];
174       rargc=argc-optind;                          175       rargc=argc-optind;
175     }                                             176     }
176   else                                            177   else
177     {                                             178     {
178       rargv=0;                                    179       rargv=0;
179       rargc=0;                                    180       rargc=0;
180     }                                             181     }
181                                                   182 
182   if(directory)                                   183   if(directory)
183     {                                             184     {
184       if(rargc==0)                                185       if(rargc==0)
185   {                                               186   {
186     rargv=parsedir(directory,&rargc);             187     rargv=parsedir(directory,&rargc);
187   }                                               188   }
188       else                                        189       else
189   {                                               190   {
190     fprintf                                       191     fprintf
191       (stderr,                                    192       (stderr,
192        "  ERROR: If you specify a directory do    193        "  ERROR: If you specify a directory don't also specify files\n");
193     exit(1);                                      194     exit(1);
194   }                                               195   }
195     }                                             196     }
196                                                   197 
197   if(optl)fprintf(stderr,"  Reading library na    198   if(optl)fprintf(stderr,"  Reading library name map file...\n");
198   while (!feof(stdin))                            199   while (!feof(stdin))
199     {                                             200     {
200       /* Get library name... */                   201       /* Get library name... */
201       fgets(buffer,BUFSIZE,stdin);                202       fgets(buffer,BUFSIZE,stdin);
202       if(feof(stdin)) break;                      203       if(feof(stdin)) break;
203       if (strlen(buffer) >= BUFSIZE-1)            204       if (strlen(buffer) >= BUFSIZE-1)
204       {                                           205       {
205          fprintf(stderr,                          206          fprintf(stderr,
206      " Internal ERROR: BUFSIZE too small to re    207      " Internal ERROR: BUFSIZE too small to read library name map file\n");
207    exit(1);                                       208    exit(1);
208       }                                           209       }
209          /* discarded trailing \n, as gets() w    210          /* discarded trailing \n, as gets() was doing */
210       if ( buffer[strlen(buffer)-1] == '\n')      211       if ( buffer[strlen(buffer)-1] == '\n') 
211         {   buffer[strlen(buffer)-1]='\0'; }      212         {   buffer[strlen(buffer)-1]='\0'; }  
212                                                   213 
213       ptr=strtok(buffer,":\n");                   214       ptr=strtok(buffer,":\n");
214                                                   215 
215       /* Check for duplicate names... */          216       /* Check for duplicate names... */
216       for(libmapPtr1=libmap;libmapPtr1;libmapP    217       for(libmapPtr1=libmap;libmapPtr1;libmapPtr1=libmapPtr1->next)
217   {                                               218   {
218     if(strcmp(libmapPtr1->lib,ptr)==0)            219     if(strcmp(libmapPtr1->lib,ptr)==0)
219       {                                           220       {
220         fprintf(stderr,"  ERROR: Duplicate lib    221         fprintf(stderr,"  ERROR: Duplicate library name: %s\n",ptr);
221         fprintf(stderr,                           222         fprintf(stderr,
222           "  Perhaps a duplicate subdirectory     223           "  Perhaps a duplicate subdirectory with"
223           " a GNUmakefile with the same librar    224           " a GNUmakefile with the same library name.\n"
224           );                                      225           );
225         exit(1);                                  226         exit(1);
226       }                                           227       }
227   }                                               228   }
228                                                   229 
229       if(libmap)                                  230       if(libmap)
230   {                                               231   {
231     libmapPtr->next=(struct libmap_*) malloc(s    232     libmapPtr->next=(struct libmap_*) malloc(sizeof(struct libmap_));
232     libmapPtr=libmapPtr->next;                    233     libmapPtr=libmapPtr->next;
233   }                                               234   }
234       else /* First time through anchor libmap    235       else /* First time through anchor libmapPtr to libmap. */
235   {                                               236   {
236     libmap=(struct libmap_*) malloc(sizeof(str    237     libmap=(struct libmap_*) malloc(sizeof(struct libmap_));
237     libmapPtr=libmap;                             238     libmapPtr=libmap;
238   }                                               239   }
239       libmapPtr->next=0;                          240       libmapPtr->next=0;      
240       libmapPtr->lib=strdup(ptr);                 241       libmapPtr->lib=strdup(ptr);
241       libmapPtr->used=0;                          242       libmapPtr->used=0;
242       libmapPtr->uses=(char**)calloc(NLIBMAX,s    243       libmapPtr->uses=(char**)calloc(NLIBMAX,sizeof(char*));
243                                                   244 
244       /* If option -l not specified, fill uses    245       /* If option -l not specified, fill uses list... */
245       if(!optl && !optm)                          246       if(!optl && !optm)
246   {                                               247   {
247     pp=libmapPtr->uses;                           248     pp=libmapPtr->uses;
248     if(ptr)                                       249     if(ptr)
249       {                                           250       {
250         ptr=strtok(NULL," \n");                   251         ptr=strtok(NULL," \n");
251         while (ptr)                               252         while (ptr)
252     {                                             253     {
253       *pp=strdup(ptr);                            254       *pp=strdup(ptr);
254       pp++;                                       255       pp++;
255       ptr=strtok(NULL," \n");                     256       ptr=strtok(NULL," \n");
256     }                                             257     }
257       }                                           258       }
258   }                                               259   }
259                                                   260 
260       if(!optm)                                   261       if(!optm)
261         {                                         262         {
262           /* Get directory name... */             263           /* Get directory name... */
263           fgets(buffer,BUFSIZE,stdin);            264           fgets(buffer,BUFSIZE,stdin);
264     if (strlen(buffer) >= BUFSIZE-1)              265     if (strlen(buffer) >= BUFSIZE-1)
265     {                                             266     {
266              fprintf(stderr,                      267              fprintf(stderr,
267          " Internal ERROR: BUFSIZE too small t    268          " Internal ERROR: BUFSIZE too small to read directory name\n");
268        exit(1);                                   269        exit(1);
269     }                                             270     }
270          /* discarded trailing \n, as gets() w    271          /* discarded trailing \n, as gets() was doing */
271           if ( buffer[strlen(buffer)-1] == '\n    272           if ( buffer[strlen(buffer)-1] == '\n') 
272              {   buffer[strlen(buffer)-1]='\0'    273              {   buffer[strlen(buffer)-1]='\0'; }  
273                                                   274 
274           ptr=strtok(buffer,"/");                 275           ptr=strtok(buffer,"/");
275           if(!ptr)                                276           if(!ptr)
276       {                                           277       {
277         fprintf(stderr,"  ERROR: \"/\" before     278         fprintf(stderr,"  ERROR: \"/\" before \"source\" expected.\n");
278         exit(1);                                  279         exit(1);
279       }                                           280       }
280           while(ptr&&strcmp (ptr,"source"))ptr    281           while(ptr&&strcmp (ptr,"source"))ptr=strtok(NULL,"/");
281           ptr=strtok(NULL,"/");                   282           ptr=strtok(NULL,"/");
282           if(!ptr)                                283           if(!ptr)
283       {                                           284       {
284         fprintf(stderr,"  ERROR: \"source\" ex    285         fprintf(stderr,"  ERROR: \"source\" expected.\n");
285         exit(1);                                  286         exit(1);
286       }                                           287       }
287           libmapPtr->trigger=(char*)malloc(TRI    288           libmapPtr->trigger=(char*)malloc(TRIGSIZE);
288     if(strlen(ptr)>TRIGSIZE)                      289     if(strlen(ptr)>TRIGSIZE)
289           {                                       290           {
290             fprintf(stderr,"  ERROR: String ov    291             fprintf(stderr,"  ERROR: String overflow for: %s\n", ptr);
291             exit(1);                              292             exit(1);
292           }                                       293           }
293           strcpy(libmapPtr->trigger,ptr);         294           strcpy(libmapPtr->trigger,ptr);
294           ptr=strtok(NULL,"/");                   295           ptr=strtok(NULL,"/");
295           while(ptr&&strcmp(ptr,"GNUmakefile")    296           while(ptr&&strcmp(ptr,"GNUmakefile"))
296       {                                           297       {
297         strcat(libmapPtr->trigger,"/");        << 298         strncat(libmapPtr->trigger,"/",1);
298         strcat(libmapPtr->trigger,ptr);        << 299         strncat(libmapPtr->trigger,ptr,strlen(ptr));
299         ptr=strtok(NULL,"/");                     300         ptr=strtok(NULL,"/");
300       }                                           301       }
301           if(!ptr)                                302           if(!ptr)
302       {                                           303       {
303         fprintf                                   304         fprintf
304           (stderr,                                305           (stderr,
305            "  ERROR: \"source/<unique-sub-path    306            "  ERROR: \"source/<unique-sub-path>/GNUmakefile\" expected.\n");
306         exit(1);                                  307         exit(1);
307       }                                           308       }
308   }                                               309   }
309     }                                             310     }
310                                                   311 
311   if(optl)fprintf(stderr,"  Reading dependency    312   if(optl)fprintf(stderr,"  Reading dependency files...\n");
312                                                   313 
313 #if defined ( _WIN32 ) || defined ( __CYGWIN__    314 #if defined ( _WIN32 ) || defined ( __CYGWIN__ ) || defined ( __CYGWIN32__ )
314       ntg4tmp=getenv("G4TMP");                    315       ntg4tmp=getenv("G4TMP");
315       if ( ! ntg4tmp )                            316       if ( ! ntg4tmp ) 
316         {                                         317         {
317            fprintf(stderr,"  ERROR: Cannot fin    318            fprintf(stderr,"  ERROR: Cannot find environment variable G4TMP\n");
318            exit(1);                               319            exit(1);
319         }                                         320         }
320       ntg4tmp1=strdup(ntg4tmp);                   321       ntg4tmp1=strdup(ntg4tmp);
321 #endif                                            322 #endif
322                                                   323 
323   for(i=0;i<rargc;i++)                            324   for(i=0;i<rargc;i++)
324     {                                             325     {
325       fp=fopen(rargv[i],"r");                     326       fp=fopen(rargv[i],"r");
326       fgets(buffer,BUFSIZE,fp);                   327       fgets(buffer,BUFSIZE,fp);
327                                                   328 
328 #if defined ( _WIN32 ) || defined ( __CYGWIN__    329 #if defined ( _WIN32 ) || defined ( __CYGWIN__ ) || defined ( __CYGWIN32__ )
329       ptr=strchr(ntg4tmp1,':');                   330       ptr=strchr(ntg4tmp1,':');
330                                                   331 
331       while ( ptr=strchr(buffer,'\\') ) *ptr='    332       while ( ptr=strchr(buffer,'\\') ) *ptr='/';
332                                                   333  
333       while (ntg4tmp1!=NULL &&  (ptr=strstr(bu    334       while (ntg4tmp1!=NULL &&  (ptr=strstr(buffer,ntg4tmp1))!=NULL )
334         {                                         335         {
335           for(nti=0;nti<strlen(ntg4tmp1);nti++    336           for(nti=0;nti<strlen(ntg4tmp1);nti++) ptr[nti]=' ';
336         }                                         337         }
337 #endif                                            338 #endif
338                                                   339      
339       /* Clip target out of dependency file...    340       /* Clip target out of dependency file... */
340       ptr=strtok(buffer,":");                     341       ptr=strtok(buffer,":");
341                                                   342       
342       /* Look for a "user" library... */          343       /* Look for a "user" library... */
343       for(libmapPtr=libmap;libmapPtr;libmapPtr    344       for(libmapPtr=libmap;libmapPtr;libmapPtr=libmapPtr->next)
344   {                                               345   {
345     if(strlen(libmapPtr->lib)>256)                346     if(strlen(libmapPtr->lib)>256)
346           {                                       347           {
347             fprintf(stderr,"  ERROR: String ov    348             fprintf(stderr,"  ERROR: String overflow for: %s\n", libmapPtr->lib);
348             exit(1);                              349             exit(1);
349           }                                       350           }
350           strcpy(workbuf,libmapPtr->lib);         351           strcpy(workbuf,libmapPtr->lib);
351     /* Add trailing "/" to distinguish track/     352     /* Add trailing "/" to distinguish track/ and tracking/, etc. */
352     strcat(workbuf,"/");                       << 353     strncat(workbuf,"/",1);
353     if(strstr(ptr,workbuf)) break;                354     if(strstr(ptr,workbuf)) break;
354   }                                               355   }
355       if(libmapPtr)                               356       if(libmapPtr)
356   {                                               357   {
357     userLibmapPtr=libmapPtr;                      358     userLibmapPtr=libmapPtr;
358   }                                               359   }
359       else                                        360       else
360   {                                               361   {
361     userLibmapPtr=0;                              362     userLibmapPtr=0;
362   }                                               363   }
363                                                   364 
364       if(!optm)                                   365       if(!optm)
365   {                                               366   {
366     /* Look for a "used" library and add it to    367     /* Look for a "used" library and add it to the "user" uses list... */
367     bufferPtr=strtok(NULL,"\n");  /* Start *af    368     bufferPtr=strtok(NULL,"\n");  /* Start *after* ":". */
368     if (!bufferPtr)                               369     if (!bufferPtr) 
369       {                                           370       {
370         fprintf(stderr,"  WARNING: It seems th    371         fprintf(stderr,"  WARNING: It seems there is nothing after \':\' in dependency file %s.\n", rargv[i]);
371       }                                           372       }
372     else {                                        373     else {
373     do                                            374     do
374       {                                           375       {
375         for(libmapPtr=libmap;libmapPtr;libmapP    376         for(libmapPtr=libmap;libmapPtr;libmapPtr=libmapPtr->next)
376           {                                       377           {
377       /* Look for trigger string. */              378       /* Look for trigger string. */
378             if(strlen(libmapPtr->trigger)>256)    379             if(strlen(libmapPtr->trigger)>256)
379                   {                               380                   {
380                     fprintf(stderr,"  ERROR: S    381                     fprintf(stderr,"  ERROR: String overflow for: %s\n", libmapPtr->trigger);
381                     exit(1);                      382                     exit(1);
382                   }                               383                   }
383                   strcpy(workbuf,libmapPtr->tr    384                   strcpy(workbuf,libmapPtr->trigger);
384       strcat(workbuf,"/include");              << 385       strncat(workbuf,"/include",8);
385       ptr=strstr(bufferPtr,workbuf);              386       ptr=strstr(bufferPtr,workbuf);
386       if(ptr && (userLibmapPtr != libmapPtr))     387       if(ptr && (userLibmapPtr != libmapPtr))
387         {                                         388         {
388           libmapPtr->used=1;                      389           libmapPtr->used=1;
389           if(userLibmapPtr)                       390           if(userLibmapPtr)
390             {                                     391             {
391         for(pp=userLibmapPtr->uses;*pp;pp++)      392         for(pp=userLibmapPtr->uses;*pp;pp++)
392           {                                       393           {
393             if(strcmp(*pp,libmapPtr->lib)==0)b    394             if(strcmp(*pp,libmapPtr->lib)==0)break;
394           }                                       395           }
395         if(!*pp)*pp=libmapPtr->lib;               396         if(!*pp)*pp=libmapPtr->lib;
396             }                                     397             }
397         }                                         398         }
398       /* Also look for library name in case he    399       /* Also look for library name in case header files are
399          placed in temporary directories under    400          placed in temporary directories under a subdirectory
400          with the same name as the library nam    401          with the same name as the library name.  This can
401          happen with Objectivity which makes h    402          happen with Objectivity which makes header files
402          from .ddl files and places them in a     403          from .ddl files and places them in a temporary
403          directory. */                            404          directory. */
404             if(strlen(libmapPtr->lib)>256)        405             if(strlen(libmapPtr->lib)>256)
405                   {                               406                   {
406                     fprintf(stderr,"  ERROR: S    407                     fprintf(stderr,"  ERROR: String overflow for: %s\n", libmapPtr->lib);
407                     exit(1);                      408                     exit(1);
408                   }                               409                   }
409       strcpy(workbuf,libmapPtr->lib);             410       strcpy(workbuf,libmapPtr->lib);
410       strcat(workbuf,"/");                     << 411       strncat(workbuf,"/",1);
411       ptr=strstr(bufferPtr,workbuf);              412       ptr=strstr(bufferPtr,workbuf);
412       if(ptr && (userLibmapPtr != libmapPtr))     413       if(ptr && (userLibmapPtr != libmapPtr))
413         {                                         414         {
414           libmapPtr->used=1;                      415           libmapPtr->used=1;
415           if(userLibmapPtr)                       416           if(userLibmapPtr)
416             {                                     417             {
417         for(pp=userLibmapPtr->uses;*pp;pp++)      418         for(pp=userLibmapPtr->uses;*pp;pp++)
418           {                                       419           {
419             if(strcmp(*pp,libmapPtr->lib)==0)b    420             if(strcmp(*pp,libmapPtr->lib)==0)break;
420           }                                       421           }
421         if(!*pp)*pp=libmapPtr->lib;               422         if(!*pp)*pp=libmapPtr->lib;
422             }                                     423             }
423         }                                         424         }
424           }                                       425           }
425         fgets(buffer,BUFSIZE,fp);                 426         fgets(buffer,BUFSIZE,fp);
426         bufferPtr=buffer;                         427         bufferPtr=buffer;
427                                                   428 
428 #if defined ( _WIN32 ) || defined ( __CYGWIN__    429 #if defined ( _WIN32 ) || defined ( __CYGWIN__ ) || defined ( __CYGWIN32__ )
429         while ( ptr=strchr(buffer,'\\') ) *ptr    430         while ( ptr=strchr(buffer,'\\') ) *ptr='/';
430                                                   431 
431         while (ntg4tmp1 &&  (ptr=strstr(buffer    432         while (ntg4tmp1 &&  (ptr=strstr(buffer,ntg4tmp1)) )
432           {                                       433           {
433       for(nti=0;nti<strlen(ntg4tmp1);nti++) pt    434       for(nti=0;nti<strlen(ntg4tmp1);nti++) ptr[nti]=' ';
434           }                                       435           }
435 #endif                                            436 #endif
436                                                   437 
437       } while(!feof(fp));                         438       } while(!feof(fp));
438     fclose(fp);                                   439     fclose(fp);
439         }                                         440         }
440       }                                           441       }
441     }                                             442     }
442                                                   443 
443 #if defined ( _WIN32 ) || defined ( __CYGWIN__    444 #if defined ( _WIN32 ) || defined ( __CYGWIN__ ) || defined ( __CYGWIN32__ )
444       free(ntg4tmp1);                             445       free(ntg4tmp1);
445 #endif                                            446 #endif
446                                                   447 
447   if(optl) /* This option is used for compilin    448   if(optl) /* This option is used for compiling the file libname.map
448         from all the dependencies. */             449         from all the dependencies. */
449     {                                             450     {
450       fprintf(stderr,"  Checking for circular     451       fprintf(stderr,"  Checking for circular dependencies...\n");
451       for(libmapPtr=libmap;libmapPtr;libmapPtr    452       for(libmapPtr=libmap;libmapPtr;libmapPtr=libmapPtr->next)
452   {                                               453   {
453     for(pp=libmapPtr->uses;*pp;pp++)              454     for(pp=libmapPtr->uses;*pp;pp++)
454       {                                           455       {
455         for(libmapPtr1=libmap;libmapPtr1!=libm    456         for(libmapPtr1=libmap;libmapPtr1!=libmapPtr;
456       libmapPtr1=libmapPtr1->next)                457       libmapPtr1=libmapPtr1->next)
457     {                                             458     {
458       if(strcmp(libmapPtr1->lib,*pp)==0)          459       if(strcmp(libmapPtr1->lib,*pp)==0)
459         {                                         460         {
460           for(pp1=libmapPtr1->uses;*pp1;pp1++)    461           for(pp1=libmapPtr1->uses;*pp1;pp1++)
461       {                                           462       {
462         if(strcmp(*pp1,libmapPtr->lib)==0)brea    463         if(strcmp(*pp1,libmapPtr->lib)==0)break;
463       }                                           464       }
464           if(*pp1)                                465           if(*pp1)
465       {                                           466       {
466         fprintf                                   467         fprintf
467           (stderr,                                468           (stderr,
468            "  WARNING: %s and %s use each othe    469            "  WARNING: %s and %s use each other.\n",
469            libmapPtr->lib,                        470            libmapPtr->lib,
470            libmapPtr1->lib);                      471            libmapPtr1->lib);
471       }                                           472       }
472         }                                         473         }
473       else                                        474       else 
474         {                                         475         {
475           /* Not right yet...                     476           /* Not right yet...
476           for(pp1=libmapPtr1->uses;*pp1;pp1++)    477           for(pp1=libmapPtr1->uses;*pp1;pp1++)
477       {                                           478       {
478         for(libmapPtr0=libmap;libmapPtr0!=libm    479         for(libmapPtr0=libmap;libmapPtr0!=libmapPtr1;
479             libmapPtr0=libmapPtr0->next)          480             libmapPtr0=libmapPtr0->next)
480           {                                       481           {
481             if(libmapPtr0==*pp)                   482             if(libmapPtr0==*pp)
482         {                                         483         {
483           fprintf                                 484           fprintf
484             (stderr,                              485             (stderr,
485              "  WARNING: triangular dependecy:    486              "  WARNING: triangular dependecy:\n"
486              "  %s uses %s uses %s uses %s.\n"    487              "  %s uses %s uses %s uses %s.\n",
487              libmapPtr->lib,                      488              libmapPtr->lib,
488              libmapPtr1->lib,                     489              libmapPtr1->lib,
489              libmapPtr0->lib,                     490              libmapPtr0->lib,
490              libmapPtr->lib);                     491              libmapPtr->lib);
491         }                                         492         }
492           }                                       493           }
493       }                                           494       }
494           */                                      495           */
495         }                                         496         }
496     }                                             497     }
497       }                                           498       }
498   }                                               499   }
499                                                   500 
500       fprintf(stderr,"  Reordering according t    501       fprintf(stderr,"  Reordering according to dependencies...\n");
501       do                                          502       do
502   {                                               503   {
503     swapping=0;                                   504     swapping=0;
504     prevPtr2=0;                                   505     prevPtr2=0;
505     for(libmapPtr=libmap;libmapPtr;libmapPtr=l    506     for(libmapPtr=libmap;libmapPtr;libmapPtr=libmapPtr->next)
506       {                                           507       {
507         for(pp=libmapPtr->uses;*pp;pp++)          508         for(pp=libmapPtr->uses;*pp;pp++)
508     {                                             509     {
509       prevPtr1=0;                                 510       prevPtr1=0;
510       for(libmapPtr1=libmap;libmapPtr1!=libmap    511       for(libmapPtr1=libmap;libmapPtr1!=libmapPtr;
511           libmapPtr1=libmapPtr1->next)            512           libmapPtr1=libmapPtr1->next)
512         {                                         513         {
513           if(strcmp(libmapPtr1->lib,*pp)==0)      514           if(strcmp(libmapPtr1->lib,*pp)==0)
514       {                                           515       {
515         /* Check that 1st doesn't use 2nd... *    516         /* Check that 1st doesn't use 2nd... */
516         for(pp1=libmapPtr1->uses;*pp1;pp1++)      517         for(pp1=libmapPtr1->uses;*pp1;pp1++)
517           {                                       518           {
518             if(strcmp(*pp1,libmapPtr->lib)==0)    519             if(strcmp(*pp1,libmapPtr->lib)==0)break;
519           }                                       520           }
520         if(!*pp1) /* If not... */                 521         if(!*pp1) /* If not... */
521           {                                       522           {
522             swapping=1;                           523             swapping=1;
523             /* Make previous of 1st now point     524             /* Make previous of 1st now point to 2nd... */
524             if(prevPtr1)                          525             if(prevPtr1)
525         {                                         526         {
526           prevPtr1->next=libmapPtr;               527           prevPtr1->next=libmapPtr;
527         }                                         528         }
528             else                                  529             else
529         {                                         530         {
530           libmap=libmapPtr;                       531           libmap=libmapPtr;
531         }                                         532         }
532             /* Make 2nd now point to what 1st     533             /* Make 2nd now point to what 1st did, unless
533          it's adjacent, in which case make it     534          it's adjacent, in which case make it point
534          to 1st itself... */                      535          to 1st itself... */
535             tmpp=libmapPtr->next;                 536             tmpp=libmapPtr->next;
536             if(libmapPtr1->next==libmapPtr)       537             if(libmapPtr1->next==libmapPtr)
537         {                                         538         {
538           libmapPtr->next=libmapPtr1;             539           libmapPtr->next=libmapPtr1;
539         }                                         540         }
540             else                                  541             else
541         {                                         542         {
542           libmapPtr->next=libmapPtr1->next;       543           libmapPtr->next=libmapPtr1->next;
543         }                                         544         }
544             /* Make previous of 2nd point to 1    545             /* Make previous of 2nd point to 1st, unless
545          it's adjacent, in which case leave it    546          it's adjacent, in which case leave it... */
546             if(libmapPtr1->next!=libmapPtr)       547             if(libmapPtr1->next!=libmapPtr)
547         {                                         548         {
548           prevPtr2->next=libmapPtr1;              549           prevPtr2->next=libmapPtr1;
549         }                                         550         }
550             /* Make 1st now point to what 2nd     551             /* Make 1st now point to what 2nd did... */
551             libmapPtr1->next=tmpp;                552             libmapPtr1->next=tmpp;
552             break;                                553             break;
553           }                                       554           }
554       }                                           555       }
555           prevPtr1=libmapPtr1;                    556           prevPtr1=libmapPtr1;
556         }                                         557         }
557       if(swapping)break;                          558       if(swapping)break;
558     }                                             559     }
559         prevPtr2=libmapPtr;                       560         prevPtr2=libmapPtr;
560         if(swapping)break;                        561         if(swapping)break;
561       }                                           562       }
562   }while(swapping);                               563   }while(swapping);
563                                                   564 
564       fprintf(stderr,"  Writing new library ma    565       fprintf(stderr,"  Writing new library map file...\n");
565       for(libmapPtr=libmap;libmapPtr;libmapPtr    566       for(libmapPtr=libmap;libmapPtr;libmapPtr=libmapPtr->next)
566   {                                               567   {
567     printf("%s:",libmapPtr->lib);                 568     printf("%s:",libmapPtr->lib);
568     for(pp=libmapPtr->uses;*pp;pp++)              569     for(pp=libmapPtr->uses;*pp;pp++)
569       {                                           570       {
570         printf(" %s",*pp);                        571         printf(" %s",*pp);
571       }                                           572       }
572     printf("\n");                                 573     printf("\n");
573     printf("source/%s/GNUmakefile\n",libmapPtr    574     printf("source/%s/GNUmakefile\n",libmapPtr->trigger);
574   }                                               575   }
575     }                                             576     }
576   else if (optm)                                  577   else if (optm)
577     {                                             578     {
578       /* create tmp. string libname */            579       /* create tmp. string libname */ 
579       int libname_usable_size=24;                 580       int libname_usable_size=24;
580       if ( ! libname ) libname=malloc(libname_    581       if ( ! libname ) libname=malloc(libname_usable_size+16);
581                                                   582 
582       /* Write out full library list... */        583       /* Write out full library list... */      
583       for(libmapPtr=libmap;libmapPtr;libmapPtr    584       for(libmapPtr=libmap;libmapPtr;libmapPtr=libmapPtr->next)
584       {                                           585       {
585   if ( strlen(libpath)+strlen(libmapPtr->lib)     586   if ( strlen(libpath)+strlen(libmapPtr->lib) > libname_usable_size ) {
586     libname_usable_size=(strlen(libpath)+strle    587     libname_usable_size=(strlen(libpath)+strlen(libmapPtr->lib))*2;
587     free(libname);                                588     free(libname);
588     libname=malloc(libname_usable_size+16);       589     libname=malloc(libname_usable_size+16);
589   }                                               590   }
590         /* Check existance of libraries and pr    591         /* Check existance of libraries and print out only installed ones */
591                                                   592     
592                                                   593   
593   snprintf(libname, libname_usable_size+16, "% << 594   sprintf(libname, "%s/lib%s.a", libpath, libmapPtr->lib);
594         if (access(libname,R_OK))                 595         if (access(libname,R_OK))
595   {                                               596   {
596     snprintf(libname, libname_usable_size+16,  << 597     sprintf(libname, "%s/lib%s.so", libpath, libmapPtr->lib);
597           if (!access(libname,R_OK))              598           if (!access(libname,R_OK))
598     {                                             599     {
599             printf("-l%s ",libmapPtr->lib);       600             printf("-l%s ",libmapPtr->lib);
600     }                                             601     }
601           else  /* case MacOS .dylib */           602           else  /* case MacOS .dylib */
602           {                                       603           {
603       snprintf(libname, libname_usable_size+16 << 604       sprintf(libname, "%s/lib%s.dylib", libpath, libmapPtr->lib);
604             if (!access(libname,R_OK))            605             if (!access(libname,R_OK))
605       {                                           606       {
606               printf("-l%s ",libmapPtr->lib);     607               printf("-l%s ",libmapPtr->lib);
607       }                                           608       }
608           }                                       609           }
609   }                                               610   }
610         else                                      611         else
611   {                                               612   {
612           printf("-l%s ",libmapPtr->lib);         613           printf("-l%s ",libmapPtr->lib);
613   }                                               614   }
614   libmapPtr=libmapPtr->next;                      615   libmapPtr=libmapPtr->next;
615       }                                           616       }
616     }                                             617     }
617   else                                            618   else
618     {                                             619     {
619       /* Add dependent libraries... */            620       /* Add dependent libraries... */
620       for(libmapPtr=libmap;libmapPtr;libmapPtr    621       for(libmapPtr=libmap;libmapPtr;libmapPtr=libmapPtr->next)
621   {                                               622   {
622     if(libmapPtr->used)                           623     if(libmapPtr->used)
623       {                                           624       {
624         for(pp=libmapPtr->uses;*pp;pp++)          625         for(pp=libmapPtr->uses;*pp;pp++)
625     {                                             626     {
626       for(libmapPtr1=libmap;libmapPtr1;libmapP    627       for(libmapPtr1=libmap;libmapPtr1;libmapPtr1=libmapPtr1->next)
627         {                                         628         {
628           if(strcmp(libmapPtr1->lib,*pp)==0)      629           if(strcmp(libmapPtr1->lib,*pp)==0)
629       {                                           630       {
630         libmapPtr1->used=1;                       631         libmapPtr1->used=1;
631       }                                           632       }
632         }                                         633         }
633     }                                             634     }       
634       }                                           635       }
635   }                                               636   }
636                                                   637 
637       /* Write out library list... */             638       /* Write out library list... */
638       for(libmapPtr=libmap;libmapPtr;libmapPtr    639       for(libmapPtr=libmap;libmapPtr;libmapPtr=libmapPtr->next)
639   {                                               640   {
640     if(libmapPtr->used)                           641     if(libmapPtr->used)
641       {                                           642       {
642         printf("-l%s ",libmapPtr->lib);           643         printf("-l%s ",libmapPtr->lib);
643       }                                           644       }
644   }                                               645   }
645     }                                             646     }
646                                                   647       
647   exit(0);                                        648   exit(0);
648                                                   649   
649 }                                                 650 }
650                                                   651