|
JonePeng
金牌会员
      D◎$ Fαп
积分 4562
发帖 1883
注册 2004-1-19 来自 广东广州
状态 离线
|
『楼 主』:
[推荐] BAT转COM的C语言源程序
使用 LLM 解释/回答一下
最近我发现了一个把BAT文件转成COM的C语言原代码,编译后效果不错,转换后的COM文件比BAT2COM转换的要小得多,执行效率也更快。为了尊重原作者的创作权,在此不列出源程序,请光临他的网站: http://member.netease.com/~gmounto/cpro/BAT2COM.html
Recently I discovered a C language original code that converts BAT files to COM. After compilation, the effect is good. The converted COM file is much smaller than the one converted by BAT2COM, and the execution efficiency is also faster. To respect the original author's copyright, the source program is not listed here. Please visit his website: http://member.netease.com/~gmounto/cpro/BAT2COM.html
|

----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
|
|
2004-8-23 00:00 |
|
|
Kinglion
铂金会员
       痴迷DOS者
积分 5798
发帖 1924
注册 2003-6-20 来自 金獅電腦軟體工作室
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
支持原创作品!
|

熟能生巧,巧能生精,一艺不精,终生无成,精亦求精,始有所成,臻于完美,永无止境!
金狮電腦軟體工作室愿竭诚为您服务!
QQ群:8393170(定期清理不发言者)
个人网站:http://www.520269.cn
电子邮件:doujiehui@vip.qq.com
微信公众号: doujiehui
|
|
2004-8-26 00:00 |
|
|
JonePeng
金牌会员
      D◎$ Fαп
