home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 31 / CDASC_31_1996_juillet_aout.iso / vrac / cuj0796.zip / COLNER.ZIP / HTML.CPP < prev    next >
C/C++ Source or Header  |  1996-05-08  |  2KB  |  87 lines

  1. #include "html.h"
  2.     void
  3. message( char* code, unsigned long line, char* file, char* date){
  4.     cout << (
  5.         Html("Error")
  6.         << (Block("H1") << "Error!")
  7.         <<    (Block("DL")
  8.             << "\n<DT>CODE<DD>" << code
  9.             << "\n<DT>LINE<DD>" << line
  10.             << "\n<DT>FILE<DD>" << file
  11.             << "\n<DT>DATE<DD>" << date
  12.             << "\n"
  13.             )
  14.         );
  15.     }
  16. //************************ Block messages *****************************
  17.     Block& Block :: operator
  18. << ( BlockOption& opt ){
  19.         if(blockOptionCount < 10)    // Deep copy the option
  20.             option[blockOptionCount++] = new BlockOption(opt);
  21.         return *this;
  22.         }
  23.     Block ::
  24. Block( Block& b): String(b), tag(b.tag){
  25.     for(     blockOptionCount =0;
  26.             blockOptionCount < b.blockOptionCount;
  27.             blockOptionCount++
  28.             )option[blockOptionCount]
  29.                     =new BlockOption(*b.option[b.blockOptionCount]);
  30.     }
  31.     Block ::
  32. ~Block(){
  33.     unsigned k =0;
  34.     while(k < blockOptionCount) delete option[k++];
  35.     }
  36.     Block& Block ::
  37. filter(const char * text){
  38.     char *s =(char*)text, c;
  39.     while( (c =*s++) != 0 )switch(c){
  40.         case '&':  *this << "&"; break;
  41.         case '<':  *this << "<";  break;
  42.         default:  *this << c;
  43.         }
  44.     return *this;
  45.     }
  46.     ostream& operator
  47. << ( ostream& out, Block& b){
  48.     out << "<" << b.tag;
  49.     unsigned k =0;
  50.     while(k < b.blockOptionCount)out << b.option[k++];
  51.     out << ">" ;
  52.     return out << (String&)b << "</" << b.tag << ">\n";
  53.     }
  54. //************************ BlockOption *****************************
  55.     ostream& operator
  56. << ( ostream& out, BlockOption& b){
  57.         out << " ";
  58.         out << b.name;
  59.         out << "=\"";
  60.         out << (String&)b;
  61.         out << "\"";
  62.     return out;
  63.     }
  64. //************************ Html messages *****************************
  65. int Html::responseHeader =1;
  66.     ostream& operator
  67. <<( ostream& out, Html& body){
  68.         Block htmlBlock("html");
  69.     if( body.title.notNull() || body.isIndex ){
  70.         Block head("head");
  71.         if(body.title.notNull()){
  72.             Block title("title");
  73.             title << body.title;
  74.             head << title;
  75.             }
  76.         if( body.isIndex )
  77.             head << "<isIndex>";
  78.         htmlBlock << head;
  79.         }
  80.     htmlBlock << (Block&)body;
  81.     if(Html::responseHeader)
  82.         out << "Content-type: text/html\n\n";
  83.     else
  84.         out << "Suppress:  Content-type: text/html\n\n";
  85.     return out << htmlBlock << endl;
  86.     }
  87.