/* domain.c -- compute the domain of minimality for each ELS */ #include #include "ios.h" /* using the input/output service module */ #define ERR_FIRST_LINE 1 #define ERR_SECOND_LINE 2 #define ERR_DATA_LINE 3 #define ERR_LONG_FAMILY 4 #define ERR_LINE_WRONG 5 #define ERR_HEADER 6 #define MAXRECNO 50 typedef struct { int x, y, z; long pos,sk; } CodeStruct; typedef struct { int x, y, z; long pos, sk, p1,p2, hlim,llim; } FamilyStruct; static CodeStruct InData [MAXRECNO]; static FamilyStruct OutData [MAXRECNO]; static long TextLength; static void BuildFamilyBlock ( FamilyStruct * BlockCreated, CodeStruct * CodesFound, int EndIndex, int WordLen ); static FILE * outfile; void main ( int argc, char * argv [] ) { int WordLength; char * from; int k, n; int x,y,z; long int start; int pitch; CodeStruct * p; FamilyStruct * q; if ( argc < 3 ) err_command_line ( "domain infile outfile" ); open_input_file ( argv [1] ); get_line_sure ( & from ); if ( 2 != sscanf ( from, "%d %ld", &WordLength, &TextLength ) ) { printf ( "wrong first input line\n" ); exit ( ERR_FIRST_LINE ); } outfile = open_output_file ( argv [2] ); fprintf ( outfile, "[ %3d%7ld ]\n", WordLength, TextLength ); get_line_sure ( & from ); if ( '*' != from [0] ) { printf ( "wrong second input line\n" ); exit ( ERR_SECOND_LINE ); } do { if ( 3 != sscanf ( from, "*** %2d %2d %2d", &x, &y, &z ) ) { printf ( "wrong family header (%s)\n", from ); exit ( ERR_HEADER ); } fprintf ( outfile, "[*** %2d %2d %2d ]\n", x, y, z ); k = 0; do { get_line ( & from ); if ( from == NULL ) break; if ( ' ' != from [0] ) break; if ( 2 != sscanf ( from, " %ld %d", &start, &pitch ) ) { printf ( "wrong data line (%s)\n", from ); exit ( ERR_DATA_LINE ); } if ( k >= MAXRECNO ) { printf ( "too long family" ); exit ( ERR_LONG_FAMILY ); } p = & InData [k++]; p->x = x; p->y = y; p->z = z; p->pos = start; p->sk = (long) pitch; } while (1); n = 0; BuildFamilyBlock ( OutData, InData, k-1, WordLength ); for ( n=0; npos, q->sk, q->p1, q->p2, q->llim, q->hlim ); } if ( from == NULL ) exit (0); if ( '*' == from [0] ) continue; printf ( "wrong input line: [%s]\n", from ); exit ( ERR_LINE_WRONG ); } while (1); /* unreachable */ } static void BuildFamilyBlock ( FamilyStruct * BlockCreated, CodeStruct * CodesFound, int EndIndex, int WordLen ) { int BlockSize; int i, j; long p1, p2, p3, p4; CodeStruct * thiscs; FamilyStruct * thispnt, * chkpnt; FamilyStruct * FamilyBlock = BlockCreated; i = 0; BlockSize = 0; while ( i <= EndIndex ) { /* first pass: extensions */ BlockSize++; thiscs = & CodesFound[i]; thispnt = & FamilyBlock [BlockSize - 1]; thispnt->x = thiscs->x; thispnt->y = thiscs->y; thispnt->z = thiscs->z; thispnt->pos = thiscs->pos; thispnt->sk = thiscs->sk; thispnt->p2 = thiscs->pos + (WordLen - 1) * thiscs->sk; if (thiscs->sk >0) thispnt->p1 = thispnt->pos; else { thispnt->p1 = thispnt->p2; thispnt->p2 = thispnt->pos; } i++; } thispnt = FamilyBlock; for (i = 0; i < BlockSize; i++) { /* second pass: domains */ thispnt->llim = 0; thispnt->hlim = TextLength; chkpnt = FamilyBlock; for (j = 0; j < BlockSize; j++) { /* loop on competitors */ if ( labs (chkpnt->sk) < labs (thispnt->sk) ) { p1 = thispnt->p1; p2 = thispnt->p2; p3 = chkpnt->p1; p4 = chkpnt->p2; if ( ( thispnt->llim < p3 ) && ( p3 < p1 ) ) thispnt->llim=p3; if ( ( thispnt->hlim > p4 ) && ( p4 > p2 ) ) thispnt->hlim=p4; if ( ( p4 <= p2 ) && ( p3 >= p1 ) ) { /* internal competitor */ thispnt->llim = p1; thispnt->hlim = p1 + 1; } } chkpnt++; } thispnt++; } } /* end of domain.c */