Exemplo n.º 1
0
CmdLineOptions::CmdLineOptions(std::string const &program_description,
                               std::string const &additional_args)
    : programDescription_(program_description), errorStream_(std::cerr),
      stdStream_(std::cout), parserResultHandler_() {
  add_switch(HELP_SWITCH_NAME, "Show program help.", false);

  // Default fail function.
  parserResultHandler_ = [this](StringList const &unknownInput,
                                StringList const &missingOptions,
                                StringList const &emptyOptions,
                                StringList const &invalidOptions) {
    for (std::string const &name : emptyOptions) {
      ErrorPrinter(errorStream_) << "option requires an argument: " << name;
    }
    for (std::string const &name : invalidOptions) {
      ErrorPrinter(errorStream_) << "invalid argument: "
      << name << " = " << this->get_option(name);
    }
    for (std::string const &name : missingOptions) {
      ErrorPrinter(errorStream_) << "option is required: " << name;
    }
    if (!missingOptions.empty() || !invalidOptions.empty()
        || !emptyOptions.empty()) {
      exit(EXIT_FAILURE);
    }
  };
}
Exemplo n.º 2
0
struct mf_switch * mf_switch_create(uint32_t sockfd)
{
	struct mf_switch * sw = (struct mf_switch*)malloc(sizeof(struct mf_switch));
	if(sw == NULL)
	{
		log_err("malloc failed");
		exit(0);
	}
	sw->sockfd = sockfd;
	sw->epoll_recv_incomplete_length = 0;
	sw->datapath_id = 0;
	sw->n_buffers = 0;
	sw->n_tables = 0;
	sw->auxiliary_id = 0;
	sw->capabilities = 0;
	sw->port_num = 0;
	memset(&(sw->ports), 0, sizeof(sw->ports));
	sw->is_hello_sent = 0;
	sw->is_feature_request_sent = 0;
	sw->is_port_desc_request_sent = 0;
	sw->feature_request_xid = 0;
	/*link_list has already been assigned an address*/
	add_switch(sw);
	pthread_mutex_init(&(sw->switch_mutex), NULL);
	return sw;
}
Exemplo n.º 3
0
/*
 *	Read a switch configuration
 */
