src/jdk.pack/share/native/unpack200/main.cpp
author ihse
Thu, 05 Apr 2018 21:33:38 +0200
changeset 49534 210cf224b690
parent 48543 7067fe4e054e
child 49843 e0af66d6e968
permissions -rw-r--r--
8200358: Remove mapfiles for JDK executables Reviewed-by: erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    25
#ifdef _ALLBSD_SOURCE
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    26
#include <stdint.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    27
#define THRTYPE intptr_t
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    28
#else
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    29
#define THRTYPE int
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    30
#endif
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    31
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <stdarg.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <errno.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <limits.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include <time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#if defined(unix) && !defined(PRODUCT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#include "pthread.h"
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    45
#define THREAD_SELF ((THRTYPE)pthread_self())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
49534
210cf224b690 8200358: Remove mapfiles for JDK executables
ihse
parents: 48543
diff changeset
    48
#include "jni.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#include "defines.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#include "bytes.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#include "utils.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#include "coding.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#include "bands.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#include "constants.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#include "zip.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
#include "unpack.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
49534
210cf224b690 8200358: Remove mapfiles for JDK executables
ihse
parents: 48543
diff changeset
    62
JNIEXPORT int JNICALL
210cf224b690 8200358: Remove mapfiles for JDK executables
ihse
parents: 48543
diff changeset
    63
main(int argc, char **argv) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    return unpacker::run(argc, argv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
// Single-threaded, implementation, not reentrant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
// Includes a weak error check against MT access.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#ifndef THREAD_SELF
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    70
#define THREAD_SELF ((THRTYPE) 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#endif
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    72
NOT_PRODUCT(static THRTYPE uThread = -1;)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
unpacker* unpacker::non_mt_current = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
unpacker* unpacker::current() {
15261
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 14342
diff changeset
    76
  //assert(uThread == THREAD_SELF);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  return non_mt_current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
static void set_current_unpacker(unpacker* u) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  unpacker::non_mt_current = u;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    81
  assert(((uThread = (u == null) ? (THRTYPE) -1 : THREAD_SELF),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
          true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
// Callback for fetching data, Unix style.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
static jlong read_input_via_stdio(unpacker* u,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                                  void* buf, jlong minlen, jlong maxlen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
  assert(minlen <= maxlen);  // don't talk nonsense
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
  jlong numread = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  char* bufptr = (char*) buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
  while (numread < minlen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    // read available input, up to buf.length or maxlen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    int readlen = (1<<16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    if (readlen > (maxlen - numread))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
      readlen = (int)(maxlen - numread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    int nr = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    if (u->infileptr != null) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    98
      nr = (int)fread(bufptr, 1, readlen, u->infileptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
#ifndef WIN32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
      // we prefer unbuffered inputs
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   102
      nr = (int)read(u->infileno, bufptr, readlen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
#else
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   104
      nr = (int)fread(bufptr, 1, readlen, stdin);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    if (nr <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
      if (errno != EINTR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
      nr = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    numread += nr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    bufptr += nr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    assert(numread <= maxlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
  //fprintf(u->errstrm, "readInputFn(%d,%d) => %d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
  //        (int)minlen, (int)maxlen, (int)numread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  return numread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
enum { EOF_MAGIC = 0, BAD_MAGIC = -1 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
static int read_magic(unpacker* u, char peek[], int peeklen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
  assert(peeklen == 4);  // magic numbers are always 4 bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
  jlong nr = (u->read_input_fn)(u, peek, peeklen, peeklen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
  if (nr != peeklen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    return (nr == 0) ? EOF_MAGIC : BAD_MAGIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  int magic = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  for (int i = 0; i < peeklen; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    magic <<= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    magic += peek[i] & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
  return magic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
static void setup_gzin(unpacker* u) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
  gunzip* gzin = NEW(gunzip, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
  gzin->init(u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
static const char* nbasename(const char* progname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
  const char* slash = strrchr(progname, '/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
  if (slash != null)  progname = ++slash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
  return progname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   147
#define USAGE_HEADER "Usage:  %s [-opt... | --option=value]... x.pack[.gz] y.jar\n"
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   148
#define USAGE_OPTIONS \
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   149
    "\n" \
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   150
    "Unpacking Options\n" \
38969
94e7f56f371c 8065831: Ensure the pack200/unpack200 help is consistent with man page
ksrini
parents: 36960
diff changeset
   151
    "  -H{h}, --deflate-hint={h}     override transmitted deflate hint:\n" \
94e7f56f371c 8065831: Ensure the pack200/unpack200 help is consistent with man page
ksrini
parents: 36960
diff changeset
   152
    "                                true, false, or keep (default)\n" \
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   153
    "  -r, --remove-pack-file        remove input file after unpacking\n" \
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   154
    "  -v, --verbose                 increase program verbosity\n" \
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   155
    "  -q, --quiet                   set verbosity to lowest level\n" \
38969
94e7f56f371c 8065831: Ensure the pack200/unpack200 help is consistent with man page
ksrini
parents: 36960
diff changeset
   156
    "  -l{F}, --log-file={F}         output to the given log file,\n" \
94e7f56f371c 8065831: Ensure the pack200/unpack200 help is consistent with man page
ksrini
parents: 36960
diff changeset
   157
    "                                or '-' for standard output (default)\n" \
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 47216
diff changeset
   158
    "  -?, -h, --help                print this help message\n" \
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   159
    "  -V, --version                 print program version\n" \
38969
94e7f56f371c 8065831: Ensure the pack200/unpack200 help is consistent with man page
ksrini
parents: 36960
diff changeset
   160
    "\n" \
94e7f56f371c 8065831: Ensure the pack200/unpack200 help is consistent with man page
ksrini
parents: 36960
diff changeset
   161
    "Exit Status:\n" \
94e7f56f371c 8065831: Ensure the pack200/unpack200 help is consistent with man page
ksrini
parents: 36960
diff changeset
   162
    "  0 if successful, >0 if an error occurred\n"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
static void usage(unpacker* u, const char* progname, bool full = false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
  // WinMain does not set argv[0] to the progrname
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
  progname = (progname != null) ? nbasename(progname) : "unpack200";
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   167
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   168
  fprintf(u->errstrm, USAGE_HEADER, progname);
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   169
  if (full) {
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   170
    fprintf(u->errstrm, USAGE_OPTIONS);
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   171
  } else {
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   172
    fprintf(u->errstrm, "(For more information, run %s --help .)\n", progname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
// argument parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
static char** init_args(int argc, char** argv, int &envargc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
  const char* env = getenv("UNPACK200_FLAGS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
  ptrlist envargs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
  envargs.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
  if (env != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    char* buf = (char*) strdup(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    const char* delim = "\n\t ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    for (char* p = strtok(buf, delim); p != null; p = strtok(null, delim)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
      envargs.add(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
  // allocate extra margin at both head and tail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
  char** argp = NEW(char*, envargs.length()+argc+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
  char** argp0 = argp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
  for (i = 0; i < envargs.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    *argp++ = (char*) envargs.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
  for (i = 1; i < argc; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    // note: skip argv[0] (program name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    *argp++ = (char*) strdup(argv[i]);  // make a scratch copy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
  *argp = null; // sentinel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
  envargc = envargs.length();  // report this count to next_arg
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
  envargs.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
  return argp0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
static int strpcmp(const char* str, const char* pfx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
  return strncmp(str, pfx, strlen(pfx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
static const char flag_opts[] = "vqrVh?";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
static const char string_opts[] = "HlJ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
static int next_arg(char** &argp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
  char* arg = *argp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
  if (arg == null || arg[0] != '-') { // end of option list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
  //printf("opt: %s\n", arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
  char ach = arg[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
  if (ach == '\0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    // ++argp;  // do not pop this arg
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    return 0;  // bare "-" is stdin/stdout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
  } else if (arg[1] == '-') {  // --foo option
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    static const char* keys[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
      "Hdeflate-hint=",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
      "vverbose",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
      "qquiet",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
      "rremove-pack-file",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
      "llog-file=",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
      "Vversion",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
      "hhelp",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
      null };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    if (arg[2] == '\0') {  // end of option list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
      ++argp;  // pop the "--"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
      return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    for (int i = 0; keys[i] != null; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
      const char* key = keys[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
      char kch = *key++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
      if (strchr(key, '=') == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (!strcmp(arg+2, key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
          ++argp;  // pop option arg
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
          return kch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
      } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (!strpcmp(arg+2, key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
          *argp += 2 + strlen(key);  // remove "--"+key from arg
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
          return kch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
  } else if (strchr(flag_opts, ach) != null) {  // plain option
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    if (arg[2] == '\0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
      ++argp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
      // in-place edit of "-vxyz" to "-xyz"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
      arg += 1;  // skip original '-'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
      arg[0] = '-';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
      *argp = arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    //printf("  key => %c\n", ach);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    return ach;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
  } else if (strchr(string_opts, ach) != null) {  // argument-bearing option
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    if (arg[2] == '\0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
      if (argp[1] == null)  return -1;  // no next arg
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
      ++argp;  // leave the argument in place
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
      // in-place edit of "-Hxyz" to "xyz"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
      arg += 2;  // skip original '-H'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
      *argp = arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    //printf("  key => %c\n", ach);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    return ach;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
  return -1;  // bad argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
static const char sccsver[] = "1.30, 07/05/05";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
// Usage:  unpackage input.pack output.jar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
int unpacker::run(int argc, char **argv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
  unpacker u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
  u.init(read_input_via_stdio);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
  set_current_unpacker(&u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
  jar jarout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
  jarout.init(&u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
  int envargc = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
  char** argbuf = init_args(argc, argv, envargc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
  char** arg0 = argbuf+envargc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
  char** argp = argbuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
  int verbose = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
  char* logfile = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
  for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    const char* arg = (*argp == null)? "": u.saveStr(*argp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    bool isenvarg = (argp < arg0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    int ach = next_arg(argp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    bool hasoptarg = (ach != 0 && strchr(string_opts, ach) != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    if (ach == 0 && argp >= arg0)  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    if (isenvarg && argp == arg0 && hasoptarg)  ach = 0;  // don't pull from cmdline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    switch (ach) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    case 'H':  u.set_option(UNPACK_DEFLATE_HINT,*argp++); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    case 'v':  ++verbose; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    case 'q':  verbose = 0; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    case 'r':  u.set_option(UNPACK_REMOVE_PACKFILE,"1"); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    case 'l':  logfile = *argp++; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    case 'J':  argp += 1; break;  // skip ignored -Jxxx parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    case 'V':
2602
5b394a4b6ce1 6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents: 2
diff changeset
   312
      fprintf(u.errstrm, VERSION_STRING, nbasename(argv[0]), sccsver);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
      exit(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    case 'h':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    case '?':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
      usage(&u, argv[0], true);
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 47216
diff changeset
   318
      exit(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
      const char* inenv = isenvarg? " in ${UNPACK200_FLAGS}": "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
      if (hasoptarg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        fprintf(u.errstrm, "Missing option string%s: %s\n", inenv, arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        fprintf(u.errstrm, "Unrecognized argument%s: %s\n", inenv, arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
      usage(&u, argv[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
      exit(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
  if (verbose != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    u.set_option(DEBUG_VERBOSE, u.saveIntStr(verbose));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
  if (logfile != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    u.set_option(UNPACK_LOG_FILE, logfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
  u.redirect_stdio();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
  const char* source_file      = *argp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
  const char* destination_file = *argp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
  if (source_file == null || destination_file == null || *argp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    usage(&u, argv[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    exit(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
  if (verbose != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    fprintf(u.errstrm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            "Unpacking from %s to %s\n", source_file, destination_file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
  bool& remove_source = u.remove_packfile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
  if (strcmp(source_file, "-") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    remove_source = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    u.infileno = fileno(stdin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    u.infileptr = fopen(source_file, "rb");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    if (u.infileptr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
       fprintf(u.errstrm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
               "Error: Could not open input file: %s\n", source_file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
       exit(3); // Called only from the native standalone unpacker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
  if (strcmp(destination_file, "-") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    jarout.jarfp = stdout;
36960
d7731fdfe7c3 8150469: unpack200 fails to compare crc correctly.
ksrini
parents: 29591
diff changeset
   368
    jarout.jarname = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    if (u.errstrm == stdout) // do not mix output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
      u.set_option(UNPACK_LOG_FILE, LOGFILE_STDERR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    jarout.openJarFile(destination_file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    assert(jarout.jarfp != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
  if (verbose != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    u.dump_options();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
  char peek[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
  int magic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
  // check for GZIP input
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   383
  magic = read_magic(&u, peek, (int)sizeof(peek));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
  if ((magic & GZIP_MAGIC_MASK) == GZIP_MAGIC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    // Oops; must slap an input filter on this data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    setup_gzin(&u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    u.gzin->start(magic);
36960
d7731fdfe7c3 8150469: unpack200 fails to compare crc correctly.
ksrini
parents: 29591
diff changeset
   388
    u.gzin->gzcrc = 0;
d7731fdfe7c3 8150469: unpack200 fails to compare crc correctly.
ksrini
parents: 29591
diff changeset
   389
    u.gzin->gzlen = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    if (!u.aborting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
      u.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    u.start(peek, sizeof(peek));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
  // Note:  The checks to u.aborting() are necessary to gracefully
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
  // terminate processing when the first segment throws an error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
  for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    if (u.aborting())  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    // Each trip through this loop unpacks one segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    // and then resets the unpacker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    for (unpacker::file* filep; (filep = u.get_next_file()) != null; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
      if (u.aborting())  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
      u.write_file_to_jar(filep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    if (u.aborting())  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    // Peek ahead for more data.
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   412
    magic = read_magic(&u, peek, (int)sizeof(peek));
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   413
    if (magic != (int)JAVA_PACKAGE_MAGIC) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
      if (magic != EOF_MAGIC)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        u.abort("garbage after end of pack archive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
      break;   // all done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    // Release all storage from parsing the old segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    u.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    // Restart, beginning with the peek-ahead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    u.start(peek, sizeof(peek));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
  int status = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
  if (u.aborting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    fprintf(u.errstrm, "Error: %s\n", u.get_abort_message());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    status = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
36960
d7731fdfe7c3 8150469: unpack200 fails to compare crc correctly.
ksrini
parents: 29591
diff changeset
   432
  if (u.infileptr != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    fclose(u.infileptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    u.infileptr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
  if (!u.aborting() && remove_source)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    remove(source_file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
  if (verbose != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    fprintf(u.errstrm, "unpacker completed with status=%d\n", status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
  u.finish();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
  u.free();  // tidy up malloc blocks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
  set_current_unpacker(null);  // clean up global pointer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
  return status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
}