G_parser::G_parser() : grammar(grammar_path, std::ifstream::in){

    //"int main(){}"
    
    //grammar_path = "/Users/christodoulosaspromallis/Desktop/UCL/PhD Year 2/Development/OF/of_v0.9.1_osx_release/apps/midiWorkspace/blues/parser_project/bin/data/blues_grammar.txt";
    //cout << "CONTRUCTOR" << endl;
    
    grammar_path = "/Users/christodoulosaspromallis/Desktop/UCL/PhD Year 2/Development/OF/of_v0.9.1_osx_release/apps/midiWorkspace/blues/parser_project/bin/data/blues_grammar.txt";
    
    //ifstream grammar(grammar_path, ifstream::in);
    grammar.open(grammar_path);
    
    if (grammar.fail()){
        cerr << "Error Opening File";
        exit(1);
    };
    
    //cout << "setting up" << endl;
    
    //get main grammar elements
    while(!grammar.fail()){//z<12//!grammar.eof() //or while(grammar)
        nc = get_nc();
        //c = grammar.get();
        //cout << z << "_1: " << nc << endl;
        get_time_signature(nc);
        //cout << z << "_2: " << nc << endl;
        get_form_length(nc);
        //cout << z << "_3: " << nc << endl;
        get_harm_rh(nc);
        //cout << z << "_4: " << nc << endl;
        get_basic_vectors(nc);
        //cout << z << "_5: " << nc << endl;
        store_rules(nc);//normally will finish the significant bit of text file (i.e. the rules are last)
        //cout << z << "_6: " << nc << endl;
        
    }
    //restart reading from top (for next loop)
    grammar.clear();
    grammar.seekg(0, ios::beg);
    
    //initialise curr_cycle with tonics (rootpitch level)
    for(int i=0; i<harm_rh*form_length; i++) {
        
        curr_cycle.push_back(elem_ID());
        curr_cycle[i].time = {0, i};// {beat, harm_rh next..}
        curr_cycle[i].name = "i";
    }
    
    //place decs for the 1st cycle
    vector<int> t_aux = {0, 0, 0, 11, 0};
    update_dec(t_aux);
    
    grammar.close();
    
}
예제 #2
0
파일: mark.c 프로젝트: willsure/netsukuku
/*
 * This function builds:
 * 	- OUTPUT rule
 * 	- POSTROUTING rule
 * 	- PREROUTING rule
 * 	- ntk_mark_chain
 * and store rules for future deletion.
 *
 * Returns:
 * 	0
 * 	-1
 *
 * If -1, any rule will be committed.
 */
int
mark_init(int igw)
{
	int res;
	iptc_handle_t t;
	char rule[MAX_RULE_SZ];

	/*res=inet_aton(NTK_NET_STR,&inet_dst);
	   if (!res) {
	   error("Can not convert str to addr.");
	   goto cannot_init;
	   }
	   res=inet_aton(NTK_NET_MASK_STR,&inet_dst_mask);
	   if (!res) {
	   error("Can not convert str to addr.");
	   goto cannot_init;
	   } */

	res = table_init(MANGLE_TABLE, &t);
	if (res) {
		error(err_str);
		goto cannot_init;
	}
	res = ntk_mark_chain_init(&t);
	if (res) {
		error(err_str);
		error("Unable to create netfilter ntk_mark_chain.");
		goto cannot_init;
	}
	restore_output_rule_init(rule);
	res = insert_rule(rule, &t, CHAIN_OUTPUT, 0);
	if (res) {
		error(err_str);
		error("Unable to create netfilter restore-marking rule.");
		goto cannot_init;
	}
	ntk_forward_rule_init(rule);
	res = insert_rule(rule, &t, CHAIN_POSTROUTING, 0);
	if (res) {
		error(err_str);
		error("Unable to create netfilter forwarding rule.");
		goto cannot_init;
	}
	if (igw) {
		death_loop_rule = 1;
		igw_mark_rule_init(rule);
		res = insert_rule(rule, &t, CHAIN_PREROUTING, 0);
		if (res) {
			error(err_str);
			error("Unable to create netfilter igw death loop rule.");
			death_loop_rule = 0;
			goto cannot_init;
		}
	} else
		death_loop_rule = 0;

	res = commit_rules(&t);
	if (res) {
		error(err_str);
		error("Netfilter mangle table was not altered!");
		goto cannot_init;
	}
	res = store_rules();
	if (res) {
		error(err_str);
		error
			("Rules storing failed: autocleaning netfilter on exit disable.");
		clean_on_exit = 0;
	} else
		clean_on_exit = 1;
	dump_rules();
	debug(DBG_NORMAL, "Netfilter chain ntk_mark_chain created (mangle).");
	debug(DBG_NORMAL,
		  "Netfilter restoring rule created (mangle->output).");
	debug(DBG_NORMAL,
		  "Netfilter forwarding rule created (mangle->postrouting).");
	if (igw)
		debug(DBG_NORMAL, "Netfilter death loop igw rule created.");
	debug(DBG_NORMAL, "mark_init(), netfilter mangle table initialized.");
	loginfo("Netfilter mangle table modified.");
	return 0;
  cannot_init:
	err_ret(ERR_MRKINI, -1);

}