Changeset 900 in kBuild for vendor/gnumake/current/expand.c
- Timestamp:
- May 23, 2007 3:13:11 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/expand.c
r501 r900 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);441 442 tmp = (char *)alloca (end - str + 1);443 bcopy (str, tmp, end - str);451 return allocated_variable_expand (str); 452 453 tmp = alloca (end - str + 1); 454 memcpy (tmp, str, end - str); 444 455 tmp[end - str] = '\0'; 445 456 … … 452 463 453 464 char * 454 variable_expand_for_file (c har *line, struct file *file)465 variable_expand_for_file (const char *line, struct file *file) 455 466 { 456 467 char *result; … … 543 554 544 555 char * 545 allocated_variable_expand_for_file (c har *line, struct file *file)556 allocated_variable_expand_for_file (const char *line, struct file *file) 546 557 { 547 558 char *value;
Note:
See TracChangeset
for help on using the changeset viewer.