* ========== Copyright Header Begin ==========================================
* Hypervisor Software File: mdparse.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 "@(#)mdparse.c 1.7 07/06/07 SMI"
static bool_t
get_token_value(pair_entry_t
*pep
, lexer_tok_t tok
);
#if ENABLE_LOOKUP /* { */
parse_lookup(pair_entry_t
*pep
)
src
= grab_node("lookup(<node>, <property): bad node");
prop
= grab_prop("lookup(<node>, <property): bad property", src
);
pep
->utype
= prop
->utype
;
parse_expr(pair_entry_t
*ipep
)
pair_entry_t mypp
, pp
, *opep
= &pp
, *pep
= &mypp
;
pep
->namep
= ipep
->namep
;
opep
->namep
= ipep
->namep
;
str
[idx
] = Xstrdup(lstr
);
type
= (((pep
->utype
== PE_int
) ||
(pep
->utype
== PE_none
)) ?
type
= (((pep
->utype
== PE_string
) ||
(pep
->utype
== PE_none
)) ?
lex_fatal("Bad EXPR type: %d\n",
lex_fatal("Bad expression: %s", lex
.strp
);
if (tok
== T_R_Bracket
) {
if (pep
->utype
== PE_int
) {
pep
->u
.strp
= Xstrdup(str
[0]);
printf("EXPR_OP: idx == 0???\n");
type
= ((pep
->utype
== PE_int
) ?
pep
->u
.val
= n
[0] - n
[1];
pep
->u
.val
= n
[0] ^ n
[1];
pep
->u
.val
= n
[0] | n
[1];
pep
->u
.val
= n
[0] & n
[1];
pep
->u
.val
= n
[0] + n
[1];
pep
->u
.val
= n
[0] * n
[1];
pep
->u
.val
= n
[0] << n
[1];
char *dst
= Xmalloc(strlen(str
[0]) +
sprintf(dst
, "%s%s", str
[0], str
[1]);
lex_fatal("Expression syntax error");
if (pep
->utype
== PE_int
) {
printf("Int Expr: %llx\n", pep
->u
.val
);
printf("Str Expr: [%s]\n", pep
->u
.strp
);
clone_pair_entry(pair_list_t
*plp
, pair_entry_t
*pep
)
np
= add_pair_entry(plp
);
np
->namep
= Xstrdup(pep
->namep
);
np
->u
.strp
= Xstrdup(pep
->u
.strp
);
memmove(np
->u
.data
.buffer
, pep
->u
.data
.buffer
, pep
->u
.data
.len
);
np
->u
.data
.len
= pep
->u
.data
.len
;
fatal("clone_pair_entry: Internal error: unexpected type %d\n",
parse_include(dag_node_t
*dnp
)
src
= grab_node("include <node>: bad node");
pep
= grab_prop("lookup(<node>, <property>): bad property",
/* be careful.. clone_pair_entry does a Realloc */
clone_pair_entry(&dnp
->properties
, pep
);
lex_fatal("include: <node>[, <property>]; syntax error");
for (i
= 0; i
< n
; i
++) {
/* be careful.. clone_pair_entry does a Realloc */
clone_pair_entry(&dnp
->properties
, &(plp
->listp
[i
]));
parse_data(pair_entry_t
*pep
)
* FIXME: not true anymore.
* represented as ints, upper zero bytes are discarded.
* [0] is a single zero byte
* [01020304] is 01,02,03,04, the upper 32bits were discarded.
pp
.utype
= PE_none
; /* SANITY */
ok
= get_token_value(&pp
, tok
);
if (!ok
) lex_fatal("Illegal assignment expression");
for (n
= 7; n
> 0; n
--) {
if ((pp
.u
.val
>> (8*n
)) != 0) break;
if (pep
->u
.data
.len
+n
+1 >= MAX_DATALEN
)
lex_fatal("Internal error; out of data space");
pep
->u
.data
.buffer
[pep
->u
.data
.len
++] =
(uint8_t)(pp
.u
.val
>> (8*n
));
if (pep
->u
.data
.len
+n
>= MAX_DATALEN
)
lex_fatal("Internal error; out of data space");
memmove(&(pep
->u
.data
.buffer
[pep
->u
.data
.len
]),
lex_fatal("data concat unimplemented !");
lex_fatal("invalid data entry");
/* Look for a comma, or R brace */
if (tok
!= T_Comma
&& tok
!= T_R_Brace
)
lex_fatal("Syntax error; comma or } expected");
} while (tok
!= T_R_Brace
);
if (pep
->u
.data
.len
== 0) {
lex_fatal("Empty data encoding");
get_token_value(pair_entry_t
*pep
, lexer_tok_t tok
)
pep
->u
.strp
= Xstrdup(lex
.strp
);
do_assignment(pair_entry_t
*pep
, bool_t fn
)
if (tok
== T_S_Colon
) lex_fatal("empty assignment");
if (tok
== T_Comma
) lex_fatal("invalid compound data");
if (fn
&& (tok
== T_R_Bracket
)) lex_fatal("missing argument");
ok
= get_token_value(&pp
, tok
);
if (!ok
) lex_fatal("Illegal assignment expression");
* first iteration, copy data,
* this is the 'normal' path.
pp
.namep
= NULL
; /* cleanup */
pp
.utype
= PE_none
; /* cleanup */
pp
.u
.strp
= NULL
; /* cleanup in case of a str */
/* FIXME: memory order !! */
d
= mypp
.u
.val
; /* move to be copy safe */
memmove(mypp
.u
.data
.buffer
, &d
, len
);
* an append onto a string.
memmove(mypp
.u
.data
.buffer
, src
, len
);
ASSERT(mypp
.utype
== PE_data
);
len
= strlen(pp
.u
.strp
) + 1;
lex_fatal("improper concatination");
if ((mypp
.u
.data
.len
+ len
) >= MAX_DATALEN
)
lex_fatal("compound data too long");
dest
= &(mypp
.u
.data
.buffer
[mypp
.u
.data
.len
]);
memmove(dest
, &pp
.u
.val
, len
);
memmove(dest
, pp
.u
.strp
, len
);
memmove(dest
, pp
.u
.data
.buffer
, len
);
lex_fatal("improper concatination");
if ((tok
== T_S_Colon
) || (fn
&& (tok
== T_R_Bracket
))) {
lex_fatal("invalid compound expression");
#if ENABLE_SETPROP /* { */
src
= grab_node("setprop(<node>, <property>, <value>): bad node");
pep
= grab_prop("setprop(<node>, <property>, <value>): bad property",
do_assignment(pep
, true);
parse_dag(char *fnamep
, FILE *fp
)
init_lexer(fnamep
, fp
, NULL
);
while ((tok
= lex_get_token()) != T_EOF
) {
#if ENABLE_PROTO /* FIXME: delete enourage CPP macros { */
if ((tok
!= T_KW_node
) &&
lex_fatal("node definition expected");
lex_fatal("node definition expected");
dnp
->typep
= Xstrdup(lex
.strp
);
dnp
->namep
= Xstrdup(lex
.strp
);
while ((tok
= lex_get_token()) != T_R_Brace
) {
#if ENABLE_SETPROP /* FIXME: TBD delete in favour of variables { */
#if ENABLE_PROTO /* FIXME: use CPP macros instead */
pep
= add_pair_entry(&dnp
->properties
);
pep
->namep
= Xstrdup(lex
.strp
);
do_assignment(pep
, false);
pep
->u
.strp
= Xstrdup(lex
.strp
);
lex_fatal("property expected");