63 //#include <stdio.h> // printf() |
63 //#include <stdio.h> // printf() |
64 #include <string.h> |
64 #include <string.h> |
65 #include <stdlib.h> // EXIT_FAILURE |
65 #include <stdlib.h> // EXIT_FAILURE |
66 #include "absyntax/absyntax.hh" // symbol_c type |
66 #include "absyntax/absyntax.hh" // symbol_c type |
67 |
67 |
68 |
|
69 |
|
70 |
|
71 /* A macro for printing out internal parser errors... */ |
68 /* A macro for printing out internal parser errors... */ |
72 #include <iostream> // required for std::cerr |
69 #include <iostream> // required for std::cerr |
73 #define ERROR error_exit(__FILE__,__LINE__) |
70 #define ERROR error_exit(__FILE__,__LINE__) |
74 void error_exit(const char *file_name, int line_no) { |
71 void error_exit(const char *file_name, int line_no) { |
75 std::cerr << "\nInternal program error in file " << file_name |
72 std::cerr << "\nInternal program error in file " << file_name |
77 exit(EXIT_FAILURE); |
74 exit(EXIT_FAILURE); |
78 } |
75 } |
79 |
76 |
80 |
77 |
81 |
78 |
82 /* forward declarations... */ |
79 |
83 int stage1_2(const char *filename, const char *includedir, symbol_c **tree_root, bool full); |
80 #include "stage1_2/stage1_2.hh" |
|
81 |
84 //int stage3(symbol_c *tree_root); |
82 //int stage3(symbol_c *tree_root); |
85 int stage4(symbol_c *tree_root, const char *builddir); |
83 int stage4(symbol_c *tree_root, const char *builddir); |
86 |
84 |
87 |
85 |
88 static void printusage(const char *cmd) { |
86 static void printusage(const char *cmd) { |
89 printf("syntaxe: %s [-fh] <input_file> [-I <include_directory>] [<target_directory>]\n", cmd); |
87 printf("syntax: %s [-h] [-f] [-s] [-I <include_directory>] [-T <target_directory>] <input_file>\n", cmd); |
|
88 printf(" h : show this help message\n"); |
90 printf(" f : full token location on error messages\n"); |
89 printf(" f : full token location on error messages\n"); |
91 printf(" h : show this help message\n"); |
90 /******************************************************/ |
|
91 /* whether we are suporting safe extensions */ |
|
92 /* as defined in PLCopen - Technical Committee 5 */ |
|
93 /* Safety Software Technical Specification, */ |
|
94 /* Part 1: Concepts and Function Blocks, */ |
|
95 /* Version 1.0 – Official Release */ |
|
96 /******************************************************/ |
|
97 printf(" s : allow use of safe extensions\n"); |
92 } |
98 } |
93 |
99 |
94 |
100 |
95 |
101 |
96 int main(int argc, char **argv) { |
102 int main(int argc, char **argv) { |
97 symbol_c *tree_root; |
103 symbol_c *tree_root; |
98 char * includedir = NULL; |
|
99 char * builddir = NULL; |
104 char * builddir = NULL; |
100 bool full = false; |
105 stage1_2_options_t stage1_2_options = {false, false, NULL}; |
101 int offset = 0; |
106 int optres, errflg = 0; |
|
107 /* |
|
108 extern char *optarg; |
|
109 extern int optind, optopt; |
|
110 */ |
102 |
111 |
103 if (argc < 2 || argc > 6) { |
112 while ((optres = getopt(argc, argv, ":hfsI:T:")) != -1) { |
104 printusage(argv[0]); |
113 switch(optres) { |
105 return EXIT_FAILURE; |
114 case 'h': |
|
115 printusage(argv[0]); |
|
116 return 0; |
|
117 break; |
|
118 case 'f': |
|
119 stage1_2_options.full_token_loc = true; |
|
120 break; |
|
121 case 's': |
|
122 stage1_2_options.safe_extensions = true; |
|
123 break; |
|
124 case 'I': |
|
125 stage1_2_options.includedir = optarg; |
|
126 break; |
|
127 case ':': /* -I or -T without operand */ |
|
128 fprintf(stderr, "Option -%c requires an operand\n", optopt); |
|
129 errflg++; |
|
130 break; |
|
131 case '?': |
|
132 default: |
|
133 fprintf(stderr, "Unrecognized option: -%c\n", optopt); |
|
134 errflg++; |
|
135 break; |
|
136 } |
106 } |
137 } |
107 |
138 |
108 if (strcmp(argv[1], "-h") == 0) { |
139 if (optind == argc) { |
109 printusage(argv[0]); |
140 fprintf(stderr, "Missing input file\n"); |
110 return 0; |
141 errflg++; |
111 } |
142 } |
112 |
143 |
113 if (strcmp(argv[1], "-f") == 0) { |
144 if (optind > argc) { |
114 if (argc == 2) { |
145 fprintf(stderr, "Too many input files\n"); |
|
146 errflg++; |
|
147 } |
|
148 |
|
149 if (errflg) { |
115 printusage(argv[0]); |
150 printusage(argv[0]); |
116 return EXIT_FAILURE; |
151 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 } |
152 } |
126 |
153 |
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 |
154 |
141 /* 1st Pass */ |
155 /* 1st Pass */ |
142 if (stage1_2(argv[1 + offset], includedir, &tree_root, full) < 0) |
156 if (stage1_2(argv[optind], &tree_root, stage1_2_options) < 0) |
143 return EXIT_FAILURE; |
157 return EXIT_FAILURE; |
144 |
158 |
145 /* 2nd Pass */ |
159 /* 2nd Pass */ |
146 /* not yet implemented... */ |
160 /* not yet implemented... */ |
147 /* |
161 /* |