1 /******************************************************************************
2 * Copyright (c) 2000-2014 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
7 ******************************************************************************/
10 %option never-interactive
14 /* #define CHK_ACCESS */
17 #include <sys/types.h>
20 #include "../common/version_internal.h"
24 #include "../common/license.h"
41 struct listentry *first, *tclist;
43 static char title[MAXLEN];
44 static char code_srcdir[MAXLEN], log_srcdir[MAXLEN], dump_srcdir[MAXLEN];
45 static char tcname[MAXLEN], dstdir[MAXLEN];
46 static int tablen, fillcol;
50 %x PP TITLE NAME SHORT LONG CODE LOGS DUMP DEST TABLEN FILLCOL ERROR
57 alphanum {alpha}|{digit}
59 allwhite [ \t\f\b\v\r\n]
61 path [./~a-zA-Z_0-9\-]
63 pp_title ^{allwhite}*"#Title"{allwhite}*
64 pp_name ^{allwhite}*"#Testcase"{allwhite}*
65 pp_short ^{allwhite}*"#Purpose"{whitespace}*[\n]*
66 pp_long ^{allwhite}*"#Description"{whitespace}*[\n]*
67 pp_code ^{allwhite}*"#TTCN-3 code"{allwhite}*
68 pp_logs ^{allwhite}*"#TTCN-3 log"{allwhite}*
69 pp_dump ^{allwhite}*"#Other log"{allwhite}*
70 pp_dest ^{allwhite}*"#Destination"{allwhite}*
71 pp_tablen ^{allwhite}*"#Tab length"{allwhite}*
72 pp_fillcol ^{allwhite}*"#Column width"{allwhite}*
73 pp_error ^{allwhite}*"#"{alphanum}*
77 <INITIAL>{pp_title} { BEGIN(TITLE); }
78 <TITLE>{alpha}*{alphanum}* { strcat(title, yytext); }
79 <TITLE>{whitespace}* { strcat(title, " "); }
80 <TITLE>[\n]* { BEGIN(INITIAL); return T_TITLE; }
82 <INITIAL>{pp_name} { BEGIN(NAME); }
83 <NAME>{alpha}*{alphanum}* { strcpy(tcname, yytext); return T_NAME; }
84 <NAME>{allwhite}* { BEGIN(INITIAL); }
86 <INITIAL>{pp_code} { BEGIN(CODE); }
87 <CODE>{path}*{alphanum}* { strcpy(code_srcdir, yytext); return T_CODE; }
88 <CODE>{allwhite}* { BEGIN(INITIAL); }
90 <INITIAL>{pp_logs} { BEGIN(LOGS); }
91 <LOGS>{path}*{alphanum}* { strcpy(log_srcdir, yytext); return T_LOGS; }
92 <LOGS>{allwhite}* { BEGIN(INITIAL); }
94 <INITIAL>{pp_dump} { BEGIN(DUMP); }
95 <DUMP>{path}*{alphanum}* { strcpy(dump_srcdir, yytext); return T_DUMP; }
96 <DUMP>{allwhite}* { BEGIN(INITIAL); }
98 <INITIAL>{pp_dest} { BEGIN(DEST); }
99 <DEST>{path}*{alphanum}* { strcpy(dstdir, yytext); return T_DEST; }
100 <DEST>{allwhite}* { BEGIN(INITIAL); }
102 <INITIAL>{pp_short} { return T_SHORT; }
104 <INITIAL>{pp_long} { return T_LONG; }
106 <INITIAL>{pp_tablen} { BEGIN(TABLEN); }
107 <TABLEN>{digit}* { tablen = atoi(yytext); return T_TABLEN; }
108 <TABLEN>{allwhite}* { BEGIN(INITIAL); }
110 <INITIAL>{pp_fillcol} { BEGIN(FILLCOL); }
111 <FILLCOL>{digit}* { fillcol = atoi(yytext); return T_FILLCOL; }
112 <FILLCOL>{allwhite}* { BEGIN(INITIAL); }
114 <INITIAL>.|\n { ch = yytext[0]; return T_STR; }
116 <INITIAL>{pp_error} |
117 <*>.|\n { return T_ERROR; }
120 int main ( int argc, char *argv[] )
128 mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
136 fprintf ( stderr, "Usage: %s inputfile [-h]\n", argv[0] );
140 if ( strcmp ( argv[1], "-h" ) == 0 )
143 fputs("HTML Report Generator for the TTCN-3 Test Executor\n"
144 "Product number: " PRODUCT_NUMBER "\n"
145 "Build date: " __DATE__ " " __TIME__ "\n"
146 "Compiled with: " C_COMPILER_VERSION "\n\n"
147 COPYRIGHT_STRING "\n\n"
148 "Example input file is printed to standard output.\n", stderr);
150 puts ("#Title Sample\n"
158 "#Testcase testcase1\n"
160 "The purpose of the test case comes here.\n"
162 "This section describes the test case in detail.\n"
164 "#Testcase testcase2\n"
166 "The purpose of the test case comes here.\n"
168 "This section describes the test case in detail.\n" );
176 if (!verify_license(&lstr)) {
181 if (!check_feature(&lstr, FEATURE_LOGFORMAT)) {
182 fputs("The license key does not allow the usage of HTML "
183 "report generator.\n", stderr);
190 if ( ( yyin = fopen ( argv[1], "r" ) ) == 0 )
196 sprintf ( dstdir, "./" );
198 tclist = (struct listentry *)malloc ( sizeof ( struct listentry ) );
202 while ( ( token = yylex() ) )
211 strcpy ( tclist->tcname, tcname );
212 tclist->next = (struct listentry *)malloc ( sizeof ( struct listentry ) );
213 tclist = tclist->next;
216 sprintf ( sname, "%s/%s.short", dstdir, tcname );
217 sprintf ( lname, "%s/%s.long", dstdir, tcname );
219 if ( sfh ) fclose ( sfh );
220 if ( ! ( sfh = fopen ( sname, "wt" ) ) )
226 if ( lfh ) fclose ( lfh );
227 if ( ! ( lfh = fopen ( lname, "wt" ) ) )
264 if ( dstdir[strlen(dstdir)-1] != '/' ) dstdir[strlen(dstdir)] = '/';
272 if ( errno != EEXIST )
274 fprintf ( stderr, "Cannot create directory: %s\n", dstdir );
277 /* else fprintf ( stderr, "Directory already exists: %s\n", dstdir ); */
280 offset = strlen ( dstdir );
281 for ( i = 0; i < strlen ( title ); i++ )
283 if ( title[i] == ' ' ) dstdir[offset+i] = '_';
284 else dstdir[offset+i] = title[i];
286 strcat ( dstdir, "-report" );
298 if ( yytext[strlen(yytext)-1] == '\n' ) yytext[strlen(yytext)-1] = '\0';
299 fprintf ( stderr, "Parse error at line %d: %s\n", yylineno, yytext );
304 if ( sfh ) fclose ( sfh );
305 if ( lfh ) fclose ( lfh );
309 WriteCode ( first, code_srcdir, dstdir, tablen, fillcol );
310 WriteLog ( first, log_srcdir, dstdir );
311 WriteDump ( first, dump_srcdir, dstdir, tablen, fillcol );
313 Genhtml ( first, title, dstdir );