Ignore:
Timestamp:
May 23, 2007, 7:31:19 AM (18 years ago)
Author:
bird
Message:

Merged with the 2007-05-23 CVS. Added rsort and fixed a couple of windows build issues.

File:
1 edited

Legend:

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

    r863 r903  
    5353    unsigned char maximum_args;
    5454    char expand_args;
    55     char *(*func_ptr) PARAMS ((char *output, char **argv, const char *fname));
     55    char *(*func_ptr) (char *output, char **argv, const char *fname);
    5656  };
    5757
     
    5959function_table_entry_hash_1 (const void *keyv)
    6060{
    61   struct function_table_entry const *key = (struct function_table_entry const *) keyv;
     61  const struct function_table_entry *key = keyv;
    6262  return_STRING_N_HASH_1 (key->name, key->len);
    6363}
     
    6666function_table_entry_hash_2 (const void *keyv)
    6767{
    68   struct function_table_entry const *key = (struct function_table_entry const *) keyv;
     68  const struct function_table_entry *key = keyv;
    6969  return_STRING_N_HASH_2 (key->name, key->len);
    7070}
     
    7373function_table_entry_hash_cmp (const void *xv, const void *yv)
    7474{
    75   struct function_table_entry const *x = (struct function_table_entry const *) xv;
    76   struct function_table_entry const *y = (struct function_table_entry const *) yv;
     75  const struct function_table_entry *x = xv;
     76  const struct function_table_entry *y = yv;
    7777  int result = x->len - y->len;
    7878  if (result)
     
    9292
    9393char *
    94 subst_expand (char *o, char *text, char *subst, char *replace,
     94subst_expand (char *o, const char *text, const char *subst, const char *replace,
    9595              unsigned int slen, unsigned int rlen, int by_word)
    9696{
    97   char *t = text;
    98   char *p;
     97  const char *t = text;
     98  const char *p;
    9999
    100100  if (slen == 0 && !by_word)
     
    141141
    142142      /* Advance T past the string to be replaced.  */
    143       {
    144         char *nt = p + slen;
    145         t = nt;
    146       }
     143      t = p + slen;
    147144    } while (*t != '\0');
    148145
     
    163160
    164161char *
    165 patsubst_expand (char *o, char *text, char *pattern, char *replace,
    166                  char *pattern_percent, char *replace_percent)
     162patsubst_expand_pat (char *o, const char *text,
     163                     const char *pattern, const char *replace,
     164                     const char *pattern_percent, const char *replace_percent)
    167165{
    168166  unsigned int pattern_prepercent_len, pattern_postpercent_len;
    169167  unsigned int replace_prepercent_len, replace_postpercent_len;
    170   char *t;
     168  const char *t;
    171169  unsigned int len;
    172170  int doneany = 0;
    173 
    174   /* We call find_percent on REPLACE before checking PATTERN so that REPLACE
    175      will be collapsed before we call subst_expand if PATTERN has no %.  */
    176   if (!replace_percent)
    177     {
    178       replace_percent = find_percent (replace);
    179       if (replace_percent)
    180         ++replace_percent;
    181     }
    182171
    183172  /* Record the length of REPLACE before and after the % so we don't have to
     
    194183    }
    195184
    196   if (!pattern_percent)
    197     {
    198       pattern_percent = find_percent (pattern);
    199       if (pattern_percent)
    200         ++pattern_percent;
    201     }
    202185  if (!pattern_percent)
    203186    /* With no % in the pattern, this is just a simple substitution.  */
     
    271254}
    272255
     256/* Store into VARIABLE_BUFFER at O the result of scanning TEXT
     257   and replacing strings matching PATTERN with REPLACE.
     258   If PATTERN_PERCENT is not nil, PATTERN has already been
     259   run through find_percent, and PATTERN_PERCENT is the result.
     260   If REPLACE_PERCENT is not nil, REPLACE has already been
     261   run through find_percent, and REPLACE_PERCENT is the result.
     262   Note that we expect PATTERN_PERCENT and REPLACE_PERCENT to point to the
     263   character _AFTER_ the %, not to the % itself.
     264*/
     265
     266char *
     267patsubst_expand (char *o, const char *text, char *pattern, char *replace)
     268{
     269  const char *pattern_percent = find_percent (pattern);
     270  const char *replace_percent = find_percent (replace);
     271
     272  /* If there's a percent in the pattern or replacement skip it.  */
     273  if (replace_percent)
     274    ++replace_percent;
     275  if (pattern_percent)
     276    ++pattern_percent;
     277
     278  return patsubst_expand_pat (o, text, pattern, replace,
     279                              pattern_percent, replace_percent);
     280}
     281
    273282
    274283#ifdef CONFIG_WITH_OPTIMIZATION_HACKS
     
    276285   it can't be function and we can skip the hash lookup drop out. */
    277286
    278 #ifdef KMK
    279 # define MAX_FUNCTION_LENGTH 12
    280 #else
    281 # define MAX_FUNCTION_LENGTH 10
    282 #endif
     287# ifdef KMK
     288#  define MAX_FUNCTION_LENGTH 12
     289# else
     290#  define MAX_FUNCTION_LENGTH 10
     291# endif
     292#endif /* CONFIG_WITH_OPTIMIZATION_HACKS */
    283293
    284294/* Look up a function by name.  */
     295
     296#ifdef CONFIG_WITH_OPTIMIZATION_HACKS
    285297__inline
    286298#endif /* CONFIG_WITH_OPTIMIZATION_HACKS */
     
    318330
    319331int
    320 pattern_matches (char *pattern, char *percent, char *str)
     332pattern_matches (const char *pattern, const char *percent, const char *str)
    321333{
    322334  unsigned int sfxlen, strlength;
     
    325337    {
    326338      unsigned int len = strlen (pattern) + 1;
    327       char *new_chars = (char *) alloca (len);
    328       bcopy (pattern, new_chars, len);
     339      char *new_chars = alloca (len);
     340      memcpy (new_chars, pattern, len);
     341      percent = find_percent (new_chars);
     342      if (percent == 0)
     343        return streq (new_chars, str);
    329344      pattern = new_chars;
    330       percent = find_percent (pattern);
    331       if (percent == 0)
    332         return streq (pattern, str);
    333345    }
    334346
     
    386398  static char *result = 0;
    387399  static unsigned int length;
    388   register struct nameseq *chain;
    389   register unsigned int idx;
     400  struct nameseq *chain;
     401  unsigned int idx;
    390402
    391403  chain = multi_glob (parse_file_seq
     
    400412    {
    401413      length = 100;
    402       result = (char *) xmalloc (100);
     414      result = xmalloc (100);
    403415    }
    404416
     
    406418  while (chain != 0)
    407419    {
    408       register char *name = chain->name;
     420      const char *name = chain->name;
    409421      unsigned int len = strlen (name);
    410422
    411423      struct nameseq *next = chain->next;
    412       free ((char *) chain);
     424      free (chain);
    413425      chain = next;
    414426
     
    420432            {
    421433              length += (len + 1) * 2;
    422               result = (char *) xrealloc (result, length);
     434              result = xrealloc (result, length);
    423435            }
    424           bcopy (name, &result[idx], len);
     436          memcpy (&result[idx], name, len);
    425437          idx += len;
    426438          result[idx++] = ' ';
    427439        }
    428 
    429       free (name);
    430440    }
    431441
     
    447457func_patsubst (char *o, char **argv, const char *funcname UNUSED)
    448458{
    449   o = patsubst_expand (o, argv[2], argv[0], argv[1], (char *) 0, (char *) 0);
     459  o = patsubst_expand (o, argv[2], argv[0], argv[1]);
    450460  return o;
    451461}
     
    461471     If the two arguments have a different number of words,
    462472     the excess words are just output separated by blanks.  */
    463   register char *tp;
    464   register char *pp;
    465   char *list1_iterator = argv[0];
    466   char *list2_iterator = argv[1];
     473  const char *tp;
     474  const char *pp;
     475  const char *list1_iterator = argv[0];
     476  const char *list2_iterator = argv[1];
    467477  do
    468478    {
     
    496506{
    497507  /* Expand the argument.  */
    498   register struct variable *v = lookup_variable (argv[0], strlen (argv[0]));
     508  struct variable *v = lookup_variable (argv[0], strlen (argv[0]));
    499509  if (v == 0)
    500510    o = variable_buffer_output (o, "undefined", 9);
     
    535545func_flavor (char *o, char **argv, const char *funcname UNUSED)
    536546{
    537   register struct variable *v = lookup_variable (argv[0], strlen (argv[0]));
     547  struct variable *v = lookup_variable (argv[0], strlen (argv[0]));
    538548
    539549  if (v == 0)
     
    563573{
    564574  /* Expand the argument.  */
    565   char *list_iterator = argv[0];
    566   char *p2 =0;
     575  const char *list_iterator = argv[0];
     576  const char *p2;
    567577  int doneany =0;
    568578  unsigned int len=0;
     
    572582  while ((p2 = find_next_token (&list_iterator, &len)) != 0)
    573583    {
    574       char *p = p2 + len;
     584      const char *p = p2 + len;
    575585
    576586
     
    607617        }
    608618    }
     619
    609620  if (doneany)
    610621    /* Kill last space.  */
    611622    --o;
    612623
    613 
    614   return o;
    615 
     624  return o;
    616625}
    617626
     
    621630{
    622631  /* Expand the argument.  */
    623   char *p3 = argv[0];
    624   char *p2=0;
     632  const char *p3 = argv[0];
     633  const char *p2;
    625634  int doneany=0;
    626635  unsigned int len=0;
    627   char *p=0;
     636
    628637  int is_basename= streq (funcname, "basename");
    629638  int is_dir= !is_basename;
    630639
    631640  while ((p2 = find_next_token (&p3, &len)) != 0)
    632         {
    633           p = p2 + len;
    634           while (p >= p2 && (!is_basename  || *p != '.'))
    635             {
    636               if (IS_PATHSEP (*p))
    637                 break;
    638                     --p;
    639             }
    640 
    641           if (p >= p2 && (is_dir))
    642             o = variable_buffer_output (o, p2, ++p - p2);
    643           else if (p >= p2 && (*p == '.'))
    644             o = variable_buffer_output (o, p2, p - p2);
     641    {
     642      const char *p = p2 + len;
     643      while (p >= p2 && (!is_basename  || *p != '.'))
     644        {
     645          if (IS_PATHSEP (*p))
     646            break;
     647          --p;
     648        }
     649
     650      if (p >= p2 && (is_dir))
     651        o = variable_buffer_output (o, p2, ++p - p2);
     652      else if (p >= p2 && (*p == '.'))
     653        o = variable_buffer_output (o, p2, p - p2);
    645654#ifdef HAVE_DOS_PATHS
    646         /* Handle the "d:foobar" case */
    647           else if (p2[0] && p2[1] == ':' && is_dir)
    648             o = variable_buffer_output (o, p2, 2);
    649 #endif
    650           else if (is_dir)
     655      /* Handle the "d:foobar" case */
     656      else if (p2[0] && p2[1] == ':' && is_dir)
     657        o = variable_buffer_output (o, p2, 2);
     658#endif
     659      else if (is_dir)
    651660#ifdef VMS
    652             o = variable_buffer_output (o, "[]", 2);
     661        o = variable_buffer_output (o, "[]", 2);
    653662#else
    654663#ifndef _AMIGA
    655             o = variable_buffer_output (o, "./", 2);
     664      o = variable_buffer_output (o, "./", 2);
    656665#else
    657             ; /* Just a nop...  */
     666      ; /* Just a nop...  */
    658667#endif /* AMIGA */
    659668#endif /* !VMS */
    660           else
    661             /* The entire name is the basename.  */
    662             o = variable_buffer_output (o, p2, len);
    663 
    664           o = variable_buffer_output (o, " ", 1);
    665           doneany = 1;
    666         }
    667       if (doneany)
    668         /* Kill last space.  */
    669         --o;
    670 
    671 
    672  return o;
     669      else
     670        /* The entire name is the basename.  */
     671        o = variable_buffer_output (o, p2, len);
     672
     673      o = variable_buffer_output (o, " ", 1);
     674      doneany = 1;
     675    }
     676
     677  if (doneany)
     678    /* Kill last space.  */
     679    --o;
     680
     681  return o;
    673682}
    674683
     
    677686{
    678687  int fixlen = strlen (argv[0]);
    679   char *list_iterator = argv[1];
     688  const char *list_iterator = argv[1];
    680689  int is_addprefix = streq (funcname, "addprefix");
    681690  int is_addsuffix = !is_addprefix;
    682691
    683692  int doneany = 0;
    684   char *p;
     693  const char *p;
    685694  unsigned int len;
    686695
     
    717726{
    718727  unsigned int i;
    719   char *words = argv[0];    /* Use a temp variable for find_next_token */
    720   char *p = find_next_token (&words, &i);
     728  const char *words = argv[0];    /* Use a temp variable for find_next_token */
     729  const char *p = find_next_token (&words, &i);
    721730
    722731  if (p != 0)
     
    730739{
    731740  unsigned int i;
    732   char *words = argv[0];    /* Use a temp variable for find_next_token */
    733   char *p = 0;
    734   char *t;
     741  const char *words = argv[0];    /* Use a temp variable for find_next_token */
     742  const char *p = NULL;
     743  const char *t;
    735744
    736745  while ((t = find_next_token (&words, &i)))
     
    747756{
    748757  int i = 0;
    749   char *word_iterator = argv[0];
     758  const char *word_iterator = argv[0];
    750759  char buf[20];
    751760
     
    755764  sprintf (buf, "%d", i);
    756765  o = variable_buffer_output (o, buf, strlen (buf));
    757 
    758766
    759767  return o;
     
    776784
    777785static void
    778 check_numeric (const char *s, const char *message)
     786check_numeric (const char *s, const char *msg)
    779787{
    780788  const char *end = s + strlen (s) - 1;
     
    787795
    788796  if (s <= end || end - beg < 0)
    789     fatal (*expanding_var, "%s: '%s'", message, beg);
     797    fatal (*expanding_var, "%s: '%s'", msg, beg);
    790798}
    791799
     
    795803func_word (char *o, char **argv, const char *funcname UNUSED)
    796804{
    797   char *end_p=0;
    798   int i=0;
    799   char *p=0;
     805  const char *end_p;
     806  const char *p;
     807  int i;
    800808
    801809  /* Check the first argument.  */
    802810  check_numeric (argv[0], _("non-numeric first argument to `word' function"));
    803   i =  atoi (argv[0]);
     811  i = atoi (argv[0]);
    804812
    805813  if (i == 0)
    806814    fatal (*expanding_var,
    807815           _("first argument to `word' function must be greater than 0"));
    808 
    809816
    810817  end_p = argv[1];
     
    839846  if (count > 0)
    840847    {
    841       char *p;
    842       char *end_p = argv[2];
     848      const char *p;
     849      const char *end_p = argv[2];
    843850
    844851      /* Find the beginning of the "start"th word.  */
     
    860867}
    861868
    862 static char*
     869static char *
    863870func_findstring (char *o, char **argv, const char *funcname UNUSED)
    864871{
     
    876883  char *varname = expand_argument (argv[0], NULL);
    877884  char *list = expand_argument (argv[1], NULL);
    878   char *body = argv[2];
     885  const char *body = argv[2];
    879886
    880887  int doneany = 0;
    881   char *list_iterator = list;
    882   char *p;
     888  const char *list_iterator = list;
     889  const char *p;
    883890  unsigned int len;
    884   register struct variable *var;
     891  struct variable *var;
    885892
    886893  push_new_variable_scope ();
     
    902909      var->value_length = len;
    903910#else
    904       {
    905         char save = p[len];
    906 
    907         p[len] = '\0';
    908         free (var->value);
    909         var->value = (char *) xstrdup ((char*) p);
    910         p[len] = save;
    911       }
     911      free (var->value);
     912      var->value = savestring (p, len);
    912913#endif
    913914
     
    983984  struct hash_table a_word_table;
    984985  int is_filter = streq (funcname, "filter");
    985   char *pat_iterator = argv[0];
    986   char *word_iterator = argv[1];
     986  const char *pat_iterator = argv[0];
     987  const char *word_iterator = argv[1];
    987988  int literals = 0;
    988989  int words = 0;
     
    996997  while ((p = find_next_token (&pat_iterator, &len)) != 0)
    997998    {
    998       struct a_pattern *pat = (struct a_pattern *) alloca (sizeof (struct a_pattern));
     999      struct a_pattern *pat = alloca (sizeof (struct a_pattern));
    9991000
    10001001      *pattail = pat;
     
    10191020  while ((p = find_next_token (&word_iterator, &len)) != 0)
    10201021    {
    1021       struct a_word *word = (struct a_word *) alloca (sizeof (struct a_word));
     1022      struct a_word *word = alloca (sizeof (struct a_word));
    10221023
    10231024      *wordtail = word;
     
    10401041  if (hashing)
    10411042    {
    1042       hash_init (&a_word_table, words, a_word_hash_1, a_word_hash_2, a_word_hash_cmp);
     1043      hash_init (&a_word_table, words, a_word_hash_1, a_word_hash_2,
     1044                 a_word_hash_cmp);
    10431045      for (wp = wordhead; wp != 0; wp = wp->next)
    10441046        {
     
    10641066              a_word_key.str = pp->str;
    10651067              a_word_key.length = pp->length;
    1066               wp = (struct a_word *) hash_find_item (&a_word_table, &a_word_key);
     1068              wp = hash_find_item (&a_word_table, &a_word_key);
    10671069              while (wp)
    10681070                {
     
    11041106func_strip (char *o, char **argv, const char *funcname UNUSED)
    11051107{
    1106   char *p = argv[0];
    1107   int doneany =0;
     1108  const char *p = argv[0];
     1109  int doneany = 0;
    11081110
    11091111  while (*p != '\0')
    11101112    {
    11111113      int i=0;
    1112       char *word_start=0;
     1114      const char *word_start;
    11131115
    11141116      while (isspace ((unsigned char)*p))
     
    11271129    /* Kill the last space.  */
    11281130    --o;
     1131
    11291132  return o;
    11301133}
     
    11461149    len += strlen (*argvp) + 2;
    11471150
    1148   p = msg = (char *) alloca (len + 1);
     1151  p = msg = alloca (len + 1);
    11491152
    11501153  for (argvp=argv; argvp[1] != 0; ++argvp)
     
    11851188func_sort (char *o, char **argv, const char *funcname UNUSED)
    11861189{
    1187   char **words = 0;
    1188   int nwords = 0;
    1189   register int wordi = 0;
    1190 
    1191   /* Chop ARGV[0] into words and put them in WORDS.  */
    1192   char *t = argv[0];
     1190  const char *t;
     1191  char **words;
     1192  int wordi;
    11931193  char *p;
    11941194  unsigned int len;
    11951195  int i;
    11961196
     1197  /* Find the maximum number of words we'll have.  */
     1198  t = argv[0];
     1199  wordi = 1;
     1200  while (*t != '\0')
     1201    {
     1202      char c = *(t++);
     1203
     1204      if (! isspace ((unsigned char)c))
     1205        continue;
     1206
     1207      ++wordi;
     1208
     1209      while (isspace ((unsigned char)*t))
     1210        ++t;
     1211    }
     1212
     1213  words = xmalloc (wordi * sizeof (char *));
     1214
     1215  /* Now assign pointers to each string in the array.  */
     1216  t = argv[0];
     1217  wordi = 0;
    11971218  while ((p = find_next_token (&t, &len)) != 0)
    11981219    {
    1199       if (wordi >= nwords - 1)
    1200         {
    1201           nwords = (2 * nwords) + 5;
    1202           words = (char **) xrealloc ((char *) words,
    1203                                       nwords * sizeof (char *));
    1204         }
    1205       words[wordi++] = savestring (p, len);
    1206     }
    1207 
    1208   if (!wordi)
    1209     return o;
    1210 
    1211   /* Now sort the list of words.  */
    1212   qsort ((char *) words, wordi, sizeof (char *), alpha_compare);
    1213 
    1214   /* Now write the sorted list.  */
    1215   for (i = 0; i < wordi; ++i)
    1216     {
    1217       len = strlen (words[i]);
    1218       if (i == wordi - 1 || strlen (words[i + 1]) != len
    1219           || strcmp (words[i], words[i + 1]))
     1220      ++t;
     1221      p[len] = '\0';
     1222      words[wordi++] = p;
     1223    }
     1224
     1225  if (wordi)
     1226    {
     1227      /* Now sort the list of words.  */
     1228      qsort (words, wordi, sizeof (char *), alpha_compare);
     1229
     1230      /* Now write the sorted list, uniquified.  */
     1231#ifdef CONFIG_WITH_RSORT
     1232      if (strcmp (funcname, "rsort"))
    12201233        {
    1221           o = variable_buffer_output (o, words[i], len);
    1222           o = variable_buffer_output (o, " ", 1);
     1234          /* sort */
     1235#endif
     1236          for (i = 0; i < wordi; ++i)
     1237            {
     1238              len = strlen (words[i]);
     1239              if (i == wordi - 1 || strlen (words[i + 1]) != len
     1240                  || strcmp (words[i], words[i + 1]))
     1241                {
     1242                  o = variable_buffer_output (o, words[i], len);
     1243                  o = variable_buffer_output (o, " ", 1);
     1244                }
     1245            }
     1246#ifdef CONFIG_WITH_RSORT
    12231247        }
    1224       free (words[i]);
    1225     }
    1226   /* Kill the last space.  */
    1227   --o;
     1248      else
     1249        {
     1250          /* rsort - reverse the result */
     1251          i = wordi;
     1252          while (i-- > 0)
     1253            {
     1254              len = strlen (words[i]);
     1255              if (i == 0 || strlen (words[i + 1]) != len
     1256                  || strcmp (words[i], words[i + 1]))
     1257                {
     1258                  o = variable_buffer_output (o, words[i], len);
     1259                  o = variable_buffer_output (o, " ", 1);
     1260                }
     1261            }
     1262        }
     1263#endif
     1264
     1265      /* Kill the last space.  */
     1266      --o;
     1267    }
    12281268
    12291269  free (words);
     
    12711311  argv += 1 + !result;
    12721312
    1273   if (argv[0])
    1274     {
    1275       char *expansion;
    1276 
    1277       expansion = expand_argument (argv[0], NULL);
     1313  if (*argv)
     1314    {
     1315      char *expansion = expand_argument (*argv, NULL);
    12781316
    12791317      o = variable_buffer_output (o, expansion, strlen (expansion));
     
    13921430func_wildcard (char *o, char **argv, const char *funcname UNUSED)
    13931431{
    1394 
    13951432#ifdef _AMIGA
    13961433   o = wildcard_expansion (argv[0], o);
     
    16371674func_shell (char *o, char **argv, const char *funcname UNUSED)
    16381675{
    1639   char* batch_filename = NULL;
     1676  char *batch_filename = NULL;
    16401677
    16411678#ifdef __MSDOS__
     
    16431680#endif
    16441681  char **command_argv;
    1645   char *error_prefix;
     1682  const char *error_prefix;
    16461683  char **envp;
    16471684  int pipedes[2];
     
    16501687#ifndef __MSDOS__
    16511688  /* Construct the argument list.  */
    1652   command_argv = construct_command_argv (argv[0],
    1653                                          (char **) NULL, (struct file *) 0,
    1654                                          &batch_filename);
     1689  command_argv = construct_command_argv (argv[0], NULL, NULL, &batch_filename);
    16551690  if (command_argv == 0)
    16561691    return o;
     
    16641699     calling environment.
    16651700
     1701     See Savannah bug #10593.
     1702
    16661703  envp = target_environment (NILF);
    16671704  */
     
    16721709  if (reading_file && reading_file->filenm)
    16731710    {
    1674       error_prefix = (char *) alloca (strlen (reading_file->filenm)+11+4);
    1675       sprintf (error_prefix,
    1676                "%s:%lu: ", reading_file->filenm, reading_file->lineno);
     1711      char *p = alloca (strlen (reading_file->filenm)+11+4);
     1712      sprintf (p, "%s:%lu: ", reading_file->filenm, reading_file->lineno);
     1713      error_prefix = p;
    16771714    }
    16781715  else
    16791716    error_prefix = "";
    16801717
    1681 #ifdef WINDOWS32
    1682 
    1683   windows32_openpipe (pipedes, &pid, command_argv, envp);
    1684 
    1685   if (pipedes[0] < 0) {
    1686         /* open of the pipe failed, mark as failed execution */
    1687     shell_function_completed = -1;
    1688 
    1689         return o;
    1690   } else
    1691 
    1692 #elif defined(__MSDOS__)
    1693 
     1718#if defined(__MSDOS__)
    16941719  fpipe = msdos_openpipe (pipedes, &pid, argv[0]);
    16951720  if (pipedes[0] < 0)
     
    16981723      return o;
    16991724    }
    1700 
     1725#elif defined(WINDOWS32)
     1726  windows32_openpipe (pipedes, &pid, command_argv, envp);
     1727  if (pipedes[0] < 0)
     1728    {
     1729      /* open of the pipe failed, mark as failed execution */
     1730      shell_function_completed = -1;
     1731
     1732      return o;
     1733    }
     1734  else
    17011735#else
    1702 
    17031736  if (pipe (pipedes) < 0)
    17041737    {
     
    17081741
    17091742# ifdef __EMX__
    1710 
    17111743  /* close some handles that are unnecessary for the child process */
    17121744  CLOSE_ON_EXEC(pipedes[1]);
     
    17161748  if (pid < 0)
    17171749    perror_with_name (error_prefix, "spawn");
    1718 
    17191750# else /* ! __EMX__ */
    1720 
    17211751  pid = vfork ();
    17221752  if (pid < 0)
     
    17251755    child_execute_job (0, pipedes[1], command_argv, envp);
    17261756  else
    1727 
    17281757# endif
    1729 
    17301758#endif
    17311759    {
     
    17421770      /* Free the storage only the child needed.  */
    17431771      free (command_argv[0]);
    1744       free ((char *) command_argv);
     1772      free (command_argv);
    17451773
    17461774      /* Close the write side of the pipe.  */
    1747 # ifdef _MSC_VER /* crap. */
     1775# ifdef _MSC_VER /* Avoid annoying msvcrt when debugging. (bird) */
    17481776      if (pipedes[1] != -1)
    1749 # endif 
    1750       (void) close (pipedes[1]);
     1777# endif
     1778      close (pipedes[1]);
    17511779#endif
    17521780
     
    17541782
    17551783      maxlen = 200;
    1756       buffer = (char *) xmalloc (maxlen + 1);
     1784      buffer = xmalloc (maxlen + 1);
    17571785
    17581786      /* Read from the pipe until it gets EOF.  */
     
    17621790            {
    17631791              maxlen += 512;
    1764               buffer = (char *) xrealloc (buffer, maxlen + 1);
     1792              buffer = xrealloc (buffer, maxlen + 1);
    17651793            }
    17661794
     
    17761804        (void) pclose (fpipe);
    17771805#else
    1778 # ifdef _MSC_VER /* crap. */
     1806# ifdef _MSC_VER /* Avoid annoying msvcrt when debugging. (bird) */
    17791807      if (pipedes[0] != -1)
    1780 # endif 
     1808# endif
    17811809      (void) close (pipedes[0]);
    17821810#endif
     
    18921920        {
    18931921          maxlen += 512;
    1894           buffer = (char *) xrealloc (buffer, maxlen + 1);
     1922          buffer = xrealloc (buffer, maxlen + 1);
    18951923        }
    18961924
     
    19301958func_not (char *o, char **argv, const char *funcname)
    19311959{
    1932   char *s = argv[0];
     1960  const char *s = argv[0];
    19331961  int result = 0;
    19341962  while (isspace ((unsigned char)*s))
     
    20632091{
    20642092  /* Expand the argument.  */
    2065   char *p = argv[0];
    2066   char *path = 0;
     2093  const char *p = argv[0];
     2094  const char *path = 0;
    20672095  int doneany = 0;
    20682096  unsigned int len = 0;
     
    20772105          in[len] = '\0';
    20782106
    2079           if
    2080           (
     2107          if (
    20812108#ifdef HAVE_REALPATH
    2082             realpath (in, out)
     2109              realpath (in, out)
    20832110#else
    2084             abspath (in, out)
    2085 #endif
    2086           )
     2111              abspath (in, out)
     2112#endif
     2113             )
    20872114            {
    20882115              o = variable_buffer_output (o, out, strlen (out));
     
    20972124    --o;
    20982125
    2099  return o;
     2126  return o;
    21002127}
    21012128
     
    21042131{
    21052132  /* Expand the argument.  */
    2106   char *p = argv[0];
    2107   char *path = 0;
     2133  const char *p = argv[0];
     2134  const char *path = 0;
    21082135  int doneany = 0;
    21092136  unsigned int len = 0;
     
    21312158    --o;
    21322159
    2133  return o;
     2160  return o;
    21342161}
    21352162
     
    21412168  /* Expand the argument.  */
    21422169  char *p = argv[0];
    2143   PATH_VAR (current_directory);
    21442170  char *cwd = argv[1];
    21452171  unsigned int cwd_len = ~0U;
     
    29743000}
    29753001
    2976 
    29773002#endif /* CONFIG_WITH_MATH */
     3003
    29783004
    29793005/* Lookup table for builtin functions.
     
    29893015   Functions that do namespace tricks (foreach) don't automatically expand.  */
    29903016
    2991 static char *func_call PARAMS ((char *o, char **argv, const char *funcname));
     3017static char *func_call (char *o, char **argv, const char *funcname);
    29923018
    29933019
     
    30123038  { STRING_SIZE_TUPLE("patsubst"),      3,  3,  1,  func_patsubst},
    30133039  { STRING_SIZE_TUPLE("realpath"),      0,  1,  1,  func_realpath},
     3040#ifdef CONFIG_WITH_RSORT
     3041  { STRING_SIZE_TUPLE("rsort"),         0,  1,  1,  func_sort},
     3042#endif
    30143043  { STRING_SIZE_TUPLE("shell"),         0,  1,  1,  func_shell},
    30153044  { STRING_SIZE_TUPLE("sort"),          0,  1,  1,  func_sort},
     
    31153144
    31163145static int
    3117 handle_function2 (const struct function_table_entry *entry_p, char **op, char **stringp) /* bird split it up. */
     3146handle_function2 (const struct function_table_entry *entry_p, char **op, const char **stringp) /* bird split it up. */
    31183147{
    31193148  char openparen = (*stringp)[0];
    31203149  char closeparen = openparen == '(' ? ')' : '}';
    3121   char *beg;
    3122   char *end;
     3150  const char *beg;
     3151  const char *end;
    31233152  int count = 0;
    3124   register char *p;
     3153  char *abeg = NULL;
    31253154  char **argv, **argvp;
    31263155  int nargs;
     
    31543183
    31553184  /* Get some memory to store the arg pointers.  */
    3156   argvp = argv = (char **) alloca (sizeof (char *) * (nargs + 2));
     3185  argvp = argv = alloca (sizeof (char *) * (nargs + 2));
    31573186
    31583187  /* Chop the string into arguments, then a nul.  As soon as we hit
     
    31643193     each argument.  */
    31653194
    3166   if (!entry_p->expand_args)
     3195  if (entry_p->expand_args)
     3196    {
     3197      const char *p;
     3198      for (p=beg, nargs=0; p <= end; ++argvp)
     3199        {
     3200          const char *next;
     3201
     3202          ++nargs;
     3203
     3204          if (nargs == entry_p->maximum_args
     3205              || (! (next = find_next_argument (openparen, closeparen, p, end))))
     3206            next = end;
     3207
     3208          *argvp = expand_argument (p, next);
     3209          p = next + 1;
     3210        }
     3211    }
     3212  else
    31673213    {
    31683214      int len = end - beg;
    3169 
    3170       p = xmalloc (len+1);
    3171       memcpy (p, beg, len);
    3172       p[len] = '\0';
    3173       beg = p;
    3174       end = beg + len;
    3175     }
    3176 
    3177   for (p=beg, nargs=0; p <= end; ++argvp)
    3178     {
    3179       char *next;
    3180 
    3181       ++nargs;
    3182 
    3183       if (nargs == entry_p->maximum_args
    3184           || (! (next = find_next_argument (openparen, closeparen, p, end))))
    3185         next = end;
    3186 
    3187       if (entry_p->expand_args)
    3188         *argvp = expand_argument (p, next);
    3189       else
     3215      char *p, *aend;
     3216
     3217      abeg = xmalloc (len+1);
     3218      memcpy (abeg, beg, len);
     3219      abeg[len] = '\0';
     3220      aend = abeg + len;
     3221
     3222      for (p=abeg, nargs=0; p <= aend; ++argvp)
    31903223        {
     3224          char *next;
     3225
     3226          ++nargs;
     3227
     3228          if (nargs == entry_p->maximum_args
     3229              || (! (next = find_next_argument (openparen, closeparen, p, aend))))
     3230            next = aend;
     3231
    31913232          *argvp = p;
    31923233          *next = '\0';
     3234          p = next + 1;
    31933235        }
    3194 
    3195       p = next + 1;
    31963236    }
    31973237  *argvp = NULL;
     
    32043244    for (argvp=argv; *argvp != 0; ++argvp)
    32053245      free (*argvp);
    3206   else
    3207     free (beg);
     3246  if (abeg)
     3247    free (abeg);
    32083248
    32093249  return 1;
     
    32113251
    32123252int
    3213 handle_function (char **op, char **stringp) /* bird split it up */
     3253handle_function (char **op, const char **stringp) /* bird split it up */
    32143254{
    32153255  const struct function_table_entry *entry_p = lookup_function (*stringp + 1);
     
    32563296
    32573297  entry_p = lookup_function (fname);
    3258 
    32593298  if (entry_p)
    32603299    {
    32613300      /* How many arguments do we have?  */
    32623301      for (i=0; argv[i+1]; ++i)
    3263         ;
    3264 
     3302        ;
    32653303      return expand_builtin_function (o, i, argv+1, entry_p);
    32663304    }
     
    32783316    return o;
    32793317
    3280   body = (char *) alloca (flen + 4);
     3318  body = alloca (flen + 4);
    32813319  body[0] = '$';
    32823320  body[1] = '(';
     
    33393377    unsigned i;
    33403378    for (i = 0; i < FUNCTION_TABLE_ENTRIES; i++)
    3341         assert(function_table_init[i].len <= MAX_FUNCTION_LENGTH);
     3379        assert (function_table_init[i].len <= MAX_FUNCTION_LENGTH);
    33423380  }
    33433381#endif
Note: See TracChangeset for help on using the changeset viewer.