Blame src/m17n-core.c

Packit Service a721b1
/* m17n-core.c -- body of the CORE API.
Packit Service a721b1
   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
Packit Service a721b1
     National Institute of Advanced Industrial Science and Technology (AIST)
Packit Service a721b1
     Registration Number H15PRO112
Packit Service a721b1
Packit Service a721b1
   This file is part of the m17n library.
Packit Service a721b1
Packit Service a721b1
   The m17n library is free software; you can redistribute it and/or
Packit Service a721b1
   modify it under the terms of the GNU Lesser General Public License
Packit Service a721b1
   as published by the Free Software Foundation; either version 2.1 of
Packit Service a721b1
   the License, or (at your option) any later version.
Packit Service a721b1
Packit Service a721b1
   The m17n library is distributed in the hope that it will be useful,
Packit Service a721b1
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service a721b1
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service a721b1
   Lesser General Public License for more details.
Packit Service a721b1
Packit Service a721b1
   You should have received a copy of the GNU Lesser General Public
Packit Service a721b1
   License along with the m17n library; if not, write to the Free
Packit Service a721b1
   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Packit Service a721b1
   Boston, MA 02110-1301 USA.  */
Packit Service a721b1
Packit Service a721b1
/***en
Packit Service a721b1
    @addtogroup m17nIntro
Packit Service a721b1
    @brief Introduction to the m17n library.
Packit Service a721b1
Packit Service a721b1
    API LEVELS
Packit Service a721b1
Packit Service a721b1
    The API of the m17n library is divided into these five.
Packit Service a721b1
Packit Service a721b1
    
    Packit Service a721b1
        
  1. CORE API
  2. Packit Service a721b1
    Packit Service a721b1
        It provides basic modules to handle M-texts.  To use this API, an
    Packit Service a721b1
        application program must include <m17n-core<EM>.h> and be
    Packit Service a721b1
        linked with -lm17n-core.
    Packit Service a721b1
    Packit Service a721b1
        
  3. SHELL API
  4. Packit Service a721b1
    Packit Service a721b1
        It provides modules for character properties, character set
    Packit Service a721b1
        handling, code conversion, etc.  They load various kinds of
    Packit Service a721b1
        data from the database on demand.  To use this API, an application
    Packit Service a721b1
        program must include <m17n<EM>.h> and be linked with
    Packit Service a721b1
        -lm17n-core -lm17n.
    Packit Service a721b1
    Packit Service a721b1
        When you use this API, CORE API is also available.
    Packit Service a721b1
    Packit Service a721b1
        
  5. FLT API
  6. Packit Service a721b1
    Packit Service a721b1
        It provides modules for text shaping using @ref mdbFLT.  To use
    Packit Service a721b1
        this API, an application program must include <m17n<EM>.h>
    Packit Service a721b1
        and be linked with -lm17n-core -lm17n-flt.
    Packit Service a721b1
    Packit Service a721b1
        When you use this API, CORE API is also available.
    Packit Service a721b1
    Packit Service a721b1
        
  7. GUI API
  8. Packit Service a721b1
    Packit Service a721b1
        It provides GUI modules such as drawing and inputting M-texts on a
    Packit Service a721b1
        graphic device.  This API itself is independent of graphic
    Packit Service a721b1
        devices, but most functions require an argument MFrame that is
    Packit Service a721b1
        created for a specific type of graphic devices.  The currently
    Packit Service a721b1
        supported graphic devices are null device, the X Window System,
    Packit Service a721b1
        and image data (gdImagePtr) of the GD library.
    Packit Service a721b1
    Packit Service a721b1
        On a frame of a null device, you cannot draw text nor use input
    Packit Service a721b1
        methods.  However, functions like mdraw_glyph_list (), etc. are
    Packit Service a721b1
        available.
    Packit Service a721b1
    Packit Service a721b1
        On a frame of the X Window System, you can use the whole GUI API.
    Packit Service a721b1
    Packit Service a721b1
        On a frame of the GD library, you can use all drawing API but
    Packit Service a721b1
        cannot use input methods.
    Packit Service a721b1
    Packit Service a721b1
        To use this API, an application program must include
    Packit Service a721b1
        <m17n-gui<EM>.h> and be linked with -lm17n-core -lm17n
    Packit Service a721b1
        -lm17n-gui.
    Packit Service a721b1
    Packit Service a721b1
        When you use this API, CORE, SHELL, and FLT APIs are also
    Packit Service a721b1
        available.
    Packit Service a721b1
    Packit Service a721b1
        
  9. MISC API
  10. Packit Service a721b1
    Packit Service a721b1
        It provides miscellaneous functions to support error handling and
    Packit Service a721b1
        debugging.  This API cannot be used standalone; it must be used
    Packit Service a721b1
        with one or more APIs listed above.  To use this API, an
    Packit Service a721b1
        application program must include <m17n-misc<EM>.h> in
    Packit Service a721b1
        addition to one of the header files described above.
    Packit Service a721b1
    Packit Service a721b1
        
    Packit Service a721b1
    Packit Service a721b1
        See also the section @ref m17n-config "m17n-config(1)".
    Packit Service a721b1
    Packit Service a721b1
        ENVIRONMENT VARIABLES
    Packit Service a721b1
    Packit Service a721b1
        The m17n library pays attention to the following environment
    Packit Service a721b1
        variables.
    Packit Service a721b1
    Packit Service a721b1
        
      Packit Service a721b1
          
    • @c M17NDIR
    • Packit Service a721b1
      Packit Service a721b1
          The name of the directory that contains data of the m17n database.
      Packit Service a721b1
          See @ref m17nDatabase for details.
      Packit Service a721b1
      Packit Service a721b1
          
    • @c MDEBUG_XXX
    • Packit Service a721b1
      Packit Service a721b1
          Environment variables whose names start with "MDEBUG_" control
      Packit Service a721b1
          debug information output.  See @ref m17nDebug for details.
      Packit Service a721b1
      Packit Service a721b1
          
      Packit Service a721b1
      Packit Service a721b1
          API NAMING CONVENTION
      Packit Service a721b1
      Packit Service a721b1
          The m17n library exports functions, variables, macros, and types.
      Packit Service a721b1
          All of them start with the letter 'm' or 'M', and are followed by
      Packit Service a721b1
          an object name (e.g. "symbol", "plist") or a module name
      Packit Service a721b1
          (e.g. draw, input).  Note that the name of M-text objects start
      Packit Service a721b1
          with "mtext" and not with "mmtext".
      Packit Service a721b1
      Packit Service a721b1
          
        Packit Service a721b1
        Packit Service a721b1
            
      • functions -- mobject () or mobject_xxx ()
      • Packit Service a721b1
        Packit Service a721b1
            They start with 'm' and are followed by an object name in lower
        Packit Service a721b1
            case.  Words are separated by '_'.  For example, msymbol (),
        Packit Service a721b1
            mtext_ref_char (), mdraw_text ().
        Packit Service a721b1
        Packit Service a721b1
            
      • non-symbol variables -- mobject, or mobject_xxx
      • Packit Service a721b1
            
        Packit Service a721b1
            The naming convention is the same as functions (e.g. mface_large).
        Packit Service a721b1
        Packit Service a721b1
            
      • symbol variables -- Mname
      • Packit Service a721b1
        Packit Service a721b1
            Variables of the type MSymbol start with 'M' and are followed by
        Packit Service a721b1
            their names.  Words are separated by '_'.  For example, Mlanguage
        Packit Service a721b1
            (the name is "language"), Miso_2022 (the name is "iso-2022").
        Packit Service a721b1
        Packit Service a721b1
            
      • macros -- MOBJECT_XXX
      • Packit Service a721b1
        Packit Service a721b1
            They start with 'M' and are followed by an object name in upper
        Packit Service a721b1
            case.  Words are separated by '_'.
        Packit Service a721b1
        Packit Service a721b1
            
      • types -- MObject or MObjectXxx
      • Packit Service a721b1
        Packit Service a721b1
            They start with 'M' and are followed by capitalized object names.
        Packit Service a721b1
            Words are concatenated directly and no '_' are used.  For example,
        Packit Service a721b1
            MConverter, MInputDriver.
        Packit Service a721b1
        Packit Service a721b1
            
        Packit Service a721b1
        Packit Service a721b1
          */
        Packit Service a721b1
        Packit Service a721b1
        /***ja
        Packit Service a721b1
            @addtogroup m17nIntro
        Packit Service a721b1
            @brief m17n ライブラリ イントロダクション.
        Packit Service a721b1
        Packit Service a721b1
            @em APIのレベル
        Packit Service a721b1
        Packit Service a721b1
            m17n ライブラリの API は以下の4種に分類されている。
        Packit Service a721b1
        Packit Service a721b1
            
          Packit Service a721b1
              
        1. コア API
        2. Packit Service a721b1
          Packit Service a721b1
              M-text を扱うための基本的なモジュールを提供する。
          Packit Service a721b1
              この API を利用するためには、アプリケーションプログラムは
          Packit Service a721b1
              <m17n-core<EM>.h> を include し、 -lm17n-core
          Packit Service a721b1
              でリンクされなくてはならない。
          Packit Service a721b1
          Packit Service a721b1
              
        3. シェル API
        4. Packit Service a721b1
          Packit Service a721b1
              文字プロパティ、文字集合操作、コード変換等のためのモジュールを提供する。
          Packit Service a721b1
              これらのモジュールは、データベースから必要に応じて多様なデータをロードする。
          Packit Service a721b1
              この API を利用するためには、アプリケーションプログラムは
          Packit Service a721b1
              <m17n<EM>.h> を include し、 -lm17n-core -lm17n
          Packit Service a721b1
              でリンクされなくてはならない。
          Packit Service a721b1
          Packit Service a721b1
              この API を使用すれば、コア API も自動的に使用可能となる。
          Packit Service a721b1
          Packit Service a721b1
              
        5. FLT API
        6. Packit Service a721b1
          Packit Service a721b1
              文字列表示に @ref mdbFLT を用いるモジュールを提供する。この API
          Packit Service a721b1
              を利用するためには、アプリケーションプログラムは <m17n<EM>.h> 
          Packit Service a721b1
              を include し、 -lm17n-core -lm17n-flt でリンクされなくてはならない。
          Packit Service a721b1
          Packit Service a721b1
              この API を使用すれば、コア API も自動的に使用可能となる。
          Packit Service a721b1
          Packit Service a721b1
              
        7. GUI API
        8. Packit Service a721b1
          Packit Service a721b1
              グラフィックデバイス上で M-text を表示したり入力したりするための
          Packit Service a721b1
              GUI モジュールを提供する。この API
          Packit Service a721b1
              自体はグラフィックデバイスとは独立であるが、
          Packit Service a721b1
              多くの関数は特定のグラフィックデバイス用に作成された 
          Packit Service a721b1
              MFrame を引数に取る。
          Packit Service a721b1
              現時点でサポートされているグラフィックデバイスは、ヌルデバイス、X
          Packit Service a721b1
              ウィンドウシステム、および GD ライブラリのイメージデータ
          Packit Service a721b1
              (gdImagePtr) である。
          Packit Service a721b1
          Packit Service a721b1
              ヌルデバイスのフレーム上では表示も入力もできない。ただし
          Packit Service a721b1
              mdraw_glyph_list () などの関数は使用可能である。
          Packit Service a721b1
          Packit Service a721b1
              X ウィンドウシステムのフレーム上ではすべての GUI API が使用できる。
          Packit Service a721b1
          Packit Service a721b1
              GD ライブラリのフレーム上では、描画用の API
          Packit Service a721b1
              はすべて使用できるが、入力はできない。
          Packit Service a721b1
          Packit Service a721b1
              この API を使用するためには、アプリケーションプログラムは
          Packit Service a721b1
              <m17n-gui<EM>.h> を include し、-lm17n-core -lm17n -lm17n-gui
          Packit Service a721b1
              でリンクされなくてはならない。
          Packit Service a721b1
          Packit Service a721b1
              この API を使用すれば、コア API、シェル API、および FLT API
          Packit Service a721b1
              も自動的に使用可能となる。
          Packit Service a721b1
          Packit Service a721b1
              
        9. その他の API
        10. Packit Service a721b1
          Packit Service a721b1
              エラー処理、デバッグ用のその他の関数を提供する。この API
          Packit Service a721b1
              はそれだけでは使用できず、上記の他の API
          Packit Service a721b1
              と共に使う。利用するためには、上記のいずれかのinclude
          Packit Service a721b1
              ファイルに加えて、 <m17n-misc<EM>.h> をinclude
          Packit Service a721b1
              しなくてはならない。
          Packit Service a721b1
          Packit Service a721b1
              
          Packit Service a721b1
          Packit Service a721b1
              @ref m17n-config "m17n-config(1)" 節も参照。
          Packit Service a721b1
          Packit Service a721b1
              @em 環境変数
          Packit Service a721b1
          Packit Service a721b1
              m17n ライブラリは以下の環境変数を参照する。
          Packit Service a721b1
          Packit Service a721b1
              
            Packit Service a721b1
                
          • @c M17NDIR
          • Packit Service a721b1
            Packit Service a721b1
                m17n データベースのデータを格納したディレクトリの名前。詳細は @ref
            Packit Service a721b1
                m17nDatabase 参照。
            Packit Service a721b1
            Packit Service a721b1
                
          • @c MDEBUG_XXX
          • Packit Service a721b1
            Packit Service a721b1
                "MDEBUG_" で始まる名前を持つ環境変数はデバッグ情報の出力を制御する。
            Packit Service a721b1
                詳細は @ref m17nDebug 参照。
            Packit Service a721b1
            Packit Service a721b1
                
            Packit Service a721b1
            Packit Service a721b1
                @em API @em の命名規則
            Packit Service a721b1
            Packit Service a721b1
                m17n ライブラリは、関数、変数、マクロ、型を export する。それらは 'm' 
            Packit Service a721b1
                または 'M' のあとにオブジェクト名 ("symbol"、"plist" など)
            Packit Service a721b1
                またはモジュール名 (draw, input など) を続けたものである。
            Packit Service a721b1
                M-text オブジェクトの名前は "mmtext" ではなくて "mtext"
            Packit Service a721b1
                で始まることに注意。
            Packit Service a721b1
                
            Packit Service a721b1
                
              Packit Service a721b1
              Packit Service a721b1
                  
            • 関数 -- mobject () または mobject_xxx ()
            • Packit Service a721b1
              Packit Service a721b1
                  'm' のあとに小文字でオブジェクト名が続く。単語間は '_'
              Packit Service a721b1
                  で区切られる。たとえば、msymbol (),
              Packit Service a721b1
                   mtext_ref_char (), mdraw_text () など。
              Packit Service a721b1
              Packit Service a721b1
                  
            • シンボルでない変数 -- mobject, または mobject_xxx
            • Packit Service a721b1
                  
              Packit Service a721b1
                  関数と同じ命名規則に従う。たとえば  mface_large など。
              Packit Service a721b1
              Packit Service a721b1
                  
            • シンボル変数 -- Mname
            • Packit Service a721b1
              Packit Service a721b1
                  MSymbol 型変数は、'M' の後に名前が続く。単語間は '_'
              Packit Service a721b1
                  で区切られる。たとえば Mlanguage (名前は "language"), Miso_2022
              Packit Service a721b1
                  (名前は"iso-2022") など。
              Packit Service a721b1
              Packit Service a721b1
                  
            • マクロ -- MOBJECT_XXX
            • Packit Service a721b1
              Packit Service a721b1
                  'M' の後に大文字でオブジェクト名が続く。単語間は '_' で区切られる。
              Packit Service a721b1
              Packit Service a721b1
                  
            • タイプ -- MObject または MObjectXxx
            • Packit Service a721b1
              Packit Service a721b1
                  'M' の後に大文字で始まるオブジェクト名が続く。単語は連続して書かれ、
              Packit Service a721b1
                  '_' は用いられない。たとえば MConverter, MInputDriver など。
              Packit Service a721b1
              Packit Service a721b1
                  
              Packit Service a721b1
                  
              Packit Service a721b1
                  */
              Packit Service a721b1
              /*=*/
              Packit Service a721b1
              /*** @{ */
              Packit Service a721b1
              #ifdef FOR_DOXYGEN
              Packit Service a721b1
              /***en
              Packit Service a721b1
                  The #M17NLIB_MAJOR_VERSION macro gives the major version number
              Packit Service a721b1
                  of the m17n library.  */
              Packit Service a721b1
              /***ja
              Packit Service a721b1
                  マクロ #M17NLIB_MAJOR_VERSION は m17n 
              Packit Service a721b1
                  ライブラリのメジャーバージョン番号を与える.  */
              Packit Service a721b1
              Packit Service a721b1
              #define M17NLIB_MAJOR_VERSION
              Packit Service a721b1
              Packit Service a721b1
              /*=*/
              Packit Service a721b1
              Packit Service a721b1
              /***en
              Packit Service a721b1
                  The #M17NLIB_MINOR_VERSION macro gives the minor version number
              Packit Service a721b1
                  of the m17n library.  */
              Packit Service a721b1
              Packit Service a721b1
              /***ja
              Packit Service a721b1
                  マクロ #M17NLIB_MINOR_VERSION は m17n 
              Packit Service a721b1
                  ライブラリのマイナーバージョン番号を与える.  */
              Packit Service a721b1
              Packit Service a721b1
              #define M17NLIB_MINOR_VERSION
              Packit Service a721b1
              Packit Service a721b1
              /*=*/
              Packit Service a721b1
              Packit Service a721b1
              /***en
              Packit Service a721b1
                  The #M17NLIB_PATCH_LEVEL macro gives the patch level number
              Packit Service a721b1
                  of the m17n library.  */
              Packit Service a721b1
              Packit Service a721b1
              /***ja
              Packit Service a721b1
                  マクロ #M17NLIB_PATCH_LEVEL は m17n 
              Packit Service a721b1
                  ライブラリのパッチレベル番号を与える.  */
              Packit Service a721b1
              Packit Service a721b1
              #define M17NLIB_PATCH_LEVEL
              Packit Service a721b1
              Packit Service a721b1
              /*=*/
              Packit Service a721b1
              Packit Service a721b1
              /***en
              Packit Service a721b1
                  The #M17NLIB_VERSION_NAME macro gives the version name of the
              Packit Service a721b1
                  m17n library as a string.  */
              Packit Service a721b1
              Packit Service a721b1
              /***ja
              Packit Service a721b1
                  マクロ #M17NLIB_VERSION_NAME は m17n 
              Packit Service a721b1
                  ライブラリのバージョン名を文字列として与える.  */
              Packit Service a721b1
              Packit Service a721b1
              #define M17NLIB_VERSION_NAME
              Packit Service a721b1
              Packit Service a721b1
              /*=*/
              Packit Service a721b1
              Packit Service a721b1
              /***en
              Packit Service a721b1
                  @brief Initialize the m17n library.
              Packit Service a721b1
              Packit Service a721b1
                  The macro M17N_INIT () initializes the m17n library.  This macro
              Packit Service a721b1
                  must be called before any m17n functions are used.
              Packit Service a721b1
              Packit Service a721b1
                  It is safe to call this macro multiple times, but in that case,
              Packit Service a721b1
                  the macro M17N_FINI () must be called the same times to free the
              Packit Service a721b1
                  memory.
              Packit Service a721b1
              Packit Service a721b1
                  If the initialization was successful, the external variable
              Packit Service a721b1
                  #merror_code is set to 0.  Otherwise it is set to -1.
              Packit Service a721b1
              Packit Service a721b1
                  @seealso
              Packit Service a721b1
                  M17N_FINI (), m17n_status ()  */
              Packit Service a721b1
              Packit Service a721b1
              /***ja
              Packit Service a721b1
                  @brief m17n ライブラリを初期化する.
              Packit Service a721b1
              Packit Service a721b1
                  マクロ M17N_INIT () は m17n ライブラリを初期化する。m17n 
              Packit Service a721b1
                  の関数を利用する前に、このマクロをまず呼ばなくてはならない。
              Packit Service a721b1
                  
              Packit Service a721b1
                  このマクロを複数回呼んでも安全であるが、その場合メモリを解放するためにマクロ
              Packit Service a721b1
                  M17N_FINI () を同じ回数呼ぶ必要がある。
              Packit Service a721b1
              Packit Service a721b1
                  外部変数 #merror_code は、初期化が成功すれば 0 に、そうでなければ 
              Packit Service a721b1
                  -1 に設定される。  
              Packit Service a721b1
              Packit Service a721b1
                  @seealso
              Packit Service a721b1
                  M17N_FINI (), m17n_status ()  */
              Packit Service a721b1
              Packit Service a721b1
              #define M17N_INIT()
              Packit Service a721b1
              Packit Service a721b1
              /*=*/
              Packit Service a721b1
              Packit Service a721b1
              /***en
              Packit Service a721b1
                  @brief Finalize the m17n library.
              Packit Service a721b1
              Packit Service a721b1
                  The macro M17N_FINI () finalizes the m17n library.  It frees all the
              Packit Service a721b1
                  memory area used by the m17n library.  Once this macro is
              Packit Service a721b1
                  called, no m17n functions should be used until the
              Packit Service a721b1
                  macro M17N_INIT () is called again.
              Packit Service a721b1
              Packit Service a721b1
                  If the macro M17N_INIT () was called N times, the Nth call of this
              Packit Service a721b1
                  macro actually free the memory. 
              Packit Service a721b1
              Packit Service a721b1
                  @seealso
              Packit Service a721b1
                  M17N_INIT (), m17n_status ()  */
              Packit Service a721b1
              /***ja
              Packit Service a721b1
                  @brief m17n ライブラリを終了する. 
              Packit Service a721b1
              Packit Service a721b1
                  マクロ M17N_FINI () は m17n ライブラリを終了する。m17n 
              Packit Service a721b1
                  ライブラリが使った全てのメモリ領域は解放される。一度このマクロが呼ばれたら、マクロ
              Packit Service a721b1
                  M17N_INIT () が再度呼ばれるまで m17n 関数は使うべきでない。
              Packit Service a721b1
              Packit Service a721b1
                  マクロ M17N_INIT () が N 回呼ばれていた場合には、このマクロが N 
              Packit Service a721b1
                  回呼ばれて初めてメモリが解放される。
              Packit Service a721b1
              Packit Service a721b1
                  @seealso
              Packit Service a721b1
                  M17N_INIT (), m17n_status ()  */
              Packit Service a721b1
              Packit Service a721b1
              #define M17N_FINI()
              Packit Service a721b1
              #endif /* FOR_DOXYGEN */
              Packit Service a721b1
              /*=*/
              Packit Service a721b1
              /*** @} */ 
              Packit Service a721b1
              /*=*/
              Packit Service a721b1
              Packit Service a721b1
              #if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
              Packit Service a721b1
              /*** @addtogroup m17nInternal
              Packit Service a721b1
                   @{ */
              Packit Service a721b1
              Packit Service a721b1
              #include <config.h>
              Packit Service a721b1
              #include <stdio.h>
              Packit Service a721b1
              #include <stdlib.h>
              Packit Service a721b1
              #include <string.h>
              Packit Service a721b1
              #include <sys/time.h>
              Packit Service a721b1
              #include <sys/resource.h>
              Packit Service a721b1
              #include <unistd.h>
              Packit Service a721b1
              Packit Service a721b1
              #include "m17n-core.h"
              Packit Service a721b1
              #include "m17n-misc.h"
              Packit Service a721b1
              #include "internal.h"
              Packit Service a721b1
              #include "symbol.h"
              Packit Service a721b1
              Packit Service a721b1
              static void
              Packit Service a721b1
              default_error_handler (enum MErrorCode err)
              Packit Service a721b1
              {
              Packit Service a721b1
                exit (err);
              Packit Service a721b1
              }
              Packit Service a721b1
              Packit Service a721b1
              static struct timeval time_stack[16];
              Packit Service a721b1
              static int time_stack_index;
              Packit Service a721b1
              Packit Service a721b1
              static M17NObjectArray *object_array_root;
              Packit Service a721b1
              Packit Service a721b1
              static void
              Packit Service a721b1
              report_object_array ()
              Packit Service a721b1
              {
              Packit Service a721b1
                fprintf (mdebug__output, "%16s %7s %7s %7s\n",
              Packit Service a721b1
              	   "object", "created", "freed", "alive");
              Packit Service a721b1
                fprintf (mdebug__output, "%16s %7s %7s %7s\n",
              Packit Service a721b1
              	   "------", "-------", "-----", "-----");
              Packit Service a721b1
                for (; object_array_root; object_array_root = object_array_root->next)
              Packit Service a721b1
                  {
              Packit Service a721b1
                    M17NObjectArray *array = object_array_root;
              Packit Service a721b1
              Packit Service a721b1
                    fprintf (mdebug__output, "%16s %7d %7d %7d\n", array->name,
              Packit Service a721b1
              	       array->used, array->used - array->count, array->count);
              Packit Service a721b1
                    if (array->count > 0)
              Packit Service a721b1
              	{
              Packit Service a721b1
              	  int i;
              Packit Service a721b1
              	  for (i = 0; i < array->used && ! array->objects[i]; i++);
              Packit Service a721b1
              Packit Service a721b1
              	  if (strcmp (array->name, "M-text") == 0)
              Packit Service a721b1
              	    {
              Packit Service a721b1
              	      MText *mt = (MText *) array->objects[i];
              Packit Service a721b1
              Packit Service a721b1
              	      if (mt->format <= MTEXT_FORMAT_UTF_8)
              Packit Service a721b1
              		fprintf (mdebug__output, "\t\"%s\"\n", (char *) mt->data);
              Packit Service a721b1
              	    }
              Packit Service a721b1
              	  else if (strcmp (array->name, "Plist") == 0)
              Packit Service a721b1
              	    {
              Packit Service a721b1
              	      MPlist *plist = (MPlist *) array->objects[i];
              Packit Service a721b1
              Packit Service a721b1
              	      mdebug_dump_plist (plist, 8);
              Packit Service a721b1
              	      fprintf (mdebug__output, "\n");
              Packit Service a721b1
              	    }
              Packit Service a721b1
              	}
              Packit Service a721b1
              Packit Service a721b1
                    if (array->objects != NULL)
              Packit Service a721b1
              	{
              Packit Service a721b1
              	  free (array->objects);
              Packit Service a721b1
              	  array->count = array->used = 0;
              Packit Service a721b1
              	}
              Packit Service a721b1
                  }
              Packit Service a721b1
              }
              Packit Service a721b1
              Packit Service a721b1
              Packit Service a721b1
              
              Packit Service a721b1
              /* Internal API */
              Packit Service a721b1
              Packit Service a721b1
              int m17n__core_initialized;
              Packit Service a721b1
              int m17n__shell_initialized;
              Packit Service a721b1
              int m17n__gui_initialized;
              Packit Service a721b1
              Packit Service a721b1
              int mdebug__flags[MDEBUG_MAX];
              Packit Service a721b1
              FILE *mdebug__output;
              Packit Service a721b1
              Packit Service a721b1
              void
              Packit Service a721b1
              mdebug__push_time ()
              Packit Service a721b1
              {
              Packit Service a721b1
                struct timezone tz;
              Packit Service a721b1
              Packit Service a721b1
                gettimeofday (time_stack + time_stack_index++, &tz;;
              Packit Service a721b1
              }
              Packit Service a721b1
              Packit Service a721b1
              void
              Packit Service a721b1
              mdebug__pop_time ()
              Packit Service a721b1
              {
              Packit Service a721b1
                time_stack_index--;
              Packit Service a721b1
              }
              Packit Service a721b1
              Packit Service a721b1
              void
              Packit Service a721b1
              mdebug__print_time ()
              Packit Service a721b1
              {
              Packit Service a721b1
                struct timeval tv;
              Packit Service a721b1
                struct timezone tz;
              Packit Service a721b1
                long diff;
              Packit Service a721b1
              Packit Service a721b1
                gettimeofday (&tv, &tz;;
              Packit Service a721b1
                diff = ((tv.tv_sec - time_stack[time_stack_index - 1].tv_sec) * 1000000
              Packit Service a721b1
              	  + (tv.tv_usec - time_stack[time_stack_index - 1].tv_usec));
              Packit Service a721b1
                fprintf (mdebug__output, "%8ld ms.", diff);
              Packit Service a721b1
                time_stack[time_stack_index - 1] = tv;
              Packit Service a721b1
              }
              Packit Service a721b1
              Packit Service a721b1
              static void
              Packit Service a721b1
              SET_DEBUG_FLAG (char *env_name, enum MDebugFlag flag)
              Packit Service a721b1
              {
              Packit Service a721b1
                char *env_value = getenv (env_name);
              Packit Service a721b1
              Packit Service a721b1
                if (env_value)
              Packit Service a721b1
                  {
              Packit Service a721b1
                    int int_value = atoi (env_value);
              Packit Service a721b1
              Packit Service a721b1
                    if (flag == MDEBUG_ALL)
              Packit Service a721b1
              	{
              Packit Service a721b1
              	  int i;
              Packit Service a721b1
              	  for (i = 0; i < MDEBUG_MAX; i++)
              Packit Service a721b1
              	    mdebug__flags[i] = int_value;
              Packit Service a721b1
              	}
              Packit Service a721b1
                    else
              Packit Service a721b1
              	mdebug__flags[flag] = int_value;
              Packit Service a721b1
                  }
              Packit Service a721b1
              }
              Packit Service a721b1
              Packit Service a721b1
              void
              Packit Service a721b1
              mdebug__add_object_array (M17NObjectArray *array, char *name)
              Packit Service a721b1
              {
              Packit Service a721b1
                array->name = name;
              Packit Service a721b1
                array->count = 0;
              Packit Service a721b1
                array->next = object_array_root;
              Packit Service a721b1
                object_array_root = array;
              Packit Service a721b1
              }
              Packit Service a721b1
              Packit Service a721b1
              Packit Service a721b1
              void
              Packit Service a721b1
              mdebug__register_object (M17NObjectArray *array, void *object)
              Packit Service a721b1
              {
              Packit Service a721b1
                if (array->objects == NULL)
              Packit Service a721b1
                  MLIST_INIT1 (array, objects, 256);
              Packit Service a721b1
                array->count++;
              Packit Service a721b1
                MLIST_APPEND1 (array, objects, object, MERROR_OBJECT);
              Packit Service a721b1
              }
              Packit Service a721b1
              Packit Service a721b1
              void
              Packit Service a721b1
              mdebug__unregister_object (M17NObjectArray *array, void *object)
              Packit Service a721b1
              {
              Packit Service a721b1
                array->count--;
              Packit Service a721b1
                if (array->count >= 0)
              Packit Service a721b1
                  {
              Packit Service a721b1
                    int i;
              Packit Service a721b1
              Packit Service a721b1
                    for (i = array->used - 1; i >= 0 && array->objects[i] != object; i--);
              Packit Service a721b1
                    if (i >= 0)
              Packit Service a721b1
              	{
              Packit Service a721b1
              	  if (i == array->used - 1)
              Packit Service a721b1
              	    array->used--;
              Packit Service a721b1
              	  array->objects[i] = NULL;
              Packit Service a721b1
              	}
              Packit Service a721b1
                    else
              Packit Service a721b1
              	mdebug_hook ();
              Packit Service a721b1
                  }
              Packit Service a721b1
                else									\
              Packit Service a721b1
                  mdebug_hook ();
              Packit Service a721b1
              }
              Packit Service a721b1
              Packit Service a721b1
              
              Packit Service a721b1
              /* External API */
              Packit Service a721b1
              Packit Service a721b1
              /* The following two are actually not exposed to a user but concealed
              Packit Service a721b1
                 by the macro M17N_INIT (). */
              Packit Service a721b1
              Packit Service a721b1
              void
              Packit Service a721b1
              m17n_init_core (void)
              Packit Service a721b1
              {
              Packit Service a721b1
                int mdebug_flag = MDEBUG_INIT;
              Packit Service a721b1
              Packit Service a721b1
                merror_code = MERROR_NONE;
              Packit Service a721b1
                if (m17n__core_initialized++)
              Packit Service a721b1
                  return;
              Packit Service a721b1
              Packit Service a721b1
                m17n_memory_full_handler = default_error_handler;
              Packit Service a721b1
              Packit Service a721b1
                SET_DEBUG_FLAG ("MDEBUG_ALL", MDEBUG_ALL);
              Packit Service a721b1
                SET_DEBUG_FLAG ("MDEBUG_INIT", MDEBUG_INIT);
              Packit Service a721b1
                SET_DEBUG_FLAG ("MDEBUG_FINI", MDEBUG_FINI);
              Packit Service a721b1
                SET_DEBUG_FLAG ("MDEBUG_CHARSET", MDEBUG_CHARSET);
              Packit Service a721b1
                SET_DEBUG_FLAG ("MDEBUG_CODING", MDEBUG_CODING);
              Packit Service a721b1
                SET_DEBUG_FLAG ("MDEBUG_DATABASE", MDEBUG_DATABASE);
              Packit Service a721b1
                SET_DEBUG_FLAG ("MDEBUG_FONT", MDEBUG_FONT); 
              Packit Service a721b1
                SET_DEBUG_FLAG ("MDEBUG_FLT", MDEBUG_FLT);
              Packit Service a721b1
                SET_DEBUG_FLAG ("MDEBUG_FONTSET", MDEBUG_FONTSET);
              Packit Service a721b1
                SET_DEBUG_FLAG ("MDEBUG_INPUT", MDEBUG_INPUT);
              Packit Service a721b1
                /* for backward compatibility... */
              Packit Service a721b1
                SET_DEBUG_FLAG ("MDEBUG_FONT_FLT", MDEBUG_FLT);
              Packit Service a721b1
                SET_DEBUG_FLAG ("MDEBUG_FONT_OTF", MDEBUG_FLT);
              Packit Service a721b1
                {
              Packit Service a721b1
                  char *env_value = getenv ("MDEBUG_OUTPUT_FILE");
              Packit Service a721b1
              Packit Service a721b1
                  mdebug__output = NULL;
              Packit Service a721b1
                  if (env_value)
              Packit Service a721b1
                    {
              Packit Service a721b1
              	if (strcmp (env_value, "stdout") == 0)
              Packit Service a721b1
              	  mdebug__output = stdout;
              Packit Service a721b1
              	else
              Packit Service a721b1
              	  mdebug__output = fopen (env_value, "a");
              Packit Service a721b1
                    }
              Packit Service a721b1
                  if (! mdebug__output)
              Packit Service a721b1
                    mdebug__output = stderr;
              Packit Service a721b1
                }
              Packit Service a721b1
              Packit Service a721b1
                MDEBUG_PUSH_TIME ();
              Packit Service a721b1
                MDEBUG_PUSH_TIME ();
              Packit Service a721b1
                if (msymbol__init () < 0)
              Packit Service a721b1
                  goto err;
              Packit Service a721b1
                MDEBUG_PRINT_TIME ("INIT", (mdebug__output, " to initialize symbol module."));
              Packit Service a721b1
                if  (mplist__init () < 0)
              Packit Service a721b1
                  goto err;
              Packit Service a721b1
                MDEBUG_PRINT_TIME ("INIT", (mdebug__output, " to initialize plist module."));
              Packit Service a721b1
                if (mchar__init () < 0)
              Packit Service a721b1
                  goto err;
              Packit Service a721b1
                MDEBUG_PRINT_TIME ("INIT",
              Packit Service a721b1
              		     (mdebug__output, " to initialize character module."));
              Packit Service a721b1
                if  (mchartable__init () < 0)
              Packit Service a721b1
                  goto err;
              Packit Service a721b1
                MDEBUG_PRINT_TIME ("INIT",
              Packit Service a721b1
              		     (mdebug__output, " to initialize chartable module."));
              Packit Service a721b1
                if (mtext__init () < 0 || mtext__prop_init () < 0)
              Packit Service a721b1
                  goto err;
              Packit Service a721b1
                MDEBUG_PRINT_TIME ("INIT", (mdebug__output, " to initialize mtext module."));
              Packit Service a721b1
                if (mdatabase__init () < 0)
              Packit Service a721b1
                  goto err;
              Packit Service a721b1
                MDEBUG_PRINT_TIME ("INIT",
              Packit Service a721b1
              		     (mdebug__output, " to initialize database module."));
              Packit Service a721b1
              Packit Service a721b1
              #if ENABLE_NLS
              Packit Service a721b1
                bindtextdomain ("m17n-lib", GETTEXTDIR);
              Packit Service a721b1
                bindtextdomain ("m17n-db", GETTEXTDIR);
              Packit Service a721b1
                bindtextdomain ("m17n-contrib", GETTEXTDIR);
              Packit Service a721b1
                bind_textdomain_codeset ("m17n-lib", "UTF-8");
              Packit Service a721b1
                bind_textdomain_codeset ("m17n-db", "UTF-8");
              Packit Service a721b1
                bind_textdomain_codeset ("m17n-contrib", "UTF-8");
              Packit Service a721b1
              #endif
              Packit Service a721b1
              Packit Service a721b1
               err:
              Packit Service a721b1
                MDEBUG_POP_TIME ();
              Packit Service a721b1
                MDEBUG_PRINT_TIME ("INIT",
              Packit Service a721b1
              		     (mdebug__output, " to initialize the core modules."));
              Packit Service a721b1
                MDEBUG_POP_TIME ();
              Packit Service a721b1
              }
              Packit Service a721b1
              Packit Service a721b1
              void
              Packit Service a721b1
              m17n_fini_core (void)
              Packit Service a721b1
              {
              Packit Service a721b1
                int mdebug_flag = MDEBUG_FINI;
              Packit Service a721b1
              Packit Service a721b1
                if (m17n__core_initialized == 0
              Packit Service a721b1
                    || --m17n__core_initialized > 0)
              Packit Service a721b1
                  return;
              Packit Service a721b1
              Packit Service a721b1
                MDEBUG_PUSH_TIME ();
              Packit Service a721b1
                MDEBUG_PUSH_TIME ();
              Packit Service a721b1
                mchartable__fini ();
              Packit Service a721b1
                MDEBUG_PRINT_TIME ("FINI", (mdebug__output, " to finalize chartable module."));
              Packit Service a721b1
                mtext__fini ();
              Packit Service a721b1
                MDEBUG_PRINT_TIME ("FINI", (mdebug__output, " to finalize mtext module."));
              Packit Service a721b1
                msymbol__fini ();
              Packit Service a721b1
                MDEBUG_PRINT_TIME ("FINI", (mdebug__output, " to finalize symbol module."));
              Packit Service a721b1
                mplist__fini ();
              Packit Service a721b1
                MDEBUG_PRINT_TIME ("FINI", (mdebug__output, " to finalize plist module."));
              Packit Service a721b1
                /* We must call this after the aboves because it frees interval
              Packit Service a721b1
                   pools.  */
              Packit Service a721b1
                mtext__prop_fini ();
              Packit Service a721b1
                MDEBUG_PRINT_TIME ("FINI", (mdebug__output, " to finalize textprop module."));
              Packit Service a721b1
                MDEBUG_POP_TIME ();
              Packit Service a721b1
                MDEBUG_PRINT_TIME ("FINI", (mdebug__output, " to finalize the core modules."));
              Packit Service a721b1
                MDEBUG_POP_TIME ();
              Packit Service a721b1
                if (mdebug__flags[MDEBUG_FINI])
              Packit Service a721b1
                  report_object_array ();
              Packit Service a721b1
                msymbol__free_table ();
              Packit Service a721b1
                if (mdebug__output != stderr)
              Packit Service a721b1
                  fclose (mdebug__output);
              Packit Service a721b1
              }
              Packit Service a721b1
              Packit Service a721b1
              /*** @} */
              Packit Service a721b1
              #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
              Packit Service a721b1
              /*=*/
              Packit Service a721b1
              Packit Service a721b1
              /*** @addtogroup m17nIntro */
              Packit Service a721b1
              Packit Service a721b1
              /*** @{  */
              Packit Service a721b1
              /*=*/
              Packit Service a721b1
              Packit Service a721b1
              /***en
              Packit Service a721b1
                  @brief Report which part of the m17n library is initialized.
              Packit Service a721b1
              Packit Service a721b1
                  The m17n_status () function returns one of these values depending
              Packit Service a721b1
                  on which part of the m17n library is initialized:
              Packit Service a721b1
              Packit Service a721b1
              	#M17N_NOT_INITIALIZED, #M17N_CORE_INITIALIZED,
              Packit Service a721b1
              	#M17N_SHELL_INITIALIZED, #M17N_GUI_INITIALIZED  */
              Packit Service a721b1
              Packit Service a721b1
              /***ja
              Packit Service a721b1
                  @brief m17n ライブラリのどの部分が初期化されたか報告する.
              Packit Service a721b1
              Packit Service a721b1
                  関数 m17n_status () は 
              Packit Service a721b1
                  m17n ライブラリのどの部分が初期化されたかに応じて、以下の値のいずれかを返す。
              Packit Service a721b1
              Packit Service a721b1
              	#M17N_NOT_INITIALIZED, #M17N_CORE_INITIALIZED,
              Packit Service a721b1
              	#M17N_SHELL_INITIALIZED, #M17N_GUI_INITIALIZED  */
              Packit Service a721b1
              Packit Service a721b1
              enum M17NStatus
              Packit Service a721b1
              m17n_status (void)
              Packit Service a721b1
              {
              Packit Service a721b1
                return (m17n__gui_initialized ? M17N_GUI_INITIALIZED
              Packit Service a721b1
              	  : m17n__shell_initialized ? M17N_SHELL_INITIALIZED
              Packit Service a721b1
              	  : m17n__core_initialized ? M17N_CORE_INITIALIZED
              Packit Service a721b1
              	  : M17N_NOT_INITIALIZED);
              Packit Service a721b1
              }
              Packit Service a721b1
              Packit Service a721b1
              /*** @} */
              Packit Service a721b1
              Packit Service a721b1
              /*=*/
              Packit Service a721b1
              /***en
              Packit Service a721b1
                  @addtogroup m17nObject
              Packit Service a721b1
                  @brief Managed objects are objects managed by the reference count.
              Packit Service a721b1
              Packit Service a721b1
                  There are some types of m17n objects that are managed by their
              Packit Service a721b1
                  reference count.  Those objects are called @e managed @e objects.
              Packit Service a721b1
                  When created, the reference count of a managed object is
              Packit Service a721b1
                  initialized to one.  The m17n_object_ref () function increments
              Packit Service a721b1
                  the reference count of a managed object by one, and the
              Packit Service a721b1
                  m17n_object_unref () function decrements by one.  A managed
              Packit Service a721b1
                  object is automatically freed when its reference count becomes
              Packit Service a721b1
                  zero.
              Packit Service a721b1
              Packit Service a721b1
                  A property whose key is a managing key can have only a managed
              Packit Service a721b1
                  object as its value.  Some functions, for instance msymbol_put ()
              Packit Service a721b1
                  and mplist_put (), pay special attention to such a property.
              Packit Service a721b1
              Packit Service a721b1
                  In addition to the predefined managed object types, users can
              Packit Service a721b1
                  define their own managed object types.  See the documentation of
              Packit Service a721b1
                  the m17n_object () for more details.  */
              Packit Service a721b1
              /***ja
              Packit Service a721b1
                  @addtogroup m17nObject
              Packit Service a721b1
                  @brief 管理下オブジェクトとは参照数によって管理されているオブジェクトである.
              Packit Service a721b1
              Packit Service a721b1
                  m17n オブジェクトのある型のものは、参照数によって管理されている。
              Packit Service a721b1
                  それらのオブジェクトは @e 管理下オブジェクト と呼ばれる。生成された時点での参照数は
              Packit Service a721b1
                  1 に初期化されている。関数 m17n_object_ref () は管理下オブジェクトの参照数を
              Packit Service a721b1
                  1 増やし、関数m17n_object_unref () は 1 減らす。参照数が
              Packit Service a721b1
                  0 になった管理下オブジェクトは自動的に解放される。
              Packit Service a721b1
              Packit Service a721b1
                  キーが管理キーであるプロパティは、値として管理下オブジェクトだけを取る。
              Packit Service a721b1
                  関数 msymbol_put () や mplist_put () などはそれらのプロパティを特別扱いする。
              Packit Service a721b1
              Packit Service a721b1
                  定義済み管理下オブジェクトタイプの他に、ユーザは必要な管理下オブジェクトタイプを自分で定義することができる。詳細は
              Packit Service a721b1
                  m17n_object () の説明を参照。  */
              Packit Service a721b1
              Packit Service a721b1
              /*** @{  */
              Packit Service a721b1
              /*=*/
              Packit Service a721b1
              /***en
              Packit Service a721b1
                  @brief Allocate a managed object.
              Packit Service a721b1
              Packit Service a721b1
                  The m17n_object () function allocates a new managed object of
              Packit Service a721b1
                  $SIZE bytes and sets its reference count to 1.  $FREER is the
              Packit Service a721b1
                  function that is used to free the object when the reference count
              Packit Service a721b1
                  becomes 0.  If $FREER is NULL, the object is freed by the free ()
              Packit Service a721b1
                  function.
              Packit Service a721b1
              Packit Service a721b1
                  The heading bytes of the allocated object is occupied by
              Packit Service a721b1
                  #M17NObjectHead.  That area is reserved for the m17n library and
              Packit Service a721b1
                  application programs should never touch it.
              Packit Service a721b1
              Packit Service a721b1
                  @return
              Packit Service a721b1
                  This function returns a newly allocated object.
              Packit Service a721b1
              Packit Service a721b1
                  @errors
              Packit Service a721b1
                  This function never fails.  */
              Packit Service a721b1
              Packit Service a721b1
              /***ja
              Packit Service a721b1
                  @brief 管理下オブジェクトを割り当てる.
              Packit Service a721b1
              Packit Service a721b1
                  関数 m17n_object () は$SIZE バイトの新しい管理下オブジェクトを割り当て、その参照数を
              Packit Service a721b1
                  1 とする。 $FREER は参照数が 0 
              Packit Service a721b1
                  になった際にそのオブジェクトを解放するために用いられる関数である。$FREER
              Packit Service a721b1
                  が NULLならば、オブジェクトは関数 free () によって解放される。
              Packit Service a721b1
              Packit Service a721b1
                  割り当てられたオブジェクト冒頭のバイトは、#M17NObjectHead 
              Packit Service a721b1
                  が占める。この領域は m17n ライブラリが使用するので、アプリケーションプログラムは触れてはならない。
              Packit Service a721b1
              Packit Service a721b1
                  @return
              Packit Service a721b1
                  この関数は新しく割り当てられたオブジェクトを返す。
              Packit Service a721b1
              Packit Service a721b1
                  @errors
              Packit Service a721b1
                  この関数は失敗しない。    */
              Packit Service a721b1
              Packit Service a721b1
              #if EXAMPLE_CODE
              Packit Service a721b1
              typedef struct
              Packit Service a721b1
              {
              Packit Service a721b1
                M17NObjectHead head;
              Packit Service a721b1
                int mem1;
              Packit Service a721b1
                char *mem2;
              Packit Service a721b1
              } MYStruct;
              Packit Service a721b1
              Packit Service a721b1
              void
              Packit Service a721b1
              my_freer (void *obj)
              Packit Service a721b1
              {
              Packit Service a721b1
                free (((MYStruct *) obj)->mem2);
              Packit Service a721b1
                free (obj);
              Packit Service a721b1
              }
              Packit Service a721b1
              Packit Service a721b1
              void
              Packit Service a721b1
              my_func (MText *mt, MSymbol key, int num, char *str)
              Packit Service a721b1
              {
              Packit Service a721b1
                MYStruct *st = m17n_object (sizeof (MYStruct), my_freer);
              Packit Service a721b1
              Packit Service a721b1
                st->mem1 = num;
              Packit Service a721b1
                st->mem2 = strdup (str);
              Packit Service a721b1
                /* KEY must be a managing key.   */
              Packit Service a721b1
                mtext_put_prop (mt, 0, mtext_len (mt), key, st);
              Packit Service a721b1
                /* This sets the reference count of ST back to 1.  */
              Packit Service a721b1
                m17n_object_unref (st);
              Packit Service a721b1
              }
              Packit Service a721b1
              #endif
              Packit Service a721b1
              Packit Service a721b1
              void *
              Packit Service a721b1
              m17n_object (int size, void (*freer) (void *))
              Packit Service a721b1
              {
              Packit Service a721b1
                M17NObject *obj = malloc (size);
              Packit Service a721b1
              Packit Service a721b1
                obj->ref_count = 1;
              Packit Service a721b1
                obj->ref_count_extended = 0;
              Packit Service a721b1
                obj->flag = 0;
              Packit Service a721b1
                obj->u.freer = freer;
              Packit Service a721b1
                return obj;
              Packit Service a721b1
              }
              Packit Service a721b1
              Packit Service a721b1
              /*=*/
              Packit Service a721b1
              Packit Service a721b1
              /***en
              Packit Service a721b1
                  @brief Increment the reference count of a managed object.
              Packit Service a721b1
              Packit Service a721b1
                  The m17n_object_ref () function increments the reference count of
              Packit Service a721b1
                  the managed object pointed to by $OBJECT.
              Packit Service a721b1
              Packit Service a721b1
                  @return
              Packit Service a721b1
                  This function returns the resulting reference count if it fits in
              Packit Service a721b1
                  a 16-bit unsigned integer (i.e. less than 0x10000).  Otherwise, it
              Packit Service a721b1
                  return -1.
              Packit Service a721b1
              Packit Service a721b1
                  @errors
              Packit Service a721b1
                  This function never fails.  */
              Packit Service a721b1
              /***ja
              Packit Service a721b1
                  @brief 管理下オブジェクトの参照数を 1 増やす.
              Packit Service a721b1
              Packit Service a721b1
                  関数 m17n_object_ref () は $OBJECT 
              Packit Service a721b1
                  で指される管理下オブジェクトの参照数を 1 増やす。
              Packit Service a721b1
              Packit Service a721b1
                  @return 
              Packit Service a721b1
                  この関数は、増やした参照数が 16 ビットの符号無し整数値(すなわち 
              Packit Service a721b1
                  0x10000 未満)におさまれば、それを返す。そうでなければ -1 を返す。
              Packit Service a721b1
              Packit Service a721b1
                  @errors
              Packit Service a721b1
                  この関数は失敗しない。    */
              Packit Service a721b1
              Packit Service a721b1
              int
              Packit Service a721b1
              m17n_object_ref (void *object)
              Packit Service a721b1
              {
              Packit Service a721b1
                M17NObject *obj = (M17NObject *) object;
              Packit Service a721b1
                M17NObjectRecord *record;
              Packit Service a721b1
                unsigned *count;
              Packit Service a721b1
              Packit Service a721b1
                if (! obj->ref_count_extended)
              Packit Service a721b1
                  {
              Packit Service a721b1
                    if (++obj->ref_count)
              Packit Service a721b1
              	return (int) obj->ref_count;
              Packit Service a721b1
                    MSTRUCT_MALLOC (record, MERROR_OBJECT);
              Packit Service a721b1
                    record->freer = obj->u.freer;
              Packit Service a721b1
                    MLIST_INIT1 (record, counts, 1);
              Packit Service a721b1
                    MLIST_APPEND1 (record, counts, 0, MERROR_OBJECT);
              Packit Service a721b1
                    obj->u.record = record;
              Packit Service a721b1
                    obj->ref_count_extended = 1;
              Packit Service a721b1
                  }
              Packit Service a721b1
                else
              Packit Service a721b1
                  record = obj->u.record;
              Packit Service a721b1
              Packit Service a721b1
                count = record->counts;
              Packit Service a721b1
                while (*count == 0xFFFFFFFF)
              Packit Service a721b1
                  *(count++) = 0;
              Packit Service a721b1
                (*count)++;
              Packit Service a721b1
                if (*count == 0xFFFFFFFF)
              Packit Service a721b1
                  MLIST_APPEND1 (record, counts, 0, MERROR_OBJECT);
              Packit Service a721b1
                return -1;
              Packit Service a721b1
              }
              Packit Service a721b1
              Packit Service a721b1
              /*=*/
              Packit Service a721b1
              Packit Service a721b1
              /***en
              Packit Service a721b1
                  @brief Decrement the reference count of a managed object.
              Packit Service a721b1
              Packit Service a721b1
                  The m17n_object_unref () function decrements the reference count
              Packit Service a721b1
                  of the managed object pointed to by $OBJECT.  When the reference
              Packit Service a721b1
                  count becomes zero, the object is freed by its freer function.
              Packit Service a721b1
              Packit Service a721b1
                  @return
              Packit Service a721b1
                  This function returns the resulting reference count if it fits in
              Packit Service a721b1
                  a 16-bit unsigned integer (i.e. less than 0x10000).  Otherwise, it
              Packit Service a721b1
                  returns -1.  Thus, the return value zero means that $OBJECT is
              Packit Service a721b1
                  freed.
              Packit Service a721b1
              Packit Service a721b1
                  @errors
              Packit Service a721b1
                  This function never fails.  */
              Packit Service a721b1
              /***ja
              Packit Service a721b1
                  @brief 管理下オブジェクトの参照数を 1 減らす.
              Packit Service a721b1
              Packit Service a721b1
                  関数 m17n_object_unref () は $OBJECT で指される管理下オブジェクトの参照数を
              Packit Service a721b1
                  1 減らす。参照数が 0 になれば、オブジェクトは解放関数によって解放される。
              Packit Service a721b1
              Packit Service a721b1
                  @return 
              Packit Service a721b1
                  この関数は、減らした参照数が 16 ビットの符号無し整数値(すなわち 
              Packit Service a721b1
                  0x10000 未満)におさまれば、それを返す。そうでなければ -1 
              Packit Service a721b1
                  を返す。つまり、0 が返って来た場合は$OBJECT は解放されている。
              Packit Service a721b1
              Packit Service a721b1
                  @errors
              Packit Service a721b1
                  この関数は失敗しない。    */
              Packit Service a721b1
              int
              Packit Service a721b1
              m17n_object_unref (void *object)
              Packit Service a721b1
              {
              Packit Service a721b1
                M17NObject *obj = (M17NObject *) object;
              Packit Service a721b1
                M17NObjectRecord *record;
              Packit Service a721b1
                unsigned *count;
              Packit Service a721b1
              Packit Service a721b1
                if (! obj->ref_count_extended)
              Packit Service a721b1
                  {
              Packit Service a721b1
                    if (! --obj->ref_count)
              Packit Service a721b1
              	{
              Packit Service a721b1
              	  if (obj->u.freer)
              Packit Service a721b1
              	    (obj->u.freer) (object);
              Packit Service a721b1
              	  else
              Packit Service a721b1
              	    free (object);
              Packit Service a721b1
              	  return 0;
              Packit Service a721b1
              	}
              Packit Service a721b1
                    return (int) obj->ref_count;
              Packit Service a721b1
                  }
              Packit Service a721b1
              Packit Service a721b1
                record = obj->u.record;
              Packit Service a721b1
                count = record->counts;
              Packit Service a721b1
                while (! *count)
              Packit Service a721b1
                  *(count++) = 0xFFFFFFFF;
              Packit Service a721b1
                (*count)--;
              Packit Service a721b1
                if (! record->counts[0])
              Packit Service a721b1
                  {
              Packit Service a721b1
                    obj->ref_count_extended = 0;
              Packit Service a721b1
                    obj->ref_count--;
              Packit Service a721b1
                    obj->u.freer = record->freer;
              Packit Service a721b1
                    MLIST_FREE1 (record, counts);
              Packit Service a721b1
                    free (record);
              Packit Service a721b1
                  }
              Packit Service a721b1
                return -1;
              Packit Service a721b1
              }
              Packit Service a721b1
              Packit Service a721b1
              /*=*/
              Packit Service a721b1
              Packit Service a721b1
              /*** @} */
              Packit Service a721b1
              Packit Service a721b1
              /***en
              Packit Service a721b1
                  @addtogroup m17nError Error Handling
              Packit Service a721b1
                  @brief Error handling of the m17n library.
              Packit Service a721b1
              Packit Service a721b1
                  There are two types of errors that may happen in a function of
              Packit Service a721b1
                  the m17n library.
              Packit Service a721b1
              Packit Service a721b1
                  The first type is argument errors.  When a library function is
              Packit Service a721b1
                  called with invalid arguments, it returns a value that indicates
              Packit Service a721b1
                  error and at the same time sets the external variable #merror_code
              Packit Service a721b1
                  to a non-zero integer.
              Packit Service a721b1
              Packit Service a721b1
                  The second type is memory allocation errors.  When the required
              Packit Service a721b1
                  amount of memory is not available on the system, m17n library
              Packit Service a721b1
                  functions call a function pointed to by the external variable @c
              Packit Service a721b1
                  m17n_memory_full_handler.  The default value of the variable is a
              Packit Service a721b1
                  pointer to the default_error_handle () function, which just calls
              Packit Service a721b1
                  <tt> exit ()</tt>.  */
              Packit Service a721b1
              Packit Service a721b1
              /***ja
              Packit Service a721b1
                  @addtogroup m17nError エラー処理
              Packit Service a721b1
                  @brief m17n ライブラリのエラー処理.
              Packit Service a721b1
              Packit Service a721b1
                  m17n ライブラリの関数では、2つの種類のエラーが起こり得る。
              Packit Service a721b1
              Packit Service a721b1
                  一つは引数のエラーである。
              Packit Service a721b1
                  ライブラリの関数が妥当でない引数とともに呼ばれた場合、その関数はエラーを意味する値を返し、同時に外部変数 
              Packit Service a721b1
                  #merror_code にゼロでない整数をセットする。
              Packit Service a721b1
              Packit Service a721b1
                  もう一つの種類はメモリ割当てエラーである。
              Packit Service a721b1
                  システムが必要な量のメモリを割当てることができない場合、ライブラリ関数は外部変数 
              Packit Service a721b1
                  @c m17n_memory_full_handler が指す関数を呼ぶ。デフォルトでは、関数 
              Packit Service a721b1
                  default_error_handle () を指しており、この関数は単に <tt>exit
              Packit Service a721b1
                  ()</tt> を呼ぶ。
              Packit Service a721b1
              */
              Packit Service a721b1
              Packit Service a721b1
              /*** @{ */
              Packit Service a721b1
              Packit Service a721b1
              /*=*/
              Packit Service a721b1
              Packit Service a721b1
              /***en 
              Packit Service a721b1
                  @brief External variable to hold error code of the m17n library.
              Packit Service a721b1
              Packit Service a721b1
                  The external variable #merror_code holds an error code of the
              Packit Service a721b1
                  m17n library.  When a library function is called with an invalid
              Packit Service a721b1
                  argument, it sets this variable to one of @c enum #MErrorCode.
              Packit Service a721b1
              Packit Service a721b1
                  This variable initially has the value 0.  */
              Packit Service a721b1
              Packit Service a721b1
              /***ja 
              Packit Service a721b1
                  @brief m17n ライブラリのエラーコードを保持する外部変数.
              Packit Service a721b1
              Packit Service a721b1
                  外部変数 #merror_code は、m17n ライブラリのエラーコードを保持する。
              Packit Service a721b1
                  ライブラリ関数が妥当でない引数とともに呼ばれた際には、この変数を 
              Packit Service a721b1
                  @c enum #MErrorCode の一つにセットする。
              Packit Service a721b1
              Packit Service a721b1
                  この変数の初期値は 0 である。  */
              Packit Service a721b1
              Packit Service a721b1
              int merror_code;
              Packit Service a721b1
              Packit Service a721b1
              /*=*/
              Packit Service a721b1
              Packit Service a721b1
              /***en 
              Packit Service a721b1
                  @brief Memory allocation error handler.
              Packit Service a721b1
              Packit Service a721b1
                  The external variable #m17n_memory_full_handler holds a pointer
              Packit Service a721b1
                  to the function to call when a library function failed to allocate
              Packit Service a721b1
                  memory.  $ERR is one of @c enum #MErrorCode indicating in which
              Packit Service a721b1
                  function the error occurred.
              Packit Service a721b1
              Packit Service a721b1
                  This variable initially points a function that simply calls the
              Packit Service a721b1
                  <tt>exit </tt>() function with $ERR as an argument.
              Packit Service a721b1
              Packit Service a721b1
                  An application program that needs a different error handling can
              Packit Service a721b1
                  change this variable to point a proper function.  */
              Packit Service a721b1
              Packit Service a721b1
              /***ja 
              Packit Service a721b1
                  @brief メモリ割当てエラーハンドラ.
              Packit Service a721b1
              Packit Service a721b1
                  変数 #m17n_memory_full_handler 
              Packit Service a721b1
                  は、ライブラリ関数がメモリ割当てに失敗した際に呼ぶべき関数へのポインタである。
              Packit Service a721b1
                  $ERR は @c enum #MErrorCode 
              Packit Service a721b1
                  のうちのいずれかであり、どのライブラリ関数でエラーが起ったかを示す。
              Packit Service a721b1
              Packit Service a721b1
                  @anchor test
              Packit Service a721b1
              Packit Service a721b1
                  初期設定では、この変数は単に <tt>exit ()</tt> を $ERR 
              Packit Service a721b1
                  を引数として呼ぶ関数を指している。
              Packit Service a721b1
              Packit Service a721b1
                  これとは異なるエラー処理を必要とするアプリケーションは、この変数を適当な関数に設定することで、目的を達成できる。  */
              Packit Service a721b1
              Packit Service a721b1
              void (*m17n_memory_full_handler) (enum MErrorCode err);
              Packit Service a721b1
              Packit Service a721b1
              /*** @} */
              Packit Service a721b1
              Packit Service a721b1
              /*=*/
              Packit Service a721b1
              Packit Service a721b1
              /***en
              Packit Service a721b1
                  @addtogroup m17nDebug
              Packit Service a721b1
                  @brief Support for m17n library users to debug their programs.
              Packit Service a721b1
              Packit Service a721b1
                  The m17n library provides the following facilities to support the
              Packit Service a721b1
                  library users to debug their programs.
              Packit Service a721b1
              Packit Service a721b1
                  
                Packit Service a721b1
                Packit Service a721b1
                    
              • Environment variables to control printing of various
              • Packit Service a721b1
                    information to stderr.
                Packit Service a721b1
                Packit Service a721b1
                    
                  Packit Service a721b1
                  Packit Service a721b1
                      
                • MDEBUG_INIT -- If set to 1, print information about the
                • Packit Service a721b1
                      library initialization on the call of M17N_INIT ().
                  Packit Service a721b1
                  Packit Service a721b1
                      
                • MDEBUG_FINI -- If set to 1, print counts of objects that are
                • Packit Service a721b1
                      not yet freed on the call of M17N_FINI ().
                  Packit Service a721b1
                  Packit Service a721b1
                      
                • MDEBUG_CHARSET -- If set to 1, print information about
                • Packit Service a721b1
                      charsets being loaded from the m17n database.
                  Packit Service a721b1
                  Packit Service a721b1
                      
                • MDEBUG_CODING -- If set to 1, print information about coding
                • Packit Service a721b1
                      systems being loaded from the m17n database.
                  Packit Service a721b1
                  Packit Service a721b1
                      
                • MDEBUG_DATABASE -- If set to 1, print information about
                • Packit Service a721b1
                      data being loaded from the m17n database.
                  Packit Service a721b1
                  Packit Service a721b1
                      
                • MDEBUG_FONT -- If set to 1, print information about fonts
                • Packit Service a721b1
                      being selected and opened.
                  Packit Service a721b1
                  Packit Service a721b1
                      
                • MDEBUG_FLT -- If set to 1, 2, or 3, print information about
                • Packit Service a721b1
                      which command of Font Layout Table are being executed.  The bigger
                  Packit Service a721b1
                      number prints the more detailed information.
                  Packit Service a721b1
                  Packit Service a721b1
                      
                • MDEBUG_INPUT -- If set to 1, print information about how an
                • Packit Service a721b1
                      input method is running.
                  Packit Service a721b1
                  Packit Service a721b1
                      
                • MDEBUG_ALL -- Setting this variable to 1 is equivalent to
                • Packit Service a721b1
                      setting all the above variables to 1.
                  Packit Service a721b1
                  Packit Service a721b1
                      
                • MDEBUG_OUTPUT_FILE -- If set to a file name, the above
                • Packit Service a721b1
                      debugging information is appended to the file.  If set to
                  Packit Service a721b1
                      "stdout", the information is printed to stdout.
                  Packit Service a721b1
                  Packit Service a721b1
                      
                  Packit Service a721b1
                  Packit Service a721b1
                      
                • Functions to print various objects in a human readable way.
                • Packit Service a721b1
                      See the documentation of mdebug_dump_XXXX () functions.
                  Packit Service a721b1
                  Packit Service a721b1
                      
                • The hook function called on an error. See the documentation
                • Packit Service a721b1
                      of mdebug_hook ().
                  Packit Service a721b1
                  Packit Service a721b1
                      
                  Packit Service a721b1
                  */
                  Packit Service a721b1
                  /***ja
                  Packit Service a721b1
                      @addtogroup m17nDebug
                  Packit Service a721b1
                      @brief m17n ライブラリユーザのためのプログラムデバッグサポート.
                  Packit Service a721b1
                  Packit Service a721b1
                      m17n ライブラリは、そのユーザが自分のプログラムをデバッグするために、以下の機能をサポートしている。
                  Packit Service a721b1
                  Packit Service a721b1
                      
                    Packit Service a721b1
                    Packit Service a721b1
                        
                  • さまざまな情報の標準エラー出力へのプリントを制御する環境変数。
                  • Packit Service a721b1
                    Packit Service a721b1
                        
                      Packit Service a721b1
                      Packit Service a721b1
                          
                    • MDEBUG_INIT -- 1 ならば、M17N_INIT ()
                    • Packit Service a721b1
                          が呼ばれた時点で、ライブラリの初期化に関する情報をプリントする。
                      Packit Service a721b1
                      Packit Service a721b1
                          
                    • MDEBUG_FINI -- 1 ならば、M17N_FINI ()
                    • Packit Service a721b1
                          が呼ばれた時点で、まだ解放されていないオブジェクトの参照数をプリントする。
                      Packit Service a721b1
                      Packit Service a721b1
                          
                    • MDEBUG_CHARSET -- 1 ならば、m17n
                    • Packit Service a721b1
                          データベースからロードされた文字セットについての情報をプリントする。
                      Packit Service a721b1
                      Packit Service a721b1
                          
                    • MDEBUG_CODING -- 1 ならば、m17n
                    • Packit Service a721b1
                          データベースからロードされたコード系についての情報をプリントする。
                      Packit Service a721b1
                      Packit Service a721b1
                          
                    • MDEBUG_DATABASE -- 1 ならば、m17n
                    • Packit Service a721b1
                          データベースからロードされたデータについての情報をプリントする。
                      Packit Service a721b1
                      Packit Service a721b1
                          
                    • MDEBUG_FONT -- 1 ならば、選択されてオープンされたフォントにつ
                    • Packit Service a721b1
                          いての情報をプリントする。
                      Packit Service a721b1
                      Packit Service a721b1
                          
                    • MDEBUG_FLT -- 1、2、もしくは 3 ならば、Font Layout Table のど
                    • Packit Service a721b1
                          のコマンドが実行中かについてのをプリントする。より大きな値程より詳
                      Packit Service a721b1
                          しい情報をプリントする。
                      Packit Service a721b1
                      Packit Service a721b1
                          
                    • MDEBUG_INPUT -- 1 ならば、実行中の入力メソッドの状態に付いての
                    • Packit Service a721b1
                          情報をプリントする。
                      Packit Service a721b1
                      Packit Service a721b1
                          
                    • MDEBUG_ALL -- 1 ならば、上記すべての変数を 1
                    • Packit Service a721b1
                          にしたのと同じ効果を持つ。
                      Packit Service a721b1
                      Packit Service a721b1
                          
                    • MDEBUG_OUTPUT_FILE -- もしファイル名なら、上記デバッグ情報はそ
                    • Packit Service a721b1
                          のファイルに追加される。もし "stdout" ならその情報は標準出力に出力
                      Packit Service a721b1
                          される。
                      Packit Service a721b1
                      Packit Service a721b1
                          
                      Packit Service a721b1
                      Packit Service a721b1
                          
                    • 種々のオブジェクトを人間に可読な形でプリントする関数。詳細は関数
                    • Packit Service a721b1
                          mdebug_dump_XXXX () の説明参照。
                      Packit Service a721b1
                      Packit Service a721b1
                          
                    • エラー発生時に呼ばれるフック関数。mdebug_hook () の説明参照。
                    • Packit Service a721b1
                      Packit Service a721b1
                          
                      Packit Service a721b1
                      */
                      Packit Service a721b1
                      Packit Service a721b1
                      /*=*/
                      Packit Service a721b1
                      /*** @{ */
                      Packit Service a721b1
                      /*=*/
                      Packit Service a721b1
                      Packit Service a721b1
                      /***en
                      Packit Service a721b1
                          @brief Hook function called on an error.
                      Packit Service a721b1
                      Packit Service a721b1
                          The mdebug_hook () function is called when an error happens.  It
                      Packit Service a721b1
                          returns -1 without doing anything.  It is useful to set a break
                      Packit Service a721b1
                          point on this function in a debugger.  */ 
                      Packit Service a721b1
                      /***ja
                      Packit Service a721b1
                          @brief エラーの際に呼ばれるフック関数.
                      Packit Service a721b1
                      Packit Service a721b1
                          関数 mdebug_hook () はエラーが起こった際に呼ばれ、何もせずに-1 
                      Packit Service a721b1
                          を返す。デバッガ内でブレークポイントを設定するために用いることができる。
                      Packit Service a721b1
                          */ 
                      Packit Service a721b1
                      Packit Service a721b1
                      int
                      Packit Service a721b1
                      mdebug_hook ()
                      Packit Service a721b1
                      {
                      Packit Service a721b1
                        return -1;
                      Packit Service a721b1
                      }
                      Packit Service a721b1
                      Packit Service a721b1
                      /*=*/
                      Packit Service a721b1
                      Packit Service a721b1
                      /*** @} */ 
                      Packit Service a721b1
                      Packit Service a721b1
                      /*
                      Packit Service a721b1
                        Local Variables:
                      Packit Service a721b1
                        coding: euc-japan
                      Packit Service a721b1
                        End:
                      Packit Service a721b1
                      */