void LLUploadDialog::setMessage( const std::string& msg) { const LLFontGL* font = LLFontGL::getFontSansSerif(); const S32 VPAD = 16; const S32 HPAD = 25; // Make the text boxes a little wider than the text const S32 TEXT_PAD = 8; // Split message into lines, separated by '\n' S32 max_msg_width = 0; std::list<std::string> msg_lines; S32 size = msg.size() + 1; std::vector<char> temp_msg(size); // non-const copy to make strtok happy strcpy( &temp_msg[0], msg.c_str()); char* token = strtok( &temp_msg[0], "\n" ); while( token ) { std::string tokstr(token); S32 cur_width = S32(font->getWidth(tokstr) + 0.99f) + TEXT_PAD; max_msg_width = llmax( max_msg_width, cur_width ); msg_lines.push_back( tokstr ); token = strtok( NULL, "\n" ); } S32 line_height = S32( font->getLineHeight() + 0.99f ); S32 dialog_width = max_msg_width + 2 * HPAD; S32 dialog_height = line_height * msg_lines.size() + 2 * VPAD; reshape( dialog_width, dialog_height, FALSE ); // Message S32 msg_x = (getRect().getWidth() - max_msg_width) / 2; S32 msg_y = getRect().getHeight() - VPAD - line_height; int line_num; for (line_num=0; line_num<16; ++line_num) { mLabelBox[line_num]->setVisible(FALSE); } line_num = 0; for (std::list<std::string>::iterator iter = msg_lines.begin(); iter != msg_lines.end(); ++iter) { std::string& cur_line = *iter; LLRect msg_rect; msg_rect.setOriginAndSize( msg_x, msg_y, max_msg_width, line_height ); mLabelBox[line_num]->setRect(msg_rect); mLabelBox[line_num]->setText(cur_line); mLabelBox[line_num]->setColor( LLUIColorTable::instance().getColor( "LabelTextColor" ) ); mLabelBox[line_num]->setVisible(TRUE); msg_y -= line_height; ++line_num; } centerWithin(gViewerWindow->getRootView()->getRect()); }
void LLUploadDialog::setMessage( const std::string& msg) { const LLFontGL* font = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF ); const S32 VPAD = 16; const S32 HPAD = 25; // Make the text boxes a little wider than the text const S32 TEXT_PAD = 8; // Split message into lines, separated by '\n' S32 max_msg_width = 0; std::list<std::string> msg_lines; S32 size = msg.size() + 1;// + strlen("Uploading...\n\n"); char* temp_msg = new char[size]; //strcpy(temp_msg,"Uploading...\n\n"); if (temp_msg == NULL) { llerrs << "Memory Allocation Failed" << llendl; return; } strcpy( temp_msg, msg.c_str()); /* Flawfinder: ignore */ char* token = strtok( temp_msg, "\n" ); while( token ) { std::string tokstr(token); S32 cur_width = S32(font->getWidth(tokstr) + 0.99f) + TEXT_PAD; max_msg_width = llmax( max_msg_width, cur_width ); msg_lines.push_back( tokstr ); token = strtok( NULL, "\n" ); } delete[] temp_msg; S32 line_height = S32( font->getLineHeight() + 0.99f ); S32 dialog_width = max_msg_width + 2 * HPAD; S32 dialog_height = line_height * msg_lines.size() + 2 * VPAD; reshape( dialog_width, dialog_height, FALSE ); // Message S32 msg_x = (getRect().getWidth() - max_msg_width) / 2; S32 msg_y = getRect().getHeight() - VPAD - line_height; int line_num; for (line_num=0; line_num<16; ++line_num) { mLabelBox[line_num]->setVisible(FALSE); } line_num = 0; for (std::list<std::string>::iterator iter = msg_lines.begin(); iter != msg_lines.end(); ++iter) { std::string& cur_line = *iter; LLRect msg_rect; msg_rect.setOriginAndSize( msg_x, msg_y, max_msg_width, line_height ); mLabelBox[line_num]->setRect(msg_rect); mLabelBox[line_num]->setText(cur_line); mLabelBox[line_num]->setColor( gColors.getColor( "LabelTextColor" ) ); mLabelBox[line_num]->setVisible(TRUE); msg_y -= line_height; ++line_num; } centerWithin(gViewerWindow->getRootView()->getRect()); }
int main( int argc, const char** argv) { try { g_errorBuffer = strus::createErrorBuffer_standard( 0, 1); if (!g_errorBuffer) { std::cerr << "construction of error buffer failed" << std::endl; return -1; } else if (argc > 3) { printUsage( argc, argv); std::cerr << "too many arguments" << std::endl; return 1; } else if (argc < 3) { printUsage( argc, argv); std::cerr << "too few arguments" << std::endl; return 1; } // Create objects: std::auto_ptr<strus::TokenPatternMatchInterface> pti( strus::createTokenPatternMatch_standard( g_errorBuffer)); if (!pti.get()) throw std::runtime_error("failed to create pattern matcher"); std::auto_ptr<strus::CharRegexMatchInterface> cri( strus::createCharRegexMatch_standard( g_errorBuffer)); if (!cri.get()) throw std::runtime_error("failed to create char regex matcher"); std::auto_ptr<strus::PatternMatchProgramInterface> ppi( strus::createPatternMatchProgram_standard( pti.get(), cri.get(), g_errorBuffer)); if (!ppi.get()) throw std::runtime_error("failed to create pattern program loader"); std::auto_ptr<strus::PatternMatchProgramInstanceInterface> pii( ppi->createInstance()); if (!pii.get()) throw std::runtime_error("failed to create pattern program loader instance"); // Load program: std::string programfile( argv[ 1]); std::string programsrc; unsigned int ec; ec = strus::readFile( programfile, programsrc); if (ec) { char errmsg[ 256]; ::snprintf( errmsg, sizeof(errmsg), "error (%u) reading program source '%s': %s", ec, programfile.c_str(), ::strerror(ec)); throw std::runtime_error( errmsg); } if (!pii->load( programsrc)) { throw std::runtime_error( "error loading pattern match program source"); } if (!pii->compile()) { throw std::runtime_error( "error compiling pattern match program"); } // Load input: std::string inputfile( argv[ 2]); std::string inputsrc; ec = strus::readFile( inputfile, inputsrc); if (ec) { char errmsg[ 256]; ::snprintf( errmsg, sizeof(errmsg), "error (%u) reading input file '%s': %s", ec, inputfile.c_str(), ::strerror(ec)); throw std::runtime_error( errmsg); } // Load expected output: char const* argv2ext = std::strchr( argv[ 2], '.'); if (argv2ext) { char const* aa = std::strchr( argv2ext+1, '.'); while (aa) { argv2ext = aa; aa = std::strchr( argv2ext+1, '.'); } } else { argv2ext = std::strchr( argv[ 2], '\0'); } std::string expectedfile( argv[ 2], argv2ext - argv[ 2]); expectedfile.append( ".res"); std::string expectedsrc; ec = strus::readFile( expectedfile, expectedsrc); if (ec) { char errmsg[ 256]; ::snprintf( errmsg, sizeof(errmsg), "error (%u) reading expected file '%s': %s", ec, expectedfile.c_str(), ::strerror(ec)); throw std::runtime_error( errmsg); } // Scan source with char regex automaton for tokens: const strus::CharRegexMatchInstanceInterface* crinst = pii->getCharRegexMatchInstance(); std::auto_ptr<strus::CharRegexMatchContextInterface> crctx( crinst->createContext()); std::vector<strus::stream::PatternMatchToken> crmatches = crctx->match( inputsrc.c_str(), inputsrc.size()); if (crmatches.size() == 0 && g_errorBuffer->hasError()) { throw std::runtime_error( "failed to scan for tokens with char regex match automaton"); } std::ostringstream resultstrbuf; // Scan tokens with token pattern match automaton and print results: const strus::TokenPatternMatchInstanceInterface* ptinst = pii->getTokenPatternMatchInstance(); std::auto_ptr<strus::TokenPatternMatchContextInterface> ptctx( ptinst->createContext()); std::vector<strus::stream::PatternMatchToken>::const_iterator ci = crmatches.begin(), ce = crmatches.end(); for (; ci != ce; ++ci) { std::string tokstr( std::string( inputsrc.c_str() + ci->origpos(), ci->origsize())); resultstrbuf << "token " << pii->tokenName(ci->id()) << "(" << ci->id() << ") at " << ci->ordpos() << "[" << ci->origpos() << ":" << ci->origsize() << "] '" << tokstr << "'" << std::endl; ptctx->putInput( *ci); } std::vector<strus::stream::TokenPatternMatchResult> results = ptctx->fetchResults(); if (results.size() == 0 && g_errorBuffer->hasError()) { throw std::runtime_error( "failed to scan for patterns with token pattern match automaton"); } // Print results to buffer: strus::utils::printResults( resultstrbuf, results, inputsrc.c_str()); strus::stream::TokenPatternMatchStatistics stats = ptctx->getStatistics(); strus::utils::printStatistics( resultstrbuf, stats); // Print result to stdout and verify result by comparing it with the expected output: std::string resultstr = resultstrbuf.str(); std::cout << resultstr << std::endl; if (!diffContent( expectedsrc, resultstr)) { throw std::runtime_error( "output and expected result differ"); } if (g_errorBuffer->hasError()) { throw std::runtime_error( "uncaught error"); } std::cerr << "OK" << std::endl; delete g_errorBuffer; return 0; } catch (const std::runtime_error& err) { if (g_errorBuffer->hasError()) { std::cerr << "error processing pattern matching: " << g_errorBuffer->fetchError() << " (" << err.what() << ")" << std::endl; } else { std::cerr << "error processing pattern matching: " << err.what() << std::endl; } } catch (const std::bad_alloc&) { std::cerr << "out of memory processing pattern matching" << std::endl; } delete g_errorBuffer; return -1; }
int main(int argc, char *argv[]) { s_block *S_block; p_table *P_table=NULL; inode *Inode = NULL; options *Opt; FILE *fs; FILE *output; /*where all the data will be outputed*/ uint32_t part_start; /*beginning file system*/ uint32_t inode_off; /*beginning of inode zone*/ uint32_t zone_size; uint8_t *data; char **path; if ((Opt = handleOptions(argc, argv))==NULL) { printf("minget [-v] [-p part [-s subpart]] imagefile srcpath [dstpath]\n"); exit(EXIT_FAILURE); } FATALCALL((fs = fopen(Opt->imagefile, "rb"))==NULL,"fopen"); /*check super block*/ output = stdout; if (Opt->dstpath) FATALCALL((output = fopen(Opt->dstpath, "w+b"))==NULL,"fopen"); part_start = 0; /*0 is start of image*/ if (Opt->part_num == -1 && Opt->subpart_num == -1) /*no partition or subpartition*/ { if((S_block = getSuperBlock(fs, 0)) == NULL) /*MAGIC NUMBER*/ { free(S_block); exit(EXIT_FAILURE); } zone_size = S_block->block_size << S_block->log_zone_size; inode_off = part_start + (2 + S_block->imap_blocks + S_block->zmap_blocks) * S_block->block_size; } else if (Opt->part && !Opt->subpart) /*partition but no subpartition*/ { P_table = getPartTable(fs, part_start, Opt->part_num); if (P_table == NULL) exit(EXIT_FAILURE); part_start = P_table->lFirst * SECTOR_SIZE; if((S_block = getSuperBlock(fs, 0)) == NULL) /*MAGIC NUMBER*/ { free(S_block); exit(EXIT_FAILURE); } zone_size = S_block->block_size << S_block->log_zone_size; inode_off = part_start + (2 + S_block->imap_blocks + S_block->zmap_blocks) * S_block->block_size; } else if (Opt->part && Opt->subpart) /* partition and subpartition */ { P_table = getPartTable(fs, part_start, Opt->part_num); /*0 is start of image*/ if (P_table == NULL) { free(P_table); exit(EXIT_FAILURE); } part_start = P_table->lFirst * SECTOR_SIZE; free(P_table); P_table = getPartTable(fs, part_start, Opt->subpart_num); if (P_table == NULL) { free(P_table); exit(EXIT_FAILURE); } part_start = P_table->lFirst * SECTOR_SIZE; if((S_block = getSuperBlock(fs, part_start)) == NULL) /*MAGIC NUMBER*/ { free(S_block); exit(EXIT_FAILURE); } zone_size = S_block->block_size << S_block->log_zone_size; inode_off = part_start + (2 + S_block->imap_blocks + S_block->zmap_blocks) * S_block->block_size; } else { exit(EXIT_FAILURE); } path =tokstr(Opt->path, "/"); if ((Inode = getFile(fs, path, inode_off, part_start, zone_size))==NULL) { fprintf(stderr, "File Doesn't Exist\n"); exit(EXIT_FAILURE); } data = getData(fs, Inode, part_start, zone_size); if (Opt->verbose) verbose(S_block, Inode); printFile(output, data, Inode->size); fclose(fs); /*check for errors*/ if(P_table!=NULL) { free(P_table); } free(Opt); free(S_block); return EXIT_SUCCESS; }