2 * Copyright (C) 2003 Robert Kooima
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
20 #include <SDL_byteorder.h>
22 /*---------------------------------------------------------------------------*/
24 void put_float(FILE *fout, const float *f)
26 const unsigned char *p = (const unsigned char *) f;
28 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
29 fputc((int) p[3], fout);
30 fputc((int) p[2], fout);
31 fputc((int) p[1], fout);
32 fputc((int) p[0], fout);
34 fputc((int) p[0], fout);
35 fputc((int) p[1], fout);
36 fputc((int) p[2], fout);
37 fputc((int) p[3], fout);
41 void put_index(FILE *fout, const int *i)
43 const unsigned char *p = (const unsigned char *) i;
45 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
46 fputc((int) p[3], fout);
47 fputc((int) p[2], fout);
48 fputc((int) p[1], fout);
49 fputc((int) p[0], fout);
51 fputc((int) p[0], fout);
52 fputc((int) p[1], fout);
53 fputc((int) p[2], fout);
54 fputc((int) p[3], fout);
58 void put_array(FILE *fout, const float *v, size_t n)
62 for (i = 0; i < n; i++)
63 put_float(fout, v + i);
66 /*---------------------------------------------------------------------------*/
68 void get_float(FILE *fin, float *f)
70 unsigned char *p = (unsigned char *) f;
72 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
73 p[3] = (unsigned char) fgetc(fin);
74 p[2] = (unsigned char) fgetc(fin);
75 p[1] = (unsigned char) fgetc(fin);
76 p[0] = (unsigned char) fgetc(fin);
78 p[0] = (unsigned char) fgetc(fin);
79 p[1] = (unsigned char) fgetc(fin);
80 p[2] = (unsigned char) fgetc(fin);
81 p[3] = (unsigned char) fgetc(fin);
85 void get_index(FILE *fin, int *i)
87 unsigned char *p = (unsigned char *) i;
89 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
90 p[3] = (unsigned char) fgetc(fin);
91 p[2] = (unsigned char) fgetc(fin);
92 p[1] = (unsigned char) fgetc(fin);
93 p[0] = (unsigned char) fgetc(fin);
95 p[0] = (unsigned char) fgetc(fin);
96 p[1] = (unsigned char) fgetc(fin);
97 p[2] = (unsigned char) fgetc(fin);
98 p[3] = (unsigned char) fgetc(fin);
102 void get_array(FILE *fin, float *v, size_t n)
106 for (i = 0; i < n; i++)
107 get_float(fin, v + i);
110 /*---------------------------------------------------------------------------*/
112 void put_string(FILE *fout, const char *s)
118 void get_string(FILE *fin, char *s, int max)
121 *s = (char) fgetc(fin);
122 while (*s++ != '\0' && max-- > 0);
128 /*---------------------------------------------------------------------------*/