# kc-20220628/README.ja.txt for kc.c on Unix

Copyleft (C) 2022 Taiji Yamada <taiji@aihara.co.jp>

## kc.c for Unix

これは DOS 以外の POSIX システムでコンパイル可能に修正した kc.c です。
オリジナルは以下の source/kc/kc.c にあります。

	https://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.0/pkgs/keybs.zip

そもそも単なるテキスト処理のプログラムなので、難なく移植できますが、多
少面倒だったのが、DOS 独自の itoa 関数の実現です。kc.c のためだけの用
途であれば面倒ではないのですが、横着なコードが誤って流布しても宜しくな
いので、itoa の仕様を実現しました。

## itoa.h, itoa.c for Unix

基数 2, 8, 10, 16 以外の atoi の逆関数の必要性は不明ですが、itoa が基
数 2〜32 をサポートしているので、その通りに実現しました。以下の通り、
他にも関数を用意してあります。

--------
char *itoa(int v, char *b, const int r);
char *i16toa(int16_t v, char *b, const int r);
char *ui16toa(uint16_t v, char *b, const int r);
char *i32toa(int32_t v, char *b, const int r);
char *ui32toa(uint32_t v, char *b, const int r);
--------

検証のため、atoi ならぬ stoi なる itoa シリーズの逆関数を用意しました。

--------
int stoi(const char *b, const int r);
int16_t stoi16(const char *b, const int r);
int16_t stoui16(const char *b, const int r);
int32_t stoi32(const char *b, const int r);
uint32_t stoui32(const char *b, const int r);
--------

ちなみに、以下を実装するには、上記と同じ方針では上手くいかないでしょう。いずれ検討します。

--------
char *i64toa(int64_t v, char *b, const int r);
char *ui64toa(uint64_t v, char *b, const int r);
int64_t stoi64(const char *b, const int r);
uint64_t stoui64(const char *b, const int r);
--------

## 参考文献

[1] Microsoft, ``itoa, …,'' https://docs.microsoft.com/ja-jp/cpp/c-runtime-library/reference/itoa-itow?view=msvc-170, 2022/06/28 閲覧.
