From 871eecac6c4fd5374b80af2cd0c80507117c44fd Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Tue, 9 Jul 2024 01:49:01 -0400 Subject: [PATCH] clarified the foreground mode usage --- app/maild.c | 12 +++---- lib/subrou.c | 4 +-- lib/subrou.h | 2 +- lib/unipar.c | 92 +++++++++------------------------------------------- 4 files changed, 24 insertions(+), 86 deletions(-) diff --git a/app/maild.c b/app/maild.c index a90cfad..6666fd8 100644 --- a/app/maild.c +++ b/app/maild.c @@ -42,15 +42,15 @@ phase=0; proceed=true; while (proceed==true) { switch (phase) { - case 0 : //initialising process - (void) rou_modesubrou(true); - (void) uni_modeunipar(true); - break; - case 1 : //checking parameters - if ((params=par_getparams(argc,argv,"d:hr:v"))==(ARGTYP *)0) { + case 0 : //checking parameters + if ((params=par_getparams(argc,argv,"d:fhr:v"))==(ARGTYP *)0) { phase=999; //no need to go further } break; + case 1 : //initialising process + (void) rou_modesubrou(true); + (void) uni_modeunipar(true); + break; default : //end of task (void) uni_modeunipar(false); (void) rou_modesubrou(false); diff --git a/lib/subrou.c b/lib/subrou.c index 0414c09..4dfdcae 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -14,7 +14,7 @@ //version definition #define VERSION "0.1" -#define RELEASE "7" +#define RELEASE "8" //Public variables PUBLIC int debug=0; //debug level @@ -153,8 +153,6 @@ if (mode!=modopen) { switch ((int)mode) { case true : debug=0; - //application started in background mode by default - foreground=false; off64_time=(time_t)0; off_date=(time_t)0; if (appname!=(char *)0) diff --git a/lib/subrou.h b/lib/subrou.h index 5444a60..316319a 100644 --- a/lib/subrou.h +++ b/lib/subrou.h @@ -12,7 +12,7 @@ #include -#define APPNAME "mailled" //application name +#define APPNAME "maild" //application name //--- Variables defined within subrou.c --------- extern int debug; //application debug mode diff --git a/lib/unipar.c b/lib/unipar.c index 8ad1745..551387c 100644 --- a/lib/unipar.c +++ b/lib/unipar.c @@ -44,91 +44,22 @@ return params; static void usage_aid(char *name) { -(void) fprintf(stderr,"%s-%s\n",name,rou_getversion()); (void) fprintf(stderr,"usage:\n "); (void) fprintf(stderr,"%s\t" "[-d debug] " + "[-f] " "[-h] " "[-r root] " "[-v] " "\n",name); (void) fprintf(stderr,"\twhere:\n"); (void) fprintf(stderr,"\t\t-d level\t: debug level [1-10]\n"); +(void) fprintf(stderr,"\t\t-f\t\t: start program in foreground (CLI) mode\n"); (void) fprintf(stderr,"\t\t-h\t\t: print this help message\n"); (void) fprintf(stderr,"\t\t-r root\t\t: root working directory\n"); (void) fprintf(stderr,"\t\t-v\t\t: Print program version number\n"); } /* - -*/ -/********************************************************/ -/* */ -/* Display aidobj usage parameter */ -/* */ -/********************************************************/ -static void usage_obj(char *name) - -{ -(void) fprintf(stderr,"%s-%s\n",name,rou_getversion()); -(void) fprintf(stderr,"usage:\n "); -(void) fprintf(stderr,"%s\t" - "[-d debug] " - "[-h] " - "[-r root] " - "[-v] " - "\n",name); -(void) fprintf(stderr,"\twhere:\n"); -(void) fprintf(stderr,"\t\t-d level\t: debug level [1-10]\n"); -(void) fprintf(stderr,"\t\t-h\t\t: print this help message\n"); -(void) fprintf(stderr,"\t\t-r root\t\t: root working directory\n"); -(void) fprintf(stderr,"\t\t-v\t\t: Print program version number\n"); -} -/* - -*/ -/********************************************************/ -/* */ -/* Display a list of parameters available according*/ -/* the name used to call the backd program */ -/* */ -/********************************************************/ -static int usage(char *name) - -{ -static char *prg[]={ - "aid", - "aidhud", - "aidobj", - (char *)0 - }; -int status; -int seq; -char *shortname; - -status=0; -if ((shortname=strrchr(name,'/'))==(char *)0) - shortname=name; -else - shortname++; -for (seq=0;prg[seq]!=(char *)0;seq++) { - if (strcmp(prg[seq],shortname)==0) - break; - } -switch (seq) { - case 0 : //aid - case 1 : //aidhud - (void) usage_aid(name); - break; - case 2 : //aidobj - (void) usage_obj(name); - break; - default : - (void) usage_aid(name); //unexpected default! - break; - } -return status; -} -/* ^L */ /********************************************************/ @@ -171,9 +102,14 @@ ARGTYP *par_getparams(int argc,char * const argv[],const char *optstring) { ARGTYP *params; +char *shortname; int c; params=initparams(); +if ((shortname=strrchr(argv[0],'/'))==(char *)0) + shortname=argv[0]; +else + shortname++; opterr=0; //no error message from getopt library routine while (((c=getopt(argc,argv,optstring))!=EOF)&&(params!=(ARGTYP *)0)) { switch(c) { @@ -181,11 +117,13 @@ while (((c=getopt(argc,argv,optstring))!=EOF)&&(params!=(ARGTYP *)0)) { debug=atoi(optarg); (void) rou_alert(1,"debug level is now '%d'",debug); break; - case 'f' : //foreground mode + case 'f' : //background/daemon mode foreground=true; + (void) fprintf(stderr,"%s-%s, foreground mode requested\n",shortname,rou_getversion()); break; case 'h' : //requestion program help - (void) usage(argv[0]); + (void) fprintf(stderr,"%s-%s\n",shortname,rou_getversion()); + (void) usage_aid(shortname); params=par_freeparams(params); break; case 'r' : @@ -194,12 +132,14 @@ while (((c=getopt(argc,argv,optstring))!=EOF)&&(params!=(ARGTYP *)0)) { rootdir=strdup(optarg); break; case 'v' : - (void) fprintf(stderr,"%s Version <%s>\n",argv[0],rou_getversion()); + (void) fprintf(stderr,"%s:\tVersion <%s>\n",shortname,rou_getversion()); (void) exit(0); //just display version break; default : - (void) usage(argv[0]); - (void) rou_alert(0,"\"%s\" unexpected argument designator",argv[optind-1]); + (void) fprintf(stderr,"%s-%s\n",shortname,rou_getversion()); + (void) fprintf(stderr,"\"%s\" unexpected argument designator\n\n", + argv[optind-1]); + (void) usage_aid(shortname); params=par_freeparams(params); break; } -- 2.47.3