Skip to content

Commit

Permalink
reverse pinghost ordering - but without creating graphical glitches
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbesen committed Apr 10, 2024
1 parent 2fb8c4b commit 4891773
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cnping.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ int main( int argc, const char ** argv )
//Parameter-based field.
switch( thisargv[1] )
{
case 'h': prependPingHost( &pinghostList, &pinghostListSize, nextargv ); break;
case 'h': appendPingHost( &pinghostList, &pinghostListSize, nextargv ); break;
case 'p': pingperiodseconds = atof( nextargv ); break;
case 's': ExtraPingSize = atoi( nextargv ); break;
case 'y': GuiYScaleFactor = atof( nextargv ); break;
Expand All @@ -750,7 +750,7 @@ int main( int argc, const char ** argv )
//Unmarked fields
switch( argcunmarked++ )
{
case 1: prependPingHost( &pinghostList, &pinghostListSize, thisargv ); break;
case 1: appendPingHost( &pinghostList, &pinghostListSize, thisargv ); break;
case 2: pingperiodseconds = atof( thisargv ); break;
case 3: ExtraPingSize = atoi( thisargv ); break;
case 4: GuiYScaleFactor = atof( thisargv ); break;
Expand Down
25 changes: 22 additions & 3 deletions pinghostlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,31 @@
#include <stddef.h>
#include <stdlib.h>

void prependPingHost( struct PingHost ** list, unsigned int * listSize, const char * newEntryValue )
void appendPingHost( struct PingHost ** list, unsigned int * listSize, const char * newEntryValue )
{
// find last entry
struct PingHost * current = *list;
struct PingHost * last = current;
while( current )
{
struct PingHost * next = current->next;
last = current;
current = next;
}

struct PingHost* newEntry = malloc( sizeof(struct PingHost) );
newEntry->host = newEntryValue;
newEntry->next = *list;
*list = newEntry;
newEntry->next = NULL;

if ( last )
{
last->next = newEntry;
}
else
{
*list = newEntry;
}

(*listSize) ++;
}

Expand Down
2 changes: 1 addition & 1 deletion pinghostlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct PingHost
};

// add a new entry to the list
void prependPingHost( struct PingHost ** list, unsigned int * listSize, const char * newEntryValue );
void appendPingHost( struct PingHost ** list, unsigned int * listSize, const char * newEntryValue );

// delete the list
// *list and *listsize will be set to 0
Expand Down

0 comments on commit 4891773

Please sign in to comment.