~ubuntu-branches/ubuntu/maverick/bc/maverick

« back to all changes in this revision

Viewing changes to bc/bcdefs.h

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2002-04-13 11:33:49 UTC
  • Revision ID: james.westby@ubuntu.com-20020413113349-hl2r1t730b91ov68
Tags: upstream-1.06
ImportĀ upstreamĀ versionĀ 1.06

Show diffs side-by-side

added added

removed removed

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