00001 /* 00002 * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc. 00003 * All rights reserved. This program is made available under the terms of the 00004 * Eclipse Public License v1.0 which accompanies this distribution, and is 00005 * available at http://www.eclipse.org/legal/epl-v10.html 00006 * Contributors: 00007 * The University of Tokyo 00008 */ 00009 /* 00010 * load.cpp 00011 * Create: Katsu Yamane, 03.12.02 00012 */ 00013 00014 #include "chain.h" 00015 00016 #define DEFAULT_LEX_LINE_BUFFER_SIZE (64*1024) 00017 00018 void ClearBuffer(); 00019 void ChainMakeLexerBuffers(int lexBufferSize, int lineBufferSize); 00020 void ChainSetInputFile(FILE *fp); 00021 int chparse(); 00022 void ChainDeleteLexerBuffers(); 00023 void SetCharName(const char* chname); 00024 void SetChain(Chain* ch); 00025 00026 int Chain::Load(const char* fname, const char* charname) 00027 { 00028 ClearBuffer(); 00029 FILE* fp = fopen(fname, "r"); 00030 if(!fp) 00031 { 00032 cerr << "Chain::Load- error: failed to open " << fname << " to read" << endl; 00033 return -1; 00034 } 00035 00036 fseek(fp, 0, SEEK_END); 00037 int lexBufferSize = ftell(fp); 00038 fseek(fp, 0, SEEK_SET); 00039 ChainMakeLexerBuffers(lexBufferSize, DEFAULT_LEX_LINE_BUFFER_SIZE); 00040 00041 if(charname && strcmp(charname, "")) 00042 SetCharName(charname); 00043 SetChain(this); 00044 00045 ChainSetInputFile(fp); 00046 int ret = chparse(); 00047 00048 ChainDeleteLexerBuffers(); 00049 fclose(fp); 00050 00051 // Dump(cout); 00052 return ret; 00053 }