gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
WSL metrics script
[mjc2wsl.git] / src-wsl / metrics.wsl
1 C:"This program generates metrics for WSL programs,
2 including options for comparing two programs (mainly ment to
3 compare different versions) and output differences as direct
4 numbers and percentages in a CSV type of format.
6 One of the goals was to enable this to be used both in the
7 command line for quick checks but also to be used for
8 automation and creation of CSV files for collections of
9 programs.";
11 C:"Doni Pracner (c) 2015";
13 C:"Released under the terms of the GPL v3 or later";
15 C:"usage {option} {filename}";
17 C:"Options";
18 C:" -h or --help - help screen";
19 C:" -H or --header - print header for metrics";
20 C:" -c 'file1' 'file2' - compare two files and print the metrics";
21 C:" -HC print header for comparison";
22 C:" -o 'file' - set output for the print";
23 C:" -s 'separator' - set the separator in outputs (default comma)";
24 C:" otherwise print the metrics of the given file(s)";
26 C:"options are processed in sequence, so you can have
27 for instance multiple outputs during the execution and
28 run it for different programs";
30 C:"examples;
32 'filename' 'file2' 'file3'
33 - just output the metrics all files on the screen,
34 each in it's own row
36 -c 'f1' 'f2'
37 - compare two files and output the differences on the
38 screen
40 -o res.tmp -HC -c 'f1' 'f1a' -c 'f2' 'f2a'
41 - output a header row and two rows comparing the given
42 files in the specified file
43 ";
45 C:"
46 This program is free software; you can redistribute it
47 and/or modify it under the terms of the GNU General Public
48 License as published by the Free Software Foundation; either
49 version 3 of the License, or (at your option) any later
50 version.
52 This program is distributed in the hope that it will be
53 useful, but WITHOUT ANY WARRANTY; without even the implied
54 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
55 PURPOSE. See the GNU General Public License for more
56 details.
58 You should have received a copy of the GNU General Public
59 License along with this program. If not, see
60 <http://www.gnu.org/licenses/>.
61 ==========================================================";
63 Field_Separator := ",";
65 MW_PROC @Get_New_Name(VAR str) ==
66 IF @Ends_With?(str, ".wsl") THEN
67 str := SUBSTR(str, 0, SLENGTH(str)-4)
68 FI;
69 str := str ++ ".met"
70 END;
72 MW_PROC @Process_File(filename VAR metricslist) ==
73 metricslist := < >;
74 IF @File_Exists?(filename) THEN
75 @New_Program(@Parse_File(filename, T_Statements));
77 C:"add them in reverse to the start of the list";
78 metricslist := < @Struct_Metric(@Program) > ++ metricslist ;
79 metricslist := < @Total_Size(@Program) > ++ metricslist ;
80 metricslist := < @CFDF_Metric(@Program) > ++ metricslist ;
81 metricslist := < @Gen_Type_Count("T_Expression",@Program) > ++ metricslist ;
82 metricslist := < @Stat_Count(@Program) > ++ metricslist ;
83 metricslist := < @Essential(@Program) > ++ metricslist ;
84 metricslist := < @McCabe(@Program) > ++ metricslist
85 ELSE
86 PRINT("ERROR: File ",filename," not found");
87 FI
88 END;
90 MW_PROC @Write_Metrics(metrics VAR) ==
91 FOR met IN metrics DO
92 @WS(Field_Separator);
93 @WN(met)
94 OD
95 END;
97 MW_PROC @Write_Metrics_List() ==
98 @WS("McCabe Cyclo");@WS(Field_Separator);
99 @WS("McCabe Essential");@WS(Field_Separator);
100 @WS("Statements");@WS(Field_Separator);
101 @WS("Expressions");@WS(Field_Separator);
102 @WS("CFDF");@WS(Field_Separator);
103 @WS("Size");@WS(Field_Separator);
104 @WS("Structure")
105 END;
107 MW_PROC @Metrics_Main() ==
108 VAR< prog := < >,
109 filename:="", filename2 := "",
110 metrics := < >, met2 := < >,
111 opened := 0,
112 Argv := @Argv
113 >:
114 C:"First one is the script name that is being executed";
115 Argv := TAIL(Argv);
117 IF Argv = < > THEN
118 PRINT("no arguments passed; supply a filename to make metrics for ");
119 ELSE
120 WHILE Argv <> < > DO
121 POP(filename,Argv);
122 IF filename = "-h" OR filename = "--help" THEN
123 PRINT("HELP - for now in the comments at the start of the script");
124 PRINT("options: --header or -H | -c | -HC | -o | -s");
125 SKIP
126 ELSE IF filename = "-H" OR filename = "--header" THEN
127 @WS("filename");@WS(Field_Separator);
128 @Write_Metrics_List();
129 @WL("");
130 ELSE IF filename = "-HC" THEN
131 C:"Header for comparison";
132 @WS("filename");@WS(Field_Separator);
133 @Write_Metrics_List();@WS(Field_Separator);
134 @Write_Metrics_List();@WS(Field_Separator);
135 @WS("DIF");@Write_Metrics_List();@WS(Field_Separator);
136 @WS("%");@Write_Metrics_List();
137 @WL("");
138 ELSE IF filename = "-o" THEN
139 C:"set output";
140 IF Argv = < > THEN
141 PRINT("argument needed after -o")
142 ELSE
143 POP(filename, Argv);
144 opened := opened + 1;
145 @Write_To(filename)
146 FI
147 ELSE IF filename = "-s" THEN
148 C:"set separator";
149 IF Argv = < > THEN
150 PRINT("argument needed after -s")
151 ELSE
152 POP(Field_Separator, Argv);
153 FI
154 ELSE IF filename = "-c" THEN
155 C:"compare two files and dump the comparison";
156 IF LENGTH(Argv) < 2 THEN
157 PRINT("two arguments needed after -c")
158 ELSE
159 POP(filename, Argv);
161 @Process_File(filename VAR metrics);
162 @WS(filename);
163 @Write_Metrics(metrics);
165 POP(filename2,Argv);
166 @Process_File(filename2 VAR met2);
167 @Write_Metrics(met2);
169 C:"calculate the differences";
170 FOR i := 1 TO LENGTH(metrics) STEP 1 DO
171 met2[i] := metrics[i] - met2[i];
172 IF metrics[i] <> 0 THEN
173 metrics[i] := met2[i] * 100 DIV metrics[i]
174 FI
175 OD;
176 @Write_Metrics(met2);
177 @Write_Metrics(metrics);
179 @WL("");
180 FI;
181 SKIP
182 ELSE
183 @Process_File(filename VAR metrics);
184 @WS(filename);
185 @Write_Metrics(metrics);
186 @WL("");
187 SKIP
188 FI FI FI FI FI FI
189 OD;
190 C:"be nice and close all the opened writes";
191 FOR count := 1 TO opened STEP 1 DO
192 @End_Write
193 OD
194 FI
195 ENDVAR
196 END;
198 @Metrics_Main()
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner