Thursday, February 2, 2006, 10:26:56 AM, Nicolas Cannasse wrote:

> Maybe we should try to figure-out the init_path problem, that might be a
> tip for the next one.

This gets me over that hump so I crash now directly from MSYS bash
shell...

#ifdef _WIN32
#define PATHS_SEP ';'
#else
#define PATHS_SEP ':'
#endif

static value init_path( const char *path ) {
        value l = val_null, tmp;
        char *p;
printf("init_path %s\n", path);
#ifdef _WIN32
        char exe_path[MAX_PATH];
        if( path == NULL ) {
                if( 
GetModuleFileName(GetModuleHandle("neko.dll"),exe_path,MAX_PATH) == 0 )
                        return val_null;
                p = strrchr(exe_path,'\\');
                if( p == NULL )
                        return val_null;
                *p = 0;
                path = exe_path;
        }
#else
        if( path == NULL )
                path = 
"/usr/lib/neko:/usr/local/lib/neko:/usr/bin:/usr/local/bin";
#endif
        while( true ) {
                // windows drive letter (same behavior expected on all os)
                if( *path && path[1] == ':' )
                        p = strchr(path+2,PATHS_SEP);
                else
                        p = strchr(path,PATHS_SEP);
                if( p != NULL )
                        *p = 0;
                tmp = alloc_array(2);
                if( (p && p[-1] != '/' && p[-1] != '\\') || (!p && 
path[strlen(path)-1] != '/' && path[strlen(path)-1] != '\\') ) {
                        buffer b = alloc_buffer(path);
                        char c = '/';
                        buffer_append_sub(b,&c,1);
                        val_array_ptr(tmp)[0] = buffer_to_string(b);
                } else
                        val_array_ptr(tmp)[0] = alloc_string(path);
                val_array_ptr(tmp)[1] = l;
printf("init_path %s %s\n", val_string(val_array_ptr(tmp)[0]), p);
                l = tmp;
                if( p != NULL )
                        *p = PATHS_SEP;
                else
                        break;
                path = p+1;
        }
        return l;
}


e


-- 
Neko : One VM to run them all
(http://nekovm.org)

Reply via email to