summaryrefslogtreecommitdiff
path: root/bin/bbackupquery/bbackupquery.cpp
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2006-10-15 18:54:23 +0000
committerChris Wilson <chris+github@qwirx.com>2006-10-15 18:54:23 +0000
commit03ac876c25900b9a8ee7640622454383a98730e2 (patch)
treed01e9eee2b8979da2f47bd34b69f8eac5a5c9e59 /bin/bbackupquery/bbackupquery.cpp
parenta2c4bfae39d3c6da32f804d0dcc11e3981b3c2b4 (diff)
Convert command-line arguments from the system locale/character set to
the console character set (code page), so they they can be converted from console to UTF-8 (yuck). Don't try to read from stdin or change its code page when it's not open (invalid file handle) (refs #3)
Diffstat (limited to 'bin/bbackupquery/bbackupquery.cpp')
-rw-r--r--bin/bbackupquery/bbackupquery.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/bin/bbackupquery/bbackupquery.cpp b/bin/bbackupquery/bbackupquery.cpp
index abd0177b..4b836406 100644
--- a/bin/bbackupquery/bbackupquery.cpp
+++ b/bin/bbackupquery/bbackupquery.cpp
@@ -171,7 +171,8 @@ int main(int argc, const char *argv[])
}
// enable input of Unicode characters
- if (_setmode(_fileno(stdin), _O_TEXT) == -1)
+ if (_fileno(stdin) != -1 &&
+ _setmode(_fileno(stdin), _O_TEXT) == -1)
{
perror("Failed to set the console input to "
"binary mode");
@@ -245,7 +246,7 @@ int main(int argc, const char *argv[])
int c = 0;
while(c < argc && !context.Stop())
{
- context.DoCommand(argv[c++]);
+ context.DoCommand(argv[c++], true);
}
}
@@ -263,7 +264,7 @@ int main(int argc, const char *argv[])
// Ctrl-D pressed -- terminate now
break;
}
- context.DoCommand(command);
+ context.DoCommand(command, false);
if(last_cmd != 0 && ::strcmp(last_cmd, command) == 0)
{
free(command);
@@ -284,13 +285,16 @@ int main(int argc, const char *argv[])
#endif
#else
// Version for platforms which don't have readline by default
- FdGetLine getLine(fileno(stdin));
- while(!context.Stop())
+ if(fileno(stdin) >= 0)
{
- printf("query > ");
- fflush(stdout);
- std::string command(getLine.GetLine());
- context.DoCommand(command.c_str());
+ FdGetLine getLine(fileno(stdin));
+ while(!context.Stop())
+ {
+ printf("query > ");
+ fflush(stdout);
+ std::string command(getLine.GetLine());
+ context.DoCommand(command.c_str(), false);
+ }
}
#endif