积分 4562
发帖 1883
注册 2004-1-19 来自 广东广州
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
坛友wang6610今天提醒我 1 楼的链接已经失效,可能原链接更改或者因作者没有付费而空间被关闭。幸好我有源程序的备份,现在贴出来供大家学习和研究。
/*************************************************************/
/* 程序名称: BAT2COM.C 1.50 */
/* 作 者: 董占山 */
/* 完成日期: 1993,1995 */
/* 用 途: 将批处理文件(.bat)转换为命令文件(.COM) */
/* 编译方法: 用下列命令编译连接可以得到BAT2COM.COM: */
/* tcc -mt bat2com */
/* tlink c:\tc\lib\c0t+bat2com,bat2com,,c:\tc\lib\cs\lib /t */
/*************************************************************/
#include <stdio.h>
#include <string.h>
/* 生成命令文件的头部,包含调用2EH的机器指令 */
char bat2comhead = {
0xBB,0x00,0x10,0xB4,0x4A,0xCD,0x21,0x0E,0x1F,0x2E,
0x8B,0x0E,0x51,0x01,0xBE,0x51,0x01,0x8B,0xC6,0x50,
0x5B,0x51,0x83,0xC3,0x02,0x8B,0xF3,0x33,0xDB,0x8A,
0x1C,0x53,0x56,0x2E,0x8C,0x16,0x4D,0x01,0x2E,0x89,
0x26,0x4F,0x01,0xCD,0x2E,0x0E,0x1F,0x2E,0x8B,0x26,
0x4F,0x01,0x2E,0x8E,0x16,0x4D,0x01,0x58,0x5B,0x59,
0x03,0xC3,0x50,0x83,0xE9,0x01,0x83,0xF9,0x00,0x75,
0xCD,0xB8,0x00,0x4C,0xCD,0x21,0xC3,0x00,0x00,0x00,
0x00};
int totallength; /* 所生成文件的总长度 */
char buffer; /* 生成命令文件的缓冲区 */
/* 删除批命令中的无意义的前导空格函数 */
void removespace(str1)
char *str1;
{
unsigned int i=0;
char *str2;
str2=str1; /* str2指向str1的地址 */
if ((str1==' ') && (i==0))
{
++str1; /* str1地址加1 */
movmem(str1,str2,strlen(str1)+1); /* 删除一个前导空格 */
removespace(str2); /* 递归调用此函数 */
}
}
/* 将批命令中的"%%"改为"%"的函数 */
void removedouble(str1)
char *str1;
{
unsigned int j,i=0;
char *str2;
str2=str1; /* str2指向str1的地址 */
if ((str1=='%') && (str1=='%'))
{
--i;
for (j=0;j<i;j++) {
++str1;++str2;
}
++str1;
movmem(str1,str2,strlen(str1)+1); /* 删除一个'%'字符 */
removedouble(str2); /* 递归调用此函数 */
}
}
/* 删除批命令中的"@"符号函数 */
void removeatchar(str1)
char *str1;
{
char *str2;
str2=str1; /* str2指向str1的地址 */
if (str1=='@')
{
++str1;
movmem(str1,str2,strlen(str1)+1); /* 删除字符'@' */
}
}
/* 转换所有的批命令,并写入缓冲区 */
void transfer(flnm)
char *flnm;
{
unsigned int i, cmnum=0;
char strlen1,ch,str1,*p,*cm;
FILE *txtfl;
if ((txtfl=fopen(flnm,"r"))==NULL) {
printf("Input file is not found !");
exit(0);
}
p = buffer; /* p指向缓冲区的开始地址 */
for (i=0;i<81;++i) *p++=bat2comhead; /* 将命令文件头写入缓冲区 */
ch = 0x0d; /* 回车符 */
totallength = 83; /* 命令文件头加2个字节的总长度 */
for (i=0;i<2;i++) p++; /* p指针相前移动2个字节 */
do {
fgets(str1,256,txtfl); /* 从批文件中读一条命令 */
removespace(str1); /* 删除前导空格 */
removedouble(str1); /* 将"%%"改为"%" */
removeatchar(str1); /* 删除"@"字符 */
strlen1 = strlen(str1); /* 计算命令串长度 */
if (strlen1>2) { /* 合法命令? */
++cmnum; /* 命令数加1 */
*p++ = strlen1-1; /* 把命令长度写入缓冲区 */
++totallength; /* 命令文件总长度加1 */
for (i=0;i<strlen1-1;++i) *p++ = str1; /* 将命令串写入缓冲区 */
totallength += strlen1-1; /* 命令文件总长度加上命令串长度 */
*p++=ch; /* 写入一个回车符 */
++totallength; /* 命令文件总长度加1 */
strcpy(str1,""); /* 清除命令字符串内容 */
}
} while (!feof(txtfl)); /* 是文件尾吗 ? */
cm = &cmnum; /* 写入命令个数 */
buffer = *cm++;
buffer = *cm;
fclose(txtfl); /* 关闭文件 */
}
/* 将构造好的缓冲区内容写入命令文件 */
void writeBAT2COM(flnm)
char *flnm;
{
FILE *bfl;
unsigned int i;
char drive,dir,name,ext;
fnsplit(flnm,drive,dir,name,ext);
strcat(name,".com");
if ((bfl=fopen(name,"wb"))==NULL) { /* 建立并打开一个二进制文件 */
printf("File does not opened !");
exit(1);
}
fwrite(buffer,totallength,1,bfl); /* 写缓冲区的内容 */
/* for (i=0;i<totallength;++i) fprintf(bfl,"%c",buffer); */
/* for (i=0;i<totallength;++i) fputc(buffer,bfl); */
fclose(bfl);
}
/* 帮助函数 */
void help()
{
printf("\nSyntex : B2C Batch_filename");
exit(0);
}
/* 主函数 */
main(argc,argv)
int argc;
char *argv;
{
char flnm;
printf("\nB2C Version 1.0 Copyright (c) 1993,94 Dong Zhanshan");
switch (argc) {
case 1 : help();break;
case 2 : strcpy(flnm,argv);break;
default: help();
}
transfer(flnm);
writeBAT2COM(flnm);
}
A forum user wang6610 reminded me today that the link in post 1 has expired. It might be that the original link was changed or the space was closed because the author didn't pay. Fortunately, I have a backup of the source program, and now I'll post it for everyone to study and research.
/*************************************************************/
/* Program Name: BAT2COM.C 1.50 */
/* Author: Dong Zhanshan */
/* Completion Date: 1993,1995 */
/* Purpose: Convert batch files (.bat) to command files (.COM) */
/* Compilation Method: You can get BAT2COM.COM by compiling and linking with the following commands: */
/* tcc -mt bat2com */
/* tlink c:\tc\lib\c0t+bat2com,bat2com,,c:\tc\lib\cs\lib /t */
/*************************************************************/
#include <stdio.h>
#include <string.h>
/* Generate the header of the command file, including the machine instructions for calling 2EH */
char bat2comhead = {
0xBB,0x00,0x10,0xB4,0x4A,0xCD,0x21,0x0E,0x1F,0x2E,
0x8B,0x0E,0x51,0x01,0xBE,0x51,0x01,0x8B,0xC6,0x50,
0x5B,0x51,0x83,0xC3,0x02,0x8B,0xF3,0x33,0xDB,0x8A,
0x1C,0x53,0x56,0x2E,0x8C,0x16,0x4D,0x01,0x2E,0x89,
0x26,0x4F,0x01,0xCD,0x2E,0x0E,0x1F,0x2E,0x8B,0x26,
0x4F,0x01,0x2E,0x8E,0x16,0x4D,0x01,0x58,0x5B,0x59,
0x03,0xC3,0x50,0x83,0xE9,0x01,0x83,0xF9,0x00,0x75,
0xCD,0xB8,0x00,0x4C,0xCD,0x21,0xC3,0x00,0x00,0x00,
0x00};
int totallength; /* Total length of the generated file */
char buffer; /* Buffer for generating the command file */
/* Function to remove leading meaningless spaces in batch commands */
void removespace(str1)
char *str1;
{
unsigned int i=0;
char *str2;
str2=str1; /* str2 points to the address of str1 */
if ((str1==' ') && (i==0))
{
++str1; /* Increment the address of str1 */
movmem(str1,str2,strlen(str1)+1); /* Remove one leading space */
removespace(str2); /* Recursive call to this function */
}
}
/* Function to change "%%" to "%" in batch commands */
void removedouble(str1)
char *str1;
{
unsigned int j,i=0;
char *str2;
str2=str1; /* str2 points to the address of str1 */
if ((str1=='%') && (str1=='%'))
{
--i;
for (j=0;j<i;j++) {
++str1;++str2;
}
++str1;
movmem(str1,str2,strlen(str1)+1); /* Remove one '%' character */
removedouble(str2); /* Recursive call to this function */
}
}
/* Function to remove the "@" symbol in batch commands */
void removeatchar(str1)
char *str1;
{
char *str2;
str2=str1; /* str2 points to the address of str1 */
if (str1=='@')
{
++str1;
movmem(str1,str2,strlen(str1)+1); /* Remove the character '@' */
}
}
/* Convert all batch commands and write to the buffer */
void transfer(flnm)
char *flnm;
{
unsigned int i, cmnum=0;
char strlen1,ch,str1,*p,*cm;
FILE *txtfl;
if ((txtfl=fopen(flnm,"r"))==NULL) {
printf("Input file is not found !");
exit(0);
}
p = buffer; /* p points to the start address of the buffer */
for (i=0;i<81;++i) *p++=bat2comhead; /* Write the command file header to the buffer */
ch = 0x0d; /* Carriage return character */
totallength = 83; /* Total length of the command file header plus 2 bytes */
for (i=0;i<2;i++) p++; /* Move the p pointer forward by 2 bytes */
do {
fgets(str1,256,txtfl); /* Read a command from the batch file */
removespace(str1); /* Remove leading spaces */
removedouble(str1); /* Change "%%" to "%" */
removeatchar(str1); /* Remove the "@" character */
strlen1 = strlen(str1); /* Calculate the length of the command string */
if (strlen1>2) { /* Is it a valid command? */
++cmnum; /* Increment the command count */
*p++ = strlen1-1; /* Write the command length to the buffer */
++totallength; /* Increment the total length of the command file */
for (i=0;i<strlen1-1;++i) *p++ = str1; /* Write the command string to the buffer */
totallength += strlen1-1; /* Add the command string length to the total length of the command file */
*p++=ch; /* Write a carriage return character */
++totallength; /* Increment the total length of the command file */
strcpy(str1,""); /* Clear the command string content */
}
} while (!feof(txtfl)); /* Is it the end of the file? */
cm = &cmnum; /* Write the command count */
buffer = *cm++;
buffer = *cm;
fclose(txtfl); /* Close the file */
}
/* Write the constructed buffer content to the command file */
void writeBAT2COM(flnm)
char *flnm;
{
FILE *bfl;
unsigned int i;
char drive,dir,name,ext;
fnsplit(flnm,drive,dir,name,ext);
strcat(name,".com");
if ((bfl=fopen(name,"wb"))==NULL) { /* Create and open a binary file */
printf("File does not opened !");
exit(1);
}
fwrite(buffer,totallength,1,bfl); /* Write the content of the buffer */
/* for (i=0;i<totallength;++i) fprintf(bfl,"%c",buffer); */
/* for (i=0;i<totallength;++i) fputc(buffer,bfl); */
fclose(bfl);
}
/* Help function */
void help()
{
printf("\nSyntex : B2C Batch_filename");
exit(0);
}
/* Main function */
main(argc,argv)
int argc;
char *argv;
{
char flnm;
printf("\nB2C Version 1.0 Copyright (c) 1993,94 Dong Zhanshan");
switch (argc) {
case 1 : help();break;
case 2 : strcpy(flnm,argv);break;
default: help();
}
transfer(flnm);
writeBAT2COM(flnm);
}
|

