jdk/src/java.base/share/native/libjli/wildcard.c
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 17445 jdk/src/share/bin/wildcard.c@6c4e2d6b953b
child 29742 b73f38796859
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
17445
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14517
diff changeset
     2
 * Copyright (c) 2005, 2013, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
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
};
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   132
// since this is used repeatedly we keep it here.
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   133
static WIN32_FIND_DATA find_data;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
static WildcardIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
WildcardIterator_for(const char *wildcard)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
{
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);
17445
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14517
diff changeset
   139
    if (handle == INVALID_HANDLE_VALUE) {
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14517
diff changeset
   140
        JLI_MemFree(it);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        return NULL;
17445
6c4e2d6b953b 8013736: [launcher] cleanup code for correctness
ksrini
parents: 14517
diff changeset
   142
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    it->handle = handle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    it->firstFile = find_data.cFileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    return it;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
WildcardIterator_next(WildcardIterator it)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    if (it->firstFile != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        char *firstFile = it->firstFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        it->firstFile = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        return firstFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    return FindNextFile(it->handle, &find_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        ? find_data.cFileName : NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
WildcardIterator_close(WildcardIterator it)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    if (it) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        FindClose(it->handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        JLI_MemFree(it->firstFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        JLI_MemFree(it);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
#else /* Unix */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
struct WildcardIterator_
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    DIR *dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
static WildcardIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
WildcardIterator_for(const char *wildcard)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    DIR *dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    int wildlen = JLI_StrLen(wildcard);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    if (wildlen < 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        dir = opendir(".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        char *dirname = JLI_StringDup(wildcard);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        dirname[wildlen - 1] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        dir = opendir(dirname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        JLI_MemFree(dirname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    if (dir == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        WildcardIterator it = NEW_(WildcardIterator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        it->dir = dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return it;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
WildcardIterator_next(WildcardIterator it)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    struct dirent* dirp = readdir(it->dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    return dirp ? dirp->d_name : NULL;
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 void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
WildcardIterator_close(WildcardIterator it)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    if (it) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        closedir(it->dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        JLI_MemFree(it);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
#endif /* Unix */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
equal(const char *s1, const char *s2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    return JLI_StrCmp(s1, s2) == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 * FileList ADT - a dynamic list of C filenames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
struct FileList_
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    char **files;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    int size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    int capacity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
typedef struct FileList_ *FileList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
static FileList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
FileList_new(int capacity)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    FileList fl = NEW_(FileList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    fl->capacity = capacity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    fl->files = (char **) JLI_MemAlloc(capacity * sizeof(fl->files[0]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    fl->size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    return fl;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
FileList_free(FileList fl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    if (fl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (fl->files) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            for (i = 0; i < fl->size; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                JLI_MemFree(fl->files[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            JLI_MemFree(fl->files);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        JLI_MemFree(fl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
FileList_ensureCapacity(FileList fl, int capacity)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    if (fl->capacity < capacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        while (fl->capacity < capacity)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            fl->capacity *= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        fl->files = JLI_MemRealloc(fl->files,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                               fl->capacity * sizeof(fl->files[0]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
FileList_add(FileList fl, char *file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    FileList_ensureCapacity(fl, fl->size+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    fl->files[fl->size++] = file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
FileList_addSubstring(FileList fl, const char *beg, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    char *filename = (char *) JLI_MemAlloc(len+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    memcpy(filename, beg, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    filename[len] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    FileList_ensureCapacity(fl, fl->size+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    fl->files[fl->size++] = filename;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
FileList_join(FileList fl, char sep)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    int size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    char *path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    char *p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    for (i = 0, size = 1; i < fl->size; i++)
7028
adadd244f506 6989469: (launcher) compiler warnings in jli native code
ksrini
parents: 5506
diff changeset
   294
        size += (int)JLI_StrLen(fl->files[i]) + 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    path = JLI_MemAlloc(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    for (i = 0, p = path; i < fl->size; i++) {
7028
adadd244f506 6989469: (launcher) compiler warnings in jli native code
ksrini
parents: 5506
diff changeset
   299
        int len = (int)JLI_StrLen(fl->files[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if (i > 0) *p++ = sep;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        memcpy(p, fl->files[i], len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        p += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    *p = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    return path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
static FileList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
FileList_split(const char *path, char sep)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    const char *p, *q;
7028
adadd244f506 6989469: (launcher) compiler warnings in jli native code
ksrini
parents: 5506
diff changeset
   313
    int len = (int)JLI_StrLen(path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    FileList fl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    for (count = 1, p = path; p < path + len; p++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        count += (*p == sep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    fl = FileList_new(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    for (p = path;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        for (q = p; q <= path + len; q++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            if (*q == sep || *q == '\0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                FileList_addSubstring(fl, p, q - p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                if (*q == '\0')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                    return fl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                p = q + 1;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
isJarFileName(const char *filename)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
{
7028
adadd244f506 6989469: (launcher) compiler warnings in jli native code
ksrini
parents: 5506
diff changeset
   334
    int len = (int)JLI_StrLen(filename);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    return (len >= 4) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        (filename[len - 4] == '.') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        (equal(filename + len - 3, "jar") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
         equal(filename + len - 3, "JAR")) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        /* Paranoia: Maybe filename is "DIR:foo.jar" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        (JLI_StrChr(filename, PATH_SEPARATOR) == NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
wildcardConcat(const char *wildcard, const char *basename)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
{
7028
adadd244f506 6989469: (launcher) compiler warnings in jli native code
ksrini
parents: 5506
diff changeset
   346
    int wildlen = (int)JLI_StrLen(wildcard);
adadd244f506 6989469: (launcher) compiler warnings in jli native code
ksrini
parents: 5506
diff changeset
   347
    int baselen = (int)JLI_StrLen(basename);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    char *filename = (char *) JLI_MemAlloc(wildlen + baselen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /* Replace the trailing '*' with basename */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    memcpy(filename, wildcard, wildlen-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    memcpy(filename+wildlen-1, basename, baselen+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    return filename;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
static FileList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
wildcardFileList(const char *wildcard)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    const char *basename;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    FileList fl = FileList_new(16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    WildcardIterator it = WildcardIterator_for(wildcard);
14517
e50acb436a8d 8000476: Memory Leaks and uninitialized memory access in PKCS11 and other native code
jzavgren
parents: 13411
diff changeset
   361
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    if (it == NULL)
14517
e50acb436a8d 8000476: Memory Leaks and uninitialized memory access in PKCS11 and other native code
jzavgren
parents: 13411
diff changeset
   363
    {
e50acb436a8d 8000476: Memory Leaks and uninitialized memory access in PKCS11 and other native code
jzavgren
parents: 13411
diff changeset
   364
        FileList_free(fl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        return NULL;
14517
e50acb436a8d 8000476: Memory Leaks and uninitialized memory access in PKCS11 and other native code
jzavgren
parents: 13411
diff changeset
   366
    }
e50acb436a8d 8000476: Memory Leaks and uninitialized memory access in PKCS11 and other native code
jzavgren
parents: 13411
diff changeset
   367
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    while ((basename = WildcardIterator_next(it)) != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (isJarFileName(basename))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            FileList_add(fl, wildcardConcat(wildcard, basename));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    WildcardIterator_close(it);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    return fl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
isWildcard(const char *filename)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
{
7028
adadd244f506 6989469: (launcher) compiler warnings in jli native code
ksrini
parents: 5506
diff changeset
   378
    int len = (int)JLI_StrLen(filename);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    return (len > 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        (filename[len - 1] == '*') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        (len == 1 || IS_FILE_SEPARATOR(filename[len - 2])) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        (! exists(filename));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
FileList_expandWildcards(FileList fl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    int i, j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    for (i = 0; i < fl->size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (isWildcard(fl->files[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            FileList expanded = wildcardFileList(fl->files[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            if (expanded != NULL && expanded->size > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                JLI_MemFree(fl->files[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                FileList_ensureCapacity(fl, fl->size + expanded->size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                for (j = fl->size - 1; j >= i+1; j--)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                    fl->files[j+expanded->size-1] = fl->files[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                for (j = 0; j < expanded->size; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                    fl->files[i+j] = expanded->files[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                i += expanded->size - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                fl->size += expanded->size - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                /* fl expropriates expanded's elements. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                expanded->size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            FileList_free(expanded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
const char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
JLI_WildcardExpandClasspath(const char *classpath)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    char *expanded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    FileList fl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    if (JLI_StrChr(classpath, '*') == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        return classpath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    fl = FileList_split(classpath, PATH_SEPARATOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    FileList_expandWildcards(fl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    expanded = FileList_join(fl, PATH_SEPARATOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    FileList_free(fl);
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 7668
diff changeset
   421
    if (getenv(JLDEBUG_ENV_ENTRY) != 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        printf("Expanded wildcards:\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
               "    before: \"%s\"\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
               "    after : \"%s\"\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
               classpath, expanded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    return expanded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
#ifdef DEBUG_WILDCARD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
FileList_print(FileList fl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    putchar('[');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    for (i = 0; i < fl->size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (i > 0) printf(", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        printf("\"%s\"",fl->files[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    putchar(']');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
wildcardExpandArgv(const char ***argv)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    for (i = 0; (*argv)[i]; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        if (equal((*argv)[i], "-cp") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            equal((*argv)[i], "-classpath")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            (*argv)[i] = wildcardExpandClasspath((*argv)[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
debugPrintArgv(char *argv[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    putchar('[');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    for (i = 0; argv[i]; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        if (i > 0) printf(", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        printf("\"%s\"", argv[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    printf("]\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
main(int argc, char *argv[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    argv[0] = "java";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    wildcardExpandArgv((const char***)&argv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    debugPrintArgv(argv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /* execvp("java", argv); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
#endif /* DEBUG_WILDCARD */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
/* Cute little perl prototype implementation....
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
my $sep = ($^O =~ /^(Windows|cygwin)/) ? ";" : ":";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
sub expand($) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
  opendir DIR, $_[0] or return $_[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
  join $sep, map {"$_[0]/$_"} grep {/\.(jar|JAR)$/} readdir DIR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
sub munge($) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
  join $sep,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    map {(! -r $_ and s/[\/\\]+\*$//) ? expand $_ : $_} split $sep, $_[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
for (my $i = 0; $i < @ARGV - 1; $i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
  $ARGV[$i+1] = munge $ARGV[$i+1] if $ARGV[$i] =~ /^-c(p|lasspath)$/;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
$ENV{CLASSPATH} = munge $ENV{CLASSPATH} if exists $ENV{CLASSPATH};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
@ARGV = ("java", @ARGV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
print "@ARGV\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
exec @ARGV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
*/