Hello All, i did some modifications on the bug, see attached, but when i try to run the program i get the following error:
Failed to write cookie file: Unknown error .. " when trying to run the program, happens at line 381 i = readline(bot_w, 1, 30, mycall, 1); Any ideas?
--- qrq.c_original 2015-04-18 07:53:42.000000000 -0400 +++ qrq.c 2015-04-18 08:25:34.000000000 -0400 @@ -86,10 +86,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 +157,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 +172,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 +240,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 +271,7 @@ /****** Reading configuration file ******/ printw("\nReading configuration file qrqrc \n"); + read_config(); attemptvalid = 1; @@ -245,6 +280,8 @@ } /****** Reading callsign database ******/ + + printw("\nReading callsign database... "); nrofcalls = read_callbase(); @@ -339,8 +376,10 @@ maxspeed = errornr = score = 0; speed = initialspeed; - /* prompt for own callsign */ + /* prompt for own callsign */ + i = readline(bot_w, 1, 30, mycall, 1); + /* F5 -> Configure sound */ if (i == 5) { @@ -544,6 +583,13 @@ delwin(mid_w); delwin(right_w); getch(); + + + free(cbfilename); + free(dspdevice); + free(tlfilename); + free(rcfilename); + return 0; } @@ -635,6 +681,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"); @@ -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,77 @@ "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"); + + //realloc(rcfilename, sizeof(char) * (strlen(rcfilename)+strlen("qrqrc")+1) ); + rcfilename = malloc(strlen("qrqrc") + 1 ); strcpy(rcfilename, "qrqrc"); + + tlfilename = malloc(strlen("toplist") + 1); strcpy(tlfilename, "toplist"); + + // gold + 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 +2044,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 +2114,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 +2142,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 ... */