Ejemplo n.º 1
0
Archivo: readseq.c Proyecto: Pency/BSPT
int check_read(SEQ_QUAL *item, int mode){
	if(mode == 2){
		if(strlen(item->qual) < item->length){
			warning_msg("sequence %d : quality string is shorter than sequence string, quality length will be used as sequence length\n",item->id);
			item->length = strlen(item->qual);
			item->seq[item->length]='\0';
		}else if(strlen(item->qual) > item->length)
			warning_msg("sequence %d : quality string is longer than sequence string, the longer part will be discarded\n",item->id);
			item->qual[item->length]='\0';
	}

	if(mode == 3){
		if(strlen(item->qual) == 0){
			warning_msg("sequence %d : no quality string, quality will be assiated automatically\n",item->id);
			item->qual = realloc(item->qual, sizeof(char) * (item->length + 1));
			memset(item->qual, 'H', item->length);
			//item->qual[0]='\0';
		}
	}

	if(strlen(item->name) == 0){
		warning_msg("sequence %d is not complete: no sequence name specified, automatically associated\n", item->id);
		sprintf(item->name, "BSPT%6d", item->id);
	}
	if(strlen(item->seq) == 0){
		error_msg("sequence %d is not complete: no bases\n", item->id);
		return -1;
	}
	return 1;
}
Ejemplo n.º 2
0
precedence * mk_precedence(ast_manager & m, order_params const & params) {
    if (params.m_order_precedence_gen.empty())
        return mk_default_precedence(m, params);

    symbol user("user");
    symbol definition("definition");
    symbol interpreted("interpreted");
    symbol frequency("frequency");
    symbol arity("arity");
    symbol arbitrary("arbitrary");
    symbol inv("-");

    ptr_buffer<precedence> ps;

    svector<symbol>::const_iterator it  =  params.m_order_precedence_gen.begin();
    svector<symbol>::const_iterator end =  params.m_order_precedence_gen.end();
    bool prev_inv = false;
    for (; it != end; ++it) {
        symbol curr = *it;
        if (curr == user) {
            if (params.m_order_precedence.empty())
                ps.push_back(mk_inv_precedence(prev_inv, alloc(user_precedence, m, params.m_order_precedence.size(), params.m_order_precedence.c_ptr())));
        }
        else if (curr == definition) {
            warning_msg("definition precedence was not implement yet.");
        }
        else if (curr == interpreted) {
            ps.push_back(mk_inv_precedence(prev_inv, alloc(interpreted_precedence)));
        }
        else if (curr == frequency) {
            warning_msg("frequency precedence was not implement yet.");
        }
        else if (curr == arity) {
            ps.push_back(mk_inv_precedence(prev_inv, alloc(arity_precedence)));
        }
        else if (curr == arbitrary) {
            ps.push_back(mk_inv_precedence(prev_inv, alloc(arbitrary_precedence)));
            // it is pointless to continue, arbitrary_precedence is a total order
            return mk_lex_precedence(ps);
        }
        else if (curr == inv) {
            prev_inv = true;
        }
        else {
            warning_msg("invalid precedence generator: ignoring atom '%s'.", curr.bare_str());
        }
    }
    
    return mk_lex_precedence(ps);
}
Ejemplo n.º 3
0
 void operator()(app * n) {
     func_decl * decl = to_app(n)->get_decl();
     if (is_forbidden(decl)) {
         warning_msg("'%s' cannot be used in patterns.", decl->get_name().str().c_str());
         m_result = false;
     }
 }
Ejemplo n.º 4
0
bool pattern_validator::process(uint_set & found_vars, unsigned num_bindings, unsigned num_new_bindings, expr * n) {
    // I'm traversing the DAG as a tree, this is not a problem since pattern are supposed to be small ASTs.
    if (n->get_kind() == AST_VAR) {
        warning_msg("invalid pattern: variable.");
        return false;
    }

    pattern_validation_functor f(found_vars, num_bindings, num_new_bindings, m_bfid, m_lfid);
    for_each_expr(f, n);
    if (!f.m_result)
        return false;
    if (!f.m_found_a_var) {
        warning_msg("pattern does not contain any variable.");
        return false;
    }
    return true;
}
Ejemplo n.º 5
0
bool pattern_validator::operator()(unsigned num_bindings, unsigned num_new_bindings, expr * n) {
    uint_set found_vars;
    if (!process(found_vars, num_bindings, num_new_bindings, n))
        return false;
    bool r = found_vars.num_elems() == num_new_bindings;
    if (!r)
        warning_msg("pattern does not contain all quantified variables.");
    return r;
}
Ejemplo n.º 6
0
context::~context() {
    reset_parser();
    m_last_obj = 0;
    u_map<api::object*>::iterator it = m_allocated_objects.begin();
    while (it != m_allocated_objects.end()) {
        DEBUG_CODE(warning_msg("Uncollected memory: %d: %s", it->m_key, typeid(*it->m_value).name()););
        m_allocated_objects.remove(it->m_key);
        dealloc(it->m_value);
        it = m_allocated_objects.begin();
    }
Ejemplo n.º 7
0
 context::~context() {
     m_last_obj = nullptr;
     u_map<api::object*>::iterator it = m_allocated_objects.begin();
     while (it != m_allocated_objects.end()) {
         api::object* val = it->m_value;
         DEBUG_CODE(warning_msg("Uncollected memory: %d: %s", it->m_key, typeid(*val).name()););
         m_allocated_objects.remove(it->m_key);
         dealloc(val);
         it = m_allocated_objects.begin();
     }
Ejemplo n.º 8
0
Archivo: step.c Proyecto: AkaBlood/ogs5
/* ---------------------------------------------------------------------- */
int
gas_phase_check (struct gas_phase *gas_phase_ptr)
/* ---------------------------------------------------------------------- */
{
/*
 *   Check for missing elements
 */
  int i, j;

  struct gas_comp *gas_comp_ptr;
  struct master *master_ptr;

  if (gas_phase_ptr == NULL)
    return (OK);
  gas_comp_ptr = gas_phase_ptr->comps;
/*
 *   Check that all elements are in solution for phases with zero mass
 */
  for (i = 0; i < gas_phase_ptr->count_comps; i++)
  {
    count_elts = 0;
    paren_count = 0;
    if (gas_comp_ptr[i].moles <= 0.0)
    {
      add_elt_list (gas_comp_ptr[i].phase->next_elt, 1.0);
      for (j = 0; j < count_elts; j++)
      {
	master_ptr = elt_list[j].elt->primary;
	if (master_ptr->s == s_hplus)
	{
	  continue;
	}
	else if (master_ptr->s == s_h2o)
	{
	  continue;
	}
	else if (master_ptr->total > MIN_TOTAL)
	{
	  continue;
	}
	else
	{
	  if (state != ADVECTION && state != TRANSPORT && state != PHAST)
	  {
	    sprintf (error_string,
		     "Element %s is contained in gas %s (which has 0.0 mass),\nbut is not in solution or other phases.",
		     elt_list[j].elt->name, gas_comp_ptr[i].phase->name);
	    warning_msg (error_string);
	  }
	}
      }
    }
  }
  return (OK);
}
Ejemplo n.º 9
0
//=============================================================================
void Metaserver::HandleClientShake(SA *pcliaddr, ClientShakeMsg &msg)
{
  int                       active;
  unsigned int              handshake;
  list<Handshake>::iterator i;
  char                     *presentation;
  SAIN                     *sa;
  Handshake                 search_for;

  sa = (SAIN *)pcliaddr;
  handshake = msg.GetHandshake();
  search_for.SetValues(sa->sin_addr.s_addr, handshake, 0);
  i = FindByHS(mClientHandshakes.begin(), mClientHandshakes.end(), 
	       search_for);
  if(i != mClientHandshakes.end())
  {
#ifdef DEBUG
    presentation = sock_ntop(pcliaddr, sizeof(SA));
    debug_msg("Received valid handshake from %s", 
	      PolishedPresentation(presentation));
#endif
    mClientHandshakes.erase(i);
    i = FindByAddr(mActiveClients.begin(), mActiveClients.end(), 
		   search_for);
    if(i == mActiveClients.end())
    {
      search_for.SetValues(sa->sin_addr.s_addr, 0, time(NULL));
      mActiveClients.push_back(search_for);

      if((active = mActiveClients.size()) > mPeakActiveClients)
	mPeakActiveClients = active;
#ifdef DEBUG
      presentation = sock_ntop(pcliaddr, sizeof(SA));
      debug_msg("Added new active client at %s",
		PolishedPresentation(presentation));
#endif
    }
    else
    {
      (*i).SetTimestamp(time(NULL));
#ifdef DEBUG
      presentation = sock_ntop(pcliaddr, sizeof(SA));
      debug_msg("Updated existing client at %s",
		PolishedPresentation(presentation));
#endif
    }
  }
  else
  {
    presentation = sock_ntop(pcliaddr, sizeof(SA));
    warning_msg("Bogus CLIENTSHAKE packet received from: %s", 
		PolishedPresentation(presentation));
  }
}
Ejemplo n.º 10
0
 void operator()(var * v) {
     unsigned idx = to_var(v)->get_idx();
     if (idx >= m_num_bindings) {
         warning_msg("free variables cannot be used in patterns.");
         m_result = false;
         return;
     }
     if (idx < m_num_new_bindings) {
         m_found_a_var = true;
         m_found_vars.insert(idx);
     }
 }
Ejemplo n.º 11
0
bool simple_parser::parse_file(char const * file, expr_ref & result) {
    if (file != 0) {
        std::ifstream stream(file);
        if (!stream) {
            warning_msg("ERROR: could not open file '%s'.", file);
            return false;
        }
        return parse(stream, result);
    }
    else {
        return parse(std::cin, result);
    }
}
Ejemplo n.º 12
0
//=============================================================================
void Metaserver::HandleTerminate(SA *pcliaddr)
{
  list<Handshake>::iterator i;
  char                     *presentation;
  SAIN                     *sa;
  Handshake                 search_for;

  sa = (SAIN *)pcliaddr;
  search_for.SetValues(sa->sin_addr.s_addr, 0, 0);
  i = FindByAddr(mActiveServers.begin(), mActiveServers.end(), 
		 search_for);
  if(i != mActiveServers.end())
  {
#ifdef DEBUG
    presentation = sock_ntop(pcliaddr, sizeof(SA));
    debug_msg("Received termination from server at %s",
	      PolishedPresentation(presentation));
#endif
    mActiveServers.erase(i);
    if(mExecute[0] != '\0') {
      int res = system(mExecute);
      if (res == -1) {
        err_sys("fork");
      } else {
        int status = WEXITSTATUS(res);
        if (status != 0) {
          warning_msg("error running %s: %d", mExecute, status);
        }
      }
    }
  }
  else
  {
    presentation = sock_ntop(pcliaddr, sizeof(SA));
    warning_msg("Received TERMINATION packet for unlisted server from: "
		"%s", PolishedPresentation(presentation));
  }
}
Ejemplo n.º 13
0
bool simple_parser::parse(std::istream & in, expr_ref & result) {
	scanner s(in, std::cerr, false);
    try {
        result = parse_expr(s);
        if (!result)
            throw parser_error();
    }
    catch (parser_error) {
        warning_msg("parser error");
        return false;
    } 
    m_exprs.reset();
    return result.get() != 0;
}
Ejemplo n.º 14
0
int
CVReInitDense(void *cvode_mem, CVDenseJacFn djac, void *jac_data)
{
	CVodeMem cv_mem;
	CVDenseMem cvdense_mem;

	/* Return immediately if cvode_mem is NULL */
	cv_mem = (CVodeMem) cvode_mem;
	if (cv_mem == NULL)
	{							/* CVode reports this error */
		//CVMEM warning_msg( MSG_CVMEM_NULL);
#if !defined(R_SO)
		std::cerr << MSG_CVMEM_NULL << std::endl;
#endif
		return (LMEM_FAIL);
	}

	/* Test if the NVECTOR package is compatible with the DENSE solver */
	if ((strcmp(machenv->tag, "serial")) ||
		machenv->ops->nvmake == NULL ||
		machenv->ops->nvdispose == NULL ||
		machenv->ops->nvgetdata == NULL || machenv->ops->nvsetdata == NULL)
	{
		CVMEM warning_msg( MSG_WRONG_NVEC);
		return (LMEM_FAIL);
	}

	cvdense_mem = (CVDenseMem) lmem;	/* Use existing linear solver memory pointer */

	/* Set four main function fields in cv_mem */
	linit = CVDenseInit;
	lsetup = CVDenseSetup;
	lsolve = CVDenseSolve;
	lfree = CVDenseFree;

	/* Set Jacobian routine field, J_data, and setupNonNull */
	if (djac == NULL)
	{
		jac = CVDenseDQJac;
	}
	else
	{
		jac = djac;
	}
	J_data = jac_data;
	setupNonNull = TRUE;

	return (SUCCESS);
}
Ejemplo n.º 15
0
static int set_usb_power(void)
{
	int ret;

	ret = file_puts_retry(USB_POWER_CONTROL_PATH, "on", 10);
	if (ret < 0)
	{
#ifdef CAVAN_DEBUG
		warning_msg("write file \"%s\"", USB_POWER_CONTROL_PATH);
#endif
		return ret;
	}

	ret = file_puts_retry(USB_POWER_WAKEUP_PATH, "disabled", 10);
	if (ret < 0)
	{
#ifdef CAVAN_DEBUG
		warning_msg("write file \"%s\"", USB_POWER_WAKEUP_PATH);
#endif
		return ret;
	}

	return 0;
}
Ejemplo n.º 16
0
int mkdir_report(char *path)
{
	struct stat buf;
	if(stat(path, &buf) != 0){
		warning_msg("There is no directory [%s], will be created!\n",path);
		if(mkdir(path, 10705) != 0){
			error_msg("Directory [%s] can not be created!\n",path);
			return -1;
		}else{
			notice_msg("Directory has been created successfully!\n");
		}
	}else if(!S_ISDIR(buf.st_mode)){
			error_msg("%s is not dir\n",path);
			return -1;
	}
	return 0;
}
Ejemplo n.º 17
0
Archivo: step.c Proyecto: AkaBlood/ogs5
/* ---------------------------------------------------------------------- */
int
solution_check (void)
/* ---------------------------------------------------------------------- */
{
/*
 *   Check for missing elements
 */
  int i;
  struct master *master_ptr;

/*
 *   Check that all elements are in solution for phases with zero mass
 */
  for (i = 0; i < count_master; i++)
  {
    master_ptr = master[i];
    if (master_ptr->total >= 0.0)
      continue;
    if (master_ptr->total > -MIN_TOTAL)
    {
      master_ptr->total = 0;
      continue;
    }
    if (master_ptr->s == s_eminus || master_ptr->s == s_h2o
	|| master_ptr->s == s_hplus || master_ptr->s == s_h3oplus)
    {
      master_ptr->total = 0;
      continue;
    }
    /*
    sprintf (error_string,
	     "Element %s has negative moles in solution, %e. \n\tErroneous mole balance occurs as moles are added to produce zero moles.\n\tUsually caused by KINETICS, REACTION, or diffuse layer calculation.\n\tMay be due to large time steps in early part of KINETICS simulation or negative concentrations in the diffuse layer.",
	     master_ptr->elt->name, (double) master_ptr->total);
    */
    sprintf (error_string,
	     "Negative moles in solution for %s, %e. Recovering...", master_ptr->elt->name, (double) master_ptr->total);
    warning_msg (error_string);
    return (MASS_BALANCE);
  }
  return (OK);
}
Ejemplo n.º 18
0
int detect_datatype(char *file){

	int dataType=0;
	int i = 0;
	int max = 0;
	int min = 999;
	int sample = 100;

	SEQ_QUAL item = init_read();
	gzFile zfp = gzopen_report(file,"r");

	if(gzgetc(zfp) == '>'){
		dataType |= FILE_FASTA;
	}else{
		gzseek(zfp, 0L, SEEK_SET);
		if(read_fastq(zfp,&item,i) >= 0){
			dataType |= FILE_FASTQ;
			do{
				for(i=0;i+1<strlen(item.qual);i++){
                                        min = MIN(min, item.qual[i]);
                                        max = MAX(max, item.qual[i]);
                                }
                                if((sample--) == 0){
                                        if(max >= 75)
						dataType|=FILE_PHRED64;
                                        else{
						dataType|=FILE_PHRED33;
						if(min > 58)
							warning_msg("Can not identified quality score type in 100 read samples, assume phred+33\n");
					}
					break;
				}
			}while(read_fastq(zfp,&item, i));
		}else
			dataType |= FILE_UNKN;
	}

	gzclose(zfp);
	free_read(&item);
	return dataType;
}
Ejemplo n.º 19
0
    /**
       \brief Default method for complementation.

       It assumes that the compiler creates only tables with
       at most one column (0 or 1 columns).       
       Complementation of tables with more than one columns
       is transformed into a cross product of complements and/or
       difference. 

     */
    table_base * table_base::complement(func_decl* p, const table_element * func_columns) const {
        const table_signature & sig = get_signature();
        SASSERT(sig.functional_columns()==0 || func_columns!=0);
        SASSERT(sig.first_functional() <= 1);

        table_base * res = get_plugin().mk_empty(sig);

        table_fact fact;
        fact.resize(sig.first_functional());
        fact.append(sig.functional_columns(), func_columns);

        if (sig.first_functional() == 0) {
            if (empty()) {
                res->add_fact(fact);
            }
            return res;
        }

        VERIFY(sig.first_functional() == 1);

        uint64 upper_bound = get_signature()[0];
        bool empty_table = empty();

        if (upper_bound > (1 << 18)) {
            std::ostringstream buffer;
            buffer << "creating large table of size " << upper_bound;
            if (p) buffer << " for relation " << p->get_name();
            warning_msg(buffer.str().c_str());
        }

        for(table_element i = 0; i < upper_bound; i++) {
            fact[0] = i;
            if(empty_table || !contains_fact(fact)) {
                res->add_fact(fact);
            }
        }
        return res;
    }
Ejemplo n.º 20
0
int file_name(char* file_name, char* file_path)	//parse full path string and get file name
{
	struct stat buf;
	if(stat(file_path, &buf) == 0 && S_ISDIR(buf.st_mode)){
		warning_msg("This path [%s] is not contain file name.\n",file_path);
		return -1;
	}

	int i = 0;
	int lgth = strlen(file_path);
	if(lgth <= 0 )	return -1;

	for(i=lgth; i>=0; i--)
		if(file_path[i] == '/')
			break;

	int start = i+1;
	for(i=0; (start+i)<=lgth; i++)
		file_name[i] = file_path[start+i];

	file_name[i]='\0';
	return 0;
}
Ejemplo n.º 21
0
void Phreeqc::
fpunchf_user(int user_index, const char *format, double d)
{
	const char *name;
	
	if (current_user_punch == NULL)
		return;
	// check headings
	//if (user_index < user_punch_count_headings)
	int user_punch_count_headings = (int) current_user_punch->Get_headings().size();
	if (user_index < user_punch_count_headings)
	{
		//name = user_punch_headings[user_index];
		name = current_user_punch->Get_headings()[user_index].c_str();
	}
	else
	{
		if (fpunchf_user_s_warning == 0)
		{
			error_string = sformatf(
					"USER_PUNCH: Headings count does not match number of calls to PUNCH.\n");
			warning_msg(error_string);
			fpunchf_user_s_warning = 1;
		}
		sprintf(fpunchf_user_buffer, "no_heading_%d",
				(user_index - user_punch_count_headings) + 1);
		name = fpunchf_user_buffer;
	}
	try
	{
		if (phrq_io) phrq_io->fpunchf(name, format, (double) d);
	}
	catch(std::bad_alloc)
	{
		malloc_error();
	}
}
Ejemplo n.º 22
0
 void context::check_sorts(ast * n) {
     if (!m().check_sorts(n)) {
         switch(n->get_kind()) {
         case AST_APP: {
             std::ostringstream buffer;
             app * a = to_app(n);
             buffer << mk_pp(a->get_decl(), m()) << " applied to: ";
             if (a->get_num_args() > 1) buffer << "\n";
             for (unsigned i = 0; i < a->get_num_args(); ++i) {
                 buffer << mk_bounded_pp(a->get_arg(i), m(), 3) << " of sort ";
                 buffer << mk_pp(m().get_sort(a->get_arg(i)), m()) << "\n";
             }
             warning_msg("%s",buffer.str().c_str());
             break;
         }
         case AST_VAR:
         case AST_QUANTIFIER:
         case AST_SORT:
         case AST_FUNC_DECL:
             break;
         }
         set_error_code(Z3_SORT_ERROR);
     }
 }
Ejemplo n.º 23
0
 Z3_sort Z3_API Z3_get_relation_column(Z3_context c, Z3_sort s, unsigned col) {
     Z3_TRY;
     LOG_Z3_get_relation_column(c, s, col);
     RESET_ERROR_CODE();
     sort * r = to_sort(s);
     if (Z3_get_sort_kind(c, s) != Z3_RELATION_SORT) {
         SET_ERROR_CODE(Z3_INVALID_ARG);
         RETURN_Z3(0);
     }
     if (col >= r->get_num_parameters()) {
         SET_ERROR_CODE(Z3_IOB);
         RETURN_Z3(0);
     }
     parameter const& p = r->get_parameter(col);
     if (!p.is_ast() || !is_sort(p.get_ast())) {
         UNREACHABLE();
         warning_msg("Sort parameter expected at %d", col);
         SET_ERROR_CODE(Z3_INTERNAL_FATAL);
         RETURN_Z3(0);
     }
     Z3_sort res = of_sort(to_sort(p.get_ast()));
     RETURN_Z3(res);
     Z3_CATCH_RETURN(0);
 }
Ejemplo n.º 24
0
/* ---------------------------------------------------------------------- */
PHRQ_io::LINE_TYPE PHRQ_io::
get_line(void)
/* ---------------------------------------------------------------------- */
{
/*
 *   Read a line from input file put in "line".
 *   Copy of input line is stored in "line_save".
 *   Characters after # are discarded in line but retained in "line_save"
 *
 *   Arguments:
 *      fp is file name
 *   Returns:
 *      EMPTY,
 *      EOF,
 *      KEYWORD,
 *      OK,
 *      OPTION
 */
	std::string stdtoken;
	bool continue_loop = true;;

	PHRQ_io::LINE_TYPE return_value;
	// loop for include files
	for (;;)
	{
		if (this->get_istream() == NULL)
		{
			break;
		}
		return_value = LT_EMPTY;
		while (return_value == LT_EMPTY)
		{
			/*
			*   Eliminate all characters after # sign as a comment
			*/
			/*
			*   Get line, check for eof
			*/
			continue_loop = false;

			if (get_logical_line() == LT_EOF)
			{
				//pop next file
				this->pop_istream();
				continue_loop = true;
				break;
			}
			/*
			*   Get long lines
			*/
			bool empty = true;
			m_line = m_line_save.substr(0, m_line_save.find_first_of('#'));
			for (unsigned int i = 0; i < m_line.size(); ++i)
			{
				if (!::isspace(m_line[i]))
				{
					empty = false;
					break;
				}
			}

			if (this->accumulate)
			{
				this->accumulated.append(m_line_save);
				this->accumulated.append("\n");
			}
			//
			// New line character encountered
			//
			return_value = (empty ? LT_EMPTY : LT_OK);

		}
		if (continue_loop) continue;
		//
		// Determine return_value
		//
		if (return_value == LT_OK)
		{
			if (check_key(m_line.begin(), m_line.end()))
			{
				return_value = LT_KEYWORD;
			}
			else
			{
				std::string::iterator beg = m_line.begin();
				std::string::iterator end = m_line.end();
				std::string token;
				CParser::copy_token(token, beg, end);

				if (token.size() > 1 && token[0] == '-' &&::isalpha(token[1]))
				{
					return_value = LT_OPTION;
				}
			}
		}

		// add new include file to stack
		std::string::iterator beg = m_line.begin();
		std::string::iterator end = m_line.end();
		CParser::copy_token(stdtoken, beg, end);
		std::transform(stdtoken.begin(), stdtoken.end(), stdtoken.begin(), ::tolower);
		if ((strstr(stdtoken.c_str(),"include$") == stdtoken.c_str()) ||
			(strstr(stdtoken.c_str(),"include_file") == stdtoken.c_str()))
		{
			std::string file_name;
			file_name.assign(beg, end);
			file_name = trim(file_name);

			if (file_name.size() > 0)
			{
				std::ifstream *next_stream = new std::ifstream(file_name.c_str(), std::ios_base::in);
				if (!next_stream->is_open())
				{
					std::ostringstream errstr;
					errstr << "\n***********  Could not open include file " << file_name
						   <<".\n             Please, write the full path to this file. ***********\n\n";
					delete next_stream;
#if defined(PHREEQCI_GUI)
					warning_msg(errstr.str().c_str());
					continue;
#else
					output_msg(errstr.str().c_str());
					error_msg(errstr.str().c_str(), OT_STOP);
#endif
				}
				else
				{
					this->push_istream(next_stream);
					std::ostringstream errstr;
					errstr << "\n\tReading data from " << file_name <<" ...\n";
					output_msg(errstr.str().c_str()); // **appt
				}
				continue;
			}
		}
		return return_value;
	}
	m_next_keyword = Keywords::KEY_END;
	return LT_EOF;
}
Ejemplo n.º 25
0
void parse_cmd_line_args(int argc, char ** argv) {
    int i = 1;
    char * eq_pos = 0;
    while (i < argc) {
        char * arg = argv[i];

        if (arg[0] == '-' && arg[1] == '-' && arg[2] == 0) {
            // Little hack used to read files with strange names such as -foo.smt2
            // z3 -- -foo.smt2
            i++;
            g_aux_input_file = "";
            for (; i < argc; i++) {
                g_aux_input_file += argv[i];
                if (i < argc - 1)
                    g_aux_input_file += " ";
            }
            if (g_input_file) {
                warning_msg("input file was already specified.");
            }
            else {
                g_input_file = g_aux_input_file.c_str();
            }
            break;
        }

        if (arg[0] == '-'
#ifdef _WINDOWS
            || arg[0] == '/'
#endif
            ) {
            char * opt_name = arg + 1;
            // allow names such as --help
            if (*opt_name == '-')
                opt_name++;
            char * opt_arg  = 0;
            char * colon    = strchr(arg, ':');
            if (colon) {
                opt_arg = colon + 1;
                *colon  = 0;
            }
            if (strcmp(opt_name, "h") == 0 || strcmp(opt_name, "?") == 0 || strcmp(opt_name, "help") == 0) {
                display_usage();
                exit(0);
            }
            if (strcmp(opt_name, "version") == 0) {
                std::cout << "Z3 version " << Z3_MAJOR_VERSION << "." << Z3_MINOR_VERSION << "." << Z3_BUILD_NUMBER << "\n";
                exit(0);
            }
            else if (strcmp(opt_name, "smt") == 0) {
                g_input_kind = IN_SMTLIB;
            }
            else if (strcmp(opt_name, "smt2") == 0) {
                g_input_kind = IN_SMTLIB_2;
            }
            else if (strcmp(opt_name, "in") == 0) {
                g_standard_input = true;
            }
            else if (strcmp(opt_name, "dimacs") == 0) {
                g_input_kind = IN_DIMACS;
            }
            else if (strcmp(opt_name, "log") == 0) {
                g_input_kind = IN_Z3_LOG;
            }
            else if (strcmp(opt_name, "st") == 0) {
                g_display_statistics = true;
            }
            else if (strcmp(opt_name, "ist") == 0) {
                g_display_istatistics = true;
            }
            else if (strcmp(opt_name, "v") == 0) {
                if (!opt_arg)
                    error("option argument (-v:level) is missing.");
                long lvl = strtol(opt_arg, 0, 10);
                set_verbosity_level(lvl);
            }
            else if (strcmp(opt_name, "file") == 0) {
                g_input_file = opt_arg;
            }
            else if (strcmp(opt_name, "T") == 0) {
                if (!opt_arg)
                    error("option argument (-T:timeout) is missing.");
                long tm = strtol(opt_arg, 0, 10);
                set_timeout(tm * 1000);
            }
            else if (strcmp(opt_name, "t") == 0) {
                if (!opt_arg)
                    error("option argument (-t:timeout) is missing.");
                gparams::set("timeout", opt_arg);
            }
            else if (strcmp(opt_name, "nw") == 0) {
                enable_warning_messages(false);
            }
            else if (strcmp(opt_name, "p") == 0) {
                gparams::display(std::cout, 0, false, false);
                exit(0);
            }
            else if (strcmp(opt_name, "pd") == 0) {
                gparams::display(std::cout, 0, false, true);
                exit(0);
            }
            else if (strcmp(opt_name, "pm") == 0) {
                if (opt_arg) {
                    gparams::display_module(std::cout, opt_arg);
                }
                else {
                    gparams::display_modules(std::cout);
                    std::cout << "\nUse -pm:name to display all parameters available at module 'name'\n";
                }
                exit(0);
            }
            else if (strcmp(opt_name, "pp") == 0) {
                if (!opt_arg)
                    error("option argument (-pp:name) is missing.");
                gparams::display_parameter(std::cout, opt_arg);
                exit(0);
            }
#ifdef _TRACE
            else if (strcmp(opt_name, "tr") == 0) {
                if (!opt_arg)
                    error("option argument (-tr:tag) is missing.");
                enable_trace(opt_arg);
            }
#endif
#ifdef Z3DEBUG
            else if (strcmp(opt_name, "dbg") == 0) {
                if (!opt_arg)
                    error("option argument (-dbg:tag) is missing.");
                enable_debug(opt_arg);
            }
#endif
            else if (strcmp(opt_name, "memory") == 0) {
                if (!opt_arg)
                    error("option argument (-memory:val) is missing.");
                gparams::set("memory_max_size", opt_arg);
            }
            else {
                std::cerr << "Error: invalid command line option: " << arg << "\n";
                std::cerr << "For usage information: z3 -h\n";
                exit(ERR_CMD_LINE);
            }
        }
        else if (argv[i][0] != '"' && (eq_pos = strchr(argv[i], '='))) {
            char * key   = argv[i];
            *eq_pos      = 0;
            char * value = eq_pos+1;
            gparams::set(key, value);
        }
        else {
            if (g_input_file) {
                warning_msg("input file was already specified.");
            }
            else {
                g_input_file = arg;
            }
        }
        i++;
    }
}
Ejemplo n.º 26
0
//=============================================================================
void Metaserver::HandleServerShake(SA *pcliaddr, const ServerShakeMsg &msg)
{
  int                       active;
  unsigned int              handshake;
  list<Handshake>::iterator i;
  char                     *presentation;
  SAIN                     *sa;
  Handshake                 search_for;

  sa = (SAIN *)pcliaddr;
  handshake = msg.GetHandshake();
  search_for.SetValues(sa->sin_addr.s_addr, handshake, 0);
  i = FindByHS(mServerHandshakes.begin(), mServerHandshakes.end(), 
	       search_for);
  if(i != mServerHandshakes.end())
  {
#ifdef DEBUG
    presentation = sock_ntop(pcliaddr, sizeof(SA));
    debug_msg("Received valid server handshake from %s", 
	      PolishedPresentation(presentation));
#endif
    mServerHandshakes.erase(i);
    i = FindByAddr(mActiveServers.begin(), mActiveServers.end(), 
		   search_for);
    if(i == mActiveServers.end())
    {
      search_for.SetValues(sa->sin_addr.s_addr, 0, time(NULL));
      mActiveServers.push_back(search_for);

      if(mExecute[0] != '\0') {
        int res = system(mExecute);
        if (res == -1) {
          err_sys("fork");
        } else {
          int status = WEXITSTATUS(res);
          if (status != 0) {
            warning_msg("error running %s: %d", mExecute, status);
          }
        }
      }

      if((active = mActiveServers.size()) > mPeakActiveServers)
	mPeakActiveServers = active;
#ifdef DEBUG
      presentation = sock_ntop(pcliaddr, sizeof(SA));
      debug_msg("Added new active server at %s",
		PolishedPresentation(presentation));
#endif
    }
    else
    {
      (*i).SetTimestamp(time(NULL));
#ifdef DEBUG
      presentation = sock_ntop(pcliaddr, sizeof(SA));
      debug_msg("Updated existing active server at %s",
		PolishedPresentation(presentation));
#endif
    }
  }
  else
  {
    presentation = sock_ntop(pcliaddr, sizeof(SA));
    warning_msg("Bogus SERVERSHAKE packet received from: %s", 
		PolishedPresentation(presentation));
  }
}
Ejemplo n.º 27
0
Archivo: step.c Proyecto: AkaBlood/ogs5
/* ---------------------------------------------------------------------- */
int
s_s_assemblage_check (struct s_s_assemblage *s_s_assemblage_ptr)
/* ---------------------------------------------------------------------- */
{
/*
 *   Check for missing elements
 */
  int i, j, k, l;
  struct master *master_ptr;

  if (s_s_assemblage_ptr == NULL)
    return (OK);
/*
 *   Check that all elements are in solution for phases with zero mass
 */
  for (i = 0; i < s_s_assemblage_ptr->count_s_s; i++)
  {
    for (j = 0; j < s_s_assemblage_ptr->s_s[i].count_comps; j++)
    {
      count_elts = 0;
      paren_count = 0;
      if (s_s_assemblage_ptr->s_s[i].comps[j].moles <= 0.0)
      {
	add_elt_list (s_s_assemblage_ptr->s_s[i].comps[j].phase->next_elt,
		      1.0);
	for (l = 0; l < count_elts; l++)
	{
	  master_ptr = elt_list[l].elt->primary;
	  if (master_ptr->s == s_hplus)
	  {
	    continue;
	  }
	  else if (master_ptr->s == s_h2o)
	  {
	    continue;
	  }
	  else if (master_ptr->total > MIN_TOTAL_SS)
	  {
	    continue;
	  }
	  else
	  {
	    if (state != ADVECTION && state != TRANSPORT && state != PHAST)
	    {
	      sprintf (error_string,
		       "Element %s is contained in solid solution %s (which has 0.0 mass),\nbut is not in solution or other phases.",
		       elt_list[l].elt->name,
		       s_s_assemblage_ptr->s_s[i].comps[j].phase->name);
	      warning_msg (error_string);
	    }
	  }
	  /*
	   *   Make la's of all master species for the element small, 
	   *   so SI will be small
	   *   and no mass transfer will be calculated
	   */
	  for (k = 0; k < count_master; k++)
	  {
	    if (master[k]->elt->primary == master_ptr)
	    {
	      master[k]->s->la = -9999.999;
	    }
	  }
	}
      }
    }
  }
  return (OK);
}
Ejemplo n.º 28
0
Archivo: step.c Proyecto: AkaBlood/ogs5
/* ---------------------------------------------------------------------- */
int
pp_assemblage_check (struct pp_assemblage *pp_assemblage_ptr)
/* ---------------------------------------------------------------------- */
{
/*
 *   Check for missing elements
 */
  int i, j, k;
  char token[MAX_LENGTH];
  char *ptr;
  struct pure_phase *pure_phase_ptr;
  struct master *master_ptr;

  if (check_pp_assemblage (pp_assemblage_ptr) == OK)
    return (OK);
/*
 *   Check that all elements are in solution for phases with zero mass
 */
  pure_phase_ptr = pp_assemblage_ptr->pure_phases;
  for (j = 0; j < pp_assemblage_ptr->count_comps; j++)
  {
    count_elts = 0;
    paren_count = 0;
    if (pure_phase_ptr[j].moles <= 0.0)
    {
      pure_phase_ptr[j].delta = 0.0;
      if (pure_phase_ptr[j].add_formula != NULL)
      {
	strcpy (token, pure_phase_ptr[j].add_formula);
	ptr = &(token[0]);
	get_elts_in_species (&ptr, 1.0);
      }
      else
      {
	strcpy (token, pure_phase_ptr[j].phase->formula);
	add_elt_list (pure_phase_ptr[j].phase->next_elt, 1.0);
      }
      for (i = 0; i < count_elts; i++)
      {
	master_ptr = elt_list[i].elt->primary;
	if (master_ptr->s == s_hplus)
	{
	  continue;
	}
	else if (master_ptr->s == s_h2o)
	{
	  continue;
	}
	else if (master_ptr->total > MIN_TOTAL)
	{
	  continue;
	}
	else
	{
	  if (state != ADVECTION && state != TRANSPORT && state != PHAST)
	  {
	    sprintf (error_string,
		     "Element %s is contained in %s (which has 0.0 mass),"
		     "\t\nbut is not in solution or other phases.",
		     elt_list[i].elt->name, pure_phase_ptr[j].phase->name);
	    warning_msg (error_string);
	  }
/*
 *   Make la's of all master species for the element small, so SI will be small
 *   and no mass transfer will be calculated
 */
	  for (k = 0; k < count_master; k++)
	  {
	    if (master[k]->elt->primary == master_ptr)
	    {
	      master[k]->s->la = -9999.999;
	    }
	  }
	}
      }
    }
  }
  return (OK);
}
Ejemplo n.º 29
0
void c_typecheck_baset::typecheck_redefinition_non_type(
  symbolt &old_symbol,
  symbolt &new_symbol)
{
  const typet &final_old=follow(old_symbol.type);
  const typet &initial_new=follow(new_symbol.type);

  if(final_old.id()==ID_array &&
     to_array_type(final_old).size().is_not_nil() &&
     initial_new.id()==ID_array &&
     to_array_type(initial_new).size().is_nil() &&
     final_old.subtype()==initial_new.subtype())
  {
    // this is ok, just use old type
    new_symbol.type=old_symbol.type;
  }

  // do initializer, this may change the type
  if(follow(new_symbol.type).id()!=ID_code)
    do_initializer(new_symbol);
  
  const typet &final_new=follow(new_symbol.type);
  
  // K&R stuff?
  if(old_symbol.type.id()==ID_KnR)
  {
    // check the type
    if(final_new.id()==ID_code)
    {
      err_location(new_symbol.location);
      throw "function type not allowed for K&R function parameter";
    }
    
    // fix up old symbol -- we now got the type
    old_symbol.type=new_symbol.type;
    return;
  }
  
  if(final_new.id()==ID_code)
  {
    bool inlined=
       (new_symbol.type.get_bool(ID_C_inlined) ||
        old_symbol.type.get_bool(ID_C_inlined));
        
    if(final_old.id()!=ID_code)
    {
      err_location(new_symbol.location);
      str << "error: function symbol `" << new_symbol.display_name()
          << "' redefined with a different type:" << "\n";
      str << "Original: " << to_string(old_symbol.type) << "\n";
      str << "     New: " << to_string(new_symbol.type);
      throw 0;
    }

    code_typet &old_ct=to_code_type(old_symbol.type);
    code_typet &new_ct=to_code_type(new_symbol.type);
    
    if(old_ct.has_ellipsis() && !new_ct.has_ellipsis())
      old_ct=new_ct;
    else if(!old_ct.has_ellipsis() && new_ct.has_ellipsis())
      new_ct=old_ct;

    if(inlined)
    {
      old_symbol.type.set(ID_C_inlined, true);
      new_symbol.type.set(ID_C_inlined, true);
    }

    // do body
    
    if(new_symbol.value.is_not_nil())
    {  
      if(old_symbol.value.is_not_nil())
      {
        // gcc allows re-definition if the first
        // definition is marked as "extern inline"
        
        if(old_symbol.type.get_bool(ID_C_inlined) &&
           (config.ansi_c.mode==configt::ansi_ct::flavourt::MODE_GCC_C ||
            config.ansi_c.mode==configt::ansi_ct::flavourt::MODE_ARM_C_CPP))
        {
          // overwrite "extern inline" properties
          old_symbol.is_extern=new_symbol.is_extern;
          old_symbol.is_file_local=new_symbol.is_file_local;

          // remove parameter declarations to avoid conflicts
          const code_typet::parameterst &old_p=old_ct.parameters();
          for(code_typet::parameterst::const_iterator
              p_it=old_p.begin();
              p_it!=old_p.end();
              p_it++)
          {
            const irep_idt &identifier=p_it->get_identifier();

            symbol_tablet::symbolst::iterator p_s_it=
              symbol_table.symbols.find(identifier);
            if(p_s_it!=symbol_table.symbols.end())
              symbol_table.symbols.erase(p_s_it);
          }
        }
        else
        {
          err_location(new_symbol.location);
          str << "function body `" << new_symbol.display_name()
              << "' defined twice";
          error_msg();
          throw 0;
        }
      }
      else if(inlined)
      {
        // preserve "extern inline" properties
        old_symbol.is_extern=new_symbol.is_extern;
        old_symbol.is_file_local=new_symbol.is_file_local;
      }

      typecheck_function_body(new_symbol);
    
      // overwrite location
      old_symbol.location=new_symbol.location;
    
      // move body
      old_symbol.value.swap(new_symbol.value);

      // overwrite type (because of parameter names)
      old_symbol.type=new_symbol.type;
    }

    return;
  }

  if(final_old!=final_new)
  {
    if(final_old.id()==ID_array &&
            to_array_type(final_old).size().is_nil() &&
            final_new.id()==ID_array &&
            to_array_type(final_new).size().is_not_nil() &&
            final_old.subtype()==final_new.subtype())
    {
      // this is also ok
      if(old_symbol.type.id()==ID_symbol)
      {
        // fix the symbol, not just the type
        const irep_idt identifier=
          to_symbol_type(old_symbol.type).get_identifier();

        symbol_tablet::symbolst::iterator s_it=symbol_table.symbols.find(identifier);
  
        if(s_it==symbol_table.symbols.end())
        {
          err_location(old_symbol.location);
          str << "typecheck_redefinition_non_type: "
                 "failed to find symbol `" << identifier << "'";
          throw 0;
        }
                  
        symbolt &symbol=s_it->second;
          
        symbol.type=final_new;          
      }
      else
        old_symbol.type=new_symbol.type;
    }
    else if((final_old.id()==ID_incomplete_c_enum ||
             final_old.id()==ID_c_enum) &&
            (final_new.id()==ID_incomplete_c_enum ||
             final_new.id()==ID_c_enum))
    {
      // this is ok for now
    }
    else if(final_old.id()==ID_pointer &&
            follow(final_old).subtype().id()==ID_code &&
            to_code_type(follow(final_old).subtype()).has_ellipsis() &&
            final_new.id()==ID_pointer &&
            follow(final_new).subtype().id()==ID_code)
    {
      // to allow 
      // int (*f) ();
      // int (*f) (int)=0;
      old_symbol.type=new_symbol.type;
    }
    else if(final_old.id()==ID_pointer &&
            follow(final_old).subtype().id()==ID_code &&
            final_new.id()==ID_pointer &&
            follow(final_new).subtype().id()==ID_code &&
            to_code_type(follow(final_new).subtype()).has_ellipsis())
    {
      // to allow 
      // int (*f) (int)=0;
      // int (*f) ();
    }
    else
    {
      err_location(new_symbol.location);
      str << "error: symbol `" << new_symbol.display_name()
          << "' redefined with a different type:" << "\n";
      str << "Original: " << to_string(old_symbol.type) << "\n";
      str << "     New: " << to_string(new_symbol.type);
      throw 0;
    }
  }
  else // finals are equal
  {
  }

  // do value
  if(new_symbol.value.is_not_nil())
  {
    // see if we already have one
    if(old_symbol.value.is_not_nil())
    {
      if(new_symbol.value.get_bool(ID_C_zero_initializer))
      {
        // do nothing
      }
      else if(old_symbol.value.get_bool(ID_C_zero_initializer))
      {
        old_symbol.value=new_symbol.value;
        old_symbol.type=new_symbol.type;
      }
      else
      {
        if(new_symbol.is_macro &&
           (final_new.id()==ID_incomplete_c_enum ||
            final_new.id()==ID_c_enum) &&
            old_symbol.value.is_constant() &&
            new_symbol.value.is_constant() &&
            old_symbol.value.get(ID_value)==new_symbol.value.get(ID_value))
        {
          // ignore
        }
        else
        {
          err_location(new_symbol.value);
          str << "symbol `" << new_symbol.display_name()
              << "' already has an initial value";
          warning_msg();
        }
      }
    }
    else
    {
      old_symbol.value=new_symbol.value;
      old_symbol.type=new_symbol.type;
    }
  }
  
  // take care of some flags
  if(old_symbol.is_extern && !new_symbol.is_extern)
    old_symbol.location=new_symbol.location;

  old_symbol.is_extern=old_symbol.is_extern && new_symbol.is_extern;
  
  // We should likely check is_volatile and
  // is_thread_local for consistency. GCC complains if these
  // mismatch.
}
Ejemplo n.º 30
0
float cost_evaluator::eval(expr * f) const {
#define E(IDX) eval(to_app(f)->get_arg(IDX))
    if (is_app(f)) {
        unsigned num_args;
        family_id fid = to_app(f)->get_family_id();
        if (fid == m_manager.get_basic_family_id()) {
            switch (to_app(f)->get_decl_kind()) {
            case OP_TRUE:     return 1.0f;
            case OP_FALSE:    return 0.0f;
            case OP_NOT:      return E(0) == 0.0f ? 1.0f : 0.0f;
            case OP_AND:      
                num_args = to_app(f)->get_num_args();
                for (unsigned i = 0; i < num_args; i++) 
                    if (E(i) == 0.0f)
                        return 0.0f;
                return 1.0f;
            case OP_OR:
                num_args = to_app(f)->get_num_args();
                for (unsigned i = 0; i < num_args; i++) 
                    if (E(i) != 0.0f)
                        return 1.0f;
                return 0.0f;
            case OP_ITE:      return E(0) != 0.0f ? E(1) : E(2);
            case OP_EQ:
            case OP_IFF:      return E(0) == E(1) ? 1.0f : 0.0f;
            case OP_XOR:      return E(0) != E(1) ? 1.0f : 0.0f;
            case OP_IMPLIES:  
                if (E(0) == 0.0f)
                    return 1.0f;
                return E(1) != 0.0f ? 1.0f : 0.0f;
            default:
                ;
            }
        }
        else if (fid == m_util.get_family_id()) {
            switch (to_app(f)->get_decl_kind()) {
            case OP_NUM: {
                rational r = to_app(f)->get_decl()->get_parameter(0).get_rational();
                return static_cast<float>(numerator(r).get_int64())/static_cast<float>(denominator(r).get_int64());
            } 
            case OP_LE:       return E(0) <= E(1) ? 1.0f : 0.0f;
            case OP_GE:       return E(0) >= E(1) ? 1.0f : 0.0f;
            case OP_LT:       return E(0) <  E(1) ? 1.0f : 0.0f;
            case OP_GT:       return E(0) >  E(1) ? 1.0f : 0.0f;
            case OP_ADD:      return E(0) + E(1);
            case OP_SUB:      return E(0) - E(1);
            case OP_UMINUS:   return - E(0);
            case OP_MUL:      return E(0) * E(1);
            case OP_DIV: {     
                float q = E(1);
                if (q == 0.0f) {
                    warning_msg("cost function division by zero");
                    return 1.0f;
                }
                return E(0) / q;
            }
            default:
                ;
            }
        }
    }
    else if (is_var(f)) {
        unsigned idx = to_var(f)->get_idx();
        if (idx < m_num_args)
            return m_args[m_num_args - idx - 1];
    }
    warning_msg("cost function evaluation error");
    return 1.0f;
}