43 #if defined __cplusplus
48 static tpi_channelID *
_tpi_channelID_parse2( statusMessageReporting *smr,
char const *str,
char const *origStr,
int isDecayChannel,
char **EOP );
49 static tpi_spectralID *
_tpi_spectralID_parse2( statusMessageReporting *smr,
char const *str,
char const *origStr,
char **EOP );
58 if( ( channelID = (tpi_channelID*) xData_malloc2( smr,
sizeof( tpi_channelID ), 0,
"channelID" ) ) == NULL )
return( NULL );
68 memset( channelID, 0,
sizeof( tpi_channelID ) );
76 if( channelID != NULL ) {
87 tpi_spectralID *spectralID, *next;
89 for( spectralID = channelID->spectralIDs; spectralID != NULL; spectralID = next ) {
90 next = spectralID->next;
106 static tpi_channelID *
_tpi_channelID_parse2( statusMessageReporting *smr,
char const *str,
char const *origStr,
int isDecayChannel,
char **EOP ) {
109 tpi_spectralID *spectralID, *priorSpectral;
113 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Empty channel string to parse for '%s'", origStr );
117 priorSpectral= (tpi_spectralID *) &(channelID->spectralIDs);
121 priorSpectral->next = spectralID;
122 priorSpectral = spectralID;
124 if( **EOP == 0 )
break;
125 if( isDecayChannel && ( **EOP ==
')' ) )
break;
127 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Missing '+' (or maybe ')') in channelID at '%s' of '%s'", *EOP, origStr );
148 char *sans[] = { (
char*)
"revision", NULL };
157 tpi_spectralID *spectralID;
159 for( spectralID = channelID->spectralIDs; spectralID != NULL; spectralID = spectralID->next ) {
161 if( spectralID->next != NULL ) {
162 if( (
gString_addTo( smr, gStr,
" + " ) ) != 0 )
return( 1 );
172 tpi_spectralID *spectralID;
175 if( ( spectralID = (tpi_spectralID*) xData_malloc2( smr,
sizeof( tpi_spectralID ), 1,
"spectralID" ) ) == NULL )
return( NULL );
177 return( spectralID );
185 memset( spectralID, 0,
sizeof( tpi_spectralID ) );
193 if( spectralID != NULL ) {
204 tpi_spectralIDQualifier *qualifier, *next;
206 if( spectralID->name != NULL )
free( spectralID->name );
207 for( qualifier = spectralID->qualifiers; qualifier != NULL; qualifier = next ) {
208 next = qualifier->next;
211 if( spectralID->decayChannel != NULL )
tpi_channelID_free( smr, spectralID->decayChannel );
225 static tpi_spectralID *
_tpi_spectralID_parse2( statusMessageReporting *smr,
char const *str,
char const *origStr,
char **EOP ) {
227 int breakup = 0, i1, i2,
m;
232 tpi_spectralID *spectralID;
233 tpi_spectralIDQualifier *qualifier, *priorQualifier = NULL;
237 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Empty spectralID string to parse for '%s'", origStr );
245 if( !isalpha( **EOP ) ) {
246 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Invalid spectralID name '%s' in '%s'", *EOP, origStr );
249 for( s = *EOP, i1 = 0; ( isalnum( **EOP ) ) || ( **EOP ==
'_' ); (*EOP)++ ) i1++;
255 priorQualifier = (tpi_spectralIDQualifier *) &(spectralID->qualifiers);
257 while( **EOP == bOrC ) {
261 if( !isalpha( **EOP ) ) {
262 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Invalid qualifier name '%s' in '%s'", *EOP, origStr );
266 for( s = *EOP, i1 = 0; ( isalnum( **EOP ) ) || ( **EOP ==
'_' ); (*EOP)++ ) i1++;
270 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Missing ':' in qualifier defintion at '%s' in '%s'", *EOP, origStr );
277 if( ( **EOP !=
'"' ) && ( **EOP !=
'\'' ) ) {
278 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Missing start quote in qualifier defintion at '%s' in '%s'", *EOP, origStr );
284 for( q = *EOP, i2 = 0; ( **EOP != c ) && ( **EOP != 0 ); (*EOP)++ ) i2++;
286 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Missing end quote in qualifier defintion at '%s' in '%s'", *EOP, origStr );
294 if( ( qualifier = (tpi_spectralIDQualifier*) xData_malloc2( smr,
sizeof( tpi_spectralIDQualifier ) + i1 + i2 + 2, 1,
"qualifier" ) ) == NULL )
297 qualifier->next = NULL;
298 qualifier->name = (
char *) &(qualifier[1]);
299 qualifier->value = &(qualifier->name[i1+1]);
300 strncpy( qualifier->name, s, i1 );
301 qualifier->name[i1] = 0;
302 strncpy( qualifier->value, q, i2 );
303 qualifier->value[i2] = 0;
305 if( strcmp( qualifier->name,
"revision" ) == 0 ) {
306 spectralID->revision = qualifier->value; }
307 else if( strcmp( qualifier->name,
"multiplicity" ) == 0 ) {
308 spectralID->multiplicityStr = qualifier->value; }
309 else if( strcmp( qualifier->name,
"level" ) == 0 ) {
310 spectralID->levelStr = qualifier->value;
312 priorQualifier->next = qualifier;
313 priorQualifier = qualifier;
316 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Missing ']' for qualifier at '%s' in '%s'", *EOP, origStr );
321 if( spectralID->multiplicityStr != NULL ) {
322 m = strtol( spectralID->multiplicityStr, &e, 10 );
323 if( ( *e == 0 ) && ( e != spectralID->multiplicityStr ) ) spectralID->multiplicity =
m;
325 if( spectralID->levelStr != NULL ) {
326 d = strtod( spectralID->levelStr, &e );
327 if( ( *e == 0 ) && ( e != spectralID->levelStr ) ) spectralID->level = d;
332 if( ( **EOP !=
'-' ) || ( (*EOP)[1] !=
'>' ) ) {
333 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Missing '->' for breakup at '%s' in '%s'", *EOP, origStr );
342 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Missing ')' for breakup at '%s' in '%s'", *EOP, origStr );
348 return( spectralID );
363 char *sans[] = { (
char*)
"revision", NULL };
373 tpi_spectralIDQualifier *qualifier;
375 char **san, *sSan[] = { NULL };
377 if( sans == NULL ) sans = sSan;
378 if( spectralID->decayChannel != NULL )
if(
gString_addTo( smr, gStr,
"(" ) != 0 )
return( 1 );
379 if( (
gString_addTo( smr, gStr, spectralID->name ) ) != 0 )
return( 1 );
380 if( spectralID->qualifiers != NULL ) {
381 for( qualifier = spectralID->qualifiers, i = 0; qualifier != NULL; qualifier = qualifier->next ) i++;
382 for( qualifier = spectralID->qualifiers; qualifier != NULL; qualifier = qualifier->next ) {
383 for( san = (
char **) sans; *san != NULL; san++ ) {
384 if( strcmp( *san, qualifier->name ) == 0 ) {
392 for( qualifier = spectralID->qualifiers; qualifier != NULL; qualifier = qualifier->next ) {
393 for( san = (
char **) sans; *san != NULL; san++ )
if( strcmp( *san, qualifier->name ) == 0 )
break;
394 if( *san != NULL )
continue;
395 if(
gString_addTo( smr, gStr, qualifier->name ) != 0 )
return( 1 );
397 if(
gString_addTo( smr, gStr, qualifier->value ) != 0 )
return( 1 );
408 if( spectralID->decayChannel != NULL ) {
409 if( (
gString_addTo( smr, gStr,
" -> " ) ) != 0 )
return( 1 );
423 for( s = str; ( *s != 0 ) && isspace( *s ); s++ ) ;
434 if( ( s = (
char*) xData_malloc2( smr, n + 1, 0,
"s" ) ) == NULL )
return( NULL );
435 strncpy( s, str, n );
440 #if defined __cplusplus
tpi_channelID * tpi_channelID_parse(statusMessageReporting *smr, char const *str, char **EOP)
static tpi_channelID * _tpi_channelID_parse2(statusMessageReporting *smr, char const *str, char const *origStr, int isDecayChannel, char **EOP)
int smr_setMessageError(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
int tpi_spectralID_toStringSanRevision(statusMessageReporting *smr, tpi_spectralID *spectralID, gString *gStr)
int gString_addTo(statusMessageReporting *smr, gString *gStr, char const *str)
static tpi_spectralID * _tpi_spectralID_parse2(statusMessageReporting *smr, char const *str, char const *origStr, char **EOP)
int tpi_channelID_release(statusMessageReporting *smr, tpi_channelID *channelID)
tpi_spectralID * tpi_spectralID_parse(statusMessageReporting *smr, char const *str, char **EOP)
int tpi_spectralID_release(statusMessageReporting *smr, tpi_spectralID *spectralID)
struct channelID_s channelID
int tpi_spectralID_initialize(statusMessageReporting *, tpi_spectralID *spectralID)
int tpi_channelID_toStringSanRevision(statusMessageReporting *smr, tpi_channelID *channelID, gString *gStr)
tpi_channelID * tpi_channelID_allocate(statusMessageReporting *smr)
char * tpi_misc_allocateAndCopyNCharacters(statusMessageReporting *smr, char const *str, int n)
void * tpi_spectralID_free(statusMessageReporting *smr, tpi_spectralID *spectralID)
int tpi_spectralID_toStringSans(statusMessageReporting *smr, tpi_spectralID *spectralID, gString *gStr, char *sans[])
tpi_spectralID * tpi_spectralID_allocate(statusMessageReporting *smr)
void * xData_free(statusMessageReporting *, void *p)
void * tpi_channelID_free(statusMessageReporting *smr, tpi_channelID *channelID)
int tpi_spectralID_toString(statusMessageReporting *smr, tpi_spectralID *spectralID, gString *gStr)
int tpi_channelID_toString(statusMessageReporting *smr, tpi_channelID *channelID, gString *gStr)
int tpi_channelID_initialize(statusMessageReporting *, tpi_channelID *channelID)
int tpi_channelID_toStringSans(statusMessageReporting *smr, tpi_channelID *channelID, gString *gStr, char *sans[])
char const * tpi_misc_firstNonWhiteSpace(statusMessageReporting *, char const *str)