----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
|
|
2006-5-4 21:56 |
|
|
wang6610
银牌会员
    
积分 1246
发帖 488
注册 2003-11-11
状态 离线
|
|
2006-5-5 05:46 |
|
|
chineselgs
高级用户
    论坛灌水专业户
积分 613
发帖 266
注册 2006-4-19 来自 河南省
状态 离线
|
『第 5 楼』:
晕,这个网站怎么打不开啊??
使用 LLM 解释/回答一下
|

饮马恒河畔,剑指天山西,碎叶城揽月,库叶岛赏雪,黑海之滨垂钓,贝尔加湖面张弓;中南半岛访古,东京废墟祭祖!
|
|
2006-5-6 15:24 |
|
|
272922032
禁止访问
积分 97
发帖 41
注册 2005-10-6
状态 离线
|
|
2006-5-8 07:02 |
|
|
home
初级用户
 
积分 170
发帖 27
注册 2005-2-27
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
源程序清单
/*************************************************************/
/* 程序名称: BAT2COM.C 1.50 */
/* 作 者: 董占山 */
/* 完成日期: 1993,1995 */
/* 用 途: 将批处理文件(.bat)转换为命令文件(.COM) */
/* 编译方法: 用下列命令编译连接可以得到BAT2COM.COM: */
/* tcc -mt bat2com */
/* tlink c:\tc\lib\c0t+bat2com,bat2com,,c:\tc\lib\cs\lib /t */
/*************************************************************/
#include <stdio.h>
#include <string.h>
/* 生成命令文件的头部,包含调用2EH的机器指令 */
char bat2comhead[81] = {
0xBB,0x00,0x10,0xB4,0x4A,0xCD,0x21,0x0E,0x1F,0x2E,
0x8B,0x0E,0x51,0x01,0xBE,0x51,0x01,0x8B,0xC6,0x50,
0x5B,0x51,0x83,0xC3,0x02,0x8B,0xF3,0x33,0xDB,0x8A,
0x1C,0x53,0x56,0x2E,0x8C,0x16,0x4D,0x01,0x2E,0x89,
0x26,0x4F,0x01,0xCD,0x2E,0x0E,0x1F,0x2E,0x8B,0x26,
0x4F,0x01,0x2E,0x8E,0x16,0x4D,0x01,0x58,0x5B,0x59,
0x03,0xC3,0x50,0x83,0xE9,0x01,0x83,0xF9,0x00,0x75,
0xCD,0xB8,0x00,0x4C,0xCD,0x21,0xC3,0x00,0x00,0x00,
0x00};
int totallength; /* 所生成文件的总长度 */
char buffer[10000]; /* 生成命令文件的缓冲区 */
/* 删除批命令中的无意义的前导空格函数 */
void removespace(str1)
char *str1;
{
unsigned int i=0;
char *str2;
str2=str1; /* str2指向str1的地址 */
if ((str1==' ') && (i==0))
{
++str1; /* str1地址加1 */
movmem(str1,str2,strlen(str1)+1); /* 删除一个前导空格 */
removespace(str2); /* 递归调用此函数 */
}
}
/* 将批命令中的"%%"改为"%"的函数 */
void removedouble(str1)
char *str1;
{
unsigned int j,i=0;
char *str2;
str2=str1; /* str2指向str1的地址 */
if ((str1=='%') && (str1[++i]=='%'))
{
--i;
for (j=0;j<i;j++) {
++str1;++str2;
}
++str1;
movmem(str1,str2,strlen(str1)+1); /* 删除一个'%'字符 */
removedouble(str2); /* 递归调用此函数 */
}
}
/* 删除批命令中的"@"符号函数 */
void removeatchar(str1)
char *str1;
{
char *str2;
str2=str1; /* str2指向str1的地址 */
if (str1[0]=='@')
{
++str1;
movmem(str1,str2,strlen(str1)+1); /* 删除字符'@' */
}
}
/* 转换所有的批命令,并写入缓冲区 */
void transfer(flnm)
char *flnm;
{
unsigned int i, cmnum=0;
char strlen1,ch,str1[256],*p,*cm;
FILE *txtfl;
if ((txtfl=fopen(flnm,"r"))==NULL) {
printf("Input file is not found !");
exit(0);
}
p = buffer; /* p指向缓冲区的开始地址 */
for (i=0;i<81;++i) *p++=bat2comhead; /* 将命令文件头写入缓冲区 */
ch = 0x0d; /* 回车符 */
totallength = 83; /* 命令文件头加2个字节的总长度 */
for (i=0;i<2;i++) p++; /* p指针相前移动2个字节 */
do {
fgets(str1,256,txtfl); /* 从批文件中读一条命令 */
removespace(str1); /* 删除前导空格 */
removedouble(str1); /* 将"%%"改为"%" */
removeatchar(str1); /* 删除"@"字符 */
strlen1 = strlen(str1); /* 计算命令串长度 */
if (strlen1>2) { /* 合法命令? */
++cmnum; /* 命令数加1 */
*p++ = strlen1-1; /* 把命令长度写入缓冲区 */
++totallength; /* 命令文件总长度加1 */
for (i=0;i<strlen1-1;++i) *p++ = str1; /* 将命令串写入缓冲区 */
totallength += strlen1-1; /* 命令文件总长度加上命令串长度 */
*p++=ch; /* 写入一个回车符 */
++totallength; /* 命令文件总长度加1 */
strcpy(str1,""); /* 清除命令字符串内容 */
}
} while (!feof(txtfl)); /* 是文件尾吗 ? */
cm = &cmnum; /* 写入命令个数 */
buffer[81] = *cm++;
buffer[80] = *cm;
fclose(txtfl); /* 关闭文件 */
}
/* 将构造好的缓冲区内容写入命令文件 */
void writeBAT2COM(flnm)
char *flnm;
{
FILE *bfl;
unsigned int i;
char drive[3],dir[65],name[9],ext[5];
fnsplit(flnm,drive,dir,name,ext);
strcat(name,".com");
if ((bfl=fopen(name,"wb"))==NULL) { /* 建立并打开一个二进制文件 */
printf("File does not opened !");
exit(1);
}
fwrite(buffer,totallength,1,bfl); /* 写缓冲区的内容 */
/* for (i=0;i<totallength;++i) fprintf(bfl,"%c",buffer); */
/* for (i=0;i<totallength;++i) fputc(buffer,bfl); */
fclose(bfl);
}
/* 帮助函数 */
void help()
{
printf("\nSyntex : B2C Batch_filename");
exit(0);
}
/* 主函数 */
main(argc,argv)
int argc;
char *argv[];
{
char flnm[80];
printf("\nB2C Version 1.0 Copyright (c) 1993,94 Dong Zhanshan");
switch (argc) {
case 1 : help();break;
case 2 : strcpy(flnm,argv[1]);break;
default: help();
}
transfer(flnm);
writeBAT2COM(flnm);
}
大家看看这个,是不是
Source program list
/*************************************************************/
/* Program name: BAT2COM.C 1.50 */
/* Author: Dong Zhanshan */
/* Completion date: 1993,1995 */
/* Purpose: Convert batch files (.bat) to command files (.COM) */
/* Compilation method: You can get BAT2COM.COM by compiling and linking with the following commands: */
/* tcc -mt bat2com */
/* tlink c:\tc\lib\c0t+bat2com,bat2com,,c:\tc\lib\cs\lib /t */
/*************************************************************/
#include <stdio.h>
#include <string.h>
/* Generate the header of the command file, including the machine instructions for calling 2EH */
char bat2comhead = {
0xBB,0x00,0x10,0xB4,0x4A,0xCD,0x21,0x0E,0x1F,0x2E,
0x8B,0x0E,0x51,0x01,0xBE,0x51,0x01,0x8B,0xC6,0x50,
0x5B,0x51,0x83,0xC3,0x02,0x8B,0xF3,0x33,0xDB,0x8A,
0x1C,0x53,0x56,0x2E,0x8C,0x16,0x4D,0x01,0x2E,0x89,
0x26,0x4F,0x01,0xCD,0x2E,0x0E,0x1F,0x2E,0x8B,0x26,
0x4F,0x01,0x2E,0x8E,0x16,0x4D,0x01,0x58,0x5B,0x59,
0x03,0xC3,0x50,0x83,0xE9,0x01,0x83,0xF9,0x00,0x75,
0xCD,0xB8,0x00,0x4C,0xCD,0x21,0xC3,0x00,0x00,0x00,
0x00};
int totallength; /* Total length of the generated file */
char buffer; /* Buffer for generating command file */
/* Function to remove meaningless leading spaces in batch commands */
void removespace(str1)
char *str1;
{
unsigned int i = 0;
char *str2;
str2 = str1; /* str2 points to the address of str1 */
if ((str1 == ' ') && (i == 0))
{
++str1; /* str1 address plus 1 */
movmem(str1, str2, strlen(str1) + 1); /* Remove one leading space */
removespace(str2); /* Recursive call to this function */
}
}
/* Function to replace "%%" with "%" in batch commands */
void removedouble(str1)
char *str1;
{
unsigned int j, i = 0;
char *str2;
str2 = str1; /* str2 points to the address of str1 */
if ((str1 == '%') && (str1 == '%'))
{
--i;
for (j = 0; j < i; j++) {
++str1; ++str2;
}
++str1;
movmem(str1, str2, strlen(str1) + 1); /* Remove one '%' character */
removedouble(str2); /* Recursive call to this function */
}
}
/* Function to remove "@" symbol in batch commands */
void removeatchar(str1)
char *str1;
{
char *str2;
str2 = str1; /* str2 points to the address of str1 */
if (str1 == '@')
{
++str1;
movmem(str1, str2, strlen(str1) + 1); /* Remove character '@' */
}
}
/* Convert all batch commands and write to buffer */
void transfer(flnm)
char *flnm;
{
unsigned int i, cmnum = 0;
char strlen1, ch, str1, *p, *cm;
FILE *txtfl;
if ((txtfl = fopen(flnm, "r")) == NULL) {
printf("Input file is not found !");
exit(0);
}
p = buffer; /* p points to the start address of the buffer */
for (i = 0; i < 81; ++i) *p++ = bat2comhead; /* Write command file header to buffer */
ch = 0x0d; /* Carriage return character */
totallength = 83; /* Total length of command file: header plus 2 bytes */
for (i = 0; i < 2; i++) p++; /* Move p pointer forward by 2 bytes */
do {
fgets(str1, 256, txtfl); /* Read a command from the batch file */
removespace(str1); /* Remove leading spaces */
removedouble(str1); /* Replace "%%" with "%" */
removeatchar(str1); /* Remove "@" character */
strlen1 = strlen(str1); /* Calculate command string length */
if (strlen1 > 2) { /* Is it a valid command? */
++cmnum; /* Increment command count */
*p++ = strlen1 - 1; /* Write command length to buffer */
++totallength; /* Increment total length of command file */
for (i = 0; i < strlen1 - 1; ++i) *p++ = str1; /* Write command string to buffer */
totallength += strlen1 - 1; /* Add command string length to total length of command file */
*p++ = ch; /* Write a carriage return character */
++totallength; /* Increment total length of command file */
strcpy(str1, ""); /* Clear command string content */
}
} while (!feof(txtfl)); /* Is it the end of the file? */
cm = &cmnum; /* Write command count */
buffer = *cm++;
buffer = *cm;
fclose(txtfl); /* Close file */
}
/* Write the constructed buffer content to the command file */
void writeBAT2COM(flnm)
char *flnm;
{
FILE *bfl;
unsigned int i;
char drive, dir, name, ext;
fnsplit(flnm, drive, dir, name, ext);
strcat(name, ".com");
if ((bfl = fopen(name, "wb")) == NULL) { /* Create and open a binary file */
printf("File does not opened !");
exit(1);
}
fwrite(buffer, totallength, 1, bfl); /* Write buffer content */
/* for (i=0;i<totallength;++i) fprintf(bfl,"%c",buffer); */
/* for (i=0;i<totallength;++i) fputc(buffer,bfl); */
fclose(bfl);
}
/* Help function */
void help()
{
printf("\nSyntex : B2C Batch_filename");
exit(0);
}
/* Main function */
main(argc, argv)
int argc;
char *argv;
{
char flnm;
printf("\nB2C Version 1.0 Copyright (c) 1993,94 Dong Zhanshan");
switch (argc) {
case 1 : help();break;
case 2 : strcpy(flnm, argv);break;
default: help();
}
transfer(flnm);
writeBAT2COM(flnm);
}
Everyone, take a look, is it
|
|
2006-5-22 21:35 |
|
|
qylml
新手上路

