config.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "config.h"
  2. #define _POSIX_C_SOURCE 200801L
  3. #define _POSIX_SOURCE 200801L
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. int woe_config_init_args(struct woe_config * config, int argc, char * argv[]) {
  7. char opt;
  8. config->port = 7777;
  9. config->data_dir = getenv("WOE_DATA");
  10. if (!config->data_dir) {
  11. config->data_dir= "data";
  12. }
  13. config->log_file = getenv("WOE_LOG");
  14. if (!config->log_file) {
  15. config->log_file = "woe.log";
  16. }
  17. while ((opt = getopt(argc, argv, "p:d:l:")) != -1) {
  18. switch (opt) {
  19. case 'p':
  20. config->port = atoi(optarg);
  21. break;
  22. case 'd':
  23. config->data_dir = optarg;
  24. break;
  25. case 'l':
  26. config->log_file = optarg;
  27. break;
  28. default: /* '?' */
  29. break;
  30. }
  31. }
  32. return 0;
  33. }
  34. static struct woe_config global_woe_config;
  35. struct woe_config woe_config_get() {
  36. return global_woe_config;
  37. }
  38. struct woe_config woe_config_put(struct woe_config * config) {
  39. if (config) {
  40. global_woe_config = *config;
  41. }
  42. return woe_config_get();
  43. }