Beispiel #1
0
void insert_rec_adjust(int node_idx, long *parents, int parent_cnt, int *parent_is, int parent_i_cnt) {
	int i;

	node_t node;
	node.idx = node_idx;
	load_node(&node);

	if (node.rec_cnt <= ORDER_2) return;

	rec_t mid_rec = node.recs[ORDER];

	node_t left;
	for (i=0;i<ORDER;i++) left.recs[i] = node.recs[i];
	left.rec_cnt = ORDER;
	for (i=0;i<node.child_cnt/2;i++) left.childs[i] = node.childs[i];
	left.child_cnt = node.child_cnt/2;

	add_node(&left);

	node_t right;
	for (i=ORDER+1;i<node.rec_cnt;i++) right.recs[i-(ORDER+1)] = node.recs[i];
	right.rec_cnt = ORDER;
	for (i=node.child_cnt/2;i<node.child_cnt;i++) right.childs[i-(node.child_cnt/2)] = node.childs[i];
	right.child_cnt = node.child_cnt/2;

	add_node(&right);

	node.childs[0] = left.idx;
	node.childs[1] = right.idx;
	node.child_cnt = 2;

	if (parent_cnt) {
		node_t parent;
		parent.idx = parents[0];
		load_node(&parent);

		int parent_i = parent_is[0];

		for (i=parent.rec_cnt-1;i>=parent_i;i--) parent.recs[i+1] = parent.recs[i];
		parent.rec_cnt++;
		parent.recs[parent_i] = mid_rec;

		for (i=parent.child_cnt-1;i>=(parent_i+1);i--) parent.childs[i+1] = parent.childs[i];
		parent.child_cnt++;
		parent.childs[parent_i] = left.idx;
		parent.childs[parent_i+1] = right.idx;

		save_node(&parent);

		insert_rec_adjust(parent.idx, parents+1, parent_cnt-1, parent_is+1, parent_i_cnt-1);
	} else {
		node.recs[0] = mid_rec;
		node.rec_cnt = 1;

		save_node(&node);
	}
}
Beispiel #2
0
int main (void) {
	PageManager* pm = new_page_manager(".");
	printf("I Made my pm\n");
	printf("My index path is: %s\n", pm->index_path);
	RawPage* new_page = new_data_page(pm);
	printf("new page fd is %d at memory addr %p\n", new_page->fd, new_page->page);
	// Save some strings
	PageRef* str_1 = save_string(new_page, "Hello There");
	PageRef* str_2 = save_string(new_page, "I am a second string");
	printf("Before unload page\n");
	unload_page(new_page);
	printf("After unloda page\n");
	// load some strings
	load_string(pm, str_1);
	load_string(pm, str_2);

	//make our tree page
	RawPage* t_page = new_tree_page(pm);
	TreeNode* test_node = malloc(sizeof(TreeNode));
	memset(test_node, 0, sizeof(TreeNode));
	test_node->size = 0;
	test_node->order = 2;
	test_node->num_leaves = 0;
	test_node->parent.page_type = 0xDE110;
	test_node->parent.page_num = 31337;
	test_node->parent.node_offset = 31337;
	PageRef* node1 = save_node(t_page, test_node);
	unload_page(t_page);
	load_node(pm, node1);

}
/* Load a YAML sequence into a Perl array */
SV *
load_sequence(perl_yaml_loader_t *loader)
{
    SV *node;
    AV *array = newAV();
    SV *array_ref = (SV *)newRV_noinc((SV *)array);
    char *anchor = (char *)loader->event.data.sequence_start.anchor;
    char *tag = (char *)loader->event.data.mapping_start.tag;
    if (anchor)
        hv_store(loader->anchors, anchor, strlen(anchor), SvREFCNT_inc(array_ref), 0);
    while ((node = load_node(loader))) {
        av_push(array, node);
    } 
    if (tag && strEQ(tag, TAG_PERL_PREFIX "array"))
        tag = NULL;
    if (tag) {
        char *class;
        char *prefix = TAG_PERL_PREFIX "array:";
        if (*tag == '!')
            prefix = "!";
        else if (strlen(tag) <= strlen(prefix) ||
            ! strnEQ(tag, prefix, strlen(prefix))
        ) croak(
            loader_error_msg(loader, form("bad tag found for array: '%s'", tag))
        );
        class = tag + strlen(prefix);
        sv_bless(array_ref, gv_stashpv(class, TRUE)); 
    }
    return array_ref;
}
Beispiel #4
0
int main(int argc, char *argv[])
{
	FILE *f;
	char buf[LINE];
	int n = 0;
	int n1, n2;
	
	srand(time(NULL));
	f = fopen(argv[1], "r");
	if (f == NULL)
		return errno;
	while (fgets(buf, LINE, f)) {
		load_node(buf, &nodes[n]);
		n++;
	}
	fclose(f);
	max_nodes = num_nodes = n;

	while (num_nodes > 2) {
		pick_edge(&n1, &n2);
		merge_nodes(n1, n2);
	}

	print_graph();

	return 0;
}
Beispiel #5
0
indexed_force_tri_3D* load_node(std::ifstream& in, QT_TRI_NODE* current_node, 
							    indexed_force_tri_3D* current_tri,
							    point_cloud* pPC)
{
	// assign the current data
	(*current_node->get_data()) = *current_tri;
	// get the next triangle in the file
	indexed_force_tri_3D* next_tri = new indexed_force_tri_3D;
	next_tri->load(in, pPC);
	// check the current triangle label against the previous triangle label
	if (next_tri->get_label().size() == current_tri->get_label().size() || in.eof())
		// occur at same level so do not create any children
		return next_tri;
	if (next_tri->get_label().size() > current_tri->get_label().size())
	{
		// do not occur at same level so add children and start the recursion
		for (int i=0; i<4; i++)
		{
			// add child and assign the next triangle to it
			current_node = current_node->add_child(indexed_force_tri_3D());
			next_tri = load_node(in, current_node, next_tri, pPC);
			// need to go back up to the parent node so as to create the siblings correctly
			// otherwise we would be reproducing with our own siblings
			if (current_node->get_parent() != NULL)
				current_node = current_node->get_parent();
		}
	}
	// control will never reach here but will return next_tri anyway to avoid warnings
	return next_tri;
}
Beispiel #6
0
void tri_grid::load(std::string filename)
{
	std::cout << "# Loading mesh" << std::endl;
	// do this as a text file first
	std::ifstream in;
	in.open(filename.c_str(), std::ios::in | std::ios::binary);
	if (!in)
		throw(std::string("Loading mesh.  File could not be opened ") + filename);
	meta_data = read_meta_data(in);
	// read in the point cloud
	point_cloud_instance.load(in);
	// read in the number of triangle roots
	int n_tris = read_int(in);
	// create the quad trees for the triangle roots
	// start with the first triangle
	indexed_force_tri_3D* current_tri = new indexed_force_tri_3D;
	current_tri->load(in, &point_cloud_instance);
	// now loop through the rest of the triangles
	for (int i=0; i<(int)(n_tris); i++)
	{
		triangles.push_back(new quadtree<indexed_force_tri_3D>);
		// get the current node as the first root node
		QT_TRI_NODE* current_node = triangles[i]->get_root();
		current_tri = load_node(in, current_node, current_tri, &point_cloud_instance);
	}
	in.close();
}
Beispiel #7
0
int insert_rec_2(long node_idx, rec_t *rec, long *parents, int parent_cnt, int *parent_is, int parent_i_cnt) {
	int i;

	node_t node;
	node.idx = node_idx;
	load_node(&node);

	for (i=0;i<node.rec_cnt;i++) {
		int cmped = rec_cmp(&node.recs[i], rec);

		if (cmped > 0) break;
		else if (cmped == 0) return -1;
	}

	int cur_i = i;

	if (node.child_cnt) {
		fseek(fp, node.idx*sizeof(node_t), SEEK_SET);
		fwrite(&node, sizeof(node), 1, fp);

		parents[-1] = node.idx;
		parent_is[-1] = cur_i;
		return insert_rec_2(node.childs[i], rec, parents-1, parent_cnt+1, parent_is-1, parent_i_cnt+1);
	} else {
		for (i=node.rec_cnt-1;i>=cur_i;i--) node.recs[i+1] = node.recs[i];
		node.rec_cnt++;
		node.recs[cur_i] = *rec;

		fseek(fp, node.idx*sizeof(node_t), SEEK_SET);
		fwrite(&node, sizeof(node), 1, fp);

		insert_rec_adjust(node_idx, parents, parent_cnt, parent_is, parent_i_cnt);
		return 0;
	}
}
Beispiel #8
0
void print_node_2(FILE *fp, int node_idx) {
	int i;

	node_t node;
	node.idx = node_idx;
	load_node(&node);

//	printf("(");

	bool done = false;
	i = 0;
	while (i < ORDER_3) {
		if (i < node.child_cnt) {
			if (done) fprintf(fp, "%s", DELIMITER);
			done = true;

			print_node_2(fp, node.childs[i]);
		}

		if (i < node.rec_cnt) {
			if (done) fprintf(fp, "%s", DELIMITER);
			done = true;

//			rec_print(&node.recs[i]);
			fprintf(fp, "%s", node.recs[i].name);
		}

		i++;
	}

//	printf(")");
}
/*
 * Load a YAML mapping into a Perl hash
 */
