BOOL WINAPI _export OpenArchive(const char *Name,int *Type) { if (setjmp(jumper) != 0) {cleanup(); return FALSE;} // Сюда мы попадём при возникновении ошибки в одной из вызываемых процедур // OEM -> UTF8 char utf8name[MY_FILENAME_MAX*4]; oem_to_utf8 (Name, utf8name); // Прочитаем структуру архива arcinfo = new ARCHIVE (FILENAME (utf8name)); arcinfo->read_structure(); *Type = 0; // Сделаем так, чтобы следующий вызов GetArcItem привёл к чтению первого блока current_block=-1; dirblock=NULL; return TRUE; }
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 }