Author: paultcochrane
Date: Mon May 7 01:00:15 2007
New Revision: 18446
Modified:
trunk/src/library.c
Log:
[src] Applied rebased extension-guessing patch from Mike Mattie <codermattie
at gmail dot com>, see RT#41908.
Modified: trunk/src/library.c
==============================================================================
--- trunk/src/library.c (original)
+++ trunk/src/library.c Mon May 7 01:00:15 2007
@@ -257,6 +257,78 @@
return join;
}
+#define LOAD_EXT_CODE_LAST 3
+
+static const char* load_ext_code[ LOAD_EXT_CODE_LAST + 1 ] = {
+ ".pbc",
+
+ /* source level files */
+
+ ".pasm",
+ ".past",
+ ".pir",
+};
+
+static STRING*
+try_load_path(Interp *interp, STRING* path) {
+ STRING *final;
+
+ final = string_copy(interp, path);
+
+#if 0
+ printf("path is \"%s\"\n",
+ string_to_cstring(interp, final ));
+#endif
+
+ final = path_finalize(interp, final );
+
+ if (Parrot_stat_info_intval(interp, final , STAT_EXISTS)) {
+ return final;
+ }
+
+ return NULL;
+}
+
+/*
+ guess extensions, so that the user can drop the extensions
+ leaving it up to the build process/install whether or not
+ a .pbc or a .pir file is used.
+ */
+
+static STRING*
+try_bytecode_extensions (Interp *interp, STRING* path )
+{
+ STRING *with_ext, *result;
+
+ int guess;
+
+ /*
+ first try the path without guessing ensure compatability with existing
code.
+ */
+
+ with_ext = string_copy(interp, path);
+
+ if ( (result = try_load_path(interp, with_ext) ) )
+ return result;
+
+ /*
+ start guessing now. this version tries to find the lowest form of the
+ code, starting with bytecode and working up to PIR. note the atypical
+ loop control. This is so the array can easily be processed in reverse.
+ */
+
+ for( guess = 0 ; guess <= LOAD_EXT_CODE_LAST ; guess++ ) {
+ with_ext = string_copy(interp, path);
+ with_ext = string_append(interp,
+ with_ext, const_string(interp,
load_ext_code[guess]));
+
+ if ( (result = try_load_path(interp, with_ext)) )
+ return result;
+ }
+
+ return NULL;
+}
+
/*
=item C<char* Parrot_locate_runtime_file(Interp *, const char *file_name,
@@ -289,6 +361,11 @@
INTVAL i, n;
PMC *paths;
+#if 0
+ printf("requesting path: \"%s\"\n",
+ string_to_cstring(interp, file ));
+#endif
+
/* if this is an absolute path return it as is */
if (is_abs_path(interp, file))
return file;
@@ -313,16 +390,20 @@
full_name = path_append(interp, full_name , file);
- full_name = path_finalize(interp, full_name);
- if (Parrot_stat_info_intval(interp, full_name, STAT_EXISTS)) {
+ full_name = ( type & PARROT_RUNTIME_FT_DYNEXT )
+ ? try_load_path(interp, full_name)
+ : try_bytecode_extensions(interp, full_name);
+
+ if ( full_name )
return full_name;
- }
}
- full_name = path_finalize(interp, file);
- if (Parrot_stat_info_intval(interp, full_name, STAT_EXISTS)) {
- return full_name;
- }
+ full_name = ( type & PARROT_RUNTIME_FT_DYNEXT )
+ ? try_load_path(interp, file)
+ : try_bytecode_extensions(interp, file);
+
+ if ( full_name )
+ return full_name;
return NULL;
}