|
@@ -1,45 +1,190 @@
|
|
|
-
|
|
|
+
|
|
|
package al
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
#include <allegro5/allegro.h>
|
|
|
#include "helpers.h"
|
|
|
-#include "callbacks.h"
|
|
|
*/
|
|
|
import "C"
|
|
|
+import "runtime"
|
|
|
|
|
|
|
|
|
-
|
|
|
-typedef struct ALLEGRO_CONFIG ALLEGRO_CONFIG;
|
|
|
-
|
|
|
-typedef struct ALLEGRO_CONFIG_SECTION ALLEGRO_CONFIG_SECTION;
|
|
|
-
|
|
|
-typedef struct ALLEGRO_CONFIG_ENTRY ALLEGRO_CONFIG_ENTRY;
|
|
|
-
|
|
|
-AL_FUNC(ALLEGRO_CONFIG *, al_create_config, (void));
|
|
|
-AL_FUNC(void, al_add_config_section, (ALLEGRO_CONFIG *config, const char *name));
|
|
|
-AL_FUNC(void, al_set_config_value, (ALLEGRO_CONFIG *config, const char *section, const char *key, const char *value));
|
|
|
-AL_FUNC(void, al_add_config_comment, (ALLEGRO_CONFIG *config, const char *section, const char *comment));
|
|
|
-AL_FUNC(const char*, al_get_config_value, (const ALLEGRO_CONFIG *config, const char *section, const char *key));
|
|
|
-AL_FUNC(ALLEGRO_CONFIG*, al_load_config_file, (const char *filename));
|
|
|
-AL_FUNC(ALLEGRO_CONFIG*, al_load_config_file_f, (ALLEGRO_FILE *filename));
|
|
|
-AL_FUNC(bool, al_save_config_file, (const char *filename, const ALLEGRO_CONFIG *config));
|
|
|
-AL_FUNC(bool, al_save_config_file_f, (ALLEGRO_FILE *file, const ALLEGRO_CONFIG *config));
|
|
|
-AL_FUNC(void, al_merge_config_into, (ALLEGRO_CONFIG *master, const ALLEGRO_CONFIG *add));
|
|
|
-AL_FUNC(ALLEGRO_CONFIG *, al_merge_config, (const ALLEGRO_CONFIG *cfg1, const ALLEGRO_CONFIG *cfg2));
|
|
|
-AL_FUNC(void, al_destroy_config, (ALLEGRO_CONFIG *config));
|
|
|
-AL_FUNC(bool, al_remove_config_section, (ALLEGRO_CONFIG *config,
|
|
|
- char const *section));
|
|
|
-AL_FUNC(bool, al_remove_config_key, (ALLEGRO_CONFIG *config,
|
|
|
- char const *section, char const *key));
|
|
|
-
|
|
|
-AL_FUNC(char const *, al_get_first_config_section, (ALLEGRO_CONFIG const *config, ALLEGRO_CONFIG_SECTION **iterator));
|
|
|
-AL_FUNC(char const *, al_get_next_config_section, (ALLEGRO_CONFIG_SECTION **iterator));
|
|
|
-AL_FUNC(char const *, al_get_first_config_entry, (ALLEGRO_CONFIG const *config, char const *section,
|
|
|
- ALLEGRO_CONFIG_ENTRY **iterator));
|
|
|
-AL_FUNC(char const *, al_get_next_config_entry, (ALLEGRO_CONFIG_ENTRY **iterator));
|
|
|
+type Config struct {
|
|
|
+ handle * C.ALLEGRO_CONFIG
|
|
|
+}
|
|
|
|
|
|
-*/
|
|
|
+
|
|
|
+func (self * Config) toC() *C.ALLEGRO_CONFIG {
|
|
|
+ return (*C.ALLEGRO_CONFIG)(self.handle)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Config) Destroy() {
|
|
|
+ if self.handle != nil {
|
|
|
+ C.al_destroy_config(self.toC())
|
|
|
+ }
|
|
|
+ self.handle = nil
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func wrapConfigRaw(data *C.ALLEGRO_CONFIG) *Config {
|
|
|
+ if data == nil {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return &Config{data}
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Config) SetDestroyFinalizer() *Config {
|
|
|
+ if self != nil {
|
|
|
+ runtime.SetFinalizer(self, func(me *Config) { me.Destroy() })
|
|
|
+ }
|
|
|
+ return self
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func wrapConfig(data *C.ALLEGRO_CONFIG) *Config {
|
|
|
+ self := wrapConfigRaw(data)
|
|
|
+ return self.SetDestroyFinalizer()
|
|
|
+}
|
|
|
+
|
|
|
+type ConfigSection C.ALLEGRO_CONFIG_SECTION
|
|
|
+
|
|
|
+func (cs * ConfigSection) toC() * C.ALLEGRO_CONFIG_SECTION {
|
|
|
+ return (*C.ALLEGRO_CONFIG_SECTION)(cs)
|
|
|
+}
|
|
|
+
|
|
|
+func wrapConfigSectionRaw(ccs * C.ALLEGRO_CONFIG_SECTION) * ConfigSection {
|
|
|
+ return (*ConfigSection)(ccs)
|
|
|
+}
|
|
|
+
|
|
|
+type ConfigEntry C.ALLEGRO_CONFIG_ENTRY
|
|
|
+
|
|
|
+func (cs * ConfigEntry) toC() * C.ALLEGRO_CONFIG_ENTRY {
|
|
|
+ return (*C.ALLEGRO_CONFIG_ENTRY)(cs)
|
|
|
+}
|
|
|
+
|
|
|
+func wrapConfigEntryRaw(ccs * C.ALLEGRO_CONFIG_ENTRY) * ConfigEntry {
|
|
|
+ return (*ConfigEntry)(ccs)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func SystemConfig() * Config {
|
|
|
+ return wrapConfig(C.al_get_system_config())
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func CreateConfig() * Config {
|
|
|
+ return wrapConfig(C.al_create_config())
|
|
|
+}
|
|
|
+
|
|
|
+func (cf * Config) AddSection(name string) {
|
|
|
+ cname := cstr(name); defer cstrFree(cname)
|
|
|
+ C.al_add_config_section(cf.toC(), cname)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (cf * Config) SetValue(section, key, value string) {
|
|
|
+ csection := cstr(section); defer cstrFree(csection)
|
|
|
+ ckey := cstr(key); defer cstrFree(ckey)
|
|
|
+ cvalue := cstr(value); defer cstrFree(cvalue)
|
|
|
+ C.al_set_config_value(cf.toC(), csection, ckey, cvalue)
|
|
|
+}
|
|
|
+
|
|
|
+func (cf * Config) AddComment(section, key, comment string) {
|
|
|
+ csection := cstr(section); defer cstrFree(csection)
|
|
|
+ ckey := cstr(key); defer cstrFree(ckey)
|
|
|
+ ccomment := cstr(comment); defer cstrFree(ccomment)
|
|
|
+ C.al_set_config_value(cf.toC(), csection, ckey, ccomment)
|
|
|
+}
|
|
|
+
|
|
|
+func (cf * Config) Value(section, key string) string {
|
|
|
+ csection := cstr(section); defer cstrFree(csection)
|
|
|
+ ckey := cstr(key); defer cstrFree(ckey)
|
|
|
+ return C.GoString(C.al_get_config_value(cf.toC(), csection, ckey))
|
|
|
+}
|
|
|
+
|
|
|
+func LoadConfig(filename string) * Config{
|
|
|
+ cfilename := cstr(filename); defer cstrFree(cfilename)
|
|
|
+ return wrapConfig(C.al_load_config_file(cfilename))
|
|
|
+}
|
|
|
+
|
|
|
+func LoadConfigFile(file * File) * Config{
|
|
|
+ return wrapConfig(C.al_load_config_file_f(file.toC()))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (cf * Config) Save(filename string) bool {
|
|
|
+ cfilename := cstr(filename); defer cstrFree(cfilename)
|
|
|
+ return bool(C.al_save_config_file(cfilename, cf.toC()))
|
|
|
+}
|
|
|
+
|
|
|
+func (cf * Config) SaveFile(file * File) bool {
|
|
|
+ return bool(C.al_save_config_file_f(file.toC(), cf.toC()))
|
|
|
+}
|
|
|
+
|
|
|
+func (cf * Config) MergeInto(add * Config) {
|
|
|
+ C.al_merge_config_into(cf.toC(), add.toC())
|
|
|
+}
|
|
|
+
|
|
|
+func (cf * Config) Merge(cf2 * Config) * Config {
|
|
|
+ return wrapConfig(C.al_merge_config(cf.toC(), cf2.toC()))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (cf * Config) RemoveSection(name string) bool {
|
|
|
+ cname := cstr(name); defer cstrFree(cname)
|
|
|
+ return bool(C.al_remove_config_section(cf.toC(), cname))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (cf * Config) RemoveKey(section, key string) bool {
|
|
|
+ csection := cstr(section); defer cstrFree(csection)
|
|
|
+ ckey := cstr(key); defer cstrFree(ckey)
|
|
|
+ return bool(C.al_remove_config_key(cf.toC(), csection, ckey))
|
|
|
+}
|
|
|
+
|
|
|
+func (cf * Config) FirstSection() (name string, section * ConfigSection) {
|
|
|
+ section = &ConfigSection{}
|
|
|
+ csection := section.toC()
|
|
|
+ name = C.GoString(C.al_get_first_config_section(cf.toC(), &csection))
|
|
|
+ return name, section
|
|
|
+}
|
|
|
+
|
|
|
+func (section * ConfigSection) Next() (name string, ok bool) {
|
|
|
+ csection := section.toC()
|
|
|
+ cname := C.al_get_next_config_section(&csection)
|
|
|
+ if cname == nil {
|
|
|
+ name = ""
|
|
|
+ ok = false
|
|
|
+ } else {
|
|
|
+ name = C.GoString(cname)
|
|
|
+ ok = true
|
|
|
+ }
|
|
|
+ return name, ok
|
|
|
+}
|
|
|
+
|
|
|
+func (cf * Config) FirstEntry(section string) (name string, entry * ConfigEntry) {
|
|
|
+ csection := cstr(section); defer cstrFree(csection)
|
|
|
+ entry = &ConfigEntry{}
|
|
|
+ centry := entry.toC()
|
|
|
+ name = C.GoString(C.al_get_first_config_entry(cf.toC(), csection, ¢ry))
|
|
|
+ return name, entry
|
|
|
+}
|
|
|
+
|
|
|
+func (entry * ConfigEntry) Next() (name string, ok bool) {
|
|
|
+ centry := entry.toC()
|
|
|
+ cname := C.al_get_next_config_entry(¢ry)
|
|
|
+ if cname == nil {
|
|
|
+ name = ""
|
|
|
+ ok = false
|
|
|
+ } else {
|
|
|
+ name = C.GoString(cname)
|
|
|
+ ok = true
|
|
|
+ }
|
|
|
+ return name, ok
|
|
|
+}
|
|
|
|
|
|
|