KK-branch, Updated message in intro, merged current trunk (3120) with branch
[neverball] / share / binary.c
index 3ba6c3e..9cb383f 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
-#include <SDL.h>
-#include <SDL_byteorder.h>
+#include <SDL_endian.h>
 
 /*---------------------------------------------------------------------------*/
 
 void put_float(FILE *fout, const float *f)
 {
-    unsigned char *p = (unsigned char *) f;
+    const unsigned char *p = (const unsigned char *) f;
 
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
     fputc((int) p[3], fout);
@@ -40,7 +39,7 @@ void put_float(FILE *fout, const float *f)
 
 void put_index(FILE *fout, const int *i)
 {
-    unsigned char *p = (unsigned char *) i;
+    const unsigned char *p = (const unsigned char *) i;
 
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
     fputc((int) p[3], fout);
@@ -108,3 +107,21 @@ void get_array(FILE *fin, float *v, size_t n)
 }
 
 /*---------------------------------------------------------------------------*/
+
+void put_string(FILE *fout, const char *s)
+{
+    fputs(s, fout);
+    fputc('\0', fout);
+}
+
+void get_string(FILE *fin, char *s, int max)
+{
+    do
+        *s = (char) fgetc(fin);
+    while (*s++ != '\0' && max-- > 0);
+
+    if(*(s - 1) != '\0')
+        *(s - 1) = '\0';
+}
+
+/*---------------------------------------------------------------------------*/