static char * get_terminal_line(char *input_string, FILE *in, FILE *out) { static char *pline; const char *prompt = (0 == verbosity)? "" : "linkparser> "; #ifdef HAVE_EDITLINE pline = lg_readline(prompt); #else fprintf(out, "%s", prompt); fflush(out); #ifdef _WIN32 if (!running_under_cygwin) pline = get_console_line(); else pline = fgets(input_string, MAX_INPUT, in); #else pline = fgets(input_string, MAX_INPUT, in); #endif /* _WIN32 */ #endif /* HAVE_EDITLINE */ return pline; }
static char * fget_input_string(FILE *in, FILE *out, Command_Options* copts) { #ifdef HAVE_EDITLINE static char * pline = NULL; const char * prompt = "linkparser> "; if (NULL == in) { if (pline) free(pline); return NULL; } if (in != stdin) { static char input_string[MAX_INPUT]; input_pending = false; if (fgets(input_string, MAX_INPUT, in)) return input_string; return NULL; } if (input_pending && pline != NULL) { input_pending = false; return pline; } if (copts->batch_mode || verbosity == 0 || input_pending) { prompt = ""; } input_pending = false; if (pline) free(pline); pline = lg_readline(prompt); return pline; #else static char input_string[MAX_INPUT]; if (NULL == in) return NULL; if (!copts->batch_mode && verbosity > 0 && !input_pending) { fprintf(out, "linkparser> "); fflush(out); } input_pending = false; #if defined(_MSC_VER) || defined(__MINGW32__) /* Windows console input comes using the console codepage; * convert it to utf8 */ if (stdin == in) { static char * pline = NULL; if (fgets(input_string, MAX_INPUT, in)) { char *cr, *lf; if (pline) free(pline); pline = oem_to_utf8(input_string); cr = strchr(pline, '\r'); if (cr) *cr = '\0'; lf = strchr(pline, '\n'); if (lf) *lf = '\0'; return pline; } } else { /* It appears that MS Win always provides wide chars, even if * one asked for "just a string". So lets explicitly ask for * wide chars here, and convert to multi-byte UTF-8 on the fly. */ wchar_t winput_string[MAX_INPUT]; if (fgetws(winput_string, MAX_INPUT, in)) { size_t nc = wcstombs(input_string, winput_string, MAX_INPUT); if (nc && (((size_t) -1) != nc)) { char *cr, *lf; cr = strchr(input_string, '\r'); if (cr) *cr = '\0'; lf = strchr(input_string, '\n'); if (lf) *lf = '\0'; return input_string; } } } #else /* Linux et al return UTF-8 multi-byte strings. */ if (fgets(input_string, MAX_INPUT, in)) return input_string; #endif return NULL; #endif }