Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
nsInstallExecute.cpp File Reference
#include "nsCRT.h"
#include "prmem.h"
#include "VerReg.h"
#include "nsInstallExecute.h"
#include "nsInstallResources.h"
#include "ScheduledTasks.h"
#include "nsInstall.h"
#include "nsIDOMInstallVersion.h"
#include "nsProcess.h"
#include "nsReadableUtils.h"

Go to the source code of this file.

Defines

#define ARG_SLOTS   256

Functions

static NS_DEFINE_CID (kIProcessCID, NS_PROCESS_CID)
PRInt32 xpi_PrepareProcessArguments (const char *aArgsString, char **aArgs, PRInt32 aArgsAvailable)

Define Documentation

#define ARG_SLOTS   256

Function Documentation

static NS_DEFINE_CID ( kIProcessCID  ,
NS_PROCESS_CID   
) [static]
PRInt32 xpi_PrepareProcessArguments ( const char *  aArgsString,
char **  aArgs,
PRInt32  aArgsAvailable 
)

Definition at line 72 of file nsInstallExecute.cpp.

{
   int   argc;
   char *c;
   char *p; // look ahead
   PRBool quoted = PR_FALSE;

   aArgs[0] = (char *)aArgsString;
   if (!aArgs[0])
      return -1;

   // Strip leading spaces from command-line string.
   argc = 0;
   c = aArgs[argc];
   while (*c == ' ') ++c;
   aArgs[argc++] = c;

   for (; *c && argc < aArgsAvailable; ++c) 
   {
      switch(*c) {

      // Only handle escaped double quote and escaped backslash.
      case '\\':
         // See if next character is backslash or dquote
         if ( *(c+1) == '\\' || *(c+1) == '\"' )
         {
            // Eat escape character (i.e., backslash) by
            //   shifting all characters to the left one.
            for (p=c; *p != 0; ++p)
               *p = *(p+1);
         }
         break;

      case '\"':
         *c = 0; // terminate current arg
         if (quoted) 
         {
            p = c+1; // look ahead
            while (*p == ' ')
               ++p; // eat spaces
            if (*p)
               aArgs[argc++] = p; //not at end, set next arg
            c = p-1;

            quoted = PR_FALSE;
         }
         else 
         {
            quoted = PR_TRUE;

            if (aArgs[argc-1] == c)
              // Quote is at beginning so 
              //   start current argument after the quote.
              aArgs[argc-1] = c+1;
            else
              // Quote is embedded so 
              //   start a new argument after the quote.
              aArgs[argc++] = c+1;
         }
         break;

      case ' ':
         if (!quoted) 
         {
            *c = 0; // terminate current arg
            p = c+1; // look ahead
            while (*p == ' ')
               ++p; // eat spaces
            if (*p)
               aArgs[argc++] = p; //not at end, set next arg
            c = p-1;
         }
         break;

      default:
         break;  // nothing to do
      }
   }
   return argc;
}

Here is the caller graph for this function: