summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Slice/Preprocessor.cpp118
-rw-r--r--cpp/src/slice2cpp/Main.cpp2
-rw-r--r--cpp/src/slice2cs/Main.cpp2
-rw-r--r--cpp/src/slice2freezej/Main.cpp2
-rw-r--r--cpp/src/slice2java/Main.cpp2
5 files changed, 100 insertions, 26 deletions
diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp
index b88f2e53d11..6d1e8f233c2 100644
--- a/cpp/src/Slice/Preprocessor.cpp
+++ b/cpp/src/Slice/Preprocessor.cpp
@@ -85,7 +85,7 @@ Slice::Preprocessor::preprocess(bool keepComments)
}
void
-Slice::Preprocessor::printMakefileDependencies(const string& suffix)
+Slice::Preprocessor::printMakefileDependencies(Language lang)
{
if(!checkInputFile())
{
@@ -101,40 +101,114 @@ Slice::Preprocessor::printMakefileDependencies(const string& suffix)
cmd += " -M " + _args + " " + _fileName;
- //
- // Change the suffix for non-C++ dependency files (such as for C#)
- //
- const char* cSuffix = suffix.c_str();
-
#ifdef _WIN32
FILE* cppHandle = _popen(cmd.c_str(), "r");
#else
FILE* cppHandle = popen(cmd.c_str(), "r");
#endif
- char buf[1024];
- while(fgets(buf, sizeof(buf), cppHandle) != NULL)
+ switch(lang)
{
- char* dot;
- char* colon = strchr(buf, ':');
- if(colon != NULL)
+ case CPlusPlus:
{
- *colon = '\0';
- dot = strrchr(buf, '.');
- *colon = ':';
- if(dot != NULL)
+ char buf[1024];
+ while(fgets(buf, sizeof(buf), cppHandle) != NULL)
{
- if(strncmp(dot, ".cpp:", 5) == 0)
+ fputs(buf, stdout);
+ }
+ break;
+ }
+ case Java:
+ {
+ //
+ // Remove leading "<file>.cpp:" and make the first following
+ // file the dependent. For example, "x.cpp: x.ice y.ice"
+ // is rewritten as "x.ice: y.ice".
+ //
+ char buf[1024];
+ while(fgets(buf, sizeof(buf), cppHandle) != NULL)
+ {
+ bool needNewline = false;
+ char *p = buf;
+ char* pos = strchr(buf, ':'); // Find first colon.
+ if(pos != NULL)
+ {
+ *pos = '\0'; // Find last dot preceding colon.
+ char* pos2 = strrchr(buf, '.');
+ *pos = ':';
+ if(pos2 != NULL)
+ {
+ if(strncmp(pos2, ".cpp:", 5) == 0) // Check for ".cpp:".
+ {
+ while(isspace(*++pos)) // Move pos to first non-space char following colon.
+ {
+ ;
+ }
+ char* pos2 = pos;
+ while(!isspace(*++pos2)) // Move pos2 to first space char following pos.
+ {
+ ;
+ }
+ *pos2 = '\0';
+ while(isspace(*++pos2)) // Move pos2 to next non-space char.
+ {
+ ;
+ }
+ if(*pos2 == '\0')
+ {
+ continue;
+ }
+ needNewline = *pos2 == '\0'; // Don't lose trailing newline.
+ fputs(pos, stdout); // Write first file name following colon.
+ fputs(": ", stdout);
+ p = pos2;
+ }
+ }
+ }
+ fputs(p, stdout);
+ if(needNewline)
{
- *dot = '\0';
- fputs(buf, stdout);
- fputs(cSuffix, stdout);
- fputs(colon, stdout);
- continue;
+ fputs("\n", stdout);
}
}
+ break;
+ }
+ case CSharp:
+ {
+ //
+ // Change .cpp suffix to .cs suffix.
+ //
+ char buf[1024];
+ while(fgets(buf, sizeof(buf), cppHandle) != NULL)
+ {
+ char* dot;
+ char* colon = strchr(buf, ':');
+ if(colon != NULL)
+ {
+ *colon = '\0';
+ dot = strrchr(buf, '.');
+ *colon = ':';
+ if(dot != NULL)
+ {
+ if(strncmp(dot, ".cpp:", 5) == 0)
+ {
+ *dot = '\0';
+ fputs(buf, stdout);
+ fputs(".cs", stdout);
+ fputs(colon, stdout);
+ continue;
+ }
+ }
+ }
+ fputs(buf, stdout);
+ }
+ break;
+ }
+ default:
+ {
+ abort();
+ break;
}
- fputs(buf, stdout);
}
}
diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp
index 9655c1c2068..a8dd55c3403 100644
--- a/cpp/src/slice2cpp/Main.cpp
+++ b/cpp/src/slice2cpp/Main.cpp
@@ -246,7 +246,7 @@ main(int argc, char* argv[])
if(depend)
{
Preprocessor icecpp(argv[0], argv[idx], cppArgs);
- icecpp.printMakefileDependencies();
+ icecpp.printMakefileDependencies(Preprocessor.CPlusPlus);
}
else
{
diff --git a/cpp/src/slice2cs/Main.cpp b/cpp/src/slice2cs/Main.cpp
index d8262899dce..583c0aad011 100644
--- a/cpp/src/slice2cs/Main.cpp
+++ b/cpp/src/slice2cs/Main.cpp
@@ -209,7 +209,7 @@ main(int argc, char* argv[])
if(depend)
{
Preprocessor icecpp(argv[0], argv[idx], cppArgs);
- icecpp.printMakefileDependencies(".cs");
+ icecpp.printMakefileDependencies(Preprocessor::CSharp);
}
else
{
diff --git a/cpp/src/slice2freezej/Main.cpp b/cpp/src/slice2freezej/Main.cpp
index 6fb84317128..129e52f0162 100644
--- a/cpp/src/slice2freezej/Main.cpp
+++ b/cpp/src/slice2freezej/Main.cpp
@@ -870,7 +870,7 @@ main(int argc, char* argv[])
if(depend)
{
Preprocessor icecpp(argv[0], argv[idx], cppArgs);
- icecpp.printMakefileDependencies();
+ icecpp.printMakefileDependencies(Preprocessor::Java);
}
else
{
diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp
index 227652a4abc..fbfbdcdc0ed 100644
--- a/cpp/src/slice2java/Main.cpp
+++ b/cpp/src/slice2java/Main.cpp
@@ -209,7 +209,7 @@ main(int argc, char* argv[])
if(depend)
{
Preprocessor icecpp(argv[0], argv[idx], cppArgs);
- icecpp.printMakefileDependencies(".java");
+ icecpp.printMakefileDependencies(Preprocessor::Java);
}
else
{