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