🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: vmsnet.sources
Article #109

XSCOPE/VMS 1.0, part 06/08

#109
From: Patrick L. Mahan - TGV Window Wa...
Date: Fri, 04 Sep 1992 05:34
1807 lines
50178 bytes
Submitted-by: mahan@tgv.com (Patrick L. Mahan - TGV Window Washer)
Posting-number: Volume 3, Issue 158
Archive-name: xscope/part06


-+-+-+-+-+-+-+-+ START OF PART 6 -+-+-+-+-+-+-+-+
X    fprintf(stdout, "None");
X  else
X    fprintf(stdout, "WIN %08x", n);
X  return(4);
X`7D
X
XPrintWINDOWD(buf)
X     unsigned char *buf;
X`7B
X  /* print a WINDOWD -- CARD32  plus 0 = PointerWindow, 1 = InputFocus */
X  long    n = ILong (buf);
X  if (n == 0)
X    fprintf(stdout, "PointerWindow");
X  else if (n == 1)
X      fprintf(stdout, "InputFocus");
X    else
X      PrintWINDOW(buf);
X`7D
X
XPrintWINDOWNR(buf)
X     unsigned char *buf;
X`7B
X  /* print a WINDOWNR -- CARD32  plus 0 = None, 1 = PointerRoot */
X  long    n = ILong (buf);
X  if (n == 0)
X    fprintf(stdout, "None");
X  else if (n == 1)
X      fprintf(stdout, "PointerRoot");
X    else
X      PrintWINDOW(buf);
X`7D
X
X
XPrintPIXMAP(buf)
X     unsigned char *buf;
X`7B
X  /* print a PIXMAP -- CARD32  plus 0 = None */
X  long    n = ILong (buf);
X  if (n == 0)
X    fprintf(stdout, "None");
X  else
X    fprintf(stdout, "PXM %08x", n);
X`7D
X
XPrintPIXMAPNPR(buf)
X     unsigned char *buf;
X`7B
X  /* print a PIXMAPNPR -- CARD32  plus 0 = None, 1 = ParentRelative */
X  long    n = ILong (buf);
X  if (n == 0)
X    fprintf(stdout, "None");
X  else if (n == 1)
X      fprintf(stdout, "ParentRelative");
X    else
X      PrintPIXMAP(buf);
X`7D
X
XPrintPIXMAPC(buf)
X     unsigned char *buf;
X`7B
X  /* print a PIXMAPC -- CARD32  plus 0 = CopyFromParent */
X  long    n = ILong (buf);
X  if (n == 0)
X    fprintf(stdout, "CopyFromParent");
X  else
X    PrintPIXMAP(buf);
X`7D
X
X
XPrintCURSOR(buf)
X     unsigned char *buf;
X`7B
X  /* print a CURSOR -- CARD32  plus 0 = None */
X  long    n = ILong (buf);
X  if (n == 0)
X    fprintf(stdout, "None");
X  else
X    fprintf(stdout, "CUR %08x", n);
X`7D
X
X
XPrintFONT(buf)
X     unsigned char *buf;
X`7B
X  /* print a FONT -- CARD32  plus 0 = None */
X  long    n = ILong (buf);
X  if (n == 0)
X    fprintf(stdout, "None");
X  else
X    fprintf(stdout, "FNT %08x", n);
X`7D
X
X
XPrintGCONTEXT(buf)
X     unsigned char *buf;
X`7B
X  /* print a GCONTEXT -- CARD32 */
X  long    n = ILong (buf);
X  fprintf(stdout, "GXC %08x", n);
X`7D
X
X
XPrintCOLORMAP(buf)
X     unsigned char *buf;
X`7B
X  /* print a COLORMAP -- CARD32 plus 0 = None */
X  long    n = ILong (buf);
X  if (n == 0)
X    fprintf(stdout, "None");
X  else
X    fprintf(stdout, "CMP %08x", n);
X  return(4);
X`7D
X
XPrintCOLORMAPC(buf)
X     unsigned char *buf;
X`7B
X  /* print a COLORMAPC -- CARD32 plus 0 = CopyFromParent */
X  long    n = ILong (buf);
X  if (n == 0)
X    fprintf(stdout, "CopyFromParent");
X  else
X    PrintCOLORMAP(buf);
X`7D
X
X
XPrintDRAWABLE(buf)
X     unsigned char *buf;
X`7B
X  /* print a DRAWABLE -- CARD32 */
X  long    n = ILong (buf);
X  fprintf(stdout, "DWB %08x", n);
X`7D
X
XPrintFONTABLE(buf)
X     unsigned char *buf;
X`7B
X  /* print a FONTABLE -- CARD32 */
X  long    n = ILong (buf);
X  fprintf(stdout, "FTB %08x", n);
X`7D
X
X/* ************************************************************ */
X
X#define NumberofAtoms 68
X
Xchar   *AtomTable`5BNumberofAtoms + 1`5D =
X`7B
X  "NONE", "PRIMARY", "SECONDARY", "ARC", "ATOM", "BITMAP", "CARDINAL",
X  "COLORMAP", "CURSOR", "CUT_BUFFER0", "CUT_BUFFER1", "CUT_BUFFER2",
X  "CUT_BUFFER3", "CUT_BUFFER4", "CUT_BUFFER5", "CUT_BUFFER6",
X  "CUT_BUFFER7", "DRAWABLE", "FONT", "INTEGER", "PIXMAP", "POINT",
X  "RECTANGLE", "RESOURCE_MANAGER", "RGB_COLOR_MAP", "RGB_BEST_MAP",
X  "RGB_BLUE_MAP", "RGB_DEFAULT_MAP", "RGB_GRAY_MAP", "RGB_GREEN_MAP",
X  "RGB_RED_MAP", "STRING", "VISUALID", "WINDOW", "WM_COMMAND",
X  "WM_HINTS", "WM_CLIENT_MACHINE", "WM_ICON_NAME", "WM_ICON_SIZE",
X  "WM_NAME", "WM_NORMAL_HINTS", "WM_SIZE_HINTS", "WM_ZOOM_HINTS",
X  "MIN_SPACE", "NORM_SPACE", "MAX_SPACE", "END_SPACE", "SUPERSCRIPT_X",
X  "SUPERSCRIPT_Y", "SUBSCRIPT_X", "SUBSCRIPT_Y", "UNDERLINE_POSITION",
X  "UNDERLINE_THICKNESS", "STRIKEOUT_ASCENT", "STRIKEOUT_DESCENT",
X  "ITALIC_ANGLE", "X_HEIGHT", "QUAD_WIDTH", "WEIGHT", "POINT_SIZE",
X  "RESOLUTION", "COPYRIGHT", "NOTICE", "FONT_NAME", "FAMILY_NAME",
X  "FULL_NAME", "CAP_HEIGHT", "WM_CLASS", "WM_TRANSIENT_FOR"
X  `7D;
X
X/* for atoms, we print the built-in atoms.  We could expand to printing
X   the user defined ones, too. */
X
XPrintATOM(buf)
X     unsigned char *buf;
X`7B
X  /* print a ATOM -- CARD32 plus 0 = None */
X  long    n = ILong (buf);
X  if (0 <= n && n <= NumberofAtoms)
X    fprintf(stdout, "<%s>", AtomTable`5Bn`5D);
X  else
X    fprintf(stdout, "ATM %08x", n);
X  return(4);
X`7D
X
XPrintATOMT(buf)
X     unsigned char *buf;
X`7B
X  /* print a ATOMT -- CARD32 plus 0 = AnyPropertyType */
X  long    n = ILong (buf);
X  if (n == 0)
X    fprintf(stdout, "AnyPropertyType");
X  else
X    PrintATOM(buf);
X`7D
X
X
XPrintVISUALID(buf)
X     unsigned char *buf;
X`7B
X  /* print a VISUALID -- CARD32 plus 0 = None */
X  long    n = ILong (buf);
X  if (n == 0)
X    fprintf(stdout, "None");
X  else
X    fprintf(stdout, "VIS %08x", n);
X`7D
X
XPrintVISUALIDC(buf)
X     unsigned char *buf;
X`7B
X  /* print a VISUALIDC -- CARD32 plus 0 = CopyFromParent */
X  long    n = ILong (buf);
X  if (n == 0)
X    fprintf(stdout, "CopyFromParent");
X  else
X    PrintVISUALID(buf);
X`7D
X
X
XPrintTIMESTAMP(buf)
X     unsigned char *buf;
X`7B
X  /* print a TIMESTAMP -- CARD32 plus 0 as the current time */
X  long    n = ILong (buf);
X  if (n == 0)
X    fprintf(stdout, "CurrentTime");
X  else
X    fprintf(stdout, "TIM %08x", n);
X`7D
X
X
XPrintRESOURCEID(buf)
X     unsigned char *buf;
X`7B
X  /* print a RESOURCEID -- CARD32 plus 0 = AllTemporary */
X  long    n = ILong (buf);
X  if (n == 0)
X    fprintf(stdout, "AllTemporary");
X  else
X    fprintf(stdout, "RID %08x", n);
X`7D
X
X
XPrintKEYSYM(buf)
X     unsigned char *buf;
X`7B
X  /* print a KEYSYM -- CARD32 */
X  long    n = ILong (buf);
X  fprintf(stdout, "KYS %08x", n);
X  return(4);
X`7D
X
XPrintKEYCODE(buf)
X     unsigned char *buf;
X`7B
X  /* print a KEYCODE -- CARD8 */
X  unsigned short n = IByte (buf);
X  fprintf(stdout, "%d (%s)", n, printrep(n));
X  return(1);
X`7D
X
XPrintKEYCODEA(buf)
X     unsigned char *buf;
X`7B
X  /* print a KEYCODEA -- CARD8 plus 0 = AnyKey */
X  long    n = IByte (buf);
X  if (n == 0)
X    fprintf(stdout, "AnyKey");
X  else
X    PrintKEYCODE(buf);
X`7D
X
X
XPrintBUTTON(buf)
X     unsigned char *buf;
X`7B
X  /* print a BUTTON -- CARD8 */
X  unsigned short n = IByte (buf);
X  fprintf(stdout, "%d (%s)", n, printrep(n));
X`7D
X
XPrintBUTTONA(buf)
X     unsigned char *buf;
X`7B
X  /* print a BUTTONA -- CARD8 plus 0 = AnyButton */
X  long    n = IByte (buf);
X  if (n == 0)
X    fprintf(stdout, "AnyButton");
X  else
X    PrintBUTTON(buf);
X`7D
X
X
X/* this is an interesting cheat -- we call DecodeEvent to print an event */
X/* should work, but its never been tried */
XPrintEVENTFORM(buf)
X     unsigned char *buf;
X`7B
X  /* print an EVENT_FORM -- event format */
X  DecodeEvent(-1, buf, (long)-1);
X`7D
X
X/* ************************************************************ */
X
XPrintENUMERATED(buf, length, ValueList)
X     unsigned char *buf;
X     short   length;
X     struct ValueListEntry  *ValueList;
X`7B
X  long   n;
X  struct ValueListEntry  *p;
X
X  if (length == 1)
X    n = IByte(buf);
X  else if (length == 2)
X      n = IShort(buf);
X    else
X      n = ILong(buf);
X
X  p = ValueList;
X  while (p != NULL && p->Value != n)
X    p = p->Next;
X
X  if (p != NULL)
X    fprintf(stdout, "%s", p->Name);
X  else
X    fprintf(stdout, "**INVALID** (%d)", n);
X`7D
X
X/* ************************************************************ */
X
XPrintSET(buf, length, ValueList)
X     unsigned char *buf;
X     short   length;
X     struct ValueListEntry  *ValueList;
X`7B
X  unsigned long   n;
X  struct ValueListEntry  *p;
X  Boolean MatchesAll = false;
X  Boolean FoundOne = false;
X
X  if (length == 1)
X    n = IByte(buf);
X  else if (length == 2)
X      n = IShort(buf);
X    else
X      n = ILong(buf);
X
X  if (n != 0)
X    `7B
X      /* first check if the value matches ALL of the bits. */
X      MatchesAll = true;
X      for (p = ValueList; MatchesAll && (p != NULL); p = p->Next)
X`09`7B
X`09  if ((p->Value & n) == 0)
X`09      MatchesAll = false;
X`09`7D
X
X      if (!MatchesAll)
X`09/* if it matches some, but not all, print only those it matches */
X`09for (p = ValueList; p != NULL; p = p->Next)
X`09  `7B
X`09    if ((p->Value & n) != 0)
X`09      `7B
X`09`09if (FoundOne)
X`09`09  fprintf(stdout, " `7C ");
X`09`09fprintf(stdout, "%s", p->Name);
X`09`09FoundOne = true;
X`09      `7D
X`09  `7D
X    `7D
X
X  if (MatchesAll)
X    fprintf(stdout, "<ALL>");
X  else if (!FoundOne)
X    fprintf(stdout, "0");
X`7D
X
X
X/* ************************************************************ */
X/*`09`09`09`09`09`09`09`09*/
X/*`09`09`09`09`09`09`09`09*/
X/* ************************************************************ */
X
XPrintField(buf, start, length, FieldType, name)
X     unsigned char *buf;
X     short   start;
X     short   length;
X     short   FieldType;
X     char   *name;
X`7B
X  if (length == 0)
X    return;
X
X  fprintf(stdout, "%s%20s: ", Leader, name);
X
X  if (debuglevel & 8)
X    DumpHexBuffer(&(buf`5Bstart`5D), (long)length);
X
X  switch (TD`5BFieldType`5D.Type)
X    `7B
X`09  case BUILTIN:
X`09`09 (*TD`5BFieldType`5D.PrintProc)(&buf`5Bstart`5D);
X`09`09 break;
X
X`09  case ENUMERATED:
X`09`09 PrintENUMERATED(&buf`5Bstart`5D, length, TD`5BFieldType`5D.ValueList)
V;
X`09`09 break;
X
X`09  case SET:
X`09`09 PrintSET(&buf`5Bstart`5D, length, TD`5BFieldType`5D.ValueList);
X`09`09 break;
X
X`09  case RECORD:
X`09`09 ModifyIndentLevel(1);
X`09`09 fprintf(stdout, "\n");
X`09`09 if (Verbose < 3)
X`09`09   return;
X`09`09 (*TD`5BFieldType`5D.PrintProc)(&buf`5Bstart`5D);
X`09`09 ModifyIndentLevel(-1);
X`09`09 break;
X    `7D
X  fprintf(stdout, "\n");
X  fflush(stdout);
X`7D
X
X/* ************************************************************ */
X/*`09`09`09`09`09`09`09`09*/
X/*`09`09`09`09`09`09`09`09*/
X/* ************************************************************ */
X
X/* print a list of things.  The things are of type <ListType>.
X   They start at <buf>.  There are <number> things in the list */
X
Xlong PrintList(buf, number, ListType, name)
X     unsigned char *buf;
X     long   number;
X     short   ListType;
X     char   *name;
X`7B
X  long    n;
X  long    i;
X  long    sum;
X
X  if (number == 0)
X    return(0);
X
X  fprintf(stdout, "%s%20s: (%d)\n", Leader, name, number);
X  if (Verbose < 2)
X    return(0);
X
X  ModifyIndentLevel(1);
X  sum = 0;
X  for (i = 0; i < number; i++)
X    `7B
X      switch (TD`5BListType`5D.Type)
X`09`7B
X`09`09    case BUILTIN:
X`09`09`09    n = (*TD`5BListType`5D.PrintProc)(buf);
X`09`09`09    break;
X`09`09    case RECORD:
X`09`09`09    n = (*TD`5BListType`5D.PrintProc)(buf);
X`09`09`09    break;
X`09`09    default:
X`09`09`09    fprintf(stdout, "**INVALID**");
X`09`09`09    n = 0;
X`09`09`09    break;
X`09`7D
X      buf = buf + n;
X      sum = sum + n;
X      fprintf(stdout, "%s---\n", Leader);
X    `7D
X
X  ModifyIndentLevel(-1);
X  return(sum);
X`7D
X
X/* ************************************************************ */
X/*`09`09`09`09`09`09`09`09*/
X/*`09`09`09`09`09`09`09`09*/
X/* ************************************************************ */
X
X/* print a list of STRs.  Similar to PrintList
X   They start at <buf>.  There are <number> things in the list */
X
Xlong PrintListSTR(buf, number, name)
X     unsigned char *buf;
X     long   number;
X     char   *name;
X`7B
X  long    n;
X  long    i;
X  long    sum;
X
X  if (number == 0)
X    return(0);
X
X  fprintf(stdout, "%s%20s: (%d)\n", Leader, name, number);
X  if (Verbose < 2)
X    return(0);
X
X  ModifyIndentLevel(1);
X  sum = 0;
X  for (i = 0; i < number; i++)
X    `7B
X      fprintf(stdout, "%s", Leader);
X      n = PrintSTR(buf);
X      buf = buf + n;
X      sum = sum + n;
X      fprintf(stdout, "\n");
X    `7D
X
X  ModifyIndentLevel(-1);
X  return(sum);
X`7D
X
X
X/* ************************************************************ */
X/*`09`09`09`09`09`09`09`09*/
X/*`09`09`09`09`09`09`09`09*/
X/* ************************************************************ */
X
X
XPrintBytes(buf, number, name)
X     unsigned char   buf`5B`5D;
X     long   number;
X     char   *name;
X`7B
X  /* print a list of BYTE -- 8-bit character */
X  long   i;
X  short   column;
X
X  if (number == 0)
X    return(0);
X
X  fprintf(stdout, "%s%20s: ", Leader, name);
X  column = SizeofLeader() + 25;
X  for (i = 0; i < number; i++)
X    `7B
X      if (column > 80)
X`09`7B
X`09  if (Verbose < 2)
X`09    break;
X`09  fprintf(stdout, "\n%s%20s: ", Leader, "");
X`09  column = SizeofLeader() + 25;
X`09`7D
X      fprintf(stdout, "%02x ",((unsigned int) buf`5Bi`5D));
X      column += 3;
X    `7D
X  fprintf(stdout, "\n");
X
X  return(number);
X`7D
X
X
X/* ************************************************************ */
X/*`09`09`09`09`09`09`09`09*/
X/*`09`09`09`09`09`09`09`09*/
X/* ************************************************************ */
X
X
X/* print a String of CHAR8 -- 8-bit characters */
X
XPrintString8(buf, number, name)
X     unsigned char    buf`5B`5D;
X     short   number;
X     char   *name;
X`7B
X  short   i;
X
X  if (number == 0)
X    return(0);
X
X  fprintf(stdout, "%s%20s: \"", Leader, name);
X  for (i = 0; i < number; i++)
X    fprintf(stdout, "%s", printrep(buf`5Bi`5D));
X  fprintf(stdout, "\"\n");
X
X  return(number);
X`7D
X
X
X/* print a String of CHAR16 -- 16-bit characters */
X
XPrintString16(buf, number, name)
X     unsigned char    buf`5B`5D;
X     short   number;
X     char   *name;
X`7B
X  short   i;
X  unsigned short   c;
X
X  if (number == 0)
X    return(0);
X
X  fprintf(stdout, "%s%20s: \"", Leader, name);
X  for (i = 0; i < number; i += 2)
X    `7B
X      c = IShort(&buf`5Bi`5D);
X      fprintf(stdout, "%s", printrep(c));
X    `7D
X  fprintf(stdout, "\"\n");
X
X  return(number);
X`7D
X
X/* ************************************************************ */
X/*`09`09`09`09`09`09`09`09*/
X/*`09`09`09`09`09`09`09`09*/
X/* ************************************************************ */
X
X/*
X  A Value List is two things:
X
X  (1) A controlling bitmask.  For each one bit in the control,
X  a value is in the list.
X  (2) A list of values.
X*/
X
XPrintValues(control, clength, ctype, values, name)
X     unsigned char   *control;
X     short   clength;
X     short   ctype;
X     unsigned char   *values;
X     char   *name;
X`7B
X  long    cmask;
X  struct ValueListEntry  *p;
X
X  /* first get the control mask */
X  if (clength == 1)
X    cmask = IByte(control);
X  else if (clength == 2)
X      cmask = IShort(control);
X    else
X      cmask = ILong(control);
X
X  /* now if it is zero, ignore and return */
X  if (cmask == 0)
X    return;
X
X  /* there are bits in the controlling bitmask, figure out which */
X  /* the ctype is a set type, so this code is similar to PrintSET */
X  fprintf(stdout, "%s%20s:\n", Leader, name);
X  ModifyIndentLevel(1);
X  for (p = TD`5Bctype`5D.ValueList; p != NULL; p = p->Next)
X    `7B
X      if ((p->Value & cmask) != 0)
X`09`7B
X`09  short   m = 4 - p->Length;
X`09  PrintField(values, m, p->Length, p->Type, p->Name);
X`09  values += 4;
X`09`7D
X    `7D
X  ModifyIndentLevel(-1);
X`7D
X
X
X/* ************************************************************ */
X/*`09`09`09`09`09`09`09`09*/
X/*`09`09`09`09`09`09`09`09*/
X/* ************************************************************ */
X
X/* PolyText8 and PolyText16 take lists of characters with possible
X   font changes in them. */
X
XPrintTextList8(buf, length, name)
X     unsigned char *buf;
X     short   length;
X     char   *name;
X`7B
X  short   n;
X
X  fprintf(stdout, "%s%20s:\n", Leader, name);
X  while (length > 1)
X    `7B
X      n = IByte(&buf`5B0`5D);
X      if (n != 255)
X`09`7B
X`09  PrintField(buf, 1, 1, INT8, "delta");
X`09  PrintString8(&buf`5B2`5D, n, "text item 8 string");
X`09  buf += n + 2;
X`09  length -= n + 2;
X`09`7D
X      else
X`09`7B
X`09  PrintField(buf, 1, 4, FONT, "font-shift-id");
X`09  buf += 4;
X`09  length -= 4;
X`09`7D
X    `7D
X`7D
X
XPrintTextList16(buf, length, name)
X     unsigned char *buf;
X     short   length;
X     char   *name;
X`7B
X  short   n;
X
X  fprintf(stdout, "%s%20s:\n", Leader, name);
X  while (length > 1)
X    `7B
X      n = IByte(&buf`5B0`5D);
X      if (n != 255)
X`09`7B
X`09  PrintField(buf, 1, 1, INT8, "delta");
X`09  PrintString16(&buf`5B2`5D, n, "text item 16 string");
X`09  buf += n + 2;
X`09  length -= n + 2;
X`09`7D
X      else
X`09`7B
X`09  PrintField(buf, 1, 4, FONT, "font-shift-id");
X`09  buf += 4;
X`09  length -= 4;
X`09`7D
X    `7D
X`7D
X
X
X/* ************************************************************ */
X/*`09`09`09`09`09`09`09`09*/
X/*`09`09`09`09`09`09`09`09*/
X/* ************************************************************ */
X
X#define MAXline 78
X
XDumpHexBuffer(buf, n)
X     unsigned char *buf;
X     long    n;
X`7B
X  short   i;
X  short   column;
X  char    h`5B6`5D /* one hex or octal character */ ;
X
X  column = 27 + SizeofLeader();
X  for (i = 0; i < n; i++)
X    `7B
X      /* get the hex representations */
X      sprintf(h, "%02x",(0xff & buf`5Bi`5D));
X
X      /* check if these characters will fit on this line */
X      if ((column + strlen(h) + 1) > MAXline)
X`09`7B
X`09  /* line will be too long -- print it */
X`09  fprintf(stdout, "\n");
X`09  column = 0;
X`09`7D
X      fprintf(stdout, "%s ", h);
X      column += 3;
X    `7D
X`7D
$ CALL UNPACK PRTYPE.C;10 1148940676
$ create 'f'
X
X`09XSCOPE -- a program to monitor X11/Client conversations
X
XXSCOPE is a program to monitor the connections between the X11 window
Xserver and a client program.  xscope runs as a separate process.  By
Xadjusting the host and/or display number that a X11 client attaches
Xto, the client is attached to xscope instead of X11.  xscope attaches
Xto X11 as if it were the client.  All bytes from the client are sent
Xto xscope which passes them on to X11; All bytes from X11 are sent to
Xxscope which sends them on to the client.  xscope is transparent to
Xthe client and X11.
X
XIn addition to passing characters back and forth, xscope will print
Xinformation about this traffic on stdout, giving performance and
Xdebugging information for an X11 client and server.
X
X
X  --------------               --------------             --------------
X  `7C            `7C               `7C            `7C             `7C
V            `7C
X  `7C            `7C ------------> `7C            `7C ----------> `7C
V            `7C
X  `7C   client   `7C               `7C  xscope    `7C             `7C   serv
Ver   `7C
X  `7C            `7C               `7C            `7C             `7C
V            `7C
X  `7C            `7C <-----------  `7C            `7C <---------- `7C
V            `7C
X  `7C            `7C               `7C            `7C             `7C
V            `7C
X  --------------               --------------             --------------
X                                     `7C
X`09`09`09`09     `7C
X`09`09`09`09     v
X`09`09`09    trace output to stdout
X
X
XWhen running with xscope, three processes are involved, potentially all
Xon different machines:
X
XX11 -- the X11 window server will be running on machine "A" for Display "B".
X`09("A" is a machine name; "B" is a display number).
X
Xxscope -- xscope must be told where the X11 window server is`20
X`09(what machine and what display).  The options for xscope are`20
X`09-h<X11-host> and -d<display-number>.  In our example, -hA and -dB.`20
X`09Typically the display-number is not given. xscope will not try to`20
X`09connect to X11 until the client connects to xscope.
X
Xclient -- the client should connect to xscope rather than X11.  To avoid`20
X`09changing the code for the client, xscope listens on the same port`20
X`09as X11. If X11 and xscope are on different machines, this works`20
X`09well.  However, if X11 and xscope are on the same machine, this`20
X`09creates a port conflict.  To resolve this conflict, xscope can`20
X`09be given a different input or output port number, as necessary`20
X`09to avoid the port that X11 is listening to.  The client must connect`20
X`09to this offset port number.  The input port for xscope is set by`20
X`09-i<port-number>; the output port is set by -o<port-number>. The`20
X`09default input port is 1; the default output port is 0. These ports
X`09are offset by the X11 base (6000) and the display number. The client`20
X`09attaches to xscope by changing its display number by the port offset.
X
XFor example, with X11 running on "bagel", display 0 (the default), and
Xxscope and the client running on "cleo", we would start xscope as
X"xscope -hbagel -i0".  The client program could then connect to "X11" on
X"cleo:0", and would be attached to xscope, which would then attach to
XX11 on "bagel:0".
X
XIf, however, all three processes were running on "cleo", we would
Xstart xscope by "xscope -i1".  This would cause it to listen on
Xport 6001 (which is display 1 for X11).  The client would attach to
XX11 on "cleo:1", and xscope would connect through to X11 on "cleo:0".
X
X
XLIMITATIONS:
X
Xxscope has been written and used on a Sun3. Additional code may be needed
Xfor byteswapping on different architectures.
X
XThe command line arguments for specifying the real X server should probably
X`09be changed to be more consistent with X11R3 applications.
X
XThe Imakefile may be incorrect.
X
XThe builtin atoms have been wired in directly; they should probably be
Xpicked up from a header file.
X
XNo provision is included for extensions to the base protocol.
X
XThere is no code yet to interpret typed commands from the keyboard.
X   It would be possible for a command language at the keyboard to create
X   artificial characters to be sent to X11 or the client as if they were`20
X   generated  by the other, or to dynamically alter requests or replies.
X
X
X
X
$ CALL UNPACK README.;1 1246703115
$ create 'f'
X                                  XScope/VMS
X                                      1.0
X
XDescription
X
X  This is a version of XSCOPE for VMS.  It supports both DECnet and TCP/IP
X  transports and fully compatible with the X11 protocol.  For a description
X  of how XSCOPE works see the file README.;
X
XWhere to get XScope/VMS
X
X  XScope/VMS is distributed as both a VMS Shar file and a VMS Backup Saveset
V.
X  The VMS Shar file is posted to vmsnet.sources and the VMS Backup Saveset
X  is available from PUBLIC.TGV.COM under `5B.MAHAN`5D.
X
XBuilding Xscope/VMS
X
X  After unpacking the VMS Shar file, or the VMS Backup Saveset, issue the
X  command @MAKE.COM to compile and link both xscope programs.  This build
X  produces at least one executable and maybe two if you have MultiNet`20
X  installed on your system.  DNXSCOPE.EXE is the DECnet version of XSCOPE.
X  It requires the following privileges to run: NETMBX, TMPMBX and SYSNAM.
X  IPXSCOPE.EXE is the TCP/IP version built using TGV's MultiNet Socket libra
Vry,
X  though it should easily any of the current VMS TCP/IP vendor's socket
X  libraries.
X
X  After building the executables, simply define the executables as foreign
X  commands.
X
XUser Help
X
X  Currently the only help provided is the original Unix man page provided
X  with XSCOPE.
X
XRestrictions
X
X  The DECnet version requires SYSNAM privilege.  This is due to the nature
X  of DECnet objects which require the ability to create system wide logical
X  names.
X
X  The TCP/IP version is built using TGV's MultiNet.  Hopefully, somebody
X  will convert it to support other vendor's VMS TCP/IP libraries as well.
X  If you do, I would like the modified source sent back to me.  One small
X  caveat, the other vendor's TCP/IP must be a fairly full implementation
X  of the standard socket library.  To see what I did for MultiNet, look
X  for the #ifdef MULTINET lines in the .C files.
X
X  Please report any bugs or enhancements to me.
X
XAuthors
X
X  Patrick L. Mahan (mahan@tgv.com)`09Original port to VMS
X  Osborne Hardison (hardison@ncd.com)`09Author of the DECnet socket library
X
$ CALL UNPACK README.VMS;2 1061555220
$ create 'f'
X/* ******************************************************
X *`09`09`09`09`09`09      `09*
X *  A spy program to reveal X11  traffic`09    `09*
X *`09`09`09`09`09`09      `09*
X *`09James Peterson, 1988`09       `09`09`09*
X *`09(c) Copyright MCC, 1988 `09`09`09*
X *`09`09`09`09`09`09`09*
X ***************************************************** */
X#if defined(vax11c) && !defined(MULTINET)
X#include "emulationlib.h"
X#endif
X
X#include "scope.h"
X
X
X/* ********************************************** */
X/*                                                */
X/* ********************************************** */
X
X#define DefaultPort 6000
X
Xchar    ServerHostName`5B255`5D;
Xlong    ServerBasePort = DefaultPort;
Xlong    ServerInPort = 1;
Xlong    ServerOutPort = 0;
Xlong    ServerDisplay = 0;
X
X
X/* ********************************************** */
X/*                                                */
X/*                                                */
X/* ********************************************** */
X
Xshort     GetServerport ()
X`7B
X  short     port;
X
X  enterprocedure("GetServerport");
X
X  port = ServerBasePort + ServerOutPort + ServerDisplay;
X  debug(4,(stderr, "Server service is on port %d\n", port));
X  return(port);
X`7D
X
Xshort     GetScopePort ()
X`7B
X  short     port;
X
X  enterprocedure("GetScopePort");
X
X  port = ServerBasePort + ServerInPort + ServerDisplay;
X  debug(4,(stderr, "scope service is on port %d\n", port));
X  return(port);
X`7D
X
X/* ********************************************** */
X/*                                                */
X/* ********************************************** */
X
XUsage()
X`7B
X  fprintf(stderr, "Usage: xscope\n");
X  fprintf(stderr, "              `5B-h<server-host>`5D\n");
X  fprintf(stderr, "              `5B-i<in-port>`5D\n");
X  fprintf(stderr, "              `5B-o<out-port>`5D\n");
X  fprintf(stderr, "              `5B-d<display-number>`5D\n");
X  fprintf(stderr, "              `5B-v<n>`5D  -- verbose output\n");
X  fprintf(stderr, "              `5B-q`5D  -- quiet output\n");
X  fprintf(stderr, "              `5B-D<debug-level>`5D\n");
X  exit(1);
X`7D
X
X
Xchar *OfficialName()  /* forward type declaration */;
X
XScanArgs(argc, argv)
X     int     argc;
X     char  **argv;
X`7B
X  Verbose = 1 /* default verbose-ness level */;
X
X  /* Scan argument list */
X  while (--argc > 0)
X    `7B
X      ++argv;
X      if (**argv == '-')
X`09switch (*++*argv)
X`09  `7B
X`09    /*
X`09      debug levels:
X`09      `092 - trace each procedure entry
X`09      `094 - I/O, connections
X`09      `098 - Scope internals
X`09      `0916 - Message protocol
X`09`0932 - 64 - malloc
X`09`09128 - 256 - really low level
X`09    */
X`09  case 'D':
X`09    debuglevel = atoi(++*argv);
X`09    if (debuglevel == 0)
X`09      debuglevel = 255;
X`09    debuglevel `7C= 1;
X`09    Verbose = 7;
X`09    debug(1,(stderr, "debuglevel = %d\n", debuglevel));
X`09    break;
X
X`09  case 'q': /* quiet mode */
X`09    Verbose = 0;
X`09    debug(1,(stderr, "Verbose = %d\n", Verbose));
X`09    break;
X
X`09  case 'v': /* verbose mode */
X`09    Verbose = atoi(++*argv);
X`09    debug(1,(stderr, "Verbose = %d\n", Verbose));
X`09    break;
X
X`09  case 'o':
X`09    ServerOutPort = atoi(++*argv);
X`09    if (ServerOutPort <= 0)
X`09      ServerOutPort = 0;
X`09    debug(1,(stderr, "ServerOutPort = %d\n", ServerOutPort));
X`09    break;
X
X`09  case 'd':
X`09    ServerDisplay = atoi(++*argv);
X`09    if (ServerDisplay <= 0)
X`09      ServerDisplay = 0;
X`09    debug(1,(stderr, "ServerDisplay=%d\n", ServerDisplay));
X`09    break;
X
X`09  case 'i':
X`09    ServerInPort = atoi(++*argv);
X`09    if (ServerInPort <= 0)
X`09      ServerInPort = 0;
X`09    debug(1,(stderr, "ServerInPort = %d\n", ServerInPort));
X`09    break;
X
X`09  case 'h':
X`09    if (++*argv != NULL && **argv != '\0')
X`09      strcpy(ServerHostName, OfficialName(*argv));
X`09    debug(1,(stderr, "ServerHostName=%s\n", ServerHostName));
X`09    break;
X
X`09  default:
X`09    fprintf(stderr, "Unknown option %c\n", **argv);
X`09    Usage();
X`09    break;
X
X`09  `7D
X      else
X`09`7B
X`09  /* file argument to scope -- error */
X`09  Usage();
X`09`7D
X    `7D
X
X  /* check for different port numbers or different machines */
X  if (ServerInPort == ServerOutPort)
X    if (ServerHostName`5B0`5D == '\0')
X      `7B
X`09fprintf(stderr, "Can't have xscope on same port as server (%d)\n",
X`09`09ServerInPort);
X`09Usage();
X      `7D
X
X`7D
X
X
X/* ********************************************** */
X/*                                                */
X/* ********************************************** */
X
Xmain(argc, argv)
X     int     argc;
X     char  **argv;
X`7B
X  ScanArgs(argc, argv);
X  InitializeFD();
X  InitializeX11();
X  SetUpStdin();
X  SetUpConnectionSocket(GetScopePort());
X  SetSignalHandling();
X
X  MainLoop();
X`7D
X
XTimerExpired()
X`7B
X  debug(16,(stderr, "Timer tick\n"));
X`7D
X
X/* ********************************************** */
X/*                                                */
X/* ********************************************** */
X
X/*
X  here is where we would add code to allow control from
X  the keyboard.  We would want to read a command and
X  interpret it.  Possibilties:
X
X  (a) verbose level setting
X  (b) reset time
X  (c) save X requests to a file.
X  (d) replay X requests from a file.
X  (e) allow fake events, errors to be generated.
X*/
X
XReadStdin(fd)
X     FD fd;
X`7B
X  char    buf`5B2048`5D;
X  long    n;
X
X  enterprocedure("ReadStdin");
X  n = read(fd, buf, 2048);
X  debug(4,(stderr, "read %d bytes from stdin\n", n));
X`7D
X
XSetUpStdin()
X`7B
X  enterprocedure("SetUpStdin");
X#ifndef vax11c`09/* Not supported under VMS */
X  UsingFD(fileno(stdin), ReadStdin);
X#endif /* vax11c */
X`7D
X
X/* ************************************************************ */
X/*`09`09`09`09`09`09`09`09*/
X/*`09`09`09`09`09`09`09`09*/
X/* ************************************************************ */
X
X/*
X  xscope is really meant to look at one client at a time.  However,
X  it can easily handle multiple clients and servers.  To do so,
X  we need to have a pair of FDs: one for the client and one for the
X  server for that client.  If either goes away, so does the other.
X  We need to be able to identify the other FD of a pair, so that if
X  we get input from one, we can write it to the other.
X*/
X
Xstruct fdinfo
X`7B
X  Boolean Server;
X  long    ClientNumber;
X  FD pair;
X`7D;
X
Xstatic long ClientNumber = 0;
X#ifdef vax11c
Xstatic struct fdinfo  *FDinfo = (struct fdinfo *)NULL;
X#else
Xstruct fdinfo   FDinfo`5BStaticMaxFD`5D;
X#endif /* vax11c */
X
XSetUpPair(client, server)
X     FD client;
X     FD server;
X`7B
X#ifdef vax11c
X  /*
X   *`09HACK ALERT!`09This is wasting to much memory, gotta to
X   *`09come back and clean this up.
X   */
X  if (!FDinfo) FDinfo = (struct fdinfo *) MyMalloc`20
X    `09`09((long)(MaxFD * sizeof (struct fdinfo)));
X#endif /* vax11c */
X  if (client >= 0)
X    `7B
X      ClientNumber += 1;
X      FDinfo`5Bclient`5D.Server = false;
X      FDinfo`5Bclient`5D.pair = server;
X      FDinfo`5Bclient`5D.ClientNumber = ClientNumber;
X      if (server >= 0)
X`09`7B
X`09  FDinfo`5Bserver`5D.Server = true;
X`09  FDinfo`5Bserver`5D.pair = client;
X`09  FDinfo`5Bserver`5D.ClientNumber = FDinfo`5Bclient`5D.ClientNumber;
X`09`7D
X    `7D
X  else if (server >= 0)
X      `7B
X`09socket_close(server);
X`09NotUsingFD(server);
X      `7D
X`7D
X
X
XCloseConnection(fd)
X     FD fd;
X`7B
X  debug(4,(stderr, "close %d and %d\n", fd, FDPair(fd)));
X  StopClientConnection(ServerHalf(fd));
X  StopServerConnection(ClientHalf(fd));
X
X  socket_close(fd);
X  NotUsingFD(fd);
X  socket_close(FDPair(fd));
X  NotUsingFD(FDPair(fd));
X`7D
X
X/* ************************************************************ */
X
XFD FDPair(fd)
X     FD fd;
X`7B
X  return(FDinfo`5Bfd`5D.pair);
X`7D
X
XFD ClientHalf(fd)
X     FD fd;
X`7B
X  if (FDinfo`5Bfd`5D.Server)
X    return(FDinfo`5Bfd`5D.pair);
X  return(fd);
X`7D
X
XFD ServerHalf(fd)
X     FD fd;
X`7B
X  if (FDinfo`5Bfd`5D.Server)
X    return(fd);
X  return(FDinfo`5Bfd`5D.pair);
X`7D
X
Xchar   *ClientName (fd)
X     FD fd;
X`7B
X  static char name`5B12`5D;
X
X  if (ClientNumber <= 1)
X    return("");
X  sprintf(name, " %d", FDinfo`5Bfd`5D.ClientNumber);
X  return(name);
X`7D
X
X
X/* ********************************************** */
X/*                                                */
X/* ********************************************** */
X
X/* when we get data from a client, we read it in, copy it to the
X   server for this client, then dump it to the client. Note, we don't
X   have to have a server, if there isn't one. */
X
XDataFromClient(fd)
X     FD fd;
X`7B
X  unsigned char    buf`5B2048`5D;
X  long    n;
X  FD ServerFD;
X
X  enterprocedure("DataFromClient");
X  n = read(fd, (char *)buf, 2048);
X  debug(4,(stderr, "read %d bytes from Client%s\n", n, ClientName(fd)));
X  if (n < 0)
X    `7B
X      PrintTime();
X      perror("Client --> read error:");
X      CloseConnection(fd);
X      return;
X    `7D
X  if (n == 0)
X    `7B
X      PrintTime();
X      fprintf(stdout, "Client%s --> EOF\n", ClientName(fd));
X      CloseConnection(fd);
X      return;
X    `7D
X
X  ServerFD = FDPair(fd);
X  if (ServerFD < 0)
X    `7B
X      ServerFD = ConnectToServer(false);
X      SetUpPair(fd, ServerFD);
X    `7D
X
X  /* write bytes from client to server, allow for server to fail */
X  if (ServerFD >= 0)
X    `7B
X      long    BytesToWrite = n;
X      unsigned char   *p = buf;
X
X      while (BytesToWrite > 0)
X`09`7B
X`09  int     n1 = write (ServerFD, (char *)p, (int)BytesToWrite);
X`09  debug(4,(stderr, "write %d bytes to Server%s\n", n1, ClientName(fd)));
X`09  if (n1 > 0)
X`09    `7B
X`09      BytesToWrite -= n1;
X`09      p += n1;
X`09    `7D
X`09  else
X`09    `7B
X`09`09`09    perror("Error on write to Server");
X`09      CloseConnection(fd);
X`09      BytesToWrite = 0;
X`09    `7D
X`09`7D
X    `7D
X
X  /* also report the bytes to standard out */
X  ReportFromClient(fd, buf, n);
X`7D
X
X/* ********************************************** */
X/*                                                */
X/* ********************************************** */
X
X/* similar situation for the server, but note that if there is no client,
X   we close the connection down -- don't need a server with no client. */
X
XDataFromServer(fd)
X     FD fd;
X`7B
X  unsigned char    buf`5B2048`5D;
X  long    n;
X  FD ClientFD;
X
X  enterprocedure("DataFromServer");
X  n = read(fd, (char *)buf, 2048);
X  debug(4,(stderr, "read %d bytes from Server%s\n", n, ClientName(fd)));
X  if (n < 0)
X    `7B
X      PrintTime();
X      perror("read error <- Server");
X      CloseConnection(fd);
X      return;
X    `7D
X  if (n == 0)
X    `7B
X      PrintTime();
X      fprintf(stdout, "EOF <-- Server%s\n", ClientName(fd));
X      CloseConnection(fd);
X      return;
X    `7D
X
X  ClientFD = FDPair(fd);
X  if (ClientFD < 0)
X    `7B
X      CloseConnection(fd);
X      return;
X    `7D
X
X  /* write bytes from server to client, allow for client to fail */
X  `7B
X    long    BytesToWrite = n;
X    unsigned char   *p = buf;
X    while (BytesToWrite > 0)
X      `7B
X`09int     n1 = write (ClientFD, (char *)p, (int)BytesToWrite);
X`09debug(4,(stderr, "write %d bytes to Client%s\n", n1, ClientName(fd)));
X`09if (n1 > 0)
X`09  `7B
X`09    BytesToWrite -= n1;
X`09    p += n1;
X`09  `7D
X`09else
X`09  `7B
X`09`09`09perror("Error on write to Client");
X`09    CloseConnection(fd);
X`09    BytesToWrite = 0;
X`09  `7D
X      `7D
X  `7D
X
X  /* also report the bytes to standard out */
X  ReportFromServer(fd, buf, n);
X`7D
X
X
X
X/* ************************************************************ */
X/*`09`09`09`09`09`09`09`09*/
X/*     Create New Connection to a client program and to Server  */
X/*`09`09`09`09`09`09`09`09*/
X/* ************************************************************ */
X
X#ifdef vax11c
X#ifdef MULTINET
X#include <sys$common/multinet/include/sys/types.h>`09       /* needed by sys
V/socket.h and netinet/in.h */
X#include <sys$common/multinet/include/sys/uio.h>`09       /* for struct iove
Vc, used by socket.h */
X#include <sys$common/multinet/include/sys/socket.h>`09       /* for AF_INET,
V SOCK_STREAM, ... */
X#include <sys$common/multinet/include/sys/ioctl.h>`09       /* for FIONCLEX,
V FIONBIO, ... */
X#include <sys$common/multinet/include/netinet/in.h>`09       /* struct socka
Vddr_in */
X#include <sys$common/multinet/include/netdb.h>`09       /* struct servent *
V and struct hostent * */
X#endif /* MULTINET */
X#include <errno.h>`09       /* for EINTR, EADDRINUSE, ... */
Xextern volatile int noshare errno;
X#else
X#include <sys/types.h>`09       /* needed by sys/socket.h and netinet/in.h *
V/
X#include <sys/uio.h>`09       /* for struct iovec, used by socket.h */
X#include <sys/socket.h>`09       /* for AF_INET, SOCK_STREAM, ... */
X#include <sys/ioctl.h>`09       /* for FIONCLEX, FIONBIO, ... */
X#include <netinet/in.h>`09       /* struct sockaddr_in */
X#include <netdb.h>`09       /* struct servent * and struct hostent * */
X#include <errno.h>`09       /* for EINTR, EADDRINUSE, ... */
Xextern int  errno;
X#endif /* vax11c */
X
Xstatic int  ON = 1 /* used in ioctl */ ;
X
XNewConnection(fd)
X     FD fd;
X`7B
X  FD ServerFD = -1;
X  FD ClientFD = -1;
X
X  ClientFD = ConnectToClient(fd);
X  ServerFD = ConnectToServer(true);
X  SetUpPair(ClientFD, ServerFD);
X`7D
X
X
X/* ************************************************************ */
X
XFD ConnectToClient(ConnectionSocket)
X     FD ConnectionSocket;
X`7B
X  FD ClientFD;
X  struct sockaddr_in  from;
X  int    len = sizeof (from);
X
X  enterprocedure("ConnectToClient");
X
X  ClientFD = accept(ConnectionSocket, (struct sockaddr *)&from, &len);
X  debug(4,(stderr, "Connect To Client: FD %d\n", ClientFD));
X  if (ClientFD < 0 && errno == EWOULDBLOCK)
X    `7B
X      debug(4,(stderr, "Almost blocked accepting FD %d\n", ClientFD));
X      panic("Can't connect to Client");
X    `7D
X  if (ClientFD < 0)
X    `7B
X      debug(4,(stderr, "NewConnection: error %d\n", errno));
X      panic("Can't connect to Client");
X    `7D
X
X  UsingFD(ClientFD, DataFromClient);
X#ifdef vax11c
X  /* socket_ioctl(ClientFD, FIOCLEX, 0); ! Not need since close on exit is d
Vef */
X  socket_ioctl(ClientFD, FIONBIO, &ON);
X#else
X  ioctl(ClientFD, FIOCLEX, 0);
X  ioctl(ClientFD, FIONBIO, &ON);
X#endif /* vax11c */
X  StartClientConnection(ClientFD);
X  return(ClientFD);
X`7D
X
X
X
X/* ************************************************************ */
X/*`09`09`09`09`09`09`09`09*/
X/*`09`09`09`09`09`09`09`09*/
X/* ************************************************************ */
X
X
X
XFD ConnectToServer(report)
X     Boolean report;
X`7B
X  FD ServerFD;
X  struct sockaddr_in  sin;
X  struct hostent *hp;
X  short port;
X#ifdef vax11c
X  unsigned long int On;
X#endif /* vax11c */
X
X  enterprocedure("ConnectToServer");
X
X  /* establish a socket to the name server for this host */
X  bzero((char *)&sin, sizeof(sin));
X  ServerFD = socket(AF_INET, SOCK_STREAM, 0);
X  if (ServerFD < 0)
X    `7B
X      perror("socket() to Server failed");
X      debug(1,(stderr, "socket failed\n"));
X      panic("Can't open connection to Server");
X    `7D
X#ifdef vax11c
X  On = 0;
X  if (setsockopt(ServerFD, SOL_SOCKET, SO_REUSEADDR,  &On, sizeof(On)) < 0)
V `7B
X`09socket_perror("SOCKOPT: REUSADDR");
X`09exit (-1);
X  `7D
X  if (setsockopt(ServerFD, SOL_SOCKET, SO_USELOOPBACK, &On, sizeof(On)) < 0)
V `7B
X`09socket_perror("SOCKOPT: USELOOPBACK");
X`09exit (-1);
X  `7D
X#ifdef SO_DONTLINGER
X  if (setsockopt(ServerFD, SOL_SOCKET, SO_DONTLINGER, (char *) NULL, 0) < 0)
V `7B
X`09socket_perror("SOCKOPT: DONTLINGER");
X`09exit (-1);
X  `7D
X#endif
X#else
X  (void) setsockopt(ServerFD, SOL_SOCKET, SO_REUSEADDR,  (char *) NULL, 0);
X  (void) setsockopt(ServerFD, SOL_SOCKET, SO_USELOOPBACK,(char *) NULL, 0);
X#ifdef SO_DONTLINGER
X  (void) setsockopt(ServerFD, SOL_SOCKET, SO_DONTLINGER, (char *) NULL, 0);
X#endif
X#endif /* vax11c */
X
X  /* determine the host machine for this process */
X  if (ServerHostName`5B0`5D == '\0')
X    (void) gethostname(ServerHostName, sizeof (ServerHostName));
X  debug(4,(stderr, "try to connect on %s\n", ServerHostName));
X
X  hp = gethostbyname(ServerHostName);
X  if (hp == 0)
X    `7B
X      perror("gethostbyname failed");
X      debug(1,(stderr, "gethostbyname failed for %s\n", ServerHostName));
X      panic("Can't open connection to Server");
X    `7D
X
X  sin.sin_family = AF_INET;
X  bcopy((char *)hp->h_addr, (char *)&sin.sin_addr, hp->h_length);
X  port = GetServerport ();
X
X  if (port == ScopePort
X      && strcmp(ServerHostName, ScopeHost) == 0)
X    `7B
X      char error_message`5B100`5D;
X      sprintf(error_message, "Trying to attach to myself: %s,%d\n",
X`09      ServerHostName, sin.sin_port);
X      panic(error_message);
X    `7D
X
X  sin.sin_port = htons (port);
X
X  /* ******************************************************** */
X  /* try to connect to Server */
X
X  if (connect(ServerFD, (struct sockaddr *)&sin, sizeof(sin)) < 0)
X    `7B
X      debug(4,(stderr, "connect returns errno of %d\n", errno));
X      if (errno != 0)
X`09if (report)
X`09  perror("connect");
X      switch (errno)
X`09`7B
X`09case ECONNREFUSED:
X`09  /* experience says this is because there is no Server
X`09     to connect to */
X`09  socket_close(ServerFD);
X`09  debug(1,(stderr, "No Server\n"));
X`09  if (report)
X`09    warn("Can't open connection to Server");
X`09  return(-1);
X
X`09default:
X`09  socket_close(ServerFD);
X`09  panic("Can't open connection to Server");
X`09`7D
X    `7D
X
X  debug(4,(stderr, "Connect To Server: FD %d\n", ServerFD));
X  if (ServerFD >= 0)
X    `7B
X      UsingFD(ServerFD, DataFromServer);
X      StartServerConnection(ServerFD);
X    `7D
X  return(ServerFD);
X`7D
X
X
X/* ********************************************** */
X/*                                                */
X/* ********************************************** */
X
Xchar *OfficialName(name)
Xchar *name;
X`7B
X  struct hostent *HostEntry;
X
X  HostEntry = gethostbyname(name);
X  if (HostEntry == NULL)
X    `7B
X      perror("gethostbyname");
X      exit(-1);
X    `7D
X  debug(4,(stderr, "Official name of %s is %s\n", name, HostEntry->h_name));
X  return(HostEntry->h_name);
X`7D
X
$ CALL UNPACK SCOPE.C;19 388685410
$ create 'f'
X/* **********************************************
X *`09`09`09`09`09`09*
X * header file for the Server spy scope           *
X *`09`09`09`09`09`09*
X *`09James Peterson, 1987`09`09`09*
X *`09(c) Copyright MCC, 1987 `09`09*
X *`09`09`09`09`09`09*
X ********************************************** */
X
X#include <stdio.h>
X#ifdef vax11c
X#include <string.h>
X#ifdef MULTINET
X#include <sys$common/multinet/include/sys/types.h>
X#endif /* MULTINET */
X#ifndef perror
X#define perror`09socket_perror
X#endif /* !perror */
X#ifdef read
X#undef read
X#endif /* read */
X#ifdef write
X#undef write
X#endif /* write */
X#define read`09socket_read
X#define write`09socket_write
X#else
X#define socket_close  close
X#endif /* vax11c */
X
X#define Boolean short
X#define true 1
X#define false 0
X
X/* ********************************************** */
X/*                                                */
X/* ********************************************** */
X
X#define Assert(b) (b)
X#define debug(n,f) (void)((debuglevel & n) ? (fprintf f,fflush(stderr)) : 0)
Xshort   debuglevel;
X
X/* ********************************************** */
X/*                                                */
X/* ********************************************** */
X
Xshort   Verbose`09`09  /* quiet (0) or increasingly verbose  ( > 0) */ ;
X
X
Xint     ScopePort;
Xchar   *ScopeHost;
X
X/* external function type declarations */
X
X#ifdef vax11c
Xextern char   *MyMalloc ();
X#else
Xextern char   *Malloc ();
Xextern char *strcpy();
Xextern char *sprintf();
X#endif /* vax11c */
Xchar   *ClientName ();
X
X/* ********************************************** */
X/*                                                */
X/* ********************************************** */
X
X/* need to change the MaxFD to allow larger number of fd's */
X#define StaticMaxFD 32
X
X
X#include "fd.h"
$ CALL UNPACK SCOPE.H;8 1627813533
$ create 'f'
X/* ************************************************** *
X *`09`09`09`09`09`09      *
X *  Code to decode and print X11 protocol`09      *
X *`09`09`09`09`09`09      *
X *`09James Peterson, 1988`09`09`09      *
X *`09(c) Copyright MCC, 1988 `09`09      *
X *`09`09`09`09`09`09      *
X * ************************************************** */
X
X#if defined(vax11c) && !defined(MULTINET)
X#include "emulationlib.h"
X#endif
X
X#include "scope.h"
X#include "x11.h"
X
X#ifdef vax11c`09/* allocate storage for this information (shameful waste) */
X/* ************************************************************ */
X/*`09`09`09`09`09`09`09`09*/
X/*`09`09`09`09`09`09`09`09*/
X/* ************************************************************ */
X
XInitializeCS()
X`7B
X`09register int i;
X
X`09enterprocedure("InitializeCS");
X`09/*
X `09 *`09HACK! Must come back and fix this.  Should allocate all this
X `09 *`09memory if I'm not going to use it.
X `09 */
X `09if (CS == NULL)
X`09`09CS = (struct ConnState *)
X`09`09MyMalloc((long)(MaxFD * sizeof (struct ConnState)));
X
X`09/* initialize it */
X
X`09for (i = 0; i < MaxFD; i++) `7B
X`09`09CS`5Bi`5D.SavedBytes = NULL;
X`09`09CS`5Bi`5D.littleEndian = 0;
X`09`09CS`5Bi`5D.SizeofSavedBytes = 0;
X`09`09CS`5Bi`5D.NumberofSavedBytes = 0;
X`09`09CS`5Bi`5D.NumberofBytesNeeded = 0;
X`09`09CS`5Bi`5D.ByteProcessing = (long *)NULL;
X`09`09CS`5Bi`5D.SequenceNumber = 0;
X`09`7D
X`7D
X#endif /* vax11c
X
X/* ************************************************************ */
X/*`09`09`09`09`09`09`09`09*/
X/*`09`09`09`09`09`09`09`09*/
X/* ************************************************************ */
X
XReportFromClient(fd, buf, n)
X     FD fd;
X     unsigned char *buf;
X     long    n;
X`7B
X  PrintTime();
X  fprintf(stdout, "Client%s --> %4d %s\n",
X`09  ClientName(fd), n, (n == 1 ? "byte" : "bytes"));
X  ProcessBuffer(fd, buf, n);
X`7D
X
XReportFromServer(fd, buf, n)
X     FD fd;
X     unsigned char *buf;
X     long    n;
X`7B
X  PrintTime();
X  fprintf(stdout, "\t\t\t\t\t%4d %s <-- X11 Server%s\n",
X`09  n, (n == 1 ? "byte" : "bytes"), ClientName(fd));
X  ProcessBuffer(fd, buf, n);
X`7D
X
X
X/* ************************************************************ */
X/*`09`09`09`09`09`09`09`09*/
X/*`09`09`09`09`09`09`09`09*/
X/* ************************************************************ */
X
X#ifdef vax11c
X#ifdef MULTINET
X#include <sys$common/multinet/include/sys/time.h>
X#endif /* MULTINET */
X#else
X#include <sys/time.h>`09       /* for struct timeval * */
X#endif /* vax11c */
Xstatic long ZeroTime1 = -1;
Xstatic long ZeroTime2 = -1;
Xstatic struct timeval   tp;
X
X/* print the time since we started in hundredths (1/100) of seconds */
X
XPrintTime()
X`7B
X  static long lastsec = 0;
X  long    sec /* seconds */ ;
X  long    hsec /* hundredths of a second */ ;
X
X  gettimeofday(&tp, (struct timezone *)NULL);
X  if (ZeroTime1 == -1 `7C`7C (tp.tv_sec - lastsec) >= 1000)
X    `7B
X      ZeroTime1 = tp.tv_sec;
X      ZeroTime2 = tp.tv_usec / 10000;
X    `7D
X
X  lastsec = tp.tv_sec;
+-+-+-+-+-+-+-+-  END  OF PART 6 +-+-+-+-+-+-+-+-
--
Patrick L. Mahan

--- TGV Window Washer ------------------------------- Mahan@TGV.COM ---------

Waking a person unnecessarily should not be considered  - Lazarus Long
a capital crime.  For a first offense, that is            From the Notebooks of
							  Lazarus Long
Technical Details
Message-ID: <8045409@MVB.SAIC.COM>
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!cs.utexas.edu!rutgers!network.ucsd.edu!mvb.saic.com!vmsnet-sources

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!cs.utexas.edu!rutgers!network.ucsd.edu!mvb.saic.com!vmsnet-sources
From: mahan@tgv.com (Patrick L. Mahan - TGV Window Washer)
Newsgroups: vmsnet.sources
Subject: XSCOPE/VMS 1.0, part 06/08
Message-ID: <8045409@MVB.SAIC.COM>
Date: 4 Sep 92 05:34:33 GMT
Reply-To: mahan@tgv.com
Organization: TGV Incorporated (Tech Support) in Santa Cruz, CA
Lines: 1807
Approved: Mark.Berryman@Mvb.Saic.Com