Changeset 610 for CMT


Ignore:
Timestamp:
Apr 16, 2012, 12:17:30 PM (12 years ago)
Author:
rybkin
Message:

See C.L. 485

Location:
CMT/HEAD
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • CMT/HEAD/ChangeLog

    r609 r610  
     12012-04-16    <rybkin@lal.in2p3.fr> 485
     2
     3        * source/cmt_system.cxx: In class CmtSystem, re-write split function in
     4        order to improve and optimise algorithm
     5        * source/cmt_system.h: In class CmtSystem split function, introduce
     6        argument bool& unquote with default value true
     7        * source/cmt_use.cxx: In classes VersionReader, PackageReader function
     8        filter, do not parse comment lines
     9        * source/cmt_project.cxx: In class ProjectReader function filter, do not
     10        parse comment lines
     11        * source/cmt_string.h: In class cmt_string, introduce constructor from
     12        character array with
     13        * source/cmt_string.cxx: In class cmt_string, implement constructor from
     14        character array with
     15        * source/cmt_parser.cxx: In class Cmt function vector_to_string, make sure
     16        separator is not prepended at beginning
     17        * source/cmt_symbol.cxx: Introduce helper function find_path_entry with
     18        cmt_string_vector& (rather than cmt_string) first argument, in class
     19        PathBuilder function build, perform all calculations on vector of values,
     20        rather than string, in order to optimise and improve algorithm
     21       
    1222012-04-05    <rybkin@lal.in2p3.fr> 484
    223
  • CMT/HEAD/source/cmt_parser.cxx

    r607 r610  
    98429842      if (s == "") continue;
    98439843
    9844       if (i > 0) result += separator;
     9844      if (result.size () != 0) result += separator;
     9845      //if (i > 0) result += separator;
    98459846      result += v[i];
    98469847    }
  • CMT/HEAD/source/cmt_project.cxx

    r608 r610  
    3636  void filter (const cmt_string& line)
    3737  {
     38    if (0 == line.size () ||
     39        line[0] == '#') return;
    3840    CmtSystem::cmt_string_vector words;
    3941    CmtSystem::split (line, " \t", words);
  • CMT/HEAD/source/cmt_string.cxx

    r607 r610  
    4949      allocate (_size + 1);
    5050      strcpy (_data, text);
     51    }
     52}
     53
     54cmt_string::cmt_string (const char* text, int n)
     55{
     56  _data = 0;
     57  _allocated = 0;
     58  _size = 0;
     59
     60  if (text != 0)
     61    {
     62      _size = strlen (text) < n ? strlen (text) : n;
     63      allocate (_size + 1);
     64      strncpy (_data, text, _size);
     65      _data[_size] = 0;
    5166    }
    5267}
  • CMT/HEAD/source/cmt_string.h

    r11 r610  
    2626  cmt_string (char c);
    2727  cmt_string (const char* text);
     28  cmt_string (const char* text, int n);
    2829  cmt_string (const cmt_string& other);
    2930  ~cmt_string ();
  • CMT/HEAD/source/cmt_symbol.cxx

    r608 r610  
    22202220}
    22212221
    2222 static bool find_path_entry (const cmt_string& paths, const cmt_string& value)
     2222static bool find_path_entry (const CmtSystem::cmt_string_vector& items, const cmt_string& value)
    22232223{
    22242224  static const cmt_string path_separator = CmtSystem::path_separator ();
    22252225  static cmt_vmap <cmt_string, cmt_string> realpaths;
     2226
     2227  if (value.size () == 0) return true;
    22262228
    22272229  cmt_string rvalue;
     
    22402242    }
    22412243
    2242   CmtSystem::cmt_string_vector items;
    2243   CmtSystem::split (paths, path_separator, items);
     2244  //  CmtSystem::cmt_string_vector items;
     2245  //  CmtSystem::split (paths, path_separator, items);
    22442246
    22452247  bool found = false;
     
    22482250    {
    22492251      const cmt_string& item = items[i];
     2252      if (item.size () == 0) continue;
    22502253      cmt_string ritem;
    22512254      const cmt_string * pritem;
     
    22722275}
    22732276
     2277static bool find_path_entry (const cmt_string& paths, const cmt_string& value)
     2278{
     2279  static const cmt_string path_separator = CmtSystem::path_separator ();
     2280  static cmt_vmap <cmt_string, cmt_string> realpaths;
     2281
     2282  cmt_string rvalue;
     2283  const cmt_string * prvalue;
     2284
     2285  if (!(prvalue = realpaths.find (value)))
     2286    {
     2287      if (!CmtSystem::realpath_ (value, rvalue))
     2288        {
     2289          rvalue = value;
     2290          CmtSystem::compress_path (rvalue);
     2291        }
     2292      prvalue = &rvalue;
     2293      realpaths.add (value, rvalue);
     2294      //      cerr << "realpaths.add: " << value << " , " << rvalue << endl;
     2295    }
     2296
     2297  CmtSystem::cmt_string_vector items;
     2298  CmtSystem::split (paths, path_separator, items);
     2299
     2300  bool found = false;
     2301
     2302  for (int i = 0; i < items.size (); i++)
     2303    {
     2304      const cmt_string& item = items[i];
     2305      cmt_string ritem;
     2306      const cmt_string * pritem;
     2307
     2308      if (!(pritem = realpaths.find (item)))
     2309        {
     2310          if (!CmtSystem::realpath_ (item, ritem))
     2311            {
     2312              ritem = item;
     2313              CmtSystem::compress_path (ritem);
     2314            }
     2315          pritem = &ritem;
     2316          realpaths.add (item, ritem);
     2317          //  cerr << "realpaths.add: " << item << " , " << ritem << endl;
     2318        }
     2319      if (*pritem == *prvalue)
     2320        {
     2321          found = true;
     2322          break;
     2323        }
     2324    }
     2325
     2326  return (found);
     2327}
     2328
    22742329//-------------------------------------------------------------
    22752330const cmt_string PathBuilder::build (const Symbol& symbol,
     
    22822337
    22832338  cmt_string temp;
    2284   cmt_string previous_temp;
     2339  CmtSystem::cmt_string_vector temp_vector;
     2340  //  cmt_string previous_temp;
     2341  CmtSystem::cmt_string_vector new_value_vector;
    22852342  cmt_string new_value;
    22862343  static const cmt_string empty;
     
    23012358  level++;
    23022359
    2303   temp = CmtSystem::getenv (symbol.name);
     2360  CmtSystem::split (CmtSystem::getenv (symbol.name), path_separator, temp_vector);
     2361  //temp = CmtSystem::getenv (symbol.name);
    23042362
    23052363  bool first_definition = true;
     
    23372395                !symbol.value_is_reflexive (value.text))
    23382396              {
     2397                Cmt::vector_to_string (temp_vector, path_separator, temp);
    23392398                resolve_value (new_value, symbol.name, temp);
    2340                 temp = new_value;
     2399                CmtSystem::split (new_value, path_separator, temp_vector);
     2400                //temp = new_value;
    23412401              }
    23422402
     
    23462406            if (new_value != "")
    23472407              {
    2348                 if (!find_path_entry (temp, new_value))
    2349                   {
    2350                     if (temp != "") temp += path_separator;
    2351                      
    2352                     temp += new_value;
    2353                   }
     2408                CmtSystem::split (new_value, path_separator, new_value_vector);
     2409                for (int i = 0; i < new_value_vector.size (); i++)
     2410                  if (!find_path_entry (temp_vector, new_value_vector[i]))
     2411                    //if (!find_path_entry (temp, new_value))
     2412                    {
     2413                      temp_vector.push_back (new_value_vector[i]);
     2414                      /*
     2415                        if (temp != "") temp += path_separator;
     2416                       
     2417                        temp += new_value;
     2418                      */
     2419                    }
    23542420              }
    23552421                 
     
    23592425            if (new_value != "")
    23602426              {
    2361                 if (!find_path_entry (temp, new_value))
    2362                   {
    2363                     previous_temp = temp;
    2364                     temp = new_value;
    2365                     if (previous_temp != "") temp += path_separator;
    2366                     temp += previous_temp;
    2367                   }
     2427                CmtSystem::split (new_value, path_separator, new_value_vector);
     2428                int n (new_value_vector.size ());
     2429                temp_vector.resize (temp_vector.size () + n);
     2430                for (int i = temp_vector.size () - 1; i > n - 1; i--)
     2431                  temp_vector [i] = temp_vector [i - n];
     2432                for (int i = 0; i < new_value_vector.size (); i++)
     2433                  if (!find_path_entry (temp_vector, new_value_vector[i]))
     2434                    //if (!find_path_entry (temp, new_value))
     2435                    {
     2436                      temp_vector [i] = new_value_vector[i];
     2437                      /*
     2438                        previous_temp = temp;
     2439                        temp = new_value;
     2440                        if (previous_temp != "") temp += path_separator;
     2441                        temp += previous_temp;
     2442                      */
     2443                    }
     2444                  else
     2445                    temp_vector [i] = "";
    23682446              }
    2369                  
     2447           
    23702448            break;
    23712449          case CommandPathRemove :
     
    23732451            if (new_value != "")
    23742452              {
     2453                for (int j = 0; j < temp_vector.size (); ++j)
     2454                  {
     2455                    cmt_string& s = temp_vector[j];
     2456                   
     2457                    if (s.find (new_value) != cmt_string::npos)
     2458                      {
     2459                        s = "";
     2460                      }
     2461                  }
     2462                /*
    23752463                CmtSystem::cmt_string_vector paths;
    23762464                 
     
    23882476
    23892477                Cmt::vector_to_string (paths, path_separator, temp);
     2478                */
    23902479              }
    23912480             
     
    23972486                cmt_regexp e (new_value);
    23982487
     2488                for (int j = 0; j < temp_vector.size (); ++j)
     2489                  {
     2490                    cmt_string& s = temp_vector[j];
     2491
     2492                    if (Cmt::get_debug () &&
     2493                        CmtSystem::getenv ("TESTPRR") != "")
     2494                      {
     2495                        cerr << "PRR> s=[" << s << "]";
     2496                      }
     2497
     2498                    if (e.match (s))
     2499                      {
     2500                        s = "";
     2501
     2502                        if (Cmt::get_debug () &&
     2503                            CmtSystem::getenv ("TESTPRR") != "")
     2504                          {
     2505                            cerr << " match ";
     2506                          }
     2507                      }
     2508                    else
     2509                      {
     2510                        if (Cmt::get_debug () &&
     2511                            CmtSystem::getenv ("TESTPRR") != "")
     2512                          {
     2513                            cerr << " no match ";
     2514                          }
     2515                      }
     2516
     2517                    if (Cmt::get_debug () &&
     2518                        CmtSystem::getenv ("TESTPRR") != "")
     2519                      {
     2520                        cerr << endl;
     2521                      }
     2522                  }
     2523
     2524                /*
    23992525                CmtSystem::cmt_string_vector paths;
    24002526                 
     
    24342560
    24352561                Cmt::vector_to_string (paths, path_separator, temp);
     2562                */
    24362563              }
    24372564             
     
    24402567
    24412568    }
     2569
     2570  Cmt::vector_to_string (temp_vector, path_separator, temp);
    24422571
    24432572  level--;
  • CMT/HEAD/source/cmt_system.cxx

    r607 r610  
    22312231void CmtSystem::split (const cmt_string& text,
    22322232                       const cmt_string& separators,
    2233                        cmt_string_vector& strings)
     2233                       cmt_string_vector& strings,
     2234                       const bool& unquote)
    22342235{
    22352236  static char* buffer = 0;
    22362237  static int allocated = 0;
    2237 
    2238   bool finished = false;
    22392238
    22402239  strings.clear ();
     
    22772276  */
    22782277
    2279   char* current_word = buffer;
    2280 
    2281   while (*current_word != 0)
    2282     {
    2283       size_t prefix_length;
    2284       size_t word_length;
    2285 
    2286       /*
    2287         while ((*current_word == ' ') ||
    2288         (*current_word == '\t'))
    2289         {
    2290         current_word++;
    2291         }
    2292       */
    2293 
    2294       // first skip all starting separators.
    2295 
    2296       prefix_length = strspn (current_word, separators.c_str ());
    2297       if (prefix_length > 0)
    2298         {
    2299           // Move to the first non-separator character
    2300 
    2301           current_word += prefix_length;
    2302         }
    2303 
    2304       /*
    2305         Parse the next word.
    2306 
    2307         It may contain enclosures in quote characters or not.
    2308         Quotes must be identical on both sides of each enclosure.
    2309       */
    2310 
    2311       char* running_char = current_word;
    2312 
    2313       word_length = 0;
    2314 
    2315       for (;;)
    2316         {
    2317           size_t unquoted_length;
    2318           size_t separator_offset;
    2319 
    2320           for (int p = 0;;)
     2278  char * b = buffer;
     2279  char * begin = b;
     2280  char * e;
     2281  char * pq = 0;
     2282  char * pqm = 0;
     2283  char q, ev;
     2284  char * token = 0;
     2285  bool before_q = false;
     2286  bool after_q = false;
     2287  bool matched = false;
     2288
     2289//   cerr << "split: " << buffer << endl;
     2290//   cerr << "seps: `";
     2291//   for (int i = 0; i < separators.size (); i++)
     2292//     cerr << separators[i];
     2293//   cerr << "'" << endl;
     2294
     2295  // sep...ab..."cd"ef...sep...
     2296  while (pq = strpbrk (begin, "\"\'"))
     2297    {
     2298      if (begin < pq && *(pq - 1) == '\\')
     2299        {// quote considered escaped
     2300          begin = pq + 1;
     2301          continue;
     2302        }
     2303
     2304      if ((b < pq && NULL == strchr (separators.c_str (), *(pq - 1))) ||
     2305          (b == pq && after_q))
     2306        before_q = true;
     2307      else
     2308        before_q = false;
     2309
     2310      // save quote found
     2311      q = *pq;
     2312      // terminate string for standard string functions
     2313      *pq = 0;
     2314
     2315      // parse string - up to quote - into a sequence of tokens
     2316      if (token = strtok (b, separators.c_str ()))
     2317        {
     2318          if (after_q)
     2319            strings.back () += token;
     2320          else
     2321            strings.add () = token;
     2322
     2323//        cerr << (after_q ? "append: " : "add: ")
     2324//             << "[" << token << "]{" << strings.back () << "}";
     2325
     2326          while (token = strtok (NULL, separators.c_str ()))
    23212327            {
    2322               unquoted_length = strcspn (running_char + p, "\"\'") + p;
    2323               if ((unquoted_length > 0) && (running_char[unquoted_length-1] == '\\'))
    2324                 {
    2325                   p = unquoted_length + 1;
    2326                 }
    2327               else
    2328                 {
    2329                   break;
    2330                 }
     2328              strings.add () = token;
     2329              //strings.push_back (token);
     2330              //cerr << "[" << token << "]{" << strings.back () << "}";
     2331            } // while ( token = strtok (NULL, separators.c_str ()) )
     2332          //cerr << endl;
     2333        }
     2334
     2335      if (unquote)
     2336        {
     2337          b = pq + 1;
     2338        }
     2339      else
     2340        {
     2341          // restore quote found
     2342          *pq = q;
     2343          b = pq;
     2344        }
     2345      begin = pq + 1;
     2346
     2347      // look for matching quote
     2348      matched = false;
     2349      while (pqm = strchr (begin, q))
     2350        {
     2351          // commented out because of
     2352          // inconsistency of quoting rules
     2353          // and backward compatibility
     2354//        if (begin < pqm && *(pqm - 1) == '\\')
     2355//          {// quote considered escaped
     2356//            begin = pqm + 1;
     2357//            continue;
     2358//          }
     2359          matched = true;
     2360
     2361          if (*(pqm + 1) && NULL == strchr (separators.c_str (), *(pqm + 1)))
     2362            after_q = true;
     2363          else
     2364            after_q = false;
     2365
     2366          if (unquote)
     2367            {
     2368              e = pqm;
    23312369            }
    2332 
    2333           separator_offset = strcspn (running_char, separators.c_str ());
    2334 
    2335           if (separator_offset <= unquoted_length)
    2336             {
    2337               // no quote in this word -> we are finished for this one.
    2338               running_char += separator_offset;
    2339               break;
    2340             }
    2341 
    2342           // We have found a quoted enclosure. Move to it.
    2343 
    2344           running_char += unquoted_length;
    2345 
    2346           char quote = running_char[0];
    2347 
    2348           // Remove it.
    2349           {
    2350             char* p = running_char;
    2351             while (p[1] != 0)
    2352               {
    2353                 *p = p[1];
    2354                 p++;
    2355               }
    2356             *p = 0;
    2357           }
    2358 
    2359           // Look for the next occurence of this quote.
    2360           {
    2361             char* p = strchr (running_char, quote);
    2362             if (p == 0)
    2363               {
    2364                 // Unmatched quote : the rest of the line will be taken as a word...
    2365                 running_char += strlen (running_char);
    2366                 finished = true;
    2367                 break;
    2368               }
    2369             else
    2370               {
    2371                 running_char = p;
    2372               }
    2373           }
    2374 
    2375           // Now we remove the ending quote from the word
    2376           // (by shifting all remaining characters by one place to the left)
    2377 
    2378           {
    2379             char* p = running_char;
    2380             while (p[1] != 0)
    2381               {
    2382                 *p = p[1];
    2383                 p++;
    2384               }
    2385             *p = 0;
    2386           }
    2387         }
    2388 
    2389       word_length = running_char - current_word;
    2390 
    2391       if (current_word[word_length] == 0)
    2392         {
    2393           finished = true;
    2394         }
    2395       else
    2396         {
    2397           current_word[word_length] = 0;
    2398         }
    2399 
    2400       /*
    2401         if ((t[0] == '"') ||
    2402         (t[0] == '\'') ||
    2403         (t[0] == ':'))
    2404         {
    2405         char* quote;
    2406 
    2407         t++;
    2408         quote = strchr (t, sep);
    2409         if (quote != 0) *quote = 0;
    2410         else finished = true;
    2411         }
    2412         else
    2413         {
    2414         int offset;
    2415 
    2416         offset = strcspn (t, " \t:");
    2417         if ((offset < 0) || (t[offset] == 0)) finished = true;
    2418         if (!finished)
    2419         {
    2420         space = t + offset;
    2421         *space = 0;
    2422         }
    2423         }
    2424       */
    2425 
    2426       // Store the current word into the vector of strings
    2427 
    2428       {
    2429         cmt_string& s = strings.add ();
    2430         s = current_word;
    2431       }
    2432 
    2433       if (finished) break;
    2434 
    2435       // Move to the next possible word.
    2436       current_word += word_length + 1;
    2437     }
     2370          else
     2371            {
     2372              e = pqm + 1;
     2373              ev = *e;
     2374            }
     2375          // terminate string for standard string functions
     2376          *e = 0;
     2377         
     2378          if (before_q)
     2379            strings.back () += b;
     2380          else
     2381            strings.add () = b;
     2382
     2383//        cerr << (before_q ? "append: " : "add: ")
     2384//             << "|" << b << "|{" << strings.back () << "}" << endl;
     2385         
     2386          // restore e value
     2387          if (!unquote)
     2388            {
     2389              *e = ev;
     2390            }
     2391          b = pqm + 1;
     2392          begin = b;
     2393          break;
     2394        } // while (pqm = strchr (begin, q))
     2395
     2396      if (!matched)
     2397        { // unmatched quote : the rest of the line will be taken as a token
     2398          if (before_q)
     2399            strings.back () += b;
     2400          else
     2401            strings.add () = b;
     2402
     2403          // append quote to match
     2404          if (!unquote)
     2405            strings.back () += q;
     2406         
     2407//        cerr << (before_q ? "append: " : "add: ")
     2408//             << "|" << b << "|{" << strings.back () << "}" << endl;
     2409
     2410          b = buffer + strlen(buffer);
     2411          begin = b;
     2412          break;
     2413        }
     2414
     2415    } // while (pq = strpbrk (begin, "\"\'"))
     2416
     2417      // parse string - up to end - into a sequence of tokens
     2418      if (token = strtok (b, separators.c_str ()))
     2419        {
     2420          if (after_q)
     2421            strings.back () += token;
     2422          else
     2423            strings.add () = token;
     2424
     2425//        cerr << (after_q ? "append: " : "add: ")
     2426//             << "<" << token << ">{" << strings.back () << "}";
     2427
     2428          while (token = strtok (NULL, separators.c_str ()))
     2429            {
     2430              strings.add () = token;
     2431              //cerr << "<" << token << ">{" << strings.back () << "}";
     2432            } // while ( token = strtok (NULL, separators.c_str ()) )
     2433          //cerr << endl;
     2434        }
     2435//       cerr << "strings:";
     2436//       for (int i = 0; i < strings.size (); i++)
     2437//      cerr << " {" << strings[i] << "}";
     2438//       //     cerr << " `" << strings[i] << "'";
     2439//       cerr << endl;
    24382440}
    24392441
  • CMT/HEAD/source/cmt_system.h

    r599 r610  
    153153  static void split (const cmt_string& text,
    154154                     const cmt_string& separators,
    155                      cmt_string_vector& strings);
     155                     cmt_string_vector& strings,
     156                     const bool& unquote = true);
    156157  static cmt_string quote (const cmt_string& text,
    157158                           const cmt_string& separators);
  • CMT/HEAD/source/cmt_use.cxx

    r608 r610  
    54225422  void filter (const cmt_string& line)
    54235423  {
     5424    if (0 == line.size () ||
     5425        line[0] == '#') return;
    54245426    CmtSystem::cmt_string_vector words;
    54255427    CmtSystem::split (line, " \t", words);
     
    54505452  void filter (const cmt_string& line)
    54515453  {
     5454    if (0 == line.size () ||
     5455        line[0] == '#') return;
    54525456    CmtSystem::cmt_string_vector words;
    54535457    CmtSystem::split (line, " \t", words);
Note: See TracChangeset for help on using the changeset viewer.