3 #include "language/control/control-stack.h"
8 #include "libpspp/compiler.h"
9 #include "libpspp/message.h"
11 #include "gl/xalloc.h"
14 #define _(msgid) gettext (msgid)
18 const struct ctl_class *class; /* Class of control structure. */
19 struct ctl_struct *down; /* Points toward the bottom of ctl_stack. */
20 void *private; /* Private data. */
23 static struct ctl_struct *ctl_stack;
26 ctl_stack_clear (void)
28 while (ctl_stack != NULL)
30 struct ctl_struct *top = ctl_stack;
31 msg (SE, _("%s without %s."),
32 top->class->start_name, top->class->end_name);
33 ctl_stack_pop (top->private);
38 ctl_stack_push (const struct ctl_class *class, void *private)
40 struct ctl_struct *ctl;
42 assert (private != NULL);
43 ctl = xmalloc (sizeof *ctl);
45 ctl->down = ctl_stack;
46 ctl->private = private;
51 ctl_stack_top (const struct ctl_class *class)
53 struct ctl_struct *top = ctl_stack;
54 if (top != NULL && top->class == class)
58 if (ctl_stack_search (class) != NULL)
59 msg (SE, _("This command must appear inside %s...%s, "
60 "without intermediate %s...%s."),
61 class->start_name, class->end_name,
62 top->class->start_name, top->class->end_name);
68 ctl_stack_search (const struct ctl_class *class)
70 struct ctl_struct *ctl;
72 for (ctl = ctl_stack; ctl != NULL; ctl = ctl->down)
73 if (ctl->class == class)
76 msg (SE, _("This command cannot appear outside %s...%s."),
77 class->start_name, class->end_name);
82 ctl_stack_pop (void *private)
84 struct ctl_struct *top = ctl_stack;
87 assert (top->private == private);
89 top->class->close (top->private);
90 ctl_stack = top->down;
95 ctl_stack_is_empty (void)
97 return ctl_stack == NULL;