1275
1258
DBUG_ENTER("run_tool");
1276
1259
DBUG_PRINT("enter", ("tool_path: %s", tool_path));
1278
if (init_dynamic_string(&ds_cmdline, IF_WIN("\"", ""), FN_REFLEN, FN_REFLEN))
1261
if (init_dynamic_string(&ds_cmdline, "", FN_REFLEN, FN_REFLEN))
1279
1262
die("Out of memory");
1281
1264
dynstr_append_os_quoted(&ds_cmdline, tool_path, NullS);
2268
/* Variables used for temporary sh files used for emulating Unix on Windows */
2269
char tmp_sh_name[64], tmp_sh_cmd[70];
2272
void init_tmp_sh_file()
2275
/* Format a name for the tmp sh file that is unique for this process */
2276
my_snprintf(tmp_sh_name, sizeof(tmp_sh_name), "tmp_%d.sh", getpid());
2277
/* Format the command to execute in order to run the script */
2278
my_snprintf(tmp_sh_cmd, sizeof(tmp_sh_cmd), "sh %s", tmp_sh_name);
2283
void free_tmp_sh_file()
2286
my_delete(tmp_sh_name, MYF(0));
2292
2241
FILE* my_popen(DYNAMIC_STRING *ds_cmd, const char *mode)
2294
#if defined __WIN__ && defined USE_CYGWIN
2295
/* Dump the command into a sh script file and execute with popen */
2296
str_to_file(tmp_sh_name, ds_cmd->str, ds_cmd->length);
2297
return popen(tmp_sh_cmd, mode);
2299
2243
return popen(ds_cmd->str, mode);
2304
2247
static void init_builtin_echo(void)
2309
/* Look for "echo.exe" in same dir as mysqltest was started from */
2310
dirname_part(builtin_echo, my_progname, &echo_length);
2311
fn_format(builtin_echo, ".\\echo.exe",
2312
builtin_echo, "", MYF(MY_REPLACE_DIR));
2314
/* Make sure echo.exe exists */
2315
if (access(builtin_echo, F_OK) != 0)
2321
2249
builtin_echo[0]= 0;
2409
2335
replace(&ds_cmd, "echo", 4, builtin_echo, strlen(builtin_echo));
2414
/* Replace /dev/null with NUL */
2415
while(replace(&ds_cmd, "/dev/null", 9, "NUL", 3) == 0)
2417
/* Replace "closed stdout" with non existing output fd */
2418
while(replace(&ds_cmd, ">&-", 3, ">&4", 3) == 0)
2423
2338
DBUG_PRINT("info", ("Executing '%s' as '%s'",
2424
2339
command->first_argument, ds_cmd.str));
2589
2498
/* Eval the system command, thus replacing all environment variables */
2590
2499
do_eval(&ds_cmd, command->first_argument, command->end, !is_windows);
2594
/* Replace /dev/null with NUL */
2595
while(replace(&ds_cmd, "/dev/null", 9, "NUL", 3) == 0)
2601
2501
DBUG_PRINT("info", ("running system command '%s' as '%s'",
2602
2502
command->first_argument, ds_cmd.str));
2603
2503
if (my_system(&ds_cmd))
5410
DYNAMIC_ARRAY patterns;
5413
init_win_path_patterns
5416
Setup string patterns that will be used to detect filenames that
5417
needs to be converted from Win to Unix format
5421
void init_win_path_patterns()
5423
/* List of string patterns to match in order to find paths */
5424
const char* paths[] = { "$MYSQL_TEST_DIR",
5426
"$MYSQLTEST_VARDIR",
5428
int num_paths= sizeof(paths)/sizeof(char*);
5432
DBUG_ENTER("init_win_path_patterns");
5434
my_init_dynamic_array(&patterns, sizeof(const char*), 16, 16);
5436
/* Loop through all paths in the array */
5437
for (i= 0; i < num_paths; i++)
5440
if (*(paths[i]) == '$')
5442
v= var_get(paths[i], 0, 0, 0);
5443
p= my_strdup(v->str_val, MYF(MY_FAE));
5446
p= my_strdup(paths[i], MYF(MY_FAE));
5448
/* Don't insert zero length strings in patterns array */
5455
if (insert_dynamic(&patterns, (uchar*) &p))
5458
DBUG_PRINT("info", ("p: %s", p));
5469
void free_win_path_patterns()
5472
for (i=0 ; i < patterns.elements ; i++)
5474
const char** pattern= dynamic_element(&patterns, i, const char**);
5475
my_free((char*) *pattern, MYF(0));
5477
delete_dynamic(&patterns);
5484
Search the string 'val' for the patterns that are known to be
5485
strings that contain filenames. Convert all \ to / in the
5486
filenames that are found.
5489
val = 'Error "c:\mysql\mysql-test\var\test\t1.frm" didn't exist'
5490
=> $MYSQL_TEST_DIR is found by strstr
5491
=> all \ from c:\mysql\m... until next space is converted into /
5494
void fix_win_paths(const char *val, int len)
5499
DBUG_ENTER("fix_win_paths");
5500
for (i= 0; i < patterns.elements; i++)
5502
const char** pattern= dynamic_element(&patterns, i, const char**);
5503
DBUG_PRINT("info", ("pattern: %s", *pattern));
5505
/* Search for the path in string */
5506
while ((p= strstr(val, *pattern)))
5508
DBUG_PRINT("info", ("Found %s in val p: %s", *pattern, p));
5510
while (*p && !my_isspace(charset_info, *p))
5516
DBUG_PRINT("info", ("Converted \\ to /, p: %s", p));
5519
DBUG_PRINT("exit", (" val: %s, len: %d", val, len));
5527
5308
Append the result for one field to the dynamic string ds
5544
else if ((field->type == MYSQL_TYPE_DOUBLE ||
5545
field->type == MYSQL_TYPE_FLOAT ) &&
5546
field->decimals >= 31)
5548
/* Convert 1.2e+018 to 1.2e+18 and 1.2e-018 to 1.2e-18 */
5549
char *start= strchr(val, 'e');
5550
if (start && strlen(start) >= 5 &&
5551
(start[1] == '-' || start[1] == '+') && start[2] == '0')
5553
start+=2; /* Now points at first '0' */
5554
/* Move all chars after the first '0' one step left */
5555
memmove(start, start + 1, strlen(start));
5561
5325
if (!display_result_vertically)
6816
6580
memset(&var_reg, 0, sizeof(var_reg));
6818
6582
init_builtin_echo();
6824
init_win_path_patterns();
6827
6584
init_dynamic_string(&ds_res, "", 65536, 65536);
6828
6585
init_dynamic_string(&ds_progress, "", 0, 2048);