--- xplanet-1.3.0.orig/src/libimage/gif.c	2006-03-25 14:50:51.000000000 -0800
+++ xplanet-1.3.0/src/libimage/gif.c	2015-01-30 21:01:52.000000000 -0800
@@ -28,6 +28,18 @@
   distribution. 
 */
 
+#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
+void
+PrintGifError(int ErrorCode) {
+    const char *Err = GifErrorString(ErrorCode);
+    if (Err != NULL)
+        fprintf(stderr, "GIF-LIB error: %s.\n", Err);
+    else
+        fprintf(stderr, "GIF-LIB undefined error %d.\n", ErrorCode);
+}
+#endif
+
+
 int
 read_gif(const char *filename, int *width, int *height, unsigned char **rgb)
 {
@@ -41,12 +53,23 @@
     int i, j;
     int color_index;
     unsigned char *ptr = NULL;
-
+#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
+    int err;
+#endif
+
+#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
+    infile = DGifOpenFileName(filename, NULL);
+#else
     infile = DGifOpenFileName(filename);
+#endif
 
     if (infile == NULL)
     {
+#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
+        PrintGifError(infile->Error);
+#else
         PrintGifError();
+#endif
         return(0);
     }
 
@@ -54,7 +77,11 @@
     {
         if (DGifGetRecordType(infile, &record_type) == GIF_ERROR) 
         {
+#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
+            PrintGifError(infile->Error);
+#else
             PrintGifError();
+#endif
             return(0);
         }
 
@@ -63,7 +90,11 @@
         case IMAGE_DESC_RECORD_TYPE:
             if (DGifGetImageDesc(infile) == GIF_ERROR)
             {
+#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
+                PrintGifError(infile->Error);
+#else
                 PrintGifError();
+#endif
                 return(0);
             }
 
@@ -107,14 +138,22 @@
             GifByteType *ext;
             if (DGifGetExtension(infile, &ext_code, &ext) == GIF_ERROR) 
             {
+#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
+                PrintGifError(infile->Error);
+#else
                 PrintGifError();
+#endif
                 return(0);
             }
             while (ext != NULL) 
             {
                 if (DGifGetExtensionNext(infile, &ext) == GIF_ERROR) 
                 {
+#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
+                    PrintGifError(infile->Error);
+#else
                     PrintGifError();
+#endif
                     return(0);
                 }
             }
@@ -154,7 +193,11 @@
     
     free(buffer);
 
+#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5 && GIFLIB_MINOR >= 1
+    DGifCloseFile(infile, NULL);
+#else
     DGifCloseFile(infile);
+#endif
     return(1);
 }
 
@@ -166,6 +209,9 @@
     GifByteType *red, *green, *blue, *buffer, *ptr;
     GifFileType *outfile;
     ColorMapObject *colormap;
+#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
+    int err;
+#endif
 
     red = malloc(width * height * sizeof(GifByteType));
     green = malloc(width * height * sizeof(GifByteType));
@@ -178,7 +224,11 @@
         return(0);
     }
 
+#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
+    colormap = GifMakeMapObject(colormap_size, NULL);
+#else
     colormap = MakeMapObject(colormap_size, NULL);
+#endif
 
     for (i = 0; i < width * height; i++)
     {
@@ -187,10 +237,17 @@
         blue[i]  = (GifByteType) rgb[3*i+2];
     }
   
+#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
+    if (GifQuantizeBuffer(width, height, &colormap_size, red, green, blue,   
+                          buffer, colormap->Colors) == GIF_ERROR)
+    {
+        PrintGifError(-1);
+#else
     if (QuantizeBuffer(width, height, &colormap_size, red, green, blue,   
                        buffer, colormap->Colors) == GIF_ERROR)
     {
         PrintGifError();
+#endif
         return(0);
     }
 
@@ -198,24 +255,41 @@
     free(green);
     free(blue);
 
+#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
+    outfile = EGifOpenFileName((char *) filename, 0, &err);
+    if (outfile == NULL)
+    {
+        PrintGifError(err);
+        return(0);
+    }
+#else
     outfile = EGifOpenFileName((char *) filename, FALSE);
     if (outfile == NULL)
     {
         PrintGifError();
         return(0);
     }
+#endif
 
     if (EGifPutScreenDesc(outfile, width, height, colormap_size, 0, colormap)
         == GIF_ERROR)
     {
+#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
+        PrintGifError(outfile->Error);
+#else
         PrintGifError();
+#endif
         return(0);
     }
 
-    if (EGifPutImageDesc(outfile, 0, 0, width, height, FALSE, NULL)
+    if (EGifPutImageDesc(outfile, 0, 0, width, height, 0, NULL)
         == GIF_ERROR)
     {
+#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
+        PrintGifError(outfile->Error);
+#else
         PrintGifError();
+#endif
         return(0);
     }
 
@@ -224,7 +298,11 @@
     {
         if (EGifPutLine(outfile, ptr, width) == GIF_ERROR)
         {
+#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
+            PrintGifError(outfile->Error);
+#else
             PrintGifError();
+#endif
             return(0);
         }
         ptr += width;
@@ -232,8 +310,13 @@
 
     EGifSpew(outfile);
 
+#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5 && GIFLIB_MINOR >= 1
+    if (EGifCloseFile(outfile, &err) == GIF_ERROR) 
+        PrintGifError(err);
+#else
     if (EGifCloseFile(outfile) == GIF_ERROR) 
         PrintGifError();
+#endif
 
     free(buffer);
 
