1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0027342: STEP - support C++ streams for import / export

- Although Lex and YACC predate C++, have been generated a C++ parser.
- Porting parser now allows use C++ stream's
- Added in ImportExport sample the function of reading the .stpZ files (Zip_Files.cxx, Zip_Files.h files with BSD License) with the STEP file
-- xxx.stpZ names and archive file inside xxx.stp or (xxx.step) must match
-- and reading limit no more than one STEP file in the stpZ compressed file
This commit is contained in:
imn
2016-04-06 16:09:55 +03:00
committed by apl
parent 2029028dfa
commit de7db1220c
31 changed files with 3751 additions and 2811 deletions

View File

@@ -40,6 +40,7 @@
#include <TColStd_HSequenceOfTransient.hxx>
#include <STEPConstruct.hxx>
#include <StepVisual_StyledItem.hxx>
#include <Zip_Files.h>
#ifdef _DEBUG
#undef THIS_FILE
@@ -385,7 +386,7 @@ Handle(TopTools_HSequenceOfShape) CImportExport::ReadSTEP()// not by reference -
NULL,
NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
L"STEP Files (*.stp;*.step)|*.stp; *.step|All Files (*.*)|*.*||",
L"STEP Files (*.stp;*.step;*.stpZ)|*.stp; *.step; *.stpZ|All Files (*.*)|*.*||",
NULL );
CString SHAREPATHValue;
@@ -399,7 +400,7 @@ dlg.m_ofn.lpstrInitialDir = initdir;
{
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
TCollection_AsciiString aFileName ((const wchar_t* )dlg.GetPathName());
IFSelect_ReturnStatus ReturnStatus = ReadSTEP (aFileName.ToCString(), aSequence);
IFSelect_ReturnStatus ReturnStatus = ReadSTEP (aFileName.ToCString(), aSequence);
switch (ReturnStatus)
{
case IFSelect_RetError :
@@ -421,10 +422,38 @@ IFSelect_ReturnStatus CImportExport::ReadSTEP(const Standard_CString& aFileName,
Handle(TopTools_HSequenceOfShape)& aHSequenceOfShape)
{
aHSequenceOfShape->Clear();
// create additional log file
STEPControl_Reader aReader;
IFSelect_ReturnStatus status = aReader.ReadFile(aFileName);
IFSelect_ReturnStatus status = IFSelect_RetError;
std::string name(aFileName);
std::size_t posname = name.rfind(".stpZ");
if (posname == std::string::npos) {
status = aReader.ReadFile(aFileName);
}
else {
std::ifstream ifstream;
ZipFileReader archive(ifstream, name);
if (ifstream) {
std::vector<std::string> filenames;
archive.Get_File_List(filenames);
if (filenames.size() == 1) {
std::string stepnamefile = filenames[0];
std::size_t posnamefile = stepnamefile.find(".");
std::string stepname = stepnamefile.substr(0, posnamefile);
std::size_t firstpos = name.rfind(stepname);
if (firstpos != std::string::npos) {
std::string str = name.substr(firstpos, posname - firstpos);
if (stepname == str) {
std::istream* istream;
istream = archive.Get_File(ifstream, stepnamefile);
status = aReader.ReadFile(aFileName, istream);
}
}
}
}
}
if (status != IFSelect_RetDone)
return status;

View File

@@ -0,0 +1,416 @@
/*
PARTIO SOFTWARE
Copyright 2010 Disney Enterprises, Inc. All rights reserved
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* The names "Disney", "Walt Disney Pictures", "Walt Disney Animation
Studios" or the names of its contributors may NOT be used to
endorse or promote products derived from this software without
specific prior written permission from Walt Disney Pictures.
Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED.
IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#ifdef HAVE_ZLIB
extern "C"{
#include <zlib.h>
}
#endif
#include <cassert>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <stdexcept>
#include <cstring>
#include <string>
#include <algorithm>
#include "Zip_Files.h"
template<class T>
inline void Read_Primitive(std::istream& stream, T& x)
{
stream.read(&(char&)x, sizeof(T));
}
//#####################################################################
// class GZipFileHeader
//#####################################################################
struct GZipFileHeader
{
unsigned char magic0, magic1; // magic should be 0x8b,0x1f
unsigned char cm; // compression method 0x8 is gzip
unsigned char flags; // flags
unsigned int modtime; // 4 byte modification time
unsigned char flags2; // secondary flags
unsigned char os; // operating system 0xff for unknown
unsigned short crc16; // crc check
unsigned int crc32;
GZipFileHeader()
:magic0(0), magic1(0), flags(0), modtime(0), flags2(0), os(0), crc16(0), crc32(0)
{}
bool Read(std::istream& istream)
{
Read_Primitive(istream, magic0);
Read_Primitive(istream, magic1);
if (magic0 != 0x1f || magic1 != 0x8b){//std::cerr<<"gzip: did not find gzip magic 0x1f 0x8b"<<std::endl;
return false;
}
Read_Primitive(istream, cm);
if (cm != 8){ std::cerr << "gzip: compression method not 0x8" << std::endl; return false; }
Read_Primitive(istream, flags);
Read_Primitive(istream, modtime);
Read_Primitive(istream, flags2);
Read_Primitive(istream, os);
unsigned char dummyByte;
// read flags if necessary
if (flags & 2){
unsigned short flgExtraLen;
Read_Primitive(istream, flgExtraLen);
for (int k = 0; k<flgExtraLen; k++) Read_Primitive(istream, dummyByte);
}
// read filename/comment if present
int stringsToRead = ((flags & 8) ? 1 : 0) + ((flags & 4) ? 1 : 0);
for (int i = 0; i<stringsToRead; i++)
do{ Read_Primitive(istream, dummyByte); } while (dummyByte != 0 && istream);
if (flags & 1) Read_Primitive(istream, crc16);
if (!istream) { std::cerr << "gzip: got to end of file after only reading gzip header" << std::endl; return false; }
return true;
}
};
#ifdef HAVE_ZLIB
//#####################################################################
// class ZipFileHeader
//#####################################################################
struct ZipFileHeader
{
unsigned short version;
unsigned short flags;
unsigned short compression_type;
unsigned short stamp_date, stamp_time;
unsigned int crc;
unsigned int compressed_size, uncompressed_size;
std::string filename;
unsigned int header_offset; // local header offset
ZipFileHeader()
{}
ZipFileHeader(const std::string& filename_input)
:version(20), flags(0), compression_type(8), stamp_date(0), stamp_time(0), crc(0),
compressed_size(0), uncompressed_size(0), filename(filename_input), header_offset(0)
{}
bool Read(std::istream& istream, const bool global)
{
unsigned int sig;
unsigned short version, flags;
// read and check for local/global magic
if (global){
Read_Primitive(istream, sig);
if (sig != 0x02014b50){ std::cerr << "Did not find global header signature" << std::endl; return false; }
Read_Primitive(istream, version);
}
else{
Read_Primitive(istream, sig);
if (sig != 0x04034b50){ std::cerr << "Did not find local header signature" << std::endl; return false; }
}
// Read rest of header
Read_Primitive(istream, version);
Read_Primitive(istream, flags);
Read_Primitive(istream, compression_type);
Read_Primitive(istream, stamp_date);
Read_Primitive(istream, stamp_time);
Read_Primitive(istream, crc);
Read_Primitive(istream, compressed_size);
Read_Primitive(istream, uncompressed_size);
unsigned short filename_length, extra_length;
Read_Primitive(istream, filename_length);
Read_Primitive(istream, extra_length);
unsigned short comment_length = 0;
if (global){
Read_Primitive(istream, comment_length); // filecomment
unsigned short disk_number_start, int_file_attrib;
unsigned int ext_file_attrib;
Read_Primitive(istream, disk_number_start); // disk# start
Read_Primitive(istream, int_file_attrib); // internal file
Read_Primitive(istream, ext_file_attrib); // ext final
Read_Primitive(istream, header_offset);
} // rel offset
char* buf = new char[std::max(comment_length, std::max(filename_length, extra_length)) + 1];
istream.read(buf, filename_length);
buf[filename_length] = 0;
filename = std::string(buf);
istream.read(buf, extra_length);
if (global) istream.read(buf, comment_length);
delete[] buf;
return true;
}
};
//#####################################################################
// class ZipStreambufDecompress
//#####################################################################
class ZipStreambufDecompress :public std::streambuf
{
static const unsigned int buffer_size = 512;
std::istream& istream;
z_stream strm;
unsigned char in[buffer_size], out[buffer_size];
ZipFileHeader header;
GZipFileHeader gzip_header;
int total_read, total_uncompressed;
bool part_of_zip_file;
bool own_istream;
bool valid;
bool compressed_data;
static const unsigned short DEFLATE = 8;
static const unsigned short UNCOMPRESSED = 0;
public:
ZipStreambufDecompress(std::istream& stream, bool part_of_zip_file_input)
:istream(stream), total_read(0), total_uncompressed(0), part_of_zip_file(part_of_zip_file_input), valid(true)
{
strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; strm.avail_in = 0; strm.next_in = Z_NULL;
setg((char*)in, (char*)in, (char*)in);
setp(0, 0);
// skip the header
if (part_of_zip_file){
valid = header.Read(istream, false);
if (header.compression_type == DEFLATE) compressed_data = true;
else if (header.compression_type == UNCOMPRESSED) compressed_data = false;
else{
compressed_data = false; std::cerr << "ZIP: got unrecognized compressed data (Supported deflate/uncompressed)" << std::endl;
valid = false;
}
}
else{ valid = gzip_header.Read(istream); compressed_data = true; }
// initialize the inflate
if (compressed_data && valid){
int result = inflateInit2(&strm, -MAX_WBITS);
if (result != Z_OK){ std::cerr << "gzip: inflateInit2 did not return Z_OK" << std::endl; valid = false; }
}
}
ZipStreambufDecompress & operator=(const ZipStreambufDecompress &) { return *this; }
virtual ~ZipStreambufDecompress()
{
if (compressed_data && valid) inflateEnd(&strm);
if (!part_of_zip_file) delete &istream;
}
int process()
{
if (!valid) return -1;
if (compressed_data){
strm.avail_out = buffer_size - 4;
strm.next_out = (Bytef*)(out + 4);
while (strm.avail_out != 0){
if (strm.avail_in == 0){ // buffer empty, read some more from file
istream.read((char*)in, part_of_zip_file ? std::min((unsigned int)buffer_size, header.compressed_size - total_read) : (unsigned int)buffer_size);
strm.avail_in = (uInt)istream.gcount();
total_read += strm.avail_in;
strm.next_in = (Bytef*)in;
}
int ret = inflate(&strm, Z_NO_FLUSH); // decompress
switch (ret){
case Z_STREAM_ERROR:
std::cerr << "libz error Z_STREAM_ERROR" << std::endl;
valid = false; return -1;
case Z_NEED_DICT:
case Z_DATA_ERROR:
case Z_MEM_ERROR:
std::cerr << "gzip error " << strm.msg << std::endl;
valid = false; return -1;
}
if (ret == Z_STREAM_END) break;
}
int unzip_count = buffer_size - strm.avail_out - 4;
total_uncompressed += unzip_count;
return unzip_count;
}
else{ // uncompressed, so just read
istream.read((char*)(out + 4), std::min(buffer_size - 4, header.uncompressed_size - total_read));
int count = (int)istream.gcount();
total_read += count;
return count;
}
}
virtual int underflow()
{
if (gptr() && (gptr()<egptr())) return traits_type::to_int_type(*gptr()); // if we already have data just use it
int put_back_count = (int) (gptr() - eback());
if (put_back_count>4) put_back_count = 4;
std::memmove(out + (4 - put_back_count), gptr() - put_back_count, put_back_count);
int num = process();
setg((char*)(out + 4 - put_back_count), (char*)(out + 4), (char*)(out + 4 + num));
if (num <= 0) return EOF;
return traits_type::to_int_type(*gptr());
}
virtual int overflow()
{
assert(false); return EOF;
}
};
//#####################################################################
// Class ZIP_FILE_ISTREAM
//#####################################################################
// Class needed because istream cannot own its streambuf
class ZIP_FILE_ISTREAM :public std::istream
{
ZipStreambufDecompress buf;
public:
ZIP_FILE_ISTREAM(std::istream& istream, bool part_of_zip_file)
:std::istream(&buf), buf(istream, part_of_zip_file)
{}
virtual ~ZIP_FILE_ISTREAM()
{}
};
//#####################################################################
// Function ZipFileReader
//#####################################################################
ZipFileReader::
ZipFileReader(std::ifstream& ifstream, const std::string& filename)
{
ifstream.open(filename.c_str(), std::ios::in | std::ios::binary);
if (!ifstream) throw std::runtime_error("ZIP: Invalid file handle");
Find_And_Read_Central_Header(ifstream);
}
//#####################################################################
// Function ZipFileReader
//#####################################################################
ZipFileReader::
~ZipFileReader()
{
std::map<std::string, ZipFileHeader*>::iterator i = filename_to_header.begin();
for (; i != filename_to_header.end(); ++i)
delete i->second;
}
//#####################################################################
// Function Find_And_Read_Central_Header
//#####################################################################
bool ZipFileReader::
Find_And_Read_Central_Header(std::ifstream& ifstream)
{
// Find the header
// NOTE: this assumes the zip file header is the last thing written to file...
ifstream.seekg(0, std::ios_base::end);
std::ios::streampos end_position = ifstream.tellg();
unsigned int max_comment_size = 0xffff; // max size of header
unsigned int read_size_before_comment = 22;
std::ios::streamoff read_start = max_comment_size + read_size_before_comment;
if (read_start>end_position) read_start = end_position;
ifstream.seekg(end_position - read_start);
char *buf = new char[read_start];
if (read_start <= 0){ std::cerr << "ZIP: Invalid read buffer size" << std::endl; return false; }
ifstream.read(buf, read_start);
int found = -1;
for (unsigned int i = 0; i<read_start - 3; i++){
if (buf[i] == 0x50 && buf[i + 1] == 0x4b && buf[i + 2] == 0x05 && buf[i + 3] == 0x06){ found = i; break; }
}
delete[] buf;
if (found == -1){ std::cerr << "ZIP: Failed to find zip header" << std::endl; return false; }
// seek to end of central header and read
ifstream.seekg(end_position - (read_start - found));
unsigned int word;
unsigned short disk_number1, disk_number2, num_files, num_files_this_disk;
Read_Primitive(ifstream, word); // end of central
Read_Primitive(ifstream, disk_number1); // this disk number
Read_Primitive(ifstream, disk_number2); // this disk number
if (disk_number1 != disk_number2 || disk_number1 != 0){
std::cerr << "ZIP: multiple disk zip files are not supported" << std::endl; return false;
}
Read_Primitive(ifstream, num_files); // one entry in center in this disk
Read_Primitive(ifstream, num_files_this_disk); // one entry in center
if (num_files != num_files_this_disk){
std::cerr << "ZIP: multi disk zip files are not supported" << std::endl; return false;
}
unsigned int size_of_header, header_offset;
Read_Primitive(ifstream, size_of_header); // size of header
Read_Primitive(ifstream, header_offset); // offset to header
// go to header and read all file headers
ifstream.seekg(header_offset);
for (int i = 0; i<num_files; i++){
ZipFileHeader* header = new ZipFileHeader;
bool valid = header->Read(ifstream, true);
if (valid) filename_to_header[header->filename] = header;
}
return true;
}
//#####################################################################
// Function Get_File
//#####################################################################
std::istream* ZipFileReader::Get_File(std::ifstream& ifstream,const std::string& filename)
{
std::map<std::string, ZipFileHeader*>::iterator i = filename_to_header.find(filename);
if (i != filename_to_header.end()){
ZipFileHeader* header = i->second;
ifstream.seekg((*header).header_offset); return new ZIP_FILE_ISTREAM(ifstream, true);
}
return 0;
}
//#####################################################################
// Function Get_File_List
//#####################################################################
void ZipFileReader::Get_File_List(std::vector<std::string>& filenames) const
{
filenames.clear();
std::map<std::string, ZipFileHeader*>::const_iterator i = filename_to_header.begin();
for (; i != filename_to_header.end(); ++i)
filenames.push_back(i->first);
}
#else
ZipFileReader::
ZipFileReader(std::ifstream& ifstream, const std::string& filename)
{
if (!ifstream) std::cerr << "Encountered stpZ file '" << filename << "' not compiled with zlib" << std::endl;
}
ZipFileReader::
~ZipFileReader()
{
}
std::istream* ZipFileReader::Get_File(std::ifstream& ifstream, const std::string& filename)
{
if (!ifstream) std::cerr << "Encountered stpZ file '" << filename << "' not compiled with zlib" << std::endl;
return 0;
}
void ZipFileReader::Get_File_List(std::vector<std::string>& filenames) const
{
std::cerr << "Filenames empty because not compiled with zlib" << std::endl;
filenames.clear();
}
#endif

View File

@@ -0,0 +1,57 @@
/*
PARTIO SOFTWARE
Copyright 2010 Disney Enterprises, Inc. All rights reserved
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* The names "Disney", "Walt Disney Pictures", "Walt Disney Animation
Studios" or the names of its contributors may NOT be used to
endorse or promote products derived from this software without
specific prior written permission from Walt Disney Pictures.
Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED.
IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#ifndef __Zip_Files__
#define __Zip_Files__
#include <fstream>
#include <iostream>
#include <map>
#include <stdexcept>
#include <vector>
struct ZipFileHeader;
//#####################################################################
// Class ZipFileReader
//#####################################################################
class ZipFileReader
{
public:
std::map<std::string, ZipFileHeader*> filename_to_header;
ZipFileReader(std::ifstream& ifstream, const std::string& filename);
~ZipFileReader();
std::istream* Get_File(std::ifstream& ifstream, const std::string& filename);
void Get_File_List(std::vector<std::string>& filenames) const;
private:
bool Find_And_Read_Central_Header(std::ifstream& ifstream);
};
#endif

View File

@@ -5,6 +5,17 @@ project (mfcsample)
add_definitions(-DWINVER=0x0501 -D_AFXEXT -DUNICODE -D_UNICODE)
set (CMAKE_MFC_FLAG 2)
# use zlib
FIND_PRODUCT_DIR ("${3RDPARTY_DIR}" ZLIB ZLIB_ROOT_DIR)
if (ZLIB_ROOT_DIR)
set(ZLIB_INCLUDE_DIR ${3RDPARTY_DIR}/${ZLIB_ROOT_DIR}/include)
set(ZLIB_LIBRARY ${3RDPARTY_DIR}/${ZLIB_ROOT_DIR}/lib)
find_package(ZLIB)
if (ZLIB_FOUND)
add_definitions(-DHAVE_ZLIB)
endif()
endif()
# mfcsample
set (mfcsample_SOURCE_FILES ${MFC_STANDARD_SAMPLES_DIR}/mfcsample/src/mfcsample.cpp
${MFC_STANDARD_SAMPLES_DIR}/mfcsample/src/StdAfx.cpp )
@@ -39,9 +50,11 @@ set (COMMON_SOURCE_FILES ${MFC_STANDARD_COMMON_SAMPLES_DIR}/AISDialogs.cpp
# Common ImportExport
set (COMMON_IE_DIR ${MFC_STANDARD_COMMON_SAMPLES_DIR}/ImportExport)
set (COMMON_IE_HEADER_FILES ${COMMON_IE_DIR}/ImportExport.h
${COMMON_IE_DIR}/SaveSTEPDlg.h )
${COMMON_IE_DIR}/SaveSTEPDlg.h
${COMMON_IE_DIR}/Zip_Files.h )
set (COMMON_IE_SOURCE_FILES ${COMMON_IE_DIR}/ImportExport.cpp
${COMMON_IE_DIR}/SaveSTEPDlg.cpp )
${COMMON_IE_DIR}/SaveSTEPDlg.cpp
${COMMON_IE_DIR}/Zip_Files.cpp )
# Common ISession2D
set (COMMON_ISESSION2D_DIR ${MFC_STANDARD_COMMON_SAMPLES_DIR}/ISession2D)
@@ -154,12 +167,18 @@ else()
LIBRARY DESTINATION "${INSTALL_DIR_LIB}d")
endif()
include_directories( ${CMAKE_BINARY_DIR}/inc
${MFC_STANDARD_COMMON_SAMPLES_DIR}
${COMMON_IE_DIR}
${COMMON_ISESSION2D_DIR}
${COMMON_PRIMITIVE_DIR}
${COMMON_RESOURCE2D_DIR})
set (mfcsample_INCLUDE ${CMAKE_BINARY_DIR}/inc
${MFC_STANDARD_COMMON_SAMPLES_DIR}
${COMMON_IE_DIR}
${COMMON_ISESSION2D_DIR}
${COMMON_PRIMITIVE_DIR}
${COMMON_RESOURCE2D_DIR})
if (EXISTS ${ZLIB_INCLUDE_DIR})
set(mfcsample_INCLUDE ${mfcsample_INCLUDE} ${ZLIB_INCLUDE_DIR})
endif()
include_directories(${mfcsample_INCLUDE})
# OCCT libraries for using
set (mfcsample_USED_LIBS TKVRML
@@ -189,4 +208,8 @@ set (mfcsample_USED_LIBS TKVRML
TKMesh
TKV3d)
if (EXISTS ${ZLIB_LIBRARY})
set(mfcsample_USED_LIBS ${mfcsample_USED_LIBS} ${ZLIB_LIBRARY}/zlibstatic.lib)
endif()
target_link_libraries (mfcsample ${mfcsample_USED_LIBS})

View File

@@ -63,6 +63,15 @@ public:
//! and recognize the Entities)
Standard_EXPORT virtual Standard_Integer ReadFile (const Standard_CString name, Handle(Interface_InterfaceModel)& model, const Handle(Interface_Protocol)& protocol) const = 0;
//! Gives the way to Read a File and transfer it to a Model
//! <mod> is the resulting Model, which has to be created by this
//! method. In case of error, <mod> must be returned Null
//! Return value is a status with free values.
//! Simply, 0 is for "Execution OK"
//! The Protocol can be used to work (e.g. create the Model, read
//! and recognize the Entities)
Standard_EXPORT virtual Standard_Integer ReadFile(const Standard_CString name, std::istream* istream, Handle(Interface_InterfaceModel)& model, const Handle(Interface_Protocol)& protocol) const = 0;
//! Gives the way to Write a File from a Model.
//! <ctx> contains all necessary informations : the model, the
//! protocol, the file name, and the list of File Modifiers to be

View File

@@ -208,7 +208,7 @@ void IFSelect_WorkSession::SetModel
//=======================================================================
IFSelect_ReturnStatus IFSelect_WorkSession::ReadFile
(const Standard_CString filename)
(const Standard_CString filename, std::istream* istream)
{
if (thelibrary.IsNull()) return IFSelect_RetVoid;
if (theprotocol.IsNull()) return IFSelect_RetVoid;
@@ -216,7 +216,11 @@ IFSelect_ReturnStatus IFSelect_WorkSession::ReadFile
IFSelect_ReturnStatus status = IFSelect_RetVoid;
try {
OCC_CATCH_SIGNALS
Standard_Integer stat = thelibrary->ReadFile (filename,model,theprotocol);
Standard_Integer stat;
if ( !istream )
stat = thelibrary->ReadFile(filename, model, theprotocol);
else
stat = thelibrary->ReadFile(filename, istream, model, theprotocol);
if (stat == 0) status = IFSelect_RetDone;
else if (stat < 0) status = IFSelect_RetError;
else status = IFSelect_RetFail;

View File

@@ -170,7 +170,7 @@ public:
//! Returns a integer status which can be :
//! RetDone if OK, RetVoid if no Protocol not defined,
//! RetError for file not found, RetFail if fail during read
Standard_EXPORT IFSelect_ReturnStatus ReadFile (const Standard_CString filename);
Standard_EXPORT IFSelect_ReturnStatus ReadFile(const Standard_CString filename, std::istream* istream = 0);
//! Returns the count of Entities stored in the Model, or 0
Standard_EXPORT Standard_Integer NbStartingEntities() const;

View File

@@ -90,7 +90,17 @@ static Handle(IGESData_FileProtocol) IGESProto;
else model.Nullify();
return status;
}
Standard_Integer IGESSelect_WorkLibrary::ReadFile
(const Standard_CString name,
std::istream* istream,
Handle(Interface_InterfaceModel)& model,
const Handle(Interface_Protocol)& protocol) const
{
if (!istream) return ReadFile(name, model, protocol);
Handle(Message_Messenger) sout = Message::DefaultMessenger();
sout << "Error when reading file : " << name << endl;
return 1;
}
Standard_Boolean IGESSelect_WorkLibrary::WriteFile
(IFSelect_ContextWrite& ctx) const

View File

@@ -50,6 +50,11 @@ public:
//! or lets <mod> "Null" in case of Error
//! Returns 0 if OK, 1 if Read Error, -1 if File not opened
Standard_EXPORT Standard_Integer ReadFile (const Standard_CString name, Handle(Interface_InterfaceModel)& model, const Handle(Interface_Protocol)& protocol) const Standard_OVERRIDE;
//! Reads a IGES File and returns a IGES Model (into <mod>),
//! or lets <mod> "Null" in case of Error
//! Returns 0 if OK, 1 if Read Error, -1 if File not opened
Standard_EXPORT Standard_Integer ReadFile(const Standard_CString name, std::istream* istream, Handle(Interface_InterfaceModel)& model, const Handle(Interface_Protocol)& protocol) const Standard_OVERRIDE;
//! Writes a File from a IGES Model (brought by <ctx>)
//! Returns False (and writes no file) if <ctx> is not for IGES

View File

@@ -1,12 +1,17 @@
lex.step.c
lex.step.cxx
recfile.pc
recfile.ph
step.tab.c
step.tab.h
step.tab.cxx
step.tab.hxx
StepFile_CallFailure.cxx
StepFile_CallFailure.hxx
StepFile_Read.cxx
StepFile_Read.hxx
StepFile_Transfer.hxx
stepread.c
stepread.cxx
stepread.ph
FlexLexer.h
location.hh
position.hh
stack.hh
scanner.hpp

206
src/StepFile/FlexLexer.h Normal file
View File

@@ -0,0 +1,206 @@
// -*-C++-*-
// FlexLexer.h -- define interfaces for lexical analyzer classes generated
// by flex
// Copyright (c) 1993 The Regents of the University of California.
// All rights reserved.
//
// This code is derived from software contributed to Berkeley by
// Kent Williams and Tom Epperly.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// Neither the name of the University nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE.
// This file defines FlexLexer, an abstract class which specifies the
// external interface provided to flex C++ lexer objects, and yyFlexLexer,
// which defines a particular lexer class.
//
// If you want to create multiple lexer classes, you use the -P flag
// to rename each yyFlexLexer to some other xxFlexLexer. You then
// include <FlexLexer.h> in your other sources once per lexer class:
//
// #undef yyFlexLexer
// #define yyFlexLexer xxFlexLexer
// #include <FlexLexer.h>
//
// #undef yyFlexLexer
// #define yyFlexLexer zzFlexLexer
// #include <FlexLexer.h>
// ...
#ifndef __FLEX_LEXER_H
// Never included before - need to define base class.
#define __FLEX_LEXER_H
#include <iostream>
# ifndef FLEX_STD
# define FLEX_STD std::
# endif
extern "C++" {
struct yy_buffer_state;
typedef int yy_state_type;
class FlexLexer {
public:
virtual ~FlexLexer() { }
const char* YYText() const { return yytext; }
int YYLeng() const { return yyleng; }
virtual void
yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0;
virtual struct yy_buffer_state*
yy_create_buffer( FLEX_STD istream* s, int size ) = 0;
virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0;
virtual void yyrestart( FLEX_STD istream* s ) = 0;
virtual int yylex() = 0;
// Call yylex with new input/output sources.
int yylex( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 )
{
switch_streams( new_in, new_out );
return yylex();
}
// Switch to new input/output streams. A nil stream pointer
// indicates "keep the current one".
virtual void switch_streams( FLEX_STD istream* new_in = 0,
FLEX_STD ostream* new_out = 0 ) = 0;
int lineno() const { return yylineno; }
int debug() const { return yy_flex_debug; }
void set_debug( int flag ) { yy_flex_debug = flag; }
protected:
char* yytext;
int yyleng;
int yylineno; // only maintained if you use %option yylineno
int yy_flex_debug; // only has effect with -d or "%option debug"
};
}
#endif // FLEXLEXER_H
#if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce)
// Either this is the first time through (yyFlexLexerOnce not defined),
// or this is a repeated include to define a different flavor of
// yyFlexLexer, as discussed in the flex manual.
#define yyFlexLexerOnce
extern "C++" {
class yyFlexLexer : public FlexLexer {
public:
// arg_yyin and arg_yyout default to the cin and cout, but we
// only make that assignment when initializing in yylex().
yyFlexLexer( FLEX_STD istream* arg_yyin = 0, FLEX_STD ostream* arg_yyout = 0 );
virtual ~yyFlexLexer();
void yy_switch_to_buffer( struct yy_buffer_state* new_buffer );
struct yy_buffer_state* yy_create_buffer( FLEX_STD istream* s, int size );
void yy_delete_buffer( struct yy_buffer_state* b );
void yyrestart( FLEX_STD istream* s );
void yypush_buffer_state( struct yy_buffer_state* new_buffer );
void yypop_buffer_state();
virtual int yylex();
virtual void switch_streams( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 );
virtual int yywrap();
protected:
virtual int LexerInput( char* buf, int max_size );
virtual void LexerOutput( const char* buf, int size );
virtual void LexerError( const char* msg );
void yyunput( int c, char* buf_ptr );
int yyinput();
void yy_load_buffer_state();
void yy_init_buffer( struct yy_buffer_state* b, FLEX_STD istream* s );
void yy_flush_buffer( struct yy_buffer_state* b );
int yy_start_stack_ptr;
int yy_start_stack_depth;
int* yy_start_stack;
void yy_push_state( int new_state );
void yy_pop_state();
int yy_top_state();
yy_state_type yy_get_previous_state();
yy_state_type yy_try_NUL_trans( yy_state_type current_state );
int yy_get_next_buffer();
FLEX_STD istream* yyin; // input source for default LexerInput
FLEX_STD ostream* yyout; // output sink for default LexerOutput
// yy_hold_char holds the character lost when yytext is formed.
char yy_hold_char;
// Number of characters read into yy_ch_buf.
int yy_n_chars;
// Points to current character in buffer.
char* yy_c_buf_p;
int yy_init; // whether we need to initialize
int yy_start; // start state number
// Flag which is used to allow yywrap()'s to do buffer switches
// instead of setting up a fresh yyin. A bit of a hack ...
int yy_did_buffer_switch_on_eof;
size_t yy_buffer_stack_top; /**< index of top of stack. */
size_t yy_buffer_stack_max; /**< capacity of stack. */
struct yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */
void yyensure_buffer_stack(void);
// The following are not always needed, but may be depending
// on use of certain flex features (like REJECT or yymore()).
yy_state_type yy_last_accepting_state;
char* yy_last_accepting_cpos;
yy_state_type* yy_state_buf;
yy_state_type* yy_state_ptr;
char* yy_full_match;
int* yy_full_state;
int yy_full_lp;
int yy_lp;
int yy_looking_for_trail_begin;
int yy_more_flag;
int yy_more_len;
int yy_more_offset;
int yy_prev_more_offset;
};
}
#endif // yyFlexLexer || ! yyFlexLexerOnce

View File

@@ -25,13 +25,19 @@
// Compilation conditionnelle : concerne les mesures de performances
#include <stdio.h>
#include <iostream>
#include "recfile.ph"
#include "stepread.ph"
extern "C" void recfile_modeprint (int mode); // controle trace recfile
// recfile_modeprint est declare a part
#ifdef __cplusplus
extern "C" {
#endif
void recfile_modeprint (int mode); // controle trace recfile
// recfile_modeprint est declare a part
#ifdef __cplusplus
}
#endif
#include <Interface_ParamType.hxx>
#include <Interface_Protocol.hxx>
#include <Interface_Check.hxx>
@@ -65,9 +71,9 @@ void StepFile_ReadTrace (const Standard_Integer mode)
modepr = mode; // recfile_modeprint est rappele a chaque lecture de fichier
}
static Standard_Integer StepFile_Read
(char* nomfic,
std::istream* istream,
const Handle(StepData_StepModel)& stepmodel,
const Handle(StepData_Protocol)& protocol,
const Handle(StepData_FileRecognizer)& recoheader,
@@ -81,7 +87,7 @@ Standard_Integer StepFile_Read
const Handle(StepData_FileRecognizer)& recodata)
{
return StepFile_Read
(nomfic,stepmodel,
(nomfic,0,stepmodel,
Handle(StepData_Protocol)::DownCast(Interface_Protocol::Active()),
recoheader,recodata);
}
@@ -93,7 +99,7 @@ Standard_Integer StepFile_Read
const Handle(StepData_Protocol)& protocol)
{
Handle(StepData_FileRecognizer) nulreco;
return StepFile_Read (nomfic,stepmodel,protocol,recoheader,nulreco);
return StepFile_Read (nomfic,0,stepmodel,protocol,recoheader,nulreco);
}
Standard_Integer StepFile_Read
@@ -102,7 +108,17 @@ Standard_Integer StepFile_Read
const Handle(StepData_Protocol)& protocol)
{
Handle(StepData_FileRecognizer) nulreco;
return StepFile_Read (nomfic,stepmodel,protocol,nulreco,nulreco);
return StepFile_Read (nomfic,0,stepmodel,protocol,nulreco,nulreco);
}
Standard_Integer StepFile_Read
(char* nomfic,
std::istream* istream,
const Handle(StepData_StepModel)& stepmodel,
const Handle(StepData_Protocol)& protocol)
{
Handle(StepData_FileRecognizer) nulreco;
return StepFile_Read (nomfic,istream,stepmodel,protocol,nulreco,nulreco);
}
// ## ## ## ## ## ## Corps de la Routine ## ## ## ## ## ##
@@ -111,6 +127,7 @@ static Interface_ParamType LesTypes[10]; // passage types (recstep/Interface)
Standard_Integer StepFile_Read
(char* nomfic,
std::istream* istream,
const Handle(StepData_StepModel)& stepmodel,
const Handle(StepData_Protocol)& protocol,
const Handle(StepData_FileRecognizer)& recoheader,
@@ -122,8 +139,12 @@ Standard_Integer StepFile_Read
checkread->Clear();
recfile_modeprint ( (modepr > 0 ? modepr-1 : 0) );
FILE* newin = stepread_setinput(ficnom);
if (!newin) return -1;
std::ifstream newifstream;
if (!istream) {
stepread_setinput(newifstream, ficnom);
istream = &newifstream;
}
if (!istream) return -1;
#ifdef CHRONOMESURE
Standard_Integer n ;
OSD_Timer c ;
@@ -134,7 +155,11 @@ Standard_Integer StepFile_Read
try {
OCC_CATCH_SIGNALS
if (stepread () != 0) { lir_file_fin(3); stepread_endinput (newin,ficnom); return 1; }
if (stepread(istream) != 0) {
lir_file_fin(3);
stepread_endinput(newifstream, ficnom);
return 1;
}
}
catch (Standard_Failure) {
#ifdef OCCT_DEBUG
@@ -143,17 +168,17 @@ Standard_Integer StepFile_Read
sout << " ..." << endl;
#endif
lir_file_fin(3);
stepread_endinput (newin,ficnom);
stepread_endinput(newifstream, ficnom);
return 1;
}
// Continue reading of file despite of possible fails
//if (checkread->HasFailed()) { lir_file_fin(3); stepread_endinput (newin,ficnom); return 1; }
// Continue reading of file despite of possible fails
// if (checkread->HasFailed()) { lir_file_fin(3); stepread_endinput(newifstream, ficnom); return 1; }
#ifdef CHRONOMESURE
sout << " ... STEP File Read ... " << endl;
c.Show();
#endif
// Creation du StepReaderData
LesTypes[rec_argNondef] = Interface_ParamVoid ;
@@ -223,8 +248,8 @@ Standard_Integer StepFile_Read
n = stepmodel->NbEntities() ;
sout << " STEP Loading done : " << n << " Entities" << endl;
#endif
stepread_endinput (newin,ficnom); return 0 ;
stepread_endinput(newifstream, ficnom);
return 0;
}
void StepFile_Interrupt (char* mess)

View File

@@ -27,6 +27,7 @@
#ifndef StepFile_Read_HeaderFile
#define StepFile_Read_HeaderFile
#include <iostream>
//# include <stepread.h> : sauf recfile_modeprint, declare ici
# include <StepData_StepModel.hxx>
# include <StepData_FileRecognizer.hxx>
@@ -52,5 +53,11 @@ Standard_EXPORT Standard_Integer StepFile_Read
(char* nomfic,
const Handle(StepData_StepModel)& stepmodel,
const Handle(StepData_Protocol)& protocol); // Header & Data
Standard_EXPORT Standard_Integer StepFile_Read
(char* nomfic,
std::istream* istream,
const Handle(StepData_StepModel)& stepmodel,
const Handle(StepData_Protocol)& protocol); // Header & Data
#endif

File diff suppressed because it is too large Load Diff

181
src/StepFile/location.hh Normal file
View File

@@ -0,0 +1,181 @@
/* A Bison parser, made by GNU Bison 2.7. */
/* Locations for Bison parsers in C++
Copyright (C) 2002-2007, 2009-2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/**
** \file location.hh
** Define the yy::location class.
*/
#ifndef YY_YY_LOCATION_HH_INCLUDED
# define YY_YY_LOCATION_HH_INCLUDED
# include "position.hh"
namespace yy {
/* Line 166 of location.cc */
#line 47 "location.hh"
/// Abstract a location.
class location
{
public:
/// Construct a location from \a b to \a e.
location (const position& b, const position& e)
: begin (b)
, end (e)
{
}
/// Construct a 0-width location in \a p.
explicit location (const position& p = position ())
: begin (p)
, end (p)
{
}
/// Construct a 0-width location in \a f, \a l, \a c.
explicit location (std::string* f,
unsigned int l = 1u,
unsigned int c = 1u)
: begin (f, l, c)
, end (f, l, c)
{
}
/// Initialization.
void initialize (std::string* f = YY_NULL,
unsigned int l = 1u,
unsigned int c = 1u)
{
begin.initialize (f, l, c);
end = begin;
}
/** \name Line and Column related manipulators
** \{ */
public:
/// Reset initial location to final location.
void step ()
{
begin = end;
}
/// Extend the current location to the COUNT next columns.
void columns (unsigned int count = 1)
{
end += count;
}
/// Extend the current location to the COUNT next lines.
void lines (unsigned int count = 1)
{
end.lines (count);
}
/** \} */
public:
/// Beginning of the located region.
position begin;
/// End of the located region.
position end;
};
/// Join two location objects to create a location.
inline const location operator+ (const location& begin, const location& end)
{
location res = begin;
res.end = end.end;
return res;
}
/// Add two location objects.
inline const location operator+ (const location& begin, unsigned int width)
{
location res = begin;
res.columns (width);
return res;
}
/// Add and assign a location.
inline location& operator+= (location& res, unsigned int width)
{
res.columns (width);
return res;
}
/// Compare two location objects.
inline bool
operator== (const location& loc1, const location& loc2)
{
return loc1.begin == loc2.begin && loc1.end == loc2.end;
}
/// Compare two location objects.
inline bool
operator!= (const location& loc1, const location& loc2)
{
return !(loc1 == loc2);
}
/** \brief Intercept output stream redirection.
** \param ostr the destination output stream
** \param loc a reference to the location to redirect
**
** Avoid duplicate information.
*/
template <typename YYChar>
inline std::basic_ostream<YYChar>&
operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
{
position last = loc.end - 1;
ostr << loc.begin;
if (last.filename
&& (!loc.begin.filename
|| *loc.begin.filename != *last.filename))
ostr << '-' << last;
else if (loc.begin.line != last.line)
ostr << '-' << last.line << '.' << last.column;
else if (loc.begin.column != last.column)
ostr << '-' << last.column;
return ostr;
}
} // yy
/* Line 296 of location.cc */
#line 180 "location.hh"
#endif /* !YY_YY_LOCATION_HH_INCLUDED */

