"SfR Fresh" - the SfR Freeware/Shareware Archive 
Member "bc-1.06.95/bc/bcdefs.h" of archive bc-1.06.95.tar.gz:
As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers.
Alternatively you can here view or download the uninterpreted source code file.
That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
1 /* This file is part of GNU bc.
2
3 Copyright (C) 1991-1994, 1997, 2006 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License , or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to:
17 The Free Software Foundation, Inc.
18 Foundation, Inc. 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301 USA
20
21 You may contact the author by:
22 e-mail: philnelson@acm.org
23 us-mail: Philip A. Nelson
24 Computer Science Department, 9062
25 Western Washington University
26 Bellingham, WA 98226-9062
27
28 *************************************************************************/
29
30 /* bcdefs.h: The single file to include all constants and type definitions. */
31
32 /* Include the configuration file. */
33 #include "config.h"
34
35 /* Standard includes for all files. */
36 #include <stdio.h>
37 #include <sys/types.h>
38 #include <ctype.h>
39 #ifdef HAVE_STRING_H
40 #include <string.h>
41 #else
42 #include <strings.h>
43 #endif
44 #ifdef HAVE_LIMITS_H
45 #include <limits.h>
46 #endif
47
48 #if defined(LIBEDIT)
49 #include <histedit.h>
50 #endif
51
52 #if defined(READLINE)
53 #include <readline/readline.h>
54 #include <readline/history.h>
55 #endif
56
57 /* Initialization magic ... */
58 #ifdef _GLOBAL_C
59 #define EXTERN
60 #define INIT(x) = x
61 #else
62 #define EXTERN extern
63 #define INIT(x)
64 #endif
65
66 /* Include the other definitions. */
67 #include "const.h"
68 #include "number.h"
69
70 /* These definitions define all the structures used in
71 code and data storage. This includes the representation of
72 labels. The "guiding" principle is to make structures that
73 take a minimum of space when unused but can be built to contain
74 the full structures. */
75
76 /* Labels are first. Labels are generated sequentially in functions
77 and full code. They just "point" to a single bye in the code. The
78 "address" is the byte number. The byte number is used to get an
79 actual character pointer. */
80
81 typedef struct bc_label_group
82 {
83 long l_adrs [ BC_LABEL_GROUP ];
84 struct bc_label_group *l_next;
85 } bc_label_group;
86
87 /* Argument list. Recorded in the function so arguments can
88 be checked at call time. */
89
90 typedef struct arg_list
91 {
92 int av_name;
93 int arg_is_var; /* Extension ... variable parameters. */
94 struct arg_list *next;
95 } arg_list;
96
97 /* Each function has its own code segments and labels. There can be
98 no jumps between functions so labels are unique to a function. */
99
100 typedef struct
101 {
102 char f_defined; /* Is this function defined yet. */
103 char f_void; /* Is this function a void function. */
104 char *f_body;
105 int f_body_size; /* Size of body. Power of 2. */
106 int f_code_size;
107 bc_label_group *f_label;
108 arg_list *f_params;
109 arg_list *f_autos;
110 } bc_function;
111
112 /* Code addresses. */
113 typedef struct {
114 int pc_func;
115 int pc_addr;
116 } program_counter;
117
118
119 /* Variables are "pushable" (auto) and thus we need a stack mechanism.
120 This is built into the variable record. */
121
122 typedef struct bc_var
123 {
124 bc_num v_value;
125 struct bc_var *v_next;
126 } bc_var;
127
128
129 /* bc arrays can also be "auto" variables and thus need the same
130 kind of stacking mechanisms. */
131
132 typedef struct bc_array_node
133 {
134 union
135 {
136 bc_num n_num [NODE_SIZE];
137 struct bc_array_node *n_down [NODE_SIZE];
138 } n_items;
139 } bc_array_node;
140
141 typedef struct bc_array
142 {
143 bc_array_node *a_tree;
144 short a_depth;
145 } bc_array;
146
147 typedef struct bc_var_array
148 {
149 bc_array *a_value;
150 char a_param;
151 struct bc_var_array *a_next;
152 } bc_var_array;
153
154
155 /* For the stacks, execution and function, we need records to allow
156 for arbitrary size. */
157
158 typedef struct estack_rec {
159 bc_num s_num;
160 struct estack_rec *s_next;
161 } estack_rec;
162
163 typedef struct fstack_rec {
164 int s_val;
165 struct fstack_rec *s_next;
166 } fstack_rec;
167
168
169 /* The following are for the name tree. */
170
171 typedef struct id_rec {
172 char *id; /* The program name. */
173 /* A name == 0 => nothing assigned yet. */
174 int a_name; /* The array variable name (number). */
175 int f_name; /* The function name (number). */
176 int v_name; /* The variable name (number). */
177 short balance; /* For the balanced tree. */
178 struct id_rec *left, *right; /* Tree pointers. */
179 } id_rec;
180
181
182 /* A list of files to process. */
183
184 typedef struct file_node {
185 char *name;
186 struct file_node *next;
187 } file_node;
188
189 /* Macro Definitions */
190
191 #if defined(LIBEDIT)
192 #define HISTORY_SIZE(n) history(hist, &histev, H_SETSIZE, n)
193 #define UNLIMIT_HISTORY history(hist, &histev, H_SETSIZE, INT_MAX)
194 #endif
195
196 #if defined(READLINE)
197 #define HISTORY_SIZE(n) stifle_history(n)
198 #define UNLIMIT_HISTORY unstifle_history()
199 #endif
200
201 /* Now the global variable declarations. */
202 #include "global.h"