Changeset 903 for trunk/src/gmakenew/implicit.c
- Timestamp:
- May 23, 2007, 7:31:19 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmakenew/implicit.c
r503 r903 26 26 #include "commands.h" /* set_file_variables */ 27 27 28 static int 29 pattern_search PARAMS ((struct file *file, int archive, 30 unsigned int depth, unsigned int recursions)); 28 static int pattern_search (struct file *file, int archive, 29 unsigned int depth, unsigned int recursions); 31 30 32 31 … … 72 71 { 73 72 struct idep *next; /* struct dep -compatible interface */ 74 c har *name;/* name of the prerequisite */73 const char *name; /* name of the prerequisite */ 75 74 struct file *intermediate_file; /* intermediate file, 0 otherwise */ 76 c har *intermediate_pattern;/* pattern for intermediate file */75 const char *intermediate_pattern; /* pattern for intermediate file */ 77 76 unsigned char had_stem; /* had % substituted with stem */ 78 77 unsigned char ignore_mtime; /* ignore_mtime flag */ … … 87 86 { 88 87 n = p->next; 89 90 if (p->name)91 {92 struct file *f = p->intermediate_file;93 94 if (f != 095 && (f->stem < f->name || f->stem > f->name + strlen (f->name)))96 free (f->stem);97 98 free (p->name);99 }100 101 88 free (p); 102 89 } … … 109 96 110 97 static char * 111 get_next_word (c har *buffer, unsigned int *length)98 get_next_word (const char *buffer, unsigned int *length) 112 99 { 113 c har *p = buffer, *beg;100 const char *p = buffer, *beg; 114 101 char c; 115 102 … … 182 169 *length = p - beg; 183 170 184 return beg;171 return (char *)beg; 185 172 } 186 173 … … 204 191 { 205 192 /* Filename we are searching for a rule for. */ 206 c har *filename = archive ? strchr (file->name, '(') : file->name;193 const char *filename = archive ? strchr (file->name, '(') : file->name; 207 194 208 195 /* Length of FILENAME. */ … … 226 213 227 214 /* Names of possible dependencies are constructed in this buffer. */ 228 register char *depname = (char *)alloca (namelen + max_pattern_dep_length);215 char *depname = alloca (namelen + max_pattern_dep_length); 229 216 230 217 /* The start and length of the stem of FILENAME for the current rule. */ 231 registerchar *stem = 0;232 registerunsigned int stemlen = 0;233 registerunsigned int fullstemlen = 0;218 const char *stem = 0; 219 unsigned int stemlen = 0; 220 unsigned int fullstemlen = 0; 234 221 235 222 /* Buffer in which we store all the rules that are possibly applicable. */ 236 struct rule **tryrules 237 = (struct rule **) xmalloc (num_pattern_rules * max_pattern_targets 238 * sizeof (struct rule *)); 223 struct rule **tryrules = xmalloc (num_pattern_rules * max_pattern_targets 224 * sizeof (struct rule *)); 239 225 240 226 /* Number of valid elements in TRYRULES. */ … … 243 229 /* The numbers of the rule targets of each rule 244 230 in TRYRULES that matched the target file. */ 245 unsigned int *matches 246 = (unsigned int *) alloca (num_pattern_rules * sizeof (unsigned int)); 231 unsigned int *matches = alloca (num_pattern_rules * sizeof (unsigned int)); 247 232 248 233 /* Each element is nonzero if LASTSLASH was used in 249 234 matching the corresponding element of TRYRULES. */ 250 char *checked_lastslash 251 = (char *) alloca (num_pattern_rules * sizeof (char)); 235 char *checked_lastslash = alloca (num_pattern_rules * sizeof (char)); 252 236 253 237 /* The index in TRYRULES of the rule we found. */ … … 261 245 int specific_rule_matched = 0; 262 246 263 unsigned int i = 0; /* uninit checks OK */247 unsigned int ri; /* uninit checks OK */ 264 248 struct rule *rule; 265 249 struct dep *dep, *expl_d; 266 267 char *p, *vname;268 250 269 251 struct idep *d; … … 296 278 lastslash = bslash; 297 279 if (lastslash == 0 && filename[0] && filename[1] == ':') 298 lastslash = filename + 1;280 lastslash = (char *)filename + 1; 299 281 } 300 282 #endif … … 310 292 for (rule = pattern_rules; rule != 0; rule = rule->next) 311 293 { 294 unsigned int ti; 295 312 296 /* If the pattern rule has deps but no commands, ignore it. 313 297 Users cancel built-in rules by redefining them without commands. */ … … 323 307 } 324 308 325 for ( i = 0; rule->targets[i] != 0; ++i)309 for (ti = 0; ti < rule->num; ++ti) 326 310 { 327 c har *target = rule->targets[i];328 c har *suffix = rule->suffixes[i];311 const char *target = rule->targets[ti]; 312 const char *suffix = rule->suffixes[ti]; 329 313 int check_lastslash; 330 314 … … 335 319 continue; 336 320 337 if (rule->lens[ i] > namelen)321 if (rule->lens[ti] > namelen) 338 322 /* It can't possibly match. */ 339 323 continue; … … 342 326 find the stem: the part of the filename that matches the %. */ 343 327 stem = filename + (suffix - target - 1); 344 stemlen = namelen - rule->lens[ i] + 1;328 stemlen = namelen - rule->lens[ti] + 1; 345 329 346 330 /* Set CHECK_LASTSLASH if FILENAME contains a directory … … 408 392 that rule will be in TRYRULES more than once. */ 409 393 tryrules[nrules] = rule; 410 matches[nrules] = i;394 matches[nrules] = ti; 411 395 checked_lastslash[nrules] = check_lastslash; 412 396 ++nrules; … … 417 401 retroactively reject any non-"terminal" rules that do always match. */ 418 402 if (specific_rule_matched) 419 for ( i = 0; i < nrules; ++i)420 if (!tryrules[ i]->terminal)403 for (ri = 0; ri < nrules; ++ri) 404 if (!tryrules[ri]->terminal) 421 405 { 422 register unsigned int j; 423 for (j = 0; tryrules[i]->targets[j] != 0; ++j) 424 if (tryrules[i]->targets[j][1] == '\0') 425 break; 426 if (tryrules[i]->targets[j] != 0) 427 tryrules[i] = 0; 406 unsigned int j; 407 for (j = 0; j < tryrules[ri]->num; ++j) 408 if (tryrules[ri]->targets[j][1] == '\0') 409 { 410 tryrules[ri] = 0; 411 break; 412 } 428 413 } 429 414 … … 439 424 and chain them in DEPS. */ 440 425 441 for ( i = 0; i < nrules;i++)426 for (ri = 0; ri < nrules; ri++) 442 427 { 443 428 struct file *f; … … 446 431 int file_variables_set = 0; 447 432 448 rule = tryrules[ i];433 rule = tryrules[ri]; 449 434 450 435 remove_explicit_deps = 0; … … 467 452 find the stem: the part of the filename that matches the %. */ 468 453 stem = filename 469 + (rule->suffixes[matches[ i]] - rule->targets[matches[i]]) - 1;470 stemlen = namelen - rule->lens[matches[ i]] + 1;471 check_lastslash = checked_lastslash[ i];454 + (rule->suffixes[matches[ri]] - rule->targets[matches[ri]]) - 1; 455 stemlen = namelen - rule->lens[matches[ri]] + 1; 456 check_lastslash = checked_lastslash[ri]; 472 457 if (check_lastslash) 473 458 { … … 491 476 { 492 477 unsigned int len; 478 char *p; 493 479 char *p2; 494 480 unsigned int order_only = 0; /* Set if '|' was seen. */ … … 536 522 if (p2 < p + len) 537 523 { 538 registerunsigned int i = p2 - p;539 bcopy (p, depname, i);540 bcopy ("$*", depname + i, 2);541 bcopy (p2 + 1, depname + i + 2, len - i - 1);524 unsigned int i = p2 - p; 525 memcpy (depname, p, i); 526 memcpy (depname + i, "$*", 2); 527 memcpy (depname + i + 2, p2 + 1, len - i - 1); 542 528 depname[len + 2 - 1] = '\0'; 543 529 … … 549 535 else 550 536 { 551 bcopy (p, depname, len);537 memcpy (depname, p, len); 552 538 depname[len] = '\0'; 553 539 } … … 568 554 if (p2 < p + len) 569 555 { 570 registerunsigned int i = p2 - p;571 bcopy (p, depname, i);572 bcopy (stem_str, depname + i, stemlen);573 bcopy (p2 + 1, depname + i + stemlen, len - i - 1);556 unsigned int i = p2 - p; 557 memcpy (depname, p, i); 558 memcpy (depname + i, stem_str, stemlen); 559 memcpy (depname + i + stemlen, p2 + 1, len - i - 1); 574 560 depname[len + stemlen - 1] = '\0'; 575 561 … … 581 567 else 582 568 { 583 bcopy (p, depname, len);569 memcpy (depname, p, len); 584 570 depname[len] = '\0'; 585 571 } … … 619 605 if (add_dir) 620 606 { 621 char *p = d->name; 622 623 d->name = xmalloc (strlen (p) + l + 1); 624 625 bcopy (filename, d->name, l); 626 bcopy (p, d->name + l, strlen (p) + 1); 627 628 free (p); 607 char *n = alloca (strlen (d->name) + l + 1); 608 memcpy (n, filename, l); 609 memcpy (n+l, d->name, strlen (d->name) + 1); 610 d->name = strcache_add (n); 629 611 } 630 612 … … 658 640 for (d = deps; d != 0; d = d->next) 659 641 { 660 c har *name = d->name;642 const char *name = d->name; 661 643 662 644 if (file_impossible_p (name)) … … 670 652 : _("Rejecting impossible rule prerequisite `%s'.\n"), 671 653 name)); 672 tryrules[ i] = 0;654 tryrules[ri] = 0; 673 655 674 656 failed = 1; … … 706 688 /* This code, given FILENAME = "lib/foo.o", dependency name 707 689 "lib/foo.c", and VPATH=src, searches for "src/lib/foo.c". */ 708 vname = name; 709 if (vpath_search (&vname, (FILE_TIMESTAMP *) 0)) 710 { 711 DBS (DB_IMPLICIT, 712 (_("Found prerequisite `%s' as VPATH `%s'\n"), 713 name, 714 vname)); 715 716 free (vname); 717 continue; 718 } 690 { 691 const char *vname = vpath_search (name, 0); 692 if (vname) 693 { 694 DBS (DB_IMPLICIT, 695 (_("Found prerequisite `%s' as VPATH `%s'\n"), 696 name, vname)); 697 continue; 698 } 699 } 719 700 720 701 … … 726 707 { 727 708 if (intermediate_file == 0) 728 intermediate_file 729 = (struct file *) alloca (sizeof (struct file)); 709 intermediate_file = alloca (sizeof (struct file)); 730 710 731 711 DBS (DB_IMPLICIT, … … 733 713 name)); 734 714 735 bzero ((char *) intermediate_file, sizeof (struct file));715 memset (intermediate_file, '\0', sizeof (struct file)); 736 716 intermediate_file->name = name; 737 717 if (pattern_search (intermediate_file, … … 740 720 recursions + 1)) 741 721 { 722 d->intermediate_pattern = intermediate_file->name; 723 intermediate_file->name = strcache_add (name); 742 724 d->intermediate_file = intermediate_file; 743 d->intermediate_pattern = intermediate_file->name;744 745 intermediate_file->name = xstrdup (name);746 725 intermediate_file = 0; 747 726 … … 781 760 /* If we found an applicable rule without 782 761 intermediate files, don't try with them. */ 783 if ( i < nrules)762 if (ri < nrules) 784 763 break; 785 764 … … 792 771 goto done; 793 772 794 foundrule = i;773 foundrule = ri; 795 774 796 775 /* If we are recursing, store the pattern that matched … … 825 804 for (d = deps; d != 0; d = d->next) 826 805 { 827 registerchar *s;806 const char *s; 828 807 829 808 if (d->intermediate_file != 0) … … 845 824 f->precious = 1; 846 825 else 847 f = enter_file ( imf->name);826 f = enter_file (strcache_add (imf->name)); 848 827 849 828 f->deps = imf->deps; … … 865 844 { 866 845 dep->file = enter_file (dep->name); 867 /* enter_file uses dep->name _if_ we created a new file. */868 if (dep->name != dep->file->name)869 free (dep->name);870 846 dep->name = 0; 871 847 dep->file->tried_implicit |= dep->changed; … … 881 857 dep->file = lookup_file (s); 882 858 if (dep->file == 0) 883 /* enter_file consumes S's storage. */884 859 dep->file = enter_file (s); 885 else886 /* A copy of S is already allocated in DEP->file->name.887 So we can free S. */888 free (s);889 860 } 890 861 else 891 { 892 dep->name = s; 893 } 862 dep->name = s; 894 863 895 864 if (d->intermediate_file == 0 && tryrules[foundrule]->terminal) … … 916 885 /* Always allocate new storage, since STEM might be 917 886 on the stack for an intermediate file. */ 918 file->stem = s avestring(stem, stemlen);887 file->stem = strcache_add_len (stem, stemlen); 919 888 fullstemlen = stemlen; 920 889 } … … 922 891 { 923 892 int dirlen = (lastslash + 1) - filename; 893 char *sp; 924 894 925 895 /* We want to prepend the directory from 926 896 the original FILENAME onto the stem. */ 927 897 fullstemlen = dirlen + stemlen; 928 file->stem = (char *) xmalloc (fullstemlen + 1); 929 bcopy (filename, file->stem, dirlen); 930 bcopy (stem, file->stem + dirlen, stemlen); 931 file->stem[fullstemlen] = '\0'; 898 sp = alloca (fullstemlen + 1); 899 memcpy (sp, filename, dirlen); 900 memcpy (sp + dirlen, stem, stemlen); 901 sp[fullstemlen] = '\0'; 902 file->stem = strcache_add (sp); 932 903 } 933 904 … … 945 916 `also_make' member. */ 946 917 947 if (rule-> targets[1] != 0)948 for ( i = 0; rule->targets[i] != 0; ++i)949 if ( i != matches[foundrule])918 if (rule->num > 1) 919 for (ri = 0; ri < rule->num; ++ri) 920 if (ri != matches[foundrule]) 950 921 { 922 char *p = alloca (rule->lens[ri] + fullstemlen + 1); 951 923 struct file *f; 952 924 struct dep *new = alloc_dep (); 953 925 954 926 /* GKM FIMXE: handle '|' here too */ 955 new->name = p = (char *) xmalloc (rule->lens[i] + fullstemlen + 1); 956 bcopy (rule->targets[i], p, 957 rule->suffixes[i] - rule->targets[i] - 1); 958 p += rule->suffixes[i] - rule->targets[i] - 1; 959 bcopy (file->stem, p, fullstemlen); 927 memcpy (p, rule->targets[ri], 928 rule->suffixes[ri] - rule->targets[ri] - 1); 929 p += rule->suffixes[ri] - rule->targets[ri] - 1; 930 memcpy (p, file->stem, fullstemlen); 960 931 p += fullstemlen; 961 bcopy (rule->suffixes[i], p, 962 rule->lens[i] - (rule->suffixes[i] - rule->targets[i]) + 1); 932 memcpy (p, rule->suffixes[ri], 933 rule->lens[ri] - (rule->suffixes[ri] - rule->targets[ri])+1); 934 new->name = strcache_add (p); 963 935 new->file = enter_file (new->name); 964 936 new->next = file->also_make; 965 937 966 938 /* Set precious flag. */ 967 f = lookup_file (rule->targets[ i]);939 f = lookup_file (rule->targets[ri]); 968 940 if (f && f->precious) 969 941 new->file->precious = 1;
Note:
See TracChangeset
for help on using the changeset viewer.