mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 17:51:01 +00:00
Tidy indent and change user id with -u flag
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3843 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b6e905d98d
commit
f297891c86
1 changed files with 475 additions and 366 deletions
327
Tools/defaults.m
327
Tools/defaults.m
|
@ -25,6 +25,7 @@
|
||||||
#include <Foundation/NSUserDefaults.h>
|
#include <Foundation/NSUserDefaults.h>
|
||||||
#include <Foundation/NSDebug.h>
|
#include <Foundation/NSDebug.h>
|
||||||
#include <Foundation/NSAutoreleasePool.h>
|
#include <Foundation/NSAutoreleasePool.h>
|
||||||
|
#include <Foundation/NSPathUtilities.h>
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -44,7 +45,8 @@ main(int argc, char** argv)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
proc = [NSProcessInfo processInfo];
|
proc = [NSProcessInfo processInfo];
|
||||||
if (proc == nil) {
|
if (proc == nil)
|
||||||
|
{
|
||||||
NSLog(@"defaults: unable to get process information!\n");
|
NSLog(@"defaults: unable to get process information!\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -52,9 +54,11 @@ main(int argc, char** argv)
|
||||||
|
|
||||||
args = [proc arguments];
|
args = [proc arguments];
|
||||||
|
|
||||||
for (i = 1; i < [args count]; i++) {
|
for (i = 1; i < [args count]; i++)
|
||||||
|
{
|
||||||
if ([[args objectAtIndex: i] isEqual: @"--help"] ||
|
if ([[args objectAtIndex: i] isEqual: @"--help"] ||
|
||||||
[[args objectAtIndex: i] isEqual: @"help"]) {
|
[[args objectAtIndex: i] isEqual: @"help"])
|
||||||
|
{
|
||||||
printf(
|
printf(
|
||||||
"The 'defaults' command lets you to read and modify a user's defaults.\n\n"
|
"The 'defaults' command lets you to read and modify a user's defaults.\n\n"
|
||||||
"This program replaces the old NeXTstep style dread, dwrite, and dremove\n"
|
"This program replaces the old NeXTstep style dread, dwrite, and dremove\n"
|
||||||
|
@ -106,7 +110,8 @@ main(int argc, char** argv)
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
else if ([[args objectAtIndex: i] isEqual: @"plist"]) {
|
else if ([[args objectAtIndex: i] isEqual: @"plist"])
|
||||||
|
{
|
||||||
printf(
|
printf(
|
||||||
"A property list is a method of providing structured information consisting\n"
|
"A property list is a method of providing structured information consisting\n"
|
||||||
"of strings, arrays, dictionaries, and binary data.\n\n"
|
"of strings, arrays, dictionaries, and binary data.\n\n"
|
||||||
|
@ -161,28 +166,36 @@ property list which is set as the value of a default.\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
i = 1;
|
i = 1;
|
||||||
if ([args count] <= i) {
|
if ([args count] <= i)
|
||||||
|
{
|
||||||
NSLog(@"defaults: too few arguments supplied!\n");
|
NSLog(@"defaults: too few arguments supplied!\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
if ([[args objectAtIndex: i] isEqual: @"-u"]) {
|
if ([[args objectAtIndex: i] isEqual: @"-u"])
|
||||||
if ([args count] > ++i) {
|
{
|
||||||
|
if ([args count] > ++i)
|
||||||
|
{
|
||||||
user = [args objectAtIndex: i++];
|
user = [args objectAtIndex: i++];
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
NSLog(@"defaults: no name supplied for -u option!\n");
|
NSLog(@"defaults: no name supplied for -u option!\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (user) {
|
if (user)
|
||||||
|
{
|
||||||
|
GSSetUserName(user);
|
||||||
defs = [[NSUserDefaults alloc] initWithUser: user];
|
defs = [[NSUserDefaults alloc] initWithUser: user];
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
defs = [NSUserDefaults standardUserDefaults];
|
defs = [NSUserDefaults standardUserDefaults];
|
||||||
}
|
}
|
||||||
if (defs == nil) {
|
if (defs == nil)
|
||||||
|
{
|
||||||
NSLog(@"defaults: unable to access defaults database!\n");
|
NSLog(@"defaults: unable to access defaults database!\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -190,28 +203,36 @@ property list which is set as the value of a default.\n\n");
|
||||||
/* We don't want this tool in the defaults database - so remove it. */
|
/* We don't want this tool in the defaults database - so remove it. */
|
||||||
[defs removePersistentDomainForName: [proc processName]];
|
[defs removePersistentDomainForName: [proc processName]];
|
||||||
|
|
||||||
if ([args count] <= i) {
|
if ([args count] <= i)
|
||||||
|
{
|
||||||
NSLog(@"defaults: too few arguments supplied!\n");
|
NSLog(@"defaults: too few arguments supplied!\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([[args objectAtIndex: i] isEqual: @"read"] ||
|
if ([[args objectAtIndex: i] isEqual: @"read"] ||
|
||||||
[[args objectAtIndex: i] isEqual: @"readkey"]) {
|
[[args objectAtIndex: i] isEqual: @"readkey"])
|
||||||
if ([[args objectAtIndex: i] isEqual: @"read"]) {
|
{
|
||||||
if ([args count] == ++i) {
|
if ([[args objectAtIndex: i] isEqual: @"read"])
|
||||||
|
{
|
||||||
|
if ([args count] == ++i)
|
||||||
|
{
|
||||||
name = nil;
|
name = nil;
|
||||||
owner = nil;
|
owner = nil;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
owner = [args objectAtIndex: i++];
|
owner = [args objectAtIndex: i++];
|
||||||
if ([args count] > i) {
|
if ([args count] > i)
|
||||||
|
{
|
||||||
name = [args objectAtIndex: i];
|
name = [args objectAtIndex: i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
if ([args count] == ++i) {
|
{
|
||||||
|
if ([args count] == ++i)
|
||||||
|
{
|
||||||
NSLog(@"defaults: too few arguments supplied!\n");
|
NSLog(@"defaults: too few arguments supplied!\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -221,28 +242,35 @@ property list which is set as the value of a default.\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
domains = [defs persistentDomainNames];
|
domains = [defs persistentDomainNames];
|
||||||
for (i = 0; i < [domains count]; i++) {
|
for (i = 0; i < [domains count]; i++)
|
||||||
|
{
|
||||||
NSString *domainName = [domains objectAtIndex: i];
|
NSString *domainName = [domains objectAtIndex: i];
|
||||||
|
|
||||||
if (owner == nil || [owner isEqual: domainName]) {
|
if (owner == nil || [owner isEqual: domainName])
|
||||||
|
{
|
||||||
NSDictionary *dom;
|
NSDictionary *dom;
|
||||||
|
|
||||||
dom = [defs persistentDomainForName: domainName];
|
dom = [defs persistentDomainForName: domainName];
|
||||||
if (dom) {
|
if (dom)
|
||||||
if (name == nil) {
|
{
|
||||||
|
if (name == nil)
|
||||||
|
{
|
||||||
NSEnumerator *enumerator;
|
NSEnumerator *enumerator;
|
||||||
NSString *key;
|
NSString *key;
|
||||||
|
|
||||||
enumerator = [dom keyEnumerator];
|
enumerator = [dom keyEnumerator];
|
||||||
while ((key = [enumerator nextObject]) != nil) {
|
while ((key = [enumerator nextObject]) != nil)
|
||||||
|
{
|
||||||
id obj = [dom objectForKey: key];
|
id obj = [dom objectForKey: key];
|
||||||
const char *ptr;
|
const char *ptr;
|
||||||
|
|
||||||
printf("%s %s '",
|
printf("%s %s '",
|
||||||
[domainName cString], [key cString]);
|
[domainName cString], [key cString]);
|
||||||
ptr = [[obj description] cString];
|
ptr = [[obj description] cString];
|
||||||
while (*ptr) {
|
while (*ptr)
|
||||||
if (*ptr == '\'') {
|
{
|
||||||
|
if (*ptr == '\'')
|
||||||
|
{
|
||||||
putchar('\'');
|
putchar('\'');
|
||||||
}
|
}
|
||||||
putchar(*ptr);
|
putchar(*ptr);
|
||||||
|
@ -251,17 +279,21 @@ property list which is set as the value of a default.\n\n");
|
||||||
printf("'\n");
|
printf("'\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
id obj = [dom objectForKey: name];
|
id obj = [dom objectForKey: name];
|
||||||
|
|
||||||
if (obj) {
|
if (obj)
|
||||||
|
{
|
||||||
const char *ptr;
|
const char *ptr;
|
||||||
|
|
||||||
printf("%s %s '",
|
printf("%s %s '",
|
||||||
[domainName cString], [name cString]);
|
[domainName cString], [name cString]);
|
||||||
ptr = [[obj description] cString];
|
ptr = [[obj description] cString];
|
||||||
while (*ptr) {
|
while (*ptr)
|
||||||
if (*ptr == '\'') {
|
{
|
||||||
|
if (*ptr == '\'')
|
||||||
|
{
|
||||||
putchar('\'');
|
putchar('\'');
|
||||||
}
|
}
|
||||||
putchar(*ptr);
|
putchar(*ptr);
|
||||||
|
@ -275,14 +307,17 @@ property list which is set as the value of a default.\n\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found == NO && name != nil) {
|
if (found == NO && name != nil)
|
||||||
|
{
|
||||||
printf("defaults read: couldn't read default\n");
|
printf("defaults read: couldn't read default\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ([[args objectAtIndex: i] isEqual: @"write"]) {
|
else if ([[args objectAtIndex: i] isEqual: @"write"])
|
||||||
|
{
|
||||||
id obj;
|
id obj;
|
||||||
|
|
||||||
if ([args count] == ++i) {
|
if ([args count] == ++i)
|
||||||
|
{
|
||||||
int size = BUFSIZ;
|
int size = BUFSIZ;
|
||||||
char *buf = objc_malloc(size);
|
char *buf = objc_malloc(size);
|
||||||
|
|
||||||
|
@ -290,7 +325,8 @@ property list which is set as the value of a default.\n\n");
|
||||||
* Read from stdin - grow buffer as necessary since defaults
|
* Read from stdin - grow buffer as necessary since defaults
|
||||||
* values are quoted property lists which may be huge.
|
* values are quoted property lists which may be huge.
|
||||||
*/
|
*/
|
||||||
while (fgets(buf, BUFSIZ, stdin) != 0) {
|
while (fgets(buf, BUFSIZ, stdin) != 0)
|
||||||
|
{
|
||||||
char *ptr;
|
char *ptr;
|
||||||
char *start;
|
char *start;
|
||||||
char *str;
|
char *str;
|
||||||
|
@ -301,22 +337,28 @@ property list which is set as the value of a default.\n\n");
|
||||||
* Expect domain name as a space delimited string.
|
* Expect domain name as a space delimited string.
|
||||||
*/
|
*/
|
||||||
ptr = start;
|
ptr = start;
|
||||||
while (*ptr && !isspace(*ptr)) {
|
while (*ptr && !isspace(*ptr))
|
||||||
|
{
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
if (*ptr) {
|
if (*ptr)
|
||||||
|
{
|
||||||
*ptr++ = '\0';
|
*ptr++ = '\0';
|
||||||
}
|
}
|
||||||
while (isspace(*ptr)) {
|
while (isspace(*ptr))
|
||||||
|
{
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
if (*start == '\0') {
|
if (*start == '\0')
|
||||||
|
{
|
||||||
printf("defaults write: invalid input - nul domain name\n");
|
printf("defaults write: invalid input - nul domain name\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
for (str = start; *str; str++) {
|
for (str = start; *str; str++)
|
||||||
if (isspace(*str)) {
|
{
|
||||||
|
if (isspace(*str))
|
||||||
|
{
|
||||||
printf("defaults write: invalid input - "
|
printf("defaults write: invalid input - "
|
||||||
"space in domain name.\n");
|
"space in domain name.\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
|
@ -330,23 +372,29 @@ property list which is set as the value of a default.\n\n");
|
||||||
* Expect defaults key as a space delimited string.
|
* Expect defaults key as a space delimited string.
|
||||||
*/
|
*/
|
||||||
ptr = start;
|
ptr = start;
|
||||||
while (*ptr && !isspace(*ptr)) {
|
while (*ptr && !isspace(*ptr))
|
||||||
|
{
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
if (*ptr) {
|
if (*ptr)
|
||||||
|
{
|
||||||
*ptr++ = '\0';
|
*ptr++ = '\0';
|
||||||
}
|
}
|
||||||
while (isspace(*ptr)) {
|
while (isspace(*ptr))
|
||||||
|
{
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
if (*start == '\0') {
|
if (*start == '\0')
|
||||||
|
{
|
||||||
printf("defaults write: invalid input - "
|
printf("defaults write: invalid input - "
|
||||||
"nul default name.\n");
|
"nul default name.\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
for (str = start; *str; str++) {
|
for (str = start; *str; str++)
|
||||||
if (isspace(*str)) {
|
{
|
||||||
|
if (isspace(*str))
|
||||||
|
{
|
||||||
printf("defaults write: invalid input - "
|
printf("defaults write: invalid input - "
|
||||||
"space in default name.\n");
|
"space in default name.\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
|
@ -360,56 +408,70 @@ property list which is set as the value of a default.\n\n");
|
||||||
* may cover multiple lines.
|
* may cover multiple lines.
|
||||||
*/
|
*/
|
||||||
start = ptr;
|
start = ptr;
|
||||||
if (*start == '\'') {
|
if (*start == '\'')
|
||||||
for (ptr = ++start; ; ptr++) {
|
{
|
||||||
if (*ptr == '\0') {
|
for (ptr = ++start; ; ptr++)
|
||||||
|
{
|
||||||
|
if (*ptr == '\0')
|
||||||
|
{
|
||||||
int pos = ptr - buf;
|
int pos = ptr - buf;
|
||||||
|
|
||||||
if (size - pos < BUFSIZ) {
|
if (size - pos < BUFSIZ)
|
||||||
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
int spos = start - buf;
|
int spos = start - buf;
|
||||||
|
|
||||||
tmp = objc_realloc(buf, size + BUFSIZ);
|
tmp = objc_realloc(buf, size + BUFSIZ);
|
||||||
if (tmp) {
|
if (tmp)
|
||||||
|
{
|
||||||
size += BUFSIZ;
|
size += BUFSIZ;
|
||||||
buf = tmp;
|
buf = tmp;
|
||||||
ptr = &buf[pos];
|
ptr = &buf[pos];
|
||||||
start = &buf[spos];
|
start = &buf[spos];
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
printf("defaults write: fatal error - "
|
printf("defaults write: fatal error - "
|
||||||
"out of memory.\n");
|
"out of memory.\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fgets(ptr, BUFSIZ, stdin) == 0) {
|
if (fgets(ptr, BUFSIZ, stdin) == 0)
|
||||||
|
{
|
||||||
printf("defaults write: invalid input - "
|
printf("defaults write: invalid input - "
|
||||||
"no final quote.\n");
|
"no final quote.\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*ptr == '\'') {
|
if (*ptr == '\'')
|
||||||
if (ptr[1] == '\'') {
|
{
|
||||||
|
if (ptr[1] == '\'')
|
||||||
|
{
|
||||||
strcpy(ptr, &ptr[1]);
|
strcpy(ptr, &ptr[1]);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
ptr = start;
|
ptr = start;
|
||||||
while (*ptr && !isspace(*ptr)) {
|
while (*ptr && !isspace(*ptr))
|
||||||
|
{
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*ptr) {
|
if (*ptr)
|
||||||
|
{
|
||||||
*ptr++ = '\0';
|
*ptr++ = '\0';
|
||||||
}
|
}
|
||||||
if (*start == '\0') {
|
if (*start == '\0')
|
||||||
|
{
|
||||||
printf("defaults write: invalid input - "
|
printf("defaults write: invalid input - "
|
||||||
"empty property list\n");
|
"empty property list\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
|
@ -421,67 +483,80 @@ property list which is set as the value of a default.\n\n");
|
||||||
* an NSString or a structured property list.
|
* an NSString or a structured property list.
|
||||||
*/
|
*/
|
||||||
obj = [NSString stringWithCString: start];
|
obj = [NSString stringWithCString: start];
|
||||||
if (*start == '(' || *start == '{' || *start == '<') {
|
if (*start == '(' || *start == '{' || *start == '<')
|
||||||
|
{
|
||||||
id tmp = [obj propertyList];
|
id tmp = [obj propertyList];
|
||||||
|
|
||||||
if (tmp == nil) {
|
if (tmp == nil)
|
||||||
|
{
|
||||||
printf("defaults write: invalid input - "
|
printf("defaults write: invalid input - "
|
||||||
"bad property list\n");
|
"bad property list\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
obj = tmp;
|
obj = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
domain = [[defs persistentDomainForName: owner] mutableCopy];
|
domain = [[defs persistentDomainForName: owner] mutableCopy];
|
||||||
if (domain == nil) {
|
if (domain == nil)
|
||||||
|
{
|
||||||
domain = [NSMutableDictionary dictionaryWithCapacity:1];
|
domain = [NSMutableDictionary dictionaryWithCapacity:1];
|
||||||
}
|
}
|
||||||
[domain setObject: obj forKey: name];
|
[domain setObject: obj forKey: name];
|
||||||
[defs setPersistentDomain: domain forName: owner];
|
[defs setPersistentDomain: domain forName: owner];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
owner = [args objectAtIndex: i++];
|
owner = [args objectAtIndex: i++];
|
||||||
if ([args count] <= i) {
|
if ([args count] <= i)
|
||||||
|
{
|
||||||
NSLog(@"defaults: no dictionary or key for write!\n");
|
NSLog(@"defaults: no dictionary or key for write!\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
name = [args objectAtIndex: i++];
|
name = [args objectAtIndex: i++];
|
||||||
if ([args count] > i) {
|
if ([args count] > i)
|
||||||
|
{
|
||||||
const char *ptr;
|
const char *ptr;
|
||||||
|
|
||||||
value = [args objectAtIndex: i];
|
value = [args objectAtIndex: i];
|
||||||
ptr = [value cString];
|
ptr = [value cString];
|
||||||
|
|
||||||
if (*ptr == '(' || *ptr == '{' || *ptr == '<') {
|
if (*ptr == '(' || *ptr == '{' || *ptr == '<')
|
||||||
|
{
|
||||||
obj = [value propertyList];
|
obj = [value propertyList];
|
||||||
|
|
||||||
if (obj == nil) {
|
if (obj == nil)
|
||||||
|
{
|
||||||
printf("defaults write: invalid input - "
|
printf("defaults write: invalid input - "
|
||||||
"bad property list\n");
|
"bad property list\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
obj = value;
|
obj = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
domain = [[defs persistentDomainForName: owner] mutableCopy];
|
domain = [[defs persistentDomainForName: owner] mutableCopy];
|
||||||
if (domain == nil) {
|
if (domain == nil)
|
||||||
|
{
|
||||||
domain = [NSMutableDictionary dictionaryWithCapacity:1];
|
domain = [NSMutableDictionary dictionaryWithCapacity:1];
|
||||||
}
|
}
|
||||||
[domain setObject: obj forKey: name];
|
[domain setObject: obj forKey: name];
|
||||||
[defs setPersistentDomain: domain forName: owner];
|
[defs setPersistentDomain: domain forName: owner];
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
domain = [name propertyList];
|
domain = [name propertyList];
|
||||||
if (domain == nil ||
|
if (domain == nil ||
|
||||||
[domain isKindOfClass: [NSDictionary class]] == NO) {
|
[domain isKindOfClass: [NSDictionary class]] == NO)
|
||||||
|
{
|
||||||
NSLog(@"defaults write: domain is not a dictionary!\n");
|
NSLog(@"defaults write: domain is not a dictionary!\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -489,31 +564,39 @@ property list which is set as the value of a default.\n\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([defs synchronize] == NO) {
|
if ([defs synchronize] == NO)
|
||||||
|
{
|
||||||
NSLog(@"defaults: unable to write to defaults database - %s\n",
|
NSLog(@"defaults: unable to write to defaults database - %s\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ([[args objectAtIndex: i] isEqual: @"delete"]) {
|
else if ([[args objectAtIndex: i] isEqual: @"delete"])
|
||||||
if ([args count] == ++i) {
|
{
|
||||||
|
if ([args count] == ++i)
|
||||||
|
{
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
|
|
||||||
while (fgets(buf, sizeof(buf), stdin) != 0) {
|
while (fgets(buf, sizeof(buf), stdin) != 0)
|
||||||
|
{
|
||||||
char *ptr;
|
char *ptr;
|
||||||
char *start;
|
char *start;
|
||||||
|
|
||||||
start = buf;
|
start = buf;
|
||||||
ptr = start;
|
ptr = start;
|
||||||
while (*ptr && !isspace(*ptr)) {
|
while (*ptr && !isspace(*ptr))
|
||||||
|
{
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
if (*ptr) {
|
if (*ptr)
|
||||||
|
{
|
||||||
*ptr++ = '\0';
|
*ptr++ = '\0';
|
||||||
}
|
}
|
||||||
while (isspace(*ptr)) {
|
while (isspace(*ptr))
|
||||||
|
{
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
if (*start == '\0') {
|
if (*start == '\0')
|
||||||
|
{
|
||||||
printf("defaults delete: invalid input\n");
|
printf("defaults delete: invalid input\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -521,70 +604,88 @@ property list which is set as the value of a default.\n\n");
|
||||||
owner = [NSString stringWithCString: start];
|
owner = [NSString stringWithCString: start];
|
||||||
start = ptr;
|
start = ptr;
|
||||||
ptr = start;
|
ptr = start;
|
||||||
while (*ptr && !isspace(*ptr)) {
|
while (*ptr && !isspace(*ptr))
|
||||||
|
{
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
if (*ptr) {
|
if (*ptr)
|
||||||
|
{
|
||||||
*ptr++ = '\0';
|
*ptr++ = '\0';
|
||||||
}
|
}
|
||||||
while (isspace(*ptr)) {
|
while (isspace(*ptr))
|
||||||
|
{
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
if (*start == '\0') {
|
if (*start == '\0')
|
||||||
|
{
|
||||||
printf("defaults delete: invalid input\n");
|
printf("defaults delete: invalid input\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
name = [NSString stringWithCString: start];
|
name = [NSString stringWithCString: start];
|
||||||
domain = [[defs persistentDomainForName: owner] mutableCopy];
|
domain = [[defs persistentDomainForName: owner] mutableCopy];
|
||||||
if (domain == nil || [domain objectForKey: name] == nil) {
|
if (domain == nil || [domain objectForKey: name] == nil)
|
||||||
|
{
|
||||||
printf("defaults delete: couldn't remove %s owned by %s\n",
|
printf("defaults delete: couldn't remove %s owned by %s\n",
|
||||||
[name cString], [owner cString]);
|
[name cString], [owner cString]);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
[domain removeObjectForKey: name];
|
[domain removeObjectForKey: name];
|
||||||
[defs setPersistentDomain: domain forName: owner];
|
[defs setPersistentDomain: domain forName: owner];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
owner = [args objectAtIndex: i++];
|
owner = [args objectAtIndex: i++];
|
||||||
if ([args count] > i) {
|
if ([args count] > i)
|
||||||
|
{
|
||||||
name = [args objectAtIndex: i];
|
name = [args objectAtIndex: i];
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
name = nil;
|
name = nil;
|
||||||
}
|
}
|
||||||
if (name) {
|
if (name)
|
||||||
|
{
|
||||||
domain = [[defs persistentDomainForName: owner] mutableCopy];
|
domain = [[defs persistentDomainForName: owner] mutableCopy];
|
||||||
if (domain == nil || [domain objectForKey: name] == nil) {
|
if (domain == nil || [domain objectForKey: name] == nil)
|
||||||
|
{
|
||||||
printf("dremove: couldn't remove %s owned by %s\n",
|
printf("dremove: couldn't remove %s owned by %s\n",
|
||||||
[name cString], [owner cString]);
|
[name cString], [owner cString]);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
[domain removeObjectForKey: name];
|
[domain removeObjectForKey: name];
|
||||||
[defs setPersistentDomain: domain forName: owner];
|
[defs setPersistentDomain: domain forName: owner];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
[defs removePersistentDomainForName: owner];
|
[defs removePersistentDomainForName: owner];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ([defs synchronize] == NO) {
|
if ([defs synchronize] == NO)
|
||||||
|
{
|
||||||
NSLog(@"defaults: unable to write to defaults database - %s\n",
|
NSLog(@"defaults: unable to write to defaults database - %s\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ([[args objectAtIndex: i] isEqual: @"domains"]) {
|
else if ([[args objectAtIndex: i] isEqual: @"domains"])
|
||||||
|
{
|
||||||
domains = [defs persistentDomainNames];
|
domains = [defs persistentDomainNames];
|
||||||
for (i = 0; i < [domains count]; i++) {
|
for (i = 0; i < [domains count]; i++)
|
||||||
|
{
|
||||||
NSString *domainName = [domains objectAtIndex: i];
|
NSString *domainName = [domains objectAtIndex: i];
|
||||||
|
|
||||||
printf("%s\n", [domainName cString]);
|
printf("%s\n", [domainName cString]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ([[args objectAtIndex: i] isEqual: @"find"]) {
|
else if ([[args objectAtIndex: i] isEqual: @"find"])
|
||||||
if ([args count] == ++i) {
|
{
|
||||||
|
if ([args count] == ++i)
|
||||||
|
{
|
||||||
NSLog(@"defaults: no arguments for find!\n");
|
NSLog(@"defaults: no arguments for find!\n");
|
||||||
[pool release];
|
[pool release];
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -592,30 +693,37 @@ property list which is set as the value of a default.\n\n");
|
||||||
name = [args objectAtIndex: i];
|
name = [args objectAtIndex: i];
|
||||||
|
|
||||||
domains = [defs persistentDomainNames];
|
domains = [defs persistentDomainNames];
|
||||||
for (i = 0; i < [domains count]; i++) {
|
for (i = 0; i < [domains count]; i++)
|
||||||
|
{
|
||||||
NSString *domainName = [domains objectAtIndex: i];
|
NSString *domainName = [domains objectAtIndex: i];
|
||||||
NSDictionary *dom;
|
NSDictionary *dom;
|
||||||
|
|
||||||
if ([domainName isEqual: name]) {
|
if ([domainName isEqual: name])
|
||||||
|
{
|
||||||
printf("%s\n", [domainName cString]);
|
printf("%s\n", [domainName cString]);
|
||||||
found = YES;
|
found = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
dom = [defs persistentDomainForName: domainName];
|
dom = [defs persistentDomainForName: domainName];
|
||||||
if (dom) {
|
if (dom)
|
||||||
|
{
|
||||||
NSEnumerator *enumerator;
|
NSEnumerator *enumerator;
|
||||||
NSString *key;
|
NSString *key;
|
||||||
|
|
||||||
enumerator = [dom keyEnumerator];
|
enumerator = [dom keyEnumerator];
|
||||||
while ((key = [enumerator nextObject]) != nil) {
|
while ((key = [enumerator nextObject]) != nil)
|
||||||
|
{
|
||||||
id obj = [dom objectForKey: key];
|
id obj = [dom objectForKey: key];
|
||||||
|
|
||||||
if ([key isEqual: name]) {
|
if ([key isEqual: name])
|
||||||
|
{
|
||||||
printf("%s %s\n", [domainName cString], [key cString]);
|
printf("%s %s\n", [domainName cString], [key cString]);
|
||||||
found = YES;
|
found = YES;
|
||||||
}
|
}
|
||||||
if ([obj isKindOfClass: [NSString class]]) {
|
if ([obj isKindOfClass: [NSString class]])
|
||||||
if ([obj isEqual: name]) {
|
{
|
||||||
|
if ([obj isEqual: name])
|
||||||
|
{
|
||||||
printf("%s %s %s\n",
|
printf("%s %s %s\n",
|
||||||
[domainName cString],
|
[domainName cString],
|
||||||
[key cString],
|
[key cString],
|
||||||
|
@ -627,11 +735,13 @@ property list which is set as the value of a default.\n\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found == NO) {
|
if (found == NO)
|
||||||
|
{
|
||||||
printf("defaults find: couldn't find value\n");
|
printf("defaults find: couldn't find value\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
NSLog(@"defaults: unknown option supplied!\n");
|
NSLog(@"defaults: unknown option supplied!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -639,4 +749,3 @@ property list which is set as the value of a default.\n\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue