LCOV - code coverage report
Current view: top level - src - env.c (source / functions) Hit Total Coverage
Test: passgen-test.info Lines: 13 26 50.0 %
Date: 2024-11-29 06:05:05 Functions: 2 5 40.0 %

          Line data    Source code
       1             : #include "passgen/pattern/env.h"
       2             : #include "passgen/config.h"
       3             : #include "passgen/util/utf8.h"
       4             : #include "passgen/wordlist.h"
       5             : #include <stdlib.h>
       6             : #include <string.h>
       7             : 
       8          43 : void passgen_env_init(passgen_env *env, passgen_random *random) {
       9          43 :     env->depth_limit = 1024;
      10          43 :     env->random = random;
      11          43 :     passgen_hashmap_init(&env->wordlists, &passgen_hashmap_context_utf8);
      12          43 :     passgen_hashmap_init(&env->presets, &passgen_hashmap_context_utf8);
      13          43 : }
      14             : 
      15           0 : static int wordlist_entry_free(void *user, passgen_hashmap_entry *entry) {
      16             :     (void) user;
      17           0 :     free((void *) entry->key);
      18           0 :     passgen_wordlist_free(entry->value);
      19           0 :     free(entry->value);
      20           0 :     return 0;
      21             : }
      22             : 
      23           5 : void passgen_env_free(passgen_env *env) {
      24           5 :     if(env->random) {
      25           0 :         passgen_random_free(env->random);
      26             :     }
      27             : 
      28           5 :     passgen_hashmap_foreach(&env->wordlists, NULL, wordlist_entry_free);
      29           5 :     passgen_hashmap_free(&env->wordlists);
      30           5 :     passgen_hashmap_free(&env->presets);
      31             : 
      32           5 :     PASSGEN_CLEAR(env);
      33           5 : }
      34             : 
      35           0 : int passgen_env_wordlist_add(
      36             :     passgen_env *env,
      37             :     char *name,
      38             :     FILE *file,
      39             :     size_t markov_length) {
      40           0 :     passgen_wordlist *wordlist = malloc(sizeof(passgen_wordlist));
      41           0 :     passgen_hashmap_insert(&env->wordlists, name, wordlist);
      42           0 :     passgen_wordlist_init(wordlist, file, markov_length);
      43             : 
      44           0 :     return 0;
      45             : }
      46             : 
      47           0 : int passgen_env_config(passgen_env env, FILE *file) {
      48             :     (void) env;
      49             :     (void) file;
      50             :     // TODO: implement
      51           0 :     return 1;
      52             : }

Generated by: LCOV version 1.14