-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathclass_strings.c
More file actions
237 lines (208 loc) · 6.08 KB
/
class_strings.c
File metadata and controls
237 lines (208 loc) · 6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include <string.h>
#include <stdlib.h>
#include "class_strings.h"
#include "express/type.h"
const char * ClassName( const char * oldname ) {
int i = 0, j = 0;
static char newname [BUFSIZ+1];
if( !oldname ) {
return ( "" );
}
strcpy( newname, ENTITYCLASS_PREFIX ) ;
j = strlen( ENTITYCLASS_PREFIX ) ;
newname [j] = ToUpper( oldname [i] );
++i;
++j;
while( oldname [i] != '\0' ) {
newname [j] = ToLower( oldname [i] );
/* if (oldname [i] == '_') */
/* character is '_' */
/* newname [++j] = ToUpper (oldname [++i]);*/
++i;
++j;
}
newname [j] = '\0';
return ( newname );
}
const char * ENTITYget_classname( Entity ent ) {
const char * oldname = ENTITYget_name( ent );
return ( ClassName( oldname ) );
}
/** like TYPEget_ctype, but caller must alloc a buffer of at least buf_siz
* in many circumstances, this func will return a short string rather than using that buffer
* buf_siz is ignored in those cases since it is meaningless
*/
const char * TYPE_get_ctype( const Type t, char * retval, size_t buf_siz ) {
const char * ptr = "_ptr", * var = "_var", * agg = "_agg";
const char * overflowMsg = "buffer overflow detected at %s:%d!";
Class_Of_Type ctype;
Type bt;
if( TYPEinherits_from( t, aggregate_ ) ) {
bt = TYPEget_body( t )->base;
if( TYPEinherits_from( bt, aggregate_ ) ) {
return( "GenericAggregate" );
}
ctype = TYPEget_type( bt );
if( ctype == integer_ ) {
return ( "IntAggregate" );
}
if( ( ctype == number_ ) || ( ctype == real_ ) ) {
return ( "RealAggregate" );
}
if( ctype == entity_ ) {
return( "EntityAggregate" );
}
if( ( ctype == enumeration_ ) || ( ctype == select_ ) ) {
const char * tmp = TYPE_get_ctype( bt, retval, buf_siz - strlen( retval ) - 1 );
if( tmp != retval ) {
strncpy( retval, tmp, buf_siz - strlen( retval ) - 1 );
}
if( strlen( retval ) + strlen( agg ) < buf_siz ) {
strcat( retval, agg );
} else {
fprintf( stderr, overflowMsg, __FILE__, __LINE__ );
abort();
}
return ( retval );
}
if( ctype == logical_ ) {
return ( "LOGICALS" );
}
if( ctype == boolean_ ) {
return ( "BOOLEANS" );
}
if( ctype == string_ ) {
return( "StringAggregate" );
}
if( ctype == binary_ ) {
return( "BinaryAggregate" );
}
}
/* the rest is for things that are not aggregates */
ctype = TYPEget_type( t );
/* case TYPE_LOGICAL: */
if( ctype == logical_ ) {
return ( "SDAI_LOGICAL" );
}
/* case TYPE_BOOLEAN: */
if( ctype == boolean_ ) {
return ( "SDAI_BOOLEAN" );
}
/* case TYPE_INTEGER: */
if( ctype == integer_ ) {
return ( "SDAI_Integer" );
}
/* case TYPE_REAL:
* case TYPE_NUMBER: */
if( ( ctype == number_ ) || ( ctype == real_ ) ) {
return ( "SDAI_Real" );
}
/* case TYPE_STRING: */
if( ctype == string_ ) {
return ( "SDAI_String" );
}
/* case TYPE_BINARY: */
if( ctype == binary_ ) {
return ( "SDAI_Binary" );
}
/* case TYPE_ENTITY: */
if( ctype == entity_ ) {
strncpy( retval, TypeName( t ), buf_siz - strlen( retval ) - 1 );
if( strlen( retval ) + strlen( ptr ) < buf_siz ) {
strcat( retval, ptr );
} else {
fprintf( stderr, overflowMsg, __FILE__, __LINE__ );
abort();
}
return retval;
/* return ("STEPentityH"); */
}
/* case TYPE_ENUM: */
/* case TYPE_SELECT: */
if( ctype == enumeration_ ) {
strncpy( retval, TypeName( t ), buf_siz - strlen( retval ) - 1 );
if( strlen( retval ) + strlen( var ) < buf_siz ) {
strcat( retval, var );
} else {
fprintf( stderr, overflowMsg, __FILE__, __LINE__ );
abort();
}
return retval;
}
if( ctype == select_ ) {
return ( TypeName( t ) );
}
/* default returns undefined */
return ( "SCLundefined" );
}
const char * TYPEget_ctype( const Type t ) {
static char retval [BUFSIZ+1] = {0};
return TYPE_get_ctype( t, retval, BUFSIZ );
}
const char * TypeName( Type t ) {
static char name [BUFSIZ+1];
strcpy( name, TYPE_PREFIX );
if( TYPEget_name( t ) ) {
strncat( name, FirstToUpper( TYPEget_name( t ) ), BUFSIZ - strlen( TYPE_PREFIX ) - 1 );
} else {
return TYPEget_ctype( t );
}
return name;
}
char ToLower( char c ) {
if( isupper( c ) ) {
return ( tolower( c ) );
} else {
return ( c );
}
}
char ToUpper( char c ) {
if( islower( c ) ) {
return ( toupper( c ) );
} else {
return ( c );
}
}
const char * StrToLower( const char * word ) {
static char newword [MAX_LEN+1];
int i = 0;
if( !word ) {
return 0;
}
while( word [i] != '\0' ) {
newword [i] = ToLower( word [i] );
++i;
}
newword [i] = '\0';
return ( newword ) ;
}
const char * StrToUpper( const char * word ) {
static char newword [MAX_LEN+1];
int i = 0;
while( word [i] != '\0' ) {
newword [i] = ToUpper( word [i] );
++i;
}
newword [i] = '\0';
return ( newword );
}
const char * StrToConstant( const char * word ) {
static char newword[MAX_LEN+1];
int i = 0;
while( word [i] != '\0' ) {
if( word [i] == '/' || word [i] == '.' ) {
newword [i] = '_';
} else {
newword [i] = ToUpper( word [i] );
}
++i;
}
newword [i] = '\0';
return ( newword );
}
const char * FirstToUpper( const char * word ) {
static char newword [MAX_LEN+1];
strncpy( newword, word, MAX_LEN );
newword[0] = ToUpper( newword[0] );
return ( newword );
}