1 /* $NetBSD: ex_display.c,v 1.4 2014/01/26 21:43:45 christos Exp $ */ 2 /*- 3 * Copyright (c) 1992, 1993, 1994 4 * The Regents of the University of California. All rights reserved. 5 * Copyright (c) 1992, 1993, 1994, 1995, 1996 6 * Keith Bostic. All rights reserved. 7 * 8 * See the LICENSE file for redistribution information. 9 */ 10 11 #include "config.h" 12 13 #include <sys/cdefs.h> 14 #if 0 15 #ifndef lint 16 static const char sccsid[] = "Id: ex_display.c,v 10.15 2001/06/25 15:19:15 skimo Exp (Berkeley) Date: 2001/06/25 15:19:15 "; 17 #endif /* not lint */ 18 #else 19 __RCSID("$NetBSD: ex_display.c,v 1.4 2014/01/26 21:43:45 christos Exp $"); 20 #endif 21 22 #include <sys/types.h> 23 #include <sys/queue.h> 24 25 #include <bitstring.h> 26 #include <ctype.h> 27 #include <limits.h> 28 #include <stdio.h> 29 #include <string.h> 30 31 #include "../common/common.h" 32 #include "tag.h" 33 34 static int is_prefix __P((ARGS *, const CHAR_T *)); 35 static int bdisplay __P((SCR *)); 36 static void db __P((SCR *, CB *, const char *)); 37 38 /* 39 * ex_display -- :display b[uffers] | c[onnections] | s[creens] | t[ags] 40 * 41 * Display cscope connections, buffers, tags or screens. 42 * 43 * PUBLIC: int ex_display __P((SCR *, EXCMD *)); 44 */ 45 int 46 ex_display(SCR *sp, EXCMD *cmdp) 47 { 48 ARGS *arg; 49 50 arg = cmdp->argv[0]; 51 52 switch (arg->bp[0]) { 53 case L('b'): 54 if (!is_prefix(arg, L("buffers"))) 55 break; 56 return (bdisplay(sp)); 57 case L('c'): 58 if (!is_prefix(arg, L("connections"))) 59 break; 60 return (cscope_display(sp)); 61 case L('s'): 62 if (!is_prefix(arg, L("screens"))) 63 break; 64 return (ex_sdisplay(sp)); 65 case L('t'): 66 if (!is_prefix(arg, L("tags"))) 67 break; 68 return (ex_tag_display(sp)); 69 } 70 ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE); 71 return (1); 72 } 73 74 /* 75 * is_prefix -- 76 * 77 * Check that a command argument matches a prefix of a given string. 78 */ 79 static int 80 is_prefix(ARGS *arg, const CHAR_T *str) 81 { 82 return arg->len <= STRLEN(str) && !MEMCMP(arg->bp, str, arg->len); 83 } 84 85 /* 86 * bdisplay -- 87 * 88 * Display buffers. 89 */ 90 static int 91 bdisplay(SCR *sp) 92 { 93 CB *cbp; 94 95 if (LIST_EMPTY(&sp->wp->cutq) && sp->wp->dcbp == NULL) { 96 msgq(sp, M_INFO, "123|No cut buffers to display"); 97 return (0); 98 } 99 100 /* Display regular cut buffers. */ 101 LIST_FOREACH(cbp, &sp->wp->cutq, q) { 102 if (ISDIGIT(cbp->name)) 103 continue; 104 if (!TAILQ_EMPTY(&cbp->textq)) 105 db(sp, cbp, NULL); 106 if (INTERRUPTED(sp)) 107 return (0); 108 } 109 /* Display numbered buffers. */ 110 LIST_FOREACH(cbp, &sp->wp->cutq, q) { 111 if (!ISDIGIT(cbp->name)) 112 continue; 113 if (!TAILQ_EMPTY(&cbp->textq)) 114 db(sp, cbp, NULL); 115 if (INTERRUPTED(sp)) 116 return (0); 117 } 118 /* Display default buffer. */ 119 if ((cbp = sp->wp->dcbp) != NULL) 120 db(sp, cbp, "default buffer"); 121 return (0); 122 } 123 124 /* 125 * db -- 126 * Display a buffer. 127 */ 128 static void 129 db(SCR *sp, CB *cbp, const char *np) 130 { 131 CHAR_T *p; 132 TEXT *tp; 133 size_t len; 134 const unsigned char *name = (const void *)np; 135 136 (void)ex_printf(sp, "********** %s%s\n", 137 name == NULL ? KEY_NAME(sp, cbp->name) : name, 138 F_ISSET(cbp, CB_LMODE) ? " (line mode)" : " (character mode)"); 139 TAILQ_FOREACH(tp, &cbp->textq, q) { 140 for (len = tp->len, p = tp->lb; len--; ++p) { 141 (void)ex_puts(sp, (char *)KEY_NAME(sp, *p)); 142 if (INTERRUPTED(sp)) 143 return; 144 } 145 (void)ex_puts(sp, "\n"); 146 } 147 } 148