* ========== Copyright Header Begin ==========================================
* Hypervisor Software File: defines.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 ============================================
* @(#)defines.c 1.3 03/08/20
* Copyright 2001-2003 Sun Microsystems, Inc. All Rights Reserved
* Copyright Use is subject to license terms.
static define_t
*symbol_root
= NULL
;
/* find a symbol by name and return a pointer to it or NULL if not found */
define_t
*ptr
= symbol_root
;
if (strcmp(ptr
->name
, name
) == 0) {
* define a symbol, the data part follows the optional '=' sign.
* the type is just used to track where the symbol was defined - on the
* command line or by upload from the forth engine.
define_symbol(char *name
, int type
)
valuep
= strchr(tname
, '=');
valuep
= strdup(valuep
+1);
if ((new->type
!= FORTH_UNDEF
) && (new->type
!= CMD_UNDEF
)) {
fprintf(stderr
, "Warning redefining %s\n", name
);
if (new->value
!= NULL
) {
new = malloc(sizeof (define_t
));
if (symbol_root
!= NULL
) {
* 'un'def a symbol, type tracks where the 'undef' was executed from
* either the command line or the forth engine.
undef_symbol(char *name
, int type
)
define_t
*which
, *prev
, *next
;
which
= find_symbol(name
);
prev
->next
= which
->next
;
next
->prev
= which
->prev
;
if (which
->value
!= NULL
) {
define_symbol(name
, type
);
/* return true/false to test for a symbol existence */
symbol_defined(char *name
)
found
= find_symbol(name
);
return ((found
!= NULL
) &&
(found
->type
!= FORTH_UNDEF
) &&
(found
->type
!= CMD_UNDEF
));
/* return a pointer to a symbols data, return NULL if there is none. */
extract_symbol(char *name
)
which
= find_symbol(name
);
/* a debug routine to show a symbol, its data and where is was defined */
show_symbol(define_t
*ptr
)
type
= "[cmd line, defined]";
type
= "[cmd line, undef]";
type
= "[Forth defined]";
type
= "[Forth undefined]";
type
= "[invalid define type]";
if (ptr
->value
== NULL
) {
fprintf(stderr
, "%-20.20s %-20.20s %s\n", ptr
->name
, type
, value
);
* release all resources used by symbols, optionally printing the information
* about the symbol use - called when the wrapper exits.
define_t
*ptr
= symbol_root
;
fprintf(stderr
, "%-20.20s %-20.20s %s\n",
"Symbols", "location", "type/value");
define_t
*next
= ptr
->next
;
if (ptr
->value
!= NULL
) {