| 821 | } |
| 822 | |
| 823 | static int process_escape(const char *cmdstr) |
| 824 | { |
| 825 | char copy[256]; |
| 826 | char *lasts; |
| 827 | static const char *delims = " \r\n\t"; |
| 828 | char *tok; |
| 829 | |
| 830 | int len = strlen(cmdstr); |
| 831 | |
| 832 | strncpy(copy, cmdstr, sizeof(copy)); |
| 833 | copy[len] = '\0'; |
| 834 | |
| 835 | /* get first token, skip @ */ |
| 836 | tok = strtok_r(copy + 1, delims, &lasts); |
| 837 | |
| 838 | if (!tok) |
| 839 | return 0; |
| 840 | |
| 841 | if (strcasecmp(tok, "cdb2_close") == 0) { |
| 842 | cdb2_close(cdb2h); |
| 843 | cdb2h = NULL; |
| 844 | } else if (strcasecmp(tok, "redirect") == 0) { |
| 845 | tok = strtok_r(NULL, delims, &lasts); |
| 846 | |
| 847 | /* Close the redirect file. */ |
| 848 | if (!tok && redirect) { |
| 849 | fclose(redirect); |
| 850 | redirect = NULL; |
| 851 | |
| 852 | /* Move the saved stdout back to the real stdout. */ |
| 853 | dup2(hold_stdout, 1); |
| 854 | close(hold_stdout); |
| 855 | hold_stdout = -1; |
| 856 | } |
| 857 | /* User didn't supply a filename. */ |
| 858 | else if (!tok) { |
| 859 | fprintf(stderr, "expected redirect filename.\n"); |
| 860 | return -1; |
| 861 | } else { |
| 862 | if (redirect) |
| 863 | fclose(redirect); |
| 864 | |
| 865 | if (NULL == (redirect = fopen(tok, "w"))) { |
| 866 | fprintf(stderr, "error opening redirect file, %s.\n", |
| 867 | strerror(errno)); |
| 868 | return -1; |
| 869 | } |
| 870 | |
| 871 | if (-1 == hold_stdout) { |
| 872 | hold_stdout = dup(1); |
| 873 | } |
| 874 | dup2(fileno(redirect), 1); |
| 875 | } |
| 876 | } else if (strcasecmp(tok, "row_sleep") == 0) { |
| 877 | tok = strtok_r(NULL, delims, &lasts); |
| 878 | if (!tok) { |
| 879 | fprintf(stderr, "expected row sleep in seconds\n"); |
| 880 | return -1; |
no test coverage detected