treewide: Replace <name>_cnt by n_<name>s and <name>_cap by allocated_<name>.
[pspp] / src / language / control / control-stack.c
index 7263842933fe225da0a7625250b540cdb89b72aa..8d0962be63c566415cc5b102f88b45d32d870b0a 100644 (file)
@@ -1,27 +1,49 @@
+/*
+PSPP - a program for statistical analysis.
+Copyright (C) 2017 Free Software Foundation, Inc.
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
 #include <config.h>
-#include "control-stack.h"
+
+#include "language/control/control-stack.h"
+
 #include <assert.h>
 #include <stdlib.h>
-#include <libpspp/compiler.h>
-#include <libpspp/message.h>
-#include "xalloc.h"
+
+#include "libpspp/compiler.h"
+#include "libpspp/message.h"
+
+#include "gl/xalloc.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 
 struct ctl_struct
   {
-    struct ctl_class *class;    /* Class of control structure. */
+    const struct ctl_class *class;    /* Class of control structure. */
     struct ctl_struct *down;   /* Points toward the bottom of ctl_stack. */
     void *private;              /* Private data. */
   };
 
-struct ctl_struct *ctl_stack;
+static struct ctl_struct *ctl_stack;
 
 void
-ctl_stack_clear (void) 
+ctl_stack_clear (void)
 {
-  while (ctl_stack != NULL) 
+  while (ctl_stack != NULL)
     {
       struct ctl_struct *top = ctl_stack;
       msg (SE, _("%s without %s."),
@@ -31,7 +53,7 @@ ctl_stack_clear (void)
 }
 
 void
-ctl_stack_push (struct ctl_class *class, void *private) 
+ctl_stack_push (const struct ctl_class *class, void *private)
 {
   struct ctl_struct *ctl;
 
@@ -44,27 +66,27 @@ ctl_stack_push (struct ctl_class *class, void *private)
 }
 
 void *
-ctl_stack_top (struct ctl_class *class) 
+ctl_stack_top (const struct ctl_class *class)
 {
   struct ctl_struct *top = ctl_stack;
   if (top != NULL && top->class == class)
     return top->private;
-  else 
+  else
     {
       if (ctl_stack_search (class) != NULL)
         msg (SE, _("This command must appear inside %s...%s, "
                    "without intermediate %s...%s."),
              class->start_name, class->end_name,
              top->class->start_name, top->class->end_name);
-      return NULL; 
+      return NULL;
     }
 }
 
 void *
-ctl_stack_search (struct ctl_class *class) 
+ctl_stack_search (const struct ctl_class *class)
 {
   struct ctl_struct *ctl;
-  
+
   for (ctl = ctl_stack; ctl != NULL; ctl = ctl->down)
     if (ctl->class == class)
       return ctl->private;
@@ -75,10 +97,10 @@ ctl_stack_search (struct ctl_class *class)
 }
 
 void
-ctl_stack_pop (void *private UNUSED) 
+ctl_stack_pop (void *private)
 {
   struct ctl_struct *top = ctl_stack;
-  
+
   assert (top != NULL);
   assert (top->private == private);
 
@@ -88,7 +110,7 @@ ctl_stack_pop (void *private UNUSED)
 }
 
 bool
-ctl_stack_is_empty (void) 
+ctl_stack_is_empty (void)
 {
   return ctl_stack == NULL;
 }