Esempio n. 1
0
void gui_paste_from_clipboard(struct gui_window *g, int x, int y)
{
	/* This and the other clipboard code is heavily based on the RKRM examples */
	struct ContextNode *cn;
	ULONG rlen=0,error;
	struct CSet cset;
	LONG codeset = 0;
	char *clip;
	STRPTR readbuf = AllocVec(1024,MEMF_PRIVATE | MEMF_CLEAR);

	cset.CodeSet = 0;

	if(OpenIFF(iffh,IFFF_READ)) return;
	if(StopChunk(iffh,ID_FTXT,ID_CHRS)) return;
	if(StopChunk(iffh,ID_FTXT,ID_CSET)) return;

	while(1)
	{
		error = ParseIFF(iffh,IFFPARSE_SCAN);
		if(error == IFFERR_EOC) continue;
		else if(error) break;

		cn = CurrentChunk(iffh);

		if((cn)&&(cn->cn_Type == ID_FTXT)&&(cn->cn_ID == ID_CSET))
		{
			rlen = ReadChunkBytes(iffh,&cset,32);
			if(cset.CodeSet == 1) codeset = 106;
				else codeset = cset.CodeSet;
		}

		if((cn)&&(cn->cn_Type == ID_FTXT)&&(cn->cn_ID == ID_CHRS))
		{
			while((rlen = ReadChunkBytes(iffh,readbuf,1024)) > 0)
			{
				if(codeset == 0)
				{
					utf8_from_local_encoding(readbuf,rlen,&clip);
				}
				else
				{
					utf8_from_enc(readbuf,
						(const char *)ObtainCharsetInfo(DFCS_NUMBER,
										codeset, DFCS_MIMENAME),
						rlen, &clip);
				}

				browser_window_paste_text(g->shared->bw,clip,rlen,true);
			}
			if(rlen < 0) error = rlen;
		}
	}
	CloseIFF(iffh);
}
Esempio n. 2
0
/*************
 * DESCRIPTION:   Read word from iff-file
 * INPUT:         h        iffhandle
 *                buf      pointer to buffer
 *                cnt      number of words
 * OUTPUT:        FALSE if failed, else TRUE
 *************/
static BOOL ReadWord(IFFHandle *h, WORD *buf, int cnt)
{
#ifdef __SWAP__
	BOOL res;
	int  i;

	res = (ReadChunkBytes(h, buf, sizeof(WORD) * cnt) == sizeof(WORD) * cnt);
	for(i = 0; i < cnt; i++)
		buf[i] = SwapW(buf[i]);
	return res;
#else
	return (ReadChunkBytes(h, buf, sizeof(WORD) * cnt) == sizeof(WORD) * cnt);
#endif
}
Esempio n. 3
0
/*************
 * DESCRIPTION:   Read word from file
 * INPUT:       buf   pointer to buffer
 *              cnt   number of words
 * OUTPUT:      FALSE if failed, else TRUE
 *************/
static BOOL ReadWord(HANDLER_DATA *data, WORD *buf, int cnt)
{
#ifndef __SWAP__
	BOOL res;
	int  i;

	res = (ReadChunkBytes(data, buf, sizeof(WORD) * cnt) == sizeof(WORD) * cnt);
	for(i = 0; i < cnt; i++)
		buf[i] = SwapW(buf[i]);
	return res;
#else
	return (ReadChunkBytes(data, buf, sizeof(WORD) * cnt) == (long)(sizeof(WORD) * cnt));
#endif
}
Esempio n. 4
0
BOOL LoadPrefsFH(BPTR fh)
{
    static struct SerialPrefs loadprefs;
    struct IFFHandle 	    	*iff;    
    BOOL    	    	    	retval = FALSE;
    
    
    if ((iff = AllocIFF()))
    {
    	iff->iff_Stream = (IPTR)fh;
	    
	InitIFFasDOS(iff);
	
	if (!OpenIFF(iff, IFFF_READ))
	{
	    D(bug("LoadPrefs: OpenIFF okay.\n"));
	    
	    if (!StopChunk(iff, ID_PREF, ID_SERL))
	    {
		D(bug("LoadPrefs: StopChunk okay.\n"));
		
		if (!ParseIFF(iff, IFFPARSE_SCAN))
		{
		    struct ContextNode *cn;
		    
		    D(bug("LoadPrefs: ParseIFF okay.\n"));
		    
		    cn = CurrentChunk(iff);

		    if (cn->cn_Size == sizeof(struct SerialPrefs))
		    {
			D(bug("LoadPrefs: ID_SERL chunk size okay.\n"));
			
			if (ReadChunkBytes(iff, &loadprefs, sizeof(struct SerialPrefs)) == sizeof(struct SerialPrefs))
			{
			    D(bug("LoadPrefs: Reading chunk successful.\n"));

			    serialprefs = loadprefs;
			    
			    D(bug("LoadPrefs: Everything okay :-)\n"));
			    
			    retval = TRUE;
			}
		    }
		    
		} /* if (!ParseIFF(iff, IFFPARSE_SCAN)) */
		
	    } /* if (!StopChunk(iff, ID_PREF, ID_SERL)) */
	    
	    CloseIFF(iff);
			    
	} /* if (!OpenIFF(iff, IFFF_READ)) */
	
    
	FreeIFF(iff);
	
    } /* if ((iff = AllocIFF())) */
    
    return retval;
}
Esempio n. 5
0
ULONG NUMBER_READ_Gadget(piClass *cl,piObject *o,struct piIO *msg)
{
	if(CurrentChunk(msg->IFFh)->cn_Type==ID_GXGA && CurrentChunk(msg->IFFh)->cn_ID==ID_GADA)
	{
		struct TagItem *ti,*oti,tag,*sti;
		struct Node_Gadget *ng;
		int a;

		piGetAttr(o,GAOBJ_Tags,(ULONG *)&ti);
		piGetAttr(o,GAOBJ_OwnTags,(ULONG *)&oti);
		piGetAttr(o,OBJ_Node,(ULONG *)&ng);

		for(a=0;a<ng->ng_Type-1;a++)
		{
			ReadChunkBytes(msg->IFFh,(APTR)&tag,sizeof(struct TagItem));
			switch(tag.ti_Tag)
			{
				case GTNM_Format: break;
				default:
					if(sti=FindTagItem(tag.ti_Tag,ti)) sti->ti_Data=tag.ti_Data;
					break;
			}
		}
		return 0;
	}
	else
		return piDoSuperMethodA(cl,o,(Msg)msg);
}
Esempio n. 6
0
/*************
 * DESCRIPTION:   Read floats from file
 * INPUT:       buf    pointer to buffer
 *              cnt    number of fracts
 * OUTPUT:      FALSE if failed, else TRUE
 *************/
static BOOL ReadFloat(HANDLER_DATA *data, float *buf, int cnt)
{
#ifndef __SWAP__
	BOOL res;
	int  i;
	ULONG *b;

	b = (ULONG*)buf;
	res = (ReadChunkBytes(data, b, sizeof(float) * cnt) == sizeof(float) * cnt);
	for (i = 0; i < cnt; i++)
		b[i] = Swap(b[i]);
	buf = (float*)b;
	return res;
#else
	return (ReadChunkBytes(data, buf, sizeof(float) * cnt) == (long)(sizeof(float) * cnt));
#endif
}
Esempio n. 7
0
ULONG READ_Frame(piClass *cl,piObject *o,struct piIO *msg)
{
	LONG error=0;
	struct Node_Frame *nf;

	piGetAttr(o,OBJ_Node,(ULONG *)&nf);
	ReadChunkBytes(msg->IFFh,(APTR)&nf->nf_X,SIZE(Node_Frame,nf_X));
	return (ULONG)error;
}
Esempio n. 8
0
/*************
 * DESCRIPTION: reads a zero terminated string
 * INPUT:       buf    pointer to textbuffer
 * OUTPUT:      -
 *************/
static void ReadASCIIZ(HANDLER_DATA *data, char *buf)
{
	int i = 0;

	// read until zero byte
	do
	{
		ReadChunkBytes(data, &buf[i], 1);
	}
	while (buf[i++]);
}
Esempio n. 9
0
ULONG STRING_READ_Gadget(piClass *cl,piObject *o,struct piIO *msg)
{
	if(CurrentChunk(msg->IFFh)->cn_Type==ID_GXGA && CurrentChunk(msg->IFFh)->cn_ID==ID_GADA)
	{
		struct TagItem *ti,tag,*sti;
		struct Node_Gadget *ng;
		int a;
		UWORD lenstr;

		piGetAttr(o,GAOBJ_Tags,(ULONG *)&ti);
		piGetAttr(o,OBJ_Node,(ULONG *)&ng);

		for(a=0;a<ng->ng_Type-1;a++)
		{
			ReadChunkBytes(msg->IFFh,(APTR)&tag,sizeof(struct TagItem));
			switch(tag.ti_Tag)
			{
				case GT_Underscore:
					ti[0].ti_Tag=GT_Underscore;
					ti[0].ti_Data='_';
					break;
				case GTST_String: break;
				default:
					if(sti=FindTagItem(tag.ti_Tag,ti)) sti->ti_Data=tag.ti_Data;
					break;
			}
		}
		for(;a<7;a++) ReadChunkBytes(msg->IFFh,(APTR)&tag,sizeof(struct TagItem));
		ReadChunkBytes(msg->IFFh,(APTR)&lenstr,sizeof(UWORD));
		if(lenstr)
		{
			if(FindTagItem(GTST_String,ng->ng_Tags)->ti_Data) MyFreeVec((APTR)FindTagItem(GTST_String,ng->ng_Tags)->ti_Data);
			FindTagItem(GTST_String,ng->ng_Tags)->ti_Data=NULL;
			if(FindTagItem(GTST_String,ng->ng_Tags)->ti_Data=(ULONG)MyAllocVec(lenstr,MEMF_PUBLIC))
				ReadChunkBytes(msg->IFFh,(APTR)FindTagItem(GTST_String,ng->ng_Tags)->ti_Data,lenstr);
		}
		return 0;
	}
	else
		return piDoSuperMethodA(cl,o,(Msg)msg);
}
Esempio n. 10
0
/*************
 * DESCRIPTION:   Read floats from iff-file
 * INPUT:         h        iffhandle
 *                buf      pointer to buffer
 *                cnt      number of floats
 * OUTPUT:        FALSE if failed, else TRUE
 *************/
static BOOL ReadFloat(IFFHandle *h, float *buf, int cnt)
{
	if (!ReadChunkBytes(h, buf, sizeof(float) * cnt) == sizeof(float) * cnt)
		return FALSE;

#ifdef __SWAP__
	for(int i = 0; i < cnt; i++)
		buf[i] = float(LONG(Swap(buf[i])));
#endif

	return TRUE;
}
Esempio n. 11
0
/*************
 * DESCRIPTION: reads id and position of next chunk
 * INPUT:       chunk     pointer to chunk structure
 * OUTPUT:      -
 *************/
static void BeginChunk(HANDLER_DATA *data, CHUNK *chunk)
{
	ULONG next;

	// get chunk id
	ReadWord(data, (WORD*)&chunk->id, 1);
	// and position of next chunk
	ReadChunkBytes(data, &next, 4);
#ifndef __SWAP__
	next = Swap(next);
#endif
	chunk->end = ftell(data->hFile) + next - 6;
}
Esempio n. 12
0
/*** Reads the next CHRS chunk from clipboard ***/
BOOL CBReadCHRS( void *jbuf, LINE *st, ULONG pos, LONG *nbl )
{
	struct ContextNode * cn;
	BOOL   ret = FALSE;

	/* If clipboard not already allocated, makes it now */
	if( clip == NULL && !CBOpen(STD_CLIP_UNIT) ) return FALSE;

	if( !OpenIFF(clip, IFFF_READ) )
	{
		if( !StopChunk(clip, ID_FTXT, ID_CHRS) )
		{
			if( !ParseIFF(clip, IFFPARSE_SCAN) )
			{
				cn = CurrentChunk(clip);
				if( cn->cn_Type == ID_FTXT && cn->cn_ID == ID_CHRS && cn->cn_Size > 0 )
				{
					STRPTR buf;
					ULONG  size = cn->cn_Size;

					if( (buf = (STRPTR) AllocVec(size, MEMF_PUBLIC)) )
					{
						UBYTE eol;
						ReadChunkBytes(clip, buf, size);

						/* What's kind of paste method shall we used? */
						{	register STRPTR s; register ULONG n;
							for(s=buf,n=size; --n && *s!='\n' && *s!='\r'; s++);
							eol = *s;
						}
						/* Add string to the buffer */
						reg_group_by(jbuf);
						if(eol == '\n') add_string(jbuf,st,pos,buf,size,nbl) ;
						else            add_block (jbuf,st,pos,buf,size,nbl) ;
						reg_group_by(jbuf);
						FreeVec(buf);
						ret = TRUE;
					}
					else ThrowError(Wnd, ErrMsg(ERR_NOMEM));
				}
				else ThrowError(Wnd, ErrMsg(ERR_NOTXTINCLIP));
			}
			else ThrowError(Wnd, ErrMsg(ERR_NOTXTINCLIP));
		}
		else ThrowError(Wnd, ErrMsg(ERR_NOMEM));
		CloseIFF(clip);
	}
	/* ThrowError(Wnd, ErrMsg(ERR_READCLIP)); */
	return ret;
}
Esempio n. 13
0
ULONG READ_Gadget(piClass *cl,piObject *o,struct piIO *msg)
{
	LONG error=0,a;
	struct Node_Gadget *ng;
	struct Node_Window *nw;
	struct GadToolsData *gtd;
	UWORD OrgNumTags,OrgNumOwnTags;

	piGetAttr(o,OBJ_Node,(ULONG *)&ng);
	piGetAttr(ng->ng_Window,OBJ_Node,(ULONG *)&nw);
	piGetAttr(o,GAOBJ_NodeData,(ULONG *)&gtd);

	OrgNumTags=ng->ng_NumTags;
	OrgNumOwnTags=ng->ng_NumOwnTags;
	ReadChunkBytes(msg->IFFh,(APTR)&ng->ng_X,SIZE(Node_Gadget,ng_X));
	for(a=0;a<ng->ng_NumTags;a++) ReadTagItem(msg->IFFh,&ng->ng_Tags[a]);
	for(a=0;a<ng->ng_NumOwnTags;a++) ReadTagItem(msg->IFFh,&ng->ng_OwnTags[a]);
	if(ng->ng_Type==GTYPE_GADTOOLS) ReadChunkBytes(msg->IFFh,(APTR)gtd,sizeof(struct GadToolsData));
	ng->ng_NumTags=OrgNumTags;
	ng->ng_NumOwnTags=OrgNumOwnTags;
	ng->ng_Tags[ng->ng_NumTags].ti_Tag=TAG_DONE;
	ng->ng_OwnTags[ng->ng_NumOwnTags].ti_Tag=TAG_DONE;
	return (ULONG)error;
}
Esempio n. 14
0
int GetByte (struct IFFHandle * iff)
{
    if (!Fill)
    {
        Fill = ReadChunkBytes (iff, Buffer, sizeof (Buffer));

        if (Fill < 0)
            return Fill;

        ptr = Buffer;
    }

    Fill --;

    return *ptr ++;
}
Esempio n. 15
0
char *Sys_GetClipboardData(void)
{
#ifdef __AROS__
	struct IFFHandle   *IFFHandle;
	struct ContextNode *cn;
	char               *data = NULL;

	if ((IFFHandle = AllocIFF()))
	{
		if ((IFFHandle->iff_Stream = (IPTR) OpenClipboard(0)))
		{
			InitIFFasClip(IFFHandle);
			if (!OpenIFF(IFFHandle, IFFF_READ))
			{
				if (!StopChunk(IFFHandle, ID_FTXT, ID_CHRS))
				{
					if (!ParseIFF(IFFHandle, IFFPARSE_SCAN))
					{
						cn = CurrentChunk(IFFHandle);
						if (cn && (cn->cn_Type == ID_FTXT) && (cn->cn_ID == ID_CHRS) && (cn->cn_Size > 0))
						{
							data = (char *) Z_Malloc(cn->cn_Size + 1);
							if (ReadChunkBytes(IFFHandle, data, cn->cn_Size))
							{
								data[cn->cn_Size] = '\0';
							}
							else
							{
								data[0] = '\0';
							}
						}
					}
				}
				CloseIFF(IFFHandle);
			}
			CloseClipboard((struct ClipboardHandle *) IFFHandle->iff_Stream);
		}
		FreeIFF(IFFHandle);
	}

	return data;
#else
	return NULL;
#endif
}
Esempio n. 16
0
/*************
 * DESCRIPTION: read a percent value
 * INPUT:       -
 * OUTPUT:      float (0..1)
 *************/
static float ParsePercentage(HANDLER_DATA *data)
{
	CHUNK chunk;
	float percent = 0.f;

	BeginChunk(data, &chunk);

	switch (chunk.id)
	{
		case ID_PERCENT100:
				ReadFloat(data, &percent, 1);
				percent*= 0.01f;
				break;
		case ID_PERCENT1:
				ReadChunkBytes(data, &percent, 1);
				break;
	}

	EndChunk(data, &chunk);

	return percent;
}
Esempio n. 17
0
/*************
 * DESCRIPTION: read a color
 * INPUT:       color   pointer to color
 * OUTPUT:      -
 *************/
