#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <assert.h>
-#include "../pp/sl_pp_purify.h"
-#include "../pp/sl_pp_version.h"
+#include "../pp/sl_pp_public.h"
int
long size;
char *inbuf;
struct sl_pp_purify_options options;
- char *outbuf;
+ char errmsg[100] = "";
+ unsigned int errline = 0;
+ struct sl_pp_context *context;
struct sl_pp_token_info *tokens;
unsigned int version;
unsigned int tokens_eaten;
size = ftell(in);
fseek(in, 0, SEEK_SET);
+ out = fopen(argv[2], "wb");
+ if (!out) {
+ fclose(in);
+ return 1;
+ }
+
inbuf = malloc(size + 1);
if (!inbuf) {
+ fprintf(out, "$OOMERROR\n");
+
+ fclose(out);
fclose(in);
return 1;
}
if (fread(inbuf, 1, size, in) != size) {
+ fprintf(out, "$READERROR\n");
+
free(inbuf);
+ fclose(out);
fclose(in);
return 1;
}
memset(&options, 0, sizeof(options));
- if (sl_pp_purify(inbuf, &options, &outbuf)) {
+ context = sl_pp_context_create();
+ if (!context) {
+ fprintf(out, "$CONTEXERROR\n");
+
free(inbuf);
+ fclose(out);
return 1;
}
- free(inbuf);
+ if (sl_pp_tokenise(context, inbuf, &options, &tokens)) {
+ fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context));
- if (sl_pp_tokenise(outbuf, &tokens)) {
- free(outbuf);
+ sl_pp_context_destroy(context);
+ free(inbuf);
+ fclose(out);
return 1;
}
- free(outbuf);
+ free(inbuf);
- if (sl_pp_version(tokens, &version, &tokens_eaten)) {
+ if (sl_pp_version(context, tokens, &version, &tokens_eaten)) {
+ fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context));
+
+ sl_pp_context_destroy(context);
free(tokens);
+ fclose(out);
return -1;
}
+ sl_pp_context_destroy(context);
free(tokens);
- out = fopen(argv[2], "wb");
- if (!out) {
- return 1;
- }
-
- fprintf(out, "%u\n", version);
+ fprintf(out,
+ "%u\n%u\n",
+ version,
+ tokens_eaten);
fclose(out);