Ignore:
Timestamp:
Sep 15, 2006, 7:09:38 AM (19 years ago)
Author:
bird
Message:

Untested merge with GNU Make v3.81 (vendor/gnumake/2005-05-16 -> vendor/gnumake/current).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmake/function.c

    r344 r503  
    11/* Builtin function expansion for GNU Make.
    2 Copyright (C) 1988, 1989, 1991-1997, 1999, 2002 Free Software Foundation, Inc.
     2Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
     31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
     4Foundation, Inc.
    35This file is part of GNU Make.
    46
    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.  */
     7GNU Make is free software; you can redistribute it and/or modify it under the
     8terms of the GNU General Public License as published by the Free Software
     9Foundation; either version 2, or (at your option) any later version.
     10
     11GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
     12WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     13A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     14
     15You should have received a copy of the GNU General Public License along with
     16GNU Make; see the file COPYING.  If not, write to the Free Software
     17Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.  */
    1918
    2019#include "make.h"
     
    501500}
    502501
     502static char *
     503func_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
    503518#ifdef VMS
    504519# define IS_PATHSEP(c) ((c) == ']')
     
    740755
    741756  if (s <= end || end - beg < 0)
    742     fatal (reading_file, "%s: '%s'", message, beg);
     757    fatal (*expanding_var, "%s: '%s'", message, beg);
    743758}
    744759
     
    757772
    758773  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"));
    760776
    761777
     
    784800  start = atoi (argv[0]);
    785801  if (start < 1)
    786     fatal (reading_file,
     802    fatal (*expanding_var,
    787803           "invalid first argument to `wordlist' function: `%d'", start);
    788804
     
    11081124    case 'i':
    11091125      printf ("%s\n", msg);
     1126      fflush(stdout);
    11101127      break;
    11111128
    11121129    default:
    1113       fatal (reading_file, "Internal error: func_error: '%s'", funcname);
     1130      fatal (*expanding_var, "Internal error: func_error: '%s'", funcname);
    11141131  }
    11151132
     
    12251242}
    12261243
     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
     1258static char *
     1259func_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
     1308static char *
     1309func_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
    12271348static char *
    12281349func_wildcard (char *o, char **argv, const char *funcname UNUSED)
     
    12811402  \r  is replaced on UNIX as well. Is this desirable?
    12821403 */
    1283 void
    1284 fold_newlines (char *buffer, int *length)
     1404static void
     1405fold_newlines (char *buffer, unsigned int *length)
    12851406{
    12861407  char *dst = buffer;
     
    13411462                      TRUE,
    13421463                      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"),
    13441465           GetLastError());
    13451466
     
    13521473                      TRUE,
    13531474                      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"),
    13551476           GetLastError());
    13561477  }
    13571478
    13581479  if (!CreatePipe(&hChildOutRd, &hChildOutWr, &saAttr, 0))
    1359     fatal (NILF, _("CreatePipe() failed (e=%d)\n"), GetLastError());
     1480    fatal (NILF, _("CreatePipe() failed (e=%ld)\n"), GetLastError());
    13601481
    13611482  hProcess = process_init_fd(hIn, hChildOutWr, hErr);
     
    14691590{
    14701591  char* batch_filename = NULL;
    1471   unsigned int i;
    14721592
    14731593#ifdef __MSDOS__
     
    14941614     to put it in the environment.  This is even more confusing when
    14951615     var was not explicitly exported, but just appeared in the
    1496      calling environment.  */
     1616     calling environment.
     1617
     1618  envp = target_environment (NILF);
     1619  */
    14971620
    14981621  envp = environ;
     
    15601683    {
    15611684      /* We are the parent.  */
    1562 
    15631685      char *buffer;
    1564       unsigned int maxlen;
     1686      unsigned int maxlen, i;
    15651687      int cc;
    15661688
     
    16251747      if (shell_function_completed == -1)
    16261748        {
    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.  */
    16301751          fputs (buffer, stderr);
    16311752          fflush (stderr);
     
    16331754      else
    16341755        {
    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.  */
    16381758          fold_newlines (buffer, &i);
    16391759          o = variable_buffer_output (o, buffer, i);
     
    16671787  BPTR child_stdout;
    16681788  char tmp_output[FILENAME_MAX];
    1669   unsigned int maxlen = 200;
    1670   int cc, i;
     1789  unsigned int maxlen = 200, i;
     1790  int cc;
    16711791  char * buffer, * ptr;
    16721792  char ** aptr;
     
    20112131  { STRING_SIZE_TUPLE("findstring"),    2,  2,  1,  func_findstring},
    20122132  { STRING_SIZE_TUPLE("firstword"),     0,  1,  1,  func_firstword},
     2133  { STRING_SIZE_TUPLE("flavor"),        0,  1,  1,  func_flavor},
    20132134  { STRING_SIZE_TUPLE("join"),          2,  2,  1,  func_join},
    20142135  { STRING_SIZE_TUPLE("lastword"),      0,  1,  1,  func_lastword},
     
    20292150  { STRING_SIZE_TUPLE("warning"),       0,  1,  1,  func_error},
    20302151  { 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},
    20312154  { STRING_SIZE_TUPLE("value"),         0,  1,  1,  func_value},
    20322155  { STRING_SIZE_TUPLE("eval"),          0,  1,  1,  func_eval},
     
    20522175{
    20532176  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'"),
    20562179           argc, entry_p->name);
    20572180
     
    20642187
    20652188  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);
    20682191
    20692192  return entry_p->func_ptr (o, argv, entry_p->name);
     
    21142237
    21152238  if (count >= 0)
    2116     fatal (reading_file,
     2239    fatal (*expanding_var,
    21172240           _("unterminated call to function `%s': missing `%c'"),
    21182241           entry_p->name, closeparen);
Note: See TracChangeset for help on using the changeset viewer.