]> git.saurik.com Git - wxWidgets.git/blobdiff - contrib/src/applet/prepinclude.cpp
corrected assert even better
[wxWidgets.git] / contrib / src / applet / prepinclude.cpp
index 74d85e5962818d3dcb73be2defa41e417c66b035..bf03a84ef865b339df0807b58301dbc26c479942 100644 (file)
 *
 ****************************************************************************/
 
 *
 ****************************************************************************/
 
-// For compilers that support precompilation
-#include "wx/wxprec.h"
-//#include "wx/file.h"
-#include "wx/filesys.h"
 // Include private headers
 #include "wx/applet/prepinclude.h"
 // Include private headers
 #include "wx/applet/prepinclude.h"
+#include "wx/applet/echovar.h"
+
+// wxWindows
+#include "wx/filesys.h"
+#include "wx/msgdlg.h"
+
+/*----------------------------- Implementation ----------------------------*/
 
 #define RECURSE_LIMIT 50
 
 #define RECURSE_LIMIT 50
-/*---------------------------- Global variables ---------------------------*/
 
 
+/****************************************************************************
+PARAMETERS:
+text        - text to process for echo variables
 
 
-/*----------------------------- Implementation ----------------------------*/
+RETURNS:
+The string containing the processed filename
+
+REMARKS:
+This routine searches through the text of the filename for variables contained
+in % percent signs
+****************************************************************************/
+wxString ParseFilename(
+    wxString &text)
+{
+    int f = 0;
+    int e;
+    while ((f = text.find('%', f)) != wxString::npos) {
+        f++;
+        e = text.find('%', f);
+#ifdef CHECKED 
+        if (e == wxString::npos) {
+            wxMessageBox(wxString("wxHTML #include error: % signs should bracket variable names in file attribute. To use a percent sign in a filename write double percents (%%)."), "Error" ,wxICON_ERROR);
+            return text;
+            }
+#endif                 
+        if (e == f)
+            text.replace(f-1, 2, "%");
+        else {
+            wxString varname = text.Mid(f, (e-f));
+            text.replace(f-1, (e-f)+2, wxEchoVariable::GetValue(varname));
+            }
+        }
+    return text;
+}
 
 /****************************************************************************
 PARAMETERS:
 
 /****************************************************************************
 PARAMETERS:
@@ -58,10 +92,6 @@ wxString wxIncludePrep::Process(
 {
     int i;
        char ft[] = "<!--#include virtual=";
 {
     int i;
        char ft[] = "<!--#include virtual=";
-       
-    wxFileSystem *fs = new wxFileSystem;
-    fs->ChangePathTo(DOC_ROOT, true);
-
     int openedcount = 0;
 
     // make a copy so we can replace text as we go without affecting the original
     int openedcount = 0;
 
     // make a copy so we can replace text as we go without affecting the original
@@ -92,17 +122,18 @@ wxString wxIncludePrep::Process(
                // remove the #include tag
         output.Remove(i, n+21+3);
 
                // remove the #include tag
         output.Remove(i, n+21+3);
 
-        wxFSFile * file = fs->OpenFile(fname);
-                       
+        wxFSFile * file;
+        file = m_FS->OpenFile(ParseFilename(fname));
+       
         if (!file) {
 #ifdef CHECKED         
                        wxMessageBox(wxString("wxHTML #include error: File not Found ") + fname + wxString("."),"Error",wxICON_ERROR);
 #endif
         if (!file) {
 #ifdef CHECKED         
                        wxMessageBox(wxString("wxHTML #include error: File not Found ") + fname + wxString("."),"Error",wxICON_ERROR);
 #endif
+            delete file;
             continue;
                        }                       
                                                        
                wxString tmp;
             continue;
                        }                       
                                                        
                wxString tmp;
-
        
         do {
                        char tmp2[257];
        
         do {
                        char tmp2[257];
@@ -113,19 +144,16 @@ wxString wxIncludePrep::Process(
                        } while (c == 256);
 
                output = (output.Mid(0,i) + tmp + output.Mid(i));
                        } while (c == 256);
 
                output = (output.Mid(0,i) + tmp + output.Mid(i));
-
-        #ifdef CHECKED 
+#ifdef CHECKED 
         if (openedcount > RECURSE_LIMIT) {
             wxMessageBox(wxString("wxHTML #include error: More than RECURSE_LIMIT files have been #included you may have a file that is directly or indirectly including itself, causing an endless loop"), "Error" ,wxICON_ERROR);
             break;
             }
         if (openedcount > RECURSE_LIMIT) {
             wxMessageBox(wxString("wxHTML #include error: More than RECURSE_LIMIT files have been #included you may have a file that is directly or indirectly including itself, causing an endless loop"), "Error" ,wxICON_ERROR);
             break;
             }
-        #endif                 
-
+#endif                 
         openedcount++;
         delete file;
         }
        
         openedcount++;
         delete file;
         }
        
-       delete fs;
        return output;
 }
 
        return output;
 }
 
@@ -138,9 +166,8 @@ This function sets the directory to get included HTML files from. The default
 value is the current directory. Directorys may be given as a relative path.
 ****************************************************************************/
 void wxIncludePrep::ChangeDirectory(
 value is the current directory. Directorys may be given as a relative path.
 ****************************************************************************/
 void wxIncludePrep::ChangeDirectory(
-    const wxString &dir)
+    wxFileSystem *fs)
 {
 {
-
-    DOC_ROOT = dir;
+     m_FS = fs;
 }
 
 }