changeset 1855:a8e41036c0b4

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 02 Nov 2017 12:34:20 +0200
parents 956b12841624
children 6a48bc964b9e
files liblocfile.c
diffstat 1 files changed, 11 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/liblocfile.c	Wed Nov 01 12:57:29 2017 +0200
+++ b/liblocfile.c	Thu Nov 02 12:34:20 2017 +0200
@@ -6,13 +6,14 @@
 #include "liblocfile.h"
 
 
+// Internal parsing context structure
 typedef struct
 {
     LocFileInfo *file;
 
     char *filename;
     FILE *fp;
-    unsigned int lineNum;
+    unsigned int line;
     BOOL versionSet;
     int ch, parseMode, prevMode, nextMode, field, subField, sep;
     char *fieldSep;
@@ -68,7 +69,7 @@
         return;
 
     dst->n = src->n;
-    dst->locations = (LocMarker **) th_calloc(dst->n, sizeof(LocMarker *));
+    dst->locations = (LocMarker **) th_malloc(dst->n * sizeof(LocMarker *));
 
     for (int i = 0; i < dst->n; i++)
         dst->locations[i] = locCopyLocMarker(src->locations[i]);
@@ -212,7 +213,7 @@
 {
     va_list ap;
 
-    fprintf(stderr, "[%s:%d @ %d]: ", ctx->file->filename, ctx->lineNum, ctx->field);
+    fprintf(stderr, "[%s:%d @ %d]: ", ctx->file->filename, ctx->line, ctx->field);
     ctx->parseMode = PM_ERROR;
 
     va_start(ap, fmt);
@@ -570,7 +571,7 @@
 
     memset(&ctx, 0, sizeof(ctx));
     ctx.fp = fp;
-    ctx.lineNum = 1;
+    ctx.line = 1;
     ctx.ch = -1;
     ctx.file = file;
 
@@ -593,7 +594,7 @@
             else
             if (ctx.ch == '\r')
             {
-                ctx.lineNum++;
+                ctx.line++;
                 ctx.ch = locFGetc(&ctx);
                 if (ctx.ch == '\n')
                     ctx.ch = locFGetc(&ctx);
@@ -601,7 +602,7 @@
             else
             if (ctx.ch == '\n')
             {
-                ctx.lineNum++;
+                ctx.line++;
                 ctx.ch = locFGetc(&ctx);
             }
             else
@@ -625,7 +626,7 @@
             {
                 // Syntax error
                 locPMErr(&ctx, "Syntax error in '%s' line #%d.\n",
-                    ctx.filename, ctx.lineNum);
+                    ctx.filename, ctx.line);
             }
             break;
 
@@ -636,13 +637,13 @@
                 ctx.ch = locFGetc(&ctx);
                 if (ctx.ch == '\n')
                     ctx.ch = locFGetc(&ctx);
-                ctx.lineNum++;
+                ctx.line++;
                 ctx.prevMode = ctx.parseMode;
                 ctx.parseMode = ctx.nextMode;
                 break;
             case '\n':
                 ctx.ch = locFGetc(&ctx);
-                ctx.lineNum++;
+                ctx.line++;
                 ctx.prevMode = ctx.parseMode;
                 ctx.parseMode = ctx.nextMode;
                 break;
@@ -723,7 +724,7 @@
                 }
                 else
                 {
-                    ctx.lineNum++;
+                    ctx.line++;
                     ctx.ch = locFGetc(&ctx);
                     if (i == '\r' && ctx.ch == '\n')
                         ctx.ch = locFGetc(&ctx);