Re: patch adding argz_add and argz_count implementation

2008-02-26 Thread Ralf Wildenhues
Hi Karl,

* Karl Berry wrote on Tue, Feb 26, 2008 at 06:11:34PM CET:
> Good, except that I'd prefer if argz_count used strlen instead of
> 
> Ok, since you prefer it, I copied the strlen loop from libc.  Below is a
> revised patch (for both files for convenience).

Thanks.  Applied as shown below.

> I'll change the name in Libtool after 2.2.  Maybe I'll even change it to
> use gnulib-tool ...
> 
> If you start maintaining the argz files with gnulib as the master,
> please tell me so I can stop syncing from libtool to gnulib :).

Sure.  FWIW I can also apply this to gnulib for you (I'm not sure if you
prefer to do that yourself).

Cheers,
Ralf

2008-02-26  Karl Berry  <[EMAIL PROTECTED]>

* libltdl/argz.c (argz_add, argz_count): New functions.
* libltdl/argz_.h: Declare them.
Report by Juan Manuel Guerrero <[EMAIL PROTECTED]>.

Index: libltdl/argz.c
===
RCS file: /cvsroot/libtool/libtool/libltdl/argz.c,v
retrieving revision 1.11
diff -u -r1.11 argz.c
--- libltdl/argz.c  25 Mar 2007 12:12:42 -  1.11
+++ libltdl/argz.c  26 Feb 2008 22:16:15 -
@@ -1,6 +1,6 @@
 /* argz.c -- argz implementation for non-glibc systems
 
-   Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
Written by Gary V. Vaughan, 2004
 
NOTE: The canonical source of this file is maintained with the
@@ -76,6 +76,14 @@
 }
 
 
+/* Add a string to the argz vector.  */
+error_t
+argz_add (char **pargz, size_t *pargz_len, const char *str)
+{
+  return argz_append (pargz, pargz_len, str, strlen (str) + 1);
+}
+
+
 error_t
 argz_create_sep (const char *str, int delim, char **pargz, size_t *pargz_len)
 {
@@ -223,3 +231,24 @@
}
 }
 }
