⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 findinjar.c

📁 kaffe Java 解释器语言,源码,Java的子集系统,开放源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	realBootClassPath = KMALLOC(len);	for (ptr = classpath; ptr != 0; ptr = ptr->next) {		if (ptr != classpath) {			strcat(realBootClassPath, path_separator);		}		strcat(realBootClassPath, ptr->path);	}		realClassPath = (char *)Kaffe_JavaVMArgs[0].classpath;	DBG(INIT, dprintf("initClasspath() done, got %s\n", realBootClassPath); )}voidgcjInit(void){#if defined(HAVE_GCJ_SUPPORT)        classpathEntry* entry;        /* Load any shared objects into VM now */        for (entry = classpath; entry != 0; entry = entry->next) {                if (entry->type == CP_SOFILE) {			gcjLoadSharedObject(entry->path);		}	}#endif}/* * Build classpathEntries from the given classpath. */staticvoidmakeClasspath(char* cp){	char* end;DBG(INITCLASSPATH,    	dprintf("initClasspath(): '%s'\n", cp); )	for (;;) {		end = strstr(cp, path_separator);		if (end != 0) {			*end = '\0';			addClasspath(cp);			cp = end + strlen(path_separator);		}		else {			addClasspath(cp);			break;		}	}}/* * Discover all available jar and zip files in this home location and * build a classpath from them. */staticvoiddiscoverClasspath(const char* home){#if defined(HAVE_DIRENT_H)	DIR* dir;	struct dirent* entry;	int len;	int hlen;	char* name;	char* buf;	dir = opendir(home);	if (dir == 0) {		return;	}	/* Add '.' and <home>/Klasses.jar at the beginning */	addClasspath(".");	buf = KMALLOC(strlen(home) + strlen(KLASSES_JAR) + 2);	sprintf(buf, "%s/%s", home, KLASSES_JAR);	addClasspath(buf);	KFREE(buf);	hlen = strlen(home);	while ((entry = readdir(dir)) != 0) {		name = entry->d_name;		len = strlen(name);		if (len > 4 && (strcmp(&name[len-4], ".zip") == 0		    || strcmp(&name[len-4], ".jar") == 0)) {			buf = KMALLOC(strlen(home) + strlen(name) + 2);			sprintf(buf, "%s/%s", home, name);			addClasspath(buf);			KFREE(buf);		}	}	closedir(dir);#endif}/* * Append an entry in the Classpath dynamically. */intaddClasspath(const char* cp){	return insertClasspath(cp, 0);}/* * Prepend an entry in the Classpath dynamically. */intprependClasspath(const char* cp){	return insertClasspath(cp, 1);}/* * Prepend or append an entry in the Classpath dynamically. */static intinsertClasspath(const char* cp, int prepend){	classpathEntry* ptr;	classpathEntry* lptr;#ifdef __riscos__        char unixpath[256];#endifDBG(INITCLASSPATH,	dprintf("insertClasspath(): '%s' %spend\n", cp, prepend ? "pre" : "ap"); )	if (*cp == '\0')		return (0);	lptr = 0;	for (ptr = classpath; ptr != 0; ptr = ptr->next) {		if (strcmp(ptr->path, cp) == 0) {			/* Already in */			return (0);		}		lptr = ptr;	}#ifdef __riscos__        __unixify(cp, 0, unixpath, 256, __RISCOSIFY_FILETYPE_NOTSPECIFIED);        cp = unixpath;#endif	ptr = KMALLOC(sizeof(classpathEntry) + strlen(cp) + 1);	ptr->type = getClasspathType(cp);	ptr->path = (char*)(ptr+1);	strcpy(ptr->path, cp);	if (prepend || classpath == 0) {		ptr->next = classpath;		classpath = ptr;	}	else {		ptr->next = 0;		lptr->next = ptr;	}	return(1);}/* * Work out what kind of thing this path points at. */staticintgetClasspathType(const char* path){	int h;	ssize_t c;	int rc;	char buf[4];	struct stat sbuf;	if (KSTAT(path, &sbuf)) {		return (CP_INVALID);	}	if (S_ISDIR(sbuf.st_mode)) {		return (CP_DIR);	}	rc = KOPEN(path, O_RDONLY|O_BINARY, 0, &h);	if (rc) {		return (CP_INVALID);	}	rc = KREAD(h, buf, sizeof(buf), &c);	KCLOSE(h);	if (c != sizeof(buf)) {		return (CP_INVALID);	}	if (IS_ZIP(buf)) {		return (CP_ZIPFILE);	}	if (IS_SOFILE(buf)) {		return (CP_SOFILE);	}	return (CP_INVALID);}#if defined(HANDLE_MANIFEST_CLASSPATH)/* * Check whether a classpath entry is already in classpath */static intisEntryInClasspath(const char *path){	classpathEntry *ptr;	for(ptr = classpath; ptr != 0; ptr = ptr->next) {		if(!strcmp(ptr->path, path))			return 1;	}	return 0;}static uint8*getManifestMainAttribute(jarFile* file, char* attrName){	jarEntry* mf;	uint8* mfdata;	uint8* attrEntry;	uint8* ret;	int i, posAttrValue;	/* Locate manifest entry in jar */	mf = lookupJarFile(file, "META-INF/MANIFEST.MF");	if (mf == 0)		return (0);	/* Read it */	mfdata = getDataJarFile(file, mf);	if (mfdata == 0)		return (0);	/* Look for the desired entry */	attrEntry = mfdata;	for (i = 0; i < mf->uncompressedSize; ++i) {		/* Sun's jar, even under Linux, insists on terminating		   newlines with newline *and* carriage return */		if (mfdata[i] == '\n' || mfdata[i] == '\r') {			mfdata[i] = '\0';			/* Ecco! this line begins with the attribute's name */			if (strstr(attrEntry, attrName)) {				/* Skip 'attrName:' */				posAttrValue = strlen(attrName) + 1;				attrEntry += posAttrValue;				/* Skip initial whitespace */				while (*attrEntry == ' ' || *attrEntry == '\t')					++attrEntry;				/* Now look for end of string. */				while (i < mf->uncompressedSize && attrEntry[i] != 0xd)					++i;				attrEntry[i] = '\0';				/* OK, allocate memory for the result and return */				ret = KMALLOC(strlen(attrEntry) + 1);				strcpy(ret, attrEntry);				KFREE(mfdata);				return ret;			}			attrEntry = mfdata + i + 1;		}	}	KFREE(mfdata);	return (0);}/* Partially Handle Manifest Class-Path attribute.  It will be better to   handle that in a ClassLoader.  */static voidhandleManifestClassPath (classpathEntry *ptr){	char *mfclasspath0,  *mfclasspath;	char *pathname;	classpathEntry* newEntry;	int last_one;	/* See if there's a Class-Path attribute in the Manifest and have a	   look there */	mfclasspath0 = getManifestMainAttribute(ptr->u.jar, "Class-Path");	if (mfclasspath0 == 0)		return;	mfclasspath = mfclasspath0;	DBG(CLASSLOOKUP,	    dprintf("%s: Manifest 'Class-Path' attribute is '%s'\n",		    ptr->path, mfclasspath);	    );	last_one = 0;	pathname = mfclasspath;	while (*mfclasspath) {		while (*mfclasspath != ' ' &&		       *mfclasspath != '\t' &&		       *mfclasspath != '\0')			++mfclasspath;		if(*mfclasspath == '\0')			last_one = 1;		else			*mfclasspath = '\0';		/* Insert manifest classpath entries */		newEntry = KMALLOC(sizeof(classpathEntry));		newEntry->u.jar = 0;		/* Manifest classpath entries can be either absolute or		   relative to the location of the jar file. */		if (pathname[0] != file_separator[0]) {			int len;			/* Path is relative. First, get the directory of			   the jar file */			len = strlen(ptr->path);			while (len > 0 && ptr->path[len - 1] != file_separator[0])				len--;			if (len != 0) {				newEntry->path = KMALLOC(len + strlen(file_separator) + strlen(pathname));				strncpy (newEntry->path, ptr->path, len - 1);				sprintf (newEntry->path + len - 1, "%s%s",					 file_separator, pathname);			}			else {				newEntry->path = KMALLOC(strlen(pathname) + 1);				strcpy (newEntry->path, pathname);			}		}		else {			/* Path is absolute */			newEntry->path = KMALLOC(strlen(pathname) + 1);			strcpy (newEntry->path, pathname);		}		/* Check if newEntry is a valid classpath element add it to                   classpath if it wasn't already there. */		newEntry->type = getClasspathType (newEntry->path);		if ((newEntry->type != CP_INVALID) &&		    !isEntryInClasspath (newEntry->path)) {DBG(CLASSLOOKUP,	dprintf("Entry '%s' added to classpath\n", newEntry->path); )			newEntry->next = ptr->next;			ptr->next = newEntry;		}		else {			KFREE(newEntry->path);			KFREE(newEntry);		}		/* Go to the following classpath element */		if (!last_one) {			/* Skip '\0' inserted at the blank space */			++mfclasspath;			pathname = mfclasspath;		}		else {			break;		}	}	KFREE(mfclasspath0);}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -