Beispiel #1
0
int expand_token(char *s, u_int max, void (*func)(void *t, u_int n), void *t )
{
   char *str = strdup(s);
   char *p, *q, r;
   char *end;
   u_int a = 0, b = 0;
   
   DEBUG_MSG("expand_token %s", s);
   
   p = str;
   end = p + strlen(p);
   
   while (p < end) {
      q = p;
      
      /* find the end of the first digit */
      while ( isdigit((int)*q) && q++ < end);
      
      r = *q;   
      *q = 0;
      /* get the first digit */
      a = atoi(p);
      if (a > max) 
         FATAL_MSG("Out of range (%d) !!", max);
      
      /* it is a range ? */
      if ( r == '-') {
         p = ++q;
         /* find the end of the range */
         while ( isdigit((int)*q) && q++ < end);
         *q = 0;
         if (*p == '\0') 
            FATAL_MSG("Invalid range !!");
         /* get the second digit */
         b = atoi(p);
         if (b > max) 
            FATAL_MSG("Out of range (%d)!!", max);
         if (b < a)
            FATAL_MSG("Invalid decrementing range !!");
      } else {
         /* it is not a range */
         b = a; 
      } 
      
      /* process the range and invoke the callback */
      for(; a <= b; a++) {
         func(t, a);
      }
      
      if (q == end) break;
      else  p = q + 1;      
   }
  
   SAFE_FREE(str);
   
   return ESUCCESS;
}
Beispiel #2
0
/*
 * compile the regex of a filter_op
 */
