2004-06-23 00:00:36 +02:00
|
|
|
/* vi: set ts=2:
|
|
|
|
+-------------------+
|
|
|
|
| | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
|
|
| Eressea PBEM host | Enno Rehling <enno@eressea-pbem.de>
|
|
|
|
| (c) 1998 - 2004 | Katja Zedel <katze@felidae.kn-bremen.de>
|
|
|
|
| |
|
|
|
|
+-------------------+
|
|
|
|
|
|
|
|
This program may not be used, modified or distributed
|
|
|
|
without prior permission by the authors of Eressea.
|
|
|
|
*/
|
|
|
|
|
2003-11-10 00:36:11 +01:00
|
|
|
#include <config.h>
|
|
|
|
#include "eressea.h"
|
|
|
|
|
|
|
|
#include "order.h"
|
|
|
|
|
|
|
|
/* libc includes */
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
keyword_t
|
2004-06-21 18:45:27 +02:00
|
|
|
get_keyword(const order * ord)
|
2003-11-10 00:36:11 +01:00
|
|
|
{
|
2004-06-21 18:45:27 +02:00
|
|
|
if (ord==NULL) {
|
|
|
|
return NOKEYWORD;
|
|
|
|
}
|
|
|
|
return ord->_keyword;
|
2003-11-10 00:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
getcommand(const order * ord)
|
|
|
|
{
|
2004-06-21 18:45:27 +02:00
|
|
|
return ord->_str;
|
2003-11-10 00:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
free_order(order * ord)
|
|
|
|
{
|
2004-06-21 18:45:27 +02:00
|
|
|
if (ord!=NULL && --ord->_refcount==0) {
|
|
|
|
free(ord->_str);
|
2003-11-10 00:36:11 +01:00
|
|
|
free(ord);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
order *
|
|
|
|
copy_order(order * ord)
|
|
|
|
{
|
2004-06-21 18:45:27 +02:00
|
|
|
if (ord!=NULL) ++ord->_refcount;
|
2003-11-10 00:36:11 +01:00
|
|
|
return ord;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
set_order(struct order ** destp, struct order * src)
|
|
|
|
{
|
2004-06-21 18:45:27 +02:00
|
|
|
if (*destp==src) return;
|
|
|
|
free_order(*destp);
|
|
|
|
*destp = copy_order(src);
|
2003-11-10 00:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
free_orders(order ** olist)
|
|
|
|
{
|
|
|
|
while (*olist) {
|
|
|
|
order * ord = *olist;
|
|
|
|
*olist = ord->next;
|
|
|
|
free_order(ord);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
order *
|
|
|
|
parse_order(const char * s, const struct locale * lang)
|
|
|
|
{
|
2004-06-21 18:45:27 +02:00
|
|
|
while (isspace(*s)) ++s;
|
|
|
|
if (*s==0) return NULL;
|
|
|
|
else {
|
2003-11-10 00:36:11 +01:00
|
|
|
order * ord = (order*)malloc(sizeof(order));
|
2004-06-21 18:45:27 +02:00
|
|
|
ord->_str = strdup(s);
|
|
|
|
ord->_keyword = findkeyword(parse_token(&s), lang);
|
|
|
|
ord->_refcount = 1;
|
2003-11-10 00:36:11 +01:00
|
|
|
ord->next = NULL;
|
|
|
|
return ord;
|
2004-06-21 18:45:27 +02:00
|
|
|
}
|
2003-11-10 00:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
boolean
|
|
|
|
is_persistent(const order * cmd)
|
|
|
|
{
|
|
|
|
#ifdef AT_PERSISTENT
|
2004-06-21 18:45:27 +02:00
|
|
|
if (cmd->_str[0] == '@') return true;
|
2003-11-10 00:36:11 +01:00
|
|
|
#endif /* Nur kurze Befehle! */
|
2004-06-21 18:45:27 +02:00
|
|
|
switch (cmd->_keyword) {
|
2003-11-10 00:36:11 +01:00
|
|
|
case K_KOMMENTAR:
|
|
|
|
case K_LIEFERE:
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
write_order(const order * cmd, const struct locale * lang, char * buffer, size_t size)
|
|
|
|
{
|
2004-06-21 18:45:27 +02:00
|
|
|
if (cmd==0) {
|
2004-06-23 00:00:36 +02:00
|
|
|
buffer[0]=0;
|
|
|
|
} else {
|
2004-06-21 18:45:27 +02:00
|
|
|
#ifndef NDEBUG
|
2004-06-26 11:28:39 +02:00
|
|
|
const char * s = cmd->_str;
|
2004-06-23 00:00:36 +02:00
|
|
|
assert(findkeyword(parse_token(&s), lang)==cmd->_keyword);
|
2004-06-21 18:45:27 +02:00
|
|
|
#endif
|
2004-06-23 00:00:36 +02:00
|
|
|
strncpy(buffer, cmd->_str, size);
|
|
|
|
}
|
|
|
|
return buffer;
|
2003-11-10 00:36:11 +01:00
|
|
|
}
|