aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-02-02 15:05:08 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-02-02 15:05:08 -0800
commit623eb42a6aaab967cf856f7e7f2f6fc7f38b4b3f (patch)
tree9b1d3a7644b9a0ab0eedac81c636dfab570ef406
parent6afc06b97e3914062578fa7329b92f32f169f4c8 (diff)
CLean up current_filename, make it a std::stack
-rw-r--r--parser.cpp4
-rw-r--r--reader.cpp22
-rw-r--r--reader.h4
3 files changed, 18 insertions, 12 deletions
diff --git a/parser.cpp b/parser.cpp
index 34026770..7ed65bc8 100644
--- a/parser.cpp
+++ b/parser.cpp
@@ -1012,6 +1012,10 @@ int parser_t::get_lineno() const
const wchar_t *parser_t::current_filename() const
{
+ /* We query a global array for the current file name, so it only makes sense to ask this on the principal parser. */
+ ASSERT_IS_MAIN_THREAD();
+ assert(this == &principal_parser());
+
block_t *b = current_block;
while( 1 )
diff --git a/reader.cpp b/reader.cpp
index 10f02004..2e67c89f 100644
--- a/reader.cpp
+++ b/reader.cpp
@@ -44,6 +44,7 @@ commence.
#include <sys/poll.h>
#include <unistd.h>
#include <wctype.h>
+#include <stack>
#if HAVE_NCURSES_H
#include <ncurses.h>
@@ -103,6 +104,7 @@ commence.
#include "halloc.h"
#include "halloc_util.h"
#include "iothread.h"
+#include "intern.h"
#include "parse_util.h"
@@ -325,9 +327,9 @@ static int is_interactive_read;
static int end_loop = 0;
/**
- The list containing names of files that are being parsed
+ The stack containing names of files that are being parsed
*/
-static array_list_t current_filename;
+static std::stack<const wchar_t *> current_filename;
/**
@@ -498,21 +500,24 @@ void reader_handle_int( int sig )
}
-wchar_t *reader_current_filename()
+const wchar_t *reader_current_filename()
{
- return al_get_count( &current_filename )?(wchar_t *)al_peek( &current_filename ):0;
+ ASSERT_IS_MAIN_THREAD();
+ return current_filename.empty() ? NULL : current_filename.top();
}
void reader_push_current_filename( const wchar_t *fn )
{
- al_push( &current_filename, fn );
+ ASSERT_IS_MAIN_THREAD();
+ current_filename.push(intern(fn));
}
-wchar_t *reader_pop_current_filename()
+void reader_pop_current_filename()
{
- return (wchar_t *)al_pop( &current_filename );
+ ASSERT_IS_MAIN_THREAD();
+ current_filename.pop();
}
@@ -730,14 +735,11 @@ void reader_init()
shell_modes.c_lflag &= ~ECHO; /* turn off echo mode */
shell_modes.c_cc[VMIN]=1;
shell_modes.c_cc[VTIME]=0;
-
- al_init( &current_filename);
}
void reader_destroy()
{
- al_destroy( &current_filename);
tcsetattr(0, TCSANOW, &saved_modes);
}
diff --git a/reader.h b/reader.h
index e9ac2279..593a816d 100644
--- a/reader.h
+++ b/reader.h
@@ -46,7 +46,7 @@ void reader_destroy();
/**
Returns the filename of the file currently read
*/
-wchar_t *reader_current_filename();
+const wchar_t *reader_current_filename();
/**
Push a new filename on the stack of read files
@@ -57,7 +57,7 @@ void reader_push_current_filename( const wchar_t *fn );
/**
Pop the current filename from the stack of read files
*/
-wchar_t *reader_pop_current_filename();
+void reader_pop_current_filename();
/**
Write the title to the titlebar. This function is called just