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