~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

  • Committer: Brian Aker
  • Date: 2010-09-22 22:25:29 UTC
  • mto: (1791.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 1792.
  • Revision ID: brian@tangent.org-20100922222529-geo4wggmu5ntqa5k
Current boost work (more conversion).

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
#include "client/get_password.h"
41
41
 
42
 
#include "boost/date_time/posix_time/posix_time.hpp"
 
42
#if TIME_WITH_SYS_TIME
 
43
# include <sys/time.h>
 
44
# include <time.h>
 
45
#else
 
46
# if HAVE_SYS_TIME_H
 
47
#  include <sys/time.h>
 
48
# else
 
49
#  include <time.h>
 
50
# endif
 
51
#endif
43
52
 
44
53
#include <cerrno>
45
54
#include <string>
52
61
#include <cassert>
53
62
#include <stdarg.h>
54
63
#include <math.h>
55
 
#include <memory>
56
64
#include "client/linebuffer.h"
57
65
#include <signal.h>
58
66
#include <sys/ioctl.h>
150
158
#define vidattr(A) {}      // Can't get this to work
151
159
#endif
152
160
#include <boost/program_options.hpp>
153
 
#include <boost/scoped_ptr.hpp>
154
 
#include "drizzled/program_options/config_file.h"
155
161
 
156
162
using namespace std;
157
163
namespace po=boost::program_options;
158
 
namespace dpo=drizzled::program_options;
159
164
 
160
165
/* Don't try to make a nice table if the data is too big */
161
166
const uint32_t MAX_COLUMN_LENGTH= 1024;
171
176
 
172
177
  Status(int in_exit_status, 
173
178
         uint32_t in_query_start_line,
174
 
         char *in_file_name,
 
179
         char *in_file_name,
175
180
         LineBuffer *in_line_buff,
176
 
         bool in_batch,
177
 
         bool in_add_to_history)
 
181
         bool in_batch,
 
182
         bool in_add_to_history)
178
183
    :
179
184
    exit_status(in_exit_status),
180
185
    query_start_line(in_query_start_line),
184
189
    add_to_history(in_add_to_history)
185
190
    {}
186
191
 
187
 
  Status() :
188
 
    exit_status(0),
189
 
    query_start_line(0),
190
 
    file_name(NULL),
191
 
    line_buff(NULL),
192
 
    batch(false),        
193
 
    add_to_history(false)
194
 
  {}
 
192
  Status()
 
193
    :
 
194
    exit_status(),
 
195
    query_start_line(),
 
196
    file_name(),
 
197
    line_buff(),
 
198
    batch(),        
 
199
    add_to_history()
 
200
    {}
195
201
  
196
202
  int getExitStatus() const
197
203
  {
281
287
  connected= false, opt_raw_data= false, unbuffered= false,
282
288
  output_tables= false, opt_rehash= true, skip_updates= false,
283
289
  safe_updates= false, one_database= false,
284
 
  opt_shutdown= false, opt_ping= false,
 
290
  opt_compress= false, opt_shutdown= false, opt_ping= false,
285
291
  vertical= false, line_numbers= true, column_names= true,
286
292
  opt_nopager= true, opt_outfile= false, named_cmds= false,
287
293
  opt_nobeep= false, opt_reconnect= true,
316
322
  current_password,
317
323
  opt_password,
318
324
  opt_protocol;
319
 
 
320
 
static const char* get_day_name(int day_of_week)
321
 
{
322
 
  switch(day_of_week)
323
 
  {
324
 
  case 0:
325
 
    return _("Sun");
326
 
  case 1:
327
 
    return _("Mon");
328
 
  case 2:
329
 
    return _("Tue");
330
 
  case 3:
331
 
    return _("Wed");
332
 
  case 4:
333
 
    return _("Thu");
334
 
  case 5:
335
 
    return _("Fri");
336
 
  case 6:
337
 
    return _("Sat");
338
 
  }
339
 
 
340
 
  return NULL;
341
 
}
342
 
 
343
 
static const char* get_month_name(int month)
344
 
{
345
 
  switch(month)
346
 
  {
347
 
  case 0:
348
 
    return _("Jan");
349
 
  case 1:
350
 
    return _("Feb");
351
 
  case 2:
352
 
    return _("Mar");
353
 
  case 3:
354
 
    return _("Apr");
355
 
  case 4:
356
 
    return _("May");
357
 
  case 5:
358
 
    return _("Jun");
359
 
  case 6:
360
 
    return _("Jul");
361
 
  case 7:
362
 
    return _("Aug");
363
 
  case 8:
364
 
    return _("Sep");
365
 
  case 9:
366
 
    return _("Oct");
367
 
  case 10:
368
 
    return _("Nov");
369
 
  case 11:
370
 
    return _("Dec");
371
 
  }
372
 
 
373
 
  return NULL;
374
 
}
375
 
 
 
325
// TODO: Need to i18n these
 
326
static const char *day_names[]= {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
 
327
static const char *month_names[]= {"Jan","Feb","Mar","Apr","May","Jun","Jul",
 
328
                                  "Aug","Sep","Oct","Nov","Dec"};
376
329
/* @TODO: Remove this */
377
330
#define FN_REFLEN 512
378
331
 
385
338
static uint32_t delimiter_length= 1;
386
339
unsigned short terminal_width= 80;
387
340
 
388
 
int drizzleclient_real_query_for_lazy(const char *buf, size_t length,
 
341
int drizzleclient_real_query_for_lazy(const char *buf, int length,
389
342
                                      drizzle_result_st *result,
390
343
                                      uint32_t *error_code);
391
344
int drizzleclient_store_result_for_lazy(drizzle_result_st *result);
404
357
  com_help(string *str,const char*), com_clear(string *str,const char*),
405
358
  com_connect(string *str,const char*), com_status(string *str,const char*),
406
359
  com_use(string *str,const char*), com_source(string *str, const char*),
407
 
  com_shutdown(string *str,const char*),
408
360
  com_rehash(string *str, const char*), com_tee(string *str, const char*),
409
361
  com_notee(string *str, const char*),
410
362
  com_prompt(string *str, const char*), com_delimiter(string *str, const char*),
412
364
  com_nopager(string *str, const char*), com_pager(string *str, const char*);
413
365
 
414
366
static int read_and_execute(bool interactive);
415
 
static int sql_connect(const string &host, const string &database, const string &user, const string &password);
 
367
static int sql_connect(const string &host, const string &database, const string &user, const string &password,
 
368
                       uint32_t silent);
416
369
static const char *server_version_string(drizzle_con_st *con);
417
370
static int put_info(const char *str,INFO_TYPE info,uint32_t error,
418
371
                    const char *sql_state);
534
487
  Commands( "tee",    'T', com_tee,    1,
535
488
    N_("Set outfile [to_outfile]. Append everything into given outfile.") ),
536
489
  Commands( "use",    'u', com_use,    1,
537
 
    N_("Use another schema. Takes schema name as argument.") ),
538
 
  Commands( "shutdown",    'u', com_shutdown,    1,
539
 
    N_("Shutdown the instance you are connected too.") ),
 
490
    N_("Use another database. Takes database name as argument.") ),
540
491
  Commands( "warnings", 'W', com_warnings,  0,
541
492
    N_("Show warnings after every statement.") ),
542
493
  Commands( "nowarning", 'w', com_nowarnings, 0,
1165
1116
static void print_tab_data(drizzle_result_st *result);
1166
1117
static void print_table_data_vertically(drizzle_result_st *result);
1167
1118
static void print_warnings(uint32_t error_code);
1168
 
static boost::posix_time::ptime start_timer(void);
1169
 
static void end_timer(boost::posix_time::ptime, string &buff);
1170
 
static void drizzle_end_timer(boost::posix_time::ptime, string &buff);
1171
 
static void nice_time(boost::posix_time::time_duration duration, string &buff);
 
1119
static uint32_t start_timer(void);
 
1120
static void end_timer(uint32_t start_time,char *buff);
 
1121
static void drizzle_end_timer(uint32_t start_time,char *buff);
 
1122
static void nice_time(double sec,char *buff,bool part_second);
1172
1123
extern "C" void drizzle_end(int sig);
1173
1124
extern "C" void handle_sigint(int sig);
1174
1125
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
1324
1275
# if defined(HAVE_LOCALE_H)
1325
1276
  setlocale(LC_ALL, "");
1326
1277
# endif
1327
 
  bindtextdomain("drizzle7", LOCALEDIR);
1328
 
  textdomain("drizzle7");
 
1278
  bindtextdomain("drizzle", LOCALEDIR);
 
1279
  textdomain("drizzle");
1329
1280
#endif
1330
1281
 
1331
 
  po::options_description commandline_options(_("Options used only in command line"));
 
1282
  po::options_description commandline_options(N_("Options used only in command line"));
1332
1283
  commandline_options.add_options()
1333
 
  ("help,?",_("Displays this help and exit."))
1334
 
  ("batch,B",_("Don't use history file. Disable interactive behavior. (Enables --silent)"))
 
1284
  ("help,?",N_("Displays this help and exit."))
 
1285
  ("batch,B",N_("Don't use history file. Disable interactive behavior. (Enables --silent)"))
1335
1286
  ("column-type-info", po::value<bool>(&column_types_flag)->default_value(false)->zero_tokens(),
1336
 
  _("Display column type information."))
 
1287
  N_("Display column type information."))
1337
1288
  ("comments,c", po::value<bool>(&preserve_comments)->default_value(false)->zero_tokens(),
1338
 
  _("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments"))
 
1289
  N_("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments"))
 
1290
  ("compress,C", po::value<bool>(&opt_compress)->default_value(false)->zero_tokens(),
 
1291
  N_("Use compression in server/client protocol."))  
1339
1292
  ("vertical,E", po::value<bool>(&vertical)->default_value(false)->zero_tokens(),
1340
 
  _("Print the output of a query (rows) vertically."))
 
1293
  N_("Print the output of a query (rows) vertically."))
1341
1294
  ("force,f", po::value<bool>(&ignore_errors)->default_value(false)->zero_tokens(),
1342
 
  _("Continue even if we get an sql error."))
 
1295
  N_("Continue even if we get an sql error."))
1343
1296
  ("named-commands,G", po::value<bool>(&named_cmds)->default_value(false)->zero_tokens(),
1344
 
  _("Enable named commands. Named commands mean this program's internal commands; see drizzle> help . When enabled, the named commands can be used from any line of the query, otherwise only from the first line, before an enter."))
 
1297
  N_("Enable named commands. Named commands mean this program's internal commands; see drizzle> help . When enabled, the named commands can be used from any line of the query, otherwise only from the first line, before an enter."))
 
1298
  ("ignore-spaces,i", N_("Ignore space after function names."))
1345
1299
  ("no-beep,b", po::value<bool>(&opt_nobeep)->default_value(false)->zero_tokens(),
1346
 
  _("Turn off beep on error."))
1347
 
  ("disable-line-numbers", _("Do not write line numbers for errors."))
1348
 
  ("disable-column-names", _("Do not write column names in results."))
 
1300
  N_("Turn off beep on error."))
 
1301
  ("disable-line-numbers", N_("Do not write line numbers for errors."))
 
1302
  ("skip-line-numbers,L", 
 
1303
  N_("Don't write line number for errors. WARNING: -L is deprecated, use long version of this option instead."))
 
1304
  ("disable-column-names", N_("Do not write column names in results."))
1349
1305
  ("skip-column-names,N", 
1350
 
  _("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."))
 
1306
  N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."))
1351
1307
  ("set-variable,O", po::value<string>(),
1352
 
  _("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."))
 
1308
  N_("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."))
1353
1309
  ("table,t", po::value<bool>(&output_tables)->default_value(false)->zero_tokens(),
1354
 
  _("Output in table format.")) 
 
1310
  N_("Output in table format.")) 
1355
1311
  ("safe-updates,U", po::value<bool>(&safe_updates)->default_value(false)->zero_tokens(),
1356
 
  _("Only allow UPDATE and DELETE that uses keys."))
 
1312
  N_("Only allow UPDATE and DELETE that uses keys."))
1357
1313
  ("i-am-a-dummy,U", po::value<bool>(&safe_updates)->default_value(false)->zero_tokens(),
1358
 
  _("Synonym for option --safe-updates, -U."))
 
1314
  N_("Synonym for option --safe-updates, -U."))
1359
1315
  ("verbose,v", po::value<string>(&opt_verbose)->default_value(""),
1360
 
  _("-v vvv implies that verbose= 3, Used to specify verbose"))
1361
 
  ("version,V", _("Output version information and exit."))
 
1316
  N_("-v vvv implies that verbose= 3, Used to specify verbose"))
 
