END_TEST START_TEST (test_expression) { int i; expression *e = get_expression("c1, symbol O+C"); ck_assert_ptr_ne(e,NULL); ck_assert_int_eq(e->type, E_SELECTION); ck_assert_ptr_ne(e->left, NULL); ck_assert_ptr_eq(e->right, NULL); ck_assert_str_eq(e->value, "c1"); ck_assert_int_eq(e->left->type,E_SYMBOL); ck_assert_ptr_ne(e->left->left,NULL); ck_assert_ptr_eq(e->left->right,NULL); ck_assert_int_eq(e->left->left->type,E_PLUS); ck_assert_int_eq(e->left->left->left->type,E_ID); ck_assert_int_eq(e->left->left->right->type,E_ID); ck_assert_str_eq(e->left->left->right->value,"C"); ck_assert_str_eq(e->left->left->left->value,"O"); for (i = E_SELECTION; i <= E_RANGE_OPEN_R; ++i) { ck_assert_ptr_ne(e_str(i), NULL); } ck_assert_ptr_eq(e_str(E_RANGE_OPEN_R+1), NULL); }
static void die_fatal(const char *trouble, const char *fn) { if (errno) { if (fn) die_7(111, FATAL, trouble, " ", fn, ": ", e_str(errno), "\n"); die_5(111, FATAL, trouble, ": ", e_str(errno), "\n"); } if (fn) die_5(111, FATAL, trouble, " ", fn, "\n"); die_3(111, FATAL, trouble, "\n"); }
void die_fatal(const char *trouble,const char *d,const char *fn) { if (!flagverbose) die_0(111); if (d) { if (fn) die_9(111,"curvecpserver: fatal: ",trouble," ",d,"/",fn,": ",e_str(errno),"\n"); die_7(111,"curvecpserver: fatal: ",trouble," ",d,": ",e_str(errno),"\n"); } die_5(111,"curvecpserver: fatal: ",trouble,": ",e_str(errno),"\n"); }
void die_fatal(const char *trouble,const char *d,const char *fn) { /* XXX: clean up? OS can do it much more reliably */ if (!flagverbose) die_0(111); if (d) { if (fn) die_9(111,"curvecpclient: fatal: ",trouble," ",d,"/",fn,": ",e_str(errno),"\n"); die_7(111,"curvecpclient: fatal: ",trouble," ",d,": ",e_str(errno),"\n"); } if (errno) die_5(111,"curvecpclient: fatal: ",trouble,": ",e_str(errno),"\n"); die_3(111,"curvecpclient: fatal: ",trouble,"\n"); }
static int select_list(expression_type parent_type, struct selection *selection, const freesasa_structure *structure, const expression *expr) { int resr, resl; expression *left, *right; if (expr == NULL) return fail_msg("NULL expression"); left = expr->left; right = expr->right; switch(expr->type) { case E_PLUS: if (left == NULL || right == NULL) return fail_msg("NULL expression"); resl = select_list(parent_type, selection, structure, left); resr = select_list(parent_type, selection, structure, right); if (resl == FREESASA_WARN || resr == FREESASA_WARN) return FREESASA_WARN; break; case E_RANGE: if (left == NULL || right == NULL) return fail_msg("NULL expression"); return select_range(E_RANGE, parent_type, selection, structure, left, right); case E_RANGE_OPEN_L: if (left != NULL || right == NULL) return fail_msg("NULL expression"); return select_range(E_RANGE_OPEN_L, parent_type, selection, structure, left, right); case E_RANGE_OPEN_R: if (left == NULL || right != NULL) return fail_msg("NULL expression"); return select_range(E_RANGE_OPEN_R, parent_type, selection, structure, left, right); case E_ID: case E_NUMBER: if (is_valid_id(parent_type, expr) == FREESASA_SUCCESS) select_id(parent_type, selection, structure, expr->value); else return freesasa_warn("select: %s: '%s' invalid %s", e_str(parent_type), expr->value, e_str(expr->type)); break; default: return freesasa_fail("select: parse error (expression: '%s %s')", e_str(parent_type), e_str(expr->type)); } return FREESASA_SUCCESS; }
static int dnszones_dirinit2(struct dnszones *dnszones, const char *cfgdir, const char *vardir, const char *warning) { direntry *d; DIR *dir; struct stat st; const char *fqdn; unsigned char *q = 0; dir = opendir("."); if (!dir) return 0; for (;;) { errno = 0; d = readdir(dir); if (!d) break; if (d->d_name[0] == '.') continue; fqdn = d->d_name; if (str_equal(d->d_name, "@")) fqdn = "."; if (stat(d->d_name, &st) == -1) { warn_6(warning, "unable to stat ", d->d_name, ": ", e_str(errno), "\n"); continue; } if (!S_ISDIR(st.st_mode)) continue; if (!dns_domain_fromdot(&q, (unsigned char *)fqdn, str_len(fqdn))) { warn_6(warning, "unable init zone ", fqdn, ": ", e_str(errno), "\n"); continue; } if (dnszones_exist(dnszones, q)) { warn_4(warning, "unable to init zone ", fqdn, ": exist\n"); continue; } if (!dnszones_add(dnszones, d->d_name, &q, cfgdir, vardir)) { warn_6(warning, "unable init zone ", fqdn, ": ", e_str(errno), "\n"); break; } } if (errno) {closedir(dir); return 0;} closedir(dir); return 1; }
static int select_range(expression_type range_type, expression_type parent_type, struct selection *selection, const freesasa_structure *structure, const expression *left, const expression *right) { int lower, upper, i, j; assert(range_type == E_RANGE || range_type == E_RANGE_OPEN_L || range_type == E_RANGE_OPEN_R); assert(parent_type == E_RESI || parent_type == E_CHAIN); if (parent_type == E_RESI) { /* residues have integer numbering */ if (( left && left->type != E_NUMBER) || (right && right->type != E_NUMBER)) { return freesasa_warn("select: %s: range '%s-%s' invalid, needs to be two numbers, " "will be ignored",e_str(parent_type), left->value, right->value); } } else { /* chains can be numbered by both letters (common) and numbers (uncommon) */ if (left->type != right->type || (left->type == E_ID && (strlen(left->value) > 1 || strlen(right->value) > 1))) return freesasa_warn("select: %s: range '%s-%s' invalid, should be two letters (A-C) or numbers (1-5), " "will be ignored", e_str(parent_type), left->value, right->value); } if (range_type == E_RANGE_OPEN_L) { lower = atoi(freesasa_structure_atom_res_number(structure, 0)); upper = atoi(right->value); } else if (range_type == E_RANGE_OPEN_R) { lower = atoi(left->value); upper = atoi(freesasa_structure_atom_res_number(structure, freesasa_structure_n(structure) - 1)); } else if (left->type == E_NUMBER) { lower = atoi(left->value); upper = atoi(right->value); } else { lower = (int)left->value[0]; upper = (int)right->value[0]; } for (i = 0; i < selection->size; ++i) { if (parent_type == E_RESI) j = atoi(freesasa_structure_atom_res_number(structure,i)); else j = (int)freesasa_structure_atom_chain(structure,i); if (j >= lower && j <= upper) selection->atom[i] = 1; } return FREESASA_SUCCESS; }
int main(int argc, char **argv, char **envp) { if (!argv[0]) die_0(100); argv[0] = "curvecpmessage"; pathexec_run(*argv, argv, envp); die_5(111, "netcurvecpmessage: fatal: unable to run ", *argv, ": ", e_str(errno), "\n"); return 111; }
/* for debugging */ static void print_expr(FILE * output, const expression *e, int level) { int i; fprintf(output, "\n"); for (i = 0; i < level; ++i) fprintf(output, " "); if (e == NULL) { fprintf(output, "()"); } else { fprintf(output, "(%s ",e_str(e->type)); if (e->value) fprintf(output, ": %s ",e->value); print_expr(output, e->left, level+1); print_expr(output, e->right, level+1); fprintf(output, ")"); } fflush(output); }
static void select_id(expression_type parent_type, struct selection *selection, const freesasa_structure *structure, const char *id) { int count = 0, match, i; assert(id); for (i = 0; i < selection->size; ++i) { match = 0; switch(parent_type) { case E_NAME: match = match_name(structure, id, i); break; case E_SYMBOL: match = match_symbol(structure, id, i); break; case E_RESN: match = match_resn(structure, id, i); break; case E_RESI: match = match_resi(structure, id, i); break; case E_CHAIN: match = match_chain(structure, id, i); break; default: assert(0); break; } if (match) selection->atom[i] = 1; count += match; } if (count == 0) freesasa_warn("Found no matches to %s '%s', typo?", e_str(parent_type),id); }
void TestParser::parseLine( QString line) { QString n_str("Node "); QString e_str("Edge "); /** Node recognition */ QRegExp node_rx("CF ?(Enter)? ?(\\w*) Node (\\d+)"); /** Edge recognition */ QRegExp edge_rx("CF EDGE (\\d+) \\[(\\d+)->(\\d+)\\]"); QTextStream stream( stdout); /** Expression recognition */ int pos = 0; if ( edge_rx.indexIn( line) != -1) { QString name = e_str.append( edge_rx.cap(1)); QString pred_name("Node "); pred_name.append( edge_rx.cap( 2)); QString succ_name("Node "); succ_name.append( edge_rx.cap( 3)); /** Back edge */ QRegExp back_rx("Back"); /** Add edge to symtab */ if ( symtab.find( name) == symtab.end() && symtab.find( pred_name) != symtab.end() && symtab.find( succ_name) != symtab.end()) { SymEdge *edge = new SymEdge( name); edge->setPred( pred_name); edge->setSucc( succ_name); symtab[ name] = edge; /** Add edge to graph */ GNode* pred = static_cast< SymNode *>( symtab[ pred_name])->node(); GNode* succ = static_cast< SymNode *>( symtab[ succ_name])->node(); GEdge* e = graph->graph()->newEdge( pred, succ); #ifdef _DEBUG //stream << name << ": " << pred_name << "->" << succ_name << endl; #endif if ( back_rx.indexIn( line) != -1 && !e->isSelf()) { GNode* label = e->insertLabelNode( QPointF( 0,0)); label->item()->setPlainText( "Back"); } } } else if ( node_rx.indexIn( line) != -1 ) { bool good_id = false; int ir_id = node_rx.cap(3).toInt( &good_id); QString text = QString("Node ").append( node_rx.cap(3)); QString name = n_str.append( node_rx.cap(3)); if ( !node_rx.cap( 1).isEmpty()) { text.append("\n").append( node_rx.cap(1)); } if ( !node_rx.cap( 2).isEmpty()) { text.append("\n").append( node_rx.cap(2)); } /** Add node to symtab */ if ( symtab.find( name ) == symtab.end()) { SymNode* node = new SymNode( name); curr_node = static_cast<CFNode *>( graph->graph()->newNode()); curr_node->setDoc( new QTextDocument()); node->setNode( curr_node); node->node()->item()->setPlainText( text); if ( good_id) { node->node()->setIRId( ir_id); } symtab[ name] = node; #ifdef _DEBUG //stream << name << endl; #endif } } else { if ( !isStateNode()) setStateDefault(); } if ( isStateNode()) { node_text.append( line).append( "\n"); } }
void TestParser::parseLineGCC( QString line) { QString n_str("Node "); QString e_str("Edge "); /** Node recognition */ QRegExp node_rx("^;; Start of basic block"); QRegExp preds_rx("^;; Pred edge "); QRegExp succs_rx("^;; Succ edge "); QTextStream stream( stdout); /** Expression recognition */ int pos = 0; if ( preds_rx.indexIn( line) == 0) { int index = preds_rx.matchedLength(); QRegExp num_rx(" (\\d+)"); while ( ( index = num_rx.indexIn( line, index) )!= -1) { index += num_rx.matchedLength(); assert( isNotNullP( curr_node)); int pred_num = num_rx.cap(1).toInt(); QString name = QString("%1->%2") .arg( pred_num) .arg( curr_node->irId()); QString pred_name = QString("Node %1").arg( pred_num); QString succ_name = QString("Node %1").arg( curr_node->irId()); /** Add edge to symtab */ if ( symtab.find( name) == symtab.end() && symtab.find( pred_name) != symtab.end() && symtab.find( succ_name) != symtab.end()) { SymEdge *edge = new SymEdge( name); edge->setPred( pred_name); edge->setSucc( succ_name); symtab[ name] = edge; /** Add edge to graph */ GNode* pred = static_cast< SymNode *>( symtab[ pred_name])->node(); GNode* succ = static_cast< SymNode *>( symtab[ succ_name])->node(); GEdge* e = graph->graph()->newEdge( pred, succ); #ifdef _DEBUG //stream << name << ": " << pred_name << "->" << succ_name << endl; #endif } } } else if ( succs_rx.indexIn( line) == 0) { int index = succs_rx.matchedLength(); QRegExp num_rx(" (\\d+)"); while ( ( index = num_rx.indexIn( line, index) )!= -1) { index += num_rx.matchedLength(); assert( isNotNullP( curr_node)); int pred_num = num_rx.cap(1).toInt(); QString name = QString("%1->%2") .arg( curr_node->irId()) .arg( pred_num); QString pred_name = QString("Node %1").arg( curr_node->irId()); QString succ_name = QString("Node %1").arg( pred_num); /** Add edge to symtab */ if ( symtab.find( name) == symtab.end() && symtab.find( pred_name) != symtab.end() && symtab.find( succ_name) != symtab.end()) { SymEdge *edge = new SymEdge( name); edge->setPred( pred_name); edge->setSucc( succ_name); symtab[ name] = edge; /** Add edge to graph */ GNode* pred = static_cast< SymNode *>( symtab[ pred_name])->node(); GNode* succ = static_cast< SymNode *>( symtab[ succ_name])->node(); GEdge* e = graph->graph()->newEdge( pred, succ); #ifdef _DEBUG //stream << name << ": " << pred_name << "->" << succ_name << endl; #endif } } } else if ( node_rx.indexIn( line) != -1 ) { QRegExp num_rx("-> (\\d+)"); if ( num_rx.indexIn( line) != -1) { bool good_id = false; int ir_id = num_rx.cap(1).toInt( &good_id); QString text = QString("Block ").append( num_rx.cap(1)); QString name = n_str.append( num_rx.cap(1)); /** Add node to symtab */ if ( symtab.find( name ) == symtab.end()) { SymNode* node = new SymNode( name); curr_node = static_cast<CFNode *>( graph->graph()->newNode()); curr_node->setDoc( new QTextDocument()); node->setNode( curr_node); node->node()->item()->setPlainText( text); if ( good_id) { node->node()->setIRId( ir_id); } symtab[ name] = node; #ifdef _DEBUG //stream << name << endl; #endif } } } else { if ( !isStateNode()) setStateDefault(); } if ( isStateNode()) { node_text.append( line).append( "\n"); } }
void die_fatal(const char *trouble,const char *d,const char *fn) { if (fn) die_9(111,"curvecpmakekey: fatal: ",trouble," ",d,"/",fn,": ",e_str(errno),"\n"); die_7(111,"curvecpmakekey: fatal: ",trouble," ",d,": ",e_str(errno),"\n"); }
static int is_valid_id(int parent_type, const expression *expr) { int type, n, warn, i; const char* val; assert(expr->type == E_NUMBER || expr->type == E_ID); type = expr->type; val = expr->value; switch(parent_type) { case E_NAME: if (strlen(val) > PDB_ATOM_NAME_STRL) return freesasa_warn("select: %s: atom name '%s' invalid (string too long), " "will be ignored", e_str(parent_type), val); break; case E_SYMBOL: if (type != E_ID) return freesasa_warn("select: %s: '%s' invalid (should be 1 or 2 letters, 'C', 'N', 'SE', etc), " "will be ignored", e_str(parent_type), val); if (strlen(val) > 2) return freesasa_warn("select: %s: '%s' invalid (element names have 1 or 2 characters), " "will be ignored", e_str(parent_type), val); break; case E_RESN: if (strlen(val) > PDB_ATOM_RES_NAME_STRL) return freesasa_warn("select: %s: '%s' invalid (string too long), " "will be ignored", e_str(parent_type), val); break; case E_RESI: if (type == E_ID) { /* these should have format 1, 2, 345, etc or 12A, 12B, etc. */ n = strlen(val); if (n > PDB_ATOM_RES_NUMBER_STRL) { return freesasa_warn("select: %s: '%s' invalid (string too long), " "will be ignored", e_str(parent_type), val); } else { warn = 0; if (n == 1) ++warn; if (!warn && (toupper(val[n - 1]) < 'A' || toupper(val[n - 1]) > 'Z')) { ++warn; } for (i = 0; !warn && i < n - 1; ++i) { if (val[i] < '0' || val[i] > '9') { ++warn; } } if (warn) { return freesasa_warn("select: %s: '%s' invalid, should either be " "number (1, 2, 3) or number with insertion code (1A, 1B, ...), " "will be ignored", e_str(parent_type), val); } } } else if (type != E_NUMBER) { return freesasa_warn("select: %s: '%s' invalid, will be ignored", e_str(parent_type), val); } break; case E_CHAIN: if (strlen(val) > 1) return freesasa_warn("select: %s: '%s' invalid (string too long), " "will be ignored", e_str(parent_type), val); break; default: assert(0); break; } return FREESASA_SUCCESS; }
void log_9_( int level ,int ignoreerrno ,const char *f ,unsigned long long l ,const char *s0 ,const char *s1 ,const char *s2 ,const char *s3 ,const char *s4 ,const char *s5 ,const char *s6 ,const char *s7 ,const char *s8 ) { const char *s[9]; long long i; const char *m; if (level > loglevel) return; s[0] = s0; s[1] = s1; s[2] = s2; s[3] = s3; s[4] = s4; s[5] = s5; s[6] = s6; s[7] = s7; s[8] = s8; switch (level) { case -1: m = "BUG"; break; case 0: m = "usage"; break; case 1: m = "fatal"; break; case 2: if (!ignoreerrno) m = "warning"; else m = "info"; break; case 3: m = "debug"; break; default: m = "unknown"; break; } /* name: session: level: message (error){file:line} */ /* 'name:' */ do { if (level == 0) break; /* don't print in usage level */ if (logflagsyslog) break; /* don't print in syslog mode */ outs(logtext); outs(": "); } while (0); /* 'session:' */ do { if (level == 0) break; /* don't print in usage level */ if (!logflagfnln) break; /* don't print when disabled */ outs(logstring); outs(": "); } while (0); /* 'level:' */ do { if (level == 0) break; /* don't print in usage level */ outs(m); outs(": "); } while (0); /* 'message' */ for (i = 0; i < 9 && s[i]; ++i) outs(s[i]); outs(" "); /* '(error)' */ do { if (!errno) break; /* don't print when errno = 0 */ if (ignoreerrno) break; /* don't print when disabled */ outs("("); outs(e_str(errno)); outs(")"); } while (0); /* {file:line} */ do { if (level == 0) break; /* don't print in usage level */ if (!f) break; /* don't print when no f */ if (!l) break; /* don't print when no l */ if (!logflagfnln && level != -1) break; /* don't print when disabled */ outs("{"); outs(f); outs(":"); outnum(l); outs("}"); } while (0); outs("\n"); flush(); return; }