VirtualBox

Changeset 903 in kBuild for trunk


Ignore:
Timestamp:
May 23, 2007 5: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.

Location:
trunk/src/gmakenew
Files:
1 added
126 deleted
50 edited
20 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/gmakenew/ChangeLog

    r503 r903  
     12007-05-11  Paul Smith  <[email protected]>
     2
     3        * job.c (new_job): Add debug info to specify where make found the
     4        command script it is running to build a target.
     5        Fixes Savannah bug #18617.
     6
     7        * default.c (default_suffixes,default_suffix_rules,default_variables):
     8        Add support for Objective C.  Fixes Savannah bug #16389.
     9        Based on a patch provided by Peter O'Gorman <[email protected]>.
     10
     11        * function.c (func_lastword): Initialize p.
     12
     13        * doc/make.texi (Eval Function, Implicit Variables, Special Targets):
     14        Doc fixes noticed by Bob <[email protected]>.  Patch from
     15        Dave Korn <[email protected]>
     16
     172007-05-08  Paul Smith  <[email protected]>
     18
     19        Fix Savannah bug #19656:
     20
     21        * configure.in: Check for strcasecmp(), strcmpi(), and stricmp().
     22
     23        * make.h: Change all case-insensitive string compares to use
     24        strcasecmp() (from POSIX).  If we don't have that but do have one
     25        of the others, define strcasecmp to be one of those instead.  If
     26        we don't have any, declare a prototype for our own version.
     27
     28        * misc.c (strcasecmp): Use this if we can't find any native
     29        case-insensitive string comparison function.
     30        * vmsfunctions.c: Remove strcmpi(); we'll use misc.c:strcasecmp().
     31        * main.c (find_and_set_default_shell): Use strcasecmp() instead of
     32        strcmpi().
     33        * job.c (_is_unixy_shell, construct_command_argv_internal): Use
     34        strcasecmp() instead of stricmp().
     35        * hash.h (ISTRING_COMPARE, return_ISTRING_COMPARE): Use strcasecmp()
     36        instead of strcmpi().
     37        * acinclude.m4: Remove the strcasecmp() check from here.
     38
     392007-03-21  Paul Smith  <[email protected]>
     40
     41        * configure.in: Don't turn on case-insensitive file system support
     42        if --disable-... is given.  Fixes Savannah bug #19348.
     43
     442007-03-19  Paul Smith  <[email protected]>
     45
     46        * ALL: Use the strcache for all file name strings, or other
     47        strings which we will never free.  The goal is to save memory by
     48        avoiding duplicate copies of strings.  However, at the moment this
     49        doesn't save much memory in most situations: due to secondary
     50        expansion we actually save prerequisite lists twice (once before
     51        the secondary expansion, and then again after it's been parsed
     52        into individual file names in the dep list).  We will resolve this
     53        in a future change, by doing the parsing up-front for targets
     54        where secondary expansion is not set.
     55
     56        Moving things into the strcache also allows us to use const
     57        pointers in many more places.
     58
     592007-01-03  Paul Smith  <[email protected]>
     60
     61        * make.h (ENULLLOOP): Reset errno after each failed invocation of
     62        the function, not just the first.  Fixes Savannah bug #18680.
     63
     642006-11-18  Paul Smith  <[email protected]>
     65
     66        * strcache.c (strcache_add_len): Don't allocate a new buffer
     67        unless the string is not already nil-terminated.  Technically this
     68        is a violation of the standard, since we may be passed an array
     69        that is not long enough to test one past.  However, in make this
     70        is never true since we only use nil-terminated strings or
     71        sub-strings thereof.
     72
     73        * read.c (eval, do_define): Use cmd_prefix instead of '\t'.
     74
     75        * main.c: New global cmd_prefix, defaults to '\t'.
     76        * job.c (construct_command_argv_internal): Use cmd_prefix instead
     77        of '\t'.
     78
     79        * dir.c: Constified.
     80        (dir_contents_file_exists_p): Check for an error return from
     81        readdir(), just in case.
     82
     83        * commands.c: Constified.
     84        * default.c: Constified.
     85        * expand.c: Constified.
     86        * function.c: Partial constification.
     87        * variable.c: Partial constification.
     88        * vmsify.c: Constification.  Hard to test this but I hope I didn't
     89        screw it up!
     90        * vpath.c: Partial constification.
     91        * w32/pathstuff.c: Partial constification.
     92
     932006-11-16  Eli Zaretskii  <[email protected]>
     94
     95        * main.c (main) [HAVE_DOS_PATHS]: Treat DOS style argv[0] with
     96        backslashes and drive letters as absolute.
     97
     982006-10-22  Paul Smith  <[email protected]>
     99
     100        * main.c (struct command_switch): Use const and void*.
     101
     1022006-10-21  Paul Smith  <[email protected]>
     103
     104        * ar.c: Constified.
     105        * arscan.c: Constified.
     106
     1072006-09-30  Paul Smith  <[email protected]>
     108
     109        * doc/make.texi (MAKEFILE_LIST Variable): Modify reference to
     110        point to lastword since the example was updated.
     111        Fixes Savannah bug #16304.
     112        (Secondary Expansion): Correct example description.
     113        Fixes Savannah bug #16468.
     114        (Makefile Contents): Clarify that comments cannot appear within
     115        variable references or function calls.
     116        Fixes Savannah bug #16577.
     117        (Special Targets): Clarify how .NOTPARALLEL works in recursion.
     118        Fixes Savannah bug #17701.
     119        Reported by Ralf Wildenhues <[email protected]>:
     120        (Prerequisite Types): Added an example of using order-only
     121        prerequisites.  Fixes Savannah bug #17880.
     122        (Rule Syntax): "lise" -> "list"
     123        (Multiple Rules): ... -> @dots{}
     124        (Splitting Lines): ditto.
     125
     126        * remake.c (update_file_1): Prereqs that don't exist should be
     127        considered changed, for the purposes of $?.
     128        Fixes Savannah bug #16051.
     129
     130        * make.1: Remove extraneous "+".
     131        Fixes Savannah bug #16652.
     132
     1332006-09-06  Paul D. Smith  <[email protected]>
     134
     135        * configure.in: Include sys/types.h when checking for sys/wait.h.
     136
     1372006-08-18  Eli Zaretskii  <[email protected]>
     138
     139        * configure.in (PATH_SEPARATOR_CHAR): Define to the value of
     140        $PATH_SEPARATOR.
     141
     142        * make.h (PATH_SEPARATOR_CHAR): Define only if still undefined.
     143        Normally, it is defined in config.h.
     144
     145        * config/dospaths.m4 <ac_cv_dos_paths>: Define to yes on Cygwin as
     146        well.
     147
     148        * job.c (construct_command_argv_internal) [HAVE_DOS_PATHS]: Define
     149        sh_chars_sh for Windows platforms that emulate Unix.
     150
     1512006-05-07  Paul D. Smith  <[email protected]>
     152
     153        * README.OS2.template: Updates provided by Andreas Buening
     154        <[email protected]>.
     155
     1562006-04-30  Paul D. Smith  <[email protected]>
     157
     158        * make.h: Include <direct.h> if HAVE_DIRECT_H.
     159        * config.h.W32.template (HAVE_DIRECT_H): Set it if it's available.
     160
     1612006-04-26  Paul D. Smith  <[email protected]>
     162
     163        * README.cvs: Add a reminder to notify the GNU translation robot.
     164
     165        * doc/make.texi: Change @direcategory (requested by Karl Berry).
     166
     1672006-04-20  Paul D. Smith  <[email protected]>
     168
     169        * maintMakefile (po-check): Use Perl instead of grep -E, for systems
     170        that don't have extended grep.
     171        (cvsclean): Use $(PERL) instead of perl.
     172
     1732006-04-09  Paul D. Smith  <[email protected]>
     174
     175        * maintMakefile: Add some extra warning options (GCC 4.1 only?)
     176
     177        * expand.c, implicit.c, main.c, read.c: Rename variables so that
     178        inner-scope variables don't mask outer-scope variables.
     179
     180        * ar.c, arscan.c, commands.c, default.c, dir.c, expand.c, file.c:
     181        * function.c, getloadavg.c, implicit.c, job.c, main.c, misc.c, read.c:
     182        * remake.c, remote-cstms.c, rule.c, strcache.c, variable.c:
     183        * vmsfunctions.c, vmsify.c, vpath.c: Remove all casts of returned
     184        values from memory allocation functions: they return void* and so
     185        don't need to be cast.  Also remove (char *) casts of arguments to
     186        xrealloc().
     187
     188        * configure.in: Remove checks for memcpy/memmove/strchr.
     189
     190        * make.h: Remove bcmp/bcopy/bzero/strchr/strrchr macros.
     191
     192        * ar.c, arscan.c, commands.c, dir.c: Convert all bzero/bcopy/bcmp
     193        calls to memset/memcpy/memmove/memcmp calls.
     194        * expand.c, file.c, function.c, getloadavg.c, implicit.c: Ditto.
     195        * job.c, main.c, misc.c, read.c, remake.c, rule.c: Ditto.
     196        * variable.c, vpath.c: Ditto.
     197
     198        * make.h (EXIT_FAILURE): Should be 1, not 0.
     199
     2002006-04-06  Paul D. Smith  <[email protected]>
     201
     202        * configure.in: Removed AM_C_PROTOTYPES.  Starting now on we
     203        require an ISO C 1989 standard compiler and runtime library.
     204
     205        * Makefile.am: Remove the ansi2knr feature.
     206
     207        * make.h: Remove the PARAMS() macro definition and all uses of it.
     208
     209        * amiga.h, ar.c, arscan.c: Remove all uses of the PARAMS() macro.
     210        * commands.c, commands.h, config.h-vms.template: Ditto.
     211        * dep.h, dir.c, expand.c, filedef.h, function.c: Ditto.
     212        * implicit.c, job.c, job.h, main.c, read.c, remake.c: Ditto.
     213        * rule.c, rule.h, variable.h, vmsdir.h, vmsjobs.c, vpath.c: Ditto.
     214
     215        * NEWS: Update.
     216
    12172006-04-01  Paul D. Smith  <[email protected]>
    2218
     
    54270        (main): If we are re-execing, clean up the jobserver first so we
    55271        don't leak file descriptors.
    56         Fix bug reported by Craig Fithian <[email protected]>.
     272        Reported by Craig Fithian <[email protected]>
    57273
    582742006-03-17  Paul D. Smith  <[email protected]>
  • trunk/src/gmakenew/Makefile.am

    r503 r903  
    1717# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1818
    19 AUTOMAKE_OPTIONS = 1.8 dist-bzip2 check-news ansi2knr
     19AUTOMAKE_OPTIONS = 1.8 dist-bzip2 check-news
    2020ACLOCAL_AMFLAGS =  -I config
    2121
  • trunk/src/gmakenew/Makefile.kmk

    r864 r903  
    33
    44DEPTH = ../..
     5PATH_GNUMAKE_SRC = $(PATH_ROOT)/src/gmakenew
    56include $(PATH_KBUILD)/header.kmk
    67
     
    1314TEMPLATE_BIN-KMK_DEFS = HAVE_CONFIG_H $(TEMPLATE_BIN_DEFS)
    1415TEMPLATE_BIN-KMK_DEPS = $(PATH_TARGET)/config.h
     16TEMPLATE_BIN-KMK_CLEAN = $(TEMPLATE_BIN-KMK_DEPS)
    1517TEMPLATE_BIN-KMK_DEPS.solaris = \
    1618        $(PATH_TARGET)/fts.h \
    1719        $(PATH_TARGET)/paths.h
     20TEMPLATE_BIN-KMK_CLEAN.solaris = $(TEMPLATE_BIN-KMK_DEPS.solaris)
    1821TEMPLATE_BIN-KMK_DEPS.win     = \
    1922        $(PATH_TARGET)/fts.h \
     
    2427        $(PATH_TARGET)/pwd.h \
    2528        $(PATH_TARGET)/inttypes.h
     29TEMPLATE_BIN-KMK_CLEAN.win = $(TEMPLATE_BIN-KMK_DEPS.win)
    2630TEMPLATE_BIN-KMK_INCS = $(PATH_TARGET) . $(TEMPLATE_BIN_INCS)
    2731TEMPLATE_BIN-KMK_INCS.darwin = glob
     
    98102        CONFIG_WITH_INCLUDEDEP \
    99103        CONFIG_WITH_VALUE_LENGTH \
     104        CONFIG_WITH_RSORT \
    100105        CONFIG_WITH_ABSPATHEX \
    101106        CONFIG_WITH_COMPARE \
     
    266271#
    267272config.h.$(BUILD_TARGET) := config.h.$(BUILD_TARGET)
    268 config.h.win   := config.h.W32
    269 
    270273$(PATH_TARGET)/config.h: $(config.h.$(BUILD_TARGET))
    271274        $(MKDIR) -p $(dir $@)
  • trunk/src/gmakenew/NEWS

    r503 r903  
    99See the README file and the GNU make manual for instructions for
    1010reporting bugs.
     11
     12
     13Version 3.81.90
     14
     15* Compiling GNU make now requires a conforming ISO C 1989 compiler and
     16  standard runtime library.
     17
    1118
    1219
  • trunk/src/gmakenew/acinclude.m4

    r503 r903  
    6363AC_CHECK_FUNCS(gethostbyname,,[
    6464        CF_RECHECK_FUNC(gethostbyname,nsl,cf_cv_netlibs)])
    65 #
    66 AC_CHECK_FUNCS(strcasecmp,,[
    67         CF_RECHECK_FUNC(strcasecmp,resolv,cf_cv_netlibs)])
    6865])
    6966LIBS="$LIBS $cf_cv_netlibs"
  • trunk/src/gmakenew/amiga.h

    r503 r903  
    1616Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.  */
    1717
    18 extern int MyExecute PARAMS ((char ** argv));
    19 extern char * wildcard_expansion PARAMS ((char * wc, char * o));
    20 
     18int MyExecute (char ** argv);
     19char * wildcard_expansion (char * wc, char * o);
  • trunk/src/gmakenew/ar.c

    r503 r903  
    2525#include <fnmatch.h>
    2626
    27 /* Defined in arscan.c.  */
    28 extern long int ar_scan PARAMS ((char *archive, long int (*function) (), long int arg));
    29 extern int ar_name_equal PARAMS ((char *name, char *mem, int truncated));
    30 #ifndef VMS
    31 extern int ar_member_touch PARAMS ((char *arname, char *memname));
    32 #endif
    33 
    3427/* Return nonzero if NAME is an archive-member reference, zero if not.
    3528   An archive-member reference is a name like `lib(member)'.
     
    3831
    3932int
    40 ar_name (char *name)
    41 {
    42   char *p = strchr (name, '(');
    43   char *end;
     33ar_name (const char *name)
     34{
     35  const char *p = strchr (name, '(');
     36  const char *end;
    4437
    4538  if (p == 0 || p == name)
     
    5851
    5952/* Parse the archive-member reference NAME into the archive and member names.
    60    Put the malloc'd archive name in *ARNAME_P if ARNAME_P is non-nil;
    61    put the malloc'd member name in *MEMNAME_P if MEMNAME_P is non-nil.  */
     53   Creates one allocated string containing both names, pointed to by ARNAME_P.
     54   MEMNAME_P points to the member.  */
    6255
    6356void
    64 ar_parse_name (char *name, char **arname_p, char **memname_p)
    65 {
    66   char *p = strchr (name, '('), *end = name + strlen (name) - 1;
    67 
    68   if (arname_p != 0)
    69     *arname_p = savestring (name, p - name);
    70 
    71   if (memname_p != 0)
    72     *memname_p = savestring (p + 1, end - (p + 1));
    73 }
    74 
    75 
    76 static long int ar_member_date_1 PARAMS ((int desc, char *mem, int truncated, long int hdrpos,
    77         long int datapos, long int size, long int date, int uid, int gid, int mode, char *name));
     57ar_parse_name (const char *name, char **arname_p, char **memname_p)
     58{
     59  char *p;
     60
     61  *arname_p = xstrdup (name);
     62  p = strchr (*arname_p, '(');
     63  *(p++) = '\0';
     64  p[strlen(p) - 1] = '\0';
     65  *memname_p = p;
     66}
     67
     68
     69
     70/* This function is called by `ar_scan' to find which member to look at.  */
     71
     72/* ARGSUSED */
     73static long int
     74ar_member_date_1 (int desc UNUSED, const char *mem, int truncated,
     75                  long int hdrpos UNUSED, long int datapos UNUSED,
     76                  long int size UNUSED, long int date,
     77                  int uid UNUSED, int gid UNUSED, int mode UNUSED,
     78                  const void *name)
     79{
     80  return ar_name_equal (name, mem, truncated) ? date : 0;
     81}
    7882
    7983/* Return the modtime of NAME.  */
    8084
    8185time_t
    82 ar_member_date (char *name)
     86ar_member_date (const char *name)
    8387{
    8488  char *arname;
    85   int arname_used = 0;
    8689  char *memname;
    8790  long int val;
     
    100103    arfile = lookup_file (arname);
    101104    if (arfile == 0 && file_exists_p (arname))
    102       {
    103         arfile = enter_file (arname);
    104         arname_used = 1;
    105       }
     105      arfile = enter_file (strcache_add (arname));
    106106
    107107    if (arfile != 0)
     
    109109  }
    110110
    111   val = ar_scan (arname, ar_member_date_1, (long int) memname);
    112 
    113   if (!arname_used)
    114     free (arname);
    115   free (memname);
     111  val = ar_scan (arname, ar_member_date_1, memname);
     112
     113  free (arname);
    116114
    117115  return (val <= 0 ? (time_t) -1 : (time_t) val);
    118 }
    119 
    120 /* This function is called by `ar_scan' to find which member to look at.  */
    121 
    122 /* ARGSUSED */
    123 static long int
    124 ar_member_date_1 (int desc UNUSED, char *mem, int truncated,
    125                   long int hdrpos UNUSED, long int datapos UNUSED,
    126                   long int size UNUSED, long int date,
    127                   int uid UNUSED, int gid UNUSED, int mode UNUSED, char *name)
    128 {
    129   return ar_name_equal (name, mem, truncated) ? date : 0;
    130116}
    131117
     
    135121#ifdef VMS
    136122int
    137 ar_touch (char *name)
     123ar_touch (const char *name)
    138124{
    139125  error (NILF, _("touch archive member is not available on VMS"));
     
    142128#else
    143129int
    144 ar_touch (char *name)
     130ar_touch (const char *name)
    145131{
    146132  char *arname, *memname;
    147   int arname_used = 0;
    148   register int val;
     133  int val;
    149134
    150135  ar_parse_name (name, &arname, &memname);
    151136
    152137  /* Make sure we know the modtime of the archive itself before we
    153      touch the member, since this will change the archive itself.  */
     138     touch the member, since this will change the archive modtime.  */
    154139  {
    155140    struct file *arfile;
    156     arfile = lookup_file (arname);
    157     if (arfile == 0)
    158       {
    159         arfile = enter_file (arname);
    160         arname_used = 1;
    161       }
    162 
    163     (void) f_mtime (arfile, 0);
     141    arfile = enter_file (strcache_add (arname));
     142    f_mtime (arfile, 0);
    164143  }
    165144
     
    188167    }
    189168
    190   if (!arname_used)
    191     free (arname);
    192   free (memname);
     169  free (arname);
    193170
    194171  return val;
     
    201178struct ar_glob_state
    202179  {
    203     char *arname;
    204     char *pattern;
     180    const char *arname;
     181    const char *pattern;
    205182    unsigned int size;
    206183    struct nameseq *chain;
     
    212189
    213190static long int
    214 ar_glob_match (int desc UNUSED, char *mem, int truncated UNUSED,
     191ar_glob_match (int desc UNUSED, const char *mem, int truncated UNUSED,
    215192               long int hdrpos UNUSED, long int datapos UNUSED,
    216193               long int size UNUSED, long int date UNUSED, int uid UNUSED,
    217                int gid UNUSED, int mode UNUSED, struct ar_glob_state *state)
    218 {
     194               int gid UNUSED, int mode UNUSED, const void *arg)
     195{
     196  struct ar_glob_state *state = (struct ar_glob_state *)arg;
     197
    219198  if (fnmatch (state->pattern, mem, FNM_PATHNAME|FNM_PERIOD) == 0)
    220199    {
    221200      /* We have a match.  Add it to the chain.  */
    222       struct nameseq *new = (struct nameseq *) xmalloc (state->size);
    223       new->name = concat (state->arname, mem, ")");
     201      struct nameseq *new = xmalloc (state->size);
     202      new->name = strcache_add (concat (state->arname, mem, ")"));
    224203      new->next = state->chain;
    225204      state->chain = new;
     
    267246
    268247struct nameseq *
    269 ar_glob (char *arname, char *member_pattern, unsigned int size)
     248ar_glob (const char *arname, const char *member_pattern, unsigned int size)
    270249{
    271250  struct ar_glob_state state;
    272   char **names;
    273251  struct nameseq *n;
     252  const char **names;
     253  char *name;
    274254  unsigned int i;
    275255
     
    280260     ar_glob_match will accumulate them in STATE.chain.  */
    281261  i = strlen (arname);
    282   state.arname = (char *) alloca (i + 2);
    283   bcopy (arname, state.arname, i);
    284   state.arname[i] = '(';
    285   state.arname[i + 1] = '\0';
     262  name = alloca (i + 2);
     263  memcpy (name, arname, i);
     264  name[i] = '(';
     265  name[i + 1] = '\0';
     266  state.arname = name;
    286267  state.pattern = member_pattern;
    287268  state.size = size;
    288269  state.chain = 0;
    289270  state.n = 0;
    290   (void) ar_scan (arname, ar_glob_match, (long int) &state);
     271  ar_scan (arname, ar_glob_match, &state);
    291272
    292273  if (state.chain == 0)
     
    294275
    295276  /* Now put the names into a vector for sorting.  */
    296   names = (char **) alloca (state.n * sizeof (char *));
     277  names = alloca (state.n * sizeof (const char *));
    297278  i = 0;
    298279  for (n = state.chain; n != 0; n = n->next)
     
    300281
    301282  /* Sort them alphabetically.  */
    302   qsort ((char *) names, i, sizeof (*names), alpha_compare);
     283  qsort (names, i, sizeof (*names), alpha_compare);
    303284
    304285  /* Put them back into the chain in the sorted order.  */
  • trunk/src/gmakenew/arscan.c

    r503 r903  
    2626
    2727#ifndef NO_ARCHIVES
    28 
    2928
    3029#ifdef VMS
     
    136135
    137136long int
    138 ar_scan (char *archive, long int (*function) PARAMS ((void)), long int arg)
     137ar_scan (const char *archive, ar_member_func_t function, const void *arg)
    139138{
    140139  char *p;
     
    304303
    305304long int
    306 ar_scan (char *archive, long int (*function)(), long int arg)
     305ar_scan (const char *archive, ar_member_func_t function, const void *arg)
    307306{
    308307#ifdef AIAMAG
     
    316315#endif
    317316  char *namemap = 0;
    318   register int desc = open (archive, O_RDONLY, 0);
     317  int desc = open (archive, O_RDONLY, 0);
    319318  if (desc < 0)
    320319    return -1;
     
    323322    char buf[SARMAG];
    324323    register int nread = read (desc, buf, SARMAG);
    325     if (nread != SARMAG || bcmp (buf, ARMAG, SARMAG))
     324    if (nread != SARMAG || memcmp (buf, ARMAG, SARMAG))
    326325      {
    327326        (void) close (desc);
     
    332331#ifdef AIAMAG
    333332  {
    334     register int nread = read (desc, (char *) &fl_header, FL_HSZ);
     333    register int nread = read (desc, &fl_header, FL_HSZ);
    335334
    336335    if (nread != FL_HSZ)
     
    342341    /* If this is a "big" archive, then set the flag and
    343342       re-read the header into the "big" structure. */
    344     if (!bcmp (fl_header.fl_magic, AIAMAGBIG, SAIAMAG))
     343    if (!memcmp (fl_header.fl_magic, AIAMAGBIG, SAIAMAG))
    345344      {
    346345        big_archive = 1;
     
    354353
    355354        /* re-read the header into the "big" structure */
    356         nread = read (desc, (char *) &fl_header_big, FL_HSZ_BIG);
     355        nread = read (desc, &fl_header_big, FL_HSZ_BIG);
    357356        if (nread != FL_HSZ_BIG)
    358357          {
     
    364363#endif
    365364       /* Check to make sure this is a "normal" archive. */
    366       if (bcmp (fl_header.fl_magic, AIAMAG, SAIAMAG))
     365      if (memcmp (fl_header.fl_magic, AIAMAG, SAIAMAG))
    367366        {
    368367          (void) close (desc);
     
    458457        if (big_archive)
    459458          {
    460             nread = read (desc, (char *) &member_header_big,
     459            nread = read (desc, &member_header_big,
    461460                          AR_MEMHDR_SZ(member_header_big) );
    462461
     
    490489#endif
    491490          {
    492             nread = read (desc, (char *) &member_header,
     491            nread = read (desc, &member_header,
    493492                          AR_MEMHDR_SZ(member_header) );
    494493
     
    528527
    529528#else   /* Not AIAMAG.  */
    530         nread = read (desc, (char *) &member_header, AR_HDR_SIZE);
     529        nread = read (desc, &member_header, AR_HDR_SIZE);
    531530        if (nread == 0)
    532531          /* No data left means end of file; that is OK.  */
     
    537536            || (
    538537# ifdef ARFMAG
    539                 bcmp (member_header.ar_fmag, ARFMAG, 2)
     538                memcmp (member_header.ar_fmag, ARFMAG, 2)
    540539# else
    541540                1
     
    543542                &&
    544543# ifdef ARFZMAG
    545                 bcmp (member_header.ar_fmag, ARFZMAG, 2)
     544                memcmp (member_header.ar_fmag, ARFZMAG, 2)
    546545# else
    547546                1
     
    556555
    557556        name = namebuf;
    558         bcopy (member_header.ar_name, name, sizeof member_header.ar_name);
     557        memcpy (name, member_header.ar_name, sizeof member_header.ar_name);
    559558        {
    560559          register char *p = name + sizeof member_header.ar_name;
     
    596595              int namesize = atoi (name + 3);
    597596
    598               name = (char *) alloca (namesize + 1);
     597              name = alloca (namesize + 1);
    599598              nread = read (desc, name, namesize);
    600599              if (nread != namesize)
     
    667666            char *limit;
    668667
    669             namemap = (char *) alloca (eltsize);
     668            namemap = alloca (eltsize);
    670669            nread = read (desc, namemap, eltsize);
    671670            if (nread != eltsize)
     
    710709
    711710int
    712 ar_name_equal (char *name, char *mem, int truncated)
     711ar_name_equal (const char *name, const char *mem, int truncated)
    713712{
    714   char *p;
     713  const char *p;
    715714
    716715  p = strrchr (name, '/');
     
    742741/* ARGSUSED */
    743742static long int
    744 ar_member_pos (int desc UNUSED, char *mem, int truncated,
     743ar_member_pos (int desc UNUSED, const char *mem, int truncated,
    745744               long int hdrpos, long int datapos UNUSED, long int size UNUSED,
    746745               long int date UNUSED, int uid UNUSED, int gid UNUSED,
    747                int mode UNUSED, char *name)
     746               int mode UNUSED, const void *name)
    748747{
    749748  if (!ar_name_equal (name, mem, truncated))
     
    760759
    761760int
    762 ar_member_touch (char *arname, char *memname)
     761ar_member_touch (const char *arname, const char *memname)
    763762{
    764   long int pos = ar_scan (arname, ar_member_pos, (long int) memname);
     763  long int pos = ar_scan (arname, ar_member_pos, memname);
    765764  int fd;
    766765  struct ar_hdr ar_hdr;
     
    780779  if (lseek (fd, pos, 0) < 0)
    781780    goto lose;
    782   if (AR_HDR_SIZE != read (fd, (char *) &ar_hdr, AR_HDR_SIZE))
     781  if (AR_HDR_SIZE != read (fd, &ar_hdr, AR_HDR_SIZE))
    783782    goto lose;
    784783  /* Write back the header, thus touching the archive file.  */
    785784  if (lseek (fd, pos, 0) < 0)
    786785    goto lose;
    787   if (AR_HDR_SIZE != write (fd, (char *) &ar_hdr, AR_HDR_SIZE))
     786  if (AR_HDR_SIZE != write (fd, &ar_hdr, AR_HDR_SIZE))
    788787    goto lose;
    789788  /* The file's mtime is the time we we want.  */
     
    805804  if (lseek (fd, pos, 0) < 0)
    806805    goto lose;
    807   if (AR_HDR_SIZE != write (fd, (char *) &ar_hdr, AR_HDR_SIZE))
     806  if (AR_HDR_SIZE != write (fd, &ar_hdr, AR_HDR_SIZE))
    808807    goto lose;
    809808  close (fd);
     
    822821
    823822long int
    824 describe_member (int desc, char *name, int truncated,
     823describe_member (int desc, const char *name, int truncated,
    825824                 long int hdrpos, long int datapos, long int size,
    826                  long int date, int uid, int gid, int mode)
     825                 long int date, int uid, int gid, int mode, const void *arg)
    827826{
    828827  extern char *ctime ();
     
    840839main (int argc, char **argv)
    841840{
    842   ar_scan (argv[1], describe_member);
     841  ar_scan (argv[1], describe_member, NULL);
    843842  return 0;
    844843}
  • trunk/src/gmakenew/commands.c

    r778 r903  
    3434#endif
    3535
    36 extern int remote_kill PARAMS ((int id, int sig));
     36int remote_kill (int id, int sig);
    3737
    3838#ifndef HAVE_UNISTD_H
    39 extern int getpid ();
     39int getpid ();
    4040#endif
    4141
     
    4646set_file_variables (struct file *file)
    4747{
    48   struct dep *d;
    49   char *at, *percent, *star, *less;
     48  const struct dep *d;
     49  const char *at, *percent, *star, *less;
    5050
    5151#ifndef NO_ARCHIVES
     
    5656    {
    5757      unsigned int len;
     58      const char *cp;
    5859      char *p;
    5960
    60       p = strchr (file->name, '(');
    61       at = (char *) alloca (p - file->name + 1);
    62       bcopy (file->name, at, p - file->name);
    63       at[p - file->name] = '\0';
    64       len = strlen (p + 1);
    65       percent = (char *) alloca (len);
    66       bcopy (p + 1, percent, len - 1);
    67       percent[len - 1] = '\0';
     61      cp = strchr (file->name, '(');
     62      p = alloca (cp - file->name + 1);
     63      memcpy (p, file->name, cp - file->name);
     64      p[cp - file->name] = '\0';
     65      at = p;
     66      len = strlen (cp + 1);
     67      p = alloca (len);
     68      memcpy (p, cp + 1, len - 1);
     69      p[len - 1] = '\0';
     70      percent = p;
    6871    }
    6972  else
     
    8083         any suffix in the .SUFFIXES list stripped off for
    8184         explicit rules.  We store this in the `stem' member.  */
    82       register struct dep *d;
    83       char *name;
     85      const char *name;
    8486      unsigned int len;
    8587
     
    9799        }
    98100
    99       for (d = enter_file (".SUFFIXES")->deps; d != 0; d = d->next)
     101      for (d = enter_file (strcache_add (".SUFFIXES"))->deps; d ; d = d->next)
    100102        {
    101103          unsigned int slen = strlen (dep_name (d));
    102104          if (len > slen && strneq (dep_name (d), name + (len - slen), slen))
    103105            {
    104               file->stem = savestring (name, len - slen);
     106              file->stem = strcache_add_len (name, len - slen);
    105107              break;
    106108            }
     
    139141  {
    140142    static char *plus_value=0, *bar_value=0, *qmark_value=0;
    141     static unsigned int qmark_max=0, plus_max=0, bar_max=0;
     143    static unsigned int plus_max=0, bar_max=0, qmark_max=0;
    142144
    143145    unsigned int qmark_len, plus_len, bar_len;
     
    166168      if (! d->ignore_mtime)
    167169        {
    168           char *c = dep_name (d);
     170          const char *c = dep_name (d);
    169171
    170172#ifndef NO_ARCHIVES
     
    178180            len = strlen (c);
    179181
    180           bcopy (c, cp, len);
     182          memcpy (cp, c, len);
    181183          cp += len;
    182184          *cp++ = FILE_LIST_SEPARATOR;
     
    217219    for (d = file->deps; d != 0; d = d->next)
    218220      {
    219         char *c = dep_name (d);
     221        const char *c = dep_name (d);
    220222
    221223#ifndef NO_ARCHIVES
     
    231233        if (d->ignore_mtime)
    232234          {
    233             bcopy (c, bp, len);
     235            memcpy (bp, c, len);
    234236            bp += len;
    235237            *bp++ = FILE_LIST_SEPARATOR;
     
    237239        else
    238240          {
    239             bcopy (c, cp, len);
     241            memcpy (cp, c, len);
    240242            cp += len;
    241243            *cp++ = FILE_LIST_SEPARATOR;
    242244            if (d->changed)
    243245              {
    244                 bcopy (c, qp, len);
     246                memcpy (qp, c, len);
    245247                qp += len;
    246248                *qp++ = FILE_LIST_SEPARATOR;
     
    271273chop_commands (struct commands *cmds)
    272274{
    273   register char *p;
     275  const char *p;
    274276  unsigned int nlines, idx;
    275277  char **lines;
     
    286288
    287289  nlines = 5;
    288   lines = (char **) xmalloc (5 * sizeof (char *));
     290  lines = xmalloc (5 * sizeof (char *));
    289291  idx = 0;
    290292  p = cmds->commands;
    291293  while (*p != '\0')
    292294    {
    293       char *end = p;
     295      const char *end = p;
    294296    find_end:;
    295297      end = strchr (end, '\n');
     
    299301        {
    300302          int backslash = 1;
    301           register char *b;
     303          const char *b;
    302304          for (b = end - 2; b >= p && *b == '\\'; --b)
    303305            backslash = !backslash;
     
    312314        {
    313315          nlines += 2;
    314           lines = (char **) xrealloc ((char *) lines,
    315                                       nlines * sizeof (char *));
     316          lines = xrealloc (lines, nlines * sizeof (char *));
    316317        }
    317318      lines[idx++] = savestring (p, end - p);
     
    324325    {
    325326      nlines = idx;
    326       lines = (char **) xrealloc ((char *) lines,
    327                                   nlines * sizeof (char *));
     327      lines = xrealloc (lines, nlines * sizeof (char *));
    328328    }
    329329
     
    332332
    333333  cmds->any_recurse = 0;
    334   cmds->lines_flags = (char *) xmalloc (nlines);
     334  cmds->lines_flags = xmalloc (nlines);
    335335  for (idx = 0; idx < nlines; ++idx)
    336336    {
     
    382382execute_file_commands (struct file *file)
    383383{
    384   register char *p;
     384  const char *p;
    385385
    386386  /* Don't go through all the preparations if
     
    474474  if (sig == SIGTERM)
    475475    {
    476       register struct child *c;
     476      struct child *c;
    477477      for (c = children; c != 0; c = c->next)
    478478        if (!c->remote)
     
    492492    )
    493493    {
    494       register struct child *c;
     494      struct child *c;
    495495
    496496      /* Remote children won't automatically get signals sent
     
    546546
    547547static void
    548 delete_target (struct file *file, char *on_behalf_of)
     548delete_target (struct file *file, const char *on_behalf_of)
    549549{
    550550  struct stat st;
     
    601601
    602602  /* Delete the target file if it changed.  */
    603   delete_target (child->file, (char *) 0);
     603  delete_target (child->file, NULL);
    604604
    605605  /* Also remove any non-precious targets listed in the `also_make' member.  */
     
    614614
    615615void
    616 print_commands (struct commands *cmds)
     616print_commands (const struct commands *cmds)
    617617{
    618   register char *s;
     618  const char *s;
    619619
    620620  fputs (_("#  commands to execute"), stdout);
     
    629629  while (*s != '\0')
    630630    {
    631       char *end;
     631      const char *end;
    632632
    633633      while (isspace ((unsigned char)*s))
  • trunk/src/gmakenew/commands.h

    r520 r903  
    4343#endif
    4444
    45 extern void execute_file_commands PARAMS ((struct file *file));
    46 extern void print_commands PARAMS ((struct commands *cmds));
    47 extern void delete_child_targets PARAMS ((struct child *child));
    48 extern void chop_commands PARAMS ((struct commands *cmds));
    49 extern void set_file_variables PARAMS ((struct file *file));
     45void execute_file_commands (struct file *file);
     46void print_commands (const struct commands *cmds);
     47void delete_child_targets (struct child *child);
     48void chop_commands (struct commands *cmds);
     49void set_file_variables (struct file *file);
  • trunk/src/gmakenew/config.h.W32.template

    r902 r903  
    241241
    242242/* Define to 1 if you have the `strdup' function. */
    243 /* #define HAVE_STRDUP 1*/
     243#define HAVE_STRDUP 1 /* bird */
    244244
    245245/* Define to 1 if you have the `strerror' function. */
  • trunk/src/gmakenew/config/dospaths.m4

    r503 r903  
    2323      [
    2424        AC_COMPILE_IFELSE([
    25 #if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__ && !defined __EMX__ && !defined __MSYS__
     25#if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__ && !defined __EMX__ && !defined __MSYS__ && !defined __CYGWIN__
    2626neither MSDOS nor Windows nor OS2
    2727#endif
  • trunk/src/gmakenew/configure.in

    r503 r903  
    1717# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1818
    19 AC_INIT([GNU make],[3.81],[[email protected]])
     19AC_INIT([GNU make],[3.81.90],[[email protected]])
    2020
    2121AC_PREREQ(2.59)
    22 AC_REVISION([[$Id: configure.in,v 1.142 2006/04/01 06:36:40 psmith Exp $]])
     22AC_REVISION([[$Id: configure.in,v 1.147 2007/05/09 02:01:53 psmith Exp $]])
    2323
    2424# Autoconf setup
     
    4545AC_MINIX
    4646
    47 # Needed for ansi2knr
    48 AM_C_PROTOTYPES
    49 
    5047# Enable gettext, in "external" mode.
    5148
     
    7269if test "$ac_cv_prog_cc_stdc" != no; then
    7370  AC_DEFINE(HAVE_ANSI_COMPILER, 1,
    74               [Define if your compiler conforms to the ANSI C standard.])
     71              [Define to 1 if your compiler conforms to the ANSI C standard.])
    7572fi
    7673
     
    123120  if test "$ac_cv_search_clock_gettime" != no; then
    124121    AC_DEFINE(HAVE_CLOCK_GETTIME, 1,
    125               [Define if you have the clock_gettime function.])
     122              [Define to 1 if you have the clock_gettime function.])
    126123  fi
    127124fi
     
    147144if test "$ac_cv_func_gettimeofday" = yes; then
    148145  AC_DEFINE(HAVE_GETTIMEOFDAY, 1,
    149             [Define if you have a standard gettimeofday function])
    150 fi
    151 
    152 AC_CHECK_FUNCS( memcpy memmove strchr strdup mkstemp mktemp fdopen \
     146            [Define to 1 if you have a standard gettimeofday function])
     147fi
     148
     149AC_CHECK_FUNCS( strdup mkstemp mktemp fdopen \
    153150                bsd_signal dup2 getcwd realpath sigsetmask sigaction \
    154151                getgroups seteuid setegid setlinebuf setreuid setregid \
     
    157154
    158155AC_FUNC_SETVBUF_REVERSED
     156
     157# Rumor has it that strcasecmp lives in -lresolv on some odd systems.
     158# It doesn't hurt much to use our own if we can't find it so I don't
     159# make the effort here.
     160AC_CHECK_FUNCS(strcasecmp strcmpi stricmp)
    159161
    160162# strcoll() is used by the GNU glob library
     
    180182  if test "$make_cv_nlist_struct" = yes; then
    181183    AC_DEFINE(NLIST_STRUCT, 1,
    182        [Define if struct nlist.n_name is a pointer rather than an array.])
     184       [Define to 1 if struct nlist.n_name is a pointer rather than an array.])
    183185  fi
    184186fi
     
    195197
    196198# Check out the wait reality.
    197 AC_CHECK_HEADERS(sys/wait.h)
     199AC_CHECK_HEADERS(sys/wait.h,,,[[#include <sys/types.h>]])
    198200AC_CHECK_FUNCS(waitpid wait3)
    199201AC_MSG_CHECKING(for union wait)
     
    221223if test "$make_cv_union_wait" = yes; then
    222224  AC_DEFINE(HAVE_UNION_WAIT, 1,
    223             [Define this if you have the \`union wait' type in <sys/wait.h>.])
     225            [Define to 1 if you have the \`union wait' type in <sys/wait.h>.])
    224226fi
    225227AC_MSG_RESULT($make_cv_union_wait)
     
    229231if test "$PATH_SEPARATOR" = ';'; then
    230232  AC_DEFINE(HAVE_DOS_PATHS, 1,
    231             [Define this if your system requires backslashes or drive specs in pathnames.])
     233            [Define to 1 if your system requires backslashes or drive specs in pathnames.])
    232234fi
    233235
     
    265267AC_ARG_ENABLE(case-insensitive-file-system,
    266268  AC_HELP_STRING([--enable-case-insensitive-file-system],
    267                  [enable case insensitive file system support]),
    268   case_insensitive_fs="yes" AC_DEFINE(HAVE_CASE_INSENSITIVE_FS),
    269   case_insensitive_fs="no")
     269                 [assume file systems are case insensitive]),
     270  [case $enableval in
     271     yes) AC_DEFINE(HAVE_CASE_INSENSITIVE_FS) ;;
     272   esac])
    270273
    271274# See if we can handle the job server feature, and if the user wants it.
     
    290293if test "$make_cv_sa_restart" != no; then
    291294  AC_DEFINE(HAVE_SA_RESTART, 1,
    292      [Define if <signal.h> defines the SA_RESTART constant.])
     295     [Define to 1 if <signal.h> defines the SA_RESTART constant.])
    293296fi
    294297
     
    302305  yes/yes/yes/yes/yes)
    303306    AC_DEFINE(MAKE_JOBSERVER, 1,
    304               [Define this to enable job server support in GNU make.]);;
     307              [Define to 1 to enable job server support in GNU make.]);;
    305308esac
    306309
     
    310313  yes/yes)
    311314    AC_DEFINE(MAKE_SYMLINKS, 1,
    312               [Define this to enable symbolic link timestamp checking.]);;
     315              [Define to 1 to enable symbolic link timestamp checking.]);;
    313316esac
    314317
     
    337340  case "$make_cv_sys_get_minus_G" in
    338341    yes) AC_DEFINE(SCCS_GET_MINUS_G, 1,
    339            [Define this if the SCCS 'get' command understands the '-G<file>' option.]);;
     342           [Define to 1 if the SCCS 'get' command understands the '-G<file>' option.]);;
    340343  esac
    341344fi
     
    385388esac
    386389
     390AC_DEFINE_UNQUOTED(PATH_SEPARATOR_CHAR,'$PATH_SEPARATOR',[Define to the character that separates directories in PATH.])
     391
    387392# Include the Maintainer's Makefile section, if it's here.
    388393
  • trunk/src/gmakenew/default.c

    r503 r903  
    4343.w .ch .cweb .web .com .sh .elc .el";
    4444#elif defined(__EMX__)
    45   = ".out .a .ln .o .c .cc .C .cpp .p .f .F .r .y .l .s .S \
     45  = ".out .a .ln .o .c .cc .C .cpp .p .f .F .m .r .y .l .ym .yl .s .S \
    4646.mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo \
    4747.w .ch .web .sh .elc .el .obj .exe .dll .lib";
    4848#else
    49   = ".out .a .ln .o .c .cc .C .cpp .p .f .F .r .y .l .s .S \
     49  = ".out .a .ln .o .c .cc .C .cpp .p .f .F .m .r .y .l .ym .yl .s .S \
    5050.mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo \
    5151.w .ch .web .sh .elc .el";
     
    201201    ".f",
    202202    "$(LINK.f) $^ $(LOADLIBES) $(LDLIBS) -o $@",
     203    ".m",
     204    "$(LINK.m) $^ $(LOADLIBES) $(LDLIBS) -o $@",
    203205    ".p",
    204206    "$(LINK.p) $^ $(LOADLIBES) $(LDLIBS) -o $@",
     
    230232    ".f.o",
    231233    "$(COMPILE.f) $(OUTPUT_OPTION) $<",
     234    ".m.o",
     235    "$(COMPILE.m) $(OUTPUT_OPTION) $<",
    232236    ".p.o",
    233237    "$(COMPILE.p) $(OUTPUT_OPTION) $<",
     
    258262    ".l.c",
    259263    "@$(RM) $@ \n $(LEX.l) $< > $@",
     264    ".ym.m",
     265    "$(YACC.m) $< \n mv -f y.tab.c $@",
     266    ".lm.m",
     267    "@$(RM) $@ \n $(LEX.m) $< > $@",
    260268
    261269    ".F.f",
     
    264272    "$(PREPROCESS.r) $(OUTPUT_OPTION) $<",
    265273
    266     /* This might actually make lex.yy.c if there's no %R%
    267        directive in $*.l, but in that case why were you
    268        trying to make $*.r anyway?  */
     274    /* This might actually make lex.yy.c if there's no %R% directive in $*.l,
     275       but in that case why were you trying to make $*.r anyway?  */
    269276    ".l.r",
    270277    "$(LEX.l) $< > $@ \n mv -f lex.yy.r $@",
     
    311318  };
    312319
    313 static char *default_variables[] =
     320static const char *default_variables[] =
    314321  {
    315322#ifndef CONFIG_NO_DEFAULT_VARIABLES
     
    408415    "CXX", "gcc",
    409416# endif /* __MSDOS__ */
     417    "OBJC", "gcc",
    410418#else
    411419    "CC", "cc",
    412420    "CXX", "g++",
     421    "OBJC", "cc",
    413422#endif
    414423
     
    478487    "COMPILE.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
    479488    "LINK.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
     489    "COMPILE.m", "$(OBJC) $(OBJCFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
     490    "LINK.m", "$(OBJC) $(OBJCFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
    480491    "COMPILE.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
    481492    "COMPILE.C", "$(COMPILE.cc)",
     
    486497    "YACC.y", "$(YACC) $(YFLAGS)",
    487498    "LEX.l", "$(LEX) $(LFLAGS) -t",
     499    "YACC.m", "$(YACC) $(YFLAGS)",
     500    "LEX.m", "$(LEX) $(LFLAGS) -t",
    488501    "COMPILE.f", "$(FC) $(FFLAGS) $(TARGET_ARCH) -c",
    489502    "LINK.f", "$(FC) $(FFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
     
    534547set_default_suffixes (void)
    535548{
    536   suffix_file = enter_file (".SUFFIXES");
     549  suffix_file = enter_file (strcache_add (".SUFFIXES"));
    537550
    538551  if (no_builtin_rules_flag)
    539     (void) define_variable ("SUFFIXES", 8, "", o_default, 0);
     552    define_variable ("SUFFIXES", 8, "", o_default, 0);
    540553  else
    541554    {
     
    544557        multi_glob (parse_file_seq (&p, '\0', sizeof (struct dep), 1),
    545558                    sizeof (struct dep));
    546       (void) define_variable ("SUFFIXES", 8, default_suffixes, o_default, 0);
     559      define_variable ("SUFFIXES", 8, default_suffixes, o_default, 0);
    547560    }
    548561}
     
    550563/* Enter the default suffix rules as file rules.  This used to be done in
    551564   install_default_implicit_rules, but that loses because we want the
    552    suffix rules installed before reading makefiles, and thee pattern rules
     565   suffix rules installed before reading makefiles, and the pattern rules
    553566   installed after.  */
    554567
     
    556569install_default_suffix_rules (void)
    557570{
    558   register char **s;
     571  char **s;
    559572
    560573  if (no_builtin_rules_flag)
    561574    return;
    562575
    563  for (s = default_suffix_rules; *s != 0; s += 2)
     576  for (s = default_suffix_rules; *s != 0; s += 2)
    564577    {
    565       register struct file *f = enter_file (s[0]);
     578      struct file *f = enter_file (strcache_add (s[0]));
    566579      /* Don't clobber cmds given in a makefile if there were any.  */
    567580      if (f->cmds == 0)
    568581        {
    569           f->cmds = (struct commands *) xmalloc (sizeof (struct commands));
     582          f->cmds = xmalloc (sizeof (struct commands));
    570583          f->cmds->fileinfo.filenm = 0;
    571584          f->cmds->commands = s[1];
     
    581594install_default_implicit_rules (void)
    582595{
    583   register struct pspec *p;
     596  struct pspec *p;
    584597
    585598  if (no_builtin_rules_flag)
     
    596609define_default_variables (void)
    597610{
    598   register char **s;
     611  const char **s;
    599612
    600613  if (no_builtin_variables_flag)
     
    602615
    603616  for (s = default_variables; *s != 0; s += 2)
    604     (void) define_variable (s[0], strlen (s[0]), s[1], o_default, 1);
     617    define_variable (s[0], strlen (s[0]), s[1], o_default, 1);
    605618}
  • trunk/src/gmakenew/dep.h

    r530 r903  
    3737  {
    3838    struct dep *next;
    39     char *name;
    40     char *stem;
     39    const char *name;
     40    const char *stem;
    4141    struct file *file;
    4242    unsigned int changed : 8;
     
    5252  {
    5353    struct nameseq *next;
    54     char *name;
     54    const char *name;
    5555  };
    5656
    5757
    58 extern struct nameseq *multi_glob PARAMS ((struct nameseq *chain, unsigned int size));
     58struct nameseq *multi_glob (struct nameseq *chain, unsigned int size);
    5959#ifdef VMS
    60 extern struct nameseq *parse_file_seq ();
     60struct nameseq *parse_file_seq ();
    6161#else
    62 extern struct nameseq *parse_file_seq PARAMS ((char **stringp, int stopchar, unsigned int size, int strip));
     62struct nameseq *parse_file_seq (char **stringp, int stopchar, unsigned int size, int strip);
    6363#endif
    64 extern char *tilde_expand PARAMS ((char *name));
     64char *tilde_expand (const char *name);
    6565
    6666#ifndef NO_ARCHIVES
    67 extern struct nameseq *ar_glob PARAMS ((char *arname, char *member_pattern, unsigned int size));
     67struct nameseq *ar_glob (const char *arname, const char *member_pattern, unsigned int size);
    6868#endif
    6969
    70 #ifndef iAPX286
    7170#define dep_name(d) ((d)->name == 0 ? (d)->file->name : (d)->name)
    72 #else
    73 /* Buggy compiler can't hack this.  */
    74 extern char *dep_name ();
     71
     72struct dep *alloc_dep (void);
     73void free_dep (struct dep *d);
     74struct dep *copy_dep_chain (const struct dep *d);
     75void free_dep_chain (struct dep *d);
     76void free_ns_chain (struct nameseq *n);
     77struct dep *read_all_makefiles (const char **makefiles);
     78int eval_buffer (char *buffer);
     79int update_goal_chain (struct dep *goals);
     80void uniquize_deps (struct dep *);
     81
     82#ifdef CONFIG_WITH_INCLUDEDEP
     83void eval_include_dep (const char *name, struct floc *f);
    7584#endif
    7685
    77 extern struct dep *alloc_dep PARAMS ((void));
    78 extern void free_dep PARAMS ((struct dep *d));
    79 extern struct dep *copy_dep_chain PARAMS ((const struct dep *d));
    80 extern void free_dep_chain PARAMS ((struct dep *d));
    81 extern void free_ns_chain PARAMS ((struct nameseq *n));
    82 extern struct dep *read_all_makefiles PARAMS ((char **makefiles));
    83 extern int eval_buffer PARAMS ((char *buffer));
    84 #ifdef CONFIG_WITH_INCLUDEDEP
    85 extern void eval_include_dep PARAMS ((char *name, struct floc *f));
    86 #endif
    87 extern int update_goal_chain PARAMS ((struct dep *goals));
    88 extern void uniquize_deps PARAMS ((struct dep *));
    89 
  • trunk/src/gmakenew/dir.c

    r503 r903  
    2424# define NAMLEN(dirent) strlen((dirent)->d_name)
    2525# ifdef VMS
    26 extern char *vmsify PARAMS ((char *name, int type));
     26char *vmsify (char *name, int type);
    2727# endif
    2828#else
     
    6969#endif
    7070
    71 static char *
    72 dosify (char *filename)
     71static const char *
     72dosify (const char *filename)
    7373{
    7474  static char dos_filename[14];
     
    119119
    120120#ifdef HAVE_CASE_INSENSITIVE_FS
    121 static char *
    122 downcase (char *filename)
     121static const char *
     122downcase (const char *filename)
    123123{
    124124  static PATH_VAR (new_filename);
     
    132132
    133133  /* First, transform the name part.  */
    134   for (i = 0; *filename != '\0'; ++i)
    135   {
    136     *df++ = tolower ((unsigned char)*filename);
    137     ++filename;
    138   }
     134  while (*filename != '\0')
     135    {
     136      *df++ = tolower ((unsigned char)*filename);
     137      ++filename;
     138    }
    139139
    140140  *df = 0;
     
    217217    dev_t dev;                  /* Device and inode numbers of this dir.  */
    218218#ifdef WINDOWS32
    219     /*
    220      * Inode means nothing on WINDOWS32. Even file key information is
    221      * unreliable because it is random per file open and undefined
    222      * for remote filesystems. The most unique attribute I can
    223      * come up with is the fully qualified name of the directory. Beware
    224      * though, this is also unreliable. I'm open to suggestion on a better
    225      * way to emulate inode.
    226      */
     219    /* Inode means nothing on WINDOWS32. Even file key information is
     220     * unreliable because it is random per file open and undefined for remote
     221     * filesystems. The most unique attribute I can come up with is the fully
     222     * qualified name of the directory. Beware though, this is also
     223     * unreliable. I'm open to suggestion on a better way to emulate inode.  */
    227224    char *path_key;
    228225    int   ctime;
    229226    int   mtime;        /* controls check for stale directory cache */
    230227    int   fs_flags;     /* FS_FAT, FS_NTFS, ... */
    231 #define FS_FAT      0x1
    232 #define FS_NTFS     0x2
    233 #define FS_UNKNOWN  0x4
    234 #else
    235 #ifdef VMS
     228# define FS_FAT      0x1
     229# define FS_NTFS     0x2
     230# define FS_UNKNOWN  0x4
     231#else
     232# ifdef VMS
    236233    ino_t ino[3];
    237 #else
     234# else
    238235    ino_t ino;
    239 #endif
     236# endif
    240237#endif /* WINDOWS32 */
    241238    struct hash_table dirfiles; /* Files in this directory.  */
     
    246243directory_contents_hash_1 (const void *key_0)
    247244{
    248   struct directory_contents const *key = (struct directory_contents const *) key_0;
     245  const struct directory_contents *key = key_0;
    249246  unsigned long hash;
    250247
     
    269266directory_contents_hash_2 (const void *key_0)
    270267{
    271   struct directory_contents const *key = (struct directory_contents const *) key_0;
     268  const struct directory_contents *key = key_0;
    272269  unsigned long hash;
    273270
     
    304301directory_contents_hash_cmp (const void *xv, const void *yv)
    305302{
    306   struct directory_contents const *x = (struct directory_contents const *) xv;
    307   struct directory_contents const *y = (struct directory_contents const *) yv;
     303  const struct directory_contents *x = xv;
     304  const struct directory_contents *y = yv;
    308305  int result;
    309306
     
    341338struct directory
    342339  {
    343     char *name;                 /* Name of the directory.  */
     340    const char *name;                   /* Name of the directory.  */
    344341
    345342    /* The directory's contents.  This data may be shared by several
     
    352349directory_hash_1 (const void *key)
    353350{
    354   return_ISTRING_HASH_1 (((struct directory const *) key)->name);
     351  return_ISTRING_HASH_1 (((const struct directory *) key)->name);
    355352}
    356353
     
    358355directory_hash_2 (const void *key)
    359356{
    360   return_ISTRING_HASH_2 (((struct directory const *) key)->name);
     357  return_ISTRING_HASH_2 (((const struct directory *) key)->name);
    361358}
    362359
     
    364361directory_hash_cmp (const void *x, const void *y)
    365362{
    366   return_ISTRING_COMPARE (((struct directory const *) x)->name,
    367                           ((struct directory const *) y)->name);
     363  return_ISTRING_COMPARE (((const struct directory *) x)->name,
     364                          ((const struct directory *) y)->name);
    368365}
    369366
     
    382379struct dirfile
    383380  {
    384     char *name;                 /* Name of the file.  */
     381    const char *name;           /* Name of the file.  */
    385382    short length;
    386383    short impossible;           /* This file is impossible.  */
     
    402399dirfile_hash_cmp (const void *xv, const void *yv)
    403400{
    404   struct dirfile const *x = ((struct dirfile const *) xv);
    405   struct dirfile const *y = ((struct dirfile const *) yv);
     401  const struct dirfile *x = xv;
     402  const struct dirfile *y = yv;
    406403  int result = x->length - y->length;
    407404  if (result)
     
    415412
    416413
    417 static int dir_contents_file_exists_p PARAMS ((struct directory_contents *dir, char *filename));
    418 static struct directory *find_directory PARAMS ((char *name));
     414static int dir_contents_file_exists_p (struct directory_contents *dir,
     415                                       const char *filename);
     416static struct directory *find_directory (const char *name);
    419417
    420418/* Find the directory named NAME and return its `struct directory'.  */
    421419
    422420static struct directory *
    423 find_directory (char *name)
    424 {
    425   register char *p;
    426   register struct directory *dir;
    427   register struct directory **dir_slot;
     421find_directory (const char *name)
     422{
     423  const char *p;
     424  struct directory *dir;
     425  struct directory **dir_slot;
    428426  struct directory dir_key;
    429427  int r;
     
    454452
    455453      p = name + strlen (name);
    456       dir = (struct directory *) xmalloc (sizeof (struct directory));
    457       dir->name = savestring (name, p - name);
     454      dir = xmalloc (sizeof (struct directory));
     455      dir->name = strcache_add_len (name, p - name);
    458456      hash_insert_at (&directories, dir, dir_slot);
    459457      /* The directory is not in the name hash table.
     
    464462         directories if they end in '\'. */
    465463      if (p[-1] == '\\')
    466         p[-1] = '\0';
     464        ((char *)p)[-1] = '\0';
    467465#endif
    468466
     
    477475         truncating the value!  */
    478476      if (p[-1] == '\0')
    479         p[-1] = '\\';
     477        ((char *)p)[-1] = '\\';
    480478#endif
    481479
     
    553551              ENULLLOOP (dc->dirstream, opendir (name));
    554552              if (dc->dirstream == 0)
    555                 /* Couldn't open the directory.  Mark this by
    556                    setting the `files' member to a nil pointer.  */
     553                /* Couldn't open the directory.  Mark this by setting the
     554                   `files' member to a nil pointer.  */
    557555                dc->dirfiles.ht_vec = 0;
    558556              else
     
    565563                    /* We have too many directories open already.
    566564                       Read the entire directory and then close it.  */
    567                     (void) dir_contents_file_exists_p (dc, (char *) 0);
     565                    dir_contents_file_exists_p (dc, 0);
    568566                }
    569567            }
     
    582580
    583581static int
    584 dir_contents_file_exists_p (struct directory_contents *dir, char *filename)
     582dir_contents_file_exists_p (struct directory_contents *dir,
     583                            const char *filename)
    585584{
    586585  unsigned int hash;
     
    593592
    594593  if (dir == 0 || dir->dirfiles.ht_vec == 0)
    595     {
    596594    /* The directory could not be stat'd or opened.  */
    597       return 0;
    598     }
     595    return 0;
     596
    599597#ifdef __MSDOS__
    600598  filename = dosify (filename);
     
    626624      dirfile_key.name = filename;
    627625      dirfile_key.length = strlen (filename);
    628       df = (struct dirfile *) hash_find_item (&dir->dirfiles, &dirfile_key);
     626      df = hash_find_item (&dir->dirfiles, &dirfile_key);
    629627      if (df)
    630         {
    631           return !df->impossible;
    632         }
     628        return !df->impossible;
    633629    }
    634630
     
    651647              rehash = 1;
    652648            }
    653           else if (stat(dir->path_key, &st) == 0 && st.st_mtime > dir->mtime)
     649          else if (stat (dir->path_key, &st) == 0 && st.st_mtime > dir->mtime)
    654650            {
    655651              /* reset date stamp to show most recent re-process.  */
     
    663659
    664660          /* make sure directory can still be opened; if not return.  */
    665           dir->dirstream = opendir(dir->path_key);
     661          dir->dirstream = opendir (dir->path_key);
    666662          if (!dir->dirstream)
    667663            return 0;
     
    682678      ENULLLOOP (d, readdir (dir->dirstream));
    683679      if (d == 0)
    684         break;
     680        {
     681          if (errno)
     682            fatal (NILF, "INTERNAL: readdir: %s\n", strerror (errno));
     683          break;
     684        }
    685685
    686686#if defined(VMS) && defined(HAVE_DIRENT_H)
     
    707707#endif
    708708        {
    709           df = (struct dirfile *) xmalloc (sizeof (struct dirfile));
    710           df->name = savestring (d->d_name, len);
     709          df = xmalloc (sizeof (struct dirfile));
     710          df->name = strcache_add_len (d->d_name, len);
    711711          df->length = len;
    712712          df->impossible = 0;
     
    715715      /* Check if the name matches the one we're searching for.  */
    716716      if (filename != 0 && strieq (d->d_name, filename))
    717         {
    718           return 1;
    719         }
     717        return 1;
    720718    }
    721719
     
    736734
    737735int
    738 dir_file_exists_p (char *dirname, char *filename)
     736dir_file_exists_p (const char *dirname, const char *filename)
    739737{
    740738  return dir_contents_file_exists_p (find_directory (dirname)->contents,
     
    746744
    747745int
    748 file_exists_p (char *name)
    749 {
    750   char *dirend;
    751   char *dirname;
    752   char *slash;
     746file_exists_p (const char *name)
     747{
     748  const char *dirend;
     749  const char *dirname;
     750  const char *slash;
    753751
    754752#ifndef NO_ARCHIVES
     
    761759  if (dirend == 0)
    762760    dirend = strrchr (name, ':');
    763   if (dirend == (char *)0)
     761  if (dirend == 0)
    764762    return dir_file_exists_p ("[]", name);
    765763#else /* !VMS */
     
    768766  /* Forward and backslashes might be mixed.  We need the rightmost one.  */
    769767  {
    770     char *bslash = strrchr(name, '\\');
     768    const char *bslash = strrchr(name, '\\');
    771769    if (!dirend || bslash > dirend)
    772770      dirend = bslash;
     
    789787  else
    790788    {
     789      char *p;
    791790#ifdef HAVE_DOS_PATHS
    792791  /* d:/ and d: are *very* different...  */
     
    795794        dirend++;
    796795#endif
    797       dirname = (char *) alloca (dirend - name + 1);
    798       bcopy (name, dirname, dirend - name);
    799       dirname[dirend - name] = '\0';
     796      p = alloca (dirend - name + 1);
     797      memcpy (p, name, dirend - name);
     798      p[dirend - name] = '\0';
     799      dirname = p;
    800800    }
    801801  return dir_file_exists_p (dirname, slash + 1);
     
    808808
    809809void
    810 file_impossible (char *filename)
    811 {
    812   char *dirend;
    813   register char *p = filename;
    814   register struct directory *dir;
    815   register struct dirfile *new;
     810file_impossible (const char *filename)
     811{
     812  const char *dirend;
     813  const char *p = filename;
     814  struct directory *dir;
     815  struct dirfile *new;
    816816
    817817#ifdef VMS
     
    827827  /* Forward and backslashes might be mixed.  We need the rightmost one.  */
    828828  {
    829     char *bslash = strrchr(p, '\\');
     829    const char *bslash = strrchr(p, '\\');
    830830    if (!dirend || bslash > dirend)
    831831      dirend = bslash;
     
    844844  else
    845845    {
    846       char *dirname;
    847       char *slash = dirend;
     846      const char *dirname;
     847      const char *slash = dirend;
    848848      if (dirend == p)
    849849        dirname = "/";
    850850      else
    851851        {
     852          char *cp;
    852853#ifdef HAVE_DOS_PATHS
    853854          /* d:/ and d: are *very* different...  */
     
    856857            dirend++;
    857858#endif
    858           dirname = (char *) alloca (dirend - p + 1);
    859           bcopy (p, dirname, dirend - p);
    860           dirname[dirend - p] = '\0';
     859          cp = alloca (dirend - p + 1);
     860          memcpy (cp, p, dirend - p);
     861          cp[dirend - p] = '\0';
     862          dirname = cp;
    861863        }
    862864      dir = find_directory (dirname);
     
    868870      /* The directory could not be stat'd.  We allocate a contents
    869871         structure for it, but leave it out of the contents hash table.  */
    870       dir->contents = (struct directory_contents *)
    871         xmalloc (sizeof (struct directory_contents));
    872       bzero ((char *) dir->contents, sizeof (struct directory_contents));
     872      dir->contents = xmalloc (sizeof (struct directory_contents));
     873      memset (dir->contents, '\0', sizeof (struct directory_contents));
    873874    }
    874875
     
    881882  /* Make a new entry and put it in the table.  */
    882883
    883   new = (struct dirfile *) xmalloc (sizeof (struct dirfile));
    884   new->name = xstrdup (filename);
     884  new = xmalloc (sizeof (struct dirfile));
    885885  new->length = strlen (filename);
     886  new->name = strcache_add_len (filename, new->length);
    886887  new->impossible = 1;
    887888  hash_insert (&dir->contents->dirfiles, new);
     
    892893
    893894int
    894 file_impossible_p (char *filename)
    895 {
    896   char *dirend;
    897   register char *p = filename;
    898   register struct directory_contents *dir;
    899   register struct dirfile *dirfile;
     895file_impossible_p (const char *filename)
     896{
     897  const char *dirend;
     898  const char *p = filename;
     899  struct directory_contents *dir;
     900  struct dirfile *dirfile;
    900901  struct dirfile dirfile_key;
    901902
     
    909910  /* Forward and backslashes might be mixed.  We need the rightmost one.  */
    910911  {
    911     char *bslash = strrchr(filename, '\\');
     912    const char *bslash = strrchr(filename, '\\');
    912913    if (!dirend || bslash > dirend)
    913914      dirend = bslash;
     
    926927  else
    927928    {
    928       char *dirname;
    929       char *slash = dirend;
     929      const char *dirname;
     930      const char *slash = dirend;
    930931      if (dirend == filename)
    931932        dirname = "/";
    932933      else
    933934        {
     935          char *cp;
    934936#ifdef HAVE_DOS_PATHS
    935937          /* d:/ and d: are *very* different...  */
     
    938940            dirend++;
    939941#endif
    940           dirname = (char *) alloca (dirend - filename + 1);
    941           bcopy (p, dirname, dirend - p);
    942           dirname[dirend - p] = '\0';
     942          cp = alloca (dirend - filename + 1);
     943          memcpy (cp, p, dirend - p);
     944          cp[dirend - p] = '\0';
     945          dirname = cp;
    943946        }
    944947      dir = find_directory (dirname)->contents;
     
    962965  dirfile_key.name = filename;
    963966  dirfile_key.length = strlen (filename);
    964   dirfile = (struct dirfile *) hash_find_item (&dir->dirfiles, &dirfile_key);
     967  dirfile = hash_find_item (&dir->dirfiles, &dirfile_key);
    965968  if (dirfile)
    966969    return dirfile->impossible;
     
    973976   directory hash table that matches DIR.  */
    974977
    975 char *
    976 dir_name (char *dir)
     978const char *
     979dir_name (const char *dir)
    977980{
    978981  return find_directory (dir)->name;
     
    985988print_dir_data_base (void)
    986989{
    987   register unsigned int files;
    988   register unsigned int impossible;
    989   register struct directory **dir_slot;
    990   register struct directory **dir_end;
     990  unsigned int files;
     991  unsigned int impossible;
     992  struct directory **dir_slot;
     993  struct directory **dir_end;
    991994
    992995  puts (_("\n# Directories\n"));
     
    9981001  for ( ; dir_slot < dir_end; dir_slot++)
    9991002    {
    1000       register struct directory *dir = *dir_slot;
     1003      struct directory *dir = *dir_slot;
    10011004      if (! HASH_VACANT (dir))
    10021005        {
     
    10231026          else
    10241027            {
    1025               register unsigned int f = 0;
    1026               register unsigned int im = 0;
    1027               register struct dirfile **files_slot;
    1028               register struct dirfile **files_end;
     1028              unsigned int f = 0;
     1029              unsigned int im = 0;
     1030              struct dirfile **files_slot;
     1031              struct dirfile **files_end;
    10291032
    10301033              files_slot = (struct dirfile **) dir->contents->dirfiles.ht_vec;
     
    10321035              for ( ; files_slot < files_end; files_slot++)
    10331036                {
    1034                   register struct dirfile *df = *files_slot;
     1037                  struct dirfile *df = *files_slot;
    10351038                  if (! HASH_VACANT (df))
    10361039                    {
     
    11031106
    11041107/* Forward declarations.  */
    1105 static __ptr_t open_dirstream PARAMS ((const char *));
    1106 static struct dirent *read_dirstream PARAMS ((__ptr_t));
     1108static __ptr_t open_dirstream (const char *);
     1109static struct dirent *read_dirstream (__ptr_t);
    11071110
    11081111static __ptr_t
     
    11101113{
    11111114  struct dirstream *new;
    1112   struct directory *dir = find_directory ((char *)directory);
     1115  struct directory *dir = find_directory (directory);
    11131116
    11141117  if (dir->contents == 0 || dir->contents->dirfiles.ht_vec == 0)
     
    11201123     in being lazy, since glob will want to see every file anyway.  */
    11211124
    1122   (void) dir_contents_file_exists_p (dir->contents, (char *) 0);
    1123 
    1124   new = (struct dirstream *) xmalloc (sizeof (struct dirstream));
     1125  dir_contents_file_exists_p (dir->contents, 0);
     1126
     1127  new = xmalloc (sizeof (struct dirstream));
    11251128  new->contents = dir->contents;
    11261129  new->dirfile_slot = (struct dirfile **) new->contents->dirfiles.ht_vec;
     
    11321135read_dirstream (__ptr_t stream)
    11331136{
     1137  static char *buf;
     1138  static unsigned int bufsz;
     1139
    11341140  struct dirstream *const ds = (struct dirstream *) stream;
    11351141  struct directory_contents *dc = ds->contents;
    11361142  struct dirfile **dirfile_end = (struct dirfile **) dc->dirfiles.ht_vec + dc->dirfiles.ht_size;
    1137   static char *buf;
    1138   static unsigned int bufsz;
    11391143
    11401144  while (ds->dirfile_slot < dirfile_end)
    11411145    {
    1142       register struct dirfile *df = *ds->dirfile_slot++;
     1146      struct dirfile *df = *ds->dirfile_slot++;
    11431147      if (! HASH_VACANT (df) && !df->impossible)
    11441148        {
    1145           /* The glob interface wants a `struct dirent',
    1146              so mock one up.  */
     1149          /* The glob interface wants a `struct dirent', so mock one up.  */
    11471150          struct dirent *d;
    11481151          unsigned int len = df->length + 1;
    1149           if (sizeof *d - sizeof d->d_name + len > bufsz)
     1152          unsigned int sz = sizeof (*d) - sizeof (d->d_name) + len;
     1153          if (sz > bufsz)
    11501154            {
    1151               if (buf != 0)
    1152                 free (buf);
    11531155              bufsz *= 2;
    1154               if (sizeof *d - sizeof d->d_name + len > bufsz)
    1155                 bufsz = sizeof *d - sizeof d->d_name + len;
    1156               buf = xmalloc (bufsz);
     1156              if (sz > bufsz)
     1157                bufsz = sz;
     1158              buf = xrealloc (buf, bufsz);
    11571159            }
    11581160          d = (struct dirent *) buf;
     
    11911193#ifndef stat
    11921194# ifndef VMS
    1193 extern int stat PARAMS ((const char *path, struct stat *sbuf));
     1195int stat (const char *path, struct stat *sbuf);
    11941196# endif
    11951197# define local_stat stat
     
    12081210dir_setup_glob (glob_t *gl)
    12091211{
    1210   /* Bogus sunos4 compiler complains (!) about & before functions.  */
    12111212  gl->gl_opendir = open_dirstream;
    12121213  gl->gl_readdir = read_dirstream;
     
    12261227             directory_hash_1, directory_hash_2, directory_hash_cmp);
    12271228  hash_init (&directory_contents, DIRECTORY_BUCKETS,
    1228              directory_contents_hash_1, directory_contents_hash_2, directory_contents_hash_cmp);
    1229 }
     1229             directory_contents_hash_1, directory_contents_hash_2,
     1230             directory_contents_hash_cmp);
     1231}
  • trunk/src/gmakenew/doc/make.texi

    r503 r903  
    55@include version.texi
    66@set EDITION 0.70
    7 @set RCSID $Id: make.texi,v 1.45 2006/04/01 06:36:40 psmith Exp $
     7@set RCSID $Id: make.texi,v 1.47 2007/05/11 20:57:21 psmith Exp $
    88
    99@settitle GNU @code{make}
     
    5151
    5252
    53 @dircategory GNU Packages
     53@dircategory Software development
    5454@direntry
    5555* Make: (make).            Remake files automatically.
     
    10101010specially in certain situations.
    10111011
     1012You cannot use comments within variable references or function calls:
     1013any instance of @code{#} will be treated literally (rather than as the
     1014start of a comment) inside a variable reference or function call.
     1015
    10121016Within a command script (if the line begins with a TAB character) the
    10131017entire line is passed to the shell, just as with any other line that
     
    12521256@end example
    12531257
    1254 @xref{Text Functions}, for more information on the @code{word} and
    1255 @code{words} functions used above.  @xref{Flavors, The Two Flavors of
    1256 Variables}, for more information on simply-expanded (@code{:=})
    1257 variable definitions.
     1258@xref{Text Functions}, for more information on the @code{lastword}
     1259function used above.  @xref{Flavors, The Two Flavors of Variables},
     1260for more information on simply-expanded (@code{:=}) variable
     1261definitions.
    12581262
    12591263@node Special Variables, Remaking Makefiles, MAKEFILE_LIST Variable, Makefiles
     
    17451749@code{foo.1 bar.1} respectively.  In the third they will have values
    17461750@code{foo.1}, @code{foo.1 bar.1 foo.2 bar.2}, and @code{foo.1 bar.1
    1747 foo.2 bar.2} respectively.
     1751foo.2 bar.2 foo.1 foo.1 bar.1 foo.1 bar.1} respectively.
    17481752
    17491753Rules undergo secondary expansion in makefile order, except that
     
    19381942Variables, ,How to Use Variables}).  If you have enabled secondary
    19391943expansion (@pxref{Secondary Expansion}) and you want a literal dollar
    1940 sign in the prerequisites lise, you must actually write @emph{four}
     1944sign in the prerequisites list, you must actually write @emph{four}
    19411945dollar signs (@samp{$$$$}).
    19421946
     
    20012005The normal prerequisites section may of course be empty.  Also, you
    20022006may still declare multiple lines of prerequisites for the same target:
    2003 they are appended appropriately.  Note that if you declare the same
    2004 file to be both a normal and an order-only prerequisite, the normal
    2005 prerequisite takes precedence (since they are a strict superset of the
    2006 behavior of an order-only prerequisite).
     2007they are appended appropriately (normal prerequisites are appended to
     2008the list of normal prerequisites; order-only prerequisites are
     2009appended to the list of order-only prerequisites).  Note that if you
     2010declare the same file to be both a normal and an order-only
     2011prerequisite, the normal prerequisite takes precedence (since they
     2012have a strict superset of the behavior of an order-only prerequisite).
     2013
     2014Consider an example where your targets are to be placed in a separate
     2015directory, and that directory might not exist before @code{make} is
     2016run.  In this situation, you want the directory to be created before
     2017any targets are placed into it but, because the timestamps on
     2018directories change whenever a file is added, removed, or renamed, we
     2019certainly don't want to rebuild all the targets whenever the
     2020directory's timestamp changes.  One way to manage this is with
     2021order-only prerequisites: make the directory an order-only
     2022prerequisite on all the targets:
     2023
     2024@example
     2025OBJDIR := objdir
     2026OBJS := $(addprefix $(OBJDIR)/,foo.o bar.o baz.o)
     2027
     2028$(OBJDIR)/%.o : %.c
     2029        $(COMPILE.c) $(OUTPUT_OPTION) $<
     2030
     2031all: $(OBJS)
     2032
     2033$(OBJS): | $(OBJDIR)
     2034
     2035$(OBJDIR):
     2036        mkdir $(OBJDIR)
     2037@end example
     2038
     2039Now the rule to create the @file{objdir} directory will be run, if
     2040needed, before any @samp{.o} is built, but no @samp{.o} will be built
     2041because the @file{objdir} directory timestamp changed.
    20072042
    20082043@node Wildcards, Directory Search, Prerequisite Types, Rules
     
    29062941@xref{Secondary Expansion, ,Secondary Expansion}.
    29072942
    2908 The prerequisites of the special target @code{.SUFFIXES} are the list
    2909 of suffixes to be used in checking for suffix rules.
    2910 @xref{Suffix Rules, , Old-Fashioned Suffix Rules}.
    2911 
    29122943@findex .DELETE_ON_ERROR
    29132944@item .DELETE_ON_ERROR
     
    29963027@cindex parallel execution, overriding
    29973028
    2998 If @code{.NOTPARALLEL} is mentioned as a target, then this invocation of
    2999 @code{make} will be run serially, even if the @samp{-j} option is
    3000 given.  Any recursively invoked @code{make} command will still be run in
    3001 parallel (unless its makefile contains this target).  Any prerequisites
    3002 on this target are ignored.
     3029If @code{.NOTPARALLEL} is mentioned as a target, then this invocation
     3030of @code{make} will be run serially, even if the @samp{-j} option is
     3031given.  Any recursively invoked @code{make} command will still run
     3032commands in parallel (unless its makefile also contains this target).
     3033Any prerequisites on this target are ignored.
    30033034@end table
    30043035
     
    30943125if the file's name begins with a dot, no error message is printed.
    30953126This odd behavior is only for compatibility with other implementations
    3096 of @code{make}... you should avoid using it).  Occasionally it is
     3127of @code{make}@dots{} you should avoid using it).  Occasionally it is
    30973128useful to have the same target invoke multiple commands which are
    30983129defined in different parts of your makefile; you can use
     
    36533684
    36543685@noindent
    3655 Notice how the backslash/newline pair was removed inside the string quoted
    3656 with double quotes (@code{"..."}), but not from the string quoted with single
    3657 quotes (@code{'...'}).  This is the way the default shell (@file{/bin/sh})
    3658 handles backslash/newline pairs.  If you specify a different shell in your
    3659 makefiles it may treat them differently.
     3686Notice how the backslash/newline pair was removed inside the string
     3687quoted with double quotes (@code{"@dots{}"}), but not from the string
     3688quoted with single quotes (@code{'@dots{}'}).  This is the way the
     3689default shell (@file{/bin/sh}) handles backslash/newline pairs.  If
     3690you specify a different shell in your makefiles it may treat them
     3691differently.
    36603692
    36613693Sometimes you want to split a long line inside of single quotes, but
     
    39433975for it to finish before executing the next.  However, the @samp{-j} or
    39443976@samp{--jobs} option tells @code{make} to execute many commands
    3945 simultaneously.@refill
     3977simultaneously.  You can inhibit parallelism in a particular makefile
     3978with the @code{.NOTPARALLEL} pseudo-target (@pxref{Special
     3979Targets,Special Built-in Target Names}).@refill
    39463980
    39473981On MS-DOS, the @samp{-j} option has no effect, since that system doesn't
     
    83538387the special target @code{.SUFFIXES}).  The default suffix list is:
    83548388@code{.out}, @code{.a}, @code{.ln}, @code{.o}, @code{.c}, @code{.cc},
    8355 @code{.C}, @code{.cpp}, @code{.p}, @code{.f}, @code{.F}, @code{.r}, @code{.y},
    8356 @code{.l}, @code{.s}, @code{.S}, @code{.mod}, @code{.sym}, @code{.def},
    8357 @code{.h}, @code{.info}, @code{.dvi}, @code{.tex}, @code{.texinfo},
    8358 @code{.texi}, @code{.txinfo}, @code{.w}, @code{.ch} @code{.web},
    8359 @code{.sh}, @code{.elc}, @code{.el}.  All of the implicit rules
    8360 described below whose prerequisites have one of these suffixes are
    8361 actually suffix rules.  If you modify the suffix list, the only
    8362 predefined suffix rules in effect will be those named by one or two of
    8363 the suffixes that are on the list you specify; rules whose suffixes fail
    8364 to be on the list are disabled.  @xref{Suffix Rules, ,Old-Fashioned
    8365 Suffix Rules}, for full details on suffix rules.
     8389@code{.C}, @code{.cpp}, @code{.p}, @code{.f}, @code{.F}, @code{.m},
     8390@code{.r}, @code{.y}, @code{.l}, @code{.ym}, @code{.lm}, @code{.s},
     8391@code{.S}, @code{.mod}, @code{.sym}, @code{.def}, @code{.h},
     8392@code{.info}, @code{.dvi}, @code{.tex}, @code{.texinfo}, @code{.texi},
     8393@code{.txinfo}, @code{.w}, @code{.ch} @code{.web}, @code{.sh},
     8394@code{.elc}, @code{.el}.  All of the implicit rules described below
     8395whose prerequisites have one of these suffixes are actually suffix
     8396rules.  If you modify the suffix list, the only predefined suffix
     8397rules in effect will be those named by one or two of the suffixes that
     8398are on the list you specify; rules whose suffixes fail to be on the
     8399list are disabled.  @xref{Suffix Rules, ,Old-Fashioned Suffix Rules},
     8400for full details on suffix rules.
    83668401
    83678402@table @asis
     
    86948729@pindex cc
    86958730
    8696 @item CO
    8697 @vindex CO
    8698 Program for checking out files from RCS; default @samp{co}.
    8699 @pindex cc
    8700 
    87018731@item CXX
    87028732@vindex CXX
    87038733Program for compiling C++ programs; default @samp{g++}.
    87048734@pindex g++
    8705 
    8706 @item CO
    8707 @vindex CO
    8708 Program for extracting a file from RCS; default @samp{co}.
    8709 @pindex co
    87108735
    87118736@item CPP
     
    87208745@pindex f77
    87218746
     8747@item M2C
     8748@vindex M2C
     8749Program to use to compile Modula-2 source code; default @samp{m2c}.
     8750@pindex m2c
     8751
     8752@item PC
     8753@vindex PC
     8754Program for compiling Pascal programs; default @samp{pc}.
     8755@pindex pc
     8756
     8757@item CO
     8758@vindex CO
     8759Program for extracting a file from RCS; default @samp{co}.
     8760@pindex co
     8761
    87228762@item GET
    87238763@vindex GET
     
    87398779Program to use to run lint on source code; default @samp{lint}.
    87408780@pindex lint
    8741 
    8742 @item M2C
    8743 @vindex M2C
    8744 Program to use to compile Modula-2 source code; default @samp{m2c}.
    8745 @pindex m2c
    8746 
    8747 @item PC
    8748 @vindex PC
    8749 Program for compiling Pascal programs; default @samp{pc}.
    8750 @pindex pc
    87518781
    87528782@item MAKEINFO
  • trunk/src/gmakenew/expand.c

    r533 r903  
    5656
    5757char *
    58 variable_buffer_output (char *ptr, char *string, unsigned int length)
     58variable_buffer_output (char *ptr, const char *string, unsigned int length)
    5959{
    6060  register unsigned int newlen = length + (ptr - variable_buffer);
     
    6666                                ? newlen + 100
    6767                                : 2 * variable_buffer_length);
    68       variable_buffer = (char *) xrealloc (variable_buffer,
    69                                            variable_buffer_length);
     68      variable_buffer = xrealloc (variable_buffer, variable_buffer_length);
    7069      ptr = variable_buffer + offset;
    7170    }
    7271
    73   bcopy (string, ptr, length);
     72  memcpy (ptr, string, length);
    7473  return ptr + length;
    7574}
     
    8584    {
    8685      variable_buffer_length = 200;
    87       variable_buffer = (char *) xmalloc (variable_buffer_length);
     86      variable_buffer = xmalloc (variable_buffer_length);
    8887      variable_buffer[0] = '\0';
    8988    }
     
    9594/* Recursively expand V.  The returned string is malloc'd.  */
    9695
    97 static char *allocated_variable_append PARAMS ((const struct variable *v));
     96static char *allocated_variable_append (const struct variable *v);
    9897
    9998char *
     
    162161#endif
    163162static char *
    164 reference_variable (char *o, char *name, unsigned int length)
    165 {
    166   register struct variable *v;
     163reference_variable (char *o, const char *name, unsigned int length)
     164{
     165  struct variable *v;
    167166  char *value;
    168167
     
    194193   LINE is NULL, start at the beginning of the buffer.
    195194   Return a pointer to LINE, or to the beginning of the buffer if LINE is
    196    NULL.  */
    197 
     195   NULL.
     196 */
    198197char *
    199 variable_expand_string (char *line, char *string, long length)
    200 {
    201   register struct variable *v;
    202   register char *p, *o, *p1;
    203   char save_char = '\0';
     198variable_expand_string (char *line, const char *string, long length)
     199{
     200  struct variable *v;
     201  const char *p, *p1;
     202  char *abuf = NULL;
     203  char *o;
    204204  unsigned int line_offset;
    205205
    206206  if (!line)
    207207    line = initialize_variable_output();
    208 
    209   p = string;
    210208  o = line;
    211209  line_offset = line - variable_buffer;
    212210
    213   if (length >= 0)
    214     {
    215       save_char = string[length];
    216       string[length] = '\0';
    217     }
     211  if (length == 0)
     212    {
     213      variable_buffer_output (o, "", 1);
     214      return (variable_buffer);
     215    }
     216
     217  /* If we want a subset of the string, allocate a temporary buffer for it.
     218     Most of the functions we use here don't work with length limits.  */
     219  if (length > 0 && string[length] != '\0')
     220    {
     221      abuf = xmalloc(length+1);
     222      memcpy(abuf, string, length);
     223      abuf[length] = '\0';
     224      string = abuf;
     225    }
     226  p = string;
    218227
    219228  while (1)
     
    246255            char openparen = *p;
    247256            char closeparen = (openparen == '(') ? ')' : '}';
    248             register char *beg = p + 1;
    249             int free_beg = 0;
    250             char *op, *begp;
    251             char *end, *colon;
     257            const char *begp;
     258            const char *beg = p + 1;
     259            char *op;
     260            char *abeg = NULL;
     261            const char *end, *colon;
    252262
    253263            op = o;
     
    285295                if (count < 0)
    286296                  {
    287                     beg = expand_argument (beg, p); /* Expand the name.  */
    288                     free_beg = 1; /* Remember to free BEG when finished.  */
     297                    abeg = expand_argument (beg, p); /* Expand the name.  */
     298                    beg = abeg;
    289299                    end = strchr (beg, '\0');
    290300                  }
     
    304314              {
    305315                /* This looks like a substitution reference: $(FOO:A=B).  */
    306                 char *subst_beg, *subst_end, *replace_beg, *replace_end;
     316                const char *subst_beg, *subst_end, *replace_beg, *replace_end;
    307317
    308318                subst_beg = colon + 1;
     
    336346                           extra % at the beginning to use in case there
    337347                           isn't one in the pattern.  */
    338                         pattern = (char *) alloca (subst_end - subst_beg + 2);
     348                        pattern = alloca (subst_end - subst_beg + 2);
    339349                        *(pattern++) = '%';
    340                         bcopy (subst_beg, pattern, subst_end - subst_beg);
     350                        memcpy (pattern, subst_beg, subst_end - subst_beg);
    341351                        pattern[subst_end - subst_beg] = '\0';
    342352
    343                         replace = (char *) alloca (replace_end
    344                                                    - replace_beg + 2);
     353                        replace = alloca (replace_end - replace_beg + 2);
    345354                        *(replace++) = '%';
    346                         bcopy (replace_beg, replace,
     355                        memcpy (replace, replace_beg,
    347356                               replace_end - replace_beg);
    348357                        replace[replace_end - replace_beg] = '\0';
     
    354363                          {
    355364                            ++ppercent;
    356                             rpercent = 0;
     365                            rpercent = find_percent (replace);
     366                            if (rpercent)
     367                              ++rpercent;
    357368                          }
    358369                        else
     
    364375                          }
    365376
    366                         o = patsubst_expand (o, value, pattern, replace,
    367                                              ppercent, rpercent);
     377                        o = patsubst_expand_pat (o, value, pattern, replace,
     378                                                 ppercent, rpercent);
    368379
    369380                        if (v->recursive)
     
    378389                o = reference_variable (o, beg, end - beg);
    379390
    380           if (free_beg)
    381             free (beg);
     391          if (abeg)
     392            free (abeg);
    382393          }
    383394          break;
     
    403414    }
    404415
    405   if (save_char)
    406     string[length] = save_char;
    407 
    408   (void)variable_buffer_output (o, "", 1);
     416  if (abuf)
     417    free (abuf);
     418
     419  variable_buffer_output (o, "", 1);
    409420  return (variable_buffer + line_offset);
    410421}
     
    417428
    418429char *
    419 variable_expand (char *line)
     430variable_expand (const char *line)
    420431{
    421432  return variable_expand_string(NULL, line, (long)-1);
     
    438449
    439450  if (!end || *end == '\0')
    440     return allocated_variable_expand ((char *)str);
     451    return allocated_variable_expand (str);
    441452
    442453#ifdef CONFIG_WITH_OPTIMIZATION_HACKS
    443     {
    444       const char saved_char = *end;
    445       *(char *)end = '\0';
    446       tmp = allocated_variable_expand ((char *)str);
    447       *(char *)end = saved_char;
    448       return tmp;
    449     }
     454  {
     455    const char saved_char = *end;
     456    *(char *)end = '\0';
     457    tmp = allocated_variable_expand ((char *)str);
     458    *(char *)end = saved_char;
     459    return tmp;
     460  }
    450461#else
    451     {
    452       tmp = (char *) alloca (end - str + 1);
    453       bcopy (str, tmp, end - str);
    454       tmp[end - str] = '\0';
    455  
    456       return allocated_variable_expand (tmp);
    457     }
    458 #endif
     462  tmp = alloca (end - str + 1);
     463  memcpy (tmp, str, end - str);
     464  tmp[end - str] = '\0';
     465
     466  return allocated_variable_expand (tmp);
     467#endif
    459468}
    460469
     
    464473
    465474char *
    466 variable_expand_for_file (char *line, struct file *file)
     475variable_expand_for_file (const char *line, struct file *file)
    467476{
    468477  char *result;
     
    523532  if (! v->recursive)
    524533#ifdef CONFIG_WITH_VALUE_LENGTH
    525     return variable_buffer_output (buf, v->value, 
     534    return variable_buffer_output (buf, v->value,
    526535                                   v->value_length >= 0 ? v->value_length : strlen (v->value));
    527536#else
     
    539548#ifdef CONFIG_WITH_VALUE_LENGTH
    540549/* Expands the specified string, appending it to the specified variable value. */
    541 void 
     550void
    542551append_expanded_string_to_variable (struct variable *v, char *value)
    543552{
     
    594603
    595604char *
    596 allocated_variable_expand_for_file (char *line, struct file *file)
     605allocated_variable_expand_for_file (const char *line, struct file *file)
    597606{
    598607  char *value;
  • trunk/src/gmakenew/file.c

    r520 r903  
    7070/* Access the hash table of all file records.
    7171   lookup_file  given a name, return the struct file * for that name,
    72            or nil if there is none.
    73    enter_file   similar, but create one if there is none.  */
     72                or nil if there is none.
     73*/
    7474
    7575struct file *
    76 lookup_file (char *name)
    77 {
    78   register struct file *f;
     76lookup_file (const char *name)
     77{
     78  struct file *f;
    7979  struct file file_key;
    8080#if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
    81   register char *lname, *ln;
     81  char *lname;
    8282#endif
    8383
     
    9191  if (*name != '.')
    9292    {
    93       register char *n;
    94       lname = (char *) malloc (strlen (name) + 1);
     93      const char *n;
     94      char *ln;
     95      lname = xstrdup (name);
    9596      for (n = name, ln = lname; *n != '\0'; ++n, ++ln)
    9697        *ln = isupper ((unsigned char)*n) ? tolower ((unsigned char)*n) : *n;
     
    113114  if (*name == '\0')
    114115    /* It was all slashes after a dot.  */
    115 #ifdef VMS
     116#if defined(VMS)
    116117    name = "[]";
    117 #else
    118 #ifdef _AMIGA
     118#elif defined(_AMIGA)
    119119    name = "";
    120120#else
    121121    name = "./";
    122 #endif /* AMIGA */
    123 #endif /* VMS */
     122#endif
    124123
    125124  file_key.hname = name;
    126   f = (struct file *) hash_find_item (&files, &file_key);
     125  f = hash_find_item (&files, &file_key);
    127126#if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
    128127  if (*name != '.')
    129128    free (lname);
    130129#endif
     130
    131131  return f;
    132132}
    133133
     134/* Look up a file record for file NAME and return it.
     135   Create a new record if one doesn't exist.  NAME will be stored in the
     136   new record so it should be constant or in the strcache etc.
     137 */
     138
    134139struct file *
    135 enter_file (char *name)
    136 {
    137   register struct file *f;
    138   register struct file *new;
    139   register struct file **file_slot;
     140enter_file (const char *name)
     141{
     142  struct file *f;
     143  struct file *new;
     144  struct file **file_slot;
    140145  struct file file_key;
    141 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
    142   char *lname, *ln;
    143 #endif
    144146
    145147  assert (*name != '\0');
     148  assert (strcache_iscached (name));
    146149
    147150#if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
    148151  if (*name != '.')
    149152    {
    150       register char *n;
    151       lname = (char *) malloc (strlen (name) + 1);
     153      const char *n;
     154      char *lname, *ln;
     155      lname = xstrdup (name);
    152156      for (n = name, ln = lname; *n != '\0'; ++n, ++ln)
    153         {
    154           if (isupper ((unsigned char)*n))
    155             *ln = tolower ((unsigned char)*n);
    156           else
    157             *ln = *n;
    158         }
    159 
    160       *ln = 0;
    161       /* Creates a possible leak, old value of name is unreachable, but I
    162          currently don't know how to fix it. */
    163       name = lname;
     157        if (isupper ((unsigned char)*n))
     158          *ln = tolower ((unsigned char)*n);
     159        else
     160          *ln = *n;
     161
     162      *ln = '\0';
     163      name = strcache_add (lname);
     164      free (lname);
    164165    }
    165166#endif
     
    169170  f = *file_slot;
    170171  if (! HASH_VACANT (f) && !f->double_colon)
    171     {
    172 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
    173       if (*name != '.')
    174         free (lname);
    175 #endif
    176       return f;
    177     }
    178 
    179   new = (struct file *) xmalloc (sizeof (struct file));
    180   bzero ((char *) new, sizeof (struct file));
     172    return f;
     173
     174  new = xmalloc (sizeof (struct file));
     175  memset (new, '\0', sizeof (struct file));
    181176  new->name = new->hname = name;
    182177  new->update_status = -1;
     
    199194
    200195
    201 /* Rename FILE to NAME.  This is not as simple as resetting
    202    the `name' member, since it must be put in a new hash bucket,
    203    and possibly merged with an existing file called NAME.  */
    204 
    205 void
    206 rename_file (struct file *from_file, char *to_hname)
    207 {
    208   rehash_file (from_file, to_hname);
    209   while (from_file)
    210     {
    211       from_file->name = from_file->hname;
    212       from_file = from_file->prev;
    213     }
    214 }
    215 
    216196/* Rehash FILE to NAME.  This is not as simple as resetting
    217197   the `hname' member, since it must be put in a new hash bucket,
     
    219199
    220200void
    221 rehash_file (struct file *from_file, char *to_hname)
     201rehash_file (struct file *from_file, const char *to_hname)
    222202{
    223203  struct file file_key;
     
    227207  struct file *f;
    228208
     209  /* If it's already that name, we're done.  */
    229210  file_key.hname = to_hname;
    230   if (0 == file_hash_cmp (from_file, &file_key))
     211  if (! file_hash_cmp (from_file, &file_key))
    231212    return;
    232213
     214  /* Find the end of the renamed list for the "from" file.  */
    233215  file_key.hname = from_file->hname;
    234216  while (from_file->renamed != 0)
    235217    from_file = from_file->renamed;
    236218  if (file_hash_cmp (from_file, &file_key))
    237     /* hname changed unexpectedly */
     219    /* hname changed unexpectedly!! */
    238220    abort ();
    239221
     222  /* Remove the "from" file from the hash.  */
    240223  deleted_file = hash_delete (&files, from_file);
    241224  if (deleted_file != from_file)
     
    243226    abort ();
    244227
     228  /* Find where the newly renamed file will go in the hash.  */
    245229  file_key.hname = to_hname;
    246230  file_slot = (struct file **) hash_find_slot (&files, &file_key);
    247231  to_file = *file_slot;
    248232
     233  /* Change the hash name for this file.  */
    249234  from_file->hname = to_hname;
    250235  for (f = from_file->double_colon; f != 0; f = f->prev)
    251236    f->hname = to_hname;
    252237
     238  /* If the new name doesn't exist yet just set it to the renamed file.  */
    253239  if (HASH_VACANT (to_file))
    254     hash_insert_at (&files, from_file, file_slot);
     240    {
     241      hash_insert_at (&files, from_file, file_slot);
     242      return;
     243    }
     244
     245  /* TO_FILE already exists under TO_HNAME.
     246     We must retain TO_FILE and merge FROM_FILE into it.  */
     247
     248  if (from_file->cmds != 0)
     249    {
     250      if (to_file->cmds == 0)
     251        to_file->cmds = from_file->cmds;
     252      else if (from_file->cmds != to_file->cmds)
     253        {
     254          /* We have two sets of commands.  We will go with the
     255             one given in the rule explicitly mentioning this name,
     256             but give a message to let the user know what's going on.  */
     257          if (to_file->cmds->fileinfo.filenm != 0)
     258            error (&from_file->cmds->fileinfo,
     259                   _("Commands were specified for file `%s' at %s:%lu,"),
     260                   from_file->name, to_file->cmds->fileinfo.filenm,
     261                   to_file->cmds->fileinfo.lineno);
     262          else
     263            error (&from_file->cmds->fileinfo,
     264                   _("Commands for file `%s' were found by implicit rule search,"),
     265                   from_file->name);
     266          error (&from_file->cmds->fileinfo,
     267                 _("but `%s' is now considered the same file as `%s'."),
     268                 from_file->name, to_hname);
     269          error (&from_file->cmds->fileinfo,
     270                 _("Commands for `%s' will be ignored in favor of those for `%s'."),
     271                 to_hname, from_file->name);
     272        }
     273    }
     274
     275  /* Merge the dependencies of the two files.  */
     276
     277  if (to_file->deps == 0)
     278    to_file->deps = from_file->deps;
    255279  else
    256280    {
    257       /* TO_FILE already exists under TO_HNAME.
    258          We must retain TO_FILE and merge FROM_FILE into it.  */
    259 
    260       if (from_file->cmds != 0)
    261         {
    262           if (to_file->cmds == 0)
    263             to_file->cmds = from_file->cmds;
    264           else if (from_file->cmds != to_file->cmds)
    265             {
    266               /* We have two sets of commands.  We will go with the
    267                  one given in the rule explicitly mentioning this name,
    268                  but give a message to let the user know what's going on.  */
    269               if (to_file->cmds->fileinfo.filenm != 0)
    270                 error (&from_file->cmds->fileinfo,
    271                        _("Commands were specified for file `%s' at %s:%lu,"),
    272                        from_file->name, to_file->cmds->fileinfo.filenm,
    273                        to_file->cmds->fileinfo.lineno);
    274               else
    275                 error (&from_file->cmds->fileinfo,
    276                        _("Commands for file `%s' were found by implicit rule search,"),
    277                        from_file->name);
    278               error (&from_file->cmds->fileinfo,
    279                      _("but `%s' is now considered the same file as `%s'."),
    280                      from_file->name, to_hname);
    281               error (&from_file->cmds->fileinfo,
    282                      _("Commands for `%s' will be ignored in favor of those for `%s'."),
    283                      to_hname, from_file->name);
    284             }
    285         }
    286 
    287       /* Merge the dependencies of the two files.  */
    288 
    289       if (to_file->deps == 0)
    290         to_file->deps = from_file->deps;
     281      struct dep *deps = to_file->deps;
     282      while (deps->next != 0)
     283        deps = deps->next;
     284      deps->next = from_file->deps;
     285    }
     286
     287  merge_variable_set_lists (&to_file->variables, from_file->variables);
     288
     289  if (to_file->double_colon && from_file->is_target && !from_file->double_colon)
     290    fatal (NILF, _("can't rename single-colon `%s' to double-colon `%s'"),
     291           from_file->name, to_hname);
     292  if (!to_file->double_colon  && from_file->double_colon)
     293    {
     294      if (to_file->is_target)
     295        fatal (NILF, _("can't rename double-colon `%s' to single-colon `%s'"),
     296               from_file->name, to_hname);
    291297      else
    292         {
    293           register struct dep *deps = to_file->deps;
    294           while (deps->next != 0)
    295             deps = deps->next;
    296           deps->next = from_file->deps;
    297         }
    298 
    299       merge_variable_set_lists (&to_file->variables, from_file->variables);
    300 
    301       if (to_file->double_colon && from_file->is_target && !from_file->double_colon)
    302         fatal (NILF, _("can't rename single-colon `%s' to double-colon `%s'"),
    303                from_file->name, to_hname);
    304       if (!to_file->double_colon  && from_file->double_colon)
    305         {
    306           if (to_file->is_target)
    307             fatal (NILF, _("can't rename double-colon `%s' to single-colon `%s'"),
    308                    from_file->name, to_hname);
    309           else
    310             to_file->double_colon = from_file->double_colon;
    311         }
    312 
    313       if (from_file->last_mtime > to_file->last_mtime)
    314         /* %%% Kludge so -W wins on a file that gets vpathized.  */
    315         to_file->last_mtime = from_file->last_mtime;
    316 
    317       to_file->mtime_before_update = from_file->mtime_before_update;
     298        to_file->double_colon = from_file->double_colon;
     299    }
     300
     301  if (from_file->last_mtime > to_file->last_mtime)
     302    /* %%% Kludge so -W wins on a file that gets vpathized.  */
     303    to_file->last_mtime = from_file->last_mtime;
     304
     305  to_file->mtime_before_update = from_file->mtime_before_update;
    318306
    319307#define MERGE(field) to_file->field |= from_file->field
    320       MERGE (precious);
    321       MERGE (tried_implicit);
    322       MERGE (updating);
    323       MERGE (updated);
    324       MERGE (is_target);
    325       MERGE (cmd_target);
    326       MERGE (phony);
    327       MERGE (ignore_vpath);
     308  MERGE (precious);
     309  MERGE (tried_implicit);
     310  MERGE (updating);
     311  MERGE (updated);
     312  MERGE (is_target);
     313  MERGE (cmd_target);
     314  MERGE (phony);
     315  MERGE (ignore_vpath);
    328316#undef MERGE
    329317
    330       from_file->renamed = to_file;
     318  from_file->renamed = to_file;
     319}
     320
     321/* Rename FILE to NAME.  This is not as simple as resetting
     322   the `name' member, since it must be put in a new hash bucket,
     323   and possibly merged with an existing file called NAME.  */
     324
     325void
     326rename_file (struct file *from_file, const char *to_hname)
     327{
     328  rehash_file (from_file, to_hname);
     329  while (from_file)
     330    {
     331      from_file->name = from_file->hname;
     332      from_file = from_file->prev;
    331333    }
    332334}
     
    341343remove_intermediates (int sig)
    342344{
    343   register struct file **file_slot;
    344   register struct file **file_end;
     345  struct file **file_slot;
     346  struct file **file_end;
    345347  int doneany = 0;
    346348
     
    357359    if (! HASH_VACANT (*file_slot))
    358360      {
    359         register struct file *f = *file_slot;
     361        struct file *f = *file_slot;
    360362        /* Is this file eligible for automatic deletion?
    361363           Yes, IFF: it's marked intermediate, it's not secondary, it wasn't
     
    448450}
    449451
    450 
    451452/* Set the intermediate flag.  */
    452453
     
    464465  struct dep *d;
    465466  struct dep *old = f->deps;
    466   char *file_stem = f->stem;
     467  const char *file_stem = f->stem;
    467468  unsigned int last_dep_has_cmds = f->updating;
    468469  int initialized = 0;
     
    480481
    481482      /* Create the dependency list.
    482          If we're not doing 2nd expansion, then it's just the name.  */
     483         If we're not doing 2nd expansion, then it's just the name.  We will
     484         still need to massage it though.  */
    483485      if (! d->need_2nd_expansion)
    484         p = d->name;
     486        {
     487          p = variable_expand ("");
     488          variable_buffer_output (p, d->name, strlen (d->name) + 1);
     489        }
    485490      else
    486491        {
     
    494499              o = subst_expand (buffer, d->name, "%", "$*", 1, 2, 0);
    495500
    496               free (d->name);
    497               d->name = savestring (buffer, o - buffer);
     501              d->name = strcache_add_len (buffer, o - buffer);
    498502              d->staticpattern = 0; /* Clear staticpattern so that we don't
    499503                                       re-expand %s below. */
     
    529533      if (new && d->staticpattern)
    530534        {
    531           char *pattern = "%";
     535          const char *pattern = "%";
    532536          char *buffer = variable_expand ("");
    533537          struct dep *dp = new, *dl = 0;
     
    535539          while (dp != 0)
    536540            {
    537               char *percent = find_percent (dp->name);
     541              char *percent;
     542              int nl = strlen (dp->name) + 1;
     543              char *nm = alloca (nl);
     544              memcpy (nm, dp->name, nl);
     545              percent = find_percent (nm);
    538546              if (percent)
    539547                {
     548                  char *o;
     549
    540550                  /* We have to handle empty stems specially, because that
    541551                     would be equivalent to $(patsubst %,dp->name,) which
    542552                     will always be empty.  */
    543553                  if (d->stem[0] == '\0')
    544                     /* This needs memmove() in ISO C.  */
    545                     bcopy (percent+1, percent, strlen (percent));
     554                    {
     555                      memmove (percent, percent+1, strlen (percent));
     556                      o = variable_buffer_output (buffer, nm, strlen (nm) + 1);
     557                    }
    546558                  else
    547                     {
    548                       char *o = patsubst_expand (buffer, d->stem, pattern,
    549                                                  dp->name, pattern+1,
    550                                                  percent+1);
    551                       if (o == buffer)
    552                         dp->name[0] = '\0';
    553                       else
    554                         {
    555                           free (dp->name);
    556                           dp->name = savestring (buffer, o - buffer);
    557                         }
    558                     }
     559                    o = patsubst_expand_pat (buffer, d->stem, pattern, nm,
     560                                             pattern+1, percent+1);
    559561
    560562                  /* If the name expanded to the empty string, ignore it.  */
    561                   if (dp->name[0] == '\0')
     563                  if (buffer[0] == '\0')
    562564                    {
    563565                      struct dep *df = dp;
     
    566568                      else
    567569                        dp = dl->next = dp->next;
    568                       /* @@ Are we leaking df->name here?  */
    569                       df->name = 0;
    570570                      free_dep (df);
    571571                      continue;
    572572                    }
     573
     574                  /* Save the name.  */
     575                  dp->name = strcache_add_len (buffer, o - buffer);
    573576                }
    574577              dl = dp;
     
    583586          if (d1->file == 0)
    584587            d1->file = enter_file (d1->name);
    585           else
    586             free (d1->name);
    587588          d1->name = 0;
    588589          d1->staticpattern = 0;
     
    639640  struct file **file_end;
    640641
    641   /* Perform second expansion and enter each dependency
    642      name as a file. */
    643 
    644   /* Expand .SUFFIXES first; it's dependencies are used for
    645      $$* calculation. */
     642  /* Perform second expansion and enter each dependency name as a file. */
     643
     644  /* Expand .SUFFIXES first; it's dependencies are used for $$* calculation. */
    646645  for (f = lookup_file (".SUFFIXES"); f != 0; f = f->prev)
    647646    expand_deps (f);
    648647
    649   /* We must use hash_dump (), because within this loop
    650      we might add new files to the table, possibly causing
    651      an in-situ table expansion.  */
     648  /* For every target that's not .SUFFIXES, expand its dependencies.
     649     We must use hash_dump (), because within this loop we might add new files
     650     to the table, possibly causing an in-situ table expansion.  */
    652651  file_slot_0 = (struct file **) hash_dump (&files, 0, 0);
    653652  file_end = file_slot_0 + files.ht_fill;
    654653  for (file_slot = file_slot_0; file_slot < file_end; file_slot++)
    655654    for (f = *file_slot; f != 0; f = f->prev)
    656       {
    657         if (strcmp (f->name, ".SUFFIXES") != 0)
    658           expand_deps (f);
    659       }
     655      if (strcmp (f->name, ".SUFFIXES") != 0)
     656        expand_deps (f);
    660657  free (file_slot_0);
     658
     659  /* Now manage all the special targets.  */
    661660
    662661  for (f = lookup_file (".PRECIOUS"); f != 0; f = f->prev)
     
    682681
    683682  for (f = lookup_file (".INTERMEDIATE"); f != 0; f = f->prev)
    684     {
    685       /* .INTERMEDIATE with deps listed
    686          marks those deps as intermediate files.  */
     683    /* Mark .INTERMEDIATE deps as intermediate files.  */
     684    for (d = f->deps; d != 0; d = d->next)
     685      for (f2 = d->file; f2 != 0; f2 = f2->prev)
     686        f2->intermediate = 1;
     687    /* .INTERMEDIATE with no deps does nothing.
     688       Marking all files as intermediates is useless since the goal targets
     689       would be deleted after they are built.  */
     690
     691  for (f = lookup_file (".SECONDARY"); f != 0; f = f->prev)
     692    /* Mark .SECONDARY deps as both intermediate and secondary.  */
     693    if (f->deps)
    687694      for (d = f->deps; d != 0; d = d->next)
    688         for (f2 = d->file; f2 != 0; f2 = f2->prev)
    689           f2->intermediate = 1;
    690       /* .INTERMEDIATE with no deps does nothing.
    691          Marking all files as intermediates is useless
    692          since the goal targets would be deleted after they are built.  */
    693     }
    694 
    695   for (f = lookup_file (".SECONDARY"); f != 0; f = f->prev)
    696     {
    697       /* .SECONDARY with deps listed
    698          marks those deps as intermediate files
    699          in that they don't get rebuilt if not actually needed;
    700          but unlike real intermediate files,
    701          these are not deleted after make finishes.  */
    702       if (f->deps)
    703         for (d = f->deps; d != 0; d = d->next)
    704           for (f2 = d->file; f2 != 0; f2 = f2->prev)
    705             f2->intermediate = f2->secondary = 1;
    706       /* .SECONDARY with no deps listed marks *all* files that way.  */
    707       else
    708         {
    709           all_secondary = 1;
    710           hash_map (&files, set_intermediate);
    711         }
    712     }
     695        for (f2 = d->file; f2 != 0; f2 = f2->prev)
     696          f2->intermediate = f2->secondary = 1;
     697    /* .SECONDARY with no deps listed marks *all* files that way.  */
     698    else
     699      {
     700        all_secondary = 1;
     701        hash_map (&files, set_intermediate);
     702      }
    713703
    714704  f = lookup_file (".EXPORT_ALL_VARIABLES");
     
    874864  p += strlen (p);
    875865
    876   /* Append nanoseconds as a fraction, but remove trailing zeros.
    877      We don't know the actual timestamp resolution, since clock_getres
    878      applies only to local times, whereas this timestamp might come
    879      from a remote filesystem.  So removing trailing zeros is the
    880      best guess that we can do.  */
     866  /* Append nanoseconds as a fraction, but remove trailing zeros.  We don't
     867     know the actual timestamp resolution, since clock_getres applies only to
     868     local times, whereas this timestamp might come from a remote filesystem.
     869     So removing trailing zeros is the best guess that we can do.  */
    881870  sprintf (p, ".%09d", FILE_TIMESTAMP_NS (ts));
    882871  p += strlen (p) - 1;
     
    894883print_file (const void *item)
    895884{
    896   struct file *f = (struct file *) item;
     885  const struct file *f = item;
    897886  struct dep *d;
    898887  struct dep *ood = 0;
     
    10161005}
    10171006
     1007
     1008/* Verify the integrity of the data base of files.  */
     1009
     1010#define VERIFY_CACHED(_p,_n) \
     1011    do{\
     1012        if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \
     1013          printf ("%s: Field %s not cached: %s\n", _p->name, # _n, _p->_n); \
     1014    }while(0)
     1015
     1016static void
     1017verify_file (const void *item)
     1018{
     1019  const struct file *f = item;
     1020  const struct dep *d;
     1021
     1022  VERIFY_CACHED (f, name);
     1023  VERIFY_CACHED (f, hname);
     1024  VERIFY_CACHED (f, vpath);
     1025  VERIFY_CACHED (f, stem);
     1026
     1027  /* Check the deps.  */
     1028  for (d = f->deps; d != 0; d = d->next)
     1029    {
     1030      VERIFY_CACHED (d, name);
     1031      VERIFY_CACHED (d, stem);
     1032    }
     1033}
     1034
     1035void
     1036verify_file_data_base (void)
     1037{
     1038  hash_map (&files, verify_file);
     1039}
     1040
    10181041#define EXPANSION_INCREMENT(_l)  ((((_l) / 500) + 1) * 500)
    10191042
     
    10521075              }
    10531076
    1054             bcopy (f->name, p, l);
     1077            memcpy (p, f->name, l);
    10551078            p += l;
    10561079            *(p++) = ' ';
  • trunk/src/gmakenew/filedef.h

    r507 r903  
    2626struct file
    2727  {
    28     char *name;
    29     char *hname;                /* Hashed filename */
    30     char *vpath;                /* VPATH/vpath pathname */
     28    const char *name;
     29    const char *hname;          /* Hashed filename */
     30    const char *vpath;          /* VPATH/vpath pathname */
    3131    struct dep *deps;           /* all dependencies, including duplicates */
    3232    struct commands *cmds;      /* Commands to execute for this target.  */
    3333    int command_flags;          /* Flags OR'd in for cmds; see commands.h.  */
    34     char *stem;                 /* Implicit stem, if an implicit
    35                                    rule has been used */
     34    const char *stem;           /* Implicit stem, if an implicit
     35                                   rule has been used */
    3636    struct dep *also_make;      /* Targets that are made by making this.  */
    3737    FILE_TIMESTAMP last_mtime;  /* File's modtime, if already known.  */
     
    102102
    103103
    104 extern struct file *lookup_file PARAMS ((char *name));
    105 extern struct file *enter_file PARAMS ((char *name));
    106 extern struct dep *parse_prereqs PARAMS ((char *prereqs));
    107 extern void remove_intermediates PARAMS ((int sig));
    108 extern void snap_deps PARAMS ((void));
    109 extern void rename_file PARAMS ((struct file *file, char *name));
    110 extern void rehash_file PARAMS ((struct file *file, char *name));
    111 extern void set_command_state PARAMS ((struct file *file, enum cmd_state state));
    112 extern void notice_finished_file PARAMS ((struct file *file));
    113 extern void init_hash_files PARAMS ((void));
    114 extern char *build_target_list PARAMS ((char *old_list));
     104struct file *lookup_file (const char *name);
     105struct file *enter_file (const char *name);
     106struct dep *parse_prereqs (char *prereqs);
     107void remove_intermediates (int sig);
     108void snap_deps (void);
     109void rename_file (struct file *file, const char *name);
     110void rehash_file (struct file *file, const char *name);
     111void set_command_state (struct file *file, enum cmd_state state);
     112void notice_finished_file (struct file *file);
     113void init_hash_files (void);
     114char *build_target_list (char *old_list);
    115115
    116116#if FILE_TIMESTAMP_HI_RES
     
    153153   + 1 + 1 + 4 + 25)
    154154
    155 extern FILE_TIMESTAMP file_timestamp_cons PARAMS ((char const *,
    156                                                    time_t, int));
    157 extern FILE_TIMESTAMP file_timestamp_now PARAMS ((int *));
    158 extern void file_timestamp_sprintf PARAMS ((char *p, FILE_TIMESTAMP ts));
     155FILE_TIMESTAMP file_timestamp_cons (char const *, time_t, int);
     156FILE_TIMESTAMP file_timestamp_now (int *);
     157void file_timestamp_sprintf (char *p, FILE_TIMESTAMP ts);
    159158
    160159/* Return the mtime of file F (a struct file *), caching it.
     
    166165   The value is NONEXISTENT_MTIME if the file does not exist.  */
    167166#define file_mtime_no_search(f) file_mtime_1 ((f), 0)
    168 extern FILE_TIMESTAMP f_mtime PARAMS ((struct file *file, int search));
     167FILE_TIMESTAMP f_mtime (struct file *file, int search);
    169168#define file_mtime_1(f, v) \
    170169  ((f)->last_mtime == UNKNOWN_MTIME ? f_mtime ((f), v) : (f)->last_mtime)
  • 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
  • trunk/src/gmakenew/getloadavg.c

    r503 r903  
    707707        {
    708708          struct class_stats stats;
    709           bzero ((char *) &stats, sizeof stats);
     709          memset (&stats, '\0', sizeof stats);
    710710
    711711          desc.sd_type = CPUTYPE_CLASS;
  • trunk/src/gmakenew/hash.h

    r527 r903  
    278278
    279279#define ISTRING_COMPARE(X, Y, RESULT) do { \
    280   RESULT = strcmpi ((X), (Y)); \
     280  RESULT = strcasecmp ((X), (Y)); \
    281281} while (0)
    282282#define return_ISTRING_COMPARE(X, Y) do { \
    283   return strcmpi ((X), (Y)); \
     283  return strcasecmp ((X), (Y)); \
    284284} while (0)
    285285
  • trunk/src/gmakenew/implicit.c

    r503 r903  
    2626#include "commands.h" /* set_file_variables */
    2727
    28 static int
    29 pattern_search PARAMS ((struct file *file, int archive,
    30                         unsigned int depth, unsigned int recursions));
     28static int pattern_search (struct file *file, int archive,
     29                           unsigned int depth, unsigned int recursions);
    3130
    3231
     
    7271{
    7372  struct idep *next;              /* struct dep -compatible interface */
    74   char *name;                     /* name of the prerequisite */
     73  const char *name;               /* name of the prerequisite */
    7574  struct file *intermediate_file; /* intermediate file, 0 otherwise */
    76   char *intermediate_pattern;    /* pattern for intermediate file */
     75  const char *intermediate_pattern; /* pattern for intermediate file */
    7776  unsigned char had_stem;         /* had % substituted with stem */
    7877  unsigned char ignore_mtime;     /* ignore_mtime flag */
     
    8786    {
    8887      n = p->next;
    89 
    90       if (p->name)
    91         {
    92           struct file *f = p->intermediate_file;
    93 
    94           if (f != 0
    95               && (f->stem < f->name || f->stem > f->name + strlen (f->name)))
    96             free (f->stem);
    97 
    98           free (p->name);
    99         }
    100 
    10188      free (p);
    10289    }
     
    10996
    11097static char *
    111 get_next_word (char *buffer, unsigned int *length)
     98get_next_word (const char *buffer, unsigned int *length)
    11299{
    113   char *p = buffer, *beg;
     100  const char *p = buffer, *beg;
    114101  char c;
    115102
     
    182169    *length = p - beg;
    183170
    184   return beg;
     171  return (char *)beg;
    185172}
    186173
     
    204191{
    205192  /* Filename we are searching for a rule for.  */
    206   char *filename = archive ? strchr (file->name, '(') : file->name;
     193  const char *filename = archive ? strchr (file->name, '(') : file->name;
    207194
    208195  /* Length of FILENAME.  */
     
    226213
    227214  /* Names of possible dependencies are constructed in this buffer.  */
    228   register char *depname = (char *) alloca (namelen + max_pattern_dep_length);
     215  char *depname = alloca (namelen + max_pattern_dep_length);
    229216
    230217  /* The start and length of the stem of FILENAME for the current rule.  */
    231   register char *stem = 0;
    232   register unsigned int stemlen = 0;
    233   register unsigned int fullstemlen = 0;
     218  const char *stem = 0;
     219  unsigned int stemlen = 0;
     220  unsigned int fullstemlen = 0;
    234221
    235222  /* Buffer in which we store all the rules that are possibly applicable.  */
    236   struct rule **tryrules
    237     = (struct rule **) xmalloc (num_pattern_rules * max_pattern_targets
    238                                 * sizeof (struct rule *));
     223  struct rule **tryrules = xmalloc (num_pattern_rules * max_pattern_targets
     224                                    * sizeof (struct rule *));
    239225
    240226  /* Number of valid elements in TRYRULES.  */
     
    243229  /* The numbers of the rule targets of each rule
    244230     in TRYRULES that matched the target file.  */
    245   unsigned int *matches
    246     = (unsigned int *) alloca (num_pattern_rules * sizeof (unsigned int));
     231  unsigned int *matches = alloca (num_pattern_rules * sizeof (unsigned int));
    247232
    248233  /* Each element is nonzero if LASTSLASH was used in
    249234     matching the corresponding element of TRYRULES.  */
    250   char *checked_lastslash
    251     = (char *) alloca (num_pattern_rules * sizeof (char));
     235  char *checked_lastslash = alloca (num_pattern_rules * sizeof (char));
    252236
    253237  /* The index in TRYRULES of the rule we found.  */
     
    261245  int specific_rule_matched = 0;
    262246
    263   unsigned int i = 0;  /* uninit checks OK */
     247  unsigned int ri;  /* uninit checks OK */
    264248  struct rule *rule;
    265249  struct dep *dep, *expl_d;
    266 
    267   char *p, *vname;
    268250
    269251  struct idep *d;
     
    296278          lastslash = bslash;
    297279        if (lastslash == 0 && filename[0] && filename[1] == ':')
    298           lastslash = filename + 1;
     280          lastslash = (char *)filename + 1;
    299281      }
    300282#endif
     
    310292  for (rule = pattern_rules; rule != 0; rule = rule->next)
    311293    {
     294      unsigned int ti;
     295
    312296      /* If the pattern rule has deps but no commands, ignore it.
    313297         Users cancel built-in rules by redefining them without commands.  */
     
    323307        }
    324308
    325       for (i = 0; rule->targets[i] != 0; ++i)
     309      for (ti = 0; ti < rule->num; ++ti)
    326310        {
    327           char *target = rule->targets[i];
    328           char *suffix = rule->suffixes[i];
     311          const char *target = rule->targets[ti];
     312          const char *suffix = rule->suffixes[ti];
    329313          int check_lastslash;
    330314
     
    335319            continue;
    336320
    337           if (rule->lens[i] > namelen)
     321          if (rule->lens[ti] > namelen)
    338322            /* It can't possibly match.  */
    339323            continue;
     
    342326             find the stem: the part of the filename that matches the %.  */
    343327          stem = filename + (suffix - target - 1);
    344           stemlen = namelen - rule->lens[i] + 1;
     328          stemlen = namelen - rule->lens[ti] + 1;
    345329
    346330          /* Set CHECK_LASTSLASH if FILENAME contains a directory
     
    408392             that rule will be in TRYRULES more than once.  */
    409393          tryrules[nrules] = rule;
    410           matches[nrules] = i;
     394          matches[nrules] = ti;
    411395          checked_lastslash[nrules] = check_lastslash;
    412396          ++nrules;
     
    417401     retroactively reject any non-"terminal" rules that do always match.  */
    418402  if (specific_rule_matched)
    419     for (i = 0; i < nrules; ++i)
    420       if (!tryrules[i]->terminal)
     403    for (ri = 0; ri < nrules; ++ri)
     404      if (!tryrules[ri]->terminal)
    421405        {
    422           register unsigned int j;
    423           for (j = 0; tryrules[i]->targets[j] != 0; ++j)
    424             if (tryrules[i]->targets[j][1] == '\0')
    425               break;
    426           if (tryrules[i]->targets[j] != 0)
    427             tryrules[i] = 0;
     406          unsigned int j;
     407          for (j = 0; j < tryrules[ri]->num; ++j)
     408            if (tryrules[ri]->targets[j][1] == '\0')
     409              {
     410                tryrules[ri] = 0;
     411                break;
     412              }
    428413        }
    429414
     
    439424         and chain them in DEPS.  */
    440425
    441       for (i = 0; i < nrules; i++)
     426      for (ri = 0; ri < nrules; ri++)
    442427        {
    443428          struct file *f;
     
    446431          int file_variables_set = 0;
    447432
    448           rule = tryrules[i];
     433          rule = tryrules[ri];
    449434
    450435          remove_explicit_deps = 0;
     
    467452             find the stem: the part of the filename that matches the %.  */
    468453          stem = filename
    469             + (rule->suffixes[matches[i]] - rule->targets[matches[i]]) - 1;
    470           stemlen = namelen - rule->lens[matches[i]] + 1;
    471           check_lastslash = checked_lastslash[i];
     454            + (rule->suffixes[matches[ri]] - rule->targets[matches[ri]]) - 1;
     455          stemlen = namelen - rule->lens[matches[ri]] + 1;
     456          check_lastslash = checked_lastslash[ri];
    472457          if (check_lastslash)
    473458            {
     
    491476            {
    492477              unsigned int len;
     478              char *p;
    493479              char *p2;
    494480              unsigned int order_only = 0; /* Set if '|' was seen. */
     
    536522                      if (p2 < p + len)
    537523                        {
    538                           register unsigned int i = p2 - p;
    539                           bcopy (p, depname, i);
    540                           bcopy ("$*", depname + i, 2);
    541                           bcopy (p2 + 1, depname + i + 2, len - i - 1);
     524                          unsigned int i = p2 - p;
     525                          memcpy (depname, p, i);
     526                          memcpy (depname + i, "$*", 2);
     527                          memcpy (depname + i + 2, p2 + 1, len - i - 1);
    542528                          depname[len + 2 - 1] = '\0';
    543529
     
    549535                      else
    550536                        {
    551                           bcopy (p, depname, len);
     537                          memcpy (depname, p, len);
    552538                          depname[len] = '\0';
    553539                        }
     
    568554                       if (p2 < p + len)
    569555                        {
    570                           register unsigned int i = p2 - p;
    571                           bcopy (p, depname, i);
    572                           bcopy (stem_str, depname + i, stemlen);
    573                           bcopy (p2 + 1, depname + i + stemlen, len - i - 1);
     556                          unsigned int i = p2 - p;
     557                          memcpy (depname, p, i);
     558                          memcpy (depname + i, stem_str, stemlen);
     559                          memcpy (depname + i + stemlen, p2 + 1, len - i - 1);
    574560                          depname[len + stemlen - 1] = '\0';
    575561
     
    581567                      else
    582568                        {
    583                           bcopy (p, depname, len);
     569                          memcpy (depname, p, len);
    584570                          depname[len] = '\0';
    585571                        }
     
    619605                              if (add_dir)
    620606                                {
    621                                   char *p = d->name;
    622 
    623                                   d->name = xmalloc (strlen (p) + l + 1);
    624 
    625                                   bcopy (filename, d->name, l);
    626                                   bcopy (p, d->name + l, strlen (p) + 1);
    627 
    628                                   free (p);
     607                                  char *n = alloca (strlen (d->name) + l + 1);
     608                                  memcpy (n, filename, l);
     609                                  memcpy (n+l, d->name, strlen (d->name) + 1);
     610                                  d->name = strcache_add (n);
    629611                                }
    630612
     
    658640          for (d = deps; d != 0; d = d->next)
    659641            {
    660               char *name = d->name;
     642              const char *name = d->name;
    661643
    662644              if (file_impossible_p (name))
     
    670652                        : _("Rejecting impossible rule prerequisite `%s'.\n"),
    671653                        name));
    672                   tryrules[i] = 0;
     654                  tryrules[ri] = 0;
    673655
    674656                  failed = 1;
     
    706688              /* This code, given FILENAME = "lib/foo.o", dependency name
    707689                 "lib/foo.c", and VPATH=src, searches for "src/lib/foo.c".  */
    708               vname = name;
    709               if (vpath_search (&vname, (FILE_TIMESTAMP *) 0))
    710                 {
    711                   DBS (DB_IMPLICIT,
    712                        (_("Found prerequisite `%s' as VPATH `%s'\n"),
    713                         name,
    714                         vname));
    715 
    716                   free (vname);
    717                   continue;
    718                 }
     690              {
     691                const char *vname = vpath_search (name, 0);
     692                if (vname)
     693                  {
     694                    DBS (DB_IMPLICIT,
     695                         (_("Found prerequisite `%s' as VPATH `%s'\n"),
     696                          name, vname));
     697                    continue;
     698                  }
     699              }
    719700
    720701
     
    726707                {
    727708                  if (intermediate_file == 0)
    728                     intermediate_file
    729                       = (struct file *) alloca (sizeof (struct file));
     709                    intermediate_file = alloca (sizeof (struct file));
    730710
    731711                  DBS (DB_IMPLICIT,
     
    733713                        name));
    734714
    735                   bzero ((char *) intermediate_file, sizeof (struct file));
     715                  memset (intermediate_file, '\0', sizeof (struct file));
    736716                  intermediate_file->name = name;
    737717                  if (pattern_search (intermediate_file,
     
    740720                                      recursions + 1))
    741721                    {
     722                      d->intermediate_pattern = intermediate_file->name;
     723                      intermediate_file->name = strcache_add (name);
    742724                      d->intermediate_file = intermediate_file;
    743                       d->intermediate_pattern = intermediate_file->name;
    744 
    745                       intermediate_file->name = xstrdup (name);
    746725                      intermediate_file = 0;
    747726
     
    781760      /* If we found an applicable rule without
    782761         intermediate files, don't try with them.  */
    783       if (i < nrules)
     762      if (ri < nrules)
    784763        break;
    785764
     
    792771    goto done;
    793772
    794   foundrule = i;
     773  foundrule = ri;
    795774
    796775  /* If we are recursing, store the pattern that matched
     
    825804  for (d = deps; d != 0; d = d->next)
    826805    {
    827       register char *s;
     806      const char *s;
    828807
    829808      if (d->intermediate_file != 0)
     
    845824            f->precious = 1;
    846825          else
    847             f = enter_file (imf->name);
     826            f = enter_file (strcache_add (imf->name));
    848827
    849828          f->deps = imf->deps;
     
    865844            {
    866845              dep->file = enter_file (dep->name);
    867               /* enter_file uses dep->name _if_ we created a new file.  */
    868               if (dep->name != dep->file->name)
    869                 free (dep->name);
    870846              dep->name = 0;
    871847              dep->file->tried_implicit |= dep->changed;
     
    881857          dep->file = lookup_file (s);
    882858          if (dep->file == 0)
    883             /* enter_file consumes S's storage.  */
    884859            dep->file = enter_file (s);
    885           else
    886             /* A copy of S is already allocated in DEP->file->name.
    887                So we can free S.  */
    888             free (s);
    889860        }
    890861      else
    891         {
    892           dep->name = s;
    893         }
     862        dep->name = s;
    894863
    895864      if (d->intermediate_file == 0 && tryrules[foundrule]->terminal)
     
    916885      /* Always allocate new storage, since STEM might be
    917886         on the stack for an intermediate file.  */
    918       file->stem = savestring (stem, stemlen);
     887      file->stem = strcache_add_len (stem, stemlen);
    919888      fullstemlen = stemlen;
    920889    }
     
    922891    {
    923892      int dirlen = (lastslash + 1) - filename;
     893      char *sp;
    924894
    925895      /* We want to prepend the directory from
    926896         the original FILENAME onto the stem.  */
    927897      fullstemlen = dirlen + stemlen;
    928       file->stem = (char *) xmalloc (fullstemlen + 1);
    929       bcopy (filename, file->stem, dirlen);
    930       bcopy (stem, file->stem + dirlen, stemlen);
    931       file->stem[fullstemlen] = '\0';
     898      sp = alloca (fullstemlen + 1);
     899      memcpy (sp, filename, dirlen);
     900      memcpy (sp + dirlen, stem, stemlen);
     901      sp[fullstemlen] = '\0';
     902      file->stem = strcache_add (sp);
    932903    }
    933904
     
    945916     `also_make' member.  */
    946917
    947   if (rule->targets[1] != 0)
    948     for (i = 0; rule->targets[i] != 0; ++i)
    949       if (i != matches[foundrule])
     918  if (rule->num > 1)
     919    for (ri = 0; ri < rule->num; ++ri)
     920      if (ri != matches[foundrule])
    950921        {
     922          char *p = alloca (rule->lens[ri] + fullstemlen + 1);
    951923          struct file *f;
    952924          struct dep *new = alloc_dep ();
    953925
    954926          /* GKM FIMXE: handle '|' here too */
    955           new->name = p = (char *) xmalloc (rule->lens[i] + fullstemlen + 1);
    956           bcopy (rule->targets[i], p,
    957                  rule->suffixes[i] - rule->targets[i] - 1);
    958           p += rule->suffixes[i] - rule->targets[i] - 1;
    959           bcopy (file->stem, p, fullstemlen);
     927          memcpy (p, rule->targets[ri],
     928                  rule->suffixes[ri] - rule->targets[ri] - 1);
     929          p += rule->suffixes[ri] - rule->targets[ri] - 1;
     930          memcpy (p, file->stem, fullstemlen);
    960931          p += fullstemlen;
    961           bcopy (rule->suffixes[i], p,
    962                  rule->lens[i] - (rule->suffixes[i] - rule->targets[i]) + 1);
     932          memcpy (p, rule->suffixes[ri],
     933                  rule->lens[ri] - (rule->suffixes[ri] - rule->targets[ri])+1);
     934          new->name = strcache_add (p);
    963935          new->file = enter_file (new->name);
    964936          new->next = file->also_make;
    965937
    966938          /* Set precious flag. */
    967           f = lookup_file (rule->targets[i]);
     939          f = lookup_file (rule->targets[ri]);
    968940          if (f && f->precious)
    969941            new->file->precious = 1;
  • trunk/src/gmakenew/job.c

    r898 r903  
    103103# include <starlet.h>
    104104# include <lib$routines.h>
    105 static void vmsWaitForChildren PARAMS ((int *));
     105static void vmsWaitForChildren (int *);
    106106#endif
    107107
     
    135135
    136136#if !defined (wait) && !defined (POSIX)
    137 extern int wait ();
     137int wait ();
    138138#endif
    139139
     
    180180
    181181#ifndef HAVE_UNISTD_H
    182 # ifndef _MSC_VER
    183 extern int dup2 ();
    184 extern int execve ();
    185 extern void _exit ();
     182# ifndef _MSC_VER /* bird */
     183int dup2 ();
     184int execve ();
     185void _exit ();
     186# endif /* bird */
     187# ifndef VMS
     188int geteuid ();
     189int getegid ();
     190int setgid ();
     191int getgid ();
    186192# endif
    187 # ifndef VMS
    188 extern int geteuid ();
    189 extern int getegid ();
    190 extern int setgid ();
    191 extern int getgid ();
    192 # endif
    193 #endif
    194 
    195 extern char *allocated_variable_expand_for_file PARAMS ((char *line, struct file *file));
    196 
    197 extern int getloadavg PARAMS ((double loadavg[], int nelem));
    198 extern int start_remote_job PARAMS ((char **argv, char **envp, int stdin_fd,
    199                 int *is_remote, int *id_ptr, int *used_stdin));
    200 extern int start_remote_job_p PARAMS ((int));
    201 extern int remote_status PARAMS ((int *exit_code_ptr, int *signal_ptr,
    202                 int *coredump_ptr, int block));
    203 
    204 RETSIGTYPE child_handler PARAMS ((int));
    205 static void free_child PARAMS ((struct child *));
    206 static void start_job_command PARAMS ((struct child *child));
    207 static int load_too_high PARAMS ((void));
    208 static int job_next_command PARAMS ((struct child *));
    209 static int start_waiting_job PARAMS ((struct child *));
     193#endif
     194
     195int getloadavg (double loadavg[], int nelem);
     196int start_remote_job (char **argv, char **envp, int stdin_fd, int *is_remote,
     197                      int *id_ptr, int *used_stdin);
     198int start_remote_job_p (int);
     199int remote_status (int *exit_code_ptr, int *signal_ptr, int *coredump_ptr,
     200                   int block);
     201
     202RETSIGTYPE child_handler (int);
     203static void free_child (struct child *);
     204static void start_job_command (struct child *child);
     205static int load_too_high (void);
     206static int job_next_command (struct child *);
     207static int start_waiting_job (struct child *);
    210208
    211209
     
    310308        {
    311309          const unsigned final_size = path_size + size + 1;
    312           char *const path = (char *) xmalloc (final_size);
     310          char *const path = xmalloc (final_size);
    313311          memcpy (path, temp_path, final_size);
    314312          *fd = _open_osfhandle ((long)h, 0);
     
    369367  i = 0;
    370368  while (known_os2shells[i] != NULL) {
    371     if (stricmp (name, known_os2shells[i]) == 0) /* strcasecmp() */
     369    if (strcasecmp (name, known_os2shells[i]) == 0)
    372370      return 0; /* not a unix shell */
    373371    i++;
     
    386384
    387385static void
    388 child_error (char *target_name, int exit_code, int exit_sig, int coredump,
    389              int ignored)
     386child_error (const char *target_name,
     387             int exit_code, int exit_sig, int coredump, int ignored)
    390388{
    391389  if (ignored && silent_flag)
     
    435433    }
    436434
    437 #if defined __EMX__ && !defined(__INNOTEK_LIBC__)
     435#if defined __EMX__ && !defined(__INNOTEK_LIBC__) /* bird */
    438436  /* The signal handler must called only once! */
    439437  signal (SIGCHLD, SIG_DFL);
     
    510508
    511509         The test and decrement are not atomic; if it is compiled into:
    512                 register = dead_children - 1;
     510                register = dead_children - 1;
    513511                dead_children = register;
    514512         a SIGCHLD could come between the two instructions.
     
    925923      for (i = 0; i < child->file->cmds->ncommand_lines; ++i)
    926924        free (child->command_lines[i]);
    927       free ((char *) child->command_lines);
     925      free (child->command_lines);
    928926    }
    929927
     
    933931      while (*ep != 0)
    934932        free (*ep++);
    935       free ((char *) child->environment);
    936     }
    937 
    938   free ((char *) child);
     933      free (child->environment);
     934    }
     935
     936  free (child);
    939937}
    940938
     
    977975  struct sigaction sa;
    978976
    979 #if defined(__EMX__) && !defined(__KLIBC__)
     977#if defined(__EMX__) && !defined(__KLIBC__) /* bird */
    980978  /* The child handler must be turned off here.  */
    981979  signal (SIGCHLD, SIG_DFL);
    982980#endif
    983981
    984   bzero ((char *) &sa, sizeof sa);
     982  memset (&sa, '\0', sizeof sa);
    985983  sa.sa_handler = child_handler;
    986984  sa.sa_flags = set_handler ? 0 : SA_RESTART;
     
    10981096#ifndef VMS
    10991097      free (argv[0]);
    1100       free ((char *) argv);
     1098      free (argv);
    11011099#endif
    11021100      child->file->update_status = 1;
     
    11131111        {
    11141112          free (argv[0]);
    1115           free ((char *) argv);
     1113          free (argv);
    11161114        }
    11171115#endif
     
    11841182    {
    11851183      free (argv[0]);
    1186       free ((char *) argv);
     1184      free (argv);
    11871185      goto next_command;
    11881186    }
     
    11951193#ifndef VMS
    11961194      free (argv[0]);
    1197       free ((char *) argv);
     1195      free (argv);
    11981196#endif
    11991197      goto next_command;
     
    15061504#ifndef VMS
    15071505  free (argv[0]);
    1508   free ((char *) argv);
     1506  free (argv);
    15091507#endif
    15101508
     
    16251623new_job (struct file *file)
    16261624{
    1627   register struct commands *cmds = file->cmds;
    1628   register struct child *c;
     1625  struct commands *cmds = file->cmds;
     1626  struct child *c;
    16291627  char **lines;
    1630   register unsigned int i;
     1628  unsigned int i;
    16311629
    16321630  /* Let any previously decided-upon jobs that are waiting
     
    16411639
    16421640  /* Expand the command lines and store the results in LINES.  */
    1643   lines = (char **) xmalloc (cmds->ncommand_lines * sizeof (char *));
     1641  lines = xmalloc (cmds->ncommand_lines * sizeof (char *));
    16441642  for (i = 0; i < cmds->ncommand_lines; ++i)
    16451643    {
     
    16671665               we processed (where IN points) and the new chunk
    16681666               we are about to process (where REF points).  */
    1669             bcopy (in, out, ref - in);
     1667            memmove (out, in, ref - in);
    16701668
    16711669          /* Move both pointers past the boring stuff.  */
     
    17451743     `struct child', and add that to the chain.  */
    17461744
    1747   c = (struct child *) xmalloc (sizeof (struct child));
    1748   bzero ((char *)c, sizeof (struct child));
     1745  c = xmalloc (sizeof (struct child));
     1746  memset (c, '\0', sizeof (struct child));
    17491747  c->file = file;
    17501748  c->command_lines = lines;
     
    18661864  /* The job is now primed.  Start it running.
    18671865     (This will notice if there are in fact no commands.)  */
    1868   (void) start_waiting_job (c);
     1866  if (cmds->fileinfo.filenm)
     1867    DB (DB_BASIC, (_("Invoking commands from %s:%lu to update target `%s'.\n"),
     1868                   cmds->fileinfo.filenm, cmds->fileinfo.lineno,
     1869                   c->file->name));
     1870  else
     1871    DB (DB_BASIC, (_("Invoking builtin commands to update target `%s'.\n"),
     1872                   c->file->name));
     1873
     1874
     1875  start_waiting_job (c);
    18691876
    18701877#ifndef CONFIG_WITH_EXTENDED_NOTPARALLEL
     
    22932300# endif
    22942301
    2295         new_argv = (char **) alloca ((1 + argc + 1) * sizeof (char *));
     2302        new_argv = alloca ((1 + argc + 1) * sizeof (char *));
    22962303        new_argv[0] = shell;
    22972304
     
    24862493                             "shift", "switch", "test", "times", "trap",
    24872494                             "umask", "wait", "while", 0 };
    2488 #endif
    2489   register int i;
    2490   register char *p;
    2491   register char *ap;
     2495# ifdef HAVE_DOS_PATHS
     2496  /* This is required if the MSYS/Cygwin ports (which do not define
     2497     WINDOWS32) are compiled with HAVE_DOS_PATHS defined, which uses
     2498     sh_chars_sh[] directly (see below).  */
     2499  static char *sh_chars_sh = sh_chars;
     2500# endif  /* HAVE_DOS_PATHS */
     2501#endif
     2502  int i;
     2503  char *p;
     2504  char *ap;
    24922505  char *end;
    24932506  int instring, word_has_equals, seen_nonequals, last_argument_was_empty;
     
    25212534  else if (strcmp (shell, default_shell))
    25222535  {
    2523     char *s1 = _fullpath(NULL, shell, 0);
    2524     char *s2 = _fullpath(NULL, default_shell, 0);
    2525 
    2526     slow_flag = strcmp((s1 ? s1 : ""), (s2 ? s2 : ""));
     2536    char *s1 = _fullpath (NULL, shell, 0);
     2537    char *s2 = _fullpath (NULL, default_shell, 0);
     2538
     2539    slow_flag = strcmp ((s1 ? s1 : ""), (s2 ? s2 : ""));
    25272540
    25282541    if (s1)
     
    25352548#else  /* not WINDOWS32 */
    25362549#if defined (__MSDOS__) || defined (__EMX__)
    2537   else if (stricmp (shell, default_shell))
     2550  else if (strcasecmp (shell, default_shell))
    25382551    {
    25392552      extern int _is_unixy_shell (const char *_path);
     
    25872600
    25882601  /* More than 1 arg per character is impossible.  */
    2589   new_argv = (char **) xmalloc (i * sizeof (char *));
     2602  new_argv = xmalloc (i * sizeof (char *));
    25902603
    25912604  /* All the args can fit in a buffer as big as LINE is.   */
    2592   ap = new_argv[0] = argstr = (char *) xmalloc (i);
     2605  ap = new_argv[0] = argstr = xmalloc (i);
    25932606  end = ap + i;
    25942607
     
    26292642                  *(ap++) = *p;
    26302643                }
    2631               /* If there's a TAB here, skip it.  */
    2632               if (p[1] == '\t')
     2644              /* If there's a command prefix char here, skip it.  */
     2645              if (p[1] == cmd_prefix)
    26332646                ++p;
    26342647            }
     
    26792692                ++p;
    26802693
    2681                 /* If there is a tab after a backslash-newline, remove it.  */
    2682                 if (p[1] == '\t')
     2694                /* If there is a command prefix after a backslash-newline,
     2695                   remove it.  */
     2696                if (p[1] == cmd_prefix)
    26832697                  ++p;
    26842698
     
    28072821      /* Line was empty.  */
    28082822      free (argstr);
    2809       free ((char *)new_argv);
     2823      free (new_argv);
    28102824      return 0;
    28112825    }
     
    28202834      /* Free the old argument list we were working on.  */
    28212835      free (argstr);
    2822       free ((char *)new_argv);
     2836      free (new_argv);
    28232837    }
    28242838
     
    28332847    char *dptr;
    28342848
    2835     buffer = (char *)xmalloc (strlen (line)+1);
     2849    buffer = xmalloc (strlen (line)+1);
    28362850
    28372851    ptr = line;
     
    28502864    *dptr = 0;
    28512865
    2852     new_argv = (char **) xmalloc (2 * sizeof (char *));
     2866    new_argv = xmalloc (2 * sizeof (char *));
    28532867    new_argv[0] = buffer;
    28542868    new_argv[1] = 0;
     
    28862900    unsigned int line_len = strlen (line);
    28872901
    2888     char *new_line = (char *) alloca (shell_len + (sizeof (minus_c) - 1)
    2889                                       + (line_len * 2) + 1);
     2902    char *new_line = alloca (shell_len + (sizeof (minus_c)-1)
     2903                             + (line_len*2) + 1);
    28902904    char *command_ptr = NULL; /* used for batch_mode_shell mode */
    28912905
     
    28962910
    28972911    ap = new_line;
    2898     bcopy (shell, ap, shell_len);
     2912    memcpy (ap, shell, shell_len);
    28992913    ap += shell_len;
    2900     bcopy (minus_c, ap, sizeof (minus_c) - 1);
     2914    memcpy (ap, minus_c, sizeof (minus_c) - 1);
    29012915    ap += sizeof (minus_c) - 1;
    29022916    command_ptr = ap;
     
    29302944
    29312945            ++p;
    2932             if (p[1] == '\t')
     2946            if (p[1] == cmd_prefix)
    29332947              ++p;
    29342948
     
    29652979      /* Need to allocate new_argv, although it's unused, because
    29662980        start_job_command will want to free it and its 0'th element.  */
    2967       new_argv = (char **) xmalloc(2 * sizeof (char *));
     2981      new_argv = xmalloc(2 * sizeof (char *));
    29682982      new_argv[0] = xstrdup ("");
    29692983      new_argv[1] = NULL;
     
    29923006
    29933007      /* create argv */
    2994       new_argv = (char **) xmalloc(3 * sizeof (char *));
     3008      new_argv = xmalloc(3 * sizeof (char *));
    29953009      if (unixy_shell) {
    29963010        new_argv[0] = xstrdup (shell);
     
    30043018#endif /* WINDOWS32 */
    30053019    if (unixy_shell)
    3006       new_argv = construct_command_argv_internal (new_line, (char **) NULL,
    3007                                                   (char *) 0, (char *) 0,
    3008                                                   (char **) 0);
     3020      new_argv = construct_command_argv_internal (new_line, 0, 0, 0, 0);
    30093021#ifdef __EMX__
    30103022    else if (!unixy_shell)
     
    30233035              {
    30243036                q += 2; /* remove '\\' and '\n' */
    3025                 if (q[0] == '\t')
    3026                   q++; /* remove 1st tab in the next line */
     3037                /* Remove any command prefix in the next line */
     3038                if (q[0] == cmd_prefix)
     3039                  q++;
    30273040              }
    30283041            else
     
    30643077
    30653078          /* exactly 3 arguments + NULL */
    3066           new_argv = (char **) xmalloc (4 * sizeof (char *));
     3079          new_argv = xmalloc (4 * sizeof (char *));
    30673080          /* Exactly strlen(shell) + strlen("/c") + strlen(line) + 3 times
    30683081             the trailing '\0' */
    3069           new_argv[0] = (char *) malloc (sh_len + line_len + 5);
     3082          new_argv[0] = xmalloc (sh_len + line_len + 5);
    30703083          memcpy (new_argv[0], shell, sh_len + 1);
    30713084          new_argv[1] = new_argv[0] + sh_len + 1;
     
    30823095           instead of recursively calling ourselves, because we
    30833096           cannot backslash-escape the special characters (see above).  */
    3084         new_argv = (char **) xmalloc (sizeof (char *));
     3097        new_argv = xmalloc (sizeof (char *));
    30853098        line_len = strlen (new_line) - shell_len - sizeof (minus_c) + 1;
    30863099        new_argv[0] = xmalloc (line_len + 1);
     
    31403153    }
    31413154
    3142   argv = (char **)malloc (argc * sizeof (char *));
     3155  argv = xmalloc (argc * sizeof (char *));
    31433156  if (argv == 0)
    31443157    abort ();
  • trunk/src/gmakenew/job.h

    r520 r903  
    7171extern struct child *children;
    7272
    73 extern void new_job PARAMS ((struct file *file));
    74 extern void reap_children PARAMS ((int block, int err));
    75 extern void start_waiting_jobs PARAMS ((void));
     73void new_job (struct file *file);
     74void reap_children (int block, int err);
     75void start_waiting_jobs (void);
    7676
    77 extern char **construct_command_argv PARAMS ((char *line, char **restp, struct file *file, char** batch_file));
     77char **construct_command_argv (char *line, char **restp, struct file *file, char** batch_file);
    7878#ifdef VMS
    79 extern int child_execute_job PARAMS ((char *argv, struct child *child));
     79int child_execute_job (char *argv, struct child *child);
    8080#elif defined(__EMX__)
    81 extern int child_execute_job PARAMS ((int stdin_fd, int stdout_fd, char **argv, char **envp));
     81int child_execute_job (int stdin_fd, int stdout_fd, char **argv, char **envp);
    8282#else
    83 extern void child_execute_job PARAMS ((int stdin_fd, int stdout_fd, char **argv, char **envp));
     83void child_execute_job (int stdin_fd, int stdout_fd, char **argv, char **envp);
    8484#endif
    8585#ifdef _AMIGA
    86 extern void exec_command PARAMS ((char **argv));
     86void exec_command (char **argv);
    8787#elif defined(__EMX__)
    88 extern int exec_command PARAMS ((char **argv, char **envp));
     88int exec_command (char **argv, char **envp);
    8989#else
    90 extern void exec_command PARAMS ((char **argv, char **envp));
     90void exec_command (char **argv, char **envp);
    9191#endif
    9292
    9393extern unsigned int job_slots_used;
    9494
    95 extern void block_sigs PARAMS ((void));
     95void block_sigs (void);
    9696#ifdef POSIX
    97 extern void unblock_sigs PARAMS ((void));
     97void unblock_sigs (void);
    9898#else
    9999#ifdef  HAVE_SIGSETMASK
  • trunk/src/gmakenew/kbuild.h

    r813 r903  
    2828#define __kBuild_h__
    2929
    30 extern char *func_kbuild_source_tool PARAMS((char *o, char **argv, const char *pszFuncName));
    31 extern char *func_kbuild_object_base PARAMS((char *o, char **argv, const char *pszFuncName));
    32 extern char *func_kbuild_object_suffix PARAMS((char *o, char **argv, const char *pszFuncName));
    33 extern char *func_kbuild_source_prop PARAMS((char *o, char **argv, const char *pszFuncName));
    34 extern char *func_kbuild_source_one PARAMS((char *o, char **argv, const char *pszFuncName));
     30char *func_kbuild_source_tool(char *o, char **argv, const char *pszFuncName);
     31char *func_kbuild_object_base(char *o, char **argv, const char *pszFuncName);
     32char *func_kbuild_object_suffix(char *o, char **argv, const char *pszFuncName);
     33char *func_kbuild_source_prop(char *o, char **argv, const char *pszFuncName);
     34char *func_kbuild_source_one(char *o, char **argv, const char *pszFuncName);
    3535
    3636#endif
  • trunk/src/gmakenew/main.c

    r877 r903  
    11/* Argument parsing and main program of GNU Make.
    22Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
    3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
     31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
    44Foundation, Inc.
    55This file is part of GNU Make.
     
    5757#endif
    5858
    59 extern void init_dir PARAMS ((void));
    60 extern void remote_setup PARAMS ((void));
    61 extern void remote_cleanup PARAMS ((void));
    62 extern RETSIGTYPE fatal_error_signal PARAMS ((int sig));
    63 
    64 extern void print_variable_data_base PARAMS ((void));
    65 extern void print_dir_data_base PARAMS ((void));
    66 extern void print_rule_data_base PARAMS ((void));
    67 extern void print_file_data_base PARAMS ((void));
    68 extern void print_vpath_data_base PARAMS ((void));
     59void init_dir (void);
     60void remote_setup (void);
     61void remote_cleanup (void);
     62RETSIGTYPE fatal_error_signal (int sig);
     63
     64void print_variable_data_base (void);
     65void print_dir_data_base (void);
     66void print_rule_data_base (void);
     67void print_file_data_base (void);
     68void print_vpath_data_base (void);
     69
     70void verify_file_data_base (void);
    6971
    7072#if defined HAVE_WAITPID || defined HAVE_WAIT3
     
    7274#endif
    7375
    74 #if !defined(HAVE_UNISTD_H) && !defined(_MSC_VER)
    75 extern int chdir ();
     76#if !defined(HAVE_UNISTD_H) && !defined(_MSC_VER) /* bird */
     77int chdir ();
    7678#endif
    7779#ifndef STDC_HEADERS
    7880# ifndef sun                    /* Sun has an incorrect decl in a header.  */
    79 extern void exit PARAMS ((int)) __attribute__ ((noreturn));
     81void exit (int) __attribute__ ((noreturn));
    8082# endif
    81 extern double atof ();
    82 #endif
    83 
    84 static void clean_jobserver PARAMS ((int status));
    85 static void print_data_base PARAMS ((void));
    86 static void print_version PARAMS ((void));
    87 static void decode_switches PARAMS ((int argc, char **argv, int env));
    88 static void decode_env_switches PARAMS ((char *envar, unsigned int len));
    89 static void define_makeflags PARAMS ((int all, int makefile));
    90 static char *quote_for_env PARAMS ((char *out, char *in));
    91 static void initialize_global_hash_tables PARAMS ((void));
     83double atof ();
     84#endif
     85
     86static void clean_jobserver (int status);
     87static void print_data_base (void);
     88static void print_version (void);
     89static void decode_switches (int argc, char **argv, int env);
     90static void decode_env_switches (char *envar, unsigned int len);
     91static void define_makeflags (int all, int makefile);
     92static char *quote_for_env (char *out, const char *in);
     93static void initialize_global_hash_tables (void);
    9294
    9395
     
    104106        flag_off,               /* Turn int flag off.  */
    105107        string,                 /* One string per switch.  */
     108        filename,               /* A string containing a file name.  */
    106109        positive_int,           /* A positive integer.  */
    107110        floating,               /* A floating-point number (double).  */
     
    109112      } type;
    110113
    111     char *value_ptr;    /* Pointer to the value-holding variable.  */
     114    void *value_ptr;    /* Pointer to the value-holding variable.  */
    112115
    113116    unsigned int env:1;         /* Can come from MAKEFLAGS.  */
     
    115118    unsigned int no_makefile:1; /* Don't propagate when remaking makefiles.  */
    116119
    117     char *noarg_value;  /* Pointer to value used if no argument is given.  */
    118     char *default_value;/* Pointer to default value.  */
     120    const void *noarg_value;    /* Pointer to value used if no arg given.  */
     121    const void *default_value;  /* Pointer to default value.  */
    119122
    120123    char *long_name;            /* Long option name.  */
     
    130133struct stringlist
    131134  {
    132     char **list;        /* Nil-terminated list of strings.  */
     135    const char **list;  /* Nil-terminated list of strings.  */
    133136    unsigned int idx;   /* Index into above.  */
    134137    unsigned int max;   /* Number of pointers allocated.  */
     
    164167
    165168int db_level = 0;
     169
     170/* Output level (--verbosity).  */
     171
     172static struct stringlist *verbosity_flags;
    166173
    167174#ifdef WINDOWS32
     
    288295
    289296struct variable shell_var;
     297
     298/* This character introduces a command: it's the first char on the line.  */
     299
     300char cmd_prefix = '\t';
    290301
    291302#ifdef KMK
     
    382393  {
    383394    { 'b', ignore, 0, 0, 0, 0, 0, 0, 0 },
    384     { 'B', flag, (char *) &always_make_set, 1, 1, 0, 0, 0, "always-make" },
    385     { 'C', string, (char *) &directories, 0, 0, 0, 0, 0, "directory" },
    386     { 'd', flag, (char *) &debug_flag, 1, 1, 0, 0, 0, 0 },
    387     { CHAR_MAX+1, string, (char *) &db_flags, 1, 1, 0, "basic", 0, "debug" },
     395    { 'B', flag, &always_make_set, 1, 1, 0, 0, 0, "always-make" },
     396    { 'C', filename, &directories, 0, 0, 0, 0, 0, "directory" },
     397    { 'd', flag, &debug_flag, 1, 1, 0, 0, 0, 0 },
     398    { CHAR_MAX+1, string, &db_flags, 1, 1, 0, "basic", 0, "debug" },
    388399#ifdef WINDOWS32
    389     { 'D', flag, (char *) &suspend_flag, 1, 1, 0, 0, 0, "suspend-for-debug" },
    390 #endif
    391     { 'e', flag, (char *) &env_overrides, 1, 1, 0, 0, 0,
    392       "environment-overrides", },
    393     { 'f', string, (char *) &makefiles, 0, 0, 0, 0, 0, "file" },
    394     { 'h', flag, (char *) &print_usage_flag, 0, 0, 0, 0, 0, "help" },
    395     { 'i', flag, (char *) &ignore_errors_flag, 1, 1, 0, 0, 0,
    396       "ignore-errors" },
    397     { 'I', string, (char *) &include_directories, 1, 1, 0, 0, 0,
     400    { 'D', flag, &suspend_flag, 1, 1, 0, 0, 0, "suspend-for-debug" },
     401#endif
     402    { 'e', flag, &env_overrides, 1, 1, 0, 0, 0, "environment-overrides", },
     403    { 'f', filename, &makefiles, 0, 0, 0, 0, 0, "file" },
     404    { 'h', flag, &print_usage_flag, 0, 0, 0, 0, 0, "help" },
     405    { 'i', flag, &ignore_errors_flag, 1, 1, 0, 0, 0, "ignore-errors" },
     406    { 'I', filename, &include_directories, 1, 1, 0, 0, 0,
    398407      "include-dir" },
    399     { 'j', positive_int, (char *) &job_slots, 1, 1, 0, (char *) &inf_jobs,
    400       (char *) &default_job_slots, "jobs" },
    401     { CHAR_MAX+2, string, (char *) &jobserver_fds, 1, 1, 0, 0, 0,
    402       "jobserver-fds" },
    403     { 'k', flag, (char *) &keep_going_flag, 1, 1, 0, 0,
    404       (char *) &default_keep_going_flag, "keep-going" },
     408    { 'j', positive_int, &job_slots, 1, 1, 0, &inf_jobs, &default_job_slots,
     409      "jobs" },
     410    { CHAR_MAX+2, string, &jobserver_fds, 1, 1, 0, 0, 0, "jobserver-fds" },
     411    { 'k', flag, &keep_going_flag, 1, 1, 0, 0, &default_keep_going_flag,
     412      "keep-going" },
    405413#ifndef NO_FLOAT
    406     { 'l', floating, (char *) &max_load_average, 1, 1, 0,
    407       (char *) &default_load_average, (char *) &default_load_average,
    408       "load-average" },
     414    { 'l', floating, &max_load_average, 1, 1, 0, &default_load_average,
     415      &default_load_average, "load-average" },
    409416#else
    410     { 'l', positive_int, (char *) &max_load_average, 1, 1, 0,
    411       (char *) &default_load_average, (char *) &default_load_average,
    412       "load-average" },
    413 #endif
    414     { 'L', flag, (char *) &check_symlink_flag, 1, 1, 0, 0, 0,
    415       "check-symlink-times" },
     417    { 'l', positive_int, &max_load_average, 1, 1, 0, &default_load_average,
     418      &default_load_average, "load-average" },
     419#endif
     420    { 'L', flag, &check_symlink_flag, 1, 1, 0, 0, 0, "check-symlink-times" },
    416421    { 'm', ignore, 0, 0, 0, 0, 0, 0, 0 },
    417     { 'n', flag, (char *) &just_print_flag, 1, 1, 1, 0, 0, "just-print" },
    418     { 'o', string, (char *) &old_files, 0, 0, 0, 0, 0, "old-file" },
    419     { 'p', flag, (char *) &print_data_base_flag, 1, 1, 0, 0, 0,
    420       "print-data-base" },
     422    { 'n', flag, &just_print_flag, 1, 1, 1, 0, 0, "just-print" },
     423    { 'o', filename, &old_files, 0, 0, 0, 0, 0, "old-file" },
     424    { 'p', flag, &print_data_base_flag, 1, 1, 0, 0, 0, "print-data-base" },
    421425#ifdef CONFIG_PRETTY_COMMAND_PRINTING
    422426    { CHAR_MAX+6, flag, (char *) &pretty_command_printing, 1, 1, 1, 0, 0,
     
    427431      (char *) &process_priority, (char *) &process_priority, "priority" },
    428432#endif
    429     { 'q', flag, (char *) &question_flag, 1, 1, 1, 0, 0, "question" },
    430     { 'r', flag, (char *) &no_builtin_rules_flag, 1, 1, 0, 0, 0,
    431       "no-builtin-rules" },
    432     { 'R', flag, (char *) &no_builtin_variables_flag, 1, 1, 0, 0, 0,
     433    { 'q', flag, &question_flag, 1, 1, 1, 0, 0, "question" },
     434    { 'r', flag, &no_builtin_rules_flag, 1, 1, 0, 0, 0, "no-builtin-rules" },
     435    { 'R', flag, &no_builtin_variables_flag, 1, 1, 0, 0, 0,
    433436      "no-builtin-variables" },
    434     { 's', flag, (char *) &silent_flag, 1, 1, 0, 0, 0, "silent" },
    435     { 'S', flag_off, (char *) &keep_going_flag, 1, 1, 0, 0,
    436       (char *) &default_keep_going_flag, "no-keep-going" },
    437     { 't', flag, (char *) &touch_flag, 1, 1, 1, 0, 0, "touch" },
    438     { 'v', flag, (char *) &print_version_flag, 1, 1, 0, 0, 0, "version" },
    439     { 'w', flag, (char *) &print_directory_flag, 1, 1, 0, 0, 0,
    440       "print-directory" },
    441     { CHAR_MAX+3, flag, (char *) &inhibit_print_directory_flag, 1, 1, 0, 0, 0,
     437    { 's', flag, &silent_flag, 1, 1, 0, 0, 0, "silent" },
     438    { 'S', flag_off, &keep_going_flag, 1, 1, 0, 0, &default_keep_going_flag,
     439      "no-keep-going" },
     440    { 't', flag, &touch_flag, 1, 1, 1, 0, 0, "touch" },
     441    { 'v', flag, &print_version_flag, 1, 1, 0, 0, 0, "version" },
     442    { CHAR_MAX+3, string, &verbosity_flags, 1, 1, 0, 0, 0,
     443      "verbosity" },
     444    { 'w', flag, &print_directory_flag, 1, 1, 0, 0, 0, "print-directory" },
     445    { CHAR_MAX+4, flag, &inhibit_print_directory_flag, 1, 1, 0, 0, 0,
    442446      "no-print-directory" },
    443     { 'W', string, (char *) &new_files, 0, 0, 0, 0, 0, "what-if" },
    444     { CHAR_MAX+4, flag, (char *) &warn_undefined_variables_flag, 1, 1, 0, 0, 0,
     447    { 'W', filename, &new_files, 0, 0, 0, 0, 0, "what-if" },
     448    { CHAR_MAX+5, flag, &warn_undefined_variables_flag, 1, 1, 0, 0, 0,
    445449      "warn-undefined-variables" },
    446450    { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
     
    588592}
    589593
    590 static struct file *
    591 enter_command_line_file (char *name)
     594static const char *
     595expand_command_line_file (char *name)
    592596{
     597  const char *cp;
     598  char *expanded = 0;
     599
    593600  if (name[0] == '\0')
    594601    fatal (NILF, _("empty string invalid as file name"));
     
    596603  if (name[0] == '~')
    597604    {
    598       char *expanded = tilde_expand (name);
     605      expanded = tilde_expand (name);
    599606      if (expanded != 0)
    600         name = expanded;        /* Memory leak; I don't care.  */
     607        name = expanded;
    601608    }
    602609
     
    622629    }
    623630
    624   return enter_file (xstrdup (name));
     631  cp = strcache_add (name);
     632
     633  if (expanded)
     634    free (expanded);
     635
     636  return cp;
    625637}
    626638
     
    638650decode_debug_flags (void)
    639651{
    640   char **pp;
     652  const char **pp;
    641653
    642654  if (debug_flag)
     
    814826
    815827int
    816 find_and_set_default_shell (char *token)
     828find_and_set_default_shell (const char *token)
    817829{
    818830  int sh_found = 0;
     831  char *atoken = 0;
    819832  char *search_token;
    820833  char *tokend;
     
    825838    search_token = default_shell;
    826839  else
    827     search_token = token;
    828 
     840    atoken = search_token = xstrdup (token);
    829841
    830842  /* If the user explicitly requests the DOS cmd shell, obey that request.
     
    836848        || (tokend > search_token
    837849            && (tokend[-1] == '/' || tokend[-1] == '\\')))
    838        && !strcmpi (tokend, "cmd"))
     850       && !strcasecmp (tokend, "cmd"))
    839851      || ((tokend - 4 == search_token
    840852           || (tokend - 4 > search_token
    841853               && (tokend[-5] == '/' || tokend[-5] == '\\')))
    842           && !strcmpi (tokend - 4, "cmd.exe"))) {
     854          && !strcasecmp (tokend - 4, "cmd.exe"))) {
    843855    batch_mode_shell = 1;
    844856    unixy_shell = 0;
     
    852864    /* no new information, path already set or known */
    853865    sh_found = 1;
    854   } else if (file_exists_p(search_token)) {
     866  } else if (file_exists_p (search_token)) {
    855867    /* search token path was found */
    856     sprintf(sh_path, "%s", search_token);
    857     default_shell = xstrdup(w32ify(sh_path,0));
     868    sprintf (sh_path, "%s", search_token);
     869    default_shell = xstrdup (w32ify (sh_path, 0));
    858870    DB (DB_VERBOSE,
    859871        (_("find_and_set_shell setting default_shell = %s\n"), default_shell));
     
    868880
    869881      p  = v->value;
    870       ep = strchr(p, PATH_SEPARATOR_CHAR);
     882      ep = strchr (p, PATH_SEPARATOR_CHAR);
    871883
    872884      while (ep && *ep) {
    873885        *ep = '\0';
    874886
    875         if (dir_file_exists_p(p, search_token)) {
    876           sprintf(sh_path, "%s/%s", p, search_token);
    877           default_shell = xstrdup(w32ify(sh_path,0));
     887        if (dir_file_exists_p (p, search_token)) {
     888          sprintf (sh_path, "%s/%s", p, search_token);
     889          default_shell = xstrdup (w32ify (sh_path, 0));
    878890          sh_found = 1;
    879891          *ep = PATH_SEPARATOR_CHAR;
    880892
    881893          /* terminate loop */
    882           p += strlen(p);
     894          p += strlen (p);
    883895        } else {
    884896          *ep = PATH_SEPARATOR_CHAR;
     
    886898        }
    887899
    888         ep = strchr(p, PATH_SEPARATOR_CHAR);
     900        ep = strchr (p, PATH_SEPARATOR_CHAR);
    889901      }
    890902
    891903      /* be sure to check last element of Path */
    892       if (p && *p && dir_file_exists_p(p, search_token)) {
    893           sprintf(sh_path, "%s/%s", p, search_token);
    894           default_shell = xstrdup(w32ify(sh_path,0));
     904      if (p && *p && dir_file_exists_p (p, search_token)) {
     905          sprintf (sh_path, "%s/%s", p, search_token);
     906          default_shell = xstrdup (w32ify (sh_path, 0));
    895907          sh_found = 1;
    896908      }
     
    916928  /* naive test */
    917929  if (!unixy_shell && sh_found &&
    918       (strstr(default_shell, "sh") || strstr(default_shell, "SH"))) {
     930      (strstr (default_shell, "sh") || strstr (default_shell, "SH"))) {
    919931    unixy_shell = 1;
    920932    batch_mode_shell = 0;
     
    924936  batch_mode_shell = 1;
    925937#endif
     938
     939  if (atoken)
     940    free (atoken);
    926941
    927942  return (sh_found);
     
    9951010#endif  /* WINDOWS32 */
    9961011
    997 #ifdef  __MSDOS__
    998 
     1012#ifdef __MSDOS__
    9991013static void
    10001014msdos_return_to_initial_directory (void)
     
    10031017    chdir (directory_before_chdir);
    10041018}
    1005 #endif
    1006 
    1007 #ifndef _MSC_VER
    1008 extern char *mktemp PARAMS ((char *template));
    1009 #endif
    1010 extern int mkstemp PARAMS ((char *template));
     1019#endif  /* __MSDOS__ */
     1020
     1021#ifndef _MSC_VER /* bird */
     1022char *mktemp (char *template);
     1023#endif
     1024int mkstemp (char *template);
    10111025
    10121026FILE *
     
    10611075{
    10621076  static char *stdin_nm = 0;
    1063   struct file *f;
    1064   int i;
    10651077  int makefile_status = MAKE_SUCCESS;
    1066   char **p;
    10671078  struct dep *read_makefiles;
    10681079  PATH_VAR (current_directory);
     
    11931204# else  /* setvbuf not reversed.  */
    11941205  /* Some buggy systems lose if we pass 0 instead of allocating ourselves.  */
    1195   setvbuf (stdout, (char *) 0, _IOLBF, BUFSIZ);
     1206  setvbuf (stdout, 0, _IOLBF, BUFSIZ);
    11961207# endif /* setvbuf reversed.  */
    11971208#elif HAVE_SETLINEBUF
     
    13011312
    13021313#ifndef _AMIGA
    1303   for (i = 0; envp[i] != 0; ++i)
    1304     {
    1305       int do_not_define = 0;
    1306       char *ep = envp[i];
    1307 
    1308       while (*ep != '\0' && *ep != '=')
    1309         ++ep;
     1314  {
     1315    unsigned int i;
     1316
     1317    for (i = 0; envp[i] != 0; ++i)
     1318      {
     1319        int do_not_define = 0;
     1320        char *ep = envp[i];
     1321
     1322        while (*ep != '\0' && *ep != '=')
     1323          ++ep;
    13101324#ifdef WINDOWS32
    1311       if (!unix_path && strneq(envp[i], "PATH=", 5))
    1312         unix_path = ep+1;
    1313       else if (!strnicmp(envp[i], "Path=", 5)) {
    1314         do_not_define = 1; /* it gets defined after loop exits */
    1315         if (!windows32_path)
    1316           windows32_path = ep+1;
     1325        if (!unix_path && strneq(envp[i], "PATH=", 5))
     1326          unix_path = ep+1;
     1327        else if (!strnicmp(envp[i], "Path=", 5)) {
     1328          do_not_define = 1; /* it gets defined after loop exits */
     1329          if (!windows32_path)
     1330            windows32_path = ep+1;
     1331        }
     1332#endif
     1333        /* The result of pointer arithmetic is cast to unsigned int for
     1334           machines where ptrdiff_t is a different size that doesn't widen
     1335           the same.  */
     1336        if (!do_not_define)
     1337          {
     1338            struct variable *v;
     1339
     1340            v = define_variable (envp[i], (unsigned int) (ep - envp[i]),
     1341                                 ep + 1, o_env, 1);
     1342            /* Force exportation of every variable culled from the
     1343               environment.  We used to rely on target_environment's
     1344               v_default code to do this.  But that does not work for the
     1345               case where an environment variable is redefined in a makefile
     1346               with `override'; it should then still be exported, because it
     1347               was originally in the environment.  */
     1348            v->export = v_export;
     1349
     1350            /* Another wrinkle is that POSIX says the value of SHELL set in
     1351               the makefile won't change the value of SHELL given to
     1352               subprocesses.  */
     1353            if (streq (v->name, "SHELL"))
     1354              {
     1355#ifndef __MSDOS__
     1356                v->export = v_noexport;
     1357#endif
     1358                shell_var.name = "SHELL";
     1359                shell_var.value = xstrdup (ep + 1);
     1360              }
     1361
     1362            /* If MAKE_RESTARTS is set, remember it but don't export it.  */
     1363            if (streq (v->name, "MAKE_RESTARTS"))
     1364              {
     1365                v->export = v_noexport;
     1366                restarts = (unsigned int) atoi (ep + 1);
     1367              }
     1368          }
    13171369      }
    1318 #endif
    1319       /* The result of pointer arithmetic is cast to unsigned int for
    1320          machines where ptrdiff_t is a different size that doesn't widen
    1321          the same.  */
    1322       if (!do_not_define)
    1323         {
    1324           struct variable *v;
    1325 
    1326           v = define_variable (envp[i], (unsigned int) (ep - envp[i]),
    1327                                ep + 1, o_env, 1);
    1328           /* Force exportation of every variable culled from the environment.
    1329              We used to rely on target_environment's v_default code to do this.
    1330              But that does not work for the case where an environment variable
    1331              is redefined in a makefile with `override'; it should then still
    1332              be exported, because it was originally in the environment.  */
    1333           v->export = v_export;
    1334 
    1335           /* Another wrinkle is that POSIX says the value of SHELL set in the
    1336              makefile won't change the value of SHELL given to subprocesses  */
    1337           if (streq (v->name, "SHELL"))
    1338             {
    1339 #ifndef __MSDOS__
    1340               v->export = v_noexport;
    1341 #endif
    1342               shell_var.name = "SHELL";
    1343               shell_var.value = xstrdup (ep + 1);
    1344             }
    1345 
    1346           /* If MAKE_RESTARTS is set, remember it but don't export it.  */
    1347           if (streq (v->name, "MAKE_RESTARTS"))
    1348             {
    1349               v->export = v_noexport;
    1350               restarts = (unsigned int) atoi (ep + 1);
    1351             }
    1352         }
    1353     }
     1370  }
    13541371#ifdef WINDOWS32
    13551372    /* If we didn't find a correctly spelled PATH we define PATH as
     
    13971414#if 0
    13981415  /* People write things like:
    1399         MFLAGS="CC=gcc -pipe" "CFLAGS=-g"
     1416        MFLAGS="CC=gcc -pipe" "CFLAGS=-g"
    14001417     and we set the -p, -i and -e switches.  Doesn't seem quite right.  */
    14011418  decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS"));
     
    14641481      && argv[0] != 0
    14651482      && (argv[0][0] != '/' && (argv[0][0] == '\0' || argv[0][1] != ':'))
    1466 #ifdef __EMX__
     1483# ifdef __EMX__
    14671484      /* do not prepend cwd if argv[0] contains no '/', e.g. "make" */
    14681485      && (strchr (argv[0], '/') != 0 || strchr (argv[0], '\\') != 0)
    14691486# endif
    14701487      )
    1471     argv[0] = concat (current_directory, "/", argv[0]);
     1488    argv[0] = xstrdup (concat (current_directory, "/", argv[0]));
    14721489#else  /* !__MSDOS__ */
    14731490  if (current_directory[0] != '\0'
    1474       && argv[0] != 0 && argv[0][0] != '/' && strchr (argv[0], '/') != 0)
    1475     argv[0] = concat (current_directory, "/", argv[0]);
     1491      && argv[0] != 0 && argv[0][0] != '/' && strchr (argv[0], '/') != 0
     1492#ifdef HAVE_DOS_PATHS
     1493      && (argv[0][0] != '\\' && (!argv[0][0] || argv[0][1] != ':'))
     1494      && strchr (argv[0], '\\') != 0
     1495#endif
     1496      )
     1497    argv[0] = xstrdup (concat (current_directory, "/", argv[0]));
    14761498#endif /* !__MSDOS__ */
    14771499#endif /* WINDOWS32 */
     
    15071529
    15081530      /* Now allocate a buffer big enough and fill it.  */
    1509       p = value = (char *) alloca (len);
     1531      p = value = alloca (len);
    15101532      for (cv = command_variables; cv != 0; cv = cv->next)
    15111533        {
     
    15901612      }
    15911613    }
    1592 #endif
     1614#endif /* KMK */
    15931615
    15941616  /* If there were -C flags, move ourselves about.  */
    15951617  if (directories != 0)
    1596     for (i = 0; directories->list[i] != 0; ++i)
    1597       {
    1598         char *dir = directories->list[i];
    1599         char *expanded = 0;
    1600         if (dir[0] == '~')
    1601           {
    1602             expanded = tilde_expand (dir);
    1603             if (expanded != 0)
    1604               dir = expanded;
    1605           }
     1618    {
     1619      unsigned int i;
     1620      for (i = 0; directories->list[i] != 0; ++i)
     1621        {
     1622          const char *dir = directories->list[i];
    16061623#ifdef WINDOWS32
    1607         /* WINDOWS32 chdir() doesn't work if the directory has a trailing '/'
    1608            But allow -C/ just in case someone wants that.  */
    1609         {
    1610           char *p = dir + strlen (dir) - 1;
    1611           while (p > dir && (p[0] == '/' || p[0] == '\\'))
    1612             --p;
    1613           p[1] = '\0';
     1624          /* WINDOWS32 chdir() doesn't work if the directory has a trailing '/'
     1625             But allow -C/ just in case someone wants that.  */
     1626          {
     1627            char *p = (char *)dir + strlen (dir) - 1;
     1628            while (p > dir && (p[0] == '/' || p[0] == '\\'))
     1629              --p;
     1630            p[1] = '\0';
     1631          }
     1632#endif
     1633          if (chdir (dir) < 0)
     1634            pfatal_with_name (dir);
    16141635        }
    1615 #endif
    1616         if (chdir (dir) < 0)
    1617           pfatal_with_name (dir);
    1618         if (expanded)
    1619           free (expanded);
    1620       }
     1636    }
    16211637
    16221638#ifdef WINDOWS32
     
    16561672  /* Construct the list of include directories to search.  */
    16571673
    1658   construct_include_path (include_directories == 0 ? (char **) 0
    1659                           : include_directories->list);
     1674  construct_include_path (include_directories == 0
     1675                          ? 0 : include_directories->list);
    16601676
    16611677  /* Figure out where we are now, after chdir'ing.  */
     
    16881704  if (makefiles != 0)
    16891705    {
    1690       register unsigned int i;
     1706      unsigned int i;
    16911707      for (i = 0; i < makefiles->idx; ++i)
    16921708        if (makefiles->list[i][0] == '-' && makefiles->list[i][1] == '\0')
     
    17211737              tmpdir = DEFAULT_TMPDIR;
    17221738
    1723             template = (char *) alloca (strlen (tmpdir)
    1724                                         + sizeof (DEFAULT_TMPFILE) + 1);
     1739            template = alloca (strlen (tmpdir) + sizeof (DEFAULT_TMPFILE) + 1);
    17251740            strcpy (template, tmpdir);
    17261741
     
    17461761                  pfatal_with_name (_("fwrite (temporary file)"));
    17471762              }
    1748             (void) fclose (outfile);
     1763            fclose (outfile);
    17491764
    17501765            /* Replace the name that read_all_makefiles will
    17511766               see with the name of the temporary file.  */
    1752             makefiles->list[i] = xstrdup (stdin_nm);
     1767            makefiles->list[i] = strcache_add (stdin_nm);
    17531768
    17541769            /* Make sure the temporary file will not be remade.  */
    1755             f = enter_file (stdin_nm);
    1756             f->updated = 1;
    1757             f->update_status = 0;
    1758             f->command_state = cs_finished;
    1759             /* Can't be intermediate, or it'll be removed too early for
    1760                make re-exec.  */
    1761             f->intermediate = 0;
    1762             f->dontcare = 0;
     1770            {
     1771              struct file *f = enter_file (strcache_add (stdin_nm));
     1772              f->updated = 1;
     1773              f->update_status = 0;
     1774              f->command_state = cs_finished;
     1775              /* Can't be intermediate, or it'll be removed too early for
     1776                 make re-exec.  */
     1777              f->intermediate = 0;
     1778              f->dontcare = 0;
     1779            }
    17631780          }
    17641781    }
    17651782
    1766 #if !defined(__EMX__) || defined(__KLIBC__) /* Don't use a SIGCHLD handler for good old EMX */
     1783#if !defined(__EMX__) || defined(__KLIBC__) /* Don't use a SIGCHLD handler for good old EMX (bird) */
    17671784#if defined(MAKE_JOBSERVER) || !defined(HAVE_WAIT_NOHANG)
    17681785  /* Set up to handle children dying.  This must be done before
     
    17791796     If none of these are true, we don't need a signal handler at all.  */
    17801797  {
    1781     extern RETSIGTYPE child_handler PARAMS ((int sig));
     1798    RETSIGTYPE child_handler (int sig);
    17821799# if defined SIGCHLD
    17831800    bsd_signal (SIGCHLD, child_handler);
     
    18191836  define_default_variables ();
    18201837
    1821   default_file = enter_file (".DEFAULT");
     1838  default_file = enter_file (strcache_add (".DEFAULT"));
    18221839
    18231840  {
     
    18291846
    18301847  read_makefiles
    1831     = read_all_makefiles (makefiles == 0 ? (char **) 0 : makefiles->list);
     1848    = read_all_makefiles (makefiles == 0 ? 0 : makefiles->list);
    18321849
    18331850#ifdef WINDOWS32
     
    18841901  if (jobserver_fds)
    18851902  {
    1886     char *cp;
     1903    const char *cp;
    18871904    unsigned int ui;
    18881905
     
    18981915      fatal (NILF,
    18991916             _("internal error: invalid --jobserver-fds string `%s'"), cp);
     1917
     1918    DB (DB_JOBS,
     1919        (_("Jobserver client (fds %d,%d)\n"), job_fds[0], job_fds[1]));
    19001920
    19011921    /* The combination of a pipe + !job_slots means we're using the
     
    19401960  if (job_slots > 1)
    19411961    {
     1962      char *cp;
    19421963      char c = '+';
    19431964
     
    19631984      /* Fill in the jobserver_fds struct for our children.  */
    19641985
     1986      cp = xmalloc ((sizeof ("1024")*2)+1);
     1987      sprintf (cp, "%d,%d", job_fds[0], job_fds[1]);
     1988
    19651989      jobserver_fds = (struct stringlist *)
    19661990                        xmalloc (sizeof (struct stringlist));
    1967       jobserver_fds->list = (char **) xmalloc (sizeof (char *));
    1968       jobserver_fds->list[0] = xmalloc ((sizeof ("1024")*2)+1);
    1969 
    1970       sprintf (jobserver_fds->list[0], "%d,%d", job_fds[0], job_fds[1]);
     1991      jobserver_fds->list = xmalloc (sizeof (char *));
     1992      jobserver_fds->list[0] = cp;
    19711993      jobserver_fds->idx = 1;
    19721994      jobserver_fds->max = 1;
     
    20182040
    20192041  if (old_files != 0)
    2020     for (p = old_files->list; *p != 0; ++p)
    2021       {
    2022         f = enter_command_line_file (*p);
    2023         f->last_mtime = f->mtime_before_update = OLD_MTIME;
    2024         f->updated = 1;
    2025         f->update_status = 0;
    2026         f->command_state = cs_finished;
    2027       }
     2042    {
     2043      const char **p;
     2044      for (p = old_files->list; *p != 0; ++p)
     2045        {
     2046          struct file *f = enter_file (*p);
     2047          f->last_mtime = f->mtime_before_update = OLD_MTIME;
     2048          f->updated = 1;
     2049          f->update_status = 0;
     2050          f->command_state = cs_finished;
     2051        }
     2052    }
    20282053
    20292054  if (!restarts && new_files != 0)
    20302055    {
     2056      const char **p;
    20312057      for (p = new_files->list; *p != 0; ++p)
    20322058        {
    2033           f = enter_command_line_file (*p);
     2059          struct file *f = enter_file (*p);
    20342060          f->last_mtime = f->mtime_before_update = NEW_MTIME;
    20352061        }
     
    20632089        while (d != 0)
    20642090          {
    2065             register struct file *f = d->file;
     2091            struct file *f = d->file;
    20662092            if (f->double_colon)
    20672093              for (f = f->double_colon; f != NULL; f = f->prev)
     
    20962122            if (f == NULL || !f->double_colon)
    20972123              {
    2098                 makefile_mtimes = (FILE_TIMESTAMP *)
    2099                   xrealloc ((char *) makefile_mtimes,
    2100                             (mm_idx + 1) * sizeof (FILE_TIMESTAMP));
     2124                makefile_mtimes = xrealloc (makefile_mtimes,
     2125                                            (mm_idx+1)
     2126                                            * sizeof (FILE_TIMESTAMP));
    21012127                makefile_mtimes[mm_idx++] = file_mtime_no_search (d->file);
    21022128                last = d;
     
    22172243                    char *p = &argv[i][2];
    22182244                    if (*p == '\0')
    2219                       argv[++i] = makefiles->list[j];
     2245                      /* This cast is OK since we never modify argv.  */
     2246                      argv[++i] = (char *) makefiles->list[j];
    22202247                    else
    2221                       argv[i] = concat ("-f", makefiles->list[j], "");
     2248                      argv[i] = xstrdup (concat ("-f", makefiles->list[j], ""));
    22222249                    ++j;
    22232250                  }
     
    22272254          if (stdin_nm)
    22282255            {
    2229               nargv = (char **) xmalloc ((nargc + 2) * sizeof (char *));
    2230               bcopy ((char *) argv, (char *) nargv, argc * sizeof (char *));
    2231               nargv[nargc++] = concat ("-o", stdin_nm, "");
     2256              nargv = xmalloc ((nargc + 2) * sizeof (char *));
     2257              memcpy (nargv, argv, argc * sizeof (char *));
     2258              nargv[nargc++] = xstrdup (concat ("-o", stdin_nm, ""));
    22322259              nargv[nargc] = 0;
    22332260            }
     
    22352262          if (directories != 0 && directories->idx > 0)
    22362263            {
    2237               char bad;
     2264              int bad = 1;
    22382265              if (directory_before_chdir != 0)
    22392266                {
    22402267                  if (chdir (directory_before_chdir) < 0)
    2241                     {
    22422268                      perror_with_name ("chdir", "");
    2243                       bad = 1;
    2244                     }
    22452269                  else
    22462270                    bad = 0;
    22472271                }
    2248               else
    2249                 bad = 1;
    22502272              if (bad)
    22512273                fatal (NILF, _("Couldn't change back to original directory."));
     
    22642286
    22652287#ifndef _AMIGA
    2266           for (p = environ; *p != 0; ++p)
    2267             {
    2268               if (strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH)
    2269                   && (*p)[MAKELEVEL_LENGTH] == '=')
    2270                 {
    2271                   /* The SGI compiler apparently can't understand
    2272                      the concept of storing the result of a function
    2273                      in something other than a local variable.  */
    2274                   char *sgi_loses;
    2275                   sgi_loses = (char *) alloca (40);
    2276                   *p = sgi_loses;
    2277                   sprintf (*p, "%s=%u", MAKELEVEL_NAME, makelevel);
    2278                 }
    2279               if (strneq (*p, "MAKE_RESTARTS=", 14))
    2280                 {
    2281                   char *sgi_loses;
    2282                   sgi_loses = (char *) alloca (40);
    2283                   *p = sgi_loses;
    2284                   sprintf (*p, "MAKE_RESTARTS=%u", restarts);
    2285                   restarts = 0;
    2286                 }
    2287             }
     2288          {
     2289            char **p;
     2290            for (p = environ; *p != 0; ++p)
     2291              {
     2292                if (strneq (*p, MAKELEVEL_NAME, MAKELEVEL_LENGTH)
     2293                    && (*p)[MAKELEVEL_LENGTH] == '=')
     2294                  {
     2295                    *p = alloca (40);
     2296                    sprintf (*p, "%s=%u", MAKELEVEL_NAME, makelevel);
     2297                  }
     2298                if (strneq (*p, "MAKE_RESTARTS=", 14))
     2299                  {
     2300                    *p = alloca (40);
     2301                    sprintf (*p, "MAKE_RESTARTS=%u", restarts);
     2302                    restarts = 0;
     2303                  }
     2304              }
     2305          }
    22882306#else /* AMIGA */
    22892307          {
     
    23512369      /* Free the makefile mtimes (if we allocated any).  */
    23522370      if (makefile_mtimes)
    2353         free ((char *) makefile_mtimes);
     2371        free (makefile_mtimes);
    23542372    }
    23552373
     
    23632381  if (restarts && new_files != 0)
    23642382    {
     2383      const char **p;
    23652384      for (p = new_files->list; *p != 0; ++p)
    23662385        {
    2367           f = enter_command_line_file (*p);
     2386          struct file *f = enter_file (*p);
    23682387          f->last_mtime = f->mtime_before_update = NEW_MTIME;
    23692388        }
     
    24042423                      fatal (NILF, _(".DEFAULT_GOAL contains more than one target"));
    24052424
    2406                     default_goal_file = enter_file (ns->name);
     2425                    default_goal_file = enter_file (strcache_add (ns->name));
    24072426
    24082427                    ns->name = 0; /* It was reused by enter_file(). */
     
    25082527
    25092528        case string:
     2529        case filename:
    25102530        case positive_int:
    25112531        case floating:
     
    25522572
    25532573      if (! cv) {
    2554         cv = (struct command_variable *) xmalloc (sizeof (*cv));
     2574        cv = xmalloc (sizeof (*cv));
    25552575        cv->variable = v;
    25562576        cv->next = command_variables;
     
    25632583         target!  Enter it as a file and add it to the dep chain of
    25642584         goals.  */
    2565       struct file *f = enter_command_line_file (arg);
     2585      struct file *f = enter_file (strcache_add (expand_command_line_file (arg)));
    25662586      f->cmd_target = 1;
    25672587
     
    25812601      {
    25822602        /* Add this target name to the MAKECMDGOALS variable. */
    2583         struct variable *v;
    2584         char *value;
    2585 
    2586         v = lookup_variable (STRING_SIZE_TUPLE ("MAKECMDGOALS"));
    2587         if (v == 0)
     2603        struct variable *gv;
     2604        const char *value;
     2605
     2606        gv = lookup_variable (STRING_SIZE_TUPLE ("MAKECMDGOALS"));
     2607        if (gv == 0)
    25882608          value = f->name;
    25892609        else
     
    25912611            /* Paste the old and new values together */
    25922612            unsigned int oldlen, newlen;
    2593 
    2594             oldlen = strlen (v->value);
     2613            char *vp;
     2614
     2615            oldlen = strlen (gv->value);
    25952616            newlen = strlen (f->name);
    2596             value = (char *) alloca (oldlen + 1 + newlen + 1);
    2597             bcopy (v->value, value, oldlen);
    2598             value[oldlen] = ' ';
    2599             bcopy (f->name, &value[oldlen + 1], newlen + 1);
     2617            vp = alloca (oldlen + 1 + newlen + 1);
     2618            memcpy (vp, gv->value, oldlen);
     2619            vp[oldlen] = ' ';
     2620            memcpy (&vp[oldlen + 1], f->name, newlen + 1);
     2621            value = vp;
    26002622          }
    26012623        define_variable ("MAKECMDGOALS", 12, value, o_default, 0);
     
    26292651    printf (_("\nThis program is built for %s/%s/%s (%s) [" __DATE__ " " __TIME__ "]\n"),
    26302652            BUILD_PLATFORM, BUILD_PLATFORM_ARCH, BUILD_PLATFORM_CPU, remote_description);
    2631 #else
     2653#else  /* !KMK */
    26322654  if (!remote_description || *remote_description == '\0')
    26332655    fprintf (usageto, _("\nThis program built for %s\n"), make_host);
     
    26352657    fprintf (usageto, _("\nThis program built for %s (%s)\n"),
    26362658             make_host, remote_description);
    2637 #endif
     2659#endif /* !KMK */
    26382660
    26392661  fprintf (usageto, _("Report bugs to <[email protected]>\n"));
     
    27022724
    27032725                case string:
     2726                case filename:
    27042727                  if (!doit)
    27052728                    break;
    27062729
    27072730                  if (optarg == 0)
    2708                     optarg = cs->noarg_value;
     2731                    optarg = xstrdup (cs->noarg_value);
    27092732                  else if (*optarg == '\0')
    27102733                    {
     
    27212744                      sl->max = 5;
    27222745                      sl->idx = 0;
    2723                       sl->list = (char **) xmalloc (5 * sizeof (char *));
     2746                      sl->list = xmalloc (5 * sizeof (char *));
    27242747                      *(struct stringlist **) cs->value_ptr = sl;
    27252748                    }
     
    27272750                    {
    27282751                      sl->max += 5;
    2729                       sl->list = (char **)
    2730                         xrealloc ((char *) sl->list,
    2731                                   sl->max * sizeof (char *));
     2752                      sl->list = xrealloc (sl->list,
     2753                                           sl->max * sizeof (char *));
    27322754                    }
    2733                   sl->list[sl->idx++] = optarg;
     2755                  if (cs->type == filename)
     2756                    sl->list[sl->idx++] = expand_command_line_file (optarg);
     2757                  else
     2758                    sl->list[sl->idx++] = optarg;
    27342759                  sl->list[sl->idx] = 0;
    27352760                  break;
     
    28162841decode_env_switches (char *envar, unsigned int len)
    28172842{
    2818   char *varref = (char *) alloca (2 + len + 2);
     2843  char *varref = alloca (2 + len + 2);
    28192844  char *value, *p;
    28202845  int argc;
     
    28242849  varref[0] = '$';
    28252850  varref[1] = '(';
    2826   bcopy (envar, &varref[2], len);
     2851  memcpy (&varref[2], envar, len);
    28272852  varref[2 + len] = ')';
    28282853  varref[2 + len + 1] = '\0';
     
    28362861
    28372862  /* Allocate a vector that is definitely big enough.  */
    2838   argv = (char **) alloca ((1 + len + 1) * sizeof (char *));
     2863  argv = alloca ((1 + len + 1) * sizeof (char *));
    28392864
    28402865  /* Allocate a buffer to copy the value into while we split it into words
    28412866     and unquote it.  We must use permanent storage for this because
    28422867     decode_switches may store pointers into the passed argument words.  */
    2843   p = (char *) xmalloc (2 * len);
     2868  p = xmalloc (2 * len);
    28442869
    28452870  /* getopt will look at the arguments starting at ARGV[1].
     
    28722897       need permanent storage for this in case decode_switches saves
    28732898       pointers into the value.  */
    2874     argv[1] = concat ("-", argv[1], "");
     2899    argv[1] = xstrdup (concat ("-", argv[1], ""));
    28752900
    28762901  /* Parse those words.  */
     
    28862911
    28872912static char *
    2888 quote_for_env (char *out, char *in)
     2913quote_for_env (char *out, const char *in)
    28892914{
    28902915  while (*in != '\0')
     
    29242949      struct flag *next;
    29252950      const struct command_switch *cs;
    2926       char *arg;
     2951      const char *arg;
    29272952    };
    29282953  struct flag *flags = 0;
     
    29302955#define ADD_FLAG(ARG, LEN) \
    29312956  do {                                                                        \
    2932     struct flag *new = (struct flag *) alloca (sizeof (struct flag));         \
     2957    struct flag *new = alloca (sizeof (struct flag));                         \
    29332958    new->cs = cs;                                                             \
    29342959    new->arg = (ARG);                                                         \
     
    29482973      switch (cs->type)
    29492974        {
    2950         default:
    2951           abort ();
    2952 
    29532975        case ignore:
    29542976          break;
     
    29803002              else
    29813003                {
    2982                   char *buf = (char *) alloca (30);
     3004                  char *buf = alloca (30);
    29833005                  sprintf (buf, "%u", *(unsigned int *) cs->value_ptr);
    29843006                  ADD_FLAG (buf, strlen (buf));
     
    30013023              else
    30023024                {
    3003                   char *buf = (char *) alloca (100);
     3025                  char *buf = alloca (100);
    30043026                  sprintf (buf, "%g", *(double *) cs->value_ptr);
    30053027                  ADD_FLAG (buf, strlen (buf));
     
    30093031#endif
    30103032
     3033        case filename:
    30113034        case string:
    30123035          if (all)
     
    30153038              if (sl != 0)
    30163039                {
    3017                   /* Add the elements in reverse order, because
    3018                      all the flags get reversed below; and the order
    3019                      matters for some switches (like -I).  */
    3020                   register unsigned int i = sl->idx;
     3040                  /* Add the elements in reverse order, because all the flags
     3041                     get reversed below; and the order matters for some
     3042                     switches (like -I).  */
     3043                  unsigned int i = sl->idx;
    30213044                  while (i-- > 0)
    30223045                    ADD_FLAG (sl->list[i], strlen (sl->list[i]));
     
    30243047            }
    30253048          break;
     3049
     3050        default:
     3051          abort ();
    30263052        }
    30273053
     
    30323058  /* Construct the value in FLAGSTRING.
    30333059     We allocate enough space for a preceding dash and trailing null.  */
    3034   flagstring = (char *) alloca (1 + flagslen + 1);
    3035   bzero (flagstring, 1 + flagslen + 1);
     3060  flagstring = alloca (1 + flagslen + 1);
     3061  memset (flagstring, '\0', 1 + flagslen + 1);
    30363062  p = flagstring;
    30373063  words = 1;
     
    31253151      if (posix_pedantic)
    31263152        {
    3127           bcopy (posixref, p, sizeof posixref - 1);
     3153          memcpy (p, posixref, sizeof posixref - 1);
    31283154          p += sizeof posixref - 1;
    31293155        }
    31303156      else
    31313157        {
    3132           bcopy (ref, p, sizeof ref - 1);
     3158          memcpy (p, ref, sizeof ref - 1);
    31333159          p += sizeof ref - 1;
    31343160        }
     
    33423368      if (print_data_base_flag)
    33433369        print_data_base ();
     3370
     3371      verify_file_data_base ();
    33443372
    33453373      clean_jobserver (status);
  • trunk/src/gmakenew/make.1

    r503 r903  
    165165over variables from makefiles.
    166166.TP 0.5i
    167 +\fB\-f\fR \fIfile\fR, \fB\-\-file\fR=\fIfile\fR, \fB\-\-makefile\fR=\fIFILE\fR
     167\fB\-f\fR \fIfile\fR, \fB\-\-file\fR=\fIfile\fR, \fB\-\-makefile\fR=\fIFILE\fR
    168168Use
    169169.I file
  • trunk/src/gmakenew/make.h

    r803 r903  
    3939#endif
    4040
    41 
    42 /* Use prototypes if available.  */
    43 #if defined (__cplusplus) || defined (__STDC__) || defined WINDOWS32 /* bird: protos on windows */
    44 # undef  PARAMS
    45 # define PARAMS(protos)  protos
    46 #else /* Not C++ or ANSI C.  */
    47 # undef  PARAMS
    48 # define PARAMS(protos)  ()
    49 #endif /* C++ or ANSI C.  */
    5041
    5142/* Specify we want GNU source code.  This must be defined before any
     
    151142# define NEED_GET_PATH_MAX 1
    152143# define GET_PATH_MAX   (get_path_max ())
    153 # define PATH_VAR(var)  char *var = (char *) alloca (GET_PATH_MAX)
    154 extern unsigned int get_path_max PARAMS ((void));
     144# define PATH_VAR(var)  char *var = alloca (GET_PATH_MAX)
     145unsigned int get_path_max (void);
    155146#endif
    156147
     
    228219#  include <stdlib.h>
    229220# else
    230 extern char *malloc PARAMS ((int));
    231 extern char *realloc PARAMS ((char *, int));
    232 extern void free PARAMS ((char *));
    233 
    234 extern void abort PARAMS ((void)) __attribute__ ((noreturn));
    235 extern void exit PARAMS ((int)) __attribute__ ((noreturn));
     221void *malloc (int);
     222void *realloc (void *, int);
     223void free (void *);
     224
     225void abort (void) __attribute__ ((noreturn));
     226void exit (int) __attribute__ ((noreturn));
    236227# endif /* HAVE_STDLIB_H.  */
    237228
     
    243234#endif
    244235#ifndef EXIT_FAILURE
    245 # define EXIT_FAILURE 0
    246 #endif
    247 
    248 #ifdef  ANSI_STRING
    249 
    250 # ifndef bcmp
    251 #  define bcmp(s1, s2, n)   memcmp ((s1), (s2), (n))
    252 # endif
    253 # ifndef bzero
    254 #  define bzero(s, n)       memset ((s), 0, (n))
    255 # endif
    256 # if defined(HAVE_MEMMOVE) && !defined(bcopy)
    257 #  define bcopy(s, d, n)    memmove ((d), (s), (n))
    258 # endif
    259 
    260 #else   /* Not ANSI_STRING.  */
    261 
    262 # ifndef HAVE_STRCHR
    263 #  define strchr(s, c)      index((s), (c))
    264 #  define strrchr(s, c)     rindex((s), (c))
    265 # endif
    266 
    267 # ifndef bcmp
    268 extern int bcmp PARAMS ((const char *, const char *, int));
    269 # endif
    270 # ifndef bzero
    271 extern void bzero PARAMS ((char *, int));
    272 #endif
    273 # ifndef bcopy
    274 extern void bcopy PARAMS ((const char *b1, char *b2, int));
    275 # endif
     236# define EXIT_FAILURE 1
     237#endif
     238
     239#ifndef  ANSI_STRING
    276240
    277241/* SCO Xenix has a buggy macro definition in <string.h>.  */
    278242#undef  strerror
    279243#if !defined(__DECC)
    280 extern char *strerror PARAMS ((int errnum));
     244char *strerror (int errnum);
    281245#endif
    282246
     
    290254
    291255#if !defined(HAVE_STRSIGNAL)
    292 extern char *strsignal PARAMS ((int signum));
     256char *strsignal (int signum);
    293257#endif
    294258
     
    309273    (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
    310274# ifdef HAVE_CASE_INSENSITIVE_FS
    311 /* This is only used on Windows/DOS platforms, so we assume strcmpi().  */
    312275#  define strieq(a, b) \
    313276    ((a) == (b) \
    314277     || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \
    315          && (*(a) == '\0' || !strcmpi ((a) + 1, (b) + 1))))
     278         && (*(a) == '\0' || !strcasecmp ((a) + 1, (b) + 1))))
    316279# else
    317280#  define strieq(a, b) streq(a, b)
     
    323286#endif
    324287#define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0)
    325 #ifdef  VMS
    326 extern int strcmpi (const char *,const char *);
    327 #endif
    328288
    329289#if defined(__GNUC__) || defined(ENUM_BITFIELDS)
     
    348308
    349309/* Handle other OSs.  */
    350 #if defined(HAVE_DOS_PATHS)
    351 # define PATH_SEPARATOR_CHAR ';'
    352 #elif defined(VMS)
    353 # define PATH_SEPARATOR_CHAR ','
    354 #else
    355 # define PATH_SEPARATOR_CHAR ':'
    356 #endif
    357 
    358 /* This is needed for getcwd() and chdir().  */
    359 #if defined(_MSC_VER) || defined(__BORLANDC__)
     310#ifndef PATH_SEPARATOR_CHAR
     311# if defined(HAVE_DOS_PATHS)
     312#  define PATH_SEPARATOR_CHAR ';'
     313# elif defined(VMS)
     314#  define PATH_SEPARATOR_CHAR ','
     315# else
     316#  define PATH_SEPARATOR_CHAR ':'
     317# endif
     318#endif
     319
     320/* This is needed for getcwd() and chdir(), on some W32 systems.  */
     321#if defined(HAVE_DIRECT_H)
    360322# include <direct.h>
    361323#endif
     
    364326# include <fcntl.h>
    365327# include <malloc.h>
    366 # define pipe(p) _pipe(p, 512, O_BINARY)
    367 # define kill(pid,sig) w32_kill(pid,sig)
    368 
    369 extern void sync_Path_environment(void);
    370 extern int kill(int pid, int sig);
    371 extern char *end_of_token_w32(char *s, char stopchar);
    372 extern int find_and_set_default_shell(char *token);
     328# define pipe(_p)        _pipe((_p), 512, O_BINARY)
     329# define kill(_pid,_sig) w32_kill((_pid),(_sig))
     330
     331void sync_Path_environment (void);
     332int w32_kill (int pid, int sig); /* bird kill -> w32_kill - macro acquired () on the args. */
     333char *end_of_token_w32 (const char *s, char stopchar);
     334int find_and_set_default_shell (const char *token);
    373335
    374336/* indicates whether or not we have Bourne shell */
     
    400362
    401363#if HAVE_ANSI_COMPILER && USE_VARIADIC && HAVE_STDARG_H
    402 extern void message (int prefix, const char *fmt, ...)
    403                      __attribute__ ((__format__ (__printf__, 2, 3)));
    404 extern void error (const struct floc *flocp, const char *fmt, ...)
    405                    __attribute__ ((__format__ (__printf__, 2, 3)));
    406 extern void fatal (const struct floc *flocp, const char *fmt, ...)
     364void message (int prefix, const char *fmt, ...)
     365              __attribute__ ((__format__ (__printf__, 2, 3)));
     366void error (const struct floc *flocp, const char *fmt, ...)
     367            __attribute__ ((__format__ (__printf__, 2, 3)));
     368void fatal (const struct floc *flocp, const char *fmt, ...)
    407369                   __attribute__ ((noreturn, __format__ (__printf__, 2, 3)));
    408370#else
    409 extern void message ();
    410 extern void error ();
    411 extern void fatal ();
    412 #endif
    413 
    414 extern void die PARAMS ((int)) __attribute__ ((noreturn));
    415 extern void log_working_directory PARAMS ((int));
    416 extern void pfatal_with_name PARAMS ((const char *)) __attribute__ ((noreturn));
    417 extern void perror_with_name PARAMS ((const char *, const char *));
    418 extern char *savestring PARAMS ((const char *, unsigned int));
    419 extern char *concat PARAMS ((const char *, const char *, const char *));
    420 extern char *xmalloc PARAMS ((unsigned int));
    421 extern char *xrealloc PARAMS ((char *, unsigned int));
    422 extern char *xstrdup PARAMS ((const char *));
    423 extern char *find_next_token PARAMS ((char **, unsigned int *));
    424 extern char *next_token PARAMS ((const char *));
    425 extern char *end_of_token PARAMS ((const char *));
    426 extern void collapse_continuations PARAMS ((char *));
     371void message ();
     372void error ();
     373void fatal ();
     374#endif
     375
     376void die (int) __attribute__ ((noreturn));
     377void log_working_directory (int);
     378void pfatal_with_name (const char *) __attribute__ ((noreturn));
     379void perror_with_name (const char *, const char *);
     380char *savestring (const char *, unsigned int);
     381char *concat (const char *, const char *, const char *);
     382void *xmalloc (unsigned int);
     383void *xrealloc (void *, unsigned int);
     384char *xstrdup (const char *);
     385char *find_next_token (const char **, unsigned int *);
     386char *next_token (const char *);
     387char *end_of_token (const char *);
     388void collapse_continuations (char *);
    427389#ifdef CONFIG_WITH_OPTIMIZATION_HACKS /* memchr is usually compiler intrinsic, thus faster. */
    428 #define lindex(s, limit, c) ((char *)memchr((s), (c), (limit) - (s)))
    429 #else
    430 extern char *lindex PARAMS ((const char *, const char *, int));
    431 #endif
    432 extern int alpha_compare PARAMS ((const void *, const void *));
    433 extern void print_spaces PARAMS ((unsigned int));
    434 extern char *find_percent PARAMS ((char *));
    435 extern FILE *open_tmpfile PARAMS ((char **, const char *));
     390# define lindex(s, limit, c) ((char *)memchr((s), (c), (limit) - (s)))
     391#else
     392char *lindex (const char *, const char *, int);
     393#endif
     394int alpha_compare (const void *, const void *);
     395void print_spaces (unsigned int);
     396char *find_percent (char *);
     397const char *find_percent_cached (const char **);
     398FILE *open_tmpfile (char **, const char *);
    436399
    437400#ifndef NO_ARCHIVES
    438 extern int ar_name PARAMS ((char *));
    439 extern void ar_parse_name PARAMS ((char *, char **, char **));
    440 extern int ar_touch PARAMS ((char *));
    441 extern time_t ar_member_date PARAMS ((char *));
    442 #endif
    443 
    444 extern int dir_file_exists_p PARAMS ((char *, char *));
    445 extern int file_exists_p PARAMS ((char *));
    446 extern int file_impossible_p PARAMS ((char *));
    447 extern void file_impossible PARAMS ((char *));
    448 extern char *dir_name PARAMS ((char *));
    449 extern void hash_init_directories PARAMS ((void));
    450 
    451 extern void define_default_variables PARAMS ((void));
    452 extern void set_default_suffixes PARAMS ((void));
    453 extern void install_default_suffix_rules PARAMS ((void));
    454 extern void install_default_implicit_rules PARAMS ((void));
    455 
    456 extern void build_vpath_lists PARAMS ((void));
    457 extern void construct_vpath_list PARAMS ((char *pattern, char *dirpath));
    458 extern int vpath_search PARAMS ((char **file, FILE_TIMESTAMP *mtime_ptr));
    459 extern int gpath_search PARAMS ((char *file, unsigned int len));
    460 
    461 extern void construct_include_path PARAMS ((char **arg_dirs));
    462 
    463 extern void user_access PARAMS ((void));
    464 extern void make_access PARAMS ((void));
    465 extern void child_access PARAMS ((void));
    466 
    467 extern void close_stdout PARAMS ((void));
    468 
    469 extern char *strip_whitespace PARAMS ((const char **begpp, const char **endpp));
     401int ar_name (const char *);
     402void ar_parse_name (const char *, char **, char **);
     403int ar_touch (const char *);
     404time_t ar_member_date (const char *);
     405
     406typedef long int (*ar_member_func_t) (int desc, const char *mem, int truncated,
     407                                      long int hdrpos, long int datapos,
     408                                      long int size, long int date, int uid,
     409                                      int gid, int mode, const void *arg);
     410
     411long int ar_scan (const char *archive, ar_member_func_t function, const void *arg);
     412int ar_name_equal (const char *name, const char *mem, int truncated);
     413#ifndef VMS
     414int ar_member_touch (const char *arname, const char *memname);
     415#endif
     416#endif
     417
     418int dir_file_exists_p (const char *, const char *);
     419int file_exists_p (const char *);
     420int file_impossible_p (const char *);
     421void file_impossible (const char *);
     422const char *dir_name (const char *);
     423void hash_init_directories (void);
     424
     425void define_default_variables (void);
     426void set_default_suffixes (void);
     427void install_default_suffix_rules (void);
     428void install_default_implicit_rules (void);
     429
     430void build_vpath_lists (void);
     431void construct_vpath_list (char *pattern, char *dirpath);
     432const char *vpath_search (const char *file, FILE_TIMESTAMP *mtime_ptr);
     433int gpath_search (const char *file, unsigned int len);
     434
     435void construct_include_path (const char **arg_dirs);
     436
     437void user_access (void);
     438void make_access (void);
     439void child_access (void);
     440
     441void close_stdout (void);
     442
     443char *strip_whitespace (const char **begpp, const char **endpp);
    470444
    471445/* String caching  */
    472 extern void strcache_init PARAMS ((void));
    473 extern void strcache_print_stats PARAMS ((const char *prefix));
    474 extern int strcache_iscached PARAMS ((const char *str));
    475 extern const char *strcache_add PARAMS ((const char *str));
    476 extern const char *strcache_add_len PARAMS ((const char *str, int len));
    477 extern int strcache_setbufsize PARAMS ((int size));
     446void strcache_init (void);
     447void strcache_print_stats (const char *prefix);
     448int strcache_iscached (const char *str);
     449const char *strcache_add (const char *str);
     450const char *strcache_add_len (const char *str, int len);
     451int strcache_setbufsize (int size);
    478452
    479453#ifdef  HAVE_VFORK_H
     
    486460#if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32)
    487461
    488 extern long int atol ();
     462long int atol ();
    489463# ifndef VMS
    490 extern long int lseek ();
     464long int lseek ();
    491465# endif
    492466
     
    494468
    495469#ifdef  HAVE_GETCWD
    496 # if !defined(VMS) && !defined(__DECC) && !defined(_MSC_VER)
    497 extern char *getcwd ();
    498 # endif
    499 #else
    500 extern char *getwd ();
     470# if !defined(VMS) && !defined(__DECC) && !defined(_MSC_VER) /* bird: MSC */
     471char *getcwd ();
     472# endif
     473#else
     474char *getwd ();
    501475# define getcwd(buf, len)       getwd (buf)
     476#endif
     477
     478#if !HAVE_STRCASECMP
     479# if HAVE_STRICMP
     480#  define strcasecmp stricmp
     481# elif HAVE_STRCMPI
     482#  define strcasecmp strcmpi
     483# else
     484/* Create our own, in misc.c */
     485int strcasecmp (const char *s1, const char *s2);
     486# endif
    502487#endif
    503488
     
    505490extern const struct floc **expanding_var;
    506491
    507 #if !defined(_MSC_VER)
     492#if !defined(_MSC_VER) /* bird */
    508493extern char **environ;
    509494#endif
     
    522507extern int batch_mode_shell;
    523508
     509extern char cmd_prefix;
     510
    524511extern unsigned int job_slots;
    525512extern int job_fds[2];
     
    573560#endif
    574561
    575 
    576562#ifdef __EMX__
    577 # if !HAVE_STRCASECMP
    578 #  define strcasecmp stricmp
    579 # endif
    580 
    581563# if !defined chdir
    582564#  define chdir _chdir2
     
    617599   to do it ourselves here.  */
    618600
    619 #define ENULLLOOP(_v,_c)   do{ errno = 0; \
    620                                while (((_v)=_c)==0 && errno==EINTR); }while(0)
     601#define ENULLLOOP(_v,_c)   do { errno = 0; (_v) = _c; } \
     602                           while((_v)==0 && errno==EINTR)
     603
    621604
    622605#if defined(__EMX__) && defined(CONFIG_WITH_OPTIMIZATION_HACKS) /* bird: saves 40-100ms on libc. */
  • trunk/src/gmakenew/misc.c

    r549 r903  
    172172
    173173
    174 /* Return a newly-allocated string whose contents
    175    concatenate those of s1, s2, s3.  */
     174/* Return a string whose contents concatenate those of s1, s2, s3.
     175   This string lives in static, re-used memory.  */
    176176
    177177char *
     
    179179{
    180180  unsigned int len1, len2, len3;
    181   char *result;
    182 
    183   len1 = *s1 != '\0' ? strlen (s1) : 0;
    184   len2 = *s2 != '\0' ? strlen (s2) : 0;
    185   len3 = *s3 != '\0' ? strlen (s3) : 0;
    186 
    187   result = (char *) xmalloc (len1 + len2 + len3 + 1);
    188 
    189   if (*s1 != '\0')
    190     bcopy (s1, result, len1);
    191   if (*s2 != '\0')
    192     bcopy (s2, result + len1, len2);
    193   if (*s3 != '\0')
    194     bcopy (s3, result + len1 + len2, len3);
    195   *(result + len1 + len2 + len3) = '\0';
     181  static unsigned int rlen = 0;
     182  static char *result = NULL;
     183
     184  len1 = (s1 && *s1 != '\0') ? strlen (s1) : 0;
     185  len2 = (s2 && *s2 != '\0') ? strlen (s2) : 0;
     186  len3 = (s3 && *s3 != '\0') ? strlen (s3) : 0;
     187
     188  if (len1 + len2 + len3 + 1 > rlen)
     189    result = xrealloc (result, (rlen = len1 + len2 + len3 + 10));
     190
     191  if (len1)
     192    memcpy (result, s1, len1);
     193  if (len2)
     194    memcpy (result + len1, s2, len2);
     195  if (len3)
     196    memcpy (result + len1 + len2, s3, len3);
     197
     198  result[len1+len2+len3] = '\0';
    196199
    197200  return result;
     
    351354#undef xstrdup
    352355
    353 char *
     356void *
    354357xmalloc (unsigned int size)
    355358{
    356359  /* Make sure we don't allocate 0, for pre-ANSI libraries.  */
    357   char *result = (char *) malloc (size ? size : 1);
     360  void *result = malloc (size ? size : 1);
    358361  if (result == 0)
    359362    fatal (NILF, _("virtual memory exhausted"));
     
    362365
    363366
    364 char *
    365 xrealloc (char *ptr, unsigned int size)
    366 {
    367   char *result;
     367void *
     368xrealloc (void *ptr, unsigned int size)
     369{
     370  void *result;
    368371
    369372  /* Some older implementations of realloc() don't conform to ANSI.  */
     
    385388  result = strdup (ptr);
    386389#else
    387   result = (char *) malloc (strlen (ptr) + 1);
     390  result = malloc (strlen (ptr) + 1);
    388391#endif
    389392
     
    394397  return result;
    395398#else
    396   return strcpy(result, ptr);
     399  return strcpy (result, ptr);
    397400#endif
    398401}
     
    403406savestring (const char *str, unsigned int length)
    404407{
    405   register char *out = (char *) xmalloc (length + 1);
     408  char *out = xmalloc (length + 1);
    406409  if (length > 0)
    407     bcopy (str, out, length);
     410    memcpy (out, str, length);
    408411  out[length] = '\0';
    409412  return out;
     
    448451 */
    449452char *
    450 end_of_token_w32 (char *s, char stopchar)
    451 {
    452   register char *p = s;
    453   register int backslash = 0;
     453end_of_token_w32 (const char *s, char stopchar)
     454{
     455  const char *p = s;
     456  int backslash = 0;
    454457
    455458  while (*p != '\0' && *p != stopchar
     
    469472    }
    470473
    471   return p;
     474  return (char *)p;
    472475}
    473476#endif
     
    483486}
    484487
    485 /* Find the next token in PTR; return the address of it, and store the
    486    length of the token into *LENGTHPTR if LENGTHPTR is not nil.  */
     488/* Find the next token in PTR; return the address of it, and store the length
     489   of the token into *LENGTHPTR if LENGTHPTR is not nil.  Set *PTR to the end
     490   of the token, so this function can be called repeatedly in a loop.  */
    487491
    488492char *
    489 find_next_token (char **ptr, unsigned int *lengthptr)
    490 {
    491   char *p = next_token (*ptr);
    492   char *end;
     493find_next_token (const char **ptr, unsigned int *lengthptr)
     494{
     495  const char *p = next_token (*ptr);
    493496
    494497  if (*p == '\0')
    495498    return 0;
    496499
    497   *ptr = end = end_of_token (p);
     500  *ptr = end_of_token (p);
    498501  if (lengthptr != 0)
    499     *lengthptr = end - p;
    500   return p;
     502    *lengthptr = *ptr - p;
     503
     504  return (char *)p;
    501505}
    502506
     
    508512alloc_dep ()
    509513{
    510   struct dep *d = (struct dep *) xmalloc (sizeof (struct dep));
    511   bzero ((char *) d, sizeof (struct dep));
     514  struct dep *d = xmalloc (sizeof (struct dep));
     515  memset (d, '\0', sizeof (struct dep));
    512516  return d;
    513517}
     
    519523free_dep (struct dep *d)
    520524{
    521   if (d->name != 0)
    522     free (d->name);
    523 
    524   if (d->stem != 0)
    525     free (d->stem);
    526 
    527   free ((char *)d);
     525  free (d);
    528526}
    529527
     
    534532copy_dep_chain (const struct dep *d)
    535533{
    536   register struct dep *c;
    537534  struct dep *firstnew = 0;
    538535  struct dep *lastnew = 0;
     
    540537  while (d != 0)
    541538    {
    542       c = (struct dep *) xmalloc (sizeof (struct dep));
    543       bcopy ((char *) d, (char *) c, sizeof (struct dep));
    544 
    545       if (c->name != 0)
    546         c->name = xstrdup (c->name);
    547       if (c->stem != 0)
    548         c->stem = xstrdup (c->stem);
     539      struct dep *c = xmalloc (sizeof (struct dep));
     540      memcpy (c, d, sizeof (struct dep));
    549541
    550542      c->next = 0;
     
    573565}
    574566
    575 
    576 /* Free a chain of `struct nameseq'. Each nameseq->name is freed
    577    as well.  For `struct dep' chains use free_dep_chain.  */
    578 
    579 void
    580 free_ns_chain (struct nameseq *n)
    581 {
    582   register struct nameseq *tmp;
    583 
    584   while (n != 0)
    585   {
    586     if (n->name != 0)
    587       free (n->name);
    588 
    589     tmp = n;
    590 
    591     n = n->next;
    592 
    593     free (tmp);
    594   }
    595 
    596 }
    597 
    598 #ifdef  iAPX286
    599 /* The losing compiler on this machine can't handle this macro.  */
    600 
    601 char *
    602 dep_name (struct dep *dep)
    603 {
    604   return dep->name == 0 ? dep->file->name : dep->name;
     567/* Free a chain of struct nameseq.
     568   For struct dep chains use free_dep_chain.  */
     569
     570void
     571free_ns_chain (struct nameseq *ns)
     572{
     573  while (ns != 0)
     574    {
     575      struct nameseq *t = ns;
     576      ns = ns->next;
     577      free (t);
     578    }
     579}
     580
     581
     582
     583#if !HAVE_STRCASECMP && !HAVE_STRICMP && !HAVE_STRCMPI
     584
     585/* If we don't have strcasecmp() (from POSIX), or anything that can substitute
     586   for it, define our own version.  */
     587
     588int
     589strcasecmp (const char *s1, const char *s2)
     590{
     591  while (1)
     592    {
     593      int c1 = (int) *(s1++);
     594      int c2 = (int) *(s2++);
     595
     596      if (isalpha (c1))
     597        c1 = tolower (c1);
     598      if (isalpha (c2))
     599        c2 = tolower (c2);
     600
     601      if (c1 != '\0' && c1 == c2)
     602        continue;
     603
     604      return (c1 - c2);
     605    }
    605606}
    606607#endif
  • trunk/src/gmakenew/read.c

    r530 r903  
    3838#include <pwd.h>
    3939#else
    40 struct passwd *getpwnam PARAMS ((char *name));
     40struct passwd *getpwnam (char *name);
    4141#endif
    4242#endif
     
    8989/* Default directories to search for include files in  */
    9090
    91 static char *default_include_directories[] =
     91static const char *default_include_directories[] =
    9292  {
    9393#if defined(WINDOWS32) && !defined(INCLUDEDIR)
    94 /*
    95  * This completely up to the user when they install MSVC or other packages.
    96  * This is defined as a placeholder.
    97  */
    98 #define INCLUDEDIR "."
     94/* This completely up to the user when they install MSVC or other packages.
     95   This is defined as a placeholder.  */
     96# define INCLUDEDIR "."
    9997#endif
    10098    INCLUDEDIR,
     
    109107/* List of directories to search for include files in  */
    110108
    111 static char **include_directories;
     109static const char **include_directories;
    112110
    113111/* Maximum length of an element of the above.  */
     
    124122static struct dep *read_makefiles = 0;
    125123
    126 static int eval_makefile PARAMS ((char *filename, int flags));
    127 static int eval PARAMS ((struct ebuffer *buffer, int flags));
    128 
    129 static long readline PARAMS ((struct ebuffer *ebuf));
    130 static void do_define PARAMS ((char *name, unsigned int namelen,
    131                                enum variable_origin origin,
    132                                struct ebuffer *ebuf));
    133 static int conditional_line PARAMS ((char *line, int len, const struct floc *flocp));
    134 static void record_files PARAMS ((struct nameseq *filenames, char *pattern, char *pattern_percent,
    135                         struct dep *deps, unsigned int cmds_started, char *commands,
    136                         unsigned int commands_idx, int two_colon,
    137                         const struct floc *flocp));
    138 static void record_target_var PARAMS ((struct nameseq *filenames, char *defn,
    139                                        enum variable_origin origin,
    140                                        int enabled,
    141                                        const struct floc *flocp));
    142 static enum make_word_type get_next_mword PARAMS ((char *buffer, char *delim,
    143                         char **startp, unsigned int *length));
    144 static void remove_comments PARAMS ((char *line));
    145 static char *find_char_unquote PARAMS ((char *string, int stop1,
    146                                         int stop2, int blank, int ignorevars));
     124static int eval_makefile (const char *filename, int flags);
     125static int eval (struct ebuffer *buffer, int flags);
     126
     127static long readline (struct ebuffer *ebuf);
     128static void do_define (char *name, unsigned int namelen,
     129                       enum variable_origin origin, struct ebuffer *ebuf);
     130static int conditional_line (char *line, int len, const struct floc *flocp);
     131static void record_files (struct nameseq *filenames, const char *pattern,
     132                          const char *pattern_percent, struct dep *deps,
     133                          unsigned int cmds_started, char *commands,
     134                          unsigned int commands_idx, int two_colon,
     135                          const struct floc *flocp);
     136static void record_target_var (struct nameseq *filenames, char *defn,
     137                               enum variable_origin origin, int enabled,
     138                               const struct floc *flocp);
     139static enum make_word_type get_next_mword (char *buffer, char *delim,
     140                                           char **startp, unsigned int *length);
     141static void remove_comments (char *line);
     142static char *find_char_unquote (char *string, int stop1, int stop2,
     143                                int blank, int ignorevars);
    147144
    148145
     
    150147
    151148struct dep *
    152 read_all_makefiles (char **makefiles)
     149read_all_makefiles (const char **makefiles)
    153150{
    154151  unsigned int num_makefiles = 0;
     
    184181    p = value;
    185182
    186     while ((name = find_next_token (&p, &length)) != 0)
     183    while ((name = find_next_token ((const char **)&p, &length)) != 0)
    187184      {
    188185        if (*p != '\0')
     
    227224# else
    228225        { "makefile.vms", "gnumakefile.", "makefile.", 0 };
    229 # endif 
     226# endif
    230227#else
    231228#ifdef _AMIGA
     
    264261            {
    265262              struct dep *d = alloc_dep ();
    266               d->file = enter_file (*p);
     263              d->file = enter_file (strcache_add (*p));
    267264              d->file->dontcare = 1;
    268265              /* Tell update_goal_chain to bail out as soon as this file is
     
    291288  struct conditionals *save = conditionals;
    292289
    293   bzero ((char *) new, sizeof (*new));
     290  memset (new, '\0', sizeof (*new));
    294291  conditionals = new;
    295292
     
    314311
    315312static int
    316 eval_makefile (char *filename, int flags)
     313eval_makefile (const char *filename, int flags)
    317314{
    318315  struct dep *deps;
     
    320317  const struct floc *curfile;
    321318  char *expanded = 0;
    322   char *included = 0;
    323319  int makefile_errno;
    324320  int r;
    325321
    326   ebuf.floc.filenm = strcache_add (filename);
     322  filename = strcache_add (filename);
     323  ebuf.floc.filenm = filename;
    327324  ebuf.floc.lineno = 1;
    328325
     
    361358  if (ebuf.fp == 0 && (flags & RM_INCLUDED) && *filename != '/')
    362359    {
    363       register unsigned int i;
     360      unsigned int i;
    364361      for (i = 0; include_directories[i] != 0; ++i)
    365362        {
    366           included = concat (include_directories[i], "/", filename);
     363          const char *included = concat (include_directories[i], "/", filename);
    367364          ebuf.fp = fopen (included, "r");
    368365          if (ebuf.fp)
    369366            {
    370               filename = included;
     367              filename = strcache_add (included);
    371368              break;
    372369            }
    373           free (included);
    374370        }
    375       /* If we're not using it, we already freed it above.  */
    376       if (filename != included)
    377         included = 0;
    378371    }
    379372
     
    384377  deps->file = lookup_file (filename);
    385378  if (deps->file == 0)
    386     deps->file = enter_file (xstrdup (filename));
     379    deps->file = enter_file (filename);
    387380  filename = deps->file->name;
    388381  deps->changed = flags;
     
    392385  if (expanded)
    393386    free (expanded);
    394   if (included)
    395     free (included);
    396387
    397388  /* If the makefile can't be found at all, give up entirely.  */
     
    463454#ifdef CONFIG_WITH_INCLUDEDEP
    464455/* no nonsense dependency file including. */
    465 void 
    466 eval_include_dep(char *name, struct floc *f)
     456void
     457eval_include_dep (const char *name, struct floc *f)
    467458{
    468459  FILE *fp;
     
    501492  }
    502493
    503   /* allocate a buffer and read the file. \r\n -> \n conversion 
     494  /* allocate a buffer and read the file. \r\n -> \n conversion
    504495     make this intersting ... */
    505496  buf = xmalloc (max_size + 1);
     
    544535  long nlines = 0;
    545536  int two_colon = 0;
    546   char *pattern = 0, *pattern_percent;
     537  const char *pattern = 0;
     538  const char *pattern_percent;
    547539  struct floc *fstart;
    548540  struct floc fi;
     
    561553      commands_idx = 0;                                                       \
    562554      no_targets = 0;                                                         \
    563       if (pattern) { free(pattern); pattern = 0; }                            \
     555      pattern = 0;                                                            \
    564556    } while (0)
    565557
     
    586578      unsigned int linelen;
    587579      char *line;
    588       int len;
     580      unsigned int wlen;
    589581      char *p;
    590582      char *p2;
     
    607599      /* Check for a shell command line first.
    608600         If it is not one, we can stop treating tab specially.  */
    609       if (line[0] == '\t')
     601      if (line[0] == cmd_prefix)
    610602        {
    611603          if (no_targets)
     
    632624                  commands = xrealloc (commands, commands_len);
    633625                }
    634               bcopy (line, &commands[commands_idx], linelen);
     626              memcpy (&commands[commands_idx], line, linelen);
    635627              commands_idx += linelen;
    636628              commands[commands_idx++] = '\n';
     
    648640          collapsed_length = linelen+1;
    649641          if (collapsed)
    650             free ((char *)collapsed);
    651           collapsed = (char *) xmalloc (collapsed_length);
     642            free (collapsed);
     643          collapsed = xmalloc (collapsed_length);
    652644        }
    653645      strcpy (collapsed, line);
     
    657649
    658650      /* Compare a word, both length and contents. */
    659 #define word1eq(s)      (len == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))
     651#define word1eq(s)      (wlen == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))
    660652      p = collapsed;
    661653      while (isspace ((unsigned char)*p))
     
    672664      for (p2 = p+1; *p2 != '\0' && !isspace ((unsigned char)*p2); ++p2)
    673665        ;
    674       len = p2 - p;
     666      wlen = p2 - p;
    675667
    676668      /* Find the start of the second token.  If it looks like a target or
     
    695687      if (!in_ignored_define)
    696688        {
    697           int i = conditional_line (p, len, fstart);
     689          int i = conditional_line (p, wlen, fstart);
    698690          if (i != -2)
    699691            {
     
    787779              else
    788780                {
    789                   unsigned int len;
     781                  unsigned int l;
     782                  const char *cp;
    790783                  char *ap;
    791784
    792785                  /* Expand the line so we can use indirect and constructed
    793786                     variable names in an export command.  */
    794                   p2 = ap = allocated_variable_expand (p2);
    795 
    796                   for (p = find_next_token (&p2, &len); p != 0;
    797                        p = find_next_token (&p2, &len))
     787                  cp = ap = allocated_variable_expand (p2);
     788
     789                  for (p = find_next_token (&cp, &l); p != 0;
     790                       p = find_next_token (&cp, &l))
    798791                    {
    799                       v = lookup_variable (p, len);
     792                      v = lookup_variable (p, l);
    800793                      if (v == 0)
    801                         v = define_variable_loc (p, len, "", o_file, 0,
    802                                                  fstart);
     794                        v = define_variable_loc (p, l, "", o_file, 0, fstart);
    803795                      v->export = v_export;
    804796                    }
     
    816808          else
    817809            {
    818               unsigned int len;
     810              unsigned int l;
    819811              struct variable *v;
     812              const char *cp;
    820813              char *ap;
    821814
    822815              /* Expand the line so we can use indirect and constructed
    823816                 variable names in an unexport command.  */
    824               p2 = ap = allocated_variable_expand (p2);
    825 
    826               for (p = find_next_token (&p2, &len); p != 0;
    827                    p = find_next_token (&p2, &len))
     817              cp = ap = allocated_variable_expand (p2);
     818
     819              for (p = find_next_token (&cp, &l); p != 0;
     820                   p = find_next_token (&cp, &l))
    828821                {
    829                   v = lookup_variable (p, len);
     822                  v = lookup_variable (p, l);
    830823                  if (v == 0)
    831                     v = define_variable_loc (p, len, "", o_file, 0, fstart);
     824                    v = define_variable_loc (p, l, "", o_file, 0, fstart);
    832825
    833826                  v->export = v_noexport;
     
    842835      if (word1eq ("vpath"))
    843836        {
    844           char *pattern;
    845           unsigned int len;
    846           p2 = variable_expand (p2);
    847           p = find_next_token (&p2, &len);
     837          const char *cp;
     838          char *vpat;
     839          unsigned int l;
     840          cp = variable_expand (p2);
     841          p = find_next_token (&cp, &l);
    848842          if (p != 0)
    849843            {
    850               pattern = savestring (p, len);
    851               p = find_next_token (&p2, &len);
     844              vpat = savestring (p, l);
     845              p = find_next_token (&cp, &l);
    852846              /* No searchpath means remove all previous
    853847                 selective VPATH's with the same pattern.  */
     
    855849          else
    856850            /* No pattern means remove all previous selective VPATH's.  */
    857             pattern = 0;
    858           construct_vpath_list (pattern, p);
    859           if (pattern != 0)
    860             free (pattern);
     851            vpat = 0;
     852          construct_vpath_list (vpat, p);
     853          if (vpat != 0)
     854            free (vpat);
    861855
    862856          goto rule_complete;
     
    926920            {
    927921              struct nameseq *next = files->next;
    928               char *name = files->name;
     922              const char *name = files->name;
    929923              int r;
    930924
    931               free ((char *)files);
     925              free (files);
    932926              files = next;
    933927
     
    936930              if (!r && !noerror)
    937931                error (fstart, "%s: %s", name, strerror (errno));
    938               free (name);
    939932            }
    940933
     
    952945         was no preceding target, and the line might have been usable as a
    953946         variable definition.  But now we know it is definitely lossage.  */
    954       if (line[0] == '\t')
     947      if (line[0] == cmd_prefix)
    955948        fatal(fstart, _("commands commence before first target"));
    956949
     
    970963        int exported;
    971964        char *cmdleft, *semip, *lb_next;
    972         unsigned int len, plen = 0;
     965        unsigned int plen = 0;
    973966        char *colonp;
    974967        const char *end, *beg; /* Helpers for whitespace stripping. */
     
    999992           beginning, expanding as we go, and looking for "interesting"
    1000993           chars.  The first word is always expandable.  */
    1001         wtype = get_next_mword(line, NULL, &lb_next, &len);
     994        wtype = get_next_mword(line, NULL, &lb_next, &wlen);
    1002995        switch (wtype)
    1003996          {
     
    10201013          }
    10211014
    1022         p2 = variable_expand_string(NULL, lb_next, len);
     1015        p2 = variable_expand_string(NULL, lb_next, wlen);
    10231016
    10241017        while (1)
    10251018          {
    1026             lb_next += len;
     1019            lb_next += wlen;
    10271020            if (cmdleft == 0)
    10281021              {
     
    10691062              break;
    10701063
    1071             wtype = get_next_mword(lb_next, NULL, &lb_next, &len);
     1064            wtype = get_next_mword(lb_next, NULL, &lb_next, &wlen);
    10721065            if (wtype == w_eol)
    10731066              break;
     
    10751068            p2 += strlen(p2);
    10761069            *(p2++) = ' ';
    1077             p2 = variable_expand_string(p2, lb_next, len);
     1070            p2 = variable_expand_string(p2, lb_next, wlen);
    10781071            /* We don't need to worry about cmdleft here, because if it was
    10791072               found in the variable_buffer the entire buffer has already
     
    11301123            unsigned int l = p2 - variable_buffer;
    11311124            plen = strlen (p2);
    1132             (void) variable_buffer_output (p2+plen,
    1133                                            lb_next, strlen (lb_next)+1);
     1125            variable_buffer_output (p2+plen, lb_next, strlen (lb_next)+1);
    11341126            p2 = variable_buffer + l;
    11351127          }
     
    11381130           comes after it looks like a variable definition.  */
    11391131
    1140         wtype = get_next_mword (p2, NULL, &p, &len);
     1132        wtype = get_next_mword (p2, NULL, &p, &wlen);
    11411133
    11421134        v_origin = o_file;
     
    11471139              {
    11481140                v_origin = o_override;
    1149                 wtype = get_next_mword (p+len, NULL, &p, &len);
     1141                wtype = get_next_mword (p+wlen, NULL, &p, &wlen);
    11501142              }
    11511143            else if (word1eq ("export"))
    11521144              {
    11531145                exported = 1;
    1154                 wtype = get_next_mword (p+len, NULL, &p, &len);
     1146                wtype = get_next_mword (p+wlen, NULL, &p, &wlen);
    11551147              }
    11561148          }
    11571149
    11581150        if (wtype != w_eol)
    1159           wtype = get_next_mword (p+len, NULL, NULL, NULL);
     1151          wtype = get_next_mword (p+wlen, NULL, NULL, NULL);
    11601152
    11611153        if (wtype == w_varassign)
     
    12321224        {
    12331225          int check_again;
    1234 
    12351226          do {
    12361227            check_again = 0;
     
    12541245            else if (target->next != 0)
    12551246              fatal (fstart, _("multiple target patterns (target `%s')"), target->name); /* bird */
     1247            pattern_percent = find_percent_cached (&target->name);
    12561248            pattern = target->name;
    1257             pattern_percent = find_percent (pattern);
    12581249            if (pattern_percent == 0)
    12591250              fatal (fstart, _("target pattern contains no `%%' (target `%s')"), target->name); /* bird */
    1260             free ((char *)target);
     1251            free (target);
    12611252          }
    12621253        else
     
    12721263            /* Put all the prerequisites here; they'll be parsed later.  */
    12731264            deps = alloc_dep ();
    1274             deps->name = savestring (beg, end - beg + 1);
     1265            deps->name = strcache_add_len (beg, end - beg + 1);
    12751266          }
    12761267        else
     
    12811272          {
    12821273            /* Semicolon means rest of line is a command.  */
    1283             unsigned int len = strlen (cmdleft);
     1274            unsigned int l = strlen (cmdleft);
    12841275
    12851276            cmds_started = fstart->lineno;
    12861277
    12871278            /* Add this command line to the buffer.  */
    1288             if (len + 2 > commands_len)
     1279            if (l + 2 > commands_len)
    12891280              {
    1290                 commands_len = (len + 2) * 2;
    1291                 commands = (char *) xrealloc (commands, commands_len);
     1281                commands_len = (l + 2) * 2;
     1282                commands = xrealloc (commands, commands_len);
    12921283              }
    1293             bcopy (cmdleft, commands, len);
    1294             commands_idx += len;
     1284            memcpy (commands, cmdleft, l);
     1285            commands_idx += l;
    12951286            commands[commands_idx++] = '\n';
    12961287          }
     
    13141305        if (**default_goal_name == '\0' && set_default)
    13151306          {
    1316             char* name;
     1307            const char *name;
    13171308            struct dep *d;
    13181309            struct nameseq *t = filenames;
     
    13491340                    for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
    13501341                      {
    1351                         register unsigned int len = strlen (dep_name (d2));
    1352                         if (!strneq (name, dep_name (d2), len))
     1342                        unsigned int l = strlen (dep_name (d2));
     1343                        if (!strneq (name, dep_name (d2), l))
    13531344                          continue;
    1354                         if (streq (name + len, dep_name (d)))
     1345                        if (streq (name + l, dep_name (d)))
    13551346                          {
    13561347                            reject = 1;
     
    13911382
    13921383  if (collapsed)
    1393     free ((char *) collapsed);
    1394   free ((char *) commands);
     1384    free (collapsed);
     1385  free (commands);
    13951386
    13961387  return 1;
     
    14261417  int nlevels = 1;
    14271418  unsigned int length = 100;
    1428   char *definition = (char *) xmalloc (length);
     1419  char *definition = xmalloc (length);
    14291420  unsigned int idx = 0;
    14301421  char *p;
    14311422
    14321423  /* Expand the variable name.  */
    1433   char *var = (char *) alloca (namelen + 1);
    1434   bcopy (name, var, namelen);
     1424  char *var = alloca (namelen + 1);
     1425  memcpy (var, name, namelen);
    14351426  var[namelen] = '\0';
    14361427  var = variable_expand (var);
     
    14581449
    14591450      /* Stop if we find an 'endef' */
    1460       if (line[0] != '\t')
     1451      if (line[0] != cmd_prefix)
    14611452        {
    14621453          p = next_token (line);
     
    15011492        {
    15021493          length = (idx + len) * 2;
    1503           definition = (char *) xrealloc (definition, length + 1);
     1494          definition = xrealloc (definition, length + 1);
    15041495        }
    15051496
    1506       bcopy (line, &definition[idx], len);
     1497      memcpy (&definition[idx], line, len);
    15071498      idx += len;
    15081499      /* Separate lines with a newline.  */
     
    16321623    {
    16331624      conditionals->allocated = 5;
    1634       conditionals->ignoring = (char *) xmalloc (conditionals->allocated);
    1635       conditionals->seen_else = (char *) xmalloc (conditionals->allocated);
     1625      conditionals->ignoring = xmalloc (conditionals->allocated);
     1626      conditionals->seen_else = xmalloc (conditionals->allocated);
    16361627    }
    16371628
     
    16401631    {
    16411632      conditionals->allocated += 5;
    1642       conditionals->ignoring = (char *)
    1643         xrealloc (conditionals->ignoring, conditionals->allocated);
    1644       conditionals->seen_else = (char *)
    1645         xrealloc (conditionals->seen_else, conditionals->allocated);
     1633      conditionals->ignoring = xrealloc (conditionals->ignoring,
     1634                                        conditionals->allocated);
     1635      conditionals->seen_else = xrealloc (conditionals->seen_else,
     1636                                          conditionals->allocated);
    16461637    }
    16471638
     
    16871678  else
    16881679    {
    1689       /* "Ifeq" or "ifneq".  */
     1680      /* "ifeq" or "ifneq".  */
    16901681      char *s1, *s2;
    1691       unsigned int len;
     1682      unsigned int l;
    16921683      char termin = *line == '(' ? ',' : *line;
    16931684
     
    17291720      /* We must allocate a new copy of the expanded string because
    17301721         variable_expand re-uses the same buffer.  */
    1731       len = strlen (s2);
    1732       s1 = (char *) alloca (len + 1);
    1733       bcopy (s2, s1, len + 1);
     1722      l = strlen (s2);
     1723      s1 = alloca (l + 1);
     1724      memcpy (s1, s2, l + 1);
    17341725
    17351726      if (termin != ',')
     
    17441735      if (termin == ')')
    17451736        {
    1746           register int count = 0;
     1737          int count = 0;
    17471738          s2 = next_token (line);
    17481739          for (line = s2; *line != '\0'; ++line)
     
    18791870    {
    18801871      struct variable *v;
    1881       register char *name = filenames->name;
    1882       char *fname;
    1883       char *percent;
     1872      const char *name = filenames->name;
     1873      const char *fname;
     1874      const char *percent;
    18841875      struct pattern_var *p;
    18851876
    18861877      nextf = filenames->next;
    1887       free ((char *) filenames);
     1878      free (filenames);
    18881879
    18891880      /* If it's a pattern target, then add it to the pattern-specific
    18901881         variable list.  */
    1891       percent = find_percent (name);
     1882      percent = find_percent_cached (&name);
    18921883      if (percent)
    18931884        {
     
    19171908          f = lookup_file (name);
    19181909          if (!f)
    1919             f = enter_file (name);
     1910            f = enter_file (strcache_add (name));
    19201911          else if (f->double_colon)
    19211912            f = f->double_colon;
     
    19541945            }
    19551946        }
    1956 
    1957       /* Free name if not needed further.  */
    1958       if (name != fname && (name < fname || name > fname + strlen (fname)))
    1959         free (name);
    19601947    }
    19611948}
     
    19741961
    19751962static void
    1976 record_files (struct nameseq *filenames, char *pattern, char *pattern_percent,
    1977               struct dep *deps, unsigned int cmds_started, char *commands,
     1963record_files (struct nameseq *filenames, const char *pattern,
     1964              const char *pattern_percent, struct dep *deps,
     1965              unsigned int cmds_started, char *commands,
    19781966              unsigned int commands_idx, int two_colon,
    19791967              const struct floc *flocp)
     
    19821970  int implicit = 0;
    19831971  unsigned int max_targets = 0, target_idx = 0;
    1984   char **targets = 0, **target_percents = 0;
     1972  const char **targets = 0, **target_percents = 0;
    19851973  struct commands *cmds;
    19861974
     
    19941982  if (commands_idx > 0)
    19951983    {
    1996       cmds = (struct commands *) xmalloc (sizeof (struct commands));
     1984      cmds = xmalloc (sizeof (struct commands));
    19971985      cmds->fileinfo.filenm = flocp->filenm;
    19981986      cmds->fileinfo.lineno = cmds_started;
     
    20051993  for (; filenames != 0; filenames = nextf)
    20061994    {
    2007       char *name = filenames->name;
     1995      const char *name = filenames->name;
    20081996      struct file *f;
    20091997      struct dep *this = 0;
    2010       char *implicit_percent;
     1998      const char *implicit_percent;
    20111999
    20122000      nextf = filenames->next;
     
    20212009        second_expansion = 1;
    20222010
    2023       implicit_percent = find_percent (name);
     2011      implicit_percent = find_percent_cached (&name);
    20242012      implicit |= implicit_percent != 0;
    20252013
    2026       if (implicit && pattern != 0)
    2027         fatal (flocp, _("mixed implicit and static pattern rules"));
    2028 
    2029       if (implicit && implicit_percent == 0)
    2030         fatal (flocp, _("mixed implicit and normal rules"));
    2031 
    20322014      if (implicit)
    2033         {
     2015        {
     2016          if (pattern != 0)
     2017            fatal (flocp, _("mixed implicit and static pattern rules"));
     2018
     2019          if (implicit_percent == 0)
     2020            fatal (flocp, _("mixed implicit and normal rules"));
     2021
    20342022          if (targets == 0)
    20352023            {
    20362024              max_targets = 5;
    2037               targets = (char **) xmalloc (5 * sizeof (char *));
    2038               target_percents = (char **) xmalloc (5 * sizeof (char *));
     2025              targets = xmalloc (5 * sizeof (char *));
     2026              target_percents = xmalloc (5 * sizeof (char *));
    20392027              target_idx = 0;
    20402028            }
     
    20422030            {
    20432031              max_targets += 5;
    2044               targets = (char **) xrealloc ((char *) targets,
    2045                                             max_targets * sizeof (char *));
    2046               target_percents
    2047                 = (char **) xrealloc ((char *) target_percents,
    2048                                       max_targets * sizeof (char *));
     2032              targets = xrealloc (targets, max_targets * sizeof (char *));
     2033              target_percents = xrealloc (target_percents,
     2034                                          max_targets * sizeof (char *));
    20492035            }
    20502036          targets[target_idx] = name;
     
    20732059          /* Single-colon.  Combine these dependencies
    20742060             with others in file's existing record, if any.  */
    2075           f = enter_file (name);
     2061          f = enter_file (strcache_add (name));
    20762062
    20772063          if (f->double_colon)
     
    21792165            fatal (flocp,
    21802166                   _("target file `%s' has both : and :: entries"), f->name);
    2181           f = enter_file (name);
     2167          f = enter_file (strcache_add (name));
    21822168          /* If there was an existing entry and it was a double-colon entry,
    21832169             enter_file will have returned a new one, making it the prev
     
    21982184      if (pattern)
    21992185        {
    2200           static char *percent = "%";
     2186          static const char *percent = "%";
    22012187          char *buffer = variable_expand ("");
    2202           char *o = patsubst_expand (buffer, name, pattern, percent,
    2203                                      pattern_percent+1, percent+1);
    2204           f->stem = savestring (buffer, o - buffer);
     2188          char *o = patsubst_expand_pat (buffer, name, pattern, percent,
     2189                                         pattern_percent+1, percent+1);
     2190          f->stem = strcache_add_len (buffer, o - buffer);
    22052191          if (this)
    22062192            {
    22072193              this->staticpattern = 1;
    2208               this->stem = xstrdup (f->stem);
     2194              this->stem = f->stem;
    22092195            }
    22102196        }
    22112197
    2212       /* Free name if not needed further.  */
    2213       if (f != 0 && name != f->name
    2214           && (name < f->name || name > f->name + strlen (f->name)))
    2215         {
    2216           free (name);
    2217           name = f->name;
    2218         }
     2198      name = f->name;
    22192199
    22202200      /* If this target is a default target, update DEFAULT_GOAL_FILE.  */
     
    22272207  if (implicit)
    22282208    {
    2229       targets[target_idx] = 0;
    2230       target_percents[target_idx] = 0;
    22312209      if (deps)
    22322210        deps->need_2nd_expansion = second_expansion;
    2233       create_pattern_rule (targets, target_percents, two_colon, deps, cmds, 1);
    2234       free ((char *) target_percents);
     2211      create_pattern_rule (targets, target_percents, target_idx,
     2212                           two_colon, deps, cmds, 1);
    22352213    }
    22362214}
     
    22512229{
    22522230  unsigned int string_len = 0;
    2253   register char *p = string;
     2231  char *p = string;
    22542232  register int ch; /* bird: 'optimiziations' */
    22552233
     
    23112289        {
    23122290          /* Search for more backslashes.  */
    2313           register int i = -2;
     2291          int i = -2;
    23142292          while (&p[i] >= string && p[i] == '\\')
    23152293            --i;
     
    23202298          /* The number of backslashes is now -I.
    23212299             Copy P over itself to swallow half of them.  */
    2322           bcopy (&p[i / 2], &p[i], (string_len - (p - string)) - (i / 2) + 1);
    2323           p += i / 2;
     2300          memmove (&p[i], &p[i/2], (string_len - (p - string)) - (i/2) + 1);
     2301          p += i/2;
    23242302          if (i % 2 == 0)
    23252303            /* All the backslashes quoted each other; the STOPCHAR was
     
    23382316}
    23392317
    2340 /* Search PATTERN for an unquoted %.  */
     2318/* Search PATTERN for an unquoted % and handle quoting.  */
    23412319
    23422320char *
     
    23442322{
    23452323  return find_char_unquote (pattern, '%', 0, 0, 0);
     2324}
     2325
     2326/* Search STRING for an unquoted % and handle quoting.  Returns a pointer to
     2327   the % or NULL if no % was found.
     2328   This version is used with strings in the string cache: if there's a need to
     2329   modify the string a new version will be added to the string cache and
     2330   *STRING will be set to that.  */
     2331
     2332const char *
     2333find_percent_cached (const char **string)
     2334{
     2335  const char *p = *string;
     2336  char *new = 0;
     2337  int slen;
     2338
     2339  /* If the first char is a % return now.  This lets us avoid extra tests
     2340     inside the loop.  */
     2341  if (*p == '%')
     2342    return p;
     2343
     2344  while (1)
     2345    {
     2346      while (*p != '\0' && *p != '%')
     2347        ++p;
     2348
     2349      if (*p == '\0')
     2350        break;
     2351
     2352      /* See if this % is escaped with a backslash; if not we're done.  */
     2353      if (p[-1] != '\\')
     2354        break;
     2355
     2356      {
     2357        /* Search for more backslashes.  */
     2358        char *pv;
     2359        int i = -2;
     2360
     2361        while (&p[i] >= *string && p[i] == '\\')
     2362          --i;
     2363        ++i;
     2364
     2365        /* At this point we know we'll need to allocate a new string.
     2366           Make a copy if we haven't yet done so.  */
     2367        if (! new)
     2368          {
     2369            slen = strlen (*string);
     2370            new = alloca (slen + 1);
     2371            memcpy (new, *string, slen + 1);
     2372            p = new + (p - *string);
     2373            *string = new;
     2374          }
     2375
     2376        /* At this point *string, p, and new all point into the same string.
     2377           Get a non-const version of p so we can modify new.  */
     2378        pv = new + (p - *string);
     2379
     2380        /* The number of backslashes is now -I.
     2381           Copy P over itself to swallow half of them.  */
     2382        memmove (&pv[i], &pv[i/2], (slen - (pv - new)) - (i/2) + 1);
     2383        p += i/2;
     2384
     2385        /* If the backslashes quoted each other; the % was unquoted.  */
     2386        if (i % 2 == 0)
     2387          break;
     2388      }
     2389    }
     2390
     2391  /* If we had to change STRING, add it to the strcache.  */
     2392  if (new)
     2393    {
     2394      *string = strcache_add (*string);
     2395      p = *string + (p - new);
     2396    }
     2397
     2398  /* If we didn't find a %, return NULL.  Otherwise return a ptr to it.  */
     2399  return (*p == '\0') ? NULL : p;
    23462400}
    23472401
     
    23672421#ifndef NO_ARCHIVES /* bird: MSC warning */
    23682422  struct nameseq *lastnew1;
    2369 #endif 
     2423#endif
    23702424  char *p = *stringp;
    2371   char *q;
    2372   char *name;
    23732425
    23742426#ifdef VMS
     
    23802432  while (1)
    23812433    {
     2434      const char *name;
     2435      char *q;
     2436
    23822437      /* Skip whitespace; see if any more names are left.  */
    23832438      p = next_token (p);
     
    23872442        break;
    23882443
    2389       /* Yes, find end of next name.  */
     2444      /* There are, so find the end of the next name.  */
    23902445      q = p;
    23912446      p = find_char_unquote (q, stopchar, VMS_COMMA, 1, 0);
     
    23992454          && !(isspace ((unsigned char)p[1]) || !p[1]
    24002455               || isspace ((unsigned char)p[-1])))
    2401       {
    24022456        p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0);
    2403       }
    24042457#endif
    24052458#ifdef HAVE_DOS_PATHS
     
    24352488      if (q == p)
    24362489        /* ".///" was stripped to "". */
    2437 #ifdef VMS
     2490#if defined(VMS)
    24382491        continue;
     2492#elif defined(_AMIGA)
     2493        name = "";
    24392494#else
    2440 #ifdef _AMIGA
    2441         name = savestring ("", 0);
    2442 #else
    2443         name = savestring ("./", 2);
    2444 #endif
     2495        name = "./";
    24452496#endif
    24462497      else
     
    24662517              *q2++ = *q1++;
    24672518            }
    2468           name = savestring (qbase, p1 - qbase);
     2519          name = strcache_add_len (qbase, p1 - qbase);
    24692520          free (qbase);
    24702521        }
    24712522#else
    2472         name = savestring (q, p - q);
     2523        name = strcache_add_len (q, p - q);
    24732524#endif
    24742525
    24752526      /* Add it to the front of the chain.  */
    2476       new1 = (struct nameseq *) xmalloc (size);
     2527      new1 = xmalloc (size);
    24772528      new1->name = name;
    24782529      new1->next = new;
     
    25172568            /* Copy "lib(" into LIBNAME.  */
    25182569            ++paren;
    2519             libname = (char *) alloca (paren - n->name + 1);
    2520             bcopy (n->name, libname, paren - n->name);
     2570            libname = alloca (paren - n->name + 1);
     2571            memcpy (libname, n->name, paren - n->name);
    25212572            libname[paren - n->name] = '\0';
    25222573
     
    25262577                   Edit it out of the chain and free its storage.  */
    25272578                lastn->next = n->next;
    2528                 free (n->name);
    2529                 free ((char *) n);
     2579                free (n);
    25302580                /* LASTN->next is the new stopping elt for the loop below.  */
    25312581                n = lastn->next;
     
    25342584              {
    25352585                /* Replace N's name with the full archive reference.  */
    2536                 name = concat (libname, paren, ")");
    2537                 free (n->name);
    2538                 n->name = name;
     2586                n->name = strcache_add (concat (libname, paren, ")"));
    25392587              }
    25402588
     
    25492597                lastn = new1;
    25502598                new1 = new1->next;
    2551                 free (lastn->name);
    2552                 free ((char *) lastn);
     2599                free (lastn);
    25532600              }
    25542601            else
    25552602              {
    25562603                /* Replace also NEW1->name, which already has closing `)'.  */
    2557                 name = concat (libname, new1->name, "");
    2558                 free (new1->name);
    2559                 new1->name = name;
     2604                new1->name = strcache_add (concat (libname, new1->name, ""));
    25602605                new1 = new1->next;
    25612606              }
     
    25672612            while (new1 != n)
    25682613              {
    2569                 name = concat (libname, new1->name, ")");
    2570                 free (new1->name);
    2571                 new1->name = name;
     2614                new1->name = strcache_add (concat (libname, new1->name, ")"));
    25722615                lastnew1 = new1;
    25732616                new1 = new1->next;
     
    27372780        unsigned long off = p - start;
    27382781        ebuf->size *= 2;
    2739         start = ebuf->buffer = ebuf->bufstart = (char *) xrealloc (start,
    2740                                                                    ebuf->size);
     2782        start = ebuf->buffer = ebuf->bufstart = xrealloc (start, ebuf->size);
    27412783        p = start + off;
    27422784        end = start + ebuf->size;
     
    29412983
    29422984void
    2943 construct_include_path (char **arg_dirs)
     2985construct_include_path (const char **arg_dirs)
    29442986{
    2945   register unsigned int i;
    29462987#ifdef VAXC             /* just don't ask ... */
    29472988  stat_t stbuf;
     
    29492990  struct stat stbuf;
    29502991#endif
    2951   /* Table to hold the dirs.  */
    2952 
    2953   register unsigned int defsize = (sizeof (default_include_directories)
    2954                                    / sizeof (default_include_directories[0]));
    2955   register unsigned int max = 5;
    2956   register char **dirs = (char **) xmalloc ((5 + defsize) * sizeof (char *));
    2957   register unsigned int idx = 0;
     2992  const char **dirs;
     2993  const char **cpp;
     2994  unsigned int idx;
     2995
     2996  /* Compute the number of pointers we need in the table.  */
     2997  idx = sizeof (default_include_directories) / sizeof (const char *);
     2998  if (arg_dirs)
     2999    for (cpp = arg_dirs; *cpp != 0; ++cpp)
     3000      ++idx;
    29583001
    29593002#ifdef  __MSDOS__
    2960   defsize++;
     3003  /* Add one for $DJDIR.  */
     3004  ++idx;
    29613005#endif
    29623006
     3007  dirs = xmalloc (idx * sizeof (const char *));
     3008
     3009  idx = 0;
     3010  max_incl_len = 0;
     3011
    29633012  /* First consider any dirs specified with -I switches.
    2964      Ignore dirs that don't exist.  */
    2965 
    2966   if (arg_dirs != 0)
     3013     Ignore any that don't exist.  Remember the maximum string length.  */
     3014
     3015  if (arg_dirs)
    29673016    while (*arg_dirs != 0)
    29683017      {
    2969         char *dir = *arg_dirs++;
     3018        const char *dir = *(arg_dirs++);
     3019        char *expanded = 0;
    29703020        int e;
    29713021
    29723022        if (dir[0] == '~')
    29733023          {
    2974             char *expanded = tilde_expand (dir);
     3024            expanded = tilde_expand (dir);
    29753025            if (expanded != 0)
    29763026              dir = expanded;
     
    29793029        EINTRLOOP (e, stat (dir, &stbuf));
    29803030        if (e == 0 && S_ISDIR (stbuf.st_mode))
    2981           {
    2982             if (idx == max - 1)
    2983               {
    2984                 max += 5;
    2985                 dirs = (char **)
    2986                   xrealloc ((char *) dirs, (max + defsize) * sizeof (char *));
    2987               }
    2988             dirs[idx++] = dir;
    2989           }
    2990         else if (dir != arg_dirs[-1])
    2991           free (dir);
     3031          {
     3032            unsigned int len = strlen (dir);
     3033            /* If dir name is written with trailing slashes, discard them.  */
     3034            while (len > 1 && dir[len - 1] == '/')
     3035              --len;
     3036            if (len > max_incl_len)
     3037              max_incl_len = len;
     3038            dirs[idx++] = strcache_add_len (dir, len);
     3039          }
     3040
     3041        if (expanded)
     3042          free (expanded);
    29923043      }
    29933044
    2994   /* Now add at the end the standard default dirs.  */
     3045  /* Now add the standard default dirs at the end.  */
    29953046
    29963047#ifdef  __MSDOS__
    29973048  {
    2998     /* The environment variable $DJDIR holds the root of the
    2999        DJGPP directory tree; add ${DJDIR}/include.  */
     3049    /* The environment variable $DJDIR holds the root of the DJGPP directory
     3050       tree; add ${DJDIR}/include.  */
    30003051    struct variable *djdir = lookup_variable ("DJDIR", 5);
    30013052
    30023053    if (djdir)
    30033054      {
    3004         char *defdir = (char *) xmalloc (strlen (djdir->value) + 8 + 1);
     3055        unsigned int len = strlen (djdir->value) + 8;
     3056        char *defdir = alloca (len + 1);
    30053057
    30063058        strcat (strcpy (defdir, djdir->value), "/include");
    3007         dirs[idx++] = defdir;
     3059        dirs[idx++] = strcache_add (defdir);
     3060
     3061        if (len > max_incl_len)
     3062          max_incl_len = len;
    30083063      }
    30093064  }
    30103065#endif
    30113066
    3012   for (i = 0; default_include_directories[i] != 0; ++i)
     3067  for (cpp = default_include_directories; *cpp != 0; ++cpp)
    30133068    {
    30143069      int e;
    30153070
    3016       EINTRLOOP (e, stat (default_include_directories[i], &stbuf));
     3071      EINTRLOOP (e, stat (*cpp, &stbuf));
    30173072      if (e == 0 && S_ISDIR (stbuf.st_mode))
    3018         dirs[idx++] = default_include_directories[i];
     3073        {
     3074          unsigned int len = strlen (*cpp);
     3075          /* If dir name is written with trailing slashes, discard them.  */
     3076          while (len > 1 && (*cpp)[len - 1] == '/')
     3077            --len;
     3078          if (len > max_incl_len)
     3079            max_incl_len = len;
     3080          dirs[idx++] = strcache_add_len (*cpp, len - 1);
     3081        }
    30193082    }
    30203083
    30213084  dirs[idx] = 0;
    30223085
    3023   /* Now compute the maximum length of any name in it. Also add each
    3024      dir to the .INCLUDE_DIRS variable.  */
    3025 
    3026   max_incl_len = 0;
    3027   for (i = 0; i < idx; ++i)
    3028     {
    3029       unsigned int len = strlen (dirs[i]);
    3030       /* If dir name is written with a trailing slash, discard it.  */
    3031       if (dirs[i][len - 1] == '/')
    3032         /* We can't just clobber a null in because it may have come from
    3033            a literal string and literal strings may not be writable.  */
    3034         dirs[i] = savestring (dirs[i], len - 1);
    3035       if (len > max_incl_len)
    3036         max_incl_len = len;
    3037 
    3038       /* Append to .INCLUDE_DIRS.   */
    3039       do_variable_definition (NILF, ".INCLUDE_DIRS", dirs[i],
    3040                               o_default, f_append, 0);
    3041     }
     3086  /* Now add each dir to the .INCLUDE_DIRS variable.  */
     3087
     3088  for (cpp = dirs; *cpp != 0; ++cpp)
     3089    do_variable_definition (NILF, ".INCLUDE_DIRS", *cpp,
     3090                            o_default, f_append, 0);
    30423091
    30433092  include_directories = dirs;
     
    30493098
    30503099char *
    3051 tilde_expand (char *name)
     3100tilde_expand (const char *name)
    30523101{
    30533102#ifndef VMS
     
    30743123          home_dir = getenv ("HOME");
    30753124        }
    3076 #if !defined(_AMIGA) && !defined(WINDOWS32)
     3125# if !defined(_AMIGA) && !defined(WINDOWS32)
    30773126      if (home_dir == 0 || home_dir[0] == '\0')
    30783127        {
     
    30873136            }
    30883137        }
    3089 #endif /* !AMIGA && !WINDOWS32 */
     3138# endif /* !AMIGA && !WINDOWS32 */
    30903139      if (home_dir != 0)
    30913140        {
    3092           char *new = concat (home_dir, "", name + 1);
     3141          char *new = xstrdup (concat (home_dir, "", name + 1));
    30933142          if (is_variable)
    30943143            free (home_dir);
     
    30963145        }
    30973146    }
    3098 #if !defined(_AMIGA) && !defined(WINDOWS32)
     3147# if !defined(_AMIGA) && !defined(WINDOWS32)
    30993148  else
    31003149    {
     
    31093158            return xstrdup (pwent->pw_dir);
    31103159          else
    3111             return concat (pwent->pw_dir, "/", userend + 1);
     3160            return xstrdup (concat (pwent->pw_dir, "/", userend + 1));
    31123161        }
    31133162      else if (userend != 0)
    31143163        *userend = '/';
    31153164    }
    3116 #endif /* !AMIGA && !WINDOWS32 */
     3165# endif /* !AMIGA && !WINDOWS32 */
    31173166#endif /* !VMS */
    31183167  return 0;
     
    31323181multi_glob (struct nameseq *chain, unsigned int size)
    31333182{
    3134   extern void dir_setup_glob ();
    3135   register struct nameseq *new = 0;
    3136   register struct nameseq *old;
     3183  void dir_setup_glob (glob_t *);
     3184  struct nameseq *new = 0;
     3185  struct nameseq *old;
    31373186  struct nameseq *nexto;
    31383187  glob_t gl;
     
    31453194  for (old = chain; old != 0; old = nexto)
    31463195    {
     3196      const char *gname;
    31473197#ifndef NO_ARCHIVES
    3148       char *memname;
     3198      char *arname = 0;
     3199      char *memname = 0;
    31493200#endif
    3150 
    31513201      nexto = old->next;
    3152 
    3153       if (old->name[0] == '~')
     3202      gname = old->name;
     3203
     3204      if (gname[0] == '~')
    31543205        {
    31553206          char *newname = tilde_expand (old->name);
    31563207          if (newname != 0)
    3157             {
    3158               free (old->name);
    3159               old->name = newname;
    3160             }
     3208            gname = newname;
    31613209        }
    31623210
    31633211#ifndef NO_ARCHIVES
    3164       if (ar_name (old->name))
     3212      if (ar_name (gname))
    31653213        {
    3166           /* OLD->name is an archive member reference.
    3167              Replace it with the archive file name,
    3168              and save the member name in MEMNAME.
    3169              We will glob on the archive name and then
    3170              reattach MEMNAME later.  */
    3171           char *arname;
    3172           ar_parse_name (old->name, &arname, &memname);
    3173           free (old->name);
    3174           old->name = arname;
     3214          /* OLD->name is an archive member reference.  Replace it with the
     3215             archive file name, and save the member name in MEMNAME.  We will
     3216             glob on the archive name and then reattach MEMNAME later.  */
     3217          ar_parse_name (gname, &arname, &memname);
     3218          gname = arname;
    31753219        }
    3176       else
    3177         memname = 0;
    31783220#endif /* !NO_ARCHIVES */
    31793221
    31803222#if defined(KMK) || defined(__EMX__) /* speed optimization */
    3181       if (!strpbrk(old->name, "*?["))
     3223      if (!strpbrk(gname, "*?["))
    31823224        {
    31833225          gl.gl_pathc = 1;
    3184           gl.gl_pathv = &old->name;
     3226          gl.gl_pathv = (char *)&gname;
    31853227          rc = 0;
    31863228        }
    31873229      else
    3188         rc = glob (old->name, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl);
     3230        rc = glob (gname, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl);
    31893231      switch (rc)
    31903232#else
    3191       switch (glob (old->name, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl))
     3233      switch (glob (gname, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl))
    31923234#endif
    31933235        {
    31943236        case 0:                 /* Success.  */
    31953237          {
    3196             register int i = gl.gl_pathc;
     3238            int i = gl.gl_pathc;
    31973239            while (i-- > 0)
    31983240              {
     
    32033245                    struct nameseq *found
    32043246                      = ar_glob (gl.gl_pathv[i], memname, size);
    3205                     if (found == 0)
     3247                    if (! found)
    32063248                      {
    32073249                        /* No matches.  Use MEMNAME as-is.  */
    32083250                        unsigned int alen = strlen (gl.gl_pathv[i]);
    32093251                        unsigned int mlen = strlen (memname);
    3210                         struct nameseq *elt
    3211                           = (struct nameseq *) xmalloc (size);
    3212                         if (size > sizeof (struct nameseq))
    3213                           bzero (((char *) elt) + sizeof (struct nameseq),
    3214                                  size - sizeof (struct nameseq));
    3215                         elt->name = (char *) xmalloc (alen + 1 + mlen + 2);
    3216                         bcopy (gl.gl_pathv[i], elt->name, alen);
    3217                         elt->name[alen] = '(';
    3218                         bcopy (memname, &elt->name[alen + 1], mlen);
    3219                         elt->name[alen + 1 + mlen] = ')';
    3220                         elt->name[alen + 1 + mlen + 1] = '\0';
     3252                        char *name;
     3253                        struct nameseq *elt = xmalloc (size);
     3254                        memset (elt, '\0', size);
     3255
     3256                        name = alloca (alen + 1 + mlen + 2);
     3257                        memcpy (name, gl.gl_pathv[i], alen);
     3258                        name[alen] = '(';
     3259                        memcpy (name+alen+1, memname, mlen);
     3260                        name[alen + 1 + mlen] = ')';
     3261                        name[alen + 1 + mlen + 1] = '\0';
     3262                        elt->name = strcache_add (name);
    32213263                        elt->next = new;
    32223264                        new = elt;
     
    32343276                        new = found;
    32353277                      }
    3236 
    3237                     free (memname);
    32383278                  }
    32393279                else
    32403280#endif /* !NO_ARCHIVES */
    32413281                  {
    3242                     struct nameseq *elt = (struct nameseq *) xmalloc (size);
    3243                     if (size > sizeof (struct nameseq))
    3244                       bzero (((char *) elt) + sizeof (struct nameseq),
    3245                              size - sizeof (struct nameseq));
    3246                     elt->name = xstrdup (gl.gl_pathv[i]);
     3282                    struct nameseq *elt = xmalloc (size);
     3283                    memset (elt, '\0', size);
     3284                    elt->name = strcache_add (gl.gl_pathv[i]);
    32473285                    elt->next = new;
    32483286                    new = elt;
     
    32503288              }
    32513289#if defined(KMK) || defined(__EMX__) /* speed optimization */
    3252             if (gl.gl_pathv != &old->name)
     3290            if (gl.gl_pathv != &gname)
    32533291#endif
    32543292            globfree (&gl);
    3255             free (old->name);
    3256             free ((char *)old);
     3293            free (old);
    32573294            break;
    32583295          }
     
    32673304          break;
    32683305        }
     3306
     3307#ifndef NO_ARCHIVES
     3308      if (arname)
     3309        free (arname);
     3310#endif
    32693311    }
    32703312
  • trunk/src/gmakenew/remake.c

    r520 r903  
    4040#endif
    4141
    42 extern int try_implicit_rule PARAMS ((struct file *file, unsigned int depth));
     42extern int try_implicit_rule (struct file *file, unsigned int depth);
    4343
    4444
     
    6161static unsigned int considered;
    6262
    63 static int update_file PARAMS ((struct file *file, unsigned int depth));
    64 static int update_file_1 PARAMS ((struct file *file, unsigned int depth));
    65 static int check_dep PARAMS ((struct file *file, unsigned int depth, FILE_TIMESTAMP this_mtime, int *must_make_ptr));
    66 static int touch_file PARAMS ((struct file *file));
    67 static void remake_file PARAMS ((struct file *file));
    68 static FILE_TIMESTAMP name_mtime PARAMS ((char *name));
    69 static int library_search PARAMS ((char **lib, FILE_TIMESTAMP *mtime_ptr));
     63static int update_file (struct file *file, unsigned int depth);
     64static int update_file_1 (struct file *file, unsigned int depth);
     65static int check_dep (struct file *file, unsigned int depth,
     66                      FILE_TIMESTAMP this_mtime, int *must_make_ptr);
     67static int touch_file (struct file *file);
     68static void remake_file (struct file *file);
     69static FILE_TIMESTAMP name_mtime (const char *name);
     70static const char *library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr);
    7071
    7172
     
    239240
    240241              /* Free the storage.  */
    241               free ((char *) g);
     242              free (g);
    242243
    243244              g = lastgoal == 0 ? goals : lastgoal->next;
     
    538539      if (!running)
    539540        /* The prereq is considered changed if the timestamp has changed while
    540            it was built, OR it doesn't exist.
    541            This causes the Linux kernel build to break.  We'll defer this
    542            fix until GNU make 3.82 to give them time to update.  */
     541           it was built, OR it doesn't exist.  */
    543542        d->changed = ((file_mtime (d->file) != mtime)
    544                       /* || (mtime == NONEXISTENT_MTIME) */);
     543                      || (mtime == NONEXISTENT_MTIME));
    545544
    546545      lastd = d;
     
    823822  if (touch_flag
    824823      /* The update status will be:
    825                 -1      if this target was not remade;
     824                -1      if this target was not remade;
    826825                0       if 0 or more commands (+ or ${MAKE}) were run and won;
    827826                1       if some commands were run and lost.
     
    933932             so that a vpath_search can happen.  Otherwise, it would
    934933             never be done because the target is already updated.  */
    935           (void) f_mtime (d->file, 0);
     934          f_mtime (d->file, 0);
    936935      }
    937936  else if (file->update_status == -1)
     
    942941
    943942
    944 /* Check whether another file (whose mtime is THIS_MTIME)
    945    needs updating on account of a dependency which is file FILE.
    946    If it does, store 1 in *MUST_MAKE_PTR.
    947    In the process, update any non-intermediate files
    948    that FILE depends on (including FILE itself).
    949    Return nonzero if any updating failed.  */
     943/* Check whether another file (whose mtime is THIS_MTIME) needs updating on
     944   account of a dependency which is file FILE.  If it does, store 1 in
     945   *MUST_MAKE_PTR.  In the process, update any non-intermediate files that
     946   FILE depends on (including FILE itself).  Return nonzero if any updating
     947   failed.  */
    950948
    951949static int
     
    961959  if (file->phony || !file->intermediate)
    962960    {
    963       /* If this is a non-intermediate file, update it and record
    964          whether it is newer than THIS_MTIME.  */
     961      /* If this is a non-intermediate file, update it and record whether it
     962         is newer than THIS_MTIME.  */
    965963      FILE_TIMESTAMP mtime;
    966964      dep_status = update_file (file, depth);
     
    991989        }
    992990
    993       /* If the intermediate file actually exists
    994          and is newer, then we should remake from it.  */
    995991      check_renamed (file);
    996992      mtime = file_mtime (file);
    997993      check_renamed (file);
    998994      if (mtime != NONEXISTENT_MTIME && mtime > this_mtime)
     995        /* If the intermediate file actually exists and is newer, then we
     996           should remake from it.  */
    999997        *must_make_ptr = 1;
    1000           /* Otherwise, update all non-intermediate files we depend on,
    1001              if necessary, and see whether any of them is more
    1002              recent than the file on whose behalf we are checking.  */
    1003998      else
    1004999        {
     1000          /* Otherwise, update all non-intermediate files we depend on, if
     1001             necessary, and see whether any of them is more recent than the
     1002             file on whose behalf we are checking.  */
    10051003          struct dep *lastd;
    10061004
     
    10811079        {
    10821080          struct stat statbuf;
    1083           char buf;
     1081          char buf = 'x';
    10841082          int e;
    10851083
     
    11771175      char *arname, *memname;
    11781176      struct file *arfile;
    1179       int arname_used = 0;
    11801177      time_t member_date;
    11811178
     
    11871184      arfile = lookup_file (arname);
    11881185      if (arfile == 0)
    1189         {
    1190           arfile = enter_file (arname);
    1191           arname_used = 1;
    1192         }
     1186        arfile = enter_file (strcache_add (arname));
    11931187      mtime = f_mtime (arfile, search);
    11941188      check_renamed (arfile);
     
    12011195          unsigned int arlen, memlen;
    12021196
    1203           if (!arname_used)
    1204             {
    1205               free (arname);
    1206               arname_used = 1;
    1207             }
    1208 
    1209           arname = arfile->hname;
    1210           arlen = strlen (arname);
     1197          arlen = strlen (arfile->hname);
    12111198          memlen = strlen (memname);
    12121199
    1213           /* free (file->name); */
    1214 
    1215           name = (char *) xmalloc (arlen + 1 + memlen + 2);
    1216           bcopy (arname, name, arlen);
     1200          name = xmalloc (arlen + 1 + memlen + 2);
     1201          memcpy (name, arfile->hname, arlen);
    12171202          name[arlen] = '(';
    1218           bcopy (memname, name + arlen + 1, memlen);
     1203          memcpy (name + arlen + 1, memname, memlen);
    12191204          name[arlen + 1 + memlen] = ')';
    12201205          name[arlen + 1 + memlen + 1] = '\0';
     
    12291214        }
    12301215
    1231       if (!arname_used)
    1232         free (arname);
    1233       free (memname);
     1216      free (arname);
    12341217
    12351218      file->low_resolution_time = 1;
     
    12521235        {
    12531236          /* If name_mtime failed, search VPATH.  */
    1254           char *name = file->name;
    1255           if (vpath_search (&name, &mtime)
     1237          const char *name = vpath_search (file->name, &mtime);
     1238          if (name
    12561239              /* Last resort, is it a library (-lxxx)?  */
    1257               || (name[0] == '-' && name[1] == 'l'
    1258                   && library_search (&name, &mtime)))
     1240              || (file->name[0] == '-' && file->name[1] == 'l'
     1241                  && (name = library_search (file->name, &mtime)) != 0))
    12591242            {
    12601243              if (mtime != UNKNOWN_MTIME)
     
    13751358
    13761359static FILE_TIMESTAMP
    1377 name_mtime (char *name)
     1360name_mtime (const char *name)
    13781361{
    13791362  FILE_TIMESTAMP mtime;
     
    14691452   directories.  */
    14701453
    1471 static int
    1472 library_search (char **lib, FILE_TIMESTAMP *mtime_ptr)
     1454static const char *
     1455library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr)
    14731456{
    14741457  static char *dirs[] =
     
    14911474  static char *libpatterns = NULL;
    14921475
    1493   char *libname = &(*lib)[2];   /* Name without the `-l'.  */
     1476  const char *libname = lib+2;  /* Name without the '-l'.  */
    14941477  FILE_TIMESTAMP mtime;
    14951478
    14961479  /* Loop variables for the libpatterns value.  */
    1497   char *p, *p2;
     1480  char *p;
     1481  const char *p2;
    14981482  unsigned int len;
    14991483
    1500   char *file, **dp;
     1484  char **dp;
    15011485
    15021486  /* If we don't have libpatterns, get it.  */
     
    15471531      if (mtime != NONEXISTENT_MTIME)
    15481532        {
    1549           *lib = xstrdup (libbuf);
    15501533          if (mtime_ptr != 0)
    15511534            *mtime_ptr = mtime;
    1552           return 1;
     1535          return strcache_add (libbuf);
    15531536        }
    15541537
    15551538      /* Now try VPATH search on that.  */
    15561539
    1557       file = libbuf;
    1558       if (vpath_search (&file, mtime_ptr))
    1559         {
    1560           *lib = file;
    1561           return 1;
    1562         }
     1540      {
     1541        const char *file = vpath_search (libbuf, mtime_ptr);
     1542        if (file)
     1543          return file;
     1544      }
    15631545
    15641546      /* Now try the standard set of directories.  */
     
    15871569          if (mtime != NONEXISTENT_MTIME)
    15881570            {
    1589               *lib = xstrdup (buf);
    15901571              if (mtime_ptr != 0)
    15911572                *mtime_ptr = mtime;
    1592               return 1;
     1573              return strcache_add (buf);
    15931574            }
    15941575        }
  • trunk/src/gmakenew/remote-cstms.c

    r503 r903  
    100100             that should work on all machines exported to.  */
    101101
    102           normalized_cwd = (char *) xmalloc (GET_PATH_MAX);
     102          normalized_cwd = xmalloc (GET_PATH_MAX);
    103103          strcpy (normalized_cwd, starting_directory);
    104104          if (Customs_NormPath (normalized_cwd, GET_PATH_MAX) < 0)
  • trunk/src/gmakenew/rule.c

    r503 r903  
    1818
    1919#include "make.h"
     20
     21#include <assert.h>
     22
    2023#include "dep.h"
    2124#include "filedef.h"
     
    2528#include "rule.h"
    2629
    27 static void freerule PARAMS ((struct rule *rule, struct rule *lastrule));
     30static void freerule (struct rule *rule, struct rule *lastrule);
    2831
    2932
     
    7275  char *name;
    7376  int namelen;
    74   register struct rule *rule, *lastrule;
     77  struct rule *rule, *lastrule;
    7578
    7679  num_pattern_rules = max_pattern_targets = max_pattern_deps = 0;
     
    8487    {
    8588      unsigned int ndeps = 0;
    86       register struct dep *dep;
     89      struct dep *dep;
    8790      struct rule *next = rule->next;
    88       unsigned int ntargets;
    8991
    9092      ++num_pattern_rules;
    9193
    92       ntargets = 0;
    93       while (rule->targets[ntargets] != 0)
    94         ++ntargets;
    95 
    96       if (ntargets > max_pattern_targets)
    97         max_pattern_targets = ntargets;
     94      if (rule->num > max_pattern_targets)
     95        max_pattern_targets = rule->num;
    9896
    9997      for (dep = rule->deps; dep != 0; dep = dep->next)
     
    102100
    103101#ifdef VMS
    104           char *p = strrchr (dep->name, ']');
    105           char *p2;
     102          const char *p = strrchr (dep->name, ']');
     103          const char *p2;
    106104          if (p == 0)
    107105            p = strrchr (dep->name, ':');
    108106          p2 = p != 0 ? strchr (dep->name, '%') : 0;
    109107#else
    110           char *p = strrchr (dep->name, '/');
    111           char *p2 = p != 0 ? strchr (dep->name, '%') : 0;
     108          const char *p = strrchr (dep->name, '/');
     109          const char *p2 = p != 0 ? strchr (dep->name, '%') : 0;
    112110#endif
    113111          ndeps++;
     
    124122              if (p - dep->name > namelen)
    125123                {
    126                   if (name != 0)
    127                     free (name);
    128124                  namelen = p - dep->name;
    129                   name = (char *) xmalloc (namelen + 1);
     125                  name = xrealloc (name, namelen + 1);
    130126                }
    131               bcopy (dep->name, name, p - dep->name);
     127              memcpy (name, dep->name, p - dep->name);
    132128              name[p - dep->name] = '\0';
    133129
     
    162158
    163159static void
    164 convert_suffix_rule (char *target, char *source, struct commands *cmds)
    165 {
    166   char *targname, *targpercent, *depname;
    167   char **names, **percents;
     160convert_suffix_rule (const char *target, const char *source,
     161                     struct commands *cmds)
     162{
     163  const char **names, **percents;
    168164  struct dep *deps;
    169   unsigned int len;
     165
     166  names = xmalloc (sizeof (const char *));
     167  percents = xmalloc (sizeof (const char *));
    170168
    171169  if (target == 0)
    172     /* Special case: TARGET being nil means we are defining a
    173        `.X.a' suffix rule; the target pattern is always `(%.o)'.  */
    174     {
     170    {
     171      /* Special case: TARGET being nil means we are defining a `.X.a' suffix
     172         rule; the target pattern is always `(%.o)'.  */
    175173#ifdef VMS
    176       targname = savestring ("(%.obj)", 7);
     174      *names = strcache_add_len ("(%.obj)", 7);
    177175#else
    178       targname = savestring ("(%.o)", 5);
     176      *names = strcache_add_len ("(%.o)", 5);
    179177#endif
    180       targpercent = targname + 1;
     178      *percents = *names + 1;
    181179    }
    182180  else
    183181    {
    184182      /* Construct the target name.  */
    185       len = strlen (target);
    186       targname = xmalloc (1 + len + 1);
    187       targname[0] = '%';
    188       bcopy (target, targname + 1, len + 1);
    189       targpercent = targname;
    190     }
    191 
    192   names = (char **) xmalloc (2 * sizeof (char *));
    193   percents = (char **) alloca (2 * sizeof (char *));
    194   names[0] = targname;
    195   percents[0] = targpercent;
    196   names[1] = percents[1] = 0;
     183      unsigned int len = strlen (target);
     184      char *p = alloca (1 + len + 1);
     185      p[0] = '%';
     186      memcpy (p + 1, target, len + 1);
     187      *names = strcache_add_len (p, len + 1);
     188      *percents = *names;
     189    }
    197190
    198191  if (source == 0)
     
    201194    {
    202195      /* Construct the dependency name.  */
    203       len = strlen (source);
    204       depname = xmalloc (1 + len + 1);
    205       depname[0] = '%';
    206       bcopy (source, depname + 1, len + 1);
     196      unsigned int len = strlen (source);
     197      char *p = alloca (1 + len + 1);
     198      p[0] = '%';
     199      memcpy (p + 1, source, len + 1);
    207200      deps = alloc_dep ();
    208       deps->name = depname;
    209     }
    210 
    211   create_pattern_rule (names, percents, 0, deps, cmds, 0);
     201      deps->name = strcache_add_len (p, len + 1);
     202    }
     203
     204  create_pattern_rule (names, percents, 1, 0, deps, cmds, 0);
    212205}
    213206
    214207/* Convert old-style suffix rules to pattern rules.
    215    All rules for the suffixes on the .SUFFIXES list
    216    are converted and added to the chain of pattern rules.  */
     208   All rules for the suffixes on the .SUFFIXES list are converted and added to
     209   the chain of pattern rules.  */
    217210
    218211void
    219212convert_to_pattern (void)
    220213{
    221   register struct dep *d, *d2;
    222   register struct file *f;
    223   register char *rulename;
    224   register unsigned int slen, s2len;
    225 
    226   /* Compute maximum length of all the suffixes.  */
     214  struct dep *d, *d2;
     215  char *rulename;
     216
     217  /* We will compute every potential suffix rule (.x.y) from the list of
     218     suffixes in the .SUFFIXES target's dependencies and see if it exists.
     219     First find the longest of the suffixes.  */
    227220
    228221  maxsuffix = 0;
    229222  for (d = suffix_file->deps; d != 0; d = d->next)
    230223    {
    231       register unsigned int namelen = strlen (dep_name (d));
    232       if (namelen > maxsuffix)
    233         maxsuffix = namelen;
    234     }
    235 
    236   rulename = (char *) alloca ((maxsuffix * 2) + 1);
     224      unsigned int l = strlen (dep_name (d));
     225      if (l > maxsuffix)
     226        maxsuffix = l;
     227    }
     228
     229  /* Space to construct the suffix rule target name.  */
     230  rulename = alloca ((maxsuffix * 2) + 1);
    237231
    238232  for (d = suffix_file->deps; d != 0; d = d->next)
    239233    {
     234      unsigned int slen;
     235
    240236      /* Make a rule that is just the suffix, with no deps or commands.
    241237         This rule exists solely to disqualify match-anything rules.  */
    242       convert_suffix_rule (dep_name (d), (char *) 0, (struct commands *) 0);
    243 
    244       f = d->file;
    245       if (f->cmds != 0)
     238      convert_suffix_rule (dep_name (d), 0, 0);
     239
     240      if (d->file->cmds != 0)
    246241        /* Record a pattern for this suffix's null-suffix rule.  */
    247         convert_suffix_rule ("", dep_name (d), f->cmds);
    248 
    249       /* Record a pattern for each of this suffix's two-suffix rules.  */
     242        convert_suffix_rule ("", dep_name (d), d->file->cmds);
     243
     244      /* Add every other suffix to this one and see if it exists as a
     245         two-suffix rule.  */
    250246      slen = strlen (dep_name (d));
    251       bcopy (dep_name (d), rulename, slen);
     247      memcpy (rulename, dep_name (d), slen);
     248
    252249      for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
    253250        {
     251          struct file *f;
     252          unsigned int s2len;
     253
    254254          s2len = strlen (dep_name (d2));
    255255
     256          /* Can't build something from itself.  */
    256257          if (slen == s2len && streq (dep_name (d), dep_name (d2)))
    257258            continue;
    258259
    259           bcopy (dep_name (d2), rulename + slen, s2len + 1);
     260          memcpy (rulename + slen, dep_name (d2), s2len + 1);
    260261          f = lookup_file (rulename);
    261262          if (f == 0 || f->cmds == 0)
     
    265266            /* A suffix rule `.X.a:' generates the pattern rule `(%.o): %.X'.
    266267               It also generates a normal `%.a: %.X' rule below.  */
    267             convert_suffix_rule ((char *) 0, /* Indicates `(%.o)'.  */
     268            convert_suffix_rule (NULL, /* Indicates `(%.o)'.  */
    268269                                 dep_name (d),
    269270                                 f->cmds);
     
    277278
    278279
    279 /* Install the pattern rule RULE (whose fields have been filled in)
    280    at the end of the list (so that any rules previously defined
    281    will take precedence).  If this rule duplicates a previous one
    282    (identical target and dependencies), the old one is replaced
    283    if OVERRIDE is nonzero, otherwise this new one is thrown out.
    284    When an old rule is replaced, the new one is put at the end of the
    285    list.  Return nonzero if RULE is used; zero if not.  */
    286 
    287 int
     280/* Install the pattern rule RULE (whose fields have been filled in) at the end
     281   of the list (so that any rules previously defined will take precedence).
     282   If this rule duplicates a previous one (identical target and dependencies),
     283   the old one is replaced if OVERRIDE is nonzero, otherwise this new one is
     284   thrown out.  When an old rule is replaced, the new one is put at the end of
     285   the list.  Return nonzero if RULE is used; zero if not.  */
     286
     287static int
    288288new_pattern_rule (struct rule *rule, int override)
    289289{
    290   register struct rule *r, *lastrule;
    291   register unsigned int i, j;
     290  struct rule *r, *lastrule;
     291  unsigned int i, j;
    292292
    293293  rule->in_use = 0;
     
    299299  lastrule = 0;
    300300  for (r = pattern_rules; r != 0; lastrule = r, r = r->next)
    301     for (i = 0; rule->targets[i] != 0; ++i)
     301    for (i = 0; i < rule->num; ++i)
    302302      {
    303         for (j = 0; r->targets[j] != 0; ++j)
     303        for (j = 0; j < r->num; ++j)
    304304          if (!streq (rule->targets[i], r->targets[j]))
    305305            break;
    306         if (r->targets[j] == 0)
    307           /* All the targets matched.  */
     306        /* If all the targets matched...  */
     307        if (j == r->num)
    308308          {
    309             register struct dep *d, *d2;
     309            struct dep *d, *d2;
    310310            for (d = rule->deps, d2 = r->deps;
    311311                 d != 0 && d2 != 0; d = d->next, d2 = d2->next)
     
    363363install_pattern_rule (struct pspec *p, int terminal)
    364364{
    365   register struct rule *r;
     365  struct rule *r;
    366366  char *ptr;
    367367
    368   r = (struct rule *) xmalloc (sizeof (struct rule));
    369 
    370   r->targets = (char **) xmalloc (2 * sizeof (char *));
    371   r->suffixes = (char **) xmalloc (2 * sizeof (char *));
    372   r->lens = (unsigned int *) xmalloc (2 * sizeof (unsigned int));
    373 
    374   r->targets[1] = 0;
    375   r->suffixes[1] = 0;
    376   r->lens[1] = 0;
     368  r = xmalloc (sizeof (struct rule));
     369
     370  r->num = 1;
     371  r->targets = xmalloc (sizeof (const char *));
     372  r->suffixes = xmalloc (sizeof (const char *));
     373  r->lens = xmalloc (sizeof (unsigned int));
    377374
    378375  r->lens[0] = strlen (p->target);
    379   /* These will all be string literals, but we malloc space for
    380      them anyway because somebody might want to free them later on.  */
    381   r->targets[0] = savestring (p->target, r->lens[0]);
    382   r->suffixes[0] = find_percent (r->targets[0]);
    383   if (r->suffixes[0] == 0)
    384     /* Programmer-out-to-lunch error.  */
    385     abort ();
    386   else
    387     ++r->suffixes[0];
     376  r->targets[0] = p->target;
     377  r->suffixes[0] = find_percent_cached (&r->targets[0]);
     378  assert (r->suffixes[0] != NULL);
     379  ++r->suffixes[0];
    388380
    389381  ptr = p->dep;
     
    395387    {
    396388      r->terminal = terminal;
    397       r->cmds = (struct commands *) xmalloc (sizeof (struct commands));
     389      r->cmds = xmalloc (sizeof (struct commands));
    398390      r->cmds->fileinfo.filenm = 0;
    399391      r->cmds->fileinfo.lineno = 0;
     
    414406{
    415407  struct rule *next = rule->next;
    416   register unsigned int i;
    417   register struct dep *dep;
    418 
    419   for (i = 0; rule->targets[i] != 0; ++i)
    420     free (rule->targets[i]);
     408  struct dep *dep;
    421409
    422410  dep = rule->deps;
    423411  while (dep)
    424412    {
    425       struct dep *t;
    426 
    427       t = dep->next;
    428       /* We might leak dep->name here, but I'm not sure how to fix this: I
    429          think that pointer might be shared (e.g., in the file hash?)  */
    430       dep->name = 0; /* Make sure free_dep does not free name.  */
     413      struct dep *t = dep->next;
    431414      free_dep (dep);
    432415      dep = t;
    433416    }
    434417
    435   free ((char *) rule->targets);
    436   free ((char *) rule->suffixes);
    437   free ((char *) rule->lens);
     418  free (rule->targets);
     419  free (rule->suffixes);
     420  free (rule->lens);
    438421
    439422  /* We can't free the storage for the commands because there
     
    448431       pointer from the `struct file' for the suffix rule.  */
    449432
    450   free ((char *) rule);
     433  free (rule);
    451434
    452435  if (pattern_rules == rule)
     
    462445
    463446
    464 /* Create a new pattern rule with the targets in the nil-terminated
    465    array TARGETS.  If TARGET_PERCENTS is not nil, it is an array of
    466    pointers into the elements of TARGETS, where the `%'s are.
    467    The new rule has dependencies DEPS and commands from COMMANDS.
     447/* Create a new pattern rule with the targets in the nil-terminated array
     448   TARGETS.  TARGET_PERCENTS is an array of pointers to the % in each element
     449   of TARGETS.  N is the number of items in the array (not counting the nil
     450   element).  The new rule has dependencies DEPS and commands from COMMANDS.
    468451   It is a terminal rule if TERMINAL is nonzero.  This rule overrides
    469452   identical rules with different commands if OVERRIDE is nonzero.
    470453
    471    The storage for TARGETS and its elements is used and must not be freed
    472    until the rule is destroyed.  The storage for TARGET_PERCENTS is not used;
    473    it may be freed.  */
     454   The storage for TARGETS and its elements and TARGET_PERCENTS is used and
     455   must not be freed until the rule is destroyed.  */
    474456
    475457void
    476 create_pattern_rule (char **targets, char **target_percents,
    477                     int terminal, struct dep *deps,
     458create_pattern_rule (const char **targets, const char **target_percents,
     459                     unsigned int n, int terminal, struct dep *deps,
    478460                     struct commands *commands, int override)
    479461{
    480   unsigned int max_targets, i;
    481   struct rule *r = (struct rule *) xmalloc (sizeof (struct rule));
    482 
     462  unsigned int i;
     463  struct rule *r = xmalloc (sizeof (struct rule));
     464
     465  r->num = n;
    483466  r->cmds = commands;
    484467  r->deps = deps;
    485468  r->targets = targets;
    486 
    487   max_targets = 2;
    488   r->lens = (unsigned int *) xmalloc (2 * sizeof (unsigned int));
    489   r->suffixes = (char **) xmalloc (2 * sizeof (char *));
    490   for (i = 0; targets[i] != 0; ++i)
    491     {
    492       if (i == max_targets - 1)
    493         {
    494           max_targets += 5;
    495           r->lens = (unsigned int *)
    496             xrealloc ((char *) r->lens, max_targets * sizeof (unsigned int));
    497           r->suffixes = (char **)
    498             xrealloc ((char *) r->suffixes, max_targets * sizeof (char *));
    499         }
     469  r->suffixes = target_percents;
     470  r->lens = xmalloc (n * sizeof (unsigned int));
     471
     472  for (i = 0; i < n; ++i)
     473    {
    500474      r->lens[i] = strlen (targets[i]);
    501       r->suffixes[i] = (target_percents == 0 ? find_percent (targets[i])
    502                         : target_percents[i]) + 1;
    503       if (r->suffixes[i] == 0)
    504         abort ();
    505     }
    506 
    507   if (i < max_targets - 1)
    508     {
    509       r->lens = (unsigned int *) xrealloc ((char *) r->lens,
    510                                            (i + 1) * sizeof (unsigned int));
    511       r->suffixes = (char **) xrealloc ((char *) r->suffixes,
    512                                         (i + 1) * sizeof (char *));
     475      assert (r->suffixes[i] != NULL);
     476      ++r->suffixes[i];
    513477    }
    514478
     
    523487print_rule (struct rule *r)
    524488{
    525   register unsigned int i;
    526   register struct dep *d;
    527 
    528   for (i = 0; r->targets[i] != 0; ++i)
     489  unsigned int i;
     490  struct dep *d;
     491
     492  for (i = 0; i < r->num; ++i)
    529493    {
    530494      fputs (r->targets[i], stdout);
    531       if (r->targets[i + 1] != 0)
    532         putchar (' ');
    533       else
    534         putchar (':');
     495      putchar ((i + 1 == r->num) ? ':' : ' ');
    535496    }
    536497  if (r->terminal)
     
    548509print_rule_data_base (void)
    549510{
    550   register unsigned int rules, terminal;
    551   register struct rule *r;
     511  unsigned int rules, terminal;
     512  struct rule *r;
    552513
    553514  puts (_("\n# Implicit Rules"));
  • trunk/src/gmakenew/rule.h

    r503 r903  
    1717Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.  */
    1818
    19 /* Structure used for pattern rules.  */
     19
     20/* Structure used for pattern (implicit) rules.  */
    2021
    2122struct rule
    2223  {
    2324    struct rule *next;
    24     char **targets;             /* Targets of the rule.  */
     25    const char **targets;       /* Targets of the rule.  */
    2526    unsigned int *lens;         /* Lengths of each target.  */
    26     char **suffixes;            /* Suffixes (after `%') of each target.  */
     27    const char **suffixes;      /* Suffixes (after `%') of each target.  */
    2728    struct dep *deps;           /* Dependencies of the rule.  */
    2829    struct commands *cmds;      /* Commands to execute.  */
     30    unsigned short num;         /* Number of targets.  */
    2931    char terminal;              /* If terminal (double-colon).  */
    3032    char in_use;                /* If in use by a parent pattern_search.  */
     
    5052
    5153
    52 extern void install_pattern_rule PARAMS ((struct pspec *p, int terminal));
    53 extern int new_pattern_rule PARAMS ((struct rule *rule, int override));
    54 extern void count_implicit_rule_limits PARAMS ((void));
    55 extern void convert_to_pattern PARAMS ((void));
    56 extern void create_pattern_rule PARAMS ((char **targets,
    57                                          char **target_percents, int terminal,
    58                                          struct dep *deps,
    59                                          struct commands *commands,
    60                                          int override));
     54void count_implicit_rule_limits (void);
     55void convert_to_pattern (void);
     56void install_pattern_rule (struct pspec *p, int terminal);
     57void create_pattern_rule (const char **targets, const char **target_percents,
     58                          unsigned int num, int terminal, struct dep *deps,
     59                          struct commands *commands, int override);
  • trunk/src/gmakenew/strcache.c

    r503 r903  
    2121#include "hash.h"
    2222
    23 /* The size (in bytes) of each cache buffer.  */
    24 #define CACHE_BUFFER_SIZE   (4096)
     23/* The size (in bytes) of each cache buffer.
     24   Try to pick something that will map well into the heap.  */
     25#define CACHE_BUFFER_SIZE   (8192 - 16)
    2526
    2627
     
    4041static struct strcache *strcache = NULL;
    4142
     43/* Add a new buffer to the cache.  Add it at the front to reduce search time.
     44   This can also increase the overhead, since it's less likely that older
     45   buffers will be filled in.  However, GNU make has so many smaller strings
     46   that this doesn't seem to be much of an issue in practice.
     47 */
    4248static struct strcache *
    4349new_cache()
    4450{
    4551  struct strcache *new;
    46   new = (struct strcache *) xmalloc (sizeof (*new) + bufsize);
     52  new = xmalloc (sizeof (*new) + bufsize);
    4753  new->end = new->buffer;
    4854  new->count = 0;
     
    6268  const char *res;
    6369
    64   /* If the string we want is too large to fit into a single buffer, then we're
    65      screwed; nothing will ever fit!  Change the maximum size of the cache to
    66      be big enough.  */
     70  /* If the string we want is too large to fit into a single buffer, then
     71     we're screwed; nothing will ever fit!  Change the maximum size of the
     72     cache to be big enough.  */
    6773  if (len > bufsize)
    6874    bufsize = len * 2;
     
    114120
    115121static struct hash_table strings;
     122static unsigned long total_adds = 0;
    116123
    117124static const char *
     
    119126{
    120127  /* Look up the string in the hash.  If it's there, return it.  */
    121   char **slot = (char **) hash_find_slot (&strings, str);
     128  char *const *slot = (char *const *) hash_find_slot (&strings, str);
    122129  const char *key = *slot;
     130
     131  /* Count the total number of adds we performed.  */
     132  ++total_adds;
    123133
    124134  if (!HASH_VACANT (key))
     
    156166strcache_add_len (const char *str, int len)
    157167{
    158   char *key = alloca (len + 1);
    159   memcpy (key, str, len);
    160   key[len] = '\0';
    161 
    162   return add_hash (key, len);
     168  /* If we're not given a nul-terminated string we have to create one, because
     169     the hashing functions expect it.  */
     170  if (str[len] != '\0')
     171    {
     172      char *key = alloca (len + 1);
     173      memcpy (key, str, len);
     174      key[len] = '\0';
     175      str = key;
     176    }
     177
     178  return add_hash (str, len);
    163179}
    164180
     
    174190strcache_init (void)
    175191{
    176   hash_init (&strings, 1000, str_hash_1, str_hash_2, str_hash_cmp);
     192  hash_init (&strings, 8000, str_hash_1, str_hash_2, str_hash_cmp);
    177193}
    178194
     
    186202  int totsize = 0, avgsize, maxsize = 0, minsize = bufsize;
    187203  int totfree = 0, avgfree, maxfree = 0, minfree = bufsize;
    188   const struct strcache *sp;
    189 
    190   for (sp = strcache; sp != NULL; sp = sp->next)
     204  int lastused = 0, lastfree = 0;
     205
     206  if (strcache)
    191207    {
    192       int bf = sp->bytesfree;
    193       int sz = (sp->end - sp->buffer) + bf;
    194 
    195       ++numbuffs;
    196       numstrs += sp->count;
    197 
    198       totsize += sz;
    199       maxsize = (sz > maxsize ? sz : maxsize);
    200       minsize = (sz < minsize ? sz : minsize);
    201 
    202       totfree += bf;
    203       maxfree = (bf > maxfree ? bf : maxfree);
    204       minfree = (bf < minfree ? bf : minfree);
     208      const struct strcache *sp;
     209
     210      /* Count the first buffer separately since it's not full.  */
     211      lastused = strcache->end - strcache->buffer;
     212      lastfree = strcache->bytesfree;
     213
     214      for (sp = strcache->next; sp != NULL; sp = sp->next)
     215        {
     216          int bf = sp->bytesfree;
     217          int sz = sp->end - sp->buffer;
     218
     219          ++numbuffs;
     220          numstrs += sp->count;
     221
     222          totsize += sz;
     223          maxsize = (sz > maxsize ? sz : maxsize);
     224          minsize = (sz < minsize ? sz : minsize);
     225
     226          totfree += bf;
     227          maxfree = (bf > maxfree ? bf : maxfree);
     228          minfree = (bf < minfree ? bf : minfree);
     229        }
    205230    }
    206231
     
    208233  avgfree = numbuffs ? (int)(totfree / numbuffs) : 0;
    209234
    210   printf (_("\n%s # of strings in strcache: %d\n"), prefix, numstrs);
    211   printf (_("%s # of strcache buffers: %d\n"), prefix, numbuffs);
    212   printf (_("%s strcache size: total = %d / max = %d / min = %d / avg = %d\n"),
    213           prefix, totsize, maxsize, minsize, avgsize);
    214   printf (_("%s strcache free: total = %d / max = %d / min = %d / avg = %d\n"),
    215           prefix, totfree, maxfree, minfree, avgfree);
    216 }
     235  printf (_("\n%s # of strings in strcache: %d / lookups = %lu / hits = %lu\n"),
     236          prefix, numstrs, total_adds, (total_adds - numstrs));
     237  printf (_("%s # of strcache buffers: %d (* %d B/buffer = %d B)\n"),
     238          prefix, (numbuffs + 1), bufsize, ((numbuffs + 1) * bufsize));
     239  printf (_("%s strcache used: total = %d (%d) / max = %d / min = %d / avg = %d\n"),
     240          prefix, totsize, lastused, maxsize, minsize, avgsize);
     241  printf (_("%s strcache free: total = %d (%d) / max = %d / min = %d / avg = %d\n"),
     242          prefix, totfree, lastfree, maxfree, minfree, avgfree);
     243
     244  fputs (_("\n# strcache hash-table stats:\n# "), stdout);
     245  hash_print_stats (&strings, stdout);
     246}
  • trunk/src/gmakenew/tests/ChangeLog

    r503 r903  
     12006-10-01  Paul Smith  <[email protected]>
     2
     3        * run_make_tests.pl (set_more_defaults): Remove setting of LANG in
     4        ENV here.  This doesn't always work.
     5        * test_driver.pl (toplevel): Set LC_ALL to 'C' in the make
     6        environment.  Fixes Savannah bug #16698.
     7
     82006-09-30  Paul Smith  <[email protected]>
     9
     10        * scripts/variables/automatic: Add back the test for bug #8154.
     11
    1122006-04-01  Paul D. Smith  <[email protected]>
    213
  • trunk/src/gmakenew/tests/run_make_tests.pl

    r503 r903  
    191191sub print_usage
    192192{
    193    &print_standard_usage ("run_make_tests", "[-make_path make_pathname]");
     193   &print_standard_usage ("run_make_tests",
     194                          "[-make_path make_pathname] [-valgrind]",);
    194195}
    195196
     
    229230   local($index);
    230231
    231    # Make sure we're in the C locale for those systems that support it,
    232    # so sorting, etc. is predictable.
    233    #
    234    $ENV{LANG} = 'C';
    235 
    236232   # find the type of the port.  We do this up front to have a single
    237233   # point of change if it needs to be tweaked.
  • trunk/src/gmakenew/tests/scripts/features/patternrules

    r503 r903  
    1111
    1212
    13 #  TEST #1: Make sure that multiple patterns where the same target
    14 #           can be built are searched even if the first one fails
    15 #           to match properly.
     13# TEST #0: Make sure that multiple patterns where the same target
     14#          can be built are searched even if the first one fails
     15#          to match properly.
    1616#
    1717
     
    4646'');
    4747
    48 # TEST #2: make sure files that are built via implicit rules are marked
     48# TEST #1: make sure files that are built via implicit rules are marked
    4949#          as targets (Savannah bug #12202).
    5050#
     
    7070
    7171
    72 # TEST #3: make sure intermidite files that also happened to be
     72# TEST #2: make sure intermediate files that also happened to be
    7373#          prerequisites are not removed (Savannah bug #12267).
    7474#
     
    9797
    9898
    99 # TEST #4: make sure precious flag is set properly for targets
     99# TEST #3: make sure precious flag is set properly for targets
    100100#          that are built via implicit rules (Savannah bug #13218).
    101101#
     
    117117
    118118
    119 # TEST #5: make sure targets of a macthed implicit pattern rule never
     119# TEST #4: make sure targets of a matched implicit pattern rule are
    120120#          never considered intermediate (Savannah bug #13022).
    121121#
  • trunk/src/gmakenew/tests/scripts/variables/automatic

    r503 r903  
    9696# considered reasons for the target to be rebuilt.
    9797#
    98 # This was undone due to Savannah bug #16002.  We'll re-do it in the next
    99 # release.  See Savannah bug #16051.
     98# See also Savannah bugs #16002 and #16051.
    10099
    101 #touch('foo');
    102 #
    103 #run_make_test('
    104 #foo: bar ; @echo "\$$? = $?"
    105 #bar: ;',
    106 #              '',
    107 #              '$? = bar');
    108 #
    109 #unlink('foo');
     100touch('foo');
     101
     102run_make_test('
     103foo: bar ; @echo "\$$? = $?"
     104bar: ;',
     105              '',
     106              '$? = bar');
     107
     108unlink('foo');
    110109
    1111101;
  • trunk/src/gmakenew/tests/test_driver.pl

    r503 r903  
    2929# variables and then calls &toplevel, which does all the real work.
    3030
    31 # $Id: test_driver.pl,v 1.19 2006/03/10 02:20:45 psmith Exp $
     31# $Id: test_driver.pl,v 1.21 2007/03/20 03:02:26 psmith Exp $
    3232
    3333
     
    7979{
    8080  # Pull in benign variables from the user's environment
    81   #
     81
    8282  foreach (# UNIX-specific things
    83            'TZ', 'LANG', 'TMPDIR', 'HOME', 'USER', 'LOGNAME', 'PATH',
     83           'TZ', 'TMPDIR', 'HOME', 'USER', 'LOGNAME', 'PATH',
    8484           # Purify things
    8585           'PURIFYOPTIONS',
     
    9292    $makeENV{$_} = $ENV{$_} if $ENV{$_};
    9393  }
     94
     95  # Make sure our compares are not foiled by locale differences
     96
     97  $makeENV{LC_ALL} = 'C';
    9498
    9599  # Replace the environment with the new one
     
    544548  local($line);
    545549
    546   print "Usage:  perl $plname [testname] [-verbose] [-detail] [-keep]\n";
    547   print "                               [-profile] [-usage] [-help] "
    548       . "[-debug]\n";
    549   foreach $line (@moreusage)
    550   {
    551     print "                               $line\n";
     550  print "usage:\t$plname [testname] [-verbose] [-detail] [-keep]\n";
     551  print "\t\t\t[-profile] [-usage] [-help] [-debug]\n";
     552  foreach (@moreusage) {
     553    print "\t\t\t$_\n";
    552554  }
    553555}
  • 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);
  • trunk/src/gmakenew/variable.h

    r533 r903  
    6161    int value_alloc_len;        /* The amount of memory we've actually allocated. */
    6262    /* FIXME: make lengths unsigned! */
    63 #endif 
     63#endif
    6464    char *value;                /* Variable value.  */
    6565    struct floc fileinfo;       /* Where the variable was defined.  */
     
    109109  {
    110110    struct pattern_var *next;
    111     char *target;
     111    const char *suffix;
     112    const char *target;
    112113    unsigned int len;
    113     char *suffix;
    114114    struct variable variable;
    115115  };
     
    119119
    120120/* expand.c */
    121 extern char *variable_buffer_output PARAMS ((char *ptr, char *string, unsigned int length));
    122 extern char *variable_expand PARAMS ((char *line));
    123 extern char *variable_expand_for_file PARAMS ((char *line, struct file *file));
    124 extern char *allocated_variable_expand_for_file PARAMS ((char *line, struct file *file));
     121char *variable_buffer_output (char *ptr, const char *string, unsigned int length);
     122char *variable_expand (const char *line);
     123char *variable_expand_for_file (const char *line, struct file *file);
     124char *allocated_variable_expand_for_file (const char *line, struct file *file);
    125125#define allocated_variable_expand(line) \
    126126  allocated_variable_expand_for_file (line, (struct file *) 0)
    127 extern char *expand_argument PARAMS ((const char *str, const char *end));
    128 extern char *variable_expand_string PARAMS ((char *line, char *string,
    129                                              long length));
    130 extern void install_variable_buffer PARAMS ((char **bufp, unsigned int *lenp));
    131 extern void restore_variable_buffer PARAMS ((char *buf, unsigned int len));
     127char *expand_argument (const char *str, const char *end);
     128char *variable_expand_string (char *line, const char *string, long length);
     129void install_variable_buffer (char **bufp, unsigned int *lenp);
     130void restore_variable_buffer (char *buf, unsigned int len);
    132131#ifdef CONFIG_WITH_VALUE_LENGTH
    133 extern void append_expanded_string_to_variable PARAMS ((struct variable *v, char *value));
     132extern void append_expanded_string_to_variable (struct variable *v, char *value);
    134133#endif
    135134
    136135/* function.c */
    137 extern int handle_function PARAMS ((char **op, char **stringp));
    138 extern int pattern_matches PARAMS ((char *pattern, char *percent, char *str));
    139 extern char *subst_expand PARAMS ((char *o, char *text, char *subst, char *replace,
    140                 unsigned int slen, unsigned int rlen, int by_word));
    141 extern char *patsubst_expand PARAMS ((char *o, char *text, char *pattern, char *replace,
    142                 char *pattern_percent, char *replace_percent));
     136int handle_function (char **op, const char **stringp);
     137int pattern_matches (const char *pattern, const char *percent, const char *str);
     138char *subst_expand (char *o, const char *text, const char *subst,
     139                    const char *replace, unsigned int slen, unsigned int rlen,
     140                    int by_word);
     141char *patsubst_expand_pat (char *o, const char *text, const char *pattern,
     142                           const char *replace, const char *pattern_percent,
     143                           const char *replace_percent);
     144char *patsubst_expand (char *o, const char *text, char *pattern, char *replace);
    143145
    144146/* expand.c */
    145 extern char *recursively_expand_for_file PARAMS ((struct variable *v,
    146                                                   struct file *file));
     147char *recursively_expand_for_file (struct variable *v, struct file *file);
    147148#define recursively_expand(v)   recursively_expand_for_file (v, NULL)
    148149
    149150/* variable.c */
    150 extern struct variable_set_list *create_new_variable_set PARAMS ((void));
    151 extern void free_variable_set PARAMS ((struct variable_set_list *));
    152 extern struct variable_set_list *push_new_variable_scope PARAMS ((void));
    153 extern void pop_variable_scope PARAMS ((void));
    154 extern void define_automatic_variables PARAMS ((void));
    155 extern void initialize_file_variables PARAMS ((struct file *file, int read));
    156 extern void print_file_variables PARAMS ((struct file *file));
    157 extern void print_variable_set PARAMS ((struct variable_set *set, char *prefix));
    158 extern void merge_variable_set_lists PARAMS ((struct variable_set_list **to_list, struct variable_set_list *from_list));
    159 extern struct variable *do_variable_definition PARAMS ((const struct floc *flocp, const char *name, char *value, enum variable_origin origin, enum variable_flavor flavor, int target_var));
    160 extern struct variable *parse_variable_definition PARAMS ((struct variable *v, char *line));
    161 extern struct variable *try_variable_definition PARAMS ((const struct floc *flocp, char *line, enum variable_origin origin, int target_var));
    162 extern void init_hash_global_variable_set PARAMS ((void));
    163 extern void hash_init_function_table PARAMS ((void));
    164 extern struct variable *lookup_variable PARAMS ((const char *name, unsigned int length));
    165 extern struct variable *lookup_variable_in_set PARAMS ((const char *name,
    166                                                         unsigned int length,
    167                                                         const struct variable_set *set));
     151struct variable_set_list *create_new_variable_set (void);
     152void free_variable_set (struct variable_set_list *);
     153struct variable_set_list *push_new_variable_scope (void);
     154void pop_variable_scope (void);
     155void define_automatic_variables (void);
     156void initialize_file_variables (struct file *file, int reading);
     157void print_file_variables (const struct file *file);
     158void print_variable_set (struct variable_set *set, char *prefix);
     159void merge_variable_set_lists (struct variable_set_list **to_list,
     160                               struct variable_set_list *from_list);
     161struct variable *do_variable_definition (const struct floc *flocp,
     162                                         const char *name, const char *value,
     163                                         enum variable_origin origin,
     164                                         enum variable_flavor flavor,
     165                                         int target_var);
     166struct variable *parse_variable_definition (struct variable *v, char *line);
     167struct variable *try_variable_definition (const struct floc *flocp, char *line,
     168                                          enum variable_origin origin,
     169                                          int target_var);
     170void init_hash_global_variable_set (void);
     171void hash_init_function_table (void);
     172struct variable *lookup_variable (const char *name, unsigned int length);
     173struct variable *lookup_variable_in_set (const char *name, unsigned int length,
     174                                         const struct variable_set *set);
    168175
    169176#ifdef CONFIG_WITH_VALUE_LENGTH
    170177
    171 extern struct variable *define_variable_in_set
    172     PARAMS ((const char *name, unsigned int length, char *value,
    173              unsigned int value_length, int duplicate_value,
    174              enum variable_origin origin, int recursive,
    175              struct variable_set *set, const struct floc *flocp));
     178struct variable *define_variable_in_set (const char *name, unsigned int length,
     179                                         const char *value,
     180                                         unsigned int value_length,
     181                                         int duplicate_value,
     182                                         enum variable_origin origin,
     183                                         int recursive,
     184                                         struct variable_set *set,
     185                                         const struct floc *flocp);
    176186
    177187/* Define a variable in the current variable set.  */
    178188
    179189#define define_variable(n,l,v,o,r) \
    180           define_variable_in_set((n),(l),(v), ~0U,1,(o),(r),\
     190          define_variable_in_set((n),(l),(v),~0U,1,(o),(r),\
    181191                                 current_variable_set_list->set,NILF)
    182192
     
    204214          define_variable_in_set((n),(l),(v),~0U,1,(o),(r),(f)->variables->set,NILF)
    205215
    206 #else
    207 
    208 extern struct variable *define_variable_in_set
    209     PARAMS ((const char *name, unsigned int length, char *value,
    210              enum variable_origin origin, int recursive,
    211              struct variable_set *set, const struct floc *flocp));
     216#else  /* !CONFIG_WITH_VALUE_LENGTH */
     217
     218struct variable *define_variable_in_set (const char *name, unsigned int length,
     219                                         const char *value,
     220                                         enum variable_origin origin,
     221                                         int recursive,
     222                                         struct variable_set *set,
     223                                         const struct floc *flocp);
    212224
    213225/* Define a variable in the current variable set.  */
     
    215227#define define_variable(n,l,v,o,r) \
    216228          define_variable_in_set((n),(l),(v),(o),(r),\
    217                                  current_variable_set_list->set,NILF)
     229                                 current_variable_set_list->set,NILF)           /* force merge conflict */
    218230
    219231/* Define a variable with a location in the current variable set.  */
     
    221233#define define_variable_loc(n,l,v,o,r,f) \
    222234          define_variable_in_set((n),(l),(v),(o),(r),\
    223                                  current_variable_set_list->set,(f))
     235                                 current_variable_set_list->set,(f))            /* force merge conflict */
    224236
    225237/* Define a variable with a location in the global variable set.  */
    226238
    227239#define define_variable_global(n,l,v,o,r,f) \
    228           define_variable_in_set((n),(l),(v),(o),(r),NULL,(f))
     240          define_variable_in_set((n),(l),(v),(o),(r),NULL,(f))                  /* force merge conflict */
    229241
    230242/* Define a variable in FILE's variable set.  */
    231243
    232244#define define_variable_for_file(n,l,v,o,r,f) \
    233           define_variable_in_set((n),(l),(v),(o),(r),(f)->variables->set,NILF)
    234 
    235 #endif
     245          define_variable_in_set((n),(l),(v),(o),(r),(f)->variables->set,NILF)  /* force merge conflict */
     246
     247#endif /* !CONFIG_WITH_VALUE_LENGTH */
    236248
    237249/* Warn that NAME is an undefined variable.  */
     
    244256                              }while(0)
    245257
    246 extern char **target_environment PARAMS ((struct file *file));
    247 
    248 extern struct pattern_var *create_pattern_var PARAMS ((char *target, char *suffix));
     258char **target_environment (struct file *file);
     259
     260struct pattern_var *create_pattern_var (const char *target,
     261                                        const char *suffix);
    249262
    250263extern int export_all_variables;
  • trunk/src/gmakenew/vmsdir.h

    r503 r903  
    6868#endif
    6969
    70 extern  DIR *opendir PARAMS (());
    71 extern  struct direct *readdir PARAMS ((DIR *dfd));
    7270#define rewinddir(dirp) seekdir((dirp), (long)0)
    73 extern  int closedir PARAMS ((DIR *dfd));
    74 extern char *vmsify PARAMS ((char *name, int type));
     71
     72DIR *opendir ();
     73struct direct *readdir (DIR *dfd);
     74int closedir (DIR *dfd);
     75const char *vmsify (const char *name, int type);
    7576
    7677#endif /* VMSDIR_H */
  • trunk/src/gmakenew/vmsfunctions.c

    r503 r903  
    3838  struct NAM *dnam = (struct NAM *)xmalloc (sizeof (struct NAM));
    3939  struct FAB *dfab = &dir->fab;
    40   char *searchspec = (char *)xmalloc (MAXNAMLEN + 1);
     40  char *searchspec = xmalloc (MAXNAMLEN + 1);
    4141
    4242  memset (dir, 0, sizeof *dir);
     
    258258  return (str);
    259259}
    260 
    261 int
    262 strcmpi (const char *s1, const char *s2)
    263 {
    264   while (*s1 != '\0' && toupper(*s1) == toupper(*s2))
    265     {
    266       s1++;
    267       s2++;
    268     }
    269 
    270   return toupper(*(unsigned char *) s1) - toupper(*(unsigned char *) s2);
    271 }
  • trunk/src/gmakenew/vmsify.c

    r503 r903  
    6464
    6565static int
    66 copyto (char **to, char **from, char upto, int as_dir)
     66copyto (char **to, const char **from, char upto, int as_dir)
    6767{
    68   char *s;
     68  const char *s;
    6969
    7070  s = strrchr (*from, '.');
     
    112112
    113113static char *
    114 trnlog (char *name)
     114trnlog (const char *name)
    115115{
    116116  int stat;
     
    135135  reslt[resltlen] = '\0';
    136136
    137   s = (char *)malloc (resltlen+1);
     137  s = malloc (resltlen+1);
    138138  if (s == 0)
    139139    return "";
     
    20620626  filenames with a single pair of '[' ']' are left unchanged
    207207
    208   the input string is not written to
     208  The input string is not written to.  The result is also const because
     209  it's a static buffer; we don't want to change it.
    209210*/
    210211
    211 char *
    212 vmsify (char *name, int type)
     212const char *
     213vmsify (const char *name, int type)
    213214{
    214215/* max 255 device
     
    222223  enum namestate nstate;
    223224  static char vmsname[MAXPATHLEN+1];
    224   char *fptr;
     225  const char *fptr;
     226  const char *t;
    225227  char *vptr;
    226   char *s,*s1;
    227228  int as_dir;
    228229  int count;
     
    235236
    236237  /* case 25a */
    237 
    238   s = strpbrk (name, "$:");
    239   if (s != 0)
    240     {
    241       char *s1;
    242       char *s2;
     238  t = strpbrk (name, "$:");
     239
     240  if (t != 0)
     241    {
     242      const char *s1;
     243      const char *s2;
    243244
    244245      if (type == 1)
    245         {
    246           s1 = strchr (s+1, '[');
    247           s2 = strchr (s+1, ']');
    248         }
    249 
    250       if (*s == '$')
    251         {
    252           if (strchr (name, '/') == 0)
    253             {
    254               if ((type == 1) && (s1 != 0) && (s2 == 0))
    255                 {
    256                   strcpy (vmsname, name);
    257                   strcat (vmsname, "]");
    258                   return vmsname;
    259                 }
    260               else
    261                 return name;
    262             }
    263         }
     246        {
     247          s1 = strchr (t+1, '[');
     248          s2 = strchr (t+1, ']');
     249        }
     250
     251      if (*t == '$')
     252        {
     253          if (strchr (name, '/') == 0)
     254            {
     255              strcpy (vmsname, name);
     256              if ((type == 1) && (s1 != 0) && (s2 == 0))
     257                strcat (vmsname, "]");
     258              return vmsname;
     259            }
     260        }
    264261      else
    265         {
    266           if ((type == 1) && (s1 != 0) && (s2 == 0))
    267             {
    268               strcpy (vmsname, name);
    269               strcat (vmsname, "]");
    270               return vmsname;
    271             }
    272           else
    273             return name;
    274         }
     262        {
     263          strcpy (vmsname, name);
     264          if ((type == 1) && (s1 != 0) && (s2 == 0))
     265            strcat (vmsname, "]");
     266          return vmsname;
     267        }
    275268    }
    276269
    277270  /* case 26 */
    278 
    279   s = strchr (name, '[');
    280 
    281   if (s != 0)
    282     {
    283       s1 = strchr (s+1, '[');
     271  t = strchr (name, '[');
     272
     273  if (t != 0)
     274    {
     275      const char *s;
     276      const char *s1 = strchr (t+1, '[');
    284277      if (s1 == 0)
    285278        {
    286           if ((type == 1)
    287                && (strchr (s+1, ']') == 0))
    288             {
    289               strcpy (vmsname, name);
    290               strcat (vmsname, "]");
    291               return vmsname;
    292             }
    293           else
    294             return name;                        /* single [, keep unchanged */
     279          strcpy (vmsname, name);
     280          if ((type == 1) && (strchr (t+1, ']') == 0))
     281            strcat (vmsname, "]");
     282          return vmsname;
    295283        }
    296284      s1--;
    297285      if (*s1 != ']')
    298286        {
    299           return name;                  /* not ][, keep unchanged */
     287          strcpy (vmsname, name);
     288          return vmsname;               /* not ][, keep unchanged */
    300289        }
    301290
     
    306295      /* s  -> starting char
    307296         s1 -> ending ']'  */
    308 
    309297      do
    310298        {
     
    330318
    331319    }
    332 
    333320  else          /* no [ in name */
    334 
    335     {
    336 
    337       int state;
     321    {
     322      int state = 0;
    338323      int rooted = 1;   /* flag if logical is rooted, else insert [000000] */
    339 
    340       state = 0;
    341324
    342325      do
    343326        {
    344 
    345327      switch (state)
    346328        {
     
    371353
    372354          case 2:                               /* no '/' at start */
    373             s = strchr (fptr, '/');
     355            {
     356            const char *s = strchr (fptr, '/');
    374357            if (s == 0)                 /* no '/' (16) */
    375358              {
     
    402385              }
    403386            break;
     387            }
    404388
    405389          case 3:                               /* '//' at start */
     390            {
     391            const char *s;
     392            const char *s1;
     393            char *vp;
    406394            while (*fptr == '/')        /* collapse all '/' */
    407395              fptr++;
     
    413401                if (s1 == 0)
    414402                  {
    415                     return "";          /* FIXME, err getcwd */
     403                    vmsname[0] = '\0';
     404                    return vmsname;     /* FIXME, err getcwd */
    416405                  }
    417406                s = strchr (s1, ':');
    418407                if (s == 0)
    419408                  {
    420                     return "";          /* FIXME, err no device */
     409                    vmsname[0] = '\0';
     410                    return vmsname;     /* FIXME, err no device */
    421411                  }
    422412                strncpy (vptr, s1, s-s1+1);
     
    445435            *vptr = 0;
    446436                                /* check logical for [000000] insertion */
    447             s1 = trnlog (s);
    448             if (*s1 != 0)
     437            vp = trnlog (s);
     438            if (*vp != '\0')
    449439              {                 /* found translation */
    450                 char *s2;
    451440                for (;;)        /* loop over all nested logicals */
    452441                  {
    453                     s2 = s1 + strlen (s1) - 1;
    454                     if (*s2 == ':')     /* translation ends in ':' */
    455                       {
    456                         s2 = trnlog (s1);
    457                         free (s1);
    458                         if (*s2 == 0)
     442                    char *vp2 = vp + strlen (vp) - 1;
     443                    if (*vp2 == ':')    /* translation ends in ':' */
     444                      {
     445                        vp2 = trnlog (vp);
     446                        free (vp);
     447                        if (*vp2 == 0)
    459448                          {
    460449                            rooted = 0;
    461450                            break;
    462451                          }
    463                         s1 = s2;
     452                        vp = vp2;
    464453                        continue;       /* next iteration */
    465454                      }
    466                     if (*s2 == ']')     /* translation ends in ']' */
    467                       {
    468                         if (*(s2-1) == '.')     /* ends in '.]' */
     455                    if (*vp2 == ']')    /* translation ends in ']' */
     456                      {
     457                        if (*(vp2-1) == '.')    /* ends in '.]' */
    469458                          {
    470459                            if (strncmp (fptr, "000000", 6) != 0)
     
    474463                          {
    475464                            strcpy (vmsname, s1);
    476                             s = strchr (vmsname, ']');
    477                             *s = '.';
     465                            vp = strchr (vmsname, ']');
     466                            *vp = '.';
    478467                            nstate = N_DOT;
    479                             vptr = s;
     468                            vptr = vp;
    480469                          }
    481470                      }
    482471                    break;
    483472                  }
    484                 free (s1);
     473                free (vp);
    485474              }
    486475            else
     
    497486            if (rooted == 0)
    498487              {
     488                nstate = N_DOT;
    499489                strcpy (vptr, "[000000.");
    500490                vptr += 8;
    501                 s1 = vptr-1;
    502                 nstate = N_DOT;
    503               }
    504             else
    505               s1 = 0;
    506 
    507         /* s1-> '.' after 000000 or NULL */
     491                vp = vptr-1;
     492              }
     493            else
     494              vp = 0;
     495
     496            /* vp-> '.' after 000000 or NULL */
    508497
    509498            s = strchr (fptr, '/');
     
    532521            else
    533522              if ((nstate == N_DOT)
    534                  && (s1 != 0)
     523                 && (vp != 0)
    535524                 && (*(s+1) == 0))
    536525                {
    537526                  if (type == 2)
    538527                    {
    539                       *s1 = ']';
     528                      *vp = ']';
    540529                      nstate = N_CLOSED;
    541530                    }
     
    543532            state = 9;
    544533            break;
    545 
     534            }
    546535          case 4:                               /* single '/' at start (9..15) */
    547536            if (*fptr == 0)
     
    565554            break;
    566555
    567           case 6:                               /* chars following '/' at start 10..15 */
     556          case 6:               /* chars following '/' at start 10..15 */
     557            {
     558            const char *s;
    568559            *vptr++ = '[';
    569560            nstate = N_OPEN;
     
    596587              }
    597588            break;
     589            }
    598590
    599591          case 7:                               /* add '.dir' and exit */
     
    601593                || (nstate == N_DOT))
    602594              {
    603                 s = vptr-1;
    604                 while (s > vmsname)
    605                   {
    606                     if (*s == ']')
     595                char *vp = vptr-1;
     596                while (vp > vmsname)
     597                  {
     598                    if (*vp == ']')
    607599                      {
    608600                        break;
    609601                      }
    610                     if (*s == '.')
    611                       {
    612                         *s = ']';
     602                    if (*vp == '.')
     603                      {
     604                        *vp = ']';
    613605                        break;
    614606                      }
    615                     s--;
     607                    vp--;
    616608                  }
    617609              }
     
    626618            break;
    627619
    628           case 9:                               /* 17..21, fptr -> 1st '/' + 1 */
     620          case 9:                       /* 17..21, fptr -> 1st '/' + 1 */
     621            {
     622            const char *s;
    629623            if (*fptr == 0)
    630624              {
     
    688682                    || (*(fptr+2) == 0)) )
    689683              {
     684                char *vp;
    690685                fptr += 2;
    691686                if (*fptr == '/')
     
    700695                  type = 1;
    701696                vptr--;                         /* vptr -> '.' or ']' */
    702                 s1 = vptr;
     697                vp = vptr;
    703698                for (;;)
    704699                  {
    705                     s1--;
    706                     if (*s1 == '.')             /* one back */
    707                       {
    708                         vptr = s1;
     700                    vp--;
     701                    if (*vp == '.')             /* one back */
     702                      {
     703                        vptr = vp;
    709704                        nstate = N_OPEN;
    710705                        break;
    711706                      }
    712                     if (*s1 == '[')             /* top level reached */
     707                    if (*vp == '[')             /* top level reached */
    713708                      {
    714709                        if (*fptr == 0)
    715710                          {
    716                             strcpy (s1, "[000000]");
    717                             vptr = s1 + 8;
     711                            strcpy (vp, "[000000]");
     712                            vptr = vp + 8;
    718713                            nstate = N_CLOSED;
    719714                            s = 0;
     
    722717                        else
    723718                          {
    724                             vptr = s1+1;
     719                            vptr = vp+1;
    725720                            nstate = N_OPEN;
    726721                            break;
     
    757752              }
    758753            break;
     754            }
    759755
    760756          case 10:                              /* 1,2 first is '.' */
     
    774770                if (*fptr != '/')               /* got ..xxx */
    775771                  {
    776                     return name;
     772                    strcpy (vmsname, name);
     773                    return vmsname;
    777774                  }
    778775                do                              /* got ../ */
     
    792789              }
    793790            {                                   /* got '..' or '../' */
     791              char *vp;
    794792              char cwdbuf[MAXPATHLEN+1];
    795793
    796               s1 = getcwd(cwdbuf, MAXPATHLEN);
    797               if (s1 == 0)
     794              vp = getcwd(cwdbuf, MAXPATHLEN);
     795              if (vp == 0)
    798796                {
    799                   return "";        /* FIXME, err getcwd */
     797                  vmsname[0] = '\0';
     798                  return vmsname;    /* FIXME, err getcwd */
    800799                }
    801               strcpy (vptr, s1);
    802               s = strchr (vptr, ']');
    803               if (s != 0)
     800              strcpy (vptr, vp);
     801              vp = strchr (vptr, ']');
     802              if (vp != 0)
    804803                {
    805804                  nstate = N_OPEN;
    806                   while (s > vptr)
     805                  while (vp > vptr)
    807806                    {
    808                       s--;
    809                       if (*s == '[')
     807                      vp--;
     808                      if (*vp == '[')
    810809                        {
    811                           s++;
    812                           strcpy (s, "000000]");
     810                          vp++;
     811                          strcpy (vp, "000000]");
    813812                          state = -1;
    814813                          break;
    815814                        }
    816                       else if (*s == '.')
     815                      else if (*vp == '.')
    817816                        {
    818817                          if (--count == 0)
     
    820819                              if (*fptr == 0)   /* had '..' or '../' */
    821820                                {
    822                                   *s++ = ']';
     821                                  *vp++ = ']';
    823822                                  state = -1;
    824823                                }
     
    827826                                  state = 9;
    828827                                }
    829                               *s = 0;
     828                              *vp = '\0';
    830829                              break;
    831830                            }
     
    842841                if (*fptr != '/')
    843842                  {
    844                     return name;
     843                    strcpy (vmsname, name);
     844                    return vmsname;
    845845                  }
    846846                while (*fptr == '/')
     
    849849
    850850            {
     851              char *vp;
    851852              char cwdbuf[MAXPATHLEN+1];
    852853
    853               s1 = getcwd(cwdbuf, MAXPATHLEN);
    854               if (s1 == 0)
     854              vp = getcwd(cwdbuf, MAXPATHLEN);
     855              if (vp == 0)
    855856                {
    856                   return "";        /*FIXME, err getcwd */
     857                  vmsname[0] = '\0';
     858                  return vmsname;    /*FIXME, err getcwd */
    857859                }
    858               strcpy (vptr, s1);
    859               if (*fptr == 0)
    860                 {
    861                   state = -1;
    862                   break;
    863                 }
    864               else
    865                 {
    866                   s = strchr (vptr, ']');
    867                   if (s == 0)
    868                     {
    869                       state = -1;
    870                       break;
    871                     }
    872                   *s = 0;
    873                   nstate = N_OPEN;
    874                   vptr += strlen (vptr);
    875                   state = 9;
    876                 }
    877             }
     860              strcpy (vptr, vp);
     861            }
     862            if (*fptr == 0)
     863              {
     864                state = -1;
     865                break;
     866              }
     867            else
     868              {
     869                char *vp = strchr (vptr, ']');
     870                if (vp == 0)
     871                  {
     872                    state = -1;
     873                    break;
     874                  }
     875                *vp = '\0';
     876                nstate = N_OPEN;
     877                vptr += strlen (vptr);
     878                state = 9;
     879              }
    878880            break;
    879881        }
     
    904906*/
    905907
    906 char *
    907 unixify (char *name)
     908const char *
     909unixify (const char *name)
    908910{
    909911  static char piece[512];
    910   char *s, *p;
     912  const char *s;
     913  char *p;
    911914
    912915  if (strchr (name, '/') != 0)          /* already in unix style */
    913     return name;
     916    {
     917      strcpy (piece, name);
     918      return piece;
     919    }
    914920
    915921  p = piece;
     
    922928  if (s != 0)
    923929    {
    924       *s = 0;
     930      int l = s - name;
    925931      *p++ = '/';
    926932      *p++ = '/';
    927       strcpy (p, name);
    928       p += strlen (p);
    929       *s = ':';
     933      strncpy (p, name, l);
     934      p += l;
    930935    }
    931936
  • trunk/src/gmakenew/vmsjobs.c

    r503 r903  
    2222#include <clidef.h>
    2323
    24 extern char *vmsify PARAMS ((char *name, int type));
     24char *vmsify (char *name, int type);
    2525
    2626static int vms_jobsefnmask = 0;
  • trunk/src/gmakenew/vpath.c

    r527 r903  
    3030  {
    3131    struct vpath *next; /* Pointer to next struct in the linked list.  */
    32     char *pattern;      /* The pattern to match.  */
    33     char *percent;      /* Pointer into `pattern' where the `%' is.  */
     32    const char *pattern;/* The pattern to match.  */
     33    const char *percent;/* Pointer into `pattern' where the `%' is.  */
    3434    unsigned int patlen;/* Length of the pattern.  */
    35     char **searchpath;  /* Null-terminated list of directories.  */
     35    const char **searchpath; /* Null-terminated list of directories.  */
    3636    unsigned int maxlen;/* Maximum length of any entry in the list.  */
    3737  };
     
    5050
    5151
    52 static int selective_vpath_search PARAMS ((struct vpath *path, char **file, FILE_TIMESTAMP *mtime_ptr));
    53 
    54 /* Reverse the chain of selective VPATH lists so they
    55    will be searched in the order given in the makefiles
    56    and construct the list from the VPATH variable.  */
     52
     53/* Reverse the chain of selective VPATH lists so they will be searched in the
     54   order given in the makefiles and construct the list from the VPATH
     55   variable.  */
    5756
    5857void
     
    9796      /* Save the list of vpaths.  */
    9897      struct vpath *save_vpaths = vpaths;
     98      char gp[] = "%";
    9999
    100100      /* Empty `vpaths' so the new one will have no next, and `vpaths'
     
    103103
    104104      /* Parse P.  */
    105       construct_vpath_list ("%", p);
     105      construct_vpath_list (gp, p);
    106106
    107107      /* Store the created path as the general path,
     
    133133      /* Save the list of vpaths.  */
    134134      struct vpath *save_vpaths = vpaths;
     135      char gp[] = "%";
    135136
    136137      /* Empty `vpaths' so the new one will have no next, and `vpaths'
     
    139140
    140141      /* Parse P.  */
    141       construct_vpath_list ("%", p);
     142      construct_vpath_list (gp, p);
    142143
    143144      /* Store the created path as the GPATH,
     
    171172construct_vpath_list (char *pattern, char *dirpath)
    172173{
    173   register unsigned int elem;
    174   register char *p;
    175   register char **vpath;
    176   register unsigned int maxvpath;
     174  unsigned int elem;
     175  char *p;
     176  const char **vpath;
     177  unsigned int maxvpath;
    177178  unsigned int maxelem;
    178   char *percent = NULL;
     179  const char *percent = NULL;
    179180
    180181  if (pattern != 0)
    181     {
    182       pattern = xstrdup (pattern);
    183       percent = find_percent (pattern);
    184     }
     182    percent = find_percent (pattern);
    185183
    186184  if (dirpath == 0)
    187185    {
    188186      /* Remove matching listings.  */
    189       register struct vpath *path, *lastpath;
     187      struct vpath *path, *lastpath;
    190188
    191189      lastpath = 0;
     
    207205
    208206              /* Free its unused storage.  */
    209               free (path->pattern);
    210               free ((char *) path->searchpath);
    211               free ((char *) path);
     207              free (path->searchpath);
     208              free (path);
    212209            }
    213210          else
     
    217214        }
    218215
    219       if (pattern != 0)
    220         free (pattern);
    221216      return;
    222217    }
     
    225220    convert_vpath_to_windows32(dirpath, ';');
    226221#endif
     222
     223  /* Skip over any initial separators and blanks.  */
     224  while (*dirpath == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*dirpath))
     225    ++dirpath;
    227226
    228227  /* Figure out the maximum number of VPATH entries and put it in
     
    236235      ++maxelem;
    237236
    238   vpath = (char **) xmalloc (maxelem * sizeof (char *));
     237  vpath = xmalloc (maxelem * sizeof (const char *));
    239238  maxvpath = 0;
    240239
    241   /* Skip over any initial separators and blanks.  */
     240  elem = 0;
    242241  p = dirpath;
    243   while (*p == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*p))
    244     ++p;
    245 
    246   elem = 0;
    247242  while (*p != '\0')
    248243    {
     
    266261        --len;
    267262
     263      /* Put the directory on the vpath list.  */
    268264      if (len > 1 || *v != '.')
    269265        {
    270           v = savestring (v, len);
    271 
    272           /* Verify that the directory actually exists.  */
    273 
    274           if (dir_file_exists_p (v, ""))
    275             {
    276               /* It does.  Put it in the list.  */
    277               vpath[elem++] = dir_name (v);
    278               free (v);
    279               if (len > maxvpath)
    280                 maxvpath = len;
    281             }
    282           else
    283             /* The directory does not exist.  Omit from the list.  */
    284             free (v);
     266          vpath[elem++] = dir_name (strcache_add_len (v, len));
     267          if (len > maxvpath)
     268            maxvpath = len;
    285269        }
    286270
     
    297281         Usually this is maxelem - 1.  If not, shrink down.  */
    298282      if (elem < (maxelem - 1))
    299         vpath = (char **) xrealloc ((char *) vpath,
    300                                     (elem + 1) * sizeof (char *));
     283        vpath = xrealloc (vpath, (elem+1) * sizeof (const char *));
    301284
    302285      /* Put the nil-pointer terminator on the end of the VPATH list.  */
    303       vpath[elem] = 0;
     286      vpath[elem] = NULL;
    304287
    305288      /* Construct the vpath structure and put it into the linked list.  */
    306       path = (struct vpath *) xmalloc (sizeof (struct vpath));
     289      path = xmalloc (sizeof (struct vpath));
    307290      path->searchpath = vpath;
    308291      path->maxlen = maxvpath;
     
    311294
    312295      /* Set up the members.  */
    313       path->pattern = pattern;
    314       path->percent = percent;
     296      path->pattern = strcache_add (pattern);
    315297      path->patlen = strlen (pattern);
     298      path->percent = percent ? path->pattern + (percent - pattern) : 0;
    316299    }
    317300  else
    318     {
    319       /* There were no entries, so free whatever space we allocated.  */
    320       free ((char *) vpath);
    321       if (pattern != 0)
    322         free (pattern);
    323     }
     301    /* There were no entries, so free whatever space we allocated.  */
     302    free (vpath);
    324303}
    325304
     
    329308
    330309int
    331 gpath_search (char *file, unsigned int len)
     310gpath_search (const char *file, unsigned int len)
    332311{
    333   char **gp;
     312  const char **gp;
    334313
    335314  if (gpaths && (len <= gpaths->maxlen))
     
    342321
    343322
    344 /* Search the VPATH list whose pattern matches *FILE for a directory
    345    where the name pointed to by FILE exists.  If it is found, we set *FILE to
    346    the newly malloc'd name of the existing file, *MTIME_PTR (if MTIME_PTR is
    347    not NULL) to its modtime (or zero if no stat call was done), and return 1.
    348    Otherwise we return 0.  */
    349 
    350 int
    351 vpath_search (char **file, FILE_TIMESTAMP *mtime_ptr)
    352 {
    353   register struct vpath *v;
    354 
    355   /* If there are no VPATH entries or FILENAME starts at the root,
    356      there is nothing we can do.  */
    357 
    358   if (**file == '/'
    359 #ifdef HAVE_DOS_PATHS
    360       || **file == '\\'
    361       || (*file)[1] == ':'
    362 #endif
    363       || (vpaths == 0 && general_vpath == 0))
    364     return 0;
    365 
    366   for (v = vpaths; v != 0; v = v->next)
    367     if (pattern_matches (v->pattern, v->percent, *file))
    368       if (selective_vpath_search (v, file, mtime_ptr))
    369         return 1;
    370 
    371   if (general_vpath != 0
    372       && selective_vpath_search (general_vpath, file, mtime_ptr))
    373     return 1;
    374 
    375   return 0;
    376 }
    377 
    378 
    379 /* Search the given VPATH list for a directory where the name pointed
    380    to by FILE exists.  If it is found, we set *FILE to the newly malloc'd
    381    name of the existing file, *MTIME_PTR (if MTIME_PTR is not NULL) to
    382    its modtime (or zero if no stat call was done), and we return 1.
    383    Otherwise we return 0.  */
    384 
    385 static int
    386 selective_vpath_search (struct vpath *path, char **file,
     323
     324/* Search the given VPATH list for a directory where the name pointed to by
     325   FILE exists.  If it is found, we return a cached name of the existing file
     326   and set *MTIME_PTR (if MTIME_PTR is not NULL) to its modtime (or zero if no
     327   stat call was done).  Otherwise we return NULL.  */
     328
     329static const char *
     330selective_vpath_search (struct vpath *path, const char *file,
    387331                        FILE_TIMESTAMP *mtime_ptr)
    388332{
    389333  int not_target;
    390   char *name, *n;
    391   char *filename;
    392   register char **vpath = path->searchpath;
     334  char *name;
     335  const char *n;
     336  const char *filename;
     337  const char **vpath = path->searchpath;
    393338  unsigned int maxvpath = path->maxlen;
    394   register unsigned int i;
     339  unsigned int i;
    395340  unsigned int flen, vlen, name_dplen;
    396341  int exists = 0;
     
    400345     files that don't exist but are mentioned in a makefile.  */
    401346  {
    402     struct file *f = lookup_file (*file);
     347    struct file *f = lookup_file (file);
    403348    not_target = f == 0 || !f->is_target;
    404349  }
    405350
    406   flen = strlen (*file);
     351  flen = strlen (file);
    407352
    408353  /* Split *FILE into a directory prefix and a name-within-directory.
    409      NAME_DPLEN gets the length of the prefix; FILENAME gets the
    410      pointer to the name-within-directory and FLEN is its length.  */
    411 
    412   n = strrchr (*file, '/');
     354     NAME_DPLEN gets the length of the prefix; FILENAME gets the pointer to
     355     the name-within-directory and FLEN is its length.  */
     356
     357  n = strrchr (file, '/');
    413358#ifdef HAVE_DOS_PATHS
    414359  /* We need the rightmost slash or backslash.  */
    415360  {
    416     char *bslash = strrchr(*file, '\\');
     361    const char *bslash = strrchr(file, '\\');
    417362    if (!n || bslash > n)
    418363      n = bslash;
    419364  }
    420365#endif
    421   name_dplen = n != 0 ? n - *file : 0;
    422   filename = name_dplen > 0 ? n + 1 : *file;
     366  name_dplen = n != 0 ? n - file : 0;
     367  filename = name_dplen > 0 ? n + 1 : file;
    423368  if (name_dplen > 0)
    424369    flen -= name_dplen + 1;
    425370
    426   /* Allocate enough space for the biggest VPATH entry,
    427      a slash, the directory prefix that came with *FILE,
    428      another slash (although this one may not always be
    429      necessary), the filename, and a null terminator.  */
    430   name = (char *) xmalloc (maxvpath + 1 + name_dplen + 1 + flen + 1);
     371  /* Get enough space for the biggest VPATH entry, a slash, the directory
     372     prefix that came with FILE, another slash (although this one may not
     373     always be necessary), the filename, and a null terminator.  */
     374  name = alloca (maxvpath + 1 + name_dplen + 1 + flen + 1);
    431375
    432376  /* Try each VPATH entry.  */
     
    434378    {
    435379      int exists_in_cache = 0;
    436 
    437       n = name;
    438 
    439       /* Put the next VPATH entry into NAME at N and increment N past it.  */
     380      char *p;
     381
     382      p = name;
     383
     384      /* Put the next VPATH entry into NAME at P and increment P past it.  */
    440385      vlen = strlen (vpath[i]);
    441       bcopy (vpath[i], n, vlen);
    442       n += vlen;
     386      memcpy (p, vpath[i], vlen);
     387      p += vlen;
    443388
    444389      /* Add the directory prefix already in *FILE.  */
     
    446391        {
    447392#ifndef VMS
    448           *n++ = '/';
    449 #endif
    450           bcopy (*file, n, name_dplen);
    451           n += name_dplen;
     393          *p++ = '/';
     394#endif
     395          memcpy (p, file, name_dplen);
     396          p += name_dplen;
    452397        }
    453398
    454399#ifdef HAVE_DOS_PATHS
    455400      /* Cause the next if to treat backslash and slash alike.  */
    456       if (n != name && n[-1] == '\\' )
    457         n[-1] = '/';
     401      if (p != name && p[-1] == '\\' )
     402        p[-1] = '/';
    458403#endif
    459404      /* Now add the name-within-directory at the end of NAME.  */
    460405#ifndef VMS
    461       if (n != name && n[-1] != '/')
     406      if (p != name && p[-1] != '/')
    462407        {
    463           *n = '/';
    464           bcopy (filename, n + 1, flen + 1);
     408          *p = '/';
     409          memcpy (p + 1, filename, flen + 1);
    465410        }
    466411      else
    467412#endif
    468         bcopy (filename, n, flen + 1);
     413        memcpy (p, filename, flen + 1);
    469414
    470415      /* Check if the file is mentioned in a makefile.  If *FILE is not
     
    513458          /* Clobber a null into the name at the last slash.
    514459             Now NAME is the name of the directory to look in.  */
    515           *n = '\0';
     460          *p = '\0';
    516461
    517462          /* We know the directory is in the hash table now because either
     
    534479#ifndef VMS
    535480          /* Put the slash back in NAME.  */
    536           *n = '/';
     481          *p = '/';
    537482#endif
    538483
     
    557502
    558503          /* We have found a file.
    559              Store the name we found into *FILE for the caller.  */
    560 
    561           *file = savestring (name, (n + 1 - name) + flen);
    562 
    563           /* If we get here and mtime_ptr hasn't been set, record
     504             If we get here and mtime_ptr hasn't been set, record
    564505             UNKNOWN_MTIME to indicate this.  */
    565506          if (mtime_ptr != 0)
    566507            *mtime_ptr = UNKNOWN_MTIME;
    567508
    568           free (name);
    569           return 1;
     509          /* Store the name we found and return it.  */
     510
     511          return strcache_add_len (name, (p + 1 - name) + flen);
    570512        }
    571513    }
    572514
    573   free (name);
     515  return 0;
     516}
     517
     518
     519/* Search the VPATH list whose pattern matches FILE for a directory where FILE
     520   exists.  If it is found, return the cached name of an existing file, and
     521   set *MTIME_PTR (if MTIME_PTR is not NULL) to its modtime (or zero if no
     522   stat call was done).  Otherwise we return 0.  */
     523
     524const char *
     525vpath_search (const char *file, FILE_TIMESTAMP *mtime_ptr)
     526{
     527  struct vpath *v;
     528
     529  /* If there are no VPATH entries or FILENAME starts at the root,
     530     there is nothing we can do.  */
     531
     532  if (file[0] == '/'
     533#ifdef HAVE_DOS_PATHS
     534      || file[0] == '\\' || file[1] == ':'
     535#endif
     536      || (vpaths == 0 && general_vpath == 0))
     537    return 0;
     538
     539  for (v = vpaths; v != 0; v = v->next)
     540    if (pattern_matches (v->pattern, v->percent, file))
     541      {
     542        const char *p = selective_vpath_search (v, file, mtime_ptr);
     543        if (p)
     544          return p;
     545      }
     546
     547  if (general_vpath != 0)
     548    {
     549      const char *p = selective_vpath_search (general_vpath, file, mtime_ptr);
     550      if (p)
     551        return p;
     552    }
     553
    574554  return 0;
    575555}
     
    581561print_vpath_data_base (void)
    582562{
    583   register unsigned int nvpaths;
    584   register struct vpath *v;
     563  unsigned int nvpaths;
     564  struct vpath *v;
    585565
    586566  puts (_("\n# VPATH Search Paths\n"));
     
    609589  else
    610590    {
    611       register char **path = general_vpath->searchpath;
    612       register unsigned int i;
     591      const char **path = general_vpath->searchpath;
     592      unsigned int i;
    613593
    614594      fputs (_("\n# General (`VPATH' variable) search path:\n# "), stdout);
  • trunk/src/gmakenew/w32/include/pathstuff.h

    r503 r903  
    1919#define _PATHSTUFF_H
    2020
    21 extern char * convert_Path_to_windows32(char *Path, char to_delim);
    22 extern char * convert_vpath_to_windows32(char *Path, char to_delim);
    23 extern char * w32ify(char *file, int resolve);
    24 extern char * getcwd_fs(char *buf, int len);
     21char *convert_Path_to_windows32(char *Path, char to_delim);
     22char *convert_vpath_to_windows32(char *Path, char to_delim);
     23char *w32ify(const char *filename, int resolve);
     24char *getcwd_fs(char *buf, int len);
    2525
    2626#endif
  • trunk/src/gmakenew/w32/pathstuff.c

    r728 r903  
    8282}
    8383
    84 /* 
     84/*
    8585 * Corrects the case of a path.
    8686 * Expects a fullpath!
    8787 * Added by bird for the $(abspath ) function and w32ify
    8888 */
    89 void 
     89void
    9090w32_fixcase(char *pszPath)
    9191{
     
    105105#else
    106106# define my_assert(expr) do {} while (0)
    107 #endif 
    108    
     107#endif
     108
    109109    char *psz = pszPath;
    110110    if (*psz == '/' || *psz == '\\')
     
    191191
    192192    /*
    193      * Pointing to the first char after the unc or drive specifier, 
     193     * Pointing to the first char after the unc or drive specifier,
    194194     * or in case of a cache hit, the first non-matching char (following a slash of course).
    195195     */
     
    261261 */
    262262char *
    263 w32ify(char *filename, int resolve)
     263w32ify(const char *filename, int resolve)
    264264{
    265265    static char w32_path[FILENAME_MAX];
     
    293293
    294294#undef stat
    295 /* 
    296  * Workaround for directory names with trailing slashes. 
     295/*
     296 * Workaround for directory names with trailing slashes.
    297297 * Added by bird reasons stated.
    298298 */
    299 int 
     299int
    300300my_stat(const char *path, struct stat *st)
    301301{
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