Esempio n. 1
0
long file_string_search( const char *p, FILE *f, const char* opt )
{
  int ps = strlen(p);
  ASSERT( ps < MAX_PATTERN );

  int nocase = str_find( opt, 'i' ) > -1;

  long pos = -1;

  if( str_find( opt, 'r' ) > -1 )
    {
    pos = file_grep( p, f, 0, -1 );
    } else
  if( str_find( opt, 'h' ) > -1 )
    {
    char new_p[MAX_PATTERN+1];
    int pl = hex_string_to_pattern( p, new_p );
    if (pl > 0)
      pos = file_pattern_search( new_p, pl, f, nocase ? "i" : "" );
    }
  else
    {
    pos = file_pattern_search( p, strlen(p), f, nocase ? "i" : "" );
    }

  return pos;
}
Esempio n. 2
0
uint   STDCALL str_fwildcard( pstr name, pstr mask )
{
   uint   ret;
   uint   dotstr;
   uint   dotmask;
   pubyte pname = str_ptr( name );
   pubyte pmask = str_ptr( mask );
   uint   isstr = FALSE;
   uint   ismask = FALSE;
   uint   empty = 0;

   dotstr = str_find( name, 0, '.', TRUE );
   dotmask = str_find( mask, 0, '.', TRUE );

   if ( pname[ dotstr ] )
   {
      pname[ dotstr ] = 0;
      isstr = TRUE;
   }
   if ( pmask[ dotmask ] )
   {
      pmask[ dotmask ] = 0;
      ismask = TRUE;
   }
   ret = ptr_wildcardignore( pname, pmask );
   if ( ismask || ( isstr && pmask[ dotmask - 1 ] != '*' ))
      ret &= ptr_wildcardignore( isstr ? pname + dotstr + 1 : ( pubyte )&empty,
                              ismask ? pmask + dotmask + 1 : ( pubyte )&empty );
   if ( isstr )
      pname[ dotstr ] = '.';
   if ( ismask )
      pmask[ dotmask ] = '.';
   return ret;
}
Esempio n. 3
0
int mem_string_search( const char *p, const char* d, const char* opt )
{
    int ps = strlen(p);
    ASSERT( ps < MAX_PATTERN );

    int nocase = str_find( opt, 'i' ) > -1;

    long pos = -1;

    if( str_find( opt, 'r' ) > -1 )
    {
        VRegexp re;
        if ( ! re.comp( p ) ) return -1;
        if ( ! re.m( d ) ) return -1;
        pos = re.sub_sp( 0 );
    } else if( str_find( opt, 'h' ) > -1 )
    {
        char new_p[MAX_PATTERN+1];
        int pl = hex_string_to_pattern( p, new_p );
        if (pl > 0)
            if ( nocase )
                pos = mem_quick_search_nc( new_p, pl, d, strlen(d) );
            else
                pos = mem_quick_search( new_p, pl, d, strlen(d) );
    }
    else
    {
        if ( nocase )
            pos = mem_quick_search_nc( p, ps, d, strlen(d) );
        else
            pos = mem_quick_search( p, ps, d, strlen(d) );
    }

    return pos;
};
Esempio n. 4
0
void CFontMgr::Init()
{
    m_pStorage = Kernel()->RequestInterface<IStorageTW>();
    m_FontFiles.clear();
    m_FontFiles.hint_size(10);

    ReloadFontlist();

    if(g_Config.m_FtPreloadFonts)
        for(int i = 0; i < m_FontFiles.size(); i++)
            InitFont(&m_FontFiles[i]);

    // load default font
    char aFontFile[256];
    str_format(aFontFile, sizeof(aFontFile), "%s", g_Config.m_FtFont);
    if(str_comp(g_Config.m_FtFont, "fonts/DejaVuSansCJKName.ttf") == 0)
        if (str_find(g_Config.m_ClLanguagefile, "chinese") != NULL || str_find(g_Config.m_ClLanguagefile, "japanese") != NULL ||
                str_find(g_Config.m_ClLanguagefile, "korean") != NULL)
            str_format(aFontFile, sizeof(aFontFile), "fonts/DejavuWenQuanYiMicroHei.ttf");


    for(int i = 0; i < m_FontFiles.size(); i++)
    {
        if(str_comp(m_FontFiles[i].m_Path.c_str(), aFontFile) == 0)
            ActivateFont(i);
    }
}
Esempio n. 5
0
bool Is64Player(const CServerInfo *pInfo)
{
	return str_find(pInfo->m_aGameType, "64")
	    || str_find(pInfo->m_aName, "64")
	    || IsDDNet(pInfo)
	    || IsBlockInfectionZ(pInfo)
	    || IsBlockWorlds(pInfo);
}
Esempio n. 6
0
/* TODO multiple values should be handled */
static int32_t http_parse_payload(struct exo_request_args *request_args,
                                  char *payload,
                                  size_t size,
                                  size_t max_size,
                                  int32_t response_code)
{
    struct capture captures[10];
    size_t num_captures;
    int32_t status = ERR_INVALID_FORMAT;
    bool found;
    const char *pattern;

    status = response_code_to_system_error(response_code, request_args->method);
    if (status != ERR_SUCCESS) {
        if (status == ERR_NO_CONTENT)
            return ERR_SUCCESS;
        else
            return status;
    }

    switch (request_args->method) {
    case EXO_PP_ACTIVATE:
    case EXO_UP_TIMESTAMP:
        pattern = "(%w*)";
        found = str_find(payload, size, pattern, strlen(pattern), 0, 0, &num_captures, captures, 10);
        if (found) {
            if (captures[0].len + 1 < max_size)
                payload[captures[0].len] = '\0';
        }
        break;
    case EXO_DP_WRITE:
    case EXO_DP_READ:
    case EXO_DP_READ_WRITE:
    case EXO_DP_SUBSCRIBE:
    case EXO_PP_LIST_CONTENT:
    case EXO_PP_DOWNLOAD_CONTENT:
    case EXO_UP_IP:
    default:
        pattern = "(%w-)=(%w*)";
        found = str_find(payload, size, pattern, strlen(pattern), 0, 0, &num_captures, captures, 10);
        if (found) {
            memmove(payload, captures[1].init, captures[1].len);
            if (captures[1].len + 1 < max_size)
                payload[captures[1].len] = '\0';
        }

        break;
    }

    if (!found)
        return ERR_INVALID_FORMAT;

    return status;
}
Esempio n. 7
0
void vfu_load_dir_colors()
{
  #ifdef _TARGET_UNIX_

  VArray va;
  va.fload( "/etc/DIR_COLORS" );
  if (va.count() == 0) return;

  while( va.count() )
    {
    VString str = va[0];
    va.del( 0 );
    int comment = str_find( str, '#' );
    if ( comment != -1 ) str_sleft( str, comment );
    str_cut( str, " \t" );
    if ( str_len( str ) == 0 ) continue;

    if ( strncmp( str, "TERM "   , 5 ) == 0 ) continue;
    if ( strncmp( str, "COLOR "  , 6 ) == 0 ) continue;
    if ( strncmp( str, "OPTIONS ", 8 ) == 0 ) continue;

    int pos = -1;
    if ( str_find( str, "31" ) != -1 ) pos = cRED; else
    if ( str_find( str, "32" ) != -1 ) pos = cGREEN; else
    if ( str_find( str, "33" ) != -1 ) pos = cYELLOW; else
    if ( str_find( str, "34" ) != -1 ) pos = cBLUE; else
    if ( str_find( str, "35" ) != -1 ) pos = cMAGENTA; else
    if ( str_find( str, "36" ) != -1 ) pos = cCYAN; else
    if ( str_find( str, "37" ) != -1 ) pos = cWHITE; else
    ;

    int spc = str_find( str, ' ' );
    if ( spc == -1 || pos == -1 ) continue;
    str_sleft( str, spc );

    str_replace( str, "DIR", ".[].<>" );
    str_replace( str, "LINK", ".->" );
    str_replace( str, "FIFO", ".()" );
    str_replace( str, "SOCK", ".##" );
    str_replace( str, "BLK", ".==" );
    str_replace( str, "CHR", ".++" );
    str_replace( str, "EXEC", ".**" );

    str_ins( ext_colors[pos], 0, str );

    };

  for ( int z = 0; z < 16; z++ )
    if( str_len( ext_colors[z] ) > 0 )
      {
      ext_colors[z] += ".";
      if ( opt.lower_case_ext_config )
        str_low( ext_colors[z] );
      }

  #endif /* _TARGET_UNIX_ */
}
Esempio n. 8
0
int get_item_color( TF *fi )
{
  VString str;

  ASSERT( fi );

  if (!opt.use_colors)
    return cNORMAL; /* don't use colors -- option */

  if ( fi->is_dir() ) return cCYAN; // dirs are cCYAN by default

  str = fi->name();
  if ( str_get_ch( str, 0 ) == '.' )
    str = ".dotfiles";
  else
    {
    str = fi->ext();
    if ( str == "" ) str = ".";
    }
  str += ".";

  if ( opt.lower_case_ext_config ) str_low( str ); // lowercase extension

  #ifdef _TARGET_GO32_
  /* under dos/windows file names are not case sensitive */
  str_low( str );
  #endif

  int z;
  if ( str != ".." )
    {
    for ( z = cBLACK; z <= chWHITE; z++ )
      if (str_find( ext_colors[z], str ) != -1)
        return z;
    }

  /* extension not found -- try type string */
  str = fi->type_str();
  str = "." + str + ".";

  if ( str != ".." )
    {
    for ( z = cBLACK; z <= chWHITE; z++ )
      if (str_find( ext_colors[z], str ) != -1)
        return z;
    }

  /* type string not found too return std color */
  return cNORMAL;
}
Esempio n. 9
0
time_t str2time( const char* timstr )
{
    if (strlen( timstr ) < 24) return 0;
    char ts[32];
    struct tm m;
    memset( &m, 0, sizeof(m) );

    strcpy( ts, timstr );
    str_up( ts );
    //  0    5   10    5   20   4
    // "Wed Jun 30 21:49:08 1993\n"
    ts[24] = 0;
    m.tm_year = atoi( ts + 20 ) - 1900;
    ts[19] = 0;
    m.tm_sec  = atoi( ts + 17 );
    ts[16] = 0;
    m.tm_min  = atoi( ts + 14 );
    ts[13] = 0;
    m.tm_hour = atoi( ts + 11 );
    ts[10] = 0;
    m.tm_mday = atoi( ts +  8 );
    ts[ 7] = 0;
    m.tm_mon  = str_find( "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC", ts+4 ) / 3;
    m.tm_yday = 0;
    m.tm_wday = 0;
    m.tm_isdst = -1;
    time_t tim = mktime( &m );
    return tim;
};
Esempio n. 10
0
void CMenus::OnStateChange(int NewState, int OldState)
{
	// reset active item
	UI()->SetActiveItem(0);

	if(NewState == IClient::STATE_OFFLINE)
	{
		m_Popup = POPUP_NONE;
		if(Client()->ErrorString() && Client()->ErrorString()[0] != 0)
		{
			if(str_find(Client()->ErrorString(), "password"))
			{
				m_Popup = POPUP_PASSWORD;
				UI()->SetHotItem(&g_Config.m_Password);
				UI()->SetActiveItem(&g_Config.m_Password);
			}
			else
				m_Popup = POPUP_DISCONNECTED;
		}
	}
	else if(NewState == IClient::STATE_LOADING)
	{
		m_Popup = POPUP_CONNECTING;
		//client_serverinfo_request();
	}
	else if(NewState == IClient::STATE_CONNECTING)
		m_Popup = POPUP_CONNECTING;
	else if (NewState == IClient::STATE_ONLINE || NewState == IClient::STATE_DEMOPLAYBACK)
	{
		m_Popup = POPUP_NONE;
		SetActive(false);
	}
}
Esempio n. 11
0
pstr  STDCALL getmodulepath( pstr name, pstr additional )
{
   str  temp;

   str_init( &temp );

#ifdef LINUX
   //Only for linux ???
   uint len = readlink( "/proc/self/exe", additional, 512 ) - 1;
   //uint sep1 = str_find(additionaļ,0,'\304',1);
   uint   separ = str_find( additional, 0, SLASH, 1 );
   //pCopyStr=strrchr(additionaļ,SLASH);
   //while ( len && (additional[ len ] != '/') ) len--;
   //if ( str_findch(filename,SLASH) != 0 )
   mem_copyuntilzero((pubyte) (additional + separ + 1), name );
   //strcpy(str_ptr(name),pCopyStr);
   //mem_copyuntilzero( additional + len + 1, name );
#else
   getmodulename( name );
   str_getdirfile( name, &temp, NULL );
   str_dirfile( &temp, additional, name );
#endif
   str_delete( &temp );
   return name;
}
Esempio n. 12
0
void tree_fix()
{
  int z;
  for( z = dir_tree.count() - 1; z >= 0; z-- )
    {
    VString s1 = dir_tree[z];
    VString s2;
    if (z < dir_tree.count() - 1)
      s2 = dir_tree[z+1];
    else
      s2 = "";
    int i = -1;
    int n = str_count( s1, "/" );
    int p = 0;
    while(n > 2)
      {
      i = str_find( s1, '/', i+1 );
      int q = 0;
      if ( str_len( s2 ) > i )
        q = s1[i] != s2[i];
      if ( q || ( str_count(s2,"/",i+1) < 2))
        {
          p = 1;
          str_set_ch(s1, i, '\\');
        }
      n--;
      }
    if ( p )
      dir_tree.set( z, s1 );
    }
}
Esempio n. 13
0
int main( int argc, char **argv )
{
   int           i;
   int           count;
   const char    **orig;
   char          buf[100];

   maa_init( argv[0] );

   if (argc == 1) {
      count = 100;
   } else if (argc != 2 ) {
      fprintf( stderr, "usage: stringtest count\n" );
      return 1;
   } else {
      count = atoi( argv[1] );
   }

   orig = xmalloc( count * sizeof( const char ** ) );

   printf( "Running test for count of %d\n", count );

   for (i = 0; i < count; i++) {
      sprintf( buf, "key%d", i );
      orig[i] = str_find( buf );
   }

   for (i = 0; i < count; i++) {
      const char *this;

      sprintf( buf, "key%d", i );
      this = str_find( buf );
      if (orig[i] != this)
	    printf( "Pointers are different for \"%s\" (\"%s\"): %p and %p\n",
		     buf,
		     this,
		     orig[i],
		     this );
   }

   xfree( orig );

   printf( "Done.\n" );

   return 0;
}
Esempio n. 14
0
/*
 * spxml_end_of_event(&val, str, len)
 *
 * Searches the end of the event "val" which is marked
 * by "str". In returns the end position in to the structure
 * val. The string "str" has a maximum length of "len"
 *
 *	1	End of event found
 *	0	End of event not found
 *
 */
static inline int spxml_end_of_event(spxml_event_t *val, const utf8_t *str, size_t len)
{
	utf8_t *l__end = str_find(val->position, val->len, str, len + 1);
	if (l__end == NULL) return 0;
	
	val->len = l__end - val->position;
	val->total_len = (l__end - val->position) + spxml_event_types[val->type].elen;
	
	return 1;
}
Esempio n. 15
0
const char *str_unique( const char *prefix )
{
   static int i       = 1;
   char       *buf    = alloca( strlen( prefix ) + 100 );

   do {
      sprintf( buf, "%s%d", prefix, i++ );
   } while (str_exists( buf ));
   return str_find( buf );
}
Esempio n. 16
0
	virtual IOHANDLE OpenFile(const char *pFilename, int Flags, int Type, char *pBuffer = 0, int BufferSize = 0)
	{
		char aBuffer[MAX_PATH_LENGTH];
		if(!pBuffer)
		{
			pBuffer = aBuffer;
			BufferSize = sizeof(aBuffer);
		}

		if(Type == TYPE_ABSOLUTE)
		{
			return io_open(pFilename, Flags);
		}
		if(str_startswith(pFilename, "mapres/../skins/"))
		{
			pFilename = pFilename + 10; // just start from skins/
		}
		if(pFilename[0] == '/' || pFilename[0] == '\\' || str_find(pFilename, "../") != NULL || str_find(pFilename, "..\\") != NULL
		#ifdef CONF_FAMILY_WINDOWS
			|| (pFilename[0] && pFilename[1] == ':')
		#endif
		)
		{
			// don't escape base directory
		}
		else if(Flags&IOFLAG_WRITE)
		{
			return io_open(GetPath(TYPE_SAVE, pFilename, pBuffer, BufferSize), Flags);
		}
		else
		{
			IOHANDLE Handle = 0;

			if(Type <= TYPE_ALL)
			{
				// check all available directories
				for(int i = 0; i < m_NumPaths; ++i)
				{
					Handle = io_open(GetPath(i, pFilename, pBuffer, BufferSize), Flags);
					if(Handle)
						return Handle;
				}
			}
			else if(Type >= 0 && Type < m_NumPaths)
			{
				// check wanted directory
				Handle = io_open(GetPath(Type, pFilename, pBuffer, BufferSize), Flags);
				if(Handle)
					return Handle;
			}
		}

		pBuffer[0] = 0;
		return 0;
	}
