Changeset 607 for CMT


Ignore:
Timestamp:
Apr 3, 2012, 3:54:50 PM (12 years ago)
Author:
rybkin
Message:

See C.L. 482

Location:
CMT/HEAD
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • CMT/HEAD/ChangeLog

    r606 r607  
     12012-04-03    <rybkin@lal.in2p3.fr> 482
     2
     3        * source/cmt_syntax.cxx: In class SyntaxParser function
     4        do_parse_requirements, check return value of string read function and set
     5        error on failure, re-write function do_parse_text in order to optimise
     6        * source/cmt_awk.cxx: In class Parser, re-write function parse in order
     7        to optimise, in class Awk function run, test CMTTESTAWK environment
     8        variable in debug mode only, re-write function run in order to optimise
     9        * source/cmt_string.cxx: In class cmt_string, make function resize set size
     10        and terminate string with 0, optimise functions substr (int, int),
     11        substr (int, int, cmt_string&)
     12        * source/cmt_pattern.cxx: In class Pattern functions test CMTTESTPATTERN
     13        environment variable in debug mode only
     14        * source/cmt_regexp.cxx: In class cmt_and_node function match, class
     15        cmt_or_node function match, class cmt_regexp function set, test
     16        CMTTESTREGEXP environment variable in debug mode only
     17        * source/cmt_parser.cxx: In class Cmt function set_standard_macros, test
     18        TAGDEBUG environment variable once
     19        * source/cmt_system.cxx: In class CmtSystem, re-write function realpath_
     20        making use of system functions realpath (POSIX) and _fullpath (Windows)
     21        * source/cmt_use.cxx: In class Use function get_cmtpath_and_offset, check
     22        return value of CmtSystem::realpath_ and set error on failure
     23        * source/cmt_project.cxx: In class Project function find_in_cmt_paths check
     24        return value of CmtSystem::realpath_ and return on failure, do not test
     25        existence of project cmt paths as they must exist
     26        * source/cmt_symbol.cxx: In find_path_entry helper function, make use of
     27        CmtSystem::realpath_ for paths comparison
     28
    1292012-03-26    <rybkin@lal.in2p3.fr> 481
    230
  • CMT/HEAD/source/cmt_awk.cxx

    r569 r607  
    4040
    4141    cmt_string line;
     42    /*
    4243    int pos;
    4344    int max_pos;
     
    4546    pos = 0;
    4647    max_pos = text.size ();
    47 
     48    */
    4849    m_accumulator.erase (0);
    4950
     51    int nl;
     52    int begin = 0;
     53    int end = text.size ();
     54   
     55    while ((nl = text.find (begin, '\n')) != cmt_string::npos)
     56      {
     57        if (begin < nl && text[nl - 1] == '\r')
     58          {
     59            text.substr (begin, nl - 1 - begin, line);
     60          }
     61        else
     62          {
     63            text.substr (begin, nl - begin, line);
     64          }
     65        //      cerr << "|Awk::condition parse> [" << line << "]" << endl;
     66        begin = nl + 1;
     67        if (m_awk != 0) m_awk->inc_line_number ();
     68
     69        result = parse_line (line);
     70        if (result != Awk::ok) return result;
     71      } // while ((nl = text.find (begin, '\n')) != cmt_string::npos)
     72   
     73    if (begin < end)
     74      {
     75        text.substr (begin, end - begin, line);
     76        if (m_awk != 0) m_awk->inc_line_number ();
     77       
     78        result = parse_line (line);
     79      }
     80   
     81    /*
    5082    for (pos = 0; pos < max_pos;)
    5183      {
     
    90122        if (result != Awk::ok) break;
    91123      }
    92 
     124    */
    93125    return (result);
    94126  }
     
    232264  if (m_condition != ok) return (m_condition);
    233265
    234   if (CmtSystem::testenv ("CMTTESTAWK"))
     266  if (Cmt::get_debug () &&
     267      CmtSystem::testenv ("CMTTESTAWK"))
    235268    {
    236269      Parser p (this, pattern, 0);
     
    242275    {
    243276      cmt_string line;
     277      int nl;
     278      int begin = 0;
     279      int end = text.size ();
     280     
     281      while ((nl = text.find (begin, '\n')) != cmt_string::npos)
     282        {
     283          if (begin < nl && text[nl - 1] == '\r')
     284            {
     285              text.substr (begin, nl - 1 - begin, line);
     286            }
     287          else
     288            {
     289              text.substr (begin, nl - begin, line);
     290            }
     291          //      cerr << "|Awk::condition run> [" << line << "]" << endl;
     292          begin = nl + 1;
     293          m_line_number++;
     294         
     295          if (line != "")
     296            {
     297              if ((pattern == "") ||
     298                  (line.find (pattern) != cmt_string::npos))
     299                {
     300                  filter (line);
     301                  if (m_condition != ok) return (m_condition);
     302                }
     303            }
     304        } // while ((nl = text.find (begin, '\n')) != cmt_string::npos)
     305     
     306      if (begin < end)
     307        {
     308          text.substr (begin, end - begin, line);
     309          m_line_number++;
     310         
     311          if (line != "")
     312            {
     313              if ((pattern == "") ||
     314                  (line.find (pattern) != cmt_string::npos))
     315                {
     316                  filter (line);
     317                  if (m_condition != ok) return (m_condition);
     318                }
     319            }
     320        }
     321      /*
    244322      int pos = 0;
    245323      int max_pos;
     
    315393            }
    316394        }
     395      */
    317396    }
    318397
  • CMT/HEAD/source/cmt_parser.cxx

    r603 r607  
    96849684   */
    96859685
    9686   bool tag_debug = CmtSystem::testenv ("TAGDEBUG");
     9686  static bool tag_debug = CmtSystem::testenv ("TAGDEBUG");
    96879687
    96889688  if (tag_debug) cerr << "set_standard_macro0> current_tag=" << Me.m_current_tag << endl;
  • CMT/HEAD/source/cmt_pattern.cxx

    r542 r607  
    192192  add (name, words, start_index, global, use);
    193193
    194   if (CmtSystem::testenv ("CMTTESTPATTERN"))
     194  if (Cmt::get_debug () &&
     195      CmtSystem::testenv ("CMTTESTPATTERN"))
    195196    {
    196197      cerr << "Pattern::action> add " << name << endl;
     
    736737  expand (context_use, templates, replacement);
    737738
    738   if (CmtSystem::testenv ("CMTTESTPATTERN"))
     739  if (Cmt::get_debug () &&
     740      CmtSystem::testenv ("CMTTESTPATTERN"))
    739741    {
    740742      cerr << "Pattern::apply> replacement=[" << replacement << "]" << endl;
     
    754756  if (context_use == 0) context_use = &(Use::current ());
    755757
    756   if (CmtSystem::testenv ("CMTTESTPATTERN"))
     758  if (Cmt::get_debug () &&
     759      CmtSystem::testenv ("CMTTESTPATTERN"))
    757760    {
    758761      cerr << "Pattern::expand1> line=[" << line << "]" << endl;
     
    802805        }
    803806
    804       if (CmtSystem::testenv ("CMTTESTPATTERN"))
     807      if (Cmt::get_debug () &&
     808          CmtSystem::testenv ("CMTTESTPATTERN"))
    805809        {
    806810          cerr << "Pattern::expand2> repl=[" << replacement << "]" << endl;
     
    897901      cmt_string s = words[i];
    898902
    899       if (CmtSystem::testenv ("CMTTESTPATTERN"))
     903      if (Cmt::get_debug () &&
     904          CmtSystem::testenv ("CMTTESTPATTERN"))
    900905        {
    901906          cerr << "ApplyPattern::action> " << name << " s=[" << s << "] state=" << state << endl;
     
    921926              s.substr (pos + 1, tvalue);
    922927
    923               if (CmtSystem::testenv ("CMTTESTPATTERN"))
     928              if (Cmt::get_debug () &&
     929                  CmtSystem::testenv ("CMTTESTPATTERN"))
    924930                {
    925931                  cerr << "ApplyPattern::action-1> n=[" << tname << "] v=[" << tvalue << "]" << endl;
     
    9941000              s.substr (pos + 1, tvalue);
    9951001
    996               if (CmtSystem::testenv ("CMTTESTPATTERN"))
     1002              if (Cmt::get_debug () &&
     1003                  CmtSystem::testenv ("CMTTESTPATTERN"))
    9971004                {
    9981005                  cerr << "ApplyPattern::action-2> n=[" << tname << "] v=[" << tvalue << "]" << endl;
     
    10161023          state = need_template;
    10171024
    1018           if (CmtSystem::testenv ("CMTTESTPATTERN"))
     1025          if (Cmt::get_debug () &&
     1026              CmtSystem::testenv ("CMTTESTPATTERN"))
    10191027            {
    10201028              cerr << "ApplyPattern::action-3> n=[" << tname << "] v=[" << tvalue << "]" << endl;
     
    11091117void ApplyPattern::apply () const
    11101118{
    1111   if (CmtSystem::testenv ("CMTTESTPATTERN"))
     1119  if (Cmt::get_debug () &&
     1120      CmtSystem::testenv ("CMTTESTPATTERN"))
    11121121    {
    11131122      cerr << "ApplyPattern::apply> " << name << endl;
     
    11171126  if (p == 0)
    11181127    {
    1119       if (CmtSystem::testenv ("CMTTESTPATTERN"))
     1128      if (Cmt::get_debug () &&
     1129          CmtSystem::testenv ("CMTTESTPATTERN"))
    11201130        {
    11211131          cerr << "ApplyPattern::apply> " << name << " not found" << endl;
  • CMT/HEAD/source/cmt_project.cxx

    r581 r607  
    16571657  cmt_string path_real;
    16581658  //cerr << "realpath_: find_in_cmt_paths" << endl;
    1659   CmtSystem::realpath_ (path, path_real);
     1659  if (!CmtSystem::realpath_ (path, path_real))
     1660    return ("");
    16601661
    16611662  static ProjectVector& Projects = projects ();
     
    16721673      if (s == "default path") continue;
    16731674
    1674       if (CmtSystem::test_directory (p))
     1675      // MUST be directory if project added
     1676      //      if (CmtSystem::test_directory (p))
    16751677        {
    16761678//        if (path.find (p) != cmt_string::npos)
     
    16931695      if (p == w) continue;
    16941696
    1695       if (CmtSystem::test_directory (w))
     1697      // MUST be directory if project added
     1698      //      if (CmtSystem::test_directory (w))
    16961699        {
    16971700          if (path.find (w) != cmt_string::npos)
  • CMT/HEAD/source/cmt_regexp.cxx

    r581 r607  
    1010#include "cmt_system.h"
    1111
     12#include "cmt.h"
    1213//----------------------------------------------------------
    1314//
     
    987988  int p = pos;
    988989 
    989   bool dbg = CmtSystem::testenv ("CMTTESTREGEXP");
     990  bool dbg = false;
     991  if (Cmt::get_debug ()) dbg = CmtSystem::testenv ("CMTTESTREGEXP");
    990992
    991993  if (dbg) {tab (); cerr << "match and (" << this << ") pos=" << pos << endl;}
     
    11151117  if (_nodes.size () == 0) return (cmt_regexp::iterator (pos, 0));
    11161118 
    1117   bool dbg = CmtSystem::testenv ("CMTTESTREGEXP");
     1119  bool dbg = false;
     1120  if (Cmt::get_debug ()) dbg = CmtSystem::testenv ("CMTTESTREGEXP");
    11181121
    11191122  if (dbg) {tab (); cerr << "match or (" << this << ") pos=" << pos << endl;}
     
    15621565  _root = or_root;
    15631566
    1564   bool dbg = CmtSystem::testenv ("CMTTESTREGEXP");
     1567  bool dbg = false;
     1568  if (Cmt::get_debug ()) dbg = CmtSystem::testenv ("CMTTESTREGEXP");
    15651569
    15661570  if (dbg)
  • CMT/HEAD/source/cmt_string.cxx

    r527 r607  
    244244void cmt_string::resize (int n)
    245245{
     246  _size = n;
    246247  allocate (n + 1);
     248  _data[n] = 0;
    247249}
    248250
     
    544546  if ((_data == 0) ||
    545547      (pos < 0) ||
    546       (pos >= _size))
     548      (pos >= _size) ||
     549      length == 0)
    547550    {
    548551      return ((cmt_string) "");
     
    550553  else
    551554    {
     555      //      cerr << "|cmt_string::substr>: `" << *this << "' pos: " << pos << " length: " << length;
     556
     557      if ((pos + length) >= _size ||
     558          length < 0)
     559        {
     560          //      cmt_string result (&_data[pos]);
     561          //cerr << " |---> `" << result << "'" << endl;
     562          //      return (result);
     563          return (&_data[pos]);
     564        }
     565      else
     566        {
     567          cmt_string result;
     568          result.resize (length);
     569          for (int i = 0; i < length; i++)
     570            result[i] = _data[pos + i];
     571          //cerr << " |---> `" << result << "'" << endl;
     572          return (result);
     573        }
     574
     575      /*
    552576      cmt_string result (&_data[pos]);
    553577      result.erase (length);
     578      cerr << " |---> `" << result << "'" << endl;
    554579      return (result);
     580      */
    555581    }
    556582}
     
    574600  if ((_data == 0) ||
    575601      (pos < 0) ||
    576       (pos >= _size))
     602      (pos >= _size) ||
     603      length == 0)
    577604    {
    578605      dest = "";
     
    580607  else
    581608    {
     609      //      cerr << "|void cmt_string::substr>: `" << *this << "' pos: " << pos << " length: " << length;
     610
     611      if ((pos + length) >= _size ||
     612          length < 0)
     613        {
     614          dest = (const char*) &_data[pos];
     615        }
     616      else
     617        {
     618          dest.resize (length);
     619          for (int i = 0; i < length; i++)
     620            dest[i] = _data[pos + i];
     621        }
     622
     623      /*
    582624      dest = (const char*) &_data[pos];
    583625      dest.erase (length);
     626      */
     627      //      cerr << " |---> `" << dest << "'" << endl;
    584628    }
    585629}
  • CMT/HEAD/source/cmt_symbol.cxx

    r603 r607  
    22242224  static const cmt_string path_separator = CmtSystem::path_separator ();
    22252225
    2226   cmt_string here = CmtSystem::pwd ();
     2226  //  cmt_string here = CmtSystem::pwd ();
    22272227  cmt_string rvalue = value;
    22282228
     2229  /*
    22292230  if (CmtSystem::cd (value))
    22302231    {
     
    22322233    }
    22332234  else
     2235  */
     2236  if (!CmtSystem::realpath_ (value, rvalue))
    22342237    {
    22352238      CmtSystem::compress_path (rvalue);
     
    22452248      const cmt_string& item = items[i];
    22462249      cmt_string ritem = item;
     2250      /*
    22472251      if (CmtSystem::cd (item))
    22482252        {
     
    22502254        }
    22512255      else
     2256      */
     2257      if (!CmtSystem::realpath_ (item, ritem))
    22522258        {
    22532259          CmtSystem::compress_path (ritem);
     
    22612267    }
    22622268
    2263   CmtSystem::cd (here);
     2269  //  CmtSystem::cd (here);
    22642270  return (found);
    22652271}
  • CMT/HEAD/source/cmt_syntax.cxx

    r568 r607  
    16821682    }
    16831683
    1684   text.read (actual_file_name);
     1684  if (!text.read (actual_file_name))
     1685    {
     1686      CmtError::set (CmtError::file_access_error, actual_file_name);
     1687      return;
     1688    }
    16851689
    16861690  SyntaxParser::parse_requirements_text (text, actual_file_name, use);
     
    16941698 *  Each reformatted line is parsed by filter_line
    16951699 */
     1700void SyntaxParser::do_parse_text (const cmt_string& text,
     1701                                  const cmt_string& file_name,
     1702                                  ContextType context,
     1703                                  Use* use,
     1704                                  Project* project)
     1705{
     1706  cmt_string line;
     1707  int line_number = 1;
     1708
     1709  if (context == package_context)
     1710    {
     1711      if (use == 0) use = &(Use::current ());
     1712    }
     1713
     1714  m_filtered_text.erase (0);
     1715
     1716  int nl;
     1717  int begin = 0;
     1718  int end = text.size ();
     1719
     1720  while ((nl = text.find (begin, '\n')) != cmt_string::npos)
     1721    {
     1722      if (begin < nl && text[nl - 1] == '\r')
     1723        {
     1724          text.substr (begin, nl - 1 - begin, line);
     1725        }
     1726      else
     1727        {
     1728          text.substr (begin, nl - begin, line);
     1729        }
     1730      //      cerr << "|do_parse_text> [" << line << "]" << endl;
     1731      do_parse_line (line, file_name, line_number, context, use, project);
     1732      line_number++;
     1733      begin = nl + 1;
     1734    } // while ((nl = text.find (begin, '\n')) != cmt_string::npos)
     1735
     1736  if (begin < end)
     1737    {
     1738      text.substr (begin, end - begin, line);
     1739      do_parse_line (line, file_name, line_number, context, use, project);
     1740    }
     1741
     1742}
     1743/*
    16961744void SyntaxParser::do_parse_text (const cmt_string& text,
    16971745                                  const cmt_string& file_name,
     
    17621810    }
    17631811}
     1812*/
    17641813
    17651814void SyntaxParser::do_parse_line (const cmt_string& line,
     
    17941843  bool finished = true;
    17951844
    1796   length = temp_line.size ();
     1845  //  length = temp_line.size ();
    17971846
    17981847  back_slash = temp_line.find_last_of ('\\');
  • CMT/HEAD/source/cmt_system.cxx

    r599 r607  
    334334}
    335335
     336//--------------------------------------------------
     337bool CmtSystem::realpath_ (const cmt_string& path, cmt_string& result)
     338{
     339  char buffer[PATH_MAX + 1];
     340#ifndef WIN32
     341  if (::realpath (path, buffer))
     342    {
     343      result = buffer;
     344      //      cerr << "path: " << path << " result: " << result << endl;
     345      return true;
     346    }
     347  else
     348    {
     349      //      cerr << "path: " << path << " result: " << result << endl;
     350      if (errno != ENOENT
     351          && errno != ENOTDIR
     352          )
     353        {
     354          perror ("cmt: realpath failure: " + get_absolute_path (path));
     355        }
     356      return false;
     357    }
     358#else
     359  if (::_fullpath (buffer, path, PATH_MAX + 1))
     360    {
     361      result = buffer;
     362      return true;
     363    }
     364  else
     365    {
     366      return false;
     367    }
     368#endif
     369}
     370
     371/*
    336372//--------------------------------------------------
    337373bool CmtSystem::realpath_ (const cmt_string& path, cmt_string& result)
     
    359395  return false;
    360396}
    361 
     397*/
    362398//--------------------------------------------------
    363399bool CmtSystem::absolute_path (const cmt_string& name)
  • CMT/HEAD/source/cmt_use.cxx

    r597 r607  
    35743574      //      offset.replace (cmtpath, empty_string);
    35753575      //cerr << "realpath_: get_cmtpath_and_offset" << endl;
    3576       CmtSystem::realpath_ (real_path, offset);
     3576      if (!CmtSystem::realpath_ (real_path, offset))
     3577        {
     3578          CmtError::set (CmtError::file_access_error, "Cannot compute real path `" +
     3579                         real_path + "'");
     3580          CmtError::print ();
     3581          return;
     3582        }
    35773583      offset.replace (p->get_cmtpath_real (), empty_string);
    35783584
Note: See TracChangeset for help on using the changeset viewer.