]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/conf-context.c
Opt: Documented opt and its interaction with conf
[libucw.git] / ucw / conf-context.c
index dc74b66a9509d724bb6f2d3df75b174983906bec..050e43baaf47fc218e83f74aaf20479d83d14eeb 100644 (file)
 #include <ucw/conf-internal.h>
 #include <ucw/threads.h>
 
-#ifndef CONFIG_UCW_DEFAULT_CONFIG
-#define CONFIG_UCW_DEFAULT_CONFIG NULL
-#endif
+static struct cf_context cf_default_context;
 
-#ifndef CONFIG_UCW_ENV_VAR_CONFIG
-#define CONFIG_UCW_ENV_VAR_CONFIG NULL
-#endif
+static void
+cf_init_context(struct cf_context *cc)
+{
+  cc->enable_journal = 1;
+  clist_init(&cc->conf_entries);
+}
 
 struct cf_context *
 cf_new_context(void)
 {
   struct cf_context *cc = xmalloc_zero(sizeof(*cc));
-  cc->need_journal = 1;
-  clist_init(&cc->conf_entries);
+  cf_init_context(cc);
   return cc;
 }
 
 void
-cf_free_context(struct cf_context *cc)
+cf_delete_context(struct cf_context *cc)
 {
   ASSERT(!cc->is_active);
+  ASSERT(cc != &cf_default_context);
+  struct cf_context *prev = cf_switch_context(cc);
+  cf_revert();
+  cf_switch_context(prev);
   xfree(cc->parser);
   xfree(cc);
 }
@@ -53,31 +57,16 @@ cf_switch_context(struct cf_context *cc)
   return prev;
 }
 
-struct cf_context *
-cf_obtain_context(void)
+static void CONSTRUCTOR_WITH_PRIORITY(10100)
+cf_init_default_context(void)
 {
-  struct ucwlib_context *uc = ucwlib_thread_context();
-  if (unlikely(!uc->cf_context))
-    {
-      struct cf_context *cc = cf_new_context();
-      uc->cf_context = cc;
-      cc->def_file = CONFIG_UCW_DEFAULT_CONFIG;
-      cc->env_file = CONFIG_UCW_ENV_VAR_CONFIG;
-      cc->is_active = 1;
-    }
-  return uc->cf_context;
-}
-
-void
-cf_set_default_file(char *name)
-{
-  struct cf_context *cc = cf_obtain_context();
-  cc->def_file = name;
+  cf_init_context(&cf_default_context);
+  ucwlib_thread_context()->cf_context = &cf_default_context;
+  cf_default_context.is_active = 1;
 }
 
-void
-cf_set_env_override(char *name)
+struct cf_context *
+cf_obtain_context(void)
 {
-  struct cf_context *cc = cf_obtain_context();
-  cc->env_file = name;
+  return cf_get_context();
 }