📄 bmstest.c
字号:
/****************************************************************************
*测试study_bmsearch算法
* Revision Athor Modifiction
=============================================================================
* 2006-7-15 Devil 创建
*
*
****************************************************************************/
#include "..\..\include\owner\bmsearch.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct D_DATASTR{
D_U8* data;
D_U32 size;
}D_DATASTR;
static void d_paramread(D_BM_KeyWord *keyword, D_DATASTR *filename)
{
char kw[256];
char byte = '\0';
D_U8 i = 0;
printf("Please input a key word:\n");
while(byte != '\n')
{
byte = getchar();
kw[i] = byte;
i++;
}
keyword->data = malloc(i);
memcpy(keyword->data, kw, i-1);
keyword->data[i-1] = '\0';
keyword->size = i-1;
i = 0;
byte = '\0';
printf("please intput a filename:\n");
while(byte != '\n')
{
byte = getchar();
kw[i] = byte;
i++;
}
filename->data = malloc(i);
memset(filename->data, '\0', i);
memcpy(filename->data,kw,i-1);
filename->size = i-1;
return;
}
static D_U32 d_filesize(FILE *stream)
{
long curpos, length;
curpos = ftell(stream);
fseek(stream, 0L, SEEK_END);
length = ftell(stream);
fseek(stream, curpos, SEEK_SET);
return length;
}
void main(void)
{
FILE *infile = NULL;
D_U32 size, num=0;
D_DATASTR filename;
D_BM_KeyWord keydata;
D_BM_ContentData ContentData;
#ifdef _TESTSIZE
char *p[] = {"12323","gfdsfgds","adfasfas"};
p = malloc(256);
printf("sizeof(p) is %d size \n", sizeof(p));
printf("sizeof(*p) is %d size \n", sizeof(*p));
printf("sizeof(p[1]) is %d size \n", sizeof(p[1]));
printf("sizeof(*p[1]) is %d size \n", sizeof(*p[1]));
printf("strlen(p[1]) is %d size \n", strlen(p[1]));
#endif
d_paramread(&keydata, &filename);
printf("keyword is %s, filename is %s\n",keydata.data, filename.data);
infile = fopen((char*)filename.data,"r");
if(infile == NULL)
{
printf("Open file error\n");
return;
}
size = d_filesize(infile);
ContentData.data = malloc(size+5);
memset(ContentData.data, '\0', (size+5));
fread(ContentData.data, 1, size, infile);
fclose(infile);
ContentData.size = size;
#ifdef _devil_debug_
printf("keyword.size is %d\n",keydata.size);
printf("keyword.data is %s\n",keydata.data);
printf("ContentData.size is %d\n",ContentData.size);
printf("ContentData.data is\n%s\n",ContentData.data);
#endif
if(D_OK != D_BMSearch(&keydata, &ContentData, &num))
{
printf("return bmsearch error\n");
free(ContentData.data);
free(keydata.data);
return;
}
printf("Searched [%d] Same keyword in file\n",num);
free(ContentData.data);
free(keydata.data);
getchar();
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -