#include <common.h> #include "conv.h" /* 文字列処理、printfの代用品 */ char *uint2string(unsigned int i, char *buffer){ unsigned int digit; unsigned int power; unsigned char hit = FALSE; for(power = 10000000; power > 1; power /= 10){ digit = i / power; if(digit > 0){hit = TRUE;} if(hit){*(buffer++) = digit + '0';} i -= digit * power; } *(buffer++) = i + '0'; return buffer; } char *ushort2string(unsigned short i, char *buffer){ unsigned short digit; unsigned short power; unsigned char hit = FALSE; for(power = 10000; power > 1; power /= 10){ digit = i / power; if(digit > 0){hit = TRUE;} if(hit){*(buffer++) = digit + '0';} i -= digit * power; } *(buffer++) = i + '0'; return buffer; } char *short2string(short i, char *buffer){ if(i < 0){ *(buffer++) = '-'; i *= -1; } return ushort2string((unsigned short)i, buffer); } char *long2string(long l, char *buffer){ if(l < 0){*(buffer++) = '-'; l *= -1;} int digit; long power; unsigned char hit = FALSE; for(power = 1000000000; power > 1; power /= 10){ digit = l / power; if(digit > 0){hit = TRUE;} if(hit){*(buffer++) = digit + '0';} l -= digit * power; } *(buffer++) = l + '0'; return buffer; } inline char *crlf(char *buffer){ *(buffer++) = '\r'; *(buffer++) = '\n'; return buffer; } inline char *null_char(char *buffer){ *(buffer++) = '\0'; return buffer; }