Subversion Repositories svn1

Rev

Rev 315 | Rev 359 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 315 Rev 357
Line 86... Line 86...
86
    "Eleventh"
86
    "Eleventh"
87
};
87
};
88
 
88
 
89
int         sort_leg;
89
int         sort_leg;
90
int         sort_mode;
90
int         sort_mode;
-
 
91
bool        sort_withEquestrian;
91
report_type report_html = text;
92
report_type report_html = text;
92
bool        report_all = FALSE;
93
bool        report_all = FALSE;
93
 
94
 
94
/* Parameters used by the sort routine to govern its actions */
95
/* Parameters used by the sort routine to govern its actions */
95
 
96
 
Line 101... Line 102...
101
#define S_TEAM  6                                /* Sort on team order */
102
#define S_TEAM  6                                /* Sort on team order */
102
#define S_CLASS 7                                /* Sort on class/team order */
103
#define S_CLASS 7                                /* Sort on class/team order */
103
#define S_LC_NE 8                                /* Elapsed times per class, with NE sorted by real class */
104
#define S_LC_NE 8                                /* Elapsed times per class, with NE sorted by real class */
104
#define S_IFIN  9                                /* Sort on elapsed time at given leg */
105
#define S_IFIN  9                                /* Sort on elapsed time at given leg */
105
 
106
 
-
 
107
 
106
/*
108
/*
107
**  Various checking modes
109
**  Various checking modes
108
*/
110
*/
109
#define C_ELAPSED   1                            /* Check elapsed times */
111
#define C_ELAPSED   1                            /* Check elapsed times */
110
#define C_END       2                            /* Check end times */
112
#define C_END       2                            /* Check end times */
Line 365... Line 367...
365
     * Sort the data in finishing order 
367
     * Sort the data in finishing order 
366
     */
368
     */
367
 
369
 
368
    if( ck_data( leg, C_END ) )
370
    if( ck_data( leg, C_END ) )
369
        return;                                  /* Check data for this leg */
371
        return;                                  /* Check data for this leg */
370
    sort_team_data( leg, S_FIN );                /* Sort the data */
372
    sort_team_data( leg, S_FIN, true );         /* Sort the data */
371
 
373
 
372
 
374
 
373
    /*
375
    /*
374
     * Now print the data on the printer 
376
     * Now print the data on the printer 
375
     */
377
     */
Line 551... Line 553...
551
     * Sort the data in finishing order
553
     * Sort the data in finishing order
552
     */
554
     */
553
 
555
 
554
    if( ck_data( leg, C_ELAPSED ) )
556
    if( ck_data( leg, C_ELAPSED ) )
555
        return;                                  /* Check data for this leg */
557
        return;                                  /* Check data for this leg */
556
    sort_team_data( leg, S_IFIN );               /* Sort the data on elapsed time */
558
    sort_team_data( leg, S_IFIN, true );               /* Sort the data on elapsed time */
557
 
559
 
558
 
560
 
559
    /*
561
    /*
560
     * Now print the data on the printer
562
     * Now print the data on the printer
561
     */
563
     */
Line 767... Line 769...
767
    unsigned    i;
769
    unsigned    i;
768
    int         j, last_class;
770
    int         j, last_class;
769
    char        *report_title;
771
    char        *report_title;
770
    bool        class_done[MAX_CLASS+1];
772
    bool        class_done[MAX_CLASS+1];
771
    int         lcount;
773
    int         lcount;
-
 
774
    bool        isNeClass = false;
-
 
775
    int         place;
-
 
776
 
772
 
777
 
773
    if( ck_data( -1, C_ELAPSED ) )
778
    if( ck_data( -1, C_ELAPSED ) )
774
        return;
779
        return;
775
    /*
780
    /*
776
    **  Sort on every thing
781
    **  Sort on every thing
Line 789... Line 794...
789
     * Print out the data 
794
     * Print out the data 
790
     */
795
     */
791
    print_class_header( -1, TRUE );                      /* Print the header */
796
    print_class_header( -1, TRUE );                      /* Print the header */
792
 
797
 
793
    ptr = sort_data;
798
    ptr = sort_data;
794
    sort_team_data( 0, S_L );                     /* Re-sort on elapsed time */
799
    sort_team_data( 0, S_L, true );                     /* Re-sort on elapsed time */
795
    lcount = 0;
800
    lcount = 0;
