diff --git a/STYLEGUIDE.md b/STYLEGUIDE.md index df16f2c6..3d012d6e 100644 --- a/STYLEGUIDE.md +++ b/STYLEGUIDE.md @@ -58,9 +58,8 @@ spot such a pattern, feel free to send a PR to update the guide. Line length is 100 characters. In rare situations, like the collision table at the top of -[engine_collision_driver.c](https://github.com/deepmind/mujoco/search?q=repo%3Ad -eepmind%2Fmujoco+filename%3Aengine_collision_driver.c), longer lines are alowed -for readability. +[engine_collision_driver.c](https://github.com/deepmind/mujoco/blob/c8ff7b3d341560e8cc33fbdcaffbcdbc4c32327c/src/engine/engine_collision_driver.c#L36), +longer lines are alowed for readability. #### Comments diff --git a/sample/compile.cc b/sample/compile.cc index 61dc1495..b7fb7c12 100644 --- a/sample/compile.cc +++ b/sample/compile.cc @@ -14,17 +14,17 @@ #include #include -#include #include +#include #include // help -const char helpstring[] = +static constexpr char helpstring[] = "\n Usage: compile infile outfile\n" " infile can be in mjcf, urdf, mjb format\n" " outfile can be in mjcf, mjb, txt format\n\n" - " Example: compile model.xml model.mjb\n"; + " Example: compile model.xml model.mjb\n"; // deallocate and print message @@ -36,7 +36,7 @@ int finish(const char* msg = 0, mjModel* m = 0) { // print message if (msg) { - std::printf("%s\n", msg); + std::cout << msg << std::endl; } return 0; @@ -109,11 +109,16 @@ int main(int argc, const char** argv) { return finish("Illegal combination of file formats"); } - // make sure output file does not exist + // check if output file exists std::FILE* fp = std::fopen(argv[2], "r"); if (fp) { - std::fclose(fp); - return finish("Output file already exists"); + std::cout << "Output file already exists, overwrite? (Y/n) "; + char c; + std::cin >> c; + if (c!='y' && c!='Y') { + std::fclose(fp); + return finish(); + } } // load model @@ -134,7 +139,7 @@ int main(int argc, const char** argv) { // save model if (type2==typeXML) { - if (mj_saveLastXML(argv[2], m, error, 1000)) { + if (!mj_saveLastXML(argv[2], m, error, 1000)) { return finish(error, m); } } else if (type2==typeMJB) { diff --git a/src/xml/xml_api.cc b/src/xml/xml_api.cc index ae9abe53..48497508 100644 --- a/src/xml/xml_api.cc +++ b/src/xml/xml_api.cc @@ -120,6 +120,8 @@ mjModel* mj_loadXML(const char* filename, const mjVFS* vfs, // update XML data structures with info from low-level model, save as MJCF +// returns 1 if successful, 0 otherwise +// error can be NULL; otherwise assumed to have size error_sz int mj_saveLastXML(const char* filename, const mjModel* m, char* error, int error_sz) { // serialize access to themodel std::lock_guard lock(themutex);