source: golgotha/src/make/deps.cc @ 484

Last change on this file since 484 was 80, checked in by Sam Hocevar, 15 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 2.7 KB
RevLine 
[80]1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9
10enum { MAX_SRC=10000 };
11
12name_table src_files;
13name_table src_deps[MAX_SRC];
14
15int find_src(char *filename)
16{
17  for (int i=0; i<src_files.size(); i++)
18  {
19    if (strcmp(src_files[i],filename)==0)
20      return i;
21  }
22  return -1;
23}
24
25name_table *get_deps(char *filename, name_table *includes)
26{
27  int f=find_src(filename);
28  if (f!=-1)
29    return &src_deps[f];
30  else
31  {
32    FILE *fp=fopen(filename,"rb");
33    if (!fp)
34      return 0;
35    fseek(fp, 0, SEEK_END);
36    int size=ftell(fp);
37    fseek(fp, 0, SEEK_SET);
38   
39    char *mem=(char *)malloc(size+1);
40    fread(mem, 1, size, fp);
41    fclose(fp);
42    mem[size]=0;
43
44
45    int x = src_files.add(strdup(filename));
46    src_deps[x].add(strdup(filename));
47   
48    char *p=mem, name2[100], *s;
49   
50    while (*p)
51    {
52      if (p[0]=='#' &&
53          p[1]=='i' &&
54          p[2]=='n' &&
55          p[3]=='c' &&
56          p[4]=='l' &&
57          p[5]=='u' &&
58          p[6]=='d' &&
59          p[7]=='e' &&
60          p[8]==' ')
61      {
62        p+=9;
63
64        while (*p==' ') p++;
65        if (*p=='"')
66        {
67          p++; s=p;
68          while (*p && *p!='"')
69            p++;
70
71          if (*p)
72          {
73            *p=0;         
74            p++;
75          }
76
77          name_table *ret=get_deps(s, includes);
78
79          for (int j=0; !ret && j<includes->size(); j++)
80          {
81            sprintf(name2,"%s/%s",(*includes)[j],s);
82            ret=get_deps(name2, includes);
83          }
84
85          if (ret)
86          {
87            for (int i=0;i<ret->size(); i++)
88            {
89              int found=0;
90              for (int j=0; j<src_deps[x].size(); j++)
91                if (strcmp(src_deps[x][j],(*ret)[i])==0)
92                  found=1;
93              if (!found)
94                src_deps[x].add((*ret)[i]);
95            }
96          } else
97          {
98            // ignore files with a '~' because they are for name mangled 8.3 systems
99            int t=0;
100            for (char *q=s; *q; q++)
101              if (*q=='~') t=1;             
102            if (!t)
103              fprintf(stderr,"%s : couldn't find include %s\n",filename,s);
104          }
105        }
106      }
107      else p++;
108    }
109
110    free(mem);
111
112    return src_deps+x;
113  }
114}
Note: See TracBrowser for help on using the repository browser.