BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / pascal / src / string.c
CommitLineData
0fc6e47b
KB
1/*-
2 * Copyright (c) 1980 The Regents of the University of California.
3 * All rights reserved.
4 *
af359dea
C
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
252367af 32 */
1c1b91d0 33
72fbef68 34#ifndef lint
af359dea 35static char sccsid[] = "@(#)string.c 5.5 (Berkeley) 4/16/91";
0fc6e47b 36#endif /* not lint */
1c1b91d0
PK
37
38#include "whoami.h"
00a19165 39#include "align.h"
1c1b91d0
PK
40#include "0.h"
41#ifndef PI01
42#ifndef PXP
43#include "send.h"
44#endif
45#endif
46
47/*
48 * STRING SPACE DECLARATIONS
49 *
50 * Strng is the base of the current
51 * string space and strngp the
52 * base of the free area therein.
53 * Strp is the array of descriptors.
54 */
55#ifndef PI0
56STATIC char strings[STRINC];
57STATIC char *strng = strings;
58STATIC char *strngp = strings;
59#else
60char *strng, *strngp;
61#endif
62#ifndef PI01
63#ifndef PXP
64STATIC char *strp[20];
65STATIC char **stract strp;
66int strmax;
67#endif
68#endif
69
70#ifndef PI01
71#ifndef PXP
72#ifndef PI0
73initstring()
74#else
75initstring(strings)
76 char *strings;
77#endif
78{
79
80 *stract++ = strings;
81#ifdef PI0
82 strng = strngp = strings;
83#endif
84 strmax = STRINC * 2;
85}
86#endif
87#endif
88
89/*
90 * Copy a string into the string area.
91 */
92char *
93savestr(cp)
94 register char *cp;
95{
96 register int i;
97
98 i = strlen(cp) + 1;
99 if (strngp + i >= strng + STRINC) {
100 strngp = malloc(STRINC);
df51413a 101 if (strngp == 0) {
1c1b91d0
PK
102 yerror("Ran out of memory (string)");
103 pexit(DIED);
104 }
105#ifndef PI01
106#ifndef PXP
107 *stract++ = strngp;
7169b77a 108 strmax += STRINC;
1c1b91d0
PK
109#endif
110#endif
111 strng = strngp;
112 }
72fbef68 113 (void) pstrcpy(strngp, cp);
1c1b91d0
PK
114 cp = strngp;
115 strngp = cp + i;
116#ifdef PI0
117 send(RSTRING, cp);
118#endif
119 return (cp);
120}
121
122#ifndef PI1
123#ifndef PXP
72fbef68 124char *
1c1b91d0
PK
125esavestr(cp)
126 char *cp;
127{
128
129#ifdef PI0
130 send(REVENIT);
131#endif
00a19165 132 strngp = ( (char *) roundup( strngp, A_LONG ) );
1c1b91d0
PK
133 return (savestr(cp));
134}
135#endif
136#endif
137
138#ifndef PI01
139#ifndef PXP
140soffset(cp)
141 register char *cp;
142{
143 register char **sp;
144 register int i;
145
146 if (cp == NIL || cp == OCT || cp == HEX)
147 return (-cp);
148 for (i = STRINC, sp = strp; sp < stract; sp++) {
149 if (cp >= *sp && cp < (*sp + STRINC))
150 return (i + (cp - *sp));
7169b77a 151 i += STRINC;
1c1b91d0
PK
152 }
153 i = nlfund(cp);
154 if (i != 0)
155 return (i);
156 panic("soffset");
157}
158#ifdef PI1
159sreloc(i)
160 register int i;
161{
162
163 if (i == 0 || i == -OCT || i == -HEX)
164 return (-i);
165 if (i < STRINC) {
166 if (i >= INL)
167 panic("sreloc INL");
168 i = nl[i].symbol;
169 if (i == 0)
170 panic("sreloc nl[i]");
171 return (i);
172 }
173 if (i > strmax || i < 0)
174 panic("sreloc");
175 return (strp[(i / STRINC) - 1] + (i % STRINC));
176}
1c1b91d0
PK
177#endif
178#endif
179#endif