kopia lustrzana https://github.com/jamescoxon/dl-fldigi
Bug fixes/Comments
* Script Generate should save PA device index vice menu index. * PSK: Possible segment fault. Tighter control on string lengths * Util.cxx add comment block to each functions and remove trim_white_spaces() function.pull/1/head
rodzic
cbc9975bd5
commit
aedc628d92
|
@ -320,13 +320,17 @@ static int create_default_script(char *file_name)
|
|||
|
||||
if(menuPortInDev->value() > -1) {
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
snprintf(buffer, sizeof(buffer)-1, "%s:%d,\"%s\"", CMD_PORTA_CAP, menuPortInDev->value(), menuPortInDev->text());
|
||||
// Invalid warning issued (clang-600.0.56 [3.5] MacOSX) if index is replaced with reinterpret_cast<intptr_t>(x) in snprintf() routine.
|
||||
int index = reinterpret_cast<intptr_t>(menuPortInDev->mvalue()->user_data());
|
||||
snprintf(buffer, sizeof(buffer)-1, "%s:%d,\"%s\"", CMD_PORTA_CAP, index, menuPortInDev->text());
|
||||
if(add_string(fd, (char *)buffer, 1)) return fclose(fd);
|
||||
}
|
||||
|
||||
if(menuPortOutDev->value() > -1) {
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
snprintf(buffer, sizeof(buffer)-1, "%s:%d,\"%s\"", CMD_PORTA_PLAY, menuPortOutDev->value(), menuPortOutDev->text());
|
||||
// Invalid warning issued (clang-600.0.56 [3.5] MacOSX) if index is replaced with reinterpret_cast<intptr_t>(x) in snprintf() routine.
|
||||
int index = reinterpret_cast<intptr_t>(menuPortOutDev->mvalue()->user_data());
|
||||
snprintf(buffer, sizeof(buffer)-1, "%s:%d,\"%s\"", CMD_PORTA_PLAY, index, menuPortOutDev->text());
|
||||
if(add_string(fd, (char *)buffer, 1)) return fclose(fd);
|
||||
}
|
||||
#endif // USE_PORTAUDIO
|
||||
|
@ -669,9 +673,9 @@ static int add_command(FILE *fd, char *cmd, int indent_level)
|
|||
std::string indent = "";
|
||||
for(int i = 0; i < indent_level; i++)
|
||||
indent.append(" ");
|
||||
|
||||
|
||||
fprintf(fd, "%s%s:\n", indent.c_str(), cmd);
|
||||
|
||||
|
||||
return ferror(fd);
|
||||
}
|
||||
|
||||
|
|
|
@ -1102,7 +1102,7 @@ SCRIPT_CODES ScriptParsing::parse_single_command(FILE *fd, SCRIPT_COMMANDS *cur_
|
|||
return error;
|
||||
}
|
||||
|
||||
int str_count = str_cnt(buffer, allocated_buffer_size);
|
||||
int str_count = (int) strnlen(buffer, allocated_buffer_size);
|
||||
trim(buffer, (size_t) str_count);
|
||||
|
||||
|
||||
|
@ -2063,7 +2063,7 @@ ScriptParsing::~ScriptParsing()
|
|||
void ScriptParsing::add_to_delete_list(SCRIPT_COMMANDS *ptr)
|
||||
{
|
||||
if(!ptr) return;
|
||||
|
||||
|
||||
if(delete_list_count < MAX_DELETE_LIST_COUNT) {
|
||||
memory_delete_list[delete_list_count] = ptr;
|
||||
delete_list_count++;
|
||||
|
@ -2093,14 +2093,14 @@ int ScriptParsing::str_cnt(char * str, int count_limit)
|
|||
{
|
||||
if(!str || (count_limit < 1))
|
||||
return 0;
|
||||
|
||||
|
||||
int value = 0;
|
||||
|
||||
|
||||
for(int index = 0; index < count_limit; index++) {
|
||||
if(str[index] == 0) break;
|
||||
value++;
|
||||
}
|
||||
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -2115,36 +2115,36 @@ std::string &ScriptParsing::trim(std::string &s) {
|
|||
char *end = (char *)0;
|
||||
char *src = (char *)0;
|
||||
long count = s.size();
|
||||
|
||||
|
||||
buffer = new char[count + 1];
|
||||
if(!buffer) return s;
|
||||
|
||||
|
||||
memcpy(buffer, s.c_str(), count);
|
||||
buffer[count] = 0;
|
||||
|
||||
|
||||
dst = src = buffer;
|
||||
end = &buffer[count];
|
||||
|
||||
|
||||
while(src < end) {
|
||||
if(*src > ' ') break;
|
||||
src++;
|
||||
}
|
||||
|
||||
|
||||
if(src > dst) {
|
||||
while((dst < end) && (src < end))
|
||||
*dst++ = *src++;
|
||||
*dst = 0;
|
||||
}
|
||||
|
||||
|
||||
while(end >= buffer) {
|
||||
if(*end > ' ') break;
|
||||
*end-- = 0;
|
||||
}
|
||||
|
||||
|
||||
s.assign(buffer);
|
||||
|
||||
|
||||
delete [] buffer;
|
||||
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -2160,35 +2160,34 @@ void ScriptParsing::trim(char *buffer, size_t limit)
|
|||
char *e = (char *)0;
|
||||
char *dst = (char *)0;
|
||||
size_t count = 0;
|
||||
|
||||
|
||||
if(!buffer || limit < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for(count = 0; count < limit; count++)
|
||||
if(buffer[count] == 0) break;
|
||||
|
||||
|
||||
if(count < 1) return;
|
||||
|
||||
|
||||
s = buffer;
|
||||
e = &buffer[count-1];
|
||||
|
||||
|
||||
for(size_t i = 0; i < count; i++) {
|
||||
if((*s <= ' ') || (*s == '"')) s++;
|
||||
else break;
|
||||
}
|
||||
|
||||
|
||||
while(e > s) {
|
||||
if((*e <= ' ') || (*e == '"'))
|
||||
*e = 0;
|
||||
else
|
||||
break;
|
||||
if(*e == '"') { *e-- = 0; break; }
|
||||
if(*e > ' ') break;
|
||||
if(*e <= ' ') *e = 0;
|
||||
e--;
|
||||
}
|
||||
|
||||
|
||||
dst = buffer;
|
||||
for(; s <= e; s++) {
|
||||
*dst++ = *s;
|
||||
while(s <= e) {
|
||||
*dst++ = *s++;
|
||||
}
|
||||
*dst = 0;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,9 @@
|
|||
# include "compat.h"
|
||||
#endif
|
||||
|
||||
/// Return the smallest power of 2 not less than n
|
||||
/** ********************************************************************
|
||||
* Return the smallest power of 2 not less than n
|
||||
***********************************************************************/
|
||||
uint32_t ceil2(uint32_t n)
|
||||
{
|
||||
--n;
|
||||
|
@ -54,6 +56,9 @@ uint32_t ceil2(uint32_t n)
|
|||
return n + 1;
|
||||
}
|
||||
|
||||
/** ********************************************************************
|
||||
* Return the largest power of 2 not greater than n
|
||||
***********************************************************************/
|
||||
/// Return the largest power of 2 not greater than n
|
||||
uint32_t floor2(uint32_t n)
|
||||
{
|
||||
|
@ -68,7 +73,10 @@ uint32_t floor2(uint32_t n)
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
/// Transforms the version, as a string, into an integer, so comparisons are possible.
|
||||
/** ********************************************************************
|
||||
* Transforms the version, as a string, into an integer, so comparisons
|
||||
* are possible.
|
||||
***********************************************************************/
|
||||
unsigned long ver2int(const char* version)
|
||||
{
|
||||
unsigned long v = 0L;
|
||||
|
@ -81,9 +89,12 @@ unsigned long ver2int(const char* version)
|
|||
return v;
|
||||
}
|
||||
|
||||
/** ********************************************************************
|
||||
* from git 1.6.1.2 compat/strcasestr.c
|
||||
***********************************************************************/
|
||||
#if !HAVE_STRCASESTR
|
||||
# include <ctype.h>
|
||||
// from git 1.6.1.2 compat/strcasestr.c
|
||||
|
||||
char *strcasestr(const char *haystack, const char *needle)
|
||||
{
|
||||
int nlen = strlen(needle);
|
||||
|
@ -106,8 +117,10 @@ char *strcasestr(const char *haystack, const char *needle)
|
|||
}
|
||||
#endif // !HAVE_STRCASESTR
|
||||
|
||||
/** ********************************************************************
|
||||
* from git 1.6.1.2 compat/strcasestr.c
|
||||
***********************************************************************/
|
||||
#if !HAVE_STRLCPY
|
||||
// from git 1.6.1.2 compat/strcasestr.c
|
||||
size_t strlcpy(char *dest, const char *src, size_t size)
|
||||
{
|
||||
size_t ret = strlen(src);
|
||||
|
@ -121,6 +134,9 @@ size_t strlcpy(char *dest, const char *src, size_t size)
|
|||
}
|
||||
#endif // !HAVE_STRLCPY
|
||||
|
||||
/** ********************************************************************
|
||||
*
|
||||
***********************************************************************/
|
||||
#if !HAVE_STRNLEN
|
||||
size_t strnlen(const char *s, size_t maxlen)
|
||||
{
|
||||
|
@ -133,6 +149,9 @@ size_t strnlen(const char *s, size_t maxlen)
|
|||
}
|
||||
#endif // !HAVE_STRNLEN
|
||||
|
||||
/** ********************************************************************
|
||||
*
|
||||
***********************************************************************/
|
||||
#if !HAVE_STRNCPY
|
||||
char * strncpy(char *dst, const char *src, size_t maxlen)
|
||||
{
|
||||
|
@ -148,6 +167,9 @@ char * strncpy(char *dst, const char *src, size_t maxlen)
|
|||
}
|
||||
#endif // !HAVE_STRNCPY
|
||||
|
||||
/** ********************************************************************
|
||||
*
|
||||
***********************************************************************/
|
||||
#if !HAVE_STRNCMP
|
||||
int strncmp(const char *s1, const char *s2, size_t maxlen)
|
||||
{
|
||||
|
@ -166,8 +188,10 @@ int strncmp(const char *s1, const char *s2, size_t maxlen)
|
|||
}
|
||||
#endif // !HAVE_STRNCMP
|
||||
|
||||
/** ********************************************************************
|
||||
* from git 1.6.3.1 compat/setenv.c
|
||||
***********************************************************************/
|
||||
#if !HAVE_SETENV
|
||||
// from git 1.6.3.1 compat/setenv.c
|
||||
int setenv(const char *name, const char *value, int replace)
|
||||
{
|
||||
int out;
|
||||
|
@ -202,8 +226,10 @@ int setenv(const char *name, const char *value, int replace)
|
|||
}
|
||||
#endif
|
||||
|
||||
/***********************************************************************
|
||||
* from git 1.6.3.1 compat/setenv.c
|
||||
***********************************************************************/
|
||||
#if !HAVE_UNSETENV
|
||||
// from git 1.6.3.1 compat/setenv.c
|
||||
int unsetenv(const char *name)
|
||||
{
|
||||
extern char **environ;
|
||||
|
@ -232,6 +258,9 @@ int unsetenv(const char *name)
|
|||
#endif
|
||||
|
||||
|
||||
/** ********************************************************************
|
||||
*
|
||||
***********************************************************************/
|
||||
#ifdef __MINGW32__
|
||||
int set_cloexec(int fd, unsigned char v) { return 0; }
|
||||
#else
|
||||
|
@ -244,6 +273,9 @@ int set_cloexec(int fd, unsigned char v)
|
|||
}
|
||||
#endif // __MINGW32__
|
||||
|
||||
/** ********************************************************************
|
||||
*
|
||||
***********************************************************************/
|
||||
int set_nonblock(int fd, unsigned char v)
|
||||
{
|
||||
#ifndef __MINGW32__
|
||||
|
@ -267,6 +299,10 @@ int set_nonblock(int fd, unsigned char v)
|
|||
# include <netinet/in.h>
|
||||
# include <netinet/tcp.h>
|
||||
#endif
|
||||
|
||||
/** ********************************************************************
|
||||
*
|
||||
***********************************************************************/
|
||||
int set_nodelay(int fd, unsigned char v)
|
||||
{
|
||||
int val = v;
|
||||
|
@ -276,12 +312,20 @@ int set_nodelay(int fd, unsigned char v)
|
|||
#ifdef __MINGW32__
|
||||
# include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
/** ********************************************************************
|
||||
*
|
||||
***********************************************************************/
|
||||
int get_bufsize(int fd, int dir, int* len)
|
||||
{
|
||||
socklen_t optlen = sizeof(*len);
|
||||
return getsockopt(fd, SOL_SOCKET, (dir == 0 ? SO_RCVBUF : SO_SNDBUF),
|
||||
(char*)len, &optlen);
|
||||
}
|
||||
|
||||
/** ********************************************************************
|
||||
*
|
||||
***********************************************************************/
|
||||
int set_bufsize(int fd, int dir, int len)
|
||||
{
|
||||
return setsockopt(fd, SOL_SOCKET, (dir == 0 ? SO_RCVBUF : SO_SNDBUF),
|
||||
|
@ -299,6 +343,9 @@ static struct sigaction* sigact = 0;
|
|||
static pthread_mutex_t sigmutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#endif
|
||||
|
||||
/** ********************************************************************
|
||||
*
|
||||
***********************************************************************/
|
||||
void save_signals(void)
|
||||
{
|
||||
#ifndef __MINGW32__
|
||||
|
@ -312,6 +359,9 @@ void save_signals(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
/** ********************************************************************
|
||||
*
|
||||
***********************************************************************/
|
||||
void restore_signals(void)
|
||||
{
|
||||
#ifndef __MINGW32__
|
||||
|
@ -325,6 +375,9 @@ void restore_signals(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
/** ********************************************************************
|
||||
*
|
||||
***********************************************************************/
|
||||
uint32_t simple_hash_data(const unsigned char* buf, size_t len, uint32_t code)
|
||||
{
|
||||
for (size_t i = 0; i < len; i++)
|
||||
|
@ -332,6 +385,10 @@ uint32_t simple_hash_data(const unsigned char* buf, size_t len, uint32_t code)
|
|||
|
||||
return code;
|
||||
}
|
||||
|
||||
/** ********************************************************************
|
||||
*
|
||||
***********************************************************************/
|
||||
uint32_t simple_hash_str(const unsigned char* str, uint32_t code)
|
||||
{
|
||||
while (*str)
|
||||
|
@ -345,6 +402,9 @@ uint32_t simple_hash_str(const unsigned char* str, uint32_t code)
|
|||
static const char hexsym[] = "0123456789ABCDEF";
|
||||
|
||||
static std::vector<char>* hexbuf;
|
||||
/** ********************************************************************
|
||||
*
|
||||
***********************************************************************/
|
||||
const char* str2hex(const unsigned char* str, size_t len)
|
||||
{
|
||||
if (unlikely(len == 0))
|
||||
|
@ -367,12 +427,19 @@ const char* str2hex(const unsigned char* str, size_t len)
|
|||
|
||||
return &(*hexbuf)[0];
|
||||
}
|
||||
|
||||
/** ********************************************************************
|
||||
*
|
||||
***********************************************************************/
|
||||
const char* str2hex(const char* str, size_t len)
|
||||
{
|
||||
return str2hex((const unsigned char*)str, len ? len : strlen(str));
|
||||
}
|
||||
|
||||
static std::vector<char>* binbuf;
|
||||
/** ********************************************************************
|
||||
*
|
||||
***********************************************************************/
|
||||
const char* uint2bin(unsigned u, size_t len)
|
||||
{
|
||||
if (unlikely(len == 0))
|
||||
|
@ -394,6 +461,9 @@ const char* uint2bin(unsigned u, size_t len)
|
|||
return &(*binbuf)[0];
|
||||
}
|
||||
|
||||
/** ********************************************************************
|
||||
*
|
||||
***********************************************************************/
|
||||
void MilliSleep(long msecs)
|
||||
{
|
||||
#ifndef __MINGW32__
|
||||
|
@ -404,7 +474,10 @@ void MilliSleep(long msecs)
|
|||
#endif
|
||||
}
|
||||
|
||||
/// Returns 0 if a process is running, 0 if not there and -1 if the test cannot be made.
|
||||
/** ********************************************************************
|
||||
* Returns 0 if a process is running, 0 if not there and -1 if the
|
||||
* test cannot be made.
|
||||
***********************************************************************/
|
||||
int test_process(int pid)
|
||||
{
|
||||
#ifdef __MINGW32__
|
||||
|
@ -436,7 +509,9 @@ int test_process(int pid)
|
|||
/// This includes Windows.h
|
||||
#include <winbase.h>
|
||||
|
||||
/// Retrieve the system error message for the last-error code
|
||||
/** ********************************************************************
|
||||
* Retrieve the system error message for the last-error code
|
||||
***********************************************************************/
|
||||
static const char * WindowsError(DWORD dw)
|
||||
{
|
||||
LPVOID lpMsgBuf;
|
||||
|
@ -459,7 +534,10 @@ static const char * WindowsError(DWORD dw)
|
|||
}
|
||||
#endif
|
||||
|
||||
/// Starts a process and returns its pid, and -1 if error. Returns 0 if this cannot be made.
|
||||
/** ********************************************************************
|
||||
* Starts a process and returns its pid, and -1 if error. Returns 0 if
|
||||
* this cannot be made.
|
||||
***********************************************************************/
|
||||
int fork_process( const char * cmd )
|
||||
{
|
||||
#ifdef __MINGW32__
|
||||
|
@ -491,7 +569,9 @@ int fork_process( const char * cmd )
|
|||
#endif
|
||||
}
|
||||
|
||||
/// Returns true if OK. Beware, the error case is not reentrant.
|
||||
/** ********************************************************************
|
||||
* Returns true if OK. Beware, the error case is not reentrant.
|
||||
***********************************************************************/
|
||||
const char * create_directory( const char * dir )
|
||||
{
|
||||
if ( mkdir(dir, 0777) == -1 )
|
||||
|
|
|
@ -1179,7 +1179,7 @@ static double averageamp;
|
|||
// ***********************************************************
|
||||
// if (_pskr) {
|
||||
// metric = metric * 4;
|
||||
// }
|
||||
// }
|
||||
// else if ( (_xpsk || _8psk || _16psk) && !_disablefec) {
|
||||
// metric *= 2 * symbits; /// @TODO scale the metric with the psk constellation density
|
||||
// }
|
||||
|
@ -1339,16 +1339,19 @@ void psk::signalquality()
|
|||
|
||||
void psk::update_syncscope()
|
||||
{
|
||||
static char msg1[15];
|
||||
static char msg2[15];
|
||||
static char msg1[16];
|
||||
static char msg2[16];
|
||||
|
||||
display_metric(metric);
|
||||
|
||||
memset(msg1, 0, sizeof(msg1));
|
||||
memset(msg2, 0, sizeof(msg2));
|
||||
|
||||
s2n = 10.0*log10( snratio );
|
||||
snprintf(msg1, sizeof(msg1), "s/n %2d dB", (int)(floor(s2n)));
|
||||
snprintf(msg1, sizeof(msg1)-1, "s/n %2d dB", (int)(floor(s2n)));
|
||||
|
||||
imd = 10.0*log10( imdratio );
|
||||
snprintf(msg2, sizeof(msg2), "imd %3d dB", (int)(floor(imd)));
|
||||
snprintf(msg2, sizeof(msg2)-1, "imd %3d dB", (int)(floor(imd)));
|
||||
|
||||
if (imdValid) {
|
||||
put_Status1(msg1, progdefaults.StatusTimeout, progdefaults.StatusDim ? STATUS_DIM : STATUS_CLEAR);
|
||||
|
|
|
@ -88,7 +88,6 @@ using namespace std;
|
|||
|
||||
LOG_FILE_SOURCE(debug::LOG_AUDIO);
|
||||
|
||||
|
||||
SoundBase::SoundBase()
|
||||
: sample_frequency(0),
|
||||
txppm(progdefaults.TX_corr), rxppm(progdefaults.RX_corr),
|
||||
|
|
Ładowanie…
Reference in New Issue