replace malloc with emalloc; Str_Concat -> str_concat
[unix-history] / usr / src / usr.bin / make / lst.h
CommitLineData
b0ff1758
KB
1/*
2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
3 * Copyright (c) 1988, 1989 by Adam de Boor
4 * Copyright (c) 1989 by Berkeley Softworks
5 * All rights reserved.
fe902645 6 *
b0ff1758
KB
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
fe902645 9 *
b0ff1758
KB
10 * Redistribution and use in source and binary forms are permitted
11 * provided that the above copyright notice and this paragraph are
12 * duplicated in all such forms and that any documentation,
13 * advertising materials, and other materials related to such
14 * distribution and use acknowledge that the software was developed
15 * by the University of California, Berkeley. The name of the
16 * University may not be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
fe902645 21 *
b0ff1758
KB
22 * @(#)lst.h 5.2 (Berkeley) %G%
23 */
24
25/*-
26 * lst.h --
27 * Header for using the list library
fe902645
KB
28 */
29#ifndef _LST_H_
30#define _LST_H_
31
32#include <sprite.h>
33
34/*
35 * basic typedef. This is what the Lst_ functions handle
36 */
37
38typedef struct Lst *Lst;
39typedef struct LstNode *LstNode;
40
41#define NILLST ((Lst) NIL)
42#define NILLNODE ((LstNode) NIL)
43
44/*
45 * NOFREE can be used as the freeProc to Lst_Destroy when the elements are
46 * not to be freed.
47 * NOCOPY performs similarly when given as the copyProc to Lst_Duplicate.
48 */
49#define NOFREE ((void (*)()) 0)
50#define NOCOPY ((ClientData (*)()) 0)
51
52#define LST_CONCNEW 0 /* create new LstNode's when using Lst_Concat */
53#define LST_CONCLINK 1 /* relink LstNode's when using Lst_Concat */
54
55/*
56 * Creation/destruction functions
57 */
58Lst Lst_Init(); /* Create a new list */
59Lst Lst_Duplicate(); /* Duplicate an existing list */
60void Lst_Destroy(); /* Destroy an old one */
61
62int Lst_Length(); /* Find the length of a list */
63Boolean Lst_IsEmpty(); /* True if list is empty */
64
65/*
66 * Functions to modify a list
67 */
68ReturnStatus Lst_Insert(); /* Insert an element before another */
69ReturnStatus Lst_Append(); /* Insert an element after another */
70ReturnStatus Lst_AtFront(); /* Place an element at the front of
71 * a lst. */
72ReturnStatus Lst_AtEnd(); /* Place an element at the end of a
73 * lst. */
74ReturnStatus Lst_Remove(); /* Remove an element */
75ReturnStatus Lst_Replace(); /* Replace a node with a new value */
76ReturnStatus Lst_Move(); /* Move an element to another place */
77ReturnStatus Lst_Concat(); /* Concatenate two lists */
78
79/*
80 * Node-specific functions
81 */
82LstNode Lst_First(); /* Return first element in list */
83LstNode Lst_Last(); /* Return last element in list */
84LstNode Lst_Succ(); /* Return successor to given element */
85LstNode Lst_Pred(); /* Return predecessor to given
86 * element */
87ClientData Lst_Datum(); /* Get datum from LstNode */
88
89/*
90 * Functions for entire lists
91 */
92LstNode Lst_Find(); /* Find an element in a list */
93LstNode Lst_FindFrom(); /* Find an element starting from
94 * somewhere */
95LstNode Lst_Member(); /* See if the given datum is on the
96 * list. Returns the LstNode containing
97 * the datum */
98int Lst_Index(); /* Returns the index of a datum in the
99 * list, starting from 0 */
100void Lst_ForEach(); /* Apply a function to all elements of
101 * a lst */
102void Lst_ForEachFrom(); /* Apply a function to all elements of
103 * a lst starting from a certain point.
104 * If the list is circular, the
105 * application will wrap around to the
106 * beginning of the list again. */
107/*
108 * these functions are for dealing with a list as a table, of sorts.
109 * An idea of the "current element" is kept and used by all the functions
110 * between Lst_Open() and Lst_Close().
111 */
112ReturnStatus Lst_Open(); /* Open the list */
113LstNode Lst_Prev(); /* Previous element */
114LstNode Lst_Cur(); /* The current element, please */
115LstNode Lst_Next(); /* Next element please */
116Boolean Lst_IsAtEnd(); /* Done yet? */
117void Lst_Close(); /* Finish table access */
118
119/*
120 * for using the list as a queue
121 */
122ReturnStatus Lst_EnQueue(); /* Place an element at tail of queue */
123ClientData Lst_DeQueue(); /* Remove an element from head of
124 * queue */
125
126#endif _LST_H_