1317
  ("version,V", N_("Output version information and exit."))
1362
1318
  ("secure-auth", po::value<bool>(&opt_secure_auth)->default_value(false)->zero_tokens(),
1363
 
  _("Refuse client connecting to server if it uses old (pre-4.1.1) protocol"))
 
1319
  N_("Refuse client connecting to server if it uses old (pre-4.1.1) protocol"))
1364
1320
  ("show-warnings", po::value<bool>(&show_warnings)->default_value(false)->zero_tokens(),
1365
 
  _("Show warnings after every statement."))
 
1321
  N_("Show warnings after every statement."))
1366
1322
  ("show-progress-size", po::value<uint32_t>(&show_progress_size)->default_value(0),
1367
 
  _("Number of lines before each import progress report."))
 
1323
  N_("Number of lines before each import progress report."))
1368
1324
  ("ping", po::value<bool>(&opt_ping)->default_value(false)->zero_tokens(),
1369
 
  _("Ping the server to check if it's alive."))
 
1325
  N_("Ping the server to check if it's alive."))
1370
1326
  ("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1371
 
  _("Configuration file defaults are not used if no-defaults is set"))
 
1327
  N_("Configuration file defaults are not used if no-defaults is set"))
1372
1328
  ;
1373
1329
 
1374
 
  po::options_description drizzle_options(_("Options specific to the drizzle client"));
 
1330
  po::options_description drizzle_options(N_("Options specific to the drizzle client"));
1375
1331
  drizzle_options.add_options()
1376
 
  ("disable-auto-rehash,A",
1377
 
  _("Disable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time."))
 
1332
  ("disable-auto-rehash",
 
1333
  N_("Disable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time."))
1378
1334
  ("auto-vertical-output", po::value<bool>(&auto_vertical_output)->default_value(false)->zero_tokens(),
1379
 
  _("Automatically switch to vertical output mode if the result is wider than the terminal width."))
 
1335
  N_("Automatically switch to vertical output mode if the result is wider than the terminal width."))
1380
1336
  ("database,D", po::value<string>(&current_db)->default_value(""),
1381
 
  _("Database to use."))
 
1337
  N_("Database to use."))
1382
1338
  ("default-character-set",po::value<string>(),
1383
 
  _("(not used)"))
 
1339
  N_("(not used)"))
1384
1340
  ("delimiter", po::value<string>(&delimiter_str)->default_value(";"),
1385
 
  _("Delimiter to be used."))
 
1341
  N_("Delimiter to be used."))
1386
1342
  ("execute,e", po::value<string>(),
1387
 
  _("Execute command and quit. (Disables --force and history file)"))
 
1343
  N_("Execute command and quit. (Disables --force and history file)"))
1388
1344
  ("local-infile", po::value<bool>(&opt_local_infile)->default_value(false)->zero_tokens(),
1389
 
  _("Enable LOAD DATA LOCAL INFILE."))
 
1345
  N_("Enable LOAD DATA LOCAL INFILE."))
1390
1346
  ("unbuffered,n", po::value<bool>(&unbuffered)->default_value(false)->zero_tokens(),
1391
 
  _("Flush buffer after each query."))
 
1347
  N_("Flush buffer after each query."))
1392
1348
  ("sigint-ignore", po::value<bool>(&opt_sigint_ignore)->default_value(false)->zero_tokens(),
1393
 
  _("Ignore SIGINT (CTRL-C)"))
 
1349
  N_("Ignore SIGINT (CTRL-C)"))
1394
1350
  ("one-database,o", po::value<bool>(&one_database)->default_value(false)->zero_tokens(),
1395
 
  _("Only update the default database. This is useful for skipping updates to other database in the update log."))
 
1351
  N_("Only update the default database. This is useful for skipping updates to other database in the update log."))
1396
1352
  ("pager", po::value<string>(),
1397
 
  _("Pager to use to display results. If you don't supply an option the default pager is taken from your ENV variable PAGER. Valid pagers are less, more, cat [> filename], etc. See interactive help (\\h) also. This option does not work in batch mode. Disable with --disable-pager. This option is disabled by default."))
 
1353
  N_("Pager to use to display results. If you don't supply an option the default pager is taken from your ENV variable PAGER. Valid pagers are less, more, cat [> filename], etc. See interactive help (\\h) also. This option does not work in batch mode. Disable with --disable-pager. This option is disabled by default."))
1398
1354
  ("disable-pager", po::value<bool>(&opt_nopager)->default_value(false)->zero_tokens(),
1399
 
  _("Disable pager and print to stdout. See interactive help (\\h) also."))
 
1355
  N_("Disable pager and print to stdout. See interactive help (\\h) also."))
1400
1356
  ("prompt", po::value<string>(&current_prompt)->default_value(""),  
1401
 
  _("Set the drizzle prompt to this value."))
 
1357
  N_("Set the drizzle prompt to this value."))
1402
1358
  ("quick,q", po::value<bool>(&quick)->default_value(false)->zero_tokens(),
1403
 
  _("Don't cache result, print it row by row. This may slow down the server if the output is suspended. Doesn't use history file."))
 
1359
  N_("Don't cache result, print it row by row. This may slow down the server if the output is suspended. Doesn't use history file."))
1404
1360
  ("raw,r", po::value<bool>(&opt_raw_data)->default_value(false)->zero_tokens(),
1405
 
  _("Write fields without conversion. Used with --batch.")) 
1406
 
  ("disable-reconnect", _("Do not reconnect if the connection is lost."))
1407
 
  ("shutdown", po::value<bool>()->zero_tokens(),
1408
 
  _("Shutdown the server"))
1409
 
  ("silent,s", _("Be more silent. Print results with a tab as separator, each row on new line."))
 
1361
  N_("Write fields without conversion. Used with --batch.")) 
 
1362
  ("disable-reconnect", N_("Do not reconnect if the connection is lost."))
 
1363
  ("shutdown", po::value<bool>(&opt_shutdown)->default_value(false)->zero_tokens(),
 
1364
  N_("Shutdown the server"))
 
1365
  ("silent,s", N_("Be more silent. Print results with a tab as separator, each row on new line."))
1410
1366
  ("tee", po::value<string>(),
1411
 
  _("Append everything into outfile. See interactive help (\\h) also. Does not work in batch mode. Disable with --disable-tee. This option is disabled by default."))
 
