]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/applet/prepinclude.cpp
1 /****************************************************************************
3 * wxWindows HTML Applet Package
5 * Copyright (C) 1991-2001 SciTech Software, Inc.
8 * ========================================================================
10 * The contents of this file are subject to the wxWindows License
11 * Version 3.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.wxwindows.org/licence3.txt
15 * Software distributed under the License is distributed on an
16 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 * implied. See the License for the specific language governing
18 * rights and limitations under the License.
20 * ========================================================================
25 * Description: This file is the implementation of the Preprocessor object
26 * for parsing the <!--#include
28 ****************************************************************************/
30 // For compilers that support precompilation
31 #include "wx/wxprec.h"
32 //#include "wx/file.h"
33 #include "wx/filesys.h"
34 // Include private headers
35 #include "wx/applet/prepinclude.h"
37 #define RECURSE_LIMIT 50
38 /*---------------------------- Global variables ---------------------------*/
41 /*----------------------------- Implementation ----------------------------*/
43 /****************************************************************************
45 text - HTML to process for include directives
48 The string containing the processed HTML
51 This is the only implemented method of the Preprocessor class. It is a constant
52 function that parses a string. Basically we load the string search for include
53 statements then replace them with the correct file. Wash rinse and repeat until
54 all recursive cases are handled.
55 ****************************************************************************/
56 wxString
wxIncludePrep :: Process (
57 const wxString
& text
) const
60 char ft
[] = "<!--#include virtual=" ;
62 wxFileSystem
* fs
= new wxFileSystem
;
63 fs
-> ChangePathTo ( DOC_ROOT
, true );
67 // make a copy so we can replace text as we go without affecting the original
68 wxString output
= text
;
69 while (( i
= ( output
. Lower ()). Find ( ft
)) != - 1 ) {
70 // This loop makes more recursion unnecessary since each iteration adds
71 // the new include files to output.
75 n
= ( output
. Mid ( i
+ 21 )). Find ( "-->" );
79 wxMessageBox ( "wxHTML #include error: Could not read filename. Premature end of file." , "Error" , wxICON_ERROR
);
84 fname
= output
. Mid ( i
+ 21 , n
);
86 // Clip off any quotation marks if they exist. (don't die if there arn't any)
88 if ( c
!= - 1 ) fname
= fname
. Mid ( c
+ 1 );
90 if ( c
!= - 1 ) fname
= fname
. Mid ( 0 , c
);
92 // remove the #include tag
93 output
. Remove ( i
, n
+ 21 + 3 );
95 wxFSFile
* file
= fs
-> OpenFile ( fname
);
99 wxMessageBox ( wxString ( "wxHTML #include error: File not Found " ) + fname
+ wxString ( "." ), "Error" , wxICON_ERROR
);
109 ( file
-> GetStream ())-> Read ( tmp2
, 256 );
110 c
= ( file
-> GetStream ())-> LastRead ();
112 tmp
+= wxString ( tmp2
);
115 output
= ( output
. Mid ( 0 , i
) + tmp
+ output
. Mid ( i
));
118 if ( openedcount
> RECURSE_LIMIT
) {
119 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
);
132 /****************************************************************************
134 dir - Default directory to get included HTML files from
137 This function sets the directory to get included HTML files from. The default
138 value is the current directory. Directorys may be given as a relative path.
139 ****************************************************************************/
140 void wxIncludePrep :: ChangeDirectory (