172
src/StepFile/position.hh Normal file
View File

@@ -0,0 +1,172 @@
/* A Bison parser, made by GNU Bison 2.7. */
/* Positions for Bison parsers in C++
Copyright (C) 2002-2007, 2009-2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/**
** \file position.hh
** Define the yy::position class.
*/
#ifndef YY_YY_POSITION_HH_INCLUDED
# define YY_YY_POSITION_HH_INCLUDED
# include <algorithm> // std::max
# include <iostream>
# include <string>
# ifndef YY_NULL
# if defined __cplusplus && 201103L <= __cplusplus
# define YY_NULL nullptr
# else
# define YY_NULL 0
# endif
# endif
namespace yy {
/* Line 36 of location.cc */
#line 57 "position.hh"
/// Abstract a position.
class position
{
public:
/// Construct a position.
explicit position (std::string* f = YY_NULL,
unsigned int l = 1u,
unsigned int c = 1u)
: filename (f)
, line (l)
, column (c)
{
}
/// Initialization.
void initialize (std::string* fn = YY_NULL,
unsigned int l = 1u,
unsigned int c = 1u)
{
filename = fn;
line = l;
column = c;
}
/** \name Line and Column related manipulators
** \{ */
/// (line related) Advance to the COUNT next lines.
void lines (int count = 1)
{
column = 1u;
line += count;
}
/// (column related) Advance to the COUNT next columns.
void columns (int count = 1)
{
column = std::max (1u, column + count);
}
/** \} */
/// File name to which this position refers.
std::string* filename;
/// Current line number.
unsigned int line;
/// Current column number.
unsigned int column;
};
/// Add and assign a position.
inline position&
operator+= (position& res, const int width)
{
res.columns (width);
return res;
}
/// Add two position objects.
inline const position
operator+ (const position& begin, const int width)
{
position res = begin;
return res += width;
}
/// Add and assign a position.
inline position&
operator-= (position& res, const int width)
{
return res += -width;
}
/// Add two position objects.
inline const position
operator- (const position& begin, const int width)
{
return begin + -width;
}
/// Compare two position objects.
inline bool
operator== (const position& pos1, const position& pos2)
{
return (pos1.line == pos2.line
&& pos1.column == pos2.column
&& (pos1.filename == pos2.filename
|| (pos1.filename && pos2.filename
&& *pos1.filename == *pos2.filename)));
}
/// Compare two position objects.
inline bool
operator!= (const position& pos1, const position& pos2)
{
return !(pos1 == pos2);
}
/** \brief Intercept output stream redirection.
** \param ostr the destination output stream
** \param pos a reference to the position to redirect
*/
template <typename YYChar>
inline std::basic_ostream<YYChar>&
operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
{
if (pos.filename)
ostr << *pos.filename << ':';
return ostr << pos.line << '.' << pos.column;
}
} // yy
/* Line 148 of location.cc */
#line 172 "position.hh"
#endif /* !YY_YY_POSITION_HH_INCLUDED */

View File

@@ -52,9 +52,10 @@
static char txt_cart_p[] = "CARTESIAN_POINT";
void rec_restext(char* newtext, int lentext) /* destine a etre appele de l'exterieur */
void rec_restext(const char* constnewtext, int lentext) /* destine a etre appele de l'exterieur */
{
char *res, *text;
char *res, *text, *newtext;
newtext = const_cast<char*>(constnewtext);
if(strcmp(newtext,txt_cart_p)==0) {
restext = txt_cart_p;
return;
@@ -167,9 +168,18 @@ static char idzero[] = "#0";
/* Trace pour controle */
#ifdef __cplusplus
extern "C" {
#endif
void recfile_modeprint(int mode)
{ modeprint = mode; }
#ifdef __cplusplus
}
#endif
static int lastno;
extern int steplineno;
extern int modcom;
@@ -482,7 +492,9 @@ void scope_fin()
La liberation de la memoire est faite par lir_file_fin, en une fois
*/
#ifdef __cplusplus
extern "C" {
#endif
void lir_file_nbr(int* nbh, int* nbr, int* nbp)
/* initialise le traitement et retourne la taille du directory et du header */
{
@@ -562,6 +574,9 @@ int lir_file_arg(int* type, char* *val)
return (1) ;
}
#ifdef __cplusplus
}
#endif
/* Verification de l'integrite des donnees */
@@ -599,6 +614,3 @@ void rec_check(int mode)
("Liste des records pourrie, nb note %d relu %d\n",nbrec,nr) ;
}
void steperror (char *mess);
int steplex (void);

36
src/StepFile/scanner.hpp Normal file
View File

@@ -0,0 +1,36 @@
#ifndef __SCANNER_HPP__INCLUDED__
#define __SCANNER_HPP__INCLUDED__
#undef yyFlexLexer
#include <FlexLexer.h>
#include "step.tab.hxx"
// Tell flex which function to define
#ifdef YY_DECL
# undef YY_DECL
#endif
#define YY_DECL \
int yy::scanner::lex( \
yy::parser::semantic_type* yylval, \
yy::parser::location_type* yylloc)
namespace yy
{
// To feed data back to bison, the yylex method needs yylval and
// yylloc parameters. Since the yyFlexLexer class is defined in the
// system header <FlexLexer.h> the signature of its yylex() method
// can not be changed anymore. This makes it necessary to derive a
// scanner class that provides a method with the desired signature:
class scanner : public yyFlexLexer
{
public:
explicit scanner(std::istream* in=0, std::ostream* out=0);
int lex(yy::parser::semantic_type* yylval,
yy::parser::location_type* yylloc);
};
}
#endif // include guard

137
src/StepFile/stack.hh Normal file
View File

@@ -0,0 +1,137 @@
/* A Bison parser, made by GNU Bison 2.7. */
/* Stack handling for Bison parsers in C++
Copyright (C) 2002-2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/**
** \file stack.hh
** Define the yy::stack class.
*/
#ifndef YY_YY_STACK_HH_INCLUDED
# define YY_YY_STACK_HH_INCLUDED
# include <deque>
// disable MSVC warnings in bison code
#ifdef _MSC_VER
#pragma warning(disable:4512)
#endif
namespace yy {
/* Line 34 of stack.hh */
#line 47 "stack.hh"
template <class T, class S = std::deque<T> >
class stack
{
public:
// Hide our reversed order.
typedef typename S::reverse_iterator iterator;
typedef typename S::const_reverse_iterator const_iterator;
stack () : seq_ ()
{
}
stack (unsigned int n) : seq_ (n)
{
}
inline
T&
operator [] (unsigned int i)
{
return seq_[i];
}
inline
const T&
operator [] (unsigned int i) const
{
return seq_[i];
}
inline
void
push (const T& t)
{
seq_.push_front (t);
}
inline
void
pop (unsigned int n = 1)
{
for (; n; --n)
seq_.pop_front ();
}
inline
size_t
height () const
{
return seq_.size ();
}
inline const_iterator begin () const { return seq_.rbegin (); }
inline const_iterator end () const { return seq_.rend (); }
private:
S seq_;
};
/// Present a slice of the top of a stack.
template <class T, class S = stack<T> >
class slice
{
public:
slice (const S& stack, unsigned int range)
: stack_ (stack)
, range_ (range)
{
}
inline
const T&
operator [] (unsigned int i) const
{
return stack_[range_ - i];
}
private:
const S& stack_;
unsigned int range_;
};
} // yy
/* Line 116 of stack.hh */
#line 132 "stack.hh"
#endif /* !YY_YY_STACK_HH_INCLUDED */

View File

@@ -13,12 +13,27 @@
commercial license or contractual agreement.
*/
%option outfile="lex.step.cxx"
/*
c++ generate C++ parser class
8bit don't fail on 8-bit input characters
warn warn about inconsistencies
nodefault don't create default echo-all rule
noyywrap don't use yywrap() function
yylineno maintains the number of the current line
*/
%option c++
%option 8bit warn nodefault
%option noyywrap
%option yylineno
%{
#include "step.tab.h"
#include "step.tab.hxx"
#include "scanner.hpp"
#include "recfile.ph"
#include "stdio.h"
#include <StepFile_CallFailure.hxx>
typedef yy::parser::token token;
/* skl 31.01.2002 for OCC133(OCC96,97) - uncorrect
long string in files Henri.stp and 401.stp*/
#define YY_FATAL_ERROR(msg) StepFile_CallFailure( msg )
@@ -30,15 +45,14 @@ long string in files Henri.stp and 401.stp*/
void steperror ( FILE *input_file );
void steprestart ( FILE *input_file );
*/
void rec_restext(char *newtext, int lentext);
void rec_restext(const char *constnewtext, int lentext);
void rec_typarg(int argtype);
int steplineno; /* Comptage de ligne (ben oui, fait tout faire) */
int modcom = 0; /* Commentaires type C */
int modend = 0; /* Flag for finishing of the STEP file */
void resultat () /* Resultat alloue dynamiquement, "jete" une fois lu */
{ if (modcom == 0) rec_restext(yytext,yyleng); }
// MSVC specifics
#ifdef _MSC_VER
@@ -48,7 +62,7 @@ void rec_typarg(int argtype);
#if defined(__INTEL_COMPILER)
#pragma warning(disable:177 1786 1736)
#else
#pragma warning(disable:4131 4244 4273 4267 4127)
#pragma warning(disable:4131 4244 4273 4267 4127 4100)
#endif
// Avoid includion of unistd.h if parser is generated on Linux (flex 2.5.35)
@@ -62,43 +76,56 @@ void rec_typarg(int argtype);
#endif
%}
%%
" " {;}
" " {;}
[\n] { steplineno ++; }
[\r] {;} /* abv 30.06.00: for reading DOS files */
[\0]+ {;} /* fix from C21. for test load e3i file with line 15 with null symbols */
#[0-9]+/= { resultat(); if (modcom == 0) return(ENTITY); }
#[0-9]+/[ ]*= { resultat(); if (modcom == 0) return(ENTITY); }
#[0-9]+ { resultat(); if (modcom == 0) return(IDENT); }
[-+0-9][0-9]* { resultat(); if (modcom == 0) { rec_typarg(rec_argInteger); return(QUID); } }
[-+\.0-9][\.0-9]+ { resultat(); if (modcom == 0) { rec_typarg(rec_argFloat); return(QUID); } }
[-+\.0-9][\.0-9]+E[-+0-9][0-9]* { resultat(); if (modcom == 0) { rec_typarg(rec_argFloat); return(QUID); } }
[\']([\n]|[\000\011-\046\050-\176\201-\237\240-\777]|[\047][\047])*[\'] { resultat(); if (modcom == 0) { rec_typarg(rec_argText); return(QUID); } }
["][0-9A-F]+["] { resultat(); if (modcom == 0) { rec_typarg(rec_argHexa); return(QUID); } }
[.][A-Z0-9_]+[.] { resultat(); if (modcom == 0) { rec_typarg(rec_argEnum); return(QUID); } }
#[0-9]+/= { if (modcom == 0) { rec_restext(YYText(),YYLeng()); return(token::ENTITY); } }
#[0-9]+/[ ]*= { if (modcom == 0) { rec_restext(YYText(),YYLeng()); return(token::ENTITY); } }
#[0-9]+ { if (modcom == 0) { rec_restext(YYText(),YYLeng()); return(token::IDENT); } }
[-+0-9][0-9]* { if (modcom == 0) { rec_restext(YYText(),YYLeng()); rec_typarg(rec_argInteger); return(token::QUID); } }
[-+\.0-9][\.0-9]+ { if (modcom == 0) { rec_restext(YYText(),YYLeng()); rec_typarg(rec_argFloat); return(token::QUID); } }
[-+\.0-9][\.0-9]+E[-+0-9][0-9]* { if (modcom == 0) { rec_restext(YYText(),YYLeng()); rec_typarg(rec_argFloat); return(token::QUID); } }
[\']([\n]|[\000\011-\046\050-\176\201-\237\240-\777]|[\047][\047])*[\'] { if (modcom == 0) { rec_restext(YYText(),YYLeng()); rec_typarg(rec_argText); return(token::QUID); } }
["][0-9A-F]+["] { if (modcom == 0) { rec_restext(YYText(),YYLeng()); rec_typarg(rec_argHexa); return(token::QUID); } }
[.][A-Z0-9_]+[.] { if (modcom == 0) { rec_restext(YYText(),YYLeng()); rec_typarg(rec_argEnum); return(token::QUID); } }
[(] { if (modcom == 0) return ('('); }
[)] { if (modcom == 0) return (')'); }
[,] { if (modcom == 0) return (','); }
[$] { resultat(); if (modcom == 0) { rec_typarg(rec_argNondef); return(QUID); } }
[$] { if (modcom == 0) { rec_restext(YYText(),YYLeng()); rec_typarg(rec_argNondef); return(token::QUID); } }
[=] { if (modcom == 0) return ('='); }
[;] { if (modcom == 0) return (';'); }
"/*" { modcom = 1; }
"*/" { if (modend == 0) modcom = 0; }
STEP; { if (modcom == 0) return(STEP); }
HEADER; { if (modcom == 0) return(HEADER); }
ENDSEC; { if (modcom == 0) return(ENDSEC); }
DATA; { if (modcom == 0) return(DATA); }
ENDSTEP; { if (modend == 0) {modcom = 0; return(ENDSTEP);} }
"ENDSTEP;".* { if (modend == 0) {modcom = 0; return(ENDSTEP);} }
END-ISO[0-9\-]*; { modcom = 1; modend = 1; return(ENDSTEP); }
ISO[0-9\-]*; { if (modend == 0) {modcom = 0; return(STEP); } }
STEP; { if (modcom == 0) return(token::STEP); }
HEADER; { if (modcom == 0) return(token::HEADER); }
ENDSEC; { if (modcom == 0) return(token::ENDSEC); }
DATA; { if (modcom == 0) return(token::DATA); }
ENDSTEP; { if (modend == 0) {modcom = 0; return(token::ENDSTEP);} }
"ENDSTEP;".* { if (modend == 0) {modcom = 0; return(token::ENDSTEP);} }
END-ISO[0-9\-]*; { modcom = 1; modend = 1; return(token::ENDSTEP); }
ISO[0-9\-]*; { if (modend == 0) {modcom = 0; return(token::STEP); } }
[/] { if (modcom == 0) return ('/'); }
&SCOPE { if (modcom == 0) return(SCOPE); }
ENDSCOPE { if (modcom == 0) return(ENDSCOPE); }
[a-zA-Z0-9_]+ { resultat(); if (modcom == 0) return(TYPE); }
![a-zA-Z0-9_]+ { resultat(); if (modcom == 0) return(TYPE); }
[^)] { resultat(); if (modcom == 0) { rec_typarg(rec_argMisc); return(QUID); } }
&SCOPE { if (modcom == 0) return(token::SCOPE); }
ENDSCOPE { if (modcom == 0) return(token::ENDSCOPE); }
[a-zA-Z0-9_]+ { if (modcom == 0) { rec_restext(YYText(),YYLeng()); return(token::TYPE); } }
![a-zA-Z0-9_]+ { if (modcom == 0) { rec_restext(YYText(),YYLeng()); return(token::TYPE); } }
[^)] { if (modcom == 0) { rec_restext(YYText(),YYLeng()); rec_typarg(rec_argMisc); return(token::QUID); } }
%%
yy::scanner::scanner(std::istream* in, std::ostream* out)
: yyFlexLexer(in, out)
{
}
int yyFlexLexer::yylex()
{
throw std::logic_error(
"The yylex() exists for technical reasons and must not be used.");
}

File diff suppressed because it is too large Load Diff

1076
src/StepFile/step.tab.cxx Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,93 +0,0 @@
/* A Bison parser, made by GNU Bison 2.7. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
#ifndef YY_STEP_STEP_TAB_H_INCLUDED
# define YY_STEP_STEP_TAB_H_INCLUDED
/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int stepdebug;
#endif
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
STEP = 258,
HEADER = 259,
ENDSEC = 260,
DATA = 261,
ENDSTEP = 262,
SCOPE = 263,
ENDSCOPE = 264,
ENTITY = 265,
TYPE = 266,
INTEGER = 267,
FLOAT = 268,
IDENT = 269,
TEXT = 270,
NONDEF = 271,
ENUM = 272,
HEXA = 273,
QUID = 274
};
#endif
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef int YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE steplval;
#ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus
int stepparse (void *YYPARSE_PARAM);
#else
int stepparse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
int stepparse (void);
#else
int stepparse ();
#endif
#endif /* ! YYPARSE_PARAM */
#endif /* !YY_STEP_STEP_TAB_H_INCLUDED */

285
src/StepFile/step.tab.hxx Normal file
View File

@@ -0,0 +1,285 @@
/* A Bison parser, made by GNU Bison 2.7. */
/* Skeleton interface for Bison LALR(1) parsers in C++
Copyright (C) 2002-2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/**
** \file step.tab.hxx
** Define the yy::parser class.
*/
/* C++ LALR(1) parser skeleton written by Akim Demaille. */
#ifndef YY_YY_STEP_TAB_HXX_INCLUDED
# define YY_YY_STEP_TAB_HXX_INCLUDED
/* "%code requires" blocks. */
/* Line 33 of lalr1.cc */
#line 31 "StepFile/step.yacc"
#include "location.hh"
#include <stdexcept>
namespace yy {
class scanner;
};
/* Line 33 of lalr1.cc */
#line 56 "step.tab.hxx"
#include <string>
#include <iostream>
#include "stack.hh"
#include "location.hh"
/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
namespace yy {
/* Line 33 of lalr1.cc */
#line 72 "step.tab.hxx"
/// A Bison parser.
class parser
{
public:
/// Symbol semantic values.
#ifndef YYSTYPE
typedef int semantic_type;
#else
typedef YYSTYPE semantic_type;
#endif
/// Symbol locations.
typedef location location_type;
/// Tokens.
struct token
{
/* Tokens. */
enum yytokentype {
STEP = 258,
HEADER = 259,
ENDSEC = 260,
DATA = 261,
ENDSTEP = 262,
SCOPE = 263,
ENDSCOPE = 264,
ENTITY = 265,
TYPE = 266,
INTEGER = 267,
FLOAT = 268,
IDENT = 269,
TEXT = 270,
NONDEF = 271,
ENUM = 272,
HEXA = 273,
QUID = 274
};
};
/// Token type.
typedef token::yytokentype token_type;
/// Build a parser object.
parser (yy::scanner* scanner_yyarg);
virtual ~parser ();
/// Parse.
/// \returns 0 iff parsing succeeded.
virtual int parse ();
#if YYDEBUG
/// The current debugging stream.
std::ostream& debug_stream () const;
/// Set the current debugging stream.
void set_debug_stream (std::ostream &);
/// Type for debugging levels.
typedef int debug_level_type;
/// The current debugging level.
debug_level_type debug_level () const;
/// Set the current debugging level.
void set_debug_level (debug_level_type l);
#endif
private:
/// Report a syntax error.
/// \param loc where the syntax error is found.
/// \param msg a description of the syntax error.
virtual void error (const location_type& loc, const std::string& msg);
/// Generate an error message.
/// \param state the state where the error occurred.
/// \param tok the lookahead token.
virtual std::string yysyntax_error_ (int yystate, int tok);
#if YYDEBUG
/// \brief Report a symbol value on the debug stream.
/// \param yytype The token type.
/// \param yyvaluep Its semantic value.
/// \param yylocationp Its location.
virtual void yy_symbol_value_print_ (int yytype,
const semantic_type* yyvaluep,
const location_type* yylocationp);
/// \brief Report a symbol on the debug stream.
/// \param yytype The token type.
/// \param yyvaluep Its semantic value.
/// \param yylocationp Its location.
virtual void yy_symbol_print_ (int yytype,
const semantic_type* yyvaluep,
const location_type* yylocationp);
#endif
/// State numbers.
typedef int state_type;
/// State stack type.
typedef stack<state_type> state_stack_type;
/// Semantic value stack type.
typedef stack<semantic_type> semantic_stack_type;
/// location stack type.
typedef stack<location_type> location_stack_type;
/// The state stack.
state_stack_type yystate_stack_;
/// The semantic value stack.
semantic_stack_type yysemantic_stack_;
/// The location stack.
location_stack_type yylocation_stack_;
/// Whether the given \c yypact_ value indicates a defaulted state.
/// \param yyvalue the value to check
static bool yy_pact_value_is_default_ (int yyvalue);
/// Whether the given \c yytable_ value indicates a syntax error.
/// \param yyvalue the value to check
static bool yy_table_value_is_error_ (int yyvalue);
/// Internal symbol numbers.
typedef unsigned char token_number_type;
/* Tables. */
/// For a state, the index in \a yytable_ of its portion.
static const signed char yypact_[];
static const signed char yypact_ninf_;
/// For a state, default reduction number.
/// Unless\a yytable_ specifies something else to do.
/// Zero means the default is an error.
static const unsigned char yydefact_[];
static const signed char yypgoto_[];
static const signed char yydefgoto_[];
/// What to do in a state.
/// \a yytable_[yypact_[s]]: what to do in state \a s.
/// - if positive, shift that token.
/// - if negative, reduce the rule which number is the opposite.
/// - if zero, do what YYDEFACT says.
static const signed char yytable_[];
static const signed char yytable_ninf_;
static const unsigned char yycheck_[];
/// For a state, its accessing symbol.
static const unsigned char yystos_[];
/// For a rule, its LHS.
static const unsigned char yyr1_[];
/// For a rule, its RHS length.
static const unsigned char yyr2_[];
#if YYDEBUG
/// For a symbol, its name in clear.
static const char* const yytname_[];
/// A type to store symbol numbers and -1.
typedef signed char rhs_number_type;
/// A `-1'-separated list of the rules' RHS.
static const rhs_number_type yyrhs_[];
/// For each rule, the index of the first RHS symbol in \a yyrhs_.
static const unsigned char yyprhs_[];
/// For each rule, its source line number.
static const unsigned char yyrline_[];
/// For each scanner token number, its symbol number.
static const unsigned short int yytoken_number_[];
/// Report on the debug stream that the rule \a r is going to be reduced.
virtual void yy_reduce_print_ (int r);
/// Print the state stack on the debug stream.
virtual void yystack_print_ ();
/* Debugging. */
int yydebug_;
std::ostream* yycdebug_;
#endif
/// Convert a scanner token number \a t to a symbol number.
token_number_type yytranslate_ (int t);
/// \brief Reclaim the memory associated to a symbol.
/// \param yymsg Why this token is reclaimed.
/// If null, do not display the symbol, just free it.
/// \param yytype The symbol type.
/// \param yyvaluep Its semantic value.
/// \param yylocationp Its location.
inline void yydestruct_ (const char* yymsg,
int yytype,
semantic_type* yyvaluep,
location_type* yylocationp);
/// Pop \a n symbols the three stacks.
inline void yypop_ (unsigned int n = 1);
/* Constants. */
static const int yyeof_;
/* LAST_ -- Last index in TABLE_. */
static const int yylast_;
static const int yynnts_;
static const int yyempty_;
static const int yyfinal_;
static const int yyterror_;
static const int yyerrcode_;
static const int yyntokens_;
static const unsigned int yyuser_token_number_max_;
static const token_number_type yyundef_token_;
/* User arguments. */
yy::scanner* scanner;
};
} // yy
/* Line 33 of lalr1.cc */
#line 282 "step.tab.hxx"
#endif /* !YY_YY_STEP_TAB_HXX_INCLUDED */

View File

@@ -13,11 +13,35 @@
commercial license or contractual agreement.
*/
%output "step.tab.cxx"
%defines "step.tab.hxx"
%language "C++"
%require "2.7"
/* C++ parser interface */
%skeleton "lalr1.cc"
%parse-param {yy::scanner* scanner}
%locations
%token STEP HEADER ENDSEC DATA ENDSTEP SCOPE ENDSCOPE ENTITY TYPE INTEGER FLOAT IDENT TEXT NONDEF ENUM HEXA QUID
%start stepf
%{
%code requires {
#include "location.hh"
#include <stdexcept>
namespace yy {
class scanner;
};
}
%code {
#include "recfile.ph" /* definitions des types d'arguments */
#include "recfile.pc" /* la-dedans, tout y est */
#include "scanner.hpp"
#undef yylex
#define yylex scanner->lex
/*
#define stepparse STEPparse
#define steplex STEPlex
@@ -31,6 +55,7 @@
#define stepnerrs STEPnerrs
#define steperror STEPerror
*/
#define stepclearin yychar = -1
#define steperrok yyerrflag = 0
@@ -52,12 +77,12 @@
// disable MSVC warnings in bison code
#ifdef _MSC_VER
#pragma warning(disable:4244 4131 4127 4702)
#pragma warning(disable:4065 4244 4131 4127 4702)
#define YYMALLOC malloc
#define YYFREE free
#endif
%}
void StepFile_Interrupt (char* nomfic); /* rln 13.09.00 port on HP*/
}
%%
/* N.B. : les commentaires sont filtres par LEX */
/* La fin vide (selon systeme emetteur) est filtree ici */
@@ -85,7 +110,7 @@ unarg : IDENT { rec_typarg(rec_argIdent); rec_newarg(); }
| listarg /* rec_newent lors du ')' */ { rec_newarg(); }
| listype listarg /* liste typee */ { rec_newarg(); }
| error { rec_typarg(rec_argMisc); rec_newarg();
yyerrstatus = 1; yyclearin; }
yyerrstatus_ = 1; yyclearin; }
/* Erreur sur Parametre : tacher de le noter sans jeter l'Entite */
;
listype : TYPE
@@ -97,7 +122,7 @@ deblist : '('
finlist : ')'
{ if (modeprint > 0)
{ printf("Record no : %d -- ",nbrec+1); rec_print(currec); }
rec_newent (); yyerrstatus = 0; }
rec_newent (); yyerrstatus_ = 0; }
;
listarg : deblist finlist /* liste vide (peut y en avoir) */
| deblist arglist finlist /* liste normale, non vide */
@@ -146,3 +171,11 @@ entlab : ENTITY
enttype : TYPE
{ rec_type (); }
;
%%
void yy::parser::error(const parser::location_type& l, const std::string& m)
{
char newmess[80];
sprintf(newmess, "At line %d, %s : %s", scanner->lineno() + 1, l, m.c_str());
StepFile_Interrupt(newmess);
}

