Esempio n. 1
0
/**************************************************************************
 Prepares the clipboard so that text can be written into it
**************************************************************************/
struct IFFHandle *PrepareClipboard(void)
{
    struct IFFHandle *iff = AllocIFF();

    if(iff)
    {
	if((iff->iff_Stream = (ULONG) OpenClipboard (0)))
	{
	    InitIFFasClip(iff);
	    if(!OpenIFF(iff,IFFF_WRITE))
	    {
		if(!PushChunk(iff, MAKE_ID('F','T','X','T'), MAKE_ID('F','O','R','M'), IFFSIZE_UNKNOWN))
		{
		    if(!PushChunk(iff, 0, MAKE_ID('C','H','R','S'), IFFSIZE_UNKNOWN))
		    {
			return iff;
		    }
		    PopChunk(iff);
		}
		CloseIFF(iff);
	    }
	    CloseClipboard((struct ClipboardHandle*)iff->iff_Stream);
	}
	FreeIFF(iff);
    }
    
    return NULL;
}
Esempio n. 2
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);
}
Esempio n. 3
0
bool gui_empty_clipboard(void)
{
	/* Put a half-completed FTXT on the clipboard and leave it open for more additions */

	struct CSet cset = {0};

	if(!(OpenIFF(iffh,IFFF_WRITE)))
	{
		if(!(PushChunk(iffh,ID_FTXT,ID_FORM,IFFSIZE_UNKNOWN)))
		{
			if(option_utf8_clipboard || ami_utf8_clipboard)
			{
				if(!(PushChunk(iffh,0,ID_CSET,32)))
				{
					cset.CodeSet = 106; // UTF-8
					WriteChunkBytes(iffh,&cset,32);
					PopChunk(iffh);
				}
			}
		}
		else
		{
			PopChunk(iffh);
			return false;
		}
		return true;
	}
	return false;
}
Esempio n. 4
0
BOOL InitClipboard(struct InstData *data, ULONG flags)
{
  struct IFFHandle *iff;

  ENTER();

  if((iff = AllocIFF()) != NULL)
  {
    SHOWVALUE(DBF_CLIPBOARD, iff);
    if((iff->iff_Stream = (ULONG)OpenClipboard(0)) != 0)
    {
      SHOWVALUE(DBF_CLIPBOARD, iff->iff_Stream);
      InitIFFasClip(iff);

      if(OpenIFF(iff, flags) == 0)
      {
        data->iff = iff;

        SHOWVALUE(DBF_CLIPBOARD, flags);

        RETURN(TRUE);
        return TRUE;
      }

      CloseClipboard((struct ClipboardHandle *)iff->iff_Stream);
    }

    FreeIFF(iff);
  }

  RETURN(FALSE);
  return(FALSE);
}
Esempio n. 5
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;
}
Esempio n. 6
0
void
saveFile(Entries entries, char *filename)
{
   BPTR f;
   struct IFFHandle *iff = NULL;

   f = Open(filename, MODE_NEWFILE);
   if (f == NULL) {
      myMsg3("couldn't open ", FileName, IoErr());
      return;
   }

   iff = AllocIFF();

   if (! iff) {
      myMsg1("couldn't alloc iff");
      return;
   }

   iff -> iff_Stream = f;

   InitIFFasDOS(iff);

   if (OpenIFF(iff, IFFF_WRITE)) {
      myMsg1("couldn't OpenIFF(WRITE)");
      return;
   }

   writeDatabaseFile(entries, iff);
   CloseIFF(iff);
   Close(iff -> iff_Stream);
   FreeIFF(iff);
}
Esempio n. 7
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. 8
0
static void gui_set_clipboard(const char *buffer, size_t length,
	nsclipboard_styles styles[], int n_styles)
{
	char *text;
	struct CSet cset = {0};

	if(buffer == NULL) return;

	if(!(OpenIFF(iffh, IFFF_WRITE)))
	{
		if(!(PushChunk(iffh, ID_FTXT, ID_FORM, IFFSIZE_UNKNOWN)))
		{
			if(nsoption_bool(clipboard_write_utf8))
			{
				if(!(PushChunk(iffh, 0, ID_CSET, 32)))
				{
					cset.CodeSet = 106; // UTF-8
					WriteChunkBytes(iffh, &cset, 32);
					PopChunk(iffh);
				}
			}
		}
		else
		{
			PopChunk(iffh);
		}

		if(!(PushChunk(iffh, 0, ID_CHRS, IFFSIZE_UNKNOWN))) {
			if(nsoption_bool(clipboard_write_utf8)) {
				WriteChunkBytes(iffh, buffer, length);
			} else {
				if(utf8_to_local_encoding(buffer, length, &text) == NSERROR_OK) {
					char *p;

					p = text;

					while(*p != '\0') {
						if(*p == 0xa0) *p = 0x20;
						p++;
					}
					WriteChunkBytes(iffh, text, strlen(text));
					ami_utf8_free(text);
				}
			}

			PopChunk(iffh);
		} else {
			PopChunk(iffh);
		}

		if(!(PushChunk(iffh, 0, ID_UTF8, IFFSIZE_UNKNOWN))) {
			WriteChunkBytes(iffh, buffer, length);
			PopChunk(iffh);
		} else {
			PopChunk(iffh);
		}
		CloseIFF(iffh);
	}
}
Esempio n. 9
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. 10
0
/**************************************************************************
 MUIM_Configdata_Save
**************************************************************************/
IPTR Configdata__MUIM_Save(struct IClass *cl, Object * obj,
                           struct MUIP_Configdata_Save *msg)
{
    struct IFFHandle *iff;
    if ((iff = AllocIFF()))
    {
        if (!(iff->iff_Stream = (IPTR)Open(msg->filename,MODE_NEWFILE)))
        {
            /* Try to Create the directory where the file is located */
            char *path = StrDup(msg->filename);
            if (path)
            {
                char *path_end = PathPart(path);
                if (path_end != path)
                {
                    BPTR lock;
                    *path_end = 0;
                    if ((lock = CreateDir(path)))
                    {
                        UnLock(lock);
                        iff->iff_Stream = (IPTR)Open(msg->filename,MODE_NEWFILE);
                    }
                }
                FreeVec(path);
            }
        }

        if (iff->iff_Stream)
        {
            InitIFFasDOS(iff);

            if (!OpenIFF(iff, IFFF_WRITE))
            {
                if (!PushChunk(iff, MAKE_ID('P','R','E','F'), ID_FORM, IFFSIZE_UNKNOWN))
                {
                    Configdata_SetWindowPos(cl, obj, (APTR)msg);
                    if (SavePrefsHeader(iff))
                    {
                        DoMethod(obj,MUIM_Dataspace_WriteIFF, (IPTR)iff, 0, MAKE_ID('M','U','I','C'));
                    }
                    PopChunk(iff);
                }

                CloseIFF(iff);
            }
            Close((BPTR)iff->iff_Stream);
        }
        FreeIFF(iff);
    }
    return 0;
}
Esempio n. 11
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. 12
0
BOOL SaveSettings(char *name, struct List *list) {
  struct IFFHandle  *iff;
  struct PrefHeader  header = { 0, 0, 0 };
  struct Node       *n;
  BOOL               success = FALSE;

  if(name && (iff = AllocIFF())) {
    iff->iff_Stream = Open(name, MODE_NEWFILE);
    if(iff->iff_Stream) {
      InitIFFasDOS(iff);
      if(!OpenIFF(iff, IFFF_WRITE)) {
        if(! PushChunk(iff, ID_PREF, ID_FORM, IFFSIZE_UNKNOWN)) {

          success = TRUE;

          // Prefs header
          if(! PushChunk(iff, ID_PREF, ID_PRHD, sizeof header)) {
            WriteChunkBytes(iff, &header, sizeof header);
            PopChunk(iff);
          }
          else success = FALSE;

          // Global prefs
          if(! PushChunk(iff, ID_PREF, ID_AHIG, sizeof globalprefs)) {
            WriteChunkBytes(iff, &globalprefs, sizeof globalprefs);
            PopChunk(iff);
          }
          else success = FALSE;

          // Units
          if(list != NULL) {    
            for(n = list->lh_Head; n->ln_Succ; n = n->ln_Succ) {
              if(! PushChunk(iff, ID_PREF, ID_AHIU, sizeof(struct AHIUnitPrefs))) {
                WriteChunkBytes(iff, &((struct UnitNode *) n)->prefs,
                    sizeof(struct AHIUnitPrefs));
                PopChunk(iff);
              }
              else success = FALSE;
            }
          }
        }
        CloseIFF(iff);
      }
      Close(iff->iff_Stream);
    }
    FreeIFF(iff);
  }
  return success;
}
Esempio n. 13
0
bool ami_easy_clipboard_svg(struct hlcache_handle *c)
{
	const char *source_data;
	ULONG source_size;

	if(ami_mime_compare(c, "svg") == false) return false;
	if((source_data = content_get_source_data(c, &source_size)) == NULL) return false;

	if(!(OpenIFF(iffh,IFFF_WRITE)))
	{
		ami_svg_to_dr2d(iffh, source_data, source_size, nsurl_access(hlcache_handle_get_url(c)));
		CloseIFF(iffh);
	}

	return true;
}
Esempio n. 14
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;
}
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
void PutScrap(uint32 type, void *scrap, int32 length)
{
	D(bug("PutScrap type %08lx, data %08lx, length %ld\n", type, scrap, length));
	if (length <= 0 || !clipboard_open)
		return;

	switch (type) {
		case 'TEXT': {
			D(bug(" clipping TEXT\n"));

			// Open IFF stream
			if (OpenIFF(iffw, IFFF_WRITE))
				break;

			// Convert text from Mac charset to ISO-Latin1
			uint8 *buf = new uint8[length];
			uint8 *p = (uint8 *)scrap;
			uint8 *q = buf;
			for (int i=0; i<length; i++) {
				uint8 c = *p++;
				if (c < 0x80) {
					if (c == 13)	// CR -> LF
						c = 10;
				} else if (!no_clip_conversion)
					c = mac2iso[c & 0x7f];
				*q++ = c;
			}

			// Write text
			if (!PushChunk(iffw, 'FTXT', 'FORM', IFFSIZE_UNKNOWN)) {
				if (!PushChunk(iffw, 0, 'CHRS', IFFSIZE_UNKNOWN)) {
					WriteChunkBytes(iffw, scrap, length);
					PopChunk(iffw);
				}
				PopChunk(iffw);
			}

			// Close IFF stream
			CloseIFF(iffw);
			delete[] buf;
			break;
		}
	}
}
Esempio n. 17
0
/* Open preference file according to `mode' */
APTR open_prefs(STRPTR file, UBYTE mode)
{
	struct IFFHandle * pref;

	if( IFFParseBase != NULL && (pref = (APTR) AllocIFF() ) )
	{
		BPTR fh = 0;
		switch( mode )
		{
			case MODE_USE:
				if(file == NULL)
				{
					/* First: search in local directory */
					CopyMem(File, Path, sizeof(File)-1);
					if(NULL == (fh = Open( Path, MODE_OLDFILE )))
					{
						/* Otherwise, look in directory ENVARC */
						CopyMem(ENV, Path,sizeof(ENV)-1);
						CopyMem(File,Path+sizeof(ENV)-1,sizeof(File)-1);
						fh = Open( Path, MODE_OLDFILE );
					}
				} else if(NULL != (fh = Open( file, MODE_OLDFILE )))
					strcpy(Path, file);
				break;
			case MODE_SAVE:
				fh = Open(Path, MODE_NEWFILE);
		}
		/* Did we have a opened file? */
		if( fh )
		{
			pref->iff_Stream = (IPTR) fh;
			/* Use DOS function for accessing it */
			InitIFFasDOS( pref );
			/* Open it through iffparse */
			if( !OpenIFF( pref, mode == MODE_SAVE ? IFFF_WRITE : IFFF_READ) )
				return pref;
		}
		FreeIFF( pref );
	}
	return NULL;
}
Esempio n. 18
0
static void
readIFFFile(Gui_t gui, Entries entries, char *file)
{
   BPTR f;
   struct IFFHandle *iff = NULL;

   if (file)
      strcpy(FileName, file);
   else
      getFileName(gui,FileName,getString(MSG_OPEN_FILE), FileName, Pattern);

   f = Open(FileName, MODE_OLDFILE);
   if (f == NULL) {
      myMsg2("couldn't open", FileName);
      return;
   }

   iff = AllocIFF();

   if (! iff) {
      myMsg1("couldn't alloc iff");
      return;
   }

   iff -> iff_Stream = f;

   InitIFFasDOS(iff);

   if (OpenIFF(iff, IFFF_READ)) {
      myMsg1("couldn't OpenIFF(READ)");
      return;
   }

   readDatabaseFile(entries, iff);
   CloseIFF(iff);
   Close(iff -> iff_Stream);
   FreeIFF(iff);
}
Esempio n. 19
0
/*************
 * DESCRIPTION:   save a surface definition
 * INPUT:         filename    name of surface file
 * OUTPUT:        error string or NULL if all ok
 *************/
