--- a/demosrc/main.c	2011-03-13 11:01:07.000000000 +0000
+++ b/demosrc/main.c	2016-07-04 15:28:58.422923000 +0000
@@ -1,4 +1,4 @@
-/* 
+/*
  * main.c - This file contains the main program and driver for the raytracer.
  *
  *  $Id: main.c,v 1.76 2010/01/18 19:36:34 johns Exp $
@@ -31,7 +31,7 @@
   float x;
   float y;
   float z;
-} floatvec; 
+} floatvec;
 
 
 typedef struct {
@@ -88,7 +88,7 @@
         printf("Couldn't allocate image buffer for framebuffer display!!\n");
         free(dh);
         return NULL;
-      } 
+      }
 #endif
   }
 
@@ -119,9 +119,9 @@
 }
 
 
-/* 
+/*
  * main loop for creating animations by flying using a spaceball
- * or other 3-D input mechanism. 
+ * or other 3-D input mechanism.
  */
 static int fly_scene(argoptions opt, SceneHandle scene, int node) {
   dispHandle * dh = NULL;
@@ -178,7 +178,7 @@
     if (node == 0) {
       printf("\rRendering Frame: %9d   %10.4f FPS       ", frameno, fps);
       fflush(stdout);
-    } 
+    }
 
 #if defined(USESPACEBALL)
     if (bh != NULL)
@@ -188,18 +188,18 @@
     rt_renderscene(scene);
 
     if (dh != NULL)
-      tachyon_display_draw(dh); 
+      tachyon_display_draw(dh);
 
     frameno++;
-  } 
+  }
 
   rt_timer_stop(animationtimer);
   fps = frameno / rt_timer_time(animationtimer);
 
   if (node == 0) {
     printf("\rCompleted animation of %d frames                            \n", frameno);
-    printf("Animation Time: %10.4f seconds  (Averaged %7.4f FPS)\n", 
-         rt_timer_time(animationtimer), fps); 
+    printf("Animation Time: %10.4f seconds  (Averaged %7.4f FPS)\n",
+         rt_timer_time(animationtimer), fps);
   }
   rt_timer_destroy(fpstimer);
 
@@ -218,7 +218,7 @@
 
 
 
-/* 
+/*
  * main loop for creating animations by playing recorded camera fly-throughs
  */
 static int animate_scene(argoptions opt, SceneHandle scene, int node) {
@@ -270,7 +270,7 @@
         if (node == 0) {
           printf("\rRendering Frame: %9d   %10.4f FPS       ", frameno, fps);
           fflush(stdout);
-        } 
+        }
       }
       else {
         sprintf(outfilename, opt.outfilename, frameno);
@@ -279,23 +279,23 @@
           fflush(stdout);
         }
       }
- 
+
       rt_outputfile(scene, outfilename);
       rt_camera_position(scene, cmc, cmv, cmu);
 
       rt_renderscene(scene);
 
       if (dh != NULL)
-        tachyon_display_draw(dh); 
+        tachyon_display_draw(dh);
 
       frameno++;
-    } 
+    }
     rt_timer_stop(animationtimer);
     fps = frameno / rt_timer_time(animationtimer);
     if (node == 0) {
       printf("\rCompleted animation of %d frames                            \n", frameno);
-      printf("Animation Time: %10.4f seconds  (Averaged %7.4f FPS)\n", 
-           rt_timer_time(animationtimer), fps); 
+      printf("Animation Time: %10.4f seconds  (Averaged %7.4f FPS)\n",
+           rt_timer_time(animationtimer), fps);
     }
     rt_timer_destroy(fpstimer);
     fclose(camfp);
@@ -336,7 +336,8 @@
   char * filename;
   int node, fileindex;
   rt_timerhandle parsetimer;
-   
+  size_t len;
+
   node = rt_initialize(&argc, &argv);
 
   rt_set_ui_message(my_ui_message);
@@ -346,7 +347,7 @@
     printf("Tachyon Parallel/Multiprocessor Ray Tracer   Version %s   \n",
            TACHYON_VERSION_STRING);
     printf("Copyright 1994-2010,    John E. Stone <john.stone@gmail.com> \n");
-    printf("------------------------------------------------------------ \n"); 
+    printf("------------------------------------------------------------ \n");
   }
 
   if ((rc = getargs(argc, argv, &opt, node)) != 0) {
@@ -358,7 +359,7 @@
     printf("Rendering %d scene files.\n", opt.numfiles);
   }
 
-  for (fileindex=0; fileindex<opt.numfiles; fileindex++) { 
+  for (fileindex=0; fileindex<opt.numfiles; fileindex++) {
     scene = rt_newscene();
 
     /* process command line overrides */
@@ -373,26 +374,31 @@
     parsetimer=rt_timer_create();
     rt_timer_start(parsetimer);
 
-    if (strstr(filename, ".nff") || strstr(filename, ".NFF")) {
+    len = strlen(filename);
+
+    if (len > 4 && (!strcmp(filename+len-4, ".nff") ||
+                    !strcmp(filename+len-4, ".NFF"))) {
       rc = ParseNFF(filename, scene); /* must be an NFF file */
     }
-    else if (strstr(filename, ".ac") || strstr(filename, ".AC")) {
+    else if (len > 3 && (!strcmp(filename+len-3, ".ac") ||
+                         !strcmp(filename+len-3, ".AC"))) {
       rc = ParseAC3D(filename, scene); /* Must be an AC3D file */
     }
 #ifdef USELIBMGF
-    else if (strstr(filename, ".mgf") || strstr(filename, ".MGF")) {
+    else if (len > 4 && (!strcmp(filename+len-4, ".mgf") ||
+                         !strcmp(filename+len-4, ".MGF"))) {
       rc = ParseMGF(filename, scene, 1); /* Must be an MGF file */
     }
 #endif
-    else {  
+    else {
       rc = readmodel(filename, scene); /* Assume its a Tachyon scene file */
     }
 
     rt_timer_stop(parsetimer);
-    if (rc == PARSENOERR && node == 0) 
+    if (rc == PARSENOERR && node == 0)
       printf("Scene Parsing Time: %10.4f seconds\n", rt_timer_time(parsetimer));
     rt_timer_destroy(parsetimer);
-   
+
     if (rc != PARSENOERR && node == 0) {
       switch(rc) {
         case PARSEBADFILE:
@@ -409,7 +415,7 @@
           break;
         case PARSEALLOCERR:
           printf("Parser ran out of memory.\n");
-          break; 
+          break;
       }
       if (fileindex+1 < opt.numfiles)
         printf("Aborting render, continuing with next scene file...\n");
@@ -429,7 +435,7 @@
     }
     else if (strlen(opt.spaceball) > 0) {
       return fly_scene(opt, scene, node);     /* fly with spaceball etc */
-    } 
+    }
     else {
       if (opt.numfiles > 1 && opt.nosave != 1) {
         char multioutfilename[FILENAME_MAX];
