home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- //#include <clib/dos_protos.h>
- //#include <pragmas/dos_pragmas.h>
-
- #define TMPFLE "tmpfilexx"
-
- void chkfile(char*,char);
- void replace(char*,char,int);
-
- char version[]="$VER: Pc2Am 1.0 (27.11.95) ©Thomas Zander";
-
- /// main
- void main(int argc,char *argv[])
- { char verander;
- int i;
- if(argc<3)
- {
- puts("Usage pc2am -[/,\\] filename/m\n");
- return;
- }
- if(*argv[1]!='-')
- {
- puts("Usage pc2am -[/,\\] filename/m\n");
- return;
- }
- verander=argv[1][1];
- for(i=2;i<argc;i++)
- chkfile(argv[i],verander);
-
- }
- ///
-
- /// chkfile
- void chkfile(char* filename,char verander)
- {
- FILE *fp,*fp2;
- int i,lengte;
- char txt,a,b,c;
- char *string,*path;
- i=strlen(TMPFLE);
- path=malloc(i+10);
- strcpy(path,filename);
- for(;i>0 && path[i]!='/' && path[i]!=':';i--);
- path[i+1]=0;
- strcat(path,TMPFLE);
- if((fp=fopen(filename,"r"))==NULL)
- {
- puts("file not found");
- return;
- }
- if((fp2=fopen(path,"w"))==NULL)
- {
- puts("can no open tempfile\n");
- fclose(fp);
- return;
- }
- txt=fgetc(fp);
- do
- {
- fputc((int)txt,fp2);
- if(txt=='T')
- {
- if((a=fgetc(fp))=='X')
- if((b=fgetc(fp))=='T')
- if((c=fgetc(fp))=='3')
- //txt3 chunk
- {
- fputs("XT3",fp2);
- for(i=0;i<183;i++)
- {
- lengte=(int)fgetc(fp);
- fputc((lengte),fp2);
- }
- string=(char*)malloc(lengte);
- string=fgets(string,lengte,fp);
- replace(string,verander,lengte);
- fputs(string,fp2);
- }
- else
- {
- if(c=='4')
- // txt4 chunk
- {
- fputs("XT4",fp2);
- for(i=0;i<205;i++)
- {
- lengte=(int)fgetc(fp);
- fputc((lengte),fp2);
- }
- string=(char*)malloc(lengte);
- string=fgets(string,lengte,fp);
- replace(string,verander,lengte);
- fputs(string,fp2);
- }
- else
- {
- // c if fout.
- // print a,b,c
- fputc(a,fp2);
- fputc(b,fp2);
- fputc(c,fp2);
- }
- }
- else
- {
- // b is fout
- // print a,b
- fputc(a,fp2);
- fputc(b,fp2);
- }
- else
- //a is fout
- fputc(a,fp2);
- }
- txt=fgetc(fp);
-
- }
- while(feof(fp)==0);
- fclose(fp);
- fclose(fp2);
- remove(filename);
- rename(path,filename);
- }
- ///
-
- /// replace
- void replace(char *string,char replace,int lengte)
- {
- int i;
- char with;
- if(replace=='/')
- with='\\';
- else
- with='/';
- for(i=0;i<lengte;i++)
- {
- if(string[i]==replace)
- string[i]=with;
- }
- }
- ///
-