Added error messages displaying using source file name and line number
[zilutils.git] / zilasm / main.cpp
index 22b7e7145c09d8642fe8df92455ebae9b11d26ec..68846b03da7fb491cf82c6861d67baf59a8bdc8b 100644 (file)
@@ -2,7 +2,7 @@
  * main.c
  *
  * Copyright (C) 2015 Alexander Andrejevic <theflash AT sdf DOT lonestar DOT org>
- * Copyright (C) 2015, 2019 Jason Self <j@jxself.org>
+ * Copyright (C) 2015, 2019, 2020 Jason Self <j@jxself.org>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
+#include <string>
+#include <list>
+#include <stack>
+using namespace std;
+
+
 extern "C"
 {
 #include <strings.h>
@@ -39,9 +45,7 @@ extern "C"
 }
 #include "parser.h"
 
-#include <string>
-#include <list>
-using namespace std;
+
 
 const int DEFAULT_ZVERSION = 6;
 
@@ -143,7 +147,7 @@ CMain::assembly ()
       ++m_code_size;
 
       // write instructions' codes
-      for (int i = 0; i < g_numberOfInstructions; ++i)
+      for (int i = 0; i < g_number_of_instructions; ++i)
        {
          for (int j = 0; j < g_codes[i]->used_size; ++j)
            {
@@ -424,9 +428,33 @@ main (int argc, char *argv[], char *envp[])
 
   init_parser ();
 
-  for (int i = optind; i < argc; i++)
-    parse_file (argv[i]);
-  main.assembly ();
+       //for (int i = optind; i < argc; i++)
+       //      parse_file(argv[i]);
+  
+  string file_name = argv[optind];
+  Parsing_Context pc;
+
+#ifdef WIN32
+  char delimeter = '\\';
+#else
+  char delimeter = '/';
+#endif
+
+  if (file_name.rfind(delimeter) == string::npos)
+  {
+         pc.current_directory = "";
+         pc.current_file_name = file_name;
+  }
+  else
+  {
+         pc.current_directory = file_name.substr(0, file_name.rfind(delimeter)+1);
+         pc.current_file_name = file_name.substr(file_name.rfind(delimeter)+1);
+  }
+  g_parsing_contexts.push(pc);
+
+  parse_file();// argv[optind]);
+  if ( !g_haveErrors )
+       main.assembly ();
 
   /* TODO! List global symbols */
   /* TODO! Find abbreviations */