Changeset caff45d in tol


Ignore:
Timestamp:
Jan 2, 2012, 3:05:37 PM (15 years ago)
Author:
Jorge Pérez <josp.jorge@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
aa709a5
Parents:
633537f
Message:

refs #1118, function POpen, must compiled and tested on windows

Set View( POpen( [[ "svn", "status" ]] ), "" );

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

File:
1 edited

Legend:

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

    r633537f rcaff45d  
    5353#include "llkarma.h"
    5454
     55#ifdef WIN32
     56#define popen _popen
     57#define pclose _pclose
     58#endif
    5559
    5660//static const char* bayesVersionId =
    … …  
    27822786  }
    27832787}
     2788
     2789//--------------------------------------------------------------------
     2790DeclareContensClass(BSet, BSetTemporary, BSetPOpen);
     2791DefExtOpr(1, BSetPOpen, "POpen", 1, 1,
     2792          "Set",
     2793          "(Set Args)",
     2794          I2("Execute an external program. The output of the program is returned in the member output.",
     2795             "Ejecuta un programa externo. la salida del programa se retorna en el miembro ouput del conjunto resultado."),
     2796          BOperClassify::System_);
     2797
     2798#ifdef POPEN
     2799//--------------------------------------------------------------------
     2800void BSetPOpen::CalcContens()
     2801//--------------------------------------------------------------------
     2802{
     2803  const BSet& args = Set(Arg(1));
     2804  BDat status;
     2805  BText desc, output;
     2806  if ( args.Card() ) {
     2807    BText cmd;
     2808    int badArg = 0;
     2809    for ( int i = 1; i <= args.Card(); i++ ) {
     2810      cmd += '"';
     2811      BSyntaxObject* arg  = args[ i ];
     2812      if ( arg->Grammar() != GraText() ) {
     2813        status = 0;
     2814        desc = I2( "all argument must be of type Text",
     2815                   "todos los argumentos deben ser de tipo texto" );
     2816        badArg = 1;
     2817      }
     2818      const BText &txt = Text( arg );
     2819      cmd += txt;
     2820      cmd += "\" ";
     2821    }
     2822    if ( !badArg ) {
     2823      FILE* pipe = popen(cmd, "r");
     2824      if ( pipe ) {
     2825        char buffer[128];
     2826        output = "";
     2827        while( !feof( pipe ) ) {
     2828          if( fgets( buffer, 128, pipe ) != NULL )
     2829            output += buffer;
     2830        }
     2831        status = 1;
     2832        desc = "";
     2833        pclose( pipe );
     2834      }
     2835    } else {
     2836      status = 0;
     2837      BText desc = I2( "Could not execute: ", "No se pudo ejecutar: " );
     2838      desc += cmd;
     2839      BText output = "";
     2840    }
     2841  } else {
     2842    status = 0;
     2843    BText desc = I2( "Nothing to execute", "Nada que ejecutar" );
     2844    BText output = "";
     2845  }
     2846  BList * result = NIL;
     2847  BSyntaxObject * so;
     2848  result = Cons(so = new BContensDat("", status), result);
     2849  so->PutName("status");
     2850  result = Cons(so = new BContensText("", desc), result);
     2851  so->PutName("description");
     2852  result = Cons(so = new BContensText("", output), result);
     2853  so->PutName("output");
     2854  contens_.RobElement(result); 
     2855}
     2856#endif
Note: See TracChangeset for help on using the changeset viewer.