jdk/src/share/bin/wildcard.c
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * Class-Path Wildcards
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * The syntax for wildcards is a single asterisk. The class path
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * foo/"*", e.g., loads all jar files in the directory named foo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * (This requires careful quotation when used in shell scripts.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Only files whose names end in .jar or .JAR are matched.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Files whose names end in .zip, or which have a particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * magic number, regardless of filename extension, are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * matched.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Files are considered regardless of whether or not they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * "hidden" in the UNIX sense, i.e., have names beginning with '.'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * A wildcard only matches jar files, not class files in the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * directory.  If you want to load both class files and jar files from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * a single directory foo then you can say foo:foo/"*", or foo/"*":foo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * if you want the jar files to take precedence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Subdirectories are not searched recursively, i.e., foo/"*" only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * looks for jar files in foo, not in foo/bar, foo/baz, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Expansion of wildcards is done early, prior to the invocation of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * program's main method, rather than late, during the class-loading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * process itself.  Each element of the input class path containing a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * wildcard is replaced by the (possibly empty) sequence of elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * generated by enumerating the jar files in the named directory.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * the directory foo contains a.jar, b.jar, and c.jar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * e.g., then the class path foo/"*" is expanded into
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * foo/a.jar:foo/b.jar:foo/c.jar, and that string would be the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * of the system property java.class.path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * The order in which the jar files in a directory are enumerated in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * the expanded class path is not specified and may vary from platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * to platform and even from moment to moment on the same machine.  A
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * well-constructed application should not depend upon any particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * order.  If a specific order is required then the jar files can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * enumerated explicitly in the class path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * The CLASSPATH environment variable is not treated any differently
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * from the -classpath (equiv. -cp) command-line option,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * i.e. wildcards are honored in all these cases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * Class-path wildcards are not honored in the Class-Path jar-manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * header.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * Class-path wildcards are honored not only by the Java launcher but
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * also by most other command-line tools that accept class paths, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * in particular by javac and javadoc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * Class-path wildcards are not honored in any other kind of path, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * especially not in the bootstrap class path, which is a mere
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * artifact of our implementation and not something that developers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * should use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * Classpath wildcards are only expanded in the Java launcher code,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * supporting the use of wildcards on the command line and in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * CLASSPATH environment variable.  We do not support the use of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * wildcards by applications that embed the JVM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
#include <stddef.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
#include "java.h"       /* Strictly for PATH_SEPARATOR/FILE_SEPARATOR */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
#include "jli_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
#ifdef _WIN32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
#include <windows.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
#else /* Unix */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
#include <unistd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
#include <dirent.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
#endif /* Unix */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
exists(const char* filename)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
#ifdef _WIN32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    return _access(filename, 0) == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    return access(filename, F_OK) == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
#define NEW_(TYPE) ((TYPE) JLI_MemAlloc(sizeof(struct TYPE##_)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * Wildcard directory iteration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * WildcardIterator_for(wildcard) returns an iterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * Each call to that iterator's next() method returns the basename
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * of an entry in the wildcard's directory.  The basename's memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * belongs to the iterator.  The caller is responsible for prepending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * the directory name and file separator, if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * When done with the iterator, call the close method to clean up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
typedef struct WildcardIterator_* WildcardIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
#ifdef _WIN32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
struct WildcardIterator_
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    HANDLE handle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    char *firstFile; /* Stupid FindFirstFile...FindNextFile */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
static WildcardIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
WildcardIterator_for(const char *wildcard)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    WIN32_FIND_DATA find_data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    WildcardIterator it = NEW_(WildcardIterator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    HANDLE handle = FindFirstFile(wildcard, &find_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    if (handle == INVALID_HANDLE_VALUE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    it->handle = handle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    it->firstFile = find_data.cFileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    return it;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
WildcardIterator_next(WildcardIterator it)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    WIN32_FIND_DATA find_data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    if (it->firstFile != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        char *firstFile = it->firstFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        it->firstFile = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return firstFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    return FindNextFile(it->handle, &find_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        ? find_data.cFileName : NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
WildcardIterator_close(WildcardIterator it)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    if (it) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        FindClose(it->handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        JLI_MemFree(it->firstFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        JLI_MemFree(it);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
#else /* Unix */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
struct WildcardIterator_
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    DIR *dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
static WildcardIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
WildcardIterator_for(const char *wildcard)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    DIR *dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    int wildlen = JLI_StrLen(wildcard);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    if (wildlen < 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        dir = opendir(".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        char *dirname = JLI_StringDup(wildcard);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        dirname[wildlen - 1] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        dir = opendir(dirname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        JLI_MemFree(dirname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    if (dir == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        WildcardIterator it = NEW_(WildcardIterator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        it->dir = dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return it;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
WildcardIterator_next(WildcardIterator it)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    struct dirent* dirp = readdir(it->dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    return dirp ? dirp->d_name : NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
WildcardIterator_close(WildcardIterator it)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    if (it) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        closedir(it->dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        JLI_MemFree(it);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
#endif /* Unix */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
equal(const char *s1, const char *s2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    return JLI_StrCmp(s1, s2) == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 * FileList ADT - a dynamic list of C filenames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
struct FileList_
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    char **files;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    int size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    int capacity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
typedef struct FileList_ *FileList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
static FileList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
FileList_new(int capacity)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    FileList fl = NEW_(FileList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    fl->capacity = capacity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    fl->files = (char **) JLI_MemAlloc(capacity * sizeof(fl->files[0]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    fl->size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    return fl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
FileList_free(FileList fl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    if (fl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (fl->files) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            for (i = 0; i < fl->size; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                JLI_MemFree(fl->files[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            JLI_MemFree(fl->files);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        JLI_MemFree(fl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
FileList_ensureCapacity(FileList fl, int capacity)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    if (fl->capacity < capacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        while (fl->capacity < capacity)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            fl->capacity *= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        fl->files = JLI_MemRealloc(fl->files,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                               fl->capacity * sizeof(fl->files[0]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
FileList_add(FileList fl, char *file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    FileList_ensureCapacity(fl, fl->size+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    fl->files[fl->size++] = file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
FileList_addSubstring(FileList fl, const char *beg, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    char *filename = (char *) JLI_MemAlloc(len+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    memcpy(filename, beg, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    filename[len] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    FileList_ensureCapacity(fl, fl->size+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    fl->files[fl->size++] = filename;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
FileList_join(FileList fl, char sep)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    int size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    char *path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    char *p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    for (i = 0, size = 1; i < fl->size; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        size += JLI_StrLen(fl->files[i]) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    path = JLI_MemAlloc(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    for (i = 0, p = path; i < fl->size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        int len = JLI_StrLen(fl->files[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        if (i > 0) *p++ = sep;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        memcpy(p, fl->files[i], len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        p += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    *p = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    return path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
static FileList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
FileList_split(const char *path, char sep)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    const char *p, *q;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    int len = JLI_StrLen(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    FileList fl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    for (count = 1, p = path; p < path + len; p++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        count += (*p == sep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    fl = FileList_new(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    for (p = path;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        for (q = p; q <= path + len; q++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            if (*q == sep || *q == '\0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                FileList_addSubstring(fl, p, q - p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                if (*q == '\0')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                    return fl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                p = q + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
isJarFileName(const char *filename)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    int len = JLI_StrLen(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    return (len >= 4) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        (filename[len - 4] == '.') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        (equal(filename + len - 3, "jar") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
         equal(filename + len - 3, "JAR")) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        /* Paranoia: Maybe filename is "DIR:foo.jar" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        (JLI_StrChr(filename, PATH_SEPARATOR) == NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
wildcardConcat(const char *wildcard, const char *basename)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    int wildlen = JLI_StrLen(wildcard);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    int baselen = JLI_StrLen(basename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    char *filename = (char *) JLI_MemAlloc(wildlen + baselen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /* Replace the trailing '*' with basename */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    memcpy(filename, wildcard, wildlen-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    memcpy(filename+wildlen-1, basename, baselen+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    return filename;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
static FileList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
wildcardFileList(const char *wildcard)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    const char *basename;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    FileList fl = FileList_new(16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    WildcardIterator it = WildcardIterator_for(wildcard);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    if (it == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    while ((basename = WildcardIterator_next(it)) != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        if (isJarFileName(basename))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            FileList_add(fl, wildcardConcat(wildcard, basename));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    WildcardIterator_close(it);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    return fl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
isWildcard(const char *filename)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    int len = JLI_StrLen(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    return (len > 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        (filename[len - 1] == '*') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        (len == 1 || IS_FILE_SEPARATOR(filename[len - 2])) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        (! exists(filename));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
FileList_expandWildcards(FileList fl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    int i, j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    for (i = 0; i < fl->size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        if (isWildcard(fl->files[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            FileList expanded = wildcardFileList(fl->files[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            if (expanded != NULL && expanded->size > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                JLI_MemFree(fl->files[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                FileList_ensureCapacity(fl, fl->size + expanded->size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                for (j = fl->size - 1; j >= i+1; j--)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                    fl->files[j+expanded->size-1] = fl->files[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                for (j = 0; j < expanded->size; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    fl->files[i+j] = expanded->files[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                i += expanded->size - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                fl->size += expanded->size - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                /* fl expropriates expanded's elements. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                expanded->size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            FileList_free(expanded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
const char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
JLI_WildcardExpandClasspath(const char *classpath)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    char *expanded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    FileList fl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    if (JLI_StrChr(classpath, '*') == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        return classpath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    fl = FileList_split(classpath, PATH_SEPARATOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    FileList_expandWildcards(fl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    expanded = FileList_join(fl, PATH_SEPARATOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    FileList_free(fl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    if (getenv("_JAVA_LAUNCHER_DEBUG") != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        printf("Expanded wildcards:\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
               "    before: \"%s\"\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
               "    after : \"%s\"\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
               classpath, expanded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    return expanded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
#ifdef DEBUG_WILDCARD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
FileList_print(FileList fl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    putchar('[');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    for (i = 0; i < fl->size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        if (i > 0) printf(", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        printf("\"%s\"",fl->files[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    putchar(']');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
wildcardExpandArgv(const char ***argv)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    for (i = 0; (*argv)[i]; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        if (equal((*argv)[i], "-cp") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            equal((*argv)[i], "-classpath")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            (*argv)[i] = wildcardExpandClasspath((*argv)[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
debugPrintArgv(char *argv[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    putchar('[');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    for (i = 0; argv[i]; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        if (i > 0) printf(", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        printf("\"%s\"", argv[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    printf("]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
main(int argc, char *argv[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    argv[0] = "java";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    wildcardExpandArgv((const char***)&argv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    debugPrintArgv(argv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    /* execvp("java", argv); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
#endif /* DEBUG_WILDCARD */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
/* Cute little perl prototype implementation....
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
my $sep = ($^O =~ /^(Windows|cygwin)/) ? ";" : ":";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
sub expand($) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
  opendir DIR, $_[0] or return $_[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
  join $sep, map {"$_[0]/$_"} grep {/\.(jar|JAR)$/} readdir DIR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
sub munge($) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
  join $sep,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    map {(! -r $_ and s/[\/\\]+\*$//) ? expand $_ : $_} split $sep, $_[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
for (my $i = 0; $i < @ARGV - 1; $i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
  $ARGV[$i+1] = munge $ARGV[$i+1] if $ARGV[$i] =~ /^-c(p|lasspath)$/;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
$ENV{CLASSPATH} = munge $ENV{CLASSPATH} if exists $ENV{CLASSPATH};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
@ARGV = ("java", @ARGV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
print "@ARGV\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
exec @ARGV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
*/