From owner-svn-soc-all@freebsd.org Wed Jun 21 07:14:11 2017 Return-Path: Delivered-To: svn-soc-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DD34DD885C5 for ; Wed, 21 Jun 2017 07:14:11 +0000 (UTC) (envelope-from kneitinger@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id CF07B832C3 for ; Wed, 21 Jun 2017 07:14:11 +0000 (UTC) (envelope-from kneitinger@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id v5L7EBfK087049 for ; Wed, 21 Jun 2017 07:14:11 GMT (envelope-from kneitinger@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id v5L7EBhQ087015 for svn-soc-all@FreeBSD.org; Wed, 21 Jun 2017 07:14:11 GMT (envelope-from kneitinger@FreeBSD.org) Date: Wed, 21 Jun 2017 07:14:11 GMT Message-Id: <201706210714.v5L7EBhQ087015@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to kneitinger@FreeBSD.org using -f From: kneitinger@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r323785 - soc2017/kneitinger/libbe-head/usr.bin/be MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Jun 2017 07:14:12 -0000 Author: kneitinger Date: Wed Jun 21 07:14:10 2017 New Revision: 323785 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=323785 Log: Add parser for be activate command Modified: soc2017/kneitinger/libbe-head/usr.bin/be/be.c Modified: soc2017/kneitinger/libbe-head/usr.bin/be/be.c ============================================================================== --- soc2017/kneitinger/libbe-head/usr.bin/be/be.c Wed Jun 21 06:44:56 2017 (r323784) +++ soc2017/kneitinger/libbe-head/usr.bin/be/be.c Wed Jun 21 07:14:10 2017 (r323785) @@ -31,6 +31,7 @@ #include #include #include +#include static int be_activate( int argc, char *argv[]); static int be_create( int argc, char *argv[]); @@ -68,12 +69,12 @@ * Represents a relationship between the command name and the parser action * that handles it. */ -struct cmd_map_entry { +struct command_map_entry { const char *command; int (*fn)(int argc, char *argv[]); }; -static struct cmd_map_entry command_map[] = { +static struct command_map_entry command_map[] = { { "activate", be_activate }, { "create", be_create }, { "destroy", be_destroy }, @@ -85,11 +86,56 @@ { "unmount", be_unmount }, }; +static int +get_cmd_index(char *cmd, int *index) +{ + int map_size = sizeof(command_map) / sizeof (struct command_map_entry); + + for (int i=0; i < map_size; ++i) { + if (strcmp(cmd, command_map[i].command) == 0) { + *index = i; + return 0; + } + } + + return 1; +} + static int be_activate( int argc, char *argv[]) { - return(EX_USAGE); + int opt; + bool temp; + char *bootenv; + + temp = false; + while((opt = getopt(argc, argv, "t")) != -1) { + switch(opt) { + case 't': + temp = true; + break; + default: + fprintf(stderr, "be activate: unknown option '-%c'\n", + optopt); + usage(false); + return(EX_USAGE); + } + } + + argc -= optind; + argv += optind; + + if(argc != 1) { + fprintf(stderr, "be activate: wrong number of arguments\n"); + usage(false); + } + + bootenv = argv[0]; + + /* activate logic goes here */ + + return 0; } static int @@ -143,7 +189,8 @@ int main(int argc, char *argv[]) { - char *command; + char *command; + int command_index; if (argc < 2) { fprintf(stderr, "missing command\n"); @@ -162,5 +209,13 @@ if (strcmp(command, "-?") == 0 || strcmp(command, "-h") == 0) usage(true); - return 0; + + if (get_cmd_index(command, &command_index)) { + fprintf(stderr, "unknown command: %s\n", command); + usage(false); + exit(EX_USAGE); + } + + + return command_map[command_index].fn(argc-1,argv+1); }