home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume20 / xgrabsc / part02 < prev    next >
Encoding:
Text File  |  1993-08-04  |  54.2 KB  |  2,067 lines

  1. Newsgroups: comp.sources.x
  2. From: bruce@servio.slc.com (Bruce Schuchardt)
  3. Subject: v20i101:  xgrabsc - Grab and dump X displays, Part02/05
  4. Message-ID: <1993Aug4.171656.9413@sparky.sterling.com>
  5. X-Md4-Signature: ef39928670b5e6cd5ed8a95358ef7b0c
  6. Sender: chris@sparky.sterling.com (Chris Olson)
  7. Organization: Sterling Software
  8. Date: Wed, 4 Aug 1993 17:16:56 GMT
  9. Approved: chris@sterling.com
  10.  
  11. Submitted-by: bruce@servio.slc.com (Bruce Schuchardt)
  12. Posting-number: Volume 20, Issue 101
  13. Archive-name: xgrabsc/part02
  14. Environment: X11
  15. Supersedes: xgrabsc: Volume 18, Issue 52-56
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 2 (of 5)."
  24. # Contents:  xgrabsc.2_3/XGrabxm.res xgrabsc.2_3/xgrabsc.c
  25. #   xgrabsc.2_3/xgrabxm.c
  26. # Wrapped by bruce@trout on Mon Jun 28 09:14:50 1993
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. if test -f 'xgrabsc.2_3/XGrabxm.res' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'xgrabsc.2_3/XGrabxm.res'\"
  30. else
  31. echo shar: Extracting \"'xgrabsc.2_3/XGrabxm.res'\" \(10437 characters\)
  32. sed "s/^X//" >'xgrabsc.2_3/XGrabxm.res' <<'END_OF_FILE'
  33. X#include "config.h"
  34. X
  35. XXGrab*.title.labelString: X-Windows Screen Grabber
  36. XXGrab*.title.FontList:   *-times-medium-r-normal--18-*
  37. XXGrab*.title.x: 135
  38. X
  39. X!----------------------------box 1
  40. X
  41. XXGrab*.box1.x: 0
  42. XXGrab*.box1.y:  35
  43. X
  44. XXGrab*.inputLbl.x:     5
  45. XXGrab*.inputLbl.y:      0
  46. XXGrab*.inputLbl.FontList: *-helvetica-medium-o-normal--14-*
  47. XXGrab*.inputLbl.labelString: Input Options--------------------------------------------
  48. X
  49. XXGrab*.selectiontype.topAttachment: attach_widget
  50. XXGrab*.selectiontype.topWidget: inputLbl
  51. XXGrab*.selectiontype.topOffset: 2
  52. XXGrab*.selectiontype.orientation: horizontal
  53. XXGrab*.selectiontype.numColumns: 2
  54. XXGrab*.selectiontype.x: 5
  55. X
  56. XXGrab*.click.labelString: Click on Window
  57. XXGrab*.stretch.labelString: Stretch Rectangle
  58. XXGrab*.stretch.set: 1
  59. XXGrab*.key.labelString: Wait for Control key
  60. XXGrab*.root.labelString: Grab Whole Screen
  61. X
  62. XXGrab*.sleeplbl.x: 10
  63. XXGrab*.sleeplbl.y:  90
  64. XXGrab*.sleeplbl.labelString: Sleep before starting
  65. X
  66. XXGrab*.sleeptime.leftAttachment: attach_widget
  67. XXGrab*.sleeptime.leftWidget:      sleeplbl
  68. XXGrab*.sleeptime.leftOffset:  5
  69. XXGrab*.sleeptime.y:      85
  70. XXGrab*.sleeptime.width:  40
  71. XXGrab*.sleeptime*value:  DEFAULT_PRESLEEP
  72. X
  73. XXGrab*.psleeplbl.leftAttachment: attach_widget
  74. XXGrab*.psleeplbl.leftWidget:    sleeptime
  75. XXGrab*.psleeplbl.leftOffset:    10
  76. XXGrab*.psleeplbl.y:    90
  77. XXGrab*.psleeplbl.labelString: Sleep after selecting
  78. X
  79. XXGrab*.psleeptime.leftAttachment: attach_widget
  80. XXGrab*.psleeptime.leftWidget:    psleeplbl
  81. XXGrab*.psleeptime.leftOffset:     5
  82. XXGrab*.psleeptime.y:     85
  83. XXGrab*.psleeptime.width:  40
  84. XXGrab*.psleeptime*value: DEFAULT_POSTSLEEP
  85. X
  86. XXGrab*.host.x:   10
  87. XXGrab*.host.y:   120
  88. XXGrab*.host.labelString: Use Alternate Display:
  89. XXGrab*.host.width:  150
  90. XXGrab*.host.set: 0
  91. X
  92. XXGrab*.hostText.leftAttachment: attach_widget
  93. XXGrab*.hostText.leftWidget:    host
  94. XXGrab*.hostText.leftOffset:     5
  95. XXGrab*.hostText.y:    115
  96. X! xgrab sets DISPLAY value into this widget
  97. X! XGrab*.hostText*value: :0
  98. X
  99. X
  100. X!----------------------------box 2
  101. XXGrab*.box2.x:   0
  102. XXGrab*.box2.topAttachment: attach_widget
  103. XXGrab*.box2.topWidget: box1
  104. X
  105. XXGrab*.outputFormat.x:   5
  106. XXGrab*.outputFormat.y:    0
  107. XXGrab*.outputFormat.FontList: *-helvetica-medium-o-normal--12-*
  108. XXGrab*.outputFormat.labelString: Output Format-------------------------------------------------
  109. X
  110. XXGrab*.formattype.topAttachment: attach_widget
  111. XXGrab*.formattype.topWidget: outputFormat
  112. XXGrab*.formattype.topOffset: 2
  113. XXGrab*.formattype.orientation: horizontal
  114. XXGrab*.formattype.numColumns: 2
  115. X
  116. XXGrab*.xwd.labelString:    X Window Dump
  117. XXGrab*.ps.labelString:     PostScript
  118. XXGrab*.ps.set: 1
  119. XXGrab*.puzzle.labelString: Puzzle
  120. XXGrab*.xwdxy.labelString:  XWD-xy
  121. XXGrab*.xpm.labelString:    Bitmap/XPM
  122. XXGrab*.xpm2.labelString:   Bm/XPM2
  123. XXGrab*.xpm3.labelString:   Bm/XPM3
  124. X
  125. X!----------------------------box 3
  126. XXGrab*.box3.x:   0
  127. XXGrab*.box3.topAttachment: attach_widget
  128. XXGrab*.box3.topWidget: box2
  129. X
  130. XXGrab*.psOptions.x:   5
  131. XXGrab*.psOptions.y:    0
  132. XXGrab*.psOptions.FontList: *-helvetica-medium-o-normal--12-*
  133. XXGrab*.psOptions.labelString: PostScript Options----------------------------------------------
  134. X
  135. XXGrab*.compress.x:   10
  136. XXGrab*.compress.y:    25 
  137. XXGrab*.compress.labelString: Compress
  138. XXGrab*.compress.set: 1
  139. X
  140. XXGrab*.color.leftAttachment: attach_widget
  141. XXGrab*.color.leftWidget: compress
  142. XXGrab*.color.leftOffset:    10
  143. XXGrab*.color.y:     25
  144. XXGrab*.color.labelString: Color Output
  145. X
  146. XXGrab*.binary.leftAttachment: attach_widget
  147. XXGrab*.binary.leftWidget: color
  148. XXGrab*.binary.leftOffset: 10
  149. XXGrab*.binary.y: 25
  150. XXGrab*.binary.labelString: Binary
  151. X
  152. XXGrab*.limit.leftAttachment: attach_widget
  153. XXGrab*.limit.leftWidget: binary
  154. XXGrab*.limit.leftOffset: 10
  155. XXGrab*.limit.y: 25
  156. X#if defined(NO_PRINTER_MEMORY_CHECKS)
  157. XXGrab*.limit.set: 0
  158. X#else
  159. XXGrab*.limit.set: 1
  160. X#endif
  161. XXGrab*.limit.labelString: Limit Check
  162. X
  163. XXGrab*.postscripttype.topAttachment: attach_widget
  164. XXGrab*.postscripttype.topWidget: compress
  165. XXGrab*.postscripttype.topOffset: 2
  166. XXGrab*.postscripttype.orientation: horizontal
  167. XXGrab*.postscripttype.numColumns: 1
  168. XXGrab*.postscripttype.x: 5
  169. X
  170. XXGrab*.portrait.labelString: Portrait
  171. XXGrab*.portrait.set: true
  172. XXGrab*.landscape.labelString: Landscape
  173. XXGrab*.epsi.labelString: PS Figure
  174. XXGrab*.onlyEpsi.labelString: Preview Only
  175. XXGrab*.pageWidth.x: 10
  176. XXGrab*.pageWidth.y:  90
  177. XXGrab*.pageWidth.labelString: Paper Width
  178. X
  179. XXGrab*.pageWidthText.leftAttachment: attach_widget
  180. XXGrab*.pageWidthText.leftWidget: pageWidth
  181. XXGrab*.pageWidthText.leftOffset: 0
  182. XXGrab*.pageWidthText.y:  85
  183. XXGrab*.pageWidthText.width: 45
  184. XXGrab*.pageWidthText*value: PAPER_WIDTH
  185. X
  186. XXGrab*.pageHeight.leftAttachment: attach_widget
  187. XXGrab*.pageHeight.leftWidget:    pageWidthText
  188. XXGrab*.pageHeight.leftOffset: 2
  189. XXGrab*.pageHeight.y:  90
  190. XXGrab*.pageHeight.labelString: Height
  191. X
  192. XXGrab*.pageHeightText.leftAttachment: attach_widget
  193. XXGrab*.pageHeightText.leftWidget: pageHeight
  194. XXGrab*.pageHeightText.leftOffset:  0
  195. XXGrab*.pageHeightText.y:  85
  196. XXGrab*.pageHeightText.width: 45
  197. XXGrab*.pageHeightText*value: PAPER_HEIGHT
  198. X
  199. XXGrab*.horizMargin.leftAttachment: attach_widget
  200. XXGrab*.horizMargin.leftWidget: pageHeightText
  201. XXGrab*.horizMargin.leftOffset:  2
  202. XXGrab*.horizMargin.y:  90
  203. XXGrab*.horizMargin.labelString: Margin Width
  204. X
  205. XXGrab*.horizMarginText.leftAttachment: attach_widget
  206. XXGrab*.horizMarginText.leftWidget: horizMargin
  207. XXGrab*.horizMarginText.leftOffset:  0
  208. XXGrab*.horizMarginText.y:  85
  209. XXGrab*.horizMarginText.width: 45
  210. XXGrab*.horizMarginText*value: HORIZ_MARGIN
  211. X
  212. XXGrab*.vertMargin.leftAttachment: attach_widget
  213. XXGrab*.vertMargin.leftWidget: horizMarginText
  214. XXGrab*.vertMargin.leftOffset:  2
  215. XXGrab*.vertMargin.y:  90
  216. XXGrab*.vertMargin.labelString:  Height
  217. X
  218. XXGrab*.vertMarginText.leftAttachment: attach_widget
  219. XXGrab*.vertMarginText.leftWidget: vertMargin
  220. XXGrab*.vertMarginText.leftOffset:  0
  221. XXGrab*.vertMarginText.y:  85
  222. XXGrab*.vertMarginText.width: 45
  223. XXGrab*.vertMarginText*value: VERT_MARGIN
  224. X
  225. X!----------------------------box 4
  226. XXGrab*.box4.x: 0
  227. XXGrab*.box4.topAttachment: attach_widget
  228. XXGrab*.box4.topWidget: box3
  229. X
  230. XXGrab*.prOptions.x:   5
  231. XXGrab*.prOptions.y:    0
  232. XXGrab*.prOptions.FontList: *-helvetica-medium-o-normal--12-*
  233. XXGrab*.prOptions.labelString: Image Processing Options-----
  234. X
  235. XXGrab*.borders.x:   10
  236. XXGrab*.borders.y:    20
  237. XXGrab*.borders.labelString: Include Borders
  238. XXGrab*.borders.width:          105
  239. XXGrab*.borders.set:            1
  240. X
  241. XXGrab*.reverse.x:   10
  242. XXGrab*.reverse.y:    45
  243. XXGrab*.reverse.labelString: Reverse Colors
  244. XXGrab*.reverse.width:           105
  245. X
  246. XXGrab*.brightnessLbl.x:   10
  247. XXGrab*.brightnessLbl.y:    75
  248. XXGrab*.brightnessLbl.labelString: Brightness
  249. X
  250. XXGrab*.brightnessText.x:   85
  251. XXGrab*.brightnessText.y:    70
  252. XXGrab*.brightnessText.width: 40
  253. XXGrab*.brightnessText*value: 100
  254. X
  255. X!----------------------------box 5
  256. XXGrab*.box5.leftAttachment: attach_widget
  257. XXGrab*.box5.leftWidget: box4
  258. XXGrab*.box5.leftOffset: 5
  259. XXGrab*.box5.topAttachment: attach_widget
  260. XXGrab*.box5.topWidget: box3
  261. X
  262. XXGrab*.outputLbl.x:     5
  263. XXGrab*.outputLbl.y:      0
  264. XXGrab*.outputLbl.FontList: *-helvetica-medium-o-normal--12-*
  265. XXGrab*.outputLbl.labelString: Output Options------------------------
  266. X
  267. XXGrab*.outputtype.topAttachment: attach_widget
  268. XXGrab*.outputtype.topWidget: outputLbl
  269. XXGrab*.outputtype.topOffset: 2
  270. XXGrab*.outputtype.orientation: vertical
  271. XXGrab*.outputtype.numColumns: 1
  272. X
  273. XXGrab*.file.labelString: To File:
  274. XXGrab*.file.set: 1
  275. XXGrab*.file.marginHeight: 2
  276. XXGrab*.printer.labelString: To Command:
  277. XXGrab*.printer.marginHeight: 4
  278. X
  279. XXGrab*.fileText.leftAttachment: attach_widget
  280. XXGrab*.fileText.leftWidget: outputtype
  281. XXGrab*.fileText.leftOffset: 5
  282. XXGrab*.fileText.topAttachment: attach_widget
  283. XXGrab*.fileText.topWidget: outputLbl
  284. XXGrab*.fileText.topOffset: 2
  285. XXGrab*.fileText.width: 110
  286. XXGrab*.fileText*value: DEFAULT_FILENAME
  287. X
  288. XXGrab*.printerText.leftAttachment: attach_widget
  289. XXGrab*.printerText.leftWidget: outputtype
  290. XXGrab*.printerText.leftOffset: 5
  291. XXGrab*.printerText.topAttachment: attach_widget
  292. XXGrab*.printerText.topWidget: fileText
  293. XXGrab*.printerText.topOffset: 2
  294. XXGrab*.printerText.width: 110
  295. XXGrab*.printerText*value: DEFAULT_COMMAND
  296. X
  297. X
  298. X
  299. XXGrab*.converttype.topAttachment: attach_widget
  300. XXGrab*.converttype.topWidget: box5
  301. XXGrab*.converttype.topOffset: 15
  302. XXGrab*.converttype.orientation: horizontal
  303. XXGrab*.converttype.numColumns: 2
  304. XXGrab*.converttype.x: 5
  305. X
  306. XXGrab*.nodither.labelString: No Dither
  307. XXGrab*.nodither.set: true
  308. XXGrab*.dither.labelString: Dither
  309. XXGrab*.halftone.labelString: Halftone
  310. XXGrab*.mapbw.labelString: Map to B/W
  311. XXGrab*.mdither.labelString: M-Dither
  312. X
  313. X!----------------------------box 6
  314. XXGrab*.box6.x:   0
  315. XXGrab*.box6.topAttachment: attach_widget
  316. XXGrab*.box6.topWidget: converttype
  317. X
  318. X
  319. XXGrab*.splat.labelString: ------------------------------------------------------------
  320. X
  321. XXGrab*.OK.x:   110
  322. XXGrab*.OK.y:     25
  323. XXGrab*.OK.width:            80
  324. XXGrab*.OK.FontList: *-helvetica-bold-r-normal--14-*
  325. XXGrab*.OK.labelString: OK
  326. X
  327. XXGrab*.Dismiss.x:   265
  328. XXGrab*.Dismiss.y:     25
  329. XXGrab*.Dismiss.width:            80
  330. XXGrab*.Dismiss.FontList: *-helvetica-bold-r-normal--14-*
  331. XXGrab*.Dismiss.labelString: Dismiss
  332. X
  333. X
  334. X!----------------------------- pervasive resources
  335. XXGrab*FontList: *-helvetica-medium-r-normal--12-*
  336. XXGrab*XmText.FontList: *-helvetica-medium-r-normal--12-*
  337. XXGrab*XmToggleButton.FontList: *-helvetica-medium-r-normal--12-*
  338. XXGrab*XmLabel.FontList: *-helvetica-medium-r-normal--12-*
  339. XXGrab*XmLabel.borderWidth: 0
  340. XXGrab*XmToggleButton.borderWidth: 0
  341. XXGrab*XmForm.borderWidth: 0
  342. XXGrab*XmPushButton.shadowThickness: 3
  343. X
  344. XXGrab*XmToggleButton.marginHeight: 0
  345. XXGrab*XmRowColumn*adjustMargin: false
  346. X
  347. XXGrab*XmForm.background: #a3d1f2
  348. XXGrab*XmRowColumn.background: #a3d1f2
  349. XXGrab*XmLabel.background: #a3d1f2
  350. XXGrab*XmText*background: ivory
  351. XXGrab*XmToggleButton.background: #a3d1f2
  352. X!XGrab*XmPushButton.background: #d3f1ff
  353. X
  354. XXGrab*selstyle.foreground: navy
  355. XXGrab*outputXmFormat.foreground: navy
  356. XXGrab*psOptions.foreground: navy
  357. XXGrab*prOptions.foreground: navy
  358. XXGrab*outputLbl.foreground: navy
  359. XXGrab*foreground: navy
  360. XXGrab*background: #d3f1ff
  361. X
  362. XXGrab*selectColor: navy
  363. XXGrab*highlightColor: navy
  364. XXGrab*highlightThickness: 2
  365. X
  366. X! ========================================================================
  367. X! *
  368. X! * Name - XGrabxm.ad
  369. X! *
  370. X! * Version:    1.2
  371. X! *
  372. X! * ccsid:    @(#)XGrabxm.res    1.2 -06/28/93 09:13:40
  373. X! * from:     ccs/s.XGrabxm.res
  374. X! * date:     06/28/93 09:14:48
  375. X! *
  376. X! * Copyright (c) 1991-3 Bruce Schuchardt.
  377. X! * Read the file cpyright.h for full copyright inXmFormation.
  378. X! *
  379. X! *
  380. X! * Description: Application Defaults file for xgrabxm
  381. X! *
  382. X! *========================================================================
  383. X
  384. END_OF_FILE
  385. if test 10437 -ne `wc -c <'xgrabsc.2_3/XGrabxm.res'`; then
  386.     echo shar: \"'xgrabsc.2_3/XGrabxm.res'\" unpacked with wrong size!
  387. fi
  388. # end of 'xgrabsc.2_3/XGrabxm.res'
  389. fi
  390. if test -f 'xgrabsc.2_3/xgrabsc.c' -a "${1}" != "-c" ; then 
  391.   echo shar: Will not clobber existing file \"'xgrabsc.2_3/xgrabsc.c'\"
  392. else
  393. echo shar: Extracting \"'xgrabsc.2_3/xgrabsc.c'\" \(22410 characters\)
  394. sed "s/^X//" >'xgrabsc.2_3/xgrabsc.c' <<'END_OF_FILE'
  395. X/*========================================================================
  396. X *
  397. X * Name - xgrabsc.c
  398. X *
  399. X * ccs version:    1.31
  400. X *
  401. X * ccsid:    @(#)xgrabsc.c    1.31 - 06/28/93 09:13:50
  402. X * from:     ccs/s.xgrabsc.c
  403. X * date:     06/28/93 09:14:49
  404. X *
  405. X * Copyright (c) 1990-93 Bruce Schuchardt.
  406. X * Read the file cpyright.h for full copyright information.
  407. X *
  408. X * XmuClientWindow and TryChildren are Copyright 1989 by the Massachusetts
  409. X * Institute of Technology
  410. X *
  411. X * Permission to use, copy, modify, and distribute this [XmuClientWindow]
  412. X * software and its
  413. X * documentation for any purpose and without fee is hereby granted, provided 
  414. X * that the above copyright notice appear in all copies and that both that 
  415. X * copyright notice and this permission notice appear in supporting 
  416. X * documentation, and that the name of M.I.T. not be used in advertising
  417. X * or publicity pertaining to distribution of the software without specific, 
  418. X * written prior permission. M.I.T. makes no representations about the 
  419. X * suitability of this software for any purpose.  It is provided "as is"
  420. X * without express or implied warranty.
  421. X *
  422. X * Description:
  423. X *
  424. X * xgrabsc - grab screen images and store in files
  425. X *
  426. X *========================================================================
  427. X */
  428. X
  429. X#if defined(__hpux)
  430. X/* the folks at HP have decided to make things more difficult
  431. X */
  432. X#define XLIB_ILLEGAL_ACCESS
  433. X#endif
  434. X
  435. X
  436. X#include "cpyright.h"
  437. X#include "patchlevel.h"
  438. X#include "config.h"
  439. X#include "checkvm.h"
  440. X#include "cmdopts.h"
  441. X
  442. X#include <stdio.h>
  443. X
  444. X#include <X11/Xos.h>
  445. X#include <X11/Xlib.h>
  446. X#include <X11/Xutil.h>
  447. X#include <X11/cursorfont.h>
  448. X#include <X11/Xatom.h>
  449. X
  450. X#ifdef VMS
  451. X#include "XWDFile.h"
  452. X#else
  453. X#include <X11/XWDFile.h>
  454. X#endif /* VMS */
  455. X
  456. X#ifndef CARD32
  457. X#include <X11/Xmd.h>
  458. X#endif
  459. X
  460. X
  461. X#ifndef NO_VIRTUAL_WINDOW
  462. X#include "virtual.h"
  463. X#endif
  464. X
  465. X
  466. X#define MAX_CELLS  256
  467. X#define TRUE  1
  468. X#define FALSE 0
  469. X
  470. X
  471. Xtypedef enum {
  472. X  NO_DITHER=0,
  473. X  FS_DITHER,
  474. X  MATRIX_DITHER,
  475. X  MATRIX_HALFTONE,
  476. X  MAP_BW
  477. X} ditherType;
  478. X
  479. X
  480. Xtypedef unsigned char byte;
  481. Xtypedef unsigned long dw;
  482. Xtypedef unsigned int  word;
  483. X
  484. X
  485. X
  486. Xtypedef struct {
  487. X  XImage *ximage;
  488. X  word numcells;
  489. X  word red[MAX_CELLS], green[MAX_CELLS], blue[MAX_CELLS];
  490. X  byte used[MAX_CELLS];
  491. X} imageInfo;
  492. X
  493. X
  494. Xtypedef enum {
  495. X  sourceRect,
  496. X  sourceRoot,
  497. X  sourceId,
  498. X  sourceWd,
  499. X  sourceKey,
  500. X  sourceCoords
  501. X} sourceType;
  502. X
  503. Xtypedef enum {
  504. X  puzzleFormat,
  505. X  psFormat,
  506. X  simpleFormat,
  507. X  xwdFormat,
  508. X  pixmapFormat
  509. X} formatType;
  510. X
  511. X
  512. X
  513. X
  514. X#ifdef BCOPY
  515. X#ifdef MEMCPY
  516. X#undef MEMCPY
  517. X#endif
  518. X#define memcpy(x,y,c) bcopy(y,x,c)
  519. X#define memset(x,c)   bzero(x,c) /* well, I only use it for zeroing out stuff */
  520. X#endif
  521. X
  522. X#ifdef MEMCPY
  523. Xchar *memcpy();
  524. Xchar *memset();
  525. X#endif
  526. X
  527. X
  528. X#ifdef VMS
  529. X#define rindex strrchr
  530. X#endif
  531. X
  532. Xstatic Display *hDisplay;
  533. Xstatic int      hScreen;
  534. Xstatic Window   hRoot, vRoot;
  535. Xstatic int      displayCells;
  536. Xstatic char    *programName;
  537. Xstatic char    imageName[64];
  538. X
  539. Xstatic char    *version    = XGRABSC_VERSION;
  540. Xstatic int      patchLevel = XGRABSC_PATCHLEVEL;
  541. Xstatic int      verbose;
  542. X
  543. Xstatic word nr[MAX_CELLS], ng[MAX_CELLS], nb[MAX_CELLS];
  544. X
  545. Xstatic char   hexdigits[] = "0123456789abcdef";
  546. X
  547. Xstatic double pageWidth   = PAPER_WIDTH;
  548. Xstatic double pageHeight  = PAPER_HEIGHT;
  549. Xstatic double horizMargin = HORIZ_MARGIN;
  550. Xstatic double vertMargin  = VERT_MARGIN;
  551. Xstatic double horizInset  = PAPER_WIDTH - HORIZ_MARGIN - HORIZ_MARGIN;
  552. Xstatic double vertInset   = PAPER_HEIGHT - VERT_MARGIN - VERT_MARGIN;
  553. X
  554. Xstatic char        *outfileName;
  555. X
  556. XditherType  DitherKind;
  557. Xint         Halftone;
  558. Xint         ForceBitmap;
  559. X
  560. Xstatic int needColorImageProc;
  561. X
  562. X
  563. X/* most functions have been moved to seperate source include files */
  564. X
  565. X#include "process.hc"         /* color processing     */
  566. X#include "get.hc"             /* get images           */
  567. X#include "mem.hc"             /* memcpy, memset       */
  568. X#include "convert.hc"         /* color->bw conversion */
  569. X#include "write.hc"           /* output functions     */
  570. X
  571. X
  572. X
  573. X
  574. Xstatic Window xgTryChildren();
  575. X
  576. X/* versions of XmuGetClientWindow and screenNumberOfScreen.
  577. X * GetClientWindow is used so Xmu need not be linked (causes problems on
  578. X *  some platforms and configurations if Xt is not used)
  579. X * ScreenNumberOfScreen is used because some X implementations do not
  580. X *  include this function (HP in particular).
  581. X *
  582. X * The following three functions are from the X11R4 MIT distribution and
  583. X * are copyrighted by MIT (see the file header)
  584. X */
  585. X
  586. Xstatic Window GetClientWindow (win)
  587. X    Window win;
  588. X{
  589. X    Atom WM_STATE;
  590. X    Atom type = None;
  591. X    int format;
  592. X    unsigned long nitems, after;
  593. X    unsigned char *data;
  594. X    Window inf;
  595. X
  596. X    WM_STATE = XInternAtom(hDisplay, "WM_STATE", True);
  597. X    if (!WM_STATE)
  598. X    return win;
  599. X    XGetWindowProperty(hDisplay, win, WM_STATE, 0, 0, False, AnyPropertyType,
  600. X               &type, &format, &nitems, &after, &data);
  601. X    if (type)
  602. X    return win;
  603. X    inf = xgTryChildren(win, WM_STATE);
  604. X    if (!inf)
  605. X    inf = win;
  606. X    return inf;
  607. X}
  608. X
  609. Xstatic Window xgTryChildren (win, WM_STATE)
  610. X    Window win;
  611. X    Atom WM_STATE;
  612. X{
  613. X    Window root, parent;
  614. X    Window *children;
  615. X    unsigned int nchildren;
  616. X    unsigned int i;
  617. X    Atom type = None;
  618. X    int format;
  619. X    unsigned long nitems, after;
  620. X    unsigned char *data;
  621. X    Window inf = 0;
  622. X
  623. X    if (!XQueryTree(hDisplay, win, &root, &parent, &children, &nchildren))
  624. X    return 0;
  625. X    for (i = 0; !inf && (i < nchildren); i++) {
  626. X    XGetWindowProperty(hDisplay, children[i], WM_STATE, 0, 0, False,
  627. X               AnyPropertyType, &type, &format, &nitems,
  628. X               &after, &data);
  629. X    if (type)
  630. X        inf = children[i];
  631. X    }
  632. X    for (i = 0; !inf && (i < nchildren); i++)
  633. X    inf = xgTryChildren(children[i], WM_STATE);
  634. X    if (children) XFree((char *)children);
  635. X    return inf;
  636. X}
  637. X
  638. X
  639. X
  640. Xint ScreenNumberOfScreen (scr)
  641. X    register Screen *scr;
  642. X{
  643. X    register Display *dpy = scr->display;
  644. X    register Screen *dpyscr = dpy->screens;
  645. X    register int i;
  646. X
  647. X    for (i = 0; i < dpy->nscreens; i++, dpyscr++) {
  648. X    if (scr == dpyscr) return i;
  649. X    }
  650. X    return -1;
  651. X}
  652. X
  653. X
  654. X
  655. Xxgrabsc(argc, argv, env)
  656. X  int argc;
  657. X  char *argv[];  /* must have at least argv[0] == programName */
  658. X  char *env;
  659. X{
  660. X  char        *args[100], *arg;
  661. X  extern char *optarg;
  662. X  FILE        *outfile;
  663. X  XRectangle  xrect;
  664. X  XWindowAttributes xwa;
  665. X  imageInfo   image;
  666. X  int         argn, argi, polarity;
  667. X  int          cmdi, cmdargi;
  668. X  int         doAnd;
  669. X  int         doOr;
  670. X  int         doReverse;
  671. X  int         depth;
  672. X  int         noBell;
  673. X  int         psColor;
  674. X  int         brighten;
  675. X  int         grabServer;
  676. X  int         compress;
  677. X  int         sleepSeconds;
  678. X  int         postSelectSleepSeconds;
  679. X  int         andBits;
  680. X  int         orBits;
  681. X  int         encapsulate;
  682. X  Window      sourceWindow, childWindow, clientWindow, wmWindow, ignored;
  683. X  char       *ptr;
  684. X  char       *display;
  685. X  int         i, x, y;
  686. X  int         brightenFactor;
  687. X  sourceType  source;
  688. X  formatType  outputFormat;
  689. X  int         xpmFormat;
  690. X  int         landscape;
  691. X  int         binary;
  692. X  int          borders;
  693. X  int          checkLimits;
  694. X  int          preview;
  695. X  int         onlyEpsi;
  696. X  int         xwdxy;
  697. X
  698. X
  699. X  outfile     = stdout;
  700. X  outfileName = NULL;
  701. X  display     = NULL;
  702. X  programName = argv[0];
  703. X
  704. X  noBell       = FALSE;
  705. X  brighten     = FALSE;
  706. X  compress     = TRUE;
  707. X  DitherKind   = NO_DITHER;
  708. X  doAnd        = FALSE;
  709. X  doOr         = FALSE;
  710. X  doReverse    = FALSE;
  711. X  encapsulate  = FALSE;
  712. X  ForceBitmap  = FALSE;
  713. X  grabServer   = TRUE;
  714. X  Halftone     = FALSE;
  715. X  landscape    = FALSE;
  716. X  binary       = FALSE;
  717. X  sleepSeconds = 0;
  718. X  postSelectSleepSeconds = 0;
  719. X  verbose      = FALSE;
  720. X  borders      = TRUE;
  721. X#ifdef NO_PRINTER_MEMORY_CHECKS
  722. X  checkLimits  = FALSE;
  723. X#else
  724. X  checkLimits  = TRUE;
  725. X#endif
  726. X  preview      = FALSE;
  727. X  needColorImageProc = DEFAULT_NEED_COLORIMAGE_PROC;
  728. X
  729. X  source       = sourceRect;
  730. X  outputFormat = psFormat;
  731. X  psColor      = FALSE;
  732. X  onlyEpsi     = FALSE;
  733. X  xwdxy           = FALSE;
  734. X
  735. X
  736. X  /* merge environment options and command line options */
  737. X  args[0] = programName;
  738. X  if (env != NULL) {
  739. X    args[1] = env;
  740. X    for (argn=2; argn<100  &&
  741. X                (args[argn]=(char *)strchr(args[argn-1], ' ')) != NULL;
  742. X            argn++) {
  743. X      /* remove leading white space */
  744. X      while (*args[argn] == ' ' || *args[argn] == 9) {
  745. X        *(args[argn]) = '\0';
  746. X        args[argn]++;
  747. X      }
  748. X      if (*args[argn] == '|' || *args[argn] == '>') /* dbx leaves these in the cmd line */
  749. X        break;
  750. X    }
  751. X  }
  752. X  else
  753. X    argn = 1;
  754. X
  755. X  for (i=1; i<argc && argn<100; argn++, i++)
  756. X    args[argn] = argv[i];
  757. X
  758. X  
  759. X  for (argi=1; argi<argn; argi++) {
  760. X    arg = args[argi];
  761. X
  762. X    polarity = 1;
  763. X    if (arg[0] == '-') {
  764. X      arg++;
  765. X      if (arg[0] == '-') {
  766. X        arg++;
  767. X        polarity = 0;
  768. X      }
  769. X      else if (arg[0] == 'n' && arg[1] == 'o') {
  770. X        arg += 2;
  771. X    polarity = 0;
  772. X      }
  773. X    }
  774. X
  775. X    for (cmdi=0; cmdi<numCmds; cmdi++) {
  776. X      if (strcmp(arg, commands[cmdi].userstr) == 0)
  777. X        break;
  778. X    }
  779. X    if (cmdi >= numCmds) {
  780. X      fprintf(stderr, "%s: unknown option '%s'\n", programName, arg);
  781. X      exit(3);
  782. X    }
  783. X
  784. X    cmdargi = argi+1;
  785. X    argi += commands[cmdi].numargs;
  786. X    if (argi >= argn) {
  787. X      fprintf(stderr, "%s: not enough arguments for '%s'\n", programName, arg);
  788. X      exit(3);
  789. X    }
  790. X
  791. X    switch (commands[cmdi].command) {
  792. X      case CMD_DISPLAY:
  793. X        display = args[cmdargi];
  794. X        break;
  795. X      case CMD_BELL:
  796. X        noBell = !polarity;
  797. X        break;
  798. X      case CMD_GRABSERVER:
  799. X        grabServer = polarity;
  800. X        break;
  801. X      case CMD_OUTPUT:
  802. X        outfileName = args[cmdargi];
  803. X        break;
  804. X      case CMD_PRESLEEP:
  805. X        sleepSeconds = atoi(args[cmdargi]);
  806. X        if (sleepSeconds < 0) sleepSeconds = 0;
  807. X        break;
  808. X      case CMD_POSTSLEEP:
  809. X        postSelectSleepSeconds = atoi(args[cmdargi]);
  810. X        if (postSelectSleepSeconds < 0) postSelectSleepSeconds = 0;
  811. X        break;
  812. X      case CMD_VERBOSE:
  813. X        verbose = polarity;
  814. X        break;
  815. X      case CMD_BORDERS:
  816. X        borders = polarity;
  817. X    break;
  818. X      case CMD_NOBORDERS:
  819. X        borders = !polarity;
  820. X    break;
  821. X
  822. X
  823. X      case CMD_SOURCE_KEY:
  824. X        source = sourceKey;
  825. X        grabServer = FALSE;
  826. X    break;
  827. X      case CMD_SOURCE_COORDS:
  828. X      { short w,h,x,y;
  829. X    source = sourceCoords;
  830. X        sscanf(args[cmdargi], "%ix%i+%i+%i", &w, &h, &x, &y);
  831. X    xrect.width = w; 
  832. X    xrect.height = h;
  833. X    xrect.x = x;  
  834. X    xrect.y = y;
  835. X    break;
  836. X      }
  837. X
  838. X      case CMD_SOURCE_ID:
  839. X        source = sourceId;
  840. X        sourceWindow = 0;
  841. X        if (!sscanf(args[cmdargi], "%ix", &sourceWindow)) {
  842. X          fprintf(stderr, "%s: invalid window id '%s'\n", programName, args[cmdargi]);
  843. X      exit(3);
  844. X        }
  845. X        break;
  846. X      case CMD_SOURCE_RECT:
  847. X    source = sourceRect;
  848. X    break;
  849. X      case CMD_SOURCE_ROOT:
  850. X        source = sourceRoot;
  851. X        break;
  852. X      case CMD_SOURCE_WD:
  853. X        source = sourceWd;
  854. X        break;
  855. X
  856. X
  857. X
  858. X      case CMD_AND:
  859. X        doAnd = polarity;
  860. X    if (doAnd)
  861. X          andBits = atoi(args[cmdargi]);
  862. X        break;
  863. X      case CMD_OR:
  864. X        doOr = polarity;
  865. X    if (doOr)
  866. X          orBits = atoi(args[cmdargi]);
  867. X        break;
  868. X      case CMD_NOT:
  869. X        doReverse = polarity;
  870. X    break;
  871. X      case CMD_BRIGHTEN:
  872. X        brighten = polarity;
  873. X    if (brighten) {
  874. X          brightenFactor = atoi(args[cmdargi]);
  875. X          if (brightenFactor <= 0) {
  876. X            fprintf(stderr, "%s: brightening factor must be a positive number\n",
  877. X              programName);
  878. X            exit(3);
  879. X          }
  880. X      if (brightenFactor != 100)
  881. X            brighten = TRUE;
  882. X      else
  883. X        brighten = FALSE;
  884. X    }
  885. X        break;
  886. X
  887. X      case CMD_DITHER_MAP:
  888. X        ForceBitmap = TRUE;
  889. X        Halftone = FALSE;
  890. X        break;
  891. X      case CMD_DITHER_MATRIX:
  892. X        DitherKind = MATRIX_DITHER;
  893. X        Halftone = TRUE;
  894. X        ForceBitmap = FALSE;
  895. X        break;
  896. X      case CMD_DITHER_FS:
  897. X        if (!polarity) {
  898. X          DitherKind = NO_DITHER;
  899. X      Halftone = ForceBitmap = FALSE;
  900. X        }
  901. X        else {
  902. X          DitherKind = FS_DITHER;
  903. X          Halftone = TRUE;
  904. X          ForceBitmap = FALSE;
  905. X        }
  906. X        break;
  907. X      case CMD_DITHER_HALFTONE:
  908. X        DitherKind = MATRIX_HALFTONE;
  909. X        Halftone = TRUE;
  910. X        ForceBitmap = FALSE;
  911. X        break;
  912. X      case CMD_DITHER_NONE:
  913. X        DitherKind = NO_DITHER;
  914. X    Halftone = ForceBitmap = FALSE;
  915. X    break;
  916. X
  917. X
  918. X
  919. X      case CMD_OUTPUT_PS:
  920. X        psColor = FALSE;
  921. X        outputFormat = psFormat;
  922. X        break;
  923. X      case CMD_OUTPUT_CPS:
  924. X        psColor = polarity;
  925. X        outputFormat = psFormat;
  926. X    break;
  927. X      case CMD_OUTPUT_SIMPLE:
  928. X        outputFormat = simpleFormat;
  929. X        break;
  930. X      case CMD_OUTPUT_XWD:
  931. X        outputFormat = xwdFormat;
  932. X    xwdxy = FALSE;
  933. X        break;
  934. X      case CMD_OUTPUT_XWDXY:
  935. X        outputFormat = xwdFormat;
  936. X    xwdxy = TRUE;
  937. X        break;
  938. X      case CMD_OUTPUT_PIXMAP:
  939. X        xpmFormat = 1;
  940. X        outputFormat = pixmapFormat;
  941. X        break;
  942. X      case CMD_OUTPUT_XPM2:
  943. X        if (polarity) xpmFormat = 2;
  944. X    else if (xpmFormat == 2) xpmFormat = 1;
  945. X    outputFormat = pixmapFormat;
  946. X    break;
  947. X      case CMD_OUTPUT_XPM3:
  948. X        if (polarity) xpmFormat = 3;
  949. X    else if (xpmFormat == 3) xpmFormat = 1;
  950. X    outputFormat = pixmapFormat;
  951. X    break;
  952. X
  953. X      case CMD_OUTPUT_PUZZLE:
  954. X        outputFormat = puzzleFormat;
  955. X        break;
  956. X
  957. X      case CMD_LANDSCAPE:
  958. X        landscape = polarity;
  959. X    outputFormat = psFormat;
  960. X        break;
  961. X      case CMD_BIN:
  962. X        binary = polarity;
  963. X        outputFormat = psFormat;
  964. X    break;
  965. X      case CMD_COMPRESS:
  966. X        compress = polarity;
  967. X        outputFormat = psFormat;
  968. X        break;
  969. X      case CMD_EPS:
  970. X        encapsulate = polarity;
  971. X        outputFormat = psFormat;
  972. X    break;
  973. X      case CMD_PREVIEWONLY:
  974. X        onlyEpsi = polarity;
  975. X    preview = polarity;
  976. X        outputFormat = psFormat;
  977. X    break;
  978. X      case CMD_LIMIT:
  979. X        checkLimits = polarity;
  980. X        outputFormat = psFormat;
  981. X    break;
  982. X      case CMD_PREVIEW:
  983. X        preview = polarity;
  984. X        outputFormat = psFormat;
  985. X    break;  
  986. X      case CMD_PAGE:
  987. X        outputFormat = psFormat;
  988. X        sscanf(args[cmdargi], "%lfx%lf-%lf-%lf",
  989. X      &pageWidth, &pageHeight, &horizMargin, &vertMargin);
  990. X    horizInset = pageWidth - horizMargin - horizMargin;
  991. X    vertInset  = pageHeight - vertMargin - vertMargin;
  992. X        break;
  993. X      case CMD_COLORPROC:
  994. X        outputFormat = psFormat;
  995. X    needColorImageProc = polarity;
  996. X    break;
  997. X    }
  998. X  }
  999. X
  1000. X
  1001. X  if (verbose) {
  1002. X    fprintf(stderr, "%s: xgrabsc version %s\n", programName, version);
  1003. X    fprintf(stderr, "%s:         patchlevel %d\n", programName, patchLevel);
  1004. X    fprintf(stderr, "%s:         %s\n\n", programName, Copyright);
  1005. X  }
  1006. X
  1007. X  if (!display) display = (char *)getenv("DISPLAY");
  1008. X  hDisplay = XOpenDisplay(display);
  1009. X  if (!hDisplay) {
  1010. X    fprintf(stderr, "%s: could not open X display\n", programName);
  1011. X    exit(3);
  1012. X  }
  1013. X  hScreen  = DefaultScreen(hDisplay);
  1014. X  hRoot    = DefaultRootWindow(hDisplay);
  1015. X#ifndef NO_VIRTUAL_WINDOW
  1016. X  vRoot    = VirtualRootWindow(hDisplay, hScreen);
  1017. X#else
  1018. X  vRoot    = hRoot;
  1019. X#endif
  1020. X
  1021. X  depth  = DefaultDepth(hDisplay, hScreen);
  1022. X  if (DisplayCells(hDisplay, hScreen) > MAX_CELLS) {
  1023. X    fprintf(stderr, "%s: color table is too big for this program\n",
  1024. X      programName);
  1025. X    XCloseDisplay(hDisplay);
  1026. X    exit(3);
  1027. X  }
  1028. X
  1029. X  /* sleep if asked to do so */
  1030. X  if (sleepSeconds)
  1031. X    sleep(sleepSeconds);
  1032. X
  1033. X  /* grab the screen if asked to do so */
  1034. X  if (grabServer)
  1035. X    XGrabServer(hDisplay);
  1036. X
  1037. X  if (source != sourceId)
  1038. X    sourceWindow = hRoot;
  1039. X
  1040. X  childWindow = (Window)NULL;
  1041. X
  1042. X  switch (source) {
  1043. X    case sourceKey:
  1044. X      childWindow =
  1045. X#ifdef SELECTION_MASK
  1046. X          getWindowWhenKeyIsPressed(SELECTION_MASK)
  1047. X#else
  1048. X          getWindowWhenKeyIsPressed(ControlMask);
  1049. X#endif
  1050. X      if (!childWindow) {
  1051. X        fprintf(stderr, "%s: unable to find source window\n", programName);
  1052. X        XCloseDisplay(hDisplay);
  1053. X        exit(3);
  1054. X      }
  1055. X      break;
  1056. X    case sourceCoords:
  1057. X      /* already got the xrect in the command line processing section */
  1058. X      break;
  1059. X    case sourceId:
  1060. X      childWindow = sourceWindow;
  1061. X      break;
  1062. X    case sourceWd:
  1063. X      /* grab the image from the root window so menus will show up on top
  1064. X       * of the window */
  1065. X      childWindow=getWindow();
  1066. X      if (!childWindow) {
  1067. X        fprintf(stderr, "%s: unable to find source window\n", programName);
  1068. X        XCloseDisplay(hDisplay);
  1069. X        exit(3);
  1070. X      }
  1071. X      break;
  1072. X    case sourceRoot:
  1073. X      xrect.x = xrect.y = 0;
  1074. X      xrect.width  = DisplayWidth(hDisplay, hScreen);
  1075. X      xrect.height = DisplayHeight(hDisplay, hScreen);
  1076. X      break;
  1077. X    case sourceRect:
  1078. X    default:
  1079. X      if (!getRectangle(&xrect)) {
  1080. X        XCloseDisplay(hDisplay);
  1081. X        exit(3);
  1082. X      }
  1083. X      break;
  1084. X  }
  1085. X
  1086. X
  1087. X
  1088. X  clientWindow = (Window)NULL;
  1089. X  if (!borders  &&
  1090. X      (source == sourceKey || source == sourceWd || source == sourceId)  &&
  1091. X      childWindow != hRoot) {
  1092. X    /* look for a different client window */
  1093. X    clientWindow = GetClientWindow(childWindow);
  1094. X    if (clientWindow && clientWindow != childWindow) {
  1095. X      if (verbose)
  1096. X    fprintf(stderr, "%s: found subwindow 0x%x\n", programName, clientWindow);
  1097. X      wmWindow = childWindow;
  1098. X      childWindow = clientWindow;
  1099. X    }
  1100. X  }
  1101. X
  1102. X  if ((source == sourceKey && childWindow != hRoot) ||
  1103. X      source == sourceId ||
  1104. X      source == sourceWd) {
  1105. X
  1106. X    if (childWindow == hRoot) {
  1107. X      xrect.x      = 0;
  1108. X      xrect.y      = 0;
  1109. X      xrect.width  = DisplayWidth(hDisplay, hScreen);
  1110. X      xrect.height = DisplayHeight(hDisplay, hScreen);
  1111. X    }
  1112. X    else {
  1113. X
  1114. X      /* take the child window (and optional client/wm window info) and
  1115. X      * determine the portion of the root window that should be grabbed */
  1116. X
  1117. X      if (!XGetWindowAttributes(hDisplay, childWindow, &xwa)) {
  1118. X        fprintf(stderr, "%s: unable to get window coordinates\n", programName);
  1119. X        XCloseDisplay(hDisplay);
  1120. X        exit(3);
  1121. X      }
  1122. X
  1123. X      /* get the correct screen and root window for the selected window,
  1124. X        * and if it isn't the default, muck with the global state of the
  1125. X        * program a bit
  1126. X        */
  1127. X      i = ScreenNumberOfScreen(xwa.screen);
  1128. X      if (i != hScreen) {
  1129. X        hRoot   = xwa.root;
  1130. X        hScreen = i;
  1131. X#ifndef NO_VIRTUAL_WINDOW
  1132. X        vRoot   = VirtualRootWindow(hDisplay, hScreen);
  1133. X#else
  1134. X        vRoot   = hRoot;
  1135. X#endif
  1136. X        depth   = DefaultDepth(hDisplay, hScreen);
  1137. X      }
  1138. X
  1139. X      sourceWindow = vRoot;
  1140. X      if (!borders) {
  1141. X        xrect.x      = 0;
  1142. X        xrect.y      = 0;
  1143. X        xrect.width  = xwa.width;
  1144. X        xrect.height = xwa.height;
  1145. X      }
  1146. X      else {
  1147. X        xrect.x      = -xwa.border_width;
  1148. X        xrect.y      = -xwa.border_width;
  1149. X        xrect.width  = xwa.width + (2 * xwa.border_width);
  1150. X        xrect.height = xwa.height + (2 * xwa.border_width);
  1151. X      }
  1152. X
  1153. X      /* translate the rectangle coordinates to root-window coordinates */
  1154. X      if (!XTranslateCoordinates(hDisplay, childWindow, vRoot,
  1155. X            (int)(xrect.x), (int)(xrect.y), &x, &y, &ignored)) {
  1156. X    fprintf(stderr, "%s: unable to translate window coordinates\n", programName);
  1157. X    XCloseDisplay(hDisplay);
  1158. X    exit(3);
  1159. X      }
  1160. X      xrect.x = (short)x;   /* why did they make rectangle coords shorts? */
  1161. X      xrect.y = (short)y;
  1162. X
  1163. X
  1164. X      if (hRoot == vRoot) {
  1165. X        /* do some clipping here, since it's cheap */
  1166. X        i = DisplayWidth(hDisplay, hScreen);
  1167. X        if (xrect.x + xrect.width > i) {
  1168. X          x = i - (int)(xrect.x);
  1169. X          if (x < 0) x = 0;
  1170. X          xrect.width = x;
  1171. X        }
  1172. X        i = DisplayHeight(hDisplay, hScreen);
  1173. X        if (xrect.y + xrect.height > i) {
  1174. X          x = i - (int)(xrect.y);
  1175. X          if (x < 0) x = 0;
  1176. X          xrect.height = x;
  1177. X        }
  1178. X      }
  1179. X    }
  1180. X  }
  1181. X
  1182. X
  1183. X  if (verbose)
  1184. X    fprintf(stderr, "%s: bounding box is [x=%d y=%d w=%d h=%d]\n", programName, xrect.x, xrect.y,
  1185. X                    xrect.width, xrect.height);
  1186. X
  1187. X  /* sleep if asked to do so */
  1188. X  if (postSelectSleepSeconds) {
  1189. X    if (grabServer) {
  1190. X      XUngrabServer(hDisplay);
  1191. X      XSync(hDisplay, FALSE);
  1192. X    }
  1193. X    sleep(postSelectSleepSeconds);
  1194. X    if (grabServer)
  1195. X      XGrabServer(hDisplay);
  1196. X  }
  1197. X
  1198. X
  1199. X  /* get the image bounded by the rectangle from the source window */
  1200. X  if (!noBell)
  1201. X    XBell(hDisplay, 50);
  1202. X
  1203. X  if (!getImage(&xrect, &image, sourceWindow, childWindow)) {
  1204. X    XCloseDisplay(hDisplay);
  1205. X    exit(3);
  1206. X  }
  1207. X  if (grabServer)
  1208. X    XUngrabServer(hDisplay);
  1209. X
  1210. X  if (!noBell) {
  1211. X    XBell(hDisplay, 20);
  1212. X    XBell(hDisplay, 30);
  1213. X  }
  1214. X
  1215. X  XFlush(hDisplay);
  1216. X
  1217. X
  1218. X
  1219. X  /* do color image processing/conversions */
  1220. X
  1221. X  if (depth >= 2) {
  1222. X    if (brighten)
  1223. X      brightenColors(&image, brightenFactor);
  1224. X    if (doAnd)
  1225. X      alterPlanes(&image, TRUE, andBits);
  1226. X    if (doOr)
  1227. X      alterPlanes(&image, FALSE, orBits);
  1228. X  }
  1229. X  
  1230. X  if (doReverse)
  1231. X    reverseColors(&image);
  1232. X
  1233. X  if (depth >= 2) {
  1234. X    if (! (preview && psColor) ) {
  1235. X      if (ForceBitmap) {
  1236. X        pixmap2bitmap(&image);
  1237. X        depth = 1;
  1238. X      }
  1239. X      else if (Halftone)
  1240. X        pixmap2halftone(&image, DitherKind);
  1241. X      else
  1242. X        compressColormap(&image);
  1243. X    }
  1244. X    else
  1245. X      compressColormap(&image);
  1246. X  }
  1247. X
  1248. X
  1249. X  /* open the output stream */
  1250. X  if (outfileName) {
  1251. X    outfile = fopen(outfileName, "w");
  1252. X    if (!outfile) {
  1253. X      fprintf(stderr, "%s: ", programName);
  1254. X      perror(outfileName);
  1255. X      exit(3);
  1256. X    }
  1257. X    /* form an image name based on the file name */
  1258. X    {
  1259. X    char *img = rindex(outfileName, '/');
  1260. X    if (img) strcpy(imageName, img + 1);
  1261. X    else strcpy(imageName, outfileName);
  1262. X    ptr = rindex(imageName, '.');  /* Drop the final extension */
  1263. X    if (ptr) *ptr = '\0';
  1264. X    }
  1265. X  }
  1266. X  else
  1267. X    strcpy(imageName,"unnamed");
  1268. X
  1269. X
  1270. X  /* write to the output stream in the requested format */
  1271. X  switch (outputFormat) {
  1272. X    case xwdFormat:
  1273. X      writeXWD(&image, outfile, xwdxy);
  1274. X      break;
  1275. X    case simpleFormat:
  1276. X      writeSimple(&image, outfile);
  1277. X      break;
  1278. X    case puzzleFormat:
  1279. X      writePuzzle(&image, outfile);
  1280. X      break;
  1281. X    case pixmapFormat:
  1282. X      if (image.ximage->depth <= 1)
  1283. X        writeXYPixmap(&image, outfile);
  1284. X      else
  1285. X        writeZPixmap(xpmFormat, &image, outfile);
  1286. X      break;
  1287. X    case psFormat:
  1288. X    default:
  1289. X      if (onlyEpsi)
  1290. X        writeOnlyPreview(&image, outfile);
  1291. X      else if (psColor && image.ximage->depth >= 2)
  1292. X        writeColorPS(&image, outfile, compress, encapsulate,
  1293. X                    preview, landscape, binary, checkLimits);
  1294. X      else
  1295. X        writePostscript(&image, outfile, compress, encapsulate,
  1296. X                    preview, landscape, binary, checkLimits);
  1297. X      break;
  1298. X  }
  1299. X
  1300. X
  1301. X  XDestroyImage(image.ximage);
  1302. X  XCloseDisplay(hDisplay);
  1303. X  if (outfileName)
  1304. X    fclose(outfile);
  1305. X
  1306. X  exit(0);
  1307. X}
  1308. X
  1309. X
  1310. X
  1311. X
  1312. X
  1313. X#ifndef NO_MAIN
  1314. Xmain(argc, argv)
  1315. X  int argc;
  1316. X  char *argv[];
  1317. X{
  1318. X  char *env;
  1319. X  env = (char *)getenv("XGRABSC");
  1320. X  xgrabsc(argc, argv, env);
  1321. X}
  1322. X#endif
  1323. END_OF_FILE
  1324. if test 22410 -ne `wc -c <'xgrabsc.2_3/xgrabsc.c'`; then
  1325.     echo shar: \"'xgrabsc.2_3/xgrabsc.c'\" unpacked with wrong size!
  1326. fi
  1327. # end of 'xgrabsc.2_3/xgrabsc.c'
  1328. fi
  1329. if test -f 'xgrabsc.2_3/xgrabxm.c' -a "${1}" != "-c" ; then 
  1330.   echo shar: Will not clobber existing file \"'xgrabsc.2_3/xgrabxm.c'\"
  1331. else
  1332. echo shar: Extracting \"'xgrabsc.2_3/xgrabxm.c'\" \(17554 characters\)
  1333. sed "s/^X//" >'xgrabsc.2_3/xgrabxm.c' <<'END_OF_FILE'
  1334. X/*========================================================================
  1335. X *
  1336. X * Name - xgrabxm.c
  1337. X *
  1338. X * Version:    1.5
  1339. X *
  1340. X * ccsid:    @(#)xgrabxm.c    1.5 -06/28/93 09:13:55
  1341. X * from:     ccs/s.xgrabxm.c
  1342. X * date:     06/28/93 09:14:49
  1343. X *
  1344. X * Copyright (c) 1990-93 Bruce Schuchardt.
  1345. X * Read the file cpyright.h for full copyright information.
  1346. X *
  1347. X *
  1348. X * Description:
  1349. X *
  1350. X * xgrab.c - interactive front for xgrabsc
  1351. X *
  1352. X *========================================================================
  1353. X */
  1354. X#include "cpyright.h"
  1355. X#include "patchlevel.h"
  1356. X#include "config.h"
  1357. X
  1358. X#include <stdio.h>
  1359. X#include <X11/Intrinsic.h>
  1360. X#include <X11/StringDefs.h>
  1361. X#include <X11/Shell.h>
  1362. X#include <Xm/Xm.h>
  1363. X#include <Xm/Form.h>
  1364. X#include <Xm/Label.h>
  1365. X#include <Xm/PushB.h>
  1366. X#include <Xm/RowColumn.h>
  1367. X#include <Xm/ToggleB.h>
  1368. X#include <Xm/Text.h>
  1369. X
  1370. Xstatic char *fallback_resources[] = {
  1371. X#include "xgrabxm_ad.h"
  1372. X  NULL
  1373. X  };
  1374. X
  1375. X
  1376. Xstatic Display *hDisplay;
  1377. X
  1378. Xtypedef enum {
  1379. X  HITWIN = 1,
  1380. X  STRETCH,
  1381. X  KEY,
  1382. X  ROOT,
  1383. X
  1384. X  XWD,
  1385. X  XWDXY,
  1386. X  PS,
  1387. X  BITMAP,
  1388. X  BITMAP2,
  1389. X  BITMAP3,
  1390. X  PUZZLE,
  1391. X  SIMPLE,
  1392. X
  1393. X  NO_DITHER,
  1394. X  DITHER,
  1395. X  MDITHER,
  1396. X  HALFTONE,
  1397. X  MAPBW,
  1398. X
  1399. X  REVERSE,
  1400. X
  1401. X  TOFILE,
  1402. X  TOPRN,
  1403. X
  1404. X  PS_NORMAL,
  1405. X  PS_EPS,
  1406. X  PS_EPSI,
  1407. X  PS_EPSIONLY,
  1408. X  PS_LANDSCAPE
  1409. X  
  1410. X  } radioType;
  1411. X
  1412. XradioType encValue = PS_NORMAL;
  1413. XradioType cnvValue = NO_DITHER;
  1414. XradioType selValue = STRETCH;
  1415. XradioType fmtValue = PS;
  1416. XradioType outValue = TOFILE;
  1417. X
  1418. X
  1419. X
  1420. Xvoid encValueChanged(widget, newValue, tag)
  1421. X  Widget widget;
  1422. X  void *tag;
  1423. X  radioType newValue;
  1424. X{
  1425. X  if (newValue == encValue) /* turning it off */
  1426. X    encValue = PS_NORMAL;
  1427. X  else
  1428. X    encValue = newValue;
  1429. X}
  1430. X
  1431. X
  1432. Xvoid cnvValueChanged(widget, newValue, tag)
  1433. X  Widget widget;
  1434. X  void *tag;
  1435. X  radioType newValue;
  1436. X{
  1437. X  if (newValue == cnvValue) /* turning it off */
  1438. X    cnvValue = NO_DITHER;
  1439. X  else
  1440. X    cnvValue = newValue;
  1441. X}
  1442. X
  1443. X
  1444. Xvoid selValueChanged(widget, newValue, tag)
  1445. X  Widget widget;
  1446. X  void *tag;
  1447. X  radioType newValue;
  1448. X{
  1449. X  radioType oldValue = selValue;
  1450. X  
  1451. X  if (newValue == selValue) /* turning it off */
  1452. X    selValue = STRETCH;
  1453. X  else
  1454. X    selValue = newValue;
  1455. X#ifdef DEBUGGING
  1456. X  fprintf(stderr, "old sel value = %d   new = %d\n", oldValue, selValue);
  1457. X#endif
  1458. X}
  1459. X
  1460. Xvoid fmtValueChanged(widget, newValue, tag)
  1461. X  Widget widget;
  1462. X  void *tag;
  1463. X  radioType newValue;
  1464. X{
  1465. X  if (newValue == fmtValue) /* turning it off */
  1466. X    fmtValue = PS;
  1467. X  else
  1468. X    fmtValue = newValue;
  1469. X}
  1470. X
  1471. Xvoid outValueChanged(widget, newValue, tag)
  1472. X  Widget widget;
  1473. X  void *tag;
  1474. X  radioType newValue;
  1475. X{
  1476. X  if (newValue == encValue) /* turning it off */
  1477. X    outValue = TOFILE;
  1478. X  else
  1479. X    outValue = newValue;
  1480. X}
  1481. X
  1482. X
  1483. XWidget selBtns, formatBtns, psColr, encBtns, psComp, sltext, psltext,
  1484. X       psLim, 
  1485. X       psBin, borderBtn, horizMargin, vertMargin, pgHeight, pgWidth,
  1486. X       cnvBtns, revBtn, brtext, outBtns, filenm, prncmd, dispBtn, hostnm;
  1487. XWidget hShell;
  1488. X
  1489. XXtAppContext appContext;
  1490. X
  1491. X
  1492. Xstatic char* stradi(ptr, i)    /* Add an integer to a string */
  1493. X    char* ptr;
  1494. X    int i; {
  1495. X
  1496. X    sprintf(ptr + strlen(ptr), "%d", i);
  1497. X    return ptr;
  1498. X}
  1499. X
  1500. Xstatic char* stradw(ptr, s)   /* Add a string to another, with no ws */
  1501. X    char* ptr;
  1502. X    char* s; {
  1503. X
  1504. X    char* ou = ptr + strlen(ptr);
  1505. X
  1506. X    while (isspace(*s)) {
  1507. X    ++s;
  1508. X    }
  1509. X    while (*s && !isspace(*s)) {
  1510. X    *ou++ = *s++;
  1511. X    }
  1512. X    *ou = '\0';
  1513. X
  1514. X    return ptr;
  1515. X}
  1516. X
  1517. X
  1518. Xstatic void doGrab() {
  1519. X  char tmp[257];
  1520. X  char cmdargs[200];
  1521. X  char piper[200];
  1522. X  char cmd[500];
  1523. X  char *txt;
  1524. X  int  s, d, len, num;
  1525. X  int  sltime, psltime;
  1526. X  int  bright;
  1527. X  Boolean state;
  1528. X
  1529. X  cmdargs[0] = '\0';
  1530. X  piper[0] = '\0';
  1531. X
  1532. X  XtVaGetValues(sltext, XmNvalue, &txt, NULL);
  1533. X  sltime = atoi(txt);
  1534. X  if (sltime < 0) sltime = 0;
  1535. X  sprintf(tmp, "-sleep %d ", sltime);
  1536. X  strcat(cmdargs, tmp);
  1537. X
  1538. X  XtVaGetValues(psltext, XmNvalue, &txt, NULL);
  1539. X  psltime = atoi(txt);
  1540. X  if (psltime < 0) psltime = 0;
  1541. X  sprintf(tmp, "-post %d ", psltime);
  1542. X  strcat(cmdargs, tmp);
  1543. X
  1544. X  XtVaGetValues(brtext, XmNvalue, &txt, NULL);
  1545. X  bright = atoi(txt);
  1546. X  sprintf(tmp, "-brighten %d ", bright);
  1547. X  strcat(cmdargs, tmp);
  1548. X
  1549. X  XtVaGetValues(borderBtn, XmNset, &state, NULL);
  1550. X  if (!state)
  1551. X    strcat(cmdargs, "-");
  1552. X  strcat(cmdargs, "-bdrs ");
  1553. X
  1554. X  XtVaGetValues(revBtn, XmNset, &state, NULL);
  1555. X  if (!state)
  1556. X    strcat(cmdargs, "-");
  1557. X  strcat(cmdargs, "-reverse ");
  1558. X
  1559. X  switch (selValue) {
  1560. X    case HITWIN:
  1561. X      strcat(cmdargs, "-click ");
  1562. X      break;
  1563. X    case KEY:
  1564. X      strcat(cmdargs, "-key ");
  1565. X      break;
  1566. X    case ROOT:
  1567. X      strcat(cmdargs, "-root ");
  1568. X      break;
  1569. X    case STRETCH:
  1570. X    default:
  1571. X      strcat(cmdargs, "-stretch ");
  1572. X      break;
  1573. X  }
  1574. X  switch (fmtValue) {
  1575. X    case XWD:
  1576. X      strcat(cmdargs, "-xwd ");
  1577. X      break;
  1578. X    case XWDXY:
  1579. X      strcat(cmdargs, "-xwdxy ");
  1580. X      break;
  1581. X    case BITMAP:
  1582. X      strcat(cmdargs, "-bm ");
  1583. X      break;
  1584. X    case BITMAP2:
  1585. X      strcat(cmdargs, "-bm2 ");
  1586. X      break;
  1587. X    case BITMAP3:
  1588. X      strcat(cmdargs, "-bm3 ");
  1589. X      break;
  1590. X    case PUZZLE:
  1591. X      strcat(cmdargs, "-puzzle ");
  1592. X      break;
  1593. X    case SIMPLE:
  1594. X      strcat(cmdargs, "-simple ");
  1595. X      break;
  1596. X    case PS:
  1597. X    default:
  1598. X      XtVaGetValues(psColr, XmNset, &state, NULL);
  1599. X      if (!state)
  1600. X        strcat(cmdargs, "-ps ");
  1601. X      else
  1602. X        strcat(cmdargs, "-cps ");
  1603. X
  1604. X      switch (encValue) {
  1605. X        case PS_EPS:
  1606. X          strcat(cmdargs, "-eps ");
  1607. X      break;
  1608. X    case PS_EPSI:
  1609. X      strcat(cmdargs, "-preview ");
  1610. X      break;
  1611. X    case PS_EPSIONLY:
  1612. X      strcat(cmdargs, "-previewonly ");
  1613. X      break;
  1614. X    case PS_LANDSCAPE:
  1615. X      strcat(cmdargs, "-landscape ");
  1616. X      break;
  1617. X    default:
  1618. X      break;
  1619. X      }
  1620. X
  1621. X      XtVaGetValues(psComp, XmNset, &state, NULL);
  1622. X      if (!state)
  1623. X        strcat(cmdargs, "-");
  1624. X      strcat(cmdargs, "-compress ");
  1625. X      XtVaGetValues(psBin, XmNset, &state, NULL);
  1626. X      if (!state)
  1627. X        strcat(cmdargs, "-");
  1628. X      strcat(cmdargs, "-bin ");
  1629. X
  1630. X      XtVaGetValues(psLim, XmNset, &state, NULL);
  1631. X      if (!state)
  1632. X        strcat(cmdargs, "-");
  1633. X      strcat(cmdargs, "-limit ");
  1634. X
  1635. X      strcat(cmdargs, "-page ");
  1636. X      XtVaGetValues(pgWidth, XmNvalue, &txt, NULL);
  1637. X      if (strlen(txt))    stradw(cmdargs, txt);
  1638. X      else                stradi(cmdargs, PAPER_WIDTH);
  1639. X      strcat(cmdargs, "x");
  1640. X      XtVaGetValues(pgHeight, XmNvalue, &txt, NULL);
  1641. X      if (strlen(txt))    stradw(cmdargs, txt);
  1642. X      else                stradi(cmdargs, PAPER_HEIGHT);
  1643. X      strcat(cmdargs, "-");
  1644. X      XtVaGetValues(horizMargin, XmNvalue, &txt, NULL);
  1645. X      if (strlen(txt))    stradw(cmdargs, txt);
  1646. X      else                stradi(cmdargs, HORIZ_MARGIN);
  1647. X      strcat(cmdargs, "-");
  1648. X      XtVaGetValues(horizMargin, XmNvalue, &txt, NULL);
  1649. X      if (strlen(txt))    stradw(cmdargs, txt);
  1650. X      else                stradi(cmdargs, VERT_MARGIN);
  1651. X      strcat(cmdargs, " ");
  1652. X
  1653. X      break;
  1654. X  }
  1655. X  switch (cnvValue) {
  1656. X    case DITHER:
  1657. X      strcat(cmdargs, "-dither ");
  1658. X      break;
  1659. X    case MDITHER:
  1660. X      strcat(cmdargs, "-mdither ");
  1661. X      break;
  1662. X    case HALFTONE:
  1663. X      strcat(cmdargs, "-halftone ");
  1664. X      break;
  1665. X    case MAPBW:
  1666. X      strcat(cmdargs, "-bw ");
  1667. X      break;
  1668. X    default:
  1669. X      break;
  1670. X  }
  1671. X  switch (outValue) {
  1672. X    case TOPRN:
  1673. X      XtVaGetValues(prncmd, XmNvalue, &txt, NULL);
  1674. X      if (strlen(txt)) {
  1675. X        strcat(piper, " | ");
  1676. X        strcat(piper, txt);
  1677. X      }
  1678. X      break;
  1679. X    case TOFILE:
  1680. X    default:
  1681. X      strcat(cmdargs, "-o ");
  1682. X      XtVaGetValues(filenm, XmNvalue, &txt, NULL);
  1683. X      if (strlen(txt)) {
  1684. X        strcat(cmdargs, txt);
  1685. X#ifdef BUMP_FILENAMES
  1686. X    len = strlen(txt);
  1687. X    for (s=0; s<len && (txt[s] != '.'); s++)
  1688. X    {}
  1689. X    strcpy(tmp, txt);
  1690. X    tmp[s] = '\0';
  1691. X    d = s;
  1692. X    while (d > 0  &&  ('0' <= txt[d-1]  &&  txt[d-1] <= '9'))
  1693. X      d--;
  1694. X    if ('0' <= txt[d]  && txt[d] <= '9')
  1695. X      num = atoi(&tmp[d]);
  1696. X    else
  1697. X      num = 0;
  1698. X    num++;
  1699. X    sprintf(&tmp[d], "%d", num);
  1700. X    strcat(tmp, &txt[s]);
  1701. X    XtVaSetValues(filenm, XmNvalue, tmp, NULL);
  1702. X#endif
  1703. X      }
  1704. X      else {
  1705. X        strcat(cmdargs, "screen.dmp");
  1706. X    XtVaSetValues(filenm, XmNvalue, "screen.dmp", NULL);
  1707. X      }
  1708. X      strcat(cmdargs, " ");
  1709. X      break;
  1710. X  }
  1711. X
  1712. X  XtVaGetValues(dispBtn, XmNset, &state, NULL);
  1713. X  if (state) {
  1714. X    XtVaGetValues(hostnm, XmNvalue, &txt, NULL);
  1715. X    strcat(cmdargs, "-d ");
  1716. X    if (strlen(txt)) {
  1717. X      strcat(cmdargs, txt);
  1718. X      strcat(cmdargs, " ");
  1719. X    }
  1720. X    else
  1721. X      strcat(cmdargs, ":0 ");
  1722. X  }
  1723. X
  1724. X  sprintf(cmd, "xgrabsc %s%s\n", cmdargs, piper);
  1725. X#ifdef DEBUGGING
  1726. X  fputs(cmd, stderr);
  1727. X#else
  1728. X  /* try to make the window iconic */
  1729. X  XtUnmapWidget(hShell);
  1730. X  XSync(hDisplay, False);
  1731. X  system(cmd);
  1732. X  XtMapWidget(hShell);
  1733. X#endif
  1734. X}
  1735. X
  1736. X
  1737. X
  1738. X
  1739. Xstatic void doDismiss() {
  1740. X  if (hShell) {
  1741. X    XtDestroyWidget(hShell);
  1742. X    hShell = NULL;
  1743. X    exit(0);
  1744. X  }
  1745. X}
  1746. X
  1747. X
  1748. X
  1749. X
  1750. Xstatic void createWindow() {
  1751. X  Widget dialog, button, box1, box2, box3, box4, box5, box6;
  1752. X
  1753. X  dialog = XtVaCreateManagedWidget("dialog", xmFormWidgetClass, hShell,
  1754. X           NULL);
  1755. X           XtVaCreateManagedWidget("title",  xmLabelWidgetClass, dialog,
  1756. X           NULL);
  1757. X
  1758. X
  1759. X  /* selection options */
  1760. X  /* input options */
  1761. X  box1 = XtVaCreateManagedWidget("box1", xmFormWidgetClass, dialog, NULL);
  1762. X
  1763. X           XtVaCreateManagedWidget("inputLbl", xmLabelWidgetClass, box1,
  1764. X       NULL);
  1765. X
  1766. X  dispBtn= XtVaCreateManagedWidget("host", xmToggleButtonWidgetClass, box1,
  1767. X       NULL);
  1768. X
  1769. X  hostnm = XtVaCreateManagedWidget("hostText", xmTextWidgetClass, box1,
  1770. X           NULL);
  1771. X
  1772. X  if (getenv("DISPLAY"))
  1773. X    XtVaSetValues(hostnm, XmNvalue, getenv("DISPLAY"), NULL);
  1774. X
  1775. X  selBtns = XmCreateRadioBox(box1, "selectiontype", NULL, 0);
  1776. X           XtManageChild(selBtns);
  1777. X       
  1778. X  button = XtVaCreateManagedWidget("click", xmToggleButtonWidgetClass, selBtns,
  1779. X       NULL);
  1780. X           XtAddCallback(button, XmNvalueChangedCallback, selValueChanged,
  1781. X       HITWIN);
  1782. X
  1783. X  button = XtVaCreateManagedWidget("stretch", xmToggleButtonWidgetClass, selBtns,
  1784. X       NULL);
  1785. X           XtAddCallback(button, XmNvalueChangedCallback, selValueChanged,
  1786. X       STRETCH);
  1787. X
  1788. X  button = XtVaCreateManagedWidget("key", xmToggleButtonWidgetClass, selBtns,
  1789. X       NULL);
  1790. X           XtAddCallback(button, XmNvalueChangedCallback, selValueChanged,
  1791. X       KEY);
  1792. X
  1793. X  button = XtVaCreateManagedWidget("root", xmToggleButtonWidgetClass, selBtns,
  1794. X       NULL);
  1795. X           XtAddCallback(button, XmNvalueChangedCallback, selValueChanged,
  1796. X       ROOT);
  1797. X
  1798. X           XtVaCreateManagedWidget("sleeplbl", xmLabelWidgetClass, box1,
  1799. X           NULL);
  1800. X
  1801. X  sltext = XtVaCreateManagedWidget("sleeptime", xmTextWidgetClass, box1,
  1802. X           NULL);
  1803. X
  1804. X           XtVaCreateManagedWidget("psleeplbl", xmLabelWidgetClass, box1,
  1805. X           NULL);
  1806. X
  1807. X  psltext = XtVaCreateManagedWidget("psleeptime", xmTextWidgetClass, box1,
  1808. X           NULL);
  1809. X
  1810. X  box2 = XtVaCreateManagedWidget("box2", xmFormWidgetClass, dialog, NULL);
  1811. X
  1812. X  /* output options */
  1813. X           XtVaCreateManagedWidget("outputFormat", xmLabelWidgetClass, box2,
  1814. X           NULL);
  1815. X
  1816. X  formatBtns = XmCreateRadioBox(box2, "formattype", NULL, 0);
  1817. X       XtManageChild(formatBtns);
  1818. X       
  1819. X  button = XtVaCreateManagedWidget("xwd", xmToggleButtonWidgetClass, formatBtns,
  1820. X       NULL);
  1821. X           XtAddCallback(button, XmNvalueChangedCallback, fmtValueChanged,
  1822. X       XWD);
  1823. X
  1824. X  button = XtVaCreateManagedWidget("xwdxy", xmToggleButtonWidgetClass, formatBtns,
  1825. X       NULL);
  1826. X           XtAddCallback(button, XmNvalueChangedCallback, fmtValueChanged,
  1827. X       XWDXY);
  1828. X
  1829. X  button = XtVaCreateManagedWidget("ps", xmToggleButtonWidgetClass, formatBtns,
  1830. X       NULL);
  1831. X           XtAddCallback(button, XmNvalueChangedCallback, fmtValueChanged,
  1832. X       PS);
  1833. X
  1834. X  button = XtVaCreateManagedWidget("xpm", xmToggleButtonWidgetClass, formatBtns,
  1835. X       NULL);
  1836. X           XtAddCallback(button, XmNvalueChangedCallback, fmtValueChanged,
  1837. X       BITMAP);
  1838. X
  1839. X  button = XtVaCreateManagedWidget("xpm2", xmToggleButtonWidgetClass, formatBtns,
  1840. X       NULL);
  1841. X           XtAddCallback(button, XmNvalueChangedCallback, fmtValueChanged,
  1842. X       BITMAP2);
  1843. X
  1844. X  button = XtVaCreateManagedWidget("xpm3", xmToggleButtonWidgetClass, formatBtns,
  1845. X       NULL);
  1846. X           XtAddCallback(button, XmNvalueChangedCallback, fmtValueChanged,
  1847. X       BITMAP3);
  1848. X
  1849. X  button = XtVaCreateManagedWidget("puzzle", xmToggleButtonWidgetClass, formatBtns,
  1850. X       NULL);
  1851. X           XtAddCallback(button, XmNvalueChangedCallback, fmtValueChanged,
  1852. X       PUZZLE);
  1853. X
  1854. X
  1855. X
  1856. X  /* postscript options */
  1857. X  box3 = XtVaCreateManagedWidget("box3", xmFormWidgetClass, dialog, NULL);
  1858. X
  1859. X           XtVaCreateManagedWidget("psOptions", xmLabelWidgetClass, box3,
  1860. X           NULL);
  1861. X
  1862. X  psComp = XtVaCreateManagedWidget("compress", xmToggleButtonWidgetClass, box3,
  1863. X       NULL);
  1864. X
  1865. X  psColr = XtVaCreateManagedWidget("color", xmToggleButtonWidgetClass, box3,
  1866. X       NULL);
  1867. X
  1868. X           XtVaCreateManagedWidget("pageWidth", xmLabelWidgetClass, box3,
  1869. X           NULL);
  1870. X
  1871. X  pgWidth = XtVaCreateManagedWidget("pageWidthText",xmTextWidgetClass, box3,
  1872. X           NULL);
  1873. X
  1874. X           XtVaCreateManagedWidget("pageHeight", xmLabelWidgetClass, box3,
  1875. X           NULL);
  1876. X
  1877. X  pgHeight = XtVaCreateManagedWidget("pageHeightText",xmTextWidgetClass, box3,
  1878. X           NULL);
  1879. X
  1880. X           XtVaCreateManagedWidget("horizMargin", xmLabelWidgetClass, box3,
  1881. X           NULL);
  1882. X
  1883. X  horizMargin = XtVaCreateManagedWidget("horizMarginText",xmTextWidgetClass, box3,
  1884. X           NULL);
  1885. X
  1886. X           XtVaCreateManagedWidget("vertMargin", xmLabelWidgetClass, box3,
  1887. X           NULL);
  1888. X
  1889. X  vertMargin = XtVaCreateManagedWidget("vertMarginText",xmTextWidgetClass, box3,
  1890. X           NULL);
  1891. X
  1892. X
  1893. X  encBtns = XmCreateRadioBox(box3, "postscripttype", NULL, 0);
  1894. X       XtManageChild(encBtns);
  1895. X       
  1896. X  button = XtVaCreateManagedWidget("portrait", xmToggleButtonWidgetClass, encBtns,
  1897. X       NULL);
  1898. X           XtAddCallback(button, XmNvalueChangedCallback, encValueChanged,
  1899. X       PS_NORMAL);
  1900. X
  1901. X  button = XtVaCreateManagedWidget("landscape", xmToggleButtonWidgetClass, encBtns,
  1902. X       NULL);
  1903. X           XtAddCallback(button, XmNvalueChangedCallback, encValueChanged,
  1904. X       PS_LANDSCAPE);
  1905. X
  1906. X  button = XtVaCreateManagedWidget("epsi", xmToggleButtonWidgetClass, encBtns,
  1907. X       NULL);
  1908. X           XtAddCallback(button, XmNvalueChangedCallback, encValueChanged,
  1909. X       PS_EPSI);
  1910. X
  1911. X/*------------
  1912. X  button = XtVaCreateManagedWidget("encap", xmToggleButtonWidgetClass, encBtns,
  1913. X       NULL);
  1914. X           XtAddCallback(button, XmNvalueChangedCallback, encValueChanged,
  1915. X       PS_EPS);
  1916. X---------------*/
  1917. X
  1918. X  button = XtVaCreateManagedWidget("onlyEpsi", xmToggleButtonWidgetClass, encBtns,
  1919. X       NULL);
  1920. X           XtAddCallback(button, XmNvalueChangedCallback, encValueChanged,
  1921. X       PS_EPSIONLY);
  1922. X
  1923. X  psBin = XtVaCreateManagedWidget("binary", xmToggleButtonWidgetClass, box3,
  1924. X       NULL);
  1925. X
  1926. X  psLim = XtVaCreateManagedWidget("limit", xmToggleButtonWidgetClass, box3,
  1927. X       NULL);
  1928. X
  1929. X
  1930. X  /* image processing options */
  1931. X  box4 = XtVaCreateManagedWidget("box4", xmFormWidgetClass, dialog, NULL);
  1932. X
  1933. X           XtVaCreateManagedWidget("prOptions", xmLabelWidgetClass, box4,
  1934. X           NULL);
  1935. X
  1936. X           XtVaCreateManagedWidget("brightnessLbl", xmLabelWidgetClass, box4,
  1937. X       NULL);
  1938. X  brtext = XtVaCreateManagedWidget("brightnessText", xmTextWidgetClass, box4,
  1939. X           NULL);
  1940. X
  1941. X  revBtn = XtVaCreateManagedWidget("reverse", xmToggleButtonWidgetClass, box4, NULL);
  1942. X
  1943. X  borderBtn = XtVaCreateManagedWidget("borders", xmToggleButtonWidgetClass, box4, NULL);
  1944. X
  1945. X
  1946. X  box5 = XtVaCreateManagedWidget("box5", xmFormWidgetClass, dialog, NULL);
  1947. X
  1948. X           XtVaCreateManagedWidget("outputLbl", xmLabelWidgetClass, box5,
  1949. X       NULL);
  1950. X
  1951. X  outBtns = XmCreateRadioBox(box5, "outputtype", NULL, 0);
  1952. X       XtManageChild(outBtns);
  1953. X
  1954. X
  1955. X  button = XtVaCreateManagedWidget("file", xmToggleButtonWidgetClass, outBtns,
  1956. X       NULL);
  1957. X           XtAddCallback(button, XmNvalueChangedCallback, outValueChanged,
  1958. X       TOFILE);
  1959. X
  1960. X  filenm = XtVaCreateManagedWidget("fileText", xmTextWidgetClass, box5,
  1961. X           NULL);
  1962. X
  1963. X  button = XtVaCreateManagedWidget("printer", xmToggleButtonWidgetClass, outBtns,
  1964. X       NULL);
  1965. X           XtAddCallback(button, XmNvalueChangedCallback, outValueChanged,
  1966. X       TOPRN);
  1967. X
  1968. X  prncmd = XtVaCreateManagedWidget("printerText", xmTextWidgetClass, box5,
  1969. X           NULL);
  1970. X
  1971. X
  1972. X  cnvBtns = XmCreateRadioBox(dialog, "converttype", NULL, 0);
  1973. X
  1974. X           XtVaSetValues(cnvBtns,
  1975. X       XmNorientation, XmHORIZONTAL,
  1976. X       NULL);
  1977. X       XtManageChild(cnvBtns);
  1978. X       
  1979. X  button = XtVaCreateManagedWidget("nodither", xmToggleButtonWidgetClass, cnvBtns,
  1980. X       NULL);
  1981. X           XtAddCallback(button, XmNvalueChangedCallback, cnvValueChanged,
  1982. X       NO_DITHER);
  1983. X
  1984. X  button = XtVaCreateManagedWidget("dither", xmToggleButtonWidgetClass, cnvBtns,
  1985. X       NULL);
  1986. X           XtAddCallback(button, XmNvalueChangedCallback, cnvValueChanged,
  1987. X       DITHER);
  1988. X
  1989. X  button = XtVaCreateManagedWidget("mdither", xmToggleButtonWidgetClass, cnvBtns,
  1990. X       NULL);
  1991. X           XtAddCallback(button, XmNvalueChangedCallback, cnvValueChanged,
  1992. X       MDITHER);
  1993. X
  1994. X  button = XtVaCreateManagedWidget("halftone", xmToggleButtonWidgetClass, cnvBtns,
  1995. X       NULL);
  1996. X           XtAddCallback(button, XmNvalueChangedCallback, cnvValueChanged,
  1997. X       HALFTONE);
  1998. X
  1999. X  button = XtVaCreateManagedWidget("mapbw", xmToggleButtonWidgetClass, cnvBtns,
  2000. X       NULL);
  2001. X           XtAddCallback(button, XmNvalueChangedCallback, cnvValueChanged,
  2002. X       MAPBW);
  2003. X
  2004. X  box6 = XtVaCreateManagedWidget("box6", xmFormWidgetClass, dialog, NULL);
  2005. X
  2006. X  XtVaCreateManagedWidget("splat", xmLabelWidgetClass, box6, NULL);
  2007. X  
  2008. X  button = XtVaCreateManagedWidget("OK", xmPushButtonWidgetClass, box6, NULL);
  2009. X  XtAddCallback(button, XmNactivateCallback, doGrab, NULL);
  2010. X
  2011. X  button = XtVaCreateManagedWidget("Dismiss", xmPushButtonWidgetClass, box6, NULL);
  2012. X  XtAddCallback(button, XmNactivateCallback, doDismiss, NULL);
  2013. X
  2014. X}
  2015. X
  2016. X
  2017. X
  2018. Xint main(argc, argv, envp)
  2019. X  int argc;
  2020. X  char *argv[];
  2021. X  char *envp;
  2022. X{
  2023. X  puts("X-Windows Screen Grabber");
  2024. X  puts(Copyright);
  2025. X  puts("");
  2026. X
  2027. X
  2028. X  hShell = XtAppInitialize(&appContext, "XGrab", NULL, 0, &argc, argv,
  2029. X     fallback_resources, NULL, 0);
  2030. X
  2031. X  hDisplay = XtDisplay(hShell);
  2032. X  createWindow();
  2033. X
  2034. X  XtRealizeWidget(hShell);
  2035. X  XtAppMainLoop(appContext);
  2036. X}
  2037. END_OF_FILE
  2038. if test 17554 -ne `wc -c <'xgrabsc.2_3/xgrabxm.c'`; then
  2039.     echo shar: \"'xgrabsc.2_3/xgrabxm.c'\" unpacked with wrong size!
  2040. fi
  2041. # end of 'xgrabsc.2_3/xgrabxm.c'
  2042. fi
  2043. echo shar: End of archive 2 \(of 5\).
  2044. cp /dev/null ark2isdone
  2045. MISSING=""
  2046. for I in 1 2 3 4 5 ; do
  2047.     if test ! -f ark${I}isdone ; then
  2048.     MISSING="${MISSING} ${I}"
  2049.     fi
  2050. done
  2051. if test "${MISSING}" = "" ; then
  2052.     echo You have unpacked all 5 archives.
  2053.     rm -f ark[1-9]isdone
  2054. else
  2055.     echo You still need to unpack the following archives:
  2056.     echo "        " ${MISSING}
  2057. fi
  2058. ##  End of shell archive.
  2059. exit 0
  2060.  
  2061. exit 0 # Just in case...
  2062. -- 
  2063.   // chris@Sterling.COM           | Send comp.sources.x submissions to:
  2064. \X/  Amiga - The only way to fly! |    sources-x@sterling.com
  2065.  "It's intuitively obvious to the |
  2066.   most casual observer..."        | GCS d+/-- p+ c++ l+ m+ s++/+ g+ w+ t+ r+ x+
  2067.