Subversion Repositories filter_foundry

Rev

Rev 193 | Rev 268 | 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-2012 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 <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);
  36.         str1[0] += n;
  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.  
  73. pascal StringPtr  PLstrcpy(StringPtr str1, StringPtr str2)
  74.  {
  75.    BlockMove(str2, str1, str2[0] + 1);
  76.    return(str1);
  77.  }
  78.  
  79. pascal StringPtr PLstrcat(StringPtr str1, StringPtr str2)
  80.  {
  81.   long copyLen;
  82.  
  83.    if (str1[0] + 1 + str2[0]>255)
  84.      copyLen = 255 - str1[0];
  85.    else
  86.     copyLen = str2[0];
  87.  
  88.    BlockMove(&str2[1], str1 + 1 + str1[0], copyLen);
  89.    str1[0] += copyLen;
  90.  
  91.    return(str1);
  92.  }
  93.  */
  94.