Esempio n. 1
0
ParseExp::Result ParseExp::ParseItemType(POETCode* input, int *p_lineno)
   {
      POETCode* res = 0, *tail=0;
      if ( get_head(input) == lp) {
           Result resOfRest = ParseExpImpl(NextToken(input),exp_bop->get_entry().get_code(),0, p_lineno);
           if (get_head(resOfRest.second) == rp) {
                 input = NextToken(resOfRest.second);
                 res = resOfRest.first;
           }
           else return Result(0,input);
      }
      else if (match_expItem(input)) {
          try {
           res = parse_AST(input, exp_item->get_entry().get_code(), &tail);
           assert(res != 0);
           input=SkipEmpty(tail, p_lineno);
          }
          catch (ParseError err) { 
                   if (backtrack) return Result(0,input); 
                   throw err;
             }
      }
      else return Result(0,input);
     if (funcall->get_entry().get_code() != 0 && get_head(input) == lp)
     {
        CodeVar* fvar = dynamic_cast<CodeVar*>(funcall->get_entry().get_code());
        if (fvar == 0) INCORRECT_CVAR(funcall->get_entry().get_code());
        Result resOfTail = ParseExpImpl(NextToken(input),exp_bop->get_entry().get_code(),0, p_lineno);
        std::vector<POETCode*> argVec; 
        while (resOfTail.first!=0 && (get_head(resOfTail.second) != rp)) {
              argVec.push_back(resOfTail.first);
              resOfTail=ParseExpImpl(NextToken(resOfTail.second),exp_bop->get_entry().get_code(),0, p_lineno);
        }
        argVec.push_back(resOfTail.first);
        POETCode* args = Vector2List(argVec);
        if (args == 0) args = EMPTY;
        return Result(CODE_REF(fvar,PAIR(res,args)),
                      NextToken(resOfTail.second));
     }
     else if (arrref->get_entry().get_code() != 0 && get_head(input) == lb )
     {
        CodeVar* fvar = dynamic_cast<CodeVar*>(arrref->get_entry().get_code());
        if (fvar == 0) INCORRECT_CVAR(arrref->get_entry().get_code());
        std::vector<POETCode*> argVec; 
        while (get_head(input) == lb) 
        {
          Result resOfTail = ParseExpImpl(NextToken(input),exp_bop->get_entry().get_code(),0, p_lineno);
          if (resOfTail.first==0 || get_head(resOfTail.second) != rb) 
              return Result(res,input);
          argVec.push_back(resOfTail.first);
          input = NextToken(resOfTail.second);
        }
        POETCode* args = Vector2List(argVec);
        if (args == 0) args = EMPTY;
        return Result(CODE_REF(fvar,PAIR(res,args)),input);
     }
     return Result(res, input);
  }
Esempio n. 2
0
File: n5.c Progetto: aksr/heirloom
void
caserd(void)
{

	lgf++;
	skip(0);
	getname();
	if (!iflg) {
		if (quiet) {
#ifdef	NROFF
			echo_off();
			flusho();
#endif	/* NROFF */
			fdprintf(stderr, "\007"); /*bell*/
		} else {
			if (nextf[0]) {
				fdprintf(stderr, "%s:", nextf);
			} else {
				fdprintf(stderr, "\007"); /*bell*/
			}
		}
	}
	collect();
	tty++;
	pushi(-1, PAIR('r','d'), 0);
}
Esempio n. 3
0
 ///function to insert shuffled values one by one into the Map
 void insert_random() {
     long i = 0;
     while ( i < n ) {
         hashmap.insert ( PAIR ( data[i], 2 * data[i] ) );
         i++;
     }
 }
Esempio n. 4
0
		void Begin( const TCHAR* name )
		{
			PROFILE_CONTAINOER::iterator it = m_ProfileContainer.find( name );
			if ( it != m_ProfileContainer.end() )
			{	
				stPROFILE_SAMPLE& sample = it->second;
				unsigned long ulCurTick = GetTickCount();
				unsigned long ulDeltaTick = ulCurTick - sample.ulEndTick;

				sample.ulCount++;
				if ( sample.ulMax < ulDeltaTick )
					sample.ulMax = ulDeltaTick;

				if ( sample.ulMin > ulDeltaTick )
					sample.ulMin = ulDeltaTick;

				sample.ulEndTick = ulCurTick;
			}
			else
			{
				unsigned long ulTick = GetTickCount();
				PROFILE_SAMPLE sample;
				sample.ulCount++;
				sample.ulMax = ulTick;
				sample.ulMin = ulTick;
				sample.ulAvg = 0;
				sample.ulFirstTick = ulTick;
				m_ProfileContainer.insert( PAIR( name , sample ) );
			}
		}
Esempio n. 5
0
 void insert_random() {
     long i = 0;
     while ( i < n ) {
         //cout << "Inserting = " << data[i] <<  endl;
         hashTable[data[i] % s].insert ( PAIR ( data[i], 2 * data[i] ) );
         i++;
     }
 }
Esempio n. 6
0
GxsFeedItem *GxsFeedWidget::findGxsFeedItem(const RsGxsGroupId &groupId, const RsGxsMessageId &messageId)
{
	QMap<QPair<RsGxsGroupId, RsGxsMessageId>, FeedItem*>::iterator it = mGxsItems.find(PAIR(groupId, messageId));
	if (it == mGxsItems.end()) {
		return NULL;
	}

	return dynamic_cast<GxsFeedItem*>(it.value());
}
Esempio n. 7
0
int main(int argc, char** argv)
{
    // initializing a const reference means first
    // implicit type conversion to a PAIR
    // the resulting value is placed in a temporary variable
    // of type PAIR.  and that variable is passed to
    // the initializer of the reference.  
    //
    // however, here the comma operator takes effect
    // so hello is discarded, world is passed as the first 
    // argument and the second argument defaults to 
    // goodbye
    const PAIR& pair1("hello", "world");

    // the above is the same as this:
    const PAIR& pair2 = ("hello", "world");
    
    // and the comma operator is used, 
    // so the above is the same as this:
    const PAIR& pair3 = "world";

    // the difference between pair1 and pair2 and pair3
    // is that if the PAIR constructor were declared explicit
    // then the compiler would complain about pair2 and pair3
    // but not about pair1.  

    // on the other hand, this works
    const PAIR& pair4 = PAIR("hello", "world");

    // as does this
    PAIR temp = PAIR("hello", "world");
    const PAIR& pair5 = temp;

    // prints "world goodbye"
    cout << pair1._a << " " << pair1._b << endl;
    cout << pair2._a << " " << pair2._b << endl;
    cout << pair3._a << " " << pair2._b << endl;
    // prints "hello world"
    cout << pair4._a << " " << pair4._b << endl;
    cout << pair5._a << " " << pair4._b << endl;

    return 0;
}
Esempio n. 8
0
File: n1.c Progetto: 99years/plan9
int getrq(void)
{
	int i, j;

	if ((i = getach()) == 0 || (j = getach()) == 0)
		goto rtn;
	i = PAIR(i, j);
rtn:
	return(i);
}
Esempio n. 9
0
void GxsFeedWidget::feedAdded(FeedItem *feedItem, QTreeWidgetItem *treeItem)
{
	RSFeedWidget::feedAdded(feedItem, treeItem);

	GxsFeedItem *gxsFeedItem = dynamic_cast<GxsFeedItem*>(feedItem);
	if (!gxsFeedItem) {
		return;
	}

	mGxsItems.insert(PAIR(gxsFeedItem->groupId(), gxsFeedItem->messageId()), feedItem);
}
Esempio n. 10
0
void GxsFeedWidget::feedRemoved(FeedItem *feedItem)
{
	RSFeedWidget::feedRemoved(feedItem);

	GxsFeedItem *gxsFeedItem = dynamic_cast<GxsFeedItem*>(feedItem);
	if (!gxsFeedItem) {
		return;
	}

	mGxsItems.remove(PAIR(gxsFeedItem->groupId(), gxsFeedItem->messageId()));
}
Esempio n. 11
0
const char *strttype(int ttype)
{
	static const struct pair ttype_pairs[] = {
		PAIR(TPASS)
		PAIR(TFAIL)
		PAIR(TBROK)
		PAIR(TCONF)
		PAIR(TWARN)
		PAIR(TINFO)
	};

	PAIR_LOOKUP(ttype_pairs, TTYPE_RESULT(ttype));
}
Esempio n. 12
0
POETCode* ROSE_2_POET_list(PtrList& l, POETCode* res, 
                           SgTemplateInstantiationFunctionDecl* tmp)
{
static POETCode* tmpPars=0;
    if (l.size() == 1) { /* return the only element inside the list */
      return POETAstInterface::Ast2POET(*l.begin()); 
    }
    typename PtrList::const_reverse_iterator p = l.rbegin(); 
    if (p == l.rend()) return (res==0)? EMPTY : res;

    SgNode* prev2 = (SgNode*)*p;
    POETCode* prev = POETAstInterface::Ast2POET(prev2);
    for (++p; p != l.rend(); ++p) {
       SgNode* cur = (SgNode*)*p;
       SgPragmaDeclaration* info = isSgPragmaDeclaration(cur);
       if (info!=0) { /* replace template parameters in pragma */
           POETAstInterface::set_Ast2POET(prev2, EMPTY);
           std::string pragma_str = info->get_pragma()->get_pragma();
           POETCode *content=STRING(pragma_str);
           POETCode* tokens = split_string("",content);
           if (tmp == 0) tmpPars = 0;
           else { 
             const SgTemplateArgumentPtrList& args= tmp->get_templateArguments();
             if (tmpPars == 0) 
               tmpPars=get_template_parameters(tmp->get_templateDeclaration ()->get_string());
             POETCode* pars = tmpPars;
             for (SgTemplateArgumentPtrList::const_iterator p2 = args.begin();
                   p2 != args.end(); p2++) {
                 POETCode* from = get_head(pars); pars=get_tail(pars);
                 POETCode* to = STRING((*p2)->unparseToString());
                 tokens = eval_replace(from, to, tokens); 
              } 
           }
           prev = new POETCode_ext(info, PAIR(tokens, prev));
           POETAstInterface::set_Ast2POET(info,prev);
       }
       else { 
         res = LIST(prev, res);
         prev = POETAstInterface::Ast2POET((SgNode*)cur); }
    } 
    res = LIST(prev,res); 
    return res;
}
Esempio n. 13
0
void sighandler(int sig, siginfo_t *si, void *arg)
{
	if (si->si_addr != expected_addr) {
		printf("XXX: Unexpected address in signal %p (expected %p)\n", si->si_addr,
			expected_addr);
		failure++;
	}

	printf("signal %d code %d addr %p\n", sig, si->si_code, si->si_addr);

	if (--recovercount == 0) {
		write(1, PAIR("I seem to be in a signal loop. bailing out.\n"));
		exit(1);
	}

	if (si->si_code == 4)
		siglongjmp(recover_ctx, 1);
	else
		siglongjmp(early_recover_ctx, 1);
}
Esempio n. 14
0
void ConfigHandler::setParametersInternal(string configFile, MAP& configMap) {

	ifstream ifs(configFile.c_str(), ifstream::in);

	const char *delimiter = Const::CFG_DELIMITERS.c_str();

	string line;
	while (getline(ifs, line)) {

		string remains = Const::toString(line);
		if (remains.empty())
			continue;

		size_t found = remains.find(delimiter);

		if (found != string::npos) {

			string one = Const::toString(remains.substr(0, int(found)));
			string two = Const::toString(remains.substr(int(found) + 1));

			if (one.empty() || two.empty())
				continue;

			if (one.substr(0, 1) == "#") //starts with #, means comment
				continue;

			string name = one;
			string value = two;

			if (!name.empty() && !value.empty()) {

				ConfigEntry ce(name, value);
				configMap.insert(PAIR(ce.toString(), ce)); //todo: use hash code to reduce size of key/value pair.
			}
		}
	}

	ifs.close();
}
Esempio n. 15
0
void ConfHandler::setParametersInternal(string configFile, MAP& configMap) {

    ifstream ifs(configFile.c_str(), ifstream::in);

    const char *delimiter = Const::CONF_DELIMITERS.c_str();

    string line;
    while (getline(ifs, line)) {

        string remains = line;

        if (remains.empty())
            continue;

        if (remains.substr(0, 1) == "#") //starts with #, means comment
            continue;

        StrTokenizer strtok(remains);

        string one;
        string two;

        if (strtok.has_more_tokens())
            one = strtok.next_token();

        if (strtok.has_more_tokens())
            two = strtok.next_token();

        if (one.empty())
            continue;

        ConfEntry ce(one, two);
        configMap.insert(PAIR(ce.toString(), ce)); //todo: use hash code to reduce size of key/value pair.
    }

    ifs.close();
}
Esempio n. 16
0
int
ptinit()
{
	int	i, fin, nw;
	char	*setbrk(), *filebase, *p;

	/* open table for device,
	 * read in resolution, size info, font info, etc.
	 * and set params
	 */
	strcat(termtab, "/dev");
	strcat(termtab, devname);
	strcat(termtab, "/DESC.out");	/* makes "..../devXXX/DESC.out" */
	if ((fin = open(termtab, 0)) < 0) {
		errprint(gettext("can't open tables for %s"), termtab);
		done3(1);
	}
	read(fin, (char *) &dev, sizeof(struct dev ));
	Inch = dev.res;
	Hor = dev.hor;
	Vert = dev.vert;
	Unitwidth = dev.unitwidth;
	nfonts = dev.nfonts;
	nsizes = dev.nsizes;
	nchtab = dev.nchtab;
	if (nchtab >= NCHARS - 128) {
		errprint(gettext("too many special characters in file %s"),
			termtab);
		done3(1);
	}
	filebase = setbrk(dev.filesize + 2*EXTRAFONT);	/* enough room for whole file */
	read(fin, filebase, dev.filesize);	/* all at once */
	pstab = (short *) filebase;
	chtab = pstab + nsizes + 1;
	chname = (char *) (chtab + dev.nchtab);
	p = chname + dev.lchname;
	for (i = 1; i <= nfonts; i++) {
		fontbase[i] = (struct Font *) p;
		nw = *p & BYTEMASK;	/* 1st thing is width count */
		fontlab[i] = PAIR(fontbase[i]->namefont[0], fontbase[i]->namefont[1]);
		/* for now, still 2 char names */
		if (smnt == 0 && fontbase[i]->specfont == 1)
			smnt = i;	/* first special font */
		p += sizeof(struct Font);	/* that's what's on the beginning */
		fontab[i] = p;
		kerntab[i] = p + nw;
		codetab[i] = p + 2 * nw;
		fitab[i] = p + 3 * nw;	/* skip width, kern, code */
		p += 3 * nw + dev.nchtab + 128 - 32;
	}
	fontbase[0] = (struct Font *) p;	/* the last shall be first */
	fontbase[0]->nwfont = EXTRAFONT - dev.nchtab - (128-32) - sizeof (struct Font);
	fontab[0] = p + sizeof (struct Font);
	close(fin);
	/* there are a lot of things that used to be constant
	 * that now require code to be executed.
	 */
	sps = SPS;
	ics = ICS;
	for (i = 0; i < 16; i++)
		tabtab[i] = DTAB * (i + 1);
	pl = 11 * INCH;
	po = PO;
	spacesz = SS;
	lss = lss1 = VS;
	ll = ll1 = lt = lt1 = LL;
	specnames();	/* install names like "hyphen", etc. */
	if (ascii)
		return (0);
	fdprintf(ptid, "x T %s\n", devname);
	fdprintf(ptid, "x res %d %d %d\n", Inch, Hor, Vert);
	fdprintf(ptid, "x init\n");	/* do initialization for particular device */
  /*
	for (i = 1; i <= nfonts; i++)
		fdprintf(ptid, "x font %d %s\n", i, fontbase[i]->namefont);
	fdprintf(ptid, "x xxx fonts=%d sizes=%d unit=%d\n", nfonts, nsizes, Unitwidth);
	fdprintf(ptid, "x xxx nchtab=%d lchname=%d nfitab=%d\n",
		dev.nchtab, dev.lchname, dev.nchtab+128-32);
	fdprintf(ptid, "x xxx sizes:\nx xxx ");
	for (i = 0; i < nsizes; i++)
		fdprintf(ptid, " %d", pstab[i]);
	fdprintf(ptid, "\nx xxx chars:\nx xxx ");
	for (i = 0; i < dev.nchtab; i++)
		fdprintf(ptid, " %s", &chname[chtab[i]]);
	fdprintf(ptid, "\nx xxx\n");
  */

	return (0);
}
Esempio n. 17
0
SICPStream *integers(int starting) {
  return PAIR(starting, integers(starting + 1));
}
// Gets the next token from the input stream, advancing the variables which keep track of the current input position and line.
bool FBaseParser::GetToken( FToken& Token, bool bNoConsts/*=false*/, ESymbolParseOption bParseTemplateClosingBracket/*=ESymbolParseOption::Normal*/ )
{
	Token.TokenName	= NAME_None;
	TCHAR c = GetLeadingChar();
	TCHAR p = PeekChar();
	if( c == 0 )
	{
		UngetChar();
		return 0;
	}
	Token.StartPos		= PrevPos;
	Token.StartLine		= PrevLine;
	if( (c>='A' && c<='Z') || (c>='a' && c<='z') || (c=='_') )
	{
		// Alphanumeric token.
		int32 Length=0;
		do
		{
			Token.Identifier[Length++] = c;
			if( Length >= NAME_SIZE )
			{
				FError::Throwf(TEXT("Identifer length exceeds maximum of %i"), (int32)NAME_SIZE);
				Length = ((int32)NAME_SIZE) - 1;
				break;
			}
			c = GetChar();
		} while( ((c>='A')&&(c<='Z')) || ((c>='a')&&(c<='z')) || ((c>='0')&&(c<='9')) || (c=='_') );
		UngetChar();
		Token.Identifier[Length]=0;

		// Assume this is an identifier unless we find otherwise.
		Token.TokenType = TOKEN_Identifier;

		// Lookup the token's global name.
		Token.TokenName = FName( Token.Identifier, FNAME_Find, true );

		// If const values are allowed, determine whether the identifier represents a constant
		if ( !bNoConsts )
		{
			// See if the identifier is part of a vector, rotation or other struct constant.
			// boolean true/false
			if( Token.Matches(TEXT("true")) )
			{
				Token.SetConstBool(true);
				return true;
			}
			else if( Token.Matches(TEXT("false")) )
			{
				Token.SetConstBool(false);
				return true;
			}
		}
		return true;
	}

	// if const values are allowed, determine whether the non-identifier token represents a const
	else if ( !bNoConsts && ((c>='0' && c<='9') || ((c=='+' || c=='-') && (p>='0' && p<='9'))) )
	{
		// Integer or floating point constant.
		bool  bIsFloat = 0;
		int32 Length   = 0;
		bool  bIsHex   = 0;
		do
		{
			if( c==TEXT('.') )
			{
				bIsFloat = true;
			}
			if( c==TEXT('X') || c == TEXT('x') )
			{
				bIsHex = true;
			}

			Token.Identifier[Length++] = c;
			if( Length >= NAME_SIZE )
			{
				FError::Throwf(TEXT("Number length exceeds maximum of %i "), (int32)NAME_SIZE );
				Length = ((int32)NAME_SIZE) - 1;
				break;
			}
			c = FChar::ToUpper(GetChar());
		} while ((c >= TEXT('0') && c <= TEXT('9')) || (!bIsFloat && c == TEXT('.')) || (!bIsHex && c == TEXT('X')) || (bIsHex && c >= TEXT('A') && c <= TEXT('F')));

		Token.Identifier[Length]=0;
		if (!bIsFloat || c != 'F')
		{
			UngetChar();
		}

		if (bIsFloat)
		{
			Token.SetConstFloat( FCString::Atof(Token.Identifier) );
		}
		else if (bIsHex)
		{
			TCHAR* End = Token.Identifier + FCString::Strlen(Token.Identifier);
			Token.SetConstInt( FCString::Strtoi(Token.Identifier,&End,0) );
		}
		else
		{
			Token.SetConstInt( FCString::Atoi(Token.Identifier) );
		}
		return true;
	}
	else if (c == '\'')
	{
		TCHAR ActualCharLiteral = GetChar(/*bLiteral=*/ true);

		if (ActualCharLiteral == '\\')
		{
			ActualCharLiteral = GetChar(/*bLiteral=*/ true);
			switch (ActualCharLiteral)
			{
			case TCHAR('t'):
				ActualCharLiteral = '\t';
				break;
			case TCHAR('n'):
				ActualCharLiteral = '\n';
				break;
			case TCHAR('r'):
				ActualCharLiteral = '\r';
				break;
			}
		}

		c = GetChar(/*bLiteral=*/ true);
		if (c != '\'')
		{
			FError::Throwf(TEXT("Unterminated character constant"));
			UngetChar();
		}

		Token.SetConstChar(ActualCharLiteral);
		return true;
	}
	else if (c == '"')
	{
		// String constant.
		TCHAR Temp[MAX_STRING_CONST_SIZE];
		int32 Length=0;
		c = GetChar(/*bLiteral=*/ true);
		while( (c!='"') && !IsEOL(c) )
		{
			if( c=='\\' )
			{
				c = GetChar(/*bLiteral=*/ true);
				if( IsEOL(c) )
				{
					break;
				}
				else if(c == 'n')
				{
					// Newline escape sequence.
					c = '\n';
				}
			}
			Temp[Length++] = c;
			if( Length >= MAX_STRING_CONST_SIZE )
			{
				FError::Throwf(TEXT("String constant exceeds maximum of %i characters"), (int32)MAX_STRING_CONST_SIZE );
				c = TEXT('\"');
				Length = ((int32)MAX_STRING_CONST_SIZE) - 1;
				break;
			}
			c = GetChar(/*bLiteral=*/ true);
		}
		Temp[Length]=0;

		if( c != '"' )
		{
			FError::Throwf(TEXT("Unterminated string constant: %s"), Temp);
			UngetChar();
		}

		Token.SetConstString(Temp);
		return true;
	}
	else
	{
		// Symbol.
		int32 Length=0;
		Token.Identifier[Length++] = c;

		// Handle special 2-character symbols.
		#define PAIR(cc,dd) ((c==cc)&&(d==dd)) /* Comparison macro for convenience */
		TCHAR d = GetChar();
		if
		(	PAIR('<','<')
		||	(PAIR('>','>') && (bParseTemplateClosingBracket != ESymbolParseOption::CloseTemplateBracket))
		||	PAIR('!','=')
		||	PAIR('<','=')
		||	PAIR('>','=')
		||	PAIR('+','+')
		||	PAIR('-','-')
		||	PAIR('+','=')
		||	PAIR('-','=')
		||	PAIR('*','=')
		||	PAIR('/','=')
		||	PAIR('&','&')
		||	PAIR('|','|')
		||	PAIR('^','^')
		||	PAIR('=','=')
		||	PAIR('*','*')
		||	PAIR('~','=')
		||	PAIR(':',':')
		)
		{
			Token.Identifier[Length++] = d;
			if( c=='>' && d=='>' )
			{
				if( GetChar()=='>' )
					Token.Identifier[Length++] = '>';
				else
					UngetChar();
			}
		}
		else UngetChar();
		#undef PAIR

		Token.Identifier[Length] = 0;
		Token.TokenType = TOKEN_Symbol;

		// Lookup the token's global name.
		Token.TokenName = FName( Token.Identifier, FNAME_Find, true );

		return true;
	}
}
Esempio n. 19
0
POETCode* POETAstInterface::Ast2POET(const Ast& n)
{
  static SgTemplateInstantiationFunctionDecl* tmp=0;
  SgNode* input = (SgNode*) n;
  if (input == 0) return EMPTY;
  POETCode* res = POETAstInterface::find_Ast2POET(input);
  if (res != 0) return res;

  {
  SgProject* sageProject=isSgProject(input); 
  if (sageProject != 0) {
    int filenum = sageProject->numberOfFiles(); 
    for (int i = 0; i < filenum; ++i) { 
      SgSourceFile* sageFile = isSgSourceFile(sageProject->get_fileList()[i]); 
      SgGlobal *root = sageFile->get_globalScope(); 
      SgDeclarationStatementPtrList declList = root->get_declarations ();
      POETCode* curfile = ROSE_2_POET_list(declList, 0, tmp);
      curfile = new POETCode_ext(sageFile, curfile);
      POETAstInterface::set_Ast2POET(sageFile, curfile);
      res=LIST(curfile, res);
    }
    POETAstInterface::set_Ast2POET(sageProject,res); 
    return res;
  } }
  { 
  SgBasicBlock* block = isSgBasicBlock(input);
  if (block != 0) {
    res=ROSE_2_POET_list(block->get_statements(), res, tmp);
    POETAstInterface::set_Ast2POET(block, res); 
    return res;
  } }
  { 
  SgExprListExp* block = isSgExprListExp(input);
  if (block != 0) {
    res=ROSE_2_POET_list(block->get_expressions(), 0, tmp);
    POETAstInterface::set_Ast2POET(block, res); 
    return res;
  } }
 {
  SgForStatement *f = isSgForStatement(input);
  if (f != 0) {
      POETCode* init = ROSE_2_POET_list(f->get_for_init_stmt()->get_init_stmt(),0, tmp);
      POETCode* ctrl = new POETCode_ext(f, TUPLE3(init,Ast2POET(f->get_test_expr()), Ast2POET(f->get_increment())));
      res = CODE_ACC("Nest", PAIR(ctrl,Ast2POET(f->get_loop_body())));  
      POETAstInterface::set_Ast2POET(input, res); 
      return res;
  }
  }
  {
    SgVarRefExp * v = isSgVarRefExp(input);
    if (v != 0) {
       res = STRING(v->get_symbol()->get_name().str());
       POETAstInterface::set_Ast2POET(input, res); 
       return res;
    }
  }
  {
    SgMemberFunctionRefExp * v = isSgMemberFunctionRefExp(input);
    if (v != 0) {
       res = STRING(v->get_symbol()->get_name().str());
       POETAstInterface::set_Ast2POET(input, res); 
       return res;
    }
  }
  {
    SgIntVal * v = isSgIntVal(input);
    if (v != 0) {
       res = ICONST(v->get_value());
       POETAstInterface::set_Ast2POET(input, res); 
       return res;
    }
  }
  {
   SgInitializedName* var = isSgInitializedName(input);
   if (var != 0) {
     POETCode* name = STRING(var->get_name().str()); 
     POETCode* init = Ast2POET(var->get_initializer());
     res = new POETCode_ext(var, PAIR(name,init));
     POETAstInterface::set_Ast2POET(input, res); 
     return res;
   }
  }

/*
  {
  std::string fname;
  AstInterface::AstList params;
  AstNodeType returnType;
  AstNodePtr body;
  if (AstInterface :: IsFunctionDefinition( input, &fname, &params, (AstInterface::AstList*)0, &body, (AstInterface::AstTypeList*)0, &returnType)) {
if (body != AST_NULL)
 std::cerr << "body not empty:" << fname << "\n";
      POETCode* c = TUPLE4(STRING(fname), ROSE_2_POET_list(0,params,0), 
                 STRING(AstInterface::GetTypeName(returnType)), 
                 Ast2POET(body.get_ptr()));
      res = new POETCode_ext(input, c);
      POETAstInterface::set_Ast2POET(input,res);
      return res;
  } }   
*/

  AstInterface::AstList c = AstInterface::GetChildrenList(input);
  switch (input->variantT()) {
    case V_SgCastExp:
    case V_SgAssignInitializer:
      res = Ast2POET(c[0]); 
      POETAstInterface::set_Ast2POET(input, res); return res; 
    case V_SgDotExp:
     {
      POETCode* v1 = Ast2POET(c[1]);
      if (dynamic_cast<POETString*>(v1)->get_content() == "operator()") 
           return Ast2POET(c[0]);
      res = CODE_ACC("Bop",TUPLE3(STRING("."), Ast2POET(c[0]), v1)); return res;
     }
    case V_SgLessThanOp:
      res = CODE_ACC("Bop",TUPLE3(STRING("<"),Ast2POET(c[0]), Ast2POET(c[1])));
      POETAstInterface::set_Ast2POET(input, res); return res;
    case V_SgSubtractOp:
      res = CODE_ACC("Bop",TUPLE3(STRING("-"),Ast2POET(c[0]), Ast2POET(c[1])));
      POETAstInterface::set_Ast2POET(input, res); return res;
    case V_SgAddOp:
      res = CODE_ACC("Bop",TUPLE3(STRING("+"),Ast2POET(c[0]), Ast2POET(c[1])));
      POETAstInterface::set_Ast2POET(input, res); return res;
    case V_SgMultiplyOp:
      res = CODE_ACC("Bop",TUPLE3(STRING("*"),Ast2POET(c[0]), Ast2POET(c[1])));
      POETAstInterface::set_Ast2POET(input, res); return res;
    case V_SgDivideOp:
      res = CODE_ACC("Bop",TUPLE3(STRING("/"),Ast2POET(c[0]), Ast2POET(c[1])));
      POETAstInterface::set_Ast2POET(input, res); return res;
    case V_SgAssignOp:
      res = CODE_ACC("Assign",PAIR(Ast2POET(c[0]), Ast2POET(c[1])));
      POETAstInterface::set_Ast2POET(input, res); return res;
    case V_SgFunctionCallExp:
      res = CODE_ACC("FunctionCall",PAIR(Ast2POET(c[0]), Ast2POET(c[1])));
      POETAstInterface::set_Ast2POET(input, res); return res;
  } 
  POETCode * c2 = 0; 
  if (tmp == 0) tmp=isSgTemplateInstantiationFunctionDecl(input);
   switch (c.size()) {
   case 0: break;
   case 1: c2 = Ast2POET(c[0]); break;
   case 2: c2 = PAIR(Ast2POET(c[0]),Ast2POET(c[1])); break;
   case 3: c2 = TUPLE3(Ast2POET(c[0]),Ast2POET(c[1]),Ast2POET(c[2])); break;
   case 4: c2 = TUPLE4(Ast2POET(c[0]),Ast2POET(c[1]),Ast2POET(c[2]),Ast2POET(c[3])); break;
   default: 
     //std::cerr << "too many children: " << c.size() << ":" << input->unparseToString() << "\n";
     c2 = EMPTY;
   }
  if (tmp == input) tmp = 0;
  res = new POETCode_ext(input, c2); 
  POETAstInterface::set_Ast2POET(input,res);
  return res;
}
Esempio n. 20
0
        *(szPtr ++) = ' ';
    *(szPtr ++) = '^';
    *(szPtr ++) = '\0';
}

