summaryrefslogtreecommitdiff
path: root/awkgram.y
diff options
context:
space:
mode:
authorAndrew J. Schorr <aschorr@telemetry-investments.com>2012-08-11 17:07:24 -0400
committerAndrew J. Schorr <aschorr@telemetry-investments.com>2012-08-11 17:07:24 -0400
commit8d5a66b529a220239037a3cd7a2421aab85de53d (patch)
tree481b5086951c67d367c128b2551683c7421e372b /awkgram.y
parent9cc3e7f1126d924a343f01be6a92cf6aefe97bab (diff)
downloadgawk-8d5a66b529a220239037a3cd7a2421aab85de53d.tar.gz
Make it a fatal error to load the same file with -f and -i (or @include).
Diffstat (limited to 'awkgram.y')
-rw-r--r--awkgram.y19
1 files changed, 14 insertions, 5 deletions
diff --git a/awkgram.y b/awkgram.y
index d094b0e7..a6669e97 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -2328,11 +2328,13 @@ add_srcfile(int stype, char *src, SRCFILE *thisfile, bool *already_included, int
}
/* N.B. We do not eliminate duplicate SRC_FILE (-f) programs. */
- if (stype == SRC_INC || stype == SRC_EXTLIB) {
- for (s = srcfiles->next; s != srcfiles; s = s->next) {
- if ((s->stype == SRC_FILE || s->stype == SRC_INC || s->stype == SRC_EXTLIB)
- && files_are_same(path, s)
- ) {
+ for (s = srcfiles->next; s != srcfiles; s = s->next) {
+ if ((s->stype == SRC_FILE || s->stype == SRC_INC || s->stype == SRC_EXTLIB) && files_are_same(path, s)) {
+ if (stype == SRC_INC || stype == SRC_EXTLIB) {
+ /* eliminate duplicates */
+ if ((stype == SRC_INC) && (s->stype == SRC_FILE))
+ fatal(_("can't include `%s' and use it as a program file"), src);
+
if (do_lint) {
int line = sourceline;
/* Kludge: the line number may be off for `@include file'.
@@ -2352,6 +2354,13 @@ add_srcfile(int stype, char *src, SRCFILE *thisfile, bool *already_included, int
if (already_included)
*already_included = true;
return NULL;
+ } else {
+ /* duplicates are allowed for -f */
+ if (s->stype == SRC_INC)
+ fatal(_("can't include `%s' and use it as a program file"), src);
+ /* no need to scan for further matches, since
+ * they must be of homogeneous type */
+ break;
}
}
}