Changeset 3167 for trunk/src/kmk/kmkbuiltin
- Timestamp:
- Mar 20, 2018, 10:47:25 PM (7 years ago)
- Location:
- trunk/src/kmk/kmkbuiltin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/kDepIDB.c
r3159 r3167 24 24 */ 25 25 26 /******************************************************************************* 27 * Header Files * 28 *******************************************************************************/ 26 27 /********************************************************************************************************************************* 28 * Header Files * 29 *********************************************************************************************************************************/ 29 30 #include "config.h" 30 31 #include <stdio.h> … … 48 49 49 50 50 /******************************************************************************* 51 * Defined Constants And Macros *52 ******************************************************************************* /51 /********************************************************************************************************************************* 52 * Defined Constants And Macros * 53 *********************************************************************************************************************************/ 53 54 /*#define DEBUG*/ 54 55 #ifdef DEBUG … … 60 61 #endif 61 62 62 63 /******************************************************************************* 64 * Global Variables * 65 *******************************************************************************/ 66 /** the executable name. */ 67 static const char *argv0 = ""; 63 /********************************************************************************************************************************* 64 * Structures and Typedefs * 65 *********************************************************************************************************************************/ 66 typedef struct KDEPIDBGLOBALS 67 { 68 DEPGLOBALS Core; 69 const char *argv0; 70 } KDEPIDBGLOBALS; 71 typedef KDEPIDBGLOBALS *PKDEPIDBGLOBALS; 68 72 69 73 … … 73 77 * @returns 0 on success. 74 78 * @returns !0 on failure. 79 * @param pThis The kDepIDB instance. 75 80 * @param pbStream The stream bits. 76 81 * @param cbStream The size of the stream. … … 78 83 * @param cchPrefix The size of the prefix. 79 84 */ 80 static int ScanStream( KU8 *pbStream, size_t cbStream, const char *pszPrefix, size_t cchPrefix)85 static int ScanStream(PKDEPIDBGLOBALS pThis, KU8 *pbStream, size_t cbStream, const char *pszPrefix, size_t cchPrefix) 81 86 { 82 87 const KU8 *pbCur = pbStream; … … 96 101 pbCur += cchPrefix; 97 102 cchDep = strlen((const char *)pbCur); 98 depAdd( (const char *)pbCur, cchDep);103 depAdd(&pThis->Core, (const char *) pbCur, cchDep); 99 104 dprintf(("%05x: '%s'\n", pbCur - pbStream, pbCur)); 100 105 … … 189 194 190 195 191 static int Pdb70ValidateHeader(P PDB70HDR pHdr, size_t cbFile)196 static int Pdb70ValidateHeader(PKDEPIDBGLOBALS pThis, PPDB70HDR pHdr, size_t cbFile) 192 197 { 193 198 if (pHdr->cbPage * pHdr->cPages != cbFile) 194 199 { 195 fprintf(stderr, "%s: error: Bad PDB 2.0 header - cbPage * cPages != cbFile.\n", argv0);200 fprintf(stderr, "%s: error: Bad PDB 2.0 header - cbPage * cPages != cbFile.\n", pThis->argv0); 196 201 return 1; 197 202 } 198 203 if (pHdr->iStartPage >= pHdr->cPages && pHdr->iStartPage <= 0) 199 204 { 200 fprintf(stderr, "%s: error: Bad PDB 2.0 header - iStartPage=%u cPages=%u.\n", argv0,205 fprintf(stderr, "%s: error: Bad PDB 2.0 header - iStartPage=%u cPages=%u.\n", pThis->argv0, 201 206 pHdr->iStartPage, pHdr->cPages); 202 207 return 1; … … 204 209 if (pHdr->iRootPages >= pHdr->cPages && pHdr->iRootPages <= 0) 205 210 { 206 fprintf(stderr, "%s: error: Bad PDB 2.0 header - iRootPages=%u cPage=%u.\n", argv0,211 fprintf(stderr, "%s: error: Bad PDB 2.0 header - iRootPages=%u cPage=%u.\n", pThis->argv0, 207 212 pHdr->iStartPage, pHdr->cPages); 208 213 return 1; … … 227 232 } 228 233 229 static void *Pdb70AllocAndRead(P PDB70HDR pHdr, size_t cb, PPDB70PAGE paiPageMap)234 static void *Pdb70AllocAndRead(PKDEPIDBGLOBALS pThis, PPDB70HDR pHdr, size_t cb, PPDB70PAGE paiPageMap) 230 235 { 231 236 const size_t cbPage = pHdr->cbPage; … … 246 251 else 247 252 { 248 fprintf(stderr, "%s: warning: Invalid page index %u (max %u)!\n", argv0,253 fprintf(stderr, "%s: warning: Invalid page index %u (max %u)!\n", pThis->argv0, 249 254 (unsigned)off, pHdr->cPages); 250 255 memset(pbBuf + iPage * cbPage, 0, cbPage); … … 256 261 } 257 262 else 258 fprintf(stderr, "%s: error: failed to allocate %lu bytes\n", argv0, (unsigned long)(cPages * cbPage + 1));263 fprintf(stderr, "%s: error: failed to allocate %lu bytes\n", pThis->argv0, (unsigned long)(cPages * cbPage + 1)); 259 264 return pbBuf; 260 265 } 261 266 262 static PPDB70ROOT Pdb70AllocAndReadRoot(P PDB70HDR pHdr)267 static PPDB70ROOT Pdb70AllocAndReadRoot(PKDEPIDBGLOBALS pThis, PPDB70HDR pHdr) 263 268 { 264 269 /* … … 267 272 */ 268 273 PPDB70PAGE piPageMap = (KU32 *)((KU8 *)pHdr + pHdr->iRootPages * pHdr->cbPage); 269 PPDB70ROOT pRoot = Pdb70AllocAndRead(p Hdr, pHdr->cbRoot, piPageMap);274 PPDB70ROOT pRoot = Pdb70AllocAndRead(pThis, pHdr, pHdr->cbRoot, piPageMap); 270 275 if (pRoot) 271 276 { … … 275 280 size_t cb = K_OFFSETOF(PDB70ROOT, aStreams[pRoot->cStreams]); 276 281 free(pRoot); 277 pRoot = Pdb70AllocAndRead(p Hdr, cb, piPageMap);282 pRoot = Pdb70AllocAndRead(pThis, pHdr, cb, piPageMap); 278 283 if (pRoot) 279 284 { … … 284 289 cb += Pdb70Pages(pHdr, pRoot->aStreams[iStream].cbStream) * sizeof(PDB70PAGE); 285 290 free(pRoot); 286 pRoot = Pdb70AllocAndRead(p Hdr, cb, piPageMap);291 pRoot = Pdb70AllocAndRead(pThis, pHdr, cb, piPageMap); 287 292 if (pRoot) 288 293 { … … 299 304 } 300 305 301 static void *Pdb70AllocAndReadStream(P PDB70HDR pHdr, PPDB70ROOT pRoot, unsigned iStream, size_t *pcbStream)306 static void *Pdb70AllocAndReadStream(PKDEPIDBGLOBALS pThis, PPDB70HDR pHdr, PPDB70ROOT pRoot, unsigned iStream, size_t *pcbStream) 302 307 { 303 308 const size_t cbStream = pRoot->aStreams[iStream].cbStream; … … 306 311 || cbStream == ~(KU32)0) 307 312 { 308 fprintf(stderr, "%s: error: Invalid stream %d\n", argv0, iStream);313 fprintf(stderr, "%s: error: Invalid stream %d\n", pThis->argv0, iStream); 309 314 return NULL; 310 315 } … … 317 322 if (pcbStream) 318 323 *pcbStream = cbStream; 319 return Pdb70AllocAndRead(p Hdr, cbStream, paiPageMap);320 } 321 322 static int Pdb70Process( KU8 *pbFile, size_t cbFile)324 return Pdb70AllocAndRead(pThis, pHdr, cbStream, paiPageMap); 325 } 326 327 static int Pdb70Process(PKDEPIDBGLOBALS pThis, KU8 *pbFile, size_t cbFile) 323 328 { 324 329 PPDB70HDR pHdr = (PPDB70HDR)pbFile; … … 334 339 * Validate the header and read the root stream. 335 340 */ 336 if (Pdb70ValidateHeader(p Hdr, cbFile))337 return 1; 338 pRoot = Pdb70AllocAndReadRoot(p Hdr);341 if (Pdb70ValidateHeader(pThis, pHdr, cbFile)) 342 return 1; 343 pRoot = Pdb70AllocAndReadRoot(pThis, pHdr); 339 344 if (!pRoot) 340 345 return 1; … … 344 349 */ 345 350 dprintf(("Reading the names stream....\n")); 346 pNames = Pdb70AllocAndReadStream(p Hdr, pRoot, 1, &cbStream);351 pNames = Pdb70AllocAndReadStream(pThis, pHdr, pRoot, 1, &cbStream); 347 352 if (pNames) 348 353 { … … 366 371 && !memcmp(psz, "/mr/inversedeps/", sizeof("/mr/inversedeps/") - 1)) 367 372 { 368 depAdd( psz + sizeof("/mr/inversedeps/") - 1, cch - (sizeof("/mr/inversedeps/") - 1));373 depAdd(&pThis->Core, psz + sizeof("/mr/inversedeps/") - 1, cch - (sizeof("/mr/inversedeps/") - 1)); 369 374 fAdded = 1; 370 375 } … … 408 413 dprintf(("Stream #%d: %#x bytes (%#x aligned)\n", iStream, pRoot->aStreams[iStream].cbStream, 409 414 Pdb70Align(pHdr, pRoot->aStreams[iStream].cbStream))); 410 pbStream = (KU8 *)Pdb70AllocAndReadStream(p Hdr, pRoot, iStream, &cbStream);415 pbStream = (KU8 *)Pdb70AllocAndReadStream(pThis, pHdr, pRoot, iStream, &cbStream); 411 416 if (pbStream) 412 417 { 413 rc = ScanStream(p bStream, cbStream, "/mr/inversedeps/", sizeof("/mr/inversedeps/") - 1);418 rc = ScanStream(pThis, pbStream, cbStream, "/mr/inversedeps/", sizeof("/mr/inversedeps/") - 1); 414 419 free(pbStream); 415 420 } … … 485 490 486 491 487 static int Pdb20ValidateHeader(P PDB20HDR pHdr, size_t cbFile)492 static int Pdb20ValidateHeader(PKDEPIDBGLOBALS pThis, PPDB20HDR pHdr, size_t cbFile) 488 493 { 489 494 if (pHdr->cbPage * pHdr->cPages != cbFile) 490 495 { 491 fprintf(stderr, "%s: error: Bad PDB 2.0 header - cbPage * cPages != cbFile.\n", argv0);496 fprintf(stderr, "%s: error: Bad PDB 2.0 header - cbPage * cPages != cbFile.\n", pThis->argv0); 492 497 return 1; 493 498 } 494 499 if (pHdr->iStartPage >= pHdr->cPages && pHdr->iStartPage <= 0) 495 500 { 496 fprintf(stderr, "%s: error: Bad PDB 2.0 header - cbPage * cPages != cbFile.\n", argv0);501 fprintf(stderr, "%s: error: Bad PDB 2.0 header - cbPage * cPages != cbFile.\n", pThis->argv0); 497 502 return 1; 498 503 } … … 507 512 } 508 513 509 static void *Pdb20AllocAndRead(P PDB20HDR pHdr, size_t cb, PPDB20PAGE paiPageMap)514 static void *Pdb20AllocAndRead(PKDEPIDBGLOBALS pThis, PPDB20HDR pHdr, size_t cb, PPDB20PAGE paiPageMap) 510 515 { 511 516 size_t cPages = Pdb20Pages(pHdr, cb); … … 524 529 } 525 530 else 526 fprintf(stderr, "%s: error: failed to allocate %lu bytes\n", argv0, (unsigned long)(cPages * pHdr->cbPage + 1));531 fprintf(stderr, "%s: error: failed to allocate %lu bytes\n", pThis->argv0, (unsigned long)(cPages * pHdr->cbPage + 1)); 527 532 return pbBuf; 528 533 } 529 534 530 static PPDB20ROOT Pdb20AllocAndReadRoot(P PDB20HDR pHdr)535 static PPDB20ROOT Pdb20AllocAndReadRoot(PKDEPIDBGLOBALS pThis, PPDB20HDR pHdr) 531 536 { 532 537 /* … … 534 539 * (Todo: Check if we can just use the stream size..) 535 540 */ 536 PPDB20ROOT pRoot = Pdb20AllocAndRead(p Hdr, sizeof(*pRoot), &pHdr->aiRootPageMap[0]);541 PPDB20ROOT pRoot = Pdb20AllocAndRead(pThis, pHdr, sizeof(*pRoot), &pHdr->aiRootPageMap[0]); 537 542 if (pRoot) 538 543 { … … 540 545 size_t cb = K_OFFSETOF(PDB20ROOT, aStreams[pRoot->cStreams]); 541 546 free(pRoot); 542 pRoot = Pdb20AllocAndRead(p Hdr, cb, &pHdr->aiRootPageMap[0]);547 pRoot = Pdb20AllocAndRead(pThis, pHdr, cb, &pHdr->aiRootPageMap[0]); 543 548 if (pRoot) 544 549 { … … 549 554 cb += Pdb20Pages(pHdr, pRoot->aStreams[iStream].cbStream) * sizeof(PDB20PAGE); 550 555 free(pRoot); 551 pRoot = Pdb20AllocAndRead(p Hdr, cb, &pHdr->aiRootPageMap[0]);556 pRoot = Pdb20AllocAndRead(pThis, pHdr, cb, &pHdr->aiRootPageMap[0]); 552 557 if (pRoot) 553 558 { … … 561 566 } 562 567 563 static void *Pdb20AllocAndReadStream(P PDB20HDR pHdr, PPDB20ROOT pRoot, unsigned iStream, size_t *pcbStream)568 static void *Pdb20AllocAndReadStream(PKDEPIDBGLOBALS pThis, PPDB20HDR pHdr, PPDB20ROOT pRoot, unsigned iStream, size_t *pcbStream) 564 569 { 565 570 size_t cbStream = pRoot->aStreams[iStream].cbStream; … … 568 573 || cbStream == ~(KU32)0) 569 574 { 570 fprintf(stderr, "%s: error: Invalid stream %d\n", argv0, iStream);575 fprintf(stderr, "%s: error: Invalid stream %d\n", pThis->argv0, iStream); 571 576 return NULL; 572 577 } … … 579 584 if (pcbStream) 580 585 *pcbStream = cbStream; 581 return Pdb20AllocAndRead(p Hdr, cbStream, paiPageMap);582 } 583 584 static int Pdb20Process( KU8 *pbFile, size_t cbFile)586 return Pdb20AllocAndRead(pThis, pHdr, cbStream, paiPageMap); 587 } 588 589 static int Pdb20Process(PKDEPIDBGLOBALS pThis, KU8 *pbFile, size_t cbFile) 585 590 { 586 591 PPDB20HDR pHdr = (PPDB20HDR)pbFile; … … 592 597 * Validate the header and read the root stream. 593 598 */ 594 if (Pdb20ValidateHeader(p Hdr, cbFile))595 return 1; 596 pRoot = Pdb20AllocAndReadRoot(p Hdr);599 if (Pdb20ValidateHeader(pThis, pHdr, cbFile)) 600 return 1; 601 pRoot = Pdb20AllocAndReadRoot(pThis, pHdr); 597 602 if (!pRoot) 598 603 return 1; … … 608 613 if (pRoot->aStreams[iStream].cbStream == ~(KU32)0) 609 614 continue; 610 pbStream = (KU8 *)Pdb20AllocAndReadStream(p Hdr, pRoot, iStream, NULL);615 pbStream = (KU8 *)Pdb20AllocAndReadStream(pThis, pHdr, pRoot, iStream, NULL); 611 616 if (pbStream) 612 617 { 613 rc = ScanStream(p bStream, pRoot->aStreams[iStream].cbStream, "/ipm/header/", sizeof("/ipm/header/") - 1);618 rc = ScanStream(pThis, pbStream, pRoot->aStreams[iStream].cbStream, "/ipm/header/", sizeof("/ipm/header/") - 1); 614 619 free(pbStream); 615 620 } … … 626 631 * Make an attempt at parsing a Visual C++ IDB file. 627 632 */ 628 static int ProcessIDB( FILE *pInput)633 static int ProcessIDB(PKDEPIDBGLOBALS pThis, FILE *pInput) 629 634 { 630 635 size_t cbFile; … … 644 649 */ 645 650 if (!memcmp(pbFile, PDB_SIGNATURE_700, sizeof(PDB_SIGNATURE_700))) 646 rc = Pdb70Process(p bFile, cbFile);651 rc = Pdb70Process(pThis, pbFile, cbFile); 647 652 else if (!memcmp(pbFile, PDB_SIGNATURE_200, sizeof(PDB_SIGNATURE_200))) 648 rc = Pdb20Process(p bFile, cbFile);653 rc = Pdb20Process(pThis, pbFile, cbFile); 649 654 else 650 655 { 651 fprintf(stderr, "%s: error: Doesn't recognize the header of the Visual C++ IDB file.\n", argv0);656 fprintf(stderr, "%s: error: Doesn't recognize the header of the Visual C++ IDB file.\n", pThis->argv0); 652 657 rc = 1; 653 658 } … … 658 663 659 664 660 static void usage(const char *a_argv0)665 static void kDepIDBUsage(const char *a_argv0) 661 666 { 662 667 printf("usage: %s -o <output> -t <target> [-fqs] <vc idb-file>\n" … … 669 674 int kmk_builtin_kDepIDB(int argc, char *argv[], char **envp) 670 675 { 671 int i; 676 int i; 677 KDEPIDBGLOBALS This; 672 678 673 679 /* Arguments. */ … … 682 688 int fQuiet = 0; 683 689 684 argv0 = argv[0]; 690 /* Init the instance data. */ 691 This.argv0 = argv[0]; 685 692 686 693 /* … … 689 696 if (argc <= 1) 690 697 { 691 usage(argv[0]);698 kDepIDBUsage(This.argv0); 692 699 return 1; 693 700 } … … 717 724 if (pOutput) 718 725 { 719 fprintf(stderr, "%s: syntax error: only one output file!\n", argv[0]);726 fprintf(stderr, "%s: syntax error: only one output file!\n", This.argv0); 720 727 return 1; 721 728 } … … 724 731 if (++i >= argc) 725 732 { 726 fprintf(stderr, "%s: syntax error: The '-o' argument is missing the filename.\n", argv[0]);733 fprintf(stderr, "%s: syntax error: The '-o' argument is missing the filename.\n", This.argv0); 727 734 return 1; 728 735 } … … 735 742 if (!pOutput) 736 743 { 737 fprintf(stderr, "%s: error: Failed to create output file '%s'.\n", argv[0], pszOutput);744 fprintf(stderr, "%s: error: Failed to create output file '%s'.\n", This.argv0, pszOutput); 738 745 return 1; 739 746 } … … 748 755 if (pszTarget) 749 756 { 750 fprintf(stderr, "%s: syntax error: only one target!\n", argv[0]);757 fprintf(stderr, "%s: syntax error: only one target!\n", This.argv0); 751 758 return 1; 752 759 } … … 756 763 if (++i >= argc) 757 764 { 758 fprintf(stderr, "%s: syntax error: The '-t' argument is missing the target name.\n", argv[0]);765 fprintf(stderr, "%s: syntax error: The '-t' argument is missing the target name.\n", This.argv0); 759 766 return 1; 760 767 } … … 795 802 */ 796 803 case '?': 797 usage(argv[0]);804 kDepIDBUsage(This.argv0); 798 805 return 0; 799 806 case 'V': 800 807 case 'v': 801 return kbuild_version( argv[0]);808 return kbuild_version(This.argv0); 802 809 803 810 /* … … 805 812 */ 806 813 default: 807 fprintf(stderr, "%s: syntax error: Invalid argument '%s'.\n", argv[0], argv[i]);808 usage(argv[0]);814 fprintf(stderr, "%s: syntax error: Invalid argument '%s'.\n", This.argv0, argv[i]); 815 kDepIDBUsage(This.argv0); 809 816 return 1; 810 817 } … … 815 822 if (!pInput) 816 823 { 817 fprintf(stderr, "%s: error: Failed to open input file '%s'.\n", argv[0], argv[i]);824 fprintf(stderr, "%s: error: Failed to open input file '%s'.\n", This.argv0, argv[i]); 818 825 return 1; 819 826 } … … 828 835 if (++i < argc) 829 836 { 830 fprintf(stderr, "%s: syntax error: No arguments shall follow the input spec.\n", argv[0]);837 fprintf(stderr, "%s: syntax error: No arguments shall follow the input spec.\n", This.argv0); 831 838 return 1; 832 839 } … … 840 847 if (!pInput) 841 848 { 842 fprintf(stderr, "%s: syntax error: No input!\n", argv[0]);849 fprintf(stderr, "%s: syntax error: No input!\n", This.argv0); 843 850 return 1; 844 851 } 845 852 if (!pOutput) 846 853 { 847 fprintf(stderr, "%s: syntax error: No output!\n", argv[0]);854 fprintf(stderr, "%s: syntax error: No output!\n", This.argv0); 848 855 return 1; 849 856 } 850 857 if (!pszTarget) 851 858 { 852 fprintf(stderr, "%s: syntax error: No target!\n", argv[0]);859 fprintf(stderr, "%s: syntax error: No target!\n", This.argv0); 853 860 return 1; 854 861 } … … 857 864 * Do the parsing. 858 865 */ 859 i = ProcessIDB(pInput); 866 depInit(&This.Core); 867 i = ProcessIDB(&This, pInput); 860 868 fclose(pInput); 861 869 … … 865 873 if (!i) 866 874 { 867 depOptimize( fFixCase, fQuiet, NULL /*pszIgnoredExt*/);875 depOptimize(&This.Core, fFixCase, fQuiet, NULL /*pszIgnoredExt*/); 868 876 fprintf(pOutput, "%s:", pszTarget); 869 depPrint( pOutput);877 depPrint(&This.Core, pOutput); 870 878 if (fStubs) 871 depPrintStubs( pOutput);879 depPrintStubs(&This.Core, pOutput); 872 880 } 873 881 … … 878 886 { 879 887 i = 1; 880 fprintf(stderr, "%s: error: Error writing to '%s'.\n", argv[0], pszOutput);888 fprintf(stderr, "%s: error: Error writing to '%s'.\n", This.argv0, pszOutput); 881 889 } 882 890 fclose(pOutput); … … 884 892 { 885 893 if (unlink(pszOutput)) 886 fprintf(stderr, "%s: warning: failed to remove output file '%s' on failure.\n", argv[0], pszOutput);887 } 888 889 depCleanup( );894 fprintf(stderr, "%s: warning: failed to remove output file '%s' on failure.\n", This.argv0, pszOutput); 895 } 896 897 depCleanup(&This.Core); 890 898 return i; 891 899 } -
trunk/src/kmk/kmkbuiltin/kDepObj.c
r3141 r3167 165 165 /** @} */ 166 166 167 168 /******************************************************************************* 169 * Global Variables * 170 *******************************************************************************/ 171 /** the executable name. */ 172 static const char *argv0 = ""; 173 static const char *g_pszFile = NULL; 167 /** 168 * Globals. 169 */ 170 typedef struct KDEPOBJGLOBALS 171 { 172 /** Core instance. */ 173 DEPGLOBALS Core; 174 /** the executable name. */ 175 const char *argv0; 176 /** The file. */ 177 const char *pszFile; 178 } KDEPOBJGLOBALS; 179 /** Pointer to kDepObj globals. */ 180 typedef KDEPOBJGLOBALS *PKDEPOBJGLOBALS; 181 174 182 175 183 … … 178 186 * 179 187 * @returns rc. 188 * @param pThis kObjDep instance data. 180 189 * @param rc The return code, for making one line return statements. 181 190 * @param pszFormat The message format string. … … 183 192 * @todo Promote this to kDep.c. 184 193 */ 185 static int kDepErr( int rc, const char *pszFormat, ...)194 static int kDepErr(PKDEPOBJGLOBALS pThis, int rc, const char *pszFormat, ...) 186 195 { 187 196 va_list va; 188 197 const char *psz; 189 const char *pszName = argv0;198 const char *pszName = pThis->argv0; 190 199 191 200 fflush(stdout); … … 195 204 pszName = psz + 1; 196 205 197 if ( g_pszFile)198 fprintf(stderr, "%s: %s: error: ", pszName, g_pszFile);206 if (pThis->pszFile) 207 fprintf(stderr, "%s: %s: error: ", pszName, pThis->pszFile); 199 208 else 200 209 fprintf(stderr, "%s: error: ", pszName); … … 245 254 * 246 255 * @returns 0 on success, 1 on failure, 2 if no dependencies was found. 256 * @param pThis The kDepObj instance data. 247 257 * @param pbFile The start of the file. 248 258 * @param cbFile The file size. 249 259 */ 250 int kDepObjOMFParse( const KU8 *pbFile, KSIZE cbFile)260 int kDepObjOMFParse(PKDEPOBJGLOBALS pThis, const KU8 *pbFile, KSIZE cbFile) 251 261 { 252 262 PCKDEPOMFHDR pHdr = (PCKDEPOMFHDR)pbFile; … … 284 294 PCKDEPOMFTHEADR pTHeadr = (PCKDEPOMFTHEADR)pHdr; 285 295 if (1 + pTHeadr->Name.cch + 1 != pHdr->cbRec) 286 return kDepErr( 1, "%#07x - Bad %cHEADR record, length mismatch.\n",296 return kDepErr(pThis, 1, "%#07x - Bad %cHEADR record, length mismatch.\n", 287 297 (const KU8*)pHdr - pbFile, pHdr->bType == KDEPOMF_THEADR ? 'T' : 'L'); 288 298 if ( ( pTHeadr->Name.cch > 2 … … 303 313 { 304 314 dprintf(("%cHEADR: %.*s\n", pHdr->bType == KDEPOMF_THEADR ? 'T' : 'L', pTHeadr->Name.cch, pTHeadr->Name.ach)); 305 depAdd( pTHeadr->Name.ach, pTHeadr->Name.cch);315 depAdd(&pThis->Core, pTHeadr->Name.ach, pTHeadr->Name.cch); 306 316 iMaybeSrc++; 307 317 } … … 315 325 316 326 if (pHdr->cbRec < 2 + 1) 317 return kDepErr( 1, "%#07x - Bad COMMENT record, too small.\n", (const KU8*)pHdr - pbFile);327 return kDepErr(pThis, 1, "%#07x - Bad COMMENT record, too small.\n", (const KU8*)pHdr - pbFile); 318 328 if (uData.pb[0] & 0x3f) 319 return kDepErr( 1, "%#07x - Bad COMMENT record, reserved flags set.\n", (const KU8*)pHdr - pbFile);329 return kDepErr(pThis, 1, "%#07x - Bad COMMENT record, reserved flags set.\n", (const KU8*)pHdr - pbFile); 320 330 uClass = uData.pb[1]; 321 331 uData.pb += 2; … … 334 344 if (pHdr->cbRec == 2 + 1) 335 345 return 0; 336 return kDepErr( 1, "%#07lx - Bad DEPENDENCY FILE record, length mismatch. (%u/%u)\n",346 return kDepErr(pThis, 1, "%#07lx - Bad DEPENDENCY FILE record, length mismatch. (%u/%u)\n", 337 347 (long)((const KU8 *)pHdr - pbFile), 338 348 K_OFFSETOF(KDEPOMFDEPFILE, Name.ach[pDep->Name.cch]) + 1, 339 349 (unsigned)(pHdr->cbRec + sizeof(*pHdr))); 340 350 } 341 depAdd( pDep->Name.ach, pDep->Name.cch);351 depAdd(&pThis->Core, pDep->Name.ach, pDep->Name.cch); 342 352 iSrc++; 343 353 break; … … 388 398 KU16 uSeg = kDepObjOMFGetIndex(&uData, &cbRecLeft); 389 399 if (uSeg == KU16_MAX) 390 return kDepErr( 1, "%#07lx - Bad LINNUM32 record\n", (long)((const KU8 *)pHdr - pbFile));400 return kDepErr(pThis, 1, "%#07lx - Bad LINNUM32 record\n", (long)((const KU8 *)pHdr - pbFile)); 391 401 K_NOREF(uGrp); 392 402 … … 405 415 406 416 if (cbRecLeft < 2+1+1+2+2+4) 407 return kDepErr( 1, "%#07lx - Bad LINNUM32 record, too short\n", (long)((const KU8 *)pHdr - pbFile));417 return kDepErr(pThis, 1, "%#07lx - Bad LINNUM32 record, too short\n", (long)((const KU8 *)pHdr - pbFile)); 408 418 cbRecLeft -= 2+1+1+2+2+4; 409 419 uLine = *uData.pu16++; … … 421 431 422 432 if (uLine != 0) 423 return kDepErr( 1, "%#07lx - Bad LINNUM32 record, line %#x (MBZ)\n", (long)((const KU8 *)pHdr - pbFile), uLine);433 return kDepErr(pThis, 1, "%#07lx - Bad LINNUM32 record, line %#x (MBZ)\n", (long)((const KU8 *)pHdr - pbFile), uLine); 424 434 cLinFiles = iLinFile = KU32_MAX; 425 435 if ( uLinNumType == 3 /* file names table */ … … 427 437 cLinNums = 0; /* no line numbers */ 428 438 else if (uLinNumType > 4) 429 return kDepErr( 1, "%#07lx - Bad LINNUM32 record, type %#x unknown\n", (long)((const KU8 *)pHdr - pbFile), uLinNumType);439 return kDepErr(pThis, 1, "%#07lx - Bad LINNUM32 record, type %#x unknown\n", (long)((const KU8 *)pHdr - pbFile), uLinNumType); 430 440 } 431 441 else … … 442 452 { 443 453 if (cbRecLeft < cbEntry) 444 return kDepErr( 1, "%#07lx - Bad LINNUM32 record, incomplete line entry\n", (long)((const KU8 *)pHdr - pbFile));454 return kDepErr(pThis, 1, "%#07lx - Bad LINNUM32 record, incomplete line entry\n", (long)((const KU8 *)pHdr - pbFile)); 445 455 446 456 switch (uLinNumType) … … 482 492 483 493 if (cbRecLeft < 4+4+4) 484 return kDepErr( 1, "%#07lx - Bad LINNUM32 record, incomplete file/path table header\n", (long)((const KU8 *)pHdr - pbFile));494 return kDepErr(pThis, 1, "%#07lx - Bad LINNUM32 record, incomplete file/path table header\n", (long)((const KU8 *)pHdr - pbFile)); 485 495 cbRecLeft -= 4+4+4; 486 496 … … 491 501 uLinNumType == 3 ? "file names" : "path", cLinFiles, cLinFiles, iFirstCol, cCols)); 492 502 if (cLinFiles == KU32_MAX) 493 return kDepErr( 1, "%#07lx - Bad LINNUM32 record, too many file/path table entries.\n", (long)((const KU8 *)pHdr - pbFile));503 return kDepErr(pThis, 1, "%#07lx - Bad LINNUM32 record, too many file/path table entries.\n", (long)((const KU8 *)pHdr - pbFile)); 494 504 iLinFile = 0; 495 505 } … … 500 510 int cbName = *uData.pb++; 501 511 if (cbRecLeft < 1 + cbName) 502 return kDepErr( 1, "%#07lx - Bad LINNUM32 record, file/path table entry too long.\n", (long)((const KU8 *)pHdr - pbFile));512 return kDepErr(pThis, 1, "%#07lx - Bad LINNUM32 record, file/path table entry too long.\n", (long)((const KU8 *)pHdr - pbFile)); 503 513 iLinFile++; 504 514 dprintf(("#%" KU32_PRI": %.*s\n", iLinFile, cbName, uData.pch)); 505 515 if (uLinNumType == 3) 506 516 { 507 depAdd( uData.pch, cbName);517 depAdd(&pThis->Core, uData.pch, cbName); 508 518 iSrc++; 509 519 } … … 532 542 533 543 if (cbLeft) 534 return kDepErr( 1, "%#07x - Unexpected EOF. cbLeft=%#x\n", (const KU8*)pHdr - pbFile, cbLeft);544 return kDepErr(pThis, 1, "%#07x - Unexpected EOF. cbLeft=%#x\n", (const KU8*)pHdr - pbFile, cbLeft); 535 545 536 546 if (iSrc == 0 && iMaybeSrc <= 1) … … 574 584 * 575 585 * @returns 0 on success, 1 on failure, 2 if no dependencies was found. 586 * @param pThis The kDepObj instance data. 576 587 * @param pbSyms Pointer to the start of the symbol section. 577 588 * @param cbSyms Size of the symbol section. 578 589 */ 579 int kDepObjCOFFParseCV8SymbolSection( const KU8 *pbSyms, KU32 cbSyms)590 int kDepObjCOFFParseCV8SymbolSection(PKDEPOBJGLOBALS pThis, const KU8 *pbSyms, KU32 cbSyms) 580 591 { 581 592 char const * pchStrTab = NULL; … … 602 613 { 603 614 fprintf(stderr, "%s: CV symbol table entry at %08" KX32_PRI " is too long; cbSyms=%#" KX32_PRI "\n", 604 argv0, off, cbSyms);615 pThis->argv0, off, cbSyms); 605 616 return 1; /* FIXME */ 606 617 } … … 610 621 { 611 622 fprintf(stderr, "%s: CV symbol table entry at %08" KX32_PRI " is too long; cbData=%#" KX32_PRI " cbSyms=%#" KX32_PRI "\n", 612 argv0, off, cbData, cbSyms);623 pThis->argv0, off, cbData, cbSyms); 613 624 return 1; /* FIXME */ 614 625 } … … 634 645 dprintf(("%06" KX32_PRI " %06" KX32_PRI ": String table\n", off, cbData)); 635 646 if (pchStrTab) 636 fprintf(stderr, "%s: warning: Found yet another string table!\n", argv0);647 fprintf(stderr, "%s: warning: Found yet another string table!\n", pThis->argv0); 637 648 pchStrTab = uData.pch; 638 649 cbStrTab = cbData; … … 643 654 dprintf(("%06" KX32_PRI " %06" KX32_PRI ": Source files\n", off, cbData)); 644 655 if (uSrcFiles.pb) 645 fprintf(stderr, "%s: warning: Found yet another source files table!\n", argv0);656 fprintf(stderr, "%s: warning: Found yet another source files table!\n", pThis->argv0); 646 657 uSrcFiles = uData; 647 658 cbSrcFiles = cbData; … … 694 705 { 695 706 fprintf(stderr, "%s: CV source file entry at %08" KX32_PRI " is too long; cbSrcFiles=%#" KX32_PRI "\n", 696 argv0, off, cbSrcFiles);707 pThis->argv0, off, cbSrcFiles); 697 708 return 1; 698 709 } … … 703 714 { 704 715 fprintf(stderr, "%s: CV source file entry at %08" KX32_PRI " is too long; cbSrc=%#" KX32_PRI " cbSrcFiles=%#" KX32_PRI "\n", 705 argv0, off, cbSrc, cbSrcFiles);716 pThis->argv0, off, cbSrc, cbSrcFiles); 706 717 return 1; 707 718 } … … 711 722 { 712 723 fprintf(stderr, "%s: CV source file entry at %08" KX32_PRI " is out side the string table; offFile=%#" KX32_PRI " cbStrTab=%#" KX32_PRI "\n", 713 argv0, off, offFile, cbStrTab);724 pThis->argv0, off, offFile, cbStrTab); 714 725 return 1; 715 726 } … … 719 730 { 720 731 fprintf(stderr, "%s: CV source file entry at %08" KX32_PRI " has an empty file name; offFile=%#x" KX32_PRI "\n", 721 argv0, off, offFile);732 pThis->argv0, off, offFile); 722 733 return 1; 723 734 } … … 726 737 * Display the result and add it to the dependency database. 727 738 */ 728 depAdd( pszFile, cchFile);739 depAdd(&pThis->Core, pszFile, cchFile); 729 740 if (u16Type == 0x0110) 730 741 dprintf(("#%03" KU32_PRI ": {todo-md5-todo} '%s'\n", … … 753 764 * 754 765 * @returns 0 on success, 1 on failure, 2 if no dependencies was found. 766 * @param pThis The kDepObj instance data. 755 767 * @param pbFile The start of the file. 756 768 * @param cbFile The file size. 757 769 */ 758 int kDepObjCOFFParse( const KU8 *pbFile, KSIZE cbFile)770 int kDepObjCOFFParse(PKDEPOBJGLOBALS pThis, const KU8 *pbFile, KSIZE cbFile) 759 771 { 760 772 IMAGE_FILE_HEADER const *pFileHdr = (IMAGE_FILE_HEADER const *)pbFile; … … 790 802 dprintf(("CV symbol table: version=%x\n", *u.pu32)); 791 803 if (*u.pu32 == 0x000000004) 792 rc = kDepObjCOFFParseCV8SymbolSection( u.pb, paSHdrs[iSHdr].SizeOfRawData);804 rc = kDepObjCOFFParseCV8SymbolSection(pThis, u.pb, paSHdrs[iSHdr].SizeOfRawData); 793 805 else 794 806 rc = 2; … … 946 958 * Read the file into memory and parse it. 947 959 */ 948 static int kDepObjProcessFile( FILE *pInput)960 static int kDepObjProcessFile(PKDEPOBJGLOBALS pThis, FILE *pInput) 949 961 { 950 962 size_t cbFile; … … 964 976 */ 965 977 if (kDepObjOMFTest(pbFile, cbFile)) 966 rc = kDepObjOMFParse(p bFile, cbFile);978 rc = kDepObjOMFParse(pThis, pbFile, cbFile); 967 979 else if (kDepObjCOFFTest(pbFile, cbFile)) 968 rc = kDepObjCOFFParse(p bFile, cbFile);980 rc = kDepObjCOFFParse(pThis, pbFile, cbFile); 969 981 else 970 982 { 971 fprintf(stderr, "%s: error: Doesn't recognize the header of the OMF/COFF file.\n", argv0);983 fprintf(stderr, "%s: error: Doesn't recognize the header of the OMF/COFF file.\n", pThis->argv0); 972 984 rc = 1; 973 985 } … … 978 990 979 991 980 static void usage(const char *a_argv0)992 static void kDebObjUsage(const char *a_argv0) 981 993 { 982 994 printf("usage: %s -o <output> -t <target> [-fqs] [-e <ignore-ext>] <OMF or COFF file>\n" … … 989 1001 int kmk_builtin_kDepObj(int argc, char *argv[], char **envp) 990 1002 { 991 int i; 1003 int i; 1004 KDEPOBJGLOBALS This; 992 1005 993 1006 /* Arguments. */ … … 1003 1016 int fQuiet = 0; 1004 1017 1005 argv0 = argv[0]; 1018 /* Init instance data. */ 1019 This.argv0 = argv[0]; 1020 This.pszFile = NULL; 1006 1021 1007 1022 /* … … 1010 1025 if (argc <= 1) 1011 1026 { 1012 usage(argv[0]);1027 kDebObjUsage(argv[0]); 1013 1028 return 1; 1014 1029 } … … 1033 1048 { 1034 1049 fprintf(stderr, "%s: syntax error: Invalid argument '%s'.\n", argv[0], argv[i]); 1035 usage(argv[0]);1050 kDebObjUsage(argv[0]); 1036 1051 return 2; 1037 1052 } … … 1148 1163 */ 1149 1164 case '?': 1150 usage(argv[0]);1165 kDebObjUsage(argv[0]); 1151 1166 return 0; 1152 1167 case 'V': … … 1159 1174 default: 1160 1175 fprintf(stderr, "%s: syntax error: Invalid argument '%s'.\n", argv[0], argv[i]); 1161 usage(argv[0]);1176 kDebObjUsage(argv[0]); 1162 1177 return 2; 1163 1178 } … … 1210 1225 * Do the parsing. 1211 1226 */ 1212 i = kDepObjProcessFile(pInput); 1227 depInit(&This.Core); 1228 i = kDepObjProcessFile(&This, pInput); 1213 1229 fclose(pInput); 1214 1230 … … 1218 1234 if (!i) 1219 1235 { 1220 depOptimize( fFixCase, fQuiet, pszIgnoreExt);1236 depOptimize(&This.Core, fFixCase, fQuiet, pszIgnoreExt); 1221 1237 fprintf(pOutput, "%s:", pszTarget); 1222 depPrint( pOutput);1238 depPrint(&This.Core, pOutput); 1223 1239 if (fStubs) 1224 depPrintStubs( pOutput);1240 depPrintStubs(&This.Core, pOutput); 1225 1241 } 1226 1242 … … 1240 1256 } 1241 1257 1242 depCleanup( );1258 depCleanup(&This.Core); 1243 1259 return i; 1244 1260 }
Note:
See TracChangeset
for help on using the changeset viewer.