static void ParseColor(HANDLER_DATA *data, COLOR *color)
{
	CHUNK chunk;
	UBYTE c[3];

	BeginChunk(data, &chunk);

	switch (chunk.id)
	{
		case ID_COLOR1:
				ReadFloat(data, &color->r, 1);
				ReadFloat(data, &color->g, 1);
				ReadFloat(data, &color->b, 1);
				break;

		case ID_COLOR255:
				ReadChunkBytes(data, &c, 3);
				color->r = c[0]/255.0f;
				color->g = c[1]/255.0f;
				color->b = c[2]/255.0f;
				break;
	}
	EndChunk(data, &chunk);
}
Esempio n. 18
0
ULONG PALETTE_READ_Gadget(piClass *cl,piObject *o,struct piIO *msg)
{
	if(CurrentChunk(msg->IFFh)->cn_Type==ID_GXGA && CurrentChunk(msg->IFFh)->cn_ID==ID_GADA)
	{
		struct TagItem *ti,*oti,tag,*sti;
		struct Node_Gadget *ng;
		int a;

		piGetAttr(o,GAOBJ_Tags,(ULONG *)&ti);
		piGetAttr(o,GAOBJ_OwnTags,(ULONG *)&oti);
		piGetAttr(o,OBJ_Node,(ULONG *)&ng);

		for(a=0;a<ng->ng_Type-1;a++)
		{
			ReadChunkBytes(msg->IFFh,(APTR)&tag,sizeof(struct TagItem));
			switch(tag.ti_Tag)
			{
				case GT_Underscore:
					ti[0].ti_Tag=GT_Underscore;
					ti[0].ti_Data='_';
					break;
				case GTPA_NumColors:
					ti[1].ti_Tag=GTPA_NumColors;
					ti[1].ti_Data=tag.ti_Data;
					ti[2].ti_Tag=TAG_IGNORE;
					break;
				default:
					if(sti=FindTagItem(tag.ti_Tag,ti)) sti->ti_Data=tag.ti_Data;
					break;
			}
		}
		return 0;
	}
	else
		return piDoSuperMethodA(cl,o,(Msg)msg);
}
Esempio n. 19
0
LONG CollectionFunc
(
    struct Hook 	* hook,
    struct IFFHandle	* iff,
    APTR		  p
)
{
    struct LocalContextItem *lci;

    struct ContextNode	    *cn;
    struct CIPtr	    *ciptr;
    struct CollectionItem    *collitem;

    struct CF_ResourceInfo resinfo = {0}; /* = {0} is important */



    LONG   type,
	  id,
	  size;

    LONG  bytesread,
	  err;

    APTR buf;

    /* The Chunk that caused us to be invoked is always the top chunk */
    cn = TopChunk(iff);

    type   = cn->cn_Type;
    id	  = cn->cn_ID;

    /* IMPORTANT !! For collectionchunks we MUST check if a collection is allready present,
    if so there is no clever to add a new one */

    lci = FindLocalItem
    (
	iff,
	type,
	id,
	IFFLCI_COLLECTION
    );

    if (!lci)
    {

	/* Allocate new LCI for containing the property */

	lci = AllocLocalItem
	(
	    type,
	    id,
	    IFFLCI_COLLECTION,
	    sizeof (struct CIPtr)
	);
	if (!lci) return (IFFERR_NOMEM);

	resinfo.LCI = lci;

	/* Store the new LCI into top of stack */

	err = StoreLocalItem(iff,lci,IFFSLI_PROP);

	if (err)
	{
	    CF_FreeResources(&resinfo, IFFParseBase);
	    return (err);
	}
	resinfo.LCIStored = TRUE;

	SetLocalItemPurge(lci,&IFFParseBase->collectionpurgehook);

    }

    /* Allocate a new CollectionItem */

    collitem = (struct CollectionItem*)AllocMem
    (
	sizeof (struct CollectionItem),
	MEMF_ANY|MEMF_CLEAR
    );

    if (!collitem)
    {
	CF_FreeResources(&resinfo, IFFParseBase);
	return (IFFERR_NOMEM);
    }

    resinfo.CollItem = collitem;



    /* Allocate buffer to read chunk into */
    if ((size = cn->cn_Size))
    {
	buf = AllocMem
	(
	    size,
	    MEMF_ANY
	);
    
	if (!buf)
	{
	    CF_FreeResources(&resinfo, IFFParseBase);
	    return (IFFERR_NOMEM);
	}
    }
    else buf = NULL;

    resinfo.Buffer = buf;
    resinfo.BufferSize = size;

    if (buf)
    {
	/* Read chunk into the buffer */

	bytesread = ReadChunkBytes
	(
	    iff,
	    buf,
	    size
	);

	/* Sucess ? */
	if (bytesread != size)
	{
	    CF_FreeResources(&resinfo, IFFParseBase);

	    /* IFFERR_.. ? */
	    if (bytesread >= 0)
		err = IFFERR_MANGLED;
	}
	
    }

    /* Get pointer to first ContextItem from LCIs userdata */
    ciptr = (struct CIPtr*)LocalItemData(lci);

    /* Update pointers in linked list of collectionitems */
    collitem->ci_Next = ciptr->FirstCI;
    ciptr->FirstCI = collitem;

    collitem->ci_Data = buf;
    collitem->ci_Size = size;


    return 0;
}
Esempio n. 20
0
static BOOL ami_print_readunit(CONST_STRPTR filename, char name[],
	uint32 namesize, int unitnum)
{
	/* This is a modified version of a function from the OS4 SDK.
	 * The README says "You can use it in your application",
	 * no licence is specified. (c) 1999 Amiga Inc */

	BPTR fp;
	BOOL ok;
	struct IFFHandle *iff;
	struct ContextNode *cn;
	struct PrefHeader phead;
	struct PrinterDeviceUnitPrefs pdev;

	SNPrintf(name,namesize,"Unit %ld",unitnum);
	fp = Open(filename, MODE_OLDFILE);
	if (fp)
	{
		iff = AllocIFF();
		if (iff)
		{
			iff->iff_Stream = fp;
			InitIFFasDOS(iff);

			if (!OpenIFF(iff, IFFF_READ))
			{
				if (!ParseIFF(iff, IFFPARSE_STEP))
				{
					cn = CurrentChunk(iff);
					if (cn->cn_ID == ID_FORM && cn->cn_Type == ID_PREF)
					{
						if (!StopChunks(iff, IFFPrefChunks, IFFPrefChunkCnt))
						{
							ok = TRUE;
							while (ok)
							{
								if (ParseIFF(iff, IFFPARSE_SCAN))
									break;
								cn = CurrentChunk(iff);
								if (cn->cn_Type == ID_PREF)
								{
									switch (cn->cn_ID)
									{
										case ID_PRHD:
											if (ReadChunkBytes(iff, &phead, sizeof(struct PrefHeader)) != sizeof(struct PrefHeader))
											{
												ok = FALSE;
												break;
											}
											if (phead.ph_Version != 0)
											{
												ok = FALSE;
												break;
											}
											break;
										case ID_PDEV:
											if (ReadChunkBytes(iff, &pdev, sizeof(pdev)) == sizeof(pdev))
											{
												if (pdev.pd_UnitName[0])
													strcpy(name,pdev.pd_UnitName);
											}
											break;
										default:
											break;
									}
								}
							}
						}
					}
				}
				CloseIFF(iff);
			}
			FreeIFF(iff);
		}
		Close(fp);
	}
	else return FALSE;

	return TRUE;
}
Esempio n. 21
0
/*************
 * DESCRIPTION:   parse a texture from a RSCN file
 * INPUT:         iff      iff handle
 *                surf     surface to add texture to
 * OUTPUT:        FALSE if failed else TRUE
 *************/
