X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fline-buffer.c;h=0dcb70f94952bab00fdd98cf09db83f02d729d6e;hb=3816248a008a4af75aac6319d0c9929cb7ff679e;hp=1b48f5386e26457bf95bcc797e5458d1ffb96429;hpb=b74d09af5e07f954c18e7cdb8aca3af47fa10208;p=pspp diff --git a/src/language/line-buffer.c b/src/language/line-buffer.c index 1b48f5386e..0dcb70f949 100644 --- a/src/language/line-buffer.c +++ b/src/language/line-buffer.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -85,7 +86,7 @@ struct getl_source function; /* INTERACTIVE. */ - bool (*interactive) (struct string *line, const char *prompt); + bool (*interactive) (struct string *line, enum getl_prompt_style); } u; @@ -97,13 +98,13 @@ static struct getl_source *last_source; static struct string getl_include_path; -struct string getl_buf; static void close_source (void); static void init_prompts (void); static void uninit_prompts (void); -static const char *get_prompt (void); +static enum getl_prompt_style get_prompt_style (void); + /* Initialize getl. */ void @@ -111,10 +112,10 @@ getl_initialize (void) { ds_init_cstr (&getl_include_path, fn_getenv_default ("STAT_INCLUDE_PATH", include_path)); - ds_init_empty (&getl_buf); init_prompts (); } + /* Delete everything from the include path. */ void getl_clear_include_path (void) @@ -214,7 +215,7 @@ create_function_source (bool (*read) (struct string *line, /* Creates an interactive source with the given FUNCTION. */ static struct getl_source * create_interactive_source (bool (*function) (struct string *line, - const char *prompt)) + enum getl_prompt_style)) { struct getl_source *s = xmalloc (sizeof *s); s->fn = NULL; @@ -297,7 +298,7 @@ getl_include_function (bool (*read) (struct string *line, obtained or false at end of file. */ void getl_append_interactive (bool (*function) (struct string *line, - const char *prompt)) + enum getl_prompt_style)) { append_source (create_interactive_source (function)); } @@ -377,6 +378,7 @@ getl_location (const char **fn, int *ln) /* File locator stack. */ static const struct msg_locator **file_loc; + static int nfile_loc, mfile_loc; /* Close getl. */ @@ -385,7 +387,6 @@ getl_uninitialize (void) { while (cur_source != NULL) close_source (); - ds_destroy (&getl_buf); ds_destroy (&getl_include_path); free(file_loc); file_loc = NULL; @@ -423,10 +424,10 @@ msg_pop_msg_locator (const struct msg_locator *loc) nfile_loc--; } -/* Puts the current file and line number in F, or NULL and -1 if +/* Puts the current file and line number into LOC, or NULL and -1 if none. */ void -msg_location (struct msg_locator *loc) +get_msg_location (struct msg_locator *loc) { if (nfile_loc) *loc = *file_loc[nfile_loc - 1]; @@ -489,10 +490,10 @@ read_line_from_source (struct string *line, struct getl_source *s) case FUNCTION: return s->u.function.read (line, &s->fn, &s->ln, s->u.function.aux); case INTERACTIVE: - return s->u.interactive (line, get_prompt ()); + return s->u.interactive (line, get_prompt_style ()); } - abort (); + NOT_REACHED (); } /* Reads a single line into LINE. @@ -500,7 +501,7 @@ read_line_from_source (struct string *line, struct getl_source *s) If INTERACTIVE is non-null, then when true is returned *INTERACTIVE will be set to true if the line was obtained interactively, false otherwise. */ -static bool +bool do_read_line (struct string *line, bool *interactive) { while (cur_source != NULL) @@ -523,16 +524,6 @@ do_read_line (struct string *line, bool *interactive) return false; } -/* Reads a single line into getl_buf. - Returns true when a line has been read, false at end of input. - If INTERACTIVE is non-null, then when true is returned - *INTERACTIVE will be set to true if the line was obtained - interactively, false otherwise. */ -bool -getl_read_line (bool *interactive) -{ - return do_read_line (&getl_buf, interactive); -} /* Current prompts in each style. */ static char *prompts[GETL_PROMPT_CNT]; @@ -589,8 +580,8 @@ getl_set_prompt_style (enum getl_prompt_style style) } /* Returns the current prompt. */ -static const char * -get_prompt (void) +static enum getl_prompt_style +get_prompt_style (void) { - return prompts[current_style]; + return current_style; }