- Timestamp:
- May 23, 2007 5:31:19 AM (18 years ago)
- Location:
- trunk/src/gmakenew
- Files:
-
- 1 added
- 126 deleted
- 50 edited
- 20 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmakenew/ChangeLog
r503 r903 1 2007-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 17 2007-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 39 2007-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 44 2007-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 59 2007-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 64 2006-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 93 2006-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 98 2006-10-22 Paul Smith <[email protected]> 99 100 * main.c (struct command_switch): Use const and void*. 101 102 2006-10-21 Paul Smith <[email protected]> 103 104 * ar.c: Constified. 105 * arscan.c: Constified. 106 107 2006-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 133 2006-09-06 Paul D. Smith <[email protected]> 134 135 * configure.in: Include sys/types.h when checking for sys/wait.h. 136 137 2006-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 151 2006-05-07 Paul D. Smith <[email protected]> 152 153 * README.OS2.template: Updates provided by Andreas Buening 154 <[email protected]>. 155 156 2006-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 161 2006-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 167 2006-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 173 2006-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 200 2006-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 1 217 2006-04-01 Paul D. Smith <[email protected]> 2 218 … … 54 270 (main): If we are re-execing, clean up the jobserver first so we 55 271 don't leak file descriptors. 56 Fix bug reported by Craig Fithian <[email protected]>.272 Reported by Craig Fithian <[email protected]> 57 273 58 274 2006-03-17 Paul D. Smith <[email protected]> -
trunk/src/gmakenew/Makefile.am
r503 r903 17 17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 18 19 AUTOMAKE_OPTIONS = 1.8 dist-bzip2 check-news ansi2knr19 AUTOMAKE_OPTIONS = 1.8 dist-bzip2 check-news 20 20 ACLOCAL_AMFLAGS = -I config 21 21 -
trunk/src/gmakenew/Makefile.kmk
r864 r903 3 3 4 4 DEPTH = ../.. 5 PATH_GNUMAKE_SRC = $(PATH_ROOT)/src/gmakenew 5 6 include $(PATH_KBUILD)/header.kmk 6 7 … … 13 14 TEMPLATE_BIN-KMK_DEFS = HAVE_CONFIG_H $(TEMPLATE_BIN_DEFS) 14 15 TEMPLATE_BIN-KMK_DEPS = $(PATH_TARGET)/config.h 16 TEMPLATE_BIN-KMK_CLEAN = $(TEMPLATE_BIN-KMK_DEPS) 15 17 TEMPLATE_BIN-KMK_DEPS.solaris = \ 16 18 $(PATH_TARGET)/fts.h \ 17 19 $(PATH_TARGET)/paths.h 20 TEMPLATE_BIN-KMK_CLEAN.solaris = $(TEMPLATE_BIN-KMK_DEPS.solaris) 18 21 TEMPLATE_BIN-KMK_DEPS.win = \ 19 22 $(PATH_TARGET)/fts.h \ … … 24 27 $(PATH_TARGET)/pwd.h \ 25 28 $(PATH_TARGET)/inttypes.h 29 TEMPLATE_BIN-KMK_CLEAN.win = $(TEMPLATE_BIN-KMK_DEPS.win) 26 30 TEMPLATE_BIN-KMK_INCS = $(PATH_TARGET) . $(TEMPLATE_BIN_INCS) 27 31 TEMPLATE_BIN-KMK_INCS.darwin = glob … … 98 102 CONFIG_WITH_INCLUDEDEP \ 99 103 CONFIG_WITH_VALUE_LENGTH \ 104 CONFIG_WITH_RSORT \ 100 105 CONFIG_WITH_ABSPATHEX \ 101 106 CONFIG_WITH_COMPARE \ … … 266 271 # 267 272 config.h.$(BUILD_TARGET) := config.h.$(BUILD_TARGET) 268 config.h.win := config.h.W32269 270 273 $(PATH_TARGET)/config.h: $(config.h.$(BUILD_TARGET)) 271 274 $(MKDIR) -p $(dir $@) -
trunk/src/gmakenew/NEWS
r503 r903 9 9 See the README file and the GNU make manual for instructions for 10 10 reporting bugs. 11 12 13 Version 3.81.90 14 15 * Compiling GNU make now requires a conforming ISO C 1989 compiler and 16 standard runtime library. 17 11 18 12 19 -
trunk/src/gmakenew/acinclude.m4
r503 r903 63 63 AC_CHECK_FUNCS(gethostbyname,,[ 64 64 CF_RECHECK_FUNC(gethostbyname,nsl,cf_cv_netlibs)]) 65 #66 AC_CHECK_FUNCS(strcasecmp,,[67 CF_RECHECK_FUNC(strcasecmp,resolv,cf_cv_netlibs)])68 65 ]) 69 66 LIBS="$LIBS $cf_cv_netlibs" -
trunk/src/gmakenew/amiga.h
r503 r903 16 16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ 17 17 18 extern int MyExecute PARAMS ((char ** argv)); 19 extern char * wildcard_expansion PARAMS ((char * wc, char * o)); 20 18 int MyExecute (char ** argv); 19 char * wildcard_expansion (char * wc, char * o); -
trunk/src/gmakenew/ar.c
r503 r903 25 25 #include <fnmatch.h> 26 26 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 VMS31 extern int ar_member_touch PARAMS ((char *arname, char *memname));32 #endif33 34 27 /* Return nonzero if NAME is an archive-member reference, zero if not. 35 28 An archive-member reference is a name like `lib(member)'. … … 38 31 39 32 int 40 ar_name (c har *name)41 { 42 c har *p = strchr (name, '(');43 c har *end;33 ar_name (const char *name) 34 { 35 const char *p = strchr (name, '('); 36 const char *end; 44 37 45 38 if (p == 0 || p == name) … … 58 51 59 52 /* 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. */ 62 55 63 56 void 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)); 57 ar_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 */ 73 static long int 74 ar_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 } 78 82 79 83 /* Return the modtime of NAME. */ 80 84 81 85 time_t 82 ar_member_date (c har *name)86 ar_member_date (const char *name) 83 87 { 84 88 char *arname; 85 int arname_used = 0;86 89 char *memname; 87 90 long int val; … … 100 103 arfile = lookup_file (arname); 101 104 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)); 106 106 107 107 if (arfile != 0) … … 109 109 } 110 110 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); 116 114 117 115 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 int124 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;130 116 } 131 117 … … 135 121 #ifdef VMS 136 122 int 137 ar_touch (c har *name)123 ar_touch (const char *name) 138 124 { 139 125 error (NILF, _("touch archive member is not available on VMS")); … … 142 128 #else 143 129 int 144 ar_touch (c har *name)130 ar_touch (const char *name) 145 131 { 146 132 char *arname, *memname; 147 int arname_used = 0; 148 register int val; 133 int val; 149 134 150 135 ar_parse_name (name, &arname, &memname); 151 136 152 137 /* 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. */ 154 139 { 155 140 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); 164 143 } 165 144 … … 188 167 } 189 168 190 if (!arname_used) 191 free (arname); 192 free (memname); 169 free (arname); 193 170 194 171 return val; … … 201 178 struct ar_glob_state 202 179 { 203 c har *arname;204 c har *pattern;180 const char *arname; 181 const char *pattern; 205 182 unsigned int size; 206 183 struct nameseq *chain; … … 212 189 213 190 static long int 214 ar_glob_match (int desc UNUSED, c har *mem, int truncated UNUSED,191 ar_glob_match (int desc UNUSED, const char *mem, int truncated UNUSED, 215 192 long int hdrpos UNUSED, long int datapos UNUSED, 216 193 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 219 198 if (fnmatch (state->pattern, mem, FNM_PATHNAME|FNM_PERIOD) == 0) 220 199 { 221 200 /* 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, ")")); 224 203 new->next = state->chain; 225 204 state->chain = new; … … 267 246 268 247 struct nameseq * 269 ar_glob (c har *arname,char *member_pattern, unsigned int size)248 ar_glob (const char *arname, const char *member_pattern, unsigned int size) 270 249 { 271 250 struct ar_glob_state state; 272 char **names;273 251 struct nameseq *n; 252 const char **names; 253 char *name; 274 254 unsigned int i; 275 255 … … 280 260 ar_glob_match will accumulate them in STATE.chain. */ 281 261 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; 286 267 state.pattern = member_pattern; 287 268 state.size = size; 288 269 state.chain = 0; 289 270 state.n = 0; 290 (void) ar_scan (arname, ar_glob_match, (long int)&state);271 ar_scan (arname, ar_glob_match, &state); 291 272 292 273 if (state.chain == 0) … … 294 275 295 276 /* 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 *)); 297 278 i = 0; 298 279 for (n = state.chain; n != 0; n = n->next) … … 300 281 301 282 /* Sort them alphabetically. */ 302 qsort ( (char *)names, i, sizeof (*names), alpha_compare);283 qsort (names, i, sizeof (*names), alpha_compare); 303 284 304 285 /* Put them back into the chain in the sorted order. */ -
trunk/src/gmakenew/arscan.c
r503 r903 26 26 27 27 #ifndef NO_ARCHIVES 28 29 28 30 29 #ifdef VMS … … 136 135 137 136 long int 138 ar_scan (c har *archive, long int (*function) PARAMS ((void)), long intarg)137 ar_scan (const char *archive, ar_member_func_t function, const void *arg) 139 138 { 140 139 char *p; … … 304 303 305 304 long int 306 ar_scan (c har *archive, long int (*function)(), long intarg)305 ar_scan (const char *archive, ar_member_func_t function, const void *arg) 307 306 { 308 307 #ifdef AIAMAG … … 316 315 #endif 317 316 char *namemap = 0; 318 registerint desc = open (archive, O_RDONLY, 0);317 int desc = open (archive, O_RDONLY, 0); 319 318 if (desc < 0) 320 319 return -1; … … 323 322 char buf[SARMAG]; 324 323 register int nread = read (desc, buf, SARMAG); 325 if (nread != SARMAG || bcmp (buf, ARMAG, SARMAG))324 if (nread != SARMAG || memcmp (buf, ARMAG, SARMAG)) 326 325 { 327 326 (void) close (desc); … … 332 331 #ifdef AIAMAG 333 332 { 334 register int nread = read (desc, (char *)&fl_header, FL_HSZ);333 register int nread = read (desc, &fl_header, FL_HSZ); 335 334 336 335 if (nread != FL_HSZ) … … 342 341 /* If this is a "big" archive, then set the flag and 343 342 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)) 345 344 { 346 345 big_archive = 1; … … 354 353 355 354 /* 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); 357 356 if (nread != FL_HSZ_BIG) 358 357 { … … 364 363 #endif 365 364 /* 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)) 367 366 { 368 367 (void) close (desc); … … 458 457 if (big_archive) 459 458 { 460 nread = read (desc, (char *)&member_header_big,459 nread = read (desc, &member_header_big, 461 460 AR_MEMHDR_SZ(member_header_big) ); 462 461 … … 490 489 #endif 491 490 { 492 nread = read (desc, (char *)&member_header,491 nread = read (desc, &member_header, 493 492 AR_MEMHDR_SZ(member_header) ); 494 493 … … 528 527 529 528 #else /* Not AIAMAG. */ 530 nread = read (desc, (char *)&member_header, AR_HDR_SIZE);529 nread = read (desc, &member_header, AR_HDR_SIZE); 531 530 if (nread == 0) 532 531 /* No data left means end of file; that is OK. */ … … 537 536 || ( 538 537 # ifdef ARFMAG 539 bcmp (member_header.ar_fmag, ARFMAG, 2)538 memcmp (member_header.ar_fmag, ARFMAG, 2) 540 539 # else 541 540 1 … … 543 542 && 544 543 # ifdef ARFZMAG 545 bcmp (member_header.ar_fmag, ARFZMAG, 2)544 memcmp (member_header.ar_fmag, ARFZMAG, 2) 546 545 # else 547 546 1 … … 556 555 557 556 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); 559 558 { 560 559 register char *p = name + sizeof member_header.ar_name; … … 596 595 int namesize = atoi (name + 3); 597 596 598 name = (char *)alloca (namesize + 1);597 name = alloca (namesize + 1); 599 598 nread = read (desc, name, namesize); 600 599 if (nread != namesize) … … 667 666 char *limit; 668 667 669 namemap = (char *)alloca (eltsize);668 namemap = alloca (eltsize); 670 669 nread = read (desc, namemap, eltsize); 671 670 if (nread != eltsize) … … 710 709 711 710 int 712 ar_name_equal (c har *name,char *mem, int truncated)711 ar_name_equal (const char *name, const char *mem, int truncated) 713 712 { 714 c har *p;713 const char *p; 715 714 716 715 p = strrchr (name, '/'); … … 742 741 /* ARGSUSED */ 743 742 static long int 744 ar_member_pos (int desc UNUSED, c har *mem, int truncated,743 ar_member_pos (int desc UNUSED, const char *mem, int truncated, 745 744 long int hdrpos, long int datapos UNUSED, long int size UNUSED, 746 745 long int date UNUSED, int uid UNUSED, int gid UNUSED, 747 int mode UNUSED, c har*name)746 int mode UNUSED, const void *name) 748 747 { 749 748 if (!ar_name_equal (name, mem, truncated)) … … 760 759 761 760 int 762 ar_member_touch (c har *arname,char *memname)761 ar_member_touch (const char *arname, const char *memname) 763 762 { 764 long int pos = ar_scan (arname, ar_member_pos, (long int)memname);763 long int pos = ar_scan (arname, ar_member_pos, memname); 765 764 int fd; 766 765 struct ar_hdr ar_hdr; … … 780 779 if (lseek (fd, pos, 0) < 0) 781 780 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)) 783 782 goto lose; 784 783 /* Write back the header, thus touching the archive file. */ 785 784 if (lseek (fd, pos, 0) < 0) 786 785 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)) 788 787 goto lose; 789 788 /* The file's mtime is the time we we want. */ … … 805 804 if (lseek (fd, pos, 0) < 0) 806 805 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)) 808 807 goto lose; 809 808 close (fd); … … 822 821 823 822 long int 824 describe_member (int desc, c har *name, int truncated,823 describe_member (int desc, const char *name, int truncated, 825 824 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) 827 826 { 828 827 extern char *ctime (); … … 840 839 main (int argc, char **argv) 841 840 { 842 ar_scan (argv[1], describe_member );841 ar_scan (argv[1], describe_member, NULL); 843 842 return 0; 844 843 } -
trunk/src/gmakenew/commands.c
r778 r903 34 34 #endif 35 35 36 extern int remote_kill PARAMS ((int id, int sig));36 int remote_kill (int id, int sig); 37 37 38 38 #ifndef HAVE_UNISTD_H 39 externint getpid ();39 int getpid (); 40 40 #endif 41 41 … … 46 46 set_file_variables (struct file *file) 47 47 { 48 struct dep *d;49 c har *at, *percent, *star, *less;48 const struct dep *d; 49 const char *at, *percent, *star, *less; 50 50 51 51 #ifndef NO_ARCHIVES … … 56 56 { 57 57 unsigned int len; 58 const char *cp; 58 59 char *p; 59 60 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; 68 71 } 69 72 else … … 80 83 any suffix in the .SUFFIXES list stripped off for 81 84 explicit rules. We store this in the `stem' member. */ 82 register struct dep *d; 83 char *name; 85 const char *name; 84 86 unsigned int len; 85 87 … … 97 99 } 98 100 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) 100 102 { 101 103 unsigned int slen = strlen (dep_name (d)); 102 104 if (len > slen && strneq (dep_name (d), name + (len - slen), slen)) 103 105 { 104 file->stem = s avestring(name, len - slen);106 file->stem = strcache_add_len (name, len - slen); 105 107 break; 106 108 } … … 139 141 { 140 142 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; 142 144 143 145 unsigned int qmark_len, plus_len, bar_len; … … 166 168 if (! d->ignore_mtime) 167 169 { 168 c har *c = dep_name (d);170 const char *c = dep_name (d); 169 171 170 172 #ifndef NO_ARCHIVES … … 178 180 len = strlen (c); 179 181 180 bcopy (c, cp, len);182 memcpy (cp, c, len); 181 183 cp += len; 182 184 *cp++ = FILE_LIST_SEPARATOR; … … 217 219 for (d = file->deps; d != 0; d = d->next) 218 220 { 219 c har *c = dep_name (d);221 const char *c = dep_name (d); 220 222 221 223 #ifndef NO_ARCHIVES … … 231 233 if (d->ignore_mtime) 232 234 { 233 bcopy (c, bp, len);235 memcpy (bp, c, len); 234 236 bp += len; 235 237 *bp++ = FILE_LIST_SEPARATOR; … … 237 239 else 238 240 { 239 bcopy (c, cp, len);241 memcpy (cp, c, len); 240 242 cp += len; 241 243 *cp++ = FILE_LIST_SEPARATOR; 242 244 if (d->changed) 243 245 { 244 bcopy (c, qp, len);246 memcpy (qp, c, len); 245 247 qp += len; 246 248 *qp++ = FILE_LIST_SEPARATOR; … … 271 273 chop_commands (struct commands *cmds) 272 274 { 273 registerchar *p;275 const char *p; 274 276 unsigned int nlines, idx; 275 277 char **lines; … … 286 288 287 289 nlines = 5; 288 lines = (char **)xmalloc (5 * sizeof (char *));290 lines = xmalloc (5 * sizeof (char *)); 289 291 idx = 0; 290 292 p = cmds->commands; 291 293 while (*p != '\0') 292 294 { 293 c har *end = p;295 const char *end = p; 294 296 find_end:; 295 297 end = strchr (end, '\n'); … … 299 301 { 300 302 int backslash = 1; 301 registerchar *b;303 const char *b; 302 304 for (b = end - 2; b >= p && *b == '\\'; --b) 303 305 backslash = !backslash; … … 312 314 { 313 315 nlines += 2; 314 lines = (char **) xrealloc ((char *) lines, 315 nlines * sizeof (char *)); 316 lines = xrealloc (lines, nlines * sizeof (char *)); 316 317 } 317 318 lines[idx++] = savestring (p, end - p); … … 324 325 { 325 326 nlines = idx; 326 lines = (char **) xrealloc ((char *) lines, 327 nlines * sizeof (char *)); 327 lines = xrealloc (lines, nlines * sizeof (char *)); 328 328 } 329 329 … … 332 332 333 333 cmds->any_recurse = 0; 334 cmds->lines_flags = (char *)xmalloc (nlines);334 cmds->lines_flags = xmalloc (nlines); 335 335 for (idx = 0; idx < nlines; ++idx) 336 336 { … … 382 382 execute_file_commands (struct file *file) 383 383 { 384 registerchar *p;384 const char *p; 385 385 386 386 /* Don't go through all the preparations if … … 474 474 if (sig == SIGTERM) 475 475 { 476 registerstruct child *c;476 struct child *c; 477 477 for (c = children; c != 0; c = c->next) 478 478 if (!c->remote) … … 492 492 ) 493 493 { 494 registerstruct child *c;494 struct child *c; 495 495 496 496 /* Remote children won't automatically get signals sent … … 546 546 547 547 static void 548 delete_target (struct file *file, c har *on_behalf_of)548 delete_target (struct file *file, const char *on_behalf_of) 549 549 { 550 550 struct stat st; … … 601 601 602 602 /* Delete the target file if it changed. */ 603 delete_target (child->file, (char *) 0);603 delete_target (child->file, NULL); 604 604 605 605 /* Also remove any non-precious targets listed in the `also_make' member. */ … … 614 614 615 615 void 616 print_commands ( struct commands *cmds)616 print_commands (const struct commands *cmds) 617 617 { 618 registerchar *s;618 const char *s; 619 619 620 620 fputs (_("# commands to execute"), stdout); … … 629 629 while (*s != '\0') 630 630 { 631 c har *end;631 const char *end; 632 632 633 633 while (isspace ((unsigned char)*s)) -
trunk/src/gmakenew/commands.h
r520 r903 43 43 #endif 44 44 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));45 void execute_file_commands (struct file *file); 46 void print_commands (const struct commands *cmds); 47 void delete_child_targets (struct child *child); 48 void chop_commands (struct commands *cmds); 49 void set_file_variables (struct file *file); -
trunk/src/gmakenew/config.h.W32.template
r902 r903 241 241 242 242 /* Define to 1 if you have the `strdup' function. */ 243 /* #define HAVE_STRDUP 1*/243 #define HAVE_STRDUP 1 /* bird */ 244 244 245 245 /* Define to 1 if you have the `strerror' function. */ -
trunk/src/gmakenew/config/dospaths.m4
r503 r903 23 23 [ 24 24 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__ 26 26 neither MSDOS nor Windows nor OS2 27 27 #endif -
trunk/src/gmakenew/configure.in
r503 r903 17 17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 18 19 AC_INIT([GNU make],[3.81 ],[[email protected]])19 AC_INIT([GNU make],[3.81.90],[[email protected]]) 20 20 21 21 AC_PREREQ(2.59) 22 AC_REVISION([[$Id: configure.in,v 1.14 2 2006/04/01 06:36:40psmith Exp $]])22 AC_REVISION([[$Id: configure.in,v 1.147 2007/05/09 02:01:53 psmith Exp $]]) 23 23 24 24 # Autoconf setup … … 45 45 AC_MINIX 46 46 47 # Needed for ansi2knr48 AM_C_PROTOTYPES49 50 47 # Enable gettext, in "external" mode. 51 48 … … 72 69 if test "$ac_cv_prog_cc_stdc" != no; then 73 70 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.]) 75 72 fi 76 73 … … 123 120 if test "$ac_cv_search_clock_gettime" != no; then 124 121 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.]) 126 123 fi 127 124 fi … … 147 144 if test "$ac_cv_func_gettimeofday" = yes; then 148 145 AC_DEFINE(HAVE_GETTIMEOFDAY, 1, 149 [Define if you have a standard gettimeofday function])150 fi 151 152 AC_CHECK_FUNCS( memcpy memmove strchrstrdup mkstemp mktemp fdopen \146 [Define to 1 if you have a standard gettimeofday function]) 147 fi 148 149 AC_CHECK_FUNCS( strdup mkstemp mktemp fdopen \ 153 150 bsd_signal dup2 getcwd realpath sigsetmask sigaction \ 154 151 getgroups seteuid setegid setlinebuf setreuid setregid \ … … 157 154 158 155 AC_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. 160 AC_CHECK_FUNCS(strcasecmp strcmpi stricmp) 159 161 160 162 # strcoll() is used by the GNU glob library … … 180 182 if test "$make_cv_nlist_struct" = yes; then 181 183 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.]) 183 185 fi 184 186 fi … … 195 197 196 198 # Check out the wait reality. 197 AC_CHECK_HEADERS(sys/wait.h )199 AC_CHECK_HEADERS(sys/wait.h,,,[[#include <sys/types.h>]]) 198 200 AC_CHECK_FUNCS(waitpid wait3) 199 201 AC_MSG_CHECKING(for union wait) … … 221 223 if test "$make_cv_union_wait" = yes; then 222 224 AC_DEFINE(HAVE_UNION_WAIT, 1, 223 [Define t hisif 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>.]) 224 226 fi 225 227 AC_MSG_RESULT($make_cv_union_wait) … … 229 231 if test "$PATH_SEPARATOR" = ';'; then 230 232 AC_DEFINE(HAVE_DOS_PATHS, 1, 231 [Define t hisif your system requires backslashes or drive specs in pathnames.])233 [Define to 1 if your system requires backslashes or drive specs in pathnames.]) 232 234 fi 233 235 … … 265 267 AC_ARG_ENABLE(case-insensitive-file-system, 266 268 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]) 270 273 271 274 # See if we can handle the job server feature, and if the user wants it. … … 290 293 if test "$make_cv_sa_restart" != no; then 291 294 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.]) 293 296 fi 294 297 … … 302 305 yes/yes/yes/yes/yes) 303 306 AC_DEFINE(MAKE_JOBSERVER, 1, 304 [Define t histo enable job server support in GNU make.]);;307 [Define to 1 to enable job server support in GNU make.]);; 305 308 esac 306 309 … … 310 313 yes/yes) 311 314 AC_DEFINE(MAKE_SYMLINKS, 1, 312 [Define t histo enable symbolic link timestamp checking.]);;315 [Define to 1 to enable symbolic link timestamp checking.]);; 313 316 esac 314 317 … … 337 340 case "$make_cv_sys_get_minus_G" in 338 341 yes) AC_DEFINE(SCCS_GET_MINUS_G, 1, 339 [Define t hisif the SCCS 'get' command understands the '-G<file>' option.]);;342 [Define to 1 if the SCCS 'get' command understands the '-G<file>' option.]);; 340 343 esac 341 344 fi … … 385 388 esac 386 389 390 AC_DEFINE_UNQUOTED(PATH_SEPARATOR_CHAR,'$PATH_SEPARATOR',[Define to the character that separates directories in PATH.]) 391 387 392 # Include the Maintainer's Makefile section, if it's here. 388 393 -
trunk/src/gmakenew/default.c
r503 r903 43 43 .w .ch .cweb .web .com .sh .elc .el"; 44 44 #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 \ 46 46 .mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo \ 47 47 .w .ch .web .sh .elc .el .obj .exe .dll .lib"; 48 48 #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 \ 50 50 .mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo \ 51 51 .w .ch .web .sh .elc .el"; … … 201 201 ".f", 202 202 "$(LINK.f) $^ $(LOADLIBES) $(LDLIBS) -o $@", 203 ".m", 204 "$(LINK.m) $^ $(LOADLIBES) $(LDLIBS) -o $@", 203 205 ".p", 204 206 "$(LINK.p) $^ $(LOADLIBES) $(LDLIBS) -o $@", … … 230 232 ".f.o", 231 233 "$(COMPILE.f) $(OUTPUT_OPTION) $<", 234 ".m.o", 235 "$(COMPILE.m) $(OUTPUT_OPTION) $<", 232 236 ".p.o", 233 237 "$(COMPILE.p) $(OUTPUT_OPTION) $<", … … 258 262 ".l.c", 259 263 "@$(RM) $@ \n $(LEX.l) $< > $@", 264 ".ym.m", 265 "$(YACC.m) $< \n mv -f y.tab.c $@", 266 ".lm.m", 267 "@$(RM) $@ \n $(LEX.m) $< > $@", 260 268 261 269 ".F.f", … … 264 272 "$(PREPROCESS.r) $(OUTPUT_OPTION) $<", 265 273 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? */ 269 276 ".l.r", 270 277 "$(LEX.l) $< > $@ \n mv -f lex.yy.r $@", … … 311 318 }; 312 319 313 static c har *default_variables[] =320 static const char *default_variables[] = 314 321 { 315 322 #ifndef CONFIG_NO_DEFAULT_VARIABLES … … 408 415 "CXX", "gcc", 409 416 # endif /* __MSDOS__ */ 417 "OBJC", "gcc", 410 418 #else 411 419 "CC", "cc", 412 420 "CXX", "g++", 421 "OBJC", "cc", 413 422 #endif 414 423 … … 478 487 "COMPILE.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c", 479 488 "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)", 480 491 "COMPILE.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c", 481 492 "COMPILE.C", "$(COMPILE.cc)", … … 486 497 "YACC.y", "$(YACC) $(YFLAGS)", 487 498 "LEX.l", "$(LEX) $(LFLAGS) -t", 499 "YACC.m", "$(YACC) $(YFLAGS)", 500 "LEX.m", "$(LEX) $(LFLAGS) -t", 488 501 "COMPILE.f", "$(FC) $(FFLAGS) $(TARGET_ARCH) -c", 489 502 "LINK.f", "$(FC) $(FFLAGS) $(LDFLAGS) $(TARGET_ARCH)", … … 534 547 set_default_suffixes (void) 535 548 { 536 suffix_file = enter_file ( ".SUFFIXES");549 suffix_file = enter_file (strcache_add (".SUFFIXES")); 537 550 538 551 if (no_builtin_rules_flag) 539 (void)define_variable ("SUFFIXES", 8, "", o_default, 0);552 define_variable ("SUFFIXES", 8, "", o_default, 0); 540 553 else 541 554 { … … 544 557 multi_glob (parse_file_seq (&p, '\0', sizeof (struct dep), 1), 545 558 sizeof (struct dep)); 546 (void)define_variable ("SUFFIXES", 8, default_suffixes, o_default, 0);559 define_variable ("SUFFIXES", 8, default_suffixes, o_default, 0); 547 560 } 548 561 } … … 550 563 /* Enter the default suffix rules as file rules. This used to be done in 551 564 install_default_implicit_rules, but that loses because we want the 552 suffix rules installed before reading makefiles, and the epattern rules565 suffix rules installed before reading makefiles, and the pattern rules 553 566 installed after. */ 554 567 … … 556 569 install_default_suffix_rules (void) 557 570 { 558 registerchar **s;571 char **s; 559 572 560 573 if (no_builtin_rules_flag) 561 574 return; 562 575 563 for (s = default_suffix_rules; *s != 0; s += 2)576 for (s = default_suffix_rules; *s != 0; s += 2) 564 577 { 565 register struct file *f = enter_file (s[0]);578 struct file *f = enter_file (strcache_add (s[0])); 566 579 /* Don't clobber cmds given in a makefile if there were any. */ 567 580 if (f->cmds == 0) 568 581 { 569 f->cmds = (struct commands *)xmalloc (sizeof (struct commands));582 f->cmds = xmalloc (sizeof (struct commands)); 570 583 f->cmds->fileinfo.filenm = 0; 571 584 f->cmds->commands = s[1]; … … 581 594 install_default_implicit_rules (void) 582 595 { 583 registerstruct pspec *p;596 struct pspec *p; 584 597 585 598 if (no_builtin_rules_flag) … … 596 609 define_default_variables (void) 597 610 { 598 registerchar **s;611 const char **s; 599 612 600 613 if (no_builtin_variables_flag) … … 602 615 603 616 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); 605 618 } -
trunk/src/gmakenew/dep.h
r530 r903 37 37 { 38 38 struct dep *next; 39 c har *name;40 c har *stem;39 const char *name; 40 const char *stem; 41 41 struct file *file; 42 42 unsigned int changed : 8; … … 52 52 { 53 53 struct nameseq *next; 54 c har *name;54 const char *name; 55 55 }; 56 56 57 57 58 extern struct nameseq *multi_glob PARAMS ((struct nameseq *chain, unsigned int size));58 struct nameseq *multi_glob (struct nameseq *chain, unsigned int size); 59 59 #ifdef VMS 60 externstruct nameseq *parse_file_seq ();60 struct nameseq *parse_file_seq (); 61 61 #else 62 extern struct nameseq *parse_file_seq PARAMS ((char **stringp, int stopchar, unsigned int size, int strip));62 struct nameseq *parse_file_seq (char **stringp, int stopchar, unsigned int size, int strip); 63 63 #endif 64 extern char *tilde_expand PARAMS ((char *name));64 char *tilde_expand (const char *name); 65 65 66 66 #ifndef NO_ARCHIVES 67 extern struct nameseq *ar_glob PARAMS ((char *arname, char *member_pattern, unsigned int size));67 struct nameseq *ar_glob (const char *arname, const char *member_pattern, unsigned int size); 68 68 #endif 69 69 70 #ifndef iAPX28671 70 #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 72 struct dep *alloc_dep (void); 73 void free_dep (struct dep *d); 74 struct dep *copy_dep_chain (const struct dep *d); 75 void free_dep_chain (struct dep *d); 76 void free_ns_chain (struct nameseq *n); 77 struct dep *read_all_makefiles (const char **makefiles); 78 int eval_buffer (char *buffer); 79 int update_goal_chain (struct dep *goals); 80 void uniquize_deps (struct dep *); 81 82 #ifdef CONFIG_WITH_INCLUDEDEP 83 void eval_include_dep (const char *name, struct floc *f); 75 84 #endif 76 85 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_INCLUDEDEP85 extern void eval_include_dep PARAMS ((char *name, struct floc *f));86 #endif87 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 24 24 # define NAMLEN(dirent) strlen((dirent)->d_name) 25 25 # ifdef VMS 26 extern char *vmsify PARAMS ((char *name, int type));26 char *vmsify (char *name, int type); 27 27 # endif 28 28 #else … … 69 69 #endif 70 70 71 static c har *72 dosify (c har *filename)71 static const char * 72 dosify (const char *filename) 73 73 { 74 74 static char dos_filename[14]; … … 119 119 120 120 #ifdef HAVE_CASE_INSENSITIVE_FS 121 static c har *122 downcase (c har *filename)121 static const char * 122 downcase (const char *filename) 123 123 { 124 124 static PATH_VAR (new_filename); … … 132 132 133 133 /* 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 } 139 139 140 140 *df = 0; … … 217 217 dev_t dev; /* Device and inode numbers of this dir. */ 218 218 #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. */ 227 224 char *path_key; 228 225 int ctime; 229 226 int mtime; /* controls check for stale directory cache */ 230 227 int fs_flags; /* FS_FAT, FS_NTFS, ... */ 231 # define FS_FAT 0x1232 # define FS_NTFS 0x2233 # define FS_UNKNOWN 0x4234 #else 235 # ifdef VMS228 # define FS_FAT 0x1 229 # define FS_NTFS 0x2 230 # define FS_UNKNOWN 0x4 231 #else 232 # ifdef VMS 236 233 ino_t ino[3]; 237 # else234 # else 238 235 ino_t ino; 239 # endif236 # endif 240 237 #endif /* WINDOWS32 */ 241 238 struct hash_table dirfiles; /* Files in this directory. */ … … 246 243 directory_contents_hash_1 (const void *key_0) 247 244 { 248 struct directory_contents const *key = (struct directory_contents const *)key_0;245 const struct directory_contents *key = key_0; 249 246 unsigned long hash; 250 247 … … 269 266 directory_contents_hash_2 (const void *key_0) 270 267 { 271 struct directory_contents const *key = (struct directory_contents const *)key_0;268 const struct directory_contents *key = key_0; 272 269 unsigned long hash; 273 270 … … 304 301 directory_contents_hash_cmp (const void *xv, const void *yv) 305 302 { 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; 308 305 int result; 309 306 … … 341 338 struct directory 342 339 { 343 c har *name; /* Name of the directory. */340 const char *name; /* Name of the directory. */ 344 341 345 342 /* The directory's contents. This data may be shared by several … … 352 349 directory_hash_1 (const void *key) 353 350 { 354 return_ISTRING_HASH_1 ((( struct directory const*) key)->name);351 return_ISTRING_HASH_1 (((const struct directory *) key)->name); 355 352 } 356 353 … … 358 355 directory_hash_2 (const void *key) 359 356 { 360 return_ISTRING_HASH_2 ((( struct directory const*) key)->name);357 return_ISTRING_HASH_2 (((const struct directory *) key)->name); 361 358 } 362 359 … … 364 361 directory_hash_cmp (const void *x, const void *y) 365 362 { 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); 368 365 } 369 366 … … 382 379 struct dirfile 383 380 { 384 c har *name;/* Name of the file. */381 const char *name; /* Name of the file. */ 385 382 short length; 386 383 short impossible; /* This file is impossible. */ … … 402 399 dirfile_hash_cmp (const void *xv, const void *yv) 403 400 { 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; 406 403 int result = x->length - y->length; 407 404 if (result) … … 415 412 416 413 417 static int dir_contents_file_exists_p PARAMS ((struct directory_contents *dir, char *filename)); 418 static struct directory *find_directory PARAMS ((char *name)); 414 static int dir_contents_file_exists_p (struct directory_contents *dir, 415 const char *filename); 416 static struct directory *find_directory (const char *name); 419 417 420 418 /* Find the directory named NAME and return its `struct directory'. */ 421 419 422 420 static struct directory * 423 find_directory (c har *name)424 { 425 registerchar *p;426 registerstruct directory *dir;427 registerstruct directory **dir_slot;421 find_directory (const char *name) 422 { 423 const char *p; 424 struct directory *dir; 425 struct directory **dir_slot; 428 426 struct directory dir_key; 429 427 int r; … … 454 452 455 453 p = name + strlen (name); 456 dir = (struct directory *)xmalloc (sizeof (struct directory));457 dir->name = s avestring(name, p - name);454 dir = xmalloc (sizeof (struct directory)); 455 dir->name = strcache_add_len (name, p - name); 458 456 hash_insert_at (&directories, dir, dir_slot); 459 457 /* The directory is not in the name hash table. … … 464 462 directories if they end in '\'. */ 465 463 if (p[-1] == '\\') 466 p[-1] = '\0';464 ((char *)p)[-1] = '\0'; 467 465 #endif 468 466 … … 477 475 truncating the value! */ 478 476 if (p[-1] == '\0') 479 p[-1] = '\\';477 ((char *)p)[-1] = '\\'; 480 478 #endif 481 479 … … 553 551 ENULLLOOP (dc->dirstream, opendir (name)); 554 552 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. */ 557 555 dc->dirfiles.ht_vec = 0; 558 556 else … … 565 563 /* We have too many directories open already. 566 564 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); 568 566 } 569 567 } … … 582 580 583 581 static int 584 dir_contents_file_exists_p (struct directory_contents *dir, char *filename) 582 dir_contents_file_exists_p (struct directory_contents *dir, 583 const char *filename) 585 584 { 586 585 unsigned int hash; … … 593 592 594 593 if (dir == 0 || dir->dirfiles.ht_vec == 0) 595 {596 594 /* The directory could not be stat'd or opened. */ 597 598 } 595 return 0; 596 599 597 #ifdef __MSDOS__ 600 598 filename = dosify (filename); … … 626 624 dirfile_key.name = filename; 627 625 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); 629 627 if (df) 630 { 631 return !df->impossible; 632 } 628 return !df->impossible; 633 629 } 634 630 … … 651 647 rehash = 1; 652 648 } 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) 654 650 { 655 651 /* reset date stamp to show most recent re-process. */ … … 663 659 664 660 /* make sure directory can still be opened; if not return. */ 665 dir->dirstream = opendir (dir->path_key);661 dir->dirstream = opendir (dir->path_key); 666 662 if (!dir->dirstream) 667 663 return 0; … … 682 678 ENULLLOOP (d, readdir (dir->dirstream)); 683 679 if (d == 0) 684 break; 680 { 681 if (errno) 682 fatal (NILF, "INTERNAL: readdir: %s\n", strerror (errno)); 683 break; 684 } 685 685 686 686 #if defined(VMS) && defined(HAVE_DIRENT_H) … … 707 707 #endif 708 708 { 709 df = (struct dirfile *)xmalloc (sizeof (struct dirfile));710 df->name = s avestring(d->d_name, len);709 df = xmalloc (sizeof (struct dirfile)); 710 df->name = strcache_add_len (d->d_name, len); 711 711 df->length = len; 712 712 df->impossible = 0; … … 715 715 /* Check if the name matches the one we're searching for. */ 716 716 if (filename != 0 && strieq (d->d_name, filename)) 717 { 718 return 1; 719 } 717 return 1; 720 718 } 721 719 … … 736 734 737 735 int 738 dir_file_exists_p (c har *dirname,char *filename)736 dir_file_exists_p (const char *dirname, const char *filename) 739 737 { 740 738 return dir_contents_file_exists_p (find_directory (dirname)->contents, … … 746 744 747 745 int 748 file_exists_p (c har *name)749 { 750 c har *dirend;751 c har *dirname;752 c har *slash;746 file_exists_p (const char *name) 747 { 748 const char *dirend; 749 const char *dirname; 750 const char *slash; 753 751 754 752 #ifndef NO_ARCHIVES … … 761 759 if (dirend == 0) 762 760 dirend = strrchr (name, ':'); 763 if (dirend == (char *)0)761 if (dirend == 0) 764 762 return dir_file_exists_p ("[]", name); 765 763 #else /* !VMS */ … … 768 766 /* Forward and backslashes might be mixed. We need the rightmost one. */ 769 767 { 770 c har *bslash = strrchr(name, '\\');768 const char *bslash = strrchr(name, '\\'); 771 769 if (!dirend || bslash > dirend) 772 770 dirend = bslash; … … 789 787 else 790 788 { 789 char *p; 791 790 #ifdef HAVE_DOS_PATHS 792 791 /* d:/ and d: are *very* different... */ … … 795 794 dirend++; 796 795 #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; 800 800 } 801 801 return dir_file_exists_p (dirname, slash + 1); … … 808 808 809 809 void 810 file_impossible (c har *filename)811 { 812 c har *dirend;813 registerchar *p = filename;814 registerstruct directory *dir;815 registerstruct dirfile *new;810 file_impossible (const char *filename) 811 { 812 const char *dirend; 813 const char *p = filename; 814 struct directory *dir; 815 struct dirfile *new; 816 816 817 817 #ifdef VMS … … 827 827 /* Forward and backslashes might be mixed. We need the rightmost one. */ 828 828 { 829 c har *bslash = strrchr(p, '\\');829 const char *bslash = strrchr(p, '\\'); 830 830 if (!dirend || bslash > dirend) 831 831 dirend = bslash; … … 844 844 else 845 845 { 846 c har *dirname;847 c har *slash = dirend;846 const char *dirname; 847 const char *slash = dirend; 848 848 if (dirend == p) 849 849 dirname = "/"; 850 850 else 851 851 { 852 char *cp; 852 853 #ifdef HAVE_DOS_PATHS 853 854 /* d:/ and d: are *very* different... */ … … 856 857 dirend++; 857 858 #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; 861 863 } 862 864 dir = find_directory (dirname); … … 868 870 /* The directory could not be stat'd. We allocate a contents 869 871 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)); 873 874 } 874 875 … … 881 882 /* Make a new entry and put it in the table. */ 882 883 883 new = (struct dirfile *) xmalloc (sizeof (struct dirfile)); 884 new->name = xstrdup (filename); 884 new = xmalloc (sizeof (struct dirfile)); 885 885 new->length = strlen (filename); 886 new->name = strcache_add_len (filename, new->length); 886 887 new->impossible = 1; 887 888 hash_insert (&dir->contents->dirfiles, new); … … 892 893 893 894 int 894 file_impossible_p (c har *filename)895 { 896 c har *dirend;897 registerchar *p = filename;898 registerstruct directory_contents *dir;899 registerstruct dirfile *dirfile;895 file_impossible_p (const char *filename) 896 { 897 const char *dirend; 898 const char *p = filename; 899 struct directory_contents *dir; 900 struct dirfile *dirfile; 900 901 struct dirfile dirfile_key; 901 902 … … 909 910 /* Forward and backslashes might be mixed. We need the rightmost one. */ 910 911 { 911 c har *bslash = strrchr(filename, '\\');912 const char *bslash = strrchr(filename, '\\'); 912 913 if (!dirend || bslash > dirend) 913 914 dirend = bslash; … … 926 927 else 927 928 { 928 c har *dirname;929 c har *slash = dirend;929 const char *dirname; 930 const char *slash = dirend; 930 931 if (dirend == filename) 931 932 dirname = "/"; 932 933 else 933 934 { 935 char *cp; 934 936 #ifdef HAVE_DOS_PATHS 935 937 /* d:/ and d: are *very* different... */ … … 938 940 dirend++; 939 941 #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; 943 946 } 944 947 dir = find_directory (dirname)->contents; … … 962 965 dirfile_key.name = filename; 963 966 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); 965 968 if (dirfile) 966 969 return dirfile->impossible; … … 973 976 directory hash table that matches DIR. */ 974 977 975 c har *976 dir_name (c har *dir)978 const char * 979 dir_name (const char *dir) 977 980 { 978 981 return find_directory (dir)->name; … … 985 988 print_dir_data_base (void) 986 989 { 987 registerunsigned int files;988 registerunsigned int impossible;989 registerstruct directory **dir_slot;990 registerstruct directory **dir_end;990 unsigned int files; 991 unsigned int impossible; 992 struct directory **dir_slot; 993 struct directory **dir_end; 991 994 992 995 puts (_("\n# Directories\n")); … … 998 1001 for ( ; dir_slot < dir_end; dir_slot++) 999 1002 { 1000 registerstruct directory *dir = *dir_slot;1003 struct directory *dir = *dir_slot; 1001 1004 if (! HASH_VACANT (dir)) 1002 1005 { … … 1023 1026 else 1024 1027 { 1025 registerunsigned int f = 0;1026 registerunsigned int im = 0;1027 registerstruct dirfile **files_slot;1028 registerstruct dirfile **files_end;1028 unsigned int f = 0; 1029 unsigned int im = 0; 1030 struct dirfile **files_slot; 1031 struct dirfile **files_end; 1029 1032 1030 1033 files_slot = (struct dirfile **) dir->contents->dirfiles.ht_vec; … … 1032 1035 for ( ; files_slot < files_end; files_slot++) 1033 1036 { 1034 registerstruct dirfile *df = *files_slot;1037 struct dirfile *df = *files_slot; 1035 1038 if (! HASH_VACANT (df)) 1036 1039 { … … 1103 1106 1104 1107 /* Forward declarations. */ 1105 static __ptr_t open_dirstream PARAMS ((const char *));1106 static struct dirent *read_dirstream PARAMS ((__ptr_t));1108 static __ptr_t open_dirstream (const char *); 1109 static struct dirent *read_dirstream (__ptr_t); 1107 1110 1108 1111 static __ptr_t … … 1110 1113 { 1111 1114 struct dirstream *new; 1112 struct directory *dir = find_directory ( (char *)directory);1115 struct directory *dir = find_directory (directory); 1113 1116 1114 1117 if (dir->contents == 0 || dir->contents->dirfiles.ht_vec == 0) … … 1120 1123 in being lazy, since glob will want to see every file anyway. */ 1121 1124 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)); 1125 1128 new->contents = dir->contents; 1126 1129 new->dirfile_slot = (struct dirfile **) new->contents->dirfiles.ht_vec; … … 1132 1135 read_dirstream (__ptr_t stream) 1133 1136 { 1137 static char *buf; 1138 static unsigned int bufsz; 1139 1134 1140 struct dirstream *const ds = (struct dirstream *) stream; 1135 1141 struct directory_contents *dc = ds->contents; 1136 1142 struct dirfile **dirfile_end = (struct dirfile **) dc->dirfiles.ht_vec + dc->dirfiles.ht_size; 1137 static char *buf;1138 static unsigned int bufsz;1139 1143 1140 1144 while (ds->dirfile_slot < dirfile_end) 1141 1145 { 1142 registerstruct dirfile *df = *ds->dirfile_slot++;1146 struct dirfile *df = *ds->dirfile_slot++; 1143 1147 if (! HASH_VACANT (df) && !df->impossible) 1144 1148 { 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. */ 1147 1150 struct dirent *d; 1148 1151 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) 1150 1154 { 1151 if (buf != 0)1152 free (buf);1153 1155 bufsz *= 2; 1154 if (s izeof *d - sizeof d->d_name + len> bufsz)1155 bufsz = s izeof *d - sizeof d->d_name + len;1156 buf = x malloc (bufsz);1156 if (sz > bufsz) 1157 bufsz = sz; 1158 buf = xrealloc (buf, bufsz); 1157 1159 } 1158 1160 d = (struct dirent *) buf; … … 1191 1193 #ifndef stat 1192 1194 # ifndef VMS 1193 extern int stat PARAMS ((const char *path, struct stat *sbuf));1195 int stat (const char *path, struct stat *sbuf); 1194 1196 # endif 1195 1197 # define local_stat stat … … 1208 1210 dir_setup_glob (glob_t *gl) 1209 1211 { 1210 /* Bogus sunos4 compiler complains (!) about & before functions. */1211 1212 gl->gl_opendir = open_dirstream; 1212 1213 gl->gl_readdir = read_dirstream; … … 1226 1227 directory_hash_1, directory_hash_2, directory_hash_cmp); 1227 1228 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 5 5 @include version.texi 6 6 @set EDITION 0.70 7 @set RCSID $Id: make.texi,v 1.4 5 2006/04/01 06:36:40psmith Exp $7 @set RCSID $Id: make.texi,v 1.47 2007/05/11 20:57:21 psmith Exp $ 8 8 9 9 @settitle GNU @code{make} … … 51 51 52 52 53 @dircategory GNU Packages53 @dircategory Software development 54 54 @direntry 55 55 * Make: (make). Remake files automatically. … … 1010 1010 specially in certain situations. 1011 1011 1012 You cannot use comments within variable references or function calls: 1013 any instance of @code{#} will be treated literally (rather than as the 1014 start of a comment) inside a variable reference or function call. 1015 1012 1016 Within a command script (if the line begins with a TAB character) the 1013 1017 entire line is passed to the shell, just as with any other line that … … 1252 1256 @end example 1253 1257 1254 @xref{Text Functions}, for more information on the @code{ word} and1255 @code{words} functions used above. @xref{Flavors, The Two Flavors of 1256 Variables}, for more information on simply-expanded (@code{:=}) 1257 variabledefinitions.1258 @xref{Text Functions}, for more information on the @code{lastword} 1259 function used above. @xref{Flavors, The Two Flavors of Variables}, 1260 for more information on simply-expanded (@code{:=}) variable 1261 definitions. 1258 1262 1259 1263 @node Special Variables, Remaking Makefiles, MAKEFILE_LIST Variable, Makefiles … … 1745 1749 @code{foo.1 bar.1} respectively. In the third they will have values 1746 1750 @code{foo.1}, @code{foo.1 bar.1 foo.2 bar.2}, and @code{foo.1 bar.1 1747 foo.2 bar.2 } respectively.1751 foo.2 bar.2 foo.1 foo.1 bar.1 foo.1 bar.1} respectively. 1748 1752 1749 1753 Rules undergo secondary expansion in makefile order, except that … … 1938 1942 Variables, ,How to Use Variables}). If you have enabled secondary 1939 1943 expansion (@pxref{Secondary Expansion}) and you want a literal dollar 1940 sign in the prerequisites lis e, you must actually write @emph{four}1944 sign in the prerequisites list, you must actually write @emph{four} 1941 1945 dollar signs (@samp{$$$$}). 1942 1946 … … 2001 2005 The normal prerequisites section may of course be empty. Also, you 2002 2006 may 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). 2007 they are appended appropriately (normal prerequisites are appended to 2008 the list of normal prerequisites; order-only prerequisites are 2009 appended to the list of order-only prerequisites). Note that if you 2010 declare the same file to be both a normal and an order-only 2011 prerequisite, the normal prerequisite takes precedence (since they 2012 have a strict superset of the behavior of an order-only prerequisite). 2013 2014 Consider an example where your targets are to be placed in a separate 2015 directory, and that directory might not exist before @code{make} is 2016 run. In this situation, you want the directory to be created before 2017 any targets are placed into it but, because the timestamps on 2018 directories change whenever a file is added, removed, or renamed, we 2019 certainly don't want to rebuild all the targets whenever the 2020 directory's timestamp changes. One way to manage this is with 2021 order-only prerequisites: make the directory an order-only 2022 prerequisite on all the targets: 2023 2024 @example 2025 OBJDIR := objdir 2026 OBJS := $(addprefix $(OBJDIR)/,foo.o bar.o baz.o) 2027 2028 $(OBJDIR)/%.o : %.c 2029 $(COMPILE.c) $(OUTPUT_OPTION) $< 2030 2031 all: $(OBJS) 2032 2033 $(OBJS): | $(OBJDIR) 2034 2035 $(OBJDIR): 2036 mkdir $(OBJDIR) 2037 @end example 2038 2039 Now the rule to create the @file{objdir} directory will be run, if 2040 needed, before any @samp{.o} is built, but no @samp{.o} will be built 2041 because the @file{objdir} directory timestamp changed. 2007 2042 2008 2043 @node Wildcards, Directory Search, Prerequisite Types, Rules … … 2906 2941 @xref{Secondary Expansion, ,Secondary Expansion}. 2907 2942 2908 The prerequisites of the special target @code{.SUFFIXES} are the list2909 of suffixes to be used in checking for suffix rules.2910 @xref{Suffix Rules, , Old-Fashioned Suffix Rules}.2911 2912 2943 @findex .DELETE_ON_ERROR 2913 2944 @item .DELETE_ON_ERROR … … 2996 3027 @cindex parallel execution, overriding 2997 3028 2998 If @code{.NOTPARALLEL} is mentioned as a target, then this invocation of2999 @code{make} will be run serially, even if the @samp{-j} option is3000 given. Any recursively invoked @code{make} command will still be run in3001 parallel (unless its makefile contains this target). Any prerequisites 3002 on this target are ignored.3029 If @code{.NOTPARALLEL} is mentioned as a target, then this invocation 3030 of @code{make} will be run serially, even if the @samp{-j} option is 3031 given. Any recursively invoked @code{make} command will still run 3032 commands in parallel (unless its makefile also contains this target). 3033 Any prerequisites on this target are ignored. 3003 3034 @end table 3004 3035 … … 3094 3125 if the file's name begins with a dot, no error message is printed. 3095 3126 This odd behavior is only for compatibility with other implementations 3096 of @code{make} ...you should avoid using it). Occasionally it is3127 of @code{make}@dots{} you should avoid using it). Occasionally it is 3097 3128 useful to have the same target invoke multiple commands which are 3098 3129 defined in different parts of your makefile; you can use … … 3653 3684 3654 3685 @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. 3686 Notice how the backslash/newline pair was removed inside the string 3687 quoted with double quotes (@code{"@dots{}"}), but not from the string 3688 quoted with single quotes (@code{'@dots{}'}). This is the way the 3689 default shell (@file{/bin/sh}) handles backslash/newline pairs. If 3690 you specify a different shell in your makefiles it may treat them 3691 differently. 3660 3692 3661 3693 Sometimes you want to split a long line inside of single quotes, but … … 3943 3975 for it to finish before executing the next. However, the @samp{-j} or 3944 3976 @samp{--jobs} option tells @code{make} to execute many commands 3945 simultaneously.@refill 3977 simultaneously. You can inhibit parallelism in a particular makefile 3978 with the @code{.NOTPARALLEL} pseudo-target (@pxref{Special 3979 Targets,Special Built-in Target Names}).@refill 3946 3980 3947 3981 On MS-DOS, the @samp{-j} option has no effect, since that system doesn't … … 8353 8387 the special target @code{.SUFFIXES}). The default suffix list is: 8354 8388 @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 8395 whose prerequisites have one of these suffixes are actually suffix 8396 rules. If you modify the suffix list, the only predefined suffix 8397 rules in effect will be those named by one or two of the suffixes that 8398 are on the list you specify; rules whose suffixes fail to be on the 8399 list are disabled. @xref{Suffix Rules, ,Old-Fashioned Suffix Rules}, 8400 for full details on suffix rules. 8366 8401 8367 8402 @table @asis … … 8694 8729 @pindex cc 8695 8730 8696 @item CO8697 @vindex CO8698 Program for checking out files from RCS; default @samp{co}.8699 @pindex cc8700 8701 8731 @item CXX 8702 8732 @vindex CXX 8703 8733 Program for compiling C++ programs; default @samp{g++}. 8704 8734 @pindex g++ 8705 8706 @item CO8707 @vindex CO8708 Program for extracting a file from RCS; default @samp{co}.8709 @pindex co8710 8735 8711 8736 @item CPP … … 8720 8745 @pindex f77 8721 8746 8747 @item M2C 8748 @vindex M2C 8749 Program to use to compile Modula-2 source code; default @samp{m2c}. 8750 @pindex m2c 8751 8752 @item PC 8753 @vindex PC 8754 Program for compiling Pascal programs; default @samp{pc}. 8755 @pindex pc 8756 8757 @item CO 8758 @vindex CO 8759 Program for extracting a file from RCS; default @samp{co}. 8760 @pindex co 8761 8722 8762 @item GET 8723 8763 @vindex GET … … 8739 8779 Program to use to run lint on source code; default @samp{lint}. 8740 8780 @pindex lint 8741 8742 @item M2C8743 @vindex M2C8744 Program to use to compile Modula-2 source code; default @samp{m2c}.8745 @pindex m2c8746 8747 @item PC8748 @vindex PC8749 Program for compiling Pascal programs; default @samp{pc}.8750 @pindex pc8751 8781 8752 8782 @item MAKEINFO -
trunk/src/gmakenew/expand.c
r533 r903 56 56 57 57 char * 58 variable_buffer_output (char *ptr, c har *string, unsigned int length)58 variable_buffer_output (char *ptr, const char *string, unsigned int length) 59 59 { 60 60 register unsigned int newlen = length + (ptr - variable_buffer); … … 66 66 ? newlen + 100 67 67 : 2 * variable_buffer_length); 68 variable_buffer = (char *) xrealloc (variable_buffer, 69 variable_buffer_length); 68 variable_buffer = xrealloc (variable_buffer, variable_buffer_length); 70 69 ptr = variable_buffer + offset; 71 70 } 72 71 73 bcopy (string, ptr, length);72 memcpy (ptr, string, length); 74 73 return ptr + length; 75 74 } … … 85 84 { 86 85 variable_buffer_length = 200; 87 variable_buffer = (char *)xmalloc (variable_buffer_length);86 variable_buffer = xmalloc (variable_buffer_length); 88 87 variable_buffer[0] = '\0'; 89 88 } … … 95 94 /* Recursively expand V. The returned string is malloc'd. */ 96 95 97 static char *allocated_variable_append PARAMS ((const struct variable *v));96 static char *allocated_variable_append (const struct variable *v); 98 97 99 98 char * … … 162 161 #endif 163 162 static char * 164 reference_variable (char *o, c har *name, unsigned int length)165 { 166 registerstruct variable *v;163 reference_variable (char *o, const char *name, unsigned int length) 164 { 165 struct variable *v; 167 166 char *value; 168 167 … … 194 193 LINE is NULL, start at the beginning of the buffer. 195 194 Return a pointer to LINE, or to the beginning of the buffer if LINE is 196 NULL. */197 195 NULL. 196 */ 198 197 char * 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'; 198 variable_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; 204 204 unsigned int line_offset; 205 205 206 206 if (!line) 207 207 line = initialize_variable_output(); 208 209 p = string;210 208 o = line; 211 209 line_offset = line - variable_buffer; 212 210 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; 218 227 219 228 while (1) … … 246 255 char openparen = *p; 247 256 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; 252 262 253 263 op = o; … … 285 295 if (count < 0) 286 296 { 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; 289 299 end = strchr (beg, '\0'); 290 300 } … … 304 314 { 305 315 /* This looks like a substitution reference: $(FOO:A=B). */ 306 c har *subst_beg, *subst_end, *replace_beg, *replace_end;316 const char *subst_beg, *subst_end, *replace_beg, *replace_end; 307 317 308 318 subst_beg = colon + 1; … … 336 346 extra % at the beginning to use in case there 337 347 isn't one in the pattern. */ 338 pattern = (char *)alloca (subst_end - subst_beg + 2);348 pattern = alloca (subst_end - subst_beg + 2); 339 349 *(pattern++) = '%'; 340 bcopy (subst_beg, pattern, subst_end - subst_beg);350 memcpy (pattern, subst_beg, subst_end - subst_beg); 341 351 pattern[subst_end - subst_beg] = '\0'; 342 352 343 replace = (char *) alloca (replace_end 344 - replace_beg + 2); 353 replace = alloca (replace_end - replace_beg + 2); 345 354 *(replace++) = '%'; 346 bcopy (replace_beg, replace,355 memcpy (replace, replace_beg, 347 356 replace_end - replace_beg); 348 357 replace[replace_end - replace_beg] = '\0'; … … 354 363 { 355 364 ++ppercent; 356 rpercent = 0; 365 rpercent = find_percent (replace); 366 if (rpercent) 367 ++rpercent; 357 368 } 358 369 else … … 364 375 } 365 376 366 o = patsubst_expand (o, value, pattern, replace,367 ppercent, rpercent);377 o = patsubst_expand_pat (o, value, pattern, replace, 378 ppercent, rpercent); 368 379 369 380 if (v->recursive) … … 378 389 o = reference_variable (o, beg, end - beg); 379 390 380 if ( free_beg)381 free ( beg);391 if (abeg) 392 free (abeg); 382 393 } 383 394 break; … … 403 414 } 404 415 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); 409 420 return (variable_buffer + line_offset); 410 421 } … … 417 428 418 429 char * 419 variable_expand (c har *line)430 variable_expand (const char *line) 420 431 { 421 432 return variable_expand_string(NULL, line, (long)-1); … … 438 449 439 450 if (!end || *end == '\0') 440 return allocated_variable_expand ( (char *)str);451 return allocated_variable_expand (str); 441 452 442 453 #ifdef CONFIG_WITH_OPTIMIZATION_HACKS 443 444 445 446 447 448 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 } 450 461 #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 459 468 } 460 469 … … 464 473 465 474 char * 466 variable_expand_for_file (c har *line, struct file *file)475 variable_expand_for_file (const char *line, struct file *file) 467 476 { 468 477 char *result; … … 523 532 if (! v->recursive) 524 533 #ifdef CONFIG_WITH_VALUE_LENGTH 525 return variable_buffer_output (buf, v->value, 534 return variable_buffer_output (buf, v->value, 526 535 v->value_length >= 0 ? v->value_length : strlen (v->value)); 527 536 #else … … 539 548 #ifdef CONFIG_WITH_VALUE_LENGTH 540 549 /* Expands the specified string, appending it to the specified variable value. */ 541 void 550 void 542 551 append_expanded_string_to_variable (struct variable *v, char *value) 543 552 { … … 594 603 595 604 char * 596 allocated_variable_expand_for_file (c har *line, struct file *file)605 allocated_variable_expand_for_file (const char *line, struct file *file) 597 606 { 598 607 char *value; -
trunk/src/gmakenew/file.c
r520 r903 70 70 /* Access the hash table of all file records. 71 71 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 */ 74 74 75 75 struct file * 76 lookup_file (c har *name)77 { 78 registerstruct file *f;76 lookup_file (const char *name) 77 { 78 struct file *f; 79 79 struct file file_key; 80 80 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS) 81 register char *lname, *ln;81 char *lname; 82 82 #endif 83 83 … … 91 91 if (*name != '.') 92 92 { 93 register char *n; 94 lname = (char *) malloc (strlen (name) + 1); 93 const char *n; 94 char *ln; 95 lname = xstrdup (name); 95 96 for (n = name, ln = lname; *n != '\0'; ++n, ++ln) 96 97 *ln = isupper ((unsigned char)*n) ? tolower ((unsigned char)*n) : *n; … … 113 114 if (*name == '\0') 114 115 /* It was all slashes after a dot. */ 115 #if def VMS116 #if defined(VMS) 116 117 name = "[]"; 117 #else 118 #ifdef _AMIGA 118 #elif defined(_AMIGA) 119 119 name = ""; 120 120 #else 121 121 name = "./"; 122 #endif /* AMIGA */ 123 #endif /* VMS */ 122 #endif 124 123 125 124 file_key.hname = name; 126 f = (struct file *)hash_find_item (&files, &file_key);125 f = hash_find_item (&files, &file_key); 127 126 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS) 128 127 if (*name != '.') 129 128 free (lname); 130 129 #endif 130 131 131 return f; 132 132 } 133 133 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 134 139 struct file * 135 enter_file (c har *name)136 { 137 registerstruct file *f;138 registerstruct file *new;139 registerstruct file **file_slot;140 enter_file (const char *name) 141 { 142 struct file *f; 143 struct file *new; 144 struct file **file_slot; 140 145 struct file file_key; 141 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)142 char *lname, *ln;143 #endif144 146 145 147 assert (*name != '\0'); 148 assert (strcache_iscached (name)); 146 149 147 150 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS) 148 151 if (*name != '.') 149 152 { 150 register char *n; 151 lname = (char *) malloc (strlen (name) + 1); 153 const char *n; 154 char *lname, *ln; 155 lname = xstrdup (name); 152 156 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); 164 165 } 165 166 #endif … … 169 170 f = *file_slot; 170 171 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)); 181 176 new->name = new->hname = name; 182 177 new->update_status = -1; … … 199 194 200 195 201 /* Rename FILE to NAME. This is not as simple as resetting202 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 void206 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 216 196 /* Rehash FILE to NAME. This is not as simple as resetting 217 197 the `hname' member, since it must be put in a new hash bucket, … … 219 199 220 200 void 221 rehash_file (struct file *from_file, c har *to_hname)201 rehash_file (struct file *from_file, const char *to_hname) 222 202 { 223 203 struct file file_key; … … 227 207 struct file *f; 228 208 209 /* If it's already that name, we're done. */ 229 210 file_key.hname = to_hname; 230 if ( 0 ==file_hash_cmp (from_file, &file_key))211 if (! file_hash_cmp (from_file, &file_key)) 231 212 return; 232 213 214 /* Find the end of the renamed list for the "from" file. */ 233 215 file_key.hname = from_file->hname; 234 216 while (from_file->renamed != 0) 235 217 from_file = from_file->renamed; 236 218 if (file_hash_cmp (from_file, &file_key)) 237 /* hname changed unexpectedly */219 /* hname changed unexpectedly!! */ 238 220 abort (); 239 221 222 /* Remove the "from" file from the hash. */ 240 223 deleted_file = hash_delete (&files, from_file); 241 224 if (deleted_file != from_file) … … 243 226 abort (); 244 227 228 /* Find where the newly renamed file will go in the hash. */ 245 229 file_key.hname = to_hname; 246 230 file_slot = (struct file **) hash_find_slot (&files, &file_key); 247 231 to_file = *file_slot; 248 232 233 /* Change the hash name for this file. */ 249 234 from_file->hname = to_hname; 250 235 for (f = from_file->double_colon; f != 0; f = f->prev) 251 236 f->hname = to_hname; 252 237 238 /* If the new name doesn't exist yet just set it to the renamed file. */ 253 239 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; 255 279 else 256 280 { 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); 291 297 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; 318 306 319 307 #define MERGE(field) to_file->field |= from_file->field 320 321 322 323 324 325 326 327 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); 328 316 #undef MERGE 329 317 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 325 void 326 rename_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; 331 333 } 332 334 } … … 341 343 remove_intermediates (int sig) 342 344 { 343 registerstruct file **file_slot;344 registerstruct file **file_end;345 struct file **file_slot; 346 struct file **file_end; 345 347 int doneany = 0; 346 348 … … 357 359 if (! HASH_VACANT (*file_slot)) 358 360 { 359 registerstruct file *f = *file_slot;361 struct file *f = *file_slot; 360 362 /* Is this file eligible for automatic deletion? 361 363 Yes, IFF: it's marked intermediate, it's not secondary, it wasn't … … 448 450 } 449 451 450 451 452 /* Set the intermediate flag. */ 452 453 … … 464 465 struct dep *d; 465 466 struct dep *old = f->deps; 466 c har *file_stem = f->stem;467 const char *file_stem = f->stem; 467 468 unsigned int last_dep_has_cmds = f->updating; 468 469 int initialized = 0; … … 480 481 481 482 /* 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. */ 483 485 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 } 485 490 else 486 491 { … … 494 499 o = subst_expand (buffer, d->name, "%", "$*", 1, 2, 0); 495 500 496 free (d->name); 497 d->name = savestring (buffer, o - buffer); 501 d->name = strcache_add_len (buffer, o - buffer); 498 502 d->staticpattern = 0; /* Clear staticpattern so that we don't 499 503 re-expand %s below. */ … … 529 533 if (new && d->staticpattern) 530 534 { 531 c har *pattern = "%";535 const char *pattern = "%"; 532 536 char *buffer = variable_expand (""); 533 537 struct dep *dp = new, *dl = 0; … … 535 539 while (dp != 0) 536 540 { 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); 538 546 if (percent) 539 547 { 548 char *o; 549 540 550 /* We have to handle empty stems specially, because that 541 551 would be equivalent to $(patsubst %,dp->name,) which 542 552 will always be empty. */ 543 553 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 } 546 558 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); 559 561 560 562 /* If the name expanded to the empty string, ignore it. */ 561 if ( dp->name[0] == '\0')563 if (buffer[0] == '\0') 562 564 { 563 565 struct dep *df = dp; … … 566 568 else 567 569 dp = dl->next = dp->next; 568 /* @@ Are we leaking df->name here? */569 df->name = 0;570 570 free_dep (df); 571 571 continue; 572 572 } 573 574 /* Save the name. */ 575 dp->name = strcache_add_len (buffer, o - buffer); 573 576 } 574 577 dl = dp; … … 583 586 if (d1->file == 0) 584 587 d1->file = enter_file (d1->name); 585 else586 free (d1->name);587 588 d1->name = 0; 588 589 d1->staticpattern = 0; … … 639 640 struct file **file_end; 640 641 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. */ 646 645 for (f = lookup_file (".SUFFIXES"); f != 0; f = f->prev) 647 646 expand_deps (f); 648 647 649 /* We must use hash_dump (), because within this loop650 we might add new files to the table, possibly causing651 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. */ 652 651 file_slot_0 = (struct file **) hash_dump (&files, 0, 0); 653 652 file_end = file_slot_0 + files.ht_fill; 654 653 for (file_slot = file_slot_0; file_slot < file_end; file_slot++) 655 654 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); 660 657 free (file_slot_0); 658 659 /* Now manage all the special targets. */ 661 660 662 661 for (f = lookup_file (".PRECIOUS"); f != 0; f = f->prev) … … 682 681 683 682 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) 687 694 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 } 713 703 714 704 f = lookup_file (".EXPORT_ALL_VARIABLES"); … … 874 864 p += strlen (p); 875 865 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. */ 881 870 sprintf (p, ".%09d", FILE_TIMESTAMP_NS (ts)); 882 871 p += strlen (p) - 1; … … 894 883 print_file (const void *item) 895 884 { 896 struct file *f = (struct file *)item;885 const struct file *f = item; 897 886 struct dep *d; 898 887 struct dep *ood = 0; … … 1016 1005 } 1017 1006 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 1016 static void 1017 verify_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 1035 void 1036 verify_file_data_base (void) 1037 { 1038 hash_map (&files, verify_file); 1039 } 1040 1018 1041 #define EXPANSION_INCREMENT(_l) ((((_l) / 500) + 1) * 500) 1019 1042 … … 1052 1075 } 1053 1076 1054 bcopy (f->name, p, l);1077 memcpy (p, f->name, l); 1055 1078 p += l; 1056 1079 *(p++) = ' '; -
trunk/src/gmakenew/filedef.h
r507 r903 26 26 struct file 27 27 { 28 c har *name;29 c har *hname;/* Hashed filename */30 c har *vpath;/* VPATH/vpath pathname */28 const char *name; 29 const char *hname; /* Hashed filename */ 30 const char *vpath; /* VPATH/vpath pathname */ 31 31 struct dep *deps; /* all dependencies, including duplicates */ 32 32 struct commands *cmds; /* Commands to execute for this target. */ 33 33 int command_flags; /* Flags OR'd in for cmds; see commands.h. */ 34 c har *stem;/* Implicit stem, if an implicit35 34 const char *stem; /* Implicit stem, if an implicit 35 rule has been used */ 36 36 struct dep *also_make; /* Targets that are made by making this. */ 37 37 FILE_TIMESTAMP last_mtime; /* File's modtime, if already known. */ … … 102 102 103 103 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));104 struct file *lookup_file (const char *name); 105 struct file *enter_file (const char *name); 106 struct dep *parse_prereqs (char *prereqs); 107 void remove_intermediates (int sig); 108 void snap_deps (void); 109 void rename_file (struct file *file, const char *name); 110 void rehash_file (struct file *file, const char *name); 111 void set_command_state (struct file *file, enum cmd_state state); 112 void notice_finished_file (struct file *file); 113 void init_hash_files (void); 114 char *build_target_list (char *old_list); 115 115 116 116 #if FILE_TIMESTAMP_HI_RES … … 153 153 + 1 + 1 + 4 + 25) 154 154 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)); 155 FILE_TIMESTAMP file_timestamp_cons (char const *, time_t, int); 156 FILE_TIMESTAMP file_timestamp_now (int *); 157 void file_timestamp_sprintf (char *p, FILE_TIMESTAMP ts); 159 158 160 159 /* Return the mtime of file F (a struct file *), caching it. … … 166 165 The value is NONEXISTENT_MTIME if the file does not exist. */ 167 166 #define file_mtime_no_search(f) file_mtime_1 ((f), 0) 168 extern FILE_TIMESTAMP f_mtime PARAMS ((struct file *file, int search));167 FILE_TIMESTAMP f_mtime (struct file *file, int search); 169 168 #define file_mtime_1(f, v) \ 170 169 ((f)->last_mtime == UNKNOWN_MTIME ? f_mtime ((f), v) : (f)->last_mtime) -
trunk/src/gmakenew/function.c
r863 r903 53 53 unsigned char maximum_args; 54 54 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); 56 56 }; 57 57 … … 59 59 function_table_entry_hash_1 (const void *keyv) 60 60 { 61 struct function_table_entry const *key = (struct function_table_entry const *)keyv;61 const struct function_table_entry *key = keyv; 62 62 return_STRING_N_HASH_1 (key->name, key->len); 63 63 } … … 66 66 function_table_entry_hash_2 (const void *keyv) 67 67 { 68 struct function_table_entry const *key = (struct function_table_entry const *)keyv;68 const struct function_table_entry *key = keyv; 69 69 return_STRING_N_HASH_2 (key->name, key->len); 70 70 } … … 73 73 function_table_entry_hash_cmp (const void *xv, const void *yv) 74 74 { 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; 77 77 int result = x->len - y->len; 78 78 if (result) … … 92 92 93 93 char * 94 subst_expand (char *o, c har *text, char *subst,char *replace,94 subst_expand (char *o, const char *text, const char *subst, const char *replace, 95 95 unsigned int slen, unsigned int rlen, int by_word) 96 96 { 97 c har *t = text;98 c har *p;97 const char *t = text; 98 const char *p; 99 99 100 100 if (slen == 0 && !by_word) … … 141 141 142 142 /* Advance T past the string to be replaced. */ 143 { 144 char *nt = p + slen; 145 t = nt; 146 } 143 t = p + slen; 147 144 } while (*t != '\0'); 148 145 … … 163 160 164 161 char * 165 patsubst_expand (char *o, char *text, char *pattern, char *replace, 166 char *pattern_percent, char *replace_percent) 162 patsubst_expand_pat (char *o, const char *text, 163 const char *pattern, const char *replace, 164 const char *pattern_percent, const char *replace_percent) 167 165 { 168 166 unsigned int pattern_prepercent_len, pattern_postpercent_len; 169 167 unsigned int replace_prepercent_len, replace_postpercent_len; 170 c har *t;168 const char *t; 171 169 unsigned int len; 172 170 int doneany = 0; 173 174 /* We call find_percent on REPLACE before checking PATTERN so that REPLACE175 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 }182 171 183 172 /* Record the length of REPLACE before and after the % so we don't have to … … 194 183 } 195 184 196 if (!pattern_percent)197 {198 pattern_percent = find_percent (pattern);199 if (pattern_percent)200 ++pattern_percent;201 }202 185 if (!pattern_percent) 203 186 /* With no % in the pattern, this is just a simple substitution. */ … … 271 254 } 272 255 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 266 char * 267 patsubst_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 273 282 274 283 #ifdef CONFIG_WITH_OPTIMIZATION_HACKS … … 276 285 it can't be function and we can skip the hash lookup drop out. */ 277 286 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 */ 283 293 284 294 /* Look up a function by name. */ 295 296 #ifdef CONFIG_WITH_OPTIMIZATION_HACKS 285 297 __inline 286 298 #endif /* CONFIG_WITH_OPTIMIZATION_HACKS */ … … 318 330 319 331 int 320 pattern_matches (c har *pattern, char *percent,char *str)332 pattern_matches (const char *pattern, const char *percent, const char *str) 321 333 { 322 334 unsigned int sfxlen, strlength; … … 325 337 { 326 338 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); 329 344 pattern = new_chars; 330 percent = find_percent (pattern);331 if (percent == 0)332 return streq (pattern, str);333 345 } 334 346 … … 386 398 static char *result = 0; 387 399 static unsigned int length; 388 registerstruct nameseq *chain;389 registerunsigned int idx;400 struct nameseq *chain; 401 unsigned int idx; 390 402 391 403 chain = multi_glob (parse_file_seq … … 400 412 { 401 413 length = 100; 402 result = (char *)xmalloc (100);414 result = xmalloc (100); 403 415 } 404 416 … … 406 418 while (chain != 0) 407 419 { 408 registerchar *name = chain->name;420 const char *name = chain->name; 409 421 unsigned int len = strlen (name); 410 422 411 423 struct nameseq *next = chain->next; 412 free ( (char *)chain);424 free (chain); 413 425 chain = next; 414 426 … … 420 432 { 421 433 length += (len + 1) * 2; 422 result = (char *)xrealloc (result, length);434 result = xrealloc (result, length); 423 435 } 424 bcopy (name, &result[idx], len);436 memcpy (&result[idx], name, len); 425 437 idx += len; 426 438 result[idx++] = ' '; 427 439 } 428 429 free (name);430 440 } 431 441 … … 447 457 func_patsubst (char *o, char **argv, const char *funcname UNUSED) 448 458 { 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]); 450 460 return o; 451 461 } … … 461 471 If the two arguments have a different number of words, 462 472 the excess words are just output separated by blanks. */ 463 registerchar *tp;464 registerchar *pp;465 c har *list1_iterator = argv[0];466 c har *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]; 467 477 do 468 478 { … … 496 506 { 497 507 /* Expand the argument. */ 498 registerstruct variable *v = lookup_variable (argv[0], strlen (argv[0]));508 struct variable *v = lookup_variable (argv[0], strlen (argv[0])); 499 509 if (v == 0) 500 510 o = variable_buffer_output (o, "undefined", 9); … … 535 545 func_flavor (char *o, char **argv, const char *funcname UNUSED) 536 546 { 537 registerstruct variable *v = lookup_variable (argv[0], strlen (argv[0]));547 struct variable *v = lookup_variable (argv[0], strlen (argv[0])); 538 548 539 549 if (v == 0) … … 563 573 { 564 574 /* Expand the argument. */ 565 c har *list_iterator = argv[0];566 c har *p2 =0;575 const char *list_iterator = argv[0]; 576 const char *p2; 567 577 int doneany =0; 568 578 unsigned int len=0; … … 572 582 while ((p2 = find_next_token (&list_iterator, &len)) != 0) 573 583 { 574 c har *p = p2 + len;584 const char *p = p2 + len; 575 585 576 586 … … 607 617 } 608 618 } 619 609 620 if (doneany) 610 621 /* Kill last space. */ 611 622 --o; 612 623 613 614 return o; 615 624 return o; 616 625 } 617 626 … … 621 630 { 622 631 /* Expand the argument. */ 623 c har *p3 = argv[0];624 c har *p2=0;632 const char *p3 = argv[0]; 633 const char *p2; 625 634 int doneany=0; 626 635 unsigned int len=0; 627 char *p=0; 636 628 637 int is_basename= streq (funcname, "basename"); 629 638 int is_dir= !is_basename; 630 639 631 640 while ((p2 = find_next_token (&p3, &len)) != 0) 632 633 634 635 636 637 638 639 640 641 642 643 644 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); 645 654 #ifdef HAVE_DOS_PATHS 646 647 648 649 #endif 650 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) 651 660 #ifdef VMS 652 661 o = variable_buffer_output (o, "[]", 2); 653 662 #else 654 663 #ifndef _AMIGA 655 664 o = variable_buffer_output (o, "./", 2); 656 665 #else 657 666 ; /* Just a nop... */ 658 667 #endif /* AMIGA */ 659 668 #endif /* !VMS */ 660 661 662 663 664 665 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; 673 682 } 674 683 … … 677 686 { 678 687 int fixlen = strlen (argv[0]); 679 c har *list_iterator = argv[1];688 const char *list_iterator = argv[1]; 680 689 int is_addprefix = streq (funcname, "addprefix"); 681 690 int is_addsuffix = !is_addprefix; 682 691 683 692 int doneany = 0; 684 c har *p;693 const char *p; 685 694 unsigned int len; 686 695 … … 717 726 { 718 727 unsigned int i; 719 c har *words = argv[0]; /* Use a temp variable for find_next_token */720 c har *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); 721 730 722 731 if (p != 0) … … 730 739 { 731 740 unsigned int i; 732 c har *words = argv[0]; /* Use a temp variable for find_next_token */733 c har *p = 0;734 c har *t;741 const char *words = argv[0]; /* Use a temp variable for find_next_token */ 742 const char *p = NULL; 743 const char *t; 735 744 736 745 while ((t = find_next_token (&words, &i))) … … 747 756 { 748 757 int i = 0; 749 c har *word_iterator = argv[0];758 const char *word_iterator = argv[0]; 750 759 char buf[20]; 751 760 … … 755 764 sprintf (buf, "%d", i); 756 765 o = variable_buffer_output (o, buf, strlen (buf)); 757 758 766 759 767 return o; … … 776 784 777 785 static void 778 check_numeric (const char *s, const char *m essage)786 check_numeric (const char *s, const char *msg) 779 787 { 780 788 const char *end = s + strlen (s) - 1; … … 787 795 788 796 if (s <= end || end - beg < 0) 789 fatal (*expanding_var, "%s: '%s'", m essage, beg);797 fatal (*expanding_var, "%s: '%s'", msg, beg); 790 798 } 791 799 … … 795 803 func_word (char *o, char **argv, const char *funcname UNUSED) 796 804 { 797 c har *end_p=0;798 int i=0;799 char *p=0;805 const char *end_p; 806 const char *p; 807 int i; 800 808 801 809 /* Check the first argument. */ 802 810 check_numeric (argv[0], _("non-numeric first argument to `word' function")); 803 i = 811 i = atoi (argv[0]); 804 812 805 813 if (i == 0) 806 814 fatal (*expanding_var, 807 815 _("first argument to `word' function must be greater than 0")); 808 809 816 810 817 end_p = argv[1]; … … 839 846 if (count > 0) 840 847 { 841 c har *p;842 c har *end_p = argv[2];848 const char *p; 849 const char *end_p = argv[2]; 843 850 844 851 /* Find the beginning of the "start"th word. */ … … 860 867 } 861 868 862 static char *869 static char * 863 870 func_findstring (char *o, char **argv, const char *funcname UNUSED) 864 871 { … … 876 883 char *varname = expand_argument (argv[0], NULL); 877 884 char *list = expand_argument (argv[1], NULL); 878 c har *body = argv[2];885 const char *body = argv[2]; 879 886 880 887 int doneany = 0; 881 c har *list_iterator = list;882 c har *p;888 const char *list_iterator = list; 889 const char *p; 883 890 unsigned int len; 884 registerstruct variable *var;891 struct variable *var; 885 892 886 893 push_new_variable_scope (); … … 902 909 var->value_length = len; 903 910 #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); 912 913 #endif 913 914 … … 983 984 struct hash_table a_word_table; 984 985 int is_filter = streq (funcname, "filter"); 985 c har *pat_iterator = argv[0];986 c har *word_iterator = argv[1];986 const char *pat_iterator = argv[0]; 987 const char *word_iterator = argv[1]; 987 988 int literals = 0; 988 989 int words = 0; … … 996 997 while ((p = find_next_token (&pat_iterator, &len)) != 0) 997 998 { 998 struct a_pattern *pat = (struct a_pattern *)alloca (sizeof (struct a_pattern));999 struct a_pattern *pat = alloca (sizeof (struct a_pattern)); 999 1000 1000 1001 *pattail = pat; … … 1019 1020 while ((p = find_next_token (&word_iterator, &len)) != 0) 1020 1021 { 1021 struct a_word *word = (struct a_word *)alloca (sizeof (struct a_word));1022 struct a_word *word = alloca (sizeof (struct a_word)); 1022 1023 1023 1024 *wordtail = word; … … 1040 1041 if (hashing) 1041 1042 { 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); 1043 1045 for (wp = wordhead; wp != 0; wp = wp->next) 1044 1046 { … … 1064 1066 a_word_key.str = pp->str; 1065 1067 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); 1067 1069 while (wp) 1068 1070 { … … 1104 1106 func_strip (char *o, char **argv, const char *funcname UNUSED) 1105 1107 { 1106 c har *p = argv[0];1107 int doneany = 0;1108 const char *p = argv[0]; 1109 int doneany = 0; 1108 1110 1109 1111 while (*p != '\0') 1110 1112 { 1111 1113 int i=0; 1112 c har *word_start=0;1114 const char *word_start; 1113 1115 1114 1116 while (isspace ((unsigned char)*p)) … … 1127 1129 /* Kill the last space. */ 1128 1130 --o; 1131 1129 1132 return o; 1130 1133 } … … 1146 1149 len += strlen (*argvp) + 2; 1147 1150 1148 p = msg = (char *)alloca (len + 1);1151 p = msg = alloca (len + 1); 1149 1152 1150 1153 for (argvp=argv; argvp[1] != 0; ++argvp) … … 1185 1188 func_sort (char *o, char **argv, const char *funcname UNUSED) 1186 1189 { 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; 1193 1193 char *p; 1194 1194 unsigned int len; 1195 1195 int i; 1196 1196 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; 1197 1218 while ((p = find_next_token (&t, &len)) != 0) 1198 1219 { 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")) 1220 1233 { 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 1223 1247 } 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 } 1228 1268 1229 1269 free (words); … … 1271 1311 argv += 1 + !result; 1272 1312 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); 1278 1316 1279 1317 o = variable_buffer_output (o, expansion, strlen (expansion)); … … 1392 1430 func_wildcard (char *o, char **argv, const char *funcname UNUSED) 1393 1431 { 1394 1395 1432 #ifdef _AMIGA 1396 1433 o = wildcard_expansion (argv[0], o); … … 1637 1674 func_shell (char *o, char **argv, const char *funcname UNUSED) 1638 1675 { 1639 char *batch_filename = NULL;1676 char *batch_filename = NULL; 1640 1677 1641 1678 #ifdef __MSDOS__ … … 1643 1680 #endif 1644 1681 char **command_argv; 1645 c har *error_prefix;1682 const char *error_prefix; 1646 1683 char **envp; 1647 1684 int pipedes[2]; … … 1650 1687 #ifndef __MSDOS__ 1651 1688 /* 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); 1655 1690 if (command_argv == 0) 1656 1691 return o; … … 1664 1699 calling environment. 1665 1700 1701 See Savannah bug #10593. 1702 1666 1703 envp = target_environment (NILF); 1667 1704 */ … … 1672 1709 if (reading_file && reading_file->filenm) 1673 1710 { 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; 1677 1714 } 1678 1715 else 1679 1716 error_prefix = ""; 1680 1717 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__) 1694 1719 fpipe = msdos_openpipe (pipedes, &pid, argv[0]); 1695 1720 if (pipedes[0] < 0) … … 1698 1723 return o; 1699 1724 } 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 1701 1735 #else 1702 1703 1736 if (pipe (pipedes) < 0) 1704 1737 { … … 1708 1741 1709 1742 # ifdef __EMX__ 1710 1711 1743 /* close some handles that are unnecessary for the child process */ 1712 1744 CLOSE_ON_EXEC(pipedes[1]); … … 1716 1748 if (pid < 0) 1717 1749 perror_with_name (error_prefix, "spawn"); 1718 1719 1750 # else /* ! __EMX__ */ 1720 1721 1751 pid = vfork (); 1722 1752 if (pid < 0) … … 1725 1755 child_execute_job (0, pipedes[1], command_argv, envp); 1726 1756 else 1727 1728 1757 # endif 1729 1730 1758 #endif 1731 1759 { … … 1742 1770 /* Free the storage only the child needed. */ 1743 1771 free (command_argv[0]); 1744 free ( (char *)command_argv);1772 free (command_argv); 1745 1773 1746 1774 /* Close the write side of the pipe. */ 1747 # ifdef _MSC_VER /* crap.*/1775 # ifdef _MSC_VER /* Avoid annoying msvcrt when debugging. (bird) */ 1748 1776 if (pipedes[1] != -1) 1749 # endif 1750 (void)close (pipedes[1]);1777 # endif 1778 close (pipedes[1]); 1751 1779 #endif 1752 1780 … … 1754 1782 1755 1783 maxlen = 200; 1756 buffer = (char *)xmalloc (maxlen + 1);1784 buffer = xmalloc (maxlen + 1); 1757 1785 1758 1786 /* Read from the pipe until it gets EOF. */ … … 1762 1790 { 1763 1791 maxlen += 512; 1764 buffer = (char *)xrealloc (buffer, maxlen + 1);1792 buffer = xrealloc (buffer, maxlen + 1); 1765 1793 } 1766 1794 … … 1776 1804 (void) pclose (fpipe); 1777 1805 #else 1778 # ifdef _MSC_VER /* crap.*/1806 # ifdef _MSC_VER /* Avoid annoying msvcrt when debugging. (bird) */ 1779 1807 if (pipedes[0] != -1) 1780 # endif 1808 # endif 1781 1809 (void) close (pipedes[0]); 1782 1810 #endif … … 1892 1920 { 1893 1921 maxlen += 512; 1894 buffer = (char *)xrealloc (buffer, maxlen + 1);1922 buffer = xrealloc (buffer, maxlen + 1); 1895 1923 } 1896 1924 … … 1930 1958 func_not (char *o, char **argv, const char *funcname) 1931 1959 { 1932 c har *s = argv[0];1960 const char *s = argv[0]; 1933 1961 int result = 0; 1934 1962 while (isspace ((unsigned char)*s)) … … 2063 2091 { 2064 2092 /* Expand the argument. */ 2065 c har *p = argv[0];2066 c har *path = 0;2093 const char *p = argv[0]; 2094 const char *path = 0; 2067 2095 int doneany = 0; 2068 2096 unsigned int len = 0; … … 2077 2105 in[len] = '\0'; 2078 2106 2079 if 2080 ( 2107 if ( 2081 2108 #ifdef HAVE_REALPATH 2082 realpath (in, out)2109 realpath (in, out) 2083 2110 #else 2084 abspath (in, out)2085 #endif 2086 )2111 abspath (in, out) 2112 #endif 2113 ) 2087 2114 { 2088 2115 o = variable_buffer_output (o, out, strlen (out)); … … 2097 2124 --o; 2098 2125 2099 return o;2126 return o; 2100 2127 } 2101 2128 … … 2104 2131 { 2105 2132 /* Expand the argument. */ 2106 c har *p = argv[0];2107 c har *path = 0;2133 const char *p = argv[0]; 2134 const char *path = 0; 2108 2135 int doneany = 0; 2109 2136 unsigned int len = 0; … … 2131 2158 --o; 2132 2159 2133 return o;2160 return o; 2134 2161 } 2135 2162 … … 2141 2168 /* Expand the argument. */ 2142 2169 char *p = argv[0]; 2143 PATH_VAR (current_directory);2144 2170 char *cwd = argv[1]; 2145 2171 unsigned int cwd_len = ~0U; … … 2974 3000 } 2975 3001 2976 2977 3002 #endif /* CONFIG_WITH_MATH */ 3003 2978 3004 2979 3005 /* Lookup table for builtin functions. … … 2989 3015 Functions that do namespace tricks (foreach) don't automatically expand. */ 2990 3016 2991 static char *func_call PARAMS ((char *o, char **argv, const char *funcname));3017 static char *func_call (char *o, char **argv, const char *funcname); 2992 3018 2993 3019 … … 3012 3038 { STRING_SIZE_TUPLE("patsubst"), 3, 3, 1, func_patsubst}, 3013 3039 { 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 3014 3043 { STRING_SIZE_TUPLE("shell"), 0, 1, 1, func_shell}, 3015 3044 { STRING_SIZE_TUPLE("sort"), 0, 1, 1, func_sort}, … … 3115 3144 3116 3145 static int 3117 handle_function2 (const struct function_table_entry *entry_p, char **op, c har **stringp) /* bird split it up. */3146 handle_function2 (const struct function_table_entry *entry_p, char **op, const char **stringp) /* bird split it up. */ 3118 3147 { 3119 3148 char openparen = (*stringp)[0]; 3120 3149 char closeparen = openparen == '(' ? ')' : '}'; 3121 c har *beg;3122 c har *end;3150 const char *beg; 3151 const char *end; 3123 3152 int count = 0; 3124 register char *p;3153 char *abeg = NULL; 3125 3154 char **argv, **argvp; 3126 3155 int nargs; … … 3154 3183 3155 3184 /* 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)); 3157 3186 3158 3187 /* Chop the string into arguments, then a nul. As soon as we hit … … 3164 3193 each argument. */ 3165 3194 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 3167 3213 { 3168 3214 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) 3190 3223 { 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 3191 3232 *argvp = p; 3192 3233 *next = '\0'; 3234 p = next + 1; 3193 3235 } 3194 3195 p = next + 1;3196 3236 } 3197 3237 *argvp = NULL; … … 3204 3244 for (argvp=argv; *argvp != 0; ++argvp) 3205 3245 free (*argvp); 3206 else3207 free ( beg);3246 if (abeg) 3247 free (abeg); 3208 3248 3209 3249 return 1; … … 3211 3251 3212 3252 int 3213 handle_function (char **op, c har **stringp) /* bird split it up */3253 handle_function (char **op, const char **stringp) /* bird split it up */ 3214 3254 { 3215 3255 const struct function_table_entry *entry_p = lookup_function (*stringp + 1); … … 3256 3296 3257 3297 entry_p = lookup_function (fname); 3258 3259 3298 if (entry_p) 3260 3299 { 3261 3300 /* How many arguments do we have? */ 3262 3301 for (i=0; argv[i+1]; ++i) 3263 ; 3264 3302 ; 3265 3303 return expand_builtin_function (o, i, argv+1, entry_p); 3266 3304 } … … 3278 3316 return o; 3279 3317 3280 body = (char *)alloca (flen + 4);3318 body = alloca (flen + 4); 3281 3319 body[0] = '$'; 3282 3320 body[1] = '('; … … 3339 3377 unsigned i; 3340 3378 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); 3342 3380 } 3343 3381 #endif -
trunk/src/gmakenew/getloadavg.c
r503 r903 707 707 { 708 708 struct class_stats stats; 709 bzero ((char *) &stats, sizeof stats);709 memset (&stats, '\0', sizeof stats); 710 710 711 711 desc.sd_type = CPUTYPE_CLASS; -
trunk/src/gmakenew/hash.h
r527 r903 278 278 279 279 #define ISTRING_COMPARE(X, Y, RESULT) do { \ 280 RESULT = strc mpi((X), (Y)); \280 RESULT = strcasecmp ((X), (Y)); \ 281 281 } while (0) 282 282 #define return_ISTRING_COMPARE(X, Y) do { \ 283 return strc mpi((X), (Y)); \283 return strcasecmp ((X), (Y)); \ 284 284 } while (0) 285 285 -
trunk/src/gmakenew/implicit.c
r503 r903 26 26 #include "commands.h" /* set_file_variables */ 27 27 28 static int 29 pattern_search PARAMS ((struct file *file, int archive, 30 unsigned int depth, unsigned int recursions)); 28 static int pattern_search (struct file *file, int archive, 29 unsigned int depth, unsigned int recursions); 31 30 32 31 … … 72 71 { 73 72 struct idep *next; /* struct dep -compatible interface */ 74 c har *name;/* name of the prerequisite */73 const char *name; /* name of the prerequisite */ 75 74 struct file *intermediate_file; /* intermediate file, 0 otherwise */ 76 c har *intermediate_pattern;/* pattern for intermediate file */75 const char *intermediate_pattern; /* pattern for intermediate file */ 77 76 unsigned char had_stem; /* had % substituted with stem */ 78 77 unsigned char ignore_mtime; /* ignore_mtime flag */ … … 87 86 { 88 87 n = p->next; 89 90 if (p->name)91 {92 struct file *f = p->intermediate_file;93 94 if (f != 095 && (f->stem < f->name || f->stem > f->name + strlen (f->name)))96 free (f->stem);97 98 free (p->name);99 }100 101 88 free (p); 102 89 } … … 109 96 110 97 static char * 111 get_next_word (c har *buffer, unsigned int *length)98 get_next_word (const char *buffer, unsigned int *length) 112 99 { 113 c har *p = buffer, *beg;100 const char *p = buffer, *beg; 114 101 char c; 115 102 … … 182 169 *length = p - beg; 183 170 184 return beg;171 return (char *)beg; 185 172 } 186 173 … … 204 191 { 205 192 /* Filename we are searching for a rule for. */ 206 c har *filename = archive ? strchr (file->name, '(') : file->name;193 const char *filename = archive ? strchr (file->name, '(') : file->name; 207 194 208 195 /* Length of FILENAME. */ … … 226 213 227 214 /* 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); 229 216 230 217 /* The start and length of the stem of FILENAME for the current rule. */ 231 registerchar *stem = 0;232 registerunsigned int stemlen = 0;233 registerunsigned int fullstemlen = 0;218 const char *stem = 0; 219 unsigned int stemlen = 0; 220 unsigned int fullstemlen = 0; 234 221 235 222 /* 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 *)); 239 225 240 226 /* Number of valid elements in TRYRULES. */ … … 243 229 /* The numbers of the rule targets of each rule 244 230 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)); 247 232 248 233 /* Each element is nonzero if LASTSLASH was used in 249 234 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)); 252 236 253 237 /* The index in TRYRULES of the rule we found. */ … … 261 245 int specific_rule_matched = 0; 262 246 263 unsigned int i = 0; /* uninit checks OK */247 unsigned int ri; /* uninit checks OK */ 264 248 struct rule *rule; 265 249 struct dep *dep, *expl_d; 266 267 char *p, *vname;268 250 269 251 struct idep *d; … … 296 278 lastslash = bslash; 297 279 if (lastslash == 0 && filename[0] && filename[1] == ':') 298 lastslash = filename + 1;280 lastslash = (char *)filename + 1; 299 281 } 300 282 #endif … … 310 292 for (rule = pattern_rules; rule != 0; rule = rule->next) 311 293 { 294 unsigned int ti; 295 312 296 /* If the pattern rule has deps but no commands, ignore it. 313 297 Users cancel built-in rules by redefining them without commands. */ … … 323 307 } 324 308 325 for ( i = 0; rule->targets[i] != 0; ++i)309 for (ti = 0; ti < rule->num; ++ti) 326 310 { 327 c har *target = rule->targets[i];328 c har *suffix = rule->suffixes[i];311 const char *target = rule->targets[ti]; 312 const char *suffix = rule->suffixes[ti]; 329 313 int check_lastslash; 330 314 … … 335 319 continue; 336 320 337 if (rule->lens[ i] > namelen)321 if (rule->lens[ti] > namelen) 338 322 /* It can't possibly match. */ 339 323 continue; … … 342 326 find the stem: the part of the filename that matches the %. */ 343 327 stem = filename + (suffix - target - 1); 344 stemlen = namelen - rule->lens[ i] + 1;328 stemlen = namelen - rule->lens[ti] + 1; 345 329 346 330 /* Set CHECK_LASTSLASH if FILENAME contains a directory … … 408 392 that rule will be in TRYRULES more than once. */ 409 393 tryrules[nrules] = rule; 410 matches[nrules] = i;394 matches[nrules] = ti; 411 395 checked_lastslash[nrules] = check_lastslash; 412 396 ++nrules; … … 417 401 retroactively reject any non-"terminal" rules that do always match. */ 418 402 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) 421 405 { 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 } 428 413 } 429 414 … … 439 424 and chain them in DEPS. */ 440 425 441 for ( i = 0; i < nrules;i++)426 for (ri = 0; ri < nrules; ri++) 442 427 { 443 428 struct file *f; … … 446 431 int file_variables_set = 0; 447 432 448 rule = tryrules[ i];433 rule = tryrules[ri]; 449 434 450 435 remove_explicit_deps = 0; … … 467 452 find the stem: the part of the filename that matches the %. */ 468 453 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]; 472 457 if (check_lastslash) 473 458 { … … 491 476 { 492 477 unsigned int len; 478 char *p; 493 479 char *p2; 494 480 unsigned int order_only = 0; /* Set if '|' was seen. */ … … 536 522 if (p2 < p + len) 537 523 { 538 registerunsigned 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); 542 528 depname[len + 2 - 1] = '\0'; 543 529 … … 549 535 else 550 536 { 551 bcopy (p, depname, len);537 memcpy (depname, p, len); 552 538 depname[len] = '\0'; 553 539 } … … 568 554 if (p2 < p + len) 569 555 { 570 registerunsigned 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); 574 560 depname[len + stemlen - 1] = '\0'; 575 561 … … 581 567 else 582 568 { 583 bcopy (p, depname, len);569 memcpy (depname, p, len); 584 570 depname[len] = '\0'; 585 571 } … … 619 605 if (add_dir) 620 606 { 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); 629 611 } 630 612 … … 658 640 for (d = deps; d != 0; d = d->next) 659 641 { 660 c har *name = d->name;642 const char *name = d->name; 661 643 662 644 if (file_impossible_p (name)) … … 670 652 : _("Rejecting impossible rule prerequisite `%s'.\n"), 671 653 name)); 672 tryrules[ i] = 0;654 tryrules[ri] = 0; 673 655 674 656 failed = 1; … … 706 688 /* This code, given FILENAME = "lib/foo.o", dependency name 707 689 "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 } 719 700 720 701 … … 726 707 { 727 708 if (intermediate_file == 0) 728 intermediate_file 729 = (struct file *) alloca (sizeof (struct file)); 709 intermediate_file = alloca (sizeof (struct file)); 730 710 731 711 DBS (DB_IMPLICIT, … … 733 713 name)); 734 714 735 bzero ((char *) intermediate_file, sizeof (struct file));715 memset (intermediate_file, '\0', sizeof (struct file)); 736 716 intermediate_file->name = name; 737 717 if (pattern_search (intermediate_file, … … 740 720 recursions + 1)) 741 721 { 722 d->intermediate_pattern = intermediate_file->name; 723 intermediate_file->name = strcache_add (name); 742 724 d->intermediate_file = intermediate_file; 743 d->intermediate_pattern = intermediate_file->name;744 745 intermediate_file->name = xstrdup (name);746 725 intermediate_file = 0; 747 726 … … 781 760 /* If we found an applicable rule without 782 761 intermediate files, don't try with them. */ 783 if ( i < nrules)762 if (ri < nrules) 784 763 break; 785 764 … … 792 771 goto done; 793 772 794 foundrule = i;773 foundrule = ri; 795 774 796 775 /* If we are recursing, store the pattern that matched … … 825 804 for (d = deps; d != 0; d = d->next) 826 805 { 827 registerchar *s;806 const char *s; 828 807 829 808 if (d->intermediate_file != 0) … … 845 824 f->precious = 1; 846 825 else 847 f = enter_file ( imf->name);826 f = enter_file (strcache_add (imf->name)); 848 827 849 828 f->deps = imf->deps; … … 865 844 { 866 845 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);870 846 dep->name = 0; 871 847 dep->file->tried_implicit |= dep->changed; … … 881 857 dep->file = lookup_file (s); 882 858 if (dep->file == 0) 883 /* enter_file consumes S's storage. */884 859 dep->file = enter_file (s); 885 else886 /* A copy of S is already allocated in DEP->file->name.887 So we can free S. */888 free (s);889 860 } 890 861 else 891 { 892 dep->name = s; 893 } 862 dep->name = s; 894 863 895 864 if (d->intermediate_file == 0 && tryrules[foundrule]->terminal) … … 916 885 /* Always allocate new storage, since STEM might be 917 886 on the stack for an intermediate file. */ 918 file->stem = s avestring(stem, stemlen);887 file->stem = strcache_add_len (stem, stemlen); 919 888 fullstemlen = stemlen; 920 889 } … … 922 891 { 923 892 int dirlen = (lastslash + 1) - filename; 893 char *sp; 924 894 925 895 /* We want to prepend the directory from 926 896 the original FILENAME onto the stem. */ 927 897 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); 932 903 } 933 904 … … 945 916 `also_make' member. */ 946 917 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]) 950 921 { 922 char *p = alloca (rule->lens[ri] + fullstemlen + 1); 951 923 struct file *f; 952 924 struct dep *new = alloc_dep (); 953 925 954 926 /* 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); 960 931 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); 963 935 new->file = enter_file (new->name); 964 936 new->next = file->also_make; 965 937 966 938 /* Set precious flag. */ 967 f = lookup_file (rule->targets[ i]);939 f = lookup_file (rule->targets[ri]); 968 940 if (f && f->precious) 969 941 new->file->precious = 1; -
trunk/src/gmakenew/job.c
r898 r903 103 103 # include <starlet.h> 104 104 # include <lib$routines.h> 105 static void vmsWaitForChildren PARAMS ((int *));105 static void vmsWaitForChildren (int *); 106 106 #endif 107 107 … … 135 135 136 136 #if !defined (wait) && !defined (POSIX) 137 externint wait ();137 int wait (); 138 138 #endif 139 139 … … 180 180 181 181 #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 */ 183 int dup2 (); 184 int execve (); 185 void _exit (); 186 # endif /* bird */ 187 # ifndef VMS 188 int geteuid (); 189 int getegid (); 190 int setgid (); 191 int getgid (); 186 192 # 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 195 int getloadavg (double loadavg[], int nelem); 196 int start_remote_job (char **argv, char **envp, int stdin_fd, int *is_remote, 197 int *id_ptr, int *used_stdin); 198 int start_remote_job_p (int); 199 int remote_status (int *exit_code_ptr, int *signal_ptr, int *coredump_ptr, 200 int block); 201 202 RETSIGTYPE child_handler (int); 203 static void free_child (struct child *); 204 static void start_job_command (struct child *child); 205 static int load_too_high (void); 206 static int job_next_command (struct child *); 207 static int start_waiting_job (struct child *); 210 208 211 209 … … 310 308 { 311 309 const unsigned final_size = path_size + size + 1; 312 char *const path = (char *)xmalloc (final_size);310 char *const path = xmalloc (final_size); 313 311 memcpy (path, temp_path, final_size); 314 312 *fd = _open_osfhandle ((long)h, 0); … … 369 367 i = 0; 370 368 while (known_os2shells[i] != NULL) { 371 if (str icmp (name, known_os2shells[i]) == 0) /* strcasecmp() */369 if (strcasecmp (name, known_os2shells[i]) == 0) 372 370 return 0; /* not a unix shell */ 373 371 i++; … … 386 384 387 385 static void 388 child_error (c har *target_name, int exit_code, int exit_sig, int coredump,389 int ignored)386 child_error (const char *target_name, 387 int exit_code, int exit_sig, int coredump, int ignored) 390 388 { 391 389 if (ignored && silent_flag) … … 435 433 } 436 434 437 #if defined __EMX__ && !defined(__INNOTEK_LIBC__) 435 #if defined __EMX__ && !defined(__INNOTEK_LIBC__) /* bird */ 438 436 /* The signal handler must called only once! */ 439 437 signal (SIGCHLD, SIG_DFL); … … 510 508 511 509 The test and decrement are not atomic; if it is compiled into: 512 510 register = dead_children - 1; 513 511 dead_children = register; 514 512 a SIGCHLD could come between the two instructions. … … 925 923 for (i = 0; i < child->file->cmds->ncommand_lines; ++i) 926 924 free (child->command_lines[i]); 927 free ( (char *)child->command_lines);925 free (child->command_lines); 928 926 } 929 927 … … 933 931 while (*ep != 0) 934 932 free (*ep++); 935 free ( (char *)child->environment);936 } 937 938 free ( (char *)child);933 free (child->environment); 934 } 935 936 free (child); 939 937 } 940 938 … … 977 975 struct sigaction sa; 978 976 979 #if defined(__EMX__) && !defined(__KLIBC__) 977 #if defined(__EMX__) && !defined(__KLIBC__) /* bird */ 980 978 /* The child handler must be turned off here. */ 981 979 signal (SIGCHLD, SIG_DFL); 982 980 #endif 983 981 984 bzero ((char *) &sa, sizeof sa);982 memset (&sa, '\0', sizeof sa); 985 983 sa.sa_handler = child_handler; 986 984 sa.sa_flags = set_handler ? 0 : SA_RESTART; … … 1098 1096 #ifndef VMS 1099 1097 free (argv[0]); 1100 free ( (char *)argv);1098 free (argv); 1101 1099 #endif 1102 1100 child->file->update_status = 1; … … 1113 1111 { 1114 1112 free (argv[0]); 1115 free ( (char *)argv);1113 free (argv); 1116 1114 } 1117 1115 #endif … … 1184 1182 { 1185 1183 free (argv[0]); 1186 free ( (char *)argv);1184 free (argv); 1187 1185 goto next_command; 1188 1186 } … … 1195 1193 #ifndef VMS 1196 1194 free (argv[0]); 1197 free ( (char *)argv);1195 free (argv); 1198 1196 #endif 1199 1197 goto next_command; … … 1506 1504 #ifndef VMS 1507 1505 free (argv[0]); 1508 free ( (char *)argv);1506 free (argv); 1509 1507 #endif 1510 1508 … … 1625 1623 new_job (struct file *file) 1626 1624 { 1627 registerstruct commands *cmds = file->cmds;1628 registerstruct child *c;1625 struct commands *cmds = file->cmds; 1626 struct child *c; 1629 1627 char **lines; 1630 registerunsigned int i;1628 unsigned int i; 1631 1629 1632 1630 /* Let any previously decided-upon jobs that are waiting … … 1641 1639 1642 1640 /* 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 *)); 1644 1642 for (i = 0; i < cmds->ncommand_lines; ++i) 1645 1643 { … … 1667 1665 we processed (where IN points) and the new chunk 1668 1666 we are about to process (where REF points). */ 1669 bcopy (in, out, ref - in);1667 memmove (out, in, ref - in); 1670 1668 1671 1669 /* Move both pointers past the boring stuff. */ … … 1745 1743 `struct child', and add that to the chain. */ 1746 1744 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)); 1749 1747 c->file = file; 1750 1748 c->command_lines = lines; … … 1866 1864 /* The job is now primed. Start it running. 1867 1865 (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); 1869 1876 1870 1877 #ifndef CONFIG_WITH_EXTENDED_NOTPARALLEL … … 2293 2300 # endif 2294 2301 2295 new_argv = (char **)alloca ((1 + argc + 1) * sizeof (char *));2302 new_argv = alloca ((1 + argc + 1) * sizeof (char *)); 2296 2303 new_argv[0] = shell; 2297 2304 … … 2486 2493 "shift", "switch", "test", "times", "trap", 2487 2494 "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; 2492 2505 char *end; 2493 2506 int instring, word_has_equals, seen_nonequals, last_argument_was_empty; … … 2521 2534 else if (strcmp (shell, default_shell)) 2522 2535 { 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 : "")); 2527 2540 2528 2541 if (s1) … … 2535 2548 #else /* not WINDOWS32 */ 2536 2549 #if defined (__MSDOS__) || defined (__EMX__) 2537 else if (str icmp (shell, default_shell))2550 else if (strcasecmp (shell, default_shell)) 2538 2551 { 2539 2552 extern int _is_unixy_shell (const char *_path); … … 2587 2600 2588 2601 /* More than 1 arg per character is impossible. */ 2589 new_argv = (char **)xmalloc (i * sizeof (char *));2602 new_argv = xmalloc (i * sizeof (char *)); 2590 2603 2591 2604 /* 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); 2593 2606 end = ap + i; 2594 2607 … … 2629 2642 *(ap++) = *p; 2630 2643 } 2631 /* If there's a TABhere, skip it. */2632 if (p[1] == '\t')2644 /* If there's a command prefix char here, skip it. */ 2645 if (p[1] == cmd_prefix) 2633 2646 ++p; 2634 2647 } … … 2679 2692 ++p; 2680 2693 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) 2683 2697 ++p; 2684 2698 … … 2807 2821 /* Line was empty. */ 2808 2822 free (argstr); 2809 free ( (char *)new_argv);2823 free (new_argv); 2810 2824 return 0; 2811 2825 } … … 2820 2834 /* Free the old argument list we were working on. */ 2821 2835 free (argstr); 2822 free ( (char *)new_argv);2836 free (new_argv); 2823 2837 } 2824 2838 … … 2833 2847 char *dptr; 2834 2848 2835 buffer = (char *)xmalloc (strlen (line)+1);2849 buffer = xmalloc (strlen (line)+1); 2836 2850 2837 2851 ptr = line; … … 2850 2864 *dptr = 0; 2851 2865 2852 new_argv = (char **)xmalloc (2 * sizeof (char *));2866 new_argv = xmalloc (2 * sizeof (char *)); 2853 2867 new_argv[0] = buffer; 2854 2868 new_argv[1] = 0; … … 2886 2900 unsigned int line_len = strlen (line); 2887 2901 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); 2890 2904 char *command_ptr = NULL; /* used for batch_mode_shell mode */ 2891 2905 … … 2896 2910 2897 2911 ap = new_line; 2898 bcopy (shell, ap, shell_len);2912 memcpy (ap, shell, shell_len); 2899 2913 ap += shell_len; 2900 bcopy (minus_c, ap, sizeof (minus_c) - 1);2914 memcpy (ap, minus_c, sizeof (minus_c) - 1); 2901 2915 ap += sizeof (minus_c) - 1; 2902 2916 command_ptr = ap; … … 2930 2944 2931 2945 ++p; 2932 if (p[1] == '\t')2946 if (p[1] == cmd_prefix) 2933 2947 ++p; 2934 2948 … … 2965 2979 /* Need to allocate new_argv, although it's unused, because 2966 2980 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 *)); 2968 2982 new_argv[0] = xstrdup (""); 2969 2983 new_argv[1] = NULL; … … 2992 3006 2993 3007 /* create argv */ 2994 new_argv = (char **)xmalloc(3 * sizeof (char *));3008 new_argv = xmalloc(3 * sizeof (char *)); 2995 3009 if (unixy_shell) { 2996 3010 new_argv[0] = xstrdup (shell); … … 3004 3018 #endif /* WINDOWS32 */ 3005 3019 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); 3009 3021 #ifdef __EMX__ 3010 3022 else if (!unixy_shell) … … 3023 3035 { 3024 3036 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++; 3027 3040 } 3028 3041 else … … 3064 3077 3065 3078 /* exactly 3 arguments + NULL */ 3066 new_argv = (char **)xmalloc (4 * sizeof (char *));3079 new_argv = xmalloc (4 * sizeof (char *)); 3067 3080 /* Exactly strlen(shell) + strlen("/c") + strlen(line) + 3 times 3068 3081 the trailing '\0' */ 3069 new_argv[0] = (char *)malloc (sh_len + line_len + 5);3082 new_argv[0] = xmalloc (sh_len + line_len + 5); 3070 3083 memcpy (new_argv[0], shell, sh_len + 1); 3071 3084 new_argv[1] = new_argv[0] + sh_len + 1; … … 3082 3095 instead of recursively calling ourselves, because we 3083 3096 cannot backslash-escape the special characters (see above). */ 3084 new_argv = (char **)xmalloc (sizeof (char *));3097 new_argv = xmalloc (sizeof (char *)); 3085 3098 line_len = strlen (new_line) - shell_len - sizeof (minus_c) + 1; 3086 3099 new_argv[0] = xmalloc (line_len + 1); … … 3140 3153 } 3141 3154 3142 argv = (char **)malloc (argc * sizeof (char *));3155 argv = xmalloc (argc * sizeof (char *)); 3143 3156 if (argv == 0) 3144 3157 abort (); -
trunk/src/gmakenew/job.h
r520 r903 71 71 extern struct child *children; 72 72 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));73 void new_job (struct file *file); 74 void reap_children (int block, int err); 75 void start_waiting_jobs (void); 76 76 77 extern char **construct_command_argv PARAMS ((char *line, char **restp, struct file *file, char** batch_file));77 char **construct_command_argv (char *line, char **restp, struct file *file, char** batch_file); 78 78 #ifdef VMS 79 extern int child_execute_job PARAMS ((char *argv, struct child *child));79 int child_execute_job (char *argv, struct child *child); 80 80 #elif defined(__EMX__) 81 extern int child_execute_job PARAMS ((int stdin_fd, int stdout_fd, char **argv, char **envp));81 int child_execute_job (int stdin_fd, int stdout_fd, char **argv, char **envp); 82 82 #else 83 extern void child_execute_job PARAMS ((int stdin_fd, int stdout_fd, char **argv, char **envp));83 void child_execute_job (int stdin_fd, int stdout_fd, char **argv, char **envp); 84 84 #endif 85 85 #ifdef _AMIGA 86 extern void exec_command PARAMS ((char **argv));86 void exec_command (char **argv); 87 87 #elif defined(__EMX__) 88 extern int exec_command PARAMS ((char **argv, char **envp));88 int exec_command (char **argv, char **envp); 89 89 #else 90 extern void exec_command PARAMS ((char **argv, char **envp));90 void exec_command (char **argv, char **envp); 91 91 #endif 92 92 93 93 extern unsigned int job_slots_used; 94 94 95 extern void block_sigs PARAMS ((void));95 void block_sigs (void); 96 96 #ifdef POSIX 97 extern void unblock_sigs PARAMS ((void));97 void unblock_sigs (void); 98 98 #else 99 99 #ifdef HAVE_SIGSETMASK -
trunk/src/gmakenew/kbuild.h
r813 r903 28 28 #define __kBuild_h__ 29 29 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));30 char *func_kbuild_source_tool(char *o, char **argv, const char *pszFuncName); 31 char *func_kbuild_object_base(char *o, char **argv, const char *pszFuncName); 32 char *func_kbuild_object_suffix(char *o, char **argv, const char *pszFuncName); 33 char *func_kbuild_source_prop(char *o, char **argv, const char *pszFuncName); 34 char *func_kbuild_source_one(char *o, char **argv, const char *pszFuncName); 35 35 36 36 #endif -
trunk/src/gmakenew/main.c
r877 r903 1 1 /* Argument parsing and main program of GNU Make. 2 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software 4 4 Foundation, Inc. 5 5 This file is part of GNU Make. … … 57 57 #endif 58 58 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)); 59 void init_dir (void); 60 void remote_setup (void); 61 void remote_cleanup (void); 62 RETSIGTYPE fatal_error_signal (int sig); 63 64 void print_variable_data_base (void); 65 void print_dir_data_base (void); 66 void print_rule_data_base (void); 67 void print_file_data_base (void); 68 void print_vpath_data_base (void); 69 70 void verify_file_data_base (void); 69 71 70 72 #if defined HAVE_WAITPID || defined HAVE_WAIT3 … … 72 74 #endif 73 75 74 #if !defined(HAVE_UNISTD_H) && !defined(_MSC_VER) 75 externint chdir ();76 #if !defined(HAVE_UNISTD_H) && !defined(_MSC_VER) /* bird */ 77 int chdir (); 76 78 #endif 77 79 #ifndef STDC_HEADERS 78 80 # ifndef sun /* Sun has an incorrect decl in a header. */ 79 extern void exit PARAMS ((int)) __attribute__ ((noreturn));81 void exit (int) __attribute__ ((noreturn)); 80 82 # endif 81 externdouble 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));83 double atof (); 84 #endif 85 86 static void clean_jobserver (int status); 87 static void print_data_base (void); 88 static void print_version (void); 89 static void decode_switches (int argc, char **argv, int env); 90 static void decode_env_switches (char *envar, unsigned int len); 91 static void define_makeflags (int all, int makefile); 92 static char *quote_for_env (char *out, const char *in); 93 static void initialize_global_hash_tables (void); 92 94 93 95 … … 104 106 flag_off, /* Turn int flag off. */ 105 107 string, /* One string per switch. */ 108 filename, /* A string containing a file name. */ 106 109 positive_int, /* A positive integer. */ 107 110 floating, /* A floating-point number (double). */ … … 109 112 } type; 110 113 111 char*value_ptr; /* Pointer to the value-holding variable. */114 void *value_ptr; /* Pointer to the value-holding variable. */ 112 115 113 116 unsigned int env:1; /* Can come from MAKEFLAGS. */ … … 115 118 unsigned int no_makefile:1; /* Don't propagate when remaking makefiles. */ 116 119 117 c har *noarg_value; /* Pointer to value used if no argument isgiven. */118 c har *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. */ 119 122 120 123 char *long_name; /* Long option name. */ … … 130 133 struct stringlist 131 134 { 132 c har **list; /* Nil-terminated list of strings. */135 const char **list; /* Nil-terminated list of strings. */ 133 136 unsigned int idx; /* Index into above. */ 134 137 unsigned int max; /* Number of pointers allocated. */ … … 164 167 165 168 int db_level = 0; 169 170 /* Output level (--verbosity). */ 171 172 static struct stringlist *verbosity_flags; 166 173 167 174 #ifdef WINDOWS32 … … 288 295 289 296 struct variable shell_var; 297 298 /* This character introduces a command: it's the first char on the line. */ 299 300 char cmd_prefix = '\t'; 290 301 291 302 #ifdef KMK … … 382 393 { 383 394 { '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" }, 388 399 #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, 398 407 "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" }, 405 413 #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" }, 409 416 #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" }, 416 421 { '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" }, 421 425 #ifdef CONFIG_PRETTY_COMMAND_PRINTING 422 426 { CHAR_MAX+6, flag, (char *) &pretty_command_printing, 1, 1, 1, 0, 0, … … 427 431 (char *) &process_priority, (char *) &process_priority, "priority" }, 428 432 #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, 433 436 "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, 442 446 "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, 445 449 "warn-undefined-variables" }, 446 450 { 0, 0, 0, 0, 0, 0, 0, 0, 0 } … … 588 592 } 589 593 590 static struct file*591 e nter_command_line_file (char *name)594 static const char * 595 expand_command_line_file (char *name) 592 596 { 597 const char *cp; 598 char *expanded = 0; 599 593 600 if (name[0] == '\0') 594 601 fatal (NILF, _("empty string invalid as file name")); … … 596 603 if (name[0] == '~') 597 604 { 598 char *expanded = tilde_expand (name);605 expanded = tilde_expand (name); 599 606 if (expanded != 0) 600 name = expanded; /* Memory leak; I don't care. */607 name = expanded; 601 608 } 602 609 … … 622 629 } 623 630 624 return enter_file (xstrdup (name)); 631 cp = strcache_add (name); 632 633 if (expanded) 634 free (expanded); 635 636 return cp; 625 637 } 626 638 … … 638 650 decode_debug_flags (void) 639 651 { 640 c har **pp;652 const char **pp; 641 653 642 654 if (debug_flag) … … 814 826 815 827 int 816 find_and_set_default_shell (c har *token)828 find_and_set_default_shell (const char *token) 817 829 { 818 830 int sh_found = 0; 831 char *atoken = 0; 819 832 char *search_token; 820 833 char *tokend; … … 825 838 search_token = default_shell; 826 839 else 827 search_token = token; 828 840 atoken = search_token = xstrdup (token); 829 841 830 842 /* If the user explicitly requests the DOS cmd shell, obey that request. … … 836 848 || (tokend > search_token 837 849 && (tokend[-1] == '/' || tokend[-1] == '\\'))) 838 && !strc mpi(tokend, "cmd"))850 && !strcasecmp (tokend, "cmd")) 839 851 || ((tokend - 4 == search_token 840 852 || (tokend - 4 > search_token 841 853 && (tokend[-5] == '/' || tokend[-5] == '\\'))) 842 && !strc mpi(tokend - 4, "cmd.exe"))) {854 && !strcasecmp (tokend - 4, "cmd.exe"))) { 843 855 batch_mode_shell = 1; 844 856 unixy_shell = 0; … … 852 864 /* no new information, path already set or known */ 853 865 sh_found = 1; 854 } else if (file_exists_p (search_token)) {866 } else if (file_exists_p (search_token)) { 855 867 /* 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)); 858 870 DB (DB_VERBOSE, 859 871 (_("find_and_set_shell setting default_shell = %s\n"), default_shell)); … … 868 880 869 881 p = v->value; 870 ep = strchr (p, PATH_SEPARATOR_CHAR);882 ep = strchr (p, PATH_SEPARATOR_CHAR); 871 883 872 884 while (ep && *ep) { 873 885 *ep = '\0'; 874 886 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)); 878 890 sh_found = 1; 879 891 *ep = PATH_SEPARATOR_CHAR; 880 892 881 893 /* terminate loop */ 882 p += strlen (p);894 p += strlen (p); 883 895 } else { 884 896 *ep = PATH_SEPARATOR_CHAR; … … 886 898 } 887 899 888 ep = strchr (p, PATH_SEPARATOR_CHAR);900 ep = strchr (p, PATH_SEPARATOR_CHAR); 889 901 } 890 902 891 903 /* 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)); 895 907 sh_found = 1; 896 908 } … … 916 928 /* naive test */ 917 929 if (!unixy_shell && sh_found && 918 (strstr (default_shell, "sh") || strstr(default_shell, "SH"))) {930 (strstr (default_shell, "sh") || strstr (default_shell, "SH"))) { 919 931 unixy_shell = 1; 920 932 batch_mode_shell = 0; … … 924 936 batch_mode_shell = 1; 925 937 #endif 938 939 if (atoken) 940 free (atoken); 926 941 927 942 return (sh_found); … … 995 1010 #endif /* WINDOWS32 */ 996 1011 997 #ifdef __MSDOS__ 998 1012 #ifdef __MSDOS__ 999 1013 static void 1000 1014 msdos_return_to_initial_directory (void) … … 1003 1017 chdir (directory_before_chdir); 1004 1018 } 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 */ 1022 char *mktemp (char *template); 1023 #endif 1024 int mkstemp (char *template); 1011 1025 1012 1026 FILE * … … 1061 1075 { 1062 1076 static char *stdin_nm = 0; 1063 struct file *f;1064 int i;1065 1077 int makefile_status = MAKE_SUCCESS; 1066 char **p;1067 1078 struct dep *read_makefiles; 1068 1079 PATH_VAR (current_directory); … … 1193 1204 # else /* setvbuf not reversed. */ 1194 1205 /* 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); 1196 1207 # endif /* setvbuf reversed. */ 1197 1208 #elif HAVE_SETLINEBUF … … 1301 1312 1302 1313 #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; 1310 1324 #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 } 1317 1369 } 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 } 1354 1371 #ifdef WINDOWS32 1355 1372 /* If we didn't find a correctly spelled PATH we define PATH as … … 1397 1414 #if 0 1398 1415 /* People write things like: 1399 1416 MFLAGS="CC=gcc -pipe" "CFLAGS=-g" 1400 1417 and we set the -p, -i and -e switches. Doesn't seem quite right. */ 1401 1418 decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS")); … … 1464 1481 && argv[0] != 0 1465 1482 && (argv[0][0] != '/' && (argv[0][0] == '\0' || argv[0][1] != ':')) 1466 # ifdef __EMX__1483 # ifdef __EMX__ 1467 1484 /* do not prepend cwd if argv[0] contains no '/', e.g. "make" */ 1468 1485 && (strchr (argv[0], '/') != 0 || strchr (argv[0], '\\') != 0) 1469 1486 # endif 1470 1487 ) 1471 argv[0] = concat (current_directory, "/", argv[0]);1488 argv[0] = xstrdup (concat (current_directory, "/", argv[0])); 1472 1489 #else /* !__MSDOS__ */ 1473 1490 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])); 1476 1498 #endif /* !__MSDOS__ */ 1477 1499 #endif /* WINDOWS32 */ … … 1507 1529 1508 1530 /* Now allocate a buffer big enough and fill it. */ 1509 p = value = (char *)alloca (len);1531 p = value = alloca (len); 1510 1532 for (cv = command_variables; cv != 0; cv = cv->next) 1511 1533 { … … 1590 1612 } 1591 1613 } 1592 #endif 1614 #endif /* KMK */ 1593 1615 1594 1616 /* If there were -C flags, move ourselves about. */ 1595 1617 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]; 1606 1623 #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); 1614 1635 } 1615 #endif 1616 if (chdir (dir) < 0) 1617 pfatal_with_name (dir); 1618 if (expanded) 1619 free (expanded); 1620 } 1636 } 1621 1637 1622 1638 #ifdef WINDOWS32 … … 1656 1672 /* Construct the list of include directories to search. */ 1657 1673 1658 construct_include_path (include_directories == 0 ? (char **) 01659 1674 construct_include_path (include_directories == 0 1675 ? 0 : include_directories->list); 1660 1676 1661 1677 /* Figure out where we are now, after chdir'ing. */ … … 1688 1704 if (makefiles != 0) 1689 1705 { 1690 registerunsigned int i;1706 unsigned int i; 1691 1707 for (i = 0; i < makefiles->idx; ++i) 1692 1708 if (makefiles->list[i][0] == '-' && makefiles->list[i][1] == '\0') … … 1721 1737 tmpdir = DEFAULT_TMPDIR; 1722 1738 1723 template = (char *) alloca (strlen (tmpdir) 1724 + sizeof (DEFAULT_TMPFILE) + 1); 1739 template = alloca (strlen (tmpdir) + sizeof (DEFAULT_TMPFILE) + 1); 1725 1740 strcpy (template, tmpdir); 1726 1741 … … 1746 1761 pfatal_with_name (_("fwrite (temporary file)")); 1747 1762 } 1748 (void)fclose (outfile);1763 fclose (outfile); 1749 1764 1750 1765 /* Replace the name that read_all_makefiles will 1751 1766 see with the name of the temporary file. */ 1752 makefiles->list[i] = xstrdup(stdin_nm);1767 makefiles->list[i] = strcache_add (stdin_nm); 1753 1768 1754 1769 /* 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 } 1763 1780 } 1764 1781 } 1765 1782 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) */ 1767 1784 #if defined(MAKE_JOBSERVER) || !defined(HAVE_WAIT_NOHANG) 1768 1785 /* Set up to handle children dying. This must be done before … … 1779 1796 If none of these are true, we don't need a signal handler at all. */ 1780 1797 { 1781 extern RETSIGTYPE child_handler PARAMS ((int sig));1798 RETSIGTYPE child_handler (int sig); 1782 1799 # if defined SIGCHLD 1783 1800 bsd_signal (SIGCHLD, child_handler); … … 1819 1836 define_default_variables (); 1820 1837 1821 default_file = enter_file ( ".DEFAULT");1838 default_file = enter_file (strcache_add (".DEFAULT")); 1822 1839 1823 1840 { … … 1829 1846 1830 1847 read_makefiles 1831 = read_all_makefiles (makefiles == 0 ? (char **)0 : makefiles->list);1848 = read_all_makefiles (makefiles == 0 ? 0 : makefiles->list); 1832 1849 1833 1850 #ifdef WINDOWS32 … … 1884 1901 if (jobserver_fds) 1885 1902 { 1886 c har *cp;1903 const char *cp; 1887 1904 unsigned int ui; 1888 1905 … … 1898 1915 fatal (NILF, 1899 1916 _("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])); 1900 1920 1901 1921 /* The combination of a pipe + !job_slots means we're using the … … 1940 1960 if (job_slots > 1) 1941 1961 { 1962 char *cp; 1942 1963 char c = '+'; 1943 1964 … … 1963 1984 /* Fill in the jobserver_fds struct for our children. */ 1964 1985 1986 cp = xmalloc ((sizeof ("1024")*2)+1); 1987 sprintf (cp, "%d,%d", job_fds[0], job_fds[1]); 1988 1965 1989 jobserver_fds = (struct stringlist *) 1966 1990 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; 1971 1993 jobserver_fds->idx = 1; 1972 1994 jobserver_fds->max = 1; … … 2018 2040 2019 2041 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 } 2028 2053 2029 2054 if (!restarts && new_files != 0) 2030 2055 { 2056 const char **p; 2031 2057 for (p = new_files->list; *p != 0; ++p) 2032 2058 { 2033 f = enter_command_line_file (*p);2059 struct file *f = enter_file (*p); 2034 2060 f->last_mtime = f->mtime_before_update = NEW_MTIME; 2035 2061 } … … 2063 2089 while (d != 0) 2064 2090 { 2065 registerstruct file *f = d->file;2091 struct file *f = d->file; 2066 2092 if (f->double_colon) 2067 2093 for (f = f->double_colon; f != NULL; f = f->prev) … … 2096 2122 if (f == NULL || !f->double_colon) 2097 2123 { 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)); 2101 2127 makefile_mtimes[mm_idx++] = file_mtime_no_search (d->file); 2102 2128 last = d; … … 2217 2243 char *p = &argv[i][2]; 2218 2244 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]; 2220 2247 else 2221 argv[i] = concat ("-f", makefiles->list[j], "");2248 argv[i] = xstrdup (concat ("-f", makefiles->list[j], "")); 2222 2249 ++j; 2223 2250 } … … 2227 2254 if (stdin_nm) 2228 2255 { 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, "")); 2232 2259 nargv[nargc] = 0; 2233 2260 } … … 2235 2262 if (directories != 0 && directories->idx > 0) 2236 2263 { 2237 char bad;2264 int bad = 1; 2238 2265 if (directory_before_chdir != 0) 2239 2266 { 2240 2267 if (chdir (directory_before_chdir) < 0) 2241 {2242 2268 perror_with_name ("chdir", ""); 2243 bad = 1;2244 }2245 2269 else 2246 2270 bad = 0; 2247 2271 } 2248 else2249 bad = 1;2250 2272 if (bad) 2251 2273 fatal (NILF, _("Couldn't change back to original directory.")); … … 2264 2286 2265 2287 #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 } 2288 2306 #else /* AMIGA */ 2289 2307 { … … 2351 2369 /* Free the makefile mtimes (if we allocated any). */ 2352 2370 if (makefile_mtimes) 2353 free ( (char *)makefile_mtimes);2371 free (makefile_mtimes); 2354 2372 } 2355 2373 … … 2363 2381 if (restarts && new_files != 0) 2364 2382 { 2383 const char **p; 2365 2384 for (p = new_files->list; *p != 0; ++p) 2366 2385 { 2367 f = enter_command_line_file (*p);2386 struct file *f = enter_file (*p); 2368 2387 f->last_mtime = f->mtime_before_update = NEW_MTIME; 2369 2388 } … … 2404 2423 fatal (NILF, _(".DEFAULT_GOAL contains more than one target")); 2405 2424 2406 default_goal_file = enter_file ( ns->name);2425 default_goal_file = enter_file (strcache_add (ns->name)); 2407 2426 2408 2427 ns->name = 0; /* It was reused by enter_file(). */ … … 2508 2527 2509 2528 case string: 2529 case filename: 2510 2530 case positive_int: 2511 2531 case floating: … … 2552 2572 2553 2573 if (! cv) { 2554 cv = (struct command_variable *)xmalloc (sizeof (*cv));2574 cv = xmalloc (sizeof (*cv)); 2555 2575 cv->variable = v; 2556 2576 cv->next = command_variables; … … 2563 2583 target! Enter it as a file and add it to the dep chain of 2564 2584 goals. */ 2565 struct file *f = enter_ command_line_file (arg);2585 struct file *f = enter_file (strcache_add (expand_command_line_file (arg))); 2566 2586 f->cmd_target = 1; 2567 2587 … … 2581 2601 { 2582 2602 /* Add this target name to the MAKECMDGOALS variable. */ 2583 struct variable * v;2584 c har *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) 2588 2608 value = f->name; 2589 2609 else … … 2591 2611 /* Paste the old and new values together */ 2592 2612 unsigned int oldlen, newlen; 2593 2594 oldlen = strlen (v->value); 2613 char *vp; 2614 2615 oldlen = strlen (gv->value); 2595 2616 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; 2600 2622 } 2601 2623 define_variable ("MAKECMDGOALS", 12, value, o_default, 0); … … 2629 2651 printf (_("\nThis program is built for %s/%s/%s (%s) [" __DATE__ " " __TIME__ "]\n"), 2630 2652 BUILD_PLATFORM, BUILD_PLATFORM_ARCH, BUILD_PLATFORM_CPU, remote_description); 2631 #else 2653 #else /* !KMK */ 2632 2654 if (!remote_description || *remote_description == '\0') 2633 2655 fprintf (usageto, _("\nThis program built for %s\n"), make_host); … … 2635 2657 fprintf (usageto, _("\nThis program built for %s (%s)\n"), 2636 2658 make_host, remote_description); 2637 #endif 2659 #endif /* !KMK */ 2638 2660 2639 2661 fprintf (usageto, _("Report bugs to <[email protected]>\n")); … … 2702 2724 2703 2725 case string: 2726 case filename: 2704 2727 if (!doit) 2705 2728 break; 2706 2729 2707 2730 if (optarg == 0) 2708 optarg = cs->noarg_value;2731 optarg = xstrdup (cs->noarg_value); 2709 2732 else if (*optarg == '\0') 2710 2733 { … … 2721 2744 sl->max = 5; 2722 2745 sl->idx = 0; 2723 sl->list = (char **)xmalloc (5 * sizeof (char *));2746 sl->list = xmalloc (5 * sizeof (char *)); 2724 2747 *(struct stringlist **) cs->value_ptr = sl; 2725 2748 } … … 2727 2750 { 2728 2751 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 *)); 2732 2754 } 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; 2734 2759 sl->list[sl->idx] = 0; 2735 2760 break; … … 2816 2841 decode_env_switches (char *envar, unsigned int len) 2817 2842 { 2818 char *varref = (char *)alloca (2 + len + 2);2843 char *varref = alloca (2 + len + 2); 2819 2844 char *value, *p; 2820 2845 int argc; … … 2824 2849 varref[0] = '$'; 2825 2850 varref[1] = '('; 2826 bcopy (envar, &varref[2], len);2851 memcpy (&varref[2], envar, len); 2827 2852 varref[2 + len] = ')'; 2828 2853 varref[2 + len + 1] = '\0'; … … 2836 2861 2837 2862 /* 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 *)); 2839 2864 2840 2865 /* Allocate a buffer to copy the value into while we split it into words 2841 2866 and unquote it. We must use permanent storage for this because 2842 2867 decode_switches may store pointers into the passed argument words. */ 2843 p = (char *)xmalloc (2 * len);2868 p = xmalloc (2 * len); 2844 2869 2845 2870 /* getopt will look at the arguments starting at ARGV[1]. … … 2872 2897 need permanent storage for this in case decode_switches saves 2873 2898 pointers into the value. */ 2874 argv[1] = concat ("-", argv[1], "");2899 argv[1] = xstrdup (concat ("-", argv[1], "")); 2875 2900 2876 2901 /* Parse those words. */ … … 2886 2911 2887 2912 static char * 2888 quote_for_env (char *out, c har *in)2913 quote_for_env (char *out, const char *in) 2889 2914 { 2890 2915 while (*in != '\0') … … 2924 2949 struct flag *next; 2925 2950 const struct command_switch *cs; 2926 c har *arg;2951 const char *arg; 2927 2952 }; 2928 2953 struct flag *flags = 0; … … 2930 2955 #define ADD_FLAG(ARG, LEN) \ 2931 2956 do { \ 2932 struct flag *new = (struct flag *) alloca (sizeof (struct flag));\2957 struct flag *new = alloca (sizeof (struct flag)); \ 2933 2958 new->cs = cs; \ 2934 2959 new->arg = (ARG); \ … … 2948 2973 switch (cs->type) 2949 2974 { 2950 default:2951 abort ();2952 2953 2975 case ignore: 2954 2976 break; … … 2980 3002 else 2981 3003 { 2982 char *buf = (char *)alloca (30);3004 char *buf = alloca (30); 2983 3005 sprintf (buf, "%u", *(unsigned int *) cs->value_ptr); 2984 3006 ADD_FLAG (buf, strlen (buf)); … … 3001 3023 else 3002 3024 { 3003 char *buf = (char *)alloca (100);3025 char *buf = alloca (100); 3004 3026 sprintf (buf, "%g", *(double *) cs->value_ptr); 3005 3027 ADD_FLAG (buf, strlen (buf)); … … 3009 3031 #endif 3010 3032 3033 case filename: 3011 3034 case string: 3012 3035 if (all) … … 3015 3038 if (sl != 0) 3016 3039 { 3017 /* Add the elements in reverse order, because 3018 all the flags get reversed below; and the order3019 matters for someswitches (like -I). */3020 registerunsigned 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; 3021 3044 while (i-- > 0) 3022 3045 ADD_FLAG (sl->list[i], strlen (sl->list[i])); … … 3024 3047 } 3025 3048 break; 3049 3050 default: 3051 abort (); 3026 3052 } 3027 3053 … … 3032 3058 /* Construct the value in FLAGSTRING. 3033 3059 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); 3036 3062 p = flagstring; 3037 3063 words = 1; … … 3125 3151 if (posix_pedantic) 3126 3152 { 3127 bcopy (posixref, p, sizeof posixref - 1);3153 memcpy (p, posixref, sizeof posixref - 1); 3128 3154 p += sizeof posixref - 1; 3129 3155 } 3130 3156 else 3131 3157 { 3132 bcopy (ref, p, sizeof ref - 1);3158 memcpy (p, ref, sizeof ref - 1); 3133 3159 p += sizeof ref - 1; 3134 3160 } … … 3342 3368 if (print_data_base_flag) 3343 3369 print_data_base (); 3370 3371 verify_file_data_base (); 3344 3372 3345 3373 clean_jobserver (status); -
trunk/src/gmakenew/make.1
r503 r903 165 165 over variables from makefiles. 166 166 .TP 0.5i 167 +\fB\-f\fR \fIfile\fR, \fB\-\-file\fR=\fIfile\fR, \fB\-\-makefile\fR=\fIFILE\fR167 \fB\-f\fR \fIfile\fR, \fB\-\-file\fR=\fIfile\fR, \fB\-\-makefile\fR=\fIFILE\fR 168 168 Use 169 169 .I file -
trunk/src/gmakenew/make.h
r803 r903 39 39 #endif 40 40 41 42 /* Use prototypes if available. */43 #if defined (__cplusplus) || defined (__STDC__) || defined WINDOWS32 /* bird: protos on windows */44 # undef PARAMS45 # define PARAMS(protos) protos46 #else /* Not C++ or ANSI C. */47 # undef PARAMS48 # define PARAMS(protos) ()49 #endif /* C++ or ANSI C. */50 41 51 42 /* Specify we want GNU source code. This must be defined before any … … 151 142 # define NEED_GET_PATH_MAX 1 152 143 # 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) 145 unsigned int get_path_max (void); 155 146 #endif 156 147 … … 228 219 # include <stdlib.h> 229 220 # 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));221 void *malloc (int); 222 void *realloc (void *, int); 223 void free (void *); 224 225 void abort (void) __attribute__ ((noreturn)); 226 void exit (int) __attribute__ ((noreturn)); 236 227 # endif /* HAVE_STDLIB_H. */ 237 228 … … 243 234 #endif 244 235 #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 276 240 277 241 /* SCO Xenix has a buggy macro definition in <string.h>. */ 278 242 #undef strerror 279 243 #if !defined(__DECC) 280 extern char *strerror PARAMS ((int errnum));244 char *strerror (int errnum); 281 245 #endif 282 246 … … 290 254 291 255 #if !defined(HAVE_STRSIGNAL) 292 extern char *strsignal PARAMS ((int signum));256 char *strsignal (int signum); 293 257 #endif 294 258 … … 309 273 (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1)))) 310 274 # ifdef HAVE_CASE_INSENSITIVE_FS 311 /* This is only used on Windows/DOS platforms, so we assume strcmpi(). */312 275 # define strieq(a, b) \ 313 276 ((a) == (b) \ 314 277 || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \ 315 && (*(a) == '\0' || !strc mpi((a) + 1, (b) + 1))))278 && (*(a) == '\0' || !strcasecmp ((a) + 1, (b) + 1)))) 316 279 # else 317 280 # define strieq(a, b) streq(a, b) … … 323 286 #endif 324 287 #define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0) 325 #ifdef VMS326 extern int strcmpi (const char *,const char *);327 #endif328 288 329 289 #if defined(__GNUC__) || defined(ENUM_BITFIELDS) … … 348 308 349 309 /* 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) 360 322 # include <direct.h> 361 323 #endif … … 364 326 # include <fcntl.h> 365 327 # 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 331 void sync_Path_environment (void); 332 int w32_kill (int pid, int sig); /* bird kill -> w32_kill - macro acquired () on the args. */ 333 char *end_of_token_w32 (const char *s, char stopchar); 334 int find_and_set_default_shell (const char *token); 373 335 374 336 /* indicates whether or not we have Bourne shell */ … … 400 362 401 363 #if HAVE_ANSI_COMPILER && USE_VARIADIC && HAVE_STDARG_H 402 externvoid message (int prefix, const char *fmt, ...)403 404 externvoid error (const struct floc *flocp, const char *fmt, ...)405 406 externvoid fatal (const struct floc *flocp, const char *fmt, ...)364 void message (int prefix, const char *fmt, ...) 365 __attribute__ ((__format__ (__printf__, 2, 3))); 366 void error (const struct floc *flocp, const char *fmt, ...) 367 __attribute__ ((__format__ (__printf__, 2, 3))); 368 void fatal (const struct floc *flocp, const char *fmt, ...) 407 369 __attribute__ ((noreturn, __format__ (__printf__, 2, 3))); 408 370 #else 409 externvoid message ();410 externvoid error ();411 externvoid 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 *));371 void message (); 372 void error (); 373 void fatal (); 374 #endif 375 376 void die (int) __attribute__ ((noreturn)); 377 void log_working_directory (int); 378 void pfatal_with_name (const char *) __attribute__ ((noreturn)); 379 void perror_with_name (const char *, const char *); 380 char *savestring (const char *, unsigned int); 381 char *concat (const char *, const char *, const char *); 382 void *xmalloc (unsigned int); 383 void *xrealloc (void *, unsigned int); 384 char *xstrdup (const char *); 385 char *find_next_token (const char **, unsigned int *); 386 char *next_token (const char *); 387 char *end_of_token (const char *); 388 void collapse_continuations (char *); 427 389 #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 392 char *lindex (const char *, const char *, int); 393 #endif 394 int alpha_compare (const void *, const void *); 395 void print_spaces (unsigned int); 396 char *find_percent (char *); 397 const char *find_percent_cached (const char **); 398 FILE *open_tmpfile (char **, const char *); 436 399 437 400 #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)); 401 int ar_name (const char *); 402 void ar_parse_name (const char *, char **, char **); 403 int ar_touch (const char *); 404 time_t ar_member_date (const char *); 405 406 typedef 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 411 long int ar_scan (const char *archive, ar_member_func_t function, const void *arg); 412 int ar_name_equal (const char *name, const char *mem, int truncated); 413 #ifndef VMS 414 int ar_member_touch (const char *arname, const char *memname); 415 #endif 416 #endif 417 418 int dir_file_exists_p (const char *, const char *); 419 int file_exists_p (const char *); 420 int file_impossible_p (const char *); 421 void file_impossible (const char *); 422 const char *dir_name (const char *); 423 void hash_init_directories (void); 424 425 void define_default_variables (void); 426 void set_default_suffixes (void); 427 void install_default_suffix_rules (void); 428 void install_default_implicit_rules (void); 429 430 void build_vpath_lists (void); 431 void construct_vpath_list (char *pattern, char *dirpath); 432 const char *vpath_search (const char *file, FILE_TIMESTAMP *mtime_ptr); 433 int gpath_search (const char *file, unsigned int len); 434 435 void construct_include_path (const char **arg_dirs); 436 437 void user_access (void); 438 void make_access (void); 439 void child_access (void); 440 441 void close_stdout (void); 442 443 char *strip_whitespace (const char **begpp, const char **endpp); 470 444 471 445 /* 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));446 void strcache_init (void); 447 void strcache_print_stats (const char *prefix); 448 int strcache_iscached (const char *str); 449 const char *strcache_add (const char *str); 450 const char *strcache_add_len (const char *str, int len); 451 int strcache_setbufsize (int size); 478 452 479 453 #ifdef HAVE_VFORK_H … … 486 460 #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32) 487 461 488 externlong int atol ();462 long int atol (); 489 463 # ifndef VMS 490 externlong int lseek ();464 long int lseek (); 491 465 # endif 492 466 … … 494 468 495 469 #ifdef HAVE_GETCWD 496 # if !defined(VMS) && !defined(__DECC) && !defined(_MSC_VER) 497 externchar *getcwd ();498 # endif 499 #else 500 externchar *getwd ();470 # if !defined(VMS) && !defined(__DECC) && !defined(_MSC_VER) /* bird: MSC */ 471 char *getcwd (); 472 # endif 473 #else 474 char *getwd (); 501 475 # 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 */ 485 int strcasecmp (const char *s1, const char *s2); 486 # endif 502 487 #endif 503 488 … … 505 490 extern const struct floc **expanding_var; 506 491 507 #if !defined(_MSC_VER) 492 #if !defined(_MSC_VER) /* bird */ 508 493 extern char **environ; 509 494 #endif … … 522 507 extern int batch_mode_shell; 523 508 509 extern char cmd_prefix; 510 524 511 extern unsigned int job_slots; 525 512 extern int job_fds[2]; … … 573 560 #endif 574 561 575 576 562 #ifdef __EMX__ 577 # if !HAVE_STRCASECMP578 # define strcasecmp stricmp579 # endif580 581 563 # if !defined chdir 582 564 # define chdir _chdir2 … … 617 599 to do it ourselves here. */ 618 600 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 621 604 622 605 #if defined(__EMX__) && defined(CONFIG_WITH_OPTIMIZATION_HACKS) /* bird: saves 40-100ms on libc. */ -
trunk/src/gmakenew/misc.c
r549 r903 172 172 173 173 174 /* Return a newly-allocated string whose contents175 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. */ 176 176 177 177 char * … … 179 179 { 180 180 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'; 196 199 197 200 return result; … … 351 354 #undef xstrdup 352 355 353 char*356 void * 354 357 xmalloc (unsigned int size) 355 358 { 356 359 /* 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); 358 361 if (result == 0) 359 362 fatal (NILF, _("virtual memory exhausted")); … … 362 365 363 366 364 char*365 xrealloc ( char*ptr, unsigned int size)366 { 367 char*result;367 void * 368 xrealloc (void *ptr, unsigned int size) 369 { 370 void *result; 368 371 369 372 /* Some older implementations of realloc() don't conform to ANSI. */ … … 385 388 result = strdup (ptr); 386 389 #else 387 result = (char *)malloc (strlen (ptr) + 1);390 result = malloc (strlen (ptr) + 1); 388 391 #endif 389 392 … … 394 397 return result; 395 398 #else 396 return strcpy (result, ptr);399 return strcpy (result, ptr); 397 400 #endif 398 401 } … … 403 406 savestring (const char *str, unsigned int length) 404 407 { 405 register char *out = (char *)xmalloc (length + 1);408 char *out = xmalloc (length + 1); 406 409 if (length > 0) 407 bcopy (str, out, length);410 memcpy (out, str, length); 408 411 out[length] = '\0'; 409 412 return out; … … 448 451 */ 449 452 char * 450 end_of_token_w32 (c har *s, char stopchar)451 { 452 registerchar *p = s;453 registerint backslash = 0;453 end_of_token_w32 (const char *s, char stopchar) 454 { 455 const char *p = s; 456 int backslash = 0; 454 457 455 458 while (*p != '\0' && *p != stopchar … … 469 472 } 470 473 471 return p;474 return (char *)p; 472 475 } 473 476 #endif … … 483 486 } 484 487 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. */ 487 491 488 492 char * 489 find_next_token (char **ptr, unsigned int *lengthptr) 490 { 491 char *p = next_token (*ptr); 492 char *end; 493 find_next_token (const char **ptr, unsigned int *lengthptr) 494 { 495 const char *p = next_token (*ptr); 493 496 494 497 if (*p == '\0') 495 498 return 0; 496 499 497 *ptr = end = end_of_token (p);500 *ptr = end_of_token (p); 498 501 if (lengthptr != 0) 499 *lengthptr = end - p; 500 return p; 502 *lengthptr = *ptr - p; 503 504 return (char *)p; 501 505 } 502 506 … … 508 512 alloc_dep () 509 513 { 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)); 512 516 return d; 513 517 } … … 519 523 free_dep (struct dep *d) 520 524 { 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); 528 526 } 529 527 … … 534 532 copy_dep_chain (const struct dep *d) 535 533 { 536 register struct dep *c;537 534 struct dep *firstnew = 0; 538 535 struct dep *lastnew = 0; … … 540 537 while (d != 0) 541 538 { 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)); 549 541 550 542 c->next = 0; … … 573 565 } 574 566 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 570 void 571 free_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 588 int 589 strcasecmp (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 } 605 606 } 606 607 #endif -
trunk/src/gmakenew/read.c
r530 r903 38 38 #include <pwd.h> 39 39 #else 40 struct passwd *getpwnam PARAMS ((char *name));40 struct passwd *getpwnam (char *name); 41 41 #endif 42 42 #endif … … 89 89 /* Default directories to search for include files in */ 90 90 91 static c har *default_include_directories[] =91 static const char *default_include_directories[] = 92 92 { 93 93 #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 "." 99 97 #endif 100 98 INCLUDEDIR, … … 109 107 /* List of directories to search for include files in */ 110 108 111 static c har **include_directories;109 static const char **include_directories; 112 110 113 111 /* Maximum length of an element of the above. */ … … 124 122 static struct dep *read_makefiles = 0; 125 123 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)); 124 static int eval_makefile (const char *filename, int flags); 125 static int eval (struct ebuffer *buffer, int flags); 126 127 static long readline (struct ebuffer *ebuf); 128 static void do_define (char *name, unsigned int namelen, 129 enum variable_origin origin, struct ebuffer *ebuf); 130 static int conditional_line (char *line, int len, const struct floc *flocp); 131 static 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); 136 static void record_target_var (struct nameseq *filenames, char *defn, 137 enum variable_origin origin, int enabled, 138 const struct floc *flocp); 139 static enum make_word_type get_next_mword (char *buffer, char *delim, 140 char **startp, unsigned int *length); 141 static void remove_comments (char *line); 142 static char *find_char_unquote (char *string, int stop1, int stop2, 143 int blank, int ignorevars); 147 144 148 145 … … 150 147 151 148 struct dep * 152 read_all_makefiles (c har **makefiles)149 read_all_makefiles (const char **makefiles) 153 150 { 154 151 unsigned int num_makefiles = 0; … … 184 181 p = value; 185 182 186 while ((name = find_next_token ( &p, &length)) != 0)183 while ((name = find_next_token ((const char **)&p, &length)) != 0) 187 184 { 188 185 if (*p != '\0') … … 227 224 # else 228 225 { "makefile.vms", "gnumakefile.", "makefile.", 0 }; 229 # endif 226 # endif 230 227 #else 231 228 #ifdef _AMIGA … … 264 261 { 265 262 struct dep *d = alloc_dep (); 266 d->file = enter_file ( *p);263 d->file = enter_file (strcache_add (*p)); 267 264 d->file->dontcare = 1; 268 265 /* Tell update_goal_chain to bail out as soon as this file is … … 291 288 struct conditionals *save = conditionals; 292 289 293 bzero ((char *) new, sizeof (*new));290 memset (new, '\0', sizeof (*new)); 294 291 conditionals = new; 295 292 … … 314 311 315 312 static int 316 eval_makefile (c har *filename, int flags)313 eval_makefile (const char *filename, int flags) 317 314 { 318 315 struct dep *deps; … … 320 317 const struct floc *curfile; 321 318 char *expanded = 0; 322 char *included = 0;323 319 int makefile_errno; 324 320 int r; 325 321 326 ebuf.floc.filenm = strcache_add (filename); 322 filename = strcache_add (filename); 323 ebuf.floc.filenm = filename; 327 324 ebuf.floc.lineno = 1; 328 325 … … 361 358 if (ebuf.fp == 0 && (flags & RM_INCLUDED) && *filename != '/') 362 359 { 363 registerunsigned int i;360 unsigned int i; 364 361 for (i = 0; include_directories[i] != 0; ++i) 365 362 { 366 included = concat (include_directories[i], "/", filename);363 const char *included = concat (include_directories[i], "/", filename); 367 364 ebuf.fp = fopen (included, "r"); 368 365 if (ebuf.fp) 369 366 { 370 filename = included;367 filename = strcache_add (included); 371 368 break; 372 369 } 373 free (included);374 370 } 375 /* If we're not using it, we already freed it above. */376 if (filename != included)377 included = 0;378 371 } 379 372 … … 384 377 deps->file = lookup_file (filename); 385 378 if (deps->file == 0) 386 deps->file = enter_file ( xstrdup (filename));379 deps->file = enter_file (filename); 387 380 filename = deps->file->name; 388 381 deps->changed = flags; … … 392 385 if (expanded) 393 386 free (expanded); 394 if (included)395 free (included);396 387 397 388 /* If the makefile can't be found at all, give up entirely. */ … … 463 454 #ifdef CONFIG_WITH_INCLUDEDEP 464 455 /* no nonsense dependency file including. */ 465 void 466 eval_include_dep (char *name, struct floc *f)456 void 457 eval_include_dep (const char *name, struct floc *f) 467 458 { 468 459 FILE *fp; … … 501 492 } 502 493 503 /* allocate a buffer and read the file. \r\n -> \n conversion 494 /* allocate a buffer and read the file. \r\n -> \n conversion 504 495 make this intersting ... */ 505 496 buf = xmalloc (max_size + 1); … … 544 535 long nlines = 0; 545 536 int two_colon = 0; 546 char *pattern = 0, *pattern_percent; 537 const char *pattern = 0; 538 const char *pattern_percent; 547 539 struct floc *fstart; 548 540 struct floc fi; … … 561 553 commands_idx = 0; \ 562 554 no_targets = 0; \ 563 if (pattern) { free(pattern); pattern = 0; }\555 pattern = 0; \ 564 556 } while (0) 565 557 … … 586 578 unsigned int linelen; 587 579 char *line; 588 intlen;580 unsigned int wlen; 589 581 char *p; 590 582 char *p2; … … 607 599 /* Check for a shell command line first. 608 600 If it is not one, we can stop treating tab specially. */ 609 if (line[0] == '\t')601 if (line[0] == cmd_prefix) 610 602 { 611 603 if (no_targets) … … 632 624 commands = xrealloc (commands, commands_len); 633 625 } 634 bcopy (line, &commands[commands_idx], linelen);626 memcpy (&commands[commands_idx], line, linelen); 635 627 commands_idx += linelen; 636 628 commands[commands_idx++] = '\n'; … … 648 640 collapsed_length = linelen+1; 649 641 if (collapsed) 650 free ( (char *)collapsed);651 collapsed = (char *)xmalloc (collapsed_length);642 free (collapsed); 643 collapsed = xmalloc (collapsed_length); 652 644 } 653 645 strcpy (collapsed, line); … … 657 649 658 650 /* 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)) 660 652 p = collapsed; 661 653 while (isspace ((unsigned char)*p)) … … 672 664 for (p2 = p+1; *p2 != '\0' && !isspace ((unsigned char)*p2); ++p2) 673 665 ; 674 len = p2 - p;666 wlen = p2 - p; 675 667 676 668 /* Find the start of the second token. If it looks like a target or … … 695 687 if (!in_ignored_define) 696 688 { 697 int i = conditional_line (p, len, fstart);689 int i = conditional_line (p, wlen, fstart); 698 690 if (i != -2) 699 691 { … … 787 779 else 788 780 { 789 unsigned int len; 781 unsigned int l; 782 const char *cp; 790 783 char *ap; 791 784 792 785 /* Expand the line so we can use indirect and constructed 793 786 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)) 798 791 { 799 v = lookup_variable (p, l en);792 v = lookup_variable (p, l); 800 793 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); 803 795 v->export = v_export; 804 796 } … … 816 808 else 817 809 { 818 unsigned int l en;810 unsigned int l; 819 811 struct variable *v; 812 const char *cp; 820 813 char *ap; 821 814 822 815 /* Expand the line so we can use indirect and constructed 823 816 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)) 828 821 { 829 v = lookup_variable (p, l en);822 v = lookup_variable (p, l); 830 823 if (v == 0) 831 v = define_variable_loc (p, l en, "", o_file, 0, fstart);824 v = define_variable_loc (p, l, "", o_file, 0, fstart); 832 825 833 826 v->export = v_noexport; … … 842 835 if (word1eq ("vpath")) 843 836 { 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); 848 842 if (p != 0) 849 843 { 850 pattern = savestring (p, len);851 p = find_next_token (& p2, &len);844 vpat = savestring (p, l); 845 p = find_next_token (&cp, &l); 852 846 /* No searchpath means remove all previous 853 847 selective VPATH's with the same pattern. */ … … 855 849 else 856 850 /* 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); 861 855 862 856 goto rule_complete; … … 926 920 { 927 921 struct nameseq *next = files->next; 928 c har *name = files->name;922 const char *name = files->name; 929 923 int r; 930 924 931 free ( (char *)files);925 free (files); 932 926 files = next; 933 927 … … 936 930 if (!r && !noerror) 937 931 error (fstart, "%s: %s", name, strerror (errno)); 938 free (name);939 932 } 940 933 … … 952 945 was no preceding target, and the line might have been usable as a 953 946 variable definition. But now we know it is definitely lossage. */ 954 if (line[0] == '\t')947 if (line[0] == cmd_prefix) 955 948 fatal(fstart, _("commands commence before first target")); 956 949 … … 970 963 int exported; 971 964 char *cmdleft, *semip, *lb_next; 972 unsigned int len,plen = 0;965 unsigned int plen = 0; 973 966 char *colonp; 974 967 const char *end, *beg; /* Helpers for whitespace stripping. */ … … 999 992 beginning, expanding as we go, and looking for "interesting" 1000 993 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); 1002 995 switch (wtype) 1003 996 { … … 1020 1013 } 1021 1014 1022 p2 = variable_expand_string(NULL, lb_next, len);1015 p2 = variable_expand_string(NULL, lb_next, wlen); 1023 1016 1024 1017 while (1) 1025 1018 { 1026 lb_next += len;1019 lb_next += wlen; 1027 1020 if (cmdleft == 0) 1028 1021 { … … 1069 1062 break; 1070 1063 1071 wtype = get_next_mword(lb_next, NULL, &lb_next, & len);1064 wtype = get_next_mword(lb_next, NULL, &lb_next, &wlen); 1072 1065 if (wtype == w_eol) 1073 1066 break; … … 1075 1068 p2 += strlen(p2); 1076 1069 *(p2++) = ' '; 1077 p2 = variable_expand_string(p2, lb_next, len);1070 p2 = variable_expand_string(p2, lb_next, wlen); 1078 1071 /* We don't need to worry about cmdleft here, because if it was 1079 1072 found in the variable_buffer the entire buffer has already … … 1130 1123 unsigned int l = p2 - variable_buffer; 1131 1124 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); 1134 1126 p2 = variable_buffer + l; 1135 1127 } … … 1138 1130 comes after it looks like a variable definition. */ 1139 1131 1140 wtype = get_next_mword (p2, NULL, &p, & len);1132 wtype = get_next_mword (p2, NULL, &p, &wlen); 1141 1133 1142 1134 v_origin = o_file; … … 1147 1139 { 1148 1140 v_origin = o_override; 1149 wtype = get_next_mword (p+ len, NULL, &p, &len);1141 wtype = get_next_mword (p+wlen, NULL, &p, &wlen); 1150 1142 } 1151 1143 else if (word1eq ("export")) 1152 1144 { 1153 1145 exported = 1; 1154 wtype = get_next_mword (p+ len, NULL, &p, &len);1146 wtype = get_next_mword (p+wlen, NULL, &p, &wlen); 1155 1147 } 1156 1148 } 1157 1149 1158 1150 if (wtype != w_eol) 1159 wtype = get_next_mword (p+ len, NULL, NULL, NULL);1151 wtype = get_next_mword (p+wlen, NULL, NULL, NULL); 1160 1152 1161 1153 if (wtype == w_varassign) … … 1232 1224 { 1233 1225 int check_again; 1234 1235 1226 do { 1236 1227 check_again = 0; … … 1254 1245 else if (target->next != 0) 1255 1246 fatal (fstart, _("multiple target patterns (target `%s')"), target->name); /* bird */ 1247 pattern_percent = find_percent_cached (&target->name); 1256 1248 pattern = target->name; 1257 pattern_percent = find_percent (pattern);1258 1249 if (pattern_percent == 0) 1259 1250 fatal (fstart, _("target pattern contains no `%%' (target `%s')"), target->name); /* bird */ 1260 free ( (char *)target);1251 free (target); 1261 1252 } 1262 1253 else … … 1272 1263 /* Put all the prerequisites here; they'll be parsed later. */ 1273 1264 deps = alloc_dep (); 1274 deps->name = s avestring(beg, end - beg + 1);1265 deps->name = strcache_add_len (beg, end - beg + 1); 1275 1266 } 1276 1267 else … … 1281 1272 { 1282 1273 /* Semicolon means rest of line is a command. */ 1283 unsigned int l en= strlen (cmdleft);1274 unsigned int l = strlen (cmdleft); 1284 1275 1285 1276 cmds_started = fstart->lineno; 1286 1277 1287 1278 /* Add this command line to the buffer. */ 1288 if (l en+ 2 > commands_len)1279 if (l + 2 > commands_len) 1289 1280 { 1290 commands_len = (l en+ 2) * 2;1291 commands = (char *)xrealloc (commands, commands_len);1281 commands_len = (l + 2) * 2; 1282 commands = xrealloc (commands, commands_len); 1292 1283 } 1293 bcopy (cmdleft, commands, len);1294 commands_idx += l en;1284 memcpy (commands, cmdleft, l); 1285 commands_idx += l; 1295 1286 commands[commands_idx++] = '\n'; 1296 1287 } … … 1314 1305 if (**default_goal_name == '\0' && set_default) 1315 1306 { 1316 c har*name;1307 const char *name; 1317 1308 struct dep *d; 1318 1309 struct nameseq *t = filenames; … … 1349 1340 for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next) 1350 1341 { 1351 register unsigned int len= strlen (dep_name (d2));1352 if (!strneq (name, dep_name (d2), l en))1342 unsigned int l = strlen (dep_name (d2)); 1343 if (!strneq (name, dep_name (d2), l)) 1353 1344 continue; 1354 if (streq (name + l en, dep_name (d)))1345 if (streq (name + l, dep_name (d))) 1355 1346 { 1356 1347 reject = 1; … … 1391 1382 1392 1383 if (collapsed) 1393 free ( (char *)collapsed);1394 free ( (char *)commands);1384 free (collapsed); 1385 free (commands); 1395 1386 1396 1387 return 1; … … 1426 1417 int nlevels = 1; 1427 1418 unsigned int length = 100; 1428 char *definition = (char *)xmalloc (length);1419 char *definition = xmalloc (length); 1429 1420 unsigned int idx = 0; 1430 1421 char *p; 1431 1422 1432 1423 /* 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); 1435 1426 var[namelen] = '\0'; 1436 1427 var = variable_expand (var); … … 1458 1449 1459 1450 /* Stop if we find an 'endef' */ 1460 if (line[0] != '\t')1451 if (line[0] != cmd_prefix) 1461 1452 { 1462 1453 p = next_token (line); … … 1501 1492 { 1502 1493 length = (idx + len) * 2; 1503 definition = (char *)xrealloc (definition, length + 1);1494 definition = xrealloc (definition, length + 1); 1504 1495 } 1505 1496 1506 bcopy (line, &definition[idx], len);1497 memcpy (&definition[idx], line, len); 1507 1498 idx += len; 1508 1499 /* Separate lines with a newline. */ … … 1632 1623 { 1633 1624 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); 1636 1627 } 1637 1628 … … 1640 1631 { 1641 1632 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); 1646 1637 } 1647 1638 … … 1687 1678 else 1688 1679 { 1689 /* " Ifeq" or "ifneq". */1680 /* "ifeq" or "ifneq". */ 1690 1681 char *s1, *s2; 1691 unsigned int l en;1682 unsigned int l; 1692 1683 char termin = *line == '(' ? ',' : *line; 1693 1684 … … 1729 1720 /* We must allocate a new copy of the expanded string because 1730 1721 variable_expand re-uses the same buffer. */ 1731 l en= 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); 1734 1725 1735 1726 if (termin != ',') … … 1744 1735 if (termin == ')') 1745 1736 { 1746 registerint count = 0;1737 int count = 0; 1747 1738 s2 = next_token (line); 1748 1739 for (line = s2; *line != '\0'; ++line) … … 1879 1870 { 1880 1871 struct variable *v; 1881 registerchar *name = filenames->name;1882 c har *fname;1883 c har *percent;1872 const char *name = filenames->name; 1873 const char *fname; 1874 const char *percent; 1884 1875 struct pattern_var *p; 1885 1876 1886 1877 nextf = filenames->next; 1887 free ( (char *)filenames);1878 free (filenames); 1888 1879 1889 1880 /* If it's a pattern target, then add it to the pattern-specific 1890 1881 variable list. */ 1891 percent = find_percent (name);1882 percent = find_percent_cached (&name); 1892 1883 if (percent) 1893 1884 { … … 1917 1908 f = lookup_file (name); 1918 1909 if (!f) 1919 f = enter_file ( name);1910 f = enter_file (strcache_add (name)); 1920 1911 else if (f->double_colon) 1921 1912 f = f->double_colon; … … 1954 1945 } 1955 1946 } 1956 1957 /* Free name if not needed further. */1958 if (name != fname && (name < fname || name > fname + strlen (fname)))1959 free (name);1960 1947 } 1961 1948 } … … 1974 1961 1975 1962 static void 1976 record_files (struct nameseq *filenames, char *pattern, char *pattern_percent, 1977 struct dep *deps, unsigned int cmds_started, char *commands, 1963 record_files (struct nameseq *filenames, const char *pattern, 1964 const char *pattern_percent, struct dep *deps, 1965 unsigned int cmds_started, char *commands, 1978 1966 unsigned int commands_idx, int two_colon, 1979 1967 const struct floc *flocp) … … 1982 1970 int implicit = 0; 1983 1971 unsigned int max_targets = 0, target_idx = 0; 1984 c har **targets = 0, **target_percents = 0;1972 const char **targets = 0, **target_percents = 0; 1985 1973 struct commands *cmds; 1986 1974 … … 1994 1982 if (commands_idx > 0) 1995 1983 { 1996 cmds = (struct commands *)xmalloc (sizeof (struct commands));1984 cmds = xmalloc (sizeof (struct commands)); 1997 1985 cmds->fileinfo.filenm = flocp->filenm; 1998 1986 cmds->fileinfo.lineno = cmds_started; … … 2005 1993 for (; filenames != 0; filenames = nextf) 2006 1994 { 2007 c har *name = filenames->name;1995 const char *name = filenames->name; 2008 1996 struct file *f; 2009 1997 struct dep *this = 0; 2010 c har *implicit_percent;1998 const char *implicit_percent; 2011 1999 2012 2000 nextf = filenames->next; … … 2021 2009 second_expansion = 1; 2022 2010 2023 implicit_percent = find_percent (name);2011 implicit_percent = find_percent_cached (&name); 2024 2012 implicit |= implicit_percent != 0; 2025 2013 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 2032 2014 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 2034 2022 if (targets == 0) 2035 2023 { 2036 2024 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 *)); 2039 2027 target_idx = 0; 2040 2028 } … … 2042 2030 { 2043 2031 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 *)); 2049 2035 } 2050 2036 targets[target_idx] = name; … … 2073 2059 /* Single-colon. Combine these dependencies 2074 2060 with others in file's existing record, if any. */ 2075 f = enter_file ( name);2061 f = enter_file (strcache_add (name)); 2076 2062 2077 2063 if (f->double_colon) … … 2179 2165 fatal (flocp, 2180 2166 _("target file `%s' has both : and :: entries"), f->name); 2181 f = enter_file ( name);2167 f = enter_file (strcache_add (name)); 2182 2168 /* If there was an existing entry and it was a double-colon entry, 2183 2169 enter_file will have returned a new one, making it the prev … … 2198 2184 if (pattern) 2199 2185 { 2200 static c har *percent = "%";2186 static const char *percent = "%"; 2201 2187 char *buffer = variable_expand (""); 2202 char *o = patsubst_expand (buffer, name, pattern, percent,2203 pattern_percent+1, percent+1);2204 f->stem = s avestring(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); 2205 2191 if (this) 2206 2192 { 2207 2193 this->staticpattern = 1; 2208 this->stem = xstrdup (f->stem);2194 this->stem = f->stem; 2209 2195 } 2210 2196 } 2211 2197 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; 2219 2199 2220 2200 /* If this target is a default target, update DEFAULT_GOAL_FILE. */ … … 2227 2207 if (implicit) 2228 2208 { 2229 targets[target_idx] = 0;2230 target_percents[target_idx] = 0;2231 2209 if (deps) 2232 2210 deps->need_2nd_expansion = second_expansion; 2233 create_pattern_rule (targets, target_percents, t wo_colon, deps, cmds, 1);2234 free ((char *) target_percents);2211 create_pattern_rule (targets, target_percents, target_idx, 2212 two_colon, deps, cmds, 1); 2235 2213 } 2236 2214 } … … 2251 2229 { 2252 2230 unsigned int string_len = 0; 2253 registerchar *p = string;2231 char *p = string; 2254 2232 register int ch; /* bird: 'optimiziations' */ 2255 2233 … … 2311 2289 { 2312 2290 /* Search for more backslashes. */ 2313 registerint i = -2;2291 int i = -2; 2314 2292 while (&p[i] >= string && p[i] == '\\') 2315 2293 --i; … … 2320 2298 /* The number of backslashes is now -I. 2321 2299 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; 2324 2302 if (i % 2 == 0) 2325 2303 /* All the backslashes quoted each other; the STOPCHAR was … … 2338 2316 } 2339 2317 2340 /* Search PATTERN for an unquoted % . */2318 /* Search PATTERN for an unquoted % and handle quoting. */ 2341 2319 2342 2320 char * … … 2344 2322 { 2345 2323 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 2332 const char * 2333 find_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; 2346 2400 } 2347 2401 … … 2367 2421 #ifndef NO_ARCHIVES /* bird: MSC warning */ 2368 2422 struct nameseq *lastnew1; 2369 #endif 2423 #endif 2370 2424 char *p = *stringp; 2371 char *q;2372 char *name;2373 2425 2374 2426 #ifdef VMS … … 2380 2432 while (1) 2381 2433 { 2434 const char *name; 2435 char *q; 2436 2382 2437 /* Skip whitespace; see if any more names are left. */ 2383 2438 p = next_token (p); … … 2387 2442 break; 2388 2443 2389 /* Yes, find end ofnext name. */2444 /* There are, so find the end of the next name. */ 2390 2445 q = p; 2391 2446 p = find_char_unquote (q, stopchar, VMS_COMMA, 1, 0); … … 2399 2454 && !(isspace ((unsigned char)p[1]) || !p[1] 2400 2455 || isspace ((unsigned char)p[-1]))) 2401 {2402 2456 p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0); 2403 }2404 2457 #endif 2405 2458 #ifdef HAVE_DOS_PATHS … … 2435 2488 if (q == p) 2436 2489 /* ".///" was stripped to "". */ 2437 #if def VMS2490 #if defined(VMS) 2438 2491 continue; 2492 #elif defined(_AMIGA) 2493 name = ""; 2439 2494 #else 2440 #ifdef _AMIGA 2441 name = savestring ("", 0); 2442 #else 2443 name = savestring ("./", 2); 2444 #endif 2495 name = "./"; 2445 2496 #endif 2446 2497 else … … 2466 2517 *q2++ = *q1++; 2467 2518 } 2468 name = s avestring(qbase, p1 - qbase);2519 name = strcache_add_len (qbase, p1 - qbase); 2469 2520 free (qbase); 2470 2521 } 2471 2522 #else 2472 name = s avestring(q, p - q);2523 name = strcache_add_len (q, p - q); 2473 2524 #endif 2474 2525 2475 2526 /* Add it to the front of the chain. */ 2476 new1 = (struct nameseq *)xmalloc (size);2527 new1 = xmalloc (size); 2477 2528 new1->name = name; 2478 2529 new1->next = new; … … 2517 2568 /* Copy "lib(" into LIBNAME. */ 2518 2569 ++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); 2521 2572 libname[paren - n->name] = '\0'; 2522 2573 … … 2526 2577 Edit it out of the chain and free its storage. */ 2527 2578 lastn->next = n->next; 2528 free (n->name); 2529 free ((char *) n); 2579 free (n); 2530 2580 /* LASTN->next is the new stopping elt for the loop below. */ 2531 2581 n = lastn->next; … … 2534 2584 { 2535 2585 /* 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, ")")); 2539 2587 } 2540 2588 … … 2549 2597 lastn = new1; 2550 2598 new1 = new1->next; 2551 free (lastn->name); 2552 free ((char *) lastn); 2599 free (lastn); 2553 2600 } 2554 2601 else 2555 2602 { 2556 2603 /* 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, "")); 2560 2605 new1 = new1->next; 2561 2606 } … … 2567 2612 while (new1 != n) 2568 2613 { 2569 name = concat (libname, new1->name, ")"); 2570 free (new1->name); 2571 new1->name = name; 2614 new1->name = strcache_add (concat (libname, new1->name, ")")); 2572 2615 lastnew1 = new1; 2573 2616 new1 = new1->next; … … 2737 2780 unsigned long off = p - start; 2738 2781 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); 2741 2783 p = start + off; 2742 2784 end = start + ebuf->size; … … 2941 2983 2942 2984 void 2943 construct_include_path (c har **arg_dirs)2985 construct_include_path (const char **arg_dirs) 2944 2986 { 2945 register unsigned int i;2946 2987 #ifdef VAXC /* just don't ask ... */ 2947 2988 stat_t stbuf; … … 2949 2990 struct stat stbuf; 2950 2991 #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; 2958 3001 2959 3002 #ifdef __MSDOS__ 2960 defsize++; 3003 /* Add one for $DJDIR. */ 3004 ++idx; 2961 3005 #endif 2962 3006 3007 dirs = xmalloc (idx * sizeof (const char *)); 3008 3009 idx = 0; 3010 max_incl_len = 0; 3011 2963 3012 /* 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) 2967 3016 while (*arg_dirs != 0) 2968 3017 { 2969 char *dir = *arg_dirs++; 3018 const char *dir = *(arg_dirs++); 3019 char *expanded = 0; 2970 3020 int e; 2971 3021 2972 3022 if (dir[0] == '~') 2973 3023 { 2974 char *expanded = tilde_expand (dir);3024 expanded = tilde_expand (dir); 2975 3025 if (expanded != 0) 2976 3026 dir = expanded; … … 2979 3029 EINTRLOOP (e, stat (dir, &stbuf)); 2980 3030 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); 2992 3043 } 2993 3044 2994 /* Now add at the end the standard default dirs. */3045 /* Now add the standard default dirs at the end. */ 2995 3046 2996 3047 #ifdef __MSDOS__ 2997 3048 { 2998 /* The environment variable $DJDIR holds the root of the 2999 DJGPP directorytree; add ${DJDIR}/include. */3049 /* The environment variable $DJDIR holds the root of the DJGPP directory 3050 tree; add ${DJDIR}/include. */ 3000 3051 struct variable *djdir = lookup_variable ("DJDIR", 5); 3001 3052 3002 3053 if (djdir) 3003 3054 { 3004 char *defdir = (char *) xmalloc (strlen (djdir->value) + 8 + 1); 3055 unsigned int len = strlen (djdir->value) + 8; 3056 char *defdir = alloca (len + 1); 3005 3057 3006 3058 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; 3008 3063 } 3009 3064 } 3010 3065 #endif 3011 3066 3012 for ( i = 0; default_include_directories[i] != 0; ++i)3067 for (cpp = default_include_directories; *cpp != 0; ++cpp) 3013 3068 { 3014 3069 int e; 3015 3070 3016 EINTRLOOP (e, stat ( default_include_directories[i], &stbuf));3071 EINTRLOOP (e, stat (*cpp, &stbuf)); 3017 3072 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 } 3019 3082 } 3020 3083 3021 3084 dirs[idx] = 0; 3022 3085 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); 3042 3091 3043 3092 include_directories = dirs; … … 3049 3098 3050 3099 char * 3051 tilde_expand (c har *name)3100 tilde_expand (const char *name) 3052 3101 { 3053 3102 #ifndef VMS … … 3074 3123 home_dir = getenv ("HOME"); 3075 3124 } 3076 # if !defined(_AMIGA) && !defined(WINDOWS32)3125 # if !defined(_AMIGA) && !defined(WINDOWS32) 3077 3126 if (home_dir == 0 || home_dir[0] == '\0') 3078 3127 { … … 3087 3136 } 3088 3137 } 3089 # endif /* !AMIGA && !WINDOWS32 */3138 # endif /* !AMIGA && !WINDOWS32 */ 3090 3139 if (home_dir != 0) 3091 3140 { 3092 char *new = concat (home_dir, "", name + 1);3141 char *new = xstrdup (concat (home_dir, "", name + 1)); 3093 3142 if (is_variable) 3094 3143 free (home_dir); … … 3096 3145 } 3097 3146 } 3098 # if !defined(_AMIGA) && !defined(WINDOWS32)3147 # if !defined(_AMIGA) && !defined(WINDOWS32) 3099 3148 else 3100 3149 { … … 3109 3158 return xstrdup (pwent->pw_dir); 3110 3159 else 3111 return concat (pwent->pw_dir, "/", userend + 1);3160 return xstrdup (concat (pwent->pw_dir, "/", userend + 1)); 3112 3161 } 3113 3162 else if (userend != 0) 3114 3163 *userend = '/'; 3115 3164 } 3116 # endif /* !AMIGA && !WINDOWS32 */3165 # endif /* !AMIGA && !WINDOWS32 */ 3117 3166 #endif /* !VMS */ 3118 3167 return 0; … … 3132 3181 multi_glob (struct nameseq *chain, unsigned int size) 3133 3182 { 3134 extern void dir_setup_glob ();3135 registerstruct nameseq *new = 0;3136 registerstruct nameseq *old;3183 void dir_setup_glob (glob_t *); 3184 struct nameseq *new = 0; 3185 struct nameseq *old; 3137 3186 struct nameseq *nexto; 3138 3187 glob_t gl; … … 3145 3194 for (old = chain; old != 0; old = nexto) 3146 3195 { 3196 const char *gname; 3147 3197 #ifndef NO_ARCHIVES 3148 char *memname; 3198 char *arname = 0; 3199 char *memname = 0; 3149 3200 #endif 3150 3151 3201 nexto = old->next; 3152 3153 if (old->name[0] == '~') 3202 gname = old->name; 3203 3204 if (gname[0] == '~') 3154 3205 { 3155 3206 char *newname = tilde_expand (old->name); 3156 3207 if (newname != 0) 3157 { 3158 free (old->name); 3159 old->name = newname; 3160 } 3208 gname = newname; 3161 3209 } 3162 3210 3163 3211 #ifndef NO_ARCHIVES 3164 if (ar_name ( old->name))3212 if (ar_name (gname)) 3165 3213 { 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; 3175 3219 } 3176 else3177 memname = 0;3178 3220 #endif /* !NO_ARCHIVES */ 3179 3221 3180 3222 #if defined(KMK) || defined(__EMX__) /* speed optimization */ 3181 if (!strpbrk( old->name, "*?["))3223 if (!strpbrk(gname, "*?[")) 3182 3224 { 3183 3225 gl.gl_pathc = 1; 3184 gl.gl_pathv = &old->name;3226 gl.gl_pathv = (char *)&gname; 3185 3227 rc = 0; 3186 3228 } 3187 3229 else 3188 rc = glob ( old->name, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl);3230 rc = glob (gname, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl); 3189 3231 switch (rc) 3190 3232 #else 3191 switch (glob ( old->name, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl))3233 switch (glob (gname, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl)) 3192 3234 #endif 3193 3235 { 3194 3236 case 0: /* Success. */ 3195 3237 { 3196 registerint i = gl.gl_pathc;3238 int i = gl.gl_pathc; 3197 3239 while (i-- > 0) 3198 3240 { … … 3203 3245 struct nameseq *found 3204 3246 = ar_glob (gl.gl_pathv[i], memname, size); 3205 if ( found == 0)3247 if (! found) 3206 3248 { 3207 3249 /* No matches. Use MEMNAME as-is. */ 3208 3250 unsigned int alen = strlen (gl.gl_pathv[i]); 3209 3251 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); 3221 3263 elt->next = new; 3222 3264 new = elt; … … 3234 3276 new = found; 3235 3277 } 3236 3237 free (memname);3238 3278 } 3239 3279 else 3240 3280 #endif /* !NO_ARCHIVES */ 3241 3281 { 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]); 3247 3285 elt->next = new; 3248 3286 new = elt; … … 3250 3288 } 3251 3289 #if defined(KMK) || defined(__EMX__) /* speed optimization */ 3252 if (gl.gl_pathv != & old->name)3290 if (gl.gl_pathv != &gname) 3253 3291 #endif 3254 3292 globfree (&gl); 3255 free (old->name); 3256 free ((char *)old); 3293 free (old); 3257 3294 break; 3258 3295 } … … 3267 3304 break; 3268 3305 } 3306 3307 #ifndef NO_ARCHIVES 3308 if (arname) 3309 free (arname); 3310 #endif 3269 3311 } 3270 3312 -
trunk/src/gmakenew/remake.c
r520 r903 40 40 #endif 41 41 42 extern int try_implicit_rule PARAMS ((struct file *file, unsigned int depth));42 extern int try_implicit_rule (struct file *file, unsigned int depth); 43 43 44 44 … … 61 61 static unsigned int considered; 62 62 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)); 63 static int update_file (struct file *file, unsigned int depth); 64 static int update_file_1 (struct file *file, unsigned int depth); 65 static int check_dep (struct file *file, unsigned int depth, 66 FILE_TIMESTAMP this_mtime, int *must_make_ptr); 67 static int touch_file (struct file *file); 68 static void remake_file (struct file *file); 69 static FILE_TIMESTAMP name_mtime (const char *name); 70 static const char *library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr); 70 71 71 72 … … 239 240 240 241 /* Free the storage. */ 241 free ( (char *)g);242 free (g); 242 243 243 244 g = lastgoal == 0 ? goals : lastgoal->next; … … 538 539 if (!running) 539 540 /* 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. */ 543 542 d->changed = ((file_mtime (d->file) != mtime) 544 /* || (mtime == NONEXISTENT_MTIME) */);543 || (mtime == NONEXISTENT_MTIME)); 545 544 546 545 lastd = d; … … 823 822 if (touch_flag 824 823 /* The update status will be: 825 824 -1 if this target was not remade; 826 825 0 if 0 or more commands (+ or ${MAKE}) were run and won; 827 826 1 if some commands were run and lost. … … 933 932 so that a vpath_search can happen. Otherwise, it would 934 933 never be done because the target is already updated. */ 935 (void)f_mtime (d->file, 0);934 f_mtime (d->file, 0); 936 935 } 937 936 else if (file->update_status == -1) … … 942 941 943 942 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. */ 950 948 951 949 static int … … 961 959 if (file->phony || !file->intermediate) 962 960 { 963 /* If this is a non-intermediate file, update it and record 964 whether itis newer than THIS_MTIME. */961 /* If this is a non-intermediate file, update it and record whether it 962 is newer than THIS_MTIME. */ 965 963 FILE_TIMESTAMP mtime; 966 964 dep_status = update_file (file, depth); … … 991 989 } 992 990 993 /* If the intermediate file actually exists994 and is newer, then we should remake from it. */995 991 check_renamed (file); 996 992 mtime = file_mtime (file); 997 993 check_renamed (file); 998 994 if (mtime != NONEXISTENT_MTIME && mtime > this_mtime) 995 /* If the intermediate file actually exists and is newer, then we 996 should remake from it. */ 999 997 *must_make_ptr = 1; 1000 /* Otherwise, update all non-intermediate files we depend on,1001 if necessary, and see whether any of them is more1002 recent than the file on whose behalf we are checking. */1003 998 else 1004 999 { 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. */ 1005 1003 struct dep *lastd; 1006 1004 … … 1081 1079 { 1082 1080 struct stat statbuf; 1083 char buf ;1081 char buf = 'x'; 1084 1082 int e; 1085 1083 … … 1177 1175 char *arname, *memname; 1178 1176 struct file *arfile; 1179 int arname_used = 0;1180 1177 time_t member_date; 1181 1178 … … 1187 1184 arfile = lookup_file (arname); 1188 1185 if (arfile == 0) 1189 { 1190 arfile = enter_file (arname); 1191 arname_used = 1; 1192 } 1186 arfile = enter_file (strcache_add (arname)); 1193 1187 mtime = f_mtime (arfile, search); 1194 1188 check_renamed (arfile); … … 1201 1195 unsigned int arlen, memlen; 1202 1196 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); 1211 1198 memlen = strlen (memname); 1212 1199 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); 1217 1202 name[arlen] = '('; 1218 bcopy (memname, name + arlen + 1, memlen);1203 memcpy (name + arlen + 1, memname, memlen); 1219 1204 name[arlen + 1 + memlen] = ')'; 1220 1205 name[arlen + 1 + memlen + 1] = '\0'; … … 1229 1214 } 1230 1215 1231 if (!arname_used) 1232 free (arname); 1233 free (memname); 1216 free (arname); 1234 1217 1235 1218 file->low_resolution_time = 1; … … 1252 1235 { 1253 1236 /* If name_mtime failed, search VPATH. */ 1254 c har *name = file->name;1255 if ( vpath_search (&name, &mtime)1237 const char *name = vpath_search (file->name, &mtime); 1238 if (name 1256 1239 /* 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)) 1259 1242 { 1260 1243 if (mtime != UNKNOWN_MTIME) … … 1375 1358 1376 1359 static FILE_TIMESTAMP 1377 name_mtime (c har *name)1360 name_mtime (const char *name) 1378 1361 { 1379 1362 FILE_TIMESTAMP mtime; … … 1469 1452 directories. */ 1470 1453 1471 static int1472 library_search (c har **lib, FILE_TIMESTAMP *mtime_ptr)1454 static const char * 1455 library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr) 1473 1456 { 1474 1457 static char *dirs[] = … … 1491 1474 static char *libpatterns = NULL; 1492 1475 1493 c har *libname = &(*lib)[2]; /* Name without the `-l'. */1476 const char *libname = lib+2; /* Name without the '-l'. */ 1494 1477 FILE_TIMESTAMP mtime; 1495 1478 1496 1479 /* Loop variables for the libpatterns value. */ 1497 char *p, *p2; 1480 char *p; 1481 const char *p2; 1498 1482 unsigned int len; 1499 1483 1500 char * file, **dp;1484 char **dp; 1501 1485 1502 1486 /* If we don't have libpatterns, get it. */ … … 1547 1531 if (mtime != NONEXISTENT_MTIME) 1548 1532 { 1549 *lib = xstrdup (libbuf);1550 1533 if (mtime_ptr != 0) 1551 1534 *mtime_ptr = mtime; 1552 return 1;1535 return strcache_add (libbuf); 1553 1536 } 1554 1537 1555 1538 /* Now try VPATH search on that. */ 1556 1539 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 } 1563 1545 1564 1546 /* Now try the standard set of directories. */ … … 1587 1569 if (mtime != NONEXISTENT_MTIME) 1588 1570 { 1589 *lib = xstrdup (buf);1590 1571 if (mtime_ptr != 0) 1591 1572 *mtime_ptr = mtime; 1592 return 1;1573 return strcache_add (buf); 1593 1574 } 1594 1575 } -
trunk/src/gmakenew/remote-cstms.c
r503 r903 100 100 that should work on all machines exported to. */ 101 101 102 normalized_cwd = (char *)xmalloc (GET_PATH_MAX);102 normalized_cwd = xmalloc (GET_PATH_MAX); 103 103 strcpy (normalized_cwd, starting_directory); 104 104 if (Customs_NormPath (normalized_cwd, GET_PATH_MAX) < 0) -
trunk/src/gmakenew/rule.c
r503 r903 18 18 19 19 #include "make.h" 20 21 #include <assert.h> 22 20 23 #include "dep.h" 21 24 #include "filedef.h" … … 25 28 #include "rule.h" 26 29 27 static void freerule PARAMS ((struct rule *rule, struct rule *lastrule));30 static void freerule (struct rule *rule, struct rule *lastrule); 28 31 29 32 … … 72 75 char *name; 73 76 int namelen; 74 registerstruct rule *rule, *lastrule;77 struct rule *rule, *lastrule; 75 78 76 79 num_pattern_rules = max_pattern_targets = max_pattern_deps = 0; … … 84 87 { 85 88 unsigned int ndeps = 0; 86 registerstruct dep *dep;89 struct dep *dep; 87 90 struct rule *next = rule->next; 88 unsigned int ntargets;89 91 90 92 ++num_pattern_rules; 91 93 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; 98 96 99 97 for (dep = rule->deps; dep != 0; dep = dep->next) … … 102 100 103 101 #ifdef VMS 104 c har *p = strrchr (dep->name, ']');105 c har *p2;102 const char *p = strrchr (dep->name, ']'); 103 const char *p2; 106 104 if (p == 0) 107 105 p = strrchr (dep->name, ':'); 108 106 p2 = p != 0 ? strchr (dep->name, '%') : 0; 109 107 #else 110 c har *p = strrchr (dep->name, '/');111 c har *p2 = p != 0 ? strchr (dep->name, '%') : 0;108 const char *p = strrchr (dep->name, '/'); 109 const char *p2 = p != 0 ? strchr (dep->name, '%') : 0; 112 110 #endif 113 111 ndeps++; … … 124 122 if (p - dep->name > namelen) 125 123 { 126 if (name != 0)127 free (name);128 124 namelen = p - dep->name; 129 name = (char *) xmalloc (namelen + 1);125 name = xrealloc (name, namelen + 1); 130 126 } 131 bcopy (dep->name,name, p - dep->name);127 memcpy (name, dep->name, p - dep->name); 132 128 name[p - dep->name] = '\0'; 133 129 … … 162 158 163 159 static void 164 convert_suffix_rule (c har *target, char *source, struct commands *cmds)165 { 166 char *targname, *targpercent, *depname; 167 c har **names, **percents;160 convert_suffix_rule (const char *target, const char *source, 161 struct commands *cmds) 162 { 163 const char **names, **percents; 168 164 struct dep *deps; 169 unsigned int len; 165 166 names = xmalloc (sizeof (const char *)); 167 percents = xmalloc (sizeof (const char *)); 170 168 171 169 if (target == 0) 172 /* Special case: TARGET being nil means we are defining a173 `.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)'. */ 175 173 #ifdef VMS 176 targname = savestring("(%.obj)", 7);174 *names = strcache_add_len ("(%.obj)", 7); 177 175 #else 178 targname = savestring("(%.o)", 5);176 *names = strcache_add_len ("(%.o)", 5); 179 177 #endif 180 targpercent = targname+ 1;178 *percents = *names + 1; 181 179 } 182 180 else 183 181 { 184 182 /* 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 } 197 190 198 191 if (source == 0) … … 201 194 { 202 195 /* 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); 207 200 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); 212 205 } 213 206 214 207 /* Convert old-style suffix rules to pattern rules. 215 All rules for the suffixes on the .SUFFIXES list 216 are converted and added tothe 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. */ 217 210 218 211 void 219 212 convert_to_pattern (void) 220 213 { 221 registerstruct dep *d, *d2;222 register struct file *f;223 register char *rulename; 224 register unsigned int slen, s2len;225 226 /* Compute maximum length of allthe 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. */ 227 220 228 221 maxsuffix = 0; 229 222 for (d = suffix_file->deps; d != 0; d = d->next) 230 223 { 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); 237 231 238 232 for (d = suffix_file->deps; d != 0; d = d->next) 239 233 { 234 unsigned int slen; 235 240 236 /* Make a rule that is just the suffix, with no deps or commands. 241 237 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) 246 241 /* 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. */ 250 246 slen = strlen (dep_name (d)); 251 bcopy (dep_name (d), rulename, slen); 247 memcpy (rulename, dep_name (d), slen); 248 252 249 for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next) 253 250 { 251 struct file *f; 252 unsigned int s2len; 253 254 254 s2len = strlen (dep_name (d2)); 255 255 256 /* Can't build something from itself. */ 256 257 if (slen == s2len && streq (dep_name (d), dep_name (d2))) 257 258 continue; 258 259 259 bcopy (dep_name (d2), rulename + slen, s2len + 1);260 memcpy (rulename + slen, dep_name (d2), s2len + 1); 260 261 f = lookup_file (rulename); 261 262 if (f == 0 || f->cmds == 0) … … 265 266 /* A suffix rule `.X.a:' generates the pattern rule `(%.o): %.X'. 266 267 It also generates a normal `%.a: %.X' rule below. */ 267 convert_suffix_rule ( (char *) 0, /* Indicates `(%.o)'. */268 convert_suffix_rule (NULL, /* Indicates `(%.o)'. */ 268 269 dep_name (d), 269 270 f->cmds); … … 277 278 278 279 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 287 static int 288 288 new_pattern_rule (struct rule *rule, int override) 289 289 { 290 registerstruct rule *r, *lastrule;291 registerunsigned int i, j;290 struct rule *r, *lastrule; 291 unsigned int i, j; 292 292 293 293 rule->in_use = 0; … … 299 299 lastrule = 0; 300 300 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) 302 302 { 303 for (j = 0; r->targets[j] != 0; ++j)303 for (j = 0; j < r->num; ++j) 304 304 if (!streq (rule->targets[i], r->targets[j])) 305 305 break; 306 if (r->targets[j] == 0) 307 /* All the targets matched. */306 /* If all the targets matched... */ 307 if (j == r->num) 308 308 { 309 registerstruct dep *d, *d2;309 struct dep *d, *d2; 310 310 for (d = rule->deps, d2 = r->deps; 311 311 d != 0 && d2 != 0; d = d->next, d2 = d2->next) … … 363 363 install_pattern_rule (struct pspec *p, int terminal) 364 364 { 365 registerstruct rule *r;365 struct rule *r; 366 366 char *ptr; 367 367 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)); 377 374 378 375 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]; 388 380 389 381 ptr = p->dep; … … 395 387 { 396 388 r->terminal = terminal; 397 r->cmds = (struct commands *)xmalloc (sizeof (struct commands));389 r->cmds = xmalloc (sizeof (struct commands)); 398 390 r->cmds->fileinfo.filenm = 0; 399 391 r->cmds->fileinfo.lineno = 0; … … 414 406 { 415 407 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; 421 409 422 410 dep = rule->deps; 423 411 while (dep) 424 412 { 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; 431 414 free_dep (dep); 432 415 dep = t; 433 416 } 434 417 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); 438 421 439 422 /* We can't free the storage for the commands because there … … 448 431 pointer from the `struct file' for the suffix rule. */ 449 432 450 free ( (char *)rule);433 free (rule); 451 434 452 435 if (pattern_rules == rule) … … 462 445 463 446 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 of466 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. 468 451 It is a terminal rule if TERMINAL is nonzero. This rule overrides 469 452 identical rules with different commands if OVERRIDE is nonzero. 470 453 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. */ 474 456 475 457 void 476 create_pattern_rule (c har **targets,char **target_percents,477 458 create_pattern_rule (const char **targets, const char **target_percents, 459 unsigned int n, int terminal, struct dep *deps, 478 460 struct commands *commands, int override) 479 461 { 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; 483 466 r->cmds = commands; 484 467 r->deps = deps; 485 468 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 { 500 474 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]; 513 477 } 514 478 … … 523 487 print_rule (struct rule *r) 524 488 { 525 registerunsigned int i;526 registerstruct 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) 529 493 { 530 494 fputs (r->targets[i], stdout); 531 if (r->targets[i + 1] != 0) 532 putchar (' '); 533 else 534 putchar (':'); 495 putchar ((i + 1 == r->num) ? ':' : ' '); 535 496 } 536 497 if (r->terminal) … … 548 509 print_rule_data_base (void) 549 510 { 550 registerunsigned int rules, terminal;551 registerstruct rule *r;511 unsigned int rules, terminal; 512 struct rule *r; 552 513 553 514 puts (_("\n# Implicit Rules")); -
trunk/src/gmakenew/rule.h
r503 r903 17 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ 18 18 19 /* Structure used for pattern rules. */ 19 20 /* Structure used for pattern (implicit) rules. */ 20 21 21 22 struct rule 22 23 { 23 24 struct rule *next; 24 c har **targets;/* Targets of the rule. */25 const char **targets; /* Targets of the rule. */ 25 26 unsigned int *lens; /* Lengths of each target. */ 26 c har **suffixes;/* Suffixes (after `%') of each target. */27 const char **suffixes; /* Suffixes (after `%') of each target. */ 27 28 struct dep *deps; /* Dependencies of the rule. */ 28 29 struct commands *cmds; /* Commands to execute. */ 30 unsigned short num; /* Number of targets. */ 29 31 char terminal; /* If terminal (double-colon). */ 30 32 char in_use; /* If in use by a parent pattern_search. */ … … 50 52 51 53 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)); 54 void count_implicit_rule_limits (void); 55 void convert_to_pattern (void); 56 void install_pattern_rule (struct pspec *p, int terminal); 57 void 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 21 21 #include "hash.h" 22 22 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) 25 26 26 27 … … 40 41 static struct strcache *strcache = NULL; 41 42 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 */ 42 48 static struct strcache * 43 49 new_cache() 44 50 { 45 51 struct strcache *new; 46 new = (struct strcache *)xmalloc (sizeof (*new) + bufsize);52 new = xmalloc (sizeof (*new) + bufsize); 47 53 new->end = new->buffer; 48 54 new->count = 0; … … 62 68 const char *res; 63 69 64 /* If the string we want is too large to fit into a single buffer, then we're65 screwed; nothing will ever fit! Change the maximum size of the cache to66 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. */ 67 73 if (len > bufsize) 68 74 bufsize = len * 2; … … 114 120 115 121 static struct hash_table strings; 122 static unsigned long total_adds = 0; 116 123 117 124 static const char * … … 119 126 { 120 127 /* 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); 122 129 const char *key = *slot; 130 131 /* Count the total number of adds we performed. */ 132 ++total_adds; 123 133 124 134 if (!HASH_VACANT (key)) … … 156 166 strcache_add_len (const char *str, int len) 157 167 { 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); 163 179 } 164 180 … … 174 190 strcache_init (void) 175 191 { 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); 177 193 } 178 194 … … 186 202 int totsize = 0, avgsize, maxsize = 0, minsize = bufsize; 187 203 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) 191 207 { 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 } 205 230 } 206 231 … … 208 233 avgfree = numbuffs ? (int)(totfree / numbuffs) : 0; 209 234 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 1 2006-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 8 2006-09-30 Paul Smith <[email protected]> 9 10 * scripts/variables/automatic: Add back the test for bug #8154. 11 1 12 2006-04-01 Paul D. Smith <[email protected]> 2 13 -
trunk/src/gmakenew/tests/run_make_tests.pl
r503 r903 191 191 sub print_usage 192 192 { 193 &print_standard_usage ("run_make_tests", "[-make_path make_pathname]"); 193 &print_standard_usage ("run_make_tests", 194 "[-make_path make_pathname] [-valgrind]",); 194 195 } 195 196 … … 229 230 local($index); 230 231 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 236 232 # find the type of the port. We do this up front to have a single 237 233 # point of change if it needs to be tweaked. -
trunk/src/gmakenew/tests/scripts/features/patternrules
r503 r903 11 11 12 12 13 # TEST #1: Make sure that multiple patterns where the same target14 # 15 # 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. 16 16 # 17 17 … … 46 46 ''); 47 47 48 # TEST # 2: make sure files that are built via implicit rules are marked48 # TEST #1: make sure files that are built via implicit rules are marked 49 49 # as targets (Savannah bug #12202). 50 50 # … … 70 70 71 71 72 # TEST # 3: make sure intermidite files that also happened to be72 # TEST #2: make sure intermediate files that also happened to be 73 73 # prerequisites are not removed (Savannah bug #12267). 74 74 # … … 97 97 98 98 99 # TEST # 4: make sure precious flag is set properly for targets99 # TEST #3: make sure precious flag is set properly for targets 100 100 # that are built via implicit rules (Savannah bug #13218). 101 101 # … … 117 117 118 118 119 # TEST # 5: make sure targets of a macthed implicit pattern rule never119 # TEST #4: make sure targets of a matched implicit pattern rule are 120 120 # never considered intermediate (Savannah bug #13022). 121 121 # -
trunk/src/gmakenew/tests/scripts/variables/automatic
r503 r903 96 96 # considered reasons for the target to be rebuilt. 97 97 # 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. 100 99 101 #touch('foo');102 # 103 #run_make_test('104 #foo: bar ; @echo "\$$? = $?"105 #bar: ;',106 #'',107 #'$? = bar');108 # 109 #unlink('foo');100 touch('foo'); 101 102 run_make_test(' 103 foo: bar ; @echo "\$$? = $?" 104 bar: ;', 105 '', 106 '$? = bar'); 107 108 unlink('foo'); 110 109 111 110 1; -
trunk/src/gmakenew/tests/test_driver.pl
r503 r903 29 29 # variables and then calls &toplevel, which does all the real work. 30 30 31 # $Id: test_driver.pl,v 1. 19 2006/03/10 02:20:45psmith Exp $31 # $Id: test_driver.pl,v 1.21 2007/03/20 03:02:26 psmith Exp $ 32 32 33 33 … … 79 79 { 80 80 # Pull in benign variables from the user's environment 81 # 81 82 82 foreach (# UNIX-specific things 83 'TZ', ' LANG', 'TMPDIR', 'HOME', 'USER', 'LOGNAME', 'PATH',83 'TZ', 'TMPDIR', 'HOME', 'USER', 'LOGNAME', 'PATH', 84 84 # Purify things 85 85 'PURIFYOPTIONS', … … 92 92 $makeENV{$_} = $ENV{$_} if $ENV{$_}; 93 93 } 94 95 # Make sure our compares are not foiled by locale differences 96 97 $makeENV{LC_ALL} = 'C'; 94 98 95 99 # Replace the environment with the new one … … 544 548 local($line); 545 549 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"; 552 554 } 553 555 } -
trunk/src/gmakenew/variable.c
r821 r903 43 43 44 44 struct 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)); 45 create_pattern_var (const char *target, const char *suffix) 46 { 47 register struct pattern_var *p = xmalloc (sizeof (struct pattern_var)); 49 48 50 49 if (last_pattern_var != 0) … … 65 64 66 65 static struct pattern_var * 67 lookup_pattern_var (struct pattern_var *start, c har *target)66 lookup_pattern_var (struct pattern_var *start, const char *target) 68 67 { 69 68 struct pattern_var *p; … … 72 71 for (p = start ? start->next : pattern_vars; p != 0; p = p->next) 73 72 { 74 c har *stem;73 const char *stem; 75 74 unsigned int stemlen; 76 75 … … 278 277 279 278 #ifndef VARIABLE_BUCKETS 279 # ifdef KMK /* Move to Makefile.kmk? */ 280 # define VARIABLE_BUCKETS 16384 281 # else /*!KMK*/ 280 282 #define VARIABLE_BUCKETS 523 283 # endif /*!KMK*/ 281 284 #endif 282 285 #ifndef PERFILE_VARIABLE_BUCKETS … … 298 301 init_hash_global_variable_set (void) 299 302 { 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, 306 304 variable_hash_1, variable_hash_2, variable_hash_cmp); 307 305 } … … 317 315 struct variable * 318 316 define_variable_in_set (const char *name, unsigned int length, 319 c har *value, unsigned int value_length, int duplicate_value,317 const char *value, unsigned int value_length, int duplicate_value, 320 318 enum variable_origin origin, int recursive, 321 319 struct variable_set *set, const struct floc *flocp) … … 323 321 struct variable * 324 322 define_variable_in_set (const char *name, unsigned int length, 325 c har *value, enum variable_origin origin,323 const char *value, enum variable_origin origin, 326 324 int recursive, struct variable_set *set, 327 325 const struct floc *flocp) … … 368 366 if (v->value != 0) 369 367 free (v->value); 370 v->value = value;368 v->value = (char *)value; 371 369 v->value_alloc_len = value_length + 1; 372 370 } … … 399 397 /* Create a new variable definition and add it to the hash table. */ 400 398 401 v = (struct variable *)xmalloc (sizeof (struct variable));399 v = xmalloc (sizeof (struct variable)); 402 400 v->name = savestring (name, length); 403 401 v->length = length; … … 416 414 { 417 415 v->value_alloc_len = value_length + 1; 418 v->value = value;416 v->value = (char *)value; 419 417 } 420 418 else … … 531 529 } 532 530 533 bcopy (v->name, p, l);531 memcpy (p, v->name, l); 534 532 p += l; 535 533 *(p++) = ' '; … … 698 696 parent of FILE's variable set. 699 697 700 If we're READ inga makefile, don't do the pattern variable search now,698 If we're READING a makefile, don't do the pattern variable search now, 701 699 since the pattern variable might not have been defined yet. */ 702 700 … … 710 708 l = (struct variable_set_list *) 711 709 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)); 713 711 hash_init (&l->set->table, PERFILE_VARIABLE_BUCKETS, 714 712 variable_hash_1, variable_hash_2, variable_hash_cmp); … … 806 804 register struct variable_set *set; 807 805 808 set = (struct variable_set *)xmalloc (sizeof (struct variable_set));806 set = xmalloc (sizeof (struct variable_set)); 809 807 hash_init (&set->table, SMALL_SCOPE_VARIABLE_BUCKETS, 810 808 variable_hash_1, variable_hash_2, variable_hash_cmp); … … 831 829 hash_map (&list->set->table, free_variable_name_and_value); 832 830 hash_free (&list->set->table, 1); 833 free ( (char *)list->set);834 free ( (char *)list);831 free (list->set); 832 free (list); 835 833 } 836 834 … … 888 886 889 887 /* Free the one we no longer need. */ 890 free ( (char *)setlist);888 free (setlist); 891 889 hash_map (&set->table, free_variable_name_and_value); 892 890 hash_free (&set->table, 1); 893 free ( (char *)set);891 free (set); 894 892 } 895 893 … … 1036 1034 /* Define KMK_FEATURES to indicate various working KMK features. */ 1037 1035 # if defined(CONFIG_WITH_TOUPPER_TOLOWER) \ 1036 && defined(CONFIG_WITH_RSORT) \ 1038 1037 && defined(CONFIG_WITH_ABSPATHEX) \ 1039 1038 && defined(CONFIG_WITH_VALUE_LENGTH) && defined(CONFIG_WITH_COMPARE) \ … … 1043 1042 && defined(KMK_HELPERS) 1044 1043 (void) define_variable ("KMK_FEATURES", 12, 1045 "append-dash-n " 1046 "abspath abspathex" 1044 "append-dash-n abspath" 1045 " rsort" 1046 " abspathex" 1047 1047 " toupper tolower" 1048 1048 " comp-vars comp-cmds" … … 1054 1054 # else /* MSC can't deal with strings mixed with #if/#endif, thus the slow way. */ 1055 1055 strcpy(buf, "append-dash-n abspath"); 1056 # if defined(CONFIG_WITH_RSORT) 1057 strcat(buf, " rsort"); 1058 # endif 1056 1059 # if defined(CONFIG_WITH_ABSPATHEX) 1057 1060 strcat(buf, " abspathex"); … … 1316 1319 hash_delete (&table, &makelevel_key); 1317 1320 1318 result = result_0 = (char **)xmalloc ((table.ht_fill + 2) * sizeof (char *));1321 result = result_0 = xmalloc ((table.ht_fill + 2) * sizeof (char *)); 1319 1322 1320 1323 v_slot = (struct variable **) table.ht_vec; … … 1337 1340 convert_Path_to_windows32(value, ';'); 1338 1341 #endif 1339 *result++ = concat (v->name, "=", value);1342 *result++ = xstrdup (concat (v->name, "=", value)); 1340 1343 free (value); 1341 1344 } … … 1347 1350 convert_Path_to_windows32(v->value, ';'); 1348 1351 #endif 1349 *result++ = concat (v->name, "=", v->value);1352 *result++ = xstrdup (concat (v->name, "=", v->value)); 1350 1353 } 1351 1354 } 1352 1355 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); 1355 1358 *++result = 0; 1356 1359 … … 1363 1366 #ifdef CONFIG_WITH_VALUE_LENGTH 1364 1367 static struct variable * 1365 do_variable_definition_append (const struct floc *flocp, struct variable *v, c har *value,1368 do_variable_definition_append (const struct floc *flocp, struct variable *v, const char *value, 1366 1369 enum variable_origin origin) 1367 1370 { … … 1430 1433 struct variable * 1431 1434 do_variable_definition (const struct floc *flocp, const char *varname, 1432 c har *value, enum variable_origin origin,1435 const char *value, enum variable_origin origin, 1433 1436 enum variable_flavor flavor, int target_var) 1434 1437 { 1435 char *p, *alloc_value = NULL; 1438 const char *p; 1439 char *alloc_value = NULL; 1436 1440 struct variable *v; 1437 1441 int append = 0; … … 1507 1511 1508 1512 unsigned int oldlen, vallen; 1509 char *val; 1513 const char *val; 1514 char *tp; 1510 1515 1511 1516 val = value; … … 1524 1529 oldlen = strlen (v->value); 1525 1530 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; 1530 1536 #endif /* !CONFIG_WITH_VALUE_LENGTH */ 1531 1537 } … … 1554 1560 1555 1561 /* 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)) 1557 1563 { 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 1565 1570 v = define_variable_loc (varname, varname_len, 1566 1571 shellpath, origin, flavor == f_recursive, … … 1569 1574 else 1570 1575 { 1571 c har *shellbase, *bslash;1576 const char *shellbase, *bslash; 1572 1577 struct variable *pathv = lookup_variable ("PATH", 4); 1573 1578 char *path_string; … … 1590 1595 if (pathv) 1591 1596 pathlen = strlen (pathv->value); 1592 path_string = (char *)xmalloc (5 + pathlen + 2 + 1);1597 path_string = xmalloc (5 + pathlen + 2 + 1); 1593 1598 /* On MSDOS, current directory is considered as part of $PATH. */ 1594 1599 sprintf (path_string, "PATH=.;%s", pathv ? pathv->value : ""); 1595 1600 fake_env[0] = path_string; 1596 fake_env[1] = (char *)0;1601 fake_env[1] = 0; 1597 1602 if (__dosexec_find_on_path (shellbase, fake_env, shellpath)) 1598 1603 { 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 1606 1610 v = define_variable_loc (varname, varname_len, 1607 1611 shellpath, origin, … … 1773 1777 1774 1778 /* 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); 1777 1781 name[end - beg] = '\0'; 1778 1782 v->name = allocated_variable_expand (name); … … 1827 1831 print_variable (const void *item, void *arg) 1828 1832 { 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; 1831 1835 const char *origin; 1832 1836 … … 1942 1946 1943 1947 void 1944 print_file_variables ( struct file *file)1948 print_file_variables (const struct file *file) 1945 1949 { 1946 1950 if (file->variables != 0) … … 1969 1973 */ 1970 1974 convert_Path_to_windows32 (path, ';'); 1971 environ_path = concat ("PATH", "=", path);1975 environ_path = xstrdup (concat ("PATH", "=", path)); 1972 1976 putenv (environ_path); 1973 1977 free (path); -
trunk/src/gmakenew/variable.h
r533 r903 61 61 int value_alloc_len; /* The amount of memory we've actually allocated. */ 62 62 /* FIXME: make lengths unsigned! */ 63 #endif 63 #endif 64 64 char *value; /* Variable value. */ 65 65 struct floc fileinfo; /* Where the variable was defined. */ … … 109 109 { 110 110 struct pattern_var *next; 111 char *target; 111 const char *suffix; 112 const char *target; 112 113 unsigned int len; 113 char *suffix;114 114 struct variable variable; 115 115 }; … … 119 119 120 120 /* 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));121 char *variable_buffer_output (char *ptr, const char *string, unsigned int length); 122 char *variable_expand (const char *line); 123 char *variable_expand_for_file (const char *line, struct file *file); 124 char *allocated_variable_expand_for_file (const char *line, struct file *file); 125 125 #define allocated_variable_expand(line) \ 126 126 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)); 127 char *expand_argument (const char *str, const char *end); 128 char *variable_expand_string (char *line, const char *string, long length); 129 void install_variable_buffer (char **bufp, unsigned int *lenp); 130 void restore_variable_buffer (char *buf, unsigned int len); 132 131 #ifdef CONFIG_WITH_VALUE_LENGTH 133 extern void append_expanded_string_to_variable PARAMS ((struct variable *v, char *value));132 extern void append_expanded_string_to_variable (struct variable *v, char *value); 134 133 #endif 135 134 136 135 /* 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)); 136 int handle_function (char **op, const char **stringp); 137 int pattern_matches (const char *pattern, const char *percent, const char *str); 138 char *subst_expand (char *o, const char *text, const char *subst, 139 const char *replace, unsigned int slen, unsigned int rlen, 140 int by_word); 141 char *patsubst_expand_pat (char *o, const char *text, const char *pattern, 142 const char *replace, const char *pattern_percent, 143 const char *replace_percent); 144 char *patsubst_expand (char *o, const char *text, char *pattern, char *replace); 143 145 144 146 /* expand.c */ 145 extern char *recursively_expand_for_file PARAMS ((struct variable *v, 146 struct file *file)); 147 char *recursively_expand_for_file (struct variable *v, struct file *file); 147 148 #define recursively_expand(v) recursively_expand_for_file (v, NULL) 148 149 149 150 /* 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)); 151 struct variable_set_list *create_new_variable_set (void); 152 void free_variable_set (struct variable_set_list *); 153 struct variable_set_list *push_new_variable_scope (void); 154 void pop_variable_scope (void); 155 void define_automatic_variables (void); 156 void initialize_file_variables (struct file *file, int reading); 157 void print_file_variables (const struct file *file); 158 void print_variable_set (struct variable_set *set, char *prefix); 159 void merge_variable_set_lists (struct variable_set_list **to_list, 160 struct variable_set_list *from_list); 161 struct 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); 166 struct variable *parse_variable_definition (struct variable *v, char *line); 167 struct variable *try_variable_definition (const struct floc *flocp, char *line, 168 enum variable_origin origin, 169 int target_var); 170 void init_hash_global_variable_set (void); 171 void hash_init_function_table (void); 172 struct variable *lookup_variable (const char *name, unsigned int length); 173 struct variable *lookup_variable_in_set (const char *name, unsigned int length, 174 const struct variable_set *set); 168 175 169 176 #ifdef CONFIG_WITH_VALUE_LENGTH 170 177 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)); 178 struct 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); 176 186 177 187 /* Define a variable in the current variable set. */ 178 188 179 189 #define define_variable(n,l,v,o,r) \ 180 define_variable_in_set((n),(l),(v), 190 define_variable_in_set((n),(l),(v),~0U,1,(o),(r),\ 181 191 current_variable_set_list->set,NILF) 182 192 … … 204 214 define_variable_in_set((n),(l),(v),~0U,1,(o),(r),(f)->variables->set,NILF) 205 215 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 218 struct 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); 212 224 213 225 /* Define a variable in the current variable set. */ … … 215 227 #define define_variable(n,l,v,o,r) \ 216 228 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 */ 218 230 219 231 /* Define a variable with a location in the current variable set. */ … … 221 233 #define define_variable_loc(n,l,v,o,r,f) \ 222 234 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 */ 224 236 225 237 /* Define a variable with a location in the global variable set. */ 226 238 227 239 #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 */ 229 241 230 242 /* Define a variable in FILE's variable set. */ 231 243 232 244 #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 */ 236 248 237 249 /* Warn that NAME is an undefined variable. */ … … 244 256 }while(0) 245 257 246 extern char **target_environment PARAMS ((struct file *file)); 247 248 extern struct pattern_var *create_pattern_var PARAMS ((char *target, char *suffix)); 258 char **target_environment (struct file *file); 259 260 struct pattern_var *create_pattern_var (const char *target, 261 const char *suffix); 249 262 250 263 extern int export_all_variables; -
trunk/src/gmakenew/vmsdir.h
r503 r903 68 68 #endif 69 69 70 extern DIR *opendir PARAMS (());71 extern struct direct *readdir PARAMS ((DIR *dfd));72 70 #define rewinddir(dirp) seekdir((dirp), (long)0) 73 extern int closedir PARAMS ((DIR *dfd)); 74 extern char *vmsify PARAMS ((char *name, int type)); 71 72 DIR *opendir (); 73 struct direct *readdir (DIR *dfd); 74 int closedir (DIR *dfd); 75 const char *vmsify (const char *name, int type); 75 76 76 77 #endif /* VMSDIR_H */ -
trunk/src/gmakenew/vmsfunctions.c
r503 r903 38 38 struct NAM *dnam = (struct NAM *)xmalloc (sizeof (struct NAM)); 39 39 struct FAB *dfab = &dir->fab; 40 char *searchspec = (char *)xmalloc (MAXNAMLEN + 1);40 char *searchspec = xmalloc (MAXNAMLEN + 1); 41 41 42 42 memset (dir, 0, sizeof *dir); … … 258 258 return (str); 259 259 } 260 261 int262 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 64 64 65 65 static int 66 copyto (char **to, c har **from, char upto, int as_dir)66 copyto (char **to, const char **from, char upto, int as_dir) 67 67 { 68 c har *s;68 const char *s; 69 69 70 70 s = strrchr (*from, '.'); … … 112 112 113 113 static char * 114 trnlog (c har *name)114 trnlog (const char *name) 115 115 { 116 116 int stat; … … 135 135 reslt[resltlen] = '\0'; 136 136 137 s = (char *)malloc (resltlen+1);137 s = malloc (resltlen+1); 138 138 if (s == 0) 139 139 return ""; … … 206 206 26 filenames with a single pair of '[' ']' are left unchanged 207 207 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. 209 210 */ 210 211 211 c har *212 vmsify (c har *name, int type)212 const char * 213 vmsify (const char *name, int type) 213 214 { 214 215 /* max 255 device … … 222 223 enum namestate nstate; 223 224 static char vmsname[MAXPATHLEN+1]; 224 char *fptr; 225 const char *fptr; 226 const char *t; 225 227 char *vptr; 226 char *s,*s1;227 228 int as_dir; 228 229 int count; … … 235 236 236 237 /* case 25a */ 237 238 s = strpbrk (name, "$:"); 239 if ( s!= 0)240 { 241 c har *s1;242 c har *s2;238 t = strpbrk (name, "$:"); 239 240 if (t != 0) 241 { 242 const char *s1; 243 const char *s2; 243 244 244 245 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 } 264 261 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 } 275 268 } 276 269 277 270 /* 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, '['); 284 277 if (s1 == 0) 285 278 { 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; 295 283 } 296 284 s1--; 297 285 if (*s1 != ']') 298 286 { 299 return name; /* not ][, keep unchanged */ 287 strcpy (vmsname, name); 288 return vmsname; /* not ][, keep unchanged */ 300 289 } 301 290 … … 306 295 /* s -> starting char 307 296 s1 -> ending ']' */ 308 309 297 do 310 298 { … … 330 318 331 319 } 332 333 320 else /* no [ in name */ 334 335 { 336 337 int state; 321 { 322 int state = 0; 338 323 int rooted = 1; /* flag if logical is rooted, else insert [000000] */ 339 340 state = 0;341 324 342 325 do 343 326 { 344 345 327 switch (state) 346 328 { … … 371 353 372 354 case 2: /* no '/' at start */ 373 s = strchr (fptr, '/'); 355 { 356 const char *s = strchr (fptr, '/'); 374 357 if (s == 0) /* no '/' (16) */ 375 358 { … … 402 385 } 403 386 break; 387 } 404 388 405 389 case 3: /* '//' at start */ 390 { 391 const char *s; 392 const char *s1; 393 char *vp; 406 394 while (*fptr == '/') /* collapse all '/' */ 407 395 fptr++; … … 413 401 if (s1 == 0) 414 402 { 415 return ""; /* FIXME, err getcwd */ 403 vmsname[0] = '\0'; 404 return vmsname; /* FIXME, err getcwd */ 416 405 } 417 406 s = strchr (s1, ':'); 418 407 if (s == 0) 419 408 { 420 return ""; /* FIXME, err no device */ 409 vmsname[0] = '\0'; 410 return vmsname; /* FIXME, err no device */ 421 411 } 422 412 strncpy (vptr, s1, s-s1+1); … … 445 435 *vptr = 0; 446 436 /* check logical for [000000] insertion */ 447 s1= trnlog (s);448 if (* s1 != 0)437 vp = trnlog (s); 438 if (*vp != '\0') 449 439 { /* found translation */ 450 char *s2;451 440 for (;;) /* loop over all nested logicals */ 452 441 { 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) 459 448 { 460 449 rooted = 0; 461 450 break; 462 451 } 463 s1 = s2;452 vp = vp2; 464 453 continue; /* next iteration */ 465 454 } 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 '.]' */ 469 458 { 470 459 if (strncmp (fptr, "000000", 6) != 0) … … 474 463 { 475 464 strcpy (vmsname, s1); 476 s= strchr (vmsname, ']');477 * s= '.';465 vp = strchr (vmsname, ']'); 466 *vp = '.'; 478 467 nstate = N_DOT; 479 vptr = s;468 vptr = vp; 480 469 } 481 470 } 482 471 break; 483 472 } 484 free ( s1);473 free (vp); 485 474 } 486 475 else … … 497 486 if (rooted == 0) 498 487 { 488 nstate = N_DOT; 499 489 strcpy (vptr, "[000000."); 500 490 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 */ 508 497 509 498 s = strchr (fptr, '/'); … … 532 521 else 533 522 if ((nstate == N_DOT) 534 && ( s1!= 0)523 && (vp != 0) 535 524 && (*(s+1) == 0)) 536 525 { 537 526 if (type == 2) 538 527 { 539 * s1= ']';528 *vp = ']'; 540 529 nstate = N_CLOSED; 541 530 } … … 543 532 state = 9; 544 533 break; 545 534 } 546 535 case 4: /* single '/' at start (9..15) */ 547 536 if (*fptr == 0) … … 565 554 break; 566 555 567 case 6: /* chars following '/' at start 10..15 */ 556 case 6: /* chars following '/' at start 10..15 */ 557 { 558 const char *s; 568 559 *vptr++ = '['; 569 560 nstate = N_OPEN; … … 596 587 } 597 588 break; 589 } 598 590 599 591 case 7: /* add '.dir' and exit */ … … 601 593 || (nstate == N_DOT)) 602 594 { 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 == ']') 607 599 { 608 600 break; 609 601 } 610 if (* s== '.')611 { 612 * s= ']';602 if (*vp == '.') 603 { 604 *vp = ']'; 613 605 break; 614 606 } 615 s--;607 vp--; 616 608 } 617 609 } … … 626 618 break; 627 619 628 case 9: /* 17..21, fptr -> 1st '/' + 1 */ 620 case 9: /* 17..21, fptr -> 1st '/' + 1 */ 621 { 622 const char *s; 629 623 if (*fptr == 0) 630 624 { … … 688 682 || (*(fptr+2) == 0)) ) 689 683 { 684 char *vp; 690 685 fptr += 2; 691 686 if (*fptr == '/') … … 700 695 type = 1; 701 696 vptr--; /* vptr -> '.' or ']' */ 702 s1= vptr;697 vp = vptr; 703 698 for (;;) 704 699 { 705 s1--;706 if (* s1== '.') /* one back */707 { 708 vptr = s1;700 vp--; 701 if (*vp == '.') /* one back */ 702 { 703 vptr = vp; 709 704 nstate = N_OPEN; 710 705 break; 711 706 } 712 if (* s1== '[') /* top level reached */707 if (*vp == '[') /* top level reached */ 713 708 { 714 709 if (*fptr == 0) 715 710 { 716 strcpy ( s1, "[000000]");717 vptr = s1+ 8;711 strcpy (vp, "[000000]"); 712 vptr = vp + 8; 718 713 nstate = N_CLOSED; 719 714 s = 0; … … 722 717 else 723 718 { 724 vptr = s1+1;719 vptr = vp+1; 725 720 nstate = N_OPEN; 726 721 break; … … 757 752 } 758 753 break; 754 } 759 755 760 756 case 10: /* 1,2 first is '.' */ … … 774 770 if (*fptr != '/') /* got ..xxx */ 775 771 { 776 return name; 772 strcpy (vmsname, name); 773 return vmsname; 777 774 } 778 775 do /* got ../ */ … … 792 789 } 793 790 { /* got '..' or '../' */ 791 char *vp; 794 792 char cwdbuf[MAXPATHLEN+1]; 795 793 796 s1= getcwd(cwdbuf, MAXPATHLEN);797 if ( s1== 0)794 vp = getcwd(cwdbuf, MAXPATHLEN); 795 if (vp == 0) 798 796 { 799 return ""; /* FIXME, err getcwd */ 797 vmsname[0] = '\0'; 798 return vmsname; /* FIXME, err getcwd */ 800 799 } 801 strcpy (vptr, s1);802 s= strchr (vptr, ']');803 if ( s!= 0)800 strcpy (vptr, vp); 801 vp = strchr (vptr, ']'); 802 if (vp != 0) 804 803 { 805 804 nstate = N_OPEN; 806 while ( s> vptr)805 while (vp > vptr) 807 806 { 808 s--;809 if (* s== '[')807 vp--; 808 if (*vp == '[') 810 809 { 811 s++;812 strcpy ( s, "000000]");810 vp++; 811 strcpy (vp, "000000]"); 813 812 state = -1; 814 813 break; 815 814 } 816 else if (* s== '.')815 else if (*vp == '.') 817 816 { 818 817 if (--count == 0) … … 820 819 if (*fptr == 0) /* had '..' or '../' */ 821 820 { 822 * s++ = ']';821 *vp++ = ']'; 823 822 state = -1; 824 823 } … … 827 826 state = 9; 828 827 } 829 * s = 0;828 *vp = '\0'; 830 829 break; 831 830 } … … 842 841 if (*fptr != '/') 843 842 { 844 return name; 843 strcpy (vmsname, name); 844 return vmsname; 845 845 } 846 846 while (*fptr == '/') … … 849 849 850 850 { 851 char *vp; 851 852 char cwdbuf[MAXPATHLEN+1]; 852 853 853 s1= getcwd(cwdbuf, MAXPATHLEN);854 if ( s1== 0)854 vp = getcwd(cwdbuf, MAXPATHLEN); 855 if (vp == 0) 855 856 { 856 return ""; /*FIXME, err getcwd */ 857 vmsname[0] = '\0'; 858 return vmsname; /*FIXME, err getcwd */ 857 859 } 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 } 878 880 break; 879 881 } … … 904 906 */ 905 907 906 c har *907 unixify (c har *name)908 const char * 909 unixify (const char *name) 908 910 { 909 911 static char piece[512]; 910 char *s, *p; 912 const char *s; 913 char *p; 911 914 912 915 if (strchr (name, '/') != 0) /* already in unix style */ 913 return name; 916 { 917 strcpy (piece, name); 918 return piece; 919 } 914 920 915 921 p = piece; … … 922 928 if (s != 0) 923 929 { 924 *s = 0;930 int l = s - name; 925 931 *p++ = '/'; 926 932 *p++ = '/'; 927 strcpy (p, name); 928 p += strlen (p); 929 *s = ':'; 933 strncpy (p, name, l); 934 p += l; 930 935 } 931 936 -
trunk/src/gmakenew/vmsjobs.c
r503 r903 22 22 #include <clidef.h> 23 23 24 extern char *vmsify PARAMS ((char *name, int type));24 char *vmsify (char *name, int type); 25 25 26 26 static int vms_jobsefnmask = 0; -
trunk/src/gmakenew/vpath.c
r527 r903 30 30 { 31 31 struct vpath *next; /* Pointer to next struct in the linked list. */ 32 c har *pattern;/* The pattern to match. */33 c har *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. */ 34 34 unsigned int patlen;/* Length of the pattern. */ 35 c har **searchpath;/* Null-terminated list of directories. */35 const char **searchpath; /* Null-terminated list of directories. */ 36 36 unsigned int maxlen;/* Maximum length of any entry in the list. */ 37 37 }; … … 50 50 51 51 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. */ 57 56 58 57 void … … 97 96 /* Save the list of vpaths. */ 98 97 struct vpath *save_vpaths = vpaths; 98 char gp[] = "%"; 99 99 100 100 /* Empty `vpaths' so the new one will have no next, and `vpaths' … … 103 103 104 104 /* Parse P. */ 105 construct_vpath_list ( "%", p);105 construct_vpath_list (gp, p); 106 106 107 107 /* Store the created path as the general path, … … 133 133 /* Save the list of vpaths. */ 134 134 struct vpath *save_vpaths = vpaths; 135 char gp[] = "%"; 135 136 136 137 /* Empty `vpaths' so the new one will have no next, and `vpaths' … … 139 140 140 141 /* Parse P. */ 141 construct_vpath_list ( "%", p);142 construct_vpath_list (gp, p); 142 143 143 144 /* Store the created path as the GPATH, … … 171 172 construct_vpath_list (char *pattern, char *dirpath) 172 173 { 173 registerunsigned int elem;174 registerchar *p;175 registerchar **vpath;176 registerunsigned int maxvpath;174 unsigned int elem; 175 char *p; 176 const char **vpath; 177 unsigned int maxvpath; 177 178 unsigned int maxelem; 178 c har *percent = NULL;179 const char *percent = NULL; 179 180 180 181 if (pattern != 0) 181 { 182 pattern = xstrdup (pattern); 183 percent = find_percent (pattern); 184 } 182 percent = find_percent (pattern); 185 183 186 184 if (dirpath == 0) 187 185 { 188 186 /* Remove matching listings. */ 189 registerstruct vpath *path, *lastpath;187 struct vpath *path, *lastpath; 190 188 191 189 lastpath = 0; … … 207 205 208 206 /* Free its unused storage. */ 209 free (path->pattern); 210 free ((char *) path->searchpath); 211 free ((char *) path); 207 free (path->searchpath); 208 free (path); 212 209 } 213 210 else … … 217 214 } 218 215 219 if (pattern != 0)220 free (pattern);221 216 return; 222 217 } … … 225 220 convert_vpath_to_windows32(dirpath, ';'); 226 221 #endif 222 223 /* Skip over any initial separators and blanks. */ 224 while (*dirpath == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*dirpath)) 225 ++dirpath; 227 226 228 227 /* Figure out the maximum number of VPATH entries and put it in … … 236 235 ++maxelem; 237 236 238 vpath = (char **) xmalloc (maxelem * sizeof (char *));237 vpath = xmalloc (maxelem * sizeof (const char *)); 239 238 maxvpath = 0; 240 239 241 /* Skip over any initial separators and blanks. */240 elem = 0; 242 241 p = dirpath; 243 while (*p == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*p))244 ++p;245 246 elem = 0;247 242 while (*p != '\0') 248 243 { … … 266 261 --len; 267 262 263 /* Put the directory on the vpath list. */ 268 264 if (len > 1 || *v != '.') 269 265 { 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; 285 269 } 286 270 … … 297 281 Usually this is maxelem - 1. If not, shrink down. */ 298 282 if (elem < (maxelem - 1)) 299 vpath = (char **) xrealloc ((char *) vpath, 300 (elem + 1) * sizeof (char *)); 283 vpath = xrealloc (vpath, (elem+1) * sizeof (const char *)); 301 284 302 285 /* Put the nil-pointer terminator on the end of the VPATH list. */ 303 vpath[elem] = 0;286 vpath[elem] = NULL; 304 287 305 288 /* 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)); 307 290 path->searchpath = vpath; 308 291 path->maxlen = maxvpath; … … 311 294 312 295 /* Set up the members. */ 313 path->pattern = pattern; 314 path->percent = percent; 296 path->pattern = strcache_add (pattern); 315 297 path->patlen = strlen (pattern); 298 path->percent = percent ? path->pattern + (percent - pattern) : 0; 316 299 } 317 300 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); 324 303 } 325 304 … … 329 308 330 309 int 331 gpath_search (c har *file, unsigned int len)310 gpath_search (const char *file, unsigned int len) 332 311 { 333 c har **gp;312 const char **gp; 334 313 335 314 if (gpaths && (len <= gpaths->maxlen)) … … 342 321 343 322 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 329 static const char * 330 selective_vpath_search (struct vpath *path, const char *file, 387 331 FILE_TIMESTAMP *mtime_ptr) 388 332 { 389 333 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; 393 338 unsigned int maxvpath = path->maxlen; 394 registerunsigned int i;339 unsigned int i; 395 340 unsigned int flen, vlen, name_dplen; 396 341 int exists = 0; … … 400 345 files that don't exist but are mentioned in a makefile. */ 401 346 { 402 struct file *f = lookup_file ( *file);347 struct file *f = lookup_file (file); 403 348 not_target = f == 0 || !f->is_target; 404 349 } 405 350 406 flen = strlen ( *file);351 flen = strlen (file); 407 352 408 353 /* 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 tothe 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, '/'); 413 358 #ifdef HAVE_DOS_PATHS 414 359 /* We need the rightmost slash or backslash. */ 415 360 { 416 c har *bslash = strrchr(*file, '\\');361 const char *bslash = strrchr(file, '\\'); 417 362 if (!n || bslash > n) 418 363 n = bslash; 419 364 } 420 365 #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; 423 368 if (name_dplen > 0) 424 369 flen -= name_dplen + 1; 425 370 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); 431 375 432 376 /* Try each VPATH entry. */ … … 434 378 { 435 379 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. */ 440 385 vlen = strlen (vpath[i]); 441 bcopy (vpath[i], n, vlen);442 n+= vlen;386 memcpy (p, vpath[i], vlen); 387 p += vlen; 443 388 444 389 /* Add the directory prefix already in *FILE. */ … … 446 391 { 447 392 #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; 452 397 } 453 398 454 399 #ifdef HAVE_DOS_PATHS 455 400 /* 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] = '/'; 458 403 #endif 459 404 /* Now add the name-within-directory at the end of NAME. */ 460 405 #ifndef VMS 461 if ( n != name && n[-1] != '/')406 if (p != name && p[-1] != '/') 462 407 { 463 * n= '/';464 bcopy (filename, n + 1, flen + 1);408 *p = '/'; 409 memcpy (p + 1, filename, flen + 1); 465 410 } 466 411 else 467 412 #endif 468 bcopy (filename, n, flen + 1);413 memcpy (p, filename, flen + 1); 469 414 470 415 /* Check if the file is mentioned in a makefile. If *FILE is not … … 513 458 /* Clobber a null into the name at the last slash. 514 459 Now NAME is the name of the directory to look in. */ 515 * n= '\0';460 *p = '\0'; 516 461 517 462 /* We know the directory is in the hash table now because either … … 534 479 #ifndef VMS 535 480 /* Put the slash back in NAME. */ 536 * n= '/';481 *p = '/'; 537 482 #endif 538 483 … … 557 502 558 503 /* 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 564 505 UNKNOWN_MTIME to indicate this. */ 565 506 if (mtime_ptr != 0) 566 507 *mtime_ptr = UNKNOWN_MTIME; 567 508 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); 570 512 } 571 513 } 572 514 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 524 const char * 525 vpath_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 574 554 return 0; 575 555 } … … 581 561 print_vpath_data_base (void) 582 562 { 583 registerunsigned int nvpaths;584 registerstruct vpath *v;563 unsigned int nvpaths; 564 struct vpath *v; 585 565 586 566 puts (_("\n# VPATH Search Paths\n")); … … 609 589 else 610 590 { 611 registerchar **path = general_vpath->searchpath;612 registerunsigned int i;591 const char **path = general_vpath->searchpath; 592 unsigned int i; 613 593 614 594 fputs (_("\n# General (`VPATH' variable) search path:\n# "), stdout); -
trunk/src/gmakenew/w32/include/pathstuff.h
r503 r903 19 19 #define _PATHSTUFF_H 20 20 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);21 char *convert_Path_to_windows32(char *Path, char to_delim); 22 char *convert_vpath_to_windows32(char *Path, char to_delim); 23 char *w32ify(const char *filename, int resolve); 24 char *getcwd_fs(char *buf, int len); 25 25 26 26 #endif -
trunk/src/gmakenew/w32/pathstuff.c
r728 r903 82 82 } 83 83 84 /* 84 /* 85 85 * Corrects the case of a path. 86 86 * Expects a fullpath! 87 87 * Added by bird for the $(abspath ) function and w32ify 88 88 */ 89 void 89 void 90 90 w32_fixcase(char *pszPath) 91 91 { … … 105 105 #else 106 106 # define my_assert(expr) do {} while (0) 107 #endif 108 107 #endif 108 109 109 char *psz = pszPath; 110 110 if (*psz == '/' || *psz == '\\') … … 191 191 192 192 /* 193 * Pointing to the first char after the unc or drive specifier, 193 * Pointing to the first char after the unc or drive specifier, 194 194 * or in case of a cache hit, the first non-matching char (following a slash of course). 195 195 */ … … 261 261 */ 262 262 char * 263 w32ify(c har *filename, int resolve)263 w32ify(const char *filename, int resolve) 264 264 { 265 265 static char w32_path[FILENAME_MAX]; … … 293 293 294 294 #undef stat 295 /* 296 * Workaround for directory names with trailing slashes. 295 /* 296 * Workaround for directory names with trailing slashes. 297 297 * Added by bird reasons stated. 298 298 */ 299 int 299 int 300 300 my_stat(const char *path, struct stat *st) 301 301 {
Note:
See TracChangeset
for help on using the changeset viewer.