TEXTURE *ParseRayStormTexture(struct IFFHandle *iff, SURFACE *surf)
{
	RAYSTORM_TEXTURE *texture;
	struct ContextNode *cn;
	long error = 0;
	char buffer[256];

	texture = new RAYSTORM_TEXTURE;
	if(!texture)
		return NULL;

	while(!error)
	{
		error = ParseIFF(iff, IFFPARSE_RAWSTEP);
		if(error < 0 && error != IFFERR_EOC)
		{
			delete texture;
			return NULL;
		}

		// Get a pointer to the context node describing the current context
		cn = CurrentChunk(iff);
		if(!cn)
			continue;

		if(cn->cn_ID == ID_FORM)
			break;

		if(error == IFFERR_EOC)
		{
			error = 0;
			continue;
		}
		switch (cn->cn_ID)
		{
			case ID_NAME:
				if(!ReadString(iff,buffer,256))
				{
					delete texture;
					return NULL;
				}
				if(!texture->SetName(buffer))
				{
					delete texture;
					return NULL;
				}
				break;
			case ID_PARM:
				texture->datasize = cn->cn_Size;
				texture->data = new UBYTE[texture->datasize];
				if(!texture->data)
				{
					delete texture;
					return NULL;
				}
				if(!ReadChunkBytes(iff, texture->data, texture->datasize))
				{
					delete texture;
					return NULL;
				}
				break;
		}
	}

	surf->AddTexture(texture);

	return (TEXTURE*)texture;
}
Esempio n. 22
0
/*** Try to load a preference file ***/
UBYTE load_prefs(PREFS *prefs, STRPTR filename)
{
	APTR  file;
	UBYTE err = RETURN_OK;

	/* Locate preference file */
	if( (file = open_prefs(filename, MODE_USE)) )
	{
		/* Search for PREF/JANO chunk in this file */
		if( !StopChunk(file, ID_PREF, ID_JANO) )
		{
			if( !ParseIFF(file, IFFPARSE_SCAN) )
			{
				struct ContextNode * cn = CurrentChunk(file);
				STRPTR buffer   = NULL;
				UWORD  ByteRead = 0;

				if( cn->cn_Type == ID_PREF && cn->cn_ID == ID_JANO           &&
				   (buffer = (STRPTR) AllocVec(cn->cn_Size, MEMF_PUBLIC))    &&
				    ReadChunkBytes(file, buffer, cn->cn_Size) == cn->cn_Size )
				{
					/* He have read the file, converts it into PREFS struct */
					memset(prefs, 0, sizeof(*prefs));
					prefs->wordssep = WordsSep;
					prefs->attrtxt.ta_Name = FontName;
					prefs->attrscr.ta_Name = FontName+30;
					while(ByteRead < cn->cn_Size)
					{
						register STRPTR src;
						src = buffer + ByteRead;
						if(src[0] < MAX_NUMFIELD) {
							register STRPTR dest = (STRPTR)prefs+offsets[*src];
							if(sizefields[ *src ] == 0) dest = *(STRPTR *)dest;
							CopyMem(src+2, dest, src[1]);
						}
						ByteRead += src[1]+2;
					}
				} else err = RETURN_FAIL;
				if(buffer != NULL) FreeVec( buffer );
			} else err = RETURN_FAIL;
		} else err = RETURN_FAIL;
		close_prefs(file);
	} else err = RETURN_FAIL;

	if(err == RETURN_OK)
	{
		info_screen(prefs, IntuitionBase->ActiveScreen);

		/* If user wants to use a custom font for its interface, try lo **
		** load it, otherwise use default screen font of parent screen: */
		if(!prefs->use_scrfont ||
		   !(prefs->scrfont = (void *) OpenDiskFont( &prefs->attrscr )) )
			prefs->scrfont = prefs->parent->RastPort.Font;
		/* Ditto with text font */
		if(!prefs->use_txtfont ||
		   !(prefs->txtfont = (void *) OpenDiskFont( &prefs->attrtxt )) )
			prefs->txtfont = GfxBase->DefaultFont;
		/* Makes valid pointers */
		text_to_attr(prefs->scrfont, &prefs->attrscr);
		text_to_attr(prefs->txtfont, &prefs->attrtxt);
		/* Special characters that separate words */
		unpack_separators(prefs->wordssep);
	}
	else set_default_prefs(prefs, IntuitionBase->ActiveScreen);
	/* All done */
	return err;
}
Esempio n. 23
0
static void
readDatabaseFile(Entries entries, struct IFFHandle *iff)
{
   struct ContextNode *cn;
   struct _Entry entry;
   struct StoredProperty *sp;
   struct _Automatic automatic;
   char *data;
   LONG *p;
   int error, n, i;

   PropChunk(iff, ID_FTXT, ID_AUTO);
   StopChunk(iff, ID_FTXT, ID_CHRS);

   error = ParseIFF(iff, IFFPARSE_SCAN);

/* Read AUTO entries first */
   sp = FindProp(iff, ID_FTXT, ID_AUTO);
   n = AUTO_SIZE;
   if (sp -> sp_Size && sp -> sp_Size % n)
      myMsg1("auto sizes don't match. Old version? Doing my best...");

   p = (LONG *) sp -> sp_Data;
   for (i = 0; i < sp -> sp_Size; i += n) {
      automatic.first.ds_Days = *p++;
      automatic.first.ds_Minute = *p++;
      automatic.first.ds_Tick = *p++;
      automatic.last.ds_Days = *p++;
      automatic.last.ds_Minute = *p++;
      automatic.last.ds_Tick = *p++;
      automatic.repeatDays = *p++;
      automatic.repeatWeeks = *p++;
      automatic.repeatMonths = *p++;
      automatic.repeatYears = *p++;
      memcpy(automatic.amount, p, AMOUNTL); p += (AMOUNTL/ sizeof(p));
      memcpy(automatic.transaction,p, TRANSACTIONL);p += (TRANSACTIONL/sizeof(p));
      memcpy(automatic.imputation, p,IMPUTATIONL); p += (IMPUTATIONL / sizeof(p));
      DB_AddEntry((DataBase) entries -> automatic, & automatic);
   }

/* And then the database itself */
   cn = CurrentChunk(iff);
   n = ENTRY_SIZE;
   if (cn -> cn_Size && cn -> cn_Size % n)
      myMsg1("entry sizes don't match. Old version? Doing my best...");

   for (i=0; i < cn -> cn_Size; i += n) {
      struct DateStamp *ds = & entry.date;

      ReadChunkBytes(iff, & ds -> ds_Days, sizeof(LONG));
      ReadChunkBytes(iff, & ds -> ds_Minute, sizeof(LONG));
      ReadChunkBytes(iff, & ds -> ds_Tick, sizeof(LONG));

      ReadChunkBytes(iff, & entry.transaction, TRANSACTIONL);
      ReadChunkBytes(iff, & entry.amount, AMOUNTL);
      ReadChunkBytes(iff, & entry.checkNumber, CHECKNUMBERL);
      ReadChunkBytes(iff, & entry.imputation, IMPUTATIONL);
      ReadChunkBytes(iff, & entry.reason, REASONL);
      ReadChunkBytes(iff, & entry.validated, 4);
      addEntryDatabase(entries, & entry, 0, 0);  /* not a fake entry */
   }
}
Esempio n. 24
0
/*----------------------*
 * Paste from Clipboard *
 *----------------------*/
