/* Some functions that can be used in state codes */ #include #include #include #include #include #include "miscFunctions4SNCs.h" /* Small wrapper for getting a string out of a SNL MACRO. If the string value is "none", then the string is replaced by an empty string */ char* myMacValueGet( SS_ID ssId, char* name ) { char* tmpString = seq_macValueGet(ssId, name ); if( strcmp(tmpString, "none") == 0 ) { strcpy(tmpString, ""); } return tmpString; } /* Checks if the pvName matches the regular expression using regular expression GNU C-library. */ int pvNameMatched( char* pvName, char* regexpString ) { regex_t regexpObject; int returnStatus; char messageBuffer[512]; /* Compile regular expression */ returnStatus = regcomp(®expObject, regexpString, 0); if (returnStatus) { fprintf(stderr, "Could not compile regex %s\n", regexpString ); /* Free memory allocated to the pattern buffer by regcomp() */ regfree(®expObject); return 0; } /* Execute regular expression */ returnStatus = regexec(®expObject, pvName, 0, NULL, 0); if (!returnStatus) { /* Free memory allocated to the pattern buffer by regcomp() */ regfree(®expObject); return 1; } else if (returnStatus == REG_NOMATCH) { /* Free memory allocated to the pattern buffer by regcomp() */ regfree(®expObject); return 0;; } else { regerror(returnStatus, ®expObject, messageBuffer, sizeof(messageBuffer)); fprintf(stderr, "Regex match failed: %s\n", messageBuffer); /* Free memory allocated to the pattern buffer by regcomp() */ regfree(®expObject); return 0; } }