| 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, David 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_t pfCStringLength( const char *s ) |
| 31 | { |
| 32 | cell_t len = 0; |
| 33 | while( *s++ != NUL ) len++; |
| 34 | return len; |
| 35 | } |
| 36 | |
| 37 | /* void *memset (void *s, cell_t c, size_t n); */ |
| 38 | void *pfSetMemory( void *s, cell_t c, cell_t n ) |
| 39 | { |
| 40 | uint8_t *p = s, byt = (uint8_t) c; |
| 41 | while( (n--) > 0) *p++ = byt; |
| 42 | return s; |
| 43 | } |
| 44 | |
| 45 | /* void *memccpy (void *s1, const void *s2, cell_t c, size_t n); */ |
| 46 | void *pfCopyMemory( void *s1, const void *s2, cell_t n) |
| 47 | { |
| 48 | uint8_t *p1 = s1; |
| 49 | const uint8_t *p2 = s2; |
| 50 | while( (n--) > 0) *p1++ = *p2++; |
| 51 | return s1; |
| 52 | } |
| 53 | |
| 54 | #endif /* PF_NO_CLIB */ |
| 55 | |
| 56 | char pfCharToUpper( char c ) |
| 57 | { |
| 58 | return (char) ( ((c>='a') && (c<='z')) ? (c - ('a' - 'A')) : c ); |
| 59 | } |
| 60 | |
| 61 | char pfCharToLower( char c ) |
| 62 | { |
| 63 | return (char) ( ((c>='A') && (c<='Z')) ? (c + ('a' - 'A')) : c ); |
| 64 | } |