From 6b983079b7a92f9e7af9367df39836b47922f97d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 4 Oct 2018 04:47:20 +0200 Subject: [PATCH] remember to set faction.lastorders (NMR count was off). checker just removes comments now. --- src/checker.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- src/orderfile.c | 5 ++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/checker.c b/src/checker.c index 302c80390..f87b91891 100644 --- a/src/checker.c +++ b/src/checker.c @@ -2,10 +2,50 @@ #include #endif -#include "util/parser.h" +#include "util/order_parser.h" #include +typedef struct parser_state { + FILE * F; +} parser_state; + +static void handle_order(void *userData, const char *str) { + parser_state * state = (parser_state*)userData; + fputs(str, state->F); + fputc('\n', state->F); +} + +int parsefile(FILE *F) { + OP_Parser parser; + char buf[1024]; + int done = 0, err = 0; + parser_state state = { NULL }; + + state.F = stdout; + + parser = OP_ParserCreate(); + OP_SetOrderHandler(parser, handle_order); + OP_SetUserData(parser, &state); + + while (!done) { + size_t len = (int)fread(buf, 1, sizeof(buf), F); + if (ferror(F)) { + /* TODO: error message */ + err = errno; + break; + } + done = feof(F); + if (OP_Parse(parser, buf, len, done) == OP_STATUS_ERROR) { + /* TODO: error message */ + err = (int)OP_GetErrorCode(parser); + break; + } + } + OP_ParserFree(parser); + return err; +} + int main(int argc, char **argv) { FILE * F = stdin; if (argc >= 1) { @@ -15,8 +55,10 @@ int main(int argc, char **argv) { perror(filename); return -1; } + } + parsefile(F); + if (F != stdin) { fclose(F); } return 0; } - diff --git a/src/orderfile.c b/src/orderfile.c index 1677321eb..90b44477b 100644 --- a/src/orderfile.c +++ b/src/orderfile.c @@ -245,7 +245,10 @@ static void handle_faction(void *userData, int no, const char *password) { log_debug("orders for unknown faction %s", itoa36(no)); } else { - if (!checkpasswd(f, password)) { + if (checkpasswd(f, password)) { + f->lastorders = turn; + } + else { log_debug("invalid password for faction %s", itoa36(no)); ADDMSG(&f->msgs, msg_message("wrongpasswd", "password", password)); }