Пример #1
0
/*************
 * FUNCTION:      OpenIFF
 * DESCRIPTION:   open iff file and parse to begin of file
 * INPUT:         iff      iff handle
 *                filename name of file
 *                filesize   size of file is returned in this variable
 * OUTPUT:        error string
 *************/
static char *OpenIFF(struct IFFHandle **iff, char *filename, ULONG *filesize)
{
	struct ContextNode *cn;

	// Allocate IFF_File structure.
	*iff = AllocIFF();
	if(!*iff)
		return errors[ERR_MEM];

#ifdef __AMIGA__
	// Set up IFF_File for AmigaDOS I/O.
	(*iff)->iff_Stream = Open(filename, MODE_OLDFILE);
#else
	(*iff)->iff_Stream = Open_(filename, MODE_OLDFILE);
#endif
	if(!(*iff)->iff_Stream)
		return errors[ERR_OPENFILE];

	InitIFFasDOS(*iff);

	// Start the IFF transaction.
	if(OpenIFF(*iff, IFFF_READ))
		return errors[ERR_LWOBFILE];

	if(ParseIFF(*iff, IFFPARSE_RAWSTEP))
		return errors[ERR_LWOBFILE];

	cn = CurrentChunk(*iff);
	if((cn->cn_ID != ID_FORM) || (cn->cn_Type != ID_LWOB))
		return errors[ERR_LWOBFILE];

	*filesize = cn->cn_Size;

	return NULL;
}
Пример #2
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;
}
Пример #3
0
void gui_get_clipboard(char **buffer, size_t *length)
{
	struct ContextNode *cn;
	struct CollectionItem *ci = NULL;
	struct StoredProperty *sp = NULL;
	ULONG rlen=0,error;
	struct CSet *cset;
	LONG codeset = 0;

	if(OpenIFF(iffh,IFFF_READ)) return;
	
	if(CollectionChunk(iffh,ID_FTXT,ID_CHRS)) return;
	if(PropChunk(iffh,ID_FTXT,ID_CSET)) return;
	if(CollectionChunk(iffh,ID_FTXT,ID_UTF8)) return;
	if(StopOnExit(iffh, ID_FTXT, ID_FORM)) return;
	
	error = ParseIFF(iffh,IFFPARSE_SCAN);

	if(ci = FindCollection(iffh, ID_FTXT, ID_UTF8)) {
		*buffer = ami_clipboard_cat_collection(ci, 106, length);
	} else if(ci = FindCollection(iffh, ID_FTXT, ID_CHRS)) {
		if(sp = FindProp(iffh, ID_FTXT, ID_CSET)) {
			cset = (struct CSet *)sp->sp_Data;
			codeset = cset->CodeSet;
		}
		*buffer = ami_clipboard_cat_collection(ci, codeset, length);
	}

	CloseIFF(iffh);
}
Пример #4
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 *ParseHyperTexture(struct IFFHandle *iff, SURFACE *surf)
{
	HYPER_TEXTURE *texture;
	struct ContextNode *cn;
	long error = 0;
	char buffer[256];

	texture = new HYPER_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;
		}
	}

	surf->AddTexture(texture);

	return (TEXTURE*)texture;
}
Пример #5
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);
}
Пример #6
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;
}
Пример #7
0
/*************
 * DESCRIPTION:   Parse surfaces
 * INPUT:         -
 * OUTPUT:        error string
 *************/
char *ParseSurfaces(struct IFFHandle *iff)
{
	SURFACE *surf;
	struct ContextNode *cn;
	long error = 0;

	while(!error)
	{
		error = ParseIFF(iff, IFFPARSE_RAWSTEP);
		if(error < 0 && error != IFFERR_EOC)
			return errors[ERR_RSCNFILE];

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

		if((cn->cn_ID == ID_FORM) && (cn->cn_Type == ID_SRFS))
			break;

		if(error == IFFERR_EOC)
		{
			error = 0;
			continue;
		}
		switch (cn->cn_ID)
		{
			case ID_FORM:
				switch(cn->cn_Type)
				{
					case ID_SURF:
						surf = sciCreateSurface(SURF_DEFAULTNAME);
						if(!surf)
							return errors[ERR_MEM];

						if(!surf->Read(iff, NULL))
						{
							delete surf;
							return errors[ERR_RSCNFILE];
						}
						sciAddMaterial(surf);
						break;
				}
				break;
		}
	}

	return NULL;
}
Пример #8
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
}
Пример #9
0
/**************************************************************************
 MUIM_Configdata_Load
 Get the content of the file into the object.
**************************************************************************/
IPTR Configdata__MUIM_Load(struct IClass *cl, Object * obj,
                           struct MUIP_Configdata_Load *msg)
{
    struct IFFHandle *iff;
    IPTR res = TRUE;

    if ((iff = AllocIFF()))
    {
        D(bug("loading prefs from %s\n", msg->filename));
        if ((iff->iff_Stream = (IPTR)Open(msg->filename,MODE_OLDFILE)))
        {
            InitIFFasDOS(iff);

            if (!OpenIFF(iff, IFFF_READ))
            {
                StopChunk( iff, MAKE_ID('P','R','E','F'), MAKE_ID('M','U','I','C'));

                while (!ParseIFF(iff, IFFPARSE_SCAN))
                {
                    struct ContextNode *cn;
                    if (!(cn = CurrentChunk(iff))) continue;
                    if (cn->cn_ID == MAKE_ID('M','U','I','C'))
                        DoMethod(obj, MUIM_Dataspace_ReadIFF, (IPTR)iff);
                }

                CloseIFF(iff);
            }
            else
            {
                res = FALSE;
            }
            Close((BPTR)iff->iff_Stream);
        }
        else
        {
            res = FALSE;
        }
        FreeIFF(iff);
    }
    else
    {
        res = FALSE;
    }
    return res;
}
Пример #10
0
/*************
 * DESCRIPTION:   read a camera from scene file
 * INPUT:         iff      iff handler
 *                where    where to insert after
 *                dir      insert direction
 * OUTPUT:        created object
 *************/
OBJECT *ParseCamera(struct IFFHandle *iff, OBJECT *where, int dir)
{
	CAMERA *camera;
	struct ContextNode *cn;
	long error = 0;
	ULONG flags;

	camera = new CAMERA;
	if(!camera)
		return NULL;

	if(!camera->ReadAxis(iff))
	{
		delete camera;
		return NULL;
	}

	while(!error)
	{
		error = ParseIFF(iff, IFFPARSE_RAWSTEP);
		if(error < 0 && error != IFFERR_EOC)
		{
			delete camera;
			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) && (cn->cn_Type == ID_CAMR))
			break;

		if(error == IFFERR_EOC)
		{
			error = 0;
			continue;
		}

		switch (cn->cn_ID)
		{
			case ID_NAME:
				if(!camera->ReadName(iff))
				{
					delete camera;
					return NULL;
				}
				break;
			case ID_TRCK:
				if(!camera->ReadTrack(iff))
				{
					delete camera;
					return NULL;
				}
				break;
			case ID_FLGS:
				if(rscn_version < 200)
				{
					if(!ReadULONG(iff, &flags, 1))
					{
						delete camera;
						return NULL;
					}
					if(flags & 1)
						camera->flags |= OBJECT_CAMERA_VFOV;
					else
						camera->flags &= ~OBJECT_CAMERA_VFOV;
					if(flags & 4)
						camera->flags |= OBJECT_CAMERA_FOCUSTRACK;
					else
						camera->flags &= ~OBJECT_CAMERA_FOCUSTRACK;
				}
				else
				{
					if(!camera->ReadFlags(iff))
					{
						delete camera;
						return NULL;
					}
				}
				break;
			case ID_FDST:
				if(!ReadFloat(iff,&camera->focaldist,1))
				{
					delete camera;
					return NULL;
				}
				break;
			case ID_APER:
				if(!ReadFloat(iff,&camera->aperture,1))
					return NULL;
				break;
			case ID_FDOV:
				if(!ReadFloat(iff,&camera->hfov,1))
				{
					delete camera;
					return NULL;
				}
				if(!ReadFloat(iff,&camera->vfov,1))
				{
					delete camera;
					return NULL;
				}
				break;
		}
	}

	SetVector(&camera->bboxmin, -camera->size.z*.5, -camera->size.z*.5, -camera->size.z);
	SetVector(&camera->bboxmax, camera->size.z*.5, camera->size.z*1.3, camera->size.z*1.5);

	camera->Insert(where,dir);

	return (OBJECT*)camera;
}
Пример #11
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 */
   }
}
Пример #12
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;
}
Пример #13
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;
}
Пример #14
0
static char *ParseFrame(struct IFFHandle *iff)
{
	struct ContextNode *cn;
	long error = 0;
	ULONG flags;
	char buffer[256];
	int len;
	UBYTE ubnum;

	while(!error)
	{
		error = ParseIFF(iff, IFFPARSE_RAWSTEP);
		if(error < 0 && error != IFFERR_EOC )
			return errors[ERR_IFFPARSE];

		// 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_FLGS:
				if(!ReadULONG(iff,&flags,1))
					return errors[ERR_RSCNFILE];
				global.quick = flags & RSCN_FRAME_QUICK ? TRUE : FALSE;
				global.randjit = flags & RSCN_FRAME_RANDJIT ? TRUE : FALSE;
				break;
			case ID_CAMR:
				len = ReadString(iff,camera,256);
				break;
			case ID_AMBT:
				if(!ReadFloat(iff,(float*)&global.ambient,3))
					return errors[ERR_RSCNFILE];
				break;
			case ID_ANTS:
				if(!ReadInt(iff,&global.antialias,1))
					return errors[ERR_RSCNFILE];
				break;
			case ID_ANTC:
				if(!ReadFloat(iff,(float*)&global.anticont,3))
					return errors[ERR_RSCNFILE];
				break;
			case ID_BCKC:
				if(!ReadFloat(iff,(float*)&global.backcol,3))
					return errors[ERR_RSCNFILE];
				break;
			case ID_BCKP:
				len = ReadString(iff,buffer,256);
				global.SetBackPic(buffer);
				if(rscn_version < 200)
					global.SetEnableBack(TRUE);
				break;
			case ID_REFM:
				len = ReadString(iff,buffer,256);
				global.SetReflMap(buffer);
				if(rscn_version < 200)
					global.SetEnableRefl(TRUE);
				break;
			case ID_SOFT:
				if(!ReadUBYTE(iff,&ubnum,1))
					return errors[ERR_RSCNFILE];
				global.softshad = ubnum;
				break;
			case ID_MBLR:
				if(!ReadUBYTE(iff,&ubnum,1))
					return errors[ERR_RSCNFILE];
				global.distrib = ubnum;
				break;
			case ID_ODPT:
				if(!ReadUBYTE(iff,&ubnum,1))
					return errors[ERR_RSCNFILE];
				global.octreedepth = ubnum;
				break;
		}
	}
	return NULL;
}
Пример #15
0
BOOL
ReadConfig ( struct AHIDevUnit *iounit,
             struct AHIBase *AHIBase )
{
  struct IFFHandle *iff;
  struct StoredProperty *prhd,*ahig;
  struct CollectionItem *ci;

  if(iounit)
  {
    /* Internal defaults for device unit */
    iounit->AudioMode       = AHI_INVALID_ID;   // See at the end of the function!
    iounit->Frequency       = 10000;
    iounit->Channels        = 4;
    iounit->MonitorVolume   = ~0;
    iounit->InputGain       = ~0;
    iounit->OutputVolume    = ~0;
    iounit->Input           = ~0;
    iounit->Output          = ~0;
  }
  else
  {
    /* Internal defaults for low-level mode */
    AHIBase->ahib_AudioMode       = AHI_INVALID_ID;
    AHIBase->ahib_Frequency       = 10000;
    AHIBase->ahib_MonitorVolume   = 0x00000;
    AHIBase->ahib_InputGain       = 0x10000;
    AHIBase->ahib_OutputVolume    = 0x10000;
    AHIBase->ahib_Input           = 0;
    AHIBase->ahib_Output          = 0;
  }

