diff options
author | unknown <msvensson@pilot.blaudden> | 2007-02-16 15:23:06 +0100 |
---|---|---|
committer | unknown <msvensson@pilot.blaudden> | 2007-02-16 15:23:06 +0100 |
commit | c6e1de4c5636c55367fddeed07bb3dd74bfbbea8 (patch) | |
tree | 3ae64853f920570211f122c5292236c5bf8322f3 /client | |
parent | 4ff5ff2c0ba91941f0fb313bc48962d1ea2cb143 (diff) | |
parent | a843a05f92b962477ee338f26696e253ed23607f (diff) | |
download | mariadb-git-c6e1de4c5636c55367fddeed07bb3dd74bfbbea8.tar.gz |
Merge 192.168.0.10:mysql/mysql-4.1-maint
into pilot.blaudden:/home/msvensson/mysql/mysql-4.1-maint
client/mysqltest.c:
Auto merged
Diffstat (limited to 'client')
-rw-r--r-- | client/echo.c | 45 | ||||
-rw-r--r-- | client/mysqltest.c | 93 |
2 files changed, 129 insertions, 9 deletions
diff --git a/client/echo.c b/client/echo.c new file mode 100644 index 00000000000..4483eaad293 --- /dev/null +++ b/client/echo.c @@ -0,0 +1,45 @@ +/* Copyright (C) 2000 MySQL AB + + This program 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; either version 2 of the License, or + (at your option) any later version. + + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* + echo is a replacement for the "echo" command builtin to cmd.exe + on Windows, to get a Unix eqvivalent behaviour when running commands + like: + $> echo "hello" | mysql + + The windows "echo" would have sent "hello" to mysql while + Unix echo will send hello without the enclosing hyphens + + This is a very advanced high tech program so take care when + you change it and remember to valgrind it before production + use. + +*/ + +#include <stdio.h> + +int main(int argc, char **argv) +{ + int i; + for (i= 1; i < argc; i++) + { + fprintf(stdout, "%s", argv[i]); + if (i < argc - 1) + fprintf(stdout, " "); + } + fprintf(stdout, "\n"); + return 0; +} diff --git a/client/mysqltest.c b/client/mysqltest.c index 99462d82f40..c7504aee9ef 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -407,6 +407,8 @@ TYPELIB command_typelib= {array_elements(command_names),"", DYNAMIC_STRING ds_res, ds_progress, ds_warning_messages; +char builtin_echo[FN_REFLEN]; + void die(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2); void abort_not_supported_test(const char *fmt, ...) @@ -916,10 +918,10 @@ void warning_msg(const char *fmt, ...) dynstr_append_mem(&ds_warning_messages, buff, len); } -#ifndef __WIN__ - len= vsnprintf(buff, sizeof(buff), fmt, args); + + len= my_vsnprintf(buff, sizeof(buff), fmt, args); dynstr_append_mem(&ds_warning_messages, buff, len); -#endif + dynstr_append(&ds_warning_messages, "\n"); va_end(args); @@ -1519,29 +1521,36 @@ void do_source(struct st_command *command) } -#ifdef __WIN__ +#if defined __WIN__ + +#ifdef USE_CYGWIN /* Variables used for temporary sh files used for emulating Unix on Windows */ char tmp_sh_name[64], tmp_sh_cmd[70]; +#endif void init_tmp_sh_file() { +#ifdef USE_CYGWIN /* Format a name for the tmp sh file that is unique for this process */ my_snprintf(tmp_sh_name, sizeof(tmp_sh_name), "tmp_%d.sh", getpid()); /* Format the command to execute in order to run the script */ my_snprintf(tmp_sh_cmd, sizeof(tmp_sh_cmd), "sh %s", tmp_sh_name); +#endif } void free_tmp_sh_file() { +#ifdef USE_CYGWIN my_delete(tmp_sh_name, MYF(0)); +#endif } #endif FILE* my_popen(DYNAMIC_STRING *ds_cmd, const char *mode) { -#ifdef __WIN__ +#if defined __WIN__ && defined USE_CYGWIN /* Dump the command into a sh script file and execute with popen */ str_to_file(tmp_sh_name, ds_cmd->str, ds_cmd->length); return popen(tmp_sh_cmd, mode); @@ -1551,6 +1560,64 @@ FILE* my_popen(DYNAMIC_STRING *ds_cmd, const char *mode) } +static void init_builtin_echo(void) +{ +#ifdef __WIN__ + + /* Look for "echo.exe" in same dir as mysqltest was started from */ + dirname_part(builtin_echo, my_progname); + fn_format(builtin_echo, ".\\echo.exe", + builtin_echo, "", MYF(MY_REPLACE_DIR)); + + /* Make sure echo.exe exists */ + if (access(builtin_echo, F_OK) != 0) + builtin_echo[0]= 0; + return; + +#else + + builtin_echo[0]= 0; + return; + +#endif +} + + +/* + Replace a substring + + SYNOPSIS + replace + ds_str The string to search and perform the replace in + search_str The string to search for + search_len Length of the string to search for + replace_str The string to replace with + replace_len Length of the string to replace with + + RETURN + 0 String replaced + 1 Could not find search_str in str +*/ + +static int replace(DYNAMIC_STRING *ds_str, + const char *search_str, ulong search_len, + const char *replace_str, ulong replace_len) +{ + DYNAMIC_STRING ds_tmp; + const char *start= strstr(ds_str->str, search_str); + if (!start) + return 1; + init_dynamic_string(&ds_tmp, "", + ds_str->length + replace_len, 256); + dynstr_append_mem(&ds_tmp, ds_str->str, start - ds_str->str); + dynstr_append_mem(&ds_tmp, replace_str, replace_len); + dynstr_append(&ds_tmp, start + search_len); + dynstr_set(ds_str, ds_tmp.str); + dynstr_free(&ds_tmp); + return 0; +} + + /* Execute given command. @@ -1569,13 +1636,13 @@ FILE* my_popen(DYNAMIC_STRING *ds_cmd, const char *mode) NOTE Although mysqltest is executed from cygwin shell, the command will be executed in "cmd.exe". Thus commands like "rm" etc can NOT be used, use - system for those commands. + mysqltest commmand(s) like "remove_file" for that */ void do_exec(struct st_command *command) { int error; - char buf[1024]; + char buf[512]; FILE *res_file; char *cmd= command->first_argument; DYNAMIC_STRING ds_cmd; @@ -1593,8 +1660,15 @@ void do_exec(struct st_command *command) /* Eval the command, thus replacing all environment variables */ do_eval(&ds_cmd, cmd, command->end, TRUE); + /* Check if echo should be replaced with "builtin" echo */ + if (builtin_echo[0] && strncmp(cmd, "echo", 4) == 0) + { + /* Replace echo with our "builtin" echo */ + replace(&ds_cmd, "echo", 4, builtin_echo, strlen(builtin_echo)); + } + DBUG_PRINT("info", ("Executing '%s' as '%s'", - command->first_argument, cmd)); + command->first_argument, ds_cmd.str)); if (!(res_file= my_popen(&ds_cmd, "r")) && command->abort_on_error) die("popen(\"%s\", \"r\") failed", command->first_argument); @@ -1718,7 +1792,7 @@ int do_modify_var(struct st_command *command, int my_system(DYNAMIC_STRING* ds_cmd) { -#ifdef __WIN__ +#if defined __WIN__ && defined USE_CYGWIN /* Dump the command into a sh script file and execute with system */ str_to_file(tmp_sh_name, ds_cmd->str, ds_cmd->length); return system(tmp_sh_cmd); @@ -5641,6 +5715,7 @@ int main(int argc, char **argv) parser.current_line= parser.read_lines= 0; memset(&var_reg, 0, sizeof(var_reg)); + init_builtin_echo(); #ifdef __WIN__ init_tmp_sh_file(); init_win_path_patterns(); |