Skip to content

Commit 52acad5

Browse files
committed
move some functions related to class/file names into class_strings.c/h
this is to reduce the number of source files necessary for the schema scanner
1 parent 44ab3e3 commit 52acad5

File tree

8 files changed

+271
-309
lines changed

8 files changed

+271
-309
lines changed

src/exp2cxx/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ set(exp2cxx_SOURCES
88
fedex_main.c
99
classes_wrapper.cc
1010
classes.c
11-
classes_attribute.c
12-
classes_entity.c
13-
classes_type.c
11+
classes_attribute.c
12+
classes_entity.c
13+
classes_type.c
14+
class_strings.c
1415
selects.c
1516
multpass.c
1617
collect.cc

src/exp2cxx/class_strings.c

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
#include <string.h>
2+
3+
#include "class_strings.h"
4+
#include "express/type.h"
5+
6+
const char * ClassName( const char * oldname ) {
7+
int i = 0, j = 0;
8+
static char newname [BUFSIZ];
9+
if( !oldname ) {
10+
return ( "" );
11+
}
12+
strcpy( newname, ENTITYCLASS_PREFIX ) ;
13+
j = strlen( ENTITYCLASS_PREFIX ) ;
14+
newname [j] = ToUpper( oldname [i] );
15+
++i;
16+
++j;
17+
while( oldname [i] != '\0' ) {
18+
newname [j] = ToLower( oldname [i] );
19+
/* if (oldname [i] == '_') */
20+
/* character is '_' */
21+
/* newname [++j] = ToUpper (oldname [++i]);*/
22+
++i;
23+
++j;
24+
}
25+
newname [j] = '\0';
26+
return ( newname );
27+
}
28+
29+
const char * ENTITYget_classname( Entity ent ) {
30+
const char * oldname = ENTITYget_name( ent );
31+
return ( ClassName( oldname ) );
32+
}
33+
34+
const char * TYPEget_ctype( const Type t ) {
35+
Class_Of_Type ctype;
36+
Type bt;
37+
static char retval [BUFSIZ];
38+
39+
if( TYPEinherits_from( t, aggregate_ ) ) {
40+
bt = TYPEget_body( t )->base;
41+
if( TYPEinherits_from( bt, aggregate_ ) ) {
42+
return( "GenericAggregate" );
43+
}
44+
45+
ctype = TYPEget_type( bt );
46+
if( ctype == integer_ ) {
47+
return ( "IntAggregate" );
48+
}
49+
if( ( ctype == number_ ) || ( ctype == real_ ) ) {
50+
return ( "RealAggregate" );
51+
}
52+
if( ctype == entity_ ) {
53+
return( "EntityAggregate" );
54+
}
55+
if( ( ctype == enumeration_ ) || ( ctype == select_ ) ) {
56+
strcpy( retval, TYPEget_ctype( bt ) );
57+
strcat( retval, "_agg" );
58+
return ( retval );
59+
}
60+
if( ctype == logical_ ) {
61+
return ( "LOGICALS" );
62+
}
63+
if( ctype == boolean_ ) {
64+
return ( "BOOLEANS" );
65+
}
66+
if( ctype == string_ ) {
67+
return( "StringAggregate" );
68+
}
69+
if( ctype == binary_ ) {
70+
return( "BinaryAggregate" );
71+
}
72+
}
73+
74+
/* the rest is for things that are not aggregates */
75+
ctype = TYPEget_type( t );
76+
77+
/* case TYPE_LOGICAL: */
78+
if( ctype == logical_ ) {
79+
return ( "SDAI_LOGICAL" );
80+
}
81+
82+
/* case TYPE_BOOLEAN: */
83+
if( ctype == boolean_ ) {
84+
return ( "SDAI_BOOLEAN" );
85+
}
86+
87+
/* case TYPE_INTEGER: */
88+
if( ctype == integer_ ) {
89+
return ( "SDAI_Integer" );
90+
}
91+
92+
/* case TYPE_REAL:
93+
* case TYPE_NUMBER: */
94+
if( ( ctype == number_ ) || ( ctype == real_ ) ) {
95+
return ( "SDAI_Real" );
96+
}
97+
98+
/* case TYPE_STRING: */
99+
if( ctype == string_ ) {
100+
return ( "SDAI_String" );
101+
}
102+
103+
/* case TYPE_BINARY: */
104+
if( ctype == binary_ ) {
105+
return ( "SDAI_Binary" );
106+
}
107+
108+
/* case TYPE_ENTITY: */
109+
if( ctype == entity_ ) {
110+
strncpy( retval, TypeName( t ), BUFSIZ - 2 );
111+
strcat( retval, "_ptr" );
112+
return retval;
113+
/* return ("STEPentityH"); */
114+
}
115+
/* case TYPE_ENUM: */
116+
/* case TYPE_SELECT: */
117+
if( ctype == enumeration_ ) {
118+
strncpy( retval, TypeName( t ), BUFSIZ - 2 );
119+
strcat( retval, "_var" );
120+
return retval;
121+
}
122+
if( ctype == select_ ) {
123+
return ( TypeName( t ) );
124+
}
125+
126+
/* default returns undefined */
127+
return ( "SCLundefined" );
128+
}
129+
130+
const char * TypeName( Type t ) {
131+
static char name [BUFSIZ];
132+
strcpy( name, TYPE_PREFIX );
133+
if( TYPEget_name( t ) ) {
134+
strncat( name, FirstToUpper( TYPEget_name( t ) ), BUFSIZ - strlen( TYPE_PREFIX ) - 1 );
135+
} else {
136+
return TYPEget_ctype( t );
137+
}
138+
return name;
139+
}
140+
141+
char ToLower( char c ) {
142+
if( isupper( c ) ) {
143+
return ( tolower( c ) );
144+
} else {
145+
return ( c );
146+
}
147+
148+
}
149+
150+
char ToUpper( char c ) {
151+
if( islower( c ) ) {
152+
return ( toupper( c ) );
153+
} else {
154+
return ( c );
155+
}
156+
}
157+
158+
const char * StrToLower( const char * word ) {
159+
static char newword [MAX_LEN];
160+
int i = 0;
161+
if( !word ) {
162+
return 0;
163+
}
164+
while( word [i] != '\0' ) {
165+
newword [i] = ToLower( word [i] );
166+
++i;
167+
}
168+
newword [i] = '\0';
169+
return ( newword ) ;
170+
171+
}
172+
173+
const char * StrToUpper( const char * word ) {
174+
static char newword [MAX_LEN];
175+
int i = 0;
176+
177+
while( word [i] != '\0' ) {
178+
newword [i] = ToUpper( word [i] );
179+
++i;
180+
}
181+
newword [i] = '\0';
182+
return ( newword );
183+
}
184+
185+
const char * StrToConstant( const char * word ) {
186+
static char newword[MAX_LEN];
187+
int i = 0;
188+
189+
while( word [i] != '\0' ) {
190+
if( word [i] == '/' || word [i] == '.' ) {
191+
newword [i] = '_';
192+
} else {
193+
newword [i] = ToUpper( word [i] );
194+
}
195+
++i;
196+
197+
}
198+
newword [i] = '\0';
199+
return ( newword );
200+
}
201+
202+
const char * FirstToUpper( const char * word ) {
203+
static char newword [MAX_LEN];
204+
205+
strncpy( newword, word, MAX_LEN );
206+
newword[0] = ToUpper( newword[0] );
207+
return ( newword );
208+
}

src/exp2cxx/class_strings.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#ifndef CLASS_STRINGS_H
2+
#define CLASS_STRINGS_H
3+
4+
/** \file class_strings.h
5+
* These functions are all required to generate class names, so they
6+
* are used by the configure-time schema scanner to determine what
7+
* filenames will be used for a given schema. They are grouped here
8+
* to reduce the number of source files the scanner depends upon.
9+
*
10+
* Functions prototyped here are implemented in class_strings.c
11+
*/
12+
13+
#include <express/entity.h>
14+
#include <express/type.h>
15+
16+
#define MAX_LEN 240
17+
#define TYPE_PREFIX "Sdai"
18+
#define ENTITYCLASS_PREFIX TYPE_PREFIX
19+
20+
/** \returns: temporary copy of name suitable for use as a class name
21+
* Side Effects: erases the name created by a previous call to this function
22+
*/
23+
const char * ClassName( const char * oldname );
24+
25+
/** \returns the name of the c++ class representing the entity */
26+
const char * ENTITYget_classname( Entity ent );
27+
28+
/** supplies the type of a data member for the c++ class
29+
* \returns: a string which is the type of the data member in the c++ class
30+
*/
31+
const char * TYPEget_ctype( const Type t );
32+
33+
/** name of type as defined in SDAI C++ binding 4-Nov-1993 */
34+
const char * TypeName( Type t );
35+
36+
/** These functions take a character or a string and return
37+
** a temporary copy of the string with the function applied to it.
38+
**
39+
** Side Effects: character or string returned persists until the
40+
** next invocation of the function
41+
**
42+
** \returns a temporary copy of characters
43+
** @{
44+
*/
45+
char ToLower( char c );
46+
char ToUpper( char c );
47+
const char * StrToLower( const char * word );
48+
const char * StrToUpper( const char * word );
49+
const char * StrToConstant( const char * word );
50+
const char * FirstToUpper( const char * word );
51+
/* @} */
52+
#endif /* CLASS_STRINGS_H */

src/exp2cxx/classes.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7.
2626
#include "exppp.h"
2727
#include "dict.h"
2828

29-
#define MAX_LEN 240
3029
#define DEBUG if (0) printf
3130

3231
/* Values for multiple schema support: */
@@ -44,8 +43,6 @@ N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7.
4443
#define TYPEprefix(t) (TYPEis_entity (t) ? ENT_PREFIX : TD_PREFIX)
4544

4645
#define SCHEMA_FILE_PREFIX "Sdai"
47-
#define TYPE_PREFIX "Sdai"
48-
#define ENTITYCLASS_PREFIX TYPE_PREFIX
4946
#define ENUM_PREFIX ""
5047

5148
#define move(b) (b = (b + strlen(b)))

src/exp2cxx/classes_entity.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ N350 ( August 31, 1993 ) of ISO 10303 TC184/SC4/WG7.
1919
#include <assert.h>
2020
#include <sc_mkdir.h>
2121
#include "classes.h"
22+
#include "class_strings.h"
2223
#include <ordered_attrs.h>
2324

2425
#include <sc_trace_fprintf.h>

0 commit comments

Comments
 (0)