From: Date: September 6 2005 5:04pm Subject: bk commit into 4.1 tree (SergeyV:1.2419) BUG#12929 List-Archive: http://lists.mysql.com/internals/29374 X-Bug: 12929 Message-Id: <200509061504.j86F4Epg001103@selena.creware.com> Below is the list of changes that have just been committed into a local 4.1 repository of sergeyv. When sergeyv does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.2419 05/09/06 19:03:59 SergeyV@selena. +6 -0 Fixes bug #12929. Uses my_cgets instead of _cgets function, thus eliminating a restriction to 255 chars for editable buffer. mysys/my_conio.c 1.1 05/09/06 19:03:52 SergeyV@selena. +134 -0 Added _cgets() replacement that is not limited to 255 chars retrieval from win32 console. mysys/my_conio.c 1.0 05/09/06 19:03:52 SergeyV@selena. +0 -0 BitKeeper file H:/MYSQL/src/#12929-mysql-4.1/mysys/my_conio.c mysys/Makefile.am 1.58 05/09/06 19:03:51 SergeyV@selena. +2 -1 Added my_conio.c include/my_sys.h 1.142 05/09/06 19:03:51 SergeyV@selena. +6 -0 Added declarations for my_conio.c functions client/mysql.cc 1.211 05/09/06 19:03:50 SergeyV@selena. +41 -4 Fixes bug #12929. Uses my_cgets instead of _cgets function, thus eliminating a restriction to 255 chars for editable buffer. VC++Files/mysys/mysys_ia64.dsp 1.3 05/09/06 19:03:49 SergeyV@selena. +4 -0 Added my_conio.c VC++Files/mysys/mysys.dsp 1.26 05/09/06 19:03:48 SergeyV@selena. +4 -0 Added my_conio.c # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: SergeyV # Host: selena. # Root: H:/MYSQL/src/#12929-mysql-4.1 --- 1.210/client/mysql.cc 2005-08-25 13:08:20 +04:00 +++ 1.211/client/mysql.cc 2005-09-06 19:03:50 +04:00 @@ -345,6 +345,10 @@ DBUG_ENTER("main"); DBUG_PROCESS(argv[0]); +#if defined(__WIN__) + my_initconio(); +#endif + delimiter_str= delimiter; default_prompt = my_strdup(getenv("MYSQL_PS1") ? getenv("MYSQL_PS1") : @@ -498,6 +502,11 @@ mysql_server_end(); free_defaults(defaults_argv); my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); + +#if defined(__WIN__) + my_freeconio(); +#endif + exit(status.exit_status); } @@ -938,10 +947,15 @@ static int read_lines(bool execute_commands) { -#if defined( __WIN__) || defined(OS2) || defined(__NETWARE__) +#if defined(OS2) || defined(__NETWARE__) char linebuffer[254]; String buffer; #endif +#if defined(__WIN__) + String tmpbuf; + String buffer; +#endif + char *line; char in_string=0; ulong line_number=0; @@ -972,7 +986,7 @@ #if defined( __WIN__) || defined(OS2) || defined(__NETWARE__) tee_fputs(prompt, stdout); -#ifdef __NETWARE__ +#if defined(__NETWARE__) line=fgets(linebuffer, sizeof(linebuffer)-1, stdin); /* Remove the '\n' */ if (line) @@ -981,7 +995,26 @@ if (p != NULL) *p = '\0'; } -#else +#elif defined(__WIN__) + /* + allocate as much as ReadConsole might accept. + real input buffer will be less than allocated. + */ + if (!tmpbuf.is_alloced()) + tmpbuf.alloc(65535); + buffer.length(0); + unsigned long clen; + do + { + line= my_cgets(tmpbuf.c_ptr(), tmpbuf.alloced_length(), &clen); + buffer.append(line, clen); + /* + if we got our buffer fully filled, then there is a chance that + something else is still in console input buffer + */ + } while (tmpbuf.alloced_length() <= clen + 1); + line= buffer.c_ptr(); +#else /* OS2 */ buffer.length(0); /* _cgets() expects the buffer size - 3 as the first byte */ linebuffer[0]= (char) sizeof(linebuffer) - 3; @@ -1057,7 +1090,11 @@ status.exit_status=0; } } -#if defined( __WIN__) || defined(OS2) || defined(__NETWARE__) +#if defined(OS2) || defined(__NETWARE__) + buffer.free(); +#endif +#if defined( __WIN__) + tmpbuf.free(); buffer.free(); #endif return status.exit_status; --- 1.141/include/my_sys.h 2005-08-19 22:49:29 +04:00 +++ 1.142/include/my_sys.h 2005-09-06 19:03:51 +04:00 @@ -804,6 +804,12 @@ void my_security_attr_free(SECURITY_ATTRIBUTES *sa); +/* implemented in my_conio.c */ + +char* my_cgets(char *string, unsigned long clen, unsigned long* plen); +void my_initconio(void); +void my_freeconio(void); + #endif #ifdef __NETWARE__ void netware_reg_user(const char *ip, const char *user, --- 1.57/mysys/Makefile.am 2005-07-03 05:29:04 +04:00 +++ 1.58/mysys/Makefile.am 2005-09-06 19:03:51 +04:00 @@ -54,7 +54,8 @@ my_net.c my_semaphore.c my_port.c my_sleep.c \ charset.c charset-def.c my_bitmap.c my_bit.c md5.c \ my_gethostbyname.c rijndael.c my_aes.c sha1.c \ - my_handler.c my_netware.c my_windac.c my_access.c + my_handler.c my_netware.c my_windac.c my_access.c \ + my_conio.c EXTRA_DIST = thr_alarm.c thr_lock.c my_pthread.c my_thr_init.c \ thr_mutex.c thr_rwlock.c libmysys_a_LIBADD = @THREAD_LOBJECTS@ --- New file --- +++ mysys/my_conio.c 05/09/06 19:03:52 /* 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 */ #include "mysys_priv.h" #ifdef __WIN__ static int my_coninpfh= 0; /* console input */ static pthread_mutex_t conio_lock; void my_initconio(void) { pthread_mutex_init(&conio_lock, 0); my_coninpfh= (int)CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); } void my_freeconio(void) { pthread_mutex_destroy(&conio_lock); if ((my_coninpfh) && (my_coninpfh != -1)) CloseHandle((HANDLE)my_coninpfh); } /* char* my_cgets(char *string, unsigned long clen, unsigned long* plen) NOTES Replaces _cgets from libc to support input of more than 255 chars. Reads from the console via ReadConsole into buffer which should be at least clen characters. Actual length of string returned in plen. WARNING my_cgets() does NOT check the pushback character buffer (i.e., _chbuf). Thus, my_cgets() will not return any character that is pushed back by the _ungetch() call. RETURN string pointer ok NULL Error */ char* my_cgets(char *buffer, unsigned long clen, unsigned long* plen) { ULONG state; char *result; CONSOLE_SCREEN_BUFFER_INFO csbi; pthread_mutex_lock(&conio_lock); /* lock the console */ if (my_coninpfh == -1) { pthread_mutex_unlock(&conio_lock); /* unlock the console */ return(NULL); /* return failure */ } GetConsoleMode((HANDLE)my_coninpfh, &state); SetConsoleMode((HANDLE)my_coninpfh, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT); GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); /* there is no known way to determine allowed buffer size for input though it is known it should not be more than 64K so we cut 64K and try first size of screen buffer if it is still to large we cut half of it and try again later we may want to cycle from min(clen, 65535) to allowed size with small decrement to determine exact allowed buffer */ clen= min(clen, 65535); do { clen= min(clen, csbi.dwSize.X*csbi.dwSize.Y); if (!ReadConsole((HANDLE)my_coninpfh, (LPVOID)buffer, clen - 1, plen, NULL)) { result= NULL; clen>>= 1; } else { result= buffer; break; } } while (GetLastError() == ERROR_NOT_ENOUGH_MEMORY); if (result != NULL) { if (buffer[*plen - 2] == '\r') { *plen= *plen - 2; } else { if (buffer[*plen - 1] == '\r') { char tmp[3]; int tmplen= sizeof(tmp); *plen= *plen - 1; /* read /n left in the buffer */ ReadConsole((HANDLE)my_coninpfh, (LPVOID)tmp, tmplen, &tmplen, NULL); } } buffer[*plen]= '\0'; } SetConsoleMode((HANDLE)my_coninpfh, state); pthread_mutex_unlock(&conio_lock); /* unlock the console */ return result; } #endif /* __WIN__ */ --- 1.2/VC++Files/mysys/mysys_ia64.dsp 2005-05-21 01:03:54 +04:00 +++ 1.3/VC++Files/mysys/mysys_ia64.dsp 2005-09-06 19:03:49 +04:00 @@ -362,6 +362,10 @@ # End Source File # Begin Source File +SOURCE=.\my_conio.c +# End Source File +# Begin Source File + SOURCE=.\my_copy.c # End Source File # Begin Source File --- 1.25/VC++Files/mysys/mysys.dsp 2005-05-21 01:03:54 +04:00 +++ 1.26/VC++Files/mysys/mysys.dsp 2005-09-06 19:03:48 +04:00 @@ -361,6 +361,10 @@ # End Source File # Begin Source File +SOURCE=.\my_conio.c +# End Source File +# Begin Source File + SOURCE=.\my_copy.c # End Source File # Begin Source File