Changeset 2466 in Sophya for trunk/SophyaLib/SysTools


Ignore:
Timestamp:
Nov 27, 2003, 11:52:55 AM (22 years ago)
Author:
ansari
Message:

Amelioration classe SOPHYA::Commander, en particulier Ajout description d'un HelpGroup - Reza 27 Nov 2003

Location:
trunk/SophyaLib/SysTools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/SysTools/commander.cc

    r2464 r2466  
    321321
    322322// cmdhgrp["All"] = 0;
     323
     324string grp = "Commander";
     325string gdesc = "Basic (generic) interpreter (class SOPHYA::Commander) builtin commands";
     326AddHelpGroup(grp, gdesc);
    323327
    324328string kw = "Commander";
     
    354358usage += "  > help <command_name>  # <command_name> usage info \n";
    355359usage += "  > timingon  timingoff traceon  traceoff \n";
    356 string grp = "Commander";
    357360RegisterHelp(kw, usage, grp);
    358361
     
    436439
    437440/* --Methode-- */
    438 void Commander::RegisterCommand(string& keyw, string& usage, CmdExecutor * ce, string grp)
     441void Commander::AddHelpGroup(string& grp, string& desc)
     442{
     443  int gid;
     444  CheckHelpGrp(grp, gid, desc);
     445}
     446
     447/* --Methode-- */
     448void Commander::RegisterCommand(string& keyw, string& usage, CmdExecutor * ce, string& grp)
    439449{
    440450if (!ce) {
     
    442452  return;
    443453  }
    444 int gid = CheckHelpGrp(grp);
     454int gid;
     455CheckHelpGrp(grp,gid);
    445456cmdex cme;
    446457cme.group = gid;
     
    453464void Commander::RegisterHelp(string& keyw, string& usage, string& grp)
    454465{
    455 int gid = CheckHelpGrp(grp);
     466int gid;
     467CheckHelpGrp(grp,gid);
    456468cmdex cme;
    457469cme.group = gid;
     
    462474
    463475/* --Methode-- */
    464 int Commander::CheckHelpGrp(string& grp)
    465 {
    466 int gid=0;
     476bool Commander::CheckHelpGrp(string& grp, int& gid, string& desc)
     477{
     478gid = 0;
    467479CmdHGroup::iterator it = cmdhgrp.find(grp);
    468480if (it == cmdhgrp.end()) {
    469   cmdgrpid++;   gid = cmdgrpid;
    470   cmdhgrp[grp] = gid;
    471   //  _helpmgr->AddHelpGroup(grp.c_str(), gid);
    472   }
    473 else gid = (*it).second;
    474 return(gid);
     481  cmdgrpid++;  gid = cmdgrpid;
     482  hgrpst hgs;  hgs.gid = gid;  hgs.desc = desc;
     483  cmdhgrp[grp] = hgs;
     484  return true;
     485  }
     486else {
     487  if (desc.length() > 0)  (*it).second.desc = desc;
     488  gid = (*it).second.gid;
     489  return false;
     490}
    475491}
    476492
     
    17361752    if (! isalnum(prl[k]) )  prl[k] = 'Z';
    17371753}
     1754
    17381755// Fonction qui remplace _ en \_
    17391756static string check_latex_underscore(string const & mot)
     
    17411758  string rs;
    17421759  for(int k=0; k<mot.length(); k++) {
    1743     if (mot[k] == '_') rs += "\\_";
     1760    if (mot[k] == '_')  rs += "\\_";
    17441761    else rs += mot[k];
    17451762  }
     
    18001817int gid;
    18011818for(it = cmdhgrp.begin(); it != cmdhgrp.end(); it++) {
    1802   gid = (*it).second;
     1819  gid = (*it).second.gid;
    18031820  if (gid == 0)  continue;
    18041821  //  fputs("\\begin{table}[h!] \n",fip);
    18051822  fputs("\\vspace{6mm} \n",fip);
    18061823  fputs("\\begin{center} \n ", fip);
    1807   fprintf(fip, "\\rule{2cm}{1mm} \\makebox[60mm]{{ \\bf %s } help group} \\rule{2cm}{1mm} \\\\ \n",
     1824  fprintf(fip, "\\rule{2cm}{0.5mm} \\makebox[60mm]{{ \\bf %s } help group} \\rule{2cm}{0.5mm} \\\\ \n",
    18081825          (*it).first.c_str());
    18091826  fputs("\\vspace{3mm} \n",fip);
     
    18411858
    18421859for(it = cmdhgrp.begin(); it != cmdhgrp.end(); it++) {
    1843   gid = (*it).second;
     1860  gid = (*it).second.gid;
    18441861  if (gid == 0)  continue;
    18451862  prl = (*it).first;  check_latex_reflabel(prl);
    18461863  fprintf(fip,"\\subsection{%s} \\label{%s} \n",
    18471864          (*it).first.c_str(), prl.c_str());
     1865  if ((*it).second.desc.length() > 0)
     1866    fprintf(fip,"%s \n \\\\[2mm]  ", (*it).second.desc.c_str());
    18481867  fprintf(fip,"\\noindent \n");
    18491868  for(ite = helpexmap.begin(); ite != helpexmap.end(); ite++) {
     
    18701889
    18711890fclose(fip);
     1891cout << " Commander::HelptoLaTeX() - LaTeX format help written to file " <<  fname << endl;
     1892 
    18721893return;
    18731894}
  • trunk/SophyaLib/SysTools/commander.h

    r2446 r2466  
    7373  virtual string        Name();
    7474
     75  virtual void          AddHelpGroup(string& grp, string& desc);
    7576  virtual void          RegisterCommand(string& keyw, string& usage, CmdExecutor * ce,
    76                                         string grp="Commands");
     77                                        string& grp);
     78  inline  void          RegisterCommand(string& keyw, string& usage, CmdExecutor * ce,
     79                                        char* grp)
     80                        { string sgrp = grp; RegisterCommand(keyw, usage, ce, sgrp); }
     81
    7782  virtual void          RegisterHelp(string& keyw, string& usage, string& grp);
    7883
     
    104109                            string& toks, bool uq=true);
    105110protected:
    106   virtual int   CheckHelpGrp(string& grp);
     111  virtual bool  CheckHelpGrp(string& grp, int& gid, string& desc);
     112  inline  bool  CheckHelpGrp(string& grp, int& gid)
     113  { string desc=""; return CheckHelpGrp(grp, gid, desc); }
     114
    107115  int           ExecuteCommandLine(string & keyw, vector<string> & args,
    108116                                   string & toks);
     
    135143// Pour enregistrer la liste de commandes et leurs executeurs et le help
    136144  struct cmdex {int group; string us; CmdExecutor * cex; } ;
    137   typedef map<string, int, less<string> > CmdHGroup;   // Liste des groupes de commandes
     145  struct hgrpst {int gid; string desc; } ;               // Identification+description d'un groupe de help
     146  typedef map<string, hgrpst, less<string> > CmdHGroup;   // Liste des groupes de commandes
    138147  CmdHGroup cmdhgrp;
    139   int cmdgrpid;                                     // Numero de groupe courant
    140   typedef map<string, cmdex, less<string> > CmdExmap;
    141   CmdExmap cmdexmap;
    142   CmdExmap helpexmap;                               // Pour les helps sans commande
     148  int cmdgrpid;                                        // Numero de groupe courant
     149  typedef map<string, cmdex, less<string> > CmdExmap; 
     150  CmdExmap cmdexmap;                                   // Liste des commandes et leurs executeurs
     151  CmdExmap helpexmap;                                  // Pour les helps sans commande
    143152
    144153// Pour garder la liste des modules
Note: See TracChangeset for help on using the changeset viewer.