#pragma implementation #include #include #include #include #include #include #include #include #include #include #include "tlmpdoc.h" #include "tlmpdoc.m" #include "internal.h" using namespace std; W_INT step1("s1"); W_INT step2("s2"); W_INT step3("s3"); W_INT step4("s4"); W_INT step5("s5"); W_INT step6("s6"); W_INT full("full",0,"S"); DOC_ID id_null; static int alloc_id=0; class DOC_ID_PRIVATE{ public: string label; DOCUMENT_POINTER pt; }; PUBLIC DOC_ID::DOC_ID() { priv = new DOC_ID_PRIVATE; priv->label = string_f("%d",alloc_id++); } PUBLIC DOC_ID::~DOC_ID() { delete priv; } PUBLIC DOC_ID::DOC_ID(const char *_label) { priv = new DOC_ID_PRIVATE; priv->label = _label; } PUBLIC const char *DOC_ID::getlabel() const { return priv->label.c_str(); } void page(_F_page &c, const char *title) { htmlprintf ("

%s

\n",title); c.desc(); c.image(); } static bool is_index (int niveau, int tbno[]) { bool ret = true; for (int i=0; imatch(tbno)){ ret = true; break; } } return ret; } static void tlmpdoc_setparms (char parms[40], const int tb[]) { int len = 0; for (int i=0; i 30) break; } sprintf (parms+len,"&full=%d",full.getval()); } static string tlmpdoc_link(const int tb[], const char *text) { char parms[40]; tlmpdoc_setparms (parms,tb); return( url_getself (parms,text) ); } static DOC_ID *doc_id_top = nullptr; static string tlmpdoc_urltop() { static int tbno[10]; char parms[40]; tlmpdoc_setparms (parms,doc_id_top != nullptr ? doc_id_top->priv->pt.tb : tbno); return( url_getself (parms,MSG_U(B_TOP,"Top")).c_str() ); } static SECTIONS sections; static void print_white(const char *text) { htmlprintf ("%s\n",text); } static bool tlmpdoc_index = true; // If there is an index (on the side), we print section number in the title static void tlmpdoc_control (const char *title, int here, bool top) { //setDebug( true ); //setDebugFilename( "z_tlmpdoc.log" ); htmlout ("\n"); htmlout ("
\n"); if (full){ htmlout (url_getself ("tb=1","Content")); } htmlout (tlmpdoc_urltop()); { int tbtmp[TLMPDOC_MAXLEVEL]; memcpy (tbtmp,tlmpdoc_tbno,sizeof(tbtmp)); tbtmp[tlmpdoc_niveau-1] = 0; tbtmp[tlmpdoc_niveau] = 0; htmlout (" "); htmlout (tlmpdoc_link (tbtmp,MSG_U(B_UP,"Up"))); if (here > 1){ int tbtmp[TLMPDOC_MAXLEVEL]; memcpy (tbtmp,tlmpdoc_tbno,sizeof(tbtmp)); tbtmp[tlmpdoc_niveau-1] = here-1; tbtmp[tlmpdoc_niveau] = 0; htmlout (" "); htmlout (tlmpdoc_link (tbtmp,MSG_U(B_PREC,"Prec"))); } } htmlout (" "); if (top){ stringstream sout; htmlout ("

