[Box Backup-commit] COMMIT r1043 - box/chris/general/bin/bbackupquery
boxbackup-dev@fluffy.co.uk
boxbackup-dev@fluffy.co.uk
Sun, 15 Oct 2006 14:50:21 +0100
Author: chris
Date: 2006-10-15 14:50:21 +0100 (Sun, 15 Oct 2006)
New Revision: 1043
Modified:
box/chris/general/bin/bbackupquery/BackupQueries.cpp
box/chris/general/bin/bbackupquery/BackupQueries.h
box/chris/general/bin/bbackupquery/bbackupquery.cpp
Log:
Tell BackupQueries whether the commands came from command line or from
console.
Convert command line commands from system encoding to console encoding,
so that we can convert them from console to UTF-8 later (yuck).
Don't try to read from the console when its file handle is invalid (e.g.
when running under LocalProcessStream).
Modified: box/chris/general/bin/bbackupquery/BackupQueries.cpp
===================================================================
--- box/chris/general/bin/bbackupquery/BackupQueries.cpp 2006-10-15 13:47:18 UTC (rev 1042)
+++ box/chris/general/bin/bbackupquery/BackupQueries.cpp 2006-10-15 13:50:21 UTC (rev 1043)
@@ -102,12 +102,12 @@
// --------------------------------------------------------------------------
//
// Function
-// Name: BackupQueries::DoCommand(const char *)
+// Name: BackupQueries::DoCommand(const char *, bool)
// Purpose: Perform a command
// Created: 2003/10/10
//
// --------------------------------------------------------------------------
-void BackupQueries::DoCommand(const char *Command)
+void BackupQueries::DoCommand(const char *Command, bool isFromCommandLine)
{
// is the command a shell command?
if(Command[0] == 's' && Command[1] == 'h' && Command[2] == ' ' && Command[3] != '\0')
@@ -168,6 +168,25 @@
if(!s.empty()) cmdElements.push_back(s);
}
+ #ifdef WIN32
+ if (isFromCommandLine)
+ {
+ for (std::vector<std::string>::iterator
+ i = cmdElements.begin();
+ i != cmdElements.end(); i++)
+ {
+ std::string converted;
+ if (!ConvertEncoding(*i, CP_ACP, converted,
+ GetConsoleCP()))
+ {
+ printf("Failed to convert encoding");
+ return;
+ }
+ *i = converted;
+ }
+ }
+ #endif
+
// Check...
if(cmdElements.size() < 1)
{
Modified: box/chris/general/bin/bbackupquery/BackupQueries.h
===================================================================
--- box/chris/general/bin/bbackupquery/BackupQueries.h 2006-10-15 13:47:18 UTC (rev 1042)
+++ box/chris/general/bin/bbackupquery/BackupQueries.h 2006-10-15 13:50:21 UTC (rev 1043)
@@ -36,7 +36,7 @@
BackupQueries(const BackupQueries &);
public:
- void DoCommand(const char *Command);
+ void DoCommand(const char *Command, bool isFromCommandLine);
// Ready to stop?
bool Stop() {return mQuitNow;}
Modified: box/chris/general/bin/bbackupquery/bbackupquery.cpp
===================================================================
--- box/chris/general/bin/bbackupquery/bbackupquery.cpp 2006-10-15 13:47:18 UTC (rev 1042)
+++ box/chris/general/bin/bbackupquery/bbackupquery.cpp 2006-10-15 13:50:21 UTC (rev 1043)
@@ -171,7 +171,8 @@
}
// 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 c = 0;
while(c < argc && !context.Stop())
{
- context.DoCommand(argv[c++]);
+ context.DoCommand(argv[c++], true);
}
}
@@ -263,7 +264,7 @@
// 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 @@
#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