Rev 6618 | Rev 7545 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6446 | GerdtR | 1 | #define _MAIN_ |
2 | |||
3 | #ifdef _UNIX_ |
||
6447 | GerdtR | 4 | #define DIV_PATH ':' //делитель путей в переменной окружения PATH |
5 | #define DIV_FOLD '/' //этим символом разделяются папки в пути к файлу |
||
6 | #endif |
||
7 | |||
8 | #ifdef _WIN32_ |
||
6446 | GerdtR | 9 | #define DIV_PATH ';' |
6447 | GerdtR | 10 | #define DIV_FOLD '\\' |
6446 | GerdtR | 11 | #endif |
12 | |||
6447 | GerdtR | 13 | #ifdef _KOS_ |
14 | #define DIV_PATH ';' |
||
15 | #define DIV_FOLD '/' |
||
16 | #endif |
||
17 | |||
6446 | GerdtR | 18 | #include |
6618 | siemargl | 19 | #include |
20 | #include |
||
6446 | GerdtR | 21 | #include |
22 | #include "tok.h" |
||
23 | |||
24 | static char **_Argv; //!!! simplest way to make your own variable |
||
25 | |||
26 | unsigned char compilerstr[]="SPHINX C-- 0.239"; |
||
27 | char *rawfilename; /* file name */ |
||
28 | char *rawext; |
||
29 | LISTCOM *listcom; |
||
30 | EWAR wartype={NULL,NULL},errfile={NULL,NULL}; |
||
31 | int numfindpath=0; |
||
32 | char *findpath[16]; |
||
33 | char modelmem=TINY; |
||
34 | char *stubfile=NULL; |
||
35 | char *winstub=NULL; |
||
36 | FILE *hout=NULL; |
||
37 | char *namestartupfile="startup.h--"; |
||
38 | |||
39 | char outext[4]="com"; |
||
40 | short extflag=TRUE;//расширение можно присвоить |
||
41 | //int scrsize; |
||
42 | unsigned char gwarning=FALSE; |
||
43 | unsigned char sobj=FALSE; |
||
44 | unsigned char usestub=TRUE; |
||
45 | unsigned char dpmistub=FALSE; |
||
46 | short dllflag=FALSE; |
||
47 | static int numstr; |
||
48 | |||
49 | char meinfo[]= |
||
50 | "\nEdition of this version by\n" |
||
51 | " Mishel Sheker\n" |
||
52 | " Fido 2:5021/3.40\n" |
||
53 | " E-Mail sheker@mail.ru\n" |
||
54 | " Russia"; |
||
55 | |||
56 | time_t systime; |
||
57 | struct tm timeptr; |
||
58 | char comsymbios=FALSE; |
||
59 | char fobj=FALSE; //признак генерации obj |
||
60 | unsigned int startptr = 0x100; // start address |
||
61 | unsigned char wconsole=FALSE; //признак генерации консольного приложения windows |
||
62 | unsigned char optstr=FALSE; //оптимизация строковых констант |
||
63 | unsigned char crif=TRUE; //check reply include file |
||
64 | unsigned char idasm=FALSE; //ассемблерные инструкции считать идентификаторами |
||
65 | unsigned char wbss=2; //пост переменные в отдельную секцию |
||
66 | unsigned char use_env=FALSE; //переменная окружения |
||
67 | int numrel=0; //число элементов в таблице перемещений |
||
68 | unsigned char useordinal=FALSE; |
||
69 | unsigned char useDOS4GW=FALSE; |
||
70 | unsigned char clearpost=FALSE; |
||
71 | unsigned char uselea=TRUE; |
||
72 | unsigned char regoverstack=TRUE; |
||
73 | unsigned char shortimport=FALSE; |
||
74 | unsigned char useinline=2; |
||
75 | unsigned char ocoff=FALSE; |
||
76 | unsigned char ESPloc=FALSE; |
||
77 | |||
78 | int startupfile=-1; |
||
79 | int alignproc=8,aligncycle=8; |
||
80 | |||
81 | char *usage[]={ |
||
82 | "USAGE: C-- [options] [FILE_NAME.INI] [SOURCE_FILE_NAME]", |
||
83 | "", |
||
84 | " C-- COMPILER OPTIONS", |
||
85 | "", |
||
86 | " OPTIMIZATION", |
||
87 | "/OC optimize for code size /DE enable temporary expansion variable", |
||
88 | "/OS optimize for speed /OST enable optimization string", |
||
89 | "/ON enable optimization number /AP[=n] align start function", |
||
90 | "/UST use startup code for variables /AC[=n] align start cycles", |
||
91 | #ifdef OPTVARCONST |
||
92 | "/ORV replace variable on constant /OIR skip repeated initializing register", |
||
93 | #else |
||
94 | " /OIR skip repeated initializing register", |
||
95 | #endif |
||
96 | "", |
||
97 | " CODE GENERATION", |
||
98 | "/2 80286 code optimizations /SA=#### start code address", |
||
99 | "/3 80386 code optimizations /AL=## set value insert byte", |
||
100 | "/4 80486 code optimizations /WFA fast call API functions", |
||
101 | "/5 pentium code optimizations /IV initial all variables", |
||
102 | "/A enable address alignment /SUV=#### start address variables", |
||
103 | "/AS[=n] def. alignment in structures /LRS load in registers over stack", |
||
104 | "/UL use 'lea' for adding registers /JS join stack calling functions", |
||
105 | "/BA byte access to array",// /ASP addressing local variable via ESP", |
||
106 | "", |
||
107 | " PREPROCESSOR", |
||
108 | "/IP= |
||
109 | "/D= |
||
110 | "/MIF= |
||
111 | "/SF= |
||
112 | "", |
||
113 | " LINKING", |
||
114 | "/AT insert ATEXIT support block /NS disable stub", |
||
115 | "/ARGC insert parse command line /S=##### set stack size", |
||
116 | "/P insert parse command line /WIB=##### set image base address", |
||
117 | "/C insert CTRL |
||
118 | "/R insert resize memory block /WMB create Windows mono block", |
||
119 | "/ENV insert variable with environ /WS= |
||
120 | "/J0 disable initial jump to main() /WBSS set post data in bss section", |
||
121 | "/J1 initial jump to main() short /WO call API functions on ordinals", |
||
122 | "/J2 initial jump to main() near /CPA clear post area", |
||
123 | "/STUB= |
||
124 | "/DOS4GW file running with DOS4GW /WAF=#### align Windows file (def 512)", |
||
125 | "/STM startup code in main function", |
||
126 | "", |
||
127 | " OUTPUT FILES", |
||
128 | "/TEXE DOS EXE file (model TINY) /D32 EXE file (32bit code for DOS)", |
||
129 | "/EXE DOS EXE file (model SMALL) /W32 EXE for Windows32 GUI", |
||
130 | "/OBJ OBJ output file /W32C EXE for Windows32 console", |
||
131 | "/SOBJ slave OBJ output file /DLL DLL for Windows32", |
||
132 | "/COFF OBJ COFF output file /DBG create debug information", |
||
133 | "/SYM COM file symbiosis /LST create assembly listing", |
||
134 | "/SYS device (SYS) file /B32 32bit binary files", |
||
135 | "/MEOS executable file for MeOS /MAP create function map file", |
||
136 | "/EXT= |
||
137 | "", |
||
138 | " MISCELLANEOUS", |
||
139 | "/HELP /H /? help, this info /WORDS list of C-- reserved words", |
||
140 | "/W enable warning /LAI list of assembler instructions", |
||
141 | "/WF= |
||
142 | "/MER=## set maximum number errors /X disable SPHINX C-- header in output", |
||
143 | "/NW=## disable selected warnings /WE=## selected warning will be error", |
||
144 | //" /SCD split code and date", |
||
145 | NULL}; |
||
146 | |||
147 | char *dir[]={ |
||
148 | "ME", "WORDS", "SYM", "LAI", |
||
149 | |||
150 | "OBJ", "SOBJ", "J0", "J1", "J2", "C", "R", |
||
151 | "P", "X", "EXE", "S", "SYS", "ARGC", "TEXE", |
||
152 | "ROM", "W32", "D32", "W32C", "AT", "WFA", "SA", |
||
153 | "STM", "SUV", "UST", "MIF", "DLL", "DOS4GW","ENV", |
||
154 | "CPA", "WBSS", "MEOS", "SF", "B32", "WIB", "DBG", |
||
155 | |||
156 | "OS", "OC", "A", "0", "1", "2", "3", |
||
157 | "4", "5", "6", "7", "8", "9", "W", |
||
158 | "WF", "DE", |
||
159 | "ON", "IP", "STUB", "NS", "AP", "D", "OST", |
||
160 | "CRI", "IA", "SCD", "AL", "WFU", "IV", |
||
161 | "MER", "WMB", "HELP", "H", "?", "AC", "WS", |
||
162 | "IND", "WO", "NW", "LST", "AS", "UL", "LRS", |
||
163 | "WSI", "WAF", "OIR", "COFF", "JS", "BA", "ASP", |
||
164 | #ifdef OPTVARCONST |
||
165 | "ORV", |
||
166 | #endif |
||
167 | "MAP", "WE", "EXT", NULL}; |
||
168 | |||
169 | enum { |
||
170 | c_me, c_key, c_sym, c_lasm, c_endinfo=c_lasm, |
||
171 | |||
172 | c_obj, c_sobj, c_j0, c_j1, c_j2, c_ctrlc, c_r, |
||
173 | c_p, c_x, c_exe, c_s, c_sys, c_arg, c_texe, |
||
174 | c_rom, c_w32, c_d32, c_w32c, c_at, c_wfa, c_sa, |
||
175 | c_stm, c_suv, c_ust, c_mif, c_dll, c_d4g, c_env, |
||
176 | c_cpa, c_wbss, c_meos, c_sf, c_b32, c_wib, c_dbg, |
||
177 | c_endstart=c_dbg, |
||
178 | |||
179 | c_os, c_oc, c_a, c_0, c_1, c_2, c_3, |
||
180 | c_4, c_5, c_6, c_7, c_8, c_9, c_w, |
||
181 | c_wf, c_de, |
||
182 | c_opnum, c_ip, c_stub, c_ns, c_ap, c_define,c_ost, |
||
183 | c_cri, c_ia, c_scd, c_al, c_wfu, c_iv, |
||
184 | c_mer, c_wmb, c_help, c_h, c_hh, c_ac, c_ws, |
||
185 | c_ind, c_wo, c_nw, c_lst, c_as, c_ul, c_lrs, |
||
186 | c_wsi, c_waf, c_oir, c_coff, c_js, c_ba, c_asp, |
||
187 | #ifdef OPTVARCONST |
||
188 | c_orv, |
||
189 | #endif |
||
190 | c_map, c_we, c_ext, c_end}; |
||
191 | |||
192 | #define NUMEXT 6 //число разрешенных расширений компилируемого файла |
||
193 | char extcompile[NUMEXT][4]={"c--","cmm","c","h--","hmm","h"}; |
||
194 | |||
195 | #ifdef _KOS_ |
||
196 | char __pgmname[256]; |
||
197 | char __cmdline[256]; |
||
198 | #endif |
||
199 | |||
200 | char *bufstr=NULL; //буфер для строк из процедур |
||
201 | int sbufstr=SIZEBUF; //начальный размер этого буфера |
||
202 | |||
203 | void compile(); |
||
204 | void PrintInfo(char **str); |
||
205 | void LoadIni(char *name); |
||
206 | //void CheckNumStr(); |
||
207 | void ListId(int num,unsigned char *list,short *ofs); |
||
208 | void printmemsizes(); |
||
209 | void print8item(char *str); |
||
210 | void doposts(void); |
||
211 | void GetMemExeDat(); |
||
212 | void AddJmpApi(); |
||
213 | void startsymbiosys(char *symfile); |
||
214 | int writeoutput(); |
||
215 | void BadCommandLine(char *str); |
||
216 | void CheckExtenshions(); |
||
217 | void ImportName(char *name); |
||
218 | void WarnUnusedVar();//предупреждения о неиспользованных процедурах и переменных |
||
219 | void MakeExeHeader(EXE_DOS_HEADER *exeheader); |
||
220 | void CheckPageCode(unsigned int ofs); |
||
221 | int MakePE(); |
||
222 | int MakeObj(); |
||
223 | void CheckUndefClassProc(); |
||
7543 | leency | 224 | |
6446 | GerdtR | 225 | /* |
7543 | leency | 226 | |
227 | PAVEL YAKOV |
||
228 | |||
229 | char* strupr(char* s) |
||
230 | { |
||
231 | char* p = s; |
||
232 | while (*p = toupper(*p)) p++; |
||
233 | return s; |
||
234 | } |
||
235 | char* strlwr(char* s) |
||
236 | { |
||
237 | char* p = s; |
||
238 | while (*p = tolower(*p)) p++; |
||
239 | return s; |
||
240 | } |
||
241 | int strnicmp(const char* s1, const char* s2, int len) |
||
242 | { |
||
243 | unsigned char c1,c2; |
||
244 | |||
245 | if(!len) |
||
246 | return 0; |
||
247 | |||
248 | do{ |
||
249 | c1 = *s1++; |
||
250 | c2 = *s2++; |
||
251 | if (!c1||!c2) |
||
252 | break; |
||
253 | if (c1 == c2) |
||