Пример #1
0
static rxt_node* get_internal(char *key, rxt_node *root)
{
    int equal = 1;
    char *route_token;
    char *route_token_ptr;
    char *request_token;
    char *request_token_ptr;
    char prefix;

    if (!root) return NULL;

    if (root->color) 
    {
        if (2 == root->color) 
        {
            root = (rxt_node *)root->value;
        }

        route_token = strtok_r(root->key, "/", &route_token_ptr);
        request_token = strtok_r(key, "/", &request_token_ptr);
        while (route_token != NULL && request_token != NULL)
        {
            if (route_token == NULL || request_token == NULL)
                break;

            prefix = *route_token;
            if (prefix == '$')
            {
                // Variable substitution.
            }
            else
            {
                if (strncasecmp(route_token, request_token, 0))
                {
                    equal = 0;
                    break;
                }
            }
            
            //printf ("ROUTE:%s\tREQUEST:%s\n", route_token, request_token);
            route_token = strtok_r(NULL, "/", &route_token_ptr);
            request_token = strtok_r(NULL, "/", &request_token_ptr);
        }

        if (equal)
        {
            return root;
        }
        return NULL;
    }

    if (get_bit_at(key, root->pos))
    {
        return get_internal(key, root->right);
    }
    return get_internal(key, root->left);
}
Пример #2
0
static rxt_node* get_internal(char *key, rxt_node *root)
{
    if (!root) return NULL;

    if (root->color) {
        if (2 == root->color) root = root->value;
        if (!strncmp(key, root->key, root->pos))
            return root;
        return NULL;
    }

    if (get_bit_at(key, root->pos))
        return get_internal(key, root->right);
    return get_internal(key, root->left);
}
Пример #3
0
    int main(int argc, char **argv) {

        initiate(argc, argv); /* initialize executor */
        #ifndef BASIC
        socket_setup();
        network_socket = socket_connect();
        #endif
        runsys(); /* initialize running system */
        if (has_network_socket()) {
            request_id();
            GraphRes = get_graph_res();
            graph_setstatus();
            if (GraphRes < 0) exit(12);
            if (remote) send_ready();
        }

        setjmp (contenv); /* set label for continue long jump */
        while (TRUE) { /* repeat until exit() is called */
            get_internal();
            schedule(); /* reschedule current process */
            if (ready != 0) {
                decode(); /* fetch instruction */
                execute(); /* and execute it */
            }
        }
        return 0;
    } /* end main */
Пример #4
0
void* rxt_get(char *key, rxt_node *root)
{
    rxt_node *n = get_internal(key, root);
    if (!n) return NULL;
    return n->value;
}
Пример #5
0
void* rxt_delete(char *key, rxt_node *root)
{
    rxt_node *parent, *grandparent;
    rxt_node *n = get_internal(key, root);
    void *v;
    char *newkey = NULL;
    if (!n) return NULL; // nonexistent

    v = n->value;

    // remove both the node and the parent inner node
    // XXX TODO FIXME Still somewhat broken. Figure out.
    parent = n->parent;
    grandparent = parent->parent;

    if (!grandparent) {
        if (parent->left == n) {
            return delete_internal(n, parent->right);
        } else if (parent->right == n) {
            return delete_internal(n, parent->left);
        } else if (parent->value == n) {
            parent->value = NULL;
            parent->color = 0;
            parent->pos = 0;
        } else
            printf("something very wrong when removing w/o gp!\n");

        free(n);
        return v;
    }

    // properly move around pointers and shit
    // TODO ascii art
    if (grandparent->left == n->parent) {
        newkey = grandparent->right->key; // not sure if this is correct
        if (parent->left == n) {
            grandparent->left = parent->right;
            parent->right->parent = grandparent;
        } else if (parent->right == n) {
            grandparent->left = parent->left;
            parent->left->parent = grandparent;
        } else
            printf("something very wrong: removing grandparent->left\n");
    } else if (grandparent->right == n->parent) {
        newkey = grandparent->left->key;
        if (parent->left == n ) {
            grandparent->right = parent->right;
            parent->right->parent = grandparent;
        } else if (parent->right == n) {
            grandparent->right = parent->left;
            parent->left->parent = grandparent;
        } else
            printf("something very wrong: removing grandparent->right\n");
    } else
        printf("something very wrong: grandparent does not possess child\n");

    reset_key(n->key, newkey, grandparent);
    parent->left = NULL;
    parent->right = NULL;
    free(parent);
    free(n); // we don't dynamically allocate node

    return v;
}
Пример #6
0
	Value get(const Value& self, Symbol member) {
		return get_internal(self.value(), member);
	}