stringlib refactoring
[mala.git] / engine / actiondesc.c
blob55844cb9851ddce54b43faeafd30c3234411c052
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;
55 void mala_actiondesc_free (MalaActionDesc self)
57 if (!self)
58 return;
60 MALA_DEBUG("start %p",self);
61 while (self->actions.lh_first != NULL)
63 MalaAction act = self->actions.lh_first;
64 MALA_DEBUG("name %s",act->name->str);
65 LIST_REMOVE(act, stknode);
66 mala_action_free (act);
69 mala_string_user_set (self->name, NULL);
71 MALA_DEBUG("done %p",self);
72 free (self);
76 void
77 mala_actiondesc_push_action (MalaActionDesc self, MalaAction action)
79 LIST_INSERT_HEAD (&self->actions, action, stknode);
80 action->desc = self;
84 // Local Variables:
85 // mode: C
86 // c-file-style: "gnu"
87 // End:
88 // arch-tag: 52850120-1610-46ce-9cd8-ec035f0fc025
89 // end_of_file