int main( int argc, char** argv ) { screen s; struct matrix *edges; struct matrix *transform; edges = new_matrix(4, 4); transform = new_matrix(4, 4); if ( argc == 2 ) parse_file( argv[1], transform, edges, s ); else parse_file( "stdin", transform, edges, s ); free_matrix( transform ); free_matrix( edges ); }
void wav_reader_c::read_headers() { if (!wav_reader_c::probe_file(m_in.get(), m_size)) throw mtx::input::invalid_format_x(); parse_file(); create_demuxer(); }
/* * Read the INI files for device-specific values and save them in * internal data structures for later lookup. */ int ompi_btl_wv_ini_init(void) { int ret = OMPI_ERR_NOT_FOUND; char *colon; char separator = ';'; OBJ_CONSTRUCT(&devices, opal_list_t); colon = strchr(mca_btl_wv_component.device_params_file_names, separator); if (NULL == colon) { /* If we've only got 1 file (i.e., no colons found), parse it and be done */ ret = parse_file(mca_btl_wv_component.device_params_file_names); } else { /* Otherwise, loop over all the files and parse them */ char *orig = strdup(mca_btl_wv_component.device_params_file_names); char *str = orig; while (NULL != (colon = strchr(str, ':'))) { *colon = '\0'; ret = parse_file(str); /* Note that NOT_FOUND and SUCCESS are not fatal errors and we keep going. Other errors are treated as fatal */ if (OMPI_ERR_NOT_FOUND != OPAL_SOS_GET_ERROR_CODE(ret) && OMPI_SUCCESS != ret) { break; } str = colon + 1; } /* Parse the last file if we didn't have a fatal error above */ if (OMPI_ERR_NOT_FOUND != OPAL_SOS_GET_ERROR_CODE(ret) && OMPI_SUCCESS != ret) { ret = parse_file(str); } /* All done */ free(orig); } /* Return SUCCESS unless we got a fatal error */ initialized = true; return (OMPI_SUCCESS == ret || OMPI_ERR_NOT_FOUND == OPAL_SOS_GET_ERROR_CODE(ret)) ? OMPI_SUCCESS : ret; }
void xml_configuration::parse_all() { for (auto && file : _files) { auto result = parse_file(file); if (!result.empty()) // no need to throw because desperion has default values for config options std::cerr << "parsing failed " << file << ": " << result << std::endl; } }
void make_makefile(char* module_name) { printf("Make Makefile %s/%s/Makefile \n",out_dir,module_name); char buf[4096] = {0}; FILE *fp = NULL ; char new_file_name[128]; char *replace_args[] = {"{{src_dir}}",src_dir,"{{module_name}}",module_name}; sprintf(new_file_name,"%s/%s/Makefile",out_dir,module_name); parse_file("tpls/Makefile.tpl",new_file_name,replace_args,4); }
/** * @short Bulk converts all files at dirname, excepting *~, and the creates a handler for such directory. */ void parse_directory(const char *prefix, const char *dirname, FILE * outfd, onion_assets_file * assets) { DIR *dir = opendir(dirname); if (!dir) { fprintf(stderr, "ERROR: Could not open directory %s, check permissions.", dirname); exit(4); } // First create other files/dirs struct dirent *de; char fullname[1024]; while ((de = readdir(dir))) { if (de->d_name[0] == '.' || de->d_name[strlen(de->d_name) - 1] == '~') continue; snprintf(fullname, sizeof(fullname), "%s/%s", dirname, de->d_name); if (de->d_type == DT_DIR) { char prefix2[256]; snprintf(prefix2, sizeof(prefix2), "%s/%s", prefix, de->d_name); parse_directory(prefix2, fullname, outfd, assets); } else parse_file(prefix, fullname, outfd, assets); } closedir(dir); // Now create current char *fname = funcname(prefix, NULL); snprintf(fullname, sizeof(fullname), "onion_connection_status %s(void *_, onion_request *req, onion_response *res);", fname); onion_assets_file_update(assets, fullname); fprintf(stderr, "Parsing directory: %s to '%s'.\n", dirname, fullname); fprintf(outfd, "onion_connection_status %s(void *_, onion_request *req, onion_response *res){\n", fname); fprintf(outfd, " const char *path=onion_request_get_path(req);\n\n"); dir = opendir(dirname); while ((de = readdir(dir))) { if (de->d_name[0] == '.' || de->d_name[strlen(de->d_name) - 1] == '~') continue; char *fname = funcname(prefix, de->d_name); if (de->d_type == DT_DIR) { int l = strlen(de->d_name); fprintf(outfd, " if (strncmp(\"%s/\", path, %d)==0){\n", de->d_name, l + 1); fprintf(outfd, " onion_request_advance_path(req, %d);\n", l + 1); } else fprintf(outfd, " if (strcmp(\"%s\", path)==0){\n", de->d_name); fprintf(outfd, " return %s(_, req, res);\n", fname); fprintf(outfd, " }\n"); free(fname); } closedir(dir); fprintf(outfd, " return OCS_NOT_PROCESSED;\n"); fprintf(outfd, "}\n\n"); free(fname); }
int main(int argc, char *argv[]) { // needs at least 1 argument if (argc < 2) { fprintf(stderr, "Usage:\n" " makelist <source.lst>\n" ); return 0; } // extract arguments const char *srcfile = argv[1]; // parse the root file, exit early upon failure drivcount = 0; ignorecount = 0; if (parse_file(srcfile)) return 1; // output a count if (drivcount == 0) { fprintf(stderr, "No drivers found\n"); return 1; } fprintf(stderr, "%d drivers found\n", drivcount); // add a reference to the ___empty driver drivlist[drivcount++] = "___empty"; // sort the list qsort(drivlist, drivcount, sizeof(*drivlist), sort_callback); // start with a header printf("#include \"emu.h\"\n\n"); printf("#include \"drivenum.h\"\n\n"); // output the list of externs first for (int index = 0; index < drivcount; index++) printf("GAME_EXTERN(%s);\n", drivlist[index]); printf("\n"); // then output the array printf("const game_driver * const driver_list::s_drivers_sorted[%d] =\n", drivcount); printf("{\n"); for (int index = 0; index < drivcount; index++) printf("\t&GAME_NAME(%s)%s\n", drivlist[index], (index == drivcount - 1) ? "" : ","); printf("};\n"); printf("\n"); // also output a global count printf("int driver_list::s_driver_count = %d;\n", drivcount); return 0; }
void TestRenumber::testMerge() { QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml"), 0); process_dives(true, false); QCOMPARE(dive_table.nr, 1); QCOMPARE(unsaved_changes(), 1); mark_divelist_changed(false); dive_table.preexisting = dive_table.nr; }
void parse_configuration(struct ccx_s_options *opt) { FILE *f = NULL; if( (f = fopen(CNF_FILE,"r") ) != NULL) { parse_file(f,opt); fclose(f); } }
int main( int argc, char** argv ) { screen s; struct matrix *edges; struct matrix *transform; color c; c.red = 0; c.green = 255; c.blue = 255; edges = new_matrix(4, 4); transform = new_matrix(4, 4); if ( argc == 2 ) parse_file( argv[1], transform, edges, s ); else parse_file( "stdin", transform, edges, s ); add_edge( edges, 250,0,0, 250,25,0 );//M add_edge( edges, 250,25,0, 263,0,0 ); add_edge( edges, 263,0,0, 275,25,0 ); add_edge( edges, 275,25,0, 275,0,0 ); add_edge( edges, 280,0,0, 293,25,0 );//A add_edge( edges, 293,25,0, 305,0,0 ); add_edge( edges, 287,13,0, 299,13,0 ); add_edge( edges, 310,0,0, 325,25,0 );//Y add_edge( edges, 318,13,0, 305,25,0 ); add_edge( edges, 330,0,0, 343,25,0 );//A add_edge( edges, 343,25,0, 355,0,0 ); add_edge( edges, 337,13,0, 349,13,0 ); add_edge( edges, 360,0,0, 360,25,0 );//N add_edge( edges, 360,25,0, 385,0,0 ); add_edge( edges, 385,0,0, 385,25,0 ); add_edge( edges, 390,0,0, 390,25,0 );//K add_edge( edges, 390,13,0, 408,25,0 ); add_edge( edges, 395,14,0, 408,0,0 ); draw_lines(edges, s, c); save_extension(s, "dimensional.png"); display(s); free_matrix( transform ); free_matrix( edges ); }
static int parse_document( fs::path const& filein_ , fs::path const& fileout_ , fs::path const& deps_out_ , fs::path const& locations_out_ , fs::path const& xinclude_base_ , int indent , int linewidth , bool pretty_print) { string_stream buffer; id_manager ids; int result = 0; try { quickbook::state state(filein_, xinclude_base_, buffer, ids); set_macros(state); if (state.error_count == 0) { state.add_dependency(filein_); state.current_file = load(filein_); // Throws load_error parse_file(state); if(state.error_count) { detail::outerr() << "Error count: " << state.error_count << ".\n"; } } result = state.error_count ? 1 : 0; if (!deps_out_.empty()) { fs::ofstream out(deps_out_); BOOST_FOREACH(quickbook::state::dependency_list::value_type const& d, state.dependencies) { if (d.second) { out << detail::path_to_generic(d.first) << std::endl; } } } if (!locations_out_.empty()) { fs::ofstream out(locations_out_); BOOST_FOREACH(quickbook::state::dependency_list::value_type const& d, state.dependencies) { out << (d.second ? "+ " : "- ") << detail::path_to_generic(d.first) << std::endl; } }
/** * @brief writeFile a profile string to a ini file * @param section [in] name of the section,can't be NULL and empty string * @param key [in] name of the key pairs to value, can't be NULL and empty string * @param value [in] profile string value * @param file [in] path of ini file * @return 1 : success\n 0 : failure */ int write_profile_string(const char *section, const char *key, const char *value, const char *file) { char buf[MAX_FILE_SIZE] = {0}; char w_buf[MAX_FILE_SIZE] = {0}; int sec_s, sec_e, key_s, key_e, value_s, value_e; int value_len = (int) strlen(value); int file_size; FILE *out; //check parameters assert(section != NULL && strlen(section)); assert(key != NULL && strlen(key)); assert(value != NULL); assert(file != NULL && strlen(key)); if (!load_ini_file(file, buf, &file_size)) { sec_s = -1; } else { parse_file(section, key, buf, &sec_s, &sec_e, &key_s, &key_e, &value_s, &value_e); } if (-1 == sec_s) { if (0 == file_size) { sprintf(w_buf + file_size, "[%s]\n%s=%s\n", section, key, value); } else { //not find the section, then add the new section at end of the file memcpy(w_buf, buf, file_size); sprintf(w_buf + file_size, "\n[%s]\n%s=%s\n", section, key, value); } } else if (-1 == key_s) { //not find the key, then add the new key=value at end of the section memcpy(w_buf, buf, sec_e); sprintf(w_buf + sec_e, "%s=%s\n", key, value); sprintf(w_buf + sec_e + strlen(key) + strlen(value) + 2, buf + sec_e, file_size - sec_e); } else { //update value with new value memcpy(w_buf, buf, value_s); memcpy(w_buf + value_s, value, value_len); memcpy(w_buf + value_s + value_len, buf + value_e, file_size - value_e); } out = fopen(file, "w"); if (NULL == out) { return 0; } if (-1 == fputs(w_buf, out)) { fclose(out); return 0; } fclose(out); return 1; }
int mca_coll_ml_config_file_init(void) { int ret = OMPI_ERR_NOT_FOUND; ret = parse_file(mca_coll_ml_component.config_file_name); return (OMPI_SUCCESS == ret ) ? OMPI_SUCCESS : ret; }
void generate_file(const char *file_name, int article) { parsed_article *pa = parse_file(file_name); extend_buffer(article); parse_xrefs(pa); if (pa != NULL) { pa->article = article; generate_article(pa); } }
void gfp_load_files(const char **filelist, int n) { _byte_order = get_bit_endian(); _msg_defs._type = GF_PROTO_TYPE_ARRAY; _msg_defs._len = 0; for (int i = 0; i < n; i++) { parse_file(filelist[i]); } }
int parse_nf (char *string, List *list) { newts_nfref *ref = nfref_alloc (); char *copy; if (string == NULL || list == NULL) return -1; copy = newts_strdup (string); if (!pattern_flag) sense = PARSE_ADD; if (*copy == ':') { return parse_file (copy + 1, list); } if (*copy == '!') { char *change = newts_strdup (copy + 1); newts_free (copy); copy = change; sense = PARSE_DELETE; } if (!pattern_flag && (strchr (copy, '?') || strchr (copy, '[') || strchr (copy, '*') || strchr (copy, ' '))) { /* Pattern matching. */ int result; pattern_flag = TRUE; result = parse_pattern (copy, list); pattern_flag = FALSE; return result; } parse_single_nf (copy, ref); if (sense == PARSE_ADD) list_insert_next (list, list_tail (list), (void *) ref); else { list_remove_match (list, (void *) ref); nfref_free (ref); } newts_free (copy); return 0; }
/* * Read in the entire mtree file into memory on the first request. * Then use the next unused file to satisfy each header request. */ static int read_header(struct archive_read *a, struct archive_entry *entry) { struct mtree *mtree; char *p; int r, use_next; mtree = (struct mtree *)(a->format->data); if (mtree->fd >= 0) { close(mtree->fd); mtree->fd = -1; } if (mtree->entries == NULL) { mtree->resolver = archive_entry_linkresolver_new(); if (mtree->resolver == NULL) return ARCHIVE_FATAL; archive_entry_linkresolver_set_strategy(mtree->resolver, ARCHIVE_FORMAT_MTREE); r = read_mtree(a, mtree); if (r != ARCHIVE_OK) return (r); } a->archive.archive_format = mtree->archive_format; a->archive.archive_format_name = mtree->archive_format_name; for (;;) { if (mtree->this_entry == NULL) return (ARCHIVE_EOF); if (strcmp(mtree->this_entry->name, "..") == 0) { mtree->this_entry->used = 1; if (archive_strlen(&mtree->current_dir) > 0) { /* Roll back current path. */ p = mtree->current_dir.s + mtree->current_dir.length - 1; while (p >= mtree->current_dir.s && *p != '/') --p; if (p >= mtree->current_dir.s) --p; mtree->current_dir.length = p - mtree->current_dir.s + 1; } } if (!mtree->this_entry->used) { use_next = 0; r = parse_file(a, entry, mtree, mtree->this_entry, &use_next); if (use_next == 0) return (r); } mtree->this_entry = mtree->this_entry->next; } }
int main(int argc, char** argv) { std::cout << "Hello, world!" << std::endl; // setup signal interrupt handler signal(SIGINT, signal_callback_handler); // specify which options are available as cmd line arguments setupCmdLineReader(); // read agent id from command line parameters (--agent=mario) agent = readAgentFromCmdLine(argc, argv); // initialize the behavior tree client node ros::init(argc, argv, std::string("behavior_tree") + "_" + agent); // initialize OpenGL engine for visualization glut_setup(argc, argv); // point to the root of the behavior tree node_cursor = node = &root; node_cursor->set_highlighted(true); // create the bt from the file bt.txt (put on the path) std::cout << "----------------- PARSE FILE -----------------" << std::endl; parse_file(std::string("bt") + "_" + agent + ".txt"); // print the data parsed from the specification file std::cout << "----------------- PRINT TREE -----------------" << std::endl; root.print_subtree(); // wait until user inputs Enter to start std::cout << "Press Enter To Start" << std::endl; std::cin.get(); // start ticking the root of the tree at frequency: TICK_FREQUENCY while (ros::ok()) { std::cout << "**** run" << run << std::endl; std::cout << "-------------- EXECUTE TREE --------------" << std::endl; root.execute_reset_status(); root.execute(); // sending tick get_keypressed(); // processing keystrokes process_keypressed(); glut_process(); // update visualization glutPostRedisplay(); ros::Duration(1.0/TICK_FREQUENCY).sleep(); std::cout << "**** run" << run << std::endl; } // missing to clear the dynamically allocated tree // delete_tree(); return 0; }
int most_load_user_keymaps (void) { #ifndef VMS char filebuf[MAX_PATHLEN]; unsigned int len; #endif char *file; #ifdef MOST_SYSTEM_INITFILE if (MOST_SYSTEM_INITFILE != NULL) { int status; status = parse_file (MOST_SYSTEM_INITFILE); if (status == -1) return -1; } #endif if (NULL == (file = getenv ("MOST_INITFILE"))) { #ifdef VMS file = "SYS$LOGIN:MOST.RC"; #else *filebuf = 0; file = getenv ("HOME"); if (file == NULL) return -1; len = strlen (file); if (len + 8 >= sizeof (filebuf)) /* 8 for strlen("/.mostrc") */ return -1; strcpy (filebuf, file); file = filebuf; if (len && (file[len - 1] == '/')) len--; strcpy (file + len, "/.mostrc"); #endif } return parse_file (file); }
int main(int argc, const char *argv[]) { char *file; file = read_file(FILENAME); //printf("%s", file); parse_file(file); printf("The value of total_servers: %s\n", total_servers); sleep(100); return 0; }
void parse(FILE *fpin,FILE *fpout) { int nlines; nlines=parse_file(fpin,fpout,process_transition); fprintf(stderr,"%4d transitions parsed\n",nlines); fprintf(stderr,"Down-numbering .... (transitions)\n"); sort_transitions(); fprintf(stderr,"Combining .... (transitions)\n"); print_transitions(fpout); fprintf(stderr,"Done printing....\n"); }
/** *@brief read string in initialization file\n * retrieves a string from the specified section in an initialization file *@param section [in] name of the section containing the key name *@param key [in] name of the key pairs to value *@param value [in] pointer to the buffer that receives the retrieved string *@param size [in] size of result's buffer *@param default_value [in] default value of result *@param file [in] path of the initialization file *@return 1 : read success; \n 0 : read fail */ int read_profile_string( const char *section, const char *key,char *value, int size, const char *default_value, const char *file) { char *buf; int file_size; int sec_s,sec_e,key_s,key_e, value_s, value_e; //check parameters assert(section != NULL && strlen(section)); assert(key != NULL && strlen(key)); assert(value != NULL); assert(size > 0); assert(file !=NULL &&strlen(key)); buf = (char *)sys_malloc(MAX_FILE_SIZE); memset(buf,0,MAX_FILE_SIZE); if(!load_ini_file(file,buf,&file_size)) { if(default_value!=NULL) { strncpy(value,default_value, size); } sys_free(buf); return 0; } if(!parse_file(section,key,buf,&sec_s,&sec_e,&key_s,&key_e,&value_s,&value_e)) { if(default_value!=NULL) { strncpy(value,default_value, size); } sys_free(buf); return 0; //not find the key } else { int cpcount = value_e -value_s; if( size-1 < cpcount) { cpcount = size-1; } memset(value, 0, size); memcpy(value,buf+value_s, cpcount ); value[cpcount] = '\0'; sys_free(buf); return 1; } }
/* Win32 version */ static void process_directory (char *path, char *cvspath) { struct _finddata_t f; int findhandle; char searchbuf[MAX_PATH]; char buf[MAX_PATH]; char newcvspath[MAX_PATH]; strcpy(searchbuf, path); strcat(searchbuf, "*.*"); findhandle =_findfirst(searchbuf, &f); if (findhandle != -1) { do { if (f.attrib & _A_SUBDIR) { if (f.name[0] != '.') { strcpy(buf, path); strcat(buf, f.name); strcat(buf, DIR_SEPARATOR_STRING); strcpy(newcvspath, cvspath); strcat(newcvspath, f.name); strcat(newcvspath, "/"); process_directory(buf, newcvspath); } continue; } strcpy(buf, path); strcat(buf, f.name); /* Must be a .c file */ if (!is_valid_file(buf)) { continue; } parse_file(buf, cvspath, f.name); } while (_findnext(findhandle, &f) == 0); _findclose(findhandle); } else { printf("Cannot open directory '%s'", path); exit(1); } }
int cmd_testtools_batch_file(struct command_context *ctx ) { if (ctx->argc != 2) return CMD_ERROR_SYNTAX; int ret = parse_file(ctx->argv[1]); printf("Parsed %d lines in %s.\n", ret, ctx->argv[1]); return CMD_ERROR_NONE; }
void TestRenumber::testMergeAndAppend() { QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml"), 0); process_dives(true, false); QCOMPARE(dive_table.nr, 2); QCOMPARE(unsaved_changes(), 1); struct dive *d = get_dive(1); QVERIFY(d != NULL); if (d) QCOMPARE(d->number, 2); }
// Main function. int main(int argc, char *argv[]) { if (argc == 3) { parse_file(argv[1]); passing_automat(argv[2]); } else { fprintf(stderr, "Error: bad arguments!\n"); fprintf(stderr, "Example: ./history_fa parse_file data_file\n"); exit(1); } return 0; }
int open_file(t_tetrim *t, char const *file) { int fd; char *data; data = (char*)malloc(sizeof(char)); if ((fd = open(file, O_RDONLY)) == -1) return (-1); if (parse_file(t, fd, data) == -1) return (-1); return (0); }
int parse_cfg(zt_cfg_ty* cfg) { int ret = 0; FILE * file; if ((file = fopen(cfg->filename, "r")) == NULL) { return -1; } ret = parse_file(cfg, file); fclose(file); return ret; }
static void do_import_file(gpointer data, gpointer user_data) { GError *error = NULL; parse_file(data, &error); if (error != NULL) { report_error(error); g_error_free(error); error = NULL; } }
/******************************************************************* * main */ int main( int argc, char *argv[] ) { INCL_FILE *pFile; ProgramName = argv[0]; while (argc > 1) { if (*argv[1] == '-') parse_option( argv[1] ); else { pFile = add_src_file( argv[1] ); parse_file( pFile, 1 ); } argc--; argv++; } for (pFile = firstInclude; pFile; pFile = pFile->next) parse_file( pFile, 0 ); if( firstSrc ) output_dependencies(); return 0; }