Logo Search packages:      
Sourcecode: condor version File versions  Download package

cgahp_common.cpp

/***************************************************************
 *
 * Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
 * University of Wisconsin-Madison, WI.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License.  You may
 * obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ***************************************************************/

#include "condor_common.h"
#include "cgahp_common.h"
#include "condor_debug.h"

int
parse_gahp_command (const char* raw, Gahp_Args* args) {

      if (!raw) {
            dprintf(D_ALWAYS,"ERROR parse_gahp_command: empty command\n");
            return FALSE;
      }

      args->reset();

      int beginning = 0;

      int len=strlen(raw);

      char * buff = (char*)malloc(len+1);
      int buff_len = 0;

      for (int i = 0; i<len; i++) {

            if ( raw[i] == '\\' ) {
                  i++;              //skip this char
                  if (i<(len-1))
                        buff[buff_len++] = raw[i];
                  continue;
            }

            /* Check if charcater read was whitespace */
            if ( raw[i]==' ' || raw[i]=='\t' || raw[i]=='\r' || raw[i] == '\n') {

                  /* Handle Transparency: we would only see these chars
                  if they WEREN'T escaped, so treat them as arg separators
                  */
                  buff[buff_len++] = '\0';
                  args->add_arg( strdup(buff) );
                  buff_len = 0;     // re-set temporary buffer

                  beginning = i+1; // next char will be one after whitespace
            }
            else {
                  // It's just a regular character, save it
                  buff[buff_len++] = raw[i];
            }
      }

      /* Copy the last portion */
      buff[buff_len++] = '\0';
      args->add_arg( strdup(buff) );

      free (buff);
      return TRUE;


}

Generated by  Doxygen 1.6.0   Back to index