Changeset 448421b in tol


Ignore:
Timestamp:
Jan 3, 2012, 5:33:17 PM (15 years ago)
Author:
Jorge Pérez <josp.jorge@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
0d27864
Parents:
c495c08
Message:

refs #1118, using PExec as a more appropiate name, also implementing automatic protect of arguments with spaces (pending check on windows)

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@3981 be4846ae-f051-483a-831f-b64e7d08527f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol/btol/set_type/setgra.cpp

    rc495c08 r448421b  
    27882788
    27892789//--------------------------------------------------------------------
    2790 DeclareContensClass(BSet, BSetTemporary, BSetPOpen);
    2791 DefExtOpr(1, BSetPOpen, "POpen", 1, 1,
     2790DeclareContensClass(BSet, BSetTemporary, BSetPExec);
     2791DefExtOpr(1, BSetPExec, "PExec", 1, 1,
    27922792          "Set",
    27932793          "(Set Args)",
    … …  
    27962796          BOperClassify::System_);
    27972797
    2798 #define POPEN
    2799 #ifdef POPEN
    2800 //--------------------------------------------------------------------
    2801 void BSetPOpen::CalcContens()
     2798#ifdef WIN32
     2799void escapeCmdArg( const char *input, BText &output )
     2800{
     2801  const char *pCh = input;
     2802  int bs = 0;
     2803  int need = 0;
     2804 
     2805  while ( *pCh ) {
     2806    if ( !bs && *pCh == ' ' ) {
     2807      need = 1;
     2808      break;
     2809    }
     2810    bs = ((*pCh == '\\') && !bs);
     2811    ++pCh;
     2812  }
     2813  if ( need ) {
     2814    output = "\"";
     2815    output += input;
     2816    output += "\"";
     2817  } else {
     2818    output = input;
     2819  }
     2820}
     2821#else
     2822void escapeCmdArg( const char *input, BText &output )
     2823{
     2824  const char *pCh = input;
     2825  output = "";
     2826  int bs = 0;
     2827 
     2828  while ( *pCh ) {
     2829    if ( !bs && *pCh == ' ' ) {
     2830      output += "\\ ";
     2831    } else {
     2832      output += *pCh;
     2833    }
     2834    bs = ((*pCh == '\\') && !bs);
     2835    ++pCh;
     2836  }
     2837}
     2838#endif
     2839
     2840//--------------------------------------------------------------------
     2841void BSetPExec::CalcContens()
    28022842//--------------------------------------------------------------------
    28032843{
    … …  
    28162856        badArg = 1;
    28172857      }
    2818       const BText &txt = Text( arg );
    2819           /*
    2820           char *start = txt.Buffer();
    2821           char *end ;
    2822           char *tmp = new char[ txt.Length() ];
    2823           do {
    2824                 end = start;
    2825                 int bs = 0;
    2826                 while ( *end ) {
    2827                   if ( !bs && isspace( *end ) ) break;
    2828                   bs = *end == '\\';
    2829                   ++end
    2830                 }
    2831           }
    2832           while ( *end ) {
    2833             cmd += strncpy( tmp, start, end - start );
    2834                 cmd += "\\ ";
    2835                 start = end + 1;
    2836           }
    2837           delete []tmp;
    2838           */
    2839       cmd += txt;
    2840       cmd += " ";
     2858      BText &_arg = Text( arg ), escapedArg;
     2859      escapeCmdArg( _arg, escapedArg );
     2860      if ( i > 1 ) {
     2861        cmd += " ";
     2862      }
     2863      cmd += escapedArg;
    28412864    }
    28422865    if ( !badArg ) {
    … …  
    28752898  contens_.RobElement(result); 
    28762899}
    2877 #endif
Note: See TracChangeset for help on using the changeset viewer.