-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLSTRFUNS.C
381 lines (305 loc) · 8.7 KB
/
LSTRFUNS.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/*
;
; This module belongs to St. Vitus' Lisp which is the Lisp Interpreter
; for the MS-DOS machines.
; Following text applies to this module and to
; all other modules in this package unless otherwise noted:
;
; Copyright (C) 1991 Antti J. Karttunen
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 1, or (at your option)
; any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License (in file GPL.TXT) for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;
*/
#include "linclude.h"
TOB fetch_char(string,index) /* vlambda */
TOB string,index;
{
return(char_tob(*(tob_string(string) +
(endmarkp(index) ? 0 : tob_int(index)))));
}
TOB set_char(string,character,index)
TOB string,character,index;
{
BYTE *s;
UINT i;
s = tob_string(string);
i = (endmarkp(index) ? 0 : tob_uint(index));
*(s+i) = tob_uint(character);
return(string);
}
TOB L_strcpy(s1,s2)
TOB s1,s2;
{
strcpy(tob_string(s1),tob_string(s2));
return(s1);
}
TOB L_strncpy(s1,s2,n)
TOB s1,s2,n;
{
strncpy(tob_string(s1),tob_string(s2),tob_uint(n));
return(s1);
}
TOB L_strcat(s1,s2)
TOB s1,s2;
{
strcat(tob_string(s1),tob_string(s2));
return(s1);
}
TOB L_strncat(s1,s2,n)
TOB s1,s2,n;
{
strncat(tob_string(s1),tob_string(s2),tob_uint(n));
return(s1);
}
TOB L_strcmp(s1,s2)
TOB s1,s2;
{
return(int_tob(strcmp(tob_string(s1),tob_string(s2))));
}
TOB L_strncmp(s1,s2,n)
TOB s1,s2,n;
{
return(int_tob(strncmp(tob_string(s1),tob_string(s2),tob_uint(n))));
}
TOB L_strchr(s,c) /* strchr is ANSI-C name */
TOB s,c;
{
BYTE *veba;
BYTE *index(); /* index is the old name of the same function */
veba = index(tob_string(s),tob_char(c));
return(veba ? string_tob(veba) : NIL);
}
TOB L_strrchr(s,c) /* strrchr is ANSI-C name */
TOB s,c;
{
BYTE *veba;
BYTE *rindex(); /* rindex is the old name of the same function */
veba = rindex(tob_string(s),tob_char(c));
return(veba ? string_tob(veba) : NIL);
}
TOB L_strlen(s1)
TOB s1;
{
return(int_tob(strlen(tob_string(s1))));
}
/* Note! Don't put here any stringp check for the argument !
(perhaps otherp check can be used, however).
See the note for functions L_argv & L_getenv in the file LISPFUNS.C
*/
TOB L_strdup(s1)
TOB s1;
{
return(stringsave(tob_string(s1)));
}
TOB L_strequ(s1,s2)
TOB s1,s2;
{
return(T_OR_NIL(!strcmp(tob_string(s1),tob_string(s2))));
}
TOB L_monostrequ(s1,s2) /* *strequ */
TOB s1,s2;
{
return(T_OR_NIL(monostrequ(tob_string(s1),tob_string(s2))));
}
TOB L_streq(s1,s2)
TOB s1,s2;
{
return(streq(tob_string(s1),tob_string(s2)) ? s2 : NIL);
}
TOB L_monostreq(s1,s2) /* *streq */
TOB s1,s2;
{
return(monocase_streq(tob_string(s1),tob_string(s2)) ? s2 : NIL);
}
/* (strmatchp string pattern) Returns pattern if matches. */
TOB strmatchp(str,pat)
TOB str,pat;
{
if(!gen_stringp(str) || !gen_stringp(pat)) { return(NIL); }
return(wildcard(tob_string(pat),tob_string(str)) ? pat : NIL);
}
/* (*strmatchp pattern string) Returns string if matches. */
TOB strmatchp2(pat,str)
TOB pat,str;
{
if(!gen_stringp(str) || !gen_stringp(pat)) { return(NIL); }
return(wildcard(tob_string(pat),tob_string(str)) ? str : NIL);
}
/* (istrmatchp string pattern) Returns index information if matches. */
TOB istrmatchp(str,pat)
TOB str,pat;
{
register UINT i;
if(!gen_stringp(str) || !gen_stringp(pat)) { return(NIL); }
return((i = wildcard(tob_string(pat),tob_string(str)))
? int_tob((getlowbyte(i) == 1) ? (i-1) : (i-2))
: NIL);
}
TOB L_convert_string(string,convfun)
TOB string;
TOB convfun;
{
register BYTE *s;
TOB orig_s;
orig_s = string;
s = tob_string(string);
while(*s) { *s = tob_char(apply(convfun,char_tob(*s))); s++; }
return(orig_s);
}
TOB L_substchars(s,c1,c2)
TOB s,c1,c2;
{
return(int_tob(substchars(tob_string(s),tob_char(c1),tob_char(c2))));
}
TOB L_delchars(s,c)
TOB s,c;
{
return(int_tob(delchars(tob_string(s),tob_char(c))));
}
TOB isalphap(c)
TOB c;
{
return((intp(c) && (tob_int(c) < 128) && isalpha(tob_int(c))) ? c : NIL);
}
TOB isupperp(c)
TOB c;
{
return((intp(c) && (tob_int(c) < 128) && isupper(tob_int(c))) ? c : NIL);
}
TOB islowerp(c)
TOB c;
{
return((intp(c) && (tob_int(c) < 128) && islower(tob_int(c))) ? c : NIL);
}
TOB isdigitp(c)
TOB c;
{
return((intp(c) && (tob_int(c) < 128) && isdigit(tob_int(c))) ? c : NIL);
}
TOB isxdigitp(c)
TOB c;
{
return((intp(c) && (tob_int(c) < 128) && isxdigit(tob_int(c))) ? c : NIL);
}
TOB isalnump(c)
TOB c;
{
return((intp(c) && (tob_int(c) < 128) && isalnum(tob_int(c))) ? c : NIL);
}
TOB isspacep(c)
TOB c;
{
return((intp(c) && (tob_int(c) < 128) && isspace(tob_int(c))) ? c : NIL);
}
TOB ispunctp(c)
TOB c;
{
return((intp(c) && (tob_int(c) < 128) && ispunct(tob_int(c))) ? c : NIL);
}
TOB iscntrlp(c)
TOB c;
{
return((intp(c) && (tob_int(c) < 128) && iscntrl(tob_int(c))) ? c : NIL);
}
TOB isprintp(c)
TOB c;
{
return((intp(c) && (tob_int(c) < 128) && isprint(tob_int(c))) ? c : NIL);
}
TOB isgraphp(c)
TOB c;
{
return((intp(c) && (tob_int(c) < 128) && isgraph(tob_int(c))) ? c : NIL);
}
TOB isasciip(c)
TOB c;
{
return((intp(c) && (tob_int(c) < 128)) ? c : NIL);
}
TOB isoctdigitp(c)
TOB c;
{
return((intp(c) && isoctdigit(tob_int(c))) ? c : NIL);
}
TOB L_tolower(c)
TOB c;
{
return(isupper(tob_int(c)) ? char_tob(_tolower(tob_int(c))) : c);
}
TOB L_toupper(c)
TOB c;
{
return(islower(tob_int(c)) ? char_tob(_toupper(tob_int(c))) : c);
}
/* ibm_scand2asc & asc_scand2ibm are defined in parsechr.c
Sorry, names are somewhat inconsistent...
*/
TOB L_ibm2sevenbit(c) /* Convert ibm-scandis to 7-bit-scandis. */
TOB c;
{
return(int_tob(ibm_scand2asc(tob_char(c))));
}
TOB L_sevenbit2ibm(c) /* And vice versa... */
TOB c;
{
return(int_tob(asc_scand2ibm(tob_char(c))));
}
/* Default bits in {,},|,[,] and \ characters in ctp_ table */
/* This belongs to same group as those other: */
#define SCAND_DEFAULT ctp_['_'+1]
#define UAVAL ctp_['A'+1] /* Ascii Uppercase Value */
#define LAVAL ctp_['a'+1] /* lowercase value */
/* This sets scandinavian mode if argument is non-nil, otherwise clears it.
Returns as result the previous mode, i.e. NIL or T
That is, it sets bits of the some special characters (which are used
as diacritic letters in some european languages) so that "issomething"
macros of C, defined in ctype.h, think that they are normal letters.
*/
TOB setscandmode(flag)
TOB flag;
{
int result;
result = (ctp_['|'+1] != SCAND_DEFAULT);
if(!nilp(flag)) /* Set scandinavian mode */
{
/* Uppercase 'special' letters: */
ctp_['@'+1] = UAVAL; /* Some kind of French E with accent */
ctp_['['+1] = UAVAL; /* A with dots */
ctp_[']'+1] = UAVAL; /* A with one circle (= swedish O) */
ctp_['\\'+1] = UAVAL; /* O with dots */
/* U with dots. This is for Germans & Estonians: */
ctp_['^'+1] = UAVAL;
/* Lowercase 'special' letters: */
ctp_['`'+1] = LAVAL; /* Some kind of French e */
ctp_['{'+1] = LAVAL; /* a with dots */
ctp_['}'+1] = LAVAL; /* a with circle */
ctp_['|'+1] = LAVAL; /* o with dots */
ctp_['~'+1] = LAVAL; /* u with dots. */
}
else /* Remove scandinavian mode */
{
ctp_['@'+1] = SCAND_DEFAULT;
ctp_['['+1] = SCAND_DEFAULT;
ctp_[']'+1] = SCAND_DEFAULT;
ctp_['\\'+1] = SCAND_DEFAULT;
ctp_['^'+1] = SCAND_DEFAULT;
ctp_['`'+1] = SCAND_DEFAULT;
ctp_['{'+1] = SCAND_DEFAULT;
ctp_['}'+1] = SCAND_DEFAULT;
ctp_['|'+1] = SCAND_DEFAULT;
ctp_['~'+1] = SCAND_DEFAULT;
}
return(T_OR_NIL(result));
}