# include "data.h"

int box (int argc, char **argv) {
  
  int i, N, kapa, size;
  char *name, fontname[64];
  Graphdata graphmode;
  
  name = NULL;
  if ((N = get_argument (argc, argv, "-n"))) {
    remove_argument (N, &argc, argv);
    name = strcreate (argv[N]);
    remove_argument (N, &argc, argv);
  }
  if (!GetGraph (&graphmode, &kapa, name)) return (FALSE);
  FREE (name);

  if ((N = get_argument (argc, argv, "-fn"))) {
    remove_argument (N, &argc, argv);
    strcpy (fontname, argv[N]);
    remove_argument (N, &argc, argv);
    size = atof (argv[N]);
    remove_argument (N, &argc, argv);
    KapaSetFont (kapa, fontname, size);
  } 

  graphmode.lweight = 1;
  if ((N = get_argument (argc, argv, "-lw"))) {
    remove_argument (N, &argc, argv);
    graphmode.lweight = atof(argv[N]);
    remove_argument (N, &argc, argv);
  }

  graphmode.color = KapaColorByName ("black");
  if ((N = get_argument (argc, argv, "-c"))) {
    remove_argument (N, &argc, argv);
    graphmode.color = KapaColorByName (argv[N]);
    if (graphmode.color == -1) return (FALSE);
    remove_argument (N, &argc, argv);
  }

  strcpy (graphmode.ticks, "2222");
  if ((N = get_argument (argc, argv, "-ticks"))) {
    remove_argument (N, &argc, argv);
    strcpy (graphmode.ticks, argv[N]);
    remove_argument (N, &argc, argv);
    if (strlen (graphmode.ticks) != 4) { goto usage; }
    for (i = 0; i < strlen (graphmode.ticks); i++) {
      if ((graphmode.ticks[i] != '0') && (graphmode.ticks[i] != '1') && (graphmode.ticks[i] != '2')) { goto usage; }
    }
  }
  
  strcpy (graphmode.labels, "2222");
  if ((N = get_argument (argc, argv, "-labels"))) {
    remove_argument (N, &argc, argv);
    strcpy (graphmode.labels, argv[N]);
    remove_argument (N, &argc, argv);
    if (strlen (graphmode.labels) != 4) { goto usage; }
    for (i = 0; i < strlen (graphmode.labels); i++) {
      if ((graphmode.labels[i] != '0') && (graphmode.labels[i] != '1') && (graphmode.labels[i] != '2')) { goto usage; }
    }
  }

  strcpy (graphmode.axis, "2222");
  if ((N = get_argument (argc, argv, "-axis"))) {
    remove_argument (N, &argc, argv);
    strcpy (graphmode.axis, argv[N]);
    remove_argument (N, &argc, argv);
    if (strlen (graphmode.axis) != 4) { goto usage; }
    for (i = 0; i < strlen (graphmode.axis); i++) {
      if ((graphmode.axis[i] != '0') && (graphmode.axis[i] != '1') && (graphmode.axis[i] != '2')) { goto usage; }
    }
  }

  if (argc != 1) goto usage;

  KapaBox (kapa, &graphmode);
  return (TRUE);
      
 usage:
  gprint (GP_ERR, "USAGE: box [-ticks NNNN] [-axis NNNN] [-labels NNNN]\n");
  return (FALSE);
}


/* box has:
   axis
   labels
   ticks

   assign like this:   
   -axis 0000
   -labels 0000
   -ticks 0000

   default:
   -axis 1111
   -labels 1100
   -ticks 1111

   messages to kapa:

   DBOX
   (xmin) (xmax) (ymin) (ymax)
   AAAA LLLL TTTT

   A = axis
   L = label
   T = ticks
   
   0 = off
   1 = on
   2 = default / maintain

*/
