예제 #1
0
bool	SMDImporter::Parse ( FILE *f )
{
	char *buffer = NULL;

	try 
	{
		fseek(f, 0, SEEK_END );
		long fl = ftell ( f );
		fseek (f, 0,SEEK_SET);
		buffer = new char [fl + 7];
		fread (buffer,fl,sizeof(char),f);
		
		buffer[fl] = '\r';
		buffer[fl+1] = '\n';
		buffer[fl+2] = 'E';
		buffer[fl+3] = 'N';
		buffer[fl+4] = 'D';
		buffer[fl+5] = 0;
		
		fixNames ( buffer );

		char seps[] = " \t\n\r";
		char *token = GetNextToken (buffer, seps);
		int	smdversion = NextTokenAsInteger();

		if ( strcmp ( token, "version" ))
		{
			XSILogMessage ( L"SMDImport: Not an SMD file.", XSI::siErrorMsg );
			return false;
		}

		if ( smdversion != 1 )
		{
			XSILogMessage ( L"SMDImport: Attempting to load unsupported SMD version.", XSI::siWarningMsg );
		}

		while (1)
		{
			char *currenttok = GetNextToken (NULL, seps);

			if ( !strcmp ( currenttok, "nodes"))
			{
				if ( !ImportNodes () )
				{
					return false;
				}
			}

			if ( !strcmp ( currenttok, "skeleton"))
			{
				if ( !ImportSkeleton () )
				{
					return false;
				}
			}

			
			if ( !strcmp ( currenttok, "triangles"))
			{
				if ( !ImportTriangles () )
				{
					return false;
				}
			}

			if ( !strcmp ( currenttok, "vertexanimation"))
			{
				if ( !ImportVertexAnimation () )
				{
					return false;
				}
			}

			
			
			if (!strcmp ( currenttok, "END"))
			{
				break;	// were done
			}

		}

		//
		// Create Hierarchy
		//

		
	}
	catch (...)
	{
		XSILogMessage ( L"SMDImport: Invalid or corrupted SMD file.", XSI::siErrorMsg );
		
		return false;
	}

	delete [] buffer;

	return true;
}
예제 #2
0
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
+   L o a d M a g i c C a c h e                                               %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  LoadMagicCache() loads the magic configurations which provides a mapping
%  between magic attributes and a magic name.
%
%  The format of the LoadMagicCache method is:
%
%      MagickBooleanType LoadMagicCache(LinkedListInfo *magic_cache,
%        const char *xml,const char *filename,const size_t depth,
%        ExceptionInfo *exception)
%
%  A description of each parameter follows:
%
%    o xml: The magic list in XML format.
%
%    o filename: The magic list filename.
%
%    o depth: depth of <include /> statements.
%
%    o exception: return any errors or warnings in this structure.
%
*/
static MagickBooleanType LoadMagicCache(LinkedListInfo *magic_cache,
  const char *xml,const char *filename,const size_t depth,
  ExceptionInfo *exception)
{
  char
    keyword[MagickPathExtent],
    *token;

  const char
    *q;

  MagicInfo
    *magic_info;

  MagickStatusType
    status;

  size_t
    extent;

  /*
    Load the magic map file.
  */
  (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
    "Loading magic configure file \"%s\" ...",filename);
  if (xml == (char *) NULL)
    return(MagickFalse);
  status=MagickTrue;
  magic_info=(MagicInfo *) NULL;
  token=AcquireString(xml);
  extent=strlen(token)+MagickPathExtent;
  for (q=(char *) xml; *q != '\0'; )
  {
    /*
      Interpret XML.
    */
    GetNextToken(q,&q,extent,token);
    if (*token == '\0')
      break;
    (void) CopyMagickString(keyword,token,MagickPathExtent);
    if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
      {
        /*
          Doctype element.
        */
        while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
          GetNextToken(q,&q,extent,token);
        continue;
      }
    if (LocaleNCompare(keyword,"<!--",4) == 0)
      {
        /*
          Comment element.
        */
        while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
          GetNextToken(q,&q,extent,token);
        continue;
      }
    if (LocaleCompare(keyword,"<include") == 0)
      {
        /*
          Include element.
        */
        while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
        {
          (void) CopyMagickString(keyword,token,MagickPathExtent);
          GetNextToken(q,&q,extent,token);
          if (*token != '=')
            continue;
          GetNextToken(q,&q,extent,token);
          if (LocaleCompare(keyword,"file") == 0)
            {
              if (depth > 200)
                (void) ThrowMagickException(exception,GetMagickModule(),
                  ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token);
              else
                {
                  char
                    path[MagickPathExtent],
                    *file_xml;

                  GetPathComponent(filename,HeadPath,path);
                  if (*path != '\0')
                    (void) ConcatenateMagickString(path,DirectorySeparator,
                      MagickPathExtent);
                  if (*token == *DirectorySeparator)
                    (void) CopyMagickString(path,token,MagickPathExtent);
                  else
                    (void) ConcatenateMagickString(path,token,MagickPathExtent);
                  file_xml=FileToXML(path,~0UL);
                  if (xml != (char *) NULL)
                    {
                      status&=LoadMagicCache(magic_cache,file_xml,path,depth+1,
                        exception);
                      file_xml=DestroyString(file_xml);
                    }
                }
            }
        }
        continue;
      }
    if (LocaleCompare(keyword,"<magic") == 0)
      {
        /*
          Magic element.
        */
        magic_info=(MagicInfo *) AcquireMagickMemory(sizeof(*magic_info));
        if (magic_info == (MagicInfo *) NULL)
          ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
        (void) ResetMagickMemory(magic_info,0,sizeof(*magic_info));
        magic_info->path=ConstantString(filename);
        magic_info->exempt=MagickFalse;
        magic_info->signature=MagickCoreSignature;
        continue;
      }
    if (magic_info == (MagicInfo *) NULL)
      continue;
    if (LocaleCompare(keyword,"/>") == 0)
      {
        status=InsertValueInSortedLinkedList(magic_cache,CompareMagickInfoSize,
          NULL,magic_info);
        if (status == MagickFalse)
          (void) ThrowMagickException(exception,GetMagickModule(),
            ResourceLimitError,"MemoryAllocationFailed","`%s'",
            magic_info->name);
        magic_info=(MagicInfo *) NULL;
        continue;
      }
    GetNextToken(q,(const char **) NULL,extent,token);
    if (*token != '=')
      continue;
    GetNextToken(q,&q,extent,token);
    GetNextToken(q,&q,extent,token);
    switch (*keyword)
    {
      case 'N':
      case 'n':
      {
        if (LocaleCompare((char *) keyword,"name") == 0)
          {
            magic_info->name=ConstantString(token);
            break;
          }
        break;
      }
      case 'O':
      case 'o':
      {
        if (LocaleCompare((char *) keyword,"offset") == 0)
          {
            magic_info->offset=(MagickOffsetType) StringToLong(token);
            break;
          }
        break;
      }
      case 'S':
      case 's':
      {
        if (LocaleCompare((char *) keyword,"stealth") == 0)
          {
            magic_info->stealth=IsStringTrue(token);
            break;
          }
        break;
      }
      case 'T':
      case 't':
      {
        if (LocaleCompare((char *) keyword,"target") == 0)
          {
            char
              *p;

            register unsigned char
              *q;

            size_t
              length;

            length=strlen(token);
            magic_info->target=ConstantString(token);
            magic_info->magic=(unsigned char *) ConstantString(token);
            q=magic_info->magic;
            for (p=magic_info->target; *p != '\0'; )
            {
              if (*p == '\\')
                {
                  p++;
                  if (isdigit((int) ((unsigned char) *p)) != 0)
                    {
                      char
                        *end;

                      *q++=(unsigned char) strtol(p,&end,8);
                      p+=(end-p);
                      magic_info->length++;
                      continue;
                    }
                  switch (*p)
                  {
                    case 'b': *q='\b'; break;
                    case 'f': *q='\f'; break;
                    case 'n': *q='\n'; break;
                    case 'r': *q='\r'; break;
                    case 't': *q='\t'; break;
                    case 'v': *q='\v'; break;
                    case 'a': *q='a'; break;
                    case '?': *q='\?'; break;
                    default: *q=(unsigned char) (*p); break;
                  }
                  p++;
                  q++;
                  magic_info->length++;
                  continue;
                }
              else
                if (LocaleNCompare(p,"&amp;",5) == 0)
                  (void) CopyMagickString(p+1,p+5,length-magic_info->length);
              *q++=(unsigned char) (*p++);
              magic_info->length++;
            }
            break;
          }
        break;
      }
      default:
        break;
    }
  }
  token=(char *) RelinquishMagickMemory(token);
  return(status != 0 ? MagickTrue : MagickFalse);
}
예제 #3
0
UnicoreJob::UnicoreJob( ClassAd *classad )
	: BaseJob( classad )
{
	MyString buff;
	std::string error_string = "";

	resourceName = NULL;
	jobContact = NULL;
	gmState = GM_INIT;
	unicoreState = condorState;
	lastProbeTime = 0;
	probeNow = false;
	enteredCurrentGmState = time(NULL);
	enteredCurrentUnicoreState = time(NULL);
	lastSubmitAttempt = 0;
	numSubmitAttempts = 0;
	submitFailureCode = 0;
	submitAd = NULL;
	newRemoteStatusAd = NULL;
	gahp = NULL;
	errorString = "";

	// In GM_HOLD, we assume HoldReason to be set only if we set it, so make
	// sure it's unset when we start.
	if ( jobAd->LookupString( ATTR_HOLD_REASON, NULL, 0 ) != 0 ) {
		jobAd->AssignExpr( ATTR_HOLD_REASON, "UNDEFINED" );
	}

	char *gahp_path = param("UNICORE_GAHP");
	if ( gahp_path == NULL ) {
		error_string = "UNICORE_GAHP not defined";
		goto error_exit;
	}
	gahp = new GahpClient( "UNICORE", gahp_path );
	free( gahp_path );

	gahp->setNotificationTimerId( evaluateStateTid );
	gahp->setMode( GahpClient::normal );
	gahp->setTimeout( gahpCallTimeout );

	jobAd->LookupString( ATTR_GRID_RESOURCE, &resourceName );

	jobAd->LookupString( ATTR_GRID_JOB_ID, buff );
	if ( !buff.IsEmpty() ) {
		const char *token;

		Tokenize( buff );

		token = GetNextToken( " ", false );
		if ( !token || strcasecmp( token, "unicore" ) ) {
			formatstr( error_string, "%s not of type unicore", ATTR_GRID_JOB_ID );
			goto error_exit;
		}

		GetNextToken( " ", false );
		GetNextToken( " ", false );
		token = GetNextToken( " ", false );
		if ( !token ) {
			formatstr( error_string, "%s missing job ID",
								  ATTR_GRID_JOB_ID );
			goto error_exit;
		}
		SetRemoteJobId( token );
	}

	return;

 error_exit:
		// We must ensure that the code-path from GM_HOLD doesn't depend
		// on any initialization that's been skipped.
	gmState = GM_HOLD;
	if ( !error_string.empty() ) {
		jobAd->Assign( ATTR_HOLD_REASON, error_string.c_str() );
	}
	return;
}
예제 #4
0
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
+   L o a d C o d e r C a c h e                                               %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  LoadCoderCache() loads the coder configurations which provides a
%  mapping between coder attributes and a coder name.
%
%  The format of the LoadCoderCache coder is:
%
%      MagickBooleanType LoadCoderCache(SplayTreeInfo *coder_cache,
%        const char *xml,const char *filename,const size_t depth,
%        ExceptionInfo *exception)
%
%  A description of each parameter follows:
%
%    o xml:  The coder list in XML format.
%
%    o filename:  The coder list filename.
%
%    o depth: depth of <include /> statements.
%
%    o exception: return any errors or warnings in this structure.
%
*/
static MagickBooleanType LoadCoderCache(SplayTreeInfo *coder_cache,
  const char *xml,const char *filename,const size_t depth,
  ExceptionInfo *exception)
{
  char
    keyword[MagickPathExtent],
    *token;

  const char
    *q;

  CoderInfo
    *coder_info;

  MagickStatusType
    status;

  size_t
    extent;

  /*
    Load the coder map file.
  */
  (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
    "Loading coder configuration file \"%s\" ...",filename);
  if (xml == (const char *) NULL)
    return(MagickFalse);
  status=MagickTrue;
  coder_info=(CoderInfo *) NULL;
  token=AcquireString(xml);
  extent=strlen(token)+MagickPathExtent;
  for (q=(char *) xml; *q != '\0'; )
  {
    /*
      Interpret XML.
    */
    GetNextToken(q,&q,extent,token);
    if (*token == '\0')
      break;
    (void) CopyMagickString(keyword,token,MagickPathExtent);
    if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
      {
        /*
          Doctype element.
        */
        while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
          GetNextToken(q,&q,extent,token);
        continue;
      }
    if (LocaleNCompare(keyword,"<!--",4) == 0)
      {
        /*
          Comment element.
        */
        while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
          GetNextToken(q,&q,extent,token);
        continue;
      }
    if (LocaleCompare(keyword,"<include") == 0)
      {
        /*
          Include element.
        */
        while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
        {
          (void) CopyMagickString(keyword,token,MagickPathExtent);
          GetNextToken(q,&q,extent,token);
          if (*token != '=')
            continue;
          GetNextToken(q,&q,extent,token);
          if (LocaleCompare(keyword,"file") == 0)
            {
              if (depth > 200)
                (void) ThrowMagickException(exception,GetMagickModule(),
                  ConfigureError,"IncludeNodeNestedTooDeeply","`%s'",token);
              else
                {
                  char
                    path[MagickPathExtent],
                    *file_xml;

                  GetPathComponent(filename,HeadPath,path);
                  if (*path != '\0')
                    (void) ConcatenateMagickString(path,DirectorySeparator,
                      MagickPathExtent);
                  if (*token == *DirectorySeparator)
                    (void) CopyMagickString(path,token,MagickPathExtent);
                  else
                    (void) ConcatenateMagickString(path,token,MagickPathExtent);
                  file_xml=FileToXML(path,~0UL);
                  if (file_xml != (char *) NULL)
                    {
                      status&=LoadCoderCache(coder_cache,file_xml,path,depth+1,
                        exception);
                      file_xml=DestroyString(file_xml);
                    }
                }
            }
        }
        continue;
      }
    if (LocaleCompare(keyword,"<coder") == 0)
      {
        /*
          Coder element.
        */
        coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info));
        if (coder_info == (CoderInfo *) NULL)
          ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
        (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info));
        coder_info->path=ConstantString(filename);
        coder_info->exempt=MagickFalse;
        coder_info->signature=MagickCoreSignature;
        continue;
      }
    if (coder_info == (CoderInfo *) NULL)
      continue;
    if (LocaleCompare(keyword,"/>") == 0)
      {
        status=AddValueToSplayTree(coder_cache,ConstantString(
          coder_info->magick),coder_info);
        if (status == MagickFalse)
          (void) ThrowMagickException(exception,GetMagickModule(),
            ResourceLimitError,"MemoryAllocationFailed","`%s'",
            coder_info->magick);
        coder_info=(CoderInfo *) NULL;
        continue;
      }
    GetNextToken(q,(const char **) NULL,extent,token);
    if (*token != '=')
      continue;
    GetNextToken(q,&q,extent,token);
    GetNextToken(q,&q,extent,token);
    switch (*keyword)
    {
      case 'M':
      case 'm':
      {
        if (LocaleCompare((char *) keyword,"magick") == 0)
          {
            coder_info->magick=ConstantString(token);
            break;
          }
        break;
      }
      case 'N':
      case 'n':
      {
        if (LocaleCompare((char *) keyword,"name") == 0)
          {
            coder_info->name=ConstantString(token);
            break;
          }
        break;
      }
      case 'S':
      case 's':
      {
        if (LocaleCompare((char *) keyword,"stealth") == 0)
          {
            coder_info->stealth=IsStringTrue(token);
            break;
          }
        break;
      }
      default:
        break;
    }
  }
  token=(char *) RelinquishMagickMemory(token);
  return(status != 0 ? MagickTrue : MagickFalse);
}
예제 #5
0
파일: xbexp.cpp 프로젝트: utech/UtechLib
/*!
*/
xbShort xbExpn::BuildExpressionTree( const char * Expression,
          xbShort MaxTokenLen, xbDbf * d )
{
  /* previous node is the node to insert under */
  xbExpNode * CurNode = 0;
  xbExpNode * PreviousNode;
  xbShort rc, FieldNo=0, BufLen;
  xbShort TokenLenCtr;
  char  c;
  const char *p;
  char  TempField[11];
  char  TableName[31];
  xbDbf * TempDbf=0;
  int LocTokenLen;

  if( Tree ) {
    delete Tree;
    Tree = NULL;
  }

  p = Expression;
  PreviousNode = NULL;
  PreviousType = TokenLenCtr = 0;

  while( IsWhiteSpace( *p )) {
    p++;
    TokenLenCtr++;
    if(TokenLenCtr >= MaxTokenLen)
      return XB_NO_ERROR;
  }

  rc = GetNextToken( p, MaxTokenLen-TokenLenCtr );
  LocTokenLen = TokenLen;
  if( rc != XB_NO_DATA && rc != XB_NO_ERROR )
    return rc;

  while( rc == 0 ){
    if( TokenType == 'D' && d ){
      if( TokenLen > 30 )
        strncpy( TableName, p, 30 );
      else
        strncpy( TableName, p, TokenLen );

      memset( TempField, 0x00, 11 );

      if( strstr( p, "->" ) != NULL ) {
        if(( TempDbf = d->xbase->GetDbfPtr( TableName )) == NULL )
          return XB_INVALID_FIELD;
        xbShort tlen = 0;
        while( TableName[tlen] != '-' && TableName[tlen+1] != '>' )
          tlen++;
        tlen = TokenLen - tlen - 2;    // length of field name
        const char * fp = strstr( p, "->" );
        fp += 2;                       // ptr to beginning of field name
        strncpy( TempField, fp, tlen );
      } else {
        TempDbf = d;
        if( TokenLen > 10 )
        return XB_INVALID_FIELD;
        strncpy( TempField, p, TokenLen );
      }
      if(( FieldNo = TempDbf->GetFieldNo( TempField )) == -1 )
        return XB_INVALID_FIELD;
        BufLen = TempDbf->GetFieldLen( FieldNo ) + 1;
    }
    else if( TokenType == 'C' || TokenType == 'N' )
      BufLen = TokenLen + 1;
    else
      BufLen = 0;

    if( TokenType == 'C' ) p++;   /* go past first ' */

    if( TokenType != 'O' ){
      if( !Tree ) {  /* create root node with this token */
        CurNode = LoadExpNode( p, TokenType, TokenLen, BufLen );
        Tree = CurNode;
      } else {        /* put as child 2 of previous node  */
        CurNode = LoadExpNode( p, TokenType, TokenLen, BufLen );
        PreviousNode->Sibling2 = CurNode;
        CurNode->Node = PreviousNode;
      }

      if( TokenType == 'E' ){
        if((rc=ReduceComplexExpression(p,TokenLen,CurNode,d))!=0)
          return rc;
        if(PreviousNode)
          CurNode = PreviousNode->Sibling2;
        else
          CurNode = Tree;
      } else if( TokenType == 'F' ){
        if(( rc = ReduceFunction( p, CurNode, d)) != 0 )
          return rc;

        xbShort parmCnt = GetFuncInfo( p, 1 );
        if( (parmCnt == 1 || parmCnt == 101 ) && !CurNode->Sibling1 ||
            (parmCnt == 2 || parmCnt == 201 ) && !CurNode->Sibling2 || 
            (parmCnt == 3 ) && !CurNode->Sibling3 )
          return XB_INSUFFICIENT_PARMS;
        else if( parmCnt == 0 && CurNode->Sibling1 )
          return XB_TOO_MANY_PARMS;
        else if( parmCnt == 1 && CurNode->Sibling2 )
          return XB_TOO_MANY_PARMS;
        else if( parmCnt == 2 && CurNode->Sibling3 )
          return XB_TOO_MANY_PARMS;

        CurNode->ExpressionType = GetFuncInfo( p, 2 );
        if( CurNode->ExpressionType == '1' ){
          if( CurNode->Sibling1 )
            if( CurNode->Sibling1->ExpressionType == 'C' )
              CurNode->ExpressionType = 'C';
            else
              CurNode->ExpressionType = 'N';
          else
            return XB_INSUFFICIENT_PARMS;
        }
          
        CurNode->dbf = d;
      }
      else if( TokenType == 'D' && d ) {
        CurNode->DataLen = BufLen - 1;
        CurNode->FieldNo = FieldNo;
        CurNode->dbf = TempDbf;
        c = TempDbf->GetFieldType( FieldNo );
        if( c == 'C' || c == 'M' ) CurNode->ExpressionType = 'C';
        else if( c == 'L' ) CurNode->ExpressionType = 'L';
        else if( c == 'N' || c == 'F' ) CurNode->ExpressionType = 'N';
        else if( c == 'D' ) CurNode->ExpressionType = 'D';
      } else if( TokenType == 'C' || TokenType == 'N' ) {
        CurNode->DataLen = CurNode->Len;
        CurNode->StringResult = CurNode->NodeText;
        CurNode->StringResult.resize( CurNode->DataLen+1 );
        if( TokenType == 'N' ) {
          CurNode->DoubResult = strtod( CurNode->StringResult, 0 );
          CurNode->ExpressionType = 'N';
        } else
          CurNode->ExpressionType = 'C';
      }
    }
    else /* it is an operator */
    {
      if(!Tree){
        if(*p == '-'){
          CurNode = LoadExpNode( p, TokenType, TokenLen, 0 );
          CurNode->ExpressionType = 'C';
        } else
          return XB_EXP_SYNTAX_ERROR;
      } else {
        if( Tree->Type != 'O' ){
          CurNode = LoadExpNode( p, TokenType, TokenLen, 0 );
          Tree->Node = CurNode;       /* link the new parent to old tree */
          CurNode->Sibling1 = Tree;   /* connect the sibling             */
          Tree = CurNode;             /*  root in tree                 */
        } else {
          PreviousNode = CurNode->Node;
          CurNode = LoadExpNode( p, TokenType, TokenLen, 0 );
          while( PreviousNode &&
            (( OperatorWeight( PreviousNode->NodeText, TokenLen ) == 0 ) ||
             ( OperatorWeight( CurNode->NodeText, TokenLen ) <= 
               OperatorWeight( PreviousNode->NodeText, TokenLen ))))
               PreviousNode = PreviousNode->Node;

            if( PreviousNode ) {
              CurNode->Node = PreviousNode;
              CurNode->Sibling1 = PreviousNode->Sibling2;
              PreviousNode->Sibling2 = CurNode;
              CurNode->Sibling1->Node = CurNode;
            } else { /* insert at root */
              CurNode->Sibling1 = Tree;
              Tree = CurNode;
              CurNode->Sibling1->Node = CurNode;
            }
          }
          if( LogicalType )
            CurNode->ExpressionType = 'L';
        }
      }
      PreviousNode = CurNode;
//      p += CurNode->Len;   // 2/20/04 - not sure when this was updated - gk
      p += LocTokenLen;

//    if( TokenType == 'C' ) {  gk - 2/20/04 func("fff") + 4 didn't work
      if( TokenType == 'C' && CurNode->Type != 'F' ){
         p++;              /* go past last ' */
         TokenLenCtr+=2;   /* add the quotes */
      }

//    TokenLenCtr += CurNode->Len;  // 2/20/04 - not sure when this was updated - gk
      TokenLenCtr += LocTokenLen;
      if( TokenLenCtr >= MaxTokenLen )
         return XB_NO_ERROR;
      if( p && *p && TokenType == 'E' ) {
         p++;
         TokenLenCtr++;
      }

      while( IsWhiteSpace( *p )) {
         p++;
         TokenLenCtr++;
         if( TokenLenCtr >= MaxTokenLen )
            return XB_NO_ERROR;
      }
      rc = GetNextToken( p, MaxTokenLen-TokenLenCtr );
      LocTokenLen = TokenLen;
      if( rc != XB_NO_DATA && rc != XB_NO_ERROR )
         return rc;
   }
   return XB_NO_ERROR;
}
예제 #6
0
// Get + or - as operator, not sign and number 
Token* SqlParser::GetNextPlusMinusAsOperatorToken(const char ch, const wchar_t wch)
{
	Token *token = GetNextToken();

	if(token == NULL)
		return NULL;

	// If + or - already returned as separate token then exit, for example when there is  "+ var"
	if(token->Compare(ch, wch) == true)
		return token;

	// If a number follows + or - they will be in single token as +1, but check for + or - first
	if(token->Compare(ch, wch, 0) == false)
	{
		PushBack(token);
		return NULL;
	}

	// Change the first token to hold operator +/-
	token->type = TOKEN_SYMBOL;
	token->chr = ch;
	token->wchr = 0;
	token->str = NULL;
	token->wstr = NULL;

	// Rewind input pointer
	_next_start -= token->len - 1;
	_remain_size += token->len - 1;

	token->len = 0;

	token->next_start = _next_start;
	token->remain_size = _remain_size;

	/*// Separate +/- operator and number constant tokens
	Token *token2 = new Token();

	*token2 = *token;

	token2->prev = NULL;
	token2->next = NULL;

	token2->t_str = NULL;
	token2->t_wstr = NULL;
	token2->t_len = 0;	

	// Second token hold number (decrease size by 1)
	token2->type = TOKEN_WORD;
	token2->chr = 0;
	token2->wchr = 0;
	token2->str = token2->str + 1;
	token2->wstr = 0;
	token2->len = token2->len - 1;

	_tokens.Append(token, token2);

	// Allow number to be selected as the next token
	PushBack(token2); */

	return token;
}
예제 #7
0
파일: ReadOBJ.cpp 프로젝트: TurkeyMan/fuji
void ParseOBJFile(const char *pFilePtr)
{
	const char *pToken = GetNextToken(pFilePtr);

	while(*pToken != 0)
	{
		if(!MFString_CaseCmp(pToken, "o"))
		{
			const char *pName = GetRestOfLine(pFilePtr);

			pModel->name = pName;
		}
		else if(!MFString_CaseCmp(pToken, "g"))
		{
			const char *pName = GetRestOfLine(pFilePtr);

			if(!vertsInGroup)
			{
				// we'll just rename the current subobject, since theres nothing in it..
				F3DSubObject &sub = pModel->GetMeshChunk()->subObjects[subObject];
				sub.name = pName;
			}
			else
			{
				// probably wanna copy vertex data in at this point..
				// and subtract the min from each of the components indices..
				CopyDataIntoSubobject(subObject);

				++subObject;

				matSub = 0;

				minVertIndex = -1;
				minUVIndex = -1;
				minNormIndex = -1;
				maxVertIndex = -1;
				maxUVIndex = -1;
				maxNormIndex = -1;

				vertsInGroup = false;
				vertsInMatSub = false;

				F3DSubObject &sub = pModel->GetMeshChunk()->subObjects[subObject];
				sub.name = pName;
			}
		}
		else if(!MFString_CaseCmp(pToken, "v"))
		{
			const char *pX = GetNextToken(pFilePtr);
			const char *pY = GetNextToken(pFilePtr);
			const char *pZ = GetNextToken(pFilePtr);
			pFilePtr = MFSeekNewline(pFilePtr);

			MFVector v;
			v.x = (float)atof(pX);
			v.y = (float)atof(pY);
			v.z = (float)atof(pZ);
			v.w = 1.0f;

			verts.push(v);
		}
		else if(!MFString_CaseCmp(pToken, "vt"))
		{
			const char *pU = GetNextToken(pFilePtr);
			const char *pV = GetNextToken(pFilePtr);
			pFilePtr = MFSeekNewline(pFilePtr);

			MFVector v;
			v.x = (float)atof(pU);
			v.y = (float)atof(pV);
			v.z = 0.0f;
			v.w = 1.0f;

			uvs.push(v);
		}
		else if(!MFString_CaseCmp(pToken, "vn"))
		{
			const char *pX = GetNextToken(pFilePtr);
			const char *pY = GetNextToken(pFilePtr);
			const char *pZ = GetNextToken(pFilePtr);
			pFilePtr = MFSeekNewline(pFilePtr);

			MFVector v;
			v.x = (float)atof(pX);
			v.y = (float)atof(pY);
			v.z = (float)atof(pZ);
			v.w = 1.0f;

			normals.push(v);
		}
		else if(!MFString_CaseCmp(pToken, "f"))
		{
			vertsInGroup = true;
			vertsInMatSub = true;

			F3DSubObject &sub = pModel->GetMeshChunk()->subObjects[subObject];

			const char *pRestOfLine = GetRestOfLine(pFilePtr);

			int firstVert = (int)sub.matSubobjects[matSub].vertices.size();

			pToken = GetNextToken(pRestOfLine);

			while(*pToken)
			{
				const char *pPos = GetNextIndex(pToken);
				const char *pUV = GetNextIndex(pToken);
				const char *pNorm = GetNextIndex(pToken);

				int posid = atoi(pPos);
				int texid = atoi(pUV);
				int normid = atoi(pNorm);

				if(posid < 0)
					posid = (int)verts.size() - posid;
				else
					posid = posid - 1;

				if(texid < 0)
					texid = (int)uvs.size() - texid;
				else
					texid = texid - 1;

				if(normid < 0)
					normid = (int)normals.size() - normid;
				else
					normid = normid - 1;

				minVertIndex = minVertIndex == -1 ? posid : MFMin(minVertIndex, posid);
				minUVIndex = minUVIndex == -1 ? texid : MFMin(minUVIndex, texid);
				minNormIndex = minNormIndex == -1 ? normid : MFMin(minNormIndex, normid);
				maxVertIndex = minVertIndex == -1 ? posid : MFMax(maxVertIndex, posid);
				maxUVIndex = maxUVIndex == -1 ? texid : MFMax(maxUVIndex, texid);
				maxNormIndex = maxNormIndex == -1 ? normid : MFMax(maxNormIndex, normid);

				int vi = (int)sub.matSubobjects[matSub].vertices.size();
				int f = vi - firstVert;

				F3DVertex &vert = sub.matSubobjects[matSub].vertices[firstVert + f];
				vert.position = posid;
				vert.uv[0] = texid;
				vert.normal = normid;

				// add a triangle if we are up to the third vert or beyond
				if(f >= 2)
				{
					F3DTriangle &tri = sub.matSubobjects[matSub].triangles.push();

					tri.v[0] = firstVert;
					tri.v[1] = vi-1;
					tri.v[2] = vi;
				}

				pToken = GetNextToken(pRestOfLine);
			}
		}
		else if(!MFString_CaseCmp(pToken, "usemtl"))
		{
			F3DSubObject &sub = pModel->GetMeshChunk()->subObjects[subObject];

			if(vertsInGroup && vertsInMatSub)
			{
				++matSub;
				vertsInMatSub = false;
			}

			const char *pName = GetRestOfLine(pFilePtr);

			sub.matSubobjects[matSub].materialIndex = GetMaterialID(pName);
		}
		else if(!MFString_CaseCmp(pToken, "mtllib"))
		{
			// load material info?
			//..
			
			pFilePtr = MFSeekNewline(pFilePtr);
		}
		else if(pToken[0] == '#')
		{
			pFilePtr = MFSeekNewline(pFilePtr);
		}
		else
		{
			MFDebug_Warn(2, MFStr("Unknown token encountered in obj file '%s'!", pToken));
			pFilePtr = MFSeekNewline(pFilePtr);
		}

		pToken = GetNextToken(pFilePtr);
	}

	// want to copy vertex data into the last subobject at this point...
	if(vertsInGroup)
	{
		CopyDataIntoSubobject(subObject);
	}
}
예제 #8
0
파일: focus.c 프로젝트: ThomasAdam/mvwm
void CMD_WarpToWindow(F_CMD_ARGS)
{
	int val1_unit, val2_unit, n;
	int val1, val2;
	struct monitor *m;
	int do_raise;
	char *next;
	char *token;

	next = GetNextToken(action, &token);
	if (StrEquals(token, "!raise"))
	{
		do_raise = 0;
		action = next;
	}
	else if (StrEquals(token, "raise"))
	{
		do_raise = 1;
		action = next;
	}
	else
	{
		do_raise = 1;
	}
	n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit);
	if (exc->w.wcontext != C_UNMANAGED)
	{
		if (n == 2)
		{
			warp_to_mvwm_window(
				exc, val1, val1_unit, val2, val2_unit,
				do_raise);
		}
		else
		{
			warp_to_mvwm_window(exc, 0, 0, 0, 0, do_raise);
		}
	}
	else
	{
		int x = 0;
		int y = 0;

		if (n == 2)
		{
			int wx;
			int wy;
			int ww;
			int wh;

			if (exc->w.w == None || !XGetGeometry(
				    dpy, exc->w.w, &JunkRoot, &wx, &wy,
				    (unsigned int*)&ww, (unsigned int*)&wh,
				    (unsigned int*)&JunkBW,
				    (unsigned int*)&JunkDepth))
			{
				return;
			}

			/* TA:  2014-09-11:  This window is unmanaged.  Since
			 * mvwm won't have created a window for this, fw will be
			 * NULL and hence no monitor information will be
			 * present.  Since we already know the coordinates of
			 * the unmanaged window, use those in determining the
			 * monitor to use.
			 */
			m = monitor_by_xy(wx, wy);

			if (val1_unit != m->coord.w)
			{
				x = val1;
			}
			else
			{
				x = (ww - 1) * val1 / 100;
			}
			if (val2_unit != m->coord.h)
			{
				y = val2;
			}
			else
			{
				y = (wh - 1) * val2 / 100;
			}
			if (x < 0)
			{
				x += ww;
			}
			if (y < 0)
			{
				y += wh;
			}
		}
		FWarpPointerUpdateEvpos(
			exc->x.elast, dpy, None, exc->w.w, 0, 0, 0, 0, x, y);
	}

	return;
}
예제 #9
0
bool
LocalUserLog::initFromJobAd( ClassAd* ad, const char* path_attr,
							 const char* xml_attr,
							 bool write_event_log )
{
	MyString tmp, dagmanLogFilename, logfilename;
	bool use_xml = false;
	const char* iwd = jic->jobIWD();
	int cluster = jic->jobCluster();
	int proc = jic->jobProc();
	int subproc = jic->jobSubproc();
	std::vector<const char*> logfiles;
	
	dprintf( D_FULLDEBUG, "LocalUserLog::initFromJobAd: path_attr = %s\n", path_attr);
	dprintf( D_FULLDEBUG, "LocalUserLog::initFromJobAd: xml_attr = %s\n", xml_attr);

		// Look for the "regular" user log file (e.g., UserLog or
		// StarterUserLog).
	if( ! ad->LookupString(path_attr, tmp) ) {
			// The fact that this attribute is not found in the ClassAd
			// indicates we do not want logging to a log file specified
			// in the submit file.
			// These semantics are defined in JICShadow::init.
			// We still need to check below for a DAGMan-specified
			// workflow log file for local universe!!
		dprintf( D_FULLDEBUG, "No %s found in job ClassAd\n", path_attr );

	} else {
		dprintf( D_FULLDEBUG, "LocalUserLog::initFromJobAd: tmp = %s\n",
			tmp.Value());
		if( fullpath (tmp.Value() ) ) {
				// we have a full pathname in the job ad.  however, if the
				// job is using a different iwd (namely, filetransfer is
				// being used), we want to just stick it in the local iwd
				// for the job, instead.
			if( jic->iwdIsChanged() ) {
				const char* base = condor_basename(tmp.Value());
				logfilename.formatstr( "%s/%s", iwd, base);
			} else {
				logfilename = tmp;
			}
		} else {
				// no full path, so, use the job's iwd...
			logfilename.formatstr( "%s/%s", iwd, tmp.Value());
		}
		logfiles.push_back( logfilename.Value());
	}

		// Look for the special workflow log file for DAGMan (local
		// universe only -- for other universes, the schedd or the
		// shadow will log to that file and trying to write it in
		// the starter will cause the starter to crash -- see
		// gittrac #5299).
	std::vector<ULogEventNumber> mask_vec;
	if ( jic->jobUniverse() == CONDOR_UNIVERSE_LOCAL &&
				ad->LookupString(ATTR_DAGMAN_WORKFLOW_LOG, tmp) ) {
		dprintf( D_FULLDEBUG, "LocalUserLog::initFromJobAd: %s is defined\n",
			ATTR_DAGMAN_WORKFLOW_LOG);
		dprintf( D_FULLDEBUG, "LocalUserLog::initFromJobAd: tmp = %s\n",
			tmp.Value());
		if( fullpath (tmp.Value() ) ) {
				// we have a full pathname in the job ad.  however, if the
				// job is using a different iwd (namely, filetransfer is
				// being used), we want to just stick it in the local iwd
				// for the job, instead.
			if( jic->iwdIsChanged() ) {
				const char* base = condor_basename(tmp.Value());
				dagmanLogFilename.formatstr( "%s/%s", iwd, base);
			} else {
				dagmanLogFilename = tmp;
			}
		} else {
				// no full path, so, use the job's iwd...
			dagmanLogFilename.formatstr( "%s/%s", iwd, tmp.Value());
		}
		logfiles.push_back( dagmanLogFilename.Value());
		MyString msk;
		if( ad->LookupString(ATTR_DAGMAN_WORKFLOW_MASK, msk) ) {
				// Check the mask of the DAGMan log
			dprintf( D_FULLDEBUG, "LocalUserLog::initFromJobAd: msk = %s\n",
				msk.Value());
			Tokenize(msk.Value());
			while(const char* mask = GetNextToken(",",true)) {
				dprintf( D_FULLDEBUG, "Adding \"%s\" to the mask\n",mask);
				mask_vec.push_back(ULogEventNumber(atoi(mask)));
			}
		}
	}

	if ( logfiles.empty() && write_event_log ) {
		char *global_log = param( "EVENT_LOG" );
		if ( global_log ) {
			logfiles.push_back( UNIX_NULL_FILE );
			free( global_log );
		}
	}

	if ( logfiles.empty() ) {
		return initNoLogging();
	}

	ad->LookupBool( xml_attr, use_xml );
	for(std::vector<const char*>::iterator p = logfiles.begin();
			p != logfiles.end(); ++p) {
		dprintf( D_FULLDEBUG, "LocalUserLog::initFromJobAd: UserLog "
			"file %s\n",*p);
	}
	bool ret = init( logfiles, use_xml, cluster, proc, subproc );
	if(ret) { 
		for(std::vector<ULogEventNumber>::iterator m = mask_vec.begin();
				m != mask_vec.end(); ++m) {
			u_log.AddToMask(*m);
		}
	}
	dprintf( D_FULLDEBUG, "LocalUserLog::initFromJobAd: returning %s\n",
		ret?"True":"False");
	return ret;
}
예제 #10
0
void CPragma( void )
/******************/
{
    bool    check_end = TRUE;

    /* Note that the include_alias pragma must always be processed
     * because it's intended for the preprocessor, not the compiler.
     */
    CompFlags.in_pragma = 1;
    NextToken();
    if( PragRecog( "include_alias" ) ) {
        PragIncludeAlias();
    } else if( CompFlags.cpp_output ) {
        PPCTL_ENABLE_MACROS();
        CppPrtf( "#pragma " );
        for( ; CurToken != T_NULL; ) {
            CppPrtToken();
            GetNextToken();
        }
        PPCTL_DISABLE_MACROS();
    } else if( IS_ID_OR_KEYWORD( CurToken ) ) {
        if( PragIdRecog( "on" ) ) {
            PragFlag( 1 );
        } else if( PragIdRecog( "off" ) ) {
            PragFlag( 0 );
        } else if( PragIdRecog( "aux" ) || PragIdRecog( "linkage" ) ) {
            PragAux();
        } else if( PragIdRecog( "library" ) ) {
            PragLibs();
        } else if( PragIdRecog( "comment" ) ) {
            PragComment();
        } else if( PragIdRecog( "pack" ) ) {
            PragPack();
        } else if( PragIdRecog( "alloc_text" ) ) {
            PragAllocText();
        } else if( PragIdRecog( "code_seg" ) ) {
            PragCodeSeg();
        } else if( PragIdRecog( "data_seg" ) ) {
            PragDataSeg();
        } else if( PragIdRecog( "disable_message" ) ) {
            PragEnableDisableMessage( 0 );
        } else if( PragIdRecog( "enable_message" ) ) {
            PragEnableDisableMessage( 1 );
        } else if( PragIdRecog( "include_alias" ) ) {
            PragIncludeAlias();
        } else if( PragIdRecog( "message" ) ) {
            PragMessage();
        } else if( PragIdRecog( "intrinsic" ) ) {
            PragIntrinsic( 1 );
        } else if( PragIdRecog( "function" ) ) {
            PragIntrinsic( 0 );
        } else if( PragIdRecog( "enum" ) ) {
            PragEnum();
        } else if( startPragRecog( "read_only_file" ) ) {
            PragReadOnlyFile();
        } else if( startPragRecog( "read_only_directory" ) ) {
            PragReadOnlyDir();
        } else if( PragIdRecog( "once" ) ) {
            PragOnce();
        } else if( PragIdRecog( "unroll" ) ) {
            PragUnroll();
        } else if( PragIdRecog( "STDC" ) ) {
            PragSTDC();
        } else if( PragIdRecog( "extref" ) ) {
            PragExtRef();
        } else if( PragIdRecog( "alias" ) ) {
            PragAlias();
        } else {
            check_end = FALSE;
        }
    } else {
        check_end = FALSE;
    }
    if( check_end )
        EndOfPragma();
    CompFlags.in_pragma = 0;
}
예제 #11
0
NordugridJob::NordugridJob( ClassAd *classad )
	: BaseJob( classad )
{
	char buff[4096];
	std::string error_string = "";
	char *gahp_path = NULL;

	remoteJobId = NULL;
	remoteJobState = "";
	gmState = GM_INIT;
	lastProbeTime = 0;
	probeNow = false;
	enteredCurrentGmState = time(NULL);
	lastSubmitAttempt = 0;
	numSubmitAttempts = 0;
	resourceManagerString = NULL;
	jobProxy = NULL;
	myResource = NULL;
	gahp = NULL;
	RSL = NULL;
	stageList = NULL;
	stageLocalList = NULL;

	// In GM_HOLD, we assume HoldReason to be set only if we set it, so make
	// sure it's unset when we start (unless the job is already held).
	if ( condorState != HELD &&
		 jobAd->LookupString( ATTR_HOLD_REASON, NULL, 0 ) != 0 ) {

		jobAd->AssignExpr( ATTR_HOLD_REASON, "Undefined" );
	}

	jobProxy = AcquireProxy( jobAd, error_string,
							 (TimerHandlercpp)&BaseJob::SetEvaluateState, this );
	if ( jobProxy == NULL ) {
		if ( error_string == "" ) {
			formatstr( error_string, "%s is not set in the job ad",
								  ATTR_X509_USER_PROXY );
		}
		goto error_exit;
	}

	gahp_path = param( "NORDUGRID_GAHP" );
	if ( gahp_path == NULL ) {
		error_string = "NORDUGRID_GAHP not defined";
		goto error_exit;
	}
	snprintf( buff, sizeof(buff), "NORDUGRID/%s",
			  jobProxy->subject->fqan );
	gahp = new GahpClient( buff, gahp_path );
	gahp->setNotificationTimerId( evaluateStateTid );
	gahp->setMode( GahpClient::normal );
	gahp->setTimeout( gahpCallTimeout );

	free( gahp_path );
	gahp_path = NULL;

	buff[0] = '\0';
	jobAd->LookupString( ATTR_GRID_RESOURCE, buff, sizeof(buff) );
	if ( buff[0] != '\0' ) {
		const char *token;

		Tokenize( buff );

		token = GetNextToken( " ", false );
		if ( !token || strcasecmp( token, "nordugrid" ) ) {
			formatstr( error_string, "%s not of type nordugrid",
								  ATTR_GRID_RESOURCE );
			goto error_exit;
		}

		token = GetNextToken( " ", false );
		if ( token && *token ) {
			resourceManagerString = strdup( token );
		} else {
			formatstr( error_string, "%s missing server name",
								  ATTR_GRID_RESOURCE );
			goto error_exit;
		}

	} else {
		formatstr( error_string, "%s is not set in the job ad",
							  ATTR_GRID_RESOURCE );
		goto error_exit;
	}

	myResource = NordugridResource::FindOrCreateResource( resourceManagerString,
														  jobProxy );
	myResource->RegisterJob( this );

	buff[0] = '\0';
	jobAd->LookupString( ATTR_GRID_JOB_ID, buff, sizeof(buff) );
	if ( strrchr( buff, ' ' ) ) {
		SetRemoteJobId( strrchr( buff, ' ' ) + 1 );
		myResource->AlreadySubmitted( this );
	} else {
		SetRemoteJobId( NULL );
	}

	jobAd->LookupString( ATTR_GRID_JOB_STATUS, remoteJobState );

	return;

 error_exit:
	gmState = GM_HOLD;
	if ( !error_string.empty() ) {
		jobAd->Assign( ATTR_HOLD_REASON, error_string.c_str() );
	}
	return;
}
예제 #12
0
float	SMDImporter::NextTokenAsFloat ()
{
	char seps[] = " \t\n\r";
	char *token = GetNextToken (NULL, seps);
	return atof ( token );
}
예제 #13
0
int		SMDImporter::NextTokenAsInteger ()
{
	char seps[] = " \t\n\r";
	char *token = GetNextToken (NULL, seps);
	return atoi ( token );
}
예제 #14
0
bool SMDImporter::ImportTriangles ()
{
	char seps[] = " \t\r\n";
	char sepswnl[] = " \t\r\10";

	bool nextIsTexture = false;

	char *token = NULL;
	while (1)
	{
		
		if (!nextIsTexture)
		{
			token = GetNextToken (NULL, seps);
		} else {
			token++;
		}

		if ( !strcmp ( token, "end" ) )
			return true;

		SMDTriangle* l_pTriangle = new SMDTriangle;
		m_pTriangles.Extend(1);
		
		m_pTriangles[m_pTriangles.GetUsed()-1] = l_pTriangle;
		memset ( l_pTriangle->m_szTexture, 0, MAX_PATH );
		strcpy ( l_pTriangle->m_szTexture, token );


		bool jumpNext = false;

		int rigid = 0;
		for (int v=0;v<3;v++)
		{
			
			if ( !jumpNext)
				rigid = atoi(GetNextToken (NULL, seps));

			l_pTriangle->m_pVertex.Extend(1);
			SMDVertex* l_pVert = &l_pTriangle->m_pVertex[l_pTriangle->m_pVertex.GetUsed()-1];
			l_pVert->m_vPosition.PutX ( atof(GetNextToken (NULL, seps)) );
			l_pVert->m_vPosition.PutY ( atof(GetNextToken (NULL, seps)) );
			l_pVert->m_vPosition.PutZ ( atof(GetNextToken (NULL, seps)) );
			l_pVert->m_vNormal.PutX ( atof(GetNextToken (NULL, seps)) );
			l_pVert->m_vNormal.PutY ( atof(GetNextToken (NULL, seps)) );
			l_pVert->m_vNormal.PutZ ( atof(GetNextToken (NULL, seps)) );
			l_pVert->m_vUV.PutX ( atof(GetNextToken (NULL, seps)) );
			l_pVert->m_vUV.PutY ( atof(GetNextToken (NULL, seps)) );

			token = GetNextToken (NULL, sepswnl);
			if ( isdigit( token[0] ) )
			{
				//
				// import weights
				//

				int numWeights = atoi ( token );

				for (int w=0;w<numWeights;w++)
				{
					l_pVert->m_vWeights.Extend(1);
					l_pVert->m_vWeights[l_pVert->m_vWeights.GetUsed()-1].m_iBoneID = atoi(GetNextToken (NULL, seps));
					l_pVert->m_vWeights[l_pVert->m_vWeights.GetUsed()-1].m_fWeight = atof(GetNextToken (NULL, seps));

				}
			
				jumpNext = false;
				nextIsTexture = false;

			} else {

				if ( rigid != 0 )
				{
					//
					// add rigid weight
					//

					l_pVert->m_vWeights.Extend(1);
					l_pVert->m_vWeights[l_pVert->m_vWeights.GetUsed()-1].m_iBoneID = rigid;
					l_pVert->m_vWeights[l_pVert->m_vWeights.GetUsed()-1].m_fWeight = 1.0f;

				}

				if ((token[0] == 10 ) && ( strlen(token) == 1 ))
				{
					token = GetNextToken (NULL, sepswnl);
					rigid = atoi(token);
				}
				jumpNext = true;
				
				if ( v == 2 )
					nextIsTexture = true;
			}


		}

	}

}
예제 #15
0
	//Public Function 4164
	string StringTokenizer::GetNextToken(char * DelimiterChar)
	{
	  SetDelimiterString(DelimiterChar);

	  return(GetNextToken());
	}
예제 #16
0
/* Calcola e restituisce il risultato di un'espressione in forma infissa */
double EvalInfix(const char *strExpression, char * strError)
{
    Token tok;
    Token tok_temp;
    double left, right;
    double dblRet;

    strcpy(strError, "");

    tok_temp.Type = EOL;
    tok_temp.str[0] = '@';
    tok_temp.str[1] = '\0';
    push_op(tok_temp, strError);
    if ( strError[0] != '\0' )
        return 0.0;

    left = right = 0.0;
    while ( (PreviousTokenType = GetNextToken(strExpression, &tok, TRUE)) != EOL )
    {
        if ( tok.Type == UNKNOWN )
        {
            sprintf(strError, "Error: invalid token: %s\n", tok.str);
            return 0.0;
        }
        else if ( tok.Type == VALUE )
        {
            push_val(tok.Value, strError);
            if ( strError[0] != '\0' )
                return 0.0;
        }
        else if ( tok.Type == OPAREN || tok.Type == UMINUS || tok.Type == UPLUS )
        {
            push_op(tok, strError);
            if ( strError[0] != '\0' )
                return 0.0;
        }
        else if ( tok.Type == CPAREN )
        {
            while ( top_op(strError).Type != OPAREN )
            {
                if ( strError[0] != '\0' )
                    return 0.0;

                tok_temp = pop_op(strError);
                if ( strError[0] != '\0' )
                    return 0.0;

                if ( (tok_temp.Type == EOL) || (is_empty_op()) )
                {
                    sprintf(strError, "Error: unbalanced brackets.\n");
                    return 0.0;
                }

                right = pop_val(strError);
                if ( strError[0] != '\0' )
                    return 0.0;

                if ( tok_temp.Type != UMINUS )
                {
                    left = pop_val(strError);
                    if ( strError[0] != '\0' )
                        return 0.0;

                    dblRet = BinaryOperation(left, right, tok_temp.str[0], strError);
                    if ( strError[0] != '\0' )
                        return 0.0;

                    push_val(dblRet, strError);
                    if ( strError[0] != '\0' )
                        return 0.0;
                }
                else
                {
                    push_val( -1 * right, strError );
                    if ( strError[0] != '\0' )
                        return 0.0;
                }
            }
            pop_op(strError);
            if ( strError[0] != '\0' )
                return 0.0;
        }
        else
        {
            while ( PREC_TABLE[ top_op(strError).Type ].topOfStack >= PREC_TABLE[ tok.Type ].inputSymbol )
            {
                if ( strError[0] != '\0' )
                    return 0.0;

                if ( top_op(strError).Type != UMINUS && top_op(strError).Type != UPLUS )
                {
                    if ( strError[0] != '\0' )
                        return 0.0;

                    right = pop_val(strError);
                    if ( strError[0] != '\0' )
                        return 0.0;

                    left = pop_val(strError);
                    if ( strError[0] != '\0' )
                        return 0.0;

                    tok_temp = pop_op(strError);
                    if ( strError[0] != '\0' )
                        return 0.0;

                    dblRet = BinaryOperation(left, right, tok_temp.str[0], strError);
                    if ( strError[0] != '\0' )
                        return 0.0;

                    push_val(dblRet, strError);
                    if ( strError[0] != '\0' )
                        return 0.0;
                }
                else
                {
                    if ( top_op(strError).Type == UMINUS )
                    {
                        if ( strError[0] != '\0' )
                            return 0.0;

                        right = pop_val(strError);
                        if ( strError[0] != '\0' )
                            return 0.0;

                        pop_op(strError);
                        if ( strError[0] != '\0' )
                            return 0.0;

                        push_val(-1 * right, strError);
                        if ( strError[0] != '\0' )
                            return 0.0;
                    }
                    else
                    {
                        pop_op(strError);
                        if ( strError[0] != '\0' )
                            return 0.0;
                    }
                }
            }

            if ( tok.Type != EOL )
            {
                push_op(tok, strError);
                if ( strError[0] != '\0' )
                    return 0.0;
            }
        }
    }

    while ( 1 )
    {
        tok_temp = pop_op(strError);
        if ( strError[0] != '\0' )
            return 0.0;

        if ( tok_temp.Type == EOL )
            break;

        if ( tok_temp.Type != UPLUS )
        {
            right = pop_val(strError);
            if ( strError[0] != '\0' )
                return 0.0;
        }

        if ( tok_temp.Type != UMINUS && tok_temp.Type != UPLUS )
        {
            left = pop_val(strError);
            if ( strError[0] != '\0' )
                return 0.0;

            dblRet = BinaryOperation(left, right, tok_temp.str[0], strError);
            if ( strError[0] != '\0' )
                return 0.0;

            push_val(dblRet, strError);
            if ( strError[0] != '\0' )
                return 0.0;
        }
        else
        {
            push_val( -1 * right, strError );
            if ( strError[0] != '\0' )
                return 0.0;
        }
    }

    dblRet = pop_val(strError);
    if ( strError[0] != '\0' )
        return 0.0;

    if ( is_empty_val() )
    {
        return dblRet;
    }
    else
    {
        sprintf(strError, "Error: malformed expression.\n");
        return 0.0;
    }
}
예제 #17
0
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   N T A c q u i r e T y p e C a c h e                                       %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  NTAcquireTypeCache() loads a Windows TrueType fonts.
%
%  The format of the NTAcquireTypeCache method is:
%
%      MagickBooleanType NTAcquireTypeCache(SplayTreeInfo *type_cache)
%
%  A description of each parameter follows:
%
%    o type_cache: A linked list of fonts.
%
*/
MagickExport MagickBooleanType NTAcquireTypeCache(SplayTreeInfo *type_cache,
  ExceptionInfo *exception)
{
  HKEY
    reg_key = (HKEY) INVALID_HANDLE_VALUE;

  LONG
    res;

  int
    list_entries = 0;

  char
    buffer[MagickPathExtent],
    system_root[MagickPathExtent],
    font_root[MagickPathExtent];

  DWORD
    type,
    system_root_length;

  MagickBooleanType
    status;

  /*
    Try to find the right Windows*\CurrentVersion key, the SystemRoot and
    then the Fonts key
  */
  res = RegOpenKeyExA (HKEY_LOCAL_MACHINE,
    "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &reg_key);
  if (res == ERROR_SUCCESS) {
    system_root_length=sizeof(system_root)-1;
    res = RegQueryValueExA(reg_key,"SystemRoot",NULL, &type,
      (BYTE*) system_root, &system_root_length);
  }
  if (res != ERROR_SUCCESS) {
    res = RegOpenKeyExA (HKEY_LOCAL_MACHINE,
      "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", 0, KEY_READ, &reg_key);
    if (res == ERROR_SUCCESS) {
      system_root_length=sizeof(system_root)-1;
      res = RegQueryValueExA(reg_key,"SystemRoot",NULL, &type,
        (BYTE*)system_root, &system_root_length);
    }
  }
  if (res == ERROR_SUCCESS)
    res = RegOpenKeyExA (reg_key, "Fonts",0, KEY_READ, &reg_key);
  if (res != ERROR_SUCCESS)
    return(MagickFalse);
  *font_root='\0';
  (void) CopyMagickString(buffer,system_root,MagickPathExtent);
  (void) ConcatenateMagickString(buffer,"\\fonts\\arial.ttf",MagickPathExtent);
  if (IsPathAccessible(buffer) != MagickFalse)
    {
      (void) CopyMagickString(font_root,system_root,MagickPathExtent);
      (void) ConcatenateMagickString(font_root,"\\fonts\\",MagickPathExtent);
    }
  else
    {
      (void) CopyMagickString(font_root,system_root,MagickPathExtent);
      (void) ConcatenateMagickString(font_root,"\\",MagickPathExtent);
    }

  {
    TypeInfo
      *type_info;

    DWORD
      registry_index = 0,
      type,
      value_data_size,
      value_name_length;

    char
      value_data[MagickPathExtent],
      value_name[MagickPathExtent];

    res = ERROR_SUCCESS;

    while (res != ERROR_NO_MORE_ITEMS)
      {
        char
          *family_extent,
          token[MagickPathExtent],
          *pos,
          *q;

        value_name_length = sizeof(value_name) - 1;
        value_data_size = sizeof(value_data) - 1;
        res = RegEnumValueA ( reg_key, registry_index, value_name,
          &value_name_length, 0, &type, (BYTE*)value_data, &value_data_size);
        registry_index++;
        if (res != ERROR_SUCCESS)
          continue;
        if ( (pos = strstr(value_name, " (TrueType)")) == (char*) NULL )
          continue;
        *pos='\0'; /* Remove (TrueType) from string */

        type_info=(TypeInfo *) AcquireCriticalMemory(sizeof(*type_info));
        (void) ResetMagickMemory(type_info,0,sizeof(TypeInfo));

        type_info->path=ConstantString("Windows Fonts");
        type_info->signature=MagickCoreSignature;

        /* Name */
        (void) CopyMagickString(buffer,value_name,MagickPathExtent);
        for(pos = buffer; *pos != 0 ; pos++)
          if (*pos == ' ')
            *pos = '-';
        type_info->name=ConstantString(buffer);

        /* Fullname */
        type_info->description=ConstantString(value_name);

        /* Format */
        type_info->format=ConstantString("truetype");

        /* Glyphs */
        if (strchr(value_data,'\\') != (char *) NULL)
          (void) CopyMagickString(buffer,value_data,MagickPathExtent);
        else
          {
            (void) CopyMagickString(buffer,font_root,MagickPathExtent);
            (void) ConcatenateMagickString(buffer,value_data,MagickPathExtent);
          }

        LocaleLower(buffer);
        type_info->glyphs=ConstantString(buffer);

        type_info->stretch=NormalStretch;
        type_info->style=NormalStyle;
        type_info->weight=400;

        /* Some fonts are known to require special encodings */
        if ( (LocaleCompare(type_info->name, "Symbol") == 0 ) ||
             (LocaleCompare(type_info->name, "Wingdings") == 0 ) ||
             (LocaleCompare(type_info->name, "Wingdings-2") == 0 ) ||
             (LocaleCompare(type_info->name, "Wingdings-3") == 0 ) )
          type_info->encoding=ConstantString("AppleRoman");

        family_extent=value_name;

        for (q=value_name; *q != '\0'; )
          {
            GetNextToken(q,(const char **) &q,MagickPathExtent,token);
            if (*token == '\0')
              break;

            if (LocaleCompare(token,"Italic") == 0)
              {
                type_info->style=ItalicStyle;
              }

            else if (LocaleCompare(token,"Oblique") == 0)
              {
                type_info->style=ObliqueStyle;
              }

            else if (LocaleCompare(token,"Bold") == 0)
              {
                type_info->weight=700;
              }

            else if (LocaleCompare(token,"Thin") == 0)
              {
                type_info->weight=100;
              }

            else if ( (LocaleCompare(token,"ExtraLight") == 0) ||
                      (LocaleCompare(token,"UltraLight") == 0) )
              {
                type_info->weight=200;
              }

            else if (LocaleCompare(token,"Light") == 0)
              {
                type_info->weight=300;
              }

            else if ( (LocaleCompare(token,"Normal") == 0) ||
                      (LocaleCompare(token,"Regular") == 0) )
              {
                type_info->weight=400;
              }

            else if (LocaleCompare(token,"Medium") == 0)
              {
                type_info->weight=500;
              }

            else if ( (LocaleCompare(token,"SemiBold") == 0) ||
                      (LocaleCompare(token,"DemiBold") == 0) )
              {
                type_info->weight=600;
              }

            else if ( (LocaleCompare(token,"ExtraBold") == 0) ||
                      (LocaleCompare(token,"UltraBold") == 0) )
              {
                type_info->weight=800;
              }

            else if ( (LocaleCompare(token,"Heavy") == 0) ||
                      (LocaleCompare(token,"Black") == 0) )
              {
                type_info->weight=900;
              }

            else if (LocaleCompare(token,"Condensed") == 0)
              {
                type_info->stretch = CondensedStretch;
              }

            else if (LocaleCompare(token,"Expanded") == 0)
              {
                type_info->stretch = ExpandedStretch;
              }

            else if (LocaleCompare(token,"ExtraCondensed") == 0)
              {
                type_info->stretch = ExtraCondensedStretch;
              }

            else if (LocaleCompare(token,"ExtraExpanded") == 0)
              {
                type_info->stretch = ExtraExpandedStretch;
              }

            else if (LocaleCompare(token,"SemiCondensed") == 0)
              {
                type_info->stretch = SemiCondensedStretch;
              }

            else if (LocaleCompare(token,"SemiExpanded") == 0)
              {
                type_info->stretch = SemiExpandedStretch;
              }

            else if (LocaleCompare(token,"UltraCondensed") == 0)
              {
                type_info->stretch = UltraCondensedStretch;
              }

            else if (LocaleCompare(token,"UltraExpanded") == 0)
              {
                type_info->stretch = UltraExpandedStretch;
              }

            else
              {
                family_extent=q;
              }
          }

        (void) CopyMagickString(buffer,value_name,family_extent-value_name+1);
        StripString(buffer);
        type_info->family=ConstantString(buffer);

        list_entries++;
        status=AddValueToSplayTree(type_cache,type_info->name,type_info);
        if (status == MagickFalse)
          (void) ThrowMagickException(exception,GetMagickModule(),
            ResourceLimitError,"MemoryAllocationFailed","`%s'",type_info->name);
      }
  }
  RegCloseKey ( reg_key );
  return(MagickTrue);
}
예제 #18
0
void SymbolParserThread::ParseFileSymbols(wxInputStream& input, std::vector<Symbol*>& symbols)
{

    if (!input.IsOk())
    {
        return;
    }

    wxString token;

    unsigned int lineNumber = 1;

    Symbol *return_symbol = nullptr;

    wxStack<Symbol *> symStack;
    symStack.push(nullptr);

    std::vector<Token> tokens;
    while (GetToken(input, token, lineNumber))
    {
      tokens.emplace_back(token, lineNumber);
    }

    for (unsigned current_token = 0; current_token < tokens.size(); ++current_token)
    {
      token = tokens[current_token].token;
      lineNumber = tokens[current_token].lineNumber;

      if (token == "function")
      {
        unsigned int defLineNumber = lineNumber;
        Symbol *function = nullptr;

        // Lua functions can have these forms:
        //    function (...)
        //    function Name (...)
        //    function Module.Function (...)
        //    function Class:Method (...)

        wxString t1;
        if (!GetNextToken(tokens, t1, lineNumber, current_token)) break;

        if (t1 == "(")
        {
          // The form function (...) which doesn't have a name. If we
          // were being really clever we could check to see what is being
          // done with this value, but we're not.
          continue;
        }

        wxString t2;

        if (!GetNextToken(tokens, t2, lineNumber, current_token)) break;

        if (t2 == "(")
        {
          function = new Symbol(symStack.top(), t1, defLineNumber);

          if (return_symbol)
          {
            function->typeSymbol = return_symbol;
            return_symbol = nullptr;
          }

          // The form function Name (...).
          symbols.push_back(function);
        }
        else
        {

          wxString t3;
          if (!GetNextToken(tokens, t3, lineNumber, current_token)) break;

          if (t2 == "." || t2 == ":")
          {
            Symbol *module = GetSymbol(t1, symbols);
            if (module == nullptr)
            {
              module = new Symbol(symStack.top(), t1, defLineNumber, SymbolType::Module);
              symbols.push_back(module);
            }

            function = new Symbol(module, t3, defLineNumber);
            if (return_symbol)
            {
              function->typeSymbol = return_symbol;
              return_symbol = nullptr;
            }

            symbols.push_back(function);
          }

        }


        if (function)
          symStack.push(function);

      }
      else if (token == "decodadef")
      {
        //A decodadef will be in the form:
        //decodadef name { Definitions }
        //decodadef name ret

        unsigned int defLineNumber = lineNumber;

        wxString moduleName;
        if (!GetNextToken(tokens, moduleName, lineNumber, current_token)) break;

        wxString t1 = PeekNextToken(tokens, current_token, lineNumber);
        if (t1 == "{")
        {
          if (!GetNextToken(tokens, t1, lineNumber, current_token)) break;
          //outputWin->OutputMessage("Processing " + moduleName);

          Symbol *module = GetSymbol(moduleName, symbols);
          if (module == nullptr)
          {
            module = new Symbol(symStack.top(), moduleName, lineNumber, SymbolType::Type);
            symbols.push_back(module);
          }

          DecodaDefRecursive(symbols, lineNumber, module, tokens, current_token);
        }
        else
        {
          DecodaDefFunction(symbols, lineNumber, nullptr, tokens, current_token, moduleName);
        }
      }
      else if (token == "end")
      {
        if (symStack.size() > 1)
          symStack.pop();
      }
      else if (token == "decodaprefix")
      {
        //A decodaprefix will be in the form:
        //decodaprefix Module name

        /*
        decodaprefix this __FILENAME__
        decodaprefix this { Weapon nil }

        */

        unsigned int defLineNumber = lineNumber;

        wxString moduleName;
        if (!GetNextToken(tokens, moduleName, lineNumber, current_token)) break;


        Symbol *module = GetSymbol(moduleName, symbols, SymbolType::Prefix);
        if (module == nullptr)
        {
          module = new Symbol(nullptr, moduleName, defLineNumber, SymbolType::Prefix);
          symbols.push_back(module);
        }

        wxString t1;
        if (!GetNextToken(tokens, t1, lineNumber, current_token)) break;

        //List of 
        if (t1 == "{")
        {
          DecodaPrefixRecursive(symbols, lineNumber, module, tokens, current_token);
        }
        else
        {
          Symbol *sym_prefix = new Symbol(module, t1, defLineNumber, SymbolType::Prefix);
          sym_prefix->requiredModule = moduleName;
          symbols.push_back(sym_prefix);
        }
      }
      else if (token == "decodareturn")
      {
        //A decodaprefix will be in the form:
        //decodareturn Module

        unsigned int defLineNumber = lineNumber;

        wxString moduleName;
        if (!GetNextToken(tokens, moduleName, lineNumber, current_token)) break;

        Symbol *module = GetSymbol(moduleName, symbols);
        if (module == nullptr)
        {
          module = new Symbol(symStack.top(), moduleName, lineNumber, SymbolType::Type);
          symbols.push_back(module);
        }

        return_symbol = module;
      }
      else if (token == "=")
      {
        unsigned int defLineNumber = lineNumber;

        //If we find an equal sign, we need to find the left and right hand side
        unsigned start = current_token;

        //First handle +=, -=, *=, /=
        wxString prev = PeekPrevToken(tokens, current_token, lineNumber);
        if (prev == "+" || prev == "-" || prev == "*" || prev == "/")
          GetPrevToken(tokens, prev, lineNumber, current_token);

        wxStack<wxString> lhs_stack;
        wxString lhs;
        if (!GetPrevToken(tokens, lhs, lineNumber, current_token)) break;
        
        lhs_stack.push(lhs);

        int currentLine = lineNumber;

        prev = PeekPrevToken(tokens, current_token, lineNumber);
        while ((prev == "." || prev == ":" || prev == ")" || prev == "]") && lineNumber == currentLine)
        {
          if (prev == "." || prev == ":")
          {
            GetPrevToken(tokens, prev, lineNumber, current_token);
            lhs_stack.push(prev);

            wxString part;
            if (!GetPrevToken(tokens, part, lineNumber, current_token)) return;
            if (part == ")" || part == "]")
            {
              current_token++;
              prev = part;
              continue;
            }

            lhs_stack.push(part);
          }
          else if (prev == ")" || prev == "]")
          {
            GetPrevToken(tokens, prev, lineNumber, current_token);
            lhs_stack.push(prev);

            wxString open;
            wxString close;

            if (prev == ")")
            {
              open = "(";
              close = ")";
            }
            else if (prev == "]")
            {
              open = "[";
              close = "]";
            }


            int parenStack = 0;
            wxString part;
            if (!GetPrevToken(tokens, part, lineNumber, current_token)) return;
            for (;;)
            {
              if (part == close)
                parenStack++;
              if (part == open)
              {
                if (parenStack == 0)
                  break;
                parenStack--;
              }

              lhs_stack.push(part);
              if (!GetPrevToken(tokens, part, lineNumber, current_token)) return;
            }
            lhs_stack.push(part);

            if (!GetPrevToken(tokens, part, lineNumber, current_token)) return;
            lhs_stack.push(part);
          }

          prev = PeekPrevToken(tokens, current_token, lineNumber);
        }

        //Parse rhs
        current_token = start;

        //First handle +=, -=, *=, /=
        wxString next = PeekNextToken(tokens, current_token, lineNumber);
        bool valid = true;
        for (int i = 0; i < next.size(); ++i)
        {
          if (IsSymbol(next[i]) || IsSpace(next[i]))
          {
            valid = false;
            break;
          }
        }

        wxString rhs;

        if (valid)
        {
          GetNextToken(tokens, next, lineNumber, current_token);
          rhs.Append(next);

          next = PeekNextToken(tokens, current_token, lineNumber);
          while ((next == "." || next == ":" || next == "(" || next == "[") && lineNumber == currentLine)
          {
            if (next == "." || next == ":")
            {
              GetNextToken(tokens, next, lineNumber, current_token);
              rhs.Append(next);

              wxString part;
              if (!GetNextToken(tokens, part, lineNumber, current_token)) return;
              rhs.Append(part);
            }
            else if (next == "(" || next == "[")
            {
              GetNextToken(tokens, next, lineNumber, current_token);
              rhs.Append(next);

              wxString open;
              wxString close;

              if (next == "(")
              {
                open = "(";
                close = ")";
              }
              else if (next == "[")
              {
                open = "[";
                close = "]";
              }


              int parenStack = 0;
              wxString part;
              if (!GetNextToken(tokens, part, lineNumber, current_token)) return;
              for (;;)
              {
                if (part == open)
                  parenStack++;
                if (part == close)
                {
                  if (parenStack == 0)
                    break;
                  parenStack--;
                }

                rhs.Append(part);
                if (!GetNextToken(tokens, part, lineNumber, current_token)) return;
              }
              rhs.Append(part);
            }

            next = PeekNextToken(tokens, current_token, lineNumber);
          }
        }

        //Build up the strings with the stacks
        if (lhs_stack.size() > 0 && rhs.size() > 0)
        {
          lhs.Empty();

          while (!lhs_stack.empty())
          {
            lhs.Append(lhs_stack.top());
            lhs_stack.pop();
          }

          Symbol *assignment = new Symbol(symStack.top(), lhs, defLineNumber, SymbolType::Assignment);
          assignment->rhs = rhs;
          symbols.push_back(assignment);
        }

        //Reset token
        current_token = start;
      }
    }
}
예제 #19
0
파일: focus.c 프로젝트: fvwmorg/fvwm
void CMD_WarpToWindow(F_CMD_ARGS)
{
	int val1_unit, val2_unit, n;
	int val1, val2;
	int do_raise;
	char *next;
	char *token;

	next = GetNextToken(action, &token);
	if (StrEquals(token, "!raise"))
	{
		do_raise = 0;
		action = next;
	}
	else if (StrEquals(token, "raise"))
	{
		do_raise = 1;
		action = next;
	}
	else
	{
		do_raise = 1;
	}
	n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit);
	if (exc->w.wcontext != C_UNMANAGED)
	{
		if (n == 2)
		{
			warp_to_fvwm_window(
				exc, val1, val1_unit, val2, val2_unit,
				do_raise);
		}
		else
		{
			warp_to_fvwm_window(exc, 0, 0, 0, 0, do_raise);
		}
	}
	else
	{
		int x = 0;
		int y = 0;

		if (n == 2)
		{
			int wx;
			int wy;
			int ww;
			int wh;

			if (!XGetGeometry(
				    dpy, exc->w.w, &JunkRoot, &wx, &wy,
				    (unsigned int*)&ww, (unsigned int*)&wh,
				    (unsigned int*)&JunkBW,
				    (unsigned int*)&JunkDepth))
			{
				return;
			}
			if (val1_unit != Scr.MyDisplayWidth)
			{
				x = val1;
			}
			else
			{
				x = (ww - 1) * val1 / 100;
			}
			if (val2_unit != Scr.MyDisplayHeight)
			{
				y = val2;
			}
			else
			{
				y = (wh - 1) * val2 / 100;
			}
			if (x < 0)
			{
				x += ww;
			}
			if (y < 0)
			{
				y += wh;
			}
		}
		FWarpPointerUpdateEvpos(
			exc->x.elast, dpy, None, exc->w.w, 0, 0, 0, 0, x, y);
	}

	return;
}
예제 #20
0
파일: FvwmPager.c 프로젝트: att/uwin
/*****************************************************************************
 *
 * This routine is responsible for reading and parsing the config file
 *
 ****************************************************************************/
