* * * Shell Interface * * * ************************************************************************/ * xmlShellReadline: * @prompt: the prompt value * * Read a string * * Returns a pointer to it or NULL on EOF the caller is expected to * free the returned string. */
| 57 | * free the returned string. |
| 58 | */ |
| 59 | static char * |
| 60 | xmlShellReadline(const char *prompt) { |
| 61 | #ifdef HAVE_LIBREADLINE |
| 62 | char *line_read; |
| 63 | |
| 64 | /* Get a line from the user. */ |
| 65 | line_read = readline (prompt); |
| 66 | |
| 67 | /* If the line has any text in it, save it on the history. */ |
| 68 | if (line_read && *line_read) |
| 69 | add_history (line_read); |
| 70 | |
| 71 | return (line_read); |
| 72 | #else |
| 73 | char line_read[501]; |
| 74 | char *ret; |
| 75 | int len; |
| 76 | |
| 77 | if (prompt != NULL) |
| 78 | fprintf(stdout, "%s", prompt); |
| 79 | fflush(stdout); |
| 80 | if (!fgets(line_read, 500, stdin)) |
| 81 | return(NULL); |
| 82 | line_read[500] = 0; |
| 83 | len = strlen(line_read); |
| 84 | ret = (char *) malloc(len + 1); |
| 85 | if (ret != NULL) { |
| 86 | memcpy (ret, line_read, len + 1); |
| 87 | } |
| 88 | return(ret); |
| 89 | #endif |
| 90 | } |
| 91 | |
| 92 | static void usershell(void) { |
| 93 | char *cmdline = NULL, *cur; |