Skip to content

Commit

Permalink
move pinghostlist to extra file
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbesen committed Feb 22, 2024
1 parent 2d9cd21 commit 0db40ee
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 35 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ ADMINFLAGS := $(ADMINFLAGS) -DWIN_USE_NO_ADMIN_PING
GIT_VERSION := "$(shell git describe --abbrev=4 --dirty --always --tags)"
CFLAGS += -DVERSION=\"$(GIT_VERSION)\"

cnping-wingdi.exe : cnping.c ping.c httping.c resources.o
cnping-wingdi.exe : cnping.c ping.c httping.c pinghostlist.c resolve.c resources.o
$(MINGW32)gcc -g -fno-ident -mwindows -m32 $(CFLAGS) -o $@ $^ -lgdi32 -lws2_32 -s -D_WIN32_WINNT=0x0600 -DWIN32 -liphlpapi -DMINGW_BUILD $(ADMINFLAGS)

cnping.exe : cnping.c ping.c httping.c resolve.c resources.o
cnping.exe : cnping.c ping.c httping.c pinghostlist.c resolve.c resources.o
$(MINGW32)gcc -g -fno-ident -mwindows -m32 -DCNFGOGL $(CFLAGS) -o $@ $^ -lgdi32 -lws2_32 -s -D_WIN32_WINNT=0x0600 -DWIN32 -liphlpapi -lopengl32 -DMINGW_BUILD $(ADMINFLAGS)

resources.o : resources.rc
Expand All @@ -39,13 +39,13 @@ resources.o : resources.rc

# Unix

cnping : cnping.c ping.c httping.c resolve.c
cnping : cnping.c ping.c httping.c resolve.c pinghostlist.c
$(CC) $(CFLAGS) -o $@ $^ -lX11 -lm -lpthread -lGL $(LDFLAGS)

cnping_ogl : cnping.c ping.c httping.c resolve.c
cnping_ogl : cnping.c ping.c httping.c resolve.c pinghostlist.c
$(CC) $(CFLAGS) -o $@ $^ -DCNFGOGL $(CFLAGS) -lX11 -lm -lpthread $(LDFLAGS) -lGL

cnping_mac : cnping.c ping.c httping.c resolve.c
cnping_mac : cnping.c ping.c httping.c resolve.c pinghostlist.c
$(CC) -o cnping $^ -x objective-c -framework Cocoa -framework QuartzCore -lm -lpthread -DOSX

searchnet : ping.c searchnet.c resolve.c
Expand Down
32 changes: 2 additions & 30 deletions cnping.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "ping.h"
#include "error_handling.h"
#include "httping.h"
#include "pinghostlist.h"

// #### Cross-plattform debugging ####
// Windows does not print to Console, use DebugView from SysInternals to
Expand All @@ -55,13 +56,6 @@
#endif


// linked list of hosts to ping
struct PingHost
{
const char * host;
struct PingHost* next;
};

short screenx, screeny;
float GuiYScaleFactor;
int GuiYscaleFactorIsConstant;
Expand Down Expand Up @@ -660,28 +654,6 @@ INT_PTR CALLBACK TextEntry( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
}
#endif

void prependPingHost( struct PingHost ** list, unsigned int * listSize, const char * newEntryValue )
{
struct PingHost* newEntry = malloc( sizeof(struct PingHost) );
newEntry->host = newEntryValue;
newEntry->next = *list;
*list = newEntry;
(*listSize) ++;
}

void freePingHostList( struct PingHost ** list, unsigned int * listSize )
{
struct PingHost * current = *list;
while( current )
{
struct PingHost * next = current->next;
free( current );
current = next;
}
*list = NULL;
*listSize = 0;
}

int main( int argc, const char ** argv )
{
char title[1024];
Expand Down Expand Up @@ -803,7 +775,7 @@ int main( int argc, const char ** argv )
freePingHostList( &pinghostList, &pinghostListSize );
exit( -1 );
}

if( WSAStartup(MAKEWORD(2,2), &wsaData) )
{
ERRM( "Fault in WSAStartup\n" );
Expand Down
29 changes: 29 additions & 0 deletions pinghostlist.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "pinghostlist.h"

#include <stddef.h>
#include <stdlib.h>

void prependPingHost( struct PingHost ** list, unsigned int * listSize, const char * newEntryValue )
{
struct PingHost* newEntry = malloc( sizeof(struct PingHost) );
newEntry->host = newEntryValue;
newEntry->next = *list;
*list = newEntry;
(*listSize) ++;
}

void freePingHostList( struct PingHost ** list, unsigned int * listSize )
{
struct PingHost * current = *list;
while( current )
{
struct PingHost * next = current->next;
free( current );
current = next;
}
*list = NULL;
if(listSize)
{
*listSize = 0;
}
}
19 changes: 19 additions & 0 deletions pinghostlist.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef PING_HOST_LIST_H
#define PING_HOST_LIST_H


// linked list of hosts to ping
struct PingHost
{
const char * host;
struct PingHost* next;
};

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

// delete the list
// *list and *listsize will be set to 0
void freePingHostList( struct PingHost ** list, unsigned int * listSize );

#endif

0 comments on commit 0db40ee

Please sign in to comment.