i社区用户: 密码:
搜索:
首页| 资讯| 信息化| 产品| 专题| 创业| 技术天地| 企业中心| 企业论坛| 职场| 周报全文| 商城| 市场
会展| Blog| i社区| 社区联盟| RSS| 电子杂志| 发行| 直播| IT两会| i| 下载| 上网导航| CIO俱乐部

PRG文件的结构检测及格式编排



李志伟 河南省军区司令部自动化站(450003)
UPPER()将程序行非引号(包括单引号、双引号)内的字母转换为大写,因
为引号内的字母或字符串常作为查询、判断条件用,所以不应进行大小写转换;
OUTFILE()将程序行根据格式编排并输出到临时文件中。
考虑到PRG程序中TEXT…ENDT之间的内容多为菜单或说明等,所以不应剔
除前导空格和进行大小写转换,以免影响屏幕格式。
程序中还扩充了通配符文件查询功能,一次可处理一批PRG文件,并且充分考虑了
PRG文件的结构特点,使输出文件结构整齐美观,便于读写和查错。*****
/*Foxcheck.c*/
#include<dos.h>
#include<stdio.h>
#include<string.h>
#include<dir.h>
#define LINELEN 256
#define STACK 1000
char *(ltrim(char*);
char *substr(char*s,int nl,int n2);
int at(char*sl,char *s2);
int push(int tag,int line),pop(void);
void outfile(int,char*);
char*upper(char *);
int bz[STACK],hh[STACK],sp=0;
FILE *fp3;
main(int argc,char*argv[])

char in[80],out[4],s[LINELEN];
int tag=0,line=0,k=0,i;
int gs;
char lbz;
char ubz;
struct ffblk prg;
char *n=“>null”;
char *del=“del cxbp txt>null”;
char *name=:“cxbp txt”;
char copy[30];
int done;
FILE *fpl;*fp2;
if(argc<2||arg>3){
printf(USAGE:FoxcheckIPRG-FILE
I-P[p].\n);
exit(1);

strcpy(out,“con”);
for(i=1;i<argc;i++){
if(!stricmp(argv[i],“-p”))
} strcpy(out,“prn”);
strcpy(in,argv[1]);
if(!strstr(strlwr(in),“prg”))
strcat(in.“prg”);
done=findfirst(in,&prg,0);
if(done){
printf(“File &s not
found”,in);
exit(1):

while(|done) {
if((fpl=fopen(prg.ff-name,
“r”))==NULL){
printf(“Cannot open file:%s.
\n”,prg.ff-name);
exit(1);

if((fp2=fopen(out,“w”))==NULL){
printf(“cannot open
device :%s\n”,out);
exit(1);

fprintf(fp2,“正在检测文件%s…
\n”,prg.ff-name);
if((fp3=fopen(name,“w))==NULL){
printf(“cannot open file
:%s\n”,name);
exit(1);

gs=0;
lbz=0;
ubz=0;
while(fgets(s,LINELEN,fpl)){
line++;
if(!ubz)
upper(s);
if(at(“TEXT”,s)==1||at
(“ENDT”,S)==1)
{lbz=!lbz;ubz=!ubz;}
if(!lbz)
ltrim(s);
if(at(“CASE”,s)==1||at(“OTHE”,
s)==1||at(“ELSE”,s)==1||at(
ENDD”,s)==1||at(“ENDI”,s)==1)
outfile(gs-4,s);
else if(at(“ENDC”,s)==1)
outfile(gs-8,s);
else
outfile(gs,s);
if(at(“IF”,s)==1)
{tag=10;gs+=4;}
else if(at(“ENDI”,s)==1)
{tag=11;gs-=4;}
else if(at(“DO”,s)==!&&at(“CASE”
ltrim(substr(s,3,0)))==1
{tag=20;gs+=8;}
else if(at(“ENDC”,s)==1
{tag=21;gs-=8;}
else if (at(“DO”,s)==1 && at
(“WH!L”.ltrim(substr(s,3,o)))
{tag=30;gs+g4;}
else if(at(“ENDD”,s)==1)
{tag=31;gs-=4;}
else if(at(“TEXT”,s)==1)
tag=40;
else if(at(“ENDT”,s)==1)
tag=41;
else tag=0;
if(tag){
if(tag-bz[sp]==1)pop();
else push(tag,line);
  }
}/*endwhile*/
if(sp){
printf(“程序中不匹配的行如下:
\007\n);
rewind(fpl);
line=0;k=1;
while(fgets(s,LINELEN,fpl)
&& k<=sp){
line++;
if(line==hh[k]){
fprintf(fp2,
‘%-3d:%s’,line,s);
k++;



else fprintf(fp2,“没有发现语法错误,文件检测编排完成,
\n”);
fputc(0xla,fp3);
fclose(fpl);fclose(fp2);fclose(fp3);
strcpy(copy,“copy”);
copy[5]=’\0’;
strcat(copy,cxbp.txt);
strcat(copy,prg.ff-name);
strcat(copy,n);
strcat(copy,’\0’);
system(copy);
if(kbhit())exit(2);
done=findnext(&prg);

system(del);

int push(int tag,int line)

if(sp<STACK-1)}
sp++;
bz[sp]=tag;
hh[sp]=line;

return(sp);

int pop(void)

if(sp>0)sp--;
return(sp);

char *ltrim(char *s)
{ char *p=s;
while(*p==’’||*p==’\t’)
p++;
strcpy(s,p);
return(s);

int at(char *sl, char *s2)

int n1,n2;
nl=strlen(s2);
n2=strlen(strstr(s2,sl)
);
return(n2==0?0:nl-n2+1)

}    
char *substr(char *s,int nl,int n2)

int len=strlen(s );
static char ss[LINELEN]

if(nl>len)return(NULL);
if(n2>len-nl+1||n2==0)
n2=len-nl+1;
strncpy(ss,&s[nl-1],n2)

ss[n2]=’\0’;
return(ss);

void outfile(int gs,char *s)

int len=strlen(s);
static char ss[LINEEN];
if(nl>len)return(NULL);
if(n2>len-nl+1||n2==0)
n2=len-nl+1;
strncpy(ss,&s[nl-1],n2)

ss[n2]=’\0’;
rturn(ss);

void outfile (int gs,char *s)

int i;
for(i=1;i<=gs;++i)
fputc(0x20,fp3)

fputs(s,fp3) }
char *upper(char *s)

int i;
char ss[LINELEN];
char bz=0;
int len;
len=strlen(s);
for(i=0;i<len;i++)

if((s[i]==’\’’)||(s[i]==’
\’’))
bz=!bz;
if(bz==0)
ss[i]=toupper(s[
i]);       else                       
     
ss[i]=s[i];

ss[i]=’\0’ strcpy(s,ss);
return(s);
*****

(计算机世界报 1994年 第5期)



周报全文频道联系方式:010-68130909
【关于我们】  【广告服务】  【周报发行】  【投稿指南】  【投稿声明】  【联系方式】  【法律声明】
  【媒体手册】  【编读往来】  
Copyright© ccw.com.cn,All rights reserved
中国计算机世界出版服务公司版权所有