VirtualBox

source: kBuild/trunk/src/gmake/read.c@ 520

Last change on this file since 520 was 520, checked in by bird, 19 years ago

Cleaning up the modifications. Changes are now either configurable or marked, and dead stuff has been removed (dll shell).

  • Property svn:eol-style set to native
File size: 89.2 KB
Line 
1/* Reading and parsing of makefiles for GNU Make.
2Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
4Foundation, Inc.
5This file is part of GNU Make.
6
7GNU Make is free software; you can redistribute it and/or modify it under the
8terms of the GNU General Public License as published by the Free Software
9Foundation; either version 2, or (at your option) any later version.
10
11GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License along with
16GNU Make; see the file COPYING. If not, write to the Free Software
17Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */
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
40struct passwd *getpwnam PARAMS ((char *name));
41#endif
42#endif
43#endif /* !WINDOWS32 */
44
45/* A 'struct ebuffer' controls the origin of the makefile we are currently
46 eval'ing.
47*/
48
49struct ebuffer
50 {
51 char *buffer; /* Start of the current line in the buffer. */
52 char *bufnext; /* Start of the next line in the buffer. */
53 char *bufstart; /* Start of the entire buffer. */
54 unsigned int size; /* Malloc'd size of buffer. */
55 FILE *fp; /* File, or NULL if this is an internal buffer. */
56 struct floc floc; /* Info on the file in fp (if any). */
57 };
58
59/* Types of "words" that can be read in a makefile. */
60enum 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/* A `struct conditionals' contains the information describing
68 all the active conditionals in a makefile.
69
70 The global variable `conditionals' contains the conditionals
71 information for the current makefile. It is initialized from
72 the static structure `toplevel_conditionals' and is later changed
73 to new structures for included makefiles. */
74
75struct conditionals
76 {
77 unsigned int if_cmds; /* Depth of conditional nesting. */
78 unsigned int allocated; /* Elts allocated in following arrays. */
79 char *ignoring; /* Are we ignoring or interpreting?
80 0=interpreting, 1=not yet interpreted,
81 2=already interpreted */
82 char *seen_else; /* Have we already seen an `else'? */
83 };
84
85static struct conditionals toplevel_conditionals;
86static struct conditionals *conditionals = &toplevel_conditionals;
87
88
89/* Default directories to search for include files in */
90
91static char *default_include_directories[] =
92 {
93#if defined(WINDOWS32) && !defined(INCLUDEDIR)
94/*
95 * This completely up to the user when they install MSVC or other packages.
96 * This is defined as a placeholder.
97 */
98#define INCLUDEDIR "."
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/* List of directories to search for include files in */
110
111static char **include_directories;
112
113/* Maximum length of an element of the above. */
114
115static unsigned int max_incl_len;
116
117/* The filename and pointer to line number of the
118 makefile currently being read in. */
119
120const struct floc *reading_file = 0;
121
122/* The chain of makefiles read by read_makefile. */
123
124static struct dep *read_makefiles = 0;
125
126static int eval_makefile PARAMS ((char *filename, int flags));
127static int eval PARAMS ((struct ebuffer *buffer, int flags));
128
129static long readline PARAMS ((struct ebuffer *ebuf));
130static void do_define PARAMS ((char *name, unsigned int namelen,
131 enum variable_origin origin,
132 struct ebuffer *ebuf));
133static int conditional_line PARAMS ((char *line, int len, const struct floc *flocp));
134static 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));
138static void record_target_var PARAMS ((struct nameseq *filenames, char *defn,
139 enum variable_origin origin,
140 int enabled,
141 const struct floc *flocp));
142static enum make_word_type get_next_mword PARAMS ((char *buffer, char *delim,
143 char **startp, unsigned int *length));
144static void remove_comments PARAMS ((char *line));
145static char *find_char_unquote PARAMS ((char *string, int stop1,
146 int stop2, int blank, int ignorevars));
147
148
149/* Read in all the makefiles and return the chain of their names. */
150
151struct dep *
152read_all_makefiles (char **makefiles)
153{
154 unsigned int num_makefiles = 0;
155
156 /* Create *_LIST variables, to hold the makefiles, targets, and variables
157 we will be reading. */
158
159 define_variable ("MAKEFILE_LIST", sizeof ("MAKEFILE_LIST")-1, "", o_file, 0);
160
161 DB (DB_BASIC, (_("Reading makefiles...\n")));
162
163 /* If there's a non-null variable MAKEFILES, its value is a list of
164 files to read first thing. But don't let it prevent reading the
165 default makefiles and don't let the default goal come from there. */
166
167 {
168 char *value;
169 char *name, *p;
170 unsigned int length;
171
172 {
173 /* Turn off --warn-undefined-variables while we expand MAKEFILES. */
174 int save = warn_undefined_variables_flag;
175 warn_undefined_variables_flag = 0;
176
177 value = allocated_variable_expand ("$(MAKEFILES)");
178
179 warn_undefined_variables_flag = save;
180 }
181
182 /* Set NAME to the start of next token and LENGTH to its length.
183 MAKEFILES is updated for finding remaining tokens. */
184 p = value;
185
186 while ((name = find_next_token (&p, &length)) != 0)
187 {
188 if (*p != '\0')
189 *p++ = '\0';
190 eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE);
191 }
192
193 free (value);
194 }
195
196 /* Read makefiles specified with -f switches. */
197
198 if (makefiles != 0)
199 while (*makefiles != 0)
200 {
201 struct dep *tail = read_makefiles;
202 register struct dep *d;
203
204 if (! eval_makefile (*makefiles, 0))
205 perror_with_name ("", *makefiles);
206
207 /* Find the right element of read_makefiles. */
208 d = read_makefiles;
209 while (d->next != tail)
210 d = d->next;
211
212 /* Use the storage read_makefile allocates. */
213 *makefiles = dep_name (d);
214 ++num_makefiles;
215 ++makefiles;
216 }
217
218 /* If there were no -f switches, try the default names. */
219
220 if (num_makefiles == 0)
221 {
222 static char *default_makefiles[] =
223#ifdef VMS
224 /* all lower case since readdir() (the vms version) 'lowercasifies' */
225# ifdef KMK
226 { "makefile.kmk", "makefile.vms", "gnumakefile.", "makefile.", 0 };
227# else
228 { "makefile.vms", "gnumakefile.", "makefile.", 0 };
229# endif
230#else
231#ifdef _AMIGA
232 /* what's the deal here? no dots? */
233# ifdef KMK
234 { "Makefile.kmk", "makefile.kmk", "GNUmakefile", "Makefile", "SMakefile", 0 };
235# else
236 { "GNUmakefile", "Makefile", "SMakefile", 0 };
237# endif
238#else /* !Amiga && !VMS */
239# ifdef KMK
240 { "Makefile.kmk", "makefile.kmk", "GNUmakefile", "makefile", "Makefile", 0 };
241# else
242 { "GNUmakefile", "makefile", "Makefile", 0 };
243# endif
244#endif /* AMIGA */
245#endif /* VMS */
246 register char **p = default_makefiles;
247 while (*p != 0 && !file_exists_p (*p))
248 ++p;
249
250 if (*p != 0)
251 {
252 if (! eval_makefile (*p, 0))
253 perror_with_name ("", *p);
254 }
255 else
256 {
257 /* No default makefile was found. Add the default makefiles to the
258 `read_makefiles' chain so they will be updated if possible. */
259 struct dep *tail = read_makefiles;
260 /* Add them to the tail, after any MAKEFILES variable makefiles. */
261 while (tail != 0 && tail->next != 0)
262 tail = tail->next;
263 for (p = default_makefiles; *p != 0; ++p)
264 {
265 struct dep *d = alloc_dep ();
266 d->file = enter_file (*p);
267 d->file->dontcare = 1;
268 /* Tell update_goal_chain to bail out as soon as this file is
269 made, and main not to die if we can't make this file. */
270 d->changed = RM_DONTCARE;
271 if (tail == 0)
272 read_makefiles = d;
273 else
274 tail->next = d;
275 tail = d;
276 }
277 if (tail != 0)
278 tail->next = 0;
279 }
280 }
281
282 return read_makefiles;
283}
284
285
286/* Install a new conditional and return the previous one. */
287
288static struct conditionals *
289install_conditionals (struct conditionals *new)
290{
291 struct conditionals *save = conditionals;
292
293 bzero ((char *) new, sizeof (*new));
294 conditionals = new;
295
296 return save;
297}
298
299/* Free the current conditionals and reinstate a saved one. */
300
301static void
302restore_conditionals (struct conditionals *saved)
303{
304 /* Free any space allocated by conditional_line. */
305 if (conditionals->ignoring)
306 free (conditionals->ignoring);
307 if (conditionals->seen_else)
308 free (conditionals->seen_else);
309
310 /* Restore state. */
311 conditionals = saved;
312}
313
314
315static int
316eval_makefile (char *filename, int flags)
317{
318 struct dep *deps;
319 struct ebuffer ebuf;
320 const struct floc *curfile;
321 char *expanded = 0;
322 char *included = 0;
323 int makefile_errno;
324 int r;
325
326 ebuf.floc.filenm = strcache_add (filename);
327 ebuf.floc.lineno = 1;
328
329 if (ISDB (DB_VERBOSE))
330 {
331 printf (_("Reading makefile `%s'"), filename);
332 if (flags & RM_NO_DEFAULT_GOAL)
333 printf (_(" (no default goal)"));
334 if (flags & RM_INCLUDED)
335 printf (_(" (search path)"));
336 if (flags & RM_DONTCARE)
337 printf (_(" (don't care)"));
338 if (flags & RM_NO_TILDE)
339 printf (_(" (no ~ expansion)"));
340 puts ("...");
341 }
342
343 /* First, get a stream to read. */
344
345 /* Expand ~ in FILENAME unless it came from `include',
346 in which case it was already done. */
347 if (!(flags & RM_NO_TILDE) && filename[0] == '~')
348 {
349 expanded = tilde_expand (filename);
350 if (expanded != 0)
351 filename = expanded;
352 }
353
354 ebuf.fp = fopen (filename, "r");
355 /* Save the error code so we print the right message later. */
356 makefile_errno = errno;
357
358 /* If the makefile wasn't found and it's either a makefile from
359 the `MAKEFILES' variable or an included makefile,
360 search the included makefile search path for this makefile. */
361 if (ebuf.fp == 0 && (flags & RM_INCLUDED) && *filename != '/')
362 {
363 register unsigned int i;
364 for (i = 0; include_directories[i] != 0; ++i)
365 {
366 included = concat (include_directories[i], "/", filename);
367 ebuf.fp = fopen (included, "r");
368 if (ebuf.fp)
369 {
370 filename = included;
371 break;
372 }
373 free (included);
374 }
375 /* If we're not using it, we already freed it above. */
376 if (filename != included)
377 included = 0;
378 }
379
380 /* Add FILENAME to the chain of read makefiles. */
381 deps = alloc_dep ();
382 deps->next = read_makefiles;
383 read_makefiles = deps;
384 deps->file = lookup_file (filename);
385 if (deps->file == 0)
386 deps->file = enter_file (xstrdup (filename));
387 filename = deps->file->name;
388 deps->changed = flags;
389 if (flags & RM_DONTCARE)
390 deps->file->dontcare = 1;
391
392 if (expanded)
393 free (expanded);
394 if (included)
395 free (included);
396
397 /* If the makefile can't be found at all, give up entirely. */
398
399 if (ebuf.fp == 0)
400 {
401 /* If we did some searching, errno has the error from the last
402 attempt, rather from FILENAME itself. Restore it in case the
403 caller wants to use it in a message. */
404 errno = makefile_errno;
405 return 0;
406 }
407
408 /* Add this makefile to the list. */
409 do_variable_definition (&ebuf.floc, "MAKEFILE_LIST", filename, o_file,
410 f_append, 0);
411
412 /* Evaluate the makefile */
413
414 ebuf.size = 200;
415 ebuf.buffer = ebuf.bufnext = ebuf.bufstart = xmalloc (ebuf.size);
416
417 curfile = reading_file;
418 reading_file = &ebuf.floc;
419
420 r = eval (&ebuf, !(flags & RM_NO_DEFAULT_GOAL));
421
422 reading_file = curfile;
423
424 fclose (ebuf.fp);
425
426 free (ebuf.bufstart);
427 alloca (0);
428 return r;
429}
430
431int
432eval_buffer (char *buffer)
433{
434 struct ebuffer ebuf;
435 struct conditionals *saved;
436 struct conditionals new;
437 const struct floc *curfile;
438 int r;
439
440 /* Evaluate the buffer */
441
442 ebuf.size = strlen (buffer);
443 ebuf.buffer = ebuf.bufnext = ebuf.bufstart = buffer;
444 ebuf.fp = NULL;
445
446 ebuf.floc = *reading_file;
447
448 curfile = reading_file;
449 reading_file = &ebuf.floc;
450
451 saved = install_conditionals (&new);
452
453 r = eval (&ebuf, 1);
454
455 restore_conditionals (saved);
456
457 reading_file = curfile;
458
459 alloca (0);
460 return r;
461}
462
463
464
465/* Read file FILENAME as a makefile and add its contents to the data base.
466
467 SET_DEFAULT is true if we are allowed to set the default goal. */
468
469
470static int
471eval (struct ebuffer *ebuf, int set_default)
472{
473 char *collapsed = 0;
474 unsigned int collapsed_length = 0;
475 unsigned int commands_len = 200;
476 char *commands;
477 unsigned int commands_idx = 0;
478 unsigned int cmds_started, tgts_started;
479 int ignoring = 0, in_ignored_define = 0;
480 int no_targets = 0; /* Set when reading a rule without targets. */
481 struct nameseq *filenames = 0;
482 struct dep *deps = 0;
483 long nlines = 0;
484 int two_colon = 0;
485 char *pattern = 0, *pattern_percent;
486 struct floc *fstart;
487 struct floc fi;
488
489#define record_waiting_files() \
490 do \
491 { \
492 if (filenames != 0) \
493 { \
494 fi.lineno = tgts_started; \
495 record_files (filenames, pattern, pattern_percent, deps, \
496 cmds_started, commands, commands_idx, two_colon, \
497 &fi); \
498 } \
499 filenames = 0; \
500 commands_idx = 0; \
501 no_targets = 0; \
502 if (pattern) { free(pattern); pattern = 0; } \
503 } while (0)
504
505 pattern_percent = 0;
506 cmds_started = tgts_started = 1;
507
508 fstart = &ebuf->floc;
509 fi.filenm = ebuf->floc.filenm;
510
511 /* Loop over lines in the file.
512 The strategy is to accumulate target names in FILENAMES, dependencies
513 in DEPS and commands in COMMANDS. These are used to define a rule
514 when the start of the next rule (or eof) is encountered.
515
516 When you see a "continue" in the loop below, that means we are moving on
517 to the next line _without_ ending any rule that we happen to be working
518 with at the moment. If you see a "goto rule_complete", then the
519 statement we just parsed also finishes the previous rule. */
520
521 commands = xmalloc (200);
522
523 while (1)
524 {
525 unsigned int linelen;
526 char *line;
527 int len;
528 char *p;
529 char *p2;
530
531 /* Grab the next line to be evaluated */
532 ebuf->floc.lineno += nlines;
533 nlines = readline (ebuf);
534
535 /* If there is nothing left to eval, we're done. */
536 if (nlines < 0)
537 break;
538
539 /* If this line is empty, skip it. */
540 line = ebuf->buffer;
541 if (line[0] == '\0')
542 continue;
543
544 linelen = strlen (line);
545
546 /* Check for a shell command line first.
547 If it is not one, we can stop treating tab specially. */
548 if (line[0] == '\t')
549 {
550 if (no_targets)
551 /* Ignore the commands in a rule with no targets. */
552 continue;
553
554 /* If there is no preceding rule line, don't treat this line
555 as a command, even though it begins with a tab character.
556 SunOS 4 make appears to behave this way. */
557
558 if (filenames != 0)
559 {
560 if (ignoring)
561 /* Yep, this is a shell command, and we don't care. */
562 continue;
563
564 /* Append this command line to the line being accumulated. */
565 if (commands_idx == 0)
566 cmds_started = ebuf->floc.lineno;
567
568 if (linelen + 1 + commands_idx > commands_len)
569 {
570 commands_len = (linelen + 1 + commands_idx) * 2;
571 commands = xrealloc (commands, commands_len);
572 }
573 bcopy (line, &commands[commands_idx], linelen);
574 commands_idx += linelen;
575 commands[commands_idx++] = '\n';
576
577 continue;
578 }
579 }
580
581 /* This line is not a shell command line. Don't worry about tabs.
582 Get more space if we need it; we don't need to preserve the current
583 contents of the buffer. */
584
585 if (collapsed_length < linelen+1)
586 {
587 collapsed_length = linelen+1;
588 if (collapsed)
589 free ((char *)collapsed);
590 collapsed = (char *) xmalloc (collapsed_length);
591 }
592 strcpy (collapsed, line);
593 /* Collapse continuation lines. */
594 collapse_continuations (collapsed);
595 remove_comments (collapsed);
596
597 /* Compare a word, both length and contents. */
598#define word1eq(s) (len == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))
599 p = collapsed;
600 while (isspace ((unsigned char)*p))
601 ++p;
602
603 if (*p == '\0')
604 /* This line is completely empty--ignore it. */
605 continue;
606
607 /* Find the end of the first token. Note we don't need to worry about
608 * ":" here since we compare tokens by length (so "export" will never
609 * be equal to "export:").
610 */
611 for (p2 = p+1; *p2 != '\0' && !isspace ((unsigned char)*p2); ++p2)
612 ;
613 len = p2 - p;
614
615 /* Find the start of the second token. If it looks like a target or
616 variable definition it can't be a preprocessor token so skip
617 them--this allows variables/targets named `ifdef', `export', etc. */
618 while (isspace ((unsigned char)*p2))
619 ++p2;
620
621 if ((p2[0] == ':' || p2[0] == '+' || p2[0] == '=') && p2[1] == '\0')
622 {
623 /* It can't be a preprocessor token so skip it if we're ignoring */
624 if (ignoring)
625 continue;
626
627 goto skip_conditionals;
628 }
629
630 /* We must first check for conditional and `define' directives before
631 ignoring anything, since they control what we will do with
632 following lines. */
633
634 if (!in_ignored_define)
635 {
636 int i = conditional_line (p, len, fstart);
637 if (i != -2)
638 {
639 if (i == -1)
640 fatal (fstart, _("invalid syntax in conditional"));
641
642 ignoring = i;
643 continue;
644 }
645 }
646
647 if (word1eq ("endef"))
648 {
649 if (!in_ignored_define)
650 fatal (fstart, _("extraneous `endef'"));
651 in_ignored_define = 0;
652 continue;
653 }
654
655 if (word1eq ("define"))
656 {
657 if (ignoring)
658 in_ignored_define = 1;
659 else
660 {
661 if (*p2 == '\0')
662 fatal (fstart, _("empty variable name"));
663
664 /* Let the variable name be the whole rest of the line,
665 with trailing blanks stripped (comments have already been
666 removed), so it could be a complex variable/function
667 reference that might contain blanks. */
668 p = strchr (p2, '\0');
669 while (isblank ((unsigned char)p[-1]))
670 --p;
671 do_define (p2, p - p2, o_file, ebuf);
672 }
673 continue;
674 }
675
676 if (word1eq ("override"))
677 {
678 if (*p2 == '\0')
679 error (fstart, _("empty `override' directive"));
680
681 if (strneq (p2, "define", 6)
682 && (isblank ((unsigned char)p2[6]) || p2[6] == '\0'))
683 {
684 if (ignoring)
685 in_ignored_define = 1;
686 else
687 {
688 p2 = next_token (p2 + 6);
689 if (*p2 == '\0')
690 fatal (fstart, _("empty variable name"));
691
692 /* Let the variable name be the whole rest of the line,
693 with trailing blanks stripped (comments have already been
694 removed), so it could be a complex variable/function
695 reference that might contain blanks. */
696 p = strchr (p2, '\0');
697 while (isblank ((unsigned char)p[-1]))
698 --p;
699 do_define (p2, p - p2, o_override, ebuf);
700 }
701 }
702 else if (!ignoring
703 && !try_variable_definition (fstart, p2, o_override, 0))
704 error (fstart, _("invalid `override' directive"));
705
706 continue;
707 }
708
709 if (ignoring)
710 /* Ignore the line. We continue here so conditionals
711 can appear in the middle of a rule. */
712 continue;
713
714 if (word1eq ("export"))
715 {
716 /* 'export' by itself causes everything to be exported. */
717 if (*p2 == '\0')
718 export_all_variables = 1;
719 else
720 {
721 struct variable *v;
722
723 v = try_variable_definition (fstart, p2, o_file, 0);
724 if (v != 0)
725 v->export = v_export;
726 else
727 {
728 unsigned int len;
729 char *ap;
730
731 /* Expand the line so we can use indirect and constructed
732 variable names in an export command. */
733 p2 = ap = allocated_variable_expand (p2);
734
735 for (p = find_next_token (&p2, &len); p != 0;
736 p = find_next_token (&p2, &len))
737 {
738 v = lookup_variable (p, len);
739 if (v == 0)
740 v = define_variable_loc (p, len, "", o_file, 0,
741 fstart);
742 v->export = v_export;
743 }
744
745 free (ap);
746 }
747 }
748 goto rule_complete;
749 }
750
751 if (word1eq ("unexport"))
752 {
753 if (*p2 == '\0')
754 export_all_variables = 0;
755 else
756 {
757 unsigned int len;
758 struct variable *v;
759 char *ap;
760
761 /* Expand the line so we can use indirect and constructed
762 variable names in an unexport command. */
763 p2 = ap = allocated_variable_expand (p2);
764
765 for (p = find_next_token (&p2, &len); p != 0;
766 p = find_next_token (&p2, &len))
767 {
768 v = lookup_variable (p, len);
769 if (v == 0)
770 v = define_variable_loc (p, len, "", o_file, 0, fstart);
771
772 v->export = v_noexport;
773 }
774
775 free (ap);
776 }
777 goto rule_complete;
778 }
779
780 skip_conditionals:
781 if (word1eq ("vpath"))
782 {
783 char *pattern;
784 unsigned int len;
785 p2 = variable_expand (p2);
786 p = find_next_token (&p2, &len);
787 if (p != 0)
788 {
789 pattern = savestring (p, len);
790 p = find_next_token (&p2, &len);
791 /* No searchpath means remove all previous
792 selective VPATH's with the same pattern. */
793 }
794 else
795 /* No pattern means remove all previous selective VPATH's. */
796 pattern = 0;
797 construct_vpath_list (pattern, p);
798 if (pattern != 0)
799 free (pattern);
800
801 goto rule_complete;
802 }
803
804 if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude"))
805 {
806 /* We have found an `include' line specifying a nested
807 makefile to be read at this point. */
808 struct conditionals *save;
809 struct conditionals new_conditionals;
810 struct nameseq *files;
811 /* "-include" (vs "include") says no error if the file does not
812 exist. "sinclude" is an alias for this from SGI. */
813 int noerror = (p[0] != 'i');
814
815 p = allocated_variable_expand (p2);
816
817 /* If no filenames, it's a no-op. */
818 if (*p == '\0')
819 {
820 free (p);
821 continue;
822 }
823
824 /* Parse the list of file names. */
825 p2 = p;
826 files = multi_glob (parse_file_seq (&p2, '\0',
827 sizeof (struct nameseq),
828 1),
829 sizeof (struct nameseq));
830 free (p);
831
832 /* Save the state of conditionals and start
833 the included makefile with a clean slate. */
834 save = install_conditionals (&new_conditionals);
835
836 /* Record the rules that are waiting so they will determine
837 the default goal before those in the included makefile. */
838 record_waiting_files ();
839
840 /* Read each included makefile. */
841 while (files != 0)
842 {
843 struct nameseq *next = files->next;
844 char *name = files->name;
845 int r;
846
847 free ((char *)files);
848 files = next;
849
850 r = eval_makefile (name, (RM_INCLUDED | RM_NO_TILDE
851 | (noerror ? RM_DONTCARE : 0)));
852 if (!r && !noerror)
853 error (fstart, "%s: %s", name, strerror (errno));
854 free (name);
855 }
856
857 /* Restore conditional state. */
858 restore_conditionals (save);
859
860 goto rule_complete;
861 }
862
863 if (try_variable_definition (fstart, p, o_file, 0))
864 /* This line has been dealt with. */
865 goto rule_complete;
866
867 /* This line starts with a tab but was not caught above because there
868 was no preceding target, and the line might have been usable as a
869 variable definition. But now we know it is definitely lossage. */
870 if (line[0] == '\t')
871 fatal(fstart, _("commands commence before first target"));
872
873 /* This line describes some target files. This is complicated by
874 the existence of target-specific variables, because we can't
875 expand the entire line until we know if we have one or not. So
876 we expand the line word by word until we find the first `:',
877 then check to see if it's a target-specific variable.
878
879 In this algorithm, `lb_next' will point to the beginning of the
880 unexpanded parts of the input buffer, while `p2' points to the
881 parts of the expanded buffer we haven't searched yet. */
882
883 {
884 enum make_word_type wtype;
885 enum variable_origin v_origin;
886 int exported;
887 char *cmdleft, *semip, *lb_next;
888 unsigned int len, plen = 0;
889 char *colonp;
890 const char *end, *beg; /* Helpers for whitespace stripping. */
891
892 /* Record the previous rule. */
893
894 record_waiting_files ();
895 tgts_started = fstart->lineno;
896
897 /* Search the line for an unquoted ; that is not after an
898 unquoted #. */
899 cmdleft = find_char_unquote (line, ';', '#', 0, 1);
900 if (cmdleft != 0 && *cmdleft == '#')
901 {
902 /* We found a comment before a semicolon. */
903 *cmdleft = '\0';
904 cmdleft = 0;
905 }
906 else if (cmdleft != 0)
907 /* Found one. Cut the line short there before expanding it. */
908 *(cmdleft++) = '\0';
909 semip = cmdleft;
910
911 collapse_continuations (line);
912
913 /* We can't expand the entire line, since if it's a per-target
914 variable we don't want to expand it. So, walk from the
915 beginning, expanding as we go, and looking for "interesting"
916 chars. The first word is always expandable. */
917 wtype = get_next_mword(line, NULL, &lb_next, &len);
918 switch (wtype)
919 {
920 case w_eol:
921 if (cmdleft != 0)
922 fatal(fstart, _("missing rule before commands"));
923 /* This line contained something but turned out to be nothing
924 but whitespace (a comment?). */
925 continue;
926
927 case w_colon:
928 case w_dcolon:
929 /* We accept and ignore rules without targets for
930 compatibility with SunOS 4 make. */
931 no_targets = 1;
932 continue;
933
934 default:
935 break;
936 }
937
938 p2 = variable_expand_string(NULL, lb_next, len);
939
940 while (1)
941 {
942 lb_next += len;
943 if (cmdleft == 0)
944 {
945 /* Look for a semicolon in the expanded line. */
946 cmdleft = find_char_unquote (p2, ';', 0, 0, 0);
947
948 if (cmdleft != 0)
949 {
950 unsigned long p2_off = p2 - variable_buffer;
951 unsigned long cmd_off = cmdleft - variable_buffer;
952 char *pend = p2 + strlen(p2);
953
954 /* Append any remnants of lb, then cut the line short
955 at the semicolon. */
956 *cmdleft = '\0';
957
958 /* One school of thought says that you shouldn't expand
959 here, but merely copy, since now you're beyond a ";"
960 and into a command script. However, the old parser
961 expanded the whole line, so we continue that for
962 backwards-compatiblity. Also, it wouldn't be
963 entirely consistent, since we do an unconditional
964 expand below once we know we don't have a
965 target-specific variable. */
966 (void)variable_expand_string(pend, lb_next, (long)-1);
967 lb_next += strlen(lb_next);
968 p2 = variable_buffer + p2_off;
969 cmdleft = variable_buffer + cmd_off + 1;
970 }
971 }
972
973 colonp = find_char_unquote(p2, ':', 0, 0, 0);
974#ifdef HAVE_DOS_PATHS
975 /* The drive spec brain-damage strikes again... */
976 /* Note that the only separators of targets in this context
977 are whitespace and a left paren. If others are possible,
978 they should be added to the string in the call to index. */
979 while (colonp && (colonp[1] == '/' || colonp[1] == '\\') &&
980 colonp > p2 && isalpha ((unsigned char)colonp[-1]) &&
981 (colonp == p2 + 1 || strchr (" \t(", colonp[-2]) != 0))
982 colonp = find_char_unquote(colonp + 1, ':', 0, 0, 0);
983#endif
984 if (colonp != 0)
985 break;
986
987 wtype = get_next_mword(lb_next, NULL, &lb_next, &len);
988 if (wtype == w_eol)
989 break;
990
991 p2 += strlen(p2);
992 *(p2++) = ' ';
993 p2 = variable_expand_string(p2, lb_next, len);
994 /* We don't need to worry about cmdleft here, because if it was
995 found in the variable_buffer the entire buffer has already
996 been expanded... we'll never get here. */
997 }
998
999 p2 = next_token (variable_buffer);
1000
1001 /* If the word we're looking at is EOL, see if there's _anything_
1002 on the line. If not, a variable expanded to nothing, so ignore
1003 it. If so, we can't parse this line so punt. */
1004 if (wtype == w_eol)
1005 {
1006 if (*p2 != '\0')
1007 /* There's no need to be ivory-tower about this: check for
1008 one of the most common bugs found in makefiles... */
1009 fatal (fstart, _("missing separator%s"),
1010 !strneq(line, " ", 8) ? ""
1011 : _(" (did you mean TAB instead of 8 spaces?)"));
1012 continue;
1013 }
1014
1015 /* Make the colon the end-of-string so we know where to stop
1016 looking for targets. */
1017 *colonp = '\0';
1018 filenames = multi_glob (parse_file_seq (&p2, '\0',
1019 sizeof (struct nameseq),
1020 1),
1021 sizeof (struct nameseq));
1022 *p2 = ':';
1023
1024 if (!filenames)
1025 {
1026 /* We accept and ignore rules without targets for
1027 compatibility with SunOS 4 make. */
1028 no_targets = 1;
1029 continue;
1030 }
1031 /* This should never be possible; we handled it above. */
1032 assert (*p2 != '\0');
1033 ++p2;
1034
1035 /* Is this a one-colon or two-colon entry? */
1036 two_colon = *p2 == ':';
1037 if (two_colon)
1038 p2++;
1039
1040 /* Test to see if it's a target-specific variable. Copy the rest
1041 of the buffer over, possibly temporarily (we'll expand it later
1042 if it's not a target-specific variable). PLEN saves the length
1043 of the unparsed section of p2, for later. */
1044 if (*lb_next != '\0')
1045 {
1046 unsigned int l = p2 - variable_buffer;
1047 plen = strlen (p2);
1048 (void) variable_buffer_output (p2+plen,
1049 lb_next, strlen (lb_next)+1);
1050 p2 = variable_buffer + l;
1051 }
1052
1053 /* See if it's an "override" or "export" keyword; if so see if what
1054 comes after it looks like a variable definition. */
1055
1056 wtype = get_next_mword (p2, NULL, &p, &len);
1057
1058 v_origin = o_file;
1059 exported = 0;
1060 if (wtype == w_static)
1061 {
1062 if (word1eq ("override"))
1063 {
1064 v_origin = o_override;
1065 wtype = get_next_mword (p+len, NULL, &p, &len);
1066 }
1067 else if (word1eq ("export"))
1068 {
1069 exported = 1;
1070 wtype = get_next_mword (p+len, NULL, &p, &len);
1071 }
1072 }
1073
1074 if (wtype != w_eol)
1075 wtype = get_next_mword (p+len, NULL, NULL, NULL);
1076
1077 if (wtype == w_varassign)
1078 {
1079 /* If there was a semicolon found, add it back, plus anything
1080 after it. */
1081 if (semip)
1082 {
1083 unsigned int l = p - variable_buffer;
1084 *(--semip) = ';';
1085 variable_buffer_output (p2 + strlen (p2),
1086 semip, strlen (semip)+1);
1087 p = variable_buffer + l;
1088 }
1089 record_target_var (filenames, p, v_origin, exported, fstart);
1090 filenames = 0;
1091 continue;
1092 }
1093
1094 /* This is a normal target, _not_ a target-specific variable.
1095 Unquote any = in the dependency list. */
1096 find_char_unquote (lb_next, '=', 0, 0, 0);
1097
1098 /* We have some targets, so don't ignore the following commands. */
1099 no_targets = 0;
1100
1101 /* Expand the dependencies, etc. */
1102 if (*lb_next != '\0')
1103 {
1104 unsigned int l = p2 - variable_buffer;
1105 (void) variable_expand_string (p2 + plen, lb_next, (long)-1);
1106 p2 = variable_buffer + l;
1107
1108 /* Look for a semicolon in the expanded line. */
1109 if (cmdleft == 0)
1110 {
1111 cmdleft = find_char_unquote (p2, ';', 0, 0, 0);
1112 if (cmdleft != 0)
1113 *(cmdleft++) = '\0';
1114 }
1115 }
1116
1117 /* Is this a static pattern rule: `target: %targ: %dep; ...'? */
1118 p = strchr (p2, ':');
1119 while (p != 0 && p[-1] == '\\')
1120 {
1121 register char *q = &p[-1];
1122 register int backslash = 0;
1123 while (*q-- == '\\')
1124 backslash = !backslash;
1125 if (backslash)
1126 p = strchr (p + 1, ':');
1127 else
1128 break;
1129 }
1130#ifdef _AMIGA
1131 /* Here, the situation is quite complicated. Let's have a look
1132 at a couple of targets:
1133
1134 install: dev:make
1135
1136 dev:make: make
1137
1138 dev:make:: xyz
1139
1140 The rule is that it's only a target, if there are TWO :'s
1141 OR a space around the :.
1142 */
1143 if (p && !(isspace ((unsigned char)p[1]) || !p[1]
1144 || isspace ((unsigned char)p[-1])))
1145 p = 0;
1146#endif
1147#ifdef HAVE_DOS_PATHS
1148 {
1149 int check_again;
1150
1151 do {
1152 check_again = 0;
1153 /* For DOS-style paths, skip a "C:\..." or a "C:/..." */
1154 if (p != 0 && (p[1] == '\\' || p[1] == '/') &&
1155 isalpha ((unsigned char)p[-1]) &&
1156 (p == p2 + 1 || strchr (" \t:(", p[-2]) != 0)) {
1157 p = strchr (p + 1, ':');
1158 check_again = 1;
1159 }
1160 } while (check_again);
1161 }
1162#endif
1163 if (p != 0)
1164 {
1165 struct nameseq *target;
1166 target = parse_file_seq (&p2, ':', sizeof (struct nameseq), 1);
1167 ++p2;
1168 if (target == 0)
1169 fatal (fstart, _("missing target pattern"));
1170 else if (target->next != 0)
1171 fatal (fstart, _("multiple target patterns (target `%s')"), target->name); /* bird */
1172 pattern = target->name;
1173 pattern_percent = find_percent (pattern);
1174 if (pattern_percent == 0)
1175 fatal (fstart, _("target pattern contains no `%%' (target `%s')"), target->name); /* bird */
1176 free ((char *)target);
1177 }
1178 else
1179 pattern = 0;
1180
1181 /* Strip leading and trailing whitespaces. */
1182 beg = p2;
1183 end = beg + strlen (beg) - 1;
1184 strip_whitespace (&beg, &end);
1185
1186 if (beg <= end && *beg != '\0')
1187 {
1188 /* Put all the prerequisites here; they'll be parsed later. */
1189 deps = alloc_dep ();
1190 deps->name = savestring (beg, end - beg + 1);
1191 }
1192 else
1193 deps = 0;
1194
1195 commands_idx = 0;
1196 if (cmdleft != 0)
1197 {
1198 /* Semicolon means rest of line is a command. */
1199 unsigned int len = strlen (cmdleft);
1200
1201 cmds_started = fstart->lineno;
1202
1203 /* Add this command line to the buffer. */
1204 if (len + 2 > commands_len)
1205 {
1206 commands_len = (len + 2) * 2;
1207 commands = (char *) xrealloc (commands, commands_len);
1208 }
1209 bcopy (cmdleft, commands, len);
1210 commands_idx += len;
1211 commands[commands_idx++] = '\n';
1212 }
1213
1214 /* Determine if this target should be made default. We used to do
1215 this in record_files() but because of the delayed target recording
1216 and because preprocessor directives are legal in target's commands
1217 it is too late. Consider this fragment for example:
1218
1219 foo:
1220
1221 ifeq ($(.DEFAULT_GOAL),foo)
1222 ...
1223 endif
1224
1225 Because the target is not recorded until after ifeq directive is
1226 evaluated the .DEFAULT_GOAL does not contain foo yet as one
1227 would expect. Because of this we have to move some of the logic
1228 here. */
1229
1230 if (**default_goal_name == '\0' && set_default)
1231 {
1232 char* name;
1233 struct dep *d;
1234 struct nameseq *t = filenames;
1235
1236 for (; t != 0; t = t->next)
1237 {
1238 int reject = 0;
1239 name = t->name;
1240
1241 /* We have nothing to do if this is an implicit rule. */
1242 if (strchr (name, '%') != 0)
1243 break;
1244
1245 /* See if this target's name does not start with a `.',
1246 unless it contains a slash. */
1247 if (*name == '.' && strchr (name, '/') == 0
1248#ifdef HAVE_DOS_PATHS
1249 && strchr (name, '\\') == 0
1250#endif
1251 )
1252 continue;
1253
1254
1255 /* If this file is a suffix, don't let it be
1256 the default goal file. */
1257 for (d = suffix_file->deps; d != 0; d = d->next)
1258 {
1259 register struct dep *d2;
1260 if (*dep_name (d) != '.' && streq (name, dep_name (d)))
1261 {
1262 reject = 1;
1263 break;
1264 }
1265 for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
1266 {
1267 register unsigned int len = strlen (dep_name (d2));
1268 if (!strneq (name, dep_name (d2), len))
1269 continue;
1270 if (streq (name + len, dep_name (d)))
1271 {
1272 reject = 1;
1273 break;
1274 }
1275 }
1276
1277 if (reject)
1278 break;
1279 }
1280
1281 if (!reject)
1282 {
1283 define_variable_global (".DEFAULT_GOAL", 13, t->name,
1284 o_file, 0, NILF);
1285 break;
1286 }
1287 }
1288 }
1289
1290 continue;
1291 }
1292
1293 /* We get here except in the case that we just read a rule line.
1294 Record now the last rule we read, so following spurious
1295 commands are properly diagnosed. */
1296 rule_complete:
1297 record_waiting_files ();
1298 }
1299
1300#undef word1eq
1301
1302 if (conditionals->if_cmds)
1303 fatal (fstart, _("missing `endif'"));
1304
1305 /* At eof, record the last rule. */
1306 record_waiting_files ();
1307
1308 if (collapsed)
1309 free ((char *) collapsed);
1310 free ((char *) commands);
1311
1312 return 1;
1313}
1314
1315
1316
1317/* Remove comments from LINE.
1318 This is done by copying the text at LINE onto itself. */
1319
1320static void
1321remove_comments (char *line)
1322{
1323 char *comment;
1324
1325 comment = find_char_unquote (line, '#', 0, 0, 0);
1326
1327 if (comment != 0)
1328 /* Cut off the line at the #. */
1329 *comment = '\0';
1330}
1331
1332/* Execute a `define' directive.
1333 The first line has already been read, and NAME is the name of
1334 the variable to be defined. The following lines remain to be read. */
1335
1336static void
1337do_define (char *name, unsigned int namelen,
1338 enum variable_origin origin, struct ebuffer *ebuf)
1339{
1340 struct floc defstart;
1341 long nlines = 0;
1342 int nlevels = 1;
1343 unsigned int length = 100;
1344 char *definition = (char *) xmalloc (length);
1345 unsigned int idx = 0;
1346 char *p;
1347
1348 /* Expand the variable name. */
1349 char *var = (char *) alloca (namelen + 1);
1350 bcopy (name, var, namelen);
1351 var[namelen] = '\0';
1352 var = variable_expand (var);
1353
1354 defstart = ebuf->floc;
1355
1356 while (1)
1357 {
1358 unsigned int len;
1359 char *line;
1360
1361 nlines = readline (ebuf);
1362 ebuf->floc.lineno += nlines;
1363
1364 /* If there is nothing left to eval, we're done. */
1365 if (nlines < 0)
1366 break;
1367
1368 line = ebuf->buffer;
1369
1370 collapse_continuations (line);
1371
1372 /* If the line doesn't begin with a tab, test to see if it introduces
1373 another define, or ends one. */
1374
1375 /* Stop if we find an 'endef' */
1376 if (line[0] != '\t')
1377 {
1378 p = next_token (line);
1379 len = strlen (p);
1380
1381 /* If this is another 'define', increment the level count. */
1382 if ((len == 6 || (len > 6 && isblank ((unsigned char)p[6])))
1383 && strneq (p, "define", 6))
1384 ++nlevels;
1385
1386 /* If this is an 'endef', decrement the count. If it's now 0,
1387 we've found the last one. */
1388 else if ((len == 5 || (len > 5 && isblank ((unsigned char)p[5])))
1389 && strneq (p, "endef", 5))
1390 {
1391 p += 5;
1392 remove_comments (p);
1393 if (*next_token (p) != '\0')
1394 error (&ebuf->floc,
1395 _("Extraneous text after `endef' directive"));
1396
1397 if (--nlevels == 0)
1398 {
1399 /* Define the variable. */
1400 if (idx == 0)
1401 definition[0] = '\0';
1402 else
1403 definition[idx - 1] = '\0';
1404
1405 /* Always define these variables in the global set. */
1406 define_variable_global (var, strlen (var), definition,
1407 origin, 1, &defstart);
1408 free (definition);
1409 return;
1410 }
1411 }
1412 }
1413
1414 /* Otherwise add this line to the variable definition. */
1415 len = strlen (line);
1416 if (idx + len + 1 > length)
1417 {
1418 length = (idx + len) * 2;
1419 definition = (char *) xrealloc (definition, length + 1);
1420 }
1421
1422 bcopy (line, &definition[idx], len);
1423 idx += len;
1424 /* Separate lines with a newline. */
1425 definition[idx++] = '\n';
1426 }
1427
1428 /* No `endef'!! */
1429 fatal (&defstart, _("missing `endef', unterminated `define'"));
1430
1431 /* NOTREACHED */
1432 return;
1433}
1434
1435
1436/* Interpret conditional commands "ifdef", "ifndef", "ifeq",
1437 "ifneq", "else" and "endif".
1438 LINE is the input line, with the command as its first word.
1439
1440 FILENAME and LINENO are the filename and line number in the
1441 current makefile. They are used for error messages.
1442
1443 Value is -2 if the line is not a conditional at all,
1444 -1 if the line is an invalid conditional,
1445 0 if following text should be interpreted,
1446 1 if following text should be ignored. */
1447
1448static int
1449conditional_line (char *line, int len, const struct floc *flocp)
1450{
1451 char *cmdname;
1452 enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq, c_else, c_endif } cmdtype;
1453 unsigned int i;
1454 unsigned int o;
1455
1456 /* Compare a word, both length and contents. */
1457#define word1eq(s) (len == sizeof(s)-1 && strneq (s, line, sizeof(s)-1))
1458#define chkword(s, t) if (word1eq (s)) { cmdtype = (t); cmdname = (s); }
1459
1460 /* Make sure this line is a conditional. */
1461 chkword ("ifdef", c_ifdef)
1462 else chkword ("ifndef", c_ifndef)
1463 else chkword ("ifeq", c_ifeq)
1464 else chkword ("ifneq", c_ifneq)
1465 else chkword ("else", c_else)
1466 else chkword ("endif", c_endif)
1467 else
1468 return -2;
1469
1470 /* Found one: skip past it and any whitespace after it. */
1471 line = next_token (line + len);
1472
1473#define EXTRANEOUS() error (flocp, _("Extraneous text after `%s' directive"), cmdname)
1474
1475 /* An 'endif' cannot contain extra text, and reduces the if-depth by 1 */
1476 if (cmdtype == c_endif)
1477 {
1478 if (*line != '\0')
1479 EXTRANEOUS ();
1480
1481 if (!conditionals->if_cmds)
1482 fatal (flocp, _("extraneous `%s'"), cmdname);
1483
1484 --conditionals->if_cmds;
1485
1486 goto DONE;
1487 }
1488
1489 /* An 'else' statement can either be simple, or it can have another
1490 conditional after it. */
1491 if (cmdtype == c_else)
1492 {
1493 const char *p;
1494
1495 if (!conditionals->if_cmds)
1496 fatal (flocp, _("extraneous `%s'"), cmdname);
1497
1498 o = conditionals->if_cmds - 1;
1499
1500 if (conditionals->seen_else[o])
1501 fatal (flocp, _("only one `else' per conditional"));
1502
1503 /* Change the state of ignorance. */
1504 switch (conditionals->ignoring[o])
1505 {
1506 case 0:
1507 /* We've just been interpreting. Never do it again. */
1508 conditionals->ignoring[o] = 2;
1509 break;
1510 case 1:
1511 /* We've never interpreted yet. Maybe this time! */
1512 conditionals->ignoring[o] = 0;
1513 break;
1514 }
1515
1516 /* It's a simple 'else'. */
1517 if (*line == '\0')
1518 {
1519 conditionals->seen_else[o] = 1;
1520 goto DONE;
1521 }
1522
1523 /* The 'else' has extra text. That text must be another conditional
1524 and cannot be an 'else' or 'endif'. */
1525
1526 /* Find the length of the next word. */
1527 for (p = line+1; *p != '\0' && !isspace ((unsigned char)*p); ++p)
1528 ;
1529 len = p - line;
1530
1531 /* If it's 'else' or 'endif' or an illegal conditional, fail. */
1532 if (word1eq("else") || word1eq("endif")
1533 || conditional_line (line, len, flocp) < 0)
1534 EXTRANEOUS ();
1535 else
1536 {
1537 /* conditional_line() created a new level of conditional.
1538 Raise it back to this level. */
1539 if (conditionals->ignoring[o] < 2)
1540 conditionals->ignoring[o] = conditionals->ignoring[o+1];
1541 --conditionals->if_cmds;
1542 }
1543
1544 goto DONE;
1545 }
1546
1547 if (conditionals->allocated == 0)
1548 {
1549 conditionals->allocated = 5;
1550 conditionals->ignoring = (char *) xmalloc (conditionals->allocated);
1551 conditionals->seen_else = (char *) xmalloc (conditionals->allocated);
1552 }
1553
1554 o = conditionals->if_cmds++;
1555 if (conditionals->if_cmds > conditionals->allocated)
1556 {
1557 conditionals->allocated += 5;
1558 conditionals->ignoring = (char *)
1559 xrealloc (conditionals->ignoring, conditionals->allocated);
1560 conditionals->seen_else = (char *)
1561 xrealloc (conditionals->seen_else, conditionals->allocated);
1562 }
1563
1564 /* Record that we have seen an `if...' but no `else' so far. */
1565 conditionals->seen_else[o] = 0;
1566
1567 /* Search through the stack to see if we're already ignoring. */
1568 for (i = 0; i < o; ++i)
1569 if (conditionals->ignoring[i])
1570 {
1571 /* We are already ignoring, so just push a level to match the next
1572 "else" or "endif", and keep ignoring. We don't want to expand
1573 variables in the condition. */
1574 conditionals->ignoring[o] = 1;
1575 return 1;
1576 }
1577
1578 if (cmdtype == c_ifdef || cmdtype == c_ifndef)
1579 {
1580 char *var;
1581 struct variable *v;
1582 char *p;
1583
1584 /* Expand the thing we're looking up, so we can use indirect and
1585 constructed variable names. */
1586 var = allocated_variable_expand (line);
1587
1588 /* Make sure there's only one variable name to test. */
1589 p = end_of_token (var);
1590 i = p - var;
1591 p = next_token (p);
1592 if (*p != '\0')
1593 return -1;
1594
1595 var[i] = '\0';
1596 v = lookup_variable (var, i);
1597
1598 conditionals->ignoring[o] =
1599 ((v != 0 && *v->value != '\0') == (cmdtype == c_ifndef));
1600
1601 free (var);
1602 }
1603 else
1604 {
1605 /* "Ifeq" or "ifneq". */
1606 char *s1, *s2;
1607 unsigned int len;
1608 char termin = *line == '(' ? ',' : *line;
1609
1610 if (termin != ',' && termin != '"' && termin != '\'')
1611 return -1;
1612
1613 s1 = ++line;
1614 /* Find the end of the first string. */
1615 if (termin == ',')
1616 {
1617 int count = 0;
1618 for (; *line != '\0'; ++line)
1619 if (*line == '(')
1620 ++count;
1621 else if (*line == ')')
1622 --count;
1623 else if (*line == ',' && count <= 0)
1624 break;
1625 }
1626 else
1627 while (*line != '\0' && *line != termin)
1628 ++line;
1629
1630 if (*line == '\0')
1631 return -1;
1632
1633 if (termin == ',')
1634 {
1635 /* Strip blanks after the first string. */
1636 char *p = line++;
1637 while (isblank ((unsigned char)p[-1]))
1638 --p;
1639 *p = '\0';
1640 }
1641 else
1642 *line++ = '\0';
1643
1644 s2 = variable_expand (s1);
1645 /* We must allocate a new copy of the expanded string because
1646 variable_expand re-uses the same buffer. */
1647 len = strlen (s2);
1648 s1 = (char *) alloca (len + 1);
1649 bcopy (s2, s1, len + 1);
1650
1651 if (termin != ',')
1652 /* Find the start of the second string. */
1653 line = next_token (line);
1654
1655 termin = termin == ',' ? ')' : *line;
1656 if (termin != ')' && termin != '"' && termin != '\'')
1657 return -1;
1658
1659 /* Find the end of the second string. */
1660 if (termin == ')')
1661 {
1662 register int count = 0;
1663 s2 = next_token (line);
1664 for (line = s2; *line != '\0'; ++line)
1665 {
1666 if (*line == '(')
1667 ++count;
1668 else if (*line == ')')
1669 {
1670 if (count <= 0)
1671 break;
1672 else
1673 --count;
1674 }
1675 }
1676 }
1677 else
1678 {
1679 ++line;
1680 s2 = line;
1681 while (*line != '\0' && *line != termin)
1682 ++line;
1683 }
1684
1685 if (*line == '\0')
1686 return -1;
1687
1688 *line = '\0';
1689 line = next_token (++line);
1690 if (*line != '\0')
1691 EXTRANEOUS ();
1692
1693 s2 = variable_expand (s2);
1694 conditionals->ignoring[o] = (streq (s1, s2) == (cmdtype == c_ifneq));
1695 }
1696
1697 DONE:
1698 /* Search through the stack to see if we're ignoring. */
1699 for (i = 0; i < conditionals->if_cmds; ++i)
1700 if (conditionals->ignoring[i])
1701 return 1;
1702 return 0;
1703}
1704
1705
1706/* Remove duplicate dependencies in CHAIN. */
1707
1708static unsigned long
1709dep_hash_1 (const void *key)
1710{
1711 return_STRING_HASH_1 (dep_name ((struct dep const *) key));
1712}
1713
1714static unsigned long
1715dep_hash_2 (const void *key)
1716{
1717 return_STRING_HASH_2 (dep_name ((struct dep const *) key));
1718}
1719
1720static int
1721dep_hash_cmp (const void *x, const void *y)
1722{
1723 struct dep *dx = (struct dep *) x;
1724 struct dep *dy = (struct dep *) y;
1725 int cmp = strcmp (dep_name (dx), dep_name (dy));
1726
1727 /* If the names are the same but ignore_mtimes are not equal, one of these
1728 is an order-only prerequisite and one isn't. That means that we should
1729 remove the one that isn't and keep the one that is. */
1730
1731 if (!cmp && dx->ignore_mtime != dy->ignore_mtime)
1732 dx->ignore_mtime = dy->ignore_mtime = 0;
1733
1734 return cmp;
1735}
1736
1737
1738void
1739uniquize_deps (struct dep *chain)
1740{
1741 struct hash_table deps;
1742 register struct dep **depp;
1743
1744 hash_init (&deps, 500, dep_hash_1, dep_hash_2, dep_hash_cmp);
1745
1746 /* Make sure that no dependencies are repeated. This does not
1747 really matter for the purpose of updating targets, but it
1748 might make some names be listed twice for $^ and $?. */
1749
1750 depp = &chain;
1751 while (*depp)
1752 {
1753 struct dep *dep = *depp;
1754 struct dep **dep_slot = (struct dep **) hash_find_slot (&deps, dep);
1755 if (HASH_VACANT (*dep_slot))
1756 {
1757 hash_insert_at (&deps, dep, dep_slot);
1758 depp = &dep->next;
1759 }
1760 else
1761 {
1762 /* Don't bother freeing duplicates.
1763 It's dangerous and little benefit accrues. */
1764 *depp = dep->next;
1765 }
1766 }
1767
1768 hash_free (&deps, 0);
1769}
1770
1771
1772/* Record target-specific variable values for files FILENAMES.
1773 TWO_COLON is nonzero if a double colon was used.
1774
1775 The links of FILENAMES are freed, and so are any names in it
1776 that are not incorporated into other data structures.
1777
1778 If the target is a pattern, add the variable to the pattern-specific
1779 variable value list. */
1780
1781static void
1782record_target_var (struct nameseq *filenames, char *defn,
1783 enum variable_origin origin, int exported,
1784 const struct floc *flocp)
1785{
1786 struct nameseq *nextf;
1787 struct variable_set_list *global;
1788
1789 global = current_variable_set_list;
1790
1791 /* If the variable is an append version, store that but treat it as a
1792 normal recursive variable. */
1793
1794 for (; filenames != 0; filenames = nextf)
1795 {
1796 struct variable *v;
1797 register char *name = filenames->name;
1798 char *fname;
1799 char *percent;
1800 struct pattern_var *p;
1801
1802 nextf = filenames->next;
1803 free ((char *) filenames);
1804
1805 /* If it's a pattern target, then add it to the pattern-specific
1806 variable list. */
1807 percent = find_percent (name);
1808 if (percent)
1809 {
1810 /* Get a reference for this pattern-specific variable struct. */
1811 p = create_pattern_var (name, percent);
1812 p->variable.fileinfo = *flocp;
1813 /* I don't think this can fail since we already determined it was a
1814 variable definition. */
1815 v = parse_variable_definition (&p->variable, defn);
1816 assert (v != 0);
1817
1818 if (v->flavor == f_simple)
1819 v->value = allocated_variable_expand (v->value);
1820 else
1821 v->value = xstrdup (v->value);
1822
1823 fname = p->target;
1824 }
1825 else
1826 {
1827 struct file *f;
1828
1829 /* Get a file reference for this file, and initialize it.
1830 We don't want to just call enter_file() because that allocates a
1831 new entry if the file is a double-colon, which we don't want in
1832 this situation. */
1833 f = lookup_file (name);
1834 if (!f)
1835 f = enter_file (name);
1836 else if (f->double_colon)
1837 f = f->double_colon;
1838
1839 initialize_file_variables (f, 1);
1840 fname = f->name;
1841
1842 current_variable_set_list = f->variables;
1843 v = try_variable_definition (flocp, defn, origin, 1);
1844 if (!v)
1845 error (flocp, _("Malformed target-specific variable definition"));
1846 current_variable_set_list = global;
1847 }
1848
1849 /* Set up the variable to be *-specific. */
1850 v->origin = origin;
1851 v->per_target = 1;
1852 v->export = exported ? v_export : v_default;
1853
1854 /* If it's not an override, check to see if there was a command-line
1855 setting. If so, reset the value. */
1856 if (origin != o_override)
1857 {
1858 struct variable *gv;
1859 int len = strlen(v->name);
1860
1861 gv = lookup_variable (v->name, len);
1862 if (gv && (gv->origin == o_env_override || gv->origin == o_command))
1863 {
1864 if (v->value != 0)
1865 free (v->value);
1866 v->value = xstrdup (gv->value);
1867 v->origin = gv->origin;
1868 v->recursive = gv->recursive;
1869 v->append = 0;
1870 }
1871 }
1872
1873 /* Free name if not needed further. */
1874 if (name != fname && (name < fname || name > fname + strlen (fname)))
1875 free (name);
1876 }
1877}
1878
1879
1880/* Record a description line for files FILENAMES,
1881 with dependencies DEPS, commands to execute described
1882 by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED.
1883 TWO_COLON is nonzero if a double colon was used.
1884 If not nil, PATTERN is the `%' pattern to make this
1885 a static pattern rule, and PATTERN_PERCENT is a pointer
1886 to the `%' within it.
1887
1888 The links of FILENAMES are freed, and so are any names in it
1889 that are not incorporated into other data structures. */
1890
1891static void
1892record_files (struct nameseq *filenames, char *pattern, char *pattern_percent,
1893 struct dep *deps, unsigned int cmds_started, char *commands,
1894 unsigned int commands_idx, int two_colon,
1895 const struct floc *flocp)
1896{
1897 struct nameseq *nextf;
1898 int implicit = 0;
1899 unsigned int max_targets = 0, target_idx = 0;
1900 char **targets = 0, **target_percents = 0;
1901 struct commands *cmds;
1902
1903 /* If we've already snapped deps, that means we're in an eval being
1904 resolved after the makefiles have been read in. We can't add more rules
1905 at this time, since they won't get snapped and we'll get core dumps.
1906 See Savannah bug # 12124. */
1907 if (snapped_deps)
1908 fatal (flocp, _("prerequisites cannot be defined in command scripts"));
1909
1910 if (commands_idx > 0)
1911 {
1912 cmds = (struct commands *) xmalloc (sizeof (struct commands));
1913 cmds->fileinfo.filenm = flocp->filenm;
1914 cmds->fileinfo.lineno = cmds_started;
1915 cmds->commands = savestring (commands, commands_idx);
1916 cmds->command_lines = 0;
1917 }
1918 else
1919 cmds = 0;
1920
1921 for (; filenames != 0; filenames = nextf)
1922 {
1923 char *name = filenames->name;
1924 struct file *f;
1925 struct dep *this = 0;
1926 char *implicit_percent;
1927
1928 nextf = filenames->next;
1929 free (filenames);
1930
1931 /* Check for special targets. Do it here instead of, say, snap_deps()
1932 so that we can immediately use the value. */
1933
1934 if (streq (name, ".POSIX"))
1935 posix_pedantic = 1;
1936 else if (streq (name, ".SECONDEXPANSION"))
1937 second_expansion = 1;
1938
1939 implicit_percent = find_percent (name);
1940 implicit |= implicit_percent != 0;
1941
1942 if (implicit && pattern != 0)
1943 fatal (flocp, _("mixed implicit and static pattern rules"));
1944
1945 if (implicit && implicit_percent == 0)
1946 fatal (flocp, _("mixed implicit and normal rules"));
1947
1948 if (implicit)
1949 {
1950 if (targets == 0)
1951 {
1952 max_targets = 5;
1953 targets = (char **) xmalloc (5 * sizeof (char *));
1954 target_percents = (char **) xmalloc (5 * sizeof (char *));
1955 target_idx = 0;
1956 }
1957 else if (target_idx == max_targets - 1)
1958 {
1959 max_targets += 5;
1960 targets = (char **) xrealloc ((char *) targets,
1961 max_targets * sizeof (char *));
1962 target_percents
1963 = (char **) xrealloc ((char *) target_percents,
1964 max_targets * sizeof (char *));
1965 }
1966 targets[target_idx] = name;
1967 target_percents[target_idx] = implicit_percent;
1968 ++target_idx;
1969 continue;
1970 }
1971
1972 /* If this is a static pattern rule:
1973 `targets: target%pattern: dep%pattern; cmds',
1974 make sure the pattern matches this target name. */
1975 if (pattern && !pattern_matches (pattern, pattern_percent, name))
1976 error (flocp, _("target `%s' doesn't match the target pattern"), name);
1977 else if (deps)
1978 {
1979 /* If there are multiple filenames, copy the chain DEPS for all but
1980 the last one. It is not safe for the same deps to go in more
1981 than one place in the database. */
1982 this = nextf != 0 ? copy_dep_chain (deps) : deps;
1983 this->need_2nd_expansion = (second_expansion
1984 && strchr (this->name, '$'));
1985 }
1986
1987 if (!two_colon)
1988 {
1989 /* Single-colon. Combine these dependencies
1990 with others in file's existing record, if any. */
1991 f = enter_file (name);
1992
1993 if (f->double_colon)
1994 fatal (flocp,
1995 _("target file `%s' has both : and :: entries"), f->name);
1996
1997 /* If CMDS == F->CMDS, this target was listed in this rule
1998 more than once. Just give a warning since this is harmless. */
1999 if (cmds != 0 && cmds == f->cmds)
2000 error (flocp,
2001 _("target `%s' given more than once in the same rule."),
2002 f->name);
2003
2004 /* Check for two single-colon entries both with commands.
2005 Check is_target so that we don't lose on files such as .c.o
2006 whose commands were preinitialized. */
2007 else if (cmds != 0 && f->cmds != 0 && f->is_target)
2008 {
2009 error (&cmds->fileinfo,
2010 _("warning: overriding commands for target `%s'"),
2011 f->name);
2012 error (&f->cmds->fileinfo,
2013 _("warning: ignoring old commands for target `%s'"),
2014 f->name);
2015 }
2016
2017 f->is_target = 1;
2018
2019 /* Defining .DEFAULT with no deps or cmds clears it. */
2020 if (f == default_file && this == 0 && cmds == 0)
2021 f->cmds = 0;
2022 if (cmds != 0)
2023 f->cmds = cmds;
2024
2025 /* Defining .SUFFIXES with no dependencies clears out the list of
2026 suffixes. */
2027 if (f == suffix_file && this == 0)
2028 {
2029 free_dep_chain (f->deps);
2030 f->deps = 0;
2031 }
2032 else if (this != 0)
2033 {
2034 /* Add the file's old deps and the new ones in THIS together. */
2035
2036 if (f->deps != 0)
2037 {
2038 struct dep **d_ptr = &f->deps;
2039
2040 while ((*d_ptr)->next != 0)
2041 d_ptr = &(*d_ptr)->next;
2042
2043 if (cmds != 0)
2044 /* This is the rule with commands, so put its deps
2045 last. The rationale behind this is that $< expands to
2046 the first dep in the chain, and commands use $<
2047 expecting to get the dep that rule specifies. However
2048 the second expansion algorithm reverses the order thus
2049 we need to make it last here. */
2050 (*d_ptr)->next = this;
2051 else
2052 {
2053 /* This is the rule without commands. Put its
2054 dependencies at the end but before dependencies from
2055 the rule with commands (if any). This way everything
2056 appears in makefile order. */
2057
2058 if (f->cmds != 0)
2059 {
2060 this->next = *d_ptr;
2061 *d_ptr = this;
2062 }
2063 else
2064 (*d_ptr)->next = this;
2065 }
2066 }
2067 else
2068 f->deps = this;
2069
2070 /* This is a hack. I need a way to communicate to snap_deps()
2071 that the last dependency line in this file came with commands
2072 (so that logic in snap_deps() can put it in front and all
2073 this $< -logic works). I cannot simply rely on file->cmds
2074 being not 0 because of the cases like the following:
2075
2076 foo: bar
2077 foo:
2078 ...
2079
2080 I am going to temporarily "borrow" UPDATING member in
2081 `struct file' for this. */
2082
2083 if (cmds != 0)
2084 f->updating = 1;
2085 }
2086 }
2087 else
2088 {
2089 /* Double-colon. Make a new record even if there already is one. */
2090 f = lookup_file (name);
2091
2092 /* Check for both : and :: rules. Check is_target so
2093 we don't lose on default suffix rules or makefiles. */
2094 if (f != 0 && f->is_target && !f->double_colon)
2095 fatal (flocp,
2096 _("target file `%s' has both : and :: entries"), f->name);
2097 f = enter_file (name);
2098 /* If there was an existing entry and it was a double-colon entry,
2099 enter_file will have returned a new one, making it the prev
2100 pointer of the old one, and setting its double_colon pointer to
2101 the first one. */
2102 if (f->double_colon == 0)
2103 /* This is the first entry for this name, so we must set its
2104 double_colon pointer to itself. */
2105 f->double_colon = f;
2106 f->is_target = 1;
2107 f->deps = this;
2108 f->cmds = cmds;
2109 }
2110
2111 /* If this is a static pattern rule, set the stem to the part of its
2112 name that matched the `%' in the pattern, so you can use $* in the
2113 commands. */
2114 if (pattern)
2115 {
2116 static char *percent = "%";
2117 char *buffer = variable_expand ("");
2118 char *o = patsubst_expand (buffer, name, pattern, percent,
2119 pattern_percent+1, percent+1);
2120 f->stem = savestring (buffer, o - buffer);
2121 if (this)
2122 {
2123 this->staticpattern = 1;
2124 this->stem = xstrdup (f->stem);
2125 }
2126 }
2127
2128 /* Free name if not needed further. */
2129 if (f != 0 && name != f->name
2130 && (name < f->name || name > f->name + strlen (f->name)))
2131 {
2132 free (name);
2133 name = f->name;
2134 }
2135
2136 /* If this target is a default target, update DEFAULT_GOAL_FILE. */
2137 if (streq (*default_goal_name, name)
2138 && (default_goal_file == 0
2139 || ! streq (default_goal_file->name, name)))
2140 default_goal_file = f;
2141 }
2142
2143 if (implicit)
2144 {
2145 targets[target_idx] = 0;
2146 target_percents[target_idx] = 0;
2147 if (deps)
2148 deps->need_2nd_expansion = second_expansion;
2149 create_pattern_rule (targets, target_percents, two_colon, deps, cmds, 1);
2150 free ((char *) target_percents);
2151 }
2152}
2153
2154
2155/* Search STRING for an unquoted STOPCHAR or blank (if BLANK is nonzero).
2156 Backslashes quote STOPCHAR, blanks if BLANK is nonzero, and backslash.
2157 Quoting backslashes are removed from STRING by compacting it into
2158 itself. Returns a pointer to the first unquoted STOPCHAR if there is
2159 one, or nil if there are none. STOPCHARs inside variable references are
2160 ignored if IGNOREVARS is true.
2161
2162 STOPCHAR _cannot_ be '$' if IGNOREVARS is true. */
2163
2164static char *
2165find_char_unquote (char *string, int stop1, int stop2, int blank,
2166 int ignorevars)
2167{
2168 unsigned int string_len = 0;
2169 register char *p = string;
2170 register int ch; /* bird: 'optimiziations' */
2171
2172 if (ignorevars)
2173 ignorevars = '$';
2174
2175 while (1)
2176 {
2177 if (stop2 && blank)
2178 while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1 && ch != stop2
2179 && ! isblank ((unsigned char) ch))
2180 ++p;
2181 else if (stop2)
2182 while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1 && ch != stop2)
2183 ++p;
2184 else if (blank)
2185 while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1
2186 && ! isblank ((unsigned char) ch))
2187 ++p;
2188 else
2189 while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1)
2190 ++p;
2191
2192 if (ch == '\0')
2193 break;
2194
2195 /* If we stopped due to a variable reference, skip over its contents. */
2196 if (ch == ignorevars)
2197 {
2198 char openparen = p[1];
2199
2200 p += 2;
2201
2202 /* Skip the contents of a non-quoted, multi-char variable ref. */
2203 if (openparen == '(' || openparen == '{')
2204 {
2205 unsigned int pcount = 1;
2206 char closeparen = (openparen == '(' ? ')' : '}');
2207
2208 while ((ch = *p))
2209 {
2210 if (ch == openparen)
2211 ++pcount;
2212 else if (ch == closeparen)
2213 if (--pcount == 0)
2214 {
2215 ++p;
2216 break;
2217 }
2218 ++p;
2219 }
2220 }
2221
2222 /* Skipped the variable reference: look for STOPCHARS again. */
2223 continue;
2224 }
2225
2226 if (p > string && p[-1] == '\\')
2227 {
2228 /* Search for more backslashes. */
2229 register int i = -2;
2230 while (&p[i] >= string && p[i] == '\\')
2231 --i;
2232 ++i;
2233 /* Only compute the length if really needed. */
2234 if (string_len == 0)
2235 string_len = strlen (string);
2236 /* The number of backslashes is now -I.
2237 Copy P over itself to swallow half of them. */
2238 bcopy (&p[i / 2], &p[i], (string_len - (p - string)) - (i / 2) + 1);
2239 p += i / 2;
2240 if (i % 2 == 0)
2241 /* All the backslashes quoted each other; the STOPCHAR was
2242 unquoted. */
2243 return p;
2244
2245 /* The STOPCHAR was quoted by a backslash. Look for another. */
2246 }
2247 else
2248 /* No backslash in sight. */
2249 return p;
2250 }
2251
2252 /* Never hit a STOPCHAR or blank (with BLANK nonzero). */
2253 return 0;
2254}
2255
2256/* Search PATTERN for an unquoted %. */
2257
2258char *
2259find_percent (char *pattern)
2260{
2261 return find_char_unquote (pattern, '%', 0, 0, 0);
2262}
2263
2264
2265/* Parse a string into a sequence of filenames represented as a
2266 chain of struct nameseq's in reverse order and return that chain.
2267
2268 The string is passed as STRINGP, the address of a string pointer.
2269 The string pointer is updated to point at the first character
2270 not parsed, which either is a null char or equals STOPCHAR.
2271
2272 SIZE is how big to construct chain elements.
2273 This is useful if we want them actually to be other structures
2274 that have room for additional info.
2275
2276 If STRIP is nonzero, strip `./'s off the beginning. */
2277
2278struct nameseq *
2279parse_file_seq (char **stringp, int stopchar, unsigned int size, int strip)
2280{
2281 struct nameseq *new = 0;
2282 struct nameseq *new1;
2283#ifndef NO_ARCHIVES /* bird: MSC warning */
2284 struct nameseq *lastnew1;
2285#endif
2286 char *p = *stringp;
2287 char *q;
2288 char *name;
2289
2290#ifdef VMS
2291# define VMS_COMMA ','
2292#else
2293# define VMS_COMMA 0
2294#endif
2295
2296 while (1)
2297 {
2298 /* Skip whitespace; see if any more names are left. */
2299 p = next_token (p);
2300 if (*p == '\0')
2301 break;
2302 if (*p == stopchar)
2303 break;
2304
2305 /* Yes, find end of next name. */
2306 q = p;
2307 p = find_char_unquote (q, stopchar, VMS_COMMA, 1, 0);
2308#ifdef VMS
2309 /* convert comma separated list to space separated */
2310 if (p && *p == ',')
2311 *p =' ';
2312#endif
2313#ifdef _AMIGA
2314 if (stopchar == ':' && p && *p == ':'
2315 && !(isspace ((unsigned char)p[1]) || !p[1]
2316 || isspace ((unsigned char)p[-1])))
2317 {
2318 p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0);
2319 }
2320#endif
2321#ifdef HAVE_DOS_PATHS
2322 /* For DOS paths, skip a "C:\..." or a "C:/..." until we find the
2323 first colon which isn't followed by a slash or a backslash.
2324 Note that tokens separated by spaces should be treated as separate
2325 tokens since make doesn't allow path names with spaces */
2326 if (stopchar == ':')
2327 while (p != 0 && !isspace ((unsigned char)*p) &&
2328 (p[1] == '\\' || p[1] == '/') && isalpha ((unsigned char)p[-1]))
2329 p = find_char_unquote (p + 1, stopchar, VMS_COMMA, 1, 0);
2330#endif
2331 if (p == 0)
2332 p = q + strlen (q);
2333
2334 if (strip)
2335#ifdef VMS
2336 /* Skip leading `[]'s. */
2337 while (p - q > 2 && q[0] == '[' && q[1] == ']')
2338#else
2339 /* Skip leading `./'s. */
2340 while (p - q > 2 && q[0] == '.' && q[1] == '/')
2341#endif
2342 {
2343 q += 2; /* Skip "./". */
2344 while (q < p && *q == '/')
2345 /* Skip following slashes: ".//foo" is "foo", not "/foo". */
2346 ++q;
2347 }
2348
2349 /* Extract the filename just found, and skip it. */
2350
2351 if (q == p)
2352 /* ".///" was stripped to "". */
2353#ifdef VMS
2354 continue;
2355#else
2356#ifdef _AMIGA
2357 name = savestring ("", 0);
2358#else
2359 name = savestring ("./", 2);
2360#endif
2361#endif
2362 else
2363#ifdef VMS
2364/* VMS filenames can have a ':' in them but they have to be '\'ed but we need
2365 * to remove this '\' before we can use the filename.
2366 * Savestring called because q may be read-only string constant.
2367 */
2368 {
2369 char *qbase = xstrdup (q);
2370 char *pbase = qbase + (p-q);
2371 char *q1 = qbase;
2372 char *q2 = q1;
2373 char *p1 = pbase;
2374
2375 while (q1 != pbase)
2376 {
2377 if (*q1 == '\\' && *(q1+1) == ':')
2378 {
2379 q1++;
2380 p1--;
2381 }
2382 *q2++ = *q1++;
2383 }
2384 name = savestring (qbase, p1 - qbase);
2385 free (qbase);
2386 }
2387#else
2388 name = savestring (q, p - q);
2389#endif
2390
2391 /* Add it to the front of the chain. */
2392 new1 = (struct nameseq *) xmalloc (size);
2393 new1->name = name;
2394 new1->next = new;
2395 new = new1;
2396 }
2397
2398#ifndef NO_ARCHIVES
2399
2400 /* Look for multi-word archive references.
2401 They are indicated by a elt ending with an unmatched `)' and
2402 an elt further down the chain (i.e., previous in the file list)
2403 with an unmatched `(' (e.g., "lib(mem"). */
2404
2405 new1 = new;
2406 lastnew1 = 0;
2407 while (new1 != 0)
2408 if (new1->name[0] != '(' /* Don't catch "(%)" and suchlike. */
2409 && new1->name[strlen (new1->name) - 1] == ')'
2410 && strchr (new1->name, '(') == 0)
2411 {
2412 /* NEW1 ends with a `)' but does not contain a `('.
2413 Look back for an elt with an opening `(' but no closing `)'. */
2414
2415 struct nameseq *n = new1->next, *lastn = new1;
2416 char *paren = 0;
2417 while (n != 0 && (paren = strchr (n->name, '(')) == 0)
2418 {
2419 lastn = n;
2420 n = n->next;
2421 }
2422 if (n != 0
2423 /* Ignore something starting with `(', as that cannot actually
2424 be an archive-member reference (and treating it as such
2425 results in an empty file name, which causes much lossage). */
2426 && n->name[0] != '(')
2427 {
2428 /* N is the first element in the archive group.
2429 Its name looks like "lib(mem" (with no closing `)'). */
2430
2431 char *libname;
2432
2433 /* Copy "lib(" into LIBNAME. */
2434 ++paren;
2435 libname = (char *) alloca (paren - n->name + 1);
2436 bcopy (n->name, libname, paren - n->name);
2437 libname[paren - n->name] = '\0';
2438
2439 if (*paren == '\0')
2440 {
2441 /* N was just "lib(", part of something like "lib( a b)".
2442 Edit it out of the chain and free its storage. */
2443 lastn->next = n->next;
2444 free (n->name);
2445 free ((char *) n);
2446 /* LASTN->next is the new stopping elt for the loop below. */
2447 n = lastn->next;
2448 }
2449 else
2450 {
2451 /* Replace N's name with the full archive reference. */
2452 name = concat (libname, paren, ")");
2453 free (n->name);
2454 n->name = name;
2455 }
2456
2457 if (new1->name[1] == '\0')
2458 {
2459 /* NEW1 is just ")", part of something like "lib(a b )".
2460 Omit it from the chain and free its storage. */
2461 if (lastnew1 == 0)
2462 new = new1->next;
2463 else
2464 lastnew1->next = new1->next;
2465 lastn = new1;
2466 new1 = new1->next;
2467 free (lastn->name);
2468 free ((char *) lastn);
2469 }
2470 else
2471 {
2472 /* Replace also NEW1->name, which already has closing `)'. */
2473 name = concat (libname, new1->name, "");
2474 free (new1->name);
2475 new1->name = name;
2476 new1 = new1->next;
2477 }
2478
2479 /* Trace back from NEW1 (the end of the list) until N
2480 (the beginning of the list), rewriting each name
2481 with the full archive reference. */
2482
2483 while (new1 != n)
2484 {
2485 name = concat (libname, new1->name, ")");
2486 free (new1->name);
2487 new1->name = name;
2488 lastnew1 = new1;
2489 new1 = new1->next;
2490 }
2491 }
2492 else
2493 {
2494 /* No frobnication happening. Just step down the list. */
2495 lastnew1 = new1;
2496 new1 = new1->next;
2497 }
2498 }
2499 else
2500 {
2501 lastnew1 = new1;
2502 new1 = new1->next;
2503 }
2504
2505#endif
2506
2507 *stringp = p;
2508 return new;
2509}
2510
2511
2512/* Find the next line of text in an eval buffer, combining continuation lines
2513 into one line.
2514 Return the number of actual lines read (> 1 if continuation lines).
2515 Returns -1 if there's nothing left in the buffer.
2516
2517 After this function, ebuf->buffer points to the first character of the
2518 line we just found.
2519 */
2520
2521/* Read a line of text from a STRING.
2522 Since we aren't really reading from a file, don't bother with linenumbers.
2523 */
2524
2525static unsigned long
2526readstring (struct ebuffer *ebuf)
2527{
2528 char *eol;
2529
2530 /* If there is nothing left in this buffer, return 0. */
2531 if (ebuf->bufnext >= ebuf->bufstart + ebuf->size)
2532 return -1;
2533
2534 /* Set up a new starting point for the buffer, and find the end of the
2535 next logical line (taking into account backslash/newline pairs). */
2536
2537 eol = ebuf->buffer = ebuf->bufnext;
2538
2539 while (1)
2540 {
2541 int backslash = 0;
2542 char *bol = eol;
2543 char *p;
2544
2545 /* Find the next newline. At EOS, stop. */
2546 eol = p = strchr (eol , '\n');
2547 if (!eol)
2548 {
2549 ebuf->bufnext = ebuf->bufstart + ebuf->size + 1;
2550 return 0;
2551 }
2552
2553 /* Found a newline; if it's escaped continue; else we're done. */
2554 while (p > bol && *(--p) == '\\')
2555 backslash = !backslash;
2556 if (!backslash)
2557 break;
2558 ++eol;
2559 }
2560
2561 /* Overwrite the newline char. */
2562 *eol = '\0';
2563 ebuf->bufnext = eol+1;
2564
2565 return 0;
2566}
2567
2568static long
2569readline (struct ebuffer *ebuf)
2570{
2571 char *p;
2572 char *end;
2573 char *start;
2574 long nlines = 0;
2575
2576 /* The behaviors between string and stream buffers are different enough to
2577 warrant different functions. Do the Right Thing. */
2578
2579 if (!ebuf->fp)
2580 return readstring (ebuf);
2581
2582 /* When reading from a file, we always start over at the beginning of the
2583 buffer for each new line. */
2584
2585 p = start = ebuf->bufstart;
2586 end = p + ebuf->size;
2587 *p = '\0';
2588
2589 while (fgets (p, end - p, ebuf->fp) != 0)
2590 {
2591 char *p2;
2592 unsigned long len;
2593 int backslash;
2594
2595 len = strlen (p);
2596 if (len == 0)
2597 {
2598 /* This only happens when the first thing on the line is a '\0'.
2599 It is a pretty hopeless case, but (wonder of wonders) Athena
2600 lossage strikes again! (xmkmf puts NULs in its makefiles.)
2601 There is nothing really to be done; we synthesize a newline so
2602 the following line doesn't appear to be part of this line. */
2603 error (&ebuf->floc,
2604 _("warning: NUL character seen; rest of line ignored"));
2605 p[0] = '\n';
2606 len = 1;
2607 }
2608
2609 /* Jump past the text we just read. */
2610 p += len;
2611
2612 /* If the last char isn't a newline, the whole line didn't fit into the
2613 buffer. Get some more buffer and try again. */
2614 if (p[-1] != '\n')
2615 goto more_buffer;
2616
2617 /* We got a newline, so add one to the count of lines. */
2618 ++nlines;
2619
2620#if !defined(WINDOWS32) && !defined(__MSDOS__) && !defined(__EMX__)
2621 /* Check to see if the line was really ended with CRLF; if so ignore
2622 the CR. */
2623 if ((p - start) > 1 && p[-2] == '\r')
2624 {
2625 --p;
2626 p[-1] = '\n';
2627 }
2628#endif
2629
2630 backslash = 0;
2631 for (p2 = p - 2; p2 >= start; --p2)
2632 {
2633 if (*p2 != '\\')
2634 break;
2635 backslash = !backslash;
2636 }
2637
2638 if (!backslash)
2639 {
2640 p[-1] = '\0';
2641 break;
2642 }
2643
2644 /* It was a backslash/newline combo. If we have more space, read
2645 another line. */
2646 if (end - p >= 80)
2647 continue;
2648
2649 /* We need more space at the end of our buffer, so realloc it.
2650 Make sure to preserve the current offset of p. */
2651 more_buffer:
2652 {
2653 unsigned long off = p - start;
2654 ebuf->size *= 2;
2655 start = ebuf->buffer = ebuf->bufstart = (char *) xrealloc (start,
2656 ebuf->size);
2657 p = start + off;
2658 end = start + ebuf->size;
2659 *p = '\0';
2660 }
2661 }
2662
2663 if (ferror (ebuf->fp))
2664 pfatal_with_name (ebuf->floc.filenm);
2665
2666 /* If we found some lines, return how many.
2667 If we didn't, but we did find _something_, that indicates we read the last
2668 line of a file with no final newline; return 1.
2669 If we read nothing, we're at EOF; return -1. */
2670
2671 return nlines ? nlines : p == ebuf->bufstart ? -1 : 1;
2672}
2673
2674
2675/* Parse the next "makefile word" from the input buffer, and return info
2676 about it.
2677
2678 A "makefile word" is one of:
2679
2680 w_bogus Should never happen
2681 w_eol End of input
2682 w_static A static word; cannot be expanded
2683 w_variable A word containing one or more variables/functions
2684 w_colon A colon
2685 w_dcolon A double-colon
2686 w_semicolon A semicolon
2687 w_varassign A variable assignment operator (=, :=, +=, or ?=)
2688
2689 Note that this function is only used when reading certain parts of the
2690 makefile. Don't use it where special rules hold sway (RHS of a variable,
2691 in a command list, etc.) */
2692
2693static enum make_word_type
2694get_next_mword (char *buffer, char *delim, char **startp, unsigned int *length)
2695{
2696 enum make_word_type wtype = w_bogus;
2697 char *p = buffer, *beg;
2698 char c;
2699
2700 /* Skip any leading whitespace. */
2701 while (isblank ((unsigned char)*p))
2702 ++p;
2703
2704 beg = p;
2705 c = *(p++);
2706 switch (c)
2707 {
2708 case '\0':
2709 wtype = w_eol;
2710 break;
2711
2712 case ';':
2713 wtype = w_semicolon;
2714 break;
2715
2716 case '=':
2717 wtype = w_varassign;
2718 break;
2719
2720 case ':':
2721 wtype = w_colon;
2722 switch (*p)
2723 {
2724 case ':':
2725 ++p;
2726 wtype = w_dcolon;
2727 break;
2728
2729 case '=':
2730 ++p;
2731 wtype = w_varassign;
2732 break;
2733 }
2734 break;
2735
2736 case '+':
2737 case '?':
2738 if (*p == '=')
2739 {
2740 ++p;
2741 wtype = w_varassign;
2742 break;
2743 }
2744
2745 default:
2746 if (delim && strchr (delim, c))
2747 wtype = w_static;
2748 break;
2749 }
2750
2751 /* Did we find something? If so, return now. */
2752 if (wtype != w_bogus)
2753 goto done;
2754
2755 /* This is some non-operator word. A word consists of the longest
2756 string of characters that doesn't contain whitespace, one of [:=#],
2757 or [?+]=, or one of the chars in the DELIM string. */
2758
2759 /* We start out assuming a static word; if we see a variable we'll
2760 adjust our assumptions then. */
2761 wtype = w_static;
2762
2763 /* We already found the first value of "c", above. */
2764 while (1)
2765 {
2766 char closeparen;
2767 int count;
2768
2769 switch (c)
2770 {
2771 case '\0':
2772 case ' ':
2773 case '\t':
2774 case '=':
2775 goto done_word;
2776
2777 case ':':
2778#ifdef HAVE_DOS_PATHS
2779 /* A word CAN include a colon in its drive spec. The drive
2780 spec is allowed either at the beginning of a word, or as part
2781 of the archive member name, like in "libfoo.a(d:/foo/bar.o)". */
2782 if (!(p - beg >= 2
2783 && (*p == '/' || *p == '\\') && isalpha ((unsigned char)p[-2])
2784 && (p - beg == 2 || p[-3] == '(')))
2785#endif
2786 goto done_word;
2787
2788 case '$':
2789 c = *(p++);
2790 if (c == '$')
2791 break;
2792
2793 /* This is a variable reference, so note that it's expandable.
2794 Then read it to the matching close paren. */
2795 wtype = w_variable;
2796
2797 if (c == '(')
2798 closeparen = ')';
2799 else if (c == '{')
2800 closeparen = '}';
2801 else
2802 /* This is a single-letter variable reference. */
2803 break;
2804
2805 for (count=0; *p != '\0'; ++p)
2806 {
2807 if (*p == c)
2808 ++count;
2809 else if (*p == closeparen && --count < 0)
2810 {
2811 ++p;
2812 break;
2813 }
2814 }
2815 break;
2816
2817 case '?':
2818 case '+':
2819 if (*p == '=')
2820 goto done_word;
2821 break;
2822
2823 case '\\':
2824 switch (*p)
2825 {
2826 case ':':
2827 case ';':
2828 case '=':
2829 case '\\':
2830 ++p;
2831 break;
2832 }
2833 break;
2834
2835 default:
2836 if (delim && strchr (delim, c))
2837 goto done_word;
2838 break;
2839 }
2840
2841 c = *(p++);
2842 }
2843 done_word:
2844 --p;
2845
2846 done:
2847 if (startp)
2848 *startp = beg;
2849 if (length)
2850 *length = p - beg;
2851 return wtype;
2852}
2853
2854
2855/* Construct the list of include directories
2856 from the arguments and the default list. */
2857
2858void
2859construct_include_path (char **arg_dirs)
2860{
2861 register unsigned int i;
2862#ifdef VAXC /* just don't ask ... */
2863 stat_t stbuf;
2864#else
2865 struct stat stbuf;
2866#endif
2867 /* Table to hold the dirs. */
2868
2869 register unsigned int defsize = (sizeof (default_include_directories)
2870 / sizeof (default_include_directories[0]));
2871 register unsigned int max = 5;
2872 register char **dirs = (char **) xmalloc ((5 + defsize) * sizeof (char *));
2873 register unsigned int idx = 0;
2874
2875#ifdef __MSDOS__
2876 defsize++;
2877#endif
2878
2879 /* First consider any dirs specified with -I switches.
2880 Ignore dirs that don't exist. */
2881
2882 if (arg_dirs != 0)
2883 while (*arg_dirs != 0)
2884 {
2885 char *dir = *arg_dirs++;
2886 int e;
2887
2888 if (dir[0] == '~')
2889 {
2890 char *expanded = tilde_expand (dir);
2891 if (expanded != 0)
2892 dir = expanded;
2893 }
2894
2895 EINTRLOOP (e, stat (dir, &stbuf));
2896 if (e == 0 && S_ISDIR (stbuf.st_mode))
2897 {
2898 if (idx == max - 1)
2899 {
2900 max += 5;
2901 dirs = (char **)
2902 xrealloc ((char *) dirs, (max + defsize) * sizeof (char *));
2903 }
2904 dirs[idx++] = dir;
2905 }
2906 else if (dir != arg_dirs[-1])
2907 free (dir);
2908 }
2909
2910 /* Now add at the end the standard default dirs. */
2911
2912#ifdef __MSDOS__
2913 {
2914 /* The environment variable $DJDIR holds the root of the
2915 DJGPP directory tree; add ${DJDIR}/include. */
2916 struct variable *djdir = lookup_variable ("DJDIR", 5);
2917
2918 if (djdir)
2919 {
2920 char *defdir = (char *) xmalloc (strlen (djdir->value) + 8 + 1);
2921
2922 strcat (strcpy (defdir, djdir->value), "/include");
2923 dirs[idx++] = defdir;
2924 }
2925 }
2926#endif
2927
2928 for (i = 0; default_include_directories[i] != 0; ++i)
2929 {
2930 int e;
2931
2932 EINTRLOOP (e, stat (default_include_directories[i], &stbuf));
2933 if (e == 0 && S_ISDIR (stbuf.st_mode))
2934 dirs[idx++] = default_include_directories[i];
2935 }
2936
2937 dirs[idx] = 0;
2938
2939 /* Now compute the maximum length of any name in it. Also add each
2940 dir to the .INCLUDE_DIRS variable. */
2941
2942 max_incl_len = 0;
2943 for (i = 0; i < idx; ++i)
2944 {
2945 unsigned int len = strlen (dirs[i]);
2946 /* If dir name is written with a trailing slash, discard it. */
2947 if (dirs[i][len - 1] == '/')
2948 /* We can't just clobber a null in because it may have come from
2949 a literal string and literal strings may not be writable. */
2950 dirs[i] = savestring (dirs[i], len - 1);
2951 if (len > max_incl_len)
2952 max_incl_len = len;
2953
2954 /* Append to .INCLUDE_DIRS. */
2955 do_variable_definition (NILF, ".INCLUDE_DIRS", dirs[i],
2956 o_default, f_append, 0);
2957 }
2958
2959 include_directories = dirs;
2960}
2961
2962
2963/* Expand ~ or ~USER at the beginning of NAME.
2964 Return a newly malloc'd string or 0. */
2965
2966char *
2967tilde_expand (char *name)
2968{
2969#ifndef VMS
2970 if (name[1] == '/' || name[1] == '\0')
2971 {
2972 extern char *getenv ();
2973 char *home_dir;
2974 int is_variable;
2975
2976 {
2977 /* Turn off --warn-undefined-variables while we expand HOME. */
2978 int save = warn_undefined_variables_flag;
2979 warn_undefined_variables_flag = 0;
2980
2981 home_dir = allocated_variable_expand ("$(HOME)");
2982
2983 warn_undefined_variables_flag = save;
2984 }
2985
2986 is_variable = home_dir[0] != '\0';
2987 if (!is_variable)
2988 {
2989 free (home_dir);
2990 home_dir = getenv ("HOME");
2991 }
2992#if !defined(_AMIGA) && !defined(WINDOWS32)
2993 if (home_dir == 0 || home_dir[0] == '\0')
2994 {
2995 extern char *getlogin ();
2996 char *logname = getlogin ();
2997 home_dir = 0;
2998 if (logname != 0)
2999 {
3000 struct passwd *p = getpwnam (logname);
3001 if (p != 0)
3002 home_dir = p->pw_dir;
3003 }
3004 }
3005#endif /* !AMIGA && !WINDOWS32 */
3006 if (home_dir != 0)
3007 {
3008 char *new = concat (home_dir, "", name + 1);
3009 if (is_variable)
3010 free (home_dir);
3011 return new;
3012 }
3013 }
3014#if !defined(_AMIGA) && !defined(WINDOWS32)
3015 else
3016 {
3017 struct passwd *pwent;
3018 char *userend = strchr (name + 1, '/');
3019 if (userend != 0)
3020 *userend = '\0';
3021 pwent = getpwnam (name + 1);
3022 if (pwent != 0)
3023 {
3024 if (userend == 0)
3025 return xstrdup (pwent->pw_dir);
3026 else
3027 return concat (pwent->pw_dir, "/", userend + 1);
3028 }
3029 else if (userend != 0)
3030 *userend = '/';
3031 }
3032#endif /* !AMIGA && !WINDOWS32 */
3033#endif /* !VMS */
3034 return 0;
3035}
3036
3037/* Given a chain of struct nameseq's describing a sequence of filenames,
3038 in reverse of the intended order, return a new chain describing the
3039 result of globbing the filenames. The new chain is in forward order.
3040 The links of the old chain are freed or used in the new chain.
3041 Likewise for the names in the old chain.
3042
3043 SIZE is how big to construct chain elements.
3044 This is useful if we want them actually to be other structures
3045 that have room for additional info. */
3046
3047struct nameseq *
3048multi_glob (struct nameseq *chain, unsigned int size)
3049{
3050 extern void dir_setup_glob ();
3051 register struct nameseq *new = 0;
3052 register struct nameseq *old;
3053 struct nameseq *nexto;
3054 glob_t gl;
3055#if defined(KMK) || defined(__EMX__) /* speed optimization */
3056 int rc;
3057#endif
3058
3059 dir_setup_glob (&gl);
3060
3061 for (old = chain; old != 0; old = nexto)
3062 {
3063#ifndef NO_ARCHIVES
3064 char *memname;
3065#endif
3066
3067 nexto = old->next;
3068
3069 if (old->name[0] == '~')
3070 {
3071 char *newname = tilde_expand (old->name);
3072 if (newname != 0)
3073 {
3074 free (old->name);
3075 old->name = newname;
3076 }
3077 }
3078
3079#ifndef NO_ARCHIVES
3080 if (ar_name (old->name))
3081 {
3082 /* OLD->name is an archive member reference.
3083 Replace it with the archive file name,
3084 and save the member name in MEMNAME.
3085 We will glob on the archive name and then
3086 reattach MEMNAME later. */
3087 char *arname;
3088 ar_parse_name (old->name, &arname, &memname);
3089 free (old->name);
3090 old->name = arname;
3091 }
3092 else
3093 memname = 0;
3094#endif /* !NO_ARCHIVES */
3095
3096#if defined(KMK) || defined(__EMX__) /* speed optimization */
3097 if (!strpbrk(old->name, "*?["))
3098 {
3099 gl.gl_pathc = 1;
3100 gl.gl_pathv = &old->name;
3101 rc = 0;
3102 }
3103 else
3104 rc = glob (old->name, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl);
3105 switch (rc)
3106#else
3107 switch (glob (old->name, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl))
3108#endif
3109 {
3110 case 0: /* Success. */
3111 {
3112 register int i = gl.gl_pathc;
3113 while (i-- > 0)
3114 {
3115#ifndef NO_ARCHIVES
3116 if (memname != 0)
3117 {
3118 /* Try to glob on MEMNAME within the archive. */
3119 struct nameseq *found
3120 = ar_glob (gl.gl_pathv[i], memname, size);
3121 if (found == 0)
3122 {
3123 /* No matches. Use MEMNAME as-is. */
3124 unsigned int alen = strlen (gl.gl_pathv[i]);
3125 unsigned int mlen = strlen (memname);
3126 struct nameseq *elt
3127 = (struct nameseq *) xmalloc (size);
3128 if (size > sizeof (struct nameseq))
3129 bzero (((char *) elt) + sizeof (struct nameseq),
3130 size - sizeof (struct nameseq));
3131 elt->name = (char *) xmalloc (alen + 1 + mlen + 2);
3132 bcopy (gl.gl_pathv[i], elt->name, alen);
3133 elt->name[alen] = '(';
3134 bcopy (memname, &elt->name[alen + 1], mlen);
3135 elt->name[alen + 1 + mlen] = ')';
3136 elt->name[alen + 1 + mlen + 1] = '\0';
3137 elt->next = new;
3138 new = elt;
3139 }
3140 else
3141 {
3142 /* Find the end of the FOUND chain. */
3143 struct nameseq *f = found;
3144 while (f->next != 0)
3145 f = f->next;
3146
3147 /* Attach the chain being built to the end of the FOUND
3148 chain, and make FOUND the new NEW chain. */
3149 f->next = new;
3150 new = found;
3151 }
3152
3153 free (memname);
3154 }
3155 else
3156#endif /* !NO_ARCHIVES */
3157 {
3158 struct nameseq *elt = (struct nameseq *) xmalloc (size);
3159 if (size > sizeof (struct nameseq))
3160 bzero (((char *) elt) + sizeof (struct nameseq),
3161 size - sizeof (struct nameseq));
3162 elt->name = xstrdup (gl.gl_pathv[i]);
3163 elt->next = new;
3164 new = elt;
3165 }
3166 }
3167#if defined(KMK) || defined(__EMX__) /* speed optimization */
3168 if (gl.gl_pathv != &old->name)
3169#endif
3170 globfree (&gl);
3171 free (old->name);
3172 free ((char *)old);
3173 break;
3174 }
3175
3176 case GLOB_NOSPACE:
3177 fatal (NILF, _("virtual memory exhausted"));
3178 break;
3179
3180 default:
3181 old->next = new;
3182 new = old;
3183 break;
3184 }
3185 }
3186
3187 return new;
3188}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette