home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / vmsnet / sources / 353 < prev    next >
Encoding:
Internet Message Format  |  1992-09-03  |  47.2 KB

  1. Path: sparky!uunet!sun-barr!cs.utexas.edu!rutgers!network.ucsd.edu!mvb.saic.com!vmsnet-sources
  2. From: mahan@tgv.com (Patrick L. Mahan - TGV Window Washer)
  3. Newsgroups: vmsnet.sources
  4. Subject: XSCOPE/VMS 1.0, part 06/08
  5. Message-ID: <8045409@MVB.SAIC.COM>
  6. Date: 4 Sep 92 05:34:33 GMT
  7. Reply-To: mahan@tgv.com
  8. Organization: TGV Incorporated (Tech Support) in Santa Cruz, CA
  9. Lines: 1807
  10. Approved: Mark.Berryman@Mvb.Saic.Com
  11.  
  12. Submitted-by: mahan@tgv.com (Patrick L. Mahan - TGV Window Washer)
  13. Posting-number: Volume 3, Issue 158
  14. Archive-name: xscope/part06
  15.  
  16.  
  17. -+-+-+-+-+-+-+-+ START OF PART 6 -+-+-+-+-+-+-+-+
  18. X    fprintf(stdout, "None");
  19. X  else
  20. X    fprintf(stdout, "WIN %08x", n);
  21. X  return(4);
  22. X`7D
  23. X
  24. XPrintWINDOWD(buf)
  25. X     unsigned char *buf;
  26. X`7B
  27. X  /* print a WINDOWD -- CARD32  plus 0 = PointerWindow, 1 = InputFocus */
  28. X  long    n = ILong (buf);
  29. X  if (n == 0)
  30. X    fprintf(stdout, "PointerWindow");
  31. X  else if (n == 1)
  32. X      fprintf(stdout, "InputFocus");
  33. X    else
  34. X      PrintWINDOW(buf);
  35. X`7D
  36. X
  37. XPrintWINDOWNR(buf)
  38. X     unsigned char *buf;
  39. X`7B
  40. X  /* print a WINDOWNR -- CARD32  plus 0 = None, 1 = PointerRoot */
  41. X  long    n = ILong (buf);
  42. X  if (n == 0)
  43. X    fprintf(stdout, "None");
  44. X  else if (n == 1)
  45. X      fprintf(stdout, "PointerRoot");
  46. X    else
  47. X      PrintWINDOW(buf);
  48. X`7D
  49. X
  50. X
  51. XPrintPIXMAP(buf)
  52. X     unsigned char *buf;
  53. X`7B
  54. X  /* print a PIXMAP -- CARD32  plus 0 = None */
  55. X  long    n = ILong (buf);
  56. X  if (n == 0)
  57. X    fprintf(stdout, "None");
  58. X  else
  59. X    fprintf(stdout, "PXM %08x", n);
  60. X`7D
  61. X
  62. XPrintPIXMAPNPR(buf)
  63. X     unsigned char *buf;
  64. X`7B
  65. X  /* print a PIXMAPNPR -- CARD32  plus 0 = None, 1 = ParentRelative */
  66. X  long    n = ILong (buf);
  67. X  if (n == 0)
  68. X    fprintf(stdout, "None");
  69. X  else if (n == 1)
  70. X      fprintf(stdout, "ParentRelative");
  71. X    else
  72. X      PrintPIXMAP(buf);
  73. X`7D
  74. X
  75. XPrintPIXMAPC(buf)
  76. X     unsigned char *buf;
  77. X`7B
  78. X  /* print a PIXMAPC -- CARD32  plus 0 = CopyFromParent */
  79. X  long    n = ILong (buf);
  80. X  if (n == 0)
  81. X    fprintf(stdout, "CopyFromParent");
  82. X  else
  83. X    PrintPIXMAP(buf);
  84. X`7D
  85. X
  86. X
  87. XPrintCURSOR(buf)
  88. X     unsigned char *buf;
  89. X`7B
  90. X  /* print a CURSOR -- CARD32  plus 0 = None */
  91. X  long    n = ILong (buf);
  92. X  if (n == 0)
  93. X    fprintf(stdout, "None");
  94. X  else
  95. X    fprintf(stdout, "CUR %08x", n);
  96. X`7D
  97. X
  98. X
  99. XPrintFONT(buf)
  100. X     unsigned char *buf;
  101. X`7B
  102. X  /* print a FONT -- CARD32  plus 0 = None */
  103. X  long    n = ILong (buf);
  104. X  if (n == 0)
  105. X    fprintf(stdout, "None");
  106. X  else
  107. X    fprintf(stdout, "FNT %08x", n);
  108. X`7D
  109. X
  110. X
  111. XPrintGCONTEXT(buf)
  112. X     unsigned char *buf;
  113. X`7B
  114. X  /* print a GCONTEXT -- CARD32 */
  115. X  long    n = ILong (buf);
  116. X  fprintf(stdout, "GXC %08x", n);
  117. X`7D
  118. X
  119. X
  120. XPrintCOLORMAP(buf)
  121. X     unsigned char *buf;
  122. X`7B
  123. X  /* print a COLORMAP -- CARD32 plus 0 = None */
  124. X  long    n = ILong (buf);
  125. X  if (n == 0)
  126. X    fprintf(stdout, "None");
  127. X  else
  128. X    fprintf(stdout, "CMP %08x", n);
  129. X  return(4);
  130. X`7D
  131. X
  132. XPrintCOLORMAPC(buf)
  133. X     unsigned char *buf;
  134. X`7B
  135. X  /* print a COLORMAPC -- CARD32 plus 0 = CopyFromParent */
  136. X  long    n = ILong (buf);
  137. X  if (n == 0)
  138. X    fprintf(stdout, "CopyFromParent");
  139. X  else
  140. X    PrintCOLORMAP(buf);
  141. X`7D
  142. X
  143. X
  144. XPrintDRAWABLE(buf)
  145. X     unsigned char *buf;
  146. X`7B
  147. X  /* print a DRAWABLE -- CARD32 */
  148. X  long    n = ILong (buf);
  149. X  fprintf(stdout, "DWB %08x", n);
  150. X`7D
  151. X
  152. XPrintFONTABLE(buf)
  153. X     unsigned char *buf;
  154. X`7B
  155. X  /* print a FONTABLE -- CARD32 */
  156. X  long    n = ILong (buf);
  157. X  fprintf(stdout, "FTB %08x", n);
  158. X`7D
  159. X
  160. X/* ************************************************************ */
  161. X
  162. X#define NumberofAtoms 68
  163. X
  164. Xchar   *AtomTable`5BNumberofAtoms + 1`5D =
  165. X`7B
  166. X  "NONE", "PRIMARY", "SECONDARY", "ARC", "ATOM", "BITMAP", "CARDINAL",
  167. X  "COLORMAP", "CURSOR", "CUT_BUFFER0", "CUT_BUFFER1", "CUT_BUFFER2",
  168. X  "CUT_BUFFER3", "CUT_BUFFER4", "CUT_BUFFER5", "CUT_BUFFER6",
  169. X  "CUT_BUFFER7", "DRAWABLE", "FONT", "INTEGER", "PIXMAP", "POINT",
  170. X  "RECTANGLE", "RESOURCE_MANAGER", "RGB_COLOR_MAP", "RGB_BEST_MAP",
  171. X  "RGB_BLUE_MAP", "RGB_DEFAULT_MAP", "RGB_GRAY_MAP", "RGB_GREEN_MAP",
  172. X  "RGB_RED_MAP", "STRING", "VISUALID", "WINDOW", "WM_COMMAND",
  173. X  "WM_HINTS", "WM_CLIENT_MACHINE", "WM_ICON_NAME", "WM_ICON_SIZE",
  174. X  "WM_NAME", "WM_NORMAL_HINTS", "WM_SIZE_HINTS", "WM_ZOOM_HINTS",
  175. X  "MIN_SPACE", "NORM_SPACE", "MAX_SPACE", "END_SPACE", "SUPERSCRIPT_X",
  176. X  "SUPERSCRIPT_Y", "SUBSCRIPT_X", "SUBSCRIPT_Y", "UNDERLINE_POSITION",
  177. X  "UNDERLINE_THICKNESS", "STRIKEOUT_ASCENT", "STRIKEOUT_DESCENT",
  178. X  "ITALIC_ANGLE", "X_HEIGHT", "QUAD_WIDTH", "WEIGHT", "POINT_SIZE",
  179. X  "RESOLUTION", "COPYRIGHT", "NOTICE", "FONT_NAME", "FAMILY_NAME",
  180. X  "FULL_NAME", "CAP_HEIGHT", "WM_CLASS", "WM_TRANSIENT_FOR"
  181. X  `7D;
  182. X
  183. X/* for atoms, we print the built-in atoms.  We could expand to printing
  184. X   the user defined ones, too. */
  185. X
  186. XPrintATOM(buf)
  187. X     unsigned char *buf;
  188. X`7B
  189. X  /* print a ATOM -- CARD32 plus 0 = None */
  190. X  long    n = ILong (buf);
  191. X  if (0 <= n && n <= NumberofAtoms)
  192. X    fprintf(stdout, "<%s>", AtomTable`5Bn`5D);
  193. X  else
  194. X    fprintf(stdout, "ATM %08x", n);
  195. X  return(4);
  196. X`7D
  197. X
  198. XPrintATOMT(buf)
  199. X     unsigned char *buf;
  200. X`7B
  201. X  /* print a ATOMT -- CARD32 plus 0 = AnyPropertyType */
  202. X  long    n = ILong (buf);
  203. X  if (n == 0)
  204. X    fprintf(stdout, "AnyPropertyType");
  205. X  else
  206. X    PrintATOM(buf);
  207. X`7D
  208. X
  209. X
  210. XPrintVISUALID(buf)
  211. X     unsigned char *buf;
  212. X`7B
  213. X  /* print a VISUALID -- CARD32 plus 0 = None */
  214. X  long    n = ILong (buf);
  215. X  if (n == 0)
  216. X    fprintf(stdout, "None");
  217. X  else
  218. X    fprintf(stdout, "VIS %08x", n);
  219. X`7D
  220. X
  221. XPrintVISUALIDC(buf)
  222. X     unsigned char *buf;
  223. X`7B
  224. X  /* print a VISUALIDC -- CARD32 plus 0 = CopyFromParent */
  225. X  long    n = ILong (buf);
  226. X  if (n == 0)
  227. X    fprintf(stdout, "CopyFromParent");
  228. X  else
  229. X    PrintVISUALID(buf);
  230. X`7D
  231. X
  232. X
  233. XPrintTIMESTAMP(buf)
  234. X     unsigned char *buf;
  235. X`7B
  236. X  /* print a TIMESTAMP -- CARD32 plus 0 as the current time */
  237. X  long    n = ILong (buf);
  238. X  if (n == 0)
  239. X    fprintf(stdout, "CurrentTime");
  240. X  else
  241. X    fprintf(stdout, "TIM %08x", n);
  242. X`7D
  243. X
  244. X
  245. XPrintRESOURCEID(buf)
  246. X     unsigned char *buf;
  247. X`7B
  248. X  /* print a RESOURCEID -- CARD32 plus 0 = AllTemporary */
  249. X  long    n = ILong (buf);
  250. X  if (n == 0)
  251. X    fprintf(stdout, "AllTemporary");
  252. X  else
  253. X    fprintf(stdout, "RID %08x", n);
  254. X`7D
  255. X
  256. X
  257. XPrintKEYSYM(buf)
  258. X     unsigned char *buf;
  259. X`7B
  260. X  /* print a KEYSYM -- CARD32 */
  261. X  long    n = ILong (buf);
  262. X  fprintf(stdout, "KYS %08x", n);
  263. X  return(4);
  264. X`7D
  265. X
  266. XPrintKEYCODE(buf)
  267. X     unsigned char *buf;
  268. X`7B
  269. X  /* print a KEYCODE -- CARD8 */
  270. X  unsigned short n = IByte (buf);
  271. X  fprintf(stdout, "%d (%s)", n, printrep(n));
  272. X  return(1);
  273. X`7D
  274. X
  275. XPrintKEYCODEA(buf)
  276. X     unsigned char *buf;
  277. X`7B
  278. X  /* print a KEYCODEA -- CARD8 plus 0 = AnyKey */
  279. X  long    n = IByte (buf);
  280. X  if (n == 0)
  281. X    fprintf(stdout, "AnyKey");
  282. X  else
  283. X    PrintKEYCODE(buf);
  284. X`7D
  285. X
  286. X
  287. XPrintBUTTON(buf)
  288. X     unsigned char *buf;
  289. X`7B
  290. X  /* print a BUTTON -- CARD8 */
  291. X  unsigned short n = IByte (buf);
  292. X  fprintf(stdout, "%d (%s)", n, printrep(n));
  293. X`7D
  294. X
  295. XPrintBUTTONA(buf)
  296. X     unsigned char *buf;
  297. X`7B
  298. X  /* print a BUTTONA -- CARD8 plus 0 = AnyButton */
  299. X  long    n = IByte (buf);
  300. X  if (n == 0)
  301. X    fprintf(stdout, "AnyButton");
  302. X  else
  303. X    PrintBUTTON(buf);
  304. X`7D
  305. X
  306. X
  307. X/* this is an interesting cheat -- we call DecodeEvent to print an event */
  308. X/* should work, but its never been tried */
  309. XPrintEVENTFORM(buf)
  310. X     unsigned char *buf;
  311. X`7B
  312. X  /* print an EVENT_FORM -- event format */
  313. X  DecodeEvent(-1, buf, (long)-1);
  314. X`7D
  315. X
  316. X/* ************************************************************ */
  317. X
  318. XPrintENUMERATED(buf, length, ValueList)
  319. X     unsigned char *buf;
  320. X     short   length;
  321. X     struct ValueListEntry  *ValueList;
  322. X`7B
  323. X  long   n;
  324. X  struct ValueListEntry  *p;
  325. X
  326. X  if (length == 1)
  327. X    n = IByte(buf);
  328. X  else if (length == 2)
  329. X      n = IShort(buf);
  330. X    else
  331. X      n = ILong(buf);
  332. X
  333. X  p = ValueList;
  334. X  while (p != NULL && p->Value != n)
  335. X    p = p->Next;
  336. X
  337. X  if (p != NULL)
  338. X    fprintf(stdout, "%s", p->Name);
  339. X  else
  340. X    fprintf(stdout, "**INVALID** (%d)", n);
  341. X`7D
  342. X
  343. X/* ************************************************************ */
  344. X
  345. XPrintSET(buf, length, ValueList)
  346. X     unsigned char *buf;
  347. X     short   length;
  348. X     struct ValueListEntry  *ValueList;
  349. X`7B
  350. X  unsigned long   n;
  351. X  struct ValueListEntry  *p;
  352. X  Boolean MatchesAll = false;
  353. X  Boolean FoundOne = false;
  354. X
  355. X  if (length == 1)
  356. X    n = IByte(buf);
  357. X  else if (length == 2)
  358. X      n = IShort(buf);
  359. X    else
  360. X      n = ILong(buf);
  361. X
  362. X  if (n != 0)
  363. X    `7B
  364. X      /* first check if the value matches ALL of the bits. */
  365. X      MatchesAll = true;
  366. X      for (p = ValueList; MatchesAll && (p != NULL); p = p->Next)
  367. X`09`7B
  368. X`09  if ((p->Value & n) == 0)
  369. X`09      MatchesAll = false;
  370. X`09`7D
  371. X
  372. X      if (!MatchesAll)
  373. X`09/* if it matches some, but not all, print only those it matches */
  374. X`09for (p = ValueList; p != NULL; p = p->Next)
  375. X`09  `7B
  376. X`09    if ((p->Value & n) != 0)
  377. X`09      `7B
  378. X`09`09if (FoundOne)
  379. X`09`09  fprintf(stdout, " `7C ");
  380. X`09`09fprintf(stdout, "%s", p->Name);
  381. X`09`09FoundOne = true;
  382. X`09      `7D
  383. X`09  `7D
  384. X    `7D
  385. X
  386. X  if (MatchesAll)
  387. X    fprintf(stdout, "<ALL>");
  388. X  else if (!FoundOne)
  389. X    fprintf(stdout, "0");
  390. X`7D
  391. X
  392. X
  393. X/* ************************************************************ */
  394. X/*`09`09`09`09`09`09`09`09*/
  395. X/*`09`09`09`09`09`09`09`09*/
  396. X/* ************************************************************ */
  397. X
  398. XPrintField(buf, start, length, FieldType, name)
  399. X     unsigned char *buf;
  400. X     short   start;
  401. X     short   length;
  402. X     short   FieldType;
  403. X     char   *name;
  404. X`7B
  405. X  if (length == 0)
  406. X    return;
  407. X
  408. X  fprintf(stdout, "%s%20s: ", Leader, name);
  409. X
  410. X  if (debuglevel & 8)
  411. X    DumpHexBuffer(&(buf`5Bstart`5D), (long)length);
  412. X
  413. X  switch (TD`5BFieldType`5D.Type)
  414. X    `7B
  415. X`09  case BUILTIN:
  416. X`09`09 (*TD`5BFieldType`5D.PrintProc)(&buf`5Bstart`5D);
  417. X`09`09 break;
  418. X
  419. X`09  case ENUMERATED:
  420. X`09`09 PrintENUMERATED(&buf`5Bstart`5D, length, TD`5BFieldType`5D.ValueList)
  421. V;
  422. X`09`09 break;
  423. X
  424. X`09  case SET:
  425. X`09`09 PrintSET(&buf`5Bstart`5D, length, TD`5BFieldType`5D.ValueList);
  426. X`09`09 break;
  427. X
  428. X`09  case RECORD:
  429. X`09`09 ModifyIndentLevel(1);
  430. X`09`09 fprintf(stdout, "\n");
  431. X`09`09 if (Verbose < 3)
  432. X`09`09   return;
  433. X`09`09 (*TD`5BFieldType`5D.PrintProc)(&buf`5Bstart`5D);
  434. X`09`09 ModifyIndentLevel(-1);
  435. X`09`09 break;
  436. X    `7D
  437. X  fprintf(stdout, "\n");
  438. X  fflush(stdout);
  439. X`7D
  440. X
  441. X/* ************************************************************ */
  442. X/*`09`09`09`09`09`09`09`09*/
  443. X/*`09`09`09`09`09`09`09`09*/
  444. X/* ************************************************************ */
  445. X
  446. X/* print a list of things.  The things are of type <ListType>.
  447. X   They start at <buf>.  There are <number> things in the list */
  448. X
  449. Xlong PrintList(buf, number, ListType, name)
  450. X     unsigned char *buf;
  451. X     long   number;
  452. X     short   ListType;
  453. X     char   *name;
  454. X`7B
  455. X  long    n;
  456. X  long    i;
  457. X  long    sum;
  458. X
  459. X  if (number == 0)
  460. X    return(0);
  461. X
  462. X  fprintf(stdout, "%s%20s: (%d)\n", Leader, name, number);
  463. X  if (Verbose < 2)
  464. X    return(0);
  465. X
  466. X  ModifyIndentLevel(1);
  467. X  sum = 0;
  468. X  for (i = 0; i < number; i++)
  469. X    `7B
  470. X      switch (TD`5BListType`5D.Type)
  471. X`09`7B
  472. X`09`09    case BUILTIN:
  473. X`09`09`09    n = (*TD`5BListType`5D.PrintProc)(buf);
  474. X`09`09`09    break;
  475. X`09`09    case RECORD:
  476. X`09`09`09    n = (*TD`5BListType`5D.PrintProc)(buf);
  477. X`09`09`09    break;
  478. X`09`09    default:
  479. X`09`09`09    fprintf(stdout, "**INVALID**");
  480. X`09`09`09    n = 0;
  481. X`09`09`09    break;
  482. X`09`7D
  483. X      buf = buf + n;
  484. X      sum = sum + n;
  485. X      fprintf(stdout, "%s---\n", Leader);
  486. X    `7D
  487. X
  488. X  ModifyIndentLevel(-1);
  489. X  return(sum);
  490. X`7D
  491. X
  492. X/* ************************************************************ */
  493. X/*`09`09`09`09`09`09`09`09*/
  494. X/*`09`09`09`09`09`09`09`09*/
  495. X/* ************************************************************ */
  496. X
  497. X/* print a list of STRs.  Similar to PrintList
  498. X   They start at <buf>.  There are <number> things in the list */
  499. X
  500. Xlong PrintListSTR(buf, number, name)
  501. X     unsigned char *buf;
  502. X     long   number;
  503. X     char   *name;
  504. X`7B
  505. X  long    n;
  506. X  long    i;
  507. X  long    sum;
  508. X
  509. X  if (number == 0)
  510. X    return(0);
  511. X
  512. X  fprintf(stdout, "%s%20s: (%d)\n", Leader, name, number);
  513. X  if (Verbose < 2)
  514. X    return(0);
  515. X
  516. X  ModifyIndentLevel(1);
  517. X  sum = 0;
  518. X  for (i = 0; i < number; i++)
  519. X    `7B
  520. X      fprintf(stdout, "%s", Leader);
  521. X      n = PrintSTR(buf);
  522. X      buf = buf + n;
  523. X      sum = sum + n;
  524. X      fprintf(stdout, "\n");
  525. X    `7D
  526. X
  527. X  ModifyIndentLevel(-1);
  528. X  return(sum);
  529. X`7D
  530. X
  531. X
  532. X/* ************************************************************ */
  533. X/*`09`09`09`09`09`09`09`09*/
  534. X/*`09`09`09`09`09`09`09`09*/
  535. X/* ************************************************************ */
  536. X
  537. X
  538. XPrintBytes(buf, number, name)
  539. X     unsigned char   buf`5B`5D;
  540. X     long   number;
  541. X     char   *name;
  542. X`7B
  543. X  /* print a list of BYTE -- 8-bit character */
  544. X  long   i;
  545. X  short   column;
  546. X
  547. X  if (number == 0)
  548. X    return(0);
  549. X
  550. X  fprintf(stdout, "%s%20s: ", Leader, name);
  551. X  column = SizeofLeader() + 25;
  552. X  for (i = 0; i < number; i++)
  553. X    `7B
  554. X      if (column > 80)
  555. X`09`7B
  556. X`09  if (Verbose < 2)
  557. X`09    break;
  558. X`09  fprintf(stdout, "\n%s%20s: ", Leader, "");
  559. X`09  column = SizeofLeader() + 25;
  560. X`09`7D
  561. X      fprintf(stdout, "%02x ",((unsigned int) buf`5Bi`5D));
  562. X      column += 3;
  563. X    `7D
  564. X  fprintf(stdout, "\n");
  565. X
  566. X  return(number);
  567. X`7D
  568. X
  569. X
  570. X/* ************************************************************ */
  571. X/*`09`09`09`09`09`09`09`09*/
  572. X/*`09`09`09`09`09`09`09`09*/
  573. X/* ************************************************************ */
  574. X
  575. X
  576. X/* print a String of CHAR8 -- 8-bit characters */
  577. X
  578. XPrintString8(buf, number, name)
  579. X     unsigned char    buf`5B`5D;
  580. X     short   number;
  581. X     char   *name;
  582. X`7B
  583. X  short   i;
  584. X
  585. X  if (number == 0)
  586. X    return(0);
  587. X
  588. X  fprintf(stdout, "%s%20s: \"", Leader, name);
  589. X  for (i = 0; i < number; i++)
  590. X    fprintf(stdout, "%s", printrep(buf`5Bi`5D));
  591. X  fprintf(stdout, "\"\n");
  592. X
  593. X  return(number);
  594. X`7D
  595. X
  596. X
  597. X/* print a String of CHAR16 -- 16-bit characters */
  598. X
  599. XPrintString16(buf, number, name)
  600. X     unsigned char    buf`5B`5D;
  601. X     short   number;
  602. X     char   *name;
  603. X`7B
  604. X  short   i;
  605. X  unsigned short   c;
  606. X
  607. X  if (number == 0)
  608. X    return(0);
  609. X
  610. X  fprintf(stdout, "%s%20s: \"", Leader, name);
  611. X  for (i = 0; i < number; i += 2)
  612. X    `7B
  613. X      c = IShort(&buf`5Bi`5D);
  614. X      fprintf(stdout, "%s", printrep(c));
  615. X    `7D
  616. X  fprintf(stdout, "\"\n");
  617. X
  618. X  return(number);
  619. X`7D
  620. X
  621. X/* ************************************************************ */
  622. X/*`09`09`09`09`09`09`09`09*/
  623. X/*`09`09`09`09`09`09`09`09*/
  624. X/* ************************************************************ */
  625. X
  626. X/*
  627. X  A Value List is two things:
  628. X
  629. X  (1) A controlling bitmask.  For each one bit in the control,
  630. X  a value is in the list.
  631. X  (2) A list of values.
  632. X*/
  633. X
  634. XPrintValues(control, clength, ctype, values, name)
  635. X     unsigned char   *control;
  636. X     short   clength;
  637. X     short   ctype;
  638. X     unsigned char   *values;
  639. X     char   *name;
  640. X`7B
  641. X  long    cmask;
  642. X  struct ValueListEntry  *p;
  643. X
  644. X  /* first get the control mask */
  645. X  if (clength == 1)
  646. X    cmask = IByte(control);
  647. X  else if (clength == 2)
  648. X      cmask = IShort(control);
  649. X    else
  650. X      cmask = ILong(control);
  651. X
  652. X  /* now if it is zero, ignore and return */
  653. X  if (cmask == 0)
  654. X    return;
  655. X
  656. X  /* there are bits in the controlling bitmask, figure out which */
  657. X  /* the ctype is a set type, so this code is similar to PrintSET */
  658. X  fprintf(stdout, "%s%20s:\n", Leader, name);
  659. X  ModifyIndentLevel(1);
  660. X  for (p = TD`5Bctype`5D.ValueList; p != NULL; p = p->Next)
  661. X    `7B
  662. X      if ((p->Value & cmask) != 0)
  663. X`09`7B
  664. X`09  short   m = 4 - p->Length;
  665. X`09  PrintField(values, m, p->Length, p->Type, p->Name);
  666. X`09  values += 4;
  667. X`09`7D
  668. X    `7D
  669. X  ModifyIndentLevel(-1);
  670. X`7D
  671. X
  672. X
  673. X/* ************************************************************ */
  674. X/*`09`09`09`09`09`09`09`09*/
  675. X/*`09`09`09`09`09`09`09`09*/
  676. X/* ************************************************************ */
  677. X
  678. X/* PolyText8 and PolyText16 take lists of characters with possible
  679. X   font changes in them. */
  680. X
  681. XPrintTextList8(buf, length, name)
  682. X     unsigned char *buf;
  683. X     short   length;
  684. X     char   *name;
  685. X`7B
  686. X  short   n;
  687. X
  688. X  fprintf(stdout, "%s%20s:\n", Leader, name);
  689. X  while (length > 1)
  690. X    `7B
  691. X      n = IByte(&buf`5B0`5D);
  692. X      if (n != 255)
  693. X`09`7B
  694. X`09  PrintField(buf, 1, 1, INT8, "delta");
  695. X`09  PrintString8(&buf`5B2`5D, n, "text item 8 string");
  696. X`09  buf += n + 2;
  697. X`09  length -= n + 2;
  698. X`09`7D
  699. X      else
  700. X`09`7B
  701. X`09  PrintField(buf, 1, 4, FONT, "font-shift-id");
  702. X`09  buf += 4;
  703. X`09  length -= 4;
  704. X`09`7D
  705. X    `7D
  706. X`7D
  707. X
  708. XPrintTextList16(buf, length, name)
  709. X     unsigned char *buf;
  710. X     short   length;
  711. X     char   *name;
  712. X`7B
  713. X  short   n;
  714. X
  715. X  fprintf(stdout, "%s%20s:\n", Leader, name);
  716. X  while (length > 1)
  717. X    `7B
  718. X      n = IByte(&buf`5B0`5D);
  719. X      if (n != 255)
  720. X`09`7B
  721. X`09  PrintField(buf, 1, 1, INT8, "delta");
  722. X`09  PrintString16(&buf`5B2`5D, n, "text item 16 string");
  723. X`09  buf += n + 2;
  724. X`09  length -= n + 2;
  725. X`09`7D
  726. X      else
  727. X`09`7B
  728. X`09  PrintField(buf, 1, 4, FONT, "font-shift-id");
  729. X`09  buf += 4;
  730. X`09  length -= 4;
  731. X`09`7D
  732. X    `7D
  733. X`7D
  734. X
  735. X
  736. X/* ************************************************************ */
  737. X/*`09`09`09`09`09`09`09`09*/
  738. X/*`09`09`09`09`09`09`09`09*/
  739. X/* ************************************************************ */
  740. X
  741. X#define MAXline 78
  742. X
  743. XDumpHexBuffer(buf, n)
  744. X     unsigned char *buf;
  745. X     long    n;
  746. X`7B
  747. X  short   i;
  748. X  short   column;
  749. X  char    h`5B6`5D /* one hex or octal character */ ;
  750. X
  751. X  column = 27 + SizeofLeader();
  752. X  for (i = 0; i < n; i++)
  753. X    `7B
  754. X      /* get the hex representations */
  755. X      sprintf(h, "%02x",(0xff & buf`5Bi`5D));
  756. X
  757. X      /* check if these characters will fit on this line */
  758. X      if ((column + strlen(h) + 1) > MAXline)
  759. X`09`7B
  760. X`09  /* line will be too long -- print it */
  761. X`09  fprintf(stdout, "\n");
  762. X`09  column = 0;
  763. X`09`7D
  764. X      fprintf(stdout, "%s ", h);
  765. X      column += 3;
  766. X    `7D
  767. X`7D
  768. $ CALL UNPACK PRTYPE.C;10 1148940676
  769. $ create 'f'
  770. X
  771. X`09XSCOPE -- a program to monitor X11/Client conversations
  772. X
  773. XXSCOPE is a program to monitor the connections between the X11 window
  774. Xserver and a client program.  xscope runs as a separate process.  By
  775. Xadjusting the host and/or display number that a X11 client attaches
  776. Xto, the client is attached to xscope instead of X11.  xscope attaches
  777. Xto X11 as if it were the client.  All bytes from the client are sent
  778. Xto xscope which passes them on to X11; All bytes from X11 are sent to
  779. Xxscope which sends them on to the client.  xscope is transparent to
  780. Xthe client and X11.
  781. X
  782. XIn addition to passing characters back and forth, xscope will print
  783. Xinformation about this traffic on stdout, giving performance and
  784. Xdebugging information for an X11 client and server.
  785. X
  786. X
  787. X  --------------               --------------             --------------
  788. X  `7C            `7C               `7C            `7C             `7C
  789. V            `7C
  790. X  `7C            `7C ------------> `7C            `7C ----------> `7C
  791. V            `7C
  792. X  `7C   client   `7C               `7C  xscope    `7C             `7C   serv
  793. Ver   `7C
  794. X  `7C            `7C               `7C            `7C             `7C
  795. V            `7C
  796. X  `7C            `7C <-----------  `7C            `7C <---------- `7C
  797. V            `7C
  798. X  `7C            `7C               `7C            `7C             `7C
  799. V            `7C
  800. X  --------------               --------------             --------------
  801. X                                     `7C
  802. X`09`09`09`09     `7C
  803. X`09`09`09`09     v
  804. X`09`09`09    trace output to stdout
  805. X
  806. X
  807. XWhen running with xscope, three processes are involved, potentially all
  808. Xon different machines:
  809. X
  810. XX11 -- the X11 window server will be running on machine "A" for Display "B".
  811. X`09("A" is a machine name; "B" is a display number).
  812. X
  813. Xxscope -- xscope must be told where the X11 window server is`20
  814. X`09(what machine and what display).  The options for xscope are`20
  815. X`09-h<X11-host> and -d<display-number>.  In our example, -hA and -dB.`20
  816. X`09Typically the display-number is not given. xscope will not try to`20
  817. X`09connect to X11 until the client connects to xscope.
  818. X
  819. Xclient -- the client should connect to xscope rather than X11.  To avoid`20
  820. X`09changing the code for the client, xscope listens on the same port`20
  821. X`09as X11. If X11 and xscope are on different machines, this works`20
  822. X`09well.  However, if X11 and xscope are on the same machine, this`20
  823. X`09creates a port conflict.  To resolve this conflict, xscope can`20
  824. X`09be given a different input or output port number, as necessary`20
  825. X`09to avoid the port that X11 is listening to.  The client must connect`20
  826. X`09to this offset port number.  The input port for xscope is set by`20
  827. X`09-i<port-number>; the output port is set by -o<port-number>. The`20
  828. X`09default input port is 1; the default output port is 0. These ports
  829. X`09are offset by the X11 base (6000) and the display number. The client`20
  830. X`09attaches to xscope by changing its display number by the port offset.
  831. X
  832. XFor example, with X11 running on "bagel", display 0 (the default), and
  833. Xxscope and the client running on "cleo", we would start xscope as
  834. X"xscope -hbagel -i0".  The client program could then connect to "X11" on
  835. X"cleo:0", and would be attached to xscope, which would then attach to
  836. XX11 on "bagel:0".
  837. X
  838. XIf, however, all three processes were running on "cleo", we would
  839. Xstart xscope by "xscope -i1".  This would cause it to listen on
  840. Xport 6001 (which is display 1 for X11).  The client would attach to
  841. XX11 on "cleo:1", and xscope would connect through to X11 on "cleo:0".
  842. X
  843. X
  844. XLIMITATIONS:
  845. X
  846. Xxscope has been written and used on a Sun3. Additional code may be needed
  847. Xfor byteswapping on different architectures.
  848. X
  849. XThe command line arguments for specifying the real X server should probably
  850. X`09be changed to be more consistent with X11R3 applications.
  851. X
  852. XThe Imakefile may be incorrect.
  853. X
  854. XThe builtin atoms have been wired in directly; they should probably be
  855. Xpicked up from a header file.
  856. X
  857. XNo provision is included for extensions to the base protocol.
  858. X
  859. XThere is no code yet to interpret typed commands from the keyboard.
  860. X   It would be possible for a command language at the keyboard to create
  861. X   artificial characters to be sent to X11 or the client as if they were`20
  862. X   generated  by the other, or to dynamically alter requests or replies.
  863. X
  864. X
  865. X
  866. X
  867. $ CALL UNPACK README.;1 1246703115
  868. $ create 'f'
  869. X                                  XScope/VMS
  870. X                                      1.0
  871. X
  872. XDescription
  873. X
  874. X  This is a version of XSCOPE for VMS.  It supports both DECnet and TCP/IP
  875. X  transports and fully compatible with the X11 protocol.  For a description
  876. X  of how XSCOPE works see the file README.;
  877. X
  878. XWhere to get XScope/VMS
  879. X
  880. X  XScope/VMS is distributed as both a VMS Shar file and a VMS Backup Saveset
  881. V.
  882. X  The VMS Shar file is posted to vmsnet.sources and the VMS Backup Saveset
  883. X  is available from PUBLIC.TGV.COM under `5B.MAHAN`5D.
  884. X
  885. XBuilding Xscope/VMS
  886. X
  887. X  After unpacking the VMS Shar file, or the VMS Backup Saveset, issue the
  888. X  command @MAKE.COM to compile and link both xscope programs.  This build
  889. X  produces at least one executable and maybe two if you have MultiNet`20
  890. X  installed on your system.  DNXSCOPE.EXE is the DECnet version of XSCOPE.
  891. X  It requires the following privileges to run: NETMBX, TMPMBX and SYSNAM.
  892. X  IPXSCOPE.EXE is the TCP/IP version built using TGV's MultiNet Socket libra
  893. Vry,
  894. X  though it should easily any of the current VMS TCP/IP vendor's socket
  895. X  libraries.
  896. X
  897. X  After building the executables, simply define the executables as foreign
  898. X  commands.
  899. X
  900. XUser Help
  901. X
  902. X  Currently the only help provided is the original Unix man page provided
  903. X  with XSCOPE.
  904. X
  905. XRestrictions
  906. X
  907. X  The DECnet version requires SYSNAM privilege.  This is due to the nature
  908. X  of DECnet objects which require the ability to create system wide logical
  909. X  names.
  910. X
  911. X  The TCP/IP version is built using TGV's MultiNet.  Hopefully, somebody
  912. X  will convert it to support other vendor's VMS TCP/IP libraries as well.
  913. X  If you do, I would like the modified source sent back to me.  One small
  914. X  caveat, the other vendor's TCP/IP must be a fairly full implementation
  915. X  of the standard socket library.  To see what I did for MultiNet, look
  916. X  for the #ifdef MULTINET lines in the .C files.
  917. X
  918. X  Please report any bugs or enhancements to me.
  919. X
  920. XAuthors
  921. X
  922. X  Patrick L. Mahan (mahan@tgv.com)`09Original port to VMS
  923. X  Osborne Hardison (hardison@ncd.com)`09Author of the DECnet socket library
  924. X
  925. $ CALL UNPACK README.VMS;2 1061555220
  926. $ create 'f'
  927. X/* ******************************************************
  928. X *`09`09`09`09`09`09      `09*
  929. X *  A spy program to reveal X11  traffic`09    `09*
  930. X *`09`09`09`09`09`09      `09*
  931. X *`09James Peterson, 1988`09       `09`09`09*
  932. X *`09(c) Copyright MCC, 1988 `09`09`09*
  933. X *`09`09`09`09`09`09`09*
  934. X ***************************************************** */
  935. X#if defined(vax11c) && !defined(MULTINET)
  936. X#include "emulationlib.h"
  937. X#endif
  938. X
  939. X#include "scope.h"
  940. X
  941. X
  942. X/* ********************************************** */
  943. X/*                                                */
  944. X/* ********************************************** */
  945. X
  946. X#define DefaultPort 6000
  947. X
  948. Xchar    ServerHostName`5B255`5D;
  949. Xlong    ServerBasePort = DefaultPort;
  950. Xlong    ServerInPort = 1;
  951. Xlong    ServerOutPort = 0;
  952. Xlong    ServerDisplay = 0;
  953. X
  954. X
  955. X/* ********************************************** */
  956. X/*                                                */
  957. X/*                                                */
  958. X/* ********************************************** */
  959. X
  960. Xshort     GetServerport ()
  961. X`7B
  962. X  short     port;
  963. X
  964. X  enterprocedure("GetServerport");
  965. X
  966. X  port = ServerBasePort + ServerOutPort + ServerDisplay;
  967. X  debug(4,(stderr, "Server service is on port %d\n", port));
  968. X  return(port);
  969. X`7D
  970. X
  971. Xshort     GetScopePort ()
  972. X`7B
  973. X  short     port;
  974. X
  975. X  enterprocedure("GetScopePort");
  976. X
  977. X  port = ServerBasePort + ServerInPort + ServerDisplay;
  978. X  debug(4,(stderr, "scope service is on port %d\n", port));
  979. X  return(port);
  980. X`7D
  981. X
  982. X/* ********************************************** */
  983. X/*                                                */
  984. X/* ********************************************** */
  985. X
  986. XUsage()
  987. X`7B
  988. X  fprintf(stderr, "Usage: xscope\n");
  989. X  fprintf(stderr, "              `5B-h<server-host>`5D\n");
  990. X  fprintf(stderr, "              `5B-i<in-port>`5D\n");
  991. X  fprintf(stderr, "              `5B-o<out-port>`5D\n");
  992. X  fprintf(stderr, "              `5B-d<display-number>`5D\n");
  993. X  fprintf(stderr, "              `5B-v<n>`5D  -- verbose output\n");
  994. X  fprintf(stderr, "              `5B-q`5D  -- quiet output\n");
  995. X  fprintf(stderr, "              `5B-D<debug-level>`5D\n");
  996. X  exit(1);
  997. X`7D
  998. X
  999. X
  1000. Xchar *OfficialName()  /* forward type declaration */;
  1001. X
  1002. XScanArgs(argc, argv)
  1003. X     int     argc;
  1004. X     char  **argv;
  1005. X`7B
  1006. X  Verbose = 1 /* default verbose-ness level */;
  1007. X
  1008. X  /* Scan argument list */
  1009. X  while (--argc > 0)
  1010. X    `7B
  1011. X      ++argv;
  1012. X      if (**argv == '-')
  1013. X`09switch (*++*argv)
  1014. X`09  `7B
  1015. X`09    /*
  1016. X`09      debug levels:
  1017. X`09      `092 - trace each procedure entry
  1018. X`09      `094 - I/O, connections
  1019. X`09      `098 - Scope internals
  1020. X`09      `0916 - Message protocol
  1021. X`09`0932 - 64 - malloc
  1022. X`09`09128 - 256 - really low level
  1023. X`09    */
  1024. X`09  case 'D':
  1025. X`09    debuglevel = atoi(++*argv);
  1026. X`09    if (debuglevel == 0)
  1027. X`09      debuglevel = 255;
  1028. X`09    debuglevel `7C= 1;
  1029. X`09    Verbose = 7;
  1030. X`09    debug(1,(stderr, "debuglevel = %d\n", debuglevel));
  1031. X`09    break;
  1032. X
  1033. X`09  case 'q': /* quiet mode */
  1034. X`09    Verbose = 0;
  1035. X`09    debug(1,(stderr, "Verbose = %d\n", Verbose));
  1036. X`09    break;
  1037. X
  1038. X`09  case 'v': /* verbose mode */
  1039. X`09    Verbose = atoi(++*argv);
  1040. X`09    debug(1,(stderr, "Verbose = %d\n", Verbose));
  1041. X`09    break;
  1042. X
  1043. X`09  case 'o':
  1044. X`09    ServerOutPort = atoi(++*argv);
  1045. X`09    if (ServerOutPort <= 0)
  1046. X`09      ServerOutPort = 0;
  1047. X`09    debug(1,(stderr, "ServerOutPort = %d\n", ServerOutPort));
  1048. X`09    break;
  1049. X
  1050. X`09  case 'd':
  1051. X`09    ServerDisplay = atoi(++*argv);
  1052. X`09    if (ServerDisplay <= 0)
  1053. X`09      ServerDisplay = 0;
  1054. X`09    debug(1,(stderr, "ServerDisplay=%d\n", ServerDisplay));
  1055. X`09    break;
  1056. X
  1057. X`09  case 'i':
  1058. X`09    ServerInPort = atoi(++*argv);
  1059. X`09    if (ServerInPort <= 0)
  1060. X`09      ServerInPort = 0;
  1061. X`09    debug(1,(stderr, "ServerInPort = %d\n", ServerInPort));
  1062. X`09    break;
  1063. X
  1064. X`09  case 'h':
  1065. X`09    if (++*argv != NULL && **argv != '\0')
  1066. X`09      strcpy(ServerHostName, OfficialName(*argv));
  1067. X`09    debug(1,(stderr, "ServerHostName=%s\n", ServerHostName));
  1068. X`09    break;
  1069. X
  1070. X`09  default:
  1071. X`09    fprintf(stderr, "Unknown option %c\n", **argv);
  1072. X`09    Usage();
  1073. X`09    break;
  1074. X
  1075. X`09  `7D
  1076. X      else
  1077. X`09`7B
  1078. X`09  /* file argument to scope -- error */
  1079. X`09  Usage();
  1080. X`09`7D
  1081. X    `7D
  1082. X
  1083. X  /* check for different port numbers or different machines */
  1084. X  if (ServerInPort == ServerOutPort)
  1085. X    if (ServerHostName`5B0`5D == '\0')
  1086. X      `7B
  1087. X`09fprintf(stderr, "Can't have xscope on same port as server (%d)\n",
  1088. X`09`09ServerInPort);
  1089. X`09Usage();
  1090. X      `7D
  1091. X
  1092. X`7D
  1093. X
  1094. X
  1095. X/* ********************************************** */
  1096. X/*                                                */
  1097. X/* ********************************************** */
  1098. X
  1099. Xmain(argc, argv)
  1100. X     int     argc;
  1101. X     char  **argv;
  1102. X`7B
  1103. X  ScanArgs(argc, argv);
  1104. X  InitializeFD();
  1105. X  InitializeX11();
  1106. X  SetUpStdin();
  1107. X  SetUpConnectionSocket(GetScopePort());
  1108. X  SetSignalHandling();
  1109. X
  1110. X  MainLoop();
  1111. X`7D
  1112. X
  1113. XTimerExpired()
  1114. X`7B
  1115. X  debug(16,(stderr, "Timer tick\n"));
  1116. X`7D
  1117. X
  1118. X/* ********************************************** */
  1119. X/*                                                */
  1120. X/* ********************************************** */
  1121. X
  1122. X/*
  1123. X  here is where we would add code to allow control from
  1124. X  the keyboard.  We would want to read a command and
  1125. X  interpret it.  Possibilties:
  1126. X
  1127. X  (a) verbose level setting
  1128. X  (b) reset time
  1129. X  (c) save X requests to a file.
  1130. X  (d) replay X requests from a file.
  1131. X  (e) allow fake events, errors to be generated.
  1132. X*/
  1133. X
  1134. XReadStdin(fd)
  1135. X     FD fd;
  1136. X`7B
  1137. X  char    buf`5B2048`5D;
  1138. X  long    n;
  1139. X
  1140. X  enterprocedure("ReadStdin");
  1141. X  n = read(fd, buf, 2048);
  1142. X  debug(4,(stderr, "read %d bytes from stdin\n", n));
  1143. X`7D
  1144. X
  1145. XSetUpStdin()
  1146. X`7B
  1147. X  enterprocedure("SetUpStdin");
  1148. X#ifndef vax11c`09/* Not supported under VMS */
  1149. X  UsingFD(fileno(stdin), ReadStdin);
  1150. X#endif /* vax11c */
  1151. X`7D
  1152. X
  1153. X/* ************************************************************ */
  1154. X/*`09`09`09`09`09`09`09`09*/
  1155. X/*`09`09`09`09`09`09`09`09*/
  1156. X/* ************************************************************ */
  1157. X
  1158. X/*
  1159. X  xscope is really meant to look at one client at a time.  However,
  1160. X  it can easily handle multiple clients and servers.  To do so,
  1161. X  we need to have a pair of FDs: one for the client and one for the
  1162. X  server for that client.  If either goes away, so does the other.
  1163. X  We need to be able to identify the other FD of a pair, so that if
  1164. X  we get input from one, we can write it to the other.
  1165. X*/
  1166. X
  1167. Xstruct fdinfo
  1168. X`7B
  1169. X  Boolean Server;
  1170. X  long    ClientNumber;
  1171. X  FD pair;
  1172. X`7D;
  1173. X
  1174. Xstatic long ClientNumber = 0;
  1175. X#ifdef vax11c
  1176. Xstatic struct fdinfo  *FDinfo = (struct fdinfo *)NULL;
  1177. X#else
  1178. Xstruct fdinfo   FDinfo`5BStaticMaxFD`5D;
  1179. X#endif /* vax11c */
  1180. X
  1181. XSetUpPair(client, server)
  1182. X     FD client;
  1183. X     FD server;
  1184. X`7B
  1185. X#ifdef vax11c
  1186. X  /*
  1187. X   *`09HACK ALERT!`09This is wasting to much memory, gotta to
  1188. X   *`09come back and clean this up.
  1189. X   */
  1190. X  if (!FDinfo) FDinfo = (struct fdinfo *) MyMalloc`20
  1191. X    `09`09((long)(MaxFD * sizeof (struct fdinfo)));
  1192. X#endif /* vax11c */
  1193. X  if (client >= 0)
  1194. X    `7B
  1195. X      ClientNumber += 1;
  1196. X      FDinfo`5Bclient`5D.Server = false;
  1197. X      FDinfo`5Bclient`5D.pair = server;
  1198. X      FDinfo`5Bclient`5D.ClientNumber = ClientNumber;
  1199. X      if (server >= 0)
  1200. X`09`7B
  1201. X`09  FDinfo`5Bserver`5D.Server = true;
  1202. X`09  FDinfo`5Bserver`5D.pair = client;
  1203. X`09  FDinfo`5Bserver`5D.ClientNumber = FDinfo`5Bclient`5D.ClientNumber;
  1204. X`09`7D
  1205. X    `7D
  1206. X  else if (server >= 0)
  1207. X      `7B
  1208. X`09socket_close(server);
  1209. X`09NotUsingFD(server);
  1210. X      `7D
  1211. X`7D
  1212. X
  1213. X
  1214. XCloseConnection(fd)
  1215. X     FD fd;
  1216. X`7B
  1217. X  debug(4,(stderr, "close %d and %d\n", fd, FDPair(fd)));
  1218. X  StopClientConnection(ServerHalf(fd));
  1219. X  StopServerConnection(ClientHalf(fd));
  1220. X
  1221. X  socket_close(fd);
  1222. X  NotUsingFD(fd);
  1223. X  socket_close(FDPair(fd));
  1224. X  NotUsingFD(FDPair(fd));
  1225. X`7D
  1226. X
  1227. X/* ************************************************************ */
  1228. X
  1229. XFD FDPair(fd)
  1230. X     FD fd;
  1231. X`7B
  1232. X  return(FDinfo`5Bfd`5D.pair);
  1233. X`7D
  1234. X
  1235. XFD ClientHalf(fd)
  1236. X     FD fd;
  1237. X`7B
  1238. X  if (FDinfo`5Bfd`5D.Server)
  1239. X    return(FDinfo`5Bfd`5D.pair);
  1240. X  return(fd);
  1241. X`7D
  1242. X
  1243. XFD ServerHalf(fd)
  1244. X     FD fd;
  1245. X`7B
  1246. X  if (FDinfo`5Bfd`5D.Server)
  1247. X    return(fd);
  1248. X  return(FDinfo`5Bfd`5D.pair);
  1249. X`7D
  1250. X
  1251. Xchar   *ClientName (fd)
  1252. X     FD fd;
  1253. X`7B
  1254. X  static char name`5B12`5D;
  1255. X
  1256. X  if (ClientNumber <= 1)
  1257. X    return("");
  1258. X  sprintf(name, " %d", FDinfo`5Bfd`5D.ClientNumber);
  1259. X  return(name);
  1260. X`7D
  1261. X
  1262. X
  1263. X/* ********************************************** */
  1264. X/*                                                */
  1265. X/* ********************************************** */
  1266. X
  1267. X/* when we get data from a client, we read it in, copy it to the
  1268. X   server for this client, then dump it to the client. Note, we don't
  1269. X   have to have a server, if there isn't one. */
  1270. X
  1271. XDataFromClient(fd)
  1272. X     FD fd;
  1273. X`7B
  1274. X  unsigned char    buf`5B2048`5D;
  1275. X  long    n;
  1276. X  FD ServerFD;
  1277. X
  1278. X  enterprocedure("DataFromClient");
  1279. X  n = read(fd, (char *)buf, 2048);
  1280. X  debug(4,(stderr, "read %d bytes from Client%s\n", n, ClientName(fd)));
  1281. X  if (n < 0)
  1282. X    `7B
  1283. X      PrintTime();
  1284. X      perror("Client --> read error:");
  1285. X      CloseConnection(fd);
  1286. X      return;
  1287. X    `7D
  1288. X  if (n == 0)
  1289. X    `7B
  1290. X      PrintTime();
  1291. X      fprintf(stdout, "Client%s --> EOF\n", ClientName(fd));
  1292. X      CloseConnection(fd);
  1293. X      return;
  1294. X    `7D
  1295. X
  1296. X  ServerFD = FDPair(fd);
  1297. X  if (ServerFD < 0)
  1298. X    `7B
  1299. X      ServerFD = ConnectToServer(false);
  1300. X      SetUpPair(fd, ServerFD);
  1301. X    `7D
  1302. X
  1303. X  /* write bytes from client to server, allow for server to fail */
  1304. X  if (ServerFD >= 0)
  1305. X    `7B
  1306. X      long    BytesToWrite = n;
  1307. X      unsigned char   *p = buf;
  1308. X
  1309. X      while (BytesToWrite > 0)
  1310. X`09`7B
  1311. X`09  int     n1 = write (ServerFD, (char *)p, (int)BytesToWrite);
  1312. X`09  debug(4,(stderr, "write %d bytes to Server%s\n", n1, ClientName(fd)));
  1313. X`09  if (n1 > 0)
  1314. X`09    `7B
  1315. X`09      BytesToWrite -= n1;
  1316. X`09      p += n1;
  1317. X`09    `7D
  1318. X`09  else
  1319. X`09    `7B
  1320. X`09`09`09    perror("Error on write to Server");
  1321. X`09      CloseConnection(fd);
  1322. X`09      BytesToWrite = 0;
  1323. X`09    `7D
  1324. X`09`7D
  1325. X    `7D
  1326. X
  1327. X  /* also report the bytes to standard out */
  1328. X  ReportFromClient(fd, buf, n);
  1329. X`7D
  1330. X
  1331. X/* ********************************************** */
  1332. X/*                                                */
  1333. X/* ********************************************** */
  1334. X
  1335. X/* similar situation for the server, but note that if there is no client,
  1336. X   we close the connection down -- don't need a server with no client. */
  1337. X
  1338. XDataFromServer(fd)
  1339. X     FD fd;
  1340. X`7B
  1341. X  unsigned char    buf`5B2048`5D;
  1342. X  long    n;
  1343. X  FD ClientFD;
  1344. X
  1345. X  enterprocedure("DataFromServer");
  1346. X  n = read(fd, (char *)buf, 2048);
  1347. X  debug(4,(stderr, "read %d bytes from Server%s\n", n, ClientName(fd)));
  1348. X  if (n < 0)
  1349. X    `7B
  1350. X      PrintTime();
  1351. X      perror("read error <- Server");
  1352. X      CloseConnection(fd);
  1353. X      return;
  1354. X    `7D
  1355. X  if (n == 0)
  1356. X    `7B
  1357. X      PrintTime();
  1358. X      fprintf(stdout, "EOF <-- Server%s\n", ClientName(fd));
  1359. X      CloseConnection(fd);
  1360. X      return;
  1361. X    `7D
  1362. X
  1363. X  ClientFD = FDPair(fd);
  1364. X  if (ClientFD < 0)
  1365. X    `7B
  1366. X      CloseConnection(fd);
  1367. X      return;
  1368. X    `7D
  1369. X
  1370. X  /* write bytes from server to client, allow for client to fail */
  1371. X  `7B
  1372. X    long    BytesToWrite = n;
  1373. X    unsigned char   *p = buf;
  1374. X    while (BytesToWrite > 0)
  1375. X      `7B
  1376. X`09int     n1 = write (ClientFD, (char *)p, (int)BytesToWrite);
  1377. X`09debug(4,(stderr, "write %d bytes to Client%s\n", n1, ClientName(fd)));
  1378. X`09if (n1 > 0)
  1379. X`09  `7B
  1380. X`09    BytesToWrite -= n1;
  1381. X`09    p += n1;
  1382. X`09  `7D
  1383. X`09else
  1384. X`09  `7B
  1385. X`09`09`09perror("Error on write to Client");
  1386. X`09    CloseConnection(fd);
  1387. X`09    BytesToWrite = 0;
  1388. X`09  `7D
  1389. X      `7D
  1390. X  `7D
  1391. X
  1392. X  /* also report the bytes to standard out */
  1393. X  ReportFromServer(fd, buf, n);
  1394. X`7D
  1395. X
  1396. X
  1397. X
  1398. X/* ************************************************************ */
  1399. X/*`09`09`09`09`09`09`09`09*/
  1400. X/*     Create New Connection to a client program and to Server  */
  1401. X/*`09`09`09`09`09`09`09`09*/
  1402. X/* ************************************************************ */
  1403. X
  1404. X#ifdef vax11c
  1405. X#ifdef MULTINET
  1406. X#include <sys$common/multinet/include/sys/types.h>`09       /* needed by sys
  1407. V/socket.h and netinet/in.h */
  1408. X#include <sys$common/multinet/include/sys/uio.h>`09       /* for struct iove
  1409. Vc, used by socket.h */
  1410. X#include <sys$common/multinet/include/sys/socket.h>`09       /* for AF_INET,
  1411. V SOCK_STREAM, ... */
  1412. X#include <sys$common/multinet/include/sys/ioctl.h>`09       /* for FIONCLEX,
  1413. V FIONBIO, ... */
  1414. X#include <sys$common/multinet/include/netinet/in.h>`09       /* struct socka
  1415. Vddr_in */
  1416. X#include <sys$common/multinet/include/netdb.h>`09       /* struct servent *
  1417. V and struct hostent * */
  1418. X#endif /* MULTINET */
  1419. X#include <errno.h>`09       /* for EINTR, EADDRINUSE, ... */
  1420. Xextern volatile int noshare errno;
  1421. X#else
  1422. X#include <sys/types.h>`09       /* needed by sys/socket.h and netinet/in.h *
  1423. V/
  1424. X#include <sys/uio.h>`09       /* for struct iovec, used by socket.h */
  1425. X#include <sys/socket.h>`09       /* for AF_INET, SOCK_STREAM, ... */
  1426. X#include <sys/ioctl.h>`09       /* for FIONCLEX, FIONBIO, ... */
  1427. X#include <netinet/in.h>`09       /* struct sockaddr_in */
  1428. X#include <netdb.h>`09       /* struct servent * and struct hostent * */
  1429. X#include <errno.h>`09       /* for EINTR, EADDRINUSE, ... */
  1430. Xextern int  errno;
  1431. X#endif /* vax11c */
  1432. X
  1433. Xstatic int  ON = 1 /* used in ioctl */ ;
  1434. X
  1435. XNewConnection(fd)
  1436. X     FD fd;
  1437. X`7B
  1438. X  FD ServerFD = -1;
  1439. X  FD ClientFD = -1;
  1440. X
  1441. X  ClientFD = ConnectToClient(fd);
  1442. X  ServerFD = ConnectToServer(true);
  1443. X  SetUpPair(ClientFD, ServerFD);
  1444. X`7D
  1445. X
  1446. X
  1447. X/* ************************************************************ */
  1448. X
  1449. XFD ConnectToClient(ConnectionSocket)
  1450. X     FD ConnectionSocket;
  1451. X`7B
  1452. X  FD ClientFD;
  1453. X  struct sockaddr_in  from;
  1454. X  int    len = sizeof (from);
  1455. X
  1456. X  enterprocedure("ConnectToClient");
  1457. X
  1458. X  ClientFD = accept(ConnectionSocket, (struct sockaddr *)&from, &len);
  1459. X  debug(4,(stderr, "Connect To Client: FD %d\n", ClientFD));
  1460. X  if (ClientFD < 0 && errno == EWOULDBLOCK)
  1461. X    `7B
  1462. X      debug(4,(stderr, "Almost blocked accepting FD %d\n", ClientFD));
  1463. X      panic("Can't connect to Client");
  1464. X    `7D
  1465. X  if (ClientFD < 0)
  1466. X    `7B
  1467. X      debug(4,(stderr, "NewConnection: error %d\n", errno));
  1468. X      panic("Can't connect to Client");
  1469. X    `7D
  1470. X
  1471. X  UsingFD(ClientFD, DataFromClient);
  1472. X#ifdef vax11c
  1473. X  /* socket_ioctl(ClientFD, FIOCLEX, 0); ! Not need since close on exit is d
  1474. Vef */
  1475. X  socket_ioctl(ClientFD, FIONBIO, &ON);
  1476. X#else
  1477. X  ioctl(ClientFD, FIOCLEX, 0);
  1478. X  ioctl(ClientFD, FIONBIO, &ON);
  1479. X#endif /* vax11c */
  1480. X  StartClientConnection(ClientFD);
  1481. X  return(ClientFD);
  1482. X`7D
  1483. X
  1484. X
  1485. X
  1486. X/* ************************************************************ */
  1487. X/*`09`09`09`09`09`09`09`09*/
  1488. X/*`09`09`09`09`09`09`09`09*/
  1489. X/* ************************************************************ */
  1490. X
  1491. X
  1492. X
  1493. XFD ConnectToServer(report)
  1494. X     Boolean report;
  1495. X`7B
  1496. X  FD ServerFD;
  1497. X  struct sockaddr_in  sin;
  1498. X  struct hostent *hp;
  1499. X  short port;
  1500. X#ifdef vax11c
  1501. X  unsigned long int On;
  1502. X#endif /* vax11c */
  1503. X
  1504. X  enterprocedure("ConnectToServer");
  1505. X
  1506. X  /* establish a socket to the name server for this host */
  1507. X  bzero((char *)&sin, sizeof(sin));
  1508. X  ServerFD = socket(AF_INET, SOCK_STREAM, 0);
  1509. X  if (ServerFD < 0)
  1510. X    `7B
  1511. X      perror("socket() to Server failed");
  1512. X      debug(1,(stderr, "socket failed\n"));
  1513. X      panic("Can't open connection to Server");
  1514. X    `7D
  1515. X#ifdef vax11c
  1516. X  On = 0;
  1517. X  if (setsockopt(ServerFD, SOL_SOCKET, SO_REUSEADDR,  &On, sizeof(On)) < 0)
  1518. V `7B
  1519. X`09socket_perror("SOCKOPT: REUSADDR");
  1520. X`09exit (-1);
  1521. X  `7D
  1522. X  if (setsockopt(ServerFD, SOL_SOCKET, SO_USELOOPBACK, &On, sizeof(On)) < 0)
  1523. V `7B
  1524. X`09socket_perror("SOCKOPT: USELOOPBACK");
  1525. X`09exit (-1);
  1526. X  `7D
  1527. X#ifdef SO_DONTLINGER
  1528. X  if (setsockopt(ServerFD, SOL_SOCKET, SO_DONTLINGER, (char *) NULL, 0) < 0)
  1529. V `7B
  1530. X`09socket_perror("SOCKOPT: DONTLINGER");
  1531. X`09exit (-1);
  1532. X  `7D
  1533. X#endif
  1534. X#else
  1535. X  (void) setsockopt(ServerFD, SOL_SOCKET, SO_REUSEADDR,  (char *) NULL, 0);
  1536. X  (void) setsockopt(ServerFD, SOL_SOCKET, SO_USELOOPBACK,(char *) NULL, 0);
  1537. X#ifdef SO_DONTLINGER
  1538. X  (void) setsockopt(ServerFD, SOL_SOCKET, SO_DONTLINGER, (char *) NULL, 0);
  1539. X#endif
  1540. X#endif /* vax11c */
  1541. X
  1542. X  /* determine the host machine for this process */
  1543. X  if (ServerHostName`5B0`5D == '\0')
  1544. X    (void) gethostname(ServerHostName, sizeof (ServerHostName));
  1545. X  debug(4,(stderr, "try to connect on %s\n", ServerHostName));
  1546. X
  1547. X  hp = gethostbyname(ServerHostName);
  1548. X  if (hp == 0)
  1549. X    `7B
  1550. X      perror("gethostbyname failed");
  1551. X      debug(1,(stderr, "gethostbyname failed for %s\n", ServerHostName));
  1552. X      panic("Can't open connection to Server");
  1553. X    `7D
  1554. X
  1555. X  sin.sin_family = AF_INET;
  1556. X  bcopy((char *)hp->h_addr, (char *)&sin.sin_addr, hp->h_length);
  1557. X  port = GetServerport ();
  1558. X
  1559. X  if (port == ScopePort
  1560. X      && strcmp(ServerHostName, ScopeHost) == 0)
  1561. X    `7B
  1562. X      char error_message`5B100`5D;
  1563. X      sprintf(error_message, "Trying to attach to myself: %s,%d\n",
  1564. X`09      ServerHostName, sin.sin_port);
  1565. X      panic(error_message);
  1566. X    `7D
  1567. X
  1568. X  sin.sin_port = htons (port);
  1569. X
  1570. X  /* ******************************************************** */
  1571. X  /* try to connect to Server */
  1572. X
  1573. X  if (connect(ServerFD, (struct sockaddr *)&sin, sizeof(sin)) < 0)
  1574. X    `7B
  1575. X      debug(4,(stderr, "connect returns errno of %d\n", errno));
  1576. X      if (errno != 0)
  1577. X`09if (report)
  1578. X`09  perror("connect");
  1579. X      switch (errno)
  1580. X`09`7B
  1581. X`09case ECONNREFUSED:
  1582. X`09  /* experience says this is because there is no Server
  1583. X`09     to connect to */
  1584. X`09  socket_close(ServerFD);
  1585. X`09  debug(1,(stderr, "No Server\n"));
  1586. X`09  if (report)
  1587. X`09    warn("Can't open connection to Server");
  1588. X`09  return(-1);
  1589. X
  1590. X`09default:
  1591. X`09  socket_close(ServerFD);
  1592. X`09  panic("Can't open connection to Server");
  1593. X`09`7D
  1594. X    `7D
  1595. X
  1596. X  debug(4,(stderr, "Connect To Server: FD %d\n", ServerFD));
  1597. X  if (ServerFD >= 0)
  1598. X    `7B
  1599. X      UsingFD(ServerFD, DataFromServer);
  1600. X      StartServerConnection(ServerFD);
  1601. X    `7D
  1602. X  return(ServerFD);
  1603. X`7D
  1604. X
  1605. X
  1606. X/* ********************************************** */
  1607. X/*                                                */
  1608. X/* ********************************************** */
  1609. X
  1610. Xchar *OfficialName(name)
  1611. Xchar *name;
  1612. X`7B
  1613. X  struct hostent *HostEntry;
  1614. X
  1615. X  HostEntry = gethostbyname(name);
  1616. X  if (HostEntry == NULL)
  1617. X    `7B
  1618. X      perror("gethostbyname");
  1619. X      exit(-1);
  1620. X    `7D
  1621. X  debug(4,(stderr, "Official name of %s is %s\n", name, HostEntry->h_name));
  1622. X  return(HostEntry->h_name);
  1623. X`7D
  1624. X
  1625. $ CALL UNPACK SCOPE.C;19 388685410
  1626. $ create 'f'
  1627. X/* **********************************************
  1628. X *`09`09`09`09`09`09*
  1629. X * header file for the Server spy scope           *
  1630. X *`09`09`09`09`09`09*
  1631. X *`09James Peterson, 1987`09`09`09*
  1632. X *`09(c) Copyright MCC, 1987 `09`09*
  1633. X *`09`09`09`09`09`09*
  1634. X ********************************************** */
  1635. X
  1636. X#include <stdio.h>
  1637. X#ifdef vax11c
  1638. X#include <string.h>
  1639. X#ifdef MULTINET
  1640. X#include <sys$common/multinet/include/sys/types.h>
  1641. X#endif /* MULTINET */
  1642. X#ifndef perror
  1643. X#define perror`09socket_perror
  1644. X#endif /* !perror */
  1645. X#ifdef read
  1646. X#undef read
  1647. X#endif /* read */
  1648. X#ifdef write
  1649. X#undef write
  1650. X#endif /* write */
  1651. X#define read`09socket_read
  1652. X#define write`09socket_write
  1653. X#else
  1654. X#define socket_close  close
  1655. X#endif /* vax11c */
  1656. X
  1657. X#define Boolean short
  1658. X#define true 1
  1659. X#define false 0
  1660. X
  1661. X/* ********************************************** */
  1662. X/*                                                */
  1663. X/* ********************************************** */
  1664. X
  1665. X#define Assert(b) (b)
  1666. X#define debug(n,f) (void)((debuglevel & n) ? (fprintf f,fflush(stderr)) : 0)
  1667. Xshort   debuglevel;
  1668. X
  1669. X/* ********************************************** */
  1670. X/*                                                */
  1671. X/* ********************************************** */
  1672. X
  1673. Xshort   Verbose`09`09  /* quiet (0) or increasingly verbose  ( > 0) */ ;
  1674. X
  1675. X
  1676. Xint     ScopePort;
  1677. Xchar   *ScopeHost;
  1678. X
  1679. X/* external function type declarations */
  1680. X
  1681. X#ifdef vax11c
  1682. Xextern char   *MyMalloc ();
  1683. X#else
  1684. Xextern char   *Malloc ();
  1685. Xextern char *strcpy();
  1686. Xextern char *sprintf();
  1687. X#endif /* vax11c */
  1688. Xchar   *ClientName ();
  1689. X
  1690. X/* ********************************************** */
  1691. X/*                                                */
  1692. X/* ********************************************** */
  1693. X
  1694. X/* need to change the MaxFD to allow larger number of fd's */
  1695. X#define StaticMaxFD 32
  1696. X
  1697. X
  1698. X#include "fd.h"
  1699. $ CALL UNPACK SCOPE.H;8 1627813533
  1700. $ create 'f'
  1701. X/* ************************************************** *
  1702. X *`09`09`09`09`09`09      *
  1703. X *  Code to decode and print X11 protocol`09      *
  1704. X *`09`09`09`09`09`09      *
  1705. X *`09James Peterson, 1988`09`09`09      *
  1706. X *`09(c) Copyright MCC, 1988 `09`09      *
  1707. X *`09`09`09`09`09`09      *
  1708. X * ************************************************** */
  1709. X
  1710. X#if defined(vax11c) && !defined(MULTINET)
  1711. X#include "emulationlib.h"
  1712. X#endif
  1713. X
  1714. X#include "scope.h"
  1715. X#include "x11.h"
  1716. X
  1717. X#ifdef vax11c`09/* allocate storage for this information (shameful waste) */
  1718. X/* ************************************************************ */
  1719. X/*`09`09`09`09`09`09`09`09*/
  1720. X/*`09`09`09`09`09`09`09`09*/
  1721. X/* ************************************************************ */
  1722. X
  1723. XInitializeCS()
  1724. X`7B
  1725. X`09register int i;
  1726. X
  1727. X`09enterprocedure("InitializeCS");
  1728. X`09/*
  1729. X `09 *`09HACK! Must come back and fix this.  Should allocate all this
  1730. X `09 *`09memory if I'm not going to use it.
  1731. X `09 */
  1732. X `09if (CS == NULL)
  1733. X`09`09CS = (struct ConnState *)
  1734. X`09`09MyMalloc((long)(MaxFD * sizeof (struct ConnState)));
  1735. X
  1736. X`09/* initialize it */
  1737. X
  1738. X`09for (i = 0; i < MaxFD; i++) `7B
  1739. X`09`09CS`5Bi`5D.SavedBytes = NULL;
  1740. X`09`09CS`5Bi`5D.littleEndian = 0;
  1741. X`09`09CS`5Bi`5D.SizeofSavedBytes = 0;
  1742. X`09`09CS`5Bi`5D.NumberofSavedBytes = 0;
  1743. X`09`09CS`5Bi`5D.NumberofBytesNeeded = 0;
  1744. X`09`09CS`5Bi`5D.ByteProcessing = (long *)NULL;
  1745. X`09`09CS`5Bi`5D.SequenceNumber = 0;
  1746. X`09`7D
  1747. X`7D
  1748. X#endif /* vax11c
  1749. X
  1750. X/* ************************************************************ */
  1751. X/*`09`09`09`09`09`09`09`09*/
  1752. X/*`09`09`09`09`09`09`09`09*/
  1753. X/* ************************************************************ */
  1754. X
  1755. XReportFromClient(fd, buf, n)
  1756. X     FD fd;
  1757. X     unsigned char *buf;
  1758. X     long    n;
  1759. X`7B
  1760. X  PrintTime();
  1761. X  fprintf(stdout, "Client%s --> %4d %s\n",
  1762. X`09  ClientName(fd), n, (n == 1 ? "byte" : "bytes"));
  1763. X  ProcessBuffer(fd, buf, n);
  1764. X`7D
  1765. X
  1766. XReportFromServer(fd, buf, n)
  1767. X     FD fd;
  1768. X     unsigned char *buf;
  1769. X     long    n;
  1770. X`7B
  1771. X  PrintTime();
  1772. X  fprintf(stdout, "\t\t\t\t\t%4d %s <-- X11 Server%s\n",
  1773. X`09  n, (n == 1 ? "byte" : "bytes"), ClientName(fd));
  1774. X  ProcessBuffer(fd, buf, n);
  1775. X`7D
  1776. X
  1777. X
  1778. X/* ************************************************************ */
  1779. X/*`09`09`09`09`09`09`09`09*/
  1780. X/*`09`09`09`09`09`09`09`09*/
  1781. X/* ************************************************************ */
  1782. X
  1783. X#ifdef vax11c
  1784. X#ifdef MULTINET
  1785. X#include <sys$common/multinet/include/sys/time.h>
  1786. X#endif /* MULTINET */
  1787. X#else
  1788. X#include <sys/time.h>`09       /* for struct timeval * */
  1789. X#endif /* vax11c */
  1790. Xstatic long ZeroTime1 = -1;
  1791. Xstatic long ZeroTime2 = -1;
  1792. Xstatic struct timeval   tp;
  1793. X
  1794. X/* print the time since we started in hundredths (1/100) of seconds */
  1795. X
  1796. XPrintTime()
  1797. X`7B
  1798. X  static long lastsec = 0;
  1799. X  long    sec /* seconds */ ;
  1800. X  long    hsec /* hundredths of a second */ ;
  1801. X
  1802. X  gettimeofday(&tp, (struct timezone *)NULL);
  1803. X  if (ZeroTime1 == -1 `7C`7C (tp.tv_sec - lastsec) >= 1000)
  1804. X    `7B
  1805. X      ZeroTime1 = tp.tv_sec;
  1806. X      ZeroTime2 = tp.tv_usec / 10000;
  1807. X    `7D
  1808. X
  1809. X  lastsec = tp.tv_sec;
  1810. +-+-+-+-+-+-+-+-  END  OF PART 6 +-+-+-+-+-+-+-+-
  1811. --
  1812. Patrick L. Mahan
  1813.  
  1814. --- TGV Window Washer ------------------------------- Mahan@TGV.COM ---------
  1815.  
  1816. Waking a person unnecessarily should not be considered  - Lazarus Long
  1817. a capital crime.  For a first offense, that is            From the Notebooks of
  1818.                               Lazarus Long
  1819.