Sunday, November 22, 2015

Serena Dimensions & KDiff3

At work we use Serena Dimensions for Version Control.
Dimensions seems to use "pvcsmerge" for Diff-view which is imho a bit out-of-date regarding functionality and usability.

My personal favorite would be BeyondCompare, but i have no budget for buying such stuff, so i looked into a way to integrate Kdiff3 (imho next-best) into Serena Dimensions.

I did some investigation and finaly came to the conclusion that calling "Diff" lets Dimensions download the Files-to-be-diff'ed to temporary files and call "pvcsmerge" with those files.

So i created an executable that takes the same parameter as "pvcsmerge," but launches Kdiff3 with reformated parameters.
Replacing the original "pvcsmerge.exe" with the homebrewn executable provided exactly the functionality i wanted!

Implementation (feedback welcome, but pls. don't flame me because of the poor C :-)):

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

main(int argc, char *argv[])
   int c;
   char ch;
     // file contains the name of the files-to-be-compared
   char* filename;
   filename = argv[2];
   FILE *fi = fopen(filename, "r");
   #define MAXLINE 200
   char bufr[MAXLINE];
   char para[MAXLINE];
   char value[MAXLINE];
   char v1 [MAXLINE];
   char v2 [MAXLINE];
   char n1 [MAXLINE];
   char n2 [MAXLINE];

   if(fi != NULL) {
     while( !feof(fi)) {
       // String2parse: <para>=<value>
       fscanf(fi, "%[^=] %*c %s\n", para, value);
       if (strcmp(para, "ANCESTOR") == 0) {
         // String2parse: "C:\Users\xxxxx\AppData\Local\Temp\SRC(yyyyy)_12.pt1646c2.tmp","SRC(yyyyy);12 - Derivative"
         sscanf( value, "\"%[^\"]\",\"%[^\"]\"", v1, n1);
       if (strcmp(para, "DERIVATIVES") == 0) {
         sscanf( value, "\"%[^\"]\",\"%[^\"]\"", v2, n2);
   } else {
   // start kdiff3  
   char start[1024];
   strcpy (start, "c:\\xxxxxx\\kdiff3\\kdiff3.exe ");
   strcat (start, v1);
   strcat (start, " ");
   strcat (start, v2);
   strcat (start, " --L1 ");
   strcat (start, n1);
   strcat (start, " --L2 ");
   strcat (start, n2);
   return 0;

Compile (i'm using mingw):
gcc pvcsmerge.c -o pvcsmerge.exe

No comments: