xref: /minix3/external/bsd/nvi/dist/ex/ex_display.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: ex_display.c,v 1.4 2014/01/26 21:43:45 christos Exp $ */
284d9c625SLionel Sambuc /*-
384d9c625SLionel Sambuc  * Copyright (c) 1992, 1993, 1994
484d9c625SLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
584d9c625SLionel Sambuc  * Copyright (c) 1992, 1993, 1994, 1995, 1996
684d9c625SLionel Sambuc  *	Keith Bostic.  All rights reserved.
784d9c625SLionel Sambuc  *
884d9c625SLionel Sambuc  * See the LICENSE file for redistribution information.
984d9c625SLionel Sambuc  */
1084d9c625SLionel Sambuc 
1184d9c625SLionel Sambuc #include "config.h"
1284d9c625SLionel Sambuc 
13*0a6a1f1dSLionel Sambuc #include <sys/cdefs.h>
14*0a6a1f1dSLionel Sambuc #if 0
1584d9c625SLionel Sambuc #ifndef lint
1684d9c625SLionel Sambuc 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 ";
1784d9c625SLionel Sambuc #endif /* not lint */
18*0a6a1f1dSLionel Sambuc #else
19*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: ex_display.c,v 1.4 2014/01/26 21:43:45 christos Exp $");
20*0a6a1f1dSLionel Sambuc #endif
2184d9c625SLionel Sambuc 
2284d9c625SLionel Sambuc #include <sys/types.h>
2384d9c625SLionel Sambuc #include <sys/queue.h>
2484d9c625SLionel Sambuc 
2584d9c625SLionel Sambuc #include <bitstring.h>
2684d9c625SLionel Sambuc #include <ctype.h>
2784d9c625SLionel Sambuc #include <limits.h>
2884d9c625SLionel Sambuc #include <stdio.h>
2984d9c625SLionel Sambuc #include <string.h>
3084d9c625SLionel Sambuc 
3184d9c625SLionel Sambuc #include "../common/common.h"
3284d9c625SLionel Sambuc #include "tag.h"
3384d9c625SLionel Sambuc 
3484d9c625SLionel Sambuc static int	is_prefix __P((ARGS *, const CHAR_T *));
3584d9c625SLionel Sambuc static int	bdisplay __P((SCR *));
3684d9c625SLionel Sambuc static void	db __P((SCR *, CB *, const char *));
3784d9c625SLionel Sambuc 
3884d9c625SLionel Sambuc /*
3984d9c625SLionel Sambuc  * ex_display -- :display b[uffers] | c[onnections] | s[creens] | t[ags]
4084d9c625SLionel Sambuc  *
4184d9c625SLionel Sambuc  *	Display cscope connections, buffers, tags or screens.
4284d9c625SLionel Sambuc  *
4384d9c625SLionel Sambuc  * PUBLIC: int ex_display __P((SCR *, EXCMD *));
4484d9c625SLionel Sambuc  */
4584d9c625SLionel Sambuc int
ex_display(SCR * sp,EXCMD * cmdp)4684d9c625SLionel Sambuc ex_display(SCR *sp, EXCMD *cmdp)
4784d9c625SLionel Sambuc {
4884d9c625SLionel Sambuc 	ARGS *arg;
4984d9c625SLionel Sambuc 
5084d9c625SLionel Sambuc 	arg = cmdp->argv[0];
5184d9c625SLionel Sambuc 
5284d9c625SLionel Sambuc 	switch (arg->bp[0]) {
5384d9c625SLionel Sambuc 	case L('b'):
5484d9c625SLionel Sambuc 		if (!is_prefix(arg, L("buffers")))
5584d9c625SLionel Sambuc 			break;
5684d9c625SLionel Sambuc 		return (bdisplay(sp));
5784d9c625SLionel Sambuc 	case L('c'):
5884d9c625SLionel Sambuc 		if (!is_prefix(arg, L("connections")))
5984d9c625SLionel Sambuc 			break;
6084d9c625SLionel Sambuc 		return (cscope_display(sp));
6184d9c625SLionel Sambuc 	case L('s'):
6284d9c625SLionel Sambuc 		if (!is_prefix(arg, L("screens")))
6384d9c625SLionel Sambuc 			break;
6484d9c625SLionel Sambuc 		return (ex_sdisplay(sp));
6584d9c625SLionel Sambuc 	case L('t'):
6684d9c625SLionel Sambuc 		if (!is_prefix(arg, L("tags")))
6784d9c625SLionel Sambuc 			break;
6884d9c625SLionel Sambuc 		return (ex_tag_display(sp));
6984d9c625SLionel Sambuc 	}
7084d9c625SLionel Sambuc 	ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
7184d9c625SLionel Sambuc 	return (1);
7284d9c625SLionel Sambuc }
7384d9c625SLionel Sambuc 
7484d9c625SLionel Sambuc /*
7584d9c625SLionel Sambuc  * is_prefix --
7684d9c625SLionel Sambuc  *
7784d9c625SLionel Sambuc  *	Check that a command argument matches a prefix of a given string.
7884d9c625SLionel Sambuc  */
7984d9c625SLionel Sambuc static int
is_prefix(ARGS * arg,const CHAR_T * str)8084d9c625SLionel Sambuc is_prefix(ARGS *arg, const CHAR_T *str)
8184d9c625SLionel Sambuc {
8284d9c625SLionel Sambuc 	return arg->len <= STRLEN(str) && !MEMCMP(arg->bp, str, arg->len);
8384d9c625SLionel Sambuc }
8484d9c625SLionel Sambuc 
8584d9c625SLionel Sambuc /*
8684d9c625SLionel Sambuc  * bdisplay --
8784d9c625SLionel Sambuc  *
8884d9c625SLionel Sambuc  *	Display buffers.
8984d9c625SLionel Sambuc  */
9084d9c625SLionel Sambuc static int
bdisplay(SCR * sp)9184d9c625SLionel Sambuc bdisplay(SCR *sp)
9284d9c625SLionel Sambuc {
9384d9c625SLionel Sambuc 	CB *cbp;
9484d9c625SLionel Sambuc 
9584d9c625SLionel Sambuc 	if (LIST_EMPTY(&sp->wp->cutq) && sp->wp->dcbp == NULL) {
9684d9c625SLionel Sambuc 		msgq(sp, M_INFO, "123|No cut buffers to display");
9784d9c625SLionel Sambuc 		return (0);
9884d9c625SLionel Sambuc 	}
9984d9c625SLionel Sambuc 
10084d9c625SLionel Sambuc 	/* Display regular cut buffers. */
10184d9c625SLionel Sambuc 	LIST_FOREACH(cbp, &sp->wp->cutq, q) {
10284d9c625SLionel Sambuc 		if (ISDIGIT(cbp->name))
10384d9c625SLionel Sambuc 			continue;
10484d9c625SLionel Sambuc 		if (!TAILQ_EMPTY(&cbp->textq))
10584d9c625SLionel Sambuc 			db(sp, cbp, NULL);
10684d9c625SLionel Sambuc 		if (INTERRUPTED(sp))
10784d9c625SLionel Sambuc 			return (0);
10884d9c625SLionel Sambuc 	}
10984d9c625SLionel Sambuc 	/* Display numbered buffers. */
11084d9c625SLionel Sambuc 	LIST_FOREACH(cbp, &sp->wp->cutq, q) {
11184d9c625SLionel Sambuc 		if (!ISDIGIT(cbp->name))
11284d9c625SLionel Sambuc 			continue;
11384d9c625SLionel Sambuc 		if (!TAILQ_EMPTY(&cbp->textq))
11484d9c625SLionel Sambuc 			db(sp, cbp, NULL);
11584d9c625SLionel Sambuc 		if (INTERRUPTED(sp))
11684d9c625SLionel Sambuc 			return (0);
11784d9c625SLionel Sambuc 	}
11884d9c625SLionel Sambuc 	/* Display default buffer. */
11984d9c625SLionel Sambuc 	if ((cbp = sp->wp->dcbp) != NULL)
12084d9c625SLionel Sambuc 		db(sp, cbp, "default buffer");
12184d9c625SLionel Sambuc 	return (0);
12284d9c625SLionel Sambuc }
12384d9c625SLionel Sambuc 
12484d9c625SLionel Sambuc /*
12584d9c625SLionel Sambuc  * db --
12684d9c625SLionel Sambuc  *	Display a buffer.
12784d9c625SLionel Sambuc  */
12884d9c625SLionel Sambuc static void
db(SCR * sp,CB * cbp,const char * np)12984d9c625SLionel Sambuc db(SCR *sp, CB *cbp, const char *np)
13084d9c625SLionel Sambuc {
13184d9c625SLionel Sambuc 	CHAR_T *p;
13284d9c625SLionel Sambuc 	TEXT *tp;
13384d9c625SLionel Sambuc 	size_t len;
13484d9c625SLionel Sambuc 	const unsigned char *name = (const void *)np;
13584d9c625SLionel Sambuc 
13684d9c625SLionel Sambuc 	(void)ex_printf(sp, "********** %s%s\n",
13784d9c625SLionel Sambuc 	    name == NULL ? KEY_NAME(sp, cbp->name) : name,
13884d9c625SLionel Sambuc 	    F_ISSET(cbp, CB_LMODE) ? " (line mode)" : " (character mode)");
13984d9c625SLionel Sambuc 	TAILQ_FOREACH(tp, &cbp->textq, q) {
14084d9c625SLionel Sambuc 		for (len = tp->len, p = tp->lb; len--; ++p) {
14184d9c625SLionel Sambuc 			(void)ex_puts(sp, (char *)KEY_NAME(sp, *p));
14284d9c625SLionel Sambuc 			if (INTERRUPTED(sp))
14384d9c625SLionel Sambuc 				return;
14484d9c625SLionel Sambuc 		}
14584d9c625SLionel Sambuc 		(void)ex_puts(sp, "\n");
14684d9c625SLionel Sambuc 	}
14784d9c625SLionel Sambuc }
148