]>
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=" ;
65 // make a copy so we can replace text as we go without affecting the original
66 wxString output
= text
;
67 while (( i
= ( output
. Lower ()). Find ( ft
)) != - 1 ) {
68 // This loop makes more recursion unnecessary since each iteration adds
69 // the new include files to output.
73 n
= ( output
. Mid ( i
+ 21 )). Find ( "-->" );
77 wxMessageBox ( "wxHTML #include error: Could not read filename. Premature end of file." , "Error" , wxICON_ERROR
);
82 fname
= output
. Mid ( i
+ 21 , n
);
84 // Clip off any quotation marks if they exist. (don't die if there arn't any)
86 if ( c
!= - 1 ) fname
= fname
. Mid ( c
+ 1 );
88 if ( c
!= - 1 ) fname
= fname
. Mid ( 0 , c
);
90 // remove the #include tag
91 output
. Remove ( i
, n
+ 21 + 3 );
94 file
= m_FS
-> OpenFile ( fname
);
98 wxMessageBox ( wxString ( "wxHTML #include error: File not Found " ) + fname
+ wxString ( "." ), "Error" , wxICON_ERROR
);
108 ( file
-> GetStream ())-> Read ( tmp2
, 256 );
109 c
= ( file
-> GetStream ())-> LastRead ();
111 tmp
+= wxString ( tmp2
);
114 output
= ( output
. Mid ( 0 , i
) + tmp
+ output
. Mid ( i
));
117 if ( openedcount
> RECURSE_LIMIT
) {
118 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
);
130 /****************************************************************************
132 dir - Default directory to get included HTML files from
135 This function sets the directory to get included HTML files from. The default
136 value is the current directory. Directorys may be given as a relative path.
137 ****************************************************************************/
138 void wxIncludePrep :: ChangeDirectory (