39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
OF_APPLICATION_DELEGATE(OFZIP)
static void
help(OFStream *stream, bool full, int status)
{
[stream writeFormat:
@"Usage: %@ -[fhlnqvx] archive.zip [file1 file2 ...]\n",
[OFApplication programName]];
if (full)
[stream writeString:
@"\nOptions:\n"
@" -f --force Force / overwrite files\n"
@" -h --help Show this help\n"
@" -l --list List all files in the archive\n"
@" -n --no-clober Never overwrite files\n"
@" -q --quiet Quiet mode (no output, except "
@"errors)\n"
@" -v --verbose Verbose output for file list\n"
@" -x --extract Extract files\n"];
[OFApplication terminateWithStatus: status];
}
static void
mutuallyExclusiveError(of_unichar_t shortOption1, OFString *longOption1,
of_unichar_t shortOption2, OFString *longOption2)
{
[of_stderr writeFormat:
@"Error: -%C / --%@ and -%C / --%@ are mutually exclusive!\n",
shortOption1, longOption1, shortOption2, longOption2];
[OFApplication terminateWithStatus: 1];
}
@implementation OFZIP
- (void)applicationDidFinishLaunching
{
const of_options_parser_option_t options[] = {
{ 'f', @"force", 0, NULL, NULL },
{ 'h', @"help", 0, NULL, NULL },
{ 'l', @"list", 0, NULL, NULL },
{ 'n', @"no-clobber", 0, NULL, NULL },
{ 'q', @"quiet", 0, NULL, NULL },
{ 'v', @"verbose", 0, NULL, NULL },
{ 'x', @"extract", 0, NULL, NULL },
{ '\0', nil, 0, NULL, NULL }
};
OFOptionsParser *optionsParser =
[OFOptionsParser parserWithOptions: options];
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
OF_APPLICATION_DELEGATE(OFZIP)
static void
help(OFStream *stream, bool full, int status)
{
[stream writeFormat:
@"Usage: %@ -[fhlnpqvx] archive.zip [file1 file2 ...]\n",
[OFApplication programName]];
if (full)
[stream writeString:
@"\nOptions:\n"
@" -f --force Force / overwrite files\n"
@" -h --help Show this help\n"
@" -l --list List all files in the archive\n"
@" -n --no-clober Never overwrite files\n"
@" -p --print Print one or more files from the "
@"archive\n"
@" -q --quiet Quiet mode (no output, except "
@"errors)\n"
@" -v --verbose Verbose output for file list\n"
@" -x --extract Extract files\n"];
[OFApplication terminateWithStatus: status];
}
static void
mutuallyExclusiveError(of_unichar_t shortOption1, OFString *longOption1,
of_unichar_t shortOption2, OFString *longOption2)
{
[of_stderr writeFormat:
@"Error: -%C / --%@ and -%C / --%@ are mutually exclusive!\n",
shortOption1, longOption1, shortOption2, longOption2];
[OFApplication terminateWithStatus: 1];
}
static void
mutuallyExclusiveError3(of_unichar_t shortOption1, OFString *longOption1,
of_unichar_t shortOption2, OFString *longOption2,
of_unichar_t shortOption3, OFString *longOption3)
{
[of_stderr writeFormat:
@"Error: -%C / --%@, -%C / --%@ and -%C / --%@ are mutually "
@"exclusive!\n", shortOption1, longOption1, shortOption2,
longOption2, shortOption3, longOption3];
[OFApplication terminateWithStatus: 1];
}
@implementation OFZIP
- (void)applicationDidFinishLaunching
{
const of_options_parser_option_t options[] = {
{ '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 },
{ 'v', @"verbose", 0, NULL, NULL },
{ 'x', @"extract", 0, NULL, NULL },
{ '\0', nil, 0, NULL, NULL }
};
OFOptionsParser *optionsParser =
[OFOptionsParser parserWithOptions: options];
|
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
mutuallyExclusiveError(
'q', @"quiet", 'v', @"verbose");
_outputLevel--;
break;
case 'l':
case 'x':
if (mode != '\0')
mutuallyExclusiveError(
'l', @"list", 'x', @"extract");
mode = option;
break;
case 'h':
help(of_stdout, true, 0);
break;
case '=':
|
>
|
|
>
|
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
mutuallyExclusiveError(
'q', @"quiet", 'v', @"verbose");
_outputLevel--;
break;
case 'l':
case 'x':
case 'p':
if (mode != '\0')
mutuallyExclusiveError3(
'l', @"list", 'x', @"extract",
'p', @"print");
mode = option;
break;
case 'h':
help(of_stdout, true, 0);
break;
case '=':
|