home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 November / APC411-2.ISO / server / ohttp203.exe / data1.cab / CGI / Cgi-Win / test-win.cpp next >
Encoding:
C/C++ Source or Header  |  1999-07-15  |  1018 b   |  54 lines

  1. #include <fstream>
  2. using namespace std;
  3.  
  4. void displayfile(char *file, ostream *output)
  5. {
  6.     ifstream    inputfile(file);
  7.     char        buffer[1024];
  8.  
  9.     if (!inputfile)
  10.     {
  11.         *output << "Error displaying file " << file << endl;
  12.         return;
  13.     }
  14.  
  15.     *output << "<pre>";
  16.     do 
  17.     {
  18.         inputfile.read(buffer, 1024);
  19.         output->write(buffer, inputfile.gcount());
  20.     } 
  21.     while (!inputfile.eof());
  22.     inputfile.close();
  23.     *output << "</pre><hr>";
  24. }
  25.  
  26. void main(int argc, char *argv[])
  27. {
  28.     //    Not enough parameters, return silently
  29.     if (argc < 4) return;
  30.  
  31.     //    Set up output
  32.     ofstream output(argv[3]);
  33.     if (!output) return;
  34.  
  35.     //    header
  36.     output << "Content-type: text/html\n\n";
  37.  
  38.     //    profile
  39.     output << "<h2>Profile:</h2>";
  40.     displayfile(argv[1], &output);
  41.  
  42.     //    content
  43.     output << "<h2>Content:</h2>";
  44.     displayfile(argv[2], &output);
  45.  
  46.     //    query string
  47.     if (argc >= 5)
  48.         output << "<h2>Query String: " << argv[4] << "</h2>";
  49.     else
  50.         output << "<h2>No Query String</h2>";
  51.  
  52.     //    close the file
  53.     output.close();
  54. }