Imported Upstream version 21
[debian/pforth] / csrc / pf_clib.c
1 /* @(#) pf_clib.c 96/12/18 1.12 */
2 /***************************************************************
3 ** Duplicate functions from stdlib for PForth based on 'C'
4 **
5 ** This code duplicates some of the code in the 'C' lib
6 ** because it reduces the dependency on foreign libraries
7 ** for monitor mode where no OS is available.
8 **
9 ** Author: Phil Burk
10 ** Copyright 1994 3DO, Phil Burk, Larry Polansky, Devid Rosenboom
11 **
12 ** The pForth software code is dedicated to the public domain,
13 ** and any third party may reproduce, distribute and modify
14 ** the pForth software code or any derivative works thereof
15 ** without any compensation or license.  The pForth software
16 ** code is provided on an "as is" basis without any warranty
17 ** of any kind, including, without limitation, the implied
18 ** warranties of merchantability and fitness for a particular
19 ** purpose and their equivalents under the laws of any jurisdiction.
20 **
21 ****************************************************************
22 ** 961124 PLB Advance pointers in pfCopyMemory() and pfSetMemory()
23 ***************************************************************/
24
25 #include "pf_all.h"
26
27 #ifdef PF_NO_CLIB
28 /* Count chars until NUL.  Replace strlen() */
29 #define  NUL  ((char) 0)
30 cell pfCStringLength( const char *s )
31 {
32         cell len = 0;
33         while( *s++ != NUL ) len++;
34         return len;
35 }
36  
37 /*    void *memset (void *s, int32 c, size_t n); */
38 void *pfSetMemory( void *s, cell c, cell n )
39 {
40         uint8 *p = s, byt = (uint8) c;
41         while( (n--) > 0) *p++ = byt;
42         return s;
43 }
44
45 /*  void *memccpy (void *s1, const void *s2, int32 c, size_t n); */
46 void *pfCopyMemory( void *s1, const void *s2, cell n)
47 {
48         uint8 *p1 = s1;
49         const uint8 *p2 = s2;
50         while( (n--) > 0) *p1++ = *p2++;
51         return s1;
52 }
53
54 #endif  /* PF_NO_CLIB */
55 \r
56 char pfCharToUpper( char c )\r
57 {\r
58         return (char) ( ((c>='a') && (c<='z')) ? (c - ('a' - 'A')) : c );\r
59 }\r
60 \r
61 char pfCharToLower( char c )\r
62 {\r
63         return (char) ( ((c>='A') && (c<='Z')) ? (c + ('a' - 'A')) : c );\r
64 }\r