aboutsummaryrefslogblamecommitdiffstats
path: root/src/confparser.h
blob: 261dc7296f397af54a83a58a417c9c1d1b1657d9 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
                                                                                


                                             






                                                                                

                                                                        

                                                                                

                    


                         
                                                                         

                                                                          
 

                       
                                   
                        
        
  
                                      
 



                          

                                                 
                        
        
  
                                                    

                                 

                            
                                    
                        
        
  
 
                                                           
                                                       
 
                                                               
                                  
                      
/* confparser.h - Configuration file parser for ck ---------------------*- C -*-
 *
 * This file is part of ck, the config keeper
 * 
 * -----------------------------------------------------------------------------
 *
 * Copyright (C) 2018  Anastasis Grammenos
 * GPLv3 (see LICENCE for the full notice)
 *
 * -----------------------------------------------------------------------------
 *
 * The code here and in confparser.c is responsible for parsing
 * the configuration and getting the values set there in the Conf struct
 *
 * -------------------------------------------------------------------------- */
#ifndef CONFPARSER_H
#define CONFPARSER_H

#include "actionparser.h"

#define CONFIG_VARIABLES_TABLE                                          \
  X(vc_dir,   " version_control_dir = %s ", "Version Control directory") \
  X(scrt_dir, " secret_dir = %s "         , "Secret directory")

enum ConfingVariables {
  CV_NO_VAL_OR_COMMENT,
#define X(var, str, name) CV_##var,
  CONFIG_VARIABLES_TABLE
#undef X
};
typedef enum ConfingVariables ConfVar;

enum ConfigParserResults {
  CPR_OK,
  CPR_NO_CONFIG_FILE,
  CPR_WRONG_CONFIG,
#define X(var, str, name)                       \
  CPR_WRONG_##var,
  CONFIG_VARIABLES_TABLE
#undef X
};
typedef enum ConfigParserResults ConfigParserResult;

typedef struct ConfigValues Conf;
struct ConfigValues {
  ConfigParserResult result;
#define X(var, str, name) char* var;
  CONFIG_VARIABLES_TABLE
#undef X
};

/* Parse the configuration file and fill the conf struct */
extern int config_file_parse(Conf *conf, UserOpt *opt);

extern void make_config_name(char * ret, const char *confPath);
extern void free_conf(Conf *conf);
#endif // CONFPARSER_H