use --WORLD as root of all actions (GC just deletes --WORLD)
[mala.git] / engine / actiondesc.c
blobcc56f6e92a4c855eeed65ef20314eb09521a41eb
1 /*
2 actiondesc.c - stack for all actions on one word
4 Copyright (C) 2004, 2005, Christian Thaeter <chth@gmx.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, contact me.
20 #include "mala_types.h"
21 #include "strings.h"
22 #include "action.h"
23 #include "actiondesc.h"
26 MalaActionDesc mala_actiondesc_new (MalaString name)
28 MalaActionDesc self;
29 self = malloc (sizeof(mala_actiondesc));
30 if (!self)
31 return NULL;
33 LIST_INIT(&self->actions);
34 self->name = name;
35 return self;
38 MalaActionDesc
39 mala_actiondesc_ensure (MalaString str)
41 MalaActionDesc self;
43 self = (MalaActionDesc) mala_string_user_get (str);
44 if (!self)
46 self = mala_actiondesc_new (str);
47 if (!self)
48 return NULL;
49 mala_string_user_set (str, self);
51 return self;
54 void mala_actiondesc_free (MalaActionDesc self)
56 if (!self)
57 return;
59 while (self->actions.lh_first != NULL)
61 MalaAction act = self->actions.lh_first;
62 LIST_REMOVE(act, stknode);
63 mala_action_free (act);
65 mala_string_user_set (self->name, NULL);
66 free (self);
70 void
71 mala_actiondesc_push_action (MalaActionDesc self, MalaAction action)
73 LIST_INSERT_HEAD (&self->actions, action, stknode);
74 action->desc = self;
77 int /*TODO return void instead?*/
78 mala_actiondesc_pop_delete (MalaActionDesc self)
80 if (self && self->actions.lh_first)
82 MalaAction act = self->actions.lh_first;
83 LIST_REMOVE(act, stknode);
84 mala_action_free (act);
85 return MALA_SUCCESS;
87 else
88 return MALA_FAILURE;
91 MalaAction
92 mala_actiondesc_pop (MalaActionDesc self)
94 if (self && self->actions.lh_first)
96 MalaAction act = self->actions.lh_first;
97 LIST_REMOVE(act, stknode);
98 return act;
100 else
101 return NULL;
104 MalaAction
105 mala_actiondesc_top (MalaActionDesc self)
107 return self ? self->actions.lh_first: NULL;
110 void*
111 mala_actiondesc_data_top (MalaActionDesc self)
113 return self ? self->actions.lh_first->data : NULL;
117 // Local Variables:
118 // mode: C
119 // c-file-style: "gnu"
120 // End:
121 // arch-tag: 52850120-1610-46ce-9cd8-ec035f0fc025
122 // end_of_file