Source code of Windows XP (NT5)
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.

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