42
42
#include <algorithm>
43
43
#include <limits.h>
45
#include "drizzled/charset_info.h"
46
45
#include <stdarg.h>
48
47
#include "client/linebuffer.h"
49
48
#include <signal.h>
50
49
#include <sys/ioctl.h>
51
50
#include <drizzled/configmake.h>
51
#include "drizzled/internal/utf8.h"
52
52
#include "drizzled/charset.h"
54
54
#if defined(HAVE_CURSES_H) && defined(HAVE_TERM_H)
318
318
static uint32_t delimiter_length= 1;
319
319
unsigned short terminal_width= 80;
321
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
323
321
int drizzleclient_real_query_for_lazy(const char *buf, int length,
324
322
drizzle_result_st *result,
325
323
uint32_t *error_code);
1726
1723
if(vm.count("version"))
1728
printf(_("%s Ver %s Distrib %s, for %s-%s (%s) using readline %s\n"),
1729
internal::my_progname, VER.c_str(), drizzle_version(),
1730
HOST_VENDOR, HOST_OS, HOST_CPU,
1731
rl_library_version);
1725
printf(_("drizzle Ver %s Distrib %s, for %s-%s (%s) using readline %s\n"),
1726
VER.c_str(), drizzle_version(),
1727
HOST_VENDOR, HOST_OS, HOST_CPU,
1728
rl_library_version);
1736
1733
if(vm.count("help"))
1738
printf(_("%s Ver %s Distrib %s, for %s-%s (%s) using readline %s\n"),
1739
internal::my_progname, VER.c_str(), drizzle_version(),
1740
HOST_VENDOR, HOST_OS, HOST_CPU,
1741
rl_library_version);
1735
printf(_("drizzle Ver %s Distrib %s, for %s-%s (%s) using readline %s\n"),
1736
VER.c_str(), drizzle_version(),
1737
HOST_VENDOR, HOST_OS, HOST_CPU,
1738
rl_library_version);
1742
1739
printf(_("Copyright (C) 2008 Sun Microsystems\n"
1743
1740
"This software comes with ABSOLUTELY NO WARRANTY. "
1744
1741
"This is free software,\n"
1745
1742
"and you are welcome to modify and redistribute it "
1746
1743
"under the GPL license\n"));
1747
printf(_("Usage: %s [OPTIONS] [database]\n"), internal::my_progname);
1744
printf(_("Usage: drizzle [OPTIONS] [database]\n"));
1748
1745
cout<<long_options;
1880
1877
tee_fprintf(stdout, _("Writing history-file %s\n"),histfile);
1881
1878
if (!write_history(histfile_tmp))
1882
internal::my_rename(histfile_tmp, histfile, MYF(MY_WME));
1879
rename(histfile_tmp, histfile);
1884
1881
delete status.getLineBuff();
1885
1882
status.setLineBuff(0);
2112
2109
if (strstr(name, "\\g") || (strstr(name, delimiter) &&
2113
2110
!(strlen(name) >= 9 &&
2114
!my_strnncoll(charset_info,
2115
(unsigned char*) name, 9,
2116
(const unsigned char*) "delimiter",
2111
!strcmp(name, "delimiter"))))
2119
2113
if ((end=strcont(name," \t")))
2121
2115
len=(uint32_t) (end - name);
2122
while (my_isspace(charset_info,*end))
2116
while (isspace(*end))
2125
2119
end=0; // no arguments to function
2131
2125
for (uint32_t i= 0; commands[i].getName(); i++)
2133
2127
if (commands[i].func &&
2134
((name && !my_strnncoll(charset_info,(const unsigned char*)name,len, (const unsigned char*)commands[i].getName(),len) && !commands[i].getName()[len] && (!end || (end && commands[i].getTakesParams()))) || (!name && commands[i].getCmdChar() == cmd_char)))
2128
((name && !strncmp(name, commands[i].getName(), len)
2129
&& !commands[i].getName()[len] && (!end || (end && commands[i].getTakesParams()))) || (!name && commands[i].getCmdChar() == cmd_char)))
2136
2131
return(&commands[i]);
2161
2156
if (!preserve_comments)
2163
2158
// Skip spaces at the beggining of a statement
2164
if (my_isspace(charset_info,inchar) && (out == line) &&
2159
if (isspace(inchar) && (out == line) &&
2165
2160
(buffer->empty()))
2169
2164
// Accept multi-byte characters as-is
2171
if (use_mb(charset_info) &&
2172
(length= my_ismbchar(charset_info, pos, end_of_line)))
2166
if ((length= U8_LENGTH(*pos)))
2174
2168
if (!*ml_comment || preserve_comments)
2249
2243
else if (!*ml_comment && !*in_string &&
2250
2244
(end_of_line - pos) >= 10 &&
2251
!my_strnncoll(charset_info, (unsigned char*) pos, 10,
2252
(const unsigned char*) "delimiter ", 10))
2245
!strncmp(pos, "delimiter ", 10))
2254
2247
// Flush previously accepted characters
2255
2248
if (out != line)
2392
2385
*in_string= (char) inchar;
2393
2386
if (!*ml_comment || preserve_comments)
2395
if (need_space && !my_isspace(charset_info, (char)inchar))
2388
if (need_space && !isspace((char)inchar))
2398
2391
*out++= (char) inchar;
3144
3137
drizzle_column_db(field), drizzle_column_table(field),
3145
3138
drizzle_column_orig_table(field),
3146
3139
fieldtype2str(drizzle_column_type(field)),
3147
get_charset_name(drizzle_column_charset(field)),
3148
3140
drizzle_column_charset(field), drizzle_column_size(field),
3149
3141
drizzle_column_max_size(field), drizzle_column_decimals(field),
3150
3142
fieldflags2str(drizzle_column_flags(field)));
3184
3176
/* Check if the max_byte value is really the maximum in terms
3185
3177
of visual length since multibyte characters can affect the
3186
3178
length of the separator. */
3187
length= charset_info->cset->numcells(charset_info,
3188
drizzle_column_name(field),
3189
drizzle_column_name(field) +
3179
length= U8_LENGTH(*(drizzle_column_name(field)));
3192
3181
if (name_length == drizzle_column_max_size(field))
3225
3214
for (uint32_t off=0; (field = drizzle_column_next(result)) ; off++)
3227
3216
uint32_t name_length= (uint32_t) strlen(drizzle_column_name(field));
3228
uint32_t numcells= charset_info->cset->numcells(charset_info,
3229
drizzle_column_name(field),
3230
drizzle_column_name(field) +
3217
uint32_t numcells= U8_LENGTH(*drizzle_column_name(field));
3232
3218
uint32_t display_length= drizzle_column_max_size(field) + name_length -
3234
3220
tee_fprintf(PAGER, " %-*s |",(int) min(display_length,
3291
3277
We need to find how much screen real-estate we will occupy to know how
3292
3278
many extra padding-characters we should send with the printing function.
3294
visible_length= charset_info->cset->numcells(charset_info, buffer, buffer + data_length);
3280
visible_length= U8_LENGTH(*buffer);
3295
3281
extra_padding= data_length - visible_length;
3297
3283
if (field_max_length > MAX_COLUMN_LENGTH)
3519
3505
else for (const char *end=pos+length ; pos != end ; pos++)
3522
if (use_mb(charset_info) &&
3523
(l = my_ismbchar(charset_info, pos, end)))
3508
if ((l = U8_LENGTH(*pos)))
3526
3511
tee_putc(*pos++, PAGER);
3620
3605
/* eliminate the spaces before the parameters */
3621
while (my_isspace(charset_info,*param))
3606
while (isspace(*param))
3623
3608
strncpy(file_name, param, sizeof(file_name) - 1);
3624
3609
end= file_name + strlen(file_name);
3625
3610
/* remove end space from command line */
3626
while (end > file_name && (my_isspace(charset_info,end[-1]) ||
3627
my_iscntrl(charset_info,end[-1])))
3611
while (end > file_name && (isspace(end[-1]) ||
3630
3615
if (end == file_name)
3659
3644
if (status.getBatch())
3661
3646
/* Skip spaces in front of the pager command */
3662
while (my_isspace(charset_info, *line))
3647
while (isspace(*line))
3664
3649
/* Skip the pager command */
3665
3650
param= strchr(line, ' ');
3666
3651
/* Skip the spaces between the command and the argument */
3667
while (param && my_isspace(charset_info, *param))
3652
while (param && isspace(*param))
3669
3654
if (!param || !strlen(param)) // if pager was not given, use the default
3683
3668
end= strncpy(pager_name, param, sizeof(pager_name)-1);
3684
3669
end+= strlen(pager_name);
3685
while (end > pager_name && (my_isspace(charset_info,end[-1]) ||
3686
my_iscntrl(charset_info,end[-1])))
3670
while (end > pager_name && (isspace(end[-1]) ||
3689
3674
strcpy(pager, pager_name);
3804
3789
FILE *sql_file;
3806
3791
/* Skip space from file name */
3807
while (my_isspace(charset_info,*line))
3792
while (isspace(*line))
3809
3794
if (!(param = strchr(line, ' '))) // Skip command name
3810
3795
return put_info("Usage: \\. <filename> | source <filename>",
3811
3796
INFO_ERROR, 0,0);
3812
while (my_isspace(charset_info,*param))
3797
while (isspace(*param))
3814
3799
end= strncpy(source_name,param,sizeof(source_name)-1);
3815
3800
end+= strlen(source_name);
3816
while (end > source_name && (my_isspace(charset_info,end[-1]) ||
3817
my_iscntrl(charset_info,end[-1])))
3801
while (end > source_name && (isspace(end[-1]) ||
3820
internal::unpack_filename(source_name,source_name);
3821
3806
/* open file name */
3822
3807
if (!(sql_file = fopen(source_name, "r")))
4015
4000
/* skip leading white spaces */
4016
while (my_isspace(charset_info, *ptr))
4001
while (isspace(*ptr))
4018
4003
if (*ptr == '\\') // short command was used
4021
while (*ptr &&!my_isspace(charset_info, *ptr)) // skip command
4006
while (*ptr &&!isspace(*ptr)) // skip command
4026
while (my_isspace(charset_info, *ptr))
4011
while (isspace(*ptr))
4028
4013
if (*ptr == '\'' || *ptr == '\"' || *ptr == '`')
4118
4103
drizzle_return_t ret;
4120
4105
tee_puts("--------------", stdout);
4121
printf(_("%s Ver %s Distrib %s, for %s-%s (%s) using readline %s\n"),
4122
internal::my_progname, VER.c_str(), drizzle_version(),
4106
printf(_("drizzle Ver %s Distrib %s, for %s-%s (%s) using readline %s\n"),
4107
VER.c_str(), drizzle_version(),
4123
4108
HOST_VENDOR, HOST_OS, HOST_CPU,
4124
4109
rl_library_version); /* Print version */
4331
4316
const char *start= buffer->c_str();
4332
4317
const char *end= start + (buffer->length());
4333
while (start < end && !my_isgraph(charset_info,end[-1]))
4318
while (start < end && !isgraph(end[-1]))
4335
4320
uint32_t pos_to_truncate= (end-start);
4336
4321
if (buffer->length() > pos_to_truncate)