积分 10
发帖 5
注册 2006-6-13
状态 离线
|
|
2006-6-14 16:49 |
|
|
wang6610
银牌会员
    
积分 1246
发帖 488
注册 2003-11-11
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
/*************************************************************/
/* 程序名称: BAT2COM.C 1.50 */
/* 作 者: 董占山 */
/* 完成日期: 1993,1995 */
/* 用 途: 将批处理文件(.bat)转换为命令文件(.COM) */
/* 编译方法: 用下列命令编译连接可以得到BAT2COM.COM: */
/* tcc -mt bat2com */
/* tlink c:\tc\lib\c0t+bat2com,bat2com,,c:\tc\lib\cs\lib /t */
/*************************************************************/
#include <stdio.h>
#include <string.h>
/* 生成命令文件的头部,包含调用2EH的机器指令 */
char bat2comhead[81] = {
0xBB,0x00,0x10,0xB4,0x4A,0xCD,0x21,0x0E,0x1F,0x2E,
0x8B,0x0E,0x51,0x01,0xBE,0x51,0x01,0x8B,0xC6,0x50,
0x5B,0x51,0x83,0xC3,0x02,0x8B,0xF3,0x33,0xDB,0x8A,
0x1C,0x53,0x56,0x2E,0x8C,0x16,0x4D,0x01,0x2E,0x89,
0x26,0x4F,0x01,0xCD,0x2E,0x0E,0x1F,0x2E,0x8B,0x26,
0x4F,0x01,0x2E,0x8E,0x16,0x4D,0x01,0x58,0x5B,0x59,
0x03,0xC3,0x50,0x83,0xE9,0x01,0x83,0xF9,0x00,0x75,
0xCD,0xB8,0x00,0x4C,0xCD,0x21,0xC3,0x00,0x00,0x00,
0x00};
int totallength; /* 所生成文件的总长度 */
char buffer[10000]; /* 生成命令文件的缓冲区 */
/* 删除批命令中的无意义的前导空格函数 */
void removespace(str1)
char *str1;
{
unsigned int i=0;
char *str2;
str2=str1; /* str2指向str1的地址 */
if ((str1[i]==' ') && (i==0))
{
++str1; /* str1地址加1 */
movmem(str1,str2,strlen(str1)+1); /* 删除一个前导空格 */
removespace(str2); /* 递归调用此函数 */
}
}
/* 将批命令中的"%%"改为"%"的函数 */
void removedouble(str1)
char *str1;
{
unsigned int j,i=0;
char *str2;
str2=str1; /* str2指向str1的地址 */
if ((str1[i]=='%') && (str1[++i]=='%'))
{
--i;
for (j=0;j<i;j++) {
++str1;++str2;
}
++str1;
movmem(str1,str2,strlen(str1)+1); /* 删除一个'%'字符 */
removedouble(str2); /* 递归调用此函数 */
}
}
/* 删除批命令中的"@"符号函数 */
void removeatchar(str1)
char *str1;
{
char *str2;
str2=str1; /* str2指向str1的地址 */
if (str1[0]=='@')
{
++str1;
movmem(str1,str2,strlen(str1)+1); /* 删除字符'@' */
}
}
/* 转换所有的批命令,并写入缓冲区 */
void transfer(flnm)
char *flnm;
{
unsigned int i, cmnum=0;
char strlen1,ch,str1[256],*p,*cm;
FILE *txtfl;
if ((txtfl=fopen(flnm,"r"))==NULL) {
printf("Input file is not found !");
exit(0);
}
p = buffer; /* p指向缓冲区的开始地址 */
for (i=0;i<81;++i) *p++=bat2comhead[i]; /* 将命令文件头写入缓冲区 */
ch = 0x0d; /* 回车符 */
totallength = 83; /* 命令文件头加2个字节的总长度 */
for (i=0;i<2;i++) p++; /* p指针相前移动2个字节 */
do {
fgets(str1,256,txtfl); /* 从批文件中读一条命令 */
removespace(str1); /* 删除前导空格 */
removedouble(str1); /* 将"%%"改为"%" */
removeatchar(str1); /* 删除"@"字符 */
strlen1 = strlen(str1); /* 计算命令串长度 */
if (strlen1>2) { /* 合法命令? */
++cmnum; /* 命令数加1 */
*p++ = strlen1-1; /* 把命令长度写入缓冲区 */
++totallength; /* 命令文件总长度加1 */
for (i=0;i<strlen1-1;++i) *p++ = str1[i]; /* 将命令串写入缓冲区 */
totallength += strlen1-1; /* 命令文件总长度加上命令串长度 */
*p++=ch; /* 写入一个回车符 */
++totallength; /* 命令文件总长度加1 */
strcpy(str1,""); /* 清除命令字符串内容 */
}
} while (!feof(txtfl)); /* 是文件尾吗 ? */
cm = &cmnum; /* 写入命令个数 */
buffer[81] = *cm++;
buffer[80] = *cm;
fclose(txtfl); /* 关闭文件 */
}
/* 将构造好的缓冲区内容写入命令文件 */
void writeBAT2COM(flnm)
char *flnm;
{
FILE *bfl;
unsigned int i;
char drive[3],dir[65],name[9],ext[5];
fnsplit(flnm,drive,dir,name,ext);
strcat(name,".com");
if ((bfl=fopen(name,"wb"))==NULL) { /* 建立并打开一个二进制文件 */
printf("File does not opened !");
exit(1);
}
fwrite(buffer,totallength,1,bfl); /* 写缓冲区的内容 */
/* for (i=0;i<totallength;++i) fprintf(bfl,"%c",buffer[i]); */
/* for (i=0;i<totallength;++i) fputc(buffer[i],bfl); */
fclose(bfl);
}
/* 帮助函数 */
void help()
{
printf("\nSyntex : B2C Batch_filename");
exit(0);
}
/* 主函数 */
main(argc,argv)
int argc;
char *argv[];
{
char flnm[80];
printf("\nB2C Version 1.0 Copyright (c) 1993,94 Dong Zhanshan");
switch (argc) {
case 1 : help();break;
case 2 : strcpy(flnm,argv[1]);break;
default: help();
}
transfer(flnm);
writeBAT2COM(flnm);
}
/*************************************************************/
/* Program Name: BAT2COM.C 1.50 */
/* Author: Dong Zhanshan */
/* Completion Date: 1993,1995 */
/* Purpose: Convert batch files (.bat) to command files (.COM)*/
/* Compilation Method: Compile and link with the following commands to get BAT2COM.COM:*/
/* tcc -mt bat2com */
/* tlink c:\tc\lib\c0t+bat2com,bat2com,,c:\tc\lib\cs\lib /t */
/*************************************************************/
#include <stdio.h>
#include <string.h>
/* Generate the header of the command file, including machine instructions to call 2EH */
char bat2comhead = {
0xBB, 0x00, 0x10, 0xB4, 0x4A, 0xCD, 0x21, 0x0E, 0x1F, 0x2E,
0x8B, 0x0E, 0x51, 0x01, 0xBE, 0x51, 0x01, 0x8B, 0xC6, 0x50,
0x5B, 0x51, 0x83, 0xC3, 0x02, 0x8B, 0xF3, 0x33, 0xDB, 0x8A,
0x1C, 0x53, 0x56, 0x2E, 0x8C, 0x16, 0x4D, 0x01, 0x2E, 0x89,
0x26, 0x4F, 0x01, 0xCD, 0x2E, 0x0E, 0x1F, 0x2E, 0x8B, 0x26,
0x4F, 0x01, 0x2E, 0x8E, 0x16, 0x4D, 0x01, 0x58, 0x5B, 0x59,
0x03, 0xC3, 0x50, 0x83, 0xE9, 0x01, 0x83, 0xF9, 0x00, 0x75,
0xCD, 0xB8, 0x00, 0x4C, 0xCD, 0x21, 0xC3, 0x00, 0x00, 0x00,
0x00};
int totallength; /* Total length of the generated file */
char buffer; /* Buffer for generating the command file */
/* Function to remove leading spaces in batch commands */
void removespace(char *str1)
{
unsigned int i = 0;
char *str2;
str2 = str1; /* str2 points to the address of str1 */
if ((str1 == ' ') && (i == 0))
{
++str1; /* Increment the address of str1 */
movmem(str1, str2, strlen(str1) + 1); /* Remove a leading space */
removespace(str2); /* Recursively call this function */
}
}
/* Function to replace "%%" with "%" in batch commands */
void removedouble(char *str1)
{
unsigned int j, i = 0;
char *str2;
str2 = str1; /* str2 points to the address of str1 */
if ((str1 == '%') && (str1 == '%'))
{
--i;
for (j = 0; j < i; j++)
{
++str1;
++str2;
}
++str1;
movmem(str1, str2, strlen(str1) + 1); /* Remove a '%' character */
removedouble(str2); /* Recursively call this function */
}
}
/* Function to remove "@" symbols in batch commands */
void removeatchar(char *str1)
{
char *str2;
str2 = str1; /* str2 points to the address of str1 */
if (str1 == '@')
{
++str1;
movmem(str1, str2, strlen(str1) + 1); /* Remove the '@' character */
}
}
/* Convert all batch commands and write to the buffer */
void transfer(char *flnm)
{
unsigned int i, cmnum = 0;
char strlen1, ch, str1, *p, *cm;
FILE *txtfl;
if ((txtfl = fopen(flnm, "r")) == NULL)
{
printf("Input file is not found !");
exit(0);
}
p = buffer; /* p points to the start address of the buffer */
for (i = 0; i < 81; ++i)
*p++ = bat2comhead; /* Write the command file header to the buffer */
ch = 0x0d; /* Carriage return character */
totallength = 83; /* Total length of the command file header plus 2 bytes */
for (i = 0; i < 2; i++)
p++; /* Move the p pointer forward by 2 bytes */
do
{
fgets(str1, 256, txtfl); /* Read a command from the batch file */
removespace(str1); /* Remove leading spaces */
removedouble(str1); /* Replace "%%" with "%" */
removeatchar(str1); /* Remove "@" characters */
strlen1 = strlen(str1); /* Calculate the length of the command string */
if (strlen1 > 2) /* Is it a valid command? */
{
++cmnum; /* Increment the command count by 1 */
*p++ = strlen1 - 1; /* Write the command length to the buffer */
++totallength; /* Increment the total length of the command file by 1 */
for (i = 0; i < strlen1 - 1; ++i)
*p++ = str1; /* Write the command string to the buffer */
totallength += strlen1 - 1; /* Add the command string length to the total length of the command file */
*p++ = ch; /* Write a carriage return character */
++totallength; /* Increment the total length of the command file by 1 */
strcpy(str1, ""); /* Clear the content of the command string */
}
} while (!feof(txtfl)); /* Is it the end of the file? */
cm = &cmnum; /* Write the command count */
buffer = *cm++;
buffer = *cm;
fclose(txtfl); /* Close the file */
}
/* Write the constructed buffer content to the command file */
void writeBAT2COM(char *flnm)
{
FILE *bfl;
unsigned int i;
char drive, dir, name, ext;
fnsplit(flnm, drive, dir, name, ext);
strcat(name, ".com");
if ((bfl = fopen(name, "wb")) == NULL)
{ /* Create and open a binary file */
printf("File does not opened !");
exit(1);
}
fwrite(buffer, totallength, 1, bfl); /* Write the content of the buffer */
/* for (i=0;i<totallength;++i) fprintf(bfl,"%c",buffer); */
/* for (i=0;i<totallength;++i) fputc(buffer,bfl); */
fclose(bfl);
}
/* Help function */
void help()
{
printf("\nSyntex : B2C Batch_filename");
exit(0);
}
/* Main function */
main(int argc, char *argv)
{
char flnm;
printf("\nB2C Version 1.0 Copyright (c) 1993,94 Dong Zhanshan");
switch (argc)
{
case 1:
help();
break;
case 2:
strcpy(flnm, argv);
break;
default:
help();
}
transfer(flnm);
writeBAT2COM(flnm);
}
|
|
2006-8-13 15:55 |
|
|
NaturalJ0
银牌会员
    
