コード例 #1
0
ファイル: dhcpv6.cpp プロジェクト: Temptationx/libtins
void DHCPv6::vendor_info(const vendor_info_type &value) {
    std::vector<uint8_t> buffer(sizeof(uint32_t) + value.data.size());
    uint32_t enterprise_number = Endian::host_to_be(value.enterprise_number);
    std::memcpy(&buffer[0], &enterprise_number, sizeof(uint32_t));
    std::copy(
        value.data.begin(),
        value.data.end(),
        buffer.begin() + sizeof(uint32_t)
    );
    add_option(
        option(VENDOR_OPTS, buffer.begin(), buffer.end())
    );
}
コード例 #2
0
ファイル: protocol.c プロジェクト: kevburdick/cs544_group9
/* response.options MUST be free_options()ed! */
CTP_STATUS_t
get_STATUS(textbuf *buf)
{
    client_t *c;
    char id_buf[sizeof(client->id) + 1] = { 0 };
    CTP_STATUS_t response;
    /* XXX TODO set response.checksum */
    response.options = new_options();

    /* build list of peers in options */
    for (c = clients; c <= max_active_client; ++c) {
        if (c->active) {
            memcpy(id_buf, &c->id, sizeof(c->id));
            add_option(response.options, "Peer ID", id_buf);
            /* TODO Peer Nick? */
            if (c->state == Locked)
                add_option(response.options, "Lock ID", id_buf);
        }
    }

    return response;
}
コード例 #3
0
ファイル: dhcpv6.cpp プロジェクト: Temptationx/libtins
void DHCPv6::server_id(const duid_type &value) {
    serialization_type buffer(sizeof(uint16_t) + value.data.size());
    uint16_t tmp_id = Endian::host_to_be(value.id);
    std::memcpy(&buffer[0], &tmp_id, sizeof(uint16_t));
    std::copy(
        value.data.begin(),
        value.data.end(),
        buffer.begin() + sizeof(uint16_t)
    );
    add_option(
        option(SERVERID, buffer.begin(), buffer.end())
    );
}
コード例 #4
0
ファイル: dhcpv6.cpp プロジェクト: jalons/libtins
void DHCPv6::ia_ta(const ia_ta_type &value) {
    std::vector<uint8_t> buffer(sizeof(uint32_t) + value.options.size());
    uint32_t *ptr = (uint32_t*)&buffer[0];
    *ptr++ = Endian::host_to_be(value.id);
    std::copy(
        value.options.begin(), 
        value.options.end(), 
        buffer.begin() + sizeof(uint32_t)
    );
    add_option(
        option(IA_TA, buffer.begin(), buffer.end())
    );
}
コード例 #5
0
ファイル: dhcpv6.cpp プロジェクト: Temptationx/libtins
void DHCPv6::status_code(const status_code_type &value) {
    std::vector<uint8_t> buffer(sizeof(uint16_t) + value.message.size());
    uint16_t uint16_t_buffer = Endian::host_to_be(value.code);
    std::memcpy(&buffer[0], &uint16_t_buffer, sizeof(uint16_t));
    std::copy(
        value.message.begin(), 
        value.message.end(), 
        buffer.begin() + sizeof(uint16_t)
    );
    add_option(
        option(STATUS_CODE, buffer.begin(), buffer.end())
    );
}
コード例 #6
0
static char* add_fuse_options(char* options, const char* spec)
{
	options = add_option(options, "fsname", spec);
	if (options == NULL)
		return NULL;
	options = add_user_option(options);
	if (options == NULL)
		return NULL;
	options = add_blksize_option(options, CLUSTER_SIZE(*ef.sb));
	if (options == NULL)
		return NULL;

	return options;
}
コード例 #7
0
ファイル: dhcpv6.cpp プロジェクト: Temptationx/libtins
void DHCPv6::option_request(const option_request_type &value) {
    typedef option_request_type::const_iterator iterator;
    
    std::vector<uint8_t> buffer(value.size() * sizeof(uint16_t));
    size_t index = 0;
    uint16_t uint16_t_buffer;
    for(iterator it = value.begin(); it != value.end(); ++it, index += 2) {
        uint16_t_buffer = Endian::host_to_be<uint16_t>(*it);
        std::memcpy(&buffer[index], &uint16_t_buffer, sizeof(uint16_t));
    }
    add_option(
        option(OPTION_REQUEST, buffer.begin(), buffer.end())
    );
}
コード例 #8
0
void
ObjectSettings::add_path_ref(const std::string& text, const std::string& path_ref, const std::string& key,
                             unsigned int flags)
{
  add_option(std::make_unique<PathRefObjectOption>(text, path_ref, key, flags));

  if (!path_ref.empty()) {
    m_options.erase(std::remove_if(m_options.begin(), m_options.end(),
                                   [](const std::unique_ptr<ObjectOption>& obj) {
                                     return obj->get_key() == "x" || obj->get_key() == "y";
                                   }),
                    m_options.end());
  }
}
コード例 #9
0
ファイル: options.c プロジェクト: HackLinux/sim-R10K
/* register an enumeration option array, NOTE: all enumeration option variables
   must be of type `int', since true enum variables may be allocated with
   variable sizes by some compilers */
