Subversion Repositories Kolibri OS

Rev

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