如何快速、有效地在PROTEL电路原理图中增添汉字
笔者根据PROTEL中元件的存贮 格式,用TURBO C编写了一个程序,可 以将一定数量的全角字符转换成PROTEL的存贮格式,然后以“BLOCK”的形 式,读入原理图中去,程序清单见后。
用户只要事先将要转换的汉字(最 多达2304个)存到一个文本文件中,然后 运行该程序, 就可以转换得到可读入 PROTEL原理图中的文件,更为方便的 是,每一个汉字在原理图中均可以作为 一个独立的元件来进行各种操作。
本程序在编写时,借鉴了南京大学信息物理系93 研究生陶建华同志的思路,在此向他表示感谢!
#include<stdio.h>
#include<io.h>
#include<fcntl.h>
char matrix[32];
unsi gned charpp[298];
FILE* fc;
void getmatrix(unsigned char str []){int qu,wei;
unsigned long int addr;
register int k,1;
qu= (str[0])- 0xa1;
wei= (str[1])- 0xa1;
addr= (long)(qu* 94+ wei);
fseek (fc, (long) addr< < 5, SEEK - SET);
fread (matrix,1,32,fc);
}
main(int argc,char* argv[]);
{
FILE* fp1,* fp2,* fp3;
char sfile[30],tfile[30],c;
unsigned char stt[2],ch,ch1;
int i,ff;
clrscr();
for (i = 0; i < 62; i + + ) printf (〃 - 〃 );
textcolor(14);printf(〃 \ n\ n〃 );
cprintf(〃 protel- Schematic Chi nese compiler〃 );
printf(〃 \ t\ tV ersion 2.0\ n\ n \ n〃 );textcolor(14);
cprintf(〃 Contributed by〃 );
textcolor(15);
cprintf(〃 Shihai Yan〃 );
textcolor(15);
printf(〃 \ t\ t\ t1993. 10. 21 \ n \ n〃 );for (i = 0; i < 62; i + + ) printf (〃 - 〃 )〃 ;
if(argc< 3)
{
textcolor(14);printf(〃 \ n\ n\ n \ n〃 );
cprintf(〃 Chinese source file name > 〃 );scanf(〃 % s〃 ,sfile);
argv[1]= sfile;
do
{
printf(〃 \ n〃 );
cprintf(〃 O utput Protel file name > 〃 );
scanf(〃 % s〃 ,tfile)
argv[2]= tfile;
c= '';
if ((fp2 = fopen (argv [2], 〃 r 〃 ))!= NULL)
{
printf (〃 \ n% s exist, overwrite (y/ n? 〃 ,tfile);
c= getch( );
putchar(c);
fclose(fp2);
printf(〃 \ n〃 );
}
}
while ((toupper (c))= = 'N');
PRINTF (〃 \ n
〃 );
}
if ((fp1 = fopen (argv[1],〃 r〃 ))
= = NULL)
{
printf(〃 \ n% scannot be open!
〃 ,argv[1]);
exit(1);
}
fp2= fopen(argv[2];〃 wb〃 );
if ((fc = fopen (〃 zk. lib 〃 , 〃 rb
〃 ))
= = NULL)
{
printf(〃 zk.lib if not found! 〃 );
exit(2);
}
if((fp3 = fopen(〃 fmt. dat〃 , 〃 rb
〃 ))
= = NULL)
{
printf(〃 fmt. dat is not found!
〃 );
exit(3);
}
fread(pp,1,298,fp3);
for(ff= 0;ff< = 175;ff+ + )
fputc(pp[ff],fp2);
ch= getc(fp1);
ch1= getc(fp1);
while(feof(fp1)= = 0)
{
while(ch< 128)
{
if(feof(fp1)! = 0)goto end1;
ch= ch1;
ch1= getc(fp1);
}
stt[0]= ch;
stt[1]= ch1;
for(ff= 176;ff< = 297;ff+ + )
fputc(pp[ff],fp2);
pp[204]= pp[204]+ 0X14;
if(pp[204]= = 0xf0)
{
pp[204]= 0x00;
pp[205]+ + ;
}
if(pp[205]= = 0x04
{
pp[205]= 0x00;
pp[206]= pp[206]+ 0x14;
}
if(pp[206]= = 0xf0)
{
pp[206]= 0x00;
pp[207]+ + ;
}
if(pp[207]= 0x04)
{
printf(〃 Source file is too long!
〃 );
exit(4);
}
getmatrix(stt);
for(ff= 0;ff< 32;ff= ff+ 2)
{
fputc(matrix[ff],fp2);
fputc(matrix[ff+ 1],fp2);
fputc(0x00,fp2);
}
for(ff= 0;ff< 6;ff+ + )
fputc(0x00,f02);
ch= getc(fp1);
ch1= getc(fp1);
}
end1:
fclose(fp1);
fclose(fp2);
fclose(fp3);
fclose(fc);
(南京 燕士海)