]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: add vty_frame() to get rid of unneeded config
authorDavid Lamparter <equinox@diac24.net>
Fri, 5 Feb 2010 08:48:45 +0000 (09:48 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Tue, 29 Aug 2017 06:36:00 +0000 (08:36 +0200)
vty_frame() can be used to reduce the amount of output produced by "show
running-config" and "write ...".  It buffers output in struct vty->frame
(1024 bytes) and outputs it when vty_out is called.  If vty_out isn't
called, it can be removed with vty_endframe() later.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/vty.c
lib/vty.h

index 59a8825357b1989e63c8e546e8ab90f47581d588..1bd27cfa952e2c52bcefb6717799c33938fcc9f8 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -91,6 +91,25 @@ char integrate_default[] = SYSCONFDIR INTEGRATE_DEFAULT_CONFIG;
 
 static int do_log_commands = 0;
 
+void vty_frame(struct vty *vty, const char *format, ...)
+{
+       va_list args;
+
+       va_start(args, format);
+       vsnprintf(vty->frame + vty->frame_pos,
+                 sizeof(vty->frame) - vty->frame_pos,
+                 format, args);
+       vty->frame_pos = strlen(vty->frame);
+       va_end(args);
+}
+
+void vty_endframe(struct vty *vty, const char *endtext)
+{
+       if (vty->frame_pos == 0 && endtext)
+               vty_out(vty, "%s", endtext);
+       vty->frame_pos = 0;
+}
+
 /* VTY standard output function. */
 int vty_out(struct vty *vty, const char *format, ...)
 {
@@ -100,6 +119,11 @@ int vty_out(struct vty *vty, const char *format, ...)
        char buf[1024];
        char *p = NULL;
 
+       if (vty->frame_pos) {
+               vty->frame_pos = 0;
+               vty_out(vty, "%s", vty->frame);
+       }
+
        if (vty_shell(vty)) {
                va_start(args, format);
                vprintf(format, args);
index 9acd62af3cb1a6268cff82bef12495d42e2af73a..3b75afb02ceec496818ba1ee5ebd653b4c918555 100644 (file)
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -125,6 +125,12 @@ struct vty {
 
        /* What address is this vty comming from. */
        char address[SU_ADDRSTRLEN];
+
+       /* "frame" output.  This is buffered and will be printed if some
+        * actual output follows, or will be discarded if the frame ends
+        * without any output. */
+       size_t frame_pos;
+       char frame[1024];
 };
 
 static inline void vty_push_context(struct vty *vty, int node, uint64_t id)
@@ -247,7 +253,16 @@ extern void vty_terminate(void);
 extern void vty_reset(void);
 extern struct vty *vty_new(void);
 extern struct vty *vty_stdio(void (*atclose)(int isexit));
+
+/* - vty_frame() output goes to a buffer (for context-begin markers)
+ * - vty_out() will first print this buffer, and clear it
+ * - vty_endframe() clears the buffer without printing it, and prints an
+ *   extra string if the buffer was empty before (for context-end markers)
+ */
 extern int vty_out(struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
+extern void vty_frame(struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
+extern void vty_endframe(struct vty *, const char *);
+
 extern void vty_read_config(const char *, char *);
 extern void vty_time_print(struct vty *, int);
 extern void vty_serv_sock(const char *, unsigned short, const char *);