void ParseOptions(void)
{
  char *tline= NULL;
  int desk;
  int dx = 3;
  int dy = 3;

  Scr.FvwmRoot = NULL;
  Scr.Hilite = NULL;
  Scr.VScale = 32;

  Scr.MyDisplayWidth = DisplayWidth(dpy, Scr.screen);
  Scr.MyDisplayHeight = DisplayHeight(dpy, Scr.screen);

  InitGetConfigLine(fd,CatString3("*",MyName,0));
  for (GetConfigLine(fd,&tline); tline != NULL; GetConfigLine(fd,&tline))
  {
    int g_x, g_y, flags;
    unsigned width,height;
    char *resource;
    char *resource_string;
    char *arg1;
    char *arg2;
    char *tline2;
    char *token;
    char *next;
    Bool MoveThresholdSetForModule = False;

    resource_string = arg1 = arg2 = NULL;

    token = PeekToken(tline, &next);
    if (StrEquals(token, "Colorset"))
    {
      LoadColorset(next);
      continue;
    }
    else if (StrEquals(token, XINERAMA_CONFIG_STRING))
    {
      FScreenConfigureModule(next);
    }
    else if (StrEquals(token, "DesktopSize"))
    {
      token = PeekToken(next, &next);
      if (token)
      {
	sscanf(token, "%d", &dx);
	token = PeekToken(next, &next);
	if (token)
	  sscanf(token, "%d", &dy);
      }
      continue;
    }
    else if (StrEquals(token, "ImagePath"))
    {
      if (ImagePath != NULL)
      {
	free(ImagePath);
	ImagePath = NULL;
      }
      GetNextToken(next, &ImagePath);

#ifdef DEBUG
      fprintf(stderr, "[ParseOptions]: ImagePath = %s\n", ImagePath);
#endif
      continue;
    }
    else if (StrEquals(token, "MoveThreshold"))
    {
      if (!MoveThresholdSetForModule)
      {
	int val;
	if (GetIntegerArguments(next, NULL, &val, 1) > 0)
	{
	  if (val >= 0)
	    MoveThreshold = val;
	  else
	    MoveThreshold = DEFAULT_PAGER_MOVE_THRESHOLD;
	}
      }
      continue;
    }

    tline2 = GetModuleResource(tline, &resource, MyName);
    if (!resource)
      continue;
    tline2 = GetNextToken(tline2, &arg1);
    if (!arg1)
    {
      arg1 = (char *)safemalloc(1);
      arg1[0] = 0;
    }
    tline2 = GetNextToken(tline2, &arg2);
    if (!arg2)
    {
      arg2 = (char *)safemalloc(1);
      arg2[0] = 0;
    }

    if(StrEquals(resource,"Colorset"))
    {
      ParseColorset(arg1, arg2,
		    &(((DeskInfo *)(NULL))->colorset),
		    &(((PagerStringList *)(NULL))->colorset),
		    &globalcolorset);
    }
    else if(StrEquals(resource,"BalloonColorset"))
    {
      ParseColorset(arg1, arg2,
		    &(((DeskInfo *)(NULL))->ballooncolorset),
		    &(((PagerStringList *)(NULL))->ballooncolorset),
		    &globalballooncolorset);
    }
    else if(StrEquals(resource,"HilightColorset"))
    {
      ParseColorset(arg1, arg2,
		    &(((DeskInfo *)(NULL))->highcolorset),
		    &(((PagerStringList *)(NULL))->highcolorset),
		    &globalhighcolorset);
    }
    else if (StrEquals(resource, "Geometry"))
    {
      window_w = 0;
      window_h = 0;
      window_x = 0;
      window_y = 0;
      xneg = 0;
      yneg = 0;
      usposition = 0;
      flags = FScreenParseGeometry(arg1,&g_x,&g_y,&width,&height);
      if (flags & WidthValue)
      {
	window_w = width;
      }
      if (flags & HeightValue)
      {
	window_h = height;
      }
      if (flags & XValue)
      {
	window_x = g_x;
	usposition = 1;
        if (flags & XNegative)
        {
          xneg = 1;
        }
      }
      if (flags & YValue)
      {
	window_y = g_y;
	usposition = 1;
        if (flags & YNegative)
        {
          yneg = 1;
        }
      }
    }
    else if (StrEquals(resource, "IconGeometry"))
    {
      icon_w = 0;
      icon_h = 0;
      icon_x = -10000;
      icon_y = -10000;
      icon_xneg = 0;
      icon_yneg = 0;
      flags = FScreenParseGeometry(arg1,&g_x,&g_y,&width,&height);
      if (flags & WidthValue)
	icon_w = width;
      if (flags & HeightValue)
	icon_h = height;
      if (flags & XValue)
      {
	icon_x = g_x;
        if (flags & XNegative)
        {
          icon_xneg = 1;
        }
      }
      if (flags & YValue)
      {
	icon_y = g_y;
        if (flags & YNegative)
        {
          icon_yneg = 1;
        }
      }
    }
    else if (StrEquals(resource, "Label"))
    {
      if (StrEquals(arg1, "*"))
      {
	desk = Scr.CurrentDesk;
      }
      else
      {
	desk = desk1;
	sscanf(arg1,"%d",&desk);
      }
      if (fAlwaysCurrentDesk)
      {
	PagerStringList *item;

	item = FindDeskStrings(desk);
	if (item->next != NULL)
	{
	  /* replace label */
	  if (item->next->label != NULL)
	  {
	    free(item->next->label);
	    item->next->label = NULL;
	  }
	  CopyString(&(item->next->label), arg2);
	}
	else
	{
	  /* new Dcolor and desktop */
	  item = NewPagerStringItem(item, desk);
	  CopyString(&(item->label), arg2);
	}
	if (desk == Scr.CurrentDesk)
	{
	  free(Desks[0].label);
	  CopyString(&Desks[0].label, arg2);
	}
      }
      else if((desk >= desk1)&&(desk <=desk2))
      {
	free(Desks[desk - desk1].label);
	CopyString(&Desks[desk - desk1].label, arg2);
      }
    }
    else if (StrEquals(resource, "Font"))
    {
      if (font_string)
	free(font_string);
      if (next && next[0] == '\"')
      {
	int l;

	next++;
	CopyString(&font_string, next);
	l = strlen(font_string);
	if (l > 0 && font_string[l - 1] == '\"')
	{
	  font_string[l - 1] = 0;
	}
      }
      else
      {
	CopyString(&font_string,next);
      }
      if(strncasecmp(font_string,"none",4) == 0)
	uselabel = 0;
    }
    else if (StrEquals(resource, "Fore"))
    {
      if(Pdepth > 1)
      {
	if (PagerFore)
	  free(PagerFore);
	CopyString(&PagerFore,arg1);
      }
    }
    else if (StrEquals(resource, "Back"))
    {
      if(Pdepth > 1)
      {
	if (PagerBack)
	  free(PagerBack);
	CopyString(&PagerBack,arg1);
      }
    }
    else if (StrEquals(resource, "DeskColor"))
    {
      if (StrEquals(arg1, "*"))
      {
	desk = Scr.CurrentDesk;
      }
      else
      {
	desk = desk1;
	sscanf(arg1,"%d",&desk);
      }
      if (fAlwaysCurrentDesk)
      {
	PagerStringList *item;

	item = FindDeskStrings(desk);
	if (item->next != NULL)
	{
	  /* replace Dcolor */
	  if (item->next->Dcolor != NULL)
	  {
	    free(item->next->Dcolor);
	    item->next->Dcolor = NULL;
	  }
	  CopyString(&(item->next->Dcolor), arg2);
	}
	else
	{
	  /* new Dcolor and desktop */
	  item = NewPagerStringItem(item, desk);
	  CopyString(&(item->Dcolor), arg2);
	}
	if (desk == Scr.CurrentDesk)
	{
	  free(Desks[0].Dcolor);
	  CopyString(&Desks[0].Dcolor, arg2);
	}
      }
      else if((desk >= desk1)&&(desk <=desk2))
      {
	free(Desks[desk - desk1].Dcolor);
	CopyString(&Desks[desk - desk1].Dcolor, arg2);
      }
    }
    else if (StrEquals(resource, "DeskPixmap"))
    {
      if (StrEquals(arg1, "*"))
      {
	desk = Scr.CurrentDesk;
      }
      else
      {
	desk = desk1;
	sscanf(arg1,"%d",&desk);
      }
      if (fAlwaysCurrentDesk)
      {
	PagerStringList *item;

	item = FindDeskStrings(desk);

	if (item->next != NULL)
	{
	  if (item->next->bgPixmap != NULL)
	  {
	    DestroyPicture(dpy, item->next->bgPixmap);
	    item->next->bgPixmap = NULL;
	  }
	  item->next->bgPixmap = CachePicture (dpy, Scr.Pager_w,
					       ImagePath,
					       arg2, 0);
	}
	else
	{
	  /* new Dcolor and desktop */
	  item = NewPagerStringItem(item, desk);
	  item->bgPixmap = CachePicture (dpy, Scr.Pager_w,
					 ImagePath,
					 arg2, 0);
	}
	if (desk == Scr.CurrentDesk)
	{
	  if (Desks[0].bgPixmap != NULL)
	  {
	    DestroyPicture(dpy, Desks[0].bgPixmap);
	    Desks[0].bgPixmap = NULL;
	  }

	  Desks[0].bgPixmap = CachePicture (dpy, Scr.Pager_w,
					    ImagePath,
					    arg2, 0);
	}
      }
      else if((desk >= desk1)&&(desk <=desk2))
      {
	int dNr = desk - desk1;

	if (Desks[dNr].bgPixmap != NULL)
	{
	  DestroyPicture(dpy, Desks[dNr].bgPixmap);
	  Desks[dNr].bgPixmap = NULL;
	}
	Desks[dNr].bgPixmap = CachePicture (dpy, Scr.Pager_w,
					    ImagePath,
					    arg2, 0);
      }

#ifdef DEBUG
      fprintf(stderr,
	      "[ParseOptions]: Desk %d: bgPixmap = %s\n",
	      desk, arg2);
#endif
    }
    else if (StrEquals(resource, "Pixmap"))
    {
      if(Pdepth > 1)
      {
	if (PixmapBack) {
	  DestroyPicture (dpy, PixmapBack);
	  PixmapBack = NULL;
	}

	PixmapBack = CachePicture (dpy, Scr.Pager_w,
				   ImagePath,
				   arg1, 0);
#ifdef DEBUG
	fprintf(stderr,
		"[ParseOptions]: Global: bgPixmap = %s\n", arg1);
#endif

      }
    }
    else if (StrEquals(resource, "HilightPixmap"))
    {
      if(Pdepth > 1)
      {
	if (HilightPixmap) {
	  DestroyPicture (dpy, HilightPixmap);
	  HilightPixmap = NULL;
	}

	HilightPixmap = CachePicture (dpy, Scr.Pager_w,
				      ImagePath,
				      arg1, 0);

#ifdef DEBUG
	fprintf(stderr,
		"[ParseOptions]: HilightPixmap = %s\n", arg1);
#endif

      }
    }
    else if (StrEquals(resource, "DeskHilight"))
    {
      HilightDesks = 1;
    }
    else if (StrEquals(resource, "NoDeskHilight"))
    {
      HilightDesks = 0;
    }
    else if (StrEquals(resource, "Hilight"))
    {
      if(Pdepth > 1)
      {
	if (HilightC)
	  free(HilightC);
	CopyString(&HilightC,arg1);
      }
    }
    else if (StrEquals(resource, "SmallFont"))
    {
      if (smallFont)
	free(smallFont);
      if (next && next[0] == '\"')
      {
	int l;

	next++;
	CopyString(&smallFont, next);
	l = strlen(smallFont);
	if (l > 0 && smallFont[l - 1] == '\"')
	{
	  smallFont[l - 1] = 0;
	}
      }
      else
      {
	CopyString(&smallFont,next);
      }
      if (strncasecmp(smallFont,"none",4) == 0)
      {
	free(smallFont);
	smallFont = NULL;
      }
    }
    else if (StrEquals(resource, "MiniIcons"))
    {
      MiniIcons = 1;
    }
    else if (StrEquals(resource, "StartIconic"))
    {
      StartIconic = 1;
    }
    else if (StrEquals(resource, "NoStartIconic"))
    {
      StartIconic = 0;
    }
    else if (StrEquals(resource, "LabelsBelow"))
    {
      LabelsBelow = 1;
    }
    else if (StrEquals(resource, "LabelsAbove"))
    {
      LabelsBelow = 0;
    }
    else if (FHaveShapeExtension && StrEquals(resource, "ShapeLabels"))
    {
      ShapeLabels = 1;
    }
    else if (FHaveShapeExtension && StrEquals(resource, "NoShapeLabels"))
    {
      ShapeLabels = 0;
    }
    else if (StrEquals(resource, "Rows"))
    {
      sscanf(arg1,"%d",&Rows);
    }
    else if (StrEquals(resource, "Columns"))
    {
      sscanf(arg1,"%d",&Columns);
    }
    else if (StrEquals(resource, "DeskTopScale"))
    {
      sscanf(arg1,"%d",&Scr.VScale);
    }
    else if (StrEquals(resource, "WindowColors"))
    {
      if (Pdepth > 1)
      {
	if (WindowFore)
	  free(WindowFore);
	if (WindowBack)
	  free(WindowBack);
	if (WindowHiFore)
	  free(WindowHiFore);
	if (WindowHiBack)
	  free(WindowHiBack);
	CopyString(&WindowFore, arg1);
	CopyString(&WindowBack, arg2);
	tline2 = GetNextToken(tline2, &WindowHiFore);
	GetNextToken(tline2, &WindowHiBack);
      }
    }
    else if (StrEquals(resource, "WindowBorderWidth"))
    {
      sscanf(arg1, "%d", &WindowBorderWidth);
      MinSize = 2 * WindowBorderWidth + 1;
    }
    else if (StrEquals(resource, "Window3dBorders"))
    {
      WindowBorders3d = True;
    }
    else if (StrEquals(resource,"WindowColorsets"))
    {
      sscanf(arg1,"%d",&windowcolorset);
      AllocColorset(windowcolorset);
      sscanf(arg2,"%d",&activecolorset);
      AllocColorset(activecolorset);
    }
    else if (StrEquals(resource,"WindowLabelFormat"))
    {
      if (WindowLabelFormat)
	free(WindowLabelFormat);
      CopyString(&WindowLabelFormat,arg1);
    }
    else if (StrEquals(resource, "MoveThreshold"))
    {
      int val;
      if (GetIntegerArguments(next, NULL, &val, 1) > 0 && val >= 0)
      {
	MoveThreshold = val;
	MoveThresholdSetForModule = True;
      }
    }
    else if (StrEquals(resource, "SloppyFocus"))
    {
      do_focus_on_enter = True;
    }
    else if (StrEquals(resource, "SolidSeparators"))
    {
      use_dashed_separators = False;
      use_no_separators = False;
    }
    else if (StrEquals(resource, "NoSeparators"))
    {
      use_no_separators = True;
    }
    /* ... and get Balloon config options ...
       -- [email protected] */
    else if (StrEquals(resource, "Balloons"))
    {
      if (BalloonTypeString)
	free(BalloonTypeString);
      CopyString(&BalloonTypeString, arg1);

      if ( strncasecmp(BalloonTypeString, "Pager", 5) == 0 ) {
	ShowPagerBalloons = 1;
	ShowIconBalloons = 0;
      }
      else if ( strncasecmp(BalloonTypeString, "Icon", 4) == 0 ) {
	ShowPagerBalloons = 0;
	ShowIconBalloons = 1;
      }
      else {
	ShowPagerBalloons = 1;
	ShowIconBalloons = 1;
      }

      /* turn this on initially so balloon window is created; later this
	 variable is changed to match ShowPagerBalloons or ShowIconBalloons
	 whenever we receive iconify or deiconify packets */
      ShowBalloons = 1;
    }

    else if (StrEquals(resource, "BalloonBack"))
    {
      if (Pdepth > 1)
      {
	if (BalloonBack)
	  free(BalloonBack);
	CopyString(&BalloonBack, arg1);
      }
    }

    else if (StrEquals(resource, "BalloonFore"))
    {
      if (Pdepth > 1)
      {
	if (BalloonFore)
	  free(BalloonFore);
	CopyString(&BalloonFore, arg1);
      }
    }

    else if (StrEquals(resource, "BalloonFont"))
    {
      if (BalloonFont)
	free(BalloonFont);
      CopyStringWithQuotes(&BalloonFont, next);
    }

    else if (StrEquals(resource, "BalloonBorderColor"))
    {
      if (BalloonBorderColor)
	free(BalloonBorderColor);
      CopyString(&BalloonBorderColor, arg1);
    }

    else if (StrEquals(resource, "BalloonBorderWidth"))
    {
      sscanf(arg1, "%d", &BalloonBorderWidth);
    }

    else if (StrEquals(resource, "BalloonYOffset"))
    {
      sscanf(arg1, "%d", &BalloonYOffset);
    }
    else if (StrEquals(resource,"BalloonStringFormat"))
    {
      if (BalloonFormatString)
	free(BalloonFormatString);
      CopyString(&BalloonFormatString,arg1);
    }

    free(resource);
    free(arg1);
    free(arg2);
  }

  Scr.VxMax = dx * Scr.MyDisplayWidth - Scr.MyDisplayWidth;
  Scr.VyMax = dy * Scr.MyDisplayHeight - Scr.MyDisplayHeight;
  if(Scr.VxMax <0)
    Scr.VxMax = 0;
  if(Scr.VyMax <0)
    Scr.VyMax = 0;
  Scr.VxPages = Scr.VxMax / Scr.MyDisplayWidth;
  Scr.VyPages = Scr.VyMax / Scr.MyDisplayHeight;
  Scr.VWidth = Scr.VxMax + Scr.MyDisplayWidth;
  Scr.VHeight = Scr.VyMax + Scr.MyDisplayHeight;
  Scr.Vx = 0;
  Scr.Vy = 0;

  return;
}
예제 #21
0
std::unique_ptr<ExprAST> UDFParser::ParseReturn() {
  GetNextToken();  // eat the return
  return ParsePrimary();
}
예제 #22
0
bool CConfigFile::Read( char const *pFilename )
{
	Term();

	// Read in the whole file.
	FILE *fp = fopen( pFilename, "rt" );
	if( !fp )
		return false;

	int iCurPos = 0;
	if( !VerifyNextToken( fp, "ssdatabase" ) || 
		!GetNextToken( fp, m_SSDatabase, sizeof(m_SSDatabase) ) )
	{
		fclose( fp );
		return false;
	}

	if( !VerifyNextToken( fp, "resourcepath" )  || 
		!GetNextToken( fp, m_SSResourcePath, sizeof(m_SSResourcePath) ) )
	{
		fclose( fp );
		return false;
	}

	if( !VerifyNextToken( fp, "bsppath" ) ||
		!GetNextToken( fp, m_SSBSPPath, sizeof(m_SSBSPPath) ) )
	{
		fclose( fp );
		return false;
	}

	while( VerifyNextToken( fp, "file" ) )
	{
		CConfigFile::Entry entry;
		char timeStr[512];
		if( !GetNextToken( fp, entry.m_Filename, sizeof(entry.m_Filename) ) ||
			!GetNextToken( fp, entry.m_VMFPath, sizeof(entry.m_VMFPath) ) ||
			!GetNextToken( fp, timeStr, sizeof(timeStr) ) 
		)
		{
			fclose( fp );
			return false;
		}
		
		entry.m_VMFTime = atoi( timeStr );

		// Read the email addresses.
		while(1)
		{		 
			char token[1024];

			int curPos = ftell( fp );
			if( entry.m_nEMailAddresses < CConfigFile::Entry::MAX_EMAIL_ADDRESSES && 
				GetNextToken( fp, token, sizeof(token) ) )
			{
				if( stricmp( token, "-email" ) == 0 )
				{
					CConfigFile::EMailAddress *addr = &entry.m_EMailAddresses[entry.m_nEMailAddresses];
					if( !GetNextToken( fp, addr->m_EMailAddress, sizeof(addr->m_EMailAddress) ) )
					{
						delete addr;
						fclose( fp );
						return false;
					}

					++entry.m_nEMailAddresses;
					continue;
				}
				else if( stricmp( token, "-fast" ) == 0 )
				{
					entry.m_bFastVis = true;
					continue;
				}
			}
			
			// No more options..
			fseek( fp, curPos, SEEK_SET );
			break;
		}

		m_Entries.AddToTail( entry );
	}

	fclose( fp );
	return true;
}
예제 #23
0
/* Process a style command.  First built up in a temp area.
   If valid, added to the list in a malloced area. */
