forked from Macroassembler-AS/asl-releases
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asmsub.c
2321 lines (2039 loc) · 59.6 KB
/
asmsub.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
/* asmsub.c */
/*****************************************************************************/
/* AS-Portierung */
/* */
/* Unterfunktionen, vermischtes */
/* */
/* Historie: 4. 5.1996 Grundsteinlegung */
/* 13. 8.1997 KillBlanks-Funktionen nach stringutil.c geschoben */
/* 26. 6.1998 Fehlermeldung Codepage nicht gefunden */
/* 7. 7.1998 Fix Zugriffe auf CharTransTable wg. signed chars */
/* 17. 8.1998 Unterfunktion zur Buchhaltung Adressbereiche */
/* 1. 9.1998 FloatString behandelte Sonderwerte nicht korrekt */
/* 13. 9.1998 Prozessorliste macht Zeilenvorschub nach 6 Namen */
/* 14.10.1998 Fehlerzeilen mit > > > */
/* 30. 1.1999 Formatstrings maschinenunabhaengig gemacht */
/* 18. 4.1999 Ausgabeliste Sharefiles */
/* 13. 7.1999 Fehlermeldungen relokatible Symbole */
/* 13. 9.1999 I/O-Fehler 25 ignorieren */
/* 5.11.1999 ExtendErrors ist jetzt ShortInt */
/* 13. 2.2000 Ausgabeliste Listing */
/* 6. 8.2000 added ValidSymChar array */
/* 21. 7.2001 added not repeatable message */
/* 2001-08-01 QuotPos also works for ) resp. ] characters */
/* 2001-09-03 added warning message about X-indexed conversion */
/* 2001-10-21 additions for GNU-style errors */
/* 2002-03-31 fixed operand order of memset */
/* */
/*****************************************************************************/
/* $Id: asmsub.c,v 1.35 2017/04/02 11:10:37 alfred Exp $ */
/*****************************************************************************
* $Log: asmsub.c,v $
* Revision 1.35 2017/04/02 11:10:37 alfred
* - allow more fine-grained macro expansion in listing
*
* Revision 1.34 2016/11/25 18:12:13 alfred
* - first version to support OLMS-50
*
* Revision 1.33 2016/09/12 19:49:16 alfred
* - use gettime() to get DOS time (int86 leaks memory per call)
*
* Revision 1.32 2016/09/11 15:39:49 alfred
* - determine DOS time without floatig point
*
* Revision 1.31 2016/08/30 09:53:46 alfred
* - make string argument const
*
* Revision 1.30 2015/10/23 08:43:33 alfred
* - beef up & fix structure handling
*
* Revision 1.29 2015/08/05 18:28:06 alfred
* - correct initial construction of ALLARGS, compute ALLARGS/NUMARGS only if needed
*
* Revision 1.28 2014/12/14 17:58:46 alfred
* - remove static variables in strutil.c
*
* Revision 1.27 2014/12/05 11:58:15 alfred
* - collapse STDC queries into one file
*
* Revision 1.26 2014/12/03 19:01:00 alfred
* - remove static return value
*
* Revision 1.25 2014/11/28 22:02:25 alfred
* - rework to current style
*
* Revision 1.24 2014/11/23 17:06:32 alfred
* - add error #2060 (unimplemented)
*
* Revision 1.23 2014/11/10 13:15:13 alfred
* - make arg of QuotPos() const
*
* Revision 1.22 2014/11/06 11:22:01 alfred
* - replace hook chain for ClearUp, document new mechanism
*
* Revision 1.21 2014/11/05 15:47:13 alfred
* - replace InitPass callchain with registry
*
* Revision 1.20 2014/10/06 17:54:56 alfred
* - display filename if include failed
* - some valgrind workaraounds
*
* Revision 1.19 2014/09/14 13:22:33 alfred
* - ass keyword arguments
*
* Revision 1.18 2014/05/29 10:59:05 alfred
* - some const cleanups
*
* Revision 1.17 2014/03/08 10:52:07 alfred
* - correctly handle escaped quotation marks
*
* Revision 1.16 2012-08-22 20:01:45 alfred
* - regard UTF-8
*
* Revision 1.15 2012-05-26 13:49:19 alfred
* - MSP additions, make implicit macro parameters always case-insensitive
*
* Revision 1.14 2011-10-20 14:00:40 alfred
* - SRP handling more graceful on Z8
*
* Revision 1.13 2010/05/01 17:22:02 alfred
* - use strmov()
*
* Revision 1.12 2010/04/17 13:14:19 alfred
* - address overlapping strcpy()
*
* Revision 1.11 2008/11/23 10:39:16 alfred
* - allow strings with NUL characters
*
* Revision 1.10 2008/08/10 11:57:48 alfred
* - handle truncated bit numbers for 68K
*
* Revision 1.9 2008/01/02 22:32:21 alfred
* - better heap checking for DOS target
*
* Revision 1.8 2007/11/24 22:48:02 alfred
* - some NetBSD changes
*
* Revision 1.7 2007/09/24 17:51:48 alfred
* - better handle non-printable characters
*
* Revision 1.6 2007/04/30 18:37:52 alfred
* - add weird integer coding
*
* Revision 1.5 2006/12/09 19:54:53 alfred
* - remove unplausible part in time computation
*
* Revision 1.4 2005/10/02 10:00:44 alfred
* - ConstLongInt gets default base, correct length check on KCPSM3 registers
*
* Revision 1.3 2004/10/03 11:44:58 alfred
* - addition for MinGW
*
* Revision 1.2 2004/05/31 15:19:26 alfred
* - add StrCaseCmp
*
* Revision 1.1 2003/11/06 02:49:19 alfred
* - recreated
*
* Revision 1.12 2003/10/04 15:38:47 alfred
* - differentiate constant/variable messages
*
* Revision 1.11 2003/10/04 14:00:39 alfred
* - complain about empty arguments
*
* Revision 1.10 2003/09/21 21:15:54 alfred
* - fix string length
*
* Revision 1.9 2003/05/20 17:45:03 alfred
* - StrSym with length spec
*
* Revision 1.8 2003/05/02 21:23:09 alfred
* - strlen() updates
*
* Revision 1.7 2002/11/16 20:52:18 alfred
* - added ErrMsgStructNameMissing
*
* Revision 1.6 2002/11/04 19:04:26 alfred
* - prevent modification of constants with SET
*
* Revision 1.5 2002/08/14 18:43:47 alfred
* - warn null allocation, remove some warnings
*
* Revision 1.4 2002/05/13 18:17:13 alfred
* - added error 2010/2020
*
* Revision 1.3 2002/05/12 20:56:28 alfred
* - added 3206x error messages
*
*****************************************************************************/
#include "stdinc.h"
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include "version.h"
#include "endian.h"
#include "stdhandl.h"
#include "nls.h"
#include "nlmessages.h"
#include "as.rsc"
#include "strutil.h"
#include "stringlists.h"
#include "chunks.h"
#include "ioerrs.h"
#include "errmsg.h"
#include "asmdef.h"
#include "asmpars.h"
#include "asmdebug.h"
#include "intconsts.h"
#include "as.h"
#include "asmsub.h"
#ifdef __TURBOC__
#ifdef __DPMI16__
#define STKSIZE 40960
#else
#define STKSIZE 49152
#endif
#endif
#define VALID_S1 1
#define VALID_SN 2
#define VALID_M1 4
#define VALID_MN 8
Word ErrorCount, WarnCount;
static StringList CopyrightList, OutList, ShareOutList, ListOutList;
static LongWord StartStack, MinStack, LowStack;
static Byte *ValidSymChar;
/****************************************************************************/
/* Modulinitialisierung */
void AsmSubInit(void)
{
PageLength = 60;
PageWidth = 0;
ErrorCount = 0;
WarnCount = 0;
}
/****************************************************************************/
/* Copyrightlistenverwaltung */
void AddCopyright(char *NewLine)
{
AddStringListLast(&CopyrightList, NewLine);
}
void WriteCopyrights(TSwitchProc NxtProc)
{
StringRecPtr Lauf;
if (!StringListEmpty(CopyrightList))
{
printf("%s\n", GetStringListFirst(CopyrightList, &Lauf));
NxtProc();
while (Lauf)
{
printf("%s\n", GetStringListNext(&Lauf));
NxtProc();
}
}
}
/*--------------------------------------------------------------------------*/
/* ermittelt das erste/letzte Auftauchen eines Zeichens ausserhalb */
/* "geschuetzten" Bereichen */
char *QuotMultPos(const char *s, const char *pSearch)
{
register ShortInt Brack = 0, AngBrack = 0;
register const char *i;
Boolean InSglQuot = False, InDblQuot = False, ThisEscaped = False, NextEscaped = False;
for (i = s; *i; i++, ThisEscaped = NextEscaped)
{
NextEscaped = False;
if (strchr(pSearch, *i))
{
if (!AngBrack && !Brack && !InSglQuot && !InDblQuot)
return (char*)i;
}
switch (*i)
{
case '"':
if (!InSglQuot && !ThisEscaped)
InDblQuot = !InDblQuot;
break;
case '\'':
if (!InDblQuot && !ThisEscaped)
InSglQuot = !InSglQuot;
break;
case '\\':
if ((InSglQuot || InDblQuot) && !ThisEscaped)
NextEscaped = True;
break;
case '(':
if (!AngBrack && !InDblQuot && !InSglQuot)
Brack++;
break;
case ')':
if (!AngBrack && !InDblQuot && !InSglQuot)
Brack--;
break;
case '[':
if (!Brack && !InDblQuot && !InSglQuot)
AngBrack++;
break;
case ']':
if (!Brack && !InDblQuot && !InSglQuot)
AngBrack--;
break;
}
}
return NULL;
}
char *QuotPos(const char *s, char Zeichen)
{
char Tmp[2];
Tmp[0] = Zeichen;
Tmp[1] = '\0';
return QuotMultPos(s, Tmp);
}
char *RQuotPos(char *s, char Zeichen)
{
ShortInt Brack = 0, AngBrack = 0;
char *i;
Boolean Quot = False, Paren = False;
for (i = s + strlen(s) - 1; i >= s; i--)
if (*i == Zeichen)
{
if ((!AngBrack) && (!Brack) && (!Paren) && (!Quot))
return i;
}
else switch (*i)
{
case '"':
if ((!Brack) && (!AngBrack) && (!Quot))
Paren = !Paren;
break;
case '\'':
if ((!Brack) && (!AngBrack) && (!Paren))
Quot = !Quot;
break;
case ')':
if ((!AngBrack) && (!Paren) && (!Quot))
Brack++;
break;
case '(':
if ((!AngBrack) && (!Paren) && (!Quot))
Brack--;
break;
case ']':
if ((!Brack) && (!Paren) && (!Quot))
AngBrack++;
break;
case '[':
if ((!Brack) && (!Paren) && (!Quot))
AngBrack--;
break;
}
return NULL;
}
/*--------------------------------------------------------------------------*/
/* ermittelt das erste (nicht-) Leerzeichen in einem String */
char *FirstBlank(const char *s)
{
const char *h, *Min = NULL;
h = strchr(s, ' ');
if (h)
if ((!Min) || (h < Min))
Min = h;
h = strchr(s, Char_HT);
if (h)
if ((!Min) || (h < Min))
Min = h;
return (char*)Min;
}
/*--------------------------------------------------------------------------*/
/* einen String in zwei Teile zerlegen */
void SplitString(char *Source, char *Left, char *Right, char *Trenner)
{
char Save;
LongInt slen = strlen(Source);
if ((!Trenner) || (Trenner >= Source + slen))
Trenner = Source + slen;
Save = (*Trenner);
*Trenner = '\0';
strmov(Left, Source);
*Trenner = Save;
if (Trenner >= Source + slen)
*Right = '\0';
else
strmov(Right, Trenner + 1);
}
/*--------------------------------------------------------------------------*/
/* verbesserte Grossbuchstabenfunktion */
/* einen String in Grossbuchstaben umwandeln. Dabei Stringkonstanten in Ruhe */
/* lassen */
void UpString(char *s)
{
char *z;
int hypquot = 0;
Boolean LastBk = FALSE, ThisBk;
for (z = s; *z != '\0'; z++)
{
ThisBk = FALSE;
switch (*z)
{
case '\\':
ThisBk = TRUE;
break;
case '\'':
if ((!(hypquot & 2)) && (!LastBk))
hypquot ^= 1;
break;
case '"':
if ((!(hypquot & 1)) && (!LastBk))
hypquot ^= 2;
break;
default:
if (!hypquot)
*z = UpCaseTable[(int)*z];
}
LastBk = ThisBk;
}
}
/****************************************************************************/
void TranslateString(char *s, int Length)
{
char *pRun, *pEnd;
if (Length < 0)
Length = strlen(s);
for (pRun = s, pEnd = pRun + Length; pRun < pEnd; pRun++)
*pRun = CharTransTable[((usint)(*pRun)) & 0xff];
}
ShortInt StrCaseCmp(const char *s1, const char *s2, LongInt Hand1, LongInt Hand2)
{
int tmp;
tmp = mytoupper(*s1) - mytoupper(*s2);
if (!tmp)
tmp = strcasecmp(s1, s2);
if (!tmp)
tmp = Hand1 - Hand2;
if (tmp < 0)
return -1;
if (tmp > 0)
return 1;
return 0;
}
/****************************************************************************/
/* an einen Dateinamen eine Endung anhaengen */
void AddSuffix(char *s, char *Suff)
{
char *p, *z, *Part;
p = NULL;
for (z = s; *z != '\0'; z++)
if (*z == '\\')
p = z;
Part = p ? p : s;
if (!strchr(Part, '.'))
strmaxcat(s, Suff, 255);
}
/*--------------------------------------------------------------------------*/
/* von einem Dateinamen die Endung loeschen */
void KillSuffix(char *s)
{
char *p, *z, *Part;
p = NULL;
for (z = s; *z != '\0'; z++)
if (*z == '\\')
p = z;
Part = p ? p : s;
Part = strchr(Part, '.');
if (Part)
*Part = '\0';
}
/*--------------------------------------------------------------------------*/
/* Pfadanteil (Laufwerk+Verzeichnis) von einem Dateinamen abspalten */
char *PathPart(char *Name)
{
static String s;
char *p;
strmaxcpy(s, Name, 255);
p = strrchr(Name, PATHSEP);
#ifdef DRSEP
if (!p)
p = strrchr(Name, DRSEP);
#endif
if (!p)
*s = '\0';
else
s[1] = '\0';
return s;
}
/*--------------------------------------------------------------------------*/
/* Namensanteil von einem Dateinamen abspalten */
char *NamePart(char *Name)
{
char *p = strrchr(Name, PATHSEP);
#ifdef DRSEP
if (!p)
p = strrchr(Name, DRSEP);
#endif
return p ? p + 1 : Name;
}
/****************************************************************************/
/* eine Gleitkommazahl in einen String umwandeln */
char *FloatString(Double f)
{
#define MaxLen 18
static String s;
char *p, *d;
sint n, ExpVal, nzeroes;
Boolean WithE, OK;
/* 1. mit Maximallaenge wandeln, fuehrendes Vorzeichen weg */
sprintf(s, "%27.15e", f);
for (p = s; (*p == ' ') || (*p == '+'); p++);
if (p != s)
strmov(s, p);
/* 2. Exponenten soweit als moeglich kuerzen, evtl. ganz streichen */
p = strchr(s, 'e');
if (!p)
return s;
switch (*(++p))
{
case '+':
strmov(p, p + 1);
break;
case '-':
p++;
break;
}
while (*p == '0')
strmov(p, p + 1);
WithE = (*p != '\0');
if (!WithE)
s[strlen(s) - 1] = '\0';
/* 3. Nullen am Ende der Mantisse entfernen, Komma bleibt noch */
p = WithE ? strchr(s, 'e') : s + strlen(s);
p--;
while (*p == '0')
{
strmov(p, p + 1);
p--;
}
/* 4. auf die gewuenschte Maximalstellenzahl begrenzen */
p = WithE ? strchr(s, 'e') : s + strlen(s);
d = strchr(s, '.');
n = p - d - 1;
/* 5. Maximallaenge ueberschritten ? */
if (strlen(s) > MaxLen)
strmov(d + (n - (strlen(s) - MaxLen)), d + n);
/* 6. Exponentenwert berechnen */
if (WithE)
{
p = strchr(s, 'e');
ExpVal = ConstLongInt(p + 1, &OK, 10);
}
else
{
p = s + strlen(s);
ExpVal = 0;
}
/* 7. soviel Platz, dass wir den Exponenten weglassen und evtl. Nullen
anhaengen koennen ? */
if (ExpVal > 0)
{
nzeroes = ExpVal - (p - strchr(s, '.') - 1); /* = Zahl von Nullen, die anzuhaengen waere */
/* 7a. nur Kommaverschiebung erforderlich. Exponenten loeschen und
evtl. auch Komma */
if (nzeroes <= 0)
{
*p = '\0';
d = strchr(s, '.');
strmov(d, d + 1);
if (nzeroes != 0)
{
memmove(s + strlen(s) + nzeroes + 1, s + strlen(s) + nzeroes, -nzeroes);
s[strlen(s) - 1 + nzeroes] = '.';
}
}
/* 7b. Es muessen Nullen angehaengt werden. Schauen, ob nach Loeschen von
Punkt und E-Teil genuegend Platz ist */
else
{
n = strlen(p) + 1 + (MaxLen - strlen(s)); /* = Anzahl freizubekommender Zeichen+Gutschrift */
if (n >= nzeroes)
{
*p = '\0';
d = strchr(s, '.');
strmov(d, d + 1);
d = s + strlen(s);
for (n = 0; n < nzeroes; n++)
*(d++) = '0';
*d = '\0';
}
}
}
/* 8. soviel Platz, dass Exponent wegkann und die Zahl mit vielen Nullen
vorne geschrieben werden kann ? */
else if (ExpVal < 0)
{
n = (-ExpVal) - (strlen(p)); /* = Verlaengerung nach Operation */
if (strlen(s) + n <= MaxLen)
{
*p = '\0';
d = strchr(s, '.');
strmov(d, d + 1);
d = (s[0] == '-') ? s + 1 : s;
memmove(d - ExpVal + 1, d, strlen(s) + 1);
*(d++) = '0';
*(d++) = '.';
for (n = 0; n < -ExpVal - 1; n++)
*(d++) = '0';
}
}
/* 9. Ueberfluessiges Komma entfernen */
if (WithE)
{
p = strchr(s, 'e');
if (p)
*p = 'E';
}
else
p = s + strlen(s);
if ((p) && (*(p - 1) == '.'))
strmov(p - 1, p);
return s;
}
/****************************************************************************/
/* Symbol in String wandeln */
void StrSym(TempResult *t, Boolean WithSystem, char *Dest, int DestLen)
{
switch (t->Typ)
{
case TempInt:
HexString(Dest, DestLen - 3, t->Contents.Int, 1);
if (WithSystem)
switch (ConstMode)
{
case ConstModeIntel:
strcat(Dest, "H");
break;
case ConstModeMoto:
strprep(Dest, "$");
break;
case ConstModeC:
strprep(Dest, "0x");
break;
case ConstModeWeird :
strprep(Dest, "x'");
strcat(Dest, "'");
break;
}
break;
case TempFloat:
strmaxcpy(Dest, FloatString(t->Contents.Float), DestLen);
break;
case TempString:
snstrlenprint(Dest, DestLen, t->Contents.Ascii.Contents, t->Contents.Ascii.Length);
break;
default:
strmaxcpy(Dest, "???", DestLen);
}
}
/****************************************************************************/
/* Listingzaehler zuruecksetzen */
void ResetPageCounter(void)
{
int z;
for (z = 0; z <= ChapMax; z++)
PageCounter[z] = 0;
LstCounter = 0;
ChapDepth = 0;
}
/*--------------------------------------------------------------------------*/
/* eine neue Seite im Listing beginnen */
void NewPage(ShortInt Level, Boolean WithFF)
{
ShortInt z;
String Header, s;
char Save;
if (ListOn == 0)
return;
LstCounter = 0;
if (ChapDepth < (Byte) Level)
{
memmove(PageCounter + (Level - ChapDepth), PageCounter, (ChapDepth + 1) * sizeof(Word));
for (z = 0; z <= Level - ChapDepth; PageCounter[z++] = 1);
ChapDepth = Level;
}
for (z = 0; z <= Level - 1; PageCounter[z++] = 1);
PageCounter[Level]++;
if ((WithFF) && (!ListToNull))
{
errno = 0;
fprintf(LstFile, "%c", Char_FF);
ChkIO(10002);
}
sprintf(Header, " AS V%s%s%s",
Version,
getmessage(Num_HeadingFileNameLab),
NamePart(SourceFile));
if ((strcmp(CurrFileName, "INTERNAL"))
&& (strcmp(NamePart(CurrFileName), NamePart(SourceFile))))
{
strmaxcat(Header, "(", 255);
strmaxcat(Header, NamePart(CurrFileName), 255);
strmaxcat(Header, ")", 255);
}
strmaxcat(Header, getmessage(Num_HeadingPageLab), 255);
for (z = ChapDepth; z >= 0; z--)
{
sprintf(s, IntegerFormat, PageCounter[z]);
strmaxcat(Header, s, 255);
if (z != 0)
strmaxcat(Header, ".", 255);
}
strmaxcat(Header, " - ", 255);
NLS_CurrDateString(s);
strmaxcat(Header, s, 255);
strmaxcat(Header, " ", 255);
NLS_CurrTimeString(False, s);
strmaxcat(Header, s, 255);
if (PageWidth != 0)
while (strlen(Header) > PageWidth)
{
Save = Header[PageWidth];
Header[PageWidth] = '\0';
if (!ListToNull)
{
errno = 0;
fprintf(LstFile, "%s\n", Header);
ChkIO(10002);
}
Header[PageWidth] = Save;
strmov(Header, Header + PageWidth);
}
if (!ListToNull)
{
errno = 0;
fprintf(LstFile, "%s\n", Header);
ChkIO(10002);
if (PrtTitleString[0])
{
errno = 0;
fprintf(LstFile, "%s\n", PrtTitleString);
ChkIO(10002);
}
errno = 0;
fprintf(LstFile, "\n\n");
ChkIO(10002);
}
}
/*--------------------------------------------------------------------------*/
/* eine Zeile ins Listing schieben */
void WrLstLine(char *Line)
{
int LLength;
char bbuf[2500];
String LLine;
int blen = 0, hlen, z, Start;
if ((ListOn == 0) || (ListToNull))
return;
if (PageLength == 0)
{
errno = 0;
fprintf(LstFile, "%s\n", Line);
ChkIO(10002);
}
else
{
if ((PageWidth == 0) || ((strlen(Line) << 3) < PageWidth))
LLength = 1;
else
{
blen = 0;
for (z = 0; z < (int)strlen(Line); z++)
if (Line[z] == Char_HT)
{
memset(bbuf + blen, ' ', 8 - (blen & 7));
blen += 8 - (blen&7);
}
else
bbuf[blen++] = Line[z];
LLength = blen / PageWidth;
if (blen % PageWidth)
LLength++;
}
if (LLength == 1)
{
errno = 0;
fprintf(LstFile, "%s\n", Line);
ChkIO(10002);
if ((++LstCounter) == PageLength)
NewPage(0, True);
}
else
{
Start = 0;
for (z = 1; z <= LLength; z++)
{
hlen = PageWidth;
if (blen - Start < hlen)
hlen = blen - Start;
memcpy(LLine, bbuf + Start, hlen);
LLine[hlen] = '\0';
errno = 0;
fprintf(LstFile, "%s\n", LLine);
if ((++LstCounter) == PageLength)
NewPage(0, True);
Start += hlen;
}
}
}
}
/*****************************************************************************/
/* Ausdruck in Spalte vor Listing */
void SetListLineVal(TempResult *t)
{
StrSym(t, True, ListLine, STRINGSIZE);
strmaxprep(ListLine, "=", STRINGSIZE - 1);
if (strlen(ListLine) > 14)
{
ListLine[12] = '\0';
strmaxcat(ListLine, "..", STRINGSIZE - 1);
}
}
/*!------------------------------------------------------------------------
* \fn PrintOneLineMuted(FILE *pFile, const char *pLine,
const struct sLineComp *pMuteComponent,
const struct sLineComp *pMuteComponent2)
* \brief print a line, with a certain component muted out (i.e. replaced by spaces)
* \param pFile where to write
* \param pLine line to print
* \param pMuteComponent component to mute in printout
* ------------------------------------------------------------------------ */
static Boolean CompMatch(int Col, const struct sLineComp *pComp)
{
return (pComp
&& (pComp->StartCol >= 0)
&& (Col >= pComp->StartCol)
&& (Col < pComp->StartCol + (int)pComp->Len));
}
void PrintOneLineMuted(FILE *pFile, const char *pLine,
const struct sLineComp *pMuteComponent,
const struct sLineComp *pMuteComponent2)
{
int z, Len = strlen(pLine);
Boolean Match;
errno = 0;
for (z = 0; z < Len; z++)
{
Match = CompMatch(z, pMuteComponent) || CompMatch(z, pMuteComponent2);
fputc(Match ? ' ' : pLine[z], pFile);
}
fputc('\n', pFile);
ChkIO(10002);
}
/*!------------------------------------------------------------------------
* \fn PrLineMarker(FILE *pFile, const char *pLine, const char *pPrefix, const char *pTrailer,
char Marker, const struct sLineComp *pLineComp)
* \brief print a line, optionally with a marking of a component below
* \param pFile where to write
* \param pLine line to print/underline
* \param pPrefix what to print before (under)line
* \param pTrailer what to print after (under)line
* \param Marker character to use for marking
* \param pLineComp position and length of optional marker
* ------------------------------------------------------------------------ */
/* replace TABs in line with spaces - column counting counts TAB as one character */
char TabCompressed(char in)
{
return (in == '\t') ? ' ' : (myisprint(in) ? in : '*');
}
void PrLineMarker(FILE *pFile, const char *pLine, const char *pPrefix, const char *pTrailer,
char Marker, const struct sLineComp *pLineComp)
{
const char *pRun;
int z;
fputs(pPrefix, pFile);
for (pRun = pLine; *pRun; pRun++)
fputc(TabCompressed(*pRun), pFile);
fprintf(pFile, "%s\n", pTrailer);
if (pLineComp && (pLineComp->StartCol >= 0) && (pLineComp->Len > 0))
{
fputs(pPrefix, pFile);
if (pLineComp->StartCol > 0)
fprintf(pFile, "%*s", pLineComp->StartCol, "");
for (z = 0; z < (int)pLineComp->Len; z++)
fputc(Marker, pFile);
fprintf(pFile, "%s\n", pTrailer);
}
}
/*!------------------------------------------------------------------------
* \fn GenLineForMarking(char *pDest, unsigned DestSize, const char *pSrc, const char *pPrefix)
* \brief generate a line, in compressed form for optional marking of a component below
* \param pDest where to write
* \param DestSize destination buffer size
* \param pSrc line to print/underline
* \param pPrefix what to print before (under)line
* ------------------------------------------------------------------------ */
void GenLineForMarking(char *pDest, unsigned DestSize, const char *pSrc, const char *pPrefix)
{
char *pRun;
strmaxcpy(pDest, pPrefix, DestSize);
pRun = pDest + strlen(pDest);
/* replace TABs in line with spaces - column counting counts TAB as one character */