commit-inetutils
[Top][All Lists]
Advanced

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

[SCM] GNU Inetutils branch, master, updated. inetutils-1_7-34-ge6013a6


From: Sergey Poznyakoff
Subject: [SCM] GNU Inetutils branch, master, updated. inetutils-1_7-34-ge6013a6
Date: Mon, 08 Feb 2010 20:38:39 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Inetutils ".

The branch, master has been updated
       via  e6013a6e9a42c4b3af939b2eb0811083ea713ddf (commit)
      from  1c9891407d45e3214d8a47273f28c33856f7ad62 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=e6013a6e9a42c4b3af939b2eb0811083ea713ddf


commit e6013a6e9a42c4b3af939b2eb0811083ea713ddf
Author: Sergey Poznyakoff <address@hidden>
Date:   Mon Feb 8 22:38:58 2010 +0200

    Ifconfig: add more format functions; implement --format=help.
    
    * ifconfig/if_index.c (if_nametoindex): Fix return value.
    * ifconfig/ifconfig.c (main): Rewrite loop.
    * ifconfig/options.c (formats): Add docstrings.
    Add "help" format.
    (format_find): New function.
    * ifconfig/options.h (format)<docstr>: New member.
    (format_find): New prototype.
    * ifconfig/printif.c (format_handles): New functions:
    format?, docstr?, defn, foreachformat, verbose?, rep.
    (put_flags): Minor change.
    (format_handler, fh_exists_query, fh_error): Rewrite the loop.
    (fh_format_query, fh_docstr)
    (fh_defn, fh_foreachformat)
    (fh_rep, fh_verbose_query): New functions.
    (fh_format): Rewrite using format_find.
    * ifconfig/printif.h (fh_format_query, fh_docstr)
    (fh_defn, fh_foreachformat)
    (fh_rep, fh_verbose_query): New prototypes.
    * NEWS: Update.

diff --git a/ChangeLog b/ChangeLog
index 7d3d83b..4a6bc2f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,29 @@
 2010-02-08  Sergey Poznyakoff  <address@hidden>
 
+       Ifconfig: add more format functions; implement --format=help.
+
+       * ifconfig/if_index.c (if_nametoindex): Fix return value.
+       * ifconfig/ifconfig.c (main): Rewrite loop.
+       * ifconfig/options.c (formats): Add docstrings.
+       Add "help" format.
+       (format_find): New function.
+       * ifconfig/options.h (format)<docstr>: New member.
+       (format_find): New prototype.
+       * ifconfig/printif.c (format_handles): New functions:
+       format?, docstr?, defn, foreachformat, verbose?, rep.
+       (put_flags): Minor change.
+       (format_handler, fh_exists_query, fh_error): Rewrite the loop.
+       (fh_format_query, fh_docstr)
+       (fh_defn, fh_foreachformat)
+       (fh_rep, fh_verbose_query): New functions.
+       (fh_format): Rewrite using format_find.
+       * ifconfig/printif.h (fh_format_query, fh_docstr)
+       (fh_defn, fh_foreachformat)
+       (fh_rep, fh_verbose_query): New prototypes.
+       * NEWS: Update.
+
+2010-02-08  Sergey Poznyakoff  <address@hidden>
+
        Ifconfig: read format from files and implement the -s option.
 
        * ifconfig/flags.c (if_format_flags): Rename to if_list_flags.
