X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fgetl.c;h=9db6c3ae56260d3be735efd45588622b4eb2077b;hb=refs%2Fbuilds%2F149%2Fpspp;hp=1214b95ca1f3da178f6b34bac1af8893e0b5d3c3;hpb=9f087e7aa4cdff1d5d46d5e188c0017a9d2d0029;p=pspp
diff --git a/src/libpspp/getl.c b/src/libpspp/getl.c
index 1214b95ca1..9db6c3ae56 100644
--- a/src/libpspp/getl.c
+++ b/src/libpspp/getl.c
@@ -1,5 +1,5 @@
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006, 2009, 2010 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
@@ -14,16 +14,19 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see . */
-#include
#include
-#include "getl.h"
+#include "libpspp/getl.h"
+
+#include
-#include
-#include
-#include
+#include "libpspp/ll.h"
+#include "libpspp/str.h"
+#include "libpspp/string-array.h"
-#include "xalloc.h"
+#include "gl/configmake.h"
+#include "gl/relocatable.h"
+#include "gl/xalloc.h"
struct getl_source
{
@@ -40,14 +43,15 @@ struct getl_source
struct source_stream
{
struct ll_list sources ; /* List of source files. */
-
- struct string the_include_path;
+ struct string_array include_path;
};
-const char *
-getl_include_path (const struct source_stream *ss)
+char **
+getl_include_path (const struct source_stream *ss_)
{
- return ds_cstr (&ss->the_include_path);
+ struct source_stream *ss = CONST_CAST (struct source_stream *, ss_);
+ string_array_terminate_null (&ss->include_path);
+ return ss->include_path.strings;
}
static struct getl_source *
@@ -79,15 +83,19 @@ source_stream_current_error_mode (const struct source_stream *ss)
/* Initialize getl. */
struct source_stream *
-create_source_stream (const char *initial_include_path)
+create_source_stream (void)
{
- struct source_stream *ss = xzalloc (sizeof (*ss));
+ struct source_stream *ss;
+
+ ss = xzalloc (sizeof (*ss));
ll_init (&ss->sources);
-#if 0
- ds_init_cstr (&ss->the_include_path,
- fn_getenv_default ("STAT_INCLUDE_PATH", include_path));
-#endif
- ds_init_cstr (&ss->the_include_path, initial_include_path);
+
+ string_array_init (&ss->include_path);
+ string_array_append (&ss->include_path, ".");
+ if (getenv ("HOME") != NULL)
+ string_array_append_nocopy (&ss->include_path,
+ xasprintf ("%s/.pspp", getenv ("HOME")));
+ string_array_append (&ss->include_path, relocate (PKGDATADIR));
return ss;
}
@@ -96,17 +104,14 @@ create_source_stream (const char *initial_include_path)
void
getl_clear_include_path (struct source_stream *ss)
{
- ds_clear (&ss->the_include_path);
+ string_array_clear (&ss->include_path);
}
/* Add to the include path. */
void
getl_add_include_dir (struct source_stream *ss, const char *path)
{
- if (ds_length (&ss->the_include_path))
- ds_put_char (&ss->the_include_path, ':');
-
- ds_put_cstr (&ss->the_include_path, path);
+ string_array_append (&ss->include_path, path);
}
/* Appends source S to the list of source files. */
@@ -207,18 +212,18 @@ getl_source_name (const struct source_stream *ss)
return s->interface->name (s->interface);
}
-/* Returns the location within the current source, or -1 if there is
- no current source */
+/* Returns the line number within the current source, or 0 if there is no
+ current source. */
int
getl_source_location (const struct source_stream *ss)
{
const struct getl_source *s = current_source (ss);
if ( ll_is_empty (&ss->sources) )
- return -1;
+ return 0;
if ( !s->interface->location )
- return -1;
+ return 0;
return s->interface->location (s->interface);
}
@@ -230,7 +235,7 @@ destroy_source_stream (struct source_stream *ss)
{
while ( !ll_is_empty (&ss->sources))
close_source (ss);
- ds_destroy (&ss->the_include_path);
+ string_array_destroy (&ss->include_path);
free (ss);
}