This is Webservice SDK for mbed. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088

Dependents:   MbedFileServer_1768MiniDK2 RedWireBridge IssueDebug_gcc MiMicRemoteMCU-for-Mbed ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers NyLPC_stdlib.c Source File

NyLPC_stdlib.c

00001 /*********************************************************************************
00002  * PROJECT: MiMic
00003  * --------------------------------------------------------------------------------
00004  *
00005  * This file is part of MiMic
00006  * Copyright (C)2011 Ryo Iizuka
00007  *
00008  * MiMic is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License as published
00010  * by the Free Software Foundation, either version 3 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public License
00019  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020  *
00021  * For further information please contact.
00022  *  http://nyatla.jp/
00023  *  <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
00024  *
00025  *********************************************************************************/
00026 #include "NyLPC_stdlib.h"
00027 
00028 NyLPC_TUInt32 NyLPC_TUInt32_bswap(NyLPC_TUInt32 n)
00029 {
00030     return(
00031         ((((NyLPC_TUInt32)(n))<<24)&0xff000000)|
00032         ((((NyLPC_TUInt32)(n))<< 8)&0x00ff0000)|
00033         ((((NyLPC_TUInt32)(n))>> 8)&0x0000ff00)|
00034         ((((NyLPC_TUInt32)(n))>>24)&0x000000ff));
00035 }
00036 NyLPC_TUInt16 NyLPC_TUInt16_bswap(NyLPC_TUInt16 n)
00037 {
00038     return NyLPC_TUInt16_BSWAP(n);
00039 }
00040 
00041 static int _line_log_l;
00042 static const char* _line_log_m;
00043 unsigned int NyLPC_assert_counter=0;
00044 unsigned int NyLPC_abort_counter=0;
00045 unsigned int NyLPC_debug_counter=0;
00046 
00047 void NyLPC_assertHook(const char* m,int l)
00048 {
00049     _line_log_l=l;
00050     _line_log_m=m;
00051     NyLPC_assert_counter++;
00052     return;
00053 }
00054 void NyLPC_abortHook(const char* m,int l)
00055 {
00056     _line_log_l=l;
00057     _line_log_m=m;
00058     NyLPC_abort_counter++;
00059 }
00060 void NyLPC_debugHook(const char* m,int l)
00061 {
00062     _line_log_l=l;
00063     _line_log_m=m;
00064     NyLPC_debug_counter++;
00065     return;
00066 }
00067 
00068 NyLPC_TBool NyLPC_TCharArrayPtr_seek(struct NyLPC_TCharArrayPtr* i_struct,NyLPC_TUInt16 i_seek)
00069 {
00070     if(i_struct->len<i_seek){
00071         return NyLPC_TBool_FALSE;
00072     }
00073     i_struct->ptr+=i_seek;
00074     i_struct->len-=i_seek;
00075     return NyLPC_TBool_TRUE;
00076 }
00077 
00078 NyLPC_TBool NyLPC_TUInt32ArrayPtr_seek(struct NyLPC_TUInt32ArrayPtr* i_struct,NyLPC_TUInt16 i_seek)
00079 {
00080     if(i_struct->len<i_seek){
00081         return NyLPC_TBool_FALSE;
00082     }
00083     i_struct->ptr+=i_seek;
00084     i_struct->len-=i_seek;
00085     return NyLPC_TBool_TRUE;
00086 }
00087 void NyLPC_TUInt32ArrayPtr_setBuf(struct NyLPC_TUInt32ArrayPtr* i_struct,NyLPC_TUInt32* i_ptr,NyLPC_TUInt16 i_len)
00088 {
00089     i_struct->ptr=i_ptr;
00090     i_struct->len=i_len;
00091 }
00092 
00093 
00094 /** ----------
00095  * NyLPC_TTextIdTbl
00096  ---------- */
00097 
00098 /**
00099  * IDテーブル
00100  */
00101 
00102 NyLPC_TUInt8 NyLPC_TTextIdTbl_getMatchId(const NyLPC_TChar* i_str,const struct NyLPC_TTextIdTbl i_tbl[])
00103 {
00104     int i;
00105     for(i=0;i_tbl[i].n!=NULL;i++){
00106         if(strcmp(i_str,i_tbl[i].n)==0){
00107             break;
00108         }
00109     }
00110     return i_tbl[i].id;
00111 }
00112 NyLPC_TUInt8 NyLPC_TTextIdTbl_getMatchIdIgnoreCase(const NyLPC_TChar* i_str,const struct NyLPC_TTextIdTbl i_tbl[])
00113 {
00114     int i;
00115     for(i=0;i_tbl[i].n!=NULL;i++){
00116         if(NyLPC_stricmp(i_str,i_tbl[i].n)==0){
00117             break;
00118         }
00119     }
00120     return i_tbl[i].id;
00121 }
00122 const NyLPC_TChar* NyLPC_TTextIdTbl_getTextById(NyLPC_TUInt8 i_id,const struct NyLPC_TTextIdTbl i_tbl[])
00123 {
00124     int i;
00125     for(i=0;i_tbl[i].n!=NULL;i++){
00126         if(i_id==i_tbl[i].id){
00127             return i_tbl[i].n;
00128         }
00129     }
00130     return NULL;
00131 }
00132 
00133 
00134 
00135 
00136 /** ----------
00137  * Standard functions
00138  ---------- */
00139 
00140 
00141 
00142 NyLPC_TInt8 NyLPC_itoa(int i_n,char* o_out,NyLPC_TInt8 i_base)
00143 {
00144     NyLPC_TInt8 i,v;
00145     int sign;
00146      if ((sign = i_n) < 0){
00147          i_n = -i_n;
00148      }
00149      i = 0;
00150      do{
00151          v=(NyLPC_TInt8)(i_n % i_base);
00152          o_out[i++] = (v<10)?(v+'0'):(v+'a'-10);
00153      }while ((i_n /= i_base) > 0);
00154      if (sign < 0){
00155          o_out[i++] = '-';
00156      }
00157      o_out[i] = '\0';
00158      NyLPC_reverse(o_out);
00159      return i;
00160 }
00161 NyLPC_TInt8 NyLPC_uitoa (unsigned int i_n,char* o_out,NyLPC_TInt8 i_base)
00162 {
00163     NyLPC_TInt8 i = 0;
00164     NyLPC_TInt8 v;
00165      do{
00166          v=(NyLPC_TInt8)(i_n % i_base);
00167          o_out[i++] = (v<10)?(v+'0'):(v+'a'-10);
00168      }while ((i_n /= i_base) > 0);
00169      o_out[i] = '\0';
00170      NyLPC_reverse(o_out);
00171      return i;
00172 }
00173 
00174 /**
00175  * 桁数の指定できるuitoaです。
00176  */
00177 NyLPC_TInt8 NyLPC_uitoa2(unsigned int i_n,char* o_out,NyLPC_TInt8 i_base,NyLPC_TInt8 i_digit)
00178 {
00179      NyLPC_TInt8 i = 0;
00180      NyLPC_TInt8 v;
00181      do{
00182          v=(NyLPC_TInt8)(i_n % i_base);
00183          o_out[i++] = (v<10)?(v+'0'):(v+'a'-10);
00184      }while ((i_n /= i_base) > 0);
00185      while(i<i_digit){
00186          o_out[i++] = '0';
00187      }
00188      o_out[i] = '\0';
00189      NyLPC_reverse(o_out);
00190      return i;
00191 }
00192 
00193 void NyLPC_reverse(char* s)
00194 {
00195     char *j;
00196     char c;
00197     j = s + strlen(s) - 1;
00198     while(s < j){
00199         c = *s;
00200         *s++ = *j;
00201         *j-- = c;
00202     }
00203 }
00204 
00205 
00206 int NyLPC_stricmp(const char *i_s1, const char *i_s2)
00207 {
00208     const char* s1 =i_s1;
00209     const char* s2 =i_s2;
00210     for (;*s1 != '\0';s1++, s2++)
00211     {
00212         if(*s1!=*s2){
00213             if(NyLPC_tolower(*s1) != NyLPC_tolower(*s2)){
00214               break;
00215             }
00216         }
00217     }
00218     return (int)((unsigned char)*s1) - (int)((unsigned char)(*s2));
00219 }
00220 
00221 int NyLPC_strnicmp(const char *i_s1, const char *i_s2,int n)
00222 {
00223     char c;
00224     int n2=n;
00225     for(;n2>0;n2--,i_s1++,i_s2++)
00226     {
00227         if(*i_s1!=*i_s2){
00228             c=(int)((unsigned char)NyLPC_tolower(*i_s1)) - (int)((unsigned char)NyLPC_tolower(*i_s2));
00229             if(c!=0){
00230                 return c;
00231             }
00232         }
00233     }
00234     return 0;
00235 }
00236 
00237 
00238 int NyLPC_ctoi(char i)
00239 {
00240     if('0'<=i && i<='9') return (i-'0');
00241     return 0;
00242 }
00243 int NyLPC_ctox(char i)
00244 {
00245     if('0'<=i && i<='9') return (i-'0');
00246     if('a'<=i && i<='f') return (i-'a'+10);
00247     if('A'<=i && i<='F') return (i-'A'+10);
00248     return 0;
00249 }
00250 
00251 
00252 
00253 
00254