1 /*
2 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
136 gzin->init(u);
137 }
138
139 static const char* nbasename(const char* progname) {
140 const char* slash = strrchr(progname, '/');
141 if (slash != null) progname = ++slash;
142 return progname;
143 }
144
145 #define USAGE_HEADER "Usage: %s [-opt... | --option=value]... x.pack[.gz] y.jar\n"
146 #define USAGE_OPTIONS \
147 "\n" \
148 "Unpacking Options\n" \
149 " -H{h}, --deflate-hint={h} override transmitted deflate hint:\n" \
150 " true, false, or keep (default)\n" \
151 " -r, --remove-pack-file remove input file after unpacking\n" \
152 " -v, --verbose increase program verbosity\n" \
153 " -q, --quiet set verbosity to lowest level\n" \
154 " -l{F}, --log-file={F} output to the given log file,\n" \
155 " or '-' for standard output (default)\n" \
156 " -?, -h, --help print this message\n" \
157 " -V, --version print program version\n" \
158 "\n" \
159 "Exit Status:\n" \
160 " 0 if successful, >0 if an error occurred\n"
161
162 static void usage(unpacker* u, const char* progname, bool full = false) {
163 // WinMain does not set argv[0] to the progrname
164 progname = (progname != null) ? nbasename(progname) : "unpack200";
165
166 fprintf(u->errstrm, USAGE_HEADER, progname);
167 if (full) {
168 fprintf(u->errstrm, USAGE_OPTIONS);
169 } else {
170 fprintf(u->errstrm, "(For more information, run %s --help .)\n", progname);
171 }
172 }
173
174 // argument parsing
175 static char** init_args(int argc, char** argv, int &envargc) {
176 const char* env = getenv("UNPACK200_FLAGS");
296 bool isenvarg = (argp < arg0);
297 int ach = next_arg(argp);
298 bool hasoptarg = (ach != 0 && strchr(string_opts, ach) != null);
299 if (ach == 0 && argp >= arg0) break;
300 if (isenvarg && argp == arg0 && hasoptarg) ach = 0; // don't pull from cmdline
301 switch (ach) {
302 case 'H': u.set_option(UNPACK_DEFLATE_HINT,*argp++); break;
303 case 'v': ++verbose; break;
304 case 'q': verbose = 0; break;
305 case 'r': u.set_option(UNPACK_REMOVE_PACKFILE,"1"); break;
306 case 'l': logfile = *argp++; break;
307 case 'J': argp += 1; break; // skip ignored -Jxxx parameter
308
309 case 'V':
310 fprintf(u.errstrm, VERSION_STRING, nbasename(argv[0]), sccsver);
311 exit(0);
312
313 case 'h':
314 case '?':
315 usage(&u, argv[0], true);
316 exit(1);
317
318 default:
319 const char* inenv = isenvarg? " in ${UNPACK200_FLAGS}": "";
320 if (hasoptarg)
321 fprintf(u.errstrm, "Missing option string%s: %s\n", inenv, arg);
322 else
323 fprintf(u.errstrm, "Unrecognized argument%s: %s\n", inenv, arg);
324 usage(&u, argv[0]);
325 exit(2);
326 }
327 }
328
329 if (verbose != 0) {
330 u.set_option(DEBUG_VERBOSE, u.saveIntStr(verbose));
331 }
332 if (logfile != null) {
333 u.set_option(UNPACK_LOG_FILE, logfile);
334 }
335
336 u.redirect_stdio();
|
1 /*
2 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
136 gzin->init(u);
137 }
138
139 static const char* nbasename(const char* progname) {
140 const char* slash = strrchr(progname, '/');
141 if (slash != null) progname = ++slash;
142 return progname;
143 }
144
145 #define USAGE_HEADER "Usage: %s [-opt... | --option=value]... x.pack[.gz] y.jar\n"
146 #define USAGE_OPTIONS \
147 "\n" \
148 "Unpacking Options\n" \
149 " -H{h}, --deflate-hint={h} override transmitted deflate hint:\n" \
150 " true, false, or keep (default)\n" \
151 " -r, --remove-pack-file remove input file after unpacking\n" \
152 " -v, --verbose increase program verbosity\n" \
153 " -q, --quiet set verbosity to lowest level\n" \
154 " -l{F}, --log-file={F} output to the given log file,\n" \
155 " or '-' for standard output (default)\n" \
156 " -?, -h, --help print this help message\n" \
157 " -V, --version print program version\n" \
158 "\n" \
159 "Exit Status:\n" \
160 " 0 if successful, >0 if an error occurred\n"
161
162 static void usage(unpacker* u, const char* progname, bool full = false) {
163 // WinMain does not set argv[0] to the progrname
164 progname = (progname != null) ? nbasename(progname) : "unpack200";
165
166 fprintf(u->errstrm, USAGE_HEADER, progname);
167 if (full) {
168 fprintf(u->errstrm, USAGE_OPTIONS);
169 } else {
170 fprintf(u->errstrm, "(For more information, run %s --help .)\n", progname);
171 }
172 }
173
174 // argument parsing
175 static char** init_args(int argc, char** argv, int &envargc) {
176 const char* env = getenv("UNPACK200_FLAGS");
296 bool isenvarg = (argp < arg0);
297 int ach = next_arg(argp);
298 bool hasoptarg = (ach != 0 && strchr(string_opts, ach) != null);
299 if (ach == 0 && argp >= arg0) break;
300 if (isenvarg && argp == arg0 && hasoptarg) ach = 0; // don't pull from cmdline
301 switch (ach) {
302 case 'H': u.set_option(UNPACK_DEFLATE_HINT,*argp++); break;
303 case 'v': ++verbose; break;
304 case 'q': verbose = 0; break;
305 case 'r': u.set_option(UNPACK_REMOVE_PACKFILE,"1"); break;
306 case 'l': logfile = *argp++; break;
307 case 'J': argp += 1; break; // skip ignored -Jxxx parameter
308
309 case 'V':
310 fprintf(u.errstrm, VERSION_STRING, nbasename(argv[0]), sccsver);
311 exit(0);
312
313 case 'h':
314 case '?':
315 usage(&u, argv[0], true);
316 exit(0);
317
318 default:
319 const char* inenv = isenvarg? " in ${UNPACK200_FLAGS}": "";
320 if (hasoptarg)
321 fprintf(u.errstrm, "Missing option string%s: %s\n", inenv, arg);
322 else
323 fprintf(u.errstrm, "Unrecognized argument%s: %s\n", inenv, arg);
324 usage(&u, argv[0]);
325 exit(2);
326 }
327 }
328
329 if (verbose != 0) {
330 u.set_option(DEBUG_VERBOSE, u.saveIntStr(verbose));
331 }
332 if (logfile != null) {
333 u.set_option(UNPACK_LOG_FILE, logfile);
334 }
335
336 u.redirect_stdio();
|