Subversion Repositories Kolibri OS

Rev

Rev 6447 | Rev 7543 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6447 Rev 6618
1
#define _MAIN_
1
#define _MAIN_
2
 
2
 
3
#ifdef _UNIX_
3
#ifdef _UNIX_
4
#define DIV_PATH ':'			//äåëèòåëü ïóòåé â ïåðåìåííîé îêðóæåíèÿ PATH
4
#define DIV_PATH ':'			//äåëèòåëü ïóòåé â ïåðåìåííîé îêðóæåíèÿ PATH
5
#define DIV_FOLD '/'			//ýòèì ñèìâîëîì ðàçäåëÿþòñÿ ïàïêè â ïóòè ê ôàéëó
5
#define DIV_FOLD '/'			//ýòèì ñèìâîëîì ðàçäåëÿþòñÿ ïàïêè â ïóòè ê ôàéëó
6
#endif
6
#endif
7
 
7
 
8
#ifdef _WIN32_
8
#ifdef _WIN32_
9
#define DIV_PATH ';'
9
#define DIV_PATH ';'
10
#define DIV_FOLD '\\'
10
#define DIV_FOLD '\\'
11
#endif
11
#endif
12
 
12
 
13
#ifdef _KOS_
13
#ifdef _KOS_
14
#define DIV_PATH ';'
14
#define DIV_PATH ';'
15
#define DIV_FOLD '/'
15
#define DIV_FOLD '/'
16
#endif
16
#endif
17
 
17
 
18
#include 
18
#include 
-
 
19
#include 
-
 
20
#include 
19
#include 
21
#include 
20
#include "tok.h"
22
#include "tok.h"
21
 
23
 
22
static char **_Argv; //!!! simplest way to make your own variable
24
static char **_Argv; //!!! simplest way to make your own variable
23
 
25
 
24
unsigned char compilerstr[]="SPHINX C-- 0.239";
26
unsigned char compilerstr[]="SPHINX C-- 0.239";
25
char *rawfilename;					/* file name */
27
char *rawfilename;					/* file name */
26
char *rawext;
28
char *rawext;
27
LISTCOM *listcom;
29
LISTCOM *listcom;
28
EWAR wartype={NULL,NULL},errfile={NULL,NULL};
30
EWAR wartype={NULL,NULL},errfile={NULL,NULL};
29
int numfindpath=0;
31
int numfindpath=0;
30
char *findpath[16];
32
char *findpath[16];
31
char modelmem=TINY;
33
char modelmem=TINY;
32
char *stubfile=NULL;
34
char *stubfile=NULL;
33
char *winstub=NULL;
35
char *winstub=NULL;
34
FILE *hout=NULL;
36
FILE *hout=NULL;
35
char *namestartupfile="startup.h--";
37
char *namestartupfile="startup.h--";
36
 
38
 
37
char outext[4]="com";
39
char outext[4]="com";
38
short extflag=TRUE;//ðàñøèðåíèå ìîæíî ïðèñâîèòü
40
short extflag=TRUE;//ðàñøèðåíèå ìîæíî ïðèñâîèòü
39
//int scrsize;
41
//int scrsize;
40
unsigned char gwarning=FALSE;
42
unsigned char gwarning=FALSE;
41
unsigned char sobj=FALSE;
43
unsigned char sobj=FALSE;
42
unsigned char usestub=TRUE;
44
unsigned char usestub=TRUE;
43
unsigned char dpmistub=FALSE;
45
unsigned char dpmistub=FALSE;
44
short dllflag=FALSE;
46
short dllflag=FALSE;
45
static int numstr;
47
static int numstr;
46
 
48
 
47
char meinfo[]=
49
char meinfo[]=
48
	"\nEdition of this version by\n"
50
	"\nEdition of this version by\n"
49
	"    Mishel Sheker\n"
51
	"    Mishel Sheker\n"
50
	"    Fido 2:5021/3.40\n"
52
	"    Fido 2:5021/3.40\n"
51
	"    E-Mail sheker@mail.ru\n"
53
	"    E-Mail sheker@mail.ru\n"
52
	"    Russia";
54
	"    Russia";
53
 
55
 
54
time_t systime;
56
time_t systime;
55
struct tm timeptr;
57
struct tm timeptr;
56
char comsymbios=FALSE;
58
char comsymbios=FALSE;
57
char fobj=FALSE;	//ïðèçíàê ãåíåðàöèè obj
59
char fobj=FALSE;	//ïðèçíàê ãåíåðàöèè obj
58
unsigned int	startptr = 0x100; 			// start address
60
unsigned int	startptr = 0x100; 			// start address
59
unsigned char wconsole=FALSE;	//ïðèçíàê ãåíåðàöèè êîíñîëüíîãî ïðèëîæåíèÿ windows
61
unsigned char wconsole=FALSE;	//ïðèçíàê ãåíåðàöèè êîíñîëüíîãî ïðèëîæåíèÿ windows
60
unsigned char optstr=FALSE;	//îïòèìèçàöèÿ ñòðîêîâûõ êîíñòàíò
62
unsigned char optstr=FALSE;	//îïòèìèçàöèÿ ñòðîêîâûõ êîíñòàíò
61
unsigned char crif=TRUE;	//check reply include file
63
unsigned char crif=TRUE;	//check reply include file
62
unsigned char idasm=FALSE;	//àññåìáëåðíûå èíñòðóêöèè ñ÷èòàòü èäåíòèôèêàòîðàìè
64
unsigned char idasm=FALSE;	//àññåìáëåðíûå èíñòðóêöèè ñ÷èòàòü èäåíòèôèêàòîðàìè
63
unsigned char wbss=2;	//ïîñò ïåðåìåííûå â îòäåëüíóþ ñåêöèþ
65
unsigned char wbss=2;	//ïîñò ïåðåìåííûå â îòäåëüíóþ ñåêöèþ
64
unsigned char use_env=FALSE;	//ïåðåìåííàÿ îêðóæåíèÿ
66
unsigned char use_env=FALSE;	//ïåðåìåííàÿ îêðóæåíèÿ
65
int numrel=0;	//÷èñëî ýëåìåíòîâ â òàáëèöå ïåðåìåùåíèé
67
int numrel=0;	//÷èñëî ýëåìåíòîâ â òàáëèöå ïåðåìåùåíèé
66
unsigned char useordinal=FALSE;
68
unsigned char useordinal=FALSE;
67
unsigned char useDOS4GW=FALSE;
69
unsigned char useDOS4GW=FALSE;
68
unsigned char clearpost=FALSE;
70
unsigned char clearpost=FALSE;
69
unsigned char uselea=TRUE;
71
unsigned char uselea=TRUE;
70
unsigned char regoverstack=TRUE;
72
unsigned char regoverstack=TRUE;
71
unsigned char shortimport=FALSE;
73
unsigned char shortimport=FALSE;
72
unsigned char useinline=2;
74
unsigned char useinline=2;
73
unsigned char ocoff=FALSE;
75
unsigned char ocoff=FALSE;
74
unsigned char ESPloc=FALSE;
76
unsigned char ESPloc=FALSE;
75
 
77
 
76
int startupfile=-1;
78
int startupfile=-1;
77
int alignproc=8,aligncycle=8;
79
int alignproc=8,aligncycle=8;
78
 
80
 
79
char *usage[]={
81
char *usage[]={
80
"USAGE: C-- [options] [FILE_NAME.INI] [SOURCE_FILE_NAME]",
82
"USAGE: C-- [options] [FILE_NAME.INI] [SOURCE_FILE_NAME]",
81
"",
83
"",
82
"                       C-- COMPILER OPTIONS",
84
"                       C-- COMPILER OPTIONS",
83
"",
85
"",
84
"                           OPTIMIZATION",
86
"                           OPTIMIZATION",
85
"/OC  optimize for code size           /DE  enable temporary expansion variable",
87
"/OC  optimize for code size           /DE  enable temporary expansion variable",
86
"/OS  optimize for speed               /OST enable optimization string",
88
"/OS  optimize for speed               /OST enable optimization string",
87
"/ON  enable optimization number       /AP[=n] align start function",
89
"/ON  enable optimization number       /AP[=n] align start function",
88
"/UST use startup code for variables   /AC[=n] align start cycles",
90
"/UST use startup code for variables   /AC[=n] align start cycles",
89
#ifdef OPTVARCONST
91
#ifdef OPTVARCONST
90
"/ORV replace variable on constant     /OIR skip repeated initializing register",
92
"/ORV replace variable on constant     /OIR skip repeated initializing register",
91
#else
93
#else
92
"                                      /OIR skip repeated initializing register",
94
"                                      /OIR skip repeated initializing register",
93
#endif
95
#endif
94
"",
96
"",
95
"                          CODE GENERATION",
97
"                          CODE GENERATION",
96
"/2   80286 code optimizations         /SA=#### start code address",
98
"/2   80286 code optimizations         /SA=#### start code address",
97
"/3   80386 code optimizations         /AL=## set value insert byte",
99
"/3   80386 code optimizations         /AL=## set value insert byte",
98
"/4   80486 code optimizations         /WFA fast call API functions",
100
"/4   80486 code optimizations         /WFA fast call API functions",
99
"/5   pentium code optimizations       /IV  initial all variables",
101
"/5   pentium code optimizations       /IV  initial all variables",
100
"/A   enable address alignment         /SUV=#### start address variables",
102
"/A   enable address alignment         /SUV=#### start address variables",
101
"/AS[=n] def. alignment in structures  /LRS load in registers over stack",
103
"/AS[=n] def. alignment in structures  /LRS load in registers over stack",
102
"/UL  use 'lea' for adding registers   /JS  join stack calling functions",
104
"/UL  use 'lea' for adding registers   /JS  join stack calling functions",
103
"/BA  byte access to array",//             /ASP addressing local variable via ESP",
105
"/BA  byte access to array",//             /ASP addressing local variable via ESP",
104
"",
106
"",
105
"                           PREPROCESSOR",
107
"                           PREPROCESSOR",
106
"/IP=  include file path         /IA   assembly instructions as identifier",
108
"/IP=  include file path         /IA   assembly instructions as identifier",
107
"/D= defined identifier        /CRI- not check include file on repeated",
109
"/D= defined identifier        /CRI- not check include file on repeated",
108
"/MIF= main input file           /IND= import name from dll",
110
"/MIF= main input file           /IND= import name from dll",
109
"/SF=  other startup file",
111
"/SF=  other startup file",
110
"",
112
"",
111
"                              LINKING",
113
"                              LINKING",
112
"/AT    insert ATEXIT support block    /NS    disable stub",
114
"/AT    insert ATEXIT support block    /NS    disable stub",
113
"/ARGC  insert parse command line      /S=#####  set stack size",
115
"/ARGC  insert parse command line      /S=#####  set stack size",
114
"/P     insert parse command line      /WIB=##### set image base address",
116
"/P     insert parse command line      /WIB=##### set image base address",
115
"/C     insert CTRL ignoring code   /WFU   add Fix Up table, for Windows",
117
"/C     insert CTRL ignoring code   /WFU   add Fix Up table, for Windows",
116
"/R     insert resize memory block     /WMB   create Windows mono block",
118
"/R     insert resize memory block     /WMB   create Windows mono block",
117
"/ENV   insert variable with environ   /WS= set name stub file for win32",
119
"/ENV   insert variable with environ   /WS= set name stub file for win32",
118
"/J0    disable initial jump to main() /WBSS  set post data in bss section",
120
"/J0    disable initial jump to main() /WBSS  set post data in bss section",
119
"/J1    initial jump to main() short   /WO    call API functions on ordinals",
121
"/J1    initial jump to main() short   /WO    call API functions on ordinals",
120
"/J2    initial jump to main() near    /CPA   clear post area",
122
"/J2    initial jump to main() near    /CPA   clear post area",
121
"/STUB=  set name stub file      /WSI   short import table, for Windows",
123
"/STUB=  set name stub file      /WSI   short import table, for Windows",
122
"/DOS4GW file running with DOS4GW      /WAF=#### align Windows file (def 512)",
124
"/DOS4GW file running with DOS4GW      /WAF=#### align Windows file (def 512)",
123
"/STM   startup code in main function",
125
"/STM   startup code in main function",
124
"",
126
"",
125
"                           OUTPUT FILES",
127
"                           OUTPUT FILES",
126
"/TEXE DOS EXE file (model TINY)       /D32  EXE file (32bit code for DOS)",
128
"/TEXE DOS EXE file (model TINY)       /D32  EXE file (32bit code for DOS)",
127
"/EXE  DOS EXE file (model SMALL)      /W32  EXE for Windows32 GUI",
129
"/EXE  DOS EXE file (model SMALL)      /W32  EXE for Windows32 GUI",
128
"/OBJ  OBJ output file                 /W32C EXE for Windows32 console",
130
"/OBJ  OBJ output file                 /W32C EXE for Windows32 console",
129
"/SOBJ slave OBJ output file           /DLL  DLL for Windows32",
131
"/SOBJ slave OBJ output file           /DLL  DLL for Windows32",
130
"/COFF OBJ COFF output file            /DBG  create debug information",
132
"/COFF OBJ COFF output file            /DBG  create debug information",
131
"/SYM  COM file symbiosis              /LST  create assembly listing",
133
"/SYM  COM file symbiosis              /LST  create assembly listing",
132
"/SYS  device (SYS) file               /B32  32bit binary files",
134
"/SYS  device (SYS) file               /B32  32bit binary files",
133
"/MEOS executable file for MeOS        /MAP  create function map file",
135
"/MEOS executable file for MeOS        /MAP  create function map file",
134
"/EXT=  set file extension",
136
"/EXT=  set file extension",
135
"",
137
"",
136
"                           MISCELLANEOUS",
138
"                           MISCELLANEOUS",
137
"/HELP /H /? help, this info           /WORDS list of C-- reserved words",
139
"/HELP /H /? help, this info           /WORDS list of C-- reserved words",
138
"/W         enable warning             /LAI   list of assembler instructions",
140
"/W         enable warning             /LAI   list of assembler instructions",
139
"/WF= direct warnings to a file  /ME    display my name and my address",
141
"/WF= direct warnings to a file  /ME    display my name and my address",
140
"/MER=##    set maximum number errors  /X     disable SPHINX C-- header in output",
142
"/MER=##    set maximum number errors  /X     disable SPHINX C-- header in output",
141
"/NW=##     disable selected warnings  /WE=## selected warning will be error",
143
"/NW=##     disable selected warnings  /WE=## selected warning will be error",
142
//" /SCD        split code and date",
144
//" /SCD        split code and date",
143
NULL};
145
NULL};
144
 
146
 
145
char *dir[]={
147
char *dir[]={
146
	"ME",    "WORDS",   "SYM",   "LAI",
148
	"ME",    "WORDS",   "SYM",   "LAI",
147
 
149
 
148
	"OBJ",   "SOBJ",    "J0",		 "J1",     "J2",    "C",     "R",
150
	"OBJ",   "SOBJ",    "J0",		 "J1",     "J2",    "C",     "R",
149
	"P",     "X",       "EXE",   "S",      "SYS",   "ARGC",  "TEXE",
151
	"P",     "X",       "EXE",   "S",      "SYS",   "ARGC",  "TEXE",
150
	"ROM",   "W32",     "D32",   "W32C",   "AT",    "WFA",   "SA",
152
	"ROM",   "W32",     "D32",   "W32C",   "AT",    "WFA",   "SA",
151
	"STM",   "SUV",     "UST",   "MIF",    "DLL", 	"DOS4GW","ENV",
153
	"STM",   "SUV",     "UST",   "MIF",    "DLL", 	"DOS4GW","ENV",
152
	"CPA",   "WBSS",    "MEOS",  "SF",     "B32",   "WIB",   "DBG",
154
	"CPA",   "WBSS",    "MEOS",  "SF",     "B32",   "WIB",   "DBG",
153
 
155
 
154
	"OS",    "OC",      "A",     "0",      "1",     "2",     "3",
156
	"OS",    "OC",      "A",     "0",      "1",     "2",     "3",
155
	"4",     "5",       "6",     "7",      "8",     "9",     "W",
157
	"4",     "5",       "6",     "7",      "8",     "9",     "W",
156
	"WF",    "DE",
158
	"WF",    "DE",
157
	"ON",    "IP",      "STUB",  "NS",     "AP",    "D",     "OST",
159
	"ON",    "IP",      "STUB",  "NS",     "AP",    "D",     "OST",
158
	"CRI",   "IA",      "SCD",   "AL",     "WFU",   "IV",
160
	"CRI",   "IA",      "SCD",   "AL",     "WFU",   "IV",
159
	"MER",   "WMB",     "HELP",  "H",      "?",     "AC",    "WS",
161
	"MER",   "WMB",     "HELP",  "H",      "?",     "AC",    "WS",
160
	"IND",   "WO",      "NW",    "LST",    "AS",    "UL",    "LRS",
162
	"IND",   "WO",      "NW",    "LST",    "AS",    "UL",    "LRS",
161
	"WSI",   "WAF",     "OIR",   "COFF",   "JS",    "BA",    "ASP",
163
	"WSI",   "WAF",     "OIR",   "COFF",   "JS",    "BA",    "ASP",
162
#ifdef OPTVARCONST
164
#ifdef OPTVARCONST
163
	"ORV",
165
	"ORV",
164
#endif
166
#endif
165
   "MAP",  "WE",   "EXT",   NULL};
167
   "MAP",  "WE",   "EXT",   NULL};
166
 
168
 
