#include <config.h>
#include <stdlib.h> /* exit() */
#include <stdio.h> /* FILE decl for dd_esb.h, printf etc */
#include "dwarf.h"
#include "libdwarf.h"
#include "libdwarf_private.h"
#include "dd_defined_types.h"
#include "dd_checkutil.h"
#include "dd_glflags.h"
#include "dd_globals.h"
#include "dd_common.h"
#include "dd_esb.h"
#include "dd_tag_common.h"
#include "dd_getopt.h"
#include "dd_tsearchbal.h"
#include "dd_attr_form.h"
#include "dd_safe_strcpy.h"
#include "dd_minimal.h"
void
dd_minimal_count_global_error(
void
) {}
Dwarf_Bool ellipsis = FALSE;
#define AF_STANDARD 1
#define AF_EXTENDED 2
static
const
char
*usage[] = {
"Usage: attr_form_build <options>"
,
" -i input-table-path"
,
" -o output-table-path"
,
" -s (Generate standard attr-formclass table)"
,
" -e (Generate extended attr-formclass table "
,
" common extensions))"
,
""
};
const
char
*program_name = 0;
char
*input_name = 0;
char
*output_name = 0;
int
standard_flag = FALSE;
int
extended_flag = FALSE;
static
void
process_args(
int
argc,
char
*argv[])
{
int
c = 0;
Dwarf_Bool usage_error = FALSE;
program_name = argv[0];
while
((c = dwgetopt(argc, argv,
"i:o:se"
)) != EOF) {
switch
(c) {
case
'i'
:
input_name = dwoptarg;
break
;
case
'o'
:
output_name = dwoptarg;
break
;
case
'e'
:
extended_flag = TRUE;
break
;
case
's'
:
standard_flag = TRUE;
break
;
default
:
usage_error = TRUE;
break
;
}
}
if
(usage_error || 1 == dwoptind || dwoptind != argc) {
print_usage_message(usage);
exit
(EXIT_FAILURE);
}
}
int
main(
int
argc,
char
**argv)
{
unsigned
int
num = 0;
int
input_eof = 0;
FILE
*fileInp = 0;
FILE
*fileOut = 0;
unsigned table_type = 0;
const
char
*structname = 0;
const
char
*macroname = 0;
print_version_details(argv[0]);
print_args(argc,argv);
process_args(argc,argv);
if
(!input_name ) {
fprintf
(stderr,
"Input name required, not supplied.\n"
);
print_usage_message(usage);
exit
(EXIT_FAILURE);
}
fileInp =
fopen
(input_name,
"r"
);
if
(!fileInp) {
fprintf
(stderr,
"Invalid input filename,"
" could not open '%s'\n"
,
input_name);
print_usage_message(usage);
exit
(EXIT_FAILURE);
}
if
(!output_name ) {
fprintf
(stderr,
"Output name required, not supplied.\n"
);
print_usage_message(usage);
exit
(EXIT_FAILURE);
}
fileOut =
fopen
(output_name,
"w"
);
if
(!fileOut) {
fprintf
(stderr,
"Invalid output filename,"
" could not open: '%s'\n"
,
output_name);
print_usage_message(usage);
exit
(EXIT_FAILURE);
}
if
((standard_flag && extended_flag) ||
(!standard_flag && !extended_flag)) {
fprintf
(stderr,
"Invalid table type\n"
);
fprintf
(stderr,
"Choose -e or -s .\n"
);
print_usage_message(usage);
exit
(EXIT_FAILURE);
}
input_eof = read_value(&num,fileInp);
if
(IS_EOF == input_eof) {
bad_line_input(
"Empty input file"
);
}
if
(num != MAGIC_TOKEN_VALUE) {
bad_line_input(
"Expected 0xffffffff"
);
}
if
(standard_flag) {
table_type = AF_STD;
structname =
"dd_threekey_af_table_std"
;
macroname =
"DWARFDUMP_AF_TABLE_STD_H"
;
}
else
{
table_type = AF_EXTEN;
structname =
"dd_threekey_af_table_ext"
;
macroname =
"DWARFDUMP_AF_TABLE_EXT_H"
;
}
fprintf
(fileOut,
"/* Generated table, do not edit. */\n"
);
fprintf
(fileOut,
"/* Generated for source version %s */\n"
,
PACKAGE_VERSION);
fprintf
(fileOut,
"\n"
);
fprintf
(fileOut,
"%s%s\n"
,
"#ifndef "
,macroname);
fprintf
(fileOut,
"%s%s\n"
,
"#define "
,macroname);
fprintf
(fileOut,
"\n"
);
fprintf
(fileOut,
"%s\n"
,
"#ifdef __cplusplus"
);
fprintf
(fileOut,
"%s\n"
,
"extern \"C\" {"
);
fprintf
(fileOut,
"%s\n"
,
"#endif /* __cplusplus */"
);
fprintf
(fileOut,
"struct Three_Key_Entry_s %s [] = {\n"
,
structname);
while
(!
feof
(stdin)) {
int
res = 0;
unsigned
int
attr = 0;
const
char
* attrname = 0;
input_eof = read_value(&attr,fileInp);
if
(IS_EOF == input_eof) {
break
;
}
res = dwarf_get_AT_name(attr,&attrname);
if
(res != DW_DLV_OK) {
printf
(
"Unknown attribute number of 0x%x,"
" Giving up\n"
,attr);
exit
(EXIT_FAILURE);
}
fprintf
(fileOut,
"/* 0x%04x %s */\n"
,attr,attrname);
input_eof = read_value(&num,fileInp);
if
(IS_EOF == input_eof) {
bad_line_input(
"Not terminated correctly."
);
}
while
(num != MAGIC_TOKEN_VALUE) {
fprintf
(fileOut,
"{0x%04x,0x%04x,%u,%d,0,0},\n"
,
(Dwarf_Half)attr,(Dwarf_Half)num,(Dwarf_Half)0,
table_type);
input_eof = read_value(&num,fileInp);
if
(IS_EOF == input_eof) {
bad_line_input(
"Not terminated correctly."
);
}
}
}
fprintf
(fileOut,
"{0,0,0,0,0,0}};"
);
fprintf
(fileOut,
"\n/* END FILE */\n"
);
fprintf
(fileOut,
"%s\n"
,
"#ifdef __cplusplus"
);
fprintf
(fileOut,
"%s\n"
,
"}"
);
fprintf
(fileOut,
"%s\n"
,
"#endif /* __cplusplus */"
);
fprintf
(fileOut,
"%s%s%s\n"
,
"#endif /* "
,
macroname,
" */"
);
fclose
(fileInp);
fclose
(fileOut);
return
(0);
}
void
print_error (Dwarf_Debug dbg,
const
char
* msg,
int
res,
Dwarf_Error localerr)
{
(
void
)dbg;
(
void
)msg;
(
void
)res;
(
void
)localerr;
}