Beispiel #1
0
IO_stat MCCdata::load(IO_handle stream, MCObject *parent, const char *version)
{
	IO_stat stat;

	if ((stat = IO_read_uint4(&id, stream)) != IO_NORMAL)
		return stat;
	if (parent->gettype() == CT_BUTTON)
	{
		uint1 set;
		stat = IO_read_uint1(&set, stream);
		data = (void *)(set ? 1 : 0);
		return stat;
	}
	else
	{
		if (id & COMPACT_PARAGRAPHS)
		{
			char *string;
			if ((stat = IO_read_string(string, stream, sizeof(uint1))) != IO_NORMAL)
				return stat;
			data = string;
		}
		else
		{
			MCParagraph *paragraphs = NULL;
			while (True)
			{
				uint1 type;
				if ((stat = IO_read_uint1(&type, stream)) != IO_NORMAL)
					return stat;
				switch (type)
				{
				// MW-2012-03-04: [[ StackFile5500 ]] Handle either the paragraph or extended
				//   paragraph tag.
				case OT_PARAGRAPH:
				case OT_PARAGRAPH_EXT:
					{
						MCParagraph *newpar = new MCParagraph;
						newpar->setparent((MCField *)parent);
						
						// MW-2012-03-04: [[ StackFile5500 ]] If the paragraph tab was the extended
						//   variant, then pass the correct is_ext parameter.
						if ((stat = newpar->load(stream, version, type == OT_PARAGRAPH_EXT)) != IO_NORMAL)
						{
							delete newpar;
							return stat;
						}
						newpar->appendto(paragraphs);
					}
					break;
				default:
					data = paragraphs;
					MCS_seek_cur(stream, -1);
					return IO_NORMAL;
				}
			}
		}
	}
	return IO_NORMAL;
}
Beispiel #2
0
IO_stat IO_fgets(char *ptr, uint4 length, IO_handle stream)
{
	uint4 bytes = length;
	if (MCS_read(ptr, sizeof(uint1), bytes, stream) == IO_ERROR)
		return IO_ERROR;
	ptr[bytes - 1] = '\0';
	strtok(ptr, "\n");
	length = strlen(ptr) + 1;
	if (length != bytes)
		if (MCS_seek_cur(stream, length - bytes) != IO_NORMAL)
			return IO_ERROR;
	return IO_NORMAL;
}
Beispiel #3
0
IO_stat MCStyledText::load(IO_handle p_stream, const char *p_version)
{
	IO_stat stat;
	MCParagraph *paragraphs = NULL;
	while (True)
	{
		uint1 type;
		if ((stat = IO_read_uint1(&type, p_stream)) != IO_NORMAL)
			return stat;
		switch (type)
		{
		// MW-2012-03-04: [[ StackFile5500 ]] Handle both the paragraph and extended
		//   paragraph record.
		case OT_PARAGRAPH:
		case OT_PARAGRAPH_EXT:
			{
				MCParagraph *newpar = new MCParagraph;
				newpar->setparent((MCField *)parent);
				
				// MW-2012-03-04: [[ StackFile5500 ]] If the record is extended then
				//   pass in 'true' for 'is_ext'.
				if ((stat = newpar->load(p_stream, p_version, type == OT_PARAGRAPH_EXT)) != IO_NORMAL)
				{
					delete newpar;
					return stat;
				}

				newpar->appendto(paragraphs);
			}
			break;
		default:
			m_paragraphs = paragraphs;
			MCS_seek_cur(p_stream, -1);
			return IO_NORMAL;
		}
	}
	return IO_NORMAL;
}
Beispiel #4
0
IO_stat MCCdata::load(IO_handle stream, MCObject *parent, uint32_t version)
{
	IO_stat stat;

	if ((stat = IO_read_uint4(&id, stream)) != IO_NORMAL)
		return checkloadstat(stat);
	if (parent->gettype() == CT_BUTTON)
	{
		uint1 set;
		stat = IO_read_uint1(&set, stream);
		data = reinterpret_cast<void *>(set ? 1 : 0);
		return checkloadstat(stat);
	}
	else
	{
		if (id & COMPACT_PARAGRAPHS)
		{
			// MW-2013-11-19: [[ UnicodeFileFormat ]] This flag is never set by newer engines
			//   so is just legacy.
			char *string;
			if ((stat = IO_read_cstring_legacy(string, stream, sizeof(uint1))) != IO_NORMAL)
				return checkloadstat(stat);
			data = string;
		}
		else
		{
			MCParagraph *paragraphs = NULL;
			while (True)
			{
				uint1 type;
				if ((stat = IO_read_uint1(&type, stream)) != IO_NORMAL)
					return checkloadstat(stat);
				switch (type)
				{
				// MW-2012-03-04: [[ StackFile5500 ]] Handle either the paragraph or extended
				//   paragraph tag.
				case OT_PARAGRAPH:
				case OT_PARAGRAPH_EXT:
					{
						MCParagraph *newpar = new (nothrow) MCParagraph;
						newpar->setparent((MCField *)parent);
						
						// MW-2012-03-04: [[ StackFile5500 ]] If the paragraph tab was the extended
						//   variant, then pass the correct is_ext parameter.
						if ((stat = newpar->load(stream, version, type == OT_PARAGRAPH_EXT)) != IO_NORMAL)
						{
							delete newpar;
							return checkloadstat(stat);
						}
						newpar->appendto(paragraphs);
					}
					break;
				default:
					data = paragraphs;
					MCS_seek_cur(stream, -1);
					return IO_NORMAL;
				}
			}
		}
	}
	return IO_NORMAL;
}
Beispiel #5
0
// if the image is in a directly supported format return the raw data otherwise decode & return the bitmap
bool MCImageImport(IO_handle p_stream, IO_handle p_mask_stream, MCPoint &r_hotspot, char *&r_name, MCImageCompressedBitmap *&r_compressed, MCImageBitmap *&r_bitmap)
{
	bool t_success = true;

	uindex_t t_width = 0, t_height = 0;

	uint8_t t_head[8];
	uindex_t t_size = 8;

	uint32_t t_compression = F_RLE;

	if (t_success)
		t_success = MCS_read(t_head, sizeof(uint8_t), t_size, p_stream) == IO_NORMAL &&
		t_size == 8 && MCS_seek_cur(p_stream, -8) == IO_NORMAL;

	if (t_success)
	{
		if (memcmp(t_head, "GIF87a", 6) == 0)
			t_compression = F_GIF;
		else if (memcmp(t_head, "GIF89a", 6) == 0)
			t_compression = F_GIF;
		else if (memcmp(t_head, "\211PNG", 4) == 0)
			t_compression = F_PNG;
		else if (memcmp(t_head, "\xff\xd8", 2) == 0)
			t_compression = F_JPEG;
		else if (MCImageGetMetafileGeometry(p_stream, t_width, t_height))
			t_compression = F_PICT;

		if (t_compression != F_RLE)
		{
			t_success = MCImageCreateCompressedBitmap(t_compression, r_compressed);
			if (t_success)
			{
				if (t_success)
					t_success = read_all(p_stream, r_compressed->data, r_compressed->size);

				r_compressed->width = t_width;
				r_compressed->height = t_height;
			}
		}
		else
		{
			MCImageBitmap *t_bitmap = nil;
			
			if (memcmp(t_head, "BM", 2) == 0)
				t_success = MCImageDecodeBMP(p_stream, r_hotspot, t_bitmap);
			else if (memcmp(t_head, "#define", 7) == 0)
				t_success = MCImageDecodeXBM(p_stream, r_hotspot, r_name, t_bitmap);
			else if (memcmp(t_head, "/* XPM", 6) == 0)
				t_success = MCImageDecodeXPM(p_stream, t_bitmap);
			else if (t_head[0] == 'P' && (t_head[1] >= '1' && t_head[1] <= '6'))
			{
				t_success = MCImageDecodeNetPBM(p_stream, t_bitmap);
				// may have a mask image
				if (t_success && p_mask_stream != nil)
				{
					MCImageBitmap *t_mask = nil;
					t_success = MCImageDecodeNetPBM(p_mask_stream, t_mask) &&
						MCImageBitmapApplyMask(t_bitmap, t_mask);
					MCImageFreeBitmap(t_mask);
				}
			}
			else // if all else fails, assume it's an XWD
				t_success = MCImageDecodeXWD(p_stream, r_name, t_bitmap);

			if (t_success)
				r_bitmap = t_bitmap;
			else
				MCImageFreeBitmap(t_bitmap);
		}
	}

	return t_success;
}
Beispiel #6
0
IO_stat MCParagraph::load(IO_handle stream, const char *version)
{
	IO_stat stat;
	stat = IO_NORMAL;

	if (stat == IO_NORMAL)
		stat = IO_read_uint2(&m_text_size, stream);

	if (m_text_size == 1)
	{
		if (stat == IO_NORMAL)
		{
			char t_temp;
			uint4 t_temp_count;
			t_temp_count = 1;
			stat = IO_read(&t_temp, sizeof(uint1), t_temp_count, stream);
		}

		if (stat == IO_NORMAL)
			m_text_size = 0;
	}
	else if (m_text_size > 1)
	{
		if (stat == IO_NORMAL)
		{
			m_text = malloc(m_text_size);
			if (m_text == NULL)
				stat = IO_ERROR;
		}

		if (stat == IO_NORMAL)
		{
			uint4 t_temp_text_size;
			t_temp_text_size = m_text_size;
			stat = IO_read(m_text, sizeof(uint1), t_temp_text_size, stream);
		}

		if (stat == IO_NORMAL)
		{
			if (MCencryptstring != NULL)
				MCX_passde((char *)m_text, MCencryptstring, m_text_size);

			m_text_size -= 1;
		}
	}

	while(stat == IO_NORMAL)
	{
		uint1 t_type;
		stat = IO_read_uint1(&t_type, stream);
		if (stat != IO_NORMAL)
			break;

		uint4 t_block_offset, t_block_length, t_block_style;
		stat = load_block(stream, version, t_block_offset, t_block_length, t_block_style);
		if (stat != IO_NORMAL)
			break;

		// Make sure the block doesn't overrun the text buffer (shouldn't ever be
		// necessary...)
		t_block_length = MCU_min(m_text_size - t_block_offset, t_block_length);

		// Byte-swap the text to native byte-order if its unicode, otherwise translate
		// Mac<->ISO if necessary.
		const MCParagraphCharStyle *t_style_info;
		t_style_info = FetchCharStyle(t_block_style);
		if (t_style_info -> is_unicode)
		{
			uint4 t_length;
			t_length = t_block_length / 2;

			uint2 *t_ptr;
			t_ptr = (uint2 *)((uint1 *)m_text + t_block_offset);

			for(; t_length > 0; t_length -= 1)
				swap_uint2(t_ptr++);
		}
		else if (MCtranslatechars)
		{
#ifdef _MACOSX
			IO_iso_to_mac((char *)m_text + t_block_offset, t_block_length);
#else
			IO_mac_to_iso((char *)m_text + t_block_offset, t_block_length);
#endif
		}

		// Replace the style in the given range with the style
		ReplaceStyles(t_block_offset, t_block_length, t_block_style);
	}

	if (stat == IO_NORMAL)
	{
		// If no styles were applied, we need to translate the text
		if (m_styles_size == 0 && MCtranslatechars && m_text_size > 0)
#ifdef _MACOSX
			IO_iso_to_mac((char *)m_text, m_text_size);
#else
			IO_mac_to_iso((char *)m_text, m_text_size);
#endif

		Compact();

		MCS_seek_cur(stream, -1);
	}

	return stat;
}