Home | History | Annotate | Download | only in toolutil
      1 /*
      2 ************************************************************************
      3 * Copyright (c) 2008-2013, International Business Machines
      4 * Corporation and others.  All Rights Reserved.
      5 ************************************************************************
      6 */
      7 
      8 /** C Utilities to aid in debugging **/
      9 
     10 #ifndef _UDBGUTIL_H
     11 #define _UDBGUTIL_H
     12 
     13 #include "unicode/utypes.h"
     14 #include <stdio.h>
     15 
     16 enum UDebugEnumType {
     17     UDBG_UDebugEnumType = 0, /* Self-referential, strings for UDebugEnumType. Count=ENUM_COUNT. */
     18 #if !UCONFIG_NO_FORMATTING
     19     UDBG_UCalendarDateFields, /* UCalendarDateFields. Count=UCAL_FIELD_COUNT.  Unsupported if UCONFIG_NO_FORMATTING. */
     20     UDBG_UCalendarMonths, /* UCalendarMonths. Count= (UCAL_UNDECIMBER+1) */
     21     UDBG_UDateFormatStyle, /* Count = UDAT_SHORT=1 */
     22 #endif
     23     UDBG_UPlugReason,   /* Count = UPLUG_REASON_COUNT */
     24     UDBG_UPlugLevel,    /* COUNT = UPLUG_LEVEL_COUNT */
     25     UDBG_UAcceptResult, /* Count = ULOC_ACCEPT_FALLBACK+1=3 */
     26 
     27     /* All following enums may be discontiguous. */
     28 
     29 #if !UCONFIG_NO_COLLATION
     30     UDBG_UColAttributeValue,  /* UCOL_ATTRIBUTE_VALUE_COUNT */
     31 #endif
     32     UDBG_ENUM_COUNT,
     33     UDBG_HIGHEST_CONTIGUOUS_ENUM = UDBG_UAcceptResult,  /**< last enum in this list with contiguous (testable) values. */
     34     UDBG_INVALID_ENUM = -1 /** Invalid enum value **/
     35 };
     36 
     37 typedef enum UDebugEnumType UDebugEnumType;
     38 
     39 /**
     40  * @param type the type of enum
     41  * Print how many enums are contained for this type.
     42  * Should be equal to the appropriate _COUNT constant or there is an error. Return -1 if unsupported.
     43  */
     44 U_CAPI int32_t U_EXPORT2 udbg_enumCount(UDebugEnumType type);
     45 
     46 /**
     47  * Convert an enum to a string
     48  * @param type type of enum
     49  * @param field field number
     50  * @return string of the format "ERA", "YEAR", etc, or NULL if out of range or unsupported
     51  */
     52 U_CAPI const char * U_EXPORT2 udbg_enumName(UDebugEnumType type, int32_t field);
     53 
     54 /**
     55  * for consistency checking
     56  * @param type the type of enum
     57  * Print how many enums should be contained for this type.
     58  * This is equal to the appropriate _COUNT constant or there is an error. Returns -1 if unsupported.
     59  */
     60 U_CAPI int32_t U_EXPORT2 udbg_enumExpectedCount(UDebugEnumType type);
     61 
     62 /**
     63  * For consistency checking, returns the expected enum ordinal value for the given index value.
     64  * @param type which type
     65  * @param field field number
     66  * @return should be equal to 'field' or -1 if out of range.
     67  */
     68 U_CAPI int32_t U_EXPORT2 udbg_enumArrayValue(UDebugEnumType type, int32_t field);
     69 
     70 /**
     71  * Locate the specified field value by name.
     72  * @param type which type
     73  * @param name name of string (case sensitive)
     74  * @return should be a field value or -1 if not found.
     75  */
     76 U_CAPI int32_t U_EXPORT2 udbg_enumByName(UDebugEnumType type, const char *name);
     77 
     78 
     79 /**
     80  * Return the Platform (U_PLATFORM) as a string
     81  */
     82 U_CAPI const char *udbg_getPlatform(void);
     83 
     84 /**
     85  * Get the nth system parameter's name
     86  * @param i index of name, starting from zero
     87  * @return name, or NULL if off the end
     88  * @see udbg_getSystemParameterValue
     89  */
     90 U_CAPI const char *udbg_getSystemParameterNameByIndex(int32_t i);
     91 
     92 /**
     93  * Get the nth system parameter's value, in a user supplied buffer
     94  * @parameter i index of value, starting from zero
     95  * @param status error status
     96  * @return length written (standard termination rules)
     97  * @see udbg_getSystemParameterName
     98  */
     99 U_CAPI int32_t udbg_getSystemParameterValueByIndex(int32_t i, char *buffer, int32_t bufferCapacity, UErrorCode *status);
    100 
    101 /**
    102  * Write ICU info as XML
    103  */
    104 U_CAPI void udbg_writeIcuInfo(FILE *f);
    105 
    106 /**
    107  * \def UDBG_KNOWNISSUE_LEN
    108  * Length of output buffer for udbg_knownIssueURLFrom
    109  */
    110 #define UDBG_KNOWNISSUE_LEN 255
    111 
    112 /**
    113  * Convert a "known issue" string into a URL
    114  * @param ticket ticket string such as "10245" or "cldrbug:5013"
    115  * @param buf output buffer - must be UDBG_KNOWNISSUE_LEN in size
    116  * @return pointer to output buffer, or NULL on err
    117  */
    118 U_CAPI char *udbg_knownIssueURLFrom(const char *ticket, char *buf);
    119 
    120 /**
    121  * Open (or reopen) a 'known issue' table.
    122  * @param ptr pointer to 'table'. Opaque.
    123  * @return new or existing ptr
    124  */
    125 U_CAPI void *udbg_knownIssue_openU(void *ptr, const char *ticket, char *where, const UChar *msg, UBool *firstForTicket,
    126                                    UBool *firstForWhere);
    127 
    128 
    129 /**
    130  * Open (or reopen) a 'known issue' table.
    131  * @param ptr pointer to 'table'. Opaque.
    132  * @return new or existing ptr
    133  */
    134 U_CAPI void *udbg_knownIssue_open(void *ptr, const char *ticket, char *where, const char *msg, UBool *firstForTicket,
    135                                    UBool *firstForWhere);
    136 
    137 /**
    138  * Print 'known issue' table, to std::cout.
    139  * @param ptr pointer from udbg_knownIssue
    140  * @return TRUE if there were any issues.
    141  */
    142 U_CAPI UBool udbg_knownIssue_print(void *ptr);
    143 
    144 /**
    145  * Close 'known issue' table.
    146  * @param ptr
    147  */
    148 U_CAPI void udbg_knownIssue_close(void *ptr);
    149 
    150 
    151 #endif
    152