projekty/Source/example1/src/conv.c

Go to the documentation of this file.
00001 /*
00002  * $Id: conv.c,v 1.0 2005/05/17 8:40:00 BorisK Exp $
00003  *
00004  * Copyright (C) 2005 ONTRACK s.r.o.
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA    
00019  * 02111-1307, USA.
00020  *
00021  * [1] ARM-based Microcontroller LPC2119/2129/2194/2292/9994, "Preliminary User Manual", February 03, 2004
00022  *
00023  * Written by Boris Kralik <kralikbo@yahoo.com>, 2005
00024  *
00025  */
00026 #include "conv.h"
00027 short   char2num(char inp)
00028 {
00029         return (inp-0x30);
00030 }
00031 int _memcmp(char *cs, char *ct, int count)
00032 {
00033          char *su1, *su2;
00034          int res = 0;
00035 
00036          for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
00037                  if ((res = *su1 - *su2) != 0)
00038                          break;
00039          return res;
00040 }
00041 unsigned char *_strstr(unsigned char *s1,unsigned char *s2)
00042 {
00043          int l1, l2;
00044 
00045          l2 = strlen(s2);
00046          if (!l2)
00047          {
00048                         #if 0
00049                                 UARTWriteStr("\n\rl2==0");UARTWriteStr(itoa_16(l2));
00050                         #endif
00051                  return (unsigned char *)s1;       
00052          }
00053          l2-=1;
00054          l1 = strlen(s1);
00055         #if 0
00056                 UARTWriteStr("\n\rs1=");UARTWriteStr(s1);
00057                 UARTWriteStr("\n\rl1=");UARTWriteStr(itoa_16(l1));
00058                 UARTWriteStr("\n\rl2=");UARTWriteStr(itoa_16(l2));
00059                 UARTWriteStr("\n\rs2=");UARTWriteStr(s2);
00060         #endif
00061          while (l1 >= l2) {
00062                  l1--;
00063                  if (!_memcmp(s1, s2, l2))
00064                          return (unsigned char *)s1;
00065                  s1++;
00066          }
00067          return NULL;
00068 }
00069 int iContNum(unsigned char *uchPulse,unsigned char *uchPattern)
00070 {
00071         int     vyskyt  =       0;
00072         int     iLen    =       _strlen(uchPulse);
00073         int     iPoc    =       0;
00074         #if 0
00075                 UARTWriteStr("\n\riContNum:uchPulse  =");UARTWriteStr(uchPulse);
00076                 UARTWriteStr("\n\riContNum:uchPattern=");UARTWriteStr(uchPattern);
00077         #endif
00078         do
00079         {
00080                 uchPulse=_strstr(uchPulse,uchPattern);
00081                 if (uchPulse == NULL)
00082                 {
00083                         #if 0
00084                                 UARTWriteStr("\n\riContNum:vyskyt1=");UARTWriteStr(itoa_16(vyskyt));
00085                                 UARTWriteStr("\n\riContNum:iPoc=");UARTWriteStr(itoa_16(iPoc));
00086                         #endif
00087                         iPoc++;
00088                         return (vyskyt);
00089                 }
00090                 uchPulse+=_strlen(uchPattern);
00091                 vyskyt++;
00092         }while(_strlen(uchPulse) != 0);
00093         #if 0
00094                 UARTWriteStr("\n\riContNum:vyskyt2=");UARTWriteStr(itoa_16(vyskyt));
00095         #endif
00096         return (vyskyt-1);
00097 }
00098 /*
00099         Name:           strlen
00100         Parameter:      char *
00101         Return:         int
00102         Description:    Function return number chars in input string
00103 */
00104 int strlen(char *s)
00105 {
00106         char *sc;
00107 #if 0
00108         printf("\n\rstrlen(%s)",s);
00109 #endif
00110          for (sc = s; *sc != '\0'; ++sc)
00111                 #if 0
00112                         printf("\n\rsc:%s",sc);
00113                 #else
00114                         /* nothing */;
00115                 #endif
00116 #if 0
00117         printf("\n\rstrlen(%s)=%d",s,(sc-s));
00118 #endif
00119          return sc - s;
00120 }
00121 int _strlen(char *s)
00122 {
00123          char *sc;
00124  
00125          for (sc = s; *sc != '\0'; ++sc)
00126                  /* nothing */;
00127          return sc - s;
00128 }
00129 
00130 char *strcat(char *str1,char *str2)
00131 {
00132   int i,j;
00133   char *ptr;
00134   char buf[200]="";
00135   ptr = &buf[200];
00136   for(i=0;i<strlen(str1);i++)
00137     {
00138       ptr[i]=str1[i];
00139     }
00140   for(j=0;j<strlen(str2);j++)
00141     {
00142       ptr[i+j]=str2[j];
00143     }
00144   ptr[i+j+1]='\x0';
00145   return ptr;
00146 }
00147 
00148 char *int2string(int val){
00149     char buffer[12]="";
00150     char *ptr;
00151     ptr=&buffer[12];
00152     *ptr=0;
00153     ptr--;
00154     do {
00155          *ptr = 48 + (val % 10);
00156          val = val / 10;
00157          ptr--;
00158     } while (val);
00159     ptr++;
00160     return ptr;
00161 }
00162 
00163 char *itoa_16(int val){
00164     char buffer[13]="";
00165     char *ptr;
00166     ptr=&buffer[13];
00167     *ptr=0;
00168     ptr--;
00169     do {
00170          *ptr = 48 + (val % 16);
00171          if (*ptr > 57) *ptr=(55 + (val % 16));
00172          val = val / 16;
00173          ptr--;
00174     } while (val);
00175     ptr++;
00176     return ptr;
00177 }
00178 
00179 short   strcmp(char *str1,char *str2)
00180 {
00181         int i=0,n1=strlen(str1);
00182         #if 0
00183                                 printf("\n\rstrcmp(%s,%s)=%d",str1,str2,n);
00184         #endif  
00185         if (n1 != strlen(str2)) return 0;
00186         do{
00187                 if (str1[i]!=str2[i]) {
00188                         #if 0
00189                                 printf("\n\rreturn 0");
00190                         #endif
00191                         return 0;}
00192         }while(str1[++i]!=0);
00193         
00194         return n1;
00195 }

Generated on Fri Sep 21 13:41:54 2007 for example1 by  doxygen 1.4.7