diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 1995-05-04 10:15:53 +0000 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 1995-05-04 10:15:53 +0000 |
commit | 61bd8ace6bdb2652f4d51d64e3239a7105f56c26 (patch) | |
tree | e8b957df0957c1b483d41d68973824e280445548 /byterun/str.c | |
parent | 8f9ea2a7b886e3e0a5cfd76b11fe79d083a7f20c (diff) | |
download | ocaml-61bd8ace6bdb2652f4d51d64e3239a7105f56c26.tar.gz |
Passage a la version bootstrappee (franchissement du Rubicon)
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'byterun/str.c')
-rw-r--r-- | byterun/str.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/byterun/str.c b/byterun/str.c new file mode 100644 index 0000000000..c5f5eedb2d --- /dev/null +++ b/byterun/str.c @@ -0,0 +1,81 @@ +/* Operations on strings */ + +#include <string.h> +#include "alloc.h" +#include "fail.h" +#include "mlvalues.h" +#include "misc.h" + +mlsize_t string_length(s) + value s; +{ + mlsize_t temp; + temp = Bosize_val(s) - 1; + Assert (Byte (s, temp - Byte (s, temp)) == 0); + return temp - Byte (s, temp); +} + +value ml_string_length(s) /* ML */ + value s; +{ + mlsize_t temp; + temp = Bosize_val(s) - 1; + Assert (Byte (s, temp - Byte (s, temp)) == 0); + return Val_long(temp - Byte (s, temp)); +} + +value create_string(len) /* ML */ + value len; +{ + mlsize_t size = Long_val(len); + if (size > Max_wosize * sizeof(value) - 2) invalid_argument("String.create"); + return alloc_string(size); +} + +value blit_string(argv, argc) /* ML */ + value * argv; + int argc; +{ + bcopy(&Byte(argv[0], Long_val(argv[1])), + &Byte(argv[2], Long_val(argv[3])), + Int_val(argv[4])); + return Atom(0); +} + +value fill_string(s, offset, len, init) /* ML */ + value s, offset, len, init; +{ + register char * p; + register mlsize_t n; + register char c; + + c = Long_val(init); + for(p = &Byte(s, Long_val(offset)), n = Long_val(len); + n > 0; n--, p++) + *p = c; + return Atom(0); +} + +static unsigned char printable_chars_ascii[] = /* 0x20-0x7E */ + "\000\000\000\000\377\377\377\377\377\377\377\377\377\377\377\177\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"; +static unsigned char printable_chars_iso[] = /* 0x20-0x7E 0xA1-0xFF */ + "\000\000\000\000\377\377\377\377\377\377\377\377\377\377\377\177\000\000\000\000\376\377\377\377\377\377\377\377\377\377\377\377"; + +value is_printable(chr) /* ML */ + value chr; +{ + int c; + static int iso_charset = -1; + unsigned char * printable_chars; + + if (iso_charset == -1) { + char * lc_ctype = (char *) getenv("LC_CTYPE"); + if (lc_ctype != 0 && strcmp(lc_ctype, "iso_8859_1") == 0) + iso_charset = 1; + else + iso_charset = 0; + } + printable_chars = iso_charset ? printable_chars_iso : printable_chars_ascii; + c = Int_val(chr); + return Val_bool(printable_chars[c >> 3] & (1 << (c & 7))); +} |