#include "bg_vehicles_parser.h"

void parser_clear_string(char *string, int length) {
	if(string) {
		int i;
		for(i = 0; i < length; i++) {
			string[i] = '\0';	
		}
	}
}

char *combat_strstr( const char *string, const char *substring ) {
   int i, len;
   char source[MAX_QPATH], target[MAX_QPATH];

   parser_clear_string(target, MAX_QPATH);
   len = strlen(substring);
   for(i = 0; i < len-1; i++)
      target[i] = substring[i];
   target[i] = '\0';
 
   //if(string && substring) {
      while ( *string ) {
      //while ( string ) {
   
         parser_clear_string(source, MAX_QPATH);

         //printf("strstr: %s\n", string);

         for( i = 0; i < len-1; i++)
            source[i] = string[i];
         source[i] = '\0';

         if(strcmp(source, target) == 0)
            return (char*)string;

         /*
		   for ( i = 0 ; substring[i] ; i++ ) {
			   if ( string[i] != substring[i] ) {
				   break;
			   }
            if(i == len-1)
               return string;
		   }
         
   		
         //if ( !substring[i] ) {
         if ( substring[i] == '\0' ) {
			   return (char *)string;
		   }
         */
		   string++;
	   }
   //}
	return (char *)0;
}

char *parser_strstr( const char *string, const char *substring ) {
   //if(string && substring) {
      while ( *string ) {
      //while ( string ) {
		   int		i;

         //printf("strstr: %s\n", string);

		   for ( i = 0 ; substring[i] ; i++ ) {
			   if ( string[i] != substring[i] ) {
				   break;
			   }
		   }
   		
         //if ( !substring[i] ) {
         if ( substring[i] == '\0' ) {
			   return (char *)string;
		   }
		   string++;
	   }
   //}
	return (char *)0;
}