~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

  • Committer: Jay Pipes
  • Date: 2009-02-04 15:44:25 UTC
  • mfrom: (829 drizzle)
  • mto: This revision was merged to the branch mainline in revision 830.
  • Revision ID: jpipes@serialcoder-20090204154425-th8xfk2ujz2y8xwg
Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
274
274
 
275
275
 
276
276
static COMMANDS commands[] = {
277
 
  { "?",      '?', com_help,   1, N_("Synonym for `help'.") },
 
277
  { "?",      '?', com_help,   0, N_("Synonym for `help'.") },
278
278
  { "clear",  'c', com_clear,  0, N_("Clear command.")},
279
279
  { "connect",'r', com_connect,1,
280
280
    N_("Reconnect to the server. Optional arguments are db and host." }),
284
284
    N_("Send command to drizzle server, display result vertically.")},
285
285
  { "exit",   'q', com_quit,   0, N_("Exit drizzle. Same as quit.")},
286
286
  { "go",     'g', com_go,     0, N_("Send command to drizzle server.") },
287
 
  { "help",   'h', com_help,   1, N_("Display this help.") },
 
287
  { "help",   'h', com_help,   0, N_("Display this help.") },
288
288
  { "nopager",'n', com_nopager,0, N_("Disable pager, print to stdout.") },
289
289
  { "notee",  't', com_notee,  0, N_("Don't write into outfile.") },
290
290
  { "pager",  'P', com_pager,  1,
2548
2548
  return 0;
2549
2549
}
2550
2550
 
2551
 
static void print_help_item(DRIZZLE_ROW *cur, int num_name, int num_cat, char *last_char)
2552
 
{
2553
 
  char ccat= (*cur)[num_cat][0];
2554
 
  if (*last_char != ccat)
2555
 
  {
2556
 
    put_info(ccat == 'Y' ? _("categories:") : _("topics:"), INFO_INFO,0,0);
2557
 
    *last_char= ccat;
2558
 
  }
2559
 
  tee_fprintf(PAGER, "   %s\n", (*cur)[num_name]);
2560
 
}
2561
 
 
2562
 
 
2563
 
static int com_server_help(string *buffer, const char *, const char *help_arg)
2564
 
{
2565
 
  DRIZZLE_ROW cur;
2566
 
  const char *server_cmd= buffer->c_str();
2567
 
  string cmd_buf;
2568
 
  DRIZZLE_RES *result;
2569
 
  int error;
2570
 
 
2571
 
  cmd_buf.reserve(100);
2572
 
  if (help_arg[0] != '\'')
2573
 
  {
2574
 
    const char *end_arg= strchr(help_arg, '\0');
2575
 
    if(--end_arg)
2576
 
    {
2577
 
      while (my_isspace(charset_info,*end_arg))
2578
 
        end_arg--;
2579
 
    }
2580
 
    cmd_buf.append("help '");
2581
 
    cmd_buf.append(help_arg, end_arg-help_arg);
2582
 
    cmd_buf.append("'");
2583
 
 
2584
 
    server_cmd= cmd_buf.c_str();
2585
 
  }
2586
 
 
2587
 
  if (!connected && reconnect())
2588
 
    return 1;
2589
 
 
2590
 
  if ((error= drizzle_real_query_for_lazy(server_cmd,(int)strlen(server_cmd))) ||
2591
 
      (error= drizzle_store_result_for_lazy(&result)))
2592
 
    return error;
2593
 
 
2594
 
  if (result)
2595
 
  {
2596
 
    unsigned int num_fields= drizzle_num_fields(result);
2597
 
    uint64_t num_rows= drizzle_num_rows(result);
2598
 
    drizzle_fetch_fields(result);
2599
 
    if (num_fields==3 && num_rows==1)
2600
 
    {
2601
 
      if (!(cur= drizzle_fetch_row(result)))
2602
 
      {
2603
 
        error= -1;
2604
 
        goto err;
2605
 
      }
2606
 
 
2607
 
      init_pager();
2608
 
      tee_fprintf(PAGER,   _("Name: \'%s\'\n"), cur[0]);
2609
 
      tee_fprintf(PAGER,   _("Description:\n%s"), cur[1]);
2610
 
      if (cur[2] && *((char*)cur[2]))
2611
 
        tee_fprintf(PAGER, _("Examples:\n%s"), cur[2]);
2612
 
      tee_fprintf(PAGER,   "\n");
2613
 
      end_pager();
2614
 
    }
2615
 
    else if (num_fields >= 2 && num_rows)
2616
 
    {
2617
 
      init_pager();
2618
 
      char last_char= 0;
2619
 
 
2620
 
      int num_name= 0, num_cat= 0;
2621
 
 
2622
 
      if (num_fields == 2)
2623
 
      {
2624
 
        put_info(_("Many help items for your request exist."), INFO_INFO,0,0);
2625
 
        put_info(_("To make a more specific request, please type 'help <item>',\nwhere <item> is one of the following"), INFO_INFO,0,0);
2626
 
        num_name= 0;
2627
 
        num_cat= 1;
2628
 
      }
2629
 
      else if ((cur= drizzle_fetch_row(result)))
2630
 
      {
2631
 
        tee_fprintf(PAGER, _("You asked for help about help category: '%s'\n"), cur[0]);
2632
 
        put_info(_("For more information, type 'help <item>', where <item> is one of the following"), INFO_INFO,0,0);
2633
 
        num_name= 1;
2634
 
        num_cat= 2;
2635
 
        print_help_item(&cur,1,2,&last_char);
2636
 
      }
2637
 
 
2638
 
      while ((cur= drizzle_fetch_row(result)))
2639
 
        print_help_item(&cur,num_name,num_cat,&last_char);
2640
 
      tee_fprintf(PAGER, "\n");
2641
 
      end_pager();
2642
 
    }
2643
 
    else
2644
 
    {
2645
 
      put_info(_("\nNothing found"), INFO_INFO,0,0);
2646
 
      put_info(_("Please try to run 'help contents' for a list of all accessible topics\n"), INFO_INFO,0,0);
2647
 
    }
2648
 
  }
2649
 
 
2650
 
err:
2651
 
  drizzle_free_result(result);
2652
 
  return error;
2653
 
}
2654
 
 
2655
2551
static int
2656
 
com_help(string *buffer, const char *line)
 
2552
com_help(string *buffer, const char *)
2657
2553
{
2658
2554
  register int i, j;
2659
 
  const char *help_arg= strchr(line,' ');
2660
2555
  char buff[32], *end;
2661
 
  if (help_arg)
2662
 
  {
2663
 
    while (my_isspace(charset_info,*help_arg))
2664
 
      help_arg++;
2665
 
    if (*help_arg) return com_server_help(buffer,line,help_arg);
2666
 
  }
2667
2556
 
2668
2557
  put_info(_("List of all Drizzle commands:"), INFO_INFO,0,0);
2669
2558
  if (!named_cmds)
2678
2567
      tee_fprintf(stdout, "%s(\\%c) %s\n", buff,
2679
2568
                  commands[i].cmd_char, _(commands[i].doc));
2680
2569
  }
2681
 
  if (connected && drizzle_get_server_version(&drizzle) >= 40100)
2682
 
    put_info(_("\nFor server side help, type 'help contents'\n"), INFO_INFO,0,0);
 
2570
  tee_fprintf(stdout, "\n");
 
2571
  buffer->clear();
2683
2572
  return 0;
2684
2573
}
2685
2574