static int compile_regex(struct filter_env *fenv, struct filter_header *fh)
{
   size_t i = 0;
   struct filter_op *fop = fenv->chain;
   char errbuf[100];
   int err;
#ifdef HAVE_PCRE
   const char *perrbuf = NULL;
#endif
     
   /* parse all the instruction */ 
   while (i < (fenv->len / sizeof(struct filter_op)) ) {
      
      /* search for func regex and pcre */
      if(fop[i].opcode == FOP_FUNC) {
         switch(fop[i].op.func.op) {
            case FFUNC_REGEX:

               /* alloc the structures */
               SAFE_CALLOC(fop[i].op.func.ropt, 1, sizeof(struct regex_opt));
               SAFE_CALLOC(fop[i].op.func.ropt->regex, 1, sizeof(regex_t));
   
               /* prepare the regex */
               err = regcomp(fop[i].op.func.ropt->regex, fop[i].op.func.string, REG_EXTENDED | REG_NOSUB | REG_ICASE );
               if (err) {
                  regerror(err, fop[i].op.func.ropt->regex, errbuf, sizeof(errbuf));
                  FATAL_MSG("filter engine: %s", errbuf);
               } 
               break;
               
            case FFUNC_PCRE:
               #ifdef HAVE_PCRE

               /* alloc the structure */
               SAFE_CALLOC(fop[i].op.func.ropt, 1, sizeof(struct regex_opt));

               /* prepare the regex (with default option) */
               fop[i].op.func.ropt->pregex = pcre_compile(fop[i].op.func.string, 0, &perrbuf, &err, NULL );
               if (fop[i].op.func.ropt->pregex == NULL)
                  FATAL_MSG("filter engine: %s\n", perrbuf);
  
               /* optimize the pcre */
               fop[i].op.func.ropt->preg_extra = pcre_study(fop[i].op.func.ropt->pregex, 0, &perrbuf);
               if (perrbuf != NULL)
                  FATAL_MSG("filter engine: %s\n", perrbuf);
               
               #endif               
               break;
         }
      }
      i++;
   } 

   return ESUCCESS;
}
Beispiel #3
0
void clASELoader::ASE_ReadTVertexList( iIStream* FStream, clVAMender* Mender )
{
	guard();

#ifdef ASE_HEAVY_DEBUG
	Env->Logger->Log( L_DEBUG, "Reading Tvertex list..." );
#endif

	char Keyword[32];

	while ( !FStream->Eof() )
	{
		LString Line = FStream->ReadLineTrimLeadSpaces();

		if ( LStr::ContainsSubStr( Line, "}" ) )
		{
			break;
		}
		else if ( LStr::StartsWith( Line, ASE_MeshTVertex ) )
		{
			int Index;
			float U, V, W;

			sscanf( Line.c_str(), "%s %d %f %f %f", Keyword, &Index, &U, &V, &W );

			Mender->EmitTextureVertex( Index, LVector3( U, 1.0f - V, W ) );
		}
		else
		{
			FATAL_MSG( "Unexpected token in " + ASE_MeshTVertexList + " : " + Line );
		}
	}

	unguard();
}
Beispiel #4
0
void clASELoader::ASE_ReadVertexList( iIStream* FStream, clVAMender* Mender )
{
	guard();

#ifdef ASE_HEAVY_DEBUG
	Env->Logger->Log( L_DEBUG, "Reading vertex list..." );
#endif

	char Keyword[32];

	int Index;
	float X, Y, Z;

	while ( !FStream->Eof() )
	{
		LString Line( FStream->ReadLineTrimLeadSpaces() );

		if ( LStr::StartsWith( Line, ASE_MeshVertex ) )
		{
			sscanf( Line.c_str(), "%s %d %f %f %f", Keyword, &Index, &X, &Y, &Z );

			Mender->EmitVertex( Index, LVector3( X, Y, Z ), -1, -1 );
		}
		else if ( LStr::ContainsSubStr( Line, "}" ) )
		{
			break;
		}
		else
		{
			FATAL_MSG( "Unexpected token in " + ASE_MeshVertexList + " : " + Line );
		}
	}

	unguard();
}
Beispiel #5
0
void clASELoader::ASE_ReadMaterialList( iIStream* FStream )
{
	guard();

	while ( !FStream->Eof() )
	{
		LString Line = FStream->ReadLineTrimLeadSpaces();

		if ( LStr::ContainsSubStr( Line, "}" ) )
		{
			break;
		}
		else if ( LStr::StartsWith( Line, ASE_MaterialCount ) )
		{
			int MaterialCount = LStr::ToInt( LStr::GetToken( Line, 2 ) );

			FMaterialList.resize( MaterialCount );
		}
		else if ( LStr::StartsWith( Line, ASE_Material ) )
		{
			int MaterialIndex = LStr::ToInt( LStr::GetToken( Line, 2 ) );

			//ASE_ReadMaterial( MaterialIndex, -1, 0 );
			FMaterialList[ MaterialIndex ] = ASE_ReadMaterial( FStream, 0 );
		}
		else
		{
			FATAL_MSG( "Unexpected token in " + ASE_MaterialList + " : " + Line );
		}
	}

	unguard();
}
Beispiel #6
0
int set_regex(char *regex)
{
   int err;
   char errbuf[100];
   
   DEBUG_MSG("set_regex: %s", regex);

   /* free any previous compilation */
   if (GBL_OPTIONS->regex)
      regfree(GBL_OPTIONS->regex);

   /* unset the regex if empty */
   if (!strcmp(regex, "")) {
      SAFE_FREE(GBL_OPTIONS->regex);
      return ESUCCESS;
   }
  
   /* allocate the new structure */
   SAFE_CALLOC(GBL_OPTIONS->regex, 1, sizeof(regex_t));
  
   /* compile the regex */
   err = regcomp(GBL_OPTIONS->regex, regex, REG_EXTENDED | REG_NOSUB | REG_ICASE );

   if (err) {
      regerror(err, GBL_OPTIONS->regex, errbuf, sizeof(errbuf));
      FATAL_MSG("%s\n", errbuf);
   }

   return ESUCCESS;
}
Beispiel #7
0
/*
 * inject a file into the communication
 */
static int func_inject(struct filter_op *fop, struct packet_object *po)
{
   int fd;
   void *file;
   size_t size, ret;
   
   /* check the offensiveness */
   if (GBL_OPTIONS->unoffensive)
      JIT_FAULT("Cannot inject packets in unoffensive mode");
   

   DEBUG_MSG("filter engine: func_inject %s", fop->op.func.string);
   
   /* open the file */
   if ((fd = open(fop->op.func.string, O_RDONLY | O_BINARY)) == -1) {
      USER_MSG("filter engine: inject(): File not found (%s)\n", fop->op.func.string);
      return -EFATAL;
   }

   /* get the size */
   size = lseek(fd, 0, SEEK_END);

   /* load the file in memory */
   SAFE_CALLOC(file, size, sizeof(char));
 
   /* rewind the pointer */
   lseek(fd, 0, SEEK_SET);
   
   ret = read(fd, file, size);
   
   close(fd);

   if (ret != size)
      FATAL_MSG("Cannot read the file into memory");
 
   /* check if we are overflowing pcap buffer */
   if(GBL_PCAP->snaplen - (po->L4.header - (po->packet + po->L2.len) + po->L4.len) <= po->DATA.len + size)
      JIT_FAULT("injected file too long");
         
   /* copy the file into the buffer */
   memcpy(po->DATA.data + po->DATA.len, file, size);

   /* Adjust packet len and delta */
   po->DATA.delta += size;
   po->DATA.len += size;    

   /* mark the packet as modified */
   po->flags |= PO_MODIFIED;
   
   /* unset the flag to be dropped */
   if (po->flags & PO_DROPPED)
      po->flags ^= PO_DROPPED;

   /* close and unmap the file */
   SAFE_FREE(file);
   
   return ESUCCESS;
}
Beispiel #8
0
void clConsole::DisplayMessage( const LString& Message, const LConsoleMessageType MSGType ) const
{
	if ( Env )
	{
		Env->SendSync( L_EVENT_CONSOLELOG, LEventArgs( &Message ), false );
	}

	FTimeVisible = MESSAGE_VISIBILITY_TIME;

	LVector4 Color;

	switch ( MSGType )
	{
		case CMSG_ENGINEMESSAGE:
			Color = LC_LinderdaumConsoleEM;
			break;
		case CMSG_ERRORMESSAGE:
			Color = LC_LinderdaumConsoleERR;
			break;
		case CMSG_INFOTIP:
			Color = LC_LinderdaumConsoleIT;
			break;
		default:
			FATAL_MSG( "Unknown message type" );
	}

	LString Msg = Message;

	LMutex Lock( &FMessagesHistoryMutex );

	while ( true )
	{
		size_t Separation = Msg.find( "\n" );

		if ( Separation == LString::npos )
		{
			break;
		}

		LString NewMsg = Msg.substr( 0, Separation );

		FMessagesHistory.push_back( sConsoleMessage( NewMsg, Color ) );

		if ( FMessagesHistory.size() > MAX_HISTORY_SIZE )
		{
			FMessagesHistory.pop_front();
		}

		Msg = Msg.substr( Separation + 1, Message.length() - 1 );
	}

	FMessagesHistory.push_back( sConsoleMessage( Msg, Color ) );
}
void clLoaderThread::clLoadOp_Image::Load()
{
	// this Env is used in guard()
	sEnvironment* Env = this->FResource->Env;

	guard( "%s", this->FResource->GetFileName().c_str() );

	LString FileName = this->FResource->GetFileName();

	clBitmap* Bitmap = clBitmap::CreateEmptyBitmap( Env );
	sBitmapParams* Params = &( this->FResource->GetDefaultBitmap()->FBitmapParams );

	Env->Logger->Log( L_DEBUG, "Reallocating image data for new bitmap..." );

	Bitmap->ReallocImageData( Params );

	switch  ( Bitmap->GetTextureType() )
	{
		case L_TEXTURE_2D:
			FATAL( Bitmap->Load2DImage( Env, FileName ) == false, "Unable to load 2D texture: " + FileName );
			break;
		case L_TEXTURE_3D:

			if ( Params->FAutoGradient )
			{
				FATAL( Bitmap->Load3DImageGradients( Env, FileName ) == false, "Unable to load Gradients 3D texture: " + FileName );
			}
			else if ( Params->FAutoESL )
			{
				FATAL( Bitmap->Load3DImageESL( Env, FileName ) == false, "Unable to load ESL 3D texture: " + FileName );
			}
			else
			{
				FATAL( Bitmap->Load3DImage( Env, FileName ) == false, "Unable to load 3D texture: " + FileName );
			}

			break;
		case L_TEXTURE_CUBE:
			FATAL( Bitmap->LoadCubeImage( Env, FileName ) == false, "Unable to load CUBE texture: " + FileName );
			break;
		default:
			FATAL_MSG( "Unknown texture type" );
	}

	Env->Logger->Log( L_DEBUG, "Updating bitmap in resource..." );

	this->FResource->SetBitmap( Bitmap );
	this->FResource->SetAsyncLoadComplete( true );

	unguard();
}
Beispiel #10
0
void clASELoader::ASE_ReadTFaceList( iIStream* FStream, clVAMender* Mender )
{
	guard();

#ifdef ASE_HEAVY_DEBUG
	Env->Logger->Log( L_DEBUG, "Reading Tface list..." );
#endif

	LStr::clStringsVector Tokens( 6 );

	while ( !FStream->Eof() )
	{
		LString Line = FStream->ReadLineTrimLeadSpaces();

		if ( LStr::ContainsSubStr( Line, "}" ) )
		{
			break;
		}
		else if ( LStr::StartsWith( Line, ASE_MeshTFace ) )
		{
			LStr::FastSplitLine( 1, 5, Line, Tokens, true );

			int Index  = LStr::ToInt( Tokens[2] );
			int A      = LStr::ToInt( Tokens[3] );
			int B      = LStr::ToInt( Tokens[4] );
			int C      = LStr::ToInt( Tokens[5] );

			Mender->EmitTextureFace( Index, A, B, C );
		}
		else
		{
			FATAL_MSG( "Unexpected token in " + ASE_MeshTFaceList + " : " + Line );
		}
	}

	unguard();
}
Beispiel #11
0
/*
 * open/close the file to store all the USER_MSG
 */
int set_msg_loglevel(int level, char *filename)
{
   switch (level) {
      case LOG_TRUE:
         /* close the filedesc if already opened */
         set_msg_loglevel(LOG_FALSE, filename);

         EC_GBL_OPTIONS->msg_fd = fopen(filename, FOPEN_WRITE_TEXT);
         if (EC_GBL_OPTIONS->msg_fd == NULL)
            FATAL_MSG("Cannot open \"%s\" for writing", filename);

         break;
         
      case LOG_FALSE:
         /* close the file and set the pointer to NULL */
         if (EC_GBL_OPTIONS->msg_fd) {
            fclose(EC_GBL_OPTIONS->msg_fd);
            EC_GBL_OPTIONS->msg_fd = NULL;
         }
         break;
   }

   return E_SUCCESS;
}
Beispiel #12
0
/*
 * parses the "format" and set the right visualization method
 */
int set_format(char *format)
{
   DEBUG_MSG("set_format: %s", format);
   
   if (!strcasecmp(format, "hex")) {
      GBL_FORMAT = &hex_format;
      return ESUCCESS;
   }

   if (!strcasecmp(format, "ascii")) {
      GBL_FORMAT = &ascii_format;
      return ESUCCESS;
   }

   if (!strcasecmp(format, "text")) {
      GBL_FORMAT = &text_format;
      return ESUCCESS;
   }

   if (!strcasecmp(format, "html")) {
      GBL_FORMAT = &html_format;
      return ESUCCESS;
   }

   if (!strcasecmp(format, "ebcdic")) {
      GBL_FORMAT = &ebcdic_format;
      return ESUCCESS;
   }

   if (!strcasecmp(format, "utf8")) {
      GBL_FORMAT = &utf8_format;
      return ESUCCESS;
   }

   FATAL_MSG("Unsupported format (%s)", format);
}
Beispiel #13
0
/*
 * load the filter from a file 
 */
