Changeset 1210


Ignore:
Timestamp:
14/12/2006 23:20:36 (5 years ago)
Author:
chris
Message:
  • 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)

(merges [1050]+[1051])

Location:
box/trunk/bin/bbackupquery
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/bin/bbackupquery/BackupQueries.cpp

    r1209 r1210  
    103103// 
    104104// Function 
    105 //              Name:    BackupQueries::DoCommand(const char *) 
     105//              Name:    BackupQueries::DoCommand(const char *, bool) 
    106106//              Purpose: Perform a command 
    107107//              Created: 2003/10/10 
    108108// 
    109109// -------------------------------------------------------------------------- 
    110 void BackupQueries::DoCommand(const char *Command) 
     110void BackupQueries::DoCommand(const char *Command, bool isFromCommandLine) 
    111111{ 
    112112        // is the command a shell command? 
     
    169169        } 
    170170         
     171        #ifdef WIN32 
     172        if (isFromCommandLine) 
     173        { 
     174                for (std::vector<std::string>::iterator  
     175                        i  = cmdElements.begin(); 
     176                        i != cmdElements.end(); i++) 
     177                { 
     178                        std::string converted; 
     179                        if (!ConvertEncoding(*i, CP_ACP, converted,  
     180                                GetConsoleCP())) 
     181                        { 
     182                                printf("Failed to convert encoding"); 
     183                                return; 
     184                        } 
     185                        *i = converted; 
     186                } 
     187        } 
     188        #endif 
     189                 
    171190        // Check... 
    172191        if(cmdElements.size() < 1) 
     
    395414// 
    396415// Function 
    397 //              Name:    BackupQueries::List(int64_t, const std::string &, const bool *) 
     416//              Name:    BackupQueries::List(int64_t, const std::string &, const bool *, bool) 
    398417//              Purpose: Do the actual listing of directories and files 
    399418//              Created: 2003/10/10 
     
    872891// 
    873892// -------------------------------------------------------------------------- 
    874 void BackupQueries::CommandGet(const std::vector<std::string> &args, const bool *opts) 
     893void BackupQueries::CommandGet(std::vector<std::string> args, const bool *opts) 
    875894{ 
    876895        // At least one argument? 
     
    889908        // BLOCK 
    890909        { 
     910#ifdef WIN32 
     911                for (std::vector<std::string>::iterator  
     912                        i = args.begin(); i != args.end(); i++) 
     913                { 
     914                        std::string out; 
     915                        if(!ConvertConsoleToUtf8(i->c_str(), out)) 
     916                        { 
     917                                fprintf(stderr, "failed to convert encoding\n"); 
     918                                return; 
     919                        } 
     920                        *i = out; 
     921                } 
     922#endif 
     923 
     924                std::string fileName(args[0]); 
     925 
     926                if(!opts['i']) 
     927                { 
     928                        // does this remote filename include a path? 
     929                        std::string::size_type index = fileName.rfind('/'); 
     930                        if(index != std::string::npos) 
     931                        { 
     932                                std::string dirName(fileName.substr(0, index)); 
     933                                fileName = fileName.substr(index + 1); 
     934 
     935                                dirId = FindDirectoryObjectID(dirName); 
     936                                if(dirId == 0) 
     937                                { 
     938                                        printf("Directory '%s' not found\n",  
     939                                                dirName.c_str()); 
     940                                        return; 
     941                                } 
     942                        } 
     943                } 
     944 
     945                BackupStoreFilenameClear fn(fileName); 
     946 
    891947                // Need to look it up in the current directory 
    892948                mrConnection.QueryListDirectory( 
     
    925981                        // Specified by name, find the object in the directory to get the ID 
    926982                        BackupStoreDirectory::Iterator i(dir); 
    927 #ifdef WIN32 
    928                         std::string fileName; 
    929                         if(!ConvertConsoleToUtf8(args[0].c_str(), fileName)) 
    930                                 return; 
    931                         BackupStoreFilenameClear fn(fileName); 
    932 #else 
    933                         BackupStoreFilenameClear fn(args[0]); 
    934 #endif 
    935983                        BackupStoreDirectory::Entry *en = i.FindMatchingClearName(fn); 
    936984                         
  • box/trunk/bin/bbackupquery/BackupQueries.h

    r217 r1210  
    3737public: 
    3838 
    39         void DoCommand(const char *Command); 
     39        void DoCommand(const char *Command, bool isFromCommandLine); 
    4040 
    4141        // Ready to stop? 
     
    5151        void CommandChangeLocalDir(const std::vector<std::string> &args); 
    5252        void CommandGetObject(const std::vector<std::string> &args, const bool *opts); 
    53         void CommandGet(const std::vector<std::string> &args, const bool *opts); 
     53        void CommandGet(std::vector<std::string> args, const bool *opts); 
    5454        void CommandCompare(const std::vector<std::string> &args, const bool *opts); 
    5555        void CommandRestore(const std::vector<std::string> &args, const bool *opts); 
  • box/trunk/bin/bbackupquery/bbackupquery.cpp

    r1158 r1210  
    172172 
    173173                // enable input of Unicode characters 
    174                 if (_setmode(_fileno(stdin), _O_TEXT) == -1) 
     174                if (_fileno(stdin) != -1 && 
     175                        _setmode(_fileno(stdin), _O_TEXT) == -1) 
    175176                { 
    176177                        perror("Failed to set the console input to " 
     
    246247                while(c < argc && !context.Stop()) 
    247248                { 
    248                         context.DoCommand(argv[c++]); 
     249                        context.DoCommand(argv[c++], true); 
    249250                } 
    250251        } 
     
    264265                        break; 
    265266                } 
    266                 context.DoCommand(command); 
     267                context.DoCommand(command, false); 
    267268                if(last_cmd != 0 && ::strcmp(last_cmd, command) == 0) 
    268269                { 
     
    285286#else 
    286287        // Version for platforms which don't have readline by default 
    287         FdGetLine getLine(fileno(stdin)); 
    288         while(!context.Stop()) 
    289         { 
    290                 printf("query > "); 
    291                 fflush(stdout); 
    292                 std::string command(getLine.GetLine()); 
    293                 context.DoCommand(command.c_str()); 
     288        if(fileno(stdin) >= 0) 
     289        { 
     290                FdGetLine getLine(fileno(stdin)); 
     291                while(!context.Stop()) 
     292                { 
     293                        printf("query > "); 
     294                        fflush(stdout); 
     295                        std::string command(getLine.GetLine()); 
     296                        context.DoCommand(command.c_str(), false); 
     297                } 
    294298        } 
    295299#endif 
Note: See TracChangeset for help on using the changeset viewer.