ocaml-bitstring-2.0.4/0000775000175000017500000000000012144457302014201 5ustar rjonesrjonesocaml-bitstring-2.0.4/MANIFEST0000664000175000017500000000675012144455551015346 0ustar rjonesrjonesaclocal.m4 benchmarks/parse_ext3_superblock.ml bitmatch.ml bitstring.ml bitstring.mli bitstring_c.c bitstring_config.ml.in bitstring_objinfo.ml bitstring_persistent.ml bitstring_persistent.mli bitstring_types.ml bootstrap byteswap.in.h .depend cil-tools/bitstring_import_c.ml cil-tools/bitstring-import-prefix.h cil-tools/.depend cil-tools/ext3.c cil-tools/ext3.ml cil-tools/Makefile.in cil-tools/task_struct.c cil-tools/task_struct.ml configure.ac COPYING COPYING.LIB coverage-report/file0000.html coverage-report/file0001.html coverage-report/file0002.html coverage-report/file0003.html coverage-report/style.css coverage-report/index.html create_test_pattern.ml examples/elf.ml examples/ext3_sb examples/ext3_superblock.ml examples/gif.ml examples/ipv4_header.ml examples/libpcap.ml examples/make_ipv4_header.ml examples/ping.ipv4 examples/ping.ipv6 examples/ping.ml install-sh Makefile.in MANIFEST META.in README pa_bitstring.ml tests/test_01_load.ml tests/test_02_run.ml tests/test_10_match_bits.ml tests/test_11_match_ints.ml tests/test_15_extract_int.ml tests/test_18_extract_32_64_int.ml tests/test_20_varsize.ml tests/test_30_bitbuffer.ml tests/test_31_bitstring_concat.ml tests/test_32_bitstring_compare.ml tests/test_33_substring.ml tests/test_34_takebits.ml tests/test_35_load_from_file.ml tests/test_40_endianexpr.ml tests/test_50_named_pattern.ml tests/test_51_open_pattern.ml tests/test_60_simple_offset.ml tests/test_61_offset_string.ml tests/test_62_offset_padding.ml tests/test_65_save_offset_to.ml tests/test_70_check_and_bind.ml tests/test_80_hexdump.ml tests/80_testdata/hex1000.expected tests/80_testdata/hex10.expected tests/80_testdata/hex11.expected tests/80_testdata/hex127.expected tests/80_testdata/hex128.expected tests/80_testdata/hex12.expected tests/80_testdata/hex13.expected tests/80_testdata/hex14.expected tests/80_testdata/hex15.expected tests/80_testdata/hex16.expected tests/80_testdata/hex1.expected tests/80_testdata/hex200.expected tests/80_testdata/hex2.expected tests/80_testdata/hex31.expected tests/80_testdata/hex32.expected tests/80_testdata/hex33.expected tests/80_testdata/hex34.expected tests/80_testdata/hex3.expected tests/80_testdata/hex47.expected tests/80_testdata/hex48.expected tests/80_testdata/hex49.expected tests/80_testdata/hex4.expected tests/80_testdata/hex500.expected tests/80_testdata/hex50.expected tests/80_testdata/hex5.expected tests/80_testdata/hex63.expected tests/80_testdata/hex64.expected tests/80_testdata/hex65.expected tests/80_testdata/hex66.expected tests/80_testdata/hex67.expected tests/80_testdata/hex6.expected tests/80_testdata/hex7.expected tests/80_testdata/hex8.expected tests/80_testdata/hex9.expected tests/80_testdata/rnd1 tests/80_testdata/rnd10 tests/80_testdata/rnd1000 tests/80_testdata/rnd11 tests/80_testdata/rnd12 tests/80_testdata/rnd127 tests/80_testdata/rnd128 tests/80_testdata/rnd13 tests/80_testdata/rnd14 tests/80_testdata/rnd15 tests/80_testdata/rnd16 tests/80_testdata/rnd2 tests/80_testdata/rnd200 tests/80_testdata/rnd3 tests/80_testdata/rnd31 tests/80_testdata/rnd32 tests/80_testdata/rnd33 tests/80_testdata/rnd34 tests/80_testdata/rnd4 tests/80_testdata/rnd47 tests/80_testdata/rnd48 tests/80_testdata/rnd49 tests/80_testdata/rnd5 tests/80_testdata/rnd50 tests/80_testdata/rnd500 tests/80_testdata/rnd6 tests/80_testdata/rnd63 tests/80_testdata/rnd64 tests/80_testdata/rnd65 tests/80_testdata/rnd66 tests/80_testdata/rnd67 tests/80_testdata/rnd7 tests/80_testdata/rnd8 tests/80_testdata/rnd9 tests/test_90_bind_as.ml tests/test_91_concat.ml TODO ocaml-bitstring-2.0.4/config.h.in0000644000175000017500000000410512144457302016222 0ustar rjonesrjones/* config.h.in. Generated from configure.ac by autoheader. */ /* Define if building universal (internal helper macro) */ #undef AC_APPLE_UNIVERSAL_BUILD /* Define to 1 if you have the header file. */ #undef HAVE_BYTESWAP_H /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H /* Define to 1 if you have the header file. */ #undef HAVE_STRINGS_H /* Define to 1 if you have the header file. */ #undef HAVE_STRING_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STAT_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H /* Define to 1 if your C compiler doesn't accept -c and -o together. */ #undef NO_MINUS_C_MINUS_O /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT /* Define to the full name of this package. */ #undef PACKAGE_NAME /* Define to the full name and version of this package. */ #undef PACKAGE_STRING /* Define to the one symbol short name of this package. */ #undef PACKAGE_TARNAME /* Define to the home page for this package. */ #undef PACKAGE_URL /* Define to the version of this package. */ #undef PACKAGE_VERSION /* Define to 1 if the C compiler supports function prototypes. */ #undef PROTOTYPES /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ #if defined AC_APPLE_UNIVERSAL_BUILD # if defined __BIG_ENDIAN__ # define WORDS_BIGENDIAN 1 # endif #else # ifndef WORDS_BIGENDIAN # undef WORDS_BIGENDIAN # endif #endif /* Define like PROTOTYPES; this can be used by system headers. */ #undef __PROTOTYPES ocaml-bitstring-2.0.4/bitmatch.ml0000664000175000017500000000225412144455550016334 0ustar rjonesrjones(** Bitmatch backwards compatibility library. *) (* Bitstring library. * Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version, * with the OCaml linking exception described in COPYING.LIB. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: bitmatch.ml 142 2008-07-17 15:45:56Z richard.wm.jones $ *) (** This is just for backwards compatibility with code from when the library was called bitmatch. You should replace all references to this module with {!Bitstring}. *) include Bitstring ocaml-bitstring-2.0.4/byteswap.in.h0000664000175000017500000000376712144455550016635 0ustar rjonesrjones/* byteswap.h - Byte swapping Copyright (C) 2005, 2007 Free Software Foundation, Inc. Written by Oskar Liljeblad , 2005. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* NB: This file is from Gnulib, and in accordance with the convention there, the real license of this file comes from the module definition. It is really LGPLv2+. - RWMJ. 2008/08/23 */ #ifndef _GL_BYTESWAP_H #define _GL_BYTESWAP_H /* Given an unsigned 16-bit argument X, return the value corresponding to X with reversed byte order. */ #define bswap_16(x) ((((x) & 0x00FF) << 8) | \ (((x) & 0xFF00) >> 8)) /* Given an unsigned 32-bit argument X, return the value corresponding to X with reversed byte order. */ #define bswap_32(x) ((((x) & 0x000000FF) << 24) | \ (((x) & 0x0000FF00) << 8) | \ (((x) & 0x00FF0000) >> 8) | \ (((x) & 0xFF000000) >> 24)) /* Given an unsigned 64-bit argument X, return the value corresponding to X with reversed byte order. */ #define bswap_64(x) ((((x) & 0x00000000000000FFULL) << 56) | \ (((x) & 0x000000000000FF00ULL) << 40) | \ (((x) & 0x0000000000FF0000ULL) << 24) | \ (((x) & 0x00000000FF000000ULL) << 8) | \ (((x) & 0x000000FF00000000ULL) >> 8) | \ (((x) & 0x0000FF0000000000ULL) >> 24) | \ (((x) & 0x00FF000000000000ULL) >> 40) | \ (((x) & 0xFF00000000000000ULL) >> 56)) #endif /* _GL_BYTESWAP_H */ ocaml-bitstring-2.0.4/bitstring.mli0000664000175000017500000011675412144457237016736 0ustar rjonesrjones(** Bitstring library. *) (* Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version, * with the OCaml linking exception described in COPYING.LIB. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: bitstring.mli 198 2013-05-14 15:56:07Z richard.wm.jones@gmail.com $ *) (** {{:#reference}Jump straight to the reference section for documentation on types and functions}. {2 Introduction} Bitstring adds Erlang-style bitstrings and matching over bitstrings as a syntax extension and library for OCaml. You can use this module to both parse and generate binary formats, for example, communications protocols, disk formats and binary files. {{:http://code.google.com/p/bitstring/}OCaml bitstring website} This library used to be called "bitmatch". {2 Examples} A function which can parse IPv4 packets: {[ let display pkt = bitmatch pkt with (* IPv4 packet header 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 4 | IHL |Type of Service| Total Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Identification |Flags| Fragment Offset | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Time to Live | Protocol | Header Checksum | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Source Address | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Destination Address | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options | Padding | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ *) | { 4 : 4; hdrlen : 4; tos : 8; length : 16; identification : 16; flags : 3; fragoffset : 13; ttl : 8; protocol : 8; checksum : 16; source : 32; dest : 32; options : (hdrlen-5)*32 : bitstring; payload : -1 : bitstring } -> printf "IPv4:\n"; printf " header length: %d * 32 bit words\n" hdrlen; printf " type of service: %d\n" tos; printf " packet length: %d bytes\n" length; printf " identification: %d\n" identification; printf " flags: %d\n" flags; printf " fragment offset: %d\n" fragoffset; printf " ttl: %d\n" ttl; printf " protocol: %d\n" protocol; printf " checksum: %d\n" checksum; printf " source: %lx dest: %lx\n" source dest; printf " header options + padding:\n"; Bitstring.hexdump_bitstring stdout options; printf " packet payload:\n"; Bitstring.hexdump_bitstring stdout payload | { version : 4 } -> eprintf "unknown IP version %d\n" version; exit 1 | { _ } as pkt -> eprintf "data is smaller than one nibble:\n"; Bitstring.hexdump_bitstring stderr pkt; exit 1 ]} A program which can parse {{:http://lxr.linux.no/linux/include/linux/ext3_fs.h}Linux EXT3 filesystem superblocks}: {[ let bits = Bitstring.bitstring_of_file "tests/ext3_sb" let () = bitmatch bits with | { s_inodes_count : 32 : littleendian; (* Inodes count *) s_blocks_count : 32 : littleendian; (* Blocks count *) s_r_blocks_count : 32 : littleendian; (* Reserved blocks count *) s_free_blocks_count : 32 : littleendian; (* Free blocks count *) s_free_inodes_count : 32 : littleendian; (* Free inodes count *) s_first_data_block : 32 : littleendian; (* First Data Block *) s_log_block_size : 32 : littleendian; (* Block size *) s_log_frag_size : 32 : littleendian; (* Fragment size *) s_blocks_per_group : 32 : littleendian; (* # Blocks per group *) s_frags_per_group : 32 : littleendian; (* # Fragments per group *) s_inodes_per_group : 32 : littleendian; (* # Inodes per group *) s_mtime : 32 : littleendian; (* Mount time *) s_wtime : 32 : littleendian; (* Write time *) s_mnt_count : 16 : littleendian; (* Mount count *) s_max_mnt_count : 16 : littleendian; (* Maximal mount count *) 0xef53 : 16 : littleendian } -> (* Magic signature *) printf "ext3 superblock:\n"; printf " s_inodes_count = %ld\n" s_inodes_count; printf " s_blocks_count = %ld\n" s_blocks_count; printf " s_free_inodes_count = %ld\n" s_free_inodes_count; printf " s_free_blocks_count = %ld\n" s_free_blocks_count | { _ } -> eprintf "not an ext3 superblock!\n%!"; exit 2 ]} Constructing packets for a simple binary message protocol: {[ (* +---------------+---------------+--------------------------+ | type | subtype | parameter | +---------------+---------------+--------------------------+ <-- 16 bits --> <-- 16 bits --> <------- 32 bits --------> All fields are in network byte order. *) let make_message typ subtype param = (BITSTRING { typ : 16; subtype : 16; param : 32 }) ;; ]} {2 Loading, creating bitstrings} The basic data type is the {!bitstring}, a string of bits of arbitrary length. Bitstrings can be any length in bits and operations do not need to be byte-aligned (although they will generally be more efficient if they are byte-aligned). Internally a bitstring is stored as a normal OCaml [string] together with an offset and length, where the offset and length are measured in bits. Thus one can efficiently form substrings of bitstrings, overlay a bitstring on existing data, and load and save bitstrings from files or other external sources. To load a bitstring from a file use {!bitstring_of_file} or {!bitstring_of_chan}. There are also functions to create bitstrings from arbitrary data. See the {{:#reference}reference} below. {2 Matching bitstrings with patterns} Use the [bitmatch] operator (part of the syntax extension) to break apart a bitstring into its fields. [bitmatch] works a lot like the OCaml [match] operator. The general form of [bitmatch] is: [bitmatch] {i bitstring-expression} [with] [| {] {i pattern} [} ->] {i code} [| {] {i pattern} [} ->] {i code} [|] ... As with normal match, the statement attempts to match the bitstring against each pattern in turn. If none of the patterns match then the standard library [Match_failure] exception is thrown. Patterns look a bit different from normal match patterns. They consist of a list of bitfields separated by [;] where each bitfield contains a bind variable, the width (in bits) of the field, and other information. Some example patterns: {[ bitmatch bits with | { version : 8; name : 8; param : 8 } -> ... (* Bitstring of at least 3 bytes. First byte is the version number, second byte is a field called name, third byte is a field called parameter. *) | { flag : 1 } -> printf "flag is %b\n" flag (* A single flag bit (mapped into an OCaml boolean). *) | { len : 4; data : 1+len } -> printf "len = %d, data = 0x%Lx\n" len data (* A 4-bit length, followed by 1-16 bits of data, where the length of the data is computed from len. *) | { ipv6_source : 128 : bitstring; ipv6_dest : 128 : bitstring } -> ... (* IPv6 source and destination addresses. Each is 128 bits and is mapped into a bitstring type which will be a substring of the main bitstring expression. *) ]} You can also add conditional when-clauses: {[ | { version : 4 } when version = 4 || version = 6 -> ... (* Only match and run the code when version is 4 or 6. If it isn't we will drop through to the next case. *) ]} Note that the pattern is only compared against the first part of the bitstring (there may be more data in the bitstring following the pattern, which is not matched). In terms of regular expressions you might say that the pattern matches [^pattern], not [^pattern$]. To ensure that the bitstring contains only the pattern, add a length -1 bitstring to the end and test that its length is zero in the when-clause: {[ | { n : 4; rest : -1 : bitstring } when Bitstring.bitstring_length rest = 0 -> ... (* Only matches exactly 4 bits. *) ]} Normally the first part of each field is a binding variable, but you can also match a constant, as in: {[ | { (4|6) : 4 } -> ... (* Only matches if the first 4 bits contain either the integer 4 or the integer 6. *) ]} One may also match on strings: {[ | { "MAGIC" : 5*8 : string } -> ... (* Only matches if the string "MAGIC" appears at the start of the input. *) ]} {3:patternfieldreference Pattern field reference} The exact format of each pattern field is: [pattern : length [: qualifier [,qualifier ...]]] [pattern] is the pattern, binding variable name, or constant to match. [length] is the length in bits which may be either a constant or an expression. The length expression is just an OCaml expression and can use any values defined in the program, and refer back to earlier fields (but not to later fields). Integers can only have lengths in the range \[1..64\] bits. See the {{:#integertypes}integer types} section below for how these are mapped to the OCaml int/int32/int64 types. This is checked at compile time if the length expression is constant, otherwise it is checked at runtime and you will get a runtime exception eg. in the case of a computed length expression. A bitstring field of length -1 matches all the rest of the bitstring (thus this is only useful as the last field in a pattern). A bitstring field of length 0 matches an empty bitstring (occasionally useful when matching optional subfields). Qualifiers are a list of identifiers/expressions which control the type, signedness and endianness of the field. Permissible qualifiers are: - [int]: field has an integer type - [string]: field is a string type - [bitstring]: field is a bitstring type - [signed]: field is signed - [unsigned]: field is unsigned - [bigendian]: field is big endian - a.k.a network byte order - [littleendian]: field is little endian - a.k.a Intel byte order - [nativeendian]: field is same endianness as the machine - [endian (expr)]: [expr] should be an expression which evaluates to a {!endian} type, ie. [LittleEndian], [BigEndian] or [NativeEndian]. The expression is an arbitrary OCaml expression and can use the value of earlier fields in the bitmatch. - [offset (expr)]: see {{:#computedoffsets}computed offsets} below. The default settings are [int], [unsigned], [bigendian], no offset. Note that many of these qualifiers cannot be used together, eg. bitstrings do not have endianness. The syntax extension should give you a compile-time error if you use incompatible qualifiers. {3 Other cases in bitmatch} As well as a list of fields, it is possible to name the bitstring and/or have a default match case: {[ | { _ } -> ... (* Default match case. *) | { _ } as pkt -> ... (* Default match case, with 'pkt' bound to the whole bitstring. *) ]} {2 Constructing bitstrings} Bitstrings may be constructed using the [BITSTRING] operator (as an expression). The [BITSTRING] operator takes a list of fields, similar to the list of fields for matching: {[ let version = 1 ;; let data = 10 ;; let bits = BITSTRING { version : 4; data : 12 } ;; (* Constructs a 16-bit bitstring with the first four bits containing the integer 1, and the following 12 bits containing the integer 10, arranged in network byte order. *) Bitstring.hexdump_bitstring stdout bits ;; (* Prints: 00000000 10 0a |.. | *) ]} The format of each field is the same as for pattern fields (see {{:#patternfieldreference}Pattern field reference section}), and things like computed length fields, fixed value fields, insertion of bitstrings within bitstrings, etc. are all supported. {3 Construction exception} The [BITSTRING] operator may throw a {!Construct_failure} exception at runtime. Runtime errors include: - int field length not in the range \[1..64\] - a bitstring with a length declared which doesn't have the same length at runtime - trying to insert an out of range value into an int field (eg. an unsigned int field which is 2 bits wide can only take values in the range \[0..3\]). {2:integertypes Integer types} Integer types are mapped to OCaml types [bool], [int], [int32] or [int64] using a system which tries to ensure that (a) the types are reasonably predictable and (b) the most efficient type is preferred. The rules are slightly different depending on whether the bit length expression in the field is a compile-time constant or a computed expression. Detection of compile-time constants is quite simplistic so only simple integer literals and simple expressions (eg. [5*8]) are recognized as constants. In any case the bit size of an integer is limited to the range \[1..64\]. This is detected as a compile-time error if that is possible, otherwise a runtime check is added which can throw an [Invalid_argument] exception. The mapping is thus: {v Bit size ---- OCaml type ---- Constant Computed expression 1 bool int64 2..31 int int64 32 int32 int64 33..64 int64 int64 v} A possible future extension may allow people with 64 bit computers to specify a more optimal [int] type for bit sizes in the range [32..63]. If this was implemented then such code {i could not even be compiled} on 32 bit platforms, so it would limit portability. Another future extension may be to allow computed expressions to assert min/max range for the bit size, allowing a more efficient data type than int64 to be used. (Of course under such circumstances there would still need to be a runtime check to enforce the size). {2 Advanced pattern-matching features} {3:computedoffsets Computed offsets} You can add an [offset(..)] qualifier to bitmatch patterns in order to move the current offset within the bitstring forwards. For example: {[ bitmatch bits with | { field1 : 8; field2 : 8 : offset(160) } -> ... ]} matches [field1] at the start of the bitstring and [field2] at 160 bits into the bitstring. The middle 152 bits go unmatched (ie. can be anything). The generated code is efficient. If field lengths and offsets are known to be constant at compile time, then almost all runtime checks are avoided. Non-constant field lengths and/or non-constant offsets can result in more runtime checks being added. Note that moving the offset backwards, and moving the offset in [BITSTRING] constructors, are both not supported at present. {3 Check expressions} You can add a [check(expr)] qualifier to bitmatch patterns. If the expression evaluates to false then the current match case fails to match (in other words, we fall through to the next match case - there is no error). For example: {[ bitmatch bits with | { field : 16 : check (field > 100) } -> ... ]} Note the difference between a check expression and a when-clause is that the when-clause is evaluated after all the fields have been matched. On the other hand a check expression is evaluated after the individual field has been matched, which means it is potentially more efficient (if the check expression fails then we don't waste any time matching later fields). We wanted to use the notation [when(expr)] here, but because [when] is a reserved word we could not do this. {3 Bind expressions} A bind expression is used to change the value of a matched field. For example: {[ bitmatch bits with | { len : 16 : bind (len * 8); field : len : bitstring } -> ... ]} In the example, after 'len' has been matched, its value would be multiplied by 8, so the width of 'field' is the matched value multiplied by 8. In the general case: {[ | { field : ... : bind (expr) } -> ... ]} evaluates the following after the field has been matched: {[ let field = expr in (* remaining fields *) ]} {3 Order of evaluation of check() and bind()} The choice is arbitrary, but we have chosen that check expressions are evaluated first, and bind expressions are evaluated after. This means that the result of bind() is {i not} available in the check expression. Note that this rule applies regardless of the order of check() and bind() in the source code. {3 save_offset_to} Use [save_offset_to(variable)] to save the current bit offset within the match to a variable (strictly speaking, to a pattern). This variable is then made available in any [check()] and [bind()] clauses in the current field, {i and} to any later fields, and to the code after the [->]. For example: {[ bitmatch bits with | { len : 16; _ : len : bitstring; field : 16 : save_offset_to (field_offset) } -> printf "field is at bit offset %d in the match\n" field_offset ]} (In that example, [field_offset] should always have the value [len+16]). {2 Named patterns and persistent patterns} Please see {!Bitstring_persistent} for documentation on this subject. {2 Compiling} Using the compiler directly you can do: {v ocamlc -I +bitstring \ -pp "camlp4of bitstring.cma bitstring_persistent.cma \ `ocamlc -where`/bitstring/pa_bitstring.cmo" \ unix.cma bitstring.cma test.ml -o test v} Simpler method using findlib: {v ocamlfind ocamlc \ -package bitstring,bitstring.syntax -syntax bitstring.syntax \ -linkpkg test.ml -o test v} {2 Security and type safety} {3 Security on input} The main concerns for input are buffer overflows and denial of service. It is believed that this library is robust against attempted buffer overflows. In addition to OCaml's normal bounds checks, we check that field lengths are >= 0, and many additional checks. Denial of service attacks are more problematic. We only work forwards through the bitstring, thus computation will eventually terminate. As for computed lengths, code such as this is thought to be secure: {[ bitmatch bits with | { len : 64; buffer : Int64.to_int len : bitstring } -> ]} The [len] field can be set arbitrarily large by an attacker, but when pattern-matching against the [buffer] field this merely causes a test such as [if len <= remaining_size] to fail. Even if the length is chosen so that [buffer] bitstring is allocated, the allocation of sub-bitstrings is efficient and doesn't involve an arbitary-sized allocation or any copying. However the above does not necessarily apply to strings used in matching, since they may cause the library to use the {!Bitstring.string_of_bitstring} function, which allocates a string. So you should take care if you use the [string] type particularly with a computed length that is derived from external input. The main protection against attackers should be to ensure that the main program will only read input bitstrings up to a certain length, which is outside the scope of this library. {3 Security on output} As with the input side, computed lengths are believed to be safe. For example: {[ let len = read_untrusted_source () in let buffer = allocate_bitstring () in BITSTRING { buffer : len : bitstring } ]} This code merely causes a check that buffer's length is the same as [len]. However the program function [allocate_bitstring] must refuse to allocate an oversized buffer (but that is outside the scope of this library). {3 Order of evaluation} In [bitmatch] statements, fields are evaluated left to right. Note that the when-clause is evaluated {i last}, so if you are relying on the when-clause to filter cases then your code may do a lot of extra and unncessary pattern-matching work on fields which may never be needed just to evaluate the when-clause. Either rearrange the code to do only the first part of the match, followed by the when-clause, followed by a second inner bitmatch, or use a [check()] qualifier within fields. {3 Safety} The current implementation is believed to be fully type-safe, and makes compile and run-time checks where appropriate. If you find a case where a check is missing please submit a bug report or a patch. {2 Limits} These are thought to be the current limits: Integers: \[1..64\] bits. Bitstrings (32 bit platforms): maximum length is limited by the string size, ie. 16 MBytes. Bitstrings (64 bit platforms): maximum length is thought to be limited by the string size, ie. effectively unlimited. Bitstrings must be loaded into memory before we can match against them. Thus available memory may be considered a limit for some applications. {2:reference Reference} {3 Types} *) type endian = BigEndian | LittleEndian | NativeEndian val string_of_endian : endian -> string (** Endianness. *) type bitstring = string * int * int (** [bitstring] is the basic type used to store bitstrings. The type contains the underlying data (a string), the current bit offset within the string and the current bit length of the string (counting from the bit offset). Note that the offset and length are in {b bits}, not bytes. Normally you don't need to use the bitstring type directly, since there are functions and syntax extensions which hide the details. See also {!bitstring_of_string}, {!bitstring_of_file}, {!hexdump_bitstring}, {!bitstring_length}. *) type t = bitstring (** [t] is a synonym for the {!bitstring} type. This allows you to use this module with functors like [Set] and [Map] from the stdlib. *) (** {3 Exceptions} *) exception Construct_failure of string * string * int * int (** [Construct_failure (message, file, line, char)] may be raised by the [BITSTRING] constructor. Common reasons are that values are out of range of the fields that contain them, or that computed lengths are impossible (eg. negative length bitfields). [message] is the error message. [file], [line] and [char] point to the original source location of the [BITSTRING] constructor that failed. *) (** {3 Bitstring comparison} *) val compare : bitstring -> bitstring -> int (** [compare bs1 bs2] compares two bitstrings and returns zero if they are equal, a negative number if [bs1 < bs2], or a positive number if [bs1 > bs2]. This tests "semantic equality" which is not affected by the offset or alignment of the underlying representation (see {!bitstring}). The ordering is total and lexicographic. *) val equals : bitstring -> bitstring -> bool (** [equals] returns true if and only if the two bitstrings are semantically equal. It is the same as calling [compare] and testing if the result is [0], but usually more efficient. *) val is_zeroes_bitstring : bitstring -> bool (** Tests if the bitstring is all zero bits (cf. {!zeroes_bitstring}) *) val is_ones_bitstring : bitstring -> bool (** Tests if the bitstring is all one bits (cf. {!ones_bitstring}). *) (** {3 Bitstring manipulation} *) val bitstring_length : bitstring -> int (** [bitstring_length bitstring] returns the length of the bitstring in bits. Note this just returns the third field in the {!bitstring} tuple. *) val subbitstring : bitstring -> int -> int -> bitstring (** [subbitstring bits off len] returns a sub-bitstring of the bitstring, starting at offset [off] bits and with length [len] bits. If the original bitstring is not long enough to do this then the function raises [Invalid_argument "subbitstring"]. Note that this function just changes the offset and length fields of the {!bitstring} tuple, so is very efficient. *) val dropbits : int -> bitstring -> bitstring (** Drop the first n bits of the bitstring and return a new bitstring which is shorter by n bits. If the length of the original bitstring is less than n bits, this raises [Invalid_argument "dropbits"]. Note that this function just changes the offset and length fields of the {!bitstring} tuple, so is very efficient. *) val takebits : int -> bitstring -> bitstring (** Take the first n bits of the bitstring and return a new bitstring which is exactly n bits long. If the length of the original bitstring is less than n bits, this raises [Invalid_argument "takebits"]. Note that this function just changes the offset and length fields of the {!bitstring} tuple, so is very efficient. *) val concat : bitstring list -> bitstring (** Concatenate a list of bitstrings together into a single bitstring. *) (** {3 Constructing bitstrings} *) val empty_bitstring : bitstring (** [empty_bitstring] is the empty, zero-length bitstring. *) val create_bitstring : int -> bitstring (** [create_bitstring n] creates an [n] bit bitstring containing all zeroes. *) val make_bitstring : int -> char -> bitstring (** [make_bitstring n c] creates an [n] bit bitstring containing the repeated 8 bit pattern in [c]. For example, [make_bitstring 16 '\x5a'] will create the bitstring [0x5a5a] or in binary [0101 1010 0101 1010]. Note that the length is in bits, not bytes. The length does NOT need to be a multiple of 8. *) val zeroes_bitstring : int -> bitstring (** [zeroes_bitstring] creates an [n] bit bitstring of all 0's. Actually this is the same as {!create_bitstring}. *) val ones_bitstring : int -> bitstring (** [ones_bitstring] creates an [n] bit bitstring of all 1's. *) val bitstring_of_string : string -> bitstring (** [bitstring_of_string str] creates a bitstring of length [String.length str * 8] (bits) containing the bits in [str]. Note that the bitstring uses [str] as the underlying string (see the representation of {!bitstring}) so you should not change [str] after calling this. *) val bitstring_of_file : string -> bitstring (** [bitstring_of_file filename] loads the named file into a bitstring. *) val bitstring_of_chan : in_channel -> bitstring (** [bitstring_of_chan chan] loads the contents of the input channel [chan] as a bitstring. The length of the final bitstring is determined by the remaining input in [chan], but will always be a multiple of 8 bits. See also {!bitstring_of_chan_max}. *) val bitstring_of_chan_max : in_channel -> int -> bitstring (** [bitstring_of_chan_max chan max] works like {!bitstring_of_chan} but will only read up to [max] bytes from the channel (or fewer if the end of input occurs before that). *) val bitstring_of_file_descr : Unix.file_descr -> bitstring (** [bitstring_of_file_descr fd] loads the contents of the file descriptor [fd] as a bitstring. See also {!bitstring_of_chan}, {!bitstring_of_file_descr_max}. *) val bitstring_of_file_descr_max : Unix.file_descr -> int -> bitstring (** [bitstring_of_file_descr_max fd max] works like {!bitstring_of_file_descr} but will only read up to [max] bytes from the channel (or fewer if the end of input occurs before that). *) (** {3 Converting bitstrings} *) val string_of_bitstring : bitstring -> string (** [string_of_bitstring bitstring] converts a bitstring to a string (eg. to allow comparison). This function is inefficient. In the best case when the bitstring is nicely byte-aligned we do a [String.sub] operation. If the bitstring isn't aligned then this involves a lot of bit twiddling and is particularly inefficient. If the bitstring is not a multiple of 8 bits wide then the final byte of the string contains the high bits set to the remaining bits and the low bits set to 0. *) val bitstring_to_file : bitstring -> string -> unit (** [bitstring_to_file bits filename] writes the bitstring [bits] to the file [filename]. It overwrites the output file. Some restrictions apply, see {!bitstring_to_chan}. *) val bitstring_to_chan : bitstring -> out_channel -> unit (** [bitstring_to_file bits filename] writes the bitstring [bits] to the channel [chan]. Channels are made up of bytes, bitstrings can be any bit length including fractions of bytes. So this function only works if the length of the bitstring is an exact multiple of 8 bits (otherwise it raises [Invalid_argument "bitstring_to_chan"]). Furthermore the function is efficient only in the case where the bitstring is stored fully aligned, otherwise it has to do inefficient bit twiddling like {!string_of_bitstring}. In the common case where the bitstring was generated by the [BITSTRING] operator and is an exact multiple of 8 bits wide, then this function will always work efficiently. *) (** {3 Printing bitstrings} *) val hexdump_bitstring : out_channel -> bitstring -> unit (** [hexdump_bitstring chan bitstring] prints the bitstring to the output channel in a format similar to the Unix command [hexdump -C]. *) (** {3 Bitstring buffer} *) module Buffer : sig type t val create : unit -> t val contents : t -> bitstring val add_bits : t -> string -> int -> unit val add_bit : t -> bool -> unit val add_byte : t -> int -> unit end (** Buffers are mainly used by the [BITSTRING] constructor, but may also be useful for end users. They work much like the standard library [Buffer] module. *) (** {3 Get/set bits} These functions let you manipulate individual bits in the bitstring. However they are not particularly efficient and you should generally use the [bitmatch] and [BITSTRING] operators when building and parsing bitstrings. These functions all raise [Invalid_argument "index out of bounds"] if the index is out of range of the bitstring. *) val set : bitstring -> int -> unit (** [set bits n] sets the [n]th bit in the bitstring to 1. *) val clear : bitstring -> int -> unit (** [clear bits n] sets the [n]th bit in the bitstring to 0. *) val is_set : bitstring -> int -> bool (** [is_set bits n] is true if the [n]th bit is set to 1. *) val is_clear : bitstring -> int -> bool (** [is_clear bits n] is true if the [n]th bit is set to 0. *) val put : bitstring -> int -> int -> unit (** [put bits n v] sets the [n]th bit in the bitstring to 1 if [v] is not zero, or to 0 if [v] is zero. *) val get : bitstring -> int -> int (** [get bits n] returns the [n]th bit (returns non-zero or 0). *) (** {3 Miscellaneous} *) val package : string (** The package name, always ["ocaml-bitstring"] *) val version : string (** The package version as a string. *) val debug : bool ref (** Set this variable to true to enable extended debugging. This only works if debugging was also enabled in the [pa_bitstring.ml] file at compile time, otherwise it does nothing. *) (**/**) (* Private functions, called from generated code. Do not use * these directly - they are not safe. *) (* 'extract' functions are used in bitmatch statements. *) val extract_bit : string -> int -> int -> int -> bool val extract_char_unsigned : string -> int -> int -> int -> int val extract_int_be_unsigned : string -> int -> int -> int -> int val extract_int_le_unsigned : string -> int -> int -> int -> int val extract_int_ne_unsigned : string -> int -> int -> int -> int val extract_int_ee_unsigned : endian -> string -> int -> int -> int -> int val extract_int32_be_unsigned : string -> int -> int -> int -> int32 val extract_int32_le_unsigned : string -> int -> int -> int -> int32 val extract_int32_ne_unsigned : string -> int -> int -> int -> int32 val extract_int32_ee_unsigned : endian -> string -> int -> int -> int -> int32 val extract_int64_be_unsigned : string -> int -> int -> int -> int64 val extract_int64_le_unsigned : string -> int -> int -> int -> int64 val extract_int64_ne_unsigned : string -> int -> int -> int -> int64 val extract_int64_ee_unsigned : endian -> string -> int -> int -> int -> int64 external extract_fastpath_int16_be_unsigned : string -> int -> int = "ocaml_bitstring_extract_fastpath_int16_be_unsigned" "noalloc" external extract_fastpath_int16_le_unsigned : string -> int -> int = "ocaml_bitstring_extract_fastpath_int16_le_unsigned" "noalloc" external extract_fastpath_int16_ne_unsigned : string -> int -> int = "ocaml_bitstring_extract_fastpath_int16_ne_unsigned" "noalloc" external extract_fastpath_int16_be_signed : string -> int -> int = "ocaml_bitstring_extract_fastpath_int16_be_signed" "noalloc" external extract_fastpath_int16_le_signed : string -> int -> int = "ocaml_bitstring_extract_fastpath_int16_le_signed" "noalloc" external extract_fastpath_int16_ne_signed : string -> int -> int = "ocaml_bitstring_extract_fastpath_int16_ne_signed" "noalloc" (* external extract_fastpath_int24_be_unsigned : string -> int -> int = "ocaml_bitstring_extract_fastpath_int24_be_unsigned" "noalloc" external extract_fastpath_int24_le_unsigned : string -> int -> int = "ocaml_bitstring_extract_fastpath_int24_le_unsigned" "noalloc" external extract_fastpath_int24_ne_unsigned : string -> int -> int = "ocaml_bitstring_extract_fastpath_int24_ne_unsigned" "noalloc" external extract_fastpath_int24_be_signed : string -> int -> int = "ocaml_bitstring_extract_fastpath_int24_be_signed" "noalloc" external extract_fastpath_int24_le_signed : string -> int -> int = "ocaml_bitstring_extract_fastpath_int24_le_signed" "noalloc" external extract_fastpath_int24_ne_signed : string -> int -> int = "ocaml_bitstring_extract_fastpath_int24_ne_signed" "noalloc" *) external extract_fastpath_int32_be_unsigned : string -> int -> int32 -> int32 = "ocaml_bitstring_extract_fastpath_int32_be_unsigned" "noalloc" external extract_fastpath_int32_le_unsigned : string -> int -> int32 -> int32 = "ocaml_bitstring_extract_fastpath_int32_le_unsigned" "noalloc" external extract_fastpath_int32_ne_unsigned : string -> int -> int32 -> int32 = "ocaml_bitstring_extract_fastpath_int32_ne_unsigned" "noalloc" external extract_fastpath_int32_be_signed : string -> int -> int32 -> int32 = "ocaml_bitstring_extract_fastpath_int32_be_signed" "noalloc" external extract_fastpath_int32_le_signed : string -> int -> int32 -> int32 = "ocaml_bitstring_extract_fastpath_int32_le_signed" "noalloc" external extract_fastpath_int32_ne_signed : string -> int -> int32 -> int32 = "ocaml_bitstring_extract_fastpath_int32_ne_signed" "noalloc" (* external extract_fastpath_int40_be_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int40_be_unsigned" "noalloc" external extract_fastpath_int40_le_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int40_le_unsigned" "noalloc" external extract_fastpath_int40_ne_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int40_ne_unsigned" "noalloc" external extract_fastpath_int40_be_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int40_be_signed" "noalloc" external extract_fastpath_int40_le_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int40_le_signed" "noalloc" external extract_fastpath_int40_ne_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int40_ne_signed" "noalloc" external extract_fastpath_int48_be_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int48_be_unsigned" "noalloc" external extract_fastpath_int48_le_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int48_le_unsigned" "noalloc" external extract_fastpath_int48_ne_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int48_ne_unsigned" "noalloc" external extract_fastpath_int48_be_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int48_be_signed" "noalloc" external extract_fastpath_int48_le_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int48_le_signed" "noalloc" external extract_fastpath_int48_ne_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int48_ne_signed" "noalloc" external extract_fastpath_int56_be_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int56_be_unsigned" "noalloc" external extract_fastpath_int56_le_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int56_le_unsigned" "noalloc" external extract_fastpath_int56_ne_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int56_ne_unsigned" "noalloc" external extract_fastpath_int56_be_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int56_be_signed" "noalloc" external extract_fastpath_int56_le_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int56_le_signed" "noalloc" external extract_fastpath_int56_ne_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int56_ne_signed" "noalloc" *) external extract_fastpath_int64_be_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int64_be_unsigned" "noalloc" external extract_fastpath_int64_le_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int64_le_unsigned" "noalloc" external extract_fastpath_int64_ne_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int64_ne_unsigned" "noalloc" external extract_fastpath_int64_be_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int64_be_signed" "noalloc" external extract_fastpath_int64_le_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int64_le_signed" "noalloc" external extract_fastpath_int64_ne_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int64_ne_signed" "noalloc" (* 'construct' functions are used in BITSTRING constructors. *) val construct_bit : Buffer.t -> bool -> int -> exn -> unit val construct_char_unsigned : Buffer.t -> int -> int -> exn -> unit val construct_int_be_unsigned : Buffer.t -> int -> int -> exn -> unit val construct_int_le_unsigned : Buffer.t -> int -> int -> exn -> unit val construct_int_ne_unsigned : Buffer.t -> int -> int -> exn -> unit val construct_int_ee_unsigned : endian -> Buffer.t -> int -> int -> exn -> unit val construct_int32_be_unsigned : Buffer.t -> int32 -> int -> exn -> unit val construct_int32_le_unsigned : Buffer.t -> int32 -> int -> exn -> unit val construct_int32_ne_unsigned : Buffer.t -> int32 -> int -> exn -> unit val construct_int32_ee_unsigned : endian -> Buffer.t -> int32 -> int -> exn -> unit val construct_int64_be_unsigned : Buffer.t -> int64 -> int -> exn -> unit val construct_int64_le_unsigned : Buffer.t -> int64 -> int -> exn -> unit val construct_int64_ne_unsigned : Buffer.t -> int64 -> int -> exn -> unit val construct_int64_ee_unsigned : endian -> Buffer.t -> int64 -> int -> exn -> unit val construct_string : Buffer.t -> string -> unit val construct_bitstring : Buffer.t -> bitstring -> unit ocaml-bitstring-2.0.4/create_test_pattern.ml0000664000175000017500000000134312144455551020577 0ustar rjonesrjones(* Create persistent pattern. * $Id: create_test_pattern.ml 142 2008-07-17 15:45:56Z richard.wm.jones $ *) open Bitstring_persistent open Camlp4.PreCast open Syntax open Ast let () = let _loc = Loc.ghost in let len_field = create_pattern_field _loc in let len_field = set_length_int len_field 8 in let len_field = set_lident_patt len_field "len" in let str_field = create_pattern_field _loc in let str_field = set_length str_field <:expr< len*8 >> in let str_field = set_lident_patt str_field "str" in let str_field = set_type_string str_field in let named_pattern = "pascal_string", Pattern [len_field; str_field] in let chan = open_out Sys.argv.(1) in named_to_channel chan named_pattern; close_out chan ocaml-bitstring-2.0.4/examples/0000775000175000017500000000000012144457302016017 5ustar rjonesrjonesocaml-bitstring-2.0.4/examples/gif.ml0000664000175000017500000000207712144455551017130 0ustar rjonesrjones(* GIF header parser. * $Id: gif.ml 142 2008-07-17 15:45:56Z richard.wm.jones $ *) open Printf let () = if Array.length Sys.argv <= 1 then failwith "usage: gif input.gif"; let filename = Sys.argv.(1) in let bits = Bitstring.bitstring_of_file filename in bitmatch bits with | { ("GIF87a"|"GIF89a") : 6*8 : string; (* GIF magic. *) width : 16 : littleendian; height : 16 : littleendian; colormap : 1; (* Has colormap? *) colorbits : 3; (* Color res = colorbits+1 *) sortflag : 1; bps : 3; (* Bits/pixel = bps+1 *) bg : 8; (* Background colour. *) aspectratio : 8 } -> printf "%s: GIF image:\n" filename; printf " size %d %d\n" width height; printf " has global colormap? %b\n" colormap; printf " colorbits %d\n" (colorbits+1); printf " global colormap is sorted? %b\n" sortflag; printf " bits/pixel %d\n" (bps+1); printf " background color index %d\n" bg; printf " aspect ratio %d\n" aspectratio | { _ } -> eprintf "%s: Not a GIF image\n" filename ocaml-bitstring-2.0.4/examples/ping.ml0000664000175000017500000000413612144455551017316 0ustar rjonesrjones(* Read in IPv4 and IPv6 ping packets and display them. * $Id: ping.ml 142 2008-07-17 15:45:56Z richard.wm.jones $ *) open Printf let display pkt = bitmatch pkt with (* IPv4 packet header *) | { 4 : 4; hdrlen : 4; tos : 8; length : 16; identification : 16; flags : 3; fragoffset : 13; ttl : 8; protocol : 8; checksum : 16; source : 32; dest : 32; options : (hdrlen-5)*32 : bitstring; payload : -1 : bitstring } -> printf "IPv4:\n"; printf " header length: %d * 32 bit words\n" hdrlen; printf " type of service: %d\n" tos; printf " packet length: %d bytes\n" length; printf " identification: %d\n" identification; printf " flags: %d\n" flags; printf " fragment offset: %d\n" fragoffset; printf " ttl: %d\n" ttl; printf " protocol: %d\n" protocol; printf " checksum: %d\n" checksum; printf " source: %lx dest: %lx\n" source dest; printf " header options + padding:\n"; Bitstring.hexdump_bitstring stdout options; printf " packet payload:\n"; Bitstring.hexdump_bitstring stdout payload (* IPv6 packet header *) | { 6 : 4; tclass : 8; flow : 20; length : 16; nexthdr : 8; ttl : 8; source : 128 : bitstring; dest : 128 : bitstring; payload : -1 : bitstring } -> printf "IPv6:\n"; printf " traffic class: %d\n" tclass; printf " flow label: %d\n" flow; printf " packet (payload) length: %d bytes\n" length; printf " next header: %d\n" nexthdr; printf " ttl: %d\n" ttl; printf " source address:\n"; Bitstring.hexdump_bitstring stdout source; printf " destination address:\n"; Bitstring.hexdump_bitstring stdout dest; printf "packet payload:\n"; Bitstring.hexdump_bitstring stdout payload | { version : 4 } -> eprintf "unknown IP version %d\n" version; exit 1 | { _ } as pkt -> eprintf "data is smaller than one nibble:\n"; Bitstring.hexdump_bitstring stderr pkt; exit 1 let () = let pkt = Bitstring.bitstring_of_file "ping.ipv4" in display pkt; let pkt = Bitstring.bitstring_of_file "ping.ipv6" in display pkt ocaml-bitstring-2.0.4/examples/ext3_superblock.ml0000664000175000017500000001027512144455551021476 0ustar rjonesrjones(* Parse an ext3 superblock. * $Id: ext3_superblock.ml 142 2008-07-17 15:45:56Z richard.wm.jones $ *) open Printf (*let () = Bitstring.debug := true*) let bits = Bitstring.bitstring_of_file "ext3_sb" (* The structure is straight from /usr/include/linux/ext3_fs.h *) let () = bitmatch bits with | { s_inodes_count : 32 : littleendian; (* Inodes count *) s_blocks_count : 32 : littleendian; (* Blocks count *) s_r_blocks_count : 32 : littleendian; (* Reserved blocks count *) s_free_blocks_count : 32 : littleendian; (* Free blocks count *) s_free_inodes_count : 32 : littleendian; (* Free inodes count *) s_first_data_block : 32 : littleendian; (* First Data Block *) s_log_block_size : 32 : littleendian; (* Block size *) s_log_frag_size : 32 : littleendian; (* Fragment size *) s_blocks_per_group : 32 : littleendian; (* # Blocks per group *) s_frags_per_group : 32 : littleendian; (* # Fragments per group *) s_inodes_per_group : 32 : littleendian; (* # Inodes per group *) s_mtime : 32 : littleendian; (* Mount time *) s_wtime : 32 : littleendian; (* Write time *) s_mnt_count : 16 : littleendian; (* Mount count *) s_max_mnt_count : 16 : littleendian; (* Maximal mount count *) 0xef53 : 16 : littleendian; (* Magic signature *) s_state : 16 : littleendian; (* File system state *) s_errors : 16 : littleendian; (* Behaviour when detecting errors *) s_minor_rev_level : 16 : littleendian; (* minor revision level *) s_lastcheck : 32 : littleendian; (* time of last check *) s_checkinterval : 32 : littleendian; (* max. time between checks *) s_creator_os : 32 : littleendian; (* OS *) s_rev_level : 32 : littleendian; (* Revision level *) s_def_resuid : 16 : littleendian; (* Default uid for reserved blocks *) s_def_resgid : 16 : littleendian; (* Default gid for reserved blocks *) s_first_ino : 32 : littleendian; (* First non-reserved inode *) s_inode_size : 16 : littleendian; (* size of inode structure *) s_block_group_nr : 16 : littleendian; (* block group # of this superblock *) s_feature_compat : 32 : littleendian; (* compatible feature set *) s_feature_incompat : 32 : littleendian; (* incompatible feature set *) s_feature_ro_compat : 32 : littleendian; (* readonly-compatible feature set *) s_uuid : 128 : string; (* 128-bit uuid for volume *) s_volume_name : 128 : string; (* volume name *) s_last_mounted : 512 : string; (* directory where last mounted *) s_algorithm_usage_bitmap : 32 : littleendian; (* For compression *) s_prealloc_blocks : 8; (* Nr of blocks to try to preallocate*) s_prealloc_dir_blocks : 8; (* Nr to preallocate for dirs *) s_reserved_gdt_blocks : 16 : littleendian;(* Per group desc for online growth *) s_journal_uuid : 128 : string; (* uuid of journal superblock *) s_journal_inum : 32 : littleendian; (* inode number of journal file *) s_journal_dev : 32 : littleendian; (* device number of journal file *) s_last_orphan : 32 : littleendian; (* start of list of inodes to delete *) s_hash_seed0 : 32 : littleendian; (* HTREE hash seed *) s_hash_seed1 : 32 : littleendian; s_hash_seed2 : 32 : littleendian; s_hash_seed3 : 32 : littleendian; s_def_hash_version : 8; (* Default hash version to use *) s_reserved_char_pad : 8; s_reserved_word_pad : 16 : littleendian; s_default_mount_opts : 32 : littleendian; s_first_meta_bg : 32 : littleendian; (* First metablock block group *) _ : 6080 : bitstring } -> (* Padding to the end of the block *) printf "ext3 superblock:\n"; printf " s_inodes_count = %ld\n" s_inodes_count; printf " s_blocks_count = %ld\n" s_blocks_count; printf " s_free_inodes_count = %ld\n" s_free_inodes_count; printf " s_free_blocks_count = %ld\n" s_free_blocks_count; printf " s_uuid = %S\n" s_uuid; printf " s_volume_name = %S\n" s_volume_name; printf " s_last_mounted = %S\n" s_last_mounted | { _ } -> eprintf "not an ext3 superblock!\n%!"; exit 2 ocaml-bitstring-2.0.4/examples/ext3_sb0000664000175000017500000000200012144455551017305 0ustar rjonesrjonesÄL7'Å^æÃ ØéÐìGéÐìGÿÿSïÁ¬]G €<HxTÚÀŒDK•”ƒ°ë/boot¨Qb¨ÚJ$šÊMY`{u‡ Á¬]G@ocaml-bitstring-2.0.4/examples/make_ipv4_header.ml0000664000175000017500000000170112144455551021543 0ustar rjonesrjones(* Create an IPv4 header. * $Id: make_ipv4_header.ml 142 2008-07-17 15:45:56Z richard.wm.jones $ *) open Printf let version = 4 let hdrlen = 5 (* no options *) let tos = 16 let length = 64 (* total packet length *) let identification = 0 let flags = 0 let fragoffset = 0 let ttl = 255 let protocol = 17 (* UDP *) let checksum = 0 let source = 0xc0a80202_l (* 192.168.2.2 *) let dest = 0xc0a80201_l (* 192.168.2.1 *) let options = Bitstring.empty_bitstring let payload_length = (length - hdrlen*4) * 8 let payload = Bitstring.create_bitstring payload_length let header = BITSTRING { version : 4; hdrlen : 4; tos : 8; length : 16; identification : 16; flags : 3; fragoffset : 13; ttl : 8; protocol : 8; checksum : 16; source : 32; dest : 32 (* Not implemented at the moment XXX options : -1 : bitstring; payload : payload_length : bitstring *) } let () = Bitstring.bitstring_to_file header "ipv4_header_out.dat" ocaml-bitstring-2.0.4/examples/ping.ipv40000664000175000017500000000012412144455551017561 0ustar rjonesrjonesET@@<§‡B<ùñG  !"#$%&'()*+,-./01234567ocaml-bitstring-2.0.4/examples/libpcap.ml0000664000175000017500000000754512144455551020002 0ustar rjonesrjones(* Print out packets from a tcpdump / libpcap / wireshark capture file. * $Id: libpcap.ml 142 2008-07-17 15:45:56Z richard.wm.jones $ * * To test this, capture some data using: * /usr/sbin/tcpdump -s 1500 -w /tmp/dump * then analyze it using: * ./libpcap /tmp/dump * * The file format is documented here: * http://wiki.wireshark.org/Development/LibpcapFileFormat * * libpcap endianness is determined at runtime. *) open Printf let rec main () = if Array.length Sys.argv <= 1 then failwith "libpcap dumpfile"; let bits = Bitstring.bitstring_of_file Sys.argv.(1) in let endian, file_header, bits = libpcap_header bits in (* Read the packets and print them out. *) let rec loop bits = let pkt_header, pkt_data, bits = libpcap_packet endian file_header bits in decode_and_print_packet file_header pkt_header pkt_data; loop bits in try loop bits with End_of_file -> () (* Determine the endianness (at runtime) from the magic number. *) and endian_of = function | 0xa1b2c3d4_l -> Bitstring.BigEndian | 0xd4c3b2a1_l -> Bitstring.LittleEndian | _ -> assert false and libpcap_header bits = bitmatch bits with | { ((0xa1b2c3d4_l|0xd4c3b2a1_l) as magic) : 32; (* magic number *) major : 16 : endian (endian_of magic); (* version *) minor : 16 : endian (endian_of magic); timezone : 32 : endian (endian_of magic); (* timezone correction (secs)*) _ : 32 : endian (endian_of magic); (* always 0 apparently *) snaplen : 32 : endian (endian_of magic); (* max length of capt pckts *) network : 32 : endian (endian_of magic); (* data link layer type *) rest : -1 : bitstring } -> endian_of magic, (major, minor, timezone, snaplen, network), rest | { _ } -> failwith "not a libpcap/tcpdump packet capture file" and libpcap_packet e file_header bits = bitmatch bits with | { ts_sec : 32 : endian (e); (* packet timestamp seconds *) ts_usec : 32 : endian (e); (* packet timestamp microseconds *) incl_len : 32 : endian (e); (* packet length saved in this file *) orig_len : 32 : endian (e); (* packet length originally on wire *) pkt_data : Int32.to_int incl_len*8 : bitstring; rest : -1 : bitstring } -> (ts_sec, ts_usec, incl_len, orig_len), pkt_data, rest | { _ } -> raise End_of_file and decode_and_print_packet file_header pkt_header pkt_data = let (ts_sec, ts_usec, _, orig_len) = pkt_header in printf "%ld.%ld %ldB " ts_sec ts_usec orig_len; (* Assume an ethernet frame containing an IPv4/6 packet. We ignore * the ethertype field and determine the IP version from the packet * itself. If it doesn't match our assumptions, hexdump it. *) (bitmatch pkt_data with | { d0 : 8; d1 : 8; d2 : 8; d3 : 8; d4 : 8; d5 : 8; (* ether dest *) s0 : 8; s1 : 8; s2 : 8; s3 : 8; s4 : 8; s5 : 8; (* ether src *) _ : 16; (* ethertype *) packet : -1 : bitstring (* payload *) } -> printf "%x:%x:%x:%x:%x:%x < %x:%x:%x:%x:%x:%x " d0 d1 d2 d3 d4 d5 s0 s1 s2 s3 s4 s5; (bitmatch packet with | { 4 : 4; (* IPv4 *) hdrlen : 4; tos : 8; length : 16; identification : 16; flags : 3; fragoffset : 13; ttl : 8; protocol : 8; checksum : 16; s0 : 8; s1 : 8; s2 : 8; s3 : 8; d0 : 8; d1 : 8; d2 : 8; d3 : 8; _(*options*) : (hdrlen-5)*32 : bitstring; _(*payload*) : -1 : bitstring } -> printf "IPv4 %d.%d.%d.%d < %d.%d.%d.%d " s0 s1 s2 s3 d0 d1 d2 d3 | { 6 : 4; (* IPv6 *) tclass : 8; flow : 20; length : 16; nexthdr : 8; ttl : 8; _(*source*) : 128 : bitstring; _(*dest*) : 128 : bitstring; _(*payload*) : -1 : bitstring } -> printf "IPv6 "; | { _ } -> printf "\n"; Bitstring.hexdump_bitstring stdout packet ) | { _ } -> printf "\n"; Bitstring.hexdump_bitstring stdout pkt_data ); printf "\n" let () = main () ocaml-bitstring-2.0.4/examples/ipv4_header.ml0000664000175000017500000000252312144455551020551 0ustar rjonesrjones(* Parse and display an IPv4 header from a file. * $Id: ipv4_header.ml 142 2008-07-17 15:45:56Z richard.wm.jones $ *) open Printf let header = Bitstring.bitstring_of_file "ipv4_header.dat" let () = bitmatch header with | { version : 4; hdrlen : 4; tos : 8; length : 16; identification : 16; flags : 3; fragoffset : 13; ttl : 8; protocol : 8; checksum : 16; source : 32; dest : 32; options : (hdrlen-5)*32 : bitstring; payload : -1 : bitstring } when version = 4 -> printf "IPv%d:\n" version; printf " header length: %d * 32 bit words\n" hdrlen; printf " type of service: %d\n" tos; printf " packet length: %d bytes\n" length; printf " identification: %d\n" identification; printf " flags: %d\n" flags; printf " fragment offset: %d\n" fragoffset; printf " ttl: %d\n" ttl; printf " protocol: %d\n" protocol; printf " checksum: %d\n" checksum; printf " source: %lx dest: %lx\n" source dest; printf " header options + padding:\n"; Bitstring.hexdump_bitstring stdout options; printf " packet payload:\n"; Bitstring.hexdump_bitstring stdout payload | { version : 4 } -> eprintf "cannot parse IP version %d\n" version | { _ } as header -> eprintf "data is smaller than one nibble:\n"; Bitstring.hexdump_bitstring stderr header ocaml-bitstring-2.0.4/examples/ping.ipv60000664000175000017500000000015012144455551017562 0ustar rjonesrjones`@:@€+ýBdùñGŸ. !"#$%&'()*+,-./01234567ocaml-bitstring-2.0.4/examples/elf.ml0000664000175000017500000000112712144455551017124 0ustar rjonesrjones(* Read an ELF (Linux binary) header. * $Id: elf.ml 142 2008-07-17 15:45:56Z richard.wm.jones $ *) open Printf let () = let filename = "/bin/ls" in let bits = Bitstring.bitstring_of_file filename in bitmatch bits with | { 0x7f : 8; "ELF" : 24 : string; (* ELF magic number *) _ : 12*8 : bitstring; (* ELF identifier *) e_type : 16 : littleendian; (* object file type *) e_machine : 16 : littleendian (* architecture *) } -> printf "%s: ELF binary, type %d, arch %d\n" filename e_type e_machine | { _ } -> eprintf "%s: Not an ELF binary\n" filename ocaml-bitstring-2.0.4/bitstring_persistent.mli0000664000175000017500000004506612144455551021210 0ustar rjonesrjones(** Bitstring persistent patterns. *) (* Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version, * with the OCaml linking exception described in COPYING.LIB. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: bitstring_persistent.mli 142 2008-07-17 15:45:56Z richard.wm.jones $ *) (** {b Warning:} This documentation is for ADVANCED USERS ONLY. If you are not an advanced user, you are probably looking for {{:Bitstring.html}the Bitstring documentation}. {{:#reference}Jump straight to the reference section for documentation on types and functions}. {2 Introduction} Bitstring allows you to name sets of fields and reuse them elsewhere. For example if you frequently need to parse Pascal-style strings in the form length byte + string, then you could name the [{ strlen : 8 : int; str : strlen*8 : string }] pattern and reuse it everywhere by name. These are called {b persistent patterns}. The basic usage is: {v (* Create a persistent pattern called 'pascal_string' which * matches Pascal-style strings (length byte + string). *) let bitmatch pascal_string = \{ strlen : 8 : int; str : strlen*8 : string } let is_pascal_string bits = bitmatch bits with | \{ :pascal_string } -> printf "matches a Pascal string %s, len %d bytes\n" str strlen v} or: {v (* Load a persistent pattern from a file. *) open bitmatch "pascal.bmpp" let is_pascal_string bits = bitmatch bits with | \{ :pascal_string } -> printf "matches a Pascal string %s, len %d bytes\n" str strlen v} {3 Important notes} There are some important things you should know about persistent patterns before you decide to use them: 'Persistent' refers to the fact that they can be saved into binary files. However these binary files use OCaml [Marshal] module and depend (sometimes) on the version of OCaml used to generate them and (sometimes) the version of bitstring used. So your build system should rebuild these files from source when your code is rebuilt. Persistent patterns are syntactic. They work in the same way as cutting and pasting (or [#include]-ing) code. For example if a persistent pattern binds a field named [len], then any uses of [len] following in the surrounding pattern could be affected. Programs which generate and manipulate persistent patterns have to link to camlp4. Since camlp4 in OCaml >= 3.10 is rather large, we have placed this code into this separate submodule, so that programs which just use bitstring don't need to pull in the whole of camlp4. This restriction does not apply to code which only uses persistent patterns but does not generate them. If the distinction isn't clear, use [ocamlobjinfo] to look at the dependencies of your [*.cmo] files. Persistent patterns can be generated in several ways, but they can only be {i used} by the [pa_bitstring] syntax extension. This means they are purely compile-time constructs. You cannot use them to make arbitrary patterns and run those patterns (not unless your program runs [ocamlc] to make a [*.cmo] file then dynamically links to the [*.cmo] file). {2 Named patterns} A named pattern is a way to name a pattern and use it later in the same source file. To name a pattern, use: [let bitmatch name = { fields ... } ;;] and you can then use the name later on inside another pattern, by prefixing the name with a colon. For example: [bitmatch bits with { :name } -> ...] You can nest named patterns within named patterns to any depth. Currently the use of named patterns is somewhat limited. The restrictions are: Named patterns can only be used within the same source file, and the names occupy a completely separate namespace from anything else in the source file. The [let bitmatch] syntax only works at the top level. We may add a [let bitmatch ... in] for inner levels later. Because you cannot rename the bound identifiers in named patterns, you can effectively only use them once in a pattern. For example, [{ :name; :name }] is legal, but any bindings in the first name would be overridden by the second name. There are no "named constructors" yet, but the machinery is in place to do this, and we may add them later. {2 Persistent patterns in files} More useful than just naming patterns, you can load persistent patterns from external files. The patterns in these external files can come from a variety of sources: for example, in the [cil-tools] subdirectory are some {{:http://cil.sf.net/}Cil-based} tools for importing C structures from header files. You can also generate your own files or write your own tools, as described below. To use the persistent pattern(s) from a file do: [open bitmatch "filename.bmpp" ;;] A list of zero or more {!named} patterns are read from the file and each is bound to a name (as contained in the file), and then the patterns can be used with the usual [:name] syntax described above. {3 Extension} The standard extension is [.bmpp]. This is just a convention and you can use any extension you want. {3 Directory search order} If the filename is an absolute or explicit path, then we try to load it from that path and stop if it fails. See the [Filename] module in the standard OCaml library for the definitions of "absolute path" and "explicit path". Otherwise we use the following directory search order: - Relative to the current directory - Relative to the OCaml library directory {3 bitstring-objinfo} The [bitstring-objinfo] command can be run on a file in order to print out the patterns in the file. {3 Constructors} We haven't implemented persistent constructors yet, although the machinery is in place to make this happen. Any constructors found in the file are ignored. {2 Creating your own persistent patterns} If you want to write a tool to import bitstrings from an exotic location or markup language, you will need to use the functions found in the {{:#reference}reference section}. I will describe using an example here of how you would programmatically create a persistent pattern which matches Pascal-style "length byte + data" strings. Firstly note that there are two fields, so our pattern will be a list of length 2 and type {!pattern}. You will need to create a camlp4 location object ([Loc.t]) describing the source file. This source file is used to generate useful error messages for the user, so you may want to set it to be the name and location in the file that your tool reads for input. By convention, locations are bound to name [_loc]: {v let _loc = Loc.move_line 42 (Loc.mk "input.xml") v} Create a pattern field representing a length field which is 8 bits wide, bound to the identifier [len]: {v let len_field = create_pattern_field _loc let len_field = set_length_int len_field 8 let len_field = set_lident_patt len_field "len" v} Create a pattern field representing a string of [len*8] bits. Note that the use of [<:expr< >>] quotation requires you to preprocess your source with [camlp4of] (see {{:http://brion.inria.fr/gallium/index.php/Reflective_OCaml}this page on Reflective OCaml}). {v let str_field = create_pattern_field _loc let str_field = set_length str_field <:expr< len*8 >> let str_field = set_lident_patt str_field "str" let str_field = set_type_string str_field v} Join the two fields together and name it: {v let pattern = [len_field; str_field] let named_pattern = "pascal_string", Pattern pattern v} Save it to a file: {v let chan = open_out "output.bmpp" in named_to_channel chan named_pattern; close_out chan v} You can now use this pattern in another program like this: {v open bitmatch "output.bmpp" ;; let parse_pascal_string bits = bitmatch bits with | \{ :pascal_string } -> str, len | \{ _ } -> invalid_arg "not a Pascal string" v} You can write more than one named pattern to the output file, and they will all be loaded at the same time by [open bitmatch ".."] (obviously you should give each pattern a different name). To do this, just call {!named_to_channel} as many times as needed. {2:reference Reference} {3 Types} *) type patt = Camlp4.PreCast.Syntax.Ast.patt type expr = Camlp4.PreCast.Syntax.Ast.expr type loc_t = Camlp4.PreCast.Syntax.Ast.Loc.t (** Just short names for the camlp4 types. *) type 'a field (** A field in a persistent pattern or persistent constructor. *) type pattern = patt field list (** A persistent pattern (used in [bitmatch] operator), is just a list of pattern fields. *) type constructor = expr field list (** A persistent constructor (used in [BITSTRING] operator), is just a list of constructor fields. *) type named = string * alt and alt = | Pattern of pattern (** Pattern *) | Constructor of constructor (** Constructor *) (** A named pattern or constructor. The name is used when binding a pattern from a file, but is otherwise ignored. *) (** {3 Printers} *) val string_of_pattern : pattern -> string val string_of_constructor : constructor -> string val string_of_pattern_field : patt field -> string val string_of_constructor_field : expr field -> string (** Convert patterns, constructors or individual fields into printable strings for debugging purposes. The strings look similar to the syntax used by bitmatch, but some things cannot be printed fully, eg. length expressions. *) (** {3 Persistence} *) val named_to_channel : out_channel -> named -> unit (** Save a pattern/constructor to an output channel. *) val named_to_string : named -> string (** Serialize a pattern/constructor to a string. *) val named_to_buffer : string -> int -> int -> named -> int (** Serialize a pattern/constructor to part of a string, return the length. *) val named_from_channel : in_channel -> named (** Load a pattern/constructor from an output channel. Note: This is not type safe. The pattern/constructor must have been written out under the same version of OCaml and the same version of bitstring. *) val named_from_string : string -> int -> named (** Load a pattern/constructor from a string at offset within the string. Note: This is not type safe. The pattern/constructor must have been written out under the same version of OCaml and the same version of bitstring. *) (** {3 Create pattern fields} These fields are used in pattern matches ([bitmatch]). *) val create_pattern_field : loc_t -> patt field (** Create a pattern field. The pattern is unbound, the type is set to [int], bit length to [32], endianness to [BigEndian], signedness to unsigned ([false]), source code location to the [_loc] parameter, and no offset expression. To create a complete field you need to call the [set_*] functions. For example, to create [{ len : 8 : int }] you would do: {v let field = create_pattern_field _loc in let field = set_lident_patt field "len" in let field = set_length_int field 8 in v} *) val set_lident_patt : patt field -> string -> patt field (** Sets the pattern to the pattern binding an identifier given in the string. The effect is that the field [{ len : 8 : int }] could be created by calling [set_lident_patt field "len"]. *) val set_int_patt : patt field -> int -> patt field (** Sets the pattern field to the pattern which matches an integer. The effect is that the field [{ 2 : 8 : int }] could be created by calling [set_int_patt field 2]. *) val set_string_patt : patt field -> string -> patt field (** Sets the pattern field to the pattern which matches a string. The effect is that the field [{ "MAGIC" : 8*5 : string }] could be created by calling [set_int_patt field "MAGIC"]. *) val set_unbound_patt : patt field -> patt field (** Sets the pattern field to the unbound pattern (usually written [_]). The effect is that the field [{ _ : 8 : int }] could be created by calling [set_unbound_patt field]. *) val set_patt : patt field -> patt -> patt field (** Sets the pattern field to an arbitrary OCaml pattern match. *) val set_length_int : 'a field -> int -> 'a field (** Sets the length in bits of a field to a constant integer. The effect is that the field [{ len : 8 : string }] could be created by calling [set_length field 8]. *) val set_length : 'a field -> expr -> 'a field (** Sets the length in bits of a field to an OCaml expression. The effect is that the field [{ len : 2*i : string }] could be created by calling [set_length field <:expr< 2*i >>]. *) val set_endian : 'a field -> Bitstring.endian -> 'a field (** Sets the endianness of a field to the constant endianness. The effect is that the field [{ _ : 16 : bigendian }] could be created by calling [set_endian field Bitstring.BigEndian]. *) val set_endian_expr : 'a field -> expr -> 'a field (** Sets the endianness of a field to an endianness expression. The effect is that the field [{ _ : 16 : endian(e) }] could be created by calling [set_endian_expr field e]. *) val set_signed : 'a field -> bool -> 'a field (** Sets the signedness of a field to a constant signedness. The effect is that the field [{ _ : 16 : signed }] could be created by calling [set_signed field true]. *) val set_type_int : 'a field -> 'a field (** Sets the type of a field to [int]. The effect is that the field [{ _ : 16 : int }] could be created by calling [set_type_int field]. *) val set_type_string : 'a field -> 'a field (** Sets the type of a field to [string]. The effect is that the field [{ str : 16 : string }] could be created by calling [set_type_string field]. *) val set_type_bitstring : 'a field -> 'a field (** Sets the type of a field to [bitstring]. The effect is that the field [{ _ : 768 : bitstring }] could be created by calling [set_type_bitstring field]. *) val set_location : 'a field -> loc_t -> 'a field (** Sets the source code location of a field. This is used when pa_bitstring displays error messages. *) val set_offset_int : 'a field -> int -> 'a field (** Set the offset expression for a field to the given number. The effect is that the field [{ _ : 8 : offset(160) }] could be created by calling [set_offset_int field 160]. *) val set_offset : 'a field -> expr -> 'a field (** Set the offset expression for a field to the given expression. The effect is that the field [{ _ : 8 : offset(160) }] could be created by calling [set_offset_int field <:expr< 160 >>]. *) val set_no_offset : 'a field -> 'a field (** Remove the offset expression from a field. The field will follow the previous field, or if it is the first field will be at offset zero. *) val set_check : 'a field -> expr -> 'a field (** Set the check expression for a field to the given expression. *) val set_no_check : 'a field -> 'a field (** Remove the check expression from a field. *) val set_bind : 'a field -> expr -> 'a field (** Set the bind-expression for a field to the given expression. *) val set_no_bind : 'a field -> 'a field (** Remove the bind-expression from a field. *) val set_save_offset_to : 'a field -> patt -> 'a field (** Set the save_offset_to pattern for a field to the given pattern. *) val set_save_offset_to_lident : 'a field -> string -> 'a field (** Set the save_offset_to pattern for a field to identifier. *) val set_no_save_offset_to : 'a field -> 'a field (** Remove the save_offset_to from a field. *) (** {3 Create constructor fields} These fields are used in constructors ([BITSTRING]). *) val create_constructor_field : loc_t -> expr field (** Create a constructor field. The defaults are the same as for {!create_pattern_field} except that the expression is initialized to [0]. *) val set_lident_expr : expr field -> string -> expr field (** Sets the expression in a constructor field to an expression which uses the identifier. The effect is that the field [{ len : 8 : int }] could be created by calling [set_lident_expr field "len"]. *) val set_int_expr : expr field -> int -> expr field (** Sets the expression to the value of the integer. The effect is that the field [{ 2 : 8 : int }] could be created by calling [set_int_expr field 2]. *) val set_string_expr : expr field -> string -> expr field (** Sets the expression to the value of the string. The effect is that the field [{ "MAGIC" : 8*5 : string }] could be created by calling [set_int_expr field "MAGIC"]. *) val set_expr : expr field -> expr -> expr field (** Sets the expression field to an arbitrary OCaml expression. *) (** {3 Accessors} *) val get_patt : patt field -> patt (** Get the pattern from a pattern field. *) val get_expr : expr field -> expr (** Get the expression from an expression field. *) val get_length : 'a field -> expr (** Get the length in bits from a field. Note that what is returned is an OCaml expression, since lengths can be non-constant. *) type endian_expr = | ConstantEndian of Bitstring.endian | EndianExpr of expr val get_endian : 'a field -> endian_expr (** Get the endianness of a field. This is an {!endian_expr} which could be a constant or an OCaml expression. *) val get_signed : 'a field -> bool (** Get the signedness of a field. *) type field_type = Int | String | Bitstring val get_type : 'a field -> field_type (** Get the type of a field, [Int], [String] or [Bitstring]. *) val get_location : 'a field -> loc_t (** Get the source code location of a field. *) val get_offset : 'a field -> expr option (** Get the offset expression of a field, or [None] if there is none. *) val get_check : 'a field -> expr option (** Get the check expression of a field, or [None] if there is none. *) val get_bind : 'a field -> expr option (** Get the bind expression of a field, or [None] if there is none. *) val get_save_offset_to : 'a field -> patt option (** Get the save_offset_to pattern of a field, or [None] if there is none. *) ocaml-bitstring-2.0.4/benchmarks/0000775000175000017500000000000012144457302016316 5ustar rjonesrjonesocaml-bitstring-2.0.4/benchmarks/parse_ext3_superblock.ml0000664000175000017500000000744212144455551023171 0ustar rjonesrjones(* Benchmark parsing of an ext3 superblock. * $Id: parse_ext3_superblock.ml 149 2008-08-26 08:16:01Z richard.wm.jones $ *) open Printf let bits = Bitstring.bitstring_of_file "examples/ext3_sb" let parse () = bitmatch bits with | { s_inodes_count : 32 : littleendian; (* Inodes count *) s_blocks_count : 32 : littleendian; (* Blocks count *) s_r_blocks_count : 32 : littleendian; (* Reserved blocks count *) s_free_blocks_count : 32 : littleendian; (* Free blocks count *) s_free_inodes_count : 32 : littleendian; (* Free inodes count *) s_first_data_block : 32 : littleendian; (* First Data Block *) s_log_block_size : 32 : littleendian; (* Block size *) s_log_frag_size : 32 : littleendian; (* Fragment size *) s_blocks_per_group : 32 : littleendian; (* # Blocks per group *) s_frags_per_group : 32 : littleendian; (* # Fragments per group *) s_inodes_per_group : 32 : littleendian; (* # Inodes per group *) s_mtime : 32 : littleendian; (* Mount time *) s_wtime : 32 : littleendian; (* Write time *) s_mnt_count : 16 : littleendian; (* Mount count *) s_max_mnt_count : 16 : littleendian; (* Maximal mount count *) 0xef53 : 16 : littleendian; (* Magic signature *) s_state : 16 : littleendian; (* File system state *) s_errors : 16 : littleendian; (* Behaviour when detecting errors *) s_minor_rev_level : 16 : littleendian; (* minor revision level *) s_lastcheck : 32 : littleendian; (* time of last check *) s_checkinterval : 32 : littleendian; (* max. time between checks *) s_creator_os : 32 : littleendian; (* OS *) s_rev_level : 32 : littleendian; (* Revision level *) s_def_resuid : 16 : littleendian; (* Default uid for reserved blocks *) s_def_resgid : 16 : littleendian; (* Default gid for reserved blocks *) s_first_ino : 32 : littleendian; (* First non-reserved inode *) s_inode_size : 16 : littleendian; (* size of inode structure *) s_block_group_nr : 16 : littleendian; (* block group # of this superblock *) s_feature_compat : 32 : littleendian; (* compatible feature set *) s_feature_incompat : 32 : littleendian; (* incompatible feature set *) s_feature_ro_compat : 32 : littleendian; (* readonly-compatible feature set *) s_uuid : 128 : string; (* 128-bit uuid for volume *) s_volume_name : 128 : string; (* volume name *) s_last_mounted : 512 : string; (* directory where last mounted *) s_algorithm_usage_bitmap : 32 : littleendian; (* For compression *) s_prealloc_blocks : 8; (* Nr of blocks to try to preallocate*) s_prealloc_dir_blocks : 8; (* Nr to preallocate for dirs *) s_reserved_gdt_blocks : 16 : littleendian;(* Per group desc for online growth *) s_journal_uuid : 128 : string; (* uuid of journal superblock *) s_journal_inum : 32 : littleendian; (* inode number of journal file *) s_journal_dev : 32 : littleendian; (* device number of journal file *) s_last_orphan : 32 : littleendian; (* start of list of inodes to delete *) s_hash_seed0 : 32 : littleendian; (* HTREE hash seed *) s_hash_seed1 : 32 : littleendian; s_hash_seed2 : 32 : littleendian; s_hash_seed3 : 32 : littleendian; s_def_hash_version : 8; (* Default hash version to use *) s_reserved_char_pad : 8; s_reserved_word_pad : 16 : littleendian; s_default_mount_opts : 32 : littleendian; s_first_meta_bg : 32 : littleendian; (* First metablock block group *) _ : 6080 : bitstring } -> (* Padding to the end of the block *) () | { _ } -> eprintf "not an ext3 superblock!\n%!"; exit 2 let () = for i = 0 to 2_000_000 do parse () done ocaml-bitstring-2.0.4/configure0000755000175000017500000055644312144457302016127 0ustar rjonesrjones#! /bin/sh # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.69 for ocaml-bitstring 2.0.4. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. # # # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # Use a proper internal environment variable to ensure we don't fall # into an infinite loop, continuously re-executing ourselves. if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then _as_can_reexec=no; export _as_can_reexec; # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 as_fn_exit 255 fi # We don't want this to propagate to other subprocesses. { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST else case \`(set -o) 2>/dev/null\` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi " as_required="as_fn_return () { (exit \$1); } as_fn_success () { as_fn_return 0; } as_fn_failure () { as_fn_return 1; } as_fn_ret_success () { return 0; } as_fn_ret_failure () { return 1; } exitcode=0 as_fn_success || { exitcode=1; echo as_fn_success failed.; } as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : else exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1 test -x / || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 test \$(( 1 + 1 )) = 2 || exit 1" if (eval "$as_required") 2>/dev/null; then : as_have_required=yes else as_have_required=no fi if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. as_found=: case $as_dir in #( /*) for as_base in sh bash ksh sh5; do # Try only shells that exist, to save several forks. as_shell=$as_dir/$as_base if { test -f "$as_shell" || test -f "$as_shell.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : CONFIG_SHELL=$as_shell as_have_required=yes if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : break 2 fi fi done;; esac as_found=false done $as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : CONFIG_SHELL=$SHELL as_have_required=yes fi; } IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : export CONFIG_SHELL # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi if test x$as_have_required = xno; then : $as_echo "$0: This script requires a shell more modern than all" $as_echo "$0: the shells that I found on your system." if test x${ZSH_VERSION+set} = xset ; then $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" $as_echo "$0: be upgraded to zsh 4.3.4 or later." else $as_echo "$0: Please tell bug-autoconf@gnu.org about your system, $0: including any error possibly output before this $0: message. Then install a modern shell, or manually run $0: the script under such a shell if you do have one." fi exit 1 fi fi fi SHELL=${CONFIG_SHELL-/bin/sh} export SHELL # Unset more variables known to interfere with behavior of common tools. CLICOLOR_FORCE= GREP_OPTIONS= unset CLICOLOR_FORCE GREP_OPTIONS ## --------------------- ## ## M4sh Shell Functions. ## ## --------------------- ## # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits as_lineno_1=$LINENO as_lineno_1a=$LINENO as_lineno_2=$LINENO as_lineno_2a=$LINENO eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) sed -n ' p /[$]LINENO/= ' <$as_myself | sed ' s/[$]LINENO.*/&-/ t lineno b :lineno N :loop s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ t loop s/-\n.*// ' >$as_me.lineno && chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } # If we had to re-execute with $CONFIG_SHELL, we're ensured to have # already done that, so ensure we don't try to do so again and fall # in an infinite loop. This has already happened in practice. _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). . "./$as_me.lineno" # Exit status is that of the last command. exit } ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" test -n "$DJDIR" || exec 7<&0 &1 # Name of the host. # hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, # so uname gets run too. ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` # # Initializations. # ac_default_prefix=/usr/local ac_clean_files= ac_config_libobj_dir=. LIBOBJS= cross_compiling=no subdirs= MFLAGS= MAKEFLAGS= # Identity of this package. PACKAGE_NAME='ocaml-bitstring' PACKAGE_TARNAME='ocaml-bitstring' PACKAGE_VERSION='2.0.4' PACKAGE_STRING='ocaml-bitstring 2.0.4' PACKAGE_BUGREPORT='' PACKAGE_URL='' # Factoring default headers for most tests. ac_includes_default="\ #include #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef HAVE_SYS_STAT_H # include #endif #ifdef STDC_HEADERS # include # include #else # ifdef HAVE_STDLIB_H # include # endif #endif #ifdef HAVE_STRING_H # if !defined STDC_HEADERS && defined HAVE_MEMORY_H # include # endif # include #endif #ifdef HAVE_STRINGS_H # include #endif #ifdef HAVE_INTTYPES_H # include #endif #ifdef HAVE_STDINT_H # include #endif #ifdef HAVE_UNISTD_H # include #endif" ac_subst_vars='LTLIBOBJS LIBOBJS enable_coverage BISECT_REPORT GPROF DIFF TIME OCAML_PKG_cil OCAML_PKG_extlib CAMLP4OF OCAMLFIND OCAMLBUILD OCAMLDOC OCAMLMKLIB OCAMLMKTOP OCAMLDEP OCAML OCAMLOPTDOTOPT OCAMLCDOTOPT OCAMLBEST OCAMLOPT OCAMLLIB OCAMLVERSION OCAMLC BYTESWAP_H NATIVEENDIAN EGREP GREP CPP INSTALL_DATA INSTALL_SCRIPT INSTALL_PROGRAM OBJEXT EXEEXT ac_ct_CC CPPFLAGS LDFLAGS CFLAGS CC SED target_alias host_alias build_alias LIBS ECHO_T ECHO_N ECHO_C DEFS mandir localedir libdir psdir pdfdir dvidir htmldir infodir docdir oldincludedir includedir localstatedir sharedstatedir sysconfdir datadir datarootdir libexecdir sbindir bindir program_transform_name prefix exec_prefix PACKAGE_URL PACKAGE_BUGREPORT PACKAGE_STRING PACKAGE_VERSION PACKAGE_TARNAME PACKAGE_NAME PATH_SEPARATOR SHELL' ac_subst_files='' ac_user_opts=' enable_option_checking enable_coverage ' ac_precious_vars='build_alias host_alias target_alias CC CFLAGS LDFLAGS LIBS CPPFLAGS CPP' # Initialize some variables set by options. ac_init_help= ac_init_version=false ac_unrecognized_opts= ac_unrecognized_sep= # The variables have the same names as the options, with # dashes changed to underlines. cache_file=/dev/null exec_prefix=NONE no_create= no_recursion= prefix=NONE program_prefix=NONE program_suffix=NONE program_transform_name=s,x,x, silent= site= srcdir= verbose= x_includes=NONE x_libraries=NONE # Installation directory options. # These are left unexpanded so users can "make install exec_prefix=/foo" # and all the variables that are supposed to be based on exec_prefix # by default will actually change. # Use braces instead of parens because sh, perl, etc. also accept them. # (The list follows the same order as the GNU Coding Standards.) bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' datarootdir='${prefix}/share' datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' infodir='${datarootdir}/info' htmldir='${docdir}' dvidir='${docdir}' pdfdir='${docdir}' psdir='${docdir}' libdir='${exec_prefix}/lib' localedir='${datarootdir}/locale' mandir='${datarootdir}/man' ac_prev= ac_dashdash= for ac_option do # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then eval $ac_prev=\$ac_option ac_prev= continue fi case $ac_option in *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; *=) ac_optarg= ;; *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. case $ac_dashdash$ac_option in --) ac_dashdash=yes ;; -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) cache_file=$ac_optarg ;; --config-cache | -C) cache_file=config.cache ;; -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; -datadir=* | --datadir=* | --datadi=* | --datad=*) datadir=$ac_optarg ;; -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ | --dataroo | --dataro | --datar) ac_prev=datarootdir ;; -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) datarootdir=$ac_optarg ;; -disable-* | --disable-*) ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=no ;; -docdir | --docdir | --docdi | --doc | --do) ac_prev=docdir ;; -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) docdir=$ac_optarg ;; -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) ac_prev=dvidir ;; -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) dvidir=$ac_optarg ;; -enable-* | --enable-*) ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ | --exec | --exe | --ex) ac_prev=exec_prefix ;; -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; -help | --help | --hel | --he | -h) ac_init_help=long ;; -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) ac_init_help=recursive ;; -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) ac_init_help=short ;; -host | --host | --hos | --ho) ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) host_alias=$ac_optarg ;; -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) ac_prev=htmldir ;; -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ | --ht=*) htmldir=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) libexecdir=$ac_optarg ;; -localedir | --localedir | --localedi | --localed | --locale) ac_prev=localedir ;; -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) localedir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ | --localstate | --localstat | --localsta | --localst | --locals) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) no_recursion=yes ;; -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ | --oldin | --oldi | --old | --ol | --o) ac_prev=oldincludedir ;; -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ | --program-transform-n | --program-transform- \ | --program-transform | --program-transfor \ | --program-transfo | --program-transf \ | --program-trans | --program-tran \ | --progr-tra | --program-tr | --program-t) ac_prev=program_transform_name ;; -program-transform-name=* | --program-transform-name=* \ | --program-transform-nam=* | --program-transform-na=* \ | --program-transform-n=* | --program-transform-=* \ | --program-transform=* | --program-transfor=* \ | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) program_transform_name=$ac_optarg ;; -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) ac_prev=pdfdir ;; -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) pdfdir=$ac_optarg ;; -psdir | --psdir | --psdi | --psd | --ps) ac_prev=psdir ;; -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ | --sharedst | --shareds | --shared | --share | --shar \ | --sha | --sh) ac_prev=sharedstatedir ;; -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; -version | --version | --versio | --versi | --vers | -V) ac_init_version=: ;; -with-* | --with-*) ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=\$ac_optarg ;; -without-* | --without-*) ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=no ;; --x) # Obsolete; use --with-x. with_x=yes ;; -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ | --x-incl | --x-inc | --x-in | --x-i) ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) x_libraries=$ac_optarg ;; -*) as_fn_error $? "unrecognized option: \`$ac_option' Try \`$0 --help' for more information" ;; *=*) ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` # Reject names that are not valid shell variable names. case $ac_envvar in #( '' | [0-9]* | *[!_$as_cr_alnum]* ) as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; esac eval $ac_envvar=\$ac_optarg export $ac_envvar ;; *) # FIXME: should be removed in autoconf 3.0. $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" ;; esac done if test -n "$ac_prev"; then ac_option=--`echo $ac_prev | sed 's/_/-/g'` as_fn_error $? "missing argument to $ac_option" fi if test -n "$ac_unrecognized_opts"; then case $enable_option_checking in no) ;; fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi # Check all directory arguments for consistency. for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. case $ac_val in */ ) ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` eval $ac_var=\$ac_val;; esac # Be sure to have absolute directory names. case $ac_val in [\\/$]* | ?:[\\/]* ) continue;; NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" done # There might be people who depend on the old broken behavior: `$host' # used to hold the argument of --host etc. # FIXME: To remove some day. build=$build_alias host=$host_alias target=$target_alias # FIXME: To remove some day. if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi fi ac_tool_prefix= test -n "$host_alias" && ac_tool_prefix=$host_alias- test "$silent" = yes && exec 6>/dev/null ac_pwd=`pwd` && test -n "$ac_pwd" && ac_ls_di=`ls -di .` && ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || as_fn_error $? "working directory cannot be determined" test "X$ac_ls_di" = "X$ac_pwd_ls_di" || as_fn_error $? "pwd does not report name of working directory" # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes # Try the directory containing this script, then the parent directory. ac_confdir=`$as_dirname -- "$as_myself" || $as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` srcdir=$ac_confdir if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi if test ! -r "$srcdir/$ac_unique_file"; then test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" fi ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" ac_abs_confdir=`( cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" pwd)` # When building in place, set srcdir=. if test "$ac_abs_confdir" = "$ac_pwd"; then srcdir=. fi # Remove unnecessary trailing slashes from srcdir. # Double slashes in file names in object file debugging info # mess up M-x gdb in Emacs. case $srcdir in */) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; esac for ac_var in $ac_precious_vars; do eval ac_env_${ac_var}_set=\${${ac_var}+set} eval ac_env_${ac_var}_value=\$${ac_var} eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} eval ac_cv_env_${ac_var}_value=\$${ac_var} done # # Report the --help message. # if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF \`configure' configures ocaml-bitstring 2.0.4 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print \`checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for \`--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or \`..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [$ac_default_prefix] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, \`make install' will install all the files in \`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify an installation prefix other than \`$ac_default_prefix' using \`--prefix', for instance \`--prefix=\$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/ocaml-bitstring] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] _ACEOF cat <<\_ACEOF _ACEOF fi if test -n "$ac_init_help"; then case $ac_init_help in short | recursive ) echo "Configuration of ocaml-bitstring 2.0.4:";; esac cat <<\_ACEOF Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --enable-coverage add code coverage information (slow) [default=no] Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L if you have libraries in a nonstandard directory LIBS libraries to pass to the linker, e.g. -l CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory CPP C preprocessor Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to the package provider. _ACEOF ac_status=$? fi if test "$ac_init_help" = "recursive"; then # If there are subdirs, report their specific --help. for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue test -d "$ac_dir" || { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || continue ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix cd "$ac_dir" || { ac_status=$?; continue; } # Check for guested configure. if test -f "$ac_srcdir/configure.gnu"; then echo && $SHELL "$ac_srcdir/configure.gnu" --help=recursive elif test -f "$ac_srcdir/configure"; then echo && $SHELL "$ac_srcdir/configure" --help=recursive else $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi || ac_status=$? cd "$ac_pwd" || { ac_status=$?; break; } done fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF ocaml-bitstring configure 2.0.4 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF exit fi ## ------------------------ ## ## Autoconf initialization. ## ## ------------------------ ## # ac_fn_c_try_compile LINENO # -------------------------- # Try to compile conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest.$ac_objext; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_compile # ac_fn_c_try_cpp LINENO # ---------------------- # Try to preprocess conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_cpp () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_cpp conftest.$ac_ext" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } > conftest.i && { test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || test ! -s conftest.err }; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_cpp # ac_fn_c_try_run LINENO # ---------------------- # Try to link conftest.$ac_ext, and return whether this succeeded. Assumes # that executables *can* be run. ac_fn_c_try_run () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then : ac_retval=0 else $as_echo "$as_me: program exited with status $ac_status" >&5 $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=$ac_status fi rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_run # ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists and can be compiled using the include files in # INCLUDES, setting the cache variable VAR accordingly. ac_fn_c_check_header_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF if ac_fn_c_try_compile "$LINENO"; then : eval "$3=yes" else eval "$3=no" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_compile # ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists, giving a warning if it cannot be compiled using # the include files in INCLUDES and setting the cache variable VAR # accordingly. ac_fn_c_check_header_mongrel () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if eval \${$3+:} false; then : { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } else # Is the header compilable? { $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 $as_echo_n "checking $2 usability... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_header_compiler=yes else ac_header_compiler=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 $as_echo "$ac_header_compiler" >&6; } # Is the header present? { $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 $as_echo_n "checking $2 presence... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include <$2> _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : ac_header_preproc=yes else ac_header_preproc=no fi rm -f conftest.err conftest.i conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 $as_echo "$ac_header_preproc" >&6; } # So? What about this header? case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( yes:no: ) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 $as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 $as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} ;; no:yes:* ) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 $as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 $as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 $as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 $as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 $as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else eval "$3=\$ac_header_compiler" fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_mongrel cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by ocaml-bitstring $as_me 2.0.4, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ _ACEOF exec 5>>config.log { cat <<_ASUNAME ## --------- ## ## Platform. ## ## --------- ## hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` /bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` /bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` /usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` /bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` /bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` _ASUNAME as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. $as_echo "PATH: $as_dir" done IFS=$as_save_IFS } >&5 cat >&5 <<_ACEOF ## ----------- ## ## Core tests. ## ## ----------- ## _ACEOF # Keep a trace of the command line. # Strip out --no-create and --no-recursion so they do not pile up. # Strip out --silent because we don't want to record it for future runs. # Also quote any args containing shell meta-characters. # Make two passes to allow for proper duplicate-argument suppression. ac_configure_args= ac_configure_args0= ac_configure_args1= ac_must_keep_next=false for ac_pass in 1 2 do for ac_arg do case $ac_arg in -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) continue ;; *\'*) ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; 2) as_fn_append ac_configure_args1 " '$ac_arg'" if test $ac_must_keep_next = true; then ac_must_keep_next=false # Got value, back to normal. else case $ac_arg in *=* | --config-cache | -C | -disable-* | --disable-* \ | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ | -with-* | --with-* | -without-* | --without-* | --x) case "$ac_configure_args0 " in "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; esac ;; -* ) ac_must_keep_next=true ;; esac fi as_fn_append ac_configure_args " '$ac_arg'" ;; esac done done { ac_configure_args0=; unset ac_configure_args0;} { ac_configure_args1=; unset ac_configure_args1;} # When interrupted or exit'd, cleanup temporary files, and complete # config.log. We remove comments because anyway the quotes in there # would cause problems or look ugly. # WARNING: Use '\'' to represent an apostrophe within the trap. # WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. trap 'exit_status=$? # Save into config.log some information that might help in debugging. { echo $as_echo "## ---------------- ## ## Cache variables. ## ## ---------------- ##" echo # The following way of writing the cache mishandles newlines in values, ( for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( *${as_nl}ac_space=\ *) sed -n \ "s/'\''/'\''\\\\'\'''\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" ;; #( *) sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) echo $as_echo "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo for ac_var in $ac_subst_vars do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then $as_echo "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo for ac_var in $ac_subst_files do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then $as_echo "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo cat confdefs.h echo fi test "$ac_signal" != 0 && $as_echo "$as_me: caught signal $ac_signal" $as_echo "$as_me: exit $exit_status" } >&5 rm -f core *.core core.conftest.* && rm -f -r conftest* confdefs* conf$$* $ac_clean_files && exit $exit_status ' 0 for ac_signal in 1 2 13 15; do trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal done ac_signal=0 # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -f -r conftest* confdefs.h $as_echo "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. cat >>confdefs.h <<_ACEOF #define PACKAGE_NAME "$PACKAGE_NAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_TARNAME "$PACKAGE_TARNAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_VERSION "$PACKAGE_VERSION" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_STRING "$PACKAGE_STRING" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_URL "$PACKAGE_URL" _ACEOF # Let the site file select an alternate cache file if it wants to. # Prefer an explicitly selected file to automatically selected ones. ac_site_file1=NONE ac_site_file2=NONE if test -n "$CONFIG_SITE"; then # We do not want a PATH search for config.site. case $CONFIG_SITE in #(( -*) ac_site_file1=./$CONFIG_SITE;; */*) ac_site_file1=$CONFIG_SITE;; *) ac_site_file1=./$CONFIG_SITE;; esac elif test "x$prefix" != xNONE; then ac_site_file1=$prefix/share/config.site ac_site_file2=$prefix/etc/config.site else ac_site_file1=$ac_default_prefix/share/config.site ac_site_file2=$ac_default_prefix/etc/config.site fi for ac_site_file in "$ac_site_file1" "$ac_site_file2" do test "x$ac_site_file" = xNONE && continue if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 $as_echo "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file See \`config.log' for more details" "$LINENO" 5; } fi done if test -r "$cache_file"; then # Some versions of bash will fail to source /dev/null (special files # actually), so we avoid doing that. DJGPP emulates it as a regular file. if test /dev/null != "$cache_file" && test -f "$cache_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 $as_echo "$as_me: loading cache $cache_file" >&6;} case $cache_file in [\\/]* | ?:[\\/]* ) . "$cache_file";; *) . "./$cache_file";; esac fi else { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 $as_echo "$as_me: creating cache $cache_file" >&6;} >$cache_file fi # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false for ac_var in $ac_precious_vars; do eval ac_old_set=\$ac_cv_env_${ac_var}_set eval ac_new_set=\$ac_env_${ac_var}_set eval ac_old_val=\$ac_cv_env_${ac_var}_value eval ac_new_val=\$ac_env_${ac_var}_value case $ac_old_set,$ac_new_set in set,) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) if test "x$ac_old_val" != "x$ac_new_val"; then # differences in whitespace do not lead to failure. ac_old_val_w=`echo x $ac_old_val` ac_new_val_w=`echo x $ac_new_val` if test "$ac_old_val_w" != "$ac_new_val_w"; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 $as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 $as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 $as_echo "$as_me: former value: \`$ac_old_val'" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 $as_echo "$as_me: current value: \`$ac_new_val'" >&2;} fi;; esac # Pass precious variables to config.status. if test "$ac_new_set" = set; then case $ac_new_val in *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; *) ac_arg=$ac_var=$ac_new_val ;; esac case " $ac_configure_args " in *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. *) as_fn_append ac_configure_args " '$ac_arg'" ;; esac fi done if $ac_cache_corrupted; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 $as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## ## -------------------- ## ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5 $as_echo_n "checking for a sed that does not truncate output... " >&6; } if ${ac_cv_path_SED+:} false; then : $as_echo_n "(cached) " >&6 else ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ for ac_i in 1 2 3 4 5 6 7; do ac_script="$ac_script$as_nl$ac_script" done echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed { ac_script=; unset ac_script;} if test -z "$SED"; then ac_path_SED_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in sed gsed; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_SED="$as_dir/$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_SED" || continue # Check for GNU ac_path_SED and select it if it is found. # Check for GNU $ac_path_SED case `"$ac_path_SED" --version 2>&1` in *GNU*) ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo '' >> "conftest.nl" "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_SED_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_SED="$ac_path_SED" ac_path_SED_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_SED_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_SED"; then as_fn_error $? "no acceptable sed could be found in \$PATH" "$LINENO" 5 fi else ac_cv_path_SED=$SED fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 $as_echo "$ac_cv_path_SED" >&6; } SED="$ac_cv_path_SED" rm -f conftest.sed ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. set dummy ${ac_tool_prefix}gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_CC"; then ac_ct_CC=$CC # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi else CC="$ac_cv_prog_CC" fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. set dummy ${ac_tool_prefix}cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi fi if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else ac_prog_rejected=no as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue fi ac_cv_prog_CC="cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS if test $ac_prog_rejected = yes; then # We found a bogon in the path, so make sure we never use it. set dummy $ac_cv_prog_CC shift if test $# != 0; then # We chose a different compiler from the bogus one. # However, it has the same basename, so the bogon will be chosen # first if we set CC to just the basename; use the full file name. shift ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" fi fi fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then for ac_prog in cl.exe do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$CC" && break done fi if test -z "$CC"; then ac_ct_CC=$CC for ac_prog in cl.exe do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$ac_ct_CC" && break done if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi fi fi test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "no acceptable C compiler found in \$PATH See \`config.log' for more details" "$LINENO" 5; } # Provide some information about the compiler. $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 set X $ac_compile ac_compiler=$2 for ac_option in --version -v -V -qversion; do { { ac_try="$ac_compiler $ac_option >&5" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then sed '10a\ ... rest of stderr output deleted ... 10q' conftest.err >conftest.er1 cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" # Try to create an executable without -o first, disregard a.out. # It will help us diagnose broken compilers, and finding out an intuition # of exeext. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 $as_echo_n "checking whether the C compiler works... " >&6; } ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` # The possible output files: ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" ac_rmfiles= for ac_file in $ac_files do case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; * ) ac_rmfiles="$ac_rmfiles $ac_file";; esac done rm -f $ac_rmfiles if { { ac_try="$ac_link_default" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link_default") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. # So ignore a value of `no', otherwise this would lead to `EXEEXT = no' # in a Makefile. We should not override ac_cv_exeext if it was cached, # so that the user can short-circuit this test for compilers unknown to # Autoconf. for ac_file in $ac_files '' do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; [ab].out ) # We found the default executable, but exeext='' is most # certainly right. break;; *.* ) if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; then :; else ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` fi # We set ac_cv_exeext here because the later test for it is not # safe: cross compilers may not add the suffix if given an `-o' # argument, so we may need to know it at that point already. # Even if this section looks crufty: it has the advantage of # actually working. break;; * ) break;; esac done test "$ac_cv_exeext" = no && ac_cv_exeext= else ac_file='' fi if test -z "$ac_file"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "C compiler cannot create executables See \`config.log' for more details" "$LINENO" 5; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 $as_echo_n "checking for C compiler default output file name... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 $as_echo "$ac_file" >&6; } ac_exeext=$ac_cv_exeext rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 $as_echo_n "checking for suffix of executables... " >&6; } if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # If both `conftest.exe' and `conftest' are `present' (well, observable) # catch `conftest.exe'. For instance with Cygwin, `ls conftest' will # work properly (i.e., refer to `conftest.exe'), while it won't with # `rm'. for ac_file in conftest.exe conftest conftest.*; do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` break;; * ) break;; esac done else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of executables: cannot compile and link See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest conftest$ac_cv_exeext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 $as_echo "$ac_cv_exeext" >&6; } rm -f conftest.$ac_ext EXEEXT=$ac_cv_exeext ac_exeext=$EXEEXT cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { FILE *f = fopen ("conftest.out", "w"); return ferror (f) || fclose (f) != 0; ; return 0; } _ACEOF ac_clean_files="$ac_clean_files conftest.out" # Check that the compiler produces executables we can run. If not, either # the compiler is broken, or we cross compile. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 $as_echo_n "checking whether we are cross compiling... " >&6; } if test "$cross_compiling" != yes; then { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if { ac_try='./conftest$ac_cv_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then cross_compiling=no else if test "$cross_compiling" = maybe; then cross_compiling=yes else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run C compiled programs. If you meant to cross compile, use \`--host'. See \`config.log' for more details" "$LINENO" 5; } fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 $as_echo "$cross_compiling" >&6; } rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 $as_echo_n "checking for suffix of object files... " >&6; } if ${ac_cv_objext+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF rm -f conftest.o conftest.obj if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : for ac_file in conftest.o conftest.obj conftest.*; do test -f "$ac_file" || continue; case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` break;; esac done else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of object files: cannot compile See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest.$ac_cv_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 $as_echo "$ac_cv_objext" >&6; } OBJEXT=$ac_cv_objext ac_objext=$OBJEXT { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 $as_echo_n "checking whether we are using the GNU C compiler... " >&6; } if ${ac_cv_c_compiler_gnu+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { #ifndef __GNUC__ choke me #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_compiler_gnu=yes else ac_compiler_gnu=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_cv_c_compiler_gnu=$ac_compiler_gnu fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 $as_echo "$ac_cv_c_compiler_gnu" >&6; } if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi ac_test_CFLAGS=${CFLAGS+set} ac_save_CFLAGS=$CFLAGS { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 $as_echo_n "checking whether $CC accepts -g... " >&6; } if ${ac_cv_prog_cc_g+:} false; then : $as_echo_n "(cached) " >&6 else ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes else CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : else ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_c_werror_flag=$ac_save_c_werror_flag fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 $as_echo "$ac_cv_prog_cc_g" >&6; } if test "$ac_test_CFLAGS" = set; then CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then CFLAGS="-g -O2" else CFLAGS="-g" fi else if test "$GCC" = yes; then CFLAGS="-O2" else CFLAGS= fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 $as_echo_n "checking for $CC option to accept ISO C89... " >&6; } if ${ac_cv_prog_cc_c89+:} false; then : $as_echo_n "(cached) " >&6 else ac_cv_prog_cc_c89=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include struct stat; /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); static char *e (p, i) char **p; int i; { return p[i]; } static char *f (char * (*g) (char **, int), char **p, ...) { char *s; va_list v; va_start (v,p); s = g (p, va_arg (v,int)); va_end (v); return s; } /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has function prototypes and stuff, but not '\xHH' hex character constants. These don't provoke an error unfortunately, instead are silently treated as 'x'. The following induces an error, until -std is added to get proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an array size at least. It's necessary to write '\x00'==0 to get something that's true only with -std. */ int osf4_cc_array ['\x00' == 0 ? 1 : -1]; /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters inside strings and character constants. */ #define FOO(x) 'x' int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; int test (int i, double x); struct s1 {int (*f) (int a);}; struct s2 {int (*f) (double a);}; int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); int argc; char **argv; int main () { return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; ; return 0; } _ACEOF for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_c89=$ac_arg fi rm -f core conftest.err conftest.$ac_objext test "x$ac_cv_prog_cc_c89" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC fi # AC_CACHE_VAL case "x$ac_cv_prog_cc_c89" in x) { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 $as_echo "none needed" >&6; } ;; xno) { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 $as_echo "unsupported" >&6; } ;; *) CC="$CC $ac_cv_prog_cc_c89" { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 $as_echo "$ac_cv_prog_cc_c89" >&6; } ;; esac if test "x$ac_cv_prog_cc_c89" != xno; then : fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu ac_aux_dir= for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do if test -f "$ac_dir/install-sh"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/install-sh -c" break elif test -f "$ac_dir/install.sh"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/install.sh -c" break elif test -f "$ac_dir/shtool"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/shtool install -c" break fi done if test -z "$ac_aux_dir"; then as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5 fi # These three variables are undocumented and unsupported, # and are intended to be withdrawn in a future Autoconf release. # They can cause serious problems if a builder's source tree is in a directory # whose full name contains unusual characters. ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or # incompatible versions: # SysV /etc/install, /usr/sbin/install # SunOS /usr/etc/install # IRIX /sbin/install # AIX /bin/install # AmigaOS /C/install, which installs bootblocks on floppy discs # AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag # AFS /usr/afsws/bin/install, which mishandles nonexistent args # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # OS/2's system install, which has a completely different semantic # ./install, which can be erroneously created by make from ./install.sh. # Reject install programs that cannot install multiple files. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 $as_echo_n "checking for a BSD-compatible install... " >&6; } if test -z "$INSTALL"; then if ${ac_cv_path_install+:} false; then : $as_echo_n "(cached) " >&6 else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. # Account for people who put trailing slashes in PATH elements. case $as_dir/ in #(( ./ | .// | /[cC]/* | \ /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ /usr/ucb/* ) ;; *) # OSF1 and SCO ODT 3.0 have their own names for install. # Don't use installbsd from OSF since it installs stuff as root # by default. for ac_prog in ginstall scoinst install; do for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then if test $ac_prog = install && grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. : elif test $ac_prog = install && grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # program-specific install script used by HP pwplus--don't use. : else rm -rf conftest.one conftest.two conftest.dir echo one > conftest.one echo two > conftest.two mkdir conftest.dir if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && test -s conftest.one && test -s conftest.two && test -s conftest.dir/conftest.one && test -s conftest.dir/conftest.two then ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" break 3 fi fi fi done done ;; esac done IFS=$as_save_IFS rm -rf conftest.one conftest.two conftest.dir fi if test "${ac_cv_path_install+set}" = set; then INSTALL=$ac_cv_path_install else # As a last resort, use the slow shell script. Don't cache a # value for INSTALL within a source directory, because that will # break other packages using the cache if that directory is # removed, or if the value is a relative name. INSTALL=$ac_install_sh fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 $as_echo "$INSTALL" >&6; } # Use test -z because SunOS4 sh mishandles braces in ${var-val}. # It thinks the first close brace ends the variable substitution. test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 $as_echo_n "checking how to run the C preprocessor... " >&6; } # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= fi if test -z "$CPP"; then if ${ac_cv_prog_CPP+:} false; then : $as_echo_n "(cached) " >&6 else # Double quotes because CPP needs to be expanded for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" do ac_preproc_ok=false for ac_c_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. # Prefer to if __STDC__ is defined, since # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __STDC__ # include #else # include #endif Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : else # Broken: fails on valid input. continue fi rm -f conftest.err conftest.i conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue else # Passes both tests. ac_preproc_ok=: break fi rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext if $ac_preproc_ok; then : break fi done ac_cv_prog_CPP=$CPP fi CPP=$ac_cv_prog_CPP else ac_cv_prog_CPP=$CPP fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 $as_echo "$CPP" >&6; } ac_preproc_ok=false for ac_c_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. # Prefer to if __STDC__ is defined, since # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __STDC__ # include #else # include #endif Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : else # Broken: fails on valid input. continue fi rm -f conftest.err conftest.i conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue else # Passes both tests. ac_preproc_ok=: break fi rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext if $ac_preproc_ok; then : else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "C preprocessor \"$CPP\" fails sanity check See \`config.log' for more details" "$LINENO" 5; } fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu { $as_echo "$as_me:${as_lineno-$LINENO}: checking for function prototypes" >&5 $as_echo_n "checking for function prototypes... " >&6; } if test "$ac_cv_prog_cc_c89" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } $as_echo "#define PROTOTYPES 1" >>confdefs.h $as_echo "#define __PROTOTYPES 1" >>confdefs.h else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test "x$U" != "x" && as_fn_error $? "Compiler not ANSI compliant" "$LINENO" 5 if test "x$CC" != xcc; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC and cc understand -c and -o together" >&5 $as_echo_n "checking whether $CC and cc understand -c and -o together... " >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether cc understands -c and -o together" >&5 $as_echo_n "checking whether cc understands -c and -o together... " >&6; } fi set dummy $CC; ac_cc=`$as_echo "$2" | sed 's/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/'` if eval \${ac_cv_prog_cc_${ac_cc}_c_o+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF # Make sure it works both with $CC and with simple cc. # We do the test twice because some compilers refuse to overwrite an # existing .o file with -o, though they will create one. ac_try='$CC -c conftest.$ac_ext -o conftest2.$ac_objext >&5' rm -f conftest2.* if { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -f conftest2.$ac_objext && { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then eval ac_cv_prog_cc_${ac_cc}_c_o=yes if test "x$CC" != xcc; then # Test first that cc exists at all. if { ac_try='cc -c conftest.$ac_ext >&5' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then ac_try='cc -c conftest.$ac_ext -o conftest2.$ac_objext >&5' rm -f conftest2.* if { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -f conftest2.$ac_objext && { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then # cc works too. : else # cc exists but doesn't like -o. eval ac_cv_prog_cc_${ac_cc}_c_o=no fi fi fi else eval ac_cv_prog_cc_${ac_cc}_c_o=no fi rm -f core conftest* fi if eval test \$ac_cv_prog_cc_${ac_cc}_c_o = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } $as_echo "#define NO_MINUS_C_MINUS_O 1" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 $as_echo_n "checking for grep that handles long lines and -e... " >&6; } if ${ac_cv_path_GREP+:} false; then : $as_echo_n "(cached) " >&6 else if test -z "$GREP"; then ac_path_GREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in grep ggrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_GREP" || continue # Check for GNU ac_path_GREP and select it if it is found. # Check for GNU $ac_path_GREP case `"$ac_path_GREP" --version 2>&1` in *GNU*) ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo 'GREP' >> "conftest.nl" "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_GREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_GREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_GREP"; then as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_GREP=$GREP fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 $as_echo "$ac_cv_path_GREP" >&6; } GREP="$ac_cv_path_GREP" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 $as_echo_n "checking for egrep... " >&6; } if ${ac_cv_path_EGREP+:} false; then : $as_echo_n "(cached) " >&6 else if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 then ac_cv_path_EGREP="$GREP -E" else if test -z "$EGREP"; then ac_path_EGREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in egrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_EGREP" || continue # Check for GNU ac_path_EGREP and select it if it is found. # Check for GNU $ac_path_EGREP case `"$ac_path_EGREP" --version 2>&1` in *GNU*) ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo 'EGREP' >> "conftest.nl" "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_EGREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_EGREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_EGREP"; then as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_EGREP=$EGREP fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 $as_echo "$ac_cv_path_EGREP" >&6; } EGREP="$ac_cv_path_EGREP" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 $as_echo_n "checking for ANSI C header files... " >&6; } if ${ac_cv_header_stdc+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include #include int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_header_stdc=yes else ac_cv_header_stdc=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "memchr" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "free" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. if test "$cross_compiling" = yes; then : : else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #if ((' ' & 0x0FF) == 0x020) # define ISLOWER(c) ('a' <= (c) && (c) <= 'z') # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) #else # define ISLOWER(c) \ (('a' <= (c) && (c) <= 'i') \ || ('j' <= (c) && (c) <= 'r') \ || ('s' <= (c) && (c) <= 'z')) # define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) #endif #define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) int main () { int i; for (i = 0; i < 256; i++) if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) return 2; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : else ac_cv_header_stdc=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 $as_echo "$ac_cv_header_stdc" >&6; } if test $ac_cv_header_stdc = yes; then $as_echo "#define STDC_HEADERS 1" >>confdefs.h fi # On IRIX 5.3, sys/types and inttypes.h are conflicting. for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ inttypes.h stdint.h unistd.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default " if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 _ACEOF fi done { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5 $as_echo_n "checking whether byte ordering is bigendian... " >&6; } if ${ac_cv_c_bigendian+:} false; then : $as_echo_n "(cached) " >&6 else ac_cv_c_bigendian=unknown # See if we're dealing with a universal compiler. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifndef __APPLE_CC__ not a universal capable compiler #endif typedef int dummy; _ACEOF if ac_fn_c_try_compile "$LINENO"; then : # Check for potential -arch flags. It is not universal unless # there are at least two -arch flags with different values. ac_arch= ac_prev= for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do if test -n "$ac_prev"; then case $ac_word in i?86 | x86_64 | ppc | ppc64) if test -z "$ac_arch" || test "$ac_arch" = "$ac_word"; then ac_arch=$ac_word else ac_cv_c_bigendian=universal break fi ;; esac ac_prev= elif test "x$ac_word" = "x-arch"; then ac_prev=arch fi done fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext if test $ac_cv_c_bigendian = unknown; then # See if sys/param.h defines the BYTE_ORDER macro. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int main () { #if ! (defined BYTE_ORDER && defined BIG_ENDIAN \ && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \ && LITTLE_ENDIAN) bogus endian macros #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : # It does; now see whether it defined to BIG_ENDIAN or not. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int main () { #if BYTE_ORDER != BIG_ENDIAN not big endian #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_c_bigendian=yes else ac_cv_c_bigendian=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi if test $ac_cv_c_bigendian = unknown; then # See if defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris). cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { #if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN) bogus endian macros #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : # It does; now see whether it defined to _BIG_ENDIAN or not. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { #ifndef _BIG_ENDIAN not big endian #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_c_bigendian=yes else ac_cv_c_bigendian=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi if test $ac_cv_c_bigendian = unknown; then # Compile a test program. if test "$cross_compiling" = yes; then : # Try to guess by grepping values from an object file. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ short int ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 }; short int ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 }; int use_ascii (int i) { return ascii_mm[i] + ascii_ii[i]; } short int ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 }; short int ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 }; int use_ebcdic (int i) { return ebcdic_mm[i] + ebcdic_ii[i]; } extern int foo; int main () { return use_ascii (foo) == use_ebcdic (foo); ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then ac_cv_c_bigendian=yes fi if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then if test "$ac_cv_c_bigendian" = unknown; then ac_cv_c_bigendian=no else # finding both strings is unlikely to happen, but who knows? ac_cv_c_bigendian=unknown fi fi fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int main () { /* Are we little or big endian? From Harbison&Steele. */ union { long int l; char c[sizeof (long int)]; } u; u.l = 1; return u.c[sizeof (long int) - 1] == 1; ; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_c_bigendian=no else ac_cv_c_bigendian=yes fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_bigendian" >&5 $as_echo "$ac_cv_c_bigendian" >&6; } case $ac_cv_c_bigendian in #( yes) $as_echo "#define WORDS_BIGENDIAN 1" >>confdefs.h ;; #( no) ;; #( universal) $as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h ;; #( *) as_fn_error $? "Machine endianness could not be determined" "$LINENO" 5 ;; esac if test "x$WORDS_BIGENDIAN" = "x"; then NATIVEENDIAN=LittleEndian else NATIVEENDIAN=BigEndian fi for ac_header in byteswap.h do : ac_fn_c_check_header_mongrel "$LINENO" "byteswap.h" "ac_cv_header_byteswap_h" "$ac_includes_default" if test "x$ac_cv_header_byteswap_h" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_BYTESWAP_H 1 _ACEOF BYTESWAP_H='' else BYTESWAP_H='byteswap.h' fi done # checking for ocamlc if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ocamlc", so it can be a program name with args. set dummy ${ac_tool_prefix}ocamlc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_OCAMLC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$OCAMLC"; then ac_cv_prog_OCAMLC="$OCAMLC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_OCAMLC="${ac_tool_prefix}ocamlc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi OCAMLC=$ac_cv_prog_OCAMLC if test -n "$OCAMLC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OCAMLC" >&5 $as_echo "$OCAMLC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_OCAMLC"; then ac_ct_OCAMLC=$OCAMLC # Extract the first word of "ocamlc", so it can be a program name with args. set dummy ocamlc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_OCAMLC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_OCAMLC"; then ac_cv_prog_ac_ct_OCAMLC="$ac_ct_OCAMLC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OCAMLC="ocamlc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_OCAMLC=$ac_cv_prog_ac_ct_OCAMLC if test -n "$ac_ct_OCAMLC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OCAMLC" >&5 $as_echo "$ac_ct_OCAMLC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_OCAMLC" = x; then OCAMLC="no" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OCAMLC=$ac_ct_OCAMLC fi else OCAMLC="$ac_cv_prog_OCAMLC" fi if test "$OCAMLC" != "no"; then OCAMLVERSION=`$OCAMLC -v | sed -n -e 's|.*version* *\(.*\)$|\1|p'` { $as_echo "$as_me:${as_lineno-$LINENO}: result: OCaml version is $OCAMLVERSION" >&5 $as_echo "OCaml version is $OCAMLVERSION" >&6; } # If OCAMLLIB is set, use it if test "$OCAMLLIB" = ""; then OCAMLLIB=`$OCAMLC -where 2>/dev/null || $OCAMLC -v|tail -1|cut -d ' ' -f 4` else { $as_echo "$as_me:${as_lineno-$LINENO}: result: OCAMLLIB previously set; preserving it." >&5 $as_echo "OCAMLLIB previously set; preserving it." >&6; } fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: OCaml library path is $OCAMLLIB" >&5 $as_echo "OCaml library path is $OCAMLLIB" >&6; } # checking for ocamlopt if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ocamlopt", so it can be a program name with args. set dummy ${ac_tool_prefix}ocamlopt; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_OCAMLOPT+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$OCAMLOPT"; then ac_cv_prog_OCAMLOPT="$OCAMLOPT" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_OCAMLOPT="${ac_tool_prefix}ocamlopt" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi OCAMLOPT=$ac_cv_prog_OCAMLOPT if test -n "$OCAMLOPT"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OCAMLOPT" >&5 $as_echo "$OCAMLOPT" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_OCAMLOPT"; then ac_ct_OCAMLOPT=$OCAMLOPT # Extract the first word of "ocamlopt", so it can be a program name with args. set dummy ocamlopt; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_OCAMLOPT+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_OCAMLOPT"; then ac_cv_prog_ac_ct_OCAMLOPT="$ac_ct_OCAMLOPT" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OCAMLOPT="ocamlopt" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_OCAMLOPT=$ac_cv_prog_ac_ct_OCAMLOPT if test -n "$ac_ct_OCAMLOPT"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OCAMLOPT" >&5 $as_echo "$ac_ct_OCAMLOPT" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_OCAMLOPT" = x; then OCAMLOPT="no" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OCAMLOPT=$ac_ct_OCAMLOPT fi else OCAMLOPT="$ac_cv_prog_OCAMLOPT" fi OCAMLBEST=byte if test "$OCAMLOPT" = "no"; then { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Cannot find ocamlopt; bytecode compilation only." >&5 $as_echo "$as_me: WARNING: Cannot find ocamlopt; bytecode compilation only." >&2;} else TMPVERSION=`$OCAMLOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' ` if test "$TMPVERSION" != "$OCAMLVERSION" ; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: versions differs from ocamlc; ocamlopt discarded." >&5 $as_echo "versions differs from ocamlc; ocamlopt discarded." >&6; } OCAMLOPT=no else OCAMLBEST=opt fi fi # checking for ocamlc.opt if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ocamlc.opt", so it can be a program name with args. set dummy ${ac_tool_prefix}ocamlc.opt; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_OCAMLCDOTOPT+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$OCAMLCDOTOPT"; then ac_cv_prog_OCAMLCDOTOPT="$OCAMLCDOTOPT" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_OCAMLCDOTOPT="${ac_tool_prefix}ocamlc.opt" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi OCAMLCDOTOPT=$ac_cv_prog_OCAMLCDOTOPT if test -n "$OCAMLCDOTOPT"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OCAMLCDOTOPT" >&5 $as_echo "$OCAMLCDOTOPT" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_OCAMLCDOTOPT"; then ac_ct_OCAMLCDOTOPT=$OCAMLCDOTOPT # Extract the first word of "ocamlc.opt", so it can be a program name with args. set dummy ocamlc.opt; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_OCAMLCDOTOPT+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_OCAMLCDOTOPT"; then ac_cv_prog_ac_ct_OCAMLCDOTOPT="$ac_ct_OCAMLCDOTOPT" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OCAMLCDOTOPT="ocamlc.opt" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_OCAMLCDOTOPT=$ac_cv_prog_ac_ct_OCAMLCDOTOPT if test -n "$ac_ct_OCAMLCDOTOPT"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OCAMLCDOTOPT" >&5 $as_echo "$ac_ct_OCAMLCDOTOPT" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_OCAMLCDOTOPT" = x; then OCAMLCDOTOPT="no" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OCAMLCDOTOPT=$ac_ct_OCAMLCDOTOPT fi else OCAMLCDOTOPT="$ac_cv_prog_OCAMLCDOTOPT" fi if test "$OCAMLCDOTOPT" != "no"; then TMPVERSION=`$OCAMLCDOTOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' ` if test "$TMPVERSION" != "$OCAMLVERSION" ; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: versions differs from ocamlc; ocamlc.opt discarded." >&5 $as_echo "versions differs from ocamlc; ocamlc.opt discarded." >&6; } else OCAMLC=$OCAMLCDOTOPT fi fi # checking for ocamlopt.opt if test "$OCAMLOPT" != "no" ; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ocamlopt.opt", so it can be a program name with args. set dummy ${ac_tool_prefix}ocamlopt.opt; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_OCAMLOPTDOTOPT+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$OCAMLOPTDOTOPT"; then ac_cv_prog_OCAMLOPTDOTOPT="$OCAMLOPTDOTOPT" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_OCAMLOPTDOTOPT="${ac_tool_prefix}ocamlopt.opt" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi OCAMLOPTDOTOPT=$ac_cv_prog_OCAMLOPTDOTOPT if test -n "$OCAMLOPTDOTOPT"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OCAMLOPTDOTOPT" >&5 $as_echo "$OCAMLOPTDOTOPT" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_OCAMLOPTDOTOPT"; then ac_ct_OCAMLOPTDOTOPT=$OCAMLOPTDOTOPT # Extract the first word of "ocamlopt.opt", so it can be a program name with args. set dummy ocamlopt.opt; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_OCAMLOPTDOTOPT+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_OCAMLOPTDOTOPT"; then ac_cv_prog_ac_ct_OCAMLOPTDOTOPT="$ac_ct_OCAMLOPTDOTOPT" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OCAMLOPTDOTOPT="ocamlopt.opt" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_OCAMLOPTDOTOPT=$ac_cv_prog_ac_ct_OCAMLOPTDOTOPT if test -n "$ac_ct_OCAMLOPTDOTOPT"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OCAMLOPTDOTOPT" >&5 $as_echo "$ac_ct_OCAMLOPTDOTOPT" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_OCAMLOPTDOTOPT" = x; then OCAMLOPTDOTOPT="no" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OCAMLOPTDOTOPT=$ac_ct_OCAMLOPTDOTOPT fi else OCAMLOPTDOTOPT="$ac_cv_prog_OCAMLOPTDOTOPT" fi if test "$OCAMLOPTDOTOPT" != "no"; then TMPVERSION=`$OCAMLOPTDOTOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' ` if test "$TMPVERSION" != "$OCAMLVERSION" ; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: version differs from ocamlc; ocamlopt.opt discarded." >&5 $as_echo "version differs from ocamlc; ocamlopt.opt discarded." >&6; } else OCAMLOPT=$OCAMLOPTDOTOPT fi fi fi fi # checking for ocaml toplevel if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ocaml", so it can be a program name with args. set dummy ${ac_tool_prefix}ocaml; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_OCAML+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$OCAML"; then ac_cv_prog_OCAML="$OCAML" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_OCAML="${ac_tool_prefix}ocaml" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi OCAML=$ac_cv_prog_OCAML if test -n "$OCAML"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OCAML" >&5 $as_echo "$OCAML" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_OCAML"; then ac_ct_OCAML=$OCAML # Extract the first word of "ocaml", so it can be a program name with args. set dummy ocaml; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_OCAML+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_OCAML"; then ac_cv_prog_ac_ct_OCAML="$ac_ct_OCAML" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OCAML="ocaml" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_OCAML=$ac_cv_prog_ac_ct_OCAML if test -n "$ac_ct_OCAML"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OCAML" >&5 $as_echo "$ac_ct_OCAML" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_OCAML" = x; then OCAML="no" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OCAML=$ac_ct_OCAML fi else OCAML="$ac_cv_prog_OCAML" fi # checking for ocamldep if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ocamldep", so it can be a program name with args. set dummy ${ac_tool_prefix}ocamldep; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_OCAMLDEP+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$OCAMLDEP"; then ac_cv_prog_OCAMLDEP="$OCAMLDEP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_OCAMLDEP="${ac_tool_prefix}ocamldep" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi OCAMLDEP=$ac_cv_prog_OCAMLDEP if test -n "$OCAMLDEP"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OCAMLDEP" >&5 $as_echo "$OCAMLDEP" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_OCAMLDEP"; then ac_ct_OCAMLDEP=$OCAMLDEP # Extract the first word of "ocamldep", so it can be a program name with args. set dummy ocamldep; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_OCAMLDEP+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_OCAMLDEP"; then ac_cv_prog_ac_ct_OCAMLDEP="$ac_ct_OCAMLDEP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OCAMLDEP="ocamldep" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_OCAMLDEP=$ac_cv_prog_ac_ct_OCAMLDEP if test -n "$ac_ct_OCAMLDEP"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OCAMLDEP" >&5 $as_echo "$ac_ct_OCAMLDEP" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_OCAMLDEP" = x; then OCAMLDEP="no" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OCAMLDEP=$ac_ct_OCAMLDEP fi else OCAMLDEP="$ac_cv_prog_OCAMLDEP" fi # checking for ocamlmktop if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ocamlmktop", so it can be a program name with args. set dummy ${ac_tool_prefix}ocamlmktop; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_OCAMLMKTOP+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$OCAMLMKTOP"; then ac_cv_prog_OCAMLMKTOP="$OCAMLMKTOP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_OCAMLMKTOP="${ac_tool_prefix}ocamlmktop" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi OCAMLMKTOP=$ac_cv_prog_OCAMLMKTOP if test -n "$OCAMLMKTOP"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OCAMLMKTOP" >&5 $as_echo "$OCAMLMKTOP" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_OCAMLMKTOP"; then ac_ct_OCAMLMKTOP=$OCAMLMKTOP # Extract the first word of "ocamlmktop", so it can be a program name with args. set dummy ocamlmktop; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_OCAMLMKTOP+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_OCAMLMKTOP"; then ac_cv_prog_ac_ct_OCAMLMKTOP="$ac_ct_OCAMLMKTOP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OCAMLMKTOP="ocamlmktop" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_OCAMLMKTOP=$ac_cv_prog_ac_ct_OCAMLMKTOP if test -n "$ac_ct_OCAMLMKTOP"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OCAMLMKTOP" >&5 $as_echo "$ac_ct_OCAMLMKTOP" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_OCAMLMKTOP" = x; then OCAMLMKTOP="no" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OCAMLMKTOP=$ac_ct_OCAMLMKTOP fi else OCAMLMKTOP="$ac_cv_prog_OCAMLMKTOP" fi # checking for ocamlmklib if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ocamlmklib", so it can be a program name with args. set dummy ${ac_tool_prefix}ocamlmklib; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_OCAMLMKLIB+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$OCAMLMKLIB"; then ac_cv_prog_OCAMLMKLIB="$OCAMLMKLIB" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_OCAMLMKLIB="${ac_tool_prefix}ocamlmklib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi OCAMLMKLIB=$ac_cv_prog_OCAMLMKLIB if test -n "$OCAMLMKLIB"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OCAMLMKLIB" >&5 $as_echo "$OCAMLMKLIB" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_OCAMLMKLIB"; then ac_ct_OCAMLMKLIB=$OCAMLMKLIB # Extract the first word of "ocamlmklib", so it can be a program name with args. set dummy ocamlmklib; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_OCAMLMKLIB+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_OCAMLMKLIB"; then ac_cv_prog_ac_ct_OCAMLMKLIB="$ac_ct_OCAMLMKLIB" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OCAMLMKLIB="ocamlmklib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_OCAMLMKLIB=$ac_cv_prog_ac_ct_OCAMLMKLIB if test -n "$ac_ct_OCAMLMKLIB"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OCAMLMKLIB" >&5 $as_echo "$ac_ct_OCAMLMKLIB" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_OCAMLMKLIB" = x; then OCAMLMKLIB="no" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OCAMLMKLIB=$ac_ct_OCAMLMKLIB fi else OCAMLMKLIB="$ac_cv_prog_OCAMLMKLIB" fi # checking for ocamldoc if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ocamldoc", so it can be a program name with args. set dummy ${ac_tool_prefix}ocamldoc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_OCAMLDOC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$OCAMLDOC"; then ac_cv_prog_OCAMLDOC="$OCAMLDOC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_OCAMLDOC="${ac_tool_prefix}ocamldoc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi OCAMLDOC=$ac_cv_prog_OCAMLDOC if test -n "$OCAMLDOC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OCAMLDOC" >&5 $as_echo "$OCAMLDOC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_OCAMLDOC"; then ac_ct_OCAMLDOC=$OCAMLDOC # Extract the first word of "ocamldoc", so it can be a program name with args. set dummy ocamldoc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_OCAMLDOC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_OCAMLDOC"; then ac_cv_prog_ac_ct_OCAMLDOC="$ac_ct_OCAMLDOC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OCAMLDOC="ocamldoc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_OCAMLDOC=$ac_cv_prog_ac_ct_OCAMLDOC if test -n "$ac_ct_OCAMLDOC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OCAMLDOC" >&5 $as_echo "$ac_ct_OCAMLDOC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_OCAMLDOC" = x; then OCAMLDOC="no" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OCAMLDOC=$ac_ct_OCAMLDOC fi else OCAMLDOC="$ac_cv_prog_OCAMLDOC" fi # checking for ocamlbuild if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ocamlbuild", so it can be a program name with args. set dummy ${ac_tool_prefix}ocamlbuild; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_OCAMLBUILD+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$OCAMLBUILD"; then ac_cv_prog_OCAMLBUILD="$OCAMLBUILD" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_OCAMLBUILD="${ac_tool_prefix}ocamlbuild" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi OCAMLBUILD=$ac_cv_prog_OCAMLBUILD if test -n "$OCAMLBUILD"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OCAMLBUILD" >&5 $as_echo "$OCAMLBUILD" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_OCAMLBUILD"; then ac_ct_OCAMLBUILD=$OCAMLBUILD # Extract the first word of "ocamlbuild", so it can be a program name with args. set dummy ocamlbuild; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_OCAMLBUILD+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_OCAMLBUILD"; then ac_cv_prog_ac_ct_OCAMLBUILD="$ac_ct_OCAMLBUILD" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OCAMLBUILD="ocamlbuild" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_OCAMLBUILD=$ac_cv_prog_ac_ct_OCAMLBUILD if test -n "$ac_ct_OCAMLBUILD"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OCAMLBUILD" >&5 $as_echo "$ac_ct_OCAMLBUILD" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_OCAMLBUILD" = x; then OCAMLBUILD="no" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OCAMLBUILD=$ac_ct_OCAMLBUILD fi else OCAMLBUILD="$ac_cv_prog_OCAMLBUILD" fi # checking for ocamlfind if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ocamlfind", so it can be a program name with args. set dummy ${ac_tool_prefix}ocamlfind; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_OCAMLFIND+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$OCAMLFIND"; then ac_cv_prog_OCAMLFIND="$OCAMLFIND" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_OCAMLFIND="${ac_tool_prefix}ocamlfind" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi OCAMLFIND=$ac_cv_prog_OCAMLFIND if test -n "$OCAMLFIND"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OCAMLFIND" >&5 $as_echo "$OCAMLFIND" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_OCAMLFIND"; then ac_ct_OCAMLFIND=$OCAMLFIND # Extract the first word of "ocamlfind", so it can be a program name with args. set dummy ocamlfind; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_OCAMLFIND+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_OCAMLFIND"; then ac_cv_prog_ac_ct_OCAMLFIND="$ac_ct_OCAMLFIND" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OCAMLFIND="ocamlfind" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_OCAMLFIND=$ac_cv_prog_ac_ct_OCAMLFIND if test -n "$ac_ct_OCAMLFIND"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OCAMLFIND" >&5 $as_echo "$ac_ct_OCAMLFIND" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_OCAMLFIND" = x; then OCAMLFIND="no" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OCAMLFIND=$ac_ct_OCAMLFIND fi else OCAMLFIND="$ac_cv_prog_OCAMLFIND" fi if test "x$OCAMLFIND" = "x"; then as_fn_error $? "You must have ocaml and findlib installed" "$LINENO" 5 fi # Extract the first word of "camlp4of.opt", so it can be a program name with args. set dummy camlp4of.opt; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CAMLP4OF+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CAMLP4OF"; then ac_cv_prog_CAMLP4OF="$CAMLP4OF" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CAMLP4OF="camlp4of.opt" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS test -z "$ac_cv_prog_CAMLP4OF" && ac_cv_prog_CAMLP4OF="no" fi fi CAMLP4OF=$ac_cv_prog_CAMLP4OF if test -n "$CAMLP4OF"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CAMLP4OF" >&5 $as_echo "$CAMLP4OF" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$CAMLP4OF" = "xno"; then as_fn_error $? "You must have camlp4 installed" "$LINENO" 5 fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for OCaml findlib package extlib" >&5 $as_echo_n "checking for OCaml findlib package extlib... " >&6; } unset found unset pkg found=no for pkg in extlib ; do if $OCAMLFIND query $pkg >/dev/null 2>/dev/null; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: found" >&5 $as_echo "found" >&6; } OCAML_PKG_extlib=$pkg found=yes break fi done if test "$found" = "no" ; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5 $as_echo "not found" >&6; } OCAML_PKG_extlib=no fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for OCaml findlib package cil" >&5 $as_echo_n "checking for OCaml findlib package cil... " >&6; } unset found unset pkg found=no for pkg in cil ; do if $OCAMLFIND query $pkg >/dev/null 2>/dev/null; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: found" >&5 $as_echo "found" >&6; } OCAML_PKG_cil=$pkg found=yes break fi done if test "$found" = "no" ; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5 $as_echo "not found" >&6; } OCAML_PKG_cil=no fi # Extract the first word of "time", so it can be a program name with args. set dummy time; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_path_TIME+:} false; then : $as_echo_n "(cached) " >&6 else case $TIME in [\\/]* | ?:[\\/]*) ac_cv_path_TIME="$TIME" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_path_TIME="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS test -z "$ac_cv_path_TIME" && ac_cv_path_TIME="no" ;; esac fi TIME=$ac_cv_path_TIME if test -n "$TIME"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $TIME" >&5 $as_echo "$TIME" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$TIME" = "xno"; then as_fn_error $? "'time' command not found" "$LINENO" 5 fi # Extract the first word of "diff", so it can be a program name with args. set dummy diff; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_path_DIFF+:} false; then : $as_echo_n "(cached) " >&6 else case $DIFF in [\\/]* | ?:[\\/]*) ac_cv_path_DIFF="$DIFF" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_path_DIFF="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS test -z "$ac_cv_path_DIFF" && ac_cv_path_DIFF="no" ;; esac fi DIFF=$ac_cv_path_DIFF if test -n "$DIFF"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DIFF" >&5 $as_echo "$DIFF" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$DIFF" = "xno"; then as_fn_error $? "'diff' command not found" "$LINENO" 5 fi # Extract the first word of "gprof", so it can be a program name with args. set dummy gprof; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_GPROF+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$GPROF"; then ac_cv_prog_GPROF="$GPROF" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_GPROF="gprof" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS test -z "$ac_cv_prog_GPROF" && ac_cv_prog_GPROF="no" fi fi GPROF=$ac_cv_prog_GPROF if test -n "$GPROF"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GPROF" >&5 $as_echo "$GPROF" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi # Extract the first word of "bisect-report", so it can be a program name with args. set dummy bisect-report; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_BISECT_REPORT+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$BISECT_REPORT"; then ac_cv_prog_BISECT_REPORT="$BISECT_REPORT" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_BISECT_REPORT="bisect-report" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS test -z "$ac_cv_prog_BISECT_REPORT" && ac_cv_prog_BISECT_REPORT="no" fi fi BISECT_REPORT=$ac_cv_prog_BISECT_REPORT if test -n "$BISECT_REPORT"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $BISECT_REPORT" >&5 $as_echo "$BISECT_REPORT" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi # Check whether --enable-coverage was given. if test "${enable_coverage+set}" = set; then : enableval=$enable_coverage; else enable_coverage=no fi if test "x$enable_coverage" != "xno" -a "x$BISECT_REPORT" = "xno"; then as_fn_error $? "You must install ocaml-bisect package to get code coverage" "$LINENO" 5 fi ac_config_headers="$ac_config_headers config.h" ac_config_files="$ac_config_files Makefile META bitstring_config.ml cil-tools/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure # scripts and configure runs, see configure's option --config-cache. # It is not useful on other systems. If it contains results you don't # want to keep, you may remove or edit it. # # config.status only pays attention to the cache file if you give it # the --recheck option to rerun configure. # # `ac_cv_env_foo' variables (set or unset) will be overridden when # loading this file, other *unset* `ac_cv_foo' will be assigned the # following values. _ACEOF # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. # So, we kill variables containing newlines. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. ( for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space=' '; set) 2>&1` in #( *${as_nl}ac_space=\ *) # `set' does not quote correctly, so add quotes: double-quote # substitution turns \\\\ into \\, and sed turns \\ into \. sed -n \ "s/'/'\\\\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" ;; #( *) # `set' quotes correctly as required by POSIX, so do not add quotes. sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) | sed ' /^ac_cv_env_/b end t clear :clear s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ t end s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ :end' >>confcache if diff "$cache_file" confcache >/dev/null 2>&1; then :; else if test -w "$cache_file"; then if test "x$cache_file" != "x/dev/null"; then { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 $as_echo "$as_me: updating cache $cache_file" >&6;} if test ! -f "$cache_file" || test -h "$cache_file"; then cat confcache >"$cache_file" else case $cache_file in #( */* | ?:*) mv -f confcache "$cache_file"$$ && mv -f "$cache_file"$$ "$cache_file" ;; #( *) mv -f confcache "$cache_file" ;; esac fi fi else { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 $as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' DEFS=-DHAVE_CONFIG_H ac_libobjs= ac_ltlibobjs= U= for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue # 1. Remove the extension, and $U if already installed. ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' ac_i=`$as_echo "$ac_i" | sed "$ac_script"` # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR # will be set to the directory where LIBOBJS objects are built. as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' done LIBOBJS=$ac_libobjs LTLIBOBJS=$ac_ltlibobjs : "${CONFIG_STATUS=./config.status}" ac_write_fail=0 ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files $CONFIG_STATUS" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 $as_echo "$as_me: creating $CONFIG_STATUS" >&6;} as_write_fail=0 cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 #! $SHELL # Generated by $as_me. # Run this file to recreate the current configuration. # Compiler output produced by configure, useful for debugging # configure, is in config.log if it exists. debug=false ac_cs_recheck=false ac_cs_silent=false SHELL=\${CONFIG_SHELL-$SHELL} export SHELL _ASEOF cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" exec 6>&1 ## ----------------------------------- ## ## Main body of $CONFIG_STATUS script. ## ## ----------------------------------- ## _ASEOF test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Save the log message, to keep $0 and so on meaningful, and to # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" This file was extended by ocaml-bitstring $as_me 2.0.4, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS CONFIG_LINKS = $CONFIG_LINKS CONFIG_COMMANDS = $CONFIG_COMMANDS $ $0 $@ on `(hostname || uname -n) 2>/dev/null | sed 1q` " _ACEOF case $ac_config_files in *" "*) set x $ac_config_files; shift; ac_config_files=$*;; esac case $ac_config_headers in *" "*) set x $ac_config_headers; shift; ac_config_headers=$*;; esac cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 # Files that config.status was made for. config_files="$ac_config_files" config_headers="$ac_config_headers" _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 ac_cs_usage="\ \`$as_me' instantiates files and other configuration actions from templates according to the current configuration. Unless the files and actions are specified as TAGs, all are instantiated by default. Usage: $0 [OPTION]... [TAG]... -h, --help print this help, then exit -V, --version print version number and configuration settings, then exit --config print configuration, then exit -q, --quiet, --silent do not print progress messages -d, --debug don't remove temporary files --recheck update $as_me by reconfiguring in the same conditions --file=FILE[:TEMPLATE] instantiate the configuration file FILE --header=FILE[:TEMPLATE] instantiate the configuration header FILE Configuration files: $config_files Configuration headers: $config_headers Report bugs to the package provider." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ ocaml-bitstring config.status 2.0.4 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" Copyright (C) 2012 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." ac_pwd='$ac_pwd' srcdir='$srcdir' INSTALL='$INSTALL' test -n "\$AWK" || AWK=awk _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # The default lists apply if the user does not specify any file. ac_need_defaults=: while test $# != 0 do case $1 in --*=?*) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` ac_shift=: ;; --*=) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg= ac_shift=: ;; *) ac_option=$1 ac_optarg=$2 ac_shift=shift ;; esac case $ac_option in # Handling of the options. -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) ac_cs_recheck=: ;; --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) $as_echo "$ac_cs_version"; exit ;; --config | --confi | --conf | --con | --co | --c ) $as_echo "$ac_cs_config"; exit ;; --debug | --debu | --deb | --de | --d | -d ) debug=: ;; --file | --fil | --fi | --f ) $ac_shift case $ac_optarg in *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; '') as_fn_error $? "missing file argument" ;; esac as_fn_append CONFIG_FILES " '$ac_optarg'" ac_need_defaults=false;; --header | --heade | --head | --hea ) $ac_shift case $ac_optarg in *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; esac as_fn_append CONFIG_HEADERS " '$ac_optarg'" ac_need_defaults=false;; --he | --h) # Conflict between --help and --header as_fn_error $? "ambiguous option: \`$1' Try \`$0 --help' for more information.";; --help | --hel | -h ) $as_echo "$ac_cs_usage"; exit ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil | --si | --s) ac_cs_silent=: ;; # This is an error. -*) as_fn_error $? "unrecognized option: \`$1' Try \`$0 --help' for more information." ;; *) as_fn_append ac_config_targets " $1" ac_need_defaults=false ;; esac shift done ac_configure_extra_args= if $ac_cs_silent; then exec 6>/dev/null ac_configure_extra_args="$ac_configure_extra_args --silent" fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' export CONFIG_SHELL exec "\$@" fi _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 exec 5>>config.log { echo sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX ## Running $as_me. ## _ASBOX $as_echo "$ac_log" } >&5 _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Handling of arguments. for ac_config_target in $ac_config_targets do case $ac_config_target in "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; "META") CONFIG_FILES="$CONFIG_FILES META" ;; "bitstring_config.ml") CONFIG_FILES="$CONFIG_FILES bitstring_config.ml" ;; "cil-tools/Makefile") CONFIG_FILES="$CONFIG_FILES cil-tools/Makefile" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; esac done # If the user did not use the arguments to specify the items to instantiate, # then the envvar interface is used. Set only those that are not. # We use the long form for the default assignment because of an extremely # bizarre bug on SunOS 4.1.3. if $ac_need_defaults; then test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers fi # Have a temporary directory for convenience. Make it in the build tree # simply because there is no reason against having it here, and in addition, # creating and moving files from /tmp can sometimes cause problems. # Hook for its removal unless debugging. # Note that there is a small window in which the directory will not be cleaned: # after its creation but before its name has been assigned to `$tmp'. $debug || { tmp= ac_tmp= trap 'exit_status=$? : "${ac_tmp:=$tmp}" { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status ' 0 trap 'as_fn_exit 1' 1 2 13 15 } # Create a (secure) tmp directory for tmp files. { tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && test -d "$tmp" } || { tmp=./conf$$-$RANDOM (umask 077 && mkdir "$tmp") } || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 ac_tmp=$tmp # Set up the scripts for CONFIG_FILES section. # No need to generate them if there are no CONFIG_FILES. # This happens for instance with `./config.status config.h'. if test -n "$CONFIG_FILES"; then ac_cr=`echo X | tr X '\015'` # On cygwin, bash can eat \r inside `` if the user requested igncr. # But we know of no other shell where ac_cr would be empty at this # point, so we can use a bashism as a fallback. if test "x$ac_cr" = x; then eval ac_cr=\$\'\\r\' fi ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then ac_cs_awk_cr='\\r' else ac_cs_awk_cr=$ac_cr fi echo 'BEGIN {' >"$ac_tmp/subs1.awk" && _ACEOF { echo "cat >conf$$subs.awk <<_ACEOF" && echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && echo "_ACEOF" } >conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` ac_delim='%!_!# ' for ac_last_try in false false false false false :; do . ./conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` if test $ac_delim_n = $ac_delim_num; then break elif $ac_last_try; then as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 else ac_delim="$ac_delim!$ac_delim _$ac_delim!! " fi done rm -f conf$$subs.sh cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK && _ACEOF sed -n ' h s/^/S["/; s/!.*/"]=/ p g s/^[^!]*!// :repl t repl s/'"$ac_delim"'$// t delim :nl h s/\(.\{148\}\)..*/\1/ t more1 s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ p n b repl :more1 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t nl :delim h s/\(.\{148\}\)..*/\1/ t more2 s/["\\]/\\&/g; s/^/"/; s/$/"/ p b :more2 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t delim ' >$CONFIG_STATUS || ac_write_fail=1 rm -f conf$$subs.awk cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACAWK cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && for (key in S) S_is_set[key] = 1 FS = "" } { line = $ 0 nfields = split(line, field, "@") substed = 0 len = length(field[1]) for (i = 2; i < nfields; i++) { key = field[i] keylen = length(key) if (S_is_set[key]) { value = S[key] line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) len += length(value) + length(field[++i]) substed = 1 } else len += 1 + keylen } print line } _ACAWK _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" else cat fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \ || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 _ACEOF # VPATH may cause trouble with some makes, so we remove sole $(srcdir), # ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and # trailing colons and then remove the whole line if VPATH becomes empty # (actually we leave an empty line to preserve line numbers). if test "x$srcdir" = x.; then ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ h s/// s/^/:/ s/[ ]*$/:/ s/:\$(srcdir):/:/g s/:\${srcdir}:/:/g s/:@srcdir@:/:/g s/^:*// s/:*$// x s/\(=[ ]*\).*/\1/ G s/\n// s/^[^=]*=[ ]*$// }' fi cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 fi # test -n "$CONFIG_FILES" # Set up the scripts for CONFIG_HEADERS section. # No need to generate them if there are no CONFIG_HEADERS. # This happens for instance with `./config.status Makefile'. if test -n "$CONFIG_HEADERS"; then cat >"$ac_tmp/defines.awk" <<\_ACAWK || BEGIN { _ACEOF # Transform confdefs.h into an awk script `defines.awk', embedded as # here-document in config.status, that substitutes the proper values into # config.h.in to produce config.h. # Create a delimiter string that does not exist in confdefs.h, to ease # handling of long lines. ac_delim='%!_!# ' for ac_last_try in false false :; do ac_tt=`sed -n "/$ac_delim/p" confdefs.h` if test -z "$ac_tt"; then break elif $ac_last_try; then as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5 else ac_delim="$ac_delim!$ac_delim _$ac_delim!! " fi done # For the awk script, D is an array of macro values keyed by name, # likewise P contains macro parameters if any. Preserve backslash # newline sequences. ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]* sed -n ' s/.\{148\}/&'"$ac_delim"'/g t rset :rset s/^[ ]*#[ ]*define[ ][ ]*/ / t def d :def s/\\$// t bsnl s/["\\]/\\&/g s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ D["\1"]=" \3"/p s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p d :bsnl s/["\\]/\\&/g s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ D["\1"]=" \3\\\\\\n"\\/p t cont s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p t cont d :cont n s/.\{148\}/&'"$ac_delim"'/g t clear :clear s/\\$// t bsnlc s/["\\]/\\&/g; s/^/"/; s/$/"/p d :bsnlc s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p b cont ' >$CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 for (key in D) D_is_set[key] = 1 FS = "" } /^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ { line = \$ 0 split(line, arg, " ") if (arg[1] == "#") { defundef = arg[2] mac1 = arg[3] } else { defundef = substr(arg[1], 2) mac1 = arg[2] } split(mac1, mac2, "(") #) macro = mac2[1] prefix = substr(line, 1, index(line, defundef) - 1) if (D_is_set[macro]) { # Preserve the white space surrounding the "#". print prefix "define", macro P[macro] D[macro] next } else { # Replace #undef with comments. This is necessary, for example, # in the case of _POSIX_SOURCE, which is predefined and required # on some systems where configure will not decide to define it. if (defundef == "undef") { print "/*", prefix defundef, macro, "*/" next } } } { print } _ACAWK _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 as_fn_error $? "could not setup config headers machinery" "$LINENO" 5 fi # test -n "$CONFIG_HEADERS" eval set X " :F $CONFIG_FILES :H $CONFIG_HEADERS " shift for ac_tag do case $ac_tag in :[FHLC]) ac_mode=$ac_tag; continue;; esac case $ac_mode$ac_tag in :[FHL]*:*);; :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; :[FH]-) ac_tag=-:-;; :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; esac ac_save_IFS=$IFS IFS=: set x $ac_tag IFS=$ac_save_IFS shift ac_file=$1 shift case $ac_mode in :L) ac_source=$1;; :[FH]) ac_file_inputs= for ac_f do case $ac_f in -) ac_f="$ac_tmp/stdin";; *) # Look for the file first in the build tree, then in the source tree # (if the path is not absolute). The absolute path cannot be DOS-style, # because $ac_f cannot contain `:'. test -f "$ac_f" || case $ac_f in [\\/$]*) false;; *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; esac || as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; esac case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append ac_file_inputs " '$ac_f'" done # Let's still pretend it is `configure' which instantiates (i.e., don't # use $as_me), people would be surprised to read: # /* config.h. Generated by config.status. */ configure_input='Generated from '` $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' `' by configure.' if test x"$ac_file" != x-; then configure_input="$ac_file. $configure_input" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 $as_echo "$as_me: creating $ac_file" >&6;} fi # Neutralize special characters interpreted by sed in replacement strings. case $configure_input in #( *\&* | *\|* | *\\* ) ac_sed_conf_input=`$as_echo "$configure_input" | sed 's/[\\\\&|]/\\\\&/g'`;; #( *) ac_sed_conf_input=$configure_input;; esac case $ac_tag in *:-:* | *:-) cat >"$ac_tmp/stdin" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; esac ;; esac ac_dir=`$as_dirname -- "$ac_file" || $as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$ac_file" : 'X\(//\)[^/]' \| \ X"$ac_file" : 'X\(//\)$' \| \ X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$ac_file" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` as_dir="$ac_dir"; as_fn_mkdir_p ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix case $ac_mode in :F) # # CONFIG_FILE # case $INSTALL in [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; esac _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # If the template does not know about datarootdir, expand it. # FIXME: This hack should be removed a few years after 2.60. ac_datarootdir_hack=; ac_datarootdir_seen= ac_sed_dataroot=' /datarootdir/ { p q } /@datadir@/p /@docdir@/p /@infodir@/p /@localedir@/p /@mandir@/p' case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in *datarootdir*) ac_datarootdir_seen=yes;; *@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 $as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_datarootdir_hack=' s&@datadir@&$datadir&g s&@docdir@&$docdir&g s&@infodir@&$infodir&g s&@localedir@&$localedir&g s&@mandir@&$mandir&g s&\\\${datarootdir}&$datarootdir&g' ;; esac _ACEOF # Neutralize VPATH when `$srcdir' = `.'. # Shell code in configure.ac might set extrasub. # FIXME: do we really want to maintain this feature? cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_sed_extra="$ac_vpsub $extrasub _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 :t /@[a-zA-Z_][a-zA-Z_0-9]*@/!b s|@configure_input@|$ac_sed_conf_input|;t t s&@top_builddir@&$ac_top_builddir_sub&;t t s&@top_build_prefix@&$ac_top_build_prefix&;t t s&@srcdir@&$ac_srcdir&;t t s&@abs_srcdir@&$ac_abs_srcdir&;t t s&@top_srcdir@&$ac_top_srcdir&;t t s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t s&@builddir@&$ac_builddir&;t t s&@abs_builddir@&$ac_abs_builddir&;t t s&@abs_top_builddir@&$ac_abs_top_builddir&;t t s&@INSTALL@&$ac_INSTALL&;t t $ac_datarootdir_hack " eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ "$ac_tmp/out"`; test -z "$ac_out"; } && { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&5 $as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&2;} rm -f "$ac_tmp/stdin" case $ac_file in -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";; *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; esac \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; :H) # # CONFIG_HEADER # if test x"$ac_file" != x-; then { $as_echo "/* $configure_input */" \ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" } >"$ac_tmp/config.h" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 $as_echo "$as_me: $ac_file is unchanged" >&6;} else rm -f "$ac_file" mv "$ac_tmp/config.h" "$ac_file" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 fi else $as_echo "/* $configure_input */" \ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \ || as_fn_error $? "could not create -" "$LINENO" 5 fi ;; esac done # for ac_tag as_fn_exit 0 _ACEOF ac_clean_files=$ac_clean_files_save test $ac_write_fail = 0 || as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 # configure is writing to config.log, and then calls config.status. # config.status does its own redirection, appending to config.log. # Unfortunately, on DOS this fails, as config.log is still kept open # by configure, so config.status won't be able to write to it; its # output is simply discarded. So we exec the FD to /dev/null, # effectively closing config.log, so it can be properly (re)opened and # appended to by config.status. When coming back to configure, we # need to make the FD available again. if test "$no_create" != yes; then ac_cs_success=: ac_config_status_args= test "$silent" = yes && ac_config_status_args="$ac_config_status_args --quiet" exec 5>/dev/null $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false exec 5>>config.log # Use ||, not &&, to avoid exiting from the if with $? = 1, which # would make configure fail if this is the last instruction. $ac_cs_success || as_fn_exit 1 fi if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi ocaml-bitstring-2.0.4/CHANGES0000664000175000017500000017536412144457304015216 0ustar rjonesrjones------------------------------------------------------------------------ r197 | richard.wm.jones@gmail.com | 2012-08-10 12:52:44 +0100 (Fri, 10 Aug 2012) | 1 line Changed paths: M /trunk/Makefile.in M /trunk/configure.ac Stable OCaml dependencies. ------------------------------------------------------------------------ r196 | richard.wm.jones@gmail.com | 2012-08-10 12:44:18 +0100 (Fri, 10 Aug 2012) | 31 lines Changed paths: M /trunk/bitstring_c.c Fix memory leaks and alignment issues (thanks rixed at happyleptic.org) First one: a huge memory leak when bitmatching on int64. The reason is that on my arch (MIPS), which is a ARCH_ALIGN_INT64 arch, the function to extract int64 calls caml_copy_int64 but you are not supposed to do that since all functions are declared noalloc (should segfault but merely leaks memory on my program). See this message of Xavier for more explanations as to why it's a bug: http://caml.inria.fr/pub/ml-archives/caml-list/2010/03/2e386c384c04f4a424acc44a1 fae3abd.en.html So the easy fix would be to remove the noallocs for the int64 functions, but there is a better way around the issue: instead of assigning a int64 onto a possibly non 8 bytes aligned memory location we can merely memcpy the value in there, thus avoiding the extra allocation and the caml_c_call wrapper. While looking at this I stumbled upon the other bug: bitstring_c.c extract values by assigning a casted rvalue into a properly stack-allocated local variable. You cannot do that, this is undefined behavior since it assumes that unaligned reads are permitted. Again, on my MIPS such unaligned access are (by default) diverted to an exception handler which (slowly!) fix them on the fly (one can see the errorcount in /proc/kernel/debug/mips/unaligned_instructions), but on other archs it could as well result in a sigbus. I believe this would be a problem on ARM as well. Again, memcpy comes to the rescue. The attached patch fixes both issues. ------------------------------------------------------------------------ r195 | richard.wm.jones@gmail.com | 2012-07-20 09:06:08 +0100 (Fri, 20 Jul 2012) | 3 lines Changed paths: M /trunk/META.in META: Add -parser and -printer options. ------------------------------------------------------------------------ r194 | richard.wm.jones@gmail.com | 2012-04-04 10:40:42 +0100 (Wed, 04 Apr 2012) | 4 lines Changed paths: M /trunk/bitstring.ml takebits/dropbits: check that n >= 0 http://code.google.com/p/bitstring/issues/detail?id=18 ------------------------------------------------------------------------ r193 | richard.wm.jones@gmail.com | 2012-03-30 13:49:30 +0100 (Fri, 30 Mar 2012) | 4 lines Changed paths: M /trunk/bitstring.ml Permissive subbitstring allows a segmentation fault (issue #16). Fix by mrvn. ------------------------------------------------------------------------ r192 | richard.wm.jones@gmail.com | 2012-01-17 13:24:46 +0000 (Tue, 17 Jan 2012) | 3 lines Changed paths: M /trunk/MANIFEST Update MANIFEST. ------------------------------------------------------------------------ r191 | richard.wm.jones@gmail.com | 2012-01-17 13:21:57 +0000 (Tue, 17 Jan 2012) | 3 lines Changed paths: M /trunk/.depend M /trunk/configure.ac Version 2.0.3. ------------------------------------------------------------------------ r190 | richard.wm.jones@gmail.com | 2012-01-17 13:20:53 +0000 (Tue, 17 Jan 2012) | 5 lines Changed paths: M /trunk/bitstring.ml A /trunk/tests/test_91_concat.ml Fix concatenation of non-aligned bitstrings (thanks Phil Tomson). This commit includes a regression test. ------------------------------------------------------------------------ r189 | richard.wm.jones@gmail.com | 2012-01-17 13:02:18 +0000 (Tue, 17 Jan 2012) | 5 lines Changed paths: M /trunk/pa_bitstring.ml A /trunk/tests/test_90_bind_as.ml In a '{...} as foo' binding, save the original bitstring offset and length as 'foo'. Before we were saving the running offset and length. This commit also adds a regression test. (Bug found by Matej Kosik). ------------------------------------------------------------------------ r188 | richard.wm.jones@gmail.com | 2012-01-17 12:44:36 +0000 (Tue, 17 Jan 2012) | 3 lines Changed paths: M /trunk/Makefile.in M /trunk/README Add 'make check' as a synonym for 'make test'. ------------------------------------------------------------------------ r187 | richard.wm.jones@gmail.com | 2012-01-17 12:39:09 +0000 (Tue, 17 Jan 2012) | 3 lines Changed paths: D /trunk/tests/01_load.ml D /trunk/tests/02_run.ml D /trunk/tests/10_match_bits.ml D /trunk/tests/11_match_ints.ml D /trunk/tests/15_extract_int.ml D /trunk/tests/18_extract_32_64_int.ml D /trunk/tests/20_varsize.ml D /trunk/tests/30_bitbuffer.ml D /trunk/tests/31_bitstring_concat.ml D /trunk/tests/32_bitstring_compare.ml D /trunk/tests/33_substring.ml D /trunk/tests/34_takebits.ml D /trunk/tests/35_load_from_file.ml D /trunk/tests/40_endianexpr.ml D /trunk/tests/50_named_pattern.ml D /trunk/tests/51_open_pattern.ml D /trunk/tests/60_simple_offset.ml D /trunk/tests/61_offset_string.ml D /trunk/tests/62_offset_padding.ml D /trunk/tests/65_save_offset_to.ml D /trunk/tests/70_check_and_bind.ml D /trunk/tests/80_hexdump.ml A /trunk/tests/test_01_load.ml (from /trunk/tests/01_load.ml:186) A /trunk/tests/test_02_run.ml (from /trunk/tests/02_run.ml:186) A /trunk/tests/test_10_match_bits.ml (from /trunk/tests/10_match_bits.ml:186) A /trunk/tests/test_11_match_ints.ml (from /trunk/tests/11_match_ints.ml:186) A /trunk/tests/test_15_extract_int.ml (from /trunk/tests/15_extract_int.ml:186) A /trunk/tests/test_18_extract_32_64_int.ml (from /trunk/tests/18_extract_32_64_int.ml:186) A /trunk/tests/test_20_varsize.ml (from /trunk/tests/20_varsize.ml:186) A /trunk/tests/test_30_bitbuffer.ml (from /trunk/tests/30_bitbuffer.ml:186) A /trunk/tests/test_31_bitstring_concat.ml (from /trunk/tests/31_bitstring_concat.ml:186) A /trunk/tests/test_32_bitstring_compare.ml (from /trunk/tests/32_bitstring_compare.ml:186) A /trunk/tests/test_33_substring.ml (from /trunk/tests/33_substring.ml:186) A /trunk/tests/test_34_takebits.ml (from /trunk/tests/34_takebits.ml:186) A /trunk/tests/test_35_load_from_file.ml (from /trunk/tests/35_load_from_file.ml:186) A /trunk/tests/test_40_endianexpr.ml (from /trunk/tests/40_endianexpr.ml:186) A /trunk/tests/test_50_named_pattern.ml (from /trunk/tests/50_named_pattern.ml:186) A /trunk/tests/test_51_open_pattern.ml (from /trunk/tests/51_open_pattern.ml:186) A /trunk/tests/test_60_simple_offset.ml (from /trunk/tests/60_simple_offset.ml:186) A /trunk/tests/test_61_offset_string.ml (from /trunk/tests/61_offset_string.ml:186) A /trunk/tests/test_62_offset_padding.ml (from /trunk/tests/62_offset_padding.ml:186) A /trunk/tests/test_65_save_offset_to.ml (from /trunk/tests/65_save_offset_to.ml:186) A /trunk/tests/test_70_check_and_bind.ml (from /trunk/tests/70_check_and_bind.ml:186) A /trunk/tests/test_80_hexdump.ml (from /trunk/tests/80_hexdump.ml:186) Rename test programs so the name is a valid OCaml module name. ------------------------------------------------------------------------ r186 | richard.wm.jones | 2010-02-05 14:01:53 +0000 (Fri, 05 Feb 2010) | 2 lines Changed paths: M /trunk/TODO TODO: Added more suggested features based on feedback from hivex. ------------------------------------------------------------------------ r185 | richard.wm.jones | 2010-01-11 13:05:01 +0000 (Mon, 11 Jan 2010) | 2 lines Changed paths: M /trunk/META.in Fix issue 5: Bitstring cannot be used with other syntax extensions when using ocamlfind ------------------------------------------------------------------------ r184 | richard.wm.jones | 2010-01-08 15:13:13 +0000 (Fri, 08 Jan 2010) | 1 line Changed paths: M /trunk/configure.ac Version 2.0.2 for release. ------------------------------------------------------------------------ r183 | richard.wm.jones | 2010-01-08 15:10:04 +0000 (Fri, 08 Jan 2010) | 2 lines Changed paths: M /trunk/Makefile.in M /trunk/configure.ac Fix handling of OCAML_PKG_* macros for new OCaml autoconf. ------------------------------------------------------------------------ r182 | richard.wm.jones | 2010-01-08 14:44:42 +0000 (Fri, 08 Jan 2010) | 2 lines Changed paths: M /trunk/configure.ac Version 2.0.1 for release. ------------------------------------------------------------------------ r181 | richard.wm.jones | 2010-01-08 14:43:45 +0000 (Fri, 08 Jan 2010) | 2 lines Changed paths: M /trunk/cil-tools/ext3.c CIL example: is now required for ------------------------------------------------------------------------ r180 | richard.wm.jones | 2010-01-08 14:43:07 +0000 (Fri, 08 Jan 2010) | 2 lines Changed paths: M /trunk/cil-tools/Makefile.in CIL: Include dynlink for OCaml 3.11. ------------------------------------------------------------------------ r179 | richard.wm.jones | 2010-01-08 14:28:17 +0000 (Fri, 08 Jan 2010) | 2 lines Changed paths: M /trunk/pa_bitstring.ml Fix empty case for OCaml 3.11 and above. ------------------------------------------------------------------------ r178 | richard.wm.jones | 2010-01-08 14:27:38 +0000 (Fri, 08 Jan 2010) | 2 lines Changed paths: M /trunk/Makefile.in Fix handling of dynlink in OCaml 3.11 and above. ------------------------------------------------------------------------ r177 | richard.wm.jones | 2010-01-08 14:26:23 +0000 (Fri, 08 Jan 2010) | 2 lines Changed paths: M /trunk/aclocal.m4 Update aclocal.m4 to latest OCaml autoconf macros. ------------------------------------------------------------------------ r176 | richard.wm.jones | 2009-07-10 13:22:45 +0100 (Fri, 10 Jul 2009) | 2 lines Changed paths: M /trunk/bitstring_c.c Fix for ARCH_ALIGN_INT64 platforms (Stephane Glondu). ------------------------------------------------------------------------ r175 | richard.wm.jones | 2008-10-17 09:58:29 +0100 (Fri, 17 Oct 2008) | 2 lines Changed paths: M /trunk/configure.ac Version 2.0.0 for release. ------------------------------------------------------------------------ r174 | richard.wm.jones | 2008-10-17 09:58:16 +0100 (Fri, 17 Oct 2008) | 2 lines Changed paths: M /trunk/MANIFEST A /trunk/tests/18_extract_32_64_int.ml Add regression test for 32/64-bit aligned fastpath extraction. ------------------------------------------------------------------------ r173 | richard.wm.jones | 2008-10-17 09:57:43 +0100 (Fri, 17 Oct 2008) | 2 lines Changed paths: M /trunk/pa_bitstring.ml On fastpath, 32/64 bit zeros must be allocated each time (Hans Ole Rafaelsen). ------------------------------------------------------------------------ r172 | richard.wm.jones | 2008-10-06 09:43:14 +0100 (Mon, 06 Oct 2008) | 1 line Changed paths: M /trunk/bitstring.ml Fix index checks in get/put functions (jessicah) ------------------------------------------------------------------------ r171 | toots@rastageeks.org | 2008-08-28 17:44:07 +0100 (Thu, 28 Aug 2008) | 1 line Changed paths: M /trunk/Makefile.in A /trunk/bootstrap Added bootstrap and uninstall target ------------------------------------------------------------------------ r170 | richard.wm.jones | 2008-08-28 10:11:25 +0100 (Thu, 28 Aug 2008) | 1 line Changed paths: M /trunk/configure.ac Version 1.9.9 for release. ------------------------------------------------------------------------ r169 | richard.wm.jones | 2008-08-27 14:04:46 +0100 (Wed, 27 Aug 2008) | 1 line Changed paths: M /trunk/MANIFEST Updated manifest file. ------------------------------------------------------------------------ r168 | richard.wm.jones | 2008-08-27 14:01:46 +0100 (Wed, 27 Aug 2008) | 1 line Changed paths: M /trunk/coverage-report/file0000.html M /trunk/coverage-report/file0001.html M /trunk/coverage-report/file0002.html M /trunk/coverage-report/file0003.html M /trunk/coverage-report/index.html Updated test coverage report. ------------------------------------------------------------------------ r167 | richard.wm.jones | 2008-08-27 13:58:25 +0100 (Wed, 27 Aug 2008) | 2 lines Changed paths: A /trunk/tests/80_hexdump.ml A /trunk/tests/80_testdata A /trunk/tests/80_testdata/hex1.expected A /trunk/tests/80_testdata/hex10.expected A /trunk/tests/80_testdata/hex1000.expected A /trunk/tests/80_testdata/hex11.expected A /trunk/tests/80_testdata/hex12.expected A /trunk/tests/80_testdata/hex127.expected A /trunk/tests/80_testdata/hex128.expected A /trunk/tests/80_testdata/hex13.expected A /trunk/tests/80_testdata/hex14.expected A /trunk/tests/80_testdata/hex15.expected A /trunk/tests/80_testdata/hex16.expected A /trunk/tests/80_testdata/hex2.expected A /trunk/tests/80_testdata/hex200.expected A /trunk/tests/80_testdata/hex3.expected A /trunk/tests/80_testdata/hex31.expected A /trunk/tests/80_testdata/hex32.expected A /trunk/tests/80_testdata/hex33.expected A /trunk/tests/80_testdata/hex34.expected A /trunk/tests/80_testdata/hex4.expected A /trunk/tests/80_testdata/hex47.expected A /trunk/tests/80_testdata/hex48.expected A /trunk/tests/80_testdata/hex49.expected A /trunk/tests/80_testdata/hex5.expected A /trunk/tests/80_testdata/hex50.expected A /trunk/tests/80_testdata/hex500.expected A /trunk/tests/80_testdata/hex6.expected A /trunk/tests/80_testdata/hex63.expected A /trunk/tests/80_testdata/hex64.expected A /trunk/tests/80_testdata/hex65.expected A /trunk/tests/80_testdata/hex66.expected A /trunk/tests/80_testdata/hex67.expected A /trunk/tests/80_testdata/hex7.expected A /trunk/tests/80_testdata/hex8.expected A /trunk/tests/80_testdata/hex9.expected A /trunk/tests/80_testdata/rnd1 A /trunk/tests/80_testdata/rnd10 A /trunk/tests/80_testdata/rnd1000 A /trunk/tests/80_testdata/rnd11 A /trunk/tests/80_testdata/rnd12 A /trunk/tests/80_testdata/rnd127 A /trunk/tests/80_testdata/rnd128 A /trunk/tests/80_testdata/rnd13 A /trunk/tests/80_testdata/rnd14 A /trunk/tests/80_testdata/rnd15 A /trunk/tests/80_testdata/rnd16 A /trunk/tests/80_testdata/rnd2 A /trunk/tests/80_testdata/rnd200 A /trunk/tests/80_testdata/rnd3 A /trunk/tests/80_testdata/rnd31 A /trunk/tests/80_testdata/rnd32 A /trunk/tests/80_testdata/rnd33 A /trunk/tests/80_testdata/rnd34 A /trunk/tests/80_testdata/rnd4 A /trunk/tests/80_testdata/rnd47 A /trunk/tests/80_testdata/rnd48 A /trunk/tests/80_testdata/rnd49 A /trunk/tests/80_testdata/rnd5 A /trunk/tests/80_testdata/rnd50 A /trunk/tests/80_testdata/rnd500 A /trunk/tests/80_testdata/rnd6 A /trunk/tests/80_testdata/rnd63 A /trunk/tests/80_testdata/rnd64 A /trunk/tests/80_testdata/rnd65 A /trunk/tests/80_testdata/rnd66 A /trunk/tests/80_testdata/rnd67 A /trunk/tests/80_testdata/rnd7 A /trunk/tests/80_testdata/rnd8 A /trunk/tests/80_testdata/rnd9 Test the hexdump function. ------------------------------------------------------------------------ r166 | richard.wm.jones | 2008-08-27 13:56:49 +0100 (Wed, 27 Aug 2008) | 2 lines Changed paths: A /trunk/tests/15_extract_int.ml Comprehensive test of fixed-size int construct & extract functions. ------------------------------------------------------------------------ r165 | richard.wm.jones | 2008-08-27 13:56:11 +0100 (Wed, 27 Aug 2008) | 2 lines Changed paths: A /trunk/tests/33_substring.ml A /trunk/tests/34_takebits.ml Test the subbitstring and takebits functions. ------------------------------------------------------------------------ r164 | richard.wm.jones | 2008-08-27 13:55:34 +0100 (Wed, 27 Aug 2008) | 1 line Changed paths: M /trunk/bitstring.ml Fix buggy construct_int64_ne_unsigned and construct_int64_ee_unsigned functions. ------------------------------------------------------------------------ r163 | richard.wm.jones | 2008-08-27 13:54:57 +0100 (Wed, 27 Aug 2008) | 2 lines Changed paths: M /trunk/bitstring_config.ml.in M /trunk/configure.ac Check for 'diff' program (now required to run tests). ------------------------------------------------------------------------ r162 | richard.wm.jones | 2008-08-27 12:28:42 +0100 (Wed, 27 Aug 2008) | 1 line Changed paths: M /trunk/coverage-report/file0000.html M /trunk/coverage-report/file0001.html M /trunk/coverage-report/file0002.html M /trunk/coverage-report/file0003.html M /trunk/coverage-report/index.html Update coverage report. ------------------------------------------------------------------------ r161 | richard.wm.jones | 2008-08-27 12:28:18 +0100 (Wed, 27 Aug 2008) | 1 line Changed paths: A /trunk/tests/31_bitstring_concat.ml A /trunk/tests/32_bitstring_compare.ml A /trunk/tests/35_load_from_file.ml Add tests for compare, load, etc. ------------------------------------------------------------------------ r160 | richard.wm.jones | 2008-08-27 12:27:47 +0100 (Wed, 27 Aug 2008) | 1 line Changed paths: M /trunk/Makefile.in Fix 'make test' rule. ------------------------------------------------------------------------ r159 | richard.wm.jones | 2008-08-27 12:26:45 +0100 (Wed, 27 Aug 2008) | 6 lines Changed paths: M /trunk/bitstring.ml M /trunk/bitstring.mli Added: - Bitstring.compare, Bitstring.equals - Bitstring.t as a synonym for Bitstring.bitstring type - get and set functions for mutating individual bits (rarely used) - Bitstring.concat ------------------------------------------------------------------------ r158 | richard.wm.jones | 2008-08-26 15:18:50 +0100 (Tue, 26 Aug 2008) | 1 line Changed paths: M /trunk/Makefile.in M /trunk/cil-tools/Makefile.in 'make clean' rules remove more generated files. ------------------------------------------------------------------------ r157 | richard.wm.jones | 2008-08-26 10:43:14 +0100 (Tue, 26 Aug 2008) | 1 line Changed paths: M /trunk/configure.ac Version 1.9.8 for release. ------------------------------------------------------------------------ r156 | richard.wm.jones | 2008-08-26 10:42:05 +0100 (Tue, 26 Aug 2008) | 2 lines Changed paths: M /trunk M /trunk/MANIFEST M /trunk/Makefile.in M /trunk/bitstring.ml M /trunk/cil-tools/Makefile.in M /trunk/configure.ac A /trunk/coverage-report A /trunk/coverage-report/file0000.html A /trunk/coverage-report/file0001.html A /trunk/coverage-report/file0002.html A /trunk/coverage-report/file0003.html A /trunk/coverage-report/index.html A /trunk/coverage-report/style.css M /trunk/tests Use ocaml-bisect to compute coverage of tests. ------------------------------------------------------------------------ r155 | richard.wm.jones | 2008-08-26 09:26:23 +0100 (Tue, 26 Aug 2008) | 2 lines Changed paths: M /trunk/MANIFEST Add byteswap.in.h ------------------------------------------------------------------------ r154 | richard.wm.jones | 2008-08-26 09:25:42 +0100 (Tue, 26 Aug 2008) | 1 line Changed paths: M /trunk Ignore *.so files. ------------------------------------------------------------------------ r153 | richard.wm.jones | 2008-08-26 09:24:31 +0100 (Tue, 26 Aug 2008) | 2 lines Changed paths: M /trunk/Makefile.in M /trunk/bitstring.ml M /trunk/bitstring.mli M /trunk/bitstring_c.c A /trunk/byteswap.in.h M /trunk/configure.ac M /trunk/pa_bitstring.ml This patch completes the optimization / fastpaths in C enhancement. ------------------------------------------------------------------------ r152 | richard.wm.jones | 2008-08-26 09:22:42 +0100 (Tue, 26 Aug 2008) | 3 lines Changed paths: M /trunk/bitstring.ml M /trunk/bitstring.mli M /trunk/pa_bitstring.ml This large, but mostly mechanical, patch removes an unnecessary tuple allocation from generated code. ------------------------------------------------------------------------ r151 | richard.wm.jones | 2008-08-26 09:21:43 +0100 (Tue, 26 Aug 2008) | 4 lines Changed paths: M /trunk/bitstring_persistent.ml This patch improves the string_of_* functions in Bitmatch_persistent so that they can print (many) expressions. At the moment they can only print stuff like "bind ([expr])" for most expressions. ------------------------------------------------------------------------ r150 | richard.wm.jones | 2008-08-26 09:20:41 +0100 (Tue, 26 Aug 2008) | 2 lines Changed paths: M /trunk/MANIFEST M /trunk/Makefile.in M /trunk/bitstring.ml A /trunk/bitstring_c.c This patch adds the framework for including C code in bitstring. ------------------------------------------------------------------------ r149 | richard.wm.jones | 2008-08-26 09:16:01 +0100 (Tue, 26 Aug 2008) | 2 lines Changed paths: M /trunk/MANIFEST A /trunk/benchmarks A /trunk/benchmarks/parse_ext3_superblock.ml Include benchmarks directory. ------------------------------------------------------------------------ r148 | richard.wm.jones | 2008-08-26 09:13:48 +0100 (Tue, 26 Aug 2008) | 2 lines Changed paths: M /trunk/Makefile.in M /trunk/configure.ac This adds the outline of a benchmark suite to bitstring. ------------------------------------------------------------------------ r147 | richard.wm.jones | 2008-08-26 09:13:07 +0100 (Tue, 26 Aug 2008) | 4 lines Changed paths: M /trunk/pa_bitstring.ml The attached patch is necessary to work around a bug in the parsing in OCaml 3.10.0 (fixed in 3.10.2 and later). It doesn't affect performance of the generated code. ------------------------------------------------------------------------ r146 | richard.wm.jones | 2008-08-20 17:58:33 +0100 (Wed, 20 Aug 2008) | 2 lines Changed paths: M /trunk/bitstring.ml M /trunk/bitstring.mli Added little-endian constructors (thanks to Romain Beauxis and Samuel Mimram). ------------------------------------------------------------------------ r145 | richard.wm.jones | 2008-07-17 16:58:23 +0100 (Thu, 17 Jul 2008) | 1 line Changed paths: M /trunk/Makefile.in Document the bitmatch compatibility library. ------------------------------------------------------------------------ r142 | richard.wm.jones | 2008-07-17 16:45:56 +0100 (Thu, 17 Jul 2008) | 2 lines Changed paths: M /trunk M /trunk/.depend M /trunk/MANIFEST M /trunk/META.in M /trunk/Makefile.in M /trunk/README A /trunk/bitmatch.ml M /trunk/bitstring.ml M /trunk/bitstring.mli M /trunk/bitstring_config.ml.in M /trunk/bitstring_objinfo.ml M /trunk/bitstring_persistent.ml M /trunk/bitstring_persistent.mli M /trunk/bitstring_types.ml M /trunk/cil-tools M /trunk/cil-tools/.depend M /trunk/cil-tools/Makefile.in M /trunk/cil-tools/bitstring-import-prefix.h M /trunk/cil-tools/bitstring_import_c.ml M /trunk/cil-tools/ext3.c M /trunk/cil-tools/ext3.ml M /trunk/cil-tools/task_struct.c M /trunk/cil-tools/task_struct.ml M /trunk/configure.ac M /trunk/create_test_pattern.ml M /trunk/examples/elf.ml M /trunk/examples/ext3_superblock.ml M /trunk/examples/gif.ml M /trunk/examples/ipv4_header.ml M /trunk/examples/libpcap.ml M /trunk/examples/make_ipv4_header.ml M /trunk/examples/ping.ml M /trunk/pa_bitstring.ml M /trunk/tests/01_load.ml M /trunk/tests/02_run.ml M /trunk/tests/10_match_bits.ml M /trunk/tests/11_match_ints.ml M /trunk/tests/20_varsize.ml M /trunk/tests/30_bitbuffer.ml M /trunk/tests/40_endianexpr.ml M /trunk/tests/50_named_pattern.ml M /trunk/tests/51_open_pattern.ml M /trunk/tests/60_simple_offset.ml M /trunk/tests/61_offset_string.ml M /trunk/tests/62_offset_padding.ml M /trunk/tests/65_save_offset_to.ml M /trunk/tests/70_check_and_bind.ml Renaming bitmatch -> bitstring. ------------------------------------------------------------------------ r141 | richard.wm.jones | 2008-07-17 16:09:05 +0100 (Thu, 17 Jul 2008) | 1 line Changed paths: D /trunk/bitmatch.ml D /trunk/bitmatch.mli D /trunk/bitmatch_config.ml.in D /trunk/bitmatch_objinfo.ml D /trunk/bitmatch_persistent.ml D /trunk/bitmatch_persistent.mli D /trunk/bitmatch_types.ml A /trunk/bitstring.ml (from /trunk/bitmatch.ml:140) A /trunk/bitstring.mli (from /trunk/bitmatch.mli:140) A /trunk/bitstring_config.ml.in (from /trunk/bitmatch_config.ml.in:140) A /trunk/bitstring_objinfo.ml (from /trunk/bitmatch_objinfo.ml:140) A /trunk/bitstring_persistent.ml (from /trunk/bitmatch_persistent.ml:140) A /trunk/bitstring_persistent.mli (from /trunk/bitmatch_persistent.mli:140) A /trunk/bitstring_types.ml (from /trunk/bitmatch_types.ml:140) D /trunk/cil-tools/bitmatch-import-prefix.h D /trunk/cil-tools/bitmatch_import_c.ml A /trunk/cil-tools/bitstring-import-prefix.h (from /trunk/cil-tools/bitmatch-import-prefix.h:140) A /trunk/cil-tools/bitstring_import_c.ml (from /trunk/cil-tools/bitmatch_import_c.ml:140) D /trunk/pa_bitmatch.ml A /trunk/pa_bitstring.ml (from /trunk/pa_bitmatch.ml:140) Rename files and libraries from bitmatch* to bitstring* ------------------------------------------------------------------------ r140 | richard.wm.jones | 2008-07-17 13:10:58 +0100 (Thu, 17 Jul 2008) | 1 line Changed paths: M /trunk/TODO Updated TODO file. ------------------------------------------------------------------------ r139 | richard.wm.jones | 2008-07-17 13:10:05 +0100 (Thu, 17 Jul 2008) | 3 lines Changed paths: M /trunk/MANIFEST M /trunk/configure.ac Version 1.9.6 for release. - Updated MANIFEST. ------------------------------------------------------------------------ r138 | richard.wm.jones | 2008-07-17 12:58:14 +0100 (Thu, 17 Jul 2008) | 1 line Changed paths: M /trunk/tests/70_check_and_bind.ml Improved test. ------------------------------------------------------------------------ r137 | richard.wm.jones | 2008-07-17 12:56:05 +0100 (Thu, 17 Jul 2008) | 3 lines Changed paths: M /trunk/bitmatch.mli M /trunk/bitmatch_persistent.ml M /trunk/bitmatch_persistent.mli M /trunk/pa_bitmatch.ml M /trunk/tests A /trunk/tests/70_check_and_bind.ml Implement check() and bind() qualifiers. - Previously check() was called when(). ------------------------------------------------------------------------ r136 | richard.wm.jones | 2008-07-17 12:27:13 +0100 (Thu, 17 Jul 2008) | 2 lines Changed paths: M /trunk/bitmatch.mli M /trunk/bitmatch_persistent.ml M /trunk/bitmatch_persistent.mli M /trunk/pa_bitmatch.ml M /trunk/tests A /trunk/tests/65_save_offset_to.ml Implement save_to_offset() and partially implement when() and bind(). ------------------------------------------------------------------------ r135 | richard.wm.jones | 2008-07-17 11:33:49 +0100 (Thu, 17 Jul 2008) | 2 lines Changed paths: M /trunk/tests/62_offset_padding.ml Fix an error message. ------------------------------------------------------------------------ r134 | richard.wm.jones | 2008-07-17 09:55:00 +0100 (Thu, 17 Jul 2008) | 2 lines Changed paths: M /trunk/TODO Added when(), bind() and save_offset_to() to the TODO list. ------------------------------------------------------------------------ r133 | richard.wm.jones | 2008-07-17 09:27:01 +0100 (Thu, 17 Jul 2008) | 2 lines Changed paths: M /trunk/tests Set svn:ignore. ------------------------------------------------------------------------ r132 | richard.wm.jones | 2008-07-17 09:26:23 +0100 (Thu, 17 Jul 2008) | 2 lines Changed paths: M /trunk/cil-tools/ext3.ml M /trunk/cil-tools/task_struct.ml M /trunk/tests/60_simple_offset.ml M /trunk/tests/61_offset_string.ml Set svn:keywords property to Id. ------------------------------------------------------------------------ r131 | richard.wm.jones | 2008-07-17 09:25:15 +0100 (Thu, 17 Jul 2008) | 2 lines Changed paths: A /trunk/tests/62_offset_padding.ml Added offset padding test to test the case when original_off <> 0. ------------------------------------------------------------------------ r130 | richard.wm.jones | 2008-07-17 09:24:47 +0100 (Thu, 17 Jul 2008) | 2 lines Changed paths: M /trunk/bitmatch.ml M /trunk/bitmatch.mli Implement dropbits, takebits, subbitstring. ------------------------------------------------------------------------ r129 | richard.wm.jones | 2008-07-17 09:24:20 +0100 (Thu, 17 Jul 2008) | 2 lines Changed paths: M /trunk/pa_bitmatch.ml Fix computed offset calculations when original_off <> 0. ------------------------------------------------------------------------ r128 | richard.wm.jones | 2008-07-11 12:10:30 +0100 (Fri, 11 Jul 2008) | 1 line Changed paths: M /trunk/configure.ac Version 1.9.5 for release. ------------------------------------------------------------------------ r127 | richard.wm.jones | 2008-07-11 12:07:17 +0100 (Fri, 11 Jul 2008) | 1 line Changed paths: A /trunk/COPYING M /trunk/COPYING.LIB M /trunk/MANIFEST M /trunk/README M /trunk/bitmatch.ml M /trunk/bitmatch.mli M /trunk/bitmatch_config.ml.in M /trunk/bitmatch_objinfo.ml M /trunk/bitmatch_persistent.ml M /trunk/bitmatch_persistent.mli M /trunk/bitmatch_types.ml M /trunk/cil-tools/bitmatch-import-prefix.h M /trunk/cil-tools/bitmatch_import_c.ml M /trunk/create_test_pattern.ml M /trunk/pa_bitmatch.ml Clarify licensing for Debian. ------------------------------------------------------------------------ r126 | richard.wm.jones | 2008-07-11 11:56:31 +0100 (Fri, 11 Jul 2008) | 1 line Changed paths: M /trunk/bitmatch.mli Fix documentation for how to compile using camlp4 directly. ------------------------------------------------------------------------ r125 | richard.wm.jones | 2008-07-04 14:40:31 +0100 (Fri, 04 Jul 2008) | 1 line Changed paths: M /trunk/configure.ac Version 1.9.4 for release. ------------------------------------------------------------------------ r124 | richard.wm.jones | 2008-07-04 14:40:07 +0100 (Fri, 04 Jul 2008) | 1 line Changed paths: M /trunk/META.in M /trunk/bitmatch.mli Somewhat better attempt at a META file. ------------------------------------------------------------------------ r123 | richard.wm.jones | 2008-07-04 13:35:06 +0100 (Fri, 04 Jul 2008) | 1 line Changed paths: M /trunk/pa_bitmatch.ml Don't allow zero-length patterns to be loaded from a file ------------------------------------------------------------------------ r122 | richard.wm.jones | 2008-07-04 13:03:21 +0100 (Fri, 04 Jul 2008) | 1 line Changed paths: M /trunk/TODO Update status ------------------------------------------------------------------------ r121 | richard.wm.jones | 2008-07-04 12:03:36 +0100 (Fri, 04 Jul 2008) | 1 line Changed paths: M /trunk/configure.ac Version 1.9.3 for release. ------------------------------------------------------------------------ r120 | richard.wm.jones | 2008-07-04 12:03:17 +0100 (Fri, 04 Jul 2008) | 1 line Changed paths: M /trunk/Makefile.in Include pkg_* ------------------------------------------------------------------------ r119 | richard.wm.jones | 2008-07-01 15:36:25 +0100 (Tue, 01 Jul 2008) | 1 line Changed paths: M /trunk/Makefile.in M /trunk/configure.ac extlib is needed for CIL tools subdir ------------------------------------------------------------------------ r118 | richard.wm.jones | 2008-07-01 15:21:45 +0100 (Tue, 01 Jul 2008) | 1 line Changed paths: M /trunk/TODO Note about META file ------------------------------------------------------------------------ r117 | richard.wm.jones | 2008-07-01 15:15:18 +0100 (Tue, 01 Jul 2008) | 1 line Changed paths: M /trunk/cil-tools/.depend M /trunk/cil-tools/bitmatch_import_c.ml Allow bitmatch-import-prefix.h to be installed centrally. ------------------------------------------------------------------------ r116 | richard.wm.jones | 2008-07-01 15:02:10 +0100 (Tue, 01 Jul 2008) | 1 line Changed paths: M /trunk/configure.ac Version 1.9.2 for release. ------------------------------------------------------------------------ r115 | richard.wm.jones | 2008-07-01 15:01:47 +0100 (Tue, 01 Jul 2008) | 1 line Changed paths: M /trunk/cil-tools/Makefile.in M /trunk/cil-tools/ext3.c M /trunk/cil-tools/ext3.ml Some fixes for building bmpp file. ------------------------------------------------------------------------ r114 | richard.wm.jones | 2008-07-01 13:38:11 +0100 (Tue, 01 Jul 2008) | 1 line Changed paths: M /trunk/MANIFEST Updated MANIFEST ------------------------------------------------------------------------ r113 | richard.wm.jones | 2008-07-01 13:37:03 +0100 (Tue, 01 Jul 2008) | 2 lines Changed paths: M /trunk/configure.ac Version 1.9.1 for release. ------------------------------------------------------------------------ r112 | richard.wm.jones | 2008-07-01 13:35:03 +0100 (Tue, 01 Jul 2008) | 2 lines Changed paths: M /trunk/cil-tools M /trunk/cil-tools/Makefile.in M /trunk/cil-tools/ext3.c A /trunk/cil-tools/ext3.ml M /trunk/cil-tools/task_struct.c A /trunk/cil-tools/task_struct.ml CIL examples. ------------------------------------------------------------------------ r111 | richard.wm.jones | 2008-07-01 13:34:31 +0100 (Tue, 01 Jul 2008) | 2 lines Changed paths: M /trunk/cil-tools/bitmatch_import_c.ml Just warn about unimplemented types - they can be safely skipped. ------------------------------------------------------------------------ r110 | richard.wm.jones | 2008-07-01 12:38:46 +0100 (Tue, 01 Jul 2008) | 3 lines Changed paths: M /trunk/pa_bitmatch.ml Refactor raising of Construct_failure exceptions and make the locations more precise (Bluestorm & RWMJ). ------------------------------------------------------------------------ r109 | richard.wm.jones | 2008-07-01 12:26:12 +0100 (Tue, 01 Jul 2008) | 2 lines Changed paths: M /trunk/pa_bitmatch.ml Make the locations in error messages more specific. ------------------------------------------------------------------------ r108 | richard.wm.jones | 2008-07-01 12:19:34 +0100 (Tue, 01 Jul 2008) | 2 lines Changed paths: M /trunk/pa_bitmatch.ml Refactor constructor and extractor function name generation (Bluestorm). ------------------------------------------------------------------------ r107 | richard.wm.jones | 2008-07-01 12:16:18 +0100 (Tue, 01 Jul 2008) | 2 lines Changed paths: M /trunk/pa_bitmatch.ml Refactor parse_field function (Bluestorm). ------------------------------------------------------------------------ r106 | richard.wm.jones | 2008-07-01 12:09:59 +0100 (Tue, 01 Jul 2008) | 2 lines Changed paths: M /trunk/pa_bitmatch.ml Refactor expr_is_constant (Bluestorm). ------------------------------------------------------------------------ r105 | richard.wm.jones | 2008-07-01 11:12:58 +0100 (Tue, 01 Jul 2008) | 2 lines Changed paths: M /trunk/tests A /trunk/tests/61_offset_string.ml Added string offset tests. ------------------------------------------------------------------------ r104 | richard.wm.jones | 2008-07-01 10:12:39 +0100 (Tue, 01 Jul 2008) | 2 lines Changed paths: M /trunk/pa_bitmatch.ml Convenience function locfail (thanks to Bluestorm). ------------------------------------------------------------------------ r103 | richard.wm.jones | 2008-06-17 16:33:16 +0100 (Tue, 17 Jun 2008) | 1 line Changed paths: M /trunk/cil-tools/bitmatch_import_c.ml Map 8-bit int element arrays to strings ------------------------------------------------------------------------ r102 | richard.wm.jones | 2008-06-17 16:32:27 +0100 (Tue, 17 Jun 2008) | 1 line Changed paths: M /trunk/TODO More items for TODO list ------------------------------------------------------------------------ r101 | richard.wm.jones | 2008-06-16 22:37:16 +0100 (Mon, 16 Jun 2008) | 1 line Changed paths: M /trunk/cil-tools/.depend M /trunk/cil-tools/Makefile.in M /trunk/cil-tools/bitmatch_import_c.ml M /trunk/cil-tools/ext3.c Change cil tools to use computed offsets. ------------------------------------------------------------------------ r100 | richard.wm.jones | 2008-06-16 22:36:56 +0100 (Mon, 16 Jun 2008) | 1 line Changed paths: M /trunk/bitmatch_persistent.ml M /trunk/bitmatch_persistent.mli M /trunk/pa_bitmatch.ml Add string_of_*_field so we can print out fields more accurately. ------------------------------------------------------------------------ r99 | richard.wm.jones | 2008-06-16 21:34:11 +0100 (Mon, 16 Jun 2008) | 1 line Changed paths: M /trunk/.depend M /trunk/Makefile.in Fix dependencies ------------------------------------------------------------------------ r98 | richard.wm.jones | 2008-06-16 21:33:39 +0100 (Mon, 16 Jun 2008) | 1 line Changed paths: M /trunk/tests A /trunk/tests/60_simple_offset.ml Test for offsets ------------------------------------------------------------------------ r97 | richard.wm.jones | 2008-06-16 21:33:21 +0100 (Mon, 16 Jun 2008) | 1 line Changed paths: M /trunk/bitmatch.mli Document constructed offsets, zeroes_bitstring, ones_bitstring. ------------------------------------------------------------------------ r96 | richard.wm.jones | 2008-06-16 21:32:45 +0100 (Mon, 16 Jun 2008) | 1 line Changed paths: M /trunk/bitmatch.ml Implement construct_bitstring, zeroes_bitstring, ones_bitstring functions. ------------------------------------------------------------------------ r95 | richard.wm.jones | 2008-06-16 21:30:24 +0100 (Mon, 16 Jun 2008) | 1 line Changed paths: M /trunk/pa_bitmatch.ml Support for computed offsets in output. Also allow constructed bitstrings of length 0 bits. ------------------------------------------------------------------------ r94 | richard.wm.jones | 2008-06-16 21:29:24 +0100 (Mon, 16 Jun 2008) | 1 line Changed paths: M /trunk/bitmatch_persistent.ml M /trunk/bitmatch_persistent.mli Added computed offset field ------------------------------------------------------------------------ r93 | richard.wm.jones | 2008-06-13 21:57:35 +0100 (Fri, 13 Jun 2008) | 1 line Changed paths: M /trunk/bitmatch_persistent.mli Documentation cleanups ------------------------------------------------------------------------ r92 | richard.wm.jones | 2008-06-13 21:56:02 +0100 (Fri, 13 Jun 2008) | 1 line Changed paths: M /trunk/bitmatch_persistent.mli Documentation cleanups ------------------------------------------------------------------------ r91 | richard.wm.jones | 2008-06-13 21:52:06 +0100 (Fri, 13 Jun 2008) | 1 line Changed paths: M /trunk/bitmatch.mli Documentation cleanups ------------------------------------------------------------------------ r90 | richard.wm.jones | 2008-06-13 21:07:43 +0100 (Fri, 13 Jun 2008) | 1 line Changed paths: M /trunk/bitmatch_persistent.mli Documentation clarification. ------------------------------------------------------------------------ r89 | richard.wm.jones | 2008-06-13 21:06:00 +0100 (Fri, 13 Jun 2008) | 1 line Changed paths: M /trunk/bitmatch_persistent.mli Clarify how to write multiple patterns to a file ------------------------------------------------------------------------ r88 | richard.wm.jones | 2008-06-13 17:04:51 +0100 (Fri, 13 Jun 2008) | 1 line Changed paths: M /trunk/configure.ac Version 1.9 for release. ------------------------------------------------------------------------ r87 | richard.wm.jones | 2008-06-13 16:58:53 +0100 (Fri, 13 Jun 2008) | 1 line Changed paths: M /trunk/MANIFEST Update MANIFEST ------------------------------------------------------------------------ r86 | richard.wm.jones | 2008-06-13 16:56:04 +0100 (Fri, 13 Jun 2008) | 1 line Changed paths: M /trunk M /trunk/Makefile.in M /trunk/bitmatch.mli M /trunk/bitmatch_config.ml.in A /trunk/bitmatch_objinfo.ml M /trunk/bitmatch_persistent.ml M /trunk/bitmatch_persistent.mli M /trunk/cil-tools/Makefile.in M /trunk/cil-tools/bitmatch-import-prefix.h M /trunk/cil-tools/ext3.c M /trunk/cil-tools/task_struct.c A /trunk/create_test_pattern.ml M /trunk/pa_bitmatch.ml M /trunk/tests M /trunk/tests/40_endianexpr.ml A /trunk/tests/50_named_pattern.ml A /trunk/tests/51_open_pattern.ml Persistent patterns, save and load to a file. ------------------------------------------------------------------------ r85 | richard.wm.jones | 2008-06-12 16:46:00 +0100 (Thu, 12 Jun 2008) | 1 line Changed paths: M /trunk/.depend M /trunk/Makefile.in A /trunk/bitmatch_persistent.ml A /trunk/bitmatch_persistent.mli M /trunk/pa_bitmatch.ml Split out field handling from pa_bitmatch into a common library, in preparation for pattern persistence. ------------------------------------------------------------------------ r84 | richard.wm.jones | 2008-06-11 16:04:05 +0100 (Wed, 11 Jun 2008) | 3 lines Changed paths: M /trunk/cil-tools/Makefile.in M /trunk/cil-tools/bitmatch-import-prefix.h M /trunk/cil-tools/bitmatch_import_c.ml M /trunk/cil-tools/ext3.c A /trunk/cil-tools/task_struct.c Committing NON-WORKING cil tools directory. This code all needs to be reworked for when we have reusable bitmatch structures. ------------------------------------------------------------------------ r83 | richard.wm.jones | 2008-06-10 22:50:48 +0100 (Tue, 10 Jun 2008) | 1 line Changed paths: M /trunk/Makefile.in M /trunk/README A /trunk/cil-tools A /trunk/cil-tools/.depend A /trunk/cil-tools/Makefile.in A /trunk/cil-tools/bitmatch-import-prefix.h A /trunk/cil-tools/bitmatch_import_c.ml A /trunk/cil-tools/ext3.c M /trunk/configure.ac Started to copy the import tool from libunbin. ------------------------------------------------------------------------ r81 | richard.wm.jones | 2008-05-21 10:59:21 +0100 (Wed, 21 May 2008) | 1 line Changed paths: M /trunk/Makefile.in Include CHANGES file in tarball. ------------------------------------------------------------------------ r80 | richard.wm.jones | 2008-05-21 10:46:39 +0100 (Wed, 21 May 2008) | 2 lines Changed paths: M /trunk/MANIFEST M /trunk/configure.ac Version 1.3, updated MANIFEST. ------------------------------------------------------------------------ r79 | richard.wm.jones | 2008-05-21 09:59:40 +0100 (Wed, 21 May 2008) | 1 line Changed paths: M /trunk/TODO M /trunk/bitmatch.ml M /trunk/bitmatch.mli M /trunk/examples/libpcap.ml M /trunk/pa_bitmatch.ml M /trunk/tests A /trunk/tests/40_endianexpr.ml Endianness expressions. ------------------------------------------------------------------------ r77 | richard.wm.jones | 2008-05-19 10:20:01 +0100 (Mon, 19 May 2008) | 1 line Changed paths: M /trunk/MANIFEST Updated MANIFEST ------------------------------------------------------------------------ r76 | richard.wm.jones | 2008-05-19 10:19:27 +0100 (Mon, 19 May 2008) | 1 line Changed paths: M /trunk/examples A /trunk/examples/libpcap.ml Added libpcap parsing example. ------------------------------------------------------------------------ r75 | richard.wm.jones | 2008-05-19 09:16:49 +0100 (Mon, 19 May 2008) | 2 lines Changed paths: M /trunk/pa_bitmatch.ml When flen is a constant, use the constant integer value instead of flen expr. ------------------------------------------------------------------------ r74 | richard.wm.jones | 2008-05-18 23:30:19 +0100 (Sun, 18 May 2008) | 1 line Changed paths: M /trunk/configure.ac Version 1.2 for release. ------------------------------------------------------------------------ r73 | richard.wm.jones | 2008-05-18 23:29:50 +0100 (Sun, 18 May 2008) | 1 line Changed paths: M /trunk/MANIFEST Updated MANIFEST ------------------------------------------------------------------------ r72 | richard.wm.jones | 2008-05-18 23:28:41 +0100 (Sun, 18 May 2008) | 1 line Changed paths: M /trunk/bitmatch.ml M /trunk/tests A /trunk/tests/30_bitbuffer.ml Fix string_of_bitstring/add_bits handling of non-multiple-of-8-bit length strings, and add a test case. ------------------------------------------------------------------------ r71 | richard.wm.jones | 2008-05-18 23:27:25 +0100 (Sun, 18 May 2008) | 2 lines Changed paths: M /trunk/tests/11_match_ints.ml Minor code rearrangement, improve an error message. ------------------------------------------------------------------------ r70 | richard.wm.jones | 2008-05-18 22:06:15 +0100 (Sun, 18 May 2008) | 1 line Changed paths: M /trunk/tests A /trunk/tests/11_match_ints.ml Added integer matching test. ------------------------------------------------------------------------ r69 | richard.wm.jones | 2008-05-18 21:54:08 +0100 (Sun, 18 May 2008) | 2 lines Changed paths: M /trunk/tests M /trunk/tests/01_load.ml A /trunk/tests/02_run.ml A /trunk/tests/10_match_bits.ml Bit-matching test. ------------------------------------------------------------------------ r68 | richard.wm.jones | 2008-05-18 21:11:19 +0100 (Sun, 18 May 2008) | 1 line Changed paths: M /trunk/examples/elf.ml Seems that the ELF fields are little-endian. ------------------------------------------------------------------------ r67 | richard.wm.jones | 2008-05-18 21:00:45 +0100 (Sun, 18 May 2008) | 1 line Changed paths: M /trunk/MANIFEST D /trunk/examples/.cvsignore D /trunk/tests/.cvsignore Updated MANIFEST and removed .cvsignore files. ------------------------------------------------------------------------ r66 | richard.wm.jones | 2008-05-18 20:58:56 +0100 (Sun, 18 May 2008) | 1 line Changed paths: M /trunk/configure.ac Version 1.1 for release. ------------------------------------------------------------------------ r65 | richard.wm.jones | 2008-05-18 20:58:17 +0100 (Sun, 18 May 2008) | 1 line Changed paths: M /trunk/examples A /trunk/examples/gif.ml Added GIF parsing example. ------------------------------------------------------------------------ r64 | richard.wm.jones | 2008-05-18 20:44:58 +0100 (Sun, 18 May 2008) | 1 line Changed paths: M /trunk/Makefile.in M /trunk/TODO M /trunk/bitmatch.ml M /trunk/bitmatch.mli M /trunk/bitmatch_config.ml.in M /trunk/bitmatch_types.ml M /trunk/examples/elf.ml M /trunk/examples/ext3_superblock.ml M /trunk/examples/ipv4_header.ml M /trunk/examples/make_ipv4_header.ml M /trunk/examples/ping.ml M /trunk/pa_bitmatch.ml M /trunk/tests/01_load.ml M /trunk/tests/20_varsize.ml Enable svn:keywords Id property on relevant files. ------------------------------------------------------------------------ r63 | richard.wm.jones | 2008-05-18 20:29:03 +0100 (Sun, 18 May 2008) | 1 line Changed paths: M /trunk/examples A /trunk/examples/elf.ml ELF parsing example. ------------------------------------------------------------------------ r62 | richard.wm.jones | 2008-05-18 20:28:22 +0100 (Sun, 18 May 2008) | 2 lines Changed paths: M /trunk/Makefile.in Make examples depend upon library. ------------------------------------------------------------------------ r61 | richard.wm.jones | 2008-05-18 20:23:13 +0100 (Sun, 18 May 2008) | 1 line Changed paths: D /trunk/examples/ipv4.ping D /trunk/examples/ipv6.ping A /trunk/examples/ping.ipv4 (from /trunk/examples/ipv4.ping:60) A /trunk/examples/ping.ipv6 (from /trunk/examples/ipv6.ping:60) M /trunk/examples/ping.ml More consistent naming of files. ------------------------------------------------------------------------ r60 | richard.wm.jones | 2008-05-18 20:21:59 +0100 (Sun, 18 May 2008) | 2 lines Changed paths: A /trunk/examples/ext3_sb (from /trunk/tests/ext3_sb:57) A /trunk/examples/ext3_superblock.ml (from /trunk/tests/70_ext3_sb.ml:57) A /trunk/examples/ipv4.ping (from /trunk/tests/ipv4.ping:57) A /trunk/examples/ipv6.ping (from /trunk/tests/ipv6.ping:57) A /trunk/examples/ping.ml (from /trunk/tests/60_ping.ml:57) D /trunk/tests/03_hexdump.ml D /trunk/tests/05_bits.ml D /trunk/tests/06_ints1.ml D /trunk/tests/06_ints2.ml D /trunk/tests/06_ints3.ml D /trunk/tests/10_constr1.ml D /trunk/tests/10_constr2.ml D /trunk/tests/60_ping.ml D /trunk/tests/70_ext3_sb.ml D /trunk/tests/ext3_sb D /trunk/tests/ipv4.ping D /trunk/tests/ipv6.ping Removed obsolete tests, and moved some tests into examples. ------------------------------------------------------------------------ r59 | richard.wm.jones | 2008-05-18 20:05:08 +0100 (Sun, 18 May 2008) | 2 lines Changed paths: M /trunk M /trunk/examples Fix svnignore in the examples subdirectory. ------------------------------------------------------------------------ r58 | richard.wm.jones | 2008-05-18 20:03:58 +0100 (Sun, 18 May 2008) | 2 lines Changed paths: M /trunk M /trunk/Makefile.in M /trunk/README Added rules to build examples. ------------------------------------------------------------------------ r57 | richard.wm.jones | 2008-05-18 20:03:22 +0100 (Sun, 18 May 2008) | 2 lines Changed paths: M /trunk/examples/make_ipv4_header.ml Fix this example so it now works. ------------------------------------------------------------------------ r56 | richard.wm.jones | 2008-05-18 20:02:54 +0100 (Sun, 18 May 2008) | 2 lines Changed paths: M /trunk/bitmatch.ml M /trunk/bitmatch.mli Implement bitstring_to_chan, bitstring_to_file. ------------------------------------------------------------------------ r55 | richard.wm.jones | 2008-05-18 19:32:01 +0100 (Sun, 18 May 2008) | 2 lines Changed paths: M /trunk M /trunk/.depend M /trunk/MANIFEST M /trunk/Makefile.in M /trunk/bitmatch.ml M /trunk/bitmatch.mli A /trunk/bitmatch_config.ml.in A /trunk/bitmatch_types.ml M /trunk/configure.ac M /trunk/pa_bitmatch.ml Implement the nativeendian version of some functions. ------------------------------------------------------------------------ r54 | richard.wm.jones | 2008-05-18 19:30:08 +0100 (Sun, 18 May 2008) | 2 lines Changed paths: M /trunk/examples/ipv4_header.ml M /trunk/examples/make_ipv4_header.ml Fix examples to use the new syntax. ------------------------------------------------------------------------ r53 | richard.wm.jones | 2008-05-18 17:42:38 +0100 (Sun, 18 May 2008) | 1 line Changed paths: M /trunk/TODO Updated TODO ------------------------------------------------------------------------ r52 | richard.wm.jones | 2008-05-18 17:13:50 +0100 (Sun, 18 May 2008) | 2 lines Changed paths: M /trunk/configure.ac Version 1.0 for release. ------------------------------------------------------------------------ r51 | richard.wm.jones | 2008-05-18 17:13:09 +0100 (Sun, 18 May 2008) | 1 line Changed paths: M /trunk/pa_bitmatch.ml Allow '_' to be used to ignore more types of bitstring when matching. ------------------------------------------------------------------------ r50 | richard.wm.jones | 2008-05-18 17:03:04 +0100 (Sun, 18 May 2008) | 2 lines Changed paths: M /trunk/MANIFEST M /trunk/Makefile.in Fix check-manifest rule to work with Subversion. ------------------------------------------------------------------------ r49 | richard.wm.jones | 2008-05-18 16:52:49 +0100 (Sun, 18 May 2008) | 2 lines Changed paths: M /trunk/pa_bitmatch.ml Polymorphic 'field' type. ------------------------------------------------------------------------ r48 | richard.wm.jones | 2008-05-18 16:39:29 +0100 (Sun, 18 May 2008) | 5 lines Changed paths: M /trunk D /trunk/.cvsignore M /trunk/TODO M /trunk/bitmatch.mli M /trunk/pa_bitmatch.ml More complete handling of constant field length expressions. More TODO line items. Set svnignore and remove old cvsignore file. Fix link to bitmatch home page. ------------------------------------------------------------------------ r47 | rjones | 2008-05-12 21:32:55 +0100 (Mon, 12 May 2008) | 2 lines Changed paths: M /trunk/bitmatch.ml M /trunk/configure.ac Fix extracting in little-endian case. ------------------------------------------------------------------------ r46 | rjones | 2008-05-08 22:28:28 +0100 (Thu, 08 May 2008) | 2 lines Changed paths: M /trunk/bitmatch.ml M /trunk/bitmatch.mli M /trunk/configure.ac Added extract_int64_le_unsigned, version 0.8 for release. ------------------------------------------------------------------------ r45 | rjones | 2008-05-07 15:56:53 +0100 (Wed, 07 May 2008) | 2 lines Changed paths: M /trunk/bitmatch.ml M /trunk/bitmatch.mli Missing exception arg to construct_bit, and added construct_int32_be_unsigned. ------------------------------------------------------------------------ r44 | rjones | 2008-05-07 15:41:03 +0100 (Wed, 07 May 2008) | 2 lines Changed paths: M /trunk/META.in M /trunk/Makefile.in Requires unix - new version 0.7 candidate for release. ------------------------------------------------------------------------ r43 | rjones | 2008-05-07 15:37:00 +0100 (Wed, 07 May 2008) | 2 lines Changed paths: M /trunk/TODO M /trunk/bitmatch.ml M /trunk/bitmatch.mli M /trunk/configure.ac Added construct_string, version 0.7 for release. ------------------------------------------------------------------------ r42 | rjones | 2008-04-26 21:35:02 +0100 (Sat, 26 Apr 2008) | 2 lines Changed paths: M /trunk/bitmatch.ml M /trunk/bitmatch.mli bitstring_of_string and bitstring_of_*_max functions. ------------------------------------------------------------------------ r41 | rjones | 2008-04-25 16:07:30 +0100 (Fri, 25 Apr 2008) | 2 lines Changed paths: M /trunk/configure.ac Version 0.6 for release. ------------------------------------------------------------------------ r40 | rjones | 2008-04-25 15:57:11 +0100 (Fri, 25 Apr 2008) | 2 lines Changed paths: M /trunk/pa_bitmatch.ml Turn off exhaustiveness checking (thanks: Martin Jambon). ------------------------------------------------------------------------ r39 | rjones | 2008-04-25 13:55:39 +0100 (Fri, 25 Apr 2008) | 3 lines Changed paths: M /trunk/TODO M /trunk/bitmatch.mli M /trunk/pa_bitmatch.ml M /trunk/tests/70_ext3_sb.ml Allow matching against a string type. Error locations are now very fine-grained. ------------------------------------------------------------------------ r38 | rjones | 2008-04-25 13:08:51 +0100 (Fri, 25 Apr 2008) | 2 lines Changed paths: M /trunk/TODO M /trunk/bitmatch.mli M /trunk/pa_bitmatch.ml Use patterns, not expressions, in the bitmatch operator. ------------------------------------------------------------------------ r37 | rjones | 2008-04-25 12:08:43 +0100 (Fri, 25 Apr 2008) | 2 lines Changed paths: M /trunk/TODO M /trunk/bitmatch.mli M /trunk/configure.ac M /trunk/pa_bitmatch.ml M /trunk/tests/05_bits.ml M /trunk/tests/06_ints1.ml M /trunk/tests/06_ints2.ml M /trunk/tests/06_ints3.ml M /trunk/tests/10_constr1.ml M /trunk/tests/10_constr2.ml M /trunk/tests/20_varsize.ml M /trunk/tests/60_ping.ml M /trunk/tests/70_ext3_sb.ml Change syntax so that { ... } surrounds match patterns. ------------------------------------------------------------------------ r36 | rjones | 2008-04-25 11:44:00 +0100 (Fri, 25 Apr 2008) | 2 lines Changed paths: M /trunk/pa_bitmatch.ml Typo. ------------------------------------------------------------------------ r35 | rjones | 2008-04-16 12:14:40 +0100 (Wed, 16 Apr 2008) | 2 lines Changed paths: M /trunk/MANIFEST Added TODO to MANIFEST. ------------------------------------------------------------------------ r34 | rjones | 2008-04-15 14:41:21 +0100 (Tue, 15 Apr 2008) | 2 lines Changed paths: M /trunk/configure.ac Version 0.4. ------------------------------------------------------------------------ r33 | rjones | 2008-04-15 14:41:14 +0100 (Tue, 15 Apr 2008) | 2 lines Changed paths: A /trunk/TODO Added TODO file. ------------------------------------------------------------------------ r32 | rjones | 2008-04-15 14:40:51 +0100 (Tue, 15 Apr 2008) | 2 lines Changed paths: M /trunk/bitmatch.ml M /trunk/bitmatch.mli string_of_bitstring. ------------------------------------------------------------------------ r31 | rjones | 2008-04-02 14:59:47 +0100 (Wed, 02 Apr 2008) | 2 lines Changed paths: M /trunk/META.in Some fixes to the META file, still doesn't work. ------------------------------------------------------------------------ r30 | rjones | 2008-04-02 14:59:37 +0100 (Wed, 02 Apr 2008) | 2 lines Changed paths: M /trunk/bitmatch.mli Fixed 'compiling' documentation. ------------------------------------------------------------------------ r29 | rjones | 2008-04-02 14:22:46 +0100 (Wed, 02 Apr 2008) | 2 lines Changed paths: M /trunk/Makefile.in Install pa_bitmatch.cmo, don't install pa_bitmatch.cmi, distribute config.h.in. ------------------------------------------------------------------------ r28 | rjones | 2008-04-02 14:22:07 +0100 (Wed, 02 Apr 2008) | 2 lines Changed paths: M /trunk/bitmatch.mli Documentation update ------------------------------------------------------------------------ r27 | rjones | 2008-04-02 13:36:43 +0100 (Wed, 02 Apr 2008) | 2 lines Changed paths: M /trunk/configure.ac Version 0.2 released. ------------------------------------------------------------------------ r26 | rjones | 2008-04-02 13:31:46 +0100 (Wed, 02 Apr 2008) | 2 lines Changed paths: M /trunk/MANIFEST Updated MANIFEST. ------------------------------------------------------------------------ r25 | rjones | 2008-04-02 13:29:03 +0100 (Wed, 02 Apr 2008) | 2 lines Changed paths: M /trunk/bitmatch.mli Updated documentation. ------------------------------------------------------------------------ r24 | rjones | 2008-04-02 12:06:31 +0100 (Wed, 02 Apr 2008) | 2 lines Changed paths: M /trunk/bitmatch.mli Start of documentation. ------------------------------------------------------------------------ r23 | rjones | 2008-04-02 12:06:21 +0100 (Wed, 02 Apr 2008) | 2 lines Changed paths: M /trunk/tests M /trunk/tests/.cvsignore Update cvsignore. ------------------------------------------------------------------------ r22 | rjones | 2008-04-02 12:06:07 +0100 (Wed, 02 Apr 2008) | 3 lines Changed paths: M /trunk/bitmatch.ml A /trunk/tests/10_constr2.ml Move more common bithandling code into I/I32/I64 modules. Fix constructor functions. ------------------------------------------------------------------------ r21 | rjones | 2008-04-02 09:14:40 +0100 (Wed, 02 Apr 2008) | 2 lines Changed paths: M /trunk M /trunk/.cvsignore M /trunk/Makefile.in M /trunk/README M /trunk/bitmatch.mli Outline of documentation. ------------------------------------------------------------------------ r20 | rjones | 2008-04-02 09:05:58 +0100 (Wed, 02 Apr 2008) | 2 lines Changed paths: M /trunk/bitmatch.ml M /trunk/bitmatch.mli M /trunk/pa_bitmatch.ml LGPL notices. ------------------------------------------------------------------------ r19 | rjones | 2008-04-02 09:03:26 +0100 (Wed, 02 Apr 2008) | 2 lines Changed paths: M /trunk/Makefile.in Makefile make install/clean. ------------------------------------------------------------------------ r18 | rjones | 2008-04-02 09:03:03 +0100 (Wed, 02 Apr 2008) | 2 lines Changed paths: A /trunk/README Added README ------------------------------------------------------------------------ r17 | rjones | 2008-04-02 09:02:52 +0100 (Wed, 02 Apr 2008) | 2 lines Changed paths: M /trunk/MANIFEST Updated MANIFEST ------------------------------------------------------------------------ r16 | rjones | 2008-04-02 09:02:44 +0100 (Wed, 02 Apr 2008) | 2 lines Changed paths: M /trunk/META.in META file ------------------------------------------------------------------------ r15 | rjones | 2008-04-02 08:20:26 +0100 (Wed, 02 Apr 2008) | 2 lines Changed paths: M /trunk M /trunk/.cvsignore A /trunk/COPYING.LIB A /trunk/META.in D /trunk/Makefile A /trunk/Makefile.in A /trunk/aclocal.m4 A /trunk/configure.ac A /trunk/install-sh Autoconfify. ------------------------------------------------------------------------ r14 | rjones | 2008-04-01 23:19:59 +0100 (Tue, 01 Apr 2008) | 2 lines Changed paths: M /trunk M /trunk/.cvsignore Ignore tarballs ------------------------------------------------------------------------ r13 | rjones | 2008-04-01 23:18:24 +0100 (Tue, 01 Apr 2008) | 2 lines Changed paths: A /trunk/MANIFEST M /trunk/Makefile Added MANIFEST, distribution rule. ------------------------------------------------------------------------ r12 | rjones | 2008-04-01 20:10:45 +0100 (Tue, 01 Apr 2008) | 2 lines Changed paths: M /trunk/bitmatch.ml M /trunk/bitmatch.mli M /trunk/pa_bitmatch.ml M /trunk/tests M /trunk/tests/.cvsignore A /trunk/tests/70_ext3_sb.ml A /trunk/tests/ext3_sb Fixed byte swaps so that now ext3 superblock can be parsed. ------------------------------------------------------------------------ r11 | rjones | 2008-04-01 18:31:12 +0100 (Tue, 01 Apr 2008) | 2 lines Changed paths: M /trunk/examples/ipv4_header.ml M /trunk/examples/make_ipv4_header.ml Fixed syntax of the examples. ------------------------------------------------------------------------ r10 | rjones | 2008-04-01 18:05:37 +0100 (Tue, 01 Apr 2008) | 2 lines Changed paths: M /trunk/Makefile M /trunk/bitmatch.ml M /trunk/bitmatch.mli M /trunk/pa_bitmatch.ml M /trunk/tests M /trunk/tests/.cvsignore A /trunk/tests/10_constr1.ml A /trunk/tests/20_varsize.ml Added constructors. ------------------------------------------------------------------------ r9 | rjones | 2008-04-01 16:22:46 +0100 (Tue, 01 Apr 2008) | 2 lines Changed paths: M /trunk/tests/60_ping.ml Now supports constant field patterns in bitmatch. ------------------------------------------------------------------------ r8 | rjones | 2008-04-01 11:58:53 +0100 (Tue, 01 Apr 2008) | 2 lines Changed paths: M /trunk/bitmatch.ml M /trunk/bitmatch.mli A /trunk/tests/60_ping.ml Added extract_int_be_unsigned and extract_int32_be_unsigned. ------------------------------------------------------------------------ r7 | rjones | 2008-04-01 11:58:35 +0100 (Tue, 01 Apr 2008) | 2 lines Changed paths: M /trunk/tests/ipv4.ping M /trunk/tests/ipv6.ping Fix corrupted IPv4/6 packets. ------------------------------------------------------------------------ r6 | rjones | 2008-04-01 11:06:37 +0100 (Tue, 01 Apr 2008) | 2 lines Changed paths: A /trunk/tests/ipv4.ping A /trunk/tests/ipv6.ping Added IPv4 and IPv6 ping packets. ------------------------------------------------------------------------ r5 | rjones | 2008-04-01 11:06:12 +0100 (Tue, 01 Apr 2008) | 2 lines Changed paths: M /trunk/bitmatch.ml M /trunk/bitmatch.mli M /trunk/tests M /trunk/tests/.cvsignore A /trunk/tests/03_hexdump.ml Added Bitmatch.hexdump_bitstring ------------------------------------------------------------------------ r4 | rjones | 2008-04-01 11:05:14 +0100 (Tue, 01 Apr 2008) | 2 lines Changed paths: M /trunk/pa_bitmatch.ml Avoid compiler warning from 'raise Exit; ()' ------------------------------------------------------------------------ r3 | rjones | 2008-04-01 09:56:43 +0100 (Tue, 01 Apr 2008) | 2 lines Changed paths: M /trunk/Makefile M /trunk/bitmatch.ml M /trunk/bitmatch.mli M /trunk/pa_bitmatch.ml M /trunk/tests M /trunk/tests/.cvsignore M /trunk/tests/05_bits.ml A /trunk/tests/06_ints1.ml A /trunk/tests/06_ints2.ml A /trunk/tests/06_ints3.ml extract_char_unsigned ------------------------------------------------------------------------ r2 | rjones | 2008-03-31 23:52:17 +0100 (Mon, 31 Mar 2008) | 2 lines Changed paths: M /trunk A /trunk/.cvsignore A /trunk/.depend A /trunk/Makefile A /trunk/bitmatch.ml A /trunk/bitmatch.mli A /trunk/examples A /trunk/examples/.cvsignore A /trunk/examples/ipv4_header.ml A /trunk/examples/make_ipv4_header.ml A /trunk/pa_bitmatch.ml A /trunk/tests A /trunk/tests/.cvsignore A /trunk/tests/01_load.ml A /trunk/tests/05_bits.ml Bitmatch syntax extension, working on bits and bitstrings. ------------------------------------------------------------------------ r1 | (no author) | 2008-03-31 23:52:17 +0100 (Mon, 31 Mar 2008) | 1 line Changed paths: A /branches A /tags A /trunk New repository initialized by cvs2svn. ------------------------------------------------------------------------ ocaml-bitstring-2.0.4/bitstring.ml0000664000175000017500000011563112144457237016556 0ustar rjonesrjones(* Bitstring library. * Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version, * with the OCaml linking exception described in COPYING.LIB. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: bitstring.ml 198 2013-05-14 15:56:07Z richard.wm.jones@gmail.com $ *) open Printf include Bitstring_types include Bitstring_config (* Enable runtime debug messages. Must also have been enabled * in pa_bitstring.ml. *) let debug = ref false (* Exceptions. *) exception Construct_failure of string * string * int * int (* A bitstring is simply the data itself (as a string), and the * bitoffset and the bitlength within the string. Note offset/length * are counted in bits, not bytes. *) type bitstring = string * int * int type t = bitstring (* Functions to create and load bitstrings. *) let empty_bitstring = "", 0, 0 let make_bitstring len c = if len >= 0 then String.make ((len+7) lsr 3) c, 0, len else invalid_arg ( sprintf "make_bitstring/create_bitstring: len %d < 0" len ) let create_bitstring len = make_bitstring len '\000' let zeroes_bitstring = create_bitstring let ones_bitstring len = make_bitstring len '\xff' let bitstring_of_string str = str, 0, String.length str lsl 3 let bitstring_of_chan chan = let tmpsize = 16384 in let buf = Buffer.create tmpsize in let tmp = String.create tmpsize in let n = ref 0 in while n := input chan tmp 0 tmpsize; !n > 0 do Buffer.add_substring buf tmp 0 !n; done; Buffer.contents buf, 0, Buffer.length buf lsl 3 let bitstring_of_chan_max chan max = let tmpsize = 16384 in let buf = Buffer.create tmpsize in let tmp = String.create tmpsize in let len = ref 0 in let rec loop () = if !len < max then ( let r = min tmpsize (max - !len) in let n = input chan tmp 0 r in if n > 0 then ( Buffer.add_substring buf tmp 0 n; len := !len + n; loop () ) ) in loop (); Buffer.contents buf, 0, !len lsl 3 let bitstring_of_file_descr fd = let tmpsize = 16384 in let buf = Buffer.create tmpsize in let tmp = String.create tmpsize in let n = ref 0 in while n := Unix.read fd tmp 0 tmpsize; !n > 0 do Buffer.add_substring buf tmp 0 !n; done; Buffer.contents buf, 0, Buffer.length buf lsl 3 let bitstring_of_file_descr_max fd max = let tmpsize = 16384 in let buf = Buffer.create tmpsize in let tmp = String.create tmpsize in let len = ref 0 in let rec loop () = if !len < max then ( let r = min tmpsize (max - !len) in let n = Unix.read fd tmp 0 r in if n > 0 then ( Buffer.add_substring buf tmp 0 n; len := !len + n; loop () ) ) in loop (); Buffer.contents buf, 0, !len lsl 3 let bitstring_of_file fname = let chan = open_in_bin fname in try let bs = bitstring_of_chan chan in close_in chan; bs with exn -> close_in chan; raise exn let bitstring_length (_, _, len) = len let subbitstring (data, off, len) off' len' = let off = off + off' in if off' < 0 || len' < 0 || off' > len - len' then invalid_arg "subbitstring"; (data, off, len') let dropbits n (data, off, len) = let off = off + n in let len = len - n in if len < 0 || n < 0 then invalid_arg "dropbits"; (data, off, len) let takebits n (data, off, len) = if len < n || n < 0 then invalid_arg "takebits"; (data, off, n) (*----------------------------------------------------------------------*) (* Bitwise functions. * * We try to isolate all bitwise functions within these modules. *) module I = struct (* Bitwise operations on ints. Note that we assume int <= 31 bits. *) external (<<<) : int -> int -> int = "%lslint" external (>>>) : int -> int -> int = "%lsrint" external to_int : int -> int = "%identity" let zero = 0 let one = 1 let minus_one = -1 let ff = 0xff (* Create a mask 0-31 bits wide. *) let mask bits = if bits < 30 then (one <<< bits) - 1 else if bits = 30 then max_int else if bits = 31 then minus_one else invalid_arg "Bitstring.I.mask" (* Byte swap an int of a given size. *) let byteswap v bits = if bits <= 8 then v else if bits <= 16 then ( let shift = bits-8 in let v1 = v >>> shift in let v2 = ((v land (mask shift)) <<< 8) in v2 lor v1 ) else if bits <= 24 then ( let shift = bits - 16 in let v1 = v >>> (8+shift) in let v2 = ((v >>> shift) land ff) <<< 8 in let v3 = (v land (mask shift)) <<< 16 in v3 lor v2 lor v1 ) else ( let shift = bits - 24 in let v1 = v >>> (16+shift) in let v2 = ((v >>> (8+shift)) land ff) <<< 8 in let v3 = ((v >>> shift) land ff) <<< 16 in let v4 = (v land (mask shift)) <<< 24 in v4 lor v3 lor v2 lor v1 ) (* Check a value is in range 0 .. 2^bits-1. *) let range_unsigned v bits = let mask = lnot (mask bits) in (v land mask) = zero (* Call function g on the top bits, then f on each full byte * (big endian - so start at top). *) let rec map_bytes_be g f v bits = if bits >= 8 then ( map_bytes_be g f (v >>> 8) (bits-8); let lsb = v land ff in f (to_int lsb) ) else if bits > 0 then ( let lsb = v land (mask bits) in g (to_int lsb) bits ) (* Call function g on the top bits, then f on each full byte * (little endian - so start at root). *) let rec map_bytes_le g f v bits = if bits >= 8 then ( let lsb = v land ff in f (to_int lsb); map_bytes_le g f (v >>> 8) (bits-8) ) else if bits > 0 then ( let lsb = v land (mask bits) in g (to_int lsb) bits ) end module I32 = struct (* Bitwise operations on int32s. Note we try to keep it as similar * as possible to the I module above, to make it easier to track * down bugs. *) let (<<<) = Int32.shift_left let (>>>) = Int32.shift_right_logical let (land) = Int32.logand let (lor) = Int32.logor let lnot = Int32.lognot let pred = Int32.pred let max_int = Int32.max_int let to_int = Int32.to_int let zero = Int32.zero let one = Int32.one let minus_one = Int32.minus_one let ff = 0xff_l (* Create a mask so many bits wide. *) let mask bits = if bits < 31 then pred (one <<< bits) else if bits = 31 then max_int else if bits = 32 then minus_one else invalid_arg "Bitstring.I32.mask" (* Byte swap an int of a given size. *) let byteswap v bits = if bits <= 8 then v else if bits <= 16 then ( let shift = bits-8 in let v1 = v >>> shift in let v2 = (v land (mask shift)) <<< 8 in v2 lor v1 ) else if bits <= 24 then ( let shift = bits - 16 in let v1 = v >>> (8+shift) in let v2 = ((v >>> shift) land ff) <<< 8 in let v3 = (v land (mask shift)) <<< 16 in v3 lor v2 lor v1 ) else ( let shift = bits - 24 in let v1 = v >>> (16+shift) in let v2 = ((v >>> (8+shift)) land ff) <<< 8 in let v3 = ((v >>> shift) land ff) <<< 16 in let v4 = (v land (mask shift)) <<< 24 in v4 lor v3 lor v2 lor v1 ) (* Check a value is in range 0 .. 2^bits-1. *) let range_unsigned v bits = let mask = lnot (mask bits) in (v land mask) = zero (* Call function g on the top bits, then f on each full byte * (big endian - so start at top). *) let rec map_bytes_be g f v bits = if bits >= 8 then ( map_bytes_be g f (v >>> 8) (bits-8); let lsb = v land ff in f (to_int lsb) ) else if bits > 0 then ( let lsb = v land (mask bits) in g (to_int lsb) bits ) (* Call function g on the top bits, then f on each full byte * (little endian - so start at root). *) let rec map_bytes_le g f v bits = if bits >= 8 then ( let lsb = v land ff in f (to_int lsb); map_bytes_le g f (v >>> 8) (bits-8) ) else if bits > 0 then ( let lsb = v land (mask bits) in g (to_int lsb) bits ) end module I64 = struct (* Bitwise operations on int64s. Note we try to keep it as similar * as possible to the I/I32 modules above, to make it easier to track * down bugs. *) let (<<<) = Int64.shift_left let (>>>) = Int64.shift_right_logical let (land) = Int64.logand let (lor) = Int64.logor let lnot = Int64.lognot let pred = Int64.pred let max_int = Int64.max_int let to_int = Int64.to_int let zero = Int64.zero let one = Int64.one let minus_one = Int64.minus_one let ff = 0xff_L (* Create a mask so many bits wide. *) let mask bits = if bits < 63 then pred (one <<< bits) else if bits = 63 then max_int else if bits = 64 then minus_one else invalid_arg "Bitstring.I64.mask" (* Byte swap an int of a given size. *) (* let byteswap v bits = *) (* Check a value is in range 0 .. 2^bits-1. *) let range_unsigned v bits = let mask = lnot (mask bits) in (v land mask) = zero (* Call function g on the top bits, then f on each full byte * (big endian - so start at top). *) let rec map_bytes_be g f v bits = if bits >= 8 then ( map_bytes_be g f (v >>> 8) (bits-8); let lsb = v land ff in f (to_int lsb) ) else if bits > 0 then ( let lsb = v land (mask bits) in g (to_int lsb) bits ) (* Call function g on the top bits, then f on each full byte * (little endian - so start at root). *) let rec map_bytes_le g f v bits = if bits >= 8 then ( let lsb = v land ff in f (to_int lsb); map_bytes_le g f (v >>> 8) (bits-8) ) else if bits > 0 then ( let lsb = v land (mask bits) in g (to_int lsb) bits ) end (*----------------------------------------------------------------------*) (* Extraction functions. * * NB: internal functions, called from the generated macros, and * the parameters should have been checked for sanity already). *) (* Extract and convert to numeric. A single bit is returned as * a boolean. There are no endianness or signedness considerations. *) let extract_bit data off len _ = (* final param is always 1 *) let byteoff = off lsr 3 in let bitmask = 1 lsl (7 - (off land 7)) in let b = Char.code data.[byteoff] land bitmask <> 0 in b (*, off+1, len-1*) (* Returns 8 bit unsigned aligned bytes from the string. * If the string ends then this returns 0's. *) let _get_byte data byteoff strlen = if strlen > byteoff then Char.code data.[byteoff] else 0 let _get_byte32 data byteoff strlen = if strlen > byteoff then Int32.of_int (Char.code data.[byteoff]) else 0l let _get_byte64 data byteoff strlen = if strlen > byteoff then Int64.of_int (Char.code data.[byteoff]) else 0L (* Extract [2..8] bits. Because the result fits into a single * byte we don't have to worry about endianness, only signedness. *) let extract_char_unsigned data off len flen = let byteoff = off lsr 3 in (* Optimize the common (byte-aligned) case. *) if off land 7 = 0 then ( let byte = Char.code data.[byteoff] in byte lsr (8 - flen) (*, off+flen, len-flen*) ) else ( (* Extract the 16 bits at byteoff and byteoff+1 (note that the * second byte might not exist in the original string). *) let strlen = String.length data in let word = (_get_byte data byteoff strlen lsl 8) + _get_byte data (byteoff+1) strlen in (* Mask off the top bits. *) let bitmask = (1 lsl (16 - (off land 7))) - 1 in let word = word land bitmask in (* Shift right to get rid of the bottom bits. *) let shift = 16 - ((off land 7) + flen) in let word = word lsr shift in word (*, off+flen, len-flen*) ) (* Extract [9..31] bits. We have to consider endianness and signedness. *) let extract_int_be_unsigned data off len flen = let byteoff = off lsr 3 in let strlen = String.length data in let word = (* Optimize the common (byte-aligned) case. *) if off land 7 = 0 then ( let word = (_get_byte data byteoff strlen lsl 23) + (_get_byte data (byteoff+1) strlen lsl 15) + (_get_byte data (byteoff+2) strlen lsl 7) + (_get_byte data (byteoff+3) strlen lsr 1) in word lsr (31 - flen) ) else if flen <= 24 then ( (* Extract the 31 bits at byteoff .. byteoff+3. *) let word = (_get_byte data byteoff strlen lsl 23) + (_get_byte data (byteoff+1) strlen lsl 15) + (_get_byte data (byteoff+2) strlen lsl 7) + (_get_byte data (byteoff+3) strlen lsr 1) in (* Mask off the top bits. *) let bitmask = (1 lsl (31 - (off land 7))) - 1 in let word = word land bitmask in (* Shift right to get rid of the bottom bits. *) let shift = 31 - ((off land 7) + flen) in word lsr shift ) else ( (* Extract the next 31 bits, slow method. *) let word = let c0 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c1 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c2 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c3 = extract_char_unsigned data off len 7 in (c0 lsl 23) + (c1 lsl 15) + (c2 lsl 7) + c3 in word lsr (31 - flen) ) in word (*, off+flen, len-flen*) let extract_int_le_unsigned data off len flen = let v = extract_int_be_unsigned data off len flen in let v = I.byteswap v flen in v let extract_int_ne_unsigned = if nativeendian = BigEndian then extract_int_be_unsigned else extract_int_le_unsigned let extract_int_ee_unsigned = function | BigEndian -> extract_int_be_unsigned | LittleEndian -> extract_int_le_unsigned | NativeEndian -> extract_int_ne_unsigned let _make_int32_be c0 c1 c2 c3 = Int32.logor (Int32.logor (Int32.logor (Int32.shift_left c0 24) (Int32.shift_left c1 16)) (Int32.shift_left c2 8)) c3 let _make_int32_le c0 c1 c2 c3 = Int32.logor (Int32.logor (Int32.logor (Int32.shift_left c3 24) (Int32.shift_left c2 16)) (Int32.shift_left c1 8)) c0 (* Extract exactly 32 bits. We have to consider endianness and signedness. *) let extract_int32_be_unsigned data off len flen = let byteoff = off lsr 3 in let strlen = String.length data in let word = (* Optimize the common (byte-aligned) case. *) if off land 7 = 0 then ( let word = let c0 = _get_byte32 data byteoff strlen in let c1 = _get_byte32 data (byteoff+1) strlen in let c2 = _get_byte32 data (byteoff+2) strlen in let c3 = _get_byte32 data (byteoff+3) strlen in _make_int32_be c0 c1 c2 c3 in Int32.shift_right_logical word (32 - flen) ) else ( (* Extract the next 32 bits, slow method. *) let word = let c0 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c1 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c2 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c3 = extract_char_unsigned data off len 8 in let c0 = Int32.of_int c0 in let c1 = Int32.of_int c1 in let c2 = Int32.of_int c2 in let c3 = Int32.of_int c3 in _make_int32_be c0 c1 c2 c3 in Int32.shift_right_logical word (32 - flen) ) in word (*, off+flen, len-flen*) let extract_int32_le_unsigned data off len flen = let v = extract_int32_be_unsigned data off len flen in let v = I32.byteswap v flen in v let extract_int32_ne_unsigned = if nativeendian = BigEndian then extract_int32_be_unsigned else extract_int32_le_unsigned let extract_int32_ee_unsigned = function | BigEndian -> extract_int32_be_unsigned | LittleEndian -> extract_int32_le_unsigned | NativeEndian -> extract_int32_ne_unsigned let _make_int64_be c0 c1 c2 c3 c4 c5 c6 c7 = Int64.logor (Int64.logor (Int64.logor (Int64.logor (Int64.logor (Int64.logor (Int64.logor (Int64.shift_left c0 56) (Int64.shift_left c1 48)) (Int64.shift_left c2 40)) (Int64.shift_left c3 32)) (Int64.shift_left c4 24)) (Int64.shift_left c5 16)) (Int64.shift_left c6 8)) c7 let _make_int64_le c0 c1 c2 c3 c4 c5 c6 c7 = _make_int64_be c7 c6 c5 c4 c3 c2 c1 c0 (* Extract [1..64] bits. We have to consider endianness and signedness. *) let extract_int64_be_unsigned data off len flen = let byteoff = off lsr 3 in let strlen = String.length data in let word = (* Optimize the common (byte-aligned) case. *) if off land 7 = 0 then ( let word = let c0 = _get_byte64 data byteoff strlen in let c1 = _get_byte64 data (byteoff+1) strlen in let c2 = _get_byte64 data (byteoff+2) strlen in let c3 = _get_byte64 data (byteoff+3) strlen in let c4 = _get_byte64 data (byteoff+4) strlen in let c5 = _get_byte64 data (byteoff+5) strlen in let c6 = _get_byte64 data (byteoff+6) strlen in let c7 = _get_byte64 data (byteoff+7) strlen in _make_int64_be c0 c1 c2 c3 c4 c5 c6 c7 in Int64.shift_right_logical word (64 - flen) ) else ( (* Extract the next 64 bits, slow method. *) let word = let c0 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c1 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c2 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c3 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c4 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c5 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c6 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c7 = extract_char_unsigned data off len 8 in let c0 = Int64.of_int c0 in let c1 = Int64.of_int c1 in let c2 = Int64.of_int c2 in let c3 = Int64.of_int c3 in let c4 = Int64.of_int c4 in let c5 = Int64.of_int c5 in let c6 = Int64.of_int c6 in let c7 = Int64.of_int c7 in _make_int64_be c0 c1 c2 c3 c4 c5 c6 c7 in Int64.shift_right_logical word (64 - flen) ) in word (*, off+flen, len-flen*) let extract_int64_le_unsigned data off len flen = let byteoff = off lsr 3 in let strlen = String.length data in let word = (* Optimize the common (byte-aligned) case. *) if off land 7 = 0 then ( let word = let c0 = _get_byte64 data byteoff strlen in let c1 = _get_byte64 data (byteoff+1) strlen in let c2 = _get_byte64 data (byteoff+2) strlen in let c3 = _get_byte64 data (byteoff+3) strlen in let c4 = _get_byte64 data (byteoff+4) strlen in let c5 = _get_byte64 data (byteoff+5) strlen in let c6 = _get_byte64 data (byteoff+6) strlen in let c7 = _get_byte64 data (byteoff+7) strlen in _make_int64_le c0 c1 c2 c3 c4 c5 c6 c7 in Int64.logand word (I64.mask flen) ) else ( (* Extract the next 64 bits, slow method. *) let word = let c0 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c1 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c2 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c3 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c4 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c5 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c6 = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in let c7 = extract_char_unsigned data off len 8 in let c0 = Int64.of_int c0 in let c1 = Int64.of_int c1 in let c2 = Int64.of_int c2 in let c3 = Int64.of_int c3 in let c4 = Int64.of_int c4 in let c5 = Int64.of_int c5 in let c6 = Int64.of_int c6 in let c7 = Int64.of_int c7 in _make_int64_le c0 c1 c2 c3 c4 c5 c6 c7 in Int64.logand word (I64.mask flen) ) in word (*, off+flen, len-flen*) let extract_int64_ne_unsigned = if nativeendian = BigEndian then extract_int64_be_unsigned else extract_int64_le_unsigned let extract_int64_ee_unsigned = function | BigEndian -> extract_int64_be_unsigned | LittleEndian -> extract_int64_le_unsigned | NativeEndian -> extract_int64_ne_unsigned external extract_fastpath_int16_be_unsigned : string -> int -> int = "ocaml_bitstring_extract_fastpath_int16_be_unsigned" "noalloc" external extract_fastpath_int16_le_unsigned : string -> int -> int = "ocaml_bitstring_extract_fastpath_int16_le_unsigned" "noalloc" external extract_fastpath_int16_ne_unsigned : string -> int -> int = "ocaml_bitstring_extract_fastpath_int16_ne_unsigned" "noalloc" external extract_fastpath_int16_be_signed : string -> int -> int = "ocaml_bitstring_extract_fastpath_int16_be_signed" "noalloc" external extract_fastpath_int16_le_signed : string -> int -> int = "ocaml_bitstring_extract_fastpath_int16_le_signed" "noalloc" external extract_fastpath_int16_ne_signed : string -> int -> int = "ocaml_bitstring_extract_fastpath_int16_ne_signed" "noalloc" (* external extract_fastpath_int24_be_unsigned : string -> int -> int = "ocaml_bitstring_extract_fastpath_int24_be_unsigned" "noalloc" external extract_fastpath_int24_le_unsigned : string -> int -> int = "ocaml_bitstring_extract_fastpath_int24_le_unsigned" "noalloc" external extract_fastpath_int24_ne_unsigned : string -> int -> int = "ocaml_bitstring_extract_fastpath_int24_ne_unsigned" "noalloc" external extract_fastpath_int24_be_signed : string -> int -> int = "ocaml_bitstring_extract_fastpath_int24_be_signed" "noalloc" external extract_fastpath_int24_le_signed : string -> int -> int = "ocaml_bitstring_extract_fastpath_int24_le_signed" "noalloc" external extract_fastpath_int24_ne_signed : string -> int -> int = "ocaml_bitstring_extract_fastpath_int24_ne_signed" "noalloc" *) external extract_fastpath_int32_be_unsigned : string -> int -> int32 -> int32 = "ocaml_bitstring_extract_fastpath_int32_be_unsigned" "noalloc" external extract_fastpath_int32_le_unsigned : string -> int -> int32 -> int32 = "ocaml_bitstring_extract_fastpath_int32_le_unsigned" "noalloc" external extract_fastpath_int32_ne_unsigned : string -> int -> int32 -> int32 = "ocaml_bitstring_extract_fastpath_int32_ne_unsigned" "noalloc" external extract_fastpath_int32_be_signed : string -> int -> int32 -> int32 = "ocaml_bitstring_extract_fastpath_int32_be_signed" "noalloc" external extract_fastpath_int32_le_signed : string -> int -> int32 -> int32 = "ocaml_bitstring_extract_fastpath_int32_le_signed" "noalloc" external extract_fastpath_int32_ne_signed : string -> int -> int32 -> int32 = "ocaml_bitstring_extract_fastpath_int32_ne_signed" "noalloc" (* external extract_fastpath_int40_be_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int40_be_unsigned" "noalloc" external extract_fastpath_int40_le_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int40_le_unsigned" "noalloc" external extract_fastpath_int40_ne_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int40_ne_unsigned" "noalloc" external extract_fastpath_int40_be_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int40_be_signed" "noalloc" external extract_fastpath_int40_le_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int40_le_signed" "noalloc" external extract_fastpath_int40_ne_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int40_ne_signed" "noalloc" external extract_fastpath_int48_be_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int48_be_unsigned" "noalloc" external extract_fastpath_int48_le_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int48_le_unsigned" "noalloc" external extract_fastpath_int48_ne_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int48_ne_unsigned" "noalloc" external extract_fastpath_int48_be_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int48_be_signed" "noalloc" external extract_fastpath_int48_le_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int48_le_signed" "noalloc" external extract_fastpath_int48_ne_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int48_ne_signed" "noalloc" external extract_fastpath_int56_be_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int56_be_unsigned" "noalloc" external extract_fastpath_int56_le_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int56_le_unsigned" "noalloc" external extract_fastpath_int56_ne_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int56_ne_unsigned" "noalloc" external extract_fastpath_int56_be_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int56_be_signed" "noalloc" external extract_fastpath_int56_le_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int56_le_signed" "noalloc" external extract_fastpath_int56_ne_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int56_ne_signed" "noalloc" *) external extract_fastpath_int64_be_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int64_be_unsigned" "noalloc" external extract_fastpath_int64_le_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int64_le_unsigned" "noalloc" external extract_fastpath_int64_ne_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int64_ne_unsigned" "noalloc" external extract_fastpath_int64_be_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int64_be_signed" "noalloc" external extract_fastpath_int64_le_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int64_le_signed" "noalloc" external extract_fastpath_int64_ne_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int64_ne_signed" "noalloc" (*----------------------------------------------------------------------*) (* Constructor functions. *) module Buffer = struct type t = { buf : Buffer.t; mutable len : int; (* Length in bits. *) (* Last byte in the buffer (if len is not aligned). We store * it outside the buffer because buffers aren't mutable. *) mutable last : int; } let create () = (* XXX We have almost enough information in the generator to * choose a good initial size. *) { buf = Buffer.create 128; len = 0; last = 0 } let contents { buf = buf; len = len; last = last } = let data = if len land 7 = 0 then Buffer.contents buf else Buffer.contents buf ^ (String.make 1 (Char.chr last)) in data, 0, len (* Add exactly 8 bits. *) let add_byte ({ buf = buf; len = len; last = last } as t) byte = if byte < 0 || byte > 255 then invalid_arg "Bitstring.Buffer.add_byte"; let shift = len land 7 in if shift = 0 then (* Target buffer is byte-aligned. *) Buffer.add_char buf (Char.chr byte) else ( (* Target buffer is unaligned. 'last' is meaningful. *) let first = byte lsr shift in let second = (byte lsl (8 - shift)) land 0xff in Buffer.add_char buf (Char.chr (last lor first)); t.last <- second ); t.len <- t.len + 8 (* Add exactly 1 bit. *) let add_bit ({ buf = buf; len = len; last = last } as t) bit = let shift = 7 - (len land 7) in if shift > 0 then (* Somewhere in the middle of 'last'. *) t.last <- last lor ((if bit then 1 else 0) lsl shift) else ( (* Just a single spare bit in 'last'. *) let last = last lor if bit then 1 else 0 in Buffer.add_char buf (Char.chr last); t.last <- 0 ); t.len <- len + 1 (* Add a small number of bits (definitely < 8). This uses a loop * to call add_bit so it's slow. *) let _add_bits t c slen = if slen < 1 || slen >= 8 then invalid_arg "Bitstring.Buffer._add_bits"; for i = slen-1 downto 0 do let bit = c land (1 lsl i) <> 0 in add_bit t bit done let add_bits ({ buf = buf; len = len } as t) str slen = if slen > 0 then ( if len land 7 = 0 then ( if slen land 7 = 0 then (* Common case - everything is byte-aligned. *) Buffer.add_substring buf str 0 (slen lsr 3) else ( (* Target buffer is aligned. Copy whole bytes then leave the * remaining bits in last. *) let slenbytes = slen lsr 3 in if slenbytes > 0 then Buffer.add_substring buf str 0 slenbytes; let lastidx = min slenbytes (String.length str - 1) in let last = Char.code str.[lastidx] in (* last char *) let mask = 0xff lsl (8 - (slen land 7)) in t.last <- last land mask ); t.len <- len + slen ) else ( (* Target buffer is unaligned. Copy whole bytes using * add_byte which knows how to deal with an unaligned * target buffer, then call add_bit for the remaining < 8 bits. * * XXX This is going to be dog-slow. *) let slenbytes = slen lsr 3 in for i = 0 to slenbytes-1 do let byte = Char.code str.[i] in add_byte t byte done; let bitsleft = slen - (slenbytes lsl 3) in if bitsleft > 0 then ( let c = Char.code str.[slenbytes] in for i = 0 to bitsleft - 1 do let bit = c land (0x80 lsr i) <> 0 in add_bit t bit done ) ); ) end (* Construct a single bit. *) let construct_bit buf b _ _ = Buffer.add_bit buf b (* Construct a field, flen = [2..8]. *) let construct_char_unsigned buf v flen exn = let max_val = 1 lsl flen in if v < 0 || v >= max_val then raise exn; if flen = 8 then Buffer.add_byte buf v else Buffer._add_bits buf v flen (* Construct a field of up to 31 bits. *) let construct_int_be_unsigned buf v flen exn = (* Check value is within range. *) if not (I.range_unsigned v flen) then raise exn; (* Add the bytes. *) I.map_bytes_be (Buffer._add_bits buf) (Buffer.add_byte buf) v flen (* Construct a field of up to 31 bits. *) let construct_int_le_unsigned buf v flen exn = (* Check value is within range. *) if not (I.range_unsigned v flen) then raise exn; (* Add the bytes. *) I.map_bytes_le (Buffer._add_bits buf) (Buffer.add_byte buf) v flen let construct_int_ne_unsigned = if nativeendian = BigEndian then construct_int_be_unsigned else construct_int_le_unsigned let construct_int_ee_unsigned = function | BigEndian -> construct_int_be_unsigned | LittleEndian -> construct_int_le_unsigned | NativeEndian -> construct_int_ne_unsigned (* Construct a field of exactly 32 bits. *) let construct_int32_be_unsigned buf v flen _ = Buffer.add_byte buf (Int32.to_int (Int32.shift_right_logical v 24)); Buffer.add_byte buf (Int32.to_int ((Int32.logand (Int32.shift_right_logical v 16) 0xff_l))); Buffer.add_byte buf (Int32.to_int ((Int32.logand (Int32.shift_right_logical v 8) 0xff_l))); Buffer.add_byte buf (Int32.to_int (Int32.logand v 0xff_l)) let construct_int32_le_unsigned buf v flen _ = Buffer.add_byte buf (Int32.to_int (Int32.logand v 0xff_l)); Buffer.add_byte buf (Int32.to_int ((Int32.logand (Int32.shift_right_logical v 8) 0xff_l))); Buffer.add_byte buf (Int32.to_int ((Int32.logand (Int32.shift_right_logical v 16) 0xff_l))); Buffer.add_byte buf (Int32.to_int (Int32.shift_right_logical v 24)) let construct_int32_ne_unsigned = if nativeendian = BigEndian then construct_int32_be_unsigned else construct_int32_le_unsigned let construct_int32_ee_unsigned = function | BigEndian -> construct_int32_be_unsigned | LittleEndian -> construct_int32_le_unsigned | NativeEndian -> construct_int32_ne_unsigned (* Construct a field of up to 64 bits. *) let construct_int64_be_unsigned buf v flen exn = (* Check value is within range. *) if not (I64.range_unsigned v flen) then raise exn; (* Add the bytes. *) I64.map_bytes_be (Buffer._add_bits buf) (Buffer.add_byte buf) v flen (* Construct a field of up to 64 bits. *) let construct_int64_le_unsigned buf v flen exn = (* Check value is within range. *) if not (I64.range_unsigned v flen) then raise exn; (* Add the bytes. *) I64.map_bytes_le (Buffer._add_bits buf) (Buffer.add_byte buf) v flen let construct_int64_ne_unsigned = if nativeendian = BigEndian then construct_int64_be_unsigned else construct_int64_le_unsigned let construct_int64_ee_unsigned = function | BigEndian -> construct_int64_be_unsigned | LittleEndian -> construct_int64_le_unsigned | NativeEndian -> construct_int64_ne_unsigned (* Construct from a string of bytes, exact multiple of 8 bits * in length of course. *) let construct_string buf str = let len = String.length str in Buffer.add_bits buf str (len lsl 3) (* Construct from a bitstring. *) let construct_bitstring buf (data, off, len) = (* Add individual bits until we get to the next byte boundary of * the underlying string. *) let blen = 7 - ((off + 7) land 7) in let blen = min blen len in let rec loop off len blen = if blen = 0 then (off, len) else ( let b = extract_bit data off len 1 and off = off + 1 and len = len - 1 in Buffer.add_bit buf b; loop off len (blen-1) ) in let off, len = loop off len blen in assert (len = 0 || (off land 7) = 0); (* Add the remaining 'len' bits. *) let data = let off = off lsr 3 in (* XXX dangerous allocation *) if off = 0 then data else String.sub data off (String.length data - off) in Buffer.add_bits buf data len (* Concatenate bitstrings. *) let concat bs = let buf = Buffer.create () in List.iter (construct_bitstring buf) bs; Buffer.contents buf (*----------------------------------------------------------------------*) (* Extract a string from a bitstring. *) let string_of_bitstring (data, off, len) = if off land 7 = 0 && len land 7 = 0 then (* Easy case: everything is byte-aligned. *) String.sub data (off lsr 3) (len lsr 3) else ( (* Bit-twiddling case. *) let strlen = (len + 7) lsr 3 in let str = String.make strlen '\000' in let rec loop data off len i = if len >= 8 then ( let c = extract_char_unsigned data off len 8 and off = off + 8 and len = len - 8 in str.[i] <- Char.chr c; loop data off len (i+1) ) else if len > 0 then ( let c = extract_char_unsigned data off len len in str.[i] <- Char.chr (c lsl (8-len)) ) in loop data off len 0; str ) (* To channel. *) let bitstring_to_chan ((data, off, len) as bits) chan = (* Fail if the bitstring length isn't a multiple of 8. *) if len land 7 <> 0 then invalid_arg "bitstring_to_chan"; if off land 7 = 0 then (* Easy case: string is byte-aligned. *) output chan data (off lsr 3) (len lsr 3) else ( (* Bit-twiddling case: reuse string_of_bitstring *) let str = string_of_bitstring bits in output_string chan str ) let bitstring_to_file bits filename = let chan = open_out_bin filename in try bitstring_to_chan bits chan; close_out chan with exn -> close_out chan; raise exn (*----------------------------------------------------------------------*) (* Comparison. *) let compare ((data1, off1, len1) as bs1) ((data2, off2, len2) as bs2) = (* In the fully-aligned case, this is reduced to string comparison ... *) if off1 land 7 = 0 && len1 land 7 = 0 && off2 land 7 = 0 && len2 land 7 = 0 then ( (* ... but we have to do that by hand because the bits may * not extend to the full length of the underlying string. *) let off1 = off1 lsr 3 and off2 = off2 lsr 3 and len1 = len1 lsr 3 and len2 = len2 lsr 3 in let rec loop i = if i < len1 && i < len2 then ( let c1 = String.unsafe_get data1 (off1 + i) and c2 = String.unsafe_get data2 (off2 + i) in let r = compare c1 c2 in if r <> 0 then r else loop (i+1) ) else len1 - len2 in loop 0 ) else ( (* Slow/unaligned. *) let str1 = string_of_bitstring bs1 and str2 = string_of_bitstring bs2 in let r = String.compare str1 str2 in if r <> 0 then r else len1 - len2 ) let equals ((_, _, len1) as bs1) ((_, _, len2) as bs2) = if len1 <> len2 then false else if bs1 = bs2 then true else 0 = compare bs1 bs2 let is_zeroes_bitstring ((data, off, len) as bits) = if off land 7 = 0 && len land 7 = 0 then ( let off = off lsr 3 and len = len lsr 3 in let rec loop i = if i < len then ( if String.unsafe_get data (off + i) <> '\000' then false else loop (i+1) ) else true in loop 0 ) else ( (* Slow/unaligned case. *) let len = bitstring_length bits in let zeroes = zeroes_bitstring len in 0 = compare bits zeroes ) let is_ones_bitstring ((data, off, len) as bits) = if off land 7 = 0 && len land 7 = 0 then ( let off = off lsr 3 and len = len lsr 3 in let rec loop i = if i < len then ( if String.unsafe_get data (off + i) <> '\xff' then false else loop (i+1) ) else true in loop 0 ) else ( (* Slow/unaligned case. *) let len = bitstring_length bits in let ones = ones_bitstring len in 0 = compare bits ones ) (*----------------------------------------------------------------------*) (* Bit get/set functions. *) let index_out_of_bounds () = invalid_arg "index out of bounds" let put (data, off, len) n v = if n < 0 || n >= len then index_out_of_bounds () else ( let i = off+n in let si = i lsr 3 and mask = 0x80 lsr (i land 7) in let c = Char.code data.[si] in let c = if v <> 0 then c lor mask else c land (lnot mask) in data.[si] <- Char.unsafe_chr c ) let set bits n = put bits n 1 let clear bits n = put bits n 0 let get (data, off, len) n = if n < 0 || n >= len then index_out_of_bounds () else ( let i = off+n in let si = i lsr 3 and mask = 0x80 lsr (i land 7) in let c = Char.code data.[si] in c land mask ) let is_set bits n = get bits n <> 0 let is_clear bits n = get bits n = 0 (*----------------------------------------------------------------------*) (* Display functions. *) let isprint c = let c = Char.code c in c >= 32 && c < 127 let hexdump_bitstring chan (data, off, len) = let count = ref 0 in let off = ref off in let len = ref len in let linelen = ref 0 in let linechars = String.make 16 ' ' in fprintf chan "00000000 "; while !len > 0 do let bits = min !len 8 in let byte = extract_char_unsigned data !off !len bits in off := !off + bits; len := !len - bits; let byte = byte lsl (8-bits) in fprintf chan "%02x " byte; incr count; linechars.[!linelen] <- (let c = Char.chr byte in if isprint c then c else '.'); incr linelen; if !linelen = 8 then fprintf chan " "; if !linelen = 16 then ( fprintf chan " |%s|\n%08x " linechars !count; linelen := 0; for i = 0 to 15 do linechars.[i] <- ' ' done ) done; if !linelen > 0 then ( let skip = (16 - !linelen) * 3 + if !linelen < 8 then 1 else 0 in for i = 0 to skip-1 do fprintf chan " " done; fprintf chan " |%s|\n%!" linechars ) else fprintf chan "\n%!" ocaml-bitstring-2.0.4/COPYING0000664000175000017500000004307012144455551015244 0ustar rjonesrjones GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. ocaml-bitstring-2.0.4/pa_bitstring.ml0000664000175000017500000011652412144455550017234 0ustar rjonesrjones(* Bitstring syntax extension. * Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version, * with the OCaml linking exception described in COPYING.LIB. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: pa_bitstring.ml 189 2012-01-17 13:02:18Z richard.wm.jones@gmail.com $ *) open Printf open Camlp4.PreCast open Syntax open Ast open Bitstring module P = Bitstring_persistent (* If this is true then we emit some debugging code which can * be useful to tell what is happening during matches. You * also need to do 'Bitstring.debug := true' in your main program. * * If this is false then no extra debugging code is emitted. *) let debug = false (* Hashtable storing named persistent patterns. *) let pattern_hash : (string, P.pattern) Hashtbl.t = Hashtbl.create 13 let locfail _loc msg = Loc.raise _loc (Failure msg) (* Work out if an expression is an integer constant. * * Returns [Some i] if so (where i is the integer value), else [None]. * * Fairly simplistic algorithm: we can only detect simple constant * expressions such as [k], [k+c], [k-c] etc. *) let rec expr_is_constant = function | <:expr< $int:i$ >> -> (* Literal integer constant. *) Some (int_of_string i) | <:expr< $lid:op$ $a$ $b$ >> -> (match expr_is_constant a, expr_is_constant b with | Some a, Some b -> (* Integer binary operations. *) let ops = ["+", (+); "-", (-); "*", ( * ); "/", (/); (* NB: explicit fun .. -> is necessary here to work * around a camlp4 bug in OCaml 3.10.0. *) "land", (fun a b -> a land b); "lor", (fun a b -> a lor b); "lxor", (fun a b -> a lxor b); "lsl", (fun a b -> a lsl b); "lsr", (fun a b -> a lsr b); "asr", (fun a b -> a asr b); "mod", (fun a b -> a mod b)] in (try Some ((List.assoc op ops) a b) with Not_found -> None) | _ -> None) | _ -> None (* Generate a fresh, unique symbol each time called. *) let gensym = let i = ref 1000 in fun name -> incr i; let i = !i in sprintf "__pabitstring_%s_%d" name i (* Used to keep track of which qualifiers we've seen in parse_field. *) type whatset_t = { endian_set : bool; signed_set : bool; type_set : bool; offset_set : bool; check_set : bool; bind_set : bool; save_offset_to_set : bool; } let noneset = { endian_set = false; signed_set = false; type_set = false; offset_set = false; check_set = false; bind_set = false; save_offset_to_set = false } (* Deal with the qualifiers which appear for a field of both types. *) let parse_field _loc field qs = let fail = locfail _loc in let whatset, field = match qs with | None -> noneset, field | Some qs -> let check already_set msg = if already_set then fail msg in let apply_qualifier (whatset, field) = function | "endian", Some expr -> check whatset.endian_set "an endian flag has been set already"; let field = P.set_endian_expr field expr in { whatset with endian_set = true }, field | "endian", None -> fail "qualifier 'endian' should be followed by an expression" | "offset", Some expr -> check whatset.offset_set "an offset has been set already"; let field = P.set_offset field expr in { whatset with offset_set = true }, field | "offset", None -> fail "qualifier 'offset' should be followed by an expression" | "check", Some expr -> check whatset.check_set "a check-qualifier has been set already"; let field = P.set_check field expr in { whatset with check_set = true }, field | "check", None -> fail "qualifier 'check' should be followed by an expression" | "bind", Some expr -> check whatset.bind_set "a bind expression has been set already"; let field = P.set_bind field expr in { whatset with bind_set = true }, field | "bind", None -> fail "qualifier 'bind' should be followed by an expression" | "save_offset_to", Some expr (* XXX should be a pattern *) -> check whatset.save_offset_to_set "a save_offset_to-qualifier has been set already"; let id = match expr with | <:expr< $lid:id$ >> -> id | _ -> failwith "pa_bitstring: internal error: save_offset_to only supports simple identifiers at the moment. In future we should support full patterns." in let field = P.set_save_offset_to_lident field id in { whatset with save_offset_to_set = true }, field | "save_offset_to", None -> fail "qualifier 'save_offset_to' should be followed by a binding expression" | s, Some _ -> fail (s ^ ": unknown qualifier, or qualifier should not be followed by an expression") | qual, None -> let endian_quals = ["bigendian", BigEndian; "littleendian", LittleEndian; "nativeendian", NativeEndian] in let sign_quals = ["signed", true; "unsigned", false] in let type_quals = ["int", P.set_type_int; "string", P.set_type_string; "bitstring", P.set_type_bitstring] in if List.mem_assoc qual endian_quals then ( check whatset.endian_set "an endian flag has been set already"; let field = P.set_endian field (List.assoc qual endian_quals) in { whatset with endian_set = true }, field ) else if List.mem_assoc qual sign_quals then ( check whatset.signed_set "a signed flag has been set already"; let field = P.set_signed field (List.assoc qual sign_quals) in { whatset with signed_set = true }, field ) else if List.mem_assoc qual type_quals then ( check whatset.type_set "a type flag has been set already"; let field = (List.assoc qual type_quals) field in { whatset with type_set = true }, field ) else fail (qual ^ ": unknown qualifier, or qualifier should be followed by an expression") in List.fold_left apply_qualifier (noneset, field) qs in (* If type is set to string or bitstring then endianness and * signedness qualifiers are meaningless and must not be set. *) let () = let t = P.get_type field in if (t = P.Bitstring || t = P.String) && (whatset.endian_set || whatset.signed_set) then fail "string types and endian or signed qualifiers cannot be mixed" in (* Default endianness, signedness, type if not set already. *) let field = if whatset.endian_set then field else P.set_endian field BigEndian in let field = if whatset.signed_set then field else P.set_signed field false in let field = if whatset.type_set then field else P.set_type_int field in field type functype = ExtractFunc | ConstructFunc (* Choose the right constructor function. *) let build_bitstring_call _loc functype length endian signed = match functype, length, endian, signed with (* XXX The meaning of signed/unsigned breaks down at * 31, 32, 63 and 64 bits. *) | (ExtractFunc, Some 1, _, _) -> <:expr< Bitstring.extract_bit >> | (ConstructFunc, Some 1, _, _) -> <:expr< Bitstring.construct_bit >> | (functype, Some (2|3|4|5|6|7|8), _, signed) -> let funcname = match functype with | ExtractFunc -> "extract" | ConstructFunc -> "construct" in let sign = if signed then "signed" else "unsigned" in let call = sprintf "%s_char_%s" funcname sign in <:expr< Bitstring.$lid:call$ >> | (functype, len, endian, signed) -> let funcname = match functype with | ExtractFunc -> "extract" | ConstructFunc -> "construct" in let t = match len with | Some i when i <= 31 -> "int" | Some 32 -> "int32" | _ -> "int64" in let sign = if signed then "signed" else "unsigned" in match endian with | P.ConstantEndian constant -> let endianness = match constant with | BigEndian -> "be" | LittleEndian -> "le" | NativeEndian -> "ne" in let call = sprintf "%s_%s_%s_%s" funcname t endianness sign in <:expr< Bitstring.$lid:call$ >> | P.EndianExpr expr -> let call = sprintf "%s_%s_%s_%s" funcname t "ee" sign in <:expr< Bitstring.$lid:call$ $expr$ >> (* Generate the code for a constructor, ie. 'BITSTRING ...'. *) let output_constructor _loc fields = (* This function makes code to raise a Bitstring.Construct_failure exception * containing a message and the current _loc context. * (Thanks to Bluestorm for suggesting this). *) let construct_failure _loc msg = <:expr< Bitstring.Construct_failure ($`str:msg$, $`str:Loc.file_name _loc$, $`int:Loc.start_line _loc$, $`int:Loc.start_off _loc - Loc.start_bol _loc$) >> in let raise_construct_failure _loc msg = <:expr< raise $construct_failure _loc msg$ >> in (* Bitstrings are created like the 'Buffer' module (in fact, using * the Buffer module), by appending snippets to a growing buffer. * This is reasonably efficient and avoids a lot of garbage. *) let buffer = gensym "buffer" in (* General exception which is raised inside the constructor functions * when an int expression is out of range at runtime. *) let exn = gensym "exn" in let exn_used = ref false in (* Convert each field to a simple bitstring-generating expression. *) let fields = List.map ( fun field -> let fexpr = P.get_expr field in let flen = P.get_length field in let endian = P.get_endian field in let signed = P.get_signed field in let t = P.get_type field in let _loc = P.get_location field in let fail = locfail _loc in (* offset(), check(), bind(), save_offset_to() not supported in * constructors. * * Implementation of forward-only offsets is fairly * straightforward: we would need to just calculate the length of * padding here and add it to what has been constructed. For * general offsets, including going backwards, that would require * a rethink in how we construct bitstrings. *) if P.get_offset field <> None then fail "offset expressions are not supported in BITSTRING constructors"; if P.get_check field <> None then fail "check expressions are not supported in BITSTRING constructors"; if P.get_bind field <> None then fail "bind expressions are not supported in BITSTRING constructors"; if P.get_save_offset_to field <> None then fail "save_offset_to is not supported in BITSTRING constructors"; (* Is flen an integer constant? If so, what is it? This * is very simple-minded and only detects simple constants. *) let flen_is_const = expr_is_constant flen in let int_construct_const (i, endian, signed) = build_bitstring_call _loc ConstructFunc (Some i) endian signed in let int_construct (endian, signed) = build_bitstring_call _loc ConstructFunc None endian signed in let expr = match t, flen_is_const with (* Common case: int field, constant flen. * * Range checks are done inside the construction function * because that's a lot simpler w.r.t. types. It might * be better to move them here. XXX *) | P.Int, Some i when i > 0 && i <= 64 -> let construct_fn = int_construct_const (i,endian,signed) in exn_used := true; <:expr< $construct_fn$ $lid:buffer$ $fexpr$ $`int:i$ $lid:exn$ >> | P.Int, Some _ -> fail "length of int field must be [1..64]" (* Int field, non-constant length. We need to perform a runtime * test to ensure the length is [1..64]. * * Range checks are done inside the construction function * because that's a lot simpler w.r.t. types. It might * be better to move them here. XXX *) | P.Int, None -> let construct_fn = int_construct (endian,signed) in exn_used := true; <:expr< if $flen$ >= 1 && $flen$ <= 64 then $construct_fn$ $lid:buffer$ $fexpr$ $flen$ $lid:exn$ else $raise_construct_failure _loc "length of int field must be [1..64]"$ >> (* String, constant length > 0, must be a multiple of 8. *) | P.String, Some i when i > 0 && i land 7 = 0 -> let bs = gensym "bs" in let j = i lsr 3 in <:expr< let $lid:bs$ = $fexpr$ in if String.length $lid:bs$ = $`int:j$ then Bitstring.construct_string $lid:buffer$ $lid:bs$ else $raise_construct_failure _loc "length of string does not match declaration"$ >> (* String, constant length -1, means variable length string * with no checks. *) | P.String, Some (-1) -> <:expr< Bitstring.construct_string $lid:buffer$ $fexpr$ >> (* String, constant length = 0 is probably an error, and so is * any other value. *) | P.String, Some _ -> fail "length of string must be > 0 and a multiple of 8, or the special value -1" (* String, non-constant length. * We check at runtime that the length is > 0, a multiple of 8, * and matches the declared length. *) | P.String, None -> let bslen = gensym "bslen" in let bs = gensym "bs" in <:expr< let $lid:bslen$ = $flen$ in if $lid:bslen$ > 0 then ( if $lid:bslen$ land 7 = 0 then ( let $lid:bs$ = $fexpr$ in if String.length $lid:bs$ = ($lid:bslen$ lsr 3) then Bitstring.construct_string $lid:buffer$ $lid:bs$ else $raise_construct_failure _loc "length of string does not match declaration"$ ) else $raise_construct_failure _loc "length of string must be a multiple of 8"$ ) else $raise_construct_failure _loc "length of string must be > 0"$ >> (* Bitstring, constant length >= 0. *) | P.Bitstring, Some i when i >= 0 -> let bs = gensym "bs" in <:expr< let $lid:bs$ = $fexpr$ in if Bitstring.bitstring_length $lid:bs$ = $`int:i$ then Bitstring.construct_bitstring $lid:buffer$ $lid:bs$ else $raise_construct_failure _loc "length of bitstring does not match declaration"$ >> (* Bitstring, constant length -1, means variable length bitstring * with no checks. *) | P.Bitstring, Some (-1) -> <:expr< Bitstring.construct_bitstring $lid:buffer$ $fexpr$ >> (* Bitstring, constant length < -1 is an error. *) | P.Bitstring, Some _ -> fail "length of bitstring must be >= 0 or the special value -1" (* Bitstring, non-constant length. * We check at runtime that the length is >= 0 and matches * the declared length. *) | P.Bitstring, None -> let bslen = gensym "bslen" in let bs = gensym "bs" in <:expr< let $lid:bslen$ = $flen$ in if $lid:bslen$ >= 0 then ( let $lid:bs$ = $fexpr$ in if Bitstring.bitstring_length $lid:bs$ = $lid:bslen$ then Bitstring.construct_bitstring $lid:buffer$ $lid:bs$ else $raise_construct_failure _loc "length of bitstring does not match declaration"$ ) else $raise_construct_failure _loc "length of bitstring must be > 0"$ >> in expr ) fields in (* Create the final bitstring. Start by creating an empty buffer * and then evaluate each expression above in turn which will * append some more to the bitstring buffer. Finally extract * the bitstring. * * XXX We almost have enough information to be able to guess * a good initial size for the buffer. *) let fields = match fields with | [] -> <:expr< [] >> | h::t -> List.fold_left (fun h t -> <:expr< $h$; $t$ >>) h t in let expr = <:expr< let $lid:buffer$ = Bitstring.Buffer.create () in $fields$; Bitstring.Buffer.contents $lid:buffer$ >> in if !exn_used then <:expr< let $lid:exn$ = $construct_failure _loc "value out of range"$ in $expr$ >> else expr (* Generate the code for a bitmatch statement. '_loc' is the * location, 'bs' is the bitstring parameter, 'cases' are * the list of cases to test against. *) let output_bitmatch _loc bs cases = (* These symbols are used through the generated code to record our * current position within the bitstring: * * data - original bitstring data (string, never changes) * off - current offset within data (int, increments as we move through * the bitstring) * len - current remaining length within data (int, decrements as * we move through the bitstring) * * Also: * * original_off - saved offset at the start of the match (never changes) * original_len - saved length at the start of the match (never changes) * off_aligned - true if the original offset is byte-aligned (allows * us to make some common optimizations) *) let data = gensym "data" and off = gensym "off" and len = gensym "len" and original_off = gensym "original_off" and original_len = gensym "original_len" and off_aligned = gensym "off_aligned" (* This is where the result will be stored (a reference). *) and result = gensym "result" in (* This generates the field extraction code for each * field in a single case. There must be enough remaining data * in the bitstring to satisfy the field. * * As we go through the fields, symbols 'data', 'off' and 'len' * track our position and remaining length in the bitstring. * * The whole thing is a lot of nested 'if'/'match' statements. * Code is generated from the inner-most (last) field outwards. *) let rec output_field_extraction inner = function | [] -> inner | field :: fields -> let fpatt = P.get_patt field in let flen = P.get_length field in let endian = P.get_endian field in let signed = P.get_signed field in let t = P.get_type field in let _loc = P.get_location field in let fail = locfail _loc in (* Is flen (field len) an integer constant? If so, what is it? * This will be [Some i] if it's a constant or [None] if it's * non-constant or we couldn't determine. *) let flen_is_const = expr_is_constant flen in (* Surround the inner expression by check and bind clauses, so: * if $check$ then * let $bind...$ in * $inner$ * where the check and bind are switched on only if they are * present in the field. (In the common case when neither * clause is present, expr = inner). Note the order of the * check & bind is visible to the user and defined in the * documentation, so it must not change. *) let expr = inner in let expr = match P.get_bind field with | None -> expr | Some bind_expr -> <:expr< let $fpatt$ = $bind_expr$ in $expr$ >> in let expr = match P.get_check field with | None -> expr | Some check_expr -> <:expr< if $check_expr$ then $expr$ >> in (* Compute the offset of this field within the match, if it * can be known at compile time. * * Actually, we'll compute two things: the 'natural_field_offset' * is the offset assuming this field had no offset() qualifier * (in other words, its position, immediately following the * preceding field). 'field_offset' is the real field offset * taking into account any offset() qualifier. * * This will be [Some i] if our current offset is known * at compile time, or [None] if we can't determine it. *) let natural_field_offset, field_offset = let has_constant_offset field = match P.get_offset field with | None -> false | Some expr -> match expr_is_constant expr with | None -> false | Some i -> true in let get_constant_offset field = match P.get_offset field with | None -> assert false | Some expr -> match expr_is_constant expr with | None -> assert false | Some i -> i in let has_constant_len field = match expr_is_constant (P.get_length field) with | None -> false | Some i when i > 0 -> true | Some _ -> false in let get_constant_len field = match expr_is_constant (P.get_length field) with | None -> assert false | Some i when i > 0 -> i | Some _ -> assert false in (* NB: We are looping over the PRECEDING fields in reverse order. *) let rec loop = function (* first field has constant offset 0 *) | [] -> Some 0 (* preceding field with constant offset & length *) | f :: _ when has_constant_offset f && has_constant_len f -> Some (get_constant_offset f + get_constant_len f) (* preceding field with no offset & constant length *) | f :: fs when P.get_offset f = None && has_constant_len f -> (match loop fs with | None -> None | Some offset -> Some (offset + get_constant_len f)) (* else, can't work out the offset *) | _ -> None in let natural_field_offset = loop fields in let field_offset = match P.get_offset field with | None -> natural_field_offset | Some expr -> (* has an offset() clause *) match expr_is_constant expr with | None -> None | i -> i in natural_field_offset, field_offset in (* Also compute if the field_offset is known to be byte-aligned at * compile time, which is usually both the common and best possible * case for generating optimized code. * * This is None if not aligned / don't know. * Or Some byte_offset if we can work it out. *) let field_offset_aligned = match field_offset with | None -> None (* unknown, assume no *) | Some off when off land 7 = 0 -> Some (off lsr 3) | Some _ -> None in (* definitely no *) (* Now build the code which matches a single field. *) let int_extract_const i endian signed = build_bitstring_call _loc ExtractFunc (Some i) endian signed in let int_extract endian signed = build_bitstring_call _loc ExtractFunc None endian signed in let expr = match t, flen_is_const, field_offset_aligned, endian, signed with (* Very common cases: int field, constant 8/16/32/64 bit * length, aligned to the match at a known offset. We * still have to check if the bitstring is aligned (can only * be known at runtime) but we may be able to directly access * the bytes in the string. *) | P.Int, Some 8, Some field_byte_offset, _, _ -> let extract_fn = int_extract_const 8 endian signed in (* The fast-path code when everything is aligned. *) let fastpath = <:expr< let o = ($lid:original_off$ lsr 3) + $`int:field_byte_offset$ in Char.code (String.unsafe_get $lid:data$ o) >> in <:expr< if $lid:len$ >= 8 then ( let v = if $lid:off_aligned$ then $fastpath$ else $extract_fn$ $lid:data$ $lid:off$ $lid:len$ 8 in let $lid:off$ = $lid:off$ + 8 and $lid:len$ = $lid:len$ - 8 in match v with $fpatt$ when true -> $expr$ | _ -> () ) >> | P.Int, Some ((16|32|64) as i), Some field_byte_offset, (P.ConstantEndian _ as endian), signed -> let extract_fn = int_extract_const i endian signed in (* The fast-path code when everything is aligned. *) let fastpath = let fastpath_call = let endian = match endian with | P.ConstantEndian BigEndian -> "be" | P.ConstantEndian LittleEndian -> "le" | P.ConstantEndian NativeEndian -> "ne" | P.EndianExpr _ -> assert false in let signed = if signed then "signed" else "unsigned" in let name = sprintf "extract_fastpath_int%d_%s_%s" i endian signed in match i with | 16 -> <:expr< Bitstring.$lid:name$ $lid:data$ o >> | 32 -> <:expr< (* must allocate a new zero each time *) let zero = Int32.of_int 0 in Bitstring.$lid:name$ $lid:data$ o zero >> | 64 -> <:expr< (* must allocate a new zero each time *) let zero = Int64.of_int 0 in Bitstring.$lid:name$ $lid:data$ o zero >> | _ -> assert false in <:expr< (* Starting offset within the string. *) let o = ($lid:original_off$ lsr 3) + $`int:field_byte_offset$ in $fastpath_call$ >> in let slowpath = <:expr< $extract_fn$ $lid:data$ $lid:off$ $lid:len$ $`int:i$ >> in <:expr< if $lid:len$ >= $`int:i$ then ( let v = if $lid:off_aligned$ then $fastpath$ else $slowpath$ in let $lid:off$ = $lid:off$ + $`int:i$ and $lid:len$ = $lid:len$ - $`int:i$ in match v with $fpatt$ when true -> $expr$ | _ -> () ) >> (* Common case: int field, constant flen *) | P.Int, Some i, _, _, _ when i > 0 && i <= 64 -> let extract_fn = int_extract_const i endian signed in let v = gensym "val" in <:expr< if $lid:len$ >= $`int:i$ then ( let $lid:v$ = $extract_fn$ $lid:data$ $lid:off$ $lid:len$ $`int:i$ in let $lid:off$ = $lid:off$ + $`int:i$ and $lid:len$ = $lid:len$ - $`int:i$ in match $lid:v$ with $fpatt$ when true -> $expr$ | _ -> () ) >> | P.Int, Some _, _, _, _ -> fail "length of int field must be [1..64]" (* Int field, non-const flen. We have to test the range of * the field at runtime. If outside the range it's a no-match * (not an error). *) | P.Int, None, _, _, _ -> let extract_fn = int_extract endian signed in let v = gensym "val" in <:expr< if $flen$ >= 1 && $flen$ <= 64 && $flen$ <= $lid:len$ then ( let $lid:v$ = $extract_fn$ $lid:data$ $lid:off$ $lid:len$ $flen$ in let $lid:off$ = $lid:off$ + $flen$ and $lid:len$ = $lid:len$ - $flen$ in match $lid:v$ with $fpatt$ when true -> $expr$ | _ -> () ) >> (* String, constant flen > 0. * The field is at a known byte-aligned offset so we may * be able to optimize the substring extraction. *) | P.String, Some i, Some field_byte_offset, _, _ when i > 0 && i land 7 = 0 -> let fastpath = <:expr< (* Starting offset within the string. *) let o = ($lid:original_off$ lsr 3) + $`int:field_byte_offset$ in String.sub $lid:data$ o $`int:(i lsr 3)$ >> in let slowpath = <:expr< Bitstring.string_of_bitstring ($lid:data$, $lid:off$, $`int:i$) >> in let cond = <:expr< if $lid:off_aligned$ then $fastpath$ else $slowpath$ >> in <:expr< if $lid:len$ >= $`int:i$ then ( let str = $cond$ in let $lid:off$ = $lid:off$ + $`int:i$ and $lid:len$ = $lid:len$ - $`int:i$ in match str with | $fpatt$ when true -> $expr$ | _ -> () ) >> (* String, constant flen > 0. *) | P.String, Some i, None, _, _ when i > 0 && i land 7 = 0 -> <:expr< if $lid:len$ >= $`int:i$ then ( let str = Bitstring.string_of_bitstring ($lid:data$, $lid:off$, $`int:i$) in let $lid:off$ = $lid:off$ + $`int:i$ and $lid:len$ = $lid:len$ - $`int:i$ in match str with | $fpatt$ when true -> $expr$ | _ -> () ) >> (* String, constant flen = -1, means consume all the * rest of the input. * XXX It should be possible to optimize this for known byte * offset, but the optimization is tricky because the end/length * of the string may not be byte-aligned. *) | P.String, Some i, _, _, _ when i = -1 -> let str = gensym "str" in <:expr< let $lid:str$ = Bitstring.string_of_bitstring ($lid:data$, $lid:off$, $lid:len$) in let $lid:off$ = $lid:off$ + $lid:len$ in let $lid:len$ = 0 in match $lid:str$ with | $fpatt$ when true -> $expr$ | _ -> () >> | P.String, Some _, _, _, _ -> fail "length of string must be > 0 and a multiple of 8, or the special value -1" (* String field, non-const flen. We check the flen is > 0 * and a multiple of 8 (-1 is not allowed here), at runtime. *) | P.String, None, _, _, _ -> let bs = gensym "bs" in <:expr< if $flen$ >= 0 && $flen$ <= $lid:len$ && $flen$ land 7 = 0 then ( let $lid:bs$ = ($lid:data$, $lid:off$, $flen$) in let $lid:off$ = $lid:off$ + $flen$ and $lid:len$ = $lid:len$ - $flen$ in match Bitstring.string_of_bitstring $lid:bs$ with | $fpatt$ when true -> $expr$ | _ -> () ) >> (* Bitstring, constant flen >= 0. * At the moment all we can do is assign the bitstring to an * identifier. *) | P.Bitstring, Some i, _, _, _ when i >= 0 -> let ident = match fpatt with | <:patt< $lid:ident$ >> -> ident | <:patt< _ >> -> "_" | _ -> fail "cannot compare a bitstring to a constant" in <:expr< if $lid:len$ >= $`int:i$ then ( let $lid:ident$ = ($lid:data$, $lid:off$, $`int:i$) in let $lid:off$ = $lid:off$ + $`int:i$ and $lid:len$ = $lid:len$ - $`int:i$ in $expr$ ) >> (* Bitstring, constant flen = -1, means consume all the * rest of the input. *) | P.Bitstring, Some i, _, _, _ when i = -1 -> let ident = match fpatt with | <:patt< $lid:ident$ >> -> ident | <:patt< _ >> -> "_" | _ -> fail "cannot compare a bitstring to a constant" in <:expr< let $lid:ident$ = ($lid:data$, $lid:off$, $lid:len$) in let $lid:off$ = $lid:off$ + $lid:len$ in let $lid:len$ = 0 in $expr$ >> | P.Bitstring, Some _, _, _, _ -> fail "length of bitstring must be >= 0 or the special value -1" (* Bitstring field, non-const flen. We check the flen is >= 0 * (-1 is not allowed here) at runtime. *) | P.Bitstring, None, _, _, _ -> let ident = match fpatt with | <:patt< $lid:ident$ >> -> ident | <:patt< _ >> -> "_" | _ -> fail "cannot compare a bitstring to a constant" in <:expr< if $flen$ >= 0 && $flen$ <= $lid:len$ then ( let $lid:ident$ = ($lid:data$, $lid:off$, $flen$) in let $lid:off$ = $lid:off$ + $flen$ and $lid:len$ = $lid:len$ - $flen$ in $expr$ ) >> in (* Computed offset: only offsets forward are supported. * * We try hard to optimize this based on what we know. Are * we at a predictable offset now? (Look at the outer 'fields' * list and see if they all have constant field length starting * at some constant offset). Is this offset constant? * * Based on this we can do a lot of the computation at * compile time, or defer it to runtime only if necessary. * * In all cases, the off and len fields get updated. *) let expr = match P.get_offset field with | None -> expr (* common case: there was no offset expression *) | Some offset_expr -> (* This will be [Some i] if offset is a constant expression * or [None] if it's a non-constant. *) let requested_offset = expr_is_constant offset_expr in (* Look at the field offset (if known) and requested offset * cases and determine what code to generate. *) match natural_field_offset, requested_offset with (* This is the good case: both the field offset and * the requested offset are constant, so we can remove * almost all the runtime checks. *) | Some natural_field_offset, Some requested_offset -> let move = requested_offset - natural_field_offset in if move < 0 then fail (sprintf "requested offset is less than the field offset (%d < %d)" requested_offset natural_field_offset); (* Add some code to move the offset and length by a * constant amount, and a runtime test that len >= 0 * (XXX possibly the runtime test is unnecessary?) *) <:expr< let $lid:off$ = $lid:off$ + $`int:move$ in let $lid:len$ = $lid:len$ - $`int:move$ in if $lid:len$ >= 0 then $expr$ >> (* In any other case, we need to use runtime checks. * * XXX It's not clear if a backwards move detected at runtime * is merely a match failure, or a runtime error. At the * moment it's just a match failure since bitmatch generally * doesn't raise runtime errors. *) | _ -> let move = gensym "move" in <:expr< let $lid:move$ = $offset_expr$ - ($lid:off$ - $lid:original_off$) in if $lid:move$ >= 0 then ( let $lid:off$ = $lid:off$ + $lid:move$ in let $lid:len$ = $lid:len$ - $lid:move$ in if $lid:len$ >= 0 then $expr$ ) >> in (* end of computed offset code *) (* save_offset_to(patt) saves the current offset into a variable. *) let expr = match P.get_save_offset_to field with | None -> expr (* no save_offset_to *) | Some patt -> <:expr< let $patt$ = $lid:off$ - $lid:original_off$ in $expr$ >> in (* Emit extra debugging code. *) let expr = if not debug then expr else ( let field = P.string_of_pattern_field field in <:expr< if !Bitstring.debug then ( Printf.eprintf "PA_BITSTRING: TEST:\n"; Printf.eprintf " %s\n" $str:field$; Printf.eprintf " off %d len %d\n%!" $lid:off$ $lid:len$; (*Bitstring.hexdump_bitstring stderr ($lid:data$,$lid:off$,$lid:len$);*) ); $expr$ >> ) in output_field_extraction expr fields in (* Convert each case in the match. *) let cases = List.map ( fun (fields, bind, whenclause, code) -> let inner = <:expr< $lid:result$ := Some ($code$); raise Exit >> in let inner = match whenclause with | Some whenclause -> <:expr< if $whenclause$ then $inner$ >> | None -> inner in let inner = match bind with | Some name -> <:expr< let $lid:name$ = ($lid:data$, $lid:original_off$, $lid:original_len$) in $inner$ >> | None -> inner in output_field_extraction inner (List.rev fields) ) cases in (* Join them into a single expression. * * Don't do it with a normal fold_right because that leaves * 'raise Exit; ()' at the end which causes a compiler warning. * Hence a bit of complexity here. * * Note that the number of cases is always >= 1 so List.hd is safe. *) let cases = List.rev cases in let cases = List.fold_left (fun base case -> <:expr< $case$ ; $base$ >>) (List.hd cases) (List.tl cases) in (* The final code just wraps the list of cases in a * try/with construct so that each case is tried in * turn until one case matches (that case sets 'result' * and raises 'Exit' to leave the whole statement). * If result isn't set by the end then we will raise * Match_failure with the location of the bitmatch * statement in the original code. *) let loc_fname = Loc.file_name _loc in let loc_line = string_of_int (Loc.start_line _loc) in let loc_char = string_of_int (Loc.start_off _loc - Loc.start_bol _loc) in <:expr< (* Note we save the original offset/length at the start of the match * in 'original_off'/'original_len' symbols. 'data' never changes. * This code also ensures that if original_off/original_len/off_aligned * aren't actually used, we don't get a warning. *) let ($lid:data$, $lid:original_off$, $lid:original_len$) = $bs$ in let $lid:off$ = $lid:original_off$ and $lid:len$ = $lid:original_len$ in let $lid:off_aligned$ = $lid:off$ land 7 = 0 in ignore $lid:off_aligned$; let $lid:result$ = ref None in (try $cases$ with Exit -> ()); match ! $lid:result$ with | Some x -> x | None -> raise (Match_failure ($str:loc_fname$, $int:loc_line$, $int:loc_char$)) >> (* Add a named pattern. *) let add_named_pattern _loc name pattern = Hashtbl.add pattern_hash name pattern (* Expand a named pattern from the pattern_hash. *) let expand_named_pattern _loc name = try Hashtbl.find pattern_hash name with Not_found -> locfail _loc (sprintf "named pattern not found: %s" name) (* Add named patterns from a file. See the documentation on the * directory search path in bitstring_persistent.mli *) let load_patterns_from_file _loc filename = let chan = if Filename.is_relative filename && Filename.is_implicit filename then ( (* Try current directory. *) try open_in filename with _ -> (* Try OCaml library directory. *) try open_in (Filename.concat Bitstring_config.ocamllibdir filename) with exn -> Loc.raise _loc exn ) else ( try open_in filename with exn -> Loc.raise _loc exn ) in let names = ref [] in (try let rec loop () = let name = P.named_from_channel chan in names := name :: !names in loop () with End_of_file -> () ); close_in chan; let names = List.rev !names in List.iter ( function | name, P.Pattern patt -> if patt = [] then locfail _loc (sprintf "pattern %s: no fields" name); add_named_pattern _loc name patt | _, P.Constructor _ -> () (* just ignore these for now *) ) names EXTEND Gram GLOBAL: expr str_item; (* Qualifiers are a list of identifiers ("string", "bigendian", etc.) * followed by an optional expression (used in certain cases). Note * that we are careful not to declare any explicit reserved words. *) qualifiers: [ [ LIST0 [ q = LIDENT; e = OPT [ "("; e = expr; ")" -> e ] -> (q, e) ] SEP "," ] ]; (* Field used in the bitmatch operator (a pattern). This can actually * return multiple fields, in the case where the 'field' is a named * persitent pattern. *) patt_field: [ [ fpatt = patt; ":"; len = expr LEVEL "top"; qs = OPT [ ":"; qs = qualifiers -> qs ] -> let field = P.create_pattern_field _loc in let field = P.set_patt field fpatt in let field = P.set_length field len in [parse_field _loc field qs] (* Normal, single field. *) | ":"; name = LIDENT -> expand_named_pattern _loc name (* Named -> list of fields. *) ] ]; (* Case inside bitmatch operator. *) patt_fields: [ [ "{"; fields = LIST0 patt_field SEP ";"; "}" -> List.concat fields | "{"; "_"; "}" -> [] ] ]; patt_case: [ [ fields = patt_fields; bind = OPT [ "as"; name = LIDENT -> name ]; whenclause = OPT [ "when"; e = expr -> e ]; "->"; code = expr -> (fields, bind, whenclause, code) ] ]; (* Field used in the BITSTRING constructor (an expression). *) constr_field: [ [ fexpr = expr LEVEL "top"; ":"; len = expr LEVEL "top"; qs = OPT [ ":"; qs = qualifiers -> qs ] -> let field = P.create_constructor_field _loc in let field = P.set_expr field fexpr in let field = P.set_length field len in parse_field _loc field qs ] ]; constr_fields: [ [ "{"; fields = LIST0 constr_field SEP ";"; "}" -> fields ] ]; (* 'bitmatch' expressions. *) expr: LEVEL ";" [ [ "bitmatch"; bs = expr; "with"; OPT "|"; cases = LIST1 patt_case SEP "|" -> output_bitmatch _loc bs cases ] (* Constructor. *) | [ "BITSTRING"; fields = constr_fields -> output_constructor _loc fields ] ]; (* Named persistent patterns. * * NB: Currently only allowed at the top level. We can probably lift * this restriction later if necessary. We only deal with patterns * at the moment, not constructors, but the infrastructure to do * constructors is in place. *) str_item: LEVEL "top" [ [ "let"; "bitmatch"; name = LIDENT; "="; fields = patt_fields -> add_named_pattern _loc name fields; (* The statement disappears, but we still need a str_item so ... *) <:str_item< >> | "open"; "bitmatch"; filename = STRING -> load_patterns_from_file _loc filename; <:str_item< >> ] ]; END ocaml-bitstring-2.0.4/tests/0000775000175000017500000000000012144457302015343 5ustar rjonesrjonesocaml-bitstring-2.0.4/tests/test_20_varsize.ml0000664000175000017500000000566012144455550020732 0ustar rjonesrjones(* Construct and match against random variable sized strings. * $Id: test_20_varsize.ml 187 2012-01-17 12:39:09Z richard.wm.jones@gmail.com $ *) open Printf let nr_passes = 10000 let max_size = 8 (* max field size in bits *) (* let () = Bitstring.debug := true *) (* Return a full 64 bits of randomness. *) let rand64 () = let r0 = Int64.shift_left (Int64.of_int (Random.bits ())) 34 in (* 30 bits *) let r1 = Int64.shift_left (Int64.of_int (Random.bits ())) 4 in (* 30 bits *) let r2 = Int64.of_int (Random.int 16) in (* 4 bits *) Int64.logor (Int64.logor r0 r1) r2 (* Return unsigned mask of length bits, bits <= 64. *) let mask64 bits = if bits < 63 then Int64.pred (Int64.shift_left 1L bits) else if bits = 63 then Int64.max_int else if bits = 64 then -1L else invalid_arg "mask64" (* Return a random number between 0 and 2^bits-1 where bits <= 64. *) let rand bits = let r = rand64 () in let m = mask64 bits in Int64.logand r m (* Dump the state in case there is an error. *) let dump n0 n0sz n1 n1sz n2 n2sz n3 n3sz bits r0 r1 r2 r3 = eprintf "dumping state:\n"; eprintf " 0: %3d - %016Lx - %016Lx\n" n0sz n0 r0; eprintf " 1: %3d - %016Lx - %016Lx\n" n1sz n1 r1; eprintf " 2: %3d - %016Lx - %016Lx\n" n2sz n2 r2; eprintf " 3: %3d - %016Lx - %016Lx\n" n3sz n3 r3; eprintf "bits (length = %d):\n" (Bitstring.bitstring_length bits); Bitstring.hexdump_bitstring stderr bits; eprintf "%!" let () = Random.self_init (); for pass = 0 to nr_passes-1 do let n0sz = 1 + Random.int (max_size-1) in let n0 = rand n0sz in let n1sz = 1 + Random.int (max_size-1) in let n1 = rand n1sz in let n2sz = 1 + Random.int (max_size-1) in let n2 = rand n2sz in let n3sz = 1 + Random.int (max_size-1) in let n3 = rand n3sz in (* Construct the bitstring. *) let bits = try (BITSTRING { n0 : n0sz; n1 : n1sz; n2 : n2sz; n3 : n3sz }) with Bitstring.Construct_failure (msg, _, _, _) -> eprintf "FAILED: Construct_failure %s\n%!" msg; dump n0 n0sz n1 n1sz n2 n2sz n3 n3sz (Bitstring.empty_bitstring) 0L 0L 0L 0L; exit 2 in let r0, r1, r2, r3 = bitmatch bits with | { r0 : n0sz; r1 : n1sz; r2 : n2sz; r3 : n3sz; rest : -1 : bitstring } -> let rest_len = Bitstring.bitstring_length rest in if rest_len <> 0 then ( eprintf "FAILED: rest is not zero length (length = %d)\n%!" rest_len; dump n0 n0sz n1 n1sz n2 n2sz n3 n3sz bits 0L 0L 0L 0L; exit 2 ); r0, r1, r2, r3 | { _ } -> eprintf "FAILED: bitmatch operator did not match\n%!"; dump n0 n0sz n1 n1sz n2 n2sz n3 n3sz bits 0L 0L 0L 0L; exit 2 in (*dump n0 n0sz n1 n1sz n2 n2sz n3 n3sz bits r0 r1 r2 r3;*) if n0 <> r0 || n1 <> r1 || n2 <> r2 || n3 <> r3 then ( eprintf "FAILED: numbers returned from match are different\n%!"; dump n0 n0sz n1 n1sz n2 n2sz n3 n3sz bits r0 r1 r2 r3; exit 2 ) done ocaml-bitstring-2.0.4/tests/test_70_check_and_bind.ml0000664000175000017500000000071612144455550022144 0ustar rjonesrjones(* Test check() and bind(). * $Id: test_70_check_and_bind.ml 187 2012-01-17 12:39:09Z richard.wm.jones@gmail.com $ *) open Printf open Bitstring let bits = (BITSTRING { 101 : 16; 202 : 16 }) let () = bitmatch bits with | { i : 16 : check (i = 101), bind (i*4); j : 16 : check (j = 202) } -> if i <> 404 || j <> 202 then failwith (sprintf "70_check_and_bind: failed: %d %d" i j) | { _ } -> failwith "70_check_and_bind: match failed" ocaml-bitstring-2.0.4/tests/test_15_extract_int.ml0000664000175000017500000000523112144455550021571 0ustar rjonesrjones(* Test functions which construct and extract fixed-length ints * of various sizes. * $Id$ *) open Printf open Bitstring let () = for i = 0 to 129 do let zeroes = zeroes_bitstring i in let bits = ( BITSTRING { zeroes : i : bitstring; true : 1; 2 : 2 : littleendian; 2 : 2 : bigendian; 2 : 2 : nativeendian; 3 : 3 : littleendian; 3 : 3 : bigendian; 3 : 3 : nativeendian; 0x5a : 8 : littleendian; 0x5a : 8 : bigendian; 0x5a : 8 : nativeendian; 0xa5a5 : 16 : littleendian; 0xa5a5 : 16 : bigendian; 0xa5a5 : 16 : nativeendian; 0xeeddcc : 24 : littleendian; 0xeeddcc : 24 : bigendian; 0xeeddcc : 24 : nativeendian; 0x48888888 : 31 : littleendian; 0x48888888 : 31 : bigendian; 0x48888888 : 31 : nativeendian; 0xaabbccdd_l : 32 : littleendian; 0xaabbccdd_l : 32 : bigendian; 0xaabbccdd_l : 32 : nativeendian; 0xaabbccddeeff_L : 48 : littleendian; 0xaabbccddeeff_L : 48 : bigendian; 0xaabbccddeeff_L : 48 : nativeendian; 0x0011aabbccddeeff_L : 64 : littleendian; 0x0011aabbccddeeff_L : 64 : bigendian; 0x0011aabbccddeeff_L : 64 : nativeendian } ) in bitmatch bits with | { _ : i : bitstring; a : 1; b0 : 2 : littleendian; b1 : 2 : bigendian; b2 : 2 : nativeendian; c0 : 3 : littleendian; c1 : 3 : bigendian; c2 : 3 : nativeendian; d0 : 8 : littleendian; d1 : 8 : bigendian; d2 : 8 : nativeendian; e0 : 16 : littleendian; e1 : 16 : bigendian; e2 : 16 : nativeendian; f0 : 24 : littleendian; f1 : 24 : bigendian; f2 : 24 : nativeendian; g0 : 31 : littleendian; g1 : 31 : bigendian; g2 : 31 : nativeendian; h0 : 32 : littleendian; h1 : 32 : bigendian; h2 : 32 : nativeendian; j0 : 48 : littleendian; j1 : 48 : bigendian; j2 : 48 : nativeendian; k0 : 64 : littleendian; k1 : 64 : bigendian; k2 : 64 : nativeendian } -> if a <> true || b0 <> 2 || b1 <> 2 || b2 <> 2 || c0 <> 3 || c1 <> 3 || c2 <> 3 || d0 <> 0x5a || d1 <> 0x5a || d2 <> 0x5a || e0 <> 0xa5a5 || e1 <> 0xa5a5 || e2 <> 0xa5a5 || f0 <> 0xeeddcc || f1 <> 0xeeddcc || f2 <> 0xeeddcc || g0 <> 0x48888888 || g1 <> 0x48888888 || g2 <> 0x48888888 || h0 <> 0xaabbccdd_l || h1 <> 0xaabbccdd_l || h2 <> 0xaabbccdd_l || j0 <> 0xaabbccddeeff_L || j1 <> 0xaabbccddeeff_L || j2 <> 0xaabbccddeeff_L || k0 <> 0x0011aabbccddeeff_L || k1 <> 0x0011aabbccddeeff_L || k2 <> 0x0011aabbccddeeff_L then ( eprintf "15_extract_int: match failed %b %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %ld %ld %ld %Ld %Ld %Ld %Ld %Ld %Ld\n" a b0 b1 b2 c0 c1 c2 d0 d1 d2 e0 e1 e2 f0 f1 f2 g0 g1 g2 h0 h1 h2 j0 j1 j2 k0 k1 k2; exit 1 ) | { _ } -> failwith "15_extract_int" done ocaml-bitstring-2.0.4/tests/test_80_hexdump.ml0000664000175000017500000000265012144455550020723 0ustar rjonesrjones(* Test hexdump. * $Id$ *) open Printf open Bitstring let (//) = Filename.concat let testdata = "tests" // "80_testdata" ;; Sys.chdir testdata ;; let diff = Bitstring_config.diff let () = let files = Sys.readdir "." in let files = Array.to_list files in let files = List.filter ( fun filename -> String.length filename > 3 && filename.[0] = 'r' && filename.[1] = 'n' && filename.[2] = 'd' ) files in let files = List.map ( fun filename -> let n = String.sub filename 3 (String.length filename - 3) in let n = int_of_string n in let bits = bitstring_of_file filename in (* 'bitstring_of_file' loads whole bytes. Truncate it to * the real bit-length. *) let bits = takebits n bits in filename, n, bits ) files in (* Hexdump the bits, then compare using external 'diff' program. *) List.iter ( fun (filename, n, bits) -> let output_filename = sprintf "hex%d.actual" n in let chan = open_out output_filename in hexdump_bitstring chan bits; close_out chan ) files; List.iter ( fun (filename, n, bits) -> let actual_filename = sprintf "hex%d.actual" n in let expected_filename = sprintf "hex%d.expected" n in let cmd = sprintf "%s -u %s %s" (Filename.quote diff) (Filename.quote expected_filename) (Filename.quote actual_filename) in if Sys.command cmd <> 0 then ( exit 1 ) ) files ocaml-bitstring-2.0.4/tests/test_31_bitstring_concat.ml0000664000175000017500000000105212144455550022574 0ustar rjonesrjones(* Test concat and the bit get functions. * $Id$ *) let () = for i = 0 to 33 do for j = 0 to 33 do for k = 0 to 33 do let bits = Bitstring.concat [ Bitstring.ones_bitstring i; Bitstring.zeroes_bitstring j; Bitstring.ones_bitstring k ] in assert (Bitstring.bitstring_length bits = i+j+k); for n = 0 to i-1 do assert (Bitstring.is_set bits n) done; for n = i to i+j-1 do assert (Bitstring.is_clear bits n) done; for n = i+j to i+j+k-1 do assert (Bitstring.is_set bits n) done done done done ocaml-bitstring-2.0.4/tests/test_18_extract_32_64_int.ml0000664000175000017500000000174112144455550022413 0ustar rjonesrjones(* Test fix for a regression when extracting 32 and 64 bit aligned * integers (discovered / fixed / tested by Hans Ole Rafaelsen). * $Id$ *) open Printf open Bitstring let bitstring_of_int32 i = BITSTRING { i : 32 } let bitstring_of_int64 i = BITSTRING { i : 64 } let int32_of_bitstring bits = bitmatch bits with | { i : 32 } -> i let int64_of_bitstring bits = bitmatch bits with | { i : 64 } -> i let () = let b1 = bitstring_of_int32 1_l in let b2 = bitstring_of_int32 2_l in let b3 = bitstring_of_int32 3_l in let i1 = int32_of_bitstring b1 in let i2 = int32_of_bitstring b2 in let i3 = int32_of_bitstring b3 in assert (i1 = 1_l); assert (i2 = 2_l); assert (i3 = 3_l); let b1 = bitstring_of_int64 1_L in let b2 = bitstring_of_int64 2_L in let b3 = bitstring_of_int64 3_L in let i1 = int64_of_bitstring b1 in let i2 = int64_of_bitstring b2 in let i3 = int64_of_bitstring b3 in assert (i1 = 1_L); assert (i2 = 2_L); assert (i3 = 3_L) ocaml-bitstring-2.0.4/tests/test_40_endianexpr.ml0000664000175000017500000000153012144455550021376 0ustar rjonesrjones(* Endianness expressions * $Id: test_40_endianexpr.ml 187 2012-01-17 12:39:09Z richard.wm.jones@gmail.com $ *) open Printf open Bitstring let () = let rec loop = function | (e, expected) :: rest -> let bits = BITSTRING { expected : 32 : endian (e); expected : 32 : endian (e); expected : 32 : endian (e) } in (bitmatch bits with | { actual : 32 : endian (e); actual : 32 : endian (e); actual : 32 : endian (e) } -> if actual <> expected then failwith (sprintf "actual %ld <> expected %ld" actual expected) | { _ } as bits -> hexdump_bitstring stderr bits; exit 1 ); loop rest | [] -> () in loop [ BigEndian, 0xa1b2c3d4_l; BigEndian, 0xa1d4c3b2_l; LittleEndian, 0xa1b2c3d4_l; LittleEndian, 0xa1d4c3b2_l; NativeEndian, 0xa1b2c3d4_l; NativeEndian, 0xa1d4c3b2_l; ] ocaml-bitstring-2.0.4/tests/test_61_offset_string.ml0000664000175000017500000000220012144455550022113 0ustar rjonesrjones(* Offset string. The rotation functions used for strings are * very complicated so this is worth testing separately. * $Id: test_61_offset_string.ml 187 2012-01-17 12:39:09Z richard.wm.jones@gmail.com $ *) open Printf open Bitstring let make_bits si n sj m sk = ( let pad1 = ones_bitstring (n-64) in let pad2 = ones_bitstring (m-n-8) in BITSTRING { si : 64 : string; pad1 : n-64 : bitstring; sj : 8 : string; (* this should be at offset(n) *) pad2 : m-n-8 : bitstring; sk : 64 : string (* this should be at offset(m) *) } ) let test_bits bits si n sj m sk = bitmatch bits with | { si' : 64 : string; sj' : 8 : string, offset(n); sk' : 64 : string, offset(m) } when si = si' && sj = sj' && sk = sk' -> () (* ok *) | { _ } -> failwith (sprintf "61_offset_string: test_bits: failed %S %d %S %d %S" si n sj m sk) let () = for n = 64 to 128 do for m = n+8 to 256 do List.iter (fun (si,sj,sk) -> test_bits (make_bits si n sj m sk) si n sj m sk) ["ABCDEFGH", "x", "HGFEDCBA"; "01234567", "0", "76543210"; "abcdefgh", "\x55", "poiuytre"] done; done ocaml-bitstring-2.0.4/tests/80_testdata/0000775000175000017500000000000012144457302017463 5ustar rjonesrjonesocaml-bitstring-2.0.4/tests/80_testdata/rnd340000664000175000017500000000000512144455550020336 0ustar rjonesrjones»¨­ocaml-bitstring-2.0.4/tests/80_testdata/rnd20000664000175000017500000000000112144455550020245 0ustar rjonesrjones°ocaml-bitstring-2.0.4/tests/80_testdata/hex200.expected0000664000175000017500000000023612144455550022220 0ustar rjonesrjones00000000 eb d6 25 f8 21 d6 a5 3d cb 06 3d fe f2 3a b0 a5 |..%.!..=..=..:..| 00000010 de 9a 4b cc fb 3a f1 b1 4a |..K..:..J | ocaml-bitstring-2.0.4/tests/80_testdata/hex33.expected0000664000175000017500000000011712144455550022142 0ustar rjonesrjones00000000 a7 64 a0 cd 00 |.d... | ocaml-bitstring-2.0.4/tests/80_testdata/rnd320000664000175000017500000000000412144455550020333 0ustar rjonesrjones ·[íocaml-bitstring-2.0.4/tests/80_testdata/rnd50000664000175000017500000000000112144455550020250 0ustar rjonesrjones×ocaml-bitstring-2.0.4/tests/80_testdata/rnd670000664000175000017500000000001112144455550020341 0ustar rjonesrjones£(Û¶ÕþC\ocaml-bitstring-2.0.4/tests/80_testdata/rnd630000664000175000017500000000001012144455550020334 0ustar rjonesrjonesý™D7Ö²žocaml-bitstring-2.0.4/tests/80_testdata/hex1000.expected0000664000175000017500000000117012144455550022275 0ustar rjonesrjones00000000 8e 73 d4 ea e8 ce 66 ef ac 06 e2 fe 01 95 40 65 |.s....f.......@e| 00000010 8b 6a b1 1b 1f 5a 0c 86 09 af d9 11 79 1f 9d ee |.j...Z......y...| 00000020 94 86 2d d2 9e a9 02 46 f1 0e d4 99 ac 5b 28 60 |..-....F.....[(`| 00000030 70 21 6f 5b 9b 99 85 bb 3c 4b fa 83 53 f6 c6 fb |p!o[.....6X...h.K..T..]| 00000020 45 89 97 21 23 be a5 8d 36 0d 11 ea 1e 5d bb 90 |E..!#...6....]..| 00000030 71 f1 cd e2 3c fe 27 a5 b5 92 7c 58 a1 a2 80 |q...<.'...|X... | ocaml-bitstring-2.0.4/tests/80_testdata/hex66.expected0000664000175000017500000000011712144455550022150 0ustar rjonesrjones00000000 65 fd ed ab 1e f9 bb b6 40 |e.......@ | ocaml-bitstring-2.0.4/tests/80_testdata/rnd90000664000175000017500000000000212144455550020255 0ustar rjonesrjones3[ocaml-bitstring-2.0.4/tests/80_testdata/rnd2000000664000175000017500000000003112144455550020410 0ustar rjonesrjonesëÖ%ø!Ö¥=Ë=þò:°¥ÞšKÌû:ñ±Jocaml-bitstring-2.0.4/tests/80_testdata/rnd30000664000175000017500000000000112144455550020246 0ustar rjonesrjonesäocaml-bitstring-2.0.4/tests/80_testdata/hex32.expected0000664000175000017500000000011712144455550022141 0ustar rjonesrjones00000000 0d b7 5b ed |..[. | ocaml-bitstring-2.0.4/tests/80_testdata/hex127.expected0000664000175000017500000000013212144455550022223 0ustar rjonesrjones00000000 c3 0f d4 81 b8 02 c0 88 93 89 bf ff 92 67 cc a2 |.............g..| 00000010 ocaml-bitstring-2.0.4/tests/80_testdata/rnd500000664000175000017500000000000712144455550020336 0ustar rjonesrjones4>­³l‚Éocaml-bitstring-2.0.4/tests/80_testdata/hex65.expected0000664000175000017500000000011712144455550022147 0ustar rjonesrjones00000000 be 50 66 8c a3 d7 8e e3 80 |.Pf...... | ocaml-bitstring-2.0.4/tests/80_testdata/hex64.expected0000664000175000017500000000011712144455550022146 0ustar rjonesrjones00000000 02 6b 77 6f f6 f0 4d c8 |.kwo..M. | ocaml-bitstring-2.0.4/tests/80_testdata/hex10.expected0000664000175000017500000000011712144455550022135 0ustar rjonesrjones00000000 cc 40 |.@ | ocaml-bitstring-2.0.4/tests/80_testdata/hex48.expected0000664000175000017500000000011712144455550022150 0ustar rjonesrjones00000000 3f de 0b 20 f3 9f |?.. .. | ocaml-bitstring-2.0.4/tests/80_testdata/rnd640000664000175000017500000000001012144455550020335 0ustar rjonesrjoneskwoöðMÈocaml-bitstring-2.0.4/tests/80_testdata/rnd310000664000175000017500000000000412144455550020332 0ustar rjonesrjonesLÂGocaml-bitstring-2.0.4/tests/80_testdata/rnd110000664000175000017500000000000212144455550020326 0ustar rjonesrjonesO©ocaml-bitstring-2.0.4/tests/80_testdata/rnd10000000664000175000017500000000017512144455550020500 0ustar rjonesrjonesŽsÔêèÎfï¬âþ•@e‹j±Z † ¯Ùy-Òž©FñÔ™¬[(`p!o[›™…»..l.. | ocaml-bitstring-2.0.4/tests/80_testdata/rnd330000664000175000017500000000000512144455550020335 0ustar rjonesrjones§d Íocaml-bitstring-2.0.4/tests/80_testdata/hex47.expected0000664000175000017500000000011712144455550022147 0ustar rjonesrjones00000000 4c ea de d4 3a e4 |L...:. | ocaml-bitstring-2.0.4/tests/80_testdata/rnd1270000664000175000017500000000002012144455550020416 0ustar rjonesrjonesÃÔ¸Àˆ“‰¿ÿ’gÌ¢ocaml-bitstring-2.0.4/tests/80_testdata/hex11.expected0000664000175000017500000000011712144455550022136 0ustar rjonesrjones00000000 4f a0 |O. | ocaml-bitstring-2.0.4/tests/80_testdata/rnd5000000664000175000017500000000007712144455550020425 0ustar rjonesrjonesÇ­EèSïrÀF@©Ð>Ó6X׉h°K¬´T]E‰—!#¾¥6 ê]»qñÍâ<þ'¥µ’|X¡¢…ocaml-bitstring-2.0.4/tests/80_testdata/rnd80000664000175000017500000000000112144455550020253 0ustar rjonesrjonesYocaml-bitstring-2.0.4/tests/80_testdata/rnd40000664000175000017500000000000112144455550020247 0ustar rjonesrjonesocaml-bitstring-2.0.4/tests/80_testdata/hex14.expected0000664000175000017500000000011712144455550022141 0ustar rjonesrjones00000000 27 5c |'\ | ocaml-bitstring-2.0.4/tests/80_testdata/rnd480000664000175000017500000000000612144455550020344 0ustar rjonesrjones?Þ óŸocaml-bitstring-2.0.4/tests/80_testdata/rnd100000664000175000017500000000000212144455550020325 0ustar rjonesrjonesÌDocaml-bitstring-2.0.4/tests/80_testdata/rnd470000664000175000017500000000000612144455550020343 0ustar rjonesrjonesLêÞÔ:äocaml-bitstring-2.0.4/tests/80_testdata/hex4.expected0000664000175000017500000000011712144455550022060 0ustar rjonesrjones00000000 00 |. | ocaml-bitstring-2.0.4/tests/80_testdata/rnd60000664000175000017500000000000112144455550020251 0ustar rjonesrjonesãocaml-bitstring-2.0.4/tests/80_testdata/hex9.expected0000664000175000017500000000011712144455550022065 0ustar rjonesrjones00000000 33 00 |3. | ocaml-bitstring-2.0.4/tests/80_testdata/rnd650000664000175000017500000000001112144455550020337 0ustar rjonesrjones¾PfŒ£×Žã®ocaml-bitstring-2.0.4/tests/80_testdata/hex3.expected0000664000175000017500000000011712144455550022057 0ustar rjonesrjones00000000 e0 |. | ocaml-bitstring-2.0.4/tests/80_testdata/rnd10000664000175000017500000000000112144455550020244 0ustar rjonesrjones[ocaml-bitstring-2.0.4/tests/80_testdata/hex5.expected0000664000175000017500000000011712144455550022061 0ustar rjonesrjones00000000 d0 |. | ocaml-bitstring-2.0.4/tests/test_10_match_bits.ml0000664000175000017500000000465412144455550021365 0ustar rjonesrjones(* Match random bits. * $Id: test_10_match_bits.ml 187 2012-01-17 12:39:09Z richard.wm.jones@gmail.com $ *) open Printf let rec range a b = if a <= b then a :: range (a+1) b else [] let () = Random.self_init (); for len = 0 to 999 do (* Create a random string of bits. *) let expected = List.map (fun _ -> Random.bool ()) (range 0 (len-1)) in let bits = Bitstring.Buffer.create () in List.iter (Bitstring.Buffer.add_bit bits) expected; let bits = Bitstring.Buffer.contents bits in (* Now read the bitstring in groups of 1, 2, 3 .. etc. bits. * In each case check the result against what we generated ('expected'). *) let actual = let rec loop bits = bitmatch bits with | { b0 : 1; rest : -1 : bitstring } -> b0 :: loop rest | { _ } -> [] in loop bits in if actual <> expected then failwith (sprintf "match bits: failed on 1 bit test, len = %d" len); let actual = let rec loop bits = bitmatch bits with | { b0 : 1; b1 : 1; rest : -1 : bitstring } -> b0 :: b1 :: loop rest | { b0 : 1; rest : -1 : bitstring } -> b0 :: loop rest | { _ } -> [] in loop bits in if actual <> expected then failwith (sprintf "match bits: failed on 1 bit test, len = %d" len); let actual = let rec loop bits = bitmatch bits with | { b0 : 1; b1 : 1; b2 : 1; rest : -1 : bitstring } -> b0 :: b1 :: b2 :: loop rest | { b0 : 1; rest : -1 : bitstring } -> b0 :: loop rest | { _ } -> [] in loop bits in if actual <> expected then failwith (sprintf "match bits: failed on 1 bit test, len = %d" len); let actual = let rec loop bits = bitmatch bits with | { b0 : 1; b1 : 1; b2 : 1; b3 : 1; rest : -1 : bitstring } -> b0 :: b1 :: b2 :: b3 :: loop rest | { b0 : 1; rest : -1 : bitstring } -> b0 :: loop rest | { _ } -> [] in loop bits in if actual <> expected then failwith (sprintf "match bits: failed on 1 bit test, len = %d" len); let actual = let rec loop bits = bitmatch bits with | { b0 : 1; b1 : 1; b2 : 1; b3 : 1; b4 : 1; b5 : 1; b6 : 1; b7 : 1; b8 : 1; rest : -1 : bitstring } -> b0 :: b1 :: b2 :: b3 :: b4 :: b5 :: b6 :: b7 :: b8 :: loop rest | { b0 : 1; rest : -1 : bitstring } -> b0 :: loop rest | { _ } -> [] in loop bits in if actual <> expected then failwith (sprintf "match bits: failed on 1 bit test, len = %d" len); done ocaml-bitstring-2.0.4/tests/test_11_match_ints.ml0000664000175000017500000000244012144455550021371 0ustar rjonesrjones(* Match random bits with integers. * $Id: test_11_match_ints.ml 187 2012-01-17 12:39:09Z richard.wm.jones@gmail.com $ *) open Printf let rec range a b = if a <= b then a :: range (a+1) b else [] let () = Random.self_init (); for len = 1 to 99 do for bitlen = 1 to 63 do (* Create a random string of ints. *) let expected = List.map (fun _ -> Random.int64 (Int64.sub (Int64.shift_left 1L bitlen) 1L)) (range 0 (len-1)) in let bits = Bitstring.Buffer.create () in List.iter (fun i -> Bitstring.construct_int64_be_unsigned bits i bitlen (Failure "constructing string")) expected; let bits = Bitstring.Buffer.contents bits in (* Now read the bitstring as integers. * In each case check the result against what we generated ('expected'). *) let actual = let rec loop bits = bitmatch bits with | { i : bitlen; rest : -1 : bitstring } when Bitstring.bitstring_length rest = 0 -> [i] | { i : bitlen; rest : -1 : bitstring } -> i :: loop rest | { _ } -> failwith (sprintf "loop failed with len = %d, bitlen = %d" len bitlen) in loop bits in if actual <> expected then failwith (sprintf "match ints: failed on test, len = %d, bitlen = %d" len bitlen) done done ocaml-bitstring-2.0.4/tests/test_51_open_pattern.ml0000664000175000017500000000067212144455550021747 0ustar rjonesrjones(* Open a persistent pattern * $Id: test_51_open_pattern.ml 187 2012-01-17 12:39:09Z richard.wm.jones@gmail.com $ *) open Printf open Bitstring open bitmatch "tests/test.bmpp" let () = let bits = bitstring_of_string "\022Mary had a little lamb" in bitmatch bits with | { :pascal_string } -> () (*printf "it's a Pascal string, len = %d, string = %S\n" len str*) | { _ } -> eprintf "not matching error\n"; exit 1 ocaml-bitstring-2.0.4/tests/test_91_concat.ml0000664000175000017500000000357012144455550020524 0ustar rjonesrjones(* Regression test for bug in concatenation found by Phil Tomson. * $Id$ *) open Printf open Bitstring let errors = ref 0 let () = let bs_256 = ones_bitstring 256 in assert (bitstring_length bs_256 = 256); let bs2 = BITSTRING { false : 1; (subbitstring bs_256 0 66) : 66 : bitstring } in let len = bitstring_length bs2 in if len <> 67 then ( eprintf "invalid length of bs2: len = %d, expected 67\n" len; hexdump_bitstring stderr bs2; incr errors ); let bs3 = BITSTRING { false : 1; (subbitstring bs_256 0 66) : 66 : bitstring; (subbitstring bs_256 66 67) : 67 : bitstring } in let len = bitstring_length bs3 in if len <> 134 then ( eprintf "invalid length of bs3: len = %d, expected 134\n" len; hexdump_bitstring stderr bs3; incr errors ); let bs4 = BITSTRING { (subbitstring bs_256 66 67) : 67 : bitstring } in let len = bitstring_length bs4 in if len <> 67 then ( eprintf "invalid length of bs4: len = %d, expected 67\n" len; hexdump_bitstring stderr bs4; incr errors ); let bs5 = concat [subbitstring bs_256 0 66; subbitstring bs_256 66 67] in let len = bitstring_length bs5 in if len <> 133 then ( eprintf "invalid length of bs5: len = %d, expected 133\n" len; hexdump_bitstring stderr bs5; incr errors ); let bs6 = concat [ subbitstring bs_256 0 64; subbitstring bs_256 64 64] in let len = bitstring_length bs6 in if len <> 128 then ( eprintf "invalid length of bs6: len = %d, expected 128\n" len; hexdump_bitstring stderr bs6; incr errors ); let bs7 = concat [ subbitstring bs_256 0 65; subbitstring bs_256 65 64] in let len = bitstring_length bs7 in if len <> 129 then ( eprintf "invalid length of bs7: len = %d, expected 129\n" len; hexdump_bitstring stderr bs7; incr errors ); if !errors <> 0 then exit 1 ocaml-bitstring-2.0.4/tests/test_01_load.ml0000664000175000017500000000026212144455550020156 0ustar rjonesrjones(* Just check that the extension and library load without error. * $Id: test_01_load.ml 187 2012-01-17 12:39:09Z richard.wm.jones@gmail.com $ *) let _ = Bitstring.extract_bit ocaml-bitstring-2.0.4/tests/test_02_run.ml0000664000175000017500000000036612144455550020051 0ustar rjonesrjones(* Just check that we can run some functions from the library. * $Id: test_02_run.ml 187 2012-01-17 12:39:09Z richard.wm.jones@gmail.com $ *) let () = let bits = Bitstring.create_bitstring 16 in ignore (Bitstring.string_of_bitstring bits) ocaml-bitstring-2.0.4/tests/test_50_named_pattern.ml0000664000175000017500000000076712144455550022076 0ustar rjonesrjones(* Named pattern * $Id: test_50_named_pattern.ml 187 2012-01-17 12:39:09Z richard.wm.jones@gmail.com $ *) open Printf open Bitstring (* A byte+length Pascal string. *) let bitmatch pascal_string = { len : 8; str : len*8 : string } let () = let bits = bitstring_of_string "\022Mary had a little lamb" in bitmatch bits with | { :pascal_string } -> () (*printf "it's a Pascal string, len = %d, string = %S\n" len str*) | { _ } -> eprintf "not matching error\n"; exit 1 ocaml-bitstring-2.0.4/tests/test_30_bitbuffer.ml0000664000175000017500000000410212144455550021206 0ustar rjonesrjones(* Test the Bitstring.Buffer module and string_of_bitstring in * nasty non-aligned corner cases. * $Id: test_30_bitbuffer.ml 187 2012-01-17 12:39:09Z richard.wm.jones@gmail.com $ *) open Printf let () = Random.self_init (); let str1 = "012345678" in for offset = 0 to 65 do for len = 1 to 65 do let expected = let strlen = (len+7) lsr 3 in let expected = String.create strlen in for i = 0 to strlen-1 do expected.[i] <- Char.chr (Random.int 256) done; let last = Char.code expected.[strlen-1] in let last = last land (0xff lsl (8 - (len land 7))) in expected.[strlen-1] <- Char.chr last; expected in (* Create a random bitstring: * +-------------+-------------------------------------------+ * | (random) | bits that we check (expected) | * +-------------+-------------------------------------------+ * 0 offset offset+len * <---------------- len bits ---------------> *) let bits = let bits = Bitstring.Buffer.create () in Bitstring.Buffer.add_bits bits str1 offset; Bitstring.Buffer.add_bits bits expected len; Bitstring.Buffer.contents bits in (* Create a sub bitstring corresponding to what we want to check. *) let subbits = let bits, bitoffset, bitlen = bits in (bits, bitoffset+offset, bitlen-offset) in assert (Bitstring.bitstring_length subbits = len); (* Now try to read out the substring using string_of_bitstring. *) let actual = Bitstring.string_of_bitstring subbits in if actual <> expected then ( eprintf "MISMATCH between actual and expected, offset=%d, len=%d\n" offset len; eprintf "EXPECTED string:\n"; for i = 0 to String.length expected-1 do eprintf " %02x" (Char.code expected.[i]) done; eprintf "\nACTUAL string:\n"; for i = 0 to String.length actual-1 do eprintf " %02x" (Char.code actual.[i]) done; eprintf "\nBITS:\n"; Bitstring.hexdump_bitstring stderr bits; eprintf "SUBBITS:\n"; Bitstring.hexdump_bitstring stderr subbits; exit 1 ); done done ocaml-bitstring-2.0.4/tests/test_35_load_from_file.ml0000664000175000017500000000257312144455550022216 0ustar rjonesrjones(* Test the various functions to load bitstrings from files. * $Id$ *) open Printf open Bitstring let () = let bits1 = let b1 = make_bitstring 800 '\x5a' in let b2 = make_bitstring 400 '\x88' in ( BITSTRING { b1 : 800 : bitstring; b2 : 400 : bitstring } ) in let bits2 = ( let b = make_bitstring 800 '\xaa' in BITSTRING { b : 800 : bitstring } ) in let bits = concat [bits1; bits2] in let filename, chan = Filename.open_temp_file ~mode:[Open_binary] "bitstring_test" ".tmp" in bitstring_to_chan bits chan; close_out chan; let bits' = bitstring_of_file filename in assert (equals bits bits'); let chan = open_in filename in let bits' = bitstring_of_chan chan in close_in chan; assert (equals bits bits'); let chan = open_in filename in let bits' = bitstring_of_chan_max chan 150 in assert (equals bits1 bits'); let bits' = bitstring_of_chan_max chan 100 in assert (equals bits2 bits'); close_in chan; let fd = Unix.openfile filename [Unix.O_RDONLY] 0 in let bits' = bitstring_of_file_descr fd in Unix.close fd; assert (equals bits bits'); let fd = Unix.openfile filename [Unix.O_RDONLY] 0 in let bits' = bitstring_of_file_descr_max fd 150 in assert (equals bits1 bits'); let bits' = bitstring_of_file_descr_max fd 100 in assert (equals bits2 bits'); Unix.close fd; Unix.unlink filename ocaml-bitstring-2.0.4/tests/test_33_substring.ml0000664000175000017500000000057412144455550021272 0ustar rjonesrjones(* Test subbitstring call. * $Id$ *) open Printf open Bitstring let () = let bits = make_bitstring 65 '\x5a' in for off = 0 to 65 do for len = 65-off to 0 do let sub = subbitstring bits off len in for i = 0 to len-1 do if get bits (off+i) <> get sub i then ( eprintf "33_substring: failed %d %d %d\n" off len i; exit 1 ) done done done ocaml-bitstring-2.0.4/tests/test_65_save_offset_to.ml0000664000175000017500000000242612144455550022263 0ustar rjonesrjones(* Test save_offset_to. * $Id: test_65_save_offset_to.ml 187 2012-01-17 12:39:09Z richard.wm.jones@gmail.com $ *) open Printf open Bitstring let make_bits p i n j m k = ( let pad0 = ones_bitstring p in let pad1 = ones_bitstring (n-8) in let pad2 = ones_bitstring (m-n-8) in BITSTRING { pad0 : p : bitstring; (* will be skipped below *) i : 8; pad1 : n-8 : bitstring; j : 8; (* this should be at offset(n) *) pad2 : m-n-8 : bitstring; k : 8 (* this should be at offset(m) *) } ) let test_bits bits p i n j m k = (* Skip the 'p' padding bits so the match starts at a non-zero offset. *) let bits = dropbits p bits in bitmatch bits with | { i' : 8; _ : n-8 : bitstring; j' : 8 : save_offset_to (j_offset); _ : m-n-8 : bitstring; k' : 8 : save_offset_to (k_offset) } when i = i' && j = j' && k = k' && j_offset = n && k_offset = m -> () (* ok *) | { _ } -> failwith (sprintf "65_save_offset_to: test_bits: failed %d %d %d %d %d %d" p i n j m k) let () = for p = 0 to 4 do for n = 8 to 64 do for m = n+8 to 128 do List.iter (fun (i,j,k) -> test_bits (make_bits p i n j m k) p i n j m k) [0x55, 0xaa, 0x33; 0x33, 0xaa, 0x55; 0x12, 0x34, 0x56] done; done; done ocaml-bitstring-2.0.4/tests/test_90_bind_as.ml0000664000175000017500000000060412144455550020646 0ustar rjonesrjones(* Regression test for bug in 'as-binding' found by Matej Kosik. * $Id$ *) open Printf open Bitstring let bits = Bitstring.ones_bitstring 1 in bitmatch bits with | { _ : 1 } as foo -> let len = Bitstring.bitstring_length foo in if len <> 1 then ( hexdump_bitstring stderr foo; eprintf "test error: length = %d, expecting 1\n" len; exit 1 ) | { _ } -> assert false ocaml-bitstring-2.0.4/tests/test_32_bitstring_compare.ml0000664000175000017500000000312512144455550022757 0ustar rjonesrjones(* Compare bitstrings. * $Id$ *) open Printf let sgn = function | 0 -> 0 | i when i > 0 -> 1 | _ -> -1 let () = for i = 0 to 33 do for j = 0 to 33 do let bits1 = Bitstring.ones_bitstring i and bits2 = Bitstring.ones_bitstring j in let r = Bitstring.compare bits1 bits2 in if sgn r <> sgn (compare i j) then ( eprintf "ones compare failed %d %d %d\n" i j r; exit 1 ) done done; for i = 0 to 33 do for j = 0 to 33 do let bits1 = Bitstring.zeroes_bitstring i and bits2 = Bitstring.zeroes_bitstring j in let r = Bitstring.compare bits1 bits2 in if sgn r <> sgn (compare i j) then ( eprintf "zeroes compare failed %d %d %d\n" i j r; exit 1 ) done done; for i = 0 to 33 do for j = 0 to 33 do let bits1 = Bitstring.make_bitstring i '\x55' and bits2 = Bitstring.make_bitstring j '\x55' in let r = Bitstring.compare bits1 bits2 in if sgn r <> sgn (compare i j) then ( eprintf "x55 compare failed %d %d %d\n" i j r; exit 1 ) done done; for i = 0 to 33 do for j = 0 to 33 do let bits1 = Bitstring.make_bitstring i '\x55' in let bits2 = Bitstring.make_bitstring i '\x55' in let bits2 = Bitstring.concat [Bitstring.zeroes_bitstring j; bits2] in assert (Bitstring.bitstring_length bits2 = j+i); let bits2 = Bitstring.dropbits j bits2 in assert (Bitstring.bitstring_length bits2 = i); let r = Bitstring.compare bits1 bits2 in if r <> 0 then ( eprintf "x55 non-aligned compare failed %d %d %d\n" i j r; exit 1 ) done done ocaml-bitstring-2.0.4/tests/test_60_simple_offset.ml0000664000175000017500000000162412144455550022106 0ustar rjonesrjones(* Simple offset test * $Id: test_60_simple_offset.ml 187 2012-01-17 12:39:09Z richard.wm.jones@gmail.com $ *) open Printf open Bitstring let make_bits i n j m k = ( let pad1 = ones_bitstring (n-8) in let pad2 = ones_bitstring (m-n-8) in BITSTRING { i : 8; pad1 : n-8 : bitstring; j : 8; (* this should be at offset(n) *) pad2 : m-n-8 : bitstring; k : 8 (* this should be at offset(m) *) } ) let test_bits bits i n j m k = bitmatch bits with | { i' : 8; j' : 8 : offset(n); k' : 8 : offset(m) } when i = i' && j = j' && k = k' -> () (* ok *) | { _ } -> failwith (sprintf "60_simple_offset: test_bits: failed %d %d %d %d %d" i n j m k) let () = for n = 8 to 128 do for m = n+8 to 256 do List.iter (fun (i,j,k) -> test_bits (make_bits i n j m k) i n j m k) [0x55, 0xaa, 0x33; 0x33, 0xaa, 0x55; 0x12, 0x34, 0x56] done; done ocaml-bitstring-2.0.4/tests/test_34_takebits.ml0000664000175000017500000000033312144455550021052 0ustar rjonesrjones(* Test takebits call. * $Id$ *) open Printf open Bitstring let () = let bits = make_bitstring 65 '\x5a' in for len = 0 to 65 do let sub = takebits len bits in assert (bitstring_length sub = len) done ocaml-bitstring-2.0.4/tests/test_62_offset_padding.ml0000664000175000017500000000225012144455550022221 0ustar rjonesrjones(* Test computed offsets when original_off <> 0. * $Id: test_62_offset_padding.ml 187 2012-01-17 12:39:09Z richard.wm.jones@gmail.com $ *) open Printf open Bitstring let make_bits p i n j m k = ( let pad0 = ones_bitstring p in let pad1 = ones_bitstring (n-8) in let pad2 = ones_bitstring (m-n-8) in BITSTRING { pad0 : p : bitstring; (* will be skipped below *) i : 8; pad1 : n-8 : bitstring; j : 8; (* this should be at offset(n) *) pad2 : m-n-8 : bitstring; k : 8 (* this should be at offset(m) *) } ) let test_bits bits p i n j m k = (* Skip the 'p' padding bits so the match starts at a non-zero offset. *) let bits = dropbits p bits in bitmatch bits with | { i' : 8; j' : 8 : offset(n); k' : 8 : offset(m) } when i = i' && j = j' && k = k' -> () (* ok *) | { _ } -> failwith (sprintf "62_offset_padding: test_bits: failed %d %d %d %d %d %d" p i n j m k) let () = for p = 1 to 4 do for n = 8 to 128 do for m = n+8 to 256 do List.iter (fun (i,j,k) -> test_bits (make_bits p i n j m k) p i n j m k) [0x55, 0xaa, 0x33; 0x33, 0xaa, 0x55; 0x12, 0x34, 0x56] done; done; done ocaml-bitstring-2.0.4/README0000664000175000017500000000202112144455550015057 0ustar rjonesrjonesocaml-bitstring Copyright (C) 2008-2012 Red Hat Inc, Richard W.M. Jones. This library was formerly known as 'bitmatch'. Please see the html subdirectory for developer documentation. The only requirements are OCaml >= 3.10.0, camlp4, ocamldoc, and findlib. If you optionally have CIL (http://cil.sourceforge.net/) installed then there are some nice extra tools for converting C header files into matchable OCaml structures. To build: ./configure make Other make targets: make check # build and run the test suite make examples # build the examples make print-tests # print expanded test macros make print-examples # print expanded example macros To install (as root): make install LICENSE ---------------------------------------------------------------------- The library is licensed under the LGPL v2 or later, with the OCaml linking exception. See the file COPYING.LIB for full terms. Programs are licensed under the GPL v2 or later. See the file COPYING for full terms. All examples and tests are public domain. ocaml-bitstring-2.0.4/configure.ac0000664000175000017500000000571512144457261016503 0ustar rjonesrjones# Bitstring syntax extension. # Copyright (C) 2008-2013 Red Hat Inc., Richard W.M. Jones # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA dnl Process this file with autoconf to produce a configure script. AC_INIT(ocaml-bitstring,2.0.4) AC_PROG_SED dnl Check for basic C environment. AC_PROG_CC AC_PROG_INSTALL AC_PROG_CPP AC_C_PROTOTYPES test "x$U" != "x" && AC_MSG_ERROR(Compiler not ANSI compliant) AC_PROG_CC_C_O dnl Check for native endianness. AC_C_BIGENDIAN(,, [AC_MSG_ERROR([Machine endianness could not be determined])] ) if test "x$WORDS_BIGENDIAN" = "x"; then NATIVEENDIAN=LittleEndian else NATIVEENDIAN=BigEndian fi AC_SUBST(NATIVEENDIAN) dnl Create byteswap.h if the system doesn't have this file. dnl Written by Oskar Liljeblad. dnl From gnulib, license is LGPLv2+. AC_CHECK_HEADERS([byteswap.h], [ BYTESWAP_H='' ], [ BYTESWAP_H='byteswap.h' ]) AC_SUBST(BYTESWAP_H) dnl Check for basic OCaml environment & findlib. AC_PROG_OCAML AC_PROG_FINDLIB if test "x$OCAMLFIND" = "x"; then AC_MSG_ERROR([You must have ocaml and findlib installed]) fi dnl Check for camlp4 AC_CHECK_PROG(CAMLP4OF,camlp4of.opt,camlp4of.opt,no) if test "x$CAMLP4OF" = "xno"; then AC_MSG_ERROR([You must have camlp4 installed]) fi dnl Check for Extlib (optional) AC_CHECK_OCAML_PKG(extlib) dnl Check for CIL (optional) AC_CHECK_OCAML_PKG(cil) dnl Check for /usr/bin/time and get full path. AC_PATH_PROG(TIME,time,no) if test "x$TIME" = "xno"; then AC_MSG_ERROR(['time' command not found]) fi dnl Check for diff and get full path. AC_PATH_PROG(DIFF,diff,no) if test "x$DIFF" = "xno"; then AC_MSG_ERROR(['diff' command not found]) fi AC_SUBST(DIFF) dnl Check for gprof (optional). AC_CHECK_PROG(GPROF,gprof,gprof,no) dnl Check for ocaml-bisect (optional) and --enable-coverage. AC_CHECK_PROG(BISECT_REPORT,bisect-report,bisect-report,no) AC_ARG_ENABLE([coverage], [AS_HELP_STRING([--enable-coverage], [add code coverage information (slow) @<:@default=no@:>@])], [], [enable_coverage=no]) if test "x$enable_coverage" != "xno" -a "x$BISECT_REPORT" = "xno"; then AC_MSG_ERROR([You must install ocaml-bisect package to get code coverage]) fi AC_SUBST(enable_coverage) dnl Produce output files. AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile META bitstring_config.ml cil-tools/Makefile]) AC_OUTPUT ocaml-bitstring-2.0.4/COPYING.LIB0000664000175000017500000006553612144455551015664 0ustar rjonesrjonesThe Library is distributed under the terms of the GNU Library General Public License version 2 (included below). As a special exception to the GNU Library General Public License, you may link, statically or dynamically, a "work that uses the Library" with a publicly distributed version of the Library to produce an executable file containing portions of the Library, and distribute that executable file under terms of your choice, without any of the additional requirements listed in clause 6 of the GNU Library General Public License. By "a publicly distributed version of the Library", we mean either the unmodified Library as distributed by Red Hat, or a modified version of the Library that is distributed under the conditions defined in clause 2 of the GNU Library General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU Library General Public License. GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. ^L Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. ^L GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. ^L Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. ^L 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. ^L 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. ^L 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. ^L 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS ^L How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! ocaml-bitstring-2.0.4/aclocal.m40000664000175000017500000001447312144456674016065 0ustar rjonesrjones# generated automatically by aclocal 1.12.2 -*- Autoconf -*- # Copyright (C) 1996-2012 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. dnl autoconf macros for OCaml dnl dnl Copyright © 2009 Richard W.M. Jones dnl Copyright © 2009 Stefano Zacchiroli dnl Copyright © 2000-2005 Olivier Andrieu dnl Copyright © 2000-2005 Jean-Christophe Filliâtre dnl Copyright © 2000-2005 Georges Mariano dnl dnl For documentation, please read the ocaml.m4 man page. AC_DEFUN([AC_PROG_OCAML], [dnl # checking for ocamlc AC_CHECK_TOOL([OCAMLC],[ocamlc],[no]) if test "$OCAMLC" != "no"; then OCAMLVERSION=`$OCAMLC -v | sed -n -e 's|.*version* *\(.*\)$|\1|p'` AC_MSG_RESULT([OCaml version is $OCAMLVERSION]) # If OCAMLLIB is set, use it if test "$OCAMLLIB" = ""; then OCAMLLIB=`$OCAMLC -where 2>/dev/null || $OCAMLC -v|tail -1|cut -d ' ' -f 4` else AC_MSG_RESULT([OCAMLLIB previously set; preserving it.]) fi AC_MSG_RESULT([OCaml library path is $OCAMLLIB]) AC_SUBST([OCAMLVERSION]) AC_SUBST([OCAMLLIB]) # checking for ocamlopt AC_CHECK_TOOL([OCAMLOPT],[ocamlopt],[no]) OCAMLBEST=byte if test "$OCAMLOPT" = "no"; then AC_MSG_WARN([Cannot find ocamlopt; bytecode compilation only.]) else TMPVERSION=`$OCAMLOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' ` if test "$TMPVERSION" != "$OCAMLVERSION" ; then AC_MSG_RESULT([versions differs from ocamlc; ocamlopt discarded.]) OCAMLOPT=no else OCAMLBEST=opt fi fi AC_SUBST([OCAMLBEST]) # checking for ocamlc.opt AC_CHECK_TOOL([OCAMLCDOTOPT],[ocamlc.opt],[no]) if test "$OCAMLCDOTOPT" != "no"; then TMPVERSION=`$OCAMLCDOTOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' ` if test "$TMPVERSION" != "$OCAMLVERSION" ; then AC_MSG_RESULT([versions differs from ocamlc; ocamlc.opt discarded.]) else OCAMLC=$OCAMLCDOTOPT fi fi # checking for ocamlopt.opt if test "$OCAMLOPT" != "no" ; then AC_CHECK_TOOL([OCAMLOPTDOTOPT],[ocamlopt.opt],[no]) if test "$OCAMLOPTDOTOPT" != "no"; then TMPVERSION=`$OCAMLOPTDOTOPT -v | sed -n -e 's|.*version* *\(.*\)$|\1|p' ` if test "$TMPVERSION" != "$OCAMLVERSION" ; then AC_MSG_RESULT([version differs from ocamlc; ocamlopt.opt discarded.]) else OCAMLOPT=$OCAMLOPTDOTOPT fi fi fi AC_SUBST([OCAMLOPT]) fi AC_SUBST([OCAMLC]) # checking for ocaml toplevel AC_CHECK_TOOL([OCAML],[ocaml],[no]) # checking for ocamldep AC_CHECK_TOOL([OCAMLDEP],[ocamldep],[no]) # checking for ocamlmktop AC_CHECK_TOOL([OCAMLMKTOP],[ocamlmktop],[no]) # checking for ocamlmklib AC_CHECK_TOOL([OCAMLMKLIB],[ocamlmklib],[no]) # checking for ocamldoc AC_CHECK_TOOL([OCAMLDOC],[ocamldoc],[no]) # checking for ocamlbuild AC_CHECK_TOOL([OCAMLBUILD],[ocamlbuild],[no]) ]) AC_DEFUN([AC_PROG_OCAMLLEX], [dnl # checking for ocamllex AC_CHECK_TOOL([OCAMLLEX],[ocamllex],[no]) if test "$OCAMLLEX" != "no"; then AC_CHECK_TOOL([OCAMLLEXDOTOPT],[ocamllex.opt],[no]) if test "$OCAMLLEXDOTOPT" != "no"; then OCAMLLEX=$OCAMLLEXDOTOPT fi fi AC_SUBST([OCAMLLEX]) ]) AC_DEFUN([AC_PROG_OCAMLYACC], [dnl AC_CHECK_TOOL([OCAMLYACC],[ocamlyacc],[no]) AC_SUBST([OCAMLYACC]) ]) AC_DEFUN([AC_PROG_CAMLP4], [dnl AC_REQUIRE([AC_PROG_OCAML])dnl # checking for camlp4 AC_CHECK_TOOL([CAMLP4],[camlp4],[no]) if test "$CAMLP4" != "no"; then TMPVERSION=`$CAMLP4 -v 2>&1| sed -n -e 's|.*version *\(.*\)$|\1|p'` if test "$TMPVERSION" != "$OCAMLVERSION" ; then AC_MSG_RESULT([versions differs from ocamlc]) CAMLP4=no fi fi AC_SUBST([CAMLP4]) # checking for companion tools AC_CHECK_TOOL([CAMLP4BOOT],[camlp4boot],[no]) AC_CHECK_TOOL([CAMLP4O],[camlp4o],[no]) AC_CHECK_TOOL([CAMLP4OF],[camlp4of],[no]) AC_CHECK_TOOL([CAMLP4OOF],[camlp4oof],[no]) AC_CHECK_TOOL([CAMLP4ORF],[camlp4orf],[no]) AC_CHECK_TOOL([CAMLP4PROF],[camlp4prof],[no]) AC_CHECK_TOOL([CAMLP4R],[camlp4r],[no]) AC_CHECK_TOOL([CAMLP4RF],[camlp4rf],[no]) AC_SUBST([CAMLP4BOOT]) AC_SUBST([CAMLP4O]) AC_SUBST([CAMLP4OF]) AC_SUBST([CAMLP4OOF]) AC_SUBST([CAMLP4ORF]) AC_SUBST([CAMLP4PROF]) AC_SUBST([CAMLP4R]) AC_SUBST([CAMLP4RF]) ]) AC_DEFUN([AC_PROG_FINDLIB], [dnl AC_REQUIRE([AC_PROG_OCAML])dnl # checking for ocamlfind AC_CHECK_TOOL([OCAMLFIND],[ocamlfind],[no]) AC_SUBST([OCAMLFIND]) ]) dnl Thanks to Jim Meyering for working this next bit out for us. dnl XXX We should define AS_TR_SH if it's not defined already dnl (eg. for old autoconf). AC_DEFUN([AC_CHECK_OCAML_PKG], [dnl AC_REQUIRE([AC_PROG_FINDLIB])dnl AC_MSG_CHECKING([for OCaml findlib package $1]) unset found unset pkg found=no for pkg in $1 $2 ; do if $OCAMLFIND query $pkg >/dev/null 2>/dev/null; then AC_MSG_RESULT([found]) AS_TR_SH([OCAML_PKG_$1])=$pkg found=yes break fi done if test "$found" = "no" ; then AC_MSG_RESULT([not found]) AS_TR_SH([OCAML_PKG_$1])=no fi AC_SUBST(AS_TR_SH([OCAML_PKG_$1])) ]) AC_DEFUN([AC_CHECK_OCAML_MODULE], [dnl AC_MSG_CHECKING([for OCaml module $2]) cat > conftest.ml <&5 2>&5 ; then found=yes break fi done if test "$found" ; then AC_MSG_RESULT([$$1]) else AC_MSG_RESULT([not found]) $1=no fi AC_SUBST([$1]) ]) dnl XXX Cross-compiling AC_DEFUN([AC_CHECK_OCAML_WORD_SIZE], [dnl AC_REQUIRE([AC_PROG_OCAML])dnl AC_MSG_CHECKING([for OCaml compiler word size]) cat > conftest.ml < conftest.ml < task_struct.ml * * Tip: Add the --debug flag to that command line to see what's going on. * Also use bitstring-objinfo to examine the bmpp file. */ /* Any defines, etc. necessary to get the include to work. */ #define __KERNEL__ #define CONFIG_HZ 100 #define CONFIG_PAGE_OFFSETUL 0xc0000000 /* XXX? */ #define THREAD_SIZE 4096 /* XXX? */ /* Include files necessary to get the structure(s) and constant(s) we're * interested in. * * Note in this case glibc strips the useful structures out of the * so-called "kernel headers" that it supplies, so instead I have * a local copy of the real headers from a version of Linux. */ #include "linux/sched.h" /* This tells the importer program what structures and constants to import. */ typedef struct task_struct BITSTRING_IMPORT(task_struct); ocaml-bitstring-2.0.4/cil-tools/ext3.c0000664000175000017500000000172512144455551017146 0ustar rjonesrjones/* This is an example import file, showing how to import the ext3 * superblock automatically from Linux header files. * * Use: bitstring-import-c ext3.c > ext3.bmpp * * Tip: Add the --debug flag to that command line to see what's going on. * Also use bitstring-objinfo to examine the bmpp file. */ /* These are required by Linux in order to get the little/big-endian * notations present in the Linux kernel header files. Any other * defines needed can go here. */ #define __CHECKER__ 1 #define __CHECK_ENDIAN__ 1 /* Include files necessary to get the structure(s) and constant(s) we're * interested in. */ #include #include #include /* This tells the importer program what structures and constants to import. */ //typedef struct ext3_super_block BITSTRING_IMPORT(ext3_super_block); typedef struct ext2_super_block BITSTRING_IMPORT(ext3_super_block); BITSTRING_CONSTANT_INT32 (ext3_super_magic, EXT3_SUPER_MAGIC); ocaml-bitstring-2.0.4/cil-tools/bitstring_import_c.ml0000664000175000017500000002754112144455551022356 0ustar rjonesrjones(* Import a C header file. * Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id: bitstring_import_c.ml 142 2008-07-17 15:45:56Z richard.wm.jones $ *) open Printf open ExtList open ExtString open Cil module P = Bitstring_persistent let (//) = Filename.concat let () = (* Parse command line arguments. *) let debug = ref false in let save_temps = ref false in let version () = printf "bitstring-import-c %s" Bitstring.version; exit 1 in let cpp_args = ref [] in let cpp_arg2 name value = cpp_args := (name ^ value) :: !cpp_args in let argspec = Arg.align [ "--debug", Arg.Set debug, " Debug messages"; "--version", Arg.Unit version, " Display version and exit"; "-save-temps", Arg.Set save_temps, " Save temporary files"; "-I", Arg.String (cpp_arg2 "-I"), "dir Specify extra include directory for cpp"; "-D", Arg.String (cpp_arg2 "-D"), "name=value Define value in cpp"; "-U", Arg.String (cpp_arg2 "-U"), "name Undefine value in cpp"; ] in let input_file = ref None in let anon_fun str = match !input_file with | None -> input_file := Some str | Some _ -> eprintf "bitstring-import-c: only give a single input file\n"; exit 1 in let usage_msg = "\ bitstring-import-c: Import C structures and constants and generate bitmatching functions from them. Please see the manual page bitstring-import-c(1) for more information. OPTIONS" in Arg.parse argspec anon_fun usage_msg; let debug = !debug in let save_temps = !save_temps in let input_file = match !input_file with | Some f -> f | None -> eprintf "bitstring-import-c: no input file specified\n"; exit 1 in let cpp_args = List.rev !cpp_args in (* Grab the file and pass it to the preprocessor, and then read the * C code into memory using CIL. *) msvcMode := false; Cil.initCIL (); (* XXX Unavoidable tmp exploit here. Fix? *) let tmp, delete_tmp = if not save_temps then ( let tmp = Filename.temp_file (Filename.temp_dir_name) ".i" in tmp, fun () -> try Unix.unlink tmp with Unix.Unix_error _ -> () ) else ( let tmp = Filename.chop_extension input_file ^ ".i" in tmp, fun () -> (* -save-temps, so do nothing *) () ) in let cmd = sprintf "cpp %s -I %s -include bitstring-import-prefix.h %s > %s" (String.concat " " (List.map Filename.quote cpp_args)) (Filename.quote (Bitstring_config.ocamllibdir // "bitstring")) (Filename.quote input_file) (Filename.quote tmp) in if debug then prerr_endline cmd; if Sys.command cmd <> 0 then ( eprintf "%s: command failed\n" cmd; delete_tmp (); exit 1 ); (* Why does Frontc.parse return a continuation ...? *) let file = (Frontc.parse tmp) () in delete_tmp (); (* Find out which structures, #defines, etc. are to be imported. * (cf. the macros in bitstring-import-prefix.h) *) let constants = List.filter_map ( function | GVar ({vname = vname; vtype = vtype}, { init = Some (SingleInit vinit) }, loc) when String.starts_with vname "__bitstring_constant_" -> let vname = String.sub vname 20 (String.length vname - 20) in (* Do constant folding on the initializer and then calculate * its compile-time value. *) let vinit = match isInteger (constFold true vinit) with | Some i -> i | None -> Errormsg.error "%a: non-constant initializer: %a" d_loc loc d_exp vinit; -1L in Some (vname, vinit, loc) | _ -> None ) file.globals in let structs = List.filter_map ( function | GType ({tname = tname; ttype = ttype}, loc) when String.starts_with tname "__bitstring_import_" -> let tname = String.sub tname 18 (String.length tname - 18) in Some (tname, ttype, loc) | _ -> None ) file.globals in if !Errormsg.hadErrors then exit 1; (* If debugging, print out the imports. *) if debug then ( List.iter ( fun (vname, vinit, loc) -> Errormsg.log "%a: import %s as constant 0x%LX\n" d_loc loc vname vinit; ) constants; List.iter ( fun (tname, ttype, loc) -> Errormsg.log "%a: import %s as %a\n" d_loc loc tname d_type ttype; ) structs; ); (* (* Output constants. * XXX Disabled at the moment until we work out where to put them XXX *) List.iter ( fun (vname, vinit, loc) -> printf "let %s = 0x%LX\n" vname vinit ) constants; *) (* Output structures. *) List.iter ( fun (tname, ttype, loc) -> (* Uncomment the next line if you want to really print the * complete CIL structure of the type (for debugging etc.). * The ASTs printed here are usually quite large. *) (*Errormsg.log "%a: %s %a\n" d_loc loc tname d_plaintype ttype;*) (* Recursive function to generate a persistent pattern from a * C struct or union. Quite a few limitations at the moment: * (1) Structure elements must be in order. * (2) Doesn't really work with unions [XXX]. * * Parameters: * ?names List of names of parent structs. Used in the * recursive case for nested structs. * ?offset Offset of struct within parent, usually NoOffset. Used * in the recursive case for nested structs. * ?endian Inherited endianness, usually None. Used for C * __attribute__((bitwise)). * ttype CIL type of struct. * Returns: * pattern A bitstring persistent pattern. *) let rec pattern_of_struct ?(names=[]) ?(offset=NoOffset) ?(endian=None) ttype = match ttype with (* Some types contain attributes to indicate their * endianness. See many examples from . *) | (TNamed ({ tname = tname; ttype = TNamed (_, attrs) }, _) as t) when hasAttribute "bitwise" attrs -> let endian = if String.starts_with tname "__le" then Some Bitstring.LittleEndian else if String.starts_with tname "__be" then Some Bitstring.BigEndian else ( Errormsg.warn "%a: unknown bitwise attribute typename: %s\n" d_loc loc tname; endian ) in pattern_of_struct ~names ~offset ~endian (unrollType t) (* See into named types. *) | (TNamed _ as t) -> pattern_of_struct ~names ~offset ~endian (unrollType t) (* struct or union *) | TComp ({ cdefined = true; cfields = cfields }, _) -> let cfields = List.map ( fun ({ fname = fname; ftype = ftype } as finfo) -> let offset = Field (finfo, offset) in let names = fname :: names in pattern_of_struct ~names ~offset ~endian ftype ) cfields in List.flatten cfields (* int array with constant length *) | TArray (basetype, (Some _ as len), _) when isIntegralType basetype -> let nr_elems = lenOfArray len in let bitsoffset, totalwidth = bitsOffset ttype offset in let bitswidth = totalwidth / nr_elems (* of the element *) in let basetype = unrollType basetype in let ikind = match basetype with | TInt (ikind, _) -> ikind | t -> Errormsg.unimp "%a: unhandled type: %a" d_loc loc d_type t; IInt in let fname = String.concat "_" (List.rev names) in (* If the base type is 8 bits then we always translate this to * a string (whether the C type is signed or unsigned). There * is no endianness in bytes so ignore that. *) if bitswidth = 8 then [pattern_field_of_string fname bitsoffset nr_elems] else ( (* XXX Realistically we don't handle arrays well at * the moment. Perhaps we should give up and match * this to a bitstring? *) let signed = isSigned ikind in if debug then eprintf "--> array %s: nr_elems=%d signed=%b\n" fname nr_elems signed; [] (* XXX *) ) (* basic integer type *) | TInt (ikind, _) -> let bitsoffset, bitswidth = bitsOffset ttype offset in (*if debug then ( let name = String.concat "." (List.rev names) in Errormsg.log "%s: int: %d, %d\n" name bitsoffset bitswidth );*) let fname = String.concat "_" (List.rev names) in let field = pattern_field_of_int fname bitsoffset bitswidth ikind endian in [field] (* a pointer - in this mapping we assume this is an address * (endianness and wordsize come from function parameters), * in other words we DON'T try to follow pointers, we just * note that they are there. *) | TPtr _ -> let bitsoffset, bitswidth = bitsOffset ttype offset in let fname = String.concat "_" (List.rev names) in if debug then eprintf "--> pointer %s: bitsoffset=%d bitswidth=%d\n" fname bitsoffset bitswidth; [] (* XXX *) | t -> Errormsg.warn "pattern_of_struct: %a: unhandled type: %a" d_loc loc d_type t; [] (* Convert a single int field into a pattern field. * Could be a bitfield, byte, short, etc. *) and pattern_field_of_int fname bitsoffset bitswidth ikind endian = let signed = isSigned ikind in let _loc = camlp4_loc_of_cil_loc loc in let field = P.create_pattern_field _loc in let field = P.set_lident_patt field fname in let field = P.set_type_int field in let field = P.set_length_int field bitswidth in let field = P.set_offset_int field bitsoffset in let field = P.set_signed field signed in let field = match endian with | Some endian -> P.set_endian field endian | None -> P.set_endian field Bitstring.NativeEndian in field and pattern_field_of_string fname bitsoffset nr_elems = let _loc = camlp4_loc_of_cil_loc loc in let field = P.create_pattern_field _loc in let field = P.set_lident_patt field fname in let field = P.set_type_string field in let field = P.set_length_int field (nr_elems*8) in let field = P.set_offset_int field bitsoffset in field (* Convert a CIL location into a camlp4 location. Grrr these * should be compatible! *) and camlp4_loc_of_cil_loc loc = let _loc = Camlp4.PreCast.Syntax.Ast.Loc.mk loc.file in Camlp4.PreCast.Syntax.Ast.Loc.move_line loc.line _loc in (* Match on the type of this structure, and from it generate * a single parsing function. *) match ttype with (* struct or union *) | TComp ({ cdefined = true; cname = cname }, _) -> let pattern = pattern_of_struct ttype in let named_pattern = cname, P.Pattern pattern in P.named_to_channel stdout named_pattern (* An undefined struct or union -- means one which was only ever * defined with 'struct foo;'. This is an error. *) | TComp ({ cdefined = false; cname = cname }, _) -> Errormsg.error "%a: struct or union has no definition: %s" d_loc loc cname (* Types which are not allowed, eg. void, int, arrays. *) | TVoid _ | TInt _ | TFloat _ | TPtr _ | TArray _ | TFun _ | TNamed _ | TBuiltin_va_list _ -> Errormsg.error "%a: not a struct or union: %a" d_loc loc d_type ttype (* Types which we might implement in the future. * For enum we should probably split out enums separately * from structs above, since enums are more like constants. *) | TEnum ({ ename = ename }, _) -> Errormsg.unimp "%a: %a" d_loc loc d_type ttype ) structs; if !Errormsg.hadErrors then exit 1; exit 0 ocaml-bitstring-2.0.4/cil-tools/ext3.ml0000664000175000017500000000167712144455551017342 0ustar rjonesrjones(* This is an example program using an imported C structure. * * The C structure is imported from via "ext3.c" * by the bitstring-import-c program, and saved as "ext3.bmpp". * * Then we can load "ext3.bmpp" here. *) open Printf open bitmatch "ext3.bmpp" let () = (* Load a real ext3 superblock from the examples directory. *) let bits = Bitstring.bitstring_of_file "examples/ext3_sb" in bitmatch bits with | { :ext2_super_block } -> printf "ext3 superblock:\n"; printf " s_inodes_count = %ld\n" s_inodes_count; printf " s_blocks_count = %ld\n" s_blocks_count; printf " s_free_inodes_count = %ld\n" s_free_inodes_count; printf " s_free_blocks_count = %ld\n" s_free_blocks_count; printf " s_uuid = %S\n" s_uuid; printf " s_volume_name = %S\n" s_volume_name; printf " s_last_mounted = %S\n" s_last_mounted | { _ } -> failwith "input is not an ext2/3 superblock" ocaml-bitstring-2.0.4/cil-tools/task_struct.ml0000664000175000017500000000063412144455551021015 0ustar rjonesrjones(* This is an example program using an imported C structure. * * The Linux process table entry structure is imported from * via "task_struct.c" by the bitstring-import-c * program, and saved as "task_struct.bmpp". * * Then we can load "task_struct.bmpp" here. *) open Printf open bitmatch "task_struct.bmpp" (* let () = let bits = Bitstring.bitstring_of_file "examples/ext3_sb" in *) ocaml-bitstring-2.0.4/cil-tools/.depend0000664000175000017500000000031012144455551017344 0ustar rjonesrjonesbitstring_import_c.cmo: ../bitstring_persistent.cmi ../bitstring_config.cmo \ ../bitstring.cmi bitstring_import_c.cmx: ../bitstring_persistent.cmx ../bitstring_config.cmx \ ../bitstring.cmx ocaml-bitstring-2.0.4/cil-tools/Makefile.in0000664000175000017500000000713412144455551020164 0ustar rjonesrjones# Bitstring CIL tools for processing C code. # Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # $Id: Makefile.in 180 2010-01-08 14:43:07Z richard.wm.jones $ PACKAGE = @PACKAGE_NAME@ VERSION = @PACKAGE_VERSION@ OCAMLFIND = @OCAMLFIND@ OCAMLMKLIB = @OCAMLMKLIB@ OCAMLDOC = @OCAMLDOC@ INSTALL = @INSTALL@ enable_coverage = @enable_coverage@ OCAMLCFLAGS = -g OCAMLCPACKAGES = -package dynlink,unix,str,extlib,cil -I +camlp4 -I .. OCAMLCLIBS = $(OCAMLCPACKAGES) camlp4lib.cma -linkpkg ../bitstring.cma ../bitstring_persistent.cma OCAMLOPTFLAGS = OCAMLOPTPACKAGES = $(OCAMLCPACKAGES) OCAMLOPTLIBS = $(OCAMLOPTPACKAGES) camlp4lib.cmxa -linkpkg ../bitstring.cmxa ../bitstring_persistent.cmxa ifneq ($(enable_coverage),no) OCAMLCLIBS := -I +bisect bisect.cma $(OCAMLCLIBS) OCAMLOPTLIBS := -I +bisect bisect.cmxa $(OCAMLOPTLIBS) endif PP = -pp "camlp4o -I .. bitstring.cma bitstring_persistent.cma pa_bitstring.cmo" OCAMLDOCFLAGS = -html -sort all: bitstring-import-c bitstring-import-c.opt bitstring-import-c: bitstring_import_c.cmo $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCLIBS) $< -o $@ bitstring-import-c.opt: bitstring_import_c.cmx $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(OCAMLOPTLIBS) $< -o $@ test: # Examples. # # To compile task_struct you'll need to grab a copy of the Linux # kernel original header files and set the directory below. #DEBUG = DEBUG = --debug LINUX_HEADERS = linux-2.6.25.7-headers LINUX_INCLUDES = -I $(LINUX_HEADERS) #EXAMPLES = ext3 task_struct EXAMPLES = ext3 examples: $(EXAMPLES) ext3: ext3.cmo $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCLIBS) $< -o $@ ext3.cmo: ext3.ml ext3.bmpp $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) $(PP) -c $< -o $@ ext3.bmpp: ext3.c bitstring-import-c rm -f $@.new ./bitstring-import-c $(DEBUG) $< > $@.new mv $@.new $@ task_struct: task_struct.cmo $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCLIBS) $< -o $@ task_struct.cmo: task_struct.ml task_struct.bmpp $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) $(PP) -c $< -o $@ task_struct.bmpp: task_struct.c bitstring-import-c cd $(LINUX_HEADERS) && ln -sf asm-x86 asm rm -f $@.new ./bitstring-import-c $(DEBUG) $(LINUX_INCLUDES) $< > $@.new mv $@.new $@ # Clean. clean: rm -f core *~ *.cmi *.cmo *.cmx *.cma *.cmxa *.a *.o *.bmpp rm -f bitstring-import-c bitstring-import-c.opt rm -f ext3 task_struct distclean: clean # Install. install: # Standard rules. .mli.cmi: $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) -c $< .ml.cmo: $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) -c $< .ml.cmx: $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(OCAMLOPTPACKAGES) -c $< depend: .depend .depend: bitstring_import_c.ml rm -f .depend $(OCAMLFIND) ocamldep $(OCAMLCPACKAGES) $^ > $@ ifeq ($(wildcard .depend),.depend) include .depend endif .PHONY: depend dist check-manifest dpkg doc \ print-examples print-tests examples test .SUFFIXES: .cmo .cmi .cmx .ml .mli .mll ocaml-bitstring-2.0.4/cil-tools/bitstring-import-prefix.h0000664000175000017500000000100312144455551023065 0ustar rjonesrjones/* This file is automagically prefixed to all .ubd files * and provides some macros that we need for CIL. * * This file is in the public domain. */ /* This is needed for older versions of CIL which didn't * support this C99 type. */ #ifndef _Bool #define _Bool unsigned #endif #define BITSTRING_IMPORT(name) __bitstring_import_##name #define BITSTRING_CONSTANT_STRING(name,val) \ char *__bitstring_constant_##name = val #define BITSTRING_CONSTANT_INT32(name,val) \ int __bitstring_constant_##name = val ocaml-bitstring-2.0.4/bitstring_types.ml0000664000175000017500000000217012144455550017767 0ustar rjonesrjones(* Bitstring library. * Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version, * with the OCaml linking exception described in COPYING.LIB. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: bitstring_types.ml 142 2008-07-17 15:45:56Z richard.wm.jones $ *) type endian = BigEndian | LittleEndian | NativeEndian let string_of_endian = function | BigEndian -> "bigendian" | LittleEndian -> "littleendian" | NativeEndian -> "nativeendian" ocaml-bitstring-2.0.4/bitstring_objinfo.ml0000664000175000017500000000303612144455550020253 0ustar rjonesrjones(* Bitstring syntax extension. * Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id: bitstring_objinfo.ml 142 2008-07-17 15:45:56Z richard.wm.jones $ *) open Printf open Bitstring module P = Bitstring_persistent let () = if Array.length Sys.argv <= 1 then failwith "bitstring-objinfo filename.bmpp"; let filename = Sys.argv.(1) in let chan = open_in filename in let names = ref [] in (try let rec loop () = let name = P.named_from_channel chan in names := name :: !names in loop () with End_of_file -> () ); close_in chan; let names = List.rev !names in List.iter ( function | name, P.Pattern patt -> printf "let bitmatch %s =\n%s\n" name (P.string_of_pattern patt) | name, P.Constructor cons -> printf "let BITSTRING %s =\n%s\n" name (P.string_of_constructor cons) ) names ocaml-bitstring-2.0.4/bootstrap0000775000175000017500000000004712144455551016151 0ustar rjonesrjones#!/bin/sh aclocal autoheader autoconf ocaml-bitstring-2.0.4/.depend0000664000175000017500000000104512144457271015446 0ustar rjonesrjonesbitstring.cmo: bitstring_types.cmo bitstring_config.cmo bitstring.cmi bitstring.cmx: bitstring_types.cmx bitstring_config.cmx bitstring.cmi bitstring.cmi: bitstring_objinfo.cmo: bitstring_persistent.cmi bitstring.cmi bitstring_objinfo.cmx: bitstring_persistent.cmx bitstring.cmx bitstring_persistent.cmo: bitstring.cmi bitstring_persistent.cmi bitstring_persistent.cmx: bitstring.cmx bitstring_persistent.cmi bitstring_persistent.cmi: bitstring.cmi create_test_pattern.cmo: bitstring_persistent.cmi create_test_pattern.cmx: bitstring_persistent.cmx ocaml-bitstring-2.0.4/Makefile.in0000664000175000017500000002323012144455550016251 0ustar rjonesrjones# Bitstring syntax extension. # Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # $Id: Makefile.in 197 2012-08-10 11:52:44Z richard.wm.jones@gmail.com $ PACKAGE = @PACKAGE_NAME@ VERSION = @PACKAGE_VERSION@ OCAMLFIND = @OCAMLFIND@ OCAMLMKLIB = @OCAMLMKLIB@ OCAMLDOC = @OCAMLDOC@ INSTALL = @INSTALL@ TIME = @TIME@ GPROF = @GPROF@ SED = @SED@ BISECT_REPORT = @BISECT_REPORT@ BYTESWAP_H = @BYTESWAP_H@ OCAMLLIB = @OCAMLLIB@ top_srcdir = @top_srcdir@ pkg_cil = @OCAML_PKG_cil@ pkg_extlib = @OCAML_PKG_extlib@ enable_coverage = @enable_coverage@ OCAMLCFLAGS = -g OCAMLCPACKAGES = OCAMLCLIBS = -linkpkg OCAMLOPTFLAGS = OCAMLOPTPACKAGES = OCAMLOPTLIBS = -linkpkg ifneq ($(enable_coverage),no) OCAMLCFLAGS += -I +bisect -pp 'camlp4o $(OCAMLLIB)/bisect/instrument.cma' OCAMLCLIBS += -I +bisect bisect.cma OCAMLOPTFLAGS += -I +bisect -pp 'camlp4o $(OCAMLLIB)/bisect/instrument.cma' OCAMLOPTLIBS += -I +bisect bisect.cmxa endif OCAMLDOCFLAGS = -html -sort CC = @CC@ CFLAGS = @CFLAGS@ -Wall -Werror -fPIC -I$(top_srcdir) -I$(OCAMLLIB) LIBRARY_PATH = @abs_top_builddir@ LD_LIBRARY_PATH = @abs_top_builddir@ export LIBRARY_PATH export LD_LIBRARY_PATH SUBDIRS = ifneq ($(pkg_cil),no) ifneq ($(pkg_extlib),no) SUBDIRS += cil-tools endif endif EXAMPLES = $(patsubst %.ml,%,$(wildcard examples/*.ml)) TESTS = $(patsubst %.ml,%,$(wildcard tests/*.ml)) BENCHMARKS = $(patsubst %.ml,%,$(wildcard benchmarks/*.ml)) all: $(BYTESWAP_H) \ bitstring.cma bitstring_persistent.cma \ bitstring.cmxa bitstring_persistent.cmxa \ pa_bitstring.cmo \ bitstring-objinfo @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done bitstring.cma: bitstring_types.cmo bitstring_config.cmo \ bitstring_c.o bitstring.cmo bitmatch.cmo $(OCAMLMKLIB) -o bitstring $^ bitstring_persistent.cma: bitstring_persistent.cmo $(OCAMLFIND) ocamlc -a -o $@ $^ bitstring_persistent.cmo: bitstring_persistent.ml $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) \ -I +camlp4 -pp camlp4of -c $< bitstring.cmxa: bitstring_types.cmx bitstring_config.cmx \ bitstring_c.o bitstring.cmx bitmatch.cmx $(OCAMLMKLIB) -o bitstring $^ bitstring_persistent.cmxa: bitstring_persistent.cmx $(OCAMLFIND) ocamlopt -a -o $@ $^ bitstring_persistent.cmx: bitstring_persistent.ml $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(OCAMLOPTPACKAGES) \ -I +camlp4 -pp camlp4of -c $< bitstring_persistent.cmi: bitstring_persistent.mli $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) \ -I +camlp4 -pp camlp4of -c $< pa_bitstring.cmo: pa_bitstring.ml bitstring.cma bitstring_persistent.cma $(OCAMLFIND) ocamlc bitstring.cma -I +camlp4 dynlink.cma camlp4lib.cma \ -pp camlp4of -c $< -o $@ bitstring-objinfo: bitstring_objinfo.cmo bitstring.cma bitstring_persistent.cma $(OCAMLFIND) ocamlc -I +camlp4 unix.cma dynlink.cma camlp4lib.cma \ $(OCAMLCLIBS) \ bitstring.cma bitstring_persistent.cma \ $< -o $@ # Create byteswap.h if the system doesn't have this file. # From gnulib, license is LGPLv2+. byteswap.h: byteswap.in.h { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ cat $(srcdir)/byteswap.in.h; \ } > $@-t mv -f $@-t $@ # Tests. ifeq ($(enable_coverage),no) PP = -pp 'camlp4o bitstring.cma bitstring_persistent.cma pa_bitstring.cmo' else PP = -pp 'camlp4o $(OCAMLLIB)/bisect/bisect.cma bitstring.cma bitstring_persistent.cma pa_bitstring.cmo' endif check: test test: pa_bitstring.cmo \ bitstring.cma bitstring_persistent.cma \ bitstring.cmxa bitstring_persistent.cmxa \ tests/test.bmpp @for f in $(TESTS); do \ echo Building $$f; \ $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(PP) -package unix $(OCAMLOPTLIBS) -I . bitstring.cmxa $$f.ml -o $$f.opt; \ if [ $$? -ne 0 ]; then exit 1; fi; \ echo Running $$f; \ $$f.opt; \ if [ $$? -ne 0 ]; then exit 1; fi; \ done @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done tests/test.bmpp: create_test_pattern ./$< $@.new mv $@.new $@ create_test_pattern: create_test_pattern.cmo $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -pp camlp4of \ unix.cma -I +camlp4 dynlink.cma camlp4lib.cma \ $(OCAMLCLIBS) \ -I . bitstring.cma bitstring_persistent.cma $< -o $@ create_test_pattern.cmo: create_test_pattern.ml $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -pp camlp4of \ unix.cma -I +camlp4 \ -I . -c $< -o $@ # Coverage of tests. ifneq ($(BISECT_REPORT),no) coverage: rm -f coverage-report/* rm -f bisect*.out $(MAKE) test $(BISECT_REPORT) -html coverage-report bisect*.out rm -f bisect*.out @echo Coverage report is in `pwd`/coverage-report/index.html endif # Examples. examples: pa_bitstring.cmo bitstring.cma bitstring_persistent.cma @for f in $(EXAMPLES); do \ echo Building $$f; \ $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(PP) \ -package unix -linkpkg -I . bitstring.cma $$f.ml -o $$f; \ if [ $$? -ne 0 ]; then exit 1; fi; \ done @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done print-tests: pa_bitstring.cmo bitstring_persistent.cma @for f in $(TESTS); do \ echo Test: $$f.ml; \ cmd="camlp4o bitstring.cma bitstring_persistent.cma pa_bitstring.cmo \ -printer pr_o.cmo $$f.ml"; \ echo $$cmd; \ $$cmd; \ done print-examples: pa_bitstring.cmo @for f in $(EXAMPLES); do \ echo Example: $$f.ml; \ camlp4o bitstring.cma bitstring_persistent.cma pa_bitstring.cmo \ -printer pr_o.cmo $$f.ml; \ if [ $$? -ne 0 ]; then exit 1; fi; \ done # Benchmarks. ifneq ($(TIME),no) benchmarks: pa_bitstring.cmo bitstring.cma bitstring_persistent.cma @for f in $(BENCHMARKS); do \ $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(PP) \ -package unix -linkpkg -I . bitstring.cmxa $$f.ml -o $$f.opt; \ if [ $$? -ne 0 ]; then exit 1; fi; \ $(TIME) -f "$$f: %e seconds" $$f.opt; \ if [ $$? -ne 0 ]; then exit 1; fi; \ done ifneq ($(GPROF),no) @for f in $(BENCHMARKS); do \ $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(PP) -p \ -package unix -linkpkg -I . bitstring.cmxa $$f.ml -o $$f.opt.p; \ if [ $$? -ne 0 ]; then exit 1; fi; \ rm -f gmon.out; \ $$f.opt.p; \ if [ $$? -ne 0 ]; then exit 1; fi; \ gprof $$f.opt.p > $$f.profile; \ if [ $$? -ne 0 ]; then exit 1; fi; \ echo "Wrote profile of $$f"; \ echo " to $$f.profile"; \ rm -f gmon.out; \ done endif endif # Clean. clean: rm -f core *~ *.cmi *.cmo *.cmx *.cma *.cmxa *.cmp *.a *.o *.so rm -f tests/*~ tests/*.cmi tests/*.cmo tests/*.cmx tests/*.opt rm -f tests/*.o rm -f examples/*~ examples/*.cmi examples/*.cmo examples/*.cmx rm -f examples/*.o $(EXAMPLES) rm -f benchmarks/*~ benchmarks/*.cmi benchmarks/*.cmo rm -f benchmarks/*.cmx benchmarks/*.o rm -f benchmarks/*.opt benchmarks/*.opt.p benchmarks/*.profile rm -f create_test_pattern bitstring-objinfo @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done distclean: clean rm -rf autom4te.cache rm -f config.log config.status rm -f config.h Makefile META bitstring_config.ml rm -f bitstring-objinfo @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done # Documentation. ifneq ($(OCAMLDOC),) doc: rm -rf html mkdir html $(OCAMLDOC) $(OCAMLDOCFLAGS) -d html -I +camlp4 \ bitstring.mli bitstring_persistent.mli bitmatch.ml endif # Install. install: ocamlfind install bitstring META *.mli *.cmx *.cma *.cmxa *.a *.so \ bitstring.cmi \ bitstring_persistent.cmi \ pa_bitstring.cmo @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done uninstall: ocamlfind remove bitstring # Standard rules. .mli.cmi: $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) -c $< .ml.cmo: $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) -c $< .ml.cmx: $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(OCAMLOPTPACKAGES) -c $< depend: .depend @for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done .depend: bitstring.ml bitstring.mli \ bitstring_persistent.ml bitstring_persistent.mli \ bitstring_objinfo.ml \ create_test_pattern.ml rm -f $@ $@-t $(OCAMLFIND) ocamldep $(OCAMLCPACKAGES) \ bitstring.ml bitstring.mli \ bitstring_objinfo.ml | \ $(SED) 's/ :/:/' | \ $(SED) 's/ *$$//' | \ $(SED) -e :a -e '/ *\\$$/N; s/ *\\\n */ /; ta' >> $@-t $(OCAMLFIND) ocamldep $(OCAMLCPACKAGES) -pp camlp4of \ bitstring_persistent.ml bitstring_persistent.mli \ create_test_pattern.ml | \ $(SED) 's/ :/:/' | \ $(SED) 's/ *$$//' | \ $(SED) -e :a -e '/ *\\$$/N; s/ *\\\n */ /; ta' >> $@-t mv $@-t $@ ifeq ($(wildcard .depend),.depend) include .depend endif # Distribution. dist: $(MAKE) check-manifest rm -rf $(PACKAGE)-$(VERSION) mkdir $(PACKAGE)-$(VERSION) tar -cf - -T MANIFEST | tar -C $(PACKAGE)-$(VERSION) -xf - $(INSTALL) -m 0755 configure $(PACKAGE)-$(VERSION)/ $(INSTALL) -m 0644 config.h.in $(PACKAGE)-$(VERSION)/ svn log -v > $(PACKAGE)-$(VERSION)/CHANGES tar zcf $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE)-$(VERSION) rm -rf $(PACKAGE)-$(VERSION) ls -l $(PACKAGE)-$(VERSION).tar.gz check-manifest: svn -R list | grep -v '/$$' | sort > .check-manifest sort MANIFEST > .orig-manifest; \ diff -u .orig-manifest .check-manifest; rv=$$?; \ rm -f .orig-manifest .check-manifest; \ exit $$rv .PHONY: depend dist check-manifest dpkg doc \ print-examples print-tests examples test benchmarks .SUFFIXES: .cmo .cmi .cmx .ml .mli .mll ocaml-bitstring-2.0.4/coverage-report/0000775000175000017500000000000012144457302017305 5ustar rjonesrjonesocaml-bitstring-2.0.4/coverage-report/file0003.html0000664000175000017500000001144412144455551021425 0ustar rjonesrjones Bisect report

File: bitstring_types.ml (return to index)


Statistics:

kind coverage
binding 0 / 0 (- %)
sequence 0 / 0 (- %)
for 0 / 0 (- %)
if/then 0 / 0 (- %)
try 0 / 0 (- %)
while 0 / 0 (- %)
match/function 0 / 3 (0 %)
class expression 0 / 0 (- %)
class initializer 0 / 0 (- %)
class method 0 / 0 (- %)
class value 0 / 0 (- %)
toplevel expression 0 / 0 (- %)

Source:

000001| (* Bitstring library.
000002|  * Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones
000003|  *
000004|  * This library is free software; you can redistribute it and/or
000005|  * modify it under the terms of the GNU Lesser General Public
000006|  * License as published by the Free Software Foundation; either
000007|  * version 2 of the License, or (at your option) any later version,
000008|  * with the OCaml linking exception described in COPYING.LIB.
000009|  *
000010|  * This library is distributed in the hope that it will be useful,
000011|  * but WITHOUT ANY WARRANTY; without even the implied warranty of
000012|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
000013|  * Lesser General Public License for more details.
000014|  *
000015|  * You should have received a copy of the GNU Lesser General Public
000016|  * License along with this library; if not, write to the Free Software
000017|  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
000018|  *
000019|  * $Id: bitstring_types.ml 142 2008-07-17 15:45:56Z richard.wm.jones $
000020|  *)
000021|  
000022| type endian = BigEndian | LittleEndian | NativeEndian
000023|  
000024| let string_of_endian = function
000025|   | BigEndian -> (*[0]*)"bigendian"
000026|   | LittleEndian -> (*[0]*)"littleendian"
000027|   | NativeEndian -> (*[0]*)"nativeendian"

ocaml-bitstring-2.0.4/coverage-report/file0001.html0000664000175000017500000044401312144455551021425 0ustar rjonesrjones Bisect report

File: bitstring.ml (return to index)


Statistics:

kind coverage
binding 226 / 245 (92 %)
sequence 83 / 95 (87 %)
for 5 / 5 (100 %)
if/then 141 / 194 (72 %)
try 1 / 2 (50 %)
while 3 / 3 (100 %)
match/function 64 / 87 (73 %)
class expression 0 / 0 (- %)
class initializer 0 / 0 (- %)
class method 0 / 0 (- %)
class value 0 / 0 (- %)
toplevel expression 0 / 0 (- %)

Source:

000001| (* Bitstring library.
000002|  * Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones
000003|  *
000004|  * This library is free software; you can redistribute it and/or
000005|  * modify it under the terms of the GNU Lesser General Public
000006|  * License as published by the Free Software Foundation; either
000007|  * version 2 of the License, or (at your option) any later version,
000008|  * with the OCaml linking exception described in COPYING.LIB.
000009|  *
000010|  * This library is distributed in the hope that it will be useful,
000011|  * but WITHOUT ANY WARRANTY; without even the implied warranty of
000012|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
000013|  * Lesser General Public License for more details.
000014|  *
000015|  * You should have received a copy of the GNU Lesser General Public
000016|  * License along with this library; if not, write to the Free Software
000017|  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
000018|  *
000019|  * $Id: bitstring.ml 159 2008-08-27 11:26:45Z richard.wm.jones $
000020|  *)
000021|  
000022| open Printf
000023|  
000024| include Bitstring_types
000025| include Bitstring_config
000026|  
000027| (* Enable runtime debug messages.  Must also have been enabled
000028|  * in pa_bitstring.ml.
000029|  *)
000030| let debug = (*[43]*)ref false
000031|  
000032| (* Exceptions. *)
000033| exception Construct_failure of string * string * int * int
000034|  
000035| (* A bitstring is simply the data itself (as a string), and the
000036|  * bitoffset and the bitlength within the string.  Note offset/length
000037|  * are counted in bits, not bytes.
000038|  *)
000039| type bitstring = string * int * int
000040|  
000041| type t = bitstring
000042|  
000043| (* Functions to create and load bitstrings. *)
000044| let empty_bitstring = (*[43]*)"", 0, 0
000045|  
000046| let make_bitstring len c =
000047|   (*[1325989]*)if len >= 0 then (*[1325989]*)String.make ((len+7) lsr 3) c, 0, len
000048|   else
000049|     (*[0]*)invalid_arg (
000050|       sprintf "make_bitstring/create_bitstring: len %d < 0" len
000051|     )
000052|  
000053| let create_bitstring len = (*[42903]*)make_bitstring len '\000'
000054|  
000055| let zeroes_bitstring = (*[43]*)create_bitstring
000056|  
000057| let ones_bitstring len = (*[1278457]*)make_bitstring len '\xff'
000058|  
000059| let bitstring_of_string str = (*[2]*)str, 0, String.length str lsl 3
000060|  
000061| let bitstring_of_chan chan =
000062|   (*[36]*)let tmpsize = 16384 in
000063|   (*[36]*)let buf = Buffer.create tmpsize in
000064|   (*[36]*)let tmp = String.create tmpsize in
000065|   (*[36]*)let n = ref 0 in
000066|   (*[36]*)while (*[72]*)n := input chan tmp 0 tmpsize; !(*[72]*)n > 0 do
000067|     (*[36]*)Buffer.add_substring buf tmp 0 !n;
000068|   done;
000069|   (*[36]*)Buffer.contents buf, 0, Buffer.length buf lsl 3
000070|  
000071| let bitstring_of_chan_max chan max =
000072|   (*[2]*)let tmpsize = 16384 in
000073|   (*[2]*)let buf = Buffer.create tmpsize in
000074|   (*[2]*)let tmp = String.create tmpsize in
000075|   (*[2]*)let len = ref 0 in
000076|   (*[2]*)let rec loop () =
000077|     (*[2]*)if !len < max then (
000078|       (*[2]*)let r = min tmpsize (max - !len) in
000079|       (*[2]*)let n = input chan tmp 0 r in
000080|       (*[0]*)if n > 0 then (
000081|         (*[2]*)Buffer.add_substring buf tmp 0 n;
000082|         (*[2]*)len (*[2]*):= !len + n;
000083|         (*[2]*)loop ()
000084|       )
000085|     )
000086|   in
000087|   (*[2]*)loop (*[2]*)();
000088|   (*[2]*)Buffer.contents buf, 0, !len lsl 3
000089|  
000090| let bitstring_of_file_descr fd =
000091|   (*[1]*)let tmpsize = 16384 in
000092|   (*[1]*)let buf = Buffer.create tmpsize in
000093|   (*[1]*)let tmp = String.create tmpsize in
000094|   (*[1]*)let n = ref 0 in
000095|   (*[1]*)while (*[2]*)n := Unix.read fd tmp 0 tmpsize; !(*[2]*)n > 0 do
000096|     (*[1]*)Buffer.add_substring buf tmp 0 !n;
000097|   done;
000098|   (*[1]*)Buffer.contents buf, 0, Buffer.length buf lsl 3
000099|  
000100| let bitstring_of_file_descr_max fd max =
000101|   (*[2]*)let tmpsize = 16384 in
000102|   (*[2]*)let buf = Buffer.create tmpsize in
000103|   (*[2]*)let tmp = String.create tmpsize in
000104|   (*[2]*)let len = ref 0 in
000105|   (*[2]*)let rec loop () =
000106|     (*[2]*)if !len < max then (
000107|       (*[2]*)let r = min tmpsize (max - !len) in
000108|       (*[2]*)let n = Unix.read fd tmp 0 r in
000109|       (*[0]*)if n > 0 then (
000110|         (*[2]*)Buffer.add_substring buf tmp 0 n;
000111|         (*[2]*)len (*[2]*):= !len + n;
000112|         (*[2]*)loop ()
000113|       )
000114|     )
000115|   in
000116|   (*[2]*)loop (*[2]*)();
000117|   (*[2]*)Buffer.contents buf, 0, !len lsl 3
000118|  
000119| let bitstring_of_file fname =
000120|   (*[35]*)let chan = open_in_bin fname in
000121|   (*[35]*)try
000122|     (*[35]*)let bs = bitstring_of_chan chan in
000123|     (*[35]*)close_in (*[35]*)chan;
000124|     (*[35]*)bs
000125|   with exn ->
000126|     (*[0]*)close_in (*[0]*)chan;
000127|     (*[0]*)raise exn
000128|  
000129| let bitstring_length (_, _, len) = (*[1565492]*)len
000130|  
000131| let subbitstring (data, off, len) off' len' =
000132|   (*[1]*)let off = off + off' in
000133|   (*[1]*)if len < off' + len' then (*[0]*)invalid_arg "subbitstring";
000134|   ((*[1]*)data, off, len')
000135|  
000136| let dropbits n (data, off, len) =
000137|   (*[336643]*)let off = off + n in
000138|   (*[336643]*)let len = len - n in
000139|   (*[336643]*)if len < 0 then (*[0]*)invalid_arg "dropbits";
000140|   ((*[336643]*)data, off, len)
000141|  
000142| let takebits n (data, off, len) =
000143|   (*[100]*)if len < n then (*[0]*)invalid_arg "takebits";
000144|   ((*[100]*)data, off, n)
000145|  
000146| (*----------------------------------------------------------------------*)
000147| (* Bitwise functions.
000148|  *
000149|  * We try to isolate all bitwise functions within these modules.
000150|  *)
000151|  
000152| module I = struct
000153|   (* Bitwise operations on ints.  Note that we assume int <= 31 bits. *)
000154|   external (<<<) : int -> int -> int = "%lslint"
000155|   external (>>>) : int -> int -> int = "%lsrint"
000156|   external to_int : int -> int = "%identity"
000157|   let zero = (*[43]*)0
000158|   let one = (*[43]*)1
000159|   let minus_one = (*[43]*)-1
000160|   let ff = (*[43]*)0xff
000161|  
000162|   (* Create a mask 0-31 bits wide. *)
000163|   let mask bits =
000164|     (*[2342]*)if bits < 30 then
000165|       ((*[1952]*)one <<< bits) - 1
000166|     else (*[390]*)if bits = 30 then
000167|       (*[0]*)max_int
000168|     else (*[390]*)if bits = 31 then
000169|       (*[390]*)minus_one
000170|     else
000171|       (*[0]*)invalid_arg "Bitstring.I.mask"
000172|  
000173|   (* Byte swap an int of a given size. *)
000174|   let byteswap v bits =
000175|     (*[780]*)if bits <= 8 then (*[0]*)v
000176|     else (*[780]*)if bits <= 16 then (
000177|       (*[260]*)let shift = bits-8 in
000178|       (*[260]*)let v1 = v >>> shift in
000179|       (*[260]*)let v2 = ((v land (mask shift)) <<< 8) in
000180|       v2 (*[260]*)lor v1
000181|     ) else (*[520]*)if bits <= 24 then (
000182|       (*[260]*)let shift = bits - 16 in
000183|       (*[260]*)let v1 = v >>> (8+shift) in
000184|       (*[260]*)let v2 = ((v >>> shift) land ff) <<< 8 in
000185|       (*[260]*)let v3 = (v land (mask shift)) <<< 16 in
000186|       v3 lor v2 (*[260]*)lor v1
000187|     ) else (
000188|       (*[260]*)let shift = bits - 24 in
000189|       (*[260]*)let v1 = v >>> (16+shift) in
000190|       (*[260]*)let v2 = ((v >>> (8+shift)) land ff) <<< 8 in
000191|       (*[260]*)let v3 = ((v >>> shift) land ff) <<< 16 in
000192|       (*[260]*)let v4 = (v land (mask shift)) <<< 24 in
000193|       v4 lor v3 lor v2 (*[260]*)lor v1
000194|     )
000195|  
000196|   (* Check a value is in range 0 .. 2^bits-1. *)
000197|   let range_unsigned v bits =
000198|     (*[1172]*)let mask = lnot (mask bits) in
000199|     (v (*[1172]*)land mask) = zero
000200|  
000201|   (* Call function g on the top bits, then f on each full byte
000202|    * (big endian - so start at top).
000203|    *)
000204|   let rec map_bytes_be g f v bits =
000205|     (*[1436]*)if bits >= 8 then (
000206|       (*[1044]*)map_bytes_be g f (v >>> 8) (*[1044]*)(bits-8);
000207|       (*[1044]*)let lsb = v land ff in
000208|       (*[1044]*)f (to_int lsb)
000209|     ) else (*[262]*)if bits > 0 then (
000210|       (*[130]*)let lsb = v land (mask bits) in
000211|       (*[130]*)g (to_int lsb) bits
000212|     )
000213|  
000214|   (* Call function g on the top bits, then f on each full byte
000215|    * (little endian - so start at root).
000216|    *)
000217|   let rec map_bytes_le g f v bits =
000218|     (*[2860]*)if bits >= 8 then (
000219|       (*[2080]*)let lsb = v land ff in
000220|       (*[2080]*)f (*[2080]*)(to_int lsb);
000221|       (*[2080]*)map_bytes_le g f (v >>> 8) (bits-8)
000222|     ) else (*[520]*)if bits > 0 then (
000223|       (*[260]*)let lsb = v land (mask bits) in
000224|       (*[260]*)g (to_int lsb) bits
000225|     )
000226| end
000227|  
000228| module I32 = struct
000229|   (* Bitwise operations on int32s.  Note we try to keep it as similar
000230|    * as possible to the I module above, to make it easier to track
000231|    * down bugs.
000232|    *)
000233|   let (<<<) = (*[43]*)Int32.shift_left
000234|   let (>>>) = (*[43]*)Int32.shift_right_logical
000235|   let (land) = (*[43]*)Int32.logand
000236|   let (lor) = (*[43]*)Int32.logor
000237|   let lnot = (*[43]*)Int32.lognot
000238|   let pred = (*[43]*)Int32.pred
000239|   let max_int = (*[43]*)Int32.max_int
000240|   let to_int = (*[43]*)Int32.to_int
000241|   let zero = (*[43]*)Int32.zero
000242|   let one = (*[43]*)Int32.one
000243|   let minus_one = (*[43]*)Int32.minus_one
000244|   let ff = (*[43]*)0xff_l
000245|  
000246|   (* Create a mask so many bits wide. *)
000247|   let mask bits =
000248|     (*[272]*)if bits < 31 then
000249|       (*[272]*)pred (one <<< bits)
000250|     else (*[0]*)if bits = 31 then
000251|       (*[0]*)max_int
000252|     else (*[0]*)if bits = 32 then
000253|       (*[0]*)minus_one
000254|     else
000255|       (*[0]*)invalid_arg "Bitstring.I32.mask"
000256|  
000257|   (* Byte swap an int of a given size. *)
000258|   let byteswap v bits =
000259|     (*[272]*)if bits <= 8 then (*[0]*)v
000260|     else (*[272]*)if bits <= 16 then (
000261|       (*[0]*)let shift = bits-8 in
000262|       (*[0]*)let v1 = v >>> shift in
000263|       (*[0]*)let v2 = (v land (mask shift)) <<< 8 in
000264|       v2 (*[0]*)lor v1
000265|     ) else (*[272]*)if bits <= 24 then (
000266|       (*[0]*)let shift = bits - 16 in
000267|       (*[0]*)let v1 = v >>> (8+shift) in
000268|       (*[0]*)let v2 = ((v >>> shift) land ff) <<< 8 in
000269|       (*[0]*)let v3 = (v land (mask shift)) <<< 16 in
000270|       v3 lor v2 (*[0]*)lor v1
000271|     ) else (
000272|       (*[272]*)let shift = bits - 24 in
000273|       (*[272]*)let v1 = v >>> (16+shift) in
000274|       (*[272]*)let v2 = ((v >>> (8+shift)) land ff) <<< 8 in
000275|       (*[272]*)let v3 = ((v >>> shift) land ff) <<< 16 in
000276|       (*[272]*)let v4 = (v land (mask shift)) <<< 24 in
000277|       v4 lor v3 lor v2 (*[272]*)lor v1
000278|     )
000279|  
000280|   (* Check a value is in range 0 .. 2^bits-1. *)
000281|   let range_unsigned v bits =
000282|     (*[0]*)let mask = lnot (mask bits) in
000283|     (v (*[0]*)land mask) = zero
000284|  
000285|   (* Call function g on the top bits, then f on each full byte
000286|    * (big endian - so start at top).
000287|    *)
000288|   let rec map_bytes_be g f v bits =
000289|     (*[0]*)if bits >= 8 then (
000290|       (*[0]*)map_bytes_be g f (v >>> 8) (*[0]*)(bits-8);
000291|       (*[0]*)let lsb = v land ff in
000292|       (*[0]*)f (to_int lsb)
000293|     ) else (*[0]*)if bits > 0 then (
000294|       (*[0]*)let lsb = v land (mask bits) in
000295|       (*[0]*)g (to_int lsb) bits
000296|     )
000297|  
000298|   (* Call function g on the top bits, then f on each full byte
000299|    * (little endian - so start at root).
000300|    *)
000301|   let rec map_bytes_le g f v bits =
000302|     (*[0]*)if bits >= 8 then (
000303|       (*[0]*)let lsb = v land ff in
000304|       (*[0]*)f (*[0]*)(to_int lsb);
000305|       (*[0]*)map_bytes_le g f (v >>> 8) (bits-8)
000306|     ) else (*[0]*)if bits > 0 then (
000307|       (*[0]*)let lsb = v land (mask bits) in
000308|       (*[0]*)g (to_int lsb) bits
000309|     )
000310| end
000311|  
000312| module I64 = struct
000313|   (* Bitwise operations on int64s.  Note we try to keep it as similar
000314|    * as possible to the I/I32 modules above, to make it easier to track
000315|    * down bugs.
000316|    *)
000317|   let (<<<) = (*[43]*)Int64.shift_left
000318|   let (>>>) = (*[43]*)Int64.shift_right_logical
000319|   let (land) = (*[43]*)Int64.logand
000320|   let (lor) = (*[43]*)Int64.logor
000321|   let lnot = (*[43]*)Int64.lognot
000322|   let pred = (*[43]*)Int64.pred
000323|   let max_int = (*[43]*)Int64.max_int
000324|   let to_int = (*[43]*)Int64.to_int
000325|   let zero = (*[43]*)Int64.zero
000326|   let one = (*[43]*)Int64.one
000327|   let minus_one = (*[43]*)Int64.minus_one
000328|   let ff = (*[43]*)0xff_L
000329|  
000330|   (* Create a mask so many bits wide. *)
000331|   let mask bits =
000332|     (*[670350]*)if bits < 63 then
000333|       (*[664750]*)pred (one <<< bits)
000334|     else (*[5600]*)if bits = 63 then
000335|       (*[4950]*)max_int
000336|     else (*[650]*)if bits = 64 then
000337|       (*[650]*)minus_one
000338|     else
000339|       (*[0]*)invalid_arg "Bitstring.I64.mask"
000340|  
000341|   (* Byte swap an int of a given size. *)
000342|   (* let byteswap v bits = *)
000343|  
000344|   (* Check a value is in range 0 .. 2^bits-1. *)
000345|   let range_unsigned v bits =
000346|     (*[352630]*)let mask = lnot (mask bits) in
000347|     (v (*[352630]*)land mask) = zero
000348|  
000349|   (* Call function g on the top bits, then f on each full byte
000350|    * (big endian - so start at top).
000351|    *)
000352|   let rec map_bytes_be g f v bits =
000353|     (*[1462730]*)if bits >= 8 then (
000354|       (*[1110620]*)map_bytes_be g f (v >>> 8) (*[1110620]*)(bits-8);
000355|       (*[1110620]*)let lsb = v land ff in
000356|       (*[1110620]*)f (to_int lsb)
000357|     ) else (*[34910]*)if bits > 0 then (
000358|       (*[317200]*)let lsb = v land (mask bits) in
000359|       (*[317200]*)g (to_int lsb) bits
000360|     )
000361|  
000362|   (* Call function g on the top bits, then f on each full byte
000363|    * (little endian - so start at root).
000364|    *)
000365|   let rec map_bytes_le g f v bits =
000366|     (*[4160]*)if bits >= 8 then (
000367|       (*[3640]*)let lsb = v land ff in
000368|       (*[3640]*)f (*[3640]*)(to_int lsb);
000369|       (*[3640]*)map_bytes_le g f (v >>> 8) (bits-8)
000370|     ) else (*[520]*)if bits > 0 then (
000371|       (*[0]*)let lsb = v land (mask bits) in
000372|       (*[0]*)g (to_int lsb) bits
000373|     )
000374| end
000375|  
000376| (*----------------------------------------------------------------------*)
000377| (* Extraction functions.
000378|  *
000379|  * NB: internal functions, called from the generated macros, and
000380|  * the parameters should have been checked for sanity already).
000381|  *)
000382|  
000383| (* Extract and convert to numeric.  A single bit is returned as
000384|  * a boolean.  There are no endianness or signedness considerations.
000385|  *)
000386| let extract_bit data off len _ =        (* final param is always 1 *)
000387|   (*[2515282]*)let byteoff = off lsr 3 in
000388|   (*[2515282]*)let bitmask = 1 lsl (7 - (off land 7)) in
000389|   (*[2515282]*)let b = Char.code data.[byteoff] land bitmask <> 0 in
000390|   (*[2515282]*)b (*, off+1, len-1*)
000391|  
000392| (* Returns 8 bit unsigned aligned bytes from the string.
000393|  * If the string ends then this returns 0's.
000394|  *)
000395| let _get_byte data byteoff strlen =
000396|   (*[9840892]*)if strlen > byteoff then (*[9274362]*)Char.code data.[byteoff] else (*[566530]*)0
000397| let _get_byte32 data byteoff strlen =
000398|   (*[264]*)if strlen > byteoff then (*[264]*)Int32.of_int (Char.code data.[byteoff]) else (*[0]*)0l
000399| let _get_byte64 data byteoff strlen =
000400|   (*[1626792]*)if strlen > byteoff then (*[1518549]*)Int64.of_int (Char.code data.[byteoff]) else (*[108243]*)0L
000401|  
000402| (* Extract [2..8] bits.  Because the result fits into a single
000403|  * byte we don't have to worry about endianness, only signedness.
000404|  *)
000405| let extract_char_unsigned data off len flen =
000406|   (*[5040562]*)let byteoff = off lsr 3 in
000407|  
000408|   (* Optimize the common (byte-aligned) case. *)
000409|   (*[5040562]*)if off land 7 = 0 then (
000410|     (*[121776]*)let byte = Char.code data.[byteoff] in
000411|     byte (*[121776]*)lsr (8 - flen) (*, off+flen, len-flen*)
000412|   ) else (
000413|     (* Extract the 16 bits at byteoff and byteoff+1 (note that the
000414|      * second byte might not exist in the original string).
000415|      *)
000416|     (*[4918786]*)let strlen = String.length data in
000417|  
000418|     (*[4918786]*)let word =
000419|       (_get_byte data byteoff strlen lsl 8) +
000420|         _get_byte data (byteoff+1) strlen in
000421|  
000422|     (* Mask off the top bits. *)
000423|     (*[4918786]*)let bitmask = (1 lsl (16 - (off land 7))) - 1 in
000424|     (*[4918786]*)let word = word land bitmask in
000425|     (* Shift right to get rid of the bottom bits. *)
000426|     (*[4918786]*)let shift = 16 - ((off land 7) + flen) in
000427|     (*[4918786]*)let word = word lsr shift in
000428|  
000429|     (*[4918786]*)word (*, off+flen, len-flen*)
000430|   )
000431|  
000432| (* Extract [9..31] bits.  We have to consider endianness and signedness. *)
000433| let extract_int_be_unsigned data off len flen =
000434|   (*[1170]*)let byteoff = off lsr 3 in
000435|  
000436|   (*[1170]*)let strlen = String.length data in
000437|  
000438|   (*[1170]*)let word =
000439|     (* Optimize the common (byte-aligned) case. *)
000440|     if off land 7 = 0 then (
000441|       (*[152]*)let word =
000442|         (_get_byte data byteoff strlen lsl 23) +
000443|           (_get_byte data (byteoff+1) strlen lsl 15) +
000444|           (_get_byte data (byteoff+2) strlen lsl 7) +
000445|           (_get_byte data (byteoff+3) strlen lsr 1) in
000446|       word (*[152]*)lsr (31 - flen)
000447|     ) else (*[1018]*)if flen <= 24 then (
000448|       (* Extract the 31 bits at byteoff .. byteoff+3. *)
000449|       (*[678]*)let word =
000450|         (_get_byte data byteoff strlen lsl 23) +
000451|           (_get_byte data (byteoff+1) strlen lsl 15) +
000452|           (_get_byte data (byteoff+2) strlen lsl 7) +
000453|           (_get_byte data (byteoff+3) strlen lsr 1) in
000454|       (* Mask off the top bits. *)
000455|       (*[678]*)let bitmask = (1 lsl (31 - (off land 7))) - 1 in
000456|       (*[678]*)let word = word land bitmask in
000457|       (* Shift right to get rid of the bottom bits. *)
000458|       (*[678]*)let shift = 31 - ((off land 7) + flen) in
000459|       word (*[678]*)lsr shift
000460|     ) else (
000461|       (* Extract the next 31 bits, slow method. *)
000462|       (*[340]*)let word =
000463|         let c0 = extract_char_unsigned data off len 8
000464|         and off = off + 8 and len = len - 8 in
000465|         (*[340]*)let c1 = extract_char_unsigned data off len 8
000466|         and off = off + 8 and len = len - 8 in
000467|         (*[340]*)let c2 = extract_char_unsigned data off len 8
000468|         and off = off + 8 and len = len - 8 in
000469|         (*[340]*)let c3 = extract_char_unsigned data off len 7 in
000470|         (c0 (*[340]*)lsl 23) + (c1 lsl 15) + (c2 lsl 7) + c3 in
000471|       word (*[340]*)lsr (31 - flen)
000472|     ) in
000473|   (*[1170]*)word (*, off+flen, len-flen*)
000474|  
000475| let extract_int_le_unsigned data off len flen =
000476|   (*[780]*)let v = extract_int_be_unsigned data off len flen in
000477|   (*[780]*)let v = I.byteswap v flen in
000478|   (*[780]*)v
000479|  
000480| let extract_int_ne_unsigned =
000481|   (*[43]*)if nativeendian = BigEndian
000482|   then (*[0]*)extract_int_be_unsigned
000483|   else (*[43]*)extract_int_le_unsigned
000484|  
000485| let extract_int_ee_unsigned = function
000486|   | BigEndian -> (*[0]*)extract_int_be_unsigned
000487|   | LittleEndian -> (*[0]*)extract_int_le_unsigned
000488|   | NativeEndian -> (*[0]*)extract_int_ne_unsigned
000489|  
000490| let _make_int32_be c0 c1 c2 c3 =
000491|   (*[408]*)Int32.logor
000492|     (Int32.logor
000493|        (Int32.logor
000494|           (Int32.shift_left c0 24)
000495|           (Int32.shift_left c1 16))
000496|        (Int32.shift_left c2 8))
000497|     c3
000498|  
000499| let _make_int32_le c0 c1 c2 c3 =
000500|   (*[0]*)Int32.logor
000501|     (Int32.logor
000502|        (Int32.logor
000503|           (Int32.shift_left c3 24)
000504|           (Int32.shift_left c2 16))
000505|        (Int32.shift_left c1 8))
000506|     c0
000507|  
000508| (* Extract exactly 32 bits.  We have to consider endianness and signedness. *)
000509| let extract_int32_be_unsigned data off len flen =
000510|   (*[408]*)let byteoff = off lsr 3 in
000511|  
000512|   (*[408]*)let strlen = String.length data in
000513|  
000514|   (*[408]*)let word =
000515|     (* Optimize the common (byte-aligned) case. *)
000516|     if off land 7 = 0 then (
000517|       (*[66]*)let word =
000518|         let c0 = _get_byte32 data byteoff strlen in
000519|         (*[66]*)let c1 = _get_byte32 data (byteoff+1) strlen in
000520|         (*[66]*)let c2 = _get_byte32 data (byteoff+2) strlen in
000521|         (*[66]*)let c3 = _get_byte32 data (byteoff+3) strlen in
000522|         (*[66]*)_make_int32_be c0 c1 c2 c3 in
000523|       (*[66]*)Int32.shift_right_logical word (32 - flen)
000524|     ) else (
000525|       (* Extract the next 32 bits, slow method. *)
000526|       (*[342]*)let word =
000527|         let c0 = extract_char_unsigned data off len 8
000528|         and off = off + 8 and len = len - 8 in
000529|         (*[342]*)let c1 = extract_char_unsigned data off len 8
000530|         and off = off + 8 and len = len - 8 in
000531|         (*[342]*)let c2 = extract_char_unsigned data off len 8
000532|         and off = off + 8 and len = len - 8 in
000533|         (*[342]*)let c3 = extract_char_unsigned data off len 8 in
000534|         (*[342]*)let c0 = Int32.of_int c0 in
000535|         (*[342]*)let c1 = Int32.of_int c1 in
000536|         (*[342]*)let c2 = Int32.of_int c2 in
000537|         (*[342]*)let c3 = Int32.of_int c3 in
000538|         (*[342]*)_make_int32_be c0 c1 c2 c3 in
000539|       (*[342]*)Int32.shift_right_logical word (32 - flen)
000540|     ) in
000541|   (*[408]*)word (*, off+flen, len-flen*)
000542|  
000543| let extract_int32_le_unsigned data off len flen =
000544|   (*[272]*)let v = extract_int32_be_unsigned data off len flen in
000545|   (*[272]*)let v = I32.byteswap v flen in
000546|   (*[272]*)v
000547|  
000548| let extract_int32_ne_unsigned =
000549|   (*[43]*)if nativeendian = BigEndian
000550|   then (*[0]*)extract_int32_be_unsigned
000551|   else (*[43]*)extract_int32_le_unsigned
000552|  
000553| let extract_int32_ee_unsigned = function
000554|   | BigEndian -> (*[6]*)extract_int32_be_unsigned
000555|   | LittleEndian -> (*[6]*)extract_int32_le_unsigned
000556|   | NativeEndian -> (*[6]*)extract_int32_ne_unsigned
000557|  
000558| let _make_int64_be c0 c1 c2 c3 c4 c5 c6 c7 =
000559|   (*[658243]*)Int64.logor
000560|     (Int64.logor
000561|        (Int64.logor
000562|           (Int64.logor
000563|              (Int64.logor
000564|                 (Int64.logor
000565|                    (Int64.logor
000566|                       (Int64.shift_left c0 56)
000567|                       (Int64.shift_left c1 48))
000568|                    (Int64.shift_left c2 40))
000569|                 (Int64.shift_left c3 32))
000570|              (Int64.shift_left c4 24))
000571|           (Int64.shift_left c5 16))
000572|        (Int64.shift_left c6 8))
000573|     c7
000574|  
000575| let _make_int64_le c0 c1 c2 c3 c4 c5 c6 c7 =
000576|   (*[520]*)_make_int64_be c7 c6 c5 c4 c3 c2 c1 c0
000577|  
000578| (* Extract [1..64] bits.  We have to consider endianness and signedness. *)
000579| let extract_int64_be_unsigned data off len flen =
000580|   (*[657723]*)let byteoff = off lsr 3 in
000581|  
000582|   (*[657723]*)let strlen = String.length data in
000583|  
000584|   (*[657723]*)let word =
000585|     (* Optimize the common (byte-aligned) case. *)
000586|     if off land 7 = 0 then (
000587|       (*[203285]*)let word =
000588|         let c0 = _get_byte64 data byteoff strlen in
000589|         (*[203285]*)let c1 = _get_byte64 data (byteoff+1) strlen in
000590|         (*[203285]*)let c2 = _get_byte64 data (byteoff+2) strlen in
000591|         (*[203285]*)let c3 = _get_byte64 data (byteoff+3) strlen in
000592|         (*[203285]*)let c4 = _get_byte64 data (byteoff+4) strlen in
000593|         (*[203285]*)let c5 = _get_byte64 data (byteoff+5) strlen in
000594|         (*[203285]*)let c6 = _get_byte64 data (byteoff+6) strlen in
000595|         (*[203285]*)let c7 = _get_byte64 data (byteoff+7) strlen in
000596|         (*[203285]*)_make_int64_be c0 c1 c2 c3 c4 c5 c6 c7 in
000597|       (*[203285]*)Int64.shift_right_logical word (64 - flen)
000598|     ) else (
000599|       (* Extract the next 64 bits, slow method. *)
000600|       (*[454438]*)let word =
000601|         let c0 = extract_char_unsigned data off len 8
000602|         and off = off + 8 and len = len - 8 in
000603|         (*[454438]*)let c1 = extract_char_unsigned data off len 8
000604|         and off = off + 8 and len = len - 8 in
000605|         (*[454438]*)let c2 = extract_char_unsigned data off len 8
000606|         and off = off + 8 and len = len - 8 in
000607|         (*[454438]*)let c3 = extract_char_unsigned data off len 8
000608|         and off = off + 8 and len = len - 8 in
000609|         (*[454438]*)let c4 = extract_char_unsigned data off len 8
000610|         and off = off + 8 and len = len - 8 in
000611|         (*[454438]*)let c5 = extract_char_unsigned data off len 8
000612|         and off = off + 8 and len = len - 8 in
000613|         (*[454438]*)let c6 = extract_char_unsigned data off len 8
000614|         and off = off + 8 and len = len - 8 in
000615|         (*[454438]*)let c7 = extract_char_unsigned data off len 8 in
000616|         (*[454438]*)let c0 = Int64.of_int c0 in
000617|         (*[454438]*)let c1 = Int64.of_int c1 in
000618|         (*[454438]*)let c2 = Int64.of_int c2 in
000619|         (*[454438]*)let c3 = Int64.of_int c3 in
000620|         (*[454438]*)let c4 = Int64.of_int c4 in
000621|         (*[454438]*)let c5 = Int64.of_int c5 in
000622|         (*[454438]*)let c6 = Int64.of_int c6 in
000623|         (*[454438]*)let c7 = Int64.of_int c7 in
000624|         (*[454438]*)_make_int64_be c0 c1 c2 c3 c4 c5 c6 c7 in
000625|       (*[454438]*)Int64.shift_right_logical word (64 - flen)
000626|     ) in
000627|   (*[657723]*)word (*, off+flen, len-flen*)
000628|  
000629| let extract_int64_le_unsigned data off len flen =
000630|   (*[520]*)let byteoff = off lsr 3 in
000631|  
000632|   (*[520]*)let strlen = String.length data in
000633|  
000634|   (*[520]*)let word =
000635|     (* Optimize the common (byte-aligned) case. *)
000636|     if off land 7 = 0 then (
000637|       (*[64]*)let word =
000638|         let c0 = _get_byte64 data byteoff strlen in
000639|         (*[64]*)let c1 = _get_byte64 data (byteoff+1) strlen in
000640|         (*[64]*)let c2 = _get_byte64 data (byteoff+2) strlen in
000641|         (*[64]*)let c3 = _get_byte64 data (byteoff+3) strlen in
000642|         (*[64]*)let c4 = _get_byte64 data (byteoff+4) strlen in
000643|         (*[64]*)let c5 = _get_byte64 data (byteoff+5) strlen in
000644|         (*[64]*)let c6 = _get_byte64 data (byteoff+6) strlen in
000645|         (*[64]*)let c7 = _get_byte64 data (byteoff+7) strlen in
000646|         (*[64]*)_make_int64_le c0 c1 c2 c3 c4 c5 c6 c7 in
000647|       (*[64]*)Int64.logand word (I64.mask flen)
000648|     ) else (
000649|       (* Extract the next 64 bits, slow method. *)
000650|       (*[456]*)let word =
000651|         let c0 = extract_char_unsigned data off len 8
000652|         and off = off + 8 and len = len - 8 in
000653|         (*[456]*)let c1 = extract_char_unsigned data off len 8
000654|         and off = off + 8 and len = len - 8 in
000655|         (*[456]*)let c2 = extract_char_unsigned data off len 8
000656|         and off = off + 8 and len = len - 8 in
000657|         (*[456]*)let c3 = extract_char_unsigned data off len 8
000658|         and off = off + 8 and len = len - 8 in
000659|         (*[456]*)let c4 = extract_char_unsigned data off len 8
000660|         and off = off + 8 and len = len - 8 in
000661|         (*[456]*)let c5 = extract_char_unsigned data off len 8
000662|         and off = off + 8 and len = len - 8 in
000663|         (*[456]*)let c6 = extract_char_unsigned data off len 8
000664|         and off = off + 8 and len = len - 8 in
000665|         (*[456]*)let c7 = extract_char_unsigned data off len 8 in
000666|         (*[456]*)let c0 = Int64.of_int c0 in
000667|         (*[456]*)let c1 = Int64.of_int c1 in
000668|         (*[456]*)let c2 = Int64.of_int c2 in
000669|         (*[456]*)let c3 = Int64.of_int c3 in
000670|         (*[456]*)let c4 = Int64.of_int c4 in
000671|         (*[456]*)let c5 = Int64.of_int c5 in
000672|         (*[456]*)let c6 = Int64.of_int c6 in
000673|         (*[456]*)let c7 = Int64.of_int c7 in
000674|         (*[456]*)_make_int64_le c0 c1 c2 c3 c4 c5 c6 c7 in
000675|       (*[456]*)Int64.logand word (I64.mask flen)
000676|     ) in
000677|   (*[520]*)word (*, off+flen, len-flen*)
000678|  
000679| let extract_int64_ne_unsigned =
000680|   (*[43]*)if nativeendian = BigEndian
000681|   then (*[0]*)extract_int64_be_unsigned
000682|   else (*[43]*)extract_int64_le_unsigned
000683|  
000684| let extract_int64_ee_unsigned = function
000685|   | BigEndian -> (*[0]*)extract_int64_be_unsigned
000686|   | LittleEndian -> (*[0]*)extract_int64_le_unsigned
000687|   | NativeEndian -> (*[0]*)extract_int64_ne_unsigned
000688|  
000689| external extract_fastpath_int16_be_unsigned : string -> int -> int = "ocaml_bitstring_extract_fastpath_int16_be_unsigned" "noalloc"
000690|  
000691| external extract_fastpath_int16_le_unsigned : string -> int -> int = "ocaml_bitstring_extract_fastpath_int16_le_unsigned" "noalloc"
000692|  
000693| external extract_fastpath_int16_ne_unsigned : string -> int -> int = "ocaml_bitstring_extract_fastpath_int16_ne_unsigned" "noalloc"
000694|  
000695| external extract_fastpath_int16_be_signed : string -> int -> int = "ocaml_bitstring_extract_fastpath_int16_be_signed" "noalloc"
000696|  
000697| external extract_fastpath_int16_le_signed : string -> int -> int = "ocaml_bitstring_extract_fastpath_int16_le_signed" "noalloc"
000698|  
000699| external extract_fastpath_int16_ne_signed : string -> int -> int = "ocaml_bitstring_extract_fastpath_int16_ne_signed" "noalloc"
000700|  
000701| (*
000702| external extract_fastpath_int24_be_unsigned : string -> int -> int = "ocaml_bitstring_extract_fastpath_int24_be_unsigned" "noalloc"
000703|  
000704| external extract_fastpath_int24_le_unsigned : string -> int -> int = "ocaml_bitstring_extract_fastpath_int24_le_unsigned" "noalloc"
000705|  
000706| external extract_fastpath_int24_ne_unsigned : string -> int -> int = "ocaml_bitstring_extract_fastpath_int24_ne_unsigned" "noalloc"
000707|  
000708| external extract_fastpath_int24_be_signed : string -> int -> int = "ocaml_bitstring_extract_fastpath_int24_be_signed" "noalloc"
000709|  
000710| external extract_fastpath_int24_le_signed : string -> int -> int = "ocaml_bitstring_extract_fastpath_int24_le_signed" "noalloc"
000711|  
000712| external extract_fastpath_int24_ne_signed : string -> int -> int = "ocaml_bitstring_extract_fastpath_int24_ne_signed" "noalloc"
000713| *)
000714|  
000715| external extract_fastpath_int32_be_unsigned : string -> int -> int32 -> int32 = "ocaml_bitstring_extract_fastpath_int32_be_unsigned" "noalloc"
000716|  
000717| external extract_fastpath_int32_le_unsigned : string -> int -> int32 -> int32 = "ocaml_bitstring_extract_fastpath_int32_le_unsigned" "noalloc"
000718|  
000719| external extract_fastpath_int32_ne_unsigned : string -> int -> int32 -> int32 = "ocaml_bitstring_extract_fastpath_int32_ne_unsigned" "noalloc"
000720|  
000721| external extract_fastpath_int32_be_signed : string -> int -> int32 -> int32 = "ocaml_bitstring_extract_fastpath_int32_be_signed" "noalloc"
000722|  
000723| external extract_fastpath_int32_le_signed : string -> int -> int32 -> int32 = "ocaml_bitstring_extract_fastpath_int32_le_signed" "noalloc"
000724|  
000725| external extract_fastpath_int32_ne_signed : string -> int -> int32 -> int32 = "ocaml_bitstring_extract_fastpath_int32_ne_signed" "noalloc"
000726|  
000727| (*
000728| external extract_fastpath_int40_be_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int40_be_unsigned" "noalloc"
000729|  
000730| external extract_fastpath_int40_le_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int40_le_unsigned" "noalloc"
000731|  
000732| external extract_fastpath_int40_ne_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int40_ne_unsigned" "noalloc"
000733|  
000734| external extract_fastpath_int40_be_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int40_be_signed" "noalloc"
000735|  
000736| external extract_fastpath_int40_le_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int40_le_signed" "noalloc"
000737|  
000738| external extract_fastpath_int40_ne_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int40_ne_signed" "noalloc"
000739|  
000740| external extract_fastpath_int48_be_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int48_be_unsigned" "noalloc"
000741|  
000742| external extract_fastpath_int48_le_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int48_le_unsigned" "noalloc"
000743|  
000744| external extract_fastpath_int48_ne_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int48_ne_unsigned" "noalloc"
000745|  
000746| external extract_fastpath_int48_be_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int48_be_signed" "noalloc"
000747|  
000748| external extract_fastpath_int48_le_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int48_le_signed" "noalloc"
000749|  
000750| external extract_fastpath_int48_ne_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int48_ne_signed" "noalloc"
000751|  
000752| external extract_fastpath_int56_be_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int56_be_unsigned" "noalloc"
000753|  
000754| external extract_fastpath_int56_le_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int56_le_unsigned" "noalloc"
000755|  
000756| external extract_fastpath_int56_ne_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int56_ne_unsigned" "noalloc"
000757|  
000758| external extract_fastpath_int56_be_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int56_be_signed" "noalloc"
000759|  
000760| external extract_fastpath_int56_le_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int56_le_signed" "noalloc"
000761|  
000762| external extract_fastpath_int56_ne_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int56_ne_signed" "noalloc"
000763| *)
000764|  
000765| external extract_fastpath_int64_be_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int64_be_unsigned" "noalloc"
000766|  
000767| external extract_fastpath_int64_le_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int64_le_unsigned" "noalloc"
000768|  
000769| external extract_fastpath_int64_ne_unsigned : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int64_ne_unsigned" "noalloc"
000770|  
000771| external extract_fastpath_int64_be_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int64_be_signed" "noalloc"
000772|  
000773| external extract_fastpath_int64_le_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int64_le_signed" "noalloc"
000774|  
000775| external extract_fastpath_int64_ne_signed : string -> int -> int64 -> int64 = "ocaml_bitstring_extract_fastpath_int64_ne_signed" "noalloc"
000776|  
000777| (*----------------------------------------------------------------------*)
000778| (* Constructor functions. *)
000779|  
000780| module Buffer = struct
000781|   type t = {
000782|     buf : Buffer.t;
000783|     mutable len : int;                        (* Length in bits. *)
000784|     (* Last byte in the buffer (if len is not aligned).  We store
000785|      * it outside the buffer because buffers aren't mutable.
000786|      *)
000787|     mutable last : int;
000788|   }
000789|  
000790|   let create () =
000791|     (* XXX We have almost enough information in the generator to
000792|      * choose a good initial size.
000793|      *)
000794|     (*[493152]*){ buf = Buffer.create 128; len = 0; last = 0 }
000795|  
000796|   let contents { buf = buf; len = len; last = last } =
000797|     (*[493152]*)let data =
000798|       if len land 7 = 0 then
000799|         (*[63280]*)Buffer.contents buf
000800|       else
000801|         (*[429872]*)Buffer.contents buf ^ (String.make 1 (Char.chr last)) in
000802|     (*[493152]*)data, 0, len
000803|  
000804|   (* Add exactly 8 bits. *)
000805|   let add_byte ({ buf = buf; len = len; last = last } as t) byte =
000806|     (*[8266092]*)if (*[8266092]*)byte < 0 || (*[8266092]*)byte > 255 then (*[0]*)invalid_arg "Bitstring.Buffer.add_byte";
000807|     (*[8266092]*)let shift = len land 7 in
000808|     (*[8266092]*)if shift = 0 then
000809|       (* Target buffer is byte-aligned. *)
000810|       (*[521241]*)Buffer.add_char buf (Char.chr byte)
000811|     else (
000812|       (* Target buffer is unaligned.  'last' is meaningful. *)
000813|       (*[7744851]*)let first = byte lsr shift in
000814|       (*[7744851]*)let second = (byte lsl (8 - shift)) land 0xff in
000815|       (*[7744851]*)Buffer.add_char buf (*[7744851]*)(Char.chr (last lor first));
000816|       (*[7744851]*)t.last <- second
000817|     );
000818|     (*[8266092]*)t.len <- t.len + 8
000819|  
000820|   (* Add exactly 1 bit. *)
000821|   let add_bit ({ buf = buf; len = len; last = last } as t) bit =
000822|     (*[4426193]*)let shift = 7 - (len land 7) in
000823|     (*[4426193]*)if shift > 0 then
000824|       (* Somewhere in the middle of 'last'. *)
000825|       (*[3893270]*)t.last <- last lor ((if bit then (*[3004643]*)1 else (*[888627]*)0) lsl shift)
000826|     else (
000827|       (* Just a single spare bit in 'last'. *)
000828|       (*[532923]*)let last = last lor if bit then (*[407944]*)1 else (*[124979]*)0 in
000829|       (*[532923]*)Buffer.add_char buf (*[532923]*)(Char.chr last);
000830|       (*[532923]*)t.last <- 0
000831|     );
000832|     (*[4426193]*)t.len <- len + 1
000833|  
000834|   (* Add a small number of bits (definitely < 8).  This uses a loop
000835|    * to call add_bit so it's slow.
000836|    *)
000837|   let _add_bits t c slen =
000838|     (*[318370]*)if (*[318370]*)slen < 1 || (*[318370]*)slen >= 8 then (*[0]*)invalid_arg "Bitstring.Buffer._add_bits";
000839|     (*[318370]*)for i = slen-1 downto 0 do
000840|       (*[1273808]*)let bit = c land (1 lsl i) <> 0 in
000841|       (*[1273808]*)add_bit t bit
000842|     done
000843|  
000844|   let add_bits ({ buf = buf; len = len } as t) str slen =
000845|     (*[26867]*)if slen > 0 then (
000846|       (*[1389114]*)if len land 7 = 0 then (
000847|         (*[575784]*)if slen land 7 = 0 then
000848|           (* Common case - everything is byte-aligned. *)
000849|           (*[64322]*)Buffer.add_substring buf str 0 (slen lsr 3)
000850|         else (
000851|           (* Target buffer is aligned.  Copy whole bytes then leave the
000852|            * remaining bits in last.
000853|            *)
000854|           (*[511462]*)let slenbytes = slen lsr 3 in
000855|           (*[345655]*)if slenbytes > 0 then (*[165807]*)Buffer.add_substring buf str 0 slenbytes;
000856|           (*[511462]*)let last = Char.code str.[slenbytes] in (* last char *)
000857|           (*[511462]*)let mask = 0xff lsl (8 - (slen land 7)) in
000858|           (*[511462]*)t.last <- last land mask
000859|         );
000860|         (*[575784]*)t.len <- len + slen
000861|       ) else (
000862|         (* Target buffer is unaligned.  Copy whole bytes using
000863|          * add_byte which knows how to deal with an unaligned
000864|          * target buffer, then call add_bit for the remaining < 8 bits.
000865|          *
000866|          * XXX This is going to be dog-slow.
000867|          *)
000868|         (*[813330]*)let slenbytes = slen lsr 3 in
000869|         (*[813330]*)for i = 0 to slenbytes-1 do
000870|           (*[5943116]*)let byte = Char.code str.[i] in
000871|           (*[5943116]*)add_byte t byte
000872|         done;
000873|         (*[813330]*)let bitsleft = slen - (slenbytes lsl 3) in
000874|         (*[144583]*)if bitsleft > 0 then (
000875|           (*[668747]*)let c = Char.code str.[slenbytes] in
000876|           (*[668747]*)for i = 0 to bitsleft - 1 do
000877|             (*[2652755]*)let bit = c land (0x80 lsr i) <> 0 in
000878|             (*[2652755]*)add_bit t bit
000879|           done
000880|         )
000881|       );
000882|     )
000883| end
000884|  
000885| (* Construct a single bit. *)
000886| let construct_bit buf b _ _ =
000887|   (*[130]*)Buffer.add_bit buf b
000888|  
000889| (* Construct a field, flen = [2..8]. *)
000890| let construct_char_unsigned buf v flen exn =
000891|   (*[1204740]*)let max_val = 1 lsl flen in
000892|   (*[1204740]*)if (*[1204740]*)v < 0 || (*[1204740]*)v >= max_val then (*[0]*)raise exn;
000893|   (*[1204740]*)if flen = 8 then
000894|     (*[1203960]*)Buffer.add_byte buf v
000895|   else
000896|     (*[780]*)Buffer._add_bits buf v flen
000897|  
000898| (* Construct a field of up to 31 bits. *)
000899| let construct_int_be_unsigned buf v flen exn =
000900|   (* Check value is within range. *)
000901|   (*[392]*)if not (I.range_unsigned v flen) then (*[0]*)raise exn;
000902|   (* Add the bytes. *)
000903|   (*[392]*)I.map_bytes_be (Buffer._add_bits buf) (Buffer.add_byte buf) v flen
000904|  
000905| (* Construct a field of up to 31 bits. *)
000906| let construct_int_le_unsigned buf v flen exn =
000907|   (* Check value is within range. *)
000908|   (*[780]*)if not (I.range_unsigned v flen) then (*[0]*)raise exn;
000909|   (* Add the bytes. *)
000910|   (*[780]*)I.map_bytes_le (Buffer._add_bits buf) (Buffer.add_byte buf) v flen
000911|  
000912| let construct_int_ne_unsigned =
000913|   (*[43]*)if nativeendian = BigEndian
000914|   then (*[0]*)construct_int_be_unsigned
000915|   else (*[43]*)construct_int_le_unsigned
000916|  
000917| let construct_int_ee_unsigned = function
000918|   | BigEndian -> (*[0]*)construct_int_be_unsigned
000919|   | LittleEndian -> (*[0]*)construct_int_le_unsigned
000920|   | NativeEndian -> (*[0]*)construct_int_ne_unsigned
000921|  
000922| (* Construct a field of exactly 32 bits. *)
000923| let construct_int32_be_unsigned buf v flen _ =
000924|   (*[136]*)Buffer.add_byte buf
000925|     (Int32.to_int (Int32.shift_right_logical v 24));
000926|   (*[136]*)Buffer.add_byte buf
000927|     (Int32.to_int ((Int32.logand (Int32.shift_right_logical v 16) 0xff_l)));
000928|   (*[136]*)Buffer.add_byte buf
000929|     (*[136]*)(Int32.to_int ((Int32.logand (Int32.shift_right_logical v 8) 0xff_l)));
000930|   (*[136]*)Buffer.add_byte buf
000931|     (Int32.to_int (Int32.logand v 0xff_l))
000932|  
000933| let construct_int32_le_unsigned buf v flen _ =
000934|   (*[272]*)Buffer.add_byte buf
000935|     (Int32.to_int (Int32.logand v 0xff_l));
000936|   (*[272]*)Buffer.add_byte buf
000937|     (Int32.to_int ((Int32.logand (Int32.shift_right_logical v 8) 0xff_l)));
000938|   (*[272]*)Buffer.add_byte buf
000939|     (*[272]*)(Int32.to_int ((Int32.logand (Int32.shift_right_logical v 16) 0xff_l)));
000940|   (*[272]*)Buffer.add_byte buf
000941|     (Int32.to_int (Int32.shift_right_logical v 24))
000942|  
000943| let construct_int32_ne_unsigned =
000944|   (*[43]*)if nativeendian = BigEndian
000945|   then (*[0]*)construct_int32_be_unsigned
000946|   else (*[43]*)construct_int32_le_unsigned
000947|  
000948| let construct_int32_ee_unsigned = function
000949|   | BigEndian -> (*[6]*)construct_int32_be_unsigned
000950|   | LittleEndian -> (*[6]*)construct_int32_le_unsigned
000951|   | NativeEndian -> (*[6]*)construct_int32_ne_unsigned
000952|  
000953| (* Construct a field of up to 64 bits. *)
000954| let construct_int64_be_unsigned buf v flen exn =
000955|   (* Check value is within range. *)
000956|   (*[352110]*)if not (I64.range_unsigned v flen) then (*[0]*)raise exn;
000957|   (* Add the bytes. *)
000958|   (*[352110]*)I64.map_bytes_be (Buffer._add_bits buf) (Buffer.add_byte buf) v flen
000959|  
000960| (* Construct a field of up to 64 bits. *)
000961| let construct_int64_le_unsigned buf v flen exn =
000962|   (* Check value is within range. *)
000963|   (*[520]*)if not (I64.range_unsigned v flen) then (*[0]*)raise exn;
000964|   (* Add the bytes. *)
000965|   (*[520]*)I64.map_bytes_le (Buffer._add_bits buf) (Buffer.add_byte buf) v flen
000966|  
000967| let construct_int64_ne_unsigned =
000968|   (*[43]*)if nativeendian = BigEndian
000969|   then (*[0]*)construct_int64_be_unsigned
000970|   else (*[43]*)construct_int64_le_unsigned
000971|  
000972| let construct_int64_ee_unsigned = function
000973|   | BigEndian -> (*[0]*)construct_int64_be_unsigned
000974|   | LittleEndian -> (*[0]*)construct_int64_le_unsigned
000975|   | NativeEndian -> (*[0]*)construct_int64_ne_unsigned
000976|  
000977| (* Construct from a string of bytes, exact multiple of 8 bits
000978|  * in length of course.
000979|  *)
000980| let construct_string buf str =
000981|   (*[89505]*)let len = String.length str in
000982|   (*[89505]*)Buffer.add_bits buf str (len lsl 3)
000983|  
000984| (* Construct from a bitstring. *)
000985| let construct_bitstring buf (data, off, len) =
000986|   (* Add individual bits until we get to the next byte boundary of
000987|    * the underlying string.
000988|    *)
000989|   (*[1317896]*)let blen = 7 - ((off + 7) land 7) in
000990|   (*[1317896]*)let blen = min blen len in
000991|   (*[1317896]*)let rec loop off len blen =
000992|     (*[1317896]*)if blen = 0 then ((*[1317896]*)off, len)
000993|     else (
000994|       (*[0]*)let b = extract_bit data off len 1
000995|       and off = off + 1 and len = len + 1 in
000996|       (*[0]*)Buffer.add_bit buf (*[0]*)b;
000997|       (*[0]*)loop off len (blen-1)
000998|     )
000999|   in
001000|   (*[1317896]*)let off, len = loop off len blen in
001001|   (*[1317896]*)assert ((*[1317896]*)len = 0 || (off (*[1291094]*)land 7) = 0);
001002|  
001003|   (* Add the remaining 'len' bits. *)
001004|   (*[1317896]*)let data =
001005|     let off = off lsr 3 in
001006|     (* XXX dangerous allocation *)
001007|     (*[1317896]*)if off = 0 then (*[1317896]*)data
001008|     else (*[0]*)String.sub data off (String.length data - off) in
001009|  
001010|   (*[1317896]*)Buffer.add_bits buf data len
001011|  
001012| (* Concatenate bitstrings. *)
001013| let concat bs =
001014|   (*[40461]*)let buf = Buffer.create () in
001015|   (*[40461]*)List.iter (construct_bitstring buf) (*[40461]*)bs;
001016|   (*[40461]*)Buffer.contents buf
001017|  
001018| (*----------------------------------------------------------------------*)
001019| (* Extract a string from a bitstring. *)
001020| let string_of_bitstring (data, off, len) =
001021|   (*[73011]*)if off (*[73011]*)land 7 = 0 && len (*[16597]*)land 7 = 0 then
001022|     (* Easy case: everything is byte-aligned. *)
001023|     (*[9037]*)String.sub data (off lsr 3) (len lsr 3)
001024|   else (
001025|     (* Bit-twiddling case. *)
001026|     (*[63974]*)let strlen = (len + 7) lsr 3 in
001027|     (*[63974]*)let str = String.make strlen '\000' in
001028|     (*[63974]*)let rec loop data off len i =
001029|       (*[326148]*)if len >= 8 then (
001030|         (*[262174]*)let c = extract_char_unsigned data off len 8
001031|         and off = off + 8 and len = len - 8 in
001032|         (*[262174]*)str.[i] (*[262174]*)<- Char.chr c;
001033|         (*[262174]*)loop data off len (i+1)
001034|       ) else (*[52324]*)if len > 0 then (
001035|         (*[11650]*)let c = extract_char_unsigned data off len len in
001036|         (*[11650]*)str.[i] <- Char.chr (c lsl (8-len))
001037|       )
001038|     in
001039|     (*[63974]*)loop data off len (*[63974]*)0;
001040|     (*[63974]*)str
001041|   )
001042|  
001043| (* To channel. *)
001044|  
001045| let bitstring_to_chan ((data, off, len) as bits) chan =
001046|   (* Fail if the bitstring length isn't a multiple of 8. *)
001047|   (*[1]*)if len land 7 <> 0 then (*[0]*)invalid_arg "bitstring_to_chan";
001048|  
001049|   (*[1]*)if off land 7 = 0 then
001050|     (* Easy case: string is byte-aligned. *)
001051|     (*[1]*)output chan data (off lsr 3) (len lsr 3)
001052|   else (
001053|     (* Bit-twiddling case: reuse string_of_bitstring *)
001054|     (*[0]*)let str = string_of_bitstring bits in
001055|     (*[0]*)output_string chan str
001056|   )
001057|  
001058| let bitstring_to_file bits filename =
001059|   (*[0]*)let chan = open_out_bin filename in
001060|   (*[0]*)try
001061|     (*[0]*)bitstring_to_chan bits chan;
001062|     (*[0]*)close_out chan
001063|   with exn ->
001064|     (*[0]*)close_out (*[0]*)chan;
001065|     (*[0]*)raise exn
001066|  
001067| (*----------------------------------------------------------------------*)
001068| (* Comparison. *)
001069| let compare ((data1, off1, len1) as bs1) ((data2, off2, len2) as bs2) =
001070|   (* In the fully-aligned case, this is reduced to string comparison ... *)
001071|   (*[4624]*)if off1 (*[4624]*)land 7 = 0 && len1 (*[4624]*)land 7 (*[4624]*)= 0 && off2 (*[680]*)land 7 (*[680]*)= 0 && len2 (*[535]*)land 7 = 0
001072|   then (
001073|     (* ... but we have to do that by hand because the bits may
001074|      * not extend to the full length of the underlying string.
001075|      *)
001076|     (*[100]*)let off1 = off1 lsr 3 and off2 = off2 lsr 3
001077|     and len1 = len1 lsr 3 and len2 = len2 lsr 3 in
001078|     (*[100]*)let rec loop i =
001079|       (*[240]*)if (*[240]*)i < len1 && (*[170]*)i < len2 then (
001080|         (*[140]*)let c1 = String.unsafe_get data1 (off1 + i)
001081|         and c2 = String.unsafe_get data2 (off2 + i) in
001082|         (*[140]*)let r = compare c1 c2 in
001083|         (*[140]*)if r <> 0 then (*[0]*)r
001084|         else (*[140]*)loop (i+1)
001085|       )
001086|       else (*[100]*)len1 - len2
001087|     in
001088|     (*[100]*)loop 0
001089|   )
001090|   else (
001091|     (* Slow/unaligned. *)
001092|     (*[4524]*)let str1 = string_of_bitstring bs1
001093|     and str2 = string_of_bitstring bs2 in
001094|     (*[4524]*)let r = String.compare str1 str2 in
001095|     (*[4524]*)if r <> 0 then (*[3058]*)r else (*[1466]*)len1 - len2
001096|   )
001097|  
001098| let equals ((_, _, len1) as bs1) ((_, _, len2) as bs2) =
001099|   (*[7]*)if len1 <> len2 then (*[0]*)false
001100|   else (*[7]*)if bs1 = bs2 then (*[7]*)true
001101|   else (*[0]*)0 = compare bs1 bs2
001102|  
001103| (*----------------------------------------------------------------------*)
001104| (* Bit get/set functions. *)
001105|  
001106| let index_out_of_bounds () = (*[0]*)invalid_arg "index out of bounds"
001107|  
001108| let put (data, off, len) n v =
001109|   (*[0]*)if (*[0]*)n < 0 || (*[0]*)off+n >= len then (*[0]*)index_out_of_bounds ()
001110|   else (
001111|     (*[0]*)let i = off+n in
001112|     (*[0]*)let si = i lsr 3 and mask = 0x80 lsr (i land 7) in
001113|     (*[0]*)let c = Char.code data.[si] in
001114|     (*[0]*)let c = if v <> 0 then c (*[0]*)lor mask else c (*[0]*)land (lnot mask) in
001115|     (*[0]*)data.[si] <- Char.unsafe_chr c
001116|   )
001117|  
001118| let set bits n = (*[0]*)put bits n 1
001119|  
001120| let clear bits n = (*[0]*)put bits n 0
001121|  
001122| let get (data, off, len) n =
001123|   (*[1945548]*)if (*[1945548]*)n < 0 || (*[1945548]*)off+n >= len then (*[0]*)index_out_of_bounds ()
001124|   else (
001125|     (*[1945548]*)let i = off+n in
001126|     (*[1945548]*)let si = i lsr 3 and mask = 0x80 lsr (i land 7) in
001127|     (*[1945548]*)let c = Char.code data.[si] in
001128|     c (*[1945548]*)land mask
001129|   )
001130|  
001131| let is_set bits n = (*[1297032]*)get bits n <> 0
001132|  
001133| let is_clear bits n = (*[648516]*)get bits n = 0
001134|  
001135| (*----------------------------------------------------------------------*)
001136| (* Display functions. *)
001137|  
001138| let isprint c =
001139|   (*[356]*)let c = Char.code c in
001140|   (*[356]*)c (*[356]*)>= 32 && (*[311]*)c < 127
001141|  
001142| let hexdump_bitstring chan (data, off, len) =
001143|   (*[34]*)let count = ref 0 in
001144|   (*[34]*)let off = ref off in
001145|   (*[34]*)let len = ref len in
001146|   (*[34]*)let linelen = ref 0 in
001147|   (*[34]*)let linechars = String.make 16 ' ' in
001148|  
001149|   (*[34]*)fprintf chan "00000000  ";
001150|  
001151|   (*[34]*)while !len > 0 do
001152|     (*[356]*)let bits = min !len 8 in
001153|     (*[356]*)let byte = extract_char_unsigned data !off !len bits in
001154|     (*[356]*)off := !off + bits; (*[356]*)len (*[356]*):= !len - bits;
001155|  
001156|     (*[356]*)let byte = byte lsl (8-bits) in
001157|     (*[356]*)fprintf chan "%02x " byte;
001158|  
001159|     (*[356]*)incr count;
001160|     (*[356]*)linechars.[!linelen] <-
001161|       (let c = Char.chr byte in
001162|        (*[356]*)if isprint c then (*[110]*)c else (*[246]*)'.');
001163|     (*[356]*)incr linelen;
001164|     (*[335]*)if !linelen = 8 then (*[21]*)fprintf chan " ";
001165|     (*[343]*)if !linelen = 16 then (
001166|       (*[13]*)fprintf chan " |%s|\n%08x  " linechars !count;
001167|       (*[13]*)linelen (*[13]*):= 0;
001168|       (*[13]*)for i = 0 to 15 do (*[208]*)linechars.[i] <- ' ' done
001169|     )
001170|   done;
001171|  
001172|   (*[34]*)if !linelen > 0 then (
001173|     (*[32]*)let skip = (16 - !linelen) * 3 + if !linelen < 8 then (*[24]*)1 else (*[8]*)0 in
001174|     (*[32]*)for i = 0 to skip-1 do (*[1116]*)fprintf chan " " done;
001175|     (*[32]*)fprintf chan " |%s|\n%!" linechars
001176|   ) else
001177|     (*[2]*)fprintf chan "\n%!"

ocaml-bitstring-2.0.4/coverage-report/file0002.html0000664000175000017500000001147012144455551021423 0ustar rjonesrjones Bisect report

File: bitmatch.ml (return to index)


Statistics:

kind coverage
binding 0 / 0 (- %)
sequence 0 / 0 (- %)
for 0 / 0 (- %)
if/then 0 / 0 (- %)
try 0 / 0 (- %)
while 0 / 0 (- %)
match/function 0 / 0 (- %)
class expression 0 / 0 (- %)
class initializer 0 / 0 (- %)
class method 0 / 0 (- %)
class value 0 / 0 (- %)
toplevel expression 0 / 0 (- %)

Source:

000001| (** Bitmatch backwards compatibility library. *)
000002| (* Bitstring library.
000003|  * Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones
000004|  *
000005|  * This library is free software; you can redistribute it and/or
000006|  * modify it under the terms of the GNU Lesser General Public
000007|  * License as published by the Free Software Foundation; either
000008|  * version 2 of the License, or (at your option) any later version,
000009|  * with the OCaml linking exception described in COPYING.LIB.
000010|  *
000011|  * This library is distributed in the hope that it will be useful,
000012|  * but WITHOUT ANY WARRANTY; without even the implied warranty of
000013|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
000014|  * Lesser General Public License for more details.
000015|  *
000016|  * You should have received a copy of the GNU Lesser General Public
000017|  * License along with this library; if not, write to the Free Software
000018|  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
000019|  *
000020|  * $Id: bitmatch.ml 142 2008-07-17 15:45:56Z richard.wm.jones $
000021|  *)
000022| (** This is just for backwards compatibility with code
000023|     from when the library was called bitmatch.  You should
000024|     replace all references to this module with {!Bitstring}.
000025| *)
000026|  
000027| include Bitstring

ocaml-bitstring-2.0.4/coverage-report/file0000.html0000664000175000017500000001251212144455551021417 0ustar rjonesrjones Bisect report

File: bitstring_config.ml (return to index)


Statistics:

kind coverage
binding 5 / 5 (100 %)
sequence 0 / 0 (- %)
for 0 / 0 (- %)
if/then 0 / 0 (- %)
try 0 / 0 (- %)
while 0 / 0 (- %)
match/function 0 / 0 (- %)
class expression 0 / 0 (- %)
class initializer 0 / 0 (- %)
class method 0 / 0 (- %)
class value 0 / 0 (- %)
toplevel expression 0 / 0 (- %)

Source:

000001| (* Bitstring library.
000002|  * Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones
000003|  *
000004|  * bitstring_config.ml.  Generated from bitstring_config.ml.in by configure.
000005|  *
000006|  * This library is free software; you can redistribute it and/or
000007|  * modify it under the terms of the GNU Lesser General Public
000008|  * License as published by the Free Software Foundation; either
000009|  * version 2 of the License, or (at your option) any later version,
000010|  * with the OCaml linking exception described in COPYING.LIB.
000011|  *
000012|  * This library is distributed in the hope that it will be useful,
000013|  * but WITHOUT ANY WARRANTY; without even the implied warranty of
000014|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
000015|  * Lesser General Public License for more details.
000016|  *
000017|  * You should have received a copy of the GNU Lesser General Public
000018|  * License along with this library; if not, write to the Free Software
000019|  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
000020|  *
000021|  * $Id: bitstring_config.ml.in 142 2008-07-17 15:45:56Z richard.wm.jones $
000022|  *)
000023|  
000024| (* This file contains general configuration settings, set by the
000025|  * configure script.
000026|  *)
000027|  
000028| let nativeendian = (*[43]*)Bitstring_types.LittleEndian
000029|  
000030| let package = (*[43]*)"ocaml-bitstring"
000031| let version = (*[43]*)"1.9.8"
000032| let ocamllibdir = (*[43]*)"/usr/lib/ocaml"
000033|  
000034| let diff = (*[43]*)"/usr/bin/diff"

ocaml-bitstring-2.0.4/coverage-report/style.css0000664000175000017500000000241512144455551021165 0ustar rjonesrjonesbody { background: white; white-space: nowrap; } .footer { font-size: smaller; text-align: center; } .codeSep { border: none 0; border-top: 1px solid gray; height: 1px; } .indexSep { border: none 0; border-top: 1px solid gray; height: 1px; width: 75%; } .lineNone { white-space: nowrap; background: white; } .lineAllVisited { white-space: nowrap; background: green; } .lineAllUnvisited { white-space: nowrap; background: red; } .lineMixed { white-space: nowrap; background: yellow; } table.simple { border-width: 1px; border-spacing: 0px; border-top-style: solid; border-bottom-style: solid; border-color: black; } table.simple th { border-width: 1px; border-spacing: 0px; border-bottom-style: solid; border-color: black; text-align: center; font-weight: bold; } table.simple td { border-width: 1px; border-spacing: 0px; border-style: none; } table.gauge { border-width: 0px; border-spacing: 0px; padding: 0px; border-style: none; border-collapse: collapse; } table.gauge td { border-width: 0px; border-spacing: 0px; padding: 0px; border-style: none; border-collapse: collapse; } .gaugeOK { background: green; } .gaugeKO { background: red; } ocaml-bitstring-2.0.4/coverage-report/index.html0000664000175000017500000000645412144455551021317 0ustar rjonesrjones Bisect report

Bisect report


Overall statistics

kind coverage binding 231 / 250 (92 %) sequence 83 / 95 (87 %) for 5 / 5 (100 %) if/then 141 / 194 (72 %) try 1 / 2 (50 %) while 3 / 3 (100 %) match/function 64 / 90 (71 %) class expression 0 / 0 (- %) class initializer 0 / 0 (- %) class method 0 / 0 (- %) class value 0 / 0 (- %) toplevel expression 0 / 0 (- %)


Per-file coverage

coverage   file
 -%
  bitmatch.ml
 82%
  bitstring.ml
 100%
  bitstring_config.ml
 0%
  bitstring_types.ml



ocaml-bitstring-2.0.4/TODO0000664000175000017500000000773212144455551014706 0ustar rjonesrjones$Id: TODO 186 2010-02-05 14:01:53Z richard.wm.jones $ Major to-do items. (1) DONE - In bitmatch operator, use patterns not expressions. (2) DONE - Allow matching against strings. (3) DONE - Change the syntax so { ... } surrounds match patterns. (4) Provide UInt32 and UInt64 types. (5) DONE - Allow for specific offsets and alignment. Something like this: { start : 16; another : 16 : offset(256); (* location would be 256 bits from start *) } (6) and: { start : 16; another : 16 : align(32); (* implicit 16 bit gap before this *) } (7) Assertions: { start : 16 : assert (offset = 0); } (Q: Are these evaluated at compile time or at run time or selectable?) (8) Named but unbound patterns to avoid "Warning Y: unused variable". (9) DONE - Make the error locations fine-grained, particularly so they point to individual fields, not the whole match. (10) DONE - Cross-module, persistent, named patterns, see: http://caml.inria.fr/pub/ml-archives/caml-list/2008/04/25992c9c9fa999fe1d35d961dd9917a2.en.html (11) DONE - Runtime endiannness expressions. The suggested syntax is: { field : len : endian (expr) } where expr would evaluate to something like BigEndian or LittleEndian. There are several protocols around where endianness is only determined at runtime, examples are libpcap and TIFF. (12) DONE - More constant field lengths. (13) PARTLY DONE - Implement native endian functions. (14) PARTLY DONE - A proper test suite. (15) DONE - More examples: ELF binaries GIF images (16) We now know the offset of the current field relative to the whole match. This may allow more efficient aligned versions of functions to be called (at compile time). However do note that the offset in the bitstring is usually not known. (17) PARTLY DONE - Fix the META file. Current one is very broken. (18) DONE - check() qualifier: { field : 16 : check (field > 100) } The check(expr) qualifier will abort the rest of the match if the expression is false. (19) DONE - bind() qualifier: { field : 16 : bind (field * 3) } ^pattern ^new value The bind(expr) qualifier binds the pattern to a new value, equivalent to doing: let field = field * 3 in (* remainder of match *) There is a question of whether bind() should run before or after when() [best is probably when() first, then bind()]. (20) DONE - save_offset_to() qualifier: { field : 16 : save_offset_to (offset), bind (field - offset) } or: { field : 16 : save_offset_to (field_offset) } -> printf "the offset of field (%d) is %d\n" field field_offset save_offset_to(patt) binds the current match offset to the variable, for later use within bind(), when() or any later parts of the match. (21) derive() so you can add your own variable decls: { field : 32 : derive (field_as_int, Int32.to_int field) } This would add a let derivation, equivalent to: let field_as_int = Int32.to_int field allowing you to use both the original field and field_as_int as variables. Note you can do this clumsily using bind(): { field : 32 : bind (field, Int32.to_int field) } which redefines 'field' as a pair of (old value, derived value). (22) Allow constant 0 to be used in constructors to mean a zero-length bitstring of the right length, eg: BITSTRING { 0 : 32*8 : bitstring } which would be equivalent to: BITSTRING { zeroes_bitstring (32*8) : 32*8 : bitstring } (23) Add predicate Bitstring.is_zero_bitstring : bitstring -> bool (24) Add a function to turn bitstrings into printable strings. (25) Folding over bitstrings. A narrow usage for this is to generate checksums and hashes, where usually you want to fold over every 8/16/32-bit word. So a set of functions which just enabled this would be useful. (However you still need le/be/ne variations so it involves at least 7 functions). ocaml-bitstring-2.0.4/install-sh0000775000175000017500000003160012144455551016211 0ustar rjonesrjones#!/bin/sh # install - install a program, script, or datafile scriptversion=2006-10-14.15 # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the # following copyright and license. # # Copyright (C) 1994 X Consortium # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to # deal in the Software without restriction, including without limitation the # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or # sell copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # Except as contained in this notice, the name of the X Consortium shall not # be used in advertising or otherwise to promote the sale, use or other deal- # ings in this Software without prior written authorization from the X Consor- # tium. # # # FSF changes to this file are in the public domain. # # Calling this script install-sh is preferred over install.sh, to prevent # `make' implicit rules from creating a file called install from it # when there is no Makefile. # # This script is compatible with the BSD install script, but was written # from scratch. nl=' ' IFS=" "" $nl" # set DOITPROG to echo to test this script # Don't use :- since 4.3BSD and earlier shells don't like it. doit="${DOITPROG-}" if test -z "$doit"; then doit_exec=exec else doit_exec=$doit fi # Put in absolute file names if you don't have them in your path; # or use environment vars. mvprog="${MVPROG-mv}" cpprog="${CPPROG-cp}" chmodprog="${CHMODPROG-chmod}" chownprog="${CHOWNPROG-chown}" chgrpprog="${CHGRPPROG-chgrp}" stripprog="${STRIPPROG-strip}" rmprog="${RMPROG-rm}" mkdirprog="${MKDIRPROG-mkdir}" posix_glob= posix_mkdir= # Desired mode of installed file. mode=0755 chmodcmd=$chmodprog chowncmd= chgrpcmd= stripcmd= rmcmd="$rmprog -f" mvcmd="$mvprog" src= dst= dir_arg= dstarg= no_target_directory= usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE or: $0 [OPTION]... SRCFILES... DIRECTORY or: $0 [OPTION]... -t DIRECTORY SRCFILES... or: $0 [OPTION]... -d DIRECTORIES... In the 1st form, copy SRCFILE to DSTFILE. In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. In the 4th, create DIRECTORIES. Options: -c (ignored) -d create directories instead of installing files. -g GROUP $chgrpprog installed files to GROUP. -m MODE $chmodprog installed files to MODE. -o USER $chownprog installed files to USER. -s $stripprog installed files. -t DIRECTORY install into DIRECTORY. -T report an error if DSTFILE is a directory. --help display this help and exit. --version display version info and exit. Environment variables override the default commands: CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG " while test $# -ne 0; do case $1 in -c) shift continue;; -d) dir_arg=true shift continue;; -g) chgrpcmd="$chgrpprog $2" shift shift continue;; --help) echo "$usage"; exit $?;; -m) mode=$2 shift shift case $mode in *' '* | *' '* | *' '* | *'*'* | *'?'* | *'['*) echo "$0: invalid mode: $mode" >&2 exit 1;; esac continue;; -o) chowncmd="$chownprog $2" shift shift continue;; -s) stripcmd=$stripprog shift continue;; -t) dstarg=$2 shift shift continue;; -T) no_target_directory=true shift continue;; --version) echo "$0 $scriptversion"; exit $?;; --) shift break;; -*) echo "$0: invalid option: $1" >&2 exit 1;; *) break;; esac done if test $# -ne 0 && test -z "$dir_arg$dstarg"; then # When -d is used, all remaining arguments are directories to create. # When -t is used, the destination is already specified. # Otherwise, the last argument is the destination. Remove it from $@. for arg do if test -n "$dstarg"; then # $@ is not empty: it contains at least $arg. set fnord "$@" "$dstarg" shift # fnord fi shift # arg dstarg=$arg done fi if test $# -eq 0; then if test -z "$dir_arg"; then echo "$0: no input file specified." >&2 exit 1 fi # It's OK to call `install-sh -d' without argument. # This can happen when creating conditional directories. exit 0 fi if test -z "$dir_arg"; then trap '(exit $?); exit' 1 2 13 15 # Set umask so as not to create temps with too-generous modes. # However, 'strip' requires both read and write access to temps. case $mode in # Optimize common cases. *644) cp_umask=133;; *755) cp_umask=22;; *[0-7]) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw='% 200' fi cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; *) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw=,u+rw fi cp_umask=$mode$u_plus_rw;; esac fi for src do # Protect names starting with `-'. case $src in -*) src=./$src ;; esac if test -n "$dir_arg"; then dst=$src dstdir=$dst test -d "$dstdir" dstdir_status=$? else # Waiting for this to be detected by the "$cpprog $src $dsttmp" command # might cause directories to be created, which would be especially bad # if $src (and thus $dsttmp) contains '*'. if test ! -f "$src" && test ! -d "$src"; then echo "$0: $src does not exist." >&2 exit 1 fi if test -z "$dstarg"; then echo "$0: no destination specified." >&2 exit 1 fi dst=$dstarg # Protect names starting with `-'. case $dst in -*) dst=./$dst ;; esac # If destination is a directory, append the input filename; won't work # if double slashes aren't ignored. if test -d "$dst"; then if test -n "$no_target_directory"; then echo "$0: $dstarg: Is a directory" >&2 exit 1 fi dstdir=$dst dst=$dstdir/`basename "$src"` dstdir_status=0 else # Prefer dirname, but fall back on a substitute if dirname fails. dstdir=` (dirname "$dst") 2>/dev/null || expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$dst" : 'X\(//\)[^/]' \| \ X"$dst" : 'X\(//\)$' \| \ X"$dst" : 'X\(/\)' \| . 2>/dev/null || echo X"$dst" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q' ` test -d "$dstdir" dstdir_status=$? fi fi obsolete_mkdir_used=false if test $dstdir_status != 0; then case $posix_mkdir in '') # Create intermediate dirs using mode 755 as modified by the umask. # This is like FreeBSD 'install' as of 1997-10-28. umask=`umask` case $stripcmd.$umask in # Optimize common cases. *[2367][2367]) mkdir_umask=$umask;; .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; *[0-7]) mkdir_umask=`expr $umask + 22 \ - $umask % 100 % 40 + $umask % 20 \ - $umask % 10 % 4 + $umask % 2 `;; *) mkdir_umask=$umask,go-w;; esac # With -d, create the new directory with the user-specified mode. # Otherwise, rely on $mkdir_umask. if test -n "$dir_arg"; then mkdir_mode=-m$mode else mkdir_mode= fi posix_mkdir=false case $umask in *[123567][0-7][0-7]) # POSIX mkdir -p sets u+wx bits regardless of umask, which # is incompatible with FreeBSD 'install' when (umask & 300) != 0. ;; *) tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 if (umask $mkdir_umask && exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 then if test -z "$dir_arg" || { # Check for POSIX incompatibilities with -m. # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or # other-writeable bit of parent directory when it shouldn't. # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. ls_ld_tmpdir=`ls -ld "$tmpdir"` case $ls_ld_tmpdir in d????-?r-*) different_mode=700;; d????-?--*) different_mode=755;; *) false;; esac && $mkdirprog -m$different_mode -p -- "$tmpdir" && { ls_ld_tmpdir_1=`ls -ld "$tmpdir"` test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" } } then posix_mkdir=: fi rmdir "$tmpdir/d" "$tmpdir" else # Remove any dirs left behind by ancient mkdir implementations. rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null fi trap '' 0;; esac;; esac if $posix_mkdir && ( umask $mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" ) then : else # The umask is ridiculous, or mkdir does not conform to POSIX, # or it failed possibly due to a race condition. Create the # directory the slow way, step by step, checking for races as we go. case $dstdir in /*) prefix=/ ;; -*) prefix=./ ;; *) prefix= ;; esac case $posix_glob in '') if (set -f) 2>/dev/null; then posix_glob=true else posix_glob=false fi ;; esac oIFS=$IFS IFS=/ $posix_glob && set -f set fnord $dstdir shift $posix_glob && set +f IFS=$oIFS prefixes= for d do test -z "$d" && continue prefix=$prefix$d if test -d "$prefix"; then prefixes= else if $posix_mkdir; then (umask=$mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break # Don't fail if two instances are running concurrently. test -d "$prefix" || exit 1 else case $prefix in *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; *) qprefix=$prefix;; esac prefixes="$prefixes '$qprefix'" fi fi prefix=$prefix/ done if test -n "$prefixes"; then # Don't fail if two instances are running concurrently. (umask $mkdir_umask && eval "\$doit_exec \$mkdirprog $prefixes") || test -d "$dstdir" || exit 1 obsolete_mkdir_used=true fi fi fi if test -n "$dir_arg"; then { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 else # Make a couple of temp file names in the proper directory. dsttmp=$dstdir/_inst.$$_ rmtmp=$dstdir/_rm.$$_ # Trap to clean up those temp files at exit. trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 # Copy the file name to the temp name. (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && # and set any options; do chmod last to preserve setuid bits. # # If any of these fail, we abort the whole thing. If we want to # ignore errors from any of these, just make sure not to ignore # errors from the above "$doit $cpprog $src $dsttmp" command. # { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \ && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && # Now rename the file to the real destination. { $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null \ || { # The rename failed, perhaps because mv can't rename something else # to itself, or perhaps because mv is so ancient that it does not # support -f. # Now remove or move aside any old file at destination location. # We try this two ways since rm can't unlink itself on some # systems and the destination file might be busy for other # reasons. In this case, the final cleanup might fail but the new # file should still install successfully. { if test -f "$dst"; then $doit $rmcmd -f "$dst" 2>/dev/null \ || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null \ && { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }; }\ || { echo "$0: cannot unlink or rename $dst" >&2 (exit 1); exit 1 } else : fi } && # Now rename the file to the real destination. $doit $mvcmd "$dsttmp" "$dst" } } || exit 1 trap '' 0 fi done # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-end: "$" # End: ocaml-bitstring-2.0.4/bitstring_c.c0000664000175000017500000001114512144455550016661 0ustar rjonesrjones/* Bitstring library. * Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version, * with the OCaml linking exception described in COPYING.LIB. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: bitstring.ml 146 2008-08-20 16:58:33Z richard.wm.jones $ */ /* This file contains hand-coded, optimized C implementations of * certain very frequently used functions. */ #include #include #include #include #include #include #include #include /* Fastpath functions. These are used in the common case for reading * ints where the following conditions are known to be true: * (a) the int size is a whole number of bytes (eg. 16, 24, 32, etc bits) * (b) the access in the match is byte-aligned * (c) the access in the underlying bitstring is byte-aligned * * These functions are all "noalloc" meaning they must not perform * any OCaml allocations. For this reason, when the function returns * an int32 or int64, the OCaml code passes in the pre-allocated pointer * to the return value. * * The final offset in the string is calculated by the OCaml (caller) * code. All we need to do is to read the string+offset and byteswap, * sign-extend as necessary. * * There is one function for every combination of: * (i) int size: 16, 32, 64 bits * (ii) endian: bigendian, littleendian, nativeendian * (iii) signed and unsigned * * XXX Future work: Expand this to 24, 40, 48, 56 bits. This * requires some extra work because sign-extension won't "just happen". */ #ifdef WORDS_BIGENDIAN #define swap_be(size,v) #define swap_le(size,v) v = bswap_##size (v) #define swap_ne(size,v) #else #define swap_be(size,v) v = bswap_##size (v) #define swap_le(size,v) #define swap_ne(size,v) #endif #define fastpath1(size,endian,signed,type) \ CAMLprim value \ ocaml_bitstring_extract_fastpath_int##size##_##endian##_##signed \ (value strv, value offv) \ { \ type *ptr = (type *) ((void *) String_val (strv) + Int_val (offv)); \ type r; \ memcpy(&r, ptr, sizeof(r)); \ swap_##endian(size,r); \ return Val_int (r); \ } fastpath1(16,be,unsigned,uint16_t) fastpath1(16,le,unsigned,uint16_t) fastpath1(16,ne,unsigned,uint16_t) fastpath1(16,be,signed,int16_t) fastpath1(16,le,signed,int16_t) fastpath1(16,ne,signed,int16_t) #define fastpath2(size,endian,signed,type,rval) \ CAMLprim value \ ocaml_bitstring_extract_fastpath_int##size##_##endian##_##signed \ (value strv, value offv, value rv) \ { \ type *ptr = (type *) ((void *) String_val (strv) + Int_val (offv)); \ type r; \ memcpy(&r, ptr, sizeof(r)); \ swap_##endian(size,r); \ rval(rv) = r; \ return rv; \ } fastpath2(32,be,unsigned,uint32_t,Int32_val) fastpath2(32,le,unsigned,uint32_t,Int32_val) fastpath2(32,ne,unsigned,uint32_t,Int32_val) fastpath2(32,be,signed,int32_t,Int32_val) fastpath2(32,le,signed,int32_t,Int32_val) fastpath2(32,ne,signed,int32_t,Int32_val) /* Special care needs to be taken on ARCH_ALIGN_INT64 platforms (hppa and sparc in Debian). */ #ifdef ARCH_ALIGN_INT64 #include #include #define fastpath3(size,endian,signed,type,rval) \ CAMLprim value \ ocaml_bitstring_extract_fastpath_int##size##_##endian##_##signed \ (value strv, value offv, value rv) \ { \ type *ptr = (type *) ((void *) String_val (strv) + Int_val (offv)); \ type r; \ memcpy(&r, ptr, sizeof(r)); \ swap_##endian(size,r); \ memcpy(Data_custom_val(rv), &r, sizeof(r)); \ return rv; \ } #else #define fastpath3 fastpath2 #endif fastpath3(64,be,unsigned,uint64_t,Int64_val) fastpath3(64,le,unsigned,uint64_t,Int64_val) fastpath3(64,ne,unsigned,uint64_t,Int64_val) fastpath3(64,be,signed,int64_t,Int64_val) fastpath3(64,le,signed,int64_t,Int64_val) fastpath3(64,ne,signed,int64_t,Int64_val) ocaml-bitstring-2.0.4/META.in0000664000175000017500000000142512144455550015264 0ustar rjonesrjonesname = "bitstring" version = "@PACKAGE_VERSION@" description = "Bitstrings and bitstring matching" requires = "unix" archive(byte) = "bitstring.cma" archive(native) = "bitstring.cmxa" package "persistent" ( requires = "bitstring" version = "@PACKAGE_VERSION@" description = "Persistent patterns for bitstring (requires camlp4)" archive(byte) = "bitstring_persistent.cma" archive(native) = "bitstring_persistent.cmxa" ) package "syntax" ( version = "@PACKAGE_VERSION@" requires = "camlp4" description = "Syntax extension: bitstring operators" archive(syntax,preprocessor) = "-parser o -parser op -printer p unix.cma bitstring.cma bitstring_persistent.cma pa_bitstring.cmo" archive(syntax,toploop) = "unix.cma bitstring.cma bitstring_persistent.cma pa_bitstring.cmo" ) ocaml-bitstring-2.0.4/bitstring_config.ml.in0000664000175000017500000000233512144455551020501 0ustar rjonesrjones(* Bitstring library. * Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones * * @configure_input@ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version, * with the OCaml linking exception described in COPYING.LIB. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: bitstring_config.ml.in 163 2008-08-27 12:54:57Z richard.wm.jones $ *) (* This file contains general configuration settings, set by the * configure script. *) let nativeendian = Bitstring_types.@NATIVEENDIAN@ let package = "@PACKAGE_NAME@" let version = "@PACKAGE_VERSION@" let ocamllibdir = "@OCAMLLIB@" let diff = "@DIFF@" ocaml-bitstring-2.0.4/bitstring_persistent.ml0000664000175000017500000002210712144455550021025 0ustar rjonesrjones(* Bitstring persistent patterns. * Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version, * with the OCaml linking exception described in COPYING.LIB. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: bitstring_persistent.ml 151 2008-08-26 08:21:43Z richard.wm.jones $ *) open Printf open Camlp4.PreCast open Syntax open Ast type patt = Camlp4.PreCast.Syntax.Ast.patt type expr = Camlp4.PreCast.Syntax.Ast.expr type loc_t = Camlp4.PreCast.Syntax.Ast.Loc.t (* Field. In bitmatch (patterns) the type is [patt field]. In * BITSTRING (constructor) the type is [expr field]. *) type 'a field = { field : 'a; (* field ('a is either patt or expr) *) flen : expr; (* length in bits, may be non-const *) endian : endian_expr; (* endianness *) signed : bool; (* true if signed, false if unsigned *) t : field_type; (* type *) _loc : Loc.t; (* location in source code *) offset : expr option; (* offset expression *) check : expr option; (* check expression [patterns only] *) bind : expr option; (* bind expression [patterns only] *) save_offset_to : patt option; (* save_offset_to [patterns only] *) } and field_type = Int | String | Bitstring (* field type *) and endian_expr = | ConstantEndian of Bitstring.endian (* a constant little/big/nativeendian *) | EndianExpr of expr (* an endian expression *) type pattern = patt field list type constructor = expr field list type named = string * alt and alt = | Pattern of pattern | Constructor of constructor (* Work out if an expression is an integer constant. * * Returns [Some i] if so (where i is the integer value), else [None]. * * Fairly simplistic algorithm: we can only detect simple constant * expressions such as [k], [k+c], [k-c] etc. *) let rec expr_is_constant = function | <:expr< $int:i$ >> -> (* Literal integer constant. *) Some (int_of_string i) | <:expr< $a$ + $b$ >> -> (* Addition of constants. *) (match expr_is_constant a, expr_is_constant b with | Some a, Some b -> Some (a+b) | _ -> None) | <:expr< $a$ - $b$ >> -> (* Subtraction. *) (match expr_is_constant a, expr_is_constant b with | Some a, Some b -> Some (a-b) | _ -> None) | <:expr< $a$ * $b$ >> -> (* Multiplication. *) (match expr_is_constant a, expr_is_constant b with | Some a, Some b -> Some (a*b) | _ -> None) | <:expr< $a$ / $b$ >> -> (* Division. *) (match expr_is_constant a, expr_is_constant b with | Some a, Some b -> Some (a/b) | _ -> None) | <:expr< $a$ lsl $b$ >> -> (* Shift left. *) (match expr_is_constant a, expr_is_constant b with | Some a, Some b -> Some (a lsl b) | _ -> None) | <:expr< $a$ lsr $b$ >> -> (* Shift right. *) (match expr_is_constant a, expr_is_constant b with | Some a, Some b -> Some (a lsr b) | _ -> None) | _ -> None (* Anything else is not constant. *) let string_of_field_type = function | Int -> "int" | String -> "string" | Bitstring -> "bitstring" let patt_printer = function | <:patt< $lid:id$ >> -> id | <:patt< _ >> -> "_" | _ -> "[pattern]" let rec expr_printer = function | <:expr< $lid:id$ >> -> id | <:expr< $int:i$ >> -> i | <:expr< $lid:op$ $a$ $b$ >> -> sprintf "%s %s %s" op (expr_printer a) (expr_printer b) | _ -> "[expr]" let _string_of_field { flen = flen; endian = endian; signed = signed; t = t; _loc = _loc; offset = offset; check = check; bind = bind; save_offset_to = save_offset_to } = let flen = expr_printer flen in let endian = match endian with | ConstantEndian endian -> Bitstring.string_of_endian endian | EndianExpr expr -> sprintf "endian(%s)" (expr_printer expr) in let signed = if signed then "signed" else "unsigned" in let t = string_of_field_type t in let offset = match offset with | None -> "" | Some expr -> sprintf ", offset(%s)" (expr_printer expr) in let check = match check with | None -> "" | Some expr -> sprintf ", check(%s)" (expr_printer expr) in let bind = match bind with | None -> "" | Some expr -> sprintf ", bind(%s)" (expr_printer expr) in let save_offset_to = match save_offset_to with | None -> "" | Some patt -> match patt with | <:patt< $lid:id$ >> -> sprintf ", save_offset_to(%s)" id | _ -> sprintf ", save_offset_to([patt])" in let loc_fname = Loc.file_name _loc in let loc_line = Loc.start_line _loc in let loc_char = Loc.start_off _loc - Loc.start_bol _loc in sprintf "%s : %s, %s, %s%s%s%s%s (* %S:%d %d *)" flen t endian signed offset check bind save_offset_to loc_fname loc_line loc_char let rec string_of_pattern_field ({ field = patt } as field) = sprintf "%s : %s" (patt_printer patt) (_string_of_field field) and string_of_constructor_field ({ field = expr } as field) = sprintf "%s : %s" (expr_printer expr) (_string_of_field field) let string_of_pattern pattern = "{ " ^ String.concat ";\n " (List.map string_of_pattern_field pattern) ^ " }\n" let string_of_constructor constructor = "{ " ^ String.concat ";\n " (List.map string_of_constructor_field constructor) ^ " }\n" let named_to_channel chan n = Marshal.to_channel chan n [] let named_to_string n = Marshal.to_string n [] let named_to_buffer str ofs len n = Marshal.to_buffer str ofs len n [] let named_from_channel = Marshal.from_channel let named_from_string = Marshal.from_string let create_pattern_field _loc = { field = <:patt< _ >>; flen = <:expr< 32 >>; endian = ConstantEndian Bitstring.BigEndian; signed = false; t = Int; _loc = _loc; offset = None; check = None; bind = None; save_offset_to = None; } let set_lident_patt field id = let _loc = field._loc in { field with field = <:patt< $lid:id$ >> } let set_int_patt field i = let _loc = field._loc in { field with field = <:patt< $`int:i$ >> } let set_string_patt field str = let _loc = field._loc in { field with field = <:patt< $str:str$ >> } let set_unbound_patt field = let _loc = field._loc in { field with field = <:patt< _ >> } let set_patt field patt = { field with field = patt } let set_length_int field flen = let _loc = field._loc in { field with flen = <:expr< $`int:flen$ >> } let set_length field flen = { field with flen = flen } let set_endian field endian = { field with endian = ConstantEndian endian } let set_endian_expr field expr = { field with endian = EndianExpr expr } let set_signed field signed = { field with signed = signed } let set_type_int field = { field with t = Int } let set_type_string field = { field with t = String } let set_type_bitstring field = { field with t = Bitstring } let set_location field loc = { field with _loc = loc } let set_offset_int field i = let _loc = field._loc in { field with offset = Some <:expr< $`int:i$ >> } let set_offset field expr = { field with offset = Some expr } let set_no_offset field = { field with offset = None } let set_check field expr = { field with check = Some expr } let set_no_check field = { field with check = None } let set_bind field expr = { field with bind = Some expr } let set_no_bind field = { field with bind = None } let set_save_offset_to field patt = { field with save_offset_to = Some patt } let set_save_offset_to_lident field id = let _loc = field._loc in { field with save_offset_to = Some <:patt< $lid:id$ >> } let set_no_save_offset_to field = { field with save_offset_to = None } let create_constructor_field _loc = { field = <:expr< 0 >>; flen = <:expr< 32 >>; endian = ConstantEndian Bitstring.BigEndian; signed = false; t = Int; _loc = _loc; offset = None; check = None; bind = None; save_offset_to = None; } let set_lident_expr field id = let _loc = field._loc in { field with field = <:expr< $lid:id$ >> } let set_int_expr field i = let _loc = field._loc in { field with field = <:expr< $`int:i$ >> } let set_string_expr field str = let _loc = field._loc in { field with field = <:expr< $str:str$ >> } let set_expr field expr = let _loc = field._loc in { field with field = expr } let get_patt field = field.field let get_expr field = field.field let get_length field = field.flen let get_endian field = field.endian let get_signed field = field.signed let get_type field = field.t let get_location field = field._loc let get_offset field = field.offset let get_check field = field.check let get_bind field = field.bind let get_save_offset_to field = field.save_offset_to