Initial checkin. I created this by combining the XBoard 4.2.6 and
[xboard.git] / comment.in
1 #! @AWKPATH@ -f
2 #
3 # Preprocessor for chess games that are formatted as blocks of moves
4 #  interspersed with blocks of text, separated by blank lines.  Finds
5 #  the blocks of text and encloses them with "{ }" brackets so that
6 #  xboard's game parser can identify them as comments.  Many games are
7 #  posted to rec.games.chess in this format.
8 #
9 # Limitation:  Fails if a text block starts with a numbered move.  In
10 #  that case you'll have to hand-edit the output.
11 #
12 BEGIN {
13     inmoves = 0;
14     blankline = 1;
15 }
16
17 {
18     if (NF == 0) {
19         blankline = 1;
20     } else if (blankline) {
21         blankline = 0;
22         if ($1 ~ /^[0-9]+/) {
23             if (!inmoves) {
24                 inmoves = 1;
25                 print "}";
26             } else {
27                 print "";
28             }
29         } else {
30             if (inmoves) {
31                 inmoves = 0;
32                 print "{";
33             } else {
34                 print "}{";
35             }
36         }
37         print $0;
38     } else {
39         print $0;
40     }
41 }
42