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