void executeCodegen(CodegenOptions options) { llvm::SmallString<128> outpath(options.inputFilePath); llvm::sys::path::replace_extension(outpath, extension(options.type)); Parser p(options.inputFilePath); AST ast = p.parse(); filebuf outfile; outfile.open(outpath.c_str(), ios::out); ostream os(&outfile); if (options.type == codegen::AST) { pretty_print(ast, os); return; } llvm::raw_os_ostream raw_os(os); llvm::InitializeAllTargets(); llvm::InitializeAllTargetMCs(); llvm::InitializeAllAsmPrinters(); Symbols symbols; checkSemantics(ast, symbols); MjModule module(ast, symbols); Codegen cg(module, options); cg.emitCode(&raw_os); raw_os.flush(); }
bool CStatsUtil::ParseOutputPath( const string & path ) { Poco::Path outpath(path); if( outpath.isFile() || outpath.isDirectory() ) { m_outputPath = path; return true; } return false; }
void ExtractScummMac::execute() { unsigned long file_record_off, file_record_len; unsigned long file_off, file_len; unsigned long data_file_len; char file_name[0x20]; char *buf; unsigned long i; int j; Common::Filename inpath(_inputPaths[0].path); Common::Filename outpath(_outputPath); if (outpath.empty()) outpath.setFullPath("./"); Common::File ifp(inpath, "rb"); /* Get the length of the data file to use for consistency checks */ data_file_len = ifp.size(); /* Read offset and length to the file records */ file_record_off = ifp.readUint32BE(); file_record_len = ifp.readUint32BE(); /* Do a quick check to make sure the offset and length are good */ if (file_record_off + file_record_len > data_file_len) { error("\'%s\'. file records out of bounds.", inpath.getFullPath().c_str()); } /* Do a little consistancy check on file_record_length */ if (file_record_len % 0x28) { error("\'%s\'. file record length not multiple of 40.", inpath.getFullPath().c_str()); } /* Extract the files */ for (i = 0; i < file_record_len; i += 0x28) { /* read a file record */ ifp.seek(file_record_off + i, SEEK_SET); file_off = ifp.readUint32BE(); file_len = ifp.readUint32BE(); ifp.read_throwsOnError(file_name, 0x20); if (!file_name[0]) error("\'%s\'. file has no name.", inpath.getFullPath().c_str()); print("extracting \'%s\'", file_name); /* For convenience compatibility with scummvm (and case sensitive * file systems) change the file name to lowercase. * * if i ever add the ability to pass flags on the command * line, i will make this optional, but i really don't * see the point to bothering */ for (j = 0; j < 0x20; j++) { if (!file_name[j]) { break; } #ifdef CHANGECASE file_name[j] = tolower(file_name[j]); #endif } if (j == 0x20) { file_name[0x1f] = 0; warning("\'%s\'. file name not null terminated.", file_name); print("data file \'%s\' may be not a file extract_scumm_mac can extract.", inpath.getFullPath().c_str()); } print(", saving as \'%s\'", file_name); /* Consistency check. make sure the file data is in the file */ if (file_off + file_len > data_file_len) { error("\'%s\'. file out of bounds.", inpath.getFullPath().c_str()); } /* Write a file */ ifp.seek(file_off, SEEK_SET); outpath.setFullName(file_name); Common::File ofp(outpath, "wb"); if (!(buf = (char *)malloc(file_len))) { error("Could not allocate %ld bytes of memory.", file_len); } ifp.read_throwsOnError(buf, file_len); ofp.write(buf, file_len); free(buf); } }
/* ---[ */ int main (int argc, char** argv) { ros::init (argc, argv, "bag_to_pcd"); if (argc < 5) { std::cerr << "Syntax is: " << argv[0] << " <file_in.bag> <topic> <output_directory> <target_frame>" << std::endl; std::cerr << "Example: " << argv[0] << " data.bag /laser_tilt_cloud ./pointclouds /base_link" << std::endl; return (-1); } // TF tf::TransformListener tf_listener; tf::TransformBroadcaster tf_broadcaster; rosbag::Bag bag; rosbag::View view; rosbag::View::iterator view_it; try { bag.open (argv[1], rosbag::bagmode::Read); } catch (rosbag::BagException) { std::cerr << "Error opening file " << argv[1] << std::endl; return (-1); } //view.addQuery (bag, rosbag::TypeQuery ("sensor_msgs/PointCloud2")); view.addQuery (bag, rosbag::TopicQuery(argv[2])); view.addQuery (bag, rosbag::TypeQuery ("tf/tfMessage")); view_it = view.begin (); std::string output_dir = std::string (argv[3]); boost::filesystem::path outpath (output_dir); if (!boost::filesystem::exists (outpath)) { if (!boost::filesystem::create_directories (outpath)) { std::cerr << "Error creating directory " << output_dir << std::endl; return (-1); } std::cerr << "Creating directory " << output_dir << std::endl; } // Add the PointCloud2 handler std::cerr << "Saving recorded sensor_msgs::PointCloud2 messages on topic " << argv[2] << " to " << output_dir << std::endl; PointCloud cloud_t; ros::Duration r (0.001); // Loop over the whole bag file while (view_it != view.end ()) { try { // Handle TF messages first tf::tfMessage::ConstPtr tf = view_it->instantiate<tf::tfMessage> (); if (tf != NULL) { tf_broadcaster.sendTransform (tf->transforms); ros::spinOnce (); r.sleep (); } else { // Get the PointCloud2 message PointCloudConstPtr cloud = view_it->instantiate<PointCloud> (); if (cloud == NULL) { ++view_it; continue; } // Transform it tf::StampedTransform transform; //if(argv[4] != cloud->header.frame_id) tf_listener.lookupTransform(cloud->header.frame_id, argv[4], cloud->header.stamp, transform); Eigen::Matrix4f out_mat; pcl_ros::transformAsMatrix (transform, out_mat); //pcl_ros::transformPointCloud ("/head_axis_link", *cloud, cloud_t, tf_listener); pcl_ros::transformPointCloud (out_mat, *cloud, cloud_t); pcl::PCLPointCloud2 cloud_t2; pcl_conversions::toPCL(cloud_t, cloud_t2); std::cerr << "Got " << cloud_t2.width * cloud_t2.height << " data points in frame " << cloud_t2.header.frame_id << " with the following fields: " << pcl::getFieldsList (cloud_t2) << std::endl; std::stringstream ss; ss << output_dir << "/" << cloud_t2.header.stamp << ".pcd"; std::cerr << "Data saved to " << ss.str () << std::endl; pcl::io::savePCDFile (ss.str (), cloud_t2, Eigen::Vector4f::Zero (), Eigen::Quaternionf::Identity (), false); } } catch (tf::TransformException ex) { ROS_ERROR("%s",ex.what()); } // Increment the iterator ++view_it; } return (0); }
/* * NAME: showfiles() * DESCRIPTION: display a set of files */ static int showfiles(darray *files, int flags, int options, int width) { dlist list; int i, sz, result = 0; queueent *ents; dstring str; char **strs; void (*show)(int, queueent *, char **, int, int, int); if (dl_init(&list) == -1) { fprintf(stderr, "%s: not enough memory\n", argv0); return -1; } sz = darr_size(files); ents = darr_array(files); dstr_init(&str); for (i = 0; i < sz; ++i) { if (outpath(&str, &ents[i], flags) == -1 || dl_append(&list, dstr_string(&str)) == -1) { result = -1; break; } } dstr_free(&str); strs = dl_array(&list); switch (options & F_MASK) { case F_LONG: show = show_long; break; case F_ONE: show = show_one; break; case F_MANY: show = show_many; break; case F_HORIZ: show = show_horiz; break; case F_COMMAS: show = show_commas; break; default: abort(); } show(sz, ents, strs, flags, options, width); dl_free(&list); return result; }