+
+
+/* Count number of elements (null bytes) in argz vector.  */
+
+size_t
+argz_count (const char *argz, size_t argz_len)
+{
+  size_t count = 0;
+
+  assert ((argz && argz_len) || (!argz && !argz_len));
+  
+  while (argz_len > 0)
+{
+  size_t part_len = strlen (argz);
+  argz += part_len + 1;
+  argz_len -= part_len + 1;
+  count++;
+}
+  
+  return count;
+}
Index: libltdl/argz_.h
===
RCS file: /cvsroot/libtool/libtool/libltdl/argz_.h,v
retrieving revision 1.8
diff -u -r1.8 argz_.h
--- libltdl/argz_.h 25 Apr 2007 21:17:58 -  1.8
+++ libltdl/argz_.h 26 Feb 2008 22:16:15 -
@@ -1,6 +1,6 @@
 /* lt__argz.h -- internal argz interface for non-glibc systems
 
-   Copyright (C) 2004, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2007, 2008 Free Software Foundation, Inc.
Written by Gary V. Vaughan, 2004
 
NOTE: The canonical source of this file is maintained with the
@@ -49,6 +49,8 @@
 
 LT_SCOPE error_t argz_append   (char **pargz, size_t *pargz_len,
 const char *buf, size_t buf_len);
+LT_SCOPE error_t argz_add   (char **pargz, size_t *pargz_len,
+ const char *str);
 LT_SCOPE error_t argz_create_sep(const char *str, int delim,
 char **pargz, size_t *pargz_len);
 LT_SCOPE error_t argz_insert   (char **pargz, size_t *pargz_len,
@@ -56,6 +58,7 @@
 LT_SCOPE char * argz_next  (char *argz, size_t argz_len,
 const char *entry);
 LT_SCOPE void   argz_stringify (char *argz, size_t argz_len, int sep);
+LT_SCOPE size_t  argz_count (const char *argz, size_t argz_len);
 
 #if defined(__cplusplus)
 }


___
Bug-libtool mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-libtool


Re: patch adding argz_add and argz_count implementation

2008-02-26 Thread Karl Berry
Good, except that I'd prefer if argz_count used strlen instead of

Ok, since you prefer it, I copied the strlen loop from libc.  Below is a
revised patch (for both files for convenience).

I'll change the name in Libtool after 2.2.  Maybe I'll even change it to
use gnulib-tool ...

If you start maintaining the argz files with gnulib as the master,
please tell me so I can stop syncing from libtool to gnulib :).

Thanks,
karl


--- a/lib/argz_.h
+++ b/lib/argz_.h
@@ -1,6 +1,6 @@
 /* lt__argz.h -- internal argz interface for non-glibc systems
 
-   Copyright (C) 2004, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2007, 2008 Free Software Foundation, Inc.
Written by Gary V. Vaughan, 2004
 
NOTE: The canonical source of this file is maintained with the
@@ -49,6 +49,8 @@ extern "C" {
 
 LT_SCOPE error_t argz_append   (char **pargz, size_t *pargz_len,
 const char *buf, size_t buf_len);
+LT_SCOPE error_t argz_add   (char **pargz, size_t *pargz_len,
+ const char *str);
 LT_SCOPE error_t argz_create_sep(const char *str, int delim,
 char **pargz, size_t *pargz_len);
 LT_SCOPE error_t argz_insert   (char **pargz, size_t *pargz_len,
@@ -56,6 +58,7 @@ LT_SCOPE error_t argz_insert  (char **pargz, size_t 
*pargz_len,
 LT_SCOPE char * argz_next  (char *argz, size_t argz_len,
 const char *entry);
 LT_SCOPE void   argz_stringify (char *argz, size_t argz_len, int sep);
+LT_SCOPE size_t  argz_count (const char *argz, size_t argz_len);
 
 #if defined(__cplusplus)
 }
--- a/lib/argz.c
+++ b/lib/argz.c
@@ -1,6 +1,6 @@
 /* argz.c -- argz implementation for non-glibc systems
 
-   Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
Written by Gary V. Vaughan, 2004
 
NOTE: The canonical source of this file is maintained with the
@@ -76,6 +76,14 @@ argz_append (char **pargz, size_t *pargz_len, const char 
*buf, size_t buf_len)
 }
 
 
+/* Add a string to the argz vector.  */
+error_t
+argz_add (char **pargz, size_t *pargz_len, const char *str)
+{
+  return argz_append (pargz, pargz_len, str, strlen (str) + 1);
+}
+
+
 error_t
 argz_create_sep (const char *str, int delim, char **pargz, size_t *pargz_len)
 {
@@ -223,3 +231,24 @@ argz_stringify (char *argz, size_t argz_len, int sep)
}
 }
 }
+
+
+/* Count number of elements (null bytes) in argz vector.  */
+
+size_t
+argz_count (const char *argz, size_t argz_len)
+{
+  size_t count = 0;
+
+  assert ((argz && argz_len) || (!argz && !argz_len));
+  
+  while (argz_len > 0)
+{
+  size_t part_len = strlen (argz);
+  argz += part_len + 1;
+  argz_len -= part_len + 1;
+  count++;
+}
+  
+  return count;
+}


___
Bug-libtool mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-libtool


Re: patch adding argz_add and argz_count implementation

2008-02-25 Thread Ralf Wildenhues
Hi Karl,

* Karl Berry wrote on Mon, Feb 25, 2008 at 06:59:39PM CET:
> A Texinfo contributor made use of two argz functions that are not in the
> implementation in gnulib, argz_add and argz_count.  As a result, of
> course compilation failed on non-glibc systems.  They seemed trivial to
> implement, so here is a patch for argz.c and argz_.h.  How does it look?

Good, except that I'd prefer if argz_count used strlen instead of
walking the argz vector manually.  Little point in adding a suboptimal
algorithm if one can have speed (or smaller size) for free by using
a library function.

