10 static char *concat();
11 static char *concat3();
12 static char *concat4();
13 static int onlyonedir;
14 static int atleastone;
15 static char *fixeddirs, *origdirs;
17 /* Convert all /'s to \'s */
24 for (i=0; dirname[i]; i++)
25 if (dirname [i] == '/')
31 /* Examine each directory component of a path and create the directory */
37 char *ndirpath = strdup (dirpath);
44 bp = strchr (fp, '\\');
57 /* Construct a relative directory path from a given path by removing the
58 leading slash, if it exists and changing a drive letter from X: to X-. */
64 char *newname = strdup (olddirname);
66 if ((strlen (newname) >= 2)
67 && (isalpha (newname[0]) && newname[1] == ':'))
69 else if ((strlen (newname) >= 1)
70 && (newname [0] == '/' || newname [0] == '\\'))
71 newname = &newname[1];
77 /* Run the sed script on one header file. If no modifications were made, then
78 delete the newly created file. */
81 doheader (oneheader, outheader, oldsize)
82 char *oneheader, *outheader;
85 char *newbuff, *oldbuff;
86 char *newheader = concat3 ("include", "\\", newname (outheader));
87 struct _stat newstatbuf;
91 system (concat4 ("sed -f fixinc-nt.sed ", oneheader, " > ", newheader));
92 _stat (newheader, &newstatbuf);
93 if (oldsize != newstatbuf.st_size)
96 printf ("Fixing: %s\n", oneheader);
99 oldbuff = malloc (oldsize);
100 newbuff = malloc (newstatbuf.st_size);
101 olddesc = open (oneheader, _O_RDONLY | _O_BINARY);
102 newdesc = open (newheader, _O_RDONLY | _O_BINARY);
103 read (olddesc, oldbuff, oldsize);
104 read (newdesc, newbuff, newstatbuf.st_size);
107 for (i=0; i<oldsize; i++)
109 if (oldbuff [i] != newbuff [i])
114 printf ("Fixing: %s\n", oneheader);
125 /* Examine the contents of a directory and call doheader () for a regular file
126 and recursively call dodir () for an enclosed directory. */
129 dodir (indir, outdir)
130 char *indir, *outdir;
134 struct _stat statbuf;
135 char *intempbuf, *outtempbuf;
137 dir = opendir (indir);
140 mkdirpath (concat3 ("include", "\\", newname (outdir)));
141 while ((dire = readdir (dir)))
143 if (dire->d_name[0] == '.')
146 intempbuf = slash2slash (concat3 (indir, "\\", dire->d_name));
147 outtempbuf = slash2slash (concat3 (outdir, "\\", dire->d_name));
148 _stat (intempbuf, &statbuf);
150 /* If directory ... */
151 if (statbuf.st_mode & _S_IFDIR)
152 dodir (intempbuf, outtempbuf);
154 /* If regular file ... */
155 if (statbuf.st_mode & _S_IFREG)
156 doheader (intempbuf, outtempbuf, statbuf.st_size);
162 /* Retrieve the value of the Include environment variable, copy it into a
163 temporary and append a semi-colon for book-keeping purposes. Then call
164 dodir () for each complete directory that is named therein. If there is
165 only one directory, then direct the output to use include\. as the
166 root instead of include/<directory path>, where <directory path> is a path
167 constructed from the path named in the Include environment variable.
168 I.e. if Include=C:\MSTOOLS\Include;D:\MSVC20\Include then the modified
169 header files will be in include\C-\MSTOOLS\Include and
170 include\D-\MSVC20\Include. However if Include=C:\MSTOOLS\Include then the
171 modified files will be in include\. */
176 char *fp, *bp, *foobar;
177 char *incvar = getenv ("Include");
179 struct _stat statbuf;
181 if (incvar == NULL) return 0;
183 varlen = strlen (incvar);
184 foobar = (char *) malloc (varlen + 2);
186 strcpy (foobar, incvar);
187 foobar = slash2slash (foobar);
188 if (foobar [varlen-1] != ';') strcat (foobar, ";");
191 if (strchr (fp, ';') == strrchr (fp, ';'))
196 fixeddirs = strdup(".\\include");
197 origdirs = strdup("");
201 bp = strchr (fp, ';');
205 _stat (fp, &statbuf);
206 if (statbuf.st_mode & _S_IFDIR)
213 if (atleastone && !onlyonedir)
215 origdirs = concat3 (origdirs, ";", fp);
216 fixeddirs = concat3 (fixeddirs, ";",
217 concat3 (".\\include", "\\", newname(fp)));
223 printf ("set C_Include_Path=%s%s\n", fixeddirs, origdirs);
227 /* Utility function that mallocs space and concatenates two strings. */
233 int len1 = strlen (s1);
234 int len2 = strlen (s2);
235 char *result = malloc (len1 + len2 + 1);
238 strcpy (result + len1, s2);
239 *(result + len1 + len2) = 0;
244 /* Utility function that concatenates three strings. */
250 return concat (concat (s1, s2), s3);
253 /* Utility function that concatenates four strings. */
256 concat4 (s1, s2, s3, s4)
257 char *s1, *s2, *s3, *s4;
259 return concat (concat (s1, s2), concat (s3, s4));