decision_proceduret::resultt dplib_dect::read_dplib_result() { std::ifstream in(temp_result_filename.c_str()); std::string line; while(str_getline(in, line)) { if(has_prefix(line, "Invalid.")) { dplib_prop.reset_assignment(); while(str_getline(in, line)) { if(has_prefix(line, "ASSERT ")) read_assert(in, line); } return D_SATISFIABLE; } else if(has_prefix(line, "Valid.")) return D_UNSATISFIABLE; } error("Unexpected result from CVC-Lite"); return D_ERROR; }
decision_proceduret::resultt smt1_dect::read_result_boolector(std::istream &in) { std::string line; str_getline(in, line); if(line=="sat") { smt1_prop.reset_assignment(); typedef hash_map_cont<std::string, std::string, string_hash> valuest; valuest values; while(str_getline(in, line)) { std::size_t pos=line.find(' '); if(pos!=std::string::npos) values[std::string(line, 0, pos)]= std::string(line, pos+1, std::string::npos); } // Theory variables for(identifier_mapt::iterator it=identifier_map.begin(); it!=identifier_map.end(); it++) { it->second.value.make_nil(); std::string conv_id=convert_identifier(it->first); std::string value=values[conv_id]; if(value=="") continue; set_value(it->second, value); } // Booleans for(unsigned v=0; v<smt1_prop.no_variables(); v++) { std::string value=values["B"+i2string(v)]; if(value=="") continue; smt1_prop.set_assignment(literalt(v, false), value=="1"); } return D_SATISFIABLE; } else if(line=="unsat") return D_UNSATISFIABLE; else error("Unexpected result from SMT-Solver: "+line); return D_ERROR; }
char * peer_author_getsimilar(xmlDocPtr doc, char *full) { int i; char *ans=NULL; double namedist; char *fullname = str_trim(full); xmlNodeSetPtr nodeset; xmlXPathObjectPtr result; xmlNodePtr node; xmlChar *name; xmlChar *peerid; printf("Checking author name <%s>...\n", fullname); result = peer_getnodeset(doc, (const xmlChar*)"/db/authors/author"); if (result) { nodeset = result->nodesetval; for (i=0; i < nodeset->nodeNr; i++) { node = nodeset->nodeTab[i]; name = peer_getchildinfo(doc, node, "fullname"); peerid = peer_getchildinfo(doc, node, "peerid"); namedist = 100.0*str_similarity(fullname, (char*)name, false); //printf("Get similarity of %.1f with <%s>\n", namedist, name); if (namedist>50) { peer_author_printinfo(doc, (char*)peerid); printf("Is <%s> this author (similarity %.1lf)? (y/n) ", fullname, namedist); str_getline(&ans, stdin); if (ans[0]=='y' || ans[0]=='Y') { printf("Match found!\n"); xmlFree(name); free(ans); free(fullname); xmlXPathFreeObject(result); return (char*)peerid; } } xmlFree(name); xmlFree(peerid); } xmlXPathFreeObject(result); } printf("No similar names found :(\n"); free(ans); free(fullname); return NULL; }
decision_proceduret::resultt smt1_dect::read_result_z3(std::istream &in) { std::string line; decision_proceduret::resultt res = D_ERROR; smt1_prop.reset_assignment(); typedef hash_map_cont<std::string, std::string, string_hash> valuest; valuest values; while(str_getline(in, line)) { if(line=="sat") res = D_SATISFIABLE; else if(line=="unsat") res = D_UNSATISFIABLE; else { std::size_t pos=line.find(" -> "); if(pos!=std::string::npos) values[std::string(line, 0, pos)]= std::string(line, pos+4, std::string::npos); } } for(identifier_mapt::iterator it=identifier_map.begin(); it!=identifier_map.end(); it++) { it->second.value.make_nil(); std::string conv_id=convert_identifier(it->first); std::string value=values[conv_id]; if(value=="") continue; // std::cout << it->first << " := " << value << std::endl; exprt e; if(string_to_expr_z3(it->second.type, value, e)) { // std::cout << "E: " << e << std::endl; it->second.value=e; } else set_value(it->second, value); } // Booleans for(unsigned v=0; v<smt1_prop.no_variables(); v++) { std::string value=values["B"+i2string(v)]; if(value=="") continue; smt1_prop.set_assignment(literalt(v, false), value=="true"); } return res; }
void vsf_banner_write(struct vsf_session* p_sess, struct mystr* p_str, int ftpcode) { struct mystr msg_line_str = INIT_MYSTR; unsigned int str_pos = 0; while (str_getline(p_str, &msg_line_str, &str_pos)) { vsf_cmdio_write_str_hyphen(p_sess, ftpcode, &msg_line_str); } str_free(&msg_line_str); }
void dplib_dect::read_assert(std::istream &in, std::string &line) { // strip ASSERT line=std::string(line, strlen("ASSERT "), std::string::npos); if(line=="") return; // bit-vector if(line[0]=='(') { // get identifier std::string::size_type pos= line.find(' '); std::string identifier=std::string(line, 1, pos-1); // get value if(!str_getline(in, line)) return; // skip spaces pos=0; while(pos<line.size() && line[pos]==' ') pos++; // get final ")" std::string::size_type pos2=line.rfind(')'); if(pos2==std::string::npos) return; std::string value=std::string(line, pos, pos2-pos); std::cout << ">" << identifier << "< = >" << value << "<"; std::cout << std::endl; } else { // boolean tvt value=tvt(true); if(has_prefix(line, "NOT ")) { line=std::string(line, strlen("NOT "), std::string::npos); value=tvt(false); } if(line=="") return; if(line[0]=='l') { unsigned number=atoi(line.c_str()+1); assert(number<dplib_prop.no_variables()); dplib_prop.assignment[number]=value; } } }
void vsf_parseconf_load_file(const char* p_filename) { struct mystr config_file_str = INIT_MYSTR; struct mystr config_setting_str = INIT_MYSTR; struct mystr config_value_str = INIT_MYSTR; unsigned int str_pos = 0; int retval; if (!p_filename) { p_filename = s_p_saved_filename; } else { if (s_p_saved_filename) { vsf_sysutil_free((char*)s_p_saved_filename); } s_p_saved_filename = vsf_sysutil_strdup(p_filename); } if (!p_filename) { bug("null filename in vsf_parseconf_load_file"); } if (!s_strings_copied) { s_strings_copied = 1; /* A minor hack to make sure all strings are malloc()'ed so we can free * them at some later date. Specifically handles strings embedded in the * binary. */ copy_string_settings(); } retval = str_fileread(&config_file_str, p_filename, VSFTP_CONF_FILE_MAX); if (vsf_sysutil_retval_is_error(retval)) { die("cannot open config file"); } while (str_getline(&config_file_str, &config_setting_str, &str_pos)) { if (str_isempty(&config_setting_str) || str_get_char_at(&config_setting_str, 0) == '#') { continue; } /* Split into name=value pair */ str_split_char(&config_setting_str, &config_value_str, '='); handle_config_setting(&config_setting_str, &config_value_str); } str_free(&config_file_str); str_free(&config_setting_str); str_free(&config_value_str); }
decision_proceduret::resultt smt2_dect::read_result_yices(std::istream &in) { std::string line; while(str_getline(in, line)) { } error("Unexpected result from SMT-Solver"); return D_ERROR; }
int str_contains_line(const struct mystr* p_str, const struct mystr* p_line_str) { static struct mystr s_curr_line_str; unsigned int pos = 0; while (str_getline(p_str, &s_curr_line_str, &pos)) { if (str_equal(&s_curr_line_str, p_line_str)) { return 1; } } return 0; }
bool modelchecker_smvt::read_result_cadence_smv( std::istream &out_ce, abstract_modelt &abstract_model, const threadst &threads, abstract_counterexamplet &counterexample) { std::list<std::string> file; while(true) { std::string line; if(!str_getline(out_ce, line)) break; file.push_back(line); } if(file.empty()) { throw "SMV error - Cadence SMV produced no output"; } for(std::list<std::string>::const_iterator it=file.begin(); it!=file.end(); it++) { if(std::string(*it, 0, 18)=="/* truth value */ ") { if(std::string(*it, it->size()-1)=="1") { // OK } else if(std::string(*it, it->size()-1)=="0") { // produce counterexample status("Cadence SMV produced counterexample"); read_counterexample_cadence_smv( file, it, abstract_model, threads, counterexample); print(9, "Cadence SMV counterexample sucessfully read"); return false; } else throw "unexpected reply from Cadence SMV: \""+*it+"\""; } } return true; }
decision_proceduret::resultt smt1_dect::read_result_yices(std::istream &in) { std::string line; while(str_getline(in, line)) { if (line=="sat") { // fixme: read values return D_SATISFIABLE; } else if (line=="unsat") return D_UNSATISFIABLE; } error("Unexpected result from SMT-Solver"); return D_ERROR; }
int peer_author_updatename(xmlDocPtr doc, const char *peerid, const char *name, const char *surname) { /* Check input peerid */ if (peerid==NULL) { fprintf(stderr, "ERROR! Must supply a PeerID!\n"); return -1; } /* Check input affiliation */ char *name_new = str_trim(name); char *surname_new = str_trim(surname); if (name_new==NULL || surname_new==NULL) { printf("Void name or surname, do nothing.\n"); return 0; } char *fullname_new = str_concat(name_new, " ", surname_new, NULL); char *fullname_old = NULL; char *ans = NULL; xmlXPathObjectPtr result; xmlNodePtr cur, child; xmlChar *tmp; /* Get the node */ char *xpath = str_concat("/db/authors[1]/author[peerid='", peerid, "']", NULL); result = peer_getnodeset(doc, (xmlChar*)xpath); if (result->nodesetval->nodeNr != 1) { fprintf(stderr, "ERROR! Found %d authors with PeerID %s\n", result->nodesetval->nodeNr, peerid); } else { cur = result->nodesetval->nodeTab[0]; fullname_old = (char*)peer_getchildinfo(doc, cur, "fullname"); if (strlen(fullname_new)>strlen(fullname_old) && strcmp(fullname_new, fullname_old)!=0) { printf("Update old name <%s> with new <%s>? (y/n) ", fullname_old, fullname_new); str_getline(&ans, stdin); if (ans[0]=='y' || ans[0]=='Y') { /* Update name! */ child = cur->xmlChildrenNode; while (child!=NULL) { if ((!xmlStrcmp(child->name, (const xmlChar *)"name"))) { tmp = xmlEncodeEntitiesReentrant(doc, (xmlChar*)name_new); xmlNodeSetContent(child, tmp); free(tmp); tmp=NULL; } else if ((!xmlStrcmp(child->name, (const xmlChar *)"surname"))) { tmp = xmlEncodeEntitiesReentrant(doc, (xmlChar*)surname_new); xmlNodeSetContent(child, tmp); free(tmp); tmp=NULL; } else if ((!xmlStrcmp(child->name, (const xmlChar *)"fullname"))) { tmp = xmlEncodeEntitiesReentrant(doc, (xmlChar*)fullname_new); xmlNodeSetContent(child, tmp); free(tmp); tmp=NULL; } child = child->next; } } free(ans); ans=NULL; } free(fullname_old); fullname_old=NULL; } /* Free memory and exit */ free(xpath); free(name_new); free(surname_new); free(fullname_new); xmlXPathFreeObject(result); return 0; }
decision_proceduret::resultt smt1_dect::read_result_cvc3(std::istream &in) { std::string line; decision_proceduret::resultt res = D_ERROR; smt1_prop.reset_assignment(); typedef hash_map_cont<std::string, std::string, string_hash> valuest; valuest values; while(str_getline(in, line)) { if(line=="sat") res = D_SATISFIABLE; else if(line=="unsat") res = D_UNSATISFIABLE; else if(line.find("Current scope level")!=std::string::npos || line.find("Variable Assignment")!=std::string::npos) ; //ignore else { assert(line.substr(0,13)==" :assumption"); std::size_t pos=line.find('('); if(pos!=std::string::npos) { std::string var; std::string val; if(line[pos+1]=='=') { std::string ops = line.substr(pos+3, line.length()-pos-4); std::size_t blank=ops.find(' '); var = ops.substr(0, blank); val = ops.substr(blank+1, ops.length()-blank); if((var.length()>=4 && var.substr(0,4)=="cvc3") || (val.length()>=4 && val.substr(0,4)=="cvc3") || var==val) continue; else if((var.substr(0,9)=="array_of'") || (var.substr(0,2)=="bv" && val.substr(0,2)!="bv")) { std::string t=var; var=val; val=t; } } else if(line.substr(pos+1,3)=="not") { var = line.substr(pos+5, line.length()-pos-6); val = "false"; } else { var = line.substr(pos+1, line.length()-pos-2); assert(var.find(' ')==std::string::npos); val = "true"; } values[var]=val; } } } for(identifier_mapt::iterator it=identifier_map.begin(); it!=identifier_map.end(); it++) { it->second.value.make_nil(); std::string conv_id=convert_identifier(it->first); std::string value=values[conv_id]; if(value=="") continue; if(value.substr(0,2)=="bv") { std::string v=value.substr(2, value.find('[')-2); size_t p = value.find('[')+1; std::string w=value.substr(p, value.find(']')-p); std::string binary=integer2binary(string2integer(v,10), string2integer(w,10).to_ulong()); set_value(it->second, "", binary); } else if(value=="false") it->second.value.make_false(); else if(value=="true") it->second.value.make_true(); else if(value.substr(0,8)=="array_of") { // We assume that array_of has only concrete arguments... irep_idt id(value); array_of_mapt::const_iterator fit=array_of_map.begin(); while(fit!=array_of_map.end() && fit->second!=id) fit++; if(fit!=array_of_map.end()) it->second.value = fit->first; } else set_value(it->second, "", value); } // Booleans for(unsigned v=0; v<smt1_prop.no_variables(); v++) { std::string value=values["B"+i2string(v)]; if(value=="") continue; smt1_prop.set_assignment(literalt(v, false), value=="true"); } return res; }
decision_proceduret::resultt smt1_dect::read_result_mathsat(std::istream &in) { std::string line; decision_proceduret::resultt res = D_ERROR; smt1_prop.reset_assignment(); typedef hash_map_cont<std::string, valuet, string_hash> valuest; valuest values; while(str_getline(in, line)) { if(line=="sat") res=D_SATISFIABLE; else if(line=="unsat") res=D_UNSATISFIABLE; else if(line.size()>=1 && line[0]=='(') { // (= c_h39__h39___CPROVER_malloc_size_h39_35_h39_1 bv0[64]) // (= (select __h64_0 bv0[32]) bv5[8]) std::size_t pos1=line.find(' '); std::size_t pos2=line.rfind(' '); if(pos1!=std::string::npos && pos2!=std::string::npos && pos1!=pos2) { std::string id=std::string(line, pos1+1, pos2-pos1-1); std::string value=std::string(line, pos2+1, line.size()-pos2-2); if(has_prefix(id, "(select ")) { #if 0 std::size_t pos3=id.rfind(' '); std::string index=std::string(pos3+1, id.size()-pos3-1); id=std::string(id, 8, pos3-8); #endif } else values[id].value=value; } } } for(identifier_mapt::iterator it=identifier_map.begin(); it!=identifier_map.end(); it++) { it->second.value.make_nil(); std::string conv_id=convert_identifier(it->first); std::string value=mathsat_value(values[conv_id].value); if(value!="") set_value(it->second, "", value); } // Booleans for(unsigned v=0; v<smt1_prop.no_variables(); v++) { std::string value=values["B"+i2string(v)].value; if(value=="") continue; smt1_prop.set_assignment(literalt(v, false), value=="true"); } return res; }
decision_proceduret::resultt smt1_dect::read_result_boolector(std::istream &in) { std::string line; str_getline(in, line); if(line=="sat") { smt1_prop.reset_assignment(); typedef hash_map_cont<std::string, valuet, string_hash> valuest; valuest values; while(str_getline(in, line)) { std::size_t pos=line.find(' '); if(pos!=std::string::npos && pos!=0) { std::string id=std::string(line, 0, pos); std::string value=std::string(line, pos+1, std::string::npos); // Boolector offers array values as follows: // // ID[INDEX] VALUE // // There may be more than one line per ID if(id!="" && id[id.size()-1]==']') // array? { std::size_t pos2=id.find('['); if(pos2!=std::string::npos) { std::string new_id=std::string(id, 0, pos2); std::string index=std::string(id, pos2+1, id.size()-pos2-2); values[new_id].index_value_map[index]=value; } } else values[id].value=value; } } // Theory variables for(identifier_mapt::iterator it=identifier_map.begin(); it!=identifier_map.end(); it++) { it->second.value.make_nil(); std::string conv_id=convert_identifier(it->first); const valuet &v=values[conv_id]; for(valuet::index_value_mapt::const_iterator i_it=v.index_value_map.begin(); i_it!=v.index_value_map.end(); i_it++) set_value(it->second, i_it->first, i_it->second); if(v.value!="") set_value(it->second, "", v.value); } // Booleans for(unsigned v=0; v<smt1_prop.no_variables(); v++) { std::string value=values["B"+i2string(v)].value; if(value=="") continue; smt1_prop.set_assignment(literalt(v, false), value=="1"); } return D_SATISFIABLE; } else if(line=="unsat") return D_UNSATISFIABLE; else error("Unexpected result from SMT-Solver: "+line); return D_ERROR; }
bool modelchecker_smvt::read_result( std::istream &out1, std::istream &out2, std::istream &out_ce, abstract_modelt &abstract_model, const threadst &threads, abstract_counterexamplet &counterexample) { // check for errors first { std::list<std::string> file; while(true) { std::string line; if(!str_getline(out2, line)) break; std::cerr << "SMV error output: " << line << std::endl; file.push_back(line); } if(!file.empty()) throw "SMV error - SMV produced output to stderr"; } // now read output if(engine==CADENCE_SMV) return read_result_cadence_smv( out_ce, abstract_model, threads, counterexample); { std::list<std::string> file; while(true) { std::string line; if(!str_getline(out1, line)) break; file.push_back(line); } if(file.empty()) { std::cerr << "No output from SMV" << std::endl; throw "SMV error - SMV produced no output"; } for(std::list<std::string>::const_iterator it=file.begin(); it!=file.end(); it++) { if(std::string(*it, 0, 16)=="-- specification") { if(std::string(*it, it->size()-7)=="is true") { // OK } else if(std::string(*it, it->size()-8)=="is false") { // produce counterexample status("SMV produced counterexample"); read_counterexample(file, it, abstract_model, threads, counterexample); print(9, "SMV counterexample sucessfully read\n"); // show it //std::cout << counterexample; return false; } else throw "unexpected reply from SMV: \""+*it+"\""; } } } return true; }
process_ldif_rec( char *rbuf ) #endif { char *line, *dn, *type, *value, *newrdn, *newparent, *p; char *ctrl_oid=NULL, *ctrl_value=NULL; int ctrl_criticality=1; LDAPControl *ldctrl; int rc, linenum, vlen, modop, replicaport; int expect_modop, expect_sep, expect_chgtype_or_control, expect_newrdn; int expect_deleteoldrdn, expect_newparent, rename, moddn; int deleteoldrdn, saw_replica, use_record, new_entry, delete_entry; int got_all, got_value; LDAPMod **pmods; new_entry = newval; rc = got_all = saw_replica = delete_entry = expect_modop = 0; expect_deleteoldrdn = expect_newrdn = expect_newparent = expect_sep = 0; expect_chgtype_or_control = linenum = got_value = rename = moddn = 0; deleteoldrdn = 1; use_record = force; pmods = NULL; dn = newrdn = newparent = NULL; #ifdef SOLARIS_LDAP_CMD while ( rc == 0 && ( line = str_getline( &rbuf )) != NULL ) { #else while ( rc == 0 && ( line = ldif_getline( &rbuf )) != NULL ) { #endif /* SOLARIS_LDAP_CMD */ ++linenum; if ( expect_sep && strcasecmp( line, T_MODSEPSTR ) == 0 ) { expect_sep = 0; expect_modop = 1; /*If we see a separator in the input stream, but we didn't get a value from the last modify then we have to fill pmods with an empty value*/ if (modop == LDAP_MOD_REPLACE && !got_value){ addmodifyop( &pmods, modop, value, NULL, 0); } got_value = 0; continue; } #ifdef SOLARIS_LDAP_CMD if ( str_parse_line( line, &type, &value, &vlen ) < 0 ) { #else if ( ldif_parse_line( line, &type, &value, &vlen ) < 0 ) { #endif /* SOLARIS_LDAP_CMD */ fprintf( stderr, gettext("%s: invalid format (line %d of entry: %s)\n"), ldaptool_progname, linenum, dn == NULL ? "" : dn ); fprintf( stderr, gettext("%s: line contents: (%s)\n"), ldaptool_progname, line ); rc = LDAP_PARAM_ERROR; break; } evaluate_line: if ( dn == NULL ) { if ( !use_record && strcasecmp( type, T_REPLICA_STR ) == 0 ) { ++saw_replica; if (( p = strchr( value, ':' )) == NULL ) { replicaport = LDAP_PORT; } else { *p++ = '\0'; replicaport = atoi( p ); } if ( strcasecmp( value, ldaptool_host ) == 0 && replicaport == ldaptool_port ) { use_record = 1; } } else if ( strcasecmp( type, T_DN_STR ) == 0 ) { if (( dn = strdup( value )) == NULL ) { perror( "strdup" ); exit( LDAP_NO_MEMORY ); } expect_chgtype_or_control = 1; } else if ( strcasecmp( type, T_VERSION_STR ) == 0 ) { ldif_version = atoi( value ); if ( ldif_version != LDIF_VERSION_ONE ) { fprintf( stderr, gettext("%s: LDIF version %d is not supported;" " use version: %d\n"), ldaptool_progname, ldif_version, LDIF_VERSION_ONE ); exit( LDAP_PARAM_ERROR ); } if ( ldaptool_verbose ) { printf( gettext("Processing a version %d LDIF file...\n"), ldif_version ); } /* Now check if there's something left to process */ /* and if not, go get the new record, else continue */ if ( *rbuf == '\0' ) { return( 0 ); } } else if ( !saw_replica ) { printf( gettext("%s: skipping change record: no dn: line\n"), ldaptool_progname ); return( 0 ); } continue; /* skip all lines until we see "dn:" */ } if ( expect_chgtype_or_control ) { expect_chgtype_or_control = 0; if ( !use_record && saw_replica ) { printf( gettext("%s: skipping change record for entry: %s\n\t(LDAP host/port does not match replica: lines)\n"), ldaptool_progname, dn ); free( dn ); return( 0 ); } #ifndef SOLARIS_LDAP_CMD if ( strcasecmp( type, "control" ) == 0 ) { value = strdup_and_trim( value ); if (ldaptool_parse_ctrl_arg(value, ' ', &ctrl_oid, &ctrl_criticality, &ctrl_value, &vlen)) { usage(); } ldctrl = calloc(1,sizeof(LDAPControl)); if (ctrl_value) { rc = ldaptool_berval_from_ldif_value( ctrl_value, vlen, &(ldctrl->ldctl_value), 1 /* recognize file URLs */, 0 /* always try file */, 1 /* report errors */ ); if ((rc = ldaptool_fileurlerr2ldaperr( rc )) != LDAP_SUCCESS) { fprintf( stderr, gettext("Unable to parse %s\n"), ctrl_value); usage(); } } ldctrl->ldctl_oid = ctrl_oid; ldctrl->ldctl_iscritical = ctrl_criticality; ldaptool_add_control_to_array(ldctrl, ldaptool_request_ctrls); expect_chgtype_or_control = 1; continue; } #endif /* SOLARIS_LDAP_CMD */ if ( strcasecmp( type, T_CHANGETYPESTR ) == 0 ) { value = strdup_and_trim( value ); if ( strcasecmp( value, T_MODIFYCTSTR ) == 0 ) { new_entry = 0; expect_modop = 1; } else if ( strcasecmp( value, T_ADDCTSTR ) == 0 ) { new_entry = 1; modop = LDAP_MOD_ADD; } else if ( strcasecmp( value, T_MODRDNCTSTR ) == 0 ) { expect_newrdn = 1; moddn = 1; } else if ( strcasecmp( value, T_MODDNCTSTR ) == 0 ) { expect_newrdn = 1; moddn = 1; } else if ( strcasecmp( value, T_RENAMECTSTR ) == 0 ) { expect_newrdn = 1; rename = 1; } else if ( strcasecmp( value, T_DELETECTSTR ) == 0 ) { got_all = delete_entry = 1; } else { fprintf( stderr, gettext("%s: unknown %s \"%s\" (line %d of entry: %s)\n"), ldaptool_progname, T_CHANGETYPESTR, value, linenum, dn ); rc = LDAP_PARAM_ERROR; } free( value ); continue; } else if ( newval ) { /* missing changetype => add */ new_entry = 1; modop = LDAP_MOD_ADD; } else { /*The user MUST put in changetype: blah unless adding a new entry with either -a or ldapadd*/ fprintf(stderr, gettext("%s: Missing changetype operation specification.\n\tThe dn line must be followed by \"changetype: operation\"\n\t(unless ldapmodify is called with -a option)\n\twhere operation is add|delete|modify|modrdn|moddn|rename\n\t\"%s\" is not a valid changetype operation specification\n\t(line %d of entry %s)\n"), ldaptool_progname, type, linenum, dn); rc = LDAP_PARAM_ERROR; /*expect_modop = 1; missing changetype => modify */ } } if ( expect_modop ) { expect_modop = 0; expect_sep = 1; if ( strcasecmp( type, T_MODOPADDSTR ) == 0 ) { modop = LDAP_MOD_ADD; continue; } else if ( strcasecmp( type, T_MODOPREPLACESTR ) == 0 ) { modop = LDAP_MOD_REPLACE; continue; } else if ( strcasecmp( type, T_MODOPDELETESTR ) == 0 ) { modop = LDAP_MOD_DELETE; addmodifyop( &pmods, modop, value, NULL, 0 ); continue; #ifdef SOLARIS_LDAP_CMD } else { /* no modify op: use default */ modop = replace ? LDAP_MOD_REPLACE : LDAP_MOD_ADD; } #else } else { /*Bug 27479. Remove default add operation*/ fprintf(stderr, gettext("%s: Invalid parameter \"%s\" specified for changetype modify (line %d of entry %s)\n"), ldaptool_progname, type, linenum, dn); rc = LDAP_PARAM_ERROR; } #endif /* SOLARIS_LDAP_CMD */ } if ( expect_newrdn ) { if ( strcasecmp( type, T_NEWRDNSTR ) == 0 ) { if ( *value == '\0' ) { fprintf( stderr, gettext("%s: newrdn value missing (line %d of entry: %s)\n"), ldaptool_progname, linenum, dn == NULL ? "" : dn ); rc = LDAP_PARAM_ERROR; } else if (( newrdn = strdup( value )) == NULL ) { perror( "strdup" ); exit( LDAP_NO_MEMORY ); } else { expect_newrdn = 0; if ( rename ) { expect_newparent = 1; } else { expect_deleteoldrdn = 1; } } } else { fprintf( stderr, gettext("%s: expecting \"%s:\" but saw \"%s:\" (line %d of entry %s)\n"), ldaptool_progname, T_NEWRDNSTR, type, linenum, dn ); rc = LDAP_PARAM_ERROR; } } else if ( expect_newparent ) { expect_newparent = 0; if ( rename ) { expect_deleteoldrdn = 1; } if ( strcasecmp( type, T_NEWPARENTSTR ) == 0 || strcasecmp( type, T_NEWSUPERIORSTR ) == 0 ) { if (( newparent = strdup( value )) == NULL ) { perror( "strdup" ); exit( LDAP_NO_MEMORY ); } } else { /* Since this is an optional argument for rename/moddn, cause * the current line to be re-evaluated if newparent doesn't * follow deleteoldrdn. */ newparent = NULL; goto evaluate_line; } } else if ( expect_deleteoldrdn ) { if ( strcasecmp( type, T_DELETEOLDRDNSTR ) == 0 ) { if ( *value == '\0' ) { fprintf( stderr, gettext("%s: missing 0 or 1 (line %d of entry: %s)\n"), ldaptool_progname, linenum, dn == NULL ? "" : dn ); rc = LDAP_PARAM_ERROR; } else { deleteoldrdn = ( *value == '0' ) ? 0 : 1; expect_deleteoldrdn = 0; if ( moddn ) { expect_newparent = 1; } } } else { fprintf( stderr, gettext("%s: expecting \"%s:\" but saw \"%s:\" (line %d of entry %s)\n"), ldaptool_progname, T_DELETEOLDRDNSTR, type, linenum, dn ); rc = LDAP_PARAM_ERROR; } got_all = 1; } else if ( got_all ) { fprintf( stderr, gettext("%s: extra lines at end (line %d of entry %s)\n"), ldaptool_progname, linenum, dn ); rc = LDAP_PARAM_ERROR; got_all = 1; } else { addmodifyop( &pmods, modop, type, value, vlen ); /*There was a value to replace*/ got_value = 1; } } if ( rc == 0 ) { if ( delete_entry ) { #ifdef SOLARIS_LDAP_CMD rc = dodelete( ld, dn ); #else rc = dodelete( dn ); #endif /* SOLARIS_LDAP_CMD */ } else if ( newrdn != NULL ) { #ifdef SOLARIS_LDAP_CMD rc = dorename( ld, dn, newrdn, newparent, deleteoldrdn ); #else rc = dorename( dn, newrdn, newparent, deleteoldrdn ); #endif /* SOLARIS_LDAP_CMD */ rename = 0; } else { /*Patch to fix Bug 22183 If pmods is null, then there is no attribute to replace, so we alloc an empty pmods*/ if (modop == LDAP_MOD_REPLACE && !got_value && expect_sep){ addmodifyop( &pmods, modop, value, NULL, 0); }/*End Patch*/ #ifdef SOLARIS_LDAP_CMD rc = domodify( ld, dn, pmods, new_entry ); #else rc = domodify( dn, pmods, new_entry ); #endif /* SOLARIS_LDAP_CMD */ } if ( rc == LDAP_SUCCESS ) { rc = 0; } } if ( dn != NULL ) { free( dn ); } if ( newrdn != NULL ) { free( newrdn ); } if ( newparent != NULL ) { free( newparent ); } if ( pmods != NULL ) { freepmods( pmods ); } return( rc ); } static int #ifdef SOLARIS_LDAP_CMD process_ldapmod_rec( LDAP *ld, char *rbuf ) #else process_ldapmod_rec( char *rbuf ) #endif /* SOLARIS_LDAP_CMD */ { char *line, *dn, *p, *q, *attr, *value; int rc, linenum, modop; LDAPMod **pmods; pmods = NULL; dn = NULL; linenum = 0; line = rbuf; rc = 0; while ( rc == 0 && rbuf != NULL && *rbuf != '\0' ) { ++linenum; if (( p = strchr( rbuf, '\n' )) == NULL ) { rbuf = NULL; } else { if ( *(p-1) == '\\' ) { /* lines ending in '\' are continued */ strcpy( p - 1, p ); rbuf = p; continue; } *p++ = '\0'; rbuf = p; } if ( dn == NULL ) { /* first line contains DN */ if (( dn = strdup( line )) == NULL ) { perror( "strdup" ); exit( LDAP_NO_MEMORY ); } } else { if (( p = strchr( line, '=' )) == NULL ) { value = NULL; p = line + strlen( line ); } else { *p++ = '\0'; value = p; } for ( attr = line; *attr != '\0' && isspace( *attr ); ++attr ) { ; /* skip attribute leading white space */ } for ( q = p - 1; q > attr && isspace( *q ); --q ) { *q = '\0'; /* remove attribute trailing white space */ } if ( value != NULL ) { while ( isspace( *value )) { ++value; /* skip value leading white space */ } for ( q = value + strlen( value ) - 1; q > value && isspace( *q ); --q ) { *q = '\0'; /* remove value trailing white space */ } if ( *value == '\0' ) { value = NULL; } } if ( value == NULL && newval ) { fprintf( stderr, gettext("%s: missing value on line %d (attr is %s)\n"), ldaptool_progname, linenum, attr ); rc = LDAP_PARAM_ERROR; } else { switch ( *attr ) { case '-': modop = LDAP_MOD_DELETE; ++attr; break; case '+': modop = LDAP_MOD_ADD; ++attr; break; default: #ifdef SOLARIS_LDAP_CMD modop = replace ? LDAP_MOD_REPLACE : LDAP_MOD_ADD; #else /*Bug 27479. Remove the add default*/ fprintf(stderr, gettext("%s: Invalid parameter specified for changetype modify (line %d of entry %s)\n"), ldaptool_progname, linenum, dn); rc = LDAP_PARAM_ERROR; #endif /* SOLARIS_LDAP_CMD */ } addmodifyop( &pmods, modop, attr, value, ( value == NULL ) ? 0 : strlen( value )); } } line = rbuf; } if ( rc == 0 ) { if ( dn == NULL ) { rc = LDAP_PARAM_ERROR; #ifdef SOLARIS_LDAP_CMD } else if (( rc = domodify( ld, dn, pmods, newval )) == LDAP_SUCCESS ){ #else } else if (( rc = domodify( dn, pmods, newval )) == LDAP_SUCCESS ){ #endif /* SOLARIS_LDAP_CMD */ rc = 0; } } if ( pmods != NULL ) { freepmods( pmods ); } if ( dn != NULL ) { free( dn ); } return( rc ); }
/* Read a system from file */ int thermo_readthermo(Thermo *A, const char *fname) { char *row=NULL, *key, *val; int nr, i; FILE *fp; /* Open input config file */ fp = cyg_fopen(fname, "r"); cyg_assert(fp!=NULL, CYG_FAILURE, "Error opening input file."); /* Read all elements */ while (str_getline(&row, fp) != -1) { /* Skip empty or comment lines */ if (str_isempty(row, "# \n\r\t\0")) continue; /* Parse all key:val pairs */ key = strtok(row, "="); val = strtok(NULL, "="); cyg_assert(val!=NULL, CYG_FAILURE, "Invalid value <%s> for key <%s>", val, key); /* Temperature in kelvin */ if (strncmp(key, "temperature", 4)==0) { nr = sscanf(val, "%lf", &(A->T)); cyg_assert(nr==1, CYG_FAILURE, "Invalid value <%s> for key <%s>", val, key); } /* Number of moles */ else if (strncmp(key, "nmoles", 4)==0) { nr = sscanf(val, "%lf", &(A->n)); cyg_assert(nr==1, CYG_FAILURE, "Invalid value <%s> for key <%s>", val, key); } /* Volume (liters) */ else if (strncmp(key, "volume", 4)==0) { nr = sscanf(val, "%lf", &(A->V)); cyg_assert(nr==1, CYG_FAILURE, "Invalid value <%s> for key <%s>", val, key); } /* Molecular mass in g/mol */ else if (strncmp(key, "mass", 4)==0) { nr = sscanf(val, "%lf", &(A->m)); cyg_assert(nr==1, CYG_FAILURE, "Invalid value <%s> for key <%s>", val, key); } /* Translational degree of freedom */ else if (strncmp(key, "translations", 4)==0) { nr = sscanf(val, "%d", &(A->t)); cyg_assert(nr==1, CYG_FAILURE, "Invalid value <%s> for key <%s>", val, key); } /* Symmetry Number */ else if (strncmp(key, "sigma", 4)==0) { nr = sscanf(val, "%d", &(A->s)); cyg_assert(nr==1, CYG_FAILURE, "Invalid value <%s> for key <%s>", val, key); } /* Rotational degree of freedom and moments of inertia */ else if (strncmp(key, "rotations", 4)==0) { nr = sscanf(val, "%d", &(A->r)); cyg_assert(nr==1, CYG_FAILURE, "Invalid value <%s> for key <%s>", val, key); /* Read inertia moments in g/mol/A^2 */ if (A->r>0) { A->I = cyg_realloc(NULL, (A->r)*cyg_sizeof(double)); cyg_assert(A->I!=NULL, CYG_FAILURE, "Memory allocation failed!"); for (i=0; i<A->r; i++) { if (str_getline(&row, fp) != -1) { if (str_isempty(row, "#\n\0")) continue; nr=sscanf(row, "%lf", &(A->I[i])); cyg_assert(nr==1, CYG_FAILURE, "Impossible to read inertia moment #%d (expected #%d)", i, A->r); } } } }
disp_t * disp_sample_table_new_from_mat_file (const char * filename) { FILE * f; str_t row; disp_t *disp = NULL; enum disp_type dtype; int convert_ev = 0; int provide_diel_k = 0; f = fopen (filename, "r"); if (f == NULL) { notify_error_msg (LOADING_FILE_ERROR, "Cannot open %s", filename); return NULL; } str_init (row, 64); str_getline (row, f); str_getline (row, f); if (strncasecmp (CSTR(row), "CAUCHY", 6) == 0) { dtype = DISP_CAUCHY; } else if (strncasecmp (CSTR(row), "ev", 2) == 0) { convert_ev = 1; } else if (strncasecmp (CSTR(row), "nm", 2) != 0) { notify_error_msg (LOADING_FILE_ERROR, "Invalide MAT format: %s", filename); goto close_exit; } str_getline (row, f); if (strncasecmp (CSTR(row), "nk", 2) == 0) { dtype = DISP_SAMPLE_TABLE; } else if (strncasecmp (CSTR(row), "e1e2", 4) == 0) { dtype = DISP_SAMPLE_TABLE; provide_diel_k = 1; } else { notify_error_msg (LOADING_FILE_ERROR, "Invalide MAT format: %s", filename); goto close_exit; } switch (dtype) { case DISP_SAMPLE_TABLE: { struct disp_sample_table *dt; struct data_table *table; long start_pos = ftell (f); int j, lines; disp = disp_new (DISP_SAMPLE_TABLE); dt = & disp->disp.sample_table; disp_sample_table_clear (dt); start_pos = ftell (f); for (lines = 0; ; ) { float xd[3]; int read_status = fscanf (f, "%f %f %f\n", xd, xd+1, xd+2); if (read_status == 3) lines ++; if (read_status == EOF) break; } if (lines < 2) { disp_free (disp); disp = NULL; break; } fseek (f, start_pos, SEEK_SET); disp_sample_table_init (dt, lines); table = dt->table_ref; for (j = 0; j < lines; j++) { float *dptr = table->heap + 3 * j; int read_status; do read_status = fscanf (f, "%f %f %f\n", dptr, dptr+1, dptr+2); while (read_status < 3 && read_status != EOF); if (convert_ev) dptr[0] = 1239.8 / dptr[0]; if (provide_diel_k) { double e1 = dptr[1], e2 = dptr[2]; double ne = sqrt(e1*e1 + e2*e2); dptr[1] = sqrt((ne + e1) / 2.0); dptr[2] = sqrt((ne - e1) / 2.0); } if (read_status == EOF) break; } break; } case DISP_CAUCHY: notify_error_msg (LOADING_FILE_ERROR, "cauchy MAT files"); break; #if 0 cn = disp->disp.cauchy.n; ck = disp->disp.cauchy.k; fscanf (f, "%lf %lf %lf %*f %*f %*f\n", cn, cn+1, cn+2); cn[1] *= 1e3; cn[2] *= 1e6; ck[0] = ck[1] = ck[2] = 0.0; break; #endif default: notify_error_msg (LOADING_FILE_ERROR, "corrupted material card"); break; } close_exit: fclose (f); str_free (row); return disp; }
propt::resultt qbf_quantort::prop_solve() { { std::string msg= "Quantor: "+ i2string(no_variables())+" variables, "+ i2string(no_clauses())+" clauses"; messaget::status(msg); } std::string qbf_tmp_file="quantor.qdimacs"; std::string result_tmp_file="quantor.out"; { std::ofstream out(qbf_tmp_file.c_str()); // write it write_qdimacs_cnf(out); } //std::string options=" --equivalences=0"; std::string options=""; // solve it system(("quantor "+qbf_tmp_file+ options+ " -o "+result_tmp_file).c_str()); bool result=false; // read result { std::ifstream in(result_tmp_file.c_str()); bool result_found=false; while(in) { std::string line; str_getline(in, line); if(line!="" && line[line.size()-1]=='\r') line.resize(line.size()-1); if(line=="s TRUE") { result=true; result_found=true; break; } else if(line=="s FALSE") { result=false; result_found=true; break; } } if(!result_found) { messaget::error("Quantor failed: unknown result"); return P_ERROR; } } if(result) { messaget::status("Quantor: TRUE"); return P_SATISFIABLE; } else { messaget::status("Quantor: FALSE"); return P_UNSATISFIABLE; } return P_ERROR; }
disp_t * disp_sample_table_new_from_mat_file(const char * filename, str_ptr *error_msg) { FILE * f; str_t row; disp_t *disp = NULL; enum disp_type dtype; unsigned int wl_unit_conv = 0; int provide_diel_k = 0; f = fopen(filename, "r"); if(f == NULL) { *error_msg = new_error_message(LOADING_FILE_ERROR, "File \"%s\" does not exists or cannot be opened", filename); return NULL; } str_t name; str_init(name, 64); str_init(row, 64); str_getline(name, f); str_getline(row, f); if(strncasecmp(CSTR(row), "CAUCHY", 6) == 0) { dtype = DISP_CAUCHY; } else if(strncasecmp(CSTR(row), "ev", 2) == 0) { wl_unit_conv |= WL_UNIT_CONVERT_EV; } else if(strncasecmp(CSTR(row), "ANGSTROMS", 9) == 0) { wl_unit_conv |= WL_UNIT_CONVERT_ANGSTROMS; } else if(strncasecmp(CSTR(row), "nm", 2) != 0) { *error_msg = new_error_message(LOADING_FILE_ERROR, "Invalide MAT file: \"%s\"", filename); goto close_exit; } str_getline(row, f); if(strncasecmp(CSTR(row), "nk", 2) == 0) { dtype = DISP_SAMPLE_TABLE; } else if(strncasecmp(CSTR(row), "e1e2", 4) == 0) { dtype = DISP_SAMPLE_TABLE; provide_diel_k = 1; } else { *error_msg = new_error_message(LOADING_FILE_ERROR, "Invalide MAT file: \"%s\"", filename); goto close_exit; } switch(dtype) { case DISP_SAMPLE_TABLE: { struct disp_sample_table *dt; long start_pos = ftell(f); int j, lines; disp = disp_new(DISP_SAMPLE_TABLE); str_copy(disp->name, name); dt = & disp->disp.sample_table; clear(dt); start_pos = ftell(f); for(lines = 0; ;) { float xd[3]; int read_status = fscanf(f, "%f %f %f\n", xd, xd+1, xd+2); if(read_status == 3) { lines ++; } if(read_status == EOF) { break; } } if(lines < 2) { disp_free(disp); disp = NULL; break; } fseek(f, start_pos, SEEK_SET); init(dt, lines); double *wptr = wavelength_array(dt); double *nptr = n_array(dt); double *kptr = k_array(dt); for(j = 0; j < lines; j++, wptr++, nptr++, kptr++) { int read_status; do { read_status = fscanf(f, "%lf %lf %lf\n", wptr, nptr, kptr); } while(read_status < 3 && read_status != EOF); if(wl_unit_conv & WL_UNIT_CONVERT_EV) { *wptr = 1239.8 / *wptr; } else if(wl_unit_conv & WL_UNIT_CONVERT_ANGSTROMS) { *wptr /= 10.0; } if(provide_diel_k) { double e1 = *nptr, e2 = *kptr; double ne = sqrt(e1*e1 + e2*e2); *nptr = sqrt((ne + e1) / 2.0); *kptr = sqrt((ne - e1) / 2.0); } if(read_status == EOF) { break; } } prepare_interp(dt); break; } case DISP_CAUCHY: *error_msg = new_error_message(LOADING_FILE_ERROR, "cauchy MAT format is unsupported"); break; #if 0 cn = disp->disp.cauchy.n; ck = disp->disp.cauchy.k; fscanf(f, "%lf %lf %lf %*f %*f %*f\n", cn, cn+1, cn+2); cn[1] *= 1e3; cn[2] *= 1e6; ck[0] = ck[1] = ck[2] = 0.0; break; #endif default: *error_msg = new_error_message(LOADING_FILE_ERROR, "corrupted material card"); break; } close_exit: fclose(f); str_free(name); str_free(row); return disp; }
decision_proceduret::resultt smt2_dect::read_result_mathsat(std::istream &in) { std::string line; decision_proceduret::resultt res=D_ERROR; smt2_prop.reset_assignment(); typedef hash_map_cont<std::string, std::string, string_hash> valuest; valuest values; while(str_getline(in, line)) { if(line=="sat") res=D_SATISFIABLE; else if(line=="unsat") res=D_UNSATISFIABLE; else if(line.size()>=2 && line[0]=='(') { // ( (B0 true) ) std::size_t pos1=line.find('(', 1); std::size_t pos2=line.find(' ', pos1); std::size_t pos3=line.find(')', pos2); if(pos1!=std::string::npos && pos2!=std::string::npos && pos3!=std::string::npos) { std::string id=std::string(line, pos1+1, pos2-pos1-1); std::string value=std::string(line, pos2+1, pos3-pos2-1); values[id]=value; } } } for(identifier_mapt::iterator it=identifier_map.begin(); it!=identifier_map.end(); it++) { it->second.value.make_nil(); std::string conv_id=convert_identifier(it->first); std::string value=values[conv_id]; if(value=="") continue; if (value.substr(0, 5) == "(_ bv") { // value is "(_ bvDECIMAL_VALUE SIZE" // convert to binary value = value.substr(5); size_t pos = value.find(' '); std::string v = value.substr(0, pos); std::string w = value.substr(pos+1); value = integer2binary(string2integer(v, 10), string2integer(w, 10).to_ulong()); } set_value(it->second, value); } // Booleans for(unsigned v=0; v<smt2_prop.no_variables(); v++) { std::string value=values["B"+i2string(v)]; if(value=="") continue; smt2_prop.set_assignment(literalt(v, false), value=="true"); } return res; }
void vsf_parseconf_load_file(const char* p_filename, int errs_fatal) { struct mystr config_file_str = INIT_MYSTR; struct mystr config_setting_str = INIT_MYSTR; struct mystr config_value_str = INIT_MYSTR; unsigned int str_pos = 0; int retval; if (!p_filename) { p_filename = s_p_saved_filename; } else { if (s_p_saved_filename) { vsf_sysutil_free((char*)s_p_saved_filename); } s_p_saved_filename = vsf_sysutil_strdup(p_filename); } if (!p_filename) { bug("null filename in vsf_parseconf_load_file"); } retval = str_fileread(&config_file_str, p_filename, VSFTP_CONF_FILE_MAX); if (vsf_sysutil_retval_is_error(retval)) { if (errs_fatal) { die2("cannot read config file: ", p_filename); } else { str_free(&config_file_str); return; } } { struct vsf_sysutil_statbuf* p_statbuf = 0; retval = vsf_sysutil_stat(p_filename, &p_statbuf); /* Security: check current user owns the config file. These are sanity * checks for the admin, and are NOT designed to be checks safe from * race conditions. */ if (vsf_sysutil_retval_is_error(retval) || vsf_sysutil_statbuf_get_uid(p_statbuf) != vsf_sysutil_getuid() || !vsf_sysutil_statbuf_is_regfile(p_statbuf)) { die("config file not owned by correct user, or not a file"); } vsf_sysutil_free(p_statbuf); } while (str_getline(&config_file_str, &config_setting_str, &str_pos)) { if (str_isempty(&config_setting_str) || str_get_char_at(&config_setting_str, 0) == '#' || str_all_space(&config_setting_str)) { continue; } vsf_parseconf_load_setting(str_getbuf(&config_setting_str), errs_fatal); } str_free(&config_file_str); str_free(&config_setting_str); str_free(&config_value_str); }
struct spectrum * load_ellips_spectrum(const char *filename, struct extra_param *einf) { struct spectrum *spectr = NULL; enum spectra_kind spkind; FILE *f; int iseof, npt, nr; str_t ln; sr_start: f = fopen(filename, "r"); if(f == NULL) { notify_error_msg(LOADING_FILE_ERROR, "error loading spectra %s", filename); return NULL; } str_init(ln, 64); str_getline(ln, f); if(strstr(CSTR(ln), "SE ALPHA BETA")) { spkind = AB_ELLISS_SPECTR; } else if(strstr(CSTR(ln), "SE PSI DELTA")) { spkind = PSIDEL_ELLISS_SPECTR; } else { goto no_good; } einf->aoi = 71.7; einf->analyzer = 25.0; einf->numap = 0.0; for(;;) { iseof = str_getline(ln, f); if(iseof != 0) { break; } nr = sscanf(CSTR(ln), "AOI %lf", & einf->aoi); if(nr == 1) { continue; } nr = sscanf(CSTR(ln), "NA %lf", & einf->numap); if(nr == 1) { continue; } nr = sscanf(CSTR(ln), "A %lf", & einf->analyzer); if(nr == 1) { continue; } break; } einf->aoi = DEGREE(einf->aoi); einf->analyzer = DEGREE(einf->analyzer); for(npt = 0; ; npt++, iseof = str_getline(ln, f)) { double a[3]; double *dt[3] = {a, a+1, a+2}; int k; if(spectr) { dt[0] = & spectr->lambda[npt]; dt[1] = & spectr->data.ab[npt].alpha; dt[2] = & spectr->data.ab[npt].beta; } while(iseof == 0) { k = sscanf(CSTR(ln), "%*s %lf %lf %lf\n", dt[0], dt[1], dt[2]); if(k == 3) { break; } iseof = str_getline(ln, f); } if(iseof != 0) { if(spectr != NULL) { break; } if(npt < 2) { goto no_good; } spectr = emalloc(sizeof(struct spectrum)); spectr->kind = spkind; spectr->npt = npt; spectr->lambda = emalloc(npt * sizeof(double)); spectr->data.ab = emalloc(npt * sizeof(struct elliss_ab)); fclose(f); str_free(ln); goto sr_start; } } spectr->lmin = spectr->lambda[0]; spectr->lmax = spectr->lambda[spectr->npt - 1]; str_free(ln); fclose(f); return spectr; no_good: notify_error_msg(LOADING_FILE_ERROR, "format of spectra %s is incorrect", filename); str_free(ln); fclose(f); return NULL; }
bool pbs_dimacs_cnft::pbs_solve() { //std::cout << "solve: No Lit. = " << no_variables () << std::endl; std::string command; if(!pbs_path.empty()) { command += pbs_path; if (command.substr(command.length(),1) != "/") command += "/"; } command += "pbs"; //std::cout << "PBS COMMAND IS: " << command << std::endl; /* if (!(getenv("PBS_PATH") == NULL)) { command = getenv("PBS_PATH"); } else { error ("Unable to read PBS_PATH environment variable.\n"); return false; } */ command += " -f temp.cnf"; #if 1 if (optimize) { if (binary_search) { command += " -S 1000 -D 1 -H -I -a"; } else { //std::cout << "NO BINARY SEARCH" << std::endl; command += " -S 1000 -D 1 -I -a"; } } else { command += " -S 1000 -D 1 -a"; } #else command += " -z"; #endif command += " -a > temp.out"; system(command.c_str()); std::ifstream file("temp.out"); std::string line; int v; bool satisfied = false; if(file.fail()) { error("Unable to read SAT results!\n"); return false; } opt_sum = -1; while(file && !file.eof ()) { str_getline(file,line); if(strstr(line.c_str(), "Variable Assignments Satisfying CNF Formula:")!=NULL) { //print ("Reading assignments...\n"); //std::cout << "No literals: " << no_variables() << std::endl; satisfied = true; assigned.clear (); for (size_t i = 0; (file && (i < no_variables())); ++i) { file >> v; if (v > 0) { //std::cout << v << " "; assigned.insert(v); } } //std::cout << std::endl; //print ("Finished reading assignments.\n"); } else if (strstr(line.c_str(),"SAT... SUM") != NULL)