796
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
801
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
797
    {
802
    {
798
        if ( ptr->teamclass == config.nonequestrian_class )
803
        if ( ptr->teamclass == config.nonequestrian_class )
799
            continue;
804
            continue;
800
 
805
 
801
        g_record( ptr->team, &team_buf );
806
        g_record( ptr->team, &team_buf );
802
 
807
 
803
        /*
808
        /*
-
 
809
        ** If this is a NE team then dummy up some of the data that hasn't been stored in team_buf
-
 
810
        */
-
 
811
        if (ptr->flags.non_equestrian)
-
 
812
        {
-
 
813
            team_buf.leg[0].l_place = sort_aux[ptr->team].leq_place[0];
-
 
814
            team_buf.leg[0].lc_place = sort_aux[ptr->team].lq_place[0];;
-
 
815
        }
-
 
816
 
-
 
817
        /*
804
        **  If printing an HTML report then we need to mark
818
        **  If printing an HTML report then we need to mark
805
        **  the entry with a reference so that we can link to it
819
        **  the entry with a reference so that we can link to it
806
        */
820
        */
807
        if ( report_html == html )
821
        if ( report_html == html )
808
        {
822
        {
Line 814... Line 828...
814
        **      - Place within complete field
828
        **      - Place within complete field
815
        **      - Team number - with HTML reference to team file
829
        **      - Team number - with HTML reference to team file
816
        **      - Class
830
        **      - Class
817
        */
831
        */
818
        if ( report_html == printed && lcount %5 == 4 ) print_underline( TRUE );
832
        if ( report_html == printed && lcount %5 == 4 ) print_underline( TRUE );
819
        print( "%4.4s ", pr_place( team_buf.leg[0].l_place, ptr->flags.bad_times || ptr->flags.non_equestrian ) );
833
        print( "%4.4s ", pn_place( team_buf.leg[0].l_place, ptr->flags.bad_times, ptr->flags.non_equestrian ) );
820
        if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "name" ,"html")), team_buf.numb );
834
        if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "name" ,"html")), team_buf.numb );
821
        print( "%4d",  team_buf.numb );
835
        print( "%4d",  team_buf.numb );
822
        if ( report_html == html ) print( "</A>" );
836
        if ( report_html == html ) print( "</A>" );
823
 
837
 
824
        print( " %-*s", 3, team_buf.teamclass == 0 ? "" : config.team_class[team_buf.teamclass - 1].abr );
838
        print( " %-*s", 3, team_buf.teamclass == 0 ? "" : config.team_class[team_buf.teamclass - 1].abr );
Line 829... Line 843...
829
        **      - Leg place
843
        **      - Leg place
830
        **      - End place
844
        **      - End place
831
        */
845
        */
832
        for( j = 1; j <= config.num_legs; j++ )
846
        for( j = 1; j <= config.num_legs; j++ )
833
        {
847
        {
-
 
848
            bool isEquestrianLeg = (j == config.equestrian_leg && team_buf.flags.non_equestrian);
-
 
849
            bool afterEquestrianLeg = (team_buf.flags.non_equestrian && j > config.equestrian_leg);
834
            /*
850
            /*
835
            **  Ensure that non-equestrian leg data is not displayed
851
            **  Ensure that non-equestrian leg data is not displayed
836
            */
852
            */
837
            if ( j == config.equestrian_leg && team_buf.flags.non_equestrian )
853
            if ( isEquestrianLeg )
838
            {
854
            {
839
                print( "  %-8s %4.4s %4.4s", "-- NE --", "NE","NE");
855
                print( "  %-8s %4.4s %4.4s", "-- NE --", "NE","NE");
840
            }
856
            }
841
            else
857
            else
842
            {
858
            {
843
                print( "  %-8s %4.4s %4.4s",
859
                print( "  %-8s %4.4s %4.4s",
844
                    time_a( team_buf.leg[j].elapsed ),
860
                    time_a( team_buf.leg[j].elapsed ),
845
                    pr_place( team_buf.leg[j].l_place, ptr->flags.bad_times || ptr->flags.non_equestrian ),
861
                    pr_place( team_buf.leg[j].l_place, ptr->flags.bad_times ),
846
                    pr_place( team_buf.leg[j].le_place,ptr->flags.bad_times || ptr->flags.non_equestrian )
862
                    pn_place( team_buf.leg[j].le_place,ptr->flags.bad_times, afterEquestrianLeg )
847
                  );
863
                  );
848
            }
864
            }
849
        }
865
        }
850
 
866
 
851
       /*
867
       /*
Line 855... Line 871...
855
        */
871
        */
856
//        print( "  %-8s ",  time_a( team_buf.leg[0].elapsed ) );
872
//        print( "  %-8s ",  time_a( team_buf.leg[0].elapsed ) );
857
        print( "  %-8s ", time_a( ptr->lege[0] ) );
873
        print( "  %-8s ", time_a( ptr->lege[0] ) );
858
        
874
        
859
        if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">",url_encode(p_filename(filebase, config.team_class[team_buf.teamclass - 1].abr ,"html")), team_buf.numb );
875
        if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">",url_encode(p_filename(filebase, config.team_class[team_buf.teamclass - 1].abr ,"html")), team_buf.numb );
860
        print( "%-4.4s", pr_place( team_buf.leg[0].lc_place, ptr->flags.bad_times ) );
876
        print( "%-4.4s", pn_place( team_buf.leg[0].lc_place, ptr->flags.bad_times, ptr->flags.non_equestrian && 0 ) );
861
        if ( report_html == html ) print( "</A>" );
877
        if ( report_html == html ) print( "</A>" );
862
        if ( report_html == printed && lcount %5 == 4 ) print_underline( FALSE );
878
        if ( report_html == printed && lcount %5 == 4 ) print_underline( FALSE );
863
        lcount++;
879
        lcount++;
864
        print( "\n" );
880
        print( "\n" );
865
    }
881
    }
Line 871... Line 887...
871
    /*
887
    /*
872
     * Now produce a breakdown on a class by class basis 
888
     * Now produce a breakdown on a class by class basis 
873
     * Now print out the class placement information
889
     * Now print out the class placement information
874
     */
890
     */
875
 
891
 
876
    sort_team_data( 0, S_LC );                 /* Generate class placement data */
