50 lines
871 B
C
50 lines
871 B
C
|
|
|
||
|
|
|
||
|
|
#include "replacement.h"
|
||
|
|
|
||
|
|
|
||
|
|
void replacement_add( int fromKey, int toKey, char * content, struct array * replacements ) {
|
||
|
|
|
||
|
|
struct replacement * replacementInstance = malloc( sizeof( struct replacement ) );
|
||
|
|
|
||
|
|
replacementInstance->fromIndex = fromKey;
|
||
|
|
|
||
|
|
replacementInstance->toIndex = toKey;
|
||
|
|
|
||
|
|
replacementInstance->content = content;
|
||
|
|
|
||
|
|
array_add( replacements, replacementInstance );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
void replacement_sort( struct array * replacements ) {
|
||
|
|
|
||
|
|
int count = array_length( replacements );
|
||
|
|
|
||
|
|
int i, j;
|
||
|
|
|
||
|
|
void * temp;
|
||
|
|
|
||
|
|
for (i = 0; i < (count - 1); ++i)
|
||
|
|
{
|
||
|
|
for (j = 0; j < count - 1 - i; ++j )
|
||
|
|
{
|
||
|
|
struct replacement * a = array_get( replacements, j );
|
||
|
|
|
||
|
|
struct replacement * b = array_get( replacements, j+1 );
|
||
|
|
|
||
|
|
if ( a->fromIndex > b->fromIndex )
|
||
|
|
{
|
||
|
|
temp = b;
|
||
|
|
|
||
|
|
replacements->items[j+1] = a;
|
||
|
|
|
||
|
|
replacements->items[j] = temp;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|