* ========== Copyright Header Begin ==========================================
* Hypervisor Software File: mdmain.c
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* - Do no alter or remove copyright notices
* - Redistribution and use of this software in source and binary forms, with
* or without modification, are permitted provided that the following
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of Sun Microsystems, Inc. or the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
* MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
* OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
* FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or maintenance of
* ========== Copyright Header End ============================================
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
#pragma ident "@(#)mdmain.c 1.3 07/06/07 SMI"
extern void dt_write_hdr(FILE *fd
, char *name
, md_hdr_t
*root
);
extern void parse_dag(char *fnamep
, FILE *fp
);
void stichin_reqd_properties(void);
void delete_protos(void);
Out_binary
, Out_text
, Out_dot
bool_t output_dot_flag_none
= false;
bool_t flag_verbose
= false;
dag_node_t
*dag_listp
= NULL
;
dag_node_t
*dag_list_endp
= NULL
;
main(int argc
, char **argv
)
char *outfnp
; /* output filename */
output_type
= Out_binary
;
for (i
= 1; i
< argc
&& argv
[i
][0] == '-'; i
++) {
if (strcmp(argv
[i
], "-h") == 0 ||
strcmp(argv
[i
], "--help") == 0) {
fprintf(stderr
, "usage: %s "
"[--text|--binary|--header|--dot <arc>"
"|-t|-b|-H|--d <arc>] [--outfile <fname>]"
" <filename>\n", argv
[0]);
"\t--help : this message\n"
"\t-b | --binary : write binary file (default)\n"
"\t-o | --outfile : output file (default=stdout)\n"
"\t-t | --text : rewrite as text\n"
" output in dot format using arcs\n"
" Omit properties in dot format\n"
"\t-v | --verbose : be loquacious\n");
if ((strcmp(argv
[i
], "-b") == 0) ||
(strcmp(argv
[i
], "--binary") == 0)) {
output_type
= Out_binary
;
if ((strcmp(argv
[i
], "-t") == 0) ||
(strcmp(argv
[i
], "--text") == 0)) {
if ((strcmp(argv
[i
], "-d") == 0) ||
(strcmp(argv
[i
], "--dot") == 0)) {
output_dot_dagp
= argv
[++i
];
if ((strcmp(argv
[i
], "-n") == 0) ||
(strcmp(argv
[i
], "--noprop") == 0)) {
if (output_type
!= Out_dot
) {
fprintf(stderr
, "Need to specify dot output \
format before -n/--noprop\n");
output_dot_flag_none
= true;
if ((strcmp(argv
[i
], "-v") == 0) ||
(strcmp(argv
[i
], "--verbose") == 0)) {
if (strcmp(argv
[i
], "-o") == 0 ||
strcmp(argv
[i
], "--outfile") == 0) {
if (argv
[i
][1] == 'o' && argv
[i
][2] != '\0') {
fatal("Unrecognised option %s\n", argv
[i
]);
fatal("Input filename name expected");
fatal("Cannot open input file %s", fnamep
);
/* remove prototypes after parse phase */
DBGD(dump_dag_nodes(stderr
));
DBGD(dump_dag_nodes(stderr
));
stichin_reqd_properties();
DBGD(dump_dag_nodes(stderr
));
if (fp
== NULL
) fatal("Opening %s for output", outfnp
);
/* no validation just yet */
dnp
= Xcalloc(1, dag_node_t
);
dnp
->properties
.space
= 0;
dnp
->properties
.listp
= NULL
;
dnp
->prevp
= dag_list_endp
;
dag_list_endp
->nextp
= dnp
;
add_pair_entry(pair_list_t
*plp
)
if (plp
->num
>= plp
->space
) {
plp
->space
= plp
->num
+ 5;
plp
->listp
= Xrealloc(plp
->listp
,
plp
->space
* sizeof (plp
->listp
[0]));
pep
= &(plp
->listp
[plp
->num
]);
find_pair_by_name(pair_list_t
*plp
, char *namep
)
for (i
= 0; i
< plp
->num
; i
++) {
if (strcmp(pep
->namep
, namep
) == 0)
find_dag_node_by_type(char *namep
)
for (dnp
= dag_listp
; dnp
!= NULL
; dnp
= dnp
->nextp
) {
if (strcmp(dnp
->typep
, namep
) == 0)
find_dag_node_by_name(char *namep
)
for (dnp
= dag_listp
; dnp
!= NULL
; dnp
= dnp
->nextp
) {
if (strcmp(dnp
->namep
, namep
) == 0)
dnp
= find_dag_node_by_name(lex
.strp
);
lex_fatal("%s: %s", message
, lex
.strp
);
lex_fatal("%s: %s", message
, lex
.strp
);
grab_prop(char *message
, dag_node_t
*node
)
pair_entry_t
*prop
= NULL
;
prop
= find_pair_by_name(&node
->properties
, lex
.strp
);
lex_fatal("%s: %s property must exist\n",
lex_fatal("%s: %s", message
, lex
.strp
);
for (dnp
= dag_listp
; dnp
!= NULL
; dnp
= dnp
->nextp
) {
fprintf(fp
, "node %s%s %s {\n", dnp
->is_proto
? " proto" : "",
fprintf(fp
, "node %s %s {\n", dnp
->typep
, dnp
->namep
);
pep
= dnp
->properties
.listp
;
for (i
= 0; i
< dnp
->properties
.num
; i
++) {
fprintf(fp
, "\t%s = \"%s\";\n", pep
->namep
,
fprintf(fp
, "\t%s = 0x%llx;\n", pep
->namep
,
fprintf(fp
, "\t%s -> %s;\n", pep
->namep
,
fprintf(fp
, "\t%s -> %s;\n", pep
->namep
,
fprintf(fp
, "\t%s = XXXXXXXX;\n", pep
->namep
);
fprintf(stderr
, "%s:%d: Bad Encoding.. %d\n",
__FILE__
, __LINE__
, pep
->utype
);
free_node(dag_node_t
*dnp
)
for (i
= 0; i
< dnp
->properties
.num
; i
++) {
pep
= &(dnp
->properties
.listp
[i
]);
fatal("free_node: node %s : %d : PE_none element",
fatal("free_node: node %s : %d : PE_arc element",
fatal("free_node: node %s : %d : unknown type %d",
dnp
->namep
, i
, pep
->utype
);
Xfree(dnp
->properties
.listp
);
for (dnp
= dag_listp
; dnp
!= NULL
; dnp
= dnp
->nextp
, idx
++) {
/* Give this node an id number */
/* stitch all property node references */
if (dnp
->properties
.num
> 0) {
for (i
= 0; i
< dnp
->properties
.num
; i
++) {
pep
= &(dnp
->properties
.listp
[i
]);
if (pep
->utype
== PE_noderef
) {
rnp
= find_dag_node_by_name(
fprintf(errfp
, "Referenced "
* We must have a "root" node ... look for it,
* and hike it to the first entry in the table.
stichin_reqd_properties(void)
dnp
= find_dag_node_by_type("root");
fatal("A root node is required for a valid description");
* Hike the root node to be the first element.
if (dnp
->prevp
!= NULL
) {
dnp
->prevp
->nextp
= dnp
->nextp
;
if (dnp
->nextp
!= NULL
) {
dnp
->nextp
->prevp
= dnp
->prevp
;
dag_list_endp
= dnp
->prevp
;