* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / net / 802 / transit / compile.awk
blob1b3b56c377b275a25e31736064310985f0f7285f
1 # to run: awk -f transit.awk transit.p0
3 BEGIN { "date" | getline
4 enable_index = 1
5 today = $0
6 printf("\n/* this file was generated on %s */\n", today )
7 not_firstone = 0 # flag to avoid empty entry in 1st table
8 fpe = 0 # entry tbl array fill pointer
9 fpeo = 0 # entry tbl offset list fill pointer
10 fpdef = 0 # define list fill pointer
13 ### /^;/ { } # line starting with a semicolon is comment
15 /^[A-Z]/ { # table name
16 if ( $1 == "TABLE" ) {
17 tbl = $2 # get table name
18 newtbl( tbl )
20 else if ( $1 == "COMPILE" ) {
21 array_name = $2
22 if ( $3 == "NOINDEX" ) { enable_index = 0 }
24 else { # table entry
25 ec = ec +1
26 n = split( $0, fld, " " )
27 action = fld[ n-1 ]
28 newstate = fld[ n ]
29 store( action, newstate )
30 ecct = ecct +1
34 END { store( action, newstate )
36 if ( enable_index ) {
37 printf( "\n/* index name #defines: */\n\n",
38 ec, ecct )
40 for( ii = 1; ii <= fpeo; ii++ ){
41 printf( "#define %-12s %3d\n", define[ ii ], ii -1 )
45 printf( "\n\n/* size of transition table is %d bytes */\n",
46 fpe )
48 if ( enable_index ) {
49 printf( "\nstatic short int %s_offset [ ] ={", array_name )
50 for( ii = 1; ii <= fpeo; ii++ ){
51 if ( (ii % 10) == 1 ) printf("\n ")
52 printf( " %4d", entry_offset[ ii ] )
53 if ( ii < fpeo ) printf( "," )
55 printf(" };\n")
58 printf( "\nstatic char %s_entry [ ] = {", array_name )
59 for( ii = 1; ii <= fpe; ii++ ){
60 if ( (ii % 6) == 1 ) printf("\n ")
61 printf( " %-14s", entry[ ii ] )
62 if ( ii < fpe ) printf( "," )
64 printf(" };\n")
68 function store( act, ns ){
69 # printf( "%s %s\n", act, ns )
70 entry[ ++fpe ] = act
71 entry[ ++fpe ] = ns
74 function newtbl( tbl ){
75 if ( not_firstone ) {
76 store( action, newstate )
78 not_firstone = 1
79 entry_offset[ ++fpeo ] = fpe # entry tbl offset list
80 define[ ++fpdef ] = tbl # state name to define