SV *
load_mapping(perl_yaml_loader_t *loader, char *tag)
{
    SV *key_node;
    SV *value_node;
    HV *hash = newHV();
    SV *hash_ref = (SV *)newRV_noinc((SV *)hash);
    char *anchor = (char *)loader->event.data.mapping_start.anchor;

    if (!tag)
        tag = (char *)loader->event.data.mapping_start.tag;

    /* Store the anchor label if any */
    if (anchor)
        hv_store(loader->anchors, anchor, strlen(anchor), SvREFCNT_inc(hash_ref), 0);

    /* Get each key string and value node and put them in the hash */
    while ((key_node = load_node(loader))) {
        assert(SvPOK(key_node));
        value_node = load_node(loader);
        hv_store_ent(
            hash, key_node, value_node, 0
        );
    } 

    /* Deal with possibly blessing the hash if the YAML tag has a class */
    if (tag && strEQ(tag, TAG_PERL_PREFIX "hash"))
        tag = NULL;
    if (tag) {
        char *class;
        char *prefix = TAG_PERL_PREFIX "hash:";
        if (*tag == '!') {
            prefix = "!";
        }
        else if (strlen(tag) <= strlen(prefix) ||
            ! strnEQ(tag, prefix, strlen(prefix))
        ) croak(
            loader_error_msg(loader, form("bad tag found for hash: '%s'", tag))
        );
        class = tag + strlen(prefix);
        sv_bless(hash_ref, gv_stashpv(class, TRUE)); 
    }

    return hash_ref;
}
/*!--------------------------------------------------------------------------
  @brief	Starts the dialog
  @param	other		The npc name
  @param	act			The act number
  @return 	Void

  Cleans up the dialog parser.

\-----------------------------------------------------------------------------*/
void start_dialog(char *other, int act) {

	// if we've previous been in dialog free up memory
	if (dialog) {
		SSL_IniFile_Destroy(dialog);
	}

	// load the dialog
	dialog = SSL_IniFIle_Create();

	// exceptions to the rules
	char path[100];
	if (strcmp(other, "dutchess") == 0 && get_current_act() == 4 && get_current_mission() == 2) {
		sprintf(path, "%s%s%i_2.ini", dialog_path, other, act);
	} else if (act == 10) {
		sprintf(path, "%saccuse_%s.ini", dialog_path, other);
	} else if (act == 11) {
		sprintf(path, "%sGeneral_finale.ini", dialog_path);
	} else if (act == 12){
		sprintf(path, "%sAssistant_dialogue.ini", dialog_path);
	} else {
		sprintf(path, "%s%s%i.ini", dialog_path, other, act);
	}

	// if the file for the npc + act exists load that one
	if( access( path, F_OK ) != -1 ) {
		SSL_IniFile_Load(dialog, path);
		load_node("root");
	} else {

		// else check for just the npc name
		sprintf(path, "%s%s.ini", dialog_path, other);
		if( access( path, F_OK ) != -1 ) {
		} else {
			sprintf(path, "%s%s.ini", dialog_path, "test_dialogue");
		}

		// load in the fil
		SSL_IniFile_Load(dialog, path);

		// load the root node
		load_node("root");
	}
}
Beispiel #11
0
void responder_init_serialization(DSLink *link, DSNode *root) {
    DSNode *node = dslink_node_create(root, "saved", "node");

    // data for serialization testing
    dslink_node_set_meta_new(link, node, "$$$password", json_string_nocheck("Test1234"));
    // load the data after set password to test if the deserialization is correct
    load_node(link, node);
    dslink_node_set_meta_new(link, node, "$writable", json_string_nocheck("write"));
    dslink_node_set_meta_new(link, node, "$type", json_string_nocheck("string"));
    if (dslink_node_add_child(link, node) != 0) {
        log_warn("Failed to add the serialization node to the root\n");
        dslink_node_tree_free(link, node);
    }

    node->on_data_changed = on_node_changed;
}
Beispiel #12
0
int search_rec(long node_idx, rec_t *rec) {
	int i;

	node_t node;
	node.idx = node_idx;
	load_node(&node);

	for (i=0;i<node.rec_cnt;i++) {
		int cmped = rec_cmp(&node.recs[i], rec);

		if (cmped > 0) {
			if (node.child_cnt) return search_rec(node.childs[i], rec);
			else return -1;
		} else if (cmped == 0) {
			*rec = node.recs[i];
			return 0;
		}
	}

	if (node.child_cnt) return search_rec(node.childs[node.child_cnt-1], rec);
	else return -1;
}
Beispiel #13
0
int get_cnt(int node_idx) {
	node_t node;
	node.idx = node_idx;
	load_node(&node);

	int res = 0;

	int i;
	i = 0;
	while (i < ORDER_3) {
		if (i < node.child_cnt) {
			res += get_cnt(node.childs[i]);
		}

		if (i < node.rec_cnt) {
			res++;
		}

		i++;
	}

	return res;
}
/*
 * This is the main Load function.
 * It takes a yaml stream and turns it into 0 or more Perl objects.
 */
void
Load(SV *yaml_sv)
{
    dXSARGS;
    perl_yaml_loader_t loader;
    SV *node;
    char *yaml_str;
    STRLEN yaml_len;
    
    /* If UTF8, make copy and downgrade */
    if (SvPV_nolen(yaml_sv) && SvUTF8(yaml_sv)) {
        yaml_sv = sv_mortalcopy(yaml_sv);
    }
    yaml_str = SvPVbyte(yaml_sv, yaml_len);

    sp = mark;
    if (0 && (items || ax)) {} /* XXX Quiet the -Wall warnings for now. */

    yaml_parser_initialize(&loader.parser);
    loader.document = 0;
    yaml_parser_set_input_string(
        &loader.parser,
        (unsigned char *)yaml_str,
        yaml_len
    );

    /* Get the first event. Must be a STREAM_START */
    if (!yaml_parser_parse(&loader.parser, &loader.event))
        goto load_error;
    if (loader.event.type != YAML_STREAM_START_EVENT)
        croak(ERRMSG "Expected STREAM_START_EVENT; Got: %d != %d",
            loader.event.type,
            YAML_STREAM_START_EVENT
         );

    loader.anchors = newHV();
    sv_2mortal((SV*)loader.anchors);

    /* Keep calling load_node until end of stream */
    while (1) {
        loader.document++;
        if (!yaml_parser_parse(&loader.parser, &loader.event))
            goto load_error;
        if (loader.event.type == YAML_STREAM_END_EVENT)
            break;
        node = load_node(&loader);
        hv_clear(loader.anchors);
        if (! node) break;
        XPUSHs(sv_2mortal(node));
        if (!yaml_parser_parse(&loader.parser, &loader.event))
            goto load_error;
        if (loader.event.type != YAML_DOCUMENT_END_EVENT)
            croak(ERRMSG "Expected DOCUMENT_END_EVENT");
    }

    /* Make sure the last event is a STREAM_END */
    if (loader.event.type != YAML_STREAM_END_EVENT)
        croak(ERRMSG "Expected STREAM_END_EVENT; Got: %d != %d",
            loader.event.type,
            YAML_STREAM_END_EVENT
         );
    yaml_parser_delete(&loader.parser);
    PUTBACK;
    return;

load_error:
    croak(loader_error_msg(&loader, NULL));
}
/*!--------------------------------------------------------------------------
  @brief	Dialog event handler
  @param	event		The event queue
  @return 	Void

  Handles events for the dialog parser.

\-----------------------------------------------------------------------------*/
int update_dialog(SDL_Event event) {

	// if we are not on the last page allow defualt to "press one for next page"
	if (current_page_number < number_of_pages && number_of_lines > 1 && current_line + max_lines_per_page < number_of_lines) {
		if (SSL_Keybord_Keyname_Pressed("_1", event)) {
			current_line += max_lines_per_page;
			current_page_number++;
		}

	// else we are on the last page
	} else {

		// if we don't have options, progress or exit convo based on action
		if (option_count == 0) {
			if (SSL_Keybord_Keyname_Pressed("_1", event)) {
				char *action = SSL_IniFile_GetString(dialog, current_node, "action", "end");
				if (strcmp(action, "end") == 0) {
					return 0;
				} else {
					load_node(action);
				}
			}

		// else we have options, load in when the 1 - 9 button is pressed and perform tehe corrosponding action
		} else {

			char *action = "null";

			if (SSL_Keybord_Keyname_Pressed("_1", event)) {
				action = SSL_IniFile_GetString(dialog, current_node, "option_1_action", "null");
			}
			if (SSL_Keybord_Keyname_Pressed("_2", event)) {
				action = SSL_IniFile_GetString(dialog, current_node, "option_2_action", "null");
			}
			if (SSL_Keybord_Keyname_Pressed("_3", event)) {
				action = SSL_IniFile_GetString(dialog, current_node, "option_3_action", "null");
			}
			if (SSL_Keybord_Keyname_Pressed("_4", event)) {
				action = SSL_IniFile_GetString(dialog, current_node, "option_4_action", "null");
			}
			if (SSL_Keybord_Keyname_Pressed("_5", event)) {
				action = SSL_IniFile_GetString(dialog, current_node, "option_5_action", "null");
			}
			if (SSL_Keybord_Keyname_Pressed("_6", event)) {
				action = SSL_IniFile_GetString(dialog, current_node, "option_6_action", "null");
			}
			if (SSL_Keybord_Keyname_Pressed("_7", event)) {
				action = SSL_IniFile_GetString(dialog, current_node, "option_7_action", "null");
			}
			if (SSL_Keybord_Keyname_Pressed("_8", event)) {
				action = SSL_IniFile_GetString(dialog, current_node, "option_8_action", "null");
			}
			if (SSL_Keybord_Keyname_Pressed("_9", event)) {
				action = SSL_IniFile_GetString(dialog, current_node, "option_9_action", "null");
			}

			// if null do nothing else perform the action
			if (strcmp(action, "null") == 0) {

			} else if (strcmp(action, "end") == 0) {
				return 0;
			} else {
				load_node(action);
			}
		}
	}

	// return 1 by default
	return 1;
}
Beispiel #16
0
/*
 * Scan outbound, the call status is set in three counters: internet, ISDN and POTS (analogue modems).
 * For all systems the CM and Txx flags are checked and for official
 * FidoNet nodes the Zone Mail Hour wich belongs to the destination zone.
 * All nodes are qualified if there is a way to call them or not on this moment.
 * The method how to call a node is decided as well.
 *
 * On success, return 0.
 */
