#include "master-service-settings.h"
#include "iostream-ssl.h"
+#include <getopt.h>
#include <unistd.h>
#include <sys/stat.h>
#include <syslog.h>
return service;
}
+void
+master_service_register_long_options(struct master_service *service,
+ const struct option *longopts)
+{
+ service->longopts = longopts;
+}
+
int master_getopt(struct master_service *service)
{
int c;
return c;
}
+int
+master_getopt_long(struct master_service *service, const char **longopt_r)
+{
+ if (service->longopts == NULL)
+ return master_getopt(service);
+
+ i_assert(master_getopt_str_is_valid(service->getopt_str));
+
+ int c;
+ int longopt_idx = -1;
+ while ((c = getopt_long(service->argc, service->argv,
+ service->getopt_str, service->longopts,
+ &longopt_idx)) > 0) {
+ if (!master_service_parse_option(service, c, optarg))
+ break;
+ }
+ if (longopt_idx >= 0)
+ *longopt_r = service->longopts[longopt_idx].name;
+ return c;
+}
+
bool master_getopt_str_is_valid(const char *str)
{
unsigned int i, j;
struct master_service *
master_service_init(const char *name, enum master_service_flags flags,
int *argc, char **argv[], const char *getopt_str);
+void master_service_register_long_options(struct master_service *service,
+ const struct option *longopts);
/* Call getopt() and handle internal parameters. Return values are the same as
getopt()'s. */
int master_getopt(struct master_service *service);
+/* Call getopt_long() and handle internal parameters. Return values are the
+ same as getopt_long()'s. Additionally if a long option was encountered, its
+ name is written to longopt_r. */
+int master_getopt_long(struct master_service *service, const char **longopt_r);
/* Returns TRUE if str is a valid getopt_str. Currently this only checks for
duplicate args so they aren't accidentally added. */
bool master_getopt_str_is_valid(const char *str);