Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions
nsInstallExecute.h File Reference
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
#include "nsIDOMInstallVersion.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  nsInstallExecute

Functions

PRInt32 xpi_PrepareProcessArguments (const char *aArgsString, char **aArgs, PRInt32 aArgsAvailable)

Function Documentation

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: