2000-05-14 14:05:10 +00:00
# produce a header file for a parsed struct file
2000-05-15 13:41:05 +00:00
function header_elstring ( elnum ,
LOCAL , elem )
2000-05-14 14:05:10 +00:00
{
2000-05-31 05:39:54 +00:00
array_len = elements [ elnum , "array_len" ] ;
2000-05-15 13:41:05 +00:00
elem = elements [ elnum , "elem" ] ;
if ( elements [ elnum , "ptr" ] == "1" ) elem = "*" elem ;
2000-05-31 05:39:54 +00:00
if ( array_len != "" ) {
2000-06-09 02:59:50 +00:00
if ( is_constant ( array_len ) == 1 ) {
2000-05-31 05:39:54 +00:00
elem = elem "[" array_len "]" ;
} else {
elem = "*" elem ;
}
}
2000-05-15 13:41:05 +00:00
return elem ;
2000-05-14 14:05:10 +00:00
}
2000-05-15 13:41:05 +00:00
function header_element ( f , elnum ,
LOCAL , type )
2000-05-14 14:05:10 +00:00
{
2000-05-15 13:41:05 +00:00
type = elements [ elnum , "type" ] ;
2000-05-16 12:43:53 +00:00
if ( substr ( type , 1 , 1 ) == "." ) return ;
2000-05-15 13:41:05 +00:00
xprintf ( f , "\t%s %s;\n" , type , header_elstring ( elnum ) ) ;
2000-05-14 14:05:10 +00:00
}
2000-05-15 13:41:05 +00:00
function header_union ( f , elnum ,
LOCAL , i )
2000-05-14 14:05:10 +00:00
{
2000-05-15 13:41:05 +00:00
xprintf ( f , "\tunion {\n" ) ;
for ( i = 0 ; i < unions [ elnum , "num_elems" ] ; i ++ ) {
header_element ( f , unions [ elnum , i ] ) ;
}
xprintf ( f , "\t} %s;\n" , header_elstring ( elnum ) ) ;
}
2000-05-14 14:05:10 +00:00
2000-05-15 13:41:05 +00:00
function header_elem ( f , elnum )
{
if ( elements [ elnum , "type" ] == "union" ) {
header_union ( f , elnum ) ;
2000-05-14 14:05:10 +00:00
} else {
2000-05-15 13:41:05 +00:00
header_element ( f , elnum ) ;
2000-05-14 14:05:10 +00:00
}
}
function header_struct ( f , struct_num ,
LOCAL , i )
{
xprintf ( f , "/* structure %s */\n" ,
structs [ struct_num , "name" ] ) ;
xprintf ( f , "typedef struct {\n" ) ;
for ( i = 0 ; i < structs [ struct_num , "num_elems" ] ; i ++ ) {
2000-05-15 13:41:05 +00:00
header_elem ( f , structs [ struct_num , i ] ) ;
2000-05-14 14:05:10 +00:00
}
xprintf ( f , "} %s;\n\n\n" , structs [ struct_num , "name" ] ) ;
}
function produce_headers ( f , NIL ,
LOCAL , i )
{
xprintf ( f , "/* auto-generated headers for %s */\n\n\n" , module ) ;
2000-05-31 05:39:54 +00:00
xprintf ( f , "#ifndef _%s_\n" , module ) ;
xprintf ( f , "#define _%s_\n" , module ) ;
2000-06-09 02:59:50 +00:00
xprintf ( f , "\n\n" ) ;
for ( i = 0 ; i < num_options ; i ++ ) {
xprintf ( f , "#define OPTION_%s %s\n" ,
options [ i , "name" ] , options [ i , "value" ] ) ;
}
xprintf ( f , "\n\n" ) ;
2000-05-14 14:05:10 +00:00
for ( i = 0 ; i < num_structs ; i ++ ) {
header_struct ( f , i ) ;
}
xprintf ( f , "/* end auto-generated headers */\n\n" ) ;
2000-05-31 05:39:54 +00:00
xprintf ( f , "#endif /* _%s_ */\n" , module ) ;
2000-05-14 14:05:10 +00:00
}