Esempio n. 1
5
      // Numerical user_key format: "%s%ld%s",prefix,inc_number,suffix
      // if no numbers found, treat it as string
      int  NumericalComparatorImpl::Compare(const leveldb::Slice& a, const leveldb::Slice& b) const
      {
        assert(a.size() > LDB_COMPARE_META_ALL_SIZE && b.size() > LDB_COMPARE_META_ALL_SIZE );
        int64_t num_a = 0, num_b = 0;
        int ret = 0;
        const char *prefix_a, *prefix_b, *delimiter_a, *delimiter_b, *suffix_a, *suffix_b;

        prefix_a = MetaSkip(a.data() + LDB_COMPARE_META_ALL_SIZE, a.size() - LDB_COMPARE_META_ALL_SIZE);  
        delimiter_a = FindNumber(prefix_a, a.size() - (prefix_a - a.data()));
        prefix_b = MetaSkip(b.data() + LDB_COMPARE_META_ALL_SIZE, b.size() - LDB_COMPARE_META_ALL_SIZE);  
        delimiter_b = FindNumber(prefix_b, b.size() - (prefix_b - b.data()));
        //compare bucket_num+area+meta+prefix
        const size_t pre_len_a = delimiter_a - a.data() - LDB_COMPARE_SKIP_SIZE;
        const size_t pre_len_b = delimiter_b - b.data() - LDB_COMPARE_SKIP_SIZE;
        ret = StringCompare(a.data() + LDB_COMPARE_SKIP_SIZE, pre_len_a, b.data() + LDB_COMPARE_SKIP_SIZE, pre_len_b);
        if (ret == 0)
        {
          //prefixs equal, compare number
          num_a = Strntoul(delimiter_a, a.size() - (delimiter_a - a.data()), &suffix_a);
          num_b = Strntoul(delimiter_b, b.size() - (delimiter_b - b.data()), &suffix_b);
          if (num_a != num_b)
          {
            ret = (num_a - num_b) > 0 ? 1 : -1;
          } 
          else
          {
            //numbers equal or no numbers found, compare suffix
            const size_t suf_len_a = a.size() - (suffix_a - a.data());
            const size_t suf_len_b = b.size() - (suffix_b - b.data());
            ret = StringCompare(suffix_a, suf_len_a, suffix_b, suf_len_b);
          }
        }
        return ret;
      }
