Rock

FSIF | Find String Inside File

Mar 12th, 2014
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.15 KB | None | 0 0
  1. #if defined _FSIF_included
  2.         #endinput
  3. #endif
  4.  
  5. #define _FSIF_included
  6.  
  7. #include < a_samp >
  8.  
  9. stock IT( g_sTr[ ], ySa_File[ ], bool: g_iCase = false, g_Pos = 0 )
  10. {
  11.  
  12.     static
  13.           File: gZa_File, i,
  14.           yZs_BLA,
  15.           yS_ReZ
  16.     ;
  17.  
  18.     gZa_File = fopen( ySa_File, io_read );
  19.  
  20.     if( g_Pos > 0 ) fseek( gZa_File, g_Pos, seek_current );
  21.     if( g_iCase )
  22.     {
  23.         for( i = 0; g_sTr[ i ]; ++i )
  24.         g_sTr[ i ] = tolower( g_sTr[ i ] );
  25.  
  26.         for( i = 0, yZs_BLA = 0; ( yS_ReZ = fgetchar( gZa_File, -1, false ) )  != -1; ++i )
  27.         {
  28.             if( tolower( yS_ReZ ) == g_sTr[ yZs_BLA ] )
  29.             {
  30.                 yZs_BLA++;
  31.                 if( !g_sTr[ yZs_BLA ] ) return fclose( gZa_File ), i - strlen( g_sTr ) + 1  + g_Pos;
  32.             }
  33.             else
  34.                 yZs_BLA = 0;
  35.             }
  36.         }
  37.         else
  38.         {
  39.             for ( i = 0, yZs_BLA = 0; ( yS_ReZ = fgetchar( gZa_File, -1, false ) )  != -1; ++i )
  40.             {
  41.                 if( ( yS_ReZ ) == g_sTr[ yZs_BLA ] )
  42.                 {
  43.                     yZs_BLA ++;
  44.                     if( !g_sTr[ yZs_BLA ] ) return fclose( gZa_File ), i - strlen( g_sTr ) + 1;
  45.                 }
  46.                 else yZs_BLA = 0;
  47.             }
  48.     }
  49.     return fclose( gZa_File ), -1;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment