void conf_file_or_dir(FILE *f) { struct stat st; DIR *dir; struct dirent *dp; struct fname *list = NULL; fstat(fileno(f), &st); if (S_ISREG(st.st_mode)) conf_file(f); else if (!S_ISDIR(st.st_mode)) return; #if _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L dir = fdopendir(fileno(f)); if (!dir) return; while ((dp = readdir(dir)) != NULL) { int l; struct fname *fn, **p; if (dp->d_ino == 0) continue; if (dp->d_name[0] == '.') continue; l = strlen(dp->d_name); if (l < 6 || strcmp(dp->d_name+l-5, ".conf") != 0) continue; fn = xmalloc(sizeof(*fn)+l+1); strcpy(fn->name, dp->d_name); for (p = &list; *p && strcmp((*p)->name, fn->name) < 0; p = & (*p)->next) ; fn->next = *p; *p = fn; } while (list) { int fd; FILE *f2; struct fname *fn = list; list = list->next; fd = openat(fileno(f), fn->name, O_RDONLY); free(fn); if (fd < 0) continue; f2 = fdopen(fd, "r"); if (!f2) { close(fd); continue; } conf_file(f2); fclose(f2); } closedir(dir); #endif }
void configuration::read_conf(std::string file) { std::ifstream conf_file(file.c_str()); string temp; unsigned index = 1; cerr << "Reading Conf file <"<< file << "> ... " << flush; #ifdef DEBUG_MAX cerr << endl; #endif while (!conf_file.eof()) { configuration *c = NULL; try { getline(conf_file,temp); temp = temp.substr(0,temp.find("#")); if (temp=="") continue; string val = temp.substr(temp.find("=")+1,string::npos); unsigned separator=temp.find("="); unsigned pos=0; while (pos!=string::npos && pos < separator) { string prop = temp.substr(0,temp.find(".")); #ifdef DEBUG_MAX cerr << prop << "."; #endif if (c==NULL) { c = &conf[prop]; } else { configuration *t; t = c; c = &c->conf[prop]; } c->path = prop; if(temp.substr(0,temp.find("=")).find(".")==string::npos) break; // look for . before = if cannot find break temp = temp.substr(temp.find(".")+1,string::npos); pos = temp.find("."); separator=temp.find("="); } string prop = temp.substr(0,temp.find("=")); if(prop == string("$")) { stringstream ss; index = 1; ss << index++; ss >> prop; } if(prop == string("%")) { stringstream ss; ss << index++; ss >> prop; } #ifdef DEBUG_MAX cerr << prop << "\t\t=\t" << val << endl; #endif if (c==NULL) { conf[prop].data=val; conf[prop].path=prop; } else { (c->conf[prop]).data=val; (c->conf[prop]).path= prop; } } catch (std::exception e) {
int conf_parse(struct mip6_config *c, int argc, char **argv) { char cfile[MAXPATHLEN]; int ret; /* set config defaults */ conf_default(c); if ((ret = conf_alt_file(cfile, argc, argv)) != 0) { if (ret == -EINVAL) { fprintf(stderr, "%s: option requires an argument -- c\n", argv[0]); conf_usage(basename(argv[0])); return -1; } else if (ret == -ENAMETOOLONG) { fprintf(stderr, "%s: argument too long -- c <file>\n", argv[0]); return -1; } strcpy(cfile, DEFAULT_CONFIG_FILE); } if (conf_file(c, cfile) < 0 && ret == 0) return -1; if (conf_cmdline(c, argc, argv) < 0) return -1; return 0; }
rdConfUnit* rdConfLoader::load_conf(const char* conf_filename) { std::ifstream conf_file(conf_filename, std::ifstream::in); if (conf_file.fail()) { return NULL; } char line[MAX_LINE_LEN]; rdConfUnit* root = new(std::nothrow) rdConfUnit(rdConfUnit::UT_GROUP); if (NULL != root) { rdConfUnit* current = root; while (conf_file.good()) { conf_file.getline(line, MAX_LINE_LEN); if (is_white_line(line) || is_comment_line(line)) { continue; } if (0 != handle_line(line, root, current)) { delete root; root = NULL; break; } } } conf_file.close(); return root; }
/** * Read a configuration file. * * This function is guaranteed to read in all syntactically correct files, but * might also accept others. */ Conf::Conf(const char *config_fn) { // open the file std::ifstream conf_file(config_fn); if (!conf_file) throw std::runtime_error(std::string("Couldn't open config file '") + config_fn + '\''); // Read every line and put it in the list. char line[LINE_LENGTH]; std::string name; // parse: first comes the name of the command while (conf_file >> name) { // if line starts with '#', ignore it if (name[0] == '#') { conf_file.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); continue; } conf_file.ignore(std::numeric_limits<std::streamsize>::max(), '='); conf_file.ignore(std::numeric_limits<std::streamsize>::max(), ' '); conf_file.getline(line, LINE_LENGTH); DEBUG_PRINT("[Conf] " << name << " = " << line); // Write into attribute list attributes.emplace_back(name, std::string(line)); } }
int main(int argc, char *argv[]) { QLocale::setDefault(QLocale::C); QApplication a(argc, argv); QString configpath; #ifdef _WIN32 configpath = QFileInfo(QDir::currentPath(), ("mathmech.ini")).absoluteFilePath(); #elif __linux configpath = QFileInfo(QDir(QDir::homePath() + "/.config"), ("mathmech.conf")).absoluteFilePath(); #else return; #endif QFile conf_file(configpath); conf_file.open(QIODevice::ReadOnly | QIODevice::Text); QString language, text; QTextStream out(&conf_file); while (!out.atEnd()) { text = out.readLine(); if (text.contains(QString("LANG="))) language = text.split(QString("LANG="), QString::SkipEmptyParts)[0]; } conf_file.close(); QTranslator translator; translator.load(QString(":/translations/") + language); a.installTranslator(&translator); MainWindow w; w.show(); return a.exec(); }
int main(int argc, char **argv) { // we don't use printf so make cout/cerr a little bit faster std::ios_base::sync_with_stdio(false); conf = new config(); bool verbose = false, conf_arg = false; std::string conf_file_path("./ocelot.conf"); for (int i = 1; i < argc; i++) { if (!strcmp(argv[i], "-v")) { verbose = true; } else if (!strcmp(argv[i], "-c") && i < argc - 1) { conf_arg = true; conf_file_path = argv[++i]; } else { std::cout << "Usage: " << argv[0] << " [-v] [-c configfile]" << std::endl; return 0; } } std::ifstream conf_file(conf_file_path); if (conf_file.fail()) { std::cout << "Using default config because '" << conf_file_path << "' couldn't be opened" << std::endl; if (!conf_arg) { std::cout << "Start Ocelot with -c <path> to specify config file if necessary" << std::endl; } } else { conf->load(conf_file_path, conf_file); } db = new mysql(conf); if (!db->connected()) { std::cout << "Exiting" << std::endl; return 0; } db->verbose_flush = verbose; sc = new site_comm(conf); sc->verbose_flush = verbose; user_list users_list; torrent_list torrents_list; std::vector<std::string> whitelist; db->load_users(users_list); db->load_torrents(torrents_list); //db->load_whitelist(whitelist); stats.open_connections = 0; stats.opened_connections = 0; stats.connection_rate = 0; stats.requests = 0; stats.request_rate = 0; stats.leechers = 0; stats.seeders = 0; stats.announcements = 0; stats.succ_announcements = 0; stats.scrapes = 0; stats.bytes_read = 0; stats.bytes_written = 0; stats.start_time = time(NULL); // Create worker object, which handles announces and scrapes and all that jazz work = new worker(conf, torrents_list, users_list, whitelist, db, sc); // Create schedule object sched = new schedule(conf, work, db, sc); // Create connection mother, which binds to its socket and handles the event stuff mother = new connection_mother(conf, work, db, sc, sched); // Add signal handlers now that all objects have been created struct sigaction handler, ignore; ignore.sa_handler = SIG_IGN; handler.sa_handler = sig_handler; sigemptyset(&handler.sa_mask); handler.sa_flags = 0; sigaction(SIGINT, &handler, NULL); sigaction(SIGTERM, &handler, NULL); sigaction(SIGHUP, &handler, NULL); sigaction(SIGUSR1, &handler, NULL); sigaction(SIGUSR2, &ignore, NULL); mother->run(); return 0; }
int main(void) { std::vector<std::string> printvec = { "Database name? (Nothing = 'postgres')\n> ", "User? (Nothing = 'postgres')\n> ", "Password? (Nothing = '')\n> ", "Host address? (Nothing = '127.0.0.1')\n> ", "Port? (Nothing = '5432')\n> " }; std::vector<std::string> confvec = {"", "", "", "", ""}; //Iterate through each line of printing. //Store it in a vector. for(size_t a = 0; a < printvec.size(); a++) { pstring(printvec[a]); std::getline(std::cin, confvec[a]); } //String that holds connection info. std::string connstring = ""; //Iterates though input and builds the connection string. for(size_t b = 0; b < printvec.size(); b++) { //Create string for current loop object. const std::string ¤t_thing = confvec[b]; //Function to append and space an input answer. auto append_conf = [&]() { connstring += current_thing; connstring += " "; }; switch(b) { case 0: if(current_thing == "") { connstring += "dbname=postgres "; } else { connstring += "dbname="; append_conf(); } break; case 1: if(current_thing == "") { connstring += "user=postgres "; } else { connstring += "user="******"") { connstring += "password="******"") { connstring += "hostaddr=127.0.0.1 "; } else { connstring += "hostaddr="; append_conf(); } break; case 4: if(current_thing == "") { connstring += "port=5432"; } else { connstring += "port="; connstring += current_thing; } break; default: //This area of code should never be reached. pstring_n("Error: b is beyond 4."); return 1; break; } } //Display built configuration string. pstring_n("Configuration set: " + connstring); if(answer("Do you wish to test the connection")) { pqxx::connection conn(connstring); if(conn.is_open()) { std::cout << "Connection to database " << conn.dbname() << " works." << std::endl; } conn.disconnect(); //If there is a problem, an exception will be thrown. //Since the program will need to kill itself anyways, I won't bother adding an exception catcher. } if(answer("Save configuration")) { //Overwrite old file. std::ofstream conf_file("pqxxconn.conf"); if(conf_file.is_open()) { conf_file << connstring; } else { pstring_n("Could not open 'pqxxconn.conf'."); } conf_file.close(); } return 0; }
int main(int argc, char **argv) { std::vector<int> p_file_indices_conf = pcl::console::parse_file_extension_argument (argc, argv, ".conf"); std::string output_directory = "."; pcl::console::parse_argument (argc, argv, "--directory", output_directory); for (int i = 0; i < p_file_indices_conf.size(); ++i) { QFile conf_file(argv[p_file_indices_conf[i]]); if(conf_file.open(QIODevice::ReadOnly)) { QTextStream in(&conf_file); while(!in.atEnd()) { QString line = in.readLine(); //qDebug() << line; QStringList list = line.split(" "); if (list[0] == "camera" || list[0] == "mesh") continue; if (list[0] == "bmesh") { QString ply_file = list[1]; float tx = list[2].toFloat(); float ty = list[3].toFloat(); float tz = list[4].toFloat(); float qi = list[5].toFloat(); float qj = list[6].toFloat(); float qk = list[7].toFloat(); float ql = list[8].toFloat(); Eigen::Matrix4f transformation = Eigen::Matrix4f::Identity(); Eigen::Vector3f translation = Eigen::Vector3f(tx, ty, tz); Eigen::Quaternionf quaternion = Eigen::Quaternionf(qi, qj, qk, ql); transformation.block<3,3>(0,0) = quaternion.toRotationMatrix(); transformation.block<3,1>(0,3) = translation; QFileInfo fileInfo(ply_file); CloudIO::exportTransformation(QString(output_directory.c_str()) + "/" + fileInfo.completeBaseName() + ".tf", transformation); } } } } // pcl::PLYReader reader; // pcl::PolygonMesh mesh; // reader.read("dragonStandRight_0_out.ply", mesh); // std::cout << mesh.cloud.height << std::endl; // std::cout << mesh.cloud.width << std::endl; // QFileInfo info("dragonStandRight_0_out.ply"); // pcl::io::savePLYFile((info.path() + "/" + info.completeBaseName() + "_transformed.ply").toStdString(), mesh); // pcl::PLYReader reader; // pcl::PointCloud<pcl::PointXYZRGBNormal> cloud; // reader.read("bun000.ply", cloud); // std::cout << cloud << std::endl; // // pcl::PLYWriter writer; // // writer.write("bun000_out_out.ply", cloud); // pcl::PCDWriter writer; // writer.write("bun000.pcd", cloud); // pcl::PLYReader reader; // pcl::PolygonMesh mesh; // reader.read("bun000_meshlab.ply", mesh); // std::cout << mesh.cloud.height << std::endl; // std::cout << mesh.cloud.width << std::endl; // pcl::visualization::PCLVisualizer visualizer; // visualizer.addPolygonMesh(mesh); // visualizer.spin(); // std::cout << mesh.polygons.size() << std::endl; // for (int i = 0; i < 10; ++i) // { // std::cout << mesh.polygons[i].vertices.size() << std::endl; // for (int j = 0; j < mesh.polygons[i].vertices.size(); ++j) // { // std::cout << mesh.polygons[i].vertices[j] << " "; // } // std::cout << std::endl; // } // for (int i = 0; i < p_file_indices_conf.size(); ++i) // { // CloudDataPtr cloudData(new CloudData); // Eigen::Matrix4f transformation; // BoundariesPtr boundaries(new Boundaries); // QString fileName = QString(argv[p_file_indices_ply[i]]); // CloudIO::importCloudData(fileName, cloudData); // CloudIO::importTransformation(fileName, transformation); // CloudIO::importBoundaries(fileName, boundaries); // Cloud* cloud = cloudManager->addCloud(cloudData, Cloud::fromIO, fileName, transformation); // cloud->setBoundaries(boundaries); // } // float angleThreshold = 10.0f; // pcl::console::parse_argument (argc, argv, "--angle", angleThreshold); // angleThreshold = angleThreshold / 180 * M_PI; // float distanceThreshold = 0.01f; // pcl::console::parse_argument (argc, argv, "--distance", distanceThreshold); // QList<Cloud*> cloudList = cloudManager->getAllClouds(); // for (int i = 0; i < cloudList.size(); ++i) // { // Cloud *cloud = cloudList[i]; // Eigen::Matrix4f transformation = cloud->getTransformation(); // Eigen::Matrix4f randomRigidTransf = randomRigidTransformation(angleThreshold, distanceThreshold); // cloud->setTransformation(randomRigidTransf * transformation); // std::cout << randomRigidTransf << std::endl; // } // for (int i = 0; i < cloudList.size(); ++i) // { // Cloud *cloud = cloudList[i]; // QString cloudName = cloud->getCloudName(); // CloudDataPtr cloudData = cloud->getCloudData(); // Eigen::Matrix4f transformation = cloud->getTransformation(); // BoundariesPtr boundaries = cloud->getBoundaries(); // QString fileName = cloud->getFileName(); // QFileInfo fileInfo(fileName); // QString newFileName = fileInfo.path() + "/" + fileInfo.baseName() + "_out.ply"; // CloudIO::exportCloudData(newFileName, cloudData); // CloudIO::exportTransformation(newFileName, transformation); // CloudIO::exportBoundaries(newFileName, boundaries); // CloudIO::exportCloudData(newFileName, cloudData); // } return 0; }
/*********************************************************************** * Generates randomized series with normal gaussian sources of given * mean and std.dev. Puts the series to output. ***********************************************************************/ int main (int argc, char* argv[]) { if(argc != 3 && argc != 4 && argc != 5) { fprintf(stderr, "Error: need 2, 3 or 4 arguments\n"); fprintf(stderr, "Usage: drand Length Mean StdDev [DiscrTrFunc]\n"\ " or drand InputSeries DiscrTrFunc\n"\ "DRAND_SAFE=something to avoid the same seed in srand()\n"); return 1; } NaOpenLogFile("drand.log"); int length; float mean; float stddev; char *dtf_file = NULL; NaDataFile *ins = NULL; if(argc == 3) { ins = OpenInputDataFile(argv[1]); dtf_file = argv[2]; } else { length = atol(argv[1]); mean = atof(argv[2]); stddev = atof(argv[3]); if(argc == 5) dtf_file = argv[4]; } try{ int i; NaTransFunc dtf; /* K=1 */ if(NULL != dtf_file) { NaConfigPart *conf_list[] = { &dtf }; NaConfigFile conf_file(";NeuCon transfer", 1, 0); conf_file.AddPartitions(NaNUMBER(conf_list), conf_list); conf_file.LoadFromFile(dtf_file); } if(NULL == ins) { // See DRAND_SAFE to prevent dependent random series reset_rand(); } else { ins->GoStartRecord(); length = ins->CountOfRecord(); } dtf.Reset(); for(i = 0; i < length; ++i) { NaReal fRand, fOut; if(NULL == ins) fRand = rand_gaussian(mean, stddev); else { fRand = ins->GetValue(); ins->GoNextRecord(); } dtf.Function(&fRand, &fOut); printf("%g\n", fOut); } delete ins; } catch(NaException& ex){ NaPrintLog("EXCEPTION: %s\n", NaExceptionMsg(ex)); } return 0; }