Beispiel #1
0
KMLFILE *KMLPackGetKMLFILE(char *str)
{
	FILE			*filein;
	KMLFILE			*kmlf;
	int				i;
	char			path	[KML_PACK_SIZEOF_FILENAME];
	char			endname	[KML_PACK_SIZEOF_FILENAME];
	char			strtmp	[KML_PACK_SIZEOF_FILENAME];


	// clip
	if(!str)
		return NULL;

	// ouverture du fichier
	if( (filein=fopen(str,"rb")) == NULL )
		return NULL;

	strcpy(strtmp, str);
	strcpy(path, str);
	for(i=strlen(str); strtmp[i]!='/'; i--);
	strcpy(endname, &strtmp[i+1]);
	path[i]=0;
	
	//init
	kmlf				= (KMLFILE *)ALLOC2(sizeof(KMLFILE),BMKMLLightMemory);
	memset(kmlf, 0, sizeof(KMLFILE));
	kmlf->offset		= 0;
	strcpy(kmlf->filename,	endname);
	strcpy(kmlf->path,		path);

	// get file size
	fseek(filein, 0, SEEK_END);
	kmlf->sizeofdata	= (unsigned long)ftell(filein);

	// allocation
	kmlf->data			= (void *)ALLOC2(kmlf->sizeofdata,BMKMLLightMemory);

	//lecture et stockage
	fseek(filein, 0, SEEK_SET);
	fread(kmlf->data, kmlf->sizeofdata, 1, filein);
	
	//fermeture
	fclose(filein);

	return kmlf;
}
Beispiel #2
0
//*********************************************************************
//* FUNCTION: BMSendEvent
//*--------------------------------------------------------------------
//* DESCRIPT: 
//*                                                                    
//*--------------------------------------------------------------------
//* IN      : 
//*--------------------------------------------------------------------
//* OUT     : 
//*--------------------------------------------------------------------
//* AUTHOR  : MORB								    04/01/2001 10:42:17
//*********************************************************************
int BMSendEvent(BMEVENT *event)
{
	BMEVENTQUEUE *evq;
	evq=(BMEVENTQUEUE *)ALLOC2(sizeof(BMEVENTQUEUE),BMClientServerMemory);
	if(!evq)
		return FALSE;

	memcpy(&evq->event,event,sizeof(BMEVENT));

	/* Dispatch the event to the right list */
	switch(evq->event.action & BM_EVENT_DESTMASK)
	{
		case BM_CLIENT_EVENT:
			// A client can't send an event directly to another client
			if(evq->event.sender>0)
			{
				FREE2(evq,BMClientServerMemory);
				return FALSE;
			}

			KMLAddTail(&BMClEventList,evq->node);
			break;

		case BM_SERVER_EVENT:
			evq->event.recipient=EVTID_SERVER;
			KMLAddTail(&BMSvEventList,evq->node);
			break;

		case BM_MOD_EVENT:
			evq->event.recipient=EVTID_MOD;
			KMLAddTail(&BMMdEventList,evq->node);
			break;

		default:
			FREE2(evq,BMClientServerMemory);
			return FALSE;
	}

	return TRUE;
}
Beispiel #3
0
tnf_reference_t
tnf_opaque32_array_1(tnf_ops_t *ops, tnf_uint32_t *opaques,
	tnf_record_p reference, tnf_tag_data_t *tag_data)
{
	tnf_record_p 	tag_index;
	size_t		record_size;
	tnf_uint32_t	*tmp;
	tnf_uint32_t	*ref_p;
	tnf_array_header_t 	*bufhdr;

	tag_index = tag_data->tag_index ? tag_data->tag_index :
		tag_data->tag_desc(ops, tag_data);

	if (!opaques)
		return (TNF_NULL);

	record_size = sizeof (*bufhdr);
	tmp = opaques;
	while (*tmp++)
		record_size += sizeof (*ref_p);

	ALLOC2(ops, record_size, bufhdr, ops->mode);

	ASSIGN(bufhdr, tag, 		tag_index);
	/* LINTED assignment of 64-bit integer to 32-bit integer */
	ASSIGN(bufhdr, self_size, 	record_size);

	tmp = opaques;
	/* LINTED pointer cast may result in improper alignment */
	ref_p = (tnf_uint32_t *)((char *)bufhdr + sizeof (*bufhdr));
	while (*tmp) {
		*ref_p = tnf_uint32(ops, *tmp, (tnf_reference_t *)ref_p);
		tmp++;
		ref_p++;
	}

	return (tnf_ref32(ops, (tnf_record_p) bufhdr, reference));
}
Beispiel #4
0
KMLFILE *KMLPackOpen(char *packname, char *filename, long flag)
{
	KMLFILE			*kmlfile=NULL;
	KMLFILE			filetmp;
	FILE			*f;
	unsigned long	i, nbfile;
	char			strtmp	[KML_PACK_SIZEOF_FILENAME];
	char			pack	[KML_PACK_SIZEOF_FILENAME];
	char			file	[KML_PACK_SIZEOF_FILENAME];
	char			name	[KML_PACK_SIZEOF_FILENAME];

	// init
	strtmp[0] = pack[0] = file[0] = NULL;

	strcpy (name, filename);
	//-- convert the path name
	i = 0;

	while (name[i] != '\0')
	{
		if (name[i] == '\\')
			name[i] = '/';
		i++;
	}

	// Manage concatenation
	KMLPackGetPacknameFromTotalName(name, pack, file);

	// test packname
	if(packname)
		strcpy(pack, packname);

	// CHECK SUR LE HD ****
	// a la racine !
	strcpy(strtmp, "./");
	strcat(strtmp, file);
	if( (kmlfile = KMLPackGetKMLFILE(strtmp)) != NULL)
		return kmlfile;
	
	// dans le chemin KMLPackTempPath
	strcpy(strtmp, KMLPackTempPath);
	strcat(strtmp, "/");
	strcat(strtmp, file);

	if( (kmlfile = KMLPackGetKMLFILE(strtmp)) != NULL)
		return kmlfile;


	// CHECK DANS LE PACK ****

	if( !pack[0] )
		return NULL;

	// ouverture du pack dans pack
	if( (f=fopen(pack, "rb")) != NULL )
	{
		// recup nb file dans pack
		fread(&nbfile, sizeof(nbfile), 1, f);

		// scan les files du pack pour trouver le bon
		for(i=0; i<nbfile; i++)
		{
			fread(&filetmp, sizeof(KMLFILE)-sizeof(filetmp.data), 1, f);

			if(strcmp(filetmp.filename, file))
			{
				// si different
				fseek(f, filetmp.sizeofdata, SEEK_CUR);
			}
			else
			{
				// on a trouve le bon file
				// allocation de la structure
				kmlfile	= (KMLFILE *)ALLOC2(sizeof(KMLFILE),BMKMLLightMemory);
				// size du buffer
				kmlfile->sizeofdata	= filetmp.sizeofdata;
				// allocation du buffer
				kmlfile->data		= (void *)ALLOC2(kmlfile->sizeofdata,BMKMLLightMemory);
				// lecture du buffer
				fread(kmlfile->data, kmlfile->sizeofdata, 1, f);
				// MAJ du nom de fichier
				strcpy(kmlfile->filename, filetmp.filename);
				// MAJ du path
				strcpy(kmlfile->path, filetmp.path);
				// reset de la position
				kmlfile->offset = 0;
				// incrementation du conteur
				KMLPackNbFileOpen++;
				// on s'barre
				fclose(f);
				return kmlfile;
			}
		}
		fclose(f);
	}

	// ouverture du pack dans KMLPackTempPackName
	if( (f=fopen(KMLPackTempPackName,"rb")) != NULL )
	{
		// recup nb file dans pack
		fread(&nbfile, sizeof(nbfile), 1, f);

		// scan les files du pack pour trouver le bon
		for(i=0; i<nbfile; i++)
		{
			fread(&filetmp, sizeof(KMLFILE)-sizeof(filetmp.data), 1, f);

			if(strcmp(filetmp.filename, file))
			{
				// si different
				fseek(f, filetmp.sizeofdata, SEEK_CUR);
			}
			else
			{
				// on a trouve le bon file
				// allocation de la structure
				kmlfile	= (KMLFILE *)ALLOC2(sizeof(KMLFILE),BMKMLLightMemory);
				// size du buffer
				kmlfile->sizeofdata	= filetmp.sizeofdata;
				// allocation du buffer
				kmlfile->data		= (void *)ALLOC2(kmlfile->sizeofdata,BMKMLLightMemory);
				// lecture du buffer
				fread(kmlfile->data, kmlfile->sizeofdata, 1, f);
				// MAJ du nom de fichier
				strcpy(kmlfile->filename, filetmp.filename);
				// MAJ du path
				strcpy(kmlfile->path, filetmp.path);
				// reset de la position
				kmlfile->offset = 0;
				// incrementation du conteur
				KMLPackNbFileOpen++;
				// on s'barre
				fclose(f);
				return kmlfile;
			}
		}
		fclose(f);
	}

	return kmlfile;
}
Beispiel #5
0
char KMLPackAddFile(char *packname, char *filename)
{
	FILE			*filein;
	FILE			*filepack;
	KMLFILE			kmlfileadd;
	unsigned long	nbfile;

	char			path[KML_PACK_SIZEOF_FILENAME];
	char			endname[KML_PACK_SIZEOF_FILENAME];
	char			strtmp[KML_PACK_SIZEOF_FILENAME];


	// partage du filename
	long i;

	strcpy(strtmp, filename);
	strcpy(path, filename);
	for(i=strlen(filename); strtmp[i]!='/'; i--);
	strcpy(endname, &strtmp[i+1]);
	path[i]=0;

	// ouverture du fichier
	if( (filein=fopen(filename,"rb")) == NULL )
	{
		KMLError("KMLPackAddFile ( ) :\n filename invalide :\n%d", filename);
	}

	// ouverture du pack
	if( (filepack=fopen(packname,"rb")) == NULL )
	{
		nbfile = 0;
	}
	else
	{
		fread(&nbfile, sizeof(nbfile), 1, filepack);
		fclose(filepack);
	}


	//init
	memset(&kmlfileadd, 0, sizeof(KMLFILE));
	kmlfileadd.offset		= 0;
	strcpy(kmlfileadd.filename, endname);
	strcpy(kmlfileadd.path, path);

	// get file size
	fseek(filein, 0, SEEK_END);
	kmlfileadd.sizeofdata	= (unsigned long)ftell(filein);

	// allocation
	kmlfileadd.data			= (void *)ALLOC2(kmlfileadd.sizeofdata,BMKMLLightMemory);

	//lecture et stockage
	fseek(filein, 0, SEEK_SET);
	fread(kmlfileadd.data, kmlfileadd.sizeofdata, 1, filein);

	// ouverture du pack a la fin
	if( (filepack=fopen(packname,"ab")) == NULL )
	{
		KMLError("KMLPackAddFile ( ) :\n packname invalide :\n%d", packname);
	}

	// si premiere insertion
	if(nbfile == 0)
	{
		fwrite(&nbfile, sizeof(nbfile), 1, filepack);
	}

	// insertion dans le pack -> je suis a la fin du pack
	fwrite(&kmlfileadd, sizeof(KMLFILE)-sizeof(kmlfileadd.data), 1, filepack);
	fwrite(kmlfileadd.data, kmlfileadd.sizeofdata, 1, filepack);
	fclose(filepack);	

	// insertion nouveau nb file
	if( (filepack=fopen(packname,"r+b")) == NULL )
	{
		KMLError("KMLPackAddFile ( ) :\n packname invalide :\n%d", packname);
	}
	fseek(filepack, 0, SEEK_SET);
	nbfile++;
	fwrite(&nbfile, sizeof(nbfile), 1, filepack);

	//fermeture des fichier
	fclose(filein);
	fclose(filepack);

	// free
	FREE2(kmlfileadd.data,BMKMLLightMemory);

	return KML_OK;
}