jdk/src/share/bin/version_comp.c
author goetz
Thu, 21 Nov 2013 18:29:34 -0800
changeset 22852 1063026e8cee
parent 5506 202f599c92aa
permissions -rw-r--r--
8028471: PPC64 (part 215): opto: Extend ImplicitNullCheck optimization. Summary: Fixed Implicit NULL check optimization for AIX, where the page at address '0' is only write-protected. Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, 2006, 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
#include <ctype.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "jli_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "version_comp.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *      A collection of useful strings. One should think of these as #define
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *      entries, but actual strings can be more efficient (with many compilers).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
static const char *separators   = ".-_";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
static const char *zero_string  = "0";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *      Validate a string as parsable as a "Java int". If so parsable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *      return true (non-zero) and store the numeric value at the address
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *      passed in as "value"; otherwise return false (zero).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *      Note that the maximum allowable value is 2147483647 as defined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *      the "Java Language Specification" which precludes the use of native
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *      conversion routines which may have other limits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *      Also note that we don't have to worry about the alternate maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *      allowable value of 2147483648 because it is only allowed after
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *      the unary negation operator and this grammar doesn't have one
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *      of those.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *      Finally, note that a value which exceeds the maximum jint value will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *      return false (zero). This results in the otherwise purely numeric
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *      string being compared as a string of characters (as per the spec.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
isjavaint(const char *s, jint *value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    jlong sum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    jint digit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    while (*s != '\0')
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        if (isdigit(*s)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            digit = (jint)((int)(*s++) - (int)('0'));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            sum = (sum * 10) + digit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            if (sum > 2147483647)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                return (0);     /* Overflows jint (but not jlong) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            return (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    *value = (jint)sum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    return (1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *      Modeled after strcmp(), compare two strings (as in the grammar defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *      in Appendix A of JSR 56).  If both strings can be interpreted as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *      Java ints, do a numeric comparison, else it is strcmp().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
comp_string(const char *s1, const char *s2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    jint v1, v2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    if (isjavaint(s1, &v1) && isjavaint(s2, &v2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        return ((int)(v1 - v2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return (JLI_StrCmp(s1, s2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *      Modeled after strcmp(), compare two version-ids for a Prefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *      Match as defined in JSR 56.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
JLI_PrefixVersionId(const char *id1, char *id2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    char        *s1 = JLI_StringDup(id1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    char        *s2 = JLI_StringDup(id2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    char        *m1 = s1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    char        *m2 = s2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    char        *end1 = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    char        *end2 = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    int res = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if ((s1 != NULL) && ((end1 = JLI_StrPBrk(s1, ".-_")) != NULL))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            *end1 = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if ((s2 != NULL) && ((end2 = JLI_StrPBrk(s2, ".-_")) != NULL))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            *end2 = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        res = comp_string(s1, s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (end1 != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            s1 = end1 + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            s1 = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (end2 != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            s2 = end2 + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            s2 = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    } while (res == 0 && ((s1 != NULL) && (s2 != NULL)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    JLI_MemFree(m1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    JLI_MemFree(m2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    return (res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 *      Modeled after strcmp(), compare two version-ids for an Exact
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *      Match as defined in JSR 56.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
JLI_ExactVersionId(const char *id1, char *id2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    char        *s1 = JLI_StringDup(id1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    char        *s2 = JLI_StringDup(id2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    char        *m1 = s1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    char        *m2 = s2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    char        *end1 = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    char        *end2 = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    int res = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        if ((s1 != NULL) && ((end1 = JLI_StrPBrk(s1, separators)) != NULL))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            *end1 = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        if ((s2 != NULL) && ((end2 = JLI_StrPBrk(s2, separators)) != NULL))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            *end2 = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if ((s1 != NULL) && (s2 == NULL))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            res = comp_string(s1, zero_string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        else if ((s1 == NULL) && (s2 != NULL))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            res = comp_string(zero_string, s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            res = comp_string(s1, s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (end1 != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            s1 = end1 + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            s1 = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (end2 != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            s2 = end2 + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            s2 = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    } while (res == 0 && ((s1 != NULL) || (s2 != NULL)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    JLI_MemFree(m1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    JLI_MemFree(m2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    return (res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 *      Return true if this simple-element (as defined in JSR 56) forms
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 *      an acceptable match.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 *      JSR 56 is modified by the Java Web Start <rel> Developer Guide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 *      where it is stated "... Java Web Start will not consider an installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 *      non-FCS (i.e., milestone) JRE as a match. ... a JRE from Sun
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 *      Microsystems, Inc., is by convention a non-FCS (milestone) JRE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 *      if there is a dash (-) in the version string."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 *      An undocumented caveat to the above is that an exact match with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 *      hyphen is accepted as a development extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 *      These modifications are addressed by the specific comparisons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 *      for releases with hyphens.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
acceptable_simple_element(const char *release, char *simple_element)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    char        *modifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    modifier = simple_element + JLI_StrLen(simple_element) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    if (*modifier == '*') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        *modifier = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (JLI_StrChr(release, '-'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            return ((JLI_StrCmp(release, simple_element) == 0)?1:0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return ((JLI_PrefixVersionId(release, simple_element) == 0)?1:0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    } else if (*modifier == '+') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        *modifier = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (JLI_StrChr(release, '-'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            return ((JLI_StrCmp(release, simple_element) == 0)?1:0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return ((JLI_ExactVersionId(release, simple_element) >= 0)?1:0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        return ((JLI_ExactVersionId(release, simple_element) == 0)?1:0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 *      Return true if this element (as defined in JSR 56) forms
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 *      an acceptable match. An element is the intersection (and)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 *      of multiple simple-elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
acceptable_element(const char *release, char *element)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    char        *end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if ((end = JLI_StrChr(element, '&')) != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            *end = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (!acceptable_simple_element(release, element))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            return (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (end != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            element = end + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    } while (end != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    return (1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 *      Checks if release is acceptable by the specification version-string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 *      Return true if this version-string (as defined in JSR 56) forms
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 *      an acceptable match. A version-string is the union (or) of multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 *      elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
JLI_AcceptableRelease(const char *release, char *version_string)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    char        *vs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    char        *m1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    char        *end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    m1 = vs = JLI_StringDup(version_string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if ((end = JLI_StrChr(vs, ' ')) != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            *end = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (acceptable_element(release, vs)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            JLI_MemFree(m1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            return (1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (end != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            vs = end + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    } while (end != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    JLI_MemFree(m1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    return (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 *      Return true if this is a valid simple-element (as defined in JSR 56).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 *      The official grammar for a simple-element is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 *              simple-element  ::= version-id | version-id modifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
 *              modifier        ::= '+' | '*'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
 *              version-id      ::= string ( separator  string )*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
 *              string          ::= char ( char )*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 *              char            ::= Any ASCII character except a space, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 *                                  ampersand, a separator or a modifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 *              separator       ::= '.' | '-' | '_'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 *      However, for efficiency, it is time to abandon the top down parser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 *      implementation.  After deleting the potential trailing modifier, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 *      are left with a version-id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 *      Note that a valid version-id has three simple properties:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 *      1) Doesn't contain a space, an ampersand or a modifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 *      2) Doesn't begin or end with a separator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 *      3) Doesn't contain two adjacent separators.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 *      Any other line noise constitutes a valid version-id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
valid_simple_element(char *simple_element)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    char        *last;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    size_t      len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    if ((simple_element == NULL) || ((len = JLI_StrLen(simple_element)) == 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    last = simple_element + len - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    if (*last == '*' || *last == '+') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        if (--len == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            return (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        *last-- = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    if (JLI_StrPBrk(simple_element, " &+*") != NULL)    /* Property #1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        return (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    if ((JLI_StrChr(".-_", *simple_element) != NULL) || /* Property #2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
      (JLI_StrChr(".-_", *last) != NULL))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    for (; simple_element != last; simple_element++)    /* Property #3 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        if ((JLI_StrChr(".-_", *simple_element) != NULL) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
          (JLI_StrChr(".-_", *(simple_element + 1)) != NULL))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            return (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    return (1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
 *      Return true if this is a valid element (as defined in JSR 56).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
 *      An element is the intersection (and) of multiple simple-elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
valid_element(char *element)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    char        *end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    if ((element == NULL) || (JLI_StrLen(element) == 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        return (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if ((end = JLI_StrChr(element, '&')) != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            *end = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        if (!valid_simple_element(element))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            return (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        if (end != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            element = end + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    } while (end != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    return (1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
 *      Validates a version string by the extended JSR 56 grammar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
JLI_ValidVersionString(char *version_string)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    char        *vs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    char        *m1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    char        *end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    if ((version_string == NULL) || (JLI_StrLen(version_string) == 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        return (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    m1 = vs = JLI_StringDup(version_string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if ((end = JLI_StrChr(vs, ' ')) != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            *end = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (!valid_element(vs)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            JLI_MemFree(m1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            return (0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (end != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            vs = end + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    } while (end != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    JLI_MemFree(m1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    return (1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
}