Changeset 900 in kBuild for vendor/gnumake/current/function.c
- Timestamp:
- May 23, 2007 3:13:11 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/function.c
r501 r900 37 37 unsigned char maximum_args; 38 38 char expand_args; 39 char *(*func_ptr) PARAMS ((char *output, char **argv, const char *fname));39 char *(*func_ptr) (char *output, char **argv, const char *fname); 40 40 }; 41 41 … … 43 43 function_table_entry_hash_1 (const void *keyv) 44 44 { 45 struct function_table_entry const *key = (struct function_table_entry const *)keyv;45 const struct function_table_entry *key = keyv; 46 46 return_STRING_N_HASH_1 (key->name, key->len); 47 47 } … … 50 50 function_table_entry_hash_2 (const void *keyv) 51 51 { 52 struct function_table_entry const *key = (struct function_table_entry const *)keyv;52 const struct function_table_entry *key = keyv; 53 53 return_STRING_N_HASH_2 (key->name, key->len); 54 54 } … … 57 57 function_table_entry_hash_cmp (const void *xv, const void *yv) 58 58 { 59 struct function_table_entry const *x = (struct function_table_entry const *)xv;60 struct function_table_entry const *y = (struct function_table_entry const *)yv;59 const struct function_table_entry *x = xv; 60 const struct function_table_entry *y = yv; 61 61 int result = x->len - y->len; 62 62 if (result) … … 76 76 77 77 char * 78 subst_expand (char *o, c har *text, char *subst,char *replace,78 subst_expand (char *o, const char *text, const char *subst, const char *replace, 79 79 unsigned int slen, unsigned int rlen, int by_word) 80 80 { 81 c har *t = text;82 c har *p;81 const char *t = text; 82 const char *p; 83 83 84 84 if (slen == 0 && !by_word) … … 125 125 126 126 /* Advance T past the string to be replaced. */ 127 { 128 char *nt = p + slen; 129 t = nt; 130 } 127 t = p + slen; 131 128 } while (*t != '\0'); 132 129 … … 147 144 148 145 char * 149 patsubst_expand (char *o, char *text, char *pattern, char *replace, 150 char *pattern_percent, char *replace_percent) 146 patsubst_expand_pat (char *o, const char *text, 147 const char *pattern, const char *replace, 148 const char *pattern_percent, const char *replace_percent) 151 149 { 152 150 unsigned int pattern_prepercent_len, pattern_postpercent_len; 153 151 unsigned int replace_prepercent_len, replace_postpercent_len; 154 c har *t;152 const char *t; 155 153 unsigned int len; 156 154 int doneany = 0; 157 158 /* We call find_percent on REPLACE before checking PATTERN so that REPLACE159 will be collapsed before we call subst_expand if PATTERN has no %. */160 if (!replace_percent)161 {162 replace_percent = find_percent (replace);163 if (replace_percent)164 ++replace_percent;165 }166 155 167 156 /* Record the length of REPLACE before and after the % so we don't have to … … 178 167 } 179 168 180 if (!pattern_percent)181 {182 pattern_percent = find_percent (pattern);183 if (pattern_percent)184 ++pattern_percent;185 }186 169 if (!pattern_percent) 187 170 /* With no % in the pattern, this is just a simple substitution. */ … … 255 238 } 256 239 240 /* Store into VARIABLE_BUFFER at O the result of scanning TEXT 241 and replacing strings matching PATTERN with REPLACE. 242 If PATTERN_PERCENT is not nil, PATTERN has already been 243 run through find_percent, and PATTERN_PERCENT is the result. 244 If REPLACE_PERCENT is not nil, REPLACE has already been 245 run through find_percent, and REPLACE_PERCENT is the result. 246 Note that we expect PATTERN_PERCENT and REPLACE_PERCENT to point to the 247 character _AFTER_ the %, not to the % itself. 248 */ 249 250 char * 251 patsubst_expand (char *o, const char *text, char *pattern, char *replace) 252 { 253 const char *pattern_percent = find_percent (pattern); 254 const char *replace_percent = find_percent (replace); 255 256 /* If there's a percent in the pattern or replacement skip it. */ 257 if (replace_percent) 258 ++replace_percent; 259 if (pattern_percent) 260 ++pattern_percent; 261 262 return patsubst_expand_pat (o, text, pattern, replace, 263 pattern_percent, replace_percent); 264 } 265 257 266 258 267 … … 282 291 283 292 int 284 pattern_matches (c har *pattern, char *percent,char *str)293 pattern_matches (const char *pattern, const char *percent, const char *str) 285 294 { 286 295 unsigned int sfxlen, strlength; … … 289 298 { 290 299 unsigned int len = strlen (pattern) + 1; 291 char *new_chars = (char *) alloca (len); 292 bcopy (pattern, new_chars, len); 300 char *new_chars = alloca (len); 301 memcpy (new_chars, pattern, len); 302 percent = find_percent (new_chars); 303 if (percent == 0) 304 return streq (new_chars, str); 293 305 pattern = new_chars; 294 percent = find_percent (pattern);295 if (percent == 0)296 return streq (pattern, str);297 306 } 298 307 … … 350 359 static char *result = 0; 351 360 static unsigned int length; 352 registerstruct nameseq *chain;353 registerunsigned int idx;361 struct nameseq *chain; 362 unsigned int idx; 354 363 355 364 chain = multi_glob (parse_file_seq … … 364 373 { 365 374 length = 100; 366 result = (char *)xmalloc (100);375 result = xmalloc (100); 367 376 } 368 377 … … 370 379 while (chain != 0) 371 380 { 372 registerchar *name = chain->name;381 const char *name = chain->name; 373 382 unsigned int len = strlen (name); 374 383 375 384 struct nameseq *next = chain->next; 376 free ( (char *)chain);385 free (chain); 377 386 chain = next; 378 387 … … 384 393 { 385 394 length += (len + 1) * 2; 386 result = (char *)xrealloc (result, length);395 result = xrealloc (result, length); 387 396 } 388 bcopy (name, &result[idx], len);397 memcpy (&result[idx], name, len); 389 398 idx += len; 390 399 result[idx++] = ' '; 391 400 } 392 393 free (name);394 401 } 395 402 … … 411 418 func_patsubst (char *o, char **argv, const char *funcname UNUSED) 412 419 { 413 o = patsubst_expand (o, argv[2], argv[0], argv[1] , (char *) 0, (char *) 0);420 o = patsubst_expand (o, argv[2], argv[0], argv[1]); 414 421 return o; 415 422 } … … 425 432 If the two arguments have a different number of words, 426 433 the excess words are just output separated by blanks. */ 427 registerchar *tp;428 registerchar *pp;429 c har *list1_iterator = argv[0];430 c har *list2_iterator = argv[1];434 const char *tp; 435 const char *pp; 436 const char *list1_iterator = argv[0]; 437 const char *list2_iterator = argv[1]; 431 438 do 432 439 { … … 460 467 { 461 468 /* Expand the argument. */ 462 registerstruct variable *v = lookup_variable (argv[0], strlen (argv[0]));469 struct variable *v = lookup_variable (argv[0], strlen (argv[0])); 463 470 if (v == 0) 464 471 o = variable_buffer_output (o, "undefined", 9); … … 499 506 func_flavor (char *o, char **argv, const char *funcname UNUSED) 500 507 { 501 registerstruct variable *v = lookup_variable (argv[0], strlen (argv[0]));508 struct variable *v = lookup_variable (argv[0], strlen (argv[0])); 502 509 503 510 if (v == 0) … … 527 534 { 528 535 /* Expand the argument. */ 529 c har *list_iterator = argv[0];530 c har *p2 =0;536 const char *list_iterator = argv[0]; 537 const char *p2; 531 538 int doneany =0; 532 539 unsigned int len=0; … … 536 543 while ((p2 = find_next_token (&list_iterator, &len)) != 0) 537 544 { 538 c har *p = p2 + len;545 const char *p = p2 + len; 539 546 540 547 … … 571 578 } 572 579 } 580 573 581 if (doneany) 574 582 /* Kill last space. */ 575 583 --o; 576 584 577 578 return o; 579 585 return o; 580 586 } 581 587 … … 585 591 { 586 592 /* Expand the argument. */ 587 c har *p3 = argv[0];588 c har *p2=0;593 const char *p3 = argv[0]; 594 const char *p2; 589 595 int doneany=0; 590 596 unsigned int len=0; 591 char *p=0; 597 592 598 int is_basename= streq (funcname, "basename"); 593 599 int is_dir= !is_basename; 594 600 595 601 while ((p2 = find_next_token (&p3, &len)) != 0) 596 597 598 599 600 601 602 603 604 605 606 607 608 602 { 603 const char *p = p2 + len; 604 while (p >= p2 && (!is_basename || *p != '.')) 605 { 606 if (IS_PATHSEP (*p)) 607 break; 608 --p; 609 } 610 611 if (p >= p2 && (is_dir)) 612 o = variable_buffer_output (o, p2, ++p - p2); 613 else if (p >= p2 && (*p == '.')) 614 o = variable_buffer_output (o, p2, p - p2); 609 615 #ifdef HAVE_DOS_PATHS 610 611 612 616 /* Handle the "d:foobar" case */ 617 else if (p2[0] && p2[1] == ':' && is_dir) 618 o = variable_buffer_output (o, p2, 2); 613 619 #endif 614 620 else if (is_dir) 615 621 #ifdef VMS 616 622 o = variable_buffer_output (o, "[]", 2); 617 623 #else 618 624 #ifndef _AMIGA 619 625 o = variable_buffer_output (o, "./", 2); 620 626 #else 621 627 ; /* Just a nop... */ 622 628 #endif /* AMIGA */ 623 629 #endif /* !VMS */ 624 625 626 627 628 629 630 631 if (doneany) 632 /* Kill last space. */ 633 --o; 634 635 636 return o;630 else 631 /* The entire name is the basename. */ 632 o = variable_buffer_output (o, p2, len); 633 634 o = variable_buffer_output (o, " ", 1); 635 doneany = 1; 636 } 637 638 if (doneany) 639 /* Kill last space. */ 640 --o; 641 642 return o; 637 643 } 638 644 … … 641 647 { 642 648 int fixlen = strlen (argv[0]); 643 c har *list_iterator = argv[1];649 const char *list_iterator = argv[1]; 644 650 int is_addprefix = streq (funcname, "addprefix"); 645 651 int is_addsuffix = !is_addprefix; 646 652 647 653 int doneany = 0; 648 c har *p;654 const char *p; 649 655 unsigned int len; 650 656 … … 681 687 { 682 688 unsigned int i; 683 c har *words = argv[0]; /* Use a temp variable for find_next_token */684 c har *p = find_next_token (&words, &i);689 const char *words = argv[0]; /* Use a temp variable for find_next_token */ 690 const char *p = find_next_token (&words, &i); 685 691 686 692 if (p != 0) … … 694 700 { 695 701 unsigned int i; 696 c har *words = argv[0]; /* Use a temp variable for find_next_token */697 c har *p = 0;698 c har *t;702 const char *words = argv[0]; /* Use a temp variable for find_next_token */ 703 const char *p = NULL; 704 const char *t; 699 705 700 706 while ((t = find_next_token (&words, &i))) … … 711 717 { 712 718 int i = 0; 713 c har *word_iterator = argv[0];719 const char *word_iterator = argv[0]; 714 720 char buf[20]; 715 721 … … 719 725 sprintf (buf, "%d", i); 720 726 o = variable_buffer_output (o, buf, strlen (buf)); 721 722 727 723 728 return o; … … 740 745 741 746 static void 742 check_numeric (const char *s, const char *m essage)747 check_numeric (const char *s, const char *msg) 743 748 { 744 749 const char *end = s + strlen (s) - 1; … … 751 756 752 757 if (s <= end || end - beg < 0) 753 fatal (*expanding_var, "%s: '%s'", m essage, beg);758 fatal (*expanding_var, "%s: '%s'", msg, beg); 754 759 } 755 760 … … 759 764 func_word (char *o, char **argv, const char *funcname UNUSED) 760 765 { 761 c har *end_p=0;762 int i=0;763 char *p=0;766 const char *end_p; 767 const char *p; 768 int i; 764 769 765 770 /* Check the first argument. */ 766 771 check_numeric (argv[0], _("non-numeric first argument to `word' function")); 767 i = 772 i = atoi (argv[0]); 768 773 769 774 if (i == 0) 770 775 fatal (*expanding_var, 771 776 _("first argument to `word' function must be greater than 0")); 772 773 777 774 778 end_p = argv[1]; … … 803 807 if (count > 0) 804 808 { 805 c har *p;806 c har *end_p = argv[2];809 const char *p; 810 const char *end_p = argv[2]; 807 811 808 812 /* Find the beginning of the "start"th word. */ … … 824 828 } 825 829 826 static char *830 static char * 827 831 func_findstring (char *o, char **argv, const char *funcname UNUSED) 828 832 { … … 840 844 char *varname = expand_argument (argv[0], NULL); 841 845 char *list = expand_argument (argv[1], NULL); 842 c har *body = argv[2];846 const char *body = argv[2]; 843 847 844 848 int doneany = 0; 845 c har *list_iterator = list;846 c har *p;849 const char *list_iterator = list; 850 const char *p; 847 851 unsigned int len; 848 registerstruct variable *var;852 struct variable *var; 849 853 850 854 push_new_variable_scope (); … … 856 860 char *result = 0; 857 861 858 { 859 char save = p[len]; 860 861 p[len] = '\0'; 862 free (var->value); 863 var->value = (char *) xstrdup ((char*) p); 864 p[len] = save; 865 } 862 free (var->value); 863 var->value = savestring (p, len); 866 864 867 865 result = allocated_variable_expand (body); … … 936 934 struct hash_table a_word_table; 937 935 int is_filter = streq (funcname, "filter"); 938 c har *pat_iterator = argv[0];939 c har *word_iterator = argv[1];936 const char *pat_iterator = argv[0]; 937 const char *word_iterator = argv[1]; 940 938 int literals = 0; 941 939 int words = 0; … … 949 947 while ((p = find_next_token (&pat_iterator, &len)) != 0) 950 948 { 951 struct a_pattern *pat = (struct a_pattern *)alloca (sizeof (struct a_pattern));949 struct a_pattern *pat = alloca (sizeof (struct a_pattern)); 952 950 953 951 *pattail = pat; … … 972 970 while ((p = find_next_token (&word_iterator, &len)) != 0) 973 971 { 974 struct a_word *word = (struct a_word *)alloca (sizeof (struct a_word));972 struct a_word *word = alloca (sizeof (struct a_word)); 975 973 976 974 *wordtail = word; … … 993 991 if (hashing) 994 992 { 995 hash_init (&a_word_table, words, a_word_hash_1, a_word_hash_2, a_word_hash_cmp); 993 hash_init (&a_word_table, words, a_word_hash_1, a_word_hash_2, 994 a_word_hash_cmp); 996 995 for (wp = wordhead; wp != 0; wp = wp->next) 997 996 { … … 1017 1016 a_word_key.str = pp->str; 1018 1017 a_word_key.length = pp->length; 1019 wp = (struct a_word *)hash_find_item (&a_word_table, &a_word_key);1018 wp = hash_find_item (&a_word_table, &a_word_key); 1020 1019 while (wp) 1021 1020 { … … 1057 1056 func_strip (char *o, char **argv, const char *funcname UNUSED) 1058 1057 { 1059 c har *p = argv[0];1060 int doneany = 0;1058 const char *p = argv[0]; 1059 int doneany = 0; 1061 1060 1062 1061 while (*p != '\0') 1063 1062 { 1064 1063 int i=0; 1065 c har *word_start=0;1064 const char *word_start; 1066 1065 1067 1066 while (isspace ((unsigned char)*p)) … … 1080 1079 /* Kill the last space. */ 1081 1080 --o; 1081 1082 1082 return o; 1083 1083 } … … 1099 1099 len += strlen (*argvp) + 2; 1100 1100 1101 p = msg = (char *)alloca (len + 1);1101 p = msg = alloca (len + 1); 1102 1102 1103 1103 for (argvp=argv; argvp[1] != 0; ++argvp) … … 1138 1138 func_sort (char *o, char **argv, const char *funcname UNUSED) 1139 1139 { 1140 char **words = 0; 1141 int nwords = 0; 1142 register int wordi = 0; 1143 1144 /* Chop ARGV[0] into words and put them in WORDS. */ 1145 char *t = argv[0]; 1140 const char *t; 1141 char **words; 1142 int wordi; 1146 1143 char *p; 1147 1144 unsigned int len; 1148 1145 int i; 1149 1146 1147 /* Find the maximum number of words we'll have. */ 1148 t = argv[0]; 1149 wordi = 1; 1150 while (*t != '\0') 1151 { 1152 char c = *(t++); 1153 1154 if (! isspace ((unsigned char)c)) 1155 continue; 1156 1157 ++wordi; 1158 1159 while (isspace ((unsigned char)*t)) 1160 ++t; 1161 } 1162 1163 words = xmalloc (wordi * sizeof (char *)); 1164 1165 /* Now assign pointers to each string in the array. */ 1166 t = argv[0]; 1167 wordi = 0; 1150 1168 while ((p = find_next_token (&t, &len)) != 0) 1151 1169 { 1152 if (wordi >= nwords - 1) 1153 { 1154 nwords = (2 * nwords) + 5; 1155 words = (char **) xrealloc ((char *) words, 1156 nwords * sizeof (char *)); 1157 } 1158 words[wordi++] = savestring (p, len); 1159 } 1160 1161 if (!wordi) 1162 return o; 1163 1164 /* Now sort the list of words. */ 1165 qsort ((char *) words, wordi, sizeof (char *), alpha_compare); 1166 1167 /* Now write the sorted list. */ 1168 for (i = 0; i < wordi; ++i) 1169 { 1170 len = strlen (words[i]); 1171 if (i == wordi - 1 || strlen (words[i + 1]) != len 1172 || strcmp (words[i], words[i + 1])) 1170 ++t; 1171 p[len] = '\0'; 1172 words[wordi++] = p; 1173 } 1174 1175 if (wordi) 1176 { 1177 /* Now sort the list of words. */ 1178 qsort (words, wordi, sizeof (char *), alpha_compare); 1179 1180 /* Now write the sorted list, uniquified. */ 1181 for (i = 0; i < wordi; ++i) 1173 1182 { 1174 o = variable_buffer_output (o, words[i], len); 1175 o = variable_buffer_output (o, " ", 1); 1183 len = strlen (words[i]); 1184 if (i == wordi - 1 || strlen (words[i + 1]) != len 1185 || strcmp (words[i], words[i + 1])) 1186 { 1187 o = variable_buffer_output (o, words[i], len); 1188 o = variable_buffer_output (o, " ", 1); 1189 } 1176 1190 } 1177 free (words[i]); 1178 }1179 /* Kill the last space. */1180 --o;1191 1192 /* Kill the last space. */ 1193 --o; 1194 } 1181 1195 1182 1196 free (words); … … 1224 1238 argv += 1 + !result; 1225 1239 1226 if (argv[0]) 1227 { 1228 char *expansion; 1229 1230 expansion = expand_argument (argv[0], NULL); 1240 if (*argv) 1241 { 1242 char *expansion = expand_argument (*argv, NULL); 1231 1243 1232 1244 o = variable_buffer_output (o, expansion, strlen (expansion)); … … 1345 1357 func_wildcard (char *o, char **argv, const char *funcname UNUSED) 1346 1358 { 1347 1348 1359 #ifdef _AMIGA 1349 1360 o = wildcard_expansion (argv[0], o); … … 1585 1596 func_shell (char *o, char **argv, const char *funcname UNUSED) 1586 1597 { 1587 char *batch_filename = NULL;1598 char *batch_filename = NULL; 1588 1599 1589 1600 #ifdef __MSDOS__ … … 1591 1602 #endif 1592 1603 char **command_argv; 1593 c har *error_prefix;1604 const char *error_prefix; 1594 1605 char **envp; 1595 1606 int pipedes[2]; … … 1598 1609 #ifndef __MSDOS__ 1599 1610 /* Construct the argument list. */ 1600 command_argv = construct_command_argv (argv[0], 1601 (char **) NULL, (struct file *) 0, 1602 &batch_filename); 1611 command_argv = construct_command_argv (argv[0], NULL, NULL, &batch_filename); 1603 1612 if (command_argv == 0) 1604 1613 return o; … … 1612 1621 calling environment. 1613 1622 1623 See Savannah bug #10593. 1624 1614 1625 envp = target_environment (NILF); 1615 1626 */ … … 1620 1631 if (reading_file && reading_file->filenm) 1621 1632 { 1622 error_prefix = (char *)alloca (strlen (reading_file->filenm)+11+4);1623 sprintf ( error_prefix,1624 "%s:%lu: ", reading_file->filenm, reading_file->lineno);1633 char *p = alloca (strlen (reading_file->filenm)+11+4); 1634 sprintf (p, "%s:%lu: ", reading_file->filenm, reading_file->lineno); 1635 error_prefix = p; 1625 1636 } 1626 1637 else 1627 1638 error_prefix = ""; 1628 1639 1629 #ifdef WINDOWS32 1630 1631 windows32_openpipe (pipedes, &pid, command_argv, envp); 1632 1633 if (pipedes[0] < 0) { 1634 /* open of the pipe failed, mark as failed execution */ 1635 shell_function_completed = -1; 1636 1637 return o; 1638 } else 1639 1640 #elif defined(__MSDOS__) 1641 1640 #if defined(__MSDOS__) 1642 1641 fpipe = msdos_openpipe (pipedes, &pid, argv[0]); 1643 1642 if (pipedes[0] < 0) … … 1646 1645 return o; 1647 1646 } 1648 1647 #elif defined(WINDOWS32) 1648 windows32_openpipe (pipedes, &pid, command_argv, envp); 1649 if (pipedes[0] < 0) 1650 { 1651 /* open of the pipe failed, mark as failed execution */ 1652 shell_function_completed = -1; 1653 1654 return o; 1655 } 1656 else 1649 1657 #else 1650 1651 1658 if (pipe (pipedes) < 0) 1652 1659 { … … 1656 1663 1657 1664 # ifdef __EMX__ 1658 1659 1665 /* close some handles that are unnecessary for the child process */ 1660 1666 CLOSE_ON_EXEC(pipedes[1]); … … 1664 1670 if (pid < 0) 1665 1671 perror_with_name (error_prefix, "spawn"); 1666 1667 1672 # else /* ! __EMX__ */ 1668 1669 1673 pid = vfork (); 1670 1674 if (pid < 0) … … 1673 1677 child_execute_job (0, pipedes[1], command_argv, envp); 1674 1678 else 1675 1676 1679 # endif 1677 1678 1680 #endif 1679 1681 { … … 1690 1692 /* Free the storage only the child needed. */ 1691 1693 free (command_argv[0]); 1692 free ( (char *)command_argv);1694 free (command_argv); 1693 1695 1694 1696 /* Close the write side of the pipe. */ 1695 (void)close (pipedes[1]);1697 close (pipedes[1]); 1696 1698 #endif 1697 1699 … … 1699 1701 1700 1702 maxlen = 200; 1701 buffer = (char *)xmalloc (maxlen + 1);1703 buffer = xmalloc (maxlen + 1); 1702 1704 1703 1705 /* Read from the pipe until it gets EOF. */ … … 1707 1709 { 1708 1710 maxlen += 512; 1709 buffer = (char *)xrealloc (buffer, maxlen + 1);1711 buffer = xrealloc (buffer, maxlen + 1); 1710 1712 } 1711 1713 … … 1834 1836 { 1835 1837 maxlen += 512; 1836 buffer = (char *)xrealloc (buffer, maxlen + 1);1838 buffer = xrealloc (buffer, maxlen + 1); 1837 1839 } 1838 1840 … … 1872 1874 func_not (char *o, char **argv, char *funcname) 1873 1875 { 1874 c har *s = argv[0];1876 const char *s = argv[0]; 1875 1877 int result = 0; 1876 1878 while (isspace ((unsigned char)*s)) … … 1966 1968 { 1967 1969 /* Expand the argument. */ 1968 c har *p = argv[0];1969 c har *path = 0;1970 const char *p = argv[0]; 1971 const char *path = 0; 1970 1972 int doneany = 0; 1971 1973 unsigned int len = 0; … … 1980 1982 in[len] = '\0'; 1981 1983 1982 if 1983 ( 1984 if ( 1984 1985 #ifdef HAVE_REALPATH 1985 realpath (in, out)1986 realpath (in, out) 1986 1987 #else 1987 abspath (in, out)1988 abspath (in, out) 1988 1989 #endif 1989 )1990 ) 1990 1991 { 1991 1992 o = variable_buffer_output (o, out, strlen (out)); … … 2000 2001 --o; 2001 2002 2002 return o;2003 return o; 2003 2004 } 2004 2005 … … 2007 2008 { 2008 2009 /* Expand the argument. */ 2009 c har *p = argv[0];2010 c har *path = 0;2010 const char *p = argv[0]; 2011 const char *path = 0; 2011 2012 int doneany = 0; 2012 2013 unsigned int len = 0; … … 2034 2035 --o; 2035 2036 2036 return o;2037 return o; 2037 2038 } 2038 2039 … … 2049 2050 Functions that do namespace tricks (foreach) don't automatically expand. */ 2050 2051 2051 static char *func_call PARAMS ((char *o, char **argv, const char *funcname));2052 static char *func_call (char *o, char **argv, const char *funcname); 2052 2053 2053 2054 … … 2131 2132 2132 2133 int 2133 handle_function (char **op, c har **stringp)2134 handle_function (char **op, const char **stringp) 2134 2135 { 2135 2136 const struct function_table_entry *entry_p; 2136 2137 char openparen = (*stringp)[0]; 2137 2138 char closeparen = openparen == '(' ? ')' : '}'; 2138 c har *beg;2139 c har *end;2139 const char *beg; 2140 const char *end; 2140 2141 int count = 0; 2141 register char *p;2142 char *abeg = NULL; 2142 2143 char **argv, **argvp; 2143 2144 int nargs; … … 2176 2177 2177 2178 /* Get some memory to store the arg pointers. */ 2178 argvp = argv = (char **)alloca (sizeof (char *) * (nargs + 2));2179 argvp = argv = alloca (sizeof (char *) * (nargs + 2)); 2179 2180 2180 2181 /* Chop the string into arguments, then a nul. As soon as we hit … … 2186 2187 each argument. */ 2187 2188 2188 if (!entry_p->expand_args) 2189 if (entry_p->expand_args) 2190 { 2191 const char *p; 2192 for (p=beg, nargs=0; p <= end; ++argvp) 2193 { 2194 const char *next; 2195 2196 ++nargs; 2197 2198 if (nargs == entry_p->maximum_args 2199 || (! (next = find_next_argument (openparen, closeparen, p, end)))) 2200 next = end; 2201 2202 *argvp = expand_argument (p, next); 2203 p = next + 1; 2204 } 2205 } 2206 else 2189 2207 { 2190 2208 int len = end - beg; 2191 2192 p = xmalloc (len+1); 2193 memcpy (p, beg, len); 2194 p[len] = '\0'; 2195 beg = p; 2196 end = beg + len; 2197 } 2198 2199 for (p=beg, nargs=0; p <= end; ++argvp) 2200 { 2201 char *next; 2202 2203 ++nargs; 2204 2205 if (nargs == entry_p->maximum_args 2206 || (! (next = find_next_argument (openparen, closeparen, p, end)))) 2207 next = end; 2208 2209 if (entry_p->expand_args) 2210 *argvp = expand_argument (p, next); 2211 else 2209 char *p, *aend; 2210 2211 abeg = xmalloc (len+1); 2212 memcpy (abeg, beg, len); 2213 abeg[len] = '\0'; 2214 aend = abeg + len; 2215 2216 for (p=abeg, nargs=0; p <= aend; ++argvp) 2212 2217 { 2218 char *next; 2219 2220 ++nargs; 2221 2222 if (nargs == entry_p->maximum_args 2223 || (! (next = find_next_argument (openparen, closeparen, p, aend)))) 2224 next = aend; 2225 2213 2226 *argvp = p; 2214 2227 *next = '\0'; 2228 p = next + 1; 2215 2229 } 2216 2217 p = next + 1;2218 2230 } 2219 2231 *argvp = NULL; … … 2226 2238 for (argvp=argv; *argvp != 0; ++argvp) 2227 2239 free (*argvp); 2228 else2229 free ( beg);2240 if (abeg) 2241 free (abeg); 2230 2242 2231 2243 return 1; … … 2269 2281 2270 2282 entry_p = lookup_function (fname); 2271 2272 2283 if (entry_p) 2273 2284 { 2274 2285 /* How many arguments do we have? */ 2275 2286 for (i=0; argv[i+1]; ++i) 2276 ; 2277 2287 ; 2278 2288 return expand_builtin_function (o, i, argv+1, entry_p); 2279 2289 } … … 2291 2301 return o; 2292 2302 2293 body = (char *)alloca (flen + 4);2303 body = alloca (flen + 4); 2294 2304 body[0] = '$'; 2295 2305 body[1] = '(';
Note:
See TracChangeset
for help on using the changeset viewer.