View File

@@ -23,8 +23,11 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include "recfile.ph"
#include <OSD_OpenFile.hxx>
#include "scanner.hpp"
/* StepFile_Error.c
@@ -41,38 +44,14 @@
continuation a change
*/
static int lastno;
extern int steplineno;
extern void StepFile_Interrupt (char* nomfic); /* rln 13.09.00 port on HP*/
int stepparse(void);
void rec_debfile();
void steprestart(FILE *input_file);
void rec_debfile();
void rec_finfile();
void steperror (char *mess)
{
char newmess[80];
if (steplineno == lastno) return;
lastno = steplineno;
sprintf (newmess,"At line %d, %s",steplineno+1,mess);
/* yysbuf[0] = '\0';
yysptr = yysbuf;
* yylineno = 0; */
StepFile_Interrupt(newmess);
}
/* But de ce mini-programme : appeler yyparse et si besoin preciser un
fichier d'entree
StepFile_Error redefinit yyerror pour ne pas stopper (s'y reporter)
*/
extern FILE* stepin ; /* input de yyparse (executeur de lex-yacc) */
extern int steplineno; /* compteur de ligne lex (pour erreurs) */
/* Designation d'un fichier de lecture
(par defaut, c'est l'entree standard)
@@ -81,40 +60,31 @@ extern int steplineno; /* compteur de ligne lex (pour erreurs) */
iflag retourne vaut 0 si c'est OK, 1 sinon
*/
FILE* stepread_setinput (char* nomfic)
void stepread_setinput(std::ifstream& stream, char* nomfic)
{
FILE* newin ;
if (strlen(nomfic) == 0) return stepin ;
newin = OSD_OpenFile(nomfic,"r");
if (newin == NULL) {
return NULL ;
} else {
stepin = newin ; return newin ;
}
if (strlen(nomfic) == 0) return;
OSD_OpenStream(stream, nomfic, std::ios_base::in | std::ios_base::binary);
}
void stepread_endinput (FILE* infic, char* nomfic)
void stepread_endinput (std::ifstream& stream, char* nomfic)
{
if (!infic) return;
if (!stream) return;
if (strlen(nomfic) == 0) return;
fclose (infic);
stream.close();
}
/* Lecture d'un fichier ia grammaire lex-yacc
Appel : i = stepread() ; i est la valeur retournee par yyparse
(0 si OK, 1 si erreur)
*/
int stepread ()
int stepread(std::istream* stream)
{
int letat;
lastno = 0;
steplineno = 0;
rec_debfile() ;
steprestart(stepin);
letat = stepparse() ;
rec_finfile() ;
int letat = 0;
rec_debfile();
yy::scanner scanner(stream);
scanner.yyrestart(stream);
yy::parser parser(&scanner);
letat = parser.parse();
rec_finfile();
return letat;
}
int stepwrap () { return 1; }
}

View File

@@ -16,18 +16,27 @@
// stepread.h
/* lecture du fichier STEP (par appel a lex+yac) */
#include <iostream>
extern "C" FILE* stepread_setinput (char* nomfic) ;
extern "C" void stepread_endinput (FILE* infic, char* nomfic);
extern "C" int stepread() ;
extern "C" void recfile_modeprint (int mode) ; /* controle trace recfile */
#ifdef __cplusplus
extern "C" {
#endif
void recfile_modeprint (int mode) ; /* controle trace recfile */
/* creation du Direc a partir de recfile : entrys connues de c++ */
extern "C" void lir_file_nbr(int* nbh, int* nbr, int* nbp) ;
extern "C" int lir_file_rec(char* *ident , char* *type , int* nbarg) ;
extern "C" void lir_file_finrec() ;
extern "C" int lir_file_arg(int* type , char* *val) ;
extern "C" void lir_file_fin(int mode);
void lir_file_nbr(int* nbh, int* nbr, int* nbp) ;
int lir_file_rec(char* *ident , char* *type , int* nbarg) ;
void lir_file_finrec() ;
int lir_file_arg(int* type , char* *val) ;
void lir_file_fin(int mode);
/* Interruption passant par C++ */
extern "C" void StepFile_Interrupt (char* nomfic);
#ifdef __cplusplus
}
#endif
void stepread_setinput(std::ifstream& stream, char* nomfic);
void stepread_endinput (std::ifstream& stream, char* nomfic);
int stepread(std::istream* stream);
void StepFile_Interrupt (char* nomfic);

