xref: /titanic_52/usr/src/tools/cscope-fast/history.c (revision 269e59f9a28bf47e0f463e64fc5af4a408b73b21)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1988 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  * Copyright (c) 1999 by Sun Microsystems, Inc.
28  * All rights reserved.
29  */
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 /*
34  *	cscope - interactive C symbol or text cross-reference
35  *
36  *	command history
37  */
38 
39 #include <stdio.h>
40 #include "global.h"
41 
42 HISTORY *head, *tail, *current;
43 
44 /* add a cmd to the history list */
45 void
46 addcmd(int f, char *s)
47 {
48 	HISTORY *h;
49 
50 	h = (HISTORY *)mymalloc(sizeof (HISTORY));
51 	if (tail) {
52 		tail->next = h;
53 		h->next = 0;
54 		h->previous = tail;
55 		tail = h;
56 	} else {
57 		head = tail = h;
58 		h->next = h->previous = 0;
59 	}
60 	h->field = f;
61 	h->text = stralloc(s);
62 	current = 0;
63 }
64 
65 /* return previous history item */
66 
67 HISTORY *
68 prevcmd(void)
69 {
70 	if (current) {
71 		if (current->previous)	/* stay on first item */
72 			return (current = current->previous);
73 		else
74 			return (current);
75 	} else if (tail)
76 		return (current = tail);
77 	else
78 		return (NULL);
79 }
80 
81 /* return next history item */
82 
83 HISTORY *
84 nextcmd(void)
85 {
86 	if (current) {
87 		if (current->next)	/* stay on first item */
88 			return (current = current->next);
89 		else
90 			return (current);
91 	} else
92 		return (NULL);
93 }
94 
95 /* reset current to tail */
96 
97 void
98 resetcmd(void)
99 {
100 	current = 0;
101 }
102 
103 HISTORY *
104 currentcmd(void)
105 {
106 	return (current);
107 }
108