Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
purr-data
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jonathan Wilkes
purr-data
Commits
9366e8ef
There was a problem fetching the pipeline summary.
Commit
9366e8ef
authored
8 years ago
by
Jonathan Wilkes
Browse files
Options
Downloads
Plain Diff
Merge branch 'aggraef/purr-data-osx-saveprefs-fixes'
parents
e84482b1
1dabebb8
No related branches found
No related tags found
No related merge requests found
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pd/src/s_file.c
+41
-11
41 additions, 11 deletions
pd/src/s_file.c
with
41 additions
and
11 deletions
pd/src/s_file.c
+
41
−
11
View file @
9366e8ef
...
@@ -269,11 +269,6 @@ static char *sys_prefbuf;
...
@@ -269,11 +269,6 @@ static char *sys_prefbuf;
// with the previous method which invoked 'defaults read' on each individual
// with the previous method which invoked 'defaults read' on each individual
// key.
// key.
// XXXTODO: In principle, this approach should also work in reverse to import
// the data into the defaults storage in one go. Presumably this should also
// be much faster than the current implementation which invokes the shell to
// run 'defaults write' for each individual key.
static
void
sys_initloadpreferences
(
void
)
static
void
sys_initloadpreferences
(
void
)
{
{
char
cmdbuf
[
MAXPDSTRING
],
*
buf
;
char
cmdbuf
[
MAXPDSTRING
],
*
buf
;
...
@@ -317,7 +312,7 @@ static void sys_initloadpreferences(void)
...
@@ -317,7 +312,7 @@ static void sys_initloadpreferences(void)
// stages of the pipe are:
// stages of the pipe are:
// 1. defaults export: grab our defaults in XML format
// 1. defaults export: grab our defaults in XML format
// 2. plutil -convert json -r -o - -: convert to JSON
// 2. plutil -convert json -r -o - -: convert to JSON
// 3. sed: a few edits remove the extra JSON bits (curly bra
n
ces, string
// 3. sed: a few edits remove the extra JSON bits (curly braces, string
// quotes, unwanted whitespace and character escapes) and produce
// quotes, unwanted whitespace and character escapes) and produce
// Pd-L2Ork's Unix prefs format, i.e.:
// Pd-L2Ork's Unix prefs format, i.e.:
// JSON --> Unix prefs
// JSON --> Unix prefs
...
@@ -413,21 +408,56 @@ static void sys_doneloadpreferences( void)
...
@@ -413,21 +408,56 @@ static void sys_doneloadpreferences( void)
sys_prefbuf
=
NULL
;
sys_prefbuf
=
NULL
;
}
}
// AG: We use a similar approach here to import the data into the defaults
// storage in one go. To these ends, a temporary plist file in xml format is
// created which is then submitted to 'defaults import'. This is *much* faster
// than the previous implementation which invoked the shell to run 'defaults
// write' for each individual key.
#define save_prefs_template "/tmp/pd-l2ork.defaults.plist.XXXXXX"
static
FILE
*
save_fp
;
static
char
save_prefs
[]
=
save_prefs_template
;
static
void
sys_initsavepreferences
(
void
)
static
void
sys_initsavepreferences
(
void
)
{
{
strcpy
(
save_prefs
,
save_prefs_template
);
int
fd
=
mkstemp
(
save_prefs
);
if
(
fd
<
0
)
{
error
(
"save preferences: %s"
,
strerror
(
errno
));
return
;
}
save_fp
=
fdopen
(
fd
,
"w"
);
if
(
!
save_fp
)
{
error
(
"save preferences: %s"
,
strerror
(
errno
));
return
;
}
fprintf
(
save_fp
,
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?>
\n
"
"<!DOCTYPE plist PUBLIC
\"
-//Apple Computer//DTD PLIST 1.0//EN
\"
\"
http://www.apple.com/DTDs/PropertyList-1.0.dtd
\"
>
\n
"
"<plist version=
\"
1.0
\"
>
\n
"
"<dict>
\n
"
);
}
}
static
void
sys_putpreference
(
const
char
*
key
,
const
char
*
value
)
static
void
sys_putpreference
(
const
char
*
key
,
const
char
*
value
)
{
{
char
cmdbuf
[
MAXPDSTRING
];
if
(
!
save_fp
)
return
;
snprintf
(
cmdbuf
,
MAXPDSTRING
,
fprintf
(
save_fp
,
"defaults write '%s' %s
\"
%s
\"
2> /dev/null
\n
"
,
"<key>%s</key>
\n
<string>%s</string>
\n
"
,
current_prefs
,
key
,
value
);
key
,
value
);
system
(
cmdbuf
);
}
}
static
void
sys_donesavepreferences
(
void
)
static
void
sys_donesavepreferences
(
void
)
{
{
if
(
!
save_fp
)
return
;
fprintf
(
save_fp
,
"</dict>
\n
</plist>
\n
"
);
fclose
(
save_fp
);
save_fp
=
0
;
char
cmdbuf
[
MAXPDSTRING
];
snprintf
(
cmdbuf
,
MAXPDSTRING
,
"defaults import '%s' '%s' 2> /dev/null"
,
current_prefs
,
save_prefs
);
system
(
cmdbuf
);
unlink
(
save_prefs
);
}
}
#endif
/* __APPLE__ */
#endif
/* __APPLE__ */
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment