[MPlayer-cvslog] r30820 - trunk/libvo/geometry.c

reimar subversion at mplayerhq.hu
Wed Mar 3 21:24:46 CET 2010


Author: reimar
Date: Wed Mar  3 21:24:46 2010
New Revision: 30820

Log:
Avoid very deep indentation level and RESET_GEOMETRY macro in -geometry
parsing.

Modified:
   trunk/libvo/geometry.c

Modified: trunk/libvo/geometry.c
==============================================================================
--- trunk/libvo/geometry.c	Wed Mar  3 15:32:29 2010	(r30819)
+++ trunk/libvo/geometry.c	Wed Mar  3 21:24:46 2010	(r30820)
@@ -30,53 +30,50 @@ char *vo_geometry;
 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 @@ int geometry(int *xpos, int *ypos, int *
         }
 	return 1;
 }
-
-#undef RESET_GEOMETRY


More information about the MPlayer-cvslog mailing list