void ProcessNewStyle(XEvent *eventp,
                     Window w,
                     FvwmWindow *tmp_win,
                     unsigned long context,
                     char *text,
                     int *Module)
{
    char *line;
    char *restofline,*tmp;
    name_list *nptr;
    int butt;                             /* work area for button number */
    int num,i;
    /*  RBW - 11/02/1998  */
    int tmpno1 = -1, tmpno2 = -1, tmpno3 = -1, spargs = 0;
    /**/

    name_list tname;                      /* temp area to build name list */
    int len = 0;
    icon_boxes *which = 0;                /* which current boxes to chain to */
    int is_quoted;                        /* for parsing args with quotes */

    memset(&tname, 0, sizeof(name_list)); /* init temp name_list area */

    restofline = GetNextToken(text,&tname.name); /* parse style name */
    /* in case there was no argument! */
    if((tname.name == NULL)||(restofline == NULL))/* If no name, or blank cmd */
    {
        if (tname.name)
            free(tname.name);
        return;                             /* drop it. */
    }

    SKIPSPACE;                            /* skip over white space */
    line = restofline;

    if(restofline == NULL)
    {
        free(tname.name);
        return;
    }
    while((*restofline != 0)&&(*restofline != '\n'))
    {
        SKIPSPACE;                          /* skip white space */
        /* It might make more sense to capture the whole word, fix its
           case, and use strcmp, but there aren't many caseless compares
           because of this "switch" on the first letter. */
        switch (tolower(restofline[0]))
        {
        case 'a':
            if(ITIS("ACTIVEPLACEMENT"))
            {
                SKIP("ACTIVEPLACEMENT");
                tname.on_flags |= RANDOM_PLACE_FLAG;
            }
            break;
        case 'b':
            if(ITIS("BACKCOLOR"))
            {
                SKIP("BACKCOLOR");
                GETWORD;
                if(len > 0)
                {
                    tname.BackColor = safemalloc(len+1);
                    strncpy(tname.BackColor,restofline,len);
                    tname.BackColor[len] = 0;
                    tname.off_flags |= BACK_COLOR_FLAG;
                }
                restofline = tmp;
            }
            else if (ITIS("BUTTON"))
            {
                SKIP("BUTTON");
                butt = -1; /* just in case sscanf fails */
                sscanf(restofline,"%d",&butt);
                GETWORD;
                restofline = tmp;
                SKIPSPACE;
                if (butt == 0) butt = 10;
                if (butt > 0 && butt <= 10)
                    tname.on_buttons |= (1<<(butt-1));
            }
            else if(ITIS("BorderWidth"))
            {
                SKIP("BorderWidth");
                tname.off_flags |= BW_FLAG;
                sscanf(restofline,"%d",&tname.border_width);
                GETWORD;
                restofline = tmp;
                SKIPSPACE;
            }
            break;
        case 'c':
            if(ITIS("COLOR"))
            {
                SKIP("COLOR");
                SKIPSPACE;
                tmp = restofline;
                len = 0;
                while((tmp != NULL)&&(*tmp != 0)&&(*tmp != ',')&&
                        (*tmp != '\n')&&(*tmp != '/')&&(!isspace(*tmp)))
                {
                    tmp++;
                    len++;
                }
                if(len > 0)
                {
                    tname.ForeColor = safemalloc(len+1);
                    strncpy(tname.ForeColor,restofline,len);
                    tname.ForeColor[len] = 0;
                    tname.off_flags |= FORE_COLOR_FLAG;
                }

                while(isspace(*tmp))tmp++;
                if(*tmp == '/')
                {
                    tmp++;
                    while(isspace(*tmp))tmp++;
                    restofline = tmp;
                    len = 0;
                    while((tmp != NULL)&&(*tmp != 0)&&(*tmp != ',')&&
                            (*tmp != '\n')&&(*tmp != '/')&&(!isspace(*tmp)))
                    {
                        tmp++;
                        len++;
                    }
                    if(len > 0)
                    {
                        tname.BackColor = safemalloc(len+1);
                        strncpy(tname.BackColor,restofline,len);
                        tname.BackColor[len] = 0;
                        tname.off_flags |= BACK_COLOR_FLAG;
                    }
                }
                restofline = tmp;
            }
            else if(ITIS("CirculateSkipIcon"))
            {
                SKIP("CirculateSkipIcon");
                tname.off_flags |= CIRCULATE_SKIP_ICON_FLAG;
            }
            else if(ITIS("CirculateHitIcon"))
            {
                SKIP("CirculateHitIcon");
                tname.on_flags |= CIRCULATE_SKIP_ICON_FLAG;
            }
            else if(ITIS("CLICKTOFOCUS"))
            {
                SKIP("CLICKTOFOCUS");
                tname.off_flags |= CLICK_FOCUS_FLAG;
                tname.on_flags |= SLOPPY_FOCUS_FLAG;
            }
            else if(ITIS("CirculateSkip"))
            {
                SKIP("CirculateSkip");
                tname.off_flags |= CIRCULATESKIP_FLAG;
            }
            else if(ITIS("CirculateHit"))
            {
                SKIP("CirculateHit");
                tname.on_flags |= CIRCULATESKIP_FLAG;
            }
            break;
        case 'd':
            if(ITIS("DecorateTransient"))
            {
                SKIP("DecorateTransient");
                tname.off_flags |= DECORATE_TRANSIENT_FLAG;
            }
            else if(ITIS("DUMBPLACEMENT"))
            {
                SKIP("DUMBPLACEMENT");
                tname.on_flags |= SMART_PLACE_FLAG;
            }
            break;
        case 'e':
            break;
        case 'f':
            if(ITIS("FORECOLOR"))
            {
                SKIP("FORECOLOR");
                GETWORD;
                if(len > 0)
                {
                    tname.ForeColor = safemalloc(len+1);
                    strncpy(tname.ForeColor,restofline,len);
                    tname.ForeColor[len] = 0;
                    tname.off_flags |= FORE_COLOR_FLAG;
                }
                restofline = tmp;
            }
            else if(ITIS("FVWMBUTTONS"))
            {
                SKIP("FVWMBUTTONS");
                tname.on_flags |= MWM_BUTTON_FLAG;
            }
            else if(ITIS("FVWMBORDER"))
            {
                SKIP("FVWMBORDER");
                tname.on_flags |= MWM_BORDER_FLAG;
            }
            else if(ITIS("FocusFollowsMouse"))
            {
                SKIP("FocusFollowsMouse");
                tname.on_flags |= CLICK_FOCUS_FLAG;
                tname.on_flags |= SLOPPY_FOCUS_FLAG;
            }
            break;
        case 'g':
            break;
        case 'h':
            if(ITIS("HINTOVERRIDE"))
            {
                SKIP("HINTOVERRIDE");
                tname.off_flags |= MWM_OVERRIDE_FLAG;
            }
            else if(ITIS("HANDLES"))
            {
                SKIP("HANDLES");
                tname.on_flags |= NOBORDER_FLAG;
            }
            else if(ITIS("HandleWidth"))
            {
                SKIP("HandleWidth");
                tname.off_flags |= NOBW_FLAG;
                sscanf(restofline,"%d",&tname.resize_width);
                GETWORD;
                restofline = tmp;
                SKIPSPACE;
            }
            break;
        case 'i':
            if(ITIS("IconTitle"))
            {
                SKIP("IconTitle");
                tname.on_flags |= NOICON_TITLE_FLAG;
            }
            else if(ITIS("IconBox"))
            {
                icon_boxes *IconBoxes = 0;
                SKIP("IconBox");              /* Skip over word "IconBox" */
                IconBoxes = (icon_boxes *)safemalloc(sizeof(icon_boxes));
                memset(IconBoxes, 0, sizeof(icon_boxes)); /* clear it */
                IconBoxes->IconGrid[0] = 3;   /* init grid x */
                IconBoxes->IconGrid[1] = 3;   /* init grid y */
                /* try for 4 numbers x y x y */
                num = sscanf(restofline,"%d%d%d%d",
                             &IconBoxes->IconBox[0],
                             &IconBoxes->IconBox[1],
                             &IconBoxes->IconBox[2],
                             &IconBoxes->IconBox[3]);
                if (num == 4) {               /* if 4 numbers */
                    for(i=0; i<num; i++) {
                        SKIPSPACE;
                        if (*restofline == '-') { /* If leading minus sign */
                            if (i == 0 || i == 2) { /* if a width */
                                IconBoxes->IconBox[i] += Scr.MyDisplayWidth;
                            } else {                  /* it must be a height */
                                IconBoxes->IconBox[i] += Scr.MyDisplayHeight;
                            } /* end width/height */
                        } /* end leading minus sign */
                        while((!isspace(*restofline))&&(*restofline!= 0)&&
                                (*restofline != ',')&&(*restofline != '\n'))
                            restofline++;
                    }
                    /* Note: here there is no test for valid co-ords, use geom */
                } else {                   /* Not 4 numeric args dje */
                    char geom_string[25];    /* bigger than =32767x32767+32767+32767 */
                    int geom_flags;
                    GETWORD;                    /* read in 1 word w/o advancing */
                    if(len > 0 && len < 24) {   /* if word found, not too long */
                        strncpy(geom_string,restofline,len); /* copy and null term */
                        geom_string[len] = 0;     /* null terminate it */
                        geom_flags=XParseGeometry(geom_string,
                                                  &IconBoxes->IconBox[0],
                                                  &IconBoxes->IconBox[1], /* x/y */
                                                  &IconBoxes->IconBox[2],
                                                  &IconBoxes->IconBox[3]); /* width/ht */
                        if (IconBoxes->IconBox[2] == 0) { /* zero width ind invalid */
                            fvwm_msg(ERR,"ProcessNewStyle",
                                     "IconBox requires 4 numbers or geometry! Invalid string <%s>.",
                                     geom_string);
                            free(IconBoxes);        /* Drop the box */
                            IconBoxes = 0;          /* forget about it */
                        } else {                  /* got valid iconbox geom */
                            if (geom_flags&XNegative) {
                                IconBoxes->IconBox[0] = Scr.MyDisplayWidth /* screen width */
                                                        + IconBoxes->IconBox[0] /* neg x coord */
                                                        - IconBoxes->IconBox[2] -2; /* width - 2 */
                            }
                            if (geom_flags&YNegative) {
                                IconBoxes->IconBox[1] = Scr.MyDisplayHeight /* scr height */
                                                        + IconBoxes->IconBox[1] /* neg y coord */
                                                        - IconBoxes->IconBox[3] -2; /* height - 2 */
                            }
                            IconBoxes->IconBox[2] +=
                                IconBoxes->IconBox[0]; /* x + wid = right x */
                            IconBoxes->IconBox[3] +=
                                IconBoxes->IconBox[1]; /* y + height = bottom y */
                        } /* end icon geom worked */
                    } else {                    /* no word or too long */
                        fvwm_msg(ERR,"ProcessNewStyle",
                                 "IconBox requires 4 numbers or geometry! Too long (%d).",
                                 len);
                        free(IconBoxes);          /* Drop the box */
                        IconBoxes = 0;            /* forget about it */
                    } /* end word found, not too long */
                    restofline = tmp;           /* got word, move past it */
                } /* end not 4 args */
                /* If we created an IconBox, put it in the chain. */
                if (IconBoxes != 0) {         /* If no error */
                    if (tname.IconBoxes == 0) { /* If first one */
                        tname.IconBoxes = IconBoxes; /* chain to root */
                    } else {                    /* else not first one */
                        which->next = IconBoxes;  /* add to end of chain */
                    } /* end not first one */
                    which = IconBoxes;          /* new current box. save for grid */
                } /* end no error */
            } /* end iconbox parameter */
            else if(ITIS("ICONGRID")) {
                SKIP("ICONGRID");
                SKIPSPACE;                    /* skip whitespace after keyword */
                /* The grid always affects the prior iconbox */
                if (which == 0) {             /* If no current box */
                    fvwm_msg(ERR,"ProcessNewStyle",
                             "IconGrid must follow an IconBox in same Style command");
                } else {                      /* have a place to grid */
                    num = sscanf(restofline,"%hd%hd", /* 2 shorts */
                                 &which->IconGrid[0],
                                 &which->IconGrid[1]);
                    if (num != 2
                            || which->IconGrid[0] < 1
                            || which->IconGrid[1] < 1) {
                        fvwm_msg(ERR,"ProcessNewStyle",
                                 "IconGrid needs 2 numbers > 0. Got %d numbers. x=%d y=%d!",
                                 num, (int)which->IconGrid[0], (int)which->IconGrid[1]);
                        which->IconGrid[0] = 3;   /* reset grid x */
                        which->IconGrid[1] = 3;   /* reset grid y */
                    } else {                    /* it worked */
                        GETWORD;                  /* swallow word */
                        restofline = tmp;
                        GETWORD;                  /* swallow word */
                        restofline = tmp;
                    } /* end bad grid */
                } /* end place to grid */
            } else if(ITIS("ICONFILL")) {   /* direction to fill iconbox */
                SKIP("ICONFILL");
                SKIPSPACE;                    /* skip whitespace after keyword */
                /* The fill always affects the prior iconbox */
                if (which == 0) {             /* If no current box */
                    fvwm_msg(ERR,"ProcessNewStyle",
                             "IconFill must follow an IconBox in same Style command");
                } else {                      /* have a place to fill */
                    unsigned char IconFill_1;   /* first  type direction parsed */
                    unsigned char IconFill_2;   /* second type direction parsed */
                    GETWORD;                    /* read in word for length */
                    if (Get_TBLR(restofline,&IconFill_1) == 0) { /* top/bot/lft/rgt */
                        fvwm_msg(ERR,"ProcessNewStyle",
                                 "IconFill must be followed by T|B|R|L, found %.*s.",
                                 len, restofline); /* its wrong */
                    } else {                    /* first word valid */
                        restofline = tmp;         /* swallow it */
                        SKIPSPACE;                /* skip space between words */
                        GETWORD;                  /* read in second word */
                        if (Get_TBLR(restofline,&IconFill_2) == 0) {/* top/bot/lft/rgt */
                            fvwm_msg(ERR,"ProcessNewStyle",
                                     "IconFill must be followed by T|B|R|L, found %.*s.",
                                     len, restofline); /* its wrong */
                        } else if ((IconFill_1&ICONFILLHRZ)==(IconFill_2&ICONFILLHRZ)) {
                            fvwm_msg(ERR,"ProcessNewStyle",
                                     "IconFill must specify a horizontal and vertical direction.");
                        } else {                  /* Its valid! */
                            which->IconFlags |= IconFill_1; /* merge in flags */
                            IconFill_2 &= ~ICONFILLHRZ; /* ignore horiz in 2nd arg */
                            which->IconFlags |= IconFill_2; /* merge in flags */
                        } /* end second word valid */
                    } /* end first word valid */
                    restofline = tmp;           /* swallow first or second word */
                } /* end have a place to fill */
            } /* end iconfill */
            else if(ITIS("ICON"))
            {
                SKIP("ICON");
                GETWORD;
                if(len > 0)
                {
                    tname.value = safemalloc(len+1);
                    strncpy(tname.value,restofline,len);
                    tname.value[len] = 0;
                    tname.off_flags |= ICON_FLAG;
                    tname.on_flags |= SUPPRESSICON_FLAG;
                }
                else
                    tname.on_flags |= SUPPRESSICON_FLAG;
                restofline = tmp;
            }
            break;
        case 'j':
            break;
        case 'k':
            break;
        case 'l':
            if(ITIS("LENIENCE"))
            {
                SKIP("LENIENCE");
                tname.off_flags |= LENIENCE_FLAG;
            }
            break;
        case 'm':
            if(ITIS("MWMBUTTONS"))
            {
                SKIP("MWMBUTTONS");
                tname.off_flags |= MWM_BUTTON_FLAG;
            }
#ifdef MINI_ICONS
            else if (ITIS("MINIICON"))
            {
                SKIP("MINIICON");
                GETWORD;
                if(len > 0)
                {
                    tname.mini_value = safemalloc(len+1);
                    strncpy(tname.mini_value,restofline,len);
                    tname.mini_value[len] = 0;
                    tname.off_flags |= MINIICON_FLAG;
                }
                restofline = tmp;
            }
#endif
            else if(ITIS("MWMBORDER"))
            {
                SKIP("MWMBORDER");
                tname.off_flags |= MWM_BORDER_FLAG;
            }
            else if(ITIS("MWMDECOR"))
            {
                SKIP("MWMDECOR");
                tname.off_flags |= MWM_DECOR_FLAG;
            }
            else if(ITIS("MWMFUNCTIONS"))
            {
                SKIP("MWMFUNCTIONS");
                tname.off_flags |= MWM_FUNCTIONS_FLAG;
            }
            else if(ITIS("MOUSEFOCUS"))
            {
                SKIP("MOUSEFOCUS");
                tname.on_flags |= CLICK_FOCUS_FLAG;
                tname.on_flags |= SLOPPY_FOCUS_FLAG;
            }
            break;
        case 'n':
            if(ITIS("NoIconTitle"))
            {
                SKIP("NoIconTitle");
                tname.off_flags |= NOICON_TITLE_FLAG;
            }
            else if(ITIS("NOICON"))
            {
                SKIP("NOICON");
                tname.off_flags |= SUPPRESSICON_FLAG;
            }
            else if(ITIS("NOTITLE"))
            {
                SKIP("NOTITLE");
                tname.off_flags |= NOTITLE_FLAG;
            }
            else if(ITIS("NoPPosition"))
            {
                SKIP("NoPPosition");
                tname.off_flags |= NO_PPOSITION_FLAG;
            }
            else if(ITIS("NakedTransient"))
            {
                SKIP("NakedTransient");
                tname.on_flags |= DECORATE_TRANSIENT_FLAG;
            }
            else if(ITIS("NODECORHINT"))
            {
                SKIP("NODECORHINT");
                tname.on_flags |= MWM_DECOR_FLAG;
            }
            else if(ITIS("NOFUNCHINT"))
            {
                SKIP("NOFUNCHINT");
                tname.on_flags |= MWM_FUNCTIONS_FLAG;
            }
            else if(ITIS("NOOVERRIDE"))
            {
                SKIP("NOOVERRIDE");
                tname.on_flags |= MWM_OVERRIDE_FLAG;
            }
            else if(ITIS("NOHANDLES"))
            {
                SKIP("NOHANDLES");
                tname.off_flags |= NOBORDER_FLAG;
            }
            else if(ITIS("NOLENIENCE"))
            {
                SKIP("NOLENIENCE");
                tname.on_flags |= LENIENCE_FLAG;
            }
            else if (ITIS("NOBUTTON"))
            {
                SKIP("NOBUTTON");

                butt = -1; /* just in case sscanf fails */
                sscanf(restofline,"%d",&butt);
                GETWORD;
                SKIPSPACE;

                if (butt == 0) butt = 10;
                if (butt > 0 && butt <= 10)
                    tname.off_buttons |= (1<<(butt-1));
                restofline = tmp;
            }
            else if(ITIS("NOOLDECOR"))
            {
                SKIP("NOOLDECOR");
                tname.on_flags |= OL_DECOR_FLAG;
            }
            break;
        case 'o':
            if(ITIS("OLDECOR"))
            {
                SKIP("OLDECOR");
                tname.off_flags |= OL_DECOR_FLAG;
            }
            break;
        case 'p':
            break;
        case 'q':
            break;
        case 'r':
            if(ITIS("RANDOMPLACEMENT"))
            {
                SKIP("RANDOMPLACEMENT");
                tname.off_flags |= RANDOM_PLACE_FLAG;
            }
            break;
        case 's':
            if(ITIS("SMARTPLACEMENT"))
            {
                SKIP("SMARTPLACEMENT");
                tname.off_flags |= SMART_PLACE_FLAG;
            }
            else if(ITIS("SkipMapping"))
            {
                SKIP("SkipMapping");
                tname.off_flags |= SHOW_MAPPING;
            }
            else if(ITIS("ShowMapping"))
            {
                SKIP("ShowMapping");
                tname.on_flags |= SHOW_MAPPING;
            }
            else if(ITIS("StickyIcon"))
            {
                SKIP("StickyIcon");
                tname.off_flags |= STICKY_ICON_FLAG;
            }
            else if(ITIS("SlipperyIcon"))
            {
                SKIP("SlipperyIcon");
                tname.on_flags |= STICKY_ICON_FLAG;
            }
            else if(ITIS("SLOPPYFOCUS"))
            {
                SKIP("SLOPPYFOCUS");
                tname.on_flags |= CLICK_FOCUS_FLAG;
                tname.off_flags |= SLOPPY_FOCUS_FLAG;
            }
            else if(ITIS("StartIconic"))
            {
                SKIP("StartIconic");
                tname.off_flags |= START_ICONIC_FLAG;
            }
            else if(ITIS("StartNormal"))
            {
                SKIP("StartNormal");
                tname.on_flags |= START_ICONIC_FLAG;
            }
            else if(ITIS("StaysOnTop"))
            {
                SKIP("StaysOnTop");
                tname.off_flags |= STAYSONTOP_FLAG;
            }
            else if(ITIS("StaysPut"))
            {
                SKIP("StaysPut");
                tname.on_flags |= STAYSONTOP_FLAG;
            }
            else if(ITIS("Sticky"))
            {
                tname.off_flags |= STICKY_FLAG;
                SKIP("Sticky");
            }
            else if(ITIS("Slippery"))
            {
                tname.on_flags |= STICKY_FLAG;
                SKIP("Slippery");
            }
            else if(ITIS("STARTSONDESK"))
            {
                SKIP("STARTSONDESK");
                tname.off_flags |= STARTSONDESK_FLAG;
                /*  RBW - 11/02/1998  */
                spargs = sscanf(restofline,"%d",&tmpno1);
                if (spargs == 1)
                {
                    /*  RBW - 11/20/1998 - allow for the special case of -1  */
                    tname.Desk = (tmpno1 > -1) ? tmpno1 + 1 : tmpno1;
                }
                else
                {
                    tname.off_flags &= ~STARTSONDESK_FLAG;
                    fvwm_msg(ERR,"ProcessNewStyle",
                             "bad StartsOnDesk arg: %s", restofline);
                }
                /**/
                GETWORD;
                restofline = tmp;
                SKIPSPACE;
            }
            /*  RBW - 11/02/1998
                StartsOnPage is like StartsOnDesk-Plus
            */
            else if(ITIS("STARTSONPAGE"))
            {
                SKIP("STARTSONPAGE");
                tname.off_flags |= STARTSONDESK_FLAG;
                spargs = sscanf(restofline,"%d %d %d", &tmpno1, &tmpno2, &tmpno3);

                if (spargs == 1 || spargs == 3)
                {
                    /*  We have a desk no., with or without page.  */
                    /*  RBW - 11/20/1998 - allow for the special case of -1  */
                    tname.Desk = (tmpno1 > -1) ? tmpno1 + 1 : tmpno1;  /*  Desk is now actual + 1  */
                    /*  Bump past desk no.    */
                    GETWORD;
                    restofline = tmp;
                    SKIPSPACE;
                }

                if (spargs == 2 || spargs == 3)
                {
                    if (spargs == 3)
                    {
                        /*  RBW - 11/20/1998 - allow for the special case of -1  */
                        tname.PageX = (tmpno2 > -1) ? tmpno2 + 1 : tmpno2;
                        tname.PageY = (tmpno3 > -1) ? tmpno3 + 1 : tmpno3;
                    }
                    else
                    {
                        tname.PageX       =  (tmpno1 > -1) ? tmpno1 + 1 : tmpno1;
                        tname.PageY       =  (tmpno2 > -1) ? tmpno2 + 1 : tmpno2;
                    }
                    /*  Bump past next 2 args.    */
                    GETWORD;
                    restofline = tmp;
                    SKIPSPACE;
                    GETWORD;
                    restofline = tmp;
                    SKIPSPACE;

                }
                if (spargs < 1 || spargs > 3)
                {
                    tname.off_flags &= ~STARTSONDESK_FLAG;
                    fvwm_msg(ERR,"ProcessNewStyle",
                             "bad StartsOnPage args: %s", restofline);
                }

            }
            /**/
            else if(ITIS("STARTSANYWHERE"))
            {
                SKIP("STARTSANYWHERE");
                tname.on_flags |= STARTSONDESK_FLAG;
            }
            break;
        case 't':
            if(ITIS("TITLE"))
            {
                SKIP("TITLE");
                tname.on_flags |= NOTITLE_FLAG;
            }
            break;
        case 'u':
            if(ITIS("UsePPosition"))
            {
                SKIP("UsePPosition");
                tname.on_flags |= NO_PPOSITION_FLAG;
            }
#ifdef USEDECOR
            if(ITIS("UseDecor"))
            {
                SKIP("UseDecor");
                GETQUOTEDWORD;
                if (len > 0)
                {
                    tname.Decor = safemalloc(len+1);
                    strncpy(tname.Decor,restofline,len);
                    tname.Decor[len] = 0;
                }
                restofline = tmp;
            }
#endif
            else if(ITIS("UseStyle"))
            {
                SKIP("UseStyle");
                GETQUOTEDWORD;
                if (len > 0) {
                    int hit = 0;
                    /* changed to accum multiple Style definitions ([email protected]) */
                    for ( nptr = Scr.TheList; nptr; nptr = nptr->next ) {
                        if (!strncasecmp(restofline,nptr->name,len)) { /* match style */
                            if (!hit) {             /* first match */
                                char *save_name;
                                save_name = tname.name;
                                memcpy((void*)&tname, (const void*)nptr, sizeof(name_list)); /* copy everything */
                                tname.next = 0;       /* except the next pointer */
                                tname.name = save_name; /* and the name */
                                hit = 1;              /* set not first match */
                            } else {                /* subsequent match */
                                tname.off_flags     |= nptr->off_flags;
                                tname.on_flags      &= ~(nptr->on_flags);
                                tname.off_buttons   |= nptr->off_buttons;
                                tname.on_buttons    &= ~(nptr->on_buttons);
                                if(nptr->value) tname.value = nptr->value;
#ifdef MINI_ICONS
                                if(nptr->mini_value) tname.mini_value = nptr->mini_value;
#endif
#ifdef USEDECOR
                                if(nptr->Decor) tname.Decor = nptr->Decor;
#endif
                                if(nptr->off_flags & STARTSONDESK_FLAG)
                                    /*  RBW - 11/02/1998  */
                                {
                                    tname.Desk = nptr->Desk;
                                    tname.PageX = nptr->PageX;
                                    tname.PageY = nptr->PageY;
                                }
                                /**/
                                if(nptr->off_flags & BW_FLAG)
                                    tname.border_width = nptr->border_width;
                                if(nptr->off_flags & NOBW_FLAG)
                                    tname.resize_width = nptr->resize_width;
                                if(nptr->off_flags & FORE_COLOR_FLAG)
                                    tname.ForeColor = nptr->ForeColor;
                                if(nptr->off_flags & BACK_COLOR_FLAG)
                                    tname.BackColor = nptr->BackColor;
                                tname.IconBoxes = nptr->IconBoxes; /* use same chain */
                            } /* end hit/not hit */
                        } /* end found matching style */
                    } /* end looking at all styles */
                    restofline = tmp;           /* move forward one word */
                    if (!hit) {
                        tmp=safemalloc(500);
                        strlcat(tmp,"UseStyle: ", 500);
                        strlcat(tmp,restofline-len,500);
                        strlcat(tmp," style not found!",500);
                        fvwm_msg(ERR,"ProcessNewStyle",tmp);
                        free(tmp);
                    }
                }
                while(isspace(*restofline)) restofline++;
            }
            break;
        case 'v':
            break;
        case 'w':
            if(ITIS("WindowListSkip"))
            {
                SKIP("WindowListSkip");
                tname.off_flags |= LISTSKIP_FLAG;
            }
            else if(ITIS("WindowListHit"))
            {
                SKIP("WindowListHit");
                tname.on_flags |= LISTSKIP_FLAG;
            }
            break;
        case 'x':
            break;
        case 'y':
            break;
        case 'z':
            break;
        default:
            break;
        }

        SKIPSPACE;
        if(*restofline == ',')
            restofline++;
        else if((*restofline != 0)&&(*restofline != '\n'))
        {
            fvwm_msg(ERR,"ProcessNewStyle",
                     "bad style command: %s", restofline);
            /* Can't return here since all malloced memory will be lost. Ignore rest
             * of line instead. */
            break;
        }
    } /* end while still stuff on command */

    /* capture default icons */
    if(strcmp(tname.name,"*") == 0)
    {
        if(tname.off_flags & ICON_FLAG)
            Scr.DefaultIcon = tname.value;
        tname.off_flags &= ~ICON_FLAG;
        tname.value = NULL;
    }
    AddToList(&tname);                /* add temp name list to list */
}
예제 #24
0
/***********************************************************************
 *
 *  Procedure:
 *	ExecuteFunction - execute a fvwm built in function
 *
 *  Inputs:
 *	Action	- the menu action to execute
 *	tmp_win	- the fvwm window structure
 *	eventp	- pointer to the event that caused the function
 *	context - the context in which the button was pressed
 *
 ***********************************************************************/
void ExecuteFunction(char *Action, FvwmWindow *tmp_win, XEvent *eventp,
		     unsigned long context, int Module)
{
  Window w;
  int matched,j;
  char *function;
  char *action, *taction;
  char *arguments[10];
  struct functions *bif;

  if (!Action || Action[0] == 0 || Action[1] == 0)
  {
    /* impossibly short command */
    return;                             /* done */
  }
  if (Action[0] == '#') {               /* a comment */
    return;                             /* done */
  }
  /* Note: the module config command, "*" can not be handled by the
     regular command table because there is no required white space after
     the asterisk. */
  if (Action[0] == '*') {               /* a module config command */
    ModuleConfig(NULL,0,0,0,Action,0);  /* process the command */
    return;                             /* done */
  }

  for(j=0;j<10;j++)
    arguments[j] = NULL;

  if(tmp_win == NULL)
    w = Scr.Root;
  else
    w = tmp_win->w;

  if((tmp_win) &&(eventp))
    w = eventp->xany.window;
  if((tmp_win)&&(eventp->xbutton.subwindow != None)&&
     (eventp->xany.window != tmp_win->w))
    w = eventp->xbutton.subwindow;

  taction = expand(Action,arguments,tmp_win);
  action = GetNextToken(taction,&function);
  if (!function)
    return;
  j=0;
  matched = FALSE;

  bif = FindBuiltinFunction(function);
  if (bif)
  {
    matched = TRUE;
    bif->action(eventp,w,tmp_win,context,action,&Module);
  }

  if(!matched)
    {
      desperate = 1;
      ComplexFunction(eventp,w,tmp_win,context,taction, &Module);
      if(desperate)
	executeModule(eventp,w,tmp_win,context,taction, &Module);
      desperate = 0;
    }

  /* Only wait for an all-buttons-up condition after calls from
   * regular built-ins, not from complex-functions or modules. */
  if(Module == -1)
    WaitForButtonsUp();

  if (function)
    free(function);
  if(taction != NULL)
    free(taction);
  return;
}
예제 #25
0
static void menu_func(F_CMD_ARGS, Bool fStaysUp)
{
	struct MenuRoot *menu;
	char *ret_action = NULL;
	struct MenuOptions mops;
	char *menu_name = NULL;
	struct MenuParameters mp;
	struct MenuReturn mret;
	FvwmWindow * const fw = exc->w.fw;
	const Window w = exc->w.w;
	const exec_context_t *exc2;

	memset(&mops, 0, sizeof(mops));
	memset(&mret, 0, sizeof(MenuReturn));
	action = GetNextToken(action,&menu_name);
	action = get_menu_options(
		action, w, fw, NULL, NULL, NULL, &mops);
	while (action && *action && isspace((unsigned char)*action))
	{
		action++;
	}
	if (action && *action == 0)
	{
		action = NULL;
	}
	menu = menus_find_menu(menu_name);
	if (menu == NULL)
	{
		if (menu_name)
		{
			fvwm_msg(ERR,"menu_func","No such menu %s",menu_name);
			free(menu_name);
		}
		return;
	}
	if (menu_name &&
	    set_repeat_data(
		    menu_name, (fStaysUp) ? REPEAT_MENU : REPEAT_POPUP,NULL))
	{
		free(menu_name);
	}

	memset(&mp, 0, sizeof(mp));
	mp.menu = menu;
	exc2 = exc_clone_context(exc, NULL, 0);
	mp.pexc = &exc2;
	MR_IS_TEAR_OFF_MENU(menu) = 0;
	mp.flags.has_default_action = (action != NULL);
	mp.flags.is_sticky = fStaysUp;
	mp.flags.is_submenu = False;
	mp.flags.is_already_mapped = False;
	mp.flags.is_triggered_by_keypress =
		(exc->x.etrigger->type == KeyPress);
	mp.pops = &mops;
	mp.ret_paction = &ret_action;
	do_menu(&mp, &mret);
	if (mret.rc == MENU_DOUBLE_CLICKED && action)
	{
		execute_function(cond_rc, exc2, action, 0);
	}
	if (ret_action != NULL)
	{
		free(ret_action);
	}
	exc_destroy_context(exc2);

	return;
}
inline bool ParseGDBWatchValue(cb::shared_ptr<GDBWatch> watch, wxString const &value, int &start, int length)
{
    watch->SetDebugValue(value);
    watch->MarkChildsAsRemoved();

    int position = start;
    Token token, token_name, token_value;
    wxString pythonToStringValue;
    bool skip_comma = false;
    bool last_was_closing_brace = false;
    int added_children = 0;
    int token_real_end = 0;
    while (GetNextToken(value, position, token))
    {
        token_real_end = token.end;
        token.Trim(value);
        const wxString &str = token.ExtractString(value);
        if (str.StartsWith(wxT("members of ")))
        {
            wxString::size_type pos = str.find(wxT('\n'));
            if (pos == wxString::npos)
            {
                // If the token has no '\n' character, then we have to search the whole value
                // for the token and then we skip this token completely.
                wxString::size_type pos_val = value.find(wxT('\n'), token_real_end);
                if (pos_val == wxString::npos)
                    return false;
                position = pos_val+1;
                if (length > 0 && position >= start + length)
                    break;
                continue;
            }
            else
            {
                // If we have the '\n' in the token, then we have the next valid token, too,
                // so we correct the current token to be the correct one.
                if (str.find_last_of(wxT(':'), pos) == wxString::npos)
                    return false;
                token.start += pos + 2;
                token.Trim(value);
            }
        }

        if (!token.hasRepeatedChar && regexRepeatedChar.Matches(str))
        {
            Token expanded_token = token;
            while (1)
            {
                if (value[expanded_token.end] == wxT(','))
                {
                    position = token.end + 1;
                    token_real_end = position;
                    int comma_end = expanded_token.end;
                    if (GetNextToken(value, position, expanded_token))
                    {
                        const wxString &expanded_str = expanded_token.ExtractString(value);
                        if (!expanded_str.empty() && (expanded_str[0] != wxT('"') && expanded_str[0] != wxT('\'')))
                        {
                            token.end = comma_end;
                            position = comma_end;
                            token_real_end = comma_end;
                            break;
                        }
                        token.end = expanded_token.end;
                        if (regexRepeatedChar.Matches(expanded_str))
                            continue;
                        token_real_end = expanded_token.end;
                    }
                }
                else if (expanded_token.end == static_cast<int>(value.length()))
                {
                    token.end = expanded_token.end;
                    token_real_end = expanded_token.end;
                }
                break;
            }
        }

        switch (token.type)
        {
        case Token::String:
            if (token_name.type == Token::Undefined)
                token_name = token;
            else if (token_value.type == Token::Undefined)
            {
                if (   wxIsdigit(str[0])
                    || str[0]==wxT('\'')
                    || str[0]==wxT('"')
                    || str[0]==wxT('<')
                    || str[0]==wxT('-')
                    || str.StartsWith(wxT("L\""))
                    || str.StartsWith(wxT("L'")) )
                {
                    token_value = token;
                }
                else
                {
                    // Detect strings generated by python pretty printing to_string() method.
                    Token expanded_token = token;
                    int firstCloseBrace = -1;
                    for (; expanded_token.end < static_cast<int>(value.length()); ++expanded_token.end)
                    {
                        if (value[expanded_token.end] == wxT('='))
                        {
                            bool foundBrace = false;
                            for (int ii = expanded_token.end + 1; ii < static_cast<int>(value.length()); ++ii)
                            {
                                if (value[ii] == wxT('{'))
                                {
                                    foundBrace = true;
                                    break;
                                }
                                else if (value[ii] != wxT(' ') && value[ii] != wxT('\t')
                                         && value[ii] != wxT('\n') && value[ii] != wxT(' '))
                                {
                                    break;
                                }

                            }
                            if (foundBrace)
                            {
                                token.end = token_real_end = expanded_token.end;
                                token_value = token;
                                token_value.end--;
                                pythonToStringValue = token_value.ExtractString(value);
                            }
                            else
                            {
                                while (expanded_token.end >= 0)
                                {
                                    if (value[expanded_token.end] == wxT(','))
                                    {
                                        token.end = token_real_end = expanded_token.end;
                                        token_value = token;
                                        pythonToStringValue = token_value.ExtractString(value);
                                        break;
                                    }
                                    expanded_token.end--;
                                }
                            }
                            break;
                        }
                        else if (firstCloseBrace == -1 && value[expanded_token.end] == wxT('}'))
                        {
                            firstCloseBrace=expanded_token.end;
                            break;
                        }
                    }

                    if (pythonToStringValue.empty())
                    {
                        if (firstCloseBrace == -1)
                            return false;
                        token.end = token_real_end = firstCloseBrace;
                        token_value = token;
                        pythonToStringValue = token_value.ExtractString(value);
                        if (pythonToStringValue.empty())
                            return false;
                    }
                }
            }
            else
                return false;
            last_was_closing_brace = false;
            break;
        case Token::Equal:
            last_was_closing_brace = false;
            break;
        case Token::Comma:
            pythonToStringValue = wxEmptyString;
            last_was_closing_brace = false;
            if (skip_comma)
                skip_comma = false;
            else
            {
                if (token_name.type != Token::Undefined)
                {
                    if (token_value.type != Token::Undefined)
                    {
                        cb::shared_ptr<GDBWatch> child = AddChild(watch, value, token_name);
                        child->SetValue(token_value.ExtractString(value));
                    }
                    else
                    {
                        int start_arr = watch->IsArray() ? watch->GetArrayStart() : 0;
                        cb::shared_ptr<GDBWatch> child = AddChild(watch, wxString::Format(wxT("[%d]"), start_arr + added_children));
                        child->SetValue(token_name.ExtractString(value));
                    }
                    token_name.type = token_value.type = Token::Undefined;
                    added_children++;
                }
                else
                    return false;
            }
            break;
        case Token::OpenBrace:
            {
                cb::shared_ptr<GDBWatch> child;
                if(token_name.type == Token::Undefined)
                {
                    int start_arr = watch->IsArray() ? watch->GetArrayStart() : 0;
                    child = AddChild(watch, wxString::Format(wxT("[%d]"), start_arr + added_children));
                }
                else
                    child = AddChild(watch, value, token_name);
                if (!pythonToStringValue.empty())
                    child->SetValue(pythonToStringValue);
                position = token_real_end;
                added_children++;

                if(!ParseGDBWatchValue(child, value, position, 0))
                    return false;
                token_real_end = position;
                token_name.type = token_value.type = Token::Undefined;
                skip_comma = true;
                last_was_closing_brace = true;
            }
            break;
        case Token::CloseBrace:
            if (!last_was_closing_brace)
            {
                if (token_name.type != Token::Undefined)
                {
                    if (token_value.type != Token::Undefined)
                    {
                        cb::shared_ptr<GDBWatch> child = AddChild(watch, value, token_name);
                        child->SetValue(token_value.ExtractString(value));
                    }
                    else
                    {
                        int start_arr = watch->IsArray() ? watch->GetArrayStart() : 0;
                        cb::shared_ptr<GDBWatch> child = AddChild(watch, wxString::Format(wxT("[%d]"),
                                                                                          start_arr + added_children));
                        child->SetValue(token_name.ExtractString(value));
                    }
                    token_name.type = token_value.type = Token::Undefined;
                    added_children++;
                }
                else
                    watch->SetValue(wxT(""));
            }

            start = token_real_end;
            return true;
        case Token::Undefined:
        default:
            return false;
        }

        position = token_real_end;
        if (length > 0 && position >= start + length)
            break;
    }

    start = position + 1;
    if (token_name.type != Token::Undefined)
    {
        if (token_value.type != Token::Undefined)
        {
            cb::shared_ptr<GDBWatch> child = AddChild(watch, value, token_name);
            child->SetValue(token_value.ExtractString(value));
        }
        else
        {
            int start_arr = watch->IsArray() ? watch->GetArrayStart() : 0;
            cb::shared_ptr<GDBWatch> child = AddChild(watch, wxString::Format(wxT("[%d]"), start_arr + added_children));
            child->SetValue(token_name.ExtractString(value));
        }
    }

    return true;
}
예제 #27
0
파일: Parser.cpp 프로젝트: StefanL74/XCSoar
/**
 * Recursively parse an XML element.
 */
