]> git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c-lib/inc/asn-list.h
e97db18b834c90218506c7161738658b69bbf335
[apple/security.git] / SecuritySNACCRuntime / c-lib / inc / asn-list.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 /*
20 * asn_list.h
21 *
22 * ---------
23 * | AsnList |
24 * | last |-------------------------------------------|
25 * | curr |--------------------------| |
26 * | first|--------| | |
27 * --------- | | |
28 * V V V
29 * --------- --------- ---------
30 * |AsnListNode |AsnListNode |AsnListNode
31 * | next |---...->| next |--...-->| next |-----|i.
32 * .i|----| prev |<--...--| prev |<--...--| prev |
33 * | data | | data | | data |
34 * --------- --------- ---------
35 *
36 * Originally by Murray Goldberg
37 * Modified for ASN.1 use.
38 * MS 92
39 * Copyright (C) 1992 the University of British Columbia
40 *
41 * This library is free software; you can redistribute it and/or
42 * modify it provided that this copyright/license information is retained
43 * in original form.
44 *
45 * If you modify this file, you must clearly indicate your changes.
46 *
47 * This source code is distributed in the hope that it will be
48 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
49 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
50 *
51 * $Header: /cvs/root/Security/SecuritySNACCRuntime/c-lib/inc/Attic/asn-list.h,v 1.1.1.1 2001/05/18 23:14:08 mb Exp $
52 * $Log: asn-list.h,v $
53 * Revision 1.1.1.1 2001/05/18 23:14:08 mb
54 * Move from private repository to open source repository
55 *
56 * Revision 1.2 2001/05/05 00:59:22 rmurphy
57 * Adding darwin license headers
58 *
59 * Revision 1.1.1.1 1999/03/16 18:06:20 aram
60 * Originals from SMIME Free Library.
61 *
62 * Revision 1.3 1995/07/24 21:01:14 rj
63 * changed `_' to `-' in file names.
64 *
65 * Revision 1.2 1994/10/08 01:40:22 rj
66 * it is unwise to #define unbalanced if()s! (fixed.)
67 * three declarations added.
68 *
69 * Revision 1.1 1994/08/28 09:21:30 rj
70 * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
71 *
72 */
73
74 #ifndef _asn_list_h_
75 #define _asn_list_h_
76
77 typedef struct AsnListNode
78 {
79 struct AsnListNode *prev;
80 struct AsnListNode *next;
81 void *data; /* this must be the last field of this structure */
82 } AsnListNode;
83
84 typedef struct AsnList
85 {
86 AsnListNode *first;
87 AsnListNode *last;
88 AsnListNode *curr;
89 int count; /* number of elements in list */
90 int dataSize; /* space required in each node for the data */
91 } AsnList;
92
93 #define FOR_EACH_LIST_ELMT( elmt, al)\
94 if (!(al))\
95 ;\
96 else\
97 for ((al)->curr = (al)->first; (al)->curr && ((elmt) = (void *)(al)->curr->data); (al)->curr = (al)->curr->next)
98
99 #define FOR_EACH_LIST_ELMT_RVS( elmt, al)\
100 if (!(al))\
101 ;\
102 else\
103 for ((al)->curr = (al)->last; (al)->curr && ((elmt) = (void *)(al)->curr->data); (al)->curr = (al)->curr->prev)
104
105
106 #define FOR_REST_LIST_ELMT( elmt, al)\
107 if (!(al))\
108 ;\
109 else\
110 for (; (al)->curr && ((elmt) = (void *)(al)->curr->data); (al)->curr = (al)->curr->next)
111
112 #define FOR_REST_LIST_ELMT_RVS( elmt, al)\
113 if (!(al))\
114 ;\
115 else\
116 for (; ((al)->curr && ((elmt) = (void *)(al)->curr->data); (al)->curr = (al)->curr->prev)
117
118 /*
119 * The following macros return the pointer stored in the
120 * data part of the listNode. The do not change the current
121 * list pointer.
122 */
123 #define CURR_LIST_ELMT( al) ((al)->curr->data)
124 #define NEXT_LIST_ELMT( al) ((al)->curr->next->data)
125 #define PREV_LIST_ELMT( al) ((al)->curr->prev->data)
126 #define LAST_LIST_ELMT( al) ((al)->last->data)
127 #define FIRST_LIST_ELMT( al) ((al)->first->data)
128 #define LIST_EMPTY( al) ((al)->count == 0)
129 #define LIST_COUNT( al) ((al)->count)
130
131 /*
132 * list nodes are the parts of the list that contain ptrs/data
133 * to/of the list elmts.
134 */
135 #define CURR_LIST_NODE( al) ((al)->curr)
136 #define FIRST_LIST_NODE( al) ((al)->first)
137 #define LAST_LIST_NODE( al) ((al)->last)
138 #define PREV_LIST_NODE( al) ((al)->curr->prev)
139 #define NEXT_LIST_NODE( al) ((al)->curr->next)
140 #define SET_CURR_LIST_NODE( al, listNode) ((al)->curr = (listNode))
141
142 void AsnListRemove PROTO ((AsnList *));
143 void *AsnListAdd PROTO ((AsnList *));
144 void *AsnListInsert PROTO ((AsnList *));
145 void AsnListInit PROTO ((AsnList *list, int dataSize));
146 AsnList *AsnListNew PROTO ((int));
147 void *AsnListPrev PROTO ((AsnList *));
148 void *AsnListNext PROTO ((AsnList *));
149 void *AsnListLast PROTO ((AsnList *));
150 void *AsnListFirst PROTO ((AsnList *));
151 void *AsnListPrepend PROTO ((AsnList *));
152 void *AsnListAppend PROTO ((AsnList *));
153 void *AsnListCurr PROTO ((AsnList *));
154 int AsnListCount PROTO ((AsnList *));
155 AsnList *AsnListConcat PROTO ((AsnList *, AsnList *));
156 long int GetAsnListElmtIndex PROTO ((void *elmt,AsnList *list));
157 void AsnListFree PROTO (( AsnList *));
158 void *GetAsnListElmt PROTO ((AsnList *list, unsigned int index));
159
160 #endif /* conditional include */