892
    sort_team_data( 0, S_LC, true );           /* Generate class placement data */
877
    last_class = -1;                           /* Invalid class to start with */
893
    last_class = -1;                           /* Invalid class to start with */
878
    memset ( class_done, 0, sizeof(class_done));
894
    memset ( class_done, 0, sizeof(class_done));
879
 
895
 
880
 
896
    place = 1;
881
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
897
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
882
    {
898
    {
883
        int flags = 0;
899
        int flags = 0;
-
 
900
        bool eflags;
884
 
901
 
885
        /*
902
        /*
886
        **  Detect a change in the "class"
903
        **  Detect a change in the "class"
887
        **  All data is within the one array of data
904
        **  All data is within the one array of data
888
        **  Use the in-memory class as this MAY differ from that stored
905
        **  Use the in-memory class as this MAY differ from that stored
Line 895... Line 912...
895
                print_class_stats( last_class, TRUE );
912
                print_class_stats( last_class, TRUE );
896
                print_legend( last_class, 1 );
913
                print_legend( last_class, 1 );
897
                close_printer();
914
                close_printer();
898
            }
915
            }
899
 
916
 
-
 
917
            /*
-
 
918
            ** Determine if this is the crazy dummy Non-equestrian class
-
 
919
            */
-
 
920
            isNeClass = (ptr->teamclass == config.nonequestrian_class );
-
 
921
            place = 1;
-
 
922
 
900
            report_title = tprintf( "Category results for : %-*s", LEN_CLASS_NAME, ptr->teamclass == 0 ? "" : config.team_class[ptr->teamclass - 1].full_name );
923
            report_title = tprintf( "Category results for : %-*s", LEN_CLASS_NAME, ptr->teamclass == 0 ? "" : config.team_class[ptr->teamclass - 1].full_name );
901
 
924
 
902
            if( !open_printer( "", config.team_class[ptr->teamclass - 1].abr, 132, report_html, report_title ) )
925
            if( !open_printer( "", config.team_class[ptr->teamclass - 1].abr, 132, report_html, report_title ) )
903
                continue;
926
                continue;
904
            print_class_header( last_class = ptr->teamclass, TRUE );
927
            print_class_header( last_class = ptr->teamclass, TRUE );
Line 913... Line 936...
913
        /*
936
        /*
914
        **  Now read in the team record
937
        **  Now read in the team record
915
        */
938
        */
916
        g_record( ptr->team, &team_buf );
939
        g_record( ptr->team, &team_buf );
917
        flags = ptr->flags.bad_times;
940
        flags = ptr->flags.bad_times;
918
        if ( ptr->teamclass != config.nonequestrian_class )
941
        eflags = (ptr->teamclass != config.nonequestrian_class && ptr->flags.non_equestrian);
-
 
942
 
-
 
943
        /*
-
 
944
        ** Dummy up the data for the dummy nonEquestrian Class
-
 
945
        ** Its not stored in the team_buf for backwards compatability
-
 
946
        */
-
 
947
        if( isNeClass)
919
        {
948
        {
-
 
949
            for( j = 0; j <= config.num_legs; j++ )
-
 
950
            {
-
 
951
                team_buf.leg[j].lc_place = sort_aux[ptr->team].lq_place[j];
-
 
952
                team_buf.leg[j].lec_place = sort_aux[ptr->team].leq_place[j];;
-
 
953
            }
-
 
954
        }
-
 
955
        else
-
 
956
        {
920
            flags |= ptr->flags.non_equestrian;
957
            if (ptr->flags.non_equestrian)
-
 
958
            {
-
 
959
                team_buf.leg[0].lc_place =  place++; //sort_aux[ptr->team].lq_place[0];
-
 
960
                team_buf.leg[0].lec_place = sort_aux[ptr->team].leq_place[0];
-
 
961
                eflags = false;
-
 
962
            }
921
        }
963
        }
922
 
964
 
-
 
965
 
923
        /*
966
        /*
924
        **  If printing an HTML report then we need to mark
967
        **  If printing an HTML report then we need to mark
925
        **  the entry with a reference so that we can link to it
968
        **  the entry with a reference so that we can link to it
926
        */
969
        */
927
        if ( report_html == html )
970
        if ( report_html == html )
Line 933... Line 976...
933
        **      - Team number - with HTML reference to team file
976
        **      - Team number - with HTML reference to team file
934
        **      - Class
977
        **      - Class
935
        */
978
        */
936
 
979
 
937
        if ( report_html == printed && lcount %5 == 4 ) print_underline( TRUE );
980
        if ( report_html == printed && lcount %5 == 4 ) print_underline( TRUE );
938
        print( "%4.4s ", pr_place( team_buf.leg[0].lc_place, flags ) );
981
        print( "%4.4s ", pn_place( team_buf.leg[0].lc_place, flags , eflags ) );
939
        if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "name" ,"html")), team_buf.numb );
982
        if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "name" ,"html")), team_buf.numb );
940
        print( "%4d",  team_buf.numb );
983
        print( "%4d",  team_buf.numb );
941
        if ( report_html == html ) print( "</A>" );
984
        if ( report_html == html ) print( "</A>" );
942
        print( " %-*s", 3, team_buf.teamclass == 0 ? "" : config.team_class[team_buf.teamclass - 1].abr );
