2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 /* a 4 byte aligned and zero padded string allows faster string operations. */
32 #if BYTE_ORDER == LITTLE_ENDIAN
33 const int32 kLASTCHAR
= 0xFF000000;
35 const int32 kLASTCHAR
= 0x000000FF;
40 void str4cpy(int32
*dst
, const char *src
);
41 void mem4cpy(int32
*dst
, const char *src
, int charlen
);
43 // returns the number of pad bytes to add to a string of a given length
44 inline int str4padbytes(int charlen
)
46 return 4 - (charlen
& 3);
49 // converts length in bytes to length in words
50 inline int str4len(int charlen
)
52 return (charlen
+ 4) >> 2;
55 // returns length in words of a char *
56 inline int str4len(const char *src
)
58 const char *src0
= src
;
59 while (*src
) { src
++; }
60 return str4len(src
- src0
);
63 // returns length in words of a int32 *
64 inline int str4len(const int32
*src
)
66 const int32
*src0
= src
;
67 while (*src
++ & kLASTCHAR
) {}
68 int wordlen
= src
- src0
;
72 // returns length in words of a int32 *
73 inline bool str4eq(const int32
*a
, const int32
*b
)
76 if (*a
!= *b
) return false;
77 if ((*a
& kLASTCHAR
) == 0) return true;
83 inline void str4cpy(int32
*dst
, const int32
*src
)
88 } while (c
& kLASTCHAR
);
91 inline int sc_atoi(const char *string
)
94 if (*string
== 0) return -1;
96 while ((c
= *string
++ - '0') <= 9) {
97 value
= value
* 10 + c
;