All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Allow a hyphenated range in get_options
@ 2006-10-31 17:25 Derek Fults
  2006-10-31 18:11 ` Randy Dunlap
  2006-10-31 18:19 ` Alexey Dobriyan
  0 siblings, 2 replies; 5+ messages in thread
From: Derek Fults @ 2006-10-31 17:25 UTC (permalink / raw)
  To: linux-kernel

This allows a hyphenated range of positive numbers in the string passed
to command line helper function, get_options.    

Signed-off-by: Derek Fults <dfults@sgi.com>  

Index: linux/lib/cmdline.c
===================================================================
--- linux.orig/lib/cmdline.c	2006-09-19 22:42:06.000000000 -0500
+++ linux/lib/cmdline.c	2006-10-30 10:39:13.351641023 -0600
@@ -29,6 +29,10 @@
  *	0 : no int in string
  *	1 : int found, no subsequent comma
  *	2 : int found including a subsequent comma
+ *  -(int): int found with a subsequent hyphen to denote a range.
+ *          The negative number is the number of integers in the range
+ *          used to increment the counter in the while loop.
+ *      
  */
 
 int get_option (char **str, int *pint)
@@ -44,7 +48,16 @@
 		(*str)++;
 		return 2;
 	}
+	if (**str == '-') {
+	    int x,inc_counter= 0, upper_range = 0;
 
+	    (*str)++;
+	    upper_range = simple_strtol ((*str), NULL, 0);
+	    inc_counter = upper_range - *pint ;
+	    for (x=*pint; x < upper_range; x++) 
+		    *pint++ = x;
+	    return -inc_counter;
+	}
 	return 1;
 }
 
@@ -55,7 +68,8 @@
  *	@ints: integer array
  *
  *	This function parses a string containing a comma-separated
- *	list of integers.  The parse halts when the array is
+ *	list of integers, a hyphen-separated range of _positive_ integers,
+ *      or a combination of both.  The parse halts when the array is
  *	full, or when no more numbers can be retrieved from the
  *	string.
  *
@@ -75,6 +89,11 @@
 		i++;
 		if (res == 1)
 			break;
+		if (res < 0) 
+		        /* Decrement the result by one to leave out the 
+			   last number in the range.  The next iteration 
+			   will handle the upper number in the range */
+		        i += ((-res) - 1);
 	}
 	ints[0] = i - 1;
 	return (char *)str;


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Allow a hyphenated range in get_options
  2006-10-31 17:25 [PATCH] Allow a hyphenated range in get_options Derek Fults
@ 2006-10-31 18:11 ` Randy Dunlap
  2006-10-31 18:54   ` Derek Fults
  2006-10-31 18:19 ` Alexey Dobriyan
  1 sibling, 1 reply; 5+ messages in thread
From: Randy Dunlap @ 2006-10-31 18:11 UTC (permalink / raw)
  To: Derek Fults; +Cc: linux-kernel

On Tue, 31 Oct 2006 11:25:16 -0600 Derek Fults wrote:

> This allows a hyphenated range of positive numbers in the string passed
> to command line helper function, get_options.    
> 
> Signed-off-by: Derek Fults <dfults@sgi.com>  

Hi,
Needs justification (why?) and a user.

> Index: linux/lib/cmdline.c
> ===================================================================
> --- linux.orig/lib/cmdline.c	2006-09-19 22:42:06.000000000 -0500
> +++ linux/lib/cmdline.c	2006-10-30 10:39:13.351641023 -0600
> @@ -29,6 +29,10 @@
>   *	0 : no int in string
>   *	1 : int found, no subsequent comma
>   *	2 : int found including a subsequent comma
> + *  -(int): int found with a subsequent hyphen to denote a range.
> + *          The negative number is the number of integers in the range
> + *          used to increment the counter in the while loop.
> + *      
>   */
>  
>  int get_option (char **str, int *pint)
> @@ -44,7 +48,16 @@
>  		(*str)++;
>  		return 2;
>  	}
> +	if (**str == '-') {
> +	    int x,inc_counter= 0, upper_range = 0;

space after comma.

Odd indentation here.  Use tabs, no spaces.

> +	    (*str)++;
> +	    upper_range = simple_strtol ((*str), NULL, 0);

No space after function name.

> +	    inc_counter = upper_range - *pint ;
> +	    for (x=*pint; x < upper_range; x++) 

No whitespace at ends of lines (as above has).
Space around '=' sign.

> +		    *pint++ = x;
> +	    return -inc_counter;
> +	}
>  	return 1;
>  }
>  
> @@ -55,7 +68,8 @@
>   *	@ints: integer array
>   *
>   *	This function parses a string containing a comma-separated
> - *	list of integers.  The parse halts when the array is
> + *	list of integers, a hyphen-separated range of _positive_ integers,
> + *      or a combination of both.  The parse halts when the array is

Fix indentation to be same as other lines.

>   *	full, or when no more numbers can be retrieved from the
>   *	string.
>   *
> @@ -75,6 +89,11 @@
>  		i++;
>  		if (res == 1)
>  			break;
> +		if (res < 0) 
> +		        /* Decrement the result by one to leave out the 
> +			   last number in the range.  The next iteration 
> +			   will handle the upper number in the range */
> +		        i += ((-res) - 1);
>  	}
>  	ints[0] = i - 1;
>  	return (char *)str;
> 
> -


---
~Randy

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Allow a hyphenated range in get_options
  2006-10-31 17:25 [PATCH] Allow a hyphenated range in get_options Derek Fults
  2006-10-31 18:11 ` Randy Dunlap