diff --git a/NEWS b/NEWS
index db0416e..28e72fb 100644
--- a/NEWS
+++ b/NEWS
@@ -38,6 +38,13 @@ The contents of this file is read literally, except that the 
lines
 beginning with a `#' sign are ignored (and can thus be used to introduce
 comments).
 
+To obtain a list of the available built-in output formats, use
+
+         ifconfig --format=help
+
+When used with the --verbose option, --format=help also displays
+format definitions.
+
 * Man pages for the daemons are now in section 8 instead of 1.
 
 * There is now a man page for ping6 too.
diff --git a/ifconfig/if_index.c b/ifconfig/if_index.c
index 1baa1ea..e2737c2 100644
--- a/ifconfig/if_index.c
+++ b/ifconfig/if_index.c
@@ -49,12 +49,13 @@ if_nametoindex (const char *ifname)
     int fd = socket (AF_INET, SOCK_DGRAM, 0);
     if (fd >= 0)
       {
+       int rc;
        struct ifreq ifr;
        strncpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
        ifr.ifr_name[IFNAMSIZ - 1] = '\0';
-       result = ioctl (fd, SIOCGIFINDEX, &ifr);
+       rc = ioctl (fd, SIOCGIFINDEX, &ifr);
        close (fd);
-       if (result == 0)
+       if (rc == 0)
          return ifr.ifr_index;
       }
   }
diff --git a/ifconfig/ifconfig.c b/ifconfig/ifconfig.c
index 988355a..28a1d69 100644
--- a/ifconfig/ifconfig.c
+++ b/ifconfig/ifconfig.c
@@ -69,15 +69,13 @@ main (int argc, char *argv[])
       exit (1);
     }
 
-  ifp = ifs;
-  while (ifp - ifs < nifs)
+  for (ifp = ifs; ifp < ifs + nifs; ifp++)
     {
       err = configure_if (sfd, ifp);
       if (err)
        break;
-      ifp++;
     }
 
   close (sfd);
-  return (err);
+  return err;
 }
diff --git a/ifconfig/options.c b/ifconfig/options.c
index 273f1c8..1d46dbc 100644
--- a/ifconfig/options.c
+++ b/ifconfig/options.c
@@ -62,10 +62,15 @@ static struct ifconfig ifconfig_initializer = {
 struct format formats[] = {
   /* This is the default output format if no system_default_format is
      specified.  */
-  {"default", "${format}{gnu}"},
+  {"default",
+   "Default format.  Equivalent to \"gnu\".",
+   "${format}{gnu}"},
   /* This is the standard GNU output.  */
-  {"gnu", "${first?}{}{${\\n}}${format}{gnu-one-entry}"},
+  {"gnu",
+   "Standard GNU output format.",
+   "${first?}{}{${\\n}}${format}{gnu-one-entry}"},
   {"gnu-one-entry",
+   "Same as GNU, but without additional newlines between the entries.",
    "${format}{check-existence}"
    "${ifdisplay?}{"
    "${name} (${index}):${\\n}"
@@ -83,6 +88,7 @@ struct format formats[] = {
   },
   /* Resembles the output of ifconfig 1.39 (1999-03-19) in net-tools 1.52.  */
   {"net-tools",
+   "Similar to the output of net-tools.  Default for GNU/Linux.",
    "${format}{check-existence}"
    "${ifdisplay?}{"
    "${name}${exists?}{hwtype?}{${hwtype?}{${tab}{10}Link encap:${hwtype}}"
@@ -122,6 +128,7 @@ struct format formats[] = {
    "}"
   },
   {"netstat",
+   "Terse output, similar to that of \"netstat -i\".",
    "${first?}{Iface    MTU Met    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR 
TX-DRP TX-OVR Flg${newline}}"
    "${format}{check-existence}"
    "${name}${tab}{6}${mtu}{%6d} ${metric}{%3d}"
@@ -135,6 +142,7 @@ struct format formats[] = {
   /* Resembles the output of ifconfig shipped with unix systems like
      Solaris 2.7 or HPUX 10.20.  */
   {"unix",
+   "Traditional UNIX interface listing.  Default for Solaris and HPUX.",
    "${format}{check-existence}"
    "${ifdisplay?}{"
    "${name}: flags=${flags}{number}<${flags}{string}{,}>"
@@ -149,6 +157,7 @@ struct format formats[] = {
   },
   /* Resembles the output of ifconfig shipped with OSF 4.0g.  */
   {"osf",
+   "OSF-style output.",
    "${format}{check-existence}"
    "${ifdisplay?}{"
    "${name}: flags=${flags}{number}{%x}<${flags}{string}{,}>${\\n}"
@@ -160,9 +169,24 @@ struct format formats[] = {
   },
   /* If interface does not exist, print error message and exit. */
   {"check-existence",
+   "If interface does not exist, print error message and exit.",
    "${index?}{}"
    "{${error}{${progname}: error: interface `${name}' does not exist${\\n}}"
    "${exit}{1}}"},
+  {"help",
+   "Display this help output.",
+   "${foreachformat}{"
+   "${name}:${tab}{17}${docstr}"
+   "${verbose?}{"
+   "${newline}"
+   "${rep}{79}{-}"
+   "${newline}"
+   "${defn}"
+   "${newline}"
+   "}"
+   "${newline}"
+   "}"
+   "${exit}{0}"},
   {0, 0}
 };
 
@@ -221,6 +245,19 @@ const char *program_authors[] =
     NULL
   };
 
+struct format *
+format_find (const char *name)
+{
+  struct format *frm;
+
+  for (frm = formats; frm->name; frm++)
+    {
+      if (strcmp (frm->name, name) == 0)
+       return frm;
+    }
+  return NULL;
+}
+
 struct ifconfig *
 parse_opt_new_ifs (char *name)
 {
diff --git a/ifconfig/options.h b/ifconfig/options.h
index 5e2a6ab..7e403f5 100644
--- a/ifconfig/options.h
+++ b/ifconfig/options.h
@@ -57,6 +57,7 @@ struct ifconfig
 struct format
 {
   const char *name;
+  const char *docstr;
   const char *templ;
 };
 
@@ -72,6 +73,7 @@ extern int nifs;
 extern int verbose;
 
 void usage (int err);
+struct format *format_find (const char *name);
 void parse_opt_set_address (struct ifconfig *ifp, char *addr);
 void parse_opt_set_brdaddr (struct ifconfig *ifp, char *addr);
 void parse_opt_set_dstaddr (struct ifconfig *ifp, char *addr);
diff --git a/ifconfig/printif.c b/ifconfig/printif.c
index f283d1e..d3278af 100644
--- a/ifconfig/printif.c
+++ b/ifconfig/printif.c
@@ -65,9 +65,15 @@ struct format_handle format_handles[] = {
   SYSTEM_FORMAT_HANDLER
 #endif
   {"", fh_nothing},
+  {"format?", fh_format_query},
+  {"docstr", fh_docstr},
+  {"defn", fh_defn},
+  {"foreachformat", fh_foreachformat},
+  {"verbose?", fh_verbose_query},
   {"newline", fh_newline},
   {"\\n", fh_newline},
   {"\\t", fh_tabulator},
+  {"rep", fh_rep},
   {"first?", fh_first},
   {"ifdisplay?", fh_ifdisplay_query},
   {"tab", fh_tab},
@@ -304,7 +310,7 @@ put_flags (format_data_t form, int argc, char *argv[], 
short flags)
     {
       if (f & flags)
        {
-         name = if_flagtoname (f, "" /* XXX: avoid */ );
+         name = if_flagtoname (f, NULL);
          if (name)
            {
              if (!first)
@@ -348,24 +354,21 @@ void
 format_handler (const char *name, format_data_t form, int argc, char *argv[])
 {
   struct format_handle *fh;
-  fh = format_handles;
 
-  while (fh->name != NULL)
+  for (fh = format_handles; fh->name; fh++)
     {
       if (!strcmp (fh->name, name))
-       break;
-      fh++;
+       {
+         if (fh->handler)
+           (fh->handler) (form, argc, argv);
+         return;
+       }
     }
 
-  if (fh->handler)
-    (fh->handler) (form, argc, argv);
-  else
-    {
-      *column += printf ("(");
-      put_string (form, name);
-      *column += printf (" unknown)");
-      had_output = 1;
-    }
+  *column += printf ("(");
+  put_string (form, name);
+  *column += printf (" unknown)");
+  had_output = 1;
 }
 
 void
@@ -374,6 +377,60 @@ fh_nothing (format_data_t form, int argc, char *argv[])
 }
 
 void
+fh_format_query (format_data_t form, int argc, char *argv[])
+{
+  if (argc < 1)
+    return;
+  select_arg (form, argc, argv, format_find (argv[0]) ? 1 : 2);
+}
+
+void
+fh_docstr (format_data_t form, int argc, char *argv[])
+{
+  const char *name;
+  struct format *frm;
+
+  name = (argc == 0) ? form->name : argv[0];
+  frm = format_find (name);
+  if (!frm)
+    error (EXIT_FAILURE, errno, "unknown format: `%s'", name);
+  put_string (form, frm->docstr);
+}
+
+void
+fh_defn (format_data_t form, int argc, char *argv[])
+{
+  const char *name;
+  struct format *frm;
+
+  name = (argc == 0) ? form->name : argv[0];
+
+  frm = format_find (name);
+  if (!frm)
+    error (EXIT_FAILURE, errno, "unknown format: `%s'", name);
+  put_string (form, frm->templ);
+}
+
+void
+fh_foreachformat (format_data_t form, int argc, char *argv[])
+{
+  struct format *frm;
+  const char *save_name;
+
+  if (argc == 0)
+    return;
+
+  save_name = form->name;
+  for (frm = formats; frm->name; frm++)
+    {
+      form->name = frm->name;
+      form->format = argv[0];
+      print_interfaceX (form, 0);
+    }
+  form->name = save_name;
+}
+
+void
 fh_newline (format_data_t form, int argc, char *argv[])
 {
   put_char (form, '\n');
@@ -386,6 +443,24 @@ fh_tabulator (format_data_t form, int argc, char *argv[])
 }
 
 void
+fh_rep (format_data_t form, int argc, char *argv[])
+{
+  unsigned int count;
+  char *p;
+
+  if (argc < 2)
+    return;
+  count = strtoul (argv[0], &p, 10);
+  if (*p)
+    error (EXIT_FAILURE, 0, "invalid repeat count");
+  while (count--)
+    {
+      form->format = argv[1];
+      print_interfaceX (form, 0);
+    }
+}
+
+void
 fh_first (format_data_t form, int argc, char *argv[])
 {
   select_arg (form, argc, argv, form->first ? 0 : 1);
@@ -410,6 +485,12 @@ fh_ifdisplay_query (format_data_t form, int argc, char 
*argv[])
   select_arg (form, argc, argv, n);
 }
 
+void
+fh_verbose_query (format_data_t form, int argc, char *argv[])
+{
+  select_arg (form, argc, argv, verbose ? 0 : 1);
+}
+
 /* A tab implementation, which fills with spaces up to requested column or next
    tabstop.  */
 void
@@ -456,34 +537,33 @@ fh_join (format_data_t form, int argc, char *argv[])
 void
 fh_exists_query (format_data_t form, int argc, char *argv[])
 {
-  struct format_handle *fh;
-  fh = format_handles;
-
   if (argc > 0)
     {
-      while (fh->name != NULL)
+      struct format_handle *fh;
+      int sel = 2; /* assume 2nd arg by default */
+
+      for (fh = format_handles; fh->name; fh++)
        {
          if (!strcmp (fh->name, argv[0]))
-           break;
-         fh++;
+           {
+             sel = 1; /* select 1st argument */
+             break;
+           }
        }
-      select_arg (form, argc, argv, (fh->name != NULL) ? 1 : 2);
+      select_arg (form, argc, argv, sel);
     }
 }
 
 void
 fh_format (format_data_t form, int argc, char *argv[])
 {
-  int i = 0;
+  int i;
 
-  while (i < argc)
+  for (i = 0; i < argc; i++)
     {
-      struct format *frm = formats;
-
-      while (frm->name && strcmp (argv[i], frm->name))
-       frm++;
+      struct format *frm = format_find (argv[i]);
 
-      if (frm->name)
+      if (frm)
        {
          /* XXX: Avoid infinite recursion by appending name to a list
             during the next call (but removing it afterwards, and
@@ -491,22 +571,22 @@ fh_format (format_data_t form, int argc, char *argv[])
             already.  */
          form->format = frm->templ;
          print_interfaceX (form, 0);
+         break;
        }
-      i++;
     }
 }
 
 void
 fh_error (format_data_t form, int argc, char *argv[])
 {
-  int i = 0;
+  int i;
   FILE *s = ostream;
   int *c = column;
 
   ostream = stderr;
   column = &column_stderr;
-  while (i < argc)
-    select_arg (form, argc, argv, i++);
+  for (i = 0; i < argc; i++)
+    select_arg (form, argc, argv, i);
   ostream = s;
   column = c;
 }
diff --git a/ifconfig/printif.h b/ifconfig/printif.h
index b4391ce..fea738f 100644
--- a/ifconfig/printif.h
+++ b/ifconfig/printif.h
@@ -74,8 +74,14 @@ void format_handler (const char *name, format_data_t form, 
int argc,
                     char *argv[]);
 
 void fh_nothing (format_data_t form, int argc, char *argv[]);
+void fh_format_query (format_data_t form, int argc, char *argv[]);
+void fh_docstr (format_data_t form, int argc, char *argv[]);
+void fh_defn (format_data_t form, int argc, char *argv[]);
+void fh_foreachformat (format_data_t form, int argc, char *argv[]);
+void fh_verbose_query (format_data_t form, int argc, char *argv[]);
 void fh_newline (format_data_t form, int argc, char *argv[]);
 void fh_tabulator (format_data_t form, int argc, char *argv[]);
+void fh_rep (format_data_t form, int argc, char *argv[]);
 void fh_first (format_data_t form, int argc, char *argv[]);
 void fh_ifdisplay_query (format_data_t form, int argc, char *argv[]);
 void fh_tab (format_data_t form, int argc, char *argv[]);

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog           |   24 +++++++++
 NEWS                |    7 +++
 ifconfig/if_index.c |    5 +-
 ifconfig/ifconfig.c |    6 +--
 ifconfig/options.c  |   41 ++++++++++++++-
 ifconfig/options.h  |    2 +
 ifconfig/printif.c  |  144 +++++++++++++++++++++++++++++++++++++++-----------
 ifconfig/printif.h  |    6 ++
 8 files changed, 195 insertions(+), 40 deletions(-)


hooks/post-receive
-- 
GNU Inetutils 




reply via email to

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