2 #include "control-stack.h"
5 #include <libpspp/compiler.h>
6 #include <libpspp/message.h>
10 #define _(msgid) gettext (msgid)
14 const struct ctl_class *class; /* Class of control structure. */
15 struct ctl_struct *down; /* Points toward the bottom of ctl_stack. */
16 void *private; /* Private data. */
19 static struct ctl_struct *ctl_stack;
22 ctl_stack_clear (void)
24 while (ctl_stack != NULL)
26 struct ctl_struct *top = ctl_stack;
27 msg (SE, _("%s without %s."),
28 top->class->start_name, top->class->end_name);
29 ctl_stack_pop (top->private);
34 ctl_stack_push (const struct ctl_class *class, void *private)
36 struct ctl_struct *ctl;
38 assert (private != NULL);
39 ctl = xmalloc (sizeof *ctl);
41 ctl->down = ctl_stack;
42 ctl->private = private;
47 ctl_stack_top (const struct ctl_class *class)
49 struct ctl_struct *top = ctl_stack;
50 if (top != NULL && top->class == class)
54 if (ctl_stack_search (class) != NULL)
55 msg (SE, _("This command must appear inside %s...%s, "
56 "without intermediate %s...%s."),
57 class->start_name, class->end_name,
58 top->class->start_name, top->class->end_name);
64 ctl_stack_search (const struct ctl_class *class)
66 struct ctl_struct *ctl;
68 for (ctl = ctl_stack; ctl != NULL; ctl = ctl->down)
69 if (ctl->class == class)
72 msg (SE, _("This command cannot appear outside %s...%s."),
73 class->start_name, class->end_name);
78 ctl_stack_pop (void *private)
80 struct ctl_struct *top = ctl_stack;
83 assert (top->private == private);
85 top->class->close (top->private);
86 ctl_stack = top->down;
91 ctl_stack_is_empty (void)
93 return ctl_stack == NULL;