Ignore:
Timestamp:
24/08/10 11:23:06 (21 months ago)
Author:
Freddie Akeroyd
Message:

Update to tclap 1.2.0 from http://tclap.sourceforge.net/
Refs #244

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/third_party/tclap/DocBookOutput.h

    r857 r1515  
     1// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- 
    12 
    23/******************************************************************************  
     
    7778                 */ 
    7879                void substituteSpecialChars( std::string& s, char r, std::string& x ); 
     80                void removeChar( std::string& s, char r); 
     81                void basename( std::string& s ); 
     82 
     83                void printShortArg(Arg* it); 
     84                void printLongArg(Arg* it); 
     85 
     86                char theDelimiter; 
    7987}; 
    8088 
     
    8997        std::list<Arg*> argList = _cmd.getArgList(); 
    9098        std::string progName = _cmd.getProgramName(); 
     99        std::string version = _cmd.getVersion(); 
     100        theDelimiter = _cmd.getDelimiter(); 
    91101        XorHandler xorHandler = _cmd.getXorHandler(); 
    92102        std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList(); 
    93  
     103        basename(progName); 
    94104 
    95105        std::cout << "<?xml version='1.0'?>" << std::endl; 
    96         std::cout << "<!DOCTYPE book PUBLIC \"-//Norman Walsh//DTD DocBk XML V4.2//EN\"" << std::endl; 
     106        std::cout << "<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.2//EN\"" << std::endl; 
    97107        std::cout << "\t\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\">" << std::endl << std::endl; 
    98108 
    99         std::cout << "<book>" << std::endl; 
     109        std::cout << "<refentry>" << std::endl; 
     110 
     111        std::cout << "<refmeta>" << std::endl; 
     112        std::cout << "<refentrytitle>" << progName << "</refentrytitle>" << std::endl; 
     113        std::cout << "<manvolnum>1</manvolnum>" << std::endl; 
     114        std::cout << "</refmeta>" << std::endl; 
     115 
     116        std::cout << "<refnamediv>" << std::endl; 
     117        std::cout << "<refname>" << progName << "</refname>" << std::endl; 
     118        std::cout << "<refpurpose>" << _cmd.getMessage() << "</refpurpose>" << std::endl; 
     119        std::cout << "</refnamediv>" << std::endl; 
     120 
     121        std::cout << "<refsynopsisdiv>" << std::endl; 
    100122        std::cout << "<cmdsynopsis>" << std::endl; 
    101123 
    102124        std::cout << "<command>" << progName << "</command>" << std::endl; 
    103  
    104         std::string lt = "&lt;";  
    105         std::string gt = "&gt;";  
    106125 
    107126        // xor 
    108127        for ( int i = 0; (unsigned int)i < xorList.size(); i++ ) 
    109128        { 
    110                 std::cout << "<group>" << std::endl; 
     129                std::cout << "<group choice='req'>" << std::endl; 
    111130                for ( ArgVectorIterator it = xorList[i].begin();  
    112131                                                it != xorList[i].end(); it++ ) 
    113                 { 
    114                         std::string id = (*it)->shortID(); 
    115                         substituteSpecialChars(id,'<',lt); 
    116                         substituteSpecialChars(id,'>',gt); 
    117                         std::cout << "<arg>" << id << "</arg>" << std::endl;  
    118                 } 
     132                        printShortArg((*it)); 
    119133 
    120134                std::cout << "</group>" << std::endl; 
    121135        } 
    122  
     136         
     137        // rest of args 
    123138        for (ArgListIterator it = argList.begin(); it != argList.end(); it++) 
    124139                if ( !xorHandler.contains( (*it) ) ) 
    125                 { 
    126                         std::string id = (*it)->shortID(); 
    127                         substituteSpecialChars(id,'<',lt); 
    128                         substituteSpecialChars(id,'>',gt); 
    129                         std::cout << "<arg>" << id << "</arg>" << std::endl;  
    130                 } 
     140                        printShortArg((*it)); 
    131141 
    132142        std::cout << "</cmdsynopsis>" << std::endl; 
    133         std::cout << "</book>" << std::endl; 
     143        std::cout << "</refsynopsisdiv>" << std::endl; 
     144 
     145        std::cout << "<refsect1>" << std::endl; 
     146        std::cout << "<title>Description</title>" << std::endl; 
     147        std::cout << "<para>" << std::endl; 
     148        std::cout << _cmd.getMessage() << std::endl;  
     149        std::cout << "</para>" << std::endl; 
     150        std::cout << "</refsect1>" << std::endl; 
     151 
     152        std::cout << "<refsect1>" << std::endl; 
     153        std::cout << "<title>Options</title>" << std::endl; 
     154 
     155        std::cout << "<variablelist>" << std::endl; 
     156         
     157        for (ArgListIterator it = argList.begin(); it != argList.end(); it++) 
     158                printLongArg((*it)); 
     159 
     160        std::cout << "</variablelist>" << std::endl; 
     161        std::cout << "</refsect1>" << std::endl; 
     162 
     163        std::cout << "<refsect1>" << std::endl; 
     164        std::cout << "<title>Version</title>" << std::endl; 
     165        std::cout << "<para>" << std::endl; 
     166        std::cout << version << std::endl;  
     167        std::cout << "</para>" << std::endl; 
     168        std::cout << "</refsect1>" << std::endl; 
     169         
     170        std::cout << "</refentry>" << std::endl; 
    134171 
    135172} 
    136173 
    137174inline void DocBookOutput::failure( CmdLineInterface& _cmd, 
    138                                                 ArgException& e )  
     175                                    ArgException& e )  
    139176{  
    140                 std::cout << e.what() << std::endl; 
     177        static_cast<void>(_cmd); // unused 
     178        std::cout << e.what() << std::endl; 
     179        throw ExitException(1); 
    141180} 
    142181 
     
    153192} 
    154193 
     194inline void DocBookOutput::removeChar( std::string& s, char r) 
     195{ 
     196        size_t p; 
     197        while ( (p = s.find_first_of(r)) != std::string::npos ) 
     198        { 
     199                s.erase(p,1); 
     200        } 
     201} 
     202 
     203inline void DocBookOutput::basename( std::string& s ) 
     204{ 
     205        size_t p = s.find_last_of('/'); 
     206        if ( p != std::string::npos ) 
     207        { 
     208                s.erase(0, p + 1); 
     209        } 
     210} 
     211 
     212inline void DocBookOutput::printShortArg(Arg* a) 
     213{ 
     214        std::string lt = "&lt;";  
     215        std::string gt = "&gt;";  
     216 
     217        std::string id = a->shortID(); 
     218        substituteSpecialChars(id,'<',lt); 
     219        substituteSpecialChars(id,'>',gt); 
     220        removeChar(id,'['); 
     221        removeChar(id,']'); 
     222         
     223        std::string choice = "opt"; 
     224        if ( a->isRequired() ) 
     225                choice = "plain"; 
     226 
     227        std::cout << "<arg choice='" << choice << '\''; 
     228        if ( a->acceptsMultipleValues() ) 
     229                std::cout << " rep='repeat'"; 
     230 
     231 
     232        std::cout << '>'; 
     233        if ( !a->getFlag().empty() ) 
     234                std::cout << a->flagStartChar() << a->getFlag(); 
     235        else 
     236                std::cout << a->nameStartString() << a->getName(); 
     237        if ( a->isValueRequired() ) 
     238        { 
     239                std::string arg = a->shortID(); 
     240                removeChar(arg,'['); 
     241                removeChar(arg,']'); 
     242                removeChar(arg,'<'); 
     243                removeChar(arg,'>'); 
     244                arg.erase(0, arg.find_last_of(theDelimiter) + 1); 
     245                std::cout << theDelimiter; 
     246                std::cout << "<replaceable>" << arg << "</replaceable>"; 
     247        } 
     248        std::cout << "</arg>" << std::endl; 
     249 
     250} 
     251 
     252inline void DocBookOutput::printLongArg(Arg* a) 
     253{ 
     254        std::string lt = "&lt;";  
     255        std::string gt = "&gt;";  
     256 
     257        std::string desc = a->getDescription(); 
     258        substituteSpecialChars(desc,'<',lt); 
     259        substituteSpecialChars(desc,'>',gt); 
     260 
     261        std::cout << "<varlistentry>" << std::endl; 
     262 
     263        if ( !a->getFlag().empty() ) 
     264        { 
     265                std::cout << "<term>" << std::endl; 
     266                std::cout << "<option>"; 
     267                std::cout << a->flagStartChar() << a->getFlag(); 
     268                std::cout << "</option>" << std::endl; 
     269                std::cout << "</term>" << std::endl; 
     270        } 
     271 
     272        std::cout << "<term>" << std::endl; 
     273        std::cout << "<option>"; 
     274        std::cout << a->nameStartString() << a->getName(); 
     275        if ( a->isValueRequired() ) 
     276        { 
     277                std::string arg = a->shortID(); 
     278                removeChar(arg,'['); 
     279                removeChar(arg,']'); 
     280                removeChar(arg,'<'); 
     281                removeChar(arg,'>'); 
     282                arg.erase(0, arg.find_last_of(theDelimiter) + 1); 
     283                std::cout << theDelimiter; 
     284                std::cout << "<replaceable>" << arg << "</replaceable>"; 
     285        } 
     286        std::cout << "</option>" << std::endl; 
     287        std::cout << "</term>" << std::endl; 
     288 
     289        std::cout << "<listitem>" << std::endl; 
     290        std::cout << "<para>" << std::endl; 
     291        std::cout << desc << std::endl; 
     292        std::cout << "</para>" << std::endl; 
     293        std::cout << "</listitem>" << std::endl; 
     294 
     295        std::cout << "</varlistentry>" << std::endl; 
     296} 
     297 
    155298} //namespace TCLAP 
    156299#endif  
Note: See TracChangeset for help on using the changeset viewer.