@@ -245,7 +245,8 @@ static void end_pager();
245
245
static void init_tee (const char *);
246
246
static void end_tee ();
247
247
static const char * construct_prompt ();
248
- static char *get_arg (char *line, my_bool get_next_arg);
248
+ enum get_arg_mode { CHECK, GET, GET_NEXT};
249
+ static char *get_arg (char *line, get_arg_mode mode);
249
250
static void init_username ();
250
251
static void add_int_to_prompt (int toadd);
251
252
static int get_result_width (MYSQL_RES *res);
@@ -2223,7 +2224,7 @@ static COMMANDS *find_command(char *name)
2223
2224
if (!my_strnncoll (&my_charset_latin1, (uchar*) name, len,
2224
2225
(uchar*) commands[i].name , len) &&
2225
2226
(commands[i].name [len] == ' \0 ' ) &&
2226
- (!end || commands[i].takes_params ))
2227
+ (!end || ( commands[i].takes_params && get_arg (name, CHECK)) ))
2227
2228
{
2228
2229
index= i;
2229
2230
break ;
@@ -3143,7 +3144,7 @@ com_charset(String *buffer __attribute__((unused)), char *line)
3143
3144
char buff[256 ], *param;
3144
3145
CHARSET_INFO * new_cs;
3145
3146
strmake_buf (buff, line);
3146
- param= get_arg (buff, 0 );
3147
+ param= get_arg (buff, GET );
3147
3148
if (!param || !*param)
3148
3149
{
3149
3150
return put_info (" Usage: \\ C charset_name | charset charset_name" ,
@@ -4228,12 +4229,12 @@ com_connect(String *buffer, char *line)
4228
4229
#ifdef EXTRA_DEBUG
4229
4230
tmp[1 ]= 0 ;
4230
4231
#endif
4231
- tmp= get_arg (buff, 0 );
4232
+ tmp= get_arg (buff, GET );
4232
4233
if (tmp && *tmp)
4233
4234
{
4234
4235
my_free (current_db);
4235
4236
current_db= my_strdup (tmp, MYF (MY_WME));
4236
- tmp= get_arg (buff, 1 );
4237
+ tmp= get_arg (buff, GET_NEXT );
4237
4238
if (tmp)
4238
4239
{
4239
4240
my_free (current_host);
@@ -4336,7 +4337,7 @@ com_delimiter(String *buffer __attribute__((unused)), char *line)
4336
4337
char buff[256 ], *tmp;
4337
4338
4338
4339
strmake_buf (buff, line);
4339
- tmp= get_arg (buff, 0 );
4340
+ tmp= get_arg (buff, GET );
4340
4341
4341
4342
if (!tmp || !*tmp)
4342
4343
{
@@ -4367,7 +4368,7 @@ com_use(String *buffer __attribute__((unused)), char *line)
4367
4368
4368
4369
bzero (buff, sizeof (buff));
4369
4370
strmake_buf (buff, line);
4370
- tmp= get_arg (buff, 0 );
4371
+ tmp= get_arg (buff, GET );
4371
4372
if (!tmp || !*tmp)
4372
4373
{
4373
4374
put_info (" USE must be followed by a database name" , INFO_ERROR);
@@ -4452,23 +4453,22 @@ com_nowarnings(String *buffer __attribute__((unused)),
4452
4453
}
4453
4454
4454
4455
/*
4455
- Gets argument from a command on the command line. If get_next_arg is
4456
- not defined, skips the command and returns the first argument. The
4457
- line is modified by adding zero to the end of the argument. If
4458
- get_next_arg is defined, then the function searches for end of string
4459
- first, after found, returns the next argument and adds zero to the
4460
- end. If you ever wish to use this feature, remember to initialize all
4461
- items in the array to zero first.
4456
+ Gets argument from a command on the command line. If mode is not GET_NEXT,
4457
+ skips the command and returns the first argument. The line is modified by
4458
+ adding zero to the end of the argument. If mode is GET_NEXT, then the
4459
+ function searches for end of string first, after found, returns the next
4460
+ argument and adds zero to the end. If you ever wish to use this feature,
4461
+ remember to initialize all items in the array to zero first.
4462
4462
*/
4463
4463
4464
- char *get_arg (char *line, my_bool get_next_arg )
4464
+ static char *get_arg (char *line, get_arg_mode mode )
4465
4465
{
4466
4466
char *ptr, *start;
4467
- my_bool quoted= 0 , valid_arg= 0 ;
4467
+ bool short_cmd= false ;
4468
4468
char qtype= 0 ;
4469
4469
4470
4470
ptr= line;
4471
- if (get_next_arg )
4471
+ if (mode == GET_NEXT )
4472
4472
{
4473
4473
for (; *ptr; ptr++) ;
4474
4474
if (*(ptr + 1 ))
@@ -4479,7 +4479,7 @@ char *get_arg(char *line, my_bool get_next_arg)
4479
4479
/* skip leading white spaces */
4480
4480
while (my_isspace (charset_info, *ptr))
4481
4481
ptr++;
4482
- if (*ptr == ' \\ ' ) // short command was used
4482
+ if ((short_cmd= *ptr == ' \\ ' ) ) // short command was used
4483
4483
ptr+= 2 ;
4484
4484
else
4485
4485
while (*ptr &&!my_isspace (charset_info, *ptr)) // skip command
@@ -4492,24 +4492,28 @@ char *get_arg(char *line, my_bool get_next_arg)
4492
4492
if (*ptr == ' \' ' || *ptr == ' \" ' || *ptr == ' `' )
4493
4493
{
4494
4494
qtype= *ptr;
4495
- quoted= 1 ;
4496
4495
ptr++;
4497
4496
}
4498
4497
for (start=ptr ; *ptr; ptr++)
4499
4498
{
4500
- if (*ptr == ' \\ ' && ptr[1 ]) // escaped character
4499
+ if ((*ptr == ' \\ ' && ptr[1 ]) || // escaped character
4500
+ (!short_cmd && qtype && *ptr == qtype && ptr[1 ] == qtype)) // quote
4501
4501
{
4502
- // Remove the backslash
4503
- strmov_overlapp (ptr, ptr+1 );
4502
+ // Remove (or skip) the backslash (or a second quote)
4503
+ if (mode != CHECK)
4504
+ strmov_overlapp (ptr, ptr+1 );
4505
+ else
4506
+ ptr++;
4504
4507
}
4505
- else if ((!quoted && *ptr == ' ' ) || (quoted && *ptr == qtype ))
4508
+ else if (*ptr == (qtype ? qtype : ' ' ))
4506
4509
{
4507
- *ptr= 0 ;
4510
+ qtype= 0 ;
4511
+ if (mode != CHECK)
4512
+ *ptr= 0 ;
4508
4513
break ;
4509
4514
}
4510
4515
}
4511
- valid_arg= ptr != start;
4512
- return valid_arg ? start : NullS;
4516
+ return ptr != start && !qtype ? start : NullS;
4513
4517
}
4514
4518
4515
4519
0 commit comments