home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Programming / jikes-1.02 / src / config.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-05  |  24.7 KB  |  797 lines

  1. // $Id: config.h,v 1.19 1999/08/26 15:34:06 shields Exp $
  2. //
  3. // This software is subject to the terms of the IBM Jikes Compiler
  4. // License Agreement available at the following URL:
  5. // http://www.ibm.com/research/jikes.
  6. // Copyright (C) 1996, 1998, International Business Machines Corporation
  7. // and others.  All Rights Reserved.
  8. // You must accept the terms of that agreement to use this software.
  9. //
  10. #ifndef config_INCLUDED
  11. #define config_INCLUDED
  12.  
  13. #ifndef __amigaos__
  14. #include <wchar.h>
  15. #endif
  16. #include <new.h>
  17. #include <iostream.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <assert.h>
  21. #include "string.h"
  22. #include <stdio.h>
  23. #include <sys/types.h>
  24. #include <sys/stat.h>
  25.  
  26.  
  27. #if defined(GNU_LIBC5) || defined __amigaos__
  28.     extern size_t wcslen(wchar_t *);
  29.     extern wchar_t *wcscpy(wchar_t *, wchar_t *);
  30.     extern wchar_t *wcsncpy(wchar_t *, wchar_t *, int);
  31.     extern wchar_t *wcscat(wchar_t *, wchar_t *);
  32.     extern int wcscmp(wchar_t *, wchar_t *);
  33.     extern int wcsncmp(wchar_t *, wchar_t *, int);
  34. #endif
  35.  
  36.  
  37. #ifdef TEST
  38. #define NO_LEAKS
  39. #endif
  40.  
  41. //
  42. // We need to set up certain environment information depending on
  43. // the host OS.
  44. //
  45. // Jikes uses the stat() system call to query file status. Traditional
  46. // unix systems use S_IFDIR and S_IFREG as names for constants used to
  47. // see if file is directory or regular file, respectively. POSIX-based
  48. // systems use __S_IFDIR and __S_IFREG, with S_IFDIR and S_IFREG being
  49. // defined as macros
  50. //
  51. #ifdef STAT_POSIX
  52. #define STAT_S_IFDIR __S_IFDIR
  53. #define STAT_S_IFREG __S_IFREG
  54. #else
  55. #define STAT_S_IFDIR S_IFDIR
  56. #define STAT_S_IFREG S_IFREG
  57. #endif
  58.  
  59. #ifdef STAT_POSIX_1
  60. // Some variants of HPUX want just one underscore
  61. #undef STAT_S_IFDIR
  62. #undef STAT_S_IFREG
  63. #define STAT_S_IFDIR _S_IFDIR
  64. #define STAT_S_IFREG _S_IFREG
  65. #endif
  66. //
  67. // These definitions are correct for all the platforms that
  68. // we are currently using. When porting this code, they should
  69. // always be reviewed.
  70. //
  71. #include <limits.h>
  72.  
  73. #if ! (UINT_MAX == 0xFFFFFFFF)
  74. #error unsigned int does not store values in the range 0..4294967295 in this system
  75. #else
  76.     typedef unsigned int u4;
  77. #endif
  78.  
  79. #if ! ((INT_MAX == 2147483647) && (INT_MIN + 1 == -INT_MAX))
  80. #error signed int does not store values in the range -2147483648..+2147483647 in this system
  81. #else
  82.     typedef signed int i4;
  83. #endif
  84.  
  85. #if ! (USHRT_MAX == 0xFFFF)
  86. #error unsigned short does not store values in the range 0..65535 in this system
  87. #else
  88.     typedef unsigned short u2;
  89. #endif
  90.  
  91. #if ! ((SHRT_MAX == 32767) && (SHRT_MIN + 1 == -SHRT_MAX))
  92. #error signed short does not store values in the range -32767..+32768 in this system
  93. #else
  94.     typedef signed short i2;
  95. #endif
  96.  
  97. #if ! (UCHAR_MAX == 0xFF)
  98. #error unsigned char does not store values in the range 0..255 in this system
  99. #else
  100.     typedef unsigned char u1;
  101. #endif
  102.  
  103. #if ! ((SCHAR_MAX == 127) && (SCHAR_MIN + 1 == -SCHAR_MAX))
  104. #error signed character does not store values in the range -128..+127 in this system
  105. #else
  106.     typedef signed char i1;
  107. #endif
  108.  
  109. //
  110. // Jikes can be compiled on systems using the EBCDIC character set, for which character and string
  111. // literals are translated by the compiler to EBCDIC and not ASCII, and so cannot be used to represent
  112. // ASCII/UNICODE values. Such values are constructed using the U_ values defined below. Thus
  113. // 'a' is represented using U_a, and ".java" is represented by an explicit literal:
  114. //    {U_DOT, U_j, U_a, U_v, U_a, U_NULL}
  115. // Variables associated with such literals have names beginning with US_ if the value are 16-bits
  116. // or U8S_ for 8 bits. The initial underscore is followed by the characters being represented, with
  117. // letters and digits representing themselves, and other values, all of which have a two character code,
  118. // surrounded by underscore. Thus the name used for the literal above is US__DO_java.
  119. //
  120. // All string-related values are represented internally in ASCII/UNICODE using the U_ values defined
  121. // below. EBCDIC systems also require that arguments to system functions representing file names be
  122. // converted from the internal form used by Jikes to EBCDIC, and such functions are referred to using
  123. // their usual name prefixed with "system_"; for example, a call to "fopen(..." is written "system_fopen(..."
  124. // The "system_" procedures are define in the file code.cpp.
  125. //
  126. enum U_chars
  127. {
  128.     U_NULL = 0,               U_NU = U_NULL,            // L'\0'
  129.     U_BACKSPACE = 8,          U_BS = U_BACKSPACE,       // L'\b'
  130.     U_HORIZONTAL_TAB = 9,     U_HT = U_HORIZONTAL_TAB,  // L'\t'
  131.     U_LINE_FEED = 10,         U_LF = U_LINE_FEED,       // L'\n'
  132.     U_FORM_FEED = 12,         U_FF = U_FORM_FEED,       // L'\f'
  133.     U_CARRIAGE_RETURN = 13,   U_CR = U_CARRIAGE_RETURN, // L'\r'
  134.  
  135.     U_CTL_Z = 26,
  136.     U_ESCAPE = 27,
  137.  
  138.     U_SPACE = 32,             U_SP = U_SPACE,             // L' '
  139.     U_EXCLAMATION = 33,       U_EX = U_EXCLAMATION,       // L'!'
  140.     U_DOUBLE_QUOTE = 34,      U_DQ = U_DOUBLE_QUOTE,      // L'"'
  141.     U_POUND = 35,             U_SH = U_POUND,             // L'#'
  142.     U_DOLLAR = 36,            U_DS = U_DOLLAR,            // L'$'
  143.     U_PERCENT = 37,           U_PE = U_PERCENT,           // L'%'
  144.     U_AMPERSAND = 38,         U_AM = U_AMPERSAND,         // L'&'
  145.     U_SINGLE_QUOTE = 39,      U_SQ = U_SINGLE_QUOTE,      // L'\''
  146.     U_LEFT_PARENTHESIS = 40,  U_LP = U_LEFT_PARENTHESIS,  // L'('
  147.     U_RIGHT_PARENTHESIS = 41, U_RP = U_RIGHT_PARENTHESIS, // L')'
  148.     U_STAR = 42,              U_ST = U_STAR,              // L'*'
  149.     U_PLUS = 43,              U_PL = U_PLUS,              // L'+'
  150.     U_COMMA = 44,             U_CM = U_COMMA,             // L'-'
  151.     U_MINUS = 45,             U_MI = U_MINUS,             // L','
  152.     U_DOT = 46,               U_DO = U_DOT,               // L'.'
  153.     U_SLASH = 47,             U_SL = U_SLASH,             // L'/'
  154.  
  155.     U_0 = 48, // L'0'
  156.     U_1 = 49, // L'1'
  157.     U_2 = 50, // L'2'
  158.     U_3 = 51, // L'3'
  159.     U_4 = 52, // L'4'
  160.     U_5 = 53, // L'5'
  161.     U_6 = 54, // L'6'
  162.     U_7 = 55, // L'7'
  163.     U_8 = 56, // L'8'
  164.     U_9 = 57, // L'9'
  165.  
  166.     U_COLON = 58,             U_CO = U_COLON,     // L':'
  167.     U_SEMICOLON = 59,         U_SC = U_SEMICOLON, // L';'
  168.     U_LESS = 60,              U_LT = U_LESS,      // L'<'
  169.     U_EQUAL = 61,             U_EQ = U_EQUAL,     // L'='
  170.     U_GREATER = 62,           U_GT = U_GREATER,   // L'>'
  171.     U_QUESTION = 63,          U_QU = U_QUESTION,  // L'?'
  172.     U_AT = 64,                                    // L'@'
  173.  
  174.     U_A = 65, // L'A'
  175.     U_B = 66, // L'B'
  176.     U_C = 67, // L'C'
  177.     U_D = 68, // L'D'
  178.     U_E = 69, // L'E'
  179.     U_F = 70, // L'F'
  180.     U_G = 71, // L'G'
  181.     U_H = 72, // L'H'
  182.     U_I = 73, // L'I'
  183.     U_J = 74, // L'J'
  184.     U_K = 75, // L'K'
  185.     U_L = 76, // L'L'
  186.     U_M = 77, // L'M'
  187.     U_N = 78, // L'N'
  188.     U_O = 79, // L'O'
  189.     U_P = 80, // L'P'
  190.     U_Q = 81, // L'Q'
  191.     U_R = 82, // L'R'
  192.     U_S = 83, // L'S'
  193.     U_T = 84, // L'T'
  194.     U_U = 85, // L'U'
  195.     U_V = 86, // L'V'
  196.     U_W = 87, // L'W'
  197.     U_X = 88, // L'X'
  198.     U_Y = 89, // L'Y'
  199.     U_Z = 90, // L'Z'
  200.  
  201.     U_LEFT_BRACKET = 91,      U_LB = U_LEFT_BRACKET,  // L'['
  202.     U_BACKSLASH = 92,         U_RS = U_BACKSLASH,     // L'\\'
  203.     U_RIGHT_BRACKET = 93,     U_RB = U_RIGHT_BRACKET, // L']'
  204.     U_CARET = 94,             U_CA = U_CARET,         // L'^'
  205.     U_UNDERSCORE = 95,        U_UN = U_UNDERSCORE,    // L'_'
  206.  
  207.     U_a = 97, // L'a'
  208.     U_b = 98, // L'b'
  209.     U_c = 99, // L'c'
  210.     U_d = 100, // L'd'
  211.     U_e = 101, // L'e'
  212.     U_f = 102, // L'f'
  213.     U_g = 103, // L'g'
  214.     U_h = 104, // L'h'
  215.     U_i = 105, // L'i'
  216.     U_j = 106, // L'j'
  217.     U_k = 107, // L'k'
  218.     U_l = 108, // L'l'
  219.     U_m = 109, // L'm'
  220.     U_n = 110, // L'n',
  221.     U_o = 111, // L'o'
  222.     U_p = 112, // L'p'
  223.     U_q = 113, // L'q'
  224.     U_r = 114, // L'r'
  225.     U_s = 115, // L's'
  226.     U_t = 116, // L't'
  227.     U_u = 117, // L'u'
  228.     U_v = 118, // L'v'
  229.     U_w = 119, // L'w'
  230.     U_x = 120, // L'x'
  231.     U_y = 121, // L'y'
  232.     U_z = 122, // L'z'
  233.  
  234.     U_LEFT_BRACE = 123,       U_OS = U_LEFT_BRACE,  // L'{'
  235.     U_BAR = 124,              U_BA = U_BAR,         // L'|'
  236.     U_RIGHT_BRACE = 125,      U_CS = U_RIGHT_BRACE, // L'}'
  237.     U_TILDE = 126,            U_TI = U_TILDE,       // L'~'
  238.  
  239.     U_chars_size
  240. };
  241.  
  242.  
  243. //
  244. // Constant strings used in the program.
  245. //
  246. class StringConstant
  247. {
  248. public:
  249.     static wchar_t US_AND[], // "&"
  250.                    US_AND_AND[], // "&&"
  251.                    US_AND_EQUAL[], // "&="
  252.                    US_COLON[], // ":"
  253.                    US_COMMA[], // ","
  254.                    US_DIVIDE[], // "/"
  255.                    US_DIVIDE_EQUAL[], // "/="
  256.                    US_DOT[], // "."
  257.                    US_EMPTY[], // ""
  258.                    US_EQUAL[], // "="
  259.                    US_EQUAL_EQUAL[], // "=="
  260.                    US_GREATER[], // ">"
  261.                    US_GREATER_EQUAL[], // ">="
  262.                    US_LBRACE[], // "{"
  263.                    US_LBRACKET[], // "["
  264.                    US_LEFT_SHIFT[], // "<<"
  265.                    US_LEFT_SHIFT_EQUAL[], // "<<="
  266.                    US_LESS[], // "<"
  267.                    US_LESS_EQUAL[], // "<="
  268.                    US_LPAREN[], // "("
  269.                    US_MINUS[], // "-"
  270.                    US_MINUS_EQUAL[], // "-="
  271.                    US_MINUS_MINUS[], // "--"
  272.                    US_MULTIPLY[], // "*"
  273.                    US_MULTIPLY_EQUAL[], // "*="
  274.                    US_NOT[], // "!"
  275.                    US_NOT_EQUAL[], // "!="
  276.                    US_OR[], // "|"
  277.                    US_OR_EQUAL[], // "|="
  278.                    US_OR_OR[], // "||"
  279.                    US_PLUS[], // "+"
  280.                    US_PLUS_EQUAL[], // "+="
  281.                    US_PLUS_PLUS[], // "++"
  282.                    US_QUESTION[], // "?"
  283.                    US_RBRACE[], // "}"
  284.                    US_RBRACKET[], // "]"
  285.                    US_REMAINDER[], // "%"
  286.                    US_REMAINDER_EQUAL[], // "%="
  287.                    US_RIGHT_SHIFT[], // ">>"
  288.                    US_RIGHT_SHIFT_EQUAL[], // ">>="
  289.                    US_RPAREN[], // ")"
  290.                    US_SEMICOLON[], // ";"
  291.                    US_TWIDDLE[], // "~"
  292.                    US_UNSIGNED_RIGHT_SHIFT[], // ">>>"
  293.                    US_UNSIGNED_RIGHT_SHIFT_EQUAL[], // ">>>="
  294.                    US_XOR[], // "^"
  295.                    US_XOR_EQUAL[], // "^="
  296.  
  297.                    US_Boolean[], // "Boolean"
  298.                    US_Byte[], // "Byte"
  299.                    US_Character[], // "Character"
  300.                    US_Class[], // "Class"
  301.                    US_ClassNotFoundException[], // "ClassNotFoundException"
  302.                    US_Cloneable[], // "Cloneable"
  303.                    US_Double[], // "Double"
  304.                    US_Error[], // "Error"
  305.                    US_Float[],  // "Float"
  306.                    US_Integer[], // "Integer"
  307.                    US_L[], // "L"
  308.                    US_Long[], // "Long"
  309.                    US_NoClassDefFoundError[], // "NoClassDefFoundError"
  310.                    US_Object[], // "Object"
  311.                    US_PObject[], // "PObject"
  312.                    US_RuntimeException[], // "RuntimeException"
  313.                    US_Serializable[], // "Serializable"
  314.                    US_Short[], // "Short"
  315.                    US_StringBuffer[], // "StringBuffer"
  316.                    US_String[], // "String"
  317.                    US_TYPE[], // "TYPE"
  318.                    US_Throwable[], // "Throwable"
  319.                    US_Void[], // "Void"
  320.                    US__DO[], // "."
  321.                    US__DO__DO[], // ".."
  322.                    US__DS[], // "$"
  323.                    US__LB__RB[], // "[]"
  324.                    US__LT_clinit_GT[], // "<clinit>"
  325.                    US__LT_init_GT[], // "<init>"
  326.                    US__QU__QU[],  // "??"
  327.                    US__SC[], // ";"
  328.                    US__SL[], // "/"
  329.  
  330.                    US__zip[], // "zip"
  331.                    US__jar[], // "jar"
  332.  
  333.                    US__array[], // "array"
  334.                    US__access_DOLLAR[], // "access$"
  335.                    US__class_DOLLAR[], // "class$"
  336.                    US__constructor_DOLLAR[], // "constructor$"
  337.                    US__this_DOLLAR[], // "this$"
  338.                    US__val_DOLLAR[], // "val$"
  339.  
  340.                    US_abstract[], // "abstract"
  341.                    US_append[], // "append"
  342.                    US_block_DOLLAR[], // "block$"
  343.                    US_boolean[], // "boolean"
  344.                    US_break[], // "break"
  345.                    US_byte[], // "byte"
  346.                    US_case[], // "case"
  347.                    US_catch[], // "catch"
  348.                    US_char[], // "char"
  349.                    US_class[], // "class"
  350.                    US_clone[], // "clone"
  351.                    US_const[], // "const"
  352.                    US_continue[], // "continue"
  353.                    US_default[], // "default"
  354.                    US_do[], // "do"
  355.                    US_double[], // "double"
  356.                    US_else[], // "else"
  357.                    US_extends[], // "extends"
  358.                    US_false[], // "false"
  359.                    US_final[], // "final"
  360.                    US_finally[], // "finally"
  361.                    US_float[], // "float"
  362.                    US_for[], // "for"
  363.                    US_forName[], // "forName"
  364.                    US_getMessage[], // "getMessage"
  365.                    US_goto[], // "goto"
  366.                    US_if[], // "if"
  367.                    US_implements[], // "implements"
  368.                    US_import[], // "import"
  369.                    US_instanceof[], // "instanceof"
  370.                    US_int[], // "int"
  371.                    US_interface[], // "interface"
  372.                    US_java_SL_io[], // "java/io"
  373.                    US_java_SL_lang[], // "java/lang"
  374.                    US_length[], // "length"
  375.                    US_long[], // "long"
  376.                    US_native[], // "native"
  377.                    US_new[], // "new"
  378.                    US_null[], // "null"
  379.                    US_package[], // "package"
  380.                    US_private[], // "private"
  381.                    US_protected[], // "protected"
  382.                    US_public[], // "public"
  383.                    US_return[], // "return"
  384.                    US_short[], // "short"
  385.                    US_static[], // "static"
  386.                    US_strictfp[], // "strictfp"
  387.                    US_super[], // "super"
  388.                    US_switch[], // "switch"
  389.                    US_synchronized[], // "synchronized"
  390.                    US_this0[], // "this$0"
  391.                    US_this[], // "this"
  392.                    US_throw[], // "throw"
  393.                    US_throws[], // "throws"
  394.                    US_toString[], // "toString"
  395.                    US_transient[], // "transient"
  396.                    US_true[], // "true"
  397.                    US_try[], // "try"
  398.                    US_void[], // "void"
  399.                    US_volatile[], // "volatile"
  400.                    US_while[], // "while"
  401.  
  402.                    US_EOF[]; // "EOF"
  403.  
  404.     static wchar_t US_smallest_int[]; // "-2147483648"
  405.  
  406.     static char U8S_command_format[];
  407.  
  408.     static int U8S_ConstantValue_length,
  409.                U8S_Exceptions_length,
  410.                U8S_InnerClasses_length,
  411.                U8S_Synthetic_length,
  412.                U8S_Deprecated_length,
  413.                U8S_LineNumberTable_length,
  414.                U8S_LocalVariableTable_length,
  415.                U8S_Code_length,
  416.                U8S_Sourcefile_length,
  417.  
  418.                U8S_null_length,
  419.                U8S_this_length;
  420.  
  421.     static char U8S_B[], // "B"
  422.                 U8S_C[], // "C"
  423.                 U8S_Code[], // "Code"
  424.                 U8S_ConstantValue[], // "ConstantValue"
  425.                 U8S_D[], // "D"
  426.                 U8S_Exceptions[], // "Exceptions"
  427.                 U8S_F[], // "F"
  428.                 U8S_I[], // "I"
  429.                 U8S_InnerClasses[], // "InnerClasses"
  430.                 U8S_J[],  // "J"
  431.                 U8S_LP_Ljava_SL_lang_SL_String_SC_RP_Ljava_SL_lang_SL_Class_SC[], // "(Ljava/lang/String;)Ljava/lang/Class;"
  432.                 U8S_LP_Ljava_SL_lang_SL_String_SC_RP_V[], // "(Ljava/lang/String;)V"
  433.                 U8S_LP_RP_Ljava_SL_lang_SL_String_SC[], // "()Ljava/lang/String;"
  434.                 U8S_LP_RP_V[], // "()V"
  435.                 U8S_LineNumberTable[], // "LineNumberTable"
  436.                 U8S_LocalVariableTable[], // "LocalVariableTable"
  437.                 U8S_S[], // "S"
  438.                 U8S_Sourcefile[], // "Sourcefile"
  439.                 U8S_Synthetic[], // "Synthetic"
  440.                 U8S_Deprecated[], // "Deprecated"
  441.                 U8S_V[], // "V"
  442.                 U8S_Z[], // "Z"
  443.  
  444.                 U8S__DO[], // "."
  445.                 U8S__DO_class[], // ".class"
  446.                 U8S__DO_java[], // ".java"
  447.                 U8S__DO_tok[], // ".tok"
  448.                 U8S__DO_u[], // ".u"
  449.                 U8S__LP[], // "("
  450.                 U8S__RP[], // ")"
  451.                 U8S__SL[], // "/"
  452.                 U8S__ST[], // "*"
  453.  
  454.                 U8S_class[], // "class"
  455.                 U8S_java[], // "java"
  456.                 U8S_java_SL_lang_SL_ClassNotFoundException[], // "java/lang/ClassNotFoundException"
  457.                 U8S_java_SL_lang_SL_Class[], // "java/lang/Class"
  458.                 U8S_java_SL_lang_SL_InternalError[], // "java/lang/InternalError"
  459.                 U8S_java_SL_lang_SL_NoClassDefFoundError[], // "java/lang/NoClassDefFoundError"
  460.                 U8S_java_SL_lang_SL_StringBuffer[], // "java/lang/StringBuffer"
  461.                 U8S_java_SL_lang_SL_Throwable[], // "java/lang/Throwable"
  462.                 U8S_null[], // "null"
  463.                 U8S_quit[], // "quit"
  464.                 U8S_this[], // "this"
  465.  
  466.                 U8S_LP_LB_C_RP_Ljava_SL_lang_SL_StringBuffer_SC[], // "([C)Ljava/lang/StringBuffer;"
  467.                 U8S_LP_C_RP_Ljava_SL_lang_SL_StringBuffer_SC[], // "(C)Ljava/lang/StringBuffer;"
  468.                 U8S_LP_Z_RP_Ljava_SL_lang_SL_StringBuffer_SC[], // "(Z)Ljava/lang/StringBuffer;"
  469.                 U8S_LP_I_RP_Ljava_SL_lang_SL_StringBuffer_SC[], // "(I)Ljava/lang/StringBuffer;"
  470.                 U8S_LP_J_RP_Ljava_SL_lang_SL_StringBuffer_SC[], // "(J)Ljava/lang/StringBuffer;"
  471.                 U8S_LP_F_RP_Ljava_SL_lang_SL_StringBuffer_SC[], // "(F)Ljava/lang/StringBuffer;"
  472.                 U8S_LP_D_RP_Ljava_SL_lang_SL_StringBuffer_SC[], // "(D)Ljava/lang/StringBuffer;"
  473.                 U8S_LP_Ljava_SL_lang_SL_String_SC_RP_Ljava_SL_lang_SL_StringBuffer_SC[], // "(Ljava/lang/String;)Ljava/lang/StringBuffer;"
  474.                 U8S_LP_Ljava_SL_lang_SL_Object_SC_RP_Ljava_SL_lang_SL_StringBuffer_SC[]; // "(Ljava/lang/Object;)Ljava/lang/StringBuffer;"
  475.  
  476.     static char U8S_smallest_int[]; // "-2147483648"
  477. };
  478.  
  479.  
  480. //
  481. // Convert an integer to its character string representation.
  482. //
  483. class IntToString
  484. {
  485. public:
  486.     IntToString(int num)
  487.     {
  488.         if (num == 0x80000000)
  489.         {
  490.             str = info;
  491.             strcpy(str, StringConstant::U8S_smallest_int);
  492.         }
  493.         else
  494.         {
  495.             str = &info[11];
  496.             *str = U_NULL;
  497.             int n = (num < 0 ? -num : num);
  498.             do
  499.             {
  500.                 *--str = (U_0 + n % 10);
  501.                 n /= 10;
  502.             } while (n != 0);
  503.  
  504.             if (num < 0)
  505.                 *--str = '-';
  506.         }
  507.     }
  508.  
  509.     char *String() { return str; }
  510.     int Length()   { return (&info[11]) - str; }
  511.  
  512. private:
  513.  
  514.     char info[12],
  515.          *str;
  516. };
  517.  
  518.  
  519. //
  520. // Same as IntToString for wide strings
  521. //
  522. class IntToWstring
  523. {
  524. public:
  525.     IntToWstring(int num)
  526.     {
  527.         if (num == 0x80000000)
  528.         {
  529.             wstr = winfo;
  530.             wcscpy(wstr,  StringConstant::US_smallest_int);
  531.         }
  532.         else
  533.         {
  534.             wstr = &winfo[11];
  535.             *wstr = U_NULL;
  536.             int n = (num < 0 ? -num : num);
  537.             do
  538.             {
  539.                 *--wstr = (U_0 + n % 10);
  540.                 n /= 10;
  541.             } while (n != 0);
  542.  
  543.             if (num < 0)
  544.                 *--wstr = '-';
  545.         }
  546.     }
  547.  
  548.     wchar_t *String() { return wstr; }
  549.     int Length()      { return (&winfo[11]) - wstr; }
  550.  
  551. private:
  552.  
  553.     wchar_t winfo[12],
  554.             *wstr;
  555. };
  556.  
  557.  
  558. //
  559. // If the system runs out of memory, this function is invoked.
  560. //
  561. void SetNewHandler();
  562. #ifdef MICROSOFT
  563.     extern int OutOfMemory(size_t);
  564. #else
  565.     extern void OutOfMemory();
  566. #endif
  567.  
  568.  
  569. //
  570. // When using the ICC compiler on Win95 or OS/2, we need to disable
  571. // testing for various floating point exceptions. Default behavior
  572. // was causing problems reading some standard class files.
  573. //
  574. extern void FloatingPointCheck();
  575.  
  576.  
  577. //
  578. // variants of system functions requiring EBCDIC translation
  579. // are declared here and defined in code.cpp
  580. //
  581. extern int SystemStat(const char *name, struct stat *stat_struct);
  582. extern FILE *SystemFopen(char *name, char *mode);
  583. extern size_t SystemFread(char *ptr, size_t element_size, size_t count, FILE *stream,int ascii_option = 0);
  584. extern int SystemIsDirectory(char *name);
  585.  
  586.  
  587. #ifdef UNIX
  588. #define UNIX_FILE_SYSTEM
  589. #endif
  590.  
  591. #ifdef __amigaos__
  592. #define AMIGAOS_FILE_SYSTEM
  593. #endif
  594.  
  595.  
  596. //
  597. // The symbol used in this environment for separating argument in a system string. E.g., in a unix system
  598. // directories specified in the CLASSPATH are separated by a ':', whereas in win95 it is ';'.
  599. //
  600. extern char PathSeparator();
  601. extern int SystemMkdir(char *);
  602.  
  603. //
  604. // Some compilers do not correctly predefine the primitive type "bool"
  605. // and its possible values: "false" and "true"
  606. //
  607. #ifndef TYPE_bool
  608. //======================================================================
  609. // We define the type "bool" and the constants "false" and "true".
  610. // The type bool as well as the constants false and true are expected
  611. // to become standard C++. When that happens, these declarations should
  612. // be removed.
  613. //======================================================================
  614. typedef unsigned char bool;
  615. enum { false = 0, true = 1 };
  616. #endif
  617.  
  618. class LongInt;
  619. class ULongInt;
  620. //
  621. //
  622. //
  623. class Ostream
  624. {
  625.     ostream *os;
  626.  
  627.     bool expand_wchar;
  628.  
  629. public:
  630.  
  631.     Ostream() : os(&cerr),
  632.                 expand_wchar(false)
  633.     {}
  634.  
  635.     void StandardOutput() { os = &cout; }
  636.     void SetExpandWchar() { expand_wchar = true; }
  637.     bool ExpandWchar() { return expand_wchar; }
  638.  
  639.     Ostream &operator<<(wchar_t ch)
  640.     {
  641.         if (ch >> 8 == 0)
  642.             *os << (char) ch;
  643.         else
  644.         {
  645.             if (expand_wchar == 0)
  646.                 *os << (char) U_QUESTION;
  647.             else
  648.             {
  649.                 *os << (char) U_BACKSLASH
  650.                     << (char) U_u;
  651.  
  652.                 char str[4];
  653.                 for (int i = 3; i >= 0; i--)
  654.                 {
  655.                     int d = ch % 16;
  656.                     switch(d)
  657.                     {
  658.                         case 10:
  659.                             str[i] = U_A;
  660.                             break;
  661.                         case 11:
  662.                             str[i] = U_B;
  663.                             break;
  664.                         case 12:
  665.                             str[i] = U_C;
  666.                             break;
  667.                         case 13:
  668.                             str[i] = U_D;
  669.                             break;
  670.                         case 14:
  671.                             str[i] = U_E;
  672.                             break;
  673.                         case 15:
  674.                             str[i] = U_F;
  675.                             break;
  676.                         default:
  677.                             str[i] = U_0 + d;
  678.                             break;
  679.                     }
  680.                     ch /= 16;
  681.                 }
  682.                 *os << str[0];
  683.                 *os << str[1];
  684.                 *os << str[2];
  685.                 *os << str[3];
  686.             }
  687.         }
  688.  
  689.         return *this;
  690.     }
  691.  
  692.     Ostream &operator<<(const wchar_t *str)
  693.     {
  694.         for (; *str; str++)
  695.             (*this) << *str;
  696.         return *this;
  697.     }
  698.  
  699.  
  700.     Ostream &operator<<(char c)
  701.     {
  702.         *os << c;
  703.         return *this;
  704.     }
  705.  
  706.     Ostream &operator<<(signed char c)
  707.     {
  708.         *os << c;
  709.         return *this;
  710.     }
  711.  
  712.     Ostream &operator<<(unsigned char c)
  713.     {
  714.         *os << c;
  715.         return *this;
  716.     }
  717.  
  718.     Ostream &operator<<(const char *c)
  719.     {
  720.         *os << c;
  721.         return *this;
  722.     }
  723.  
  724.     Ostream& operator<<(const signed char *c)
  725.     {
  726.         *os << c;
  727.         return *this;
  728.     }
  729.  
  730.     Ostream &operator<<(const unsigned char *c)
  731.     {
  732.         *os << c;
  733.         return *this;
  734.     }
  735.  
  736.     Ostream &operator<<(int a)
  737.     {
  738.         *os << a;
  739.         return *this;
  740.     }
  741.  
  742.     Ostream &operator<<(unsigned int a)
  743.     {
  744.         *os << a;
  745.         return *this;
  746.     }
  747.  
  748.     Ostream &operator<<(LongInt);
  749.     Ostream &operator<<(ULongInt);
  750.  
  751.     Ostream &operator<<(float f)
  752.     {
  753.         *os << f;
  754.         return *this;
  755.     }
  756.  
  757.     Ostream &operator<<(double d)
  758.     {
  759.         *os << d;
  760.         return *this;
  761.     }
  762.  
  763.     char fill(char c) { return os -> fill(c); }
  764.  
  765.     Ostream &flush()
  766.     {
  767.         os -> flush();
  768.         return *this;
  769.     }
  770.  
  771.     int width(int w)
  772.     {
  773.         return os -> width(w);
  774.     }
  775.  
  776.     long setf(long setbits)
  777.     {
  778.         return os -> setf(setbits);
  779.     }
  780.  
  781.     Ostream &operator<<(ios &(*f)(ios&))
  782.     {
  783.         (*f)(*os);
  784.         return *this;
  785.     }
  786. };
  787.  
  788. extern Ostream Coutput;
  789.  
  790. //
  791. // From now on, DO NOT USE cout and cerr !!!
  792. //
  793. #define cout Please_Do_Not_Use_cout_Directly_But_use_an_instance_of_Ostream_with_cout_as_argument
  794. #define cerr Please_Do_Not_Use_cerr_Directly_But_use_an_instance_of_Ostream_with_cerr_as_argument
  795.  
  796. #endif // #ifndef config_INCLUDED
  797.