1367
  N_("Append everything into outfile. See interactive help (\\h) also. Does not work in batch mode. Disable with --disable-tee. This option is disabled by default."))
1412
1368
  ("disable-tee", po::value<bool>()->default_value(false)->zero_tokens(), 
1413
 
  _("Disable outfile. See interactive help (\\h) also."))
1414
 
  ("connect-timeout", po::value<uint32_t>(&opt_connect_timeout)->default_value(0)->notifier(&check_timeout_value),
1415
 
  _("Number of seconds before connection timeout."))
1416
 
  ("max-input-line", po::value<uint32_t>(&opt_max_input_line)->default_value(16*1024L*1024L)->notifier(&check_max_input_line),
1417
 
  _("Max length of input line"))
1418
 
  ("select-limit", po::value<uint32_t>(&select_limit)->default_value(1000L),
1419
 
  _("Automatic limit for SELECT when using --safe-updates"))
1420
 
  ("max-join-size", po::value<uint32_t>(&max_join_size)->default_value(1000000L),
1421
 
  _("Automatic limit for rows in a join when using --safe-updates"))
 
1369
  N_("Disable outfile. See interactive help (\\h) also."))
 
1370
  ("wait,w", N_("Wait and retry if connection is down."))
 
1371
  ("connect_timeout", po::value<uint32_t>(&opt_connect_timeout)->default_value(0)->notifier(&check_timeout_value),
 
1372
  N_("Number of seconds before connection timeout."))
 
1373
  ("max_input_line", po::value<uint32_t>(&opt_max_input_line)->default_value(16*1024L*1024L)->notifier(&check_max_input_line),
 
1374
  N_("Max length of input line"))
 
1375
  ("select_limit", po::value<uint32_t>(&select_limit)->default_value(1000L),
 
1376
  N_("Automatic limit for SELECT when using --safe-updates"))
 
1377
  ("max_join_size", po::value<uint32_t>(&max_join_size)->default_value(1000000L),
 
1378
  N_("Automatic limit for rows in a join when using --safe-updates"))
1422
1379
  ;
1423
1380
 
1424
 
  po::options_description client_options(_("Options specific to the client"));
 
1381
  po::options_description client_options(N_("Options specific to the client"));
1425
1382
  client_options.add_options()
1426
1383
  ("host,h", po::value<string>(&current_host)->default_value("localhost"),
1427
 
  _("Connect to host"))
 
1384
  N_("Connect to host"))
1428
1385
  ("password,P", po::value<string>(&current_password)->default_value(PASSWORD_SENTINEL),
1429
 
  _("Password to use when connecting to server. If password is not given it's asked from the tty."))
 
1386
  N_("Password to use when connecting to server. If password is not given it's asked from the tty."))
1430
1387
  ("port,p", po::value<uint32_t>()->default_value(0),
1431
 
  _("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, built-in default"))
1432
 
#ifdef DRIZZLE_ADMIN_TOOL
1433
 
  ("user,u", po::value<string>(&current_user)->default_value("root"),
1434
 
#else
 
1388
  N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, built-in default"))
1435
1389
  ("user,u", po::value<string>(&current_user)->default_value(""),
1436
 
#endif
1437
 
  _("User for login if not current user."))
 
1390
  N_("User for login if not current user."))
1438
1391
  ("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
1439
 
  _("The protocol of connection (mysql or drizzle)."))
 
1392
  N_("The protocol of connection (mysql or drizzle)."))
1440
1393
  ;
1441
1394
 
1442
 
  po::options_description long_options(_("Allowed Options"));
 
1395
  po::options_description long_options(N_("Allowed Options"));
1443
1396
  long_options.add(commandline_options).add(drizzle_options).add(client_options);
1444
1397
 
1445
1398
  std::string system_config_dir_drizzle(SYSCONFDIR); 
1449
1402
  system_config_dir_client.append("/drizzle/client.cnf");
1450
1403
 
1451
1404
  std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
1452
 
 
1453
 
  if (user_config_dir.compare(0, 2, "~/") == 0)
1454
 
  {
1455
 
    char *homedir;
1456
 
    homedir= getenv("HOME");
1457
 
    if (homedir != NULL)
1458
 
      user_config_dir.replace(0, 1, homedir);
1459
 
  }
1460
 
 
 
1405
  
1461
1406
  po::variables_map vm;
1462
1407
 
1463
1408
  po::positional_options_description p;
1464
1409
  p.add("database", 1);
1465
1410
 
1466
 
  // Disable allow_guessing
1467
 
  int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
1468
 
 
1469
1411
  po::store(po::command_line_parser(argc, argv).options(long_options).
1470
 
            style(style).positional(p).extra_parser(parse_password_arg).run(),
1471
 
            vm);
 
1412
            positional(p).extra_parser(parse_password_arg).run(), vm);
1472
1413
 
1473
1414
  if (! vm["no-defaults"].as<bool>())
1474
1415
  {
1479
1420
    user_config_dir_client.append("/drizzle/client.cnf");
1480
1421
 
1481
1422
    ifstream user_drizzle_ifs(user_config_dir_drizzle.c_str());
1482
 
    po::store(dpo::parse_config_file(user_drizzle_ifs, drizzle_options), vm);
 
1423
    po::store(parse_config_file(user_drizzle_ifs, drizzle_options), vm);
1483
1424
 
1484
1425
    ifstream user_client_ifs(user_config_dir_client.c_str());
1485
 
    po::store(dpo::parse_config_file(user_client_ifs, client_options), vm);
 
1426
    po::store(parse_config_file(user_client_ifs, client_options), vm);
1486
1427
 
1487
1428
    ifstream system_drizzle_ifs(system_config_dir_drizzle.c_str());
1488
 
    store(dpo::parse_config_file(system_drizzle_ifs, drizzle_options), vm);
 
1429
    store(parse_config_file(system_drizzle_ifs, drizzle_options), vm);
1489
1430
 
1490
1431
    ifstream system_client_ifs(system_config_dir_client.c_str());
1491
 
    po::store(dpo::parse_config_file(system_client_ifs, client_options), vm);
 
1432
    po::store(parse_config_file(system_client_ifs, client_options), vm);
1492
1433
  }
1493
1434
 
1494
1435
  po::notify(vm);
1495
1436
 
1496
 
#ifdef DRIZZLE_ADMIN_TOOL
1497
 
  default_prompt= strdup(getenv("DRIZZLE_PS1") ?
1498
 
                         getenv("DRIZZLE_PS1") :
1499
 
                         "drizzleadmin> ");
1500
 
#else
1501
1437
  default_prompt= strdup(getenv("DRIZZLE_PS1") ?
1502
1438
                         getenv("DRIZZLE_PS1") :
1503
1439
                         "drizzle> ");
1504
 
#endif
1505
1440
  if (default_prompt == NULL)
1506
1441
  {
1507
1442
    fprintf(stderr, _("Memory allocation error while constructing initial "
1508
1443
                      "prompt. Aborting.\n"));
1509
1444
    exit(ENOMEM);
1510
1445
  }
1511
 
 
1512
 
  if (current_prompt.empty())
1513
 
    current_prompt= strdup(default_prompt);
1514
 
 
 
1446
  current_prompt= strdup(default_prompt);
1515
1447
  if (current_prompt.empty())
1516
1448
  {
1517
1449
    fprintf(stderr, _("Memory allocation error while constructing initial "
1536
1468
  if (! isatty(0) || ! isatty(1))
1537
1469
  {
1538
1470
    status.setBatch(1); opt_silent=1;
 
1471
    ignore_errors=0;
1539
1472
  }
1540
1473
  else
1541
1474
    status.setAddToHistory(1);
1562
1495
  opt_rehash= (vm.count("disable-auto-rehash")) ? false : true;
1563
1496
  opt_reconnect= (vm.count("disable-reconnect")) ? false : true;
1564
1497
 
1565
 
  /* Don't rehash with --shutdown */
1566
 
  if (vm.count("shutdown"))
1567
 
  {
1568
 
    opt_rehash= false;
1569
 
    opt_shutdown= true;
1570
 
  }
1571
 
 
1572
1498
  if (vm.count("delimiter"))
1573
1499
  {
1574
1500
    /* Check that delimiter does not contain a backslash */
1712
1638
  }
1713
1639
  if (vm.count("silent"))
1714
1640
  {
1715
 
    opt_silent= 2;
 
1641
    opt_silent++;
1716
1642
  }
1717
1643
  
1718
1644
  if (vm.count("help") || vm.count("version"))
1728
1654
           "This is free software,\n"
1729
1655
           "and you are welcome to modify and redistribute it "
1730
1656
           "under the GPL license\n"));
1731
 
    printf(_("Usage: drizzle [OPTIONS] [schema]\n"));
 
1657
    printf(_("Usage: drizzle [OPTIONS] [database]\n"));
1732
1658
    cout << long_options;
1733
1659
    exit(0);
1734
1660
  }
1740
1666
  }
1741
1667
 
1742
1668
  memset(&drizzle, 0, sizeof(drizzle));
1743
 
  if (sql_connect(current_host, current_db, current_user, opt_password))
 
1669
  if (sql_connect(current_host, current_db, current_user, opt_password,opt_silent))
1744
1670
  {
1745
1671
    quick= 1;          // Avoid history
1746
1672
    status.setExitStatus(1);
1868
1794
 
1869
1795
  if (sig >= 0)
1870
1796
    put_info(sig ? _("Aborted") : _("Bye"), INFO_RESULT,0,0);
1871
 
  delete glob_buffer;
1872
 
  delete processed_prompt;
 
1797
  if (glob_buffer)
 
1798
    delete glob_buffer;
 
1799
  if (processed_prompt)
 
1800
    delete processed_prompt;
1873
1801
  opt_password.erase();
1874
1802
  free(histfile);
1875
1803
  free(histfile_tmp);
1893
1821
void handle_sigint(int sig)
1894
1822
{
1895
1823
  char kill_buffer[40];
1896
 
  boost::scoped_ptr<drizzle_con_st> kill_drizzle(new drizzle_con_st);
 
1824
  drizzle_con_st kill_drizzle;
1897
1825
  drizzle_result_st res;
1898
1826
  drizzle_return_t ret;
1899
1827
 
1902
1830
    goto err;
1903
1831
  }
1904
1832
 
1905
 
  if (drizzle_con_add_tcp(&drizzle, kill_drizzle.get(), current_host.c_str(),
 
1833
  if (drizzle_con_add_tcp(&drizzle, &kill_drizzle, current_host.c_str(),
1906
1834
    opt_drizzle_port, current_user.c_str(), opt_password.c_str(), NULL,
1907
1835
    use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL) == NULL)
1908
1836
  {
1913
1841
  sprintf(kill_buffer, "KILL /*!50000 QUERY */ %u",
1914
1842
          drizzle_con_thread_id(&con));
1915
1843
 
1916
 
  if (drizzle_query_str(kill_drizzle.get(), &res, kill_buffer, &ret) != NULL)
 
1844
  if (drizzle_query_str(&kill_drizzle, &res, kill_buffer, &ret) != NULL)
1917
1845
    drizzle_result_free(&res);
1918
1846
 
1919
 
  drizzle_con_free(kill_drizzle.get());
 
1847
  drizzle_con_free(&kill_drizzle);
1920
1848
  tee_fprintf(stdout, _("Query aborted by Ctrl+C\n"));
1921
1849
 
1922
1850
  interrupted_query= 1;
2387
2315
  {
2388
2316
    *out++='\n';
2389
2317
    uint32_t length=(uint32_t) (out-line);
2390
 
    if ((buffer->length() + length) > opt_max_input_line)
2391
 
    {
2392
 
      status.setExitStatus(1);
2393
 
      put_info(_("Not found a delimiter within max_input_line of input"), INFO_ERROR, 0, 0);
2394
 
      return 1;
2395
 
    }
2396
2318
    if ((!*ml_comment || preserve_comments))
2397
2319
      buffer->append(line, length);
2398
2320
  }
2582
2504
  drizzle_return_t ret;
2583
2505
  drizzle_result_st databases,tables,fields;
2584
2506
  drizzle_row_t database_row,table_row;
 
2507
  drizzle_column_st *sql_field;
2585
2508
  string tmp_str, tmp_str_lower;
2586
 
  std::string query;
2587
2509
 
2588
2510
  if (status.getBatch() || quick || current_db.empty())
2589
2511
    return;      // We don't need completion in batches
2603
2525
  /* hash Drizzle functions (to be implemented) */
2604
2526
 
2605
2527
  /* hash all database names */
2606
 
  if (drizzle_query_str(&con, &databases, "select schema_name from information_schema.schemata", &ret) != NULL)
 
2528
  if (drizzle_query_str(&con, &databases, "show databases", &ret) != NULL)
2607
2529
  {
2608
2530
    if (ret == DRIZZLE_RETURN_OK)
2609
2531
    {
2623
2545
    drizzle_result_free(&databases);
2624
2546
  }
2625
2547
 
2626
 
  query= "select table_name, column_name from information_schema.columns where table_schema='";
2627
 
  query.append(current_db);
2628
 
  query.append("' order by table_name");
2629
 
  
2630
 
  if (drizzle_query(&con, &fields, query.c_str(), query.length(),
2631
 
                    &ret) != NULL)
 
2548
  /* hash all table names */
 
2549
  if (drizzle_query_str(&con, &tables, "show tables", &ret) != NULL)
2632
2550
  {
2633
 
    if (ret == DRIZZLE_RETURN_OK &&
2634
 
        drizzle_result_buffer(&fields) == DRIZZLE_RETURN_OK)
 
2551
    if (ret != DRIZZLE_RETURN_OK)
 
2552
    {
 
2553
      drizzle_result_free(&tables);
 
2554
      return;
 
2555
    }
 
2556
 
 
2557
    if (drizzle_result_buffer(&tables) != DRIZZLE_RETURN_OK)
 
2558
      put_info(drizzle_error(&drizzle),INFO_INFO,0,0);
 
2559
    else
2635
2560
    {
2636
2561
      if (drizzle_result_row_count(&tables) > 0 && !opt_silent && write_info)
2637
2562
      {
2641
2566
                      "You can turn off this feature to get a quicker "
2642
2567
                      "startup with -A\n\n"));
2643
2568
      }
2644
 
 
2645
 
      std::string table_name;
2646
 
      while ((table_row=drizzle_row_next(&fields)))
 
2569
      while ((table_row=drizzle_row_next(&tables)))
2647
2570
      {
2648
 
        if (table_name.compare(table_row[0]) != 0)
2649
 
        {
2650
 
          tmp_str= table_row[0];
2651
 
          tmp_str_lower= lower_string(tmp_str);
2652
 
          completion_map[tmp_str_lower]= tmp_str;
2653
 
          table_name= table_row[0];
2654
 
        }
2655
2571
        tmp_str= table_row[0];
2656
 
        tmp_str.append(".");
2657
 
        tmp_str.append(table_row[1]);
2658
 
        tmp_str_lower= lower_string(tmp_str);
2659
 
        completion_map[tmp_str_lower]= tmp_str;
2660
 
 
2661
 
        tmp_str= table_row[1];
2662
 
        tmp_str_lower= lower_string(tmp_str);
2663
 
        completion_map[tmp_str_lower]= tmp_str;
2664
 
      }
2665
 
    }
2666
 
  }
2667
 
  drizzle_result_free(&fields);
 
2572
        tmp_str_lower= lower_string(tmp_str);
 
2573
        completion_map[tmp_str_lower]= tmp_str;
 
2574
      }
 
2575
    }
 
2576
  }
 
