>>>>> "Pierfrancesco" == Pierfrancesco Caci <[email protected]> writes:
>>>>> "Joseph" == Joseph A Counsil <[email protected]> writes:
Joseph> Greetings, If I create a macro using the <FILE...> macro,
Joseph> and the file exists, all is good. However, if the file does
Joseph> not exist, Fldigi hangs. Would it be good to perform a
Joseph> quick test for the presence of the file, and presentation of
Joseph> an error message if it does not exist?
Joseph> Otherwise, BE is running flawlessly for me on WinXP Pro/SP3.
Pierfrancesco> Hmm, so I defined the macro like this:
Pierfrancesco> // // Macro # 41 /$ 40 prova insert file pippo
Pierfrancesco> <FILE:/home/ik5pvx/pippo> //
Pierfrancesco> and it crashes on ubuntu too.
Pierfrancesco> Full strace attached
Pierfrancesco> Pf
The attached patch fixes this for me. This is way from being elegant,
and probably open a whole warehouse of worm cans.
Pf
diff --git a/src/misc/macros.cxx b/src/misc/macros.cxx
index c60aede..728ae1f 100644
--- a/src/misc/macros.cxx
+++ b/src/misc/macros.cxx
@@ -259,17 +259,26 @@ void pFILE(string &s, size_t &i)
size_t endbracket = s.find('>',i);
string fname = s.substr(i+6, endbracket - i - 6);
if (fname.length() > 0) {
- FILE *toadd = fopen(fname.c_str(), "r");
- string buffer;
- char c = getc(toadd);
- while (c && !feof(toadd)) {
- if (c != '\r') buffer += c; // damn MSDOS txt files
- c = getc(toadd);
- }
- s.replace(i, endbracket - i + 1, buffer);
- fclose(toadd);
+ string buffer;
+ FILE *toadd;
+ if ((toadd=fopen(fname.c_str(), "r")) != NULL) {
+
+ char c = getc(toadd);
+ while (c && !feof(toadd)) {
+ if (c != '\r') buffer += c; // damn MSDOS txt files
+ c = getc(toadd);
+ }
+ s.replace(i, endbracket - i + 1, buffer);
+
+ fclose(toadd);
+ } else {
+ buffer = "< Error opening file ";
+ buffer += fname.c_str();
+ buffer += " >";
+ s.replace(i, endbracket - i + 1, buffer);
+ }
} else
- s.replace(i, endbracket - i + 1, "");
+ s.replace(i, endbracket - i + 1, "");
}
void pTIMER(string &s, size_t &i)
--
Pierfrancesco Caci
_______________________________________________
fldigi-alpha mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/fldigi-alpha