@ 2006-10-31 18:19 ` Alexey Dobriyan
  1 sibling, 0 replies; 5+ messages in thread
From: Alexey Dobriyan @ 2006-10-31 18:19 UTC (permalink / raw)
  To: Derek Fults; +Cc: linux-kernel

On Tue, Oct 31, 2006 at 11:25:16AM -0600, Derek Fults wrote:
> This allows a hyphenated range of positive numbers in the string passed
> to command line helper function, get_options.

Please, find in-tree code which could use this feature. After you have
done it address comments below and resend series with this patch going
first, conversions going next.

> --- linux.orig/lib/cmdline.c
> +++ linux/lib/cmdline.c
> @@ -29,6 +29,10 @@
>   *	0 : no int in string
>   *	1 : int found, no subsequent comma
>   *	2 : int found including a subsequent comma
> + *  -(int): int found with a subsequent hyphen to denote a range.
> + *          The negative number is the number of integers in the range
> + *          used to increment the counter in the while loop.
> + *      
>   */

Comment mentions irrelevant implementations details. trailing whitespace

> @@ -44,7 +48,16 @@
>  		(*str)++;
>  		return 2;
>  	}
> +	if (**str == '-') {
> +	    int x,inc_counter= 0, upper_range = 0;
>  
> +	    (*str)++;
> +	    upper_range = simple_strtol ((*str), NULL, 0);
> +	    inc_counter = upper_range - *pint ;
> +	    for (x=*pint; x < upper_range; x++) 
> +		    *pint++ = x;
> +	    return -inc_counter;
> +	}

coding style.

> @@ -55,7 +68,8 @@
>   *	@ints: integer array
>   *
>   *	This function parses a string containing a comma-separated
> - *	list of integers.  The parse halts when the array is
> + *	list of integers, a hyphen-separated range of _positive_ integers,
> + *      or a combination of both.  The parse halts when the array is
>   *	full, or when no more numbers can be retrieved from the
>   *	string.
>   *
> @@ -75,6 +89,11 @@
>  		i++;
>  		if (res == 1)
>  			break;
> +		if (res < 0) 
> +		        /* Decrement the result by one to leave out the 
> +			   last number in the range.  The next iteration 
> +			   will handle the upper number in the range */
> +		        i += ((-res) - 1);

trailing whitespace


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Allow a hyphenated range in get_options
  2006-10-31 18:54   ` Derek Fults
@ 2006-10-31 18:52     ` Randy Dunlap
  0 siblings, 0 replies; 5+ messages in thread
From: Randy Dunlap @ 2006-10-31 18:52 UTC (permalink / raw)
  To: Derek Fults; +Cc: linux-kernel

Derek Fults wrote:
> Hi Randy,
> 
> On Tue, 2006-10-31 at 10:11 -0800, Randy Dunlap wrote:
>> On Tue, 31 Oct 2006 11:25:16 -0600 Derek Fults wrote:
>>
>>> This allows a hyphenated range of positive numbers in the string passed
>>> to command line helper function, get_options.    
>>>
>>> Signed-off-by: Derek Fults <dfults@sgi.com>  
>> Hi,
>> Needs justification (why?) and a user.
>>
> 
> Currently the command line option "isolcpus=" takes as its argument a
> list of cpus.  
> Format: <cpu number>,...,<cpu number>
> This can get extremely long when isolating the majority of cpus on a
> large system.  Valid values of  <cpu_number>  include all cpus, 0 to
> "number of CPUs in system - 1".

Yep, makes sense.  Just need to say so in the patch description
and supply a user of the code.

Thanks,
-- 
~Randy

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Allow a hyphenated range in get_options
  2006-10-31 18:11 ` Randy Dunlap
@ 2006-10-31 18:54   ` Derek Fults
  2006-10-31 18:52     ` Randy Dunlap
  0 siblings, 1 reply; 5+ messages in thread
From: Derek Fults @ 2006-10-31 18:54 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: linux-kernel

Hi Randy,

On Tue, 2006-10-31 at 10:11 -0800, Randy Dunlap wrote:
> On Tue, 31 Oct 2006 11:25:16 -0600 Derek Fults wrote:
> 
> > This allows a hyphenated range of positive numbers in the string passed
> > to command line helper function, get_options.    
> > 
> > Signed-off-by: Derek Fults <dfults@sgi.com>  
> 
> Hi,
> Needs justification (why?) and a user.
> 

Currently the command line option "isolcpus=" takes as its argument a
list of cpus.  
Format: <cpu number>,...,<cpu number>
This can get extremely long when isolating the majority of cpus on a
large system.  Valid values of  <cpu_number>  include all cpus, 0 to
"number of CPUs in system - 1".

> > Index: linux/lib/cmdline.c
> > ===================================================================
> > --- linux.orig/lib/cmdline.c	2006-09-19 22:42:06.000000000 -0500
> > +++ linux/lib/cmdline.c	2006-10-30 10:39:13.351641023 -0600
> > @@ -29,6 +29,10 @@
> >   *	0 : no int in string
> >   *	1 : int found, no subsequent comma
> >   *	2 : int found including a subsequent comma
> > + *  -(int): int found with a subsequent hyphen to denote a range.
> > + *          The negative number is the number of integers in the range
> > + *          used to increment the counter in the while loop.
> > + *      
> >   */
> >  
> >  int get_option (char **str, int *pint)
> > @@ -44,7 +48,16 @@
> >  		(*str)++;
> >  		return 2;
> >  	}
> > +	if (**str == '-') {
> > +	    int x,inc_counter= 0, upper_range = 0;
> 
> space after comma.
> 
> Odd indentation here.  Use tabs, no spaces.
> 
> > +	    (*str)++;
> > +	    upper_range = simple_strtol ((*str), NULL, 0);
> 
> No space after function name.
> 
> > +	    inc_counter = upper_range - *pint ;
> > +	    for (x=*pint; x < upper_range; x++) 
> 
> No whitespace at ends of lines (as above has).
> Space around '=' sign.
> 
> > +		    *pint++ = x;
> > +	    return -inc_counter;
> > +	}
> >  	return 1;
> >  }
> >  
> > @@ -55,7 +68,8 @@
> >   *	@ints: integer array
> >   *
> >   *	This function parses a string containing a comma-separated
> > - *	list of integers.  The parse halts when the array is
> > + *	list of integers, a hyphen-separated range of _positive_ integers,
> > + *      or a combination of both.  The parse halts when the array is
> 
> Fix indentation to be same as other lines.
> 
> >   *	full, or when no more numbers can be retrieved from the
> >   *	string.
> >   *
> > @@ -75,6 +89,11 @@
> >  		i++;
> >  		if (res == 1)
> >  			break;
> > +		if (res < 0) 
> > +		        /* Decrement the result by one to leave out the 
> > +			   last number in the range.  The next iteration 
> > +			   will handle the upper number in the range */
> > +		        i += ((-res) - 1);
> >  	}
> >  	ints[0] = i - 1;
> >  	return (char *)str;
> > 
> > -
> 
> 
> ---
> ~Randy
Derek

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-10-31 18:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-31 17:25 [PATCH] Allow a hyphenated range in get_options Derek Fults
2006-10-31 18:11 ` Randy Dunlap
2006-10-31 18:54   ` Derek Fults
2006-10-31 18:52     ` Randy Dunlap
2006-10-31 18:19 ` Alexey Dobriyan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.