- Timestamp:
- Jan 12, 2006, 5:01:09 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kDepPre/kDepPre.c
r343 r384 662 662 663 663 664 /** 665 * Make an attempt at parsing a Visual C++ IDB file. 666 */ 667 static int ParseVCxxIDB(FILE *pInput, const char *argv0) 668 { 669 char *pbFile; 670 long cbFile; 671 int rc = 0; 672 673 /* 674 * Figure out file size. 675 */ 676 if ( fseek(pInput, 0, SEEK_END) < 0 677 || (cbFile = ftell(pInput)) < 0 678 || fseek(pInput, 0, SEEK_SET)) 679 { 680 fprintf(stderr, "%s: error: Failed to determin file size of the Visual C++ IDB file.\n", argv0); 681 return -1; 682 } 683 684 /* 685 * Allocate memory and read the file. 686 */ 687 pbFile = (char *)malloc(cbFile + 1); 688 if (!pbFile) 689 { 690 fprintf(stderr, "%s: error: Failed to allocate %ld bytes of memory for the Visual C++ IDB file.\n", argv0, cbFile); 691 return -1; 692 } 693 if (fread(pbFile, cbFile, 1, pInput)) 694 { 695 const char *pszPrefix = NULL; 696 int cchPrefix = 0; 697 pbFile[cbFile] = '\0'; 698 699 /* 700 * Check the header. 701 */ 702 if (!strncmp(pbFile, "Microsoft C/C++ MSF 7.", sizeof("Microsoft C/C++ MSF 7.") - 1)) 703 { 704 pszPrefix = "/mr/inversedeps/"; 705 cchPrefix = sizeof("/mr/inversedeps/") - 1; 706 } 707 else if (!strncmp(pbFile, "Microsoft C/C++ program database 2.", sizeof("Microsoft C/C++ program database 2.") - 1)) 708 { 709 pszPrefix = "/ipm/header/"; 710 cchPrefix = sizeof("/ipm/header/") - 1; 711 } 712 if (pszPrefix) 713 { 714 /* 715 * Do a brute force scan of the file until we encounter "\0/mr/inversedeps/" (which is the 716 * vc70 and vc80 prefix) or "\0/ipm/header/" (which is the vc60 prefix). 717 * (This is highly experimental and I've no idea about the actual format of the file.) 718 */ 719 char *pb = pbFile; 720 long cbLeft = cbFile; 721 while (cbLeft > cchPrefix + 3) 722 { 723 /** @todo use memchr? */ 724 if ( *pb != *pszPrefix 725 || strncmp(pb, pszPrefix, cchPrefix)) 726 { 727 pb++; 728 cbLeft--; 729 } 730 else 731 { 732 const char *psz = &pb[cchPrefix]; 733 size_t cch = strlen(psz); 734 depAdd(psz, cch); 735 //printf("dep='%s'\n", psz); 736 pb += cch + cchPrefix; 737 cbLeft -= cch + cchPrefix; 738 } 739 } 740 } 741 else 742 { 743 fprintf(stderr, "%s: error: Doesn't recognize the header of the Visual C++ IDB file.\n", argv0, cbFile); 744 rc = 1; 745 } 746 } 747 else 748 { 749 fprintf(stderr, "%s: error: Failed to allocate %ld bytes of memory for the Visual C++ IDB file.\n", argv0, cbFile); 750 rc = 1; 751 } 752 753 return rc; 754 } 755 756 664 757 static void usage(const char *argv0) 665 758 { 666 printf("syntax: %s [-l=c] -o <output> -t <target> [-f] [-s] < - | <filename> | -e <cmdline> >\n", argv0); 667 } 759 printf("syntax: %s [-l=c] -o <output> -t <target> [-f] [-s] < - | <filename> | -e <cmdline> | -i <vc idb-file> >\n", argv0); 760 } 761 668 762 669 763 int main(int argc, char *argv[]) … … 681 775 /* Argument parsing. */ 682 776 int fInput = 0; /* set when we've found input argument. */ 777 int fIDBMode = 0; 683 778 684 779 /* … … 791 886 pInput = stdin; 792 887 fInput = 1; 888 break; 889 } 890 891 /* 892 * IDB input. 893 */ 894 case 'i': 895 { 896 if (++i >= argc) 897 { 898 fprintf(stderr, "%s: syntax error: The '-i' argument is missing IDB filename.\n", argv[0]); 899 return 1; 900 } 901 pInput = fopen(argv[i], "rb"); 902 if (!pInput) 903 { 904 fprintf(stderr, "%s: error: Failed to open input file '%s'.\n", argv[0], argv[i]); 905 return 1; 906 } 907 fInput = 1; 908 fIDBMode = 1; 793 909 break; 794 910 } … … 877 993 * Do the parsing. 878 994 */ 879 i = ParseCPrecompiler(pInput); 995 if (!fIDBMode) 996 i = ParseCPrecompiler(pInput); 997 else 998 i = ParseVCxxIDB(pInput, argv[0]); 880 999 881 1000 /*
Note:
See TracChangeset
for help on using the changeset viewer.