home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / assembler / tasm / c / DIFFER < prev    next >
Encoding:
Text File  |  1992-05-30  |  2.5 KB  |  133 lines

  1. /*
  2.         File differences for LZ debug.
  3.         R.J.P.  12-5-92
  4.         14th May 1992  Onto ARC.
  5.         
  6.         
  7. */
  8.  
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include        <ctype.h>
  14.  
  15. char  *Ustrupr( char *s,int l)
  16. {
  17.  
  18.   char  *ss  =  s ;
  19.   while( *s && l-- )
  20.   *s++ = toupper( *s) ;
  21.   return ss ;
  22. }
  23.  
  24. char   *scan( int ac , char **av , char *tag )
  25. {
  26.   short   sl   =  strlen(tag) ;
  27.   while ( --ac )
  28.   {
  29.     if( !strncmp(tag,Ustrupr(*++av,sl),sl) )
  30.     {
  31.       if (!strlen(*av + sl) )
  32.                 return 0 ;
  33.       else
  34.                 return *av + sl  ;
  35.      }
  36.   }
  37.   return  0  ;
  38. }
  39.  
  40.  
  41. /*
  42.         Switches :
  43.           /1:           First  file in comparison.
  44.           /2:           Second file in comparison.
  45.           /N:           Number of mis-matches before stop.
  46. */
  47.  
  48. int  main(int ac , char **av )
  49. {
  50.  char     *cp ;
  51.  FILE     *F1,*F2 ;
  52.  char     n1[60] , n2[60] ;
  53.  int      i , NO , N = 1 ;
  54.  int      c1,c2 ;
  55.  long     L = 0 ;
  56.  
  57.  
  58.   fprintf (stderr ,
  59.   "Byte-by-Byte file Comparison R.J.P. V1.1 14th May 1992\n"
  60.            ) ;
  61.   
  62.   if ( (cp = scan(ac,av,"/1:" )),cp==0)
  63.   {
  64.         fprintf(stderr,"*No /1:\n" ) ;
  65.         return 1 ;
  66.   }
  67.   strcpy( n1,cp) ;
  68.   if ( (F1 = fopen(cp,"rb")),F1 ==0 )
  69.   {
  70.         fprintf(stderr,"*Can't open /1:%s",cp) ;
  71.         return 2 ;
  72.   }
  73.  
  74.   if ( (cp = scan(ac,av,"/2:" )),cp==0)
  75.   {
  76.         fprintf(stderr,"*No /2:\n" ) ;
  77.         return 1 ;
  78.   }
  79.   strcpy( n2,cp ) ;
  80.  
  81.   if ( (F2 = fopen(cp,"rb")),F2 ==0 )
  82.   {
  83.         fprintf(stderr,"*Can't open /2:%s",cp) ;
  84.         return 2 ;
  85.   }
  86.  
  87.   if ( (cp = scan(ac,av,"/N:" )),cp != 0 )
  88.   {
  89.         if( sscanf(cp,"%d",&i)==1)
  90.                                 N =  i ;
  91.   }
  92.   /*
  93.         Compare loop.
  94.   */
  95.    NO  = N ;
  96.  
  97.    while ( N )
  98.    {
  99.         c1 = fgetc(F1) ;
  100.         c2 = fgetc(F2) ;
  101.  
  102.         if ( feof(F1) || feof(F2) )
  103.         {
  104.                 if (feof(F1) && feof(F2))
  105.                 {
  106.                         printf("*EOF on %s & %s\n",n1,n2) ;
  107.                         break ;
  108.                 }
  109.                 if (feof(F1))
  110.                 {
  111.                         printf("*EOF on %s\n",n1) ;
  112.                         break ;
  113.                 }
  114.                 printf("*EOF on %s\n",n2) ;
  115.                 break ;
  116.         }
  117.  
  118.         if ( c1 != c2 )
  119.         {
  120.                 printf( "\t! @ %ld (%lx) %s: %d (%x) %s: %d (%x)\n"
  121.                 , L , L ,n1, c1 , c1 ,n2, c2 , c2 ) ;
  122.                 --N ;
  123.         }
  124.         ++L ;
  125.      }
  126.  
  127.   fclose(F1) ;
  128.   fclose(F2) ;
  129.   printf("*  %d Differences %ld Bytes\n",NO-N,L);
  130. return (NO - N) ;
  131. }
  132.  
  133.