167
enum {
169
enum {
168
	c_me,    c_key,     c_sym,   c_lasm,   c_endinfo=c_lasm,
170
	c_me,    c_key,     c_sym,   c_lasm,   c_endinfo=c_lasm,
169
 
171
 
170
	c_obj,   c_sobj,    c_j0,    c_j1,     c_j2,    c_ctrlc, c_r,
172
	c_obj,   c_sobj,    c_j0,    c_j1,     c_j2,    c_ctrlc, c_r,
171
	c_p,     c_x,		    c_exe,   c_s,      c_sys,   c_arg,   c_texe,
173
	c_p,     c_x,		    c_exe,   c_s,      c_sys,   c_arg,   c_texe,
172
	c_rom,   c_w32,     c_d32,   c_w32c,   c_at,    c_wfa,   c_sa,
174
	c_rom,   c_w32,     c_d32,   c_w32c,   c_at,    c_wfa,   c_sa,
173
	c_stm,   c_suv,     c_ust,   c_mif,    c_dll,   c_d4g,   c_env,
175
	c_stm,   c_suv,     c_ust,   c_mif,    c_dll,   c_d4g,   c_env,
174
	c_cpa,   c_wbss,    c_meos,  c_sf,     c_b32,   c_wib,   c_dbg,
176
	c_cpa,   c_wbss,    c_meos,  c_sf,     c_b32,   c_wib,   c_dbg,
175
	c_endstart=c_dbg,
177
	c_endstart=c_dbg,
176
 
178
 
177
	c_os,    c_oc,      c_a,     c_0,      c_1,     c_2,     c_3,
179
	c_os,    c_oc,      c_a,     c_0,      c_1,     c_2,     c_3,
178
	c_4,     c_5,       c_6,     c_7,      c_8,     c_9,     c_w,
180
	c_4,     c_5,       c_6,     c_7,      c_8,     c_9,     c_w,
179
	c_wf,    c_de,
181
	c_wf,    c_de,
180
	c_opnum, c_ip,      c_stub,  c_ns,     c_ap,    c_define,c_ost,
182
	c_opnum, c_ip,      c_stub,  c_ns,     c_ap,    c_define,c_ost,
181
	c_cri,   c_ia,      c_scd,   c_al,     c_wfu,   c_iv,
183
	c_cri,   c_ia,      c_scd,   c_al,     c_wfu,   c_iv,
182
	c_mer,   c_wmb,     c_help,  c_h,      c_hh,    c_ac,    c_ws,
184
	c_mer,   c_wmb,     c_help,  c_h,      c_hh,    c_ac,    c_ws,
183
	c_ind,   c_wo,      c_nw,    c_lst,    c_as,    c_ul,    c_lrs,
185
	c_ind,   c_wo,      c_nw,    c_lst,    c_as,    c_ul,    c_lrs,
184
	c_wsi,   c_waf,     c_oir,   c_coff,   c_js,    c_ba,    c_asp,
186
	c_wsi,   c_waf,     c_oir,   c_coff,   c_js,    c_ba,    c_asp,
185
#ifdef OPTVARCONST
187
#ifdef OPTVARCONST
186
	c_orv,
188
	c_orv,
187
#endif
189
#endif
188
	c_map,   c_we,      c_ext,   c_end};
190
	c_map,   c_we,      c_ext,   c_end};
189
 
191
 
190
#define NUMEXT 6	//÷èñëî ðàçðåøåííûõ ðàñøèðåíèé êîìïèëèðóåìîãî ôàéëà
192
#define NUMEXT 6	//÷èñëî ðàçðåøåííûõ ðàñøèðåíèé êîìïèëèðóåìîãî ôàéëà
191
char extcompile[NUMEXT][4]={"c--","cmm","c","h--","hmm","h"};
193
char extcompile[NUMEXT][4]={"c--","cmm","c","h--","hmm","h"};
192
 
194
 
193
#ifdef _KOS_
195
#ifdef _KOS_
194
char __pgmname[256];
196
char __pgmname[256];
195
char __cmdline[256];
197
char __cmdline[256];
196
#endif
198
#endif
197
 
199
 
198
char *bufstr=NULL;	//áóôåð äëÿ ñòðîê èç ïðîöåäóð
200
char *bufstr=NULL;	//áóôåð äëÿ ñòðîê èç ïðîöåäóð
199
int sbufstr=SIZEBUF;	//íà÷àëüíûé ðàçìåð ýòîãî áóôåðà
201
int sbufstr=SIZEBUF;	//íà÷àëüíûé ðàçìåð ýòîãî áóôåðà
200
 
202
 
201
void compile();
203
void compile();
202
void PrintInfo(char **str);
204
void PrintInfo(char **str);
203
void LoadIni(char *name);
205
void LoadIni(char *name);
204
//void CheckNumStr();
206
//void CheckNumStr();
205
void ListId(int num,unsigned char *list,short *ofs);
207
void ListId(int num,unsigned char *list,short *ofs);
206
void printmemsizes();
208
void printmemsizes();
207
void print8item(char *str);
209
void print8item(char *str);
208
void doposts(void);
210
void doposts(void);
209
void GetMemExeDat();
211
void GetMemExeDat();
210
void AddJmpApi();
212
void AddJmpApi();
211
void startsymbiosys(char *symfile);
213
void startsymbiosys(char *symfile);
212
int writeoutput();
214
int writeoutput();
213
void BadCommandLine(char *str);
215
void BadCommandLine(char *str);
214
void  CheckExtenshions();
216
void  CheckExtenshions();
215
void ImportName(char *name);
217
void ImportName(char *name);
216
void WarnUnusedVar();//ïðåäóïðåæäåíèÿ î íåèñïîëüçîâàííûõ ïðîöåäóðàõ è ïåðåìåííûõ
218
void WarnUnusedVar();//ïðåäóïðåæäåíèÿ î íåèñïîëüçîâàííûõ ïðîöåäóðàõ è ïåðåìåííûõ
217
void MakeExeHeader(EXE_DOS_HEADER *exeheader);
219
void MakeExeHeader(EXE_DOS_HEADER *exeheader);
218
void CheckPageCode(unsigned int ofs);
220
void CheckPageCode(unsigned int ofs);
219
int MakePE();
221
int MakePE();
220
int MakeObj();
222
int MakeObj();
221
void CheckUndefClassProc();
223
void CheckUndefClassProc();
222
/*
224
/*
223
void PrintTegList(structteg *tteg)
225
void PrintTegList(structteg *tteg)
224
{
226
{
225
	if(tteg){
227
	if(tteg){
226
		PrintTegList(tteg->left);
228
		PrintTegList(tteg->left);
227
		PrintTegList(tteg->right);
229
		PrintTegList(tteg->right);
228
		puts(tteg->name);
230
		puts(tteg->name);
229
	}
231
	}
230
} */
232
} */
231
 
233
 
232
//unsigned long maxusedmem=0;
234
//unsigned long maxusedmem=0;
233
 
235
 
234
void ErrOpenFile(char *str)
236
void ErrOpenFile(char *str)
235
{
237
{
236
	printf("Unable to open file %s.\n",str);
238
	printf("Unable to open file %s.\n",str);
237
}
239
}
238
 
240
 
239
int main(int argc,char *argv[])
241
int main(int argc,char *argv[])
240
{
242
{
241
int count;
243
int count;
242
unsigned char pari=FALSE;
244
unsigned char pari=FALSE;
243
	char *buffer;
245
	char *buffer;
244
	
246
	
245
	printf("\nSPHINX C-- Compiler   Version %d.%d%s   %s\r\n",ver1,ver2,betta,__DATE__);
247
	printf("\nSPHINX C-- Compiler   Version %d.%d%s   %s\r\n",ver1,ver2,betta,__DATE__);
246
		
248
		
247
//	scrsize=24;
249
//	scrsize=24;
248
	if(argc>1){
250
	if(argc>1){
249
		_Argv=argv;// This make portable code
251
		_Argv=argv;// This make portable code
250
		bufstr=(char *)MALLOC(SIZEBUF);
252
		bufstr=(char *)MALLOC(SIZEBUF);
251
		output=(unsigned char *)MALLOC((size_t)MAXDATA);
253
		output=(unsigned char *)MALLOC((size_t)MAXDATA);
252
		outputdata=output;
254
		outputdata=output;
253
		postbuf=(postinfo *)MALLOC(MAXPOSTS*sizeof(postinfo));
255
		postbuf=(postinfo *)MALLOC(MAXPOSTS*sizeof(postinfo));
254
		strcpy((char *)string,argv[0]);
256
		strcpy((char *)string,argv[0]);
255
		rawext=strrchr((char *)string,DIV_FOLD);
257
		rawext=strrchr((char *)string,DIV_FOLD);
256
		
258
		
257
		if(rawext!=NULL){
259
		if(rawext!=NULL){
258
			rawext[0]=0;
260
			rawext[0]=0;
259
			IncludePath((char *)string);
261
			IncludePath((char *)string);
260
		} 
262
		} 
261
		rawfilename=getenv("C--");
263
		rawfilename=getenv("C--");
262
		if(rawfilename!=NULL)IncludePath(rawfilename);
264
		if(rawfilename!=NULL)IncludePath(rawfilename);
263
		
265
		
264
		rawfilename=rawext=NULL;
266
		rawfilename=rawext=NULL;
265
		LoadIni("c--.ini");	 
267
		LoadIni("c--.ini");	 
266
		
268
		
267
		for(count=1;count
269
		for(count=1;count
268
			//if(argv[count][0]=='/'||argv[count][0]=='-'){
270
			//if(argv[count][0]=='/'||argv[count][0]=='-'){
269
			if(argv[count][0]=='-'){
271
			if(argv[count][0]=='-'){
270
				if(SelectComand(argv[count]+1,&count)==c_end) BadCommandLine(argv[count]);
272
				if(SelectComand(argv[count]+1,&count)==c_end) BadCommandLine(argv[count]);
271
			}
273
			}
272
			else{
274
			else{
273
				if(pari==FALSE){
275
				if(pari==FALSE){
274
					rawfilename=argv[count];
276
					rawfilename=argv[count];
275
					pari=TRUE;
277
					pari=TRUE;
276
					if((rawext=strrchr(rawfilename,'.'))!=NULL){
278
					if((rawext=strrchr(rawfilename,'.'))!=NULL){
277
						if(stricmp(rawext,".ini")==0){	//óêàçàí ini ôàéë
279
						if(stricmp(rawext,".ini")==0){	//óêàçàí ini ôàéë
278
							rawfilename=NULL;
280
							rawfilename=NULL;
279
							rawext=NULL;
281
							rawext=NULL;
280
							LoadIni(argv[count]);
282
							LoadIni(argv[count]);
281
							if(rawfilename==NULL)pari=FALSE;
283
							if(rawfilename==NULL)pari=FALSE;
282
						}
284
						}
283
						else{
285
						else{
284
							*rawext++=0;
286
							*rawext++=0;
285
							CheckExtenshions();
287
							CheckExtenshions();
286
						}
288
						}
287
					}
289
					}
288
				}
290
				}
289
			}
291
			}
290
		}
292
		}
291
	}
293
	}
292
	if(rawfilename==NULL){
294
	if(rawfilename==NULL){
293
		PrintInfo(usage);
295
		PrintInfo(usage);
294
		exit( e_noinputspecified );
296
		exit( e_noinputspecified );
295
	}
297
	}
296
	time(&systime); //òåêóùåå âðåìÿ
298
	time(&systime); //òåêóùåå âðåìÿ
297
	memcpy(&timeptr,localtime(&systime),sizeof(tm));
299
	memcpy(&timeptr,localtime(&systime),sizeof(tm));
298
	InitDefineConst();
300
	InitDefineConst();
299
	compile();
301
	compile();
300
	if(error==0)exit(e_ok);
302
	if(error==0)exit(e_ok);
301
	exit(e_someerrors);
303
	exit(e_someerrors);
302
	return 0;
304
	return 0;
303
}
305
}
304
 
306
 
305
void CheckExtenshions()
307
void CheckExtenshions()
306
{
308
{
307
int i;
309
int i;
308
	for(i=0;i
310
	for(i=0;i
309
		if(stricmp(rawext,extcompile[i])==0)break;
311
		if(stricmp(rawext,extcompile[i])==0)break;
310
	}
312
	}
311
	if(i==NUMEXT){
313
	if(i==NUMEXT){
312
	 	printf("Bad input file extension '%s'.",rawext);
314
	 	printf("Bad input file extension '%s'.",rawext);
313
	  exit(e_badinputfilename);
315
	  exit(e_badinputfilename);
314
	}
316
	}
315
}
317
}
316
 
318
 
