1
/* This is a simple tool to read and display defaults information
2
Copyright (C) 1997 Free Software Foundation, Inc.
4
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
7
This file is part of the GNUstep Project
9
This library is free software; you can redistribute it and/or
10
modify it under the terms of the GNU General Public License
11
as published by the Free Software Foundation; either version 2
12
of the License, or (at your option) any later version.
14
You should have received a copy of the GNU General Public
15
License along with this library; see the file COPYING.LIB.
16
If not, write to the Free Software Foundation,
17
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
#include <Foundation/NSArray.h>
23
#include <Foundation/NSDictionary.h>
24
#include <Foundation/NSString.h>
25
#include <Foundation/NSProcessInfo.h>
26
#include <Foundation/NSUserDefaults.h>
27
#include <Foundation/NSAutoreleasePool.h>
31
main(int argc, char** argv)
33
NSAutoreleasePool *pool = [NSAutoreleasePool new];
38
NSString *owner = nil;
45
proc = [NSProcessInfo processInfo];
47
NSLog(@"unable to get process information!\n");
52
args = [proc arguments];
54
for (i = 1; i < [args count]; i++) {
55
if ([[args objectAtIndex: i] isEqual: @"--help"]) {
57
"\nThe 'dread' command lets you to read a user's defaults database.\n"
58
"WARNING - this program is obsolete - please use 'defaults read' instead.\n\n"
59
"Results are printed on standard output in a format suitable for input to\n"
60
"the 'dwrite' command. The value of each default is quoted with \"'\" and\n"
61
"may wrap over line boundaries.\n"
62
"Single quotes used within a default value are repeated.\n\n"
63
"If you have read access to another user's defaults database, you may include\n"
64
"the '-u' flag to read that user's database rather than your own.\n\n");
66
"dread [-u uname] -g key\n"
67
" read the named default from the global domain.\n\n");
69
"dread [-u uname] -l\n"
70
" read all defaults from all domains.\n\n");
72
"dread [-u uname] -n key\n"
73
" read values named 'key' from all domains.\n\n");
75
"dread [-u uname] -o domain\n"
76
" read all defaults from the specified domain.\n\n");
78
"dread [-u uname] domain key\n"
79
" read default with name 'key' from domain 'domain'.\n\n");
81
"dread [-u uname] key\n"
82
" read default named 'key' from the global domain.\n");
89
if ([args count] <= i) {
90
NSLog(@"too few arguments supplied!\n");
95
if ([[args objectAtIndex: i] isEqual: @"-u"]) {
96
if ([args count] > ++i) {
97
user = [args objectAtIndex: i++];
100
NSLog(@"no name supplied for -u option!\n");
106
if ([args count] <= i) {
107
NSLog(@"too few arguments supplied!\n");
112
if ([[args objectAtIndex: i] isEqual: @"-g"]) {
113
owner = NSGlobalDomain;
114
if ([args count] > ++i) {
115
name = [args objectAtIndex: i];
118
NSLog(@"no key supplied for -g option!\n");
123
else if ([[args objectAtIndex: i] isEqual: @"-n"]) {
125
if ([args count] > ++i) {
126
name = [args objectAtIndex: i];
129
NSLog(@"no key supplied for -n option!\n");
134
else if ([[args objectAtIndex: i] isEqual: @"-o"]) {
136
if ([args count] > ++i) {
137
owner = [args objectAtIndex: i];
140
NSLog(@"no domain name supplied for -o option!\n");
145
else if ([[args objectAtIndex: i] isEqual: @"-l"]) {
150
if ([args count] > i+1) {
151
owner = [args objectAtIndex: i];
152
name = [args objectAtIndex: ++i];
155
owner = NSGlobalDomain;
156
name = [args objectAtIndex: i];
161
defs = [[NSUserDefaults alloc] initWithUser: user];
164
defs = [NSUserDefaults standardUserDefaults];
167
NSLog(@"unable to access defaults database!\n");
171
/* We don't want dwrite in the defaults database - so remove it. */
172
[defs removePersistentDomainForName: [proc processName]];
174
locale = [defs dictionaryRepresentation];
175
domains = [defs persistentDomainNames];
176
for (i = 0; i < [domains count]; i++) {
177
NSString *domainName = [domains objectAtIndex: i];
179
if (owner == nil || [owner isEqual: domainName]) {
182
dom = [defs persistentDomainForName: domainName];
185
NSEnumerator *enumerator;
188
enumerator = [dom keyEnumerator];
189
while ((key = [enumerator nextObject]) != nil) {
190
id obj = [dom objectForKey: key];
193
printf("%s %s '", [domainName cString], [key cString]);
194
ptr = [[obj descriptionWithLocale: locale indent: 0]
207
id obj = [dom objectForKey: name];
212
printf("%s %s '", [domainName cString], [name cString]);
213
ptr = [[obj descriptionWithLocale: locale indent: 0]
230
if (found == NO && name != nil) {
231
printf("dread: couldn't read default\n");