BOOL PasteClip (LONG x, struct line_node *actline, struct InstData *data)
{
  struct line_node *line = NULL;
  struct line_node *startline = NULL;
  struct line_node *previous = NULL;
  UWORD   *styles = NULL;
  UWORD   *colors = NULL;
  STRPTR  textline;
  BOOL newline = TRUE;
  BOOL res = FALSE;

  ENTER();

  if(InitClipboard(data, IFFF_READ))
  {
    if(StopChunk(data->iff, ID_FTXT, ID_CHRS) == 0 &&
       StopChunk(data->iff, ID_FTXT, ID_FLOW) == 0 &&
       StopChunk(data->iff, ID_FTXT, ID_HIGH) == 0 &&
       StopChunk(data->iff, ID_FTXT, ID_SBAR) == 0 &&
       StopChunk(data->iff, ID_FTXT, ID_COLS) == 0 &&
       StopChunk(data->iff, ID_FTXT, ID_STYL) == 0 &&
       StopChunk(data->iff, ID_FTXT, ID_CSET) == 0)
    {
      LONG error, codeset = 0;
      UWORD flow = MUIV_TextEditor_Flow_Left;
      UWORD color = FALSE;
      UWORD separator = 0;
      BOOL ownclip = FALSE;
      LONG updatefrom;

      while(TRUE)
      {
        struct ContextNode *cn;

        error = ParseIFF(data->iff, IFFPARSE_SCAN);
        SHOWVALUE(DBF_CLIPBOARD, error);
        if(error == IFFERR_EOC)
          continue;
        else if(error)
          break;

        if((cn = CurrentChunk(data->iff)) != NULL)
        {
          switch (cn->cn_ID)
          {
            case ID_CSET:
              D(DBF_CLIPBOARD, "reading FLOW");
              SHOWVALUE(DBF_CLIPBOARD, cn->cn_Size);
              if(cn->cn_Size >= 4)
              {
                /* Only the first four bytes are interesting */
                if(ReadChunkBytes(data->iff, &codeset, 4) != 4)
                {
                  codeset = 0;
                }
                SHOWVALUE(DBF_CLIPBOARD, codeset);
              }
              break;

            case ID_FLOW:
              D(DBF_CLIPBOARD, "reading FLOW");
              SHOWVALUE(DBF_CLIPBOARD, cn->cn_Size);
              if(cn->cn_Size == 2)
              {
                if(ReadChunkBytes(data->iff, &flow, 2) == 2)
                  if(flow > MUIV_TextEditor_Flow_Right)
                    flow = MUIV_TextEditor_Flow_Left;
                SHOWVALUE(DBF_CLIPBOARD, flow);
              }
              break;

            case ID_HIGH:
              D(DBF_CLIPBOARD, "reading HIGH");
              SHOWVALUE(DBF_CLIPBOARD, cn->cn_Size);
              if (cn->cn_Size == 2)
              {
                error = ReadChunkBytes(data->iff, &color, 2);
                SHOWVALUE(DBF_CLIPBOARD, color);
                SHOWVALUE(DBF_CLIPBOARD, error);
              }
              break;

            case ID_SBAR:
              D(DBF_CLIPBOARD, "reading SBAR");
              SHOWVALUE(DBF_CLIPBOARD, cn->cn_Size);
              if (cn->cn_Size == 2)
              {
                error = ReadChunkBytes(data->iff, &separator, 2);
                SHOWVALUE(DBF_CLIPBOARD, separator);
                SHOWVALUE(DBF_CLIPBOARD, error);
              }
              break;

            case ID_COLS:
              D(DBF_CLIPBOARD, "reading COLS");
              SHOWVALUE(DBF_CLIPBOARD, cn->cn_Size);
              if(colors)
              {
                MyFreePooled(data->mypool, colors);
                colors = NULL;
              }
              // allocate one word more than the chunk tell us, because we terminate the array with an additional value
              if(cn->cn_Size > 0 && (colors = (UWORD *)MyAllocPooled(data->mypool, cn->cn_Size + sizeof(UWORD))) != NULL)
              {
                error = ReadChunkBytes(data->iff, colors, cn->cn_Size);
                SHOWVALUE(DBF_CLIPBOARD, error);
                colors[cn->cn_Size / 2] = 0xffff;
              }
              break;

            case ID_STYL:
              D(DBF_CLIPBOARD, "reading STYL");
              SHOWVALUE(DBF_CLIPBOARD, cn->cn_Size);
              ownclip = TRUE;
              if(styles)
              {
                MyFreePooled(data->mypool, styles);
                styles = NULL;
              }
              // allocate one word more than the chunk tell us, because we terminate the array with an additional value
              if(cn->cn_Size > 0 && (styles = (UWORD *)MyAllocPooled(data->mypool, cn->cn_Size + sizeof(UWORD))) != NULL)
              {
                error = ReadChunkBytes(data->iff, styles, cn->cn_Size);
                SHOWVALUE(DBF_CLIPBOARD, error);
                styles[cn->cn_Size / 2] = EOS;
              }
              break;

            case ID_CHRS:
            {
              D(DBF_CLIPBOARD, "reading CHRS");
              SHOWVALUE(DBF_CLIPBOARD, cn->cn_Size);

              data->HasChanged = TRUE;

              if(cn->cn_Size > 0 && !ownclip)
              {
                char *contents;
                ULONG length = cn->cn_Size;

                if((contents = (char *)MyAllocPooled(data->mypool, length + 1)) != NULL)
                {
                  error = ReadChunkBytes(data->iff, contents, length);
                  SHOWVALUE(DBF_CLIPBOARD, error);

                  if(contents[length - 1] != '\n')
                  {
                    newline = FALSE;
                  }
                  else
                  {
                    length--;
                  }
                  contents[length] = '\0';

                  #if defined(__MORPHOS__)
                  if (codeset == CODESET_UTF8)
                  {
                    if (IS_MORPHOS2)
                      contents = utf8_to_ansi(data, contents);
                  }
                  #endif

                  if((line = ImportText(contents, data, &ImPlainHook, data->ImportWrap)))
                  {
                    if(!startline)
                      startline = line;
                    if(previous)
                      previous->next  = line;

                    line->previous    = previous;
                    line->visual    = VisualHeight(line, data);
                    data->totallines += line->visual;
                    while(line->next)
                    {
                      line = line->next;
                      line->visual    = VisualHeight(line, data);
                      data->totallines += line->visual;
                    }
                    previous = line;
                  }
                  MyFreePooled(data->mypool, contents);
                }
              }
              else
              {
                ULONG length = cn->cn_Size;

                if(length > 0 && (textline = (char *)MyAllocPooled(data->mypool, length + 2)) != NULL)
                {
                  error = ReadChunkBytes(data->iff, textline, length);
                  SHOWVALUE(DBF_CLIPBOARD, error);

                  if (textline[length - 1] != '\n')
                  {
                    newline = FALSE;
                    textline[length] = '\n';
                    length++;
                  }
                  textline[length] = '\0';

                  if((line = AllocLine(data)))
                  {
                    line->next     = NULL;
                    line->previous   = previous;
                    line->line.Contents   = textline;
                    line->line.Length   = length;
                    line->visual   = VisualHeight(line, data);
                    line->line.Color    = color;
                    line->line.Flow     = flow;
                    line->line.Separator = separator;
                    line->line.Styles   = styles;
                    line->line.Colors   = colors;
                    data->totallines += line->visual;

                    if(!startline)
                      startline = line;
                    if(previous)
                      previous->next  = line;

                    previous = line;
                  }
                  else
                  {
                    if(styles)
                      MyFreePooled(data->mypool, (void *)styles);
                    if(colors)
                      MyFreePooled(data->mypool, (void *)colors);
                  }
                }
                else
                {
                  if(styles)
                    MyFreePooled(data->mypool, styles);
                  if(colors)
                    MyFreePooled(data->mypool, (void *)colors);
                }
                styles    = NULL;
                colors    = NULL;
                flow      = MUIV_TextEditor_Flow_Left;
                color     = FALSE;
                separator = 0;
                ownclip   = FALSE;
              }
            }
            break;
          }
        }
      }

      if(line)
      {
        BOOL oneline = FALSE;

        SplitLine(x, actline, FALSE, NULL, data);
        line->next = actline->next;
        actline->next->previous = line;
        actline->next = startline;
        startline->previous = actline;
        data->CPos_X = line->line.Length-1;
        if(actline->next == line)
        {
          data->CPos_X += actline->line.Length-1;
          oneline = TRUE;
        }
        if(!newline)
          MergeLines(line, data);
        MergeLines(actline, data);
        if(oneline)
          line = actline;
        if(newline)
        {
          line = line->next;
          data->CPos_X = 0;
        }
        data->actualline = line;
      }
      else
      {
        switch(error)
        {
          case IFFERR_MANGLED:
          case IFFERR_SYNTAX:
          case IFFERR_NOTIFF:
            D(DBF_CLIPBOARD, "no FTXT clip!");
            DoMethod(data->object, MUIM_TextEditor_HandleError, Error_ClipboardIsNotFTXT);
            break;
          default:
            D(DBF_CLIPBOARD, "clipboard is empty!");
            DoMethod(data->object, MUIM_TextEditor_HandleError, Error_ClipboardIsEmpty);
            break;
        }
      }
      data->update = TRUE;

      ScrollIntoDisplay(data);
      updatefrom = LineToVisual(actline, data)-1;
      if(updatefrom < 0)
        updatefrom = 0;
      DumpText(data->visual_y+updatefrom, updatefrom, data->maxlines, TRUE, data);

      if(data->update)
        res = TRUE;
      else
        data->update = TRUE;
    }

    EndClipSession(data);
  }

  RETURN(res);
  return res;
}
Esempio n. 25
0
IPTR SMEditor__MUIM_PrefsEditor_ImportFH
(
    Class *CLASS, Object *self, 
    struct MUIP_PrefsEditor_ImportFH *message
)
{
    SETUP_INST_DATA;
    struct ContextNode     *context;
    struct IFFHandle       *handle;
    struct ScreenModePrefs  smp;
    BOOL                    success = TRUE;
    LONG                    error;
    
    if (!(handle = AllocIFF()))
        return FALSE;
    
    handle->iff_Stream = (IPTR) message->fh;
    InitIFFasDOS(handle);

    if ((error = OpenIFF(handle, IFFF_READ)) == 0)
    {
	
        BYTE i;
        
        // FIXME: We want some sanity checking here!
        for (i = 0; i < 1; i++)
        {
            if ((error = StopChunk(handle, ID_PREF, ID_SCRM)) == 0)
            {
                if ((error = ParseIFF(handle, IFFPARSE_SCAN)) == 0)
                {
                    context = CurrentChunk(handle);
                    
                    error = ReadChunkBytes
                    (
                        handle, &smp, sizeof(struct ScreenModePrefs)
                    );
                    
                    if (error < 0)
                    {
                        printf("Error: ReadChunkBytes() returned %ld!\n", error);
                    }                    
                }
                else
                {
                    printf("ParseIFF() failed, returncode %ld!\n", error);
                    success = FALSE;
                    break;
                }
            }
            else
            {
                printf("StopChunk() failed, returncode %ld!\n", error);
                success = FALSE;
            }
        }

        CloseIFF(handle);
    }
    else
    {
        //ShowError(_(MSG_CANT_OPEN_STREAM));
    }

    FreeIFF(handle);
    
    
    if (success)
    {
        SMPByteSwap(&smp);
	
	nnset(data->selector, MUIA_ScreenModeSelector_Active, smp.smp_DisplayID);
	SetAttrs
	(
	    data->properties,
	    MUIA_NoNotify,                        TRUE,
	    MUIA_ScreenModeProperties_DisplayID,  smp.smp_DisplayID,
	    MUIA_ScreenModeProperties_Width,      smp.smp_Width,
	    MUIA_ScreenModeProperties_Height,     smp.smp_Height,
	    MUIA_ScreenModeProperties_Depth,      smp.smp_Depth,
	    MUIA_ScreenModeProperties_Autoscroll, smp.smp_Control & AUTOSCROLL,
	    TAG_DONE
        );
    }
    
    return success;
}
Esempio n. 26
0
/*************
 * DESCRIPTION:   read the surfaces
 * INPUT:         data     handler data
 *                cn       iff context node
 * OUTPUT:        error string
 *************/