317
void compile()
319
void compile()
318
{
320
{
319
long segments_required;
321
long segments_required;
320
union{
322
union{
321
	long longhold;
323
	long longhold;
322
	void *nextstr;
324
	void *nextstr;
323
};
325
};
324
//ñîçäàòü èìÿ ôàéëà ñ ïðåäóïðåæäåíèÿìè è åñëè îí åñòü óäàëèòü
326
//ñîçäàòü èìÿ ôàéëà ñ ïðåäóïðåæäåíèÿìè è åñëè îí åñòü óäàëèòü
325
	errfile.name=(char *)MALLOC(strlen(rawfilename)+5);
327
	errfile.name=(char *)MALLOC(strlen(rawfilename)+5);
326
	sprintf(errfile.name,"%s.err",rawfilename);
328
	sprintf(errfile.name,"%s.err",rawfilename);
327
	if(stat(errfile.name,(struct stat *)string2)==0)remove(errfile.name);
329
	if(stat(errfile.name,(struct stat *)string2)==0)remove(errfile.name);
328
//åñëè åñòü èìÿ ôàéëà äëÿ ïðåäóïðåæäåíèé ïðîâåðèòü åãî ñóùåñòâîâàíèå è óäàëèòü.
330
//åñëè åñòü èìÿ ôàéëà äëÿ ïðåäóïðåæäåíèé ïðîâåðèòü åãî ñóùåñòâîâàíèå è óäàëèòü.
329
	if(wartype.name!=NULL){
331
	if(wartype.name!=NULL){
330
		if(stat(wartype.name,(struct stat *)string2)==0)remove(wartype.name);
332
		if(stat(wartype.name,(struct stat *)string2)==0)remove(wartype.name);
331
	}
333
	}
332
	puts("Compiling Commenced . . .");
334
	puts("Compiling Commenced . . .");
333
	if(rawext!=NULL)sprintf((char *)string,"%s.%s",rawfilename,rawext);
335
	if(rawext!=NULL)sprintf((char *)string,"%s.%s",rawfilename,rawext);
334
	else{
336
	else{
335
		for(unsigned int i=0;i
337
		for(unsigned int i=0;i
336
			sprintf((char *)string,"%s.%s",rawfilename,extcompile[i]);
338
			sprintf((char *)string,"%s.%s",rawfilename,extcompile[i]);
337
			if(stat((char *)string,(struct stat *)string2)==0)break;
339
			if(stat((char *)string,(struct stat *)string2)==0)break;
338
		}
340
		}
339
	}
341
	}
340
	linenumber=0;
342
	linenumber=0;
341
	initregstat();
343
	initregstat();
342
#ifdef OPTVARCONST
344
#ifdef OPTVARCONST
343
	CreateMainLVIC();
345
	CreateMainLVIC();
344
#endif
346
#endif
345
#ifdef __NEWLEX__
347
#ifdef __NEWLEX__
346
	inittokn();
348
	inittokn();
347
#endif
349
#endif
348
	compilefile((char *)string,2); //ñîáñòâåííî ðàçáîðêà è êîìïèëÿöèÿ
350
	compilefile((char *)string,2); //ñîáñòâåííî ðàçáîðêà è êîìïèëÿöèÿ
349
	puts("Link . . .");
351
	puts("Link . . .");
350
	if(comfile==file_w32&&wbss==2){
352
	if(comfile==file_w32&&wbss==2){
351
		wbss=FALSE;
353
		wbss=FALSE;
352
		if(wconsole==FALSE)wbss=TRUE;
354
		if(wconsole==FALSE)wbss=TRUE;
353
	}
355
	}
354
	if(notdoneprestuff==TRUE)doprestuff();	//startup code
356
	if(notdoneprestuff==TRUE)doprestuff();	//startup code
355
	if(endifcount>=0)preerror("?endif expected before end of file");
357
	if(endifcount>=0)preerror("?endif expected before end of file");
356
	AddObj();
358
	AddObj();
357
	docalls();	//äîáàâèòü âíåøíèå ïðîöåäóðû
359
	docalls();	//äîáàâèòü âíåøíèå ïðîöåäóðû
358
	addinitvar();
360
	addinitvar();
359
	CheckUndefClassProc();
361
	CheckUndefClassProc();
360
	if(undefoffstart!=NULL){	//âûäàòü ñïèñîê íåèçâåñòíûõ ññûëîê
362
	if(undefoffstart!=NULL){	//âûäàòü ñïèñîê íåèçâåñòíûõ ññûëîê
361
		UNDEFOFF *curptr=undefoffstart;
363
		UNDEFOFF *curptr=undefoffstart;
362
		for(;;){
364
		for(;;){
363
			char holdstr[80];
365
			char holdstr[80];
364
			UNDEFOFF *ocurptr;
366
			UNDEFOFF *ocurptr;
365
			linenumber=curptr->pos->line;
367
			linenumber=curptr->pos->line;
366
			sprintf(holdstr,"\'%s\' offset undefined",curptr->name);
368
			sprintf(holdstr,"\'%s\' offset undefined",curptr->name);
367
			currentfileinfo=curptr->pos->file;
369
			currentfileinfo=curptr->pos->file;
368
			preerror(holdstr);
370
			preerror(holdstr);
369
			free(curptr->pos);
371
			free(curptr->pos);
370
			if(curptr->next==NULL)break;
372
			if(curptr->next==NULL)break;
371
			ocurptr=curptr->next;
373
			ocurptr=curptr->next;
372
			free(curptr);
374
			free(curptr);
373
			curptr=ocurptr;
375
			curptr=ocurptr;
374
		}
376
		}
375
		free(curptr);
377
		free(curptr);
376
	}
378
	}
377
	while(liststring!=NULL){
379
	while(liststring!=NULL){
378
		STRING_LIST *ins;
380
		STRING_LIST *ins;
379
		ins=(STRING_LIST *)liststring;
381
		ins=(STRING_LIST *)liststring;
380
		nextstr=ins->next;
382
		nextstr=ins->next;
381
		free(liststring);
383
		free(liststring);
382
		liststring=nextstr;
384
		liststring=nextstr;
383
	}
385
	}
384
	free(bufstr);
386
	free(bufstr);
385
	if(warning==TRUE&&wact[7].usewarn)WarnUnusedVar();//ïðåäóïðåæäåíèÿ î íåèñïîëüçîâàííûõ ïðîöåäóðàõ è ïåðåìåííûõ
387
	if(warning==TRUE&&wact[7].usewarn)WarnUnusedVar();//ïðåäóïðåæäåíèÿ î íåèñïîëüçîâàííûõ ïðîöåäóðàõ è ïåðåìåííûõ
386
	if(numstrtbl)CreatStrTabRes();	//çàâåðøèòü ñîçäàíèå ðåñóðñîâ
388
	if(numstrtbl)CreatStrTabRes();	//çàâåðøèòü ñîçäàíèå ðåñóðñîâ
387
	if(fobj==FALSE){
389
	if(fobj==FALSE){
388
		if(comfile==file_w32&&error==0){
390
		if(comfile==file_w32&&error==0){
389
			AddJmpApi();	//êîñâåííûå âûçîâû API
391
			AddJmpApi();	//êîñâåííûå âûçîâû API
390
			CreatWinStub();
392
			CreatWinStub();
391
		}
393
		}
392
		longhold=outptr;
394
		longhold=outptr;
393
		if(comfile==file_rom){
395
		if(comfile==file_rom){
394
			ooutptr=outptr;
396
			ooutptr=outptr;
395
			if(modelmem==SMALL){
397
			if(modelmem==SMALL){
396
				*(short *)&output[stackstartaddress]=(short)(((outptrdata+postsize+stacksize)/4+1)*4);
398
				*(short *)&output[stackstartaddress]=(short)(((outptrdata+postsize+stacksize)/4+1)*4);
397
				*(short *)&output[dataromstart]=(short)(outptr+4);
399
				*(short *)&output[dataromstart]=(short)(outptr+4);
398
				*(short *)&output[dataromsize]=(short)(outptrdata/2);
400
				*(short *)&output[dataromsize]=(short)(outptrdata/2);
399
//				printf("outptr=%d outptrdate=%d outptrsize=%d\n",outptr,outptrdata,outptrsize);
401
//				printf("outptr=%d outptrdate=%d outptrsize=%d\n",outptr,outptrdata,outptrsize);
400
				for(unsigned int i=0;i
402
				for(unsigned int i=0;i
401
			}
403
			}
402
			if(romsize==0){
404
			if(romsize==0){
403
				unsigned int i=outptr/1024;
405
				unsigned int i=outptr/1024;
404
				if((outptr%1024)!=0)i++;
406
				if((outptr%1024)!=0)i++;
405
				if(i>32)i=64;
407
				if(i>32)i=64;
406
				else if(i>16)i=32;
408
				else if(i>16)i=32;
407
				else if(i>8)i=16;
409
				else if(i>8)i=16;
408
				else if(i>4)i=8;
410
				else if(i>4)i=8;
409
				else if(i>2)i=4;
411
				else if(i>2)i=4;
410
		 		romsize=i*1024;
412
		 		romsize=i*1024;
411
				output[2]=(unsigned char)(romsize/512);
413
				output[2]=(unsigned char)(romsize/512);
412
			}
414
			}
413
			if(outptr>=romsize)preerror("The size of a code is more than the size of the ROM");
415
			if(outptr>=romsize)preerror("The size of a code is more than the size of the ROM");
414
			for(;outptr
416
			for(;outptr
415
			unsigned char summa=0;
417
			unsigned char summa=0;
416
			for(unsigned int i=0;i
418
			for(unsigned int i=0;i
417
			output[romsize-1]-=summa;
419
			output[romsize-1]-=summa;
418
			outptr=ooutptr;
420
			outptr=ooutptr;
419
		}
421
		}
420
		else if(modelmem==SMALL&&comfile==file_exe){ // if an EXE file
422
		else if(modelmem==SMALL&&comfile==file_exe){ // if an EXE file
421
			longhold+=AlignCD(CS,16);
423
			longhold+=AlignCD(CS,16);
422
//			if((outptr%16)!=0)outptr+=16-outptr%16;// paragraph align the end of the code seg
424
//			if((outptr%16)!=0)outptr+=16-outptr%16;// paragraph align the end of the code seg
423
			if(((long)outptrdata+(long)postsize+(long)stacksize)>65535L)
425
			if(((long)outptrdata+(long)postsize+(long)stacksize)>65535L)
424
					preerror("Data and stack total exceeds 64k");
426
					preerror("Data and stack total exceeds 64k");
425
		}
427
		}
426
		else if(comfile==file_sys){
428
		else if(comfile==file_sys){
427
			for(int i=0;i
429
			for(int i=0;i
428
				searchvar((listcom+i)->name);
430
				searchvar((listcom+i)->name);
429
				*(short *)&output[syscom+i*2]=(unsigned short)itok.number;
431
				*(short *)&output[syscom+i*2]=(unsigned short)itok.number;
430
			}
432
			}
431
			free(listcom);
433
			free(listcom);
432
		}
434
		}
433
		else longhold+=(long)postsize+(long)(stacksize);
435
		else longhold+=(long)postsize+(long)(stacksize);
434
		if(am32==0&&longhold>65535L&&!(modelmem==TINY&&(!resizemem)))preerror("Code, data and stack total exceeds 64k");
436
		if(am32==0&&longhold>65535L&&!(modelmem==TINY&&(!resizemem)))preerror("Code, data and stack total exceeds 64k");
435
		if(posts>0)doposts();  //Óñòàíîâèòü àäðåñà âûçîâîâ ïðîöåäóð è ïåðåõîäîâ
437
		if(posts>0)doposts();  //Óñòàíîâèòü àäðåñà âûçîâîâ ïðîöåäóð è ïåðåõîäîâ
436
		if(resizemem&&comfile==file_com){
438
		if(resizemem&&comfile==file_com){
437
			segments_required=(outptr+postsize+stacksize+15)/16;
439
			segments_required=(outptr+postsize+stacksize+15)/16;
438
			*(short *)&output[resizesizeaddress]=(short)segments_required;
440
			*(short *)&output[resizesizeaddress]=(short)segments_required;
439
			*(short *)&output[stackstartaddress]=(short)(segments_required*16);
441
			*(short *)&output[stackstartaddress]=(short)(segments_required*16);
440
		}
442
		}
441
	}
443
	}
442
	deinitregstat();
444
	deinitregstat();
443
#ifdef OPTVARCONST
445
#ifdef OPTVARCONST
444
	KillMainLVIC();
446
	KillMainLVIC();
445
#endif
447
#endif
446
//	puts("List Teg name:");
448
//	puts("List Teg name:");
447
//	PrintTegList(tegtree);
449
//	PrintTegList(tegtree);
448
	printf("COMPILING FINISHED.  Errors: %d\n",error);
450
	printf("COMPILING FINISHED.  Errors: %d\n",error);
449
	if(error==0){
451
	if(error==0){
450
		if(cpu>=1){
452
		if(cpu>=1){
451
			char m1[12];
453
			char m1[12];
452
			switch(cpu){
454
			switch(cpu){
453
				case 5:
455
				case 5:
454
					strcpy(m1,"Pentium");
456
					strcpy(m1,"Pentium");
455
					break;
457
					break;
456
				case 6:
458
				case 6:
457
					strcpy(m1,"MMX");
459
					strcpy(m1,"MMX");
458
					break;
460
					break;
459
				case 7:
461
				case 7:
460
					strcpy(m1,"Pentium II");
462
					strcpy(m1,"Pentium II");
461
					break;
463
					break;
462
				case 8:
464
				case 8:
463
					strcpy(m1,"Pentium III");
465
					strcpy(m1,"Pentium III");
464
					break;
466
					break;
465
				case 9:
467
				case 9:
466
					strcpy(m1,"Pentium IV");
468
					strcpy(m1,"Pentium IV");
467
					break;
469
					break;
468
				default: sprintf(m1,"80%d86",cpu);
470
				default: sprintf(m1,"80%d86",cpu);
469
			}
471
			}
470
			printf("CPU required: %s or greater.\n",m1);
472
			printf("CPU required: %s or greater.\n",m1);
471
		}
473
		}
472
		runfilesize=outptr-startptr;
474
		runfilesize=outptr-startptr;
473
		if(comfile==file_rom)runfilesize=romsize;
475
		if(comfile==file_rom)runfilesize=romsize;
474
		else if(modelmem==SMALL&&comfile==file_exe){
476
		else if(modelmem==SMALL&&comfile==file_exe){
475
			runfilesize+=outptrdata-startptrdata+0x20;
477
			runfilesize+=outptrdata-startptrdata+0x20;
476
			postsize+=postsize%2;
478
			postsize+=postsize%2;
477
			stacksize=(stacksize+15)/16*16;
479
			stacksize=(stacksize+15)/16*16;
478
		}
480
		}
479
		else if((comfile==file_exe||comfile==file_d32)&&modelmem==TINY)
481
		else if((comfile==file_exe||comfile==file_d32)&&modelmem==TINY)
480
				runfilesize+=0x20;
482
				runfilesize+=0x20;
481
		printmemsizes();
483
		printmemsizes();
482
		endinptr=outptr;
484
		endinptr=outptr;
483
		if(writeoutput()==0)printf("Run File Saved (%ld bytes).\n",runfilesize);
485
		if(writeoutput()==0)printf("Run File Saved (%ld bytes).\n",runfilesize);
484
		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);
486
		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);
485
//		else if(FILEALIGN&&fobj==FALSE)printf("For alignment file, added %u zero bytes.\n",filingzerope);
487
//		else if(FILEALIGN&&fobj==FALSE)printf("For alignment file, added %u zero bytes.\n",filingzerope);
486
	}
488
	}
487
		if(pdbg)DoTDS();
489
		if(pdbg)DoTDS();
488
}
490
}
489
 
491
 
490
void printmemsizes()
492
void printmemsizes()
491
{
493
{
492
long stacklong;
494
long stacklong;
493
unsigned int stackword;
495
unsigned int stackword;
494
unsigned int postword,codeword;
496
unsigned int postword,codeword;
495
	postword=postsize;
497
	postword=postsize;
496
	codeword=outptr-startptr;
498
	codeword=outptr-startptr;
497
	stackword=stacksize;
499
	stackword=stacksize;
498
	if(comfile==file_com||(comfile==file_exe&&modelmem==TINY)){
500
	if(comfile==file_com||(comfile==file_exe&&modelmem==TINY)){
499
		if(resizemem==0){
501
		if(resizemem==0){
500
			stacklong=0xFFFE - outptr - postsize;
502
			stacklong=0xFFFE - outptr - postsize;
501
			stackword=stacklong;
503
			stackword=stacklong;
502
		}
504
		}
503
		codeword=codeword-datasize-alignersize;
505
		codeword=codeword-datasize-alignersize;
504
	}
506
	}
505
	else if(comfile==file_sys)stackword=sysstack;
507
	else if(comfile==file_sys)stackword=sysstack;
506
	else if(comfile==file_exe||comfile==file_rom)datasize=outptrdata;
508
	else if(comfile==file_exe||comfile==file_rom)datasize=outptrdata;
507
	else if(comfile==file_d32)codeword-=datasize;
509
	else if(comfile==file_d32)codeword-=datasize;
508
	printf("Code: %u bytes, Data: %u bytes, Post: %u bytes, Stack: %u bytes\n"
510
	printf("Code: %u bytes, Data: %u bytes, Post: %u bytes, Stack: %u bytes\n"
509
			,codeword,datasize,postword,stackword);
511
			,codeword,datasize,postword,stackword);
510
	for(int i=0;i
512
	for(int i=0;i
511
		switch((postbuf+i)->type){
513
		switch((postbuf+i)->type){
512
			case CODE_SIZE:
514
			case CODE_SIZE:
513
				*(short *)&output[(postbuf+i)->loc]+=codeword;
515
				*(short *)&output[(postbuf+i)->loc]+=codeword;
514
				break;
516
				break;
515
			case CODE_SIZE32:
517
			case CODE_SIZE32:
516
				*(long *)&output[(postbuf+i)->loc]+=codeword;
518
				*(long *)&output[(postbuf+i)->loc]+=codeword;
517
				break;
519
				break;
518
			case DATA_SIZE:
520
			case DATA_SIZE:
519
				*(short *)&output[(postbuf+i)->loc]+=datasize;
521
				*(short *)&output[(postbuf+i)->loc]+=datasize;
520
				break;
522
				break;
521
			case DATA_SIZE32:
523
			case DATA_SIZE32:
522
				*(long *)&output[(postbuf+i)->loc]+=datasize;
524
				*(long *)&output[(postbuf+i)->loc]+=datasize;
523
				break;
525
				break;
524
			case POST_SIZE:
526
			case POST_SIZE:
525
				*(short *)&output[(postbuf+i)->loc]+=postword;
527
				*(short *)&output[(postbuf+i)->loc]+=postword;
526
				break;
528
				break;
527
			case POST_SIZE32:
529
			case POST_SIZE32:
528
				*(long *)&output[(postbuf+i)->loc]+=postword;
530
				*(long *)&output[(postbuf+i)->loc]+=postword;
529
				break;
531
				break;
530
			case STACK_SIZE:
532
			case STACK_SIZE:
531
				*(short *)&output[(postbuf+i)->loc]+=stackword;
533
				*(short *)&output[(postbuf+i)->loc]+=stackword;
532
				break;
534
				break;
533
			case STACK_SIZE32:
535
			case STACK_SIZE32:
534
				*(long *)&output[(postbuf+i)->loc]+=stackword;
536
				*(long *)&output[(postbuf+i)->loc]+=stackword;
535
				break;
537
				break;
536
		}
538
		}
537
	}
539
	}
538
}
540
}
539
 
541
 
540
void PrintInfo(char **str)
542
void PrintInfo(char **str)
541
{
543
{
542
	numstr=1;
544
	numstr=1;
543
	for(int i=0;str[i]!=NULL;i++){
545
	for(int i=0;str[i]!=NULL;i++){
544
		puts(str[i]);
546
		puts(str[i]);
545
//		CheckNumStr();
547
//		CheckNumStr();
546
	}
548
	}
547
}
549
}
548
 
550
 
549
/*void CheckNumStr()
551
/*void CheckNumStr()
550
{
552
{
551
#ifndef _UNIX_
553
#ifndef _UNIX_
552
	if(((numstr+1)%(scrsize-1))==0&&outfile!=0){
554
	if(((numstr+1)%(scrsize-1))==0&&outfile!=0){
553
		puts("Press any key...");
555
		puts("Press any key...");
554
		getch();
556
		getch();
555
	}
557
	}
556
	numstr++;
558
	numstr++;
557
#endif
559
#endif
558
} */
560
} */
559
 
561
 
560
void strbtrim(char *st)
562
void strbtrim(char *st)
561
{
563
{
562
int i;
564
int i;
563
char *p,*q;
565
char *p,*q;
564
	p=q=st;
566
	p=q=st;
565
	while(isspace(*p))p++;	//ïîêà íåçíà÷àùèå ñèìâîëû
567
	while(isspace(*p))p++;	//ïîêà íåçíà÷àùèå ñèìâîëû
566
	while(*p)*q++=*p++;     //ïåðåìåñòèòü ñòðîêó
568
	while(*p)*q++=*p++;     //ïåðåìåñòèòü ñòðîêó
567
	*q='\0';
569
	*q='\0';
568
	for(i=strlen(st)-1;isspace(st[i])&&i>=0;i--);
570
	for(i=strlen(st)-1;isspace(st[i])&&i>=0;i--);
569
	st[i+1]='\0';
571
	st[i+1]='\0';
570
}
572
}
571
 
573
 
572
unsigned long getnumber(unsigned char *buf)
574
unsigned long getnumber(unsigned char *buf)
573
{
575
{
574
int temp2;
576
int temp2;
575
unsigned long retnum;
577
unsigned long retnum;
576
unsigned char *oinput;
578
unsigned char *oinput;
577
unsigned int oinptr,oendinptr;
579
unsigned int oinptr,oendinptr;
578
	if(!isdigit(buf[0]))return 0;
580
	if(!isdigit(buf[0]))return 0;
579
	oinptr=inptr;
581
	oinptr=inptr;
580
	oinput=input;
582
	oinput=input;
581
	oendinptr=endinptr;
583
	oendinptr=endinptr;
582
	input=buf;
584
	input=buf;
583
	inptr=0;
585
	inptr=0;
584
	endinptr=256;
586
	endinptr=256;
585
	retnum=scannumber(&temp2);
587
	retnum=scannumber(&temp2);
586
	inptr=oinptr;
588
	inptr=oinptr;
587
	input=oinput;
589
	input=oinput;
588
	endinptr=oendinptr;
590
	endinptr=oendinptr;
589
	return retnum;
591
	return retnum;
590
}
592
}
591
 
593
 
592
int SelectComand(char *pptr,int *count)
594
int SelectComand(char *pptr,int *count)
593
{
595
{
594
int i;
596
int i;
595
unsigned char neg=FALSE;
597
unsigned char neg=FALSE;
596
char *ptr;
598
char *ptr;
597
int len;
599
int len;
598
	if((ptr=strchr(pptr,';'))!=NULL)*ptr=0;// èùåì êîììåíòàðèé îòñåêàåì âñå ïîñëå íåãî
600
	if((ptr=strchr(pptr,';'))!=NULL)*ptr=0;// èùåì êîììåíòàðèé îòñåêàåì âñå ïîñëå íåãî
599
        if((ptr=strchr(pptr,'='))!=NULL){ // èùåì çíàê ðàâåíñòâà
601
        if((ptr=strchr(pptr,'='))!=NULL){ // èùåì çíàê ðàâåíñòâà
600
		*ptr=0; // äåëèì
602
		*ptr=0; // äåëèì
601
		ptr++;
603
		ptr++;
602
	  strbtrim(ptr);	//óáðàòü ëèøíèå ïðîáåëû
604
	  strbtrim(ptr);	//óáðàòü ëèøíèå ïðîáåëû
603
	}
605
	}
604
  strbtrim(pptr);	//óáðàòü ëèøíèå ïðîáåëû
606
  strbtrim(pptr);	//óáðàòü ëèøíèå ïðîáåëû
605
	if(*pptr==0)return c_end+1;	//ïóñòàÿ ñòðîêà
607
	if(*pptr==0)return c_end+1;	//ïóñòàÿ ñòðîêà
606
	if((i=strlen(pptr))>1&&pptr[i-1]=='-'){
608
	if((i=strlen(pptr))>1&&pptr[i-1]=='-'){
607
		neg=TRUE;
609
		neg=TRUE;
608
		pptr[i-1]=0;
610
		pptr[i-1]=0;
609
	}
611
	}
610
	strupr(pptr);
612
	strupr(pptr);
611
	for(i=0;dir[i]!=NULL;i++){
613
	for(i=0;dir[i]!=NULL;i++){
612
		if(strcmp(dir[i],pptr)==0){
614
		if(strcmp(dir[i],pptr)==0){
613
			if((i<=c_endinfo)&&count==0){
615
			if((i<=c_endinfo)&&count==0){
614
				char buf[80];
616
				char buf[80];
615
				sprintf(buf,"Option '%s' is used only in command line",dir[i]);
617
				sprintf(buf,"Option '%s' is used only in command line",dir[i]);
616
				preerror(buf);
618
				preerror(buf);
617
				return i;
619
				return i;
618
			}
620
			}
619
			if(i<=c_endstart&¬doneprestuff!=TRUE){
621
			if(i<=c_endstart&¬doneprestuff!=TRUE){
620
errlate:
622
errlate:
621
				char buf[80];
623
				char buf[80];
622
				sprintf(buf,"Too late used '#pragma option %s'",dir[i]);
624
				sprintf(buf,"Too late used '#pragma option %s'",dir[i]);
623
				preerror(buf);
625
				preerror(buf);
624
				return i;
626
				return i;
625
			}
627
			}
626
			switch(i){
628
			switch(i){
627
				case c_j0: jumptomain=(unsigned char)(neg!=FALSE?CALL_NEAR:CALL_NONE); header=(unsigned char)0^neg; break;
629
				case c_j0: jumptomain=(unsigned char)(neg!=FALSE?CALL_NEAR:CALL_NONE); header=(unsigned char)0^neg; break;
628
				case c_j1: jumptomain=(unsigned char)CALL_SHORT; header=(unsigned char)1; break;
630
				case c_j1: jumptomain=(unsigned char)CALL_SHORT; header=(unsigned char)1; break;
629
				case c_j2: jumptomain=(unsigned char)(neg==FALSE?CALL_NEAR:CALL_NONE); header=(unsigned char)1^neg; break;
631
				case c_j2: jumptomain=(unsigned char)(neg==FALSE?CALL_NEAR:CALL_NONE); header=(unsigned char)1^neg; break;
630
				case c_ctrlc: killctrlc=(unsigned char)1^neg; break;
632
				case c_ctrlc: killctrlc=(unsigned char)1^neg; break;
631
				case c_os: optimizespeed=(unsigned char)1^neg; break;
633
				case c_os: optimizespeed=(unsigned char)1^neg; break;
632
				case c_oc: optimizespeed=(unsigned char)0^neg; break;
634
				case c_oc: optimizespeed=(unsigned char)0^neg; break;
633
				case c_r: resizemem=(unsigned char)1^neg; break;
635
				case c_r: resizemem=(unsigned char)1^neg; break;
634
				case c_p: parsecommandline=(unsigned char)1^neg; break;
636
				case c_p: parsecommandline=(unsigned char)1^neg; break;
635
				case c_a: alignword=(unsigned char)1^neg; break;
637
				case c_a: alignword=(unsigned char)1^neg; break;
636
				case c_sym:
638
				case c_sym:
637
					startptr=0x100;
639
					startptr=0x100;
638
					comsymbios=TRUE;
640
					comsymbios=TRUE;
639
					*count=*count+1;
641
					*count=*count+1;
640
          startsymbiosys(_Argv[*count]);
642
          startsymbiosys(_Argv[*count]);
641
					break;
643
					break;
642
				case c_0: chip=0; break;
644
				case c_0: chip=0; break;
643
				case c_1: chip=1; break;
645
				case c_1: chip=1; break;
644
				case c_2: chip=2; break;
646
				case c_2: chip=2; break;
645
				case c_3: chip=3; break;
647
				case c_3: chip=3; break;
646
				case c_4: chip=4; break;
648
				case c_4: chip=4; break;
647
				case c_5: chip=5; break;
649
				case c_5: chip=5; break;
648
				case c_6: chip=6; break;	//MMX
650
				case c_6: chip=6; break;	//MMX
649
				case c_7: chip=7; break;  //Pro
651
				case c_7: chip=7; break;  //Pro
650
				case c_8: chip=8; break;  //PII
652
				case c_8: chip=8; break;  //PII
651
				case c_9: chip=9; break;  //PIII
653
				case c_9: chip=9; break;  //PIII
652
				case c_x: header=(unsigned char)0^neg; break;
654
				case c_x: header=(unsigned char)0^neg; break;
653
				case c_exe:
655
				case c_exe:
654
					comfile=file_exe;
656
					comfile=file_exe;
655
					modelmem=SMALL;
657
					modelmem=SMALL;
656
					splitdata=TRUE;
658
					splitdata=TRUE;
657
					GetMemExeDat();
659
					GetMemExeDat();
658
					if(extflag) strcpy(outext,"exe");
660
					if(extflag) strcpy(outext,"exe");
659
					startptr=0; 			// start address
661
					startptr=0; 			// start address
660
					startptrdata=0; 	// data start address
662
					startptrdata=0; 	// data start address
661
					dos1=2;
663
					dos1=2;
662
					dos2=0;
664
					dos2=0;
663
					break;
665
					break;
664
				case c_sys:
666
				case c_sys:
665
					comfile=file_sys;
667
					comfile=file_sys;
666
					if(extflag) strcpy(outext,"sys");
668
					if(extflag) strcpy(outext,"sys");
667
					startptr=0; 		// start address
669
					startptr=0; 		// start address
668
					startptrdata=0; 	// data start address
670
					startptrdata=0; 	// data start address
669
					jumptomain=CALL_NONE;
671
					jumptomain=CALL_NONE;
670
					header=0;
672
					header=0;
671
					break;
673
					break;
672
				case c_sobj:
674
				case c_sobj:
673
					sobj=TRUE;
675
					sobj=TRUE;
674
					FixUp=TRUE;
676
					FixUp=TRUE;
675
					jumptomain=CALL_NONE;
677
					jumptomain=CALL_NONE;
676
				case c_obj:
678
				case c_obj:
677
					fobj=TRUE;
679
					fobj=TRUE;
678
//					if(comfile==file_d32)FixUp=TRUE;
680
//					if(comfile==file_d32)FixUp=TRUE;
679
					FastCallApi=FALSE;
681
					FastCallApi=FALSE;
680
					break;
682
					break;
681
				case c_me:
683
				case c_me:
682
					puts(meinfo);
684
					puts(meinfo);
683
					exit( e_ok );
685
					exit( e_ok );
684
				case c_key:
686
				case c_key:
685
					int j,jj;
687
					int j,jj;
686
					puts("LIST OF RESERVED IDENTIFIERS:");
688
					puts("LIST OF RESERVED IDENTIFIERS:");
687
					numstr=1;
689
					numstr=1;
688
					ListId(53,id,idofs);
690
					ListId(53,id,idofs);
689
					for(j=0;j
691
					for(j=0;j
690
						puts(id2[j]);
692
						puts(id2[j]);
691
//						CheckNumStr();
693
//						CheckNumStr();
692
					}
694
					}
693
					for(jj=0;jj<2;jj++){
695
					for(jj=0;jj<2;jj++){
694
						for(j=0;j<8;j++)printf("%s ",regs[jj][j]);
696
						for(j=0;j<8;j++)printf("%s ",regs[jj][j]);
695
						puts("");
697
						puts("");
696
//						CheckNumStr();
698
//						CheckNumStr();
697
					}
699
					}
698
					for(j=0;j<8;j++)printf("%s ",begs[j]);
700
					for(j=0;j<8;j++)printf("%s ",begs[j]);
699
					puts("");
701
					puts("");
700
//					CheckNumStr();
702
//					CheckNumStr();
701
					for(j=0;j<6;j++)printf("%s ",segs[j]);
703
					for(j=0;j<6;j++)printf("%s ",segs[j]);
702
					print8item("ST(%d) ");
704
					print8item("ST(%d) ");
703
					puts("ST");
705
					puts("ST");
704
					print8item("st(%d) ");
706
					print8item("st(%d) ");
705
					puts("st");
707
					puts("st");
706
					exit(e_ok);
708
					exit(e_ok);
707
				case c_lasm:
709
				case c_lasm:
708
					puts("LIST OF SUPPORTED ASSEMBLER INSTRUCTIONS:");
710
					puts("LIST OF SUPPORTED ASSEMBLER INSTRUCTIONS:");
709
					numstr=1;
711
					numstr=1;
710
					ListId(26,asmMnem,ofsmnem);
712
					ListId(26,asmMnem,ofsmnem);
711
					exit(e_ok);
713
					exit(e_ok);
712
				case c_s:
714
				case c_s:
713
					if(ptr==NULL)return c_end;
715
					if(ptr==NULL)return c_end;
714
					if((stacksize=getnumber((unsigned char *)ptr))==0){
716
					if((stacksize=getnumber((unsigned char *)ptr))==0){
715
						puts("Bad stack size.");
717
						puts("Bad stack size.");
716
						exit(e_unknowncommandline);
718
						exit(e_unknowncommandline);
717
					}
719
					}
718
					stacksize=Align(stacksize,4);
720
					stacksize=Align(stacksize,4);
719
					break;
721
					break;
720
				case c_w:
722
				case c_w:
721
					gwarning=(unsigned char)TRUE^neg;
723
					gwarning=(unsigned char)TRUE^neg;
722
					break;
724
					break;
723
				case c_wf:
725
				case c_wf:
724
					if(wartype.name)free(wartype.name);
726
					if(wartype.name)free(wartype.name);
725
					wartype.name=BackString(ptr);
727
					wartype.name=BackString(ptr);
726
					break;
728
					break;
727
				case c_de:
729
				case c_de:
728
					divexpand=(unsigned char)TRUE^neg;
730
					divexpand=(unsigned char)TRUE^neg;
729
					break;
731
					break;
730
				case c_opnum:
732
				case c_opnum:
731
					optnumber=(unsigned char)TRUE^neg;
733
					optnumber=(unsigned char)TRUE^neg;
732
					break;
734
					break;
733
				case c_ip:
735
				case c_ip:
734
					IncludePath(ptr);
736
					IncludePath(ptr);
735
					break;
737
					break;
736
				case c_arg:
738
				case c_arg:
737
					parsecommandline=(unsigned char)TRUE^neg;
739
					parsecommandline=(unsigned char)TRUE^neg;
738
					fargc=(unsigned char)TRUE^neg;
740
					fargc=(unsigned char)TRUE^neg;
739
					break;
741
					break;
740
				case c_texe:
742
				case c_texe:
741
					if(extflag) strcpy(outext,"exe");
743
					if(extflag) strcpy(outext,"exe");
742
					comfile=file_exe;
744
					comfile=file_exe;
743
					break;
745
					break;
744
				case c_rom:
746
				case c_rom:
745
					if(extflag) strcpy(outext,"rom");
747
					if(extflag) strcpy(outext,"rom");
746
					comfile=file_rom;
748
					comfile=file_rom;
747
					startptr=0;
749
					startptr=0;
748
					startptrdata=0; 	// data start address
750
					startptrdata=0; 	// data start address
749
					GetMemExeDat();
751
					GetMemExeDat();
750
					break;
752
					break;
751
				case c_dll:
753
				case c_dll:
752
					wconsole=TRUE;
754
					wconsole=TRUE;
753
					dllflag=TRUE;
755
					dllflag=TRUE;
754
					if(extflag) strcpy(outext,"dll");
756
					if(extflag) strcpy(outext,"dll");
755
					comfile=file_w32;
757
					comfile=file_w32;
756
					FixUpTable=TRUE;
758
					FixUpTable=TRUE;
757
					goto nexpardll;
759
					goto nexpardll;
758
 
760
 
759
/*					FixUp=TRUE;
761
/*					FixUp=TRUE;
760
					startptrdata=startptr=0;
762
					startptrdata=startptr=0;
761
					am32=TRUE;
763
					am32=TRUE;
762
					if(chip<3)chip=3;
764
					if(chip<3)chip=3;
763
					if(FILEALIGN==0)FILEALIGN=512;
765
					if(FILEALIGN==0)FILEALIGN=512;
764
					break;*/
766
					break;*/
765
				case c_w32c:
767
				case c_w32c:
766
					wconsole=TRUE;
768
					wconsole=TRUE;
767
					goto init_w32;
769
					goto init_w32;
768
				case c_w32:
770
				case c_w32:
769
					wconsole=FALSE;
771
					wconsole=FALSE;
770
					dllflag=FALSE;
772
					dllflag=FALSE;
771
init_w32:
773
init_w32:
772
					comfile=file_w32;
774
					comfile=file_w32;
773
					goto nexpar;
775
					goto nexpar;
774
				case c_d32:
776
				case c_d32:
775
					comfile=file_d32;
777
					comfile=file_d32;
776
nexpar:
778
nexpar:
777
					if(extflag) strcpy(outext,"exe");
779
					if(extflag) strcpy(outext,"exe");
778
nexpardll:
780
nexpardll:
779
					FixUp=TRUE;
781
					FixUp=TRUE;
780
					startptrdata=startptr=0;
782
					startptrdata=startptr=0;
781
					am32=TRUE;
783
					am32=TRUE;
782
					if(chip<3)chip=3;
784
					if(chip<3)chip=3;
783
					if(FILEALIGN==0)FILEALIGN=512;
785
					if(FILEALIGN==0)FILEALIGN=512;
784
					break;
786
					break;
785
				case c_meos:
787
				case c_meos:
786
					comfile=file_meos;
788
					comfile=file_meos;
787
					am32=TRUE;
789
					am32=TRUE;
788
					startptrdata=startptr=0;
790
					startptrdata=startptr=0;
789
					if(extflag) strcpy(outext,"");
791
					if(extflag) strcpy(outext,"");
790
					if(chip<3)chip=3;
792
					if(chip<3)chip=3;
791
					break;
793
					break;
792
				case c_b32:
794
				case c_b32:
793
					comfile=file_bin;
795
					comfile=file_bin;
794
					am32=TRUE;
796
					am32=TRUE;
795
					startptrdata=startptr=0;
797
					startptrdata=startptr=0;
796
					if(extflag) strcpy(outext,"bin");
798
					if(extflag) strcpy(outext,"bin");
797
					FixUp=TRUE;
799
					FixUp=TRUE;
798
					ImageBase=0;
800
					ImageBase=0;
799
					if(chip<3)chip=3;
801
					if(chip<3)chip=3;
800
					break;
802
					break;
801
				case c_stub:
803
				case c_stub:
802
					if(stubfile)free(stubfile);
804
					if(stubfile)free(stubfile);
803
					stubfile=BackString(ptr);
805
					stubfile=BackString(ptr);
804
					dpmistub=FALSE;
806
					dpmistub=FALSE;
805
					if(stricmp(stubfile,"dpmi")==0){
807
					if(stricmp(stubfile,"dpmi")==0){
806
						if(notdoneprestuff!=TRUE)goto errlate;
808
						if(notdoneprestuff!=TRUE)goto errlate;
807
						dpmistub=TRUE;
809
						dpmistub=TRUE;
808
						usestub=FALSE;
810
						usestub=FALSE;
809
					}
811
					}
810
					break;
812
					break;
811
				case c_ns:
813
				case c_ns:
812
					usestub=(unsigned char)0^neg;
814
					usestub=(unsigned char)0^neg;
813
					break;
815
					break;
814
				case c_ap:
816
				case c_ap:
815
					AlignProc=(unsigned char)1^neg;
817
					AlignProc=(unsigned char)1^neg;
816
					if(ptr!=NULL){
818
					if(ptr!=NULL){
817
						alignproc=getnumber((unsigned char *)ptr);
819
						alignproc=getnumber((unsigned char *)ptr);
818
						if(alignproc<1||alignproc>4096)alignproc=8;
820
						if(alignproc<1||alignproc>4096)alignproc=8;
819
					}
821
					}
820
					break;
822
					break;
821
				case c_define:
823
				case c_define:
822
					addconsttotree(ptr,TRUE);
824
					addconsttotree(ptr,TRUE);
823
					break;
825
					break;
824
				case c_ost:
826
				case c_ost:
825
					optstr=(unsigned char)TRUE^neg;
827
					optstr=(unsigned char)TRUE^neg;
826
					break;
828
					break;
827
				case c_cri:
829
				case c_cri:
828
					crif=(unsigned char)1^neg;
830
					crif=(unsigned char)1^neg;
829
					break;
831
					break;
830
				case c_ia:
832
				case c_ia:
831
					idasm=(unsigned char)1^neg;
833
					idasm=(unsigned char)1^neg;
832
					break;
834
					break;
833
				case c_dbg:
835
				case c_dbg:
834
					dbg&=0xFE;
836
					dbg&=0xFE;
835
					char c;
837
					char c;
836
					c=(unsigned char)1^neg;
838
					c=(unsigned char)1^neg;
837
					dbg|=c;
839
					dbg|=c;
838
					if(!neg)InitDbg();
840
					if(!neg)InitDbg();
839
					break;
841
					break;
840
				case c_scd:
842
				case c_scd:
841
/*-----------------13.08.00 23:01-------------------
843
/*-----------------13.08.00 23:01-------------------
842
 áóäåò ââåäåíà ïîñëå äîðàáîòêè äèíàìè÷åñêèõ ïðîöåäóð
844
 áóäåò ââåäåíà ïîñëå äîðàáîòêè äèíàìè÷åñêèõ ïðîöåäóð
843
	--------------------------------------------------*/
845
	--------------------------------------------------*/
844
					splitdata=(unsigned char)1^neg;
846
					splitdata=(unsigned char)1^neg;
845
					if(modelmem==SMALL)splitdata=TRUE;
847
					if(modelmem==SMALL)splitdata=TRUE;
846
					break;
848
					break;
847
				case c_al:
849
				case c_al:
848
					if(ptr==NULL)return c_end;
850
					if(ptr==NULL)return c_end;
849
					aligner=(unsigned char)getnumber((unsigned char *)ptr);
851
					aligner=(unsigned char)getnumber((unsigned char *)ptr);
850
					break;
852
					break;
851
				case c_at:
853
				case c_at:
852
					atex=(unsigned char)1^neg;
854
					atex=(unsigned char)1^neg;
853
					break;
855
					break;
854
				case c_wfa:
856
				case c_wfa:
855
					FastCallApi=(unsigned char)1^neg;
857
					FastCallApi=(unsigned char)1^neg;
856
					break;
858
					break;
857
				case c_wfu:
859
				case c_wfu:
858
					FixUpTable=(unsigned char)1^neg;
860
					FixUpTable=(unsigned char)1^neg;
859
					break;
861
					break;
860
				case c_wib:
862
				case c_wib:
861
					if(ptr==NULL)return c_end;
863
					if(ptr==NULL)return c_end;
862
					ImageBase=getnumber((unsigned char *)ptr);
864
					ImageBase=getnumber((unsigned char *)ptr);
863
					break;
865
					break;
864
				case c_iv:
866
				case c_iv:
865
					notpost=(unsigned char)1^neg;
867
					notpost=(unsigned char)1^neg;
866
					break;
868
					break;
867
				case c_mer:
869
				case c_mer:
868
					if(ptr==NULL)return c_end;
870
					if(ptr==NULL)return c_end;
869
					if((maxerrors=getnumber((unsigned char *)ptr))==0)maxerrors=16;
871
					if((maxerrors=getnumber((unsigned char *)ptr))==0)maxerrors=16;
870
					break;
872
					break;
871
				case c_sa:
873
				case c_sa:
872
					if(ptr==NULL)return c_end;
874
					if(ptr==NULL)return c_end;
873
					startptrdata=startptr=getnumber((unsigned char *)ptr);
875
					startptrdata=startptr=getnumber((unsigned char *)ptr);
874
					break;
876
					break;
875
				case c_stm:
877
				case c_stm:
876
					startuptomain=(unsigned char)1^neg;
878
					startuptomain=(unsigned char)1^neg;
877
					break;
879
					break;
878
				case c_suv:
880
				case c_suv:
879
					if(ptr==NULL)return c_end;
881
					if(ptr==NULL)return c_end;
880
					startStartup=getnumber((unsigned char *)ptr);
882
					startStartup=getnumber((unsigned char *)ptr);
881
					break;
883
					break;
882
				case c_wmb:
884
				case c_wmb:
883
					WinMonoBlock=(unsigned char)1^neg;
885
					WinMonoBlock=(unsigned char)1^neg;
884
					break;
886
					break;
885
				case c_ust:
887
				case c_ust:
886
					useStartup=(unsigned char)1^neg;
888
					useStartup=(unsigned char)1^neg;
887
					break;
889
					break;
888
				case c_help:
890
				case c_help:
889
				case c_h:
891
				case c_h:
890
				case c_hh:
892
				case c_hh:
891
					PrintInfo(usage);
893
					PrintInfo(usage);
892
					exit(e_ok);
894
					exit(e_ok);
893
				case c_mif:
895
				case c_mif:
894
					if(ptr==NULL)return c_end;
896
					if(ptr==NULL)return c_end;
895
					if(rawfilename!=NULL){
897
					if(rawfilename!=NULL){
896
						free(rawfilename);
898
						free(rawfilename);
897
						rawfilename=NULL;
899
						rawfilename=NULL;
898
					}
900
					}
899
					if(rawext!=NULL){
901
					if(rawext!=NULL){
900
						free(rawext);
902
						free(rawext);
901
						rawext=NULL;
903
						rawext=NULL;
902
					}
904
					}
903
					char *temp;
905
					char *temp;
904
        	if((temp=strrchr(ptr,'.'))!=NULL){
906
        	if((temp=strrchr(ptr,'.'))!=NULL){
905
						*temp++=0;
907
						*temp++=0;
906
						rawext=BackString(temp);
908
						rawext=BackString(temp);
907
						CheckExtenshions();
909
						CheckExtenshions();
908
 	  	    }
910
 	  	    }
909
					rawfilename=BackString(ptr);
911
					rawfilename=BackString(ptr);
910
					break;
912
					break;
911
				case c_ac:
913
				case c_ac:
912
					AlignCycle=(unsigned char)1^neg;
914
					AlignCycle=(unsigned char)1^neg;
913
					if(ptr!=NULL){
915
					if(ptr!=NULL){
914
						aligncycle=getnumber((unsigned char *)ptr);
916
						aligncycle=getnumber((unsigned char *)ptr);
915
						if(aligncycle<1&&aligncycle>4096)aligncycle=8;
917
						if(aligncycle<1&&aligncycle>4096)aligncycle=8;
916
					}
918
					}
917
					break;
919
					break;
918
				case c_ws:	//dos-stub for windows programs
920
				case c_ws:	//dos-stub for windows programs
919
					if(winstub)free(winstub);
921
					if(winstub)free(winstub);
920
					winstub=BackString(ptr);
922
					winstub=BackString(ptr);
921
					break;
923
					break;
922
				case c_ind:
924
				case c_ind:
923
					ImportName(ptr);
925
					ImportName(ptr);
924
					break;
926
					break;
925
				case c_wbss:
927
				case c_wbss:
926
					wbss=(unsigned char)1^neg;
928
					wbss=(unsigned char)1^neg;
927
					break;
929
					break;
928
				case c_wo:
930
				case c_wo:
929
					useordinal=(unsigned char)1^neg;
931
					useordinal=(unsigned char)1^neg;
930
					break;
932
					break;
931
				case c_nw:
933
				case c_nw:
932
					if(ptr==NULL)return c_end;
934
					if(ptr==NULL)return c_end;
933
					len=getnumber((unsigned char *)ptr);
935
					len=getnumber((unsigned char *)ptr);
934
					if(len>0&&len<=WARNCOUNT)wact[len-1].usewarn=(unsigned char)0^neg;
936
					if(len>0&&len<=WARNCOUNT)wact[len-1].usewarn=(unsigned char)0^neg;
935
					break;
937
					break;
936
				case c_we:
938
				case c_we:
937
					if(ptr==NULL)return c_end;
939
					if(ptr==NULL)return c_end;
938
					len=getnumber((unsigned char *)ptr);
940
					len=getnumber((unsigned char *)ptr);
939
					if(len>0&&len<=WARNCOUNT){
941
					if(len>0&&len<=WARNCOUNT){
940
						if(neg)wact[len-1].fwarn=warningprint;
942
						if(neg)wact[len-1].fwarn=warningprint;
941
						else wact[len-1].fwarn=preerror3;
943
						else wact[len-1].fwarn=preerror3;
942
					}
944
					}
943
					break;
945
					break;
944
				case c_lst:
946
				case c_lst:
945
					SetLST(neg);
947
					SetLST(neg);
946
					break;
948
					break;
947
				case c_d4g:
949
				case c_d4g:
948
					useDOS4GW=(unsigned char)1^neg;
950
					useDOS4GW=(unsigned char)1^neg;
949
					break;
951
					break;
950
				case c_env:
952
				case c_env:
951
					use_env=(unsigned char)1^neg;
953
					use_env=(unsigned char)1^neg;
952
					break;
954
					break;
953
				case c_cpa:
955
				case c_cpa:
954
					clearpost=(unsigned char)1^neg;
956
					clearpost=(unsigned char)1^neg;
955
					break;
957
					break;
956
				case c_ul:
958
				case c_ul:
957
					uselea=(unsigned char)1^neg;
959
					uselea=(unsigned char)1^neg;
958
					break;
960
					break;
959
				case c_as:
961
				case c_as:
960
					if(ptr){
962
					if(ptr){
961
						len=getnumber((unsigned char *)ptr);
963
						len=getnumber((unsigned char *)ptr);
962
						if(caselong(len)!=NUMNUM)strpackdef=len;
964
						if(caselong(len)!=NUMNUM)strpackdef=len;
963
					}
965
					}
964
					else strpackdef=(neg==FALSE?8:1);
966
					else strpackdef=(neg==FALSE?8:1);
965
					strpackcur=strpackdef;
967
					strpackcur=strpackdef;
966
					break;
968
					break;
967
				case c_lrs:
969
				case c_lrs:
968
					regoverstack=(unsigned char)1^neg;
970
					regoverstack=(unsigned char)1^neg;
969
					break;
971
					break;
970
				case c_wsi:
972
				case c_wsi:
971
					shortimport=(unsigned char)1^neg;
973
					shortimport=(unsigned char)1^neg;
972
					break;
974
					break;
973
				case c_waf:
975
				case c_waf:
974
					if(ptr!=NULL){
976
					if(ptr!=NULL){
975
						FILEALIGN=Align(getnumber((unsigned char *)ptr),16);
977
						FILEALIGN=Align(getnumber((unsigned char *)ptr),16);
976
					}
978
					}
977
					break;
979
					break;
978
				case c_sf:
980
				case c_sf:
979
					if(ptr==NULL)return c_end;
981
					if(ptr==NULL)return c_end;
980
					namestartupfile=BackString(ptr);
982
					namestartupfile=BackString(ptr);
981
					break;
983
					break;
982
				case c_oir:
984
				case c_oir:
983
					optinitreg=(unsigned char)1^neg;
985
					optinitreg=(unsigned char)1^neg;
984
					break;
986
					break;
985
				case c_coff:
987
				case c_coff:
986
					ocoff=(unsigned char)1^neg;
988
					ocoff=(unsigned char)1^neg;
987
					break;
989
					break;
988
				case c_js:
990
				case c_js:
989
					addstack=(unsigned char)1^neg;
991
					addstack=(unsigned char)1^neg;
990
					if(addstack==0)RestoreStack();
992
					if(addstack==0)RestoreStack();
991
					break;
993
					break;
992
				case c_ba:
994
				case c_ba:
993
					bytesize=(unsigned char)1^neg;
995
					bytesize=(unsigned char)1^neg;
994
					break;
996
					break;
995
				case c_asp:
997
				case c_asp:
996
					if(blockproc)goto errlate;
998
					if(blockproc)goto errlate;
997
					else ESPloc=(unsigned char)1^neg;
999
					else ESPloc=(unsigned char)1^neg;
998
					break;
1000
					break;
999
#ifdef OPTVARCONST
1001
#ifdef OPTVARCONST
1000
				case c_orv:
1002
				case c_orv:
1001
					replasevar=(unsigned char)1^neg;
1003
					replasevar=(unsigned char)1^neg;
1002
					if(replasevar&&listvic)ClearLVIC();
1004
					if(replasevar&&listvic)ClearLVIC();
1003
					break;
1005
					break;
1004
				case c_map:
1006
				case c_map:
1005
					mapfile=(unsigned char)1^neg;
1007
					mapfile=(unsigned char)1^neg;
1006
					break;
1008
					break;
1007
#endif
1009
#endif
1008
				case c_ext:     //***lev***
1010
				case c_ext:     //***lev***
1009
					strcpy(outext,BackString(ptr)); //***lev***
1011
					strcpy(outext,BackString(ptr)); //***lev***
1010
					extflag=FALSE; //÷òîáû ðàñøèðåíèå íå ïåðåçàáèâàëîñü äðóãèìè êëþ÷àìè, åñëè îíè èäóò ïîçæå
1012
					extflag=FALSE; //÷òîáû ðàñøèðåíèå íå ïåðåçàáèâàëîñü äðóãèìè êëþ÷àìè, åñëè îíè èäóò ïîçæå
1011
					break;  //***lev***
1013
					break;  //***lev***
1012
			}
1014
			}
1013
			break;
1015
			break;
1014
		}
1016
		}
1015
	}
1017
	}
1016
	return i;
1018
	return i;
1017
}
1019
}
1018
 
1020
 
1019
void SetLST(unsigned char neg)
1021
void SetLST(unsigned char neg)
1020
{
1022
{
1021
	if(((dbg&2)>>1)==neg){
1023
	if(((dbg&2)>>1)==neg){
1022
		dbg&=0xFD;
1024
		dbg&=0xFD;
1023
		unsigned char c=(unsigned char)((1^neg)<<1);
1025
		unsigned char c=(unsigned char)((1^neg)<<1);
1024
		dbg|=c;
1026
		dbg|=c;
1025
		if(neg){
1027
		if(neg){
1026
			if((dbg&0xFE)==0)dbgact=TRUE;
1028
			if((dbg&0xFE)==0)dbgact=TRUE;
1027
			AddEndLine();
1029
			AddEndLine();
1028
		}
1030
		}
1029
		else{
1031
		else{
1030
			InitDbg();
1032
			InitDbg();
1031
			if(notdoneprestuff!=TRUE)dbgact=FALSE;	//startup cod
1033
			if(notdoneprestuff!=TRUE)dbgact=FALSE;	//startup cod
1032
		}
1034
		}
1033
	}
1035
	}
1034
}
1036
}
1035
 
1037
 
1036
void print8item(char *str)
1038
void print8item(char *str)
1037
{
1039
{
1038
//	CheckNumStr();
1040
//	CheckNumStr();
1039
	for(int j=0;j<8;j++)printf(str,j);
1041
	for(int j=0;j<8;j++)printf(str,j);
1040
	puts("");
1042
	puts("");
1041
}
1043
}
1042
 
1044
 
1043
 
1045
 
1044
 
1046
 
1045
 
1047
 
1046
void _loadIni(FILE *inih)
1048
void _loadIni(FILE *inih)
1047
{
1049
{
1048
	char m1[256];
1050
	char m1[256];
1049
	for(;;){
1051
	for(;;){
1050
		if(fgets(m1,255,inih)==NULL)break;
1052
		if(fgets(m1,255,inih)==NULL)break;
1051
		if(SelectComand(m1,0)==c_end)BadCommandLine(m1);
1053
		if(SelectComand(m1,0)==c_end)BadCommandLine(m1);
1052
	}
1054
	}
1053
	fclose(inih);
1055
	fclose(inih);
1054
}
1056
}
1055
 
1057
 
1056
void LoadIni(char *name)
1058
void LoadIni(char *name)
1057
{
1059
{
1058
FILE *inih;
1060
FILE *inih;
1059
char m1[256];
1061
char m1[256];
1060
 
1062
 
1061
							// load name
1063
							// load name
1062
	if (inih = fopen(name,"rb"))
1064
	if (inih = fopen(name,"rb"))
1063
	{_loadIni(inih);return;}
1065
	{_loadIni(inih);return;}
1064
	
1066
	
1065
	if(strcmp(name,"c--.ini")!=0)
1067
	if(strcmp(name,"c--.ini")!=0)
1066
			return;
1068
			return;
1067
 
1069
 
1068
							//load findpath[0]\c--.ini
1070
							//load findpath[0]\c--.ini
1069
	if (findpath[0]!=0)
1071
	if (findpath[0]!=0)
1070
	{
1072
	{
1071
		sprintf(m1,"%s%s",findpath[0],name);
1073
		sprintf(m1,"%s%s",findpath[0],name);
1072
		if (inih = fopen(m1,"rb"))
1074
		if (inih = fopen(m1,"rb"))
1073
		{_loadIni(inih);return;}
1075
		{_loadIni(inih);return;}
1074
	}
1076
	}
1075
							//load PATH[i=0..end]/c--.ini
1077
							//load PATH[i=0..end]/c--.ini
1076
	char* pth = getenv("PATH");	
1078
	char* pth = getenv("PATH");	
1077
	if (pth != 0)
1079
	if (pth != 0)
1078
	{
1080
	{
1079
		char* start;
1081
		char* start;
1080
		int size;
1082
		int size;
1081
		start = pth;	
1083
		start = pth;	
1082
		while(*start) 
1084
		while(*start) 
1083
		{
1085
		{
1084
			size = 0;
1086
			size = 0;
1085
			char* endp = strchr(start, DIV_PATH);
1087
			char* endp = strchr(start, DIV_PATH);
1086
			size = (endp == 0)? strlen(start): endp-start;
1088
			size = (endp == 0)? strlen(start): endp-start;
1087
			strncpy(m1, start, size);
1089
			strncpy(m1, start, size);
1088
			start += size + 1;
1090
			start += size + 1;
1089
			if (m1[size - 1] != DIV_FOLD)
1091
			if (m1[size - 1] != DIV_FOLD)
1090
				m1[size++] = '/';
1092
				m1[size++] = '/';
1091
			
1093
			
1092
			strcpy(m1 + size,"c--.ini");
1094
			strcpy(m1 + size,"c--.ini");
1093
			if (inih = fopen(m1,"rb"))
1095
			if (inih = fopen(m1,"rb"))
1094
			{_loadIni(inih);return;}
1096
			{_loadIni(inih);return;}
1095
		}
1097
		}
1096
	}
1098
	}
1097
#ifdef _KOS_
1099
#ifdef _KOS_
1098
								//for KolibriOS: load program_dir/c--.ini 
1100
								//for KolibriOS: load program_dir/c--.ini 
1099
	int p;
1101
	int p;
1100
	strcpy(m1,__pgmname);
1102
	strcpy(m1,__pgmname);
1101
	p = strlen(m1);
1103
	p = strlen(m1);
1102
	while ((*(m1+p)!='/') && (p != 0))
1104
	while ((*(m1+p)!='/') && (p != 0))
1103
		p--;
1105
		p--;
1104
	if (p){
1106
	if (p){
1105
		p++;
1107
		p++;
1106
		strcpy(m1+p,"c--.ini");
1108
		strcpy(m1+p,"c--.ini");
1107
		if (inih = fopen(m1,"rb"))
1109
		if (inih = fopen(m1,"rb"))
1108
		{_loadIni(inih);return;}
1110
		{_loadIni(inih);return;}
1109
	}
1111
	}
1110
								//for KolibriOS: load /rd/0/settings/c--.ini 
1112
								//for KolibriOS: load /rd/0/settings/c--.ini 
1111
	inih = fopen("/rd/1/settings/c--.ini","rb");
1113
	inih = fopen("/rd/1/settings/c--.ini","rb");
1112
	for(;;){
1114
	for(;;){
1113
		if(fgets(m1,255,inih)==NULL)break;
1115
		if(fgets(m1,255,inih)==NULL)break;
1114
		if(SelectComand(m1,0)==c_end)BadCommandLine(m1);
1116
		if(SelectComand(m1,0)==c_end)BadCommandLine(m1);
1115
	}
1117
	}
1116
	fclose(inih);
1118
	fclose(inih);
1117
	return;
1119
	return;
1118
#endif //_KOS_		
1120
#endif //_KOS_		
1119
}
1121
}
1120
			
1122
			
1121
/*****************************************************************************
1123
/*****************************************************************************
1122
* .NAME   : MALLOC
1124
* .NAME   : MALLOC
1123
* .TITLE  : Âûäåëÿåò ïàìÿòü ñ îáðàáîòêîé îøèáîê.
1125
* .TITLE  : Âûäåëÿåò ïàìÿòü ñ îáðàáîòêîé îøèáîê.
1124
*****************************************************************************/
1126
*****************************************************************************/
1125
void OutMemory()
1127
void OutMemory()
1126
{
1128
{
1127
	preerror("Compiler out of memory");
1129
	preerror("Compiler out of memory");
1128
	exit(e_outofmemory);
1130
	exit(e_outofmemory);
1129
}
1131
}
1130
 
1132
 
1131
void * MALLOC (unsigned long size)
1133
void * MALLOC (unsigned long size)
1132
{
1134
{
1133
void *mem;
1135
void *mem;
1134
	mem=malloc(size);
1136
	mem=malloc(size);
1135
	if(mem==NULL)OutMemory();
1137
	if(mem==NULL)OutMemory();
1136
 
1138
 
1137
//	if(((unsigned long)mem+size)>maxusedmem)maxusedmem=(unsigned long)mem+size;
1139
//	if(((unsigned long)mem+size)>maxusedmem)maxusedmem=(unsigned long)mem+size;
1138
 
1140
 
1139
	return mem;
1141
	return mem;
1140
}
1142
}
1141
 
1143
 
1142
void *REALLOC(void *block,unsigned long size)
1144
void *REALLOC(void *block,unsigned long size)
1143
{
1145
{
1144
void *mem;
1146
void *mem;
1145
	mem=realloc(block,size);
1147
	mem=realloc(block,size);
1146
	if(mem==NULL)OutMemory();
1148
	if(mem==NULL)OutMemory();
1147
 
1149
 
1148
//	if(((unsigned long)mem+size)>maxusedmem)maxusedmem=(unsigned long)mem+size;
1150
//	if(((unsigned long)mem+size)>maxusedmem)maxusedmem=(unsigned long)mem+size;
1149
 
1151
 
1150
	return mem;
1152
	return mem;
1151
}
1153
}
1152
 
1154
 
1153
void IncludePath(char *buf)
1155
void IncludePath(char *buf)
1154
{
1156
{
1155
	char divfold[3];
1157
	char divfold[3];
1156
	sprintf(divfold,"%c",DIV_FOLD);
1158
	sprintf(divfold,"%c",DIV_FOLD);
1157
	if(numfindpath
1159
	if(numfindpath
1158
		int len=strlen(buf);
1160
		int len=strlen(buf);
1159
		if(buf[len-1]==DIV_FOLD)buf[len-1]=0;
1161
		if(buf[len-1]==DIV_FOLD)buf[len-1]=0;
1160
		else len++;
1162
		else len++;
1161
		char *a=(char *)MALLOC(len+1);
1163
		char *a=(char *)MALLOC(len+1);
1162
		strcpy(a,buf);
1164
		strcpy(a,buf);
1163
		strcat(a,divfold);
1165
		strcat(a,divfold);
1164
		findpath[numfindpath]=a;
1166
		findpath[numfindpath]=a;
1165
		numfindpath++;
1167
		numfindpath++;
1166
		findpath[numfindpath]="";
1168
		findpath[numfindpath]="";
1167
	}
1169
	}
1168
	else puts("Too many include paths");
1170
	else puts("Too many include paths");
1169
}
1171
}
1170
 
1172
 
1171
void doposts()
1173
void doposts()
1172
{
1174
{
1173
unsigned long addvalue,i,addval,addvalw32=0,addvalbss=0;
1175
unsigned long addvalue,i,addval,addvalw32=0,addvalbss=0;
1174
	if(splitdata&&modelmem==TINY&&outptrdata){
1176
	if(splitdata&&modelmem==TINY&&outptrdata){
1175
		memcpy((char *)&output[outptr],(char *)&outputdata[0],outptrdata);
1177
		memcpy((char *)&output[outptr],(char *)&outputdata[0],outptrdata);
1176
		addval=outptr;
1178
		addval=outptr;
1177
		outptr+=outptrdata;
1179
		outptr+=outptrdata;
1178
		outptrdata=outptr;
1180
		outptrdata=outptr;
1179
	}
1181
	}
1180
	addvalue=outptrdata;
1182
	addvalue=outptrdata;
1181
	if(comfile==file_bin)addvalbss=addvalw32=ImageBase;
1183
	if(comfile==file_bin)addvalbss=addvalw32=ImageBase;
1182
	else if(comfile==file_w32){
1184
	else if(comfile==file_w32){
1183
		addvalbss=addvalw32=ImageBase+vsizeheader;
1185
		addvalbss=addvalw32=ImageBase+vsizeheader;
1184
		if(postsize&&wbss){
1186
		if(postsize&&wbss){
1185
			addvalw32+=Align(postsize,OBJECTALIGN);
1187
			addvalw32+=Align(postsize,OBJECTALIGN);
1186
			addvalue=0;
1188
			addvalue=0;
1187
		}
1189
		}
1188
	}
1190
	}
1189
	else{
1191
	else{
1190
		if((outptrdata%2)==1){	/* alignment of entire post data block manditory */
1192
		if((outptrdata%2)==1){	/* alignment of entire post data block manditory */
1191
			addvalue++;	//íà÷àëî íåèíèö.äàííûõ
1193
			addvalue++;	//íà÷àëî íåèíèö.äàííûõ
1192
			postsize++;
1194
			postsize++;
1193
		}
1195
		}
1194
/*		if(am32&&(outptrdata%4)==2){
1196
/*		if(am32&&(outptrdata%4)==2){
1195
			addvalue+=2;	//íà÷àëî íåèíèö.äàííûõ
1197
			addvalue+=2;	//íà÷àëî íåèíèö.äàííûõ
1196
			postsize+=2;
1198
			postsize+=2;
1197
		}*/
1199
		}*/
1198
	}
1200
	}
1199
	if(am32==0&&(MAXDATA-outptrdata)
1201
	if(am32==0&&(MAXDATA-outptrdata)
1200
	for(i=0;i
1202
	for(i=0;i
1201
		switch((postbuf+i)->type){
1203
		switch((postbuf+i)->type){
1202
			case POST_VAR:
1204
			case POST_VAR:
1203
				*(short *)&output[(postbuf+i)->loc]+=(short)addvalue;
1205
				*(short *)&output[(postbuf+i)->loc]+=(short)addvalue;
1204
				break;
1206
				break;
1205
			case POST_VAR32:
1207
			case POST_VAR32:
1206
				*(long *)&output[(postbuf+i)->loc]+=addvalue+addvalbss;
1208
				*(long *)&output[(postbuf+i)->loc]+=addvalue+addvalbss;
1207
				numrel++;
1209
				numrel++;
1208
				break;
1210
				break;
1209
			case FIX_VAR32:
1211
			case FIX_VAR32:
1210
			case FIX_CODE32:
1212
			case FIX_CODE32:
1211
				*(long *)&output[(postbuf+i)->loc]+=addvalw32;
1213
				*(long *)&output[(postbuf+i)->loc]+=addvalw32;
1212
				numrel++;
1214
				numrel++;
1213
				break;
1215
				break;
1214
			case FIX_CODE_ADD:
1216
			case FIX_CODE_ADD:
1215
				if(am32){
1217
				if(am32){
1216
					*(long *)&output[(postbuf+i)->loc]+=addvalw32+(postbuf+i)->num;
1218
					*(long *)&output[(postbuf+i)->loc]+=addvalw32+(postbuf+i)->num;
1217
					(postbuf+i)->type=(unsigned short)FIX_VAR32;
1219
					(postbuf+i)->type=(unsigned short)FIX_VAR32;
1218
				}
1220
				}
1219
				else{
1221
				else{
1220
					*(short *)&output[(postbuf+i)->loc]+=(short)(addval+(postbuf+i)->num);
1222
					*(short *)&output[(postbuf+i)->loc]+=(short)(addval+(postbuf+i)->num);
1221
					(postbuf+i)->type=(unsigned short)FIX_VAR;
1223
					(postbuf+i)->type=(unsigned short)FIX_VAR;
1222
				}
1224
				}
1223
				numrel++;
1225
				numrel++;
1224
				break;
1226
				break;
1225
			case DATABLOCK_VAR:
1227
			case DATABLOCK_VAR:
1226
				*(short *)&output[(postbuf+i)->loc]+=(short)addval;
1228
				*(short *)&output[(postbuf+i)->loc]+=(short)addval;
1227
				if(FixUp)(postbuf+i)->type=(unsigned short)FIX_VAR;
1229
				if(FixUp)(postbuf+i)->type=(unsigned short)FIX_VAR;
1228
				break;
1230
				break;
1229
			case DATABLOCK_VAR32:
1231
			case DATABLOCK_VAR32:
1230
				*(long *)&output[(postbuf+i)->loc]+=addval+addvalw32;
1232
				*(long *)&output[(postbuf+i)->loc]+=addval+addvalw32;
1231
				if(FixUp)(postbuf+i)->type=(unsigned short)FIX_VAR32;
1233
				if(FixUp)(postbuf+i)->type=(unsigned short)FIX_VAR32;
1232
				numrel++;
1234
				numrel++;
1233
				break;
1235
				break;
1234
		}
1236
		}
1235
	}
1237
	}
1236
	ooutptr=addvalue;	//ñîõðàíèòü íà÷àëî post äëÿ debug;
1238
	ooutptr=addvalue;	//ñîõðàíèòü íà÷àëî post äëÿ debug;
1237
}
1239
}
1238
 
1240
 
1239
void GetMemExeDat()
1241
void GetMemExeDat()
1240
{
1242
{
1241
	if(outputdata==output&&outputdata!=0)outputdata=(unsigned char *)MALLOC((size_t)MAXDATA);
1243
	if(outputdata==output&&outputdata!=0)outputdata=(unsigned char *)MALLOC((size_t)MAXDATA);
1242
}
1244
}
1243
 
1245
 
1244
void ListId(int numfirstchar,unsigned char *list,short *ofs)
1246
void ListId(int numfirstchar,unsigned char *list,short *ofs)
1245
{
1247
{
1246
char buf[40];
1248
char buf[40];
1247
	for(int i=0;i
1249
	for(int i=0;i
1248
		if((short)ofs[i]!=-1){
1250
		if((short)ofs[i]!=-1){
1249
			if(i<26)buf[0]=(char)('A'+i);
1251
			if(i<26)buf[0]=(char)('A'+i);
1250
			else if(i==26)buf[0]='_';
1252
			else if(i==26)buf[0]='_';
1251
			else buf[0]=(char)(i-27+'a');
1253
			else buf[0]=(char)(i-27+'a');
1252
			unsigned char *ii=(unsigned char *)(list+ofs[i]);
1254
			unsigned char *ii=(unsigned char *)(list+ofs[i]);
1253
			while(*(short *)&*ii!=-1){
1255
			while(*(short *)&*ii!=-1){
1254
				ii+=2;
1256
				ii+=2;
1255
				strcpy(buf+1,(char *)ii);
1257
				strcpy(buf+1,(char *)ii);
1256
				ii+=strlen((char *)ii)+1;
1258
				ii+=strlen((char *)ii)+1;
1257
				puts(buf);
1259
				puts(buf);
1258
//				CheckNumStr();
1260
//				CheckNumStr();
1259
			}
1261
			}
1260
		}
1262
		}
1261
	}
1263
	}
1262
}
1264
}
1263
 
1265
 
1264
int writeoutput()
1266
int writeoutput()
1265
{
1267
{
1266
EXE_DOS_HEADER exeheader;  // header for EXE format
1268
EXE_DOS_HEADER exeheader;  // header for EXE format
1267
	if(fobj){
1269
	if(fobj){
1268
		if(comfile==file_w32&&ocoff)return MakeCoff();
1270
		if(comfile==file_w32&&ocoff)return MakeCoff();
1269
		return MakeObj();
1271
		return MakeObj();
1270
	}
1272
	}
1271
	if(comfile==file_w32)return MakePE();
1273
	if(comfile==file_w32)return MakePE();
1272
	if(comfile==file_meos)return MakeMEOS();
1274
	if(comfile==file_meos)return MakeMEOS();
1273
	if(comfile==file_bin)return MakeBin32();
1275
	if(comfile==file_bin)return MakeBin32();
1274
	memset(&exeheader,0,sizeof(EXE_DOS_HEADER));
1276
	memset(&exeheader,0,sizeof(EXE_DOS_HEADER));
1275
	if(comfile==file_d32){
1277
	if(comfile==file_d32){
1276
		if(usestub){
1278
		if(usestub){
1277
			MakeLE();
1279
			MakeLE();
1278
			runfilesize+=ftell(hout)-32;
1280
			runfilesize+=ftell(hout)-32;
1279
			goto savecode;
1281
			goto savecode;
1280
		}
1282
		}
1281
		else goto exefile;
1283
		else goto exefile;
1282
	}
1284
	}
1283
	if(comfile==file_com||comfile==file_sys||comfile==file_rom){
1285
	if(comfile==file_com||comfile==file_sys||comfile==file_rom){
1284
		hout=CreateOutPut(outext,"wb");
1286
		hout=CreateOutPut(outext,"wb");
1285
		if(fwrite(output+startptr,comfile==file_rom?romsize:outptr-startptr,1,hout)!=1){
1287
		if(fwrite(output+startptr,comfile==file_rom?romsize:outptr-startptr,1,hout)!=1){
1286
			ErrWrite();
1288
			ErrWrite();
1287
			return(-1);
1289
			return(-1);
1288
		}
1290
		}
1289
	}
1291
	}
1290
	else if(comfile==file_exe){
1292
	else if(comfile==file_exe){
1291
exefile:
1293
exefile:
1292
		hout=CreateOutPut(outext,"wb");
1294
		hout=CreateOutPut(outext,"wb");
1293
		MakeExeHeader(&exeheader);
1295
		MakeExeHeader(&exeheader);
1294
		if(fwrite(&exeheader,sizeof(EXE_DOS_HEADER),1,hout)!=1){
1296
		if(fwrite(&exeheader,sizeof(EXE_DOS_HEADER),1,hout)!=1){
1295
errwr:
1297
errwr:
1296
			fclose(hout);
1298
			fclose(hout);
1297
			hout=NULL;
1299
			hout=NULL;
1298
			ErrWrite();
1300
			ErrWrite();
1299
			return(-1);
1301
			return(-1);
1300
		}
1302
		}
1301
		outputcodestart=ftell(hout);
1303
		outputcodestart=ftell(hout);
1302
savecode:
1304
savecode:
1303
		if(fwrite(output+startptr,outptr-startptr,1,hout)!=1)goto errwr;
1305
		if(fwrite(output+startptr,outptr-startptr,1,hout)!=1)goto errwr;
1304
		if(modelmem==SMALL&&outptrdata!=0){
1306
		if(modelmem==SMALL&&outptrdata!=0){
1305
			if(fwrite(outputdata,outptrdata,1,hout)!=1)goto errwr;
1307
			if(fwrite(outputdata,outptrdata,1,hout)!=1)goto errwr;
1306
		}
1308
		}
1307
	}
1309
	}
1308
	fclose(hout);
1310
	fclose(hout);
1309
	hout=NULL;
1311
	hout=NULL;
1310
	return(0);
1312
	return(0);
1311
}
1313
}
1312
 
1314
 
1313
long CopyFile(FILE *in,FILE *out)
1315
long CopyFile(FILE *in,FILE *out)
1314
{
1316
{
1315
char tbuf[1024];
1317
char tbuf[1024];
1316
long loads=0;
1318
long loads=0;
1317
unsigned int len;
1319
unsigned int len;
1318
	do{
1320
	do{
1319
		len=fread(tbuf,1,1024,in);
1321
		len=fread(tbuf,1,1024,in);
1320
		if(fwrite(tbuf,1,len,out)!=len){
1322
		if(fwrite(tbuf,1,len,out)!=len){
1321
			ErrWrite();
1323
			ErrWrite();
1322
			return -1;
1324
			return -1;
1323
		}
1325
		}
1324
		loads+=len;
1326
		loads+=len;
1325
	}while(len==1024);
1327
	}while(len==1024);
1326
	return loads;
1328
	return loads;
1327
}
1329
}
1328
 
1330
 
1329
unsigned int EntryPoint()
1331
unsigned int EntryPoint()
1330
{
1332
{
1331
ITOK btok;
1333
ITOK btok;
1332
int bb=tk_id;
1334
int bb=tk_id;
1333
unsigned char bufmain[]="main";
1335
unsigned char bufmain[]="main";
1334
unsigned char buf2[]="__startupproc";
1336
unsigned char buf2[]="__startupproc";
1335
unsigned char *buf;
1337
unsigned char *buf;
1336
	if(comfile==file_com)return startptr;
1338
	if(comfile==file_com)return startptr;
1337
	btok.number=0;
1339
	btok.number=0;
1338
//	if(jumptomain!=CALL_NONE||(comfile==file_w32&&dllflag))buf=buf2;
1340
//	if(jumptomain!=CALL_NONE||(comfile==file_w32&&dllflag))buf=buf2;
1339
//	else buf=bufmain;
1341
//	else buf=bufmain;
1340
 
1342
 
1341
	if(jumptomain==CALL_NONE){
1343
	if(jumptomain==CALL_NONE){
1342
		if(useDOS4GW)buf=buf2;
1344
		if(useDOS4GW)buf=buf2;
1343
		else buf=bufmain;
1345
		else buf=bufmain;
1344
	}
1346
	}
1345
	else buf=buf2;
1347
	else buf=buf2;
1346
 
1348
 
1347
	searchtree(&btok,&bb,buf);
1349
	searchtree(&btok,&bb,buf);
1348
	if(bb==tk_id){
1350
	if(bb==tk_id){
1349
		if(comfile==file_w32&&dllflag)return 0xffffffff;
1351
		if(comfile==file_w32&&dllflag)return 0xffffffff;
1350
		printf("Error! Entry point '%s' is not found.\n",buf);
1352
		printf("Error! Entry point '%s' is not found.\n",buf);
1351
		exit(e_entrynotfound);
1353
		exit(e_entrynotfound);
1352
	}
1354
	}
1353
	return btok.number;
1355
	return btok.number;
1354
}
1356
}
1355
 
1357
 
1356
void MakeExeHeader(EXE_DOS_HEADER *exeheader)
1358
void MakeExeHeader(EXE_DOS_HEADER *exeheader)
1357
{
1359
{
1358
long paragraphsrequired;
1360
long paragraphsrequired;
1359
unsigned short count,i;
1361
unsigned short count,i;
1360
int pointstart;
1362
int pointstart;
1361
	exeheader->sign=0x5a4D;				 // MZ
1363
	exeheader->sign=0x5a4D;				 // MZ
1362
//	if(modelmem==TINY&&comfile==file_exe)pointstart=0x100;
1364
//	if(modelmem==TINY&&comfile==file_exe)pointstart=0x100;
1363
/*	else*/ pointstart=EntryPoint();
1365
/*	else*/ pointstart=EntryPoint();
1364
	count=(unsigned short)(runfilesize%512);
1366
	count=(unsigned short)(runfilesize%512);
1365
	i=(unsigned short)(runfilesize/512);
1367
	i=(unsigned short)(runfilesize/512);
1366
	exeheader->numlastbyte=count;
1368
	exeheader->numlastbyte=count;
1367
	exeheader->numpage=(unsigned short)(count==0?i:i+1);
1369
	exeheader->numpage=(unsigned short)(count==0?i:i+1);
1368
	exeheader->headsize=2; 		// size of header in paragraphs (2 paragraphs)
1370
	exeheader->headsize=2; 		// size of header in paragraphs (2 paragraphs)
1369
	exeheader->initIP=(unsigned short)pointstart;	 // IP at entry (0x0000)
1371
	exeheader->initIP=(unsigned short)pointstart;	 // IP at entry (0x0000)
1370
	paragraphsrequired=(outptr+outptrdata+postsize+stacksize+15)/16;
1372
	paragraphsrequired=(outptr+outptrdata+postsize+stacksize+15)/16;
1371
	if(modelmem==TINY&&comfile==file_exe){
1373
	if(modelmem==TINY&&comfile==file_exe){
1372
		exeheader->initSS=0xFFF0; 		 // displacement of SS
1374
		exeheader->initSS=0xFFF0; 		 // displacement of SS
1373
		exeheader->initSP=0xFFFE; // intial value of SP
1375
		exeheader->initSP=0xFFFE; // intial value of SP
1374
		exeheader->initCS=0xfff0;						 // displacement of CS (0x0000)
1376
		exeheader->initCS=0xfff0;						 // displacement of CS (0x0000)
1375
		if(!resizemem){
1377
		if(!resizemem){
1376
			exeheader->minmem=0xfff;	// min-paragraphs
1378
			exeheader->minmem=0xfff;	// min-paragraphs
1377
			exeheader->maxmem=0xffff;	// max-paragraphs
1379
			exeheader->maxmem=0xffff;	// max-paragraphs
1378
		}
1380
		}
1379
		else{
1381
		else{
1380
			paragraphsrequired-=0x10;
1382
			paragraphsrequired-=0x10;
1381
			exeheader->initSP=(unsigned short)(paragraphsrequired*16); // intial value of SP
1383
			exeheader->initSP=(unsigned short)(paragraphsrequired*16); // intial value of SP
1382
			exeheader->minmem=(unsigned short)paragraphsrequired;	// min-paragraphs
1384
			exeheader->minmem=(unsigned short)paragraphsrequired;	// min-paragraphs
1383
			exeheader->maxmem=(unsigned short)paragraphsrequired;	// max-paragraphs
1385
			exeheader->maxmem=(unsigned short)paragraphsrequired;	// max-paragraphs
1384
		}
1386
		}
1385
	}
1387
	}
1386
	else if(comfile==file_d32){
1388
	else if(comfile==file_d32){
1387
		exeheader->initSP=(unsigned short)stacksize; // intial value of SP
1389
		exeheader->initSP=(unsigned short)stacksize; // intial value of SP
1388
		exeheader->initSS=(unsigned short)((outptr+postsize+15)/16); // displacement of SS
1390
		exeheader->initSS=(unsigned short)((outptr+postsize+15)/16); // displacement of SS
1389
		exeheader->initCS=(unsigned short)((pointstart/65536)*4096);
1391
		exeheader->initCS=(unsigned short)((pointstart/65536)*4096);
1390
		if(resizemem){
1392
		if(resizemem){
1391
			exeheader->minmem=(unsigned short)paragraphsrequired;	// min-paragraphs
1393
			exeheader->minmem=(unsigned short)paragraphsrequired;	// min-paragraphs
1392
			exeheader->maxmem=(unsigned short)paragraphsrequired;	// max-paragraphs
1394
			exeheader->maxmem=(unsigned short)paragraphsrequired;	// max-paragraphs
1393
		}
1395
		}
1394
		else exeheader->maxmem=(unsigned short)0xFFFF;	// max-paragraphs
1396
		else exeheader->maxmem=(unsigned short)0xFFFF;	// max-paragraphs
1395
	}
1397
	}
1396
	else{
1398
	else{
1397
		exeheader->initSS=(unsigned short)(outptr/16); 		 // displacement of SS
1399
		exeheader->initSS=(unsigned short)(outptr/16); 		 // displacement of SS
1398
		exeheader->initSP=(unsigned short)(outptrdata+postsize+stacksize); // intial value of SP
1400
		exeheader->initSP=(unsigned short)(outptrdata+postsize+stacksize); // intial value of SP
1399
		exeheader->minmem=(unsigned short)paragraphsrequired;	// min-paragraphs
1401
		exeheader->minmem=(unsigned short)paragraphsrequired;	// min-paragraphs
1400
		exeheader->maxmem=(unsigned short)paragraphsrequired;	// max-paragraphs
1402
		exeheader->maxmem=(unsigned short)paragraphsrequired;	// max-paragraphs
1401
	}
1403
	}
1402
	exeheader->ofsreloc=0x1c;						 // offset of first relocation item (0x0000)
1404
	exeheader->ofsreloc=0x1c;						 // offset of first relocation item (0x0000)
1403
}
1405
}
1404
 
1406
 
1405
void startsymbiosys(char *symfile)
1407
void startsymbiosys(char *symfile)
1406
{
1408
{
1407
unsigned int size;
1409
unsigned int size;
1408
int filehandle;
1410
int filehandle;
1409
long filesize;
1411
long filesize;
1410
	outptr=startptr;
1412
	outptr=startptr;
1411
	if((filehandle=open(symfile,O_BINARY|O_RDONLY))==-1){;
1413
	if((filehandle=open(symfile,O_BINARY|O_RDONLY))==-1){;
1412
		ErrOpenFile(symfile);
1414
		ErrOpenFile(symfile);
1413
		exit(e_symbioerror);
1415
		exit(e_symbioerror);
1414
	}
1416
	}
1415
	if((filesize=getfilelen(filehandle))!=-1L){
1417
	if((filesize=getfilelen(filehandle))!=-1L){
1416
		if(filesize+outptr
1418
		if(filesize+outptr
1417
			size=filesize;
1419
			size=filesize;
1418
			if((unsigned int)read(filehandle,output+outptr,size)!=size){
1420
			if((unsigned int)read(filehandle,output+outptr,size)!=size){
1419
				close(filehandle);
1421
				close(filehandle);
1420
				puts("Error reading symbio COM file.");
1422
				puts("Error reading symbio COM file.");
1421
				exit(e_symbioerror);
1423
				exit(e_symbioerror);
1422
			}
1424
			}
1423
			outptr+=size;
1425
			outptr+=size;
1424
		}
1426
		}
1425
		else{
1427
		else{
1426
			puts("Symbio COM file is too large.");
1428
			puts("Symbio COM file is too large.");
1427
			exit(e_symbioerror);
1429
			exit(e_symbioerror);
1428
		}
1430
		}
1429
	}
1431
	}
1430
	else{
1432
	else{
1431
		puts("Unable to determine symbio COM file size.");
1433
		puts("Unable to determine symbio COM file size.");
1432
		exit(e_symbioerror);
1434
		exit(e_symbioerror);
1433
	}
1435
	}
1434
	close(filehandle);
1436
	close(filehandle);
1435
	outptrdata=outptr;
1437
	outptrdata=outptr;
1436
	outputcodestart=outptr-startptr;
1438
	outputcodestart=outptr-startptr;
1437
	addconsttotree("__comsymbios",TRUE);
1439
	addconsttotree("__comsymbios",TRUE);
1438
}
1440
}
1439
 
1441
 
1440
void BadCommandLine(char *str)
1442
void BadCommandLine(char *str)
1441
{
1443
{
1442
	printf("Unknown or bad command line option '%s'.\n",str);
1444
	printf("Unknown or bad command line option '%s'.\n",str);
1443
//					PrintInfo(usage);
1445
//					PrintInfo(usage);
1444
	exit(e_unknowncommandline);
1446
	exit(e_unknowncommandline);
1445
}
1447
}
1446
 
1448
 
1447
void warnunused(struct idrec *ptr)
1449
void warnunused(struct idrec *ptr)
1448
{
1450
{
1449
//static count=0;
1451
//static count=0;
1450
	if(ptr!=NULL){
1452
	if(ptr!=NULL){
1451
		if(ptr->count==0&&startupfile!=ptr->file){
1453
		if(ptr->count==0&&startupfile!=ptr->file){
1452
			linenumber=ptr->line;
1454
			linenumber=ptr->line;
1453
			currentfileinfo=ptr->file;
1455
			currentfileinfo=ptr->file;
1454
			int i=0;
1456
			int i=0;
1455
			switch(ptr->rectok){
1457
			switch(ptr->rectok){
1456
				case tk_proc:
1458
				case tk_proc:
1457
					if(ptr->recsegm!=NOT_DYNAMIC||strcmp(ptr->recid,mesmain)==0)break;
1459
					if(ptr->recsegm!=NOT_DYNAMIC||strcmp(ptr->recid,mesmain)==0)break;
1458
					i++;
1460
					i++;
1459
				case tk_structvar:
1461
				case tk_structvar:
1460
					i++;
1462
					i++;
1461
				case tk_charvar:
1463
				case tk_charvar:
1462
				case tk_bytevar:
1464
				case tk_bytevar:
1463
				case tk_intvar:
1465
				case tk_intvar:
1464
				case tk_wordvar:
1466
				case tk_wordvar:
1465
				case tk_longvar:
1467
				case tk_longvar:
1466
				case tk_dwordvar:
1468
				case tk_dwordvar:
1467
				case tk_floatvar:
1469
				case tk_floatvar:
1468
				case tk_pointer:
1470
				case tk_pointer:
1469
				case tk_qword:
1471
				case tk_qword:
1470
				case tk_double:
1472
				case tk_double:
1471
					if(i<=1&&(ptr->recpost==DYNAMIC_VAR||ptr->recpost==DYNAMIC_POST))break;
1473
					if(i<=1&&(ptr->recpost==DYNAMIC_VAR||ptr->recpost==DYNAMIC_POST))break;
1472
					warningnotused(ptr->recid,i);
1474
					warningnotused(ptr->recid,i);
1473
					break;
1475
					break;
1474
			}
1476
			}
1475
		}
1477
		}
1476
		warnunused(ptr ->left);
1478
		warnunused(ptr ->left);
1477
		warnunused(ptr ->right);
1479
		warnunused(ptr ->right);
1478
	}
1480
	}
1479
}
1481
}
1480
 
1482
 
1481
void WarnUnusedVar()//ïðåäóïðåæäåíèÿ î íåèñïîëüçîâàííûõ ïðîöåäóðàõ è ïåðåìåííûõ
1483
void WarnUnusedVar()//ïðåäóïðåæäåíèÿ î íåèñïîëüçîâàííûõ ïðîöåäóðàõ è ïåðåìåííûõ
1482
{
1484
{
1483
	warnunused(treestart);
1485
	warnunused(treestart);
1484
	for(unsigned int i=0;istlist);
1486
	for(unsigned int i=0;istlist);
1485
}
1487
}
1486
 
1488
 
1487
void addinitvar()
1489
void addinitvar()
1488
{
1490
{
1489
unsigned int i;
1491
unsigned int i;
1490
	if(numfloatconst){	//âñòàâèòü êîíñòàíòû float è ïðèâÿçàòü èõ
1492
	if(numfloatconst){	//âñòàâèòü êîíñòàíòû float è ïðèâÿçàòü èõ
1491
		if(alignword||optimizespeed)AlignCD(DS,chip>5?16:4);
1493
		if(alignword||optimizespeed)AlignCD(DS,chip>5?16:4);
1492
		for(i=0;i
1494
		for(i=0;i
1493
			if((postbuf+i)->type==POST_FLOATNUM){
1495
			if((postbuf+i)->type==POST_FLOATNUM){
1494
				if(am32)*(unsigned long *)&output[(postbuf+i)->loc]=outptrdata+(postbuf+i)->num;
1496
				if(am32)*(unsigned long *)&output[(postbuf+i)->loc]=outptrdata+(postbuf+i)->num;
1495
				else *(unsigned short *)&output[(postbuf+i)->loc]=(unsigned short)(outptrdata+(postbuf+i)->num);
1497
				else *(unsigned short *)&output[(postbuf+i)->loc]=(unsigned short)(outptrdata+(postbuf+i)->num);
1496
				if(FixUp)(postbuf+i)->type=FIX_VAR32;
1498
				if(FixUp)(postbuf+i)->type=FIX_VAR32;
1497
				else killpost(i--);
1499
				else killpost(i--);
1498
			}
1500
			}
1499
		}
1501
		}
1500
		for(i=0;i
1502
		for(i=0;i
1501
			if(dbg&2){
1503
			if(dbg&2){
1502
				if((floatnum+i)->type==tk_float)sprintf((char *)string,"const float %f",(floatnum+i)->fnum);
1504
				if((floatnum+i)->type==tk_float)sprintf((char *)string,"const float %f",(floatnum+i)->fnum);
1503
				else sprintf((char *)string,"const double %f",(floatnum+i)->dnum);
1505
				else sprintf((char *)string,"const double %f",(floatnum+i)->dnum);
1504
				AddDataNullLine(4,(char *)string);
1506
				AddDataNullLine(4,(char *)string);
1505
			}
1507
			}
1506
			outdwordd((floatnum+i)->num[0]);
1508
			outdwordd((floatnum+i)->num[0]);
1507
			if((floatnum+i)->type!=tk_float){
1509
			if((floatnum+i)->type!=tk_float){
1508
				outdwordd((floatnum+i)->num[1]);
1510
				outdwordd((floatnum+i)->num[1]);
1509
				datasize+=4;
1511
				datasize+=4;
1510
			}
1512
			}
1511
			datasize+=4;
1513
			datasize+=4;
1512
		}
1514
		}
1513
		free(floatnum);
1515
		free(floatnum);
1514
		numfloatconst=0;
1516
		numfloatconst=0;
1515
		floatnum=NULL;
1517
		floatnum=NULL;
1516
	}
1518
	}
1517
	for(i=0;i<(unsigned int)numswtable;i++){	//ñîçäàòü è âñòàâèòü òàáëèöû switch
1519
	for(i=0;i<(unsigned int)numswtable;i++){	//ñîçäàòü è âñòàâèòü òàáëèöû switch
1518
		int j;
1520
		int j;
1519
		FSWI *swt=swtables+i;
1521
		FSWI *swt=swtables+i;
1520
		if(alignword)AlignCD(DS,swt->type);
1522
		if(alignword)AlignCD(DS,swt->type);
1521
		if(dbg&2)AddDataNullLine((char)swt->type,"switch table address");
1523
		if(dbg&2)AddDataNullLine((char)swt->type,"switch table address");
1522
		if(am32==FALSE){	//âñòàâèòü â êîä àäðåñ òàáëèöû
1524
		if(am32==FALSE){	//âñòàâèòü â êîä àäðåñ òàáëèöû
1523
			*(unsigned short *)&output[swt->ptb]=(unsigned short)outptrdata;
1525
			*(unsigned short *)&output[swt->ptb]=(unsigned short)outptrdata;
1524
		}
1526
		}
1525
		else *(unsigned long *)&output[swt->ptb]=outptrdata;
1527
		else *(unsigned long *)&output[swt->ptb]=outptrdata;
1526
		unsigned char oam32=am32;
1528
		unsigned char oam32=am32;
1527
		am32=(unsigned char)(swt->type/2-1);
1529
		am32=(unsigned char)(swt->type/2-1);
1528
 
1530
 
1529
		unsigned long val=swt->defal;
1531
		unsigned long val=swt->defal;
1530
		int oline=outptrdata;
1532
		int oline=outptrdata;
1531
		for(j=0;jsizetab;j++){	//çàïîëíèòü òàáëèöó çíà÷åíèÿìè ïî óìîë÷àíèþ
1533
		for(j=0;jsizetab;j++){	//çàïîëíèòü òàáëèöó çíà÷åíèÿìè ïî óìîë÷àíèþ
1532
//			if((swt->info+jj)->type==singlcase)
1534
//			if((swt->info+jj)->type==singlcase)
1533
			AddReloc(DS);
1535
			AddReloc(DS);
1534
			if(am32)outdwordd(val);
1536
			if(am32)outdwordd(val);
1535
			else outwordd(val);
1537
			else outwordd(val);
1536
		}
1538
		}
1537
		if(swt->mode==2){
1539
		if(swt->mode==2){
1538
			if(dbg&2)AddDataNullLine((char)swt->razr,"switch table value");
1540
			if(dbg&2)AddDataNullLine((char)swt->razr,"switch table value");
1539
			if(oam32==FALSE){	//âñòàâèòü â êîä àäðåñ òàáëèöû
1541
			if(oam32==FALSE){	//âñòàâèòü â êîä àäðåñ òàáëèöû
1540
				*(unsigned short *)&output[swt->ptv]=(unsigned short)outptrdata;
1542
				*(unsigned short *)&output[swt->ptv]=(unsigned short)outptrdata;
1541
			}
1543
			}
1542
			else *(unsigned long *)&output[swt->ptv]=outptrdata;
1544
			else *(unsigned long *)&output[swt->ptv]=outptrdata;
1543
		}
1545
		}
1544
		int ii=0;	//ñ÷åò÷èê case
1546
		int ii=0;	//ñ÷åò÷èê case
1545
		for(int jj=0;jjnumcase;jj++){
1547
		for(int jj=0;jjnumcase;jj++){
1546
			j=(swt->info+jj)->value;	//çíà÷åíèå
1548
			j=(swt->info+jj)->value;	//çíà÷åíèå
1547
			val=(swt->info+jj)->postcase;
1549
			val=(swt->info+jj)->postcase;
1548
			if((swt->info+jj)->type==singlcase){
1550
			if((swt->info+jj)->type==singlcase){
1549
				if(swt->mode==1){
1551
				if(swt->mode==1){
1550
					if(am32==FALSE)*(unsigned short *)&outputdata[oline+j*2]=(unsigned short)val;
1552
					if(am32==FALSE)*(unsigned short *)&outputdata[oline+j*2]=(unsigned short)val;
1551
					else *(unsigned long *)&outputdata[oline+j*4]=val;
1553
					else *(unsigned long *)&outputdata[oline+j*4]=val;
1552
				}
1554
				}
1553
				else{
1555
				else{
1554
					if(am32==FALSE)*(unsigned short *)&outputdata[oline+ii*2]=(unsigned short)val;
1556
					if(am32==FALSE)*(unsigned short *)&outputdata[oline+ii*2]=(unsigned short)val;
1555
					else *(unsigned long *)&outputdata[oline+ii*4]=val;
1557
					else *(unsigned long *)&outputdata[oline+ii*4]=val;
1556
					switch(swt->razr){
1558
					switch(swt->razr){
1557
						case r8: opd(j); break;
1559
						case r8: opd(j); break;
1558
						case r16: outwordd(j); break;
1560
						case r16: outwordd(j); break;
1559
						case r32: outdwordd(j); break;
1561
						case r32: outdwordd(j); break;
1560
					}
1562
					}
1561
					ii++;
1563
					ii++;
1562
				}
1564
				}
1563
			}
1565
			}
1564
			else{
1566
			else{
1565
				jj++;
1567
				jj++;
1566
				for(;(unsigned int)j<=(swt->info+jj)->value;j++){
1568
				for(;(unsigned int)j<=(swt->info+jj)->value;j++){
1567
					if(swt->mode==1){
1569
					if(swt->mode==1){
1568
						if(am32==FALSE)*(unsigned short *)&outputdata[oline+j*2]=(unsigned short)val;
1570
						if(am32==FALSE)*(unsigned short *)&outputdata[oline+j*2]=(unsigned short)val;
1569
						else *(unsigned long *)&outputdata[oline+j*4]=val;
1571
						else *(unsigned long *)&outputdata[oline+j*4]=val;
1570
					}
1572
					}
1571
					else{
1573
					else{
1572
						if(am32==FALSE)*(unsigned short *)&outputdata[oline+ii*2]=(unsigned short)val;
1574
						if(am32==FALSE)*(unsigned short *)&outputdata[oline+ii*2]=(unsigned short)val;
1573
						else *(unsigned long *)&outputdata[oline+ii*4]=val;
1575
						else *(unsigned long *)&outputdata[oline+ii*4]=val;
1574
						switch(swt->razr){
1576
						switch(swt->razr){
1575
							case r8: opd(j); break;
1577
							case r8: opd(j); break;
1576
							case r16: outwordd(j); break;
1578
							case r16: outwordd(j); break;
1577
							case r32: outdwordd(j); break;
1579
							case r32: outdwordd(j); break;
1578
						}
1580
						}
1579
						ii++;
1581
						ii++;
1580
					}
1582
					}
1581
				}
1583
				}
1582
			}
1584
			}
1583
		}
1585
		}
1584
		am32=oam32;
1586
		am32=oam32;
1585
		free(swt->info);
1587
		free(swt->info);
1586
	}
1588
	}
1587
	if(numswtable){
1589
	if(numswtable){
1588
		free(swtables);
1590
		free(swtables);
1589
		numswtable=0;
1591
		numswtable=0;
1590
	}
1592
	}
1591
 
1593
 
1592
	for(i=0;i
1594
	for(i=0;i
1593
		if((postbuf+i)->type==DIN_VAR||(postbuf+i)->type==DIN_VAR32){
1595
		if((postbuf+i)->type==DIN_VAR||(postbuf+i)->type==DIN_VAR32){
1594
			idrec *ptr=(idrec *)(postbuf+i)->num;
1596
			idrec *ptr=(idrec *)(postbuf+i)->num;
1595
//			printf("post=%u num=%08X %s\n",ptr->recpost,ptr->recnumber,ptr->recid);
1597
//			printf("post=%u num=%08X %s\n",ptr->recpost,ptr->recnumber,ptr->recid);
1596
			if(ptr->recpost==USED_DIN_VAR)setdindata(ptr,i);
1598
			if(ptr->recpost==USED_DIN_VAR)setdindata(ptr,i);
1597
			else{
1599
			else{
1598
				if((postbuf+i)->type==DIN_VAR){
1600
				if((postbuf+i)->type==DIN_VAR){
1599
					*(unsigned short *)&output[(postbuf+i)->loc]+=(unsigned short)(ptr->recnumber);
1601
					*(unsigned short *)&output[(postbuf+i)->loc]+=(unsigned short)(ptr->recnumber);
1600
				}
1602
				}
1601
				else{
1603
				else{
1602
//					printf("loc=%08X num=%08X\n",*(unsigned long *)&output[(postbuf+i)->loc],ptr->recnumber);
1604
//					printf("loc=%08X num=%08X\n",*(unsigned long *)&output[(postbuf+i)->loc],ptr->recnumber);
1603
					*(unsigned long *)&output[(postbuf+i)->loc]+=ptr->recnumber;
1605
					*(unsigned long *)&output[(postbuf+i)->loc]+=ptr->recnumber;
1604
				}
1606
				}
1605
			}
1607
			}
1606
			if(FixUp)(postbuf+i)->type=(unsigned short)((postbuf+i)->type==DIN_VAR?FIX_VAR:FIX_VAR32);
1608
			if(FixUp)(postbuf+i)->type=(unsigned short)((postbuf+i)->type==DIN_VAR?FIX_VAR:FIX_VAR32);
1607
			else killpost(i--);
1609
			else killpost(i--);
1608
		}
1610
		}
1609
	}
1611
	}
1610
	dopoststrings();
1612
	dopoststrings();
1611
}
1613
}
1612
 
1614
 
1613
void setdindata(idrec *ptr,int i)
1615
void setdindata(idrec *ptr,int i)
1614
{
1616
{
1615
unsigned char *oldinput;
1617
unsigned char *oldinput;
1616
unsigned int oldinptr,oldendinptr;
1618
unsigned int oldinptr,oldendinptr;
1617
unsigned char bcha;
1619
unsigned char bcha;
1618
unsigned int oline,ofile;
1620
unsigned int oline,ofile;
1619
char *ostartline;
1621
char *ostartline;
1620
	if(alignword){
1622
	if(alignword){
1621
		if(ptr->rectok==tk_structvar)alignersize+=AlignCD(DS,2);	//âûðîâíÿòü
1623
		if(ptr->rectok==tk_structvar)alignersize+=AlignCD(DS,2);	//âûðîâíÿòü
1622
		else alignersize+=AlignCD(DS,GetVarSize(ptr->rectok));
1624
		else alignersize+=AlignCD(DS,GetVarSize(ptr->rectok));
1623
	}
1625
	}
1624
//	printf("loc=%08X out=%08X num=%08X\n",*(unsigned long *)&output[(postbuf+i)->loc],outptrdata,ptr->recnumber);
1626
//	printf("loc=%08X out=%08X num=%08X\n",*(unsigned long *)&output[(postbuf+i)->loc],outptrdata,ptr->recnumber);
1625
	if((postbuf+i)->type==DIN_VAR)*(unsigned short *)&output[(postbuf+i)->loc]+=(unsigned short)(outptrdata);
1627
	if((postbuf+i)->type==DIN_VAR)*(unsigned short *)&output[(postbuf+i)->loc]+=(unsigned short)(outptrdata);
1626
	else *(unsigned long *)&output[(postbuf+i)->loc]+=outptrdata;
1628
	else *(unsigned long *)&output[(postbuf+i)->loc]+=outptrdata;
1627
	ptr->recpost=0;
1629
	ptr->recpost=0;
1628
	ptr->recnumber+=outptrdata;
1630
	ptr->recnumber+=outptrdata;
1629
	oline=linenum2;
1631
	oline=linenum2;
1630
	ofile=currentfileinfo;
1632
	ofile=currentfileinfo;
1631
	oldinput=input;
1633
	oldinput=input;
1632
	oldinptr=inptr2;
1634
	oldinptr=inptr2;
1633
	bcha=cha2;
1635
	bcha=cha2;
1634
	oldendinptr=endinptr;
1636
	oldendinptr=endinptr;
1635
	input=(unsigned char *)ptr->sbuf;
1637
	input=(unsigned char *)ptr->sbuf;
1636
	inptr2=1;
1638
	inptr2=1;
1637
	ostartline=startline;
1639
	ostartline=startline;
1638
	startline=(char*)input;
1640
	startline=(char*)input;
1639
	cha2=input[0];
1641
	cha2=input[0];
1640
	linenum2=ptr->line;
1642
	linenum2=ptr->line;
1641
	currentfileinfo=ptr->file;
1643
	currentfileinfo=ptr->file;
1642
	endinptr=strlen((char *)input);
1644
	endinptr=strlen((char *)input);
1643
	endinput=startline+endinptr;
1645
	endinput=startline+endinptr;
1644
	endoffile=0;
1646
	endoffile=0;
1645
	tok=ptr->rectok;
1647
	tok=ptr->rectok;
1646
	if(tok==tk_structvar)datasize+=initstructvar((structteg *)ptr->newid,ptr->recrm);
1648
	if(tok==tk_structvar)datasize+=initstructvar((structteg *)ptr->newid,ptr->recrm);
1647
	else{
1649
	else{
1648
long type,ssize;
1650
long type,ssize;
1649
unsigned char typev;
1651
unsigned char typev;
1650
		if(tok>=tk_charvar&&tok<=tk_doublevar){
1652
		if(tok>=tk_charvar&&tok<=tk_doublevar){
1651
			type=tok-(tk_charvar-tk_char);
1653
			type=tok-(tk_charvar-tk_char);
1652
			typev=variable;
1654
			typev=variable;
1653
			ssize=typesize(type);
1655
			ssize=typesize(type);
1654
		}
1656
		}
1655
		else if(tok==tk_pointer){
1657
		else if(tok==tk_pointer){
1656
			typev=pointer;
1658
			typev=pointer;
1657
			type=itok.type;
1659
			type=itok.type;
1658
			if(am32==FALSE&&((itok.flag&f_far)==0))ssize=2;
1660
			if(am32==FALSE&&((itok.flag&f_far)==0))ssize=2;
1659
			else ssize=4;
1661
			else ssize=4;
1660
		}
1662
		}
1661
		datasize+=initglobalvar(type,ptr->recsize/ssize,ssize,typev);
1663
		datasize+=initglobalvar(type,ptr->recsize/ssize,ssize,typev);
1662
	}
1664
	}
1663
	free(input);
1665
	free(input);
1664
	linenum2=oline;
1666
	linenum2=oline;
1665
	currentfileinfo=ofile;
1667
	currentfileinfo=ofile;
1666
	input=oldinput;
1668
	input=oldinput;
1667
	inptr2=oldinptr;
1669
	inptr2=oldinptr;
1668
	cha2=bcha;
1670
	cha2=bcha;
1669
	endinptr=oldendinptr;
1671
	endinptr=oldendinptr;
1670
	endoffile=0;
1672
	endoffile=0;
1671
	startline=ostartline;
1673
	startline=ostartline;
1672
}
1674
}
1673
 
1675
 
1674
FILE *CreateOutPut(char *ext,char *mode)
1676
FILE *CreateOutPut(char *ext,char *mode)
1675
{
1677
{
1676
char buf[256];
1678
char buf[256];
1677
FILE *diskout;
1679
FILE *diskout;
1678
	sprintf(buf,"%s.%s",rawfilename,ext);
1680
	sprintf(buf,"%s.%s",rawfilename,ext);
1679
	if((diskout=fopen(buf,mode))==NULL){
1681
	if((diskout=fopen(buf,mode))==NULL){
1680
		ErrOpenFile(buf);
1682
		ErrOpenFile(buf);
1681
		exit(e_notcreateoutput);
1683
		exit(e_notcreateoutput);
1682
	}
1684
	}
1683
	return diskout;
1685
	return diskout;
1684
}
1686
}
1685
 
1687
 
1686
int numundefclassproc=0;
1688
int numundefclassproc=0;
1687
idrec **undefclassproc;
1689
idrec **undefclassproc;
1688
 
1690
 
1689
void AddUndefClassProc()
1691
void AddUndefClassProc()
1690
{
1692
{
1691
	if(numundefclassproc==0)undefclassproc=(idrec **)MALLOC(sizeof(idrec **));
1693
	if(numundefclassproc==0)undefclassproc=(idrec **)MALLOC(sizeof(idrec **));
1692
	else undefclassproc=(idrec **)REALLOC(undefclassproc,sizeof(idrec **)*(numundefclassproc+1));
1694
	else undefclassproc=(idrec **)REALLOC(undefclassproc,sizeof(idrec **)*(numundefclassproc+1));
1693
	undefclassproc[numundefclassproc]=itok.rec;
1695
	undefclassproc[numundefclassproc]=itok.rec;
1694
	numundefclassproc++;
1696
	numundefclassproc++;
1695
}
1697
}
1696
 
1698
 
1697
void CheckUndefClassProc()
1699
void CheckUndefClassProc()
1698
{
1700
{
1699
	for(int i=0;i
1701
	for(int i=0;i
1700
		idrec *ptr=undefclassproc[i];
1702
		idrec *ptr=undefclassproc[i];
1701
		if(ptr->rectok==tk_undefproc){
1703
		if(ptr->rectok==tk_undefproc){
1702
			currentfileinfo=ptr->file;
1704
			currentfileinfo=ptr->file;
1703
			linenumber=ptr->line;
1705
			linenumber=ptr->line;
1704
			thisundefined(ptr->recid);
1706
			thisundefined(ptr->recid);
1705
		}
1707
		}
1706
	}
1708
	}
1707
}
1709
}
1708
>
1710
>
1709
>
1711
>
1710
>
1712
>
1711
>
1713
>
1712
>
1714
>
1713
>
1715
>
1714
>
1716
>
1715
>
1717
>
1716
>
1718
>
1717
>
1719
>
1718
>
1720
>
1719
>
1721
>
1720
>
1722
>
1721
>
1723
>
1722
>
1724
>
1723
>
1725
>
1724
>
1726
>
1725
>
1727
>
1726
>
1728
>
1727
>
1729
>
1728
errlate:
1730
errlate:
1729
>
1731
>
1730
>
1732
>
1731
>
1733
>
1732
>
1734
>
1733
>
1735
>
1734
>
1736
>
1735
>
1737
>
1736
>
1738
>
1737
>
1739
>