Subversion Repositories filter_foundry

Rev

Rev 444 | Rev 495 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.     This file is part of a common library
  3.     Copyright (C) 2002-6 Toby Thain, toby@telegraphics.com.au
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. */
  19.  
  20. #include <string.h>
  21. #include <stdlib.h>
  22.  
  23. #ifdef WIN_ENV
  24. #include <windows.h>
  25. #endif
  26.  
  27. #include "str.h"
  28. #include "sprintf_tiny.h"
  29.  
  30. #ifdef UNICODE
  31. size_t xstrlen(wchar_t* s) {
  32.         return lstrlen(s);
  33. }
  34. wchar_t* xstrcpy(wchar_t* dst, wchar_t* src) {
  35.         return lstrcpy(dst, src);
  36. }
  37. wchar_t* xstrcat(wchar_t* dst, const wchar_t* src) {
  38.         return lstrcat(dst, src);
  39. }
  40. wchar_t* xstrrchr(wchar_t* const _Str, const int _Ch) {
  41.         return wcsrchr(_Str, _Ch);
  42. }
  43. int xstrcasecmp(const wchar_t* a, const wchar_t* b) {
  44.         return _wcsicmp(a, b);
  45. }
  46. int xstrcmp(const wchar_t* a, const wchar_t* b) {
  47.         return lstrcmpW(a, b);
  48. }
  49. #else
  50. size_t xstrlen(char* s) {
  51.         return strlen(s);
  52. }
  53. char* xstrcpy(char* dst, char* src) {
  54.         return strcpy(dst, src);
  55. }
  56. char* xstrcat(char* dst, const char* src) {
  57.         return strcat(dst, src);
  58. }
  59. char* xstrrchr(char* const _Str, const int _Ch) {
  60.         return strrchr(_Str, _Ch);
  61. }
  62. int xstrcasecmp(const char* a, const char* b) {
  63.         //return strcasecmp(a, b);
  64.         return _stricmp(a, b);
  65. }
  66. int xstrcmp(const char* a, const char* b) {
  67.         return strcmp(a, b);
  68. }
  69. #endif
  70.  
  71. // convert C (null-terminated) to Pascal (length byte) string
  72. // no bounds checking
  73. unsigned char *myc2pstr(char *s){
  74.         size_t n = strlen(s);
  75.         memmove(s+1,s,n);
  76.         *s = (unsigned char)n;
  77.         return (unsigned char*)s;
  78. }
  79.  
  80. // convert Pascal string to C string
  81. // no bounds checking
  82. char *myp2cstr(unsigned char *s){
  83.         int n = *s;
  84.         memmove(s,s+1,n);
  85.         s[n] = 0;
  86.         return (char*)s;
  87. }
  88.  
  89. // copy Pascal string to C string
  90. // no bounds checking
  91. char *myp2cstrcpy(char *dst,const unsigned char *src){
  92.         memcpy(dst,src+1,src[0]);
  93.         dst[src[0]] = 0;
  94.         return dst;
  95. }
  96.  
  97. // copy C string to Pascal string
  98. unsigned char *myc2pstrcpy(unsigned char *dst,const char *src){
  99.         size_t n = strlen(src);
  100.         *dst = n <= 255 ? (unsigned char)n : 255;
  101.         memcpy(dst+1,src,*dst);
  102.         return dst;
  103. }
  104.  
  105. // copy null-terminated string;
  106. // returns pointer after last character copied
  107. char *cat(char *d,char *s){
  108.         while( (*d = *s++) )
  109.                 d++;
  110.         return d;
  111. }
  112.  
  113. /*
  114. void *my_memset(void *dst, int val, size_t len){
  115.         char *p;
  116.         for(p=(char*)dst;len--;)
  117.                 *p++ = val;
  118.         return dst;
  119. }
  120. */
  121.  
  122. // my_strdup() is like _strdup(), with the difference that it accepts "char*" instead of "const char*" as argument
  123. char *my_strdup(char *s){
  124.         size_t n = strlen(s);
  125.         char *p = (char*)malloc(n+1);
  126.         if(p)
  127.                 memcpy(p,s,n+1);
  128.         return p;
  129. }
  130.  
  131. // DM 03.12.2021 removed, because it is not used in Filter Foundry
  132. /*
  133. unsigned char *PLcstrcpy(unsigned char *s1,const char *s2){
  134.         size_t n = strlen(s2);
  135.         if(n>255)
  136.                 n = 255;
  137.         memcpy(s1+1,s2,n);
  138.         *s1 = (unsigned char)n;
  139.         return s1;
  140. }
  141. */
  142.  
  143. // DM 03.12.2021 removed, because it is not used in Filter Foundry
  144. /*
  145. unsigned char *PLcstrcat(unsigned char * str1,const char * s2){
  146.         size_t n = strlen(s2);
  147.         if(str1[0]+n > 255)
  148.                 n = 255 - str1[0];
  149.         memcpy(str1+1+str1[0],s2,n);
  150.         str1[0] += (unsigned char)n;
  151.         return str1;
  152. }
  153. */
  154.