4 * Copyright (C) 1993-1999 by Jochen Wiedmann and Marcin Orlowski
5 * Copyright (C) 2002-2010 by the FlexCat Open Source Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "showfuncs.h"
25 #include "readprefs.h"
28 #include "createcat.h"
30 struct CDLine
*FirstCDLine
= NULL
; /* First catalog description line. */
31 char *HeaderName
= NULL
;
35 /* This scans the catalog description file.
36 Inputs: cdfile - name of the catalog description file
37 Result: TRUE if successful, FALSE otherwise */
39 int ScanCDFile(char *cdfile
)
42 struct CDLine
*cdline
, **cdptr
= &FirstCDLine
;
43 struct CatString
*cs
, **csptr
= &FirstCatString
;
52 if((fp
= fopen(cdfile
, "r")) == NULL
)
54 ShowErrorQuick(MSG_ERR_NOCATALOGDESCRIPTION
, cdfile
);
58 setvbuf(fp
, NULL
, _IOFBF
, buffer_size
);
60 while(!feof(fp
) && (line
= newline
= ReadLine(fp
, TRUE
)) != NULL
)
62 if((cdline
= malloc(sizeof(*cdline
))) == NULL
)
68 cdptr
= &cdline
->Next
;
70 cdline
->Line
= line
= AllocString(newline
);
79 int CheckExtra
= TRUE
;
81 /* '#' in the first column of a line is the command introducer --
82 any number of # symbols, blank spaces and tabs afterwards are
83 skipped for compatibility with CatComp */
85 while(*line
== '#' || *line
== ' ' || *line
== '\t')
90 if(Strnicmp(line
, "language", 8) == 0)
96 Language
= AllocString(line
);
99 for(ptr
= Language
; *ptr
; ptr
++)
101 *ptr
= tolower((int)*ptr
);
106 else if(Strnicmp(line
, "version", 7) == 0)
110 CatVersion
= strtol(line
, &line
, 0);
113 else if(Strnicmp(line
, "basename", 8) == 0)
118 BaseName
= AllocString(line
);
121 else if(Strnicmp(line
, "ifdef", 5) == 0)
125 else if(Strnicmp(line
, "endif", 5) == 0)
129 else if(Strnicmp(line
, "array", 5) == 0)
133 else if(Strnicmp(line
, "header", 6) == 0)
138 HeaderName
= AllocString(line
);
142 else if(Strnicmp(line
, "lengthbytes", 11) == 0)
146 lenbytes
= atoi(line
);
149 else if(Strnicmp(line
, "printf_check_off", 16) == 0)
153 else if(Strnicmp(line
, "printf_check_on", 15) == 0)
159 ShowWarn(MSG_ERR_UNKNOWNCDCOMMAND
);
164 if(CheckExtra
== TRUE
)
169 ShowError(MSG_ERR_EXTRA_CHARACTERS
);
178 /* Check for blanks at the start of line. */
180 if(*line
== ' ' || *line
== '\t')
182 ShowError(MSG_ERR_UNEXPECTEDBLANKS
);
188 while((*line
>= 'a' && *line
<= 'z') ||
189 (*line
>= 'A' && *line
<= 'Z') ||
190 (*line
>= '0' && *line
<= '9') ||
198 ShowError(MSG_ERR_NOIDENTIFIER
);
205 if((cs
= malloc(sizeof(*cs
))) == NULL
)
212 struct CatString
*scs
;
215 for(scs
= FirstCatString
; scs
!= NULL
; scs
= scs
->Next
)
217 if(scs
->ID
== NextID
)
225 while(found
== FALSE
);
231 cs
->CD_Str
= (char *)"";
234 cs
->POformat
= FALSE
;
236 if((cs
->ID_Str
= malloc((line
- idstr
) + 1)) == NULL
)
240 strncpy(cs
->ID_Str
, idstr
, line
- idstr
);
241 cs
->ID_Str
[line
- idstr
] = '\0';
244 /* Check if next char in line is '('? (//) */
248 ShowError(MSG_ERR_NO_LEADING_BRACKET
, cs
->ID_Str
);
254 struct CatString
*scs
;
256 int bytesread
, reallen
;
261 /* Check for default config of line (//) */
267 NextID
= cs
->ID
= NextID
+ strtol(line
, &line
, 0);
269 else if(*line
== '$')
272 cs
->ID
= NextID
= strtol(line
, &line
, 16);
276 cs
->ID
= NextID
= strtol(line
, &line
, 0);
281 /* Check for already used identifier. */
283 for(scs
= FirstCatString
; scs
!= NULL
; scs
= scs
->Next
)
285 if(scs
->ID
== cs
->ID
)
287 ShowError(MSG_ERR_DOUBLE_ID
, cs
->ID_Str
);
290 if(strcmp(cs
->ID_Str
, scs
->ID_Str
) == 0)
292 ShowError(MSG_ERR_DOUBLE_IDENTIFIER
, cs
->ID_Str
);
297 /* Check for min/len values (//) */
301 ShowWarn(MSG_ERR_NO_MIN_LEN
, cs
->ID_Str
);
310 cs
->MinLen
= strtol(line
, &line
, 0);
315 ShowWarn(MSG_ERR_NO_MAX_LEN
, cs
->ID_Str
);
324 cs
->MaxLen
= strtol(line
, &line
, 0);
329 ShowError(MSG_ERR_NO_TRAILING_BRACKET
, cs
->ID_Str
);
338 ShowError(MSG_ERR_EXTRA_CHARACTERS_ID
, cs
->ID_Str
);
344 /* Huh? There is no string for this definition? */
346 if((newline
= ReadLine(fp
, FALSE
)) == FALSE
)
348 ShowWarn(MSG_ERR_MISSINGSTRING
);
350 cs
->CD_Str
= (char *)"";
354 // Check if there are any non-ASCII characters contained in the line.
355 // This will cause a warning only, since non-ASCII characters in the
356 // default language are discouraged.
360 while((c
= *p
++) != '\0')
366 ShowWarn(MSG_ERR_NON_ASCII_CHARACTER
, v
& 0xff, cs
->ID_Str
);
371 cs
->CD_Str
= AllocString(newline
);
375 /* Get string length. */
379 while(*oldstr
!= '\0')
381 bytesread
= ReadChar(&oldstr
, bytes
);
386 reallen
+= bytesread
;
389 /* String too short. */
391 if(cs
->MinLen
> 0 && reallen
< cs
->MinLen
)
393 ShowWarn(MSG_ERR_STRING_TOO_SHORT
, cs
->ID_Str
);
396 /* String too long. */
398 if(cs
->MaxLen
> 0 && reallen
> cs
->MaxLen
)
400 ShowWarn(MSG_ERR_STRING_TOO_LONG
, cs
->ID_Str
);
404 cs
->LenBytes
= lenbytes
;