Exemple #1
0
DocoptArgs docopt(int argc, char *argv[], bool help, const char *version) {
    DocoptArgs args = {
        0, 0, (char*) "finance", (char*) "localhost", (char*) "5432",
        usage_pattern, help_message
    };
    Tokens ts;
    Command commands[] = {
    };
    Argument arguments[] = {
    };
    Option options[] = {
        {"-h", 0, 0, NULL},
        {NULL, 0, 0, NULL},
        {NULL, 1, 0, NULL},
        {NULL, 1, 0, NULL},
        {"-p", 1, 0, NULL}
    };
    Elements elements = {0, 0, 5, commands, arguments, options};

    ts = tokens_new(argc, argv);
    if (parse_args(&ts, &elements))
        exit(EXIT_FAILURE);
    if (elems_to_args(&elements, &args, help, version))
        exit(EXIT_SUCCESS);
    return args;
}
Exemple #2
0
DocoptArgs docopt(int argc, char *argv[], bool help, const char *version) {
    DocoptArgs args = {
        0, 0, (char*) "ObserverDataObject", (char*) "true", (char*) "30",
        (char*) "haggleobserver.log", (char *) "-1", (char *) "-1", (char *) "-1",
        usage_pattern, help_message
    };
    Tokens ts;
    Command commands[] = {
    };
    Argument arguments[] = {
    };
    Option options[] = {
        {"-h", "--help", 0, 0, NULL},
        {NULL, "--version", 0, 0, NULL},
        {NULL, "--attribute_name", 1, 0, NULL},
        {NULL, "--attribute_value", 1, 0, NULL},
        {NULL, "--duration", 1, 0, NULL},
        {NULL, "--logfile", 1, 0, NULL},
        {NULL, "--reduce-dist-frequency-after", 1, 0, NULL},
        {NULL, "--set-max-hop-count-after", 1, 0, NULL},
        {NULL, "--set-max-hop-count-after-average", 1, 0, NULL},
    };
    Elements elements = {0, 0, 9, commands, arguments, options};

    ts = tokens_new(argc, argv);
    if (parse_args(&ts, &elements))
        exit(EXIT_FAILURE);
    if (elems_to_args(&elements, &args, help, version))
        exit(EXIT_SUCCESS);
    return args;
}
Exemple #3
0
/* auth_mysql_init:
 * Initialise the database connection driver. */
int auth_mysql_init() {
    char *hostname = NULL, *localhost = "localhost", *s;

    if (!config_get_string("auth-mysql-username")) {
        log_print(LOG_ERR, _("auth_mysql_init: no auth-mysql-username directive in config"));
        return 0;
    }

    if (!config_get_string("auth-mysql-password")) {
        log_print(LOG_WARNING, _("auth_mysql_init: no auth-mysql-password directive in config; using blank password"));
    }

    if (!config_get_string("auth-mysql-database")) {
        log_print(LOG_ERR, _("auth_mysql_init: no auth-mysql-database directive in config"));
        return 0;
    }

    if ((s = config_get_string("auth-mysql-hostname")))
        hostname = s;
    else hostname = localhost;

    /* Obtain query templates. The special string `none' means `don't use
     * any query for this action'. */
    if ((s = config_get_string("auth-mysql-pass-query")))
        user_pass_query_template = s;
    if (strcmp(user_pass_query_template, "none") == 0)
        user_pass_query_template = NULL;

    if ((s = config_get_string("auth-mysql-apop-query")))
        apop_query_template = s;
    if (strcmp(apop_query_template, "none") == 0)
        apop_query_template = NULL;

    /* This is an optional action to put a row into the database after a
     * successful login, for POP-before-SMTP relaying. */
    if ((s = config_get_string("auth-mysql-onlogin-query")))
        onlogin_query_template = s;

    /* Obtain gid to use */
    if ((s = config_get_string("auth-mysql-mail-group"))) {
        if (!parse_gid(s, &mail_gid)) {
            log_print(LOG_ERR, _("auth_mysql_init: auth-mysql-mail-group directive `%s' does not make sense"), s);
            return 0;
        }
        use_gid = 1;
    }

    mysql_servers = tokens_new(hostname, " \t");

    if (get_mysql_server() == -1) {
        /* No server has been found working. */
        tokens_delete(mysql_servers);
        log_print(LOG_ERR, _("auth_mysql_init: aborting"));
        return 0;
    }

    mysql_driver_active = 1;

    return 1;
}
Exemple #4
0
GArray * readTokensFromFile(char * fileName, char * delimiters) {
  GArray * tokens = tokens_new();

  int fd = open(fileName, O_RDONLY);
  if (fd < 0) {
    printf("FATAL: can not open %s\n", fileName);
    return tokens;
  }

  Token * remainder = NULL;

  char buffer[BUFFSIZE];
  int n;
  while ((n = read(fd, buffer, BUFFSIZE)) > 0) {
    int addedTokens = streamTokenize(buffer, n, delimiters, &tokens, &remainder);
    if (addedTokens < 0) {
      printf("WARNING: can not complete tokenizing of '%s'\n", fileName);
      break;
    }
  }
  if ((remainder) && (remainder->length > 0))
    g_array_append_val(tokens, *remainder);

  if (remainder)
    free(remainder);

  close(fd);

  return tokens;
}
Exemple #5
0
DocoptArgs docopt(int argc, char *argv[], bool help, const char *version) {
    DocoptArgs args = {
        0, NULL, NULL, NULL,
        usage_pattern, help_message
    };
    Tokens ts;
    Command commands[] = {
    };
    Argument arguments[] = {
    };
    Option options[] = {
        {"-h", "--help", 0, 0, NULL},
        {"-c", "--connect", 1, 0, NULL},
        {"-f", "--folder", 1, 0, NULL},
        {"-p", "--port", 1, 0, NULL}
    };
    Elements elements = {0, 0, 4, commands, arguments, options};

    ts = tokens_new(argc, argv);
    if (parse_args(&ts, &elements))
        exit(EXIT_FAILURE);
    if (elems_to_args(&elements, &args, help, version))
        exit(EXIT_SUCCESS);
    return args;
}
Exemple #6
0
DocoptArgs docopt(int argc, char *argv[], bool help, const char *version) {
    DocoptArgs args = {
        0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0,
        0, 0, 0,
        usage_pattern, help_message
    };
    Tokens ts;
    Command commands[] = {
        {"binarize", 0},
        {"build", 0},
        {"derapify", 0},
        {"unpack", 0}
    };
    Argument arguments[] = {
        {"<includefolder>", NULL, NULL},
        {"<indentation>", NULL, NULL},
        {"<keyfile>", NULL, NULL},
        {"<source>", NULL, NULL},
        {"<target>", NULL, NULL},
        {"<wname>", NULL, NULL},
        {"<xlist>", NULL, NULL}
    };
    Option options[] = {
        {"-x", "--exclude", 0, 0, NULL},
        {"-f", "--force", 0, 0, NULL},
        {"-h", "--help", 0, 0, NULL},
        {"-i", "--include", 0, 0, NULL},
        {"-d", "--indent", 0, 0, NULL},
        {"-k", "--key", 0, 0, NULL},
        {"-p", "--packonly", 0, 0, NULL},
        {"-v", "--version", 0, 0, NULL},
        {"-w", "--warning", 0, 0, NULL}
    };
    Elements elements = {4, 7, 9, commands, arguments, options};

    ts = tokens_new(argc, argv);
    if (parse_args(&ts, &elements))
        exit(EXIT_FAILURE);
    if (elems_to_args(&elements, &args, help, version))
        exit(EXIT_SUCCESS);
    return args;
}