-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdpic.c
19455 lines (17637 loc) · 456 KB
/
dpic.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
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
/* dpic translator program. */
/* BSD Licence:
Copyright (c) 2018, J. D. Aplevich
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* Comments within D ... D pairs are (Pascal) debug statements that are
activated by the Makefile if debug is enabled. Comments within other
uppercase pairs are activated for specific operating systems or compilers.
Pascal between P2CIP ... P2CP comment pairs is ignored during p2c conversion.
P2 IP and P2 P comments are converted to P2CIP ... P2CP for some compilers.
C code in P2CC ... comments is included by p2c.
*/
#include "p2c.h"
#include <time.h>
/*D,log D*/
/* exit label for parser errors */
/* include dp0.h */
/* dp0.x */
/* Global definitions */
/* Some PC versions of p2c crash on Pascal
const declarations at low levels.
All consts should be in dp0.x */
#define distmax 3.40282347e+38 /*assumes at least IEEE single */
#define MaxReal distmax
/*GH distmax = MaxReal; HG*/
#define mdistmax (-distmax)
#define pi 3.1415926535897931
#define ln10 2.3025850929940459
/*F MaxInt F*/
#define maxint 2147483647L
#define randmax maxint
#define HASHLIM 9 /* Hash array upper val for var names */
/* Parser constants */
#define next 1
#define kind 2
#define symb 3
#define err 4
#define rs 3
#define prod 4
#define lb 3
/* include parscst.i */
#define symbmax 242
#define prodmax 183
#define lrmax 4851
#define lxmax 456
/* include parscdc.i */
#define METAGOAL1 0
#define input1 1
#define input2 2
#define picture1 3
#define picture2 4
#define NL1 5
#define NL2 6
#define start1 7
#define start2 8
#define start3 9
#define elementlist1 10
#define elementlist2 11
#define elementlist3 12
#define term1 13
#define term2 14
#define term3 15
#define term4 16
#define element1 17
#define element2 18
#define element3 19
#define element4 20
#define element5 21
#define element6 22
#define element7 23
#define element8 24
#define element9 25
#define element10 26
#define element11 27
#define element12 28
#define lbrace1 29
#define namedobj1 30
#define namedobj2 31
#define suffix1 32
#define suffix2 33
#define suffix3 34
#define position1 35
#define position2 36
#define position3 37
#define position4 38
#define assignlist1 39
#define assignlist2 40
#define command1 41
#define command2 42
#define command3 43
#define command4 44
#define command5 45
#define command6 46
#define command7 47
#define command8 48
#define command9 49
#define command10 50
#define optnl1 51
#define optnl2 52
#define ifpart1 53
#define elsehead1 54
#define for1 55
#define for2 56
#define stringexpr1 57
#define stringexpr2 58
#define string1 59
#define string2 60
#define assignment1 61
#define assignment2 62
#define assignment3 63
#define assignment4 64
#define expression1 65
#define expression2 66
#define expression3 67
#define expression4 68
#define expression5 69
#define ifhead1 70
#define setlogic1 71
#define logexpr1 72
#define logexpr2 73
#define forhead1 74
#define forincr1 75
#define do1 76
#define do2 77
#define by1 78
#define by2 79
#define redirect1 80
#define redirect2 81
#define redirect3 82
#define resetlist1 83
#define resetlist2 84
#define systemcmd1 85
#define defhead1 86
#define defhead2 87
#define sprintf1 88
#define sprintf2 89
#define exprlist1 90
#define exprlist2 91
#define object1 92
#define object2 93
#define object3 94
#define object4 95
#define object5 96
#define object6 97
#define object7 98
#define object8 99
#define object9 100
#define object10 101
#define object11 102
#define object12 103
#define object13 104
#define object14 105
#define object15 106
#define object16 107
#define object17 108
#define object18 109
#define object19 110
#define object20 111
#define object21 112
#define object22 113
#define object23 114
#define object24 115
#define object25 116
#define object26 117
#define object27 118
#define openblock1 119
#define block1 120
#define block2 121
#define block3 122
#define block4 123
#define optexp1 124
#define optexp2 125
#define closeblock1 126
#define objectwith1 127
#define objectwith2 128
#define objectwith3 129
#define pair1 130
#define pair2 131
#define nth1 132
#define nth2 133
#define nth3 134
#define primobj1 135
#define primobj2 136
#define primobj3 137
#define primobj4 138
#define shift1 139
#define shift2 140
#define shift3 141
#define location1 142
#define location2 143
#define location3 144
#define location4 145
#define location5 146
#define place1 147
#define place2 148
#define place3 149
#define place4 150
#define place5 151
#define factor1 152
#define factor2 153
#define factor3 154
#define placename1 155
#define placename2 156
#define placename3 157
#define placename4 158
#define ncount1 159
#define ncount2 160
#define ncount3 161
#define logprod1 162
#define logprod2 163
#define logval1 164
#define logval2 165
#define logval3 166
#define lcompare1 167
#define lcompare2 168
#define lcompare3 169
#define lcompare4 170
#define primary1 171
#define primary2 172
#define primary3 173
#define primary4 174
#define primary5 175
#define primary6 176
#define primary7 177
#define primary8 178
#define primary9 179
#define primary10 180
#define primary11 181
#define primary12 182
#define primary13 183
/* include lxcst.h */
#define XBLOCK 26
#define XBRACKETL 21
#define XBRACKETR 22
#define XCOMMENT 42
#define XLcolrspec 137
#define XLcolour 138
#define XCOLON 20
#define XD 25
#define XDOUBLEHEAD 150
#define XDc 98
#define XDe 94
#define XDend 97
#define XDn 92
#define XDne 88
#define XDnw 90
#define XDs 93
#define XDse 89
#define XDstart 96
#define XDsw 91
#define XDw 95
#define XEMPTY 2
#define XEND 45
#define XEQEQ 100
#define XEQ 29
#define XGE 102
#define XLE 103
#define XERROR 3
#define XFOR 83
#define XGT 104
#define XLBRACE 23
#define XLEFTHEAD 148
#define XLT 4
#define XLabel 39
#define XLabove 145
#define XLabs 113
#define XLacos 114
#define XLarc 160
#define XLarcrad 166
#define XLarg 43
#define XLarrow 162
#define XLarrowhd 147
#define XLarrowhead 183
#define XLarrowht 167
#define XLarrowwid 168
#define XLasin 115
#define XLat 54
#define XLatan2 128
#define XLbelow 146
#define XLbox 157
#define XLboxht 169
#define XLboxrad 170
#define XLboxwid 171
#define XLccw 6
#define XLcenter 142
#define XLchop 59
#define XLcircle 158
#define XLcirclerad 172
#define XLcoloneq 30
#define XLcontinue 58
#define XLcorner 87
#define XLcos 116
#define XLcw 5
#define XLdashed 135
#define XLdashwid 173
#define XLdefine 78
#define XLdiameter 109
#define XLdirecton 151
#define XLdiveq 34
#define XLdo 84
#define XLdotted 134
#define XLdown 153
#define XLellipse 159
#define XLellipseht 174
#define XLellipsewid 175
#define XLelse 82
#define XLendfor 85
#define XLenvvar 165
#define XLexec 75
#define XLexp 117
#define XLexpe 118
#define XLfillval 184
#define XLfloat 37
#define XLfloor 126
#define XLfrom 52
#define XLfunc1 112
#define XLfunc2 127
#define XLheight 106
#define XLint 119
#define XLinvis 136
#define XLlastenv 188
#define XLlastsc 182
#define XLleft 155
#define XLlength 111
#define XLline 161
#define XLlineht 176
#define XLlinethick 185
#define XLlinetype 132
#define XLlinewid 177
#define XLljust 143
#define XLlog 120
#define XLloge 121
#define XLcompare 99
#define XLmax 129
#define XLmaxpsht 186
#define XLmaxpswid 187
#define XLmin 130
#define XLminuseq 32
#define XLmove 163
#define XLmoveht 178
#define XLmovewid 179
#define XLmulteq 33
#define XLname 38
#define XLoutlined 139
#define XLparam 105
#define XLpluseq 31
#define XLpmod 131
#define XLprimitiv 156
#define XLradius 108
#define XLremeq 35
#define XLright 154
#define XLrjust 144
#define XLscale 188
#define XLshaded 140
#define XLsign 122
#define XLsin 123
#define XLsolid 133
#define XLspline 164
#define XLsqrt 124
#define XLstring 41
#define XLtan 125
#define XLtextht 180
#define XLtextoffset 181
#define XLtextpos 141
#define XLtextwid 182
#define XLthen 57
#define XLthickness 110
#define XLto 53
#define XLaTeX 40
#define XLundefine 79
#define XLup 152
#define XLwidth 107
#define XNEQ 101
#define XNOT 16
#define XNL 14
#define XRBRACE 24
#define XRIGHTHEAD 149
#define XSEMICOLON 14
#define XSTAR 9
#define XSTART 44
#define XANDAND 17
#define XOROR 18
#define Xlparen 7
#define Xrparen 8
#define Xplus 10
#define Xcomma 19
#define Xminus 11
#define XSLASH 12
/* Machine constants */
/* Assume ASCII; forget EBCDIC */
#define ordMINCH 0
#define ordMAXCH 255
#define ordNL 10
#define ordTAB 9
#define ordCR 13
#define ordETX 3
#define ordBSL 92
#define nlch ((Char)ordNL)
#define tabch ((Char)ordTAB)
#define crch ((Char)ordCR)
#define etxch ((Char)ordETX)
#define bslch ((Char)ordBSL)
#define CHBUFSIZ 4095 /* upper limit of chbuf buffers */
#define maxbval 16383
/* must be > CHBUFSIZ-2 */
/* Lexical parameters */
#define FILENAMELEN 1024 /* max length of file names */
/*F FILENAMELEN = 255; F*/
/* Lalr machine parameters */
#define STACKMAX 255 /* size of attstack and parsestack */
#define REDUMAX 128 /* size of reduction buffer */
#define MAXERRCOUNT 3 /* max no of errors before giving up */
/* Draw types */
#define MFpic 1
#define MPost 2
#define PDF 3
#define PGF 4
#define Pict2e 5
#define PS 6
#define PSfrag 7
#define PSTricks 8
#define SVG 9
#define TeX 10
#define tTeX 11
#define xfig 12
#define SPLT 0.551784 /* optimum spline tension for arcs */
#define pointd 72
/* postprocessor constants (vars?) */
#define xfigres 1200
#define xdispres 80
/* Text parameters (vars?) */
#define DFONT 11 /* default svg font size, pt */
/* Lexical types */
typedef short chbufinx;
/* 0..symbmax; */
typedef int symbol;
typedef short lxinx;
typedef uchar production;
typedef Char chbufarray[CHBUFSIZ + 1];
typedef Char mstring[FILENAMELEN];
/* Environment variable index */
/*GH1HG*/
typedef uchar environx;
/* Lalr machine types */
typedef uchar stackinx;
typedef short redubufrange;
typedef struct reduelem {
/* packed */
/*D oldtop, D*/
stackinx newtop;
production prod_;
} reduelem;
/* Production types */
/* For storing names */
typedef struct nametype {
double val;
Char *segmnt;
chbufinx seginx;
int len;
struct nametype *next_;
} nametype;
/* Lexical input for loops and macros */
typedef struct fbuffer {
Char *carray;
int savedlen, readx, attrib;
struct fbuffer *higherb, *prevb, *nextb;
} fbuffer;
/* Macro argument list pointer */
typedef struct arg {
fbuffer *argbody;
struct arg *highera, *nexta;
} arg;
/* Pic position */
typedef struct postype {
/* packed */
double xpos, ypos;
} postype;
typedef double envarray[XLlastenv - XLenvvar];
typedef struct primitive {
nametype *name, *textp, *outlinep, *shadedp;
struct primitive *parent, *son, *next_;
postype aat;
double lparam, lthick;
int direction, spec, ptype;
union {
struct {
double boxheight, boxwidth, boxfill, boxradius;
} Ubox;
struct {
double blockheight, blockwidth;
postype here;
nametype *(vars[HASHLIM + 1]);
int nvars[HASHLIM + 1];
double *env;
} UBLOCK;
struct {
double cfill, radius;
} Ucircle;
struct {
double elheight, elwidth, efill;
} Uellipse;
struct {
/* XLarc:( endpos.xpos,endpos.ypos: real );
endpos.xpos, endpos.ypos (uses XLline) */
postype endpos;
double height, width, lfill, aradius;
int atype;
} Uline;
} Upr;
} primitive;
/* To force optimum dynamic storage of
primitives: */
typedef struct XLboxprimitive {
nametype *name, *textp, *outlinep, *shadedp;
primitive *parent, *son, *next_;
postype aat;
double lparam, lthick;
int direction, spec, ptype;
union {
struct {
double boxheight, boxwidth, boxfill, boxradius;
} Ubox;
} Upr;
} XLboxprimitive;
typedef struct XLcircleprimitive {
nametype *name, *textp, *outlinep, *shadedp;
primitive *parent, *son, *next_;
postype aat;
double lparam, lthick;
int direction, spec, ptype;
union {
struct {
double cfill, radius;
} Ucircle;
} Upr;
} XLcircleprimitive;
typedef struct XLellipseprimitive {
nametype *name, *textp, *outlinep, *shadedp;
primitive *parent, *son, *next_;
postype aat;
double lparam, lthick;
int direction, spec, ptype;
union {
struct {
double elheight, elwidth, efill;
} Uellipse;
} Upr;
} XLellipseprimitive;
typedef struct XLlineprimitive {
nametype *name, *textp, *outlinep, *shadedp;
primitive *parent, *son, *next_;
postype aat;
double lparam, lthick;
int direction, spec, ptype;
union {
struct {
postype endpos;
double height, width, lfill, aradius;
int atype;
} Uline;
} Upr;
} XLlineprimitive;
typedef struct XLabelprimitive {
nametype *name, *textp, *outlinep, *shadedp;
primitive *parent, *son, *next_;
postype aat;
double lparam, lthick;
int direction, spec, ptype;
} XLabelprimitive;
/* Attribute stack types */
typedef struct attribute {
chbufinx chbufx;
int length;
primitive *prim, *internal;
nametype *varname;
double xval, yval, startchop, endchop;
int lexval, state;
} attribute;
typedef attribute attstacktype[STACKMAX + 1];
/* Parser types */
typedef struct stackelm {
stackinx link;
int table;
} stackelm;
typedef stackelm tparsestack[STACKMAX + 1];
/* Machine-dependent characters */
/* tabch, nlch, crch, etxch: char; */
/* File names */
FILE *input, *output, *errout; /*G asmname 'std_err'; G*/
FILE *copyin; /*G asmname 'copy_in'; G*/
FILE *redirect; /*G asmname 'redi_rect'; G*/
/*D log: text; D*/
/*DG asmname 'log_file'; GD*/
mstring infname; /* name of current input file */
mstring outfnam; /* name of current output file */
boolean inputeof; /* end-of-input flag */
boolean forbufend; /* end of for buffer */
int argct; /* argument counter for options */
int drawmode; /* output conversion */
boolean safemode; /* disable sh and copy */
/*D oflag: integer; D*/
/* debug level and open logfile flag */
/* Lexical analyzer character buffer */
Char *chbuf;
chbufinx chbufi, oldbufi; /* character buffer indices */
/* Lexical variables */
Char ch; /* current character */
short newsymb; /* current lexical symbol */
int lexsymb, lexstate; /* 0..4: <.PS; .PS; in pic; .PE; >.PE */
boolean inlogic; /* set < to <compare> in context */
boolean instr; /* set while reading a string */
fbuffer *inbuf, *savebuf, *freeinbuf, *topbuf;
/* Error handling */
int errcount; /* becomes nonzero when errors found */
int lineno; /* current input line number */
int currprod; /* current production for error msgs */
/* Production variables */
attribute *attstack;
/*D stackhigh: integer;D*/
redubufrange reduinx, redutop;
reduelem redubuf[REDUMAX + REDUMAX + 1]; /* reduction buffer */
double floatvalue; /* numerical value of floats read */
primitive *envblock; /* block containing the current scope */
primitive *globalenv; /* the global environment block */
double dptextratio; /* text parameters for SVG,PDF,PS */
double dpPPI; /* pixels per inch */
double north, south, east, west; /* compass corners of a primitive */
double xfheight; /* for calculating xfig coordinates */
Char *freeseg; /* segment open to store strings */
short freex; /* next free location */
Char *tmpbuf; /* buffer for snprintf or sprintf */
Char *tmpfmt; /* snprintf, findvar buffer */
double scale, fsc; /* scale factor and final scale factor*/
int splcount, spltot; /* spline depth counter */
int pdfobjcount; /* pdf objects */
primitive *snode; /* temporary node storage */
boolean bfill; /* fill flag for linear objects */
double vfill; /* fill value */
nametype *sshade, *soutline; /* temp values for linear objects */
double lastfillval; /* last-used fill density */
int printstate; /* for passing output state info */
/* graphics state parameters */
boolean gsocolor, gsfcolor, gsgcolor;
/* stroke, fill, gray fill flags */
double gslinethick; /* last-used line thickness */
int gslinecap, gslinejoin; /* 0 = butt */
double gsdashw, gsdashs; /* line dash and space lengths */
nametype *stream, *cx; /* pdf stream storage and current seg */
int pdfoffs[8]; /* pdf output byte counts */
/* Global tables for easy C conversion.
Alternative: use run-time space */
short lr[lrmax + 1]={
#include "parstab.i"
};
lxinx entryhp[ordMAXCH + 1]={
#include "entryhp.h"
}; /* assumes ordMINCH = 0 */
lxinx lxhp[lxmax + 1]={
#include "lxhp.h"
};
lxinx lxnp[lxmax + 1]={
#include "lxnp.h"
};
symbol lxtv[lxmax + 1]={
#include "lxtv.h"
};
symbol entrytv[ordMAXCH + 1]={
#include "entrytv.h"
};
Char lxch[lxmax + 1]={
#include "lxch.h"
};
/* integer debugging constants */
/*D debuglevel, linesignal: integer; D*/
/*D trace: boolean; D*/
/* used for debugging the parser */
/* Parser variables */
int oldsymb; /* last lexical symbol */
arg *macros, *args, *freearg; /* macro and macro argument list */
stackinx stacktop, pseudotop, validtop, top;
stackelm *parsestack; /* parse stack */
boolean parsestop; /* parser flags */
int startinx, lri, start;
/*--------------------------------------------------------------------*/
void copyleft(fbuffer *mac, fbuffer **buf, int attr);
void doprod(int prno);
void markerror(int emi);
void readfor(fbuffer *p0, int attx, fbuffer **p2);
void skiptobrace(void);
void deletename(nametype **head);
void newstr(nametype **sp);
void deletetree(primitive **p);
/*D procedure printobject(primp: primitivep); forward;
procedure snaptype(var iou: text; p: integer); forward;
procedure wrbuf(p: fbufferp; job,r: integer); forward;
procedure logaddr(b: fbufferp); forward;
procedure wrbufaddr(q: fbufferp; job: integer); forward;
procedure wlogfl( nm: string; v: real; cr: integer); forward;
D*/
/* DGHM function ordp(p:pointer): integer; forward; MHGD */
/* F function ordp(p:pointer): PtrUInt; forward; F */
#ifndef SAFE_MODE
void pointinput(nametype *txt);
void pointoutput(boolean nw, nametype *txt, int *ier);
#endif
/*--------------------------------------------------------------------*/
/* include sysdep.h */
/* sysdep.x Required UNIX functions */
/*F{$linklib c} F*/
/* access */
/*F cdecl; F*/
/*HF name 'access' FH*/
/*G; asmname '_p_Access' G*/
extern int access(Char *f, int n);
/* isatty */
/*F cdecl; F*/
/*HF name FH*/
/*G; asmname G*/
/*GHF 'isatty' FHG*/
/* time */
/*F cdecl; F*/
/*HF name FH*/
/*G; asmname G*/
/*GHF 'time' FHG*/
/* sprintf */
/*GHF real FHG*/
/*F cdecl; F*/
/*HF name FH*/
/*G; asmname G*/
/*GHF 'sprintf' FHG*/
/* snprintf */
/*GHF real FHG*/
/*F cdecl; F*/
/*HF name FH*/
/*G; asmname G*/
/*GHF 'snprintf' FHG*/
/* system */
/*F cdecl; F*/
/*HF name FH*/
/*G; asmname G*/
/*GHF 'system' FHG*/
/* The following legacy tests may need tweaking for different operating
systems and probably could be handled in the configure script. */
/* random */
/*F cdecl; F*/
/*HF name FH*/
/*G; asmname G*/
/*GHF 'random' FHG*/
/* srandom */
/*HF name FH*/
/*G; asmname G*/
/*GHF 'srandom' FHG*/
/*-----------------------------------------------------------------*/
/*DM function ordp(p:pointer): integer; external; MD*/
/*DFGHM function odp(p:pointer): integer; MHGFD*/
/*D begin
odp := abs(ordp(p)) mod 10000
end; D*/
/* Numerical utilities: */
double
principal(double x, double r)
{ while (x > r) {
x -= 2 * r;
}
while (x < (-r)) {
x += 2 * r;
}
return x;
}
double
Max(double x, double y)
{ if (y > x) {
return y;
}
else {
return x;
}
}
double
Min(double x, double y)
{ if (y < x) {
return y;
}
else {
return x;
}
}
int
Floor(double x)
{ if ((x >= 0) || (((long)x) == x)) {
return ((long)x);
}
else {
return (((long)x) - 1);
}
}
int
Ceil(double x)
{ if ((x < 0) || (((long)x) == x)) {
return ((long)x);
}
else {
return (((long)x) + 1);
}
}
boolean
isdistmax(double x)
{ return (fabs((x / distmax) - 1.0) < 1e-6);
}
boolean
ismdistmax(double x)
{ return (fabs((x / mdistmax) - 1.0) < 1e-6);
}
double
datan(double y, double x)
{ double r;
r = atan2(y , x);
return r;
}
double
linlen(double x, double y)
{ double xm, ym;
/* linlen := sqrt( x*x + y*y ) */
if (fabs(x) > fabs(y)) {
xm = fabs(x);
ym = y / xm;
return (xm * sqrt(1.0 + (ym * ym)));
}
if (y == 0.0) {
xm = 0.0;
ym = 0.0;
}
else {
xm = fabs(y);
ym = x / xm;
}
return (xm * sqrt(1.0 + (ym * ym)));
}
/* Get and initialize a buffer from the
old-buffer stack or make a new one */
void
newbuf(fbuffer **buf)
{ fbuffer *With;
/*D if debuglevel > 0 then write(log,' newbuf'); D*/
if (freeinbuf == NULL) {
*buf = Malloc(sizeof(fbuffer));
(*buf)->carray = Malloc(sizeof(chbufarray));
}
/* p2c automatically adds memory allocation failure checks */
else {
/*D if debuglevel > 0 then write(log,' f'); D*/
*buf = freeinbuf;
freeinbuf = freeinbuf->nextb;
}
With = *buf;
/*D; if debuglevel > 0 then begin logaddr( buf ); writeln(log) end D*/
With->savedlen = 0;
With->carray[0] = ' ';
With->readx = 1;
With->attrib = 0;
With->higherb = NULL;
With->prevb = NULL;
With->nextb = NULL;
}
/* Put buffers onto top of old-buffer stack */
void
disposebufs(fbuffer **buf)
{ /*D; loc: integer D*/
fbuffer *bu;
/*D if debuglevel > 0 then begin writeln(log);
write(log,'disposebufs(',loc:1,')'); wrbufaddr(buf,1) end; D*/
if ((*buf) == NULL) {
return;
}
bu = *buf;
while (bu->nextb != NULL) {
bu = bu->nextb;
}
bu->nextb = freeinbuf;
freeinbuf = *buf;
*buf = NULL;
}
/* Get and initialize an arg from the
old-arg stack or make a new one */
void
newarg(arg **ar)
{ arg *With;
if (freearg == NULL) {
*ar = Malloc(sizeof(arg));
}
else {