// a simple program which executes a perl script at // one of following locations, whichever comes first: // modules/[name].pl // perl/[name].pl // ./[name].pl // modules/executor-resolver.pl // perl/executor-resolver.pl // ./executor-resolver.pl //? modules/[name] //? perl/[name] //? ./[name] #include #include #include #include "EXTERN.h" #include "perl.h" int main(int argc, char *argv[], char **env) { char bufstr[2048]; char fullpath[2048]; char name[2048]; char **xargv = (char**)malloc(sizeof(char*)*(argc+2)); char *script[] = // how to search for script to run { "modules\\", "perl\\", "", 0 }; char history[2048]; int i=0, j, k, rc; bufstr[0]=0; strcpy(history,"tried:\n "); GetModuleFileName(NULL,fullpath,2048); j = strlen(fullpath); while (j && fullpath[j]!='\\') j--; j++; strcpy(name,fullpath+j); k = strlen(name); if (stricmp(name+k-4,".exe")==0) { //okay name[k-4] = 0; } else { MessageBox(0,name,"bad: not able to parse",0); return 1; } //MessageBox(0,name,"good:",0); fullpath[j] = 0; strcpy(bufstr,fullpath); // try with 'name' first for (k=0;script[k];k++) { strcpy(bufstr+j,script[k]); strcat(bufstr+j,name); strcat(bufstr+j,".pl"); strcat(history,bufstr); strcat(history,"\n "); #undef access if (!access(bufstr,0)) { //found it! goto found; } } // try with "executor-resolver.pl" at second set of tries for (k=0;script[k];k++) { strcpy(bufstr+j,script[k]); strcat(bufstr+j,"executor-resolver.pl"); strcat(history,bufstr); strcat(history,"\n "); #undef access if (!access(bufstr,0)) { //found it! //but here script name should be inserted xargv = (char**)malloc(sizeof(char*)*(argc+4)); for (k=0; k