xref: /illumos-gate/usr/src/tools/cscope-fast/history.c (revision 8119dad84d6416f13557b0ba8e2aaf9064cbcfd3)
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 /*
32  *	cscope - interactive C symbol or text cross-reference
33  *
34  *	command history
35  */
36 
37 #include <stdio.h>
38 #include "global.h"
39 
40 HISTORY *head, *tail, *current;
41 
42 /* add a cmd to the history list */
43 void
44 addcmd(int f, char *s)
45 {
46 	HISTORY *h;
47 
48 	h = (HISTORY *)mymalloc(sizeof (HISTORY));
49 	if (tail) {
50 		tail->next = h;
51 		h->next = 0;
52 		h->previous = tail;
53 		tail = h;
54 	} else {
55 		head = tail = h;
56 		h->next = h->previous = 0;
57 	}
58 	h->field = f;
59 	h->text = stralloc(s);
60 	current = 0;
61 }
62 
63 /* return previous history item */
64 
65 HISTORY *
66 prevcmd(void)
67 {
68 	if (current) {
69 		if (current->previous)	/* stay on first item */
70 			return (current = current->previous);
71 		else
72 			return (current);
73 	} else if (tail)
74 		return (current = tail);
75 	else
76 		return (NULL);
77 }
78 
79 /* return next history item */
80 
81 HISTORY *
82 nextcmd(void)
83 {
84 	if (current) {
85 		if (current->next)	/* stay on first item */
86 			return (current = current->next);
87 		else
88 			return (current);
89 	} else
90 		return (NULL);
91 }
92 
93 /* reset current to tail */
94 
95 void
96 resetcmd(void)
97 {
98 	current = 0;
99 }
100 
101 HISTORY *
102 currentcmd(void)
103 {
104 	return (current);
105 }
106