size_t EmulateInstruction::WriteMemoryDefault (EmulateInstruction *instruction, void *baton, const Context &context, lldb::addr_t addr, const void *dst, size_t length) { StreamFile strm (stdout, false); strm.Printf (" Write to Memory (address = 0x%" PRIx64 ", length = %" PRIu64 ", context = ", addr, (uint64_t)length); context.Dump (strm, instruction); strm.EOL(); return length; }
bool EmulateInstruction::WriteRegisterDefault (EmulateInstruction *instruction, void *baton, const Context &context, const RegisterInfo *reg_info, const RegisterValue ®_value) { StreamFile strm (stdout, false); strm.Printf (" Write to Register (name = %s, value = " , reg_info->name); reg_value.Dump(&strm, reg_info, false, false, eFormatDefault); strm.PutCString (", context = "); context.Dump (strm, instruction); strm.EOL(); return true; }
bool EmulateInstruction::ReadRegisterDefault (EmulateInstruction *instruction, void *baton, const RegisterInfo *reg_info, RegisterValue ®_value) { StreamFile strm (stdout, false); strm.Printf (" Read Register (%s)\n", reg_info->name); lldb::RegisterKind reg_kind; uint32_t reg_num; if (GetBestRegisterKindAndNumber (reg_info, reg_kind, reg_num)) reg_value.SetUInt64((uint64_t)reg_kind << 24 | reg_num); else reg_value.SetUInt64(0); return true; }
int main(int argc, char *argv[]) { rw::Engine::init(); gta::attachPlugins(); rw::Driver::open(); ARGBEGIN{ }ARGEND; if(argc < 1) usage(); StreamFile in; if(in.open(argv[0], "rb") == NULL) return 1; readColFile(&in); in.close(); return 0; }
Template* TemplateCache::LoadTemplate(const String& name) { // Check if the template is already loaded Templates::iterator itr = instance->templates.find(name); if (itr != instance->templates.end()) return (*itr).second; // Nope, we better load it Template* new_template = NULL; StreamFile* stream = new StreamFile(); if (stream->Open(name)) { new_template = new Template(); if (!new_template->Load(stream)) { Log::Message(Log::LT_ERROR, "Failed to load template %s.", name.CString()); delete new_template; new_template = NULL; } else if (new_template->GetName().Empty()) { Log::Message(Log::LT_ERROR, "Failed to load template %s, template is missing its name.", name.CString()); delete new_template; new_template = NULL; } else { instance->templates[name] = new_template; instance->template_ids[new_template->GetName()] = new_template; } } else { Log::Message(Log::LT_ERROR, "Failed to open template file %s.", name.CString()); } stream->RemoveReference(); return new_template; }
void writeSingleCol(CColModel *colmodel, char *name) { char colname[24]; ColHeader header; uint8 *buf; StreamFile stream; stream.open("out.col", "wb"); header.ident = COLL; header.size = writeColModel(colmodel, &buf)+24; stream.write(&header, 8); memset(colname, 0, 24); strncpy(colname, name, 24); stream.write(colname, 24); stream.write(buf, header.size-24); delete[] buf; stream.close(); }
//------------------------------------------------------------------ /// Install the utility function into a process /// /// @param[in] error_stream /// A stream to print parse errors and warnings to. /// /// @param[in] exe_ctx /// The execution context to install the utility function to. /// /// @return /// True on success (no errors); false otherwise. //------------------------------------------------------------------ bool ClangUtilityFunction::Install (Stream &error_stream, ExecutionContext &exe_ctx) { lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); if (m_jit_start_addr != LLDB_INVALID_ADDRESS) { error_stream.PutCString("error: already installed\n"); return false; } //////////////////////////////////// // Set up the target and compiler // Target *target = exe_ctx.GetTargetPtr(); if (!target) { error_stream.PutCString ("error: invalid target\n"); return false; } Process *process = exe_ctx.GetProcessPtr(); if (!process) { error_stream.PutCString ("error: invalid process\n"); return false; } ////////////////////////// // Parse the expression // bool keep_result_in_memory = false; m_expr_decl_map.reset(new ClangExpressionDeclMap(keep_result_in_memory, exe_ctx)); m_data_allocator.reset(new ProcessDataAllocator(*process)); if (!m_expr_decl_map->WillParse(exe_ctx)) { error_stream.PutCString ("error: current process state is unsuitable for expression parsing\n"); return false; } ClangExpressionParser parser(exe_ctx.GetBestExecutionContextScope(), *this); unsigned num_errors = parser.Parse (error_stream); if (num_errors) { error_stream.Printf ("error: %d errors parsing expression\n", num_errors); m_expr_decl_map.reset(); return false; } ////////////////////////////////// // JIT the output of the parser // lldb::ClangExpressionVariableSP const_result; bool evaluated_statically = false; // should stay that way Error jit_error = parser.PrepareForExecution (m_jit_alloc, m_jit_start_addr, m_jit_end_addr, exe_ctx, m_data_allocator.get(), evaluated_statically, const_result, eExecutionPolicyAlways); if (log) { StreamString dump_string; m_data_allocator->Dump(dump_string); log->Printf("Data buffer contents:\n%s", dump_string.GetString().c_str()); } if (m_jit_start_addr != LLDB_INVALID_ADDRESS) m_jit_process_wp = lldb::ProcessWP(process->shared_from_this()); #if 0 // jingham: look here StreamFile logfile ("/tmp/exprs.txt", "a"); logfile.Printf ("0x%16.16" PRIx64 ": func = %s, source =\n%s\n", m_jit_start_addr, m_function_name.c_str(), m_function_text.c_str()); #endif m_expr_decl_map->DidParse(); m_expr_decl_map.reset(); if (jit_error.Success()) { return true; } else { const char *error_cstr = jit_error.AsCString(); if (error_cstr && error_cstr[0]) error_stream.Printf ("error: %s\n", error_cstr); else error_stream.Printf ("error: expression can't be interpreted or run\n"); return false; } }
//------------------------------------------------------------------ /// Install the utility function into a process /// /// @param[in] error_stream /// A stream to print parse errors and warnings to. /// /// @param[in] exe_ctx /// The execution context to install the utility function to. /// /// @return /// True on success (no errors); false otherwise. //------------------------------------------------------------------ bool ClangUtilityFunction::Install (Stream &error_stream, ExecutionContext &exe_ctx) { if (m_jit_start_addr != LLDB_INVALID_ADDRESS) { error_stream.PutCString("error: already installed\n"); return false; } //////////////////////////////////// // Set up the target and compiler // Target *target = exe_ctx.GetTargetPtr(); if (!target) { error_stream.PutCString ("error: invalid target\n"); return false; } Process *process = exe_ctx.GetProcessPtr(); if (!process) { error_stream.PutCString ("error: invalid process\n"); return false; } ////////////////////////// // Parse the expression // bool keep_result_in_memory = false; m_expr_decl_map.reset(new ClangExpressionDeclMap(keep_result_in_memory, exe_ctx)); if (!m_expr_decl_map->WillParse(exe_ctx, NULL)) { error_stream.PutCString ("error: current process state is unsuitable for expression parsing\n"); return false; } ClangExpressionParser parser(exe_ctx.GetBestExecutionContextScope(), *this); unsigned num_errors = parser.Parse (error_stream); if (num_errors) { error_stream.Printf ("error: %d errors parsing expression\n", num_errors); m_expr_decl_map.reset(); return false; } ////////////////////////////////// // JIT the output of the parser // bool can_interpret = false; // should stay that way Error jit_error = parser.PrepareForExecution (m_jit_start_addr, m_jit_end_addr, m_execution_unit_ap, exe_ctx, can_interpret, eExecutionPolicyAlways); if (m_jit_start_addr != LLDB_INVALID_ADDRESS) m_jit_process_wp = lldb::ProcessWP(process->shared_from_this()); #if 0 // jingham: look here StreamFile logfile ("/tmp/exprs.txt", "a"); logfile.Printf ("0x%16.16" PRIx64 ": func = %s, source =\n%s\n", m_jit_start_addr, m_function_name.c_str(), m_function_text.c_str()); #endif m_expr_decl_map->DidParse(); m_expr_decl_map.reset(); if (jit_error.Success()) { return true; } else { const char *error_cstr = jit_error.AsCString(); if (error_cstr && error_cstr[0]) error_stream.Printf ("error: %s\n", error_cstr); else error_stream.Printf ("error: expression can't be interpreted or run\n"); return false; } }
void Openchunk::run() { png_structp png_ptr_read; png_infop info_ptr_read; png_structp png_ptr_write; png_infop info_ptr_write; png_uint_32 next_frame_width; png_uint_32 next_frame_height; png_uint_32 next_frame_x_offset; png_uint_32 next_frame_y_offset; png_uint_16 next_frame_delay_num; png_uint_16 next_frame_delay_den; png_byte next_frame_dispose_op; png_byte next_frame_blend_op; png_color_16p Framebg; framlist.clear(); buffer = new StreamFile(); buffer->LoadFile(subfile); qDebug() << "### start read ->" << subfile; if (!buffer->isValid()) { alert("unvalid buffer fill",__LINE__); exit(0); } validpng = buffer->device()->peek(4).contains("PNG"); qDebug() << "### ahed ->" << validpng; frame1.loadFromData(buffer->stream()); /* load first frame */ if (frame1.isNull()) { alert("unable find a valid image",__LINE__); return; } png_ptr_read = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if(png_ptr_read == NULL) { alert("unable to create read struct",__LINE__); return; } info_ptr_read = png_create_info_struct(png_ptr_read); if(info_ptr_read == NULL) { alert("unable to create info struct",__LINE__); return; } png_set_read_fn(png_ptr_read,buffer,EncoderReaderCallback); if(setjmp(png_ptr_read->jmpbuf)) { alert("something didn't work, jump 1",__LINE__); return; } png_read_info(png_ptr_read, info_ptr_read); if(!png_get_valid(png_ptr_read, info_ptr_read, PNG_INFO_acTL)) { alert("source image must be animated",__LINE__); return; } QRect Frect(0,0,info_ptr_read->width,info_ptr_read->height); ////////////qDebug() << "### Frame rect from head ->" << Frect; QImage master(Frect.width(),Frect.height(),QImage::Format_ARGB32); const uint height = master.height(); png_bytep *row_pointers = new png_bytep[height]; for (uint i = 0; i < height; ++i) { row_pointers[i] = (png_bytep)master.scanLine(i); } int validloop = -1; for(int i = 0; i < png_get_num_frames(png_ptr_read, info_ptr_read); i++) { /////////qDebug() << "### frame read ------------- " << i; png_ptr_write = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if(png_ptr_write == NULL) { alert("unable to create write struct"); return; } StreamFile *framer = new StreamFile(); png_set_write_fn(png_ptr_write,framer,EncoderWriteCallback, NULL); info_ptr_write = png_create_info_struct(png_ptr_write); if(info_ptr_write == NULL) { alert("unable to create write struct"); return; } if(setjmp(png_ptr_write->jmpbuf)) { alert("something didn't work, jump 2"); return; } png_read_frame_head(png_ptr_read, info_ptr_read); if(png_get_valid(png_ptr_read, info_ptr_read, PNG_INFO_fcTL)) { png_get_next_frame_fcTL(png_ptr_read, info_ptr_read, &next_frame_width, &next_frame_height, &next_frame_x_offset, &next_frame_y_offset, &next_frame_delay_num, &next_frame_delay_den, &next_frame_dispose_op, &next_frame_blend_op); } else { /* the first frame doesn't have an fcTL so it's expected to be hidden, * but we'll extract it anyway next_frame_x_offset , next_frame_y_offset */ next_frame_width = png_get_image_width(png_ptr_read, info_ptr_read); next_frame_height = png_get_image_height(png_ptr_read, info_ptr_read); } QRect C_frame_rect(0,0,next_frame_width,next_frame_height); AFRAMES FrameInfo = OneFrameReader(png_ptr_read, info_ptr_read, png_ptr_write, info_ptr_write, next_frame_width, next_frame_height); png_write_info(png_ptr_write, info_ptr_write); png_read_image(png_ptr_read, row_pointers); png_write_image(png_ptr_write, row_pointers); png_write_end(png_ptr_write, NULL); float Fraction = (float)next_frame_delay_num / (float)next_frame_delay_den + 0.00; ////////qDebug() << "### Fraction " << Fraction; int PlayGo; if (Fraction < 0.001 ) { PlayGo = 100; } else if (Fraction < 1.010 && Fraction > 0.9) { PlayGo = 1000; } else { PlayGo = Fraction * 1000; } /* extract frames */ if ( framer->isValid() && Frect.contains(C_frame_rect) ) { validloop++; int Coalpha = 255; /* prepare image if no background find grab a pixel color! */ QImage tmpgd(C_frame_rect.width(),C_frame_rect.height(),QImage::Format_ARGB32); /* compose it files */ APNGFRAME one; one.dimg = framer->stream(); one.maxframe = Frect; one.pos = validloop; one.point = QPoint(next_frame_x_offset,next_frame_y_offset); one.play = PlayGo; if (!(png_get_valid(png_ptr_read, info_ptr_read, PNG_INFO_bKGD))) { tmpgd.loadFromData(one.dimg); QRgb GrepColor = tmpgd.pixel(QPoint(2,2)); one.bg = QColor(GrepColor); one.bg.setAlpha(qAlpha(GrepColor)); Coalpha = qAlpha(GrepColor); } else { one.bg = FrameInfo.bg; } QImage tmpe; QImage Pvidi(one.maxframe.width(),one.maxframe.height(),QImage::Format_ARGB32); if (tmpe.loadFromData(one.dimg)) { QPainter p(&Pvidi); p.setRenderHint(QPainter::Antialiasing, true); p.setBrush(one.bg); p.drawRect(Pvidi.rect()); p.drawImage(one.point,tmpe); p.end(); one.item = Pvidi; ////qDebug() << "### isNull() in theard .." << one.item.isNull(); } //////item tmpe //////qDebug() << "### Frame rect ->" << one.point << ",nr." << validloop << "C." << one.bg.name() << "Al." << Coalpha; framlist.insert(validloop,one); } framer->~StreamFile(); png_ptr_write = 0; info_ptr_write = 0; } qDebug() << "### Frame size() ->" << framlist.size(); //////alert("end of chunks",__LINE__); validpng = true; buffer->~StreamFile(); exit(0); }
//------------------------------------------------------------------ /// Install the utility function into a process /// /// @param[in] diagnostic_manager /// A diagnostic manager to report errors and warnings to. /// /// @param[in] exe_ctx /// The execution context to install the utility function to. /// /// @return /// True on success (no errors); false otherwise. //------------------------------------------------------------------ bool ClangUtilityFunction::Install(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx) { if (m_jit_start_addr != LLDB_INVALID_ADDRESS) { diagnostic_manager.PutCString(eDiagnosticSeverityWarning, "already installed"); return false; } //////////////////////////////////// // Set up the target and compiler // Target *target = exe_ctx.GetTargetPtr(); if (!target) { diagnostic_manager.PutCString(eDiagnosticSeverityError, "invalid target"); return false; } Process *process = exe_ctx.GetProcessPtr(); if (!process) { diagnostic_manager.PutCString(eDiagnosticSeverityError, "invalid process"); return false; } ////////////////////////// // Parse the expression // bool keep_result_in_memory = false; ResetDeclMap(exe_ctx, keep_result_in_memory); if (!DeclMap()->WillParse(exe_ctx, NULL)) { diagnostic_manager.PutCString( eDiagnosticSeverityError, "current process state is unsuitable for expression parsing"); return false; } const bool generate_debug_info = true; ClangExpressionParser parser(exe_ctx.GetBestExecutionContextScope(), *this, generate_debug_info); unsigned num_errors = parser.Parse(diagnostic_manager); if (num_errors) { ResetDeclMap(); return false; } ////////////////////////////////// // JIT the output of the parser // bool can_interpret = false; // should stay that way Error jit_error = parser.PrepareForExecution( m_jit_start_addr, m_jit_end_addr, m_execution_unit_sp, exe_ctx, can_interpret, eExecutionPolicyAlways); if (m_jit_start_addr != LLDB_INVALID_ADDRESS) { m_jit_process_wp = process->shared_from_this(); if (parser.GetGenerateDebugInfo()) m_execution_unit_sp->CreateJITModule(FunctionName()); } #if 0 // jingham: look here StreamFile logfile ("/tmp/exprs.txt", "a"); logfile.Printf ("0x%16.16" PRIx64 ": func = %s, source =\n%s\n", m_jit_start_addr, m_function_name.c_str(), m_function_text.c_str()); #endif DeclMap()->DidParse(); ResetDeclMap(); if (jit_error.Success()) { return true; } else { const char *error_cstr = jit_error.AsCString(); if (error_cstr && error_cstr[0]) { diagnostic_manager.Printf(eDiagnosticSeverityError, "%s", error_cstr); } else { diagnostic_manager.PutCString(eDiagnosticSeverityError, "expression can't be interpreted or run"); } return false; } }
void ElementDocument::ProcessHeader(const DocumentHeader* document_header) { // Store the source address that we came from source_url = document_header->source; // Construct a new header and copy the template details across DocumentHeader header; header.MergePaths(header.template_resources, document_header->template_resources, document_header->source); // Merge in any templates, note a merge may cause more templates to merge for (size_t i = 0; i < header.template_resources.size(); i++) { Template* merge_template = TemplateCache::LoadTemplate(URL(header.template_resources[i]).GetURL()); if (merge_template) header.MergeHeader(*merge_template->GetHeader()); else Log::Message(Log::LT_WARNING, "Template %s not found", header.template_resources[i].CString()); } // Merge the document's header last, as it is the most overriding. header.MergeHeader(*document_header); // Set the title to the document title. title = document_header->title; // If a style-sheet (or sheets) has been specified for this element, then we load them and set the combined sheet // on the element; all of its children will inherit it by default. StyleSheet* style_sheet = NULL; if (header.rcss_external.size() > 0) style_sheet = StyleSheetFactory::GetStyleSheet(header.rcss_external); // Combine any inline sheets. if (header.rcss_inline.size() > 0) { for (size_t i = 0;i < header.rcss_inline.size(); i++) { StyleSheet* new_sheet = new StyleSheet(); StreamMemory* stream = new StreamMemory((const byte*) header.rcss_inline[i].CString(), header.rcss_inline[i].Length()); stream->SetSourceURL(document_header->source); if (new_sheet->LoadStyleSheet(stream)) { if (style_sheet) { StyleSheet* combined_sheet = style_sheet->CombineStyleSheet(new_sheet); style_sheet->RemoveReference(); new_sheet->RemoveReference(); style_sheet = combined_sheet; } else style_sheet = new_sheet; } else new_sheet->RemoveReference(); stream->RemoveReference(); } } // If a style sheet is available, set it on the document and release it. if (style_sheet) { SetStyleSheet(style_sheet); style_sheet->RemoveReference(); } // Load external scripts. for (size_t i = 0; i < header.scripts_external.size(); i++) { StreamFile* stream = new StreamFile(); if (stream->Open(header.scripts_external[i])) LoadScript(stream, header.scripts_external[i]); stream->RemoveReference(); } // Load internal scripts. for (size_t i = 0; i < header.scripts_inline.size(); i++) { StreamMemory* stream = new StreamMemory((const byte*) header.scripts_inline[i].CString(), header.scripts_inline[i].Length()); LoadScript(stream, ""); stream->RemoveReference(); } // Hide this document. SetProperty(VISIBILITY, "hidden"); }