File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -735,7 +735,7 @@ int main( int argc, const char ** argv )
735735 //Parameter-based field.
736736 switch ( thisargv [1 ] )
737737 {
738- case 'h' : prependPingHost ( & pinghostList , & pinghostListSize , nextargv ); break ;
738+ case 'h' : appendPingHost ( & pinghostList , & pinghostListSize , nextargv ); break ;
739739 case 'p' : pingperiodseconds = atof ( nextargv ); break ;
740740 case 's' : ExtraPingSize = atoi ( nextargv ); break ;
741741 case 'y' : GuiYScaleFactor = atof ( nextargv ); break ;
@@ -750,7 +750,7 @@ int main( int argc, const char ** argv )
750750 //Unmarked fields
751751 switch ( argcunmarked ++ )
752752 {
753- case 1 : prependPingHost ( & pinghostList , & pinghostListSize , thisargv ); break ;
753+ case 1 : appendPingHost ( & pinghostList , & pinghostListSize , thisargv ); break ;
754754 case 2 : pingperiodseconds = atof ( thisargv ); break ;
755755 case 3 : ExtraPingSize = atoi ( thisargv ); break ;
756756 case 4 : GuiYScaleFactor = atof ( thisargv ); break ;
Original file line number Diff line number Diff line change 33#include <stddef.h>
44#include <stdlib.h>
55
6- void prependPingHost ( struct PingHost * * list , unsigned int * listSize , const char * newEntryValue )
6+ void appendPingHost ( struct PingHost * * list , unsigned int * listSize , const char * newEntryValue )
77{
8+ // find last entry
9+ struct PingHost * current = * list ;
10+ struct PingHost * last = current ;
11+ while ( current )
12+ {
13+ struct PingHost * next = current -> next ;
14+ last = current ;
15+ current = next ;
16+ }
17+
818 struct PingHost * newEntry = malloc ( sizeof (struct PingHost ) );
919 newEntry -> host = newEntryValue ;
10- newEntry -> next = * list ;
11- * list = newEntry ;
20+ newEntry -> next = NULL ;
21+
22+ if ( last )
23+ {
24+ last -> next = newEntry ;
25+ }
26+ else
27+ {
28+ * list = newEntry ;
29+ }
30+
1231 (* listSize ) ++ ;
1332}
1433
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ struct PingHost
1010};
1111
1212// add a new entry to the list
13- void prependPingHost ( struct PingHost * * list , unsigned int * listSize , const char * newEntryValue );
13+ void appendPingHost ( struct PingHost * * list , unsigned int * listSize , const char * newEntryValue );
1414
1515// delete the list
1616// *list and *listsize will be set to 0
You can’t perform that action at this time.
0 commit comments