cvsuser     04/08/07 07:09:39

  Modified:    config/gen/platform/win32 exec.c
  Log:
  Add proper exec code for Win32
  
  Courtesy of "Jonathan Worthington" <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.9       +76 -9     parrot/config/gen/platform/win32/exec.c
  
  Index: exec.c
  ===================================================================
  RCS file: /cvs/public/parrot/config/gen/platform/win32/exec.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -w -r1.8 -r1.9
  --- exec.c    5 Aug 2004 17:43:06 -0000       1.8
  +++ exec.c    7 Aug 2004 14:09:39 -0000       1.9
  @@ -44,13 +44,80 @@
   }
   
   void 
  -Parrot_Exec_OS_Command(Parrot_Interp interpreter, STRING *command) {
  -  /* Be horribly profligate with memory, since we're
  -     about to be something else */
  +Parrot_Exec_OS_Command(Parrot_Interp interpreter, STRING *command)
  +{
     int status;
  -  status = _execlp(string_to_cstring(interpreter, command), NULL);
  -  /* if we get here, something's horribly wrong... */
  +     char *in = string_to_cstring(interpreter, command);
  +     char *cmd = NULL;
  +     char **argv = mem_sys_allocate_zeroed(2 * sizeof(int));
  +
  +     /* Grab string, extract command and parameters. */
  +     char *curPos = in;
  +     char *lastCommandStart = in;
  +     char seekChar = 0; 
  +     int argc = 1;
  +     while (*curPos)
  +     {
  +             /* If we don't have a seek character and this is a quote... */
  +             if (seekChar == 0 && (*curPos == '\'' || *curPos == '"'))
  +             {
  +                     seekChar = *curPos;
  +                     lastCommandStart = curPos;
  +             }
  +
  +             /* If we don't have a seek character and this is not a space... */
  +             else if (seekChar == 0 && *curPos != ' ')
  +             {
  +                     if (!seekChar)
  +                             seekChar = ' ';
  +                     lastCommandStart = curPos;
  +             }
  +
  +             /* If we seek the seek character... */
  +             else if (*curPos == seekChar || (*(curPos + 1) == 0 && seekChar == ' 
'))
  +             {
  +                     /* Copy what we found to a temporary string. */
  +                     char *tmp;
  +                     int lenFound = curPos - lastCommandStart;
  +                     if (*(curPos + 1) == 0)
  +                             lenFound++;
  +                     tmp = mem_sys_allocate(1 + lenFound);
  +                     memcpy(tmp, lastCommandStart, lenFound);
  +                     *(tmp + lenFound) = 0;
  +                     
  +                     /* Is it command or argument? */
  +                     if (cmd == NULL)
  +                     {
  +                             cmd = tmp;
  +                             *argv = tmp;
  +                     }
  +                     else
  +                     {
  +                             /* Allocate space for another pointer in **argv. */
  +                             argc++;
  +                             argv = mem_sys_realloc(argv, (argc + 1) * sizeof(int));
  +                             *(argv + (argc - 1)) = tmp;
  +                             *(argv + argc) = NULL;
  +                     }
  +
  +                     /* Clear seek character. */
  +                     seekChar = 0;
  +             }
  +
  +             /* Move to next character. */
  +             curPos ++;
  +     }
  +
  +     /* If we still have a seek char, then the input was improper. */
  +     if (seekChar)
  +     {
  +             internal_exception(NOSPAWN, "Exec failed, invalid command string");
  +     }
  +
  +     /* Now do the exec. */
  +     status = _execvp(cmd, argv);
     if (status) {
       internal_exception(NOSPAWN, "Exec failed, code %i", status);
     }
   }
  +
  
  
  

Reply via email to