[giv] Improved handling of broken files.



commit ef2abf35ff0a51a2131535db365777f7aba7c2b7
Author: Dov Grobgeld <dov grobgeld gmail com>
Date:   Thu Jun 30 23:32:14 2011 +0300

    Improved handling of broken files.
    
    2011-06-30  Dov Grobgeld  <dov grobgeld gmail com>
    
            * plugins/SConstruct: Fixed compilation under windows for
            Fedora 15 cross compilation.
    
            * giv-parser.cc: Changed logic to finish end of input if
            no \n or \r was found at the end of the line.

 ChangeLog                               |    8 +++++
 SConstruct                              |    2 +-
 src/giv-parser.cc                       |   49 +++++++++++++++++-------------
 src/gtkimageviewer/gtk-image-viewer.gob |    2 +-
 src/plugins/SConscript                  |    6 +++-
 5 files changed, 43 insertions(+), 24 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 66217be..76404ff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-06-30  Dov Grobgeld  <dov grobgeld gmail com>
+
+        * plugins/SConstruct: Fixed compilation under windows for
+        Fedora 15 cross compilation.
+
+        * giv-parser.cc: Changed logic to finish end of input if
+        no \n or \r was found at the end of the line.
+
 2011-04-28  Dov Grobgeld  <dov grobgeld gmail com>
 
         * configure.in : Bumped version to 0.9.19 .
diff --git a/SConstruct b/SConstruct
index 16eccd9..7fdf011 100644
--- a/SConstruct
+++ b/SConstruct
@@ -90,7 +90,7 @@ if ARGUMENTS.get('mingw', 0):
                  "src/plugins/npy.dll",
                  ],
                 ["makensis giv.wine.nsi"])
-    env.Append(LINKFLAGS=['-mwindows'],
+    env.Append(#LINKFLAGS=['-mwindows'],
 #               CPPPATH=["/usr/local/mingw32/include"],
 #               LIBPATH=["/usr/local/mingw32/lib"],
                )
diff --git a/src/giv-parser.cc b/src/giv-parser.cc
index ae56478..eb8cbdb 100644
--- a/src/giv-parser.cc
+++ b/src/giv-parser.cc
@@ -112,12 +112,13 @@ giv_parser_parse_file(GivParser *gp,
     
     FILE *GIV;
 
-    GIV = fopen(filename, "r");
+    GIV = fopen(filename, "rb");
     if (!GIV)
 	return -1;
 
     is_new_set = TRUE;
-    while(1) {
+    gboolean empty_line = false;
+    while(!empty_line) {
 	char S_[256];
 	int len;
 	
@@ -125,18 +126,20 @@ giv_parser_parse_file(GivParser *gp,
 	fgets(S_, sizeof(S_), GIV);
 	len = strlen(S_);
 
-        if (feof(GIV))
-            break;
-#if 0
-	if (len<=1)
-	    continue;
-#endif
-	
+        // Skip damaged sections with all NULLS
+        if (len==0)
+            empty_line = true;
+
 	// Get rid of CR and LF at end of line
+        int org_len = len;
 	while (len>0 && (S_[len-1] == '\r' || S_[len-1] == '\n')) {
 	    S_[len-1] = 0;
 	    len--;
 	}
+
+        // Get out if we didn't get a \r or \n at the end of the line!
+        if (org_len == len)
+            break;
 	
 	if (is_new_set || marks==NULL) {
 	    marks = new_giv_dataset(num_sets);
@@ -155,6 +158,9 @@ giv_parser_parse_file(GivParser *gp,
 	}
 
         giv_parser_giv_marks_data_add_line(gp, marks, S_, filename, linenum);
+
+        if (feof(GIV))
+            break;
     }
     fclose(GIV);
 
@@ -605,20 +611,22 @@ giv_parser_giv_marks_data_add_line(GivParser *gp,
     case STRING_MOVE:
     case STRING_QUIVER:
         if (type == STRING_DRAW) {
-            sscanf(S_, "%lf %lf", &p.data.point.x, &p.data.point.y);
-            if (marks->points->len == 0)
-                p.op = OP_MOVE;
-            else
-                p.op = OP_DRAW;
+            if (sscanf(S_, "%lf %lf", &p.data.point.x, &p.data.point.y)==2) {
+                if (marks->points->len == 0)
+                    p.op = OP_MOVE;
+                else
+                    p.op = OP_DRAW;
+            }
         }
         else {
-            sscanf(S_, "%s %lf %lf", dummy, &p.data.point.x, &p.data.point.y);
-            if (type == STRING_QUIVER) {
-                p.op = OP_QUIVER;
-                marks->has_quiver = TRUE;
+            if (sscanf(S_, "%s %lf %lf", dummy, &p.data.point.x, &p.data.point.y)==3) {
+                if (type == STRING_QUIVER) {
+                    p.op = OP_QUIVER;
+                    marks->has_quiver = TRUE;
+                }
+                else
+                    p.op = OP_MOVE;
             }
-            else
-                p.op = OP_MOVE;
         }
 
         /* Find marks bounding box */
@@ -630,7 +638,6 @@ giv_parser_giv_marks_data_add_line(GivParser *gp,
             gp->global_mark_min_y = p.data.point.y - ms2;
         if (p.data.point.y > gp->global_mark_max_y)
             gp->global_mark_max_y = p.data.point.y + ms2;
-	    
         g_array_append_val(marks->points, p);
         break;
     case STRING_TEXT:
diff --git a/src/gtkimageviewer/gtk-image-viewer.gob b/src/gtkimageviewer/gtk-image-viewer.gob
index 350a22d..8b2d566 100644
--- a/src/gtkimageviewer/gtk-image-viewer.gob
+++ b/src/gtkimageviewer/gtk-image-viewer.gob
@@ -526,7 +526,7 @@ class Gtk:Image:Viewer from Gtk:Widget
     if (selfp->button == (int)event->button)
       {
         if (selfp->is_mouse_button2_pressed) {
-  	selfp->is_mouse_button2_pressed = FALSE;
+          selfp->is_mouse_button2_pressed = FALSE;
   	if (selfp->last_pan_anchor_x>0 && selfp->last_pan_anchor_y > 0)
   	    zoom_translate(self,
                            (int)(selfp->last_pan_anchor_x-x),
diff --git a/src/plugins/SConscript b/src/plugins/SConscript
index bb15c03..9b0410c 100644
--- a/src/plugins/SConscript
+++ b/src/plugins/SConscript
@@ -33,10 +33,14 @@ if not env['SBOX']:
                       LIBS=['libtiff','giv-image']+env['LIBS'],
                       )
 
+    if ARGUMENTS.get('mingw', 0):
+        png_lib = ['png14']
+    else:
+        png_lib = []
     env.SharedLibrary('png',
                       ['png.c'],
                       LIBPATH=['..','../gtkimageviewer','../agg','../pcre','../plis'] + env['LIBPATH'],
-                      LIBS=['giv-image']+env['LIBS'],
+                      LIBS=['giv-image']+png_lib+env['LIBS'],
                       )
     
     SConscript('dcmtk/SConscript',



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]