Esempio n. 1
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. 2
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. 3
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. 4
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. 5
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. 6
0
/**************************************************************************
 Free all resources allocated in PrepareClipboard
**************************************************************************/
VOID FreeClipboard(struct IFFHandle *iff)
{
    PopChunk(iff);
    PopChunk(iff);
    CloseIFF(iff);
    CloseClipboard((struct ClipboardHandle*)iff->iff_Stream);
    FreeIFF(iff);
}
Esempio n. 7
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. 8
0
/*************
 * DESCRIPTION:   free mem and iff-handle
 * INPUT:         data     handler data
 * OUTPUT:        none
 *************/
static void readLWOB_cleanup(HANDLER_DATA *data)
{
	FreeBuffers(data);

	if(data->iff)
	{
		CloseIFF(data->iff);
		if(data->iff->iff_Stream)
			Close(data->iff->iff_Stream);
		FreeIFF(data->iff);
		data->iff = NULL;
	}
}
Esempio n. 9
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. 10
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. 11
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. 12
0
void EndClipSession(struct InstData *data)
{
  ENTER();

  if(data->iff != NULL)
  {
    CloseIFF(data->iff);

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

    FreeIFF(data->iff);
    data->iff = NULL;
  }

  LEAVE();
}
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
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. 18
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. 19
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. 20
0
static BOOL ami_print_readunit(CONST_STRPTR filename, char name[],
	uint32 namesize, int unitnum)
{
	/* This is a modified version of a function from the OS4 SDK.
	 * The README says "You can use it in your application",
	 * no licence is specified. (c) 1999 Amiga Inc */

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

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

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

	return TRUE;
}
Esempio n. 21
0
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. 22
0
int WriteOutDTD(struct DTDesc *TheDTDesc)
{
    struct IFFHandle *IH;
    struct FileDataTypeHeader FileDTH;
    int i;

    if(!TheDTDesc)
    {
        return(FALSE);
    }

    if(strlen(TheDTDesc->Name)==0)
    {
        return(FALSE);
    }

    if(strlen(TheDTDesc->BaseName)==0)
    {
        return(FALSE);
    }

#if 0
    if(TheDTDesc->DTH.dth_MaskLen==0)
    {
        return(FALSE);
    }
#endif

    if(strlen(TheDTDesc->Pattern)==0)
    {
        TheDTDesc->Pattern[0]='#';
        TheDTDesc->Pattern[1]='?';
        TheDTDesc->Pattern[2]='\0';
    }

    IH=NewIFF(TheDTDesc->OutputName, MAKE_ID('D','T','Y','P'));
    if(!IH)
    {
        return(FALSE);
    }

    if(!NewChunk(IH, MAKE_ID('N','A','M','E')))
    {
        CloseIFF(IH);
        remove(TheDTDesc->Name);
        return(FALSE);
    }

    if(WriteChunkData(IH, TheDTDesc->Name, (strlen(TheDTDesc->Name)+1))<=0)
    {
        EndChunk(IH);
        CloseIFF(IH);
        remove(TheDTDesc->Name);
        return(FALSE);
    }

    EndChunk(IH);

    if(strlen(TheDTDesc->Version) > 0)
    {
        if(!NewChunk(IH, MAKE_ID('F','V','E','R')))
        {
            CloseIFF(IH);
            remove(TheDTDesc->Name);
            return(FALSE);
        }

        if(WriteChunkData(IH, TheDTDesc->Version, (strlen(TheDTDesc->Version)+1))<=0)
        {
            EndChunk(IH);
            CloseIFF(IH);
            remove(TheDTDesc->Name);
            return(FALSE);
        }

        EndChunk(IH);
    }

    if(!NewChunk(IH, MAKE_ID('D','T','H','D')))
    {
        CloseIFF(IH);
        remove(TheDTDesc->Name);
        return(FALSE);
    }

    FileDTH.dth_Name     = (((unsigned int) sizeof(struct FileDataTypeHeader)));
    FileDTH.dth_BaseName = (((unsigned int) FileDTH.dth_Name) + strlen(TheDTDesc->DTH.dth_Name) + 1);
    FileDTH.dth_Pattern  = (((unsigned int) FileDTH.dth_BaseName) + strlen(TheDTDesc->DTH.dth_BaseName) + 1);
    FileDTH.dth_Mask     = (((unsigned int) FileDTH.dth_Pattern) + strlen(TheDTDesc->DTH.dth_Pattern) + 1);
    FileDTH.dth_GroupID  = TheDTDesc->DTH.dth_GroupID;
    FileDTH.dth_ID       = TheDTDesc->DTH.dth_ID;
    FileDTH.dth_MaskLen  = TheDTDesc->DTH.dth_MaskLen;
    FileDTH.dth_Pad      = TheDTDesc->DTH.dth_Pad;
    FileDTH.dth_Flags    = TheDTDesc->DTH.dth_Flags;
    FileDTH.dth_Priority = TheDTDesc->DTH.dth_Priority;

    FileDTH.dth_Name     = Swap32IfLE(((uint32_t) FileDTH.dth_Name));
    FileDTH.dth_BaseName = Swap32IfLE(((uint32_t) FileDTH.dth_BaseName));
    FileDTH.dth_Pattern  = Swap32IfLE(((uint32_t) FileDTH.dth_Pattern));
    FileDTH.dth_Mask     = Swap32IfLE(((uint32_t) FileDTH.dth_Mask));
    FileDTH.dth_GroupID  = Swap32IfLE(FileDTH.dth_GroupID);
    FileDTH.dth_ID       = Swap32IfLE(FileDTH.dth_ID);
    FileDTH.dth_MaskLen  = Swap16IfLE(FileDTH.dth_MaskLen);
    FileDTH.dth_Pad      = Swap16IfLE(FileDTH.dth_Pad);
    FileDTH.dth_Flags    = Swap16IfLE(FileDTH.dth_Flags);
    FileDTH.dth_Priority = Swap16IfLE(FileDTH.dth_Priority);

    if(WriteChunkData(IH, (char *) &FileDTH, sizeof(struct FileDataTypeHeader))<=0)
    {
        EndChunk(IH);
        CloseIFF(IH);
        remove(TheDTDesc->Name);
        return(FALSE);
    }

    if(WriteChunkData(IH, TheDTDesc->DTH.dth_Name, (strlen(TheDTDesc->DTH.dth_Name)+1))<=0)
    {
        EndChunk(IH);
        CloseIFF(IH);
        remove(TheDTDesc->Name);
        return(FALSE);
    }

    if(WriteChunkData(IH, TheDTDesc->DTH.dth_BaseName, (strlen(TheDTDesc->DTH.dth_BaseName)+1))<=0)
    {
        EndChunk(IH);
        CloseIFF(IH);
        remove(TheDTDesc->Name);
        return(FALSE);
    }

    if(WriteChunkData(IH, TheDTDesc->DTH.dth_Pattern, (strlen(TheDTDesc->DTH.dth_Pattern)+1))<=0)
    {
        EndChunk(IH);
        CloseIFF(IH);
        remove(TheDTDesc->Name);
        return(FALSE);
    }

    for(i=0; i<TheDTDesc->DTH.dth_MaskLen; i++)
    {
        TheDTDesc->DTH.dth_Mask[i]=Swap16IfLE(TheDTDesc->DTH.dth_Mask[i]);
    }

    if (TheDTDesc->DTH.dth_MaskLen)
    {
        if(WriteChunkData(IH, (char *) TheDTDesc->DTH.dth_Mask, TheDTDesc->DTH.dth_MaskLen*sizeof(uint16_t))<=0)
        {
            EndChunk(IH);
            CloseIFF(IH);
            remove(TheDTDesc->Name);
            return(FALSE);
        }
    }

    EndChunk(IH);

    CloseIFF(IH);

    return(TRUE);
}
Esempio n. 23
0
static ULONG
AddModeFile ( UBYTE *filename )
{
  struct IFFHandle *iff;
  struct StoredProperty *name,*data;
  struct CollectionItem *ci;
  struct TagItem *tag,*tstate;
  struct TagItem extratags[]=
  {
    { AHIDB_Driver, NULL },
    { AHIDB_Data, NULL },
    { TAG_MORE,   NULL }
  };
  ULONG rc=FALSE;

  iff = AllocIFF();

  if(iff != NULL)
  {

    iff->iff_Stream = Open(filename, MODE_OLDFILE);

    if(iff->iff_Stream != NULL)
    {
      InitIFFasDOS(iff);

      if(!OpenIFF(iff, IFFF_READ))
      {

        if(!(PropChunk(iff,       ID_AHIM, ID_AUDN)
          || PropChunk(iff,       ID_AHIM, ID_AUDD)
          || CollectionChunk(iff, ID_AHIM, ID_AUDM)
          || StopOnExit(iff,      ID_AHIM, ID_FORM)))
        {
          if(ParseIFF(iff, IFFPARSE_SCAN) == IFFERR_EOC)
          {
            name = FindProp(iff,       ID_AHIM, ID_AUDN);
            data = FindProp(iff,       ID_AHIM, ID_AUDD);
            ci   = FindCollection(iff, ID_AHIM, ID_AUDM);

            if(name != NULL)
            {
              extratags[0].ti_Data = (ULONG) name->sp_Data;
            }

            if(data != NULL)
            {
              extratags[1].ti_Data = (ULONG) data->sp_Data;
            }

            rc = TRUE;

            while(ci != NULL)
            {
              // Relocate loaded taglist

              tstate = (struct TagItem *) ci->ci_Data;
              while((tag = NextTagItem(&tstate)) != NULL )
              {
                if(tag->ti_Tag & (AHI_TagBaseR ^ AHI_TagBase))
                {
                  tag->ti_Data += (ULONG) ci->ci_Data;
                }
              }

              // Link taglists

              extratags[2].ti_Data = (ULONG) ci->ci_Data;

              rc = AHI_AddAudioMode(extratags);

              ci = ci->ci_Next;
            }
          }
        }
        CloseIFF(iff);
      }
      Close(iff->iff_Stream);
    }
    FreeIFF(iff);
  }

  return rc;
}
Esempio n. 24
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. 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
bool gui_commit_clipboard(void)
{
	if(iffh) CloseIFF(iffh);

	return true;
}
Esempio n. 27
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;
}
Esempio n. 28
0
/*** Close properly IFF handle ***/
void close_prefs( struct IFFHandle * file )
{
	CloseIFF( file );
	if( file->iff_Stream ) Close((BPTR) file->iff_Stream );
	FreeIFF( file );
}
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
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;
}