Пример #1
0
bool ami_clipboard_copy(const char *text, size_t length, struct box *box,
	void *handle, const char *whitespace_text,size_t whitespace_length)
{
	if(!(PushChunk(iffh,0,ID_CHRS,IFFSIZE_UNKNOWN)))
	{
		if (whitespace_text)
		{
			if(!ami_add_to_clipboard(whitespace_text,whitespace_length, false)) return false;
		}

		if(text)
		{
			bool add_space = box != NULL ? box->space != 0 : false;

			if (!ami_add_to_clipboard(text, length, add_space)) return false;
		}

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

	return true;
}
Пример #2
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;
}
Пример #3
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);
}
Пример #4
0
void ClipLine(struct line_node *line, struct InstData *data)
{
  UWORD *styles = line->line.Styles;
  UWORD *colors = line->line.Colors;
  LONG error;

  ENTER();

  D(DBF_CLIPBOARD, "ClipLine()");

  ClipInfo(line, data);

  if(colors)
  {
    D(DBF_CLIPBOARD, "writing COLS");
    error = PushChunk(data->iff, 0, ID_COLS, IFFSIZE_UNKNOWN);
    SHOWVALUE(DBF_CLIPBOARD, error);

    while(*colors != 0xffff)
    {
      colors += 2;
    }

    error = WriteChunkBytes(data->iff, line->line.Colors, colors - line->line.Colors);
    SHOWVALUE(DBF_CLIPBOARD, error);
    error = PopChunk(data->iff);
    SHOWVALUE(DBF_CLIPBOARD, error);
  }

  if(styles)
  {
    D(DBF_CLIPBOARD, "writing STYL");
    error = PushChunk(data->iff, 0, ID_STYL, IFFSIZE_UNKNOWN);
    SHOWVALUE(DBF_CLIPBOARD, error);

    while(*styles != EOS)
    {
      styles += 2;
    }

    error = WriteChunkBytes(data->iff, line->line.Styles, styles - line->line.Styles);
    SHOWVALUE(DBF_CLIPBOARD, error);
    error = PopChunk(data->iff);
    SHOWVALUE(DBF_CLIPBOARD, error);
  }

  D(DBF_CLIPBOARD, "writing CHRS");
  error = PushChunk(data->iff, 0, ID_CHRS, IFFSIZE_UNKNOWN);
  SHOWVALUE(DBF_CLIPBOARD, error);
  error = WriteChunkBytes(data->iff, line->line.Contents, line->line.Length);
  SHOWVALUE(DBF_CLIPBOARD, error);
  error = PopChunk(data->iff);
  SHOWVALUE(DBF_CLIPBOARD, error);

  LEAVE();
}
Пример #5
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;
}
Пример #6
0
/**************************************************************************
 SavePrefsHeader: Write a PRHD chunk
**************************************************************************/
static int SavePrefsHeader(struct IFFHandle *iff)
{
    if (!PushChunk( iff, 0, MAKE_ID('P','R','H','D'), IFFSIZE_UNKNOWN))
    {
        struct PrefHeader ph;
        ph.ph_Version = 0;
        ph.ph_Type = 0;
        ph.ph_Flags = 0;

        if (WriteChunkBytes(iff, &ph, sizeof(struct PrefHeader)))
            if (!PopChunk(iff)) return 1;
        PopChunk(iff);
    }
    return 0;
}
Пример #7
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;
}
Пример #8
0
/*************
 * DESCRIPTION:   write camera to scene file
 * INPUT:         iff      iff handler
 * OUTPUT:        FALSE if failed else TRUE
 *************/
BOOL CAMERA::WriteObject(struct IFFHandle *iff)
{
	float data[2];

	if(PushChunk(iff, ID_CAMR, ID_FORM, IFFSIZE_UNKNOWN))
		return FALSE;

	if(!WriteCommon(iff))
		return FALSE;

	if(!WriteLongChunk(iff, ID_FDST, &focaldist, 1))
		return FALSE;

	if(!WriteLongChunk(iff, ID_APER, &aperture, 1))
		return FALSE;

	data[0] = hfov;
	data[1] = vfov;
	if(!WriteLongChunk(iff, ID_FDOV, data, 2))
		return FALSE;

	if(PopChunk(iff))
		return FALSE;

	return TRUE;
}
Пример #9
0
/*************
 * DESCRIPTION:   write texture to scene file
 * INPUT:         iff      iff handler
 * OUTPUT:        FALSE if failed else TRUE
 *************/
BOOL TEXTURE_OBJECT::WriteObject(struct IFFHandle *iff)
{
	VECTOR v[3];

	if(PushChunk(iff, ID_ITXT, ID_FORM, IFFSIZE_UNKNOWN))
		return FALSE;

	if(!WriteLongChunk(iff, ID_POSI, &pos, 3))
		return FALSE;

	v[0] = orient_x;
	v[1] = orient_y;
	v[2] = orient_z;
	if(!WriteLongChunk(iff, ID_ALGN, v, 9))
		return FALSE;

	if(!WriteLongChunk(iff, ID_SIZE, &size, 3))
		return FALSE;

	if(!WriteTrack(iff))
		return FALSE;

	if(!WriteFlags(iff))
		return FALSE;

	if(PopChunk(iff))
		return FALSE;

	return TRUE;
}
Пример #10
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;
		}
	}
}
Пример #11
0
ULONG WRITE_Frame(piClass *cl,piObject *o,struct piIO *msg)
{
	LONG error=0;
	struct Node_Frame *nf;

	piGetAttr(o,OBJ_Node,(ULONG *)&nf);
	if(error=PushChunk(msg->IFFh,NULL,ID_FRME,IFFSIZE_UNKNOWN)) return (ULONG)error;
	WriteChunkBytes(msg->IFFh,(APTR)&nf->nf_X,SIZE(Node_Frame,nf_X));
	if(error=PopChunk(msg->IFFh)) return (ULONG)error;
	return (ULONG)error;
}
Пример #12
0
void ClipInfo(struct line_node *line, struct InstData *data)
{
  LONG error;

  ENTER();

  if(line->line.Flow != MUIV_TextEditor_Flow_Left)
  {
    D(DBF_CLIPBOARD, "writing FLOW");
    error = PushChunk(data->iff, 0, ID_FLOW, IFFSIZE_UNKNOWN);
    SHOWVALUE(DBF_CLIPBOARD, error);
    error = WriteChunkBytes(data->iff, &line->line.Flow, 2);
    SHOWVALUE(DBF_CLIPBOARD, error);
    error = PopChunk(data->iff);
    SHOWVALUE(DBF_CLIPBOARD, error);
  }

  if(line->line.Separator)
  {
    D(DBF_CLIPBOARD, "writing SBAR");
    error = PushChunk(data->iff, 0, ID_SBAR, IFFSIZE_UNKNOWN);
    SHOWVALUE(DBF_CLIPBOARD, error);
    error = WriteChunkBytes(data->iff, &line->line.Separator, 2);
    SHOWVALUE(DBF_CLIPBOARD, error);
    error = PopChunk(data->iff);
    SHOWVALUE(DBF_CLIPBOARD, error);
  }

  if(line->line.Color)
  {
    D(DBF_CLIPBOARD, "writing HIGH");
    error = PushChunk(data->iff, 0, ID_HIGH, IFFSIZE_UNKNOWN);
    SHOWVALUE(DBF_CLIPBOARD, error);
    error = WriteChunkBytes(data->iff, &line->line.Color, 2);
    SHOWVALUE(DBF_CLIPBOARD, error);
    error = PopChunk(data->iff);
    SHOWVALUE(DBF_CLIPBOARD, error);
  }

  LEAVE();
}
Пример #13
0
BOOL PushStringChunk( struct IFFHandle *iff, LONG id, STRPTR txt)
{
	if(txt)
	{
		if(!PushChunk(iff,0,id,IFFSIZE_UNKNOWN))
		{
			WriteChunkBytes(iff,txt,strlen(txt));
			PopChunk(iff);
		}
	}
	return TRUE;
}
Пример #14
0
/*** Save a file where we found it, otherwise in ENVARC: ***/
UBYTE save_prefs(PREFS *prefs)
{
	APTR  file;
	UBYTE num, size;
	UBYTE NumField[2];
	if( (file = open_prefs(Path, MODE_SAVE)) )
	{
		if( !PushChunk(file, ID_PREF, ID_FORM, IFFSIZE_UNKNOWN) )
		{
			if( !PushChunk(file, ID_PREF, ID_JANO, IFFSIZE_UNKNOWN) )
			{	 
			    	if (Wnd)
				{
				    /* Save window dimension */
				    CopyMem(&Wnd->LeftEdge, &prefs->left, 4*sizeof(WORD));
				}
				else
				{
				    prefs->left = prefs->top = prefs->width = prefs->height = 0;
				}
				
				/* Write configuration file */
				for(num=0; num < MAX_NUMFIELD; num++) {
					register STRPTR src;
					size = sizefields[ num ];
					src  = (STRPTR)prefs + offsets[ num ];
					if(size == 0) src = *(STRPTR *)src, size = strlen(src)+1;

					NumField[0] = num; NumField[1] = size;
					if( WriteChunkBytes(file, NumField, 2) != 2   ||
					    WriteChunkBytes(file, src,   size) != size ) break;
				}
				PopChunk( file );
			}
			PopChunk( file );
		}
		close_prefs(file);
	}
	return 0;
}
Пример #15
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);
	}
}
Пример #16
0
/*************
 * DESCRIPTION:   write texture to scene file
 * INPUT:         iff      iff handler
 * OUTPUT:        FALSE if failed else TRUE
 *************/
