home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 211.lha / Spiff / exact.c < prev    next >
C/C++ Source or Header  |  1996-02-14  |  2KB  |  93 lines

  1. /*                        Copyright (c) 1988 Bellcore
  2. **                            All Rights Reserved
  3. **       Permission is granted to copy or use this program, EXCEPT that it
  4. **       may not be sold for profit, the copyright notice must be reproduced
  5. **       on copies, and credit should be given to Bellcore where it is due.
  6. **       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7. */
  8.  
  9.  
  10. #ifndef lint
  11. static char rcsid[]= "$Header: exact.c,v 1.1 88/09/15 11:33:55 daniel Rel $";
  12. #endif
  13.  
  14. #include "misc.h"
  15. #include "edit.h"
  16.  
  17. /*
  18. **    routine to compare each object with its ordinal twin
  19. */
  20. E_edit
  21. Q_do_exact(size1,size2,max_d,comflags)
  22. int size1;
  23. int size2;
  24. int max_d;
  25. int comflags;
  26. {
  27.     int i = 0;
  28.     int diffcnt = 0;
  29.     int last = Z_MIN(size1,size2);
  30.     int next_edit = 0;
  31.     E_edit last_ptr = E_NULL;
  32.     int start,tmp;
  33.     E_edit *script;
  34.  
  35.     script = Z_ALLOC(max_d+1,E_edit);
  36.  
  37.     if (size1 != size2)
  38.     {
  39.         (void) sprintf(Z_err_buf,"unequal number of tokens, %d and %d respectively\n",size1,size2);
  40.         Z_complain(Z_err_buf);
  41.     }
  42.  
  43.     do
  44.     {
  45.         /*
  46.         **    skip identical objects
  47.         */
  48.         while (i<last && (!X_com(i,i,comflags)))
  49.         {
  50.             i++;
  51.         }
  52.         start = i;
  53.         /*
  54.         **    see how many difference we have in a row
  55.         */
  56.         while (i<last && X_com(i,i,comflags))
  57.         {
  58.             if ((diffcnt += 2) >= max_d+1)
  59.                 Z_exceed(max_d);
  60.             i++;
  61.         }
  62.         /*
  63.         **    build the list of deletions
  64.         */
  65.         for(tmp=start;tmp<i;tmp++,next_edit++)
  66.         {
  67.             script[next_edit] = E_edit_alloc();
  68.             E_setnext(script[next_edit],last_ptr);
  69.             last_ptr = script[next_edit];
  70.  
  71.             E_setop(script[next_edit],E_DELETE);
  72.             E_setl1(script[next_edit],tmp+1);
  73.             /* no need to set line2, it is never used */
  74.             E_setl2(script[next_edit],0);
  75.         }
  76.         /*
  77.         **    build the list of insertions
  78.         */
  79.         for(tmp=start;tmp<i;tmp++,next_edit++)
  80.         {
  81.             script[next_edit] = E_edit_alloc();
  82.             E_setnext(script[next_edit],last_ptr);
  83.             last_ptr = script[next_edit];
  84.  
  85.             E_setop(script[next_edit],E_INSERT);
  86.             E_setl1(script[next_edit],i);
  87.             E_setl2(script[next_edit],tmp+1);
  88.         }
  89.     } while (i<last);
  90.  
  91.     return(last_ptr);
  92. }
  93.