# include "data.h"

int labels (int argc, char **argv) {
  
  char name[64], buffer[32];
  int N, size, Xgraph;

  if (!GetGraph (NULL, &Xgraph, NULL)) return (FALSE);

  if (get_argument (argc, argv, "-h")) {
    fprintf (stderr, "label options: \n");
    fprintf (stderr, " -x : bottom-center\n");
    fprintf (stderr, " +x : top-center\n");
    fprintf (stderr, " -y : right-side\n");
    fprintf (stderr, " +y : left-side\n\n");

    fprintf (stderr, " -ul : upper-left corner\n");
    fprintf (stderr, " -ll : lower-left corner\n");
    fprintf (stderr, " -ur : upper-right corner\n");
    fprintf (stderr, " -lr : lower-right corner\n\n");

    fprintf (stderr, " -fn (font) (size) : set font and size\n");
    fprintf (stderr, "   (font) : courier, helvetica, times, symbol\n\n");
    fprintf (stderr, " label special characters:\n");
    fprintf (stderr, " ^ : superscript\n");
    fprintf (stderr, " _ : subscript\n");
    fprintf (stderr, " | : default script \n");
    fprintf (stderr, " &c, &h, &t, &s : set font\n\n");
    return (FALSE);
  }

  if (N = get_argument (argc, argv, "-fn")) {
    remove_argument (N, &argc, argv);
    strcpy (name, argv[N]);
    remove_argument (N, &argc, argv);
    size = atof (argv[N]);
    remove_argument (N, &argc, argv);
    write (Xgraph, "FONT", 4);
    sprintf (buffer, "%s", name);
    write (Xgraph, buffer, 16);
    sprintf (buffer, "%d", size);
    write (Xgraph, buffer, 16);
  } 

  if (N = get_argument (argc, argv, "-x")) {
    remove_argument (N, &argc, argv);
    SendLabel (argv[N], Xgraph, 0);
    remove_argument (N, &argc, argv);
  }

  if (N = get_argument (argc, argv, "-y")) {
    remove_argument (N, &argc, argv);
    SendLabel (argv[N], Xgraph, 1);
    remove_argument (N, &argc, argv);
  }

  if (N = get_argument (argc, argv, "+x")) {
    remove_argument (N, &argc, argv);
    SendLabel (argv[N], Xgraph, 2);
    remove_argument (N, &argc, argv);
  }

  if (N = get_argument (argc, argv, "+y")) {
    remove_argument (N, &argc, argv);
    SendLabel (argv[N], Xgraph, 3);
    remove_argument (N, &argc, argv);
  }

  if (N = get_argument (argc, argv, "-ul")) {
    remove_argument (N, &argc, argv);
    SendLabel (argv[N], Xgraph, 4);
    remove_argument (N, &argc, argv);
  }

  if (N = get_argument (argc, argv, "-ur")) {
    remove_argument (N, &argc, argv);
    SendLabel (argv[N], Xgraph, 5);
    remove_argument (N, &argc, argv);
  }

  if (N = get_argument (argc, argv, "-ll")) {
    remove_argument (N, &argc, argv);
    SendLabel (argv[N], Xgraph, 6);
    remove_argument (N, &argc, argv);
  }

  if (N = get_argument (argc, argv, "-lr")) {
    remove_argument (N, &argc, argv);
    SendLabel (argv[N], Xgraph, 7);
    remove_argument (N, &argc, argv);
  }

  if (argc != 1) {
    fprintf (stderr, "USAGE: labels [-x] [-y] [+x] [+y] [-ul] [-ur] [-ll] [-lr]\n");
    return (FALSE);
  }

  return (TRUE);
}