static char *ReadSurfaces(HANDLER_DATA *data, struct ContextNode *cn)
{
	char *buffer, *name;
	int current;
	BOOL done;
	int len;

	buffer = ALLOCMEM(char, cn->cn_Size);
	if(!buffer)
		return errors[ERR_MEM];

	if(ReadChunkBytes(data->iff, buffer, cn->cn_Size) != cn->cn_Size)
	{
		FREEMEM(buffer);
		return errors[ERR_LWOBFILE];
	}

	// count names
	name = buffer;
	data->surfcount = 0;
	done = FALSE;
	while(!done)
	{
		data->surfcount++;
		len = strlen(name)+1;
		len += len & 1;
		name = name + len;
		if(name - buffer >= cn->cn_Size)
			done = TRUE;
	}

	data->surfaces = ALLOCMEM(SURF_DATA, data->surfcount);
	if(!data->surfaces)
	{
		FREEMEM(buffer);
		return errors[ERR_MEM];
	}

	name = buffer;
	done = FALSE;
	current = 0;
	while(!done)
	{
		if(!data->replacesurf)
		{
			data->surfaces[current].surface = data->link->SurfaceAdd(data->rc);
			if(!data->surfaces[current].surface)
			{
				FREEMEM(buffer);
				return errors[ERR_LWOBFILE];
			}
		}
		else
			data->surfaces[current].surface = data->replacesurf;
		len = strlen(name)+1;
		data->surfaces[current].name = new char[len];
		if(!data->surfaces[current].name)
		{
			FREEMEM(buffer);
			return errors[ERR_LWOBFILE];
		}
		strcpy(data->surfaces[current].name, name);
		if(!data->replacesurf)
			data->link->SurfaceName(data->rc, data->surfaces[current].surface, name);

		current++;
		len += len & 1;
		name = name + len;
		if(name - buffer >= cn->cn_Size)
			done = TRUE;
	}
	return NULL;
}
Esempio n. 27
0
/*************
 * DESCRIPTION:   read the surface information
 * INPUT:         data     handler data
 *                cn       iff context node
 * OUTPUT:        error string
 *************/
