change is_raw to set_cooked.

This commit is contained in:
Christopher Jeffrey 2014-12-10 11:42:33 -08:00
parent 7eba2dec57
commit 7a8ecff423

View File

@ -194,6 +194,8 @@ using namespace v8;
#define USE_LDB_ADDR 0 #define USE_LDB_ADDR 0
#define USE_LDB_TX 0 #define USE_LDB_TX 0
static termios orig_termios;
/** /**
* Node.js Exposed Function Templates * Node.js Exposed Function Templates
*/ */
@ -624,7 +626,7 @@ get_block_by_tx_unspent(const std::string itxid, CBlock& rcblock, CBlockIndex **
*/ */
static bool static bool
is_raw(void); set_cooked(void);
/** /**
* Functions * Functions
@ -714,6 +716,7 @@ async_start_node(uv_work_t *req) {
g_rpc = (bool)data->rpc; g_rpc = (bool)data->rpc;
g_testnet = (bool)data->testnet; g_testnet = (bool)data->testnet;
g_txindex = (bool)data->txindex; g_txindex = (bool)data->txindex;
tcgetattr(STDIN_FILENO, &orig_termios);
start_node(); start_node();
data->result = std::string("bitcoind opened."); data->result = std::string("bitcoind opened.");
} }
@ -812,7 +815,7 @@ start_node_thread(void) {
argv[argc] = arg; argv[argc] = arg;
argc++; argc++;
} else { } else {
if (!is_raw()) { if (set_cooked()) {
fprintf(stderr, "bitcoind.js: Bad -datadir value.\n"); fprintf(stderr, "bitcoind.js: Bad -datadir value.\n");
} }
} }
@ -840,7 +843,7 @@ start_node_thread(void) {
ParseParameters((const int)argc, (const char **)argv); ParseParameters((const int)argc, (const char **)argv);
if (!boost::filesystem::is_directory(GetDataDir(false))) { if (!boost::filesystem::is_directory(GetDataDir(false))) {
if (!is_raw()) { if (set_cooked()) {
fprintf(stderr, fprintf(stderr,
"bitcoind.js: Specified data directory \"%s\" does not exist.\n", "bitcoind.js: Specified data directory \"%s\" does not exist.\n",
mapArgs["-datadir"].c_str()); mapArgs["-datadir"].c_str());
@ -853,7 +856,7 @@ start_node_thread(void) {
try { try {
ReadConfigFile(mapArgs, mapMultiArgs); ReadConfigFile(mapArgs, mapMultiArgs);
} catch(std::exception &e) { } catch(std::exception &e) {
if (!is_raw()) { if (set_cooked()) {
fprintf(stderr, fprintf(stderr,
"bitcoind.js: Error reading configuration file: %s\n", e.what()); "bitcoind.js: Error reading configuration file: %s\n", e.what());
} }
@ -863,7 +866,7 @@ start_node_thread(void) {
} }
if (!SelectParamsFromCommandLine()) { if (!SelectParamsFromCommandLine()) {
if (!is_raw()) { if (set_cooked()) {
fprintf(stderr, fprintf(stderr,
"bitcoind.js: Invalid combination of -regtest and -testnet.\n"); "bitcoind.js: Invalid combination of -regtest and -testnet.\n");
} }
@ -874,7 +877,7 @@ start_node_thread(void) {
// Check for changed -txindex state // Check for changed -txindex state
if (fTxIndex != GetBoolArg("-txindex", false)) { if (fTxIndex != GetBoolArg("-txindex", false)) {
if (!is_raw()) { if (set_cooked()) {
fprintf(stderr, "You need to rebuild the database using -reindex to change -txindex\n"); fprintf(stderr, "You need to rebuild the database using -reindex to change -txindex\n");
} }
shutdown_complete = true; shutdown_complete = true;
@ -888,11 +891,11 @@ start_node_thread(void) {
boost::bind(&DetectShutdownThread, &threadGroup)); boost::bind(&DetectShutdownThread, &threadGroup));
fRet = AppInit2(threadGroup); fRet = AppInit2(threadGroup);
} catch (std::exception& e) { } catch (std::exception& e) {
if (!is_raw()) { if (set_cooked()) {
fprintf(stderr, "bitcoind.js: AppInit(): std::exception\n"); fprintf(stderr, "bitcoind.js: AppInit(): std::exception\n");
} }
} catch (...) { } catch (...) {
if (!is_raw()) { if (set_cooked()) {
fprintf(stderr, "bitcoind.js: AppInit(): other exception\n"); fprintf(stderr, "bitcoind.js: AppInit(): other exception\n");
} }
} }
@ -4822,7 +4825,7 @@ NAN_METHOD(WalletEncrypt) {
// unencrypted private keys. So: // unencrypted private keys. So:
StartShutdown(); StartShutdown();
if (!is_raw()) { if (set_cooked()) {
printf( printf(
"bitcoind.js:" "bitcoind.js:"
" wallet encrypted; bitcoind.js stopping," " wallet encrypted; bitcoind.js stopping,"
@ -6722,27 +6725,18 @@ SatoshiFromAmount(const CAmount& amount) {
* Helpers * Helpers
*/ */
// https://github.com/joyent/node/blob/master/src/tty_wrap.cc
// https://github.com/joyent/node/blob/master/deps/uv/src/unix/tty.c
static bool static bool
is_raw(void) { set_cooked(void) {
termios raw; uv_tty_t tty;
tty.mode = 1;
tty.orig_termios = orig_termios;
if (tcgetattr(STDIN_FILENO, &raw)) { if (!uv_tty_set_mode(&tty, 0)) {
return true; // failsafe printf("\x1b[H\x1b[J");
} return true;
// libuv sets:
// raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
// raw.c_oflag |= (ONLCR);
// raw.c_cflag |= (CS8);
// raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
// raw.c_cc[VMIN] = 1;
// raw.c_cc[VTIME] = 0;
if ((raw.c_oflag & ONLCR)
&& (raw.c_cflag & CS8)
&& raw.c_cc[VMIN] == 1
&& raw.c_cc[VTIME] == 0) {
return true;
} }
return false; return false;