src/lib/bpipe.c
static void build_argc_argv(char *cmd, int *bargc, char *bargv[], int max_argv)
{
   int i;
   char *p, *q, quote;
   int argc = 0;

   argc = 0;
   for (i=0; i<max_argv; i++)
      bargv[i] = NULL;

   p = cmd;
   quote = 0;
   while  (*p && (*p == ' ' || *p == '\t'))
      p++;
   if (*p == '\"' || *p == '\'') {
      quote = *p;
      p++;
   }
   if (*p) {
      while (*p && argc < MAX_ARGV) {
         q = p;
         if (quote) {
            while (*q && *q != quote)
            q++;
            quote = 0;
         } else {
            while (*q && *q != ' ')
            q++;
         }
         if (*q)
            *(q++) = '\0';
         bargv[argc++] = p;
         p = q;
         while (*p && (*p == ' ' || *p == '\t'))
            p++;
         if (*p == '\"' || *p == '\'') {
            quote = *p;
            p++;
         }
      }
   }
   *bargc = argc;
}
/*
 * Build argc and argv from a string
 */
Build argc and argv from a string
Build argc and argv from a string
static void build_argc_argv(char *cmd, int *bargc, char *bargv[], int max_argv)
{
   int i;
   char *p, *q, quote;
   int argc = 0;
   argc = 0;
   for (i=0; i<max_argv; i++)
      bargv[i] = NULL;
   p = cmd;
   quote = 0;
   while  (*p && (*p == ' ' || *p == '\t'))
      p++;
   if (*p == '\"' || *p == '\'') {
      quote = *p;
      p++;
   }
   if (*p) {
      while (*p && argc < MAX_ARGV) {
         q = p;
         if (quote) {
            while (*q && *q != quote)
            q++;
            quote = 0;
         } else {
            while (*q && *q != ' ')
            q++;
         }
         if (*q)
            *(q++) = '\0';
         bargv[argc++] = p;
         p = q;
         while (*p && (*p == ' ' || *p == '\t'))
            p++;
         if (*p == '\"' || *p == '\'') {
            quote = *p;
            p++;
         }
      }
   }
   *bargc = argc;
}
static void build_argc_argv ( char * cmd , int * bargc , char * bargv [ ] , int max_argv ) { int i ; char * p , * q , quote ; int argc = 0 ; argc = 0 ; for ( i = 0 ; i < max_argv ; i ++ ) bargv [ i ] = NULL ; p = cmd ; quote = 0 ; while ( * p && ( * p == ' ' || * p == ' \t ' ) ) p ++ ; if ( * p == ' \" ' || * p == ' \' ' ) { quote = * p ; p ++ ; } if ( * p ) { while ( * p && argc < MAX_ARGV ) { q = p ; if ( quote ) { while ( * q && * q != quote ) q ++ ; quote = 0 ; } else { while ( * q && * q != ' ' ) q ++ ; } if ( * q ) * ( q ++ ) = ' \0 ' ; bargv [ argc ++ ] = p ; p = q ; while ( * p && ( * p == ' ' || * p == ' \t ' ) ) p ++ ; if ( * p == ' \" ' || * p == ' \' ' ) { quote = * p ; p ++ ; } } } * bargc = argc ; }
Build argc and argv from a string
Build argc and argv from a string