Skip to content

Commit 4891773

Browse files
committed
reverse pinghost ordering - but without creating graphical glitches
1 parent 2fb8c4b commit 4891773

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

cnping.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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;

pinghostlist.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,31 @@
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

pinghostlist.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)