Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

build open-axiom

54513 views
1
/*
2
Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
3
All rights reserved.
4
5
Redistribution and use in source and binary forms, with or without
6
modification, are permitted provided that the following conditions are
7
met:
8
9
- Redistributions of source code must retain the above copyright
10
notice, this list of conditions and the following disclaimer.
11
12
- Redistributions in binary form must reproduce the above copyright
13
notice, this list of conditions and the following disclaimer in
14
the documentation and/or other materials provided with the
15
distribution.
16
17
- Neither the name of The Numerical ALgorithms Group Ltd. nor the
18
names of its contributors may be used to endorse or promote products
19
derived from this software without specific prior written permission.
20
21
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
*/
33
34
/* asq is a mini browser for the AXIOM databases */
35
36
#define VERSION 7
37
/* 040206007 tpd fix anal compiler warnings */
38
/* 030710006 tpd remove share directory */
39
/* 940112005 tpd cleanup of printinfo */
40
/* 931228004 tpd more output to stdout */
41
/* 931228003 tpd properties are flags, output to stdout */
42
/* 931221002 tpd sourcefile was misspelled in pprintinfo */
43
/* 931206001 tpd initial release */
44
45
/* add: asq inv ... look up as an operation */
46
/* add: asq *IN* ... give list of matching domains and abbreviations */
47
48
/* asq -property searchkey */
49
/* property is one of the following flags: (all is the default) */
50
/* (ab) abbreviation (an) ancestors */
51
/* (at) attributes (ca cc) constructorcategory */
52
/* (cf fo) constructorform (ck ki) constructorkind */
53
/* (cm) constructormodemap (con) constructor */
54
/* (cos) cosig (de) defaultdomain */
55
/* (dom) domain (doc) documentation */
56
/* (mo) modemaps (ni) niladic */
57
/* (ob) object (op) operationalist */
58
/* (pr) predicates (so) sourcefile */
59
/*searchkey can be either a domain or its abbreviation. */
60
/* e.g. %s -so Integer */
61
/* will give the source file name written to stdout */
62
63
/* echoargs -- echo the arguments */
64
/* printnoquotes-- print a string with no quote marks */
65
/* printenter -- print on entry */
66
/* printexit -- print on exit */
67
/* readlist -- read the key information as a list (uses global list var)*/
68
/* readstring2 -- read a string (including escape chars) */
69
/* readlist2 -- read a list without smashing the main list uses list2 var*/
70
/* pprintatom -- print anything but a list */
71
/* printlist -- recursively print a list object */
72
/* pprintlist -- recursively pprint a list object */
73
/* printob -- print the object file name (uses printlist) */
74
/* pprintobject -- recursively print an object */
75
/* skiplist -- skip over a list we don't want to print */
76
/* pprintalist -- read an alist and prettyprint it */
77
/* pprint -- prettyprint the information at a given pointer */
78
/* printdomain -- prints the domain name */
79
/* printobject -- print the object file name (uses pprintlist) */
80
/* printconstructorkind -- print the constructorkind data */
81
/* printniladic -- print the niladic property */
82
/* printabbreviation -- print the abbreviation */
83
/* printsourcefile -- print the source file */
84
/* printdefaultdomain -- print the default domain */
85
/* printancestors -- print the ancestors */
86
/* printoperationalist -- print the operationalist */
87
/* printhas -- print a has clause */
88
/* printand -- print an and clause */
89
/* printor -- print an or clause */
90
/* printandor -- print an and/or clause */
91
/* printcond -- prettyprint a list of conditions */
92
/* printattributes -- print the attributes */
93
/* printcosig -- print the cosig property */
94
/* printconstructorform -- print the constructorform property */
95
/* printconstructormodemap -- print the constructormodemap property */
96
/* printmodemaps-- print the modemaps property */
97
/* printconstructorcategory -- print the constructorcategory property */
98
/* printdocumentation -- print the documentation property */
99
/* printpredicates -- print the predicates */
100
/* openinterp -- open the interp.daase file and point at the first key */
101
/* parseinterp -- parse the key gotten from interp.daase */
102
/* openbrowse -- open the browse.daase file and point at the first key */
103
/* parsebrowse -- parse the key gotten from browse.daase */
104
/* opencompress -- open the compress.daase file and point at the first key */
105
/* pprintinfo -- prettyprint the information from the database files */
106
/* fullname -- expand an abbreviation to the full name */
107
/* printhelp -- print the help info */
108
/* main */
109
110
#include "openaxiom-c-macros.h"
111
112
#include <ctype.h>
113
#include <unistd.h>
114
#include <stdlib.h>
115
#include <stdio.h>
116
#include <string.h>
117
118
#include "cfuns.h"
119
using namespace OpenAxiom;
120
121
/* we need to predeclare some functions so their signatures are known */
122
int printandor(char *list);
123
int printlist(char *list);
124
int pprintobject(char *list);
125
int pprintcond(int seekpt,char *path);
126
127
/*defvar*/ char *AXIOM; /* the AXIOM shell variable */
128
129
/*defvar*/ char interppath[256]; /* where the file is */
130
/*defvar*/ FILE *interp; /* what the handle is */
131
/*defvar*/ int seekinterp; /* where in the file? */
132
133
/*defvar*/ char browsepath[256]; /* where the file is */
134
/*defvar*/ FILE *browse; /* what the handle is */
135
/*defvar*/ int seekbrowse; /* where in the file? */
136
137
/*defvar*/ char compresspath[256]; /* where the file is */
138
/*defvar*/ FILE *compress; /* what the handle is */
139
/*defvar*/ int seekcompress; /* where in the file? */
140
141
/*defvar*/ char **ct; /* compressed string array */
142
/*defvar*/ int Nct; /* length of above */
143
144
/*defvar*/ char list[2048]; /* the key for the domain */
145
/*defvar*/ int listptr = 0; /* pointer into list variable */
146
147
/*defvar*/ char list2[65535]; /* the data for an item */
148
/*defvar*/ int listptr2 = 0; /* pointer into list2 variable */
149
150
/*defvar*/ int ppcount=0; /* where the prettyprinter is in the list */
151
/*defvar*/ int indent=6; /* how far over to move this item */
152
153
/*defvar*/ char erasecmd[256]; /* a system command to erase the test file*/
154
155
/* interp.daase entries */
156
/*defvar*/ char domain[256];
157
/*defvar*/ char operationalist[256];
158
/*defvar*/ char constructormodemap[256];
159
/*defvar*/ char modemaps[256];
160
/*defvar*/ char object[256];
161
/*defvar*/ char constructorcategory[256];
162
/*defvar*/ char niladic[256];
163
/*defvar*/ char abbreviation[256];
164
/*defvar*/ char constructor[256];
165
/*defvar*/ char cosig[256];
166
/*defvar*/ char constructorkind[256];
167
/*defvar*/ char defaultdomain[256];
168
/*defvar*/ char ancestors[256];
169
170
/* browse.daase entries */
171
/*defvar*/ char bdomain[256];
172
/*defvar*/ char bsourcefile[256];
173
/*defvar*/ char bconstructorform[256];
174
/*defvar*/ char bdocumentation[256];
175
/*defvar*/ char battributes[256];
176
/*defvar*/ char bpredicates[256];
177
178
/*defun*/ int S2N(char *s)
179
{
180
int i;
181
for (i=0;i<Nct;i++) {
182
if(strcmp(ct[i],s)==0) return -i;
183
}
184
return 1;
185
}
186
187
/*defun*/ const char* N2S(int n)
188
{
189
return ((n<=0 && n>-Nct) ? ct[-n] : "the unknown thing");
190
}
191
192
/*defun*/ int echoargs(int argc, char *argv[])
193
/* echo the arguments */
194
{
195
int i;
196
for (i=0; i < argc; i++)
197
printf("%d=%s%s",i,argv[i],(i < argc-1) ? " " : "");
198
printf("\n");
199
return 0;
200
}
201
202
/*defun*/ int printnoquotes(char *chars)
203
{ int i;
204
for (i=0; chars[i] != '\0'; i++)
205
if (chars[i] != '\"') putchar(chars[i]);
206
putchar('\n');
207
return(0);
208
}
209
210
/*defun*/ int printenter(char *name)
211
/* debugging...print on entry */
212
{ int i;
213
printf("\n>enter %s >",name);
214
for (i=0; i < 10; i++) printf("%c",list2[ppcount+i]);
215
printf("<\n");
216
return(0);
217
}
218
219
/*defun*/ int printexit(char *name)
220
/* debugging...print on exit */
221
{ int i;
222
printf("\n<exit %s >",name);
223
for (i=0; i < 10; i++) printf("%c",list2[ppcount+i]);
224
printf("<\n");
225
return(0);
226
}
227
228
/*defun*/ int readlist(FILE *file)
229
/* read the key information as a list (uses global list var) */
230
/* note: this function assumes the caller has done an fseek and read */
231
/* one character which was an '(', starting a list */
232
/* it also assumes that the caller has set listptr to 0 */
233
{
234
int c;
235
list[listptr++]='(';
236
while ((c=fgetc(file)) != EOF)
237
{if ((char)c == ')') break;
238
if ((char)c == '(') readlist(file);
239
else list[listptr++]=(char)c;}
240
list[listptr++]=')';
241
list[listptr]='\0';
242
return(0);
243
}
244
245
/*defun*/ int readstring2(FILE *file)
246
/* read a string (including escape chars) uses (global list2 var) */
247
/* note: this function assumes the caller has done an fseek and read */
248
/* one character which was a '"', starting a string */
249
/* it also assumes that the caller has set listptr2 correctly */
250
{ int c;
251
list2[listptr2++]='"';
252
while ((c=fgetc(file)) != EOF)
253
{if ((char)c == '"') break;
254
if ((char)c == '\\') list2[listptr2++]=fgetc(file);
255
else list2[listptr2++]=(char)c;}
256
list2[listptr2++]='"';
257
list2[listptr2]='\0';
258
return(0);
259
}
260
261
/*defun*/ int readlist2(FILE *file)
262
/* read a list without smashing the main list (uses global list2 var) */
263
/* note: this function assumes the caller has done an fseek and read */
264
/* one character which was an '(', starting a list */
265
/* it also assumes that the caller has set listptr2 to 0 */
266
{
267
int c;
268
list2[listptr2++]='(';
269
while ((c=fgetc(file)) != EOF)
270
{if ((char)c == ')') break;
271
if ((char)c == '"') readstring2(file);
272
if ((char)c == '(') readlist2(file);
273
else list2[listptr2++]=(char)c;}
274
list2[listptr2++]=')';
275
list2[listptr2]='\0';
276
return(0);
277
}
278
279
/*defun*/ int pprintatom(char *list)
280
/* print anything but a list */
281
/* note: this function assumes that list[ppcount] is an atom */
282
{
283
char c;
284
/*printenter("pprintatom");*/
285
while ((c=list[ppcount]) != 0)
286
{
287
if (c == '-') {
288
printf("%s",N2S(atoi(list+ppcount)));
289
while(c=='-' || isdigit(c)) {
290
c=list[++ppcount];
291
}
292
break;
293
}
294
if (c == ' ') {
295
printf("%c",list[ppcount++]);
296
break;
297
}
298
if (c == '(') break;
299
if (c == ')') break;
300
if (c == '|')
301
ppcount ++;
302
else
303
printf("%c",list[ppcount++]);};
304
/*printexit("pprintatom");*/
305
return(0);
306
}
307
308
/*defun*/ int printob(char *list)
309
/* recursively print an object */
310
{ char c;
311
while ((c=list[ppcount]) != 0)
312
{if (list[ppcount] == '(' ) printlist(list);
313
else if (list[ppcount] == ')' ) return(0);
314
else
315
pprintatom(list);}
316
return(0);
317
}
318
319
/*defun*/ int printlist(char *list)
320
/* recursively print a list object */
321
/* note: this function assumes that list[ppcount] is a '(' */
322
{ printf("%c",list[ppcount++]);
323
printob(list);
324
printf("%c",list[ppcount++]);
325
return(0);
326
}
327
328
/*defun*/ int pprintlist(char *list)
329
/* recursively pprint a list object */
330
/* note: this function assumes that list[ppcount] is a '(' */
331
/* it assumes that indent and ppcount have been properly set */
332
{ int i;
333
printf("\n");
334
for (i=indent; i != 0; --i) printf(" ");
335
indent=indent+2;
336
printf("%c",list[ppcount++]);
337
pprintobject(list);
338
printf("%c",list[ppcount++]);
339
indent=indent-2;
340
return(0);
341
}
342
343
/*defun*/ int pprintobject(char *list)
344
/* recursively print an object */
345
{ char c;
346
while ((c=list[ppcount]) != 0)
347
{if (list[ppcount] == '(' ) pprintlist(list);
348
else if (list[ppcount] == ')' ) return(0);
349
else
350
pprintatom(list);}
351
return(0);
352
}
353
354
/*defun*/ int skiplist(char *list)
355
/* skip over a list we don't want to print */
356
{ while (list[ppcount++] != '(');
357
while(list[ppcount] !=')')
358
{if (list[ppcount] == '(')
359
skiplist(list);
360
else
361
ppcount++;}
362
ppcount++;
363
return(0);
364
}
365
366
/*defun*/ int pprintalist(int seekpt,char *path)
367
/* read an alist and prettyprint it */
368
/* note: we reopen the file due to a DJGPP fseek bug */
369
{ char c;
370
int i;
371
FILE *file;
372
file=fopen(path,"r");
373
fseek(file,seekpt,SEEK_SET);
374
listptr2=0;
375
if ((c=fgetc(file)) == '(')
376
readlist2(file);
377
else
378
{ list2[listptr2++]=c;
379
while (! isspace(c = fgetc(file))) list2[listptr2++]=c;};
380
list2[listptr2]='\0';
381
fclose(file);
382
ppcount=0; /*printenter("pprintalist");*/
383
if (list2[0] != '(')
384
pprintatom(list2);
385
else
386
while (list2[ppcount++] != ')')
387
{while (list2[ppcount++] !='(');
388
printf("\n");
389
for (i=indent; i != 0; --i) printf(" ");
390
if (list2[ppcount] == '(')
391
printlist(list2);
392
else
393
pprintatom(list2);
394
while(list2[ppcount] != ')')
395
if (list2[ppcount] == '(')
396
skiplist(list2);
397
else
398
ppcount++;
399
ppcount++;};
400
/*printexit("printalist");*/
401
return(0);
402
}
403
404
405
/*defun*/ int pprint(int seekpt,char *path)
406
/* prettyprint the information at a given pointer */
407
/* note: we reopen the file due to a DJGPP fseek bug */
408
{ char c;
409
FILE *file;
410
file=fopen(path,"r");
411
listptr2=0;
412
fseek(file,seekpt,SEEK_SET);
413
if ((c=fgetc(file)) == '(')
414
readlist2(file);
415
else
416
{ list2[listptr2++]=c;
417
while (! isspace(c = fgetc(file))) list2[listptr2++]=c;}
418
list2[listptr2]='\0';
419
fclose(file);
420
ppcount=0;
421
pprintobject(list2);
422
printf("\n");
423
return(0);
424
}
425
426
/*defun*/ int printdomain()
427
/* prints the domain name */
428
{
429
printf("%s\n",N2S(atoi(domain)));
430
return(0);
431
}
432
433
/*defun*/ int printobject(int all)
434
/* print the object file name */
435
{ char stripped[256];
436
int i;
437
for (i=1; object[i] != '"'; i++) stripped[i-1]=object[i];
438
stripped[i-1]='\0';
439
printf("...loading info not available yet\n");
440
/*
441
if (all == 1)
442
printf("...will load from %s/algebra/%s.o\n",AXIOM,stripped);
443
else
444
printf("%s/algebra/%s.o\n",AXIOM,stripped);
445
*/
446
return(0);
447
}
448
449
/*defun*/ int printconstructorkind(int all)
450
/* print the constructorkind data */
451
{if (all == 1)
452
printf("...is a %s\n",N2S(atoi(constructorkind)));
453
else
454
printf("%s\n",N2S(atoi(constructorkind)));
455
return(0);
456
}
457
458
/*defun*/ int printniladic(int all)
459
/* print the niladic property */
460
{ if (niladic[0] == 'T')
461
if (all == 1)
462
printf("...is niladic\n");
463
else
464
printf("niladic\n");
465
else
466
if (all == 1)
467
printf("...is not niladic\n");
468
else
469
printf("padic\n");
470
return(0);
471
}
472
473
/*defun*/ int printabbreviation(int all)
474
/* print the abbreviation */
475
{ if (all == 1)
476
printf("...is abbreviated as %s\n",abbreviation);
477
else
478
printf("%s\n",abbreviation);
479
return(0);
480
}
481
482
/*defun*/ int printsourcefile(int all)
483
/* print the source file */
484
{ if (all == 1)
485
printf("...is defined in the source file %s\n",bsourcefile);
486
else
487
printnoquotes(bsourcefile);
488
return(0);
489
}
490
491
/*defun*/ int printdefaultdomain(int all)
492
/* print the default domain */
493
{ int i;
494
if (strcmp(defaultdomain,"NIL") == 0)
495
if (all == 1)
496
printf("...has no default domain\n");
497
else
498
printf("NIL\n");
499
else
500
if (all == 1)
501
{printf("...has a default domain of ");
502
for (i=1; defaultdomain[i] != '|'; i++) putchar(defaultdomain[i]);
503
printf("\n");}
504
else
505
{for (i=1; defaultdomain[i] != '|'; i++) putchar(defaultdomain[i]);
506
printf("\n");}
507
return(0);
508
}
509
510
/*defun*/ int printancestors(int pretty)
511
/* print the ancestors */
512
{ if (strcmp(ancestors,"NIL") == 0)
513
printf("...has no ancestors\n");
514
else
515
{seekinterp=atoi(ancestors)+1;
516
printf("...has the ancestors: ");
517
if (pretty == 1)
518
{ppcount=0;
519
pprintcond(seekinterp,interppath);
520
printf("\n");}
521
else
522
printf("%d\n",seekinterp);}
523
return(0);
524
}
525
526
/*defun*/ int printoperationalist(int pretty)
527
/* print the operationalist */
528
{ /*printenter("printoperationalist");*/
529
if (strcmp(operationalist,"NIL") == 0)
530
printf("...has no operationalist\n");
531
else
532
{seekinterp=atoi(operationalist)+1;
533
printf("...has the operations: ");
534
if (pretty == 1)
535
{pprintalist(seekinterp,interppath);
536
printf("\n");}
537
else
538
printf("%d\n",seekinterp);};
539
/*printexit("printoperationalist");*/
540
return(0);
541
}
542
543
/*defun*/ int printhas(char *list)
544
/* print a has clause */
545
/* note: assumes ppcount points at the |has| */
546
{ /*printenter("printhas");*/
547
printf(" if ");
548
ppcount=ppcount+6;
549
if (list2[ppcount] == '(')
550
{printlist(list2);
551
printf(" ");
552
ppcount++;}
553
else
554
pprintatom(list2);
555
printf("has ");
556
if (list2[ppcount] == '(')
557
printlist(list2);
558
else
559
pprintatom(list2);
560
ppcount++;
561
/*printexit("printhas");*/
562
return(0);
563
}
564
565
/*defun*/ int printand(char *list)
566
/* print an and clause */
567
/* note: assumes ppcount points at the AND */
568
{ /*printenter("printand");*/
569
if ((list2[ppcount] == '|') && (list2[ppcount+1] == 'a')) ppcount=ppcount+2;
570
ppcount=ppcount+5;
571
printandor(list2);
572
ppcount++;
573
while (list2[ppcount] == '(')
574
{printf(" and");
575
ppcount++;
576
printandor(list2);
577
ppcount++;}
578
/*printexit("printand");*/
579
return(0);
580
}
581
582
/*defun*/ int printor(char *list)
583
/* print an or clause */
584
/* note: assumes ppcount points at the OR */
585
{ /*printenter("printor");*/
586
ppcount=ppcount+4;
587
printandor(list2);
588
ppcount++;
589
while (list2[ppcount] == '(')
590
{printf(" or");
591
ppcount++; /*=ppcount+2; */
592
printandor(list2);
593
ppcount++;}
594
/*printexit("printor");*/
595
return(0);
596
}
597
598
/*defun*/ int printandor(char *list)
599
/* print an and/or clause */
600
/* note: this function assumes that list[ppcount] is a '(' */
601
{ /*printenter("printandor");*/
602
if ((list2[ppcount] == '|') && (list2[ppcount+1] == 'a')) printand(list2);
603
if (list2[ppcount] == '|') printhas(list2);
604
if (list2[ppcount] == 'A') printand(list2);
605
if (list2[ppcount] == 'O') printor(list2);
606
/*printexit("printandor");*/
607
return(0);
608
}
609
610
/*defun*/ int pprintcond(int seekpt,char *path)
611
/* prettyprint a list of conditions */
612
/* note: we reopen the file due to a DJGPP fseek bug */
613
{ char c;
614
int i;
615
FILE *file;
616
file=fopen(path,"r");
617
fseek(file,seekpt,SEEK_SET);
618
listptr2=0;
619
if ((c=fgetc(file)) == '(')
620
readlist2(file);
621
else
622
{ list2[listptr2++]=c;
623
while (! isspace(c = fgetc(file))) list2[listptr2++]=c;};
624
list2[listptr2]='\0';
625
fclose(file);
626
ppcount=0;
627
/*printf("data=%s\n",list2);*/
628
if (list2[0] != '(') /* the whole list */
629
pprintatom(list2);
630
else
631
while (list2[ppcount++] != ')') /* until the whole list ends */
632
{while (list2[ppcount++] !='('); /* do one alist item */
633
printf("\n");
634
for (i=indent; i != 0; --i) printf(" ");
635
if (list2[ppcount] == '(') /* print the car */
636
printlist(list2);
637
else
638
pprintatom(list2);
639
while(isspace(list2[ppcount])) ppcount++;
640
/*printf("char=%c\n",list2[ppcount]);*/
641
if (list2[ppcount] != '.') /* is it (foo . T)? */
642
printandor(list2); /* and print the non-T ones */
643
else
644
while(list2[ppcount++] !=')');}; /* skip the . T ) */
645
return(0);
646
}
647
648
/*defun*/ int printattributes(int pretty)
649
/* print the attributes */
650
{if (strcmp(battributes,"NIL") == 0)
651
printf("...has no attributes\n");
652
else
653
{seekbrowse=atoi(battributes)+1;
654
printf("...has the attributes: ");
655
if (pretty == 1)
656
{pprintcond(seekbrowse,browsepath);
657
printf("\n");}
658
else
659
printf("%d\n",seekbrowse);};
660
return(0);
661
}
662
663
/*defun*/ int printcosig()
664
/* print the cosig property */
665
{ printf("...has the cosig: %s\n",cosig);
666
return(0);
667
}
668
669
/*defun*/ int printconstructorform(int pretty)
670
/* print the constructorform property */
671
{ FILE *file;
672
/*printenter("printconstructorform");*/
673
seekbrowse=atoi(bconstructorform)+1;
674
printf("...has the constructorform: ");
675
if (pretty == 1)
676
{file=fopen(browsepath,"r");
677
fseek(file,seekbrowse,SEEK_SET);
678
fgetc(file);
679
listptr2=0;
680
readlist2(file);
681
listptr2=0;
682
ppcount=0;
683
pprintlist(list2);
684
printf("\n");}
685
else
686
printf("%d\n",seekbrowse);
687
/*printexit("printconstructorform");*/
688
return(0);
689
}
690
691
/*defun*/ int printconstructormodemap(int pretty)
692
/* print the constructormodemap property */
693
{ FILE *file;
694
/*printenter("printconstructormodemap"); */
695
seekinterp=atoi(constructormodemap)+1;
696
printf("...has the constructormodemap: ");
697
if (pretty == 1)
698
{file=fopen(interppath,"r");
699
fseek(file,seekinterp,SEEK_SET);
700
fgetc(file);
701
listptr2=0;
702
readlist2(file);
703
listptr2=0;
704
ppcount=0;
705
pprintlist(list2);
706
printf("\n");}
707
else
708
printf("%d\n",seekinterp);
709
/*printexit("printconstructormodemap");*/
710
return(0);
711
}
712
713
/*defun*/ int printmodemaps(int pretty)
714
/* print the modemaps property */
715
{ FILE *file;
716
/*printenter("printmodemaps"); */
717
seekinterp=atoi(modemaps)+1;
718
if (pretty == 1)
719
{file=fopen(interppath,"r");
720
fseek(file,seekinterp,SEEK_SET);
721
if (fgetc(file) == 'N')
722
printf("...has no modemaps\n");
723
else
724
{printf("...has the modemaps: ");
725
listptr2=0;
726
readlist2(file);
727
listptr2=0;
728
ppcount=0;
729
pprintlist(list2);
730
printf("\n");};}
731
else
732
printf("%d\n",seekinterp);
733
/* printexit("printmodemaps");*/
734
return(0);
735
}
736
737
/*defun*/ int printconstructorcategory(int pretty)
738
/* print the constructorcategory property */
739
{ FILE *file;
740
/*printenter("printconstructorcategory"); */
741
seekinterp=atoi(constructorcategory)+1;
742
printf("...has the constructorcategory: ");
743
if (pretty == 1)
744
{file=fopen(interppath,"r");
745
fseek(file,seekinterp,SEEK_SET);
746
fgetc(file);
747
listptr2=0;
748
readlist2(file);
749
listptr2=0;
750
ppcount=0;
751
pprintlist(list2);
752
printf("\n");}
753
else
754
printf("%d\n",seekinterp);
755
/*printexit("printconstructorcategory");*/
756
return(0);
757
}
758
759
/*defun*/ int printdocumentation(int pretty)
760
/* print the documentation property */
761
{ FILE *file;
762
/*printenter("printdocumentation");*/
763
seekbrowse=atoi(bdocumentation)+1;
764
if (pretty == 1)
765
{file=fopen(browsepath,"r");
766
fseek(file,seekbrowse,SEEK_SET);
767
if (fgetc(file) == 'N')
768
printf("...has no documentation\n");
769
else
770
{printf("...has the documentation: ");
771
listptr2=0;
772
readlist2(file);
773
listptr2=0;
774
ppcount=0;
775
pprintlist(list2);
776
printf("\n");};}
777
else
778
printf("%d\n",seekbrowse);
779
/*printexit("printdocumentation");*/
780
return(0);
781
}
782
783
/*defun*/ int printpredicates(int pretty)
784
/* print the predicates */
785
{ FILE *file;
786
/*printenter("printpredicates");*/
787
{seekbrowse=atoi(bpredicates)+1;
788
if (pretty == 1)
789
{file=fopen(browsepath,"r");
790
fseek(file,seekbrowse,SEEK_SET);
791
if (fgetc(file) == 'N')
792
printf("...has no predicates\n");
793
else
794
{printf("...has the predicates: ");
795
listptr2=0;
796
readlist2(file);
797
listptr2=0;
798
ppcount=0;
799
pprintlist(list2);
800
printf("\n");};}
801
else
802
printf("%d\n",seekbrowse);};
803
/*printexit("printpredicates");*/
804
return(0);
805
}
806
807
/*defun*/ int opencompress()
808
/* open the compress.daase file and point at the first key */
809
{ char line[256];
810
char other[256];
811
int count = 256;
812
int i;
813
if (AXIOM != NULL)
814
sprintf(compresspath,"%s/algebra/compress.daase",AXIOM);
815
else
816
sprintf(compresspath,"compress.daase");
817
compress=fopen(compresspath,"r");
818
if (compress == NULL)
819
{printf("unable to find the file %s\n",compresspath);
820
exit(1);};
821
fseek(compress,1,SEEK_SET);
822
if (fgets(line,count,compress) == NULL)
823
printf("get failed\n");
824
else
825
for (i=1; ! isspace(line[i]); i++) other[i-1]=line[i];
826
seekcompress=atoi(other)+2;
827
return(0);
828
}
829
830
/*defun*/ int openinterp()
831
/* open the interp.daase file and point at the first key */
832
{ char line[256];
833
char other[256];
834
int count = 256;
835
int i;
836
if (AXIOM != NULL)
837
sprintf(interppath,"%s/algebra/interp.daase",AXIOM);
838
else
839
sprintf(interppath,"interp.daase");
840
interp=fopen(interppath,"r");
841
if (interp == NULL)
842
{printf("unable to find the file %s\n",interppath);
843
exit(1);};
844
fseek(interp,1,SEEK_SET);
845
if (fgets(line,count,interp) == NULL)
846
printf("get failed\n");
847
else
848
for (i=1; ! isspace(line[i]); i++) other[i-1]=line[i];
849
seekinterp=atoi(other)+2;
850
return(0);
851
}
852
853
/*defun*/ int parseinterp()
854
/* parse the key gotten from interp.daase */
855
{ int i;
856
int j;
857
for ((i=1, j=0); ! isspace(list[i]); (i++,j++))
858
domain[j]=list[i];
859
domain[j]='\0';
860
for ((i++,j=0); ! isspace(list[i]); (i++,j++))
861
operationalist[j]=list[i];
862
operationalist[j]='\0';
863
for ((i++,j=0); ! isspace(list[i]); (i++,j++))
864
constructormodemap[j]=list[i];
865
constructormodemap[j]='\0';
866
for ((i++,j=0); ! isspace(list[i]); (i++,j++))
867
modemaps[j]=list[i];
868
modemaps[j]='\0';
869
for ((i++,j=0); ! isspace(list[i]); (i++,j++))
870
object[j]=list[i];
871
object[j]='\0';
872
for ((i++,j=0); ! isspace(list[i]); (i++,j++))
873
constructorcategory[j]=list[i];
874
constructorcategory[j]='\0';
875
for ((i++,j=0); ! isspace(list[i]); (i++,j++))
876
niladic[j]=list[i];
877
niladic[j]='\0';
878
for ((i++,j=0); ! isspace(list[i]); (i++,j++))
879
abbreviation[j]=list[i];
880
abbreviation[j]='\0';
881
for ((i++,j=0); (list[i] != ')'); (i++,j++))
882
cosig[j]=list[i];
883
cosig[j++]=')';
884
i++;
885
cosig[j]='\0';
886
for ((i++,j=0); ! isspace(list[i]); (i++,j++))
887
constructorkind[j]=list[i];
888
constructorkind[j]='\0';
889
for ((i++,j=0); ! isspace(list[i]); (i++,j++))
890
defaultdomain[j]=list[i];
891
defaultdomain[j]='\0';
892
for ((i++,j=0); (list[i] != ')'); (i++,j++))
893
ancestors[j]=list[i];
894
ancestors[j]='\0';
895
return(0);
896
}
897
898
899
/*defun*/ int openbrowse()
900
/* open the browse.daase file and point at the first key */
901
{
902
char line[256];
903
char other[256];
904
int count = 256;
905
int i;
906
if (AXIOM != NULL)
907
sprintf(browsepath,"%s/algebra/browse.daase",AXIOM);
908
else
909
sprintf(browsepath,"browse.daase");
910
browse=fopen(browsepath,"r");
911
if (browse == NULL)
912
{printf("unable to find the file %s\n",browsepath);
913
exit(1);};
914
fseek(browse,1,SEEK_SET);
915
if (fgets(line,count,browse) == NULL)
916
printf("get failed\n");
917
else
918
for (i=1; ! isspace(line[i]); i++) other[i-1]=line[i];
919
seekbrowse=atoi(other)+2;
920
return(0);
921
}
922
923
/*defun*/ int parsebrowse()
924
/* parse the key gotten from browse.daase */
925
{ int i;
926
int j;
927
for ((i=1, j=0); ! isspace(list[i]); (i++,j++)) bdomain[j]=list[i];
928
bdomain[j]='\0';
929
for ((i++, j=0); ! isspace(list[i]); (i++,j++)) bsourcefile[j]=list[i];
930
bsourcefile[j]='\0';
931
for ((i++, j=0); ! isspace(list[i]); (i++,j++)) bconstructorform[j]=list[i];
932
bconstructorform[j]='\0';
933
for ((i++, j=0); ! isspace(list[i]); (i++,j++)) bdocumentation[j]=list[i];
934
bdocumentation[j]='\0';
935
for ((i++, j=0); ! isspace(list[i]); (i++,j++)) battributes[j]=list[i];
936
battributes[j]='\0';
937
for ((i++, j=0); ! isspace(list[i]); (i++,j++)) bpredicates[j]=list[i];
938
bpredicates[j]='\0';
939
return(0);
940
}
941
942
/*defun*/ int pprintinfo(const char* property)
943
/* prettyprint the information from the database files */
944
{ int pretty = 1; /* print pretty form for any option */
945
int all = 0; /* only print the option specificed */
946
/*printenter("pprintinfo");*/
947
if (strcmp(property,"short") == 0) {pretty=0; all=1;}
948
if (strcmp(property,"all") == 0) all=1;
949
if (all) printf("\n");
950
if (all || (strcmp(property,"domain") == 0))
951
printdomain();
952
if (all || (strcmp(property,"sourcefile") == 0))
953
printsourcefile(all);
954
if (all || (strcmp(property,"object" ) == 0))
955
printobject(all);
956
if (all || (strcmp(property,"constructorkind")) == 0)
957
printconstructorkind(all);
958
if (all || (strcmp(property,"niladic") == 0))
959
printniladic(all);
960
if (all || (strcmp(property,"abbreviation") == 0))
961
printabbreviation(all);
962
if (all || (strcmp(property,"defaultdomain") == 0))
963
printdefaultdomain(all);
964
if (all || (strcmp(property,"ancestors") == 0))
965
printancestors(pretty);
966
if (all || (strcmp(property,"operationalist") == 0))
967
printoperationalist(pretty);
968
if (all || (strcmp(property,"attributes") == 0))
969
printattributes(pretty);
970
if (all || (strcmp(property,"cosig") == 0))
971
printcosig();
972
if (all || (strcmp(property,"constructorform") == 0))
973
printconstructorform(pretty);
974
if (all || (strcmp(property,"constructormodemap") == 0))
975
printconstructormodemap(pretty);
976
if (all || (strcmp(property,"modemaps") == 0))
977
printmodemaps(pretty);
978
if (all || (strcmp(property,"constructorcategory") == 0))
979
printconstructorcategory(pretty);
980
if (all || (strcmp(property,"documentation") == 0))
981
printdocumentation(pretty);
982
if (all || (strcmp(property,"predicates") == 0))
983
printpredicates(pretty);
984
/*printexit("pprintinfo");*/
985
return(0);
986
}
987
988
/*defun*/ const char* fullname(char *property, char *progname)
989
/* expand an abbreviation to the full name */
990
{ if (strncmp(property,"ab",2) == 0) return "abbreviation";
991
else if (strncmp(property,"al",2) == 0) return "all";
992
else if (strncmp(property,"an",2) == 0) return "ancestors";
993
else if (strncmp(property,"at",2) == 0) return "attributes";
994
else if (strncmp(property,"ca",2) == 0) return "constructorcategory";
995
else if (strncmp(property,"cc",2) == 0) return "constructorcategory";
996
else if (strncmp(property,"cf",2) == 0) return "constructorform";
997
else if (strncmp(property,"fo",2) == 0) return "constructorform";
998
else if (strncmp(property,"ck",2) == 0) return "constructorkind";
999
else if (strncmp(property,"ki",2) == 0) return "constructorkind";
1000
else if (strncmp(property,"cm",2) == 0) return "constructormodemap";
1001
else if (strncmp(property,"con",3) == 0) return "constructor";
1002
else if (strncmp(property,"cos",3) == 0) return "cosig";
1003
else if (strncmp(property,"de",2) == 0) return "defaultdomain";
1004
else if (strncmp(property,"dom",3) == 0) return "domain";
1005
else if (strncmp(property,"doc",3) == 0) return "documentation";
1006
else if (strncmp(property,"mo",2) == 0) return "modemaps";
1007
else if (strncmp(property,"ni",2) == 0) return "niladic";
1008
else if (strncmp(property,"ob",2) == 0) return "object";
1009
else if (strncmp(property,"op",2) == 0) return "operationalist";
1010
else if (strncmp(property,"pr",2) == 0) return "predicates";
1011
else if (strncmp(property,"sh",2) == 0) return "short";
1012
else if (strncmp(property,"so",2) == 0) return("sourcefile");
1013
printf("I don't know what %s means. I'll use 'short'\n",property);
1014
printf("type %s with no arguments to get the usage page\n",progname);
1015
return "short";
1016
}
1017
1018
/*defun*/ int printhelp(const char* arg)
1019
{printf("%s -property searchkey \n\n",arg);
1020
printf("property is one of the following flags: \n");
1021
printf(" (al) all (default) (sh) short\n");
1022
printf(" (ab) abbreviation (an) ancestors\n");
1023
printf(" (at) attributes (ca cc) constructorcategory\n");
1024
printf(" (cf fo) constructorform (ck ki) constructorkind\n");
1025
printf(" (cm) constructormodemap (con) constructor\n");
1026
printf(" (cos) cosig (de) defaultdomain\n");
1027
printf(" (dom) domain (doc) documentation\n");
1028
printf(" (mo) modemaps (ni) niladic\n");
1029
printf(" (ob) object (op) operationalist\n");
1030
printf(" (pr) predicates (so) sourcefile\n");
1031
printf("searchkey can be either a domain or its abbreviation.\n");
1032
printf("\n e.g. %s -so Integer\n",arg);
1033
printf(" will give the source file name written to stdout\n");
1034
printf(" (Version %d)\n",VERSION);
1035
return(0);
1036
}
1037
1038
/*defun*/ int main(int argc, char *argv[])
1039
{
1040
/* FILE *test; when testing we leave tombstones */
1041
const char* ssearch =""; /* the domain or abbreviation */
1042
const char* property=""; /* the property we want (e.g. niladic) */
1043
int found=1; /* did we find the domain? print if yes */
1044
char c; /* a temporary */
1045
int i; /* a temporary */
1046
char proparg[256]; /* a temporary */
1047
/* echoargs(argc, argv);*/
1048
AXIOM=oa_getenv("AXIOM");
1049
if (AXIOM == NULL)
1050
printf("AXIOM shell variable has no value. using current directory\n");
1051
1052
/* if we have no argument tell him how it works */
1053
if ((argv[1] == NULL) || (strcmp(argv[1],"") == 0))
1054
{printhelp(argv[0]);
1055
exit(1);}
1056
1057
/* we have at least one argument; lets see what it is */
1058
if (strncmp(argv[1],"-",1) == 0) /* is it a flag? */
1059
{for (i=1; argv[1][i] != '\0'; i++) proparg[i-1]=argv[1][i];
1060
property=fullname(proparg,argv[0]);
1061
if ((argv[2] == NULL) || (strcmp(argv[2],"") == 0))
1062
{printhelp(argv[0]);
1063
exit(1);}
1064
ssearch=argv[2];}
1065
else /* nope, assume a domain */
1066
if ((argv[2] == NULL) || (strcmp(argv[2],"") == 0))
1067
{property="all";
1068
ssearch=argv[1];}
1069
1070
/* printf("property=%s\n",property);*/
1071
/* printf("ssearch=%s\n",ssearch);*/
1072
opencompress();
1073
fseek(compress,seekcompress,SEEK_SET);
1074
fscanf(compress,"%d",&Nct);
1075
ct = (char**) malloc(Nct*sizeof(char *));
1076
/* put entries in ct */
1077
{
1078
int foo1,foo2;
1079
for (foo1=0;foo1<Nct;foo1++) {
1080
foo2=0;
1081
while(isspace(c=fgetc(compress)) || c=='|') {};
1082
list[foo2++]=c;
1083
while(1) {
1084
c=fgetc(compress);
1085
if (isspace(c) || c == ')' ) break;
1086
if (c != '|') list[foo2++] = c;
1087
}
1088
list[foo2]='\0';
1089
ct[foo1]=strdup(list);
1090
}
1091
}
1092
/* -n correspons to string ct[n] */
1093
openinterp();
1094
if (strcmp(property,"all") == 0)
1095
printf("Searching %s for %s\n",interppath,ssearch);
1096
while (1)
1097
{
1098
fseek(interp,seekinterp,SEEK_SET);
1099
if ((c=fgetc(interp)) != '(')
1100
{
1101
printf("%s not found\n",ssearch);
1102
found=0;
1103
break;};
1104
readlist(interp);
1105
seekinterp=seekinterp+listptr+1;
1106
listptr=0;
1107
parseinterp();
1108
if (strcmp(ssearch,N2S(atoi(domain))) == 0) break;
1109
if (strcmp(ssearch,abbreviation) == 0)
1110
{
1111
ssearch=N2S(atoi(domain));
1112
break;
1113
}
1114
}
1115
1116
openbrowse();
1117
if (strcmp(property,"all") == 0)
1118
printf("Searching %s for %s\n",browsepath,ssearch);
1119
while (1)
1120
{fseek(browse,seekbrowse,SEEK_SET);
1121
if ((c=fgetc(browse)) != '(')
1122
{printf("%s not found\n",ssearch);
1123
found=0;
1124
break;};
1125
readlist(browse);
1126
seekbrowse=seekbrowse+listptr+1;
1127
listptr=0;
1128
parsebrowse();
1129
if (strcmp(ssearch,N2S(atoi(bdomain))) == 0) break;};
1130
1131
if (found == 1) pprintinfo(property);
1132
1133
/* code won't get here if it crashes, leaving the tombstone */
1134
if ((argv[2] != NULL) && (strcmp(argv[2],"test") == 0))
1135
{sprintf(erasecmd,"erase %s",argv[1]);
1136
system(erasecmd);}
1137
return(0);
1138
}
1139
1140
1141