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

module system simplified

Rev: lib/master.pike:1.25
parent aec39a16
No related branches found
No related tags found
No related merge requests found
...@@ -179,13 +179,18 @@ class mergenode ...@@ -179,13 +179,18 @@ class mergenode
} }
}; };
object findmodule(string fullname) object low_findmodule(string fullname)
{ {
mixed *stat; mixed *stat;
program p; program p;
if(p=(program)(fullname+".pmod")) if(mixed *stat=file_stat(fullname+".pmod"))
return (object)(fullname+".pmod"); {
if(stat[1]==-2)
return dirnode(fullname+".pmod");
else
return (object)(fullname+".pmod");
}
#if constant(load_module) #if constant(load_module)
if(file_stat(fullname+".so")) if(file_stat(fullname+".so"))
{ {
...@@ -193,43 +198,41 @@ object findmodule(string fullname) ...@@ -193,43 +198,41 @@ object findmodule(string fullname)
} }
#endif #endif
#ifdef NOT_INSTALLED
/* Hack for pre-install testing */ /* Hack for pre-install testing */
if(mixed *stat=file_stat(fullname)) if(mixed *stat=file_stat(fullname))
{ {
if(stat[1]==-2) if(stat[1]==-2)
return findmodule(fullname+"/module"); return low_findmodule(fullname+"/module");
} }
#endif
if(mixed *stat=file_stat(fullname+".pmd"))
{
if(stat[1]==-2)
return dirnode(fullname+".pmd");
}
return UNDEFINED; return UNDEFINED;
} }
static mixed idiresolv(string identifier) mixed findmodule(string path)
{ {
string path=combine_path(pike_library_path+"/modules",identifier); if(object o=low_findmodule(path))
if(mixed ret=findmodule(path)) return ret; {
return _static_modules[identifier]; if(mixed tmp=o->_module_value)
{
return tmp;
}
}
return o;
} }
mixed resolv(string identifier, string current_file) varargs mixed resolv(string identifier, string current_file)
{ {
mixed ret; mixed ret;
string *tmp,path; string *tmp,path;
multiset tested=(<>);
mixed *modules=({});
tmp=current_file/"/"; if(current_file)
tmp[-1]=identifier;
path=combine_path(getcwd(), tmp*"/");
if(!tested[path])
{ {
tested[path]=1; tmp=current_file/"/";
if(ret=findmodule(path)) modules+=({ret}); tmp[-1]=identifier;
path=combine_path(getcwd(), tmp*"/");
if(ret=findmodule(path)) return ret;
} }
if(path=getenv("PIKE_MODULE_PATH")) if(path=getenv("PIKE_MODULE_PATH"))
...@@ -238,39 +241,14 @@ mixed resolv(string identifier, string current_file) ...@@ -238,39 +241,14 @@ mixed resolv(string identifier, string current_file)
{ {
if(!sizeof(path)) continue; if(!sizeof(path)) continue;
path=combine_path(path,identifier); path=combine_path(path,identifier);
if(!tested[path]) if(ret=findmodule(path)) return ret;
{
tested[path]=1;
if(ret=findmodule(path)) modules+=({ret});
}
} }
} }
string path=combine_path(pike_library_path+"/modules",identifier); string path=combine_path(pike_library_path+"/modules",identifier);
if(!tested[path]) if(ret=findmodule(path)) return ret;
{
tested[path]=1;
if(ret=findmodule(path)) modules+=({ret});
}
if(ret=_static_modules[identifier]) modules+=({ret});
switch(sizeof(modules)) if(ret=_static_modules[identifier]) return ret;;
{ return UNDEFINED;
default:
mixed tmp=mergenode(modules);
werror(sprintf("%O\n",tmp["file"]));
return tmp;
case 1:
return modules[0];
case 0:
switch(identifier)
{
case "readline":
if(!resolv("readlinemod", current_file))
werror("No readline module.\n");
return all_constants()->readline;
}
return UNDEFINED;
}
} }
/* This function is called when all the driver is done with all setup /* This function is called when all the driver is done with all setup
...@@ -291,13 +269,13 @@ void _main(string *argv, string *env) ...@@ -291,13 +269,13 @@ void _main(string *argv, string *env)
add_constant("getenv",getenv); add_constant("getenv",getenv);
add_constant("putenv",putenv); add_constant("putenv",putenv);
add_constant("write",idiresolv("files")->file("stdout")->write); add_constant("write",_static_modules.files.file("stdout")->write);
a=backtrace()[-1][0]; a=backtrace()[-1][0];
q=a/"/"; q=a/"/";
pike_library_path = q[0..sizeof(q)-2] * "/"; pike_library_path = q[0..sizeof(q)-2] * "/";
tmp=idiresolv("getopt"); tmp=resolv("Getopt");
foreach(tmp->find_all_options(argv,({ foreach(tmp->find_all_options(argv,({
({"version",tmp->NO_ARG,({"-v","--version"})}), ({"version",tmp->NO_ARG,({"-v","--version"})}),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment