Max 5 API Reference
00001 #include "ext.h" 00002 #include "ext_strings.h" 00003 00004 #ifdef WIN_VERSION 00005 00006 #ifndef _CRT_SECURE_NO_WARNINGS 00007 #define _CRT_SECURE_NO_WARNINGS 00008 #endif 00009 00010 #include <string.h> 00011 00012 #endif // #ifdef WIN_VERSION 00013 00014 #ifndef WIN_VERSION 00015 #ifndef NDEBUG 00016 00017 char *strcpy(char *s1, const char *s2) 00018 { 00019 char *ret = s1; 00020 00021 while ((*s1++ = *s2++) != 0) 00022 ; 00023 00024 return ret; 00025 } 00026 00027 char *strcat(char *s1, const char *s2) 00028 { 00029 char *ret = s1; 00030 00031 while (*s1++) 00032 ; 00033 --s1; 00034 while ((*s1++ = *s2++) != 0) 00035 ; 00036 return ret; 00037 } 00038 00039 int strcmp(const char *s1, const char *s2) 00040 { 00041 char c1, c2, dif; 00042 00043 for (;;) { 00044 if (!(c1 = *s1++)) 00045 return *s2 ? -1 : 0; 00046 if (!(c2 = *s2++)) 00047 return 1; 00048 if (!(dif = (c1 - c2))) 00049 continue; 00050 if (dif < 0) 00051 return -1; 00052 else 00053 return 1; 00054 } 00055 00056 return 0; 00057 } 00058 00059 unsigned long strlen(const char *s) 00060 { 00061 long len = 0; 00062 00063 while (*s++) 00064 ++len; 00065 00066 return len; 00067 } 00068 00069 char *strncpy(char *s1, const char *s2, unsigned long n) 00070 { 00071 char *res = s1; 00072 00073 while (n--) { 00074 if ((*s1++ = *s2)!=0) 00075 ++s2; 00076 } 00077 return res; 00078 } 00079 00080 char *strncat(char *s1, const char *s2, unsigned long n) 00081 { 00082 char *res = s1; 00083 00084 if (n) { 00085 while (*s1++) 00086 ; 00087 --s1; 00088 while (n--) 00089 if (!(*s1++ = *s2++)) 00090 return res; 00091 *s1 = '\0'; 00092 } 00093 return res; 00094 } 00095 00096 int strncmp(const char *s1, const char *s2, unsigned long n) 00097 { 00098 char c1, c2, dif; 00099 00100 while (n--) { 00101 if (!(c1 = *s1++)) 00102 return *s2 ? -1 : 0; 00103 if (!(c2 = *s2++)) 00104 return 1; 00105 if (!(dif = (c1 - c2))) 00106 continue; 00107 if (dif < 0) 00108 return -1; 00109 else 00110 return 1; 00111 } 00112 return 0; 00113 } 00114 00115 #endif // NDEBUG 00116 #endif // #ifndef WIN_VERSION 00117 00118 void ctopcpy(unsigned char *p1, char *p2) 00119 { 00120 long len= (long) strlen(p2); 00121 //changed this to not rely on CtoPstr 00122 strcpy((char *)p1+1, p2); 00123 p1[0]=(len>255)?255:(unsigned char)len; 00124 } 00125 00126 void ptoccpy(char *p1, unsigned char *p2) 00127 { 00128 register int len = (*p2++) & 0xff; 00129 while (len--) *p1++ = *p2++; 00130 *p1 = '\0'; 00131 } 00132 00133 void setmem(void *ss, long n, short b) 00134 { 00135 register int i; 00136 unsigned char *s = (unsigned char *)ss; 00137 00138 for (i=0; i < n; i++,s++) 00139 *s = (unsigned char)b; 00140 } 00141 00142 void pstrcpy(unsigned char *p2, unsigned char *p1) 00143 { 00144 register int len; 00145 00146 len = *p2++ = *p1++; 00147 while (--len>=0) *p2++=*p1++; 00148 }
Copyright © 2008, Cycling '74