View File

@@ -78,6 +78,23 @@ Standard_Integer StepSelect_WorkLibrary::ReadFile
return status;
}
Standard_Integer StepSelect_WorkLibrary::ReadFile
(const Standard_CString name,
std::istream* istream,
Handle(Interface_InterfaceModel)& model,
const Handle(Interface_Protocol)& protocol) const
{
long status = 1;
DeclareAndCast(StepData_Protocol, stepro, protocol);
if (stepro.IsNull()) return 1;
Handle(StepData_StepModel) stepmodel = new StepData_StepModel;
model = stepmodel;
StepFile_ReadTrace(0);
char *pName = (char *)name;
status = StepFile_Read(pName, istream, stepmodel, stepro);
return status;
}
Standard_Boolean StepSelect_WorkLibrary::WriteFile
(IFSelect_ContextWrite& ctx) const

View File

@@ -58,7 +58,12 @@ public:
//! or lets <mod> "Null" in case of Error
//! Returns 0 if OK, 1 if Read Error, -1 if File not opened
Standard_EXPORT Standard_Integer ReadFile (const Standard_CString name, Handle(Interface_InterfaceModel)& model, const Handle(Interface_Protocol)& protocol) const Standard_OVERRIDE;
//! Reads a STEP File and returns a STEP Model (into <mod>),
//! or lets <mod> "Null" in case of Error
//! Returns 0 if OK, 1 if Read Error, -1 if File not opened
Standard_EXPORT Standard_Integer ReadFile(const Standard_CString name, std::istream* istream, Handle(Interface_InterfaceModel)& model, const Handle(Interface_Protocol)& protocol) const Standard_OVERRIDE;
//! Writes a File from a STEP Model
//! Returns False (and writes no file) if <ctx> does not bring a
//! STEP Model

View File

@@ -123,9 +123,9 @@ Handle(XSControl_WorkSession) XSControl_Reader::WS () const
//=======================================================================
IFSelect_ReturnStatus XSControl_Reader::ReadFile
(const Standard_CString filename)
(const Standard_CString filename, std::istream* istream)
{
IFSelect_ReturnStatus stat = thesession->ReadFile(filename);
IFSelect_ReturnStatus stat = thesession->ReadFile(filename, istream);
thesession->InitTransferReader(4);
return stat;
}

View File

@@ -100,7 +100,7 @@ Standard_EXPORT virtual ~XSControl_Reader() {}
//! Loads a file and returns the read status
//! Zero for a Model which compies with the Controller
Standard_EXPORT IFSelect_ReturnStatus ReadFile (const Standard_CString filename);
Standard_EXPORT IFSelect_ReturnStatus ReadFile (const Standard_CString filename, std::istream* istream = 0);
//! Returns the model. It can then be consulted (header, product)
Standard_EXPORT Handle(Interface_InterfaceModel) Model() const;