6060
6161pthread_mutex_t bm_mutex = PTHREAD_MUTEX_INITIALIZER ;
6262
63- /** \brief sorted list of all recent DX spots
63+ /** \brief list sorted by frequency of all recent DX spots
6464 */
6565GList * allspots = NULL ;
6666
67- /** \brief sorted list of filtered spots
67+ /** \brief sorted list of spots filtered for display
6868 */
6969GPtrArray * spots ;
7070
@@ -78,12 +78,10 @@ bm_config_t bm_config = {
7878 .show_out_of_band = false, /* do not show out-of-band spots */
7979};
8080
81- static bool bm_initialized = false;
82-
83- char * qtc_format (char * call );
84- gint cmp_freq (spot * a , spot * b );
81+ static char * qtc_format (char * call );
82+ static gint cmp_freq (spot * a , spot * b );
8583void free_spot (spot * data );
86- spot * copy_spot (spot * data );
84+ static spot * copy_spot (spot * data );
8785
8886/*
8987 * write bandmap spots to a file
@@ -212,6 +210,7 @@ void bmdata_read_file() {
212210 * initialize colors and data structures for bandmap operation
213211 */
214212void bm_init () {
213+ static bool bm_initialized = false;
215214
216215 if (bm_initialized )
217216 return ;
@@ -236,7 +235,7 @@ void bm_init() {
236235 *
237236 * \return CWMODE, DIGIMODE or SSBMODE
238237 */
239- int freq2mode (freq_t freq , int band ) {
238+ static int freq2mode (freq_t freq , int band ) {
240239 if (freq <= cwcorner [band ])
241240 return CWMODE ;
242241 else if (freq < ssbcorner [band ])
@@ -273,12 +272,12 @@ void bm_add(char *s) {
273272}
274273
275274/* compare functions to search in list */
276- gint cmp_call (spot * ldata , char * call ) {
275+ static gint cmp_call (spot * ldata , char * call ) {
277276
278277 return g_strcmp0 (ldata -> call , call );
279278}
280279
281- gint cmp_freq (spot * a , spot * b ) {
280+ static gint cmp_freq (spot * a , spot * b ) {
282281 unsigned int af = a -> freq ;
283282 unsigned int bf = b -> freq ;
284283
@@ -431,7 +430,6 @@ void bandmap_age() {
431430 /*
432431 * go through all entries
433432 * + decrement timeout
434- * + set state to new, normal, aged or dead
435433 * + if dead -> drop it from collection
436434 */
437435
@@ -506,7 +504,7 @@ bool bm_isdupe(char *call, int band) {
506504 return false;
507505}
508506
509- void bm_show_info () {
507+ static void bm_show_info () {
510508
511509 int curx , cury ;
512510
@@ -555,8 +553,8 @@ void bm_show_info() {
555553 * - new bright blue
556554 * - normal blue
557555 * - aged brown
558- * - worked small caps */
559- void colorize_spot (spot * data ) {
556+ * - worked grey, small caps */
557+ static void colorize_spot (spot * data ) {
560558
561559 if (data -> timeout > SPOT_NORMAL )
562560 attrset (COLOR_PAIR (CB_NEW ) | A_BOLD );
@@ -573,11 +571,47 @@ void colorize_spot(spot *data) {
573571 }
574572}
575573
574+ /*
575+ * copy string to buffer but truncate it to n characters
576+ * If truncated show it by replacing last two chars by '..'
577+ * The buffer has to be at least n+1 chars long.
578+ */
579+ static void str_truncate (char * buffer , char * string , int n ) {
580+ if (strlen (string ) > n ) {
581+ g_strlcpy (buffer , string , n - 1 ); /* truncate to n-2 chars */
582+ strcat (buffer , ".." );
583+ } else {
584+ g_strlcpy (buffer , string , n + 1 ); /* copy up to n chars */
585+ }
586+ }
587+
588+ /*
589+ * format bandmap call output for WAE
590+ * - prepare and return a temporary string from call and number of QTCs
591+ * (if any)
592+ */
593+ static char * qtc_format (char * call ) {
594+ char tcall [15 ];
595+ char qtcflag ;
596+ struct t_qtc_store_obj * qtc_temp_ptr ;
597+
598+ qtc_temp_ptr = qtc_get (call );
599+ qtcflag = qtc_get_value (qtc_temp_ptr );
600+
601+ if (qtc_temp_ptr -> total <= 0 && qtcflag == '\0' ) {
602+ str_truncate (tcall , call , SPOT_CALL_WIDTH );
603+ } else {
604+ str_truncate (tcall , call , SPOT_CALL_WIDTH - 2 );
605+ sprintf (tcall + strlen (tcall ), " %c" , qtcflag );
606+ }
607+ return g_strdup (tcall );
608+ }
609+
576610/* helper function for bandmap display
577- * convert dupes to lower case
578611 * add QTC flags for WAE contest
612+ * convert dupes to lower case
579613 */
580- char * format_spot (spot * data ) {
614+ static char * format_spot (spot * data ) {
581615 char * temp ;
582616 char * temp2 ;
583617
@@ -609,7 +643,7 @@ static char get_spot_marker(spot *data) {
609643/* helper function for bandmap display
610644 * shows formatted spot on actual cursor position
611645 */
612- void show_spot (spot * data ) {
646+ static void show_spot (spot * data ) {
613647 attrset (COLOR_PAIR (CB_DUPE ) | A_BOLD );
614648 printw ("%7.1f%c" , (data -> freq / 1000. ),
615649 (data -> node == thisnode ? '*' : data -> node ));
@@ -632,7 +666,7 @@ void show_spot(spot *data) {
632666/* helper function for bandmap display
633667 * shows spot on actual working frequency
634668 */
635- void show_spot_on_qrg (spot * data ) {
669+ static void show_spot_on_qrg (spot * data ) {
636670
637671 printw ("%7.1f%c%c " , (data -> freq / 1000. ),
638672 (data -> node == thisnode ? '*' : data -> node ),
@@ -644,9 +678,9 @@ void show_spot_on_qrg(spot *data) {
644678}
645679
646680/* helper function for bandmap display
647- * advance to next spot position
681+ * advance to display position for next spot
648682 */
649- void next_spot_position (int * y , int * x ) {
683+ static void next_spot_position (int * y , int * x ) {
650684 * y += 1 ;
651685 if (* y == LASTLINE + 1 ) {
652686 * y = TOPLINE ;
@@ -661,7 +695,7 @@ void next_spot_position(int *y, int *x) {
661695 * Otherwise calculate center frequency from band and mode
662696 * as middle value of the band/mode corners.
663697 */
664- freq_t bm_get_center (int band , int mode ) {
698+ static freq_t bm_get_center (int band , int mode ) {
665699 freq_t centerfrequency ;
666700
667701 if (trx_control )
@@ -690,18 +724,11 @@ static bool mode_matches(spot *data) {
690724/*
691725 * filter 'allspots' list according to settings and prepare 'spots' array with
692726 * selected spots
727+ * !! should only be used with bm_mutex locked !!
693728 */
694- void filter_spots () {
729+ static void filter_spots () {
695730 GList * list ;
696731 spot * data ;
697- /* acquire mutex
698- * do not add new spots to allspots during
699- * - aging and
700- * - filtering
701- * furthermore do not allow call lookup as long as
702- * filtered spot array is build anew */
703-
704- pthread_mutex_lock (& bm_mutex );
705732
706733 if (spots )
707734 g_ptr_array_free (spots , TRUE); /* free spot array */
@@ -742,15 +769,21 @@ void filter_spots() {
742769 g_ptr_array_add (spots , copy );
743770 }
744771 }
745- pthread_mutex_unlock (& bm_mutex );
746772}
747773
774+
775+ /* index to first displayed entry from filtered spot array */
776+ unsigned int startindex ;
777+ /* index to first entry beyond the displayed spots */
778+ unsigned int stopindex ;
779+
748780void bandmap_show () {
749781 /*
750782 * display depending on filter state
751783 * - all bands on/off
752784 * - all mode on/off
753785 * - dupes on/off
786+ * - only Mults on/off
754787 *
755788 * If more entries to show than room in window, show around
756789 * current frequency
@@ -759,10 +792,11 @@ void bandmap_show() {
759792 * - new bright blue
760793 * - normal blue
761794 * - aged brown
762- * - worked small caps
795+ * - worked small caps, grey
763796 * - new multi mark with blue M between QRG and call
764797 * - self announced stations
765798 * small preceding letter for reporting station
799+ * star if reported by own station
766800 *
767801 * show own frequency as dashline in green color
768802 * - highlight actual spot if near own frequency
@@ -786,32 +820,16 @@ void bandmap_show() {
786820 int i , j ;
787821
788822 bm_init ();
789- filter_spots ();
790823
791- /* afterwards display filtered list around own QRG +/- some offset
792- * (offset gets reset if we change frequency */
793-
794- getyx (stdscr , cury , curx ); /* remember cursor */
795-
796- /* start in TOPLINE, column 0 */
797- bm_y = TOPLINE ;
798- bm_x = 0 ;
799-
800- /* clear space for bandmap */
801- attrset (COLOR_PAIR (CB_DUPE ) | A_BOLD );
802-
803- move (bm_y , 0 ); /* do not overwrite # frequency */
804- for (j = 0 ; j < 67 ; j ++ )
805- addch (' ' );
806-
807- for (i = bm_y + 1 ; i < LASTLINE + 1 ; i ++ ) {
808- move (i , 0 );
809- for (j = 0 ; j < 80 ; j ++ )
810- addch (' ' );
811- }
824+ /* do not add new spots to allspots during
825+ * - aging and
826+ * - filtering
827+ * furthermore do not allow call lookup as long as
828+ * filtered spot is build anew and display range is calculated
829+ * (spots array and display range needs to stay in sync) */
830+ pthread_mutex_lock (& bm_mutex );
812831
813- /* show info text */
814- bm_show_info ();
832+ filter_spots ();
815833
816834 /* split bandmap into two parts below and above current QRG.
817835 * Give both both parts equal size.
@@ -823,7 +841,6 @@ void bandmap_show() {
823841 */
824842 unsigned int below_qrg = 0 ;
825843 unsigned int on_qrg = 0 ;
826- unsigned int startindex , stopindex ;
827844
828845 const freq_t centerfrequency = bm_get_center (bandinx , trxmode );
829846
@@ -874,6 +891,33 @@ void bandmap_show() {
874891 stopindex = spots -> len ;
875892 }
876893
894+ pthread_mutex_unlock (& bm_mutex );
895+
896+
897+ /* afterwards display filtered list around own QRG
898+ * from start- to stopindex */
899+ getyx (stdscr , cury , curx ); /* remember cursor */
900+
901+ /* start in TOPLINE, column 0 */
902+ bm_y = TOPLINE ;
903+ bm_x = 0 ;
904+
905+ /* clear space for bandmap */
906+ attrset (COLOR_PAIR (CB_DUPE ) | A_BOLD );
907+
908+ move (bm_y , 0 ); /* do not overwrite # frequency */
909+ for (j = 0 ; j < 67 ; j ++ )
910+ addch (' ' );
911+
912+ for (i = bm_y + 1 ; i < LASTLINE + 1 ; i ++ ) {
913+ move (i , 0 );
914+ for (j = 0 ; j < 80 ; j ++ )
915+ addch (' ' );
916+ }
917+
918+ /* show info text */
919+ bm_show_info ();
920+
877921 /* show spots below QRG */
878922 for (i = startindex ; i < below_qrg ; i ++ ) {
879923 move (bm_y , bm_x );
@@ -948,7 +992,7 @@ void bm_menu() {
948992 refreshp ();
949993}
950994
951- spot * copy_spot (spot * data ) {
995+ static spot * copy_spot (spot * data ) {
952996 spot * result = NULL ;
953997
954998 result = g_new0 (spot , 1 );
@@ -985,7 +1029,7 @@ spot *bandmap_lookup(char *partialcall) {
9851029
9861030 pthread_mutex_lock (& bm_mutex );
9871031
988- for (i = 0 ; i < spots -> len ; i ++ ) {
1032+ for (i = startindex ; i < stopindex ; i ++ ) {
9891033 spot * data ;
9901034 data = g_ptr_array_index (spots , i );
9911035
@@ -1050,42 +1094,6 @@ spot *bandmap_next(bool upwards, freq_t freq) {
10501094 return result ;
10511095}
10521096
1053- /*
1054- * copy string to buffer but truncate it to n characters
1055- * If truncated show it by replacing last two chars by '..'
1056- * The buffer has to be at least n+1 chars long.
1057- */
1058- void str_truncate (char * buffer , char * string , int n ) {
1059- if (strlen (string ) > n ) {
1060- g_strlcpy (buffer , string , n - 1 ); /* truncate to n-2 chars */
1061- strcat (buffer , ".." );
1062- } else {
1063- g_strlcpy (buffer , string , n + 1 ); /* copy up to n chars */
1064- }
1065- }
1066-
1067- /*
1068- * format bandmap call output for WAE
1069- * - prepare and return a temporary string from call and number of QTCs
1070- * (if any)
1071- */
1072- char * qtc_format (char * call ) {
1073- char tcall [15 ];
1074- char qtcflag ;
1075- struct t_qtc_store_obj * qtc_temp_ptr ;
1076-
1077- qtc_temp_ptr = qtc_get (call );
1078- qtcflag = qtc_get_value (qtc_temp_ptr );
1079-
1080- if (qtc_temp_ptr -> total <= 0 && qtcflag == '\0' ) {
1081- str_truncate (tcall , call , SPOT_CALL_WIDTH );
1082- } else {
1083- str_truncate (tcall , call , SPOT_CALL_WIDTH - 2 );
1084- sprintf (tcall + strlen (tcall ), " %c" , qtcflag );
1085- }
1086- return g_strdup (tcall );
1087- }
1088-
10891097/** Search filtered bandmap for a spot near the given frequency
10901098 *
10911099 * Return the call found at that frequency or NULL if no spot found
0 commit comments