00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifdef HAVE_CONFIG_H
00028 #include <config.h>
00029 #endif
00030
00031
00032
00033
00034
00035 #include <cpl.h>
00036
00037 #include <regex.h>
00038 #include <string.h>
00039 #include <strings.h>
00040 #include <sys/types.h>
00041 #include <fnmatch.h>
00042 #include <string.h>
00043 #include <assert.h>
00044
00045 #include "xsh_msg.h"
00046 #include "xsh_qc_handling.h"
00047 #include "xsh_qc_definition.h"
00048
00049
00050
00051
00052
00053 #define USE_REGEXP
00054
00059
00060
00063
00064
00065
00066
00067
00068
00069 qc_description * xsh_get_qc_desc_by_kw( const char *kw )
00070 {
00071 qc_description * current ;
00072
00073 for( current = (qc_description *)qc_table ; current->kw_name != NULL ;
00074 current++ )
00075 if ( strcmp( current->kw_name, kw ) == 0 ) return current ;
00076 return NULL ;
00077 }
00078
00079
00080 qc_description * xsh_get_qc_desc_by_pro_catg( const char * pro_catg )
00081 {
00082 qc_description * current ;
00083 #if defined(USE_REGEXP)
00084 regex_t reg ;
00085 int err ;
00086
00087 for( current = (qc_description *)qc_table ; current->kw_name != NULL ;
00088 current++ ) {
00089 if ( current->pro_catg == NULL ) continue ;
00090 err = regcomp( ®, current->pro_catg, REG_EXTENDED | REG_ICASE ) ;
00091 if ( err != 0 ) continue ;
00092 err = regexec( ®, pro_catg, 0, 0, 0 ) ;
00093 regfree( ® ) ;
00094 if ( err == 0 ) return current ;
00095 }
00096 #else
00097 for( current = (qc_description *)qc_table ; current->kw_name != NULL ;
00098 current++ ) {
00099 if ( current->pro_catg == NULL ) return current ;
00100 if ( fnmatch( current->pro_catg, pro_catg, 0 ) == 0 )
00101 return current ;
00102 }
00103 #endif
00104 return NULL ;
00105 }
00106
00107 int xsh_qc_in_recipe( qc_description * pqc, xsh_instrument * instrument )
00108 {
00109 if ( ( pqc->kw_recipes != NULL &&
00110 strstr( pqc->kw_recipes, instrument->recipe_id ) != NULL ) ||
00111 ( pqc->kw_recipes_tbw != NULL &&
00112 strstr( pqc->kw_recipes_tbw, instrument->recipe_id ) != NULL ) ) return 0 ;
00113
00114 return -1 ;
00115 }
00116
00117 qc_description * xsh_get_qc_desc_by_recipe( const char *recipe,
00118 qc_description *prev )
00119 {
00120 qc_description * current ;
00121
00122 if ( prev == NULL ) {
00123 current = (qc_description *)qc_table ;
00124 }
00125 else current = prev+1 ;
00126
00127 for( ; current->kw_name != NULL ; current++ ) {
00128 if ( ((current->kw_recipes != NULL &&
00129 strstr( current->kw_recipes, recipe ) != NULL) ||
00130 (current->kw_recipes_tbw != NULL &&
00131 strstr( current->kw_recipes_tbw, recipe ) != NULL)) &&
00132 current->kw_type != CPL_TYPE_INVALID )
00133 return current ;
00134 }
00135 return NULL ;
00136 }
00137
00138
00139 qc_description * xsh_get_qc_desc_by_function( char *function,
00140 qc_description *prev )
00141 {
00142 qc_description * current ;
00143
00144 if ( prev == NULL ) {
00145 current = (qc_description *)qc_table ;
00146 }
00147 else current = prev+1 ;
00148
00149 for( ; current->kw_name != NULL ; current++ ) {
00150 if ( (current->kw_function != NULL &&
00151 strstr( current->kw_function, function ) != NULL) )
00152 return current ;
00153 }
00154 return NULL ;
00155 }
00156
00168 int xsh_is_qc_for_arm( const char * arm, qc_description * pqc )
00169 {
00170 if ( pqc->arms == NULL ||
00171 strstr( pqc->arms, arm ) != NULL ) return 1 ;
00172 return 0 ;
00173 }
00174
00185 int xsh_is_qc_for_pro_catg( const char * pro_catg, qc_description * pqc )
00186 {
00187 #if defined(USE_REGEXP)
00188 regex_t reg ;
00189 int err ;
00190
00191 if ( pqc == NULL || pqc->pro_catg == NULL ) return 1 ;
00192
00193 err = regcomp( ®, pqc->pro_catg, REG_EXTENDED | REG_ICASE ) ;
00194 if ( err != 0 ) return 0 ;
00195 err = regexec( ®, pro_catg, 0, 0, 0 ) ;
00196 regfree( ® ) ;
00197 if ( err == 0 ) return 1 ;
00198
00199 #else
00200 if( pqc->pro_catg == NULL || fnmatch( pqc->pro_catg, pro_catg, 0 ) == 0 ) {
00201 if ( pqc->pro_catg == NULL ) {
00202 xsh_msg_dbg_high( "++++++++ QC '%s' has a NULL PRO.CATG",
00203 pqc->kw_name ) ;
00204 }
00205 else {
00206 xsh_msg_dbg_high( "++++++++ QC '%s' found for PRO.CATG '%s'",
00207 pqc->kw_name, pqc->pro_catg ) ;
00208 }
00209 return 1 ;
00210 }
00211 #endif
00212 return 0 ;
00213 }
00214