home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftptest.leeds.ac.uk
/
2015.02.ftptest.leeds.ac.uk.tar
/
ftptest.leeds.ac.uk
/
bionet
/
CAE-GROUP
/
SCL-WIN3x
/
SCL.EXE
/
UNDEFINE.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-06
|
9KB
|
439 lines
/*
* NIST STEP Core Class Library
* clstepcore/STEPundefined.cc
* February, 1994
* KC Morris
* David Sauder
* Development of this software was funded by the United States Government,
* and is not subject to copyright.
*/
/* $Id: STEPundefined.cc,v 2.0.1.1 1994/04/05 16:39:53 sauderd Exp $ */
#include <stdio.h> // to get the BUFSIZ #define
#include <undefine.h>
#include <attribut.h>
/******************************************************************
** helping functions for reading unknown types **/
// return 1 if 'in' points at a quoted quote otherwise return 0
int
QuoteInString(istream& in)
{
char c1, c2;
if( in.good() )
{
in >> c1;
in >> c2;
in.putback(c2);
in.putback(c1);
if (c1 == STRING_DELIM)
{
if(c2 == STRING_DELIM)
return 1;
}
}
return 0;
}
// assign 's' so that it contains an exchange file format string read from
// 'in'. The string 's' is assigned starting at 'index'. The string 's' is
// of size 'sSize'. If assigning the string causes 's' to run out of room,
// 's' is deleted and reallocated larger and 's' and 'sSize' are returned
// changed as appropriate. 'index' is changed and returned so that it points
// into 's' past the string that was assigned.
void
PushPastString (istream& in, SCLstring &s, ErrorDescriptor *err)
{
char messageBuf[BUFSIZ];
messageBuf[0] = '\0';
char c;
in >> c;
while(isspace(c))
{
s.Append(c);
in >> c;
}
if(c == STRING_DELIM)
{
s.Append(c);
while(QuoteInString(in))
{
in.get(c);
s.Append(c);
in.get(c);
s.Append(c);
}
in.get(c);
//int sk = in.skip(0);
while( ( c != STRING_DELIM) && !in.eof() )
{
s.Append(c);
while(QuoteInString(in))
{
in.get(c);
s.Append(c);
// AppendChar(c, index, s, sSize);
in.get(c);
s.Append(c);
// AppendChar(c, index, s, sSize);
}
in.get(c);
}
//in.skip(sk);
if(c != STRING_DELIM)
{
err->GreaterSeverity(SEVERITY_INPUT_ERROR);
sprintf(messageBuf, "Invalid string value.\n");
err->AppendToDetailMsg(messageBuf);
s.Append('\'');
}
else
s.Append(c);
}
}
// assign 's' so that it contains an exchange file format aggregate read from
// 'in'. The string 's' is assigned starting at 'index'. The string 's' is
// of size 'sSize'. If assigning the aggregate causes 's' to run out of room,
// 's' is deleted and reallocated larger and 's' and 'sSize' are returned
// changed as appropriate. 'index' is changed and returned so that it points
// into 's' past the aggregate that was assigned.
// This is used to read aggregates that are part of multidimensional
// aggregates.
void
PushPastImbedAggr (istream& in, SCLstring &s, ErrorDescriptor *err)
{
char messageBuf[BUFSIZ];
messageBuf[0] = '\0';
char c;
in.get(c);
while(isspace(c))
{
s.Append(c);
in.get(c);
}
if(c == '(')
{
s.Append(c);
in.get(c);
while( (c != ')') && !in.eof() )
{
if ( c == '(' )
{
in.putback(c);
PushPastImbedAggr(in, s, err);
}
else if (c == STRING_DELIM)
{
in.putback(c);
PushPastString(in, s, err);
}
else
s.Append(c);
in.get(c);
}
if(c != ')')
{
err->GreaterSeverity(SEVERITY_INPUT_ERROR);
sprintf(messageBuf, "Invalid aggregate value.\n");
err->AppendToDetailMsg(messageBuf);
s.Append(')');
}
else
s.Append(c);
}
}
// assign 's' so that it contains an exchange file format aggregate read from
// 'in'. The string 's' is assigned starting at 'index'. The string 's' is
// of size 'sSize'. If assigning the aggregate causes 's' to run out of room,
// 's' is deleted and reallocated larger and 's' and 'sSize' are returned
// changed as appropriate. 'index' is changed and returned so that it points
// into 's' past the aggregate that was assigned.
// This is used to read a single dimensional aggregate (i.e. it is not allowed
// to contain an aggregate as an element.
void
PushPastAggr1Dim(istream& in, SCLstring &s, ErrorDescriptor *err)
{
char messageBuf[BUFSIZ];
messageBuf[0] = '\0';
char c;
in.get(c);
while(isspace(c))
{
s.Append(c);
in.get(c);
}
if(c == '(')
{
s.Append(c);
in.get(c);
while( (c != ')') && !in.eof() )
{
if ( c == '(' )
{
err->GreaterSeverity(SEVERITY_WARNING);
sprintf(messageBuf, "Invalid aggregate value.\n");
err->AppendToDetailMsg(messageBuf);
}
if (c == STRING_DELIM)
{
in.putback(c);
PushPastString(in, s, err);
}
else
s.Append(c);
in.get(c);
}
if(c != ')')
{
err->GreaterSeverity(SEVERITY_INPUT_ERROR);
sprintf(messageBuf, "Invalid aggregate value.\n");
err->AppendToDetailMsg(messageBuf);
s.Append(')');
}
else
s.Append(c);
}
}
Severity
SCLundefined::StrToVal(const char *s, ErrorDescriptor *err)
{
val = s;
return SEVERITY_NULL;
}
Severity
SCLundefined::StrToVal(istream &in, ErrorDescriptor *err)
{
return STEPread(in, err);
}
Severity
SCLundefined::STEPread(const char *s, ErrorDescriptor *err)
{
istrstream in((char *) s);
return STEPread(in, err);
}
Severity
SCLundefined::STEPread(istream &in, ErrorDescriptor *err)
{
char c = '\0';
strstream ss;
SCLstring str;
int terminal = 0;
in >> ws; // skip white space
in >> c;
if(c == '$')
{
val = "";
CheckRemainingInput(in, err, "aggregate item", ",)");
}
else
in.putback(c);
while (!terminal)
{
in.get(c);
switch (c)
{
case '(':
in.putback(c);
PushPastImbedAggr(in, str, err);
ss << str.chars();
break;
case '\'':
in.putback(c);
PushPastString(in, str, err);
ss << str.chars();
break;
case ',':
terminal = 1; // it's a STEPattribute separator
in.putback (c);
c = '\0';
break;
case ')':
in.putback (c);
terminal = 1; // found a valid delimiter
break;
case '\0':
case EOF:
terminal = 1; // found a valid delimiter
break;
default:
ss.put(c);
break;
}
if (!in.good ()) {
terminal =1;
c = '\0';
}
// if (!in.readable ()) terminal =1;
}
ss << ends;
val = ss.str();
err->GreaterSeverity(SEVERITY_NULL);
return SEVERITY_NULL;
}
const char *
SCLundefined::asStr(SCLstring & s) const
{
s = val.chars();
return s.chars();
}
const char *
SCLundefined::STEPwrite(SCLstring &s)
{
if(val.rep())
{
s = val.chars();
}
else
s = "$";
return s.chars();
}
void
SCLundefined:: STEPwrite (ostream& out)
{
if(val.rep())
out << val.chars();
else
out << "$";
}
SCLundefined&
SCLundefined::operator= (const SCLundefined& x)
{
SCLstring tmp;
val = x.asStr(tmp);
return *this;
}
SCLundefined&
SCLundefined::operator= (const char * str)
{
if (!str)
val.set_null();
else
val = str;
return *this;
}
SCLundefined::SCLundefined ()
{
}
SCLundefined::~SCLundefined ()
{
}
int
SCLundefined::set_null ()
{
val = "";
return 1;
}
int
SCLundefined::is_null ()
{
return (!strcmp (val.chars(), ""));
}
/*
int
SCLundefined::STEPread(istream& in )
{
char c ='\0';
char buf [BUFSIZ];
int i =0;
int open_paren =0;
int terminal = 0;
while (!terminal)
{
in >> c;
switch (c)
{
case '(':
++open_paren;
break;
case ')':
if (open_paren) {
--open_paren;
break;
}
// otherwise treat it like a comma
case ',':
if (!open_paren) {
terminal =1;
in.putback (c);
c = '\0';
}
break;
case '\0':
terminal =1;
break;
}
if (!in)
{
terminal =1;
c = '\0';
}
if (i < BUFSIZ) buf [i] = c;
// BUG: read up to BUFSIZ -1 number of characters
// if more characters, NULL terminate and ignore the rest of input
if ((++i == BUFSIZ) && !terminal) {
cerr << "WARNING: information lost -- value of undefined type is too long\n";
buf [i] = '\0';
}
}
if (i < BUFSIZ) buf [i+1] = '\0';
val = buf;
return i;
}
*/