1 /* $OpenBSD: ex_display.c,v 1.13 2016/05/27 09:18:12 martijn Exp $ */ 2 3 /*- 4 * Copyright (c) 1992, 1993, 1994 5 * The Regents of the University of California. All rights reserved. 6 * Copyright (c) 1992, 1993, 1994, 1995, 1996 7 * Keith Bostic. All rights reserved. 8 * 9 * See the LICENSE file for redistribution information. 10 */ 11 12 #include "config.h" 13 14 #include <sys/types.h> 15 #include <sys/queue.h> 16 17 #include <bitstring.h> 18 #include <ctype.h> 19 #include <limits.h> 20 #include <stdio.h> 21 #include <string.h> 22 23 #include "../common/common.h" 24 #include "tag.h" 25 26 static int bdisplay(SCR *); 27 static void db(SCR *, CB *, CHAR_T *); 28 29 /* 30 * ex_display -- :display b[uffers] | s[creens] | t[ags] 31 * 32 * Display buffers, tags or screens. 33 * 34 * PUBLIC: int ex_display(SCR *, EXCMD *); 35 */ 36 int 37 ex_display(SCR *sp, EXCMD *cmdp) 38 { 39 switch (cmdp->argv[0]->bp[0]) { 40 case 'b': 41 #undef ARG 42 #define ARG "buffers" 43 if (cmdp->argv[0]->len >= sizeof(ARG) || 44 memcmp(cmdp->argv[0]->bp, ARG, cmdp->argv[0]->len)) 45 break; 46 return (bdisplay(sp)); 47 case 's': 48 #undef ARG 49 #define ARG "screens" 50 if (cmdp->argv[0]->len >= sizeof(ARG) || 51 memcmp(cmdp->argv[0]->bp, ARG, cmdp->argv[0]->len)) 52 break; 53 return (ex_sdisplay(sp)); 54 case 't': 55 #undef ARG 56 #define ARG "tags" 57 if (cmdp->argv[0]->len >= sizeof(ARG) || 58 memcmp(cmdp->argv[0]->bp, ARG, cmdp->argv[0]->len)) 59 break; 60 return (ex_tag_display(sp)); 61 } 62 ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE); 63 return (1); 64 } 65 66 /* 67 * bdisplay -- 68 * 69 * Display buffers. 70 */ 71 static int 72 bdisplay(SCR *sp) 73 { 74 CB *cbp; 75 76 if (LIST_FIRST(&sp->gp->cutq) == NULL && sp->gp->dcbp == NULL) { 77 msgq(sp, M_INFO, "No cut buffers to display"); 78 return (0); 79 } 80 81 /* Display regular cut buffers. */ 82 LIST_FOREACH(cbp, &sp->gp->cutq, q) { 83 if (isdigit(cbp->name)) 84 continue; 85 if (!TAILQ_EMPTY(&cbp->textq)) 86 db(sp, cbp, NULL); 87 if (INTERRUPTED(sp)) 88 return (0); 89 } 90 /* Display numbered buffers. */ 91 LIST_FOREACH(cbp, &sp->gp->cutq, q) { 92 if (!isdigit(cbp->name)) 93 continue; 94 if (!TAILQ_EMPTY(&cbp->textq)) 95 db(sp, cbp, NULL); 96 if (INTERRUPTED(sp)) 97 return (0); 98 } 99 /* Display default buffer. */ 100 if ((cbp = sp->gp->dcbp) != NULL) 101 db(sp, cbp, "default buffer"); 102 return (0); 103 } 104 105 /* 106 * db -- 107 * Display a buffer. 108 */ 109 static void 110 db(SCR *sp, CB *cbp, CHAR_T *name) 111 { 112 CHAR_T *p; 113 TEXT *tp; 114 size_t len; 115 116 (void)ex_printf(sp, "********** %s%s\n", 117 name == NULL ? KEY_NAME(sp, cbp->name) : name, 118 F_ISSET(cbp, CB_LMODE) ? " (line mode)" : " (character mode)"); 119 TAILQ_FOREACH(tp, &cbp->textq, q) { 120 for (len = tp->len, p = tp->lb; len--; ++p) { 121 (void)ex_puts(sp, KEY_NAME(sp, *p)); 122 if (INTERRUPTED(sp)) 123 return; 124 } 125 (void)ex_puts(sp, "\n"); 126 } 127 } 128