00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __PROFILE_H__
00023 #define __PROFILE_H__
00024
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <generic.h>
00028 #include <config.h>
00029
00030 #define MAX_SECTION_SIZE 128
00031 #define MAX_OPTION_SIZE 128
00032 #define MAX_VALUE_SIZE 128
00033 #define MAX_LINE_SIZE MAX_PATH_SIZE
00034
00035 enum cfgTYPE { cfgNULL, cfgINT, cfgSTR, cfgFLOAT };
00036
00037 struct settings {
00038 const char *name;
00039 void *var;
00040 enum cfgTYPE type;
00041 const char *defval;
00042 };
00043
00044 class Profile {
00045
00046 private:
00047 char *res[2];
00048 char *is_a_section(char *str);
00049 char **parse_option(char *str);
00050 off_t find_section(FILE *fp, const char *section);
00051 off_t find_option(FILE *fp, const char *option, char *value, off_t section_offset);
00052
00053 protected:
00054 int cfg_check(const char *file, int output);
00055 bool cfg_read(const char *file, const char *section, const char *option, char *value);
00056 bool cfg_write(const char *file, const char *section, const char *option, const char *value);
00057 bool cfg_erase(const char *file, const char *section, const char *option);
00058 int cfg_get_sections(const char *file, char *dest);
00059
00060 char profile_path[MAX_PATH_SIZE];
00061
00062 void setup(struct settings *conf) { cfg = conf; }
00063
00064 public:
00065 Profile(char *name);
00066 virtual ~Profile();
00067
00068
00069
00070 bool create_default_profile();
00071
00072 bool load_profile(const char *section);
00073 bool write_profile(const char *section);
00074 virtual bool apply_profile() =0;
00075
00076
00077 int list_profiles(char *str) {
00078 return cfg_get_sections(profile_path,str); }
00079
00080
00081
00082
00083 bool default_profile();
00084
00085 int read_int(const char *section, const char *option);
00086 bool write_int(const char *section, const char *option, const int value);
00087 bool read_str(const char *section, const char *option, char *store);
00088 bool write_str(const char *section, const char *option, const char *value);
00089 float read_float(const char *section, const char *option);
00090 bool write_float(const char *section, const char *option, const float value);
00091
00092 struct settings *cfg;
00093 };
00094
00095 #endif