Esempio n. 2
0
void test_StringCompare()
{
    char *str1 = "test string 1";
    char *str2 = "test string 2";
    
    I32 result = StringCompare(str1, str2);
    ERROR(result == -1);

    result = StringNCompare(str1, str2, 12);
    ERROR(result == 0);

    result = StringNCompare(str1, str2, 0);
    ERROR(result == 0);

    str1 = "";

    result = StringCompare(str1, str2);
    ERROR(result == -1);

    str2 = "";

    result = StringCompare(str1, str2);
    ERROR(result == 0);

    str1 = "I am, indeed, a king,";

    result = StringCompare(str1, "I am, indeed, a king,");
    ERROR(result == 0);
}
Esempio n. 3
0
void demo_CacheAlloc()
{
    // leave 1024 bytes for cache allocation
    g_hunk_low_used = g_hunk_total_size - g_hunk_high_used - 1024;

    char cmdLine[32];
    char arg0[16];
    char arg1[16];
    char userCountStr[16];
    CacheUser cacheUser[128] = {0};
    I32 cacheUserCount = 0;

    printf("Cache Alloc Demo Starts ... \n\n");
    printf("Available cache size: %d bytes\n", demo_EndFreeSizeForCache());
    printf("Allocation size includes the size of cache header which is 64 bytes and will be 16-byte aligned\n");
    printf("[allocation count | hole | end: memory size]\n");
    printf("hole and end are free memory blocks\n");
    printf("LRU list: most recent used -> least recent used\n");
    printf("type \"alloc\" and a number to allocate cache or \"exit\" to end the demo\n\n");

    bool running = true;
    while (running)
    {
        if (fgets(cmdLine, 32, stdin) != cmdLine)
        {
            continue ;
        }

        demo_ParseCommand(cmdLine, arg0, arg1);

        if (StringCompare(arg0, "alloc") == 0)
        {
            cacheUserCount++;

            if (cacheUserCount >= 128)
            {
                printf("Exceed maximum times of allocation!");
                break ;
            }

            I32 size = StringToInt(arg1);
            IntToString(cacheUserCount, userCountStr, 16);

            CacheAlloc(cacheUser + cacheUserCount, size, userCountStr);

            demo_drawCacheList();
            demo_DrawLRUList();
        }
        else if (StringCompare(arg0, "exit") == 0)
        {
            running = false;
        }
        else
        {
            printf("unrecognized command\n");
        }
    }

    printf("Cache Alloc Demo Ended.");
}
Esempio n. 4
0
//=============================================================================
char*
ListFilesInDirectory(
const char* DirName ) ///< name of a directory
{
  if ( DirName == NULL ) return NULL;
    
  DIR *directory = opendir(DirName);
  
  if ( directory == NULL ) return NULL;
  
  // entry in the directory
  struct dirent *entry;
  
  // initialize file list to empty
  char* FileList = StringDuplicate("");

  // loop over entries
  while( (entry = readdir(directory)) != NULL )
  {
    // filter . and .. entries
    if ( StringCompare(entry->d_name,".") || 
         StringCompare(entry->d_name,"..") ) continue;
    
    // append file name and separator to list
    StringAppend(&FileList,entry->d_name);
    StringAppend(&FileList," ");
  }
  
  // close directory
  assert_error( closedir(directory) == 0, "Failed to close directory");
  
  return FileList;
}
Esempio n. 5
0
static int NewsArticleCompare(const void *elem1, const void *elem2)
{
  const rssNewsArticle *article1 = elem1;
  const rssNewsArticle *article2 = elem2;
  if ((StringCompare(&article1->title, &article2->title) == 0) &&
      (StringCompare(&article1->server, &article2->server) == 0)) return 0;
  
  return StringCompare(&article1->fullURL, &article2->fullURL);
}
Esempio n. 6
0
void test_IntToString()
{
    char str[128];
    IntToString(1234, str, 128);
    ERROR(StringCompare(str, "1234") == 0);

    IntToString(123456, str, 3);
    ERROR(StringCompare(str, "56") == 0);

    IntToString(-12223, str, 128);
    ERROR(StringCompare(str, "-12223") == 0);

    IntToString(0, str, 128);
    ERROR(StringCompare(str, "0") == 0);
}
Esempio n. 7
0
bool filter_by_slice( const slice * slice, const String * refname, uint64_t start, uint64_t end )
{
    bool res = ( StringCompare( slice->refname, refname ) == 0 );
    if ( res )
        res = ( ( end >= slice->start ) && ( start <= slice->end ) );
    return res;
}
TString *USBStandardHubGetDeviceNames (TUSBDevice *pDevice)
{
	assert (pDevice != 0);

	TString *pResult = (TString *) malloc (sizeof (TString));
	assert (pResult != 0);
	String (pResult);

	for (unsigned nSelector = DeviceNameVendor; nSelector < DeviceNameUnknown; nSelector++)
	{
		TString *pName = USBDeviceGetName (pDevice, (TDeviceNameSelector) nSelector);
		assert (pName != 0);

		if (StringCompare (pName, "unknown") != 0)
		{
			if (StringGetLength (pResult) > 0)
			{
				StringAppend (pResult, ", ");
			}

			StringAppend (pResult, StringGet (pName));
		}

		_String (pName);
		free (pName);
	}

	if (StringGetLength (pResult) == 0)
	{
		StringSet (pResult, "unknown");
	}

	return pResult;
}
Esempio n. 9
0
static jc_int GetKeyword(CJcKeywordMap* map, const jc_char* sKey, jc_int defaultVal)
{
	CJcKeywordElem *e = map->pKeywordTable[jcc_string_hash(sKey) % 128];
	while (e != NULL && StringCompare(e->sKey, sKey))
		e = e->pNext;
	return e == NULL ? defaultVal : e->nVal;
}
Esempio n. 10
0
//**********************************************************************************
//	
//**********************************************************************************
int	CSkinListItem::Compare( const void * arg1, const void * arg2 )
{
	const CSkinListItem * const	p_l( ( *( CSkinListItem ** )( arg1 ) ) );
	const CSkinListItem * const	p_r( ( *( CSkinListItem ** )( arg2 ) ) );

	return StringCompare( p_l->GetSkinName(), p_r->GetSkinName() );
}
Esempio n. 11
0
FileType
SessionImpl::DeriveFileType (/*[in]*/ const char * lpszPath)
{
    MIKTEX_ASSERT_STRING (lpszPath);

    RegisterFileTypes ();

    const char * lpszExt = GetFileNameExtension(lpszPath);

    for (int idx = 1; idx < fileTypes.size(); ++ idx)
    {
        if (lpszExt == 0)
        {
            if (StringCompare(fileTypes[idx].fileTypeString.c_str(), lpszPath) == 0)
            {
                return (fileTypes[idx].fileType);
            }
        }
        else
        {
            for (CSVList ext (fileTypes[idx].fileNameExtensions.c_str(), PATH_DELIMITER);
                    ext.GetCurrent() != 0;
                    ++ ext)
            {
                if (PathName::Compare(ext.GetCurrent(), lpszExt) == 0)
                {
                    return (fileTypes[idx].fileType);
                }
            }
        }
    }

    return (FileType::None);
}
Esempio n. 12
0
Void CText::SetText( String string )
{
	if( StringCompare( string, m_Text.GetBuffer() ) == 0 )
		return;

	StringCopy( string, m_Text.GetBuffer(), m_Capacity );
	ProcessText();
}
Esempio n. 13
0
rc_t KeyRingDataAddProject(KeyRingData* data, const String* name, const String* download_ticket, const String* encryption_key)
{
    rc_t rc = 0;
    Project* p;

    p = (Project*)BSTreeFind(&data->projects, name, FindProject);
    if (p != NULL)
    {
        bool rewrite = false;
        String* dl = NULL;
        String* enc = NULL;
        if (StringCompare(p->download_ticket, download_ticket) != 0)
        {
            dl = p->download_ticket;
            rc = StringCopy((const String**)&p->download_ticket, download_ticket);
            if (rc == 0)
                rewrite = true;
            else
                dl = NULL;
        }
        if (rc == 0 && StringCompare(p->encryption_key, encryption_key) != 0)
        {
            enc = p->encryption_key;
            rc = StringCopy((const String**)&p->encryption_key, encryption_key);
            if (rc == 0)
                rewrite = true;
            else
                enc = NULL;
        }
        if (rc == 0 && rewrite)
        {
            if (dl)
                StringWhack(dl);
            if (enc)
                StringWhack(enc);
        }
    }
    else /* insert new */
    {
        rc = KeyRingDataInsertProject (&data->projects, data->next_projectId, name, download_ticket, encryption_key);
        if (rc == 0)
            ++data->next_projectId;
    }
    return rc;
}
Esempio n. 14
0
  inline
  bool
  operator() (/*[in]*/ const RepositoryInfo &	lhs,
	      /*[in]*/ const RepositoryInfo &	rhs)
  {
    return (StringCompare(lhs.country.c_str(),
			  rhs.country.c_str(),
			  true)
	    < 0);
  }
