PERFORCE change 131739 for review
Garrett Cooper
gcooper at FreeBSD.org
Wed Dec 26 15:08:28 PST 2007
http://perforce.freebsd.org/chv.cgi?CH=131739
Change 131739 by gcooper at shiina-ibook on 2007/12/26 23:08:20
- Major efforts shown are part of code re-org.
- Add stubs for clean command.
Affected files ...
.. //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/pkgman/main.c#2 edit
Differences ...
==== //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/pkgman/main.c#2 (text+ko) ====
@@ -1,108 +1,202 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
+#include "pkgman.h"
+#include "pkgman_action.h"
+#include "pkgman_arg_parser.h"
+
+pkg_action init_action(int, freebsd_pkg_q_item);
-enum commands {
- add,
- check,
- create,
- delete,
- info,
- null,
- search,
- sign,
- update,
- version
-};
+int
+main(int argc, char **argv)
+{
-#define ADD "add"
-#define CHECK "check"
-#define CREATE "create"
-#define DELETE "delete"
-#define INFO "info"
-#define SEARCH "search"
-#define SIGN "sign"
-#define UPDATE "update"
-#define VERSION "version"
+ char *cmd_str;
+ char **optional_opt_str_p;
-typedef struct pkg_action;
+ uint64 global_flags = 0;
-pkg_action init_action(int);
+ pkg_action_arg_parser parsers[COMMAND_LENGTH-1];
-int
-main(int argc, char **argv)
-{
+ STAILQ_HEAD(fpkg_actions_stailq, freebsd_pkg_action) fpkg_actions_queue_head =
+ SLIST_HEAD_INITIALIZER(fpkg_actions_queue_head);
- char *action_str;
+ struct fpkg_actions_stailq *fpkg_actions_queue_headp;
- pkg_action action = init_action(null);
+ cmd_str = strdup(*(argv+1));
- command = strdup(*(argv+1));
+ optional_opt_str_p = (char**) malloc(sizeof(char*)+1);
if (0 == strcmp(cmd_str, ADD)) {
- action = init_action(add);
+ action_type = add;
+ } else if (0 == strcmp(cmd_str, CLEAN)) {
+ action_type = clean;
} else if (0 == strcmp(cmd_str, CHECK)) {
- action = init_action(check);
+ action_type = check;
} else if (0 == strcmp(cmd_str, CREATE)) {
- action = init_action(create);
+ action_type = create;
} else if (0 == strcmp(cmd_str, DELETE)) {
- action = init_action(delete);
+ action_type = delete;
} else if (0 == strcmp(cmd_str, INFO)) {
- action = init_action(info);
+ action_type = info;
} else if (0 == strcmp(cmd_str, SEARCH)) {
- action = init_action(search);
+ action_type = search;
} else if (0 == strcmp(cmd_str, SIGN)) {
- action = init_action(sign);
+ action_type = sign;
} else if (0 == strcmp(cmd_str, UPDATE)) {
- action = init_action(update);
+ action_type = update;
} else if (0 == strcmp(cmd_str, VERSION)) {
- action = init_action(version);
+ action_type = version;
+ } else {
+ action_type = NULL;
}
/** Skip over command string.. **/
- optind++;
+ optind = OPTION_OFFSET;
+
+ char opt_char;
+
+ int old_optidx;
+ int optional_opts_idx;
+ int i;
+
+ /** Preset the initial counter variables to 0. **/
+ old_optidx = optional_opts_idx = 0;
+
+ /** Don't error out on unknown / non-globally applied flags, yet.. **/
+ opterr = 0;
/** Parse in global arguments **/
+ while ( (opt_char = getopt(argc, argv, GLOBAL_OPT_STRING)) != -1 ) {
+
+ switch (opt_char) {
+ /** Force **/
+ case 'f':
+ global_settings->opts |= FORCE_FLAG;
+ break;
+ /** Interactive **/
+ case 'i':
+ global_settings->opts |= INTERACTIVE_FLAG;
+ break;
+ /** No-exec command **/
+ case 'o':
+ if (optarg != NULL && strlen(optarg)) {
+ char *tmp_pkg_origin;
+ strdup(tmp_pkg_origin, optarg);
+ /*
+ * @todo: Add tmp_pkg_origin to STAILQ here
+ * with origin names..
+ *
+ * Does this get freed with pkg_freebsd_pkg_new
+ * (or whatever the constructor was..)?
+ */
+ }
+ break;
+ /** Prefix **/
+ case 'p':
+ if (optarg != NULL && strlen(optarg)) {
+ strdup(global_settings->prefix_path_str, optarg);
+ }
+ break;
+ /** Quiet **/
+ case 'q':
+ if (global_settings->opts & VERBOSE_FLAG) {
+ errx(QV_ERR_MSG);
+ }
+ global_settings->opts |= QUIET_FLAG;
+ break;
+ /** Recursive **/
+ case 'r':
+ global_settings->opts |= RECURSIVE_FLAG;
+ break;
+ /** Verbose **/
+ case 'v':
+ if (global_settings->opts & QUIET_FLAG) {
+ errx(QV_ERR_MSG);
+ }
+ global_settings->opts |= VERBOSE_FLAG;
+ break;
+ }
+
+ /*
+ * Copy down all char* pointers to optional_opt_str_p to parse
+ * later on [in pkg_action_arg_parser->parse_args(..)]..
+ */
+ for (i = old_optidx; i < optidx; i++) {
+ (optional_opt_str_p+optional_opts_idx) = (argv+i);
+ optional_opts_idx++;
+ }
+ old_optidx = optidx;
+
+ }
/** End global args parse **/
- /** Parse command specific args **/
- if (action->parse_args() != 0) {
- action->print_use();
- exit(1);
+ /*
+ * Parse command specific args, once and once only..
+ * See pkg_action_parsers for more details.
+ */
+ for (i = 1; i <= version; i++) {
+
+ /*
+ * If arguments usage was invalid, print usage message for specific command
+ * and exit..
+ */
+ if (0 < parsers[action_type]->parse_args(optional_opts_idx+1, optional_opt_str_p)) {
+ action->print_use();
+ exit(1);
+ }
+
}
- if (action->perform() != 0)
- warnx("Error encountered when processing command: %s\n", cmd_str);
+ /*
+ * Result for the given action(s) to be performed.
+ */
+ int action_result;
+
+ /** Foreach action / pkg, repeat necessary set of steps to reach required conclusion... **/
+
+ /** Perform the action **/
+ if ( (action_result = action->perform()) != 0 ) {
+ warnx("Error encountered when processing command: %s\n", cmd_str);
+// break;
+ }
+
+ /** End foreach **/
- return 0;
+ return action_result;
}
+/**
+ * @brief Initialize the appropriate action as per the action_type provided.
+ * @return Object for respective constructor.
+ * @return NULL on bad action_type.
+ */
pkg_action
-init_action(int action_type)
+init_action(int action_type, freebsd_pkg *fpkg)
{
switch (action_type) {
case add:
- return pkg_action_add_new();
+ return pkg_action_add_new(fpkg);
+ case clean:
+ return pkg_action_clean_new(fpkg);
case check:
- return pkg_action_check_new();
+ return pkg_action_check_new(fpkg);
+ case create:
+ return pkg_action_create_new(fpkg);
case delete:
- return pkg_action_delete_new();
+ return pkg_action_delete_new(fpkg);
case info:
- return pkg_action_info_new();
+ return pkg_action_info_new(fpkg);
case null:
- return pkg_action_null_new();
+ return pkg_action_new(fpkg);
case search:
- return pkg_action_search_new();
+ return pkg_action_search_new(fpkg);
case sign:
- return pkg_action_sign_new();
+ return pkg_action_sign_new(fpkg);
case update:
- return pkg_action_update_new();
+ return pkg_action_update_new(fpkg);
case version:
- return pkg_action_version_new();
+ return pkg_action_version_new(fpkg);
}
More information about the p4-projects
mailing list