Skip to content
search.c 1.13 KiB
Newer Older
ram's avatar
ram committed
/*

 This code was written as part of the CMU Common Lisp project at
 Carnegie Mellon University, and has been placed in the public domain.

*/

rtoy's avatar
rtoy committed
#include <string.h>
wlott's avatar
wlott committed
#include "lisp.h"
#include "internals.h"
#include "os.h"
#include "search.h"

boolean
search_for_type(int type, lispobj ** start, int *count)
wlott's avatar
wlott committed
{
    lispobj obj, *addr;

    while ((*count == -1 || (*count > 0)) &&
	   valid_addr((os_vm_address_t) * start)) {
	obj = **start;
	addr = *start;
	if (*count != -1)
	    *count -= 2;
wlott's avatar
wlott committed

	if (TypeOf(obj) == type)
	    return TRUE;
wlott's avatar
wlott committed

wlott's avatar
wlott committed
    }
    return FALSE;
}


boolean
search_for_symbol(char *name, lispobj ** start, int *count)
wlott's avatar
wlott committed
{
    struct symbol *symbol;
    struct vector *symbol_name;

    while (search_for_type(type_SymbolHeader, start, count)) {
	symbol = (struct symbol *) PTR((lispobj) * start);
wlott's avatar
wlott committed
	if (LowtagOf(symbol->name) == type_OtherPointer) {
	    symbol_name = (struct vector *) PTR(symbol->name);
	    if (valid_addr((os_vm_address_t) symbol_name) &&
wlott's avatar
wlott committed
		TypeOf(symbol_name->header) == type_SimpleString &&
		strcmp((char *) symbol_name->data, name) == 0)
		return TRUE;
wlott's avatar
wlott committed
	}
wlott's avatar
wlott committed
    }
    return FALSE;
}