~kubuntu-members/kompare/4.11

« back to all changes in this revision

Viewing changes to komparepart/diffmodel.cpp

  • Committer: Otto Bruggeman
  • Date: 2001-06-23 00:43:52 UTC
  • Revision ID: git-v1:34392a4edadd5d9f2aef99030f6dda96b4e15b92
Merge my changes into cvs so john can work with them

svn path=/trunk/kdesdk/kompare/; revision=103476

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
                format = Unified;
54
54
        else if( line.find( QRegExp( "^\\*\\*\\* " ), 0 ) == 0 )
55
55
                format = Context;
56
 
        else format = Unknown;
 
56
        else if( line.find( QRegExp( "^[acd][0-9]+ [0-9]+" ), 0 ) == 0 )
 
57
                format = RCS;
 
58
        else if( line.find( QRegExp( "^[0-9]+[0-9,]*[acd]" ), 0 ) == 0 )
 
59
                format = Ed;
 
60
        else
 
61
        {
 
62
                format = Unknown;
 
63
                kdDebug() << "Unknown format found, aborting..." << endl;
 
64
                return 1; // Error i guess...
 
65
        }
57
66
 
58
67
        return parseDiff( list, format );
59
68
};
134
143
                if ( ( pos = QRegExp( "^\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*" ).match( line, 0, &len ) ) < 0 ) return 1; // weirdness has happened
135
144
                // ok we found a hunk...
136
145
                kdDebug() << "We found the start of a hunk" << endl;
 
146
                m_noOfHunks++;
137
147
 
138
148
                ++it;
139
149
 
357
367
};
358
368
 
359
369
/**  */
360
 
int DiffModel::parseEdDiff( const QStringList& /*list*/ )
 
370
int DiffModel::parseEdDiff( const QStringList& list )
361
371
{
362
372
        kdDebug() << "Ed diff parsing:" << endl;
363
373
 
364
 
        KMessageBox::information( 0, i18n( "Sorry not yet implemented" ) );
365
 
        return 1;
 
374
        QString line;
 
375
 
 
376
        QStringList::ConstIterator it = list.begin();
 
377
 
 
378
        if ( it == list.end() )
 
379
                return 0; // Nothing to parse, should not happen though
 
380
 
 
381
        while ( it != list.end() )
 
382
        {
 
383
                line = (*it);
 
384
                kdDebug() << "Line is:" << line << endl;
 
385
                if ( line.find( QRegExp( "^[0-9]+[acd]" ), 0 ) == 0 )
 
386
                {
 
387
                        kdDebug() << "Found a added/removed/changed part" << endl;
 
388
                        // Only startline with operator, nothing else
 
389
                        // Number of lines is the same as number of lines changed
 
390
                        while( line.find( QRegExp( "^." ), 0 ) != 0 )
 
391
                        {
 
392
                                kdDebug() << "A/C/D: Line is: " << line << endl;
 
393
                                ++it;
 
394
                                line = (*it);
 
395
                        }
 
396
                }
 
397
                else if ( line.find( QRegExp( "^[0-9]+,[0-9]a" ), 0 ) == 0 )
 
398
                {
 
399
                        kdDebug() << "Found a added line with number of lines to add." << endl;
 
400
                        // Hmmm... i wonder if this ever occurs...
 
401
                        while( line.find( QRegExp( "^." ), 0 ) != 0 )
 
402
                        {
 
403
                                kdDebug() << "Added: Line is: " << line << endl;
 
404
                                // Add lines until we reach a line that starts with a '.'
 
405
                                ++it;
 
406
                                line = (*it);
 
407
                        }
 
408
                }
 
409
                else if ( line.find( QRegExp( "^[0-9]+,[0-9]c" ), 0 ) == 0 )
 
410
                {
 
411
                        kdDebug() << "Found a changed line with number of lines changed." << endl;
 
412
                        // Startline, endline, operator change
 
413
                        // Number of lines in the change has changed
 
414
                        // so could be added or deleted in disguise (sp?)
 
415
                        while( line.find( QRegExp( "^." ), 0 ) != 0 )
 
416
                        {
 
417
                                kdDebug() << "Change: Line is: " << line << endl;
 
418
                                ++it;
 
419
                                line = (*it);
 
420
                        }
 
421
                }
 
422
                else if ( line.find( QRegExp( "^[0-9]+,[0-9]d" ), 0 ) == 0 )
 
423
                {
 
424
                        kdDebug() << "Found a delete line with number of lines to delete." << endl;
 
425
                        // Startline, endline, operator delete
 
426
                        while( line.find( QRegExp( "^." ), 0 ) != 0 )
 
427
                        {
 
428
                                kdDebug() << "Delete: Line is: " << line << endl;
 
429
                                ++it;
 
430
                                line = (*it);
 
431
                        }
 
432
                }
 
433
                else
 
434
                {
 
435
                        kdDebug() << "Oops something is screwed here..." << endl;
 
436
                        kdDebug() << line << endl;
 
437
                        return 1;
 
438
                }
 
439
                ++it;
 
440
        }
 
441
 
 
442
//      KMessageBox::information( 0, i18n( "Sorry not yet implemented" ) );
 
443
//      return 1;
 
444
        return 0;
366
445
};
367
446
 
