VirtualBox

source: kBuild/vendor/gnumake/2008-10-28/read.c

Last change on this file was 1989, checked in by bird, 16 years ago

Load gnumake-2008-10-28-CVS into vendor/gnumake/current.

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

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