示例#1
0
IO_stat MCCdata::save(IO_handle stream, Object_type type, uint4 p_part)
{
	IO_stat stat;

	// If p_part is non-zero it means we only want to save data specific
	// to a given card. In this case, we simply don't save the rest.
	if (p_part != 0 && id != p_part)
		return IO_NORMAL;

	if ((stat = IO_write_uint1(type, stream)) != IO_NORMAL)
		return stat;
	if ((stat = IO_write_uint4(p_part != 0 ? 0 : id, stream)) != IO_NORMAL)
		return stat;
	if (type == OT_BDATA)
	{
		uint1 set = data ? 1 : 0;
		return IO_write_uint1(set, stream);
	}
	else
		if (id & COMPACT_PARAGRAPHS)
			return IO_write_string((char *)data, stream, sizeof(uint1));
		else
		{
			MCParagraph *tptr = (MCParagraph *)data;
			if (tptr != NULL)
				do
				{
					if ((stat = tptr->save(stream, p_part)) != IO_NORMAL)
						return stat;
					tptr = (MCParagraph *)tptr->next();
				}
				while (tptr != data);
		}
	return IO_NORMAL;
}
示例#2
0
IO_stat MCLogicalFontTableSave(IO_handle p_stream)
{
	IO_stat t_stat;
	t_stat = IO_NORMAL;

	if (t_stat == IO_NORMAL)
		t_stat = IO_write_uint2(s_logical_font_table_size, p_stream);
	
	if (t_stat == IO_NORMAL)
		for(uint32_t i = 0; i < s_logical_font_table_size && t_stat == IO_NORMAL; i++)
		{
			MCNameRef t_textfont;
			uint2 t_textstyle;
			uint2 t_textsize;
			bool t_is_unicode;
			MCLogicalFontTableGetEntry(i, t_textfont, t_textstyle, t_textsize, t_is_unicode);

			if (t_textfont == nil)
				t_textfont = kMCEmptyName;

			t_stat = IO_write_uint2(t_textsize, p_stream);
			if (t_stat == IO_NORMAL)
				t_stat = IO_write_uint2(t_textstyle, p_stream);
			if (t_stat == IO_NORMAL)
			{
				if (t_is_unicode)
				{
					char *t_unicode_textfont;
					t_unicode_textfont = new char[strlen(MCNameGetCString(t_textfont)) + 9];
					strcpy(t_unicode_textfont, MCNameGetCString(t_textfont));
					strcat(t_unicode_textfont, ",unicode");
					t_stat = IO_write_string(t_unicode_textfont, p_stream);
					delete t_unicode_textfont;
				}
				else
					t_stat = IO_write_string(MCNameGetCString(t_textfont), p_stream);
			}
		}

	return t_stat;
}
示例#3
0
文件: eps.cpp 项目: Bjoernke/livecode
IO_stat MCEPS::save(IO_handle stream, uint4 p_part, bool p_force_ext)
{
	IO_stat stat;

	if ((stat = IO_write_uint1(OT_MCEPS, stream)) != IO_NORMAL)
		return stat;
	if ((stat = MCObject::save(stream, p_part, p_force_ext)) != IO_NORMAL)
		return stat;
	if ((stat = IO_write_uint4(size, stream)) != IO_NORMAL)
		return stat;
	if ((stat = IO_write(postscript, sizeof(char), size, stream)) != IO_NORMAL)
		return stat;
	if ((stat = IO_write_string(prolog, stream)) != IO_NORMAL)
		return stat;
	if ((stat = IO_write_int4(MCU_r8toi4(xscale), stream)) != IO_NORMAL)
		return stat;
	if (flags & F_SCALE_INDEPENDENTLY)
		if ((stat = IO_write_int4(MCU_r8toi4(yscale), stream)) != IO_NORMAL)
			return stat;
	if ((stat = IO_write_int2(angle, stream)) != IO_NORMAL)
		return stat;
	if ((stat = IO_write_int2(tx, stream)) != IO_NORMAL)
		return stat;
	if ((stat = IO_write_int2(ty, stream)) != IO_NORMAL)
		return stat;
	if ((stat = IO_write_uint2(ex, stream)) != IO_NORMAL)
		return stat;
	if ((stat = IO_write_uint2(ey, stream)) != IO_NORMAL)
		return stat;
	if (flags & F_RETAIN_IMAGE)
		if ((stat = image->save(stream, p_part, p_force_ext)) != IO_NORMAL)
			return stat;
	if ((stat = IO_write_uint2(curpage, stream)) != IO_NORMAL)
		return stat;
	if ((stat = IO_write_uint2(pagecount, stream)) != IO_NORMAL)
		return stat;
	uint2 i;
	for (i = 0 ; i < pagecount ; i++)
		if ((stat = IO_write_uint4(pageIndex[i], stream)) != IO_NORMAL)
			return stat;
	return savepropsets(stream);
}
示例#4
0
IO_stat IO_write_string(const char *string, uint4 outlen, IO_handle stream,
                        Boolean isunicode, uint1 size)
{
	IO_stat stat = IO_NORMAL;
	if (isunicode)
	{
		uint16_t *t_uniptr = (uint16_t*)string;
		uint32_t t_len = outlen / 2;
		while (t_len--)
			swap_uint2(t_uniptr++);
	}
	stat = IO_write_string(MCString(string, outlen), stream, size, true);
	if (isunicode)
	{
		uint16_t *t_uniptr = (uint16_t*)string;
		uint32_t t_len = outlen / 2;
		while (t_len--)
			swap_uint2(t_uniptr++);
	}
	
	return stat;
}
示例#5
0
IO_stat IO_write_nameref(MCNameRef p_name, IO_handle stream, uint1 size)
{
	// MW-2011-10-21: [[ Bug 9826 ]] If the name is empty, write out nil string.
	return IO_write_string(MCNameIsEmpty(p_name) ? nil : MCNameGetCString(p_name), stream, size);
}
示例#6
0
IO_stat IO_write_string(const char *string, IO_handle stream, uint1 size)
{
	return IO_write_string(MCString(string), stream, size);
}
示例#7
0
IO_stat MCDispatch::dosavestack(MCStack *sptr, const MCString &fname)
{
	if (MCModeCheckSaveStack(sptr, fname) != IO_NORMAL)
		return IO_ERROR;
	
	char *linkname;
	if (fname.getlength() != 0)
		linkname = fname.clone();
	else
		if ((linkname = strclone(sptr->getfilename())) == NULL)
		{
			MCresult->sets("stack does not have a filename");
			return IO_ERROR;
		}
	if (linkname == NULL)
	{
		MCresult->sets("can't open stack file, bad path");
		return IO_ERROR;
	}
	if (MCS_noperm(linkname))
	{
		MCresult->sets("can't open stack file, no permission");
		delete linkname;
		return IO_ERROR;
	}
	char *oldfiletype = MCfiletype;
	MCfiletype = MCstackfiletype;
	char *backup = new char[strlen(linkname) + 2];
	strcpy(backup, linkname);
	strcat(backup, "~");
	MCS_unlink(backup);
	if (MCS_exists(linkname, True) && !MCS_backup(linkname, backup))
	{
		MCresult->sets("can't open stack backup file");
		MCfiletype = oldfiletype;
		delete linkname;
		delete backup;
		return IO_ERROR;
	}
	IO_handle stream;
	if ((stream = MCS_open(linkname, IO_WRITE_MODE, True, False, 0)) == NULL)
	{
		MCresult->sets("can't open stack file");
		cleanup(stream, linkname, backup);
		MCfiletype = oldfiletype;
		return IO_ERROR;
	}
	MCfiletype = oldfiletype;
	MCString errstring = "Error writing stack (disk full?)";
	
	// MW-2012-03-04: [[ StackFile5500 ]] Work out what header to emit, and the size.
	const char *t_header;
	uint32_t t_header_size;
	if (MCstackfileversion >= 5500)
		t_header = newheader5500, t_header_size = 8;
	else if (MCstackfileversion >= 2700)
		t_header = newheader, t_header_size = 8;
	else
		t_header = header, t_header_size = HEADERSIZE;
	
	if (IO_write(t_header, sizeof(char), t_header_size, stream) != IO_NORMAL
	        || IO_write_uint1(CHARSET, stream) != IO_NORMAL)
	{
		MCresult->sets(errstring);
		cleanup(stream, linkname, backup);
		return IO_ERROR;
	}

	if (IO_write_uint1(OT_NOTHOME, stream) != IO_NORMAL
	        || IO_write_string(NULL, stream) != IO_NORMAL)
	{ // was stackfiles
		MCresult->sets(errstring);
		cleanup(stream, linkname, backup);
		return IO_ERROR;
	}
	
	// MW-2012-02-22; [[ NoScrollSave ]] Adjust the rect by the current group offset.
	MCgroupedobjectoffset . x = 0;
	MCgroupedobjectoffset . y = 0;
	
	MCresult -> clear();
	if (sptr->save(stream, 0, false) != IO_NORMAL
	        || IO_write_uint1(OT_END, stream) != IO_NORMAL)
	{
		if (MCresult -> isclear())
			MCresult->sets(errstring);
		cleanup(stream, linkname, backup);
		return IO_ERROR;
	}
	MCS_close(stream);
	uint2 oldmask = MCS_umask(0);
	uint2 newmask = ~oldmask & 00777;
	if (oldmask & 00400)
		newmask &= ~00100;
	if (oldmask & 00040)
		newmask &= ~00010;
	if (oldmask & 00004)
		newmask &= ~00001;
	MCS_umask(oldmask);
	MCS_chmod(linkname, newmask);
	if (sptr->getfilename() != NULL && !strequal(linkname, sptr->getfilename()))
		MCS_copyresourcefork(sptr->getfilename(), linkname);
	else if (sptr -> getfilename() != NULL)
		MCS_copyresourcefork(backup, linkname);
	sptr->setfilename(linkname);
	if (backup != NULL)
	{
		MCS_unlink(backup);
		delete backup;
	}
	return IO_NORMAL;
}