1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
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
13 * Szabo, Janos Zoltan – initial implementation
14 * Zalanyi, Balazs Andor
16 ******************************************************************************/
19 %option never-interactive
23 /* #define CHK_ACCESS */
26 #include <sys/types.h>
29 #include "../common/version_internal.h"
33 #include "../common/license.h"
50 struct listentry *first, *tclist;
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;
59 %x PP TITLE NAME SHORT LONG CODE LOGS DUMP DEST TABLEN FILLCOL ERROR
66 alphanum {alpha}|{digit}
68 allwhite [ \t\f\b\v\r\n]
70 path [./~a-zA-Z_0-9\-]
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}*
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; }
91 <INITIAL>{pp_name} { BEGIN(NAME); }
92 <NAME>{alpha}*{alphanum}* { strcpy(tcname, yytext); return T_NAME; }
93 <NAME>{allwhite}* { BEGIN(INITIAL); }
95 <INITIAL>{pp_code} { BEGIN(CODE); }
96 <CODE>{path}*{alphanum}* { strcpy(code_srcdir, yytext); return T_CODE; }
97 <CODE>{allwhite}* { BEGIN(INITIAL); }
99 <INITIAL>{pp_logs} { BEGIN(LOGS); }
100 <LOGS>{path}*{alphanum}* { strcpy(log_srcdir, yytext); return T_LOGS; }
101 <LOGS>{allwhite}* { BEGIN(INITIAL); }
103 <INITIAL>{pp_dump} { BEGIN(DUMP); }
104 <DUMP>{path}*{alphanum}* { strcpy(dump_srcdir, yytext); return T_DUMP; }
105 <DUMP>{allwhite}* { BEGIN(INITIAL); }
107 <INITIAL>{pp_dest} { BEGIN(DEST); }
108 <DEST>{path}*{alphanum}* { strcpy(dstdir, yytext); return T_DEST; }
109 <DEST>{allwhite}* { BEGIN(INITIAL); }
111 <INITIAL>{pp_short} { return T_SHORT; }
113 <INITIAL>{pp_long} { return T_LONG; }
115 <INITIAL>{pp_tablen} { BEGIN(TABLEN); }
116 <TABLEN>{digit}* { tablen = atoi(yytext); return T_TABLEN; }
117 <TABLEN>{allwhite}* { BEGIN(INITIAL); }
119 <INITIAL>{pp_fillcol} { BEGIN(FILLCOL); }
120 <FILLCOL>{digit}* { fillcol = atoi(yytext); return T_FILLCOL; }
121 <FILLCOL>{allwhite}* { BEGIN(INITIAL); }
123 <INITIAL>.|\n { ch = yytext[0]; return T_STR; }
125 <INITIAL>{pp_error} |
126 <*>.|\n { return T_ERROR; }
129 int main ( int argc, char *argv[] )
137 mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
145 fprintf ( stderr, "Usage: %s inputfile [-h]\n", argv[0] );
149 if ( strcmp ( argv[1], "-h" ) == 0 )
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);
159 puts ("#Title Sample\n"
167 "#Testcase testcase1\n"
169 "The purpose of the test case comes here.\n"
171 "This section describes the test case in detail.\n"
173 "#Testcase testcase2\n"
175 "The purpose of the test case comes here.\n"
177 "This section describes the test case in detail.\n" );
185 if (!verify_license(&lstr)) {
190 if (!check_feature(&lstr, FEATURE_LOGFORMAT)) {
191 fputs("The license key does not allow the usage of HTML "
192 "report generator.\n", stderr);
199 if ( ( yyin = fopen ( argv[1], "r" ) ) == 0 )
205 sprintf ( dstdir, "./" );
207 tclist = (struct listentry *)malloc ( sizeof ( struct listentry ) );
211 while ( ( token = yylex() ) )
220 strcpy ( tclist->tcname, tcname );
221 tclist->next = (struct listentry *)malloc ( sizeof ( struct listentry ) );
222 tclist = tclist->next;
225 sprintf ( sname, "%s/%s.short", dstdir, tcname );
226 sprintf ( lname, "%s/%s.long", dstdir, tcname );
228 if ( sfh ) fclose ( sfh );
229 if ( ! ( sfh = fopen ( sname, "wt" ) ) )
235 if ( lfh ) fclose ( lfh );
236 if ( ! ( lfh = fopen ( lname, "wt" ) ) )
273 if ( dstdir[strlen(dstdir)-1] != '/' ) dstdir[strlen(dstdir)] = '/';
281 if ( errno != EEXIST )
283 fprintf ( stderr, "Cannot create directory: %s\n", dstdir );
286 /* else fprintf ( stderr, "Directory already exists: %s\n", dstdir ); */
289 offset = strlen ( dstdir );
290 for ( i = 0; i < strlen ( title ); i++ )
292 if ( title[i] == ' ' ) dstdir[offset+i] = '_';
293 else dstdir[offset+i] = title[i];
295 strcat ( dstdir, "-report" );
307 if ( yytext[strlen(yytext)-1] == '\n' ) yytext[strlen(yytext)-1] = '\0';
308 fprintf ( stderr, "Parse error at line %d: %s\n", yylineno, yytext );
313 if ( sfh ) fclose ( sfh );
314 if ( lfh ) fclose ( lfh );
318 WriteCode ( first, code_srcdir, dstdir, tablen, fillcol );
319 WriteLog ( first, log_srcdir, dstdir );
320 WriteDump ( first, dump_srcdir, dstdir, tablen, fillcol );
322 Genhtml ( first, title, dstdir );