Commit | Line | Data |
---|---|---|
970ed795 | 1 | /****************************************************************************** |
d44e3c4f | 2 | * Copyright (c) 2000-2016 Ericsson Telecom AB |
970ed795 EL |
3 | * All rights reserved. This program and the accompanying materials |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
d44e3c4f | 7 | * |
8 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Beres, Szabolcs | |
11 | * Raduly, Csaba | |
12 | * Szabados, Kristof | |
13 | * Szabo, Janos Zoltan – initial implementation | |
14 | * Zalanyi, Balazs Andor | |
15 | * | |
970ed795 EL |
16 | ******************************************************************************/ |
17 | %option noyywrap | |
18 | %option yylineno | |
19 | %option never-interactive | |
20 | %option nounput | |
21 | %{ | |
22 | ||
23 | /* #define CHK_ACCESS */ | |
24 | #include <string.h> | |
25 | #include <stdlib.h> | |
26 | #include <sys/types.h> | |
27 | #include <sys/stat.h> | |
28 | #include <errno.h> | |
29 | #include "../common/version_internal.h" | |
30 | #include "repgen.h" | |
31 | ||
32 | #ifdef LICENSE | |
33 | #include "../common/license.h" | |
34 | #endif | |
35 | ||
36 | #define T_TITLE 199 | |
37 | #define T_NAME 200 | |
38 | #define T_SHORT 201 | |
39 | #define T_LONG 202 | |
40 | #define T_STR 203 | |
41 | #define T_CODE 204 | |
42 | #define T_LOGS 205 | |
43 | #define T_DUMP 206 | |
44 | #define T_DEST 207 | |
45 | #define T_TABLEN 208 | |
46 | #define T_FILLCOL 209 | |
47 | #define T_ERROR 210 | |
48 | ||
49 | int token, tok; | |
50 | struct listentry *first, *tclist; | |
51 | char *str; | |
52 | static char title[MAXLEN]; | |
53 | static char code_srcdir[MAXLEN], log_srcdir[MAXLEN], dump_srcdir[MAXLEN]; | |
54 | static char tcname[MAXLEN], dstdir[MAXLEN]; | |
55 | static int tablen, fillcol; | |
56 | char ch; | |
57 | %} | |
58 | ||
59 | %x PP TITLE NAME SHORT LONG CODE LOGS DUMP DEST TABLEN FILLCOL ERROR | |
60 | ||
61 | digit [0-9] | |
62 | octdigit [0-7] | |
63 | hexdigit [0-9a-fA-F] | |
64 | digits {digit}+ | |
65 | alpha [a-zA-Z_] | |
66 | alphanum {alpha}|{digit} | |
67 | whitespace [ \t\f\v] | |
68 | allwhite [ \t\f\b\v\r\n] | |
69 | whitespace2 [ \t\f\v] | |
70 | path [./~a-zA-Z_0-9\-] | |
71 | ||
72 | pp_title ^{allwhite}*"#Title"{allwhite}* | |
73 | pp_name ^{allwhite}*"#Testcase"{allwhite}* | |
74 | pp_short ^{allwhite}*"#Purpose"{whitespace}*[\n]* | |
75 | pp_long ^{allwhite}*"#Description"{whitespace}*[\n]* | |
76 | pp_code ^{allwhite}*"#TTCN-3 code"{allwhite}* | |
77 | pp_logs ^{allwhite}*"#TTCN-3 log"{allwhite}* | |
78 | pp_dump ^{allwhite}*"#Other log"{allwhite}* | |
79 | pp_dest ^{allwhite}*"#Destination"{allwhite}* | |
80 | pp_tablen ^{allwhite}*"#Tab length"{allwhite}* | |
81 | pp_fillcol ^{allwhite}*"#Column width"{allwhite}* | |
82 | pp_error ^{allwhite}*"#"{alphanum}* | |
83 | ||
84 | %% | |
85 | ||
86 | <INITIAL>{pp_title} { BEGIN(TITLE); } | |
87 | <TITLE>{alpha}*{alphanum}* { strcat(title, yytext); } | |
88 | <TITLE>{whitespace}* { strcat(title, " "); } | |
89 | <TITLE>[\n]* { BEGIN(INITIAL); return T_TITLE; } | |
90 | ||
91 | <INITIAL>{pp_name} { BEGIN(NAME); } | |
92 | <NAME>{alpha}*{alphanum}* { strcpy(tcname, yytext); return T_NAME; } | |
93 | <NAME>{allwhite}* { BEGIN(INITIAL); } | |
94 | ||
95 | <INITIAL>{pp_code} { BEGIN(CODE); } | |
96 | <CODE>{path}*{alphanum}* { strcpy(code_srcdir, yytext); return T_CODE; } | |
97 | <CODE>{allwhite}* { BEGIN(INITIAL); } | |
98 | ||
99 | <INITIAL>{pp_logs} { BEGIN(LOGS); } | |
100 | <LOGS>{path}*{alphanum}* { strcpy(log_srcdir, yytext); return T_LOGS; } | |
101 | <LOGS>{allwhite}* { BEGIN(INITIAL); } | |
102 | ||
103 | <INITIAL>{pp_dump} { BEGIN(DUMP); } | |
104 | <DUMP>{path}*{alphanum}* { strcpy(dump_srcdir, yytext); return T_DUMP; } | |
105 | <DUMP>{allwhite}* { BEGIN(INITIAL); } | |
106 | ||
107 | <INITIAL>{pp_dest} { BEGIN(DEST); } | |
108 | <DEST>{path}*{alphanum}* { strcpy(dstdir, yytext); return T_DEST; } | |
109 | <DEST>{allwhite}* { BEGIN(INITIAL); } | |
110 | ||
111 | <INITIAL>{pp_short} { return T_SHORT; } | |
112 | ||
113 | <INITIAL>{pp_long} { return T_LONG; } | |
114 | ||
115 | <INITIAL>{pp_tablen} { BEGIN(TABLEN); } | |
116 | <TABLEN>{digit}* { tablen = atoi(yytext); return T_TABLEN; } | |
117 | <TABLEN>{allwhite}* { BEGIN(INITIAL); } | |
118 | ||
119 | <INITIAL>{pp_fillcol} { BEGIN(FILLCOL); } | |
120 | <FILLCOL>{digit}* { fillcol = atoi(yytext); return T_FILLCOL; } | |
121 | <FILLCOL>{allwhite}* { BEGIN(INITIAL); } | |
122 | ||
123 | <INITIAL>.|\n { ch = yytext[0]; return T_STR; } | |
124 | ||
125 | <INITIAL>{pp_error} | | |
126 | <*>.|\n { return T_ERROR; } | |
127 | ||
128 | %% | |
129 | int main ( int argc, char *argv[] ) | |
130 | { | |
131 | char sname[MAXLEN]; | |
132 | char lname[MAXLEN]; | |
133 | FILE *sfh = NULL; | |
134 | FILE *lfh = NULL; | |
135 | size_t i, offset; | |
136 | #ifndef MINGW | |
137 | mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; | |
138 | #endif | |
139 | #ifdef LICENSE | |
140 | license_struct lstr; | |
141 | #endif | |
142 | ||
143 | if ( argc != 2 ) | |
144 | { | |
145 | fprintf ( stderr, "Usage: %s inputfile [-h]\n", argv[0] ); | |
146 | return -1; | |
147 | } | |
148 | ||
149 | if ( strcmp ( argv[1], "-h" ) == 0 ) | |
150 | { | |
151 | ||
152 | fputs("HTML Report Generator for the TTCN-3 Test Executor\n" | |
153 | "Product number: " PRODUCT_NUMBER "\n" | |
154 | "Build date: " __DATE__ " " __TIME__ "\n" | |
155 | "Compiled with: " C_COMPILER_VERSION "\n\n" | |
156 | COPYRIGHT_STRING "\n\n" | |
157 | "Example input file is printed to standard output.\n", stderr); | |
158 | ||
159 | puts ("#Title Sample\n" | |
160 | "#Tab length 8\n" | |
161 | "#Column width 80\n" | |
162 | "#TTCN-3 code ./\n" | |
163 | "#TTCN-3 log ./\n" | |
164 | "#Other log ./\n" | |
165 | "#Destination ./\n" | |
166 | "\n" | |
167 | "#Testcase testcase1\n" | |
168 | "#Purpose\n" | |
169 | "The purpose of the test case comes here.\n" | |
170 | "#Description\n" | |
171 | "This section describes the test case in detail.\n" | |
172 | "\n" | |
173 | "#Testcase testcase2\n" | |
174 | "#Purpose\n" | |
175 | "The purpose of the test case comes here.\n" | |
176 | "#Description\n" | |
177 | "This section describes the test case in detail.\n" ); | |
178 | ||
179 | return 0; | |
180 | } | |
181 | ||
182 | #ifdef LICENSE | |
183 | init_openssl(); | |
184 | load_license(&lstr); | |
185 | if (!verify_license(&lstr)) { | |
186 | free_license(&lstr); | |
187 | free_openssl(); | |
188 | exit(EXIT_FAILURE); | |
189 | } | |
190 | if (!check_feature(&lstr, FEATURE_LOGFORMAT)) { | |
191 | fputs("The license key does not allow the usage of HTML " | |
192 | "report generator.\n", stderr); | |
193 | return 2; | |
194 | } | |
195 | free_license(&lstr); | |
196 | free_openssl(); | |
197 | #endif | |
198 | ||
199 | if ( ( yyin = fopen ( argv[1], "r" ) ) == 0 ) | |
200 | { | |
201 | perror ( argv[1] ); | |
202 | exit ( 1 ); | |
203 | } | |
204 | ||
205 | sprintf ( dstdir, "./" ); | |
206 | ||
207 | tclist = (struct listentry *)malloc ( sizeof ( struct listentry ) ); | |
208 | tclist->next = NULL; | |
209 | first = tclist; | |
210 | ||
211 | while ( ( token = yylex() ) ) | |
212 | { | |
213 | switch(token) | |
214 | { | |
215 | case T_TITLE: | |
216 | tok = token; | |
217 | break; | |
218 | ||
219 | case T_NAME: | |
220 | strcpy ( tclist->tcname, tcname ); | |
221 | tclist->next = (struct listentry *)malloc ( sizeof ( struct listentry ) ); | |
222 | tclist = tclist->next; | |
223 | tclist->next = NULL; | |
224 | ||
225 | sprintf ( sname, "%s/%s.short", dstdir, tcname ); | |
226 | sprintf ( lname, "%s/%s.long", dstdir, tcname ); | |
227 | ||
228 | if ( sfh ) fclose ( sfh ); | |
229 | if ( ! ( sfh = fopen ( sname, "wt" ) ) ) | |
230 | { | |
231 | perror ( sname ); | |
232 | return -1; | |
233 | } | |
234 | ||
235 | if ( lfh ) fclose ( lfh ); | |
236 | if ( ! ( lfh = fopen ( lname, "wt" ) ) ) | |
237 | { | |
238 | perror ( lname ); | |
239 | return -1; | |
240 | } | |
241 | break; | |
242 | ||
243 | case T_SHORT: | |
244 | case T_LONG: | |
245 | tok = token; | |
246 | break; | |
247 | ||
248 | case T_STR: | |
249 | switch ( tok ) | |
250 | { | |
251 | case T_SHORT: | |
252 | putc(ch, sfh); | |
253 | break; | |
254 | ||
255 | case T_LONG: | |
256 | putc(ch, lfh); | |
257 | break; | |
258 | ||
259 | case T_STR: | |
260 | default: | |
261 | break; | |
262 | } | |
263 | break; | |
264 | ||
265 | case T_CODE: | |
266 | case T_LOGS: | |
267 | case T_DUMP: | |
268 | case T_TABLEN: | |
269 | case T_FILLCOL: | |
270 | break; | |
271 | ||
272 | case T_DEST: | |
273 | if ( dstdir[strlen(dstdir)-1] != '/' ) dstdir[strlen(dstdir)] = '/'; | |
274 | ||
275 | if ( mkdir ( dstdir | |
276 | #ifndef MINGW | |
277 | , mode | |
278 | #endif | |
279 | ) == -1 ) | |
280 | { | |
281 | if ( errno != EEXIST ) | |
282 | { | |
283 | fprintf ( stderr, "Cannot create directory: %s\n", dstdir ); | |
284 | return -1; | |
285 | } | |
286 | /* else fprintf ( stderr, "Directory already exists: %s\n", dstdir ); */ | |
287 | } | |
288 | ||
289 | offset = strlen ( dstdir ); | |
290 | for ( i = 0; i < strlen ( title ); i++ ) | |
291 | { | |
292 | if ( title[i] == ' ' ) dstdir[offset+i] = '_'; | |
293 | else dstdir[offset+i] = title[i]; | |
294 | } | |
295 | strcat ( dstdir, "-report" ); | |
296 | ||
297 | mkdir ( dstdir | |
298 | #ifndef MINGW | |
299 | , mode | |
300 | #endif | |
301 | ); | |
302 | ||
303 | break; | |
304 | ||
305 | case T_ERROR: | |
306 | default: | |
307 | if ( yytext[strlen(yytext)-1] == '\n' ) yytext[strlen(yytext)-1] = '\0'; | |
308 | fprintf ( stderr, "Parse error at line %d: %s\n", yylineno, yytext ); | |
309 | return -1; | |
310 | } | |
311 | } | |
312 | ||
313 | if ( sfh ) fclose ( sfh ); | |
314 | if ( lfh ) fclose ( lfh ); | |
315 | ||
316 | fclose ( yyin ); | |
317 | ||
318 | WriteCode ( first, code_srcdir, dstdir, tablen, fillcol ); | |
319 | WriteLog ( first, log_srcdir, dstdir ); | |
320 | WriteDump ( first, dump_srcdir, dstdir, tablen, fillcol ); | |
321 | ||
322 | Genhtml ( first, title, dstdir ); | |
323 | ||
324 | return 0; | |
325 | } |