Esempio n. 1
0
int test(void)
{
/*	char s1[]=NULL;
	char* s2=NULL;*/
	char s3[]="";
	char* s4="";
	char s5[]="abcd";
	char* s6="dcba";
	char s7[]="ucaabbcsd";
	char* s8="dscbbaacu";
	char s9[]="a bcs";
	char* s10="scb a";

/*	if(!m_strcmp(Fun(s1),s2))
	{
		return 0;
	}*/
	if(!m_strcmp(Fun(s3),s4))
	{
		return 0;
	}
	if(!m_strcmp(Fun(s5),s6))
	{
		return 0;
	}
	if(!m_strcmp(Fun(s7),s8))
	{
		return 0;
	}
	if(!m_strcmp(Fun(s9),s10))
	{
		return 0;
	}
	return 1;
}
Esempio n. 2
0
memory_tree_t * CFileStream::FileIsExists(char* TreePath)
{
	static char szPath[MAX_PATH];
	char* szChars;
	char* pszFolderName;
	if(TreePath && TreePath[0] == '/')
	{
		strcpy(szPath,TreePath);
		szChars = (char*)&szPath;
		if(memoryTreeRoot.dataList.size() == 0)
		{
			return NULL;
		}
		szChars++;
		pszFolderName = GetFolderName(szChars);
		if(pszFolderName)
		{
			int listsize = memoryTreeRoot.dataList.size();
			if(listsize)
			{
				DWORD hashvalue = GetHashValue(pszFolderName);
				for(int i=0;i<listsize;i++)
				{
					if(memoryTreeRoot.dataList[i]->bDirectory &&
						memoryTreeRoot.dataList[i]->dwHashValue == hashvalue &&
						m_strcmp(memoryTreeRoot.dataList[i]->nStringIdx,pszFolderName))
					{
						char* nextdir = &szChars[strlen(pszFolderName)+1];
						return RecursionFileExists(nextdir,memoryTreeRoot.dataList[i]);
					}
				}
			}
			return NULL;
		}
		else
		{
			int listsize = memoryTreeRoot.dataList.size();
			if(listsize)
			{
				DWORD hashvalue = GetHashValue(szChars);
				for(int i=0;i<listsize;i++)
				{

					if(!memoryTreeRoot.dataList[i]->bDirectory &&
						memoryTreeRoot.dataList[i]->dwHashValue == hashvalue &&
						m_strcmp(memoryTreeRoot.dataList[i]->nStringIdx,szChars)
						)
					{
						return memoryTreeRoot.dataList[i];
					}
				}
			}
		}
	}
	return NULL;
}
//gcc -Wall ../m_function.c section_5.6_pointer_array.c && ll | awk '{print $5}' | ./a.out -n -r
int main(int argc, char *argv[])
{
	int nlines;
	int op_numeric, op_reverse, op_ignorecase, op_key;
	int (*op_func_comparison)(void *, void *);

	//Argument
	op_numeric = op_ignorecase = 0;
	op_reverse = 1;
	op_key = -1;
	while (--argc > 0) {
		argv++;
		if (op_key == -2)
			op_key = m_str2int(*argv, 10);
		else if (m_strcmp(*argv, "-n") == 0)
			op_numeric = 1;
		else if (m_strcmp(*argv, "-r") == 0)
			op_reverse = -1;
		else if (m_strcmp(*argv, "-f") == 0)
			op_ignorecase = 1;
		else if (m_strcmp(*argv, "-k") == 0)
			op_key = -2;
		else if (m_strncmp(*argv, "-k", 2) == 0)
			op_key = m_str2int((*argv + 2), 10);
	}
	op_key = op_key >= 0 ? op_key : 0;
	if (op_ignorecase)
		op_func_comparison = (int (*)(void*,void*)) m_strcasecmp;
	else if (op_numeric)
		op_func_comparison = (int (*)(void*,void*)) numcmp;
	else
		op_func_comparison = (int (*)(void*,void*)) m_strcmp;

	//Sort
	if ((nlines = readlines(lineptr, MAXLINES)) >= 0) {
		qsort(
			(void **)lineptr,
			0,
			nlines - 1,
			op_func_comparison,
			op_reverse,
			op_key
		);
		writelines(lineptr, nlines);
		printf("Total:%d\n", nlines);
		return 0;
	} else {
		printf("error: input too big to sort\n");
		return 1;
	}
}
Esempio n. 4
0
bool CFileStream::RecursionInsertFile(char* treepath,memory_tree_s* fileTree,memory_tree_s* DirTree)
{
	char TreeRoot[MAX_PATH];
	if(treepath[0] == '/')
	{
		treepath++;
		return RecursionInsertFile(treepath,fileTree,&memoryTreeRoot);
	}
	if(DirTree)
	{
		strcpy(TreeRoot,treepath);
		char * folderName = GetFolderName(TreeRoot);
		if(folderName)
		{
			int listsize = DirTree->dataList.size();
			if(listsize)
			{
				DWORD hashvalue = GetHashValue(folderName);
				for(int i=0;i<listsize;i++)
				{
					if(DirTree->dataList[i]->bDirectory &&
						DirTree->dataList[i]->dwHashValue == hashvalue &&
						m_strcmp(DirTree->dataList[i]->nStringIdx,folderName))
					{
						char* nextdir = &treepath[strlen(folderName)+1];
						return RecursionInsertFile(nextdir,fileTree,DirTree->dataList[i]); 
					}
				}
				memory_tree_s* newdir = new memory_tree_s;
				newdir->bDirectory = TRUE;
				newdir->nStringIdx = AllocString(folderName);
				newdir->dataSize = 0;
				newdir->dataOffset = 0;
				newdir->dwHashValue = GetHashValue(folderName);
				DirTree->dataList.push_back(newdir);
				char* nextdir = &treepath[strlen(folderName)+1];
				return RecursionInsertFile(nextdir,fileTree,newdir);
			}
			else
			{
				memory_tree_s* newdir = new memory_tree_s;
				newdir->bDirectory = TRUE;
				newdir->nStringIdx = AllocString(folderName);
				newdir->dataSize = 0;
				newdir->dataOffset = 0;
				newdir->dwHashValue = GetHashValue(folderName);
				DirTree->dataList.push_back(newdir);
				char* nextdir = &treepath[strlen(folderName)+1];
				return RecursionInsertFile(nextdir,fileTree,newdir);
			}
		}
		else
		{
			DirTree->dataList.push_back(fileTree);
			return true;
		}
	}
	return false;
}
Esempio n. 5
0
track_node * NodeNameToTrackNode(track_node * track_nodes, char * name) {
    int i;
    for (i = 0; i < TRACK_MAX; i++) {
        track_node * node = &track_nodes[i];

        if (m_strcmp(name, node->name) == 0) {
            return node;
        }
    }

    return 0;
}
Esempio n. 6
0
int NameServer_GetName(NameServer * ns, char * name) {
	int tid;

	for (tid = 0; tid < MAX_TASKS + 1; tid++) {
		if (!ns->filled[tid]) {
			continue;
		}

		if (m_strcmp(ns->names[tid], name) == 0) {
			return tid;
		}
	}

	return 0;
}
Esempio n. 7
0
memory_tree_s* CFileStream::RecursionFileExists(char* TreePath,memory_tree_s* DirTree)
{
	char* pszFolderName = GetFolderName(TreePath);
	if(pszFolderName)
	{
		DWORD hashvalue = GetHashValue(pszFolderName);
		
		int listsize = DirTree->dataList.size();
		if(listsize)
		{
			for(int i=0;i<listsize;i++)
			{
				if(DirTree->dataList[i]->bDirectory && DirTree->dataList[i]->dwHashValue == hashvalue && m_strcmp(DirTree->dataList[i]->nStringIdx,pszFolderName))
				{
					char* nextdir = &TreePath[strlen(pszFolderName)+1];
					return RecursionFileExists(nextdir,DirTree->dataList[i]);
				}
			}
		}
		else
		{
			return NULL;
		}

	}
	else
	{
		int listsize = DirTree->dataList.size();
		if(listsize)
		{
			DWORD hashvalue = GetHashValue(TreePath);
			for(int i=0;i<listsize;i++)
			{
				if(!DirTree->dataList[i]->bDirectory)
				{
					if( DirTree->dataList[i]->dwHashValue == hashvalue &&
						m_strcmp(DirTree->dataList[i]->nStringIdx,TreePath))
						return DirTree->dataList[i];
				}
			}
		}
		else
		{
			return NULL;
		}
	}
	return NULL;
}
Esempio n. 8
0
int main(int argc,char** argv)
{
	int case_no=0;
	char data[MAXLEN];
	char* stop_tag="STOP";
	while(gets(data))
	{
		if(m_strcmp(data,stop_tag))
		{
			break;
		}
		printf("#%d: %s\n",++case_no,(is_palindrome(data)?"YES":"NO"));
		clear_str(data,MAXLEN);
	}
	return 0;
}
Esempio n. 9
0
static void parse_methods(const char *p)
{
	const compress_t *c;

	for (;;)
	{
		if (p == NULL || p[0] == 0)
			usage(argv0,-1,1);
		else if ((c = find_method(p)) != NULL)
			add_method(c->id);
		else if (m_strcmp(p,"all") == 0 || m_strcmp(p,"avail") == 0)
			add_all_methods(1,M_LAST_COMPRESSOR);
		else if (m_strcmp(p,"ALL") == 0)
		{
			add_all_methods(1,M_LAST_COMPRESSOR);
			add_all_methods(9721,9729);
			add_all_methods(9781,9789);
		}
		else if (m_strcmp(p,"lzo") == 0)
			add_all_methods(1,M_MEMCPY);
		else if (m_strcmp(p,"bench") == 0)
			add_methods(benchmark_methods);
		else if (m_strcmp(p,"m1") == 0)
			add_methods(x1_methods);
		else if (m_strcmp(p,"m99") == 0)
			add_methods(x99_methods);
		else if (m_strcmp(p,"m999") == 0)
			add_methods(x999_methods);
		else if (m_strcmp(p,"1x999") == 0)
			add_all_methods(9721,9729);
		else if (m_strcmp(p,"1y999") == 0)
			add_all_methods(9821,9829);
#if defined(ALG_ZLIB)
		else if (m_strcmp(p,"zlib") == 0)
			add_all_methods(M_ZLIB_8_1,M_ZLIB_8_9);
#endif
#if defined(MFX)
#  include "maint/t_opt_m.ch"
#endif
		else if (m_strisdigit(p))
			add_method(atoi(p));
		else
		{
			printf("%s: invalid method '%s'\n\n",argv0,p);
			exit(EXIT_USAGE);
		}

		while (*p && *p != ',')
			p++;
		while (*p == ',')
			p++;
		if (*p == 0)
			return;
	}
}
Esempio n. 10
0
int   istype(t_module *objet, char *type_name)
{
  return (m_strcmp(type(objet), type_name) == 0 ? true : false);
}
Esempio n. 11
0
bool operator<(const String & str1, const String & str2)
{
	return m_strcmp(str1.str, str2.str) == RET_VALUES::LESS;
}