Changeset eb14d2d in git


Ignore:
Timestamp:
20/09/11 14:09:43 (8 years ago)
Author:
Olly Betts <olly@…>
Branches:
svn/1.0, svn/tags/1.0.40
Children:
ae275ef
Parents:
a39e539
Message:

Backport changes from 1.2.0:
configure.in,src/img.c,src/useful.c,src/useful.h: Use AC_TYPE_INT16_T
and AC_TYPE_INT32_T instead of home-brew equivalents.
configure.in,src/useful.h: On little-endian architectures, make
get16() and get32() inline functions, rather than macros which use
a global variable.
src/useful.c: Remove commented out code.

git-svn-id: file:///home/survex-svn/survex/branches/1.0@3718 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    ra39e539 reb14d2d  
     1Tue Sep 20 13:08:15 GMT 2011  Olly Betts <olly@survex.com>
     2
     3        * Backport changes from 1.2.0:
     4        * configure.in,src/img.c,src/useful.c,src/useful.h: Use AC_TYPE_INT16_T
     5          and AC_TYPE_INT32_T instead of home-brew equivalents.
     6        * configure.in,src/useful.h: On little-endian architectures, make
     7          get16() and get32() inline functions, rather than macros which use
     8          a global variable.
     9        * src/useful.c: Remove commented out code.
     10
    111Tue Sep 20 12:58:30 GMT 2011  Olly Betts <olly@survex.com>
    212
  • configure.in

    ra39e539 reb14d2d  
    254254], , AC_DEFINE(CLOCKS_PER_SEC, 1000000, [For old systems which don't define it themselves]))
    255255
    256 dnl Look for a signed 32 bit integer type
    257 AC_MSG_CHECKING(for 32 bit integer type)
    258 AC_TRY_COMPILE(,[switch (0) { case (sizeof(int)==4): case 0: break; }],
    259 INT32_T=int,
    260 AC_TRY_COMPILE(,[switch (0) { case (sizeof(long)==4): case 0: break; }],
    261 INT32_T=long,
    262 AC_MSG_ERROR(not found)
    263 )
    264 )
    265 AC_MSG_RESULT($INT32_T)
    266 AC_DEFINE_UNQUOTED(INT32_T,$INT32_T,[signed 32 bit integer type])
    267 
    268 dnl Look for a signed 16 bit integer type
    269 AC_MSG_CHECKING(for 16 bit integer type)
    270 AC_TRY_COMPILE(,[switch (0) { case (sizeof(short)==2): case 0: break; }],
    271 INT16_T=short,
    272 AC_TRY_COMPILE(,[switch (0) { case (sizeof(int)==2): case 0: break; }],
    273 INT16_T=int,
    274 AC_MSG_ERROR(not found)
    275 )
    276 )
    277 AC_MSG_RESULT($INT16_T)
    278 AC_DEFINE_UNQUOTED(INT16_T,$INT16_T,[signed 16 bit integer type])
     256dnl Check for 16-bit and 32-bit integer types.
     257AC_TYPE_INT16_T
     258AC_TYPE_INT32_T
    279259
    280260dnl Checks for library functions.
  • src/cavern.h

    ra39e539 reb14d2d  
    264264#endif
    265265#ifdef CHASM3DX
    266    INT32_T id;
     266   int32_t id;
    267267#endif
    268268} pos;
  • src/cvrotimg.h

    ra39e539 reb14d2d  
    2424
    2525/* data type used after data is read in */
    26 typedef INT32_T coord;
     26typedef int32_t coord;
    2727
    2828/* Data structures */
  • src/new3dout.c

    ra39e539 reb14d2d  
    5353   if (len == 0 || len > 255) {
    5454      if (PUTC(0, fh) == EOF) return EOF;
    55       put32((INT32_T)len, fh);
     55      put32((int32_t)len, fh);
    5656      if (ferror(fh)) return EOF;
    5757   } else {
     
    106106      const char *tag;
    107107      unsigned int len;
    108       pid->id = (INT32_T)statcount;
     108      pid->id = (int32_t)statcount;
    109109      tag = pre->ident;
    110110      len = cslen(tag) + 12 + 4;
     
    113113      if (len == 0 || len > 255) {
    114114         if (PUTC(0, p_img->fh) == EOF) return EOF;
    115          put32((INT32_T)len, p_img->fh);
     115         put32((int32_t)len, p_img->fh);
    116116         if (ferror(p_img->fh)) return EOF;
    117117      } else {
    118118         if (PUTC((unsigned char)len, p_img->fh) == EOF) return EOF;
    119119      }
    120       put32((INT32_T)statcount, p_img->fh); /* station ID */
    121       put32((INT32_T)(pid->p[0] * 100.0), p_img->fh); /* X in cm */
    122       put32((INT32_T)(pid->p[1] * 100.0), p_img->fh); /* Y */
    123       put32((INT32_T)(pid->p[2] * 100.0), p_img->fh); /* Z */
     120      put32((int32_t)statcount, p_img->fh); /* station ID */
     121      put32((int32_t)(pid->p[0] * 100.0), p_img->fh); /* X in cm */
     122      put32((int32_t)(pid->p[1] * 100.0), p_img->fh); /* Y */
     123      put32((int32_t)(pid->p[2] * 100.0), p_img->fh); /* Z */
    124124      fputcs(tag, p_img->fh);
    125125      statcount++;
     
    128128      PUTC(STATLINK_3D, p_img->fh);
    129129      PUTC(0x04, p_img->fh);
    130       put32((INT32_T)pid->id, p_img->fh);
     130      put32((int32_t)pid->id, p_img->fh);
    131131   }
    132132   return 0;
     
    227227        }
    228228        PUTC(LEG_3D, p_img->fh);
    229         put16((INT16_T)0x02, p_img->fh);
     229        put16((int16_t)0x02, p_img->fh);
    230230        PUTC(0x04, p_img->fh);
    231         put32((INT32_T)err, p_img->fh); /* output error in %*100 */
     231        put32((int32_t)err, p_img->fh); /* output error in %*100 */
    232232        cave_write_pos(p_img, twiglet->from->pos, twiglet->from);
    233233        cave_write_pos(p_img, twiglet->to->pos, twiglet->to);
     
    324324      /* and finally write how many stations there are */
    325325      fseek(p_img->fh, 7L, SEEK_SET);
    326       put32((INT32_T)statcount, p_img->fh);
     326      put32((int32_t)statcount, p_img->fh);
    327327      if (ferror(p_img->fh)) result = 0;
    328328      if (fclose(p_img->fh) == EOF) result = 0;
  • src/useful.c

    ra39e539 reb14d2d  
    11/* useful.c
    2  * Copyright (C) 1993-2001,2003 Olly Betts
     2 * Copyright (C) 1993-2001,2003,2010 Olly Betts
    33 *
    44 * This program is free software; you can redistribute it and/or modify
     
    2424#include "osdepend.h"
    2525
    26 #ifndef WORDS_BIGENDIAN
    27 
    28 /* used by macro versions of useful_get<nn> functions */
    29 INT16_T useful_w16;
    30 INT32_T useful_w32;
    31 
    32 #if 0 /* these functions aren't needed - macros do the job */
    33 /* the numbers in the file are little endian, so use fread/fwrite */
    34 extern void Far
    35 useful_put16(INT16_T w, FILE *fh)
    36 {
    37    fwrite(&w, 2, 1, fh);
    38 }
    39 
    40 #undef useful_put32
    41 extern void Far
    42 useful_put32(INT32_T w, FILE *fh)
    43 {
    44    fwrite(&w, 4, 1, fh);
    45 }
    46 
    47 #undef useful_get16
    48 extern INT16_T Far
    49 useful_get16(FILE *fh)
    50 {
    51    INT16_T w;
    52    fread(&w, 2, 1, fh);
    53    return w;
    54 }
    55 
    56 #undef useful_put32
    57 extern INT32_T Far
    58 useful_get32(FILE *fh)
    59 {
    60    INT32_T w;
    61    fread(&w, 4, 1, fh);
    62    return w;
    63 }
    64 #endif
    65 
    66 #else
     26#ifdef WORDS_BIGENDIAN
    6727
    6828extern void Far
    69 useful_put16(INT16_T w, FILE *fh)
     29useful_put16(int16_t w, FILE *fh)
    7030{
    7131   PUTC((char)(w), fh);
     
    7434
    7535extern void Far
    76 useful_put32(INT32_T w, FILE *fh)
     36useful_put32(int32_t w, FILE *fh)
    7737{
    7838   PUTC((char)(w), fh);
     
    8242}
    8343
    84 extern INT16_T Far
     44extern int16_t Far
    8545useful_get16(FILE *fh)
    8646{
    87    INT16_T w;
     47   int16_t w;
    8848   w = GETC(fh);
    89    w |= (INT16_T)(GETC(fh) << 8l);
     49   w |= (int16_t)(GETC(fh) << 8l);
    9050   return w;
    9151}
    9252
    93 extern INT32_T Far
     53extern int32_t Far
    9454useful_get32(FILE *fh)
    9555{
    96    INT32_T w;
     56   int32_t w;
    9757   w = GETC(fh);
    98    w |= (INT32_T)(GETC(fh) << 8l);
    99    w |= (INT32_T)(GETC(fh) << 16l);
    100    w |= (INT32_T)(GETC(fh) << 24l);
     58   w |= (int32_t)(GETC(fh) << 8l);
     59   w |= (int32_t)(GETC(fh) << 16l);
     60   w |= (int32_t)(GETC(fh) << 24l);
    10161   return w;
    10262}
  • src/useful.h

    ra39e539 reb14d2d  
    2323
    2424#include <config.h>
     25
     26#if HAVE_STDINT_H
     27# include <stdint.h>
     28#endif
    2529
    2630#include <stdlib.h> /* for Borland C which #defines max() & min() there */
     
    114118
    115119#ifndef WORDS_BIGENDIAN
    116 extern INT16_T useful_w16;
    117 extern INT32_T useful_w32;
     120# define put16(W, FH) BLK(int16_t w = (W); fwrite(&w, 2, 1, (FH));)
     121# define put32(W, FH) BLK(int32_t w = (W); fwrite(&w, 4, 1, (FH));)
    118122
    119 # define put16(W, FH) BLK(INT16_T w = (W); fwrite(&w, 2, 1, (FH));)
    120 # define put32(W, FH) BLK(INT32_T w = (W); fwrite(&w, 4, 1, (FH));)
    121 # define get16(FH) (fread(&useful_w16, 2, 1, (FH)), useful_w16)
    122 # define get32(FH) (fread(&useful_w32, 4, 1, (FH)), useful_w32)
     123static inline int16_t get16(FILE *fh) {
     124    int16_t w;
     125    fread(&w, 2, 1, fh);
     126    return w;
     127}
     128
     129static inline int32_t get32(FILE *fh) {
     130    int32_t w;
     131    fread(&w, 4, 1, fh);
     132    return w;
     133}
    123134#else
    124135/* FIXME: why are these "Far"? */
    125 void Far useful_put16(INT16_T, FILE *);
    126 void Far useful_put32(INT32_T, FILE *);
    127 INT16_T Far useful_get16(FILE *);
    128 INT32_T Far useful_get32(FILE *);
     136void Far useful_put16(int16_t, FILE *);
     137void Far useful_put32(int32_t, FILE *);
     138int16_t Far useful_get16(FILE *);
     139int32_t Far useful_get32(FILE *);
    129140
    130141# define put16(W, FH) useful_put16(W, FH)
Note: See TracChangeset for help on using the changeset viewer.