Esempio n. 15
0
void test_StringCopy()
{
    char *src = "normal string";
    char dest[128];

    I32 result = StringCopy(dest, 128, src, 0);
    ERROR(result == 13);
    ERROR(StringCompare(dest, src) == 0);

    result = StringCopy(dest, 128, src, 6);
    ERROR(result == 6);
    ERROR(StringCompare(dest, "normal") == 0);

    result = StringCopy(dest, 3, src, 128);
    ERROR(result == 2);
    ERROR(StringCompare(dest, "no") == 0);

    result = StringCopy(dest, 128, "", 128);
    ERROR(result == 0);
    ERROR(StringCompare(dest, "") == 0);
}
Esempio n. 16
0
/* ----------------------------------------------------------------------
 * KTocEntryCmp2
 *
 * [RET] int					>0: if n > p
 *						0:  if n == p
 *						<0: if n < p
 * [IN]  const BSTNode * 	n		where the pointer to a node matching the key is put
 * [IN]  const BSTNode * 	p		where the pointer to a node matching the key is put
 * This function fits the function signature needed for BSTreeInsert
 *
 * can not inline or make into a macro as it is referenced via a pointer
 */
int64_t CC KTocEntryCmp2 ( const BSTNode * n, const BSTNode * p )
{

    KTocEntry * nn;
    KTocEntry * pp;
    int64_t		  ii;

    nn = (KTocEntry *)n;
    pp =  (KTocEntry *)p;
    ii = StringCompare (&nn->name, &pp->name);
    return ii;
}
Esempio n. 17
0
//==============================================================================
bool
StringEndsWith(
const char* end,      ///< sub string
const char* string )  ///< string
{
  // check end
  assert_warn( end != NULL, "no extension provided" );
  
  if ( string == NULL || strlen(string) < strlen(end) ) return false;
  
  return StringCompare( &string[ strlen(string) - strlen(end) ], end );
}
Esempio n. 18
0
/* Sort
 *  compares by ( name, type ) pair
 */