985
        print( " %-*s", 3, team_buf.teamclass == 0 ? "" : config.team_class[team_buf.teamclass - 1].abr );
943
 
986
 
944
        for( j = 1; j <= config.num_legs; j++ )
987
        for( j = 1; j <= config.num_legs; j++ )
945
        {
988
        {
-
 
989
            bool isEquestrianLeg = (j == config.equestrian_leg && (ptr->teamclass == config.nonequestrian_class || ptr->flags.non_equestrian));
-
 
990
            bool afterEquestrianLeg = ((ptr->teamclass == config.nonequestrian_class || ptr->flags.non_equestrian) && j > config.equestrian_leg);
-
 
991
 
946
            /*
992
            /*
947
            **  Ensure that non-equestrian leg data is not displayed
993
            **  Ensure that non-equestrian leg data is not displayed
948
            */
994
            */
949
            if ( j == config.equestrian_leg && (ptr->teamclass == config.nonequestrian_class || ptr->flags.non_equestrian) )
995
            if ( isEquestrianLeg )
950
            {
996
            {
951
                print( "  %-8s %4.4s %4.4s", "-- NE --", "NE","NE");
997
                print( "  %-8s %4.4s %4.4s", "-- NE --", "NE","NE");
952
            }
998
            }
953
            else
999
            else
954
            {
1000
            {
955
                print( "  %-8s %4.4s %4.4s", time_a( team_buf.leg[j].elapsed ),
1001
                print( "  %-8s %4.4s %4.4s", time_a( team_buf.leg[j].elapsed ),
956
                       pr_place( team_buf.leg[j].lc_place,  flags ),
1002
                       pr_place( team_buf.leg[j].lc_place,  flags ),
957
                       pr_place( team_buf.leg[j].lec_place, flags ) );
1003
                       pn_place( team_buf.leg[j].lec_place, flags, afterEquestrianLeg ) );
958
            }
1004
            }
959
        }
1005
        }
960
 
1006
 
961
        /*
1007
        /*
962
        **  Print the trailer
1008
        **  Print the trailer
Line 965... Line 1011...
965
        */
1011
        */
966
        /* print( "  %-8s ", time_a( team_buf.leg[0].elapsed ) ); */
1012
        /* print( "  %-8s ", time_a( team_buf.leg[0].elapsed ) ); */
967
        print( "  %-8s ", time_a( ptr->lege[0] ) );
1013
        print( "  %-8s ", time_a( ptr->lege[0] ) );
968
 
1014
 
969
        if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "finish" ,"html")), team_buf.numb );
1015
        if ( report_html == html ) print( "<A HREF=\"%s#Team_%04d\">", url_encode(p_filename(filebase, "finish" ,"html")), team_buf.numb );
970
        print( "%4.4s", pr_place( team_buf.leg[0].l_place, flags || (ptr->teamclass == config.nonequestrian_class)));
1016
        print( "%4.4s", pn_place( team_buf.leg[0].l_place, flags , ptr->flags.non_equestrian));
971
        if ( report_html == html ) print( "</A>" );
1017
        if ( report_html == html ) print( "</A>" );
972
 
1018
 
973
        if ( report_html == printed && lcount %5 == 4 ) print_underline( FALSE );
1019
        if ( report_html == printed && lcount %5 == 4 ) print_underline( FALSE );
974
        lcount++;
1020
        lcount++;
975
        print( "\n" );
1021
        print( "\n" );
Line 1234... Line 1280...
1234
    if ( report_html == html ) print( "</A>" );
1280
    if ( report_html == html ) print( "</A>" );
1235
 
1281
 
1236
    /*
1282
    /*
1237
    **  Sort the data by class
1283
    **  Sort the data by class
1238
    */
1284
    */
1239
    sort_team_data( 0, S_LC );     /* Generate class placement data */
1285
    sort_team_data( 0, S_LC, true );     /* Generate class placement data */
1240
    last_class = -1;                /* Invalid class to start with */
1286
    last_class = -1;                /* Invalid class to start with */
1241
 
1287
 
1242
    /*
1288
    /*
1243
    **  Process each category
1289
    **  Process each category
1244
    */
1290
    */
Line 1403... Line 1449...
1403
        header_done = false;
1449
        header_done = false;
1404
 
1450
 
1405
        /*
1451
        /*
1406
        **  Sort the data by class with NE data sorted by real class
1452
        **  Sort the data by class with NE data sorted by real class
1407
        */
1453
        */
1408
        sort_team_data( 0, S_LC_NE );      /* Generate class placement data */
1454
        sort_team_data( 0, S_LC_NE, true );      /* Generate class placement data */
1409
        last_class = -1;                   /* Invalid class to start with */
1455
        last_class = -1;                   /* Invalid class to start with */
1410
 
1456
 
1411
        /*
1457
        /*
1412
        **  Only process the Non Equestrian teams in this pass
1458
        **  Only process the Non Equestrian teams in this pass
1413
        */
1459
        */
Line 1796... Line 1842...
1796
     * Print out the data 
1842
     * Print out the data 
1797
     */
1843
     */
1798
    print_class_header( -1, FALSE );                     /* Print the header */
1844
    print_class_header( -1, FALSE );                     /* Print the header */
1799
 
1845
 
1800
    ptr = sort_data;
1846
    ptr = sort_data;
