/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1989-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
#include "update.h"
#include "suftree.h"
/*
** Compute delta commands to transform the source string 'src'
** to the target string 'tar'. Small blockmoves are transformed
** to blockadds for space efficiency.
** Return -1 in case of error.
**
** For details on computing blockmoves, see:
** "The String-to-String Correction Problem with Block Moves"
** W. Tichy, ACM TOCS, v.2, No.4, 1984, pp.309-321.
**
** Written by Kiem-Phong Vo, 5/18/88
*/
/* structure of a delta instruction */
typedef struct _m_
{
} Move;
/* bases of the source and target strings */
/* Data buffer area */
static int Dfd;
{
if(delflush() < 0)
return -1;
return 0;
}
static int delputl(register int n, register long v)
{
register int i;
unsigned char c[4];
for(i = 0; i < n; ++i)
{
c[i] = (unsigned char)(v%BASE);
v /= BASE;
}
for(i = n-1; i >= 0; --i)
if(delputc((char)c[i]) < 0)
return -1;
return 0;
}
{
{
Dnext += n;
}
else
{
if(delflush() < 0)
return -1;
return -1;
}
return 0;
}
/* write an instruction */
{
register char inst;
{
return -1;
}
else
{
return -1;
}
return 0;
}
/* constructor for Move */
{
if(!ip) return 0;
if(last)
{
}
return ip;
}
/* destructor for Move, return the elt after move */
{
if(last)
if(next)
}
/* make a new add command */
{
if(!ip)
return 0;
/* remove small previous adjacent moves */
while(last)
{
break;
break;
}
/* merge with adjacent adds */
{
}
if(last)
{
}
return ip;
}
/* check to see if a move is appropriate */
{
return 0;
/* it's good but it may be better to merge it to an add */
if(a_size > 0)
{
/* it is better to merge! */
return 0;
}
return m_size;
}
/* optimize a sequence of moves */
{
m_cost = 0;
a_cost = 0;
{
break;
/* costs of alternatives */
if(add > 0)
{
}
{
}
/* conversion is bad */
continue;
/* convert the entire sequence to an add */
while(ip != s)
{
}
/* merge adjacent adds */
{
delMove(s);
s = last;
}
{
}
/* done */
break;
}
return s;
}
/* the real thing */
int
{
/* initialize the output area */
/* output file sizes */
return -1;
return -1;
/* bases */
/* initialize list and last block */
moves = 0;
last = 0;
/* try making suffix tree */
{
/* not enough space for tree, remove matching prefix and suffix */
break;
{
{
if(!moves)
return -1;
}
else
{
}
}
break;
{
{
if(!last)
return -1;
}
}
/* try making the tree again */
}
/* compute block moves */
tp = 0;
while(n_tar > 0)
{
char *match;
if(tree)
if(size < 0)
return -1;
if(size > 0)
/* output a block move */
if(size > 0)
{
if(tp)
{
if(!moves)
return -1;
tp = 0;
}
if(!moves)
return -1;
}
else
{
if(!tp)
tar += 1;
n_tar -= 1;
}
}
/* add any remaining blocks */
if(tp)
{
{
}
if(!moves)
return -1;
}
if(last)
{
}
/* release space use for string matching */
if(tree)
/* optimize move instructions */
if(moves)
{
}
/* write out the move instructions */
addr = 0L;
while(moves)
{
return -1;
}
/* write ending token */
delputc((char)DELTA_TYPE);
/* flush buffer */
return delflush();
}