typedef struct
{
    const char* pszToken;
    int         nTokenVal;
} osr_cs_wkt_tokens;

#define PAIR(X) { #X, T_ ##X }

static const osr_cs_wkt_tokens tokens[] =
{
    PAIR(PARAM_MT),
    PAIR(PARAMETER),
    PAIR(CONCAT_MT),
    PAIR(INVERSE_MT),
    PAIR(PASSTHROUGH_MT),

    PAIR(PROJCS),
    PAIR(PROJECTION),
    PAIR(GEOGCS),
    PAIR(DATUM),
    PAIR(SPHEROID),
    PAIR(PRIMEM),
    PAIR(UNIT),
    PAIR(GEOCCS),
    PAIR(AUTHORITY),
    PAIR(VERT_CS),
Esempio n. 21
0
void QMapView::keyPressEvent(QKeyEvent* keyEvent)
{
    switch(keyEvent->key())
     {
       case Qt::Key_Space:
       {
        /*cout<<width()<<endl;
        cout<<height()<<endl;
        Mat result;
        result.create(height(),width(),CV_8UC3);
        GLbyte *buf= new GLbyte[height()*width()*3];

        //GLbyte *buf=(GLbyte *)malloc (height()*width()*3);
        glPixelStorei(GL_PACK_ALIGNMENT,1);
        glReadPixels(0,0,width(),height(),GL_BGR,GL_UNSIGNED_BYTE,buf);
        int t=0;
        for (int i=0; i<height();i++)
        {
            for (int j=0; j<width();j++)
            {
                result.at<Vec3b>(i,j)[0]=buf[t];
                result.at<Vec3b>(i,j)[1]=buf[t+1];
                result.at<Vec3b>(i,j)[2]=buf[t+2];
                t+=3;
            }
        }
        imshow("result",result);
        delete buf[];*/
        doClassification();
        break;
    }
    case Qt::Key_End:
    {
        toDo=false;
        break;
    }
    case Qt::Key_Enter:
    {
        toDo=true;
        break;
    }
    case Qt::Key_Right:
    {
        frame_count++;
        changeXmlFrame();
        break;
    }
    case Qt::Key_Left:
    {
        frame_count--;
        changeXmlFrame();
        break;
    }
        PAIR(Qt::Key_Q, Qt::Key_A, coord_x, 0.0001);
        PAIR(Qt::Key_W, Qt::Key_S, coord_y, 0.0001);
        PAIR(Qt::Key_E, Qt::Key_D, coord_z, 0.0001);
        PAIR(Qt::Key_R, Qt::Key_F, course, 1);
        PAIR(Qt::Key_T, Qt::Key_G, roll, 1);
        PAIR(Qt::Key_Y, Qt::Key_H, pitch, 1);
        PAIR(Qt::Key_U, Qt::Key_J, aspect_x, 0.1);
        PAIR(Qt::Key_I, Qt::Key_K, aspect_y, 0.1);
      default:
      QGLWidget::keyPressEvent(keyEvent);
      break;
    }
}
Esempio n. 22
0
/* Send an ICMP packet, such as host unreachable, to the source and destination addresses */
    void
rst_icmp_send(pkt_t *rst)
{
    struct ip *ih = NULL;
    struct tcphdr *th = NULL;

    int pair = 0;
    char *state = NULL;

    size_t icmp_len = 0;

    ih = (struct ip *)(rst->pkt + sizeof(struct ether_header));
    th = (struct tcphdr *)(rst->pkt + sizeof(struct ether_header) + sizeof(struct ip));

    /* The interface described in "Building Open Source Network Security Tools"
     * appears to be deprecated. The new interface tunnels an IPv4 packet
     * within the ICMP unreachable using the libnet context.
     */
    switch (rst->icmp.type) {

        /* RFC 792
         *
         * Type 3
         *
         * Codes 0, 1, 4, and 5 may be received from a gateway.  Codes 2 and
         * 3 may be received from a host.
         *
         *  0 = net unreachable;
         *  1 = host unreachable;
         *  2 = protocol unreachable;
         *  3 = port unreachable;
         *  4 = fragmentation needed and DF set;
         *  5 = source route failed.
         *
         */
        case ICMP_UNREACH:
            icmp_len = LIBNET_ICMPV4_UNREACH_H + LIBNET_IPV4_H + ICMP_PKTLEN;
            LIBNET_ERR(libnet_build_icmpv4_unreach(
                        rst->icmp.type,                             /* ICMP type, e.g. 3 (Unreachable) */
                        rst->icmp.code,                             /* ICMP code, e.g., 1 (Bad Host) */
                        0,                                          /* auto checksum */
                        (u_char *)ih,                               /* payload */
                        LIBNET_IPV4_H + ICMP_PKTLEN,                /* payload size */
                        rst->l,                                     /* libnet context */
                        0                                           /* ptag */
                        ));
            break;

            /*
             * Type 5
             *
             * Codes 0, 1, 2, and 3 may be received from a gateway.
             *
             *  0 = Redirect datagrams for the Network.
             *  1 = Redirect datagrams for the Host.
             *  2 = Redirect datagrams for the Type of Service and Network.
             *  3 = Redirect datagrams for the Type of Service and Host.
             *
             */
        case ICMP_REDIRECT:
            icmp_len = LIBNET_ICMPV4_REDIRECT_H;
            LIBNET_ERR(libnet_build_icmpv4_unreach(
                        rst->icmp.type,
                        rst->icmp.code,
                        0,
                        (u_char *)ih,
                        LIBNET_IPV4_H + ICMP_PKTLEN,
                        rst->l,
                        0));

            break;

            /*
             * Type 11
             *
             * Code 0 may be received from a gateway.  Code 1 may be received
             * from a host.
             *
             * 0 = time to live exceeded in transit
             * 1 = fragment reassembly time exceeded
             *
             */
        case ICMP_TIMXCEED:
            icmp_len = LIBNET_ICMPV4_TIMXCEED_H + LIBNET_IPV4_H + ICMP_PKTLEN;
            LIBNET_ERR(libnet_build_icmpv4_timeexceed(
                        rst->icmp.type,
                        rst->icmp.code,
                        0,
                        (u_char *)ih,
                        LIBNET_IPV4_H + ICMP_PKTLEN,
                        rst->l,
                        0));
            break;

        case ICMP_PARAMPROB:
        case ICMP_SOURCEQUENCH:
            errx(EXIT_FAILURE, "Not supported by libnet.");
            break;

        default:
            errx(EXIT_FAILURE, "ICMP type %d is not supported yet\n",
                    rst->icmp.type);
    }

    LIBNET_ERR(libnet_build_ipv4(
                LIBNET_IPV4_H + icmp_len,                   /* payload size */
                IPTOS_LOWDELAY | IPTOS_THROUGHPUT,          /* TOS */
                ntohs(ih->ip_id)+1,                                /* IP ID */
                0,                                          /* Frag */
                64,                                         /* TTL */
                IPPROTO_ICMP,                               /* Protocol */
                0,                                          /* auto checksum */
                ih->ip_dst.s_addr,                          /* source */
                ih->ip_src.s_addr,                          /* destination */
                NULL,                                       /* payload */
                0,                                          /* payload size */
                rst->l,                                     /* libnet context */
                0                                           /* libnet ptag */
                ));

    state = ((libnet_write(rst->l) == -1) ? "x" : "I");
    (void)fprintf(stdout, "[%s] SRC = %15s:%-6u DST = %15s:%-6u len = %d/%d\n", state,
                  libnet_addr2name4(PAIR(pair, ih->ip_src.s_addr, ih->ip_dst.s_addr), LIBNET_DONT_RESOLVE),
                  PAIR(pair, ntohs(th->th_sport), ntohs(th->th_dport)),
                  libnet_addr2name4(PAIR(pair, ih->ip_dst.s_addr, ih->ip_src.s_addr), LIBNET_DONT_RESOLVE),
                  PAIR(pair, ntohs(th->th_dport), ntohs(th->th_sport)), LIBNET_IPV4_H + (u_int32_t)icmp_len, ntohs(ih->ip_len));

    (void)fflush(stdout);

    usleep(rst->sleep_for);
}
Esempio n. 23
0
// Gets the next token from the input stream, advancing the variables which keep track of the current input position and line.
bool FBaseParser::GetToken( FToken& Token, bool bNoConsts/*=false*/ )
{
	Token.TokenName	= NAME_None;
	TCHAR c = GetLeadingChar();
	TCHAR p = PeekChar();
	if( c == 0 )
	{
		UngetChar();
		return 0;
	}
	Token.StartPos		= PrevPos;
	Token.StartLine		= PrevLine;
	if( (c>='A' && c<='Z') || (c>='a' && c<='z') || (c=='_') )
	{
		// Alphanumeric token.
		int32 Length=0;
		do
		{
			Token.Identifier[Length++] = c;
			if( Length >= NAME_SIZE )
			{
				FError::Throwf(TEXT("Identifer length exceeds maximum of %i"), (int32)NAME_SIZE);
				Length = ((int32)NAME_SIZE) - 1;
				break;
			}
			c = GetChar();
		} while( ((c>='A')&&(c<='Z')) || ((c>='a')&&(c<='z')) || ((c>='0')&&(c<='9')) || (c=='_') );
		UngetChar();
		Token.Identifier[Length]=0;

		// Assume this is an identifier unless we find otherwise.
		Token.TokenType = TOKEN_Identifier;

		// Lookup the token's global name.
		Token.TokenName = FName( Token.Identifier, FNAME_Find, true );

		// If const values are allowed, determine whether the identifier represents a constant
		if ( !bNoConsts )
		{
			// See if the identifier is part of a vector, rotation or other struct constant.
			// boolean true/false
			if( Token.Matches(TEXT("true")) )
			{
				Token.SetConstBool(true);
				return true;
			}
			else if( Token.Matches(TEXT("false")) )
			{
				Token.SetConstBool(false);
				return true;
			}
		}
		return true;
	}

	// if const values are allowed, determine whether the non-identifier token represents a const
	else if ( !bNoConsts && ((c>='0' && c<='9') || ((c=='+' || c=='-') && (p>='0' && p<='9'))) )
	{
		// Integer or floating point constant.
		bool  bIsFloat = 0;
		int32 Length   = 0;
		bool  bIsHex   = 0;
		do
		{
			if( c==TEXT('.') )
			{
				bIsFloat = true;
			}
			if( c==TEXT('X') || c == TEXT('x') )
			{
				bIsHex = true;
			}

			Token.Identifier[Length++] = c;
			if( Length >= NAME_SIZE )
			{
				FError::Throwf(TEXT("Number length exceeds maximum of %i "), (int32)NAME_SIZE );
				Length = ((int32)NAME_SIZE) - 1;
				break;
			}
			c = FChar::ToUpper(GetChar());
		} while ((c >= TEXT('0') && c <= TEXT('9')) || (!bIsFloat && c == TEXT('.')) || (!bIsHex && c == TEXT('X')) || (bIsHex && c >= TEXT('A') && c <= TEXT('F')));

		Token.Identifier[Length]=0;
		if (!bIsFloat || c != 'F')
		{
			UngetChar();
		}

		if (bIsFloat)
		{
			Token.SetConstFloat( FCString::Atof(Token.Identifier) );
		}
		else if (bIsHex)
		{
			TCHAR* End = Token.Identifier + FCString::Strlen(Token.Identifier);
			Token.SetConstInt( FCString::Strtoi(Token.Identifier,&End,0) );
		}
		else
		{
			Token.SetConstInt( FCString::Atoi(Token.Identifier) );
		}
		return true;
	}
//@TODO: 'z' is a character literal in C++, not a FName like it was in UnrealScript - do we need this code? 
// 	else if( !bNoConsts && c=='\'' )
// 	{
// 		// Name constant.
// 		int32 Length=0;
// 		c = GetChar();
// 		while( (c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9') || (c=='_') || (c=='-') || (c==' ') ) //@FIXME: space in names should be illegal!
// 		{
// 			Token.Identifier[Length++] = c;
// 			if( Length >= NAME_SIZE )
// 			{
// 				FError::Throwf(TEXT("Name length exceeds maximum of %i"), (int32)NAME_SIZE );
// 				// trick the error a few lines down
// 				c = TEXT('\'');
// 				Length = ((int32)NAME_SIZE) - 1;
// 				break;
// 			}
// 			c = GetChar();
// 		}
// 		if( c != '\'' )
// 		{
// 			UngetChar();
// 			FError::Throwf(TEXT("Illegal character in name") );
// 		}
// 		Token.Identifier[Length]=0;
// 
// 		// Make constant name.
// 		Token.SetConstName( FName(Token.Identifier) );
// 		return true;
// 	}
	else if( c=='"' )
	{
		// String constant.
		TCHAR Temp[MAX_STRING_CONST_SIZE];
		int32 Length=0;
		c = GetChar(1);
		while( (c!='"') && !IsEOL(c) )
		{
			if( c=='\\' )
			{
				c = GetChar(1);
				if( IsEOL(c) )
				{
					break;
				}
				else if(c == 'n')
				{
					// Newline escape sequence.
					c = '\n';
				}
			}
			Temp[Length++] = c;
			if( Length >= MAX_STRING_CONST_SIZE )
			{
				FError::Throwf(TEXT("String constant exceeds maximum of %i characters"), (int32)MAX_STRING_CONST_SIZE );
				c = TEXT('\"');
				Length = ((int32)MAX_STRING_CONST_SIZE) - 1;
				break;
			}
			c = GetChar(1);
		}
		Temp[Length]=0;

		if( c != '"' )
		{
			FError::Throwf(TEXT("Unterminated string constant: %s"), Temp);
			UngetChar();
		}

		Token.SetConstString(Temp);
		return true;
	}
	else
	{
		// Symbol.
		int32 Length=0;
		Token.Identifier[Length++] = c;

		// Handle special 2-character symbols.
		#define PAIR(cc,dd) ((c==cc)&&(d==dd)) /* Comparison macro for convenience */
		TCHAR d = GetChar();
		if
		(	PAIR('<','<')
		||	PAIR('>','>')
		||	PAIR('!','=')
		||	PAIR('<','=')
		||	PAIR('>','=')
		||	PAIR('+','+')
		||	PAIR('-','-')
		||	PAIR('+','=')
		||	PAIR('-','=')
		||	PAIR('*','=')
		||	PAIR('/','=')
		||	PAIR('&','&')
		||	PAIR('|','|')
		||	PAIR('^','^')
		||	PAIR('=','=')
		||	PAIR('*','*')
		||	PAIR('~','=')
		||	PAIR(':',':')
		)
		{
			Token.Identifier[Length++] = d;
			if( c=='>' && d=='>' )
			{
				if( GetChar()=='>' )
					Token.Identifier[Length++] = '>';
				else
					UngetChar();
			}
		}
		else UngetChar();
		#undef PAIR

		Token.Identifier[Length] = 0;
		Token.TokenType = TOKEN_Symbol;

		// Lookup the token's global name.
		Token.TokenName = FName( Token.Identifier, FNAME_Find, true );

		return true;
	}
}
Esempio n. 24
0
 * software developed by the University of California, Berkeley, and its
 * contributors.
 */

#include "tdef.h"
#include "tw.h"
#include "ext.h"
#include <ctype.h>

/*
 * n6.c -- width functions, sizes and fonts
*/

int	bdtab[NFONT+1] ={ 0, 0, 0, 3, 3, 0, };
int	sbold = 0;
int	fontlab[NFONT+1] = { 0, 'R', 'I', 'B', PAIR('B','I'), 'S', 0 };

extern	int	nchtab;

int
width(j)
tchar j;
{
	int	i, k;

	if (j & (ZBIT|MOT)) {
		if (iszbit(j))
			return(0);
		if (isvmot(j))
			return(0);
		k = absmot(j);
Esempio n. 25
0
#ifndef lint
static char sccsid[] = "@(#)ntab.c	4.1 6/7/82";
#endif lint

#define BYTE 8
#define PAIR(A,B) (A|(B<<BYTE))
/*
character name tables
modified for BTL special font version 4
and Commercial II
*/


int chtab [] = {
PAIR('h','y'), 0200,	/*hyphen*/
PAIR('b','u'), 0201,	/*bullet*/
PAIR('s','q'), 0202,	/*square*/
PAIR('e','m'), 0203,	/*3/4em*/
PAIR('r','u'), 0204,	/*rule*/
PAIR('1','4'), 0205,	/*1/4*/
PAIR('1','2'), 0206,	/*1/2*/
PAIR('3','4'), 0207,	/*3/4*/
PAIR('m','i'), 0302,	/*equation minus*/
PAIR('f','i'), 0211,	/*fi*/
PAIR('f','l'), 0212,	/*fl*/
PAIR('f','f'), 0213,	/*ff*/
PAIR('F','i'), 0214,	/*ffi*/
PAIR('F','l'), 0215,	/*ffl*/
PAIR('d','e'), 0216,	/*degree*/
PAIR('d','g'), 0217,	/*dagger*/
PAIR('s','c'), 0220,	/*section*/
Esempio n. 26
0
//------------------------------------------------------------------------------
bool FBasicTokenParser::GetToken(FBasicToken& Token, bool bNoConsts/* = false*/)
{
	// if the parser is in a bad state, then don't continue parsing (who 
	// knows what will happen!?)
	if (!IsValid())
	{
		return false;
	}

	Token.TokenName	= NAME_None;
	TCHAR c = GetLeadingChar();
	TCHAR p = PeekChar();
	if( c == 0 )
	{
		UngetChar();
		return 0;
	}
	Token.StartPos		= PrevPos;
	Token.StartLine		= PrevLine;
	if( (c>='A' && c<='Z') || (c>='a' && c<='z') || (c=='_') )
	{
		// Alphanumeric token.
		int32 Length=0;
		do
		{
			Token.Identifier[Length++] = c;
			if( Length >= NAME_SIZE )
			{
				Length = ((int32)NAME_SIZE) - 1;
				Token.Identifier[Length]=0; // need this for the error description

				FText ErrorDesc = FText::Format(LOCTEXT("IdTooLong", "Identifer ({0}...) exceeds maximum length of {1}"), FText::FromString(Token.Identifier), FText::AsNumber((int32)NAME_SIZE));
				SetError(FErrorState::ParseError, ErrorDesc);

				break;
			}
			c = GetChar();
		} while( ((c>='A')&&(c<='Z')) || ((c>='a')&&(c<='z')) || ((c>='0')&&(c<='9')) || (c=='_') );
		UngetChar();
		Token.Identifier[Length]=0;

		// Assume this is an identifier unless we find otherwise.
		Token.TokenType = FBasicToken::TOKEN_Identifier;

		// Lookup the token's global name.
		Token.TokenName = FName( Token.Identifier, FNAME_Find, true );

		// If const values are allowed, determine whether the identifier represents a constant
		if ( !bNoConsts )
		{
			// See if the identifier is part of a vector, rotation or other struct constant.
			// boolean true/false
			if( Token.Matches(TEXT("true")) )
			{
				Token.SetConstBool(true);
				return true;
			}
			else if( Token.Matches(TEXT("false")) )
			{
				Token.SetConstBool(false);
				return true;
			}
		}

		return IsValid();
	}
	// if const values are allowed, determine whether the non-identifier token represents a const
	else if ( !bNoConsts && ((c>='0' && c<='9') || ((c=='+' || c=='-') && (p>='0' && p<='9'))) )
	{
		// Integer or floating point constant.
		bool  bIsFloat = 0;
		int32 Length   = 0;
		bool  bIsHex   = 0;
		do
		{
			if( c==TEXT('.') )
			{
				bIsFloat = true;
			}
			if( c==TEXT('X') || c == TEXT('x') )
			{
				bIsHex = true;
			}

			Token.Identifier[Length++] = c;
			if( Length >= NAME_SIZE )
			{
				Length = ((int32)NAME_SIZE) - 1;
				Token.Identifier[Length]=0; // need this for the error description

				FText ErrorDesc = FText::Format(LOCTEXT("IdTooLong", "Identifer ({0}...) exceeds maximum length of {1}"), FText::FromString(Token.Identifier), FText::AsNumber((int32)NAME_SIZE));
				SetError(FErrorState::ParseError, ErrorDesc);

				break;
			}
			c = FChar::ToUpper(GetChar());
		} while ((c >= TEXT('0') && c <= TEXT('9')) || (!bIsFloat && c == TEXT('.')) || (!bIsHex && c == TEXT('X')) || (bIsHex && c >= TEXT('A') && c <= TEXT('F')));

		Token.Identifier[Length]=0;
		if (!bIsFloat || c != 'F')
		{
			UngetChar();
		}

		if (bIsFloat)
		{
			Token.SetConstFloat( FCString::Atof(Token.Identifier) );
		}
		else if (bIsHex)
		{
			TCHAR* End = Token.Identifier + FCString::Strlen(Token.Identifier);
			Token.SetConstInt( FCString::Strtoi(Token.Identifier,&End,0) );
		}
		else
		{
			Token.SetConstInt( FCString::Atoi(Token.Identifier) );
		}
		return IsValid();
	}
	else if( c=='"' )
	{
		// String constant.
		TCHAR Temp[MAX_STRING_CONST_SIZE];
		int32 Length=0;
		c = GetChar(1);
		while( (c!='"') && !IsEOL(c) )
		{
			if( c=='\\' )
			{
				c = GetChar(1);
				if( IsEOL(c) )
				{
					break;
				}
				else if(c == 'n')
				{
					// Newline escape sequence.
					c = '\n';
				}
			}
			Temp[Length++] = c;
			if( Length >= MAX_STRING_CONST_SIZE )
			{
				Length = ((int32)MAX_STRING_CONST_SIZE) - 1;
				Temp[Length]=0; // need this for the error description

				FText ErrorDesc = FText::Format(LOCTEXT("StringConstTooLong", "String constant ({0}...) exceeds maximum of {1} characters"), FText::FromString(Temp), FText::AsNumber((int32)MAX_STRING_CONST_SIZE));
				SetError(FErrorState::ParseError, ErrorDesc);

				c = TEXT('\"');				
				break;
			}
			c = GetChar(1);
		}
		Temp[Length]=0;

		if( c != '"' )
		{
			FText ErrorDesc = FText::Format(LOCTEXT("NoClosingQuote", "Unterminated quoted string ({0})"), FText::FromString(Temp));
			SetError(FErrorState::ParseError, ErrorDesc);

			UngetChar();
		}

		Token.SetConstString(Temp);
		return IsValid();
	}
	else
	{
		// Symbol.
		int32 Length=0;
		Token.Identifier[Length++] = c;

		// Handle special 2-character symbols.
#define PAIR(cc,dd) ((c==cc)&&(d==dd)) /* Comparison macro for convenience */
		TCHAR d = GetChar();
		if
		(	PAIR('<','<')
		||	PAIR('>','>')
		||	PAIR('!','=')
		||	PAIR('<','=')
		||	PAIR('>','=')
		||	PAIR('+','+')
		||	PAIR('-','-')
		||	PAIR('+','=')
		||	PAIR('-','=')
		||	PAIR('*','=')
		||	PAIR('/','=')
		||	PAIR('&','&')
		||	PAIR('|','|')
		||	PAIR('^','^')
		||	PAIR('=','=')
		||	PAIR('*','*')
		||	PAIR('~','=')
		||	PAIR(':',':')
		)
		{
			Token.Identifier[Length++] = d;
			if( c=='>' && d=='>' )
			{
				if( GetChar()=='>' )
					Token.Identifier[Length++] = '>';
				else
					UngetChar();
			}
		}
		else UngetChar();
#undef PAIR

		Token.Identifier[Length] = 0;
		Token.TokenType = FBasicToken::TOKEN_Symbol;

		// Lookup the token's global name.
		Token.TokenName = FName( Token.Identifier, FNAME_Find, true );

		return true;
	}
}
Esempio n. 27
0
ParseExp::Result 
ParseExp::ParseExpImpl(POETCode* input, POETCode* bop, POETCode* inherit, int *p_lineno)
{
  if (inherit == 0) {
    POETCode* p_uop = exp_uop->get_entry().get_code();
    for (POETCode* cur = 0; ((cur=get_head(p_uop))!=0); p_uop = get_tail(p_uop)) 
    {
       POETCode* p_input = MatchOp(cur, input);
       if (p_input != 0) {
          Result resOfRest = ParseItemType(p_input, p_lineno);
          if (resOfRest.first != 0) {
             if (buildUop->get_entry().get_code()!=0) {
                XformVar* xvar = dynamic_cast<XformVar*>(buildUop->get_entry().get_code());
                if (xvar == 0) INCORRECT_XVAR(buildUop);
                inherit = xvar->eval(PAIR(cur,resOfRest.first),false);
             }
             else {
                CodeVar* cvar = dynamic_cast<CodeVar*>(parseUop->get_entry().get_code());
                if (cvar == 0) INCORRECT_CVAR(parseUop);
                inherit = CODE_REF(cvar, PAIR(cur,resOfRest.first));
             }
             input = resOfRest.second;
          }
          break;
       }
    }
  }
  if (inherit == 0)  {
     Result res = ParseItemType(input, p_lineno);
     inherit = res.first; input = res.second;
  }
  if (inherit == 0) { return Result(0,input); }
  if (get_tail(input) != 0) {
     POETCode* p_bop = bop;
     for (POETCode* cur_bop=0; (cur_bop = get_head(p_bop)) != 0; p_bop = get_tail(p_bop) )
     {
        for (POETCode* cur = 0; (cur = get_head(cur_bop)) != 0; cur_bop = get_tail(cur_bop)) 
        {
           POETCode* p_input = MatchOp(cur, input);
           if (p_input != 0) { 
              Result resOfTail = ParseExpImpl(p_input,get_tail(p_bop),0, p_lineno);
              if (resOfTail.first != 0) {
                 POETCode* first1 = 0;
                 if (buildBop->get_entry().get_code()!=0) {
                    XformVar* xvar = dynamic_cast<XformVar*>(buildBop->get_entry().get_code());
                    if (xvar == 0) INCORRECT_XVAR(buildBop);
                    first1 = xvar->eval(TUPLE3(cur,inherit,resOfTail.first),false);
                 } 
                 else {
                    CodeVar* cvar = dynamic_cast<CodeVar*>(parseBop->get_entry().get_code());
                    if (cvar == 0) INCORRECT_XVAR(parseBop);
                    first1=CODE_REF(cvar,TUPLE3(cur,inherit,resOfTail.first));
                 }
                 return ParseExpImpl(resOfTail.second,bop,first1, p_lineno);
              }
              return Result(inherit,input);
           }
        }
     }
   }
   return Result(inherit, input) ;
}
Esempio n. 28
0
char	devname[20] = "37";

#else

char	*termtab = FNTDIR;              /* rest added in ptinit() */
char	*fontfile = FNTDIR;             /* rest added in casefp() */
char	devname[20]	 = "ps";	/* default typesetter */
int	html;

#endif
char	obuf[OBUFSZ];	/* characters collected here for typesetter output */
char	*obufp = obuf;
int	NN;
struct numtab *numtab;
const struct numtab initnumtab[] = {
	{ PAIR('%', 0), 0, 0, 0, NULL, 0, 0, 0, 0, 0 },
	{ PAIR('n', 'l'), 0, 0, 0, NULL, 0, 0, 0, 0, 0  },
	{ PAIR('y', 'r'), 0, 0, 0, NULL, 0, 0, 0, 0, 0  },
	{ PAIR('h', 'p'), 0, 0, 0, NULL, 0, 0, 0, 0, 0  },
	{ PAIR('c', 't'), 0, 0, 0, NULL, 0, 0, 0, 0, 0  },
	{ PAIR('d', 'n'), 0, 0, 0, NULL, 0, 0, 0, 0, 0  },
	{ PAIR('m', 'o'), 0, 0, 0, NULL, 0, 0, 0, 0, 0  },
	{ PAIR('d', 'y'), 0, 0, 0, NULL, 0, 0, 0, 0, 0  },
	{ PAIR('d', 'w'), 0, 0, 0, NULL, 0, 0, 0, 0, 0  },
	{ PAIR('l', 'n'), 0, 0, 0, NULL, 0, 0, 0, 0, 0  },
	{ PAIR('d', 'l'), 0, 0, 0, NULL, 0, 0, 0, 0, 0  },
	{ PAIR('s', 't'), 0, 0, 0, NULL, 0, 0, 0, 0, 0  },
	{ PAIR('s', 'b'), 0, 0, 0, NULL, 0, 0, 0, 0, 0  },
	{ PAIR('c', '.'), 0, 0, 0, NULL, 0, 0, 0, 0, 0  },
	{ PAIR('$', '$'), 0, 0, 0, NULL, 0, 0, 0, 0, 0  },
	{ 0, 0, 0, 0, NULL, 0, 0, 0, 0, 0  }
Esempio n. 29
0
int Visit (register Object *p) {
    register Object *tag;
    register int t, size, reloc = 0;

again:
    t = TYPE(*p);
    if (!Types[t].haspointer)
        return 0;
    tag = (Object *)POINTER(*p);
    if ((char *)tag >= Free_Start && (char *)tag < Free_End)
        return 0;
    if (TYPE(*tag) == T_Broken_Heart) {
        SETPOINTER(*p, POINTER(*tag));
        return 0;
    }
    ELK_ALIGN(To);
    switch (t) {
    case T_Bignum:
        size = sizeof (struct S_Bignum) - sizeof (gran_t)
               + BIGNUM(*p)->size * sizeof (gran_t);
        memcpy (To, tag, size);
        break;
    case T_Flonum:
        size = sizeof (struct S_Flonum);
        *(struct S_Flonum *)To = *(struct S_Flonum *)tag;
        break;
    case T_Symbol:
        size = sizeof (struct S_Symbol);
        *(struct S_Symbol *)To = *(struct S_Symbol *)tag;
        break;
    case T_Pair:
    case T_Environment:
        size = sizeof (struct S_Pair);
        *(struct S_Pair *)To = *(struct S_Pair *)tag;
        break;
    case T_String:
        size = sizeof (struct S_String) + STRING(*p)->size - 1;
        memcpy (To, tag, size);
        break;
    case T_Vector:
        size = sizeof (struct S_Vector) + (VECTOR(*p)->size - 1) *
            sizeof (Object);
        memcpy (To, tag, size);
        break;
    case T_Primitive:
        size = sizeof (struct S_Primitive);
        *(struct S_Primitive *)To = *(struct S_Primitive *)tag;
        break;
    case T_Compound:
        size = sizeof (struct S_Compound);
        *(struct S_Compound *)To = *(struct S_Compound *)tag;
        break;
    case T_Control_Point:
        size = sizeof (struct S_Control) + CONTROL(*p)->size - 1;
        reloc = To - (char *)tag;
        memcpy (To, tag, size);
        break;
    case T_Promise:
        size = sizeof (struct S_Promise);
        *(struct S_Promise *)To = *(struct S_Promise *)tag;
        break;
    case T_Port:
        size = sizeof (struct S_Port);
        *(struct S_Port *)To = *(struct S_Port *)tag;
        break;
    case T_Autoload:
        size = sizeof (struct S_Autoload);
        *(struct S_Autoload *)To = *(struct S_Autoload *)tag;
        break;
    case T_Macro:
        size = sizeof (struct S_Macro);
        *(struct S_Macro *)To = *(struct S_Macro *)tag;
        break;
    case T_Broken_Heart:
        Panic ("broken heart in GC");
    default:
        if (t < 0 || t >= Num_Types)
            Panic ("bad type in GC");
        if (Types[t].size == NOFUNC)
            size = Types[t].const_size;
        else
            size = (Types[t].size)(*p);
        memcpy (To, tag, size);
    }
    SETPOINTER(*p, To);
    SET(*tag, T_Broken_Heart, To);
    To += size;
    if (To > Free_End)
        Panic ("free exhausted in GC");
    switch (t) {
    case T_Symbol:
        Recursive_Visit (&SYMBOL(*p)->next);
        Recursive_Visit (&SYMBOL(*p)->name);
        Recursive_Visit (&SYMBOL(*p)->value);
        p = &SYMBOL(*p)->plist;
        goto again;
    case T_Pair:
    case T_Environment:
        Recursive_Visit (&PAIR(*p)->car);
        p = &PAIR(*p)->cdr;
        goto again;
    case T_Vector: {
            register int i, n;
            for (i = 0, n = VECTOR(*p)->size; i < n; i++)
                Recursive_Visit (&VECTOR(*p)->data[i]);
            break;
        }
    case T_Compound:
        Recursive_Visit (&COMPOUND(*p)->closure);
        Recursive_Visit (&COMPOUND(*p)->env);
        p = &COMPOUND(*p)->name;
        goto again;
    case T_Control_Point:
        Recursive_Visit (&CONTROL(*p)->memsave);
        CONTROL(*p)->delta += reloc;
#ifdef HAVE_ALLOCA
        Visit_GC_List (CONTROL(*p)->gclist, CONTROL(*p)->delta);
#else
        Recursive_Visit (&CONTROL(*p)->gcsave);
#endif
        Visit_Wind (CONTROL(*p)->firstwind, CONTROL(*p)->delta);
        p = &CONTROL(*p)->env;
        goto again;
    case T_Promise:
        Recursive_Visit (&PROMISE(*p)->env);
        p = &PROMISE(*p)->thunk;
        goto again;
    case T_Port:
        p = &PORT(*p)->name;
        goto again;
    case T_Autoload:
        Recursive_Visit (&AUTOLOAD(*p)->files);
        p = &AUTOLOAD(*p)->env;
        goto again;
    case T_Macro:
        Recursive_Visit (&MACRO(*p)->body);
        p = &MACRO(*p)->name;
        goto again;
    default:
        if (Types[t].visit)
            (Types[t].visit)(p, Visit);
    }

    return 0;
}
Esempio n. 30
0
void n_ptinit(void)
{
	int i;
	char *p;
	char opt[50], cmd[100];
	FILE *fp;

	hmot = n_hmot;
	makem = n_makem;
	setabs = n_setabs;
	setch = n_setch;
	sethl = n_sethl;
	setht = n_setht;
	setslant = n_setslant;
	vmot = n_vmot;
	xlss = n_xlss;
	findft = n_findft;
	width = n_width;
	mchbits = n_mchbits;
	ptlead = n_ptlead;
	ptout = n_ptout;
	ptpause = n_ptpause;
	setfont = n_setfont;
	setps = n_setps;
	setwd = n_setwd;

	if ((p = getenv("NROFFTERM")) != 0)
		strcpy(devname, p);
	if (termtab[0] == 0)
		strcpy(termtab,DWBntermdir);
	if (fontdir[0] == 0)
		strcpy(fontdir, "");
	if (devname[0] == 0)
		strcpy(devname, NDEVNAME);
	pl = 11*INCH;
	po = PO;
	hyf = 0;
	ascii = 1;
	lg = 0;
	fontlab[1] = 'R';
	fontlab[2] = 'I';
	fontlab[3] = 'B';
	fontlab[4] = PAIR('B','I');
	fontlab[5] = 'D';
	bdtab[3] = 3;
	bdtab[4] = 3;

	/* hyphalg = 0;	/* for testing */

	strcat(termtab, devname);
	if ((fp = fopen(unsharp(termtab), "r")) == NULL) {
		ERROR "cannot open %s", termtab WARN;
		exit(-1);
	}


/* this loop isn't robust about input format errors. */
/* it assumes  name, name-value pairs..., charset */
/* god help us if we get out of sync. */

	fscanf(fp, "%s", cmd);	/* should be device name... */
	if (!is(devname) && trace)
		ERROR "wrong terminal name: saw %s, wanted %s", cmd, devname WARN;
	for (;;) {
		fscanf(fp, "%s", cmd);
		if (is("charset"))
			break;
		fscanf(fp, " %[^\n]", opt);
		if (is("bset")) t.bset = atoi(opt);
		else if (is("breset")) t.breset = atoi(opt);
		else if (is("Hor")) t.Hor = atoi(opt);
		else if (is("Vert")) t.Vert = atoi(opt);
		else if (is("Newline")) t.Newline = atoi(opt);
		else if (is("Char")) t.Char = atoi(opt);
		else if (is("Em")) t.Em = atoi(opt);
		else if (is("Halfline")) t.Halfline = atoi(opt);
		else if (is("Adj")) t.Adj = atoi(opt);
		else if (is("twinit")) t.twinit = strdupl(parse(opt, Notype));
		else if (is("twrest")) t.twrest = strdupl(parse(opt, Notype));
		else if (is("twnl")) t.twnl = strdupl(parse(opt, Notype));
		else if (is("hlr")) t.hlr = strdupl(parse(opt, Notype));
		else if (is("hlf")) t.hlf = strdupl(parse(opt, Notype));
		else if (is("flr")) t.flr = strdupl(parse(opt, Notype));
		else if (is("bdon")) t.bdon = strdupl(parse(opt, Notype));
		else if (is("bdoff")) t.bdoff = strdupl(parse(opt, Notype));
		else if (is("iton")) t.iton = strdupl(parse(opt, Notype));
		else if (is("itoff")) t.itoff = strdupl(parse(opt, Notype));
		else if (is("ploton")) t.ploton = strdupl(parse(opt, Notype));
		else if (is("plotoff")) t.plotoff = strdupl(parse(opt, Notype));
		else if (is("up")) t.up = strdupl(parse(opt, Notype));
		else if (is("down")) t.down = strdupl(parse(opt, Notype));
		else if (is("right")) t.right = strdupl(parse(opt, Notype));
		else if (is("left")) t.left = strdupl(parse(opt, Notype));
		else
			ERROR "bad tab.%s file, %s %s", devname, cmd, opt WARN;
	}

	getnrfont(fp);
	fclose(fp);

	sps = EM;
	ics = EM * 2;
	dtab = 8 * t.Em;
	for (i = 0; i < 16; i++)
		tabtab[i] = dtab * (i + 1);
	pl = 11 * INCH;
	po = PO;
	spacesz = SS;
	lss = lss1 = VS;
	ll = ll1 = lt = lt1 = LL;
	smnt = nfonts = 5;	/* R I B BI S */
	n_specnames();	/* install names like "hyphen", etc. */
	if (eqflg)
		t.Adj = t.Hor;
}