/***************************************************************************** * * Copyright 1996 Puget Sound Power & Light. All rights reserved. * * Module: ot_sort * * Arguments: None. * * Description: This function implements three different sort alogrithms * on the opr table and then records the result in a special * opr2 record which is attached to a rapport formatted display. * * The sort alogrithms are performed in the following sequence: * * 1) The opr_name field is searched for the named strings: * a) "VACANT" * b) 20 spaces (0x20) * Records that match are not recorded in the opr2 record. * * 2) The opr_name field is scanned for any occurance of * the '*' character in any location within the field. * a) The entry is pushed to the bottom of the list within * the opr2 record. * b) A special field (sort_opr2) is flagged true. Rapport * uses this field to change the display color attributes. * * 3) The remaining opr entries are sorted in ascending order * by endstr_pg_opr and then shifted into the opr2 record * from the top down. * * This function was developed at the DMS support facility. * * 02-Jan-1997 - NEW - R. M. St. Andre & J. J. Martin * ****************************************************************************/ static int ot_sort(char *resp_p) { int major_counter, /* general purpose int counters */ minor_counter, /* 2 ea. */ subscript, /* an entry in sorted array from unsorted */ bottom, /* shows bottom of sorted array */ enabled, /* a flag i can set and check */ period, /* period from schedule db to sort */ skip[ TABLESIZE ], /* flags to tell if subscript already sorted */ sorted [ TABLESIZE ], /* buffer of sorted schedule db subscripts */ SCHED_LV, /* saves $lv from schedule db */ max_disp_row; /* last row to display */ float lowest = 9999.99; /* holds current lowest in sort logic */ /* save $lv from opr table (sets height of accum ot report) */ SCHED_LV = schedule.lv$opr; /* get the current ot totals */ period = eot$pg_year[schedule.lv$year - 1] - 1; /* init sorted flags and report size pointers */ for( major_counter=0; major_counter <= SCHED_LV; major_counter++) { skip[major_counter] = 0; sort_opr2[major_counter] = 0x0; } /* init opr2 record */ for( major_counter=0; major_counter <= SCHED_LV; major_counter++) { strcpy( name_opr2[major_counter], " "); strcpy( telehome_opr2[major_counter], " "); strcpy( telecell_opr2[major_counter], " "); strcpy( telealt1_opr2[major_counter], " "); strcpy( telealt2_opr2[major_counter], " "); strcpy( telepage_opr2[major_counter], " "); endstr_opr2[major_counter] = 0.00; sort_opr2[major_counter] = 0x0; } bottom = 0; max_disp_row = 0; /* omit the given named strings from the opr2 record */ for( major_counter=0; major_counter <= SCHED_LV; major_counter++ ) { if( strncmp( name_opr[major_counter], "VACANT", 6 ) == 0 ) { skip[major_counter] = 9; bottom++; } if( strcspn( name_opr[ major_counter], "\0" ) < 20 ) { skip[major_counter] = 9; bottom++; } if( strncmp( name_opr[major_counter], " ", 20 ) == 0 ) { skip[major_counter] = 9; bottom++; } } max_disp_row = bottom; /* push name_opr containing '*' to bottom of list. flag sort_opr2 */ for( major_counter = 0; major_counter <= SCHED_LV; major_counter++) { if( skip[major_counter] != 9) { if( strcspn( name_opr[ major_counter], "*" ) < 20 ) { sort_opr2[SCHED_LV - bottom] = 0x1; sorted[SCHED_LV - bottom]=major_counter; bottom++; skip[ major_counter] = 9; } } } /* sort remaining subsrcripts in ascending order by endstr_pg_opr */ for( major_counter=0; major_counter <= SCHED_LV; major_counter++ ) { lowest=9999.99; /* ensure a lowest is always found */ for( minor_counter=0; minor_counter <= SCHED_LV; minor_counter++ ) { if( skip[minor_counter] != 9 ) { if( endstr_pg_opr[period][minor_counter] <= lowest ) { enabled = 1; lowest = endstr_pg_opr[period][minor_counter]; subscript = minor_counter; } } } /* end minor_counter loop */ if( enabled ) { skip[subscript] = 9; /* already sorted */ sorted[major_counter] = subscript; /* save subscript */ enabled = 0; } }/* end major_counter loop, table sorted. */ /* build ot report in opr2 record */ for( major_counter=0; major_counter <= SCHED_LV-max_disp_row; major_counter++ ) { strncpy(name_opr2[major_counter], name_opr[ sorted[major_counter] ], NAME_OPR$CHAR$SIZE); strncpy(telehome_opr2[major_counter], telehome_opr[ sorted[major_counter] ], TELEHOME_OPR$CHAR$SIZE); strncpy(telecell_opr2[major_counter], telecell_opr[ sorted[major_counter] ], TELECELL_OPR$CHAR$SIZE); strncpy(telealt1_opr2[major_counter], telealt1_opr[ sorted[major_counter] ], TELEALT1_OPR$CHAR$SIZE); strncpy(telealt2_opr2[major_counter], telealt2_opr[ sorted[major_counter] ], TELEALT2_OPR$CHAR$SIZE); strncpy(telepage_opr2[major_counter], telepage_opr[ sorted[major_counter] ], TELEPAGE_OPR$CHAR$SIZE); endstr_opr2[ major_counter] = endstr_pg_opr[period][ sorted[major_counter] ]; } return(TRUE); }/************************** end of sort_ot *********************************/