OSDN Git Service

itoaを自前の実装に変更。
[mimic/MiMicSDK.git] / lib / src / NyLPC_stdlib.c
1 /*********************************************************************************\r
2  * PROJECT: MiMic\r
3  * --------------------------------------------------------------------------------\r
4  *\r
5  * This file is part of MiMic\r
6  * Copyright (C)2011 Ryo Iizuka\r
7  *\r
8  * MiMic is free software: you can redistribute it and/or modify\r
9  * it under the terms of the GNU Lesser General Public License as published\r
10  * by the Free Software Foundation, either version 3 of the License, or\r
11  * (at your option) any later version.\r
12  *\r
13  * This program is distributed in the hope that it will be useful,\r
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
16  * GNU General Public License for more details.\r
17  *\r
18  * You should have received a copy of the GNU Lesser General Public License\r
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
20  *\r
21  * For further information please contact.\r
22  *      http://nyatla.jp/\r
23  *      <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
24  *\r
25  *********************************************************************************/\r
26 #include "NyLPC_stdlib.h"\r
27 NyLPC_TUInt32 NyLPC_TUInt32_bswap(NyLPC_TUInt32 n)\r
28 {\r
29         return(\r
30                 ((((NyLPC_TUInt32)(n))<<24)&0xff000000)|\r
31                 ((((NyLPC_TUInt32)(n))<< 8)&0x00ff0000)|\r
32                 ((((NyLPC_TUInt32)(n))>> 8)&0x0000ff00)|\r
33                 ((((NyLPC_TUInt32)(n))>>24)&0x000000ff));\r
34 }\r
35 NyLPC_TUInt16 NyLPC_TUInt16_bswap(NyLPC_TUInt16 n)\r
36 {\r
37         return NyLPC_TUInt16_BSWAP(n);\r
38 }\r
39 \r
40 static int _line_log_l;\r
41 static const char* _line_log_m;\r
42 unsigned int NyLPC_assert_counter=0;\r
43 unsigned int NyLPC_abort_counter=0;\r
44 unsigned int NyLPC_debug_counter=0;\r
45 \r
46 void NyLPC_assertHook(const char* m,int l)\r
47 {\r
48         _line_log_l=l;\r
49         _line_log_m=m;\r
50         NyLPC_assert_counter++;\r
51         return;\r
52 }\r
53 void NyLPC_abortHook(const char* m,int l)\r
54 {\r
55         _line_log_l=l;\r
56         _line_log_m=m;\r
57         NyLPC_abort_counter++;\r
58 }\r
59 void NyLPC_debugHook(const char* m,int l)\r
60 {\r
61         _line_log_l=l;\r
62         _line_log_m=m;\r
63         NyLPC_debug_counter++;\r
64         return;\r
65 }\r
66 \r
67 NyLPC_TBool NyLPC_TCharArrayPtr_seek(struct NyLPC_TCharArrayPtr* i_struct,NyLPC_TUInt16 i_seek)\r
68 {\r
69         if(i_struct->len<i_seek){\r
70                 return NyLPC_TBool_FALSE;\r
71         }\r
72         i_struct->ptr+=i_seek;\r
73         i_struct->len-=i_seek;\r
74         return NyLPC_TBool_TRUE;\r
75 }\r
76 \r
77 NyLPC_TBool NyLPC_TUInt32ArrayPtr_seek(struct NyLPC_TUInt32ArrayPtr* i_struct,NyLPC_TUInt16 i_seek)\r
78 {\r
79         if(i_struct->len<i_seek){\r
80                 return NyLPC_TBool_FALSE;\r
81         }\r
82         i_struct->ptr+=i_seek;\r
83         i_struct->len-=i_seek;\r
84         return NyLPC_TBool_TRUE;\r
85 }\r
86 void NyLPC_TUInt32ArrayPtr_setBuf(struct NyLPC_TUInt32ArrayPtr* i_struct,NyLPC_TUInt32* i_ptr,NyLPC_TUInt16 i_len)\r
87 {\r
88         i_struct->ptr=i_ptr;\r
89         i_struct->len=i_len;\r
90 }\r
91 \r
92 \r
93 void NyLPC_itoa(int i_n,char* o_out,int i_digit)\r
94 {\r
95          int i, sign;\r
96          if ((sign = i_n) < 0){\r
97                  i_n = -i_n;\r
98          }\r
99          i = 0;\r
100          do{\r
101                  o_out[i++] = i_n % 10 + '0';\r
102          }while ((i_n /= 10) > 0);\r
103          if (sign < 0){\r
104                  o_out[i++] = '-';\r
105          }\r
106          o_out[i] = '\0';\r
107          NyLPC_reverse(o_out);\r
108 }\r
109 \r
110 void NyLPC_reverse(char* s)\r
111 {\r
112         char *j;\r
113         char c;\r
114         j = s + strlen(s) - 1;\r
115         while(s < j){\r
116                 c = *s;\r
117                 *s++ = *j;\r
118                 *j-- = c;\r
119         }\r
120 }\r