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; }
static bool load_custom_font_file_into_buffer_from_path(const char *p_path, char *&r_buffer, uint32_t &r_size) { bool t_success; t_success = true; char *t_font_path; t_font_path = nil; if (t_success) t_success = MCCStringFormat(t_font_path, "%s/%s%s", MCcmd, s_font_folder, p_path); if (t_success) t_success = MCS_exists(t_font_path, true); IO_handle t_font_file_handle; t_font_file_handle = nil; if (t_success) { t_font_file_handle = MCS_open(t_font_path, IO_READ_MODE, false, false, 0); t_success = t_font_file_handle != nil; } uint32_t t_file_size; t_file_size = 0; char *t_buffer; t_buffer = nil; if (t_success) { t_file_size = MCS_fsize(t_font_file_handle); t_success = MCMemoryAllocate(t_file_size + 1, t_buffer); } if (t_success) { IO_stat t_read_stat; uint32_t t_bytes_read; t_bytes_read = 0; while (t_success && t_bytes_read < t_file_size) { uint32_t t_count; t_count = t_file_size - t_bytes_read; t_read_stat = MCS_read(t_buffer + t_bytes_read, 1, t_count, t_font_file_handle); t_bytes_read += t_count; t_success = (t_read_stat == IO_NORMAL || (t_read_stat == IO_EOF && t_bytes_read == t_file_size)); } } if (t_success) { r_buffer = t_buffer; r_size = t_file_size; } else /*UNCHECKED */ MCMemoryDelete(t_buffer); /*UNCHECKED */ MCCStringFree(t_font_path); return t_success; }
IO_stat IO_read_to_eof(IO_handle stream, MCExecPoint &ep) { uint4 nread; nread = (uint4)MCS_fsize(stream) - (uint4)MCS_tell(stream); char *dptr = ep.getbuffer(nread); MCS_read(dptr, 1, nread, stream); ep.setlength(nread); return IO_NORMAL; }
Boolean MCVideoClip::import(const char *fname, IO_handle fstream) { const char *tname = strrchr(fname, PATH_SEPARATOR); if (tname != NULL) tname += 1; else tname = fname; setname_cstring(tname); size = (uint4)MCS_fsize(fstream); frames = new uint1[size]; if (MCS_read(frames, sizeof(int1), size, fstream) != IO_NORMAL) return False; return True; }
bool read_all(IO_handle p_stream, uint8_t *&r_data, uindex_t &r_data_size) { bool t_success = true; uint8_t *t_buffer = nil; uindex_t t_size = 0; t_size = MCS_fsize(p_stream) - MCS_tell(p_stream); t_success = MCMemoryAllocate(t_size, t_buffer); if (t_success) t_success = IO_NORMAL == MCS_readfixed(t_buffer, t_size, p_stream); if (t_success) { r_data = t_buffer; r_data_size = t_size; } else MCMemoryDeallocate(t_buffer); return t_success; }
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; }
bool Measure(uint32_t& r_size) { r_size = (uint32_t)MCS_fsize(handle); return true; }
// 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; }
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; }