1 /* Variable function expansion for GNU Make.
2 Copyright (C) 1988, 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
3 This file is part of GNU Make.
5 GNU Make is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 GNU Make is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNU Make; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 static char *string_glob ();
27 /* Store into VARIABLE_BUFFER at O the result of scanning TEXT and replacing
28 each occurrence of SUBST with REPLACE. TEXT is null-terminated. SLEN is
29 the length of SUBST and RLEN is the length of REPLACE. If BY_WORD is
30 nonzero, substitutions are done only on matches which are complete
31 whitespace-delimited words. If SUFFIX_ONLY is nonzero, substitutions are
32 done only at the ends of whitespace-delimited words. */
35 subst_expand (o
, text
, subst
, replace
, slen
, rlen
, by_word
, suffix_only
)
38 char *subst
, *replace
;
39 unsigned int slen
, rlen
;
40 int by_word
, suffix_only
;
42 register char *t
= text
;
45 if (slen
== 0 && !by_word
&& !suffix_only
)
47 /* The first occurrence of "" in any string is its end. */
48 o
= variable_buffer_output (o
, t
, strlen (t
));
50 o
= variable_buffer_output (o
, replace
, rlen
);
54 while ((p
= sindex (t
, 0, subst
, slen
)) != 0)
56 /* Output everything before this occurrence of the string to replace. */
58 o
= variable_buffer_output (o
, t
, p
- t
);
60 /* If we're substituting only by fully matched words,
61 or only at the ends of words, check that this case qualifies. */
63 && ((p
> t
&& !isblank (p
[-1]))
64 || (p
[slen
] != '\0' && !isblank (p
[slen
]))))
66 && (p
[slen
] != '\0' && !isblank (p
[slen
]))))
67 /* Struck out. Output the rest of the string that is
68 no longer to be replaced. */
69 o
= variable_buffer_output (o
, subst
, slen
);
71 /* Output the replacement string. */
72 o
= variable_buffer_output (o
, replace
, rlen
);
74 /* Advance T past the string to be replaced. */
78 /* Output everything left on the end. */
80 o
= variable_buffer_output (o
, t
, strlen (t
));
86 /* Store into VARIABLE_BUFFER at O the result of scanning TEXT
87 and replacing strings matching PATTERN with REPLACE.
88 If PATTERN_PERCENT is not nil, PATTERN has already been
89 run through find_percent, and PATTERN_PERCENT is the result.
90 If REPLACE_PERCENT is not nil, REPLACE has already been
91 run through find_percent, and REPLACE_PERCENT is the result. */
94 patsubst_expand (o
, text
, pattern
, replace
, pattern_percent
, replace_percent
)
97 register char *pattern
, *replace
;
98 register char *pattern_percent
, *replace_percent
;
100 register int pattern_prepercent_len
, pattern_postpercent_len
;
101 register int replace_prepercent_len
, replace_postpercent_len
;
106 /* We call find_percent on REPLACE before checking PATTERN so that REPLACE
107 will be collapsed before we call subst_expand if PATTERN has no %. */
108 if (replace_percent
== 0)
109 replace_percent
= find_percent (replace
);
110 if (replace_percent
!= 0)
112 /* Record the length of REPLACE before and after the % so
113 we don't have to compute these lengths more than once. */
114 replace_prepercent_len
= replace_percent
- replace
;
115 replace_postpercent_len
= strlen (replace_percent
+ 1);
118 /* We store the length of the replacement
119 so we only need to compute it once. */
120 replace_prepercent_len
= strlen (replace
);
122 if (pattern_percent
== 0)
123 pattern_percent
= find_percent (pattern
);
124 if (pattern_percent
== 0)
125 /* With no % in the pattern, this is just a simple substitution. */
126 return subst_expand (o
, text
, pattern
, replace
,
127 strlen (pattern
), strlen (replace
), 1, 0);
129 /* Record the length of PATTERN before and after the %
130 so we don't have to compute it more than once. */
131 pattern_prepercent_len
= pattern_percent
- pattern
;
132 pattern_postpercent_len
= strlen (pattern_percent
+ 1);
134 while ((t
= find_next_token (&text
, &len
)) != 0)
138 /* Is it big enough to match? */
139 if (len
< pattern_prepercent_len
+ pattern_postpercent_len
)
142 /* Does the prefix match? */
143 if (!fail
&& pattern_prepercent_len
> 0
145 || t
[pattern_prepercent_len
- 1] != pattern_percent
[-1]
146 || strncmp (t
+ 1, pattern
+ 1, pattern_prepercent_len
- 1)))
149 /* Does the suffix match? */
150 if (!fail
&& pattern_postpercent_len
> 0
151 && (t
[len
- 1] != pattern_percent
[pattern_postpercent_len
]
152 || t
[len
- pattern_postpercent_len
] != pattern_percent
[1]
153 || strncmp (&t
[len
- pattern_postpercent_len
],
154 &pattern_percent
[1], pattern_postpercent_len
- 1)))
158 /* It didn't match. Output the string. */
159 o
= variable_buffer_output (o
, t
, len
);
162 /* It matched. Output the replacement. */
164 /* Output the part of the replacement before the %. */
165 o
= variable_buffer_output (o
, replace
, replace_prepercent_len
);
167 if (replace_percent
!= 0)
169 /* Output the part of the matched string that
170 matched the % in the pattern. */
171 o
= variable_buffer_output (o
, t
+ pattern_prepercent_len
,
172 len
- (pattern_prepercent_len
173 + pattern_postpercent_len
));
174 /* Output the part of the replacement after the %. */
175 o
= variable_buffer_output (o
, replace_percent
+ 1,
176 replace_postpercent_len
);
180 /* Output a space, but not if the replacement is "". */
181 if (fail
|| replace_prepercent_len
> 0
182 || (replace_percent
!= 0 && len
+ replace_postpercent_len
> 0))
184 o
= variable_buffer_output (o
, " ", 1);
189 /* Kill the last space. */
195 /* Handle variable-expansion-time functions such as $(dir foo/bar) ==> foo/ */
197 /* These enumeration constants distinguish the
198 various expansion-time built-in functions. */
226 /* Greater than the length of any function name. */
227 #define MAXFUNCTIONLEN 11
229 /* The function names and lengths of names, for looking them up. */
235 enum function function
;
238 { "subst", 5, function_subst
},
239 { "addsuffix", 9, function_addsuffix
},
240 { "addprefix", 9, function_addprefix
},
241 { "dir", 3, function_dir
},
242 { "notdir", 6, function_notdir
},
243 { "suffix", 6, function_suffix
},
244 { "basename", 8, function_basename
},
245 { "wildcard", 8, function_wildcard
},
246 { "firstword", 9, function_firstword
},
247 { "word", 4, function_word
},
248 { "words", 5, function_words
},
249 { "findstring", 10, function_findstring
},
250 { "strip", 5, function_strip
},
251 { "join", 4, function_join
},
252 { "patsubst", 8, function_patsubst
},
253 { "filter", 6, function_filter
},
254 { "filter-out", 10, function_filter_out
},
255 { "foreach", 7, function_foreach
},
256 { "sort", 4, function_sort
},
257 { "origin", 6, function_origin
},
258 { "shell", 5, function_shell
},
259 { 0, 0, function_invalid
}
262 /* Return 1 if PATTERN matches WORD, 0 if not. */
265 pattern_matches (pattern
, percent
, word
)
266 register char *pattern
, *percent
, *word
;
268 unsigned int sfxlen
, wordlen
;
272 unsigned int len
= strlen (pattern
) + 1;
273 char *new = (char *) alloca (len
);
274 bcopy (pattern
, new, len
);
276 percent
= find_percent (pattern
);
278 return streq (pattern
, word
);
281 sfxlen
= strlen (percent
+ 1);
282 wordlen
= strlen (word
);
284 if (wordlen
< (percent
- pattern
) + sfxlen
285 || strncmp (pattern
, word
, percent
- pattern
))
288 return !strcmp (percent
+ 1, word
+ (wordlen
- sfxlen
));
291 int shell_function_pid
= 0, shell_function_completed
;
293 /* Perform the function specified by FUNCTION on the text at TEXT.
294 END is points to the end of the argument text (exclusive).
295 The output is written into VARIABLE_BUFFER starting at O. */
297 /* Note this absorbs a semicolon and is safe to use in conditionals. */
298 #define BADARGS(func) \
299 if (reading_filename != 0) \
300 makefile_fatal (reading_filename, *reading_lineno_ptr, \
301 "insufficient arguments to function `%s'", \
304 fatal ("insufficient arguments to function `%s'", func)
307 expand_function (o
, function
, text
, end
)
309 enum function function
;
317 char endparen
= *end
, startparen
= *end
== ')' ? '(' : '{';
332 /* Expand the command line. */
333 text
= expand_argument (text
, end
);
335 /* Construct the argument list. */
336 argv
= construct_command_argv (text
, (char *) NULL
, (struct file
*) 0);
340 /* For error messages. */
341 if (reading_filename
!= 0)
343 error_prefix
= (char *) alloca (strlen (reading_filename
) + 100);
344 sprintf (error_prefix
,
345 "%s:%u: ", reading_filename
, *reading_lineno_ptr
);
350 if (pipe (pipedes
) < 0)
352 perror_with_name (error_prefix
, "pipe");
358 perror_with_name (error_prefix
, "fork");
360 child_execute_job (0, pipedes
[1], argv
, environ
);
363 /* We are the parent. Set up and read from the pipe. */
364 char *buffer
= (char *) xmalloc (201);
365 unsigned int maxlen
= 200;
368 /* Record the PID for child_handler. */
369 shell_function_pid
= pid
;
370 shell_function_completed
= 0;
372 /* Close the write side of the pipe. */
373 (void) close (pipedes
[1]);
375 /* Read from the pipe until it gets EOF. */
382 buffer
= (char *) xrealloc (buffer
, maxlen
+ 1);
386 cc
= read (pipedes
[0], &buffer
[i
], maxlen
- i
);
391 while (cc
> 0 || errno
== EINTR
);
396 /* Close the read side of the pipe. */
397 (void) close (pipedes
[0]);
399 /* Loop until child_handler sets shell_function_completed
400 to the status of our child shell. */
401 while (shell_function_completed
== 0)
402 reap_children (1, 0);
404 shell_function_pid
= 0;
406 /* The child_handler function will set shell_function_completed
407 to 1 when the child dies normally, or to -1 if it
408 dies with status 127, which is most likely an exec fail. */
410 if (shell_function_completed
== -1)
412 /* This most likely means that the execvp failed,
413 so we should just write out the error message
414 that came in over the pipe from the child. */
415 fputs (buffer
, stderr
);
420 /* The child finished normally. Replace all
421 newlines in its output with spaces, and put
422 that in the variable output buffer. */
425 if (buffer
[i
- 1] == '\n')
430 while ((p
= index (p
, '\n')) != 0)
432 o
= variable_buffer_output (o
, buffer
, i
);
437 free ((char *) argv
);
445 case function_origin
:
446 /* Expand the argument. */
447 text
= expand_argument (text
, end
);
450 register struct variable
*v
= lookup_variable (text
, strlen (text
));
452 o
= variable_buffer_output (o
, "undefined", 9);
461 o
= variable_buffer_output (o
, "default", 7);
464 o
= variable_buffer_output (o
, "environment", 11);
467 o
= variable_buffer_output (o
, "file", 4);
470 o
= variable_buffer_output (o
, "environment override", 20);
473 o
= variable_buffer_output (o
, "command line", 12);
476 o
= variable_buffer_output (o
, "override", 8);
479 o
= variable_buffer_output (o
, "automatic", 9);
488 /* Expand the argument. */
489 text
= expand_argument (text
, end
);
492 char **words
= (char **) xmalloc (10 * sizeof (char *));
493 unsigned int nwords
= 10;
494 register unsigned int wordi
= 0;
497 /* Chop TEXT into words and put them in WORDS. */
499 while ((p
= find_next_token (&t
, &len
)) != 0)
501 if (wordi
>= nwords
- 1)
504 words
= (char **) xrealloc ((char *) words
,
505 nwords
* sizeof (char *));
507 words
[wordi
++] = savestring (p
, len
);
512 /* Now sort the list of words. */
513 qsort ((char *) words
, wordi
, sizeof (char *), alpha_compare
);
515 /* Now write the sorted list. */
516 for (i
= 0; i
< wordi
; ++i
)
518 len
= strlen (words
[i
]);
519 if (i
== wordi
- 1 || strlen (words
[i
+ 1]) != len
520 || strcmp (words
[i
], words
[i
+ 1]))
522 o
= variable_buffer_output (o
, words
[i
], len
);
523 o
= variable_buffer_output (o
, " ", 1);
527 /* Kill the last space. */
531 free ((char *) words
);
537 case function_foreach
:
539 /* Get three comma-separated arguments but
540 expand only the first two. */
542 register struct variable
*v
;
545 for (p
= text
; p
< end
; ++p
)
547 if (*p
== startparen
)
549 else if (*p
== endparen
)
551 else if (*p
== ',' && count
<= 0)
556 var
= expand_argument (text
, p
);
560 for (p
= p2
; p
< end
; ++p
)
562 if (*p
== startparen
)
564 else if (*p
== endparen
)
566 else if (*p
== ',' && count
<= 0)
571 list
= expand_argument (p2
, p
);
574 text
= savestring (p
, end
- p
);
576 push_new_variable_scope ();
577 v
= define_variable (var
, strlen (var
), "", o_automatic
, 0);
579 while ((p
= find_next_token (&p3
, &len
)) != 0)
585 result
= allocated_variable_expand (text
);
588 o
= variable_buffer_output (o
, result
, strlen (result
));
589 o
= variable_buffer_output (o
, " ", 1);
594 /* Kill the last space. */
597 pop_variable_scope ();
605 case function_filter
:
606 case function_filter_out
:
613 } *words
, *wordtail
, *wp
;
615 /* Get two comma-separated arguments and expand each one. */
617 for (p
= text
; p
< end
; ++p
)
619 if (*p
== startparen
)
621 else if (*p
== endparen
)
623 else if (*p
== ',' && count
<= 0)
627 BADARGS (function
== function_filter
? "filter" : "filter-out");
628 p2
= expand_argument (text
, p
);
630 text
= expand_argument (p
+ 1, end
);
632 /* Chop TEXT up into words and then run each pattern through. */
633 words
= wordtail
= 0;
635 while ((p
= find_next_token (&p3
, &len
)) != 0)
637 struct word
*w
= (struct word
*) alloca (sizeof (struct word
));
655 /* Run each pattern through the words, killing words. */
657 while ((p
= find_next_token (&p3
, &len
)) != 0)
663 percent
= find_percent (p
);
664 for (wp
= words
; wp
!= 0; wp
= wp
->next
)
665 wp
->matched
|= (percent
== 0 ? streq (p
, wp
->word
)
666 : pattern_matches (p
, percent
, wp
->word
));
671 /* Output the words that matched (or didn't, for filter-out). */
672 for (wp
= words
; wp
!= 0; wp
= wp
->next
)
673 if (function
== function_filter
? wp
->matched
: !wp
->matched
)
675 o
= variable_buffer_output (o
, wp
->word
, strlen (wp
->word
));
676 o
= variable_buffer_output (o
, " ", 1);
680 /* Kill the last space. */
689 case function_patsubst
:
690 /* Get three comma-separated arguments and expand each one. */
692 for (p
= text
; p
< end
; ++p
)
694 if (*p
== startparen
)
696 else if (*p
== endparen
)
698 else if (*p
== ',' && count
<= 0)
702 BADARGS ("patsubst");
706 for (++p
; p
< end
; ++p
)
708 if (*p
== startparen
)
710 else if (*p
== endparen
)
712 else if (*p
== ',' && count
<= 0)
716 BADARGS ("patsubst");
718 text
= expand_argument (text
, p2
);
719 p3
= expand_argument (p2
+ 1, p
);
720 p2
= expand_argument (p
+ 1, end
);
722 o
= patsubst_expand (o
, p2
, text
, p3
, (char *) 0, (char *) 0);
730 /* Get two comma-separated arguments and expand each one. */
732 for (p
= text
; p
< end
; ++p
)
734 if (*p
== startparen
)
736 else if (*p
== endparen
)
738 else if (*p
== ',' && count
<= 0)
743 text
= expand_argument (text
, p
);
745 p
= expand_argument (p
+ 1, end
);
748 /* Write each word of the first argument directly followed
749 by the corresponding word of the second argument.
750 If the two arguments have a different number of words,
751 the excess words are just output separated by blanks. */
752 register char *tp
, *pp
;
757 unsigned int tlen
, plen
;
759 tp
= find_next_token (&p2
, &tlen
);
761 o
= variable_buffer_output (o
, tp
, tlen
);
763 pp
= find_next_token (&p3
, &plen
);
765 o
= variable_buffer_output (o
, pp
, plen
);
767 if (tp
!= 0 || pp
!= 0)
769 o
= variable_buffer_output (o
, " ", 1);
773 while (tp
!= 0 || pp
!= 0);
775 /* Kill the last blank. */
784 /* Expand the argument. */
785 text
= expand_argument (text
, end
);
788 while ((p
= find_next_token (&p2
, &i
)) != 0)
790 o
= variable_buffer_output (o
, p
, i
);
791 o
= variable_buffer_output (o
, " ", 1);
795 /* Kill the last space. */
801 case function_wildcard
:
802 text
= expand_argument (text
, end
);
804 p
= string_glob (text
);
805 o
= variable_buffer_output (o
, p
, strlen (p
));
811 /* Get three comma-separated arguments and expand each one. */
813 for (p
= text
; p
< end
; ++p
)
815 if (*p
== startparen
)
817 else if (*p
== endparen
)
819 else if (*p
== ',' && count
<= 0)
827 for (++p
; p
< end
; ++p
)
829 if (*p
== startparen
)
831 else if (*p
== endparen
)
833 else if (*p
== ',' && count
<= 0)
839 text
= expand_argument (text
, p2
);
840 p3
= expand_argument (p2
+ 1, p
);
841 p2
= expand_argument (p
+ 1, end
);
843 o
= subst_expand (o
, p2
, text
, p3
, strlen (text
), strlen (p3
), 0, 0);
850 case function_firstword
:
851 /* Expand the argument. */
852 text
= expand_argument (text
, end
);
854 /* Find the first word in TEXT. */
856 p
= find_next_token (&p2
, &i
);
858 o
= variable_buffer_output (o
, p
, i
);
864 /* Get two comma-separated arguments and expand each one. */
866 for (p
= text
; p
< end
; ++p
)
868 if (*p
== startparen
)
870 else if (*p
== endparen
)
872 else if (*p
== ',' && count
<= 0)
877 text
= expand_argument (text
, p
);
879 p3
= expand_argument (p
+ 1, end
);
881 /* Check the first argument. */
882 for (p2
= text
; *p2
!= '\0'; ++p2
)
883 if (*p2
< '0' || *p2
> '9')
885 if (reading_filename
!= 0)
886 makefile_fatal (reading_filename
, *reading_lineno_ptr
,
887 "non-numeric first argument to `word' function");
889 fatal ("non-numeric first argument to `word' function");
892 i
= (unsigned int) atoi (text
);
895 if (reading_filename
!= 0)
896 makefile_fatal (reading_filename
, *reading_lineno_ptr
,
897 "the `word' function takes a one-origin \
900 fatal ("the `word' function takes a one-origin index argument");
904 while ((p
= find_next_token (&p2
, &len
)) != 0)
908 o
= variable_buffer_output (o
, p
, len
);
915 /* Expand the argument. */
916 text
= expand_argument (text
, end
);
920 while (find_next_token (&p2
, (unsigned int *) 0) != 0)
925 sprintf (buf
, "%d", i
);
926 o
= variable_buffer_output (o
, buf
, strlen (buf
));
932 case function_findstring
:
933 /* Get two comma-separated arguments and expand each one. */
935 for (p
= text
; p
< end
; ++p
)
937 if (*p
== startparen
)
939 else if (*p
== endparen
)
941 else if (*p
== ',' && count
<= 0)
945 BADARGS ("findstring");
946 text
= expand_argument (text
, p
);
948 p
= expand_argument (p
+ 1, end
);
950 /* Find the first occurrence of the first string in the second. */
952 if (sindex (p
, 0, text
, i
) != 0)
953 o
= variable_buffer_output (o
, text
, i
);
959 case function_addsuffix
:
960 case function_addprefix
:
961 /* Get two comma-separated arguments and expand each one. */
963 for (p
= text
; p
< end
; ++p
)
965 if (*p
== startparen
)
967 else if (*p
== endparen
)
969 else if (*p
== ',' && count
<= 0)
973 BADARGS (function
== function_addsuffix
? "addsuffix" : "addprefix");
974 text
= expand_argument (text
, p
);
977 p2
= expand_argument (p
+ 1, end
);
980 while ((p
= find_next_token (&p3
, &len
)) != 0)
982 if (function
== function_addprefix
)
983 o
= variable_buffer_output (o
, text
, i
);
984 o
= variable_buffer_output (o
, p
, len
);
985 if (function
== function_addsuffix
)
986 o
= variable_buffer_output (o
, text
, i
);
987 o
= variable_buffer_output (o
, " ", 1);
991 /* Kill last space. */
999 case function_basename
:
1000 /* Expand the argument. */
1001 text
= expand_argument (text
, end
);
1004 while ((p2
= find_next_token (&p3
, &len
)) != 0)
1007 while (p
>= p2
&& *p
!= (function
== function_dir
? '/' : '.'))
1011 if (function
== function_dir
)
1013 o
= variable_buffer_output (o
, p2
, p
- p2
);
1015 else if (function
== function_dir
)
1016 o
= variable_buffer_output (o
, "./", 2);
1018 /* The entire name is the basename. */
1019 o
= variable_buffer_output (o
, p2
, len
);
1021 o
= variable_buffer_output (o
, " ", 1);
1025 /* Kill last space. */
1031 case function_notdir
:
1032 case function_suffix
:
1033 /* Expand the argument. */
1034 text
= expand_argument (text
, end
);
1037 while ((p2
= find_next_token (&p3
, &len
)) != 0)
1040 while (p
>= p2
&& *p
!= (function
== function_notdir
? '/' : '.'))
1044 if (function
== function_notdir
)
1046 o
= variable_buffer_output (o
, p
, len
- (p
- p2
));
1048 else if (function
== function_notdir
)
1049 o
= variable_buffer_output (o
, p2
, len
);
1051 if (function
== function_notdir
|| p
>= p2
)
1053 o
= variable_buffer_output (o
, " ", 1);
1058 /* Kill last space. */
1068 /* Check for a function invocation in *STRINGP. *STRINGP points at the
1069 opening ( or { and is not null-terminated. If a function invocation
1070 is found, expand it into the buffer at *OP, updating *OP, incrementing
1071 *STRINGP past the reference and returning nonzero. If not, return zero. */
1074 handle_function (op
, stringp
)
1079 register unsigned int code
;
1080 unsigned int maxlen
;
1081 char *beg
= *stringp
+ 1;
1084 endref
= lindex (beg
, beg
+ MAXFUNCTIONLEN
, '\0');
1085 maxlen
= endref
!= 0 ? endref
- beg
: MAXFUNCTIONLEN
;
1087 for (code
= 0; function_table
[code
].name
!= 0; ++code
)
1089 if (maxlen
< function_table
[code
].len
)
1091 endref
= beg
+ function_table
[code
].len
;
1092 if (isblank (*endref
)
1093 && !strncmp (function_table
[code
].name
, beg
,
1094 function_table
[code
].len
))
1097 if (function_table
[code
].name
!= 0)
1099 /* We have found a call to an expansion-time function.
1100 Find the end of the arguments, and do the function. */
1102 char openparen
= beg
[-1], closeparen
= openparen
== '(' ? ')' : '}';
1107 /* Space after function name isn't part of the args. */
1108 p
= next_token (endref
);
1111 /* Count nested use of whichever kind of parens we use,
1112 so that nested calls and variable refs work. */
1114 for (; *p
!= '\0'; ++p
)
1116 if (*p
== openparen
)
1118 else if (*p
== closeparen
&& --count
< 0)
1122 /* We found the end; expand the function call. */
1124 *op
= expand_function (*op
, function_table
[code
].function
, argbeg
, p
);
1132 /* Glob-expand LINE. The returned pointer is
1133 only good until the next call to string_glob. */
1139 static char *result
= 0;
1140 static unsigned int length
;
1141 register struct nameseq
*chain
;
1142 register unsigned int idx
;
1144 chain
= multi_glob (parse_file_seq (&line
, '\0', sizeof (struct nameseq
), 0),
1145 sizeof (struct nameseq
),
1146 /* We do not want parse_file_seq to strip `./'s.
1147 That would break examples like:
1148 $(patsubst ./%.c,obj/%.o,$(wildcard ./*.c)) */
1154 result
= (char *) xmalloc (100);
1160 register char *name
= chain
->name
;
1161 unsigned int len
= strlen (name
);
1163 struct nameseq
*next
= chain
->next
;
1164 free ((char *) chain
);
1167 /* multi_glob will pass names without globbing metacharacters
1168 through as is, but we want only files that actually exist. */
1169 if (file_exists_p (name
))
1171 if (idx
+ len
+ 1 > length
)
1173 length
+= (len
+ 1) * 2;
1174 result
= (char *) xrealloc (result
, length
);
1176 bcopy (name
, &result
[idx
], len
);
1178 result
[idx
++] = ' ';
1184 /* Kill the last space and terminate the string. */
1188 result
[idx
- 1] = '\0';