diff mbox series

[rt-tests,v2,08/18] pip_stress: Add command line parser

Message ID 20201007085653.11961-9-dwagner@suse.de
State New
Headers show
Series Streamline command line | expand

Commit Message

Daniel Wagner Oct. 7, 2020, 8:56 a.m. UTC
Add a default command line parser to print at least the current
version.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
 src/pi_tests/pip_stress.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

Comments

John Kacur Oct. 23, 2020, 5:33 p.m. UTC | #1
On Wed, 7 Oct 2020, Daniel Wagner wrote:

> Add a default command line parser to print at least the current

> version.

> 

> Signed-off-by: Daniel Wagner <dwagner@suse.de>

> ---

>  src/pi_tests/pip_stress.c | 34 +++++++++++++++++++++++++++++-----

>  1 file changed, 29 insertions(+), 5 deletions(-)

> 

> diff --git a/src/pi_tests/pip_stress.c b/src/pi_tests/pip_stress.c

> index c9dbd992e15d..74cf53dcfa7a 100644

> --- a/src/pi_tests/pip_stress.c

> +++ b/src/pi_tests/pip_stress.c

> @@ -67,12 +67,17 @@ struct State *statep;

>  const int policy = SCHED_FIFO;

>  const int prio_min;	/* Initialized for the minimum priority of policy */

>  

> -struct option long_options[] = {

> -    { "usleep", required_argument, 0, 0 },

> -    { 0,        0,                 0, 0 },

> -};

> +static void usage(int error)

> +{

> +	printf("pip_stress V %1.2f\n", VERSION);

> +	printf("Usage:\n"

> +	       "pip_stress <options>\n"\

> +	       "-h	--help                  Show this help menu.\n"

> +	       );

> +	exit(error);

> +}

>  

> -int main(void)

> +int main(int argc, char *argv[])

>  {

>  	void *mptr;	/* memory pointer */

>  	pid_t pid1, pid2;

> @@ -80,6 +85,25 @@ int main(void)

>  	int res;

>  	int *minimum_priority = (int*)&prio_min;

>  

> +	for (;;) {

> +		struct option long_options[] = {

> +			{ "help",	no_argument,		NULL,	'h' },

> +			{ NULL,		0,			NULL,	0 },

> +		};

> +

> +		int c = getopt_long(argc, argv, "s:h", long_options, NULL);

> +		if (c == -1)

> +			break;

> +		switch (c) {

> +		case 'h':

> +			usage(0);

> +			break;

> +		default:

> +			usage(1);

> +			break;

> +		};

> +	}

> +

>  	*minimum_priority = sched_get_priority_min(policy);

>  

>  	if (check_privs())

> -- 

> 2.28.0

> 

> 


Uglifying my beautiful program in the name conformity?

Ugh, ok fine

Signed-off-by: John Kacur <jkacur@redhat.com>
Daniel Wagner Oct. 27, 2020, 8:09 a.m. UTC | #2
On Fri, Oct 23, 2020 at 01:33:42PM -0400, John Kacur wrote:
> Uglifying my beautiful program in the name conformity?

But now it can say 'help' :)
diff mbox series

Patch

diff --git a/src/pi_tests/pip_stress.c b/src/pi_tests/pip_stress.c
index c9dbd992e15d..74cf53dcfa7a 100644
--- a/src/pi_tests/pip_stress.c
+++ b/src/pi_tests/pip_stress.c
@@ -67,12 +67,17 @@  struct State *statep;
 const int policy = SCHED_FIFO;
 const int prio_min;	/* Initialized for the minimum priority of policy */
 
-struct option long_options[] = {
-    { "usleep", required_argument, 0, 0 },
-    { 0,        0,                 0, 0 },
-};
+static void usage(int error)
+{
+	printf("pip_stress V %1.2f\n", VERSION);
+	printf("Usage:\n"
+	       "pip_stress <options>\n"\
+	       "-h	--help                  Show this help menu.\n"
+	       );
+	exit(error);
+}
 
-int main(void)
+int main(int argc, char *argv[])
 {
 	void *mptr;	/* memory pointer */
 	pid_t pid1, pid2;
@@ -80,6 +85,25 @@  int main(void)
 	int res;
 	int *minimum_priority = (int*)&prio_min;
 
+	for (;;) {
+		struct option long_options[] = {
+			{ "help",	no_argument,		NULL,	'h' },
+			{ NULL,		0,			NULL,	0 },
+		};
+
+		int c = getopt_long(argc, argv, "s:h", long_options, NULL);
+		if (c == -1)
+			break;
+		switch (c) {
+		case 'h':
+			usage(0);
+			break;
+		default:
+			usage(1);
+			break;
+		};
+	}
+
 	*minimum_priority = sched_get_priority_min(policy);
 
 	if (check_privs())