If picture does no exist, warn and exit
[cascardo/movie.git] / gdk.c
diff --git a/gdk.c b/gdk.c
index 413cb49..d9ed4cd 100644 (file)
--- a/gdk.c
+++ b/gdk.c
@@ -17,6 +17,8 @@
  */
 
 
+#include <stdio.h>
+#include <stdlib.h>
 #include <gtk/gtk.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include "point.h"
@@ -33,7 +35,6 @@ struct ctx
   PangoAttrList *list;
 };
 
-#define FILENAME "/home/cascardo/fotos/debconf.jpg"
 #define WIDTH 800
 #define HEIGHT 600
 
@@ -97,10 +98,18 @@ expose (GtkWidget *widget, GdkEventExpose *event, gpointer data)
 
 #define FPF 40
 
+void
+usage ()
+{
+  fprintf (stderr, "movie picture dotsfile\n");
+  exit (0);
+}
+
 int
 main (int argc, char **argv)
 {
   char *filename;
+  char *dotsfile;
   GdkColorspace colorspace;
   gboolean has_alpha;
   int bits_per_sample;
@@ -110,15 +119,29 @@ main (int argc, char **argv)
   GdkColor Yellow;
   GdkColor Black;
   PangoAttribute *attr;
+  GError *error;
   gtk_init (&argc, &argv);
-  if (argc < 2)
-    filename = FILENAME;
+  if (argc < 3)
+    {
+      usage ();
+    }
   else
-    filename = argv[1];
-  ctx.points = ReadPoints ("pro-gnu");
+    {
+      filename = argv[1];
+      dotsfile = argv[2];
+    }
+  ctx.points = ReadPoints (dotsfile);
   ctx.points = drop_dup_frames (ctx.points, FPF);
   rescale_points (ctx.points, get_scales (FPF));
-  ctx.picture = gdk_pixbuf_new_from_file (filename, NULL);
+  error = NULL;
+  ctx.picture = gdk_pixbuf_new_from_file (filename, &error);
+  if (ctx.picture == NULL)
+    {
+      fprintf (stderr, "Could not open picture %s: %s\n", filename,
+               error->message);
+      g_error_free (error);
+      exit (1);
+    }
   ctx.i = ctx.points->len;
   colorspace = gdk_pixbuf_get_colorspace (ctx.picture);
   has_alpha = gdk_pixbuf_get_has_alpha (ctx.picture);