From f66d8e2562ec885c29a578956bf092a1e48cd9da Mon Sep 17 00:00:00 2001 From: Galin Simeonov Date: Thu, 30 Sep 2021 23:20:00 +0300 Subject: reworked argument parsing and added the tree output option --- system_part.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 94 insertions(+), 24 deletions(-) (limited to 'system_part.c') diff --git a/system_part.c b/system_part.c index 04ea155..0c162b2 100644 --- a/system_part.c +++ b/system_part.c @@ -2,38 +2,105 @@ #define VOLGIT_SYSTEM_PART_C VOLGIT_SYSTEM_PART_C #include -const char *default_header="GIT"; -const char *default_footer=""; +const char *const default_header="GIT"; +const char *const default_footer=""; -struct Volgit_Options options; +struct Volgit_Options options + = + { + .input_path=NULL, + .output_path=NULL, + .header=default_header, + .footer=default_footer, + .output_dir_fd=-1, + .tree_cutoff=NO_TREE_CUTOFF, + .output_is_tree_like=0, + }; + +const char *usage= +"Options: \n" +" --input \n" +" --output \n" +" --header \n" +" --footer \n" +" --tree \n" +" Use 'tree' like output for directory index\n" +" --tree-cutoff \n" +" The tree output can get too bulky\n" +" so you can set a depth at which the output\n" +" is seperated into a different file\n" +" -h --help\n" +" Print this message\n"; + +static inline int get_next_option_or_die(int i,int argc,const char *error_message) +{ + if(i+1>=argc) + die(error_message); + return i+1; +} void parse_options(int argc,char **argv) { +#define if_option(option) if(!strncmp(argv[i],option,sizeof(option))) + int i; + if(argc==1) + die(usage); - options.header=default_header; - options.footer=default_footer; - switch(argc) + for(i=1;i