>Richard,
>
>Can you show us a minimal worked example, please - I'm not sure I'm
>grasping what you are doing with the entries() method...
>
>Something complete enough to compile, if possible, as that makes it more
>likely someone will have time to investigate!
Here is a small program and perfs file that demonstrates the problem.
main.cpp
#include <unistd.h>
#include <string.h>
#include <malloc.h>
#include <FL/Fl.H>
#include <FL/Fl_Preferences.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
char **str_tbl;
int main (void)
{
int entries, loop, str_len;
char path[512], name[8];
Fl_Preferences *preference;
getcwd(path, 512);
preference = new Fl_Preferences(path, "I will never tell", "en");
entries = preference->entries(); // this should return 15 with the
preference file supplied but returns 17
if(!entries)
exit(0);
if((str_tbl = (char **)malloc(sizeof(char *) * entries)) == NULL)
exit(1); // malloc failed
for(loop = 0; loop < entries; ++loop)
{
sprintf(name, "%d", loop);
if(!preference->entryExists(name))
exit(2); // should not get to this but loop will have a value of
15 at this point
if((str_len = preference->size(name)) == 0)
exit(3); // oops, name exists but there is no value
if((str_tbl[loop] = (char *)malloc(sizeof(char) * str_len + 1)) ==
NULL)
exit(1); // malloc failed
preference->get((const char *)name, str_tbl[loop], "", str_len +
1);
}
exit(0); // all is well
}
// a snippet from the fluid generated source file
/*
{
Fl_Button* o = btn_circle = new Fl_Button(5, 3, 130, 36);
btn_circle->callback((Fl_Callback*)cb_btn_circle, (void*)((int
*)1));
btn_circle->align(Fl_Align(FL_ALIGN_WRAP));
o->label((char *)str_tbl[0]);
}
*/
en.perfs
; FLTK preferences file format 1.0
; vendor: I will never tell
; application: en
[.]
; button menu on the left
0:Chord, Arc and Sector
1:Triangle one
2:Triangle two
3:Dovetail
4:Bolt circle
5:Thread measurement
6:Dividing head
7:Tap drill
8:Regular Polygon (hexagons etc.)
9:Set metric as default
10:Set inch as default
11:About
12:Quit
; the window title
13:Metal Shop Calculator (metric mode)
14:Metal Shop Calculator (inch mode)
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk