2 Prueba de concepto de buscador de diferencias por bloques.
9 // CLIG - Command Line Interpreter Generator:
17 printf("Usage: \n"); usage();
20 int doBLRMerge(char *base
, char *local
, char *remote
)
22 BLRintA split
=splitBLR(base
, local
, remote
);
24 fprintf( stderr
, "Base File: %d blocks found\n",split
.basesz
);
25 fprintf( stderr
, "Local File: %d blocks found\n",split
.localsz
);
26 fprintf( stderr
, "Remote File: %d blocks found\n",split
.remotesz
);
30 int *base_file
=NULL
, base_file_size
=0;
31 base_file
=hash_loadfile(base
,&base_file_size
);
32 if (!base_file
) exit( 0 ); // Error de memoria.
33 fprintf( stderr
, "Base File: %d lines loaded\n",base_file_size
);
35 int *local_file
=NULL
, local_file_size
=0;
36 local_file
=hash_loadfile(local
,&local_file_size
);
37 if (!local_file
) exit( 0 ); // Error de memoria.
38 fprintf( stderr
, "Local File: %d lines loaded\n",local_file_size
);
40 hashblock bloque_BL
[64];
41 int nbloquesBL
= compare2hashvectors(base_file
,base_file_size
,
42 local_file
,local_file_size
,256,bloque_BL
,64);
44 int *remote_file
=NULL
, remote_file_size
=0;
45 remote_file
=hash_loadfile(remote
,&remote_file_size
);
46 if (!remote_file
) exit( 0 ); // Error de memoria.
47 fprintf( stderr
, "Remote File: %d lines loaded\n",remote_file_size
);
49 hashblock bloque_BR
[64];
50 int nbloquesBR
= compare2hashvectors(base_file
,base_file_size
,
51 remote_file
,remote_file_size
,256,bloque_BR
,64);
53 hashblock
*bloque
=bloque_BR
;
58 int total_huerfanas
=0;
59 int total_huerfanas2
=0,j
;
61 for (j
=0;j
<nbloquesBR
;j
++)
63 total_huerfanas2
+=bloque
[j
].line2
-l2bb
;
64 total_huerfanas
+=bloque
[j
].line1
-lbb
;
65 total
+=bloque
[j
].size
;
66 printf("\t-- %d -> %d lineas huerfanas -- \n",bloque
[j
].line1
-lbb
, bloque
[j
].line2
-l2bb
);
68 printf("BLOQUE %d: @%d:%d \t--> \t%d:%d \t(%d:%d)\n", j
, bloque
[j
].line1
,bloque
[j
].line2
, bloque
[j
].line1
+bloque
[j
].size
,bloque
[j
].line2
+bloque
[j
].size
,
69 bloque
[j
].line2
-bloque
[j
].line1
,bloque
[j
].size
);
71 lbb
=bloque
[j
].line1
+bloque
[j
].size
+1;
72 l2bb
=bloque
[j
].line2
+bloque
[j
].size
+1;
74 if (base_file_size
!=lbb
+1 || local_file_size
!=l2bb
+1)
76 total_huerfanas2
+=local_file_size
-l2bb
-1;
77 printf("\t-- %d -> %d lineas huerfanas -- \n",base_file_size
-lbb
-1, local_file_size
-l2bb
-1);
80 float p100_found
=100*total
/(float)base_file_size
;
81 float p100_obsolete
=100*(total_huerfanas
)/(float)base_file_size
;
82 float p100_new
=100*total_huerfanas2
/(float)local_file_size
;
83 float p100_probability
=100-p100_obsolete
-p100_new
;
85 printf("\n\nRESUMEN: %d lineas encontradas en %d bloques (%.2f%% del total)\n",
86 total
,nbloquesBR
, p100_found
);
87 printf("\t(Total: %d lineas huerfanas. %.2f%% del fichero base es obsoleto)\n", total_huerfanas
,p100_obsolete
);
88 printf("\t(Total: %d lineas nuevas. %.2f%% del fichero local es nuevo)\n",total_huerfanas2
,p100_new
);
89 printf(" -- %.2f%% de probabilidad de completar el merge correctamente -- \n",p100_probability
);
98 int main(int argc
, char **argv
) {
99 // Parse the command line args.
100 Cmdline
*cmd
= parseCmdline(argc
, argv
);
102 if (cmd
->show_helpP
) showUsage();
104 if (cmd
->do_blrmergeP
)
106 return doBLRMerge(cmd
->do_blrmerge
[0],cmd
->do_blrmerge
[1],cmd
->do_blrmerge
[2]);
108 if (cmd
->test_pluginP
)
110 printf("\n Intentando cargar el plugin... \n");
111 if (loadsplitplugin())
113 printf("\n - El plugin se cargó correctamente -\n");
117 printf("\n ** ERROR \n");
121 if (cmd
->do_hashcmpP
)
124 int nhashes
=cmd
->do_hashcmpC
-1;
126 unsigned int *int_hash
=malloc((nhashes
)*sizeof(unsigned int));
127 fprintf( stderr
, "nhashes: %d\n",nhashes
);
128 for (i
=1;i
<cmd
->do_hashcmpC
;i
++)
130 int_hash
[i
-1]=ihash(cmd
->do_hashcmp
[i
]);
133 for (i
=0;i
<nhashes
-block_size
+1;i
++)
135 for (b
=0;b
<block_size
;b
++)
137 printf( "%08X", int_hash
[i
+b
]);
145 printf("* Nothing to do.\n");