📄 wordm1.c
字号:
/*
* This WordM1.c is the most important part of the program, when call it, she will
* Find out and store the characters of a library in a buffer. And by FindWords()
* to deliver the information in proper buffers. RangeTest() use to collect the
* test to keep them continous.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "WordM1.h"
#include "FAL.h"
LEVEL Lev4,Lev6,LevM;
unsigned char *pTotalBuf;
unsigned char *pWordBuf[MAXWORDNUM];
unsigned char *pExpBuf[MAXWORDNUM];
unsigned char *pTestBuf[MAXWORDNUM];
unsigned char *pAnswerBuf[MAXWORDNUM];
unsigned int *pWordEntry;
unsigned int *pListEntry;
unsigned char *pTestModify[MAXWORDNUM] ;
unsigned char *pAnswerModify[MAXWORDNUM];
static void WordBuf(int lev)
{
//Var Def
#ifdef SIM_ON_PC
FILE *fp;
#else
FAL_FILE fp;
DSTAT statobj;
#endif
int i,j = 0;
int FirstChgLine = 0;
int filelength;
unsigned int end_of_file = 0;
Lev4.index = 0, Lev4.count = 0;
Lev6.index = 0, Lev6.count = 0;
LevM.index = 0, LevM.count = 0;
switch(lev)
{
case 4:
#ifdef SIM_ON_PC
fp = fopen("d:\\CVS\\ASIXOSAPP\\app\\WordMem\\4jy.txt","rb");
fseek(fp, 0, SEEK_END);
filelength = ftell(fp);
if( (pTotalBuf = ( char *)calloc(filelength,sizeof(char))) == NULL )
{
printf("Allocation erro");
exit(1);
}
fseek(fp, 0, SEEK_SET);
fread( pTotalBuf, 1, filelength, fp );
#else
fp = FAL_Open("b:\\4jy.txt", PO_RDWR|PO_CREAT, FAL_IWRITE|FAL_IREAD);
NU_Get_First(&statobj, "b:\\4jy.txt");
filelength = statobj.fsize;
if( (pTotalBuf = ( char *)SysLmalloc(filelength)) == NULL )
{
printf("Allocation erro");
exit(1);
}
FAL_Fread(pTotalBuf, filelength, fp);
#endif
for(i = 0;i < filelength; i++)
{
if(*(pTotalBuf + i) == 35) //'#'
{
Lev4.count++; //count the NUM of word
}
}
#ifdef SIM_ON_PC
if((pWordEntry = (int *)calloc(Lev4.count,sizeof(int)))== NULL)
{
printf("Allocation erro");
exit(1);
}
#else
if((pWordEntry = (int *)SysLmalloc(Lev4.count*4) )== NULL)
{
printf("Allocation erro");
exit(1);
}
#endif
for( i = 0 ; i < filelength; i++)
{
if( *(pTotalBuf + i) == 35 )
{
*(pWordEntry+j) = i;
j++;
}
}
break;
case 6:
#ifdef SIM_ON_PC
fp = fopen("d:\\CVS\\ASIXOSAPP\\app\\WordMem\\6jy.txt","rb");
fseek(fp, 0, SEEK_END);
filelength = ftell(fp);
if( (pTotalBuf = ( char *)calloc(filelength,sizeof(char))) == NULL )
{
printf("Allocation erro");
exit(1);
}
fseek(fp, 0, SEEK_SET);
fread( pTotalBuf, 1, filelength, fp );
#else
fp = FAL_Open("b:\\6jy.txt", PO_RDWR|PO_CREAT, FAL_IWRITE|FAL_IREAD);
NU_Get_First(&statobj, "b:\\6jy.txt");
filelength = statobj.fsize;
if( (pTotalBuf = ( char *)SysLmalloc(filelength)) == NULL )
{
printf("Allocation erro");
exit(1);
}
FAL_Fread(pTotalBuf, filelength, fp);
#endif
for(i = 0;i < filelength; i++)
{
if(*(pTotalBuf + i) == 35)
{
Lev6.count++;
}
}
#ifdef SIM_ON_PC
if((pWordEntry = (int *)SysLmalloc(Lev6.count,sizeof(int)) )== NULL)
{
printf("Allocation erro");
exit(1);
}
#else
if((pWordEntry = (int *)SysLmalloc(Lev6.count*4)) == NULL)
{
printf("Allocation erro");
exit(1);
}
#endif
for( i = 0 ; i < filelength; i++)
{
if( *(pTotalBuf + i) == 35 )
{
*(pWordEntry+j) = i;
j++;
}
}
break;
case 10:
#ifdef SIM_ON_PC
fp = fopen("d:\\CVS\\ASIXOSAPP\\app\\WordMem\\master.txt","r");
fseek(fp, 0, SEEK_END);
filelength = ftell(fp);
if( (pTotalBuf = ( char *)calloc(filelength,sizeof(char))) == NULL )
{
printf("Allocation erro");
exit(1);
}
fseek(fp, 0, SEEK_SET);
fread( pTotalBuf, 1, filelength, fp );
#else
fp = FAL_Open("b:\\master.txt", PO_RDWR|PO_CREAT, FAL_IWRITE|FAL_IREAD);
NU_Get_First(&statobj, "b:\\master.txt");
filelength = statobj.fsize;
if( (pTotalBuf = ( char *)SysLmalloc(filelength)) == NULL )
{
printf("Allocation erro");
exit(1);
}
FAL_Fread(pTotalBuf, filelength, fp);
#endif
for(i = 0;i < filelength; i++)
{
if(*(pTotalBuf + i) == 35)
{
LevM.count++;
}
}
#ifdef SIM_ON_PC
if((pWordEntry = (int *)calloc(LevM.count,sizeof(int))) == NULL)
{
printf("Allocation erro");
exit(1);
}
#else
if((pWordEntry = (int *)SysLmalloc(LevM.count*4)) == NULL)
{
printf("Allocation erro");
exit(1);
}
#endif
for( i = 0 ; i < filelength; i++)
{
if( *(pTotalBuf + i) == 35 )
{
*(pWordEntry+j) = i;
j++;
}
}
break;
default:
break;
}
#ifdef SIM_ON_PC
fclose(fp);
#else
FAL_Fclose(fp, 0);
#endif
}
static void WordIndexInList(int lev)
{
int i;
Lev4.Lindex = 0, Lev6.Lindex = 0, LevM.Lindex = 0 ;
switch(lev)
{
case 4:
for(i = 0;i < Lev4.count;i += 40)
Lev4.Lindex++;
break;
case 6:
for(i = 0;i < Lev6.count;i += 40)
Lev6.Lindex++;
break;
case 10:
for(i = 0;i < LevM.count;i += 40)
LevM.Lindex++;
break;
default:
break;
}
}
int FindWord( int lev,int list) //return the num of words in a list
{
//var
int i,j,counter1,counter2,counter3,counter4;
int m = 0,n = 0,p = 0,q = 0;
int WordEntry;
int NextWordEntry;
int ExpEntry;
int TestEntry;
int AnswerEntry;
FAL_FILE fp;
DSTAT statobj;
int WordCounter = 0;
unsigned filelength = 0;
memset(pWordBuf,0,MAXWORDNUM*MAXWORDLEN);
switch(lev)
{
case 4:
NU_Get_First(&statobj, "b:\\4jy.txt");
filelength = statobj.fsize;
for(i = 0 ; i < 40 ; i ++ )
{
WordEntry = *(pWordEntry+40*(list - 1) + i);
NextWordEntry = *(pWordEntry+40*(list - 1) + i + 1);
if(NextWordEntry < filelength)
;
else
NextWordEntry = WordEntry;
WordEntry++; /* ignore the '#' */
if((40*(list-1)+ i) < Lev4.count)
{
for( j = WordEntry; (*(pTotalBuf + j) != 0xa); j++); //find the change line dot
if(j > WordEntry)
counter1 = j - WordEntry;
else
counter1 = 1;
#ifdef SIM_ON_PC
if((pWordBuf[i] = (char *)calloc(counter1,sizeof(char)))== NULL)
{
printf("In line 276 Allocation erro");
exit(1);
} /*add allocation check by xx 10/11/2004*/
#else
if((pWordBuf[i] = (char *)SysLmalloc(counter1))== NULL)
{
printf("In line 282 Allocation erro");
exit(1);
}
#endif
for(m = 0; WordEntry < j - 1; WordEntry++)
{
*((pWordBuf[i])+m) = *(pTotalBuf + WordEntry);
m++;
}
*( (pWordBuf[i])+m ) = '\0';
ExpEntry = j;
//find exp
for(;(*(pTotalBuf + j) != 36)&&(j < NextWordEntry); j++);
if(j > ExpEntry)
counter2 = j - ExpEntry;
else
counter2 = 1;
#ifdef SIM_ON_PC
if((pExpBuf[i] = (char *)calloc(counter2,sizeof(char))) == NULL)
{
printf("In line 301 Allocation erro");
exit(1);
} /*add allocation check by xx 10/11/2004*/
#else
if((pExpBuf[i] = (char *)SysLmalloc(counter2)) == NULL)
{
printf("In line 307 Allocation erro");
exit(1);
}
#endif
for(n = 0; ExpEntry < j - 1; ExpEntry++)
{
*( (pExpBuf[i])+n ) = *(pTotalBuf + ExpEntry);
n++;
}
*( (pExpBuf[i])+n ) = '\0';
//find out test
TestEntry = j + 1;
for(;(*(pTotalBuf + j)) != 37&&(j < NextWordEntry); j++);
if(j > TestEntry)
counter3 = j - TestEntry;
else
counter3 = 1;
#ifdef SIM_ON_PC
if((pTestBuf[i] = (char *)calloc(counter3,sizeof(char))) == NULL)
{
printf("In line 330 Allocation erro");
exit(1);
} /*add allocation check by xx 10/11/2004*/
#else
if((pTestBuf[i] = (char *)SysLmalloc(counter3)) == NULL)
{
printf("In line 336 Allocation erro");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -