summaryrefslogtreecommitdiff
path: root/btrfs.c
diff options
context:
space:
mode:
authorGoffredo Baroncelli <kreijack@inwind.it>2010-03-11 21:08:22 +0100
committerChris Mason <chris.mason@oracle.com>2010-03-11 22:09:38 -0500
commit7ebebb7bb14ad3a5e78d8d9047350591fa96f585 (patch)
tree17d05cddc1bebeb22648e47963cc0344b8d232e9 /btrfs.c
parent6d2cf042471cc728b5399b2beae54603739bc66a (diff)
downloadbtrfs-progs-7ebebb7bb14ad3a5e78d8d9047350591fa96f585.tar.gz
Add the program name as the first parameter in the command of the btrfs tool
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'btrfs.c')
-rw-r--r--btrfs.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/btrfs.c b/btrfs.c
index 20f7413..7e91fc8 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -104,6 +104,9 @@ static struct Command commands[] = {
{ 0, 0 , 0 }
};
+
+
+
static char *get_prgname(char *programname)
{
char *np;
@@ -208,6 +211,41 @@ static int check_ambiguity(struct Command *cmd, char **argv){
}
/*
+ * This function, compacts the program name and the command in the first
+ * element of the '*av' array
+ */
+static int prepare_args(int *ac, char ***av, char *prgname, struct Command *cmd ){
+
+ char **ret;
+ int i;
+ char *newname;
+
+ ret = (char **)malloc(sizeof(char*)*(*ac+1));
+ newname = (char*)malloc(strlen(prgname)+strlen(cmd->verb)+2);
+ if( !ret || !newname ){
+ free(ret);
+ free(newname);
+ return -1;
+ }
+
+ ret[0] = newname;
+ for(i=0; i < *ac ; i++ )
+ ret[i+1] = (*av)[i];
+
+ strcpy(newname, prgname);
+ strcat(newname, " ");
+ strcat(newname, cmd->verb);
+
+ (*ac)++;
+ *av = ret;
+
+ return 0;
+
+}
+
+
+
+/*
This function perform the following jobs:
- show the help if '--help' or 'help' or '-h' are passed
@@ -307,15 +345,20 @@ static int parse_args(int argc, char **argv,
matchcmd->verb, -matchcmd->nargs);
return -2;
}
- if(matchcmd->nargs >= 0 && matchcmd->nargs != *nargs_ && matchcmd->nargs != 999 ){
+ if(matchcmd->nargs >= 0 && matchcmd->nargs != *nargs_ && matchcmd->nargs != 999){
fprintf(stderr, "ERROR: '%s' requires %d arg(s)\n",
matchcmd->verb, matchcmd->nargs);
return -2;
}
+
+ if (prepare_args( nargs_, args_, prgname, matchcmd )){
+ fprintf(stderr, "ERROR: not enough memory\\n");
+ return -20;
+ }
+
return 1;
}
-
int main(int ac, char **av )
{