forked from github/server
at_variable
This commit is contained in:
parent
e7af625758
commit
2b1e4f0dca
|
@ -31,6 +31,7 @@ SOURCES =
|
|||
targetregion.c
|
||||
ugroup.c
|
||||
viewrange.c
|
||||
variable.c
|
||||
;
|
||||
|
||||
Library attributes : $(SOURCES) ;
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#endif
|
||||
#include "moved.h"
|
||||
#include "aggressive.h"
|
||||
#include "variable.h"
|
||||
|
||||
/* util includes */
|
||||
#include <attrib.h>
|
||||
|
@ -74,4 +75,5 @@ init_attributes(void)
|
|||
init_ugroup();
|
||||
#endif
|
||||
init_aggressive();
|
||||
init_variable();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
/* vi: set ts=2:
|
||||
*
|
||||
*
|
||||
* Eressea PB(E)M host Copyright (C) 1998-2004
|
||||
* Christian Schlittchen (corwin@amber.kn-bremen.de)
|
||||
* Katja Zedel (katze@felidae.kn-bremen.de)
|
||||
* Enno Rehling (enno@eressea-pbem.de)
|
||||
*
|
||||
* This program may not be used, modified or distributed without
|
||||
* prior permission by the authors of Eressea.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
#include <attrib.h>
|
||||
#include "variable.h"
|
||||
|
||||
/* libc includes */
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
typedef struct {
|
||||
char *key;
|
||||
char *value;
|
||||
} variable;
|
||||
|
||||
static void
|
||||
initialize_variable(struct attrib * a)
|
||||
{
|
||||
a->data.v = malloc(sizeof(variable));
|
||||
}
|
||||
|
||||
static void
|
||||
finalize_variable(struct attrib * a)
|
||||
{
|
||||
free(a->data.v);
|
||||
}
|
||||
|
||||
static void
|
||||
write_variable(const struct attrib * a, FILE *F)
|
||||
{
|
||||
fwritestr(F, ((variable *)(a->data.v))->key);
|
||||
fputc(' ', F);
|
||||
fwritestr(F, ((variable *)(a->data.v))->value);
|
||||
fputc(' ', F);
|
||||
}
|
||||
|
||||
static int
|
||||
read_variable(struct attrib *a, FILE *F)
|
||||
{
|
||||
char localBuffer[BUFSIZE];
|
||||
|
||||
freadstr(F, localBuffer, sizeof(localBuffer));
|
||||
((variable *)(a->data.v))->key = strdup(localBuffer);
|
||||
|
||||
freadstr(F, localBuffer, sizeof(localBuffer));
|
||||
((variable *)(a->data.v))->value = strdup(localBuffer);
|
||||
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
attrib_type at_variable = {
|
||||
"variable", initialize_variable, finalize_variable, NULL,
|
||||
write_variable, read_variable
|
||||
};
|
||||
|
||||
const char *
|
||||
get_variable(attrib *a, const char *key)
|
||||
{
|
||||
attrib *ap;
|
||||
|
||||
for(ap = a; ap; ap=ap->nexttype) {
|
||||
if(strcmp(key, ((variable *)ap->data.v)->key)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(ap) {
|
||||
return ((variable *)ap->data.v)->value;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
set_variable(attrib **app, const char *key, const char *value)
|
||||
{
|
||||
attrib *ap;
|
||||
|
||||
assert(value);
|
||||
|
||||
for(ap = *app; ap; ap=ap->nexttype) {
|
||||
if(strcmp(key, ((variable *)ap->data.v)->key)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(ap) {
|
||||
free(((variable *)ap->data.v)->value);
|
||||
((variable *)ap->data.v)->value = strdup(value);
|
||||
} else {
|
||||
ap = a_add(app, a_new(&at_variable));
|
||||
((variable *)ap->data.v)->key = strdup(key);
|
||||
((variable *)ap->data.v)->value = strdup(value);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
delete_variable(attrib **app, const char *key)
|
||||
{
|
||||
attrib *ap;
|
||||
|
||||
for(ap = *app; ap; ap=ap->nexttype) {
|
||||
if(strcmp(key, ((variable *)ap->data.v)->key)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(ap) {
|
||||
free(((variable *)ap->data.v)->key);
|
||||
free(((variable *)ap->data.v)->value);
|
||||
a_remove(app, ap);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
init_variable(void)
|
||||
{
|
||||
at_register(&at_variable);
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/* vi: set ts=2:
|
||||
*
|
||||
*
|
||||
* Eressea PB(E)M host Copyright (C) 1998-2004
|
||||
* Christian Schlittchen (corwin@amber.kn-bremen.de)
|
||||
* Katja Zedel (katze@felidae.kn-bremen.de)
|
||||
* Enno Rehling (enno@eressea-pbem.de)
|
||||
*
|
||||
* This program may not be used, modified or distributed without
|
||||
* prior permission by the authors of Eressea.
|
||||
*/
|
||||
|
||||
#ifndef H_ATTRIBUTE_VARIABLE
|
||||
#define H_ATTRIBUTE_VARIABLE
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
const char *get_variable(struct attrib *a, const char *key);
|
||||
void set_variable(struct attrib **app, const char *key, const char *value);
|
||||
void delete_variable(struct attrib **app, const char *key);
|
||||
void init_variable(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
#include <lua.hpp>
|
||||
#include <luabind/luabind.hpp>
|
||||
#include <luabind/iterator_policy.hpp>
|
||||
#include <luabind/object.hpp>
|
||||
|
||||
using namespace luabind;
|
||||
|
||||
|
|
Loading…
Reference in New Issue