1 # to run: awk -f transit.awk transit.p0
3 BEGIN { "date" | getline
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
20 else if ( $
1 ==
"COMPILE" ) {
22 if ( $
3 ==
"NOINDEX" ) { enable_index =
0 }
26 n =
split( $
0, fld
, " " )
29 store
( action
, newstate
)
34 END { store
( action
, newstate
)
37 printf( "\n/* index name #defines: */\n\n",
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",
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( "," )
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( "," )
68 function store
( act
, ns
){
69 # printf( "%s %s\n", act, ns )
74 function newtbl
( tbl
){
76 store
( action
, newstate
)
79 entry_offset
[ ++fpeo
] = fpe
# entry tbl offset list
80 define
[ ++fpdef
] = tbl
# state name to define