# ------------------------------------------------------------------------------
# pre.cpp |   77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
# pre.l   |   42 ++++++++++++++++++++++++++++++++-
# 2 files changed, 109 insertions(+), 10 deletions(-)
# ------------------------------------------------------------------------------
Index: src/pre.cpp
Prereq:  2.91 
--- doxygen-1.4.6/src/pre.cpp	2005-12-27 20:24:42.000000000 +0000
+++ doxygen-1.4.6-patch/src/pre.cpp	2006-01-17 23:07:10.000000000 +0000
@@ -26,8 +26,7 @@
 #define YY_FLEX_MINOR_VERSION 5
 
 #include <stdio.h>
-#include <unistd.h>
-
+#include <errno.h>
 
 /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
 #ifdef c_plusplus
@@ -40,6 +39,9 @@
 #ifdef __cplusplus
 
 #include <stdlib.h>
+#ifndef _WIN32
+#include <unistd.h>
+#endif
 
 /* Use prototypes in function declarations. */
 #define YY_USE_PROTOS
@@ -79,6 +81,7 @@
 #define YY_PROTO(proto) ()
 #endif
 
+
 /* Returned upon end-of-file. */
 #define YY_NULL 0
 
@@ -2485,7 +2488,7 @@
   //printf("expandExpression(%s,%s)\n",expr.data(),rest ? rest->data() : 0);
   QCString macroName;
   QCString expMacro;
-  int i=pos,l,p,len;
+  int i=pos,l,p,len = 0;
   while ((p=getNextId(expr,i,&l))!=-1) // search for an macro name
   {
     bool replaced=FALSE;
@@ -3129,9 +3132,20 @@
 			YY_FATAL_ERROR( "input in flex scanner failed" ); \
 		result = n; \
 		} \
-	else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
-		  && ferror( yyin ) ) \
-		YY_FATAL_ERROR( "input in flex scanner failed" );
+	else \
+		{ \
+		errno=0; \
+		while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
+			{ \
+			if( errno != EINTR) \
+				{ \
+				YY_FATAL_ERROR( "input in flex scanner failed" ); \
+				break; \
+				} \
+			errno=0; \
+			clearerr(yyin); \
+			} \
+		}
 #endif
 
 /* No semi-colon after return; correct usage is to write "yyterminate();" -
@@ -3180,7 +3194,7 @@
 YY_DECL
 	{
 	register yy_state_type yy_current_state;
-	register char *yy_cp = NULL, *yy_bp = NULL;
+	register char *yy_cp, *yy_bp;
 	register int yy_act;
 
 #line 1247 "pre.l"
@@ -5405,6 +5419,15 @@
 	}
 
 
+#ifndef _WIN32
+#include <unistd.h>
+#else
+#ifndef YY_ALWAYS_INTERACTIVE
+#ifndef YY_NEVER_INTERACTIVE
+extern int isatty YY_PROTO(( int ));
+#endif
+#endif
+#endif
 
 #ifdef YY_USE_PROTOS
 void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
@@ -5822,6 +5845,19 @@
   delete g_pathList; g_pathList=0;
 }
 
+#if defined(_WIN32)
+/*
+ * pipes do not work well enough for filters.
+ * But a temporary file works.
+ * (tested with Visual Studio 6 sp6 with Windows XP sp1).
+ */
+char *myTempName()
+{
+  char *dir = getenv("TEMP");
+  char *name = tempnam(dir, "doxygen");
+  return name;
+}
+#endif
 
 void preprocessFile(const char *fileName,BufStr &output)
 {
@@ -5946,6 +5982,9 @@
   }
  
   QCString inputFilter = getFileFilter(fileName);
+#if defined(_WIN32)
+  char *my_file = 0;
+#endif
   if (inputFilter.isEmpty())
   {
     preYYin = fopen(fileName,"r");
@@ -5955,6 +5994,20 @@
       return;
     }
   }
+#if defined(_WIN32)
+  else if ((my_file = myTempName()) != 0)
+  {
+    QCString cmd = inputFilter+" \""+fileName+"\" \"" + my_file + "\"";
+    Debug::print(Debug::ExtCmd,0,"Executing filter(`%s`)\n", cmd.data());
+    system(cmd);
+    preYYin = fopen(my_file, "r");
+    if (!preYYin)
+    {
+      err("Error: could not execute filter %s\n",cmd.data());
+      return;
+    }
+  }
+#endif // _WIN32
   else
   {
     QCString cmd = inputFilter+" \""+fileName+"\"";
@@ -5978,9 +6031,17 @@
   preYYlex();
   if (inputFilter.isEmpty())
     fclose(preYYin);
+#if defined(_WIN32)
+  else if (my_file != 0)
+  {
+    fclose(preYYin);
+    remove(my_file);
+    free(my_file);
+  }
+#endif
   else
     pclose(preYYin);
-  
+ 
   if (Debug::isFlagSet(Debug::Preprocessor))
   {
     char *orgPos=output.data()+orgOffset;
Index: src/pre.l
--- doxygen-1.4.6/src/pre.l	2005-12-27 18:04:40.000000000 +0000
+++ doxygen-1.4.6-patch/src/pre.l	2006-01-17 22:33:29.000000000 +0000
@@ -719,7 +719,7 @@
   //printf("expandExpression(%s,%s)\n",expr.data(),rest ? rest->data() : 0);
   QCString macroName;
   QCString expMacro;
-  int i=pos,l,p,len;
+  int i=pos,l,p,len = 0;
   while ((p=getNextId(expr,i,&l))!=-1) // search for an macro name
   {
     bool replaced=FALSE;
@@ -2220,6 +2220,19 @@
   delete g_pathList; g_pathList=0;
 }
 
+#if defined(_WIN32)
+/*
+ * pipes do not work well enough for filters.
+ * But a temporary file works.
+ * (tested with Visual Studio 6 sp6 with Windows XP sp1).
+ */
+char *myTempName()
+{
+  char *dir = getenv("TEMP");
+  char *name = tempnam(dir, "doxygen");
+  return name;
+}
+#endif
 
 void preprocessFile(const char *fileName,BufStr &output)
 {
@@ -2344,6 +2357,9 @@
   }
  
   QCString inputFilter = getFileFilter(fileName);
+#if defined(_WIN32)
+  char *my_file = 0;
+#endif
   if (inputFilter.isEmpty())
   {
     preYYin = fopen(fileName,"r");
@@ -2353,6 +2369,20 @@
       return;
     }
   }
+#if defined(_WIN32)
+  else if ((my_file = myTempName()) != 0)
+  {
+    QCString cmd = inputFilter+" \""+fileName+"\" \"" + my_file + "\"";
+    Debug::print(Debug::ExtCmd,0,"Executing filter(`%s`)\n", cmd.data());
+    system(cmd);
+    preYYin = fopen(my_file, "r");
+    if (!preYYin)
+    {
+      err("Error: could not execute filter %s\n",cmd.data());
+      return;
+    }
+  }
+#endif // _WIN32
   else
   {
     QCString cmd = inputFilter+" \""+fileName+"\"";
@@ -2376,9 +2406,17 @@
   preYYlex();
   if (inputFilter.isEmpty())
     fclose(preYYin);
+#if defined(_WIN32)
+  else if (my_file != 0)
+  {
+    fclose(preYYin);
+    remove(my_file);
+    free(my_file);
+  }
+#endif
   else
     pclose(preYYin);
-  
+ 
   if (Debug::isFlagSet(Debug::Preprocessor))
   {
     char *orgPos=output.data()+orgOffset;
