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
Package Registry
Model registry
Operate
Environments
Terraform modules
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
brittney allen
purr-data
Commits
cf3769a6
Commit
cf3769a6
authored
8 years ago
by
Jonathan Wilkes
Browse files
Options
Downloads
Plain Diff
Merge branch 'aggraef/purr-data-osx-loadprefs-fixes'
parents
9366e8ef
a6a61b00
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/darwin_app/org.puredata.pd-l2ork.default.plist
+1
-1
1 addition, 1 deletion
packages/darwin_app/org.puredata.pd-l2ork.default.plist
pd/src/s_file.c
+18
-19
18 additions, 19 deletions
pd/src/s_file.c
with
19 additions
and
20 deletions
packages/darwin_app/org.puredata.pd-l2ork.default.plist
+
1
−
1
View file @
cf3769a6
...
...
@@ -5,7 +5,7 @@
<key>
defeatrt
</key>
<string>
0
</string>
<key>
flags
</key>
<string>
-helppath ~/Library/Pd -helppath /Library/Pd
</string>
<string>
-helppath ~/Library/Pd
-l2ork
-helppath /Library/Pd
-l2ork
</string>
<key>
loadlib1
</key>
<string>
libdir
</string>
<key>
loadlib2
</key>
...
...
This diff is collapsed.
Click to expand it.
pd/src/s_file.c
+
18
−
19
View file @
cf3769a6
...
...
@@ -259,15 +259,14 @@ static char *sys_prefbuf;
#define BUFSZ 4096
// AG: We have to go to some lengths here since 'defaults read' doesn't
// properly deal with UTF-8 characters in the prefs data. 'defaults export'
// does the trick, however, so we use that to read the entire prefs data at
// once from a pipe, using plutil to convert the resulting data to JSON format
// which can then be translated to Pd's Unix preferences file format using
// sed. The result is stored in a character buffer for efficient access. From
// there we can retrieve the individual keys in the same fashion as on Unix. A
// welcome side effect is that loading the prefs is *much* faster now than
// with the previous method which invoked 'defaults read' on each individual
// key.
// properly deal with UTF-8 characters in the prefs data. 'plutil' does the
// trick, however, so we use that to read the entire prefs data at once from a
// pipe, converting it to JSON format which can then be translated to Pd's
// Unix preferences file format using sed. The result is stored in a character
// buffer for efficient access. From there we can retrieve the individual keys
// in the same fashion as on Unix. A welcome side effect is that loading the
// prefs is *much* faster now than with the previous method which invoked
// 'defaults read' on each individual key.
static
void
sys_initloadpreferences
(
void
)
{
...
...
@@ -275,8 +274,9 @@ static void sys_initloadpreferences(void)
FILE
*
fp
;
size_t
sz
,
n
=
0
;
int
res
;
char
default_prefs
[
FILENAME_MAX
];
// default prefs embedded in the package
char
default_prefs
[
FILENAME_MAX
];
// default prefs embedded in the package
char
embedded_prefs
[
FILENAME_MAX
];
// overrides others for standalone app
char
user_prefs
[
FILENAME_MAX
];
// user preferences
char
embedded_prefs_file
[
FILENAME_MAX
];
char
user_prefs_file
[
FILENAME_MAX
];
const
char
*
prefs
,
*
homedir
=
getenv
(
"HOME"
);
...
...
@@ -292,9 +292,10 @@ static void sys_initloadpreferences(void)
snprintf
(
embedded_prefs
,
FILENAME_MAX
,
"%s/../org.puredata.pd-l2ork"
,
sys_libdir
->
s_name
);
snprintf
(
user_prefs
,
FILENAME_MAX
,
"%s/Library/Preferences/org.puredata.pd-l2ork"
,
homedir
);
snprintf
(
embedded_prefs_file
,
FILENAME_MAX
,
"%s.plist"
,
embedded_prefs
);
snprintf
(
user_prefs_file
,
FILENAME_MAX
,
"%s/Library/Preferences/org.puredata.pd-l2ork.plist"
,
homedir
);
snprintf
(
user_prefs_file
,
FILENAME_MAX
,
"%s.plist"
,
user_prefs
);
if
(
stat
(
embedded_prefs_file
,
&
statbuf
)
==
0
)
{
// Read from and write to the embedded prefs (standalone app).
prefs
=
embedded_prefs
;
...
...
@@ -302,17 +303,16 @@ static void sys_initloadpreferences(void)
}
else
if
(
stat
(
user_prefs_file
,
&
statbuf
)
==
0
)
{
// Read from and write to the user prefs.
prefs
=
current_prefs
;
strcpy
(
current_prefs
,
"org.puredata.pd-l2ork"
);
str
n
cpy
(
current_prefs
,
user_prefs
,
FILENAME_MAX
);
}
else
{
// Read from the package defaults and write to the user prefs.
prefs
=
default_prefs
;
strcpy
(
current_prefs
,
"org.puredata.pd-l2ork"
);
str
n
cpy
(
current_prefs
,
user_prefs
,
FILENAME_MAX
);
}
// This looks complicated, but is rather straightforward. The individual
// stages of the pipe are:
// 1. defaults export: grab our defaults in XML format
// 2. plutil -convert json -r -o - -: convert to JSON
// 3. sed: a few edits remove the extra JSON bits (curly braces, string
// 1. plutil -convert json -r -o -: grab our defaults and convert to JSON
// 2. sed: a few edits remove the extra JSON bits (curly braces, string
// quotes, unwanted whitespace and character escapes) and produce
// Pd-L2Ork's Unix prefs format, i.e.:
// JSON --> Unix prefs
...
...
@@ -322,8 +322,7 @@ static void sys_initloadpreferences(void)
// "path1" : "\/System\/Library\/Fonts" path1: /System/Library/Fonts
// }
snprintf
(
cmdbuf
,
MAXPDSTRING
,
"defaults export %s - "
"| plutil -convert json -r -o - - "
"plutil -convert json -r -o - %s.plist "
"| sed -E "
"-e 's/[{}]//g' "
"-e 's/^ *
\"
(([^
\"
]|
\\\\
.)*)
\"
*: *
\"
(([^
\"
]|
\\\\
.)*)
\"
.*/
\\
1:
\\
3/' "
...
...
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