mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
Make stack traces print absolute filenames
darcs-hash:20060202152356-ac50b-9e6ab31c03d5f49824ccca7eee3b8e62d66b0009.gz
This commit is contained in:
parent
5942a6d6c1
commit
06fd1aa9f8
9 changed files with 121 additions and 22 deletions
20
builtin.c
20
builtin.c
|
@ -2001,7 +2001,6 @@ static int builtin_source( wchar_t ** argv )
|
|||
|
||||
argc = builtin_count_args( argv );
|
||||
|
||||
|
||||
if( argc != 2 )
|
||||
{
|
||||
sb_printf( sb_err, _( L"%ls: Expected exactly one argument, got %d\n" ), argv[0], argc );
|
||||
|
@ -2029,10 +2028,23 @@ static int builtin_source( wchar_t ** argv )
|
|||
}
|
||||
else
|
||||
{
|
||||
parser_push_block( SOURCE );
|
||||
reader_push_current_filename( argv[1] );
|
||||
wchar_t *fn = wrealpath( argv[1], 0 );
|
||||
const wchar_t *fn_intern;
|
||||
|
||||
current_block->param1.source_dest = wcsdup( argv[1] );
|
||||
if( !fn )
|
||||
{
|
||||
fn_intern = intern( argv[1] );
|
||||
}
|
||||
else
|
||||
{
|
||||
fn_intern = intern(fn);
|
||||
free( fn );
|
||||
}
|
||||
|
||||
parser_push_block( SOURCE );
|
||||
reader_push_current_filename( fn_intern );
|
||||
|
||||
current_block->param1.source_dest = fn_intern;
|
||||
|
||||
res = reader_read( fd );
|
||||
parser_pop_block();
|
||||
|
|
18
configure.ac
18
configure.ac
|
@ -18,6 +18,7 @@ for i in /usr/pkg /sw; do
|
|||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
# If needed, run autoheader automatically
|
||||
|
@ -163,6 +164,23 @@ else
|
|||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
# Check if realpath accepts null for its second argument
|
||||
AC_MSG_CHECKING([if realpath accepts null for its second argument])
|
||||
AC_RUN_IFELSE(
|
||||
[AC_LANG_PROGRAM([#include <limits.h>
|
||||
#include <stdlib.h>],
|
||||
[int status; char *res; res = realpath( "foo", 0 ); status = (res && (strlen(res)>3))?0:1; free(res); exit( status );])],
|
||||
[have_realpath_null=yes],
|
||||
[have_realpath_null=no] )
|
||||
|
||||
if test "$have_realpath_null" = yes; then
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE([HAVE_REALPATH_NULL], [1],
|
||||
[Define to 1 if realpath accepts null for its second argument.])
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
|
||||
# Check for libraries
|
||||
AC_CHECK_LIB(socket, connect)
|
||||
|
|
10
main.c
10
main.c
|
@ -244,6 +244,7 @@ int main( int argc, char **argv )
|
|||
int i;
|
||||
string_buffer_t sb;
|
||||
int fd;
|
||||
wchar_t *rel_filename, *abs_filename;
|
||||
|
||||
if( ( fd = open(file, O_RDONLY) ) == -1 )
|
||||
{
|
||||
|
@ -268,7 +269,12 @@ int main( int argc, char **argv )
|
|||
sb_destroy( &sb );
|
||||
}
|
||||
|
||||
reader_push_current_filename( str2wcs( file ) );
|
||||
rel_filename = str2wcs( file );
|
||||
abs_filename = wrealpath( rel_filename, 0 );
|
||||
reader_push_current_filename( intern( abs_filename ) );
|
||||
free( rel_filename );
|
||||
free( abs_filename );
|
||||
|
||||
res = reader_read( fd );
|
||||
|
||||
if( res )
|
||||
|
@ -277,7 +283,7 @@ int main( int argc, char **argv )
|
|||
_(L"Error while reading file %ls\n"),
|
||||
reader_current_filename()?reader_current_filename(): _(L"Standard input") );
|
||||
}
|
||||
free(reader_pop_current_filename());
|
||||
reader_pop_current_filename();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
11
parser.c
11
parser.c
|
@ -36,6 +36,7 @@ The fish parser. Contains functions for parsing code.
|
|||
#include "env_universal.h"
|
||||
#include "event.h"
|
||||
#include "translate.h"
|
||||
#include "intern.h"
|
||||
|
||||
/**
|
||||
Maximum number of block levels in code. This is not the same as
|
||||
|
@ -339,7 +340,7 @@ void parser_push_block( int type )
|
|||
block_t *new = calloc( 1, sizeof( block_t ));
|
||||
|
||||
new->src_lineno = parser_get_lineno();
|
||||
new->src_filename = parser_current_filename()?wcsdup(parser_current_filename()):0;
|
||||
new->src_filename = parser_current_filename()?intern(parser_current_filename()):0;
|
||||
|
||||
debug( 3, L"Block push %ls %d\n", parser_get_block_desc(type), block_count( current_block)+1 );
|
||||
|
||||
|
@ -418,12 +419,6 @@ void parser_pop_block()
|
|||
break;
|
||||
}
|
||||
|
||||
case SOURCE:
|
||||
{
|
||||
free( current_block->param1.source_dest );
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for( eb=current_block->first_event_block; eb; eb=eb_next )
|
||||
|
@ -432,8 +427,6 @@ void parser_pop_block()
|
|||
free(eb);
|
||||
}
|
||||
|
||||
free( current_block->src_filename );
|
||||
|
||||
block_t *old = current_block;
|
||||
current_block = current_block->outer;
|
||||
free( old );
|
||||
|
|
4
parser.h
4
parser.h
|
@ -65,7 +65,7 @@ typedef struct block
|
|||
int if_state; /**< The state of the if block */
|
||||
wchar_t *switch_value; /**< The value to test in a switch block */
|
||||
wchar_t *function_name; /**< The name of the function to define or the function called*/
|
||||
wchar_t *source_dest; /**< The name of the file to source*/
|
||||
const wchar_t *source_dest; /**< The name of the file to source*/
|
||||
event_t *event; /**<The event that triggered this block */
|
||||
} param1;
|
||||
|
||||
|
@ -99,7 +99,7 @@ typedef struct block
|
|||
/**
|
||||
Name of file that created this block
|
||||
*/
|
||||
wchar_t *src_filename;
|
||||
const wchar_t *src_filename;
|
||||
|
||||
/**
|
||||
Line number where this block was created
|
||||
|
|
3
reader.c
3
reader.c
|
@ -390,7 +390,7 @@ wchar_t *reader_current_filename()
|
|||
}
|
||||
|
||||
|
||||
void reader_push_current_filename( wchar_t *fn )
|
||||
void reader_push_current_filename( const wchar_t *fn )
|
||||
{
|
||||
al_push( ¤t_filename, fn );
|
||||
}
|
||||
|
@ -2678,7 +2678,6 @@ wchar_t *reader_readline()
|
|||
(last_char != R_HISTORY_TOKEN_SEARCH_FORWARD) )
|
||||
{
|
||||
reset=1;
|
||||
|
||||
}
|
||||
|
||||
handle_token_history( 0, reset );
|
||||
|
|
2
reader.h
2
reader.h
|
@ -48,7 +48,7 @@ wchar_t *reader_current_filename();
|
|||
|
||||
\param fn The fileanme to push
|
||||
*/
|
||||
void reader_push_current_filename( wchar_t *fn );
|
||||
void reader_push_current_filename( const wchar_t *fn );
|
||||
/**
|
||||
Pop the current filename from the stack of read files
|
||||
*/
|
||||
|
|
63
wutil.c
63
wutil.c
|
@ -26,6 +26,14 @@
|
|||
|
||||
#define TMP_LEN_MIN 256
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#ifdef MAXPATHLEN
|
||||
#define PATH_MAX MAXPATHLEN
|
||||
#else
|
||||
#define PATH_MAX 4096
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
Buffer for converting wide arguments to narrow arguments, used by
|
||||
the \c wutil_wcs2str() function.
|
||||
|
@ -219,6 +227,61 @@ void wperror(const wchar_t *s)
|
|||
fwprintf( stderr, L"%s\n", strerror( errno ) );
|
||||
}
|
||||
|
||||
#ifdef HAVE_REALPATH_NULL
|
||||
|
||||
wchar_t *wrealpath(const wchar_t *pathname, wchar_t *resolved_path)
|
||||
{
|
||||
char *tmp = wutil_wcs2str(pathname);
|
||||
char *narrow_res = realpath( tmp, 0 );
|
||||
wchar_t *res;
|
||||
|
||||
if( !narrow_res )
|
||||
return 0;
|
||||
|
||||
if( resolved_path )
|
||||
{
|
||||
wchar_t *tmp2 = str2wcs( narrow_res );
|
||||
wcslcpy( resolved_path, tmp2, PATH_MAX );
|
||||
free( tmp2 );
|
||||
res = resolved_path;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = str2wcs( narrow_res );
|
||||
}
|
||||
|
||||
free( narrow_res );
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
wchar_t *wrealpath(const wchar_t *pathname, wchar_t *resolved_path)
|
||||
{
|
||||
char *tmp =wutil_wcs2str(name);
|
||||
char narrow[PATH_MAX];
|
||||
char *narrow_res = realpath( tmp, narrow );
|
||||
wchar_t *res;
|
||||
|
||||
if( !narrow_res )
|
||||
return 0;
|
||||
|
||||
if( resolved_path )
|
||||
{
|
||||
wchar_t *tmp2 = str2wcs( narrow_res );
|
||||
wcslcpy( resolved_path, tmp2, PATH_MAX );
|
||||
free( tmp2 );
|
||||
res = resolved_path;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = str2wcs( narrow_res );
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if !HAVE_FWPRINTF
|
||||
|
||||
|
|
8
wutil.h
8
wutil.h
|
@ -81,6 +81,14 @@ wchar_t *wgetcwd( wchar_t *buff, size_t sz );
|
|||
*/
|
||||
int wchdir( const wchar_t * dir );
|
||||
|
||||
/**
|
||||
Wide character verion of realpath function. Just like the GNU
|
||||
version of realpath, wrealpath will accept 0 as the value for the
|
||||
second argument, in which case the result will be allocated using
|
||||
malloc, and must be free'd by the user.
|
||||
*/
|
||||
wchar_t *wrealpath(const wchar_t *pathname, wchar_t *resolved_path);
|
||||
|
||||
/*
|
||||
Here follows the prototypes for fallback implementations of various
|
||||
standarcs libc functions relating to wide character support. Some of
|
||||
|
|
Loading…
Reference in a new issue