Skip to content
Snippets Groups Projects
Commit 628b850f authored by Fredrik Hübinette (Hubbe)'s avatar Fredrik Hübinette (Hubbe)
Browse files

now handles NT pathnames better

Rev: lib/master.pike:1.60
parent 6d198b08
No related branches found
No related tags found
No related merge requests found
/* $Id: master.pike,v 1.59 1998/01/15 05:58:34 hubbe Exp $ /* $Id: master.pike,v 1.60 1998/01/15 17:52:52 hubbe Exp $
* *
* Master-file for Pike. * Master-file for Pike.
*/ */
int is_absolute_path(string p)
{
#ifdef __NT__
p=replace(p,"\\","/");
if(sscanf(p,"%[a-zA-Z]:",string s) && strlen(s)==1)
return 1;
#endif
return p[0]=='/';
}
string *explode_path(string p)
{
#ifdef __NT__
p=replace(p,"\\","/");
#endif
return p/"/";
}
string dirname(string x)
{
string *tmp=explode_path(x);
return tmp[..sizeof(tmp)-2]*"/";
}
string basename(string x)
{
string *tmp=explode_path(x);
return tmp[-1];
}
#define GETCWD_CACHE #define GETCWD_CACHE
#define FILE_STAT_CACHE #define FILE_STAT_CACHE
...@@ -46,7 +77,7 @@ string getcwd() ...@@ -46,7 +77,7 @@ string getcwd()
string combine_path_with_cwd(string path) string combine_path_with_cwd(string path)
{ {
return combine_path(path[0]=='/'?"/":getcwd(),path); return combine_path(is_absolute_path(path)?"/":getcwd(),path);
} }
#ifdef FILE_STAT_CACHE #ifdef FILE_STAT_CACHE
...@@ -58,12 +89,10 @@ mapping(string:multiset(string)) dir_cache = ([]); ...@@ -58,12 +89,10 @@ mapping(string:multiset(string)) dir_cache = ([]);
mixed *master_file_stat(string x) mixed *master_file_stat(string x)
{ {
string file, dir=reverse(combine_path_with_cwd(x)); string file, dir=combine_path_with_cwd(x);
if(sscanf(dir,"%*[/]%s/%s", file, dir)!=3)
file=x;
file=reverse(file); file=basename(dir);
dir=reverse(dir); dir=dirname(dir);
multiset(string) d; multiset(string) d;
if(time() > invalidate_time) if(time() > invalidate_time)
...@@ -209,14 +238,17 @@ program cast_to_program(string pname, string current_file) ...@@ -209,14 +238,17 @@ program cast_to_program(string pname, string current_file)
{ {
string ext; string ext;
string nname; string nname;
if(sscanf(reverse(pname),"%s.%s",ext, nname) && search(ext, "/") == -1) array(string) tmp=explode_path(pname);
if(sscanf(reverse(tmp[-1]),"%s.%s",ext, nname))
{ {
ext="."+reverse(ext); ext="."+reverse(ext);
pname=reverse(nname); tmp[-1]=reverse(nname);
pname=tmp*"/";
}else{ }else{
ext=""; ext="";
} }
if(pname[0]=='/') if(is_absolute_path(pname))
{ {
pname=combine_path("/",pname); pname=combine_path("/",pname);
return findprog(pname,ext); return findprog(pname,ext);
...@@ -224,8 +256,7 @@ program cast_to_program(string pname, string current_file) ...@@ -224,8 +256,7 @@ program cast_to_program(string pname, string current_file)
string cwd; string cwd;
if(current_file) if(current_file)
{ {
string *tmp=current_file/"/"; cwd=dirname(current_file);
cwd=tmp[..sizeof(tmp)-2]*"/";
}else{ }else{
cwd=getcwd(); cwd=getcwd();
} }
...@@ -263,6 +294,11 @@ object new(mixed prog, mixed ... args) ...@@ -263,6 +294,11 @@ object new(mixed prog, mixed ... args)
*/ */
void create() void create()
{ {
add_constant("basename",basename);
add_constant("dirname",dirname);
add_constant("is_absolute_path",is_absolute_path);
add_constant("explode_path",explode_path);
add_constant("compile_string",compile_string); add_constant("compile_string",compile_string);
add_constant("compile_file",compile_file); add_constant("compile_file",compile_file);
add_constant("add_include_path",add_include_path); add_constant("add_include_path",add_include_path);
...@@ -402,7 +438,7 @@ varargs mixed resolv(string identifier, string current_file) ...@@ -402,7 +438,7 @@ varargs mixed resolv(string identifier, string current_file)
if(current_file) if(current_file)
{ {
tmp=current_file/"/"; tmp=explode_path(current_file);
tmp[-1]=identifier; tmp[-1]=identifier;
path=combine_path_with_cwd( tmp*"/"); path=combine_path_with_cwd( tmp*"/");
ret=findmodule(path); ret=findmodule(path);
...@@ -452,8 +488,8 @@ void _main(string *argv, string *env) ...@@ -452,8 +488,8 @@ void _main(string *argv, string *env)
add_constant("write",_static_modules.files()->file("stdout")->write); add_constant("write",_static_modules.files()->file("stdout")->write);
_master_file_name=replace(backtrace()[-1][0],"\\","/"); _master_file_name=backtrace()[-1][0];
q=_master_file_name/"/"; q=explode_path(_master_file_name);
pike_library_path = combine_path_with_cwd(q[0..sizeof(q)-2] * "/"); pike_library_path = combine_path_with_cwd(q[0..sizeof(q)-2] * "/");
add_include_path(pike_library_path+"/include"); add_include_path(pike_library_path+"/include");
...@@ -550,7 +586,7 @@ void _main(string *argv, string *env) ...@@ -550,7 +586,7 @@ void _main(string *argv, string *env)
if(sizeof(argv)==1) if(sizeof(argv)==1)
{ {
argv=argv[0]/"/"; argv=explode_path(argv[0]);
argv[-1]="hilfe"; argv[-1]="hilfe";
argv=({ argv*"/" }); argv=({ argv*"/" });
if(!master_file_stat(argv[0])) if(!master_file_stat(argv[0]))
...@@ -598,8 +634,7 @@ void set_inhibit_compile_errors(mixed f) ...@@ -598,8 +634,7 @@ void set_inhibit_compile_errors(mixed f)
string trim_file_name(string s) string trim_file_name(string s)
{ {
if(getenv("SHORT_PIKE_ERRORS")) if(getenv("SHORT_PIKE_ERRORS")) return basename(s);
return (s/"/")[-1];
return s; return s;
} }
...@@ -651,7 +686,7 @@ string handle_include(string f, ...@@ -651,7 +686,7 @@ string handle_include(string f,
if(local_include) if(local_include)
{ {
tmp=current_file/"/"; tmp=explode_path(current_file);
tmp[-1]=f; tmp[-1]=f;
path=combine_path_with_cwd(tmp*"/"); path=combine_path_with_cwd(tmp*"/");
if(!master_file_stat(path)) return 0; if(!master_file_stat(path)) return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment