From patchwork Tue Jul 19 16:12:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 989192 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p6JGC8NK020633 for ; Tue, 19 Jul 2011 16:12:08 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751953Ab1GSQME (ORCPT ); Tue, 19 Jul 2011 12:12:04 -0400 Received: from smtp207.alice.it ([82.57.200.103]:44444 "EHLO smtp207.alice.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751787Ab1GSQMD (ORCPT ); Tue, 19 Jul 2011 12:12:03 -0400 Received: from venice.bhome (82.59.204.123) by smtp207.alice.it (8.5.124.08) id 4DFA189A03543042 for linux-btrfs@vger.kernel.org; Tue, 19 Jul 2011 18:12:03 +0200 Subject: [PATCH 5/6] Show the help messages from the info in the comment. To: linux-btrfs From: Goffredo Baroncelli Date: Tue, 19 Jul 2011 18:12:22 +0200 Message-ID: <20110719161222.3210.30489.stgit@venice.bhome> In-Reply-To: <20110719161049.3210.54794.stgit@venice.bhome> References: <20110719161049.3210.54794.stgit@venice.bhome> User-Agent: StGit/0.15 MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 19 Jul 2011 16:12:08 +0000 (UTC) From: Goffredo Baroncelli The makefile is update in order to use the tool "helpextract" to extract the info from the sources comments and to generate the file "helpmsg.c" which contains an array of string with all the information. Then the function "print_help" prints these information. --- btrfs.c | 34 +++++++++++++++++++++++++++++----- 1 files changed, 29 insertions(+), 5 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/btrfs.c b/btrfs.c index 98abb6c..53422f7 100644 --- a/btrfs.c +++ b/btrfs.c @@ -357,6 +357,8 @@ static struct Command commands[] = { { 0, 0, 0, 0 } }; +extern char * help_messages[]; + static char *get_prgname(char *programname) { char *np; @@ -372,21 +374,43 @@ static char *get_prgname(char *programname) static void print_help(char *programname, struct Command *cmd, int helptype) { char *pc; + int i; + char *adv_help; + char *std_help; + + /* printf("\t%s %s ", programname, cmd->verb ); */ + + adv_help = cmd->adv_help; + std_help = cmd->help; + + for(i = 0; help_messages[i]; i+= 4 ){ + if(!strncmp(help_messages[i],"btrfs ",6) && + !strcmp(help_messages[i]+6,cmd->verb) ){ + if(help_messages[i+2]) + std_help = help_messages[i+2]; + if(help_messages[i+3]) + adv_help = help_messages[i+3]; + printf("\t%s\t\t",help_messages[i+1]); + break; + } + } - printf("\t%s %s ", programname, cmd->verb ); + if( !help_messages[i]) + printf("\t%s %s ", programname, cmd->verb ); - if (helptype == ADVANCED_HELP && cmd->adv_help) - for(pc = cmd->adv_help; *pc; pc++){ + if (helptype == ADVANCED_HELP && adv_help){ + for(pc = adv_help; *pc; pc++){ putchar(*pc); if(*pc == '\n') printf("\t\t"); } - else - for(pc = cmd->help; *pc; pc++){ + }else{ + for(pc = std_help; *pc; pc++){ putchar(*pc); if(*pc == '\n') printf("\t\t"); } + } putchar('\n'); }