1 /* $Id: __oo2c.c,v 1.16 2003/06/28 10:39:26 mva Exp $ */
2 /* Run-time system for C back-ends of OOC2
3 Copyright (C) 2001, 2002 Michael van Acken
4
5 This module is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public License
7 as published by the Free Software Foundation; either version 2 of
8 the License, or (at your option) any later version.
9
10 This module is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with OOC. If not, write to the Free Software Foundation,
17 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 /* This file is #included into RT0.c, and therefore compiled into RT0.o */
21
22 #include <__oo2c.h>
23
24 /* --- string compare */
25 #ifndef HAVE_BUILTIN_STRCMP
_cmp8(const OOC_CHAR8 * l,const OOC_CHAR8 * r)26 OOC_INT32 _cmp8(const OOC_CHAR8* l, const OOC_CHAR8* r) {
27 while ((*l == *r) && *l) { l++; r++; }
28 return ((OOC_INT32)*l-(OOC_INT32)*r);
29 }
30 #endif
31
_cmp16(const OOC_CHAR16 * l,const OOC_CHAR16 * r)32 OOC_INT32 _cmp16(const OOC_CHAR16* l, const OOC_CHAR16* r) {
33 while ((*l == *r) && *l) { l++; r++; }
34 return ((OOC_INT32)*l-(OOC_INT32)*r);
35 }
36
_cmp32(const OOC_CHAR32 * l,const OOC_CHAR32 * r)37 OOC_INT32 _cmp32(const OOC_CHAR32* l, const OOC_CHAR32* r) {
38 while ((*l == *r) && *l) { l++; r++; }
39 return ((OOC_INT32)*l-(OOC_INT32)*r);
40 }
41
42 /* --- string copy */
_copy_8(const OOC_CHAR8 * src,OOC_CHAR8 * dest,OOC_LEN max_len)43 void _copy_8(const OOC_CHAR8* src, OOC_CHAR8* dest, OOC_LEN max_len) {
44 OOC_CHAR8* max=dest+max_len-1;
45 while ((dest != max) && (*(dest++) = *(src++)));
46 if (dest == max) *dest = '\000';
47 }
48
_copy_8to16(const OOC_CHAR8 * src,OOC_CHAR16 * dest,OOC_LEN max_len)49 void _copy_8to16(const OOC_CHAR8* src, OOC_CHAR16* dest, OOC_LEN max_len) {
50 OOC_CHAR16* max=dest+max_len-1;
51 while ((dest != max) && (*(dest++) = *(src++)));
52 if (dest == max) *dest = '\000';
53 }
54
_copy_8to32(const OOC_CHAR8 * src,OOC_CHAR32 * dest,OOC_LEN max_len)55 void _copy_8to32(const OOC_CHAR8* src, OOC_CHAR32* dest, OOC_LEN max_len) {
56 OOC_CHAR32* max=dest+max_len-1;
57 while ((dest != max) && (*(dest++) = *(src++)));
58 if (dest == max) *dest = '\000';
59 }
60
_copy_16(const OOC_CHAR16 * src,OOC_CHAR16 * dest,OOC_LEN max_len)61 void _copy_16(const OOC_CHAR16* src, OOC_CHAR16* dest, OOC_LEN max_len) {
62 OOC_CHAR16* max=dest+max_len-1;
63 while ((dest != max) && (*(dest++) = *(src++)));
64 if (dest == max) *dest = '\000';
65 }
66
_copy_16to32(const OOC_CHAR16 * src,OOC_CHAR32 * dest,OOC_LEN max_len)67 void _copy_16to32(const OOC_CHAR16* src, OOC_CHAR32* dest, OOC_LEN max_len) {
68 OOC_CHAR32* max=dest+max_len-1;
69 while ((dest != max) && (*(dest++) = *(src++)));
70 if (dest == max) *dest = '\000';
71 }
72
_copy_32(const OOC_CHAR32 * src,OOC_CHAR32 * dest,OOC_LEN max_len)73 void _copy_32(const OOC_CHAR32* src, OOC_CHAR32* dest, OOC_LEN max_len) {
74 OOC_CHAR32* max=dest+max_len-1;
75 while ((dest != max) && (*(dest++) = *(src++)));
76 if (dest == max) *dest = '\000';
77 }
78
79 #ifndef HAVE_LRINT
ooc_round_real32(OOC_REAL32 x)80 OOC_INT32 ooc_round_real32(OOC_REAL32 x) {
81 if (x >= 0.0f) {
82 return (OOC_INT32)(x+0.5f);
83 } else {
84 return (OOC_INT32)(x-0.5f);
85 }
86 }
ooc_round_real64(OOC_REAL64 x)87 OOC_INT32 ooc_round_real64(OOC_REAL64 x) {
88 if (x >= 0.0) {
89 return (OOC_INT32)(x+0.5);
90 } else {
91 return (OOC_INT32)(x-0.5);
92 }
93 }
94 #endif
95