< prev index next >

src/jdk.pack/share/native/unpack200/main.cpp

Print this page
rev 50498 : 8199871: Deprecate pack200 and unpack200 tools
Reviewed-by:


 144   return progname;
 145 }
 146 
 147 #define USAGE_HEADER "Usage:  %s [-opt... | --option=value]... x.pack[.gz] y.jar\n"
 148 #define USAGE_OPTIONS \
 149     "\n" \
 150     "Unpacking Options\n" \
 151     "  -H{h}, --deflate-hint={h}     override transmitted deflate hint:\n" \
 152     "                                true, false, or keep (default)\n" \
 153     "  -r, --remove-pack-file        remove input file after unpacking\n" \
 154     "  -v, --verbose                 increase program verbosity\n" \
 155     "  -q, --quiet                   set verbosity to lowest level\n" \
 156     "  -l{F}, --log-file={F}         output to the given log file,\n" \
 157     "                                or '-' for standard output (default)\n" \
 158     "  -?, -h, --help                print this help message\n" \
 159     "  -V, --version                 print program version\n" \
 160     "\n" \
 161     "Exit Status:\n" \
 162     "  0 if successful, >0 if an error occurred\n"
 163 







 164 static void usage(unpacker* u, const char* progname, bool full = false) {
 165   // WinMain does not set argv[0] to the progrname
 166   progname = (progname != null) ? nbasename(progname) : "unpack200";
 167 
 168   fprintf(u->errstrm, USAGE_HEADER, progname);
 169   if (full) {
 170     fprintf(u->errstrm, USAGE_OPTIONS);
 171   } else {
 172     fprintf(u->errstrm, "(For more information, run %s --help .)\n", progname);
 173   }
 174 }
 175 
 176 // argument parsing
 177 static char** init_args(int argc, char** argv, int &envargc) {
 178   const char* env = getenv("UNPACK200_FLAGS");
 179   ptrlist envargs;
 180   envargs.init();
 181   if (env != null) {
 182     char* buf = (char*) strdup(env);
 183     const char* delim = "\n\t ";
 184     for (char* p = strtok(buf, delim); p != null; p = strtok(null, delim)) {



 185       envargs.add(p);
 186     }
 187   }

 188   // allocate extra margin at both head and tail
 189   char** argp = NEW(char*, envargs.length()+argc+1);
 190   char** argp0 = argp;
 191   int i;
 192   for (i = 0; i < envargs.length(); i++) {
 193     *argp++ = (char*) envargs.get(i);
 194   }
 195   for (i = 1; i < argc; i++) {
 196     // note: skip argv[0] (program name)



 197     *argp++ = (char*) strdup(argv[i]);  // make a scratch copy
 198   }

 199   *argp = null; // sentinel
 200   envargc = envargs.length();  // report this count to next_arg
 201   envargs.free();
 202   return argp0;
 203 }
 204 
 205 static int strpcmp(const char* str, const char* pfx) {
 206   return strncmp(str, pfx, strlen(pfx));
 207 }
 208 
 209 static const char flag_opts[] = "vqrVh?";
 210 static const char string_opts[] = "HlJ";
 211 
 212 static int next_arg(char** &argp) {
 213   char* arg = *argp;
 214   if (arg == null || arg[0] != '-') { // end of option list
 215     return 0;
 216   }
 217   //printf("opt: %s\n", arg);
 218   char ach = arg[1];


 276 
 277 static const char sccsver[] = "1.30, 07/05/05";
 278 
 279 // Usage:  unpackage input.pack output.jar
 280 int unpacker::run(int argc, char **argv) {
 281   unpacker u;
 282   u.init(read_input_via_stdio);
 283   set_current_unpacker(&u);
 284 
 285   jar jarout;
 286   jarout.init(&u);
 287 
 288   int envargc = 0;
 289   char** argbuf = init_args(argc, argv, envargc);
 290   char** arg0 = argbuf+envargc;
 291   char** argp = argbuf;
 292 
 293   int verbose = 0;
 294   char* logfile = null;
 295 




 296   for (;;) {
 297     const char* arg = (*argp == null)? "": u.saveStr(*argp);
 298     bool isenvarg = (argp < arg0);
 299     int ach = next_arg(argp);
 300     bool hasoptarg = (ach != 0 && strchr(string_opts, ach) != null);
 301     if (ach == 0 && argp >= arg0)  break;
 302     if (isenvarg && argp == arg0 && hasoptarg)  ach = 0;  // don't pull from cmdline
 303     switch (ach) {
 304     case 'H':  u.set_option(UNPACK_DEFLATE_HINT,*argp++); break;
 305     case 'v':  ++verbose; break;
 306     case 'q':  verbose = 0; break;
 307     case 'r':  u.set_option(UNPACK_REMOVE_PACKFILE,"1"); break;
 308     case 'l':  logfile = *argp++; break;
 309     case 'J':  argp += 1; break;  // skip ignored -Jxxx parameter
 310 
 311     case 'V':
 312       fprintf(u.errstrm, VERSION_STRING, nbasename(argv[0]), sccsver);
 313       exit(0);
 314 
 315     case 'h':




 144   return progname;
 145 }
 146 
 147 #define USAGE_HEADER "Usage:  %s [-opt... | --option=value]... x.pack[.gz] y.jar\n"
 148 #define USAGE_OPTIONS \
 149     "\n" \
 150     "Unpacking Options\n" \
 151     "  -H{h}, --deflate-hint={h}     override transmitted deflate hint:\n" \
 152     "                                true, false, or keep (default)\n" \
 153     "  -r, --remove-pack-file        remove input file after unpacking\n" \
 154     "  -v, --verbose                 increase program verbosity\n" \
 155     "  -q, --quiet                   set verbosity to lowest level\n" \
 156     "  -l{F}, --log-file={F}         output to the given log file,\n" \
 157     "                                or '-' for standard output (default)\n" \
 158     "  -?, -h, --help                print this help message\n" \
 159     "  -V, --version                 print program version\n" \
 160     "\n" \
 161     "Exit Status:\n" \
 162     "  0 if successful, >0 if an error occurred\n"
 163 
 164 #define DEPRECATE_WARNING \
 165     "\nWarning: The %s tool is planned to be removed in a future JDK release.\n\n"
 166 
 167 #define SUPPRESS_DEPRECATE_MSG "-XDsuppress-tool-removal-message"
 168 
 169 static bool suppress_warning = false;
 170 
 171 static void usage(unpacker* u, const char* progname, bool full = false) {
 172   // WinMain does not set argv[0] to the progrname
 173   progname = (progname != null) ? nbasename(progname) : "unpack200";
 174 
 175   fprintf(u->errstrm, USAGE_HEADER, progname);
 176   if (full) {
 177     fprintf(u->errstrm, USAGE_OPTIONS);
 178   } else {
 179     fprintf(u->errstrm, "(For more information, run %s --help .)\n", progname);
 180   }
 181 }
 182 
 183 // argument parsing
 184 static char** init_args(int argc, char** argv, int &envargc) {
 185   const char* env = getenv("UNPACK200_FLAGS");
 186   ptrlist envargs;
 187   envargs.init();
 188   if (env != null) {
 189     char* buf = (char*) strdup(env);
 190     const char* delim = "\n\t ";
 191     for (char* p = strtok(buf, delim); p != null; p = strtok(null, delim)) {
 192       if (!strcmp(p, SUPPRESS_DEPRECATE_MSG)) {
 193         suppress_warning = true;
 194       } else {
 195         envargs.add(p);
 196       }
 197     }
 198   }
 199   // allocate extra margin at both head and tail
 200   char** argp = NEW(char*, envargs.length()+argc+1);
 201   char** argp0 = argp;
 202   int i;
 203   for (i = 0; i < envargs.length(); i++) {
 204     *argp++ = (char*) envargs.get(i);
 205   }
 206   for (i = 1; i < argc; i++) {
 207     // note: skip argv[0] (program name)
 208     if (!strcmp(argv[i], SUPPRESS_DEPRECATE_MSG)) {
 209       suppress_warning = true;
 210     } else {
 211       *argp++ = (char*) strdup(argv[i]);  // make a scratch copy
 212     }
 213   }
 214   *argp = null; // sentinel
 215   envargc = envargs.length();  // report this count to next_arg
 216   envargs.free();
 217   return argp0;
 218 }
 219 
 220 static int strpcmp(const char* str, const char* pfx) {
 221   return strncmp(str, pfx, strlen(pfx));
 222 }
 223 
 224 static const char flag_opts[] = "vqrVh?";
 225 static const char string_opts[] = "HlJ";
 226 
 227 static int next_arg(char** &argp) {
 228   char* arg = *argp;
 229   if (arg == null || arg[0] != '-') { // end of option list
 230     return 0;
 231   }
 232   //printf("opt: %s\n", arg);
 233   char ach = arg[1];


 291 
 292 static const char sccsver[] = "1.30, 07/05/05";
 293 
 294 // Usage:  unpackage input.pack output.jar
 295 int unpacker::run(int argc, char **argv) {
 296   unpacker u;
 297   u.init(read_input_via_stdio);
 298   set_current_unpacker(&u);
 299 
 300   jar jarout;
 301   jarout.init(&u);
 302 
 303   int envargc = 0;
 304   char** argbuf = init_args(argc, argv, envargc);
 305   char** arg0 = argbuf+envargc;
 306   char** argp = argbuf;
 307 
 308   int verbose = 0;
 309   char* logfile = null;
 310 
 311   if (!suppress_warning) {
 312       fprintf(u.errstrm, DEPRECATE_WARNING, nbasename(argv[0]));
 313   }
 314 
 315   for (;;) {
 316     const char* arg = (*argp == null)? "": u.saveStr(*argp);
 317     bool isenvarg = (argp < arg0);
 318     int ach = next_arg(argp);
 319     bool hasoptarg = (ach != 0 && strchr(string_opts, ach) != null);
 320     if (ach == 0 && argp >= arg0)  break;
 321     if (isenvarg && argp == arg0 && hasoptarg)  ach = 0;  // don't pull from cmdline
 322     switch (ach) {
 323     case 'H':  u.set_option(UNPACK_DEFLATE_HINT,*argp++); break;
 324     case 'v':  ++verbose; break;
 325     case 'q':  verbose = 0; break;
 326     case 'r':  u.set_option(UNPACK_REMOVE_PACKFILE,"1"); break;
 327     case 'l':  logfile = *argp++; break;
 328     case 'J':  argp += 1; break;  // skip ignored -Jxxx parameter
 329 
 330     case 'V':
 331       fprintf(u.errstrm, VERSION_STRING, nbasename(argv[0]), sccsver);
 332       exit(0);
 333 
 334     case 'h':


< prev index next >