• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*-C-*-
2  ********************************************************************************
3  *
4  * File:        array.h  (Formerly array.h)
5  * Description:  Dynamic Array of String
6  * Author:       Mark Seaman, SW Productivity
7  * Created:      Fri Oct 16 14:37:00 1987
8  * Modified:     Mon Sep 24 14:15:59 1990 (Mark Seaman) marks@hpgrlt
9  * Language:     C
10  * Package:      N/A
11  * Status:       Reusable Software Component
12  *
13  * (c) Copyright 1987, Hewlett-Packard Company.
14  ** Licensed under the Apache License, Version 2.0 (the "License");
15  ** you may not use this file except in compliance with the License.
16  ** You may obtain a copy of the License at
17  ** http://www.apache.org/licenses/LICENSE-2.0
18  ** Unless required by applicable law or agreed to in writing, software
19  ** distributed under the License is distributed on an "AS IS" BASIS,
20  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  ** See the License for the specific language governing permissions and
22  ** limitations under the License.
23  *
24  *****************************************************************************
25 
26 This file contains a set of general purpose dynamic array of string routines.
27 These routines can be used in a wide variety of ways to provide several
28 different popular data structures. A new "das" can be created by declaring
29 a variable of type 'DAS'
30 ******************************************************************************/
31 
32 #ifndef TESSARRAY_H
33 #define TESSARRAY_H
34 
35 /*
36 ----------------------------------------------------------------------
37               I n c l u d e s
38 ----------------------------------------------------------------------
39 */
40 
41 #include <stdio.h>
42 
43 /*
44 ----------------------------------------------------------------------
45               T y p e s
46 ----------------------------------------------------------------------
47 */
48 
49 typedef struct array_record
50 {
51   size_t limit;
52   size_t top;
53   void *base[2];
54 } *ARRAY;
55 
56 typedef void (*voidProc) ();
57 
58 typedef int (*intProc) ();
59 
60 /*
61 ----------------------------------------------------------------------
62               M a c r o s
63 ----------------------------------------------------------------------
64 */
65 
66 #define DEFAULT_SIZE 2
67 
68 /**********************************************************************
69  * array_count
70  *
71  * Return the value of the number of elements currently in the array.
72  **********************************************************************/
73 
74 #define array_count(a)  \
75 ((a)->top)
76 
77 /**********************************************************************
78  * array_free
79  *
80  * Free the memory allocated to this array.
81  **********************************************************************/
82 
83 #define array_free  \
84 memfree
85 
86 /**********************************************************************
87  * array_index
88  *
89  * Check to make sure that the index value is valid. Return the
90  * value of the nth element currently in the array.
91  **********************************************************************/
92 
93 #define array_index(a,i)   \
94 ((i<array_count(a)) ? (a)->base[i] : 0)
95 
96 /**********************************************************************
97  * array_limit
98  *
99  * Return the maximum number of elements that could be currently held
100  * in this array without further expansion.
101  **********************************************************************/
102 
103 #define array_limit(a)     \
104 ((a)->limit)
105 
106 /**********************************************************************
107  * array_loop
108  *
109  * Iterate through each of the array elements.  Each value can then be
110  * accessed by:
111  *    array_index (a, x)
112  **********************************************************************/
113 
114 #define array_loop(a,x)    \
115 for (x=0; x < array_count (a); x++)
116 
117 /**********************************************************************
118  * array_top
119  *
120  * Return the last element that was pushed on this array.
121  **********************************************************************/
122 
123 #define array_top(a)       \
124 ((a)->base[array_count (a) - 1])
125 
126 /**********************************************************************
127  * array_value
128  *
129  * Return the nth element of the array.  Don't do range checking.
130  **********************************************************************/
131 
132 #define array_value(a,i)   \
133 ((a)->base[i])
134 
135 /*----------------------------------------------------------------------
136               F u n c t i o n s
137 ----------------------------------------------------------------------*/
138 ARRAY array_insert(ARRAY array, int index, void *value);
139 
140 ARRAY array_new(int num);
141 
142 ARRAY array_push(ARRAY array, void *value);
143 
144 /*
145 #if defined(__STDC__) || defined(__cplusplus)
146 # define	_ARGS(s) s
147 #else
148 # define	_ARGS(s) ()
149 #endif*/
150 
151 /* array.c
152 ARRAY array_insert
153   _ARGS((ARRAY array,
154   int index,
155   char *value));
156 
157 ARRAY array_new
158   _ARGS((int num));
159 
160 ARRAY array_push
161   _ARGS((ARRAY array,
162   char *value));
163 
164 #undef _ARGS
165 */
166 #endif
167