Changeset 503 for trunk/src/gmake/function.c
- Timestamp:
- Sep 15, 2006, 7:09:38 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/function.c
r344 r503 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" … … 501 500 } 502 501 502 static char * 503 func_flavor (char *o, char **argv, const char *funcname UNUSED) 504 { 505 register struct variable *v = lookup_variable (argv[0], strlen (argv[0])); 506 507 if (v == 0) 508 o = variable_buffer_output (o, "undefined", 9); 509 else 510 if (v->recursive) 511 o = variable_buffer_output (o, "recursive", 9); 512 else 513 o = variable_buffer_output (o, "simple", 6); 514 515 return o; 516 } 517 503 518 #ifdef VMS 504 519 # define IS_PATHSEP(c) ((c) == ']') … … 740 755 741 756 if (s <= end || end - beg < 0) 742 fatal ( reading_file, "%s: '%s'", message, beg);757 fatal (*expanding_var, "%s: '%s'", message, beg); 743 758 } 744 759 … … 757 772 758 773 if (i == 0) 759 fatal (reading_file, _("first argument to `word' function must be greater than 0")); 774 fatal (*expanding_var, 775 _("first argument to `word' function must be greater than 0")); 760 776 761 777 … … 784 800 start = atoi (argv[0]); 785 801 if (start < 1) 786 fatal ( reading_file,802 fatal (*expanding_var, 787 803 "invalid first argument to `wordlist' function: `%d'", start); 788 804 … … 1108 1124 case 'i': 1109 1125 printf ("%s\n", msg); 1126 fflush(stdout); 1110 1127 break; 1111 1128 1112 1129 default: 1113 fatal ( reading_file, "Internal error: func_error: '%s'", funcname);1130 fatal (*expanding_var, "Internal error: func_error: '%s'", funcname); 1114 1131 } 1115 1132 … … 1225 1242 } 1226 1243 1244 /* 1245 $(or condition1[,condition2[,condition3[...]]]) 1246 1247 A CONDITION is false iff it evaluates to an empty string. White 1248 space before and after CONDITION are stripped before evaluation. 1249 1250 CONDITION1 is evaluated. If it's true, then this is the result of 1251 expansion. If it's false, CONDITION2 is evaluated, and so on. If none of 1252 the conditions are true, the expansion is the empty string. 1253 1254 Once a CONDITION is true no further conditions are evaluated 1255 (short-circuiting). 1256 */ 1257 1258 static char * 1259 func_or (char *o, char **argv, const char *funcname UNUSED) 1260 { 1261 for ( ; *argv ; ++argv) 1262 { 1263 const char *begp = *argv; 1264 const char *endp = begp + strlen (*argv) - 1; 1265 char *expansion; 1266 int result = 0; 1267 1268 /* Find the result of the condition: if it's false keep going. */ 1269 1270 strip_whitespace (&begp, &endp); 1271 1272 if (begp > endp) 1273 continue; 1274 1275 expansion = expand_argument (begp, endp+1); 1276 result = strlen (expansion); 1277 1278 /* If the result is false keep going. */ 1279 if (!result) 1280 { 1281 free (expansion); 1282 continue; 1283 } 1284 1285 /* It's true! Keep this result and return. */ 1286 o = variable_buffer_output (o, expansion, result); 1287 free (expansion); 1288 break; 1289 } 1290 1291 return o; 1292 } 1293 1294 /* 1295 $(and condition1[,condition2[,condition3[...]]]) 1296 1297 A CONDITION is false iff it evaluates to an empty string. White 1298 space before and after CONDITION are stripped before evaluation. 1299 1300 CONDITION1 is evaluated. If it's false, then this is the result of 1301 expansion. If it's true, CONDITION2 is evaluated, and so on. If all of 1302 the conditions are true, the expansion is the result of the last condition. 1303 1304 Once a CONDITION is false no further conditions are evaluated 1305 (short-circuiting). 1306 */ 1307 1308 static char * 1309 func_and (char *o, char **argv, const char *funcname UNUSED) 1310 { 1311 char *expansion; 1312 int result; 1313 1314 while (1) 1315 { 1316 const char *begp = *argv; 1317 const char *endp = begp + strlen (*argv) - 1; 1318 1319 /* An empty condition is always false. */ 1320 strip_whitespace (&begp, &endp); 1321 if (begp > endp) 1322 return o; 1323 1324 expansion = expand_argument (begp, endp+1); 1325 result = strlen (expansion); 1326 1327 /* If the result is false, stop here: we're done. */ 1328 if (!result) 1329 break; 1330 1331 /* Otherwise the result is true. If this is the last one, keep this 1332 result and quit. Otherwise go on to the next one! */ 1333 1334 if (*(++argv)) 1335 free (expansion); 1336 else 1337 { 1338 o = variable_buffer_output (o, expansion, result); 1339 break; 1340 } 1341 } 1342 1343 free (expansion); 1344 1345 return o; 1346 } 1347 1227 1348 static char * 1228 1349 func_wildcard (char *o, char **argv, const char *funcname UNUSED) … … 1281 1402 \r is replaced on UNIX as well. Is this desirable? 1282 1403 */ 1283 void1284 fold_newlines (char *buffer, int *length)1404 static void 1405 fold_newlines (char *buffer, unsigned int *length) 1285 1406 { 1286 1407 char *dst = buffer; … … 1341 1462 TRUE, 1342 1463 DUPLICATE_SAME_ACCESS) == FALSE) { 1343 fatal (NILF, _("create_child_process: DuplicateHandle(In) failed (e=% d)\n"),1464 fatal (NILF, _("create_child_process: DuplicateHandle(In) failed (e=%ld)\n"), 1344 1465 GetLastError()); 1345 1466 … … 1352 1473 TRUE, 1353 1474 DUPLICATE_SAME_ACCESS) == FALSE) { 1354 fatal (NILF, _("create_child_process: DuplicateHandle(Err) failed (e=% d)\n"),1475 fatal (NILF, _("create_child_process: DuplicateHandle(Err) failed (e=%ld)\n"), 1355 1476 GetLastError()); 1356 1477 } 1357 1478 1358 1479 if (!CreatePipe(&hChildOutRd, &hChildOutWr, &saAttr, 0)) 1359 fatal (NILF, _("CreatePipe() failed (e=% d)\n"), GetLastError());1480 fatal (NILF, _("CreatePipe() failed (e=%ld)\n"), GetLastError()); 1360 1481 1361 1482 hProcess = process_init_fd(hIn, hChildOutWr, hErr); … … 1469 1590 { 1470 1591 char* batch_filename = NULL; 1471 unsigned int i;1472 1592 1473 1593 #ifdef __MSDOS__ … … 1494 1614 to put it in the environment. This is even more confusing when 1495 1615 var was not explicitly exported, but just appeared in the 1496 calling environment. */ 1616 calling environment. 1617 1618 envp = target_environment (NILF); 1619 */ 1497 1620 1498 1621 envp = environ; … … 1560 1683 { 1561 1684 /* We are the parent. */ 1562 1563 1685 char *buffer; 1564 unsigned int maxlen ;1686 unsigned int maxlen, i; 1565 1687 int cc; 1566 1688 … … 1625 1747 if (shell_function_completed == -1) 1626 1748 { 1627 /* This most likely means that the execvp failed, 1628 so we should just write out the error message 1629 that came in over the pipe from the child. */ 1749 /* This likely means that the execvp failed, so we should just 1750 write the error message in the pipe from the child. */ 1630 1751 fputs (buffer, stderr); 1631 1752 fflush (stderr); … … 1633 1754 else 1634 1755 { 1635 /* The child finished normally. Replace all 1636 newlines in its output with spaces, and put 1637 that in the variable output buffer. */ 1756 /* The child finished normally. Replace all newlines in its output 1757 with spaces, and put that in the variable output buffer. */ 1638 1758 fold_newlines (buffer, &i); 1639 1759 o = variable_buffer_output (o, buffer, i); … … 1667 1787 BPTR child_stdout; 1668 1788 char tmp_output[FILENAME_MAX]; 1669 unsigned int maxlen = 200 ;1670 int cc , i;1789 unsigned int maxlen = 200, i; 1790 int cc; 1671 1791 char * buffer, * ptr; 1672 1792 char ** aptr; … … 2011 2131 { STRING_SIZE_TUPLE("findstring"), 2, 2, 1, func_findstring}, 2012 2132 { STRING_SIZE_TUPLE("firstword"), 0, 1, 1, func_firstword}, 2133 { STRING_SIZE_TUPLE("flavor"), 0, 1, 1, func_flavor}, 2013 2134 { STRING_SIZE_TUPLE("join"), 2, 2, 1, func_join}, 2014 2135 { STRING_SIZE_TUPLE("lastword"), 0, 1, 1, func_lastword}, … … 2029 2150 { STRING_SIZE_TUPLE("warning"), 0, 1, 1, func_error}, 2030 2151 { STRING_SIZE_TUPLE("if"), 2, 3, 0, func_if}, 2152 { STRING_SIZE_TUPLE("or"), 1, 0, 0, func_or}, 2153 { STRING_SIZE_TUPLE("and"), 1, 0, 0, func_and}, 2031 2154 { STRING_SIZE_TUPLE("value"), 0, 1, 1, func_value}, 2032 2155 { STRING_SIZE_TUPLE("eval"), 0, 1, 1, func_eval}, … … 2052 2175 { 2053 2176 if (argc < (int)entry_p->minimum_args) 2054 fatal ( reading_file,2055 _(" Insufficient number of arguments (%d) to function `%s'"),2177 fatal (*expanding_var, 2178 _("insufficient number of arguments (%d) to function `%s'"), 2056 2179 argc, entry_p->name); 2057 2180 … … 2064 2187 2065 2188 if (!entry_p->func_ptr) 2066 fatal ( reading_file, _("Unimplemented on this platform: function `%s'"),2067 entry_p->name);2189 fatal (*expanding_var, 2190 _("unimplemented on this platform: function `%s'"), entry_p->name); 2068 2191 2069 2192 return entry_p->func_ptr (o, argv, entry_p->name); … … 2114 2237 2115 2238 if (count >= 0) 2116 fatal ( reading_file,2239 fatal (*expanding_var, 2117 2240 _("unterminated call to function `%s': missing `%c'"), 2118 2241 entry_p->name, closeparen);
Note:
See TracChangeset
for help on using the changeset viewer.