main.cc
changeset 136 32bd7ef40897
parent 47 017efb738d95
child 139 668a54686827
equal deleted inserted replaced
135:0f3f6714b938 136:32bd7ef40897
    78 }
    78 }
    79 
    79 
    80 
    80 
    81 
    81 
    82 /* forward declarations... */
    82 /* forward declarations... */
    83 int stage1_2(const char *filename, const char *includedir, symbol_c **tree_root);
    83 int stage1_2(const char *filename, const char *includedir, symbol_c **tree_root, bool full);
    84 //int stage3(symbol_c *tree_root);
    84 //int stage3(symbol_c *tree_root);
    85 int stage4(symbol_c *tree_root, const char *builddir);
    85 int stage4(symbol_c *tree_root, const char *builddir);
    86 
    86 
    87 
    87 
    88 static void printusage(const char *cmd) {
    88 static void printusage(const char *cmd) {
    89   printf("%s [<input_file>] [-I <include_directory>] [<target_directory>]\n", cmd);
    89   printf("syntaxe: %s [-fh] <input_file> [-I <include_directory>] [<target_directory>]\n", cmd);
       
    90   printf("  f : full token location on error messages\n");
       
    91   printf("  h : show this help message\n");
    90 }
    92 }
    91 
    93 
    92 
    94 
    93 
    95 
    94 int main(int argc, char **argv) {
    96 int main(int argc, char **argv) {
    95   symbol_c *tree_root;
    97   symbol_c *tree_root;
    96   char * includedir = NULL;
    98   char * includedir = NULL;
    97   char * builddir = NULL;
    99   char * builddir = NULL;
       
   100   bool full = false;
       
   101   int offset = 0; 
    98 
   102 
    99   if (argc == 5) {
   103   if (argc < 2 || argc > 6) {
   100     builddir = argv[4];
       
   101     argc = 4;
       
   102   }
       
   103 
       
   104   if (argc == 4) {
       
   105     if (strcmp(argv[2], "-I") != 0) {
       
   106       printusage(argv[0]);
       
   107       return EXIT_FAILURE;
       
   108     }
       
   109     includedir = argv[3];
       
   110     argc = 2;
       
   111   }
       
   112 
       
   113   if (argc == 3) {
       
   114     builddir = argv[2];
       
   115     argc = 2;
       
   116   }    
       
   117 
       
   118   if (argc != 2) {
       
   119     printusage(argv[0]);
   104     printusage(argv[0]);
   120     return EXIT_FAILURE;
   105     return EXIT_FAILURE;
   121   }
   106   }
   122 
   107 
       
   108   if (strcmp(argv[1], "-h") == 0) {
       
   109     printusage(argv[0]);
       
   110     return 0;
       
   111   }
       
   112 
       
   113   if (strcmp(argv[1], "-f") == 0) {
       
   114     if (argc == 2) {
       
   115       printusage(argv[0]);
       
   116       return EXIT_FAILURE;
       
   117     }
       
   118     full = true;
       
   119     offset = 1;
       
   120   }
       
   121     
       
   122   if (argc == (5 + offset)) {
       
   123     builddir = argv[4 + offset];
       
   124     argc = 4 + offset;
       
   125   }
       
   126 
       
   127   if (argc == (4 + offset)) {
       
   128     if (strcmp(argv[2 + offset], "-I") != 0) {
       
   129       printusage(argv[0]);
       
   130       return EXIT_FAILURE;
       
   131     }
       
   132     includedir = argv[3 + offset];
       
   133     argc = 2 + offset;
       
   134   }
       
   135 
       
   136   if (argc == (3 + offset)) {
       
   137     builddir = argv[2 + offset];
       
   138     argc = 2 + offset;
       
   139   }    
       
   140 
   123   /* 1st Pass */
   141   /* 1st Pass */
   124   if (stage1_2(argv[1], includedir, &tree_root) < 0)
   142   if (stage1_2(argv[1 + offset], includedir, &tree_root, full) < 0)
   125     return EXIT_FAILURE;
   143     return EXIT_FAILURE;
   126 
   144 
   127   /* 2nd Pass */
   145   /* 2nd Pass */
   128   /* not yet implemented... */
   146   /* not yet implemented... */
   129   /*
   147   /*