Changeset 24 for branches/FREEBSD/src/kmk/arch.c
- Timestamp:
- Nov 26, 2002, 10:24:54 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/FREEBSD/src/kmk/arch.c
r8 r24 35 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 36 * SUCH DAMAGE. 37 * 38 * @(#)arch.c 8.2 (Berkeley) 1/2/94 39 */ 40 41 #include <sys/cdefs.h> 42 __FBSDID("$FreeBSD: src/usr.bin/make/arch.c,v 1.32 2002/10/09 03:42:09 jmallett Exp $"); 37 */ 38 39 #ifndef lint 40 #if 0 41 static char sccsid[] = "@(#)arch.c 8.2 (Berkeley) 1/2/94"; 42 #else 43 static const char rcsid[] = 44 "$FreeBSD: src/usr.bin/make/arch.c,v 1.15.2.1 2001/02/13 03:13:57 will Exp $"; 45 #endif 46 #endif /* not lint */ 43 47 44 48 /*- … … 114 118 } Arch; 115 119 116 static int ArchFindArchive (void *, void *);117 static void ArchFree (void *);118 static struct ar_hdr *ArchStatMember (char *, char *, Boolean);119 static FILE *ArchFindMember (char *, char *, struct ar_hdr *, char *);120 static int ArchFindArchive __P((ClientData, ClientData)); 121 static void ArchFree __P((ClientData)); 122 static struct ar_hdr *ArchStatMember __P((char *, char *, Boolean)); 123 static FILE *ArchFindMember __P((char *, char *, struct ar_hdr *, char *)); 120 124 #if defined(__svr4__) || defined(__SVR4) || defined(__ELF__) 121 #define 122 static int ArchSVR4Entry (Arch *, char *, size_t, FILE *);125 #define SVR4ARCHIVES 126 static int ArchSVR4Entry __P((Arch *, char *, size_t, FILE *)); 123 127 #endif 124 128 … … 137 141 */ 138 142 static void 139 ArchFree(void *ap) 143 ArchFree(ap) 144 ClientData ap; 140 145 { 141 146 Arch *a = (Arch *) ap; … … 147 152 entry != NULL; 148 153 entry = Hash_EnumNext(&search)) 149 free( Hash_GetValue(entry));154 free((Address) Hash_GetValue (entry)); 150 155 151 156 free(a->name); 152 157 efree(a->fnametab); 153 158 Hash_DeleteTable(&a->members); 154 free( a);159 free((Address) a); 155 160 } 156 161 … … 162 167 * Parse the archive specification in the given line and find/create 163 168 * the nodes for the specified archive members, placing their nodes 164 * on the given list, given the pointer to the start of the 165 * specification, a Lst on which to place the nodes, and a context 166 * in which to expand variables. 169 * on the given list. 167 170 * 168 171 * Results: … … 177 180 */ 178 181 ReturnStatus 179 Arch_ParseArchive (char **linePtr, Lst nodeLst, GNode *ctxt) 180 { 181 char *cp; /* Pointer into line */ 182 Arch_ParseArchive (linePtr, nodeLst, ctxt) 183 char **linePtr; /* Pointer to start of specification */ 184 Lst nodeLst; /* Lst on which to place the nodes */ 185 GNode *ctxt; /* Context in which to expand variables */ 186 { 187 register char *cp; /* Pointer into line */ 182 188 GNode *gn; /* New node */ 183 189 char *libName; /* Library-part of specification */ … … 230 236 Boolean doSubst = FALSE; /* TRUE if need to substitute in memName */ 231 237 232 while (*cp != '\0' && *cp != ')' && isspace ( (unsigned char)*cp)) {238 while (*cp != '\0' && *cp != ')' && isspace (*cp)) { 233 239 cp++; 234 240 } 235 241 memName = cp; 236 while (*cp != '\0' && *cp != ')' && !isspace ( (unsigned char)*cp)) {242 while (*cp != '\0' && *cp != ')' && !isspace (*cp)) { 237 243 if (*cp == '$') { 238 244 /* … … 305 311 * are just placed at the end of the nodeLst we're returning. 306 312 */ 307 308 313 sz = strlen(memName) + strlen(libName) + 3; 309 314 buf = sacrifice = emalloc(sz); 310 311 315 snprintf(buf, sz, "%s(%s)", libName, memName); 312 316 … … 319 323 gn = Targ_FindNode(buf, TARG_CREATE); 320 324 321 if (gn == N ULL) {325 if (gn == NILGNODE) { 322 326 free(buf); 323 327 return(FAILURE); 324 328 } else { 325 329 gn->type |= OP_ARCHV; 326 (void)Lst_AtEnd(nodeLst, ( void *)gn);330 (void)Lst_AtEnd(nodeLst, (ClientData)gn); 327 331 } 328 332 } else if (Arch_ParseArchive(&sacrifice, nodeLst, ctxt)!=SUCCESS) { … … 355 359 free(member); 356 360 gn = Targ_FindNode (nameBuf, TARG_CREATE); 357 if (gn == N ULL) {361 if (gn == NILGNODE) { 358 362 free(nameBuf); 359 363 return (FAILURE); … … 367 371 */ 368 372 gn->type |= OP_ARCHV; 369 (void) Lst_AtEnd (nodeLst, ( void *)gn);373 (void) Lst_AtEnd (nodeLst, (ClientData)gn); 370 374 } 371 375 } … … 378 382 gn = Targ_FindNode (nameBuf, TARG_CREATE); 379 383 free(nameBuf); 380 if (gn == N ULL) {384 if (gn == NILGNODE) { 381 385 return (FAILURE); 382 386 } else { … … 389 393 */ 390 394 gn->type |= OP_ARCHV; 391 (void) Lst_AtEnd (nodeLst, ( void *)gn);395 (void) Lst_AtEnd (nodeLst, (ClientData)gn); 392 396 } 393 397 } … … 413 417 do { 414 418 cp++; 415 } while (*cp != '\0' && isspace ( (unsigned char)*cp));419 } while (*cp != '\0' && isspace (*cp)); 416 420 417 421 *linePtr = cp; … … 423 427 * ArchFindArchive -- 424 428 * See if the given archive is the one we are looking for. Called 425 * From ArchStatMember and ArchFindMember via Lst_Find with the 426 * current list element and the name we want. 429 * From ArchStatMember and ArchFindMember via Lst_Find. 427 430 * 428 431 * Results: … … 435 438 */ 436 439 static int 437 ArchFindArchive (void *ar, void *archName) 440 ArchFindArchive (ar, archName) 441 ClientData ar; /* Current list element */ 442 ClientData archName; /* Name we want */ 438 443 { 439 444 return (strcmp ((char *) archName, ((Arch *) ar)->name)); … … 444 449 * ArchStatMember -- 445 450 * Locate a member of an archive, given the path of the archive and 446 * the path of the desired member, and a boolean representing whether 447 * or not the archive should be hashed (if not already hashed). 451 * the path of the desired member. 448 452 * 449 453 * Results: … … 459 463 */ 460 464 static struct ar_hdr * 461 ArchStatMember (char *archive, char *member, Boolean hash) 462 { 463 #define AR_MAX_NAME_LEN (sizeof(arh.ar_name)-1) 465 ArchStatMember (archive, member, hash) 466 char *archive; /* Path to the archive */ 467 char *member; /* Name of member. If it is a path, only the 468 * last component is used. */ 469 Boolean hash; /* TRUE if archive should be hashed if not 470 * already so. */ 471 { 472 #define AR_MAX_NAME_LEN (sizeof(arh.ar_name)-1) 464 473 FILE * arch; /* Stream to archive */ 465 474 int size; /* Size of archive member */ … … 483 492 member = cp + 1; 484 493 485 ln = Lst_Find (archives, ( void *) archive, ArchFindArchive);486 if (ln != N ULL) {494 ln = Lst_Find (archives, (ClientData) archive, ArchFindArchive); 495 if (ln != NILLNODE) { 487 496 ar = (Arch *) Lst_Datum (ln); 488 497 … … 494 503 /* Try truncated name */ 495 504 char copy[AR_MAX_NAME_LEN+1]; 496 size_t len = strlen (member);505 int len = strlen (member); 497 506 498 507 if (len > AR_MAX_NAME_LEN) { … … 615 624 memName[elen] = '\0'; 616 625 fseek (arch, -elen, SEEK_CUR); 617 /* XXX Multiple levels may be asked for, make this conditional618 * on one, and use DEBUGF.619 */620 626 if (DEBUG(ARCH) || DEBUG(MAKE)) { 621 fprintf(stderr,"ArchStat: Extended format entry for %s\n", memName);627 printf("ArchStat: Extended format entry for %s\n", memName); 622 628 } 623 629 } … … 625 631 626 632 he = Hash_CreateEntry (&ar->members, memName, NULL); 627 Hash_SetValue (he, ( void *)emalloc (sizeof (struct ar_hdr)));628 memcpy ( Hash_GetValue (he),&arh,633 Hash_SetValue (he, (ClientData)emalloc (sizeof (struct ar_hdr))); 634 memcpy ((Address)Hash_GetValue (he), (Address)&arh, 629 635 sizeof (struct ar_hdr)); 630 636 } … … 634 640 fclose (arch); 635 641 636 (void) Lst_AtEnd (archives, ( void *) ar);642 (void) Lst_AtEnd (archives, (ClientData) ar); 637 643 638 644 /* … … 652 658 Hash_DeleteTable (&ar->members); 653 659 efree(ar->fnametab); 654 free ( ar);660 free ((Address)ar); 655 661 return (NULL); 656 662 } … … 678 684 */ 679 685 static int 680 ArchSVR4Entry(Arch *ar, char *name, size_t size, FILE *arch) 681 { 682 #define ARLONGNAMES1 "//" 683 #define ARLONGNAMES2 "/ARFILENAMES" 686 ArchSVR4Entry(ar, name, size, arch) 687 Arch *ar; 688 char *name; 689 size_t size; 690 FILE *arch; 691 { 692 #define ARLONGNAMES1 "//" 693 #define ARLONGNAMES2 "/ARFILENAMES" 684 694 size_t entry; 685 695 char *ptr, *eptr; … … 689 699 690 700 if (ar->fnametab != NULL) { 691 DEBUGF(ARCH, ("Attempted to redefine an SVR4 name table\n")); 701 if (DEBUG(ARCH)) { 702 printf("Attempted to redefine an SVR4 name table\n"); 703 } 692 704 return -1; 693 705 } … … 701 713 702 714 if (fread(ar->fnametab, size, 1, arch) != 1) { 703 DEBUGF(ARCH, ("Reading an SVR4 name table failed\n")); 715 if (DEBUG(ARCH)) { 716 printf("Reading an SVR4 name table failed\n"); 717 } 704 718 return -1; 705 719 } … … 718 732 break; 719 733 } 720 DEBUGF(ARCH, ("Found svr4 archive name table with %zu entries\n", entry)); 734 if (DEBUG(ARCH)) { 735 printf("Found svr4 archive name table with %d entries\n", entry); 736 } 721 737 return 0; 722 738 } … … 727 743 entry = (size_t) strtol(&name[1], &eptr, 0); 728 744 if ((*eptr != ' ' && *eptr != '\0') || eptr == &name[1]) { 729 DEBUGF(ARCH, ("Could not parse SVR4 name %s\n", name)); 745 if (DEBUG(ARCH)) { 746 printf("Could not parse SVR4 name %s\n", name); 747 } 730 748 return 2; 731 749 } 732 750 if (entry >= ar->fnamesize) { 733 DEBUGF(ARCH, ("SVR4 entry offset %s is greater than %zu\n", 734 name, ar->fnamesize)); 751 if (DEBUG(ARCH)) { 752 printf("SVR4 entry offset %s is greater than %d\n", 753 name, ar->fnamesize); 754 } 735 755 return 2; 736 756 } 737 757 738 DEBUGF(ARCH, ("Replaced %s with %s\n", name, &ar->fnametab[entry])); 758 if (DEBUG(ARCH)) { 759 printf("Replaced %s with %s\n", name, &ar->fnametab[entry]); 760 } 739 761 740 762 (void) strncpy(name, &ar->fnametab[entry], MAXPATHLEN); … … 750 772 * Locate a member of an archive, given the path of the archive and 751 773 * the path of the desired member. If the archive is to be modified, 752 * the mode should be "r+", if not, it should be "r". arhPtr is a 753 * poitner to the header structure to fill in. 774 * the mode should be "r+", if not, it should be "r". 754 775 * 755 776 * Results: … … 764 785 */ 765 786 static FILE * 766 ArchFindMember (char *archive, char *member, struct ar_hdr *arhPtr, char *mode) 787 ArchFindMember (archive, member, arhPtr, mode) 788 char *archive; /* Path to the archive */ 789 char *member; /* Name of member. If it is a path, only the 790 * last component is used. */ 791 struct ar_hdr *arhPtr; /* Pointer to header structure to be filled in */ 792 char *mode; /* The mode for opening the stream */ 767 793 { 768 794 FILE * arch; /* Stream to archive */ … … 770 796 char *cp; /* Useful character pointer */ 771 797 char magic[SARMAG]; 772 size_tlen, tlen;798 int len, tlen; 773 799 774 800 arch = fopen (archive, mode); … … 853 879 } 854 880 ename[elen] = '\0'; 855 /*856 * XXX choose one.857 */858 881 if (DEBUG(ARCH) || DEBUG(MAKE)) { 859 882 printf("ArchFind: Extended format entry for %s\n", ename); … … 907 930 */ 908 931 void 909 Arch_Touch (GNode *gn) 932 Arch_Touch (gn) 933 GNode *gn; /* Node of member to touch */ 910 934 { 911 935 FILE * arch; /* Stream open to archive, positioned properly */ … … 942 966 */ 943 967 void 944 Arch_TouchLib (GNode *gn) 968 Arch_TouchLib (gn) 969 GNode *gn; /* The node of the library to touch */ 945 970 { 946 971 #ifdef RANLIBMAG … … 965 990 *----------------------------------------------------------------------- 966 991 * Arch_MTime -- 967 * Return the modification time of a member of an archive, given its 968 * name. 992 * Return the modification time of a member of an archive. 969 993 * 970 994 * Results: … … 978 1002 */ 979 1003 int 980 Arch_MTime(GNode *gn) 1004 Arch_MTime (gn) 1005 GNode *gn; /* Node describing archive member */ 981 1006 { 982 1007 struct ar_hdr *arhPtr; /* Header of desired member */ … … 1015 1040 */ 1016 1041 int 1017 Arch_MemMTime (GNode *gn) 1042 Arch_MemMTime (gn) 1043 GNode *gn; 1018 1044 { 1019 1045 LstNode ln; … … 1026 1052 return (0); 1027 1053 } 1028 while ((ln = Lst_Next (gn->parents)) != N ULL) {1054 while ((ln = Lst_Next (gn->parents)) != NILLNODE) { 1029 1055 pgn = (GNode *) Lst_Datum (ln); 1030 1056 … … 1062 1088 *----------------------------------------------------------------------- 1063 1089 * Arch_FindLib -- 1064 * Search for a namedlibrary along the given search path.1090 * Search for a library along the given search path. 1065 1091 * 1066 1092 * Results: … … 1080 1106 */ 1081 1107 void 1082 Arch_FindLib (GNode *gn, Lst path) 1108 Arch_FindLib (gn, path) 1109 GNode *gn; /* Node of library to find */ 1110 Lst path; /* Search path */ 1083 1111 { 1084 1112 char *libName; /* file name for archive */ … … 1104 1132 * Arch_LibOODate -- 1105 1133 * Decide if a node with the OP_LIB attribute is out-of-date. Called 1106 * from Make_OODate to make its life easier, with the library's 1107 * graph node. 1134 * from Make_OODate to make its life easier. 1108 1135 * 1109 1136 * There are several ways for a library to be out-of-date that are … … 1138 1165 */ 1139 1166 Boolean 1140 Arch_LibOODate (GNode *gn) 1167 Arch_LibOODate (gn) 1168 GNode *gn; /* The library's graph node */ 1141 1169 { 1142 1170 Boolean oodate; … … 1156 1184 modTimeTOC = (int) strtol(arhPtr->ar_date, NULL, 10); 1157 1185 1158 /* XXX choose one. */1159 1186 if (DEBUG(ARCH) || DEBUG(MAKE)) { 1160 1187 printf("%s modified %s...", RANLIBMAG, Targ_FmtTime(modTimeTOC)); … … 1191 1218 */ 1192 1219 void 1193 Arch_Init ( void)1220 Arch_Init () 1194 1221 { 1195 1222 archives = Lst_Init (FALSE); … … 1212 1239 */ 1213 1240 void 1214 Arch_End ( void)1241 Arch_End () 1215 1242 { 1216 1243 Lst_Destroy(archives, ArchFree);
Note:
See TracChangeset
for help on using the changeset viewer.