| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
#include "make.h" |
|---|
| 20 |
|
|---|
| 21 |
#include <assert.h> |
|---|
| 22 |
|
|---|
| 23 |
#include <glob.h> |
|---|
| 24 |
|
|---|
| 25 |
#include "dep.h" |
|---|
| 26 |
#include "filedef.h" |
|---|
| 27 |
#include "job.h" |
|---|
| 28 |
#include "commands.h" |
|---|
| 29 |
#include "variable.h" |
|---|
| 30 |
#include "rule.h" |
|---|
| 31 |
#include "debug.h" |
|---|
| 32 |
#include "hash.h" |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
#ifndef WINDOWS32 |
|---|
| 36 |
#ifndef _AMIGA |
|---|
| 37 |
#ifndef VMS |
|---|
| 38 |
#include <pwd.h> |
|---|
| 39 |
#else |
|---|
| 40 |
struct passwd *getpwnam PARAMS ((char *name)); |
|---|
| 41 |
#endif |
|---|
| 42 |
#endif |
|---|
| 43 |
#endif |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
struct ebuffer |
|---|
| 50 |
{ |
|---|
| 51 |
char *buffer; |
|---|
| 52 |
char *bufnext; |
|---|
| 53 |
char *bufstart; |
|---|
| 54 |
unsigned int size; |
|---|
| 55 |
FILE *fp; |
|---|
| 56 |
struct floc floc; |
|---|
| 57 |
}; |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
enum make_word_type |
|---|
| 61 |
{ |
|---|
| 62 |
w_bogus, w_eol, w_static, w_variable, w_colon, w_dcolon, w_semicolon, |
|---|
| 63 |
w_varassign |
|---|
| 64 |
}; |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
struct conditionals |
|---|
| 76 |
{ |
|---|
| 77 |
unsigned int if_cmds; |
|---|
| 78 |
unsigned int allocated; |
|---|
| 79 |
char *ignoring; |
|---|
| 80 |
0=interpreting, 1=not yet interpreted, |
|---|
| 81 |
2=already interpreted */ |
|---|
| 82 |
char *seen_else; |
|---|
| 83 |
}; |
|---|
| 84 |
|
|---|
| 85 |
static struct conditionals toplevel_conditionals; |
|---|
| 86 |
static struct conditionals *conditionals = &toplevel_conditionals; |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
static char *default_include_directories[] = |
|---|
| 92 |
{ |
|---|
| 93 |
#if defined(WINDOWS32) && !defined(INCLUDEDIR) |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
#define INCLUDEDIR "." |
|---|
| 99 |
#endif |
|---|
| 100 |
INCLUDEDIR, |
|---|
| 101 |
#ifndef _AMIGA |
|---|
| 102 |
"/usr/gnu/include", |
|---|
| 103 |
"/usr/local/include", |
|---|
| 104 |
"/usr/include", |
|---|
| 105 |
#endif |
|---|
| 106 |
0 |
|---|
| 107 |
}; |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
static char **include_directories; |
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
static unsigned int max_incl_len; |
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
const struct floc *reading_file = 0; |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
static struct dep *read_makefiles = 0; |
|---|
| 125 |
|
|---|
| 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)); |
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
struct dep * |
|---|
| 151 |
read_all_makefiles (char **makefiles) |
|---|
| 152 |
{ |
|---|
| 153 |
unsigned int num_makefiles = 0; |
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
define_variable ("MAKEFILE_LIST", sizeof ("MAKEFILE_LIST")-1, "", o_file, 0); |
|---|
| 159 |
|
|---|
| 160 |
DB (DB_BASIC, (_("Reading makefiles...\n"))); |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
{ |
|---|
| 167 |
char *value; |
|---|
| 168 |
char *name, *p; |
|---|
| 169 |
unsigned int length; |
|---|
| 170 |
|
|---|
| 171 |
{ |
|---|
| 172 |
|
|---|
| 173 |
int save = warn_undefined_variables_flag; |
|---|
| 174 |
warn_undefined_variables_flag = 0; |
|---|
| 175 |
|
|---|
| 176 |
value = allocated_variable_expand ("$(MAKEFILES)"); |
|---|
| 177 |
|
|---|
| 178 |
warn_undefined_variables_flag = save; |
|---|
| 179 |
} |
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
p = value; |
|---|
| 184 |
|
|---|
| 185 |
while ((name = find_next_token (&p, &length)) != 0) |
|---|
| 186 |
{ |
|---|
| 187 |
if (*p != '\0') |
|---|
| 188 |
*p++ = '\0'; |
|---|
| 189 |
eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE); |
|---|
| 190 |
} |
|---|
| 191 |
|
|---|
| 192 |
free (value); |
|---|
| 193 |
} |
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
if (makefiles != 0) |
|---|
| 198 |
while (*makefiles != 0) |
|---|
| 199 |
{ |
|---|
| 200 |
struct dep *tail = read_makefiles; |
|---|
| 201 |
register struct dep *d; |
|---|
| 202 |
|
|---|
| 203 |
if (! eval_makefile (*makefiles, 0)) |
|---|
| 204 |
perror_with_name ("", *makefiles); |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
d = read_makefiles; |
|---|
| 208 |
while (d->next != tail) |
|---|
| 209 |
d = d->next; |
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
*makefiles = dep_name (d); |
|---|
| 213 |
++num_makefiles; |
|---|
| 214 |
++makefiles; |
|---|
| 215 |
} |
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
if (num_makefiles == 0) |
|---|
| 220 |
{ |
|---|
| 221 |
static char *default_makefiles[] = |
|---|
| 222 |
#ifdef VMS |
|---|
| 223 |
|
|---|
| 224 |
{ "makefile.vms", "gnumakefile.", "makefile.", 0 }; |
|---|
| 225 |
#else |
|---|
| 226 |
#ifdef _AMIGA |
|---|
| 227 |
{ "GNUmakefile", "Makefile", "SMakefile", 0 }; |
|---|
| 228 |
#else |
|---|
| 229 |
{ "GNUmakefile", "makefile", "Makefile", 0 }; |
|---|
| 230 |
#endif |
|---|
| 231 |
#endif |
|---|
| 232 |
register char **p = default_makefiles; |
|---|
| 233 |
while (*p != 0 && !file_exists_p (*p)) |
|---|
| 234 |
++p; |
|---|
| 235 |
|
|---|
| 236 |
if (*p != 0) |
|---|
| 237 |
{ |
|---|
| 238 |
if (! eval_makefile (*p, 0)) |
|---|
| 239 |
perror_with_name ("", *p); |
|---|
| 240 |
} |
|---|
| 241 |
else |
|---|
| 242 |
{ |
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
struct dep *tail = read_makefiles; |
|---|
| 246 |
|
|---|
| 247 |
while (tail != 0 && tail->next != 0) |
|---|
| 248 |
tail = tail->next; |
|---|
| 249 |
for (p = default_makefiles; *p != 0; ++p) |
|---|
| 250 |
{ |
|---|
| 251 |
struct dep *d = alloc_dep (); |
|---|
| 252 |
d->file = enter_file (*p); |
|---|
| 253 |
d->file->dontcare = 1; |
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
d->changed = RM_DONTCARE; |
|---|
| 257 |
if (tail == 0) |
|---|
| 258 |
read_makefiles = d; |
|---|
| 259 |
else |
|---|
| 260 |
tail->next = d; |
|---|
| 261 |
tail = d; |
|---|
| 262 |
} |
|---|
| 263 |
if (tail != 0) |
|---|
| 264 |
tail->next = 0; |
|---|
| 265 |
} |
|---|
| 266 |
} |
|---|
| 267 |
|
|---|
| 268 |
return read_makefiles; |
|---|
| 269 |
} |
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 |
static struct conditionals * |
|---|
| 274 |
install_conditionals (struct conditionals *new) |
|---|
| 275 |
{ |
|---|
| 276 |
struct conditionals *save = conditionals; |
|---|
| 277 |
|
|---|
| 278 |
bzero ((char *) new, sizeof (*new)); |
|---|
| 279 |
conditionals = new; |
|---|
| 280 |
|
|---|
| 281 |
return save; |
|---|
| 282 |
} |
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
static void |
|---|
| 287 |
restore_conditionals (struct conditionals *saved) |
|---|
| 288 |
{ |
|---|
| 289 |
|
|---|
| 290 |
if (conditionals->ignoring) |
|---|
| 291 |
free (conditionals->ignoring); |
|---|
| 292 |
if (conditionals->seen_else) |
|---|
| 293 |
free (conditionals->seen_else); |
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 |
conditionals = saved; |
|---|
| 297 |
} |
|---|
| 298 |
|
|---|
| 299 |
static int |
|---|
| 300 |
eval_makefile (char *filename, int flags) |
|---|
| 301 |
{ |
|---|
| 302 |
struct dep *deps; |
|---|
| 303 |
struct ebuffer ebuf; |
|---|
| 304 |
const struct floc *curfile; |
|---|
| 305 |
char *expanded = 0; |
|---|
| 306 |
char *included = 0; |
|---|
| 307 |
int makefile_errno; |
|---|
| 308 |
int r; |
|---|
| 309 |
|
|---|
| 310 |
ebuf.floc.filenm = strcache_add (filename); |
|---|
| 311 |
ebuf.floc.lineno = 1; |
|---|
| 312 |
|
|---|
| 313 |
if (ISDB (DB_VERBOSE)) |
|---|
| 314 |
{ |
|---|
| 315 |
printf (_("Reading makefile `%s'"), filename); |
|---|
| 316 |
if (flags & RM_NO_DEFAULT_GOAL) |
|---|
| 317 |
printf (_(" (no default goal)")); |
|---|
| 318 |
if (flags & RM_INCLUDED) |
|---|
| 319 |
printf (_(" (search path)")); |
|---|
| 320 |
if (flags & RM_DONTCARE) |
|---|
| 321 |
printf (_(" (don't care)")); |
|---|
| 322 |
if (flags & RM_NO_TILDE) |
|---|
| 323 |
printf (_(" (no ~ expansion)")); |
|---|
| 324 |
puts ("..."); |
|---|
| 325 |
} |
|---|
| 326 |
|
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 |
if (!(flags & RM_NO_TILDE) && filename[0] == '~') |
|---|
| 332 |
{ |
|---|
| 333 |
expanded = tilde_expand (filename); |
|---|
| 334 |
if (expanded != 0) |
|---|
| 335 |
filename = expanded; |
|---|
| 336 |
} |
|---|
| 337 |
|
|---|
| 338 |
ebuf.fp = fopen (filename, "r"); |
|---|
| 339 |
|
|---|
| 340 |
makefile_errno = errno; |
|---|
| 341 |
|
|---|
| 342 |
|
|---|
| 343 |
|
|---|
| 344 |
|
|---|
| 345 |
if (ebuf.fp == 0 && (flags & RM_INCLUDED) && *filename != '/') |
|---|
| 346 |
{ |
|---|
| 347 |
register unsigned int i; |
|---|
| 348 |
for (i = 0; include_directories[i] != 0; ++i) |
|---|
| 349 |
{ |
|---|
| 350 |
included = concat (include_directories[i], "/", filename); |
|---|
| 351 |
ebuf.fp = fopen (included, "r"); |
|---|
| 352 |
if (ebuf.fp) |
|---|
| 353 |
{ |
|---|
| 354 |
filename = included; |
|---|
| 355 |
break; |
|---|
| 356 |
} |
|---|
| 357 |
free (included); |
|---|
| 358 |
} |
|---|
| 359 |
|
|---|
| 360 |
if (filename != included) |
|---|
| 361 |
included = 0; |
|---|
| 362 |
} |
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
deps = alloc_dep (); |
|---|
| 366 |
deps->next = read_makefiles; |
|---|
| 367 |
read_makefiles = deps; |
|---|
| 368 |
deps->file = lookup_file (filename); |
|---|
| 369 |
if (deps->file == 0) |
|---|
| 370 |
deps->file = enter_file (xstrdup (filename)); |
|---|
| 371 |
filename = deps->file->name; |
|---|
| 372 |
deps->changed = flags; |
|---|
| 373 |
if (flags & RM_DONTCARE) |
|---|
| 374 |
deps->file->dontcare = 1; |
|---|
| 375 |
|
|---|
| 376 |
if (expanded) |
|---|
| 377 |
free (expanded); |
|---|
| 378 |
if (included) |
|---|
| 379 |
free (included); |
|---|
| 380 |
|
|---|
| 381 |
|
|---|
| 382 |
|
|---|
| 383 |
if (ebuf.fp == 0) |
|---|
| 384 |
{ |
|---|
| 385 |
|
|---|
| 386 |
|
|---|
| 387 |
|
|---|
| 388 |
errno = makefile_errno; |
|---|
| 389 |
return 0; |
|---|
| 390 |
} |
|---|
| 391 |
|
|---|
| 392 |
|
|---|
| 393 |
do_variable_definition (&ebuf.floc, "MAKEFILE_LIST", filename, o_file, |
|---|
| 394 |
f_append, 0); |
|---|
| 395 |
|
|---|
| 396 |
|
|---|
| 397 |
|
|---|
| 398 |
ebuf.size = 200; |
|---|
| 399 |
ebuf.buffer = ebuf.bufnext = ebuf.bufstart = xmalloc (ebuf.size); |
|---|
| 400 |
|
|---|
| 401 |
curfile = reading_file; |
|---|
| 402 |
reading_file = &ebuf.floc; |
|---|
| 403 |
|
|---|
| 404 |
r = eval (&ebuf, !(flags & RM_NO_DEFAULT_GOAL)); |
|---|
| 405 |
|
|---|
| 406 |
reading_file = curfile; |
|---|
| 407 |
|
|---|
| 408 |
fclose (ebuf.fp); |
|---|
| 409 |
|
|---|
| 410 |
free (ebuf.bufstart); |
|---|
| 411 |
alloca (0); |
|---|
| 412 |
return r; |
|---|
| 413 |
} |
|---|
| 414 |
|
|---|
| 415 |
int |
|---|
| 416 |
eval_buffer (char *buffer) |
|---|
| 417 |
{ |
|---|
| 418 |
struct ebuffer ebuf; |
|---|
| 419 |
struct conditionals *saved; |
|---|
| 420 |
struct conditionals new; |
|---|
| 421 |
const struct floc *curfile; |
|---|
| 422 |
int r; |
|---|
| 423 |
|
|---|
| 424 |
|
|---|
| 425 |
|
|---|
| 426 |
ebuf.size = strlen (buffer); |
|---|
| 427 |
ebuf.buffer = ebuf.bufnext = ebuf.bufstart = buffer; |
|---|
| 428 |
ebuf.fp = NULL; |
|---|
| 429 |
|
|---|
| 430 |
ebuf.floc = *reading_file; |
|---|
| 431 |
|
|---|
| 432 |
curfile = reading_file; |
|---|
| 433 |
reading_file = &ebuf.floc; |
|---|
| 434 |
|
|---|
| 435 |
saved = install_conditionals (&new); |
|---|
| 436 |
|
|---|
| 437 |
r = eval (&ebuf, 1); |
|---|
| 438 |
|
|---|
| 439 |
restore_conditionals (saved); |
|---|
| 440 |
|
|---|
| 441 |
reading_file = curfile; |
|---|
| 442 |
|
|---|
| 443 |
alloca (0); |
|---|
| 444 |
return r; |
|---|
| 445 |
} |
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 |
static int |
|---|
| 454 |
eval (struct ebuffer *ebuf, int set_default) |
|---|
| 455 |
{ |
|---|
| 456 |
char *collapsed = 0; |
|---|
| 457 |
unsigned int collapsed_length = 0; |
|---|
| 458 |
unsigned int commands_len = 200; |
|---|
| 459 |
char *commands; |
|---|
| 460 |
unsigned int commands_idx = 0; |
|---|
| 461 |
unsigned int cmds_started, tgts_started; |
|---|
| 462 |
int ignoring = 0, in_ignored_define = 0; |
|---|
| 463 |
int no_targets = 0; |
|---|
| 464 |
struct nameseq *filenames = 0; |
|---|
| 465 |
struct dep *deps = 0; |
|---|
| 466 |
long nlines = 0; |
|---|
| 467 |
int two_colon = 0; |
|---|
| 468 |
char *pattern = 0, *pattern_percent; |
|---|
| 469 |
struct floc *fstart; |
|---|
| 470 |
struct floc fi; |
|---|
| 471 |
|
|---|
| 472 |
#define record_waiting_files() \ |
|---|
| 473 |
do \ |
|---|
| 474 |
{ \ |
|---|
| 475 |
if (filenames != 0) \ |
|---|
| 476 |
{ \ |
|---|
| 477 |
fi.lineno = tgts_started; \ |
|---|
| 478 |
record_files (filenames, pattern, pattern_percent, deps, \ |
|---|
| 479 |
cmds_started, commands, commands_idx, two_colon, \ |
|---|
| 480 |
&fi); \ |
|---|
| 481 |
} \ |
|---|
| 482 |
filenames = 0; \ |
|---|
| 483 |
commands_idx = 0; \ |
|---|
| 484 |
no_targets = 0; \ |
|---|
| 485 |
if (pattern) { free(pattern); pattern = 0; } \ |
|---|
| 486 |
} while (0) |
|---|
| 487 |
|
|---|
| 488 |
pattern_percent = 0; |
|---|
| 489 |
cmds_started = tgts_started = 1; |
|---|
| 490 |
|
|---|
| 491 |
fstart = &ebuf->floc; |
|---|
| 492 |
fi.filenm = ebuf->floc.filenm; |
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
|
|---|
| 497 |
|
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 |
|
|---|
| 504 |
commands = xmalloc (200); |
|---|
| 505 |
|
|---|
| 506 |
while (1) |
|---|
| 507 |
{ |
|---|
| 508 |
unsigned int linelen; |
|---|
| 509 |
char *line; |
|---|
| 510 |
int len; |
|---|
| 511 |
char *p; |
|---|
| 512 |
char *p2; |
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 |
ebuf->floc.lineno += nlines; |
|---|
| 516 |
nlines = readline (ebuf); |
|---|
| 517 |
|
|---|
| 518 |
|
|---|
| 519 |
if (nlines < 0) |
|---|
| 520 |
break; |
|---|
| 521 |
|
|---|
| 522 |
|
|---|
| 523 |
line = ebuf->buffer; |
|---|
| 524 |
if (line[0] == '\0') |
|---|
| 525 |
continue; |
|---|
| 526 |
|
|---|
| 527 |
linelen = strlen (line); |
|---|
| 528 |
|
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 |
if (line[0] == '\t') |
|---|
| 532 |
{ |
|---|
| 533 |
if (no_targets) |
|---|
| 534 |
|
|---|
| 535 |
continue; |
|---|
| 536 |
|
|---|
| 537 |
|
|---|
| 538 |
|
|---|
| 539 |
|
|---|
| 540 |
|
|---|
| 541 |
if (filenames != 0) |
|---|
| 542 |
{ |
|---|
| 543 |
if (ignoring) |
|---|
| 544 |
|
|---|
| 545 |
continue; |
|---|
| 546 |
|
|---|
| 547 |
|
|---|
| 548 |
if (commands_idx == 0) |
|---|
| 549 |
cmds_started = ebuf->floc.lineno; |
|---|
| 550 |
|
|---|
| 551 |
if (linelen + 1 + commands_idx > commands_len) |
|---|
| 552 |
{ |
|---|
| 553 |
commands_len = (linelen + 1 + commands_idx) * 2; |
|---|
| 554 |
commands = xrealloc (commands, commands_len); |
|---|
| 555 |
} |
|---|
| 556 |
bcopy (line, &commands[commands_idx], linelen); |
|---|
| 557 |
commands_idx += linelen; |
|---|
| 558 |
commands[commands_idx++] = '\n'; |
|---|
| 559 |
|
|---|
| 560 |
continue; |
|---|
| 561 |
} |
|---|
| 562 |
} |
|---|
| 563 |
|
|---|
| 564 |
|
|---|
| 565 |
|
|---|
| 566 |
|
|---|
| 567 |
|
|---|
| 568 |
if (collapsed_length < linelen+1) |
|---|
| 569 |
{ |
|---|
| 570 |
collapsed_length = linelen+1; |
|---|
| 571 |
if (collapsed) |
|---|
| 572 |
free ((char *)collapsed); |
|---|
| 573 |
collapsed = (char *) xmalloc (collapsed_length); |
|---|
| 574 |
} |
|---|
| 575 |
strcpy (collapsed, line); |
|---|
| 576 |
|
|---|
| 577 |
collapse_continuations (collapsed); |
|---|
| 578 |
remove_comments (collapsed); |
|---|
| 579 |
|
|---|
| 580 |
|
|---|
| 581 |
#define word1eq(s) (len == sizeof(s)-1 && strneq (s, p, sizeof(s)-1)) |
|---|
| 582 |
p = collapsed; |
|---|
| 583 |
while (isspace ((unsigned char)*p)) |
|---|
| 584 |
++p; |
|---|
| 585 |
|
|---|
| 586 |
if (*p == '\0') |
|---|
| 587 |
|
|---|
| 588 |
continue; |
|---|
| 589 |
|
|---|
| 590 |
|
|---|
| 591 |
|
|---|
| 592 |
|
|---|
| 593 |
|
|---|
| 594 |
for (p2 = p+1; *p2 != '\0' && !isspace ((unsigned char)*p2); ++p2) |
|---|
| 595 |
; |
|---|
| 596 |
len = p2 - p; |
|---|
| 597 |
|
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 |
|
|---|
| 601 |
while (isspace ((unsigned char)*p2)) |
|---|
| 602 |
++p2; |
|---|
| 603 |
|
|---|
| 604 |
if ((p2[0] == ':' || p2[0] == '+' || p2[0] == '=') && p2[1] == '\0') |
|---|
| 605 |
{ |
|---|
| 606 |
|
|---|
| 607 |
if (ignoring) |
|---|
| 608 |
continue; |
|---|
| 609 |
|
|---|
| 610 |
goto skip_conditionals; |
|---|
| 611 |
} |
|---|
| 612 |
|
|---|
| 613 |
|
|---|
| 614 |
|
|---|
| 615 |
|
|---|
| 616 |
|
|---|
| 617 |
if (!in_ignored_define) |
|---|
| 618 |
{ |
|---|
| 619 |
int i = conditional_line (p, len, fstart); |
|---|
| 620 |
if (i != -2) |
|---|
| 621 |
{ |
|---|
| 622 |
if (i == -1) |
|---|
| 623 |
fatal (fstart, _("invalid syntax in conditional")); |
|---|
| 624 |
|
|---|
| 625 |
ignoring = i; |
|---|
| 626 |
continue; |
|---|
| 627 |
} |
|---|
| 628 |
} |
|---|
| 629 |
|
|---|
| 630 |
if (word1eq ("endef")) |
|---|
| 631 |
{ |
|---|
| 632 |
if (!in_ignored_define) |
|---|
| 633 |
fatal (fstart, _("extraneous `endef'")); |
|---|
| 634 |
in_ignored_define = 0; |
|---|
| 635 |
continue; |
|---|
| 636 |
} |
|---|
| 637 |
|
|---|
| 638 |
if (word1eq ("define")) |
|---|
| 639 |
{ |
|---|
| 640 |
if (ignoring) |
|---|
| 641 |
in_ignored_define = 1; |
|---|
| 642 |
else |
|---|
| 643 |
{ |
|---|
| 644 |
if (*p2 == '\0') |
|---|
| 645 |
fatal (fstart, _("empty variable name")); |
|---|
| 646 |
|
|---|
| 647 |
|
|---|
| 648 |
|
|---|
| 649 |
|
|---|
| 650 |
|
|---|
| 651 |
p = strchr (p2, '\0'); |
|---|
| 652 |
while (isblank ((unsigned char)p[-1])) |
|---|
| 653 |
--p; |
|---|
| 654 |
do_define (p2, p - p2, o_file, ebuf); |
|---|
| 655 |
} |
|---|
| 656 |
continue; |
|---|
| 657 |
} |
|---|
| 658 |
|
|---|
| 659 |
if (word1eq ("override")) |
|---|
| 660 |
{ |
|---|
| 661 |
if (*p2 == '\0') |
|---|
| 662 |
error (fstart, _("empty `override' directive")); |
|---|
| 663 |
|
|---|
| 664 |
if (strneq (p2, "define", 6) |
|---|
| 665 |
&& (isblank ((unsigned char)p2[6]) || p2[6] == '\0')) |
|---|
| 666 |
{ |
|---|
| 667 |
if (ignoring) |
|---|
| 668 |
in_ignored_define = 1; |
|---|
| 669 |
else |
|---|
| 670 |
{ |
|---|
| 671 |
p2 = next_token (p2 + 6); |
|---|
| 672 |
if (*p2 == '\0') |
|---|
| 673 |
fatal (fstart, _("empty variable name")); |
|---|
| 674 |
|
|---|
| 675 |
|
|---|
| 676 |
|
|---|
| 677 |
|
|---|
| 678 |
|
|---|
| 679 |
p = strchr (p2, '\0'); |
|---|
| 680 |
while (isblank ((unsigned char)p[-1])) |
|---|
| 681 |
--p; |
|---|
| 682 |
do_define (p2, p - p2, o_override, ebuf); |
|---|
| 683 |
} |
|---|
| 684 |
} |
|---|
| 685 |
else if (!ignoring |
|---|
| 686 |
&& !try_variable_definition (fstart, p2, o_override, 0)) |
|---|
| 687 |
error (fstart, _("invalid `override' directive")); |
|---|
| 688 |
|
|---|
| 689 |
continue; |
|---|
| 690 |
} |
|---|
| 691 |
|
|---|
| 692 |
if (ignoring) |
|---|
| 693 |
|
|---|
| 694 |
|
|---|
| 695 |
continue; |
|---|
| 696 |
|
|---|
| 697 |
if (word1eq ("export")) |
|---|
| 698 |
{ |
|---|
| 699 |
|
|---|
| 700 |
if (*p2 == '\0') |
|---|
| 701 |
export_all_variables = 1; |
|---|
| 702 |
else |
|---|
| 703 |
{ |
|---|
| 704 |
struct variable *v; |
|---|
| 705 |
|
|---|
| 706 |
v = try_variable_definition (fstart, p2, o_file, 0); |
|---|
| 707 |
if (v != 0) |
|---|
| 708 |
v->export = v_export; |
|---|
| 709 |
else |
|---|
| 710 |
{ |
|---|
| 711 |
unsigned int len; |
|---|
| 712 |
char *ap; |
|---|
| 713 |
|
|---|
| 714 |
|
|---|
| 715 |
|
|---|
| 716 |
p2 = ap = allocated_variable_expand (p2); |
|---|
| 717 |
|
|---|
| 718 |
for (p = find_next_token (&p2, &len); p != 0; |
|---|
| 719 |
p = find_next_token (&p2, &len)) |
|---|
| 720 |
{ |
|---|
| 721 |
v = lookup_variable (p, len); |
|---|
| 722 |
if (v == 0) |
|---|
| 723 |
v = define_variable_loc (p, len, "", o_file, 0, |
|---|
| 724 |
fstart); |
|---|
| 725 |
v->export = v_export; |
|---|
| 726 |
} |
|---|
| 727 |
|
|---|
| 728 |
free (ap); |
|---|
| 729 |
} |
|---|
| 730 |
} |
|---|
| 731 |
goto rule_complete; |
|---|
| 732 |
} |
|---|
| 733 |
|
|---|
| 734 |
if (word1eq ("unexport")) |
|---|
| 735 |
{ |
|---|
| 736 |
if (*p2 == '\0') |
|---|
| 737 |
export_all_variables = 0; |
|---|
| 738 |
else |
|---|
| 739 |
{ |
|---|
| 740 |
unsigned int len; |
|---|
| 741 |
struct variable *v; |
|---|
| 742 |
char *ap; |
|---|
| 743 |
|
|---|
| 744 |
|
|---|
| 745 |
|
|---|
| 746 |
p2 = ap = allocated_variable_expand (p2); |
|---|
| 747 |
|
|---|
| 748 |
for (p = find_next_token (&p2, &len); p != 0; |
|---|
| 749 |
p = find_next_token (&p2, &len)) |
|---|
| 750 |
{ |
|---|
| 751 |
v = lookup_variable (p, len); |
|---|
| 752 |
if (v == 0) |
|---|
| 753 |
v = define_variable_loc (p, len, "", o_file, 0, fstart); |
|---|
| 754 |
|
|---|
| 755 |
v->export = v_noexport; |
|---|
| 756 |
} |
|---|
| 757 |
|
|---|
| 758 |
free (ap); |
|---|
| 759 |
} |
|---|
| 760 |
goto rule_complete; |
|---|
| 761 |
} |
|---|
| 762 |
|
|---|
| 763 |
skip_conditionals: |
|---|
| 764 |
if (word1eq ("vpath")) |
|---|
| 765 |
{ |
|---|
| 766 |
char *pattern; |
|---|
| 767 |
unsigned int len; |
|---|
| 768 |
p2 = variable_expand (p2); |
|---|
| 769 |
p = find_next_token (&p2, &len); |
|---|
| 770 |
if (p != 0) |
|---|
| 771 |
{ |
|---|
| 772 |
pattern = savestring (p, len); |
|---|
| 773 |
p = find_next_token (&p2, &len); |
|---|
| 774 |
|
|---|
| 775 |
|
|---|
| 776 |
} |
|---|
| 777 |
else |
|---|
| 778 |
|
|---|
| 779 |
pattern = 0; |
|---|
| 780 |
construct_vpath_list (pattern, p); |
|---|
| 781 |
if (pattern != 0) |
|---|
| 782 |
free (pattern); |
|---|
| 783 |
|
|---|
| 784 |
goto rule_complete; |
|---|
| 785 |
} |
|---|
| 786 |
|
|---|
| 787 |
if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude")) |
|---|
| 788 |
{ |
|---|
| 789 |
|
|---|
| 790 |
|
|---|
| 791 |
struct conditionals *save; |
|---|
| 792 |
struct conditionals new_conditionals; |
|---|
| 793 |
struct nameseq *files; |
|---|
| 794 |
|
|---|
| 795 |
|
|---|
| 796 |
int noerror = (p[0] != 'i'); |
|---|
| 797 |
|
|---|
| 798 |
p = allocated_variable_expand (p2); |
|---|
| 799 |
|
|---|
| 800 |
|
|---|
| 801 |
if (*p == '\0') |
|---|
| 802 |
{ |
|---|
| 803 |
free (p); |
|---|
| 804 |
continue; |
|---|
| 805 |
} |
|---|
| 806 |
|
|---|
| 807 |
|
|---|
| 808 |
p2 = p; |
|---|
| 809 |
files = multi_glob (parse_file_seq (&p2, '\0', |
|---|
| 810 |
sizeof (struct nameseq), |
|---|
| 811 |
1), |
|---|
| 812 |
sizeof (struct nameseq)); |
|---|
| 813 |
free (p); |
|---|
| 814 |
|
|---|
| 815 |
|
|---|
| 816 |
|
|---|
| 817 |
save = install_conditionals (&new_conditionals); |
|---|
| 818 |
|
|---|
| 819 |
|
|---|
| 820 |
|
|---|
| 821 |
record_waiting_files (); |
|---|
| 822 |
|
|---|
| 823 |
|
|---|
| 824 |
while (files != 0) |
|---|
| 825 |
{ |
|---|
| 826 |
struct nameseq *next = files->next; |
|---|
| 827 |
char *name = files->name; |
|---|
| 828 |
int r; |
|---|
| 829 |
|
|---|
| 830 |
free ((char *)files); |
|---|
| 831 |
files = next; |
|---|
| 832 |
|
|---|
| 833 |
r = eval_makefile (name, (RM_INCLUDED | RM_NO_TILDE |
|---|
| 834 |
| (noerror ? RM_DONTCARE : 0))); |
|---|
| 835 |
if (!r && !noerror) |
|---|
| 836 |
error (fstart, "%s: %s", name, strerror (errno)); |
|---|
| 837 |
free (name); |
|---|
| 838 |
} |
|---|
| 839 |
|
|---|
| 840 |
|
|---|
| 841 |
restore_conditionals (save); |
|---|
| 842 |
|
|---|
| 843 |
goto rule_complete; |
|---|
| 844 |
} |
|---|
| 845 |
|
|---|
| 846 |
if (try_variable_definition (fstart, p, o_file, 0)) |
|---|
| 847 |
|
|---|
| 848 |
goto rule_complete; |
|---|
| 849 |
|
|---|
| 850 |
|
|---|
| 851 |
|
|---|
| 852 |
|
|---|
| 853 |
if (line[0] == '\t') |
|---|
| 854 |
fatal(fstart, _("commands commence before first target")); |
|---|
| 855 |
|
|---|
| 856 |
|
|---|
| 857 |
|
|---|
| 858 |
|
|---|
| 859 |
|
|---|
| 860 |
|
|---|
| 861 |
|
|---|
| 862 |
|
|---|
| 863 |
|
|---|
| 864 |
|
|---|
| 865 |
|
|---|
| 866 |
{ |
|---|
| 867 |
enum make_word_type wtype; |
|---|
| 868 |
enum variable_origin v_origin; |
|---|
| 869 |
int exported; |
|---|
| 870 |
char *cmdleft, *semip, *lb_next; |
|---|
| 871 |
unsigned int len, plen = 0; |
|---|
| 872 |
char *colonp; |
|---|
| 873 |
const char *end, *beg; |
|---|
| 874 |
|
|---|
| 875 |
|
|---|
| 876 |
|
|---|
| 877 |
record_waiting_files (); |
|---|
| 878 |
tgts_started = fstart->lineno; |
|---|
| 879 |
|
|---|
| 880 |
|
|---|
| 881 |
|
|---|
| 882 |
cmdleft = find_char_unquote (line, ';', '#', 0, 1); |
|---|
| 883 |
if (cmdleft != 0 && *cmdleft == '#') |
|---|
| 884 |
{ |
|---|
| 885 |
|
|---|
| 886 |
*cmdleft = '\0'; |
|---|
| 887 |
cmdleft = 0; |
|---|
| 888 |
} |
|---|
| 889 |
else if (cmdleft != 0) |
|---|
| 890 |
|
|---|
| 891 |
*(cmdleft++) = '\0'; |
|---|
| 892 |
semip = cmdleft; |
|---|
| 893 |
|
|---|
| 894 |
collapse_continuations (line); |
|---|
| 895 |
|
|---|
| 896 |
|
|---|
| 897 |
|
|---|
| 898 |
|
|---|
| 899 |
|
|---|
| 900 |
wtype = get_next_mword(line, NULL, &lb_next, &len); |
|---|
| 901 |
switch (wtype) |
|---|
| 902 |
{ |
|---|
| 903 |
case w_eol: |
|---|
| 904 |
if (cmdleft != 0) |
|---|
| 905 |
fatal(fstart, _("missing rule before commands")); |
|---|
| 906 |
|
|---|
| 907 |
|
|---|
| 908 |
continue; |
|---|
| 909 |
|
|---|
| 910 |
case w_colon: |
|---|
| 911 |
case w_dcolon: |
|---|
| 912 |
|
|---|
| 913 |
|
|---|
| 914 |
no_targets = 1; |
|---|
| 915 |
continue; |
|---|
| 916 |
|
|---|
| 917 |
default: |
|---|
| 918 |
break; |
|---|
| 919 |
} |
|---|
| 920 |
|
|---|
| 921 |
p2 = variable_expand_string(NULL, lb_next, len); |
|---|
| 922 |
|
|---|
| 923 |
while (1) |
|---|
| 924 |
{ |
|---|
| 925 |
lb_next += len; |
|---|
| 926 |
if (cmdleft == 0) |
|---|
| 927 |
{ |
|---|
| 928 |
|
|---|
| 929 |
cmdleft = find_char_unquote (p2, ';', 0, 0, 0); |
|---|
| 930 |
|
|---|
| 931 |
if (cmdleft != 0) |
|---|
| 932 |
{ |
|---|
| 933 |
unsigned long p2_off = p2 - variable_buffer; |
|---|
| 934 |
unsigned long cmd_off = cmdleft - variable_buffer; |
|---|
| 935 |
char *pend = p2 + strlen(p2); |
|---|
| 936 |
|
|---|
| 937 |
|
|---|
| 938 |
|
|---|
| 939 |
*cmdleft = '\0'; |
|---|
| 940 |
|
|---|
| 941 |
|
|---|
| 942 |
|
|---|
| 943 |
|
|---|
| 944 |
|
|---|
| 945 |
|
|---|
| 946 |
|
|---|
| 947 |
|
|---|
| 948 |
|
|---|
| 949 |
(void)variable_expand_string(pend, lb_next, (long)-1); |
|---|
| 950 |
lb_next += strlen(lb_next); |
|---|
| 951 |
p2 = variable_buffer + p2_off; |
|---|
| 952 |
cmdleft = variable_buffer + cmd_off + 1; |
|---|
| 953 |
} |
|---|
| 954 |
} |
|---|
| 955 |
|
|---|
| 956 |
colonp = find_char_unquote(p2, ':', 0, 0, 0); |
|---|
| 957 |
#ifdef HAVE_DOS_PATHS |
|---|
| 958 |
|
|---|
| 959 |
|
|---|
| 960 |
|
|---|
| 961 |
|
|---|
| 962 |
while (colonp && (colonp[1] == '/' || colonp[1] == '\\') && |
|---|
| 963 |
colonp > p2 && isalpha ((unsigned char)colonp[-1]) && |
|---|
| 964 |
(colonp == p2 + 1 || strchr (" \t(", colonp[-2]) != 0)) |
|---|
| 965 |
colonp = find_char_unquote(colonp + 1, ':', 0, 0, 0); |
|---|
| 966 |
#endif |
|---|
| 967 |
if (colonp != 0) |
|---|
| 968 |
break; |
|---|
| 969 |
|
|---|
| 970 |
wtype = get_next_mword(lb_next, NULL, &lb_next, &len); |
|---|
| 971 |
if (wtype == w_eol) |
|---|
| 972 |
break; |
|---|
| 973 |
|
|---|
| 974 |
p2 += strlen(p2); |
|---|
| 975 |
*(p2++) = ' '; |
|---|
| 976 |
p2 = variable_expand_string(p2, lb_next, len); |
|---|
| 977 |
|
|---|
| 978 |
|
|---|
| 979 |
|
|---|
| 980 |
} |
|---|
| 981 |
|
|---|
| 982 |
p2 = next_token (variable_buffer); |
|---|
| 983 |
|
|---|
| 984 |
|
|---|
| 985 |
|
|---|
| 986 |
|
|---|
| 987 |
if (wtype == w_eol) |
|---|
| 988 |
{ |
|---|
| 989 |
if (*p2 != '\0') |
|---|
| 990 |
|
|---|
| 991 |
|
|---|
| 992 |
fatal (fstart, _("missing separator%s"), |
|---|
| 993 |
!strneq(line, " ", 8) ? "" |
|---|
| 994 |
: _(" (did you mean TAB instead of 8 spaces?)")); |
|---|
| 995 |
continue; |
|---|
| 996 |
} |
|---|
| 997 |
|
|---|
| 998 |
|
|---|
| 999 |
|
|---|
| 1000 |
*colonp = '\0'; |
|---|
| 1001 |
filenames = multi_glob (parse_file_seq (&p2, '\0', |
|---|
| 1002 |
sizeof (struct nameseq), |
|---|
| 1003 |
1), |
|---|
| 1004 |
sizeof (struct nameseq)); |
|---|
| 1005 |
*p2 = ':'; |
|---|
| 1006 |
|
|---|
| 1007 |
if (!filenames) |
|---|
| 1008 |
{ |
|---|
| 1009 |
|
|---|
| 1010 |
|
|---|
| 1011 |
no_targets = 1; |
|---|
| 1012 |
continue; |
|---|
| 1013 |
} |
|---|
| 1014 |
|
|---|
| 1015 |
assert (*p2 != '\0'); |
|---|
| 1016 |
++p2; |
|---|
| 1017 |
|
|---|
| 1018 |
|
|---|
| 1019 |
two_colon = *p2 == ':'; |
|---|
| 1020 |
if (two_colon) |
|---|
| 1021 |
p2++; |
|---|
| 1022 |
|
|---|
| 1023 |
|
|---|
| 1024 |
|
|---|
| 1025 |
|
|---|
| 1026 |
|
|---|
| 1027 |
if (*lb_next != '\0') |
|---|
| 1028 |
{ |
|---|
| 1029 |
unsigned int l = p2 - variable_buffer; |
|---|
| 1030 |
plen = strlen (p2); |
|---|
| 1031 |
(void) variable_buffer_output (p2+plen, |
|---|
| 1032 |
lb_next, strlen (lb_next)+1); |
|---|
| 1033 |
p2 = variable_buffer + l; |
|---|
| 1034 |
} |
|---|
| 1035 |
|
|---|
| 1036 |
|
|---|
| 1037 |
|
|---|
| 1038 |
|
|---|
| 1039 |
wtype = get_next_mword (p2, NULL, &p, &len); |
|---|
| 1040 |
|
|---|
| 1041 |
v_origin = o_file; |
|---|
| 1042 |
exported = 0; |
|---|
| 1043 |
if (wtype == w_static) |
|---|
| 1044 |
{ |
|---|
| 1045 |
if (word1eq ("override")) |
|---|
| 1046 |
{ |
|---|
| 1047 |
v_origin = o_override; |
|---|
| 1048 |
wtype = get_next_mword (p+len, NULL, &p, &len); |
|---|
| 1049 |
} |
|---|
| 1050 |
else if (word1eq ("export")) |
|---|
| 1051 |
{ |
|---|
| 1052 |
exported = 1; |
|---|
| 1053 |
wtype = get_next_mword (p+len, NULL, &p, &len); |
|---|
| 1054 |
} |
|---|
| 1055 |
} |
|---|
| 1056 |
|
|---|
| 1057 |
if (wtype != w_eol) |
|---|
| 1058 |
wtype = get_next_mword (p+len, NULL, NULL, NULL); |
|---|
| 1059 |
|
|---|
| 1060 |
if (wtype == w_varassign) |
|---|
| 1061 |
{ |
|---|
| 1062 |
|
|---|
| 1063 |
|
|---|
| 1064 |
if (semip) |
|---|
| 1065 |
{ |
|---|
| 1066 |
unsigned int l = p - variable_buffer; |
|---|
| 1067 |
*(--semip) = ';'; |
|---|
| 1068 |
variable_buffer_output (p2 + strlen (p2), |
|---|
| 1069 |
semip, strlen (semip)+1); |
|---|
| 1070 |
p = variable_buffer + l; |
|---|
| 1071 |
} |
|---|
| 1072 |
record_target_var (filenames, p, v_origin, exported, fstart); |
|---|
| 1073 |
filenames = 0; |
|---|
| 1074 |
continue; |
|---|
| 1075 |
} |
|---|
| 1076 |
|
|---|
| 1077 |
|
|---|
| 1078 |
|
|---|
| 1079 |
find_char_unquote (lb_next, '=', 0, 0, 0); |
|---|
| 1080 |
|
|---|
| 1081 |
|
|---|
| 1082 |
no_targets = 0; |
|---|
| 1083 |
|
|---|
| 1084 |
|
|---|
| 1085 |
if (*lb_next != '\0') |
|---|
| 1086 |
{ |
|---|
| 1087 |
unsigned int l = p2 - variable_buffer; |
|---|
| 1088 |
(void) variable_expand_string (p2 + plen, lb_next, (long)-1); |
|---|
| 1089 |
p2 = variable_buffer + l; |
|---|
| 1090 |
|
|---|
| 1091 |
|
|---|
| 1092 |
if (cmdleft == 0) |
|---|
| 1093 |
{ |
|---|
| 1094 |
cmdleft = find_char_unquote (p2, ';', 0, 0, 0); |
|---|
| 1095 |
if (cmdleft != 0) |
|---|
| 1096 |
*(cmdleft++) = '\0'; |
|---|
| 1097 |
} |
|---|
| 1098 |
} |
|---|
| 1099 |
|
|---|
| 1100 |
|
|---|
| 1101 |
p = strchr (p2, ':'); |
|---|
| 1102 |
while (p != 0 && p[-1] == '\\') |
|---|
| 1103 |
{ |
|---|
| 1104 |
register char *q = &p[-1]; |
|---|
| 1105 |
register int backslash = 0; |
|---|
| 1106 |
while (*q-- == '\\') |
|---|
| 1107 |
backslash = !backslash; |
|---|
| 1108 |
if (backslash) |
|---|
| 1109 |
p = strchr (p + 1, ':'); |
|---|
| 1110 |
else |
|---|
| 1111 |
break; |
|---|
| 1112 |
} |
|---|
| 1113 |
#ifdef _AMIGA |
|---|
| 1114 |
|
|---|
| 1115 |
|
|---|
| 1116 |
|
|---|
| 1117 |
|
|---|
| 1118 |
|
|---|
| 1119 |
|
|---|
| 1120 |
|
|---|
| 1121 |
|
|---|
| 1122 |
|
|---|
| 1123 |
|
|---|
| 1124 |
|
|---|
| 1125 |
|
|---|
| 1126 |
if (p && !(isspace ((unsigned char)p[1]) || !p[1] |
|---|
| 1127 |
|| isspace ((unsigned char)p[-1]))) |
|---|
| 1128 |
p = 0; |
|---|
| 1129 |
#endif |
|---|
| 1130 |
#ifdef HAVE_DOS_PATHS |
|---|
| 1131 |
{ |
|---|
| 1132 |
int check_again; |
|---|
| 1133 |
|
|---|
| 1134 |
do { |
|---|
| 1135 |
check_again = 0; |
|---|
| 1136 |
|
|---|
| 1137 |
if (p != 0 && (p[1] == '\\' || p[1] == '/') && |
|---|
| 1138 |
isalpha ((unsigned char)p[-1]) && |
|---|
| 1139 |
(p == p2 + 1 || strchr (" \t:(", p[-2]) != 0)) { |
|---|
| 1140 |
p = strchr (p + 1, ':'); |
|---|
| 1141 |
check_again = 1; |
|---|
| 1142 |
} |
|---|
| 1143 |
} while (check_again); |
|---|
| 1144 |
} |
|---|
| 1145 |
#endif |
|---|
| 1146 |
if (p != 0) |
|---|
| 1147 |
{ |
|---|
| 1148 |
struct nameseq *target; |
|---|
| 1149 |
target = parse_file_seq (&p2, ':', sizeof (struct nameseq), 1); |
|---|
| 1150 |
++p2; |
|---|
| 1151 |
if (target == 0) |
|---|
| 1152 |
fatal (fstart, _("missing target pattern")); |
|---|
| 1153 |
else if (target->next != 0) |
|---|
| 1154 |
fatal (fstart, _("multiple target patterns")); |
|---|
| 1155 |
pattern = target->name; |
|---|
| 1156 |
pattern_percent = find_percent (pattern); |
|---|
| 1157 |
if (pattern_percent == 0) |
|---|
| 1158 |
fatal (fstart, _("target pattern contains no `%%'")); |
|---|
| 1159 |
free ((char *)target); |
|---|
| 1160 |
} |
|---|
| 1161 |
else |
|---|
| 1162 |
pattern = 0; |
|---|
| 1163 |
|
|---|
| 1164 |
|
|---|
| 1165 |
beg = p2; |
|---|
| 1166 |
end = beg + strlen (beg) - 1; |
|---|
| 1167 |
strip_whitespace (&beg, &end); |
|---|
| 1168 |
|
|---|
| 1169 |
if (beg <= end && *beg != '\0') |
|---|
| 1170 |
{ |
|---|
| 1171 |
|
|---|
| 1172 |
deps = alloc_dep (); |
|---|
| 1173 |
deps->name = savestring (beg, end - beg + 1); |
|---|
| 1174 |
} |
|---|
| 1175 |
else |
|---|
| 1176 |
deps = 0; |
|---|
| 1177 |
|
|---|
| 1178 |
commands_idx = 0; |
|---|
| 1179 |
if (cmdleft != 0) |
|---|
| 1180 |
{ |
|---|
| 1181 |
|
|---|
| 1182 |
unsigned int len = strlen (cmdleft); |
|---|
| 1183 |
|
|---|
| 1184 |
cmds_started = fstart->lineno; |
|---|
| 1185 |
|
|---|
| 1186 |
|
|---|
| 1187 |
if (len + 2 > commands_len) |
|---|
| 1188 |
{ |
|---|
| 1189 |
commands_len = (len + 2) * 2; |
|---|
| 1190 |
commands = (char *) xrealloc (commands, commands_len); |
|---|
| 1191 |
} |
|---|
| 1192 |
bcopy (cmdleft, commands, len); |
|---|
| 1193 |
commands_idx += len; |
|---|
| 1194 |
commands[commands_idx++] = '\n'; |
|---|
| 1195 |
} |
|---|
| 1196 |
|
|---|
| 1197 |
|
|---|
| 1198 |
|
|---|
| 1199 |
|
|---|
| 1200 |
|
|---|
| 1201 |
|
|---|
| 1202 |
|
|---|
| 1203 |
|
|---|
| 1204 |
|
|---|
| 1205 |
|
|---|
| 1206 |
|
|---|
| 1207 |
|
|---|
| 1208 |
|
|---|
| 1209 |
|
|---|
| 1210 |
|
|---|
| 1211 |
|
|---|
| 1212 |
|
|---|
| 1213 |
if (**default_goal_name == '\0' && set_default) |
|---|
| 1214 |
{ |
|---|
| 1215 |
char* name; |
|---|
| 1216 |
struct dep *d; |
|---|
| 1217 |
struct nameseq *t = filenames; |
|---|
| 1218 |
|
|---|
| 1219 |
for (; t != 0; t = t->next) |
|---|
| 1220 |
{ |
|---|
| 1221 |
int reject = 0; |
|---|
| 1222 |
name = t->name; |
|---|
| 1223 |
|
|---|
| 1224 |
|
|---|
| 1225 |
if (strchr (name, '%') != 0) |
|---|
| 1226 |
break; |
|---|
| 1227 |
|
|---|
| 1228 |
|
|---|
| 1229 |
|
|---|
| 1230 |
if (*name == '.' && strchr (name, '/') == 0 |
|---|
| 1231 |
#ifdef HAVE_DOS_PATHS |
|---|
| 1232 |
&& strchr (name, '\\') == 0 |
|---|
| 1233 |
#endif |
|---|
| 1234 |
) |
|---|
| 1235 |
continue; |
|---|
| 1236 |
|
|---|
| 1237 |
|
|---|
| 1238 |
|
|---|
| 1239 |
|
|---|
| 1240 |
for (d = suffix_file->deps; d != 0; d = d->next) |
|---|
| 1241 |
{ |
|---|
| 1242 |
register struct dep *d2; |
|---|
| 1243 |
if (*dep_name (d) != '.' && streq (name, dep_name (d))) |
|---|
| 1244 |
{ |
|---|
| 1245 |
reject = 1; |
|---|
| 1246 |
break; |
|---|
| 1247 |
} |
|---|
| 1248 |
for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next) |
|---|
| 1249 |
{ |
|---|
| 1250 |
register unsigned int len = strlen (dep_name (d2)); |
|---|
| 1251 |
if (!strneq (name, dep_name (d2), len)) |
|---|
| 1252 |
continue; |
|---|
| 1253 |
if (streq (name + len, dep_name (d))) |
|---|
| 1254 |
{ |
|---|
| 1255 |
reject = 1; |
|---|
| 1256 |
break; |
|---|
| 1257 |
} |
|---|
| 1258 |
} |
|---|
| 1259 |
|
|---|
| 1260 |
if (reject) |
|---|
| 1261 |
break; |
|---|
| 1262 |
} |
|---|
| 1263 |
|
|---|
| 1264 |
if (!reject) |
|---|
| 1265 |
{ |
|---|
| 1266 |
define_variable_global (".DEFAULT_GOAL", 13, t->name, |
|---|
| 1267 |
o_file, 0, NILF); |
|---|
| 1268 |
break; |
|---|
| 1269 |
} |
|---|
| 1270 |
} |
|---|
| 1271 |
} |
|---|
| 1272 |
|
|---|
| 1273 |
continue; |
|---|
| 1274 |
} |
|---|
| 1275 |
|
|---|
| 1276 |
|
|---|
| 1277 |
|
|---|
| 1278 |
|
|---|
| 1279 |
rule_complete: |
|---|
| 1280 |
record_waiting_files (); |
|---|
| 1281 |
} |
|---|
| 1282 |
|
|---|
| 1283 |
#undef word1eq |
|---|
| 1284 |
|
|---|
| 1285 |
if (conditionals->if_cmds) |
|---|
| 1286 |
fatal (fstart, _("missing `endif'")); |
|---|
| 1287 |
|
|---|
| 1288 |
|
|---|
| 1289 |
record_waiting_files (); |
|---|
| 1290 |
|
|---|
| 1291 |
if (collapsed) |
|---|
| 1292 |
free ((char *) collapsed); |
|---|
| 1293 |
free ((char *) commands); |
|---|
| 1294 |
|
|---|
| 1295 |
return 1; |
|---|
| 1296 |
} |
|---|
| 1297 |
|
|---|
| 1298 |
|
|---|
| 1299 |
|
|---|
| 1300 |
|
|---|
| 1301 |
|
|---|
| 1302 |
static void |
|---|
| 1303 |
remove_comments (char *line) |
|---|
| 1304 |
{ |
|---|
| 1305 |
char *comment; |
|---|
| 1306 |
|
|---|
| 1307 |
comment = find_char_unquote (line, '#', 0, 0, 0); |
|---|
| 1308 |
|
|---|
| 1309 |
if (comment != 0) |
|---|
| 1310 |
|
|---|
| 1311 |
*comment = '\0'; |
|---|
| 1312 |
} |
|---|
| 1313 |
|
|---|
| 1314 |
|
|---|
| 1315 |
|
|---|
| 1316 |
|
|---|
| 1317 |
|
|---|
| 1318 |
static void |
|---|
| 1319 |
do_define (char *name, unsigned int namelen, |
|---|
| 1320 |
enum variable_origin origin, struct ebuffer *ebuf) |
|---|
| 1321 |
{ |
|---|
| 1322 |
struct floc defstart; |
|---|
| 1323 |
long nlines = 0; |
|---|
| 1324 |
int nlevels = 1; |
|---|
| 1325 |
unsigned int length = 100; |
|---|
| 1326 |
char *definition = (char *) xmalloc (length); |
|---|
| 1327 |
unsigned int idx = 0; |
|---|
| 1328 |
char *p; |
|---|
| 1329 |
|
|---|
| 1330 |
|
|---|
| 1331 |
char *var = (char *) alloca (namelen + 1); |
|---|
| 1332 |
bcopy (name, var, namelen); |
|---|
| 1333 |
var[namelen] = '\0'; |
|---|
| 1334 |
var = variable_expand (var); |
|---|
| 1335 |
|
|---|
| 1336 |
defstart = ebuf->floc; |
|---|
| 1337 |
|
|---|
| 1338 |
while (1) |
|---|
| 1339 |
{ |
|---|
| 1340 |
unsigned int len; |
|---|
| 1341 |
char *line; |
|---|
| 1342 |
|
|---|
| 1343 |
nlines = readline (ebuf); |
|---|
| 1344 |
ebuf->floc.lineno += nlines; |
|---|
| 1345 |
|
|---|
| 1346 |
|
|---|
| 1347 |
if (nlines < 0) |
|---|
| 1348 |
break; |
|---|
| 1349 |
|
|---|
| 1350 |
line = ebuf->buffer; |
|---|
| 1351 |
|
|---|
| 1352 |
collapse_continuations (line); |
|---|
| 1353 |
|
|---|
| 1354 |
|
|---|
| 1355 |
|
|---|
| 1356 |
|
|---|
| 1357 |
|
|---|
| 1358 |
if (line[0] != '\t') |
|---|
| 1359 |
{ |
|---|
| 1360 |
p = next_token (line); |
|---|
| 1361 |
len = strlen (p); |
|---|
| 1362 |
|
|---|
| 1363 |
|
|---|
| 1364 |
if ((len == 6 || (len > 6 && isblank ((unsigned char)p[6]))) |
|---|
| 1365 |
&& strneq (p, "define", 6)) |
|---|
| 1366 |
++nlevels; |
|---|
| 1367 |
|
|---|
| 1368 |
|
|---|
| 1369 |
|
|---|
| 1370 |
else if ((len == 5 || (len > 5 && isblank ((unsigned char)p[5]))) |
|---|
| 1371 |
&& strneq (p, "endef", 5)) |
|---|
| 1372 |
{ |
|---|
| 1373 |
p += 5; |
|---|
| 1374 |
remove_comments (p); |
|---|
| 1375 |
if (*next_token (p) != '\0') |
|---|
| 1376 |
error (&ebuf->floc, |
|---|
| 1377 |
_("Extraneous text after `endef' directive")); |
|---|
| 1378 |
|
|---|
| 1379 |
if (--nlevels == 0) |
|---|
| 1380 |
{ |
|---|
| 1381 |
|
|---|
| 1382 |
if (idx == 0) |
|---|
| 1383 |
definition[0] = '\0'; |
|---|
| 1384 |
else |
|---|
| 1385 |
definition[idx - 1] = '\0'; |
|---|
| 1386 |
|
|---|
| 1387 |
|
|---|
| 1388 |
define_variable_global (var, strlen (var), definition, |
|---|
| 1389 |
origin, 1, &defstart); |
|---|
| 1390 |
free (definition); |
|---|
| 1391 |
return; |
|---|
| 1392 |
} |
|---|
| 1393 |
} |
|---|
| 1394 |
} |
|---|
| 1395 |
|
|---|
| 1396 |
|
|---|
| 1397 |
len = strlen (line); |
|---|
| 1398 |
if (idx + len + 1 > length) |
|---|
| 1399 |
{ |
|---|
| 1400 |
length = (idx + len) * 2; |
|---|
| 1401 |
definition = (char *) xrealloc (definition, length + 1); |
|---|
| 1402 |
} |
|---|
| 1403 |
|
|---|
| 1404 |
bcopy (line, &definition[idx], len); |
|---|
| 1405 |
idx += len; |
|---|
| 1406 |
|
|---|
| 1407 |
definition[idx++] = '\n'; |
|---|
| 1408 |
} |
|---|
| 1409 |
|
|---|
| 1410 |
|
|---|
| 1411 |
fatal (&defstart, _("missing `endef', unterminated `define'")); |
|---|
| 1412 |
|
|---|
| 1413 |
|
|---|
| 1414 |
return; |
|---|
| 1415 |
} |
|---|
| 1416 |
|
|---|
| 1417 |
|
|---|
| 1418 |
|
|---|
| 1419 |
|
|---|
| 1420 |
|
|---|
| 1421 |
|
|---|
| 1422 |
|
|---|
| 1423 |
|
|---|
| 1424 |
|
|---|
| 1425 |
|
|---|
| 1426 |
|
|---|
| 1427 |
|
|---|
| 1428 |
|
|---|
| 1429 |
static int |
|---|
| 1430 |
conditional_line (char *line, int len, const struct floc *flocp) |
|---|
| 1431 |
{ |
|---|
| 1432 |
char *cmdname; |
|---|
| 1433 |
enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq, c_else, c_endif } cmdtype; |
|---|
| 1434 |
unsigned int i; |
|---|
| 1435 |
unsigned int o; |
|---|
| 1436 |
|
|---|
| 1437 |
|
|---|
| 1438 |
#define word1eq(s) (len == sizeof(s)-1 && strneq (s, line, sizeof(s)-1)) |
|---|
| 1439 |
#define chkword(s, t) if (word1eq (s)) { cmdtype = (t); cmdname = (s); } |
|---|
| 1440 |
|
|---|
| 1441 |
|
|---|
| 1442 |
chkword ("ifdef", c_ifdef) |
|---|
| 1443 |
else chkword ("ifndef", c_ifndef) |
|---|
| 1444 |
else chkword ("ifeq", c_ifeq) |
|---|
| 1445 |
else chkword ("ifneq", c_ifneq) |
|---|
| 1446 |
else chkword ("else", c_else) |
|---|
| 1447 |
else chkword ("endif", c_endif) |
|---|
| 1448 |
else |
|---|
| 1449 |
return -2; |
|---|
| 1450 |
|
|---|
| 1451 |
|
|---|
| 1452 |
line = next_token (line + len); |
|---|
| 1453 |
|
|---|
| 1454 |
#define EXTRANEOUS() error (flocp, _("Extraneous text after `%s' directive"), cmdname) |
|---|
| 1455 |
|
|---|
| 1456 |
|
|---|
| 1457 |
if (cmdtype == c_endif) |
|---|
| 1458 |
{ |
|---|
| 1459 |
if (*line != '\0') |
|---|
| 1460 |
EXTRANEOUS (); |
|---|
| 1461 |
|
|---|
| 1462 |
if (!conditionals->if_cmds) |
|---|
| 1463 |
fatal (flocp, _("extraneous `%s'"), cmdname); |
|---|
| 1464 |
|
|---|
| 1465 |
--conditionals->if_cmds; |
|---|
| 1466 |
|
|---|
| 1467 |
goto DONE; |
|---|
| 1468 |
} |
|---|
| 1469 |
|
|---|
| 1470 |
|
|---|
| 1471 |
|
|---|
| 1472 |
if (cmdtype == c_else) |
|---|
| 1473 |
{ |
|---|
| 1474 |
const char *p; |
|---|
| 1475 |
|
|---|
| 1476 |
if (!conditionals->if_cmds) |
|---|
| 1477 |
fatal (flocp, _("extraneous `%s'"), cmdname); |
|---|
| 1478 |
|
|---|
| 1479 |
o = conditionals->if_cmds - 1; |
|---|
| 1480 |
|
|---|
| 1481 |
if (conditionals->seen_else[o]) |
|---|
| 1482 |
fatal (flocp, _("only one `else' per conditional")); |
|---|
| 1483 |
|
|---|
| 1484 |
|
|---|
| 1485 |
switch (conditionals->ignoring[o]) |
|---|
| 1486 |
{ |
|---|
| 1487 |
case 0: |
|---|
| 1488 |
|
|---|
| 1489 |
conditionals->ignoring[o] = 2; |
|---|
| 1490 |
break; |
|---|
| 1491 |
case 1: |
|---|
| 1492 |
|
|---|
| 1493 |
conditionals->ignoring[o] = 0; |
|---|
| 1494 |
break; |
|---|
| 1495 |
} |
|---|
| 1496 |
|
|---|
| 1497 |
|
|---|
| 1498 |
if (*line == '\0') |
|---|
| 1499 |
{ |
|---|
| 1500 |
conditionals->seen_else[o] = 1; |
|---|
| 1501 |
goto DONE; |
|---|
| 1502 |
} |
|---|
| 1503 |
|
|---|
| 1504 |
|
|---|
| 1505 |
|
|---|
| 1506 |
|
|---|
| 1507 |
|
|---|
| 1508 |
for (p = line+1; *p != '\0' && !isspace ((unsigned char)*p); ++p) |
|---|
| 1509 |
; |
|---|
| 1510 |
len = p - line; |
|---|
| 1511 |
|
|---|
| 1512 |
|
|---|
| 1513 |
if (word1eq("else") || word1eq("endif") |
|---|
| 1514 |
|| conditional_line (line, len, flocp) < 0) |
|---|
| 1515 |
EXTRANEOUS (); |
|---|
| 1516 |
else |
|---|
| 1517 |
{ |
|---|
| 1518 |
|
|---|
| 1519 |
|
|---|
| 1520 |
if (conditionals->ignoring[o] < 2) |
|---|
| 1521 |
conditionals->ignoring[o] = conditionals->ignoring[o+1]; |
|---|
| 1522 |
--conditionals->if_cmds; |
|---|
| 1523 |
} |
|---|
| 1524 |
|
|---|
| 1525 |
goto DONE; |
|---|
| 1526 |
} |
|---|
| 1527 |
|
|---|
| 1528 |
if (conditionals->allocated == 0) |
|---|
| 1529 |
{ |
|---|
| 1530 |
conditionals->allocated = 5; |
|---|
| 1531 |
conditionals->ignoring = (char *) xmalloc (conditionals->allocated); |
|---|
| 1532 |
conditionals->seen_else = (char *) xmalloc (conditionals->allocated); |
|---|
| 1533 |
} |
|---|
| 1534 |
|
|---|
| 1535 |
o = conditionals->if_cmds++; |
|---|
| 1536 |
if (conditionals->if_cmds > conditionals->allocated) |
|---|
| 1537 |
{ |
|---|
| 1538 |
conditionals->allocated += 5; |
|---|
| 1539 |
conditionals->ignoring = (char *) |
|---|
| 1540 |
xrealloc (conditionals->ignoring, conditionals->allocated); |
|---|
| 1541 |
conditionals->seen_else = (char *) |
|---|
| 1542 |
xrealloc (conditionals->seen_else, conditionals->allocated); |
|---|
| 1543 |
} |
|---|
| 1544 |
|
|---|
| 1545 |
|
|---|
| 1546 |
conditionals->seen_else[o] = 0; |
|---|
| 1547 |
|
|---|
| 1548 |
|
|---|
| 1549 |
for (i = 0; i < o; ++i) |
|---|
| 1550 |
if (conditionals->ignoring[i]) |
|---|
| 1551 |
{ |
|---|
| 1552 |
|
|---|
| 1553 |
|
|---|
| 1554 |
|
|---|
| 1555 |
conditionals->ignoring[o] = 1; |
|---|
| 1556 |
return 1; |
|---|
| 1557 |
} |
|---|
| 1558 |
|
|---|
| 1559 |
if (cmdtype == c_ifdef || cmdtype == c_ifndef) |
|---|
| 1560 |
{ |
|---|
| 1561 |
char *var; |
|---|
| 1562 |
struct variable *v; |
|---|
| 1563 |
char *p; |
|---|
| 1564 |
|
|---|
| 1565 |
|
|---|
| 1566 |
|
|---|
| 1567 |
var = allocated_variable_expand (line); |
|---|
| 1568 |
|
|---|
| 1569 |
|
|---|
| 1570 |
p = end_of_token (var); |
|---|
| 1571 |
i = p - var; |
|---|
| 1572 |
p = next_token (p); |
|---|
| 1573 |
if (*p != '\0') |
|---|
| 1574 |
return -1; |
|---|
| 1575 |
|
|---|
| 1576 |
var[i] = '\0'; |
|---|
| 1577 |
v = lookup_variable (var, i); |
|---|
| 1578 |
|
|---|
| 1579 |
conditionals->ignoring[o] = |
|---|
| 1580 |
((v != 0 && *v->value != '\0') == (cmdtype == c_ifndef)); |
|---|
| 1581 |
|
|---|
| 1582 |
free (var); |
|---|
| 1583 |
} |
|---|
| 1584 |
else |
|---|
| 1585 |
{ |
|---|
| 1586 |
|
|---|
| 1587 |
char *s1, *s2; |
|---|
| 1588 |
unsigned int len; |
|---|
| 1589 |
char termin = *line == '(' ? ',' : *line; |
|---|
| 1590 |
|
|---|
| 1591 |
if (termin != ',' && termin != '"' && termin != '\'') |
|---|
| 1592 |
return -1; |
|---|
| 1593 |
|
|---|
| 1594 |
s1 = ++line; |
|---|
| 1595 |
|
|---|
| 1596 |
if (termin == ',') |
|---|
| 1597 |
{ |
|---|
| 1598 |
int count = 0; |
|---|
| 1599 |
for (; *line != '\0'; ++line) |
|---|
| 1600 |
if (*line == '(') |
|---|
| 1601 |
++count; |
|---|
| 1602 |
else if (*line == ')') |
|---|
| 1603 |
--count; |
|---|
| 1604 |
else if (*line == ',' && count <= 0) |
|---|
| 1605 |
break; |
|---|
| 1606 |
} |
|---|
| 1607 |
else |
|---|
| 1608 |
while (*line != '\0' && *line != termin) |
|---|
| 1609 |
++line; |
|---|
| 1610 |
|
|---|
| 1611 |
if (*line == '\0') |
|---|
| 1612 |
return -1; |
|---|
| 1613 |
|
|---|
| 1614 |
if (termin == ',') |
|---|
| 1615 |
{ |
|---|
| 1616 |
|
|---|
| 1617 |
char *p = line++; |
|---|
| 1618 |
while (isblank ((unsigned char)p[-1])) |
|---|
| 1619 |
--p; |
|---|
| 1620 |
*p = '\0'; |
|---|
| 1621 |
} |
|---|
| 1622 |
else |
|---|
| 1623 |
*line++ = '\0'; |
|---|
| 1624 |
|
|---|
| 1625 |
s2 = variable_expand (s1); |
|---|
| 1626 |
|
|---|
| 1627 |
|
|---|
| 1628 |
len = strlen (s2); |
|---|
| 1629 |
s1 = (char *) alloca (len + 1); |
|---|
| 1630 |
bcopy (s2, s1, len + 1); |
|---|
| 1631 |
|
|---|
| 1632 |
if (termin != ',') |
|---|
| 1633 |
|
|---|
| 1634 |
line = next_token (line); |
|---|
| 1635 |
|
|---|
| 1636 |
termin = termin == ',' ? ')' : *line; |
|---|
| 1637 |
if (termin != ')' && termin != '"' && termin != '\'') |
|---|
| 1638 |
return -1; |
|---|
| 1639 |
|
|---|
| 1640 |
|
|---|
| 1641 |
if (termin == ')') |
|---|
| 1642 |
{ |
|---|
| 1643 |
register int count = 0; |
|---|
| 1644 |
s2 = next_token (line); |
|---|
| 1645 |
for (line = s2; *line != '\0'; ++line) |
|---|
| 1646 |
{ |
|---|
| 1647 |
if (*line == '(') |
|---|
| 1648 |
++count; |
|---|
| 1649 |
else if (*line == ')') |
|---|
| 1650 |
{ |
|---|
| 1651 |
if (count <= 0) |
|---|
| 1652 |
break; |
|---|
| 1653 |
else |
|---|
| 1654 |
--count; |
|---|
| 1655 |
} |
|---|
| 1656 |
} |
|---|
| 1657 |
} |
|---|
| 1658 |
else |
|---|
| 1659 |
{ |
|---|
| 1660 |
++line; |
|---|
| 1661 |
s2 = line; |
|---|
| 1662 |
while (*line != '\0' && *line != termin) |
|---|
| 1663 |
++line; |
|---|
| 1664 |
} |
|---|
| 1665 |
|
|---|
| 1666 |
if (*line == '\0') |
|---|
| 1667 |
return -1; |
|---|
| 1668 |
|
|---|
| 1669 |
*line = '\0'; |
|---|
| 1670 |
line = next_token (++line); |
|---|
| 1671 |
if (*line != '\0') |
|---|
| 1672 |
EXTRANEOUS (); |
|---|
| 1673 |
|
|---|
| 1674 |
s2 = variable_expand (s2); |
|---|
| 1675 |
conditionals->ignoring[o] = (streq (s1, s2) == (cmdtype == c_ifneq)); |
|---|
| 1676 |
} |
|---|
| 1677 |
|
|---|
| 1678 |
DONE: |
|---|
| 1679 |
|
|---|
| 1680 |
for (i = 0; i < conditionals->if_cmds; ++i) |
|---|
| 1681 |
if (conditionals->ignoring[i]) |
|---|
| 1682 |
return 1; |
|---|
| 1683 |
return 0; |
|---|
| 1684 |
} |
|---|
| 1685 |
|
|---|
| 1686 |
|
|---|
| 1687 |
|
|---|
| 1688 |
static unsigned long |
|---|
| 1689 |
dep_hash_1 (const void *key) |
|---|
| 1690 |
{ |
|---|
| 1691 |
return_STRING_HASH_1 (dep_name ((struct dep const *) key)); |
|---|
| 1692 |
} |
|---|
| 1693 |
|
|---|
| 1694 |
static unsigned long |
|---|
| 1695 |
dep_hash_2 (const void *key) |
|---|
| 1696 |
{ |
|---|
| 1697 |
return_STRING_HASH_2 (dep_name ((struct dep const *) key)); |
|---|
| 1698 |
} |
|---|
| 1699 |
|
|---|
| 1700 |
static int |
|---|
| 1701 |
dep_hash_cmp (const void *x, const void *y) |
|---|
| 1702 |
{ |
|---|
| 1703 |
struct dep *dx = (struct dep *) x; |
|---|
| 1704 |
struct dep *dy = (struct dep *) y; |
|---|
| 1705 |
int cmp = strcmp (dep_name (dx), dep_name (dy)); |
|---|
| 1706 |
|
|---|
| 1707 |
|
|---|
| 1708 |
|
|---|
| 1709 |
|
|---|
| 1710 |
|
|---|
| 1711 |
if (!cmp && dx->ignore_mtime != dy->ignore_mtime) |
|---|
| 1712 |
dx->ignore_mtime = dy->ignore_mtime = 0; |
|---|
| 1713 |
|
|---|
| 1714 |
return cmp; |
|---|
| 1715 |
} |
|---|
| 1716 |
|
|---|
| 1717 |
|
|---|
| 1718 |
void |
|---|
| 1719 |
uniquize_deps (struct dep *chain) |
|---|
| 1720 |
{ |
|---|
| 1721 |
struct hash_table deps; |
|---|
| 1722 |
register struct dep **depp; |
|---|
| 1723 |
|
|---|
| 1724 |
hash_init (&deps, 500, dep_hash_1, dep_hash_2, dep_hash_cmp); |
|---|
| 1725 |
|
|---|
| 1726 |
|
|---|
| 1727 |
|
|---|
| 1728 |
|
|---|
| 1729 |
|
|---|
| 1730 |
depp = &chain; |
|---|
| 1731 |
while (*depp) |
|---|
| 1732 |
{ |
|---|
| 1733 |
struct dep *dep = *depp; |
|---|
| 1734 |
struct dep **dep_slot = (struct dep **) hash_find_slot (&deps, dep); |
|---|
| 1735 |
if (HASH_VACANT (*dep_slot)) |
|---|
| 1736 |
{ |
|---|
| 1737 |
hash_insert_at (&deps, dep, dep_slot); |
|---|
| 1738 |
depp = &dep->next; |
|---|
| 1739 |
} |
|---|
| 1740 |
else |
|---|
| 1741 |
{ |
|---|
| 1742 |
|
|---|
| 1743 |
|
|---|
| 1744 |
*depp = dep->next; |
|---|
| 1745 |
} |
|---|
| 1746 |
} |
|---|
| 1747 |
|
|---|
| 1748 |
hash_free (&deps, 0); |
|---|
| 1749 |
} |
|---|
| 1750 |
|
|---|
| 1751 |
|
|---|
| 1752 |
|
|---|
| 1753 |
|
|---|
| 1754 |
|
|---|
| 1755 |
|
|---|
| 1756 |
|
|---|
| 1757 |
|
|---|
| 1758 |
|
|---|
| 1759 |
|
|---|
| 1760 |
static void |
|---|
| 1761 |
record_target_var (struct nameseq *filenames, char *defn, |
|---|
| 1762 |
enum variable_origin origin, int exported, |
|---|
| 1763 |
const struct floc *flocp) |
|---|
| 1764 |
{ |
|---|
| 1765 |
struct nameseq *nextf; |
|---|
| 1766 |
struct variable_set_list *global; |
|---|
| 1767 |
|
|---|
| 1768 |
global = current_variable_set_list; |
|---|
| 1769 |
|
|---|
| 1770 |
|
|---|
| 1771 |
|
|---|
| 1772 |
|
|---|
| 1773 |
for (; filenames != 0; filenames = nextf) |
|---|
| 1774 |
{ |
|---|
| 1775 |
struct variable *v; |
|---|
| 1776 |
register char *name = filenames->name; |
|---|
| 1777 |
char *fname; |
|---|
| 1778 |
char *percent; |
|---|
| 1779 |
struct pattern_var *p; |
|---|
| 1780 |
|
|---|
| 1781 |
nextf = filenames->next; |
|---|
| 1782 |
free ((char *) filenames); |
|---|
| 1783 |
|
|---|
| 1784 |
|
|---|
| 1785 |
|
|---|
| 1786 |
percent = find_percent (name); |
|---|
| 1787 |
if (percent) |
|---|
| 1788 |
{ |
|---|
| 1789 |
|
|---|
| 1790 |
p = create_pattern_var (name, percent); |
|---|
| 1791 |
p->variable.fileinfo = *flocp; |
|---|
| 1792 |
|
|---|
| 1793 |
|
|---|
| 1794 |
v = parse_variable_definition (&p->variable, defn); |
|---|
| 1795 |
assert (v != 0); |
|---|
| 1796 |
|
|---|
| 1797 |
if (v->flavor == f_simple) |
|---|
| 1798 |
v->value = allocated_variable_expand (v->value); |
|---|
| 1799 |
else |
|---|
| 1800 |
v->value = xstrdup (v->value); |
|---|
| 1801 |
|
|---|
| 1802 |
fname = p->target; |
|---|
| 1803 |
} |
|---|
| 1804 |
else |
|---|
| 1805 |
{ |
|---|
| 1806 |
struct file *f; |
|---|
| 1807 |
|
|---|
| 1808 |
|
|---|
| 1809 |
|
|---|
| 1810 |
|
|---|
| 1811 |
|
|---|
| 1812 |
f = lookup_file (name); |
|---|
| 1813 |
if (!f) |
|---|
| 1814 |
f = enter_file (name); |
|---|
| 1815 |
else if (f->double_colon) |
|---|
| 1816 |
f = f->double_colon; |
|---|
| 1817 |
|
|---|
| 1818 |
initialize_file_variables (f, 1); |
|---|
| 1819 |
fname = f->name; |
|---|
| 1820 |
|
|---|
| 1821 |
current_variable_set_list = f->variables; |
|---|
| 1822 |
v = try_variable_definition (flocp, defn, origin, 1); |
|---|
| 1823 |
if (!v) |
|---|
| 1824 |
error (flocp, _("Malformed target-specific variable definition")); |
|---|
| 1825 |
current_variable_set_list = global; |
|---|
| 1826 |
} |
|---|
| 1827 |
|
|---|
| 1828 |
|
|---|
| 1829 |
v->origin = origin; |
|---|
| 1830 |
v->per_target = 1; |
|---|
| 1831 |
v->export = exported ? v_export : v_default; |
|---|
| 1832 |
|
|---|
| 1833 |
|
|---|
| 1834 |
|
|---|
| 1835 |
if (origin != o_override) |
|---|
| 1836 |
{ |
|---|
| 1837 |
struct variable *gv; |
|---|
| 1838 |
int len = strlen(v->name); |
|---|
| 1839 |
|
|---|
| 1840 |
gv = lookup_variable (v->name, len); |
|---|
| 1841 |
if (gv && (gv->origin == o_env_override || gv->origin == o_command)) |
|---|
| 1842 |
{ |
|---|
| 1843 |
if (v->value != 0) |
|---|
| 1844 |
free (v->value); |
|---|
| 1845 |
v->value = xstrdup (gv->value); |
|---|
| 1846 |
v->origin = gv->origin; |
|---|
| 1847 |
v->recursive = gv->recursive; |
|---|
| 1848 |
v->append = 0; |
|---|
| 1849 |
} |
|---|
| 1850 |
} |
|---|
| 1851 |
|
|---|
| 1852 |
|
|---|
| 1853 |
if (name != fname && (name < fname || name > fname + strlen (fname))) |
|---|
| 1854 |
free (name); |
|---|
| 1855 |
} |
|---|
| 1856 |
} |
|---|
| 1857 |
|
|---|
| 1858 |
|
|---|
| 1859 |
|
|---|
| 1860 |
|
|---|
| 1861 |
|
|---|
| 1862 |
|
|---|
| 1863 |
|
|---|
| 1864 |
|
|---|
| 1865 |
|
|---|
| 1866 |
|
|---|
| 1867 |
|
|---|
| 1868 |
|
|---|
| 1869 |
static void |
|---|
| 1870 |
record_files (struct nameseq *filenames, char *pattern, char *pattern_percent, |
|---|
| 1871 |
struct dep *deps, unsigned int cmds_started, char *commands, |
|---|
| 1872 |
unsigned int commands_idx, int two_colon, |
|---|
| 1873 |
const struct floc *flocp) |
|---|
| 1874 |
{ |
|---|
| 1875 |
struct nameseq *nextf; |
|---|
| 1876 |
int implicit = 0; |
|---|
| 1877 |
unsigned int max_targets = 0, target_idx = 0; |
|---|
| 1878 |
char **targets = 0, **target_percents = 0; |
|---|
| 1879 |
struct commands *cmds; |
|---|
| 1880 |
|
|---|
| 1881 |
|
|---|
| 1882 |
|
|---|
| 1883 |
|
|---|
| 1884 |
|
|---|
| 1885 |
if (snapped_deps) |
|---|
| 1886 |
fatal (flocp, _("prerequisites cannot be defined in command scripts")); |
|---|
| 1887 |
|
|---|
| 1888 |
if (commands_idx > 0) |
|---|
| 1889 |
{ |
|---|
| 1890 |
cmds = (struct commands *) xmalloc (sizeof (struct commands)); |
|---|
| 1891 |
cmds->fileinfo.filenm = flocp->filenm; |
|---|
| 1892 |
cmds->fileinfo.lineno = cmds_started; |
|---|
| 1893 |
cmds->commands = savestring (commands, commands_idx); |
|---|
| 1894 |
cmds->command_lines = 0; |
|---|
| 1895 |
} |
|---|
| 1896 |
else |
|---|
| 1897 |
cmds = 0; |
|---|
| 1898 |
|
|---|
| 1899 |
for (; filenames != 0; filenames = nextf) |
|---|
| 1900 |
{ |
|---|
| 1901 |
char *name = filenames->name; |
|---|
| 1902 |
struct file *f; |
|---|
| 1903 |
struct dep *this = 0; |
|---|
| 1904 |
char *implicit_percent; |
|---|
| 1905 |
|
|---|
| 1906 |
nextf = filenames->next; |
|---|
| 1907 |
free (filenames); |
|---|
| 1908 |
|
|---|
| 1909 |
|
|---|
| 1910 |
|
|---|
| 1911 |
|
|---|
| 1912 |
if (streq (name, ".POSIX")) |
|---|
| 1913 |
posix_pedantic = 1; |
|---|
| 1914 |
else if (streq (name, ".SECONDEXPANSION")) |
|---|
| 1915 |
second_expansion = 1; |
|---|
| 1916 |
|
|---|
| 1917 |
implicit_percent = find_percent (name); |
|---|
| 1918 |
implicit |= implicit_percent != 0; |
|---|
| 1919 |
|
|---|
| 1920 |
if (implicit && pattern != 0) |
|---|
| 1921 |
fatal (flocp, _("mixed implicit and static pattern rules")); |
|---|
| 1922 |
|
|---|
| 1923 |
if (implicit && implicit_percent == 0) |
|---|
| 1924 |
fatal (flocp, _("mixed implicit and normal rules")); |
|---|
| 1925 |
|
|---|
| 1926 |
if (implicit) |
|---|
| 1927 |
{ |
|---|
| 1928 |
if (targets == 0) |
|---|
| 1929 |
{ |
|---|
| 1930 |
max_targets = 5; |
|---|
| 1931 |
targets = (char **) xmalloc (5 * sizeof (char *)); |
|---|
| 1932 |
target_percents = (char **) xmalloc (5 * sizeof (char *)); |
|---|
| 1933 |
target_idx = 0; |
|---|
| 1934 |
} |
|---|
| 1935 |
else if (target_idx == max_targets - 1) |
|---|
| 1936 |
{ |
|---|
| 1937 |
max_targets += 5; |
|---|
| 1938 |
targets = (char **) xrealloc ((char *) targets, |
|---|
| 1939 |
max_targets * sizeof (char *)); |
|---|
| 1940 |
target_percents |
|---|
| 1941 |
= (char **) xrealloc ((char *) target_percents, |
|---|
| 1942 |
max_targets * sizeof (char *)); |
|---|
| 1943 |
} |
|---|
| 1944 |
targets[target_idx] = name; |
|---|
| 1945 |
target_percents[target_idx] = implicit_percent; |
|---|
| 1946 |
++target_idx; |
|---|
| 1947 |
continue; |
|---|
| 1948 |
} |
|---|
| 1949 |
|
|---|
| 1950 |
|
|---|
| 1951 |
|
|---|
| 1952 |
|
|---|
| 1953 |
if (pattern && !pattern_matches (pattern, pattern_percent, name)) |
|---|
| 1954 |
error (flocp, _("target `%s' doesn't match the target pattern"), name); |
|---|
| 1955 |
else if (deps) |
|---|
| 1956 |
{ |
|---|
| 1957 |
|
|---|
| 1958 |
|
|---|
| 1959 |
|
|---|
| 1960 |
this = nextf != 0 ? copy_dep_chain (deps) : deps; |
|---|
| 1961 |
this->need_2nd_expansion = (second_expansion |
|---|
| 1962 |
&& strchr (this->name, '$')); |
|---|
| 1963 |
} |
|---|
| 1964 |
|
|---|
| 1965 |
if (!two_colon) |
|---|
| 1966 |
{ |
|---|
| 1967 |
|
|---|
| 1968 |
|
|---|
| 1969 |
f = enter_file (name); |
|---|
| 1970 |
|
|---|
| 1971 |
if (f->double_colon) |
|---|
| 1972 |
fatal (flocp, |
|---|
| 1973 |
_("target file `%s' has both : and :: entries"), f->name); |
|---|
| 1974 |
|
|---|
| 1975 |
|
|---|
| 1976 |
|
|---|
| 1977 |
if (cmds != 0 && cmds == f->cmds) |
|---|
| 1978 |
error (flocp, |
|---|
| 1979 |
_("target `%s' given more than once in the same rule."), |
|---|
| 1980 |
f->name); |
|---|
| 1981 |
|
|---|
| 1982 |
|
|---|
| 1983 |
|
|---|
| 1984 |
|
|---|
| 1985 |
else if (cmds != 0 && f->cmds != 0 && f->is_target) |
|---|
| 1986 |
{ |
|---|
| 1987 |
error (&cmds->fileinfo, |
|---|
| 1988 |
_("warning: overriding commands for target `%s'"), |
|---|
| 1989 |
f->name); |
|---|
| 1990 |
error (&f->cmds->fileinfo, |
|---|
| 1991 |
_("warning: ignoring old commands for target `%s'"), |
|---|
| 1992 |
f->name); |
|---|
| 1993 |
} |
|---|
| 1994 |
|
|---|
| 1995 |
f->is_target = 1; |
|---|
| 1996 |
|
|---|
| 1997 |
|
|---|
| 1998 |
if (f == default_file && this == 0 && cmds == 0) |
|---|
| 1999 |
f->cmds = 0; |
|---|
| 2000 |
if (cmds != 0) |
|---|
| 2001 |
f->cmds = cmds; |
|---|
| 2002 |
|
|---|
| 2003 |
|
|---|
| 2004 |
|
|---|
| 2005 |
if (f == suffix_file && this == 0) |
|---|
| 2006 |
{ |
|---|
| 2007 |
free_dep_chain (f->deps); |
|---|
| 2008 |
f->deps = 0; |
|---|
| 2009 |
} |
|---|
| 2010 |
else if (this != 0) |
|---|
| 2011 |
{ |
|---|
| 2012 |
|
|---|
| 2013 |
|
|---|
| 2014 |
if (f->deps != 0) |
|---|
| 2015 |
{ |
|---|
| 2016 |
struct dep **d_ptr = &f->deps; |
|---|
| 2017 |
|
|---|
| 2018 |
while ((*d_ptr)->next != 0) |
|---|
| 2019 |
d_ptr = &(*d_ptr)->next; |
|---|
| 2020 |
|
|---|
| 2021 |
if (cmds != 0) |
|---|
| 2022 |
|
|---|
| 2023 |
|
|---|
| 2024 |
|
|---|
| 2025 |
|
|---|
| 2026 |
|
|---|
| 2027 |
|
|---|
| 2028 |
(*d_ptr)->next = this; |
|---|
| 2029 |
else |
|---|
| 2030 |
{ |
|---|
| 2031 |
|
|---|
| 2032 |
|
|---|
| 2033 |
|
|---|
| 2034 |
|
|---|
| 2035 |
|
|---|
| 2036 |
if (f->cmds != 0) |
|---|
| 2037 |
{ |
|---|
| 2038 |
this->next = *d_ptr; |
|---|
| 2039 |
*d_ptr = this; |
|---|
| 2040 |
} |
|---|
| 2041 |
else |
|---|
| 2042 |
(*d_ptr)->next = this; |
|---|
| 2043 |
} |
|---|
| 2044 |
} |
|---|
| 2045 |
else |
|---|
| 2046 |
f->deps = this; |
|---|
| 2047 |
|
|---|
| 2048 |
|
|---|
| 2049 |
|
|---|
| 2050 |
|
|---|
| 2051 |
|
|---|
| 2052 |
|
|---|
| 2053 |
|
|---|
| 2054 |
|
|---|
| 2055 |
|
|---|
| 2056 |
|
|---|
| 2057 |
|
|---|
| 2058 |
|
|---|
| 2059 |
|
|---|
| 2060 |
|
|---|
| 2061 |
if (cmds != 0) |
|---|
| 2062 |
f->updating = 1; |
|---|
| 2063 |
} |
|---|
| 2064 |
} |
|---|
| 2065 |
else |
|---|
| 2066 |
{ |
|---|
| 2067 |
|
|---|
| 2068 |
f = lookup_file (name); |
|---|
| 2069 |
|
|---|
| 2070 |
|
|---|
| 2071 |
|
|---|
| 2072 |
if (f != 0 && f->is_target && !f->double_colon) |
|---|
| 2073 |
fatal (flocp, |
|---|
| 2074 |
_("target file `%s' has both : and :: entries"), f->name); |
|---|
| 2075 |
f = enter_file (name); |
|---|
| 2076 |
|
|---|
| 2077 |
|
|---|
| 2078 |
|
|---|
| 2079 |
|
|---|
| 2080 |
if (f->double_colon == 0) |
|---|
| 2081 |
|
|---|
| 2082 |
|
|---|
| 2083 |
f->double_colon = f; |
|---|
| 2084 |
f->is_target = 1; |
|---|
| 2085 |
f->deps = this; |
|---|
| 2086 |
f->cmds = cmds; |
|---|
| 2087 |
} |
|---|
| 2088 |
|
|---|
| 2089 |
|
|---|
| 2090 |
|
|---|
| 2091 |
|
|---|
| 2092 |
if (pattern) |
|---|
| 2093 |
{ |
|---|
| 2094 |
static char *percent = "%"; |
|---|
| 2095 |
char *buffer = variable_expand (""); |
|---|
| 2096 |
char *o = patsubst_expand (buffer, name, pattern, percent, |
|---|
| 2097 |
pattern_percent+1, percent+1); |
|---|
| 2098 |
f->stem = savestring (buffer, o - buffer); |
|---|
| 2099 |
if (this) |
|---|
| 2100 |
{ |
|---|
| 2101 |
this->staticpattern = 1; |
|---|
| 2102 |
this->stem = xstrdup (f->stem); |
|---|
| 2103 |
} |
|---|
| 2104 |
} |
|---|
| 2105 |
|
|---|
| 2106 |
|
|---|
| 2107 |
if (f != 0 && name != f->name |
|---|
| 2108 |
&& (name < f->name || name > f->name + strlen (f->name))) |
|---|
| 2109 |
{ |
|---|
| 2110 |
free (name); |
|---|
| 2111 |
name = f->name; |
|---|
| 2112 |
} |
|---|
| 2113 |
|
|---|
| 2114 |
|
|---|
| 2115 |
if (streq (*default_goal_name, name) |
|---|
| 2116 |
&& (default_goal_file == 0 |
|---|
| 2117 |
|| ! streq (default_goal_file->name, name))) |
|---|
| 2118 |
default_goal_file = f; |
|---|
| 2119 |
} |
|---|
| 2120 |
|
|---|
| 2121 |
if (implicit) |
|---|
| 2122 |
{ |
|---|
| 2123 |
targets[target_idx] = 0; |
|---|
| 2124 |
target_percents[target_idx] = 0; |
|---|
| 2125 |
if (deps) |
|---|
| 2126 |
deps->need_2nd_expansion = second_expansion; |
|---|
| 2127 |
create_pattern_rule (targets, target_percents, two_colon, deps, cmds, 1); |
|---|
| 2128 |
free ((char *) target_percents); |
|---|
| 2129 |
} |
|---|
| 2130 |
} |
|---|
| 2131 |
|
|---|
| 2132 |
|
|---|
| 2133 |
|
|---|
| 2134 |
|
|---|
| 2135 |
|
|---|
| 2136 |
|
|---|
| 2137 |
|
|---|
| 2138 |
|
|---|
| 2139 |
|
|---|
| 2140 |
|
|---|
| 2141 |
static char * |
|---|
| 2142 |
find_char_unquote (char *string, int stop1, int stop2, int blank, |
|---|
| 2143 |
int ignorevars) |
|---|
| 2144 |
{ |
|---|
| 2145 |
unsigned int string_len = 0; |
|---|
| 2146 |
register char *p = string; |
|---|
| 2147 |
|
|---|
| 2148 |
if (ignorevars) |
|---|
| 2149 |
ignorevars = '$'; |
|---|
| 2150 |
|
|---|
| 2151 |
while (1) |
|---|
| 2152 |
{ |
|---|
| 2153 |
if (stop2 && blank) |
|---|
| 2154 |
while (*p != '\0' && *p != ignorevars && *p != stop1 && *p != stop2 |
|---|
| 2155 |
&& ! isblank ((unsigned char) *p)) |
|---|
| 2156 |
++p; |
|---|
| 2157 |
else if (stop2) |
|---|
| 2158 |
while (*p != '\0' && *p != ignorevars && *p != stop1 && *p != stop2) |
|---|
| 2159 |
++p; |
|---|
| 2160 |
else if (blank) |
|---|
| 2161 |
while (*p != '\0' && *p != ignorevars && *p != stop1 |
|---|
| 2162 |
&& ! isblank ((unsigned char) *p)) |
|---|
| 2163 |
++p; |
|---|
| 2164 |
else |
|---|
| 2165 |
while (*p != '\0' && *p != ignorevars && *p != stop1) |
|---|
| 2166 |
++p; |
|---|
| 2167 |
|
|---|
| 2168 |
if (*p == '\0') |
|---|
| 2169 |
break; |
|---|
| 2170 |
|
|---|
| 2171 |
|
|---|
| 2172 |
if (*p == ignorevars) |
|---|
| 2173 |
{ |
|---|
| 2174 |
char openparen = p[1]; |
|---|
| 2175 |
|
|---|
| 2176 |
p += 2; |
|---|
| 2177 |
|
|---|
| 2178 |
|
|---|
| 2179 |
if (openparen == '(' || openparen == '{') |
|---|
| 2180 |
{ |
|---|
| 2181 |
unsigned int pcount = 1; |
|---|
| 2182 |
char closeparen = (openparen == '(' ? ')' : '}'); |
|---|
| 2183 |
|
|---|
| 2184 |
while (*p) |
|---|
| 2185 |
{ |
|---|
| 2186 |
if (*p == openparen) |
|---|
| 2187 |
++pcount; |
|---|
| 2188 |
else if (*p == closeparen) |
|---|
| 2189 |
if (--pcount == 0) |
|---|
| 2190 |
{ |
|---|
| 2191 |
++p; |
|---|
| 2192 |
break; |
|---|
| 2193 |
} |
|---|
| 2194 |
++p; |
|---|
| 2195 |
} |
|---|
| 2196 |
} |
|---|
| 2197 |
|
|---|
| 2198 |
|
|---|
| 2199 |
continue; |
|---|
| 2200 |
} |
|---|
| 2201 |
|
|---|
| 2202 |
if (p > string && p[-1] == '\\') |
|---|
| 2203 |
{ |
|---|
| 2204 |
|
|---|
| 2205 |
register int i = -2; |
|---|
| 2206 |
while (&p[i] >= string && p[i] == '\\') |
|---|
| 2207 |
--i; |
|---|
| 2208 |
++i; |
|---|
| 2209 |
|
|---|
| 2210 |
if (string_len == 0) |
|---|
| 2211 |
string_len = strlen (string); |
|---|
| 2212 |
|
|---|
| 2213 |
|
|---|
| 2214 |
bcopy (&p[i / 2], &p[i], (string_len - (p - string)) - (i / 2) + 1); |
|---|
| 2215 |
p += i / 2; |
|---|
| 2216 |
if (i % 2 == 0) |
|---|
| 2217 |
|
|---|
| 2218 |
|
|---|
| 2219 |
return p; |
|---|
| 2220 |
|
|---|
| 2221 |
|
|---|
| 2222 |
} |
|---|
| 2223 |
else |
|---|
| 2224 |
|
|---|
| 2225 |
return p; |
|---|
| 2226 |
} |
|---|
| 2227 |
|
|---|
| 2228 |
|
|---|
| 2229 |
return 0; |
|---|
| 2230 |
} |
|---|
| 2231 |
|
|---|
| 2232 |
|
|---|
| 2233 |
|
|---|
| 2234 |
char * |
|---|
| 2235 |
find_percent (char *pattern) |
|---|
| 2236 |
{ |
|---|
| 2237 |
return find_char_unquote (pattern, '%', 0, 0, 0); |
|---|
| 2238 |
} |
|---|
| 2239 |
|
|---|
| 2240 |
|
|---|
| 2241 |
|
|---|
| 2242 |
|
|---|
| 2243 |
|
|---|
| 2244 |
|
|---|
| 2245 |
|
|---|
| 2246 |
|
|---|
| 2247 |
|
|---|
| 2248 |
|
|---|
| 2249 |
|
|---|
| 2250 |
|
|---|
| 2251 |
|
|---|
| 2252 |
|
|---|
| 2253 |
struct nameseq * |
|---|
| 2254 |
parse_file_seq (char **stringp, int stopchar, unsigned int size, int strip) |
|---|
| 2255 |
{ |
|---|
| 2256 |
struct nameseq *new = 0; |
|---|
| 2257 |
struct nameseq *new1, *lastnew1; |
|---|
| 2258 |
char *p = *stringp; |
|---|
| 2259 |
char *q; |
|---|
| 2260 |
char *name; |
|---|
| 2261 |
|
|---|
| 2262 |
#ifdef VMS |
|---|
| 2263 |
# define VMS_COMMA ',' |
|---|
| 2264 |
#else |
|---|
| 2265 |
# define VMS_COMMA 0 |
|---|
| 2266 |
#endif |
|---|
| 2267 |
|
|---|
| 2268 |
while (1) |
|---|
| 2269 |
{ |
|---|
| 2270 |
|
|---|
| 2271 |
p = next_token (p); |
|---|
| 2272 |
if (*p == '\0') |
|---|
| 2273 |
break; |
|---|
| 2274 |
if (*p == stopchar) |
|---|
| 2275 |
break; |
|---|
| 2276 |
|
|---|
| 2277 |
|
|---|
| 2278 |
q = p; |
|---|
| 2279 |
p = find_char_unquote (q, stopchar, VMS_COMMA, 1, 0); |
|---|
| 2280 |
#ifdef VMS |
|---|
| 2281 |
|
|---|
| 2282 |
if (p && *p == ',') |
|---|
| 2283 |
*p =' '; |
|---|
| 2284 |
#endif |
|---|
| 2285 |
#ifdef _AMIGA |
|---|
| 2286 |
if (stopchar == ':' && p && *p == ':' |
|---|
| 2287 |
&& !(isspace ((unsigned char)p[1]) || !p[1] |
|---|
| 2288 |
|| isspace ((unsigned char)p[-1]))) |
|---|
| 2289 |
{ |
|---|
| 2290 |
p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0); |
|---|
| 2291 |
} |
|---|
| 2292 |
#endif |
|---|
| 2293 |
#ifdef HAVE_DOS_PATHS |
|---|
| 2294 |
|
|---|
| 2295 |
|
|---|
| 2296 |
|
|---|
| 2297 |
|
|---|
| 2298 |
if (stopchar == ':') |
|---|
| 2299 |
while (p != 0 && !isspace ((unsigned char)*p) && |
|---|
| 2300 |
(p[1] == '\\' || p[1] == '/') && isalpha ((unsigned char)p[-1])) |
|---|
| 2301 |
p = find_char_unquote (p + 1, stopchar, VMS_COMMA, 1, 0); |
|---|
| 2302 |
#endif |
|---|
| 2303 |
if (p == 0) |
|---|
| 2304 |
p = q + strlen (q); |
|---|
| 2305 |
|
|---|
| 2306 |
if (strip) |
|---|
| 2307 |
#ifdef VMS |
|---|
| 2308 |
|
|---|
| 2309 |
while (p - q > 2 && q[0] == '[' && q[1] == ']') |
|---|
| 2310 |
#else |
|---|
| 2311 |
|
|---|
| 2312 |
while (p - q > 2 && q[0] == '.' && q[1] == '/') |
|---|
| 2313 |
#endif |
|---|
| 2314 |
{ |
|---|
| 2315 |
q += 2; |
|---|
| 2316 |
while (q < p && *q == '/') |
|---|
| 2317 |
|
|---|
| 2318 |
++q; |
|---|
| 2319 |
} |
|---|
| 2320 |
|
|---|
| 2321 |
|
|---|
| 2322 |
|
|---|
| 2323 |
if (q == p) |
|---|
| 2324 |
|
|---|
| 2325 |
#ifdef VMS |
|---|
| 2326 |
continue; |
|---|
| 2327 |
#else |
|---|
| 2328 |
#ifdef _AMIGA |
|---|
| 2329 |
name = savestring ("", 0); |
|---|
| 2330 |
#else |
|---|
| 2331 |
name = savestring ("./", 2); |
|---|
| 2332 |
#endif |
|---|
| 2333 |
#endif |
|---|
| 2334 |
else |
|---|
| 2335 |
#ifdef VMS |
|---|
| 2336 |
|
|---|
| 2337 |
|
|---|
| 2338 |
|
|---|
| 2339 |
|
|---|
| 2340 |
{ |
|---|
| 2341 |
char *qbase = xstrdup (q); |
|---|
| 2342 |
char *pbase = qbase + (p-q); |
|---|
| 2343 |
char *q1 = qbase; |
|---|
| 2344 |
char *q2 = q1; |
|---|
| 2345 |
char *p1 = pbase; |
|---|
| 2346 |
|
|---|
| 2347 |
while (q1 != pbase) |
|---|
| 2348 |
{ |
|---|
| 2349 |
if (*q1 == '\\' && *(q1+1) == ':') |
|---|
| 2350 |
{ |
|---|
| 2351 |
q1++; |
|---|
| 2352 |
p1--; |
|---|
| 2353 |
} |
|---|
| 2354 |
*q2++ = *q1++; |
|---|
| 2355 |
} |
|---|
| 2356 |
name = savestring (qbase, p1 - qbase); |
|---|
| 2357 |
free (qbase); |
|---|
| 2358 |
} |
|---|
| 2359 |
#else |
|---|
| 2360 |
name = savestring (q, p - q); |
|---|
| 2361 |
#endif |
|---|
| 2362 |
|
|---|
| 2363 |
|
|---|
| 2364 |
new1 = (struct nameseq *) xmalloc (size); |
|---|
| 2365 |
new1->name = name; |
|---|
| 2366 |
new1->next = new; |
|---|
| 2367 |
new = new1; |
|---|
| 2368 |
} |
|---|
| 2369 |
|
|---|
| 2370 |
#ifndef NO_ARCHIVES |
|---|
| 2371 |
|
|---|
| 2372 |
|
|---|
| 2373 |
|
|---|
| 2374 |
|
|---|
| 2375 |
|
|---|
| 2376 |
|
|---|
| 2377 |
new1 = new; |
|---|
| 2378 |
lastnew1 = 0; |
|---|
| 2379 |
while (new1 != 0) |
|---|
| 2380 |
if (new1->name[0] != '(' |
|---|
| 2381 |
&& new1->name[strlen (new1->name) - 1] == ')' |
|---|
| 2382 |
&& strchr (new1->name, '(') == 0) |
|---|
| 2383 |
{ |
|---|
| 2384 |
|
|---|
| 2385 |
|
|---|
| 2386 |
|
|---|
| 2387 |
struct nameseq *n = new1->next, *lastn = new1; |
|---|
| 2388 |
char *paren = 0; |
|---|
| 2389 |
while (n != 0 && (paren = strchr (n->name, '(')) == 0) |
|---|
| 2390 |
{ |
|---|
| 2391 |
lastn = n; |
|---|
| 2392 |
n = n->next; |
|---|
| 2393 |
} |
|---|
| 2394 |
if (n != 0 |
|---|
| 2395 |
|
|---|
| 2396 |
|
|---|
| 2397 |
|
|---|
| 2398 |
&& n->name[0] != '(') |
|---|
| 2399 |
{ |
|---|
| 2400 |
|
|---|
| 2401 |
|
|---|
| 2402 |
|
|---|
| 2403 |
char *libname; |
|---|
| 2404 |
|
|---|
| 2405 |
|
|---|
| 2406 |
++paren; |
|---|
| 2407 |
libname = (char *) alloca (paren - n->name + 1); |
|---|
| 2408 |
bcopy (n->name, libname, paren - n->name); |
|---|
| 2409 |
libname[paren - n->name] = '\0'; |
|---|
| 2410 |
|
|---|
| 2411 |
if (*paren == '\0') |
|---|
| 2412 |
{ |
|---|
| 2413 |
|
|---|
| 2414 |
|
|---|
| 2415 |
lastn->next = n->next; |
|---|
| 2416 |
free (n->name); |
|---|
| 2417 |
free ((char *) n); |
|---|
| 2418 |
|
|---|
| 2419 |
n = lastn->next; |
|---|
| 2420 |
} |
|---|
| 2421 |
else |
|---|
| 2422 |
{ |
|---|
| 2423 |
|
|---|
| 2424 |
name = concat (libname, paren, ")"); |
|---|
| 2425 |
free (n->name); |
|---|
| 2426 |
n->name = name; |
|---|
| 2427 |
} |
|---|
| 2428 |
|
|---|
| 2429 |
if (new1->name[1] == '\0') |
|---|
| 2430 |
{ |
|---|
| 2431 |
|
|---|
| 2432 |
|
|---|
| 2433 |
if (lastnew1 == 0) |
|---|
| 2434 |
new = new1->next; |
|---|
| 2435 |
else |
|---|
| 2436 |
lastnew1->next = new1->next; |
|---|
| 2437 |
lastn = new1; |
|---|
| 2438 |
new1 = new1->next; |
|---|
| 2439 |
free (lastn->name); |
|---|
| 2440 |
free ((char *) lastn); |
|---|
| 2441 |
} |
|---|
| 2442 |
else |
|---|
| 2443 |
{ |
|---|
| 2444 |
|
|---|
| 2445 |
name = concat (libname, new1->name, ""); |
|---|
| 2446 |
free (new1->name); |
|---|
| 2447 |
new1->name = name; |
|---|
| 2448 |
new1 = new1->next; |
|---|
| 2449 |
} |
|---|
| 2450 |
|
|---|
| 2451 |
|
|---|
| 2452 |
|
|---|
| 2453 |
|
|---|
| 2454 |
|
|---|
| 2455 |
while (new1 != n) |
|---|
| 2456 |
{ |
|---|
| 2457 |
name = concat (libname, new1->name, ")"); |
|---|
| 2458 |
free (new1->name); |
|---|
| 2459 |
new1->name = name; |
|---|
| 2460 |
lastnew1 = new1; |
|---|
| 2461 |
new1 = new1->next; |
|---|
| 2462 |
} |
|---|
| 2463 |
} |
|---|
| 2464 |
else |
|---|
| 2465 |
{ |
|---|
| 2466 |
|
|---|
| 2467 |
lastnew1 = new1; |
|---|
| 2468 |
new1 = new1->next; |
|---|
| 2469 |
} |
|---|
| 2470 |
} |
|---|
| 2471 |
else |
|---|
| 2472 |
{ |
|---|
| 2473 |
lastnew1 = new1; |
|---|
| 2474 |
new1 = new1->next; |
|---|
| 2475 |
} |
|---|
| 2476 |
|
|---|
| 2477 |
#endif |
|---|
| 2478 |
|
|---|
| 2479 |
*stringp = p; |
|---|
| 2480 |
return new; |
|---|
| 2481 |
} |
|---|
| 2482 |
|
|---|
| 2483 |
|
|---|
| 2484 |
|
|---|
| 2485 |
|
|---|
| 2486 |
|
|---|
| 2487 |
|
|---|
| 2488 |
|
|---|
| 2489 |
|
|---|
| 2490 |
|
|---|
| 2491 |
|
|---|
| 2492 |
|
|---|
| 2493 |
|
|---|
| 2494 |
|
|---|
| 2495 |
|
|---|
| 2496 |
static unsigned long |
|---|
| 2497 |
readstring (struct ebuffer *ebuf) |
|---|
| 2498 |
{ |
|---|
| 2499 |
char *eol; |
|---|
| 2500 |
|
|---|
| 2501 |
|
|---|
| 2502 |
if (ebuf->bufnext >= ebuf->bufstart + ebuf->size) |
|---|
| 2503 |
return -1; |
|---|
| 2504 |
|
|---|
| 2505 |
|
|---|
| 2506 |
|
|---|
| 2507 |
|
|---|
| 2508 |
eol = ebuf->buffer = ebuf->bufnext; |
|---|
| 2509 |
|
|---|
| 2510 |
while (1) |
|---|
| 2511 |
{ |
|---|
| 2512 |
int backslash = 0; |
|---|
| 2513 |
char *bol = eol; |
|---|
| 2514 |
char *p; |
|---|
| 2515 |
|
|---|
| 2516 |
|
|---|
| 2517 |
eol = p = strchr (eol , '\n'); |
|---|
| 2518 |
if (!eol) |
|---|
| 2519 |
{ |
|---|
| 2520 |
ebuf->bufnext = ebuf->bufstart + ebuf->size + 1; |
|---|
| 2521 |
return 0; |
|---|
| 2522 |
} |
|---|
| 2523 |
|
|---|
| 2524 |
|
|---|
| 2525 |
while (p > bol && *(--p) == '\\') |
|---|
| 2526 |
backslash = !backslash; |
|---|
| 2527 |
if (!backslash) |
|---|
| 2528 |
break; |
|---|
| 2529 |
++eol; |
|---|
| 2530 |
} |
|---|
| 2531 |
|
|---|
| 2532 |
|
|---|
| 2533 |
*eol = '\0'; |
|---|
| 2534 |
ebuf->bufnext = eol+1; |
|---|
| 2535 |
|
|---|
| 2536 |
return 0; |
|---|
| 2537 |
} |
|---|
| 2538 |
|
|---|
| 2539 |
static long |
|---|
| 2540 |
readline (struct ebuffer *ebuf) |
|---|
| 2541 |
{ |
|---|
| 2542 |
char *p; |
|---|
| 2543 |
char *end; |
|---|
| 2544 |
char *start; |
|---|
| 2545 |
long nlines = 0; |
|---|
| 2546 |
|
|---|
| 2547 |
|
|---|
| 2548 |
|
|---|
| 2549 |
|
|---|
| 2550 |
if (!ebuf->fp) |
|---|
| 2551 |
return readstring (ebuf); |
|---|
| 2552 |
|
|---|
| 2553 |
|
|---|
| 2554 |
|
|---|
| 2555 |
|
|---|
| 2556 |
p = start = ebuf->bufstart; |
|---|
| 2557 |
end = p + ebuf->size; |
|---|
| 2558 |
*p = '\0'; |
|---|
| 2559 |
|
|---|
| 2560 |
while (fgets (p, end - p, ebuf->fp) != 0) |
|---|
| 2561 |
{ |
|---|
| 2562 |
char *p2; |
|---|
| 2563 |
unsigned long len; |
|---|
| 2564 |
int backslash; |
|---|
| 2565 |
|
|---|
| 2566 |
len = strlen (p); |
|---|
| 2567 |
if (len == 0) |
|---|
| 2568 |
{ |
|---|
| 2569 |
|
|---|
| 2570 |
|
|---|
| 2571 |
|
|---|
| 2572 |
|
|---|
| 2573 |
|
|---|
| 2574 |
error (&ebuf->floc, |
|---|
| 2575 |
_("warning: NUL character seen; rest of line ignored")); |
|---|
| 2576 |
p[0] = '\n'; |
|---|
| 2577 |
len = 1; |
|---|
| 2578 |
} |
|---|
| 2579 |
|
|---|
| 2580 |
|
|---|
| 2581 |
p += len; |
|---|
| 2582 |
|
|---|
| 2583 |
|
|---|
| 2584 |
|
|---|
| 2585 |
if (p[-1] != '\n') |
|---|
| 2586 |
goto more_buffer; |
|---|
| 2587 |
|
|---|
| 2588 |
|
|---|
| 2589 |
++nlines; |
|---|
| 2590 |
|
|---|
| 2591 |
#if !defined(WINDOWS32) && !defined(__MSDOS__) && !defined(__EMX__) |
|---|
| 2592 |
|
|---|
| 2593 |
|
|---|
| 2594 |
if ((p - start) > 1 && p[-2] == '\r') |
|---|
| 2595 |
{ |
|---|
| 2596 |
--p; |
|---|
| 2597 |
p[-1] = '\n'; |
|---|
| 2598 |
} |
|---|
| 2599 |
#endif |
|---|
| 2600 |
|
|---|
| 2601 |
backslash = 0; |
|---|
| 2602 |
for (p2 = p - 2; p2 >= start; --p2) |
|---|
| 2603 |
{ |
|---|
| 2604 |
if (*p2 != '\\') |
|---|
| 2605 |
break; |
|---|
| 2606 |
backslash = !backslash; |
|---|
| 2607 |
} |
|---|
| 2608 |
|
|---|
| 2609 |
if (!backslash) |
|---|
| 2610 |
{ |
|---|
| 2611 |
p[-1] = '\0'; |
|---|
| 2612 |
break; |
|---|
| 2613 |
} |
|---|
| 2614 |
|
|---|
| 2615 |
|
|---|
| 2616 |
|
|---|
| 2617 |
if (end - p >= 80) |
|---|
| 2618 |
continue; |
|---|
| 2619 |
|
|---|
| 2620 |
|
|---|
| 2621 |
|
|---|
| 2622 |
more_buffer: |
|---|
| 2623 |
{ |
|---|
| 2624 |
unsigned long off = p - start; |
|---|
| 2625 |
ebuf->size *= 2; |
|---|
| 2626 |
start = ebuf->buffer = ebuf->bufstart = (char *) xrealloc (start, |
|---|
| 2627 |
ebuf->size); |
|---|
| 2628 |
p = start + off; |
|---|
| 2629 |
end = start + ebuf->size; |
|---|
| 2630 |
*p = '\0'; |
|---|
| 2631 |
} |
|---|
| 2632 |
} |
|---|
| 2633 |
|
|---|
| 2634 |
if (ferror (ebuf->fp)) |
|---|
| 2635 |
pfatal_with_name (ebuf->floc.filenm); |
|---|
| 2636 |
|
|---|
| 2637 |
|
|---|
| 2638 |
|
|---|
| 2639 |
|
|---|
| 2640 |
|
|---|
| 2641 |
|
|---|
| 2642 |
return nlines ? nlines : p == ebuf->bufstart ? -1 : 1; |
|---|
| 2643 |
} |
|---|
| 2644 |
|
|---|
| 2645 |
|
|---|
| 2646 |
|
|---|
| 2647 |
|
|---|
| 2648 |
|
|---|
| 2649 |
|
|---|
| 2650 |
|
|---|
| 2651 |
|
|---|
| 2652 |
|
|---|
| 2653 |
|
|---|
| 2654 |
|
|---|
| 2655 |
|
|---|
| 2656 |
|
|---|
| 2657 |
|
|---|
| 2658 |
|
|---|
| 2659 |
|
|---|
| 2660 |
|
|---|
| 2661 |
|
|---|
| 2662 |
|
|---|
| 2663 |
static enum make_word_type |
|---|
| 2664 |
get_next_mword (char *buffer, char *delim, char **startp, unsigned int *length) |
|---|
| 2665 |
{ |
|---|
| 2666 |
enum make_word_type wtype = w_bogus; |
|---|
| 2667 |
char *p = buffer, *beg; |
|---|
| 2668 |
char c; |
|---|
| 2669 |
|
|---|
| 2670 |
|
|---|
| 2671 |
while (isblank ((unsigned char)*p)) |
|---|
| 2672 |
++p; |
|---|
| 2673 |
|
|---|
| 2674 |
beg = p; |
|---|
| 2675 |
c = *(p++); |
|---|
| 2676 |
switch (c) |
|---|
| 2677 |
{ |
|---|
| 2678 |
case '\0': |
|---|
| 2679 |
wtype = w_eol; |
|---|
| 2680 |
break; |
|---|
| 2681 |
|
|---|
| 2682 |
case ';': |
|---|
| 2683 |
wtype = w_semicolon; |
|---|
| 2684 |
break; |
|---|
| 2685 |
|
|---|
| 2686 |
case '=': |
|---|
| 2687 |
wtype = w_varassign; |
|---|
| 2688 |
break; |
|---|
| 2689 |
|
|---|
| 2690 |
case ':': |
|---|
| 2691 |
wtype = w_colon; |
|---|
| 2692 |
switch (*p) |
|---|
| 2693 |
{ |
|---|
| 2694 |
case ':': |
|---|
| 2695 |
++p; |
|---|
| 2696 |
wtype = w_dcolon; |
|---|
| 2697 |
break; |
|---|
| 2698 |
|
|---|
| 2699 |
case '=': |
|---|
| 2700 |
++p; |
|---|
| 2701 |
wtype = w_varassign; |
|---|
| 2702 |
break; |
|---|
| 2703 |
} |
|---|
| 2704 |
break; |
|---|
| 2705 |
|
|---|
| 2706 |
case '+': |
|---|
| 2707 |
case '?': |
|---|
| 2708 |
if (*p == '=') |
|---|
| 2709 |
{ |
|---|
| 2710 |
++p; |
|---|
| 2711 |
wtype = w_varassign; |
|---|
| 2712 |
break; |
|---|
| 2713 |
} |
|---|
| 2714 |
|
|---|
| 2715 |
default: |
|---|
| 2716 |
if (delim && strchr (delim, c)) |
|---|
| 2717 |
wtype = w_static; |
|---|
| 2718 |
break; |
|---|
| 2719 |
} |
|---|
| 2720 |
|
|---|
| 2721 |
|
|---|
| 2722 |
if (wtype != w_bogus) |
|---|
| 2723 |
goto done; |
|---|
| 2724 |
|
|---|
| 2725 |
|
|---|
| 2726 |
|
|---|
| 2727 |
|
|---|
| 2728 |
|
|---|
| 2729 |
|
|---|
| 2730 |
|
|---|
| 2731 |
wtype = w_static; |
|---|
| 2732 |
|
|---|
| 2733 |
|
|---|
| 2734 |
while (1) |
|---|
| 2735 |
{ |
|---|
| 2736 |
char closeparen; |
|---|
| 2737 |
int count; |
|---|
| 2738 |
|
|---|
| 2739 |
switch (c) |
|---|
| 2740 |
{ |
|---|
| 2741 |
case '\0': |
|---|
| 2742 |
case ' ': |
|---|
| 2743 |
case '\t': |
|---|
| 2744 |
case '=': |
|---|
| 2745 |
goto done_word; |
|---|
| 2746 |
|
|---|
| 2747 |
case ':': |
|---|
| 2748 |
#ifdef HAVE_DOS_PATHS |
|---|
| 2749 |
|
|---|
| 2750 |
|
|---|
| 2751 |
|
|---|
| 2752 |
if (!(p - beg >= 2 |
|---|
| 2753 |
&& (*p == '/' || *p == '\\') && isalpha ((unsigned char)p[-2]) |
|---|
| 2754 |
&& (p - beg == 2 || p[-3] == '('))) |
|---|
| 2755 |
#endif |
|---|
| 2756 |
goto done_word; |
|---|
| 2757 |
|
|---|
| 2758 |
case '$': |
|---|
| 2759 |
c = *(p++); |
|---|
| 2760 |
if (c == '$') |
|---|
| 2761 |
break; |
|---|
| 2762 |
|
|---|
| 2763 |
|
|---|
| 2764 |
|
|---|
| 2765 |
wtype = w_variable; |
|---|
| 2766 |
|
|---|
| 2767 |
if (c == '(') |
|---|
| 2768 |
closeparen = ')'; |
|---|
| 2769 |
else if (c == '{') |
|---|
| 2770 |
closeparen = '}'; |
|---|
| 2771 |
else |
|---|
| 2772 |
|
|---|
| 2773 |
break; |
|---|
| 2774 |
|
|---|
| 2775 |
for (count=0; *p != '\0'; ++p) |
|---|
| 2776 |
{ |
|---|
| 2777 |
if (*p == c) |
|---|
| 2778 |
++count; |
|---|
| 2779 |
else if (*p == closeparen && --count < 0) |
|---|
| 2780 |
{ |
|---|
| 2781 |
++p; |
|---|
| 2782 |
break; |
|---|
| 2783 |
} |
|---|
| 2784 |
} |
|---|
| 2785 |
break; |
|---|
| 2786 |
|
|---|
| 2787 |
case '?': |
|---|
| 2788 |
case '+': |
|---|
| 2789 |
if (*p == '=') |
|---|
| 2790 |
goto done_word; |
|---|
| 2791 |
break; |
|---|
| 2792 |
|
|---|
| 2793 |
case '\\': |
|---|
| 2794 |
switch (*p) |
|---|
| 2795 |
{ |
|---|
| 2796 |
case ':': |
|---|
| 2797 |
case ';': |
|---|
| 2798 |
case '=': |
|---|
| 2799 |
case '\\': |
|---|
| 2800 |
++p; |
|---|
| 2801 |
break; |
|---|
| 2802 |
} |
|---|
| 2803 |
break; |
|---|
| 2804 |
|
|---|
| 2805 |
default: |
|---|
| 2806 |
if (delim && strchr (delim, c)) |
|---|
| 2807 |
goto done_word; |
|---|
| 2808 |
break; |
|---|
| 2809 |
} |
|---|
| 2810 |
|
|---|
| 2811 |
c = *(p++); |
|---|
| 2812 |
} |
|---|
| 2813 |
done_word: |
|---|
| 2814 |
--p; |
|---|
| 2815 |
|
|---|
| 2816 |
done: |
|---|
| 2817 |
if (startp) |
|---|
| 2818 |
*startp = beg; |
|---|
| 2819 |
if (length) |
|---|
| 2820 |
*length = p - beg; |
|---|
| 2821 |
return wtype; |
|---|
| 2822 |
} |
|---|
| 2823 |
|
|---|
| 2824 |
|
|---|
| 2825 |
|
|---|
| 2826 |
|
|---|
| 2827 |
void |
|---|
| 2828 |
construct_include_path (char **arg_dirs) |
|---|
| 2829 |
{ |
|---|
| 2830 |
register unsigned int i; |
|---|
| 2831 |
#ifdef VAXC |
|---|
| 2832 |
stat_t stbuf; |
|---|
| 2833 |
#else |
|---|
| 2834 |
struct stat stbuf; |
|---|
| 2835 |
#endif |
|---|
| 2836 |
|
|---|
| 2837 |
|
|---|
| 2838 |
register unsigned int defsize = (sizeof (default_include_directories) |
|---|
| 2839 |
/ sizeof (default_include_directories[0])); |
|---|
| 2840 |
register unsigned int max = 5; |
|---|
| 2841 |
register char **dirs = (char **) xmalloc ((5 + defsize) * sizeof (char *)); |
|---|
| 2842 |
register unsigned int idx = 0; |
|---|
| 2843 |
|
|---|
| 2844 |
#ifdef __MSDOS__ |
|---|
| 2845 |
defsize++; |
|---|
| 2846 |
#endif |
|---|
| 2847 |
|
|---|
| 2848 |
|
|---|
| 2849 |
|
|---|
| 2850 |
|
|---|
| 2851 |
if (arg_dirs != 0) |
|---|
| 2852 |
while (*arg_dirs != 0) |
|---|
| 2853 |
{ |
|---|
| 2854 |
char *dir = *arg_dirs++; |
|---|
| 2855 |
int e; |
|---|
| 2856 |
|
|---|
| 2857 |
if (dir[0] == '~') |
|---|
| 2858 |
{ |
|---|
| 2859 |
char *expanded = tilde_expand (dir); |
|---|
| 2860 |
if (expanded != 0) |
|---|
| 2861 |
dir = expanded; |
|---|
| 2862 |
} |
|---|
| 2863 |
|
|---|
| 2864 |
EINTRLOOP (e, stat (dir, &stbuf)); |
|---|
| 2865 |
if (e == 0 && S_ISDIR (stbuf.st_mode)) |
|---|
| 2866 |
{ |
|---|
| 2867 |
if (idx == max - 1) |
|---|
| 2868 |
{ |
|---|
| 2869 |
max += 5; |
|---|
| 2870 |
dirs = (char **) |
|---|
| 2871 |
xrealloc ((char *) dirs, (max + defsize) * sizeof (char *)); |
|---|
| 2872 |
} |
|---|
| 2873 |
dirs[idx++] = dir; |
|---|
| 2874 |
} |
|---|
| 2875 |
else if (dir != arg_dirs[-1]) |
|---|
| 2876 |
free (dir); |
|---|
| 2877 |
} |
|---|
| 2878 |
|
|---|
| 2879 |
|
|---|
| 2880 |
|
|---|
| 2881 |
#ifdef __MSDOS__ |
|---|
| 2882 |
{ |
|---|
| 2883 |
|
|---|
| 2884 |
|
|---|
| 2885 |
struct variable *djdir = lookup_variable ("DJDIR", 5); |
|---|
| 2886 |
|
|---|
| 2887 |
if (djdir) |
|---|
| 2888 |
{ |
|---|
| 2889 |
char *defdir = (char *) xmalloc (strlen (djdir->value) + 8 + 1); |
|---|
| 2890 |
|
|---|
| 2891 |
strcat (strcpy (defdir, djdir->value), "/include"); |
|---|
| 2892 |
dirs[idx++] = defdir; |
|---|
| 2893 |
} |
|---|
| 2894 |
} |
|---|
| 2895 |
#endif |
|---|
| 2896 |
|
|---|
| 2897 |
for (i = 0; default_include_directories[i] != 0; ++i) |
|---|
| 2898 |
{ |
|---|
| 2899 |
int e; |
|---|
| 2900 |
|
|---|
| 2901 |
EINTRLOOP (e, stat (default_include_directories[i], &stbuf)); |
|---|
| 2902 |
if (e == 0 && S_ISDIR (stbuf.st_mode)) |
|---|
| 2903 |
dirs[idx++] = default_include_directories[i]; |
|---|
| 2904 |
} |
|---|
| 2905 |
|
|---|
| 2906 |
dirs[idx] = 0; |
|---|
| 2907 |
|
|---|
| 2908 |
|
|---|
| 2909 |
|
|---|
| 2910 |
|
|---|
| 2911 |
max_incl_len = 0; |
|---|
| 2912 |
for (i = 0; i < idx; ++i) |
|---|
| 2913 |
{ |
|---|
| 2914 |
unsigned int len = strlen (dirs[i]); |
|---|
| 2915 |
|
|---|
| 2916 |
if (dirs[i][len - 1] == '/') |
|---|
| 2917 |
|
|---|
| 2918 |
|
|---|
| 2919 |
dirs[i] = savestring (dirs[i], len - 1); |
|---|
| 2920 |
if (len > max_incl_len) |
|---|
| 2921 |
max_incl_len = len; |
|---|
| 2922 |
|
|---|
| 2923 |
|
|---|
| 2924 |
do_variable_definition (NILF, ".INCLUDE_DIRS", dirs[i], |
|---|
| 2925 |
o_default, f_append, 0); |
|---|
| 2926 |
} |
|---|
| 2927 |
|
|---|
| 2928 |
include_directories = dirs; |
|---|
| 2929 |
} |
|---|
| 2930 |
|
|---|
| 2931 |
|
|---|
| 2932 |
|
|---|
| 2933 |
|
|---|
| 2934 |
char * |
|---|
| 2935 |
tilde_expand (char *name) |
|---|
| 2936 |
{ |
|---|
| 2937 |
#ifndef VMS |
|---|
| 2938 |
if (name[1] == '/' || name[1] == '\0') |
|---|
| 2939 |
{ |
|---|
| 2940 |
extern char *getenv (); |
|---|
| 2941 |
char *home_dir; |
|---|
| 2942 |
int is_variable; |
|---|
| 2943 |
|
|---|
| 2944 |
{ |
|---|
| 2945 |
|
|---|
| 2946 |
int save = warn_undefined_variables_flag; |
|---|
| 2947 |
warn_undefined_variables_flag = 0; |
|---|
| 2948 |
|
|---|
| 2949 |
home_dir = allocated_variable_expand ("$(HOME)"); |
|---|
| 2950 |
|
|---|
| 2951 |
warn_undefined_variables_flag = save; |
|---|
| 2952 |
} |
|---|
| 2953 |
|
|---|
| 2954 |
is_variable = home_dir[0] != '\0'; |
|---|
| 2955 |
if (!is_variable) |
|---|
| 2956 |
{ |
|---|
| 2957 |
free (home_dir); |
|---|
| 2958 |
home_dir = getenv ("HOME"); |
|---|
| 2959 |
} |
|---|
| 2960 |
#if !defined(_AMIGA) && !defined(WINDOWS32) |
|---|
| 2961 |
if (home_dir == 0 || home_dir[0] == '\0') |
|---|
| 2962 |
{ |
|---|
| 2963 |
extern char *getlogin (); |
|---|
| 2964 |
char *logname = getlogin (); |
|---|
| 2965 |
home_dir = 0; |
|---|
| 2966 |
if (logname != 0) |
|---|
| 2967 |
{ |
|---|
| 2968 |
struct passwd *p = getpwnam (logname); |
|---|
| 2969 |
if (p != 0) |
|---|
| 2970 |
home_dir = p->pw_dir; |
|---|
| 2971 |
} |
|---|
| 2972 |
} |
|---|
| 2973 |
#endif |
|---|
| 2974 |
if (home_dir != 0) |
|---|
| 2975 |
{ |
|---|
| 2976 |
char *new = concat (home_dir, "", name + 1); |
|---|
| 2977 |
if (is_variable) |
|---|
| 2978 |
free (home_dir); |
|---|
| 2979 |
return new; |
|---|
| 2980 |
} |
|---|
| 2981 |
} |
|---|
| 2982 |
#if !defined(_AMIGA) && !defined(WINDOWS32) |
|---|
| 2983 |
else |
|---|
| 2984 |
{ |
|---|
| 2985 |
struct passwd *pwent; |
|---|
| 2986 |
char *userend = strchr (name + 1, '/'); |
|---|
| 2987 |
if (userend != 0) |
|---|
| 2988 |
*userend = '\0'; |
|---|
| 2989 |
pwent = getpwnam (name + 1); |
|---|
| 2990 |
if (pwent != 0) |
|---|
| 2991 |
{ |
|---|
| 2992 |
if (userend == 0) |
|---|
| 2993 |
return xstrdup (pwent->pw_dir); |
|---|
| 2994 |
else |
|---|
| 2995 |
return concat (pwent->pw_dir, "/", userend + 1); |
|---|
| 2996 |
} |
|---|
| 2997 |
else if (userend != 0) |
|---|
| 2998 |
*userend = '/'; |
|---|
| 2999 |
} |
|---|
| 3000 |
#endif |
|---|
| 3001 |
#endif |
|---|
| 3002 |
return 0; |
|---|
| 3003 |
} |
|---|
| 3004 |
|
|---|
| 3005 |
|
|---|
| 3006 |
|
|---|
| 3007 |
|
|---|
| 3008 |
|
|---|
| 3009 |
|
|---|
| 3010 |
|
|---|
| 3011 |
|
|---|
| 3012 |
|
|---|
| 3013 |
|
|---|
| 3014 |
|
|---|
| 3015 |
struct nameseq * |
|---|
| 3016 |
multi_glob (struct nameseq *chain, unsigned int size) |
|---|
| 3017 |
{ |
|---|
| 3018 |
extern void dir_setup_glob (); |
|---|
| 3019 |
register struct nameseq *new = 0; |
|---|
| 3020 |
register struct nameseq *old; |
|---|
| 3021 |
struct nameseq *nexto; |
|---|
| 3022 |
glob_t gl; |
|---|
| 3023 |
|
|---|
| 3024 |
dir_setup_glob (&gl); |
|---|
| 3025 |
|
|---|
| 3026 |
for (old = chain; old != 0; old = nexto) |
|---|
| 3027 |
{ |
|---|
| 3028 |
#ifndef NO_ARCHIVES |
|---|
| 3029 |
char *memname; |
|---|
| 3030 |
#endif |
|---|
| 3031 |
|
|---|
| 3032 |
nexto = old->next; |
|---|
| 3033 |
|
|---|
| 3034 |
if (old->name[0] == '~') |
|---|
| 3035 |
{ |
|---|
| 3036 |
char *newname = tilde_expand (old->name); |
|---|
| 3037 |
if (newname != 0) |
|---|
| 3038 |
{ |
|---|
| 3039 |
free (old->name); |
|---|
| 3040 |
old->name = newname; |
|---|
| 3041 |
} |
|---|
| 3042 |
} |
|---|
| 3043 |
|
|---|
| 3044 |
#ifndef NO_ARCHIVES |
|---|
| 3045 |
if (ar_name (old->name)) |
|---|
| 3046 |
{ |
|---|
| 3047 |
|
|---|
| 3048 |
|
|---|
| 3049 |
|
|---|
| 3050 |
|
|---|
| 3051 |
|
|---|
| 3052 |
char *arname; |
|---|
| 3053 |
ar_parse_name (old->name, &arname, &memname); |
|---|
| 3054 |
free (old->name); |
|---|
| 3055 |
old->name = arname; |
|---|
| 3056 |
} |
|---|
| 3057 |
else |
|---|
| 3058 |
memname = 0; |
|---|
| 3059 |
#endif |
|---|
| 3060 |
|
|---|
| 3061 |
switch (glob (old->name, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl)) |
|---|
| 3062 |
{ |
|---|
| 3063 |
case 0: |
|---|
| 3064 |
{ |
|---|
| 3065 |
register int i = gl.gl_pathc; |
|---|
| 3066 |
while (i-- > 0) |
|---|
| 3067 |
{ |
|---|
| 3068 |
#ifndef NO_ARCHIVES |
|---|
| 3069 |
if (memname != 0) |
|---|
| 3070 |
{ |
|---|
| 3071 |
|
|---|
| 3072 |
struct nameseq *found |
|---|
| 3073 |
= ar_glob (gl.gl_pathv[i], memname, size); |
|---|
| 3074 |
if (found == 0) |
|---|
| 3075 |
{ |
|---|
| 3076 |
|
|---|
| 3077 |
unsigned int alen = strlen (gl.gl_pathv[i]); |
|---|
| 3078 |
unsigned int mlen = strlen (memname); |
|---|
| 3079 |
struct nameseq *elt |
|---|
| 3080 |
= (struct nameseq *) xmalloc (size); |
|---|
| 3081 |
if (size > sizeof (struct nameseq)) |
|---|
| 3082 |
bzero (((char *) elt) + sizeof (struct nameseq), |
|---|
| 3083 |
size - sizeof (struct nameseq)); |
|---|
| 3084 |
elt->name = (char *) xmalloc (alen + 1 + mlen + 2); |
|---|
| 3085 |
bcopy (gl.gl_pathv[i], elt->name, alen); |
|---|
| 3086 |
elt->name[alen] = '('; |
|---|
| 3087 |
bcopy (memname, &elt->name[alen + 1], mlen); |
|---|
| 3088 |
elt->name[alen + 1 + mlen] = ')'; |
|---|
| 3089 |
elt->name[alen + 1 + mlen + 1] = '\0'; |
|---|
| 3090 |
elt->next = new; |
|---|
| 3091 |
new = elt; |
|---|
| 3092 |
} |
|---|
| 3093 |
else |
|---|
| 3094 |
{ |
|---|
| 3095 |
|
|---|
| 3096 |
struct nameseq *f = found; |
|---|
| 3097 |
while (f->next != 0) |
|---|
| 3098 |
f = f->next; |
|---|
| 3099 |
|
|---|
| 3100 |
|
|---|
| 3101 |
|
|---|
| 3102 |
f->next = new; |
|---|
| 3103 |
new = found; |
|---|
| 3104 |
} |
|---|
| 3105 |
|
|---|
| 3106 |
free (memname); |
|---|
| 3107 |
} |
|---|
| 3108 |
else |
|---|
| 3109 |
#endif |
|---|
| 3110 |
{ |
|---|
| 3111 |
struct nameseq *elt = (struct nameseq *) xmalloc (size); |
|---|
| 3112 |
if (size > sizeof (struct nameseq)) |
|---|
| 3113 |
bzero (((char *) elt) + sizeof (struct nameseq), |
|---|
| 3114 |
size - sizeof (struct nameseq)); |
|---|
| 3115 |
elt->name = xstrdup (gl.gl_pathv[i]); |
|---|
| 3116 |
elt->next = new; |
|---|
| 3117 |
new = elt; |
|---|
| 3118 |
} |
|---|
| 3119 |
} |
|---|
| 3120 |
globfree (&gl); |
|---|
| 3121 |
free (old->name); |
|---|
| 3122 |
free ((char *)old); |
|---|
| 3123 |
break; |
|---|
| 3124 |
} |
|---|
| 3125 |
|
|---|
| 3126 |
case GLOB_NOSPACE: |
|---|
| 3127 |
fatal (NILF, _("virtual memory exhausted")); |
|---|
| 3128 |
break; |
|---|
| 3129 |
|
|---|
| 3130 |
default: |
|---|
| 3131 |
old->next = new; |
|---|
| 3132 |
new = old; |
|---|
| 3133 |
break; |
|---|
| 3134 |
} |
|---|
| 3135 |
} |
|---|
| 3136 |
|
|---|
| 3137 |
return new; |
|---|
| 3138 |
} |
|---|