ffecfg.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef __CFG__H__
  2. #define __CFG__H__
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. typedef struct
  7. {
  8. char *name;
  9. char *data;
  10. } CfgKey;
  11. typedef struct
  12. {
  13. char *name;
  14. int keycount;
  15. CfgKey *keys;
  16. } CfgSection;
  17. typedef struct
  18. {
  19. char *filename;
  20. int wasmodified;
  21. int sectioncount;
  22. CfgSection *sections;
  23. CfgSection *currentsection;
  24. } CfgStruct;
  25. // Initialises file filename into cfg
  26. // Returns 1 on success, 0 on failure
  27. int CfgOpen(CfgStruct *cfg,char *filename);
  28. // Closes config file - saves if modified
  29. // Returns 1 on success, 0 on failure
  30. int CfgClose(CfgStruct *cfg);
  31. // Sets offsets in cfg to position of [sectname]
  32. // Returns 1 if found, 0 on failure
  33. int CfgFindSection(CfgStruct *cfg,char *sectname);
  34. // Reads the value of key keyname as an integer
  35. // Returns 1 on success, 0 on failure
  36. int CfgGetKeyVal(CfgStruct *cfg,char *keyname,int *value);
  37. // Reads the value of key keyname as a string
  38. // Returns 1 on success, 0 on failure
  39. int CfgGetKeyStr(CfgStruct *cfg,char *keyname,char *value,int buflen);
  40. // Reads the value of key keyname as an integer
  41. // Puts def int value if no key found
  42. // Returns 1 if key was found, 0 if def was used
  43. // Note: safe to call even if CfgOpen and CfgFindSection failed
  44. int CfgGetKeyValDef(CfgStruct *cfg,char *keyname,int *value,int def);
  45. #ifdef __cplusplus
  46. }
  47. #endif
  48. #endif // __CFG__H__