BOOL HYPER_TEXTURE::Write(struct IFFHandle *iff)
{
	if(PushChunk(iff, ID_HTXT, ID_FORM, IFFSIZE_UNKNOWN))
		return FALSE;

	if(!WriteChunk(iff, ID_NAME, name, strlen(name)+1))
		return FALSE;

	if(PopChunk(iff))
		return FALSE;

	return TRUE;
}
Пример #17
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;
}
Пример #18
0
bool gui_add_to_clipboard(const char *text, size_t length, bool space)
{
	/* This might crash or at least not work if gui_empty_clipboard isn't called first,
	   and gui_commit_clipboard after.
	   These only seem to be called from desktop/textinput.c in this specific order, if they
	   are added elsewhere this might need a rewrite. */

	if(!(PushChunk(iffh,0,ID_CHRS,IFFSIZE_UNKNOWN)))
	{
		if(text)
		{
			if(!ami_add_to_clipboard(text, length, space)) return false;
		}

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

	return true;
}
Пример #19
0
ULONG WRITE_Gadget(piClass *cl,piObject *o,struct piIO *msg)
{
	LONG error=0,a;
	struct Node_Gadget *ng;
	struct GadToolsData *gtd;

	piGetAttr(o,OBJ_Node,(ULONG *)&ng);
	piGetAttr(o,GAOBJ_NodeData,(ULONG *)&gtd);
	if(error=PushChunk(msg->IFFh,NULL,ng->ng_PlugInID,IFFSIZE_UNKNOWN)) return (ULONG)error;
	WriteChunkBytes(msg->IFFh,(APTR)&ng->ng_X,SIZE(Node_Gadget,ng_X));
	for(a=0;a<ng->ng_NumTags;a++) WriteTagItem(msg->IFFh,&ng->ng_Tags[a],ng->ng_TagTypes[a]);
	for(a=0;a<ng->ng_NumOwnTags;a++) WriteTagItem(msg->IFFh,&ng->ng_OwnTags[a],ng->ng_OwnTagTypes[a]);
	if(ng->ng_Type==GTYPE_GADTOOLS) WriteChunkBytes(msg->IFFh,(APTR)gtd,sizeof(struct GadToolsData));
	if(error=PopChunk(msg->IFFh)) return (ULONG)error;
	return (ULONG)error;
}
Пример #20
0
/*************
 * DESCRIPTION:   write texture to scene file
 * INPUT:         iff      iff handler
 * OUTPUT:        FALSE if failed else TRUE
 *************/
BOOL IMAGINE_TEXTURE::Write(struct IFFHandle *iff)
{
	if(PushChunk(iff, ID_ITXT, ID_FORM, IFFSIZE_UNKNOWN))
		return FALSE;

	if(!WriteChunk(iff, ID_NAME, name, strlen(name)+1))
		return FALSE;

	if(!WriteLongChunk(iff, ID_PARM, &params, 16))
		return FALSE;

	if(PopChunk(iff))
		return FALSE;

	return TRUE;
}
Пример #21
0
/*************
 * DESCRIPTION:   write texture to scene file
 * INPUT:         iff      iff handler
 * OUTPUT:        FALSE if failed else TRUE
 *************/
BOOL RAYSTORM_TEXTURE::Write(struct IFFHandle *iff)
{
	if(PushChunk(iff, ID_RTXT, ID_FORM, IFFSIZE_UNKNOWN))
		return FALSE;

	if(!WriteChunk(iff, ID_NAME, name, strlen(name)+1))
		return FALSE;

	if(!WriteChunk(iff, ID_PARM, data, datasize))
		return FALSE;

	if(PopChunk(iff))
		return FALSE;

	return TRUE;
}
Пример #22
0
/*************
 * DESCRIPTION:   write sphere to scene file
 * INPUT:         iff      iff handler
 * OUTPUT:        FALSE if failed else TRUE
 *************/
BOOL SPHERE::WriteObject(struct IFFHandle *iff)
{
	if(PushChunk(iff, ID_SPHR, ID_FORM, IFFSIZE_UNKNOWN))
		return FALSE;

	if(!WriteCommon(iff))
		return FALSE;

	if(!WriteSurface(iff))
		return FALSE;

	if(PopChunk(iff))
		return FALSE;

	return TRUE;
}
Пример #23
0
/*************
 * DESCRIPTION:   write brush to scene file
 * INPUT:         iff      iff handle
 * OUTPUT:        FALSE if failed else TRUE
 *************/
BOOL BRUSH::Write(struct IFFHandle *iff)
{
	if(PushChunk(iff, ID_BRSH, ID_FORM, IFFSIZE_UNKNOWN))
		return FALSE;

	if(!WriteChunk(iff, ID_NAME, file, strlen(file)+1))
		return FALSE;

	if(!WriteLongChunk(iff, ID_FLGS, &flags, 1))
		return FALSE;

	if(!WriteLongChunk(iff, ID_TYPE, &type, 1))
		return FALSE;

	if(!WriteLongChunk(iff, ID_WRAP, &wrap, 1))
		return FALSE;

	if(PopChunk(iff))
		return FALSE;

	return TRUE;
}
Пример #24
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;
}
Пример #25
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);
}
Пример #26
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;    
}
Пример #27
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;
}
Пример #28
0
static void
writeDatabaseFile(Entries entries, struct IFFHandle *iff)
{
   Automatic nextFreeAuto = NULL;
   Entry nextFreeEntry = NULL;
   DataBase db;
   int j;

   PushChunk(iff, ID_FTXT, ID_FORM, IFFSIZE_UNKNOWN);

/* Write the automatic entries */
   PushChunk(iff, 0, ID_AUTO, IFFSIZE_UNKNOWN);
   j = 0;
   db = (DataBase) entries -> automatic;
   DB_Rewind(db);
   while ((nextFreeAuto = DB_NextEntry(db))) {
      struct DateStamp *ds;

   /* skip to the next free entry */
      ds = & nextFreeAuto -> first;
      WriteChunkBytes(iff, & ds -> ds_Days, sizeof(LONG));
      WriteChunkBytes(iff, & ds -> ds_Minute, sizeof(LONG));
      WriteChunkBytes(iff, & ds -> ds_Tick, sizeof(LONG));

      ds = & nextFreeAuto -> last;
      WriteChunkBytes(iff, & ds -> ds_Days, sizeof(LONG));
      WriteChunkBytes(iff, & ds -> ds_Minute, sizeof(LONG));
      WriteChunkBytes(iff, & ds -> ds_Tick, sizeof(LONG));

      WriteChunkBytes(iff, & nextFreeAuto -> repeatDays, sizeof(ULONG));
      WriteChunkBytes(iff, & nextFreeAuto -> repeatWeeks, sizeof(ULONG));
      WriteChunkBytes(iff, & nextFreeAuto -> repeatMonths, sizeof(ULONG));
      WriteChunkBytes(iff, & nextFreeAuto -> repeatYears, sizeof(ULONG));
      WriteChunkBytes(iff, nextFreeAuto -> amount, AMOUNTL);
      WriteChunkBytes(iff, nextFreeAuto -> transaction, TRANSACTIONL);
      WriteChunkBytes(iff, nextFreeAuto -> imputation, IMPUTATIONL);
   }
   PopChunk(iff);   /* AUTO */

/* Write the regular database */
   PushChunk(iff, 0, ID_CHRS, IFFSIZE_UNKNOWN);
   j = 0;
   db = (DataBase) entries -> list;
   DB_Rewind(db);
   while ((nextFreeEntry = DB_NextEntry(db))) {
      struct DateStamp *ds = & nextFreeEntry -> date;

      if (! nextFreeEntry -> fake) {  /* only save regular entries, not auto */
         WriteChunkBytes(iff, & ds -> ds_Days, sizeof(LONG));
         WriteChunkBytes(iff, & ds -> ds_Minute, sizeof(LONG));
         WriteChunkBytes(iff, & ds -> ds_Tick, sizeof(LONG));

         WriteChunkBytes(iff, nextFreeEntry -> transaction, TRANSACTIONL);
         WriteChunkBytes(iff, nextFreeEntry -> amount, AMOUNTL);
         WriteChunkBytes(iff, nextFreeEntry -> checkNumber, CHECKNUMBERL);
         WriteChunkBytes(iff, nextFreeEntry -> imputation, IMPUTATIONL);
         WriteChunkBytes(iff, nextFreeEntry -> reason, REASONL);
         WriteChunkBytes(iff, & nextFreeEntry -> validated, 4);
      }
   }
   PopChunk(iff);   /* CHRS */

   PopChunk(iff);   /* FTXT */
}
Пример #29
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 );
}
Пример #30
0
/*************
 * DESCRIPTION:   write surface to scene file
 * INPUT:         iff      iff handler
 * OUTPUT:        FALSE if failed else TRUE
 *************/
