filemorph

Check-in [8b85ff041b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add filemorph.c
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:8b85ff041babf9379b60e19c404b60a1315370f3
User & Date: kevin 2015-11-12 11:47:06
Context
2015-11-12
12:20
Further refinement of Windows C exe check-in: 061f050393 user: kevin tags: trunk
11:47
Add filemorph.c check-in: 8b85ff041b user: kevin tags: trunk
05:56
Further refinements to Windows build check-in: 720cd34e52 user: kevin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Added filemorph.c.

            1  +#include "EXTERN.h"
            2  +#include "perl.h"
            3  +#include "XSUB.h"
            4  +#include <Windows.h>
            5  +#include <shlobj.h>
            6  +
            7  +#ifndef CSIDL_APPDATA
            8  +#define CSIDL_APPDATA 0x001a 
            9  +#endif
           10  +
           11  +static PerlInterpreter *my_perl;  /***    The Perl interpreter    ***/
           12  +
           13  +
           14  +EXTERN_C void xs_init (pTHX);
           15  +
           16  +EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
           17  +EXTERN_C void boot_Win32CORE (pTHX_ CV* cv);
           18  +
           19  +EXTERN_C void
           20  +xs_init(pTHX)
           21  +{
           22  +    static const char file[] = __FILE__;
           23  +    dXSUB_SYS;
           24  +    PERL_UNUSED_CONTEXT;
           25  +
           26  +    /* DynaLoader is a special case */
           27  +    newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
           28  +    newXS("Win32CORE::bootstrap", boot_Win32CORE, file);
           29  +}
           30  +
           31  + int main( int argc , char **argv , char **env ) 
           32  +
           33  +{    
           34  +
           35  +    // shift argv and force parameters
           36  +
           37  +    int num_forced_parameters = 4;
           38  +
           39  +    argc += num_forced_parameters;
           40  +
           41  +    int i;
           42  +
           43  +    for(i=argc-1;i>num_forced_parameters;i--){
           44  +        argv[i]=argv[i-num_forced_parameters];
           45  +    }
           46  +
           47  +    //argv[0] stores the relative path of the executable
           48  +
           49  +    argv[1] = "-Ilib";
           50  +	argv[2] = "-Isite/lib";
           51  +	argv[3] = "-Ivendor/lib";
           52  +	
           53  +	
           54  +	//Construct absolute path to script so exe can be launched from anywhere.
           55  +	char script = "\\FileMorph_App\\filemorph\\filemorph.pl\0";
           56  +	char appdata = "";
           57  +	BOOL ok = SHGetSpecialFolderPath(NULL, appdata, CSIDL_APPDATA, TRUE);
           58  +	char path; //strlen(appdata) + strlen(script)];
           59  +	strcpy(path, appdata);
           60  +	strcat(path, script);
           61  +
           62  +	argv[4] = path;
           63  +
           64  +    PERL_SYS_INIT3( &argc , &argv , &env );
           65  +    my_perl = perl_alloc();
           66  +    perl_construct( my_perl );
           67  +
           68  +    perl_parse( my_perl , xs_init , argc , argv , (char **)NULL );
           69  +
           70  +    PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
           71  +
           72  +    perl_run( my_perl );
           73  +    perl_destruct( my_perl );
           74  +    perl_free( my_perl );
           75  +    PERL_SYS_TERM();
           76  +    return 0;
           77  +
           78  +}
           79  +