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