> Actually, the whole argz_.h vs argz.in.h thing is a bit confusing.  It
> seems like gnulib uses argz.in.h, but the libtool sources use argz_.h.
> I guess I should change the name when syncing from libtool to gnulib?
> Or maybe change the name in libtool?

I'll change the name in Libtool after 2.2.  Maybe I'll even change it to
use gnulib-tool ...

> P.S. I see in passing there are more argz functions not present, but
> since I didn't need them, I didn't do anything about them.  The code
> from libc/string/argz* could perhaps be used if the need ever arises.

Certainly.  

Cheers,
Ralf


___
Bug-libtool mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-libtool


patch adding argz_add and argz_count implementation

2008-02-25 Thread Karl Berry
A Texinfo contributor made use of two argz functions that are not in the
implementation in gnulib, argz_add and argz_count.  As a result, of
course compilation failed on non-glibc systems.  They seemed trivial to
implement, so here is a patch for argz.c and argz_.h.  How does it look?

Actually, the whole argz_.h vs argz.in.h thing is a bit confusing.  It
seems like gnulib uses argz.in.h, but the libtool sources use argz_.h.
I guess I should change the name when syncing from libtool to gnulib?
Or maybe change the name in libtool?

Thanks,
Karl

P.S. I see in passing there are more argz functions not present, but
since I didn't need them, I didn't do anything about them.  The code
from libc/string/argz* could perhaps be used if the need ever arises.


--- a/lib/argz.c
+++ b/lib/argz.c
@@ -1,6 +1,6 @@
 /* argz.c -- argz implementation for non-glibc systems
 
-   Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
Written by Gary V. Vaughan, 2004
 
NOTE: The canonical source of this file is maintained with the
@@ -76,6 +76,14 @@ argz_append (char **pargz, size_t *pargz_len, const char 
*buf, size_t buf_len)
 }
 
 
+/* Add a string to the argz vector.  */
+error_t
+argz_add (char **pargz, size_t *pargz_len, const char *str)
+{
+  return argz_append (pargz, pargz_len, str, strlen (str) + 1);
+}
+
+
 error_t
 argz_create_sep (const char *str, int delim, char **pargz, size_t *pargz_len)
 {
@@ -223,3 +231,22 @@ argz_stringify (char *argz, size_t argz_len, int sep)
}
 }
 }
+
+
+/* Count number of elements (null bytes) in argz vector.  */
+
+size_t
+argz_count (const char *argz, size_t argz_len)
+{
+  size_t count = 0;
+
+  assert ((argz && argz_len) || (!argz && !argz_len));
+  
+  while (--argz_len > 0)
+{
+  if (argz[argz_len] == EOS_CHAR)
+count++;
+}
+  
+  return count;
+}
--- a/lib/argz_.h
+++ b/lib/argz_.h
@@ -1,6 +1,6 @@
 /* lt__argz.h -- internal argz interface for non-glibc systems
 
-   Copyright (C) 2004, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2007, 2008 Free Software Foundation, Inc.
Written by Gary V. Vaughan, 2004
 
NOTE: The canonical source of this file is maintained with the
@@ -49,6 +49,8 @@ extern "C" {
 
 LT_SCOPE error_t argz_append   (char **pargz, size_t *pargz_len,
 const char *buf, size_t buf_len);
+LT_SCOPE error_t argz_add   (char **pargz, size_t *pargz_len,
+ const char *str);
 LT_SCOPE error_t argz_create_sep(const char *str, int delim,
 char **pargz, size_t *pargz_len);
 LT_SCOPE error_t argz_insert   (char **pargz, size_t *pargz_len,
@@ -56,6 +58,7 @@ LT_SCOPE error_t argz_insert  (char **pargz, size_t 
*pargz_len,
 LT_SCOPE char * argz_next  (char *argz, size_t argz_len,
 const char *entry);
 LT_SCOPE void   argz_stringify (char *argz, size_t argz_len, int sep);
+LT_SCOPE size_t  argz_count (const char *argz, size_t argz_len);
 
 #if defined(__cplusplus)
 }


___
Bug-libtool mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-libtool