"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Resource.c" between
chktex-1.7.6.tar.gz and chktex-1.7.8.tar.gz

About: ChkTeX is a LaTeX semantic checker.

Resource.c  (chktex-1.7.6):Resource.c  (chktex-1.7.8)
skipping to change at line 92 skipping to change at line 92
#undef BIT #undef BIT
#define BIT BITDEF1 #define BIT BITDEF1
TOKENBITS(Token_BIT); TOKENBITS(Token_BIT);
#undef BIT #undef BIT
#define BIT BITDEF2 #define BIT BITDEF2
TOKENBITS(Token); TOKENBITS(Token);
static enum Token Expect; static enum Token Expect;
static unsigned long RsrcLine; static unsigned long RsrcLine;
static enum Token ReadWord(char *, FILE *); static enum Token ReadWord(char *, FILE *,
char *(fgetsfun)(char *, int, FILE *));
static char MapChars(char **String); static char MapChars(char **String);
/* /*
* Parses the contents of a resource file. * Parses the contents of a resource file.
* *
* Format: * Format:
* Keyword { item1 item2 ... } [ item1 item2 ... ] * Keyword { item1 item2 ... } [ item1 item2 ... ]
* Keyword [ item1 item2 ... ] { item1 item2 ... } * Keyword [ item1 item2 ... ] { item1 item2 ... }
* Keyword = { item1 item2 ... } * Keyword = { item1 item2 ... }
* Keyword = [ item1 item2 ... ] * Keyword = [ item1 item2 ... ]
* Keyword = item * Keyword = item
* *
* Returns whether the attempt was a successful one. * Returns whether the attempt was a successful one.
*/ */
int ReadRC(const char *Filename) int ProcessRC(FILE *fh, const char *Filename,
char *(fgetsfun)(char *, int, FILE *))
{ {
const char *String = NULL; const char *String = NULL;
int Success = FALSE; int Success = TRUE;
FILE *fh;
enum Token Token; enum Token Token;
unsigned long Counter; unsigned long Counter;
struct KeyWord *CurWord = NULL; struct KeyWord *CurWord = NULL;
/* Interpret incoming words as ... */ /* Interpret incoming words as ... */
enum enum
{ {
whList, /* List elements */ whList, /* List elements */
whCaseList, /* Case insensitive list elements */ whCaseList, /* Case insensitive list elements */
whEqual, /* Solo elements */ whEqual, /* Solo elements */
whNone /* List items not accepted */ whNone /* List items not accepted */
} What = whNone; } What = whNone;
RsrcLine = 0; RsrcLine = 0;
Expect = FLG_Word | FLG_Eof; Expect = FLG_Word | FLG_Eof;
do
if ((fh = fopen(Filename, "r")))
{ {
Success = TRUE; Token = ReadWord(ReadBuffer, fh, fgetsfun);
do if (!(Expect & Token))
{
switch (Token)
{
case FLG_Item:
String = "item";
break;
case FLG_Word:
String = "word";
break;
case FLG_Equal:
String = "`='";
break;
case FLG_Open:
String = "`{'";
break;
case FLG_Close:
String = "`}'";
break;
case FLG_BrOpen:
String = "`['";
break;
case FLG_BrClose:
String = "`]'";
break;
case FLG_Eof:
String = "EOF";
break;
}
PrintPrgErr(pmFaultFmt, Filename, RsrcLine, String);
Success = FALSE;
Token = FLG_Eof;
}
switch (Token)
{ {
Token = ReadWord(ReadBuffer, fh); case FLG_Word:
if (!(Expect & Token)) for (Counter = 0; Keys[Counter].Name; Counter++)
{ {
switch (Token) if (!strcasecmp(ReadBuffer, Keys[Counter].Name))
{ {
case FLG_Item: CurWord = &Keys[Counter];
String = "item"; Expect = (CurWord->List ? FLG_Open : 0) |
break; (CurWord->CaseList ? FLG_BrOpen : 0) | FLG_Equal;
case FLG_Word:
String = "word";
break;
case FLG_Equal:
String = "`='";
break;
case FLG_Open:
String = "`{'";
break;
case FLG_Close:
String = "`}'";
break;
case FLG_BrOpen:
String = "`['";
break;
case FLG_BrClose:
String = "`]'";
break;
case FLG_Eof:
String = "EOF";
break; break;
} }
PrintPrgErr(pmFaultFmt, Filename, RsrcLine, String); }
if (!Keys[Counter].Name)
{
PrintPrgErr(pmKeyWord, ReadBuffer, Filename);
Success = FALSE; Success = FALSE;
Token = FLG_Eof; Token = FLG_Eof;
} }
break;
switch (Token) case FLG_Item:
switch (What)
{ {
case FLG_Word: case whEqual:
for (Counter = 0; Keys[Counter].Name; Counter++) if (!(*(CurWord->String) = strdup(ReadBuffer)))
{ {
if (!strcasecmp(ReadBuffer, Keys[Counter].Name)) PrintPrgErr(pmStrDupErr);
{ Token = FLG_Eof;
CurWord = &Keys[Counter]; Success = FALSE;
Expect = (CurWord->List ? FLG_Open : 0) |
(CurWord->CaseList ? FLG_BrOpen : 0) | FLG_Equal;
break;
}
} }
if (!Keys[Counter].Name)
What = whNone;
Expect = FLG_Word | FLG_Eof;
break;
case whCaseList:
if (!InsertWord(ReadBuffer, CurWord->CaseList))
{ {
PrintPrgErr(pmKeyWord, ReadBuffer, Filename);
Success = FALSE;
Token = FLG_Eof; Token = FLG_Eof;
Success = FALSE;
} }
break; break;
case FLG_Item: case whList:
switch (What) if (!InsertWord(ReadBuffer, CurWord->List))
{ {
case whEqual: Token = FLG_Eof;
if (!(*(CurWord->String) = strdup(ReadBuffer))) Success = FALSE;
{
PrintPrgErr(pmStrDupErr);
Token = FLG_Eof;
Success = FALSE;
}
What = whNone;
Expect = FLG_Word | FLG_Eof;
break;
case whCaseList:
if (!InsertWord(ReadBuffer, CurWord->CaseList))
{
Token = FLG_Eof;
Success = FALSE;
}
break;
case whList:
if (!InsertWord(ReadBuffer, CurWord->List))
{
Token = FLG_Eof;
Success = FALSE;
}
break;
case whNone:
PrintPrgErr(pmAssert);
} }
break; break;
case FLG_Equal: case whNone:
What = whEqual; PrintPrgErr(pmAssert);
Expect = (CurWord->List ? FLG_Open : 0) |
(CurWord->CaseList ? FLG_BrOpen : 0) |
(CurWord->String ? FLG_Item : 0);
break;
case FLG_BrOpen:
if (What == whEqual)
ClearWord(CurWord->CaseList);
What = whCaseList;
Expect = FLG_Item | FLG_BrClose;
break;
case FLG_Open:
if (What == whEqual)
ClearWord(CurWord->List);
What = whList;
Expect = FLG_Item | FLG_Close;
break;
case FLG_BrClose:
case FLG_Close:
Expect = (CurWord->List ? FLG_Open : 0) |
(CurWord->CaseList ? FLG_BrOpen : 0) |
FLG_Equal | FLG_Word | FLG_Eof;
What = whNone;
break;
case FLG_Eof:
break;
} }
break;
case FLG_Equal:
What = whEqual;
Expect = (CurWord->List ? FLG_Open : 0) |
(CurWord->CaseList ? FLG_BrOpen : 0) |
(CurWord->String ? FLG_Item : 0);
break;
case FLG_BrOpen:
if (What == whEqual)
ClearWord(CurWord->CaseList);
What = whCaseList;
Expect = FLG_Item | FLG_BrClose;
break;
case FLG_Open:
if (What == whEqual)
ClearWord(CurWord->List);
What = whList;
Expect = FLG_Item | FLG_Close;
break;
case FLG_BrClose:
case FLG_Close:
Expect = (CurWord->List ? FLG_Open : 0) |
(CurWord->CaseList ? FLG_BrOpen : 0) | FLG_Equal | FLG_Word |
FLG_Eof;
What = whNone;
break;
case FLG_Eof:
break;
} }
while (Token != FLG_Eof); } while (Token != FLG_Eof);
return (Success);
}
/*
* Opens a file and passes to ProcessRC().
*/
int ReadRC(const char *Filename)
{
int Success = FALSE;
FILE *fh;
if ((fh = fopen(Filename, "r")))
{
Success = ProcessRC(fh, Filename, &fgets);
fclose(fh); fclose(fh);
} }
else else
PrintPrgErr(pmRsrcOpen, Filename); PrintPrgErr(pmRsrcOpen, Filename);
return (Success); return (Success);
} }
const char *FGETS_TMP = NULL;
char *fgets_from_string(char *out, int size, FILE *fh)
{
char *res;
if (FGETS_TMP == NULL)
return NULL;
res = strncpy(out, FGETS_TMP, size - 1);
if (size - 1 < strlen(FGETS_TMP))
{
/* It wasn't all read, so null terminate it, and get ready for
* next time. */
res[size] = '\0';
FGETS_TMP = FGETS_TMP + (size - 1);
}
else
{
/* We're done, so signal that */
FGETS_TMP = NULL;
}
return res;
}
/*
* Opens a file and passes to ProcessRC().
*/
int ReadRCFromCmdLine(const char *CmdLineArg)
{
if (!CmdLineArg)
return FALSE;
FGETS_TMP = CmdLineArg;
return ProcessRC(NULL, "CommandLineArg", &fgets_from_string);
}
/* /*
* Reads a token from the `.chktexrc' file; if the token is * Reads a token from the `.chktexrc' file; if the token is
* FLG_Item or FLG_Word, Buffer will contain the plaintext of the * FLG_Item or FLG_Word, Buffer will contain the plaintext of the
* token. If not, the contents are undefined. * token. If not, the contents are undefined.
*/ */
static enum Token ReadWord(char *Buffer, FILE * fh) static enum Token ReadWord(char *Buffer, FILE *fh,
char *(fgetsfun)(char *, int, FILE *))
{ {
static char *String = NULL; static char *String = NULL;
static char StatBuf[BUFSIZ]; static char StatBuf[BUFFER_SIZE];
enum Token Retval = FLG_Eof; enum Token Retval = FLG_Eof;
unsigned short Chr; unsigned short Chr;
char *Ptr; char *Ptr;
int OnceMore = TRUE, Cont = TRUE; int OnceMore = TRUE, Cont = TRUE;
if (Buffer) if (Buffer)
{ {
do do
{ {
if (!(String && *String)) if (!(String && *String))
{ {
if (fgets(StatBuf, BUFSIZ - 1, fh)) if ((fgetsfun)(StatBuf, BUFFER_SIZE - 1, fh))
String = strip(StatBuf, STRP_RGT); String = strip(StatBuf, STRP_RGT);
RsrcLine++; RsrcLine++;
} }
Ptr = Buffer; Ptr = Buffer;
if (String && (String = strip(String, STRP_LFT))) if (String && (String = strip(String, STRP_LFT)))
{ {
switch (Chr = *String) switch (Chr = *String)
{ {
case 0: case 0:
 End of changes. 25 change blocks. 
109 lines changed or deleted 154 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)