Changeset 8727


Ignore:
Timestamp:
2004-12-03T11:21:34+13:00 (19 years ago)
Author:
kjdon
Message:

added some changes made by Emanuel Dejanu (Simple Words)

Location:
trunk/gsdl/lib
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/lib/cfgread.cpp

    r7733 r8727  
    2727#include <ctype.h> // for isspace()
    2828
    29 int write_ini_line (ofstream &fileout, const text_t &key, const text_t value) {
     29int write_ini_line (ofstream &fileout, const text_t &key, const text_t &value) {
    3030  if (key.empty() || value.empty()) return -1;
    3131  outconvertclass text_t2ascii;
     
    6767    else fileout << text_t2ascii << "  \"" << *here << "\"";
    6868    first = false;
    69     here ++;
     69    ++here;
    7070  }
    7171  fileout << "\n";
     
    8383    char *s=here->getcstr();
    8484    write(fileout,s ,here->size());
    85     delete s;
     85    delete []s;
    8686
    8787    ++here;
     
    9191    char *s=here->getcstr();
    9292    write(fileout,s ,here->size());
    93     delete s;
     93    delete []s;
    9494    write(fileout, "\"", 1);
    9595
  • trunk/gsdl/lib/cfgread.h

    r3010 r8727  
    4040
    4141// return 0 on success, -1 on failure
    42 int write_ini_line (ofstream &fileout, const text_t &key, const text_t value);
     42int write_ini_line (ofstream &fileout, const text_t &key, const text_t &value);
    4343int read_ini_line (ifstream &filein, text_t &key, text_t &value);
    4444int write_cfg_line (ofstream &fileout, const text_tarray &values);
  • trunk/gsdl/lib/cnfgable.cpp

    r1860 r8727  
    1313#include "cfgread.h"
    1414
    15 bool configurable::read_configfile (text_t filename) {
     15bool configurable::read_configfile (const text_t &filename) {
    1616  // read in the build configuration file
    1717  text_t key;
     
    1919  char *cstr = filename.getcstr();
    2020  ifstream confin (cstr);
    21   delete cstr;
     21  delete []cstr;
    2222
    2323  if (confin) {
  • trunk/gsdl/lib/cnfgable.h

    r1860 r8727  
    99  virtual ~configurable () {}
    1010
    11   bool read_configfile (text_t filename);
     11  bool read_configfile (const text_t &filename);
    1212 protected:
    1313  configurable() {}
  • trunk/gsdl/lib/cnfgator.cpp

    r1860 r8727  
    2020}
    2121
    22 bool configurator::configure(text_t filename) {
     22bool configurator::configure(const text_t &filename) {
    2323  // read in the build configuration file
    2424  text_t key;
     
    2626  char *cstr = filename.getcstr();
    2727  ifstream confin (cstr);
    28   delete cstr;
     28  delete []cstr;
    2929
    3030  if (confin) {
     
    4040    while (configureIter != configureobjs.end()) {
    4141      configureObject = *configureIter;
    42       configureIter ++;
     42      ++configureIter;
    4343   
    4444      configureObject->configure (key, cfgline);
  • trunk/gsdl/lib/cnfgator.h

    r1896 r8727  
    1414 public:
    1515  configurator(configurable *configureobject);
    16   bool configure(text_t filename);
     16  bool configure(const text_t &filename);
    1717  void add_configurable(configurable *configureobject);
    1818};
  • trunk/gsdl/lib/display.cpp

    r8485 r8727  
    131131  // a Global macro will still be hid by a non-Global one with
    132132  // the same name.
    133   if ((package != "Global") &&
    134       (macro_find ("Global", macroname) != NULL))
     133  if ((package != displayclass::defaultpackage) &&
     134      (macro_find (displayclass::defaultpackage, macroname) != NULL))
    135135    {
    136136      warning -= 2; // found the macroname
     
    355355        {
    356356          // found the end of the parameter
    357           here++;
     357          ++here;
    358358          break;
    359359        }
     
    368368        }
    369369     
    370       here++;
     370      ++here;
    371371    }
    372372
     
    422422    }
    423423
    424       here++;
     424      ++here;
    425425    }
    426426 
     
    460460        {
    461461          // found the end of the key
    462           here ++;
     462          ++here;
    463463          break;
    464464        }
     
    472472          key.push_back (*here); // copy this character
    473473        }
    474       here ++;
     474      ++here;
    475475    }
    476476
     
    487487        {
    488488          // found the end of the value
    489           here ++;
     489          ++here;
    490490          break;
    491491        }
     
    499499          value.push_back (*here); // copy this character
    500500        }
    501       here ++;
     501      ++here;
    502502    }
    503503   
     
    546546}
    547547
     548inline int my_isalphanum (unsigned short c)
     549{
     550  return ((c >= 'A' && c <= 'Z') ||
     551      (c >= 'a' && c <= 'z') || (c >='0' && c <= '9'));
     552}
     553 
    548554
    549555
     
    553559  if (here != end)
    554560    {
    555       here++;
     561      ++here;
    556562      if (here != end) return (*here);
    557563    }
     
    604610//        -3 if it redefined a macro and hid a Global macro
    605611//        -4 if no macroname was supplied
    606 int displayclass::setdefaultmacro (text_t package, const text_t &macroname,
    607                    text_t mparams, const text_t &macrovalue)
     612int displayclass::setdefaultmacro (const text_t &package, const text_t &macroname,
     613                   const text_t &mparams, const text_t &macrovalue)
    608614{
    609615  return setdefaultmacro (package, macroname, mparams, "memory", macrovalue);
     
    683689  }
    684690
    685   if (c == '\n') line++;
     691  if (c == '\n') ++line;
    686692  return c;
    687693}
     
    693699//         1 if was (re)loaded
    694700//        -1 an error occurred while trying to load the file
    695 int displayclass::loadparammacros (parammacros_t* macrotable, text_t thisfilename) {
     701int displayclass::loadparammacros (parammacros_t* macrotable, const text_t &thisfilename) {
    696702  // convert the filename to a C string
    697703  char *filenamestr = thisfilename.getcstr();
     
    706712  if (fin.fail()) return -1; // read failed
    707713
    708   text_t package = "Global";
     714  text_t package = defaultpackage;
    709715  int line = 1;
    710716  int isunicode = 0, bigendian = 1;
     
    747753    // get the package name
    748754    tmp.clear(); // init tmp
    749     while (!fin.eof() && my_isalpha(c)) {
     755    while (!fin.eof() && my_isalphanum(c)) {
    750756      tmp.push_back(c);
    751757      c = my_uni_get(fin, line, isunicode, bigendian);
    752758    }
    753759    package = tmp;
    754     if (package.empty()) package = "Global";
     760    if (package.empty()) package = defaultpackage;
    755761
    756762      } else {
    757763    // error
    758764    if (logout != NULL) {
    759       (*logout) << text_t2ascii << "Expected 'package' on line " << line
    760             << " of " << thisfilename << "\n";
     765      (*logout) << text_t2ascii << text_t("Expected 'package' on line ") + line + text_t(" of ") + thisfilename + "\n";
    761766    }
    762767      }
     
    842847                   thisfilename, macrovalue);
    843848      if ((err == -1 || err == -3) && logout != NULL) {
    844         (*logout) << text_t2ascii << "Warning: redefinition of _" <<
    845           package << ":" << macroname << "_[" << macroparameters <<
    846           "] on line ";
    847         (*logout) << line;
    848         (*logout) << text_t2ascii << " of " << thisfilename << "\n";
     849        (*logout) << text_t2ascii << ("Warning: redefinition of _" + package + ":" + macroname + "_[" + macroparameters + "] on line " + line +  " of " + thisfilename + "\n");
    849850       
    850851      } else if (err == -2 && logout != NULL) {
     
    860861
    861862      } else if (err == -4 && logout != NULL) {
    862         (*logout) << text_t2ascii << "Error: macro name expected on line ";
    863         (*logout) << line ;
    864         (*logout) << text_t2ascii << " of " << thisfilename << "\n";
     863        (*logout) << text_t2ascii << text_t("Error: macro name expected on line ") +  line + text_t(" of ") + thisfilename + "\n";
    865864      }       
    866865     
     
    874873    // found an error, skip to the end of the line
    875874    if (logout != NULL) {
    876       (*logout) << text_t2ascii << "Error: ";
    877       if (err == 1) (*logout) << text_t2ascii << "'_'";
    878       else if (err == 2) (*logout) << text_t2ascii << "']'";
    879       else if (err == 3) (*logout) << text_t2ascii << "'}'";
    880       else if (err == 4) (*logout) << text_t2ascii << "'{'";
    881       (*logout) << text_t2ascii << " expected on line ";
    882       (*logout) << line ;
    883       (*logout) << text_t2ascii << " of " << thisfilename << "\n";
     875      text_t message = "Error: ";
     876      if (err == 1) message += "'_'";
     877      else if (err == 2) message += "']'";
     878      else if (err == 3) message += "'}'";
     879      else if (err == 4) message += "'{'";
     880      message += " expected on line ";
     881      message += line;
     882      message += " of " + thisfilename + "\n";
     883      (*logout) << text_t2ascii << message;
     884     
     885//    (*logout) << text_t2ascii << "Error: ";
     886//    if (err == 1) (*logout) << text_t2ascii << "'_'";
     887//    else if (err == 2) (*logout) << text_t2ascii << "']'";
     888//    else if (err == 3) (*logout) << text_t2ascii << "'}'";
     889//    else if (err == 4) (*logout) << text_t2ascii << "'{'";
     890//    (*logout) << text_t2ascii << " expected on line ";
     891//    (*logout) << line ;
     892//    (*logout) << text_t2ascii << " of " << thisfilename << "\n";
    884893    }
    885894    while (!fin.eof ()) {
     
    892901      // found an error, skip to the end of the line
    893902      if (logout != NULL) {
    894     (*logout) << text_t2ascii << "Error: Unexpected input on line " << line
    895           << " of " << thisfilename << "\n";
     903    (*logout) << text_t2ascii << text_t("Error: Unexpected input on line ") + line + text_t(" of ") + thisfilename + "\n";
    896904      }
    897905      while (!fin.eof ()) {
     
    906914 
    907915  // free up memory
    908   delete filenamestr;
     916  delete []filenamestr;
    909917  return 0;
    910918}
     
    915923//         1 if was (re)loaded
    916924//        -1 an error occurred while trying to load the file
    917 int displayclass::loaddefaultmacros (text_t thisfilename)
     925int displayclass::loaddefaultmacros (const text_t &thisfilename)
    918926{
    919927  return loadparammacros(defaultmacros,thisfilename);
     
    924932//         1 if was (re)loaded
    925933//        -1 an error occurred while trying to load the file
    926 int displayclass::loadcollectionmacros (text_t thisfilename)
     934int displayclass::loadcollectionmacros (const text_t &thisfilename)
    927935{
    928936  return loadparammacros(collectionmacros,thisfilename);
     
    975983  for (text_tsetit=allparams.begin();
    976984       text_tsetit!=allparams.end();
    977        text_tsetit++)
     985       ++text_tsetit)
    978986    {
    979987      tmpps.param = (*text_tsetit);
     
    9981006      cerr << text_t2ascii << "param=" << (*pshere).param;
    9991007      cerr << " spec=" << (int)((*pshere).spec) << "\n";
    1000       pshere++;
     1008      ++pshere;
    10011009    }
    10021010#endif
     
    10091017//        -4 if no macroname was supplied
    10101018int displayclass::setmacro (const text_t &macroname,
    1011                 text_t package,
     1019                const text_t &package,
    10121020                const text_t &macrovalue)
    10131021{
     
    10161024
    10171025  // make package "Global" if it doesn't point to anything yet
    1018   if (package.empty()) package = "Global";
    1019 
     1026  if (package.empty())
     1027    return currentmacros->setmacro(defaultpackage, macroname, "memory", macrovalue);
     1028 
    10201029  // set the macro
    10211030  return currentmacros->setmacro(package, macroname, "memory", macrovalue);
    10221031}
    10231032
    1024 
    1025 void displayclass::expandstring (const text_t &inputtext, text_t &outputtext)
    1026 {
    1027   expandstring("", inputtext, outputtext);
    1028 }
    1029 
    1030 
    1031 void displayclass::expandstring (text_t package, const text_t &inputtext,
     1033int displayclass::setmacroif (const text_t &macro_to_set_and_test,
     1034                  const text_t &macro_to_set_if_macro_not_set,
     1035                  const text_t &macroname, 
     1036                  const text_t &package) {
     1037 
     1038  if (macroname.empty()) return -4;
     1039  if (macro_to_set_and_test.empty()) return -40;
     1040 
     1041  text_t temp;
     1042  expandstring(defaultpackage, macro_to_set_and_test, temp);
     1043 
     1044  if (package.empty()) {
     1045    if (temp == macro_to_set_and_test) return currentmacros->setmacro(defaultpackage, macroname, "memory", macro_to_set_if_macro_not_set);
     1046    return currentmacros->setmacro(defaultpackage, macroname, "memory", macro_to_set_and_test);
     1047  } else {
     1048    if (temp == macro_to_set_and_test) return currentmacros->setmacro(package, macroname, "memory", macro_to_set_if_macro_not_set);
     1049    return currentmacros->setmacro(package, macroname, "memory", macro_to_set_and_test);
     1050   
     1051  }
     1052}
     1053
     1054void displayclass::expandstring (const text_t &package, const text_t &inputtext,
    10321055                 text_t &outputtext, int recursiondepth)
    10331056{
     
    10381061  int openbrackets=0;
    10391062
    1040   if (package.empty()) package = "Global";
     1063  if (package.empty()) expandstring(defaultpackage, inputtext, outputtext, recursiondepth);
    10411064
    10421065  outputtext.clear();
     
    11111134        {
    11121135          c = my_ttnextchar (tthere, ttend); // skip '('
    1113           openbrackets++;
     1136          ++openbrackets;
    11141137          // have to be careful of quotes
    11151138          unsigned short quote = '\0';
     
    11291152              if (c == '(')
    11301153                {
    1131                   openbrackets++;
     1154                  ++openbrackets;
    11321155////                  macroargs.push_back (c);
    11331156////                  c = my_ttnextchar (tthere, ttend);
     
    11351158              else if (c == ')')
    11361159                {
    1137                   openbrackets--;
     1160                  --openbrackets;
    11381161                  if (openbrackets==0) {
    11391162                // found end of the arguments
     
    11711194          // try to expand out this macro
    11721195          text_t expandedmacro;
    1173           if (macro (macroname, macropackage, macroargs, expandedmacro, recursiondepth))
     1196          if (macro (macroname, macropackage.empty()?defaultpackage:macropackage, macroargs, expandedmacro, recursiondepth))
    11741197        {
    11751198          // append the expanded macro
     
    12311254//           in the global package was found
    12321255//         2 if a macro in the given package was found
    1233 int displayclass::isdefaultmacro (text_t package, const text_t &macroname) {
     1256int displayclass::isdefaultmacro (const text_t &package, const text_t &macroname) {
    12341257  // make sure a macroname was supplied
    12351258  if (macroname.empty()) return 0;
    12361259
     1260  if (!package.empty()) {
     1261    // check the given package
     1262    if (defaultmacros->macro_find(package, macroname) != NULL) return 2;
     1263  }
     1264   
     1265  // check the Global package
     1266  if (defaultmacros->macro_find(defaultpackage, macroname) != NULL) return 1;
     1267  // not found
     1268  return 0;
     1269}
     1270
     1271// havemacro sees if there is an entry in the list of macros or
     1272// default macros with the given package and macro name
     1273// returns 0 if no macros in the package or in the global package
     1274//           were found
     1275//         1 if no macros in the package were found but a macro
     1276//           in the global package was found
     1277//         2 if a macro in the given package was found
     1278//         4 if no macros in the package were found but a macro
     1279//           in the global package was found in default macros
     1280//         8 if a macro in the given package was found in default
     1281int displayclass::havemacro(const text_t &package, const text_t &macroname)
     1282{
     1283  // make sure a macroname was supplied
     1284  if (macroname.empty()) return 0;
     1285 
    12371286  // make package "Global" if it doesn't point to anything yet
    1238   if (package.empty()) package = "Global";
    1239 
    1240   // check the given package
    1241   if (defaultmacros->macro_find(package, macroname) != NULL) return 2;
    1242 
    1243   // check the Global package
    1244   if (defaultmacros->macro_find("Global", macroname) != NULL) return 1;
    1245 
    1246   return 0;
    1247 }
    1248 
    1249 
     1287  if (package.empty()) {
     1288    // check the Global package in current macros list
     1289    if (currentmacros->macro_find(defaultpackage, macroname) != NULL) return 1;
     1290   
     1291    // check the Global package in default macros list
     1292    if (defaultmacros->macro_find(defaultpackage, macroname) != NULL) return 4;
     1293  } else {
     1294    // check the given package in current macros list
     1295    if (currentmacros->macro_find(package, macroname) != NULL) return 2;
     1296   
     1297    // check the Global package in current macros list
     1298    if (currentmacros->macro_find(defaultpackage, macroname) != NULL) return 1;
     1299   
     1300    // check the given package in default macros list
     1301    if (defaultmacros->macro_find(package, macroname) != NULL) return 8;
     1302   
     1303    // check the Global package in default macros list
     1304    if (defaultmacros->macro_find(defaultpackage, macroname) != NULL) return 4;
     1305  }
     1306}
     1307 
     1308 
    12501309// setparammacro adds an entry to the list of default macros
    12511310// returns 0 if there was no error,
     
    12551314//        -4 if no macroname was supplied
    12561315int displayclass::setparammacro (parammacros_t* macrotable,
    1257                  text_t package, const text_t &macroname,
    1258                  text_t macroparams, const text_t &filename,
     1316                 const text_t &package,
     1317                 const text_t &macroname,
     1318                 text_t macroparams,
     1319                 const text_t &filename,
    12591320                 const text_t &macrovalue)
    12601321{
     
    12681329  joinparams (paramhash, macroparams);
    12691330
    1270   // make package "Global" if it doesn't point to anything yet
    1271   if (package.empty()) package = "Global";
    1272 
    12731331  // remember these parameters
    12741332  allparams.insert (macroparams);
     
    12771335
    12781336  // set the macro
    1279   return macrotable->setmacro(package, macroname, macroparams, filename,
    1280                   macrovalue);
     1337  if (package.empty()) {
     1338    return macrotable->setmacro(defaultpackage, macroname, macroparams, filename, macrovalue);
     1339  } else {
     1340    return macrotable->setmacro(package, macroname, macroparams, filename, macrovalue);
     1341  }
    12811342}
    12821343
     
    12871348//        -3 if it redefined a macro and hid a Global macro
    12881349//        -4 if no macroname was supplied
    1289 int displayclass::setdefaultmacro (text_t package, const text_t &macroname,
    1290                    text_t macroparams, const text_t &filename,
     1350int displayclass::setdefaultmacro (const text_t &package,
     1351                   const text_t &macroname,
     1352                   text_t macroparams,
     1353                   const text_t &filename,
    12911354                   const text_t &macrovalue)
    12921355{
    1293   return setparammacro(defaultmacros,package,macroname,macroparams,
    1294                filename,macrovalue);
     1356  return setparammacro(defaultmacros,package,macroname,
     1357               macroparams,filename,macrovalue);
    12951358}
    12961359
    12971360// public function
    1298 int displayclass::setcollectionmacro(text_t package, const text_t &macroname,
    1299                      text_t mparams, const text_t &macrovalue)
     1361int displayclass::setcollectionmacro(const text_t &package,
     1362                     const text_t &macroname,
     1363                     text_t mparams,
     1364                     const text_t &macrovalue)
    13001365{
    13011366  return setcollectionmacro(package, macroname, mparams, "memory", macrovalue);
     
    13081373//        -3 if it redefined a macro and hid a Global macro
    13091374//        -4 if no macroname was supplied
    1310 int displayclass::setcollectionmacro (text_t package, const text_t &macroname,
    1311                       text_t mparams, const text_t &filename,
     1375int displayclass::setcollectionmacro (const text_t &package,
     1376                      const text_t &macroname,
     1377                      text_t mparams,
     1378                      const text_t &filename,
    13121379                      const text_t &macrovalue)
    13131380{
     
    13221389// format "XXXX" eq/ne "dddd" in which case
    13231390// the two quoted strings are compared
    1324 bool displayclass::boolexpr (text_t package, const text_t &expr, int recursiondepth) {
     1391bool displayclass::boolexpr (const text_t &package, const text_t &expr, int recursiondepth) {
    13251392
    13261393  if (expr.empty()) return false;
    13271394
    13281395  text_t expexpr;
    1329   if (package.empty()) package = "Global"; 
    1330   expandstring (package, expr, expexpr, recursiondepth);
    1331 
     1396  if (package.empty()) {
     1397    expandstring (defaultpackage, expr, expexpr, recursiondepth);
     1398  } else {
     1399    expandstring (package, expr, expexpr, recursiondepth);
     1400  }
    13321401  if (expexpr.empty() || expexpr == "0") return false;
    13331402  if (expr[0] != '\"') return true;
     
    13541423    op.clear();
    13551424    while (here != end) {
    1356       if (*here == '"') quotecount++;
     1425      if (*here == '"') ++quotecount;
    13571426      else if (quotecount == 1) string1.push_back(*here);
    13581427      else if ((quotecount == 2) && !is_unicode_space (*here))
     
    13601429      else if (quotecount == 3) string2.push_back(*here);
    13611430      else if (quotecount >= 4) break;
    1362       here ++;
     1431      ++here;
    13631432    }
    13641433   
     
    13901459    while (here != end && *here != '"') {
    13911460      if (!is_unicode_space(*here)) combineop.push_back(*here);
    1392       here++;
     1461      ++here;
    13931462    }
    13941463  }
     
    13981467
    13991468
    1400 mvalue* displayclass::macro_find (parammacros_t* macrotable, text_t packagename,
     1469mvalue* displayclass::macro_find (parammacros_t* macrotable,
     1470                  const text_t &packagename,
    14011471                  const text_t &macroname)
    14021472{
     
    14131483      macrovalue = macrotable->parameter_find(packagename, macroname,
    14141484                          (*paramhere).param);
    1415       paramhere++;
     1485      ++paramhere;
    14161486    }
    14171487    }
     
    14241494// returns true  if the macro was found
    14251495//         false if the macro was not found
    1426 bool displayclass::macro (const text_t &macroname, text_t macropackage,
    1427              const text_t &macroparam, text_t &outputtext,
    1428              int recursiondepth)
    1429 {
    1430   outconvertclass text_t2ascii;
     1496// macropackage should never be empty
     1497bool displayclass::macro (const text_t &macroname,
     1498              const text_t &macropackage,
     1499              const text_t &macroparam,
     1500              text_t &outputtext,
     1501              int recursiondepth)
     1502{
     1503  assert(!macropackage.empty()); //???
     1504  //outconvertclass text_t2ascii;
    14311505  text_tlist splitmacroparam;
    14321506  text_t::const_iterator hereit, endit;
     
    14441518
    14451519  // check the macropackage
    1446   if (macropackage.empty()) macropackage = "Global";
     1520  //if (macropackage.empty()) macropackage = "Global";
    14471521
    14481522  // get the parameters (but don't expand them)
     
    14871561    } else if (c=='(') {
    14881562      aparam.push_back(c);
    1489       openbrackets++;
     1563      ++openbrackets;
    14901564    } else if (c==')') {
    1491       openbrackets--;
     1565      --openbrackets;
    14921566      aparam.push_back(c);
    14931567    } else {
     
    15141588    if (paramcond != paramend) {
    15151589      paramthen = paramcond;
    1516       paramthen++;
     1590      ++paramthen;
    15171591    }
    15181592    if (paramthen != paramend) {
    15191593      paramelse = paramthen;
    1520       paramelse++;
     1594      ++paramelse;
    15211595    }
    15221596   
     
    15841658      }
    15851659
    1586       if (macrovalue == NULL) packagehere++;
     1660      if (macrovalue == NULL) ++packagehere;
    15871661    }
    15881662
     
    16261700        text_tlist::iterator ttlistend = splitmacroparam.end();
    16271701        while ((argnum > 1) && (ttlisthere != ttlistend)) {
    1628           argnum--;
    1629           ttlisthere++;
     1702          --argnum;
     1703          ++ttlisthere;
    16301704        }
    16311705        if (ttlisthere != ttlistend) {
     
    16641738  // GRB: deal with remaining code properly as it faults
    16651739  return false;
    1666 
     1740  outconvertclass text_t2ascii;
    16671741  if (logout != NULL) {
    16681742    (*logout) << text_t2ascii << "Warning: _" <<
     
    16861760  for (packagemapit = defaultmacros->package_begin();
    16871761       packagemapit != defaultmacros->package_end();
    1688        packagemapit++)
     1762       ++packagemapit)
    16891763    {
    16901764      packagename = (*packagemapit).first;
     
    16931767      for (macromapit = (*packagemapit).second.begin();
    16941768       macromapit != (*packagemapit).second.end();
    1695        macromapit++)
     1769       ++macromapit)
    16961770    {
    16971771      macroname = (*macromapit).first;
     
    17001774      for (parammapit = (*macromapit).second.begin();
    17011775           parammapit != (*macromapit).second.end();
    1702            parammapit++)
     1776           ++parammapit)
    17031777        {
    17041778          macroparam = (*parammapit).first;
     
    17221796  for (text_tsetit=allparams.begin();
    17231797       text_tsetit!=allparams.end();
    1724        text_tsetit++) {
     1798       ++text_tsetit) {
    17251799    cerr << text_t2ascii << (*text_tsetit) << "\n";
    17261800  }
  • trunk/gsdl/lib/display.h

    r8485 r8727  
    178178  //           in the global package was found
    179179  //         2 if a macro in the given package was found
    180   int isdefaultmacro (text_t package, const text_t &macroname);
     180  int isdefaultmacro (const text_t &package, const text_t &macroname);
    181181
    182182  // setdefaultmacro adds an entry to the list of default macros
     
    186186  //        -3 if it redefined a macro and hid a Global macro
    187187  //        -4 if no macroname was supplied
    188   int setdefaultmacro (text_t package, const text_t &macroname,
    189                text_t params, const text_t &macrovalue);
     188  int setdefaultmacro (const text_t &package,
     189               const text_t &macroname,
     190               const text_t &params,
     191               const text_t &macrovalue);
    190192 
    191193  // loads a default macro file (if it isn't already loaded)
     
    193195  //         1 if was (re)loaded
    194196  //        -1 an error occurred while trying to load the file
    195   int loaddefaultmacros (text_t thisfilename);
     197  int loaddefaultmacros (const text_t &thisfilename);
    196198
    197199
     
    200202  //        -1 if it redefined a macro
    201203  //        -4 if no macroname was supplied
    202   int setcollectionmacro (text_t package, const text_t &macroname,
    203               text_t params, const text_t &macrovalue);
     204  int setcollectionmacro (const text_t &package,
     205              const text_t &macroname,
     206              text_t params,
     207              const text_t &macrovalue);
    204208
    205209  // loads a collection specific macro file
     
    207211  //         1 if was (re)loaded
    208212  //        -1 an error occurred while trying to load the file
    209   int loadcollectionmacros (text_t thisfilename);
     213  int loadcollectionmacros (const text_t &thisfilename);
    210214
    211215  // unloads all default macros
     
    230234  //        -4 if no macroname was supplied
    231235  int setmacro (const text_t &macroname,
    232         text_t package,
     236        const text_t &package,
    233237        const text_t &macrovalue);
    234238 
    235   void expandstring (const text_t &inputtext, text_t &outputtext);
    236   void expandstring (text_t package, const text_t &inputtext,
     239// havemacro sees if there is an entry in the list of macros or
     240// default macros with the given package and macro name
     241// returns 0 if no macros in the package or in the global package
     242//           were found
     243//         1 if no macros in the package were found but a macro
     244//           in the global package was found
     245//         2 if a macro in the given package was found
     246//         4 if no macros in the package were found but a macro
     247//           in the global package was found in default macros
     248//         8 if a macro in the given package was found in default
     249  int havemacro(const text_t &package, const text_t &macroname);
     250
     251  int setmacroif (const text_t &macro_to_set_and_test,
     252          const text_t &macro_to_set_if_macro_not_set,
     253          const text_t &macroname,
     254          const text_t& package);
     255 
     256  inline void expandstring (const text_t &inputtext, text_t &outputtext) { expandstring(defaultpackage, inputtext, outputtext); }
     257
     258  void expandstring (const text_t &package, const text_t &inputtext,
    237259             text_t &outputtext, int recursiondepth = 0);
    238260
     
    275297  int checkdefaultmacrofiles ();
    276298
    277   int loadparammacros (parammacros_t* macrotable, text_t thisfilename);
     299  int loadparammacros (parammacros_t* macrotable, const text_t &thisfilename);
    278300
    279301  int setparammacro (parammacros_t* macrotable,
    280              text_t package, const text_t &macroname,
     302             const text_t &package,
     303             const text_t &macroname,
    281304             text_t params, const text_t &filename,
    282305             const text_t &macrovalue);
    283306
    284   int setdefaultmacro (text_t package, const text_t &macroname,
     307  int setdefaultmacro (const text_t &package,
     308               const text_t &macroname,
    285309               text_t params, const text_t &filename,
    286310               const text_t &macrovalue);
    287311
    288   int setcollectionmacro (text_t package, const text_t &macroname,
    289               text_t params, const text_t &filename,
    290               const text_t &macrovalue);
    291 
     312  int setcollectionmacro(const text_t &package,
     313             const text_t &macroname,
     314             text_t params,
     315             const text_t &filename,
     316             const text_t &macrovalue);
     317 
    292318  // evaluates a boolean expression
    293   bool boolexpr (text_t package, const text_t &expr, int recursiondepth);
    294 
    295   mvalue* macro_find (parammacros_t* macrotable, text_t packagename,
     319  bool boolexpr (const text_t &package, const text_t &expr,
     320         int recursiondepth);
     321
     322  mvalue* macro_find (parammacros_t* macrotable,
     323              const text_t &packagename,
    296324              const text_t &macroname);
    297325
     
    299327  // returns true  if the macro was found
    300328  //         false if the macro was not found
    301   bool macro (const text_t &macroname, text_t macropackage,
     329  bool macro (const text_t &macroname,
     330          const text_t &macropackage,
    302331          const text_t &macroparam, text_t &outputtext,
    303332          int recursiondepth);
  • trunk/gsdl/lib/fileutil.cpp

    r3527 r8727  
    4949    // remove all trailing slashes
    5050    here = path1.end();
    51     here--;
     51    --here;
    5252    begin = path1.begin();
    5353    while (here != begin && (*here == '/' || *here == '\\')) {
    54       here--;
     54      --here;
    5555    }
    56     here++;
     56    ++here;
    5757    path1.erase(here,path1.end());
    5858   
     
    6969  end = path2.end();
    7070  while (here != end && (*here == '/' || *here == '\\')) {
    71     here++;
     71    ++here;
    7272  }
    7373  path2.erase (path2.begin(), here);
     
    8484    if (*here == '\\') *here = '/';
    8585#endif
    86     here ++;
     86    ++here ;
    8787  }
    8888  return fullpath;
     
    116116  ifstream filestream (cstr, ios::in);
    117117#endif
    118   delete cstr;
     118  delete []cstr;
    119119 
    120120  if (filestream) {
     
    136136  ifstream filestream (cstr, ios::out);
    137137#endif
    138   delete cstr;
     138  delete []cstr;
    139139 
    140140  if (filestream) {
     
    162162  hSearch = FindFirstFile(dirpath, &FileData);
    163163  if (hSearch == INVALID_HANDLE_VALUE) {
    164     delete dirpath;
     164    delete []dirpath;
    165165    return false;
    166166  }
    167167
    168168  FindClose (hSearch);
    169   delete dirpath;
     169  delete []dirpath;
    170170  return true;
    171171}
     
    181181  hSearch = FindFirstFile(dirpath, &FileData);
    182182  if (hSearch == INVALID_HANDLE_VALUE) {
    183     delete dirpath;
     183    delete []dirpath;
    184184    return false;
    185185  }
     
    197197 
    198198  FindClose(hSearch);
    199   delete dirpath;
     199  delete []dirpath;
    200200 
    201201  return true;
     
    212212  hSearch = FindFirstFile(dirpath, &FileData);
    213213  if (hSearch == INVALID_HANDLE_VALUE) {
    214     delete dirpath;
     214    delete []dirpath;
    215215    return false;
    216216  }
     
    228228 
    229229  FindClose(hSearch);
    230   delete dirpath;
     230  delete []dirpath;
    231231
    232232  return true;
     
    241241  char *tmp = dirname.getcstr();
    242242  DIR *dirin = opendir (tmp);
    243   delete tmp;
     243  delete []tmp;
    244244 
    245245  if (dirin == NULL) return false;
     
    252252  char *tmp = dirname.getcstr();
    253253  DIR *dirin = opendir (tmp);
    254   delete tmp;
     254  delete []tmp;
    255255 
    256256  if (dirin == NULL) return false;
     
    273273  char *tmp = dirname.getcstr();
    274274  DIR *dirin = opendir (tmp);
    275   delete tmp;
     275  delete []tmp;
    276276 
    277277  if (dirin == NULL) return false;
     
    321321#endif
    322322
    323   delete fromfilec;
    324   delete tofilec;
     323  delete []fromfilec;
     324  delete []tofilec;
    325325  if (fail) return false;
    326326  return true;
     
    353353  char linec[MAXLINELENGTH];
    354354  ifstream file_in (filenamec);
    355   delete filenamec;
     355  delete []filenamec;
    356356  if (file_in) {
    357357    file_in.seekg (0, ios::end);
     
    371371      break;
    372372    }
    373     here ++;
     373    ++here;
    374374      }
    375375    }
     
    395395  char *dirnamec = dirname.getcstr();
    396396  int rv = _mkdir (dirnamec);
    397   delete dirnamec;
     397  delete []dirnamec;
    398398  if (rv == 0) return true;
    399399  return false;
     
    411411  char *dirnamec = dirname.getcstr();
    412412  int rv = mkdir (dirnamec, mode);
    413   delete dirnamec;
     413  delete []dirnamec;
    414414  if (rv == 0) return true;
    415415  return false;
     
    429429  ifstream file_in (filenamec, ios::in);
    430430#endif
    431   delete filenamec;
     431  delete []filenamec;
    432432
    433433  if (file_in) {
  • trunk/gsdl/lib/gsdlconf.h

    r3155 r8727  
    2929
    3030#define GSDL_VERSION "x.xx"
     31
     32#if defined(__WIN32__) || defined(_WIN32) || defined(_WIN32_) || defined(WIN32)
     33#ifndef __WIN32__
     34#define __WIN32__ 1
     35#endif
     36#endif
    3137
    3238#if defined(__WIN32__) && !defined(__CYGWIN__)
  • trunk/gsdl/lib/gsdltimes.cpp

    r3516 r8727  
    3535  tm *tm_ptr = localtime(&time);
    3636
    37   if (tm_ptr == NULL) return "";
     37  if (tm_ptr == NULL) return g_EmptyText;
    3838
    3939  // year
     
    142142  if (ltime) tm_ptr = localtime (&t);
    143143  else tm_ptr = gmtime (&t);
    144   if (tm_ptr == NULL) return "";
     144  if (tm_ptr == NULL) return g_EmptyText;
    145145  char *timestr = new char[128];
    146146  text_t ret;
  • trunk/gsdl/lib/gsdltools.cpp

    r2937 r8727  
    5353}
    5454
     55void dm_js_safe(const text_t &instring, text_t &outstring)
     56{
     57  text_t::const_iterator here = instring.begin();
     58  text_t::const_iterator end = instring.end();
     59  while (here != end) {
     60    if (*here == '_') outstring.push_back('\\');
     61    else if (*here == '\\' || *here == '\'') {
     62      outstring.push_back('\\');
     63      outstring.push_back('\\');
     64    }
     65    outstring.push_back(*here);
     66    ++here;
     67  }
     68}
     69
    5570// gsdl_system creates a new process for the cmd command (which
    5671// may contain arguments).
     
    95110    logout << "gsdl_system failed to start " << cmd_c
    96111       << " process, error code " << GetLastError();
    97     delete cmd_c;
     112    delete []cmd_c;
    98113    return -1;
    99114  }
     
    118133      logout << "gsdl_system failed to start " << cmd_c
    119134         << " process, command interpreter not found\n";
    120       delete cmd_c;
     135      delete []cmd_c;
    121136      return -1;
    122137    }
     
    126141    int pid = fork();
    127142    if (pid == -1) {
    128       delete cmd_c;
     143      delete []cmd_c;
    129144      return -1;
    130145    }
     
    141156#endif
    142157
    143   delete cmd_c;
     158  delete []cmd_c;
    144159  return ret;
    145160}
  • trunk/gsdl/lib/gsdltools.h

    r1817 r8727  
    4242text_t dm_safe (const text_t &instring);
    4343
     44// escapes "\", "'" and "_" characters with '\'
     45// note that single '\' characters occurring
     46// naturally within text (or filenames!!) will
     47// be removed by the dm macro language
     48//WARNING: instring will be appended to outstring
     49// so is your responsability to clean the outstring
     50// before call this function;
     51void dm_js_safe(const text_t &instring, text_t &outstring);
     52inline text_t dm_js_safe (const text_t &instring) {text_t outstring; dm_js_safe(instring, outstring); return outstring;}
     53
    4454// gsdl_system creates a new process for the cmd command (which
    4555// may contain arguments).
  • trunk/gsdl/lib/gsdlunicode.cpp

    r8666 r8727  
    5757  while (here != end) {
    5858    charlen = output_utf8_char (*here, thischar, &thischar[MAXUTF8CHARLEN-1]);
    59     for (i=0; i<charlen; i++) out.push_back(thischar[i]);
    60     here++;
     59    for (i=0; i<charlen; ++i) out.push_back(thischar[i]);
     60    ++here;
    6161  }
    6262
     
    7676
    7777  // get the last valid character in the string
    78   while (*end != '\0') end++;
    79   end--;
     78  while (*end != '\0') ++end;
     79  --end;
    8080
    8181  while ((charlen = parse_utf8_char (here, end, &unichar)) > 0) {
     
    8484  }
    8585
    86   delete in_cstr;
     86  delete []in_cstr;
    8787
    8888  return out;
     
    101101  text_t::iterator textend = input->end();
    102102  len = 0;
    103   if (maxlen % 2) maxlen--; // we need an even number of output bytes...
     103  if (maxlen % 2) --maxlen; // we need an even number of output bytes...
    104104  while ((len < maxlen) && (texthere != textend)) {
    105105    unsigned short int uni_char=(unsigned short int) *texthere;
     
    183183      int i;
    184184      int diff = utf8buflen - realcharlen;
    185       for (i=0; i < diff; i++) utf8buf[i] = utf8buf[i+diff];
     185      for (i=0; i < diff; ++i) utf8buf[i] = utf8buf[i+diff];
    186186      utf8buflen = diff;
    187187      charlen = getutf8charlen ();
     
    244244      while (len < maxlen && utf8bufhere < utf8buflen) {
    245245    *uoutput = utf8buf[utf8bufhere];
    246     uoutput++;
    247     len++;
    248     utf8bufhere++;
     246    ++uoutput;
     247    ++len;
     248    ++utf8bufhere;
    249249      }
    250250
     
    261261    utf8buflen = output_utf8_char (*texthere, utf8buf,
    262262                       &utf8buf[MAXUTF8CHARLEN-1]);
    263       texthere++;
     263      ++texthere;
    264264      utf8bufhere = 0;
    265265    }
     
    276276
    277277mapdata_t::mapdata_t () {
    278   int i;
    279278
    280279  // reset all the map ptrs to be NULL
    281   for (i=0; i<256; i++) {
     280  for (int i=0; i<256; ++i) {
    282281    ptrs[i] = (unsigned short *)NULL;
    283282  }
     
    323322  if (cfilename == (char *)NULL) return false;
    324323  mapfilein = fopen(cfilename, "rb");
    325   delete cfilename;
     324  delete []cfilename; cfilename = NULL;
    326325
    327326  if (mapfilein == (FILE *)NULL) return false;
     
    339338
    340339    // clear the array
    341     for (i=0; i<256; i++) arrptr[i] = 0;
     340    for (i=0; i<256; ++i) arrptr[i] = 0;
    342341   
    343342    // read in this block
     
    348347      arrptr[i] = ((unsigned short)n1 << 8) | (unsigned short)n2;
    349348
    350       i++;
     349      ++i;
    351350      if (i >= 256) break;
    352351      n1 = fgetc (mapfilein);
     
    365364  if (!mapdata.loaded) return;
    366365
    367   int i;
    368   for (i=0; i<256; i++) {
     366  for (int i=0; i<256; ++i) {
    369367    if (mapdata.ptrs[i] != (unsigned short *)NULL) {
    370368      delete [] mapdata.ptrs[i];
     
    405403  while (here != end) {
    406404    outstr.push_back(this->convert(*here));
    407     here++;
     405    ++here;
    408406  }
    409407 
     
    517515      while (len < maxlen && mapbufhere < mapbuflen) {
    518516    *uoutput = mapbuf[mapbufhere];
    519     uoutput++;
    520     len++;
    521     mapbufhere++;
     517    ++uoutput;
     518    ++len;
     519    ++mapbufhere;
    522520      }
    523521
     
    548546      }
    549547
    550       texthere++;
     548      ++texthere;
    551549      mapbufhere = 0;
    552550    }
     
    568566  ifstream mapfilein (cfilename, ios::in);
    569567#endif
    570   delete cfilename;
     568  delete []cfilename;
    571569  if (!mapfilein) return false;
    572570
     
    601599    sscanf (from, "%i", &f);
    602600    sscanf (to, "%i", &t);
    603     delete from;
    604     delete to;
     601    delete []from;
     602    delete []to;
    605603   
    606604    if (in) mapping[(unsigned short)f] = (unsigned short)t;
  • trunk/gsdl/lib/text_t.cpp

    r7382 r8727  
    2828/*
    2929   $Log$
     30   Revision 1.23  2004/12/02 22:21:34  kjdon
     31   added some changes made by Emanuel Dejanu (Simple Words)
     32
    3033   Revision 1.22  2004/05/24 03:43:22  mdewsnip
    3134   (Human Info) Added const text_t g_EmptyText("") to use instead of plain ol' "".
     
    123126
    124127// new stream converter ...
    125 ostream& operator<< (ostream &o, const text_t text)
     128ostream& operator<< (ostream &o, const text_t &text)
    126129{
    127130  text_t::const_iterator ithere = text.begin();
     
    144147      o << '?';
    145148      }
    146       ithere++;
     149      ++ithere;
    147150    }
    148151
     
    163166}
    164167
    165 text_t::text_t (char *s)
     168text_t::text_t (const char *s)
    166169{
    167170  setencoding(0);
     
    170173}
    171174
     175text_t::text_t (const char *s, size_type nLength)
     176{
     177  setencoding(0);
     178  clear ();
     179  appendcarr(s, nLength);
     180}
     181
    172182
    173183void text_t::append (const text_t &t)
    174184{
    175185  text.insert(text.end(), t.begin(), t.end());
    176   //  const_iterator here, end=t.end();
    177   //  for (here=t.begin(); here!=end;here++)
    178   //    {
    179   //      text.push_back(*here);
    180   //    }
    181186}
    182187
     
    184189{
    185190  text.insert(text.end(), first, last);
    186   //  while (first != last)
    187   //  {
    188   //    text.push_back (*first);
    189   //    first++;
    190   //  }
    191191}
    192192
     
    194194{
    195195  text.insert(text.end(), first, last);
    196   //  while (first != last)
    197   //  {
    198   //    text.push_back (*first);
    199   //    first++;
    200   //  }
    201196}
    202197
     
    233228    }
    234229
    235   delete buf;
     230  delete []buf;
    236231}
    237232
     
    255250    {
    256251      mult = 1;
    257       here++;
     252      ++here;
    258253    }
    259254    }
     
    263258    {
    264259      i = 10*i + (*here - '0');
    265       here++;
     260      ++here;
    266261    }
    267262
     
    280275    {
    281276      i = 10*i + (*here - '0');
    282       here++;
     277      ++here;
    283278    }
    284279
     
    286281}
    287282
    288 void text_t::appendcarr (char *s, size_type len)
     283void text_t::appendcarr (const char *s, size_type len)
    289284{
    290285  unsigned char *us = (unsigned char *)s;
     286  if (text.capacity() < (text.size() + len + 2)) {
     287    text.reserve(text.size() + len + 2);
     288  }
     289
    291290  while (len > 0)
    292291    {
    293292      text.push_back (*us); // append this character
    294       us++;
    295       len--;
    296     }
    297 }
    298 
    299 void text_t::appendcstr (char *s)
    300 {
     293      ++us;
     294      --len;
     295    }
     296}
     297
     298void text_t::appendcstr (const char *s)
     299{
     300  size_t len = strlen(s);
     301  if (text.capacity() < (text.size() + len + 2)) {
     302    text.reserve(text.size() + len + 2);
     303  }
     304 
    301305  unsigned char *us = (unsigned char *)s;
    302306  while (*us != '\0')
    303307    {
    304308      text.push_back (*us); // append this character
    305       us++;
     309      ++us;
    306310    }
    307311}
     
    309313
    310314// strings returned from getcarr and getcstr become the callers
    311 // responsibility and should be deallocated with "delete"
     315// responsibility and should be deallocated with "delete []"
    312316
    313317char *text_t::getcarr(size_type &len) const
     
    328332    else cstr[len] = '?';
    329333      }
    330       len++;
    331       ithere++;
     334      ++len;
     335      ++ithere;
    332336    }
    333337
     
    352356    else cstr[len] = '?';
    353357      }
    354       len++;
    355       ithere++;
     358      ++len;
     359      ++ithere;
    356360    }
    357361
     
    371375    {
    372376      if (*first == c) break;
    373       first++;
     377      ++first;
    374378    }
    375379  return first;
     
    382386    {
    383387      if (*first == c) break;
    384       first++;
     388      ++first;
    385389    }
    386390  return first;
    387391}
    388392
    389 text_t::iterator findword (text_t::iterator first, text_t::iterator last,
     393text_t::iterator findword (text_t::iterator first,
     394               text_t::iterator last,
    390395               const text_t& word)
    391396{
     
    403408          break;
    404409        }
    405       char_match++;
    406       word_here++;
     410      ++char_match;
     411      ++word_here;
    407412    }
    408413      if (word_here==word_end)
     
    410415      return first;
    411416    }
    412       first++;
     417      ++first;
    413418    }
    414419  return last; // get to here only if there is no match
     
    424429  outstr.clear();
    425430  outstr.appendrange (first, here);
    426   if (here != last) here++; // skip c
     431  if (here != last) ++here; // skip c
    427432  return here;
    428433}
     
    435440  outstr.clear();
    436441  outstr.appendrange (first, here);
    437   if (here != last) here++; // skip c
     442  if (here != last) ++here; // skip c
    438443  return here;
    439444}
     
    489494  text_tset::const_iterator here = inlist.begin ();
    490495  text_tset::const_iterator end = inlist.end ();
    491   bool first = true;
    492   while (here != end)
    493     {
    494       if (!first) outtext.push_back (c);
    495       first = false;
     496
     497  if (here != end) {
     498    outtext += *here; ++here;
     499    while (here != end) {
     500      outtext.push_back (c);
    496501      outtext += *here;
    497       here++;
    498     }
     502      ++here;
     503    }
     504  }
    499505}
    500506
     
    505511  text_tlist::const_iterator here = inlist.begin ();
    506512  text_tlist::const_iterator end = inlist.end ();
    507   bool first = true;
    508   while (here != end)
    509     {
    510       if (!first) outtext.push_back (c);
    511       first = false;
     513  if (here != end) {
     514    outtext += *here; ++here;
     515    while (here != end) {
     516      outtext.push_back (c);
    512517      outtext += *here;
    513       here++;
    514     }
     518      ++here;
     519    }
     520  }
    515521}
    516522
     
    521527  text_tarray::const_iterator here = inlist.begin ();
    522528  text_tarray::const_iterator end = inlist.end ();
    523   bool first = true;
    524   while (here != end)
    525     {
    526       if (!first) outtext.push_back (c);
    527       first = false;
     529  if (here != end) {
     530    outtext += *here; ++here;
     531    while (here != end) {
     532      outtext.push_back (c);
    528533      outtext += *here;
    529       here++;
    530     }
    531 }
    532 
    533 void joinchar (const text_tlist &inlist, text_t c, text_t &outtext)
     534      ++here;
     535    }
     536  }
     537}
     538
     539void joinchar (const text_tlist &inlist, const text_t &c, text_t &outtext)
    534540{
    535541  outtext.clear ();
     
    537543  text_tlist::const_iterator here = inlist.begin ();
    538544  text_tlist::const_iterator end = inlist.end ();
    539   bool first = true;
    540   while (here != end)
    541     {
    542       if (!first) outtext += c;
    543       first = false;
     545  if (here != end) {
     546    outtext += *here; ++here;
     547    while (here != end) {
     548      outtext += c;
    544549      outtext += *here;
    545       here++;
    546     }
    547 }
    548 
    549 void joinchar (const text_tset &inlist, text_t c, text_t &outtext)
     550      ++here;
     551    }
     552  }
     553}
     554
     555void joinchar (const text_tset &inlist, const text_t &c, text_t &outtext)
    550556{
    551557  outtext.clear ();
     
    553559  text_tset::const_iterator here = inlist.begin ();
    554560  text_tset::const_iterator end = inlist.end ();
    555   bool first = true;
    556   while (here != end)
    557     {
    558       if (!first) outtext += c;
    559       first = false;
     561  if (here != end) {
     562    outtext += *here; ++here;
     563    while (here != end) {
     564      outtext += c;
    560565      outtext += *here;
    561       here++;
    562     }
    563 }
    564 
    565 void joinchar (const text_tarray &inlist, text_t c, text_t &outtext)
     566      ++here;
     567    }
     568  }
     569}
     570
     571void joinchar (const text_tarray &inlist, const text_t &c, text_t &outtext)
    566572{
    567573  outtext.clear ();
     
    569575  text_tarray::const_iterator here = inlist.begin ();
    570576  text_tarray::const_iterator end = inlist.end ();
    571   bool first = true;
    572   while (here != end)
    573     {
    574       if (!first) outtext += c;
    575       first = false;
     577  if (here != end) {
     578    outtext += *here; ++here;
     579    while (here != end) {
     580      outtext += c;
    576581      outtext += *here;
    577       here++;
    578     }
     582      ++here;
     583    }
     584  }
    579585}
    580586
     
    594600text_t substr (text_t::const_iterator first, text_t::const_iterator last) {
    595601
    596   text_t substr;
     602  text_t substr; substr.reserve(last - first + 2);
    597603  while (first != last) {
    598604    substr.push_back(*first);
    599     first ++;
     605    ++first;
    600606  }
    601607  return substr;
     
    607613  while (first != last) {
    608614    *first = unicode_tolower(*first);
    609     first++;
     615    ++first;
    610616  }
    611617}
     
    615621  while (first != last) {
    616622    *first = unicode_toupper(*first);
    617     first++;
     623    ++first;
    618624  }
    619625}
     
    631637    (*here!='6') && (*here!='7') && (*here!='8') &&
    632638    (*here!='9')) return false;
    633     here ++;
     639    ++here;
    634640  }
    635641  return true;
     
    645651  while (here != end) {
    646652    if (is_unicode_letdig (*here)) return true;
    647     here++;
     653    ++here;
    648654  }
    649655
     
    708714    }
    709715
     716  if (output.capacity() < len + 2)
     717    output.reserve(len + 2);
     718 
    710719  // don't want any funny sign conversions happening
    711720  unsigned char *here = (unsigned char *)start;
     
    732741  size_t cbuflen = 0;
    733742 
     743  out.clear();
     744  if (out.capacity() < t.size() + 2)
     745    out.reserve(t.size() + 2);
    734746  while (here != end) {
    735747    while (here != end && cbuflen < 256) {
    736748      cbuf[cbuflen++] = (unsigned char)(*here & 0xff);
    737       here++;
     749      ++here;
    738750    }
    739751
     
    792804}
    793805
     806void outconvertclass::setdata(text_t *theinput, text_t::iterator thetexthere)
     807{
     808  input = theinput;     
     809  texthere = thetexthere;
     810}
     811 
    794812void outconvertclass::convert (char *output, size_t maxlen,
    795813              size_t &len, status_t &status)
     
    832850  size_t cbuflen = 0;
    833851  status_t status = unfinished;
    834 
     852 
     853  out.clear();
     854  if (out.capacity() < t.size() + 2)
     855    out.reserve(t.size() + 2);
    835856  setinput ((text_t *)&t); // discard constant
    836857  while (status == unfinished) {
  • trunk/gsdl/lib/text_t.h

    r7396 r8727  
    5959
    6060// class prototypes
     61class text_t;
    6162class inconvertclass;
    6263class outconvertclass;
     
    7071
    7172typedef vector<unsigned short> usvector;
     73extern const text_t g_EmptyText;
    7274
    7375// The class text_t can handle long strings which may contain
     
    9496  text_t ();
    9597  text_t (int i);
    96   text_t (char *s); // assumed to be a normal c string
    97 
     98  text_t (const char *s); // assumed to be a normal c string
     99  text_t (const char *s, size_type nLength); // support for arrays of chars
    98100  void setencoding (unsigned short theencoding) {encoding=theencoding;};
    99101  unsigned short getencoding () {return encoding;};
     
    117119
    118120  void reserve (size_type n) {text.reserve(n);}
     121  size_type capacity() const { return text.capacity(); }
    119122 
    120123  bool empty () const {return text.empty();}
     
    151154
    152155  // support for arrays of chars
    153   void appendcarr (char *s, size_type len);
     156  void appendcarr (const char *s, size_type len);
    154157  void setcarr (char *s, size_type len) {clear();appendcarr(s,len);}
    155158
    156   // support for null-terminated C strings
    157   void appendcstr (char *s);
    158   void setcstr (char *s) {clear();appendcstr(s);}
    159   text_t &operator= (char *s) {setcstr(s);return *this;} // c string
    160   text_t &operator+= (char *s) {appendcstr(s);return *this;} // c string
    161 
    162   // support for const null-terminated C string
    163   void appendcstr (const char *s) {appendcstr((char *)s);}
    164   void setcstr (const char *s) {clear();appendcstr((char *) s);}
    165   text_t &operator= (const char *s) {setcstr((char *) s);return *this;} // c string
    166   text_t &operator+= (const char *s) {appendcstr((char *) s);return *this;} // c string
     159  // support for const null-terminated C strings
     160  void appendcstr (const char *s);
     161  void setcstr (const char *s) {clear();appendcstr(s);}
     162  text_t &operator= (const char *s) {setcstr(s);return *this;} // c string
     163  text_t &operator+= (const char *s) {appendcstr(s);return *this;} // c string
    167164
    168165  // strings returned from getcarr and getcstr become the callers
    169   // responsibility and should be deallocated with "delete"
     166  // responsibility and should be deallocated with "delete []"
    170167  char *getcarr(size_type &len) const;
    171168  char *getcstr() const;
     
    174171
    175172// new stream converter ...
    176 ostream& operator<< (ostream &o, const text_t text);
     173ostream& operator<< (ostream &o, const text_t &text);
    177174
    178175inline text_t operator+(const text_t &t1, const text_t &t2)
     
    250247void joinchar (const text_tlist &inlist, unsigned short c, text_t &outtext);
    251248void joinchar (const text_tarray &inlist, unsigned short c, text_t &outtext);
    252 void joinchar (const text_tset &inlist, text_t c, text_t &outtext);
    253 void joinchar (const text_tlist &inlist, text_t c, text_t &outtext);
    254 void joinchar (const text_tarray &inlist, text_t c, text_t &outtext);
     249void joinchar (const text_tset &inlist, const text_t &c, text_t &outtext);
     250void joinchar (const text_tlist &inlist, const text_t &c, text_t &outtext);
     251void joinchar (const text_tarray &inlist, const text_t &c, text_t &outtext);
    255252
    256253// count the occurances of a character within a range
     
    338335public:
    339336  outconvertclass ();
    340   void reset ();
    341   void setinput (text_t *theinput);
     337  virtual void reset ();
     338  virtual void setinput (text_t *theinput);
     339  virtual void setdata(text_t *input, text_t::iterator texthere);
    342340  // note that convert does not null-terminate the
    343341  // output array of characters
     
    350348  text_t convert (const text_t &t);
    351349
    352   void setostream (ostream *theouts);
     350  virtual void setostream (ostream *theouts);
    353351  ostream *getostream ();
    354352
     
    370368outconvertclass &operator<< (outconvertclass &outconverter, const text_t &t);
    371369
    372 extern const text_t g_EmptyText;
    373 
    374 #endif
     370
     371#endif
Note: See TracChangeset for help on using the changeset viewer.