changeset 30778:dc08ce042315

Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry parsing.
author reimar
date Wed, 03 Mar 2010 20:24:46 +0000
parents 079be31079d3
children 106543495f5b
files libvo/geometry.c
diffstat 1 files changed, 34 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/geometry.c	Wed Mar 03 14:32:29 2010 +0000
+++ b/libvo/geometry.c	Wed Mar 03 20:24:46 2010 +0000
@@ -30,53 +30,50 @@
 int geometry_wh_changed;
 int geometry_xy_changed;
 
-#define RESET_GEOMETRY width = height = xoff = yoff = xper = yper = INT_MIN;
-
 // xpos,ypos: position of the left upper corner
 // widw,widh: width and height of the window
 // scrw,scrh: width and height of the current screen
 int geometry(int *xpos, int *ypos, int *widw, int *widh, int scrw, int scrh)
 {
-        int width, height, xoff, yoff, xper, yper;
-
-        RESET_GEOMETRY
-
         if(vo_geometry != NULL) {
-		if(sscanf(vo_geometry, "%ix%i+%i+%i", &width, &height, &xoff, &yoff) != 4 )
-		{
-		 RESET_GEOMETRY
-		 if(sscanf(vo_geometry, "%ix%i", &width, &height) != 2)
-		 {
-		  RESET_GEOMETRY
-		  if(sscanf(vo_geometry, "+%i+%i", &xoff, &yoff) != 2)
-		  {
-		   char percent[2];
-		   RESET_GEOMETRY
-		   if(sscanf(vo_geometry, "%i%%:%i%1[%]", &xper, &yper, percent) != 3)
-		   {
-		    RESET_GEOMETRY
-		    if(sscanf(vo_geometry, "%i:%i%1[%]", &xoff, &yper, percent) != 3)
-		    {
-		     RESET_GEOMETRY
-		     if(sscanf(vo_geometry, "%i%%:%i", &xper, &yoff) != 2)
-		     {
-		     RESET_GEOMETRY
-		     if(sscanf(vo_geometry, "%i:%i", &xoff, &yoff) != 2)
-		     {
-		      RESET_GEOMETRY
-		      if(sscanf(vo_geometry, "%i%1[%]", &xper, percent) != 2)
-		      {
+            int width, height, xoff, yoff, xper, yper;
+            int i;
+            int ok = 0;
+            for (i = 0; !ok && i < 8; i++) {
+                char percent[2];
+                width = height = xoff = yoff = xper = yper = INT_MIN;
+                switch (i) {
+                case 0:
+                    ok = sscanf(vo_geometry, "%ix%i+%i+%i", &width, &height, &xoff, &yoff) == 4;
+                    break;
+                case 1:
+                    ok = sscanf(vo_geometry, "%ix%i", &width, &height) == 2;
+                    break;
+                case 2:
+                    ok = sscanf(vo_geometry, "+%i+%i", &xoff, &yoff) == 2;
+                    break;
+                case 3:
+                    ok = sscanf(vo_geometry, "%i%%:%i%1[%]", &xper, &yper, percent) == 3;
+                    break;
+                case 4:
+		    ok = sscanf(vo_geometry, "%i:%i%1[%]", &xoff, &yper, percent) == 3;
+                    break;
+                case 5:
+                    ok = sscanf(vo_geometry, "%i%%:%i", &xper, &yoff) == 2;
+                    break;
+                case 6:
+                    ok = sscanf(vo_geometry, "%i:%i", &xoff, &yoff) == 2;
+                    break;
+                case 7:
+                    ok = sscanf(vo_geometry, "%i%1[%]", &xper, percent) == 2;
+                    break;
+                }
+            }
+		      if (!ok) {
 			mp_msg(MSGT_VO, MSGL_ERR,
 			    "-geometry must be in [WxH][+X+Y] | [X[%%]:[Y[%%]]] format, incorrect (%s)\n", vo_geometry);
 			return 0;
 		      }
-		     }
-		    }
-		   }
-		  }
-		 }
-		}
-	       }
 
 		mp_msg(MSGT_VO, MSGL_V,"geometry set to width: %i,"
 		  "height: %i, xoff: %i, yoff: %i, xper: %i, yper: %i\n",
@@ -101,5 +98,3 @@
         }
 	return 1;
 }
-
-#undef RESET_GEOMETRY