btrfsprogs/0111-Show-the-help-messages-from-the-info-in-the-comment.patch

79 lines
2.0 KiB
Diff
Raw Normal View History

From 72aba9c58e83186db249f31198c03ebd0c34d7af Mon Sep 17 00:00:00 2001
From: Goffredo Baroncelli <kreijack@inwind.it>
Date: Sat, 16 Jul 2011 12:11:06 +0200
Subject: [PATCH 12/35] Show the help messages from the info in the comment.
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(-)
diff --git a/btrfs.c b/btrfs.c
index d2f6d4d..66b0d80 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -358,6 +358,8 @@ static struct Command commands[] = {
{ 0, 0, 0, 0 }
};
+extern char * help_messages[];
+
static char *get_prgname(char *programname)
{
char *np;
@@ -373,21 +375,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');
}
--
1.7.6.233.gd79bc