Changeset 501 in kBuild for vendor/gnumake/current/function.c
- Timestamp:
- Sep 15, 2006 2:30:32 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/function.c
r280 r501 1 1 /* Builtin function expansion for GNU Make. 2 Copyright (C) 1988, 1989, 1991-1997, 1999, 2002 Free Software Foundation, Inc. 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software 4 Foundation, Inc. 3 5 This file is part of GNU Make. 4 6 5 GNU Make is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2, or (at your option) 8 any later version. 9 10 GNU Make is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with GNU Make; see the file COPYING. If not, write to 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 Boston, MA 02111-1307, USA. */ 7 GNU Make is free software; you can redistribute it and/or modify it under the 8 terms of the GNU General Public License as published by the Free Software 9 Foundation; either version 2, or (at your option) any later version. 10 11 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY 12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 13 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License along with 16 GNU Make; see the file COPYING. If not, write to the Free Software 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ 19 18 20 19 #include "make.h" … … 497 496 } 498 497 498 static char * 499 func_flavor (char *o, char **argv, const char *funcname UNUSED) 500 { 501 register struct variable *v = lookup_variable (argv[0], strlen (argv[0])); 502 503 if (v == 0) 504 o = variable_buffer_output (o, "undefined", 9); 505 else 506 if (v->recursive) 507 o = variable_buffer_output (o, "recursive", 9); 508 else 509 o = variable_buffer_output (o, "simple", 6); 510 511 return o; 512 } 513 499 514 #ifdef VMS 500 515 # define IS_PATHSEP(c) ((c) == ']') … … 736 751 737 752 if (s <= end || end - beg < 0) 738 fatal ( reading_file, "%s: '%s'", message, beg);753 fatal (*expanding_var, "%s: '%s'", message, beg); 739 754 } 740 755 … … 753 768 754 769 if (i == 0) 755 fatal (reading_file, _("first argument to `word' function must be greater than 0")); 770 fatal (*expanding_var, 771 _("first argument to `word' function must be greater than 0")); 756 772 757 773 … … 780 796 start = atoi (argv[0]); 781 797 if (start < 1) 782 fatal ( reading_file,798 fatal (*expanding_var, 783 799 "invalid first argument to `wordlist' function: `%d'", start); 784 800 … … 1104 1120 case 'i': 1105 1121 printf ("%s\n", msg); 1122 fflush(stdout); 1106 1123 break; 1107 1124 1108 1125 default: 1109 fatal ( reading_file, "Internal error: func_error: '%s'", funcname);1126 fatal (*expanding_var, "Internal error: func_error: '%s'", funcname); 1110 1127 } 1111 1128 … … 1221 1238 } 1222 1239 1240 /* 1241 $(or condition1[,condition2[,condition3[...]]]) 1242 1243 A CONDITION is false iff it evaluates to an empty string. White 1244 space before and after CONDITION are stripped before evaluation. 1245 1246 CONDITION1 is evaluated. If it's true, then this is the result of 1247 expansion. If it's false, CONDITION2 is evaluated, and so on. If none of 1248 the conditions are true, the expansion is the empty string. 1249 1250 Once a CONDITION is true no further conditions are evaluated 1251 (short-circuiting). 1252 */ 1253 1254 static char * 1255 func_or (char *o, char **argv, const char *funcname UNUSED) 1256 { 1257 for ( ; *argv ; ++argv) 1258 { 1259 const char *begp = *argv; 1260 const char *endp = begp + strlen (*argv) - 1; 1261 char *expansion; 1262 int result = 0; 1263 1264 /* Find the result of the condition: if it's false keep going. */ 1265 1266 strip_whitespace (&begp, &endp); 1267 1268 if (begp > endp) 1269 continue; 1270 1271 expansion = expand_argument (begp, endp+1); 1272 result = strlen (expansion); 1273 1274 /* If the result is false keep going. */ 1275 if (!result) 1276 { 1277 free (expansion); 1278 continue; 1279 } 1280 1281 /* It's true! Keep this result and return. */ 1282 o = variable_buffer_output (o, expansion, result); 1283 free (expansion); 1284 break; 1285 } 1286 1287 return o; 1288 } 1289 1290 /* 1291 $(and condition1[,condition2[,condition3[...]]]) 1292 1293 A CONDITION is false iff it evaluates to an empty string. White 1294 space before and after CONDITION are stripped before evaluation. 1295 1296 CONDITION1 is evaluated. If it's false, then this is the result of 1297 expansion. If it's true, CONDITION2 is evaluated, and so on. If all of 1298 the conditions are true, the expansion is the result of the last condition. 1299 1300 Once a CONDITION is false no further conditions are evaluated 1301 (short-circuiting). 1302 */ 1303 1304 static char * 1305 func_and (char *o, char **argv, const char *funcname UNUSED) 1306 { 1307 char *expansion; 1308 int result; 1309 1310 while (1) 1311 { 1312 const char *begp = *argv; 1313 const char *endp = begp + strlen (*argv) - 1; 1314 1315 /* An empty condition is always false. */ 1316 strip_whitespace (&begp, &endp); 1317 if (begp > endp) 1318 return o; 1319 1320 expansion = expand_argument (begp, endp+1); 1321 result = strlen (expansion); 1322 1323 /* If the result is false, stop here: we're done. */ 1324 if (!result) 1325 break; 1326 1327 /* Otherwise the result is true. If this is the last one, keep this 1328 result and quit. Otherwise go on to the next one! */ 1329 1330 if (*(++argv)) 1331 free (expansion); 1332 else 1333 { 1334 o = variable_buffer_output (o, expansion, result); 1335 break; 1336 } 1337 } 1338 1339 free (expansion); 1340 1341 return o; 1342 } 1343 1223 1344 static char * 1224 1345 func_wildcard (char *o, char **argv, const char *funcname UNUSED) … … 1277 1398 \r is replaced on UNIX as well. Is this desirable? 1278 1399 */ 1279 void1280 fold_newlines (char *buffer, int *length)1400 static void 1401 fold_newlines (char *buffer, unsigned int *length) 1281 1402 { 1282 1403 char *dst = buffer; … … 1337 1458 TRUE, 1338 1459 DUPLICATE_SAME_ACCESS) == FALSE) { 1339 fatal (NILF, _("create_child_process: DuplicateHandle(In) failed (e=% d)\n"),1460 fatal (NILF, _("create_child_process: DuplicateHandle(In) failed (e=%ld)\n"), 1340 1461 GetLastError()); 1341 1462 … … 1348 1469 TRUE, 1349 1470 DUPLICATE_SAME_ACCESS) == FALSE) { 1350 fatal (NILF, _("create_child_process: DuplicateHandle(Err) failed (e=% d)\n"),1471 fatal (NILF, _("create_child_process: DuplicateHandle(Err) failed (e=%ld)\n"), 1351 1472 GetLastError()); 1352 1473 } 1353 1474 1354 1475 if (!CreatePipe(&hChildOutRd, &hChildOutWr, &saAttr, 0)) 1355 fatal (NILF, _("CreatePipe() failed (e=% d)\n"), GetLastError());1476 fatal (NILF, _("CreatePipe() failed (e=%ld)\n"), GetLastError()); 1356 1477 1357 1478 hProcess = process_init_fd(hIn, hChildOutWr, hErr); … … 1465 1586 { 1466 1587 char* batch_filename = NULL; 1467 unsigned int i;1468 1588 1469 1589 #ifdef __MSDOS__ … … 1490 1610 to put it in the environment. This is even more confusing when 1491 1611 var was not explicitly exported, but just appeared in the 1492 calling environment. */ 1612 calling environment. 1613 1614 envp = target_environment (NILF); 1615 */ 1493 1616 1494 1617 envp = environ; … … 1556 1679 { 1557 1680 /* We are the parent. */ 1558 1559 1681 char *buffer; 1560 unsigned int maxlen ;1682 unsigned int maxlen, i; 1561 1683 int cc; 1562 1684 … … 1621 1743 if (shell_function_completed == -1) 1622 1744 { 1623 /* This most likely means that the execvp failed, 1624 so we should just write out the error message 1625 that came in over the pipe from the child. */ 1745 /* This likely means that the execvp failed, so we should just 1746 write the error message in the pipe from the child. */ 1626 1747 fputs (buffer, stderr); 1627 1748 fflush (stderr); … … 1629 1750 else 1630 1751 { 1631 /* The child finished normally. Replace all 1632 newlines in its output with spaces, and put 1633 that in the variable output buffer. */ 1752 /* The child finished normally. Replace all newlines in its output 1753 with spaces, and put that in the variable output buffer. */ 1634 1754 fold_newlines (buffer, &i); 1635 1755 o = variable_buffer_output (o, buffer, i); … … 1663 1783 BPTR child_stdout; 1664 1784 char tmp_output[FILENAME_MAX]; 1665 unsigned int maxlen = 200 ;1666 int cc , i;1785 unsigned int maxlen = 200, i; 1786 int cc; 1667 1787 char * buffer, * ptr; 1668 1788 char ** aptr; … … 1947 2067 { STRING_SIZE_TUPLE("findstring"), 2, 2, 1, func_findstring}, 1948 2068 { STRING_SIZE_TUPLE("firstword"), 0, 1, 1, func_firstword}, 2069 { STRING_SIZE_TUPLE("flavor"), 0, 1, 1, func_flavor}, 1949 2070 { STRING_SIZE_TUPLE("join"), 2, 2, 1, func_join}, 1950 2071 { STRING_SIZE_TUPLE("lastword"), 0, 1, 1, func_lastword}, … … 1965 2086 { STRING_SIZE_TUPLE("warning"), 0, 1, 1, func_error}, 1966 2087 { STRING_SIZE_TUPLE("if"), 2, 3, 0, func_if}, 2088 { STRING_SIZE_TUPLE("or"), 1, 0, 0, func_or}, 2089 { STRING_SIZE_TUPLE("and"), 1, 0, 0, func_and}, 1967 2090 { STRING_SIZE_TUPLE("value"), 0, 1, 1, func_value}, 1968 2091 { STRING_SIZE_TUPLE("eval"), 0, 1, 1, func_eval}, … … 1984 2107 { 1985 2108 if (argc < (int)entry_p->minimum_args) 1986 fatal ( reading_file,1987 _(" Insufficient number of arguments (%d) to function `%s'"),2109 fatal (*expanding_var, 2110 _("insufficient number of arguments (%d) to function `%s'"), 1988 2111 argc, entry_p->name); 1989 2112 … … 1996 2119 1997 2120 if (!entry_p->func_ptr) 1998 fatal ( reading_file, _("Unimplemented on this platform: function `%s'"),1999 entry_p->name);2121 fatal (*expanding_var, 2122 _("unimplemented on this platform: function `%s'"), entry_p->name); 2000 2123 2001 2124 return entry_p->func_ptr (o, argv, entry_p->name); … … 2046 2169 2047 2170 if (count >= 0) 2048 fatal ( reading_file,2171 fatal (*expanding_var, 2049 2172 _("unterminated call to function `%s': missing `%c'"), 2050 2173 entry_p->name, closeparen);
Note:
See TracChangeset
for help on using the changeset viewer.