static char const rcsid [] = "$Id: maps_text.c,v 1.1 1998/04/22 10:22:46 stojanov Exp $"; /*****************************************************************************/ /* */ /* Unit: MAPS_TEXT (Unit for the formating and output of plain text) */ /* */ /* Author: Nikola Stojanovic */ /* */ /* Revision: 15 APR 98 */ /* */ /* Unit contains code which creates and displays plain text output of the */ /* alignment based on the prepared structures */ /* */ /*****************************************************************************/ #include #include #include #include "maps.h" #include "maps_vars.h" /*****************************************************************************/ /* */ /* Unit local procedures - not callable from outside (forward declarations) */ /* */ /*****************************************************************************/ void TEXT_Initialize (void); /*****************************************************************************/ /* */ /* Unit static variables - module level globals */ /* */ /*****************************************************************************/ /*****************************************************************************/ /* */ /* Procedure: TEXT_Initialize */ /* */ /* Initialization of module internal data structures */ void TEXT_Initialize (void) { /* ---------- */ } /*****************************************************************************/ /* */ /* Procedure: TEXT_Show */ /* */ /* Unified procedure for the display of the alignment text and annotations */ void TEXT_Show (void) { bool banner_set, completely_blank, empty_count; char *count_vector, banner_string [10], num_string [10]; int scanner, index, backup_offset, num_pos; long int position, save_pos; TEXT_Initialize (); printf ("\n"); /* One blank line before starting the output */ /* Determine first if any of the text lines requested banner - set flag */ banner_set = FALSE; for (index = 0; index < display_size; index++) { if ((display_vector [index]) -> kind == TEXT_CODE) { if ((display_vector [index]) -> banner != 0) banner_set = TRUE; } } count_vector = (char *) NTL0_ckalloc ((page_width + 7) * sizeof (char)); for (scanner = 0; scanner < page_width + 6; scanner++) count_vector [scanner] = ' '; count_vector [page_width + 6] = '\0'; /* Determine whether the description block is needed in output - print */ if (description_include == DESCRIPTION) printf ("%s\n\n", file_data -> description); /* Continue output block by block, until entire buffers length is exhausted */ position = 0; while (position < alignment_records -> size) { save_pos = position; /* Assure loop affects position only once */ for (index = 0; index < display_size; index++) { position = save_pos; /* Reset position before each buffer */ if (banner_set) { /* There is banner, fixed to 9 characters */ if ((display_vector [index]) -> kind == TEXT_CODE) { if ((display_vector [index]) -> banner != 0) sprintf (banner_string, "%6ld: ", (display_vector [index]) -> banner); else sprintf (banner_string, " "); } else sprintf (banner_string, " "); } else banner_string [0] = '\0'; /* No banner to appear in the output */ /* Examine the line - if it is completely blank, don't print it */ completely_blank = TRUE; if ((display_vector [index]) -> kind == COUNTER_CODE) { for (scanner = 0; (scanner < page_width) && (position + scanner < alignment_records -> size); scanner++) { if (((display_vector [index]) -> counts) [position + scanner] != 0) completely_blank = FALSE; } } else { /* Either text or description line */ for (scanner = 0; (scanner < page_width) && (position + scanner < alignment_records -> size); scanner++) { if (((display_vector [index]) -> buffer) [position + scanner] != ' ') completely_blank = FALSE; } } if (!completely_blank) { switch ((display_vector [index]) -> kind) { case COUNTER_CODE: { /* Clean the counter vector with all blanks - prepare for next line */ for (scanner = 0; scanner < page_width + 6; scanner++) count_vector [scanner] = ' '; /* Proceed to locate the positions of counts and convert them into */ /* printed numbers in the text buffer */ for (scanner = 0; (scanner < page_width) && (position + scanner < alignment_records -> size); scanner++) { if (((display_vector [index]) -> counts) [position + scanner] != 0) { if (((display_vector [index]) -> counts) [position + scanner] < -99999) backup_offset = 6; else if (((display_vector [index]) -> counts) [position + scanner] < -9999) backup_offset = 5; else if (((display_vector [index]) -> counts) [position + scanner] < -999) backup_offset = 4; else if (((display_vector [index]) -> counts) [position + scanner] < -99) backup_offset = 3; else if (((display_vector [index]) -> counts) [position + scanner] < -9) backup_offset = 2; else if (((display_vector [index]) -> counts) [position + scanner] < 0) backup_offset = 1; else if (((display_vector [index]) -> counts) [position + scanner] < 10) backup_offset = 0; else if (((display_vector [index]) -> counts) [position + scanner] < 100) backup_offset = 1; else if (((display_vector [index]) -> counts) [position + scanner] < 1000) backup_offset = 2; else if (((display_vector [index]) -> counts) [position + scanner] < 10000) backup_offset = 3; else if (((display_vector [index]) -> counts) [position + scanner] < 100000) backup_offset = 4; else backup_offset = 5; /* Examine if this number can be shown within the margins & display */ if ((strlen (banner_string) >= backup_offset) || (scanner - backup_offset >= 6)) { if (((display_vector [index]) -> counts) [position + scanner] < 0) { count_vector [6 + scanner - backup_offset] = '-'; sprintf (num_string, "%ld", - ((display_vector [index]) -> counts) [position + scanner]); num_pos = 0; while (num_string [num_pos] == ' ') num_pos++; while (backup_offset > 0) { count_vector [scanner - backup_offset + 7] = num_string [num_pos]; backup_offset--; num_pos++; } } else { /* Number to be placed is positive */ sprintf (num_string, "%ld", ((display_vector [index]) -> counts) [position + scanner]); num_pos = 0; while (num_string [num_pos] == ' ') num_pos++; while (backup_offset >= 0) { count_vector [6 + scanner - backup_offset] = num_string [num_pos]; backup_offset--; num_pos++; } } } } } /* Examine if there is anything in the buffer to be put in the line */ empty_count = TRUE; for (scanner = 0; scanner < page_width + 6; scanner++) if (count_vector [scanner] != ' ') empty_count = FALSE; if (!empty_count) { if (strlen (banner_string) == 0) { for (scanner = 6; scanner < page_width + 6; scanner++) printf ("%c", count_vector [scanner]); } else { /* There is margin space for the banner */ printf (" "); for (scanner = 0; scanner < page_width + 6; scanner++) printf ("%c", count_vector [scanner]); } } printf ("\n"); position += page_width; break; } case TICKMARK_CODE: { printf ("%s", banner_string); for (scanner = 0; (scanner < page_width) && (position < alignment_records -> size); scanner++) { printf ("%c", ((display_vector [index]) -> buffer) [position]); position++; } printf ("\n"); break; } case DESCRIPTION_CODE: { printf ("%s", banner_string); for (scanner = 0; (scanner < page_width) && (position < alignment_records -> size); scanner++) { printf ("%c", ((display_vector [index]) -> buffer) [position]); position++; } printf ("\n"); break; } case TEXT_CODE: { printf ("%s", banner_string); for (scanner = 0; (scanner < page_width) && (position < alignment_records -> size); scanner++) { printf ("%c", ((display_vector [index]) -> buffer) [position]); if ((((display_vector [index]) -> buffer) [position] != GAP_SYMBOL) && (((display_vector [index]) -> buffer) [position] != ' ')) { if ((display_vector [index]) -> banner != 0) { ((display_vector [index]) -> banner)++; if ((display_vector [index]) -> banner == 0) ((display_vector [index]) -> banner)++; } } position++; } if ((display_vector [index]) -> trailer != NULL) { if (scanner < page_width) { while (scanner < page_width) { printf (" "); scanner++; } } printf (" %s", (display_vector [index]) -> trailer); } printf ("\n"); break; } default: CONT_Error_Report (SYSTEM_ERROR, ERR_ILLEGAL_CODE, "Unknown code for a display buffer", NULL, UNDEFINED, NULL, 0, FALSE); } } else position += page_width; } /* Now the whole block is done, output as many breaklines as needed */ if (position < alignment_records -> size) for (index = 0; index < block_spacing; index++) printf ("\n"); } /* Output done, make just another blank line at the end */ printf ("\n"); }