int filter_load_file(char *filename, struct filter_list **list)
{
   int fd;
   void *file;
   size_t size, ret;
   struct filter_env *fenv;
   struct filter_header fh;

   DEBUG_MSG("filter_load_file (%s)", filename);

  /* open the file */
   if ((fd = open(filename, O_RDONLY | O_BINARY)) == -1)
      FATAL_MSG("File not found or permission denied");

   /* read the header */
   if (read(fd, &fh, sizeof(struct filter_header)) != sizeof(struct filter_header))
      FATAL_MSG("The file is corrupted");

   /* sanity checks */
   if (fh.magic != htons(EC_FILTER_MAGIC))
      FATAL_MSG("Bad magic in filter file\nMake sure to compile the filter with etterfilter");
  
   /* which version has compiled the filter ? */
   if (strcmp(fh.version, EC_VERSION))
      FATAL_MSG("Filter compiled for a different version");
   
   /* get the size */
   size = lseek(fd, 0, SEEK_END);

   /* load the file in memory */
   SAFE_CALLOC(file, size, sizeof(char));
 
   /* rewind the pointer */
   lseek(fd, 0, SEEK_SET);
   
   ret = read(fd, file, size);
   
   close(fd);
   
   if (ret != size)
      FATAL_MSG("Cannot read the file into memory");

   FILTERS_LOCK;

   /* advance to the end of the filter list */
   while (*list) list = &(*list)->next;

   /* allocate memory for the list entry */
   SAFE_CALLOC(*list, 1, sizeof(struct filter_list));
   fenv = &(*list)->env;
   
   /* set the global variables */
   fenv->map = file;
   fenv->chain = (struct filter_op *)(file + fh.code);
   fenv->len = size - sizeof(struct filter_header) - fh.code;

   /* 
    * adjust all the string pointers 
    * they must point to the data segment
    */
   reconstruct_strings(fenv, &fh);

   /* save the name of the loaded filter */
   (*list)->name = strdup(filename);

   /* enable the filter */
   (*list)->enabled = 1;

   FILTERS_UNLOCK;

   /* compile the regex to speed up the matching */
   if (compile_regex(fenv, &fh) != ESUCCESS)
      return -EFATAL;
   
   USER_MSG("Content filters loaded from %s...\n", filename);
   
   return ESUCCESS;
}
Beispiel #14
0
// =========
bool Tape::check_alphabet () const
{
bool	ret_bool_value = true;

symbol_t	phisical_empty_symbol = string();
vector<symbol_t>::const_iterator	iter;

  assert (!empty_symbols_alphabet_.empty());
  assert (!input_alphabet_.empty());
  assert (!internal_alphabet_.empty());

  // ---------
  iter = find (empty_symbols_alphabet_.begin(), empty_symbols_alphabet_.end(), phisical_empty_symbol); 
  if (iter != empty_symbols_alphabet_.end())
  {
    ret_bool_value = false;
    FATAL_MSG	("Empty symbols alphabet -> symbol#"
		<< distance (empty_symbols_alphabet_.begin(), iter)
		<< " is phisically empty : <"
		<< *iter
		<< ">"
		);
  }

  iter = find (input_alphabet_.begin(), input_alphabet_.end(), phisical_empty_symbol); 
  if (iter != input_alphabet_.end())
  {
    ret_bool_value = false;
    FATAL_MSG	("Input alphabet -> symbol#"
		<< distance (input_alphabet_.begin(), iter)
		<< " is phisically empty : <"
		<< *iter
		<< ">"
		);
  }


  iter = find (internal_alphabet_.begin(), internal_alphabet_.end(), phisical_empty_symbol); 
  if (iter != internal_alphabet_.end())
  {
    ret_bool_value = false;
    FATAL_MSG	("Internal alphabet -> symbol#"
		<< distance (internal_alphabet_.begin(), iter)
		<< " is phisically empty : <"
		<< *iter
		<< ">"
		);
  }

  // ------
vector<symbol_t> tmp_full_alphabet = get_full_alphabet();
vector<symbol_t>::iterator	iter2;
  for (iter2 = tmp_full_alphabet.begin(); iter2 != tmp_full_alphabet.end(); iter2++)
  {
    assert (count (iter2, tmp_full_alphabet.end(), *iter2));
    if (count (iter2, tmp_full_alphabet.end(), *iter2) > 1)
    {
      ret_bool_value = false;
      FATAL_MSG	("Alphabets -> symbol "
		<< "<"
		<< (*iter2)
	 	<< ">"
		<< " occurs more than once"
		);
    }
  }
  
  return ret_bool_value;

}
Beispiel #15
0
/* 
 * download the file and replace 
 * the existing one
 */
