8990 /opt/onbld/gk is useless
[unleashed.git] / usr / src / tools / cscope-fast / history.c
blob3fa1f6f333b6162b2462ac2dcc5cca2857c902ee
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
22 /* Copyright (c) 1988 AT&T */
23 /* All Rights Reserved */
27 * Copyright (c) 1999 by Sun Microsystems, Inc.
28 * All rights reserved.
31 #pragma ident "%Z%%M% %I% %E% SMI"
34 * cscope - interactive C symbol or text cross-reference
36 * command history
39 #include <stdio.h>
40 #include "global.h"
42 HISTORY *head, *tail, *current;
44 /* add a cmd to the history list */
45 void
46 addcmd(int f, char *s)
48 HISTORY *h;
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;
60 h->field = f;
61 h->text = stralloc(s);
62 current = 0;
65 /* return previous history item */
67 HISTORY *
68 prevcmd(void)
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);
81 /* return next history item */
83 HISTORY *
84 nextcmd(void)
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);
95 /* reset current to tail */
97 void
98 resetcmd(void)
100 current = 0;
103 HISTORY *
104 currentcmd(void)
106 return (current);