SWITCH *
switch_conf()
{
	char						*keyword;
	char						*argument;
	int							token;

	SWITCH						*sw;

	char						*name;

	struct switch_attributes	*attributes;


	sw = (SWITCH *) malloc(sizeof(SWITCH));

	if (sw == NULL) {
		config_error("malloc() failed.\n");
		exit(1);
	}

	name = read_option();		/* Read name			*/
  
	argument = read_option();	/* Read type			*/

	if ((name == NULL) || (argument == NULL)) {
		config_error("Name and type required for switch. Skipping.\n");
		next_keyword();
		return NULL;
	}

	sw->sw_type = parse_token(argument, switch_keywords);

	if (sw->sw_type == TOKEN_NOT_FOUND) {
		config_error("Switch type \"%s\" unknown. Assuming PS32.\n", argument);
		sw->sw_type = HIPPISW_PS32;
	}

	/*
	 *	Fill in defaults
	 */
	strncpy(sw->sw_name, name, SWNAMELEN);
	sw->sw_version = 1;

	/*	Set a bunch of stuff here in one wave of the hand	*/
	attributes = get_sw_attributes(sw->sw_type);
	bcopy(attributes, &(sw->sw_attributes), sizeof(sw->sw_attributes));
     
	sw->sw_ports = NULL;
	NULL_STRING(sw->sw_hostname);
	sw->sw_tport = TELNET_PORT;
	sw->sw_linenum = parsed_linenumber();
	NULL_STRING(sw->sw_comment);
	sw->sw_virt_attached  = NULL;
	NULL_STRING(sw->sw_password);
  
	/*
	 *	Read rest of options
	 */
	while ((keyword = read_option()) != NULL) {
    
		if ((token = parse_token(keyword, keywords)) == TOKEN_NOT_FOUND) {
			config_error("\"%s\" is not recognized. Skipping.\n", keyword);
			continue;
		}

		/*	Currently all options take arguments
		 */
		argument = read_option();

		if (argument == NULL) {
			config_error("Argument required for %s option.\n", keyword);
			continue;
		}

		switch(token) {
		case KEYWD_SIZE:
			if (is_numeric(argument) == FALSE) {
				config_error("\"%s\" is not a legal numeric argument. Skipping.\n",
							 argument);
				continue;
			}
			sw->sw_num_ports = str_to_int(argument);

			break;

		case KEYWD_ADDRESS:
			if (hostname_to_netaddr(argument) == NETADDR_NULL)
				config_error("Warning: can't resolve net address for \"%s\".\n",
							 argument);
      
			strncpy(sw->sw_hostname, argument, HNAMELEN);
			break;

		case KEYWD_PORT:
			if (is_numeric(argument) == FALSE) {
				config_error("\"%s\" is not a legal numeric argument. Skipping.\n",
							 argument);
				continue;
			}
			sw->sw_tport = str_to_int(argument);
			break;

		case KEYWD_PROMPT:
			config_error("\"prompt\" no longer supported. Skipping.\n");	
			break;

		case KEYWD_SMS:
			if (is_numeric(argument) == FALSE) {
				config_error("\"%s\" is not a legal numeric argument. Skipping.\n",
							 argument);
				continue;
			}
			sw->sw_version = str_to_int(argument);
			break;

		case KEYWD_COMMENT:
			strncpy(sw->sw_comment, argument, COMMENTLEN);
			break;

		case KEYWD_START_LOG:
			config_error("\"start_log\" no longer supported.\n");
			continue;
		}
	}

	if ((sw->sw_num = add_switch(sw)) == ERROR) {
		config_error("Error adding switch to list.\n");
		exit(1);
	}

	return sw;
}
Exemplo n.º 4
0
void *op_brick_add(t_brick *brick)
{
	t_context *C = ctx_get();
	t_node *node = NULL;
	t_block *block;
	t_set *set;

	// store
	scene_store(C->scene,1);

	char *name=brick->id.name;

	     if(is(name,"frame")) 		node = add_slider_int(C,"frame",&C->app->frame); 
	else if(is(name,"timer"))  		node = add_slider_float(C,"timer",&C->app->timer); 
	else if(is(name,"timer low"))  		node = add_slider_float(C,"timer low",&C->app->timer_add_low); 
	else if(is(name,"=")) 			node = add_operator_double(C,"=");
	else if(is(name,">"))  			node = add_operator_double(C,">"); 
	else if(is(name,"<"))  			node = add_operator_double(C,"<"); 
	else if(is(name,"if")) 			node = add_if(C); 
	else if(is(name,"mod"))  		node = add_operator_double(C,"mod"); 
	else if(is(name,"x")) 			node = add_maths(C,"x");
	else if(is(name,"+"))  			node = add_maths(C,"+"); 
	else if(is(name,"++")) 			node = add_plusplus(C);
	else if(is(name,"switch"))  		node = add_switch(C,"switch",NULL,NULL); 
	else if(is(name,"clone"))  		node = add_clone(C); 
	else if(is(name,"pipe")) 		node = add_pipe(C); 
	else if(is(name,"sec")) 		node = add_slider_int(C,"sec",&C->app->clock->sec);
	else if(is(name,"min")) 		node = add_slider_int(C,"min",&C->app->clock->min);
	else if(is(name,"int")) 		node = add_slider_int(C,"int",NULL);
	else if(is(name,"float")) 		node = add_slider_float(C,"float",NULL);
	else if(is(name,"10")) 			node = add_multiplier(C,"10");
	else if(is(name,"100")) 		node = add_multiplier(C,"100");
	else if(is(name,".1")) 			node = add_multiplier(C,".1");
	else if(is(name,".01")) 		node = add_multiplier(C,".01");
	else if(is(name,".001")) 		node = add_multiplier(C,".001");
	else if(is(name,"msec")) 		node = add_slider_int(C,"msec",&C->app->clock->msec);
	else if(is(name,"cos")) 		node = add_operator_single(C,"cos",op_cos);
	else if(is(name,"sin")) 		node = add_operator_single(C,"sin",op_sin);
	else if(is(name,"cam_eye_x")) 		node = add_slider_camera(C,"eye x");
	else if(is(name,"cam_eye_y")) 		node = add_slider_camera(C,"eye y");
	else if(is(name,"cam_eye_z")) 		node = add_slider_camera(C,"eye z");
	else if(is(name,"cam_pos_x")) 		node = add_slider_camera(C,"pos x");
	else if(is(name,"cam_pos_y")) 		node = add_slider_camera(C,"pos y");
	else if(is(name,"cam_pos_z")) 		node = add_slider_camera(C,"pos z");
	else if(is(name,"cam_rot_xy")) 		node = add_slider_float_custom(C,"cam rot xy",op_camera_rotate_xy); 
	else if(is(name,"cam_rot_z")) 		node = add_slider_float_custom(C,"cam rot z",op_camera_rotate_z); 
	else if(is(name,"pos x")) 		node = add_slider_object(C,"pos x");
	else if(is(name,"pos y")) 		node = add_slider_object(C,"pos y");
	else if(is(name,"pos z")) 		node = add_slider_object(C,"pos z");
	else if(is(name,"rot x")) 		node = add_slider_object(C,"rot x");
	else if(is(name,"rot y")) 		node = add_slider_object(C,"rot y");
	else if(is(name,"rot z")) 		node = add_slider_object(C,"rot z");
	else if(is(name,"scl x")) 		node = add_slider_object(C,"scl x");
	else if(is(name,"scl y")) 		node = add_slider_object(C,"scl y");
	else if(is(name,"scl z")) 		node = add_slider_object(C,"scl z");
	else if(is(name,"red")) 		node = add_slider_object(C,"red");
	else if(is(name,"green")) 		node = add_slider_object(C,"green");
	else if(is(name,"blue")) 		node = add_slider_object(C,"blue");
	else if(is(name,"color")) 		node = add_slider_object(C,"color");
	else if(is(name,"faces")) 		node = add_slider_object(C,"faces");
	else if(is(name,"alpha")) 		node = add_slider_object(C,"alpha");
	else if(is(name,"label")) 		node = add_label(C,"label");
	else if(is(name,"get")) 		node = add_get(C);
	else if(is(name,"rewind")) 		node = add_trigger_always(C,"rewind",op_rewind); 
	else if(is(name,"not")) 		node = add_slider_int_custom(C,"not",NULL,op_not); 
	else if(is(name,"mouse_x")) 		node = add_slider_int(C,"mouse x",&C->app->mouse->x); 
	else if(is(name,"mouse_y")) 		node = add_slider_int(C,"mouse y",&C->app->mouse->y); 
	else if(is(name,"keyboard")) 		node = add_slider_char(C,"keyboard",&C->app->keyboard->key_pressed); 
	else if(is(name,"rnd")) 		node = add_slider_int_custom(C,"rnd",NULL,op_rnd);
	else if(is(name,"neg")) 		node = add_slider_int_custom(C,"neg",NULL,op_neg);
	else if(is(name,"abs")) 		node = add_slider_int_custom( C, "abs", NULL, op_abs); 
	else if(is(name,"last?")) 		node = add_switch(C,"last?",NULL,op_is_last);
	else if(is(name,"for")) 		node = add_for(C);
	else if(is(name,"vector 3d")) 		node = add_vector_3d(C);
	else if(is(name,"vector 2d")) 		node = add_vector_2d(C);
	else if(is(name,"bang")) 		node = add_slider_int_custom(C,"bang",NULL,op_bang); 
	else if(is(name,"quit")) 		node = add_trigger_always(C,"quit",op_do_quit); 
	else if(is(name,"const")) 		node = add_const(C); 
	else if(is(name,"and")) 		node = add_maths(C,"and"); 
	else if(is(name,"stack")) 		node = add_stack(C); 
	else if(is(name,"mesh")) 		node = add_slider_object(C,"mesh"); 
	else if(is(name,"vertex")) 		node = add_brick_mesh(C,"vertex"); 
	else if(is(name,"edges")) 		node = add_brick_mesh(C,"edges"); 
	else if(is(name,"case")) 		node = add_case(C,"switch"); 

	// Store
	scene_store(C->scene,0);

	term_log("+ brick");

	// Switch Desk
	if(!C->ui->show_sets) show_sets(C);

	if( node)
	{
		block = node->data;
		set = block->set;
		set_setup( set);
	}
		
	return NULL;
}