Repository navigation
Expand file tree
/
Copy pathellec.c
More file actions
executable file
·1404 lines (1224 loc) · 31.9 KB
/
Copy pathellec.c
File metadata and controls
executable file
·1404 lines (1224 loc) · 31.9 KB
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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ELLEC - Copyright 1983 by Ken Harrenstien, SRI International
* This software is quasi-public; it may be used freely with
* like software, but may NOT be sold or made part of licensed
* products without permission of the author.
*/
/* ELLEC - ELLE Compiler
* Invoked with no arguments, acts as general ELLE compiler filter;
* reads ASCII profile input, and outputs a binary profile.
* Otherwise:
* -Profile Compiles user's profile.
* HOME/.ellepro.e -> HOME/.ellepro.bN (N = fmt version #)
* NOTE: on V6, "HOME/" is left out.
* -Pconf Outputs defprf.c for ELLE (accepts std in) (old -E)
* -Fconf Outputs eefdef.h for ELLE (accepts std in)
* -FXconf Outputs eefidx.h for ELLE (accepts std in)
* -CMconf Outputs config makefile for ELLE ( " )
* -CSconf arg Outputs config file using "arg" - for V6 config.v6 file.
* -Pdump Outputs defprf.e user profile (old -P)
* -Fdump Outputs deffun.e
*/
#if 0
The ASCII profile file associates command chars with functions.
It is simply a series of lisp-like expressions of the form
(keybind <char spec> <fun spec>)
e.g. (keybind "C-Y" "Yank Pop")
Command char specification:
Allowed prefixes:
<ch> The char itself
C- Controlify (zap bits 140)
^<ch> Ditto
M- Meta (add bit 200) - case ignored
X- Extended (add bit) - case ignored
To quote a char or char spec, use quoted-string syntax.
Function name specification:
Function names are specified by quoted strings containing the entire
long-form ASCII function name. Matching is done case-independently.
#endif /*COMMENT*/
#include "eesite.h" /* Site specific stuff if any */
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include "eeprof.h" /* Profile structure definition */
#define EFUNMAX 400 /* Maximum # (+1) of functions that can be defined */
#define KBTSIZ (128*2) /* Initial size of key binding tables */
/* EFUN Function definition table.
** Functions that were copied from the pre-defined table will
** have a value of NULL in ef_mod.
*/
struct fun {
int ef_idx; /* Function index (same as index of entry) */
char *ef_name; /* Function name */
char *ef_adr; /* C routine name in ELLE */
char *ef_mod; /* Source module that C routine lives in */
};
struct fun efuntab[EFUNMAX];
int efxmax = 0; /* Largest function idx used */
int format_ver = PROF_VER; /* Current version # of binary profile fmt */
/* Keybind mapping tables. There are four separate tables:
** Simple character. Always 128 single-byte items, indexed by the simple
** command char. Each item is the corresponding function index.
** Meta char. Variable number of 2-byte items; first is a command char
** and second is its function index.
** Extended char. Same format as Meta char.
** Menu item (SUN only). Variable number of single-byte items, each
** a function index.
**
*/
char *chrptr; /* Pointer to simple-char table */
int chrsiz = 128; /* Current size of table */
int chrcnt = 0; /* # bytes actually used */
char *mtaptr; /* Pointer to meta-char table */
int mtasiz = KBTSIZ; /* Current size (twice the # of items) */
int mtacnt = 0; /* # bytes actually used */
char *extptr; /* Pointer to ext-char table */
int extsiz = KBTSIZ; /* Current size (twice the # of items) */
int extcnt = 0; /* # bytes actually used */
char *mnuptr; /* Pointer to menu-item table (SUN only) */
int mnusiz = KBTSIZ; /* Current size */
int mnucnt = 0; /* # bytes actually used */
#define CB_EXT 0400 /* "X-" prefix on command char */
#define CB_META 0200 /* "M-" prefix on command char */
/* Set up the pre-defined data areas. This includes the
** predefined function table plus the default profile (keyboard mappings).
** Note this only contains entries for ef_name and ef_adr.
*/
struct fun pdfuntab[] = { /* Pre-Defined Function table */
#define EFUN(rtn,rtnstr,name) 0, name, rtnstr, 0,
#define EFUNHOLE 0, 0, 0, 0,
#include "eefdef.h"
};
int npdfuns = sizeof(pdfuntab)/sizeof(struct fun); /* # of entries */
#include "defprf.c" /* Insert default profile mapping */
/* This defines charmap, metamap, and extmap. */
/* Stuff for feeble-minded list processor */
#define NIL ((struct lnode *)0)
#define LTRUE (<ruenode)
#define LT_VAL 0
#define LT_STR 1
#define LT_LIST 2
#define LT_ATOM 3 /* Should use this later instead of LT_STR */
struct lnode {
struct lnode *lnxt;
int ltyp;
union {
int lvi;
char *lvs;
struct lnode *lvl;
} lval;
};
struct lnode ltruenode; /* Constant TRUE */
_PROTOTYPE(int main , (int argc , char **argv ));
_PROTOTYPE(int doargs , (int argc , char **argv ));
_PROTOTYPE(char **findkey , (char *cp , char ***aretp , char **tabp , int tabsiz , int elsize ));
_PROTOTYPE(int nstrcmp , (char *s1 , char *s2 ));
_PROTOTYPE(int ustrcmp , (char *s1 , char *s2 ));
_PROTOTYPE(int strueq , (char *s1 , char *s2 ));
_PROTOTYPE(int do_opcod , (void));
_PROTOTYPE(int do_opasc , (void));
_PROTOTYPE(int outkbind , (int c , int fx ));
_PROTOTYPE(int do_obprof , (void));
_PROTOTYPE(int mupcase , (int ch ));
_PROTOTYPE(int upcase , (int ch ));
_PROTOTYPE(char *qstr , (char *str ));
_PROTOTYPE(char *charep , (int c ));
_PROTOTYPE(int do_ocnf , (char *str ));
_PROTOTYPE(int do_ofcod , (void));
_PROTOTYPE(int do_ofasc , (void));
_PROTOTYPE(int do_ofxcod , (void));
_PROTOTYPE(int compile_stdin , (void));
_PROTOTYPE(int lrch , (void));
_PROTOTYPE(struct lnode *lread , (void));
_PROTOTYPE(int wspfls , (void));
_PROTOTYPE(struct lnode *lrstr , (int flg ));
_PROTOTYPE(int islword , (int c ));
_PROTOTYPE(struct lnode *eval , (struct lnode *lp ));
_PROTOTYPE(struct lnode *undefall , (struct lnode *lp ));
_PROTOTYPE(struct lnode *efun , (struct lnode *lp ));
_PROTOTYPE(struct lnode *keybind , (struct lnode *lp ));
_PROTOTYPE(struct lnode *keyallun , (void));
_PROTOTYPE(struct lnode *menuitem , (struct lnode *lp ));
_PROTOTYPE(int repchar , (char *str ));
_PROTOTYPE(struct lnode *getln , (void));
_PROTOTYPE(int numcvt , (char *str , int *anum ));
_PROTOTYPE(int listcnt , (struct lnode *lp ));
_PROTOTYPE(char *funname , (int i ));
_PROTOTYPE(int findfun , (char *name ));
_PROTOTYPE(int funcnt , (int *arr ));
_PROTOTYPE(int scpy , (char *from , char *to , int cnt ));
_PROTOTYPE(char *stripsp , (char *cp ));
int warn();
int lerr();
int fatal();
/* ELLEC argument stuff */
char *argfile;
char *outfile;
int swfilter; /* If no args */
int swprof; /* -P */
int swelle; /* -E */
int uproflg; /* Do compilation of user's profile */
int swpcnf; /* Output defprf.c (C initialization of profile) */
int swfcnf; /* Output eefdef.h */
int swfxcnf; /* Output eefidx.h */
int swcmcnf; /* Output config makefile (makecf.fun) */
char *swcscnf; /* Output config specially (for V6) */
int swallc; /* Do all of config stuff */
int swfdmp; /* Output deffun.e */
int nfiles; /* # file specs seen */
main(argc,argv)
int argc;
char **argv;
{ register int i;
register char *cp;
char temp[300];
/* Initialize LTRUE
** (cannot portably initialize a union at compile time)
*/
ltruenode.ltyp = LT_VAL; /* Set type (other fields zero) */
/* Process switches */
if(argc <= 1) swfilter++; /* If no args, assume filter */
else doargs(argc,argv);
/* Initialize function definitions and key bindings from predefs */
chrptr = malloc(chrsiz);
mtaptr = malloc(mtasiz);
extptr = malloc(extsiz);
mnuptr = malloc(mnusiz);
if (!chrptr || !mtaptr || !extptr || !mnuptr)
fatal("cannot init, no memory");
scpy(charmap, chrptr, (chrcnt = sizeof(charmap)));
scpy(metamap, mtaptr, (mtacnt = sizeof(metamap)));
scpy( extmap, extptr, (extcnt = sizeof(extmap)));
if(def_prof.menuvec)
scpy(def_prof.menuvec, mnuptr, (mnucnt = def_prof.menuvcnt));
for(i = 0; i < npdfuns; ++i) /* Initialize function defs */
if(pdfuntab[i].ef_name)
{ efuntab[i].ef_idx = i;
efuntab[i].ef_name = pdfuntab[i].ef_name;
efuntab[i].ef_adr = stripsp(pdfuntab[i].ef_adr);
if(efxmax < i) efxmax = i;
}
/* Routines expect input from stdin and output their results
* to stdout.
*/
if(argfile)
if(freopen(argfile,"r",stdin) == NULL)
fatal("cannot open input file \"%s\"",argfile);
if(outfile)
if(freopen(outfile,"w",stdout) == NULL)
fatal("cannot open output file \"%s\"",outfile);
/* Check for general compilation */
if(swfilter)
{ /* Not really implemented yet */
fatal("bad usage, see doc");
}
/* Do profile hacking of some kind */
if(swprof || swelle)
{ if (compile_stdin()) /* Compile input profile */
{ if(swprof)
do_opasc(); /* Output ASCII profile (.e) */
else if(swelle)
do_opcod(); /* Output bin profile (.b1) */
}
exit(0);
}
/* Check for variousness */
if(swpcnf)
{ if(compile_stdin()) /* Compile input */
do_opcod(); /* Output the C initialization code */
exit(0);
}
if(swfxcnf)
{ if(compile_stdin()) /* Compile input */
do_ofxcod(); /* Output the eefidx.h code */
exit(0);
}
if(swfcnf)
{ if(compile_stdin()) /* Compile input */
do_ofcod(); /* Output the eefdef.h code */
exit(0);
}
if(swcmcnf || swcscnf)
{ if(compile_stdin()) /* Compile input */
do_ocnf(swcscnf); /* Output the makecf.fun code */
exit(0);
}
if(swfdmp)
{ if(compile_stdin()) /* Compile input */
do_ofasc(); /* Output the deffun.e code */
exit(0);
}
/* Hack user's profile */
if(!uproflg) exit(0);
if(!argfile)
{
temp[0] = 0;
#if !V6
if (cp = getenv("HOME"))
strcat(temp, cp);
#if !TOPS20
strcat(temp,"/");
#endif /*-TOPS20*/
#endif /*-V6*/
strcat(temp, EVPROFTEXTFILE);
if(freopen(temp,"r",stdin) == NULL)
fatal("cannot open profile \"%s\"",temp);
}
if(!outfile)
{
temp[0] = 0;
#if !V6
if (cp = getenv("HOME"))
strcat(temp, cp);
#if !TOPS20
strcat(temp,"/");
#endif /*-TOPS20*/
#endif /*-V6*/
strcat(temp, EVPROFBINFILE);
if(freopen(temp,"wb",stdout) == NULL /* Try binary 1st */
&& freopen(temp,"w",stdout) == NULL)
fatal("cannot open output profile \"%s\"",temp);
}
/* Hack user's profile */
if(compile_stdin()) /* Compile input profile */
do_obprof(); /* Output the binary */
}
#define SW_FLG 0
#define SW_VAR 1
#define SW_STR 2
struct swarg {
char *sw_name;
long sw_type;
int *sw_avar;
char **sw_astr;
} swtab[] = {
"P", SW_FLG, &swprof, 0, /* Old stuff */
"E", SW_FLG, &swelle, 0,
"Profile", SW_FLG, &uproflg, 0,
"Pconf", SW_FLG, &swpcnf, 0,
"Fconf", SW_FLG, &swfcnf, 0,
"FXconf", SW_FLG, &swfxcnf, 0,
"CMconf", SW_FLG, &swcmcnf, 0,
"CSconf", SW_STR, 0, &swcscnf,
"Allconf", SW_FLG, &swallc, 0,
"Pdump", SW_FLG, &swprof, 0,
"Fdump", SW_FLG, &swfdmp, 0
};
doargs(argc,argv)
int argc;
char **argv;
{ register int cnt, c;
register char **av;
register int i;
register struct swarg *swp;
struct swarg *swp2;
int swerrs = 0;
av = argv;
cnt = argc;
nfiles = 0;
while(--cnt > 0)
{ ++av;
if(*av[0] != '-') /* If not switch, */
{ /* assume it's an input filename */
nfiles++;
continue;
}
av[0]++;
/* Try to look up switch in table */
swp = (struct swarg *)findkey(av[0], &swp2, swtab,
(sizeof(swtab))/(sizeof(struct swarg)),
(sizeof(struct swarg))/(sizeof(char *)));
if(swp2)
{ fprintf(stderr,"ellec: ambiguous switch: -%s = %s or %s\n",
av[0], swp->sw_name, swp2->sw_name);
goto swdone;
}
if(swp) switch(swp->sw_type)
{ case SW_FLG:
*(swp->sw_avar) = 1;
goto swdone;
case SW_VAR:
*(swp->sw_avar) = 1;
if(cnt <= 1) goto swdone;
if(isdigit(*av[1]))
{ *(swp->sw_avar) = atoi(av[1]);
--cnt;
goto swargdone;
}
goto swdone;
case SW_STR:
if(cnt <= 1) goto swdone;
*(swp->sw_astr) = av[1];
goto swargdone;
default:
fprintf(stderr,"ellec: bad switch type: %s\n",
av[0]);
swerrs++;
}
stop: fprintf(stderr,"ellec: bad switch: %s\n",*av);
swerrs++;
goto swdone;
swargdone:
av[0] = 0;
av++;
swdone: av[0] = 0;
}
if(swerrs) exit(1); /* Stop if any problems */
}
char **
findkey(cp, aretp, tabp, tabsiz, elsize)
register char *cp;
char ***aretp;
register char **tabp;
int tabsiz, elsize;
{ register char **mp1, **mp2;
register int i, res;
*aretp = mp1 = mp2 = 0;
for(i = 0; i < tabsiz; ++i, tabp += elsize)
{ if(res = ustrcmp(cp,*tabp))
{ if(res > 0) return(tabp);
if(!mp1) mp1 = tabp;
else mp2 = tabp;
}
}
if(mp2)
*aretp = mp2; /* Ambiguous */
return(mp1);
}
/* NSTRCMP - New string compare.
* Returns:
* 2 if str2 > str1 (mismatch)
* 1 if str2 counted out (str1 > str2)
* 0 if full match
* -1 if str1 counted out (str1 < str2)
* -2 if str1 < str2 (mismatch)
*/
nstrcmp(s1,s2)
register char *s1, *s2;
{ register int c, d;
while(c = *s1++)
{ if(c != *s2)
{ if((d = upcase(c) - upcase(*s2)) != 0)
return(*s2==0 ? 1 : (d > 0 ? 2 : -2));
}
++s2;
}
return(*s2 ? -1 : 0);
}
/* USTRCMP - uppercase string compare.
* Returns 0 if mismatch,
* 1 if full match,
* -1 if str1 runs out first (partial match)
*/
ustrcmp(s1,s2)
register char *s1, *s2;
{ register int c;
if ( ! s1 || ! s2 ) return ( 0 ); /* Check for null ptr */
while(c = *s1++)
{ if(c != *s2)
{ if(((c ^ *s2) != 040)
|| (upcase(c) != upcase(*s2)))
return(0);
}
s2++;
}
return(c == *s2 ? 1 : -1);
}
strueq(s1,s2)
char *s1;
char *s2;
{ return (ustrcmp(s1, s2) > 0 ? 1 : 0);
}
/* Output C initialization code for default profile (defprf.c) */
do_opcod()
{ register int i, c, f;
printf("\
/* This file defines the initial data for ELLE's default user profile.\n\
** It is automatically generated by ELLEC, and should not be edited.\n\
*/\n\
char charmap[] = {\n");
for(i=0; i < chrcnt; i++)
{ printf("\t%2d,",(f = chrptr[i]&0377));
printf("\t/* (%3o) %3s",i,charep(i));
printf(" %s",funname(f));
printf(" */\n");
}
printf("};\n char metamap[] = {\n");
for(i = 0; i < mtacnt; i += 2)
{ printf("\t0%-3o,%3d,",(c = mtaptr[i]&0377),(f = mtaptr[i+1]&0377));
printf("\t/* %4s",charep(c|CB_META));
printf(" %s",funname(f));
printf(" */\n");
}
printf("};\n char extmap[] = {\n");
for(i = 0; i < extcnt; i += 2)
{ printf("\t0%-3o,%3d,",(c = extptr[i]&0377),(f = extptr[i+1]&0377));
printf("\t/* %4s",charep(c|CB_EXT));
printf(" %s",funname(f));
printf(" */\n");
}
printf("};\n");
printf("struct profile def_prof = {\n");
printf(" %d, /* Ver */\n", format_ver);
printf(" sizeof(charmap), charmap,\n");
printf(" sizeof(metamap)/2, metamap,\n");
printf(" sizeof(extmap)/2, extmap, \n");
printf(" 0, 0\n");
printf("};\n");
}
/* Output ASCII version of default profile */
int oerrs;
do_opasc()
{ register int i, c, f;
oerrs = 0;
printf("; ELLE default ASCII profile\n\n");
printf("(keyallunbind) ; To flush all existing bindings\n\n");
for(i=0; i < chrcnt; i++)
outkbind(i, chrptr[i]&0377);
printf("\n; Meta chars\n\n");
for(i = 0; i < mtacnt; i += 2)
outkbind(CB_META | (mtaptr[i]&0377), mtaptr[i+1]&0377);
printf("\n ; Extended commands\n\n");
for(i = 0; i < extcnt; i += 2)
outkbind(CB_EXT | (extptr[i]&0377), extptr[i+1]&0377);
printf("\n");
if(oerrs)
fatal("%d errors encountered, check output file.", oerrs);
}
outkbind(c, fx)
{
if(fx == 0) /* Allow key to be mapped to nothing. */
return;
if(fx <= 0 || fx > efxmax)
printf(";INTERNAL ERROR: Bad function index %d for key %s\n",
fx, charep(c));
else if(efuntab[fx].ef_name == NULL)
printf(";INTERNAL ERROR: No name for function %d while mapping key %s\n",
fx, charep(c));
else {
printf("(keybind %s \"%s\")\n",
qstr(charep(c)),efuntab[fx].ef_name);
return;
}
oerrs++;
}
/* Output binary user profile */
do_obprof()
{ register unsigned int rp; /* Relative "pointer" */
struct stored_profile st_prof;
rp = sizeof(st_prof); /* Initialize */
/* Fixed by Kochin Chang, July 1995 */
/* format version should be the first field in compiled profile */
prof_pack(st_prof.version, format_ver);
prof_pack(st_prof.chrvec, rp);
prof_pack(st_prof.chrvcnt, chrcnt);
rp += chrcnt;
prof_pack(st_prof.metavec, rp);
prof_pack(st_prof.metavcnt, mtacnt/2);
rp += mtacnt;
prof_pack(st_prof.extvec, rp);
prof_pack(st_prof.extvcnt, extcnt/2);
rp += extcnt;
prof_pack(st_prof.menuvec, rp);
prof_pack(st_prof.menuvcnt, mnucnt);
rp += mnucnt;
fwrite((char *)&st_prof,sizeof(st_prof),1,stdout);
fwrite(chrptr,sizeof(char),chrcnt,stdout);
if(mtacnt) fwrite(mtaptr, sizeof(*mtaptr), mtacnt, stdout);
if(extcnt) fwrite(extptr, sizeof(*extptr), extcnt, stdout);
if(mnucnt) fwrite(mnuptr,sizeof(*mnuptr),mnucnt,stdout);
}
/* Return upper-case version of character */
mupcase(ch)
register int ch;
{ return((ch&(~0177)) | upcase(ch));
}
upcase (ch)
{ register int c;
c = ch&0177;
return((('a' <= c) && (c <= 'z')) ? (c - ('a'-'A')) : c);
}
char *
qstr(str)
register char *str;
{ reg
10BC8
ister int c;
static char qstrbuf[100];
register char *cp;
cp = str;
while((c = *cp++) && islword(c));
if(c == 0) return(str); /* No quoting needed */
cp = qstrbuf;
*cp++ = '"';
while(*cp++ = c = *str++)
if(c == '"') *cp++ = c; /* Double the quotes */
cp[-1] = '"';
*cp = 0;
return(qstrbuf);
}
char *
charep(c)
register int c;
{ static char chrbuf[10];
register char *cp;
cp = chrbuf;
if(c&CB_EXT)
{ *cp++ = 'X';
*cp++ = '-';
c &= ~CB_EXT;
}
if(c&CB_META)
{ *cp++ = 'M';
*cp++ = '-';
c &= ~CB_META;
}
if(c <= 037)
{ *cp++ = '^';
c += 0100;
}
if(c == 0177)
{ *cp++ = 'D';
*cp++ = 'E';
*cp++ = 'L';
}
else *cp++ = c;
*cp = 0;
return(chrbuf);
}
/* Output config Makefile (makecf.fun)
* If argument is 0 (NULL), does Makefile type output.
* Otherwise uses string for special-purpose output.
*/
do_ocnf(str)
char *str;
{ register struct fun *fnp;
register int i, mi;
register char *cp;
int fmtab[EFUNMAX];
int nfmods;
char *modtab[EFUNMAX];
char *unknown = "unknown-module";
if(str == NULL) /* If not V6 version */
{ printf("# Function module definition file, generated by ELLEC\n");
printf("FUN_OFILES = ");
}
nfmods = 0;
funcnt(fmtab); /* Count function occs */
for(i = 1; i <= efxmax; ++i)
{ if(fmtab[i] == 0) continue;
fnp = &efuntab[i];
if(fnp->ef_name == 0)
fatal("internal error - no name for function %d", i);
/* Got a function, store its module name if not a dup */
if ((cp = fnp->ef_mod) == NULL) /* Substitute if undef */
cp = unknown;
for(mi=0; mi < nfmods; ++mi)
if(ustrcmp(cp, modtab[mi]) > 0)
break;
if(mi < nfmods) continue;
modtab[nfmods++] = cp;
}
/* Now have table of all modules used. Crunch them into output. */
for(mi=0; mi < nfmods; ++mi)
if (modtab[mi] != unknown)
{ if(str != NULL) /* V6 version? */
printf("%s %s\n", str, modtab[mi]);
else printf("\\\n\t%s.o", modtab[mi]);
}
printf("\n");
}
/* Output eefdef.h */
do_ofcod()
{ register struct fun *fnp;
register int i;
char temp[40];
int fmtab[EFUNMAX];
printf("/* .H Function Definition file, generated by ELLEC */\n");
printf("/* 0 */ EFUNHOLE /* Always undefined */\n");
funcnt(fmtab); /* Count function occs */
for(i = 1; i <= efxmax ; ++i)
{
fnp = &efuntab[i];
printf("/* %3d */ ", i);
if(fmtab[i] == 0 || fnp->ef_name == 0)
printf("EFUNHOLE\n");
else
{ sprintf(temp, "\"%s\"", fnp->ef_adr);
printf("EFUN( %-12s, %-14s, \"%s\")\n", fnp->ef_adr,
temp, fnp->ef_name);
}
}
}
/* Output ascii version of function def file
*/
do_ofasc()
{ register struct fun *fnp;
register int i;
register char *fa, *fm;
printf("; Master Function Definition file\n");
for(i = 1; i <= efxmax ; ++i)
{
fnp = &efuntab[i];
if(fnp->ef_idx == 0) /* No definition for this index? */
continue;
if(fnp->ef_name == 0)
{ warn("internal error - no name for function %d", i);
continue;
}
if ((fa = fnp->ef_adr) == NULL)
fa = "unknown-addr";
if ((fm = fnp->ef_mod) == NULL)
fm = "unknown-module";
printf("(efun %d \"%s\" %s %s)\n",
fnp->ef_idx, fnp->ef_name, fa, fm);
}
}
/* Output eefidx.h */
do_ofxcod()
{ register struct fun *fnp;
register int i;
register char *cp, *cp2;
int fmtab[EFUNMAX];
char tmpstr[100];
printf("\
/* .H Function Index Definition file, generated by ELLEC */\n");
printf("\
/* FN_ defines Function Numbers (indices) for all known functions */\n");
printf("\
/* FX_ defines Function eXistence in this ELLE configuration */\n");
funcnt(fmtab); /* Count function occs */
for(i = 1; i <= efxmax ; ++i)
{
fnp = &efuntab[i];
if(fnp->ef_idx == 0) /* No definition for this index? */
continue;
if(fnp->ef_adr == 0 || fnp->ef_name == 0)
{ warn("internal error - no addr/name for function %d", i);
continue;
}
cp2 = fnp->ef_adr;
cp = tmpstr;
while(*cp++ = upcase(*cp2++));
cp = tmpstr;
if((*cp++ != 'F') || (*cp++ != '_'))
cp = tmpstr;
/* Always define FN_ as index */
printf("#define FN_%-14s %3d /* %s */\n",
cp, i, fnp->ef_name);
/* Define FX_ as 0 if unused, else same as FN_ */
printf("#define FX_%-14s %3d\n", cp,
(fmtab[i] == 0) ? 0 : i); /* 0 if unused */
}
}
/* Compile input! */
compile_stdin()
{ register struct lnode *lp;
while((lp = lread()) != NIL)
eval(lp);
return(1);
}
#define MAXLINE 300
int llstch = -1;
int leofflg;
#define unlrch(c) llstch = c
int lineno = 0;
char linebuf[MAXLINE];
char *linecp = linebuf;
lrch()
{ register int c;
if((c = llstch) >= 0)
{ if(c == 0 && leofflg)
return(EOF);
llstch = -1;
return(c);
}
if((c = getc(stdin)) == EOF)
{ leofflg = 1;
llstch = 0;
*linecp = 0;
linecp = linebuf;
return(c);
}
if(c == '\n')
{ lineno++;
linecp = linebuf;
}
else *linecp++ = c;
return(c);
}
struct lnode *
lread()
{ register int c;
register struct lnode *lp, *lp2;
struct lnode *head;
wspfls();
if((c = lrch())== EOF)
return(NIL);
if(c == ')') /* End of a list? */
return(NIL);
if(c == '(') /* Start of a list? */
{ head = lp = getln();
lp->ltyp = LT_LIST;
if((head->lval.lvl = lp = lread()) == NIL)
return(head); /* Return empty list */
while(lp2 = lread())
{ lp->lnxt = lp2;
lp = lp2;
}
return(head);
}
/* Atom of some kind */
if(c=='"')
{ return(lrstr(1));
}
unlrch(c);
return(lrstr(0));
}
wspfls()
{ register int c;
for(;;)
{ c = lrch();
if(isspace(c)) continue;
if(c == ';')
while((c = lrch()) != '\n')
if(c == EOF) return;
break;
}
if(c != EOF) unlrch(c);
}
#define LSMAX 300 /* Max # chars in atom string */
struct lnode *
lrstr(flg)
{ char cbuf[LSMAX];
register char *cp;
register int c, i;
struct lnode *lp;
cp = cbuf;
i = 0;
while((c = lrch()) != EOF)
if (flg) switch(c)
{ case '"':
if((c = lrch()) == EOF)
return(NIL);
if(c != '"')
{ unlrch(c);
goto out;
}
default:
ok:
if(++i > LSMAX)
break;
*cp++ = c;
continue;
}
else
{ if(islword(c)) goto ok;
unlrch(c);
break;
}
out:
lp = getln();
lp->ltyp = LT_STR;
lp->lval.lvs = malloc(i+1);
*cp = 0;
strcpy(lp->lval.lvs, cbuf);
return(lp);
}
islword(c)
{ return((040 < c && c < 0177
&& c != '(' && c !=')' && c != ';'
&& c != '"' && c != '\\') ? 1 : 0);
}
struct lnode *keybind(), *keyallun(), *menuitem(), *efun(),
*undefall();
struct lfun {
char *lfname; /* Name of list function */
struct lnode * (*lfrtn)(); /* Function address */
} lfntab[] = {
"keybind", keybind,
"efun", efun,
"menuitem", menuitem,
"keyallunbind", keyallun,
/* "keyunbind", keyunbind, */ /* Not yet */
"undefall", undefall,
/* "undef", undef, */ /* Not yet */
0, 0
};
struct lnode *
eval(lp)
register struct lnode *lp;
{ register struct lnode *flp;
register struct lfun *lfent;
if(lp->ltyp != LT_LIST)
return(lp);
if((flp = lp->lval.lvl) == NIL)
return(NIL);
if(flp->ltyp != LT_STR)
return(NIL);
/* Look up list function and invoke it */
for(lfent = lfntab; lfent->lfname; lfent++)
if(strueq(flp->lval.lvs, lfent->lfname))
return((*(lfent->lfrtn))(flp->lnxt));
lerr("unknown op: (%s)", flp->lval.lvs);
return(NIL);
}