]>
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 // Include private headers
31 #include "wx/applet/prepinclude.h"
32 #include "wx/applet/echovar.h"
35 #include "wx/filesys.h"
36 #include "wx/msgdlg.h"
38 /*----------------------------- Implementation ----------------------------*/
40 #define RECURSE_LIMIT 50
42 /****************************************************************************
44 text - text to process for echo variables
47 The string containing the processed filename
50 This routine searches through the text of the filename for variables contained
52 ****************************************************************************/
53 wxString
ParseFilename (
58 while (( f
= text
. find ( '%' , f
)) != wxString :: npos
) {
60 e
= text
. find ( '%' , f
);
62 if ( e
== wxString :: npos
) {
63 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
);
68 text
. replace ( f
- 1 , 2 , "%" );
70 wxString varname
= text
. Mid ( f
, ( e
- f
));
71 text
. replace ( f
- 1 , ( e
- f
)+ 2 , wxEchoVariable :: GetValue ( varname
));
77 /****************************************************************************
79 text - HTML to process for include directives
82 The string containing the processed HTML
85 This is the only implemented method of the Preprocessor class. It is a constant
86 function that parses a string. Basically we load the string search for include
87 statements then replace them with the correct file. Wash rinse and repeat until
88 all recursive cases are handled.
89 ****************************************************************************/
90 wxString
wxIncludePrep :: Process (
91 const wxString
& text
) const
94 char ft
[] = "<!--#include virtual=" ;
97 // make a copy so we can replace text as we go without affecting the original
98 wxString output
= text
;
99 while (( i
= ( output
. Lower ()). Find ( ft
)) != - 1 ) {
100 // This loop makes more recursion unnecessary since each iteration adds
101 // the new include files to output.
105 n
= ( output
. Mid ( i
+ 21 )). Find ( "-->" );
109 wxMessageBox ( "wxHTML #include error: Could not read filename. Premature end of file." , "Error" , wxICON_ERROR
);
114 fname
= output
. Mid ( i
+ 21 , n
);
116 // Clip off any quotation marks if they exist. (don't die if there arn't any)
117 c
= fname
. Find ( " \" " );
118 if ( c
!= - 1 ) fname
= fname
. Mid ( c
+ 1 );
119 c
= fname
. Find ( " \" " );
120 if ( c
!= - 1 ) fname
= fname
. Mid ( 0 , c
);
122 // remove the #include tag
123 output
. Remove ( i
, n
+ 21 + 3 );
126 file
= m_FS
-> OpenFile ( ParseFilename ( fname
));
130 wxMessageBox ( wxString ( "wxHTML #include error: File not Found " ) + fname
+ wxString ( "." ), "Error" , wxICON_ERROR
);
140 ( file
-> GetStream ())-> Read ( tmp2
, 256 );
141 c
= ( file
-> GetStream ())-> LastRead ();
143 tmp
+= wxString ( tmp2
);
146 output
= ( output
. Mid ( 0 , i
) + tmp
+ output
. Mid ( i
));
148 if ( openedcount
> RECURSE_LIMIT
) {
149 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
);
160 /****************************************************************************
162 dir - Default directory to get included HTML files from
165 This function sets the directory to get included HTML files from. The default
166 value is the current directory. Directorys may be given as a relative path.
167 ****************************************************************************/
168 void wxIncludePrep :: ChangeDirectory (