bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gnulib] Re: new module: getsubopt


From: Simon Josefsson
Subject: [Bug-gnulib] Re: new module: getsubopt
Date: Mon, 02 Aug 2004 10:46:39 +0200
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (gnu/linux)

I hope this addresses all issues.  I'll send an updated patch to
libc-alpha, once this discussion start to show up in the web archives,
so I can reference it.

Thanks.

2004-08-02  Simon Josefsson  <address@hidden>

        * MODULES.html.sh (Support for systems lacking POSIX:2001): Add
        getsubopt.

2004-08-01  Simon Josefsson  <address@hidden>

        * modules/getsubopt: New file.

2004-08-01  Simon Josefsson  <address@hidden>

        * getsubopt.h: New file.
        * getsubopt.c: New file, from glibc, but slightly modified based
        on suggestions from Paul Eggert <address@hidden>.

2004-08-01  Simon Josefsson  <address@hidden>

        * getsubopt.m4: New file.

Index: MODULES.html.sh
===================================================================
RCS file: /cvsroot/gnulib/gnulib/MODULES.html.sh,v
retrieving revision 1.54
diff -u -p -r1.54 MODULES.html.sh
--- MODULES.html.sh     22 Jun 2004 18:28:11 -0000      1.54
+++ MODULES.html.sh     2 Aug 2004 08:43:12 -0000
@@ -1702,6 +1702,7 @@ func_all_modules ()
   func_module getgroups
   func_module gethostname
   func_module gettimeofday
+  func_module getsubopt
   func_module mkdir
   func_module mkstemp
   func_module mkdtemp
Index: lib/getsubopt.c
===================================================================
RCS file: lib/getsubopt.c
diff -N lib/getsubopt.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/getsubopt.c     2 Aug 2004 08:43:13 -0000
@@ -0,0 +1,80 @@
+/* Parse comma separate list into words.
+   Copyright (C) 1996, 1997, 1999, 2004 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <address@hidden>, 1996.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <stdlib.h>
+#include <string.h>
+
+#if !_LIBC
+/* This code is written for inclusion in gnu-libc, and uses names in
+   the namespace reserved for libc.  If we're compiling in gnulib,
+   define those names to be the normal ones instead.  */
+# include "strchrnul.h"
+# undef __strchrnul
+# define __strchrnul strchrnul
+#endif
+
+/* Parse comma separated suboption from *OPTIONP and match against
+   strings in TOKENS.  If found return index and set *VALUEP to
+   optional value introduced by an equal sign.  If the suboption is
+   not part of TOKENS return in *VALUEP beginning of unknown
+   suboption.  On exit *OPTIONP is set to the beginning of the next
+   token or at the terminating NUL character.  */
+int
+getsubopt (char **optionp, char *const *tokens, char **valuep)
+{
+  char *endp, *vstart;
+  int cnt;
+
+  if (**optionp == '\0')
+    return -1;
+
+  /* Find end of next token.  */
+  endp = __strchrnul (*optionp, ',');
+
+  /* Find start of value.  */
+  vstart = memchr (*optionp, '=', endp - *optionp);
+  if (vstart == NULL)
+    vstart = endp;
+
+  /* Try to match the characters between *OPTIONP and VSTART against
+     one of the TOKENS.  */
+  for (cnt = 0; tokens[cnt] != NULL; ++cnt)
+    if (strncmp (*optionp, tokens[cnt], vstart - *optionp) == 0
+       && tokens[cnt][vstart - *optionp] == '\0')
+      {
+       /* We found the current option in TOKENS.  */
+       *valuep = vstart != endp ? vstart + 1 : NULL;
+
+       if (*endp != '\0')
+         *endp++ = '\0';
+       *optionp = endp;
+
+       return cnt;
+      }
+
+  /* The current suboption does not match any option.  */
+  *valuep = *optionp;
+
+  if (*endp != '\0')
+    *endp++ = '\0';
+  *optionp = endp;
+
+  return -1;
+}
Index: lib/getsubopt.h
===================================================================
RCS file: lib/getsubopt.h
diff -N lib/getsubopt.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/getsubopt.h     2 Aug 2004 08:43:13 -0000
@@ -0,0 +1,32 @@
+/* Parse comma separate list into words.
+   Copyright (C) 1996, 1997, 1999, 2004 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <address@hidden>, 1996.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#if HAVE_GETSUBOPT
+
+/* Get getsubopt declaration.  */
+#include <stdlib.h>
+
+#else
+
+extern int getsubopt (char **optionp,
+                     char *const *tokens,
+                     char **valuep);
+
+#endif
Index: m4/getsubopt.m4
===================================================================
RCS file: m4/getsubopt.m4
diff -N m4/getsubopt.m4
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ m4/getsubopt.m4     2 Aug 2004 08:43:14 -0000
@@ -0,0 +1,21 @@
+# getsubopt.m4 serial 1
+dnl Copyright (C) 2004 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License.  As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+AC_DEFUN([gl_FUNC_GETSUBOPT],
+[
+  dnl Persuade glibc <stdlib.h> to declare getsubopt().
+  AC_REQUIRE([AC_GNU_SOURCE])
+
+  AC_REPLACE_FUNCS(getsubopt)
+  if test $ac_cv_func_getsubopt = no; then
+    gl_PREREQ_GETSUBOPT
+  fi
+])
+
+# Prerequisites of lib/getsubopt.c.
+AC_DEFUN([gl_PREREQ_GETSUBOPT], [:])
Index: modules/getsubopt
===================================================================
RCS file: modules/getsubopt
diff -N modules/getsubopt
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ modules/getsubopt   2 Aug 2004 08:43:14 -0000
@@ -0,0 +1,22 @@
+Description:
+getsubopt: Parse comma separate list into words.
+
+Files:
+lib/getsubopt.h
+lib/getsubopt.c
+m4/getsubopt.m4
+
+Depends-on:
+strchrnul
+
+configure.ac:
+gl_FUNC_GETSUBOPT
+
+Makefile.am:
+lib_SOURCES += getsubopt.h
+
+Include:
+"getsubopt.h"
+
+Maintainer:
+all, glibc




reply via email to

[Prev in Thread] Current Thread [Next in Thread]