summaryrefslogtreecommitdiff
path: root/bin/bbackupquery/BackupQueries.h
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2010-09-29 17:59:09 +0000
committerChris Wilson <chris+github@qwirx.com>2010-09-29 17:59:09 +0000
commite9af7f8259aa9fb8440100d5c25fb755f71879d0 (patch)
treef80048b929ce720331f446528f400b6416234857 /bin/bbackupquery/BackupQueries.h
parent28a1c334a7320ca57ebd85d0c30cb228df5bb938 (diff)
Implement basic readline/editline completion of remote file and directory
names, object IDs, and command options.
Diffstat (limited to 'bin/bbackupquery/BackupQueries.h')
-rw-r--r--bin/bbackupquery/BackupQueries.h84
1 files changed, 47 insertions, 37 deletions
diff --git a/bin/bbackupquery/BackupQueries.h b/bin/bbackupquery/BackupQueries.h
index 5d562103..7bc756c0 100644
--- a/bin/bbackupquery/BackupQueries.h
+++ b/bin/bbackupquery/BackupQueries.h
@@ -40,31 +40,7 @@ typedef enum
}
CommandType;
-typedef enum
-{
- Complete_End = 0,
- Complete_RemoteDir,
- Complete_RemoteFile,
- Complete_LocalDir,
- Complete_LocalFile,
- Complete_LocationName,
- Complete_RemoteIdInCurrentDir,
-}
-CompletionType;
-
-typedef struct
-{
- const char* name;
- const char* opts;
- CommandType type;
-}
-QueryCommandSpecification;
-
-// Data about commands
-extern QueryCommandSpecification commands[];
-
-extern const char *alias[];
-extern const int aliasIs[];
+struct QueryCommandSpecification;
// --------------------------------------------------------------------------
//
@@ -86,17 +62,21 @@ private:
public:
struct ParsedCommand
{
- std::vector<std::string> cmdElements;
- std::string options;
- std::string completeCommand;
- bool failed;
- ParsedCommand() : failed(false) { }
+ std::vector<std::string> mCmdElements;
+ std::string mOptions;
+ std::string mCompleteCommand;
+ bool mInOptions, mFailed;
+ QueryCommandSpecification* pSpec;
+ // mArgCount is the same as mCmdElements.size() for a complete
+ // command, but if the command line ends in a space,
+ // e.g. during readline parsing, it can be one greater,
+ // to indicate that we should complete the next item instead.
+ size_t mArgCount;
+ ParsedCommand(const std::string& Command,
+ bool isFromCommandLine);
};
- ParsedCommand ParseCommand(const std::string& Command,
- bool isFromCommandLine);
void DoCommand(ParsedCommand& rCommand);
- CompletionType* GetCompletionTypes(ParsedCommand& rCommand);
// Ready to stop?
bool Stop() {return mQuitNow;}
@@ -374,17 +354,19 @@ public:
} Type;
};
-private:
-
- // Utility functions
+ // Were private, but needed by completion functions:
+ int64_t GetCurrentDirectoryID();
int64_t FindDirectoryObjectID(const std::string &rDirName,
bool AllowOldVersion = false, bool AllowDeletedDirs = false,
std::vector<std::pair<std::string, int64_t> > *pStack = 0);
+
+private:
+
+ // Utility functions
int64_t FindFileID(const std::string& rNameOrIdString,
const bool *opts, int64_t *pDirIdOut,
std::string* pFileNameOut, int16_t flagsInclude,
int16_t flagsExclude, int16_t* pFlagsOut);
- int64_t GetCurrentDirectoryID();
std::string GetCurrentDirectoryName();
void SetReturnCode(int code) {mReturnCode = code;}
@@ -399,5 +381,33 @@ private:
int mReturnCode;
};
+typedef std::vector<std::string> (*CompletionHandler)
+ (BackupQueries::ParsedCommand& rCommand, const std::string& prefix,
+ BackupProtocolClient& rProtocol, const Configuration& rConfig,
+ BackupQueries& rQueries);
+
+std::vector<std::string> CompleteCommand(BackupQueries::ParsedCommand& rCommand,
+ const std::string& prefix, BackupProtocolClient& rProtocol,
+ const Configuration& rConfig, BackupQueries& rQueries);
+std::vector<std::string> CompleteOptions(BackupQueries::ParsedCommand& rCommand,
+ const std::string& prefix, BackupProtocolClient& rProtocol,
+ const Configuration& rConfig, BackupQueries& rQueries);
+
+#define MAX_COMPLETION_HANDLERS 4
+
+struct QueryCommandSpecification
+{
+ const char* name;
+ const char* opts;
+ CommandType type;
+ CompletionHandler complete[MAX_COMPLETION_HANDLERS];
+};
+
+// Data about commands
+extern QueryCommandSpecification commands[];
+
+extern const char *alias[];
+extern const int aliasIs[];
+
#endif // BACKUPQUERIES__H