Bug#782096: QRQ: FTBFS on hurd-i386: PATH_MAX
Build using pulseaudio was omitted
Display corruption when using wgetc function.
Builds successfully using pulseaudio also.
see attached for patch
--- qrq.c_original 2015-04-18 07:53:42.000000000 -0400
+++ qrq.c 2015-04-21 09:51:33.000000000 -0400
@@ -43,6 +43,8 @@
#include <windows.h>
#endif
+
+
#define PI M_PI
#define SILENCE 0 /* Waveforms for the tone generator */
@@ -63,17 +65,20 @@
typedef void *AUDIO_HANDLE;
#endif
-#ifdef OSS
+//#ifdef OSS
#include "oss.h"
#define write_audio(x, y, z) write(x, y, z)
#define close_audio(x) close(x)
typedef int AUDIO_HANDLE;
-#endif
+//#endif
-#ifdef PA
+/**********************************************
+ building with pulseaudio gives cookie error
+#ifdef PA
#include "pulseaudio.h"
typedef void *AUDIO_HANDLE;
#endif
+**********************************************/
/* callsign array will be dynamically allocated */
static char **calls = NULL;
@@ -86,10 +91,10 @@
/* List of available callbase files. Probably no need to do dynamic memory allocation for that list.... */
-static char cblist[100][PATH_MAX];
+static char cblist[100][4096]; // need editing original cblist[100][PATH_MAX]
static char mycall[15]="DJ1YFK"; /* mycall. will be read from qrqrc */
-static char dspdevice[PATH_MAX]="/dev/dsp"; /* will also be read from qrqrc */
+static char *dspdevice; /* will also be read from qrqrc */
static int score = 0; /* qrq score */
static int sending_complete; /* global lock for "enter" while sending */
static int callnr = 0; /* nr of actual call in attempt */
@@ -157,11 +162,11 @@
pthread_attr_t cwattr;
#endif
-char rcfilename[PATH_MAX]=""; /* filename and path to qrqrc */
-char tlfilename[PATH_MAX]=""; /* filename and path to toplist */
-char cbfilename[PATH_MAX]=""; /* filename and path to callbase */
+char *rcfilename; /* filename and path to qrqrc */
+char *tlfilename; /* filename and path to toplist */
+char *cbfilename; /* filename and path to callbase */
-char destdir[PATH_MAX]="";
+char *destdir;
/* create windows */
@@ -172,18 +177,49 @@
WINDOW *inf_w; /* info window for param displ */
WINDOW *right_w; /* highscore list/settings */
-
+/*
+ PATH_MAX
+ 1. tempdir
+ 2. dspdevice
+ 3. tmp
+ 4. cbfilename
+ 5. tlfilename
+*/
int main (int argc, char *argv[]) {
/* if built as osx bundle set DESTDIR to Resources dir of bundle */
#ifdef OSX_BUNDLE
- char tempdir[PATH_MAX]="";
+ char *tempdir;
char* p_slash = strrchr(argv[0], '/');
+
+ tempdir = malloc( strlen(argv[0]));
+ if(tempdir==NULL){
+ printf("Error! memory not allocated.");
+ exit(0);
+ }
strncpy(tempdir, argv[0], p_slash - argv[0]);
+
p_slash = strrchr(tempdir, '/');
+
+
+ destdir = malloc( strlen(tempdir));
+ if(destdir==NULL){
+ printf("Error! memory not allocated.");
+ exit(0);
+ }
strncpy(destdir, tempdir, p_slash - tempdir);
+
+ //realloc(destdir, (strlen(destdir) + strlen("/Resources")) * sizeof(char));
strcat(destdir, "/Resources");
+ free(tempdir)
+
#else
+ destdir = malloc( strlen(DESTDIR));
+ if(destdir==NULL){
+ printf("Error! memory not allocated.");
+ exit(0);
+ }
+
strcpy(destdir, DESTDIR);
#endif
@@ -209,13 +245,16 @@
printw("qrq v%s - Copyright (C) 2006-2013 Fabian Kurz, DJ1YFK\n", VERSION);
printw("This is free software, and you are welcome to redistribute it\n");
printw("under certain conditions (see COPYING).\n");
-
- refresh();
-
+
+ refresh();
+
/* search for 'toplist', 'qrqrc' and callbase.qcb and put their locations
* into tlfilename, rcfilename, cbfilename */
+
+
find_files();
-
+
+
/* check if the toplist is in the suitable format. as of 0.0.7, each line
* is 31 characters long, with the added time stamp */
check_toplist();
@@ -237,6 +276,7 @@
/****** Reading configuration file ******/
printw("\nReading configuration file qrqrc \n");
+
read_config();
attemptvalid = 1;
@@ -245,6 +285,8 @@
}
/****** Reading callsign database ******/
+
+
printw("\nReading callsign database... ");
nrofcalls = read_callbase();
@@ -337,11 +379,11 @@
/* reset */
maxspeed = errornr = score = 0;
- speed = initialspeed;
+ speed = initialspeed;
- /* prompt for own callsign */
+ /* prompt for own callsign */
i = readline(bot_w, 1, 30, mycall, 1);
-
+
/* F5 -> Configure sound */
if (i == 5) {
parameter_dialog();
@@ -544,6 +586,13 @@
delwin(mid_w);
delwin(right_w);
getch();
+
+
+ free(cbfilename);
+ free(dspdevice);
+ free(tlfilename);
+ free(rcfilename);
+
return 0;
}
@@ -635,6 +684,12 @@
break;
#ifdef OSS
case 'e':
+ dspdevice = malloc( 15 * sizeof(char)); // max used in config file
+ if(dspdevice==NULL){
+ printf("Error! memory not allocated.");
+ exit(0);
+ }
+
readline(conf_w, 12, 25, dspdevice, 0);
if (strlen(dspdevice) == 0) {
strcpy(dspdevice, "/dev/dsp");
@@ -791,22 +846,12 @@
-
-
-
-
-
-
-
-
-
-
/* reads a callsign etc. in *win at y/x and writes it to *line */
static int readline(WINDOW *win, int y, int x, char *line, int capitals) {
int c; /* character we read */
int i=0;
-
+
if (strlen(line) == 0) {p=0;} /* cursor to start if no call in buffer */
if (mode == 1) {
@@ -822,7 +867,14 @@
curs_set(TRUE);
while (1) {
+
+ /**********************************
+
+ probable error with wgetch
+
+ **********************************/
c = wgetch(win);
+
if (c == '\n' && sending_complete)
break;
@@ -1158,7 +1210,7 @@
int i=0;
int k=0;
int line=0;
-
+
if ((fh = fopen(rcfilename, "r")) == NULL) {
endwin();
fprintf(stderr, "Unable to open config file %s!\n", rcfilename);
@@ -1218,6 +1270,12 @@
}
tmp[i]='\0';
if (strlen(tmp) > 1) {
+ dspdevice = malloc( 15 * sizeof(char)); // max used in config file
+ if(dspdevice == NULL){
+ printf("Error! memory not allocated.");
+ exit(0);
+ }
+
strcpy(dspdevice,tmp);
printw(" line %2d: dspdevice: >%s<\n", line, dspdevice);
}
@@ -1306,9 +1364,17 @@
i++;
}
tmp[i]='\0';
+
if (strlen(tmp) > 1) {
+ cbfilename = malloc ( strlen(tmp)+1);
+ if(cbfilename==NULL){
+ printf("Error! memory not allocated.");
+ exit(0);
+ }
+
strcpy(cbfilename,tmp);
printw(" line %2d: callbase: >%s<\n", line, cbfilename);
+
}
else {
printw(" line %2d: callbase: >%s< invalid. "
@@ -1324,7 +1390,7 @@
printw(" line %2d: sample rate: %d\n", line, samplerate);
}
}
-
+
printw("Finished reading qrqrc.\n");
return 0;
}
@@ -1734,15 +1800,35 @@
printw("... not found in current directory. Checking "
"%s/.qrq/...\n", homedir);
refresh();
+
+ rcfilename = malloc (strlen(homedir));
+ if(rcfilename == NULL){
+ printf("Error! memory not allocated.");
+ exit(0);
+ }
+
strcat(rcfilename, homedir);
}
else {
printw("... not found in current directory. Checking "
"./.qrq/...\n", homedir);
refresh();
+
+ rcfilename = malloc (strlen(homedir));
+ if(rcfilename==NULL){
+ printf("Error! memory not allocated.");
+ exit(0);
+ }
+
strcat(rcfilename, ".");
}
-
+
+ rcfilename = malloc ((strlen(homedir) + strlen("/.qrq/qrqrc") + 1));
+ if(rcfilename==NULL){
+ printf("Error! memory not allocated.");
+ exit(0);
+ }
+
strcat(rcfilename, "/.qrq/qrqrc");
/* check if there is ~/.qrq/qrqrc. If it's there, it's safe to assume
@@ -1776,6 +1862,13 @@
printw("Found files in %s/share/qrq/."
"\nCreating directory %s/.qrq/ and copy qrqrc and"
" toplist there.\n", destdir, homedir);
+
+ rcfilename = malloc ((strlen(homedir) + strlen( "/.qrq/") + 1));
+ if(rcfilename==NULL){
+ printf("Error! memory not allocated.");
+ exit(0);
+ }
+
strcpy(rcfilename, homedir);
strcat(rcfilename, "/.qrq/");
#ifdef WIN32
@@ -1819,27 +1912,75 @@
"qrqrc according to your needs.\n", homedir);
strcpy(rcfilename, homedir);
strcat(rcfilename, "/.qrq/qrqrc");
+
+ tlfilename = malloc (strlen(homedir));
+ if(tlfilename == NULL){
+ printf("Error! memory not allocated.");
+ exit(0);
+ }
+
strcpy(tlfilename, homedir);
+
+ //realloc(tlfilename, sizeof(char) * (strlen(tlfilename)+strlen("/.qrq/toplist")) );
strcat(tlfilename, "/.qrq/toplist");
+
+ cbfilename = malloc (strlen(tmp_cbfilename));
+ if(cbfilename == NULL){
+ printf("Error! memory not allocated.");
+ exit(0);
+ }
+
strcpy(cbfilename, tmp_cbfilename);
} /* found in DESTDIR/share/qrq/ */
}
else {
printw("... found files in %s/.qrq/.\n", homedir);
+ tlfilename = malloc (strlen(homedir) + 1);
+ if(tlfilename == NULL){
+ printf("Error! memory not allocated.");
+ exit(0);
+ }
+
strcat(tlfilename, homedir);
+
+ //realloc(tlfilename, sizeof(char) * (strlen(tlfilename)+strlen("/.qrq/toplist")) );
strcat(tlfilename, "/.qrq/toplist");
+
+ cbfilename = malloc ((strlen(destdir) + strlen("/share/qrq/callbase.qcb") + 2) );
+ if(cbfilename == NULL){
+ printf("Error! memory not allocated.");
+ exit(0);
+ }
+
strcpy(cbfilename, destdir);
strcat(cbfilename, "/share/qrq/callbase.qcb");
}
}
- else {
- printw("... found in current directory.\n");
+ else {
+
+ printw("... found in current directory.\n");
+
+ rcfilename = malloc(strlen("qrqrc") + 1 );
strcpy(rcfilename, "qrqrc");
+
+ tlfilename = malloc(strlen("toplist") + 1);
strcpy(tlfilename, "toplist");
+
+ cbfilename = malloc(strlen("callbase.qcb")+1);
+ if(cbfilename == NULL){
+ printf("Error! memory not allocated.");
+ exit(0);
+ }
+
strcpy(cbfilename, "callbase.qcb");
+
+
+
}
refresh();
fclose(fh);
+
+
return 0;
}
@@ -1901,9 +2042,11 @@
int nr=0;
if ((fh = fopen(cbfilename, "r")) == NULL) {
- endwin();
+ endwin();
+
fprintf(stderr, "Error: Couldn't read callsign database ('%s')!\n",
cbfilename);
+
exit(EXIT_FAILURE);
}
@@ -1969,8 +2112,8 @@
void find_callbases () {
DIR *dir;
struct dirent *dp;
- char tmp[PATH_MAX];
- char path[3][PATH_MAX];
+ char *tmp;
+ char path[3][4096]; // need editing PATH_MAX original path[3][PATH_MAX]
int i=0,j=0,k=0;
#ifndef WIN32
@@ -1997,8 +2140,15 @@
if (!(dir = opendir(path[k]))) {
continue;
}
-
- while ((dp = readdir(dir))) {
+
+
+ while ((dp = readdir(dir))) {
+ tmp = malloc ( strlen(dp->d_name));
+ if(tmp == NULL){
+ printf("Error! memory not allocated.");
+ exit(0);
+ }
+
strcpy(tmp, dp->d_name);
i = strlen(tmp);
/* find *.qcb files ... */
Reply to: