Changeset 903 for trunk/src/gmakenew/function.c
- Timestamp:
- May 23, 2007, 7:31:19 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmakenew/function.c
r863 r903 53 53 unsigned char maximum_args; 54 54 char expand_args; 55 char *(*func_ptr) PARAMS ((char *output, char **argv, const char *fname));55 char *(*func_ptr) (char *output, char **argv, const char *fname); 56 56 }; 57 57 … … 59 59 function_table_entry_hash_1 (const void *keyv) 60 60 { 61 struct function_table_entry const *key = (struct function_table_entry const *)keyv;61 const struct function_table_entry *key = keyv; 62 62 return_STRING_N_HASH_1 (key->name, key->len); 63 63 } … … 66 66 function_table_entry_hash_2 (const void *keyv) 67 67 { 68 struct function_table_entry const *key = (struct function_table_entry const *)keyv;68 const struct function_table_entry *key = keyv; 69 69 return_STRING_N_HASH_2 (key->name, key->len); 70 70 } … … 73 73 function_table_entry_hash_cmp (const void *xv, const void *yv) 74 74 { 75 struct function_table_entry const *x = (struct function_table_entry const *)xv;76 struct function_table_entry const *y = (struct function_table_entry const *)yv;75 const struct function_table_entry *x = xv; 76 const struct function_table_entry *y = yv; 77 77 int result = x->len - y->len; 78 78 if (result) … … 92 92 93 93 char * 94 subst_expand (char *o, c har *text, char *subst,char *replace,94 subst_expand (char *o, const char *text, const char *subst, const char *replace, 95 95 unsigned int slen, unsigned int rlen, int by_word) 96 96 { 97 c har *t = text;98 c har *p;97 const char *t = text; 98 const char *p; 99 99 100 100 if (slen == 0 && !by_word) … … 141 141 142 142 /* Advance T past the string to be replaced. */ 143 { 144 char *nt = p + slen; 145 t = nt; 146 } 143 t = p + slen; 147 144 } while (*t != '\0'); 148 145 … … 163 160 164 161 char * 165 patsubst_expand (char *o, char *text, char *pattern, char *replace, 166 char *pattern_percent, char *replace_percent) 162 patsubst_expand_pat (char *o, const char *text, 163 const char *pattern, const char *replace, 164 const char *pattern_percent, const char *replace_percent) 167 165 { 168 166 unsigned int pattern_prepercent_len, pattern_postpercent_len; 169 167 unsigned int replace_prepercent_len, replace_postpercent_len; 170 c har *t;168 const char *t; 171 169 unsigned int len; 172 170 int doneany = 0; 173 174 /* We call find_percent on REPLACE before checking PATTERN so that REPLACE175 will be collapsed before we call subst_expand if PATTERN has no %. */176 if (!replace_percent)177 {178 replace_percent = find_percent (replace);179 if (replace_percent)180 ++replace_percent;181 }182 171 183 172 /* Record the length of REPLACE before and after the % so we don't have to … … 194 183 } 195 184 196 if (!pattern_percent)197 {198 pattern_percent = find_percent (pattern);199 if (pattern_percent)200 ++pattern_percent;201 }202 185 if (!pattern_percent) 203 186 /* With no % in the pattern, this is just a simple substitution. */ … … 271 254 } 272 255 256 /* Store into VARIABLE_BUFFER at O the result of scanning TEXT 257 and replacing strings matching PATTERN with REPLACE. 258 If PATTERN_PERCENT is not nil, PATTERN has already been 259 run through find_percent, and PATTERN_PERCENT is the result. 260 If REPLACE_PERCENT is not nil, REPLACE has already been 261 run through find_percent, and REPLACE_PERCENT is the result. 262 Note that we expect PATTERN_PERCENT and REPLACE_PERCENT to point to the 263 character _AFTER_ the %, not to the % itself. 264 */ 265 266 char * 267 patsubst_expand (char *o, const char *text, char *pattern, char *replace) 268 { 269 const char *pattern_percent = find_percent (pattern); 270 const char *replace_percent = find_percent (replace); 271 272 /* If there's a percent in the pattern or replacement skip it. */ 273 if (replace_percent) 274 ++replace_percent; 275 if (pattern_percent) 276 ++pattern_percent; 277 278 return patsubst_expand_pat (o, text, pattern, replace, 279 pattern_percent, replace_percent); 280 } 281 273 282 274 283 #ifdef CONFIG_WITH_OPTIMIZATION_HACKS … … 276 285 it can't be function and we can skip the hash lookup drop out. */ 277 286 278 #ifdef KMK 279 # define MAX_FUNCTION_LENGTH 12 280 #else 281 # define MAX_FUNCTION_LENGTH 10 282 #endif 287 # ifdef KMK 288 # define MAX_FUNCTION_LENGTH 12 289 # else 290 # define MAX_FUNCTION_LENGTH 10 291 # endif 292 #endif /* CONFIG_WITH_OPTIMIZATION_HACKS */ 283 293 284 294 /* Look up a function by name. */ 295 296 #ifdef CONFIG_WITH_OPTIMIZATION_HACKS 285 297 __inline 286 298 #endif /* CONFIG_WITH_OPTIMIZATION_HACKS */ … … 318 330 319 331 int 320 pattern_matches (c har *pattern, char *percent,char *str)332 pattern_matches (const char *pattern, const char *percent, const char *str) 321 333 { 322 334 unsigned int sfxlen, strlength; … … 325 337 { 326 338 unsigned int len = strlen (pattern) + 1; 327 char *new_chars = (char *) alloca (len); 328 bcopy (pattern, new_chars, len); 339 char *new_chars = alloca (len); 340 memcpy (new_chars, pattern, len); 341 percent = find_percent (new_chars); 342 if (percent == 0) 343 return streq (new_chars, str); 329 344 pattern = new_chars; 330 percent = find_percent (pattern);331 if (percent == 0)332 return streq (pattern, str);333 345 } 334 346 … … 386 398 static char *result = 0; 387 399 static unsigned int length; 388 registerstruct nameseq *chain;389 registerunsigned int idx;400 struct nameseq *chain; 401 unsigned int idx; 390 402 391 403 chain = multi_glob (parse_file_seq … … 400 412 { 401 413 length = 100; 402 result = (char *)xmalloc (100);414 result = xmalloc (100); 403 415 } 404 416 … … 406 418 while (chain != 0) 407 419 { 408 registerchar *name = chain->name;420 const char *name = chain->name; 409 421 unsigned int len = strlen (name); 410 422 411 423 struct nameseq *next = chain->next; 412 free ( (char *)chain);424 free (chain); 413 425 chain = next; 414 426 … … 420 432 { 421 433 length += (len + 1) * 2; 422 result = (char *)xrealloc (result, length);434 result = xrealloc (result, length); 423 435 } 424 bcopy (name, &result[idx], len);436 memcpy (&result[idx], name, len); 425 437 idx += len; 426 438 result[idx++] = ' '; 427 439 } 428 429 free (name);430 440 } 431 441 … … 447 457 func_patsubst (char *o, char **argv, const char *funcname UNUSED) 448 458 { 449 o = patsubst_expand (o, argv[2], argv[0], argv[1] , (char *) 0, (char *) 0);459 o = patsubst_expand (o, argv[2], argv[0], argv[1]); 450 460 return o; 451 461 } … … 461 471 If the two arguments have a different number of words, 462 472 the excess words are just output separated by blanks. */ 463 registerchar *tp;464 registerchar *pp;465 c har *list1_iterator = argv[0];466 c har *list2_iterator = argv[1];473 const char *tp; 474 const char *pp; 475 const char *list1_iterator = argv[0]; 476 const char *list2_iterator = argv[1]; 467 477 do 468 478 { … … 496 506 { 497 507 /* Expand the argument. */ 498 registerstruct variable *v = lookup_variable (argv[0], strlen (argv[0]));508 struct variable *v = lookup_variable (argv[0], strlen (argv[0])); 499 509 if (v == 0) 500 510 o = variable_buffer_output (o, "undefined", 9); … … 535 545 func_flavor (char *o, char **argv, const char *funcname UNUSED) 536 546 { 537 registerstruct variable *v = lookup_variable (argv[0], strlen (argv[0]));547 struct variable *v = lookup_variable (argv[0], strlen (argv[0])); 538 548 539 549 if (v == 0) … … 563 573 { 564 574 /* Expand the argument. */ 565 c har *list_iterator = argv[0];566 c har *p2 =0;575 const char *list_iterator = argv[0]; 576 const char *p2; 567 577 int doneany =0; 568 578 unsigned int len=0; … … 572 582 while ((p2 = find_next_token (&list_iterator, &len)) != 0) 573 583 { 574 c har *p = p2 + len;584 const char *p = p2 + len; 575 585 576 586 … … 607 617 } 608 618 } 619 609 620 if (doneany) 610 621 /* Kill last space. */ 611 622 --o; 612 623 613 614 return o; 615 624 return o; 616 625 } 617 626 … … 621 630 { 622 631 /* Expand the argument. */ 623 c har *p3 = argv[0];624 c har *p2=0;632 const char *p3 = argv[0]; 633 const char *p2; 625 634 int doneany=0; 626 635 unsigned int len=0; 627 char *p=0; 636 628 637 int is_basename= streq (funcname, "basename"); 629 638 int is_dir= !is_basename; 630 639 631 640 while ((p2 = find_next_token (&p3, &len)) != 0) 632 633 634 635 636 637 638 639 640 641 642 643 644 641 { 642 const char *p = p2 + len; 643 while (p >= p2 && (!is_basename || *p != '.')) 644 { 645 if (IS_PATHSEP (*p)) 646 break; 647 --p; 648 } 649 650 if (p >= p2 && (is_dir)) 651 o = variable_buffer_output (o, p2, ++p - p2); 652 else if (p >= p2 && (*p == '.')) 653 o = variable_buffer_output (o, p2, p - p2); 645 654 #ifdef HAVE_DOS_PATHS 646 647 648 649 #endif 650 655 /* Handle the "d:foobar" case */ 656 else if (p2[0] && p2[1] == ':' && is_dir) 657 o = variable_buffer_output (o, p2, 2); 658 #endif 659 else if (is_dir) 651 660 #ifdef VMS 652 661 o = variable_buffer_output (o, "[]", 2); 653 662 #else 654 663 #ifndef _AMIGA 655 664 o = variable_buffer_output (o, "./", 2); 656 665 #else 657 666 ; /* Just a nop... */ 658 667 #endif /* AMIGA */ 659 668 #endif /* !VMS */ 660 661 662 663 664 665 666 667 if (doneany) 668 /* Kill last space. */ 669 --o; 670 671 672 return o;669 else 670 /* The entire name is the basename. */ 671 o = variable_buffer_output (o, p2, len); 672 673 o = variable_buffer_output (o, " ", 1); 674 doneany = 1; 675 } 676 677 if (doneany) 678 /* Kill last space. */ 679 --o; 680 681 return o; 673 682 } 674 683 … … 677 686 { 678 687 int fixlen = strlen (argv[0]); 679 c har *list_iterator = argv[1];688 const char *list_iterator = argv[1]; 680 689 int is_addprefix = streq (funcname, "addprefix"); 681 690 int is_addsuffix = !is_addprefix; 682 691 683 692 int doneany = 0; 684 c har *p;693 const char *p; 685 694 unsigned int len; 686 695 … … 717 726 { 718 727 unsigned int i; 719 c har *words = argv[0]; /* Use a temp variable for find_next_token */720 c har *p = find_next_token (&words, &i);728 const char *words = argv[0]; /* Use a temp variable for find_next_token */ 729 const char *p = find_next_token (&words, &i); 721 730 722 731 if (p != 0) … … 730 739 { 731 740 unsigned int i; 732 c har *words = argv[0]; /* Use a temp variable for find_next_token */733 c har *p = 0;734 c har *t;741 const char *words = argv[0]; /* Use a temp variable for find_next_token */ 742 const char *p = NULL; 743 const char *t; 735 744 736 745 while ((t = find_next_token (&words, &i))) … … 747 756 { 748 757 int i = 0; 749 c har *word_iterator = argv[0];758 const char *word_iterator = argv[0]; 750 759 char buf[20]; 751 760 … … 755 764 sprintf (buf, "%d", i); 756 765 o = variable_buffer_output (o, buf, strlen (buf)); 757 758 766 759 767 return o; … … 776 784 777 785 static void 778 check_numeric (const char *s, const char *m essage)786 check_numeric (const char *s, const char *msg) 779 787 { 780 788 const char *end = s + strlen (s) - 1; … … 787 795 788 796 if (s <= end || end - beg < 0) 789 fatal (*expanding_var, "%s: '%s'", m essage, beg);797 fatal (*expanding_var, "%s: '%s'", msg, beg); 790 798 } 791 799 … … 795 803 func_word (char *o, char **argv, const char *funcname UNUSED) 796 804 { 797 c har *end_p=0;798 int i=0;799 char *p=0;805 const char *end_p; 806 const char *p; 807 int i; 800 808 801 809 /* Check the first argument. */ 802 810 check_numeric (argv[0], _("non-numeric first argument to `word' function")); 803 i = 811 i = atoi (argv[0]); 804 812 805 813 if (i == 0) 806 814 fatal (*expanding_var, 807 815 _("first argument to `word' function must be greater than 0")); 808 809 816 810 817 end_p = argv[1]; … … 839 846 if (count > 0) 840 847 { 841 c har *p;842 c har *end_p = argv[2];848 const char *p; 849 const char *end_p = argv[2]; 843 850 844 851 /* Find the beginning of the "start"th word. */ … … 860 867 } 861 868 862 static char *869 static char * 863 870 func_findstring (char *o, char **argv, const char *funcname UNUSED) 864 871 { … … 876 883 char *varname = expand_argument (argv[0], NULL); 877 884 char *list = expand_argument (argv[1], NULL); 878 c har *body = argv[2];885 const char *body = argv[2]; 879 886 880 887 int doneany = 0; 881 c har *list_iterator = list;882 c har *p;888 const char *list_iterator = list; 889 const char *p; 883 890 unsigned int len; 884 registerstruct variable *var;891 struct variable *var; 885 892 886 893 push_new_variable_scope (); … … 902 909 var->value_length = len; 903 910 #else 904 { 905 char save = p[len]; 906 907 p[len] = '\0'; 908 free (var->value); 909 var->value = (char *) xstrdup ((char*) p); 910 p[len] = save; 911 } 911 free (var->value); 912 var->value = savestring (p, len); 912 913 #endif 913 914 … … 983 984 struct hash_table a_word_table; 984 985 int is_filter = streq (funcname, "filter"); 985 c har *pat_iterator = argv[0];986 c har *word_iterator = argv[1];986 const char *pat_iterator = argv[0]; 987 const char *word_iterator = argv[1]; 987 988 int literals = 0; 988 989 int words = 0; … … 996 997 while ((p = find_next_token (&pat_iterator, &len)) != 0) 997 998 { 998 struct a_pattern *pat = (struct a_pattern *)alloca (sizeof (struct a_pattern));999 struct a_pattern *pat = alloca (sizeof (struct a_pattern)); 999 1000 1000 1001 *pattail = pat; … … 1019 1020 while ((p = find_next_token (&word_iterator, &len)) != 0) 1020 1021 { 1021 struct a_word *word = (struct a_word *)alloca (sizeof (struct a_word));1022 struct a_word *word = alloca (sizeof (struct a_word)); 1022 1023 1023 1024 *wordtail = word; … … 1040 1041 if (hashing) 1041 1042 { 1042 hash_init (&a_word_table, words, a_word_hash_1, a_word_hash_2, a_word_hash_cmp); 1043 hash_init (&a_word_table, words, a_word_hash_1, a_word_hash_2, 1044 a_word_hash_cmp); 1043 1045 for (wp = wordhead; wp != 0; wp = wp->next) 1044 1046 { … … 1064 1066 a_word_key.str = pp->str; 1065 1067 a_word_key.length = pp->length; 1066 wp = (struct a_word *)hash_find_item (&a_word_table, &a_word_key);1068 wp = hash_find_item (&a_word_table, &a_word_key); 1067 1069 while (wp) 1068 1070 { … … 1104 1106 func_strip (char *o, char **argv, const char *funcname UNUSED) 1105 1107 { 1106 c har *p = argv[0];1107 int doneany = 0;1108 const char *p = argv[0]; 1109 int doneany = 0; 1108 1110 1109 1111 while (*p != '\0') 1110 1112 { 1111 1113 int i=0; 1112 c har *word_start=0;1114 const char *word_start; 1113 1115 1114 1116 while (isspace ((unsigned char)*p)) … … 1127 1129 /* Kill the last space. */ 1128 1130 --o; 1131 1129 1132 return o; 1130 1133 } … … 1146 1149 len += strlen (*argvp) + 2; 1147 1150 1148 p = msg = (char *)alloca (len + 1);1151 p = msg = alloca (len + 1); 1149 1152 1150 1153 for (argvp=argv; argvp[1] != 0; ++argvp) … … 1185 1188 func_sort (char *o, char **argv, const char *funcname UNUSED) 1186 1189 { 1187 char **words = 0; 1188 int nwords = 0; 1189 register int wordi = 0; 1190 1191 /* Chop ARGV[0] into words and put them in WORDS. */ 1192 char *t = argv[0]; 1190 const char *t; 1191 char **words; 1192 int wordi; 1193 1193 char *p; 1194 1194 unsigned int len; 1195 1195 int i; 1196 1196 1197 /* Find the maximum number of words we'll have. */ 1198 t = argv[0]; 1199 wordi = 1; 1200 while (*t != '\0') 1201 { 1202 char c = *(t++); 1203 1204 if (! isspace ((unsigned char)c)) 1205 continue; 1206 1207 ++wordi; 1208 1209 while (isspace ((unsigned char)*t)) 1210 ++t; 1211 } 1212 1213 words = xmalloc (wordi * sizeof (char *)); 1214 1215 /* Now assign pointers to each string in the array. */ 1216 t = argv[0]; 1217 wordi = 0; 1197 1218 while ((p = find_next_token (&t, &len)) != 0) 1198 1219 { 1199 if (wordi >= nwords - 1) 1200 { 1201 nwords = (2 * nwords) + 5; 1202 words = (char **) xrealloc ((char *) words, 1203 nwords * sizeof (char *)); 1204 } 1205 words[wordi++] = savestring (p, len); 1206 } 1207 1208 if (!wordi) 1209 return o; 1210 1211 /* Now sort the list of words. */ 1212 qsort ((char *) words, wordi, sizeof (char *), alpha_compare); 1213 1214 /* Now write the sorted list. */ 1215 for (i = 0; i < wordi; ++i) 1216 { 1217 len = strlen (words[i]); 1218 if (i == wordi - 1 || strlen (words[i + 1]) != len 1219 || strcmp (words[i], words[i + 1])) 1220 ++t; 1221 p[len] = '\0'; 1222 words[wordi++] = p; 1223 } 1224 1225 if (wordi) 1226 { 1227 /* Now sort the list of words. */ 1228 qsort (words, wordi, sizeof (char *), alpha_compare); 1229 1230 /* Now write the sorted list, uniquified. */ 1231 #ifdef CONFIG_WITH_RSORT 1232 if (strcmp (funcname, "rsort")) 1220 1233 { 1221 o = variable_buffer_output (o, words[i], len); 1222 o = variable_buffer_output (o, " ", 1); 1234 /* sort */ 1235 #endif 1236 for (i = 0; i < wordi; ++i) 1237 { 1238 len = strlen (words[i]); 1239 if (i == wordi - 1 || strlen (words[i + 1]) != len 1240 || strcmp (words[i], words[i + 1])) 1241 { 1242 o = variable_buffer_output (o, words[i], len); 1243 o = variable_buffer_output (o, " ", 1); 1244 } 1245 } 1246 #ifdef CONFIG_WITH_RSORT 1223 1247 } 1224 free (words[i]); 1225 } 1226 /* Kill the last space. */ 1227 --o; 1248 else 1249 { 1250 /* rsort - reverse the result */ 1251 i = wordi; 1252 while (i-- > 0) 1253 { 1254 len = strlen (words[i]); 1255 if (i == 0 || strlen (words[i + 1]) != len 1256 || strcmp (words[i], words[i + 1])) 1257 { 1258 o = variable_buffer_output (o, words[i], len); 1259 o = variable_buffer_output (o, " ", 1); 1260 } 1261 } 1262 } 1263 #endif 1264 1265 /* Kill the last space. */ 1266 --o; 1267 } 1228 1268 1229 1269 free (words); … … 1271 1311 argv += 1 + !result; 1272 1312 1273 if (argv[0]) 1274 { 1275 char *expansion; 1276 1277 expansion = expand_argument (argv[0], NULL); 1313 if (*argv) 1314 { 1315 char *expansion = expand_argument (*argv, NULL); 1278 1316 1279 1317 o = variable_buffer_output (o, expansion, strlen (expansion)); … … 1392 1430 func_wildcard (char *o, char **argv, const char *funcname UNUSED) 1393 1431 { 1394 1395 1432 #ifdef _AMIGA 1396 1433 o = wildcard_expansion (argv[0], o); … … 1637 1674 func_shell (char *o, char **argv, const char *funcname UNUSED) 1638 1675 { 1639 char *batch_filename = NULL;1676 char *batch_filename = NULL; 1640 1677 1641 1678 #ifdef __MSDOS__ … … 1643 1680 #endif 1644 1681 char **command_argv; 1645 c har *error_prefix;1682 const char *error_prefix; 1646 1683 char **envp; 1647 1684 int pipedes[2]; … … 1650 1687 #ifndef __MSDOS__ 1651 1688 /* Construct the argument list. */ 1652 command_argv = construct_command_argv (argv[0], 1653 (char **) NULL, (struct file *) 0, 1654 &batch_filename); 1689 command_argv = construct_command_argv (argv[0], NULL, NULL, &batch_filename); 1655 1690 if (command_argv == 0) 1656 1691 return o; … … 1664 1699 calling environment. 1665 1700 1701 See Savannah bug #10593. 1702 1666 1703 envp = target_environment (NILF); 1667 1704 */ … … 1672 1709 if (reading_file && reading_file->filenm) 1673 1710 { 1674 error_prefix = (char *)alloca (strlen (reading_file->filenm)+11+4);1675 sprintf ( error_prefix,1676 "%s:%lu: ", reading_file->filenm, reading_file->lineno);1711 char *p = alloca (strlen (reading_file->filenm)+11+4); 1712 sprintf (p, "%s:%lu: ", reading_file->filenm, reading_file->lineno); 1713 error_prefix = p; 1677 1714 } 1678 1715 else 1679 1716 error_prefix = ""; 1680 1717 1681 #ifdef WINDOWS32 1682 1683 windows32_openpipe (pipedes, &pid, command_argv, envp); 1684 1685 if (pipedes[0] < 0) { 1686 /* open of the pipe failed, mark as failed execution */ 1687 shell_function_completed = -1; 1688 1689 return o; 1690 } else 1691 1692 #elif defined(__MSDOS__) 1693 1718 #if defined(__MSDOS__) 1694 1719 fpipe = msdos_openpipe (pipedes, &pid, argv[0]); 1695 1720 if (pipedes[0] < 0) … … 1698 1723 return o; 1699 1724 } 1700 1725 #elif defined(WINDOWS32) 1726 windows32_openpipe (pipedes, &pid, command_argv, envp); 1727 if (pipedes[0] < 0) 1728 { 1729 /* open of the pipe failed, mark as failed execution */ 1730 shell_function_completed = -1; 1731 1732 return o; 1733 } 1734 else 1701 1735 #else 1702 1703 1736 if (pipe (pipedes) < 0) 1704 1737 { … … 1708 1741 1709 1742 # ifdef __EMX__ 1710 1711 1743 /* close some handles that are unnecessary for the child process */ 1712 1744 CLOSE_ON_EXEC(pipedes[1]); … … 1716 1748 if (pid < 0) 1717 1749 perror_with_name (error_prefix, "spawn"); 1718 1719 1750 # else /* ! __EMX__ */ 1720 1721 1751 pid = vfork (); 1722 1752 if (pid < 0) … … 1725 1755 child_execute_job (0, pipedes[1], command_argv, envp); 1726 1756 else 1727 1728 1757 # endif 1729 1730 1758 #endif 1731 1759 { … … 1742 1770 /* Free the storage only the child needed. */ 1743 1771 free (command_argv[0]); 1744 free ( (char *)command_argv);1772 free (command_argv); 1745 1773 1746 1774 /* Close the write side of the pipe. */ 1747 # ifdef _MSC_VER /* crap.*/1775 # ifdef _MSC_VER /* Avoid annoying msvcrt when debugging. (bird) */ 1748 1776 if (pipedes[1] != -1) 1749 # endif 1750 (void)close (pipedes[1]);1777 # endif 1778 close (pipedes[1]); 1751 1779 #endif 1752 1780 … … 1754 1782 1755 1783 maxlen = 200; 1756 buffer = (char *)xmalloc (maxlen + 1);1784 buffer = xmalloc (maxlen + 1); 1757 1785 1758 1786 /* Read from the pipe until it gets EOF. */ … … 1762 1790 { 1763 1791 maxlen += 512; 1764 buffer = (char *)xrealloc (buffer, maxlen + 1);1792 buffer = xrealloc (buffer, maxlen + 1); 1765 1793 } 1766 1794 … … 1776 1804 (void) pclose (fpipe); 1777 1805 #else 1778 # ifdef _MSC_VER /* crap.*/1806 # ifdef _MSC_VER /* Avoid annoying msvcrt when debugging. (bird) */ 1779 1807 if (pipedes[0] != -1) 1780 # endif 1808 # endif 1781 1809 (void) close (pipedes[0]); 1782 1810 #endif … … 1892 1920 { 1893 1921 maxlen += 512; 1894 buffer = (char *)xrealloc (buffer, maxlen + 1);1922 buffer = xrealloc (buffer, maxlen + 1); 1895 1923 } 1896 1924 … … 1930 1958 func_not (char *o, char **argv, const char *funcname) 1931 1959 { 1932 c har *s = argv[0];1960 const char *s = argv[0]; 1933 1961 int result = 0; 1934 1962 while (isspace ((unsigned char)*s)) … … 2063 2091 { 2064 2092 /* Expand the argument. */ 2065 c har *p = argv[0];2066 c har *path = 0;2093 const char *p = argv[0]; 2094 const char *path = 0; 2067 2095 int doneany = 0; 2068 2096 unsigned int len = 0; … … 2077 2105 in[len] = '\0'; 2078 2106 2079 if 2080 ( 2107 if ( 2081 2108 #ifdef HAVE_REALPATH 2082 realpath (in, out)2109 realpath (in, out) 2083 2110 #else 2084 abspath (in, out)2085 #endif 2086 )2111 abspath (in, out) 2112 #endif 2113 ) 2087 2114 { 2088 2115 o = variable_buffer_output (o, out, strlen (out)); … … 2097 2124 --o; 2098 2125 2099 return o;2126 return o; 2100 2127 } 2101 2128 … … 2104 2131 { 2105 2132 /* Expand the argument. */ 2106 c har *p = argv[0];2107 c har *path = 0;2133 const char *p = argv[0]; 2134 const char *path = 0; 2108 2135 int doneany = 0; 2109 2136 unsigned int len = 0; … … 2131 2158 --o; 2132 2159 2133 return o;2160 return o; 2134 2161 } 2135 2162 … … 2141 2168 /* Expand the argument. */ 2142 2169 char *p = argv[0]; 2143 PATH_VAR (current_directory);2144 2170 char *cwd = argv[1]; 2145 2171 unsigned int cwd_len = ~0U; … … 2974 3000 } 2975 3001 2976 2977 3002 #endif /* CONFIG_WITH_MATH */ 3003 2978 3004 2979 3005 /* Lookup table for builtin functions. … … 2989 3015 Functions that do namespace tricks (foreach) don't automatically expand. */ 2990 3016 2991 static char *func_call PARAMS ((char *o, char **argv, const char *funcname));3017 static char *func_call (char *o, char **argv, const char *funcname); 2992 3018 2993 3019 … … 3012 3038 { STRING_SIZE_TUPLE("patsubst"), 3, 3, 1, func_patsubst}, 3013 3039 { STRING_SIZE_TUPLE("realpath"), 0, 1, 1, func_realpath}, 3040 #ifdef CONFIG_WITH_RSORT 3041 { STRING_SIZE_TUPLE("rsort"), 0, 1, 1, func_sort}, 3042 #endif 3014 3043 { STRING_SIZE_TUPLE("shell"), 0, 1, 1, func_shell}, 3015 3044 { STRING_SIZE_TUPLE("sort"), 0, 1, 1, func_sort}, … … 3115 3144 3116 3145 static int 3117 handle_function2 (const struct function_table_entry *entry_p, char **op, c har **stringp) /* bird split it up. */3146 handle_function2 (const struct function_table_entry *entry_p, char **op, const char **stringp) /* bird split it up. */ 3118 3147 { 3119 3148 char openparen = (*stringp)[0]; 3120 3149 char closeparen = openparen == '(' ? ')' : '}'; 3121 c har *beg;3122 c har *end;3150 const char *beg; 3151 const char *end; 3123 3152 int count = 0; 3124 register char *p;3153 char *abeg = NULL; 3125 3154 char **argv, **argvp; 3126 3155 int nargs; … … 3154 3183 3155 3184 /* Get some memory to store the arg pointers. */ 3156 argvp = argv = (char **)alloca (sizeof (char *) * (nargs + 2));3185 argvp = argv = alloca (sizeof (char *) * (nargs + 2)); 3157 3186 3158 3187 /* Chop the string into arguments, then a nul. As soon as we hit … … 3164 3193 each argument. */ 3165 3194 3166 if (!entry_p->expand_args) 3195 if (entry_p->expand_args) 3196 { 3197 const char *p; 3198 for (p=beg, nargs=0; p <= end; ++argvp) 3199 { 3200 const char *next; 3201 3202 ++nargs; 3203 3204 if (nargs == entry_p->maximum_args 3205 || (! (next = find_next_argument (openparen, closeparen, p, end)))) 3206 next = end; 3207 3208 *argvp = expand_argument (p, next); 3209 p = next + 1; 3210 } 3211 } 3212 else 3167 3213 { 3168 3214 int len = end - beg; 3169 3170 p = xmalloc (len+1); 3171 memcpy (p, beg, len); 3172 p[len] = '\0'; 3173 beg = p; 3174 end = beg + len; 3175 } 3176 3177 for (p=beg, nargs=0; p <= end; ++argvp) 3178 { 3179 char *next; 3180 3181 ++nargs; 3182 3183 if (nargs == entry_p->maximum_args 3184 || (! (next = find_next_argument (openparen, closeparen, p, end)))) 3185 next = end; 3186 3187 if (entry_p->expand_args) 3188 *argvp = expand_argument (p, next); 3189 else 3215 char *p, *aend; 3216 3217 abeg = xmalloc (len+1); 3218 memcpy (abeg, beg, len); 3219 abeg[len] = '\0'; 3220 aend = abeg + len; 3221 3222 for (p=abeg, nargs=0; p <= aend; ++argvp) 3190 3223 { 3224 char *next; 3225 3226 ++nargs; 3227 3228 if (nargs == entry_p->maximum_args 3229 || (! (next = find_next_argument (openparen, closeparen, p, aend)))) 3230 next = aend; 3231 3191 3232 *argvp = p; 3192 3233 *next = '\0'; 3234 p = next + 1; 3193 3235 } 3194 3195 p = next + 1;3196 3236 } 3197 3237 *argvp = NULL; … … 3204 3244 for (argvp=argv; *argvp != 0; ++argvp) 3205 3245 free (*argvp); 3206 else3207 free ( beg);3246 if (abeg) 3247 free (abeg); 3208 3248 3209 3249 return 1; … … 3211 3251 3212 3252 int 3213 handle_function (char **op, c har **stringp) /* bird split it up */3253 handle_function (char **op, const char **stringp) /* bird split it up */ 3214 3254 { 3215 3255 const struct function_table_entry *entry_p = lookup_function (*stringp + 1); … … 3256 3296 3257 3297 entry_p = lookup_function (fname); 3258 3259 3298 if (entry_p) 3260 3299 { 3261 3300 /* How many arguments do we have? */ 3262 3301 for (i=0; argv[i+1]; ++i) 3263 ; 3264 3302 ; 3265 3303 return expand_builtin_function (o, i, argv+1, entry_p); 3266 3304 } … … 3278 3316 return o; 3279 3317 3280 body = (char *)alloca (flen + 4);3318 body = alloca (flen + 4); 3281 3319 body[0] = '$'; 3282 3320 body[1] = '('; … … 3339 3377 unsigned i; 3340 3378 for (i = 0; i < FUNCTION_TABLE_ENTRIES; i++) 3341 assert (function_table_init[i].len <= MAX_FUNCTION_LENGTH);3379 assert (function_table_init[i].len <= MAX_FUNCTION_LENGTH); 3342 3380 } 3343 3381 #endif
Note:
See TracChangeset
for help on using the changeset viewer.