File: eventcodes.awk

package info (click to toggle)
biosig4c++ 1.9.3-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 6,220 kB
  • sloc: ansic: 41,218; cpp: 8,946; sh: 4,365; makefile: 1,758; python: 87; awk: 73; php: 40; perl: 36; java: 14; ruby: 7
file content (75 lines) | stat: -rwxr-xr-x 2,146 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/gawk -f
#
#    Converts eventcodes.txt into eventcodes.i and eventcodegroups.i
#
#    $Id$
#    Copyright (C) 2011 Alois Schloegl <a.schloegl@ieee.org>
#    This file is part of the "BioSig for C/C++" repository
#    (biosig4c++) at http://biosig.sf.net/
#
#    BioSig is free software; you can redistribute it and/or
#    modify it under the terms of the GNU General Public License
#    as published by the Free Software Foundation; either version 3
#    of the License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.


BEGIN { FS = "\t"; 
	nG = 0;
	nC = 0;
	INIT = "#if 0\n### This file is autogenerated - Do not modify it !!! ###\n\n"; 
	printf(INIT,ARGV[0],ARGV[1]) > "eventcodes.i";
	printf(INIT,ARGV[0],ARGV[1]) > "eventcodegroups.i";
}

{
	if (NR < 12) {
		printf("%s\n", $0) >> "eventcodes.i";
		printf("%s\n", $0) >> "eventcodegroups.i";
	} else if (NR == 12) {
		printf("#endif\n") >> "eventcodes.i";
		printf("#endif\n") >> "eventcodegroups.i";
	}
}

# list of event groups
/^### 0x/ { 
        nG++;
	g = substr($1,7,4); 
	gsub(/_/, "0", g);
	G[nG,1] = g;
	G[nG,2] = $2;
} 

# list of event codes
/^[^#]/ { 
	if (255 < strtonum($1)) {
		# ignore user-specified events
	        nC++;
        	C[nC,1] = $1;
        	C[nC,2] = g;
        	C[nC,3] = $2;
	}
} 
 
END {
        for (i=1; i<=nG; i++) {
                printf("\t{ 0x%s, \"%s\" },\n",G[i,1],G[i,2]) >> "eventcodegroups.i"
        } 
       
        for (i=1; i<256; i++) {
 		# add pre-defined user-specified events 0x0001-0x00ff
               printf("\t{ 0x%04x, 0x0000, \"condition %i\" },\n",i,i) >> "eventcodes.i"
        } 
        for (i=1; i<=nC; i++) {
                printf("\t{ %s, 0x%s, \"%s\" },\n",C[i,1],C[i,2],C[i,3]) >> "eventcodes.i"
        } 
}