Refined selection of remainder functions
[shapes.git] / m4 / iconv_internal.m4
blobaadab375225ea66fd88fc17ebf29b41d1b1c32f0
1 AC_DEFUN([AM_ICONV_INTERNAL],
3         AC_MSG_CHECKING(for iconv name for Unicode in uint32_t)
5   AC_TRY_RUN([
6 #include <stdint.h>
8 void helper_BE( uint32_t * a, unsigned char ** b, unsigned char x );
10 void
11 helper_BE( uint32_t * a, unsigned char ** b, unsigned char x )
13   *a *= 0x100;
14         *a += x;
15         **b = x;
16         ++(*b);
19 int
20 main( )
22   uint32_t a = 0;
23   uint32_t b = 0;
24   unsigned char * dst = ( unsigned char * )( & b );
26         /* The following sequence will result in the same value in a and b
27          * if the machine is big endian.  (Four values are picked, rather than
28          * trying every possible value!  This is why the test is not "if and only if".)
29          * It is only after all four steps have been completed that the two
30          * would be the same, since b is written left to right, while a is
31          * shifted before each new value.
32          */
33         helper_BE( & a, & dst, 0x01 );
34         helper_BE( & a, & dst, 0x80 );
35         helper_BE( & a, & dst, 0x04 );
36         helper_BE( & a, & dst, 0x20 );
38         return ( a == b ) ? 0 : 1;
40     ],
41     [
42                   UCS_4_INTERNAL=[\"UCS-4BE\"]
43     ],[
44   AC_TRY_RUN([
45 #include <stdint.h>
47 void helper_LE( uint32_t * a, unsigned char ** b, unsigned char x );
49 void
50 helper_LE( uint32_t * a, unsigned char ** b, unsigned char x )
52   *a *= 0x100;
53         *a += x;
54         --(*b);
55         **b = x;
58 int
59 main( )
61   uint32_t a = 0;
62   uint32_t b = 0;
63   unsigned char * dst = ( unsigned char * )( & b ) + sizeof( b );
65         /* The following sequence will result in the same value in a and b
66          * if the machine is big endian.  (Four values are picked, rather than
67          * trying every possible value!  This is why the test is not "if and only if".)
68          * It is only after all four steps have been completed that the two
69          * would be the same, since b is written left to right, while a is
70          * shifted before each new value.
71          */
72         helper_LE( & a, & dst, 0x01 );
73         helper_LE( & a, & dst, 0x80 );
74         helper_LE( & a, & dst, 0x04 );
75         helper_LE( & a, & dst, 0x20 );
77         return ( a == b ) ? 0 : 1;
79     ],
80     [
81                   UCS_4_INTERNAL=[\"UCS-4LE\"]
82     ],[
83                   AC_MSG_WARN([Neither big nor little endian - hopefully, UCS-4-INTERNAL is supported anyway.])
84                   UCS_4_INTERNAL=[\"UCS-4-INTERNAL\"]
85                 ],)
86                 ],)
87         AC_MSG_RESULT($UCS_4_INTERNAL)
88   AC_DEFINE_UNQUOTED(UCS_4_INTERNAL, $UCS_4_INTERNAL, [Name to use with iconv to refer to Unicode in uint32_t.])