32 #if defined(WIN32) && !defined(__CYGWIN__) 38 # define access _access 40 #elif defined (__APPLE__) 41 # include <ApplicationServices/ApplicationServices.h> 58 typedef RPC_STATUS (WINAPI* uuid_func)(UUID __RPC_FAR *Uuid);
60 # include <sys/time.h> 84 CFUUIDRef theUUID = CFUUIDCreate(
NULL);
85 CFUUIDBytes
b = CFUUIDGetUUIDBytes(theUUID);
86 sprintf(
uuidBuffer,
"%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
87 b.byte0,
b.byte1,
b.byte2,
b.byte3,
b.byte4,
b.byte5,
b.byte6,
b.byte7,
88 b.byte8,
b.byte9,
b.byte10,
b.byte11,
b.byte12,
b.byte13,
b.byte14,
b.byte15);
95 static HMODULE hMod =
NULL;
101 hMod = LoadLibrary(
"Rpcrt4.dll");
105 uuid_func uuid_crt = (uuid_func)GetProcAddress(hMod,
"UuidCreate");
106 if (uuid_crt !=
NULL) {
107 RPC_STATUS rpc_res = uuid_crt(pu);
109 (rpc_res == RPC_S_OK) ||
110 (rpc_res == RPC_S_UUID_LOCAL_ONLY) ||
111 (rpc_res == RPC_S_UUID_NO_ADDRESS)
114 sprintf(
uuidBuffer,
"%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
115 pu->Data1, pu->Data2, pu->Data3, pu->Data4[0], pu->Data4[1],
116 pu->Data4[2], pu->Data4[3], pu->Data4[4],
117 pu->Data4[5], pu->Data4[6], pu->Data4[7]);
124 b[0] = (
unsigned char)t;
125 b[1] = (
unsigned char)(t>>8);
126 b[2] = (
unsigned char)(t>>16);
127 b[3] = (
unsigned char)(t>>24);
129 b[4] = (
unsigned char)r;
130 b[5] = (
unsigned char)(r>>8);
131 b[6] = (
unsigned char)(r>>16);
132 b[7] = (
unsigned char)(r>>24);
137 union {
void *pv;
unsigned char a[
sizeof(
void*)]; } v;
144 TCHAR
name[MAX_COMPUTERNAME_LENGTH + 1];
145 DWORD nSize = MAX_COMPUTERNAME_LENGTH + 1;
148 GetComputerName(
name, &nSize);
150 for (
int ii = 0; ii < 4; ii++) {
151 b[12 + ii] = (
unsigned char)
name[ii];
153 sprintf(
uuidBuffer,
"%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
154 b[0],
b[1],
b[2],
b[3],
b[4],
b[5],
b[6],
b[7],
155 b[8],
b[9],
b[10],
b[11],
b[12],
b[13],
b[14],
b[15]);
163 b[0] = (
unsigned char)t;
164 b[1] = (
unsigned char)(t>>8);
165 b[2] = (
unsigned char)(t>>16);
166 b[3] = (
unsigned char)(t>>24);
168 b[4] = (
unsigned char)r;
169 b[5] = (
unsigned char)(r>>8);
170 b[6] = (
unsigned char)(r>>16);
171 b[7] = (
unsigned char)(r>>24);
172 unsigned long a = (
unsigned long)&t;
173 b[8] = (
unsigned char)a;
174 b[9] = (
unsigned char)(a>>8);
175 b[10] = (
unsigned char)(a>>16);
176 b[11] = (
unsigned char)(a>>24);
181 union {
void *pv;
unsigned char a[
sizeof(
void*)]; } v;
185 b[8] = v.a[
sizeof(
void*) - 1];
186 b[9] = v.a[
sizeof(
void*) - 2];
187 b[10] = v.a[
sizeof(
void*) - 3];
188 b[11] = v.a[
sizeof(
void*) - 4];
196 gethostname(
name, 79);
197 memcpy(
b+12,
name, 4);
198 sprintf(
uuidBuffer,
"%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
199 b[0],
b[1],
b[2],
b[3],
b[4],
b[5],
b[6],
b[7],
200 b[8],
b[9],
b[10],
b[11],
b[12],
b[13],
b[14],
b[15]);
310 if (groupIndex<0 || groupIndex>=parent.
groups()) {
322 if (groupIndex<0 || groupIndex>=parent->
groups()) {
350 rootNode(rhs.rootNode)
427 if ( nd )
return nd->
remove();
511 value = v ? atoi( v ) : defaultValue;
543 value = v ? (float)atof( v ) : defaultValue;
575 sprintf(
nameBuffer,
"%.*g", precision, value );
592 value = v ? atof( v ) : defaultValue;
624 sprintf(
nameBuffer,
"%.*g", precision, value );
633 for ( ; *s; s++, len++ ) {
635 if ( isdigit( s[1] ) ) {
642 char *dst = (
char*)
malloc( len+1 ), *d = dst;
643 for ( s = src; *s; s++ ) {
646 if ( s[1] ==
'\\' ) { *d++ = c; s++; }
647 else if ( s[1] ==
'n' ) { *d++ =
'\n'; s++; }
648 else if ( s[1] ==
'r' ) { *d++ =
'\r'; s++; }
649 else if ( isdigit( s[1] ) ) { *d++ = ((s[1]-
'0')<<6) + ((s[2]-
'0')<<3) + (s[3]-
'0'); s+=3; }
674 if ( v && strchr( v,
'\\' ) ) {
680 if ( !v ) v = defaultValue;
681 if ( v )
strlcpy(text, v, maxSize);
683 return ( v != defaultValue );
700 if ( v && strchr( v,
'\\' ) ) {
704 if ( !v ) v = defaultValue;
709 return ( v != defaultValue );
723 const char *s = text ? text :
"";
725 for ( ; *s; s++ ) { n++;
if ( *s<32 || *s==
'\\' || *s==0x7f ) ns+=4; }
728 for ( s=text; *s; ) {
730 if ( c==
'\\' ) { *d++ =
'\\'; *d++ =
'\\'; s++; }
731 else if ( c==
'\n' ) { *d++ =
'\\'; *d++ =
'n'; s++; }
732 else if ( c==
'\r' ) { *d++ =
'\\'; *d++ =
'r'; s++; }
733 else if ( c<32 || c==0x7f )
734 { *d++ =
'\\'; *d++ =
'0'+((c>>6)&3); *d++ =
'0'+((c>>3)&7); *d++ =
'0'+(c&7); s++; }
748 size = (int) strlen( src )/2;
749 unsigned char *data = (
unsigned char*)
malloc( size ), *d = data;
751 for (
int i=size; i>0; i-- ) {
753 char x = tolower(*s++);
754 if (
x >=
'a' ) v =
x-
'a'+10;
else v =
x-
'0';
757 if (
x >=
'a' ) v +=
x-
'a'+10;
else v +=
x-
'0';
783 memmove( data, w, dsize>maxSize?maxSize:dsize );
788 memmove( data, defaultValue, defaultSize>maxSize?maxSize:defaultSize );
812 if ( defaultValue ) {
813 data = (
void*)
malloc( defaultSize );
814 memmove( data, defaultValue, defaultSize );
834 unsigned char *s = (
unsigned char*)data;
835 for ( ; dsize>0; dsize-- ) {
836 static char lu[] =
"0123456789abcdef";
837 unsigned char v = *s++;
855 return (
int) (v ? strlen( v ) : 0);
920 sprintf(
data_,
"%u", n);
937 data_ = (
char*)
malloc(1024);
939 va_start(args, format);
968 # define FLPREFS_RESOURCE "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders" 969 # define FLPREFS_RESOURCEW L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders" 970 size_t appDataLen = strlen(vendor) + strlen(application) + 8;
977 err = RegOpenKeyW( HKEY_LOCAL_MACHINE, FLPREFS_RESOURCEW, &
key );
978 if (err == ERROR_SUCCESS) {
980 err = RegQueryValueExW(
key, L
"Common AppData", 0L, &type,
982 if ( ( err != ERROR_SUCCESS ) && ( type == REG_SZ ) ) {
990 err = RegOpenKeyW( HKEY_CURRENT_USER, FLPREFS_RESOURCEW, &
key );
991 if (err == ERROR_SUCCESS) {
993 err = RegQueryValueExW(
key, L
"AppData", 0L, &type,
995 if ( ( err != ERROR_SUCCESS ) && ( type == REG_SZ ) ) {
1021 "/%s/%s.prefs", vendor, application);
1022 for (
char *s =
filename; *s; s++)
if (*s ==
'\\') *s =
'/';
1023 #elif defined ( __APPLE__ ) 1029 strcpy(
filename,
"/Library/Preferences");
1036 "/%s/%s.prefs", vendor, application );
1056 "%s/%s.prefs", vendor, application);
1075 application =
"unknown";
1098 if ( prefs_->node->dirty() )
1108 if ( application_ ) {
1109 free( application_ );
1112 delete prefs_->node;
1124 if (fgets(
buf, 1024,
f )==0) { }
1125 if (fgets(
buf, 1024,
f )==0) { }
1126 if (fgets(
buf, 1024,
f )==0) { }
1127 Node *nd = prefs_->node;
1129 if ( !fgets(
buf, 1024,
f ) )
break;
1130 if (
buf[0]==
'[' ) {
1131 size_t end = strcspn(
buf+1,
"]\n\r" );
1133 nd = prefs_->node->
find(
buf+1 );
1134 }
else if (
buf[0]==
'+' ) {
1135 size_t end = strcspn(
buf+1,
"\n\r" );
1141 size_t end = strcspn(
buf,
"\n\r" );
1160 fprintf(
f,
"; FLTK preferences file format 1.0\n" );
1161 fprintf(
f,
"; vendor: %s\n", vendor_ );
1162 fprintf(
f,
"; application: %s\n", application_ );
1163 prefs_->node->write(
f );
1165 #if !(defined(__APPLE__) || defined(WIN32)) 1167 if (strncmp(filename_,
"/etc/fltk/", 10) == 0) {
1174 p = strchr(
p+1,
'/');
1189 for ( s =
path; *s; s++ )
if ( *s ==
'\\' ) *s =
'/';
1190 s = strrchr(
path,
'.' );
1194 #if !(defined(__APPLE__) || defined(WIN32)) 1196 if (strncmp(
path,
"/etc/fltk/", 10) == 0) {
1207 if (
path ) path_ = strdup(
path );
else path_ = 0;
1208 child_ = 0; next_ = 0; parent_ = 0;
1210 nEntry_ = NEntry_ = 0;
1215 nIndex_ = NIndex_ = 0;
1220 for (
Node *nd = child_; nd; nd = nx ) {
1231 for (
int i = 0; i < nEntry_; i++ ) {
1232 if ( entry_[i].
name ) {
1234 entry_[i].name = 0L;
1236 if ( entry_[i].value ) {
1237 free( entry_[i].value );
1238 entry_[i].value = 0L;
1251 deleteAllChildren();
1264 if ( dirty_ )
return 1;
1265 if ( next_ && next_->dirty() )
return 1;
1266 if ( child_ && child_->dirty() )
return 1;
1274 if ( next_ ) next_->write(
f );
1275 fprintf(
f,
"\n[%s]\n\n", path_ );
1276 for (
int i = 0; i < nEntry_; i++ ) {
1277 char *src = entry_[i].value;
1279 fprintf(
f,
"%s:", entry_[i].
name );
1280 size_t cnt, written = 0;
1281 for ( cnt = 0; cnt < 60; cnt++ )
1282 if ( src[cnt]==0 )
break;
1283 written += fwrite( src, cnt, 1,
f );
1287 for ( cnt = 0; cnt < 80; cnt++ )
1288 if ( src[cnt]==0 )
break;
1290 written += fwrite( src, cnt, 1,
f );
1296 fprintf(
f,
"%s\n", entry_[i].
name );
1298 if ( child_ ) child_->write(
f );
1338 for (
int i=0; i<nEntry_; i++ ) {
1339 if ( strcmp(
name, entry_[i].
name ) == 0 ) {
1340 if ( !value )
return;
1341 if ( strcmp( value, entry_[i].value ) != 0 ) {
1342 if ( entry_[i].value )
1343 free( entry_[i].value );
1344 entry_[i].value = strdup( value );
1351 if ( NEntry_==nEntry_ ) {
1352 NEntry_ = NEntry_ ? NEntry_*2 : 10;
1353 entry_ = (
Entry*)realloc( entry_, NEntry_ *
sizeof(
Entry) );
1355 entry_[ nEntry_ ].name = strdup(
name );
1356 entry_[ nEntry_ ].value = value?strdup( value ):0;
1357 lastEntrySet = nEntry_;
1367 if ( line[0]==
';' || line[0]==0 || line[0]==
'#' ) {
1370 const char *c = strchr( line,
':' );
1372 size_t len = c-line+1;
1386 if ( lastEntrySet<0 || lastEntrySet>=nEntry_ )
return;
1387 char *&dst = entry_[ lastEntrySet ].value;
1388 size_t a = strlen( dst );
1389 size_t b = strlen( line );
1390 dst = (
char*)realloc( dst, a+
b+1 );
1391 memcpy( dst+a, line,
b+1 );
1397 int i = getEntry(
name );
1398 return i>=0 ? entry_[i].value : 0 ;
1403 for (
int i=0; i<nEntry_; i++ ) {
1404 if ( strcmp(
name, entry_[i].
name ) == 0 ) {
1413 int ix = getEntry(
name );
1414 if ( ix == -1 )
return 0;
1415 memmove( entry_+ix, entry_+ix+1, (nEntry_-ix-1) *
sizeof(
Entry) );
1425 int len = (int) strlen( path_ );
1426 if ( strncmp(
path, path_, len ) == 0 ) {
1427 if (
path[ len ] == 0 )
1429 if (
path[ len ] ==
'/' ) {
1431 for ( nd = child_; nd; nd = nd->
next_ ) {
1433 if ( nn )
return nn;
1435 const char *s =
path+len+1;
1436 const char *e = strchr( s,
'/' );
1455 if (
path[0] ==
'.' ) {
1456 if (
path[1] == 0 ) {
1458 }
else if (
path[1] ==
'/' ) {
1467 offset = (int) strlen( path_ ) + 1;
1469 int len = (int) strlen( path_ );
1470 if ( len <
offset-1 )
return 0;
1472 if ( ( len <= 0 ) || ( strncmp(
path, path_+
offset, len ) == 0 ) ) {
1473 if ( len > 0 &&
path[ len ] == 0 )
1475 if ( len <= 0 ||
path[ len ] ==
'/' ) {
1476 for (
Node *nd = child_; nd; nd = nd->
next_ ) {
1478 if ( nn )
return nn;
1492 for (
Node *nd = child_; nd; nd = nd->
next_ )
1501 char *r = strrchr( path_,
'/' );
1502 return r ? r+1 : path_ ;
1510 Node *nd = childNode( ix );
1525 int n = nChildren();
1528 for ( nd = child_; nd; nd = nd->
next_ ) {
1540 nd = parent()->
child_; np = 0L;
1541 for ( ; nd; np = nd, nd = nd->
next_ ) {
1551 parent()->updateIndex();
1558 if (indexed_)
return;
1559 int n = nChildren();
1562 index_ = (
Node**)realloc(index_, NIndex_*
sizeof(
Node**));
1566 for (nd = child_; nd; nd = nd->
next_, i++) {
1578 if (index_)
free(index_);
1579 NIndex_ = nIndex_ = 0;
1592 #ifdef FL_PLUGIN_VERBOSE 1593 printf(
"Fl_Plugin: creating a plugin, class \"%s\", name \"%s\"\n",
1604 #ifdef FL_PLUGIN_VERBOSE 1605 printf(
"Fl_Plugin: deleting a plugin\n");
1616 #ifdef FL_PLUGIN_VERBOSE 1617 printf(
"Fl_Plugin: creating a plugin manager for class \"%s\"\n", klass);
1628 #ifdef FL_PLUGIN_VERBOSE 1629 printf(
"Fl_Plugin: deleting a plugin manager\n");
1633 static unsigned char x2i(
char hi,
char lo) {
1634 return ((hi-
'A')<<4) | (lo-
'A');
1637 static void i2x(
unsigned char v,
char *d) {
1638 d[0] = ((v>>4)&0x0f)+
'A'; d[1] = (v&0x0f)+
'A';
1641 static void *
a2p(
const char *s) {
1642 union {
void *ret;
unsigned char d[
sizeof(
void*)]; } v;
1644 int i=0, n=
sizeof(
void*);
1645 for (i=0; i<n; i++) {
1646 v.d[i] =
x2i(s[2*i], s[2*i+1]);
1651 static void p2a(
void *vp,
char *d) {
1652 union {
void *vp;
unsigned char s[
sizeof(
void*)]; } v;
1654 int i=0, n=
sizeof(
void*);
1655 for (i=0; i<n; i++) {
1668 pin.
get(
"address",
buf,
"", 34);
1670 #ifdef FL_PLUGIN_VERBOSE 1671 printf(
"Fl_Plugin: returning plugin at index %d: (%s) %p\n", index,
buf, ret);
1684 pin.
get(
"address",
buf,
"", 34);
1686 #ifdef FL_PLUGIN_VERBOSE 1687 printf(
"Fl_Plugin: returning plugin named \"%s\": (%s) %p\n",
name,
buf, ret);
1691 #ifdef FL_PLUGIN_VERBOSE 1692 printf(
"Fl_Plugin: no plugin found named \"%s\"\n",
name);
1706 #ifdef FL_PLUGIN_VERBOSE 1707 printf(
"Fl_Plugin: adding plugin named \"%s\" at 0x%p\n",
name,
plugin);
1736 #if defined(WIN32) && !defined(__CYGWIN__) 1737 HMODULE dl = LoadLibrary(
filename);
1745 return (dl!=0) ? 0 : -1;
1754 for (i=0; i<n; i++) {