src/java.desktop/share/native/libawt/java2d/Trace.c
author ihse
Sat, 03 Mar 2018 08:21:47 +0100
branchihse-warnings-cflags-branch
changeset 56230 489867818774
parent 47216 71c04702a3d5
permissions -rw-r--r--
No longer disable E_OLD_STYLE_FUNC_DEF.
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, 2005, 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 <stdarg.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "Trace.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
static int j2dTraceLevel = J2D_TRACE_INVALID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
static FILE *j2dTraceFile = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
J2dTraceImpl(int level, jboolean cr, const char *string, ...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    va_list args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    if (j2dTraceLevel < J2D_TRACE_OFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        J2dTraceInit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    if (level <= j2dTraceLevel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        if (cr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
            switch (level) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
            case J2D_TRACE_ERROR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
                fprintf(j2dTraceFile, "[E] ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            case J2D_TRACE_WARNING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                fprintf(j2dTraceFile, "[W] ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            case J2D_TRACE_INFO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                fprintf(j2dTraceFile, "[I] ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            case J2D_TRACE_VERBOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                fprintf(j2dTraceFile, "[V] ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            case J2D_TRACE_VERBOSE2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                fprintf(j2dTraceFile, "[X] ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        va_start(args, string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        vfprintf(j2dTraceFile, string, args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        va_end(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        if (cr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            fprintf(j2dTraceFile, "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        fflush(j2dTraceFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
JNIEXPORT void JNICALL
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
    76
J2dTraceInit(void)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    char *j2dTraceLevelString = getenv("J2D_TRACE_LEVEL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    char *j2dTraceFileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    j2dTraceLevel = J2D_TRACE_OFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    if (j2dTraceLevelString) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        int traceLevelTmp = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        int args = sscanf(j2dTraceLevelString, "%d", &traceLevelTmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        if (args > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            traceLevelTmp > J2D_TRACE_INVALID &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            traceLevelTmp < J2D_TRACE_MAX)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            j2dTraceLevel = traceLevelTmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    j2dTraceFileName = getenv("J2D_TRACE_FILE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    if (j2dTraceFileName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        j2dTraceFile = fopen(j2dTraceFileName, "w");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (!j2dTraceFile) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            printf("[E]: Error opening trace file %s\n", j2dTraceFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    if (!j2dTraceFile) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        j2dTraceFile = stdout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
}