rdline: save return status before paging, and return it once finished
authorOlivier Matz <zer0@droids-corp.org>
Sun, 8 May 2011 16:02:09 +0000 (18:02 +0200)
committerOlivier Matz <zer0@droids-corp.org>
Sun, 8 May 2011 16:02:57 +0000 (18:02 +0200)
Signed-off-by: Olivier Matz <zer0@droids-corp.org>
src/lib/cmdline_rdline.c
src/lib/cmdline_rdline.h

index 5ff851b..4c746fa 100644 (file)
@@ -214,28 +214,30 @@ rdline_parse_char(struct rdline *rdl, char c)
 #ifndef NO_PAGER
        /* display asynchrounous printf if any */
        if (rdl->pager_buf != NULL) {
-               /* user ask to exit pager */
-               if (cmd == VT100_STD_CHAR && c == 'q') {
-                       rdline_asyncpager_reset(rdl);
-                       if (rdl->pager_cb != NULL) {
-                               rdl->pager_cb(rdl, rdl->pager_arg);
-                               rdl->pager_cb = NULL;
-                       }
-                       rdline_redisplay(rdl);
-                       return RDLINE_RES_SUCCESS;
-               }
 
-               /* last page is displayed */
-               else if (rdline_pager_next_page(rdl) == 0) {
+               /* user ask to exit pager, or last page is displayed*/
+               if ((cmd == VT100_STD_CHAR && c == 'q') ||
+                   rdline_pager_next_page(rdl) == 0) {
+                       int ret;
+
+                       ret = rdl->pager_ret;
                        rdline_asyncpager_reset(rdl);
                        if (rdl->pager_cb != NULL) {
                                rdl->pager_cb(rdl, rdl->pager_arg);
                                rdl->pager_cb = NULL;
                        }
+                       /* maybe the pager was reloaded in the
+                        * callback */
+                       if (rdl->pager_buf != NULL)
+                               return RDLINE_RES_SUCCESS;
+
+                       /* else, redisplay prompt and return the saved status */
                        rdline_redisplay(rdl);
+                       return ret;
                }
 
-               /* pages remain, async printf was called in cb() */
+               /* Some pages remain, lines were displayed in
+                * rdline_pager_next_page() */
                return RDLINE_RES_SUCCESS;
        }
 #endif
@@ -481,18 +483,23 @@ rdline_parse_char(struct rdline *rdl, char c)
 #endif
 
                        if (rdl->validate)
-                               rdl->validate(rdl, rdl->left_buf, CIRBUF_GET_LEN(&rdl->left)+2);
+                               rdl->validate(rdl, rdl->left_buf,
+                                             CIRBUF_GET_LEN(&rdl->left)+2);
 #ifndef NO_PAGER
                        /* user may have stopped rdline */
                        if (rdl->status == RDLINE_EXITED) {
                                rdline_asyncpager_reset(rdl);
                                return RDLINE_RES_EXITED;
                        }
-                       if (rdl->pager_buf != NULL)
+                       /* there is something in pager buffer, save
+                        * return value that will be return once
+                        * paging is finished */
+                       if (rdl->pager_buf != NULL) {
+                               rdl->pager_ret = RDLINE_RES_VALIDATED;
                                return RDLINE_RES_SUCCESS;
-                       else
-                               rdline_asyncpager_reset(rdl);
+                       }
 
+                       rdline_asyncpager_reset(rdl);
                        rdl->status = RDLINE_INIT;
 #else
                        if (rdl->status == RDLINE_EXITED)
@@ -786,6 +793,9 @@ rdline_asyncpager_reset(struct rdline *rdl)
        rdl->pager_lines = 0;
        rdl->pager_len = 0;
        rdl->pager_off = 0;
+       rdl->pager_cb = NULL;
+       rdl->pager_arg = NULL;
+       rdl->pager_ret = RDLINE_RES_SUCCESS;
 }
 
 /* Return the offset of the i-th occurence of char c in string s. If
index 152c8b5..bda4465 100644 (file)
@@ -155,8 +155,9 @@ struct rdline {
        int pager_len; /* total len of buffer */
        int pager_off; /* offset of next data */
        int pager_lines; /* number of lines displayed */
-       rdline_asyncpager_cb_t *pager_cb;
-       void *pager_arg;
+       rdline_asyncpager_cb_t *pager_cb; /* callback once paging is finished */
+       void *pager_arg; /* argument of callback */
+       int pager_ret; /* saved return value */
 #endif
 };