new copyright; att/bsd/shared
[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 *
5 * %sccs.include.redist.c%
252367af 6 */
1c1b91d0 7
72fbef68 8#ifndef lint
0fc6e47b
KB
9static char sccsid[] = "@(#)string.c 5.5 (Berkeley) %G%";
10#endif /* not lint */
1c1b91d0
PK
11
12#include "whoami.h"
00a19165 13#include "align.h"
1c1b91d0
PK
14#include "0.h"
15#ifndef PI01
16#ifndef PXP
17#include "send.h"
18#endif
19#endif
20
21/*
22 * STRING SPACE DECLARATIONS
23 *
24 * Strng is the base of the current
25 * string space and strngp the
26 * base of the free area therein.
27 * Strp is the array of descriptors.
28 */
29#ifndef PI0
30STATIC char strings[STRINC];
31STATIC char *strng = strings;
32STATIC char *strngp = strings;
33#else
34char *strng, *strngp;
35#endif
36#ifndef PI01
37#ifndef PXP
38STATIC char *strp[20];
39STATIC char **stract strp;
40int strmax;
41#endif
42#endif
43
44#ifndef PI01
45#ifndef PXP
46#ifndef PI0
47initstring()
48#else
49initstring(strings)
50 char *strings;
51#endif
52{
53
54 *stract++ = strings;
55#ifdef PI0
56 strng = strngp = strings;
57#endif
58 strmax = STRINC * 2;
59}
60#endif
61#endif
62
63/*
64 * Copy a string into the string area.
65 */
66char *
67savestr(cp)
68 register char *cp;
69{
70 register int i;
71
72 i = strlen(cp) + 1;
73 if (strngp + i >= strng + STRINC) {
74 strngp = malloc(STRINC);
df51413a 75 if (strngp == 0) {
1c1b91d0
PK
76 yerror("Ran out of memory (string)");
77 pexit(DIED);
78 }
79#ifndef PI01
80#ifndef PXP
81 *stract++ = strngp;
7169b77a 82 strmax += STRINC;
1c1b91d0
PK
83#endif
84#endif
85 strng = strngp;
86 }
72fbef68 87 (void) pstrcpy(strngp, cp);
1c1b91d0
PK
88 cp = strngp;
89 strngp = cp + i;
90#ifdef PI0
91 send(RSTRING, cp);
92#endif
93 return (cp);
94}
95
96#ifndef PI1
97#ifndef PXP
72fbef68 98char *
1c1b91d0
PK
99esavestr(cp)
100 char *cp;
101{
102
103#ifdef PI0
104 send(REVENIT);
105#endif
00a19165 106 strngp = ( (char *) roundup( strngp, A_LONG ) );
1c1b91d0
PK
107 return (savestr(cp));
108}
109#endif
110#endif
111
112#ifndef PI01
113#ifndef PXP
114soffset(cp)
115 register char *cp;
116{
117 register char **sp;
118 register int i;
119
120 if (cp == NIL || cp == OCT || cp == HEX)
121 return (-cp);
122 for (i = STRINC, sp = strp; sp < stract; sp++) {
123 if (cp >= *sp && cp < (*sp + STRINC))
124 return (i + (cp - *sp));
7169b77a 125 i += STRINC;
1c1b91d0
PK
126 }
127 i = nlfund(cp);
128 if (i != 0)
129 return (i);
130 panic("soffset");
131}
132#ifdef PI1
133sreloc(i)
134 register int i;
135{
136
137 if (i == 0 || i == -OCT || i == -HEX)
138 return (-i);
139 if (i < STRINC) {
140 if (i >= INL)
141 panic("sreloc INL");
142 i = nl[i].symbol;
143 if (i == 0)
144 panic("sreloc nl[i]");
145 return (i);
146 }
147 if (i > strmax || i < 0)
148 panic("sreloc");
149 return (strp[(i / STRINC) - 1] + (i % STRINC));
150}
1c1b91d0
PK
151#endif
152#endif
153#endif