2 * Program: pgn-extract: a Portable Game Notation (PGN) extractor.
3 * Copyright (C) 1994-2014 David Barnes
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 1, or (at your option)
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * David Barnes may be contacted as D.J.Barnes@kent.ac.uk
19 * http://www.cs.kent.ac.uk/people/staff/djb/
31 /* Read a single line of input. */
32 #define INIT_LINE_LENGTH 80
33 #define LINE_INCREMENT 20
35 /* Define a character that may be used to comment a line in, e.g.
36 * the variations files.
37 * Use the PGN escape mechanism character, for consistency.
39 #define COMMENT_CHAR '%'
50 line = (char *) MallocOrDie(INIT_LINE_LENGTH + 1);
51 max_length = INIT_LINE_LENGTH;
52 while((ch != '\n') && (ch != '\r') && (ch != EOF)){
53 /* Another character to add. */
54 if(len == max_length){
55 line = (char *)ReallocOrDie((void *)line,
56 max_length+LINE_INCREMENT+1);
60 max_length += LINE_INCREMENT;
68 /* Try to avoid double counting lines in dos-format files. */
70 if(ch != '\n' && ch != EOF) {
78 /* Return TRUE if line contains a non-space character, but
79 * is not a comment line.
82 non_blank_line(const char *line)
83 { Boolean blank = TRUE;
86 if(comment_line(line)){
87 /* Comment lines count as blanks. */
90 while(blank && (*line != '\0')){
91 if(!isspace((int) *line)){
104 blank_line(const char *line)
106 return !non_blank_line(line);
110 /* Should the given line be regarded as a comment line? */
112 comment_line(const char *line)
114 return *line == COMMENT_CHAR;