home *** CD-ROM | disk | FTP | other *** search
/ X-Ray / X-Ray.iso / gfx-soft / imagine-stuff / pc2am.lha / pc2am.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-28  |  3.2 KB  |  144 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. //#include <clib/dos_protos.h>
  5. //#include <pragmas/dos_pragmas.h>
  6.  
  7. #define TMPFLE "tmpfilexx"
  8.  
  9. void chkfile(char*,char);
  10. void replace(char*,char,int);
  11.  
  12. char version[]="$VER: Pc2Am 1.0 (27.11.95) ©Thomas Zander";
  13.  
  14. /// main
  15. void main(int argc,char *argv[])
  16. {       char verander;
  17.     int i;
  18.     if(argc<3)
  19.     {
  20.         puts("Usage pc2am -[/,\\] filename/m\n");
  21.         return;
  22.     }
  23.     if(*argv[1]!='-')
  24.     {
  25.         puts("Usage pc2am -[/,\\] filename/m\n");
  26.         return;
  27.     }
  28.     verander=argv[1][1];
  29.     for(i=2;i<argc;i++)
  30.         chkfile(argv[i],verander);
  31.  
  32. }
  33. ///
  34.  
  35. /// chkfile
  36. void chkfile(char* filename,char verander)
  37. {
  38.     FILE *fp,*fp2;
  39.     int i,lengte;
  40.     char txt,a,b,c;
  41.     char *string,*path;
  42.     i=strlen(TMPFLE);
  43.     path=malloc(i+10);
  44.     strcpy(path,filename);
  45.     for(;i>0 && path[i]!='/' && path[i]!=':';i--);
  46.         path[i+1]=0;
  47.     strcat(path,TMPFLE);
  48.     if((fp=fopen(filename,"r"))==NULL)
  49.     {
  50.         puts("file not found");
  51.         return;
  52.     }
  53.     if((fp2=fopen(path,"w"))==NULL)
  54.     {
  55.         puts("can no open tempfile\n");
  56.         fclose(fp);
  57.         return;
  58.     }
  59.     txt=fgetc(fp);
  60.     do
  61.     {
  62.         fputc((int)txt,fp2);
  63.         if(txt=='T')
  64.         {
  65.             if((a=fgetc(fp))=='X')
  66.               if((b=fgetc(fp))=='T')
  67.                 if((c=fgetc(fp))=='3')
  68.                 //txt3 chunk
  69.                 {
  70.                     fputs("XT3",fp2);
  71.                     for(i=0;i<183;i++)
  72.                     {
  73.                         lengte=(int)fgetc(fp);
  74.                         fputc((lengte),fp2);
  75.                     }
  76.                     string=(char*)malloc(lengte);
  77.                     string=fgets(string,lengte,fp);
  78.                     replace(string,verander,lengte);
  79.                     fputs(string,fp2);
  80.                 }
  81.                 else
  82.                 {
  83.                   if(c=='4')
  84.                   // txt4 chunk
  85.                   {
  86.                     fputs("XT4",fp2);
  87.                     for(i=0;i<205;i++)
  88.                     {
  89.                         lengte=(int)fgetc(fp);
  90.                         fputc((lengte),fp2);
  91.                     }
  92.                     string=(char*)malloc(lengte);
  93.                     string=fgets(string,lengte,fp);
  94.                     replace(string,verander,lengte);
  95.                     fputs(string,fp2);
  96.                   }
  97.                   else
  98.                   {
  99.                     // c if fout.
  100.                     // print a,b,c
  101.                     fputc(a,fp2);
  102.                     fputc(b,fp2);
  103.                     fputc(c,fp2);
  104.                   }
  105.                 }
  106.               else
  107.               {
  108.               // b is fout
  109.               // print a,b
  110.               fputc(a,fp2);
  111.               fputc(b,fp2);
  112.               }
  113.             else
  114.             //a is fout
  115.             fputc(a,fp2);
  116.         }
  117.         txt=fgetc(fp);
  118.  
  119.     }
  120.     while(feof(fp)==0);
  121.     fclose(fp);
  122.     fclose(fp2);
  123.     remove(filename);
  124.     rename(path,filename);
  125. }
  126. ///
  127.  
  128. /// replace
  129. void replace(char *string,char replace,int lengte)
  130. {
  131.     int i;
  132.     char with;
  133.     if(replace=='/')
  134.         with='\\';
  135.     else
  136.         with='/';
  137.     for(i=0;i<lengte;i++)
  138.     {
  139.         if(string[i]==replace)
  140.             string[i]=with;
  141.     }
  142. }
  143. ///
  144.