Index: trunk/Ohana/src/opihi/cmd.data/section.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/section.c	(revision 31160)
+++ trunk/Ohana/src/opihi/cmd.data/section.c	(revision 42942)
@@ -1,5 +1,5 @@
 # include "data.h"
 
-enum {NONE, LIST, UP, DOWN, TOP, BOTTOM, TOOL, BG, IMAGE};
+enum {NONE, LIST, UP, DOWN, TOP, BOTTOM, TOOL, BG, IMAGE, IMCENTER};
 
 int section (int argc, char **argv) {
@@ -17,20 +17,25 @@
   }
   if ((N = get_argument (argc, argv, "-up"))) {
+    if (action != NONE) goto escape;
     action = UP;
     remove_argument (N, &argc, argv);
   }
   if ((N = get_argument (argc, argv, "-down"))) {
+    if (action != NONE) goto escape;
     action = DOWN;
     remove_argument (N, &argc, argv);
   }
   if ((N = get_argument (argc, argv, "-top"))) {
+    if (action != NONE) goto escape;
     action = TOP;
     remove_argument (N, &argc, argv);
   }
   if ((N = get_argument (argc, argv, "-bottom"))) {
+    if (action != NONE) goto escape;
     action = BOTTOM;
     remove_argument (N, &argc, argv);
   }
   if ((N = get_argument (argc, argv, "-imtool"))) {
+    if (action != NONE) goto escape;
     action = TOOL;
     remove_argument (N, &argc, argv);
@@ -41,4 +46,5 @@
   background = -1; // invisible
   if ((N = get_argument (argc, argv, "-bg"))) {
+    if (action != NONE) goto escape;
     remove_argument (N, &argc, argv);
     if (!strcasecmp (argv[N], "NONE")) {
@@ -52,6 +58,13 @@
 
   if ((N = get_argument (argc, argv, "-image"))) {
+    if (action != NONE) goto escape;
     remove_argument (N, &argc, argv);
     action = IMAGE;
+  }
+
+  if ((N = get_argument (argc, argv, "-imcenter"))) {
+    if (action != NONE) goto escape;
+    remove_argument (N, &argc, argv);
+    action = IMCENTER;
   }
 
@@ -65,106 +78,136 @@
   FREE (name);
 
-  /* list sections */
-  if ((argc == 1) && (action == NONE)) {
-    KapaGetSection (kapa, "*");
-    gprint (GP_ERR, "USAGE: section name [x y dx dy] or [options]\n");
-    gprint (GP_ERR, "OPTIONS: -list   : show properties of all sections\n");
-    gprint (GP_ERR, "         -up     : move section up in display stack\n");
-    gprint (GP_ERR, "         -down   : move section down in display stack\n");
-    gprint (GP_ERR, "         -top    : move section to top of display stack\n");
-    gprint (GP_ERR, "         -bottom : move section to bottom of display stack\n");
-    gprint (GP_ERR, "         -imtool (position) : set location of image zoom / status box\n");
-    gprint (GP_ERR, "                 (position may be: -x, +x, -y, +y, none)\n");
-    gprint (GP_ERR, "         -image  : define section upper-right corner so image fills the section\n");
-    gprint (GP_ERR, "         -bg (color) : set background color (see style -c help for color choices)\n");
-    
-    return (TRUE);
-  } 
-  
-  if ((argc != 2) && (action != NONE)) {
-      gprint (GP_ERR, "can only use dash options without numbers\n");
+  // deal with these cases first
+  if (action == NONE) {
+    if (argc == 1) { // command: section 
+      gprint (GP_ERR, "USAGE: section name x y dx dy\n");
+      gprint (GP_ERR, "       section name -image x y\n");
+      gprint (GP_ERR, "       section name [options]\n");
+      gprint (GP_ERR, "OPTIONS: -list   : show properties of all sections\n");
+      gprint (GP_ERR, "         -up     : move section up in display stack\n");
+      gprint (GP_ERR, "         -down   : move section down in display stack\n");
+      gprint (GP_ERR, "         -top    : move section to top of display stack\n");
+      gprint (GP_ERR, "         -bottom : move section to bottom of display stack\n");
+      gprint (GP_ERR, "         -imtool (position) : set location of image zoom / status box\n");
+      gprint (GP_ERR, "                 (position may be: -x, +x, -y, +y, none)\n");
+      gprint (GP_ERR, "         -image  : define section upper-right corner so image fills the section\n");
+      gprint (GP_ERR, "         -bg (color) : set background color (see style -c help for color choices or use NONE)\n");
+      return (TRUE);
+    }
+    if (argc == 2) { // command: section name
+      KapaSelectSection (kapa, argv[1]);
+      return TRUE;
+    }
+    if (argc == 6) { // command: section name x y dx dy
+      /* set section */
+      section.name = argv[1];
+      section.x = atof (argv[2]);
+      section.y = atof (argv[3]);
+      section.dx = atof (argv[4]);
+      section.dy = atof (argv[5]);
+      section.bg = -2; // bg must be set on its own
+      KapaSetSection (kapa, &section);
+      return (TRUE);
+    }
+    goto escape;
+  }
+
+  // list properties of the specified section, or all sections
+  if (action == LIST) {
+    if (argc == 1) {
+      KapaGetSection (kapa, "*");
+      return TRUE;
+    } 
+    if (argc == 2) { 
+      KapaGetSection (kapa, argv[1]);
+      KapaSelectSection (kapa, argv[1]);
+      return TRUE;
+    }
+    goto escape;
+  }
+
+  if ((action == IMAGE) || (action == IMCENTER)) {
+    if (argc != 4) goto escape;
+  } else {
+    if (argc != 2) goto escape;
+  }
+
+  /* select / show section */
+  switch (action) {
+    case UP:
+      KapaMoveSection (kapa, argv[1], "up");
+      break;
+    case DOWN:
+      KapaMoveSection (kapa, argv[1], "down");
+      break;
+    case TOP:
+      KapaMoveSection (kapa, argv[1], "top");
+      break;
+    case BOTTOM:
+      KapaMoveSection (kapa, argv[1], "bottom");
+      break;
+
+    case BG:
+      KapaSectionBG (kapa, argv[1], background);
+      break;
+
+    case TOOL:
+      KapaSelectSection (kapa, argv[1]);
+      if (!strcmp(location, "-x")) {
+	KapaSetToolbox (kapa, 1);
+	break;
+      }
+      if (!strcmp(location, "+x")) {
+	KapaSetToolbox (kapa, 3);
+	break;
+      }
+      if (!strcmp(location, "-y")) {
+	KapaSetToolbox (kapa, 2);
+	break;
+      }
+      if (!strcmp(location, "+y")) {
+	KapaSetToolbox (kapa, 4);
+	break;
+      }
+      if (!strcmp(location, "none")) {
+	KapaSetToolbox (kapa, 0);
+	break;
+      }
+      gprint (GP_ERR, "unknown toolbox location %s\n", location);
+      gprint (GP_ERR, "valid values: -x, +x, -y, +y, none\n");
       return (FALSE);
-  }
-
-  if (argc == 2) {
-    /* select / show section */
-    switch (action) {
-      case NONE:
-	KapaSelectSection (kapa, argv[1]);
-	break;
-
-      case UP:
-	KapaMoveSection (kapa, argv[1], "up");
-	break;
-      case DOWN:
-	KapaMoveSection (kapa, argv[1], "down");
-	break;
-      case TOP:
-	KapaMoveSection (kapa, argv[1], "top");
-	break;
-      case BOTTOM:
-	KapaMoveSection (kapa, argv[1], "bottom");
-	break;
-
-      case BG:
-	KapaSectionBG (kapa, argv[1], background);
-	break;
-
-      case TOOL:
-	if (!strcmp(location, "-x")) {
-	  KapaSetToolbox (kapa, 1);
-	  break;
-	}
-	if (!strcmp(location, "+x")) {
-	  KapaSetToolbox (kapa, 3);
-	  break;
-	}
-	if (!strcmp(location, "-y")) {
-	  KapaSetToolbox (kapa, 2);
-	  break;
-	}
-	if (!strcmp(location, "+y")) {
-	  KapaSetToolbox (kapa, 4);
-	  break;
-	}
-	if (!strcmp(location, "none")) {
-	  KapaSetToolbox (kapa, 0);
-	  break;
-	}
-	gprint (GP_ERR, "unknown toolbox location %s\n", location);
-	gprint (GP_ERR, "valid values: -x, +x, -y, +y, none\n");
-	return (FALSE);
-
-      case LIST:
-	KapaGetSection (kapa, argv[1]);
-	break;
-    }
-    return (TRUE);
-  } 
-  
-  if (argc == 4) {
-    /* set section */
-    section.name = argv[1];
-    section.x = atof (argv[2]);
-    section.y = atof (argv[3]);
-    section.bg = background;
-    KapaSetSectionByImage (kapa, &section);
-    return (TRUE);
-  }
-
-  if (argc == 6) {
-    /* set section */
-    section.name = argv[1];
-    section.x = atof (argv[2]);
-    section.y = atof (argv[3]);
-    section.dx = atof (argv[4]);
-    section.dy = atof (argv[5]);
-    section.bg = background;
-    KapaSetSection (kapa, &section);
-    return (TRUE);
-  }
-  gprint (GP_ERR, "USAGE: section name [x y dx dy]\n");
-  gprint (GP_ERR, "USAGE: section name [-image x y] : width based on current image\n");
-  gprint (GP_ERR, "USAGE: section name [-list] [-up] [-down] [-top] [-bottom]\n");
+
+    case IMAGE:
+      /* set section */
+      section.name = argv[1];
+      section.x = atof (argv[2]);
+      section.y = atof (argv[3]);
+      section.bg = -2;
+      KapaSetSectionByImage (kapa, &section);
+      return (TRUE);
+
+    case IMCENTER:
+      /* set section */
+      section.name = argv[1];
+      section.x = atof (argv[2]);
+      section.y = atof (argv[3]);
+      KapaSetSectionCenterByImage (kapa, &section);
+      return (TRUE);
+
+    case NONE:
+    case LIST:
+    default:
+      gprint (GP_ERR, "oops, programming error in section.c:171\n");
+      break;
+  }
+  return (TRUE);
+
+escape:
+  gprint (GP_ERR, "USAGE: section name : select the section\n");
+  gprint (GP_ERR, "USAGE: section name x y dx dy : define section location\n");
+  gprint (GP_ERR, "USAGE: section name -image x y : width based on current image\n");
+  gprint (GP_ERR, "USAGE: section name -imtool (position) : width based on current image\n");
+  gprint (GP_ERR, "USAGE: section name [-list] [-up] [-down] [-top] [-bottom] [-bg color]\n");
+  gprint (GP_ERR, "  only one -OPTION at a time\n");
   return (FALSE);
 }
