1997-11-11 00:52:10 -05:00
|
|
|
#include <stdio.h>
|
1997-12-10 02:44:19 -05:00
|
|
|
#include <string.h>
|
1997-11-11 00:52:10 -05:00
|
|
|
#include "wfcheck.h"
|
1997-11-14 19:37:29 -05:00
|
|
|
#include "filemap.h"
|
1997-12-13 04:11:15 -05:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#include <crtdbg.h>
|
|
|
|
#endif
|
1997-11-11 00:52:10 -05:00
|
|
|
|
1997-12-10 02:44:19 -05:00
|
|
|
struct ProcessFileArg {
|
|
|
|
enum EntityType entityType;
|
|
|
|
int result;
|
|
|
|
};
|
|
|
|
|
1997-11-11 00:52:10 -05:00
|
|
|
static
|
1997-12-10 02:44:19 -05:00
|
|
|
void processFile(const void *data, size_t size, const char *filename, void *p)
|
1997-11-11 00:52:10 -05:00
|
|
|
{
|
1997-11-12 05:38:58 -05:00
|
|
|
const char *badPtr = 0;
|
|
|
|
unsigned long badLine = 0;
|
|
|
|
unsigned long badCol = 0;
|
1997-12-10 02:44:19 -05:00
|
|
|
struct ProcessFileArg *arg = p;
|
1997-11-11 00:52:10 -05:00
|
|
|
enum WfCheckResult result;
|
|
|
|
|
1997-12-10 02:44:19 -05:00
|
|
|
result = wfCheck(arg->entityType, data, size, &badPtr, &badLine, &badCol);
|
1997-11-11 00:52:10 -05:00
|
|
|
if (result) {
|
1997-12-10 02:44:19 -05:00
|
|
|
const char *msg = wfCheckMessage(result);
|
|
|
|
fprintf(stdout, "%s:", filename);
|
1997-11-12 05:38:58 -05:00
|
|
|
if (badPtr != 0)
|
1997-12-10 02:44:19 -05:00
|
|
|
fprintf(stdout, "%lu:%lu:", badLine+1, badCol);
|
|
|
|
fprintf(stdout, "E: %s", msg ? msg : "(unknown message)");
|
|
|
|
putc('\n', stdout);
|
|
|
|
arg->result = 1;
|
1997-11-11 00:52:10 -05:00
|
|
|
}
|
1997-12-10 02:44:19 -05:00
|
|
|
else
|
|
|
|
arg->result = 0;
|
1997-11-11 00:52:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
1997-12-10 02:44:19 -05:00
|
|
|
int i = 1;
|
1997-11-11 00:52:10 -05:00
|
|
|
int ret = 0;
|
1997-12-10 02:44:19 -05:00
|
|
|
struct ProcessFileArg arg;
|
|
|
|
|
1997-12-13 04:11:15 -05:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
|
|
|
|
#endif
|
1997-12-10 02:44:19 -05:00
|
|
|
arg.entityType = documentEntity;
|
|
|
|
|
|
|
|
if (i < argc && strcmp(argv[i], "-g") == 0) {
|
|
|
|
i++;
|
|
|
|
arg.entityType = generalTextEntity;
|
|
|
|
}
|
|
|
|
if (i < argc && strcmp(argv[i], "--") == 0)
|
|
|
|
i++;
|
|
|
|
if (i == argc) {
|
|
|
|
fprintf(stderr, "usage: %s [-g] filename ...\n", argv[0]);
|
1997-11-11 00:52:10 -05:00
|
|
|
return 1;
|
|
|
|
}
|
1997-12-10 02:44:19 -05:00
|
|
|
for (; i < argc; i++) {
|
|
|
|
if (!filemap(argv[i], processFile, &arg))
|
1997-11-14 19:37:29 -05:00
|
|
|
ret = 2;
|
1997-12-10 02:44:19 -05:00
|
|
|
else if (arg.result && !ret)
|
|
|
|
ret = 1;
|
1997-11-11 00:52:10 -05:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|