00001 /* Copyright (C) 2003 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 #include <ndb_global.h> 00018 #include <ndb_version.h> 00019 #include <mgmapi_configuration.hpp> 00020 00021 #include <NdbMain.h> 00022 #include <Properties.hpp> 00023 00024 #include "InitConfigFileParser.hpp" 00025 #include <Config.hpp> 00026 00027 void usage(const char * prg){ 00028 ndbout << "Usage " << prg << ": <Init config> <Binary file>" << endl; 00029 00030 } 00031 00032 NDB_COMMAND(mkconfig, 00033 "mkconfig", "mkconfig", 00034 "Make a binary configuration from a config file", 16384){ 00035 ndb_init(); 00036 if(argc < 3){ 00037 usage(argv[0]); 00038 return 0; 00039 } 00040 00041 InitConfigFileParser parser; 00042 Config* _cp; 00043 00044 if ((_cp = parser.parseConfig(argv[1])) == 0) 00045 return false; 00046 00047 ConfigValues* cp = &_cp->m_configValues->m_config; 00048 Uint32 sz = cp->getPackedSize(); 00049 UtilBuffer buf; 00050 if(!cp->pack(buf)) 00051 return -1; 00052 00053 FILE * f = fopen(argv[2], "w"); 00054 if(fwrite(buf.get_data(), 1, buf.length(), f) != sz){ 00055 fclose(f); 00056 unlink(argv[2]); 00057 return -1; 00058 } 00059 fclose(f); 00060 return 0; 00061 }
1.4.7

