|
| 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 | +} |
0 commit comments