Added -Wall to CFLAGS
[mx3r.git] / mx3r.c
blobc0629d0d7368e4c39bb54c311ba94965a3b5db65
1 /*
2 Prueba de concepto de buscador de diferencias por bloques.
3 */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
9 // CLIG - Command Line Interpreter Generator:
10 #include "cmdline.h"
11 #include "util.h"
15 void showUsage()
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;
53 int lbb=0;
54 int l2bb=0;
55 int total=0;
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);
90 free(base_file);
91 free(local_file);
92 return 0;
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");
112 return 0;
113 } else
115 printf("\n ** ERROR \n");
116 return 1;
119 if (cmd->do_hashcmpP)
121 int i,b;
122 int nhashes=cmd->do_hashcmpC-1;
123 int block_size=4;
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]);
137 printf( "\n");
139 free(int_hash);
140 return 0;
143 printf("* Nothing to do.\n");
144 showUsage();
145 return 1;