All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] convert _count_hyphens to generalised _count_chars and export
@ 2007-04-20 14:37 Dave Wysochanski
  2007-04-20 15:06 ` [PATCH REPOST] convert _count_hyphens to generalised count_chars " Dave Wysochanski
  0 siblings, 1 reply; 4+ messages in thread
From: Dave Wysochanski @ 2007-04-20 14:37 UTC (permalink / raw)
  To: lvm-devel

Should not change functional behavior and be simple to review.
Adds newly created function to lvm-string.h exports.

Index: LVM2/lib/misc/lvm-string.c
===================================================================
--- LVM2.orig/lib/misc/lvm-string.c	2006-08-21 08:54:53.000000000 -0400
+++ LVM2/lib/misc/lvm-string.c	2007-04-20 10:28:03.000000000 -0400
@@ -36,21 +36,6 @@ int emit_to_buffer(char **buffer, size_t
 }
 
 /*
- * Device layer names are all of the form <vg>-<lv>-<layer>, any
- * other hyphens that appear in these names are quoted with yet
- * another hyphen.  The top layer of any device has no layer
- * name.  eg, vg0-lvol0.
- */
-static void _count_hyphens(const char *str, size_t *len, int *hyphens)
-{
-	const char *ptr;
-
-	for (ptr = str; *ptr; ptr++, (*len)++)
-		if (*ptr == '-')
-			(*hyphens)++;
-}
-
-/*
  * Copies a string, quoting hyphens with hyphens.
  */
 static void _quote_hyphens(char **out, const char *src)
@@ -63,6 +48,17 @@ static void _quote_hyphens(char **out, c
 	}
 }
 
+
+void _count_chars(const char *str, size_t *len, int *count,
+		  char c)
+{
+	const char *ptr;
+
+	for (ptr = str; *ptr; ptr++, (*len)++)
+		if (*ptr == c)
+			(*count)++;
+}
+
 /*
  * <vg>-<lv>-<layer> or if !layer just <vg>-<lv>.
  */
@@ -73,11 +69,11 @@ char *build_dm_name(struct dm_pool *mem,
 	int hyphens = 1;
 	char *r, *out;
 
-	_count_hyphens(vgname, &len, &hyphens);
-	_count_hyphens(lvname, &len, &hyphens);
+	_count_chars(vgname, &len, &hyphens, '-');
+	_count_chars(lvname, &len, &hyphens, '-');
 
 	if (layer && *layer) {
-		_count_hyphens(layer, &len, &hyphens);
+		_count_chars(layer, &len, &hyphens, '-');
 		hyphens++;
 	}
 
@@ -105,6 +101,12 @@ char *build_dm_name(struct dm_pool *mem,
 	return r;
 }
 
+/*
+ * Device layer names are all of the form <vg>-<lv>-<layer>, any
+ * other hyphens that appear in these names are quoted with yet
+ * another hyphen.  The top layer of any device has no layer
+ * name.  eg, vg0-lvol0.
+ */
 int validate_name(const char *n)
 {
 	register char c;
Index: LVM2/lib/misc/lvm-string.h
===================================================================
--- LVM2.orig/lib/misc/lvm-string.h	2006-08-21 08:54:53.000000000 -0400
+++ LVM2/lib/misc/lvm-string.h	2007-04-20 10:22:23.000000000 -0400
@@ -30,4 +30,7 @@ char *build_dm_name(struct dm_pool *mem,
 
 int validate_name(const char *n);
 
+void _count_chars(const char *str, size_t *len, int *count,
+		  char c);
+
 #endif
Index: LVM2/WHATS_NEW
===================================================================
--- LVM2.orig/WHATS_NEW	2007-04-20 10:16:21.000000000 -0400
+++ LVM2/WHATS_NEW	2007-04-20 10:23:37.000000000 -0400
@@ -1,5 +1,6 @@
 Version 2.02.25 -
 =================================
+  Convert _count_hyphens to generalized _count_chars.
   Add dev_read_circular.
   Add pvck command stub.
   Update lists of attribute characters in man pages.




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

* [PATCH REPOST] convert _count_hyphens to generalised count_chars and export
  2007-04-20 14:37 [PATCH] convert _count_hyphens to generalised _count_chars and export Dave Wysochanski
@ 2007-04-20 15:06 ` Dave Wysochanski
  2007-04-20 17:17   ` Dave Wysochanski
  0 siblings, 1 reply; 4+ messages in thread
From: Dave Wysochanski @ 2007-04-20 15:06 UTC (permalink / raw)
  To: lvm-devel

(NOTE: only change from previous patch - remove '_' from '_count_chars')
Should not change functional behavior and be simple to review.
Adds newly created function to lvm-string.h exports.


Index: LVM2/lib/misc/lvm-string.c
===================================================================
--- LVM2.orig/lib/misc/lvm-string.c	2007-04-20 10:31:14.000000000 -0400
+++ LVM2/lib/misc/lvm-string.c	2007-04-20 11:00:53.000000000 -0400
@@ -36,21 +36,6 @@ int emit_to_buffer(char **buffer, size_t
 }
 
 /*
- * Device layer names are all of the form <vg>-<lv>-<layer>, any
- * other hyphens that appear in these names are quoted with yet
- * another hyphen.  The top layer of any device has no layer
- * name.  eg, vg0-lvol0.
- */
-static void _count_hyphens(const char *str, size_t *len, int *hyphens)
-{
-	const char *ptr;
-
-	for (ptr = str; *ptr; ptr++, (*len)++)
-		if (*ptr == '-')
-			(*hyphens)++;
-}
-
-/*
  * Copies a string, quoting hyphens with hyphens.
  */
 static void _quote_hyphens(char **out, const char *src)
@@ -63,6 +48,17 @@ static void _quote_hyphens(char **out, c
 	}
 }
 
+
+void count_chars(const char *str, size_t *len, int *count,
+		  char c)
+{
+	const char *ptr;
+
+	for (ptr = str; *ptr; ptr++, (*len)++)
+		if (*ptr == c)
+			(*count)++;
+}
+
 /*
  * <vg>-<lv>-<layer> or if !layer just <vg>-<lv>.
  */
@@ -73,11 +69,11 @@ char *build_dm_name(struct dm_pool *mem,
 	int hyphens = 1;
 	char *r, *out;
 
-	_count_hyphens(vgname, &len, &hyphens);
-	_count_hyphens(lvname, &len, &hyphens);
+	count_chars(vgname, &len, &hyphens, '-');
+	count_chars(lvname, &len, &hyphens, '-');
 
 	if (layer && *layer) {
-		_count_hyphens(layer, &len, &hyphens);
+		count_chars(layer, &len, &hyphens, '-');
 		hyphens++;
 	}
 
@@ -105,6 +101,12 @@ char *build_dm_name(struct dm_pool *mem,
 	return r;
 }
 
+/*
+ * Device layer names are all of the form <vg>-<lv>-<layer>, any
+ * other hyphens that appear in these names are quoted with yet
+ * another hyphen.  The top layer of any device has no layer
+ * name.  eg, vg0-lvol0.
+ */
 int validate_name(const char *n)
 {
 	register char c;
Index: LVM2/lib/misc/lvm-string.h
===================================================================
--- LVM2.orig/lib/misc/lvm-string.h	2007-04-20 10:31:14.000000000 -0400
+++ LVM2/lib/misc/lvm-string.h	2007-04-20 11:01:06.000000000 -0400
@@ -30,4 +30,7 @@ char *build_dm_name(struct dm_pool *mem,
 
 int validate_name(const char *n);
 
+void count_chars(const char *str, size_t *len, int *count,
+		 char c);
+
 #endif
Index: LVM2/WHATS_NEW
===================================================================
--- LVM2.orig/WHATS_NEW	2007-04-20 10:31:14.000000000 -0400
+++ LVM2/WHATS_NEW	2007-04-20 11:05:29.000000000 -0400
@@ -1,5 +1,6 @@
 Version 2.02.25 -
 =================================
+  Convert _count_hyphens to generalized count_chars.
   Add dev_read_circular.
   Add pvck command stub.
   Update lists of attribute characters in man pages.




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

* [PATCH REPOST] convert _count_hyphens to generalised count_chars and export
  2007-04-20 15:06 ` [PATCH REPOST] convert _count_hyphens to generalised count_chars " Dave Wysochanski
@ 2007-04-20 17:17   ` Dave Wysochanski
  2007-04-23 18:57     ` [PATCH REPOST2] convert _count_hyphens to generalised count_chars_null " Dave Wysochanski
  0 siblings, 1 reply; 4+ messages in thread
From: Dave Wysochanski @ 2007-04-20 17:17 UTC (permalink / raw)
  To: lvm-devel

Yet another version (similar) of this patch is coming so don't bother
review at this point.

On Fri, 2007-04-20 at 11:06 -0400, Dave Wysochanski wrote:
> (NOTE: only change from previous patch - remove '_' from '_count_chars')
> Should not change functional behavior and be simple to review.
> Adds newly created function to lvm-string.h exports.
> 
> 
> Index: LVM2/lib/misc/lvm-string.c
> ===================================================================
> --- LVM2.orig/lib/misc/lvm-string.c	2007-04-20 10:31:14.000000000 -0400
> +++ LVM2/lib/misc/lvm-string.c	2007-04-20 11:00:53.000000000 -0400
> @@ -36,21 +36,6 @@ int emit_to_buffer(char **buffer, size_t
>  }
>  
>  /*
> - * Device layer names are all of the form <vg>-<lv>-<layer>, any
> - * other hyphens that appear in these names are quoted with yet
> - * another hyphen.  The top layer of any device has no layer
> - * name.  eg, vg0-lvol0.
> - */
> -static void _count_hyphens(const char *str, size_t *len, int *hyphens)
> -{
> -	const char *ptr;
> -
> -	for (ptr = str; *ptr; ptr++, (*len)++)
> -		if (*ptr == '-')
> -			(*hyphens)++;
> -}
> -
> -/*
>   * Copies a string, quoting hyphens with hyphens.
>   */
>  static void _quote_hyphens(char **out, const char *src)
> @@ -63,6 +48,17 @@ static void _quote_hyphens(char **out, c
>  	}
>  }
>  
> +
> +void count_chars(const char *str, size_t *len, int *count,
> +		  char c)
> +{
> +	const char *ptr;
> +
> +	for (ptr = str; *ptr; ptr++, (*len)++)
> +		if (*ptr == c)
> +			(*count)++;
> +}
> +
>  /*
>   * <vg>-<lv>-<layer> or if !layer just <vg>-<lv>.
>   */
> @@ -73,11 +69,11 @@ char *build_dm_name(struct dm_pool *mem,
>  	int hyphens = 1;
>  	char *r, *out;
>  
> -	_count_hyphens(vgname, &len, &hyphens);
> -	_count_hyphens(lvname, &len, &hyphens);
> +	count_chars(vgname, &len, &hyphens, '-');
> +	count_chars(lvname, &len, &hyphens, '-');
>  
>  	if (layer && *layer) {
> -		_count_hyphens(layer, &len, &hyphens);
> +		count_chars(layer, &len, &hyphens, '-');
>  		hyphens++;
>  	}
>  
> @@ -105,6 +101,12 @@ char *build_dm_name(struct dm_pool *mem,
>  	return r;
>  }
>  
> +/*
> + * Device layer names are all of the form <vg>-<lv>-<layer>, any
> + * other hyphens that appear in these names are quoted with yet
> + * another hyphen.  The top layer of any device has no layer
> + * name.  eg, vg0-lvol0.
> + */
>  int validate_name(const char *n)
>  {
>  	register char c;
> Index: LVM2/lib/misc/lvm-string.h
> ===================================================================
> --- LVM2.orig/lib/misc/lvm-string.h	2007-04-20 10:31:14.000000000 -0400
> +++ LVM2/lib/misc/lvm-string.h	2007-04-20 11:01:06.000000000 -0400
> @@ -30,4 +30,7 @@ char *build_dm_name(struct dm_pool *mem,
>  
>  int validate_name(const char *n);
>  
> +void count_chars(const char *str, size_t *len, int *count,
> +		 char c);
> +
>  #endif
> Index: LVM2/WHATS_NEW
> ===================================================================
> --- LVM2.orig/WHATS_NEW	2007-04-20 10:31:14.000000000 -0400
> +++ LVM2/WHATS_NEW	2007-04-20 11:05:29.000000000 -0400
> @@ -1,5 +1,6 @@
>  Version 2.02.25 -
>  =================================
> +  Convert _count_hyphens to generalized count_chars.
>    Add dev_read_circular.
>    Add pvck command stub.
>    Update lists of attribute characters in man pages.
> 
> 
> --
> lvm-devel mailing list
> lvm-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/lvm-devel



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

* [PATCH REPOST2] convert _count_hyphens to generalised count_chars_null and export
  2007-04-20 17:17   ` Dave Wysochanski
@ 2007-04-23 18:57     ` Dave Wysochanski
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Wysochanski @ 2007-04-23 18:57 UTC (permalink / raw)
  To: lvm-devel

Add count_chars_null and count_chars_len functions, two
generic string utility functions.

Index: LVM2-working2/lib/misc/lvm-string.c
===================================================================
--- LVM2-working2.orig/lib/misc/lvm-string.c	2006-08-21 08:54:53.000000000 -0400
+++ LVM2-working2/lib/misc/lvm-string.c	2007-04-23 14:48:56.000000000 -0400
@@ -36,18 +36,38 @@ int emit_to_buffer(char **buffer, size_t
 }
 
 /*
- * Device layer names are all of the form <vg>-<lv>-<layer>, any
- * other hyphens that appear in these names are quoted with yet
- * another hyphen.  The top layer of any device has no layer
- * name.  eg, vg0-lvol0.
+ * Count occurences of 'c' in 'str' until we reach a null char.
+ *
+ * Returns:
+ *  len - incremented for each char we encounter, whether 'c' or not.
+ *  count - number of occurences of 'c'
  */
-static void _count_hyphens(const char *str, size_t *len, int *hyphens)
+void count_chars_null(const char *str, size_t *len, int *count,
+		      char c)
 {
 	const char *ptr;
 
 	for (ptr = str; *ptr; ptr++, (*len)++)
-		if (*ptr == '-')
-			(*hyphens)++;
+		if (*ptr == c)
+			(*count)++;
+}
+
+/*
+ * Count occurences of 'c' in 'str' of length 'size'.
+ *
+ * Returns:
+ *   # of occurences of 'c'
+ */
+unsigned count_chars_len(const char *str, size_t size, char c)
+{
+	int i;
+	unsigned count=0;
+
+	for (i=0; i<size; i++)
+		if (str[i] == c)
+			count++;
+	return count;
+
 }
 
 /*
@@ -73,11 +93,11 @@ char *build_dm_name(struct dm_pool *mem,
 	int hyphens = 1;
 	char *r, *out;
 
-	_count_hyphens(vgname, &len, &hyphens);
-	_count_hyphens(lvname, &len, &hyphens);
+	count_chars_null(vgname, &len, &hyphens, '-');
+	count_chars_null(lvname, &len, &hyphens, '-');
 
 	if (layer && *layer) {
-		_count_hyphens(layer, &len, &hyphens);
+		count_chars_null(layer, &len, &hyphens, '-');
 		hyphens++;
 	}
 
@@ -105,6 +125,12 @@ char *build_dm_name(struct dm_pool *mem,
 	return r;
 }
 
+/*
+ * Device layer names are all of the form <vg>-<lv>-<layer>, any
+ * other hyphens that appear in these names are quoted with yet
+ * another hyphen.  The top layer of any device has no layer
+ * name.  eg, vg0-lvol0.
+ */
 int validate_name(const char *n)
 {
 	register char c;
Index: LVM2-working2/lib/misc/lvm-string.h
===================================================================
--- LVM2-working2.orig/lib/misc/lvm-string.h	2006-08-21 08:54:53.000000000 -0400
+++ LVM2-working2/lib/misc/lvm-string.h	2007-04-23 14:38:45.000000000 -0400
@@ -30,4 +30,8 @@ char *build_dm_name(struct dm_pool *mem,
 
 int validate_name(const char *n);
 
+void count_chars_null(const char *str, size_t *len, int *count,
+		      char c);
+unsigned count_chars_len(const char *str, size_t size, char c);
+
 #endif
Index: LVM2-working2/WHATS_NEW
===================================================================
--- LVM2-working2.orig/WHATS_NEW	2007-04-23 14:21:01.000000000 -0400
+++ LVM2-working2/WHATS_NEW	2007-04-23 14:41:22.000000000 -0400
@@ -1,5 +1,6 @@
 Version 2.02.25 -
 =================================
+  Add count_chars_null and count_chars_len functions.
   Add scan_sector param to label_read and _find_labeller.
   Make clvmd cope with quorum devices on RHEL5
   Add dev_read_circular.




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

end of thread, other threads:[~2007-04-23 18:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-20 14:37 [PATCH] convert _count_hyphens to generalised _count_chars and export Dave Wysochanski
2007-04-20 15:06 ` [PATCH REPOST] convert _count_hyphens to generalised count_chars " Dave Wysochanski
2007-04-20 17:17   ` Dave Wysochanski
2007-04-23 18:57     ` [PATCH REPOST2] convert _count_hyphens to generalised count_chars_null " Dave Wysochanski

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.