예제 #1
0
파일: main.c 프로젝트: mikey-austin/freedcc
int
main(int argc, char **argv)
{
    DCC_packet_T packet;

    Sys_init();
    Scheduler_module_init();
    IO_module_init();

    /* Enable interrupts. */
    sei();

    /* Power on LED. */
    LED1_ON;
    
    for(;;)
    {
        if((packet = IO_read()) != NULL)
        {
            Scheduler_add_packet(packet);
        }
    }

    return 0;
}
예제 #2
0
파일: vclip.cpp 프로젝트: Bjoernke/livecode
IO_stat MCVideoClip::load(IO_handle stream, const char *version)
{
	IO_stat stat;

	if ((stat = MCObject::load(stream, version)) != IO_NORMAL)
		return stat;
	if ((stat = IO_read_uint4(&size, stream)) != IO_NORMAL)
		return stat;
	if (size != 0)
	{
		frames = new uint1[size];
		if ((stat = IO_read(frames, sizeof(uint1), size, stream)) != IO_NORMAL)
			return stat;
	}
	if (flags & F_FRAME_RATE)
		if ((stat = IO_read_uint2(&framerate, stream)) != IO_NORMAL)
			return stat;
	if (flags & F_SCALE_FACTOR)
	{
		int4 i;
		if ((stat = IO_read_int4(&i, stream)) != IO_NORMAL)
			return stat;
		scale = MCU_i4tor8(i);
	}
	return loadpropsets(stream);
}
예제 #3
0
파일: eps.cpp 프로젝트: alilloyd/livecode
Boolean MCEPS::import(MCStringRef fname, IO_handle stream)
{
	size = (uint4)MCS_fsize(stream);
	delete postscript;
	postscript = new char[size + 1];
	if (IO_read(postscript, size, stream) != IO_NORMAL)
		return False;
	postscript[size] = '\0';
	uindex_t t_sep;
    MCStringRef t_fname;
    if (MCStringLastIndexOfChar(fname, PATH_SEPARATOR, UINDEX_MAX, kMCCompareExact, t_sep))
        /* UNCHECKED */ MCStringCopySubstring(fname, MCRangeMake(t_sep + 1, MCStringGetLength(fname) - (t_sep + 1)), t_fname);
    else
        t_fname = MCValueRetain(fname);
    
    MCNewAutoNameRef t_name;
    if (!MCNameCreateAndRelease(t_fname, &t_name))
        return False;
    setname(*t_name);
	setextents();
	rect.width = (uint2)(ex * xscale / xf);
	rect.height = (uint2)(ey * yscale / yf);
	if (flags & F_SHOW_BORDER)
	{
		rect.width += borderwidth << 1;
		rect.height += borderwidth << 1;
	}
	return True;
}
예제 #4
0
//LUDO:
static inline UChar get_8bit_addr(UInt16 addr) {
  register unsigned short int memreg = addr>>13;

  if (PageR[memreg] == IOAREA)
    return(IO_read(addr));
  else
    return((UChar) (PageR[memreg][addr]));
}
예제 #5
0
파일: ipng.cpp 프로젝트: Bjoernke/livecode
extern "C" void stream_read(png_structp png_ptr, png_bytep data, png_size_t length)
{
	IO_handle t_stream = (IO_handle)png_get_io_ptr(png_ptr);

	uint4 t_length;
	t_length = length;
	if (IO_read(data, sizeof(uint1), t_length, t_stream) != IO_NORMAL)
		png_error(png_ptr, (char *)"pnglib read error");
}
예제 #6
0
IO_stat readheader(IO_handle& stream, char *version)
{
	char tnewheader[NEWHEADERSIZE];
	uint4 size = NEWHEADERSIZE;

	if (IO_read(tnewheader, sizeof(char), size, stream) == IO_NORMAL)
	{
		// MW-2012-03-04: [[ StackFile5500 ]] Check for either the 2.7 or 5.5 header.
		if (strncmp(tnewheader, newheader, NEWHEADERSIZE) == 0 ||
			strncmp(tnewheader, newheader5500, NEWHEADERSIZE) == 0)
		{
			sprintf(version, "%c.%c.%c.%c", tnewheader[4], tnewheader[5], tnewheader[6], tnewheader[7]);
			if (tnewheader[7] == '0')
			{
				version[5] = '\0';
				if (tnewheader[6] == '0')
					version[3] = '\0';
			}
		}
		else
		{
			char theader[HEADERSIZE + 1];
			uint4 size = HEADERSIZE - NEWHEADERSIZE;
			theader[HEADERSIZE] = '\0';
			uint4 offset;
			strncpy(theader, tnewheader, NEWHEADERSIZE);
			if (IO_read(theader + NEWHEADERSIZE, sizeof(char), size, stream) == IO_NORMAL
		        && MCU_offset(SIGNATURE, theader, offset))
			{
				if (theader[offset - 1] != '\n' || theader[offset - 2] == '\r')
				{
					MCresult->sets("stack was corrupted by a non-binary file transfer");
					return IO_ERROR;
				}

				strncpy(version, &theader[offset + VERSION_OFFSET], 3);
				version[3] = '\0';
			}
			else
				return IO_ERROR;
		}
	}
	return IO_NORMAL;
}
예제 #7
0
파일: eps.cpp 프로젝트: Bjoernke/livecode
Boolean MCEPS::import(char *fname, IO_handle stream)
{
	size = (uint4)MCS_fsize(stream);
	delete postscript;
	postscript = new char[size + 1];
	if (IO_read(postscript, sizeof(char), size, stream) != IO_NORMAL)
		return False;
	postscript[size] = '\0';
	const char *tname = strrchr(fname, PATH_SEPARATOR);
	if (tname != NULL)
		tname += 1;
	else
		tname = fname;
	setname_cstring(tname);
	setextents();
	rect.width = (uint2)(ex * xscale / xf);
	rect.height = (uint2)(ey * yscale / yf);
	if (flags & F_SHOW_BORDER)
	{
		rect.width += borderwidth << 1;
		rect.height += borderwidth << 1;
	}
	return True;
}
예제 #8
0
		bool ReadBytes(void *p_buffer, uint32_t p_count)
		{
			return IO_read(p_buffer, p_count, handle) == IO_NORMAL;

		}
