macrodelete_parser fix
[mala.git] / engine / actiondesc.c
blob418d3826b8fdf7fddf43cfa6b24919000c1ff68c
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 while (self->actions.lh_first != NULL)
62 MalaAction act = self->actions.lh_first;
63 LIST_REMOVE(act, stknode);
64 mala_action_free (act);
67 mala_string_user_set (self->name, NULL);
69 free (self);
73 void
74 mala_actiondesc_push_action (MalaActionDesc self, MalaAction action)
76 LIST_INSERT_HEAD (&self->actions, action, stknode);
77 action->desc = self;
80 int
81 mala_actiondesc_pop (MalaActionDesc self)
83 if (self && self->actions.lh_first)
85 MalaAction act = self->actions.lh_first;
86 LIST_REMOVE(act, stknode);
87 mala_action_free (act);
88 return MALA_SUCCESS;
90 else
91 return MALA_FAILURE;
94 MalaAction
95 mala_actiondesc_top (MalaActionDesc self)
97 return self ? self->actions.lh_first: NULL;
101 // Local Variables:
102 // mode: C
103 // c-file-style: "gnu"
104 // End:
105 // arch-tag: 52850120-1610-46ce-9cd8-ec035f0fc025
106 // end_of_file