MKS Integrity Command line API

Joe Varghese picture Joe Varghese · May 16, 2013 · Viewed 7.9k times · Source

Has anyone here got experience in building a parser for the MKS Integrity command line API. I am planning to build an API (in C#) and would need to build a CLI result parser which I could use to parse the results from the CLI. I have heard that the results from the CLI does not follow any specific data layout (there are no field separators etc.) and is subject to change from versions to versions. Is this true? I have heard about the JAVA and ANSI C api but have also heard that they don't support all the functionality exposed by the CLI. Any feedback will be of great help.

Thanks and Regards, Joe.

Answer

SzG picture SzG · Jun 25, 2013

Good luck. It's extremely difficult to parse MKS's output. For instance the "si viewsandbox" command indicates subproject structure by indentation. Here is a Perl code snippet to map members to subprojects:

our %parentproject;
our @projects;
my @subprojects;
$subprojects[0] = $sandbox;
$projects[0] = $sandbox;
open MKS, "si viewsandbox -R -S $sandbox |" or die $!;
while () {
    chomp;
    next if /working file/i;
    next if /new revision available/i;
    my ($indentation, $filename, $project, $version, $type);
    if (m:^( +)$dir/(.+) archived (.+) *$:) {
        ($indentation, $filename, $version) = ($1, $2, $3);
    }
    if (m:^( +)$dir/(.+project) (\((.+)\) )?(.*subsandbox) *$:) {
        ($indentation, $project, $version, $type) = ($1, $2, $4, $5);
    }
    next unless $indentation;
    my $level = length($indentation) / 2 + 1;
    if ($project) {
        $subprojects[$level] = $project;
        $parentproject{$project} = $subprojects[$level - 1];
        push @projects, $project;
    }
    if ($filename) {
        $parentproject{$filename} = $subprojects[$level - 1];
    }
}

This script runs on Linux, so folder separators are /. You may want to use \ in some regexps on Windows.

Please take time to appreciate the beauty of MKS' output. Direct members of the project indented by 1. Members of a subproject indented by 3. Members of a subproject of a subproject indented by 5. And so on.

I'd give up, and write ad hoc scripts where absolutely necessary, but no more. And yes, the output does change between versions. Sometimes.