static const char *basic_gets(int *cnt) { int x = 0; #ifdef _MSC_VER int read, key; char keys[CMD_BUFLEN]; HANDLE stdinHandle; if (global_profile->batch_mode) { #endif printf("%s", prompt_str); if (global_profile->batch_mode) fflush(stdout); memset(&command_buf, 0, sizeof(command_buf)); for (x = 0; x < (sizeof(command_buf) - 1); x++) { int c = getchar(); if (c < 0) { if (fgets(command_buf, sizeof(command_buf) - 1, stdin) != command_buf) { break; } command_buf[strlen(command_buf)-1] = '\0'; /* remove endline */ break; } command_buf[x] = (char) c; if (command_buf[x] == '\n') { command_buf[x] = '\0'; break; } } *cnt = x; #ifdef _MSC_VER } else { stdinHandle = GetStdHandle(STD_INPUT_HANDLE); console_bufferInput (0, 0, prompt_str, PROMPT_OP); printf("%s", prompt_str); if (global_profile->batch_mode) fflush(stdout); *cnt = 0; memset(&command_buf, 0, sizeof(command_buf)); while (!*cnt) { if (console_readConsole(stdinHandle, keys, (int)sizeof(keys), &read, &key)) { *cnt = console_bufferInput(keys, read, command_buf, key); if (global_profile->batch_mode) fflush(stdout); if (!strcmp(command_buf, "Empty")) { command_buf[0] = 0; } } sleep_ms(20); } } #endif return command_buf; }
static const char *basic_gets(int *cnt) { #ifndef _MSC_VER int x = 0; printf("%s", prompt_str); memset(&command_buf, 0, sizeof(command_buf)); for (x = 0; x < (sizeof(command_buf) - 1); x++) { int c = getchar(); if (c < 0) { int y = read(fileno(stdin), command_buf, sizeof(command_buf) - 1); command_buf[y - 1] = '\0'; break; } command_buf[x] = (char) c; if (command_buf[x] == '\n') { command_buf[x] = '\0'; break; } } *cnt = x; #else int read, key; char keys[CMD_BUFLEN]; HANDLE stdinHandle = GetStdHandle(STD_INPUT_HANDLE); console_bufferInput (0, 0, prompt_str, PROMPT_OP); printf("%s", prompt_str); *cnt = 0; memset(&command_buf, 0, sizeof(command_buf)); while (!*cnt) { if (console_readConsole(stdinHandle, keys, (int)sizeof(keys), &read, &key)) { *cnt = console_bufferInput(keys, read, command_buf, key); if (!strcmp(command_buf, "Empty")) { command_buf[0] = 0; } } Sleep(20); } return command_buf; #endif }