summaryrefslogtreecommitdiff
path: root/src/depend
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2009-06-22 23:57:33 +0000
committerglx <glx@openttd.org>2009-06-22 23:57:33 +0000
commite6af53ea01394cbe3c67a07191fe9eaa251460d7 (patch)
treeb71e5a00ac64423ba968a97262cc82807129bdc4 /src/depend
parentd703f0c3b527f1c1f324875762293929c6fbb932 (diff)
downloadopenttd-e6af53ea01394cbe3c67a07191fe9eaa251460d7.tar.xz
(svn r16629) -Fix: depend hang on solaris
-Fix: depend do not append delimiter string before deps for non empty files -Add: support for -s option (starting string delimiter)
Diffstat (limited to 'src/depend')
-rw-r--r--src/depend/depend.cpp38
1 files changed, 27 insertions, 11 deletions
diff --git a/src/depend/depend.cpp b/src/depend/depend.cpp
index ce42f1345..fda8f94c6 100644
--- a/src/depend/depend.cpp
+++ b/src/depend/depend.cpp
@@ -812,6 +812,7 @@ int main(int argc, char *argv[])
bool ignorenext = true;
char *filename = NULL;
char *ext = NULL;
+ char *delimiter = NULL;
bool append = false;
bool verbose = false;
@@ -852,6 +853,11 @@ int main(int argc, char *argv[])
ext = strdup(&argv[i][2]);
continue;
}
+ /* Starting string delimiter */
+ if (strncmp(argv[i], "-s", 2) == 0) {
+ if (delimiter != NULL) continue;
+ delimiter = strdup(&argv[i][2]);
+ }
/* Verbose */
if (strncmp(argv[i], "-v", 2) == 0) verbose = true;
continue;
@@ -862,6 +868,9 @@ int main(int argc, char *argv[])
/* Default output file is Makefile */
if (filename == NULL) filename = strdup("Makefile");
+ /* Default delimiter string */
+ if (delimiter == NULL) delimiter = strdup("# DO NOT DELETE");
+
char backup[PATH_MAX];
strcpy(backup, filename);
strcat(backup, ".bak");
@@ -881,18 +890,25 @@ int main(int argc, char *argv[])
fclose(src);
}
- FILE *dst = fopen(backup, "wb");
- if (content != NULL) fwrite(content, 1, size, dst);
- fclose(dst);
+ FILE *dst = fopen(filename, "w");
+ bool found_delimiter = false;
+
+ if (size != 0) {
+ src = fopen(backup, "wb");
+ fwrite(content, 1, size, src);
+ fclose(src);
- /* Then append it to the real file. */
- src = fopen(backup, "r");
- dst = fopen(filename, "w");
- while (fgets(content, size, src) != NULL) {
- fputs(content, dst);
- if (!append && !strncmp(content, "# DO NOT DELETE", 15)) break;
+ /* Then append it to the real file. */
+ src = fopen(backup, "rb");
+ while (fgets(content, size, src) != NULL) {
+ fputs(content, dst);
+ if (!strncmp(content, delimiter, strlen(delimiter))) found_delimiter = true;
+ if (!append && found_delimiter) break;
+ }
+ fclose(src);
}
- if (ftell(src) == 0) fprintf(dst, "\n# DO NOT DELETE\n");
+ if (!found_delimiter) fprintf(dst, "\n%s\n", delimiter);
+
for (StringMap::iterator it = _files.begin(); it != _files.end(); it++) {
for (StringSet::iterator h = it->second->begin(); h != it->second->end(); h++) {
fprintf(dst, "%s: %s\n", it->first, *h);
@@ -901,8 +917,8 @@ int main(int argc, char *argv[])
/* Clean up our mess. */
fclose(dst);
- fclose(src);
+ free(delimiter);
free(filename);
free(ext);
free(content);