예제 #9
0
파일: eps.cpp 프로젝트: alilloyd/livecode
IO_stat MCEPS::load(IO_handle stream, uint32_t version)
{
	IO_stat stat;

	if ((stat = MCObject::load(stream, version)) != IO_NORMAL)
		return stat;
	delete postscript;
	delete prolog;
	if ((stat = IO_read_uint4(&size, stream)) != IO_NORMAL)
		return stat;
	postscript = new char[size + 1];
	if ((stat = IO_read(postscript, size, stream)) != IO_NORMAL)
		return stat;
	postscript[size] = '\0';
	// MW-2013-11-19: [[ UnicodeFileFormat ]] EPS is always ASCII so legacy.
	if ((stat = IO_read_cstring_legacy(prolog, stream, 2)) != IO_NORMAL)
		return stat;
	int4 i;
	if ((stat = IO_read_int4(&i, stream)) != IO_NORMAL)
		return stat;
	xscale = MCU_i4tor8(i);
	if (flags & F_SCALE_INDEPENDENTLY)
	{
		if ((stat = IO_read_int4(&i, stream)) != IO_NORMAL)
			return stat;
		yscale = MCU_i4tor8(i);
	}
	else
		yscale = xscale;
	if ((stat = IO_read_int2(&angle, stream)) != IO_NORMAL)
		return stat;
	if ((stat = IO_read_int2(&tx, stream)) != IO_NORMAL)
		return stat;
	if ((stat = IO_read_int2(&ty, stream)) != IO_NORMAL)
		return stat;
	if ((stat = IO_read_uint2(&ex, stream)) != IO_NORMAL)
		return stat;
	if ((stat = IO_read_uint2(&ey, stream)) != IO_NORMAL)
		return stat;
	if (flags & F_RETAIN_IMAGE)
	{
		image = new MCImage;
		image->setparent(this);
		if ((stat = image->load(stream, version)) != IO_NORMAL)
			return stat;
	}
	if (version > 1300)
	{
		if ((stat = IO_read_uint2(&curpage, stream)) != IO_NORMAL)
			return stat;
		if ((stat = IO_read_uint2(&pagecount, stream)) != IO_NORMAL)
			return stat;
		if (pagecount > 0)
		{
			pageIndex = new uint4[pagecount];
			for (i = 0 ; i < pagecount ; i++)
				if ((stat = IO_read_uint4(&pageIndex[i], stream)) != IO_NORMAL)
					return stat;
		}
	}
	return loadpropsets(stream, version);
}
예제 #10
0
// MW-2012-02-17: [[ LogFonts ]] Actually load the stack file (wrapped by readfile
//   to handle font table cleanup).
IO_stat MCDispatch::doreadfile(const char *openpath, const char *inname, IO_handle &stream, MCStack *&sptr)
{
	Boolean loadhome = False;
	char version[8];

	if (readheader(stream, version) == IO_NORMAL)
	{
		if (strcmp(version, MCversionstring) > 0)
		{
			MCresult->sets("stack was produced by a newer version");
			return IO_ERROR;
		}

		// MW-2008-10-20: [[ ParentScripts ]] Set the boolean flag that tells us whether
		//   parentscript resolution is required to false.
		s_loaded_parent_script_reference = false;

		uint1 charset, type;
		char *newsf;
		if (IO_read_uint1(&charset, stream) != IO_NORMAL
		        || IO_read_uint1(&type, stream) != IO_NORMAL
		        || IO_read_string(newsf, stream) != IO_NORMAL)
		{
			MCresult->sets("stack is corrupted, check for ~ backup file");
			return IO_ERROR;
		}
		delete newsf; // stackfiles is obsolete
		MCtranslatechars = charset != CHARSET;
		sptr = nil;
		/* UNCHECKED */ MCStackSecurityCreateStack(sptr);
		if (stacks == NULL)
			sptr->setparent(this);
		else
			sptr->setparent(stacks);
		sptr->setfilename(strclone(openpath));

		if (MCModeCanLoadHome() && type == OT_HOME)
		{
			char *lstring = NULL;
			char *cstring = NULL;
			IO_read_string(lstring, stream);
			IO_read_string(cstring, stream);
			delete lstring;
			delete cstring;
		}

		MCresult -> clear();

		if (IO_read_uint1(&type, stream) != IO_NORMAL
		    || type != OT_STACK && type != OT_ENCRYPT_STACK
		    || sptr->load(stream, version, type) != IO_NORMAL)
		{
			if (MCresult -> isclear())
				MCresult->sets("stack is corrupted, check for ~ backup file");
			destroystack(sptr, False);
			sptr = NULL;
			return IO_ERROR;
		}
		
		// MW-2011-08-09: [[ Groups ]] Make sure F_GROUP_SHARED is set
		//   appropriately.
		sptr -> checksharedgroups();
		
		if (sptr->load_substacks(stream, version) != IO_NORMAL
		        || IO_read_uint1(&type, stream) != IO_NORMAL
		        || type != OT_END)
		{
			if (MCresult -> isclear())
				MCresult->sets("stack is corrupted, check for ~ backup file");
			destroystack(sptr, False);
			sptr = NULL;
			return IO_ERROR;
		}

		if (stacks != NULL)
		{
			MCStack *tstk = stacks;
			do
			{
				if (sptr->hasname(tstk->getname()))
				{
					MCAutoNameRef t_stack_name;
					/* UNCHECKED */ t_stack_name . Clone(sptr -> getname());

					delete sptr;
					sptr = NULL;

					if (strequal(tstk->getfilename(), openpath))
						sptr = tstk;
					else
					{
						MCdefaultstackptr->getcard()->message_with_args(MCM_reload_stack, MCNameGetOldString(tstk->getname()), openpath);
						tstk = stacks;
						do
						{
							if (MCNameIsEqualTo(t_stack_name, tstk->getname(), kMCCompareCaseless))
							{
								sptr = tstk;
								break;
							}
							tstk = (MCStack *)tstk->next();
						}
						while (tstk != stacks);
					}

					return IO_NORMAL;
				}
				tstk = (MCStack *)tstk->next();
			}
			while (tstk != stacks);
		}
		
		appendstack(sptr);
		
		sptr->extraopen(false);

		// MW-2008-10-28: [[ ParentScript ]]
		// We just loaded a stackfile, so check to see if parentScript resolution
		// is required and if so do it.
		// MW-2009-01-28: [[ Inherited parentScripts ]]
		// Resolving parentScripts may allocate memory, so 'resolveparentscripts'
		// will return false if it fails to allocate what it needs. At some point
		// this needs to be dealt with by deleting the stack and returning an error,
		// *However* at the time of writing, 'readfile' isn't designed to handle
		// this - so we just ignore the result for now (note that all the 'load'
		// methods *fail* to check for no-memory errors!).
		if (s_loaded_parent_script_reference)
			sptr -> resolveparentscripts();
		
	}
	else
	{
		MCS_seek_set(stream, 0);
		if (stacks == NULL)
		{
			MCnoui = True;
			MCscreen = new MCUIDC;
			/* UNCHECKED */ MCStackSecurityCreateStack(stacks);
			MCdefaultstackptr = MCstaticdefaultstackptr = stacks;
			stacks->setparent(this);
			stacks->setname_cstring("revScript");
			uint4 size = (uint4)MCS_fsize(stream);
			char *script = new char[size + 2];
			script[size] = '\n';
			script[size + 1] = '\0';
			if (IO_read(script, sizeof(char), size, stream) != IO_NORMAL
			        || !stacks->setscript(script))
			{
				delete script;
				return IO_ERROR;
			}
		}
		else
		{
			char *tname = strclone(inname);
			
			// MW-2008-06-12: [[ Bug 6476 ]] Media won't open HC stacks
			if (!MCdispatcher->cut(True) || hc_import(tname, stream, sptr) != IO_NORMAL)
			{
				MCresult->sets("file is not a stack");
				delete tname;
				return IO_ERROR;
			}
		}
	}
	return IO_NORMAL;
}
예제 #11
0
파일: eps.cpp 프로젝트: Bjoernke/livecode
IO_stat MCEPS::load(IO_handle stream, const char *version)
{
	IO_stat stat;

	if ((stat = MCObject::load(stream, version)) != IO_NORMAL)
		return stat;
	delete postscript;
	delete prolog;
	if ((stat = IO_read_uint4(&size, stream)) != IO_NORMAL)
		return stat;
	postscript = new char[size + 1];
	if ((stat = IO_read(postscript, sizeof(char), size, stream)) != IO_NORMAL)
		return stat;
	postscript[size] = '\0';
	if ((stat = IO_read_string(prolog, stream)) != IO_NORMAL)
		return stat;
	int4 i;
	if ((stat = IO_read_int4(&i, stream)) != IO_NORMAL)
		return stat;
	xscale = MCU_i4tor8(i);
	if (flags & F_SCALE_INDEPENDENTLY)
	{
		if ((stat = IO_read_int4(&i, stream)) != IO_NORMAL)
			return stat;
		yscale = MCU_i4tor8(i);
	}
	else
		yscale = xscale;
	if ((stat = IO_read_int2(&angle, stream)) != IO_NORMAL)
		return stat;
	if ((stat = IO_read_int2(&tx, stream)) != IO_NORMAL)
		return stat;
	if ((stat = IO_read_int2(&ty, stream)) != IO_NORMAL)
		return stat;
	if ((stat = IO_read_uint2(&ex, stream)) != IO_NORMAL)
		return stat;
	if ((stat = IO_read_uint2(&ey, stream)) != IO_NORMAL)
		return stat;
	if (flags & F_RETAIN_IMAGE)
	{
		image = new MCImage;
		image->setparent(this);
		if ((stat = image->load(stream, version)) != IO_NORMAL)
			return stat;
	}
	if (strncmp(version, "1.3", 3) > 0)
	{
		if ((stat = IO_read_uint2(&curpage, stream)) != IO_NORMAL)
			return stat;
		if ((stat = IO_read_uint2(&pagecount, stream)) != IO_NORMAL)
			return stat;
		if (pagecount > 0)
		{
			pageIndex = new uint4[pagecount];
			for (i = 0 ; i < pagecount ; i++)
				if ((stat = IO_read_uint4(&pageIndex[i], stream)) != IO_NORMAL)
					return stat;
		}
	}
	return loadpropsets(stream);
}
예제 #12
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;
}
예제 #13
0
Boolean MCAudioClip::import(const char *fname, IO_handle stream)
{
	size = (uint4)MCS_fsize(stream);
	if (size == 0)
		return False;
	samples = new int1[size];
	if (IO_read(samples, sizeof(int1), size, stream) != IO_NORMAL)
		return False;
	if (strnequal((char*)samples, ".snd", 4))
	{
		uint4 *header = (uint4 *)samples;
		uint4 start = swap_uint4(&header[1]);
		size -= start;
		rate = swap_uint4(&header[4]);
		nchannels = swap_uint4(&header[5]);
		switch (swap_uint4(&header[3]))
		{
		case 0:
		case 1:
			swidth = 1;
			format = AF_MULAW;
			break;
		case 2:
			swidth = 1;
			break;
		case 3:
			swidth = 2;
			break;
		case 4:
		case 5:
			swidth = 3;
			break;
		}
		memmove(samples, &samples[start], size);
	}
	else
	{
		if (strnequal((char*)samples, "FORM", 4)
		        || strnequal((char*)&samples[8], "AIFF", 4))
		{
			int1 *sptr = &samples[12];
			while (True)
			{
				uint4 length;
				memcpy((char *)&length, sptr + 4, 4);
				swap_uint4(&length);
				if (strnequal((char*)sptr, "COMM", 4))
				{
					memcpy((char *)&nchannels, sptr + 8, 2);
					memcpy((char *)&swidth, sptr + 14, 2);
					swap_uint2(&nchannels);
					swap_uint2(&swidth);
					swidth >>= 3;
					rate = (int4)MCU_stoIEEE((char *)(sptr + 16));
				}
				else
					if (strnequal((char*)sptr, "SSND", 4))
					{
						size = length - 8;
						memmove(samples, sptr + 12, size);
						break;
					}
				sptr += length + (length & 1) + 8;
			}