char *SURFACE::Save(char *filename)
{
	struct IFFHandle *iff;

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

	// Set up IFF_File for AmigaDOS I/O.
#ifdef __AMIGA__
	iff->iff_Stream = Open(filename, MODE_NEWFILE);
#else
	iff->iff_Stream = Open_(filename, MODE_NEWFILE);
#endif
	if(!iff->iff_Stream)
	{
		IFFCleanup(iff);
		return errors[ERR_OPEN];
	}
	InitIFFasDOS(iff);

	// Start the IFF transaction.
	if(OpenIFF(iff, IFFF_WRITE))
	{
		IFFCleanup(iff);
		return errors[ERR_IFFPARSE];
	}

	PUSH_CHUNK(ID_RMAT);

	// write surface
	Write(iff);

	IFFCleanup(iff);
	return NULL;
}
Esempio n. 20
0
main(int argc, char **argv)
{
    int colors;
    struct {
        long nplanes;
        long pbytes;
        long across;
        long down;
        long npics;
        long xsize;
        long ysize;
    } pdat;
    long pbytes; /* Bytes of data in a plane */
    int i, cnt;
    BitMapHeader bmhd;
    struct IFFHandle *iff;
    long camg = HIRES | LACE;
    int tiles = 0;
    char **planes;

    if (argc != 3) {
        fprintf(stderr, "Usage: %s source destination\n", argv[0]);
        exit(1);
    }

#if defined(_DCC) || defined(__GNUC__)
    IFFParseBase = OpenLibrary("iffparse.library", 0);
    if (!IFFParseBase) {
        error("unable to open iffparse.library");
        exit(1);
    }
#endif

    /* First, count the files in the file */
    if (fopen_text_file(argv[1], "r") != TRUE) {
        perror(argv[1]);
        return (1);
    }

    nplanes = 0;
    i = colorsinmap - 1; /*IFFScreen.Colors - 1; */
    while (i != 0) {
        nplanes++;
        i >>= 1;
    }

    planes = malloc(nplanes * sizeof(char *));
    if (planes == 0) {
        error("can not allocate planes pointer");
        exit(1);
    }

    while (read_text_tile(pixels) == TRUE)
        ++tiles;
    fclose_text_file();

    IFFScreen.Width = COLS * TILE_X;
    IFFScreen.Height = ROWS * TILE_Y;

    pbytes = (COLS * ROWS * TILE_X + 15) / 16 * 2 * TILE_Y;

    for (i = 0; i < nplanes; ++i) {
        planes[i] = calloc(1, pbytes);
        if (planes[i] == 0) {
            error("can not allocate planes pointer");
            exit(1);
        }
    }

    /* Now, process it */
    if (fopen_text_file(argv[1], "r") != TRUE) {
        perror(argv[1]);
        return (1);
    }

    iff = AllocIFF();
    if (!iff) {
        error("Can not allocate IFFHandle");
        return (1);
    }

    iff->iff_Stream = Open(argv[2], MODE_NEWFILE);
    if (!iff->iff_Stream) {
        error("Can not open output file");
        return (1);
    }

    InitIFFasDOS(iff);
    OpenIFF(iff, IFFF_WRITE);

    PushChunk(iff, ID_BMAP, ID_FORM, IFFSIZE_UNKNOWN);

    bmhd.w = IFFScreen.Width;
    bmhd.h = IFFScreen.Height;
    bmhd.x = 0;
    bmhd.y = 0;
    bmhd.nPlanes = nplanes;
    bmhd.masking = 0;
    bmhd.compression = 0;
    bmhd.reserved1 = 0;
    bmhd.transparentColor = 0;
    bmhd.xAspect = 100;
    bmhd.yAspect = 100;
    bmhd.pageWidth = TILE_X;
    bmhd.pageHeight = TILE_Y;

    PushChunk(iff, ID_BMAP, ID_BMHD, sizeof(bmhd));
    WriteChunkBytes(iff, &bmhd, sizeof(bmhd));
    PopChunk(iff);

    PushChunk(iff, ID_BMAP, ID_CAMG, sizeof(camg));
    WriteChunkBytes(iff, &camg, sizeof(camg));
    PopChunk(iff);

    /* We need to reorder the colors to get reasonable default pens but
     * we also need to know where some of the colors are - so go find out.
     */
    map_colors();

    cmap = malloc((colors = (1L << nplanes)) * sizeof(AmiColorMap));
    for (i = 0; i < colors; ++i) {
        cmap[colrmap[i]].r = ColorMap[CM_RED][i];
        cmap[colrmap[i]].g = ColorMap[CM_GREEN][i];
        cmap[colrmap[i]].b = ColorMap[CM_BLUE][i];
    }

    PushChunk(iff, ID_BMAP, ID_CMAP, IFFSIZE_UNKNOWN);
    for (i = 0; i < colors; ++i)
        WriteChunkBytes(iff, &cmap[i], 3);
    PopChunk(iff);

    cnt = 0;
    while (read_text_tile(pixels) == TRUE) {
        packwritebody(pixels, planes, cnt);
        if (cnt % 20 == 0)
            printf("%d..", cnt);
        ++cnt;
        fflush(stdout);
    }

    pdat.nplanes = nplanes;
    pdat.pbytes = pbytes;
    pdat.xsize = TILE_X;
    pdat.ysize = TILE_Y;
    pdat.across = COLS;
    pdat.down = ROWS;
    pdat.npics = cnt;

    PushChunk(iff, ID_BMAP, ID_PDAT, IFFSIZE_UNKNOWN);
    WriteChunkBytes(iff, &pdat, sizeof(pdat));
    PopChunk(iff);

    PushChunk(iff, ID_BMAP, ID_PLNE, IFFSIZE_UNKNOWN);
    for (i = 0; i < nplanes; ++i)
        WriteChunkBytes(iff, planes[i], pbytes);
    PopChunk(iff);

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

    printf("\n%d tiles converted\n", cnt);

#if defined(_DCC) || defined(__GNUC__)
    CloseLibrary(IFFParseBase);
#endif
    exit(0);
}
Esempio n. 21
0
BOOL SavePrefsFH(BPTR fh)
{
    static struct SerialPrefs 	saveprefs;
    struct IFFHandle 	     	*iff;    
    BOOL    	    	    	retval = FALSE, delete_if_error = FALSE;
    
    saveprefs = serialprefs;
    
    
    D(bug("SavePrefsFH: fh: %lx\n", fh));
    //if ((iff->iff_Stream = (IPTR)Open(filename, MODE_NEWFILE)))
    
    if ((iff = AllocIFF()))
    {
	iff->iff_Stream = (IPTR) fh;
	D(bug("SavePrefsFH: stream opened.\n"));
	    
	    delete_if_error = TRUE;
	    
	    InitIFFasDOS(iff);
	    
	    if (!OpenIFF(iff, IFFF_WRITE))
	    {
    	    	D(bug("SavePrefsFH: OpenIFF okay.\n"));
		
		if (!PushChunk(iff, ID_PREF, ID_FORM, IFFSIZE_UNKNOWN))
		{
    	    	    D(bug("SavePrefsFH: PushChunk(FORM) okay.\n"));
		    
		    if (!PushChunk(iff, ID_PREF, ID_PRHD, sizeof(struct FilePrefHeader)))
		    {
		    	struct FilePrefHeader head;

    	    	    	D(bug("SavePrefsFH: PushChunk(PRHD) okay.\n"));
			
			head.ph_Version  = PHV_CURRENT; 
			head.ph_Type     = 0;
			head.ph_Flags[0] =
			head.ph_Flags[1] =
			head.ph_Flags[2] =
			head.ph_Flags[3] = 0;
			
			if (WriteChunkBytes(iff, &head, sizeof(head)) == sizeof(head))
			{
    	    	    	    D(bug("SavePrefsFH: WriteChunkBytes(PRHD) okay.\n"));
			    
			    PopChunk(iff);
			    
			    if (!PushChunk(iff, ID_PREF, ID_SERL, sizeof(struct SerialPrefs)))
			    {
    	    	    	    	D(bug("SavePrefsFH: PushChunk(LCLE) okay.\n"));
				
			    	if (WriteChunkBytes(iff, &saveprefs, sizeof(saveprefs)) == sizeof(saveprefs))
				{
   	    	    	    	    D(bug("SavePrefsFH: WriteChunkBytes(SERL) okay.\n"));
  	    	    	    	    D(bug("SavePrefsFH: Everything okay :-)\n"));
				    
				    retval = TRUE;
				}
				
    			    	PopChunk(iff);

			    } /* if (!PushChunk(iff, ID_PREF, ID_SERL, sizeof(struct LocalePrefs))) */
			    			    
			} /* if (WriteChunkBytes(iff, &head, sizeof(head)) == sizeof(head)) */
			else
		    	{
			    PopChunk(iff);
			}
			
		    } /* if (!PushChunk(iff, ID_PREF, ID_PRHD, sizeof(struct PrefHeader))) */
		    
		    PopChunk(iff);
		    		    
		} /* if (!PushChunk(iff, ID_PREF, ID_FORM, IFFSIZE_UNKNOWN)) */
		
	    	CloseIFF(iff);
				
	    } /* if (!OpenIFF(iff, IFFFWRITE)) */
	    
	
	FreeIFF(iff);
	
    } /* if ((iff = AllocIFF())) */
    
    #if 0
    if (!retval && delete_if_error)
    {
    	DeleteFile(filename);
    }
    #endif
	    
    
    return retval;    
}
Esempio n. 22
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. 23
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;
            }
          }
Esempio n. 24
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;
}
Esempio n. 25
0
IPTR SMEditor__MUIM_PrefsEditor_ExportFH
(
    Class *CLASS, Object *self,
    struct MUIP_PrefsEditor_ExportFH *message
)
{
    SETUP_INST_DATA;
    
    struct PrefHeader header = { 0 }; 
    struct IFFHandle *handle;
    BOOL              success = TRUE;
    LONG              error   = 0;
        
    if ((handle = AllocIFF()))
    {
        handle->iff_Stream = (IPTR) message->fh;
        
        InitIFFasDOS(handle);
        
        if (!(error = OpenIFF(handle, IFFF_WRITE))) /* NULL = successful! */
        {
            struct ScreenModePrefs smp;
	    
	    memset(&smp, 0, sizeof(smp));
            
	    BYTE i;
            
            PushChunk(handle, ID_PREF, ID_FORM, IFFSIZE_UNKNOWN); /* FIXME: IFFSIZE_UNKNOWN? */
            
            header.ph_Version = PHV_CURRENT;
            header.ph_Type    = 0;
            
            PushChunk(handle, ID_PREF, ID_PRHD, IFFSIZE_UNKNOWN); /* FIXME: IFFSIZE_UNKNOWN? */
            
            WriteChunkBytes(handle, &header, sizeof(struct PrefHeader));
            
            PopChunk(handle);
            
            for (i = 0; i < 1; i++)
            {
                error = PushChunk(handle, ID_PREF, ID_SCRM, sizeof(struct ScreenModePrefs));
                
                if (error != 0) // TODO: We need some error checking here!
                {
                    printf("error: PushChunk() = %ld ", error);
                }
                
	        smp.smp_DisplayID = XGET(data->properties, MUIA_ScreenModeProperties_DisplayID);
                smp.smp_Width     = XGET(data->properties, MUIA_ScreenModeProperties_Width);
                smp.smp_Height    = XGET(data->properties, MUIA_ScreenModeProperties_Height);
                smp.smp_Depth     = XGET(data->properties, MUIA_ScreenModeProperties_Depth);
                
		if (XGET(data->properties, MUIA_ScreenModeProperties_Autoscroll))
		    smp.smp_Control = AUTOSCROLL;
		else
		    smp.smp_Control = 0;
                
		SMPByteSwap(&smp);
			
                error = WriteChunkBytes(handle, &smp, sizeof(struct ScreenModePrefs));
                error = PopChunk(handle);
                                
                if (error != 0) // TODO: We need some error checking here!
                {
                    printf("error: PopChunk() = %ld ", error);
                }
            }

            // Terminate the FORM
            PopChunk(handle);
        }
        else
        {
            //ShowError(_(MSG_CANT_OPEN_STREAM));
            success = FALSE;
        }
        
        CloseIFF(handle);
	FreeIFF(handle);
    }
    else // AllocIFF()
    {
        // Do something more here - if IFF allocation has failed, something isn't right
        //ShowError(_(MSG_CANT_ALLOCATE_IFFPTR));
        success = FALSE;
    }

    return success;
}
Esempio n. 26
0
main( int argc, char **argv )
{
    int colors;
    struct {
	long nplanes;
	long pbytes;
	long across;
	long down;
	long npics;
	long xsize;
	long ysize;
    } pdat;
    long pbytes;	/* Bytes of data in a plane */
    int i, cnt;
    BitMapHeader bmhd;
    struct IFFHandle *iff;
    long camg = HIRES|LACE;
    int tiles=0;
    int index;

#if defined(_DCC) || defined (__GNUC__)
    IFFParseBase = OpenLibrary( "iffparse.library", 0 );
    if( !IFFParseBase ) {
	error( "unable to open iffparse.library" );
	exit( 1 );
    }
#endif

    if( fopen_xpm_file( argv[1], "r" ) != TRUE )
    {
	perror( argv[1] );
	return( 1 );
    }

    nplanes = 0;
    i = XpmScreen.Colors - 1;
    while( i != 0 )
    {
	nplanes++;
	i >>= 1;
    }

    planes = malloc( nplanes * sizeof( char * ) );
    if( planes == 0 )
    {
	error( "can not allocate planes pointer" );
	exit( 1 );
    }

    XpmScreen.BytesPerRow = ((XpmScreen.Width + 15)/16)*2;
    pbytes = XpmScreen.BytesPerRow * XpmScreen.Height;
    for( i = 0; i < nplanes; ++i )
    {
	planes[ i ] = malloc( pbytes );
	if( planes[ i ] == 0 )
	{
	    error( "can not allocate planes pointer" );
	    exit( 1 );
	}
	memset( planes[i], 0, pbytes );
    }

    iff = AllocIFF();
    if( !iff )
    {
	error( "Can not allocate IFFHandle" );
	return( 1 );
    }

    iff->iff_Stream = Open( argv[2], MODE_NEWFILE );
    if( !iff->iff_Stream )
    {
	error( "Can not open output file" );
	return( 1 );
    }

    InitIFFasDOS( iff );
    OpenIFF( iff, IFFF_WRITE );

    PushChunk( iff, ID_BMAP, ID_FORM, IFFSIZE_UNKNOWN );

    bmhd.w = XpmScreen.Width;
    bmhd.h = XpmScreen.Height;
    bmhd.x = 0;
    bmhd.y = 0;
    bmhd.nPlanes = nplanes;
    bmhd.masking = 0;
    bmhd.compression = 0;
    bmhd.reserved1 = 0;
    bmhd.transparentColor = 0;
    bmhd.xAspect = 100;
    bmhd.yAspect = 100;
    bmhd.pageWidth = 0;			/* not needed for this program */
    bmhd.pageHeight = 0;		/* not needed for this program */

    PushChunk( iff, ID_BMAP, ID_BMHD, sizeof( bmhd ) );
    WriteChunkBytes( iff, &bmhd, sizeof( bmhd ) );
    PopChunk( iff );

    PushChunk( iff, ID_BMAP, ID_CAMG, sizeof( camg ) );
    WriteChunkBytes( iff, &camg, sizeof( camg ) );
    PopChunk( iff );

#define SCALE(x) (x)
    cmap = malloc( (colors = (1L<<nplanes)) * sizeof(AmiColorMap) );
    if(cmap == 0){
	error("Can't allocate color map");
	exit(1);
    }
    for(index = 0; index<256; index++){
	if(ttable[index].flag){
	    cmap[ttable[index].slot].r = SCALE(ttable[index].r);
	    cmap[ttable[index].slot].g = SCALE(ttable[index].g);
	    cmap[ttable[index].slot].b = SCALE(ttable[index].b);
	}
    }
#undef SCALE

    PushChunk( iff, ID_BMAP, ID_CMAP, IFFSIZE_UNKNOWN );
    WriteChunkBytes( iff, cmap, colors*sizeof(*cmap) );
    PopChunk( iff );

    conv_image();

    pdat.nplanes = nplanes;
    pdat.pbytes = pbytes;
    pdat.xsize = XpmScreen.Width;
    pdat.ysize = XpmScreen.Height;
    pdat.across = 0;
    pdat.down = 0;
    pdat.npics = 1;

    PushChunk( iff, ID_BMAP, ID_PDAT, IFFSIZE_UNKNOWN );
    WriteChunkBytes( iff, &pdat, sizeof( pdat ) );
    PopChunk( iff );

    PushChunk( iff, ID_BMAP, ID_PLNE, IFFSIZE_UNKNOWN );
    for( i = 0; i < nplanes; ++i )
	WriteChunkBytes( iff, planes[i], pbytes );
    PopChunk( iff );

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

#if defined(_DCC) || defined (__GNUC__)
    CloseLibrary( IFFParseBase );
#endif
    exit( 0 );
}
Esempio n. 27
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;
}
Esempio n. 28
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;
}
Esempio n. 29
0
/*** Write strings to the clipboard.device ***/
BOOL CBWriteFTXT( LINE *stsel, struct cutcopypast *ccp )
{
	LINE *ln;
	long  length;

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

	/* Compute how many chars are selected */
	for(length=0, ln=stsel; ln && ln->flags; ln=ln->next)
	{
		length += ln->size;
		/* In block selection mode, always add a newline */
		if(ccp->select == COLUMN_TYPE) length++;
		if(ln->flags & FIRSTSEL) length -= find_nbc(ln, ccp->startsel);
		if(ln->flags & LASTSEL)  length += find_nbc(ln, ccp->endsel)-ln->size;
		else length++; /* New line */
	}
	if(length == 0) return FALSE;

	if( !OpenIFF(clip, IFFF_WRITE) )
	{
		/* Let iffparse manage main chunk size */
		if( !PushChunk(clip, ID_FTXT, ID_FORM, IFFSIZE_UNKNOWN) )
		{
			if( !PushChunk(clip, ID_FTXT, ID_CHRS, length) )
			{
				/* In columnar selection, use '\r' as eol */
				char eol = (ccp->select == COLUMN_TYPE ? '\r':'\n'), add_eol;

				/* Write the content of strings */
				for(ln = stsel; ln && ln->flags; ln = ln->next)
				{
					STRPTR stream;
					ULONG  length;
					stream = (STRPTR)ln->stream;
					length = ln->size;
					if(ln->flags & FIRSTSEL) {
						register long rc = find_nbc(ln, ccp->startsel);
						length -= rc; stream += rc;
					}
					if(ln->flags & LASTSEL) {
						length += find_nbc(ln, ccp->endsel) - ln->size;
						/* Add automatically a newline */
						add_eol = (ccp->select == COLUMN_TYPE);
					}
					else add_eol = 1;

					WriteChunkBytes(clip, stream, length);
					if(add_eol)
						WriteChunkBytes(clip, &eol, 1);
				}
				PopChunk(clip);
			}
			else ThrowError(Wnd, ErrMsg(ERR_NOMEM));
			PopChunk(clip);
		}
		else ThrowError(Wnd, ErrMsg(ERR_NOMEM));
		CloseIFF(clip);
	}
	return TRUE;
}
Esempio n. 30
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;
}