1801
    sort_team_data( 0, S_TEAM );                   /* Re-sort on team number */
1847
    sort_team_data( 0, S_TEAM, true );                   /* Re-sort on team number */
1802
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1848
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1803
    {
1849
    {
1804
        if ( ptr->teamclass == config.nonequestrian_class )
1850
        if ( ptr->teamclass == config.nonequestrian_class )
1805
            continue;
1851
            continue;
1806
 
1852
 
Line 1838... Line 1884...
1838
    /*
1884
    /*
1839
     * Now produce a breakdown on a class by class basis 
1885
     * Now produce a breakdown on a class by class basis 
1840
     * Now print out the class placement information
1886
     * Now print out the class placement information
1841
     */
1887
     */
1842
 
1888
 
1843
    sort_team_data( 0, S_CLASS );              /* Generate class placement data */
1889
    sort_team_data( 0, S_CLASS, true );              /* Generate class placement data */
1844
    last_class = -1;                             /* Invalid class to start with */
1890
    last_class = -1;                             /* Invalid class to start with */
1845
 
1891
 
1846
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1892
    for( ptr = sort_data, i = 0; i < sort_num; i++, ptr++ )
1847
    {
1893
    {
1848
        /*
1894
        /*
Line 2494... Line 2540...
2494
 
2540
 
2495
}
2541
}
2496
 
2542
 
2497
/*========================================================================
2543
/*========================================================================
2498
 *
2544
 *
-
 
2545
 *  Return place data or NE flag
-
 
2546
 *
-
 
2547
 *  Purpose:
-
 
2548
 *      This function is called to Return place data
-
 
2549
 *
-
 
2550
 *      This routine is called to fill a print team_buffer - to allow for
-
 
2551
 *      multiple calls to this function ( before the data is used ) a number
-
 
2552
 *      of static team_buffers are maintained
-
 
2553
 *
-
 
2554
 *  Parameters:
-
 
2555
 *      num         place - if not bad_times
-
 
2556
 *      disq        Disqualified flag
-
 
2557
 *      flag        Flag NE data
-
 
2558
 *
-
 
2559
 *  Returns:
-
 
2560
 *      This function returns a pointer to the character string for the
-
 
2561
 *      number or a pointer to a bad_times string.
-
 
2562
 *
-
 
2563
 *========================================================================*/
-
 
2564
const char *pn_place( int num, int disq, bool flag )
-
 
2565
{
-
 
2566
    static char store[2][5];                     /* 2 stores for 4 digit numbers */
-
 
2567
    static int  i = 0;                           /* Current index into store */
-
 
2568
    static const char *dis = "U";
-
 
2569
    static const char *alt = "NE";
-
 
2570
 
-
 
2571
    if( disq )
-
 
2572
        return ( dis );
-
 
2573
    if (flag)
-
 
2574
        return ( alt );
-
 
2575
 
-
 
2576
    i++;
-
 
2577
    if( i >= 2 )
-
 
2578
        i = 0;                                   /* Select next entry */
-
 
2579
    sprintf( store[i], "%4d", num );
-
 
2580
    return ( store[i] );
-
 
2581
 
-
 
2582
}
-
 
2583
 
-
 
2584
/*========================================================================
-
 
2585
 *
2499
 *  Check data for bad times
2586
 *  Check data for bad times
2500
 *
2587
 *
2501
 *  Purpose:
2588
 *  Purpose:
2502
 *      This function is called to Check data for bad times
2589
 *      This function is called to Check data for bad times
2503
 *      Scan the sort data structure and locate entries that have incorrect
2590
 *      Scan the sort data structure and locate entries that have incorrect
Line 2841... Line 2928...
2841
 *
2928
 *
2842
 *========================================================================*/
2929
 *========================================================================*/
2843
 
2930
 
2844
void do_big_sort(void)
2931
void do_big_sort(void)
2845
{
2932
{
2846
    int         i, k;                            /* Looooopy things */
2933
    int         i, k, q;                             /* Looooopy things */
2847
    unsigned    j;
2934
    unsigned    j;
2848
    ty_s_data  *ptr;                             /* Pointer to sort data */
2935
    ty_s_data  *ptr;                                 /* Pointer to sort data */
2849
    int         teamclass;                           /* Current class */
2936
    int         teamclass;                           /* Current class */
-
 
2937
    int         teamclassq;                          /* Current class */
2850
    team_type   team_buf;
2938
    team_type   team_buf;
2851
 
2939
 
2852
    for( i = 0; i <= config.num_legs; i++ )
2940
    for( i = 0; i <= config.num_legs; i++ )
2853
    {
2941
    {
-
 
2942
        bool sortWithEq =  (i == 0);
-
 
2943
 
2854
        /*
2944
        /*
2855
        **  Sort on leg elapsed time
2945
        **  Sort on leg elapsed time
2856
        **  Then save the teams elapsed place in each leg
2946
        **  Then save the teams elapsed place in each leg
2857
        */
2947
        */
2858
        sort_team_data( i, S_L );
2948
        sort_team_data( i, S_L, sortWithEq );
2859
        for( j = 1, k = 1, ptr = sort_data; j <= sort_num; ptr++, j++ )
2949
        for( j = 1, k = 1, q = 1, ptr = sort_data; j <= sort_num; ptr++, j++ )
2860
        {
2950
        {
2861
            if ( ptr->teamclass == config.nonequestrian_class )
-
 
2862
                continue;
-
 
2863
            
-
 
2864
            sort_aux[ptr->team].l_place[i] = k++;
-
 
2865
            sort_aux[ptr->team].team = ptr->team;
2951
            sort_aux[ptr->team].team = ptr->team;
-
 
2952
 
-
 
2953
            if (ptr->isNeData) {
-
 
2954
                sort_aux[ptr->team].lq_place[i] = q++;
-
 
2955
            } else {
-
 
2956
                sort_aux[ptr->team].l_place[i] = k++;
-
 
2957
            }
2866
        }
2958
        }
2867
 
2959
 
2868
        /*
2960
        /*
2869
        **  Sort on leg end time
2961
        **  Sort on leg end time
2870
        **  Then save the teams place at the end of each leg
2962
        **  Then save the teams place at the end of each leg
2871
        */
2963
        */
2872
        sort_team_data( i, S_LE );
2964
        sort_team_data( i, S_LE, sortWithEq);
2873
        for( j = 1, k = 1, ptr = sort_data; j <= sort_num; ptr++, j++ )
2965
        for( j = 1, k = 1, q = 1, ptr = sort_data; j <= sort_num; ptr++, j++ )
2874
        {
2966
        {
2875
            if ( ptr->teamclass == config.nonequestrian_class )
2967
            if (ptr->isNeData) {
2876
                continue;
2968
                sort_aux[ptr->team].leq_place[i] = q++;
2877
            
2969
            }
-
 
2970
            else {
-
 
2971
 
2878
            sort_aux[ptr->team].le_place[i] = k++;
2972
                sort_aux[ptr->team].le_place[i] = k++;
-
 
2973
            }
2879
        }
2974
        }
2880
 
2975
 
2881
        /*
2976
        /*
2882
        **  Sort on elapsed time per class
2977
        **  Sort on elapsed time per class
2883
        **  The save the teams elapsed place in each leg per class
2978
        **  Then save the teams elapsed place in each leg per class
2884
        */
2979
        */
2885
        sort_team_data( i, S_LC );
2980
        sort_team_data( i, S_LC, sortWithEq );
2886
        teamclass = -1;
2981
        teamclass = -1;
-
 
2982
        teamclassq = -1;
2887
        for( k = 1, j = 1, ptr = sort_data; j <= sort_num; j++, ptr++ )
2983
        for( k = 1, j = 1, q = 1, ptr = sort_data; j <= sort_num; j++, ptr++ )
2888
        {
2984
        {
-
 
2985
            bool isNe = false;
-
 
2986
            if ( sortWithEq && ptr->teamclass == config.nonequestrian_class  ) {
-
 
2987
                if ( !ptr->isNeData)
-
 
2988
                    isNe = true;
-
 
2989
            }
-
 
2990
            else {
-
 
2991
                if (ptr->isNeData)
-
 
2992
                    isNe = true;
-
 
2993
            }
-
 
2994
 
-
 
2995
            if (isNe) {
2889
            if( teamclass != ptr->teamclass )
2996
                if( teamclassq != ptr->teamclass )
-
 
2997
                {
-
 
2998
                    q = 1;
-
 
2999
                    teamclassq = ptr->teamclass;
-
 
3000
                }
-
 
3001
                sort_aux[ptr->team].lq_place[i] = q++;
-
 
3002
 
2890
            {
3003
            }
-
 
3004
            else {
-
 
3005
 
-
 
3006
                if( teamclass != ptr->teamclass )
-
 
3007
                {
2891
                k = 1;
3008
                    k = 1;
2892
                teamclass = ptr->teamclass;
3009
                    teamclass = ptr->teamclass;
-
 
3010
                }
-
 
3011
                sort_aux[ptr->team].lc_place[i] = k++;
2893
            }
3012
            }
2894
            sort_aux[ptr->team].lc_place[i] = k++;
-
 
2895
        }
3013
        }
2896
 
3014
 
2897
        /*
3015
        /*
2898
        **  Sort on end time per class
3016
        **  Sort on end time per class
2899
        **  Then save the teams place at the end of each leg per class
3017
        **  Then save the teams place at the end of each leg per class
2900
        */
3018
        */
2901
        sort_team_data( i, S_LEC );
3019
        sort_team_data( i, S_LEC, sortWithEq );
2902
        teamclass = -1;
3020
        teamclass = -1;
-
 
3021
        teamclassq = -1;
2903
        for( k = 1, j = 1, ptr = sort_data; j <= sort_num; j++, ptr++ )
3022
        for( k = 1, j = 1, q = 1, ptr = sort_data; j <= sort_num; j++, ptr++ )
2904
        {
3023
        {
-
 
3024
            bool isNe = false;
-
 
3025
            if ( sortWithEq &&  ptr->teamclass == config.nonequestrian_class  ) {
-
 
3026
                if ( !ptr->isNeData)
-
 
3027
                    isNe = true;
-
 
3028
            }
-
 
3029
            else {
-
 
3030
                if (ptr->isNeData)
-
 
3031
                    isNe = true;
-
 
3032
            }
-
 
3033
 
-
 
3034
            if (isNe) {
2905
            if( teamclass != ptr->teamclass )
3035
                if( teamclassq != ptr->teamclass )
-
 
3036
                {
-
 
3037
                    q = 1;
-
 
3038
                    teamclassq = ptr->teamclass;
-
 
3039
                }
-
 
3040
                sort_aux[ptr->team].leq_place[i] = q++;
2906
            {
3041
            }
-
 
3042
            else {
-
 
3043
                if( teamclass != ptr->teamclass )
-
 
3044
                {
2907
                k = 1;
3045
                    k = 1;
2908
                teamclass = ptr->teamclass;
3046
                    teamclass = ptr->teamclass;
-
 
3047
                }
-
 
3048
                sort_aux[ptr->team].lec_place[i] = k++;
2909
            }
3049
            }
2910
            sort_aux[ptr->team].lec_place[i] = k++;
-
 
2911
        }
3050
        }
2912
    }
3051
    }
2913
 
3052
 
2914
    /*
3053
    /*
2915
    **  Write the place information back to disk for use in the displays
3054
    **  Write the place information back to disk for use in the displays
Line 2938... Line 3077...
2938
 *      This function is called to Sort in memory buffer
3077
 *      This function is called to Sort in memory buffer
2939
 *
3078
 *
2940
 *  Parameters:
3079
 *  Parameters:
2941
 *      leg         Requested leg
3080
 *      leg         Requested leg
2942
 *      mode        Defines the sort mode
3081
 *      mode        Defines the sort mode
-
 
3082
 *      withEq      Sort with equestrian data (True=Normal)
2943
 *
3083
 *
2944
 *  Returns:
3084
 *  Returns:
2945
 *      Nothing
3085
 *      Nothing
2946
 *
3086
 *
2947
 *========================================================================*/
3087
 *========================================================================*/
2948
 
3088
 
2949
void sort_team_data( int leg, int mode )
3089
void sort_team_data( int leg, int mode, bool withEq )
2950
{
3090
{
2951
 
3091
 
2952
    unsigned    j;
3092
    unsigned    j;
2953
    ty_s_data  *ptr;
3093
    ty_s_data  *ptr;
2954
 
3094
 
2955
    sort_leg = leg;                              /* Leg is global for the comparison function */
3095
    sort_leg = leg;                              /* Leg is global for the comparison function */
2956
    sort_mode = mode;                            /* Mode is global for compare function */
3096
    sort_mode = mode;                            /* Mode is global for compare function */
-
 
3097
    sort_withEquestrian = withEq;                /* Mode is global for compare function */
2957
 
3098
 
2958
    qsort( ( char * ) sort_data, sort_num, sizeof( ty_s_data ), sort_comp );
3099
    qsort( ( char * ) sort_data, sort_num, sizeof( ty_s_data ), sort_comp );
2959
 
3100
 
2960
    /*
3101
    /*
2961
     * Insert "place data" into the sorted data
3102
     * Insert "place data" into the sorted data
Line 3019... Line 3160...
3019
 
3160
 
3020
    /*
3161
    /*
3021
    **  Sorting within a class
3162
    **  Sorting within a class
3022
    **  First sort on the class
3163
    **  First sort on the class
3023
    */
3164
    */
3024
    if( sort_mode == S_LEC || sort_mode == S_LC || sort_mode == S_LC_NE )   /* Sort within a class */
3165
    if( sort_mode == S_LEC || sort_mode == S_LC || sort_mode == S_LC_NE ) {  /* Sort within a class */
3025
        if( a->teamclass != b->teamclass )
3166
        if (a->teamclass != b->teamclass)
3026
            return ( a->teamclass - b->teamclass );
3167
            return ( a->teamclass - b->teamclass );
-
 
3168
    }
3027
 
3169
 
3028
    /*
3170
    /*
3029
    **  Always put the nonequestrian_class at the end
3171
    **  Always put the nonequestrian_class at the end
3030
    **  Simplifies the creation of ordered lists as these
3172
    **  Simplifies the creation of ordered lists as these
3031
    **  Entries are not present in the main body
3173
    **  Entries are not present in the main body
3032
    */
3174
    */
3033
    if ( a->teamclass == config.nonequestrian_class ||  b->teamclass == config.nonequestrian_class )
3175
    if ( sort_withEquestrian && ( a->teamclass == config.nonequestrian_class ||  b->teamclass == config.nonequestrian_class ))
3034
    {
3176
    {
3035
        if ( a->teamclass == config.nonequestrian_class &&  b->teamclass == config.nonequestrian_class )
3177
        if ( a->teamclass == config.nonequestrian_class &&  b->teamclass == config.nonequestrian_class )
3036
        {
3178
        {
3037
            /*
3179
            /*
3038
            **  Both are non equestrian
3180
            **  Both are non equestrian
Line 3056... Line 3198...
3056
            return ( a->teamclass == config.nonequestrian_class ? 1 : -1 );
3198
            return ( a->teamclass == config.nonequestrian_class ? 1 : -1 );
3057
        }
3199
        }
3058
 
3200
 
3059
    }
3201
    }
3060
 
3202
 
-
 
3203
 
3061
    /*
3204
    /*
3062
    **  Now we need to examine the times as we have sorted
3205
    **  Now we need to examine the times as we have sorted
3063
    **  on every thing else.
3206
    **  on every thing else.
3064
    **
3207
    **
3065
    **  If one of the teams has bad_times, then that team is placed
3208
    **  If one of the teams has bad_times, then that team is placed
Line 3069... Line 3212...
3069
    **
3212
    **
3070
    **  If not sorting within a class (ie Overall), then Non_Equestrian
3213
    **  If not sorting within a class (ie Overall), then Non_Equestrian
3071
    **  is better than a bad time. Places NE before disqualified
3214
    **  is better than a bad time. Places NE before disqualified
3072
    **
3215
    **
3073
    */
3216
    */
3074
    if( a->flags.bad_times || b->flags.bad_times || a->flags.non_equestrian || b->flags.non_equestrian)  /* Valid data has precedence */
3217
    if( a->flags.bad_times || b->flags.bad_times || ( sort_withEquestrian && a->flags.non_equestrian) || (sort_withEquestrian && b->flags.non_equestrian))  /* Valid data has precedence */
3075
    {
3218
    {
3076
        if( a->flags.bad_times && b->flags.bad_times )
3219
        if( a->flags.bad_times && b->flags.bad_times )
3077
        {
3220
        {
3078
            return ( a->team - b->team );
3221
            return ( a->team - b->team );
3079
        }
3222
        }
Line 3173... Line 3316...
3173
      default:
3316
      default:
3174
        return ( 0 );
3317
        return ( 0 );
3175
    }
3318
    }
3176
 
3319
 
3177
    /*
3320
    /*
-
 
3321
     ** If we are ignore Equestrian config then place the Equestrian data last
-
 
3322
    */
-
 
3323
 
-
 
3324
#if 0
-
 
3325
    if (a->isNeData != b->isNeData) {
-
 
3326
         return ( a->isNeData ? 1 : -1 );
-
 
3327
    }
-
 
3328
#endif
-
 
3329
 
-
 
3330
#if 1
-
 
3331
    if (sort_withEquestrian) {
-
 
3332
        if (a->isNeData != b->isNeData)
-
 
3333
            return ( a->isNeData ? 1 : -1 );
-
 
3334
    }
-
 
3335
#endif
-
 
3336
 
-
 
3337
    if ( a->team == b->team) {
-
 
3338
        return ( a->isNeData ? 1 : -1 );
-
 
3339
    }
-
 
3340
 
-
 
3341
    /*
3178
    **  Finally. Compare the required team times
3342
    **  Finally. Compare the required team times
3179
    */
3343
    */
3180
    if( ta == tb )
3344
    if( ta == tb )
3181
        return ( a->team - b->team );
3345
        return ( a->team - b->team );
3182
    if( ( ta > 0 ) && ( tb > 0 ) )
3346
    if( ( ta > 0 ) && ( tb > 0 ) )
Line 3308... Line 3472...
3308
            g_record( team, &team_buf );
3472
            g_record( team, &team_buf );
3309
            if( team_buf.flags.valid )
3473
            if( team_buf.flags.valid )
3310
            {
3474
            {
3311
                last = ptr;
3475
                last = ptr;
3312
                ptr->team = team;
3476
                ptr->team = team;
-
 
3477
                ptr->isNeData = false;
3313
                for( j = 0; j < MAX_LEGS + 1; j++ )
3478
                for( j = 0; j < MAX_LEGS + 1; j++ )
3314
                {
3479
                {
3315
                    ptr->lege[j] = team_buf.leg[j].elapsed;
3480
                    ptr->lege[j] = team_buf.leg[j].elapsed;
3316
                    ptr->leg[j] = team_buf.leg[j].end;
3481
                    ptr->leg[j] = team_buf.leg[j].end;
3317
                }
3482
                }
3318
                ptr->start = team_buf.leg[0].start;
3483
                ptr->start = team_buf.leg[0].start;
3319
                ptr->teamclass = team_buf.teamclass;
3484
                ptr->teamclass = team_buf.teamclass;
3320
                ptr->real_teamclass = team_buf.teamclass;
3485
                ptr->real_teamclass = team_buf.teamclass;
3321
 
3486
 
3322
                ptr->flags = team_buf.flags;
3487
                ptr->flags = team_buf.flags;
-
 
3488
 
3323
//                if (ptr->flags.non_equestrian)
3489
//                if (ptr->flags.non_equestrian)
3324
//                    ptr->flags.disqualified = true;
3490
//                    ptr->flags.disqualified = true;
3325
                if (ptr->flags.vet_check)
3491
                if (ptr->flags.vet_check)
3326
                    ptr->flags.disqualified = true;
3492
                    ptr->flags.disqualified = true;
3327
 
3493
 
Line 3337... Line 3503...
3337
                */
3503
                */
3338
#if 1
3504
#if 1
3339
                if ( config.nonequestrian_class && team_buf.flags.non_equestrian )
3505
                if ( config.nonequestrian_class && team_buf.flags.non_equestrian )
3340
                {
3506
                {
3341
                    ptr->team = team;
3507
                    ptr->team = team;
-
 
3508
                    ptr->isNeData = true;
3342
                    ptr->lege[0] = 0;
3509
                    ptr->lege[0] = 0;
3343
 
3510
 
3344
                    for( j = 0; j < MAX_LEGS + 1; j++ )
3511
                    for( j = 0; j < MAX_LEGS + 1; j++ )
3345
                    {
3512
                    {
3346
                        if ( j == config.equestrian_leg )
3513
                        if ( j == config.equestrian_leg )