| 37 | } |
| 38 | |
| 39 | bool file_tmpl::copy_and_replace(const char* from, |
| 40 | const char* to, bool exec /* = false */) |
| 41 | { |
| 42 | tpl_t* tpl = open_tpl(from); |
| 43 | if (tpl == NULL) { |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | tpl_set_field_fmt_global(tpl, "PROGRAM", "%s", project_name_.c_str()); |
| 48 | |
| 49 | string filepath; |
| 50 | filepath << path_to_ << '/' << to; |
| 51 | if (tpl_save_as(tpl, filepath.c_str()) != TPL_OK) { |
| 52 | printf("save to %s error: %s\r\n", filepath.c_str(), |
| 53 | last_serror()); |
| 54 | tpl_free(tpl); |
| 55 | return false; |
| 56 | } |
| 57 | printf("create %s ok.\r\n", filepath.c_str()); |
| 58 | tpl_free(tpl); |
| 59 | |
| 60 | if (exec) { |
| 61 | #ifndef WIN32 |
| 62 | chmod(filepath.c_str(), S_IRUSR | S_IWUSR | S_IXUSR | |
| 63 | S_IRGRP | S_IWGRP | S_IXGRP); |
| 64 | #endif |
| 65 | } |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | void file_tmpl::create_dirs() |
| 70 | { |
no test coverage detected