From cca6f387bca41ae59ea0585daeb2af104b742a8d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20Mart=C3=ADnez=20Mart=C3=AD?= Date: Mon, 14 Apr 2008 18:23:46 +0200 Subject: [PATCH] Working a bit on CLIG, Makefiles, etc. --- Makefile | 9 +++++--- cmdline.c | 52 +++++++++++++++++++++++++++++--------------- cmdline.cli | 9 +++++--- cmdline.h | 18 ++++++++++------ mx3r.1 | 19 ++++++++++------ mx3r.c | 72 +++++++++++++++++++++++++++++++++++++++---------------------- 6 files changed, 118 insertions(+), 61 deletions(-) diff --git a/Makefile b/Makefile index 2e56832..9b6228b 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,12 @@ all: mx3r mx3r.1 -mx3r: mx3r.o - gcc -lstdc++ -lgcrypt -lgpg-error -o $@ $< +mx3r: mx3r.o cmdline.o mx3r.1 + gcc -lstdc++ -lgcrypt -lgpg-error -o $@ mx3r.o cmdline.o -mx3r.o: mx3r.c +mx3r.o: mx3r.c mx3r.1 + gcc -c -o $@ $< + +cmdline.o: cmdline.c mx3r.1 gcc -c -o $@ $< mx3r.1: cmdline.cli diff --git a/cmdline.c b/cmdline.c index 2367dd6..f61507d 100644 --- a/cmdline.c +++ b/cmdline.c @@ -22,13 +22,19 @@ char *Program; /*@-null*/ static Cmdline cmd = { - /***** -blr: Try a full (base->local to remote) merge */ - /* mergeP = */ 0, - /* merge = */ (char**)0, - /* mergeC = */ 0, - /***** -help: show usage information */ + /***** --blr: +Try a full (base->local to remote) merge */ + /* do_blrmergeP = */ 0, + /* do_blrmerge = */ (char**)0, + /* do_blrmergeC = */ 0, + /***** --hashcmp: ... +Do a hash compare between 4 or more lines. */ + /* do_hashcmpP = */ 0, + /* do_hashcmp = */ (char**)0, + /* do_hashcmpC = */ 0, + /***** --help: show usage information */ /* show_helpP = */ 0, - /***** -version: show program version */ + /***** --version: show program version */ /* show_versionP = */ 0, /***** uninterpreted rest of command line */ /* argc = */ 0, @@ -729,13 +735,17 @@ catArgv(int argc, char **argv) void usage(void) { - fprintf(stderr,"%s"," [-blr merge] [-help] [-version]\n"); + fprintf(stderr,"%s"," [--blr do_blrmerge] [--hashcmp do_hashcmp] [--help] [--version]\n"); fprintf(stderr,"%s"," merges files looking for similar patterns, and allows several plugins\n"); fprintf(stderr,"%s"," for understanding the syntax of several files \n"); - fprintf(stderr,"%s"," -blr: Try a full (base->local to remote) merge\n"); - fprintf(stderr,"%s"," 3 char* values\n"); - fprintf(stderr,"%s"," -help: show usage information\n"); - fprintf(stderr,"%s"," -version: show program version\n"); + fprintf(stderr,"%s"," --blr: \n"); + fprintf(stderr,"%s"," Try a full (base->local to remote) merge\n"); + fprintf(stderr,"%s"," 3 char* values\n"); + fprintf(stderr,"%s"," --hashcmp: ... \n"); + fprintf(stderr,"%s"," Do a hash compare between 4 or more lines.\n"); + fprintf(stderr,"%s"," 4 or more char* values\n"); + fprintf(stderr,"%s"," --help: show usage information\n"); + fprintf(stderr,"%s"," --version: show program version\n"); fprintf(stderr,"%s"," version: 0.1.0\n"); fprintf(stderr,"%s"," "); exit(EXIT_FAILURE); @@ -749,20 +759,28 @@ parseCmdline(int argc, char **argv) Program = argv[0]; cmd.tool = catArgv(argc, argv); for(i=1, cmd.argc=1; ilocal to remote) merge} {count = 3,3} -Flag -help show_help {show usage information} -Flag -version show_version {show program version} +String --blr do_blrmerge { +Try a full (base->local to remote) merge} {count = 3,3} +String --hashcmp do_hashcmp { ... +Do a hash compare between 4 or more lines.} {count = 4,oo} +Flag --help show_help {show usage information} +Flag --version show_version {show program version} ######################################################################## ## EXAMPLE OF FLAG OPTION diff --git a/cmdline.h b/cmdline.h index cdc7470..c08ecd3 100644 --- a/cmdline.h +++ b/cmdline.h @@ -9,13 +9,19 @@ *****/ typedef struct s_Cmdline { - /***** -blr: Try a full (base->local to remote) merge */ - char mergeP; - char* *merge; - int mergeC; - /***** -help: show usage information */ + /***** --blr: +Try a full (base->local to remote) merge */ + char do_blrmergeP; + char* *do_blrmerge; + int do_blrmergeC; + /***** --hashcmp: ... +Do a hash compare between 4 or more lines. */ + char do_hashcmpP; + char* *do_hashcmp; + int do_hashcmpC; + /***** --help: show usage information */ char show_helpP; - /***** -version: show program version */ + /***** --version: show program version */ char show_versionP; /***** uninterpreted command line parameters */ int argc; diff --git a/mx3r.1 b/mx3r.1 index 8d8152e..8454147 100644 --- a/mx3r.1 +++ b/mx3r.1 @@ -23,21 +23,28 @@ for understanding the syntax of several files .\" cligPart SYNOPSIS .SH SYNOPSIS .B mx3r -[-blr merge] -[-help] -[-version] +[--blr do_blrmerge] +[--hashcmp do_hashcmp] +[--help] +[--version] .\" cligPart SYNOPSIS end .\" cligPart OPTIONS .SH OPTIONS -.IP -blr +.IP --blr + Try a full (base->local to remote) merge, .br 3 String values -.IP -help +.IP --hashcmp + ... +Do a hash compare between 4 or more lines., +.br +4 or more String values +.IP --help show usage information. -.IP -version +.IP --version show program version. .\" cligPart OPTIONS end diff --git a/mx3r.c b/mx3r.c index 1857186..5a9c9c3 100644 --- a/mx3r.c +++ b/mx3r.c @@ -7,11 +7,15 @@ #include #include #include + +// CLIG - Command Line Interpreter Generator: +#include "cmdline.h" + // Tipos de hashes : // GCRY_MD_CRC32 - CRC32, sencillo, rápido. // GCRY_MD_SHA1 - SHA1 potente y seguro. #define HASH_TYPE GCRY_MD_SHA1 - +#define VERSION 0.1.0 // Establece cual es el ancho máximo de línea para trabajar. // Establecer como mínimo a 90. Recomendado 128 o 256. @@ -30,28 +34,25 @@ typedef struct structhashblock { int size; } hashblock; -int main(int argc, char **argv) { - // Comprobar la entrada de argumentos. - if ( argc < 2 ) { - fprintf( stderr, "Usage: %s \n", argv[0] ); - fprintf( stderr, "Usage: %s --blr \n", argv[0] ); - exit( 0 ); - } +void showUsage() +{ + printf("Usage: \n"); usage(); +} - if (argc > 4 && strcmp(argv[1],"--blr")==0) - { +int doBLRMerge(char *base, char *local, char *remote) +{ int *base_file=NULL, base_file_size=0; - base_file=hash_loadfile(argv[2],&base_file_size); + base_file=hash_loadfile(base,&base_file_size); if (!base_file) exit( 0 ); // Error de memoria. fprintf( stderr, "Base File: %d lines loaded\n",base_file_size); int *local_file=NULL, local_file_size=0; - local_file=hash_loadfile(argv[3],&local_file_size); + local_file=hash_loadfile(local,&local_file_size); if (!local_file) exit( 0 ); // Error de memoria. fprintf( stderr, "Local File: %d lines loaded\n",local_file_size); int *remote_file=NULL, remote_file_size=0; - remote_file=hash_loadfile(argv[4],&remote_file_size); + remote_file=hash_loadfile(remote,&remote_file_size); if (!remote_file) exit( 0 ); // Error de memoria. fprintf( stderr, "Remote File: %d lines loaded\n",remote_file_size); @@ -211,27 +212,46 @@ int main(int argc, char **argv) { free(base_file); free(local_file); - exit( 1 ); - } + return 0; + +} - int i,b; - int nhashes=argc-1; - unsigned int *int_hash=malloc((nhashes)*sizeof(unsigned int)); - fprintf( stderr, "nhashes: %d\n",nhashes ); - for (i=1;ishow_helpP) showUsage(); + + if (cmd->do_blrmergeP) { - int_hash[i-1]=ihash(argv[i]); + return doBLRMerge(cmd->do_blrmerge[0],cmd->do_blrmerge[1],cmd->do_blrmerge[2]); } - for (i=0;ido_hashcmpP) { - for (b=0;bdo_hashcmpC-1; + unsigned int *int_hash=malloc((nhashes)*sizeof(unsigned int)); + fprintf( stderr, "nhashes: %d\n",nhashes ); + for (i=1;ido_hashcmpC;i++) { - printf( "%08X", int_hash[i+b]); + int_hash[i-1]=ihash(cmd->do_hashcmp[i]); } - printf( "\n"); + + for (i=0;i