File: pf_clib.c

package info (click to toggle)
pforth 21-10
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 820 kB
  • ctags: 873
  • sloc: ansic: 5,050; makefile: 102
file content (64 lines) | stat: -rw-r--r-- 1,949 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* @(#) pf_clib.c 96/12/18 1.12 */
/***************************************************************
** Duplicate functions from stdlib for PForth based on 'C'
**
** This code duplicates some of the code in the 'C' lib
** because it reduces the dependency on foreign libraries
** for monitor mode where no OS is available.
**
** Author: Phil Burk
** Copyright 1994 3DO, Phil Burk, Larry Polansky, Devid Rosenboom
**
** The pForth software code is dedicated to the public domain,
** and any third party may reproduce, distribute and modify
** the pForth software code or any derivative works thereof
** without any compensation or license.  The pForth software
** code is provided on an "as is" basis without any warranty
** of any kind, including, without limitation, the implied
** warranties of merchantability and fitness for a particular
** purpose and their equivalents under the laws of any jurisdiction.
**
****************************************************************
** 961124 PLB Advance pointers in pfCopyMemory() and pfSetMemory()
***************************************************************/

#include "pf_all.h"

#ifdef PF_NO_CLIB
/* Count chars until NUL.  Replace strlen() */
#define  NUL  ((char) 0)
cell pfCStringLength( const char *s )
{
	cell len = 0;
	while( *s++ != NUL ) len++;
	return len;
}
 
/*    void *memset (void *s, int32 c, size_t n); */
void *pfSetMemory( void *s, cell c, cell n )
{
	uint8 *p = s, byt = (uint8) c;
	while( (n--) > 0) *p++ = byt;
	return s;
}

/*  void *memccpy (void *s1, const void *s2, int32 c, size_t n); */
void *pfCopyMemory( void *s1, const void *s2, cell n)
{
	uint8 *p1 = s1;
	const uint8 *p2 = s2;
	while( (n--) > 0) *p1++ = *p2++;
	return s1;
}

#endif  /* PF_NO_CLIB */

char pfCharToUpper( char c )
{
	return (char) ( ((c>='a') && (c<='z')) ? (c - ('a' - 'A')) : c );
}

char pfCharToLower( char c )
{
	return (char) ( ((c>='A') && (c<='Z')) ? (c + ('a' - 'A')) : c );
}