# Extract all examples from the manual source. -*- AWK -*-
# This file is part of GNU Bison
-# Copyright (C) 1992, 2000, 2001, 2005, 2006, 2009 Free Software
+
+# Copyright (C) 1992, 2000-2001, 2005-2006, 2009-2012 Free Software
# Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
if (ARGV[argc] == "--")
break;
for (i = argc + 1; i < ARGC; ++i)
- file_wanted[ARGV[i]] = 1;
+ file_wanted[basename(ARGV[i])] = ARGV[i];
ARGC = argc;
}
}
/^@comment file: / {
- if (!file_wanted[$3])
- message("ignoring " $3);
+ if (file = file_wanted[$3])
+ message(" GEN " file);
else
- {
- message("extracting " $3);
- file = $3;
- }
+ message("SKIP " $3);
}
-/^@example$/, /^@end example$/ {
+/^@(small)?example$/, /^@end (small)?example$/ {
if (!file)
next;
- if ($0 ~ /^@example$/)
+ if ($0 ~ /^@(small)?example$/)
{
input = files_output[file] ? "\n" : "";
# => + 2.
# Note that recent Bison support it, but not Flex.
if (file ~ /\.[chy]*$/)
- input = "#line " (FNR + 1) " \"" FILENAME "\"\n";
+ input = "#line " (FNR + 1) " \"" FILENAME "\"\n";
next;
}
- if ($0 ~ /^@end example$/)
+ if ($0 ~ /^@end (small)?example$/)
{
if (input == "")
- fatal("no contents: " file);
+ fatal("no contents: " file);
input = normalize(input);
# No spurious end of line: use printf.
if (files_output[file])
- # The parens around the output file seem to be required
+ # The parens around the output file seem to be required
# by awk on Mac OS X Tiger (darwin 8.4.6).
printf ("%s", input) >> (output_dir "/" file);
else
- printf ("%s", input) > (output_dir "/" file);
+ printf ("%s", input) > (output_dir "/" file);
close (output_dir "/" file);
files_output[file] = 1;
# Whole line commands.
if (line ~ /^@(c |comment|dots|end (ignore|group)|ignore|group)/)
- # Gperf accepts empty lines as valid input!!!
- if (file ~ /\.gperf$/)
- continue;
- else
- line = "";
+ # Gperf accepts empty lines as valid input!!!
+ if (file ~ /\.gperf$/)
+ continue;
+ else
+ line = "";
gsub (/"@value\{VERSION\}"/, "\"" VERSION "\"", line)
gsub (/^@result\{\}/, "", line);
}
+function basename(name, a, n) {
+ n = split (name, a, "/");
+ return a[n];
+}
+
function message(msg) {
if (! message_printed[msg])
{