[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] pnet/clrwrap clrwrap.c,1.1,1.2
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] pnet/clrwrap clrwrap.c,1.1,1.2 |
Date: |
Wed, 26 Nov 2003 07:56:07 +0000 |
Update of /cvsroot/dotgnu-pnet/pnet/clrwrap
In directory subversions:/tmp/cvs-serv6850/clrwrap
Modified Files:
clrwrap.c
Log Message:
Modify "clrwrap" so that it can implicitly get the name of the IL
program to run from argv[0].
Index: clrwrap.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/clrwrap/clrwrap.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** clrwrap.c 15 Jun 2002 01:05:13 -0000 1.1
--- clrwrap.c 26 Nov 2003 07:56:04 -0000 1.2
***************
*** 63,66 ****
--- 63,67 ----
#include "il_utils.h"
#include <stdio.h>
+ #include <stdlib.h>
#ifndef _WIN32
#ifdef HAVE_SYS_TYPES_H
***************
*** 106,109 ****
--- 107,112 ----
static char *FindCLR(void);
static char *RemapName(char *name, char *progname);
+ static char *GetBaseName(char *name);
+ static char *FindExecutableInGac(char *name);
int main(int argc, char *argv[])
***************
*** 114,126 ****
char *clrOption = 0;
int retval;
/* Allocate a new command-line buffer */
! if((newargv = (char **)CLR_MALLOC(sizeof(char *) * (argc + 1))) == 0)
{
OutOfMemory(progname);
}
/* Copy the arguments to the new buffer, and look for "--clr" */
newargc = 1;
while(argc > 1)
{
--- 117,148 ----
char *clrOption = 0;
int retval;
+ char *basename;
+ int needScript;
/* Allocate a new command-line buffer */
! if((newargv = (char **)CLR_MALLOC(sizeof(char *) * (argc + 2))) == 0)
{
OutOfMemory(progname);
}
+ /* Determine if we have been supplied a redirect script, or if
+ "clrwrap" has been symlinked, causing it to implicitly be
+ the name of the executable to redirect to */
+ basename = GetBaseName(progname);
+ needScript = (!ILStrICmp(basename, "clrwrap"));
+
/* Copy the arguments to the new buffer, and look for "--clr" */
newargc = 1;
+ if(!needScript)
+ {
+ newargv[newargc] = FindExecutableInGac(basename);
+ if(!(newargv[newargc]))
+ {
+ fprintf(stderr, "%s: could not find a corresponding IL
binary\n",
+ progname);
+ return 1;
+ }
+ ++newargc;
+ }
while(argc > 1)
{
***************
*** 178,185 ****
/* Remap the name if we were supplied a redirect script */
! newargv[1] = RemapName(newargv[1], progname);
! if(!(newargv[1]))
{
! return 1;
}
--- 200,210 ----
/* Remap the name if we were supplied a redirect script */
! if(needScript)
{
! newargv[1] = RemapName(newargv[1], progname);
! if(!(newargv[1]))
! {
! return 1;
! }
}
***************
*** 457,459 ****
--- 482,538 ----
strcat(newname, ".exe");
return newname;
+ }
+
+ /*
+ * Get the base name from an executable name.
+ */
+ static char *GetBaseName(char *name)
+ {
+ int len = strlen(name);
+ while(len > 0 && name[len - 1] != '/' && name[len - 1] != '\\')
+ {
+ --len;
+ }
+ name += len;
+ len = strlen(name);
+ if(len > 4 && !ILStrICmp(name + len - 4, ".exe"))
+ {
+ return ILDupNString(name, len - 4);
+ }
+ else
+ {
+ return name;
+ }
+ }
+
+ /*
+ * Find the name of an IL binary in the global assembly cache.
+ */
+ static char *FindExecutableInGac(char *name)
+ {
+ char *cachePath;
+ char *searchName;
+
+ /* Get the path to look in for the global assembly cache */
+ cachePath = getenv("CSCC_LIB_PATH");
+ if(!cachePath || *cachePath == '\0')
+ {
+ cachePath = ILGetStandardLibraryPath("cscc/lib");
+ if(!cachePath)
+ {
+ return 0;
+ }
+ }
+
+ /* Construct the name to search for */
+ searchName = (char *)ILMalloc(strlen(name) + 5);
+ if(!searchName)
+ {
+ return 0;
+ }
+ strcpy(searchName, name);
+ strcat(searchName, ".exe");
+
+ /* Search the path for the name and return it */
+ return ILSearchPath(cachePath, searchName, 0);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] pnet/clrwrap clrwrap.c,1.1,1.2,
Rhys Weatherley <address@hidden> <=