static int do_update(char *file, char *url, char *errbuf)
{
   FILE *fd;
   int sock;
   int len, header_skipped = 0;
   char *ptr = NULL;
   char *host;
   char getmsg[512];
   char buffer[4096];
 
   memset(buffer, 0, sizeof(buffer));
   
   /* check if the url is valid */
   if (!match_pattern(url, "http://*/*")) {
      snprintf(errbuf, ERR_MAX_LEN, "invalid URL");
      return 0;
   }

   /* get the hostname */
   host = strdup(url + strlen("http://"));
   ptr = host;
   while (*ptr != '/') ptr++;
   *ptr = '\0';
   
   /* open the file for writing */
   fd = open_data("share", file, FOPEN_WRITE_TEXT);
   if (fd == NULL) {
      snprintf(errbuf, ERR_MAX_LEN, "cannot open %s", file);
      return 0;
   }
  
   sock = open_socket(host, 80);
   
   switch(sock) {
      case -ENOADDRESS:
         FATAL_MSG("Cannot resolve %s", host);
         break;
      case -EFATAL:
         FATAL_MSG("Cannot create the socket");
         break;
      case -ETIMEOUT:
         FATAL_MSG("Connect timeout to %s on port 80", host);
         break;
      case -EINVALID:
         FATAL_MSG("Error connecting to %s on port 80", host);
         break;
   }
   
   /* prepare the HTTP request */
   snprintf(getmsg, sizeof(getmsg), "GET %s HTTP/1.0\r\n"
                                     "Host: %s\r\n"
                                     "User-Agent: %s (%s)\r\n"
                                     "\r\n", url, host, GBL_PROGRAM, GBL_VERSION );
   
   /* send the request to the server */
   socket_send(sock, getmsg, strlen(getmsg));

   DEBUG_MSG("do_update - SEND \n\n%s\n\n", getmsg);

   /* get the server response */
   while ( (len = socket_recv(sock, buffer, sizeof(buffer) - 1)) ) {

      DEBUG_MSG("do_update - RECEIVE \n\n%s\n\n", buffer);

      /* skip the HTTP header */
      if ( (ptr = strstr(buffer, "\r\n\r\n")))
         header_skipped = 1;
   
      /* write the data in the file */
      if (header_skipped) {
         if (ptr) {
            write(fileno(fd), ptr + 4, len - (ptr + 4 - buffer));
         } else {
            write(fileno(fd), buffer, len);
         }
      }
   
      memset(buffer, 0, sizeof(buffer));
      ptr = NULL;

   }

   SAFE_FREE(host);
   close_socket(sock);
   fclose(fd);

   return 1;
}
Beispiel #16
0
void clASELoader::ASE_ReadNormals( iIStream* FStream, clVAMender* Mender )
{
	guard();

#ifdef ASE_HEAVY_DEBUG
	Env->Logger->Log( L_DEBUG, "Reading normals..." );
#endif

	int CurrentFace = -1;
	int VertexIndex = 0;
	sFaceNormal FaceNormal;

	LStr::clStringsVector Tokens( 6 );

	while ( !FStream->Eof() )
	{
		LString Line = FStream->ReadLineTrimLeadSpaces();

		if ( LStr::ContainsSubStr( Line, "}" ) )
		{
			break;
		}
		else if ( LStr::StartsWith( Line, ASE_MeshFaceNormal ) )
		{
			if ( CurrentFace > -1 )
			{
				Mender->EmitFaceNormal( CurrentFace, FaceNormal );
			}

			LStr::FastSplitLine( 1, 5, Line, Tokens, true );

			CurrentFace = LStr::ToInt( Tokens[2] );
			float X     = LStr::ToFloat( Tokens[3] );
			float Y     = LStr::ToFloat( Tokens[4] );
			float Z     = LStr::ToFloat( Tokens[5] );

			VertexIndex = 0;

			FaceNormal.FFaceNormal = LVector3( X, Y, Z );
		}
		else if ( LStr::StartsWith( Line, ASE_MeshVertexNormal ) )
		{
			LStr::FastSplitLine( 1, 5, Line, Tokens, true );

			int   Index = LStr::ToInt( Tokens[2] );
			float X     = LStr::ToFloat( Tokens[3] );
			float Y     = LStr::ToFloat( Tokens[4] );
			float Z     = LStr::ToFloat( Tokens[5] );

			LVector3 Vec( X, Y, Z );

			Mender->EmitNormal( Index, Vec );

			FaceNormal.FVertexNormal[ VertexIndex++ ] = Vec;
		}
		else
		{
			FATAL_MSG( "Unexpected token in " + ASE_MeshNormals + " : " + Line );
		}
	}

	if ( CurrentFace > -1 )
	{
		Mender->EmitFaceNormal( CurrentFace, FaceNormal );
	}

	unguard();
}
Beispiel #17
0
void clASELoader::ASE_ReadFaceList( iIStream* FStream, clVAMender* Mender )
{
	guard();

#ifdef ASE_HEAVY_DEBUG
	Env->Logger->Log( L_DEBUG, "Reading face list..." );
#endif

	LStr::clStringsVector Tokens( 19 );

	while ( !FStream->Eof() )
	{
		LString Line = FStream->ReadLineTrimLeadSpaces();

		if ( LStr::ContainsSubStr( Line, "}" ) )
		{
			break;
		}
		else if ( LStr::StartsWith( Line, ASE_MeshFace ) )
		{
			LStr::FastSplitLine( 1, 18, Line, Tokens, true );

			int Index  = LStr::ToInt( Tokens[2].substr( 0, Tokens[2].length() - 1 ) );
			int A      = LStr::ToInt( Tokens[4] );
			int B      = LStr::ToInt( Tokens[6] );
			int C      = LStr::ToInt( Tokens[8] );

			LString Token = Tokens[16];

			int SubMTLTokenIndex = ( Token == ASE_MeshMaterialID ) ? 17 : 18;

			LString SubMTL_ID = Tokens[SubMTLTokenIndex];

			int SubMTL = SubMTL_ID.empty() ? -1 : LStr::ToInt( SubMTL_ID );

			int SmoothingGroup = LStr::ToInt( Tokens[SubMTLTokenIndex-2] );
			/*
			         LString IndexS = LStr::GetToken(Line, 2);

			         int Index  = LStr::ToInt( IndexS.substr(0, IndexS.length()-1) );
			         int A      = LStr::ToInt( LStr::GetToken(Line, 4) );
			         int B      = LStr::ToInt( LStr::GetToken(Line, 6) );
			         int C      = LStr::ToInt( LStr::GetToken(Line, 8) );

			         LString Token = LStr::GetToken(Line, 16);

			         int SubMTLTokenIndex = ( Token == ASE_MeshMaterialID ) ? 17 : 18;

			         LString SubMTL_ID = LStr::GetToken( Line, SubMTLTokenIndex );

			         int SubMTL = SubMTL_ID.empty() ? -1 : LStr::ToInt( SubMTL_ID );

			         int SmoothingGroup = LStr::ToInt( LStr::GetToken( Line, SubMTLTokenIndex-2 ) );
			*/

			/*
			         char Keyword[32];

			         int A, B, C;
			         int Index;
			         int AB, BC, CA;
			         int SmoothingGroup;
			         int SubMTL;

			         sscanf( Line.c_str(), "%s %d: A: %d  B: %d  C: %d AB: %d BC: %d CA: %d *MESH_SMOOTHING %d",
			                 Keyword, &Index, &A, &B, &C, &AB, &BC, &CA, &SmoothingGroup);

			         char* pBuf = strrchr(Keyword, '*');
			         sscanf(pBuf,"*MESH_MTLID %d", &SubMTL);
			*/
#ifdef ASE_HEAVY_DEBUG
			Env->Logger->Log( L_DEBUG, "Smoothing group:" + LStr::ToStr( SmoothingGroup ) );
#endif

			Mender->EmitFace( Index, A, B, C, SubMTL, SmoothingGroup );
		}
		else
		{
			FATAL_MSG( "Unexpected token in " + ASE_MeshFaceList + " : " + Line );
		}
	}

	unguard();
}
Beispiel #18
0
void interrupt0() {
    FATAL_MSG(("Attempted to divide by zero."));
    DEBUG_MSG(("Eventually, this should only kill the current task."));
    __asm__("hlt");
}