// // quickie - a small fast C++ Wiki Wiki // Copyright (C) 2005 Peter Miller // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. // // MANIFEST: Simple Version Tool // #include #include #include #include #include #include #include int main(int argc, char **argv) { arglex_svt cmdline(argc, argv); cmdline.token_first(); enum action_t { action_unset, action_listing, action_checkin, action_checkout, action_head_revision }; rcstring edit; rcstring file_name; rcstring history_name; action_t action = action_unset; bool verbose = false; rfc822 meta_data; while (cmdline.token_cur() != arglex::token_eoln) { switch (cmdline.token_cur()) { case arglex_svt::token_edit: edit = cmdline.get_string(arglex_svt::token_edit); break; case arglex_svt::token_file: file_name = cmdline.get_filename(arglex_svt::token_file); break; case arglex_svt::token_history: history_name = cmdline.get_filename(arglex_svt::token_history); break; case arglex_svt::token_check_in: action = action_checkin; break; case arglex_svt::token_list: action = action_listing; break; case arglex_svt::token_check_out: action = action_checkout; break; case arglex_svt::token_query: action = action_head_revision; break; case arglex::token_verbose: verbose = true; break; case arglex::token_string: // The rest of the arguments should be name=value pairs for checkin. switch (action) { default: cmdline.usage(); // NOTREACHED case action_unset: action = action_checkin; // fall through... case action_checkin: const char *arg = cmdline.value_string(); const char *ep = strchr(arg, '='); if (!ep) cmdline.bad_argument(); rcstring name(arg, ep - arg); rcstring value(ep + 1); meta_data.set(name, value); break; } break; default: cmdline.bad_argument(); // NOTREACHED } cmdline.token_next(); } if (history_name.empty()) quitter.fatal_error("no history file name specified"); // // Create an instance of the tool. // simple_version_tool archive(history_name); // // Perform the appropriate action, based on the command line options // given. // if (action == action_unset) { // Try to guess. if (!edit.empty()) action = action_checkout; } switch (action) { case action_head_revision: { if (!edit.empty() || !file_name.empty()) cmdline.usage(); rfc822_functor_print_version doodle; archive.list(doodle); } break; case action_checkin: if (!edit.empty()) cmdline.usage(); if (file_name.empty()) { quitter.message("no input file name specified"); cmdline.usage(); } archive.checkin(file_name, meta_data); break; case action_listing: { if (!edit.empty() || !file_name.empty()) cmdline.usage(); rfc822_functor_list_meta doodle; archive.list(doodle); } break; case action_checkout: if (file_name.empty()) { quitter.message("no output file name specified"); cmdline.usage(); } archive.checkout(file_name, edit); break; case action_unset: quitter.message("no action specified"); cmdline.usage(); // NOTREACHED } quitter.exit(0); return 0; }