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 printf("\n Trying to load %s file using mmap() . . . \n", base
);
24 int basesz
=0;char *basef
=loadfile(base
, &basesz
);
25 int localsz
=0;char *localf
=loadfile(local
, &localsz
);
26 int remotesz
=0;char *remotef
=loadfile(remote
, &remotesz
);
28 int *base_file
=NULL
, base_file_size
=0;
29 base_file
=hash_loadfile(base
,&base_file_size
);
30 if (!base_file
) exit( 0 ); // Error de memoria.
31 fprintf( stderr
, "Base File: %d lines loaded\n",base_file_size
);
33 int *local_file
=NULL
, local_file_size
=0;
34 local_file
=hash_loadfile(local
,&local_file_size
);
35 if (!local_file
) exit( 0 ); // Error de memoria.
36 fprintf( stderr
, "Local File: %d lines loaded\n",local_file_size
);
38 hashblock bloque_BL
[64];
39 int nbloquesBL
= compare2hashvectors(base_file
,base_file_size
,
40 local_file
,local_file_size
,256,bloque_BL
,64);
42 int *remote_file
=NULL
, remote_file_size
=0;
43 remote_file
=hash_loadfile(remote
,&remote_file_size
);
44 if (!remote_file
) exit( 0 ); // Error de memoria.
45 fprintf( stderr
, "Remote File: %d lines loaded\n",remote_file_size
);
47 hashblock bloque_BR
[64];
48 int nbloquesBR
= compare2hashvectors(base_file
,base_file_size
,
49 remote_file
,remote_file_size
,256,bloque_BR
,64);
51 hashblock
*bloque
=bloque_BR
;
56 int total_huerfanas
=0;
57 int total_huerfanas2
=0,j
;
59 for (j
=0;j
<nbloquesBR
;j
++)
61 total_huerfanas2
+=bloque
[j
].line2
-l2bb
;
62 total_huerfanas
+=bloque
[j
].line1
-lbb
;
63 total
+=bloque
[j
].size
;
64 printf("\t-- %d -> %d lineas huerfanas -- \n",bloque
[j
].line1
-lbb
, bloque
[j
].line2
-l2bb
);
66 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
,
67 bloque
[j
].line2
-bloque
[j
].line1
,bloque
[j
].size
);
69 lbb
=bloque
[j
].line1
+bloque
[j
].size
+1;
70 l2bb
=bloque
[j
].line2
+bloque
[j
].size
+1;
72 if (base_file_size
!=lbb
+1 || local_file_size
!=l2bb
+1)
74 total_huerfanas2
+=local_file_size
-l2bb
-1;
75 printf("\t-- %d -> %d lineas huerfanas -- \n",base_file_size
-lbb
-1, local_file_size
-l2bb
-1);
78 float p100_found
=100*total
/(float)base_file_size
;
79 float p100_obsolete
=100*(total_huerfanas
)/(float)base_file_size
;
80 float p100_new
=100*total_huerfanas2
/(float)local_file_size
;
81 float p100_probability
=100-p100_obsolete
-p100_new
;
83 printf("\n\nRESUMEN: %d lineas encontradas en %d bloques (%.2f%% del total)\n",
84 total
,nbloquesBR
, p100_found
);
85 printf("\t(Total: %d lineas huerfanas. %.2f%% del fichero base es obsoleto)\n", total_huerfanas
,p100_obsolete
);
86 printf("\t(Total: %d lineas nuevas. %.2f%% del fichero local es nuevo)\n",total_huerfanas2
,p100_new
);
87 printf(" -- %.2f%% de probabilidad de completar el merge correctamente -- \n",p100_probability
);
96 int main(int argc
, char **argv
) {
97 // Parse the command line args.
98 Cmdline
*cmd
= parseCmdline(argc
, argv
);
100 if (cmd
->show_helpP
) showUsage();
102 if (cmd
->do_blrmergeP
)
104 return doBLRMerge(cmd
->do_blrmerge
[0],cmd
->do_blrmerge
[1],cmd
->do_blrmerge
[2]);
106 if (cmd
->test_pluginP
)
108 printf("\n Intentando cargar el plugin... \n");
109 if (loadsplitplugin())
111 printf("\n - El plugin se cargó correctamente -\n");
115 printf("\n ** ERROR \n");
119 if (cmd
->do_hashcmpP
)
122 int nhashes
=cmd
->do_hashcmpC
-1;
124 unsigned int *int_hash
=malloc((nhashes
)*sizeof(unsigned int));
125 fprintf( stderr
, "nhashes: %d\n",nhashes
);
126 for (i
=1;i
<cmd
->do_hashcmpC
;i
++)
128 int_hash
[i
-1]=ihash(cmd
->do_hashcmp
[i
]);
131 for (i
=0;i
<nhashes
-block_size
+1;i
++)
133 for (b
=0;b
<block_size
;b
++)
135 printf( "%08X", int_hash
[i
+b
]);
143 printf("* Nothing to do.\n");