bug-mes
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-mes] constant error messages in hex2_linker


From: Jan Nieuwenhuizen
Subject: [bug-mes] constant error messages in hex2_linker
Date: Sat, 23 Feb 2019 09:42:56 +0100

Hi,

The hex2_linker currently produces constant error messages.  Here's an
ugly fix for one that bit me.

How to clean this up (and fix other constant error messages in a nice
way)?

Greetings,
janneke

>From c74ebc654830926837654e16caf4b278a5051eb2 Mon Sep 17 00:00:00 2001
From: Jan Nieuwenhuizen <address@hidden>
Date: Sat, 23 Feb 2019 09:33:26 +0100
Subject: [PATCH] hex2_linker: Make error message non-constant, in a very ugly
 way.

---
 hex2_linker.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/hex2_linker.c b/hex2_linker.c
index 5e5bd43..8b00ed0 100644
--- a/hex2_linker.c
+++ b/hex2_linker.c
@@ -30,6 +30,8 @@
 #define FALSE 0
 //CONSTANT FALSE 0
 
+int line = 1;
+
 void file_print(char* s, FILE* f);
 int match(char* a, char* b);
 char* numerate_number(int a);
@@ -40,8 +42,11 @@ struct input_files
 {
        struct input_files* next;
        char* filename;
+       int line;
 };
 
+struct input_files* input = NULL;
+
 struct entry
 {
        struct entry* next;
@@ -66,6 +71,8 @@ int consume_token(FILE* source_file)
        int c = fgetc(source_file);
        while(!in_set(c, " \t\n>"))
        {
+               if (c == '\n')
+                       line = line + 1;
                scratch[i] = c;
                i = i + 1;
                c = fgetc(source_file);
@@ -81,6 +88,8 @@ int Throwaway_token(FILE* source_file)
        {
                c = fgetc(source_file);
        } while(!in_set(c, " \t\n>"));
+       if (c == '\n')
+               line = line + 1;
 
        return c;
 }
@@ -235,7 +244,12 @@ int Architectural_displacement(int target, int base)
                }
                if (target & 3)
                {
-                       file_print("Unaligned branch target, aborting\n", 
stderr);
+                       file_print(input->filename, stderr);
+                       file_print(":", stderr);
+                       file_print(numerate_number (line), stderr);
+                       file_print(":error: Unaligned branch target, scratch=", 
stderr);
+                       file_print(scratch, stderr);
+                       file_print("\n", stderr);
                        exit(EXIT_FAILURE);
                }
                /*
@@ -444,6 +458,7 @@ void first_pass(struct input_files* input)
        if(NULL == input) return;
        first_pass(input->next);
        FILE* source_file = fopen(input->filename, "r");
+       line = 1;
 
        if(NULL == source_file)
        {
@@ -492,6 +507,7 @@ void second_pass(struct input_files* input)
        if(NULL == input) return;
        second_pass(input->next);
        FILE* source_file = fopen(input->filename, "r");
+       line = 1;
 
        /* Something that should never happen */
        if(NULL == source_file)
@@ -526,7 +542,6 @@ int main(int argc, char **argv)
        jump_table = NULL;
        Architecture = 0;
        Base_Address = 0;
-       struct input_files* input = NULL;
        output = stdout;
        char* output_file = "";
        exec_enable = FALSE;
-- 
2.20.1

-- 
Jan Nieuwenhuizen <address@hidden> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | AvatarĀ® http://AvatarAcademy.com

reply via email to

[Prev in Thread] Current Thread [Next in Thread]