Changeset 1678 for trunk/gsdl/lib


Ignore:
Timestamp:
2000-11-20T14:00:34+13:00 (23 years ago)
Author:
sjboddie
Message:

Re-added some recent changes that got lost when the cvs repository was
moved. This was mostly changes to the collector and building code

Location:
trunk/gsdl/lib
Files:
2 edited

Legend:

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

    r1456 r1678  
    2626#include "gsdltools.h"
    2727
     28#if defined(__WIN32__)
     29#include <windows.h>
     30#include <process.h>
     31#endif
     32
    2833bool littleEndian() {
    2934  char s[2] = {'\xFE', '\xEF'};
     
    5257// characters (e.g. '&') should be quoted with ""
    5358
    54 // on unix systems youcan get the same effext as this function by doing a
    55 // system call and putting the spawned process in the background
    56 // (e.g. system (funcname options &);
    57 
    5859#if defined (__WIN32__)
    59 #include <windows.h>
    6060void gsdl_system (char *cmd, ostream &logout) {
    6161
     
    101101  }
    102102}
     103#endif
    103104
     105
     106// gsdl_call_perl executes the perl script perl_cmd, passing it all the
     107// arguments provided.
     108
     109// Arguments should be char*'s, the last argument should be NULL
     110
     111// perl_cmd shouldn't contain the path to the script as we use "perl -S"
     112// to find it. This means that the PATH environment variable of the calling
     113// process should contain the directory where the perl_cmd script lives.
     114
     115// Uses a standard system() call on unix and a synchronous _spawn() on windows.
     116// We use the _spawn() because windows 9* doesn't seem to pass the
     117// environment of the calling process to the new process when using
     118// system (which we need to do).
     119
     120// all arguments will be quoted with double quotes [""] so they should be unquoted
     121// when passed in.
     122
     123// returns the exit status of the called process (-1 if system() or _spawn() failed)
     124
     125int gsdl_call_perl (char *perl_cmd, ...) {
     126
     127  va_list argn;
     128  char *thisarg = perl_cmd;
     129
     130#if defined(__WIN32__) && !defined (__GNUC__)
     131  int i = 2;
     132#define GSDL_MAX_ARGS 20
     133  char *args[GSDL_MAX_ARGS];
     134  args[0] = "perl";
     135  args[1] = "-S";
     136#else
     137  text_t cmd = "perl -S";
    104138#endif
     139
     140  // get arguments
     141  va_start(argn, perl_cmd);
     142  while(thisarg != NULL) {
     143#if defined(__WIN32__) && !defined (__GNUC__)
     144    if (i >= GSDL_MAX_ARGS) break;
     145    text_t tmp = thisarg;
     146    tmp = "\"" + tmp + "\"";
     147    args[i] = tmp.getcstr();
     148    i++;
     149#else
     150    cmd += " \"";
     151    cmd += thisarg;
     152    cmd.push_back ('"');
     153#endif
     154    thisarg = va_arg(argn, char *);
     155  }
     156  va_end(argn);
     157
     158#if defined(__WIN32__) && !defined (__GNUC__)
     159  args[i] = NULL;
     160  int rv = _spawnvp (_P_WAIT, "perl", args);
     161  while (--i > 2) delete (args[i]);
     162#else
     163  char *cmdc = cmd.getcstr();
     164  int rv = system (cmdc);
     165  delete (cmdc);
     166#endif
     167  return rv;
     168}
  • trunk/gsdl/lib/gsdltools.h

    r1456 r1678  
    3636bool littleEndian();
    3737
     38
    3839// escapes '\' and '_' characters with '\'
    3940// note that single '\' characters occurring
     
    4647// program continues and terminates normally). Arguments containing special
    4748// characters (e.g. '&') should be quoted with ""
     49void gsdl_system (char *cmd, ostream &logout);
    4850
    49 // on unix systems youcan get the same effext as this function by doing a
    50 // system call and putting the spawned process in the background
    51 // (e.g. system (funcname options &);
    52 //#if defined (__WIN32__)
    53 void gsdl_system (char *cmd, ostream &logout);
    54 //#endif
     51
     52// gsdl_call_perl executes the perl script perl_cmd, passing it all the
     53// arguments provided.
     54
     55// Arguments should be text_t's, the last argument should be an empty text_t.
     56
     57// perl_cmd shouldn't contain the path to the script as we use "perl -S"
     58// to find it. This means that the PATH environment variable of the calling
     59// process should contain the directory where the perl_cmd script lives.
     60
     61// Uses a standard system() call on unix and a synchronous _spawn() on windows.
     62// We use the _spawn() because windows 9* doesn't seem to pass the
     63// environment of the calling process to the new process when using
     64// system (which we need to do).
     65
     66// all arguments will be quoted with double quotes [""] so they should be unquoted
     67// when passed in.
     68
     69// returns the exit status of the called process (-1 if system() or _spawn() failed)
     70int gsdl_call_perl (char *perl_cmd, ...);
     71
    5572
    5673#endif
Note: See TracChangeset for help on using the changeset viewer.