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