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/variable.c

    r821 r903  
    4343
    4444struct pattern_var *
    45 create_pattern_var (char *target, char *suffix)
    46 {
    47   register struct pattern_var *p
    48     = (struct pattern_var *) xmalloc (sizeof (struct pattern_var));
     45create_pattern_var (const char *target, const char *suffix)
     46{
     47  register struct pattern_var *p = xmalloc (sizeof (struct pattern_var));
    4948
    5049  if (last_pattern_var != 0)
     
    6564
    6665static struct pattern_var *
    67 lookup_pattern_var (struct pattern_var *start, char *target)
     66lookup_pattern_var (struct pattern_var *start, const char *target)
    6867{
    6968  struct pattern_var *p;
     
    7271  for (p = start ? start->next : pattern_vars; p != 0; p = p->next)
    7372    {
    74       char *stem;
     73      const char *stem;
    7574      unsigned int stemlen;
    7675
     
    278277
    279278#ifndef VARIABLE_BUCKETS
     279# ifdef KMK /* Move to Makefile.kmk? */
     280#  define VARIABLE_BUCKETS              16384
     281# else  /*!KMK*/
    280282#define VARIABLE_BUCKETS                523
     283# endif /*!KMK*/
    281284#endif
    282285#ifndef PERFILE_VARIABLE_BUCKETS
     
    298301init_hash_global_variable_set (void)
    299302{
    300   hash_init (&global_variable_set.table,
    301 #ifdef KMK /* FIMXE: just redefine the bucket size! */
    302              16384,
    303 #else
    304              VARIABLE_BUCKETS,
    305 #endif
     303  hash_init (&global_variable_set.table, VARIABLE_BUCKETS,
    306304             variable_hash_1, variable_hash_2, variable_hash_cmp);
    307305}
     
    317315struct variable *
    318316define_variable_in_set (const char *name, unsigned int length,
    319                         char *value, unsigned int value_length, int duplicate_value,
     317                        const char *value, unsigned int value_length, int duplicate_value,
    320318                        enum variable_origin origin, int recursive,
    321319                        struct variable_set *set, const struct floc *flocp)
     
    323321struct variable *
    324322define_variable_in_set (const char *name, unsigned int length,
    325                         char *value, enum variable_origin origin,
     323                        const char *value, enum variable_origin origin,
    326324                        int recursive, struct variable_set *set,
    327325                        const struct floc *flocp)
     
    368366              if (v->value != 0)
    369367                free (v->value);
    370               v->value = value;
     368              v->value = (char *)value;
    371369              v->value_alloc_len = value_length + 1;
    372370            }
     
    399397  /* Create a new variable definition and add it to the hash table.  */
    400398
    401   v = (struct variable *) xmalloc (sizeof (struct variable));
     399  v = xmalloc (sizeof (struct variable));
    402400  v->name = savestring (name, length);
    403401  v->length = length;
     
    416414    {
    417415      v->value_alloc_len = value_length + 1;
    418       v->value = value;
     416      v->value = (char *)value;
    419417    }
    420418  else
     
    531529              }
    532530
    533             bcopy (v->name, p, l);
     531            memcpy (p, v->name, l);
    534532            p += l;
    535533            *(p++) = ' ';
     
    698696   parent of FILE's variable set.
    699697
    700    If we're READing a makefile, don't do the pattern variable search now,
     698   If we're READING a makefile, don't do the pattern variable search now,
    701699   since the pattern variable might not have been defined yet.  */
    702700
     
    710708      l = (struct variable_set_list *)
    711709        xmalloc (sizeof (struct variable_set_list));
    712       l->set = (struct variable_set *) xmalloc (sizeof (struct variable_set));
     710      l->set = xmalloc (sizeof (struct variable_set));
    713711      hash_init (&l->set->table, PERFILE_VARIABLE_BUCKETS,
    714712                 variable_hash_1, variable_hash_2, variable_hash_cmp);
     
    806804  register struct variable_set *set;
    807805
    808   set = (struct variable_set *) xmalloc (sizeof (struct variable_set));
     806  set = xmalloc (sizeof (struct variable_set));
    809807  hash_init (&set->table, SMALL_SCOPE_VARIABLE_BUCKETS,
    810808             variable_hash_1, variable_hash_2, variable_hash_cmp);
     
    831829  hash_map (&list->set->table, free_variable_name_and_value);
    832830  hash_free (&list->set->table, 1);
    833   free ((char *) list->set);
    834   free ((char *) list);
     831  free (list->set);
     832  free (list);
    835833}
    836834
     
    888886
    889887  /* Free the one we no longer need.  */
    890   free ((char *) setlist);
     888  free (setlist);
    891889  hash_map (&set->table, free_variable_name_and_value);
    892890  hash_free (&set->table, 1);
    893   free ((char *) set);
     891  free (set);
    894892}
    895893
     
    10361034  /* Define KMK_FEATURES to indicate various working KMK features. */
    10371035# if defined(CONFIG_WITH_TOUPPER_TOLOWER) \
     1036  && defined(CONFIG_WITH_RSORT) \
    10381037  && defined(CONFIG_WITH_ABSPATHEX) \
    10391038  && defined(CONFIG_WITH_VALUE_LENGTH) && defined(CONFIG_WITH_COMPARE) \
     
    10431042  && defined(KMK_HELPERS)
    10441043  (void) define_variable ("KMK_FEATURES", 12,
    1045                           "append-dash-n "
    1046                           "abspath abspathex"
     1044                          "append-dash-n abspath"
     1045                          " rsort"
     1046                          " abspathex"
    10471047                          " toupper tolower"
    10481048                          " comp-vars comp-cmds"
     
    10541054# else /* MSC can't deal with strings mixed with #if/#endif, thus the slow way. */
    10551055  strcpy(buf, "append-dash-n abspath");
     1056#  if defined(CONFIG_WITH_RSORT)
     1057  strcat(buf, " rsort");
     1058#  endif
    10561059#  if defined(CONFIG_WITH_ABSPATHEX)
    10571060  strcat(buf, " abspathex");
     
    13161319  hash_delete (&table, &makelevel_key);
    13171320
    1318   result = result_0 = (char **) xmalloc ((table.ht_fill + 2) * sizeof (char *));
     1321  result = result_0 = xmalloc ((table.ht_fill + 2) * sizeof (char *));
    13191322
    13201323  v_slot = (struct variable **) table.ht_vec;
     
    13371340              convert_Path_to_windows32(value, ';');
    13381341#endif
    1339             *result++ = concat (v->name, "=", value);
     1342            *result++ = xstrdup (concat (v->name, "=", value));
    13401343            free (value);
    13411344          }
     
    13471350              convert_Path_to_windows32(v->value, ';');
    13481351#endif
    1349             *result++ = concat (v->name, "=", v->value);
     1352            *result++ = xstrdup (concat (v->name, "=", v->value));
    13501353          }
    13511354      }
    13521355
    1353   *result = (char *) xmalloc (100);
    1354   (void) sprintf (*result, "%s=%u", MAKELEVEL_NAME, makelevel + 1);
     1356  *result = xmalloc (100);
     1357  sprintf (*result, "%s=%u", MAKELEVEL_NAME, makelevel + 1);
    13551358  *++result = 0;
    13561359
     
    13631366#ifdef CONFIG_WITH_VALUE_LENGTH
    13641367static struct variable *
    1365 do_variable_definition_append (const struct floc *flocp, struct variable *v, char *value,
     1368do_variable_definition_append (const struct floc *flocp, struct variable *v, const char *value,
    13661369                               enum variable_origin origin)
    13671370{
     
    14301433struct variable *
    14311434do_variable_definition (const struct floc *flocp, const char *varname,
    1432                         char *value, enum variable_origin origin,
     1435                        const char *value, enum variable_origin origin,
    14331436                        enum variable_flavor flavor, int target_var)
    14341437{
    1435   char *p, *alloc_value = NULL;
     1438  const char *p;
     1439  char *alloc_value = NULL;
    14361440  struct variable *v;
    14371441  int append = 0;
     
    15071511
    15081512            unsigned int oldlen, vallen;
    1509             char *val;
     1513            const char *val;
     1514            char *tp;
    15101515
    15111516            val = value;
     
    15241529            oldlen = strlen (v->value);
    15251530            vallen = strlen (val);
    1526             p = (char *) alloca (oldlen + 1 + vallen + 1);
    1527             bcopy (v->value, p, oldlen);
    1528             p[oldlen] = ' ';
    1529             bcopy (val, &p[oldlen + 1], vallen + 1);
     1531            tp = alloca (oldlen + 1 + vallen + 1);
     1532            memcpy (tp, v->value, oldlen);
     1533            tp[oldlen] = ' ';
     1534            memcpy (&tp[oldlen + 1], val, vallen + 1);
     1535            p = tp;
    15301536#endif /* !CONFIG_WITH_VALUE_LENGTH */
    15311537          }
     
    15541560
    15551561      /* See if we can find "/bin/sh.exe", "/bin/sh.com", etc.  */
    1556       if (__dosexec_find_on_path (p, (char **)0, shellpath))
     1562      if (__dosexec_find_on_path (p, NULL, shellpath))
    15571563        {
    1558           char *p;
    1559 
    1560           for (p = shellpath; *p; p++)
    1561             {
    1562               if (*p == '\\')
    1563                 *p = '/';
    1564             }
     1564          char *tp;
     1565
     1566          for (tp = shellpath; *tp; tp++)
     1567            if (*tp == '\\')
     1568              *tp = '/';
     1569
    15651570          v = define_variable_loc (varname, varname_len,
    15661571                                   shellpath, origin, flavor == f_recursive,
     
    15691574      else
    15701575        {
    1571           char *shellbase, *bslash;
     1576          const char *shellbase, *bslash;
    15721577          struct variable *pathv = lookup_variable ("PATH", 4);
    15731578          char *path_string;
     
    15901595          if (pathv)
    15911596            pathlen = strlen (pathv->value);
    1592           path_string = (char *)xmalloc (5 + pathlen + 2 + 1);
     1597          path_string = xmalloc (5 + pathlen + 2 + 1);
    15931598          /* On MSDOS, current directory is considered as part of $PATH.  */
    15941599          sprintf (path_string, "PATH=.;%s", pathv ? pathv->value : "");
    15951600          fake_env[0] = path_string;
    1596           fake_env[1] = (char *)0;
     1601          fake_env[1] = 0;
    15971602          if (__dosexec_find_on_path (shellbase, fake_env, shellpath))
    15981603            {
    1599               char *p;
    1600 
    1601               for (p = shellpath; *p; p++)
    1602                 {
    1603                   if (*p == '\\')
    1604                     *p = '/';
    1605                 }
     1604              char *tp;
     1605
     1606              for (tp = shellpath; *tp; tp++)
     1607                if (*tp == '\\')
     1608                  *tp = '/';
     1609
    16061610              v = define_variable_loc (varname, varname_len,
    16071611                                       shellpath, origin,
     
    17731777
    17741778  /* Expand the name, so "$(foo)bar = baz" works.  */
    1775   name = (char *) alloca (end - beg + 1);
    1776   bcopy (beg, name, end - beg);
     1779  name = alloca (end - beg + 1);
     1780  memcpy (name, beg, end - beg);
    17771781  name[end - beg] = '\0';
    17781782  v->name = allocated_variable_expand (name);
     
    18271831print_variable (const void *item, void *arg)
    18281832{
    1829   const struct variable *v = (struct variable *) item;
    1830   const char *prefix = (char *) arg;
     1833  const struct variable *v = item;
     1834  const char *prefix = arg;
    18311835  const char *origin;
    18321836
     
    19421946
    19431947void
    1944 print_file_variables (struct file *file)
     1948print_file_variables (const struct file *file)
    19451949{
    19461950  if (file->variables != 0)
     
    19691973   */
    19701974  convert_Path_to_windows32 (path, ';');
    1971   environ_path = concat ("PATH", "=", path);
     1975  environ_path = xstrdup (concat ("PATH", "=", path));
    19721976  putenv (environ_path);
    19731977  free (path);
Note: See TracChangeset for help on using the changeset viewer.