| 5655 | } |
| 5656 | |
| 5657 | static const char *construct_prompt() |
| 5658 | { |
| 5659 | processed_prompt.free(); // Erase the old prompt |
| 5660 | time_t lclock = time(NULL); // Get the date struct |
| 5661 | struct tm *t = localtime(&lclock); |
| 5662 | |
| 5663 | /* parse through the settings for the prompt */ |
| 5664 | for (char *c = current_prompt; *c ; c++) |
| 5665 | { |
| 5666 | if (*c != PROMPT_CHAR) |
| 5667 | processed_prompt.append(*c); |
| 5668 | else |
| 5669 | { |
| 5670 | switch (*++c) { |
| 5671 | case '\0': |
| 5672 | c--; // stop it from going beyond if ends with % |
| 5673 | break; |
| 5674 | case 'c': |
| 5675 | add_int_to_prompt(++prompt_counter); |
| 5676 | break; |
| 5677 | case 'v': |
| 5678 | { |
| 5679 | const char *info= (connected ? |
| 5680 | mysql_get_server_info(&mysql) : |
| 5681 | "not_connected"); |
| 5682 | processed_prompt.append(info, strlen(info)); |
| 5683 | break; |
| 5684 | } |
| 5685 | case 'd': |
| 5686 | { |
| 5687 | const char *db= current_db ? current_db : "(none)"; |
| 5688 | processed_prompt.append(db, strlen(db)); |
| 5689 | break; |
| 5690 | } |
| 5691 | case 'N': |
| 5692 | { |
| 5693 | const char *name= (connected ? |
| 5694 | mysql_get_server_name(&mysql) : |
| 5695 | "unknown"); |
| 5696 | processed_prompt.append(name, strlen(name)); |
| 5697 | break; |
| 5698 | } |
| 5699 | case 'h': |
| 5700 | case 'H': |
| 5701 | { |
| 5702 | const char *prompt; |
| 5703 | prompt= connected ? mysql_get_host_info(&mysql) : "not_connected"; |
| 5704 | if (strstr(prompt, "Localhost") || strstr(prompt, "localhost ")) |
| 5705 | { |
| 5706 | if (*c == 'h') |
| 5707 | processed_prompt.append(STRING_WITH_LEN("localhost")); |
| 5708 | else |
| 5709 | { |
| 5710 | static char hostname[FN_REFLEN]; |
| 5711 | static size_t hostname_length; |
| 5712 | if (hostname_length) |
| 5713 | processed_prompt.append(hostname, hostname_length); |
| 5714 | else if (gethostname(hostname, sizeof(hostname)) == 0) |
no test coverage detected