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