Rev 7668 | Rev 9352 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7668 | Rev 7700 | ||
---|---|---|---|
Line 32... | Line 32... | ||
32 | char *findpath[16]; |
32 | char *findpath[16]; |
33 | char modelmem=TINY; |
33 | char modelmem=TINY; |
34 | char *stubfile=NULL; |
34 | char *stubfile=NULL; |
35 | char *winstub=NULL; |
35 | char *winstub=NULL; |
36 | FILE *hout=NULL; |
36 | FILE *hout=NULL; |
37 | char *namestartupfile="startup.h--"; |
37 | const char *namestartupfile="startup.h--"; |
Line 38... | Line 38... | ||
38 | 38 | ||
39 | char outext[4]="com"; |
39 | char outext[4]="kex"; |
40 | short extflag=TRUE;//ðàñøèðåíèå ìîæíî ïðèñâîèòü |
40 | short extflag=TRUE;//ðàñøèðåíèå ìîæíî ïðèñâîèòü |
41 | //int scrsize; |
41 | //int scrsize; |
42 | unsigned char gwarning=FALSE; |
42 | unsigned char gwarning=FALSE; |
43 | unsigned char sobj=FALSE; |
43 | unsigned char sobj=FALSE; |
Line 76... | Line 76... | ||
76 | unsigned char ESPloc=FALSE; |
76 | unsigned char ESPloc=FALSE; |
Line 77... | Line 77... | ||
77 | 77 | ||
78 | int startupfile=-1; |
78 | int startupfile=-1; |
Line 79... | Line 79... | ||
79 | int alignproc=8,aligncycle=8; |
79 | int alignproc=8,aligncycle=8; |
80 | 80 | ||
81 | char *usage[]={ |
81 | const char *usage[]={ |
82 | "USAGE: C-- [options] [FILE_NAME.INI] [SOURCE_FILE_NAME]", |
82 | "USAGE: C-- [options] [FILE_NAME.INI] [SOURCE_FILE_NAME]", |
83 | "", |
83 | "", |
84 | " C-- COMPILER OPTIONS", |
84 | " C-- COMPILER OPTIONS", |
85 | "", |
85 | "", |
86 | " OPTIMIZATION", |
86 | " OPTIMIZATION", |
87 | "/OC optimize for code size /DE enable temporary expansion variable", |
87 | "-OC optimize for code size -DE enable temporary expansion variable", |
88 | "/OS optimize for speed /OST enable optimization string", |
88 | "-OS optimize for speed -OST enable optimization string", |
89 | "/ON enable optimization number /AP[=n] align start function", |
89 | "-ON enable optimization number -AP[=n] align start function", |
90 | "/UST use startup code for variables /AC[=n] align start cycles", |
90 | "-UST use startup code for variables -AC[=n] align start cycles", |
91 | #ifdef OPTVARCONST |
91 | #ifdef OPTVARCONST |
92 | "/ORV replace variable on constant /OIR skip repeated initializing register", |
92 | "-ORV replace variable on constant -OIR skip repeated initializing register", |
93 | #else |
93 | #else |
94 | " /OIR skip repeated initializing register", |
94 | " -OIR skip repeated initializing register", |
95 | #endif |
95 | #endif |
96 | "", |
96 | "", |
97 | " CODE GENERATION", |
97 | " CODE GENERATION", |
98 | "/2 80286 code optimizations /SA=#### start code address", |
98 | "-2 80286 code optimizations -SA=#### start code address", |
99 | "/3 80386 code optimizations /AL=## set value insert byte", |
99 | "-3 80386 code optimizations -AL=## set value insert byte", |
100 | "/4 80486 code optimizations /WFA fast call API functions", |
100 | "-4 80486 code optimizations -WFA fast call API functions", |
101 | "/5 pentium code optimizations /IV initial all variables", |
101 | "-5 pentium code optimizations -IV initial all variables", |
102 | "/A enable address alignment /SUV=#### start address variables", |
102 | "-A enable address alignment -SUV=#### start address variables", |
103 | "/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", |
104 | "/UL use 'lea' for adding registers /JS join stack calling functions", |
104 | "-UL use 'lea' for adding registers -JS join stack calling functions", |
105 | "/BA byte access to array",// /ASP addressing local variable via ESP", |
105 | "-BA byte access to array",// -ASP addressing local variable via ESP", |
106 | "", |
106 | "", |
107 | " PREPROCESSOR", |
107 | " PREPROCESSOR", |
108 | "/IP= |
108 | "-IP= |
109 | "/D= |
109 | "-D= |
110 | "/MIF= |
110 | "-MIF= |
111 | "/SF= |
111 | "-SF= |
112 | "", |
112 | "", |
113 | " LINKING", |
113 | " LINKING", |
114 | "/AT insert ATEXIT support block /NS disable stub", |
114 | "-AT insert ATEXIT support block -NS disable stub", |
115 | "/ARGC insert parse command line /S=##### set stack size", |
115 | "-ARGC insert parse command line -S=##### set stack size", |
116 | "/P insert parse command line /WIB=##### set image base address", |
116 | "-P insert parse command line -WIB=##### set image base address", |
117 | "/C insert CTRL |
117 | "-C insert CTRL |
118 | "/R insert resize memory block /WMB create Windows mono block", |
118 | "-R insert resize memory block -WMB create Windows mono block", |
119 | "/ENV insert variable with environ /WS= |
119 | "-ENV insert variable with environ -WS= |
120 | "/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", |
121 | "/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", |
122 | "/J2 initial jump to main() near /CPA clear post area", |
122 | "-J2 initial jump to main() near -CPA clear post area", |
123 | "/STUB= |
123 | "-STUB= |
124 | "/DOS4GW file running with DOS4GW /WAF=#### align Windows file (def 512)", |
124 | "-DOS4GW file running with DOS4GW -WAF=#### align Windows file (def 512)", |
125 | "/STM startup code in main function", |
125 | "-STM startup code in main function", |
126 | "", |
126 | "", |
127 | " OUTPUT FILES", |
127 | " OUTPUT FILES", |
128 | "/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)", |
129 | "/EXE DOS EXE file (model SMALL) /W32 EXE for Windows32 GUI", |
129 | "-EXE DOS EXE file (model SMALL) -W32 EXE for Windows32 GUI", |
130 | "/OBJ OBJ output file /W32C EXE for Windows32 console", |
130 | "-OBJ OBJ output file -W32C EXE for Windows32 console", |
131 | "/SOBJ slave OBJ output file /DLL DLL for Windows32", |
131 | "-SOBJ slave OBJ output file -DLL DLL for Windows32", |
132 | "/COFF OBJ COFF output file /DBG create debug information", |
132 | "-COFF OBJ COFF output file -DBG create debug information", |
133 | "/SYM COM file symbiosis /LST create assembly listing", |
133 | "-SYM COM file symbiosis -LST create assembly listing", |
134 | "/SYS device (SYS) file /B32 32bit binary files", |
134 | "-SYS device (SYS) file -B32 32bit binary files", |
135 | "/MEOS executable file for MeOS /MAP create function map file", |
135 | "-MEOS executable file for MeOS -MAP create function map file", |
136 | "/EXT= |
136 | "-EXT= |
137 | "", |
137 | "", |
138 | " MISCELLANEOUS", |
138 | " MISCELLANEOUS", |
139 | "/HELP /H /? help, this info /WORDS list of C-- reserved words", |
139 | "-HELP -H -? help, this info -WORDS list of C-- reserved words", |
140 | "/W enable warning /LAI list of assembler instructions", |
140 | "-W enable warning -LAI list of assembler instructions", |
141 | "/WF= |
141 | "-WF= |
142 | "/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", |
143 | "/NW=## disable selected warnings /WE=## selected warning will be error", |
143 | "-NW=## disable selected warnings -WE=## selected warning will be error", |
Line 144... | Line 144... | ||
144 | //" /SCD split code and date", |
144 | //" -SCD split code and date", |
145 | NULL}; |
145 | NULL}; |
Line 146... | Line 146... | ||
146 | 146 | ||
147 | char *dir[]={ |
147 | const char *dir[]={ |
148 | "ME", "WORDS", "SYM", "LAI", |
148 | "ME", "WORDS", "SYM", "LAI", |
Line 202... | Line 202... | ||
202 | 202 | ||
203 | void compile(); |
203 | void compile(); |
204 | void PrintInfo(char **str); |
204 | void PrintInfo(char **str); |
205 | void LoadIni(char *name); |
205 | void LoadIni(char *name); |
206 | //void CheckNumStr(); |
206 | //void CheckNumStr(); |
207 | void ListId(int num,unsigned char *list,short *ofs); |
207 | void ListId(int num,unsigned char *list,unsigned short *ofs); |
208 | void printmemsizes(); |
208 | void printmemsizes(); |
209 | void print8item(char *str); |
209 | void print8item(char *str); |
210 | void doposts(void); |
210 | void doposts(void); |
211 | void GetMemExeDat(); |
211 | void GetMemExeDat(); |
Line 220... | Line 220... | ||
220 | void CheckPageCode(unsigned int ofs); |
220 | void CheckPageCode(unsigned int ofs); |
221 | int MakePE(); |
221 | int MakePE(); |
222 | int MakeObj(); |
222 | int MakeObj(); |
223 | void CheckUndefClassProc(); |
223 | void CheckUndefClassProc(); |
Line -... | Line 224... | ||
- | 224 | ||
- | 225 | ||
- | 226 | void ListId(int numfirstchar,unsigned char *list,unsigned short *ofs) |
|
- | 227 | { |
|
- | 228 | char buf[40]; |
|
- | 229 | for(int i=0;i |
|
- | 230 | if((short)ofs[i]!=-1){ |
|
- | 231 | if(i<26)buf[0]=(char)('A'+i); |
|
- | 232 | else if(i==26)buf[0]='_'; |
|
- | 233 | else buf[0]=(char)(i-27+'a'); |
|
- | 234 | unsigned char *ii=(unsigned char *)(list+ofs[i]); |
|
- | 235 | while(*(short *)&*ii!=-1){ |
|
- | 236 | ii+=2; |
|
- | 237 | strcpy(buf+1,(char *)ii); |
|
- | 238 | ii+=strlen((char *)ii)+1; |
|
- | 239 | puts(buf); |
|
- | 240 | // CheckNumStr(); |
|
- | 241 | } |
|
- | 242 | } |
|
- | 243 | } |
|
- | 244 | } |
|
224 | 245 | ||
225 | /* |
246 | /* |
226 | void PrintTegList(structteg *tteg) |
247 | void PrintTegList(structteg *tteg) |
227 | { |
248 | { |
228 | if(tteg){ |
249 | if(tteg){ |
Line 263... | Line 284... | ||
263 | } |
284 | } |
264 | rawfilename=getenv("C--"); |
285 | rawfilename=getenv("C--"); |
265 | if(rawfilename!=NULL)IncludePath(rawfilename); |
286 | if(rawfilename!=NULL)IncludePath(rawfilename); |
Line 266... | Line 287... | ||
266 | 287 | ||
267 | rawfilename=rawext=NULL; |
288 | rawfilename=rawext=NULL; |
Line 268... | Line 289... | ||
268 | LoadIni("c--.ini"); |
289 | LoadIni((char *)"c--.ini"); |
269 | 290 | ||
270 | for(count=1;count |
291 | for(count=1;count |
271 | //if(argv[count][0]=='/'||argv[count][0]=='-'){ |
292 | //if(argv[count][0]=='/'||argv[count][0]=='-'){ |
Line 291... | Line 312... | ||
291 | } |
312 | } |
292 | } |
313 | } |
293 | } |
314 | } |
294 | } |
315 | } |
295 | if(rawfilename==NULL){ |
316 | if(rawfilename==NULL){ |
296 | PrintInfo(usage); |
317 | PrintInfo((char **)usage); |
297 | exit( e_noinputspecified ); |
318 | exit( e_noinputspecified ); |
298 | } |
319 | } |
299 | time(&systime); //òåêóùåå âðåìÿ |
320 | time(&systime); //òåêóùåå âðåìÿ |
300 | memcpy(&timeptr,localtime(&systime),sizeof(tm)); |
321 | memcpy(&timeptr,localtime(&systime),sizeof(tm)); |
301 | InitDefineConst(); |
322 | InitDefineConst(); |
Line 313... | Line 334... | ||
313 | } |
334 | } |
314 | if(i==NUMEXT){ |
335 | if(i==NUMEXT){ |
315 | printf("Bad input file extension '%s'.",rawext); |
336 | printf("Bad input file extension '%s'.",rawext); |
316 | exit(e_badinputfilename); |
337 | exit(e_badinputfilename); |
317 | } |
338 | } |
318 | // Add dirname of the input file to include path. |
- | |
319 | char *slash_idx = strrchr((char*)rawfilename, DIV_FOLD); |
- | |
320 | if (slash_idx) { |
- | |
321 | *slash_idx = '\0'; |
- | |
322 | IncludePath((char*)rawfilename); |
- | |
323 | *slash_idx = DIV_FOLD; |
- | |
324 | } |
- | |
325 | } |
339 | } |
Line 326... | Line 340... | ||
326 | 340 | ||
327 | void compile() |
341 | void compile() |
328 | { |
342 | { |
Line 693... | Line 707... | ||
693 | exit( e_ok ); |
707 | exit( e_ok ); |
694 | case c_key: |
708 | case c_key: |
695 | int j,jj; |
709 | int j,jj; |
696 | puts("LIST OF RESERVED IDENTIFIERS:"); |
710 | puts("LIST OF RESERVED IDENTIFIERS:"); |
697 | numstr=1; |
711 | numstr=1; |
698 | ListId(53,id,idofs); |
712 | ListId(53,(unsigned char *)id,idofs); |
699 | for(j=0;j |
713 | for(j=0;j |
700 | puts(id2[j]); |
714 | puts(id2[j]); |
701 | // CheckNumStr(); |
715 | // CheckNumStr(); |
702 | } |
716 | } |
703 | for(jj=0;jj<2;jj++){ |
717 | for(jj=0;jj<2;jj++){ |
Line 896... | Line 910... | ||
896 | useStartup=(unsigned char)1^neg; |
910 | useStartup=(unsigned char)1^neg; |
897 | break; |
911 | break; |
898 | case c_help: |
912 | case c_help: |
899 | case c_h: |
913 | case c_h: |
900 | case c_hh: |
914 | case c_hh: |
901 | PrintInfo(usage); |
915 | PrintInfo((char **)usage); |
902 | exit(e_ok); |
916 | exit(e_ok); |
903 | case c_mif: |
917 | case c_mif: |
904 | if(ptr==NULL)return c_end; |
918 | if(ptr==NULL)return c_end; |
905 | if(rawfilename!=NULL){ |
919 | if(rawfilename!=NULL){ |
906 | free(rawfilename); |
920 | free(rawfilename); |
Line 920... | Line 934... | ||
920 | break; |
934 | break; |
921 | case c_ac: |
935 | case c_ac: |
922 | AlignCycle=(unsigned char)1^neg; |
936 | AlignCycle=(unsigned char)1^neg; |
923 | if(ptr!=NULL){ |
937 | if(ptr!=NULL){ |
924 | aligncycle=getnumber((unsigned char *)ptr); |
938 | aligncycle=getnumber((unsigned char *)ptr); |
925 | if(aligncycle<1 || aligncycle>4096)aligncycle=8; // fix by cppcheck |
939 | if(aligncycle<1&&aligncycle>4096)aligncycle=8; |
926 | } |
940 | } |
927 | break; |
941 | break; |
928 | case c_ws: //dos-stub for windows programs |
942 | case c_ws: //dos-stub for windows programs |
929 | if(winstub)free(winstub); |
943 | if(winstub)free(winstub); |
930 | winstub=BackString(ptr); |
944 | winstub=BackString(ptr); |
Line 1252... | Line 1266... | ||
1252 | void GetMemExeDat() |
1266 | void GetMemExeDat() |
1253 | { |
1267 | { |
1254 | if(outputdata==output&&outputdata!=0)outputdata=(unsigned char *)MALLOC((size_t)MAXDATA); |
1268 | if(outputdata==output&&outputdata!=0)outputdata=(unsigned char *)MALLOC((size_t)MAXDATA); |
1255 | } |
1269 | } |
Line 1256... | Line -... | ||
1256 | - | ||
1257 | void ListId(int numfirstchar,unsigned char *list,short *ofs) |
1270 | |
1258 | { |
- | |
1259 | char buf[40]; |
- | |
1260 | for(int i=0;i |
- | |
1261 | if((short)ofs[i]!=-1){ |
- | |
1262 | if(i<26)buf[0]=(char)('A'+i); |
- | |
1263 | else if(i==26)buf[0]='_'; |
- | |
1264 | else buf[0]=(char)(i-27+'a'); |
- | |
1265 | unsigned char *ii=(unsigned char *)(list+ofs[i]); |
- | |
1266 | while(*(short *)&*ii!=-1){ |
- | |
1267 | ii+=2; |
- | |
1268 | strcpy(buf+1,(char *)ii); |
- | |
1269 | ii+=strlen((char *)ii)+1; |
- | |
1270 | puts(buf); |
- | |
1271 | // CheckNumStr(); |
- | |
1272 | } |
- | |
1273 | } |
- | |
1274 | } |
- | |
Line 1275... | Line 1271... | ||
1275 | } |
1271 | |
1276 | 1272 | ||
1277 | int writeoutput() |
1273 | int writeoutput() |
1278 | { |
1274 | { |
Line 1656... | Line 1652... | ||
1656 | endinput=startline+endinptr; |
1652 | endinput=startline+endinptr; |
1657 | endoffile=0; |
1653 | endoffile=0; |
1658 | tok=ptr->rectok; |
1654 | tok=ptr->rectok; |
1659 | if(tok==tk_structvar)datasize+=initstructvar((structteg *)ptr->newid,ptr->recrm); |
1655 | if(tok==tk_structvar)datasize+=initstructvar((structteg *)ptr->newid,ptr->recrm); |
1660 | else{ |
1656 | else{ |
1661 | long type,ssize; |
1657 | long type = 0,ssize = 0; |
1662 | unsigned char typev; |
1658 | unsigned char typev = 0; |
1663 | if(tok>=tk_charvar&&tok<=tk_doublevar){ |
1659 | if(tok>=tk_charvar&&tok<=tk_doublevar){ |
1664 | type=tok-(tk_charvar-tk_char); |
1660 | type=tok-(tk_charvar-tk_char); |
1665 | typev=variable; |
1661 | typev=variable; |
1666 | ssize=typesize(type); |
1662 | ssize=typesize(type); |
1667 | } |
1663 | } |
Line 1669... | Line 1665... | ||
1669 | typev=pointer; |
1665 | typev=pointer; |
1670 | type=itok.type; |
1666 | type=itok.type; |
1671 | if(am32==FALSE&&((itok.flag&f_far)==0))ssize=2; |
1667 | if(am32==FALSE&&((itok.flag&f_far)==0))ssize=2; |
1672 | else ssize=4; |
1668 | else ssize=4; |
1673 | } |
1669 | } |
1674 | else printf("unexpected condition\n"); // fix by cppcheck |
- | |
1675 | datasize+=initglobalvar(type,ptr->recsize/ssize,ssize,typev); |
1670 | datasize+=initglobalvar(type,ptr->recsize/ssize,ssize,typev); |
1676 | } |
1671 | } |
1677 | free(input); |
1672 | free(input); |
1678 | linenum2=oline; |
1673 | linenum2=oline; |
1679 | currentfileinfo=ofile; |
1674 | currentfileinfo=ofile; |
Line 1687... | Line 1682... | ||
1687 | 1682 | ||
1688 | FILE *CreateOutPut(char *ext,char *mode) |
1683 | FILE *CreateOutPut(char *ext,char *mode) |
1689 | { |
1684 | { |
1690 | char buf[256]; |
1685 | char buf[256]; |
1691 | FILE *diskout; |
- | |
1692 | if (comfile == file_meos) |
- | |
1693 | sprintf(buf,"%s",rawfilename); |
- | |
1694 | else |
1686 | FILE *diskout; |
1695 | sprintf(buf,"%s.%s",rawfilename,ext); |
1687 | sprintf(buf,"%s.%s",rawfilename,ext); |
1696 | if((diskout=fopen(buf,mode))==NULL){ |
1688 | if((diskout=fopen(buf,mode))==NULL){ |
1697 | ErrOpenFile(buf); |
1689 | ErrOpenFile(buf); |
1698 | exit(e_notcreateoutput); |
1690 | exit(e_notcreateoutput); |