VirtualBox

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


Ignore:
Timestamp:
May 23, 2007 3:13:11 AM (18 years ago)
Author:
bird
Message:

Load /home/bird/src/Gnu/make/2007-05-23 into vendor/gnumake/current.

File:
1 edited

Legend:

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

    r501 r900  
    3737    unsigned char maximum_args;
    3838    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);
    4040  };
    4141
     
    4343function_table_entry_hash_1 (const void *keyv)
    4444{
    45   struct function_table_entry const *key = (struct function_table_entry const *) keyv;
     45  const struct function_table_entry *key = keyv;
    4646  return_STRING_N_HASH_1 (key->name, key->len);
    4747}
     
    5050function_table_entry_hash_2 (const void *keyv)
    5151{
    52   struct function_table_entry const *key = (struct function_table_entry const *) keyv;
     52  const struct function_table_entry *key = keyv;
    5353  return_STRING_N_HASH_2 (key->name, key->len);
    5454}
     
    5757function_table_entry_hash_cmp (const void *xv, const void *yv)
    5858{
    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;
    6161  int result = x->len - y->len;
    6262  if (result)
     
    7676
    7777char *
    78 subst_expand (char *o, char *text, char *subst, char *replace,
     78subst_expand (char *o, const char *text, const char *subst, const char *replace,
    7979              unsigned int slen, unsigned int rlen, int by_word)
    8080{
    81   char *t = text;
    82   char *p;
     81  const char *t = text;
     82  const char *p;
    8383
    8484  if (slen == 0 && !by_word)
     
    125125
    126126      /* Advance T past the string to be replaced.  */
    127       {
    128         char *nt = p + slen;
    129         t = nt;
    130       }
     127      t = p + slen;
    131128    } while (*t != '\0');
    132129
     
    147144
    148145char *
    149 patsubst_expand (char *o, char *text, char *pattern, char *replace,
    150                  char *pattern_percent, char *replace_percent)
     146patsubst_expand_pat (char *o, const char *text,
     147                     const char *pattern, const char *replace,
     148                     const char *pattern_percent, const char *replace_percent)
    151149{
    152150  unsigned int pattern_prepercent_len, pattern_postpercent_len;
    153151  unsigned int replace_prepercent_len, replace_postpercent_len;
    154   char *t;
     152  const char *t;
    155153  unsigned int len;
    156154  int doneany = 0;
    157 
    158   /* We call find_percent on REPLACE before checking PATTERN so that REPLACE
    159      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     }
    166155
    167156  /* Record the length of REPLACE before and after the % so we don't have to
     
    178167    }
    179168
    180   if (!pattern_percent)
    181     {
    182       pattern_percent = find_percent (pattern);
    183       if (pattern_percent)
    184         ++pattern_percent;
    185     }
    186169  if (!pattern_percent)
    187170    /* With no % in the pattern, this is just a simple substitution.  */
     
    255238}
    256239
     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
     250char *
     251patsubst_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
    257266
    258267
     
    282291
    283292int
    284 pattern_matches (char *pattern, char *percent, char *str)
     293pattern_matches (const char *pattern, const char *percent, const char *str)
    285294{
    286295  unsigned int sfxlen, strlength;
     
    289298    {
    290299      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);
    293305      pattern = new_chars;
    294       percent = find_percent (pattern);
    295       if (percent == 0)
    296         return streq (pattern, str);
    297306    }
    298307
     
    350359  static char *result = 0;
    351360  static unsigned int length;
    352   register struct nameseq *chain;
    353   register unsigned int idx;
     361  struct nameseq *chain;
     362  unsigned int idx;
    354363
    355364  chain = multi_glob (parse_file_seq
     
    364373    {
    365374      length = 100;
    366       result = (char *) xmalloc (100);
     375      result = xmalloc (100);
    367376    }
    368377
     
    370379  while (chain != 0)
    371380    {
    372       register char *name = chain->name;
     381      const char *name = chain->name;
    373382      unsigned int len = strlen (name);
    374383
    375384      struct nameseq *next = chain->next;
    376       free ((char *) chain);
     385      free (chain);
    377386      chain = next;
    378387
     
    384393            {
    385394              length += (len + 1) * 2;
    386               result = (char *) xrealloc (result, length);
     395              result = xrealloc (result, length);
    387396            }
    388           bcopy (name, &result[idx], len);
     397          memcpy (&result[idx], name, len);
    389398          idx += len;
    390399          result[idx++] = ' ';
    391400        }
    392 
    393       free (name);
    394401    }
    395402
     
    411418func_patsubst (char *o, char **argv, const char *funcname UNUSED)
    412419{
    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]);
    414421  return o;
    415422}
     
    425432     If the two arguments have a different number of words,
    426433     the excess words are just output separated by blanks.  */
    427   register char *tp;
    428   register char *pp;
    429   char *list1_iterator = argv[0];
    430   char *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];
    431438  do
    432439    {
     
    460467{
    461468  /* Expand the argument.  */
    462   register struct variable *v = lookup_variable (argv[0], strlen (argv[0]));
     469  struct variable *v = lookup_variable (argv[0], strlen (argv[0]));
    463470  if (v == 0)
    464471    o = variable_buffer_output (o, "undefined", 9);
     
    499506func_flavor (char *o, char **argv, const char *funcname UNUSED)
    500507{
    501   register struct variable *v = lookup_variable (argv[0], strlen (argv[0]));
     508  struct variable *v = lookup_variable (argv[0], strlen (argv[0]));
    502509
    503510  if (v == 0)
     
    527534{
    528535  /* Expand the argument.  */
    529   char *list_iterator = argv[0];
    530   char *p2 =0;
     536  const char *list_iterator = argv[0];
     537  const char *p2;
    531538  int doneany =0;
    532539  unsigned int len=0;
     
    536543  while ((p2 = find_next_token (&list_iterator, &len)) != 0)
    537544    {
    538       char *p = p2 + len;
     545      const char *p = p2 + len;
    539546
    540547
     
    571578        }
    572579    }
     580
    573581  if (doneany)
    574582    /* Kill last space.  */
    575583    --o;
    576584
    577 
    578   return o;
    579 
     585  return o;
    580586}
    581587
     
    585591{
    586592  /* Expand the argument.  */
    587   char *p3 = argv[0];
    588   char *p2=0;
     593  const char *p3 = argv[0];
     594  const char *p2;
    589595  int doneany=0;
    590596  unsigned int len=0;
    591   char *p=0;
     597
    592598  int is_basename= streq (funcname, "basename");
    593599  int is_dir= !is_basename;
    594600
    595601  while ((p2 = find_next_token (&p3, &len)) != 0)
    596         {
    597           p = p2 + len;
    598           while (p >= p2 && (!is_basename  || *p != '.'))
    599             {
    600               if (IS_PATHSEP (*p))
    601                 break;
    602                     --p;
    603             }
    604 
    605           if (p >= p2 && (is_dir))
    606             o = variable_buffer_output (o, p2, ++p - p2);
    607           else if (p >= p2 && (*p == '.'))
    608             o = variable_buffer_output (o, p2, p - p2);
     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);
    609615#ifdef HAVE_DOS_PATHS
    610         /* Handle the "d:foobar" case */
    611           else if (p2[0] && p2[1] == ':' && is_dir)
    612             o = variable_buffer_output (o, p2, 2);
     616      /* Handle the "d:foobar" case */
     617      else if (p2[0] && p2[1] == ':' && is_dir)
     618        o = variable_buffer_output (o, p2, 2);
    613619#endif
    614           else if (is_dir)
     620      else if (is_dir)
    615621#ifdef VMS
    616             o = variable_buffer_output (o, "[]", 2);
     622        o = variable_buffer_output (o, "[]", 2);
    617623#else
    618624#ifndef _AMIGA
    619             o = variable_buffer_output (o, "./", 2);
     625      o = variable_buffer_output (o, "./", 2);
    620626#else
    621             ; /* Just a nop...  */
     627      ; /* Just a nop...  */
    622628#endif /* AMIGA */
    623629#endif /* !VMS */
    624           else
    625             /* The entire name is the basename.  */
    626             o = variable_buffer_output (o, p2, len);
    627 
    628           o = variable_buffer_output (o, " ", 1);
    629           doneany = 1;
    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;
    637643}
    638644
     
    641647{
    642648  int fixlen = strlen (argv[0]);
    643   char *list_iterator = argv[1];
     649  const char *list_iterator = argv[1];
    644650  int is_addprefix = streq (funcname, "addprefix");
    645651  int is_addsuffix = !is_addprefix;
    646652
    647653  int doneany = 0;
    648   char *p;
     654  const char *p;
    649655  unsigned int len;
    650656
     
    681687{
    682688  unsigned int i;
    683   char *words = argv[0];    /* Use a temp variable for find_next_token */
    684   char *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);
    685691
    686692  if (p != 0)
     
    694700{
    695701  unsigned int i;
    696   char *words = argv[0];    /* Use a temp variable for find_next_token */
    697   char *p = 0;
    698   char *t;
     702  const char *words = argv[0];    /* Use a temp variable for find_next_token */
     703  const char *p = NULL;
     704  const char *t;
    699705
    700706  while ((t = find_next_token (&words, &i)))
     
    711717{
    712718  int i = 0;
    713   char *word_iterator = argv[0];
     719  const char *word_iterator = argv[0];
    714720  char buf[20];
    715721
     
    719725  sprintf (buf, "%d", i);
    720726  o = variable_buffer_output (o, buf, strlen (buf));
    721 
    722727
    723728  return o;
     
    740745
    741746static void
    742 check_numeric (const char *s, const char *message)
     747check_numeric (const char *s, const char *msg)
    743748{
    744749  const char *end = s + strlen (s) - 1;
     
    751756
    752757  if (s <= end || end - beg < 0)
    753     fatal (*expanding_var, "%s: '%s'", message, beg);
     758    fatal (*expanding_var, "%s: '%s'", msg, beg);
    754759}
    755760
     
    759764func_word (char *o, char **argv, const char *funcname UNUSED)
    760765{
    761   char *end_p=0;
    762   int i=0;
    763   char *p=0;
     766  const char *end_p;
     767  const char *p;
     768  int i;
    764769
    765770  /* Check the first argument.  */
    766771  check_numeric (argv[0], _("non-numeric first argument to `word' function"));
    767   i =  atoi (argv[0]);
     772  i = atoi (argv[0]);
    768773
    769774  if (i == 0)
    770775    fatal (*expanding_var,
    771776           _("first argument to `word' function must be greater than 0"));
    772 
    773777
    774778  end_p = argv[1];
     
    803807  if (count > 0)
    804808    {
    805       char *p;
    806       char *end_p = argv[2];
     809      const char *p;
     810      const char *end_p = argv[2];
    807811
    808812      /* Find the beginning of the "start"th word.  */
     
    824828}
    825829
    826 static char*
     830static char *
    827831func_findstring (char *o, char **argv, const char *funcname UNUSED)
    828832{
     
    840844  char *varname = expand_argument (argv[0], NULL);
    841845  char *list = expand_argument (argv[1], NULL);
    842   char *body = argv[2];
     846  const char *body = argv[2];
    843847
    844848  int doneany = 0;
    845   char *list_iterator = list;
    846   char *p;
     849  const char *list_iterator = list;
     850  const char *p;
    847851  unsigned int len;
    848   register struct variable *var;
     852  struct variable *var;
    849853
    850854  push_new_variable_scope ();
     
    856860      char *result = 0;
    857861
    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);
    866864
    867865      result = allocated_variable_expand (body);
     
    936934  struct hash_table a_word_table;
    937935  int is_filter = streq (funcname, "filter");
    938   char *pat_iterator = argv[0];
    939   char *word_iterator = argv[1];
     936  const char *pat_iterator = argv[0];
     937  const char *word_iterator = argv[1];
    940938  int literals = 0;
    941939  int words = 0;
     
    949947  while ((p = find_next_token (&pat_iterator, &len)) != 0)
    950948    {
    951       struct a_pattern *pat = (struct a_pattern *) alloca (sizeof (struct a_pattern));
     949      struct a_pattern *pat = alloca (sizeof (struct a_pattern));
    952950
    953951      *pattail = pat;
     
    972970  while ((p = find_next_token (&word_iterator, &len)) != 0)
    973971    {
    974       struct a_word *word = (struct a_word *) alloca (sizeof (struct a_word));
     972      struct a_word *word = alloca (sizeof (struct a_word));
    975973
    976974      *wordtail = word;
     
    993991  if (hashing)
    994992    {
    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);
    996995      for (wp = wordhead; wp != 0; wp = wp->next)
    997996        {
     
    10171016              a_word_key.str = pp->str;
    10181017              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);
    10201019              while (wp)
    10211020                {
     
    10571056func_strip (char *o, char **argv, const char *funcname UNUSED)
    10581057{
    1059   char *p = argv[0];
    1060   int doneany =0;
     1058  const char *p = argv[0];
     1059  int doneany = 0;
    10611060
    10621061  while (*p != '\0')
    10631062    {
    10641063      int i=0;
    1065       char *word_start=0;
     1064      const char *word_start;
    10661065
    10671066      while (isspace ((unsigned char)*p))
     
    10801079    /* Kill the last space.  */
    10811080    --o;
     1081
    10821082  return o;
    10831083}
     
    10991099    len += strlen (*argvp) + 2;
    11001100
    1101   p = msg = (char *) alloca (len + 1);
     1101  p = msg = alloca (len + 1);
    11021102
    11031103  for (argvp=argv; argvp[1] != 0; ++argvp)
     
    11381138func_sort (char *o, char **argv, const char *funcname UNUSED)
    11391139{
    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;
    11461143  char *p;
    11471144  unsigned int len;
    11481145  int i;
    11491146
     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;
    11501168  while ((p = find_next_token (&t, &len)) != 0)
    11511169    {
    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)
    11731182        {
    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            }
    11761190        }
    1177       free (words[i]);
    1178     }
    1179   /* Kill the last space.  */
    1180   --o;
     1191
     1192      /* Kill the last space.  */
     1193      --o;
     1194    }
    11811195
    11821196  free (words);
     
    12241238  argv += 1 + !result;
    12251239
    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);
    12311243
    12321244      o = variable_buffer_output (o, expansion, strlen (expansion));
     
    13451357func_wildcard (char *o, char **argv, const char *funcname UNUSED)
    13461358{
    1347 
    13481359#ifdef _AMIGA
    13491360   o = wildcard_expansion (argv[0], o);
     
    15851596func_shell (char *o, char **argv, const char *funcname UNUSED)
    15861597{
    1587   char* batch_filename = NULL;
     1598  char *batch_filename = NULL;
    15881599
    15891600#ifdef __MSDOS__
     
    15911602#endif
    15921603  char **command_argv;
    1593   char *error_prefix;
     1604  const char *error_prefix;
    15941605  char **envp;
    15951606  int pipedes[2];
     
    15981609#ifndef __MSDOS__
    15991610  /* 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);
    16031612  if (command_argv == 0)
    16041613    return o;
     
    16121621     calling environment.
    16131622
     1623     See Savannah bug #10593.
     1624
    16141625  envp = target_environment (NILF);
    16151626  */
     
    16201631  if (reading_file && reading_file->filenm)
    16211632    {
    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;
    16251636    }
    16261637  else
    16271638    error_prefix = "";
    16281639
    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__)
    16421641  fpipe = msdos_openpipe (pipedes, &pid, argv[0]);
    16431642  if (pipedes[0] < 0)
     
    16461645      return o;
    16471646    }
    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
    16491657#else
    1650 
    16511658  if (pipe (pipedes) < 0)
    16521659    {
     
    16561663
    16571664# ifdef __EMX__
    1658 
    16591665  /* close some handles that are unnecessary for the child process */
    16601666  CLOSE_ON_EXEC(pipedes[1]);
     
    16641670  if (pid < 0)
    16651671    perror_with_name (error_prefix, "spawn");
    1666 
    16671672# else /* ! __EMX__ */
    1668 
    16691673  pid = vfork ();
    16701674  if (pid < 0)
     
    16731677    child_execute_job (0, pipedes[1], command_argv, envp);
    16741678  else
    1675 
    16761679# endif
    1677 
    16781680#endif
    16791681    {
     
    16901692      /* Free the storage only the child needed.  */
    16911693      free (command_argv[0]);
    1692       free ((char *) command_argv);
     1694      free (command_argv);
    16931695
    16941696      /* Close the write side of the pipe.  */
    1695       (void) close (pipedes[1]);
     1697      close (pipedes[1]);
    16961698#endif
    16971699
     
    16991701
    17001702      maxlen = 200;
    1701       buffer = (char *) xmalloc (maxlen + 1);
     1703      buffer = xmalloc (maxlen + 1);
    17021704
    17031705      /* Read from the pipe until it gets EOF.  */
     
    17071709            {
    17081710              maxlen += 512;
    1709               buffer = (char *) xrealloc (buffer, maxlen + 1);
     1711              buffer = xrealloc (buffer, maxlen + 1);
    17101712            }
    17111713
     
    18341836        {
    18351837          maxlen += 512;
    1836           buffer = (char *) xrealloc (buffer, maxlen + 1);
     1838          buffer = xrealloc (buffer, maxlen + 1);
    18371839        }
    18381840
     
    18721874func_not (char *o, char **argv, char *funcname)
    18731875{
    1874   char *s = argv[0];
     1876  const char *s = argv[0];
    18751877  int result = 0;
    18761878  while (isspace ((unsigned char)*s))
     
    19661968{
    19671969  /* Expand the argument.  */
    1968   char *p = argv[0];
    1969   char *path = 0;
     1970  const char *p = argv[0];
     1971  const char *path = 0;
    19701972  int doneany = 0;
    19711973  unsigned int len = 0;
     
    19801982          in[len] = '\0';
    19811983
    1982           if
    1983           (
     1984          if (
    19841985#ifdef HAVE_REALPATH
    1985             realpath (in, out)
     1986              realpath (in, out)
    19861987#else
    1987             abspath (in, out)
     1988              abspath (in, out)
    19881989#endif
    1989           )
     1990             )
    19901991            {
    19911992              o = variable_buffer_output (o, out, strlen (out));
     
    20002001    --o;
    20012002
    2002  return o;
     2003  return o;
    20032004}
    20042005
     
    20072008{
    20082009  /* Expand the argument.  */
    2009   char *p = argv[0];
    2010   char *path = 0;
     2010  const char *p = argv[0];
     2011  const char *path = 0;
    20112012  int doneany = 0;
    20122013  unsigned int len = 0;
     
    20342035    --o;
    20352036
    2036  return o;
     2037  return o;
    20372038}
    20382039
     
    20492050   Functions that do namespace tricks (foreach) don't automatically expand.  */
    20502051
    2051 static char *func_call PARAMS ((char *o, char **argv, const char *funcname));
     2052static char *func_call (char *o, char **argv, const char *funcname);
    20522053
    20532054
     
    21312132
    21322133int
    2133 handle_function (char **op, char **stringp)
     2134handle_function (char **op, const char **stringp)
    21342135{
    21352136  const struct function_table_entry *entry_p;
    21362137  char openparen = (*stringp)[0];
    21372138  char closeparen = openparen == '(' ? ')' : '}';
    2138   char *beg;
    2139   char *end;
     2139  const char *beg;
     2140  const char *end;
    21402141  int count = 0;
    2141   register char *p;
     2142  char *abeg = NULL;
    21422143  char **argv, **argvp;
    21432144  int nargs;
     
    21762177
    21772178  /* 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));
    21792180
    21802181  /* Chop the string into arguments, then a nul.  As soon as we hit
     
    21862187     each argument.  */
    21872188
    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
    21892207    {
    21902208      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)
    22122217        {
     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
    22132226          *argvp = p;
    22142227          *next = '\0';
     2228          p = next + 1;
    22152229        }
    2216 
    2217       p = next + 1;
    22182230    }
    22192231  *argvp = NULL;
     
    22262238    for (argvp=argv; *argvp != 0; ++argvp)
    22272239      free (*argvp);
    2228   else
    2229     free (beg);
     2240  if (abeg)
     2241    free (abeg);
    22302242
    22312243  return 1;
     
    22692281
    22702282  entry_p = lookup_function (fname);
    2271 
    22722283  if (entry_p)
    22732284    {
    22742285      /* How many arguments do we have?  */
    22752286      for (i=0; argv[i+1]; ++i)
    2276         ;
    2277 
     2287        ;
    22782288      return expand_builtin_function (o, i, argv+1, entry_p);
    22792289    }
     
    22912301    return o;
    22922302
    2293   body = (char *) alloca (flen + 4);
     2303  body = alloca (flen + 4);
    22942304  body[0] = '$';
    22952305  body[1] = '(';
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