BOOL SURFACE::Write(struct IFFHandle *iff)
{
	TEXTURE *texture;
	BRUSH *brush;

	if(PushChunk(iff, ID_SURF, ID_FORM, IFFSIZE_UNKNOWN))
		return FALSE;

	if(name)
	{
		if(!WriteChunk(iff, ID_NAME, name, strlen(name)+1))
			return FALSE;
	}

	if(!WriteLongChunk(iff, ID_FLGS, &flags, 1))
		return FALSE;

	if(!WriteLongChunk(iff, ID_AMBT, &ambient, 3))
		return FALSE;

	if(!WriteLongChunk(iff, ID_DIFU, &diffuse, 3))
		return FALSE;

	if(!WriteLongChunk(iff, ID_SPEC, &specular, 3))
		return FALSE;

	if(!WriteLongChunk(iff, ID_REFL, &reflect, 3))
		return FALSE;

	if(!WriteLongChunk(iff, ID_TRNS, &transpar, 3))
		return FALSE;

	if(!WriteLongChunk(iff, ID_DIFT, &difftrans, 3))
		return FALSE;

	if(!WriteLongChunk(iff, ID_SPCT, &spectrans, 3))
		return FALSE;

	if(!WriteLongChunk(iff, ID_RPHG, &refphong, 1))
		return FALSE;

	if(!WriteLongChunk(iff, ID_TPHG, &transphong, 1))
		return FALSE;

	if(!WriteLongChunk(iff, ID_FLEN, &foglength, 1))
		return FALSE;

	if(!WriteLongChunk(iff, ID_IXOR, &refrindex, 1))
		return FALSE;

	if(!WriteLongChunk(iff, ID_TNSL, &translucency, 1))
		return FALSE;

	texture = this->texture;
	while(texture)
	{
		texture->Write(iff);
		texture = (TEXTURE*)texture->GetNext();
	}

	brush = this->brush;
	while(brush)
	{
		brush->Write(iff);
		brush = (BRUSH*)brush->GetNext();
	}

	if(PopChunk(iff))
		return FALSE;

	return TRUE;
}