]> granicus.if.org Git - libnl/commitdiff
Export nl_dump_line() and automatically count lines while dumping
authorThomas Graf <tgr@lsx.localdomain>
Tue, 29 Apr 2008 21:08:12 +0000 (23:08 +0200)
committerThomas Graf <tgr@lsx.localdomain>
Tue, 29 Apr 2008 21:08:12 +0000 (23:08 +0200)
include/netlink-local.h
include/netlink/types.h
include/netlink/utils.h
lib/utils.c

index f3b971a05e372b5c509950aa43927a135b4097a9..10619ace40ff8ce42939efaee3a78ed83e558e8a 100644 (file)
@@ -119,7 +119,7 @@ static inline int __assert_error(const char *file, int line, char *func,
 #define nl_errno(E)    nl_error(E, NULL)
 
 /* backwards compat */
-#define dp_new_line(params, line)      nl_new_line(params, line)
+#define dp_new_line(params, line)      nl_new_line(params)
 #define dp_dump(params, fmt, arg...)   nl_dump(params, fmt, ##arg)
 
 static inline int __trans_list_add(int i, const char *a,
@@ -284,17 +284,7 @@ static inline void __dp_dump(struct nl_dump_params *parms, const char *fmt,
        }
 }
 
-static inline void dp_dump_line(struct nl_dump_params *parms, int line,
-                               const char *fmt, ...)
-{
-       va_list args;
-
-       nl_new_line(parms, line);
-
-       va_start(args, fmt);
-       __dp_dump(parms, fmt, args);
-       va_end(args);
-}
+#define dp_dump_line(params, line, fmt, arg...)        nl_dump_line(params, fmt, ##arg)
 
 static inline void dump_from_ops(struct nl_object *obj,
                                 struct nl_dump_params *params)
@@ -304,6 +294,8 @@ static inline void dump_from_ops(struct nl_object *obj,
        if (type < 0 || type > NL_DUMP_MAX)
                BUG();
 
+       params->dp_line = 0;
+
        if (params->dp_dump_msgtype) {
 #if 0
                /* XXX */
@@ -317,7 +309,7 @@ static inline void dump_from_ops(struct nl_object *obj,
 #endif
                params->dp_pre_dump = 1;
        } else
-               dp_new_line(params, 0);
+               nl_new_line(params);
 
        if (obj->ce_ops->oo_dump[type])
                obj->ce_ops->oo_dump[type](obj, params);
index 903028e3478f0505f22e80d3639cc15283d056ea..04209b6b0d8e8443b50fb978d94e484e44184ac4 100644 (file)
  * @ingroup utils
  */
 enum nl_dump_type {
-       NL_DUMP_BRIEF,          /**< Dump object in a brief one-liner */
-       NL_DUMP_FULL,           /**< Dump all attributes but no statistics */
+       NL_DUMP_ONELINE,        /**< Dump object briefly on one line */
+       NL_DUMP_DETAILS,        /**< Dump all attributes but no statistics */
        NL_DUMP_STATS,          /**< Dump all attributes including statistics */
        NL_DUMP_XML,            /**< Dump all attribtes in XML format */
        NL_DUMP_ENV,            /**< Dump all attribtues as env variables */
-       NL_DUMP_EVENTS,         /**< Dump event */
        __NL_DUMP_MAX,
 };
 #define NL_DUMP_MAX (__NL_DUMP_MAX - 1)
 
+/* backards compat */
+#define NL_DUMP_BRIEF NL_DUMP_ONELINE
+#define NL_DUMP_FULL NL_DUMP_DETAILS
+
 /**
  * Dumping parameters
  * @ingroup utils
@@ -100,6 +103,14 @@ struct nl_dump_params
         * Set if a dump was performed prior to the actual dump handler.
         */
        int                     dp_pre_dump;
+
+       /**
+        * PRIVATE
+        * Owned by the current caller
+        */
+       int                     dp_ivar;
+
+       unsigned int            dp_line;
 };
 
 #endif
index 0351d3866cf8f08a94c991890e14de61c75611a3..207e8ec3e895b8b5b795221e73c31248f5bdd861 100644 (file)
@@ -70,9 +70,9 @@ extern char * nl_ip_proto2str(int, char *, size_t);
 extern int     nl_str2ip_proto(const char *);
 
 /* Dumping helpers */
-extern void    nl_new_line(struct nl_dump_params *, int);
+extern void    nl_new_line(struct nl_dump_params *);
 extern void    nl_dump(struct nl_dump_params *, const char *, ...);
-extern void    nl_dump_line(struct nl_dump_params *, int, const char *, ...);
+extern void    nl_dump_line(struct nl_dump_params *, const char *, ...);
 
 #ifdef __cplusplus
 }
index b5b457af04794d40505a2894d7207424b2099c14..db11fb8cecba9611587faf42b9884b755117b348 100644 (file)
@@ -147,7 +147,7 @@ char *nl_geterror(void)
        if (nlerrno)
                return strerror(nlerrno);
 
-       return "Sucess\n";
+       return "Success\n";
 }
 
 /**
@@ -714,7 +714,6 @@ int nl_str2ip_proto(const char *name)
 /**
  * Handle a new line while dumping
  * @arg params         Dumping parameters
- * @arg line           Number of lines dumped already.
  *
  * This function must be called before dumping any onto a
  * new line. It will ensure proper prefixing as specified
@@ -722,8 +721,10 @@ int nl_str2ip_proto(const char *name)
  *
  * @note This function will NOT dump any newlines itself
  */
-void nl_new_line(struct nl_dump_params *params, int line)
+void nl_new_line(struct nl_dump_params *params)
 {
+       params->dp_line++;
+
        if (params->dp_prefix) {
                int i;
                for (i = 0; i < params->dp_prefix; i++) {
@@ -737,7 +738,7 @@ void nl_new_line(struct nl_dump_params *params, int line)
        }
 
        if (params->dp_nl_cb)
-               params->dp_nl_cb(params, line);
+               params->dp_nl_cb(params, params->dp_line);
 }
 
 /**
@@ -758,6 +759,18 @@ void nl_dump(struct nl_dump_params *params, const char *fmt, ...)
        va_end(args);
 }
 
+void nl_dump_line(struct nl_dump_params *parms, const char *fmt, ...)
+{
+       va_list args;
+
+       nl_new_line(parms);
+
+       va_start(args, fmt);
+       __dp_dump(parms, fmt, args);
+       va_end(args);
+}
+
+
 /** @} */
 
 /** @} */