"); if (tlmpdoc_index){ for (int j=0; j"); } htmlout ("

\n"); int tbtmp[TLMPDOC_MAXLEVEL]; // Are there sub-topics ? // If there are sub-topics, we can either jump into it using the next link // or skip over it using the Skip link. // We always display the links so the visible links keep their position. memcpy (tbtmp,tlmpdoc_tbno,sizeof(tbtmp)); tbtmp[tlmpdoc_niveau] = 1; const char *verb2 = MSG_U(B_NEXT,"Next"); bool next_thread = sections.exist (tbtmp); bool white_skip = false; // tlmp_error ("title=%s next_thread=%d\n",title,next_thread); if (next_thread){ // tlmp_error ("title=%s avant verb2=skip\n",title); htmlout (tlmpdoc_link(tbtmp,MSG_R(B_NEXT))); htmlout (" "); verb2 = MSG_U(B_SKIP,"Skip"); }else{ white_skip = true; } // Is there a next topic at the same level memcpy (tbtmp,tlmpdoc_tbno,sizeof(tbtmp)); tbtmp[tlmpdoc_niveau-1]++; tbtmp[tlmpdoc_niveau] = 0; if (sections.exist (tbtmp)){ // Skip button // tlmp_error ("title=%s Skip button\n",title); htmlout (tlmpdoc_link(tbtmp,verb2)); }else{ int back = 1; bool done = false; while (tlmpdoc_niveau - back > 0){ tbtmp[tlmpdoc_niveau-(back+1)]++; tbtmp[tlmpdoc_niveau-back] = 0; if (sections.exist(tbtmp)){ // tlmp_error ("print verb2 = %s\n",verb2); htmlout (tlmpdoc_link (tbtmp,verb2)); done = true; break; }else{ back++; } } // tlmp_error ("title=%s done=%d verb2=%s\n",title,done,verb2); if (!done) print_white (verb2); } if (white_skip){ htmlout (" "); print_white (MSG_R(B_SKIP)); } htmlout ("
\n"); }
static _F_document *tlmpdoc_f; void _F_section::htmlout (PARAM_STRING s) { ::htmlout (s.ptr); } void section(_F_section &c, const char *id, const char *title, DOC_ID &ref) { docsession_push (id); c.priv = NULL; glocal _F_section *C = &c; glocal string TITLE; glocal.TITLE = title; tlmpdoc_tbno[tlmpdoc_niveau]++; if (&ref != &id_null){ ref.priv->pt.set (tlmpdoc_tbno[0],tlmpdoc_tbno[1],tlmpdoc_tbno[2],tlmpdoc_tbno[3],tlmpdoc_tbno[4],tlmpdoc_tbno[5]); } if (tlmpdoc_domap){ sections.add (tlmpdoc_tbno,title,docsession_getstatus()); tlmpdoc_niveau++; tlmpdoc_tbno[tlmpdoc_niveau] = 0; c.body(false,false); tlmpdoc_tbno[tlmpdoc_niveau] = 0; tlmpdoc_niveau--; }else if (tlmpdoc_content != 0){ tlmpdoc_table_entry (title,NODE_SECTION); tlmpdoc_niveau++; tlmpdoc_tbno[tlmpdoc_niveau] = 0; c.body(false,false); tlmpdoc_tbno[tlmpdoc_niveau] = 0; tlmpdoc_niveau--; }else if (tlmpdoc_vdepth <= tlmpdoc_niveau){ tlmpdoc_niveau++; if (0 && &ref != &id_null){ htmlprintf ("

\n",tlmpdoc_niveau,title,tlmpdoc_niveau); c.body(false,true); docsession_endsection(); tlmpdoc_niveau--; }else{ int here = tlmpdoc_tbno[tlmpdoc_niveau]; if (is_index (tlmpdoc_niveau,tlmpdoc_tbno)){ bool on = tlmpweb_ctrloutput (true); if (here == 1) htmlprintf ("

    \n"); docsession_putli (); char parms[40]; tlmpdoc_setparms (parms,tlmpdoc_tbno); url_self (parms,"%s",title); docsession_putendli(); tlmpweb_ctrloutput (on); }else if (tlmpdoc_is_data(tlmpdoc_niveau,tlmpdoc_tbno)){ docsession_wasseen(); tlmpdoc_niveau++; tlmpdoc_tbno[tlmpdoc_niveau] = 0; bool on = tlmpweb_ctrloutput (tlmpdoc_tbstep[tlmpdoc_niveau] == 0); tlmpweb_title (title); htmlout ("\n"); htmlout ("
    \n"); tlmpdoc_control (title,here,true); htmlout ("
    \n"); htmlprintf ("

    \n"); htmlprintf ("

    \n"); c.body(true,false); htmlprintf ("
    \n"); htmlout ("
    \n"); tlmpdoc_control (title,here,false); htmlout ("
    \n"); tlmpweb_ctrloutput (on); tlmpdoc_niveau--; } } docsession_pop (); } void section(_F_section &c, const char *id, const char *title) { section (c,id,title,id_null); } void section(_F_section &c, const char *title) { section (c,title,title,id_null); } void section(_F_section &c, const char *title, DOC_ID &ref) { section (c,title,title,ref); } void showimage (const char *fname) { htmlprintf ("
    \n",fname); } void paragraph(_F_paragraph &c, const char *title) { c.priv = NULL; if (!tlmpdoc_domap){ if (tlmpdoc_content != 0){ tlmpdoc_table_entry (title,NODE_PARAGRAPH); }else{ htmlprintf ("

    %s

    \n",title); htmlprintf ("

    \n"); c.body(); htmlprintf ("

    \n"); } } } static void tlmpdoc_valid (int &var, int val) { if (val < 0 || val > 999) val = 0; var = val; } class _F_document_private{ public: string name; string email; }; void _F_document::htmlout (PARAM_STRING s) { ::htmlout (s.ptr); } void _F_document::author(const char *name, const char *email) { priv->name = name; priv->email = email; } void _F_document::bottom(int tbno[10], int level) { if (full){ url_self ("tb=1",MSG_U(I_TABLECONTENT,"Table of content")); htmlprintf ("
    \n"); } if (tlmpdoc_vdepth == 20){ url_self ("dp=0&full=1",MSG_U(I_ONEBIG,"One big HTML document")); htmlprintf ("
    \n"); }else{ htmlout(tlmpdoc_urltop ()); htmlprintf ("
    \n"); } } void _F_document::ref() { urlproject(); htmlprintf ("
    \n"); urltlmpdoc(); htmlprintf ("
    \n"); if (priv->name.size() > 0){ htmlprintf ("Document maintained by %s",priv->name.c_str()); if (priv->email.size() > 0){ htmlprintf (" (%s)" ,priv->email.c_str(),priv->email.c_str()); } htmlprintf ("
    \n"); } struct stat st; if (stat(tlmpweb_curpage(),&st)!=-1){ struct tm *t = localtime (&st.st_mtime); htmlprintf ("Last update: %s
    \n",asctime(t)); } } void _F_document::urlproject() { htmlprintf ("Back to project page\n",tlmpweb_curpage()); } void _F_document::urltlmpdoc() { htmlprintf ("About tlmpdoc and cookies\n"); } void document( _F_document &c, const char *title, DOCUMENT_POINTER &pt, DOC_ID &jump, bool display_full, bool index) { doc_id_top = &jump; tlmpdoc_index = index; if (display_full){ full = display_full; tlmpdoc_vdepth.setinitval("0"); tlmpdoc_content.setinitval("0"); } tlmpweb_title (title); if (title != NULL && title[0] != '\0'){ htmlout ("\n"); htmlprintf ("

    %s

    \n",title); int tr_height=95; htmlprintf ("
    \n",tr_height); } tlmpdoc_f = &c; _F_document_private priv; c.priv = &priv; glocal _F_document *C; glocal.C = &c; glocal _F_document_private *priv; glocal.priv = &priv; tlmpweb_title (title); sections.remove_all(); tlmpdoc_domap=true; tlmpweb_ctrloutput (false); // This one only calculates the index/menu c.body(); tlmpdoc_domap = false; tlmpdoc_niveau = 0; memset (tlmpdoc_tbno,0,sizeof(tlmpdoc_tbno)); tlmpweb_ctrloutput (true); if (step1.isset()){ pt.set (step1,step2,step3,step4,step5,step6); }else if (jump.priv->pt.ischanged() && pt.at_top()){ pt = jump.priv->pt; } for (unsigned i=0; i\n"); htmlprintf ("Table of content

    \n"); htmlprintf ("

    \n"); tlmpweb_ctrloutput (false); // This one has 'no' obvious use in this case c.body(); htmlprintf ("
    \n"); }else{ glocal vector sBody; tlmpweb_pushgrab (glocal.sBody); if (is_step (0,0,0,0)){ htmlprintf ("
    \n"); c.abstract(); htmlprintf ("

    \n"); htmlprintf ("

    \n"); } c.body(); if (is_step(0,0,0,0)){ htmlprintf ("
    \n"); htmlprintf ("

    \n"); c.bottom (tlmpdoc_tbno,0); c.ref(); } tlmpweb_popgrab (); if (!full){ DIV drow("subtabs"); drow.dispflex().flowrow().w(100).h(100).print(); unsigned wbody = 100; if (index){ DIV idx("subtabs"); idx.h(100).w(20).flexfixe().autoscroll().border(1,"black").paddings(5,5).print(); wbody = 80; htmlout ("
    \n"); SECTIONS *sectionsPtr = §ions; if (sections.getnb()){ sectionsPtr = §ions; } for (int i=0; igetnb(); i++){ SECTION *s = sectionsPtr->getitem(i); for (int j=0; jtbno[j] == 0){ if (j==1) htmlout ("."); break; } if (j < 1 ){ htmlprintf ("%d",s->tbno[j]); }else{ htmlprintf (".%d",s->tbno[j]); } } htmlout (" "); string title = tlmpdoc_link (s->tbno,s->gettitle()); if (s->match(tlmpdoc_tbstep)){ htmlprintf ("%s",title.c_str()); }else{ htmlprintf ("%s",title.c_str()); } DOCNODE_STATUS status = s->status; if (status == DOCNODE_MODIFIED){ htmlout (""); }else if (status == DOCNODE_NEW){ htmlout (""); }else if (status == DOCNODE_NEVERSEEN){ htmlout(""); } htmlout ("
    \n"); } htmlout ("
    \n"); } DIV dbody("subtabs"); dbody.flexfixe().h(100).w(wbody).autoscroll().margins(5,5).print(); htmlout (glocal.sBody); }else{ htmlout (glocal.sBody); } } if (title != NULL && title[0] != '\0'){ htmlout ("

    \n"); } doc_id_top = nullptr; }
    void document( _F_document &c, const char *title, DOCUMENT_POINTER &pt) { document (c,title,pt,id_null,false,true); } void document( _F_document &c, const char *title) { DOCUMENT_POINTER pt; document(c,title,pt,id_null,false,true); } void ref (DOC_ID &id, const char *title) { htmlprintf ("%s\n",id.getlabel(),title); } /* Create a link to another part of the document. The id is the one used in a section of the document. */ void tlmpdoc_link (DOC_ID &id, const char *title) { DOCUMENT_POINTER &pt = id.priv->pt; string parms = string_f ("s1=%d&s2=%d&s3=%d&s4=%d&s5=%d&s6=%d" ,pt.tb[0],pt.tb[1],pt.tb[2],pt.tb[3],pt.tb[4],pt.tb[5]); url_self (parms,"%s",title); } void docsession (_F_docsession &c, const char *id) { docsession_do (c,id); } void docsession (_F_docsession &c) { docsession (c,tlmpweb_curpath()); } DOCUMENT_POINTER::DOCUMENT_POINTER() { reset(); } void DOCUMENT_POINTER::reset () { memset (tb,0,sizeof(tb)); changed = false; } void DOCUMENT_POINTER::set (int s1, int s2, int s3, int s4, int s5, int s6) { if (s1 != tb[0] || s2 != tb[1] || s3 != tb[2] || s4 != tb[3] || s5 != tb[4] || s6 != tb[5]){ changed = true; tb[0] = s1; tb[1] = s2; tb[2] = s3; tb[3] = s4; tb[4] = s5; tb[5] = s6; } } DOCUMENT_POINTER & DOCUMENT_POINTER::operator = (const DOCUMENT_POINTER &n) { changed = n.changed; tb[0] = n.tb[0]; tb[1] = n.tb[1]; tb[2] = n.tb[2]; tb[3] = n.tb[3]; tb[4] = n.tb[4]; tb[5] = n.tb[5]; return *this; } bool DOCUMENT_POINTER::at_top() const { return tb[0] == 0 && tb[1] == 0 && tb[2] == 0 && tb[3] == 0 && tb[4] == 0 && tb[5] == 0; }