VirtualBox

Changeset 501 in kBuild for vendor/gnumake/current/function.c


Ignore:
Timestamp:
Sep 15, 2006 2:30:32 AM (18 years ago)
Author:
bird
Message:

Load make-3.81/ into vendor/gnumake/current.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/gnumake/current/function.c

    r280 r501  
    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"
     
    497496}
    498497
     498static char *
     499func_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
    499514#ifdef VMS
    500515# define IS_PATHSEP(c) ((c) == ']')
     
    736751
    737752  if (s <= end || end - beg < 0)
    738     fatal (reading_file, "%s: '%s'", message, beg);
     753    fatal (*expanding_var, "%s: '%s'", message, beg);
    739754}
    740755
     
    753768
    754769  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"));
    756772
    757773
     
    780796  start = atoi (argv[0]);
    781797  if (start < 1)
    782     fatal (reading_file,
     798    fatal (*expanding_var,
    783799           "invalid first argument to `wordlist' function: `%d'", start);
    784800
     
    11041120    case 'i':
    11051121      printf ("%s\n", msg);
     1122      fflush(stdout);
    11061123      break;
    11071124
    11081125    default:
    1109       fatal (reading_file, "Internal error: func_error: '%s'", funcname);
     1126      fatal (*expanding_var, "Internal error: func_error: '%s'", funcname);
    11101127  }
    11111128
     
    12211238}
    12221239
     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
     1254static char *
     1255func_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
     1304static char *
     1305func_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
    12231344static char *
    12241345func_wildcard (char *o, char **argv, const char *funcname UNUSED)
     
    12771398  \r  is replaced on UNIX as well. Is this desirable?
    12781399 */
    1279 void
    1280 fold_newlines (char *buffer, int *length)
     1400static void
     1401fold_newlines (char *buffer, unsigned int *length)
    12811402{
    12821403  char *dst = buffer;
     
    13371458                      TRUE,
    13381459                      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"),
    13401461           GetLastError());
    13411462
     
    13481469                      TRUE,
    13491470                      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"),
    13511472           GetLastError());
    13521473  }
    13531474
    13541475  if (!CreatePipe(&hChildOutRd, &hChildOutWr, &saAttr, 0))
    1355     fatal (NILF, _("CreatePipe() failed (e=%d)\n"), GetLastError());
     1476    fatal (NILF, _("CreatePipe() failed (e=%ld)\n"), GetLastError());
    13561477
    13571478  hProcess = process_init_fd(hIn, hChildOutWr, hErr);
     
    14651586{
    14661587  char* batch_filename = NULL;
    1467   unsigned int i;
    14681588
    14691589#ifdef __MSDOS__
     
    14901610     to put it in the environment.  This is even more confusing when
    14911611     var was not explicitly exported, but just appeared in the
    1492      calling environment.  */
     1612     calling environment.
     1613
     1614  envp = target_environment (NILF);
     1615  */
    14931616
    14941617  envp = environ;
     
    15561679    {
    15571680      /* We are the parent.  */
    1558 
    15591681      char *buffer;
    1560       unsigned int maxlen;
     1682      unsigned int maxlen, i;
    15611683      int cc;
    15621684
     
    16211743      if (shell_function_completed == -1)
    16221744        {
    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.  */
    16261747          fputs (buffer, stderr);
    16271748          fflush (stderr);
     
    16291750      else
    16301751        {
    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.  */
    16341754          fold_newlines (buffer, &i);
    16351755          o = variable_buffer_output (o, buffer, i);
     
    16631783  BPTR child_stdout;
    16641784  char tmp_output[FILENAME_MAX];
    1665   unsigned int maxlen = 200;
    1666   int cc, i;
     1785  unsigned int maxlen = 200, i;
     1786  int cc;
    16671787  char * buffer, * ptr;
    16681788  char ** aptr;
     
    19472067  { STRING_SIZE_TUPLE("findstring"),    2,  2,  1,  func_findstring},
    19482068  { STRING_SIZE_TUPLE("firstword"),     0,  1,  1,  func_firstword},
     2069  { STRING_SIZE_TUPLE("flavor"),        0,  1,  1,  func_flavor},
    19492070  { STRING_SIZE_TUPLE("join"),          2,  2,  1,  func_join},
    19502071  { STRING_SIZE_TUPLE("lastword"),      0,  1,  1,  func_lastword},
     
    19652086  { STRING_SIZE_TUPLE("warning"),       0,  1,  1,  func_error},
    19662087  { 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},
    19672090  { STRING_SIZE_TUPLE("value"),         0,  1,  1,  func_value},
    19682091  { STRING_SIZE_TUPLE("eval"),          0,  1,  1,  func_eval},
     
    19842107{
    19852108  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'"),
    19882111           argc, entry_p->name);
    19892112
     
    19962119
    19972120  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);
    20002123
    20012124  return entry_p->func_ptr (o, argv, entry_p->name);
     
    20462169
    20472170  if (count >= 0)
    2048     fatal (reading_file,
     2171    fatal (*expanding_var,
    20492172           _("unterminated call to function `%s': missing `%c'"),
    20502173           entry_p->name, closeparen);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette