Remove put_string and get_string: not used anymore.
[neverball] / share / binary.c
1 /*
2  * Copyright (C) 2003 Robert Kooima
3  *
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.
8  *
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.
13  */
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18
19 #include <SDL.h>
20 #include <SDL_byteorder.h>
21
22 /*---------------------------------------------------------------------------*/
23
24 void put_float(FILE *fout, const float *f)
25 {
26     unsigned char *p = (unsigned char *) f;
27
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);
33 #else
34     fputc((int) p[0], fout);
35     fputc((int) p[1], fout);
36     fputc((int) p[2], fout);
37     fputc((int) p[3], fout);
38 #endif
39 }
40
41 void put_index(FILE *fout, const int *i)
42 {
43     unsigned char *p = (unsigned char *) i;
44
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);
50 #else
51     fputc((int) p[0], fout);
52     fputc((int) p[1], fout);
53     fputc((int) p[2], fout);
54     fputc((int) p[3], fout);
55 #endif
56 }
57
58 void put_array(FILE *fout, const float *v, size_t n)
59 {
60     size_t i;
61
62     for (i = 0; i < n; i++)
63         put_float(fout, v + i);
64 }
65
66 /*---------------------------------------------------------------------------*/
67
68 void get_float(FILE *fin, float *f)
69 {
70     unsigned char *p = (unsigned char *) f;
71
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);
77 #else
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);
82 #endif
83 }
84
85 void get_index(FILE *fin, int *i)
86 {
87     unsigned char *p = (unsigned char *) i;
88
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);
94 #else
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);
99 #endif
100 }
101
102 void get_array(FILE *fin, float *v, size_t n)
103 {
104     size_t i;
105
106     for (i = 0; i < n; i++)
107         get_float(fin, v + i);
108 }
109
110 /*---------------------------------------------------------------------------*/