void
opt_reg_enum_list(struct opt_odb_t *odb,/* option data base */
		  char *name,		/* option name */
		  char *desc,		/* option description */
		  int *vars,		/* target array */
		  int nvars,		/* target array size */
		  int *nelt,		/* number of args parsed goes here */
		  char *def_val,	/* default variable value */
		  char **emap,		/* enumeration string map */
		  int *eval,		/* enumeration value map, optional */
		  int emap_sz,		/* size of maps */
		  int print,		/* print during `-dumpconfig'? */
		  char *format,		/* option value print format */
		  int accrue)		/* accrue list across uses */
{
  int i, enum_val;
  struct opt_opt_t *opt;

  opt = (struct opt_opt_t *)calloc(1, sizeof(struct opt_opt_t));
  if (!opt)
    fatal("out of virtual memory");

  opt->name = mystrdup(name);
  opt->desc = desc;
  opt->nvars = nvars;
  opt->nelt = nelt;
  opt->format = format ? format : "%s";
  opt->oc = oc_enum;
  opt->variant.for_enum.var = vars;
  opt->variant.for_enum.emap = emap;
  opt->variant.for_enum.eval = eval;
  opt->variant.for_enum.emap_sz = emap_sz;
  if (def_val)
    {
      if (!bind_to_enum(def_val, emap, eval, emap_sz, &enum_val))
	fatal("could not bind default value for option `%s'", name);
    }
  else
    enum_val = 0;
  opt->print = print;
  opt->accrue = accrue;

  /* place on ODB's option list */
  opt->next = NULL;
  add_option(odb, opt);

  /* set default value */
  for (i=0; i < *nelt; i++)
    vars[i] = enum_val;
}
コード例 #10
0
ファイル: cvs-interface.c プロジェクト: abderrahim/anjuta
void anjuta_cvs_update (AnjutaPlugin *obj, const gchar* filename, gboolean recurse, 
	gboolean prune, gboolean create, gboolean reset_sticky, const gchar* revision, GError **err)
{
	GString* options = g_string_new("");
	CVSPlugin* plugin = ANJUTA_PLUGIN_CVS (obj);
	gchar* command;	
	
	add_option(!recurse, options, "-l");
	add_option(prune, options, "-P");
	add_option(create, options, "-d");
	if (strlen(revision))
	{
		g_string_append_printf(options, " -r %s", revision);
	}
	else
	{
		add_option(reset_sticky, options, "-A");
	}
	
	if (!is_directory(filename))
	{
		gchar* file = g_strdup(filename);
		command = create_cvs_command(anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
								 NULL), "update", options->str, basename(file));
		cvs_execute(plugin, command, dirname(file));
		g_free(file);
	}
	else
	{
		gchar* dir = g_strdup(filename);
		command = create_cvs_command(anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
								 NULL), "update", options->str, "");
		cvs_execute(plugin, command, dir);
	}
	g_free(command);
	g_string_free(options, TRUE);
}
コード例 #11
0
ファイル: dhcpv6.cpp プロジェクト: jalons/libtins
void DHCPv6::vendor_class(const vendor_class_type &value) {
    std::vector<uint8_t> buffer(
        sizeof(uint32_t)
    );
    *(uint32_t*)&buffer[0] = Endian::host_to_be(value.enterprise_number);
    class_option_data2option(
        value.vendor_class_data.begin(),
        value.vendor_class_data.end(),
        buffer,
        sizeof(uint32_t)
    );
    add_option(
        option(VENDOR_CLASS, buffer.begin(), buffer.end())
    );
}
コード例 #12
0
ファイル: main.c プロジェクト: salass00/exfat
static char* add_blksize_option(char* options, long cluster_size)
{
	long page_size = 0;
	char blksize[20];

#ifdef _SC_PAGESIZE
	page_size = sysconf(_SC_PAGESIZE);
#endif

	if (page_size < 1)
		page_size = 0x1000;

	snprintf(blksize, sizeof(blksize), "%ld", MIN(page_size, cluster_size));
	return add_option(options, "blksize", blksize);
}
コード例 #13
0
ファイル: options.c プロジェクト: hoangt/sim-mp
/* register an enumeration option variable, NOTE: all enumeration option
   variables must be of type `int', since true enum variables may be allocated
   with variable sizes by some compilers */
