|
|
| #include <stdio.h>
|
| #include <stdlib.h>
|
| #include <dcmicro/htmlpp/htmlpp.h>
|
|
|
| // Load an HTML document into an object
|
| htmlGroup& IncludeHTML
|
| (
|
| htmlGroup& group, // container object
|
| char * filename // filename to load
|
| )
|
| {
|
| FILE * file ;
|
| char line_data[ 300 ] ; // increase as necessary
|
| String str ;
|
|
|
| // open the specified text file
|
| file = fopen( filename, "rt" ) ;
|
| if ( file != (FILE *) NULL )
|
| {
|
| // loop for all lines in the file
|
| while (
|
| fgets( line_data, sizeof(line_data), file ) != NULL
|
| )
|
| {
|
| str = line_data ;
|
| str.ToUpper() ;
|
|
|
| if ( str.Contains("HTML>")
|
| || str.Contains("HEAD>")
|
| || str.Contains("<BODY")
|
| || str.Contains("TITLE>")
|
| || str.Contains("BODY>") )
|
| {
|
| // Don't include lines containing
|
| // keywords relating to the page.
|
| }
|
| else
|
| {
|
| // Store the line as a literal to avoid
|
| // translation of symbols when output.
|
| group << htmlLiteral( line_data ) ;
|
| }
|
| }
|
|
|
| fclose( file ) ;
|
| }
|
|
|
| return group ;
|
| }
|
|
|
|
|
| int main( void )
|
| {
|
| htmlCgi server ;
|
| htmlPage page( "html++ test app" ) ;
|
|
|
| // Load the header document (it is assumed to exist)
|
| htmlContainer header ;
|
| IncludeHTML( header, "/home/templates/header.html" ) ;
|
|
|
| // Load the footer document
|
| htmlContainer footer ;
|
| IncludeHTML( footer, "/home/templates/footer.html" ) ;
|
|
|
| // Construct the page, inserting the header
|
| // and footer HTML documents around the text.
|
| page << header
|
| << htmlHorizontalRule()
|
| << "This is a test of using htmlContainer to "
|
| "include existing header and footer documents."
|
| << htmlHorizontalRule()
|
| << footer ;
|
|
|
| server << page ;
|
| return 0 ;
|
| }
|
|
|
| |