Reindented server/core/externcmd.[c|h]

Reindented server/core/externcmd.[c|h] and added copyright
message.
This commit is contained in:
Johan Wikman
2015-11-30 12:41:20 +02:00
parent 2afe60dd0e
commit bd94d8967a
2 changed files with 50 additions and 10 deletions

View File

@ -1,3 +1,21 @@
/*
* This file is distributed as part of the MariaDB Corporation MaxScale. It is free
* software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation,
* version 2.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright MariaDB Corporation Ab 2013-2014
*/
#include <externcmd.h> #include <externcmd.h>
/** /**
@ -20,19 +38,19 @@ int tokenize_arguments(char* argstr, char** argv)
start = args; start = args;
ptr = start; ptr = start;
while(*ptr != '\0' && i < MAXSCALE_EXTCMD_ARG_MAX) while (*ptr != '\0' && i < MAXSCALE_EXTCMD_ARG_MAX)
{ {
if(escaped) if (escaped)
{ {
escaped = false; escaped = false;
} }
else else
{ {
if(*ptr == '\\') if (*ptr == '\\')
{ {
escaped = true; escaped = true;
} }
else if(quoted && !escaped && *ptr == qc) /** End of quoted string */ else if (quoted && !escaped && *ptr == qc) /** End of quoted string */
{ {
*ptr = '\0'; *ptr = '\0';
argv[i++] = strdup(start); argv[i++] = strdup(start);
@ -41,23 +59,23 @@ int tokenize_arguments(char* argstr, char** argv)
} }
else if (!quoted) else if (!quoted)
{ {
if(isspace(*ptr)) if (isspace(*ptr))
{ {
*ptr = '\0'; *ptr = '\0';
if(read) /** New token */ if (read) /** New token */
{ {
argv[i++] = strdup(start); argv[i++] = strdup(start);
read = false; read = false;
} }
} }
else if( *ptr == '\"' || *ptr == '\'') else if (*ptr == '\"' || *ptr == '\'')
{ {
/** New quoted token, strip quotes */ /** New quoted token, strip quotes */
quoted = true; quoted = true;
qc = *ptr; qc = *ptr;
start = ptr + 1; start = ptr + 1;
} }
else if(!read) else if (!read)
{ {
start = ptr; start = ptr;
read = true; read = true;
@ -66,8 +84,11 @@ int tokenize_arguments(char* argstr, char** argv)
} }
ptr++; ptr++;
} }
if(read) if (read)
{
argv[i++] = strdup(start); argv[i++] = strdup(start);
}
argv[i] = NULL; argv[i] = NULL;
return 0; return 0;

View File

@ -1,5 +1,22 @@
#ifndef _EXTERN_CMD_HG #ifndef _EXTERN_CMD_HG
#define _EXTERN_CMD_HG #define _EXTERN_CMD_HG
/*
* This file is distributed as part of the MariaDB Corporation MaxScale. It is free
* software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation,
* version 2.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright MariaDB Corporation Ab 2013-2014
*/
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
@ -10,7 +27,8 @@
#define MAXSCALE_EXTCMD_ARG_MAX 256 #define MAXSCALE_EXTCMD_ARG_MAX 256
typedef struct extern_cmd_t{ typedef struct extern_cmd_t
{
char** argv; /*< Argument vector for the command, first being the actual command char** argv; /*< Argument vector for the command, first being the actual command
* being executed. */ * being executed. */
int n_exec; /*< Number of times executed */ int n_exec; /*< Number of times executed */
@ -23,4 +41,5 @@ void externcmd_free(EXTERNCMD* cmd);
int externcmd_execute(EXTERNCMD* cmd); int externcmd_execute(EXTERNCMD* cmd);
bool externcmd_substitute_arg(EXTERNCMD* cmd, const char* re, const char* replace); bool externcmd_substitute_arg(EXTERNCMD* cmd, const char* re, const char* replace);
bool externcmd_can_execute(const char* argstr); bool externcmd_can_execute(const char* argstr);
#endif #endif