China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 09:15
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » Repost: Add Path Program View 2,210 Replies 2
Original Poster Posted 2002-11-01 00:00 ·  中国 广东 佛山 三水区 电信
元老会员
★★★★
Credits 5,170
Posts 1,637
Joined 2002-10-16 00:00
23-year member
UID 8
Gender Male
From 广东佛山
Status Offline
Adding Path Program
Everyone often finds that some software modifies the AUTOEXEC.BAT file during installation, making the PATH point to its own directory. This article provides a small program that can complete this function. This program can be used directly: ADAPT path name, or the function addpath() can be used in your own installation program.
This program was compiled and passed under Turbo C 2.0 and works normally on X86 compatible machines.
Attached is the source program ADAPT.C
1 #include
2 #include
3 #include
4 #define flag1 "set path="
5 #define flag2 "path="
6 #define endchar(s) (((char *)s))
7 main(int argc,char *argv)
8 { if(argc<2)
9 {printf("Usage: ADPATH newpath\n";exit(1);}
10 addpath(argv);}
11 addpath(char *newpath)
12 {FILE *aut,*tmp;
13 char buffer;
14 char tname;
15 tmpnam(tname);
16 if((aut=fopen("c:\\autoexec.bat", "r")==NULL)
17 {printf("erro open autoexec.bat";exit(1);}
18 if((tmp=fopen(tname, "w")==NULL)
19 {printf("error create tmpfile";exit(1);}
20 while (!feof(aut))
21 {strcpy(buffer,"";
22 fgets(buffer, 256, aut);
23 if((strnicmp(buffer, flag1, strlen(flag1))==0) ||(strnicmp(buffer, flag2, strlen(flag2)))==0)
24 {if(endchar(buffer)=='\n' endchar(buffer) ='\0';
25 strcat(buffer, (endchar(buffer)==';' ? "" : ";");
26 strcat(strcat(buffer, newpath), "\n";
27 }fputs(buffer,tmp);
28 }fclose(aut);
29 fclose(tmp);
30 remove("c:\\autoexec.bat";
31 rename(tname,"autoexec.new";
32 system("copy autoexec.new c:\\autoexec.bat";
33 remove("autoexec.new";
34 }
□Shandong Xu Zhenhua
我的网志
http://hzmys.blog.163.com/
我的网盘
firststep.qjwm.com
fsmys.ys168.com
ssmys.ys168.com
www.brsbox.com/fsmys
www.brsbox.com/ssmys
www.brsbox.com/ccdos
Floor 2 Posted 2002-11-03 00:00 ·  中国 河北 唐山 教育网
中级用户
★★
Credits 373
Posts 69
Joined 2002-10-16 00:00
23-year member
UID 7
Gender Male
Status Offline
Nice
Floor 3 Posted 2002-11-03 00:00 ·  中国 广东 东莞 电信
元老会员
★★★
CEO
Credits 1,019
Posts 300
Joined 2002-10-20 00:00
23-year member
UID 33
Gender Male
From 广东
Status Offline
This program is not as natural as directly using batch processing : )
禅宗——大道至简,知易行难!
网站: http://www.dgzens.com

QQ: 11951692 微信: dgzens
E-MAIL: warmrose@21cn.com
Forum Jump: