Rev 193 | Rev 268 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 193 | Rev 259 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* |
1 | /* |
2 | This file is part of a common library |
2 | This file is part of a common library |
3 | Copyright (C) 2002-2012 Toby Thain, toby@telegraphics.com.au |
3 | Copyright (C) 2002-2012 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 <stdio.h> |
20 | #include <stdio.h> |
21 | #include <string.h> |
21 | #include <string.h> |
22 | #include <stdlib.h> |
22 | #include <stdlib.h> |
23 | 23 | ||
24 | #include "compat_string.h" |
24 | #include "compat_string.h" |
25 | #include "str.h" |
25 | #include "str.h" |
26 | 26 | ||
27 | unsigned char *PLstrcpy(unsigned char *s1,const unsigned char *s2){ |
27 | unsigned char *PLstrcpy(unsigned char *s1,const unsigned char *s2){ |
28 | memcpy(s1,s2,*s2+1); |
28 | memcpy(s1,s2,*s2+1); |
29 | return s1; |
29 | return s1; |
30 | } |
30 | } |
31 | unsigned char *PLstrcat(unsigned char * str1,const unsigned char * str2){ |
31 | unsigned char *PLstrcat(unsigned char * str1,const unsigned char * str2){ |
32 | int n = str2[0]; |
32 | int n = str2[0]; |
33 | if(str1[0]+n > 255) |
33 | if(str1[0]+n > 255) |
34 | n = 255 - str1[0]; |
34 | n = 255 - str1[0]; |
35 | memcpy(str1+1+str1[0],str2+1,n); |
35 | memcpy(str1+1+str1[0],str2+1,n); |
36 | str1[0] += n; |
36 | str1[0] += n; |
37 | return str1; |
37 | return str1; |
38 | } |
38 | } |
39 | const unsigned char *PLstrrchr(const unsigned char *str1, int ch1){ |
39 | const unsigned char *PLstrrchr(const unsigned char *str1, int ch1){ |
40 | const unsigned char *p; |
40 | const unsigned char *p; |
41 | for(p = str1+str1[0] ; p != str1 ; --p) |
41 | for(p = str1+str1[0] ; p != str1 ; --p) |
42 | if(*p == ch1) |
42 | if(*p == ch1) |
43 | return p; |
43 | return p; |
44 | return 0; |
44 | return 0; |
45 | } |
45 | } |
46 | 46 | ||
47 | int PLstrcmp(const unsigned char *str1,const unsigned char *str2){ |
47 | int PLstrcmp(const unsigned char *str1,const unsigned char *str2){ |
48 | int len = str1[0] < str2[0] ? str1[0] : str2[0], |
48 | int len = str1[0] < str2[0] ? str1[0] : str2[0], |
49 | ord = memcmp(str1+1,str2+1,len); |
49 | ord = memcmp(str1+1,str2+1,len); |
50 | return ord ? ord : str1[0]-str2[0]; |
50 | return ord ? ord : str1[0]-str2[0]; |
51 | } |
51 | } |
52 | 52 | ||
53 | void NumToString(long n, unsigned char *dst){ |
53 | void NumToString(long n, unsigned char *dst){ |
54 | *dst = sprintf((char*)dst+1, "%ld", n); |
54 | *dst = sprintf((char*)dst+1, "%ld", n); |
55 | } |
55 | } |
56 | 56 | ||
57 | /// 'reference' implementation: |
57 | /// 'reference' implementation: |
58 | /* |
58 | /* |
59 | PLStrs.c |
59 | PLStrs.c |
60 | 60 | ||
61 | Version 3.1 |
61 | Version 3.1 |
62 | 62 | ||
63 | Copyright 1995 Apple Computer, Inc., all rights reserved. |
63 | Copyright 1995 Apple Computer, Inc., all rights reserved. |
64 | 64 | ||
65 | MenuScripter by Nigel Humphreys and Jon Lansdell |
65 | MenuScripter by Nigel Humphreys and Jon Lansdell |
66 | AppleEvent to script extensions by Greg Sutton |
66 | AppleEvent to script extensions by Greg Sutton |
67 | 67 | ||
68 | 68 | ||
69 | #include "PLStrs.h" |
69 | #include "PLStrs.h" |
70 | 70 | ||
71 | #include <memory.h> |
71 | #include <memory.h> |
72 | 72 | ||
73 | pascal StringPtr PLstrcpy(StringPtr str1, StringPtr str2) |
73 | pascal StringPtr PLstrcpy(StringPtr str1, StringPtr str2) |
74 | { |
74 | { |
75 | BlockMove(str2, str1, str2[0] + 1); |
75 | BlockMove(str2, str1, str2[0] + 1); |
76 | return(str1); |
76 | return(str1); |
77 | } |
77 | } |
78 | 78 | ||
79 | pascal StringPtr PLstrcat(StringPtr str1, StringPtr str2) |
79 | pascal StringPtr PLstrcat(StringPtr str1, StringPtr str2) |
80 | { |
80 | { |
81 | long copyLen; |
81 | long copyLen; |
82 | 82 | ||
83 | if (str1[0] + 1 + str2[0]>255) |
83 | if (str1[0] + 1 + str2[0]>255) |
84 | copyLen = 255 - str1[0]; |
84 | copyLen = 255 - str1[0]; |
85 | else |
85 | else |
86 | copyLen = str2[0]; |
86 | copyLen = str2[0]; |
87 | 87 | ||
88 | BlockMove(&str2[1], str1 + 1 + str1[0], copyLen); |
88 | BlockMove(&str2[1], str1 + 1 + str1[0], copyLen); |
89 | str1[0] += copyLen; |
89 | str1[0] += copyLen; |
90 | 90 | ||
91 | return(str1); |
91 | return(str1); |
92 | } |
92 | } |
93 | */ |
93 | */ |