142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
@"Writing archives of type %[type] is not (yet) supported!",
@"type", type)];
}
@implementation OFZIP
- (void)applicationDidFinishLaunching
{
OFString *outputDir = nil, *type = nil;
const of_options_parser_option_t options[] = {
{ 'a', @"append", 0, NULL, NULL },
{ 'c', @"create", 0, NULL, NULL },
{ 'C', @"directory", 1, NULL, &outputDir },
{ 'f', @"force", 0, NULL, NULL },
{ 'h', @"help", 0, NULL, NULL },
{ 'l', @"list", 0, NULL, NULL },
{ 'n', @"no-clobber", 0, NULL, NULL },
{ 'p', @"print", 0, NULL, NULL },
{ 'q', @"quiet", 0, NULL, NULL },
{ 't', @"type", 1, NULL, &type },
{ 'v', @"verbose", 0, NULL, NULL },
{ 'x', @"extract", 0, NULL, NULL },
{ '\0', nil, 0, NULL, NULL }
};
OFOptionsParser *optionsParser;
of_unichar_t option, mode = '\0';
OFArray OF_GENERIC(OFString *) *remainingArguments, *files;
id <Archive> archive;
#ifdef OF_HAVE_SANDBOX
OFSandbox *sandbox = [[OFSandbox alloc] init];
@try {
[sandbox setAllowsStdIO: true];
|
|
>
>
|
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
@"Writing archives of type %[type] is not (yet) supported!",
@"type", type)];
}
@implementation OFZIP
- (void)applicationDidFinishLaunching
{
OFString *outputDir = nil, *encodingString = nil, *type = nil;
const of_options_parser_option_t options[] = {
{ 'a', @"append", 0, NULL, NULL },
{ 'c', @"create", 0, NULL, NULL },
{ 'C', @"directory", 1, NULL, &outputDir },
{ 'E', @"encoding", 1, NULL, &encodingString },
{ 'f', @"force", 0, NULL, NULL },
{ 'h', @"help", 0, NULL, NULL },
{ 'l', @"list", 0, NULL, NULL },
{ 'n', @"no-clobber", 0, NULL, NULL },
{ 'p', @"print", 0, NULL, NULL },
{ 'q', @"quiet", 0, NULL, NULL },
{ 't', @"type", 1, NULL, &type },
{ 'v', @"verbose", 0, NULL, NULL },
{ 'x', @"extract", 0, NULL, NULL },
{ '\0', nil, 0, NULL, NULL }
};
OFOptionsParser *optionsParser;
of_unichar_t option, mode = '\0';
of_string_encoding_t encoding = OF_STRING_ENCODING_UTF_8;
OFArray OF_GENERIC(OFString *) *remainingArguments, *files;
id <Archive> archive;
#ifdef OF_HAVE_SANDBOX
OFSandbox *sandbox = [[OFSandbox alloc] init];
@try {
[sandbox setAllowsStdIO: true];
|
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
@"option_takes_no_argument",
@"%[prog]: Option --%[opt] takes no argument",
@"prog", [OFApplication programName],
@"opt", [optionsParser lastLongOption])];
[OFApplication terminateWithStatus: 1];
break;
case '?':
if ([optionsParser lastLongOption] != nil)
[of_stderr writeLine: OF_LOCALIZED(
@"unknown_long_option",
@"%[prog]: Unknown option: --%[opt]",
@"prog", [OFApplication programName],
@"opt", [optionsParser lastLongOption])];
else {
OFString *optStr = [OFString
stringWithFormat: @"%c",
[optionsParser lastOption]];
[of_stderr writeLine: OF_LOCALIZED(
@"unknown_option",
@"%[prog]: Unknown option: -%[opt]",
@"prog", [OFApplication programName],
@"opt", optStr)];
}
[OFApplication terminateWithStatus: 1];
}
}
remainingArguments = [optionsParser remainingArguments];
archive = [self openArchiveWithPath: [remainingArguments firstObject]
type: type
mode: mode];
if (outputDir != nil)
[[OFFileManager defaultManager]
changeCurrentDirectoryPath: outputDir];
switch (mode) {
case 'a':
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
|
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
@"option_takes_no_argument",
@"%[prog]: Option --%[opt] takes no argument",
@"prog", [OFApplication programName],
@"opt", [optionsParser lastLongOption])];
[OFApplication terminateWithStatus: 1];
break;
case ':':
if ([optionsParser lastLongOption] != nil)
[of_stderr writeLine: OF_LOCALIZED(
@"long_option_requires_argument",
@"%[prog]: Option --%[opt] requires an "
@"argument",
@"prog", [OFApplication programName],
@"opt", [optionsParser lastLongOption])];
else {
OFString *optStr = [OFString
stringWithFormat: @"%C",
[optionsParser lastOption]];
[of_stderr writeLine: OF_LOCALIZED(
@"option_requires_argument",
@"%[prog]: Option -%[opt] requires an "
@"argument",
@"prog", [OFApplication programName],
@"opt", optStr)];
}
[OFApplication terminateWithStatus: 1];
break;
case '?':
if ([optionsParser lastLongOption] != nil)
[of_stderr writeLine: OF_LOCALIZED(
@"unknown_long_option",
@"%[prog]: Unknown option: --%[opt]",
@"prog", [OFApplication programName],
@"opt", [optionsParser lastLongOption])];
else {
OFString *optStr = [OFString
stringWithFormat: @"%C",
[optionsParser lastOption]];
[of_stderr writeLine: OF_LOCALIZED(
@"unknown_option",
@"%[prog]: Unknown option: -%[opt]",
@"prog", [OFApplication programName],
@"opt", optStr)];
}
[OFApplication terminateWithStatus: 1];
}
}
@try {
if (encodingString != nil)
encoding = of_string_parse_encoding(encodingString);
} @catch (OFInvalidEncodingException *e) {
[of_stderr writeLine: OF_LOCALIZED(
@"invalid_encoding",
@"%[prog]: Invalid encoding: %[encoding]",
@"prog", [OFApplication programName],
@"encoding", encodingString)];
[OFApplication terminateWithStatus: 1];
}
remainingArguments = [optionsParser remainingArguments];
archive = [self openArchiveWithPath: [remainingArguments firstObject]
type: type
mode: mode
encoding: encoding];
if (outputDir != nil)
[[OFFileManager defaultManager]
changeCurrentDirectoryPath: outputDir];
switch (mode) {
case 'a':
|