Refactor error messages to avoid macros.
[m4/ericb.git] / checks / get-them
blob0d3e37be8fc2c317f9ed72f891d91dceb4f6cc50
1 #!/bin/sh
2 # -*- AWK -*-
3 # Extract all examples from the manual source.
4 # Copyright (C) 1992, 2005, 2006, 2007 Free Software Foundation, Inc.
6 # This script is for use with GNU awk.
8 FILE=${1-/dev/null}
10 $AWK '
12 BEGIN {
13 node = "";
14 seq = -1;
15 count = 0;
16 file = "NONE";
17 status = 0;
18 options = "";
21 /^@node / {
22 if (seq > 0)
23 printf(" -- %d file%s", seq, seq == 1 ? "" : "s");
24 if (seq >= 0)
25 printf("\n");
27 split($0, tmp, ",");
28 node = substr(tmp[1], 7);
29 if (length(node) > 10)
30 printf("Node: %s - truncated", node);
31 else
32 printf("Node: %s ", node);
33 gsub(" ", "_", node);
34 node = tolower(substr(node, 1, 10));
35 seq = 0;
38 /^@comment ignore$/ {
39 getline;
40 status = 0;
41 options = "";
42 next;
45 /^@comment status: / {
46 status = $3;
49 /^@comment options: / {
50 options = $0;
51 gsub ("@comment options:", "", options);
54 /^@example$/, /^@end example$/ {
55 if (seq < 0)
56 next;
57 if ($0 ~ /^@example$/) {
58 if (count > 0)
59 close (file);
60 seq++;
61 count++;
62 file = sprintf("%03d.%s", count, node);
63 printf("dnl @ %s:%d: Origin of test\n"\
64 "dnl @ expected status: %d\n"\
65 "dnl @ extra options: %s\n"\
66 "dnl @ Copyright (C) 2006, 2007 Free Software Foundation\n"\
67 "dnl @ This file is free software; the Free Software Foundation\n"\
68 "dnl @ gives unlimited permission to copy and/or distribute it\n"\
69 "dnl @ with or without modifications, as long as this notice\n"\
70 "dnl @ is preserved.\n", FILENAME, NR, status, options) > file;
71 status = 0;
72 options = "";
73 next;
75 if ($0 ~ /^@end example$/) {
76 next;
78 if ($0 ~ /^\^D$/)
79 next;
80 if ($0 ~ /^\$ @kbd/)
81 next;
82 if ($0 ~ /^@result\{\}/ || $0 ~ /^@error\{\}/)
83 prefix = "dnl ";
84 else
85 prefix = "";
86 gsub("@@", "@", $0);
87 gsub("@{", "{", $0);
88 gsub("@}", "}", $0);
89 gsub("@w{ }", " ", $0);
90 gsub("@tabchar{}", "\t", $0);
91 printf("%s%s\n", prefix, $0) >> file;
94 END {
95 printf("\n");
97 ' $FILE