Esempio n. 17
0
int find_next_action_cb(Ihandle* bt_next)
{
  Ihandle* multitext = (Ihandle*)IupGetAttribute(bt_next, "MULTITEXT");
  char* str = IupGetAttribute(multitext, "VALUE");
  int find_pos = IupGetInt(multitext, "FIND_POS");

  Ihandle* txt = IupGetDialogChild(bt_next, "FIND_TEXT");
  char* str_to_find = IupGetAttribute(txt, "VALUE");

  Ihandle* find_case = IupGetDialogChild(bt_next, "FIND_CASE");
  int casesensitive = IupGetInt(find_case, "VALUE");

  int pos = str_find(str + find_pos, str_to_find, casesensitive);
  if (pos >= 0)
    pos += find_pos;
  else if (find_pos > 0)
    pos = str_find(str, str_to_find, casesensitive);  /* try again from the start */

  if (pos >= 0)
  {
    int lin, col, 
      end_pos = pos + (int)strlen(str_to_find);

    IupSetInt(multitext, "FIND_POS", end_pos);

    IupSetFocus(multitext);
    IupSetfAttribute(multitext, "SELECTIONPOS", "%d:%d", pos, end_pos);

    IupTextConvertPosToLinCol(multitext, pos, &lin, &col);
    IupTextConvertLinColToPos(multitext, lin, 0, &pos);  /* position at col=0, just scroll lines */
    IupSetInt(multitext, "SCROLLTOPOS", pos);
  }
  else
    IupMessage("Warning", "Text not found.");




  return IUP_DEFAULT;
}
Esempio n. 18
0
uint STDCALL str_getdirfile( pstr src, pstr dir, pstr name )
{
   uint   separ = str_find( src, 0, SLASH, 1 );
   uint   off;

   off = separ >= str_len( src ) ? 0 : separ + 1;
   
   if ( name )
      str_copyzero( name, str_ptr( src ) + off );
   if ( dir )
      str_substr( dir, src, 0, separ < str_len( src ) ? separ : 0 );
   return 1;
}
Esempio n. 19
0
int main(void)
{
	const char *strs[] = {"Good", "Bye", "Hello", "World"};

	for (int i = 0; i < 4; ++i) {
		std::cout << strs[i] << ": ";

		boost::optional<int> j = str_find(strs[i], 'o');
		if (j) {
			std::cout << *j << std::endl;
		} else {
			std::cout << "Not Found!!" << std::endl;
		}
	}
	return 0;
}
Esempio n. 20
0
/* 88*/ STRING *
/* 88*/ Namespace_ApplyUse(STRING *Namespace_name, int Namespace_is_class)
/* 88*/ {
/* 89*/ 	int Namespace_j = 0;
/* 89*/ 	int Namespace_i = 0;
/* 90*/ 	RECORD * Namespace_use = NULL;
/* 92*/ 	STRING * Namespace_leading = NULL;
/* 92*/ 	if( Namespace_isFullyQualified(Namespace_name) ){
/* 93*/ 		return m2runtime_substr(Namespace_name, 1, m2runtime_length(Namespace_name), 1, Namespace_0err_entry_get, 12);
/* 95*/ 	} else if( Namespace_isQualified(Namespace_name) ){
/* 96*/ 		Namespace_i = str_find(Namespace_name, m2runtime_CHR(92));
/* 97*/ 		Namespace_leading = m2runtime_substr(Namespace_name, 0, Namespace_i, 1, Namespace_0err_entry_get, 13);
/* 98*/ 		{
/* 98*/ 			int m2runtime_for_limit_1;
/* 98*/ 			Namespace_j = 0;
/* 98*/ 			m2runtime_for_limit_1 = (m2runtime_count((ARRAY *)m2runtime_dereference_rhs_RECORD(Globals_curr_package, 5 * sizeof(void*) + 2 * sizeof(int), Namespace_0err_entry_get, 14)) - 1);
/* 99*/ 			for( ; Namespace_j <= m2runtime_for_limit_1; Namespace_j += 1 ){
/* 99*/ 				Namespace_use = (RECORD *)m2runtime_dereference_rhs_ARRAY((ARRAY *)m2runtime_dereference_rhs_RECORD(Globals_curr_package, 5 * sizeof(void*) + 2 * sizeof(int), Namespace_0err_entry_get, 15), Namespace_j, Namespace_0err_entry_get, 16);
/*100*/ 				if( m2runtime_strcmp((STRING *)m2runtime_dereference_rhs_RECORD(Namespace_use, 1 * sizeof(void*) + 2 * sizeof(int), Namespace_0err_entry_get, 17), Namespace_leading) == 0 ){
/*101*/ 					m2_inc((int *)m2runtime_dereference_lhs_RECORD(&Namespace_use, 3 * sizeof(void*) + 3 * sizeof(int), 3, 3 * sizeof(void*) + 2 * sizeof(int), Namespace_0err_entry_get, 18), 1);
/*102*/ 					return m2runtime_concat_STRING(0, (STRING *)m2runtime_dereference_rhs_RECORD(Namespace_use, 0 * sizeof(void*) + 2 * sizeof(int), Namespace_0err_entry_get, 19), m2runtime_substr(Namespace_name, Namespace_i, m2runtime_length(Namespace_name), 1, Namespace_0err_entry_get, 20), (STRING *) 1);
/*105*/ 				}
/*106*/ 			}
/*106*/ 		}
/*106*/ 	} else if( Namespace_is_class ){
/*108*/ 		{
/*108*/ 			int m2runtime_for_limit_1;
/*108*/ 			Namespace_j = 0;
/*108*/ 			m2runtime_for_limit_1 = (m2runtime_count((ARRAY *)m2runtime_dereference_rhs_RECORD(Globals_curr_package, 5 * sizeof(void*) + 2 * sizeof(int), Namespace_0err_entry_get, 21)) - 1);
/*109*/ 			for( ; Namespace_j <= m2runtime_for_limit_1; Namespace_j += 1 ){
/*109*/ 				Namespace_use = (RECORD *)m2runtime_dereference_rhs_ARRAY((ARRAY *)m2runtime_dereference_rhs_RECORD(Globals_curr_package, 5 * sizeof(void*) + 2 * sizeof(int), Namespace_0err_entry_get, 22), Namespace_j, Namespace_0err_entry_get, 23);
/*110*/ 				if( m2runtime_strcmp((STRING *)m2runtime_dereference_rhs_RECORD(Namespace_use, 1 * sizeof(void*) + 2 * sizeof(int), Namespace_0err_entry_get, 24), Namespace_name) == 0 ){
/*111*/ 					m2_inc((int *)m2runtime_dereference_lhs_RECORD(&Namespace_use, 3 * sizeof(void*) + 3 * sizeof(int), 3, 3 * sizeof(void*) + 2 * sizeof(int), Namespace_0err_entry_get, 25), 1);
/*112*/ 					return (STRING *)m2runtime_dereference_rhs_RECORD(Namespace_use, 0 * sizeof(void*) + 2 * sizeof(int), Namespace_0err_entry_get, 26);
/*115*/ 				}
/*117*/ 			}
/*117*/ 		}
/*120*/ 	}
/*120*/ 	if( Namespace_inNamespace() ){
/*121*/ 		return m2runtime_concat_STRING(0, (STRING *)m2runtime_dereference_rhs_RECORD(Globals_curr_package, 4 * sizeof(void*) + 2 * sizeof(int), Namespace_0err_entry_get, 27), m2runtime_CHR(92), Namespace_name, (STRING *) 1);
/*123*/ 	} else {
/*123*/ 		return Namespace_name;
/*126*/ 	}
/*126*/ 	m2runtime_missing_return(Namespace_0err_entry_get, 28);
/*126*/ 	return NULL;
/*128*/ }
Esempio n. 21
0
File: main.cpp Progetto: CCJY/coliru
int main()
{
    std::string a = "invitationtypeSOYSOYname";
 
   /* std::string str_find = "type";
    std::size_t loc = a.find(str_find);
    //std::size_t loc2 = a.find("7")
    loc = loc + str_find.size();
    std::string sub2 = a.substr(loc);
    str_find = "name";
    loc = a.find(str_find);
    std::string sub3 = a.substr(loc);
    sub2.erase(sub2.size()-sub3.size());
    std::cout << sub2 << '\n';
    std::cout << sub3 << '\n';*/
    
    std::string sub_final = str_find("type","name", a);
    std::cout << sub_final << '\n';
}
Esempio n. 22
0
void CMenus::OnStateChange(int NewState, int OldState)
{
	// reset active item
	UI()->SetActiveItem(0);

	if(NewState == IClient::STATE_OFFLINE)
	{
		if(OldState >= IClient::STATE_ONLINE)
			m_pClient->m_pSounds->Play(CSounds::CHN_MUSIC, SOUND_MENU, 1.0f, vec2(0, 0));
		m_Popup = POPUP_NONE;
		if(Client()->ErrorString() && Client()->ErrorString()[0] != 0)
		{
			if(str_find(Client()->ErrorString(), "password"))
			{
				m_Popup = POPUP_PASSWORD;
				UI()->SetHotItem(&g_Config.m_Password);
				UI()->SetActiveItem(&g_Config.m_Password);
			}
			else
				m_Popup = POPUP_DISCONNECTED;
		}
	}
	else if(NewState == IClient::STATE_LOADING)
	{
		m_Popup = POPUP_CONNECTING;
		m_DownloadLastCheckTime = time_get();
		m_DownloadLastCheckSize = 0;
		m_DownloadSpeed = 0.0f;
		//client_serverinfo_request();
	}
	else if(NewState == IClient::STATE_CONNECTING)
		m_Popup = POPUP_CONNECTING;
	else if (NewState == IClient::STATE_ONLINE || NewState == IClient::STATE_DEMOPLAYBACK)
	{
		m_Popup = POPUP_NONE;
		SetActive(false);
	}
}
Esempio n. 23
0
long file_pattern_search( const char *p, int ps, FILE* f, const char* opt,
                          int (*mem_search)( const char *p, int ps,
                                             const char *d, int ds ) )
{
   #define BUFSIZE  (1024*1024)
   char* buff = new char[BUFSIZE];

   int nocase = str_find( opt, 'i' ) > -1;
   char* np = new char[ps+1];
   ASSERT(np);
   memcpy( np, p, ps );
   np[ps] = 0;

   if ( ! mem_search )
     mem_search = mem_quick_search;
   if ( nocase )
     mem_search = mem_quick_search_nc;

   off_t pos = -1;
   while(4)
     {
     int bs = fread( buff, 1, BUFSIZE, f );
     int cpos = mem_search( np, ps, buff, bs );
     if ( cpos > -1 )
       {
       pos = ftello(f) - bs + cpos;
       break;
       }
     else
       {
       fseeko( f, -ps, SEEK_CUR );
       }
     if ( bs < BUFSIZE ) break;
     }
   delete np;
   delete buff;
   return pos;
}
Esempio n. 24
0
void    from_file(char *filename, char *src)
{
    int fd;
    int ret;
    char buf[BUF_SIZE + 1];

    fd = open(filename, O_RDONLY);
    if (fd == -1)
    {
        ft_perror("error in open()");
        exit(1);
    }
    while ((ret = read(fd, buf, BUF_SIZE)))
    {
        buf[ret] = '\0';
        str_find(buf, src);
    }
    if (close(fd) == -1)
    {
        ft_perror("error in close()");
        exit(1);
    }
}
Esempio n. 25
0
// stolen from H-Client :3
void CMenus::RenderIRC(CUIRect MainView)
{
    CALLSTACK_ADD();

    static float YOffset = -500.0f; // dunno if a constant is optimal...
    if(!m_IRCActive)
    {
        YOffset = -500.0f;
        return;
    }

    smooth_set(&YOffset, 50.0f, 35.0f, Client()->RenderFrameTime());

    // small0r
    MainView.x = 50;
    MainView.y = YOffset;
    MainView.w -= 100;
    MainView.h -= 100;

    CUIRect Screen = *UI()->Screen();
    Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h);

    Graphics()->BlendNormal();

    RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActiveIngame-vec4(0.0f, 0.0f, 0.0f, 0.2f), CUI::CORNER_ALL, 5.0f);

    MainView.HSplitTop(15.0f, 0, &MainView);
    MainView.VSplitLeft(15.0f, 0, &MainView);

    MainView.Margin(5.0f, &MainView);
    RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActiveIngame-vec4(0.0f, 0.0f, 0.0f, 0.2f), CUI::CORNER_ALL, 5.0f);

    CUIRect MainIRC, EntryBox, Button;
    MainView.Margin(10.0f, &MainIRC);

    /*if (m_GamePagePanel != PANEL_CHAT && UI()->MouseInside(&MainView) && Input()->KeyPressed(KEY_MOUSE_1))
     {
     m_GamePagePanel = PANEL_CHAT;
     }*/

    if(m_pClient->IRC()->GetState() == IIRC::STATE_DISCONNECTED)
    {
        EntryBox.x = MainIRC.x + (MainIRC.w / 2.0f - 300.0f / 2.0f);
        EntryBox.w = 300.0f;
        EntryBox.y = MainIRC.y + (MainIRC.h / 2.0f - 55.0f / 2.0f);
        EntryBox.h = 55.0f;

        RenderTools()->DrawUIRect(&EntryBox, ms_ColorTabbarActive-vec4(0.0f, 0.0f, 0.0f, 0.2f), CUI::CORNER_ALL, 10.0f);
        EntryBox.Margin(5.0f, &EntryBox);

        EntryBox.HSplitTop(18.0f, &Button, &EntryBox);
        CUIRect Label;
        Button.VSplitLeft(40.0f, &Label, &Button);
        UI()->DoLabelScaled(&Label, Localize("Nick:"), 14.0f, -1);
        static float OffsetNick;
        if(g_Config.m_ClIRCNick[0] == 0)
        {
            str_copy(g_Config.m_ClIRCNick, g_Config.m_PlayerName, sizeof(g_Config.m_ClIRCNick));
            str_irc_sanitize(g_Config.m_ClIRCNick);
        } //TODO_ here?
        static CButtonContainer s_EditboxIRCNick;
        DoEditBox(&s_EditboxIRCNick, &Button, g_Config.m_ClIRCNick, sizeof(g_Config.m_ClIRCNick), 12.0f, &OffsetNick,
                  false, CUI::CORNER_ALL);

        EntryBox.HSplitTop(5.0f, 0x0, &EntryBox);
        EntryBox.HSplitTop(20.0f, &Button, &EntryBox);
        static CButtonContainer s_ButtonConnect;
        if(DoButton_Menu(&s_ButtonConnect, Localize("Connect"), 0, &Button))
            m_pClient->m_pIRCBind->Connect();
    }
    else if(m_pClient->IRC()->GetState() == IIRC::STATE_CONNECTING)
    {
        EntryBox.x = MainIRC.x + (MainIRC.w / 2.0f - 300.0f / 2.0f);
        EntryBox.w = 300.0f;
        EntryBox.y = MainIRC.y + (MainIRC.h / 2.0f - 25.0f / 2.0f);
        EntryBox.h = 25.0f;

        RenderTools()->DrawUIRect(&EntryBox, ms_ColorTabbarActive-vec4(0.0f, 0.0f, 0.0f, 0.2f), CUI::CORNER_ALL, 10.0f);
        EntryBox.Margin(5.0f, &EntryBox);
        UI()->DoLabelScaled(&EntryBox, Localize("Connecting, please wait..."), 14.0f, -1);
    }
    else if(m_pClient->IRC()->GetState() == IIRC::STATE_CONNECTED)
    {
        CUIRect ButtonBox, InputBox;

        // channel list
        MainIRC.HSplitTop(20.0f, &ButtonBox, &EntryBox);
        ButtonBox.VSplitRight(80.0f, &ButtonBox, &Button);
        static CButtonContainer s_ButtonDisc;
        if(DoButton_Menu(&s_ButtonDisc, g_Config.m_ClIRCAutoconnect ? Localize("Reconnect") : Localize("Disconnect"), 0, &Button))
            m_pClient->m_pIRCBind->Disconnect(g_Config.m_ClIRCLeaveMsg);

        // scroll through the tabs
        if(UI()->MouseInside(&ButtonBox) && m_pClient->m_pGameConsole->IsClosed())
        {
            if(m_pClient->Input()->KeyPress(KEY_MOUSE_WHEEL_UP))
                m_pClient->IRC()->NextRoom();
            else if(m_pClient->Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN))
                m_pClient->IRC()->PrevRoom();
        }

        float LW = (ButtonBox.w - ButtonBox.x) / m_pClient->IRC()->GetNumComs();
        static CButtonContainer s_ButsID[64];
        for(unsigned i = 0; i < m_pClient->IRC()->GetNumComs(); i++)
        {
            CIRCCom *pCom = m_pClient->IRC()->GetCom(i);

            //	if(pCom == m_pClient->IRC()->GetActiveCom())
            ButtonBox.VSplitLeft(LW - 25.0f, &Button, &ButtonBox);
            //	else
            //	{
            //		ButtonBox.VSplitLeft(LW, &Button, &ButtonBox);
            //		Button.VSplitRight(2.0f, &Button, 0x0);
            //	}

            // close using middle mouse button
            if(UI()->MouseInside(&Button) && m_pClient->Input()->KeyPress(KEY_MOUSE_3) &&
                    m_pClient->IRC()->CanCloseCom(m_pClient->IRC()->GetCom(i)))
                m_pClient->IRC()->Part(g_Config.m_ClIRCLeaveMsg, m_pClient->IRC()->GetCom(i));

            if(pCom->GetType() == CIRCCom::TYPE_CHANNEL)
            {
                CComChan *pChan = static_cast<CComChan*>(pCom);
                static float FadeVal[64] = { 0.0f };
                static bool Add[64] = { true };

                if(Add[i])
                    smooth_set(&FadeVal[i], 1.0f, 120.0f, Client()->RenderFrameTime());
                else
                    smooth_set(&FadeVal[i], 0.0f, 120.0f, Client()->RenderFrameTime());
                if(FadeVal[i] >= 0.8f) Add[i] = false;
                if(FadeVal[i] <= 0.2f) Add[i] = true;

                char aTab[255];
                if(pCom->m_NumUnreadMsg)
                {
                    str_format(aTab, sizeof(aTab), "%s [%d]", pChan->Channel(), pCom->m_NumUnreadMsg);
                    if(DoButton_MenuTab(&s_ButsID[i], aTab, pCom->m_NumUnreadMsg, &Button, i==m_pClient->IRC()->GetNumComs()-1?CUI::CORNER_R:0, vec4(0.0f, FadeVal[i], 0.0f, 1.0f)))
                        m_pClient->IRC()->SetActiveCom(i);
                }
                else
                {
                    FadeVal[i] = 0.0f;
                    Add[i] = true;
                    str_copy(aTab, pChan->Channel(), sizeof(aTab));
                    if(DoButton_MenuTab(&s_ButsID[i], aTab, pCom == m_pClient->IRC()->GetActiveCom(), &Button, i==m_pClient->IRC()->GetNumComs()-1?CUI::CORNER_R:0))
                        m_pClient->IRC()->SetActiveCom(i);
                }
            }
            else if(pCom->GetType() == CIRCCom::TYPE_QUERY)
            {
                CComQuery *pQuery = static_cast<CComQuery*>(pCom);
                static float FadeVal[64] = { 0.0f };
                static bool Add[64] = { true };

                if(Add[i])
                    smooth_set(&FadeVal[i], 1.0f, 120.0f, Client()->RenderFrameTime());
                else
                    smooth_set(&FadeVal[i], 0.0f, 120.0f, Client()->RenderFrameTime());
                if(FadeVal[i] >= 0.8f) Add[i] = false;
                if(FadeVal[i] <= 0.2f) Add[i] = true;

                char aTab[255];
                if(pCom->m_NumUnreadMsg)
                {
                    str_format(aTab, sizeof(aTab), "%s [%d]", pQuery->User(), pCom->m_NumUnreadMsg);
                    if(DoButton_MenuTab(&s_ButsID[i], aTab, pCom->m_NumUnreadMsg, &Button, i==m_pClient->IRC()->GetNumComs()-1?CUI::CORNER_R:0, vec4(0.0f, FadeVal[i], 0.0f, 1.0f)))
                        m_pClient->IRC()->SetActiveCom(i);
                }
                else
                {
                    FadeVal[i] = 0.0f;
                    Add[i] = true;
                    str_copy(aTab, pQuery->User(), sizeof(aTab));
                    if(DoButton_MenuTab(&s_ButsID[i], aTab, pCom == m_pClient->IRC()->GetActiveCom(), &Button, i==m_pClient->IRC()->GetNumComs()-1?CUI::CORNER_R:0))
                        m_pClient->IRC()->SetActiveCom(i);
                }
            }

            if(i > 0 && pCom == m_pClient->IRC()->GetActiveCom() && m_pClient->IRC()->GetNumComs() > 2 && str_comp_nocase(((CComChan*)pCom)->Channel(), "#AllTheHaxx"))
            {
                Button.VSplitRight(ButtonBox.h, 0, &Button);
                Button.Margin(3.0f, &Button);
                Button.x -= 5.0f;
                Button.h = Button.w;
                static CButtonContainer s_CloseButton;
                if(DoButton_Menu(&s_CloseButton, "×", 0, &Button, 0, CUI::CORNER_ALL, ms_ColorTabbarActive+vec4(0.3f,0.3f,0.3f,0)))
                    m_pClient->IRC()->Part(g_Config.m_ClIRCLeaveMsg);
            }
        }

        static char aEntryText[512];
        static int s_CurrBacklogIndex = -1;
        bool Update = false;
        if(Input()->KeyPress(KEY_UP))
        {
            s_CurrBacklogIndex++;
            Update = true;
        }
        if(Input()->KeyPress(KEY_DOWN))
        {
            s_CurrBacklogIndex--;
            Update = true;
        }
        s_CurrBacklogIndex = clamp(s_CurrBacklogIndex, -1, m_aIRCBacklog.size()-1);

        if(Update)
        {
            if(s_CurrBacklogIndex < 0)
                mem_zero(aEntryText, sizeof(aEntryText));
            else if(m_aIRCBacklog.size() > 0)
            {
                int ActualEntry = m_aIRCBacklog.size()-1-s_CurrBacklogIndex;
                if(str_length(m_aIRCBacklog[ActualEntry].c_str()) > 0)
                    str_copy(aEntryText, m_aIRCBacklog[ActualEntry].c_str(), sizeof(aEntryText));
            }
        }

        // Input Box
        EntryBox.HSplitBottom(20.0f, &EntryBox, &InputBox);
        InputBox.VSplitRight(max(50.0f, TextRender()->TextWidth(0, (InputBox.h-2.0f)*ms_FontmodHeight, Localize("Send"), -1)), &InputBox, &Button);
        //Button.VSplitLeft(5.0f, 0x0, &Button);
        static float s_Offset;
        CPointerContainer s_EditboxInput(&m_IRCActive);
        DoEditBox(&s_EditboxInput, &InputBox, aEntryText, sizeof(aEntryText), 12.0f, &s_Offset, false, CUI::CORNER_L, "", -1);
        static CButtonContainer s_ButtonSend;
        if(DoButton_Menu(&s_ButtonSend, Localize("Send"), 0, &Button, 0, CUI::CORNER_R, vec4(1,1,1,0.6f))
                || m_EnterPressed)
        {
            if(aEntryText[0] == '/'/* || (m_pClient->IRC()->GetActiveCom()->GetType() == CIRCCom::TYPE_QUERY &&
					str_comp_nocase(((CComQuery*)m_pClient->IRC()->GetActiveCom())->m_User, "@Status") == 0)*/)
            {
                std::string strCmdRaw;
                //if(str_comp_nocase(((CComQuery*)m_pClient->IRC()->GetActiveCom())->m_User, "@Status") == 0)
                //	strCmdRaw = aEntryText;
                //else
                strCmdRaw = aEntryText + 1;
                char aCmd[32] = { 0 }, aCmdParams[255] = { 0 };
                size_t del = strCmdRaw.find_first_of(" ");
                if(del != std::string::npos)
                {
                    str_copy(aCmd, strCmdRaw.substr(0, del).c_str(), sizeof(aCmd));
                    str_copy(aCmdParams, strCmdRaw.substr(del + 1).c_str(), sizeof(aCmdParams));
                }
                else
                    str_copy(aCmd, strCmdRaw.c_str(), sizeof(aCmd));

                if(aCmd[0] != 0)
                    m_pClient->IRC()->ExecuteCommand(aCmd, aCmdParams);
            }
            else
                m_pClient->IRC()->SendMsg(0x0, aEntryText);

            if(str_length(aEntryText) > 0)
                m_aIRCBacklog.add(std::string(aEntryText));
            s_CurrBacklogIndex = -1;
            aEntryText[0] = 0;
            UI()->SetActiveItem(s_EditboxInput.GetID());
        }

        if(!UI()->HotItem())
            UI()->SetActiveItem(s_EditboxInput.GetID());

        //Channel/Query
        CIRCCom *pCom = m_pClient->IRC()->GetActiveCom();
        if(!pCom)
            return;

        if(pCom->GetType() == CIRCCom::TYPE_CHANNEL)
        {
            CComChan *pChan = static_cast<CComChan*>(pCom);

            CUIRect Chat, HorizScrollBar, UserList;
            EntryBox.Margin(5.0f, &EntryBox);
            EntryBox.VSplitRight(150.0f, &Chat, &UserList);
            Chat.HSplitBottom(15.0f, &Chat, &HorizScrollBar);

            static CButtonContainer s_HScrollbar;
            static float s_HScrollbarVal = 0.0f;
            s_HScrollbarVal = DoScrollbarH(&s_HScrollbar, &HorizScrollBar, s_HScrollbarVal);
            if(Input()->KeyIsPressed(KEY_LSHIFT) && m_pClient->m_pGameConsole->IsClosed())
            {
                if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN)) // to the right
                    s_HScrollbarVal += 0.1f;
                if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP)) // to the left
                    s_HScrollbarVal -= 0.1f;
                s_HScrollbarVal = clamp(s_HScrollbarVal, 0.0f, 1.0f);
            }

            static int Selected = 0;
            static CButtonContainer s_UsersList;
            static float s_UsersScrollValue = 0;
            /*if(!Input()->KeyIsPressed(KEY_LSHIFT) && UI()->MouseInside(&UserList))
            {
            	if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP)) // to the right
            		s_UsersScrollValue -= 0.1f;
            	if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN)) // to the left
            		s_UsersScrollValue += 0.1f;
            	s_UsersScrollValue = clamp(s_UsersScrollValue, 0.0f, 1.0f);
            }*/
            char aBuff[50];
            str_format(aBuff, sizeof(aBuff), Localize("Total: %d"), pChan->m_Users.size());
            UiDoListboxStart(&s_UsersList, &UserList, 18.0f, Localize("Users"), aBuff, pChan->m_Users.size(), 1, Selected,
                             s_UsersScrollValue, CUI::CORNER_TR);

            for(int u = 0; u < pChan->m_Users.size(); u++)
            {
                std::string& Name = pChan->m_Users[u].m_Nick;
                CPointerContainer Container(&Name);
                CListboxItem Item = UiDoListboxNextItem(&Container, false, UI()->MouseInside(&UserList) != 0);

                if(!Item.m_Visible)
                    continue;

                // quick join button
                CUIRect Label, ButtonQS;
                Item.m_Rect.VSplitRight(Item.m_Rect.h, &Label, &ButtonQS);

                if(Selected == u)
                {
                    if(UI()->DoButtonLogic(&Item.m_Selected, "", Selected, &Label))
                    {
                        if(str_comp_nocase(Name.c_str()+1, m_pClient->IRC()->GetNick()) != 0)
                            m_pClient->IRC()->OpenQuery(Name.c_str());
                    }
                }

                CComChan::CUser *pUser = &(pChan->m_Users[u]);
                dbg_assert(pUser != NULL, "in render: pChan->m_Users contains invalid pointer");

                //DoButton_Icon(IMAGE_BROWSEICONS, SPRITE_BROWSE_JOIN, &ButtonQS/*, vec4(0.47f, 0.58f, 0.72f, 1.0f)*/);
                CPointerContainer s_JoinButton(pUser);
                ButtonQS.Margin(2.0f, &ButtonQS);
                if(!pUser->IsVoice() && !pUser->IsAdmin() && str_comp(pUser->m_Nick.c_str(), m_pClient->IRC()->GetNick()) != 0)
                    if(DoButton_Menu(&s_JoinButton, "→", 0, &ButtonQS, Localize("Join"), CUI::CORNER_ALL, vec4(0, 0, 1, 0.7f)))
                        //if(UI()->DoButtonLogic(&Item.m_Visible, "", Selected, &ButtonQS))
                    {
                        m_pClient->IRC()->SendGetServer(Name.c_str());
                    }

                // colors for admin and voice
                if(pUser->IsAdmin())
                    TextRender()->TextColor(0.2f, 0.7f, 0.2f, 1);
                else if(pUser->IsVoice())
                    TextRender()->TextColor(0.2f, 0.2f, 0.7f, 1);

                UI()->DoLabelScaled(&Item.m_Rect, Name.c_str(), 12.0f, -1);
                TextRender()->TextColor(1,1,1,1);
            }
            Selected = UiDoListboxEnd(&s_UsersScrollValue, 0);

            static CButtonContainer s_Chat;
            static float s_ChatScrollValue = 1.0f;
            /*if(!Input()->KeyIsPressed(KEY_LSHIFT) && UI()->MouseInside(&Chat))
            {
            	if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP)) // to the right
            		s_ChatScrollValue -= 0.1f;
            	if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN)) // to the left
            		s_ChatScrollValue += 0.1f;
            	s_ChatScrollValue = clamp(s_ChatScrollValue, 0.0f, 1.0f);
            }*/
            UiDoListboxStart(&s_Chat, &Chat, 12.0f,
                             pChan->m_Topic.c_str()[0] ? pChan->m_Topic.c_str() : "", "",
                             (int)pChan->m_Buffer.size(), 1, -1, s_ChatScrollValue, CUI::CORNER_TL);
            for(size_t i = 0; i < pChan->m_Buffer.size(); i++)
            {
                CPointerContainer Container(&pChan->m_Buffer[i]);
                CListboxItem Item = UiDoListboxNextItem(&Container, false, !Input()->KeyIsPressed(KEY_LSHIFT) && UI()->MouseInside(&UserList));

                if(Item.m_Visible)
                {
                    Item.m_Rect.x -= 1.7f*Item.m_Rect.w * s_HScrollbarVal;
                    const char *pSearchFrom = str_find(pChan->m_Buffer[i].c_str(), ">");
                    if(!pSearchFrom)
                        pSearchFrom = pChan->m_Buffer[i].c_str();
                    if(str_find_nocase(pSearchFrom, m_pClient->IRC()->GetNick()))
                    {
                        vec3 rgb = HslToRgb(vec3((float)g_Config.m_ClMessageHighlightHue/255.0f, (float)g_Config.m_ClMessageHighlightSat/255.0f, (float)g_Config.m_ClMessageHighlightLht/255.0f));
                        TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.0f);
                    }
                    UI()->DoLabelScaled(&Item.m_Rect, pChan->m_Buffer[i].c_str(), 10.0f, -1);
                    TextRender()->TextColor(1,1,1,1);
                }
            }
            UiDoListboxEnd(&s_ChatScrollValue, 0);
        }
        else if(pCom->GetType() == CIRCCom::TYPE_QUERY)
        {
            CComQuery *pQuery = static_cast<CComQuery*>(pCom);
            CUIRect Chat, HorizScrollBar;
            EntryBox.Margin(5.0f, &Chat);
            Chat.HSplitBottom(15.0f, &Chat, &HorizScrollBar);

            static CButtonContainer s_HScrollbar;
            static float s_HScrollbarVal = 0.0f;
            s_HScrollbarVal = DoScrollbarH(&s_HScrollbar, &HorizScrollBar, s_HScrollbarVal);
            if(Input()->KeyIsPressed(KEY_LSHIFT) && m_pClient->m_pGameConsole->IsClosed())
            {
                if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN)) // to the right
                    s_HScrollbarVal += 0.1f;
                if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP)) // to the left
                    s_HScrollbarVal -= 0.1f;
                s_HScrollbarVal = clamp(s_HScrollbarVal, 0.0f, 1.0f);
            }

            static CButtonContainer s_Chat;
            static float s_ChatScrollValue = 1.0f;
            /*if(!Input()->KeyIsPressed(KEY_LSHIFT) && UI()->MouseInside(&Chat))
            {
            	if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP)) // to the right
            		s_ChatScrollValue -= 0.1f;
            	if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN)) // to the left
            		s_ChatScrollValue += 0.1f;
            	s_ChatScrollValue = clamp(s_ChatScrollValue, 0.0f, 1.0f);
            }*/
            UiDoListboxStart(&s_Chat, &Chat, 12.0f, pQuery->User(), "", (int)pQuery->m_Buffer.size(), 1, -1,
                             s_ChatScrollValue);
            for(size_t i = 0; i < pQuery->m_Buffer.size(); i++)
            {
                CPointerContainer Container(&pQuery->m_Buffer[i]);
                CListboxItem Item = UiDoListboxNextItem(&Container, false, !Input()->KeyIsPressed(KEY_LSHIFT) && UI()->MouseInside(&Chat));

                if(Item.m_Visible)
                {
                    Item.m_Rect.x -= 1.7f*Item.m_Rect.w * s_HScrollbarVal;
                    if(pQuery->m_Buffer[i].c_str())
                        if(str_length(pQuery->m_Buffer[i].c_str()))
                            UI()->DoLabelScaled(&Item.m_Rect, pQuery->m_Buffer[i].c_str(), 10.0f, -1);
                }
            }
            UiDoListboxEnd(&s_ChatScrollValue, 0);

            // the join button
            if(str_comp_nocase(pQuery->User(), "@status") != 0 && str_comp(pQuery->User(), m_pClient->IRC()->GetNick()) != 0 &&
                    ((CComChan*)m_pClient->IRC()->GetCom(1))->GetUser(std::string(pQuery->User())) && // this is kinda inefficient but whatever...
                    !((CComChan*)m_pClient->IRC()->GetCom(1))->GetUser(std::string(pQuery->User()))->IsVoice() &&
                    !((CComChan*)m_pClient->IRC()->GetCom(1))->GetUser(std::string(pQuery->User()))->IsAdmin()
              )
            {
                CUIRect ButtonQS;
                Chat.VSplitRight(32.0f, 0x0, &ButtonQS);
                ButtonQS.h = 32.0f;
                ButtonQS.x -= 20.0f;
                ButtonQS.y += 25.0f;
                RenderTools()->DrawUIRect(&ButtonQS, vec4(0.2f, 0.6f, 0.4f, UI()->MouseInside(&ButtonQS) ? 1.0f : 0.6f),
                                          CUI::CORNER_ALL, 15.0f);
                ButtonQS.x += 5.0f;
                ButtonQS.y += 7.0f;
                UI()->DoLabelScaled(&ButtonQS, Localize("Join"), 11.0f, -1);
                //DoButton_Icon(IMAGE_BROWSEICONS, SPRITE_BROWSE_CONNECT, &ButtonQS, vec4(0.47f, 0.58f, 0.72f, 1.0f));
                static int s_ButtonQSLog = 0;
                if(UI()->DoButtonLogic(&s_ButtonQSLog, "", 0, &ButtonQS))
                {
                    m_pClient->IRC()->SendGetServer(pQuery->User());
                }
            }
        }
    }
}
Esempio n. 26
0
void prs_file( const char *filename )
{
   char              *buffer;
   const char        **pt;
   static const char *cpp = NULL;
   static const char *cpps[] = { "/lib/cpp",
                                 "/usr/lib/cpp",
                                 "/usr/ccs/lib/cpp",	/* Solaris */
                                 "/usr/lang/cpp",
                                 0 };
   static const char *extra_options = "";
   FILE              *tmp;
   
   if (!filename)
      err_fatal( __FUNCTION__, "No filename specified\n" );

   if (!cpp) {
      if ((cpp = getenv( "KHEPERA_CPP" ))) {
         PRINTF(MAA_PARSE,("%s: Using KHEPERA_CPP from %s\n",__func__,cpp));
      }
      
                                /* Always look for gcc's cpp first, since
                                   we know it is ANSI C compliant. */
      if (!cpp && (tmp = popen( "gcc -print-file-name=cpp", "r" ))) {
         char buf[1024];
         char *t;
         
         if (fread( buf, 1, 1023, tmp ) > 0) {
            if ((t = strchr( buf, '\n' ))) *t = '\0';
            PRINTF(MAA_PARSE,("%s: Using GNU cpp from %s\n",__func__,buf));
            cpp = str_find( buf );
            extra_options = "-nostdinc -nostdinc++";
         }
         pclose( tmp );
      }

                                /* Then look for the vendor's cpp, which
                                   may or may not be useful (e.g., on SunOS
                                   4.x machines, it isn't ANSI C
                                   compatible.  Considering ANSI C is C89,
                                   and this is 1996, one might think that
                                   Sun would have fixed this... */
      if (!cpp) {
         for (pt = cpps; **pt; pt++) {
            if (!access( *pt, X_OK )) {
               PRINTF(MAA_PARSE,
                      ("%s: Using system cpp from %s\n",__func__,*pt));
               cpp = *pt;
               break;
            }
         }
      }
      
      if (!cpp)
	 err_fatal("%s:Cannot locate cpp -- set KHEPERA_CPP to cpp's path\n",
		   __func__ );
   }

   buffer = alloca( strlen( cpp )
                    + sizeof( filename )
		    + (_prs_cpp_options ? strlen( _prs_cpp_options ) : 0)
		    + 100 );

   sprintf( buffer, "%s -I. %s %s 2>/dev/null", cpp,
	    _prs_cpp_options ? _prs_cpp_options : "", filename );

   PRINTF(MAA_PARSE,("%s: %s\n",__func__,buffer));
   if (!(yyin = popen( buffer, "r" )))
      err_fatal_errno("%s Cannot open \"%s\" for read\n", __func__, filename );

   src_new_file( filename );
   yydebug = _prs_debug_flag;
   yyparse();
   pclose( yyin );
}
Esempio n. 27
0
void prs_set_cpp_options( const char *cpp_options )
{
   _prs_cpp_options = cpp_options ? str_find( cpp_options ) : NULL;
}
Esempio n. 28
0
bool IsPlus(const CServerInfo *pInfo)
{
	return str_find(pInfo->m_aGameType, "+");
}
Esempio n. 29
0
/* 29*/ int
/* 29*/ Namespace_isIdentifier(STRING *Namespace_name)
/* 29*/ {
/* 29*/ 	return (str_find(Namespace_name, m2runtime_CHR(92)) < 0);
/* 33*/ }
Esempio n. 30
0
/* 23*/ int
/* 23*/ Namespace_isQualified(STRING *Namespace_name)
/* 23*/ {
/* 23*/ 	return (str_find(Namespace_name, m2runtime_CHR(92)) > 0);
/* 27*/ }