Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Makefile.linux
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ radio_info.c\
rigctl.c \
bpsk.c \
subrx.c \
actions.c
actions.c \
debug.c

HEADERS=\
main.h\
Expand Down Expand Up @@ -190,7 +191,8 @@ radio_info.h\
rigctl.h \
bpsk.h \
subrx.h \
actions.h
actions.h \
debug.h

OBJS=\
main.o\
Expand Down Expand Up @@ -242,7 +244,8 @@ radio_info.o\
rigctl.o \
bpsk.o \
subrx.o \
actions.o
actions.o \
debug.o


$(PROGRAM): $(OBJS) $(SOAPYSDR_OBJS) $(CWDAEMON_OBJS) $(MIDI_OBJS)
Expand Down
9 changes: 6 additions & 3 deletions Makefile.mac
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ error_handler.c\
radio_info.c\
bpsk.c \
css.c \
subrx.c
subrx.c \
debug.c

HEADERS=\
main.h\
Expand Down Expand Up @@ -172,7 +173,8 @@ error_handler.h\
radio_info.h\
bpsk.h \
css.h \
subrx.h
subrx.h \
debug.h

OBJS=\
main.o\
Expand Down Expand Up @@ -223,7 +225,8 @@ error_handler.o\
radio_info.o\
bpsk.o \
css.o \
subrx.o
subrx.o \
debug.o

all: prebuild $(PROGRAM) $(HEADERS) $(SOURCES) $(MIDI_SOURCES) $(SOAPYSDR_SOURCES)

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Development environment

Development and testing has been run on Ubuntu 17.10 and Ubuntu 18.04. If run on early versions there may be a problem with GTK not supporting the gtk_menu_popup_at_pointer function vfo.c. For information on MacOS support see [MacOS.md](./MacOS.md).
Development and testing has been run on Ubuntu 17.10 and Ubuntu 18.04. If run on early versions there may be a problem with GTK not supporting the gtk_menu_popup_at_pointer function vfo.c. For information on MacOS support see MacOS Support section below.

### Prerequisites for building

Expand Down Expand Up @@ -108,4 +108,3 @@ Development and testing has been run on MacOS Sierra 10.12.6 and MacOS high Sier

The build installs linHPSDR into `/usr/local/bin`. To run it, type `linhpsdr` on the command line.


19 changes: 19 additions & 0 deletions debug.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdio.h>
#include <stdarg.h>

unsigned int DEBUG = 1; // incremented by each "-d|--debug" on command line

// from public source source (source as in source code, source as in font of information)

// Our implemented function
void realdbgprintf (const char *SourceFilename,
int SourceLineno,
const char *CFormatString,
...) {
va_list ap;

(void) fprintf( stderr, "%s(%u): ", SourceFilename, SourceLineno ); // output what is not variadic

va_start(ap, CFormatString); // init ap to location of variadic arg(s)
(void) vfprintf( stderr, CFormatString, ap );
}
40 changes: 40 additions & 0 deletions debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
extern unsigned int DEBUG;

// from public source source (source as in source code, source as in font of information)

// Our implemented function
void realdbgprintf (const char *SourceFilename,
int SourceLineno,
const char *CFormatString,
...);

// Due to limitations of the variadic macro support in C++11 the following
// straightforward solution can fail and should thus be avoided:
//
// #define dbgprintf(cformat, ...) \
// realdbgprintf (__FILE__, __LINE__, cformat, __VA_ARGS__)
//
// The reason is that
//
// dbgprintf("Hallo")
//
// gets expanded to
//
// realdbgprintf (__FILE__, __LINE__, "Hallo", )
//
// where the comma before the closing brace will result in a syntax error.
//
// GNU C++ supports a non-portable extension which solves this.
//
// #define dbgprintf(cformat, ...) \
// realdbgprintf (__FILE__, __LINE__, cformat, ##__VA_ARGS__)
//
// C++20 eventually supports the following syntax.
//
// #define dbgprintf(cformat, ...) \
// realdbgprintf (__FILE__, __LINE__, cformat __VA_OPT__(,) __VA_ARGS__)
//
// By using the 'cformat' string as part of the variadic arguments we can
// circumvent the abovementioned incompatibilities. This is tricky but
// portable.
#define dbgprintf(...) realdbgprintf (__FILE__, __LINE__, __VA_ARGS__)
29 changes: 26 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <gtk/gtk.h>
#include <math.h>
#include <unistd.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -52,6 +53,7 @@
#include "property.h"
#include "rigctl.h"
#include "version.h"
#include "debug.h"

GtkWidget *main_window;
static GtkWidget *grid;
Expand Down Expand Up @@ -552,17 +554,38 @@ int main(int argc, char **argv) {
int rc;
const char *homedir;

opterr = 0;
while ((rc = getopt(argc,argv,"hd")) != -1)
switch(rc)
{
case 'd':
DEBUG++; // increment DEBUG
break;
case '?':
if (isprint(optopt))
fprintf(stderr,"Unknown option '-%c'\n",optopt);
else
fprintf(stderr,"Unknown option char '\\x%x'\n",optopt);
case 'h':
default: // fall-through
fprintf(stderr,"Usage: linhpsdr [-h] or linhpsdr [-d][-d]... (each '-d' increases DEBUG level)\n");
return 1;
}
if (DEBUG>0)
dbgprintf("DEBUG level is %d\n",DEBUG);

if((homedir=getenv("HOME"))==NULL) {
homedir=getpwuid(getuid())->pw_dir;
}
sprintf(text,"%s/.local",homedir);
rc=mkdir(text,0777);
rc=mkdir(text,0775);
sprintf(text,"%s/.local/share",homedir);
rc=mkdir(text,0777);
rc=mkdir(text,0775);
sprintf(text,"%s/.local/share/linhpsdr",homedir);
rc=mkdir(text,0777);
rc=mkdir(text,0775);

sprintf(text,"org.g0orx.hpsdr.pid%d",getpid());

hpsdr=gtk_application_new(text, G_APPLICATION_FLAGS_NONE);
g_signal_connect(hpsdr, "activate", G_CALLBACK(activate_hpsdr), NULL);
rc=g_application_run(G_APPLICATION(hpsdr), argc, argv);
Expand Down
41 changes: 25 additions & 16 deletions property.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <stdio.h>
#include <string.h>
#include "property.h"
#include "debug.h"

PROPERTY* properties;

Expand Down Expand Up @@ -49,33 +50,41 @@ void loadProperties(char* filename) {
properties=NULL;
PROPERTY* property;

fprintf(stderr,"loadProperties: %s\n",filename);
if (DEBUG>0)
dbgprintf("loadProperties: %s\n", filename);

if(f) {
while(fgets(string,sizeof(string),f)) {
if(string[0]!='#') {
if(string[0]!='#') { // content is not comment line
if(DEBUG>1) // else NOOP
dbgprintf("loading property:: %s", string); // lines from filename have '\n' already
name=strtok(string,"=");
value=strtok(NULL,"\n");
if (name != NULL && value != NULL) {
property=malloc(sizeof(PROPERTY));
property->name=malloc(strlen(name)+1);
strcpy(property->name,name);
property->value=malloc(strlen(value)+1);
strcpy(property->value,value);
property->next_property=properties;
properties=property;
if(strcmp(name,"property_version")==0) {
version=atof(value);
}
}
if (name != NULL) {
// strtok() indicates 'no token found' by returning NULL value.
if (value == 0x0) // property is empty string
value = ""; // set value accordingly

property=malloc(sizeof(PROPERTY));
property->name=malloc(strlen(name)+1);
strcpy(property->name,name);
property->value=malloc(strlen(value)+1);
strcpy(property->value,value);
property->next_property=properties;
properties=property;
if(strcmp(name,"property_version")==0) {
version=atof(value);
}
}
}
}
fclose(f);
}

if(version!=PROPERTY_VERSION) {
properties=NULL;
fprintf(stderr,"loadProperties: version=%f expected version=%f ignoring\n",version,PROPERTY_VERSION);
properties=NULL;
if (DEBUG>0)
dbgprintf("loadProperties: version=%f expected version=%f - ignoring\n",version,PROPERTY_VERSION);
}
}

Expand Down