Change license from GPLv2+ to GPLv3+.
[pspp-builds.git] / src / language / prompt.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #include <config.h>
18
19 #include <stdio.h>
20 #include <errno.h>
21 #include <stdlib.h>
22
23 #include "prompt.h"
24
25 #include <data/file-name.h>
26 #include <data/settings.h>
27 #include <data/variable.h>
28 #include <language/command.h>
29 #include <language/lexer/lexer.h>
30 #include <libpspp/alloc.h>
31 #include <libpspp/assertion.h>
32 #include <libpspp/message.h>
33 #include <libpspp/message.h>
34 #include <libpspp/str.h>
35 #include <libpspp/verbose-msg.h>
36 #include <libpspp/version.h>
37 #include <output/table.h>
38
39 /* Current prompts in each style. */
40 static char *prompts[PROMPT_CNT];
41
42 /* Current prompting style. */
43 static enum prompt_style current_style;
44
45 /* Initializes prompts. */
46 void
47 prompt_init (void)
48 {
49   prompts[PROMPT_FIRST] = xstrdup ("PSPP> ");
50   prompts[PROMPT_LATER] = xstrdup ("    > ");
51   prompts[PROMPT_DATA] = xstrdup ("data> ");
52   current_style = PROMPT_FIRST;
53 }
54
55 /* Frees prompts. */
56 void
57 prompt_done (void)
58 {
59   int i;
60
61   for (i = 0; i < PROMPT_CNT; i++)
62     {
63       free (prompts[i]);
64       prompts[i] = NULL;
65     }
66 }
67
68 /* Gets the command prompt for the given STYLE. */
69 const char *
70 prompt_get (enum prompt_style style)
71 {
72   assert (style < PROMPT_CNT);
73   return prompts[style];
74 }
75
76 /* Sets the given STYLE's prompt to STRING. */
77 void
78 prompt_set (enum prompt_style style, const char *string)
79 {
80   assert (style < PROMPT_CNT);
81   free (prompts[style]);
82   prompts[style] = xstrdup (string);
83 }
84
85 /* Sets STYLE as the current prompt style. */
86 void
87 prompt_set_style (enum prompt_style style)
88 {
89   assert (style < PROMPT_CNT);
90   current_style = style;
91 }
92
93 /* Returns the current prompt. */
94 enum prompt_style
95 prompt_get_style (void)
96 {
97   return current_style;
98 }