~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to lib/vector/diglib/port_test.c

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 *
17
17
 *****************************************************************************/
18
18
#include <stdio.h>
19
 
#include <grass/Vect.h>
 
19
#include <sys/types.h>
 
20
#include <grass/vector.h>
20
21
 
21
22
/*
22
23
 **  Written by Dave Gerdes  9/1988
56
57
 */
57
58
 
58
59
#define TEST_PATTERN 1.3333
 
60
#ifdef HAVE_LONG_LONG_INT
 
61
#define OFF_T_TEST 0x0102030405060708LL
 
62
#else
 
63
#define OFF_T_TEST 0x01020304
 
64
#endif
59
65
#define LONG_TEST 0x01020304
60
66
#define INT_TEST 0x01020304
61
67
#define SHORT_TEST 0x0102
64
70
{
65
71
    double d;
66
72
    float f;
 
73
    off_t o;
67
74
    long l;
68
75
    int i;
69
76
    short s;
76
83
    { 0x3f, 0xf5, 0x55, 0x32, 0x61, 0x7c, 0x1b, 0xda };
77
84
/* flt_cmpr holds the bytes of an IEEE representation of  TEST_PATTERN */
78
85
static unsigned char flt_cmpr[] = { 0x3f, 0xaa, 0xa9, 0x93 };
 
86
static unsigned char off_t_cmpr[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
79
87
static unsigned char lng_cmpr[] = { 0x01, 0x02, 0x03, 0x04 };
80
88
static unsigned char int_cmpr[] = { 0x01, 0x02, 0x03, 0x04 };
81
89
static unsigned char shrt_cmpr[] = { 0x01, 0x02 };
82
90
 
83
91
static char dbl_cnvrt[sizeof(double)];
84
92
static char flt_cnvrt[sizeof(float)];
 
93
static char off_t_cnvrt[sizeof(off_t)];
85
94
static char lng_cnvrt[sizeof(long)];
86
95
static char int_cnvrt[sizeof(int)];
87
96
static char shrt_cnvrt[sizeof(short)];
88
97
 
89
 
static int nat_dbl, nat_flt, nat_lng, nat_int, nat_shrt, nat_char;
 
98
static int nat_dbl, nat_flt, nat_lng, nat_off_t, nat_int, nat_shrt, nat_char;
90
99
 
91
100
 
92
101
/* function prototypes */
105
114
    printf("\n/* Native machine sizes */\n");
106
115
    printf("#define NATIVE_DOUBLE %d\n", (nat_dbl = sizeof(double)));
107
116
    printf("#define NATIVE_FLOAT  %d\n", (nat_flt = sizeof(float)));
 
117
    printf("#define NATIVE_OFF_T  %d\n", (nat_off_t = sizeof(off_t)));
108
118
    printf("#define NATIVE_LONG   %d\n", (nat_lng = sizeof(long)));
109
119
    printf("#define NATIVE_INT    %d\n", (nat_int = sizeof(int)));
110
120
    printf("#define NATIVE_SHORT  %d\n", (nat_shrt = sizeof(short)));
117
127
        err = 1;
118
128
    }
119
129
    if (nat_flt != PORT_FLOAT) {
120
 
        fprintf(stderr, "ERROR, sizeof (float) != %d\n", PORT_DOUBLE);
 
130
        fprintf(stderr, "ERROR, sizeof (float) != %d\n", PORT_FLOAT);
121
131
        err = 1;
122
132
    }
 
133
    /* port_off_t is variable */
123
134
    if (nat_lng < PORT_LONG) {
124
135
        fprintf(stderr, "ERROR, sizeof (long) < %d\n", PORT_LONG);
125
136
        err = 1;
192
203
    else
193
204
        flt_order = ENDIAN_OTHER;
194
205
 
 
206
    /* Find off_t order */
 
207
    if (nat_off_t == 8)
 
208
        u.o = OFF_T_TEST;
 
209
    else
 
210
        u.o = LONG_TEST;
 
211
    for (i = 0; i < nat_off_t; i++) {
 
212
        tmp = find_offset(u.c, off_t_cmpr[i], nat_off_t);
 
213
        if (-1 == tmp) {
 
214
            fprintf(stderr, "ERROR, could not find '%x' in off_t\n",
 
215
                    off_t_cmpr[i]);
 
216
            err = 1;
 
217
        }
 
218
        off_t_cnvrt[i] = tmp;
 
219
    }
 
220
    tmp = tmp2 = 1;
 
221
    for (i = 0; i < nat_off_t; i++) {
 
222
        if (off_t_cnvrt[i] != (i + (nat_off_t - nat_off_t)))
 
223
            tmp = 0;
 
224
        if (off_t_cnvrt[i] != (nat_off_t - i - 1))
 
225
            tmp2 = 0;
 
226
    }
 
227
    if (tmp)
 
228
        off_t_order = ENDIAN_BIG;
 
229
    else if (tmp2)
 
230
        off_t_order = ENDIAN_LITTLE;
 
231
    else
 
232
        off_t_order = ENDIAN_OTHER;
 
233
 
195
234
    /* Find long order */
196
235
    u.l = LONG_TEST;
197
236
    for (i = 0; i < PORT_LONG; i++) {
270
309
    printf("\n/* Native machine byte orders */\n");
271
310
    printf("#define DOUBLE_ORDER %d\n", dbl_order);
272
311
    printf("#define FLOAT_ORDER  %d\n", flt_order);
 
312
    printf("#define OFF_T_ORDER  %d\n", off_t_order);
273
313
    printf("#define LONG_ORDER   %d\n", lng_order);
274
314
    printf("#define INT_ORDER    %d\n", int_order);
275
315
    printf("#define SHORT_ORDER  %d\n", shrt_order);
320
360
    }
321
361
    fprintf(stdout, "};\n\n");
322
362
 
 
363
    fprintf(stdout, "/* off_t format  : */\nstatic int off_t_cnvrt[] = {");
 
364
    i = 0;
 
365
    while (i < nat_off_t) {
 
366
        fprintf(stdout, "%d", off_t_cnvrt[i]);
 
367
        if (++i < nat_off_t)
 
368
            fprintf(stdout, ", ");
 
369
    }
 
370
    fprintf(stdout, "};\n\n");
 
371
 
323
372
    fprintf(stdout, "/* Long format  : */\nstatic int lng_cnvrt[] = {");
324
373
    i = 0;
325
374
    while (i < nat_lng) {