# include "Ximage.h"
# define PAD 40

/* general initialization for things not specific to X */
void DefineLayout (int argc, char **argv) {

  int i, j, status, N, offset, FOREGROUND;
  Visual *visual = CopyFromParent;
  struct sockaddr_un Address;
  char temp[100];
  double PADx, PADy;
  
  if ((N = get_argument (argc, argv, "-debug"))) {
    remove_argument(N, &argc, argv);
    DEBUG = TRUE;
  } else {
    DEBUG = FALSE;
  }

  FOREGROUND = FALSE;
  if ((N = get_argument (argc, argv, "-fg"))) {
    remove_argument(N, &argc, argv);
    FOREGROUND = TRUE;
  }

  /** initiate connection with server **/
  if (!FOREGROUND) {	
    if (argc < 2) {
      fprintf (stderr, "socket path not specified\n");
      exit (0);
    }
    strcpy (Address.sun_path, argv[1]);
    Address.sun_family = AF_UNIX;
    sock = socket (AF_UNIX, SOCK_STREAM, 0);
    status = connect (sock, &Address, sizeof (Address));
    if (status < 0) {
      fprintf (stderr, "kapa - unsuccessful connection: %d\n", status);
      exit (0);
    }
    fcntl (sock, F_SETFL, O_NONBLOCK);  
    sprintf (temp, "rm -f %s\0", argv[1]);
    system (temp);
  }

  InitRotFonts ();
  MakeColormap (argc, argv);

  /** set up defaults for display region **/
  /* default startup uses one graphic region, filling the window */
  
  Nsection = 1;
  ALLOCATE (section, Layout, Nsection);
  TheSection = 0;

  /* set up axis positions */
  for (i = 0; i < 4; i++) {
    section[0].axis[i].min = 0.0;
    section[0].axis[i].max = 1.0;
    section[0].axis[i].isaxis = FALSE;
    section[0].axis[i].areticks = FALSE;
    section[0].axis[i].islabel = FALSE;
    strcpy (section[0].axis[i].label, " ");
  }    
  for (i = 0; i < 8; i++) {
    strcpy (section[0].label[i].text, "");
  }
  section[0].x  = 0;
  section[0].dx = 1; 
  section[0].y  = 0; 
  section[0].dy = 1; 
  strcpy (section[0].name, "default");

  PositionPicture (&section[0]);

  section[0].Nobjects = 0;
  section[0].Nptext = 0;

  ALLOCATE (section[0].objects, Gobjects, 1);  /* allocate so later free will not crash! */
  section[0].objects[0].x   = section[0].objects[0].y   = section[0].objects[0].z = (float *) NULL;
  section[0].objects[0].dxm = section[0].objects[0].dxp = (float *) NULL;
  section[0].objects[0].dym = section[0].objects[0].dyp = (float *) NULL;
  
  ALLOCATE (section[0].ptext, Label, 1);       /* allocate so later free will not crash! */

}
