summaryrefslogtreecommitdiff
path: root/app/wlib/gtklib/wpref.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2022-02-06 16:04:57 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2022-02-06 16:04:57 +0100
commit59dccf358523dfc7679d1d8c120452a71e42243c (patch)
treef0f3cc006e8157d6bd699bd644b7dd7b35387ac2 /app/wlib/gtklib/wpref.c
parentfd6639655b399a79fb72f494786a4f57da9c90e7 (diff)
parentd0ca838c7ab297036b4a7c45351761a48fe05efd (diff)
Merge branch 'feature/upstrem' into develop
Diffstat (limited to 'app/wlib/gtklib/wpref.c')
-rw-r--r--app/wlib/gtklib/wpref.c80
1 files changed, 55 insertions, 25 deletions
diff --git a/app/wlib/gtklib/wpref.c b/app/wlib/gtklib/wpref.c
index 124305a..3494ba2 100644
--- a/app/wlib/gtklib/wpref.c
+++ b/app/wlib/gtklib/wpref.c
@@ -62,8 +62,8 @@ static char userHomeDir[BUFSIZ];
* The search order is:
* 1. Directory specified by the XTRKCADLIB environment variable
* 2. Directory specified by XTRKCAD_INSTALL_PREFIX/share/xtrkcad
- * 3. /usr/lib/xtrkcad
- * 4. /usr/local/lib/xtrkcad
+ * 3. /usr/share/xtrkcad
+ * 4. /usr/local/share/xtrkcad
*
* \return pointer to directory name
*/
@@ -86,39 +86,48 @@ const char * wGetAppLibDir( void )
if (ep != NULL) {
if ((stat( ep, &buf) == 0 ) && S_ISDIR( buf.st_mode)) {
strncpy( appLibDir, ep, sizeof appLibDir );
+ //printf( "wAppLbDir=%s\n", appLibDir );
return appLibDir;
}
}
- strcpy(appLibDir, XTRKCAD_INSTALL_PREFIX);
- strcat(appLibDir, "/share/");
+ strcpy(appLibDir, "../share/");
strcat(appLibDir, wlibGetAppName());
-
if ((stat( appLibDir, &buf) == 0 ) && S_ISDIR( buf.st_mode)) {
+ //printf( "wAppLbDir=%s\n", appLibDir );
return appLibDir;
}
- strcpy( appLibDir, "/usr/lib/" );
+ char * dir1 = "/usr/share/";
+ char * dir2 = "/usr/local/share/";
+ if ( strstr( XTRKCAD_VERSION, "Beta" ) != NULL ) {
+ dir1 = "/usr/local/share/";
+ dir2 = "/usr/share/";
+ }
+
+ strcpy( appLibDir, dir1 );
strcat( appLibDir, wlibGetAppName() );
if ((stat( appLibDir, &buf) == 0 ) && S_ISDIR( buf.st_mode)) {
+ //printf( "wAppLbDir=%s\n", appLibDir );
return appLibDir;
}
- strcpy( appLibDir, "/usr/local/lib/" );
+ strcpy( appLibDir, dir2 );
strcat( appLibDir, wlibGetAppName() );
if ((stat( appLibDir, &buf) == 0 ) && S_ISDIR( buf.st_mode)) {
+ //printf( "wAppLbDir=%s\n", appLibDir );
return appLibDir;
}
sprintf( msg,
_("The required configuration files could not be located in the expected location.\n\n"
"Usually this is an installation problem. Make sure that these files are installed in either \n"
- " %s/share/xtrkcad or\n"
- " /usr/lib/%s or\n"
- " /usr/local/lib/%s\n"
+ " ../share/xtrkcad or\n"
+ " /usr/share/%s or\n"
+ " /usr/local/share/%s\n"
"If this is not possible, the environment variable %s must contain "
"the name of the correct directory."),
- XTRKCAD_INSTALL_PREFIX, wlibGetAppName(), wlibGetAppName(), envvar );
+ wlibGetAppName(), wlibGetAppName(), envvar );
wNoticeEx( NT_ERROR, msg, _("Ok"), NULL );
appLibDir[0] = '\0';
wExit(0);
@@ -223,7 +232,7 @@ wBool_t prefInitted = FALSE;
* Read the configuration file into memory
*/
-static void readPrefs( void )
+static void readPrefs( char * name, wBool_t update )
{
char tmp[BUFSIZ], *np, *vp, *cp;
const char * workDir;
@@ -232,7 +241,10 @@ static void readPrefs( void )
prefInitted = TRUE;
workDir = wGetAppWorkDir();
- sprintf( tmp, "%s/%s.rc", workDir, wConfigName );
+ if (name && name[0])
+ sprintf( tmp, "%s", name );
+ else
+ sprintf( tmp, "%s/%s.rc", workDir, wConfigName );
prefFile = fopen( tmp, "r" );
if (prefFile == NULL)
return;
@@ -260,12 +272,23 @@ static void readPrefs( void )
cp = vp + strlen(vp) -1;
while ( cp >= vp && (*cp=='\n' || *cp==' ' || *cp=='\t') ) cp--;
cp[1] = '\0';
- DYNARR_APPEND( prefs_t, prefs_da, 10 );
- p = &prefs(prefs_da.cnt-1);
- p->name = strdup(np);
- p->section = strdup(sp);
- p->dirty = FALSE;
- p->val = strdup(vp);
+ if (update) {
+ for (int i=0;i<prefs_da.cnt;i++) {
+ p = &DYNARR_N(prefs_t,prefs_da,i);
+ if (strcmp(p->name,np)==0 && strcmp(p->section,sp)==0) {
+ p->val = strdup(vp);
+ p->dirty = TRUE;
+ break;
+ }
+ }
+ } else {
+ DYNARR_APPEND( prefs_t, prefs_da, 10 );
+ p = &prefs(prefs_da.cnt-1);
+ p->name = strdup(np);
+ p->section = strdup(sp);
+ p->dirty = FALSE;
+ p->val = strdup(vp);
+ }
}
fclose( prefFile );
}
@@ -286,7 +309,7 @@ void wPrefSetString(
prefs_t * p;
if (!prefInitted)
- readPrefs();
+ readPrefs("", FALSE);
for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) {
if ( strcmp( p->section, section ) == 0 && strcmp( p->name, name ) == 0 ) {
@@ -319,7 +342,7 @@ char * wPrefGetStringBasic(
prefs_t * p;
if (!prefInitted)
- readPrefs();
+ readPrefs("", FALSE);
for (p=&prefs(0); p<&prefs(prefs_da.cnt); p++) {
if ( strcmp( p->section, section ) == 0 && strcmp( p->name, name ) == 0 ) {
@@ -344,7 +367,7 @@ char * wPrefGetStringBasic(
{
char tmp[20];
- sprintf(tmp, "%ld", lval );
+ snprintf(tmp, sizeof(tmp), "%ld", lval );
wPrefSetString( section, name, tmp );
}
@@ -395,7 +418,7 @@ wBool_t wPrefGetIntegerBasic(
{
char tmp[20];
- sprintf(tmp, "%0.6f", lval );
+ snprintf(tmp, sizeof(tmp), "%0.6f", lval );
wPrefSetString( section, name, tmp );
}
@@ -432,6 +455,10 @@ wBool_t wPrefGetFloatBasic(
return TRUE;
}
+void wPrefsLoad(char * name) {
+ readPrefs(name,TRUE);
+}
+
/**
* Save the configuration to a file. The config parameters are held and updated in an array.
* To make the settings persistant, this function has to be called.
@@ -439,7 +466,7 @@ wBool_t wPrefGetFloatBasic(
*/
void wPrefFlush(
- void )
+ char * name )
{
prefs_t * p;
char tmp[BUFSIZ];
@@ -450,7 +477,10 @@ void wPrefFlush(
return;
workDir = wGetAppWorkDir();
- sprintf( tmp, "%s/%s.rc", workDir, wConfigName );
+ if (name && name[0])
+ snprintf( tmp, sizeof(tmp), "%s", name );
+ else
+ snprintf( tmp, sizeof(tmp), "%s/%s.rc", workDir, wConfigName );
prefFile = fopen( tmp, "w" );
if (prefFile == NULL)
return;