Subversion Repositories filter_foundry

Rev

Rev 456 | Details | Compare with Previous | Last modification | View Log | RSS feed

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