LCOV - code coverage report
Current view: top level - testing - Mdiff.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 46 78 59.0 %
Date: 2018-07-12 00:10:09 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V.
       7             :  */
       8             : 
       9             : #include "monetdb_config.h"
      10             : 
      11             : #include "difflib.h"
      12             : #ifdef HAVE_IO_H
      13             : # include <io.h>
      14             : #endif
      15             : #include <string.h>
      16             : 
      17             : #ifdef HAVE_GETOPT
      18             : #ifdef HAVE_GETOPT_H
      19             : #include <getopt.h>
      20             : #endif
      21             : #else
      22             : #include "testing_getopt.c"
      23             : #endif
      24             : 
      25             : static void
      26           0 : showUsage(char *name)
      27             : {
      28           0 :         printf("Usage:  %s [-I<exp>] [-F<exp>] [-C<num>] [-A<num>] [-t<text>] [-r<rev>] <oldfile> <newfile> [<outfile>]\n", name);
      29           0 :         printf("\n");
      30           0 :         printf(" -I<exp>   : ignore lines matching <exp> during diff (optional, default: -I'^#')\n");
      31           0 :         printf(" -F<exp>   : show the most recent line matching <exp>\n");
      32           0 :         printf(" -C<num>   : use <num> lines of context during diff (optional, default: -C1)\n");
      33           0 :         printf(" -A<num>   : accuracy for diff: 0=lines, 1=words, 2=chars (optional, default: -A1)\n");
      34           0 :         printf(" -d        : change the algorithm to perhaps find a smaller set of changes;\n");
      35           0 :         printf("             this makes diff slower (sometimes much slower)\n");
      36           0 :         printf(" -t<text>  : text for caption (optional, default: empty)\n");
      37           0 :         printf(" -r<rev>   : revision of old file (optional, default: empty)\n");
      38           0 :         printf(" -q        : be less verbose\n");
      39           0 :         printf(" <oldfile> : first file for diff\n");
      40           0 :         printf(" <newfile> : second file for diff\n");
      41           0 :         printf(" <outfile> : file for HTML output (optional, default: stdout)\n");
      42           0 : }
      43             : 
      44             : int
      45        5204 : main(int argc, char **argv)
      46             : {
      47        5204 :         char EMPTY[] = "";
      48             : #ifdef NATIVE_WIN32
      49             :         char DEFAULT[] = "\"-I^#\"";
      50             : #else
      51        5204 :         char DEFAULT[] = "-I'^#'";
      52             : #endif
      53        5204 :         char ignoreWHITE[] = " -b -B";
      54        5204 :         char *old_fn, *new_fn, *html_fn, *caption = EMPTY, *revision = EMPTY, *ignoreEXP = DEFAULT, *ignore = NULL, *function = EMPTY;
      55        5204 :         int LWC = 1, context = 1, option, mindiff = 0, quiet = 0;
      56             : 
      57       45675 :         while ((option = getopt(argc, argv, "hdqA:C:I:F:t:r:")) != EOF)
      58       35267 :                 switch (option) {
      59             :                 case 'd':
      60             :                         mindiff = 1;
      61             :                         break;
      62        5204 :                 case 'A':
      63       10408 :                         LWC = atoi(optarg);
      64        5204 :                         break;
      65        5204 :                 case 'C':
      66       10408 :                         context = atoi(optarg);
      67             : 
      68        5204 :                         break;
      69        5204 :                 case 'I':
      70        5204 :                         ignoreEXP = (char *) malloc(strlen(optarg) + 6);
      71             : #ifdef NATIVE_WIN32
      72             :                         strcpy(ignoreEXP, "\"-I");
      73             : #else
      74        5204 :                         strcpy(ignoreEXP, "'-I");
      75             : #endif
      76       10408 :                         strcat(ignoreEXP, optarg);
      77             : #ifdef NATIVE_WIN32
      78             :                         strcat(ignoreEXP, "\"");
      79             : #else
      80             :                         strcat(ignoreEXP, "'");
      81             : #endif
      82             :                         break;
      83        5204 :                 case 'F':
      84        5204 :                         function = malloc(strlen(optarg) + 6);
      85             : #ifdef NATIVE_WIN32
      86             :                         strcpy(function, "\"-F");
      87             : #else
      88        5204 :                         strcpy(function, "'-F");
      89             : #endif
      90       10408 :                         strcat(function, optarg);
      91             : #ifdef NATIVE_WIN32
      92             :                         strcat(function, "\"");
      93             : #else
      94             :                         strcat(function, "'");
      95             : #endif
      96             :                         break;
      97        5204 :                 case 't':
      98        5204 :                         caption = optarg;
      99        5204 :                         break;
     100           0 :                 case 'r':
     101           0 :                         revision = optarg;
     102           0 :                         break;
     103        5204 :                 case 'q':
     104        5204 :                         quiet = 1;
     105        5204 :                         break;
     106           0 :                 case 'h':
     107             :                 default:
     108           0 :                         showUsage(argv[0]);
     109           0 :                         if (ignoreEXP != DEFAULT)
     110           0 :                                 free(ignoreEXP);
     111           0 :                         if (function != EMPTY)
     112           0 :                                 free(function);
     113           0 :                         exit(1);
     114             :                 }
     115             : 
     116        5204 :         ignore = (char *) malloc(strlen(ignoreEXP) + strlen(ignoreWHITE) + 2);
     117        5204 :         strcpy(ignore, ignoreEXP);
     118        5204 :         strcat(ignore, ignoreWHITE);
     119             : 
     120        5204 :         optind--;
     121        5204 :         old_fn = ((argc > (++optind)) ? argv[optind] : "-");
     122        5204 :         new_fn = ((argc > (++optind)) ? argv[optind] : "-");
     123        5204 :         html_fn = ((argc > (++optind)) ? argv[optind] : "-");
     124             : 
     125             :         TRACE(fprintf(STDERR, "%s %s -A %i -C %i %s %s -t %s -r %s  %s %s %s\n", argv[0], mindiff ? "-d" : "", LWC, context, ignore, function, caption, revision, old_fn, new_fn, html_fn));
     126             : 
     127        5204 :         switch (oldnew2html(mindiff, LWC, context, ignore, function, old_fn, new_fn, html_fn, caption, revision)) {
     128        5174 :         case 0:
     129        5174 :                 if (quiet == 0)
     130           0 :                         fprintf(STDERR, "%s and %s are equal.\n", old_fn, new_fn);
     131             :                 break;
     132           0 :         case 1:
     133           0 :                 if (quiet != 0) {
     134           0 :                         fprintf(STDERR, "\n+ (%s) slightly\n", new_fn);
     135             :                 } else {
     136           0 :                         fprintf(STDERR, "%s and %s differ slightly.\n", old_fn, new_fn);
     137             :                 }
     138             :                 break;
     139          30 :         case 2:
     140          30 :                 if (quiet != 0) {
     141          30 :                         fprintf(STDERR, "\n* (%s) significantly\n", new_fn);
     142             :                 } else {
     143           0 :                         fprintf(STDERR, "%s and %s differ SIGNIFICANTLY!\n", old_fn, new_fn);
     144             :                 }
     145             :                 break;
     146             :         }
     147        5204 :         free(ignore);
     148        5204 :         if (ignoreEXP != DEFAULT)
     149        5204 :                 free(ignoreEXP);
     150        5204 :         if (function != EMPTY)
     151        5204 :                 free(function);
     152             : 
     153             :         TRACE(fprintf(STDERR, "done.\n"));
     154             :         return 0;
     155             : }

Generated by: LCOV version 1.12