static bool
XML::ParseXMLElement(XMLNode &node, Parser *pXML)
{
  const TCHAR *temp = NULL;
  size_t temp_length;
  bool is_declaration;
  const TCHAR *text = NULL;
  XMLNode *pNew;
  enum Status status; // inside or outside a tag
  enum Attrib attrib = eAttribName;

  assert(pXML);

  // If this is the first call to the function
  if (pXML->nFirst) {
    // Assume we are outside of a tag definition
    pXML->nFirst = false;
    status = eOutsideTag;
  } else {
    // If this is not the first call then we should only be called when inside a tag.
    status = eInsideTag;
  }

  // Iterate through the tokens in the document
  while (true) {
    // Obtain the next token
    size_t token_length;
    enum TokenTypeTag type;
    NextToken token = GetNextToken(pXML, token_length, type);
    if (gcc_unlikely(type == eTokenError))
      return false;

    // Check the current status
    switch (status) {
      // If we are outside of a tag definition
    case eOutsideTag:

      // Check what type of token we obtained
      switch (type) {
        // If we have found text or quoted text
      case eTokenText:
      case eTokenQuotedText:
      case eTokenEquals:
        if (text == NULL)
          text = token.pStr;

        break;

        // If we found a start tag '<' and declarations '<?'
      case eTokenTagStart:
      case eTokenDeclaration:
        // Cache whether this new element is a declaration or not
        is_declaration = type == eTokenDeclaration;

        // If we have node text then add this to the element
        if (text != NULL) {
          temp_length = FindEndOfText(text, token.pStr - text);
          node.AddText(text, temp_length);
          text = NULL;
        }

        // Find the name of the tag
        token = GetNextToken(pXML, token_length, type);

        // Return an error if we couldn't obtain the next token or
        // it wasnt text
        if (type != eTokenText) {
          pXML->error = eXMLErrorMissingTagName;
          return false;
        }

        // If we found a new element which is the same as this
        // element then we need to pass this back to the caller..

#ifdef APPROXIMATE_PARSING
        if (d->name && CompareTagName(d->name, token.pStr)) {
          // Indicate to the caller that it needs to create a
          // new element.
          pXML->lpNewElement = token.pStr;
          pXML->cbNewElement = token_length;
          return true;
        }
#endif

        // If the name of the new element differs from the name of
        // the current element we need to add the new element to
        // the current one and recurse
        pNew = &node.AddChild(token.pStr, token_length,
                              is_declaration);

        while (true) {
          // Callself to process the new node.  If we return
          // FALSE this means we dont have any more
          // processing to do...

          if (!ParseXMLElement(*pNew, pXML)) {
            return false;
          } else {
            // If the call to recurse this function
            // evented in a end tag specified in XML then
            // we need to unwind the calls to this
            // function until we find the appropriate node
            // (the element name and end tag name must
            // match)
            if (pXML->cbEndTag) {
              // If we are back at the root node then we
              // have an unmatched end tag
              if (node.GetName() == NULL) {
                pXML->error = eXMLErrorUnmatchedEndTag;
                return false;
              }

              // If the end tag matches the name of this
              // element then we only need to unwind
              // once more...

              if (CompareTagName(node.GetName(), pXML->lpEndTag)) {
                pXML->cbEndTag = 0;
              }

              return true;
            } else if (pXML->cbNewElement) {
              // If the call indicated a new element is to
              // be created on THIS element.

              // If the name of this element matches the
              // name of the element we need to create
              // then we need to return to the caller
              // and let it process the element.

              if (CompareTagName(node.GetName(), pXML->lpNewElement))
                return true;

              // Add the new element and recurse
              pNew = &node.AddChild(pXML->lpNewElement, pXML->cbNewElement,
                                    false);
              pXML->cbNewElement = 0;
            } else {
              // If we didn't have a new element to create
              break;
            }
          }
        }
        break;

        // If we found an end tag
      case eTokenTagEnd:

        // If we have node text then add this to the element
        if (text != NULL) {
          temp_length = FindEndOfText(text, token.pStr - text);
          TCHAR *text2 = FromXMLString(text, temp_length);
          if (text2 == NULL) {
            pXML->error = eXMLErrorUnexpectedToken;
            return false;
          }

          node.AddText(text2);
          free(text2);
          text = NULL;
        }

        // Find the name of the end tag
        token = GetNextToken(pXML, temp_length, type);

        // The end tag should be text
        if (type != eTokenText) {
          pXML->error = eXMLErrorMissingEndTagName;
          return false;
        }
        temp = token.pStr;

        // After the end tag we should find a closing tag
        token = GetNextToken(pXML, token_length, type);
        if (type != eTokenCloseTag) {
          pXML->error = eXMLErrorMissingEndTagName;
          return false;
        }

        // We need to return to the previous caller.  If the name
        // of the tag cannot be found we need to keep returning to
        // caller until we find a match
        if (!CompareTagName(node.GetName(), temp)) {
          pXML->lpEndTag = temp;
          pXML->cbEndTag = temp_length;
        }

        // Return to the caller
        return true;

        // Errors...
      case eTokenCloseTag: /* '>'         */
      case eTokenShortHandClose: /* '/>'        */
        pXML->error = eXMLErrorUnexpectedToken;
        return false;
      default:
        break;
      }
      break;

      // If we are inside a tag definition we need to search for attributes
    case eInsideTag:
      // Check what part of the attribute (name, equals, value) we
      // are looking for.
      switch (attrib) {
        // If we are looking for a new attribute
      case eAttribName:
        // Check what the current token type is
        switch (type) {
          // If the current type is text...
          // Eg.  'attribute'
        case eTokenText:
          // Cache the token then indicate that we are next to
          // look for the equals
          temp = token.pStr;
          temp_length = token_length;
          attrib = eAttribEquals;
          break;

          // If we found a closing tag...
          // Eg.  '>'
        case eTokenCloseTag:
          // We are now outside the tag
          status = eOutsideTag;
          break;

          // If we found a short hand '/>' closing tag then we can
          // return to the caller
        case eTokenShortHandClose:
          return true;

          // Errors...
        case eTokenQuotedText: /* '"SomeText"'   */
        case eTokenTagStart: /* '<'            */
        case eTokenTagEnd: /* '</'           */
        case eTokenEquals: /* '='            */
        case eTokenDeclaration: /* '<?'           */
          pXML->error = eXMLErrorUnexpectedToken;
          return false;
        default:
          break;
        }
        break;

        // If we are looking for an equals
      case eAttribEquals:
        // Check what the current token type is
        switch (type) {
          // If the current type is text...
          // Eg.  'Attribute AnotherAttribute'
        case eTokenText:
          // Add the unvalued attribute to the list
          node.AddAttribute(temp, temp_length, _T(""), 0);
          // Cache the token then indicate.  We are next to
          // look for the equals attribute
          temp = token.pStr;
          temp_length = token_length;
          break;

          // If we found a closing tag 'Attribute >' or a short hand
          // closing tag 'Attribute />'
        case eTokenShortHandClose:
        case eTokenCloseTag:
          // If we are a declaration element '<?' then we need
          // to remove extra closing '?' if it exists
          if (node.IsDeclaration() && (temp[temp_length - 1]) == _T('?'))
            temp_length--;

          if (temp_length)
            // Add the unvalued attribute to the list
            node.AddAttribute(temp, temp_length, _T(""), 0);

          // If this is the end of the tag then return to the caller
          if (type == eTokenShortHandClose)
            return true;

          // We are now outside the tag
          status = eOutsideTag;
          break;

          // If we found the equals token...
          // Eg.  'Attribute ='
        case eTokenEquals:
          // Indicate that we next need to search for the value
          // for the attribute
          attrib = eAttribValue;
          break;

          // Errors...
        case eTokenQuotedText: /* 'Attribute "InvalidAttr"'*/
        case eTokenTagStart: /* 'Attribute <'            */
        case eTokenTagEnd: /* 'Attribute </'           */
        case eTokenDeclaration: /* 'Attribute <?'           */
          pXML->error = eXMLErrorUnexpectedToken;
          return false;
        default:
          break;
        }
        break;

        // If we are looking for an attribute value
      case eAttribValue:
        // Check what the current token type is
        switch (type) {
          // If the current type is text or quoted text...
          // Eg.  'Attribute = "Value"' or 'Attribute = Value' or
          // 'Attribute = 'Value''.
        case eTokenText:
        case eTokenQuotedText:
          // If we are a declaration element '<?' then we need
          // to remove extra closing '?' if it exists
          if (node.IsDeclaration() && (token.pStr[token_length - 1]) == _T('?')) {
            token_length--;
          }

          if (temp_length) {
            // Add the valued attribute to the list
            if (type == eTokenQuotedText) {
              token.pStr++;
              token_length -= 2;
            }

            TCHAR *value = FromXMLString(token.pStr, token_length);
            node.AddAttribute(temp, temp_length,
                              value, _tcslen(value));
            free(value);
          }

          // Indicate we are searching for a new attribute
          attrib = eAttribName;
          break;

          // Errors...
        case eTokenTagStart: /* 'Attr = <'          */
        case eTokenTagEnd: /* 'Attr = </'         */
        case eTokenCloseTag: /* 'Attr = >'          */
        case eTokenShortHandClose: /* "Attr = />"         */
        case eTokenEquals: /* 'Attr = ='          */
        case eTokenDeclaration: /* 'Attr = <?'         */
          pXML->error = eXMLErrorUnexpectedToken;
          return false;
        default:
          break;
        }
      }
    }
  }
}
예제 #28
0
파일: lex.c 프로젝트: gyc2015/GYC
static int ScanBadChar(void)
{
    Error(&TokenCoord,"illegal character:\\x%x",*CURSOR);
    CURSOR++;
    return GetNextToken();
}
예제 #29
0
// Parse DB2 partitioning clause
bool SqlParser::ParseDb2PartitioningClause(Token *partition, Token *by)
{
	if(partition == NULL || by == NULL)
		return false;

	// RANGE is optional in DB2 z/OS
	Token *range = GetNextWordToken("RANGE", L"RANGE", 5);

	// RANGE keyword is required for Oracle
	if(range == NULL && _target == SQL_ORACLE)
		Append(by, " RANGE", L" RANGE", 6);

	/*Token *open */ (void) GetNextCharToken('(', L'(');

	// Comma separated list of columns
	while(true)
	{
		Token *column = GetNextToken();

		if(column == NULL)
			break;

		Token *comma = GetNextCharToken(',', L',');

		if(comma == NULL)
			break;
	}

	/*Token *close */ (void) GetNextCharToken(')', L')');

	/*Token *open2 */ (void) GetNextCharToken('(', L'(');

	// Comma separated list of partition definitions
	while(true)
	{
		// PARTITION keyword
		Token *partition2 = GetNextWordToken("PARTITION", L"PARTITION", 9);

		if(partition2 == NULL)
			break;

		// Partition number
		Token *num = GetNextToken();

		if(num == NULL)
			break;

		// In Oracle a partition name is required so prepend 'p' to each number
		if(_target == SQL_ORACLE)
			PrependNoFormat(num, "p", L"p", 1);

		// ENDING [AT]
		Token *ending = GetNextWordToken("ENDING", L"ENDING", 6);
		Token *at = GetNextWordToken("AT", L"AT", 2);

		// VALUES LESS THAN in Oracle
		if(_target == SQL_ORACLE)
		{
			Token::Change(ending, "VALUES LESS THAN", L"VALUES LESS THAN", 16);
			Token::Remove(at);
		}

		// Each value is in ()
		/*Token *open3 */ (void) GetNextCharToken('(', L'(');

		/*Token *limit */ (void) GetNextToken();

		/*Token *close3 */ (void) GetNextCharToken(')', L')');
		
		Token *comma = GetNextCharToken(',', L',');

		if(comma == NULL)
			break;
	}

	/*Token *close2 */ (void) GetNextCharToken(')', L')');

	return true;
}
예제 #30
0
// Parse SQL Server, Sybase ASE UPDATE statememt
bool SqlParser::ParseSqlServerUpdateStatement(Token *update)
{
	Token *name = GetNextIdentToken(SQL_IDENT_OBJECT);

	if(name == NULL)
		return false;

	Token *set = TOKEN_GETNEXTW("SET");

	if(set == NULL)
	{
		PushBack(name);
		return false;
	}
	
	// Parser list of assignments: c1 = exp1, ...
	while(true)
	{
		Token *col = GetNextIdentToken();

		if(col == NULL)
			break;
		
		Token *equal = TOKEN_GETNEXT('=');

		if(equal == NULL)
			break;

		// Single value or (SELECT c1, c2, ...) can be specified
		Token *open = TOKEN_GETNEXT('(');

		Token *select = NULL;

		// Check for SELECT statement
		if(open != NULL)
		{
			select = GetNextSelectStartKeyword();

			// A subquery used to specify assignment values
			if(select != NULL)
				ParseSelectStatement(select, 0, SQL_SEL_UPDATE_SET, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

			TOKEN_GETNEXT(')');
		}
		else
		{
			Token *exp = GetNextToken();

			if(exp == NULL)
				break;

			ParseExpression(exp);
		}
		
		Token *comma = TOKEN_GETNEXT(',');

		if(comma == NULL)
			break;
	}

	Token *from = NULL;
	Token *from_end = NULL;

	// FROM clause can include inner/outer joins
	ParseSelectFromClause(NULL, false, &from, &from_end, NULL, true, NULL);
        	
    Token *where_ = NULL;
    Token *where_end = NULL;

	// optional WHERE clause
	ParseWhereClause(SQL_STMT_UPDATE, &where_, &where_end, NULL);

	// UPDATE FROM syntax is used
	if(from != NULL)
	{
		// MySQL, MariaDB use syntax UPDATE t1, t2 SET ... WHERE
		if(Target(SQL_MYSQL, SQL_MARIADB))
		{
			Token::Remove(from);

			AppendCopy(name, from, from_end, false);

			Token::Remove(name);
			Token::Remove(from, from_end);
		}
	}

    // Implement CONTINUE handler for NOT FOUND in Oracle
	if(_target == SQL_ORACLE)
		OracleContinueHandlerForUpdate(update);

	// Add statement delimiter if not set when source is SQL Server
	SqlServerAddStmtDelimiter();

	return true;
}