The following is a post from jiaking on January 18, 2005 at 1:36:07:
Also give me a copy of the source code! Thank you!
So many people want the code, why isn't the original poster generous enough to put it up so that we can all learn and progress together?
This hero is right, but unfortunately you didn't look at when this post was, at that time after I posted, no one responded for a long time, I thought it was useless, and actually deleted the source program. After more than 4 months, someone wanted it.
Because I went out to study myself in the following half year and couldn't reply to everyone, now since someone wants it, I have to re-make a program to extract and display Chinese characters, attached below,
Usage instructions:
1. The program was originally compiled with tc++, and with wildargs.obj support, it can use * and? wildcards. Now it is changed to a tc2 program and can still run, but does not support wildcards;
2. This program needs the support of hzk16 under ucdos to run;
3. After processing the program to be processed, 2 files are generated: Hz.h and Hzlib.c, which are actually small Chinese character libraries embedded in the program;
4. Copy the relevant parts of the program into one program, or use the project file, etc. It has been tested to be able to compile through tc2.0.
Attached: hz2c.c extraction Chinese character program
#include "graphics.h"
#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
#include "string.h"
#define macHzNum 7000
/*Maximum number of Chinese characters that can be recorded*/
#define macMaxLineLength 256
/*Maximum length of each line in the source program*/
unsigned int HzSum=0 ;
/*Record the number of Chinese characters in the small character library array*/
FILE*fp1 ;
/*File pointer of C, CPP source program file */
FILE*fp2 ;
/*File pointer of the generated hz.h file */
FILE*fp3 ;
/*File pointer of the generated hzlib.c file */
FILE*fHz ;
/*File pointer of UCDOS 16-dot Chinese character library HZK16 */
unsigned char Chinese;
/*Record the internal code of a Chinese character*/
char HeadFile="hz.h" ;
/*File name of the generated.H file*/
char CFile="hzlib.c" ;
/*File name of the generated.C file*/
unsigned int HugeBegin=1800 ;
/*Minimum number of Chinese characters for using Huge compilation mode*/
unsigned char IsHuge=0 ;
/*Flag whether to need Compact, Large, Huge variation mode*/
struct strHz
{
unsigned char QuHao ;
/*Area number of Chinese character*/
unsigned char WeiHao ;
/*Bit number of Chinese character*/
unsigned int RecNum ;
/*Record number of Chinese character in HZK16 file*/
unsigned char Chinese;
/*Record the internal code of Chinese character*/
}
;
/*This structure records the area number, bit number, record number in the character library and internal code of a Chinese character*/
struct strHz lay;
/*Array storing structures*/
/*This function finds whether this Chinese character has been extracted into the small character library array according to the area number and bit number of the input Chinese character. If not,*/
/*Then add it to the small character library array. The return value is the record number of the Chinese character in HZK16*/
int map(unsigned char QuHao,unsigned char WeiHao)
{
int i ;
unsigned int RecNumTemp ;
RecNumTemp=(QuHao-1)*94+(WeiHao-1);
/*Get the record number in HZK16*/
for(i=0;i<HzSum;i++)
{
if(lay.RecNum==RecNumTemp)
return lay.RecNum ;
/*This Chinese character already exists in the small character library*/
}
/*This Chinese character does not exist in the small character library array*/
lay.QuHao=QuHao ;
lay.WeiHao=WeiHao ;
lay.RecNum=(lay.QuHao-1)*94+(lay.WeiHao-1);
memcpy(lay.Chinese,Chinese,sizeof(Chinese));
/*Record the internal code of Chinese character*/
HzSum++;
return RecNumTemp ;
}
/*This function is responsible for extracting the Chinese characters used in the string in the C, CPP source program*/
void IndexHzStr(char*str)
{
unsigned char QuHao,WeiHao ;
unsigned char ch ;
int page,length ;
int MyLibRec ;
static unsigned char InString=0 ;
/*Flag to judge whether in the string*/
unsigned char HalfChinese=0 ;
/*Flag to judge whether it is a half Chinese character internal code*/
while((ch=*str++)!='\0'

{
/*Use "as the flag to enter and exit the string*/
if(ch=='\"'

InString=!InString ;
if(InString)
{
/*It's a Chinese character*/
if(ch>=0xa1)
{
if(HalfChinese==0)
{
QuHao=(ch-160);
HalfChinese=1 ;
Chinese=ch ;
continue ;
}
else
{
WeiHao=(ch-160);
HalfChinese=0 ;
Chinese=ch ;
map(QuHao,WeiHao);
}
}
}
}
}
/*This function generates the.H file according to the counted small character library array and sorts it.*/
/*When generating the.H file, the Chinese characters in the Chinese character dot matrix array generated are sorted according to the record number of the Chinese character in HZK16. In this way, when outputting Chinese characters*/
/*Using binary search to find the Chinese character array can greatly improve the speed of outputting Chinese characters*/
void WriteToH(void)
{
int i,j,k ;
int Min ;
long offset ;
unsigned char HzDotBuffer;
char HeadFileStr1=
{
"#if !defined(__HZ_H)",
"#define __HZ_H\n",
"#include \"graphics.h\"\n",
"/* Structure of Chinese character dot matrix data */",
"struct HzLib\n{",
" unsigned int RecNum; /* Record number of Chinese character in HZK16 */",
" unsigned char DotBuffer; /* Record dot matrix data of Chinese character */\n};\n",
"/* Array of Chinese character dot matrix data structure */",
}
;
/*Data in.H header file*/
char HeadFileStr2=
{
"/* Number of Chinese characters in Chinese character library array */\n",
}
;
/*Data in.H header file*/
char CFileStr1=
{
"/* This C file contains all used Chinese character dot matrix data */\n",
}
;
/*Data in.C file*/
char HFuncStr=
{
"/*The following are the definitions of function prototypes*/",
"/*Use the method of binary search to find the Chinese character in the Chinese character dot matrix data array*/",
"/*And return the dot matrix data of the Chinese character. If not found, alarm and error.*/",
"/*Return 1, find successfully; return 0, find failed*/",
"int GetHzDot(unsigned int RecNum,unsigned char *HzDotBuf);\n",
"/* Output strings containing Chinese and English according to the Chinese character dot matrix data array */",
"void hzprintf(int x,int y,int maxx,int maxy,",
" int dx,int dy,int Color,char *str);",
"/* x,y represent the starting position of outputting Chinese characters; maxx, maxy represent the left boundary of outputting Chinese characters */",
"/* and right boundary; dx, dy represent the character spacing and line spacing when outputting Chinese characters; Color represents output */",
"/* color of Chinese characters; str is the output string array, which can be mixed with Chinese and English */\n",
"#endif",
}
;
/*Definition of function prototype*/
for(i=0;i<8;i++)
fprintf(fp2,"%s\n",HeadFileStr1);
for(i=0;i<1;i++)
fprintf(fp3,"%s\n",CFileStr1);
fprintf(fp3,"#include \"%s\"\n\n",HeadFile);
/*When the number of used Chinese characters exceeds 1800, the total data may exceed 64K,*/
/*Therefore, use the Huge modifier.*/
if(HzSum>=HugeBegin)
{
fprintf(fp2,"extern struct HzLib huge ArrayOfHzLib;\n",HzSum);
IsHuge=1 ;
/*Need special three compilation modes*/
}
else
fprintf(fp2,"extern struct HzLib ArrayOfHzLib;\n",HzSum);
fprintf(fp3,"%s","/* Array of Chinese character dot matrix data structure */\n"

;
if(HzSum>=HugeBegin)
{
fprintf(fp3,"struct HzLib huge ArrayOfHzLib=\n{\n",HzSum);
IsHuge=1 ;
/*Need special three compilation modes*/
}
else
fprintf(fp3,"struct HzLib ArrayOfHzLib=\n{\n",HzSum);
for(i=0;i<HzSum;i++)
{
/*Sort and output the Chinese character dot matrix array to the.C file*/
Min=i ;
for(j=i+1;j<HzSum;j++)
{
if(lay.RecNum<lay.RecNum)
Min=j ;
if(Min!=i)
{
struct strHz strTemp ;
int Size=sizeof(strTemp);
memcpy(&strTemp,&lay,Size);
memcpy(&lay,&lay,Size);
memcpy(&lay,&strTemp,Size);
}
}
/*Write the Chinese character dot matrix array into the.H header file in order of increasing record number of Chinese characters*/
offset=(long)(lay.RecNum)*32L ;
fseek(fHz,offset,SEEK_SET);
fread(HzDotBuffer,32,1,fHz);
fprintf(fp3," {\n %d, /*- %c%c -*/\n ",
lay.RecNum,lay.Chinese,lay.Chinese);
for(k=0;k<16;k++)
{
fprintf(fp3,"%#4X,",HzDotBuffer);
}
fprintf(fp3,"\n "

;
for(k=16;k<32;k++)
{
fprintf(fp3,"%#4X,",HzDotBuffer);
}
fprintf(fp3,"\n },\n"

;
if((i%40)==0)putch('.'

;
}
fprintf(fp2,"\nextern unsigned int HzSum; "

;
for(i=0;i<1;i++)
fprintf(fp2,"%s\n",HeadFileStr2);
fprintf(fp3,"};\n\nunsigned int HzSum=%u;",HzSum);
fprintf(fp3,"%s"," /* Number of Chinese characters in Chinese character library array */\n"

;
for(i=0;i<12;i++)
fprintf(fp2,"%s\n",HFuncStr);
}
void main(int argc,char*argv)
{
int i ;
char str;
unsigned char ch ;
int ArgcNum=1 ;
unsigned char FirstLine ;
/* Judge whether it is the first line of the C program */
if(argc<2)
{
puts("\nUsage: hz2c filename"

;
exit(1);
}
for(i=0;i<macHzNum;i++)
{
lay.QuHao=-1 ;
lay.WeiHao=-1 ;
lay.RecNum=-1 ;
}
;
/*Initialize record array*/
printf("\n\nCompile Chinese characters in C or CPP source to .H .C file for C,CPP\n"

;
fp2=fopen(HeadFile,"wb"

;
if(fp2==NULL)
{
printf("Error open %s file to creat!\n",HeadFile);
exit(1);
}
fp3=fopen(CFile,"wb"

;
if(fp3==NULL)
{
printf("Error open %s file to creat!\n",HeadFile);
exit(1);
}
fHz=fopen("hzk16","rb"

;
if(fHz==NULL)
{
puts("Error in open file hzk16 (UCDOS 3.0 3.1)\n"

;
exit(1);
}
/*Support wildcards * and?, can process a batch of C or CPP source programs at one time*/
while((ArgcNum)<argc)
{
fp1=fopen(argv,"rt"

;
if(fp1==NULL)
{
puts("Error open .C or .CPP source file to read!\n"

;
exit(1);
}
FirstLine=1 ;
/* Just opened the file, it's the first line */
printf("\nNow Compile %s --> %s , %s\n",
argv,HeadFile,CFile);
printf("Compile pass one!\nCompile"

;
i=0 ;
while(!feof(fp1))
{
fgets(str,macMaxLineLength-1,fp1);
if(FirstLine)
{
if(strstr(str,HeadFile)==NULL)
/* There is no #include "hz.h" in the C program yet */
{
char FileTempName="temp.$$$" ;
char StrBuff;
FILE*fTemp ;
fTemp=fopen(FileTempName,"wt"

;
if(fTemp==NULL)
{
puts("Error open temp file to write!\n"

;
exit(1);
}
fprintf(fTemp,"#include \"%s\"\n\n",HeadFile);
fseek(fp1,0L,SEEK_SET);
while(!feof(fp1))
{
fgets(StrBuff,macMaxLineLength-1,fp1);
fputs(StrBuff,fTemp);
}
fclose(fp1);
fclose(fTemp);
remove(argv);
rename(FileTempName,argv);
fp1=fopen(argv,"rt"

;
if(fp1==NULL)
{
puts("Error open .C or .CPP source file to read!\n"

;
exit(1);
}
}
FirstLine=0 ;
}
IndexHzStr(str);
if((i++%20)==0)putch('.'

;
}
printf("\nCompile pass two!\nCompile"

;
WriteToH();
/*Generate.H file*/
puts("\nCompile pass three!"

;
fcloseall();
ArgcNum++;
}
printf("\nCompile ok!\t Use Chinese characters number: %d\n",HzSum);
/*Prompt to use special three compilation modes*/
if(IsHuge)
{
printf("\n\7\7\7Chinese characters data amount is more than 64K,\n"

;
printf("use Compact、Large、Huge mode to compile!!\n"

;
}
}
Attached: hzprintf.c Chinese and English display program
#include "stdio.h"
#include "conio.h"
#include "string.h"
#include "hz.h"
/*Use the method of binary search to find the Chinese character in the Chinese character dot matrix data array*/
/*And return the dot matrix data of the Chinese character. If not found, alarm and error.*/
/*Return 1, find successfully; return 0, find failed*/
int GetHzDot(unsigned int RecNum,unsigned char*HzDotBuf)
{
unsigned int Low,High,Mid ;
Low=0 ;
High=HzSum ;
/*Binary search method to find dot matrix data of Chinese character*/
while(Low<=High)
{
Mid=(Low+High)/2 ;
if(RecNum>ArrayOfHzLib.RecNum)
Low=Mid+1 ;
if(RecNum<ArrayOfHzLib.RecNum)
High=Mid-1 ;
if(RecNum==ArrayOfHzLib.RecNum)
{
memcpy(HzDotBuf,ArrayOfHzLib.DotBuffer,32);
return 1 ;
/*Found Chinese character*/
}
}
/*Processing for failed search*/
printf("\7\7\7\nNot find Chinese characters,please recompile your source!\n"

;
getch();
return 0 ;
}
/* Output strings containing Chinese and English according to the Chinese character dot matrix data array */
void hzprintf(int x,int y,int maxx,int maxy,
int dx,int dy,int Color,char*str)
/* x,y represent the starting position of outputting Chinese characters; maxx, maxy represent the left boundary of outputting Chinese characters */
/* and right boundary; dx, dy represent the character spacing and line spacing when outputting Chinese characters; Color represents output */
/* color of Chinese characters; str is the output string array, which can be mixed with Chinese and English */
{
unsigned char ch ;
unsigned char HalfChinese=0 ;
int QuHao,WeiHao ;
int x0=x ;
char Buff;
long RecNum ;
unsigned char HzDotBuf;
unsigned char i,j,k ;
while((ch=*str++)!=0)
{
/*It's a Chinese character*/
if(ch>=0xa1)
{
if(HalfChinese==0)
{
QuHao=(ch-160);
HalfChinese=1 ;
continue ;
}
else
{
unsigned int RecNum ;
WeiHao=(ch-160);
HalfChinese=0 ;
RecNum=(QuHao-1)*94+(WeiHao-1);
GetHzDot(RecNum,HzDotBuf);
/*Output Chinese character*/
setcolor(Color);
for(i=0;i<16;i++)
for(j=0;j<2;j++)
for(k=0;k<8;k++)
if((HzDotBuf)>>(7-k)&1)
putpixel(x+j*8+k,y+i,Color);
x+=16+dx ;
}
}
/*Process English letters and control characters*/
else
{
/*Output printable English letters*/
if(ch>=0x20&&ch<=0x7E)
{
setcolor(Color+1);
/*English letters output in different colors*/
sprintf(Buff,"%c",ch);
outtextxy(x,y+5,Buff);
x+=(8+dx/2);
}
else
{
switch(ch)
{
case 10 :
x=x0 ;
/*LF=\0, line feed*/
y=y+16+dy ;
if(y>(maxy-16-dy))
break ;
/*Reach the boundary, exit output*/
break ;
case 13 :
break ;
/*CR=\n, carriage return*/
case 9 :
x=x+32+2*dx ;
break ;
/*TAB=\t, tab*/
default :
break ;
}
}
}
/*Common processing part for Chinese and Western to wrap lines*/
if((x+dx*2)>=maxx)
{
x=x0 ;
y=y+16+dy ;
if(y>(maxy-16-dy))
break ;
/*Reach the boundary, exit output*/
}
}
}