368
447
/**  */
396
475
                kdDebug() << line << endl;
397
476
 
398
477
                if ( ( pos = QRegExp( "^[0-9]+" ).match( line, 0, &len ) ) < 0 ) return 1;
 
478
                m_noOfHunks++;
399
479
                linenoA = line.mid( pos, len ).toInt();
400
480
                kdDebug() << "LinenoA: " << linenoA << endl;
401
481
                line.replace( QRegExp( "^[0-9]+" ), "" );
497
577
};
498
578
 
499
579
/**  */
500
 
int DiffModel::parseRCSDiff( const QStringList& /*list*/ )
 
580
int DiffModel::parseRCSDiff( const QStringList& list )
501
581
{
502
582
        kdDebug() << "RCS  diff parsing:" << endl;
503
583
 
504
 
        KMessageBox::information( 0, i18n( "Sorry not yet implemented" ) );
505
 
        return 1;
 
584
        /* A rcs diff has one or 2 lines describing the changes */
 
585
        /* Unfortunately there is no char that indicates the textlines */
 
586
        /* from the difftype + linenos lines */
 
587
        /* Another problem is the fact that the deleted lines are not itself */
 
588
        /* in the difffile/diffoutput */
 
589
        /* But i guess that was not needed for rcs, since the RCS- */
 
590
        /* server/program knows the original */
 
591
        /* Anyway a line looks like this: */
 
592
        /* aLINENUMBER NUMBEROFLINES -> added NUMBEROFLINES lines in newfile at LINENUMBER, the added lines will follow this statement*/
 
593
        /* dLINENUMBER NUMBEROFLINES -> deleted in NUMBEROFLINES in oldfile at LINENUMBER */
 
594
 
 
595
        QString line;
 
596
        QStringList::ConstIterator it = list.begin();
 
597
        int linenoA, linenoB, nolinesA, nolinesB;
 
598
 
 
599
        if ( it == list.end() )
 
600
                return 0; // No lines to parse
 
601
 
 
602
        kdDebug() << "There are lines..." << endl;
 
603
 
 
604
        DiffHunk* hunk = new DiffHunk( linenoA, linenoB );
 
605
        hunks.append( hunk );
 
606
 
 
607
        while( it != list.end() )
 
608
        {
 
609
                line = (*it);
 
610
                kdDebug() << "Line is: " << line << endl;
 
611
 
 
612
                if ( line.find( QRegExp( "^a[0-9]+ [0-9]+" ), 0 ) == 0 ) 
 
613
                {
 
614
                        kdDebug() << "Added line found." << endl;
 
615
                        int len, pos;
 
616
                        line.replace( 0, 1, "" ); // Strip the 'a'
 
617
                        if ( (pos = QRegExp( "^[0-9]+" ).match( line, 0, &len ) ) < 0 ) return 1;
 
618
                        linenoB = line.mid(pos, len).toInt();
 
619
                        line.replace( pos, len+1, "" ); // Also strip the extra ' '
 
620
                        if ( (pos = QRegExp( "^[0-9]+" ).match( line, 0, &len ) ) < 0 ) return 1;
 
621
                        nolinesB = line.mid(pos, len).toInt();
 
622
 
 
623
                        DiffHunk* hunk = new DiffHunk( 0, linenoB );
 
624
                        hunks.append( hunk );
 
625
 
 
626
                        Difference* diff = new Difference( 0, linenoB ); // A is unknown
 
627
                        diff->type = Difference::Insert;
 
628
 
 
629
                        ++it;
 
630
                        line = (*it);
 
631
 
 
632
                        while ( ( it != list.end() ) && ( line.find( QRegExp( "^[ad][0-9]+ [0-9]+" ), 0 ) != 0 ) )
 
633
                        {
 
634
                                // Add it to the difference
 
635
                                kdDebug() << "AddDestinationLine( " << line << " )" << endl;
 
636
                                diff->addDestinationLine( line );
 
637
 
 
638
                                ++it;
 
639
                                line = (*it);
 
640
                        }
 
641
                        --it; // We went too far, correcting it here...
 
642
                        hunk->add( diff );
 
643
                }
 
644
                else if ( line.find( QRegExp( "^d[0-9]+ [0-9]+" ), 0 ) == 0 )
 
645
                {
 
646
                        kdDebug() << "Delete line found." << endl;
 
647
                        // We dont have the actual deleted lines in the diffoutput/difffile
 
648
                        // This will be a big problem in the viewerclass...
 
649
                        int len, pos;
 
650
                        line.replace( 0, 1, "" ); // Strip the 'd'
 
651
                        if ( (pos = QRegExp( "^[0-9]+" ).match( line, 0, &len ) ) < 0 ) return 1;
 
652
                        linenoA = line.mid(pos, len).toInt();
 
653
                        line.replace( pos, len+1, "" ); // Also strip the extra ' '
 
654
                        if ( (pos = QRegExp( "^[0-9]+" ).match( line, 0, &len ) ) < 0 ) return 1;
 
655
                        nolinesA = line.mid(pos, len).toInt();
 
656
 
 
657
// Next lines are commented out because in delete the lines are not here
 
658
// so there is nothing to add but an empty diff and an empty hunk so for
 
659
// now this is omitted. Maybe we could ask the user for the original file
 
660
// so we can indicate the deleted lines.
 
661
 
 
662
//                      DiffHunk* hunk = new DiffHunk( 0, linenoB );
 
663
//                      hunks.append( hunk );
 
664
 
 
665
//                      Difference diff = new Difference( linenoA, 0 );
 
666
//                      diff->type = Difference::Delete;
 
667
 
 
668
                        // We should now add the source lines, unfortunately there are none...
 
669
 
 
670
//                      hunk->add( diff );
 
671
                }
 
672
                else
 
673
                {
 
674
                        kdDebug() << "Oops, something is wrong here..." << endl;
 
675
                        return 1; // faulty output or something went wrong during parsing
 
676
                }
 
677
                ++it;
 
678
        }
 
679
 
 
680
//      KMessageBox::information( 0, i18n( "Sorry not yet implemented" ) );
 
681
//      return 1;
 
682
        return 0;
506
683
};
507
684
 
508
685
/**  */
545
722
                line = (*it);
546
723
 
547
724
                if ( line.find( QRegExp( "^@@ -" ), 0 ) < 0 ) return 1;
 
725
                m_noOfHunks++;
548
726
 
549
727
                // strip off the begin of the hunk header
550
728
                line.replace( QRegExp( "^@@ -" ), "" );