예제 #1
0
/*----------------------------------------------------------------------------
perl_substitute__()
The pattern substitution function which includes loading perl interpreter 
and doing the pattern substitution, then returning the replaced string.
arguments: 
  input: char* string, input text
	 char* pattern, match pattern
  output:char* string, output text
----------------------------------------------------------------------------*/
int perl_substitute__( void )
{
  SV *text;    /* Perl representation for the string to be 
		  modified by substitution */ 
  char *subst_cmd = ptoc_string(2);
  int i;                
  
  /* first load the perl interpreter, if unloaded */
  if (perlObjectStatus == UNLOADED) load_perl__();
  
  text = newSV(0);
  sv_setpv(text, ptoc_string(1));  /* put the string to the SV */
     
  if( !substitute(&text, subst_cmd) )
    return(FAILURE);
  
  global_pattern_mode = is_global_pattern(subst_cmd);

  if (substituteString != NULL ) free(substituteString);

  substituteString = malloc(strlen(SvPV(text,PL_na))+1);
  strcpy(substituteString,SvPV(text,PL_na));
  
  SvREFCNT_dec(text);  /*release space*/
  
  ctop_string(3, string_find(substituteString,1));  /*return changed text*/
  return SUCCESS;
}
예제 #2
0
파일: normalize.c 프로젝트: uwplse/arvo
term* normalize_no_unfold(typing_context* Delta, term* t) {
  if (t == NULL) return NULL;

  switch (t->tag) {
  case VAR:
    {
      return term_dup(t);
    }
  case APP:
    {
      term* l = normalize_no_unfold(Delta, t->left);
      term* r = normalize_no_unfold(Delta, t->right);
      if (l->tag == LAM) {
        term* subs = substitute(l->var, r, l->right);
        free_term(l);
        free_term(r);
        return normalize_no_unfold_and_free(Delta, subs);
      }
      return make_app(l, r);
    }
  case IMPLICIT:
  case HOLE:
  case TYPE:
  case LAM:
  case PI:
    return term_dup(t);
  default:
    sentinel("unexpected tag %d");
  }
 error:
  return NULL;
}
예제 #3
0
파일: tinexp.c 프로젝트: skout23/snowy
int find(struct session *ses, char *str, char *exp, int sub)
{
	char expbuf[BUFFER_SIZE], strbuf[BUFFER_SIZE];

	if (ses)
	{
		substitute(ses, str, strbuf, SUB_VAR|SUB_FUN);
		substitute(ses, exp, expbuf, SUB_VAR|SUB_FUN);

		return tintin_regexp(ses, NULL, strbuf, expbuf, 0, sub);
	}
	else
	{
		return tintin_regexp(ses, NULL, str, exp, 0, sub);
	}
}
예제 #4
0
파일: tinexp.c 프로젝트: skout23/snowy
int check_one_regexp(struct session *ses, struct listnode *node, char *line, char *original, int option)
{
	char *exp, *str;

	if (node->regex == NULL)
	{
		char result[BUFFER_SIZE];

		substitute(ses, node->left, result, SUB_VAR|SUB_FUN);

		exp = result;
	}
	else
	{
		exp = node->left;
	}

	if (HAS_BIT(node->flags, NODE_FLAG_META))
	{
		exp++;
		str = original;
	}
	else
	{
		str = line;
	}	

	return tintin_regexp(ses, node->regex, str, exp, option, SUB_ARG);
}
예제 #5
0
파일: cppmangle.c 프로젝트: yeswalrus/dmd
 void visit(TypeReference *t)
 {
     if (substitute(t)) return;
     buf.writeByte('R');
     t->next->accept(this);
     store(t);
 }
