char * java_path_from_java_home(){ char * path; char * jdk_bin_fullpath; char * jre_bin_fullpath; path = getenv("JAVA_HOME"); if (path == NULL) { return NULL; } if(!strcmp(JL_PLATFORM,"windows")){ jdk_bin_fullpath = merge_string(path, WIN_JDK_BIN); jre_bin_fullpath = merge_string(path, WIN_JRE_BIN); } else { jdk_bin_fullpath = merge_string(path, JDK_BIN); jre_bin_fullpath = merge_string(path, JRE_BIN); } if (!access(jdk_bin_fullpath,0)) { free(jre_bin_fullpath); return jdk_bin_fullpath; } else if (!access(jre_bin_fullpath,0)) { free(jdk_bin_fullpath); return jre_bin_fullpath; } free(jre_bin_fullpath); free(jdk_bin_fullpath); return NULL; }
static void test_string(void) { char *arr[] = { "liuwei", "suchuan", "linhaijin", "meidongting", "liuwei", "huzhaohui", "wangzhiqiang", "lijianhua", "maoxiaozhou", "qiaozhenghui", "hushengyang", "heshuangyang", "xiaohuajun", }; merge_string(arr, ELENUM(arr)); print_string(arr, ELENUM(arr)); }
std::pair<bool,std::vector<MergeConflict>> GitOpsWithTmp::merge(merge_style style) { if (style!=TRIAL_RUN) { assert(!parent->savePending()); parent->loadAll(); local_data.pull(); } common_history_ops.setModel(common_history_model=model::world_t()); common_history_ops.loadAll(); bool err=false; std::vector<MergeConflict> merge_list; model::world_t& common=common_history_model; model::world_t& remote=tmp_remote_model; model::world_t& local=*parent->model; //1. merge tmp (remote) model into parent (local) model //2. save local model //3. add/commit this model //4. pull to last_pull //first, merge world: merge_string(local.title, common.title,remote.title,local.title,style,err,merge_list, "World title"); merge_id(local.first_room,common.first_room,remote.first_room,local.first_room,style,err,merge_list,"ID of opening scenario"); //set world next_gid to the larger of the two: if (style!=TRIAL_RUN) local.next_rm_gid=std::max(local.next_rm_gid,remote.next_rm_gid); //now merge rooms: //only need to merge rooms that were in common; otherwise, they're new to both forks. //them add options just in remote for (auto iter_rm : common.rooms) { auto rm_id = iter_rm.first; //if room deleted in either fork, use non-deleted version. if (!remote.rooms.count(rm_id)) continue; if (!local.rooms.count(rm_id)) { local.rooms[rm_id]=remote.rooms[rm_id]; continue; } model::room_t& rm_common=iter_rm.second;//==common.rooms[rm_id] model::room_t& rm_remote=remote.rooms[rm_id]; model::room_t& rm_local = local.rooms[rm_id]; //merge room title merge_string(rm_local.title,rm_common.title,rm_remote.title,rm_local.title,style,err,merge_list,"Title of scenario id " + write_id(rm_id)); //merge room body merge_string(rm_local.body,rm_common.body,rm_remote.body,rm_local.body,style,err,merge_list,"Body text for scenario id " + write_id(rm_id)); //merge room options //only need to merge options that were in rm_common; otherwise, they're new to both forks. for (auto iter_opt : rm_common.options) { auto opt_id=iter_opt.first; //if option deleted in either fork, use non-deleted version if (!rm_remote.options.count(opt_id)) continue; if (!rm_local.options.count(opt_id)) { rm_local.options[opt_id]=rm_remote.options[opt_id]; continue; } model::option_t& opt_common=iter_opt.second;//==rm_common.options[opt_id] model::option_t& opt_remote=rm_remote.options[opt_id]; model::option_t& opt_local = rm_local.options[opt_id]; //merge option text: merge_string(opt_local.option_text,opt_common.option_text, opt_remote.option_text,opt_local.option_text,style,err,merge_list,"Option text for scenario id " + write_id(rm_id)); //merge option destination: merge_id(opt_local.dst,opt_common.dst,opt_remote.dst,opt_local.dst,style,err,merge_list, "Destination scenario id from an option in scenario id " + write_id(rm_id) + ", titled \"" + opt_local.option_text + "\" locally, \"" + opt_remote.option_text + "\" on remote, and previously titled \"" + opt_common.option_text + "\""); } //add options unique to remote for (auto iter_opt : rm_remote.options) if (!rm_common.options.count(iter_opt.first)) rm_local.options[iter_opt.first]=iter_opt.second; //merge room dead-end flag (set to false if options remaining) if (rm_local.options.size()) rm_local.dead_end=false; else merge_bool(rm_local.dead_end,rm_common.dead_end,rm_remote.dead_end,rm_local.dead_end, style,err,merge_list,"dead-end flag for scenario id " + write_id(rm_id)); } for (auto iter_rm : remote.rooms) if (!common.rooms.count(iter_rm.first)) local.rooms[iter_rm.first]=iter_rm.second; if (style==TRIAL_RUN) return {err,merge_list}; //save changes parent->saveAll(true); //add & commit local_data.addAll(); local_data.commit("merge result " + std::string(((err)?"(successful)":"(conflict. needs manual review)"))); //update last_pull. common_history.pull(); return {err,merge_list}; }