Changeset - f17d2abc8601
[Not reviewed]
default
0 4 0
Nathan Brink (binki) - 16 years ago 2009-04-08 23:32:22
ohnobinki@ohnopublishing.net
progress on restructuring options system
4 files changed with 34 insertions and 9 deletions:
0 comments (0 inline, 0 general)
etc/distren.conf
Show inline comments
 
@@ -21,4 +21,6 @@ server ohnopublishing
 
client
 
{
 
  render_types = {"povray", "blender", "inkscape", "imagemagick", "dcraw"}
 
  username = "distrenc"
 
}
 

	
src/client/distren.c
Show inline comments
 
@@ -45,10 +45,10 @@ int main(int argc, char *argv[])
 
  
 
  cfg_opt_t cfg_opts[] =
 
    {
 
      CFG_STR("username", "guest", CFGF_NONE),
 
      CFG_STR("hostname", "protofusion.org", CFGF_NONE),
 
      CFG_STR("name", "Guest", CFGF_NONE),
 
      CFG_STR("email", "guest@protofusion.org", CFGF_NONE),
 
      CFG_STR_LIST("render_types", NULL, 0),
 
      CFG_STR("username", NULL, 0),
 
      CFG_STR("name", NULL, 0),
 
      CFG_STR("email", NULL, 0),
 
      CFG_END()
 
    };
 

	
src/common/options.c
Show inline comments
 
@@ -23,7 +23,7 @@
 
#include <string.h>
 
#include <stdio.h>
 

	
 
int options_init(int argc, char *argv[], cfg_t **mycfg, cfg_opt_t *myopts, const char *myname, struct options_common **allopts)
 
int options_init(int argc, char *argv[], cfg_t **mycfg, cfg_opt_t *myopts, char *myname, struct options_common **allopts)
 
{
 
  char *configfile;
 
  
 
@@ -35,13 +35,36 @@ int options_init(int argc, char *argv[],
 
    }
 
      
 
  /* Conf File Parser */
 
  cfg_opt_t common_opts[] =
 
    {
 
      CFG_END()
 
    };
 
  
 
  cfg_opt_t server_opts[] = 
 
    {
 
      CFG_STR("username", NULL, CFGF_NONE),
 
      CFG_STR("hostname", NULL, CFGF_NONE),
 
      CFG_STR("method", "ssh", CFGF_NONE),
 
      CFG_END()
 
    };
 
  
 
  cfg_opt_t opts[] =
 
    {
 
      CFG_STR("username", "guest", CFGF_NONE),
 
      CFG_SEC("common",
 
	      common_opts,
 
	      CFGF_NONE),
 
      CFG_SEC("server",
 
	      server_opts,
 
	      CFGF_MULTI | CFGF_TITLE),
 
      CFG_SEC(myname,
 
	      myopts,
 
	      0),
 
      CFG_END()
 
    };
 
  cfg_t *cfg;
 
  cfg = cfg_init(opts, CFGF_NONE);
 

	
 

	
 
  cfg = cfg_init(opts, 0);
 
  switch(cfg_parse(cfg, configfile))
 
    {
 
    default:
 
@@ -59,7 +82,7 @@ int options_init(int argc, char *argv[],
 
  
 
  /* End Conf File Parser */
 

	
 
  printf("Client Username: %s\n", cfg_getstr(cfg, "username"));
 
  printf("Client Username: %s\n", cfg_getstr(cfg_getsec(cfg, "client"), "username"));
 
  cfg_free(cfg);
 
  return 0;
 
}
src/common/options.h
Show inline comments
 
@@ -51,7 +51,7 @@ struct options_common
 
  \param argc the argc that was passed to main()
 
  \param argv the argv that was passed to main()
 
 */
 
int options_init(int argc, char *argv[], cfg_t **mycfg, cfg_opt_t *myopts, const char *myname, struct options_common **allopts);
 
int options_init(int argc, char *argv[], cfg_t **mycfg, cfg_opt_t *myopts, char *myname, struct options_common **allopts);
 

	
 
/**
 
   Frees the struct options_common. This should be run before the program exits.
0 comments (0 inline, 0 general)