Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2078 lines
73 KiB

  1. /*
  2. * Created by CSD YACC (IBM PC) from "implib.y" */
  3. # define T_FALIAS 257
  4. # define T_KCLASS 258
  5. # define T_KNAME 259
  6. # define T_KLIBRARY 260
  7. # define T_KBASE 261
  8. # define T_KDEVICE 262
  9. # define T_KPHYSICAL 263
  10. # define T_KVIRTUAL 264
  11. # define T_ID 265
  12. # define T_NUMBER 266
  13. # define T_KDESCRIPTION 267
  14. # define T_KHEAPSIZE 268
  15. # define T_KSTACKSIZE 269
  16. # define T_KMAXVAL 270
  17. # define T_KCODE 271
  18. # define T_KCONSTANT 272
  19. # define T_FDISCARDABLE 273
  20. # define T_FNONDISCARDABLE 274
  21. # define T_FEXEC 275
  22. # define T_FFIXED 276
  23. # define T_FMOVABLE 277
  24. # define T_FSWAPPABLE 278
  25. # define T_FSHARED 279
  26. # define T_FMIXED 280
  27. # define T_FNONSHARED 281
  28. # define T_FPRELOAD 282
  29. # define T_FINVALID 283
  30. # define T_FLOADONCALL 284
  31. # define T_FRESIDENT 285
  32. # define T_FPERM 286
  33. # define T_FCONTIG 287
  34. # define T_FDYNAMIC 288
  35. # define T_FNONPERM 289
  36. # define T_KDATA 290
  37. # define T_FNONE 291
  38. # define T_FSINGLE 292
  39. # define T_FMULTIPLE 293
  40. # define T_KSEGMENTS 294
  41. # define T_KOBJECTS 295
  42. # define T_KSECTIONS 296
  43. # define T_KSTUB 297
  44. # define T_KEXPORTS 298
  45. # define T_KEXETYPE 299
  46. # define T_KSUBSYSTEM 300
  47. # define T_FDOS 301
  48. # define T_FOS2 302
  49. # define T_FUNKNOWN 303
  50. # define T_FWINDOWS 304
  51. # define T_FDEV386 305
  52. # define T_FMACINTOSH 306
  53. # define T_FWINDOWSNT 307
  54. # define T_FWINDOWSCHAR 308
  55. # define T_FPOSIX 309
  56. # define T_FNT 310
  57. # define T_FUNIX 311
  58. # define T_KIMPORTS 312
  59. # define T_KNODATA 313
  60. # define T_KOLD 314
  61. # define T_KCONFORM 315
  62. # define T_KNONCONFORM 316
  63. # define T_KEXPANDDOWN 317
  64. # define T_KNOEXPANDDOWN 318
  65. # define T_EQ 319
  66. # define T_AT 320
  67. # define T_KRESIDENTNAME 321
  68. # define T_KNONAME 322
  69. # define T_STRING 323
  70. # define T_DOT 324
  71. # define T_COLON 325
  72. # define T_COMA 326
  73. # define T_ERROR 327
  74. # define T_FHUGE 328
  75. # define T_FIOPL 329
  76. # define T_FNOIOPL 330
  77. # define T_PROTMODE 331
  78. # define T_FEXECREAD 332
  79. # define T_FRDWR 333
  80. # define T_FRDONLY 334
  81. # define T_FINITGLOB 335
  82. # define T_FINITINST 336
  83. # define T_FTERMINST 337
  84. # define T_FWINAPI 338
  85. # define T_FWINCOMPAT 339
  86. # define T_FNOTWINCOMPAT 340
  87. # define T_FPRIVATE 341
  88. # define T_FNEWFILES 342
  89. # define T_REALMODE 343
  90. # define T_FUNCTIONS 344
  91. # define T_APPLOADER 345
  92. # define T_OVL 346
  93. # define T_KVERSION 347
  94. /* SCCSID = %W% %E% */
  95. #if _M_IX86 >= 300
  96. #define M_I386 1
  97. #define HOST32
  98. #ifndef _WIN32
  99. #define i386
  100. #endif
  101. #endif
  102. #ifdef _WIN32
  103. #ifndef HOST32
  104. #define HOST32
  105. #endif
  106. #endif
  107. #include <basetsd.h>
  108. #include <stdio.h>
  109. #include <string.h>
  110. #include <malloc.h>
  111. #include <stdlib.h>
  112. #include <process.h>
  113. #include <stdarg.h>
  114. #include <io.h>
  115. #include "impliber.h"
  116. #include "verimp.h" /* VERSION_STRING header */
  117. #ifdef _MBCS
  118. #define _CRTVAR1
  119. #include <mbctype.h>
  120. #include <mbstring.h>
  121. #endif
  122. #define EXE386 0
  123. #define NOT !
  124. #define AND &&
  125. #define OR ||
  126. #define NEAR
  127. #include <newexe.h>
  128. typedef unsigned char BYTE; /* Byte */
  129. #ifdef HOST32
  130. #define FAR
  131. #define HUGE
  132. #define NEAR
  133. #define FSTRICMP _stricmp
  134. #define PASCAL
  135. #else
  136. #define FAR far
  137. #define HUGE huge
  138. #define FSTRICMP _fstricmp
  139. #define PASCAL __pascal
  140. #endif
  141. #ifndef TRUE
  142. #define TRUE 1
  143. #endif
  144. #ifndef FALSE
  145. #define FALSE 0
  146. #endif
  147. #define C8_IDE TRUE
  148. #ifndef LOCAL
  149. #ifndef _WIN32
  150. #define LOCAL static
  151. #else
  152. #define LOCAL
  153. #endif
  154. #endif
  155. #define WRBIN "wb" /* Write only binary mode */
  156. #define RDBIN "rb" /* Read only binary mode */
  157. #define UPPER(c) (((c)>='a' && (c)<='z')? (c) - 'a' + 'A': (c))
  158. /* Raise char to upper case */
  159. #define YYS_WD(x) (x)._wd /* Access macro */
  160. #define YYS_BP(x) (x)._bp /* Access macro */
  161. #define SBMAX 255 /* Max. of length-prefixed string */
  162. #define MAXDICLN 997 /* Max. no. of pages in dictionary */
  163. #define PAGLEN 512 /* 512 bytes per page */
  164. #define THEADR 0x80 /* THEADR record type */
  165. #define COMENT 0x88 /* COMENT record type */
  166. #define MODEND 0x8A /* MODEND record type */
  167. #define PUBDEF 0x90 /* PUBDEF record type */
  168. #define LIBHDR 0xF0 /* Library header recod */
  169. #define DICHDR 0xF1 /* Dictionary header record */
  170. #define MSEXT 0xA0 /* OMF extension comment class */
  171. #define IMPDEF 0x01 /* IMPort DEFinition record */
  172. #define NBUCKETS 37 /* Thirty-seven buckets per page */
  173. #define PAGEFULL ((char)(0xFF)) /* Page full flag */
  174. #define FREEWD 19 /* Word index of first free word */
  175. #define WPP (PAGLEN >> 1) /* Number of words per page */
  176. #define pagout(pb) fwrite(pb,1,PAGLEN,fo)
  177. /* Write dictionary page to library */
  178. #define INCLUDE_DIR 0xffff /* Include directive for the lexer */
  179. #define MAX_NEST 7
  180. #define IO_BUF_SIZE 512
  181. typedef struct import /* Import record */
  182. {
  183. struct import *i_next; /* Link to next in list */
  184. char *i_extnam; /* Pointer to external name */
  185. char *i_internal; /* Pointer to internal name */
  186. unsigned short i_ord; /* Ordinal number */
  187. unsigned short i_flags; /* Extra flags */
  188. }
  189. IMPORT; /* Import record */
  190. #define I_NEXT(x) (x).i_next
  191. #define I_EXTNAM(x) (x).i_extnam
  192. #define I_INTNAM(x) (x).i_internal
  193. #define I_ORD(x) (x).i_ord
  194. #define I_FLAGS(x) (x).i_flags
  195. typedef unsigned char byte;
  196. typedef unsigned short word;
  197. #ifdef M68000
  198. #define strrchr rindex
  199. #endif
  200. LOCAL int fIgnorecase = 1;/* True if ignoring case - default */
  201. LOCAL int fBannerOnScreen;/* True if banner on screen */
  202. LOCAL int fFileNameExpected = 1;
  203. LOCAL int fNTdll; /* If true add file name extension to module names */
  204. LOCAL int fIgnorewep = 0; /* True if ignoring multiple WEPs */
  205. LOCAL FILE *includeDisp[MAX_NEST];
  206. // Include file stack
  207. LOCAL short curLevel; // Current include nesting level
  208. // Zero means main .DEF file
  209. char prognam[] = "IMPLIB";
  210. FILE *fi; /* Input file */
  211. FILE *fo; /* Output file */
  212. int yylineno = 1; /* Line number */
  213. char rgbid[SBMAX]; /* I.D. buffer */
  214. char sbModule[SBMAX];/* Module name */
  215. IMPORT *implist; /* List of importable symbols */
  216. IMPORT *lastimp; /* Pointer to end of list */
  217. IMPORT *newimps; /* List of importable symbols */
  218. word csyms; /* Symbol count */
  219. word csymsmod; /* Per-module symbol count */
  220. long cbsyms; /* Symbol byte count */
  221. word diclength; /* Dictionary length in PAGEs */
  222. char *mpdpnpag[MAXDICLN];
  223. /* Page buffer array */
  224. char *defname; /* Name of definitions file */
  225. int exitCode; /* code returned to OS */
  226. #if C8_IDE
  227. int fC8IDE = FALSE;
  228. char msgBuf[_MAX_PATH];
  229. #endif
  230. LOCAL char moduleEXE[] = ".exe";
  231. LOCAL char moduleDLL[] = ".dll";
  232. word prime[] = /* Array of primes */
  233. {
  234. 2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
  235. 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
  236. 73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
  237. 127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
  238. 179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
  239. 233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
  240. 283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
  241. 353, 359, 367, 373, 379, 383, 389, 397, 401, 409,
  242. 419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
  243. 467, 479, 487, 491, 499, 503, 509, 521, 523, 541,
  244. 547, 557, 563, 569, 571, 577, 587, 593, 599, 601,
  245. 607, 613, 617, 619, 631, 641, 643, 647, 653, 659,
  246. 661, 673, 677, 683, 691, 701, 709, 719, 727, 733,
  247. 739, 743, 751, 757, 761, 769, 773, 787, 797, 809,
  248. 811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
  249. 877, 881, 883, 887, 907, 911, 919, 929, 937, 941,
  250. 947, 953, 961, 967, 971, 977, 983, 991, MAXDICLN,
  251. 0
  252. };
  253. LOCAL void MOVE(int cb, char *src, char *dst);
  254. LOCAL void DefaultModule(char *defaultExt);
  255. LOCAL void NewModule(char *sbNew, char *defaultExt);
  256. LOCAL char *alloc(word cb);
  257. LOCAL void export(char *sbEntry, char *sbInternal, word ordno, word flags);
  258. LOCAL word theadr(char *sbName);
  259. LOCAL void outimpdefs(void);
  260. LOCAL short symeq(char *ps1,char *ps2);
  261. LOCAL void initsl(void);
  262. LOCAL word rol(word x, word n);
  263. LOCAL word ror(word x, word n);
  264. LOCAL void hashsym(char *pf, word *pdpi, word *pdpid,word *pdpo, word *pdpod);
  265. LOCAL void nullfill(char *pbyte, word length);
  266. LOCAL int pagesearch(char *psym, char *dicpage, word *pdpo, word dpod);
  267. LOCAL word instsym(IMPORT *psym);
  268. LOCAL void nulpagout(void);
  269. LOCAL void writedic(void);
  270. LOCAL int IsPrefix(char *prefix, char *s);
  271. LOCAL void DisplayBanner(void);
  272. int NEAR yyparse(void);
  273. LOCAL void yyerror(char *);
  274. char *keywds[] = /* Keyword array */
  275. {
  276. "ALIAS", (char *) T_FALIAS,
  277. "APPLOADER", (char *) T_APPLOADER,
  278. "BASE", (char *) T_KBASE,
  279. "CLASS", (char *) T_KCLASS,
  280. "CODE", (char *) T_KCODE,
  281. "CONFORMING", (char *) T_KCONFORM,
  282. "CONSTANT", (char *) T_KCONSTANT,
  283. "CONTIGUOUS", (char *) T_FCONTIG,
  284. "DATA", (char *) T_KDATA,
  285. "DESCRIPTION", (char *) T_KDESCRIPTION,
  286. "DEV386", (char *) T_FDEV386,
  287. "DEVICE", (char *) T_KDEVICE,
  288. "DISCARDABLE", (char *) T_FDISCARDABLE,
  289. "DOS", (char *) T_FDOS,
  290. "DYNAMIC", (char *) T_FDYNAMIC,
  291. "EXECUTE-ONLY", (char *) T_FEXEC,
  292. "EXECUTEONLY", (char *) T_FEXEC,
  293. "EXECUTEREAD", (char *) T_FEXECREAD,
  294. "EXETYPE", (char *) T_KEXETYPE,
  295. "EXPANDDOWN", (char *) T_KEXPANDDOWN,
  296. "EXPORTS", (char *) T_KEXPORTS,
  297. "FIXED", (char *) T_FFIXED,
  298. "FUNCTIONS", (char *) T_FUNCTIONS,
  299. "HEAPSIZE", (char *) T_KHEAPSIZE,
  300. "HUGE", (char *) T_FHUGE,
  301. "IMPORTS", (char *) T_KIMPORTS,
  302. "IMPURE", (char *) T_FNONSHARED,
  303. "INCLUDE", (char *) INCLUDE_DIR,
  304. "INITGLOBAL", (char *) T_FINITGLOB,
  305. "INITINSTANCE", (char *) T_FINITINST,
  306. "INVALID", (char *) T_FINVALID,
  307. "IOPL", (char *) T_FIOPL,
  308. "LIBRARY", (char *) T_KLIBRARY,
  309. "LOADONCALL", (char *) T_FLOADONCALL,
  310. "LONGNAMES", (char *) T_FNEWFILES,
  311. "MACINTOSH", (char *) T_FMACINTOSH,
  312. "MAXVAL", (char *) T_KMAXVAL,
  313. "MIXED1632", (char *) T_FMIXED,
  314. "MOVABLE", (char *) T_FMOVABLE,
  315. "MOVEABLE", (char *) T_FMOVABLE,
  316. "MULTIPLE", (char *) T_FMULTIPLE,
  317. "NAME", (char *) T_KNAME,
  318. "NEWFILES", (char *) T_FNEWFILES,
  319. "NODATA", (char *) T_KNODATA,
  320. "NOEXPANDDOWN", (char *) T_KNOEXPANDDOWN,
  321. "NOIOPL", (char *) T_FNOIOPL,
  322. "NONAME", (char *) T_KNONAME,
  323. "NONCONFORMING", (char *) T_KNONCONFORM,
  324. "NONDISCARDABLE", (char *) T_FNONDISCARDABLE,
  325. "NONE", (char *) T_FNONE,
  326. "NONPERMANENT", (char *) T_FNONPERM,
  327. "NONSHARED", (char *) T_FNONSHARED,
  328. "NOTWINDOWCOMPAT", (char *) T_FNOTWINCOMPAT,
  329. "NT", (char *) T_FNT,
  330. "OBJECTS", (char *) T_KOBJECTS,
  331. "OLD", (char *) T_KOLD,
  332. "OS2", (char *) T_FOS2,
  333. "OVERLAY", (char *) T_OVL,
  334. "OVL", (char *) T_OVL,
  335. "PERMANENT", (char *) T_FPERM,
  336. "PHYSICAL", (char *) T_KPHYSICAL,
  337. "POSIX", (char *) T_FPOSIX,
  338. "PRELOAD", (char *) T_FPRELOAD,
  339. "PRIVATE", (char *) T_FPRIVATE,
  340. "PRIVATELIB", (char *) T_FPRIVATE,
  341. "PROTMODE", (char *) T_PROTMODE,
  342. "PURE", (char *) T_FSHARED,
  343. "READONLY", (char *) T_FRDONLY,
  344. "READWRITE", (char *) T_FRDWR,
  345. "REALMODE", (char *) T_REALMODE,
  346. "RESIDENT", (char *) T_FRESIDENT,
  347. "RESIDENTNAME", (char *) T_KRESIDENTNAME,
  348. "SECTIONS", (char *) T_KSECTIONS,
  349. "SEGMENTS", (char *) T_KSEGMENTS,
  350. "SHARED", (char *) T_FSHARED,
  351. "SINGLE", (char *) T_FSINGLE,
  352. "STACKSIZE", (char *) T_KSTACKSIZE,
  353. "STUB", (char *) T_KSTUB,
  354. "SUBSYSTEM", (char *) T_KSUBSYSTEM,
  355. "SWAPPABLE", (char *) T_FSWAPPABLE,
  356. "TERMINSTANCE", (char *) T_FTERMINST,
  357. "UNIX", (char *) T_FUNIX,
  358. "UNKNOWN", (char *) T_FUNKNOWN,
  359. "VERSION", (char *) T_KVERSION,
  360. "VIRTUAL", (char *) T_KVIRTUAL,
  361. "WINDOWAPI", (char *) T_FWINAPI,
  362. "WINDOWCOMPAT", (char *) T_FWINCOMPAT,
  363. "WINDOWS", (char *) T_FWINDOWS,
  364. "WINDOWSCHAR", (char *) T_FWINDOWSCHAR,
  365. "WINDOWSNT", (char *) T_FWINDOWSNT,
  366. NULL
  367. };
  368. #define UNION 1
  369. typedef union
  370. {
  371. word _wd;
  372. char *_bp;
  373. } YYSTYPE;
  374. #define yyclearin yychar = -1
  375. #define yyerrok yyerrflag = 0
  376. #ifndef YYMAXDEPTH
  377. #define YYMAXDEPTH 150
  378. #endif
  379. YYSTYPE yylval, yyval;
  380. # define YYERRCODE 256
  381. #ifndef M_I386
  382. extern char * PASCAL __FMSG_TEXT ( unsigned );
  383. #else
  384. #ifdef _WIN32
  385. extern char * PASCAL __FMSG_TEXT ( unsigned );
  386. #endif
  387. #endif
  388. /*** Error - display error message
  389. *
  390. * Purpose:
  391. * Display error message.
  392. *
  393. * Input:
  394. * errNo - error number
  395. *
  396. * Output:
  397. * No explicit value is returned. Error message written out to stderr.
  398. *
  399. * Exceptions:
  400. * None.
  401. *
  402. * Notes:
  403. * This function takes variable number of parameters. MUST be in
  404. * C calling convention.
  405. *
  406. *************************************************************************/
  407. LOCAL void cdecl Error(unsigned errNo,...)
  408. {
  409. va_list pArgList;
  410. if (!fBannerOnScreen)
  411. DisplayBanner();
  412. va_start(pArgList, errNo); /* Get start of argument list */
  413. /* Write out standard error prefix */
  414. fprintf(stderr, "%s : %s IM%d: ", prognam, GET_MSG(M_error), errNo);
  415. /* Write out error message */
  416. vfprintf(stderr, GET_MSG(errNo), pArgList);
  417. fprintf(stderr, "\n");
  418. if (!exitCode)
  419. exitCode = (errNo >= ER_Min && errNo <= ER_Max)
  420. || (errNo >= ER_MinFatal && errNo <= ER_MaxFatal);
  421. }
  422. /*** Fatal - display error message
  423. *
  424. * Purpose:
  425. * Display error message and exit to operating system.
  426. *
  427. * Input:
  428. * errNo - error number
  429. *
  430. * Output:
  431. * No explicit value is returned. Error message written out to stderr.
  432. *
  433. * Exceptions:
  434. * None.
  435. *
  436. * Notes:
  437. * This function takes variable number of parameters. MUST be in
  438. * C calling convention.
  439. *
  440. *************************************************************************/
  441. LOCAL void cdecl Fatal(unsigned errNo,...)
  442. {
  443. va_list pArgList;
  444. if (!fBannerOnScreen)
  445. DisplayBanner();
  446. va_start(pArgList, errNo); /* Get start of argument list */
  447. /* Write out standard error prefix */
  448. fprintf(stderr, "%s : %s %s IM%d: ", prognam, GET_MSG(M_fatal), GET_MSG(M_error),errNo);
  449. /* Write out fatal error message */
  450. vfprintf(stderr, GET_MSG(errNo), pArgList);
  451. fprintf(stderr, "\n");
  452. exit(1);
  453. }
  454. /*
  455. * Check if error in output file, abort if there is.
  456. */
  457. void chkerror ()
  458. {
  459. if(ferror(fo))
  460. {
  461. Fatal(ER_outfull, strerror(errno));
  462. }
  463. }
  464. LOCAL void MOVE(int cb, char *src, char *dst)
  465. {
  466. while(cb--) *dst++ = *src++;
  467. }
  468. LOCAL char *alloc(word cb)
  469. {
  470. char *cp; /* Pointer */
  471. if((cp = malloc(cb)) != NULL) return(cp);
  472. /* Call malloc() to get the space */
  473. Fatal(ER_nomem, "far");
  474. return 0;
  475. }
  476. LOCAL int lookup() /* Keyword lookup */
  477. {
  478. char **pcp; /* Pointer to character pointer */
  479. int i; /* Comparison value */
  480. for(pcp = keywds; *pcp != NULL; pcp += 2)
  481. { /* Look through keyword table */
  482. if(!(i = FSTRICMP(&rgbid[1],*pcp)))
  483. return((int)(INT_PTR) pcp[1]); /* If found, return token type */
  484. if(i < 0) break; /* Break if we've gone too far */
  485. }
  486. return(T_ID); /* Just your basic identifier */
  487. }
  488. LOCAL int GetChar(void)
  489. {
  490. int c; /* A character */
  491. c = getc(fi);
  492. if (c == EOF && curLevel > 0)
  493. {
  494. fclose(fi);
  495. fi = includeDisp[curLevel];
  496. curLevel--;
  497. c = GetChar();
  498. }
  499. return(c);
  500. }
  501. LOCAL int yylex() /* Lexical analyzer */
  502. {
  503. int c = 0; /* A character */
  504. word x; /* Numeric token value */
  505. int state; /* State variable */
  506. char *cp; /* Character pointer */
  507. char *sz; /* Zero-terminated string */
  508. static int lastc; /* Previous character */
  509. int fFileNameSave;
  510. state = 0; /* Assume we're not in a comment */
  511. for(;;) /* Loop to skip white space */
  512. {
  513. lastc = c;
  514. if((c = GetChar()) == EOF || c == '\032' || c == '\377') return(EOF);
  515. /* Get a character */
  516. if(c == ';') state = 1; /* If comment, set flag */
  517. else if(c == '\n') /* If end of line */
  518. {
  519. state = 0; /* End of comment */
  520. if(!curLevel)
  521. ++yylineno; /* Increment line number count */
  522. }
  523. else if(state == 0 && c != ' ' && c != '\t' && c != '\r') break;
  524. /* Break on non-white space */
  525. }
  526. switch(c) /* Handle one-character tokens */
  527. {
  528. case '.': /* Name separator */
  529. if (fFileNameExpected)
  530. break;
  531. return(T_DOT);
  532. case '@': /* Ordinal specifier */
  533. /*
  534. * Require that whitespace precede '@' if introducing an
  535. * ordinal, to allow '@' in identifiers.
  536. */
  537. if(lastc == ' ' || lastc == '\t' || lastc == '\r')
  538. return(T_AT);
  539. break;
  540. case '=': /* Name assignment */
  541. return(T_EQ);
  542. case ':':
  543. return(T_COLON);
  544. case ',':
  545. return(T_COMA);
  546. }
  547. if(c >= '0' && c <= '9' && !fFileNameExpected)
  548. { /* If token is a number */
  549. x = c - '0'; /* Get first digit */
  550. c = GetChar(); /* Get next character */
  551. if(x == 0) /* If octal or hex */
  552. {
  553. if(c == 'x' || c == 'X')/* If it is an 'x' */
  554. {
  555. state = 16; /* Base is hexadecimal */
  556. c = GetChar(); /* Get next character */
  557. }
  558. else state = 8; /* Else octal */
  559. }
  560. else state = 10; /* Else decimal */
  561. for(;;)
  562. {
  563. if(c >= '0' && c <= '9') c -= '0';
  564. else if(c >= 'A' && c <= 'F') c -= 'A' - 10;
  565. else if(c >= 'a' && c <= 'f') c -= 'a' - 10;
  566. else break;
  567. if(c >= state) break;
  568. x = x*state + c;
  569. c = GetChar();
  570. }
  571. ungetc(c,fi);
  572. YYS_WD(yylval) = x;
  573. return(T_NUMBER);
  574. }
  575. if(c == '\'' || c == '"') /* If token is a string */
  576. {
  577. sz = &rgbid[1]; /* Initialize */
  578. for(state = 0; state != 2;) /* State machine loop */
  579. {
  580. if((c = GetChar()) == EOF) return(EOF);
  581. /* Check for EOF */
  582. if (sz >= &rgbid[sizeof(rgbid)])
  583. {
  584. Error(ER_linemax, yylineno, sizeof(rgbid)-1);
  585. state = 2;
  586. }
  587. switch(state) /* Transitions */
  588. {
  589. case 0: /* Inside quote */
  590. if(c == '\'' || c == '"') state = 1;
  591. /* Change state if quote found */
  592. else *sz++ = (char) c;/* Else save character */
  593. break;
  594. case 1: /* Inside quote with quote */
  595. if(c == '\'' || c == '"')/* If consecutive quotes */
  596. {
  597. *sz++ = (char) c;/* Quote inside string */
  598. state = 0; /* Back to state 0 */
  599. }
  600. else state = 2; /* Else end of string */
  601. break;
  602. }
  603. }
  604. ungetc(c,fi); /* Put back last character */
  605. *sz = '\0'; /* Null-terminate the string */
  606. rgbid[0] = (char)(sz - &rgbid[1]);
  607. /* Set length of string */
  608. YYS_BP(yylval) = rgbid; /* Save ptr. to identifier */
  609. return(T_STRING); /* String found */
  610. }
  611. sz = &rgbid[1]; /* Initialize */
  612. for(;;) /* Loop to get i.d.'s */
  613. {
  614. if (fFileNameExpected)
  615. cp = " \t\r\n\f";
  616. else
  617. cp = " \t\r\n.=';\032";
  618. while(*cp && *cp != (char) c)
  619. ++cp;
  620. /* Check for end of identifier */
  621. if(*cp) break; /* Break if end of identifier found */
  622. if (sz >= &rgbid[sizeof(rgbid)])
  623. Fatal(ER_linemax, yylineno, sizeof(rgbid)-1);
  624. *sz++ = (byte) c; /* Save the character */
  625. if((c = GetChar()) == EOF) break;
  626. /* Get next character */
  627. }
  628. ungetc(c,fi); /* Put character back */
  629. *sz = '\0'; /* Null-terminate the string */
  630. rgbid[0] = (char)(sz - &rgbid[1]); /* Set length of string */
  631. YYS_BP(yylval) = rgbid; /* Save ptr. to identifier */
  632. state = lookup(); /* Look up the identifier */
  633. if (state == INCLUDE_DIR)
  634. {
  635. // Process include directive
  636. fFileNameSave = fFileNameExpected;
  637. fFileNameExpected = 1;
  638. state = yylex();
  639. fFileNameExpected = fFileNameSave;
  640. if (state == T_ID || state == T_STRING)
  641. {
  642. if (curLevel < MAX_NEST - 1)
  643. {
  644. curLevel++;
  645. includeDisp[curLevel] = fi;
  646. fi = fopen(&rgbid[1], RDBIN);
  647. if (fi == NULL)
  648. Fatal(ER_badopen, &rgbid[1], strerror(errno));
  649. return(yylex());
  650. }
  651. else
  652. Fatal(ER_toomanyincl);
  653. }
  654. else
  655. Fatal(ER_badinclname);
  656. return (0);
  657. }
  658. else
  659. return(state);
  660. }
  661. LOCAL void yyerror(s) /* Error routine */
  662. char *s; /* Error message */
  663. {
  664. fprintf(stderr, "%s(%d) : %s %s IM%d: %s %s\n",
  665. defname, yylineno, GET_MSG(M_fatal), GET_MSG(M_error),
  666. ER_syntax, s, GET_MSG(ER_syntax));
  667. exit(1);
  668. }
  669. /*
  670. * Use the basename of the current .DEF file name as the module name.
  671. */
  672. LOCAL void DefaultModule(char *defaultExt)
  673. {
  674. char drive[_MAX_DRIVE];
  675. char dir[_MAX_DIR];
  676. char fname[_MAX_FNAME];
  677. char ext[_MAX_EXT];
  678. _splitpath(defname, drive, dir, fname, ext);
  679. if (fNTdll)
  680. {
  681. if (ext[0] == '\0')
  682. _makepath(&sbModule[1], NULL, NULL, fname, defaultExt);
  683. else if (ext[0] == '.' && ext[1] == '\0')
  684. strcpy(&sbModule[1], fname);
  685. else
  686. _makepath(&sbModule[1], NULL, NULL, fname, ext);
  687. }
  688. else
  689. _makepath(&sbModule[1], NULL, NULL, fname, NULL);
  690. sbModule[0] = (unsigned char) strlen(&sbModule[1]);
  691. }
  692. LOCAL void NewModule(char *sbNew, char *defaultExt)
  693. {
  694. char drive[_MAX_DRIVE];
  695. char dir[_MAX_DIR];
  696. char fname[_MAX_FNAME];
  697. char ext[_MAX_EXT];
  698. sbNew[sbNew[0]+1] = '\0';
  699. _splitpath(&sbNew[1], drive, dir, fname, ext);
  700. if (fNTdll)
  701. {
  702. if (ext[0] == '\0')
  703. _makepath(&sbModule[1], NULL, NULL, fname, defaultExt);
  704. else if (ext[0] == '.' && ext[1] == '\0')
  705. strcpy(&sbModule[1], fname);
  706. else
  707. _makepath(&sbModule[1], NULL, NULL, fname, ext);
  708. }
  709. else
  710. strcpy(&sbModule[1], fname);
  711. sbModule[0] = (unsigned char) strlen(&sbModule[1]);
  712. }
  713. LOCAL void export(char *sbEntry, char *sbInternal, word ordno, word flags)
  714. {
  715. IMPORT *imp; /* Import definition */
  716. if(fIgnorewep && strcmp(sbEntry+1, "WEP") == 0)
  717. return;
  718. imp = (IMPORT *) alloc(sizeof(IMPORT));
  719. /* Allocate a cell */
  720. if (newimps == NULL) /* If list empty */
  721. newimps = imp; /* Define start of list */
  722. else
  723. I_NEXT(*lastimp) = imp; /* Append it to list */
  724. I_NEXT(*imp) = NULL;
  725. I_EXTNAM(*imp) = sbEntry; /* Save the external name */
  726. I_INTNAM(*imp) = sbInternal; /* Save the internal name */
  727. I_ORD(*imp) = ordno; /* Save the ordinal number */
  728. I_FLAGS(*imp) = flags; /* Save extra flags */
  729. lastimp = imp; /* Save pointer to end of list */
  730. }
  731. /* Output a THEADR record */
  732. LOCAL word theadr(char *sbName)
  733. {
  734. fputc(THEADR,fo);
  735. fputc(sbName[0] + 2,fo);
  736. fputc(0,fo);
  737. fwrite(sbName,sizeof(char),sbName[0] + 1,fo);
  738. fputc(0,fo);
  739. chkerror();
  740. return(sbName[0] + 5);
  741. }
  742. word modend() /* Output a MODEND record */
  743. {
  744. fwrite("\212\002\0\0\0",sizeof(char),5,fo);
  745. /* Write a MODEND record */
  746. chkerror();
  747. return(5); /* It is 5 bytes long */
  748. }
  749. LOCAL void outimpdefs(void)/* Output import definitions */
  750. {
  751. IMPORT *imp; /* Pointer to import record */
  752. word reclen; /* Record length */
  753. word ord; /* Ordinal number */
  754. long lfa; /* File address */
  755. word tlen; /* Length of THEADR */
  756. byte impFlags;
  757. for (imp = newimps; imp != NULL; imp = I_NEXT(*imp))
  758. { /* Traverse the list */
  759. lfa = ftell(fo); /* Find out where we are */
  760. tlen = theadr(I_EXTNAM(*imp));
  761. /* Output a THEADR record */
  762. // 1 1 1 1 n + 1 n + 1 n + 1 or 2 1
  763. // +---+----+---+-----+-----------+-----------+------------------+---+
  764. // | 0 | A0 | 1 | Flg | Ext. Name | Mod. Name | Int. Name or Ord | 0 |
  765. // +---+----+---+-----+-----------+-----------+------------------+---+
  766. reclen = 4 + sbModule[0] + 1 + I_EXTNAM(*imp)[0] + 1 + 1;
  767. /* Initialize */
  768. ord = I_ORD(*imp);
  769. if (ord != 0)
  770. reclen +=2; /* Two bytes for ordinal number */
  771. else if (I_INTNAM(*imp))
  772. reclen += I_INTNAM(*imp)[0] + 1;
  773. /* Length of internal name */
  774. else
  775. reclen++;
  776. I_ORD(*imp) = (word)(lfa >> 4);
  777. /* Save page number */
  778. ++csymsmod; /* Increment symbol count */
  779. cbsyms += (long) I_EXTNAM(*imp)[0] + 4;
  780. /* Increment symbol space count */
  781. fputc(COMENT,fo); /* Comment record */
  782. fputc(reclen & 0xFF,fo); /* Lo-byte of record length */
  783. fputc(reclen >> 8,fo); /* Hi-byte of length */
  784. fputc(0,fo); /* Purgable, listable */
  785. fputc(MSEXT,fo); /* Microsoft OMF extension class */
  786. fputc(IMPDEF,fo); /* IMPort DEFinition record */
  787. impFlags = 0;
  788. if (ord != 0)
  789. impFlags |= 0x1;
  790. if (I_FLAGS(*imp) & 0x1)
  791. impFlags |= 0x2;
  792. fputc(impFlags, fo); /* Import type (name or ordinal or constant) */
  793. fwrite(I_EXTNAM(*imp),sizeof(char),I_EXTNAM(*imp)[0] + 1,fo);
  794. /* Write the external name */
  795. fwrite(sbModule,sizeof(char),sbModule[0] + 1,fo);
  796. /* Write the module name */
  797. if (ord != 0) /* If import by ordinal */
  798. {
  799. fputc(ord & 0xFF,fo); /* Lo-byte of ordinal */
  800. fputc(ord >> 8,fo); /* Hi-byte of ordinal */
  801. }
  802. else if (I_INTNAM(*imp))
  803. fwrite(I_INTNAM(*imp), sizeof(char), I_INTNAM(*imp)[0] + 1, fo);
  804. /* Write internal name */
  805. else
  806. fputc(0, fo); /* No internal name */
  807. fputc(0,fo); /* Checksum byte */
  808. reclen += tlen + modend() + 3; /* Output a MODEND record */
  809. if(reclen &= 0xF) /* If padding needed */
  810. {
  811. reclen = 0x10 - reclen; /* Calculate needed padding */
  812. while(reclen--) fputc(0,fo);/* Pad to page boundary */
  813. }
  814. chkerror();
  815. }
  816. }
  817. /* Compare two symbols */
  818. LOCAL short symeq(char *ps1,char *ps2)
  819. {
  820. int length; /* No. of char.s to compare */
  821. length = *ps1 + 1; /* Take length of first symbol */
  822. if (length != *ps2 + 1)
  823. return(0); /* Length must match */
  824. while(length--) /* While not at end of symbol */
  825. if (fIgnorecase)
  826. {
  827. if (UPPER(*ps1) != UPPER(*ps2))
  828. return(0); /* If not equal, return zero */
  829. ++ps1;
  830. ++ps2;
  831. }
  832. else if (*ps1++ != *ps2++)
  833. return(0); /* If not equal, return zero */
  834. return(1); /* Symbols match */
  835. }
  836. LOCAL word calclen() /* Calculate dictionary length */
  837. {
  838. word avglen; /* Average entry length */
  839. word avgentries; /* Average no. of entries per page */
  840. word minpages; /* Min. no. of pages in dictionary */
  841. register word i; /* Index variable */
  842. if(!csyms) return(1); /* One page for an empty dictionary */
  843. avglen = (word)(cbsyms/csyms) + 1;
  844. /* Average entry length */
  845. avgentries = (PAGLEN - NBUCKETS - 1)/avglen;
  846. /* Average no. of entries per page */
  847. minpages = (word) csyms/avgentries + 1;
  848. /* Minimum no. of pages in dict. */
  849. if(minpages < (i = (word) csyms/NBUCKETS + 1))
  850. {
  851. minpages = i;
  852. }
  853. else
  854. {
  855. /* Add some extra pages if there is a lot long symbol names */
  856. #define MAXOVERHEAD 10
  857. i = (word)(((avglen+5L) * minpages *4)/(3*PAGLEN)); // The more symbols the larger increase...
  858. if(i>MAXOVERHEAD)
  859. i = MAXOVERHEAD; /* Do not add more than MAXOVERHEAD pages */
  860. minpages += i;
  861. }
  862. /* Insure enough buckets allotted */
  863. i = 0; /* Initialize index */
  864. do /* Look through prime array */
  865. {
  866. if(minpages <= prime[i]) return(prime[i]);
  867. /* Return smallest prime >= minpages */
  868. }
  869. while(prime[i++]); /* Until end of table found */
  870. return(0); /* Too many symbols */
  871. }
  872. /* Initialize Symbol Lookup */
  873. LOCAL void initsl(void)
  874. {
  875. register word i; /* Index variable */
  876. diclength = calclen(); /* Calculate dictionaly length */
  877. for(i = 0; i < diclength; ++i) mpdpnpag[i] = NULL;
  878. /* Initialize page table */
  879. }
  880. LOCAL word ror(word x, word n) /* Rotate right */
  881. {
  882. #if ODDWORDLN
  883. return(((x << (16 - n)) | ((x >> n) & ~(~0 << (16 - n))))
  884. & ~(~0 << 16));
  885. #else
  886. return((x << (16 - n)) | ((x >> n) & ~(~0 << (16 - n))));
  887. #endif
  888. }
  889. LOCAL word rol(word x, word n) /* Rotate left */
  890. {
  891. #if ODDWORDLN
  892. return(((x << n) | ((x >> (16 - n)) & ~(~0 << n))) & ~(~0 << 16));
  893. #else
  894. return((x << n) | ((x >> (16 - n)) & ~(~0 << n)));
  895. #endif
  896. }
  897. LOCAL void hashsym(char *pf, word *pdpi, word *pdpid,word *pdpo, word *pdpod)
  898. {
  899. char *pb; /* Pointer to back of symbol */
  900. register word len; /* Length of symbol */
  901. register word ch; /* Character */
  902. len = *pf; /* Get length */
  903. pb = &pf[len]; /* Get pointer to back */
  904. *pdpi = 0; /* Initialize */
  905. *pdpid = 0; /* Initialize */
  906. *pdpo = 0; /* Initialize */
  907. *pdpod = 0; /* Initialize */
  908. while(len--) /* Loop */
  909. {
  910. ch = *pf++ | 32; /* Force char to lower case */
  911. *pdpi = rol(*pdpi,2) ^ ch; /* Hash */
  912. *pdpod = ror(*pdpod,2) ^ ch; /* Hash */
  913. ch = *pb-- | 32; /* Force char to lower case */
  914. *pdpo = ror(*pdpo,2) ^ ch; /* Hash */
  915. *pdpid = rol(*pdpid,2) ^ ch; /* Hash */
  916. }
  917. *pdpi %= diclength; /* Calculate page index */
  918. if(!(*pdpid %= diclength)) *pdpid = 1;
  919. /* Calculate page index delta */
  920. *pdpo %= NBUCKETS; /* Calculate page bucket no. */
  921. if(!(*pdpod %= NBUCKETS)) *pdpod = 1;
  922. /* Calculate page bucket delta */
  923. }
  924. LOCAL void nullfill(char *pbyte, word length)
  925. {
  926. while(length--) *pbyte++ = '\0'; /* Load with nulls */
  927. }
  928. /*
  929. * Returns:
  930. * -1 Symbol not in dictionary
  931. * 0 Search inconclusive
  932. * 1 Symbol on this page
  933. */
  934. LOCAL int pagesearch(char *psym, char *dicpage, word *pdpo, word dpod)
  935. {
  936. register word i; /* Index variable */
  937. word dpo; /* Initial bucket number */
  938. dpo = *pdpo; /* Remember starting position */
  939. for(;;) /* Forever */
  940. {
  941. if(i = ((word) dicpage[*pdpo] & 0xFF) << 1)
  942. { /* If bucket is not empty */
  943. if(symeq(psym,&dicpage[i])) /* If we've found a match */
  944. return(1); /* Found */
  945. else /* Otherwise */
  946. {
  947. if((*pdpo += dpod) >= NBUCKETS) *pdpo -= NBUCKETS;
  948. /* Try next bucket */
  949. if(*pdpo == dpo) return(0);
  950. /* Symbol not on this page */
  951. }
  952. }
  953. else if(dicpage[NBUCKETS] == PAGEFULL) return(0);
  954. /* Search inconclusive */
  955. else return(-1); /* Symbol not in dictionary */
  956. }
  957. }
  958. /* Install symbol in dictionary */
  959. LOCAL word instsym(IMPORT *psym)
  960. {
  961. word dpi; /* Dictionary page index */
  962. word dpid; /* Dictionary page index delta */
  963. word dpo; /* Dictionary page offset */
  964. word dpod; /* Dict. page offset delta */
  965. word dpii; /* Initial dict. page index */
  966. register int erc; /* Error code */
  967. char *dicpage; /* Pointer to dictionary page */
  968. hashsym(I_EXTNAM(*psym),&dpi,&dpid,&dpo,&dpod);
  969. /* Hash the symbol */
  970. dpii = dpi; /* Save initial page index */
  971. for(;;) /* Forever */
  972. {
  973. if(mpdpnpag[dpi] == NULL) /* If page unallocated */
  974. {
  975. mpdpnpag[dpi] = alloc(PAGLEN);
  976. /* Allocate a page */
  977. nullfill(mpdpnpag[dpi],PAGLEN);
  978. /* Fill it with nulls */
  979. mpdpnpag[dpi][NBUCKETS] = FREEWD;
  980. /* Initialize pointer to free space */
  981. }
  982. dicpage = mpdpnpag[dpi]; /* Set pointer to page */
  983. if((erc = pagesearch(I_EXTNAM(*psym),dicpage,&dpo,dpod)) > 0)
  984. return(1); /* Return 1 if symbol in table */
  985. if(erc == -1) /* If empty bucket found */
  986. {
  987. if(((I_EXTNAM(*psym)[0] + 4) >> 1) <
  988. WPP - ((int) dicpage[NBUCKETS] & 0xFF))
  989. { /* If enough free space on page */
  990. dicpage[dpo] = dicpage[NBUCKETS];
  991. /* Load bucket with pointer */
  992. erc = ((int) dicpage[NBUCKETS] & 0xFF) << 1;
  993. /* Get byte index to free space */
  994. dpi = I_EXTNAM(*psym)[0];
  995. /* Get symbol length */
  996. for(dpo = 0; dpo <= dpi;)
  997. dicpage[erc++] = I_EXTNAM(*psym)[dpo++];
  998. /* Install the symbol text */
  999. dicpage[erc++] = (char)(I_ORD(*psym) & 0xFF);
  1000. /* Load low-order byte */
  1001. dicpage[erc++] = (char)(I_ORD(*psym) >> 8);
  1002. /* Load high-order byte */
  1003. if(++erc >= PAGLEN) dicpage[NBUCKETS] = PAGEFULL;
  1004. else dicpage[NBUCKETS] = (char)(erc >> 1);
  1005. /* Update free word pointer */
  1006. return(0); /* Mission accomplished */
  1007. }
  1008. else dicpage[NBUCKETS] = PAGEFULL;
  1009. /* Mark page as full */
  1010. }
  1011. if((dpi += dpid) >= diclength) dpi -= diclength;
  1012. /* Try next page */
  1013. if(dpi == dpii) return(2); /* Once around without finding it */
  1014. }
  1015. }
  1016. /* Output empty dictionary page */
  1017. LOCAL void nulpagout(void)
  1018. {
  1019. register word i; /* Counter */
  1020. char temp[PAGLEN]; /* Page buffer */
  1021. i = 0; /* Initialize */
  1022. while(i < NBUCKETS) temp[i++] = '\0';
  1023. /* Empty hash table */
  1024. temp[i++] = FREEWD; /* Set free word pointer */
  1025. while(i < PAGLEN) temp[i++] = '\0'; /* Clear rest of page */
  1026. fwrite(temp,1,PAGLEN,fo); /* Write empty page */
  1027. chkerror();
  1028. }
  1029. /* Write dictionary to library */
  1030. LOCAL void writedic(void)
  1031. {
  1032. register IMPORT *imp; /* Symbol record */
  1033. word i; /* Index variable */
  1034. initsl(); /* Initialize */
  1035. for(imp = implist; imp != NULL; imp = I_NEXT(*imp))
  1036. {
  1037. if(instsym(imp)) /* If symbol already in dictionary */
  1038. Error(ER_multdef, &I_EXTNAM(*imp)[1]);
  1039. /* Issue error message */
  1040. }
  1041. for(i = 0; i < diclength; ++i) /* Look through mapping table */
  1042. {
  1043. if(mpdpnpag[i] != NULL) pagout(mpdpnpag[i]);
  1044. /* Write page if it exists */
  1045. else nulpagout(); /* Else write an empty page */
  1046. }
  1047. chkerror();
  1048. }
  1049. LOCAL void DisplayBanner(void)
  1050. {
  1051. if (!fBannerOnScreen)
  1052. {
  1053. fprintf( stdout, "\nMicrosoft (R) Import Library Manager NtGroup "VERSION_STRING );
  1054. fputs("\nCopyright (C) Microsoft Corp 1984-1996. All rights reserved.\n\n", stdout);
  1055. fflush(stdout);
  1056. fBannerOnScreen = 1;
  1057. #if C8_IDE
  1058. if(fC8IDE)
  1059. { sprintf(msgBuf, "@I0\r\n");
  1060. _write(_fileno(stderr), msgBuf, strlen(msgBuf));
  1061. sprintf(msgBuf, "@I1Microsoft (R) Import Library Manager "VERSION_STRING"\r\n" );
  1062. _write(_fileno(stderr), msgBuf, strlen(msgBuf));
  1063. sprintf(msgBuf, "@I2Copyright (C) Microsoft Corp 1984-1992. All rights reserved.\r\n");
  1064. _write(_fileno(stderr), msgBuf, strlen(msgBuf));
  1065. }
  1066. #endif
  1067. }
  1068. }
  1069. /****************************************************************
  1070. * *
  1071. * IsPrefix: *
  1072. * *
  1073. * This function takes as its arguments a pointer to a *
  1074. * null-terminated character string and a pointer to a second *
  1075. * null-terminated character string. The function returns *
  1076. * true if the first string is a prefix of the second; *
  1077. * otherwise, it returns false. *
  1078. * *
  1079. ****************************************************************/
  1080. LOCAL int IsPrefix(char *prefix, char *s)
  1081. {
  1082. while(*prefix) /* While not at end of prefix */
  1083. {
  1084. if(UPPER(*prefix) != UPPER(*s)) return(0);
  1085. /* Return zero if mismatch */
  1086. ++prefix; /* Increment pointer */
  1087. ++s; /* Increment pointer */
  1088. }
  1089. return(1); /* We have a prefix */
  1090. }
  1091. /*** ScanTable - build list of exports
  1092. *
  1093. * Purpose:
  1094. * Scans Resident or Nonresident Name Table, Entry Table and
  1095. * builds list of exported entries.
  1096. *
  1097. * Input:
  1098. * pbTable - pointer to Name Table
  1099. * cbTable - size of Name Table
  1100. * fNoRes - TRUE if non resident name table
  1101. *
  1102. * Output:
  1103. * List of exported entries by DLL.
  1104. *
  1105. * Exceptions:
  1106. * None.
  1107. *
  1108. * Notes:
  1109. * None.
  1110. *
  1111. *************************************************************************/
  1112. LOCAL void ScanTable(word cbTable, int fNoRes)
  1113. {
  1114. word eno;
  1115. char buffer[256];
  1116. register char *pch;
  1117. register byte *pb;
  1118. byte *pTable;
  1119. pb = alloc(cbTable);
  1120. pTable = pb;
  1121. if (fread(pb, sizeof(char), cbTable, fi) != cbTable) {
  1122. Error(ER_baddll);
  1123. free(pTable);
  1124. return;
  1125. }
  1126. while(cbTable != 0)
  1127. {
  1128. /* Get exported name length - if zero continue */
  1129. --cbTable;
  1130. if (!(eno = (word) *pb++ & 0xff))
  1131. break;
  1132. cbTable -= eno + 2;
  1133. /* Copy name - length prefixed */
  1134. pch = &buffer[1];
  1135. buffer[0] = (byte) eno;
  1136. while(eno--)
  1137. *pch++ = *pb++;
  1138. *pch = '\0';
  1139. /* Get ordinal */
  1140. eno = ((word) pb[0] & 0xff) + (((word) pb[1] & 0xff) << 8);
  1141. pb += 2;
  1142. /* If WEP and fIgnorewep is TRUE, ignore this symbol */
  1143. if(fIgnorewep && strcmp(&buffer[1], "WEP") == 0)
  1144. continue;
  1145. if (eno != 0)
  1146. {
  1147. pch = alloc((word)(buffer[0] + 1));
  1148. strncpy(pch, buffer, buffer[0] + 1);
  1149. // If Implib is run on a DLL, it exports symbols:
  1150. // - by names for symbols in the resident name table
  1151. // - by ordinal for symbols in the non-resident name table
  1152. export(pch, pch, (word)(fNoRes ? eno : 0), (word)0);
  1153. }
  1154. else if (!fNoRes)
  1155. strncpy(sbModule, buffer, buffer[0] + 1);
  1156. /* eno == 0 && !fNoRes --> module name */
  1157. }
  1158. if (cbTable != 0)
  1159. Error(ER_baddll);
  1160. free(pTable);
  1161. }
  1162. /*** ProcessDLL - extract information about exports from DLL
  1163. *
  1164. * Purpose:
  1165. * Read in header of DLL and create list of exported entries.
  1166. *
  1167. * Input:
  1168. * lfahdr - seek offset to segmented executable header.
  1169. *
  1170. * Output:
  1171. * List of exported entries by DLL.
  1172. *
  1173. * Exceptions:
  1174. * None.
  1175. *
  1176. * Notes:
  1177. * None.
  1178. *
  1179. *************************************************************************/
  1180. LOCAL void ProcessDLL(long lfahdr)
  1181. {
  1182. struct new_exe hdr; /* .EXE header */
  1183. if (fseek(fi, lfahdr, SEEK_SET) == -1) {
  1184. return;
  1185. }
  1186. if (fread(&hdr, sizeof(char), sizeof(struct new_exe), fi) != sizeof(struct new_exe)) {
  1187. return;
  1188. }
  1189. if(NE_CSEG(hdr) != 0)
  1190. {
  1191. /* If there are segments - read in tables */
  1192. if (NE_MODTAB(hdr) > NE_RESTAB(hdr))
  1193. {
  1194. /* Process resident names table */
  1195. if (fseek(fi, lfahdr + NE_RESTAB(hdr), SEEK_SET) == -1)
  1196. return;
  1197. ScanTable((word)(NE_MODTAB(hdr) - NE_RESTAB(hdr)), 0);
  1198. }
  1199. if (NE_CBNRESTAB(hdr) != 0)
  1200. {
  1201. /* Process non-resident names table */
  1202. if (fseek(fi, (long) NE_NRESTAB(hdr), SEEK_SET) == -1)
  1203. return;
  1204. ScanTable(NE_CBNRESTAB(hdr), 1);
  1205. }
  1206. }
  1207. }
  1208. /* Print usage message */
  1209. void usage(int fShortHelp)
  1210. {
  1211. int nRetCode;
  1212. #if NOT C8_IDE
  1213. // in C8 implib /? == /HELP
  1214. if (!fShortHelp)
  1215. {
  1216. nRetCode = spawnlp(P_WAIT, "qh", "qh", "/u implib.exe", NULL);
  1217. fShortHelp = nRetCode<0 || nRetCode==3;
  1218. }
  1219. if (fShortHelp)
  1220. #endif
  1221. {
  1222. DisplayBanner();
  1223. fprintf(stderr,"%s\n", GET_MSG(M_usage1));
  1224. fprintf(stderr,"%s\n", GET_MSG(M_usage2));
  1225. fprintf(stderr," %s\n", GET_MSG(M_usage3));
  1226. // fprintf(stderr," %s\n", GET_MSG(M_usage4));
  1227. fprintf(stderr," %s\n", GET_MSG(M_usage8));
  1228. fprintf(stderr," %s\n", GET_MSG(M_usage5));
  1229. fprintf(stderr," %s\n", GET_MSG(M_usage6));
  1230. fprintf(stderr," %s\n", GET_MSG(M_usage7));
  1231. }
  1232. exit(0);
  1233. }
  1234. void cdecl main(int argc, char *argv[]) /* Parse the definitions file */
  1235. {
  1236. int i; /* Counter */
  1237. long lfadic; /* File address of dictionary */
  1238. int iArg; /* Argument index */
  1239. word magic; /* Magic number */
  1240. struct exe_hdr exe; /* Old .EXE header */
  1241. int fNologo;
  1242. char drive[_MAX_DRIVE], dir[_MAX_DIR]; /* Needed for _splitpath */
  1243. char fname[_MAX_FNAME], ext[_MAX_EXT];
  1244. int fDefdllfound = 0; /* Flag will be set if the user
  1245. specifies dll/def file */
  1246. #if C8_IDE
  1247. char *pIDE = getenv("_MSC_IDE_FLAGS");
  1248. #endif
  1249. exitCode = 0;
  1250. fNologo = 0;
  1251. iArg = 1;
  1252. #if C8_IDE
  1253. if(pIDE)
  1254. {
  1255. if(strstr(pIDE, "FEEDBACK"))
  1256. {
  1257. fC8IDE = TRUE;
  1258. #if DEBUG_IDE
  1259. fprintf(stdout, "\r\nIDE ACTIVE - FEEDBACK is ON");
  1260. #endif
  1261. }
  1262. }
  1263. #endif
  1264. if (argc > 1)
  1265. {
  1266. while (iArg < argc && (argv[iArg][0] == '-' || argv[iArg][0] == '/'))
  1267. {
  1268. if (argv[iArg][1] == '?')
  1269. usage(1);
  1270. else if (IsPrefix(&argv[iArg][1], "help"))
  1271. usage(0);
  1272. else if(IsPrefix(&argv[iArg][1], "ignorecase"))
  1273. fIgnorecase = 1;
  1274. else if(IsPrefix(&argv[iArg][1], "noignorecase"))
  1275. fIgnorecase = 0;
  1276. else if(IsPrefix(&argv[iArg][1], "nologo"))
  1277. fNologo = 1;
  1278. else if(IsPrefix(&argv[iArg][1], "ntdll"))
  1279. fNTdll = 1;
  1280. else if(IsPrefix(&argv[iArg][1], "nowep"))
  1281. fIgnorewep = 1;
  1282. else
  1283. Error(ER_badoption, argv[iArg]);
  1284. iArg++;
  1285. }
  1286. }
  1287. else
  1288. {
  1289. DisplayBanner();
  1290. exit(exitCode); /* All done */
  1291. }
  1292. if (!fNologo)
  1293. DisplayBanner();
  1294. _splitpath( argv[iArg], drive, dir, fname, ext );
  1295. if(!_stricmp(ext,".DEF")||!_stricmp(ext,".DLL")) /* Ext. not allowed-bug #3*/
  1296. {
  1297. Fatal(ER_badtarget, ext);
  1298. }
  1299. #if C8_IDE
  1300. if(fC8IDE)
  1301. {
  1302. sprintf(msgBuf, "@I3%s\r\n", GET_MSG(M_IDEco));
  1303. _write(_fileno(stderr), msgBuf, strlen(msgBuf));
  1304. sprintf(msgBuf, "@I4%s\r\n", argv[iArg]);
  1305. _write(_fileno(stderr), msgBuf, strlen(msgBuf));
  1306. }
  1307. #endif
  1308. if((fo = fopen(argv[iArg],WRBIN)) == NULL)
  1309. { /* If open fails */
  1310. Fatal(ER_badcreate, argv[iArg], strerror(errno));
  1311. }
  1312. for(i = 0; i < 16; ++i) fputc(0,fo);/* Skip zeroth page for now */
  1313. chkerror();
  1314. implist = NULL; /* Initialize */
  1315. csyms = 0;
  1316. cbsyms = 0L;
  1317. #if C8_IDE
  1318. if(fC8IDE)
  1319. {
  1320. sprintf(msgBuf, "@I3%s\r\n", GET_MSG(M_IDEri));
  1321. _write(_fileno(stderr), msgBuf, strlen(msgBuf));
  1322. }
  1323. #endif
  1324. for(iArg++; iArg < argc; ++iArg)
  1325. {
  1326. if (argv[iArg][0] == '-' || argv[iArg][0] == '/')
  1327. {
  1328. fIgnorecase = IsPrefix(&argv[iArg][1], "ignorecase");
  1329. iArg++;
  1330. continue;
  1331. }
  1332. #if C8_IDE
  1333. if(fC8IDE)
  1334. {
  1335. sprintf(msgBuf, "@I4%s\r\n",argv[iArg]);
  1336. _write(_fileno(stderr), msgBuf, strlen(msgBuf));
  1337. }
  1338. #endif
  1339. if((fi = fopen(defname = argv[iArg],RDBIN)) == NULL)
  1340. { /* If open fails */
  1341. Fatal(ER_badopen, argv[iArg], strerror(errno));
  1342. /* Print error message */
  1343. }
  1344. fDefdllfound = 1;
  1345. newimps = NULL; /* Initialize */
  1346. lastimp = NULL; /* Initialize */
  1347. csymsmod = 0; /* Initialize */
  1348. if (fread(&exe, 1, sizeof(struct exe_hdr), fi))
  1349. Fatal(ER_baddll1, argv[iArg]);
  1350. /* Read old .EXE header */
  1351. if(E_MAGIC(exe) == EMAGIC) /* If old header found */
  1352. {
  1353. if(E_LFARLC(exe) == sizeof(struct exe_hdr))
  1354. {
  1355. if(fseek(fi, E_LFANEW(exe), 0))
  1356. Fatal(ER_baddll1, argv[iArg]);
  1357. /* Read magic number */
  1358. magic = (word) (getc(fi) & 0xff);
  1359. magic += (word) ((getc(fi) & 0xff) << 8);
  1360. if (magic == NEMAGIC)
  1361. ProcessDLL(E_LFANEW(exe));
  1362. /* Scan .DLL */
  1363. else
  1364. {
  1365. Error(ER_baddll1, argv[iArg]);
  1366. }
  1367. }
  1368. else
  1369. {
  1370. Error(ER_baddll1, argv[iArg]);
  1371. }
  1372. }
  1373. else
  1374. {
  1375. if (fseek(fi, 0L, SEEK_SET))
  1376. Fatal(ER_baddll1, argv[iArg]);
  1377. yyparse(); /* Parse the definitions file */
  1378. }
  1379. fclose(fi); /* Close the definitions file */
  1380. if(newimps != NULL) /* If at least one new IMPDEF */
  1381. {
  1382. outimpdefs(); /* Output the library modules */
  1383. I_NEXT(*lastimp) = implist; /* Concatenate lists */
  1384. implist = newimps; /* New head of list */
  1385. csyms += csymsmod; /* Increment symbol count */
  1386. }
  1387. }
  1388. if (!fDefdllfound) /* No .def or .dll source was given */
  1389. Fatal(ER_nosource);
  1390. if(i = (int)((ftell(fo) + 4) & (PAGLEN - 1))) i = PAGLEN - i;
  1391. /* Calculate padding needed */
  1392. ++i; /* One for the checksum */
  1393. fputc(DICHDR,fo); /* Dictionary header */
  1394. fputc(i & 0xFF,fo); /* Lo-byte */
  1395. fputc(i >> 8,fo); /* Hi-byte */
  1396. while(i--) fputc(0,fo); /* Padding */
  1397. lfadic = ftell(fo); /* Get dictionary offset */
  1398. writedic(); /* Write the dictionary */
  1399. if (fseek(fo,0L,0)) /* Seek to header */
  1400. Fatal(ER_baddll1, argv[iArg]);
  1401. fputc(LIBHDR,fo); /* Library header */
  1402. fputc(13,fo); /* Length */
  1403. fputc(0,fo); /* Length */
  1404. fputc((int)(lfadic & 0xFF),fo); /* Dictionary offset */
  1405. fputc((int)((lfadic >> 8) & 0xFF),fo);
  1406. /* Dictionary offset */
  1407. fputc((int)((lfadic >> 16) & 0xFF),fo);
  1408. /* Dictionary offset */
  1409. fputc((int)(lfadic >> 24),fo); /* Dictionary offset */
  1410. fputc(diclength & 0xFF,fo); /* Dictionary length */
  1411. fputc(diclength >> 8,fo); /* Dictionary length */
  1412. if (fIgnorecase) /* Dictionary case sensivity */
  1413. fputc(0, fo);
  1414. else
  1415. fputc(1, fo);
  1416. chkerror();
  1417. fclose(fo); /* Close the library */
  1418. exit(exitCode); /* All done */
  1419. }
  1420. short yyexca[] ={
  1421. -1, 1,
  1422. 0, -1,
  1423. -2, 0,
  1424. };
  1425. # define YYNPROD 185
  1426. # define YYLAST 413
  1427. short yyact[]={
  1428. 10, 13, 14, 170, 27, 134, 135, 136, 137, 225,
  1429. 140, 143, 144, 143, 144, 149, 41, 208, 128, 189,
  1430. 167, 41, 166, 28, 185, 50, 49, 29, 30, 31,
  1431. 12, 32, 34, 35, 218, 219, 187, 48, 210, 157,
  1432. 41, 101, 205, 161, 221, 33, 215, 11, 223, 112,
  1433. 113, 114, 115, 116, 119, 217, 53, 51, 117, 118,
  1434. 54, 122, 121, 123, 15, 73, 124, 125, 126, 206,
  1435. 192, 178, 131, 46, 42, 45, 16, 36, 17, 42,
  1436. 37, 81, 82, 79, 66, 67, 71, 61, 74, 62,
  1437. 68, 63, 69, 72, 76, 77, 78, 75, 42, 102,
  1438. 4, 5, 154, 195, 6, 7, 220, 194, 181, 88,
  1439. 169, 60, 142, 133, 129, 109, 59, 106, 156, 58,
  1440. 52, 9, 164, 83, 84, 96, 97, 73, 139, 162,
  1441. 47, 99, 127, 98, 120, 55, 70, 64, 65, 86,
  1442. 80, 95, 94, 92, 93, 87, 66, 67, 71, 61,
  1443. 74, 62, 68, 63, 69, 72, 76, 77, 78, 75,
  1444. 47, 89, 90, 91, 103, 104, 8, 191, 130, 111,
  1445. 38, 108, 216, 204, 203, 105, 180, 150, 179, 153,
  1446. 100, 85, 57, 26, 25, 24, 23, 96, 97, 73,
  1447. 22, 21, 20, 19, 18, 141, 148, 176, 70, 64,
  1448. 65, 146, 87, 95, 94, 81, 82, 79, 66, 67,
  1449. 71, 61, 74, 62, 68, 63, 69, 72, 76, 77,
  1450. 78, 75, 107, 155, 158, 151, 160, 39, 43, 159,
  1451. 152, 174, 44, 138, 40, 152, 152, 132, 3, 2,
  1452. 56, 1, 224, 214, 186, 0, 168, 83, 84, 0,
  1453. 172, 0, 0, 0, 173, 0, 110, 0, 0, 0,
  1454. 70, 64, 65, 184, 80, 183, 0, 171, 145, 147,
  1455. 182, 0, 0, 0, 0, 175, 0, 177, 0, 193,
  1456. 197, 0, 196, 199, 0, 201, 0, 0, 0, 202,
  1457. 184, 0, 183, 0, 0, 0, 0, 182, 0, 0,
  1458. 0, 209, 0, 198, 211, 200, 212, 0, 213, 0,
  1459. 0, 0, 0, 0, 0, 222, 0, 0, 0, 0,
  1460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1461. 0, 110, 0, 0, 0, 0, 0, 0, 0, 0,
  1462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1463. 163, 165, 0, 0, 0, 0, 0, 0, 0, 0,
  1464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1466. 188, 0, 0, 0, 0, 190, 0, 0, 0, 0,
  1467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1469. 0, 0, 207 };
  1470. short yypact[]={
  1471. -159,-1000,-267,-267,-225,-225,-187,-189,-267,-1000,
  1472. -286,-297,-266,-210,-210,-1000,-1000,-225,-1000,-1000,
  1473. -1000,-1000,-1000,-1000,-1000,-1000,-1000, -68,-130,-224,
  1474. -224,-224,-225,-225,-252,-241,-307,-194,-267,-1000,
  1475. -333,-1000,-1000,-1000,-325,-225,-225,-1000,-1000,-1000,
  1476. -1000,-1000,-1000,-311,-1000,-1000,-1000, -68,-1000,-1000,
  1477. -1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
  1478. -1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
  1479. -1000,-1000,-1000,-1000,-1000,-130,-1000,-1000,-1000,-1000,
  1480. -1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-224,-1000,
  1481. -156,-1000,-1000,-224,-224,-225,-1000,-280,-225,-1000,
  1482. -280,-194,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-235,
  1483. -1000,-1000,-1000,-1000,-1000,-1000,-1000,-225,-244,-1000,
  1484. -304,-1000,-333,-339,-1000,-1000,-1000,-1000,-325,-339,
  1485. -1000,-323,-1000,-1000,-1000,-1000,-325,-1000,-325,-195,
  1486. -1000,-1000,-1000,-192,-299,-1000,-284,-225,-1000,-305,
  1487. -1000,-1000,-225,-1000,-1000,-1000,-1000,-196,-339,-158,
  1488. -1000,-339,-158,-1000,-325,-158,-325,-158,-1000,-1000,
  1489. -192,-1000,-1000,-1000,-1000,-1000,-271,-197,-1000,-249,
  1490. -1000,-1000,-1000,-158,-1000,-281,-158,-1000,-158,-1000,
  1491. -158,-1000,-1000,-226,-211,-1000,-287,-228,-228,-1000,
  1492. -218,-1000,-1000,-1000,-332,-1000,-1000,-1000,-1000,-1000,
  1493. -1000,-1000,-1000,-1000,-1000,-1000 };
  1494. short yypgo[]={
  1495. 0, 222, 118, 244, 243, 242, 241, 239, 166, 238,
  1496. 237, 113, 110, 107, 234, 233, 128, 232, 231, 201,
  1497. 197, 196, 195, 112, 121, 120, 194, 193, 192, 191,
  1498. 190, 186, 185, 184, 183, 182, 119, 116, 111, 181,
  1499. 139, 109, 133, 131, 180, 179, 178, 108, 176, 175,
  1500. 117, 174, 173, 172, 171, 115, 106, 169, 114, 168,
  1501. 167, 134, 132, 129, 122 };
  1502. short yyr1[]={
  1503. 0, 6, 6, 9, 6, 10, 7, 14, 7, 15,
  1504. 7, 17, 7, 18, 7, 19, 7, 20, 7, 21,
  1505. 7, 16, 16, 16, 22, 22, 23, 23, 13, 13,
  1506. 11, 11, 11, 11, 11, 12, 12, 8, 8, 24,
  1507. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  1508. 24, 24, 24, 24, 24, 24, 24, 25, 25, 25,
  1509. 26, 35, 35, 36, 36, 38, 38, 38, 38, 38,
  1510. 38, 27, 39, 39, 40, 40, 40, 40, 40, 40,
  1511. 40, 41, 41, 41, 41, 28, 28, 28, 28, 28,
  1512. 28, 42, 42, 43, 44, 44, 45, 45, 47, 47,
  1513. 47, 48, 48, 46, 46, 37, 37, 37, 37, 37,
  1514. 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
  1515. 37, 37, 37, 29, 29, 49, 49, 50, 2, 2,
  1516. 3, 3, 3, 3, 51, 52, 52, 53, 53, 4,
  1517. 4, 5, 5, 30, 30, 54, 54, 55, 55, 1,
  1518. 1, 56, 56, 31, 31, 57, 57, 57, 57, 57,
  1519. 57, 57, 57, 57, 58, 58, 59, 59, 60, 60,
  1520. 34, 32, 61, 61, 61, 61, 61, 61, 33, 62,
  1521. 62, 64, 64, 63, 63 };
  1522. short yyr2[]={
  1523. 0, 2, 1, 0, 2, 0, 6, 0, 5, 0,
  1524. 6, 0, 5, 0, 6, 0, 5, 0, 6, 0,
  1525. 5, 1, 1, 0, 2, 1, 1, 1, 3, 0,
  1526. 1, 1, 1, 1, 0, 1, 0, 2, 1, 2,
  1527. 2, 2, 2, 2, 2, 1, 1, 2, 1, 1,
  1528. 1, 1, 1, 1, 1, 1, 1, 3, 1, 1,
  1529. 2, 2, 1, 1, 1, 1, 1, 1, 1, 1,
  1530. 1, 2, 2, 1, 1, 1, 1, 1, 1, 1,
  1531. 1, 1, 1, 1, 1, 2, 1, 2, 1, 2,
  1532. 1, 2, 1, 3, 1, 1, 2, 0, 1, 1,
  1533. 1, 2, 1, 1, 0, 1, 1, 1, 1, 1,
  1534. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1535. 1, 1, 1, 2, 1, 2, 1, 6, 2, 0,
  1536. 3, 3, 2, 0, 2, 1, 0, 1, 0, 1,
  1537. 0, 1, 0, 2, 1, 2, 1, 5, 5, 1,
  1538. 1, 1, 0, 3, 1, 1, 1, 1, 1, 1,
  1539. 1, 1, 2, 1, 3, 1, 1, 0, 1, 0,
  1540. 2, 2, 1, 1, 1, 1, 1, 1, 3, 2,
  1541. 0, 1, 1, 2, 1 };
  1542. short yychk[]={
  1543. -1000, -6, -7, -9, 259, 260, 263, 264, -8, -24,
  1544. 267, 314, 297, 268, 269, 331, 343, 345, -26, -27,
  1545. -28, -29, -30, -31, -32, -33, -34, 271, 290, 294,
  1546. 295, 296, 298, 312, 299, 300, 344, 347, -8, -1,
  1547. -14, 265, 323, -1, -17, 262, 262, -24, 323, 323,
  1548. 291, 323, -25, 266, 270, -25, -1, -35, -36, -37,
  1549. -38, 279, 281, 283, 329, 330, 276, 277, 282, 284,
  1550. 328, 278, 285, 257, 280, 289, 286, 287, 288, 275,
  1551. 332, 273, 274, 315, 316, -39, -40, -37, -41, 291,
  1552. 292, 293, 273, 274, 334, 333, 317, 318, -42, -43,
  1553. -44, 265, 323, -42, -42, -49, -50, -1, -54, -55,
  1554. -1, -57, 301, 302, 303, 304, 305, 310, 311, 306,
  1555. -61, 303, 302, 304, 307, 308, 309, -62, 325, -58,
  1556. -59, 266, -10, -11, 338, 339, 340, 341, -15, -16,
  1557. 335, -22, -23, 336, 337, -1, -19, -1, -21, 326,
  1558. -36, -40, -43, -45, 258, -50, -2, 319, -55, -2,
  1559. -58, 278, -63, -1, -64, -1, 266, 324, -11, -12,
  1560. 342, -16, -12, -23, -18, -16, -20, -16, 266, -46,
  1561. -48, -47, -37, -38, -41, 323, -3, 320, -1, 324,
  1562. -1, -60, 266, -12, -13, 261, -12, -13, -16, -13,
  1563. -16, -13, -47, -51, -52, 313, 266, -1, 266, -13,
  1564. 319, -13, -13, -13, -4, 272, -53, 266, 321, 322,
  1565. -56, 272, -56, 266, -5, 341 };
  1566. short yydef[]={
  1567. 3, -2, 2, 0, 7, 11, 0, 0, 1, 38,
  1568. 0, 0, 0, 0, 0, 45, 46, 0, 48, 49,
  1569. 50, 51, 52, 53, 54, 55, 56, 0, 0, 86,
  1570. 88, 90, 124, 144, 154, 0, 180, 167, 4, 5,
  1571. 34, 149, 150, 9, 23, 15, 19, 37, 39, 40,
  1572. 41, 42, 43, 58, 59, 44, 47, 60, 62, 63,
  1573. 64, 105, 106, 107, 108, 109, 110, 111, 112, 113,
  1574. 114, 115, 116, 117, 118, 119, 120, 121, 122, 65,
  1575. 66, 67, 68, 69, 70, 71, 73, 74, 75, 76,
  1576. 77, 78, 79, 80, 81, 82, 83, 84, 85, 92,
  1577. 97, 94, 95, 87, 89, 123, 126, 129, 143, 146,
  1578. 129, 167, 155, 156, 157, 158, 159, 160, 161, 163,
  1579. 171, 172, 173, 174, 175, 176, 177, 0, 0, 170,
  1580. 165, 166, 34, 36, 30, 31, 32, 33, 23, 36,
  1581. 21, 22, 25, 26, 27, 13, 23, 17, 23, 0,
  1582. 61, 72, 91, 104, 0, 125, 133, 0, 145, 0,
  1583. 153, 162, 178, 184, 179, 181, 182, 169, 36, 29,
  1584. 35, 36, 29, 24, 23, 29, 23, 29, 57, 93,
  1585. 103, 102, 98, 99, 100, 96, 136, 0, 128, 0,
  1586. 183, 164, 168, 29, 8, 0, 29, 12, 29, 16,
  1587. 29, 20, 101, 140, 138, 135, 132, 152, 152, 6,
  1588. 0, 10, 14, 18, 142, 139, 134, 137, 130, 131,
  1589. 147, 151, 148, 28, 127, 141 };
  1590. # define YYFLAG -1000
  1591. # define YYERROR goto yyerrlab
  1592. # define YYACCEPT return(0)
  1593. # define YYABORT return(1)
  1594. #ifdef YYDEBUG /* RRR - 10/9/85 */
  1595. #define yyprintf(a, b, c) printf(a, b, c)
  1596. #else
  1597. #define yyprintf(a, b, c)
  1598. #endif
  1599. /* parser for yacc output */
  1600. YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
  1601. int yychar = -1; /* current input token number */
  1602. int yynerrs = 0; /* number of errors */
  1603. short yyerrflag = 0; /* error recovery flag */
  1604. int NEAR yyparse(void)
  1605. {
  1606. short yys[YYMAXDEPTH];
  1607. short yyj, yym;
  1608. register YYSTYPE *yypvt;
  1609. register short yystate, *yyps, yyn;
  1610. register YYSTYPE *yypv;
  1611. register short *yyxi;
  1612. yystate = 0;
  1613. yychar = -1;
  1614. yynerrs = 0;
  1615. yyerrflag = 0;
  1616. yyps= &yys[-1];
  1617. yypv= &yyv[-1];
  1618. yystack: /* put a state and value onto the stack */
  1619. yyprintf( "state %d, char 0%o\n", yystate, yychar );
  1620. if( ++yyps> &yys[YYMAXDEPTH] )
  1621. {
  1622. yyerror( "yacc stack overflow" );
  1623. return(1);
  1624. }
  1625. *yyps = yystate;
  1626. ++yypv;
  1627. *yypv = yyval;
  1628. yynewstate:
  1629. yyn = yypact[yystate];
  1630. if( yyn<= YYFLAG ) goto yydefault; /* simple state */
  1631. if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
  1632. if( (yyn += (short)yychar)<0 || yyn >= YYLAST ) goto yydefault;
  1633. if( yychk[ yyn=yyact[ yyn ] ] == yychar )
  1634. {
  1635. /* valid shift */
  1636. yychar = -1;
  1637. yyval = yylval;
  1638. yystate = yyn;
  1639. if( yyerrflag > 0 ) --yyerrflag;
  1640. goto yystack;
  1641. }
  1642. yydefault:
  1643. /* default state action */
  1644. if( (yyn=yydef[yystate]) == -2 )
  1645. {
  1646. if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
  1647. /* look through exception table */
  1648. for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
  1649. for(yyxi+=2; *yyxi >= 0; yyxi+=2)
  1650. {
  1651. if( *yyxi == yychar ) break;
  1652. }
  1653. if( (yyn = yyxi[1]) < 0 ) return(0); /* accept */
  1654. }
  1655. if( yyn == 0 )
  1656. {
  1657. /* error */
  1658. /* error ... attempt to resume parsing */
  1659. switch( yyerrflag )
  1660. {
  1661. case 0: /* brand new error */
  1662. yyerror( "syntax error" );
  1663. ++yynerrs;
  1664. case 1:
  1665. case 2: /* incompletely recovered error ... try again */
  1666. yyerrflag = 3;
  1667. /* find a state where "error" is a legal shift action */
  1668. while ( yyps >= yys )
  1669. {
  1670. yyn = yypact[*yyps] + YYERRCODE;
  1671. if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE )
  1672. {
  1673. yystate = yyact[yyn]; /* simulate a shift of "error" */
  1674. goto yystack;
  1675. }
  1676. yyn = yypact[*yyps];
  1677. /* the current yyps has no shift onn "error", pop stack */
  1678. yyprintf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
  1679. --yyps;
  1680. --yypv;
  1681. }
  1682. /* there is no state on the stack with an error shift ... abort */
  1683. yyabort:
  1684. return(1);
  1685. case 3: /* no shift yet; clobber input char */
  1686. yyprintf( "error recovery discards char %d\n", yychar, 0 );
  1687. if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
  1688. yychar = -1;
  1689. goto yynewstate; /* try again in the same state */
  1690. }
  1691. }
  1692. /* reduction by production yyn */
  1693. yyprintf("reduce %d\n",yyn, 0);
  1694. yyps -= yyr2[yyn];
  1695. yypvt = yypv;
  1696. yypv -= yyr2[yyn];
  1697. yyval = yypv[1];
  1698. yym=yyn;
  1699. /* consult goto table to find next state */
  1700. yyn = yyr1[yyn];
  1701. yyj = yypgo[yyn] + *yyps + 1;
  1702. if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
  1703. switch(yym)
  1704. {
  1705. case 3:
  1706. {
  1707. DefaultModule(moduleEXE);
  1708. } break;
  1709. case 5:
  1710. {
  1711. fFileNameExpected = 0;
  1712. } break;
  1713. case 6:
  1714. {
  1715. NewModule(yypvt[-4]._bp, moduleEXE);
  1716. } break;
  1717. case 7:
  1718. {
  1719. fFileNameExpected = 0;
  1720. } break;
  1721. case 8:
  1722. {
  1723. DefaultModule(moduleEXE);
  1724. } break;
  1725. case 9:
  1726. {
  1727. fFileNameExpected = 0;
  1728. } break;
  1729. case 10:
  1730. {
  1731. NewModule(yypvt[-4]._bp, moduleDLL);
  1732. } break;
  1733. case 11:
  1734. {
  1735. fFileNameExpected = 0;
  1736. } break;
  1737. case 12:
  1738. {
  1739. DefaultModule(moduleDLL);
  1740. } break;
  1741. case 13:
  1742. {
  1743. fFileNameExpected = 0;
  1744. } break;
  1745. case 14:
  1746. {
  1747. NewModule(yypvt[-3]._bp, moduleDLL);
  1748. } break;
  1749. case 15:
  1750. {
  1751. fFileNameExpected = 0;
  1752. } break;
  1753. case 16:
  1754. {
  1755. DefaultModule(moduleDLL);
  1756. } break;
  1757. case 17:
  1758. {
  1759. fFileNameExpected = 0;
  1760. } break;
  1761. case 18:
  1762. {
  1763. NewModule(yypvt[-3]._bp, moduleDLL);
  1764. } break;
  1765. case 19:
  1766. {
  1767. fFileNameExpected = 0;
  1768. } break;
  1769. case 20:
  1770. {
  1771. DefaultModule(moduleDLL);
  1772. } break;
  1773. case 21:
  1774. {
  1775. } break;
  1776. case 127:
  1777. {
  1778. if (yypvt[-0]._wd)
  1779. {
  1780. // Skip private exports
  1781. free(yypvt[-5]._bp);
  1782. free(yypvt[-4]._bp);
  1783. }
  1784. else
  1785. export(yypvt[-5]._bp,yypvt[-4]._bp,yypvt[-3]._wd,yypvt[-1]._wd);
  1786. } break;
  1787. case 128:
  1788. {
  1789. yyval._bp = yypvt[-0]._bp;
  1790. } break;
  1791. case 129:
  1792. {
  1793. yyval._bp = NULL;
  1794. } break;
  1795. case 130:
  1796. {
  1797. yyval._wd = yypvt[-1]._wd;
  1798. } break;
  1799. case 131:
  1800. {
  1801. yyval._wd = yypvt[-1]._wd;
  1802. } break;
  1803. case 132:
  1804. {
  1805. yyval._wd = yypvt[-0]._wd;
  1806. } break;
  1807. case 133:
  1808. {
  1809. yyval._wd = 0;
  1810. } break;
  1811. case 139:
  1812. {
  1813. yyval._wd = 0x1;
  1814. } break;
  1815. case 140:
  1816. {
  1817. yyval._wd = 0;
  1818. } break;
  1819. case 141:
  1820. {
  1821. yyval._wd = 1;
  1822. } break;
  1823. case 142:
  1824. {
  1825. yyval._wd = 0;
  1826. } break;
  1827. case 149:
  1828. {
  1829. yyval._bp = _strdup(rgbid);
  1830. } break;
  1831. case 150:
  1832. {
  1833. yyval._bp = _strdup(rgbid);
  1834. } break;/* End of actions */
  1835. }
  1836. goto yystack; /* stack new state and value */
  1837. }