Subversion Repositories Kolibri OS

Rev

Rev 9585 | Rev 9702 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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