int outstat()
{
    int		    rc, first = TRUE, T_window, iszmh = FALSE;
    struct _alist   *tmp, *old;
    char	    digit[6], flstr[15], *temp, as[6], be[6], utc[6], flavor, *temp2, *fmt, *buf;
    time_t	    now;
    struct tm	    tm;
    int		    uhour, umin, thour, tmin;
    pp_list	    *tpl;
    faddr	    *fa;
    FILE	    *fp;
    DIR		    *dp = NULL;
    struct dirent   *de;
    struct stat	    sb;
    unsigned int    ibnmask = 0, ifcmask = 0, itnmask = 0, outsize = 0;
    nodelist_modem  **tmpm;

    for (tmpm = &nl_tcpip; *tmpm; tmpm=&((*tmpm)->next)) {
        if (strcmp((*tmpm)->name, "IBN") == 0)
            ibnmask = (*tmpm)->mask;
        if (strcmp((*tmpm)->name, "IFC") == 0)
            ifcmask = (*tmpm)->mask;
        if (strcmp((*tmpm)->name, "ITN") == 0)
            itnmask = (*tmpm)->mask;
    }
    now = time(NULL);
    gmtime_r(&now, &tm);    // UTC time
    uhour = tm.tm_hour;
    umin  = tm.tm_min;
    snprintf(utc, 6, "%02d:%02d", uhour, umin);
    Syslog('+', "Scanning outbound at %s UTC.", utc);
    nxt_hour = 24;
    nxt_min  = 0;
    inet_calls = isdn_calls = pots_calls = 0;

    /*
     *  Clear current table
     */
    for (tmp = alist; tmp; tmp = old) {
        old = tmp->next;
        free(tmp);
    }
    alist = NULL;

    if ((rc = scanout(each))) {
        Syslog('?', "Error scanning outbound, aborting");
        return rc;
    }

    /*
     * Check private outbound box for nodes in the setup.
     */
    temp = calloc(PATH_MAX, sizeof(char));
    snprintf(temp, PATH_MAX, "%s/etc/nodes.data", getenv("FTND_ROOT"));
    if ((fp = fopen(temp, "r")) == NULL) {
        Syslog('?', "Error open %s, aborting", temp);
        free(temp);
        return 1;
    }
    fread(&nodeshdr, sizeof(nodeshdr), 1, fp);
    fseek(fp, 0, SEEK_SET);
    fread(&nodeshdr, nodeshdr.hdrsize, 1, fp);

    while ((fread(&nodes, nodeshdr.recsize, 1, fp)) == 1) {
        if (strlen(nodes.OutBox)) {
            if (nodes.Crash)
                flavor = 'c';
            else if (nodes.Hold)
                flavor = 'h';
            else
                flavor = 'o';

            fa = (faddr *)malloc(sizeof(faddr));
            fa->name   = NULL;
            fa->domain = xstrcpy(nodes.Aka[0].domain);
            fa->zone   = nodes.Aka[0].zone;
            fa->net    = nodes.Aka[0].net;
            fa->node   = nodes.Aka[0].node;
            fa->point  = nodes.Aka[0].point;

            checkdir(nodes.OutBox, fa, flavor);
            if (fa->domain)
                free(fa->domain);
            free(fa);
        }
        fseek(fp, nodeshdr.filegrp + nodeshdr.mailgrp, SEEK_CUR);
    }
    fclose(fp);

    /*
     * Start checking T-Mail fileboxes
     */
    if (strlen(CFG.tmailshort) && (dp = opendir(CFG.tmailshort))) {
        Syslog('o', "Checking T-Mail short box \"%s\"", CFG.tmailshort);
        while ((de = readdir(dp))) {
            if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {
                snprintf(temp, PATH_MAX, "%s/%s", CFG.tmailshort, de->d_name);
                if (stat(temp, &sb) == 0) {
                    Syslog('o' ,"checking \"%s\"", de->d_name);
                    if (S_ISDIR(sb.st_mode)) {
                        int i;
                        char b=0;
                        for (i=0; (i<8) && (!b); ++i) {
                            char c = tolower(de->d_name[i]);
                            if ( (c<'0') || (c>'v') || ((c>'9') && (c<'a')) ) b=1;
                        }
                        if (de->d_name[8]!='.') b=1;
                        for (i=9; (i<11) && (!b); ++i) {
                            char c = tolower(de->d_name[i]);
                            if ( (c<'0') || (c>'v') || ((c>'9') && (c<'a')) ) b=1;
                        }
                        if (b) continue;
                        if (de->d_name[11]==0) flavor='o';
                        else if ((tolower(de->d_name[11])=='h') && (de->d_name[12]==0)) flavor='h';
                        else continue;
                        fa = (faddr*)malloc(sizeof(faddr));
                        fa->name = NULL;
                        fa->domain = NULL;
                        memset(&digit, 0, sizeof(digit));
                        digit[0] = de->d_name[0];
                        digit[1] = de->d_name[1];
                        fa->zone = strtol(digit, NULL, 32);
                        memset(&digit, 0, sizeof(digit));
                        digit[0] = de->d_name[2];
                        digit[1] = de->d_name[3];
                        digit[2] = de->d_name[4];
                        fa->net = strtol(digit, NULL, 32);
                        memset(&digit, 0, sizeof(digit));
                        digit[0] = de->d_name[5];
                        digit[1] = de->d_name[6];
                        digit[2] = de->d_name[7];
                        fa->node = strtol(digit, NULL, 32);
                        memset(&digit, 0, sizeof(digit));
                        digit[0] = de->d_name[9];
                        digit[1] = de->d_name[10];
                        fa->point = strtol(digit, NULL, 32);
                        if (SearchFidonet(fa->zone)) {
                            fa->domain = xstrcpy(fidonet.domain);
                            checkdir(temp, fa, flavor);
                        }
                        if (fa->domain)
                            free(fa->domain);
                        free(fa);
                    }
                }
            }
        }
        closedir(dp);
    }
    if (strlen(CFG.tmaillong) && (dp = opendir(CFG.tmaillong))) {
        temp2 = calloc(PATH_MAX, sizeof(char));
        Syslog('o', "Checking T-Mail long box \"%s\"", CFG.tmaillong);
        while ((de = readdir(dp))) {
            if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {
                snprintf(temp, PATH_MAX, "%s/%s", CFG.tmaillong, de->d_name);
                if (stat(temp, &sb) == 0) {
                    Syslog('o' ,"checking \"%s\"", de->d_name);
                    if (S_ISDIR(sb.st_mode)) {
                        char c, d;
                        int n;
                        snprintf(temp2, PATH_MAX, "%s", de->d_name);
                        fa = (faddr*)malloc(sizeof(faddr));
                        fa->name = NULL;
                        fa->domain = NULL;
                        n = sscanf(temp2, "%u.%u.%u.%u.%c%c", &(fa->zone), &(fa->net), &(fa->node), &(fa->point), &c, &d);
                        if ((n==4) || ((n==5) && (tolower(c)=='h'))) {
                            if (SearchFidonet(fa->zone)) {
                                fa->domain = xstrcpy(fidonet.domain);
                                if (n==4)
                                    flavor = 'o';
                                else
                                    flavor = 'h';
                                checkdir(temp, fa, flavor);
                            }
                        }
                        if (fa->domain)
                            free(fa->domain);
                        free(fa);
                    }
                }
            }
        }
        closedir(dp);
        free(temp2);
    }

    /*
     * During processing the outbound list, determine when the next event will occur,
     * ie. the time when the callout status of a node changes because of starting a
     * ZMH, or changeing the time window for Txx flags.
     */
    for (tmp = alist; tmp; tmp = tmp->next) {
        if (first) {
            Syslog('+', "Flavor Out        Size    Online    Modem     ISDN   TCP/IP Calls Status  Mode    Address");
            first = FALSE;
        }

        rc = load_node(tmp->addr);

        /*
         * Zone Mail Hours, only use Fidonet Hours.
         * Other nets use your default ZMH.
         */
        T_window = iszmh = FALSE;
        switch (tmp->addr.zone) {
        case 1:
            if (uhour == 9)
                iszmh = TRUE;
            set_next(9, 0);
            set_next(10, 0);
            break;
        case 2:
            if (((uhour == 2) && (umin >= 30)) || ((uhour == 3) && (umin < 30)))
                iszmh = TRUE;
            set_next(2, 30);
            set_next(3, 30);
            break;
        case 3:
            if (uhour == 18)
                iszmh = TRUE;
            set_next(18, 0);
            set_next(19, 0);
            break;
        case 4:
            if (uhour == 8)
                iszmh = TRUE;
            set_next(8, 0);
            set_next(9, 0);
            break;
        case 5:
            if (uhour == 1)
                iszmh = TRUE;
            set_next(1, 0);
            set_next(2, 0);
            break;
        case 6:
            if (uhour == 20)
                iszmh = TRUE;
            set_next(20, 0);
            set_next(21, 0);
            break;
        default:
            if (get_zmh())
                iszmh = TRUE;
            break;
        }

        if (tmp->t1 && tmp->t2) {
            /*
             * Txx flags, check callwindow
             */
            thour = toupper(tmp->t1) - 'A';
            if (isupper(tmp->t1))
                tmin = 0;
            else
                tmin = 30;
            snprintf(as, 6, "%02d:%02d", thour, tmin);
            set_next(thour, tmin);
            thour = toupper(tmp->t2) - 'A';
            if (isupper(tmp->t2))
                tmin = 0;
            else
                tmin = 30;
            snprintf(be, 6, "%02d:%02d", thour, tmin);
            set_next(thour, tmin);
            if (strcmp(as, be) > 0) {
                /*
                 * Time window is passing midnight
                 */
                if ((strcmp(utc, as) >= 0) || (strcmp(utc, be) < 0))
                    T_window = TRUE;
            } else {
                /*
                 * Time window is not passing midnight
                 */
                if ((strcmp(utc, as) >= 0) && (strcmp(utc, be) < 0))
                    T_window = TRUE;
            }
        }
        memset(&flstr, 0, sizeof(flstr));
        strncpy(flstr, "...... .... ..", 14);

        /*
         * If the node has internet and we have internet configured,
         * check if we can send immediatly. Works for CM and ICM.
         */
        if (TCFG.max_tcp && (tmp->can_ip && tmp->is_icm)  &&
                (((tmp->flavors) & F_IMM) || ((tmp->flavors) & F_CRASH) || ((tmp->flavors) & F_NORMAL)) &&
                ((tmp->ipflags & ibnmask) || (tmp->ipflags & ifcmask) || (tmp->ipflags & itnmask))) {
            tmp->flavors |= F_CALL;
        }

        /*
         * Immediate Mail check
         */
        if ((tmp->flavors) & F_IMM) {
            flstr[0]='D';
            /*
             * Immediate mail, send if node is CM or is in a Txx window or is in ZMH.
             */
            if (tmp->is_cm || T_window || iszmh) {
                tmp->flavors |= F_CALL;
            }
            /*
             * Now check again for the ICM flag.
             */
            if (tmp->is_icm && TCFG.max_tcp &&
                    ((tmp->ipflags & ibnmask) || (tmp->ipflags & ifcmask) || (tmp->ipflags & itnmask))) {
                tmp->flavors |= F_CALL;
            }
        }

        if ((tmp->flavors) & F_CRASH ) {
            flstr[1]='C';
            /*
             * Crash mail, send if node is CM or is in a Txx window or is in ZMH.
             */
            if (tmp->is_cm || T_window || iszmh) {
                tmp->flavors |= F_CALL;
            }
            /*
             * Now check again for the ICM flag.
             */
            if (tmp->is_icm && TCFG.max_tcp &&
                    ((tmp->ipflags & ibnmask) || (tmp->ipflags & ifcmask) || (tmp->ipflags & itnmask))) {
                tmp->flavors |= F_CALL;
            }
        }

        if ((tmp->flavors) & F_NORMAL)
            flstr[2]='N';
        if ((tmp->flavors) & F_HOLD  )
            flstr[3]='H';
        if ((tmp->flavors) & F_FREQ  )
            flstr[4]='R';
        if ((tmp->flavors) & F_POLL  ) {
            flstr[5]='P';
            tmp->flavors |= F_CALL;
        }

        if ((tmp->flavors) & F_ISFIL ) {
            flstr[7]='A';
            /*
             * Arcmail and maybe file attaches, send during ZMH or if node has a Txx window.
             */
            if ((iszmh || T_window) && !((tmp->flavors) & F_HOLD)) {
                tmp->flavors |= F_CALL;
            }
        }

        if ((tmp->flavors) & F_ISPKT ) {
            flstr[8]='M';
            /*
             * Normal mail, send during ZMH or if node has a Txx window.
             */
            if ((iszmh || T_window) && !((tmp->flavors) & F_HOLD)) {
                tmp->flavors |= F_CALL;
            }
        }

        if ((tmp->flavors) & F_ISFLO )
            flstr[9]='F';

        if (tmp->cst.tryno >= 30) {
            /*
             * Node is undialable, clear callflag
             */
            tmp->flavors &= ~F_CALL;
        }
        if (tmp->t1)
            flstr[12] = tmp->t1;
        if (tmp->t2)
            flstr[13] = tmp->t2;

        /*
         * If forbidden to call from setup, clear callflag.
         */
        if (nodes.NoCall)
            tmp->flavors &= ~F_CALL;

        /*
         * If we must call this node, figure out how to call this node.
         */
        if ((tmp->flavors) & F_CALL) {
            tmp->callmode = CM_NONE;

            if (TCFG.max_tcp && ((tmp->ipflags & ibnmask) || (tmp->ipflags & ifcmask) || (tmp->ipflags & itnmask))) {
                inet_calls++;
                tmp->callmode = CM_INET;
            }

            if ((tmp->callmode == CM_NONE) && isdn_lines) {
                /*
                 * If any matching port found, mark node ISDN
                 */
                for (tpl = pl; tpl; tpl = tpl->next) {
                    if (tmp->diflags & tpl->dflags) {
                        isdn_calls++;
                        tmp->callmode = CM_ISDN;
                        break;
                    }
                }
            }

            if ((tmp->callmode == CM_NONE) && pots_lines) {
                /*
                 * If any matching ports found, mark node POTS
                 */
                for (tpl = pl; tpl; tpl = tpl->next) {
                    if (tmp->moflags & tpl->mflags) {
                        pots_calls++;
                        tmp->callmode = CM_POTS;
                        break;
                    }
                }
            }

            /*
             * Here we are out of options, clear callflag.
             */
            if (tmp->callmode == CM_NONE) {
                buf = calloc(81, sizeof(char));
                fido2str_r(tmp->addr, 0x0f, buf);
                Syslog('!', "No method to call %s available", buf);
                free(buf);
                tmp->flavors &= ~F_CALL;
            }
        }

        if ((tmp->flavors) & F_CALL)
            flstr[10]='C';
        else
            /*
             * Safety, clear callmode.
             */
            tmp->callmode = CM_NONE;

        /*
         * Show callresult for this node.
         */
        outsize += (unsigned int)tmp->size;
        fmt = calloc(81, sizeof(char));
        buf = calloc(81, sizeof(char));
        size_str_r(tmp->size, fmt);
        fido2str_r(tmp->addr, 0x0f, buf);
        snprintf(temp, PATH_MAX, "%s %8s %08x %08x %08x %08x %5d %s %s %s", flstr, fmt,
                 (unsigned int)tmp->olflags, (unsigned int)tmp->moflags,
                 (unsigned int)tmp->diflags, (unsigned int)tmp->ipflags,
                 tmp->cst.tryno, callstatus(tmp->cst.trystat), callmode(tmp->callmode), buf);
        Syslog('+', "%s", temp);
        free(fmt);
        free(buf);

    } /* All nodes scanned. */

    if (nxt_hour == 24) {
        /*
         * 24:00 hours doesn't exist
         */
        nxt_hour = 0;
        nxt_min  = 0;
    }

    /*
     * Always set/reset semafore do_inet if internet is needed.
     */
    if (!IsSema((char *)"do_inet") && inet_calls) {
        CreateSema((char *)"do_inet");
        s_do_inet = TRUE;
        Syslog('c', "Created semafore do_inet");
    } else if (IsSema((char *)"do_inet") && !inet_calls) {
        RemoveSema((char *)"do_inet");
        s_do_inet = FALSE;
        Syslog('c', "Removed semafore do_inet");
    }

    /*
     * Update outbound size MIB
     */
    mib_set_outsize(outsize);

    /*
     * Log results
     */
    snprintf(waitmsg, 81, "Next event at %02d:%02d UTC", nxt_hour, nxt_min);
    Syslog('+', "Systems to call: Inet=%d, ISDN=%d, POTS=%d, Next event at %02d:%02d UTC",
           inet_calls, isdn_calls, pots_calls, nxt_hour, nxt_min);
    free(temp);
    return 0;
}
/*
 * This is the main Load function.
 * It takes a yaml stream and turns it into 0 or more Perl objects.
 */
