Changeset 1610


Ignore:
Timestamp:
2000-10-25T12:25:01+13:00 (24 years ago)
Author:
paynter
Message:

Changed the formatstring parser in formattools so that an {If} macro (which
has the form {If}{decision,then,else}) can branch on any text, not just on
metadata. This means you can use extra cgi arguments and macros like
_cgiargmode_ to display documents in different modes and switch between
them. To accomplish all this, the formattools class needed to be able to
evaluate macros (through displayclass), so the other files have been
changed to pass in a displayclass object.

Location:
trunk/gsdl/src/recpt
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/browsetools.cpp

    r1606 r1610  
    116116  textout << outconvert << disp
    117117      << get_formatted_string (args["c"],collectproto,
    118                    response.docInfo[0], formatlistptr,
     118                   response.docInfo[0], disp, formatlistptr,
    119119                   logout);
    120120}
  • trunk/gsdl/src/recpt/datelistbrowserclass.cpp

    r1443 r1610  
    126126    textout << outconvert << disp
    127127            << get_formatted_string (collection, collectproto,
    128                      *thissection, formatlistptr,
     128                     *thissection, disp, formatlistptr,
    129129                     link, icon, false,
    130130                     logout) << "\n";
  • trunk/gsdl/src/recpt/documentaction.cpp

    r1443 r1610  
    720720      text_t doctext
    721721      = get_formatted_string (collection, collectproto,
    722                   docinfo, formatlistptr, docresponse.doc,
     722                  docinfo, disp, formatlistptr, docresponse.doc,
    723723                  logout);
    724724     
  • trunk/gsdl/src/recpt/formattools.cpp

    r1561 r1610  
    3232// a few function prototypes
    3333static text_t format_string (const text_t& collection, recptproto* collectproto,
    34                  ResultDocInfo_t &docinfo, format_t *formatlistptr,
     34                 ResultDocInfo_t &docinfo, displayclass &disp,
     35                 format_t *formatlistptr,
    3536                 const text_t &link, const text_t &icon,
    3637                 const text_t &text, bool highlight, ostream& logout);
     
    4950  command = dMeta;
    5051  meta.clear();
     52  text.clear();
    5153}
    5254
     
    385387    text.clear();
    386388
    387       } else {
    388     // the {If}{decide,do,else} statement
     389      }
     390
     391      // Parse an {If}{decide,do,else} statement
     392      else {
     393   
     394    // Read the decision component. 
    389395    if (commacount == 0) {
    390       // If decision only supports metadata at present
    391 
    392       // remove the surrounding square brackets
     396      // Decsion can be a metadata element, or a piece of text.
     397      // Originally Stefan's code, updated 25/10/2000 by Gordon.
     398
    393399      text_t::const_iterator beginbracket = text.begin();
    394400      text_t::const_iterator endbracket = (text.end() - 1);
     401
     402      // Decision is based on a metadata element
    395403      if ((*beginbracket == '[') && (*endbracket == ']')) {
     404        // Ignore the surrounding square brackets
    396405        text_t meta = substr (beginbracket+1, endbracket);
    397406        parse_meta (meta, formatlistptr->decision.meta, metadata, getParents);
     
    399408        text.clear();
    400409      }
    401      
    402     } else {
     410
     411      // Decision is a piece of text (probably a macro like _cgiargmode_).
     412      else {
     413        formatlistptr->decision.command = dText;
     414        formatlistptr->decision.text = text;
     415        commacount ++;
     416        text.clear();
     417      }
     418    }
     419
     420    // Read the "then" and "else" components of the {If} statement.
     421    else {
    403422      format_t** nextlistptr = NULL;
    404423      if (commacount == 1) {
    405           nextlistptr = &formatlistptr->ifptr;
     424        nextlistptr = &formatlistptr->ifptr;
    406425      } else if (commacount == 2 ) {
    407426        nextlistptr = &formatlistptr->elseptr;
     
    548567
    549568static text_t get_or (const text_t& collection, recptproto* collectproto,
    550               ResultDocInfo_t &docinfo, format_t *orptr,
     569              ResultDocInfo_t &docinfo, displayclass &disp,
     570              format_t *orptr,
    551571              const text_t &link, const text_t &icon,
    552572              const text_t &text, bool highlight,
     
    556576  while (orptr != NULL) {
    557577
    558     tmp = format_string (collection,collectproto, docinfo,orptr,
    559              link,icon,text,highlight, logout);
     578    tmp = format_string (collection,collectproto, docinfo, disp, orptr,
     579             link, icon, text, highlight, logout);
    560580    if (!tmp.empty()) return tmp;
    561581
     
    566586
    567587static text_t get_if (const text_t& collection, recptproto* collectproto,
    568               ResultDocInfo_t &docinfo, const decision_t &decision,
     588              ResultDocInfo_t &docinfo, displayclass &disp,
     589              const decision_t &decision,
    569590              format_t *ifptr, format_t *elseptr, const text_t &link,
    570591              const text_t &icon, const text_t &text, bool highlight,
     
    572593{
    573594
    574   // not much of a choice yet ...
     595  // If the decision component is a metadata element, then evaluate it
     596  // to see whether we output the "then" or the "else" clause
    575597  if (decision.command == dMeta) {
    576598    if (get_meta (docinfo, decision.meta) != "") {
    577599      if (ifptr != NULL)
    578     return get_formatted_string (collection,collectproto, docinfo,ifptr,
    579                      link,icon,text,highlight, logout);
     600    return get_formatted_string (collection,collectproto, docinfo, disp, ifptr,
     601                     link, icon, text, highlight, logout);
    580602    }
    581603    else {
    582604      if (elseptr != NULL)
    583     return get_formatted_string (collection,collectproto, docinfo,elseptr,
    584                      link,icon,text,highlight, logout);
    585     }
    586   }
     605    return get_formatted_string (collection,collectproto, docinfo, disp, elseptr,
     606                     link, icon, text, highlight, logout);
     607    }
     608  }
     609
     610  // If the decision component is text, then evaluate it (it is probably a
     611  // macro like _cgiargmode_) to decide what to output.
     612  else if (decision.command == dText) {
     613
     614    text_t outstring;
     615    disp.expandstring (decision.text, outstring);
     616
     617    // This is a tad tricky.  When we expand a string like _cgiargmode_, that is
     618    // a cgi argument macro that has not been set, it evaluates to itself.
     619    // Therefore, were have to say that a piece of text evalautes true if
     620    // it is non-empty and if it is a cgi argument evaulating to itself.
     621    if ((outstring != "") && !((outstring == decision.text) && (outstring[0] == '_'))) {
     622      if (ifptr != NULL)
     623    return get_formatted_string (collection, collectproto, docinfo, disp, ifptr,
     624                     link, icon, text, highlight, logout);
     625    } else {
     626      if (elseptr != NULL)
     627    return get_formatted_string (collection, collectproto, docinfo, disp, elseptr,
     628                     link, icon, text, highlight, logout);
     629    }
     630  }
     631 
    587632  return "";
    588633}
     
    601646
    602647text_t format_string (const text_t& collection, recptproto* collectproto,
    603               ResultDocInfo_t &docinfo, format_t *formatlistptr,
     648              ResultDocInfo_t &docinfo, displayclass &disp,
     649              format_t *formatlistptr,
    604650              const text_t &link, const text_t &icon,
    605651              const text_t &text, bool highlight,
     
    644690        {
    645691          text_t expanded_metavalue
    646         = get_formatted_string(collection,collectproto,
    647                        response.docInfo[0],expanded_formatlistptr,
     692        = get_formatted_string(collection, collectproto,
     693                       response.docInfo[0], disp, expanded_formatlistptr,
    648694                       link,icon,highlight,
    649695                       logout);
     
    670716    break;
    671717  case comIf:
    672     return get_if (collection, collectproto,
    673            docinfo, formatlistptr->decision, formatlistptr->ifptr,
     718    return get_if (collection, collectproto, docinfo, disp,
     719           formatlistptr->decision, formatlistptr->ifptr,
    674720           formatlistptr->elseptr, link, icon, text, highlight,
    675721           logout);
    676722  case comOr:
    677     return get_or (collection,collectproto, docinfo,formatlistptr->orptr,
    678            link,icon,text,highlight, logout);
     723    return get_or (collection,collectproto, docinfo, disp, formatlistptr->orptr,
     724           link, icon, text, highlight, logout);
    679725  }
    680726  return "";
     
    685731
    686732text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
    687                  ResultDocInfo_t& docinfo, format_t* formatlistptr,
     733                 ResultDocInfo_t& docinfo, displayclass &disp,
     734                 format_t* formatlistptr,
    688735                 const text_t& link, const text_t& icon,
    689736                 const text_t& text, const bool highlight,
     
    693740  while (formatlistptr != NULL)
    694741    {
    695       ft += format_string (collection, collectproto, docinfo, formatlistptr,
     742      ft += format_string (collection, collectproto, docinfo, disp, formatlistptr,
    696743               link, icon, text, highlight, logout);
    697744      formatlistptr = formatlistptr->nextptr;
     
    702749
    703750text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
    704                  ResultDocInfo_t &docinfo, format_t *formatlistptr,
     751                 ResultDocInfo_t &docinfo, displayclass &disp,
     752                 format_t *formatlistptr,
    705753                 const text_t &link, const text_t &icon,
    706754                 const bool highlight,
     
    709757  text_t text = "";
    710758
    711   return get_formatted_string(collection, collectproto, docinfo, formatlistptr,
     759  return get_formatted_string(collection, collectproto, docinfo, disp, formatlistptr,
    712760                              link, icon, text, highlight, logout);
    713761}
    714762
    715763text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
    716                  ResultDocInfo_t &docinfo, format_t *formatlistptr,
     764                 ResultDocInfo_t &docinfo, displayclass &disp,
     765                 format_t *formatlistptr,
    717766                 const text_t& text,
    718767                 ostream& logout) {
     
    722771  bool highlight = false;
    723772
    724   return get_formatted_string(collection, collectproto, docinfo, formatlistptr,
     773  return get_formatted_string(collection, collectproto, docinfo, disp, formatlistptr,
    725774                  link, icon, text, highlight, logout);
    726775}
    727776
    728777text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
    729                  ResultDocInfo_t &docinfo, format_t *formatlistptr,
     778                 ResultDocInfo_t &docinfo, displayclass &disp,
     779                 format_t *formatlistptr,
    730780                 ostream& logout) {
    731781
    732782  text_t text = "";
    733783
    734   return get_formatted_string(collection, collectproto, docinfo, formatlistptr,
     784  return get_formatted_string(collection, collectproto, docinfo, disp, formatlistptr,
    735785                  text, logout);
    736786}
    737787
     788
     789
     790
     791
     792
     793
  • trunk/gsdl/src/recpt/formattools.h

    r1443 r1610  
    3131#include "comtypes.h"
    3232#include "recptproto.h"
     33#include "display.h"
    3334
    3435enum command_t {comIf, comOr, comMeta, comText, comLink, comEndLink, comNum, comIcon,
    3536        comDoc, comHighlight, comEndHighlight};
    3637enum pcommand_t {pNone, pImmediate, pTop, pAll};
    37 enum dcommand_t {dMeta};
     38enum dcommand_t {dMeta, dText};
    3839enum mcommand_t {mNone, mCgiSafe};
    3940
     
    4849};
    4950
     51
     52// The decision component of an {If}{decision,true-text,false-text}
     53// formatstring.  Te decision can be based on metadata or on text;
     54// normally that text would be a macro like _cgiargmode_.  --gordon
    5055struct decision_t {
    5156  void clear();
     
    5459  dcommand_t command;
    5560  metadata_t meta;
     61  text_t text;
    5662};
    5763
     
    102108
    103109text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
    104                  ResultDocInfo_t &docinfo, format_t *formatlistptr,
     110                 ResultDocInfo_t &docinfo, displayclass &disp,
     111                 format_t *formatlistptr,
    105112                 const text_t &link, const text_t &icon,
    106113                 const text_t& t, const bool highlight,
     
    108115
    109116text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
    110                  ResultDocInfo_t &docinfo, format_t *formatlistptr,
     117                 ResultDocInfo_t &docinfo, displayclass &disp,
     118                 format_t *formatlistptr,
    111119                 const text_t &link, const text_t &icon,
    112120                 const bool highlight,
     
    114122
    115123text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
    116                  ResultDocInfo_t &docinfo, format_t *formatlistptr,
     124                 ResultDocInfo_t &docinfo, displayclass &disp,
     125                 format_t *formatlistptr,
    117126                 const text_t &text,
    118127                 ostream& logout);
    119128
    120129text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
    121                  ResultDocInfo_t &docinfo, format_t *formatlistptr,
    122                  ostream& logout);
     130                 ResultDocInfo_t &docinfo, displayclass &disp,
     131                 format_t *formatlistptr, ostream& logout);
    123132
    124133
  • trunk/gsdl/src/recpt/hlistbrowserclass.cpp

    r1443 r1610  
    137137    textout << outconvert << disp
    138138        << get_formatted_string (collection, collectproto,
    139                      *tsibling, formatlistptr, link, icon, highlight,
     139                     *tsibling, disp, formatlistptr, link, icon, highlight,
    140140                     logout);
    141141
  • trunk/gsdl/src/recpt/vlistbrowserclass.cpp

    r1443 r1610  
    8282  textout << outconvert << disp
    8383      << get_formatted_string (collection, collectproto,
    84                    section, formatlistptr,
     84                   section, disp, formatlistptr,
    8585                   link, icon, highlight, logout);
    8686 
     
    133133    textout << outconvert << disp
    134134        << get_formatted_string (collection, collectproto,
    135                      *thissection, formatlistptr,
     135                     *thissection, disp, formatlistptr,
    136136                     link, icon, highlight, logout);
    137137
Note: See TracChangeset for help on using the changeset viewer.