/* 日本語文字対応printf()類関数 (v1.4) * * 著作権:(c) 1999-2004 Andrew Church * * 他のソフトでの使用は(営利目的か否かに関わらず)完全に自由です。但し、 * このソースコードの再配布、または他のソフトのソースコードと一緒での配 * 布の場合は、必ず変更せずに元のままで配布して下さい。変更されたものの * 配布は禁じます。 * また、万一不具合が見つかった場合、上記メールアドレスまでご連絡下さい。 * * Copyright (c) 1999-2004 Andrew Church * * These routines may be used freely in any software, commercial or * otherwise. However, any distribution of this source code, whether * independently or as part of another program, must be of the original, * unmodified source code; distribution of modified versions of the source * code is prohibited. * Please report any bugs to the above address. */ #ifndef JPRINTF_H #define JPRINTF_H #include /*************************************************************************/ /* これらの関数は、通常のprintf()類の関数(printf, fprintf, sprintf, * snprintf, vprintf, vfprintf, vsprintf, vsnprintf)の日本語版のようなもの * で、関数名は対象となる関数の名前の先頭に「j」を付けたものになっています * (例えば、printf()の日本語版はjprintf()です)。通常の関数との違いは下記 * 3点です。 * *  ・形式(フォーマット)文字列及び「%s」で挿入される文字列に日本語の文字 *   が入っている場合、これらを自動的にプログラムが実行されているコンピュ *   ータの通常使用される文字コードに変換する。 * *  ・「%.数字s」で文字列の最大挿入文字数を指定した場合、2バイト文字(全 *   角文字)は分割されない。 * *  ・浮動小数点関係のフォーマットトークン(「%f」など)はサポートされてい *   ない。浮動小数点を出力する際は、予めsnprintf()などで文字バッファに格 *   納し、そのバッファを「%s」で出力してください。 * * なお、JPRINTF_DEFAULTを定義(#define)すれば、これらの関数は通常の関数名 * (printf, fprintf等)で呼び出せるようになります。ただ、この場合は元の関 * 数が呼び出せなくなりますのでご注意下さい。 * * These functions serve as Japanese versions of the printf() family of * functions (printf, fprintf, sprintf, snprintf, vprintf, vfprintf, * vsprintf, and vsnprintf), and are named with a "j" preceding the * appropriate function name (for example, the Japanese version of printf() * is jprintf()). There are three differences from the ordinary functions: * * - For the format string and all strings inserted with "%s", if any * Japanese characters are contained in the string, they will be * automatically converted to the encoding used on the system on which * the program is running. * * - When inserting strings with a precision value ("%.#s") to limit the * number of characters inserted, 2-byte characters will not be broken. * * - Floating-point format tokens ("%f", etc.) are not supported. To * print floating-point numbers, use e.g. snprintf() to store the * value in a character buffer, and write the buffer out with "%s". * * Additionally, if the JPRINTF_DEFAULT preprocessor symbol is defined, * these functions can be called using the ordinary printf() family of * names; however, the original functions will no longer be usable in this * case. */ /*************************************************************************/ extern int jprintf(const char *format, ...); extern int jvprintf(const char *format, va_list args); extern int jfprintf(FILE *fp, const char *format, ...); extern int jvfprintf(FILE *fp, const char *format, va_list args); extern int jsprintf(char *string, const char *format, ...); extern int jvsprintf(char *string, const char *format, va_list args); extern int jsnprintf(char *string, size_t size, const char *format, ...); extern int jvsnprintf(char *string, size_t size, const char *format, va_list args); /*************************************************************************/ #ifdef JPRINTF_DEFAULT # include # define printf jprintf # define fprintf jfprintf # define sprintf jsprintf # define snprintf jsnprintf # define vprintf jvprintf # define vfprintf jvfprintf # define vsprintf jvsprintf # define vsnprintf jvsnprintf #endif /*************************************************************************/ #endif /* JPRINTF_H */