void
Load(SV *yaml_sv)
{
    dXSARGS;
    perl_yaml_loader_t loader;
    SV *node;
    const unsigned char *yaml_str;
    STRLEN yaml_len;

    yaml_str = (const unsigned char *)SvPV_const(yaml_sv, yaml_len);

    if (DO_UTF8(yaml_sv)) {
        yaml_sv = sv_mortalcopy(yaml_sv);
        if (!sv_utf8_downgrade(yaml_sv, TRUE))
            croak("%s", "Wide character in YAML::XS::Load()");
        yaml_str = (const unsigned char *)SvPV_const(yaml_sv, yaml_len);
    }

    sp = mark;
    if (0 && (items || ax)) {} /* XXX Quiet the -Wall warnings for now. */

    yaml_parser_initialize(&loader.parser);
    loader.document = 0;
    yaml_parser_set_input_string(
        &loader.parser,
        yaml_str,
        yaml_len
    );

    /* Get the first event. Must be a STREAM_START */
    if (!yaml_parser_parse(&loader.parser, &loader.event))
        goto load_error;
    if (loader.event.type != YAML_STREAM_START_EVENT)
        croak("%sExpected STREAM_START_EVENT; Got: %d != %d",
            ERRMSG,
            loader.event.type,
            YAML_STREAM_START_EVENT
         );

    loader.anchors = newHV();
    sv_2mortal((SV *)loader.anchors);

    /* Keep calling load_node until end of stream */
    while (1) {
        loader.document++;
        /* We are through with the previous event - delete it! */
        yaml_event_delete(&loader.event);
        if (!yaml_parser_parse(&loader.parser, &loader.event))
            goto load_error;
        if (loader.event.type == YAML_STREAM_END_EVENT)
            break;
        node = load_node(&loader);
        /* We are through with the previous event - delete it! */
        yaml_event_delete(&loader.event);
        hv_clear(loader.anchors);
        if (! node) break;
        XPUSHs(sv_2mortal(node));
        if (!yaml_parser_parse(&loader.parser, &loader.event))
            goto load_error;
        if (loader.event.type != YAML_DOCUMENT_END_EVENT)
            croak("%sExpected DOCUMENT_END_EVENT", ERRMSG);
    }

    /* Make sure the last event is a STREAM_END */
    if (loader.event.type != YAML_STREAM_END_EVENT)
        croak("%sExpected STREAM_END_EVENT; Got: %d != %d",
            ERRMSG,
            loader.event.type,
            YAML_STREAM_END_EVENT
         );
    yaml_parser_delete(&loader.parser);
    PUTBACK;
    return;

load_error:
    croak("%s", loader_error_msg(&loader, NULL));
}
Beispiel #18
0
void remove_rec_adjust(long node_idx, long *parents, int parent_cnt, int *parent_is, int parent_i_cnt) {
	int i;

	node_t node;
	node.idx = node_idx;
	load_node(&node);

	node_t parent;
	parent.idx = parents[0];
	load_node(&parent);

	int parent_i = parent_is[0];

	if (!parent_cnt) {
		if (!node.rec_cnt && node.child_cnt) {
			root_idx = node.childs[0];
			set_node_unoccupied(node.idx);
		}
		return;
	}

	if (node.rec_cnt >= ORDER) return;

	if (parent_i+1 < parent.child_cnt) {
		node_t parent_child;
		parent_child.idx = parent.childs[parent_i+1];
		load_node(&parent_child);
		if (parent_child.rec_cnt > ORDER) {
			node.recs[node.rec_cnt++] = parent.recs[parent_i];
			if (parent_child.child_cnt) {
				node.childs[node.child_cnt++] = parent_child.childs[0];

				for (i=1;i<parent_child.child_cnt;i++) parent_child.childs[i-1] = parent_child.childs[i];
				parent_child.child_cnt--;
			}

			parent.recs[parent_i] = parent_child.recs[0];

			for (i=1;i<parent_child.rec_cnt;i++) parent_child.recs[i-1] = parent_child.recs[i];
			parent_child.rec_cnt--;

			save_node(&node);
			save_node(&parent);
			save_node(&parent_child);

			return;
		}
	}

	if (parent_i-1 >= 0) {
		node_t parent_child;
		parent_child.idx = parent.childs[parent_i-1];
		load_node(&parent_child);
		if (parent_child.rec_cnt > ORDER) {
			for (i=node.rec_cnt-1;i>=0;i--) node.recs[i+1] = node.recs[i];
			node.rec_cnt++;
			node.recs[0] = parent.recs[parent_i-1];

			if (parent_child.child_cnt) {
				for (i=node.child_cnt-1;i>=0;i--) node.childs[i+1] = node.childs[i];
				node.child_cnt++;

				node.childs[0] = parent_child.childs[parent_child.child_cnt-1];

				parent_child.child_cnt--;
			}

			parent.recs[parent_i-1] = parent_child.recs[parent_child.rec_cnt-1];

			parent_child.rec_cnt--;

			save_node(&node);
			save_node(&parent);
			save_node(&parent_child);

			return;
		}
	}

	if (parent_i+1 < parent.child_cnt) {
		node_t parent_child;
		parent_child.idx = parent.childs[parent_i+1];
		load_node(&parent_child);

		node.recs[node.rec_cnt++] = parent.recs[parent_i];
		for (i=0;i<parent_child.rec_cnt;i++) node.recs[node.rec_cnt++] = parent_child.recs[i];

		for (i=0;i<parent_child.child_cnt;i++) node.childs[node.child_cnt++] = parent_child.childs[i];

		for (i=parent_i+1;i<parent.rec_cnt;i++) parent.recs[i-1] = parent.recs[i];
		parent.rec_cnt--;

		set_node_unoccupied(parent.childs[parent_i+1]);
		for (i=parent_i+2;i<parent.child_cnt;i++) parent.childs[i-1] = parent.childs[i];
		parent.child_cnt--;

		save_node(&node);
		save_node(&parent);

		remove_rec_adjust(parent.idx, parents+1, parent_cnt-1, parent_is+1, parent_i_cnt-1);
		return;
	}

	if (parent_i-1 >= 0) {
		node_t parent_child;
		parent_child.idx = parent.childs[parent_i-1];
		load_node(&parent_child);

		for (i=0;i<node.rec_cnt;i++) node.recs[i+(parent_child.rec_cnt+1)] = node.recs[i];
		node.rec_cnt += (parent_child.rec_cnt+1);
		for (i=0;i<parent_child.rec_cnt;i++) node.recs[i] = parent_child.recs[i];
		node.recs[parent_child.rec_cnt] = parent.recs[parent_i-1];

		for (i=0;i<node.child_cnt;i++) node.childs[i+parent_child.child_cnt] = node.childs[i];
		node.child_cnt += parent_child.child_cnt;
		for (i=0;i<parent_child.child_cnt;i++) node.childs[i] = parent_child.childs[i];

		for (i=parent_i;i<parent.rec_cnt;i++) parent.recs[i-1] = parent.recs[i];
		parent.rec_cnt--;

		set_node_unoccupied(parent.childs[parent_i-1]);
		for (i=parent_i;i<parent.child_cnt;i++) parent.childs[i-1] = parent.childs[i];
		parent.child_cnt--;

		save_node(&node);
		save_node(&parent);

		remove_rec_adjust(parent.idx, parents+1, parent_cnt-1, parent_is+1, parent_i_cnt-1);
		return;
	}
}
Beispiel #19
0
void load_equation(Equation& current_node, pugi::xml_node& xml_equ) {

    pugi::xml_node eq_type = xml_equ.first_child();
    current_node.type = eq_type.name();

    if( std::strcmp(eq_type.name(),"assign") == 0) {

        pugi::xml_node current = eq_type.first_child();

        while(std::strcmp(current.name(),"defines") == 0) {
            current_node.lhs.insert(current.attribute("name").value());
            current = current.next_sibling();
        }


        while(std::strcmp(current.name(),"depends") == 0) {
            current_node.rhs.insert(current.attribute("name").value());
            current = current.next_sibling();
        }

        current_node.cost = 1;
    }
    else if( std::strcmp(eq_type.name(),"statement") == 0) {

        pugi::xml_node current = eq_type.first_child();

        while(std::strcmp(current.name(),"defines") == 0) {
            current_node.lhs.insert(current.attribute("name").value());
            current = current.next_sibling();
        }


        while(std::strcmp(current.name(),"depends") == 0) {
            current_node.rhs.insert(current.attribute("name").value());
            current = current.next_sibling();
        }

        current_node.cost = 1;
    }
    else if( std::strcmp(eq_type.name(),"when") == 0) {

        pugi::xml_node current = eq_type.first_child();
        current_node.rhs.insert(current.child_value());
        current = current.next_sibling();

        while(std::strcmp(current.name(),"defines") == 0) {
            current_node.lhs.insert(current.attribute("name").value());
            current = current.next_sibling();
        }


        while(std::strcmp(current.name(),"depends") == 0) {
            current_node.rhs.insert(current.attribute("name").value());
            current = current.next_sibling();
        }

        current_node.cost = 2;
    }

    else if( std::strcmp(eq_type.name(),"linear") == 0) {

        pugi::xml_node current = eq_type.first_child();

        int ls_size = 0;
        while(std::strcmp(current.name(),"defines") == 0) {
            current_node.lhs.insert(current.attribute("name").value());
            current = current.next_sibling();
            ++ls_size;
        }

        while(std::strcmp(current.name(),"depends") == 0) {
            current_node.rhs.insert(current.attribute("name").value());
            current = current.next_sibling();
        }

        current_node.cost = ls_size;
        utility::warning() << current_node.index << ": Linear equations not fully handled yet: " << ls_size << newl;
    }

    else if( std::strcmp(eq_type.name(),"nonlinear") == 0) {

        pugi::xml_node current = eq_type.first_child();

        int nls_size = 0;
        while(std::strcmp(current.name(),"defines") == 0) {
            current_node.lhs.insert(current.attribute("name").value());
            current = current.next_sibling();
            ++nls_size;
        }

        while(std::strcmp(current.name(),"depends") == 0) {
            current_node.rhs.insert(current.attribute("name").value());
            current = current.next_sibling();
        }

        current_node.cost = nls_size;
        utility::warning() << current_node.index << ": Non linear equations not fully handled yet: " << nls_size << newl;
    }

    else if( std::strcmp(eq_type.name(),"mixed") == 0) {

        int mix_size = eq_type.attribute("size").as_int();

        pugi::xml_node current = eq_type.first_child();

        while(std::strcmp(current.name(),"defines") == 0) {
            current_node.lhs.insert(current.attribute("name").value());
            current = current.next_sibling();
        }

        current_node.cost = mix_size;

        for(int count = 0; count < mix_size; ++count) {
            xml_equ = xml_equ.next_sibling();
            Equation mix_eq_node;
            load_node(mix_eq_node, xml_equ);
            current_node.lhs.insert(mix_eq_node.lhs.begin(), mix_eq_node.lhs.end());
            current_node.rhs.insert(mix_eq_node.rhs.begin(), mix_eq_node.rhs.end());
        }

        utility::warning() << current_node.index << ": Mixed equations not fully handled yet: " << mix_size << newl;
    }

    else {
        current_node.cost = 1;
        utility::error() << current_node.index << ": Unknown Equation type." << eq_type.name() << newl;
    }


}
Beispiel #20
0
int remove_rec_2(long node_idx, rec_t *rec, long *parents, int parent_cnt, int *parent_is, int parent_i_cnt) {
	int i, j;

	node_t node;
	node.idx = node_idx;
	load_node(&node);

	for (i=0;i<node.rec_cnt;i++) {
		int cmped = rec_cmp(&node.recs[i], rec);

		if (cmped > 0) {
			if (node.child_cnt) {
				parents[-1] = node.idx;
				parent_is[-1] = i;
				return remove_rec_2(node.childs[i], rec, parents-1, parent_cnt+1, parent_is-1, parent_i_cnt+1);
			} else {
				return -1;
			}
		} else if (cmped == 0) {
			if (!node.child_cnt) {
				for (j=i+1;j<node.rec_cnt;j++) node.recs[j-1] = node.recs[j];
				node.rec_cnt--;

				save_node(&node);

				remove_rec_adjust(node.idx, parents, parent_cnt, parent_is, parent_i_cnt);
				return 0;
			} else {
				int prev_i = i+1;
				long prev_suc = node.idx;

				node_t suc;
				suc.idx = node.childs[prev_i];
				load_node(&suc);

				int new_parent_cnt = 0;
				int new_parent_i_cnt = 0;

				parents[--new_parent_cnt] = prev_suc;
				parent_is[--new_parent_i_cnt] = prev_i;

				while (suc.child_cnt) {
					prev_suc = suc.idx;
					prev_i = 0;

					suc.idx = suc.childs[prev_i];
					load_node(&suc);

					parents[--new_parent_cnt] = prev_suc;
					parent_is[--new_parent_i_cnt] = prev_i;
				}

				rec_t _rec = suc.recs[0];

				node.recs[i] = _rec;
				save_node(&node);

				return remove_rec_2(suc.idx, &_rec, parents+new_parent_cnt, parent_cnt-new_parent_cnt, parent_is+new_parent_i_cnt, parent_i_cnt-new_parent_i_cnt);
			}
		}
	}

	if (node.child_cnt) {
		parents[-1] = node.idx;
		parent_is[-1] = node.child_cnt-1;
		return remove_rec_2(node.childs[node.child_cnt-1], rec, parents-1, parent_cnt+1, parent_is-1, parent_i_cnt+1);
	} else return -1;
}