int CC VColumnRefSort ( const BSTNode *item, const BSTNode *n )
{
    const VColumnRef *a = ( const VColumnRef* ) item;
    const VColumnRef *b = ( const VColumnRef* ) n;

    /* sorted first by name - case sensitive ASCII alphabetically */
    int diff = StringCompare ( & a -> name, & b -> name );
    if ( diff != 0 )
        return diff;

    /* sort by cid */
    return VCtxIdCmp ( & a -> cid, & b -> cid );
}
Esempio n. 19
0
File: ykfs.c Progetto: Yushatak/ykOS
uintptr_t ykfs_find_entry(uintptr_t ykfs, const char* name)
{
	ykfs_header_t* header = (ykfs_header_t*)ykfs;
	if (!ykfs_check_format(ykfs))
	{
		Output("\nInvalid filesystem format.");
		return 0;
	}
	uintptr_t entries = ykfs_get_entries(ykfs);
	size_t entry_size = header->format.EntrySize;
	size_t entry_count = header->format.EntryCount;
	for (int i = 0; i < entry_count; i++)
	{
		if (StringCompare((char*)entries, (char*)name))
			return entries;
		else
			entries += entry_size;
	}
	Output("Result: 0x%x", entries);
	if (StringCompare((char*)entries, (char*)name))
		return entries;
	else return 0;
}
Esempio n. 20
0
bool
IsAttributeMatch(const BMessage &test, const entry_ref &ref)
{
	BString value;
	if (test.FindString("value",&value) != B_OK)
	{
		debugger("Couldn't get value in IsTypeMatch");
		return false;
	}
	
	BString compare;
	if (test.FindString("mode",&compare) != B_OK)
	{
		debugger("Couldn't get mode in IsTypeMatch");
		return false;
	}
	
	BString attribute;
	if (test.FindString("attrtype",&attribute) != B_OK)
	{
		debugger("Couldn't get attribute in IsAttributeMatch");
		return false;
	}
	
	BString string;
	attr_info info;
	BNode node(&ref);
	if (node.InitCheck() != B_OK)
		return false;
	
	if (node.GetAttrInfo(attribute.String(),&info) != B_OK)
		return false;
	
	if (node.ReadAttrString(attribute.String(),&string) != B_OK)
		return false;
	
	
	bool result = StringCompare(value,string,compare.String(),true);
	
	
	BString attrname;
	if (test.FindString("attrname",&attrname) != B_OK)
		attrname = attribute;
	
	printf("\tAttribute test: %s %s %s - %s\n",attrname.String(),
								compare.String(),value.String(),
								result ? "MATCH" : "NO MATCH");
	
	return result;
}
Esempio n. 21
0
/**
 * @brief ATcmd     send AT common 发送AT指令通用函数
 * @param cmd       AT common string or null(send nothing) AT指令(字符串)或空(不发送任何东西)
 * @param timeOut_s   time out  多少秒超时
 * @param cmd_num   The num of cmd which it exp 需要对比的命令(即"..."的参数个数)
 * @return  大于0时,表示收到和列表匹配的字符串
 *cmd   cmdLen
 *0     0       send nothing,wait exp       不发送任何东西,等待收到列表中的字符串
 *!=0   0       send cmd string,wait exp    发送字符串,等待收到列表中的字符串
 *!=0   !=0     send hex data,wait exp      发送十六进制数据,等待收到列表中的字符串
 *0     !=0     send nothing,wait exp       不发送任何东西,等待收到列表中的字符串
 */
s8 ATcmd(u8 *cmd,u8 cmdLen,u8 timeOut_s,u8 *pOut,u8 cmd_num,...)
{
    static u8 sate=0;
    s8 ret=WAITING_EVENT;
    u8 i;
    va_list vap;
    u8 *pStr1;
    u8 *pStr2;
    if(sate!=0) goto wait;

    //send cmd
    if((cmd!=0)&&(cmdLen==0))IO_write_str((u8*)cmd);    //if cmd is string then cmdlen can be set to zro
    else if((cmd!=0)&&(cmdLen!=0))IO_write(cmd,cmdLen); //this is use to send hex data
    //if timeOut_s is zro will return TIME_OUT
    if(timeOut_s==0)
    {
        ret=TIME_OUT;
        return ret;     //@2015.6.18 时间设置为零时应该直接返回
    }
    else    setTimeOut(timeOut_s);
    sate=1;
    //set time out time
    //wait event
wait:
    if((ATevent&EVENT_AT_FRAME)||(ATevent&EVENT_TIME_OUT))
    {
        if(ATevent&EVENT_AT_FRAME)
        {
            ATevent&=~EVENT_AT_FRAME;     //clear pending event
            va_start(vap , cmd_num);     //set the last one parameter
            //get AT common string from buffer
           pStr1=GetATFrame();
           for(i=0;i<cmd_num;i++)
           {
                pStr2=va_arg(vap , u8*);  //get list's pointer
                ATAssert(pStr2!=0);
               if( StringCompare(pStr1,pStr2))
               {
                   if(pOut)StrCopy(pOut,pStr1);//if pOut not zro copy The string out
                   break;  //it is the same of list's string
               }
           }
           va_end(vap);    //set vap to zro
           if(i==cmd_num) ret=UNEXPECT_CMD; //the string is unkown
           else ret=i+1;
        }
        else
        {
Esempio n. 22
0
/* Sort
 */
static
int CC KRepositorySort ( const void **a, const void **b, void *ignore )
{
    const KRepository *left = * a;
    const KRepository *right = * b;

    if ( left -> category < right -> category )
        return -1;
    if ( left -> category > right -> category )
        return 1;
    if ( left -> subcategory < right -> subcategory )
        return -1;
    if ( left -> subcategory > right -> subcategory )
        return 1;
    return StringCompare ( & left -> name, & right -> name );
}
Esempio n. 23
0
const char *Pxf::StringFindRev(const char *t, const char *f)
{
	int lt = StringLength(t);
	int lf = StringLength(f);
	const char *p;

	if (!lf || !f || !t || lf > lt)
		return 0;

	p = (char*)t+lt-lf;
	for(;(p = StringFindRev(t, *f));t = p+1)
		if(StringCompare(p, f, lf) == 0)
			return p;

	return 0;
}
Esempio n. 24
0
static CJcSymbolItem* GetEntryAddress(CJcSymbolStack* pStack, CJcSymbolItem* pSymbol, jc_uint nSymbolCount, char* sEntrySymbol, CJcSegment* pSegment)
{
	jc_uint i;
	jc_char* ts = GetDataOfSegment(pSegment);/*GetDataOfSegment(&pStack->oConstSegment);*/
	for(i=0; i<nSymbolCount; ++i)
	{
		if(!StringCompare(ts+pSymbol->name, sEntrySymbol))
		{
			if(pSymbol->opt == JC_CS || pSymbol->opt == JC_DS)
				return pSymbol;
			break;
		}
		pSymbol++;
	}
	return NULL;
}
main()
{
    char   	One[] = "Bartman";
    char	Two[] = "Batman";

    int		Ret;

    Ret = StringCompare(One, Two);

    if (Ret == TRUE)
    {
        puts("The Strings match");
    }
    else
    {
        puts("The Strings do not match");
    }
}
Esempio n. 26
0
static int64_t CC BSTItemCmp ( const void * item, const BSTNode * n ) {
    int64_t res = 0;

    const HttpProxy * s = item;
    const BSTItem * i = ( BSTItem * ) n;

    assert ( s && i );

    res = StringCompare ( i -> proxy -> proxy_host,  s -> proxy_host );
    if ( res != 0 )
        return res;
    else if ( i -> proxy -> proxy_port == s -> proxy_port )
        return 0;
    else if ( i -> proxy -> proxy_port < s -> proxy_port )
        return -1;
    else
        return 1;
}
Esempio n. 27
0
bool
IsTypeMatch(const BMessage &test, const entry_ref &ref)
{
	BString value;
	if (test.FindString("value",&value) != B_OK)
	{
		debugger("Couldn't get value in IsTypeMatch");
		return false;
	}

//if (value == "image/")
//	debugger("");
	
	BString compare;
	if (test.FindString("mode",&compare) != B_OK)
	{
		debugger("Couldn't get mode in IsTypeMatch");
		return false;
	}
	
	BString string;
	attr_info info;
	BNode node(&ref);
	if (node.InitCheck() != B_OK)
		return false;
	
	if (node.GetAttrInfo("BEOS:TYPE",&info) != B_OK)
	{
		BPath path(&ref);
		if (update_mime_info(path.Path(),0,1,0) != B_OK)
			return false;
	}
	
	if (node.ReadAttrString("BEOS:TYPE",&string) != B_OK)
		return false;
	
	
	bool result = StringCompare(value,string.String(),compare.String(),true);
	
	printf("\tType test: %s %s %s - %s\n",ref.name,compare.String(),value.String(),
								result ? "MATCH" : "NO MATCH");
	
	return result;
}
Esempio n. 28
0
static ref_node * find_ref_node( ref_exclude *exclude, const String * s )
{
    BSTNode *node;

    if ( exclude->last_used_ref_node != NULL )
    {
        ref_node * node = ( ref_node * )exclude->last_used_ref_node;
        if ( StringCompare ( s, node->name ) == 0 )
            return node;
    }

    node = BSTreeFind ( &exclude->ref_nodes, s, ref_node_find );
    if ( node == NULL )
        return NULL;
    else
    {
        exclude->last_used_ref_node = node;
        return ( ref_node * ) node;
    }
}
Esempio n. 29
0
static spotgrp * find_spotgroup( statistic *self, const char *src, const size_t len )
{
    String s;
    BSTNode *node;

    StringInit( &s, src, len, len );
    if ( self->last_used_spotgroup != NULL )
    {
        spotgrp * sg = ( spotgrp* )self->last_used_spotgroup;
        if ( StringCompare ( &s, sg->name ) == 0 )
            return sg;
    }

    node = BSTreeFind ( &self->spotgroups, &s, spotgroup_find );
    if ( node == NULL )
        return NULL;
    else
    {
        self->last_used_spotgroup = node;
        return ( spotgrp *) node;
    }
}
Esempio n. 30
0
int main()
{
	printf("YOUUUUUU\n");
	sleep(1);
	printf("SHALL NOT\n");
	sleep(1);
	printf("PAAAAASS!!\n");
	printf("(You'll never break THIS encoding scheme!)\n");

	char *input = readline("");
	AssembleFlag();

	if(StringCompare(input, flag) == 0)
	{
		printf("Congratulations! You are a cool Mithrandir!\n");
		exit(0);
	}
	else
	{
		printf("No... you are not a very cool Mithrandir...\n");
		exit(0);
	}
}