void
opt_reg_enum(struct opt_odb_t *odb,	/* option data base */
	     char *name,		/* option name */
	     char *desc,		/* option description */
	     int *var,			/* target variable */
	     char *def_val,		/* default variable value */
	     char **emap,		/* enumeration string map */
	     int *eval,			/* enumeration value map, optional */
	     int emap_sz,		/* size of maps */
	     int print,			/* print during `-dumpconfig'? */
	     char *format)		/* option value print format */
{
  int enum_val;
#ifndef FIX_8_CLUSTER_BUG
  struct opt_opt_t *opt = NULL;
#endif

  opt = (struct opt_opt_t *)calloc(1, sizeof(struct opt_opt_t));
  if (!opt)
    fatal("out of virtual memory");

  opt->name = name;
  opt->desc = desc;
  opt->nvars = 1;
  opt->nelt = NULL;
  opt->format = format ? format : "%12s";
  opt->oc = oc_enum;
  opt->variant.for_enum.var = var;
  opt->variant.for_enum.emap = emap;
  opt->variant.for_enum.eval = eval;
  opt->variant.for_enum.emap_sz = emap_sz;
  if (def_val)
    {
      if (!bind_to_enum(def_val, emap, eval, emap_sz, &enum_val))
	fatal("could not bind default value for option `%s'", name);
    }
  else
    enum_val = 0;
  opt->print = print;
  opt->accrue = FALSE;

  /* place on ODB's option list */
  opt->next = NULL;
  add_option(odb, opt);

  /* set default value */
  *var = enum_val;
}
コード例 #14
0
ファイル: icmpv6.cpp プロジェクト: JeanJoskin/libtins
void ICMPv6::parse_options(const uint8_t *&buffer, uint32_t &total_sz) {
    while(total_sz > 0) {
        if(total_sz < 8 || (static_cast<uint32_t>(buffer[1]) * 8) > total_sz || buffer[1] < 1) 
            throw malformed_packet();
        // size(option) = option_size - identifier_size - length_identifier_size
        add_option(
            option(
                buffer[0], 
                static_cast<uint32_t>(buffer[1]) * 8 - sizeof(uint8_t) * 2, 
                buffer + 2
            )
        );
        total_sz -= buffer[1] * 8;
        buffer += buffer[1] * 8;
    }
}
コード例 #15
0
static char* add_user_option(char* options)
{
	struct passwd* pw;

	if (getuid() == 0)
		return options;

	pw = getpwuid(getuid());
	if (pw == NULL || pw->pw_name == NULL)
	{
		free(options);
		exfat_error("failed to determine username");
		return NULL;
	}
	return add_option(options, "user", pw->pw_name);
}
コード例 #16
0
ファイル: tgmlog.c プロジェクト: sunfirefox/tangramcom
/* parse a set of debugging option specifications and add them to the option list */
static void parse_options( const char *str )
{
	char *opt, *next, *options;
	unsigned int i;

	if (!(options = strdup(str))) return;
	for (opt = options; opt; opt = next)
	{
		const char *p;
		unsigned char set = 0, clear = 0;

		if ((next = strchr( opt, ',' ))) *next++ = 0;

		p = opt + strcspn( opt, "+-" );
		if (!p[0]) p = opt;  /* assume it's a debug channel name */

		if (p > opt)
		{
			for (i = 0; i < sizeof(debug_classes)/sizeof(debug_classes[0]); i++)
			{
				int len = strlen(debug_classes[i]);
				if (len != (p - opt)) continue;
				if (!memcmp( opt, debug_classes[i], len ))  /* found it */
				{
					if (*p == '+') set |= 1 << i;
					else clear |= 1 << i;
					break;
				}
			}
			if (i == sizeof(debug_classes)/sizeof(debug_classes[0])) /* bad class name, skip it */
				continue;
		}
		else
		{
			if (*p == '-') clear = ~0;
			else set = ~0;
		}
		if (*p == '+' || *p == '-') p++;
		if (!p[0]) continue;

		if (!strcmp( p, "all" ))
			default_flags = (default_flags & ~clear) | set;
		else
			add_option( p, set, clear );
	}
	free( options );
}
コード例 #17
0
ファイル: dhcpv6.cpp プロジェクト: jalons/libtins
void DHCPv6::authentication(const authentication_type &value) {
    std::vector<uint8_t> buffer(
        sizeof(uint8_t) * 3 + sizeof(uint64_t) + value.auth_info.size()
    );
    buffer[0] = value.protocol;
    buffer[1] = value.algorithm;
    buffer[2] = value.rdm;
    *(uint64_t*)&buffer[3] = Endian::host_to_be(value.replay_detection);
    std::copy(
        value.auth_info.begin(), 
        value.auth_info.end(),
        buffer.begin() + sizeof(uint8_t) * 3 + sizeof(uint64_t)
    );
    add_option(
        option(AUTH, buffer.begin(), buffer.end())
    );
}
コード例 #18
0
ファイル: dhcpv6.cpp プロジェクト: jalons/libtins
void DHCPv6::ia_address(const ia_address_type &value) {
    std::vector<uint8_t> buffer(
        sizeof(uint32_t) * 2 + ipaddress_type::address_size + value.options.size()
    );
    uint32_t *ptr = (uint32_t*)&buffer[ipaddress_type::address_size];
    value.address.copy(&buffer[0]);
    *ptr++ = Endian::host_to_be(value.preferred_lifetime);
    *ptr++ = Endian::host_to_be(value.valid_lifetime);
    std::copy(
        value.options.begin(), 
        value.options.end(), 
        buffer.begin() + sizeof(uint32_t) * 2 + ipaddress_type::address_size
    );
    add_option(
        option(IA_ADDR, buffer.begin(), buffer.end())
    );
}
コード例 #19
0
ファイル: suite.c プロジェクト: cosminadrianpopescu/vifm
SETUP()
{
	static int option_changed;
	optval_t val;

	init_options(&option_changed);

	val.str_val = "";
	cpoptions[0] = '\0';
	add_option("cpoptions", "cpo", OPT_CHARSET, OPT_GLOBAL,
			ARRAY_LEN(cpoptions_charset) - 1, &cpoptions_vals, cpoptions_handler,
			val);

	val.str_val = "";
	add_option("cdpath", "cd", OPT_STRLIST, OPT_GLOBAL, 0, NULL, dummy_handler,
			val);

	val.bool_val = fastrun = 0;
	add_option("fastrun", "fr", OPT_BOOL, OPT_GLOBAL, 0, NULL, fastrun_handler,
			val);

	value = val.str_val = "fusehome-default";
	add_option("fusehome", "fh", OPT_STR, OPT_GLOBAL, 0, NULL, fusehome_handler,
			val);

	val.enum_item = 1;
	add_option("sort", "so", OPT_ENUM, OPT_GLOBAL, ARRAY_LEN(sort_enum),
			sort_enum, &dummy_handler, val);

	val.bool_val = 1;
	add_option("sortorder", "", OPT_BOOL, OPT_GLOBAL, 0, NULL, &dummy_handler,
			val);

	val.int_val = tabstop = 8;
	add_option("tabstop", "ts", OPT_INT, OPT_GLOBAL, 0, NULL, &tabstop_handler,
			val);

	val.set_items = vifminfo = 0;
	add_option("vifminfo", "", OPT_SET, OPT_GLOBAL, ARRAY_LEN(vifminfo_set),
			vifminfo_set, &vifminfo_handler, val);
}
コード例 #20
0
ファイル: main.c プロジェクト: draekko/exfat
static char* add_fsname_option(char* options, const char* spec)
{
	/* escaped string cannot be more than twice as big as the original one */
	char* escaped = malloc(strlen(spec) * 2 + 1);

	if (escaped == NULL)
	{
		free(options);
		exfat_error("failed to allocate escaped string for %s", spec);
		return NULL;
	}

	/* on some platforms (e.g. Android, Solaris) device names can contain
	   commas */
	escape(escaped, spec);
	options = add_option(options, "fsname", escaped);
	free(escaped);
	return options;
}
コード例 #21
0
ファイル: dhcpv6.cpp プロジェクト: Temptationx/libtins
DHCPv6::DHCPv6(const uint8_t *buffer, uint32_t total_sz) 
: options_size() 
{
    if(total_sz == 0) 
        throw malformed_packet();
    // Relay Agent/Server Messages
    bool is_relay_msg = (buffer[0] == 12 || buffer[0] == 13);
    uint32_t required_size = is_relay_msg ? 2 : 4;
    if(total_sz < required_size)
        throw malformed_packet();
    std::copy(buffer, buffer + required_size, header_data);
    buffer += required_size;
    total_sz -= required_size;
    if(is_relay_message()) {
        if(total_sz < ipaddress_type::address_size * 2)
            throw malformed_packet();
        link_addr = buffer;
        peer_addr = buffer + ipaddress_type::address_size;
        buffer += ipaddress_type::address_size * 2;
        total_sz -= ipaddress_type::address_size * 2;
    }
    options_size = total_sz;
    while(total_sz) {
        if(total_sz < sizeof(uint16_t) * 2) 
            throw malformed_packet();
        
        uint16_t opt;
        std::memcpy(&opt, buffer, sizeof(uint16_t));
        opt = Endian::be_to_host(opt);
        uint16_t data_size;
        std::memcpy(&data_size, buffer + sizeof(uint16_t), sizeof(uint16_t));
        data_size = Endian::be_to_host(data_size);
        if(total_sz - sizeof(uint16_t) * 2 < data_size)
            throw malformed_packet();
        buffer += sizeof(uint16_t) * 2;
        add_option(
            option(opt, buffer, buffer + data_size)
        );
        buffer += data_size;
        total_sz -= sizeof(uint16_t) * 2 + data_size;
    }
}
コード例 #22
0
ファイル: options.c プロジェクト: IrishMarineInstitute/kplex
iface_t *get_config(FILE *fp, unsigned int *line, enum itype type)
{
    char *var,*val;
    struct kopts **opt;
    iface_t *ifp;
    int ret;

    if((ifp = (iface_t *) malloc(sizeof(iface_t))) == NULL) {
        *line = 0;
        return(NULL);
    }
    memset((void *) ifp,0,sizeof(iface_t));
    ifp->direction = BOTH;
    ifp->checksum=-1;
    ifp->strict=-1;
    ifp->type=type;

    /* Set defaults */
    switch (type) {
    case FILEIO:
        flag_set(ifp,F_NOCR);
        break;
    default:
        break;
    }

    for(opt = &ifp->options;next_config(fp,line,&var,&val) == 0;) {
        if (!var)
            return(ifp);
        if ((ret = add_common_opt(var,val,ifp)) == 0)
            continue;
        if ((ret < 0) || (((*opt) = add_option(var,val)) == NULL && (ret=-1))) {
            if (ret == -1)
                *line=0;
            break;
        }
        opt=&(*opt)->next;
    }
    free_options(ifp->options);
    free(ifp);
    return(NULL);
}
コード例 #23
0
ファイル: options.c プロジェクト: hoangt/sim-mp
/* register a boolean flag option array */
void
opt_reg_flag_list(struct opt_odb_t *odb,/* option database */
		  char *name,		/* option name */
		  char *desc,		/* option description */
		  int *vars,		/* pointer to option array */
		  int nvars,		/* total entries in option array */
		  int *nelt,		/* number of elements parsed */
		  int *def_val,		/* default array value */
		  int print,		/* print during `-dumpconfig'? */
		  char *format,		/* optional value print format */
		  int accrue)		/* accrue list across uses */
{
  int i;
#ifndef FIX_8_CLUSTER_BUG
  struct opt_opt_t *opt = NULL;
#endif

  opt = (struct opt_opt_t *)calloc(1, sizeof(struct opt_opt_t));
  if (!opt)
    fatal("out of virtual memory");

  opt->name = name;
  opt->desc = desc;
  opt->nvars = nvars;
  opt->nelt = nelt;
  opt->format = format ? format : "%s";
  opt->oc = oc_flag;
  opt->variant.for_enum.var = vars;
  opt->variant.for_enum.emap = flag_emap;
  opt->variant.for_enum.eval = flag_eval;
  opt->variant.for_enum.emap_sz = NUM_FLAGS;
  opt->print = print;
  opt->accrue = accrue;

  /* place on ODB's option list */
  opt->next = NULL;
  add_option(odb, opt);

  /* set default value */
  for (i=0; i < *nelt; i++)
    vars[i] = def_val[i];
}
コード例 #24
0
ファイル: cvs-interface.c プロジェクト: abderrahim/anjuta
void anjuta_cvs_add (AnjutaPlugin *obj, const gchar* filename, 
	gboolean binary, GError **err)
{
	gchar* command;
	CVSPlugin* plugin = ANJUTA_PLUGIN_CVS (obj);
	GString* options = g_string_new("");
	gchar* file = g_strdup(filename);
	
	add_option(binary, options, "-kb");
	
	
	command = create_cvs_command(
		anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
		NULL), "add", options->str, basename(file));
	
	cvs_execute(plugin, command, dirname(file));
	g_free(command);
	g_free(file);
	g_string_free(options, TRUE);
}
コード例 #25
0
ファイル: main.cpp プロジェクト: njun-git/kvs
    Argument( int argc, char** argv ) :
        CommandLine( argc, argv )
    {
        add_help_option();
        add_option( "r", "[size_t] Repeat level. ( default : 1 )", 1, false );

        add_option( "structure", "[string] kvs::StructuredVolumeObject file path. ( optional )", 1, false );
        add_option( "unstructure", "[string] kvs::UnstructuredVolumeObject file path. ( optional )", 1, false );
        add_option( "tfunc", "[string] kvs::TransferFunction file path. ( optional )", 1, false );

        add_option( "s", "[float] sampling step for PBVR. ( default : 1 )", 1, false );
        add_option( "DisableShading", "Disable shading. ( default : eable shading )", 0, false );

        if( !this->parse() ) exit( EXIT_FAILURE );
    }
コード例 #26
0
int
read_config_file (const char *file, int unit)
{
	FILE *fp;
	int line_num;
	char line[OPTION_LINE_SIZE];
	char *p[MAX_PARMS];
	int ret = 0;

	fp = fopen (file, "r");
	if (fp)
	{
		line_num = 0;
		while (fgets(line, sizeof (line), fp))
		{
			int offset = 0;
			CLEAR (p);
			++line_num;
			/* Ignore UTF-8 BOM at start of stream */
			if (line_num == 1 && strncmp (line, "\xEF\xBB\xBF", 3) == 0)
				offset = 3;
			if (parse_line (line + offset, p, SIZE (p), line_num))
			{
				bypass_doubledash (&p[0]);
				check_inline_file_via_fp (fp, p);
				ret |= add_option (p, line_num, unit);
			}
		}
		fclose (fp);
	}
	else
	{
		logmessage ("OVPN", "Error opening configuration file");
	}

	CLEAR (line);
	CLEAR (p);

	return ret;
}
コード例 #27
0
ファイル: options.c プロジェクト: hoangt/sim-mp
/* register a double-precision floating point option array */
void
opt_reg_double_list(struct opt_odb_t *odb, /* option data base */
		    char *name,		/* option name */
		    char *desc,		/* option description */
		    double *vars,	/* target array */
		    int nvars,		/* target array size */
		    int *nelt,		/* number of args parsed goes here */
		    double *def_val,	/* default variable value */
		    int print,		/* print during `-dumpconfig'? */
		    char *format,	/* option value print format */
		    int accrue)		/* accrue list across uses */
{
  int i;
#ifndef FIX_8_CLUSTER_BUG
  struct opt_opt_t *opt = NULL;
#endif

  opt = (struct opt_opt_t *)calloc(1, sizeof(struct opt_opt_t));
  if (!opt)
    fatal("out of virtual memory");

  opt->name = name;
  opt->desc = desc;
  opt->nvars = nvars;
  opt->nelt = nelt;
  opt->format = format ? format : "%.4f";
  opt->oc = oc_double;
  opt->variant.for_double.var = vars;
  opt->print = print;
  opt->accrue = accrue;

  /* place on ODB's option list */
  opt->next = NULL;
  add_option(odb, opt);

  /* set default value */
  for (i=0; i < *nelt; i++)
    vars[i] = def_val[i];
}
コード例 #28
0
ファイル: options.c プロジェクト: IrishMarineInstitute/kplex
int cmdlineopt(struct kopts **options, char *arg)
{
    char *val,*ptr;
    struct kopts *optr;

    for (val=arg;*val && *val != '=';val++);
    if (*val != '=') {
        logerr(0,"Badly formatted option %s\n",arg);
        return(-1);
    }

    for(*val++ = '\0',ptr=val;*ptr;ptr++);

    if ((optr=add_option(arg,val)) == NULL) {
        logerr(errno,"Failed to add option");
        return(-1);
    }

    optr->next=*options;
    *options=optr;
    return(0);
} 
コード例 #29
0
ファイル: edit_command.cpp プロジェクト: jahrsg/swx
EditCommand::EditCommand
(   string const& p_command_word,
    vector<string> const& p_aliases
):
    Command
    (   p_command_word,
        p_aliases,
        "Open the activity log or configuration file in a text editor",
        vector<HelpLine>
        {   HelpLine
            (   "Open the activity log in a text editor; the editor used is "
                    "determined by the \"editor\" configuration setting"
            )
        },
        false
    )
{
    add_option
    (   'c',
        "Instead of opening the activity log, open the configuration file",
        &m_open_config_file
    );
}
コード例 #30
0
ファイル: cvs-interface.c プロジェクト: abderrahim/anjuta
void anjuta_cvs_commit (AnjutaPlugin *obj, const gchar* filename, const gchar* log,
	const gchar* rev, gboolean recurse, GError **err)
{
	GString* options = g_string_new("");
	CVSPlugin* plugin = ANJUTA_PLUGIN_CVS (obj);
	gchar* command;	
	
	if (strlen(log))
		g_string_printf(options, "-m '%s'", log);
	else
		g_string_printf(options, "-m 'no log message'");
	
	if (strlen(rev))
	{
		g_string_append_printf(options, " -r %s", rev);
	}
	add_option(!recurse, options, "-l");
	
	if (!is_directory(filename))
	{
		gchar* file = g_strdup(filename);
		command = create_cvs_command(anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
			NULL), "commit", options->str, basename(file));
		cvs_execute(plugin, command, dirname(file));
		g_free(file);
	}
	else
	{
		gchar* dir = g_strdup(filename);
		command = create_cvs_command(anjuta_shell_get_preferences (ANJUTA_PLUGIN(plugin)->shell,
			NULL), "commit", options->str, "");
		cvs_execute(plugin, command, dir);
		g_free(dir);
	}
	g_free(command);
	g_string_free(options, TRUE);
}