예제 #6
0
unsigned int
ExpressionBuilder::EBTerm::substitute(const EBSubstitutionRule & rule)
{
  EBSubstitutionRuleList rules(1);
  rules[0] = &rule;
  return substitute(rules);
}
예제 #7
0
void ConstraintMap::substAlpha() {
	ConstraintMap alphaDefs;
	std::map<Exp*, Exp*, lessExpStar>::iterator cc;
	for (cc = cmap.begin(); cc != cmap.end(); cc++) {
		// Looking for entries with two TypeVals, where exactly one is an alpha
		if (!cc->first->isTypeVal() || !cc->second->isTypeVal())
			continue;
		Type *t1, *t2;
		t1 = ((TypeVal*)cc->first )->getType();
		t2 = ((TypeVal*)cc->second)->getType();
		int numAlpha = 0;
		if (t1->isPointerToAlpha()) numAlpha++;
		if (t2->isPointerToAlpha()) numAlpha++;
		if (numAlpha != 1)
			continue;
		// This is such an equality. Copy it to alphaDefs
		if (t1->isPointerToAlpha())
			alphaDefs.cmap[cc->first] = cc->second;
		else
			alphaDefs.cmap[cc->second] = cc->first;
	}

	// Remove these from the solution
	for (cc = alphaDefs.begin(); cc != alphaDefs.end(); cc++)
		cmap.erase(cc->first);

	// Now substitute into the remainder
	substitute(alphaDefs);
}
예제 #8
0
파일: cppmangle.c 프로젝트: yeswalrus/dmd
    void prefix_name(Dsymbol *s)
    {
        if (!substitute(s))
        {
            store(s);
            Dsymbol *p = s->toParent();
            if (p && p->isTemplateInstance())
            {
                s = p;
                if (exist(p->isTemplateInstance()->tempdecl))
                {
                    p = NULL;
                }
                else
                {
                    p = p->toParent();
                }
            }

            if (p && !p->isModule())
            {
                prefix_name(p);
            }
            source_name(s);
        }
    }
예제 #9
0
void
bridge_document_rep::notify_remove (path p, int nr) {
  // cout << "Remove " << p << ", " << nr << " in " << st << "\n";
  ASSERT (!is_nil (p), "nil path");
  if (is_atom (p)) {
    int i, n= N(brs), pos= p->item;
    array<bridge> brs2 (n-nr);
    for (i=0; i<pos ; i++) brs2[i]= brs[i];
    for (; i<n-nr; i++) {
      brs2[i]= brs[i+nr];
      brs2[i]->ip->item -= nr;
    }
    bool change_flag= false;
    for (i=pos; i<pos+nr; i++)
      change_flag |= !brs[i]->changes->empty();
    brs= brs2;
    n -= nr;
    st = st (0, pos) * st (pos+nr, N(st));
    if (pos>0) brs[pos-1]->notify_change (); // touch in case of surroundings
    if (pos<n) brs[pos  ]->notify_change (); // touch in case of surroundings
    if (change_flag) // touch brs[pos..n] for correct ``changes handling''
      for (i=pos; i<n; i++)
	brs[i]->notify_change ();
    if (!is_nil (acc)) acc->notify_remove (p, nr);
    // initialize_acc ();
  }
  else {
    brs[p->item]->notify_remove (p->next, nr);
    st= substitute (st, p->item, brs[p->item]->st);
    if (!is_nil (acc)) acc->notify_assign (p->item, st[p->item]);
  }
  status= CORRUPTED;
}
예제 #10
0
void
bridge_document_rep::notify_insert (path p, tree u) {
  //cout << "Insert " << p << ", " << u << " in " << st << "\n";
  ASSERT (!is_nil (p), "nil path");
  if (is_atom (p)) {
    int i, j, n= N(brs), pos= p->item, nr= N(u);
    array<bridge> brs2 (n+nr);
    if (pos>0) brs[pos-1]->notify_change (); // touch in case of surroundings
    if (pos<n) brs[pos  ]->notify_change (); // touch in case of surroundings
    for (i=0; i<pos; i++) brs2[i]= brs[i];
    for (j=0; j<nr ; j++) brs2[i+j]= make_bridge (ttt, u[j], descend (ip,i+j));
    for (; i<n; i++) {
      brs2[i+nr]= brs[i];
      brs2[i+nr]->ip->item += nr;
    }
    brs= brs2;
    st = (st (0, p->item) * u) * st (p->item, N(st));
    if (!is_nil (acc)) acc->notify_insert (p, u);
    // initialize_acc ();
  }
  else {
    brs[p->item]->notify_insert (p->next, u);
    st= substitute (st, p->item, brs[p->item]->st);
    if (!is_nil (acc)) acc->notify_assign (p->item, st[p->item]);
  }
  status= CORRUPTED;
}
예제 #11
0
파일: cppmangle.c 프로젝트: Arpit007/GDC
    void visit(TypeFunction *t)
    {
        /*
         *  <function-type> ::= F [Y] <bare-function-type> E
         *  <bare-function-type> ::= <signature type>+
         *  # types are possible return type, then parameter types
         */

        /* ABI says:
            "The type of a non-static member function is considered to be different,
            for the purposes of substitution, from the type of a namespace-scope or
            static member function whose type appears similar. The types of two
            non-static member functions are considered to be different, for the
            purposes of substitution, if the functions are members of different
            classes. In other words, for the purposes of substitution, the class of
            which the function is a member is considered part of the type of
            function."

            BUG: Right now, types of functions are never merged, so our simplistic
            component matcher always finds them to be different.
            We should use Type::equals on these, and use different
            TypeFunctions for non-static member functions, and non-static
            member functions of different classes.
         */
        if (substitute(t))
            return;
        buf.writeByte('F');
        if (t->linkage == LINKc)
            buf.writeByte('Y');
        t->next->accept(this);
        argsCppMangle(t->parameters, t->varargs);
        buf.writeByte('E');
        store(t);
    }
예제 #12
0
void CiteDict::parse()
{
  //msg("..parsing bbl file\n");
  QCString bblFileName(m_baseFileName + ".bbl");
  QFile f(bblFileName);
  if (!f.open(IO_ReadOnly))
  {
    err("error: could not open file %s\n",bblFileName.data());
    return;
  }

  m_ordering.clear();

  QTextStream t(&f);
  QCString label;
  QCString line;
  while (!t.eof())
  {
    label=t.readLine();
    if (label.isEmpty())
    {
      continue;
    }

    CiteInfo* ci = m_entries.find(label);
    if (!ci) insert(label); 

    // BibTeX has its own way of sorting references,
    // depending on the .bst file
    m_ordering.append(new QCString(label));

    ci->text=t.readLine();

    while (!(line=t.readLine()).isEmpty())
    {
      ci->fullText += line + '\n';
    }

    // FIXME: process LaTeX-style accents properly
    ci->fullText = substitute(substitute(substitute(ci->fullText,
            "{", ""),
          "}", ""),
        "~", " ");
    
    //printf("BIB ENTRY: %s -> %s: %s\n", ci->label.data(), ci->text.data(), ci->fullText.data());
  }
}
예제 #13
0
파일: parse.c 프로젝트: skout23/snowy
struct session *parse_tintin_command(struct session *ses, char *input)
{
	char line[BUFFER_SIZE];
	struct session *sesptr;

	input = get_arg_stop_spaces(ses, input, line, 0);

	substitute(ses, line, line, SUB_VAR|SUB_FUN);

	if (is_number(line))
	{
		int cnt = atoi(line);

		input = get_arg_in_braces(ses, input, line, TRUE);

		while (cnt-- > 0)
		{
			ses = script_driver(ses, -1, line);
		}
		return ses;
	}

	for (sesptr = gts ; sesptr ; sesptr = sesptr->next)
	{
		if (!strcmp(sesptr->name, line))
		{
			if (*input)
			{
				input = get_arg_in_braces(ses, input, line, TRUE);

				substitute(ses, line, line, SUB_VAR|SUB_FUN);

				script_driver(sesptr, -1, line);

				return ses;
			}
			else
			{
				return activate_session(sesptr);
			}
		}
	}

	tintin_printf(ses, "#ERROR: #UNKNOWN TINTIN-COMMAND '%s'.", line);

	return ses;
}
예제 #14
0
파일: cppmangle.c 프로젝트: Arpit007/GDC
 void visit(TypeSArray *t)
 {
     if (substitute(t))
         return;
     buf.printf("A%llu_", t->dim ? t->dim->toInteger() : 0);
     t->next->accept(this);
     store(t);
 }
예제 #15
0
파일: cppmangle.c 프로젝트: Arpit007/GDC
 void visit(TypePointer *t)
 {
     if (substitute(t))
         return;
     buf.writeByte('P');
     t->next->accept(this);
     store(t);
 }
예제 #16
0
QString DebconfFrontend::property(const QString &key, PropertyKey p) const
{
    QString r = m_data.value(key).value(p);
    if (p == Description || p == Choices) {
        return substitute(key, r);
    }
    return r;
}
예제 #17
0
파일: cppmangle.c 프로젝트: Arpit007/GDC
 void visit(TypeVector *t)
 {
     if (substitute(t))
         return;
     buf.writestring("U8__vector");
     t->basetype->accept(this);
     store(t);
 }
예제 #18
0
ExpressionBuilder::EBTermNode * ExpressionBuilder::EBSubstitutionRuleTyped<Node_T>::apply(const ExpressionBuilder::EBTermNode * node) const
{
  const Node_T * match_node = dynamic_cast<const Node_T *>(node);
  if (match_node == NULL)
    return NULL;
  else
    return substitute(*match_node);
}
예제 #19
0
파일: ebu.hpp 프로젝트: dlevin256/kfr
    void process_packet(const T* src)
    {
        substitute(m_kfilter, to_pointer(make_univector(src, m_packet_size) * m_input_gain));
        const T filtered_sum_of_squares = sumsqr(truncate(m_kfilter, m_packet_size));

        m_short_sum_of_squares.ringbuf_write(m_short_sum_of_squares_cursor, filtered_sum_of_squares);
        m_momentary_sum_of_squares.ringbuf_write(m_momentary_sum_of_squares_cursor, filtered_sum_of_squares);
    }
예제 #20
0
 static inline
 std::string
 substitute(boost::format& message,
            const T& argument,
            const Args&... args)
 {
     return substitute(message % argument, args...);
 }
예제 #21
0
파일: lex.c 프로젝트: whitecatboard/LiteBSD
void
set_prompt(int to, Source *s)
{
	cur_prompt = (uint8_t)to;

	switch (to) {
	/* command */
	case PS1:
		/*
		 * Substitute ! and !! here, before substitutions are done
		 * so ! in expanded variables are not expanded.
		 * NOTE: this is not what AT&T ksh does (it does it after
		 * substitutions, POSIX doesn't say which is to be done.
		 */
		{
			struct shf *shf;
			char * volatile ps1;
			Area *saved_atemp;
			int saved_lineno;

			ps1 = str_val(global("PS1"));
			shf = shf_sopen(NULL, strlen(ps1) * 2,
			    SHF_WR | SHF_DYNAMIC, NULL);
			while (*ps1)
				if (*ps1 != '!' || *++ps1 == '!')
					shf_putchar(*ps1++, shf);
				else
					shf_fprintf(shf, "%lu", s ?
					    (unsigned long)s->line + 1 : 0UL);
			ps1 = shf_sclose(shf);
			saved_lineno = current_lineno;
			if (s)
				current_lineno = s->line + 1;
			saved_atemp = ATEMP;
			newenv(E_ERRH);
			if (kshsetjmp(e->jbuf)) {
				prompt = safe_prompt;
				/*
				 * Don't print an error - assume it has already
				 * been printed. Reason is we may have forked
				 * to run a command and the child may be
				 * unwinding its stack through this code as it
				 * exits.
				 */
			} else {
				char *cp = substitute(ps1, 0);
				strdupx(prompt, cp, saved_atemp);
			}
			current_lineno = saved_lineno;
			quitenv(NULL);
		}
		break;
	/* command continuation */
	case PS2:
		prompt = str_val(global("PS2"));
		break;
	}
}
QCString NamespaceDef::displayName() const
{
  QCString result=name();
  if (Config_getBool("OPTIMIZE_OUTPUT_JAVA"))
  {
    result = substitute(result,"::",".");
  }
  return result; 
}
예제 #23
0
static
inline
std::string
format(const attribute::set_view_t& attributes,
       const std::string& fmt,
       Args&&... args)
{
    return substitute(attributes, boost::format(fmt), args...);
}
예제 #24
0
int match(struct session *ses, char *str, char *exp, int flags) {
  char expbuf[BUFFER_SIZE];

  sprintf(expbuf, "^%s$", exp);

  substitute(ses, expbuf, expbuf, flags);

  return tintin_regexp(ses, NULL, str, expbuf, 0, 0);
}
예제 #25
0
// FIXME: Rebuild the variable as if parsed.
Decl&
substitute_decl(Context& cxt, Variable_decl& d, Substitution& sub)
{
  Name& n = d.name();
  Type& t = substitute(cxt, d.type(), sub);

  Builder build(cxt);
  return build.make_variable(n, t);
}
예제 #26
0
List<T>
substitute(Context& cxt, List<T>& list, Substitution& sub)
{
  List<T> ret;
  ret.reserve(list.size());
  for (T& x : list)
    ret.push_back(substitute(cxt, x, sub));
  return ret;
}
예제 #27
0
// FIXME: Rebuild the parameter as if parsed.
//
// FIXME: Do we substitute into a default argument? It probably
// depends on context, but I assume that the general answer is yes.
Decl&
substitute_decl(Context& cxt, Object_parm& d, Substitution& sub)
{
  Name& n = d.name();
  Type& t = substitute(cxt, d.type(), sub);

  Builder build(cxt);
  return build.make_object_parm(n, t);
}
예제 #28
0
main (int argc, char **argv, char **env)
{
  char *embedding[] = { "", "-e", "0" };
  char *text, **match_list;
  int num_matches, i;
  int j;
  my_perl = perl_alloc();
  perl_construct( my_perl );
  perl_parse(my_perl, NULL, 3, embedding, NULL);
  text = (char *) malloc(sizeof(char) * 486); /** A long string follows! **/
  sprintf(text, "%s", "When he is at a convenience store and the bill comes to some amount like 76 cents, Maynard is aware that there is something he *should* do, something that will enable him to get back a quarter, but he has no idea *what*.  He fumbles through his red squeezey changepurse and gives the boy three extra pennies with his dollar, hoping that he might luck into the correct amount.  The boy gives him back two of his own pennies and then the big shiny quarter that is his prize. -RICHH");
  if (match(text, "m/quarter/")) /** Does text contain 'quarter'? **/
    printf("match: Text contains the word 'quarter'.\n\n");
  else
    printf("match: Text doesn't contain the word 'quarter'.\n\n");
  if (match(text, "m/eighth/")) /** Does text contain 'eighth'? **/
    printf("match: Text contains the word 'eighth'.\n\n");
  else
    printf("match: Text doesn't contain the word 'eighth'.\n\n");
  /** Match all occurrences of /wi../ **/
  num_matches = matches(text, "m/(wi..)/g", &match_list);
  printf("matches: m/(wi..)/g found %d matches...\n", num_matches);
  for (i = 0; i < num_matches; i++)
    printf("match: %s\n", match_list[i]);
  printf("\n");
  for (i = 0; i < num_matches; i++) {
    free(match_list[i]);
  }
  free(match_list);
  /** Remove all vowels from text **/
  num_matches = substitute(&text, "s/[aeiou]//gi");
  if (num_matches) {
    printf("substitute: s/[aeiou]//gi...%d substitutions made.\n",
	   num_matches);
    printf("Now text is: %s\n\n", text);
  }
  /** Attempt a substitution **/
  if (!substitute(&text, "s/Perl/C/")) {
    printf("substitute: s/Perl/C...No substitution made.\n\n");
  }
  free(text);
  perl_destruct(my_perl);
  perl_free(my_perl);
}
예제 #29
0
static bool matchExcludedSymbols(const char *name)
{
  static QStrList &exclSyms = Config_getList("EXCLUDE_SYMBOLS");
  if (exclSyms.count()==0) return FALSE; // nothing specified
  const char *pat = exclSyms.first();
  QCString symName = name;
  while (pat)
  {
    QCString pattern = pat;
    bool forceStart=FALSE;
    bool forceEnd=FALSE;
    if (pattern.at(0)=='^') 
      pattern=pattern.mid(1),forceStart=TRUE;
    if (pattern.at(pattern.length()-1)=='$') 
      pattern=pattern.left(pattern.length()-1),forceEnd=TRUE;
    if (pattern.find('*')!=-1) // wildcard mode
    {
      QRegExp re(substitute(pattern,"*",".*"),TRUE);
      int i,pl;
      i = re.match(symName,0,&pl);
      //printf("  %d = re.match(%s) pattern=%s\n",i,symName.data(),pattern.data());
      if (i!=-1) // wildcard match
      {
        int sl=symName.length();
        // check if it is a whole word match
        if ((i==0     || pattern.at(0)=='*'    || (!isId(symName.at(i-1))  && !forceStart)) &&
            (i+pl==sl || pattern.at(i+pl)=='*' || (!isId(symName.at(i+pl)) && !forceEnd))
           )
        {
          //printf("--> name=%s pattern=%s match at %d\n",symName.data(),pattern.data(),i);
          return TRUE;
        }
      }
    }
    else if (!pattern.isEmpty()) // match words
    {
      int i = symName.find(pattern);
      if (i!=-1) // we have a match!
      {
        int pl=pattern.length();
        int sl=symName.length();
        // check if it is a whole word match
        if ((i==0     || (!isId(symName.at(i-1))  && !forceStart)) &&
            (i+pl==sl || (!isId(symName.at(i+pl)) && !forceEnd))
           )
        {
          //printf("--> name=%s pattern=%s match at %d\n",symName.data(),pattern.data(),i);
          return TRUE; 
        }
      }
    }
    pat = exclSyms.next();
  }
  //printf("--> name=%s: no match\n",name);
  return FALSE;
}
예제 #30
0
void LSystem::next()
{
	std::vector<Symbol> new_state;
	for( int i = 0; i < state.size() ; i++)
	{
		substitute(state[i],new_state);
	}
	state = new_state;
	iteration++;
}