int kpr_read_config(KPR *kpr) { FILE *kpr_fp; char name[1024]={0}; char path[1024]={0}; char arg[1024]={0}; KPR *node; kpr_fp=fopen(KPR_CONFIG_PATH,"rb"); if(kpr_fp == NULL) return -1; while(!feof(kpr_fp)) { fscanf(kpr_fp,"%s",name); fscanf(kpr_fp,"%s",path); fgets(arg,sizeof(arg)-1,kpr_fp); to_replace(name,sizeof(name)); to_replace(path,sizeof(path)); to_replace(arg,sizeof(arg)); if(name[0] == '\0' || path[0] == '\0' || arg[0] == '\0') continue; node=malloc(sizeof(KPR)); node->pid=-1; node->name=string_add("%s",name); node->path=string_add("%s",path); if(strcmp(arg,"NULL") == 0) node->arg=NULL; else node->arg=string_add("%s",arg); node->next=NULL; kpr->next=node; kpr=kpr->next; bzero(name,sizeof(name)); bzero(path,sizeof(path)); bzero(arg,sizeof(arg)); } fclose(kpr_fp); return 0; }
int main(int ac, char **av) { if (ac == 4) { std::ifstream ifs(av[1]); std::string to_replace(av[2]); std::string by_replace(av[3]); if (ifs.is_open()) { ifs.seekg(0, std::ios::end); size_t size = ifs.tellg(); ifs.seekg(0, std::ios::beg); char buffer[size + 1]; ifs.read(buffer, size); buffer[size] = 0; std::string buff(buffer); size_t pos = 0; while ((pos = buff.find(to_replace, pos)) != std::string::npos) { buff.replace(pos, to_replace.length(), by_replace); pos += by_replace.length(); } std::ofstream ofs((std::string(av[1]) + ".replace").c_str()); if (ofs.is_open()) { ofs << buff; ofs.close(); } else { std::cerr << "Cannot open output file" << std::endl; return (3); } ifs.close(); return (0); } else { std::cerr << "Cannot open input file" << std::endl; return (2); } } std::cerr << "usage: " << av[0] << " <filename> <string_to_replace> <string_for_replace>" << std::endl; return (1); }
// replaces underscores in render algorithms variable names by blanks const QString AlgorithmWidget::nice_name(const char* name) { std::string to_replace(name); replace( to_replace.begin(), to_replace.end(), '_', ' ' ); return QString(to_replace.c_str()); }