From owner-p4-projects@FreeBSD.ORG Wed Dec 26 23:08:27 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 9CB8316A41B; Wed, 26 Dec 2007 23:08:27 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 61AE416A419 for ; Wed, 26 Dec 2007 23:08:27 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 5473413C4E8 for ; Wed, 26 Dec 2007 23:08:27 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id lBQN8R2s003956 for ; Wed, 26 Dec 2007 23:08:27 GMT (envelope-from gcooper@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id lBQN8Rxb003945 for perforce@freebsd.org; Wed, 26 Dec 2007 23:08:27 GMT (envelope-from gcooper@FreeBSD.org) Date: Wed, 26 Dec 2007 23:08:27 GMT Message-Id: <200712262308.lBQN8Rxb003945@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gcooper@FreeBSD.org using -f From: Garrett Cooper To: Perforce Change Reviews Cc: Subject: PERFORCE change 131739 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Dec 2007 23:08:28 -0000 http://perforce.freebsd.org/chv.cgi?CH=131739 Change 131739 by gcooper@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 -#include -#include -#include +#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); }