  if((iff=AllocIFF()))
  {
    iff->iff_Stream=Open("ENV:Sys/ahi.prefs", MODE_OLDFILE);
    if(iff->iff_Stream)
    {
      InitIFFasDOS(iff);
      if(!OpenIFF(iff,IFFF_READ))
      {
        if(!(PropChunk(iff,ID_PREF,ID_PRHD)
          || PropChunk(iff,ID_PREF,ID_AHIG)
          || CollectionChunk(iff,ID_PREF,ID_AHIU)
          || StopOnExit(iff,ID_PREF,ID_FORM)))
        {
          if(ParseIFF(iff,IFFPARSE_SCAN) == IFFERR_EOC)
          {
            prhd=FindProp(iff,ID_PREF,ID_PRHD);
            ahig=FindProp(iff,ID_PREF,ID_AHIG);
            
            if(ahig)
            {
              struct AHIGlobalPrefs *globalprefs;
              
              globalprefs = (struct AHIGlobalPrefs *)ahig->sp_Data;

              AHIBase->ahib_DebugLevel = globalprefs->ahigp_DebugLevel;

              AHIBase->ahib_Flags = 0;

              if(globalprefs->ahigp_DisableSurround)
                AHIBase->ahib_Flags |= AHIBF_NOSURROUND;

              if(globalprefs->ahigp_DisableEcho)
                AHIBase->ahib_Flags |= AHIBF_NOECHO;

              if(globalprefs->ahigp_FastEcho)
                AHIBase->ahib_Flags |= AHIBF_FASTECHO;
                
              if( (ULONG) ahig->sp_Size > offsetof( struct AHIGlobalPrefs,
                                                    ahigp_MaxCPU) )
              {
                AHIBase->ahib_MaxCPU = globalprefs->ahigp_MaxCPU;
              }
              else
              {
                AHIBase->ahib_MaxCPU = 0x10000 * 90 / 100;
              }

              if( (ULONG) ahig->sp_Size > offsetof( struct AHIGlobalPrefs, 
                                                    ahigp_ClipMasterVolume) )
              {
                if(globalprefs->ahigp_ClipMasterVolume)
                  AHIBase->ahib_Flags |= AHIBF_CLIPPING;
              }

              if( (ULONG) ahig->sp_Size > offsetof( struct AHIGlobalPrefs, 
                                                    ahigp_AntiClickTime ) )
              {
                AHIBase->ahib_AntiClickTime = globalprefs->ahigp_AntiClickTime;
              }
              else
              {
                AHIBase->ahib_AntiClickTime = 0;
              }

            }
            ci=FindCollection(iff,ID_PREF,ID_AHIU);
            while(ci)
            {
              struct AHIUnitPrefs *unitprefs;

              unitprefs = (struct AHIUnitPrefs *)ci->ci_Data;

              if(iounit)
              {
                if(unitprefs->ahiup_Unit == iounit->UnitNum)
                {
                  iounit->AudioMode       = unitprefs->ahiup_AudioMode;
                  iounit->Frequency       = unitprefs->ahiup_Frequency;
                  iounit->Channels        = unitprefs->ahiup_Channels;
                  iounit->MonitorVolume   = unitprefs->ahiup_MonitorVolume;
                  iounit->InputGain       = unitprefs->ahiup_InputGain;
                  iounit->OutputVolume    = unitprefs->ahiup_OutputVolume;
                  iounit->Input           = unitprefs->ahiup_Input;
                  iounit->Output          = unitprefs->ahiup_Output;
                }
              }
              else
              {
                if(unitprefs->ahiup_Unit == AHI_NO_UNIT)
                {
                  AHIBase->ahib_AudioMode       = unitprefs->ahiup_AudioMode;
                  AHIBase->ahib_Frequency       = unitprefs->ahiup_Frequency;
                  AHIBase->ahib_MonitorVolume   = unitprefs->ahiup_MonitorVolume;
                  AHIBase->ahib_InputGain       = unitprefs->ahiup_InputGain;
                  AHIBase->ahib_OutputVolume    = unitprefs->ahiup_OutputVolume;
                  AHIBase->ahib_Input           = unitprefs->ahiup_Input;
                  AHIBase->ahib_Output          = unitprefs->ahiup_Output;
                }
              }

              ci=ci->ci_Next;
            }
          }
Пример #16
0
char *PROJECT::Load(char *filename, DISPLAY *disp)
{
	long error = 0;
	struct IFFHandle *iff;
	struct ContextNode *cn;
	char *err;
	OBJECT *where = NULL;
	int dir = INSERT_HORIZ;

	// there is currently no active camera read
	camera[0] = 0;

	iff = AllocIFF();
	if (!iff)
		return errors[ERR_MEM];

#ifdef __AMIGA__
	iff->iff_Stream = Open(filename, MODE_OLDFILE);
#else
	iff->iff_Stream = Open_(filename, MODE_OLDFILE);
#endif
	if (!(iff->iff_Stream))
	{
		IFFCleanup(iff);
		return errors[ERR_OPEN];
	}

	InitIFFasDOS(iff);
	error = OpenIFF(iff, IFFF_READ);
	if (error)
	{
		IFFCleanup(iff);
		return errors[ERR_IFFPARSE];
	}

	error = ParseIFF(iff, IFFPARSE_RAWSTEP);
	if (error)
	{
		IFFCleanup(iff);
		return errors[ERR_IFFPARSE];
	}
	cn = CurrentChunk(iff);
	if(!cn)
	{
		IFFCleanup(iff);
		return errors[ERR_IFFPARSE];
	}
	if((cn->cn_ID != ID_FORM) || (cn->cn_Type != ID_RSCN))
	{
		IFFCleanup(iff);
		return errors[ERR_NORSCNFILE];
	}

	while(!error || error == IFFERR_EOC)
	{
		error = ParseIFF(iff, IFFPARSE_RAWSTEP);
		if(error != IFFERR_EOC)
		{
			// Get a pointer to the context node describing the current context
			cn = CurrentChunk(iff);
			if (cn)
			{
				switch (cn->cn_ID)
				{
					case ID_VERS:
						if(!ReadULONG(iff,&rscn_version,1))
						{
							IFFCleanup(iff);
							return errors[ERR_RSCNFILE];
						}
						if(rscn_version > VERSION)
						{
							IFFCleanup(iff);
							return errors[ERR_WRONGVERS];
						}
						break;
					case ID_FORM:
						switch(cn->cn_Type)
						{
							case ID_GNRL:
								err = ParseGeneral(iff,disp);
								if(err)
								{
									IFFCleanup(iff);
									return err;
								}
								break;
							case ID_FRAM:
								err = ParseFrame(iff);
								if(err)
								{
									IFFCleanup(iff);
									return err;
								}
								break;
							case ID_SRFS:
								err = ParseSurfaces(iff);
								if(err)
								{
									IFFCleanup(iff);
									return err;
								}
								break;
							case ID_CAMR:
								where = ParseCamera(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_SPHR:
								where = ParseSphere(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_PLAN:
								where = ParsePlane(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_PLGT:
							case ID_SLGT:
							case ID_DLGT:
								where = ParseLight(iff, where, dir, cn->cn_Type);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_MESH:
								where = ParseMesh(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_EXTN:
								where = ParseExternal(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_BOX:
								where = ParseBox(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_CYLR:
								where = ParseCylinder(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_CONE:
								where = ParseCone(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_CSG:
								where = ParseCSG(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_SOR:
								where = ParseSOR(iff, where, dir);
								if(!where)
								{
									IFFCleanup(iff);
									return errors[ERR_RSCNFILE];
								}
								dir = INSERT_HORIZ;
								break;
							case ID_HIER:
								dir = INSERT_VERT;
								break;
						}
						break;
				}
			}
		}
		else
		{
			cn = CurrentChunk(iff);
			if (cn)
			{
				if((cn->cn_ID == ID_FORM) && (cn->cn_Type == ID_HIER))
				{
					if(dir == INSERT_HORIZ)
					{
						while(where->GetPrev())
							where = (OBJECT*)where->GetPrev();
						if(where->GoUp())
							where = (OBJECT*)where->GoUp();
					}
					else
						dir = INSERT_HORIZ;
				}
			}
		}
	}
	if (error != IFFERR_EOF)
	{
		return errors[ERR_IFFPARSE];
	}

	IFFCleanup(iff);

	// we have to set the active camera
	disp->camera = (CAMERA*)GetObjectByName(camera);
	if(!disp->camera)
		err = errors[ERR_NOCAMERA];
	else
		err = NULL;

	// and translate track names to track objects
	// and the surface names to surface pointers
	TranslateNames();

	return err;
}
Пример #17
0
/*************
 * DESCRIPTION:   read surface from scene file
 * INPUT:         iff      iff handler
 *                obj      object for this surface (needed for pre V2.0 files)
 * OUTPUT:        FALSE if failed else TRUE
 *************/
BOOL SURFACE::Read(struct IFFHandle *iff, OBJECT *obj)
{
	struct ContextNode *cn;
	long error = 0;
	char buffer[256];
	BRUSH_OBJECT *brushobj;
	BRUSH *brush;
	TEXTURE_OBJECT *textureobj;
	TEXTURE *texture;

	while(!error)
	{
		error = ParseIFF(iff, IFFPARSE_RAWSTEP);
		if(error < 0 && error != IFFERR_EOC)
			return FALSE;

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

		if((cn->cn_ID == ID_FORM) && (cn->cn_Type == ID_SURF))
			break;

		if(error == IFFERR_EOC)
		{
			error = 0;
			continue;
		}

		switch (cn->cn_ID)
		{
			case ID_FORM:
				switch(cn->cn_Type)
				{
					case ID_BRSH:
						if((rscn_version < 200) && obj)
						{
							brushobj = ParseBrushObject(iff, obj);
							if(!brushobj)
								return FALSE;
						}
						brush = ParseBrush(iff,this);
						if(!brush)
							return FALSE;

						if((rscn_version < 200) && obj)
							brushobj->brush = brush;
						break;
					case ID_ITXT:
						if((rscn_version < 200) && obj)
						{
							textureobj = ParseTextureObject(iff, obj);
							if(!textureobj)
								return FALSE;
						}
						texture = ParseImagineTexture(iff,this);
						if(!texture)
							return FALSE;

						if((rscn_version < 200) && obj)
							textureobj->texture = texture;
						break;
					case ID_RTXT:
						texture = ParseRayStormTexture(iff,this);
						if(!texture)
							return FALSE;
						break;
					case ID_HTXT:
						texture = ParseHyperTexture(iff,this);
						if(!texture)
							return FALSE;
						break;
				}
				break;
			case ID_NAME:
				if(!ReadString(iff,buffer,256))
					return FALSE;
				SetName(buffer);
				break;
			case ID_FLGS:
				if(!ReadULONG(iff,&flags,1))
					return FALSE;
				break;
			case ID_AMBT:
				if(!ReadFloat(iff,(float*)&ambient,3))
					return FALSE;
				break;
			case ID_DIFU:
				if(!ReadFloat(iff,(float*)&diffuse,3))
					return FALSE;
				break;
			case ID_SPEC:
				if(!ReadFloat(iff,(float*)&specular,3))
					return FALSE;
				break;
			case ID_REFL:
				if(!ReadFloat(iff,(float*)&reflect,3))
					return FALSE;
				break;
			case ID_TRNS:
				if(!ReadFloat(iff,(float*)&transpar,3))
					return FALSE;
				break;
			case ID_DIFT:
				if(!ReadFloat(iff,(float*)&difftrans,3))
					return FALSE;
				break;
			case ID_SPCT:
				if(!ReadFloat(iff,(float*)&spectrans,3))
					return FALSE;
				break;
			case ID_RPHG:
				if(!ReadFloat(iff,&refphong,1))
					return FALSE;
				break;
			case ID_TPHG:
				if(!ReadFloat(iff,&transphong,1))
					return FALSE;
				break;
			case ID_FLEN:
				if(!ReadFloat(iff,&foglength,1))
					return FALSE;
				break;
			case ID_IXOR:
				if(!ReadFloat(iff,&refrindex,1))
					return FALSE;
				break;
			case ID_TNSL:
				if(!ReadFloat(iff,&translucency,1))
					return FALSE;
				break;
		}
	}

	return TRUE;
}
Пример #18
0
BOOL
ReadConfig ( struct AHIDevUnit *iounit,
             struct AHIBase *AHIBase )
{
    struct IFFHandle *iff;
    struct StoredProperty *prhd,*ahig;
    struct CollectionItem *ci;
    ULONG *mode;

    if(iounit)
    {
        /* Internal defaults for device unit */
        iounit->AudioMode       = AHI_INVALID_ID;   // See at the end of the function!
        iounit->Frequency       = 10000;
        iounit->Channels        = 4;
        iounit->MonitorVolume   = ~0;
        iounit->InputGain       = ~0;
        iounit->OutputVolume    = ~0;
        iounit->Input           = ~0;
        iounit->Output          = ~0;
    }
    else
    {
        /* Internal defaults for low-level mode */
        AHIBase->ahib_AudioMode       = AHI_INVALID_ID;
        AHIBase->ahib_Frequency       = 10000;
        AHIBase->ahib_MonitorVolume   = 0x00000;
        AHIBase->ahib_InputGain       = 0x10000;
        AHIBase->ahib_OutputVolume    = 0x10000;
        AHIBase->ahib_Input           = 0;
        AHIBase->ahib_Output          = 0;
    }

    if((iff=AllocIFF()))
    {
        iff->iff_Stream=(ULONG) Open("ENV:Sys/ahi.prefs", MODE_OLDFILE);
        if(iff->iff_Stream)
        {
            InitIFFasDOS(iff);
            if(!OpenIFF(iff,IFFF_READ))
            {
                if(!(PropChunk(iff,ID_PREF,ID_PRHD)
                        || PropChunk(iff,ID_PREF,ID_AHIG)
                        || CollectionChunk(iff,ID_PREF,ID_AHIU)
                        || StopOnExit(iff,ID_PREF,ID_FORM)))
                {
                    if(ParseIFF(iff,IFFPARSE_SCAN) == IFFERR_EOC)
                    {
                        prhd=FindProp(iff,ID_PREF,ID_PRHD);
                        ahig=FindProp(iff,ID_PREF,ID_AHIG);

                        if(ahig)
                        {
                            struct AHIGlobalPrefs *globalprefs;
                            UWORD debug_level;

                            globalprefs = (struct AHIGlobalPrefs *)ahig->sp_Data;

                            debug_level = globalprefs->ahigp_DebugLevel;
                            EndianSwap( sizeof (UWORD), &debug_level );
                            AHIBase->ahib_DebugLevel = debug_level;

                            AHIBase->ahib_Flags = 0;

                            /* Not used in version 5:
                             *
                             * if(globalprefs->ahigp_DisableSurround)
                             *   AHIBase->ahib_Flags |= AHIBF_NOSURROUND;
                             *
                             * if(globalprefs->ahigp_DisableEcho)
                                 *   AHIBase->ahib_Flags |= AHIBF_NOECHO;
                             *
                             * if(globalprefs->ahigp_FastEcho)
                                 *   AHIBase->ahib_Flags |= AHIBF_FASTECHO;
                             *
                             */

                            if( (ULONG) ahig->sp_Size > offsetof( struct AHIGlobalPrefs,
                                                                  ahigp_MaxCPU) )
                            {
                                AHIBase->ahib_MaxCPU = globalprefs->ahigp_MaxCPU;
                                EndianSwap( sizeof (Fixed), &AHIBase->ahib_MaxCPU );
                            }
                            else
                            {
                                AHIBase->ahib_MaxCPU = 0x10000 * 90 / 100;
                            }

                            /* In version 5: Clipping is always used
                             *
                                 * if( (ULONG) ahig->sp_Size > offsetof( struct AHIGlobalPrefs,
                                 *                                       ahigp_ClipMasterVolume) )
                                 * {
                                 *   if(globalprefs->ahigp_ClipMasterVolume)
                                 *     AHIBase->ahib_Flags |= AHIBF_CLIPPING;
                                 * }
                             */

                            if( (ULONG) ahig->sp_Size > offsetof( struct AHIGlobalPrefs,
                                                                  ahigp_AntiClickTime ) )
                            {
                                AHIBase->ahib_AntiClickTime = globalprefs->ahigp_AntiClickTime;
                                EndianSwap( sizeof (Fixed), &AHIBase->ahib_AntiClickTime );
                            }
                            else
                            {
                                AHIBase->ahib_AntiClickTime = 0;
                            }

                            if( (ULONG) ahig->sp_Size > offsetof( struct AHIGlobalPrefs,
                                                                  ahigp_ScaleMode ) )
                            {
                                AHIBase->ahib_ScaleMode = globalprefs->ahigp_ScaleMode;
                                EndianSwap( sizeof (UWORD), &AHIBase->ahib_ScaleMode );
                            }
                            else
                            {
                                AHIBase->ahib_ScaleMode = AHI_SCALE_FIXED_0_DB;
                            }
                        }
Пример #19
0
/*************
 * DESCRIPTION:   read a LWOB-file
 * INPUT:         rc          context
 *                filename    name of LWOB-file
 *                link        link structure
 *                pos         object position
 *                ox, oy, oz  object orientation
 *                actor       pointer to actor
 *                replacesurf pointer to surface to replace object surface
 *                            with
 *                version     version number
 * OUTPUT:        NULL if ok else errorstring
 *************/
extern "C" char* SAVEDS objRead(rsiCONTEXT *rc, char *filename, OBJLINK *link, VECTOR *pos, VECTOR *ox, VECTOR *oy,
	VECTOR *oz, VECTOR *scale, ACTOR *actor, SURFACE *replacesurf, ULONG *version, void (*SetProgress)(rsiCONTEXT*, float))
{
	long error = 0;
	struct ContextNode *cn;
	char *err;
	HANDLER_DATA data;

	data.link = link;
	data.iff = NULL;
	data.points = NULL;
	data.rc = rc;
	data.surfaces = NULL;
	data.pos = *pos;
	data.ox = *ox;
	data.oy = *oy;
	data.oz = *oz;
	data.size = *scale;
	data.replacesurf = replacesurf;
	data.SetProgress = SetProgress;
	data.size_done = 0;

	err = OpenIFF(&data.iff, filename, &data.filesize);
	if(err)
	{
		readLWOB_cleanup(&data);
		return err;
	}

	while (!error || error == IFFERR_EOC)
	{
		error = ParseIFF(data.iff, IFFPARSE_RAWSTEP);
		if (error != IFFERR_EOC)
		{
			// Get a pointer to the context node describing the current context
			cn = CurrentChunk(data.iff);
			if (cn)
			{
				switch (cn->cn_ID)
				{
					case ID_SRFS:
						err = ReadSurfaces(&data, cn);
						if(err)
						{
							readLWOB_cleanup(&data);
							return err;
						}
						break;
					case ID_SURF:
						if(!data.replacesurf)
						{
							err = ReadSurface(&data, cn);
							if(err)
							{
								readLWOB_cleanup(&data);
								return err;
							}
						}
						break;
					case ID_PNTS:
						err = ReadPoints(&data, cn);
						if(err)
						{
							readLWOB_cleanup(&data);
							return err;
						}
						break;
					case ID_POLS:
						err = ReadPolygons(&data, cn, actor);
						if(err)
						{
							readLWOB_cleanup(&data);
							return err;
						}
						break;
				}
				if(SetProgress)
				{
					data.size_done += cn->cn_Size;
					(*SetProgress)(rc, (float)data.size_done/(float)data.filesize);
				}
			}
		}
	}
	readLWOB_cleanup(&data);
	if (error != IFFERR_EOF)
	{
		return errors[ERR_LWOBFILE];
	}
	return NULL;
}
Пример #20
0
/*************
 * DESCRIPTION:   parse a brush object from a RSCN file
 * INPUT:         iff      iff handle
 *                obj      object to add brush to
 * OUTPUT:        created brush object
 *************/
BRUSH_OBJECT *ParseBrushObject(struct IFFHandle *iff, OBJECT *obj)
{
	BRUSH_OBJECT *brush;
	struct ContextNode *cn;
	long error = 0;

	brush = new BRUSH_OBJECT;
	if(!brush)
		return NULL;

	if(!brush->ReadAxis(iff))
	{
		delete brush;
		return NULL;
	}

	if(rscn_version >= 200)
	{
		while(!error)
		{
			error = ParseIFF(iff, IFFPARSE_RAWSTEP);
			if(error < 0 && error != IFFERR_EOC)
			{
				delete brush;
				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) && (cn->cn_Type == ID_BRSH))
				break;

			if(error == IFFERR_EOC)
			{
				error = 0;
				continue;
			}
			switch (cn->cn_ID)
			{
				case ID_TRCK:
					if(!brush->ReadTrack(iff))
					{
						delete brush;
						return NULL;
					}
					break;
				case ID_FLGS:
					if(!brush->ReadFlags(iff))
					{
						delete brush;
						return NULL;
					}
					break;
			}
		}
	}

	obj->AddBrushTop(brush);

	return brush;
}
Пример #21
0
/*************
 * DESCRIPTION:   parse a brush from a RSCN file
 * INPUT:         iff      iff handle
 *                surf     surface to add brush to
 * OUTPUT:        created brush
 *************/
BRUSH *ParseBrush(struct IFFHandle *iff, SURFACE *surf)
{
	BRUSH *brush;
	struct ContextNode *cn;
	long error = 0;
	char buffer[256];

	brush = new BRUSH;
	if(!brush)
		return NULL;

	while(!error)
	{
		error = ParseIFF(iff, IFFPARSE_RAWSTEP);
		if(error < 0 && error != IFFERR_EOC)
		{
			delete brush;
			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 brush;
					return NULL;
				}
				if(!brush->SetName(buffer))
				{
					delete brush;
					return NULL;
				}
				break;
			case ID_WRAP:
				if(!ReadULONG(iff,&brush->wrap,1))
				{
					delete brush;
					return NULL;
				}
				break;
			case ID_TYPE:
				if(!ReadULONG(iff,&brush->type,1))
				{
					delete brush;
					return NULL;
				}
				break;
			case ID_FLGS:
				if(!ReadULONG(iff,&brush->flags,1))
				{
					delete brush;
					return NULL;
				}
				break;
		}
	}

	surf->AddBrush(brush);

	return brush;
}
Пример #22
0
int main(int argc, char *argv[])
{
  struct IFFHandle *iff;
  struct StoredProperty *ahig;
  struct CollectionItem *ci;
  LONG unit = 0;
  int rc = RETURN_OK;

  if(argc != 3) {
    Printf("Usage: %s FILE UNIT\n", argv[0]);
    return RETURN_FAIL;
  }

  StrToLong(argv[2], &unit);

  if(iff = AllocIFF())
  {
    iff->iff_Stream = Open(argv[1], MODE_OLDFILE);
    if(iff->iff_Stream)
    {
      InitIFFasDOS(iff);
      if(!OpenIFF(iff, IFFF_READ))
      {
        if(!(PropChunk(iff,ID_PREF,ID_AHIG)
          || CollectionChunk(iff,ID_PREF,ID_AHIU)
          || StopOnExit(iff,ID_PREF,ID_FORM)))
        {
          if(ParseIFF(iff, IFFPARSE_SCAN) == IFFERR_EOC)
          {

            ahig = FindProp(iff,ID_PREF,ID_AHIG);
            if(ahig)
            {
              struct AHIGlobalPrefs *globalprefs;
              globalprefs = (struct AHIGlobalPrefs *)ahig->sp_Data;

              if(globalprefs->ahigp_DebugLevel != AHI_DEBUG_NONE)
              {
                Printf("Debugging is turned on.\n");
                rc = RETURN_WARN;
              }
            }

            ci = FindCollection(iff,ID_PREF,ID_AHIU);
            while(ci)
            {
              struct AHIUnitPrefs *unitprefs;
              unitprefs = (struct AHIUnitPrefs *)ci->ci_Data;

              if(unitprefs->ahiup_Unit == unit)
              {
                if(unitprefs->ahiup_Channels < 2)
                {
                  Printf("There are less than 2 channels selected for unit %ld.\n", unit);
                  rc = RETURN_WARN;
                }
              }
              ci=ci->ci_Next;
            }

          }
        }
        CloseIFF(iff);
      }
      Close(iff->iff_Stream);
    }
    FreeIFF(iff);
  }

  return rc;
}
Пример #23
0
/*************
 * DESCRIPTION:   parse a sphere from a RSCN file
 * INPUT:         iff      iff handler
 *                where    where to insert after
 *                dir      insert direction
 * OUTPUT:        created object
 *************/
OBJECT *ParseSphere(struct IFFHandle *iff, OBJECT *where, int dir)
{
	SPHERE *sphere;
	struct ContextNode *cn;
	long error = 0;

	sphere = new SPHERE;
	if(!sphere)
		return NULL;

	if(!sphere->ReadAxis(iff))
	{
		delete sphere;
		return NULL;
	}
	sphere->surf = GetSurfaceByName(SURF_DEFAULTNAME);

	while(!error)
	{
		error = ParseIFF(iff, IFFPARSE_RAWSTEP);
		if(error < 0 && error != IFFERR_EOC)
		{
			delete sphere;
			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) && (cn->cn_Type == ID_SPHR))
			break;

		if(error == IFFERR_EOC)
		{
			error = 0;
			continue;
		}
		switch (cn->cn_ID)
		{
			case ID_FORM:
				switch(cn->cn_Type)
				{
					case ID_SURF:
						if(!ReadSurface(iff, &sphere->surf, (OBJECT*)sphere))
						{
							delete sphere;
							return NULL;
						}
						break;
				}
				break;
			case ID_NAME:
				if(!sphere->ReadName(iff))
				{
					delete sphere;
					return NULL;
				}
				break;
			case ID_TRCK:
				if(!sphere->ReadTrack(iff))
				{
					delete sphere;
					return NULL;
				}
				break;
			case ID_FLGS:
				if(!sphere->ReadFlags(iff))
				{
					delete sphere;
					return NULL;
				}
				break;
		}
	}

	SetVector(&sphere->bboxmin, -sphere->size.x, -sphere->size.y, -sphere->size.z);
	sphere->bboxmax = sphere->size;
	sphere->Insert(where, dir);

	return (OBJECT*)sphere;
}
Пример #24
0
/*************
 * DESCRIPTION:   load the current project from disk
 * INPUT:         project     projectname (the project is loaded from a
 *    directory with this name)
 *                disp        current display
 * OUTPUT:        error string if failed, else NULL
 *************/
static char *ParseGeneral(struct IFFHandle *iff, DISPLAY *disp)
{
	struct ContextNode *cn;
	long error = 0;
	ULONG reso[2];
	ULONG flags;
	char buffer[256];
	int len, i;
	OBSERVER obsv;
	UBYTE activeview, currentview=0;
	BOOL viewcamera = FALSE;
	UBYTE display;

	while(!error)
	{
		error = ParseIFF(iff, IFFPARSE_RAWSTEP);
		if(error < 0 && error != IFFERR_EOC )
			return errors[ERR_IFFPARSE];

		// 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_RESO:
				if(!ReadULONG(iff,reso,2))
					return errors[ERR_RSCNFILE];
				global.xres = reso[0];
				global.yres = reso[1];
				break;
			case ID_PICT:
				len = ReadString(iff,buffer,256);
				if(!global.SetRenderdPic(buffer))
					return errors[ERR_MEM];
				break;
			case ID_PTYP:
				len = ReadString(iff,buffer,256);
				if(!global.SetPicType(buffer))
					return errors[ERR_MEM];
				break;
			case ID_DISP:
				if(!ReadUBYTE(iff,&display,1))
					return errors[ERR_RSCNFILE];
				disp->display = display;
				break;
			case ID_VIEW:
				// new in v2.1: current view number; before: current view mode
				if(rscn_version >= 210)
				{
					if(!ReadUBYTE(iff, &activeview, 1))
						return errors[ERR_RSCNFILE];
				}
				break;
			case ID_GRID:
				if(!ReadFloat(iff,&disp->gridsize,1))
					return errors[ERR_RSCNFILE];
				break;
			case ID_FLGS:
				if(!ReadULONG(iff,&flags,1))
					return errors[ERR_RSCNFILE];
				disp->grid = flags & RSCN_GENERAL_GRID ? TRUE : FALSE;
				disp->gridsnap = flags & RSCN_GENERAL_GRIDSNAP ? TRUE : FALSE;
				if(flags & RSCN_GENERAL_VIEWCAMERA)
					viewcamera = TRUE;
				disp->multiview = flags & RSCN_GENERAL_VIEWFOUR ? TRUE : FALSE;
				global.show = flags & RSCN_GENERAL_SHOW ? TRUE : FALSE;
				global.SetEnableArea(flags & RSCN_GENERAL_ENABLEAREA ? TRUE : FALSE);
				global.SetEnableBack(flags & RSCN_GENERAL_ENABLEBACK ? TRUE : FALSE);
				global.SetEnableRefl(flags & RSCN_GENERAL_ENABLEREFL ? TRUE : FALSE);
				break;
			case ID_OBSV:
				if(rscn_version >= 210)
				{
					if(!ReadFloat(iff,(float*)&obsv,12))
						return errors[ERR_RSCNFILE];
				}
				else
				{
					if(!ReadFloat(iff,(float*)&obsv,11))
						return errors[ERR_RSCNFILE];
				}
				disp->views[currentview]->vpos = obsv.vpos;
				disp->views[currentview]->valign = obsv.valign;
				disp->views[currentview]->dist = obsv.dist;
				disp->views[currentview]->viewpoint = obsv.viewpoint;
				disp->views[currentview]->zoom = obsv.zoom;
				if(rscn_version >= 210)
					disp->views[currentview]->viewmode = obsv.viewmode;
				currentview++;
				break;
			case ID_FLEN:
				if(!ReadFloat(iff,&global.flen,1))
					return errors[ERR_RSCNFILE];
				break;
			case ID_FHGT:
				if(!ReadFloat(iff,&global.fheight,1))
					return errors[ERR_RSCNFILE];
				break;
			case ID_FCOL:
				if(!ReadFloat(iff,(float*)&global.fog,3))
					return errors[ERR_RSCNFILE];
				break;
			case ID_FILD:
				if(!ReadFloat(iff,&global.xmin,4))
					return errors[ERR_RSCNFILE];
				break;
			case ID_MOBJ:
				if(!ReadULONG(iff,&global.minobjects,1))
					return errors[ERR_RSCNFILE];
				break;
			case ID_FILT:
				if(!ReadULONG(iff, (ULONG*)&disp->filter_flags, 1))
					return errors[ERR_RSCNFILE];
				break;
			case ID_HSAM:
				if(!ReadULONG(iff,&global.hyper_samples,4))
					return errors[ERR_RSCNFILE];
				break;
			case ID_HMIN:
				if(!ReadFloat(iff,&global.hyper_min_dens,4))
					return errors[ERR_RSCNFILE];
				break;
			case ID_HMAX:
				if(!ReadFloat(iff,&global.hyper_max_dens,4))
					return errors[ERR_RSCNFILE];
				break;
		}
	}
	if(rscn_version >= 210)
	{
		ASSERT((activeview >= 0) && (activeview <= 4));
		disp->view = disp->views[activeview];
	}
	else
	{
		if(disp->multiview)
			disp->views[0]->zoom *= .5f;
		for(i=1; i<4; i++)
		{
			disp->views[i]->vpos = disp->views[0]->vpos;
			disp->views[i]->valign = disp->views[0]->valign;
			disp->views[i]->dist = disp->views[0]->dist;
			disp->views[i]->viewpoint = disp->views[0]->viewpoint;
			disp->views[i]->zoom = disp->views[0]->zoom;
		}
		disp->views[0]->viewmode = VIEW_TOP;
		disp->views[1]->viewmode = viewcamera ? VIEW_CAMERA : VIEW_PERSP;
		disp->views[2]->viewmode = VIEW_FRONT;
		disp->views[3]->viewmode = VIEW_RIGHT;
	}
	return NULL;
}
Пример #25
0
/*************
 * DESCRIPTION:   parse a texture from a RSCN file
 * INPUT:         iff      iff handle
 *                obj      object to add texture to
 * OUTPUT:        FALSE if failed else TRUE
 *************/
TEXTURE_OBJECT *ParseTextureObject(struct IFFHandle *iff, OBJECT *obj)
{
	TEXTURE_OBJECT *texture;
	struct ContextNode *cn;
	long error = 0;

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

	if(!texture->ReadAxis(iff))
	{
		delete texture;
		return NULL;
	}

	if(rscn_version >= 200)
	{
		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) && (cn->cn_Type == ID_ITXT))
				break;

			if(error == IFFERR_EOC)
			{
				error = 0;
				continue;
			}
			switch (cn->cn_ID)
			{
				case ID_TRCK:
					if(!texture->ReadTrack(iff))
					{
						delete texture;
						return NULL;
					}
					break;
				case ID_FLGS:
					if(!texture->ReadFlags(iff))
					{
						delete texture;
						return NULL;
					}
					break;
			}
		}
	}

	obj->AddTextureTop(texture);

	return texture;
}
Пример #26
0
/*************
 * DESCRIPTION:   load a surface definition
 * INPUT:         filename    name of surface file
 * OUTPUT:        error string or NULL if all ok
 *************/
char *SURFACE::Load(char *filename)
{
	long error = 0;
	struct IFFHandle *iff;
	struct ContextNode *cn;

	iff = AllocIFF();
	if (!iff)
		return errors[ERR_MEM];

#ifdef __AMIGA__
	iff->iff_Stream = Open(filename, MODE_OLDFILE);
#else
	iff->iff_Stream = Open_(filename, MODE_OLDFILE);
#endif
	if (!(iff->iff_Stream))
	{
		IFFCleanup(iff);
		return errors[ERR_OPEN];
	}

	InitIFFasDOS(iff);
	error = OpenIFF(iff, IFFF_READ);
	if (error)
	{
		IFFCleanup(iff);
		return errors[ERR_IFFPARSE];
	}

	error = ParseIFF(iff, IFFPARSE_RAWSTEP);
	if (error)
	{
		IFFCleanup(iff);
		return errors[ERR_IFFPARSE];
	}
	cn = CurrentChunk(iff);
	if(!cn)
	{
		IFFCleanup(iff);
		return errors[ERR_IFFPARSE];
	}
	if((cn->cn_ID != ID_FORM) || (cn->cn_Type != ID_RMAT))
	{
		IFFCleanup(iff);
		return errors[ERR_NORMATFILE];
	}

	while(!error || error == IFFERR_EOC)
	{
		error = ParseIFF(iff, IFFPARSE_RAWSTEP);
		if(error != IFFERR_EOC)
		{
			// Get a pointer to the context node describing the current context
			cn = CurrentChunk(iff);
			if (cn)
			{
				switch (cn->cn_ID)
				{
					case ID_FORM:
						switch(cn->cn_Type)
						{
							case ID_SURF:
								if(!Read(iff, NULL))
								{
									IFFCleanup(iff);
									return errors[ERR_RMATCORRUPT];
								}
								break;
						}
						break;
				}
			}
		}
	}
	if (error != IFFERR_EOF)
	{
		return errors[ERR_IFFPARSE];
	}

	IFFCleanup(iff);

	return NULL;
}
Пример #27
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;
}
Пример #28
0
struct List *GetUnits(char *name) {
  struct List *list;
  struct IFFHandle *iff;
  BOOL devnodes[UNITNODES] = { FALSE, FALSE, FALSE, FALSE } ;
  BOOL lownode = FALSE;
  int i;

  globalprefs.ahigp_MaxCPU = (90 << 16) / 100;

  list = AllocVec(sizeof(struct List), MEMF_CLEAR);
  
  if(list) {
    NewList(list);
    
    if(name && (iff = AllocIFF())) {
      iff->iff_Stream = Open(name, MODE_OLDFILE);
      if(iff->iff_Stream) {
        InitIFFasDOS(iff);
        if(!OpenIFF(iff, IFFF_READ)) {
          if(!(PropChunk      (iff, ID_PREF, ID_AHIG) ||
               CollectionChunk(iff, ID_PREF, ID_AHIU) ||
               StopOnExit     (iff, ID_PREF, ID_FORM))) {
            if(ParseIFF(iff, IFFPARSE_SCAN) == IFFERR_EOC) {
              struct StoredProperty *global = FindProp(iff, ID_PREF, ID_AHIG);
              struct CollectionItem *ci = FindCollection(iff, ID_PREF, ID_AHIU);

              if(global != NULL) {
                CopyMem(global->sp_Data, &globalprefs, 
                    min( sizeof(struct AHIGlobalPrefs), global->sp_Size ));
              }

              while(ci) {
                struct AHIUnitPrefs *p = ci->ci_Data;
                struct UnitNode     *u;

                u = AllocVec(sizeof(struct UnitNode), MEMF_CLEAR);
                if(u == NULL)
                  break;
                CopyMem(p, &u->prefs, 
                    min( sizeof(struct AHIUnitPrefs), ci->ci_Size ));

                FillUnitName(u);
                
                u->node.ln_Pri = -(u->prefs.ahiup_Unit);
                Enqueue(list, (struct Node *) u);
                
                if(u->prefs.ahiup_Unit == AHI_NO_UNIT) {
                  lownode = TRUE;
                }
                else if(u->prefs.ahiup_Unit < UNITNODES) {
                  devnodes[u->prefs.ahiup_Unit] = TRUE;
                }
                
                ci=ci->ci_Next;
              }
            }
          }
          CloseIFF(iff);
        }
        Close(iff->iff_Stream);
      }
      FreeIFF(iff);
    }


    // Fill up to lowlevel + UNITNODES device nodes, if not found in prefs file

    if(!lownode) AddUnit(list, AHI_NO_UNIT);
    for(i = 0; i < UNITNODES; i++) {
      if(!devnodes[i]) AddUnit(list, i);
    }

  }

  return list;
}
Пример #29
0
/*************
 * DESCRIPTION:   read surface from scene file
 * INPUT:         iff      iff handler
 *                object   object surface
 * OUTPUT:        FALSE if failed else TRUE
 *************/
BOOL ReadSurface(struct IFFHandle *iff, SURFACE **surf, OBJECT *object)
{
	struct ContextNode *cn;
	long error;
	char buffer[256];
	SURFACE *tmp;
	BRUSH_OBJECT *brushobj;
	BRUSH *brush;
	TEXTURE_OBJECT *textureobj;
	TEXTURE *texture;

	if(rscn_version < 200)
	{
		*surf = sciCreateSurface(SURF_DEFAULTNAME);
		if(!*surf)
			return FALSE;

		if(!(*surf)->Read(iff, object))
			return FALSE;

		if(rscn_version == 100)
		{
			// in version 100 the brushes and textures were relative to the object
			(*surf)->ConvertV100(object);
		}
		if(rscn_version < 200)
		{
			// in pre 200 version surfaces were handled in a different way
			tmp = (*surf)->ConvertPreV200(object);
			if(!tmp)
				sciAddMaterial(*surf);
			else
				*surf = tmp;
		}
	}
	else
	{
		error = 0;

		while(!error)
		{
			error = ParseIFF(iff, IFFPARSE_RAWSTEP);
			if(error < 0 && error != IFFERR_EOC)
				return FALSE;

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

			if((cn->cn_ID == ID_FORM) && (cn->cn_Type == ID_SURF))
				break;

			if(error == IFFERR_EOC)
			{
				error = 0;
				continue;
			}
			switch (cn->cn_ID)
			{
				case ID_FORM:
					switch(cn->cn_Type)
					{
						case ID_BRSH:
							if(brush)
							{
								brushobj = ParseBrushObject(iff, object);
								if(!brushobj)
									return FALSE;
								brushobj->brush = brush;
								brush = (BRUSH*)brush->GetNext();
							}
							break;
						case ID_ITXT:
							if(texture)
							{
								textureobj = ParseTextureObject(iff, object);
								if(!textureobj)
									return FALSE;
								textureobj->texture = texture;
								texture = (TEXTURE*)texture->GetNext();
							}
							break;
					}
					break;
				case ID_NAME:
					if(!ReadString(iff,buffer,256))
						return FALSE;

					*surf = GetSurfaceByName(buffer);
					if(!(*surf))
					{
						*surf = GetSurfaceByName(SURF_DEFAULTNAME);
						if(!*surf)
							return FALSE;
					}
					brush = (*surf)->brush;
					texture = (*surf)->texture;
					break;
			}
		}
	}

	return TRUE;
}
Пример #30
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;
}