-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
1882 lines (1821 loc) · 52.9 KB
/
main.cpp
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
#define _MAIN_
#include <fcntl.h>
#include <sys/stat.h>
#ifndef _MSC_VER
#include <unistd.h>
#else
#include <io.h>
#endif
#include "misc.h"
#include "tok.h"
static char **_Argv; //!!! simplest way to make your own variable
unsigned char compilerstr[] = "SPHINX C-- 0.240";
char *rawfilename; /* file name */
char *rawext;
LISTCOM *listcom;
EWAR wartype = {stdout, NULL}, errfile = {NULL, NULL};
int numfindpath = 0;
char *findpath[16];
char modelmem = TINY;
char *stubfile = NULL;
char *winstub = NULL;
FILE *hout = NULL;
char *namestartupfile = "startup.h--";
char outext[4] = "com";
// int scrsize;
unsigned char gwarning = FALSE;
unsigned char sobj = FALSE;
unsigned char usestub = TRUE;
unsigned char dpmistub = FALSE;
short dllflag = FALSE;
static int numstr;
char meinfo[] = "\nEdition of this version by\n"
" Mishel Sheker\n"
" Fido 2:5021/3.40\n"
" E-Mail [email protected]\n"
" Russia";
time_t systime;
struct tm timeptr;
char comsymbios = FALSE;
char fobj = FALSE; //признак генерации obj
unsigned int startptr = 0x100; // start address
unsigned char wconsole =
FALSE; //признак генерации консольного приложения windows
unsigned char optstr = FALSE; //оптимизация строковых констант
unsigned char crif = TRUE; // check reply include file
unsigned char idasm = FALSE; //ассемблерные инструкции считать идентификаторами
unsigned char wbss = 2; //пост переменные в отдельную секцию
unsigned char use_env = FALSE; //переменная окружения
int numrel = 0; //число элементов в таблице перемещений
unsigned char useordinal = FALSE;
unsigned char useDOS4GW = FALSE;
unsigned char clearpost = FALSE;
unsigned char uselea = TRUE;
unsigned char regoverstack = TRUE;
unsigned char shortimport = FALSE;
unsigned char useinline = 2;
unsigned char ocoff = FALSE;
unsigned char ESPloc = FALSE;
int startupfile = -1;
int alignproc = 8, aligncycle = 8;
char const *usage[] = {
"USAGE: C-- [options] [FILE_NAME.INI] [SOURCE_FILE_NAME]", "",
" C-- COMPILER OPTIONS", "",
" OPTIMIZATION",
"/OC optimize for code size /DE enable temporary expansion "
"variable",
"/OS optimize for speed /OST enable optimization string",
"/ON enable optimization number /AP[=n] align start function",
"/UST use startup code for variables /AC[=n] align start cycles",
#ifdef OPTVARCONST
"/ORV replase variable on constant /OIR skip repeate initializing "
"register",
#else
" /OIR skip repeate initializing "
"register",
#endif
"", " CODE GENERATION",
"/2 80286 code optimizations /SA=#### start code address",
"/3 80386 code optimizations /AL=## set value insert byte",
"/4 80486 code optimizations /WFA fast call API functions",
"/5 pentium code optimizations /IV initial all variables",
"/A enable address alignment /SUV=#### start address variables",
"/AS[=n] def. alignment in structures /LRS load in registers over stack",
"/UL use 'lea' for adding registers /JS join stack calling functions",
"/BA byte access to array", // /ASP addressing local variable
// via ESP",
"", " PREPROCESSOR",
"/IP=<path> include file path /IA assembly instructions as "
"identifier",
"/D=<idname> defined identifier /CRI- not check include file on "
"repeated",
"/MIF=<file> main input file /IND=<name> impotr name from dll",
"/SF=<file> other startup file", "",
" LINKING",
"/AT insert ATEXIT support block /NS disable stub",
"/ARGC insert parse command line /S=##### set stack size",
"/P insert parse command line /WIB=##### set image base address",
"/C insert CTRL<C> ignoring code /WFU add Fix Up table, for "
"Windows",
"/R insert resize memory block /WMB create Windows mono block",
"/ENV insert variable with environ /WS=<name> set name stub file for "
"win32",
"/J0 disable initial jump to main() /WBSS set post data in bss section",
"/J1 initial jump to main() short /WO call API functions on "
"ordinals",
"/J2 initial jump to main() near /CPA clear post area",
"/STUB= <name> set name stub file /WSI short import table, for "
"Windows",
"/DOS4GW file running with DOS4GW /WAF=#### align Windows file (def "
"512)",
"/STM startup code in main function", "",
" OUTPUT FILES",
"/TEXE DOS EXE file (model TINY) /D32 EXE file (32bit code for DOS)",
"/EXE DOS EXE file (model SMALL) /W32 EXE for Windows32 GUI",
"/OBJ OBJ output file /W32C EXE for Windows32 console",
"/SOBJ slave OBJ output file /DLL DLL for Windows32",
"/COFF OBJ COFF output file /DBG create debug information",
"/SYM COM file symbiosis /LST create assembly listing",
"/SYS device (SYS) file /B32 32bit binary files",
"/MEOS executable file for MeOS /MAP create function map file", "",
" MISCELLANEOUS",
"/HELP /H /? help, this info /WORDS list of C-- reserved words",
"/W enable warning /LAI list of assembler "
"instructions",
"/WF=<file> direct warnings to a file /ME display my name and my "
"address",
"/MER=## set maximum number errors /X disable SPHINXC-- header in "
"output",
"/NW=## disable select warning /WE=## selected warning will be "
"error",
//" /SCD split code and date",
NULL};
char const *dir[] = {
"ME", "WORDS", "SYM", "LAI",
"OBJ", "SOBJ", "J0", "J1", "J2", "C", "R", "P", "X",
"EXE", "S", "SYS", "ARGC", "TEXE", "ROM", "W32", "D32", "W32C",
"AT", "WFA", "SA", "STM", "SUV", "UST", "MIF", "DLL", "DOS4GW",
"ENV", "CPA", "WBSS", "MEOS", "SF", "B32", "WIB", "DBG",
"OS", "OC", "A", "0", "1", "2", "3", "4", "5",
"6", "7", "8", "9", "W", "WF", "DE", "ON", "IP",
"STUB", "NS", "AP", "D", "OST", "CRI", "IA", "SCD", "AL",
"WFU", "IV", "MER", "WMB", "HELP", "H", "?", "AC", "WS",
"IND", "WO", "NW", "LST", "AS", "UL", "LRS", "WSI", "WAF",
"OIR", "COFF", "JS", "BA", "ASP",
#ifdef OPTVARCONST
"ORV",
#endif
"MAP", "WE", NULL};
enum {
c_me,
c_key,
c_sym,
c_lasm,
c_endinfo = c_lasm,
c_obj,
c_sobj,
c_j0,
c_j1,
c_j2,
c_ctrlc,
c_r,
c_p,
c_x,
c_exe,
c_s,
c_sys,
c_arg,
c_texe,
c_rom,
c_w32,
c_d32,
c_w32c,
c_at,
c_wfa,
c_sa,
c_stm,
c_suv,
c_ust,
c_mif,
c_dll,
c_d4g,
c_env,
c_cpa,
c_wbss,
c_meos,
c_sf,
c_b32,
c_wib,
c_dbg,
c_endstart = c_dbg,
c_os,
c_oc,
c_a,
c_0,
c_1,
c_2,
c_3,
c_4,
c_5,
c_6,
c_7,
c_8,
c_9,
c_w,
c_wf,
c_de,
c_opnum,
c_ip,
c_stub,
c_ns,
c_ap,
c_define,
c_ost,
c_cri,
c_ia,
c_scd,
c_al,
c_wfu,
c_iv,
c_mer,
c_wmb,
c_help,
c_h,
c_hh,
c_ac,
c_ws,
c_ind,
c_wo,
c_nw,
c_lst,
c_as,
c_ul,
c_lrs,
c_wsi,
c_waf,
c_oir,
c_coff,
c_js,
c_ba,
c_asp,
#ifdef OPTVARCONST
c_orv,
#endif
c_map,
c_we,
c_end
};
#define NUMEXT 6 //число разрешенных расширений компилируемого файла
char extcompile[NUMEXT][4] = {"c--", "cmm", "c", "h--", "hmm", "h"};
char *bufstr = NULL; //буфер для строк из процедур
int sbufstr = SIZEBUF; //начальный размер этого буфера
void compile();
void PrintInfo(char const **str);
void LoadIni(char *name);
// void CheckNumStr();
void ListId(int num, unsigned char *list, unsigned short *ofs);
void printmemsizes();
void print8item(const char *str);
void doposts(void);
void GetMemExeDat();
void AddJmpApi();
void startsymbiosys(char *symfile);
int writeoutput();
void BadCommandLine(char *str);
void CheckExtenshions();
void ImportName(char *name);
void WarnUnusedVar(); //предупреждения о неиспользованных процедурах и
//переменных
void MakeExeHeader(EXE_DOS_HEADER *exeheader);
void CheckPageCode(unsigned int ofs);
int MakePE();
int MakeObj();
void CheckUndefClassProc();
/*
void PrintTegList(structteg *tteg)
{
if(tteg){
PrintTegList(tteg->left);
PrintTegList(tteg->right);
puts(tteg->name);
}
} */
// unsigned long maxusedmem=0;
void ErrOpenFile(char *str) {
fprintf(stderr, "Unable to open file %s.\n", str);
}
int main(int argc, char *argv[]) {
int count;
unsigned char pari = FALSE;
printf("\nSPHINX C-- Compiler Version %d.%d%s %s\n", ver1, ver2, betta,
__DATE__);
#ifndef _UNIX_
// if(isatty(1)==0)outfile=0;
#endif
// scrsize=24;
if (argc > 1) {
_Argv = argv; // This make portable code
bufstr = (char *)MALLOC(SIZEBUF);
output = (unsigned char *)MALLOC((size_t)MAXDATA);
outputdata = output;
postbuf = (postinfo *)MALLOC(MAXPOSTS * sizeof(postinfo));
strcpy((char *)string, argv[0]);
rawext = strrchr((char *)string, PATH_SEP_C);
if (rawext != NULL) {
rawext[0] = 0;
IncludePath((char *)string);
}
rawfilename = getenv("C--");
if (rawfilename != NULL)
IncludePath(rawfilename);
rawfilename = rawext = NULL;
LoadIni("c--.ini");
for (count = 1; count < argc; count++) { //обработка командной строки
if (argv[count][0] == '/' || argv[count][0] == '-') {
if (SelectComand(argv[count] + 1, &count) == c_end)
BadCommandLine(argv[count]);
} else {
if (pari == FALSE) {
rawfilename = argv[count];
pari = TRUE;
if ((rawext = strrchr(rawfilename, '.')) != NULL) {
if (strcmp(rawext, ".ini") == 0) { //указан ini файл
rawfilename = NULL;
rawext = NULL;
LoadIni(argv[count]);
if (rawfilename == NULL)
pari = FALSE;
} else {
*rawext++ = 0;
CheckExtenshions();
}
}
}
}
}
}
if (rawfilename == NULL) {
PrintInfo(usage);
exit(e_noinputspecified);
}
time(&systime); //текущее время
memcpy(&timeptr, localtime(&systime), sizeof(tm));
InitDefineConst();
compile();
if (error == 0)
exit(e_ok);
exit(e_someerrors);
}
void CheckExtenshions() {
int i;
for (i = 0; i < NUMEXT; i++) {
if (strcmp(rawext, extcompile[i]) == 0)
break;
}
if (i == NUMEXT) {
printf("Bad input file extension '%s'.", rawext);
exit(e_badinputfilename);
}
}
void compile() {
long segments_required;
union {
long longhold;
void *nextstr;
};
//создатьь имя файла с предупреждениями и если он есть удалить
errfile.name = (char *)MALLOC(strlen(rawfilename) + 5);
sprintf(errfile.name, "%s.err", rawfilename);
if (stat(errfile.name, (struct stat *)string2) == 0)
remove(errfile.name);
//если есть имя файла для предупреждений проверить его существование и
//удалить.
if (wartype.name != NULL) {
if (stat(wartype.name, (struct stat *)string2) == 0)
remove(wartype.name);
}
puts("Compiling Commenced . . .");
if (rawext != NULL)
sprintf((char *)string, "%s.%s", rawfilename, rawext);
else {
for (unsigned int i = 0; i < NUMEXT; i++) {
sprintf((char *)string, "%s.%s", rawfilename, extcompile[i]);
if (stat((char *)string, (struct stat *)string2) == 0)
break;
}
}
linenumber = 0;
initregstat();
#ifdef OPTVARCONST
CreateMainLVIC();
#endif
#ifdef __NEWLEX__
inittokn();
#endif
compilefile((char *)string, 2); //собствено разборка и компиляция
puts("Link . . .");
if (comfile == file_w32 && wbss == 2) {
wbss = FALSE;
if (wconsole == FALSE)
wbss = TRUE;
}
if (notdoneprestuff == TRUE)
doprestuff(); // startup cod
if (endifcount >= 0)
preerror("?endif expected before end of file");
AddObj();
docalls(); //добавить внешние процедуры
addinitvar();
CheckUndefClassProc();
if (undefoffstart != NULL) { //выдать список неизвестных ссылок
UNDEFOFF *curptr = undefoffstart;
for (;;) {
char holdstr[84];
UNDEFOFF *ocurptr;
linenumber = curptr->pos->line;
sprintf(holdstr, "\'%s\' offset undefined", curptr->name);
currentfileinfo = curptr->pos->file;
preerror(holdstr);
free(curptr->pos);
if (curptr->next == NULL)
break;
ocurptr = curptr->next;
free(curptr);
curptr = ocurptr;
}
free(curptr);
}
while (liststring != NULL) {
STRING_LIST *ins;
ins = (STRING_LIST *)liststring;
nextstr = ins->next;
free(liststring);
liststring = nextstr;
}
free(bufstr);
if (warning == TRUE && wact[7].usewarn)
WarnUnusedVar(); //предупреждения о неиспользованных процедурах и переменных
if (numstrtbl)
CreatStrTabRes(); //завершить создание ресурсов
if (fobj == FALSE) {
if (comfile == file_w32 && error == 0) {
AddJmpApi(); //коственные вызовы API
CreatWinStub();
}
longhold = outptr;
if (comfile == file_rom) {
ooutptr = outptr;
if (modelmem == SMALL) {
*(short *)&output[stackstartaddress] =
(short)(((outptrdata + postsize + stacksize) / 4 + 1) * 4);
*(short *)&output[dataromstart] = (short)(outptr + 4);
*(short *)&output[dataromsize] = (short)(outptrdata / 2);
// printf("outptr=%d outptrdate=%d
// outptrsize=%d\n",outptr,outptrdata,outptrsize);
for (unsigned int i = 0; i < outptrdata; i++)
op(outputdata[i]);
}
if (romsize == 0) {
unsigned int i = outptr / 1024;
if ((outptr % 1024) != 0)
i++;
if (i > 32)
i = 64;
else if (i > 16)
i = 32;
else if (i > 8)
i = 16;
else if (i > 4)
i = 8;
else if (i > 2)
i = 4;
romsize = i * 1024;
output[2] = (unsigned char)(romsize / 512);
}
if (outptr >= romsize)
preerror("The size of a code is more than the size of the ROM");
for (; outptr < romsize;)
op(aligner);
unsigned char summa = 0;
for (unsigned int i = 0; i < romsize; i++)
summa += output[i];
output[romsize - 1] -= summa;
outptr = ooutptr;
} else if (modelmem == SMALL && comfile == file_exe) { // if an EXE file
longhold += AlignCD(CS, 16);
// if((outptr%16)!=0)outptr+=16-outptr%16;//
// paragraph align the end of the code seg
if (((long)outptrdata + (long)postsize + (long)stacksize) > 65535L)
preerror("Data and stack total exceeds 64k");
} else if (comfile == file_sys) {
for (int i = 0; i < sysnumcom; i++) {
searchvar((listcom + i)->name);
*(short *)&output[syscom + i * 2] = (unsigned short)itok.number;
}
free(listcom);
} else
longhold += (long)postsize + (long)(stacksize);
if (am32 == 0 && longhold > 65535L && !(modelmem == TINY && (!resizemem)))
preerror("Code, data and stack total exceeds 64k");
if (posts > 0)
doposts(); //Установить адреса вызовов процедур и переходов
if (resizemem && comfile == file_com) {
segments_required = (outptr + postsize + stacksize + 15) / 16;
*(short *)&output[resizesizeaddress] = (short)segments_required;
*(short *)&output[stackstartaddress] = (short)(segments_required * 16);
}
}
deinitregstat();
#ifdef OPTVARCONST
KillMainLVIC();
#endif
// puts("List Teg name:");
// PrintTegList(tegtree);
printf("COMPILING FINISHED. Errors: %d\n", error);
if (error == 0) {
if (cpu >= 1) {
char m1[12];
switch (cpu) {
case 5:
strcpy(m1, "Pentium");
break;
case 6:
strcpy(m1, "MMX");
break;
case 7:
strcpy(m1, "Pentium II");
break;
case 8:
strcpy(m1, "Pentium III");
break;
case 9:
strcpy(m1, "Pentium IV");
break;
default:
sprintf(m1, "80%d86", cpu);
}
printf("CPU required: %s or greater.\n", m1);
}
runfilesize = outptr - startptr;
if (comfile == file_rom)
runfilesize = romsize;
else if (modelmem == SMALL && comfile == file_exe) {
runfilesize += outptrdata - startptrdata + 0x20;
postsize += postsize % 2;
stacksize = (stacksize + 15) / 16 * 16;
} else if ((comfile == file_exe || comfile == file_d32) && modelmem == TINY)
runfilesize += 0x20;
printmemsizes();
endinptr = outptr;
if (writeoutput() == 0)
printf("Run File Saved (%ld bytes).\n", runfilesize);
if (comfile == file_w32 && fobj == FALSE)
printf("Created file of a format PE for Windows.\nFor alignment section "
"code, added %u zero bytes.\n",
filingzerope);
// else if(FILEALIGN&&fobj==FALSE)printf("For alignment file, added
//%u zero bytes.\n",filingzerope);
}
if (pdbg)
DoTDS();
}
void printmemsizes() {
long stacklong;
unsigned int stackword;
unsigned int postword, codeword;
postword = postsize;
codeword = outptr - startptr;
stackword = stacksize;
if (comfile == file_com || (comfile == file_exe && modelmem == TINY)) {
if (resizemem == 0) {
stacklong = 0xFFFE - outptr - postsize;
stackword = stacklong;
}
codeword = codeword - datasize - alignersize;
} else if (comfile == file_sys)
stackword = sysstack;
else if (comfile == file_exe || comfile == file_rom)
datasize = outptrdata;
else if (comfile == file_d32)
codeword -= datasize;
printf("Code: %u bytes, Data: %u bytes, Post: %u bytes, Stack: %u bytes\n",
codeword, datasize, postword, stackword);
for (unsigned int i = 0; i < posts; i++) {
switch ((postbuf + i)->type) {
case CODE_SIZE:
*(short *)&output[(postbuf + i)->loc] += codeword;
break;
case CODE_SIZE32:
*(long *)&output[(postbuf + i)->loc] += codeword;
break;
case DATA_SIZE:
*(short *)&output[(postbuf + i)->loc] += datasize;
break;
case DATA_SIZE32:
*(long *)&output[(postbuf + i)->loc] += datasize;
break;
case POST_SIZE:
*(short *)&output[(postbuf + i)->loc] += postword;
break;
case POST_SIZE32:
*(long *)&output[(postbuf + i)->loc] += postword;
break;
case STACK_SIZE:
*(short *)&output[(postbuf + i)->loc] += stackword;
break;
case STACK_SIZE32:
*(long *)&output[(postbuf + i)->loc] += stackword;
break;
}
}
}
void PrintInfo(char const **str) {
numstr = 1;
for (int i = 0; str[i] != NULL; i++) {
puts(str[i]);
// CheckNumStr();
}
}
/*void CheckNumStr()
{
#ifndef _UNIX_
if(((numstr+1)%(scrsize-1))==0&&outfile!=0){
puts("Press any key...");
getch();
}
numstr++;
#endif
} */
void strbtrim(char *st) {
int i;
char *p, *q;
p = q = st;
while (isspace(*p))
p++; //пока незначащие символы
while (*p)
*q++ = *p++; //переместить строку
*q = '\0';
for (i = strlen(st) - 1; isspace(st[i]) && i >= 0; i--)
;
st[i + 1] = '\0';
}
unsigned long getnumber(unsigned char *buf) {
int temp2;
unsigned long retnum;
unsigned char *oinput;
unsigned int oinptr, oendinptr;
if (!isdigit(buf[0]))
return 0;
oinptr = inptr;
oinput = input;
oendinptr = endinptr;
input = buf;
inptr = 0;
endinptr = 256;
retnum = scannumber(&temp2);
inptr = oinptr;
input = oinput;
endinptr = oendinptr;
return retnum;
}
int SelectComand(char *pptr, int *count) {
int i;
unsigned char neg = FALSE;
char *ptr;
int len;
if ((ptr = strchr(pptr, ';')) != NULL)
*ptr = 0; // ищем комментарий отсекаем все после него
if ((ptr = strchr(pptr, '=')) != NULL) { // ищем знак равенства
*ptr = 0; // делим
ptr++;
strbtrim(ptr); //убрать лишние пробелы
}
strbtrim(pptr); //убрать лишние пробелы
if (*pptr == 0)
return c_end + 1; //пустая строка
if ((i = strlen(pptr)) > 1 && pptr[i - 1] == '-') {
neg = TRUE;
pptr[i - 1] = 0;
}
cmm_strupr(pptr);
for (i = 0; dir[i] != NULL; i++) {
if (strcmp(dir[i], pptr) == 0) {
if ((i <= c_endinfo) && count == 0) {
char buf[80];
sprintf(buf, "Option '%s' used only command line", dir[i]);
preerror(buf);
return i;
}
if (i <= c_endstart && notdoneprestuff != TRUE) {
errlate:
char buf[80];
sprintf(buf, "Too late used '#pragma option %s'", dir[i]);
preerror(buf);
return i;
}
switch (i) {
case c_j0:
jumptomain = (unsigned char)(neg != FALSE ? CALL_NEAR : CALL_NONE);
header = (unsigned char)0 ^ neg;
break;
case c_j1:
jumptomain = (unsigned char)CALL_SHORT;
header = (unsigned char)1;
break;
case c_j2:
jumptomain = (unsigned char)(neg == FALSE ? CALL_NEAR : CALL_NONE);
header = (unsigned char)1 ^ neg;
break;
case c_ctrlc:
killctrlc = (unsigned char)1 ^ neg;
break;
case c_os:
optimizespeed = (unsigned char)1 ^ neg;
break;
case c_oc:
optimizespeed = (unsigned char)0 ^ neg;
break;
case c_r:
resizemem = (unsigned char)1 ^ neg;
break;
case c_p:
parsecommandline = (unsigned char)1 ^ neg;
break;
case c_a:
alignword = (unsigned char)1 ^ neg;
break;
case c_sym:
startptr = 0x100;
comsymbios = TRUE;
*count = *count + 1;
startsymbiosys(_Argv[*count]);
break;
case c_0:
chip = 0;
break;
case c_1:
chip = 1;
break;
case c_2:
chip = 2;
break;
case c_3:
chip = 3;
break;
case c_4:
chip = 4;
break;
case c_5:
chip = 5;
break;
case c_6:
chip = 6;
break; // MMX
case c_7:
chip = 7;
break; // Pro
case c_8:
chip = 8;
break; // PII
case c_9:
chip = 9;
break; // PIII
case c_x:
header = (unsigned char)0 ^ neg;
break;
case c_exe:
comfile = file_exe;
modelmem = SMALL;
splitdata = TRUE;
GetMemExeDat();
strcpy(outext, "exe");
startptr = 0; // start address
startptrdata = 0; // data start address
dos1 = 2;
dos2 = 0;
break;
case c_sys:
comfile = file_sys;
strcpy(outext, "sys");
startptr = 0; // start address
startptrdata = 0; // data start address
jumptomain = CALL_NONE;
header = 0;
break;
case c_sobj:
sobj = TRUE;
FixUp = TRUE;
jumptomain = CALL_NONE;
case c_obj:
fobj = TRUE;
// if(comfile==file_d32)FixUp=TRUE;
FastCallApi = FALSE;
break;
case c_me:
puts(meinfo);
exit(e_ok);
case c_key:
int j, jj;
puts("LIST OF RESERVED IDENTIFIERS:");
numstr = 1;
ListId(53, id, idofs);
for (j = 0; j < ID2S; j++) {
puts(id2[j]);
// CheckNumStr();
}
for (jj = 0; jj < 2; jj++) {
for (j = 0; j < 8; j++)
printf("%s ", regs[jj][j]);
puts("");
// CheckNumStr();
}
for (j = 0; j < 8; j++)
printf("%s ", begs[j]);
puts("");
// CheckNumStr();
for (j = 0; j < 6; j++)
printf("%s ", segs[j]);
print8item("ST(%d) ");
puts("ST");
print8item("st(%d) ");
puts("st");
exit(e_ok);
case c_lasm:
puts("LIST OF SUPPORTED ASSEMBLER INSTRUCTIONS:");
numstr = 1;
ListId(26, asmMnem, ofsmnem);
exit(e_ok);
case c_s:
if (ptr == NULL)
return c_end;
if ((stacksize = getnumber((unsigned char *)ptr)) == 0) {
puts("Bad stack size.");
exit(e_unknowncommandline);
}
stacksize = Align(stacksize, 4);
break;
case c_w:
gwarning = (unsigned char)TRUE ^ neg;
break;
case c_wf:
if (wartype.name)
free(wartype.name);
wartype.name = BackString(ptr);
break;
case c_de:
divexpand = (unsigned char)TRUE ^ neg;
break;
case c_opnum:
optnumber = (unsigned char)TRUE ^ neg;
break;
case c_ip:
IncludePath(ptr);
break;
case c_arg:
parsecommandline = (unsigned char)TRUE ^ neg;
fargc = (unsigned char)TRUE ^ neg;
break;
case c_texe:
strcpy(outext, "exe");
comfile = file_exe;
break;
case c_rom:
strcpy(outext, "rom");
comfile = file_rom;
startptr = 0;
startptrdata = 0; // data start address
GetMemExeDat();
break;
case c_dll:
wconsole = TRUE;
dllflag = TRUE;
strcpy(outext, "dll");
comfile = file_w32;
FixUpTable = TRUE;
goto nexpardll;
/* FixUp=TRUE;
startptrdata=startptr=0;
am32=TRUE;
if(chip<3)chip=3;
if(FILEALIGN==0)FILEALIGN=512;
break;*/
case c_w32c:
wconsole = TRUE;
goto init_w32;
case c_w32:
wconsole = FALSE;
dllflag = FALSE;
init_w32:
comfile = file_w32;
goto nexpar;
case c_d32:
comfile = file_d32;
nexpar:
strcpy(outext, "exe");
nexpardll:
FixUp = TRUE;
startptrdata = startptr = 0;
am32 = TRUE;
if (chip < 3)
chip = 3;
if (FILEALIGN == 0)
FILEALIGN = 512;
break;
case c_meos:
comfile = file_meos;
am32 = TRUE;
startptrdata = startptr = 0;
strcpy(outext, "");
if (chip < 3)
chip = 3;
break;
case c_b32:
comfile = file_bin;
am32 = TRUE;
startptrdata = startptr = 0;
strcpy(outext, "bin");
FixUp = TRUE;
ImageBase = 0;
if (chip < 3)
chip = 3;
break;
case c_stub:
if (stubfile)
free(stubfile);
stubfile = BackString(ptr);
dpmistub = FALSE;
if (strcmp(stubfile, "dpmi") == 0) {
if (notdoneprestuff != TRUE)
goto errlate;
dpmistub = TRUE;
usestub = FALSE;
}
break;
case c_ns:
usestub = (unsigned char)0 ^ neg;
break;
case c_ap:
AlignProc = (unsigned char)1 ^ neg;
if (ptr != NULL) {
alignproc = getnumber((unsigned char *)ptr);
if (alignproc < 1 || alignproc > 4096)
alignproc = 8;
}
break;
case c_define:
addconsttotree(ptr, TRUE);
break;
case c_ost:
optstr = (unsigned char)TRUE ^ neg;
break;
case c_cri:
crif = (unsigned char)1 ^ neg;
break;
case c_ia:
idasm = (unsigned char)1 ^ neg;
break;
case c_dbg:
dbg &= 0xFE;
char c;
c = (unsigned char)1 ^ neg;
dbg |= c;
if (!neg)
InitDbg();
break;
case c_scd:
/*-----------------13.08.00 23:01-------------------
будет введена после доработки динамических процедур
--------------------------------------------------*/
splitdata = (unsigned char)1 ^ neg;
if (modelmem == SMALL)
splitdata = TRUE;