# include "Ximage.h"
# define STRCONST(A) ((int)(0x1000000*A[0] + 0x10000*A[1] + 0x100*A[2] + 0x1*A[3]))

int CheckPipe () {

  int status;
  char buffer[32];

  /***** read (4 byte) message word from socket ****/
  status = read (sock, buffer, 4);
  buffer[4] = 0;
  switch (status) {
  case -1:                          /* no input from pipe: continue */
    return (TRUE);
    break;

  case 0:
    fprintf (stderr, "pipe has died!\n");
    return (FALSE);
    break;

  case 4:
    break;

  default:
    fprintf (stderr, "weird signal: too many or few bytes!  %d\n", status);
    return (TRUE);
    break;
  }
  
  /***** handle different messages ****/
  if (!strcmp (buffer, "QUIT")) return (FALSE);
  
  if (!strcmp (buffer, "PSIT")) {
    status = PSit (SCALE);
    write (sock, "DONE", 4);
    return (status);
  }
  
  if (!strcmp (buffer, "PSRW")) {
    status = PSit (RAW);
    write (sock, "DONE", 4);
    return (status);
  }
  
  if (!strcmp (buffer, "PSNS")) {
    status = PSit (NOSCALE);
    write (sock, "DONE", 4);
    return (status);
  }
  
  if (!strcmp (buffer, "PNGF")) {
    status = PNGit ();
    write (sock, "DONE", 4);
    return (status);
  }
  
  if (!strcmp (buffer, "PPMF")) {
    status = PPMit ();
    write (sock, "DONE", 4);
    return (status);
  }
  
  if (!strcmp (buffer, "RSIZ")) {
    status = Resize ();
    return (status);
  }

  if (!strcmp (buffer, "PLOT")) {
    status = LoadObject ();
    return (status);
  }
  
  if (!strcmp (buffer, "LIMS")) {
    sprintf (buffer, "LIMS: %8.1f %8.1f \0", 
	     section[TheSection].axis[0].dfx, section[TheSection].axis[1].dfy);
    write (sock, buffer, 30);
    return (TRUE);
  }
  
  if (!strcmp (buffer, "SLIM")) {
    status = SetLimits ();
    return (TRUE);
  }
  
  if (!strcmp (buffer, "LABL")) {
    status = LoadLabels ();
    return (TRUE);
  }
  
  if (!strcmp (buffer, "LSEC")) {
    status = ListSection ();
    return (TRUE);
  }
  
  if (!strcmp (buffer, "DSEC")) {
    status = SetSection (FALSE);
    return (TRUE);
  }
  
  if (!strcmp (buffer, "SSEC")) {
    status = SetSection (TRUE);
    return (TRUE);
  }
  
  if (!strcmp (buffer, "PTXT")) {
    status = LoadPtext ();
    return (TRUE);
  }
  
  if (!strcmp (buffer, "FONT")) {
    status = SetFont ();
    return (TRUE);
  }
  
  if (!strcmp (buffer, "CURS")) {
    cursor ();
    return (TRUE);
  }
  
  /* Erase Section */
  if (!strcmp (buffer, "ERAS")) {
    status = ErasePlot (TRUE);
    return (status);
  }
  
  /* Don't Erase Section */
  if (!strcmp (buffer, "ERSS")) {
    status = ErasePlot (FALSE);
    return (status);
  }
  
  if (!strcmp (buffer, "DBOX")) {
    status = LoadBox ();
    return (status);
  }
  
  fprintf (stderr, "unknown signal %s\n", buffer);

  return (TRUE);

}


    
