Esempio n. 1
0
/* Try to parse a config file if it exists */
g_error configfile_parse_if_exists(const char *filename) {
  FILE *f;
  
  f = fopen(filename,"r");
  if (f) {
    fclose(f);
    return configfile_parse(filename);
  }

  return success;
}
Esempio n. 2
0
retvalue pull_getrules(struct pull_rule **rules) {
	struct pull_rule *pull = NULL;
	retvalue r;

	r = configfile_parse("pulls", IGNORABLE(unknownfield),
			configparser_pull_rule_init, linkedlistfinish,
			"pull rule",
			pullconfigfields, ARRAYCOUNT(pullconfigfields), &pull);
	if (RET_IS_OK(r))
		*rules = pull;
	else if (r == RET_NOTHING) {
		assert (pull == NULL);
		*rules = NULL;
		r = RET_OK;
	} else {
		// TODO special handle unknownfield
		pull_freerules(pull);
	}
	return r;
}
Esempio n. 3
0
/* Parse a command line, and add it to the config file database.
 * If the command line was invalid or the user requested help, a help string
 * will be printed and an error will be returned.
 */
g_error commandline_parse(int argc, char **argv) {    
  int c;
  g_error e;

  while (1) {    
    c = getopt(argc,argv,"hlnv:m:i:t:c:-:s:");
    if (c==-1)
      break;
    
    switch (c) {
      
    case 'n':        /* Ignore config data */
      configfile_free();
      break;
      
    case '-':        /* config option */
      {
	char *section, *key, *value;
	
	/* Treat --help as an exception */
	if (!strcmp(optarg,"help"))
	  return commandline_help();
	
	if ((key = strchr(optarg,'.'))) {
	  *key = 0;
	  key++;
	  section = optarg;
	}
	else {
	  /* Default section */
	  key = optarg;
	  section = "pgserver";
	}

	if ((value = strchr(key,'='))) {
	  *value = 0;
	  value++;
	}
	else
	  /* Default value */
	  value = "1";
	
	e = set_param_str(section,key,value);
	errorcheck;
      } 
      break;
	
    case 'v':        /* Video driver */
      e = set_param_str("pgserver","video",optarg);
      errorcheck;
      break;
      
    case 'm':        /* Video mode */
      e = set_param_str("pgserver","mode",optarg);
      errorcheck;
      break;
      
    case 's':        /* Session manager */
      e = set_param_str("pgserver","session",optarg);
      errorcheck;
      break;

    case 'c':        /* Config file */
      e = configfile_parse(optarg);
      errorcheck;
      break;

    case 'l':        /* List */
      e = commandline_list();
      errorcheck;
      break;
      
    case 'i':        /* Input */
      e = append_param_str("pgserver","input"," ",optarg);
      errorcheck;
      break;

    case 't':        /* Theme */
      e = append_param_str("pgserver","themes"," ",optarg);
      errorcheck;
      break;
	
    default:        /* Need help */
      return commandline_help();
    }
  }
    
  if (optind < argc)  /* extra options */
    return commandline_help();
 
  return success;
}
Esempio n. 4
0
int
main (int argc, char *argv[])
{
    char *home, *conffile;

    pghandle msgscroll, msgbox;
    pghandle wToolbar, wScroll, wItem;

    row = 0;

    pgInit (argc, argv);
    picomailapp = pgRegisterApp (PG_APP_NORMAL, "PicoMail", 0);

    home = getenv ("HOME");
    conffile = malloc (strlen (home) + strlen (CONFIG_FILE) + 1);
    if (home && conffile)
    {
        strcpy (conffile, home);
        strcat (conffile, CONFIG_FILE);

        if (!configfile_parse (conffile))
        {
            pgMessageDialog ("PicoMail",
                             "Configuration file could not be parsed.\n"
                             "Please make sure you have a good '~/.picomail.conf'!",
                             PG_MSGBTN_OK || PG_MSGICON_ERROR);
            exit (1);
        }
        free (conffile);
    }

    wToolbar = pgNewWidget (PG_WIDGET_TOOLBAR, 0, 0);



    wScroll = pgNewWidget (PG_WIDGET_SCROLL, 0, 0);
    wBox = pgNewWidget (PG_WIDGET_BOX, 0, 0);
    pgSetWidget (PGDEFAULT, PG_WP_SIDE, PG_S_ALL, 0);
    pgSetWidget (wScroll, PG_WP_BIND, wBox, 0);




    pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, wToolbar);
    pgSetWidget (PGDEFAULT,
                 PG_WP_TEXT, pgNewString ("Read Message"),
                 PG_WP_SIDE, PG_S_LEFT, PG_WP_EXTDEVENTS, PG_EXEV_PNTR_DOWN, 0);
    pgBind (PGDEFAULT, PG_WE_PNTR_DOWN, &readMessage, NULL);


    pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, wToolbar);
    pgSetWidget (PGDEFAULT,
                 PG_WP_TEXT, pgNewString ("Delete Message"),
                 PG_WP_SIDE, PG_S_LEFT, PG_WP_EXTDEVENTS, PG_EXEV_PNTR_DOWN, 0);
    pgBind (PGDEFAULT, PG_WE_PNTR_DOWN, &deleteMessage, NULL);


    pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, wToolbar);
    pgSetWidget (PGDEFAULT,
                 PG_WP_TEXT, pgNewString ("Get list of messages!"),
                 PG_WP_SIDE, PG_S_LEFT, PG_WP_EXTDEVENTS, PG_EXEV_PNTR_DOWN, 0);
    pgBind (PGDEFAULT, PG_WE_PNTR_DOWN, &getList, NULL);

    pgBind (PGBIND_ANY, PG_WE_CLOSE, &closeboxHandler, NULL);

    /* message viewer */

    mesgviewer = pgRegisterApp (PG_APP_NORMAL, "PicoMail Message", 0);
    pgBind (mesgviewer, PG_WE_CLOSE, &viewerCloseboxHandler, NULL);
    pgSetWidget (mesgviewer, PG_WP_SIZE, 0, 0);
    msgscroll = pgNewWidget (PG_WIDGET_SCROLL, 0, 0);
    msgbox = pgNewWidget (PG_WIDGET_BOX, 0, 0);
    pgSetWidget (msgbox, PG_WP_SIDE, PG_S_ALL, 0);
    pgSetWidget (msgscroll, PG_WP_BIND, msgbox, 0);
    messagebox = pgNewWidget (PG_WIDGET_TEXTBOX, PG_DERIVE_INSIDE, PGDEFAULT);
//        pgSetWidget(msgscroll, PG_WP_BIND,messagebox, 0);
    pgSetWidget (messagebox,
                 PG_WP_TEXT, pgNewString ("Hier is uw bericht!"), 0);



    pgEventLoop ();

    configfile_free ();
    return 0;
}