Annotation of dmsdos/src/cmpdisk.cpp, revision 1.1

1.1     ! root        1: 
        !             2: /* BC 3.1 source code for something similar to simple diff */
        !             3: 
        !             4: #include <string.h>
        !             5: #include <dos.h>
        !             6: #include <dir.h>
        !             7: #include <stdio.h>
        !             8: #include <io.h>
        !             9: #include <fcntl.h>
        !            10: #include <sys/stat.h>
        !            11: 
        !            12: #define COMPAREBUFLEN (1024*16)
        !            13: char comparebuf1[COMPAREBUFLEN];
        !            14: char comparebuf2[COMPAREBUFLEN];
        !            15: 
        !            16: int TestAllFiles(char *path1,char *path2)
        !            17: {
        !            18:  int old_path_len1,old_path_len2;
        !            19:  int done,file1,file2,i;
        !            20:  struct ffblk s;
        !            21:  int len1,len2;
        !            22:  long int pos;
        !            23: 
        !            24:  old_path_len1=strlen(path1);
        !            25:  old_path_len2=strlen(path2);
        !            26:  strcat(path1,"*.*");
        !            27:  done=findfirst(path1,&s,0x2f);
        !            28:  path1[old_path_len1]=0;
        !            29: 
        !            30:  while(!done)
        !            31:  {
        !            32:   path1[old_path_len1]=0;
        !            33:   path2[old_path_len2]=0;
        !            34:   strcat(path1,s.ff_name);
        !            35:   strcat(path2,s.ff_name);
        !            36: 
        !            37:   printf("File in progress %s",path1);
        !            38: 
        !            39:   if ((file1=open(path1, O_RDONLY | O_BINARY , S_IREAD))==-1)
        !            40:    {printf("\nCannot open file: %s \n",path1);goto error;}
        !            41:   else if ((file2=open(path2, O_RDONLY | O_BINARY , S_IREAD))==-1)
        !            42:    {printf("\nCannot open file: %s \n",path2);close(file1);goto error;}
        !            43:   else
        !            44:   {
        !            45:    len2=len1=COMPAREBUFLEN;pos=0;
        !            46:    while((len1==COMPAREBUFLEN)&&(len2==COMPAREBUFLEN))
        !            47:    {
        !            48:     if((len1=read(file1,comparebuf1,COMPAREBUFLEN))==-1)
        !            49:     {
        !            50:      printf("\ndisk IO error!: cannot read file %s\n",path1);
        !            51:      goto error_close;
        !            52:     }
        !            53:     if((len2=read(file2,comparebuf2,COMPAREBUFLEN))==-1)
        !            54:     {
        !            55:      printf("\ndisk IO error!: cannot read file %s\n",path2);
        !            56:      goto error_close;
        !            57:     };
        !            58:     if(len1) if(memcmp(comparebuf1,comparebuf2,len1))
        !            59:     {
        !            60:      for(i=0;(i<len1)&&(*(comparebuf1+i)==*(comparebuf2+i));i++);
        !            61:      printf("\nCompare Error %s on pos %X!\n",path1,pos+i);
        !            62:      goto error_close;
        !            63:     }
        !            64:     pos+=len1;
        !            65:    }
        !            66:    if(len1!=len2)
        !            67:    {
        !            68:     printf("\nDifferent lengths of files %s and %s",path1,path2);
        !            69:     error_close:
        !            70:     close(file2);
        !            71:     close(file1);
        !            72:     error:
        !            73:     if(getchar()=='q') return(1);
        !            74:     break;
        !            75:    }else{
        !            76:     printf(" ... compared %ld bytes\n",pos);
        !            77:     close(file2);
        !            78:     close(file1);
        !            79:    };
        !            80:   }
        !            81:   done=findnext(&s);
        !            82:  }
        !            83: 
        !            84:  path1[old_path_len1]=0;
        !            85:  path2[old_path_len2]=0;
        !            86:  strcat(path1,"*.*");
        !            87:  done=findfirst(path1,&s,FA_DIREC | 0x7);
        !            88:  path1[old_path_len1]=0;
        !            89: 
        !            90: 
        !            91:  while(!done)
        !            92:  {
        !            93:   if(*s.ff_name != '.')
        !            94:   {
        !            95:    if((s.ff_attrib & FA_DIREC)!=0)
        !            96:    {
        !            97:     strcat(path1,s.ff_name);
        !            98:     strcat(path1,"\\");
        !            99:     path1[old_path_len1+strlen(s.ff_name)+1]=0;
        !           100:     strcat(path2,s.ff_name);
        !           101:     strcat(path2,"\\");
        !           102:     path1[old_path_len2+strlen(s.ff_name)+1]=0;
        !           103:     TestAllFiles(path1,path2);
        !           104:     path1[old_path_len1]=0;
        !           105:     path2[old_path_len2]=0;
        !           106:    }
        !           107:   }
        !           108:   done=findnext(&s);
        !           109:  }
        !           110:  path1[old_path_len1]=0;
        !           111:  path2[old_path_len2]=0;
        !           112: 
        !           113:  return 0;
        !           114: }
        !           115: 
        !           116: int main(int argc,char *argv[])
        !           117: {
        !           118:  if(argc<3)
        !           119:  {
        !           120:   printf("usage: cmpdisk <d>: <d>:\n");
        !           121:   return(0);
        !           122:  };
        !           123: 
        !           124:  {
        !           125:   char path1[255],path2[255];
        !           126:   strcpy(path1,argv[1]);
        !           127:   strcpy(path2,argv[2]);
        !           128:   TestAllFiles(path1,path2);
        !           129:  };
        !           130:  return(0);
        !           131: };

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.