积分 1181
发帖 533
注册 2006-8-14
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
编译失败了,请高手指点一下。非常感谢。
The compilation failed. Please ask experts for guidance. Thanks a lot.
|
|
2006-8-15 00:58 |
|
|
mornsmile
初级用户
 
积分 147
发帖 23
注册 2005-1-23
状态 离线
|
|
2006-8-16 08:11 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
精彩!!!收藏~~~
Wonderful!!! Collect~~~
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2007-2-8 07:23 |
|
|
anqing
高级用户
   
积分 859
发帖 413
注册 2006-8-14
状态 离线
|
|
2007-2-8 08:13 |
|
|
wang6610
银牌会员
    
积分 1246
发帖 488
注册 2003-11-11
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
C:\TC>tcc -mt bat2com
Turbo C Version 2.0 Copyright (c) 1987, 1988 Borland International
bat2com.c:
Error bat2com.c 11: Unable to open include file 'stdio.h'
Error bat2com.c 12: Unable to open include file 'string.h'
Error bat2com.c 82: Undefined symbol 'FILE' in function transfer
Error bat2com.c 82: Undefined symbol 'txtfl' in function transfer
Warning bat2com.c 82: Code has no effect in function transfer
Error bat2com.c 83: Undefined symbol 'NULL' in function transfer
Warning bat2com.c 109: Suspicious pointer conversion in function transfer
Error bat2com.c 119: Undefined symbol 'FILE' in function writeBAT2COM
Error bat2com.c 119: Undefined symbol 'bfl' in function writeBAT2COM
Warning bat2com.c 119: Code has no effect in function writeBAT2COM
Error bat2com.c 120: Expression syntax in function writeBAT2COM
Error bat2com.c 121: Expression syntax in function writeBAT2COM
Error bat2com.c 122: Undefined symbol 'drive' in function writeBAT2COM
Error bat2com.c 122: Undefined symbol 'dir' in function writeBAT2COM
Error bat2com.c 122: Undefined symbol 'name' in function writeBAT2COM
Error bat2com.c 122: Undefined symbol 'ext' in function writeBAT2COM
Error bat2com.c 124: Undefined symbol 'NULL' in function writeBAT2COM
*** 14 errors in Compile ***
Available memory 400928
C:\TC>tcc -mt bat2com
Turbo C Version 2.0 Copyright (c) 1987, 1988 Borland International
bat2com.c:
Error bat2com.c 11: Unable to open include file 'stdio.h'
Error bat2com.c 12: Unable to open include file 'string.h'
Error bat2com.c 82: Undefined symbol 'FILE' in function transfer
Error bat2com.c 82: Undefined symbol 'txtfl' in function transfer
Warning bat2com.c 82: Code has no effect in function transfer
Error bat2com.c 83: Undefined symbol 'NULL' in function transfer
Warning bat2com.c 109: Suspicious pointer conversion in function transfer
Error bat2com.c 119: Undefined symbol 'FILE' in function writeBAT2COM
Error bat2com.c 119: Undefined symbol 'bfl' in function writeBAT2COM
Warning bat2com.c 119: Code has no effect in function writeBAT2COM
Error bat2com.c 120: Expression syntax in function writeBAT2COM
Error bat2com.c 121: Expression syntax in function writeBAT2COM
Error bat2com.c 122: Undefined symbol 'drive' in function writeBAT2COM
Error bat2com.c 122: Undefined symbol 'dir' in function writeBAT2COM
Error bat2com.c 122: Undefined symbol 'name' in function writeBAT2COM
Error bat2com.c 122: Undefined symbol 'ext' in function writeBAT2COM
Error bat2com.c 124: Undefined symbol 'NULL' in function writeBAT2COM
*** 14 errors in Compile ***
Available memory 400928
|
|
2007-6-25 16:23 |
|
|
duanml
中级用户
  
积分 231
发帖 112
注册 2007-6-19
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
编译环境不对,stdio.h都找不到~
The compilation environment is incorrect, and stdio.h cannot be found~
|
|
2007-6-25 17:21 |
|
|