Tue Jul 2 10:44:37 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
authorroland <roland>
Tue, 2 Jul 1996 17:43:06 +0000 (17:43 +0000)
committerroland <roland>
Tue, 2 Jul 1996 17:43:06 +0000 (17:43 +0000)
* nss/nss_files/files-parse.c (LINE_PARSER): Take new first arg EOLSET.
Remove ; after `ENTDATA_DECL (data)'.
Truncate line at strpbrk (line, EOLSET "\n").
(ENTDATA_DECL): Put ; at end.
(MIDLINE_COMMENTS): Macro removed.
* nss/nss_files/files-ethers.c: Pass new argument.
* nss/nss_files/files-hosts.c: Likewise.
* nss/nss_files/files-network.c: Likewise.
* nss/nss_files/files-parse.c: Likewise.
* nss/nss_files/files-proto.c: Likewise.
* nss/nss_files/files-rpc.c: Likewise.
* nss/nss_files/files-service.c: Likewise.
* grp/fgetgrent.c: Likewise.
* pwd/fgetpwent.c: Likewise.
* nss/nss_files/files-pwd.c: Get parse_line with extern decl, since
fgetpwent.c already defines it.
* nss/nss_files/files-grp.c: Likewise.

grp/fgetgrent.c
nss/nss_files/files-ethers.c
nss/nss_files/files-grp.c
nss/nss_files/files-hosts.c
nss/nss_files/files-network.c
nss/nss_files/files-parse.c
nss/nss_files/files-proto.c
nss/nss_files/files-pwd.c
nss/nss_files/files-rpc.c
nss/nss_files/files-service.c

index aced929..38ccd15 100644 (file)
@@ -30,11 +30,11 @@ struct grent_data {};
 #define TRAILING_LIST_SEPARATOR_P(c)   ((c) == ',')
 #include "../nss/nss_files/files-parse.c"
 LINE_PARSER
-(
+(,
  STRING_FIELD (result->gr_name, ISCOLON, 0);
  STRING_FIELD (result->gr_passwd, ISCOLON, 0);
  INT_FIELD (result->gr_gid, ISCOLON, 0, 10,);
-)
+ )
 
 
 /* Read one entry from the given stream.  */
index e7579a4..b66a3c3 100644 (file)
@@ -33,8 +33,7 @@ struct etherent_data {};
 #define DATAFILE       "/etc/ethers"
 #include "files-parse.c"
 LINE_PARSER
-(
- MIDLINE_COMMENTS;
+("#",
  /* Read the ethernet address: 6 x 8bit hexadecimal number.  */
  {
    size_t cnt;
index 6d528a6..580dfbe 100644 (file)
@@ -27,12 +27,10 @@ struct grent_data {};
 #define TRAILING_LIST_MEMBER           gr_mem
 #define TRAILING_LIST_SEPARATOR_P(c)   ((c) == ',')
 #include "files-parse.c"
-LINE_PARSER
-(
- STRING_FIELD (result->gr_name, ISCOLON, 0);
- STRING_FIELD (result->gr_passwd, ISCOLON, 0);
- INT_FIELD (result->gr_gid, ISCOLON, 0, 10,);
-)
+/* Our parser function is already defined in fgetgrent.c, so use that.
+   to parse lines from the database file.  */
+extern int parse_line (char *line, struct STRUCTURE *result,
+                      void *buffer, int buflen);
 
 #include "files-XXX.c"
 
index 15f00f3..19a0075 100644 (file)
@@ -43,52 +43,53 @@ struct hostent_data
 #define TRAILING_LIST_SEPARATOR_P      isspace
 #include "files-parse.c"
 LINE_PARSER
-({
-  char *addr;
-
-  STRING_FIELD (addr, isspace, 1);
-
-  /* Parse address.  */
-  if ((_res.options & RES_USE_INET6)
-      && inet_pton (AF_INET6, addr, entdata->host_addr) > 0)
-    {
-      result->h_addrtype = AF_INET6;
-      result->h_length = IN6ADDRSZ;
-    }
-  else if (inet_pton (AF_INET, addr, entdata->host_addr) > 0)
-    {
-      if (_res.options & RES_USE_INET6)
-       {
-         map_v4v6_address ((char *) entdata->host_addr,
-                           (char *) entdata->host_addr);
-         result->h_addrtype = AF_INET6;
-         result->h_length = IN6ADDRSZ;
-       }
-      else
-       {
-         result->h_addrtype = AF_INET;
-         result->h_length = INADDRSZ;
-       }
-    }
-  else
-    /* Illegal address: ignore line.  */
-    return 0;
-
-  /* Store a pointer to the address in the expected form.  */
-  entdata->h_addr_ptrs[0] = entdata->host_addr;
-  entdata->h_addr_ptrs[1] = NULL;
-  result->h_addr_list = entdata->h_addr_ptrs;
-
-  /* If we need the host entry in IPv6 form change it now.  */
-  if (_res.options & RES_USE_INET6)
-    {
-      char *bufptr = data->linebuffer;
-      int buflen = (char *) data + datalen - bufptr;
-      map_v4v6_hostent (result, &bufptr, &buflen);
-    }
-
-  STRING_FIELD (result->h_name, isspace, 1);
-})
+("#",
+ {
+   char *addr;
+
+   STRING_FIELD (addr, isspace, 1);
+
+   /* Parse address.  */
+   if ((_res.options & RES_USE_INET6)
+       && inet_pton (AF_INET6, addr, entdata->host_addr) > 0)
+     {
+       result->h_addrtype = AF_INET6;
+       result->h_length = IN6ADDRSZ;
+     }
+   else if (inet_pton (AF_INET, addr, entdata->host_addr) > 0)
+     {
+       if (_res.options & RES_USE_INET6)
+        {
+          map_v4v6_address ((char *) entdata->host_addr,
+                            (char *) entdata->host_addr);
+          result->h_addrtype = AF_INET6;
+          result->h_length = IN6ADDRSZ;
+        }
+       else
+        {
+          result->h_addrtype = AF_INET;
+          result->h_length = INADDRSZ;
+        }
+     }
+   else
+     /* Illegal address: ignore line.  */
+     return 0;
+
+   /* Store a pointer to the address in the expected form.  */
+   entdata->h_addr_ptrs[0] = entdata->host_addr;
+   entdata->h_addr_ptrs[1] = NULL;
+   result->h_addr_list = entdata->h_addr_ptrs;
+
+   /* If we need the host entry in IPv6 form change it now.  */
+   if (_res.options & RES_USE_INET6)
+     {
+       char *bufptr = data->linebuffer;
+       int buflen = (char *) data + datalen - bufptr;
+       map_v4v6_hostent (result, &bufptr, &buflen);
+     }
+
+   STRING_FIELD (result->h_name, isspace, 1);
+ })
 
 #include "files-XXX.c"
 
index 504c420..c6cd718 100644 (file)
@@ -30,15 +30,16 @@ struct netent_data {};
 #define TRAILING_LIST_SEPARATOR_P      isspace
 #include "files-parse.c"
 LINE_PARSER
-({
-  char *addr;
+("#",
+ {
+   char *addr;
 
-  STRING_FIELD (result->n_name, isspace, 1);
+   STRING_FIELD (result->n_name, isspace, 1);
 
-  STRING_FIELD (addr, isspace, 1);
-  result->n_net = inet_network (addr);
+   STRING_FIELD (addr, isspace, 1);
+   result->n_net = inet_network (addr);
 
-})
+ })
 
 #include "files-XXX.c"
 
index be35ae1..a9c461e 100644 (file)
@@ -35,7 +35,7 @@ struct parser_data
   {
 #ifdef ENTDATA
     struct ENTDATA entdata;
-#define ENTDATA_DECL(data) struct ENTDATA *const entdata = &data->entdata
+#define ENTDATA_DECL(data) struct ENTDATA *const entdata = &data->entdata;
 #else
 #define ENTDATA_DECL(data)
 #endif
@@ -52,26 +52,21 @@ struct parser_data
 #define parse_line CONCAT(_nss_files_parse_,ENTNAME)
 #endif
 
-#define LINE_PARSER(BODY)                                                    \
+#define LINE_PARSER(EOLSET, BODY)                                            \
 parser_stclass int                                                           \
 parse_line (char *line, struct STRUCTURE *result,                            \
            struct parser_data *data, int datalen)                            \
 {                                                                            \
-  ENTDATA_DECL (data);                                                       \
+  ENTDATA_DECL (data)                                                        \
+  char *p = strpbrk (line, EOLSET "\n");                                     \
+  if (p)                                                                     \
+    *p = '\0';                                                               \
   BODY;                                                                              \
   TRAILING_LIST_PARSER;                                                              \
   return 1;                                                                  \
 }
 
 
-/* Comments can come mid-line; trim the line at the first # seen.  */
-#define MIDLINE_COMMENTS                                                     \
-  {                                                                          \
-    char *p = strchr (line, '#');                                            \
-    if (p)                                                                   \
-      *p = '\0';                                                             \
-  }
-
 #define STRING_FIELD(variable, terminator_p, swallow)                        \
   {                                                                          \
     variable = line;                                                         \
index d67f8db..ef5a7c2 100644 (file)
@@ -29,8 +29,7 @@ struct protoent_data {};
 #define TRAILING_LIST_SEPARATOR_P      isspace
 #include "files-parse.c"
 LINE_PARSER
-(
- MIDLINE_COMMENTS;
+("#",
  STRING_FIELD (result->p_name, isspace, 1);
  INT_FIELD (result->p_proto, isspace, 1, 10,);
  )
index 4b6a4b7..6b39116 100644 (file)
@@ -25,19 +25,10 @@ Cambridge, MA 02139, USA.  */
 struct pwent_data {};
 
 #include "files-parse.c"
-LINE_PARSER
-({
-  STRING_FIELD (result->pw_name, ISCOLON, 0);
-  STRING_FIELD (result->pw_passwd, ISCOLON, 0);
-  INT_FIELD (result->pw_uid, ISCOLON, 0, 10,);
-  INT_FIELD (result->pw_gid, ISCOLON, 0, 10,);
-  STRING_FIELD (result->pw_gecos, ISCOLON, 0);
-  STRING_FIELD (result->pw_dir, ISCOLON, 0);
-  result->pw_shell = line;
-  line = strchr (line, '\n');
-  if (line)
-    *line = '\0';
-})
+/* Our parser function is already defined in fgetpwent.c, so use that.
+   to parse lines from the database file.  */
+extern int parse_line (char *line, struct STRUCTURE *result,
+                      void *buffer, int buflen);
 
 #include "files-XXX.c"
 
index fef0ff8..f8bef45 100644 (file)
@@ -29,8 +29,7 @@ struct rpcent_data {};
 #define TRAILING_LIST_SEPARATOR_P      isspace
 #include "files-parse.c"
 LINE_PARSER
-(
- MIDLINE_COMMENTS;
+("#",
  STRING_FIELD (result->r_name, isspace, 1);
  INT_FIELD (result->r_number, isspace, 1, 10,);
  )
index 3bcb487..f0dba50 100644 (file)
@@ -31,8 +31,7 @@ struct servent_data {};
 #include "files-parse.c"
 #define ISSLASH(c) ((c) == '/')
 LINE_PARSER
-(
- MIDLINE_COMMENTS;
+("#",
  STRING_FIELD (result->s_name, isspace, 1);
  INT_FIELD (result->s_port, ISSLASH, 10, 0, htons);
  STRING_FIELD (result->s_proto, isspace, 1);