#!/usr/bin/python
import os
import re
def main():
r_model = re.compile( '([\S]*)[\s]*(.*)' )
i = open( 'model.txt', 'rt' )
o = open( 'model.cpp', 'wt' )
models = ''
for line in i.readlines():
line = line.strip()
if len( line ) > 0 and line[0] != '#':
m = r_model.match( line )
models += '\t{ "%s", "%s" },\n' % ( m.group(1), m.group(2) )
o.write( '''/*
model.cpp -- AUTOMATICALLY GENERATED; DO NOT EDIT.
Copyright 2006 John Poole.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "model.h"
struct Model {
std::string id;
std::string name;
};
static Model models[] = {
''' + models + '''
\t{ "", "" }
};
std::string getModelName( std::string id )
{
std::string name = id;
for( int i = 0; models[i].id.length() > 0; i++ ) {
if( models[i].id == id ) {
name = models[i].name;
break;
}
}
return name;
}
''' )
if __name__ == '__main__':
main()