GPS4Palm

Source Code Documentation


stringil.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  *
00003  * $RCSfile: stringil_8h-source.html,v $
00004  *
00005  * String Handling Inline Functions
00006  *
00007  * 2002-12-15:  first version, taken from the ZBoxZ application suite
00008  *              (Rev. 0.30) by Tom Zerucha
00009  *
00010  * This program is Copyright (C) 12/2002 Matthias Prinke
00011  * <matthias.prinke@surfeu.de> and covered by GNU's GPL.
00012  * In particular, this program is free software and comes WITHOUT
00013  * ANY WARRANTY.
00014  *
00015  * $Author: mp $
00016  *
00017  * $Date: 2007-10-08 20:40:34 $
00018  *
00019  * $Revision: 1.7.2.1 $
00020  *
00021  * $Log: stringil_8h-source.html,v $
00021  * Revision 1.7.2.1  2007-10-08 20:40:34  mp
00021  * updated for gps4palm V0.9.5 beta
00021  *
00022  * Revision 1.3  2005-02-19 14:34:07  mp
00023  * added #include <Unix/sys_types.h>
00024  *
00025  * Revision 1.2  2004/03/08 19:06:13  mp
00026  * Changed declaration of toupper()/tolower() from extern to static
00027  * to solve linker error.
00028  *
00029  * Revision 1.1.1.1  2003/07/14 18:59:29  mp
00030  * Imported GPS4Palm to CVS revision control.
00031  *
00032  *
00033  ****************************************************************************/
00034 
00035 /* linux (posix?) says val should be an int */
00036 //#include <string.h>
00037 #include <Unix/sys_types.h>
00038 #define VALT int
00039 #define SIZET size_t
00040 
00041 //need to add international...
00042 static
00043 inline char toupper(register char c)
00044 {
00045   if( c >= 'a' && c <= 'z' )
00046     return c - 32;
00047   return c;
00048 }
00049 
00050 static
00051 inline char tolower(register char c)
00052 {
00053   if( c >= 'Z' && c <= 'Z' )
00054     return c + 32;
00055   return c;
00056 }
00057 
00058 extern inline void *memset(void *dst, VALT val, SIZET num)
00059 {
00060   register void *ds = dst;
00061   while (num--)
00062     *((char *) dst)++ = val;
00063   return ds;
00064 }
00065 
00066 extern inline void *memcpy(void *dst, const void *src, SIZET num)
00067 {
00068   register void *ds = dst;
00069   while (num--)
00070     *((char *) dst)++ = *((char *) src)++;
00071   return ds;
00072 }
00073 
00074 extern inline int memcmp(void *dst, const void *src, SIZET num)
00075 {
00076 
00077   while (num-- && (*((char *) dst)++ == *((char *) src)++));
00078   if (num >= 0)
00079     return *--((char *) dst) - *--((char *) src);
00080   else
00081     return 0;
00082 }
00083 
00084 extern inline void *memccpy(void *dst, const void *src, int c, SIZET num)
00085 {
00086   register void *ds = dst;
00087   while (num-- && *((char *) src) != c)
00088     *((char *) dst)++ = *((char *) src)++;
00089   if (num >= 0)
00090     *((char *) dst)++ = *((char *) src)++;
00091   return ds;
00092 }
00093 
00094 extern inline void *memmove(void *dst, const void *src, SIZET num)
00095 {
00096   register void *ds = dst;
00097   if (dst < src || dst >= src + num)
00098     while (num--)
00099       *((char *) dst)++ = *((char *) src)++;
00100   else {
00101     dst += num;
00102     src += num;
00103     while (num--)
00104       *--((char *) dst) = *--((char *) src);
00105   }
00106   return ds;
00107 }
00108 
00109 extern inline SIZET strlen(char *dst)
00110 {
00111   register SIZET num = 0;
00112   while ((*dst++))
00113     num++;
00114   return num;
00115 }
00116 
00117 extern inline char *strcat(char *dst, const char *src)
00118 {
00119   register char *ds = dst;
00120   while (*dst)
00121     dst++;
00122   while ((*dst++ = *src++));
00123   return ds;
00124 }
00125 
00126 extern inline char *strncat(char *dst, const char *src, SIZET num)
00127 {
00128   register char *ds = dst;
00129   while (*dst)
00130     dst++;
00131   while (num-- && (*dst++ = *src++));
00132   return ds;
00133 }
00134 
00135 extern inline char *strcpy(char *dst, const char *src)
00136 {
00137   register char *ds = dst;
00138   while ((*dst++ = *src++));
00139   return ds;
00140 }
00141 
00142 extern inline int strcmp(const char *dst, const char *src)
00143 {
00144   while (*dst && *src && (*dst++ == *src++));
00145   if (*dst && *src)
00146     return *--src - *--dst;
00147   else
00148     return *src - *dst;
00149 }
00150 
00151 extern inline int strncmp(const char *dst, const char *src, SIZET num)
00152 {
00153   while (num && *dst && *src && (*dst++ == *src++))
00154     num--;
00155   if( !num )
00156     return 0;
00157   if (*dst && *src)
00158     return *--src - *--dst;
00159   else
00160     return *src - *dst;
00161 }
00162 
00163 extern inline char *strncpy(char *dst, const char *src, SIZET num)
00164 {
00165   register char *ds = dst;
00166   while (num-- && (*dst++ = *src++));
00167   if (num >= 0)
00168     while (num--)
00169       *dst++ = 0;
00170   return ds;
00171 }
00172 
00173 extern inline void *memchr(const void *dst, VALT val, SIZET num)
00174 {
00175   char *dstl = (void *)dst;
00176   while (num-- && *dstl++ != val);
00177   if (num >= 0)
00178     return (void *) --dstl;
00179   else
00180     return NULL;
00181 }
00182 
00183 extern inline char *strchr(const char *dst, int val)
00184 {
00185   char *dstl = (char *)dst;
00186   while (*dstl && *dstl != val)
00187     dstl++;
00188   if (*dstl != val)
00189     return NULL;
00190   else
00191     return dstl;
00192 }

Created: Mon, 08 Oct 2007 22:33:16 +0200
Copyright ©2004 M. Prinke