static char *ReadSurface(HANDLER_DATA *data, struct ContextNode *cn)
{
	UBYTE *buffer;
	ULONG cur = 0, size;
	ULONG id;
	float value;
	SURFACE *surf;
	float r,g,b;
	float spec=0.f, refl=0.f, tran=0.f;
	UWORD flags = 0, brush_flags = 0;
	UWORD gloss, x_mode, y_mode;
	char *surf_name, *wrap_type;
	char *err;
	ULONG type = TEXTURE_NONE;
	BRUSH *brush = NULL;
	VECTOR brush_pos = {0.f,0.f,0.f},brush_size = {1.f,1.f,1.f};

	buffer = ALLOCMEM(UBYTE, cn->cn_Size);
	if(!buffer)
		return errors[ERR_MEM];

	if(ReadChunkBytes(data->iff, buffer, cn->cn_Size) != cn->cn_Size)
	{
		FREEMEM(buffer);
		return errors[ERR_LWOBFILE];
	}

	surf_name = (char*)buffer;
	surf = data->link->SurfaceGetByName(data->rc, (char*)buffer);
	if(!surf)
	{
		// If we can't find the surface it isn't used as a main surface
		// from a polygon. So we can ignore this surface.
		FREEMEM(buffer);
		return NULL;
	}

	cur += strlen((char*)buffer)+1;
	if(cur & 1)
		cur++;

	while(cur < (cn->cn_Size-4))
	{
		id = READULONG(cur);
		cur += 4;
		size = READUWORD(cur);
		cur += 2;
		switch(id)
		{
			case ID_COLR:
				READ_COLOR(buffer, r,g,b);
				data->link->SurfaceDiffuse(data->rc, surf, r,g,b);
				break;
			case ID_SPEC:
				spec = ((float)READUWORD(cur)) / 256.f;
				break;
			case ID_REFL:
				refl = ((float)READUWORD(cur)) / 256.f;
				break;
			case ID_TRAN:
				tran = ((float)READUWORD(cur)) / 256.f;
				break;
			case ID_FLAG:
				flags = READUWORD(cur);
				break;
			case ID_RIND:
				value = *(float*)(&buffer[cur]);
				data->link->SurfaceIndOfRefr(data->rc, surf, value);
				break;
			case ID_GLOS:
				gloss = READUWORD(cur);
				data->link->SurfaceRefPhong(data->rc, surf, (float)gloss);
				break;
			case ID_CTEX:
			case ID_DTEX:
				if((type != TEXTURE_NONE) && brush)
				{
					err = SetTexture(data, surf_name, brush, type, wrap_type, brush_flags, x_mode, y_mode, &brush_pos, &brush_size);
					if(err)
					{
						FREEMEM(buffer);
						return err;
					}
				}
				type = TEXTURE_DIFFUSE;
				wrap_type = (char*)&buffer[cur];
				break;
			case ID_STEX:
				if((type != TEXTURE_NONE) && brush)
				{
					err = SetTexture(data, surf_name, brush, type, wrap_type, brush_flags, x_mode, y_mode, &brush_pos, &brush_size);
					if(err)
					{
						FREEMEM(buffer);
						return err;
					}
				}
				type = TEXTURE_SPECULAR;
				wrap_type = (char*)&buffer[cur];
				break;
			case ID_RTEX:
				if((type != TEXTURE_NONE) && brush)
				{
					err = SetTexture(data, surf_name, brush, type, wrap_type, brush_flags, x_mode, y_mode, &brush_pos, &brush_size);
					if(err)
					{
						FREEMEM(buffer);
						return err;
					}
				}
				type = TEXTURE_REFLECTION;
				wrap_type = (char*)&buffer[cur];
				break;
			case ID_TTEX:
				if((type != TEXTURE_NONE) && brush)
				{
					err = SetTexture(data, surf_name, brush, type, wrap_type, brush_flags, x_mode, y_mode, &brush_pos, &brush_size);
					if(err)
					{
						FREEMEM(buffer);
						return err;
					}
				}
				type = TEXTURE_TRANSPARENCY;
				wrap_type = (char*)&buffer[cur];
				break;
			case ID_BTEX:
				if((type != TEXTURE_NONE) && brush)
				{
					err = SetTexture(data, surf_name, brush, type, wrap_type, brush_flags, x_mode, y_mode, &brush_pos, &brush_size);
					if(err)
					{
						FREEMEM(buffer);
						return err;
					}
				}
				type = TEXTURE_BUMP;
				wrap_type = (char*)&buffer[cur];
				break;
			case ID_TIMG:
				brush = data->link->BrushAdd(data->rc, (char*)&buffer[cur], surf);
				if(!brush)
				{
					FREEMEM(buffer);
					return errors[ERR_MEM];
				}
				break;
			case ID_TFLG:
				brush_flags = READUWORD(cur);
				break;
			case ID_TWRP:
				x_mode = READUWORD(cur);
				y_mode = READUWORD(cur+2);
				break;
			case ID_TSIZ:
				brush_size.x = *(float*)(&buffer[cur]);
				brush_size.y = *(float*)(&buffer[cur+4]);
				brush_size.z = *(float*)(&buffer[cur+8]);
				break;
			case ID_TCTR:
				brush_pos.x = *(float*)(&buffer[cur]);
				brush_pos.y = *(float*)(&buffer[cur+4]);
				brush_pos.z = *(float*)(&buffer[cur+8]);
				break;
		}
		cur += size;
	}

	if((type != TEXTURE_NONE) && brush)
	{
		err = SetTexture(data, surf_name, brush, type, wrap_type, brush_flags, x_mode, y_mode, &brush_pos, &brush_size);
		if(err)
		{
			FREEMEM(buffer);
			return err;
		}
	}


	if(flags & FLAGS_COLOR_HIGHLIGHTS)
		data->link->SurfaceSpecular(data->rc, surf, r*spec, g*spec, b*spec);
	else
		data->link->SurfaceSpecular(data->rc, surf, spec, spec, spec);
	data->link->SurfaceReflect(data->rc, surf, refl, refl, refl);
	if(flags & FLAGS_COLOR_FILTER)
		data->link->SurfaceTranspar(data->rc, surf, r*tran, g*tran, b*tran);
	else
		data->link->SurfaceTranspar(data->rc, surf, tran, tran, tran);

	FREEMEM(buffer);
	return NULL;
}