2577
  else
 
2578
    return;
 
2579
 
 
2580
  /* hash all field names, both with the table prefix and without it */
 
2581
  if (drizzle_result_row_count(&tables) == 0)
 
2582
  {
 
2583
    drizzle_result_free(&tables);
 
2584
    return;
 
2585
  }
 
2586
 
 
2587
  drizzle_row_seek(&tables, 0);
 
2588
 
 
2589
  while ((table_row=drizzle_row_next(&tables)))
 
2590
  {
 
2591
    string query;
 
2592
 
 
2593
    query.append("show fields in '");
 
2594
    query.append(table_row[0]);
 
2595
    query.append("'");
 
2596
    
 
2597
    if (drizzle_query(&con, &fields, query.c_str(), query.length(),
 
2598
                      &ret) != NULL)
 
2599
    {
 
2600
      if (ret == DRIZZLE_RETURN_OK &&
 
2601
          drizzle_result_buffer(&fields) == DRIZZLE_RETURN_OK)
 
2602
      {
 
2603
        while ((sql_field=drizzle_column_next(&fields)))
 
2604
        {
 
2605
          tmp_str=table_row[0];
 
2606
          tmp_str.append(".");
 
2607
          tmp_str.append(drizzle_column_name(sql_field));
 
2608
          tmp_str_lower= lower_string(tmp_str);
 
2609
          completion_map[tmp_str_lower]= tmp_str;
 
2610
 
 
2611
          tmp_str=drizzle_column_name(sql_field);
 
2612
          tmp_str_lower= lower_string(tmp_str);
 
2613
          completion_map[tmp_str_lower]= tmp_str;
 
2614
        }
 
2615
      }
 
2616
      drizzle_result_free(&fields);
 
2617
    }
 
2618
  }
 
2619
  drizzle_result_free(&tables);
2668
2620
  completion_iter= completion_map.begin();
2669
2621
}
2670
2622
 
2710
2662
 The different commands
2711
2663
***************************************************************************/
2712
2664
 
2713
 
int drizzleclient_real_query_for_lazy(const char *buf, size_t length,
 
2665
int drizzleclient_real_query_for_lazy(const char *buf, int length,
2714
2666
                                      drizzle_result_st *result,
2715
2667
                                      uint32_t *error_code)
2716
2668
{
2809
2761
com_go(string *buffer, const char *)
2810
2762
{
2811
2763
  char          buff[200]; /* about 110 chars used so far */
 
2764
  char          time_buff[52+3+1]; /* time max + space&parens + NUL */
2812
2765
  drizzle_result_st result;
2813
2766
  drizzle_return_t ret;
2814
 
  uint32_t      warnings= 0;
2815
 
  boost::posix_time::ptime timer;
 
2767
  uint32_t      timer, warnings= 0;
2816
2768
  uint32_t      error= 0;
2817
2769
  uint32_t      error_code= 0;
2818
2770
  int           err= 0;
2881
2833
        goto end;
2882
2834
    }
2883
2835
 
2884
 
    string time_buff("");
2885
2836
    if (verbose >= 3 || !opt_silent)
2886
2837
      drizzle_end_timer(timer,time_buff);
 
2838
    else
 
2839
      time_buff[0]= '\0';
2887
2840
 
2888
2841
    /* Every branch must truncate  buff . */
2889
2842
    if (drizzle_result_column_count(&result) > 0)
2934
2887
      if (warnings != 1)
2935
2888
        *pos++= 's';
2936
2889
    }
2937
 
    strcpy(pos, time_buff.c_str());
 
2890
    strcpy(pos, time_buff);
2938
2891
    put_info(buff,INFO_RESULT,0,0);
2939
2892
    if (strcmp(drizzle_result_info(&result), ""))
2940
2893
      put_info(drizzle_result_info(&result),INFO_RESULT,0,0);
3100
3053
  {
3101
3054
    tee_fprintf(PAGER, _("Field %3u:  `%s`\n"
3102
3055
                "Catalog:    `%s`\n"
3103
 
                "Schema:     `%s`\n"
 
3056
                "Database:   `%s`\n"
3104
3057
                "Table:      `%s`\n"
3105
3058
                "Org_table:  `%s`\n"
3106
3059
                "Type:       UTF-8\n"
3626
3579
  /* Skip the spaces between the command and the argument */
3627
3580
  while (param && isspace(*param))
3628
3581
    param++;
3629
 
  if (!param || (*param == '\0')) // if pager was not given, use the default
 
3582
  if (!param || !strlen(param)) // if pager was not given, use the default
3630
3583
  {
3631
3584
    if (!default_pager_set)
3632
3585
    {
3739
3692
  }
3740
3693
  else
3741
3694
    opt_rehash= 0;
3742
 
  error=sql_connect(current_host, current_db, current_user, opt_password);
 
3695
  error=sql_connect(current_host, current_db, current_user, opt_password,0);
3743
3696
  opt_rehash= save_rehash;
3744
3697
 
3745
3698
  if (connected)
3746
3699
  {
3747
3700
    sprintf(buff, _("Connection id:    %u"), drizzle_con_thread_id(&con));
3748
3701
    put_info(buff,INFO_INFO,0,0);
3749
 
    sprintf(buff, _("Current schema: %.128s\n"),
 
3702
    sprintf(buff, _("Current database: %.128s\n"),
3750
3703
            !current_db.empty() ? current_db.c_str() : _("*** NONE ***"));
3751
3704
    put_info(buff,INFO_INFO,0,0);
3752
3705
  }
3859
3812
  tmp= get_arg(buff, 0);
3860
3813
  if (!tmp || !*tmp)
3861
3814
  {
3862
 
    put_info(_("USE must be followed by a schema name"), INFO_ERROR, 0, 0);
 
3815
    put_info(_("USE must be followed by a database name"), INFO_ERROR, 0, 0);
3863
3816
    return 0;
3864
3817
  }
3865
3818
  /*
3927
3880
      build_completion_hash(opt_rehash, 1);
3928
3881
  }
3929
3882
 
3930
 
  put_info(_("Schema changed"),INFO_INFO, 0, 0);
 
3883
  put_info(_("Database changed"),INFO_INFO, 0, 0);
3931
3884
  return 0;
3932
3885
}
3933
3886
 
3934
 
static int com_shutdown(string *, const char *)
3935
 
{
3936
 
  drizzle_result_st result;
3937
 
  drizzle_return_t ret;
3938
 
 
3939
 
  if (verbose)
3940
 
  {
3941
 
    printf(_("shutting down drizzled"));
3942
 
    if (opt_drizzle_port > 0)
3943
 
      printf(_(" on port %d"), opt_drizzle_port);
3944
 
    printf("... ");
3945
 
  }
3946
 
 
3947
 
  if (drizzle_shutdown(&con, &result, DRIZZLE_SHUTDOWN_DEFAULT,
3948
 
                       &ret) == NULL || ret != DRIZZLE_RETURN_OK)
3949
 
  {
3950
 
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
3951
 
    {
3952
 
      fprintf(stderr, _("shutdown failed; error: '%s'"),
3953
 
              drizzle_result_error(&result));
3954
 
      drizzle_result_free(&result);
3955
 
    }
3956
 
    else
3957
 
    {
3958
 
      fprintf(stderr, _("shutdown failed; error: '%s'"),
3959
 
              drizzle_con_error(&con));
3960
 
    }
3961
 
    return false;
3962
 
  }
3963
 
 
3964
 
  drizzle_result_free(&result);
3965
 
 
3966
 
  if (verbose)
3967
 
    printf(_("done\n"));
3968
 
 
3969
 
  return false;
3970
 
}
3971
 
 
3972
3887
static int
3973
3888
com_warnings(string *, const char *)
3974
3889
{
4048
3963
 
4049
3964
 
4050
3965
static int
4051
 
sql_connect(const string &host, const string &database, const string &user, const string &password)
 
3966
sql_connect(const string &host, const string &database, const string &user, const string &password,
 
3967
                 uint32_t silent)
4052
3968
{
4053
3969
  drizzle_return_t ret;
4054
3970
  if (connected)
4058
3974
    drizzle_free(&drizzle);
4059
3975
  }
4060
3976
  drizzle_create(&drizzle);
4061
 
 
4062
 
#ifdef DRIZZLE_ADMIN_TOOL
4063
 
  drizzle_con_options_t options= (drizzle_con_options_t) (DRIZZLE_CON_ADMIN | (use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL));
4064
 
#else
4065
 
  drizzle_con_options_t options= (drizzle_con_options_t) (use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
4066
 
#endif
4067
 
 
4068
3977
  if (drizzle_con_add_tcp(&drizzle, &con, (char *)host.c_str(),
4069
3978
    opt_drizzle_port, (char *)user.c_str(),
4070
3979
    (char *)password.c_str(), (char *)database.c_str(),
4071
 
    options) == NULL)
 
3980
    use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL) == NULL)
4072
3981
  {
4073
3982
    (void) put_error(&con, NULL);
4074
3983
    (void) fflush(stdout);
4097
4006
*/
4098
4007
  if ((ret= drizzle_con_connect(&con)) != DRIZZLE_RETURN_OK)
4099
4008
  {
4100
 
 
4101
 
    if (opt_silent < 2)
 
4009
    if (!silent || (ret != DRIZZLE_RETURN_GETADDRINFO &&
 
4010
                    ret != DRIZZLE_RETURN_COULD_NOT_CONNECT))
4102
4011
    {
4103
4012
      (void) put_error(&con, NULL);
4104
4013
      (void) fflush(stdout);
4143
4052
      drizzle_row_t cur=drizzle_row_next(&result);
4144
4053
      if (cur)
4145
4054
      {
4146
 
        tee_fprintf(stdout, _("Current schema:\t%s\n"), cur[0] ? cur[0] : "");
 
4055
        tee_fprintf(stdout, _("Current database:\t%s\n"), cur[0] ? cur[0] : "");
4147
4056
        tee_fprintf(stdout, _("Current user:\t\t%s\n"), cur[1]);
4148
4057
      }
4149
4058
      drizzle_result_free(&result);
4162
4071
  if (skip_updates)
4163
4072
  {
4164
4073
    vidattr(A_BOLD);
4165
 
    tee_fprintf(stdout, _("\nAll updates ignored to this schema\n"));
 
4074
    tee_fprintf(stdout, _("\nAll updates ignored to this database\n"));
4166
4075
    vidattr(A_NORMAL);
4167
4076
  }
4168
4077
  tee_fprintf(stdout, _("Current pager:\t\t%s\n"), pager.c_str());
4388
4297
}
4389
4298
 
4390
4299
#include <sys/times.h>
 
4300
#ifdef _SC_CLK_TCK        // For mit-pthreads
 
4301
#undef CLOCKS_PER_SEC
 
4302
#define CLOCKS_PER_SEC (sysconf(_SC_CLK_TCK))
 
4303
#endif
4391
4304
 
4392
 
static boost::posix_time::ptime start_timer(void)
 
4305
static uint32_t start_timer(void)
4393
4306
{
4394
 
  return boost::posix_time::microsec_clock::universal_time();
 
4307
  struct tms tms_tmp;
 
4308
  return times(&tms_tmp);
4395
4309
}
4396
4310
 
4397
 
static void nice_time(boost::posix_time::time_duration duration, string &buff)
 
4311
 
 
4312
/**
 
4313
   Write as many as 52+1 bytes to buff, in the form of a legible
 
4314
   duration of time.
 
4315
 
 
4316
   len("4294967296 days, 23 hours, 59 minutes, 60.00 seconds")  ->  52
 
4317
*/
 
4318
static void nice_time(double sec,char *buff,bool part_second)
4398
4319
{
 
4320
  uint32_t tmp;
4399
4321
  ostringstream tmp_buff_str;
4400
4322
 
4401
 
  if (duration.hours() > 0)
4402
 
  {
4403
 
    tmp_buff_str << duration.hours();
4404
 
    if (duration.hours() > 1)
 
4323
  if (sec >= 3600.0*24)
 
4324
  {
 
4325
    tmp=(uint32_t) floor(sec/(3600.0*24));
 
4326
    sec-= 3600.0*24*tmp;
 
4327
    tmp_buff_str << tmp;
 
4328
 
 
4329
    if (tmp > 1)
 
4330
      tmp_buff_str << " days ";
 
4331
    else
 
4332
      tmp_buff_str << " day ";
 
4333
 
 
4334
  }
 
4335
  if (sec >= 3600.0)
 
4336
  {
 
4337
    tmp=(uint32_t) floor(sec/3600.0);
 
4338
    sec-=3600.0*tmp;
 
4339
    tmp_buff_str << tmp;
 
4340
 
 
4341
    if (tmp > 1)
4405
4342
      tmp_buff_str << _(" hours ");
4406
4343
    else
4407
4344
      tmp_buff_str << _(" hour ");
4408
4345
  }
4409
 
  if (duration.hours() > 0 || duration.minutes() > 0)
 
4346
  if (sec >= 60.0)
4410
4347
  {
4411
 
    tmp_buff_str << duration.minutes() << _(" min ");
 
4348
    tmp=(uint32_t) floor(sec/60.0);
 
4349
    sec-=60.0*tmp;
 
4350
    tmp_buff_str << tmp << _(" min ");
4412
4351
  }
4413
 
 
4414
 
  tmp_buff_str.precision(duration.num_fractional_digits());
4415
 
 
4416
 
  double seconds= duration.fractional_seconds();
4417
 
 
4418
 
  seconds/= pow(10.0,duration.num_fractional_digits());
4419
 
 
4420
 
  seconds+= duration.seconds();
4421
 
  tmp_buff_str << seconds << _(" sec");
4422
 
 
4423
 
  buff.append(tmp_buff_str.str());
4424
 
}
4425
 
 
4426
 
static void end_timer(boost::posix_time::ptime start_time, string &buff)
4427
 
{
4428
 
  boost::posix_time::ptime end_time= start_timer();
4429
 
  boost::posix_time::time_period duration(start_time, end_time);
4430
 
 
4431
 
  nice_time(duration.length(), buff);
4432
 
}
4433
 
 
4434
 
 
4435
 
static void drizzle_end_timer(boost::posix_time::ptime start_time, string &buff)
4436
 
{
4437
 
  buff.append(" (");
4438
 
  end_timer(start_time,buff);
4439
 
  buff.append(")");
 
4352
  if (part_second)
 
4353
    tmp_buff_str.precision(2);
 
4354
  else
 
4355
    tmp_buff_str.precision(0);
 
4356
  tmp_buff_str << sec << _(" sec");
 
4357
  strcpy(buff, tmp_buff_str.str().c_str());
 
4358
}
 
4359
 
 
4360
 
 
4361
static void end_timer(uint32_t start_time,char *buff)
 
4362
{
 
4363
  nice_time((double) (start_timer() - start_time) /
 
4364
            CLOCKS_PER_SEC,buff,1);
 
4365
}
 
4366
 
 
4367
 
 
4368
static void drizzle_end_timer(uint32_t start_time,char *buff)
 
4369
{
 
4370
  buff[0]=' ';
 
4371
  buff[1]='(';
 
4372
  end_timer(start_time,buff+2);
 
4373
  strcpy(strchr(buff, '\0'),")");
4440
4374
}
4441
4375
 
4442
4376
static const char * construct_prompt()
4575
4509
        add_int_to_prompt(t->tm_sec);
4576
4510
        break;
4577
4511
      case 'w':
4578
 
        processed_prompt->append(get_day_name(t->tm_wday));
 
4512
        processed_prompt->append(day_names[t->tm_wday]);
4579
4513
        break;
4580
4514
      case 'P':
4581
4515
        processed_prompt->append(t->tm_hour < 12 ? "am" : "pm");
4584
4518
        add_int_to_prompt(t->tm_mon+1);
4585
4519
        break;
4586
4520
      case 'O':
4587
 
        processed_prompt->append(get_month_name(t->tm_mon));
 
4521
        processed_prompt->append(month_names[t->tm_mon]);
4588
4522
        break;
4589
4523
      case '\'':
4590
4524
        processed_prompt->append("'");