home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / x / volume13 / imagemagic / part02 < prev    next >
Internet Message Format  |  1991-05-22  |  75KB

  1. Path: uunet!cs.utexas.edu!sun-barr!newstop!exodus!dupont.com!cristy
  2. From: cristy@dupont.com
  3. Newsgroups: comp.sources.x
  4. Subject: v13i018: ImageMagick - Graphics display programs, Part02/21
  5. Message-ID: <13788@exodus.Eng.Sun.COM>
  6. Date: 22 May 91 08:57:07 GMT
  7. References: <csx-13i017:imagemagic@uunet.UU.NET>
  8. Sender: news@exodus.Eng.Sun.COM
  9. Lines: 2104
  10. Approved: argv@sun.com
  11.  
  12. Submitted-by: cristy@dupont.com
  13. Posting-number: Volume 13, Issue 18
  14. Archive-name: imagemagic/part02
  15.  
  16. #!/bin/sh
  17. # this is img.02 (part 2 of ImageMagick)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file ImageMagick/display.man continued
  20. #
  21. if test ! -r _shar_seq_.tmp; then
  22.     echo 'Please unpack part 1 first!'
  23.     exit 1
  24. fi
  25. (read Scheck
  26.  if test "$Scheck" != 2; then
  27.     echo Please unpack part "$Scheck" next!
  28.     exit 1
  29.  else
  30.     exit 0
  31.  fi
  32. ) < _shar_seq_.tmp || exit 1
  33. if test ! -f _shar_wnt_.tmp; then
  34.     echo 'x - still skipping ImageMagick/display.man'
  35. else
  36. echo 'x - continuing file ImageMagick/display.man'
  37. sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/display.man' &&
  38. X
  39. Note, options \fB-dither\fP and \fB-treedepth\fP affect the color reduction
  40. algorithm.
  41. .TP 5
  42. .B "-compress \fItype\fP"
  43. the type of image compression: \fIQEncoded\fP or \fIRunlengthEncoded\fP.
  44. X
  45. Use this option with \fB-write\fP to specify the the type of image
  46. compression.  See \fBMIFF FILE FORMAT\fP for details.
  47. X
  48. Specify \fB\+compress\fP to store the binary image in an uncompressed format.
  49. The default is the compression type of the specified image file.
  50. .TP 5
  51. .B "-pause \fIseconds\fP"
  52. display the next image after pausing.  
  53. X
  54. This option is useful when viewing several images in sequence.  Each
  55. image will display and wait the number of seconds specified before the
  56. next image is displayed.  The default is to display the image
  57. continuously until you terminate it.  
  58. .TP 5
  59. .B "-display \fIhost:display[.screen]\fP"
  60. specifies the X server to contact; see \fBX(1)\fP.
  61. .TP 5
  62. .B "-dither"
  63. apply Floyd/Steinberg error diffusion to the image.  
  64. X
  65. The basic strategy of dithering is to trade intensity resolution for 
  66. spatial resolution by averaging the intensities of several neighboring 
  67. pixels.  Images which suffer from severe contouring when reducing colors 
  68. can be improved with this option.
  69. X
  70. The \fB-colors\fP, \fB-gray\fP, or \fB-monochrome\fP option is required 
  71. for this option to take effect.
  72. .TP 5
  73. .B "-enhance"
  74. apply a digital filter to enhance a noisy image.
  75. .TP 5
  76. .B "-gamma \fIvalue\fP"
  77. level of gamma correction.  
  78. X
  79. The same color image displayed on two different workstations may look
  80. different due to differences in the display monitor.  Use gamma
  81. correction to adjust for this color difference.  Reasonable values
  82. extend from 0.8 to 2.3.  
  83. .TP 5
  84. .B "-geometry \fI<width>x<height>{\+-}<x offset>{\+-}<y offset>\fP"
  85. preferred size and location of the image window.  See \fBX(1)\fP for details 
  86. about the geometry specification.  By default, the window size is the image 
  87. size and the location is choosen by you when it is mapped.
  88. X
  89. If the specified image size is smaller than the actual image size, the
  90. image is first reduced to an integral of the specified image size with
  91. an antialias digital filter.  The image is then scaled to the exact
  92. specified image size with pixel replication.  If the specified image
  93. size is greater than the actual image size, the image is first enlarged
  94. to an integral of the specified image size with bilinear
  95. interpolation.  The image is then scaled to the exact specified image
  96. size with pixel replication.
  97. X
  98. When displaying an image on an X server, the x and y offset in the
  99. geometry specification is relative to the root window.  When printing
  100. an image, the x and y offset in the geometry specification is relative
  101. to a Postscript page.  See \fB-print\fP for more details.
  102. .TP 5
  103. .B "-gray"
  104. transform the image to gray scale colors.  
  105. .TP 5
  106. .B "-inverse"
  107. apply color inversion to image.  
  108. X
  109. The red, green, and blue intensities of an image are negated.
  110. .TP 5
  111. .B "-magnify \fIvalue\fP"
  112. specifies an integral factor by which the image should be enlarged.  The
  113. default is 2.
  114. X
  115. This value only affects the magnification window which is invoked with
  116. button number 1 after the image is displayed.  Refer to \fBBUTTONS\fP
  117. for more details.
  118. .TP 5
  119. .B "-map \fItype\fP"
  120. display image using this Standard Colormap type.
  121. X
  122. Choose from these Standard Colormap types:
  123. X
  124. X    default
  125. X    best
  126. X    red
  127. X    green
  128. X    blue
  129. X    gray
  130. X
  131. The X server must support the Standard Colormap you choose, otherwise an 
  132. error occurs.  See \fBxcmap(1)\fP for one way of creating Standard Colormaps.
  133. .TP 5
  134. .B "-monochrome"
  135. transform the image to black and white.
  136. X
  137. Monochrome images can benefit from error diffusion.  Use \fB-dither\fP with
  138. this option to diffuse the error.
  139. .TP 5
  140. .B "-noise"
  141. reduce the noise in an image with a noise peak elimination filter.
  142. X
  143. The principal function of noise peak elimination filter is to smooth
  144. the objects within an image without losing edge information and without
  145. creating undesired structures.  The central idea of the algorithm is to
  146. replace a pixel with its next neighbor in value within a 3 x 3 window,
  147. if this pixel has been found to be noise.  A pixel is defined as noise
  148. if and only if this pixel is a maximum or minimum within the 3 x 3 window.
  149. .TP 5
  150. .B "-normalize"
  151. tranform image to span the full the range of colors.
  152. .TP 5
  153. .B "-print \fIfile\fP"
  154. write image as encapsulated Postscript to a file.  
  155. X
  156. You can view the file with any Postscript compatible viewer or
  157. printer.  The image is displayed as color on viewers and printers that 
  158. support color Postscript, otherwise it is displayed as grayscale.
  159. X
  160. If \fIfile\fP already exists, you will be prompted as to whether
  161. it should be overwritten.  
  162. X
  163. By default, the image is centered and scaled to fit on the Postscript page.
  164. To specify a specific image size or a particular location on the Postscript
  165. page, use \fB-geometry\fP.
  166. X
  167. By default the image is output in portrait mode.  Use \fB-rotate 90\fP to
  168. display the image in landscape mode.
  169. .TP 5
  170. .B "-reflect"
  171. create a "mirror image" by reflecting the image scanlines.
  172. .TP 5
  173. .B "-root"
  174. display image onto the root window.  
  175. X
  176. The image will not display on the root window if the image has more
  177. unique colors than the root window colormap allows.  Use
  178. \fB-colors\fP to reduce the number of colors.
  179. X
  180. By default the image is tiled onto the root window.   If
  181. \fB-backdrop\fP or \fB-geometry\fP are specified, the image is
  182. surrounded by the background color.  Refer to \fBX RESOURCES\fP for
  183. details.
  184. .TP 5
  185. .B "-rotate \fIdegrees\fP"
  186. apply Paeth image rotation to the image.
  187. .TP 5
  188. .B "-scale \fI<width factor>x<height factor>\fP"
  189. preferred size factors of the image.
  190. X
  191. This option behaves like \fB-geometry\fP except the width and height values
  192. are relative instead of absolute.  The image size is multiplied by the
  193. width and height factors to obtain the final image dimensions.  If only
  194. one factor is specified, both the width and height factors assume the
  195. value.
  196. X
  197. Factors may be fractional.  For example, a factor of 1.5 will increase the
  198. image size by one and one-half.
  199. .TP 5
  200. .B "-scene \fInumber\fP"
  201. image scene number.
  202. .TP 5
  203. .B "-treedepth \fIvalue\fP"
  204. Normally, this integer value is zero or one.  A zero or one tells
  205. \fIDisplay\fP to choose a optimal tree depth for the color reduction
  206. algorithm.  
  207. X
  208. An optimal depth generally allows the best representation of the source
  209. image with the fastest computational speed and the least amount of
  210. memory.  However, the default depth is inappropriate for some images.
  211. To assure the best representation, try values between 2 and 8 for this
  212. parameter.  Refer to \fBCOLOR REDUCTION ALGORITHM\fP for more details.
  213. X
  214. The \fB-colors\fP, \fB-gray\fP, or \fB-monochrome\fP option is required
  215. for this option to take effect.
  216. .TP 5
  217. .B -verbose
  218. print detailed information about the image.  
  219. X
  220. This information is printed: image scene number;  image name;  image
  221. size; the image class (\fIDirectClass\fP or \fIPseudoClass\fP); the total 
  222. number of unique colors (if known);  and the number of seconds to read and
  223. transform the image.  Refer to \fBMIFF FILE FORMAT\fP for a description of
  224. the image class.
  225. X
  226. If \fB-colors\fP is also specified, the total unique colors in the image
  227. and color reduction error values are printed.  Refer to \fBMEASURING 
  228. COLOR REDUCTION ERROR\fP for a description of these values.  
  229. .TP 5
  230. .B "-visual \fItype\fP"
  231. display image using this visual type.
  232. X
  233. Choose from these visual classes:
  234. X
  235. X    StaticGray
  236. X    GrayScale
  237. X    StaticColor
  238. X    PseudoColor
  239. X    TrueColor
  240. X    DirectColor
  241. X    default
  242. X    \fIvisual id\fP
  243. X
  244. The X server must support the visual you choose, otherwise an error occurs.
  245. If a visual is not specified, the visual class that can display the most 
  246. simultaneous colors on the default screen is choosen.
  247. .TP 5
  248. .B "-write \fIfile\fP"
  249. write image to a file.  
  250. X
  251. The image is stored in the MIFF image format.  If the number of unique
  252. colors in the image exceed 65535, it is stored as \fIDirectClass\fP;
  253. otherwise, it is stored as \fIPseudoClass\fP format.  Refer to \fBMIFF
  254. FILE FORMAT\fP for more details.
  255. X
  256. Use \fB-compress\fP to specify the type of image compression.
  257. X
  258. If \fIfile\fP has the extension \fB.Z\fP, the file size is reduced using
  259. Lempel-Ziv coding with \fBcompress\fP.  If \fIfile\fP already exists, 
  260. you will be prompted as to whether it should be overwritten.
  261. .PP
  262. In addition to those listed above, you can specify these standard X
  263. resources as command line options:  -background, -bordercolor,
  264. -borderwidth,  -font, -foreground, -iconGeometry, -iconic, -name, or -title.  
  265. See \fBX RESOURCES\fP for details.
  266. .PP
  267. Any option you specify on the command line remains in effect until it is
  268. explicitly changed by specifying the option again with a different effect.
  269. For example, to display two images, the first with 32 colors and the
  270. second with only 16 colors, use:
  271. .PP
  272. X     display -colors 32 cockatoo.miff -colors 16 macaw.miff
  273. .PP
  274. Change \fI-\fP to \fI\+\fP in any option above to reverse its effect.
  275. For example, specify \fB\+display\fP to apply image transformations
  276. without viewing them on the X server.  Or, specify \fB\+compress\fP to store
  277. the binary image in an uncompressed format.
  278. .PP
  279. Specify \fIfile\fP as \fI-\fP for standard input or output.  If \fIfile\fP 
  280. has the extension \fB.Z\fP, the file is decoded with \fBuncompress\fP.  
  281. .SH BUTTONS
  282. .TP 5
  283. .B "Control-1"
  284. Press and drag to pan the image.
  285. .TP 5
  286. .B "1"
  287. Press and drag to select a command from a pop-up menu.  Choose from 
  288. these commands:
  289. X
  290. X    Image Info
  291. X    Half Size     
  292. X    Double Size   
  293. X    Rotate Right  
  294. X    Rotate Left   
  295. X    Reflect Image  
  296. X    Restore Image 
  297. X    Restore Window
  298. X    Magnify Window
  299. X    Next Image    
  300. X    Quit          
  301. .TP 5
  302. .B "2"
  303. Press and drag to define a region of the image to clip.  Release the button
  304. to crop the image, or return the pointer to the location of the initial button 
  305. press to cancel the cropping operation.
  306. .TP 5
  307. .B "3"
  308. Press and drag to define a region of the image to magnify.
  309. .SH KEYS
  310. .TP 5
  311. .B "1-9"
  312. Press to change the level of magnification.
  313. .TP 5
  314. .B "<"
  315. Press to half the image size.
  316. .TP 5
  317. .B ">"
  318. Press to double the image size.
  319. .TP 5
  320. .B "/"
  321. Press to rotate the image 90 degrees clockwise.
  322. .TP 5
  323. .B "\e"
  324. Press to rotate the image 90 degrees counter-clockwise.
  325. .TP 5
  326. .B "r"
  327. Press to reflect the image scanlines.
  328. .TP 5
  329. .B "o"
  330. Press to restore the image to its original size.
  331. .TP 5
  332. .B "w"
  333. Press to restore the image window to its original size.
  334. .TP 5
  335. .B "m"
  336. Press to map or unmap the magnify window.
  337. .TP 5
  338. .B "i"
  339. Press to display information about the image.  Press any key or button to 
  340. erase the information.
  341. X
  342. This information is printed: image name;  image size; the visual class
  343. (see \fB-visual\fP); and the total number of unique colors in the
  344. image.
  345. .TP 5
  346. .B "n"
  347. Press to display the next image.
  348. .TP 5
  349. .B "q"
  350. Press to discard all images and exit program.
  351. .SH "X RESOURCES"
  352. \fIDisplay\fP options can appear on the command line or in your X
  353. resource file.  Options on the command line supercede values specified
  354. in your X resource file.  See \fBX(1)\fP for more information on X
  355. resources.
  356. X
  357. All \fIdisplay\fP options have a corresponding X resource.  In addition,
  358. the \fIdisplay\fP program uses the following X resources:
  359. .TP 5
  360. .B background (\fPclass\fB Background)
  361. Specifies the preferred color to use for the image window background.  The
  362. default is black.
  363. .TP 5
  364. .B borderColor (\fPclass\fB BorderColor)
  365. Specifies the preferred color to use for the image window border.  The
  366. default is white.
  367. .TP 5
  368. .B borderWidth (\fPclass\fB BorderWidth)
  369. Specifies the width in pixels of the image window border.  The default is 2.
  370. .TP 5
  371. .B font (\fPclass\fB Font)
  372. Specifies the name of the preferred font to use when displaying text in the
  373. within the image window.  The default is 9x15, fixed, or 5x8 determined by
  374. the image window size.
  375. .TP 5
  376. .B foreground (\fPclass\fB Foreground)
  377. Specifies the preferred color to use for text within the image window.  The
  378. default is white.
  379. .TP 5
  380. .B iconGeometry (\fPclass\fB IconGeometry)
  381. Specifies the preferred size and position of the application when
  382. iconified.  It is not necessarily obeyed by all window managers.
  383. .TP 5
  384. .B iconic (\fPclass\fB Iconic)
  385. This resource indicates that you would prefer that the application's
  386. windows initially not be visible as if the windows had be immediately
  387. iconified by you.  Window managers may choose not to honor the
  388. application's request.
  389. .TP 5
  390. .B name (\fPclass\fB Name)
  391. This resource specifies the name under which resources for the
  392. application should be found.  This resource is useful in shell aliases to
  393. distinguish between invocations of an application, without resorting to
  394. creating links to alter the executable file name.  The default is the
  395. application name.
  396. .TP 5
  397. .B title (\fPclass\fB Title)
  398. This resource specifies the title to be used for the image window.  This
  399. information is sometimes used by a window manager to provide some sort
  400. of header identifying the window.  The default is the image file name.
  401. .SH "COLOR REDUCTION ALGORITHM"
  402. .PP
  403. This section describes how \fIDisplay\fP performs color reduction in an
  404. image.  To fully understand this section, you should have a knowledge
  405. of basic imaging techniques and the tree data structure and terminology.
  406. .PP
  407. For purposes of color allocation, an image is a set of \fIn\fP pixels,
  408. where each pixel is a point in RGB space.  RGB space is a 3-dimensional
  409. vector space, and each pixel, \fIp\d\s-3i\s0\u\fP,  is defined by an
  410. ordered triple of red, green, and blue coordinates, (\fIr\d\s-3i\s0\u,
  411. g\d\s-3i\s0\u, b\d\s-3i\s0\u\fP).
  412. .PP
  413. Each primary color component (red, green, or blue) represents an
  414. intensity which varies linearly from 0 to a maximum value,
  415. \fIc\d\s-3max\s0\u\fP, which corresponds to full saturation of that
  416. color.  Color allocation is defined over a domain consisting of the
  417. cube in RGB space with opposite vertices at (0,0,0) and
  418. (\fIc\d\s-3max\s0\u,c\d\s-3max\s0\u,c\d\s-3max\s0\u\fP).  \fIDisplay\fP
  419. requires \fIc\d\s-3max\s0\u = 255\fP.
  420. .PP
  421. The algorithm maps this domain onto a tree in which each node
  422. represents a cube within that domain.  In the following discussion,
  423. these cubes are defined by the coordinate of two opposite vertices: The
  424. vertex nearest the origin in RGB space and the vertex farthest from the
  425. origin.
  426. .PP
  427. The tree's root node represents the the entire domain, (0,0,0) through
  428. (\fIc\d\s-3max\s0\u,c\d\s-3max\s0\u,c\d\s-3max\s0\u\fP).  Each lower level in
  429. the tree is generated by subdividing one node's cube into eight smaller
  430. cubes of equal size.  This corresponds to bisecting the parent cube
  431. with planes passing through the midpoints of each edge.
  432. .PP
  433. The basic algorithm operates in three phases:  \fBClassification,
  434. Reduction\fP, and \fBAssignment\fP.  \fBClassification\fP builds a
  435. color description tree for the image.  \fBReduction\fP collapses the
  436. tree until the number it represents, at most, is the number of colors
  437. desired in the output image.  \fBAssignment\fP defines the output
  438. image's color map and sets each pixel's color by reclassification in
  439. the reduced tree.
  440. .PP
  441. \fBClassification\fP begins by initializing a color description tree of
  442. sufficient depth to represent each possible input color in a leaf.
  443. However, it is impractical to generate a fully-formed color description
  444. tree in the classification phase for realistic values of
  445. \fIc\d\s-3max\s0\u\fP.  If color components in the input image are
  446. quantized to \fIk\fP-bit precision, so that \fIc\d\s-3max\s0\u =
  447. 2\u\s-3k\s0\d-1\fP, the tree would need \fIk\fP levels below the root
  448. node to allow representing each possible input color in a leaf.  This
  449. becomes prohibitive because the tree's total number of nodes is
  450. .PP
  451. X        \fI\s+6\(*S\u\s-9 k\d\di=1\s0 8k\fP\s0\u
  452. .PP
  453. A complete tree would require 19,173,961 nodes for \fIk = 8,
  454. c\d\s-3max\s0\u = 255\fP.  Therefore, to avoid building a fully
  455. populated tree, \fIDisplay\fP: (1) Initializes data structures for
  456. nodes only as they are needed; (2) Chooses a maximum depth for the tree
  457. as a function of the desired number of colors in the output image
  458. (currently \fIlog\d\s-34\s0\u(colormap size)\+2\fP).  A tree of this
  459. depth generally allows the best representation of the source image with
  460. the fastest computational speed and the least amount of memory.
  461. However, the default depth is inappropriate for some images.
  462. Therefore, the caller can request a specific tree depth.
  463. .PP
  464. For each pixel in the input image, classification scans downward from
  465. the root of the color description tree.  At each level of the tree, it
  466. identifies the single node which represents a cube in RGB space
  467. containing the pixel's color.  It updates the following data for each
  468. such node:
  469. .TP 5
  470. .B n\d\s-31\s0\u:  
  471. Number of pixels whose color is contained in the RGB cube which this
  472. node represents;
  473. .TP 5
  474. .B n\d\s-32\s0\u:  
  475. Number of pixels whose color is not represented in a node at lower
  476. depth in the tree;  initially,  \fIn\d\s-32\s0\u = 0\fP for all nodes
  477. except leaves of the tree.
  478. .TP 5
  479. .B S\d\s-3r\s0\u, S\d\s-3g\s0\u, S\d\s-3b\s0\u:
  480. Sums of the red, green, and blue component values for all pixels not
  481. classified at a lower depth.  The combination of these sums and
  482. \fIn\d\s-32\s0\u\fP will ultimately characterize the mean color of a
  483. set of pixels represented by this node.
  484. .PP
  485. \fBReduction\fP repeatedly prunes the tree until the number of nodes with
  486. \fIn\d\s-32\s0\u  > 0\fP is less than or equal to the maximum number of colors
  487. allowed in the output image.  On any given iteration over the tree, it
  488. selects those nodes whose \fIn\d\s-31\s0\u\fP count is minimal for pruning and
  489. merges their color statistics upward.  It uses a pruning threshold,
  490. \fIn\d\s-3p\s0\u\fP, to govern node selection as follows:
  491. .PP
  492. X  n\d\s-3p\s0\u = 0
  493. X  while number of nodes with (n\d\s-32\s0\u > 0) > required maximum number of colors
  494. X      prune all nodes such that n\d\s-31\s0\u <= n\d\s-3p\s0\u
  495. X      Set n\d\s-3p\s0\u  to minimum n\d\s-31\s0\u  in remaining nodes
  496. .PP
  497. When a node to be pruned has offspring, the pruning procedure invokes
  498. itself recursively in order to prune the tree from the leaves upward.
  499. The values of \fIn\d\s-32\s0\u  S\d\s-3r\s0\u, S\d\s-3g\s0\u,\fP  and
  500. \fIS\d\s-3b\s0\u\fP in a node being pruned are always added to the
  501. corresponding data in that node's parent.  This retains the pruned
  502. node's color characteristics for later averaging.
  503. .PP
  504. For each node,  \fIn\d\s-32\s0\u\fP pixels exist for which that node
  505. represents the smallest volume in RGB space containing those pixel's
  506. colors.  When \fIn\d\s-32\s0\u  > 0\fP the node will uniquely define a
  507. color in the output image.  At the beginning of reduction,
  508. \fIn\d\s-32\s0\u = 0\fP  for all nodes except the leaves of the tree
  509. which represent colors present in the input image.
  510. .PP
  511. The other pixel count, \fIn\d\s-31\s0\u\fP,  indicates the total
  512. number of colors within the cubic volume which the node represents.
  513. This includes \fIn\d\s-31\s0\u - n\d\s-32\s0\u\fP pixels whose colors
  514. should be defined by nodes at a lower level in the tree.
  515. .PP
  516. \fBAssignment\fP generates the output image from the pruned tree.  The
  517. output image consists of two parts:  (1)  A color map, which is an
  518. array of color descriptions (RGB triples) for each color present in the
  519. output image; (2)  A pixel array, which represents each pixel as an
  520. index into the color map array.
  521. .PP
  522. First, the assignment phase makes one pass over the pruned color
  523. description tree to establish the image's color map.  For each node
  524. with \fIn\d\s-32\s0\u > 0\fP, it divides \fIS\d\s-3r\s0\u,
  525. S\d\s-3g\s0\u\fP, and \fPS\d\s-3b\s0\u\fP by \fIn\d\s-32\s0\u\fP.  This
  526. produces the mean color of all pixels that classify no lower than this
  527. node.  Each of these colors becomes an entry in the color map.
  528. .PP
  529. Finally, the assignment phase reclassifies each pixel in the pruned
  530. tree to identify the deepest node containing the pixel's color.  The
  531. pixel's value in the pixel array becomes the index of this node's mean
  532. color in the color map.
  533. .SH "MEASURING COLOR REDUCTION ERROR"
  534. .PP
  535. Depending on the image, the color reduction error may be obvious or
  536. invisible.  Images with high spatial frequencies (such as hair or
  537. grass) will show error much less than pictures with large smoothly
  538. shaded areas (such as faces).  This is because the high-frequency
  539. contour edges introduced by the color reduction process are masked by
  540. the high frequencies in the image.
  541. .PP
  542. To measure the difference between the original and color reduced images
  543. (the total color reduction error), \fIDisplay\fP sums over all pixels
  544. in an image the distance squared in RGB space between each original
  545. pixel value and its color reduced value. \fIDisplay\fP prints several error 
  546. measurements including the mean error per pixel, the normalized mean error,
  547. and the normalized maximum error.
  548. .PP
  549. The normalized error measurement can be used to compare images.  In
  550. general, the closer the mean error is to zero the more the quantized
  551. image resembles the source image.  Ideally, the error should be
  552. perceptually-based, since the human eye is the final judge of
  553. quantization quality.
  554. .PP
  555. These errors are measured and printed when \fB-verbose\fP and \fB-colors\fI 
  556. are specified on the command line:
  557. .TP 5
  558. .B mean error per pixel:  
  559. is the mean error for any single pixel in the image.
  560. .TP 5
  561. .B normalized mean square error:  
  562. is the normalized mean square quantization error for any single pixel in the
  563. image.  
  564. X
  565. This distance measure is normalized to a range between 0 and 1.  It is
  566. independent of the range of red, green, and blue values in the image.
  567. .TP 5
  568. .B normalized maximum square error:  
  569. is the largest normalized square quantization error for any single
  570. pixel in the image.
  571. X
  572. This distance measure is normalized to a range between 0 and 1.  It is
  573. independent of the range of red, green, and blue values in the image.
  574. .SH "MIFF FILE FORMAT"
  575. .PP
  576. The Machine Independent File Format is described in this section.
  577. .PP
  578. A MIFF image file consist of two sections.  The first section is
  579. composed of keywords describing the image in text form.  The next
  580. section is the binary image data.  The two sections are separated by a
  581. \fB:\fP character immediately followed by a \fInewline\fP.  Generally,
  582. the first section has a \fIform-feed\fP and \fInewline\fP proceeding
  583. the \fB:\fP character.   You can then list the image keywords with
  584. \fImore\fP, without printing the binary image that follows the \fB:\fP
  585. separator.
  586. .PP
  587. Each keyword must be separated by at least one space but can be
  588. separated with control characters such a \fIform-feed\fP or
  589. \fInewline\fP.
  590. .PP
  591. A list of valid keywords follows:
  592. .TP 5
  593. .B "class=\fIDirectClass | PseudoClass\fP"
  594. identifies the type of binary image stored within the file.  
  595. X
  596. This keyword is optional.  If it is not specified, a \fIDirectClass\fP
  597. image format is assumed.  An explanation of \fIDirectClass\fP and
  598. \fIPseudoClass\fP image data follows this list.
  599. .TP 5
  600. .B "colors=\fIvalue\fP"
  601. specifies the number of colors in the image, and for pseudo-color
  602. images the size of the colormap.  
  603. X
  604. This keyword is optional.  However, if a colormap size is not
  605. specified, a linear colormap is assumed for pseudo-color images.
  606. .TP 5
  607. .B "columns=\fIvalue\fP"
  608. is a required keyword and specifies the number of columns, or width in
  609. pixels, of the image.
  610. .TP 5
  611. .B "compression=\fIQEncoded | RunlengthEncoded\fP"
  612. identifies how the image stored within the file is compressed.
  613. X
  614. This keyword is optional.  If it is not specified, the image is assumed
  615. to be uncompressed.  A detailed explanation of runlength-encoded and
  616. Q-coder image compression follows this list.
  617. .TP 5
  618. .B "id=\fIImageMagick\fP"
  619. is a required keyword and identifies this file as a MIFF image.  
  620. .TP 5
  621. .B "packets=\fIvalue\fP"
  622. specifies the number of compressed color packets in the image data section.  
  623. X
  624. This keyword is optional, but recommended, for runlength-encoded image
  625. compression.  It is required for Q-encoded image compression.  A
  626. detailed explanation of image compression follows this list.
  627. .TP 5
  628. .B "rows=\fIvalue\fP"
  629. is a required keyword and specifies the number of rows, or height in pixels, 
  630. of the image.
  631. .TP 5
  632. .B "scene=\fIvalue\fP"
  633. is an optional keyword and is a reference number for sequencing of
  634. images.  
  635. X
  636. This keyword is typically useful for animating a sequence of images.
  637. .PP
  638. Comments can be included in the keyword section.  Comments must begin with
  639. a \fB{\fP character and end with a \fI}\fP character.  
  640. .PP
  641. An example keyword section follows:
  642. .PP
  643. X    {
  644. X      Rendered via Dore by Sandy Hause.
  645. X    }
  646. X    id=ImageMagick
  647. X    class=PseudoClass  colors=256
  648. X    compression=RunlengthEncoded  packets=27601
  649. X    columns=1280  rows=1024
  650. X    scene=1
  651. X    ^L
  652. X    :
  653. .PP
  654. The binary image data that follows the keyword text is stored in one of 
  655. two binary classes as specified by the \fBclass\fP keyword: 
  656. \fIDirectClass\fP or \fIPseudoClass\fP.
  657. .PP
  658. Use the \fIDirectClass\fP class to store continuous-tone images.
  659. \fIDirectClass\fP requires that the image pixels immediately follow the
  660. keyword text and be stored as binary red, green, and blue intensity
  661. values.  The total number of pixels expected is equal to the number of pixel 
  662. columns times the number of pixel rows as specified by the \fBcolumns\fP and 
  663. \fBrows\fP keywords.
  664. .PP
  665. If the \fBcompression\fP keyword is not specified, a red, green, and blue byte 
  666. in that order is expected for each pixel of the image.
  667. .PP
  668. If \fBcompression\fP is \fIQEncoded\fP, each red, green, and blue byte
  669. intensity value is encoded using the Q-coder compression algorithm.
  670. Use the \fBpackets\fP keyword to specify the total number of Q-encoded
  671. packets that comprise the image.  Refer to "Sofware implementations of
  672. the Q-Coder", by Mitchell, J. L. and Pennebaker, W.B. (IBM Journal Res.
  673. Development, Volume 32, Number 6, November 1988, pages 753 - 774) for
  674. implementation specific details.
  675. .PP
  676. If \fBcompression\fP is \fIRunlengthEncoded\fP, each red, green, and
  677. blue byte intensity value is followed by a count byte. This value
  678. specifies the number of horizonally contiguous pixels in the image of
  679. that color.  The count (0-255) is one less than the actual number of
  680. contiguous pixels; thus a single packet can represent from 1 up to 256
  681. identical pixels.  The total number of pixels specified by the
  682. individual count bytes must add up to the number of pixel columns times
  683. the number of pixel rows as specified by the \fBcolumns\fP and
  684. \fBrows\fP keywords.  Use \fBpackets\fP to specify the total number of
  685. runlength-encoded packets that comprise the image.
  686. .PP
  687. Use the \fIPseudoClass\fP class to store pseudo-color images.
  688. \fIPseudoClass\fP requires that the image colormap and
  689. pseudo-color pixels immediately follow the keyword text.  The colormap
  690. is stored as contiguous red, green, and blue intensity values.  The
  691. number of intensity values expected is determined by the \fBcolors\fP
  692. keyword.  Note, an image colormap is restricted to at most 65535
  693. entries.  The binary pseudo-color image is stored as indexes into the
  694. colormap.  If the colormap size exceeds 256 entries, then each colormap
  695. index is two bytes each with the most-significant-byte first.  The
  696. total number of pixels expected is equal to the number of pixel columns
  697. times the number of pixel rows as specified by the \fBcolumns\fP and
  698. \fBrows\fP keywords.
  699. .PP
  700. If the \fBcompression\fP keyword is not specified, a colormap index is 
  701. expected for each pixel of the image.
  702. .PP
  703. If \fBcompression\fP is \fIQEncoded\fP, each colormap index is
  704. encoded using the Q-coder compression algorithm.  Use the \fBpackets\fP
  705. keyword to specify the total number of Q-encoded packets comprise the
  706. image.  Refer to "Sofware implementations of the Q-Coder", by Mitchell,
  707. J. L. and Pennebaker, W.B. (IBM Journal Res. Development, Volume 32,
  708. Number 6, November 1988, pages 753 - 774) for implementation specific
  709. details.
  710. .PP
  711. If \fBcompression\fP is \fIRunlengthEncoded\fP, each colormap index
  712. is followed by a count byte. This value  specifies the number of
  713. horizonally contiguous pixels in the image of that color.  The count
  714. (0-255) is one less than the actual number of contiguous pixels; thus a
  715. single packet can represent from 1 up to 256 identical pixels.  The
  716. total number of pixels specified by the individual count bytes must add
  717. up to the number of pixels expected in the image as specified by the
  718. \fBcolumns\fP and \fBrows\fP keywords.  Use \fBpackets\fP to specify the 
  719. total number of runlength-encoded packets that comprise the image.
  720. .SH FEATURES
  721. Although \fIDisplay\fP will display an image on a server with an immutable
  722. colormap, the image quality may suffer as compared to a server with a 
  723. read/write colormap.
  724. .PP
  725. \fIDisplay\fP memory requirements is proportionate to the area of the image.
  726. .PP
  727. \fIDisplay\fP does not complain when it encounters a keyword in an image file
  728. it does not understand.
  729. .SH ENVIRONMENT
  730. .TP 5
  731. .B DISPLAY
  732. To get the default host, display number, and screen.
  733. .SH SEE ALSO
  734. XX(1), xcmap(1), import(1), XtoPS(1), more(1), compress(1)
  735. .SH COPYRIGHT
  736. Copyright 1991 E. I. Dupont de Nemours & Company                           
  737. .PP                                                                           
  738. Permission to use, copy, modify, distribute, and sell this software and    
  739. its documentation for any purpose is hereby granted without fee,           
  740. provided that the above copyright notice appear in all copies and that     
  741. both that copyright notice and this permission notice appear in            
  742. supporting documentation, and that the name of E. I. Dupont de Nemours     
  743. & Company not be used in advertising or publicity pertaining to            
  744. distribution of the software without specific, written prior               
  745. permission.  E. I. Dupont de Nemours & Company makes no representations    
  746. about the suitability of this software for any purpose.  It is provided    
  747. "as is" without express or implied warranty.                               
  748. .PP
  749. E. I. Dupont de Nemours & Company disclaims all warranties with regard
  750. to this software, including all implied warranties of merchantability
  751. and fitness, in no event shall E. I. Dupont de Nemours & Company be
  752. liable for any special, indirect or consequential damages or any
  753. damages whatsoever resulting from loss of use, data or profits, whether
  754. in an action of contract, negligence or other tortious action, arising
  755. out of or in connection with the use or performance of this software.      
  756. .SH ACKNOWLEDGEMENTS
  757. The MIT X Consortium for making network transparent graphics a reality.
  758. .PP
  759. Michael Halle, Spatial Imaging Group at MIT, for the initial
  760. implementation of Alan Paeth's image rotation algorithm.
  761. .PP
  762. David Pensak, E. I. Dupont de Nemours & Company, for providing a
  763. computing environment that made this program possible.
  764. .PP
  765. Paul Raveling, USC Information Sciences Institute, for the original
  766. idea of using space subdivision for the color reduction algorithm.
  767. With Paul's permission, the \fBCOLOR REDUCTION ALGORITHM\fP section is
  768. a adaptation from a document he wrote.
  769. .SH AUTHORS
  770. John Cristy, E.I. DuPont de Nemours & Company Incorporated
  771. SHAR_EOF
  772. echo 'File ImageMagick/display.man is complete' &&
  773. chmod 0755 ImageMagick/display.man ||
  774. echo 'restore of ImageMagick/display.man failed'
  775. Wc_c="`wc -c < 'ImageMagick/display.man'`"
  776. test 33436 -eq "$Wc_c" ||
  777.     echo 'ImageMagick/display.man: original size 33436, current size' "$Wc_c"
  778. rm -f _shar_wnt_.tmp
  779. fi
  780. # ============= ImageMagick/xtp/Makefile ==============
  781. if test ! -d 'ImageMagick/xtp'; then
  782.     echo 'x - creating directory ImageMagick/xtp'
  783.     mkdir 'ImageMagick/xtp'
  784. fi
  785. if test -f 'ImageMagick/xtp/Makefile' -a X"$1" != X"-c"; then
  786.     echo 'x - skipping ImageMagick/xtp/Makefile (File already exists)'
  787.     rm -f _shar_wnt_.tmp
  788. else
  789. > _shar_wnt_.tmp
  790. echo 'x - extracting ImageMagick/xtp/Makefile (Text)'
  791. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/xtp/Makefile' &&
  792. # Makefile generated by imake - do not edit!
  793. # $XConsortium: imake.c,v 1.51 89/12/12 12:37:30 jim Exp $
  794. #
  795. # The cpp used on this machine replaces all newlines and multiple tabs and
  796. # spaces in a macro expansion with a single space.  Imake tries to compensate
  797. # for this, but is not always successful.
  798. #
  799. X
  800. ###########################################################################
  801. # Makefile generated from "Imake.tmpl" and <Imakefile>
  802. # $XConsortium: Imake.tmpl,v 1.77 89/12/18 17:01:37 jim Exp $
  803. #
  804. # Platform-specific parameters may be set in the appropriate .cf
  805. # configuration files.  Site-wide parameters may be set in the file
  806. # site.def.  Full rebuilds are recommended if any parameters are changed.
  807. #
  808. # If your C preprocessor doesn't define any unique symbols, you'll need
  809. # to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
  810. # "make Makefile", "make Makefiles", or "make World").
  811. #
  812. # If you absolutely can't get imake to work, you'll need to set the
  813. # variables at the top of each Makefile as well as the dependencies at the
  814. # bottom (makedepend will do this automatically).
  815. #
  816. X
  817. ###########################################################################
  818. # platform-specific configuration parameters - edit sun.cf to change
  819. X
  820. # platform:  $XConsortium: sun.cf,v 1.38 89/12/23 16:10:10 jim Exp $
  821. # operating system:  SunOS 4.0.3
  822. X
  823. ###########################################################################
  824. # site-specific configuration parameters - edit site.def to change
  825. X
  826. # site:  $XConsortium: site.def,v 1.21 89/12/06 11:46:50 jim Exp $
  827. X
  828. X            SHELL = /bin/sh
  829. X
  830. X              TOP = .
  831. X      CURRENT_DIR = .
  832. X
  833. X               AR = ar cq
  834. X  BOOTSTRAPCFLAGS =
  835. X               CC = cc
  836. X
  837. X         COMPRESS = compress
  838. X              CPP = /lib/cpp $(STD_CPP_DEFINES)
  839. X    PREPROCESSCMD = cc -E $(STD_CPP_DEFINES)
  840. X          INSTALL = install
  841. X               LD = ld
  842. X             LINT = lint
  843. X      LINTLIBFLAG = -C
  844. X         LINTOPTS = -axz
  845. X               LN = ln -s
  846. X             MAKE = make
  847. X               MV = mv
  848. X               CP = cp
  849. X           RANLIB = ranlib
  850. X  RANLIBINSTFLAGS =
  851. X               RM = rm -f
  852. X     STD_INCLUDES =
  853. X  STD_CPP_DEFINES =
  854. X      STD_DEFINES =
  855. X EXTRA_LOAD_FLAGS =
  856. X  EXTRA_LIBRARIES =
  857. X             TAGS = ctags
  858. X
  859. X    SHAREDCODEDEF = -DSHAREDCODE
  860. X         SHLIBDEF = -DSUNSHLIB
  861. X
  862. X    PROTO_DEFINES =
  863. X
  864. X     INSTPGMFLAGS =
  865. X
  866. X     INSTBINFLAGS = -m 0755
  867. X     INSTUIDFLAGS = -m 4755
  868. X     INSTLIBFLAGS = -m 0664
  869. X     INSTINCFLAGS = -m 0444
  870. X     INSTMANFLAGS = -m 0444
  871. X     INSTDATFLAGS = -m 0444
  872. X    INSTKMEMFLAGS = -m 4755
  873. X
  874. X          DESTDIR =
  875. X
  876. X     TOP_INCLUDES = -I$(INCROOT)
  877. X
  878. X      CDEBUGFLAGS = -O
  879. X        CCOPTIONS =
  880. X      COMPATFLAGS =
  881. X
  882. X      ALLINCLUDES = $(STD_INCLUDES) $(TOP_INCLUDES) $(INCLUDES) $(EXTRA_INCLUDES)
  883. X       ALLDEFINES = $(ALLINCLUDES) $(STD_DEFINES) $(PROTO_DEFINES) $(DEFINES) $(COMPATFLAGS)
  884. X           CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(ALLDEFINES)
  885. X        LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES)
  886. X           LDLIBS = $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  887. X        LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS)
  888. X   LDCOMBINEFLAGS = -X -r
  889. X
  890. X        MACROFILE = sun.cf
  891. X           RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut
  892. X
  893. X    IMAKE_DEFINES =
  894. X
  895. X         IRULESRC = $(CONFIGDIR)
  896. X        IMAKE_CMD = $(IMAKE) -DUseInstalled -I$(IRULESRC) $(IMAKE_DEFINES)
  897. X
  898. X     ICONFIGFILES = $(IRULESRC)/Imake.tmpl $(IRULESRC)/Imake.rules \
  899. X            $(IRULESRC)/Project.tmpl $(IRULESRC)/site.def \
  900. X            $(IRULESRC)/$(MACROFILE) $(EXTRA_ICONFIGFILES)
  901. X
  902. ###########################################################################
  903. # X Window System Build Parameters
  904. # $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
  905. X
  906. ###########################################################################
  907. # X Window System make variables; this need to be coordinated with rules
  908. # $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
  909. X
  910. X          PATHSEP = /
  911. X        USRLIBDIR = $(DESTDIR)/usr/lib
  912. X           BINDIR = $(DESTDIR)/usr/bin/X11
  913. X          INCROOT = $(DESTDIR)/usr/include
  914. X     BUILDINCROOT = $(TOP)
  915. X      BUILDINCDIR = $(BUILDINCROOT)/X11
  916. X      BUILDINCTOP = ..
  917. X           INCDIR = $(INCROOT)/X11
  918. X           ADMDIR = $(DESTDIR)/usr/adm
  919. X           LIBDIR = $(USRLIBDIR)/X11
  920. X        CONFIGDIR = $(LIBDIR)/config
  921. X       LINTLIBDIR = $(USRLIBDIR)/lint
  922. X
  923. X          FONTDIR = $(LIBDIR)/fonts
  924. X         XINITDIR = $(LIBDIR)/xinit
  925. X           XDMDIR = $(LIBDIR)/xdm
  926. X           AWMDIR = $(LIBDIR)/awm
  927. X           TWMDIR = $(LIBDIR)/twm
  928. X           GWMDIR = $(LIBDIR)/gwm
  929. X          MANPATH = $(DESTDIR)/usr/man
  930. X    MANSOURCEPATH = $(MANPATH)/man
  931. X           MANDIR = $(MANSOURCEPATH)n
  932. X        LIBMANDIR = $(MANSOURCEPATH)3
  933. X      XAPPLOADDIR = $(LIBDIR)/app-defaults
  934. X
  935. X        SOXLIBREV = 4.2
  936. X          SOXTREV = 4.0
  937. X         SOXAWREV = 4.0
  938. X        SOOLDXREV = 4.0
  939. X         SOXMUREV = 4.0
  940. X        SOXEXTREV = 4.0
  941. X
  942. X       FONTCFLAGS = -t
  943. X
  944. X     INSTAPPFLAGS = $(INSTDATFLAGS)
  945. X
  946. X            IMAKE = imake
  947. X           DEPEND = makedepend
  948. X              RGB = rgb
  949. X            FONTC = bdftosnf
  950. X        MKFONTDIR = mkfontdir
  951. X        MKDIRHIER = /bin/sh $(BINDIR)/mkdirhier.sh
  952. X
  953. X        CONFIGSRC = $(TOP)/config
  954. X        CLIENTSRC = $(TOP)/clients
  955. X          DEMOSRC = $(TOP)/demos
  956. X           LIBSRC = $(TOP)/lib
  957. X          FONTSRC = $(TOP)/fonts
  958. X       INCLUDESRC = $(TOP)/X11
  959. X        SERVERSRC = $(TOP)/server
  960. X          UTILSRC = $(TOP)/util
  961. X        SCRIPTSRC = $(UTILSRC)/scripts
  962. X       EXAMPLESRC = $(TOP)/examples
  963. X       CONTRIBSRC = $(TOP)/../contrib
  964. X           DOCSRC = $(TOP)/doc
  965. X           RGBSRC = $(TOP)/rgb
  966. X        DEPENDSRC = $(UTILSRC)/makedepend
  967. X         IMAKESRC = $(CONFIGSRC)
  968. X         XAUTHSRC = $(LIBSRC)/Xau
  969. X          XLIBSRC = $(LIBSRC)/X
  970. X           XMUSRC = $(LIBSRC)/Xmu
  971. X       TOOLKITSRC = $(LIBSRC)/Xt
  972. X       AWIDGETSRC = $(LIBSRC)/Xaw
  973. X       OLDXLIBSRC = $(LIBSRC)/oldX
  974. X      XDMCPLIBSRC = $(LIBSRC)/Xdmcp
  975. X      BDFTOSNFSRC = $(FONTSRC)/bdftosnf
  976. X     MKFONTDIRSRC = $(FONTSRC)/mkfontdir
  977. X     EXTENSIONSRC = $(TOP)/extensions
  978. X
  979. X  DEPEXTENSIONLIB = $(USRLIBDIR)/libXext.a
  980. X     EXTENSIONLIB =  -lXext
  981. X
  982. X          DEPXLIB = $(DEPEXTENSIONLIB)
  983. X             XLIB = $(EXTENSIONLIB) -lX11
  984. X
  985. X      DEPXAUTHLIB = $(USRLIBDIR)/libXau.a
  986. X         XAUTHLIB =  -lXau
  987. X
  988. X        DEPXMULIB =
  989. X           XMULIB = -lXmu
  990. X
  991. X       DEPOLDXLIB =
  992. X          OLDXLIB = -loldX
  993. X
  994. X      DEPXTOOLLIB =
  995. X         XTOOLLIB = -lXt
  996. X
  997. X        DEPXAWLIB =
  998. X           XAWLIB = -lXaw
  999. X
  1000. X LINTEXTENSIONLIB = $(USRLIBDIR)/llib-lXext.ln
  1001. X         LINTXLIB = $(USRLIBDIR)/llib-lX11.ln
  1002. X          LINTXMU = $(USRLIBDIR)/llib-lXmu.ln
  1003. X        LINTXTOOL = $(USRLIBDIR)/llib-lXt.ln
  1004. X          LINTXAW = $(USRLIBDIR)/llib-lXaw.ln
  1005. X
  1006. X          DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
  1007. X
  1008. X         DEPLIBS1 = $(DEPLIBS)
  1009. X         DEPLIBS2 = $(DEPLIBS)
  1010. X         DEPLIBS3 = $(DEPLIBS)
  1011. X
  1012. ###########################################################################
  1013. # Imake rules for building libraries, programs, scripts, and data files
  1014. # rules:  $XConsortium: Imake.rules,v 1.67 89/12/18 17:14:15 jim Exp $
  1015. X
  1016. ###########################################################################
  1017. # start of Imakefile
  1018. X
  1019. BINDIR = $(DESTDIR)/usr/local/bin
  1020. PROGRAMS= xtp
  1021. SRCS= xtp.c regular.c
  1022. OBJS= xtp.o regular.o
  1023. X
  1024. all:: $(PROGRAMS)
  1025. X
  1026. X PROGRAM = xtp
  1027. X
  1028. all:: xtp
  1029. X
  1030. xtp: $(OBJS) $(DEPLIBS)
  1031. X    $(RM) $@
  1032. X    $(CC) -o $@ $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS)
  1033. X
  1034. saber_xtp:
  1035. X    #load $(ALLDEFINES) $(SRCS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  1036. X
  1037. osaber_xtp:
  1038. X    #load $(ALLDEFINES) $(OBJS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  1039. X
  1040. install:: xtp
  1041. X    $(INSTALL) -c $(INSTPGMFLAGS)   xtp $(BINDIR)
  1042. X
  1043. install.man:: xtp.man
  1044. X    $(INSTALL) -c $(INSTMANFLAGS) xtp.man $(MANDIR)/xtp.n
  1045. X
  1046. depend::
  1047. X    $(DEPEND) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS)
  1048. X
  1049. lint:
  1050. X    $(LINT) $(LINTFLAGS) $(SRCS) $(LINTLIBS)
  1051. lint1:
  1052. X    $(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS)
  1053. X
  1054. clean::
  1055. X    $(RM) $(PROGRAM)
  1056. X
  1057. ###########################################################################
  1058. # common rules for all Makefiles - do not edit
  1059. X
  1060. emptyrule::
  1061. X
  1062. clean::
  1063. X    $(RM_CMD) \#*
  1064. X
  1065. Makefile::
  1066. X    -@if [ -f Makefile ]; then \
  1067. X    echo "    $(RM) Makefile.bak; $(MV) Makefile Makefile.bak"; \
  1068. X    $(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
  1069. X    else exit 0; fi
  1070. X    $(IMAKE_CMD) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
  1071. X
  1072. tags::
  1073. X    $(TAGS) -w *.[ch]
  1074. X    $(TAGS) -xw *.[ch] > TAGS
  1075. X
  1076. saber:
  1077. X    #load $(ALLDEFINES) $(SRCS)
  1078. X
  1079. osaber:
  1080. X    #load $(ALLDEFINES) $(OBJS)
  1081. X
  1082. ###########################################################################
  1083. # empty rules for directories that do not have SUBDIRS - do not edit
  1084. X
  1085. install::
  1086. X    @echo "install in $(CURRENT_DIR) done"
  1087. X
  1088. install.man::
  1089. X    @echo "install.man in $(CURRENT_DIR) done"
  1090. X
  1091. Makefiles::
  1092. X
  1093. includes::
  1094. X
  1095. ###########################################################################
  1096. # dependencies generated by makedepend
  1097. X
  1098. SHAR_EOF
  1099. chmod 0755 ImageMagick/xtp/Makefile ||
  1100. echo 'restore of ImageMagick/xtp/Makefile failed'
  1101. Wc_c="`wc -c < 'ImageMagick/xtp/Makefile'`"
  1102. test 8840 -eq "$Wc_c" ||
  1103.     echo 'ImageMagick/xtp/Makefile: original size 8840, current size' "$Wc_c"
  1104. rm -f _shar_wnt_.tmp
  1105. fi
  1106. # ============= ImageMagick/xtp/Imakefile ==============
  1107. if test -f 'ImageMagick/xtp/Imakefile' -a X"$1" != X"-c"; then
  1108.     echo 'x - skipping ImageMagick/xtp/Imakefile (File already exists)'
  1109.     rm -f _shar_wnt_.tmp
  1110. else
  1111. > _shar_wnt_.tmp
  1112. echo 'x - extracting ImageMagick/xtp/Imakefile (Text)'
  1113. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/xtp/Imakefile' &&
  1114. BINDIR = $(DESTDIR)/usr/local/bin
  1115. PROGRAMS= xtp
  1116. SRCS= xtp.c regular.c
  1117. OBJS= xtp.o regular.o
  1118. X
  1119. AllTarget($(PROGRAMS))
  1120. X
  1121. ComplexProgramTarget(xtp)
  1122. SHAR_EOF
  1123. chmod 0755 ImageMagick/xtp/Imakefile ||
  1124. echo 'restore of ImageMagick/xtp/Imakefile failed'
  1125. Wc_c="`wc -c < 'ImageMagick/xtp/Imakefile'`"
  1126. test 143 -eq "$Wc_c" ||
  1127.     echo 'ImageMagick/xtp/Imakefile: original size 143, current size' "$Wc_c"
  1128. rm -f _shar_wnt_.tmp
  1129. fi
  1130. # ============= ImageMagick/xtp/xtp.1 ==============
  1131. if test -f 'ImageMagick/xtp/xtp.1' -a X"$1" != X"-c"; then
  1132.     echo 'x - skipping ImageMagick/xtp/xtp.1 (File already exists)'
  1133.     rm -f _shar_wnt_.tmp
  1134. else
  1135. > _shar_wnt_.tmp
  1136. echo 'x - extracting ImageMagick/xtp/xtp.1 (Text)'
  1137. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/xtp/xtp.1' &&
  1138. X
  1139. X
  1140. X
  1141. X9XTP(1)                    (16 June 1990)                   XTP(1)
  1142. X
  1143. X
  1144. X
  1145. NNNNAAAAMMMMEEEE
  1146. X     xtp - file transfer program
  1147. X
  1148. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  1149. X     xxxxttttpppp [ -_o_p_t_i_o_n_s ... ] <_h_o_s_t/_i_p _a_d_d_r_e_s_s> <_h_o_m_e _d_i_r_e_c_t_o_r_y>
  1150. X
  1151. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  1152. X     _X_t_p is a utility for retrieving, listing, or printing files
  1153. X     from a remote network site.  _X_t_p performs most of the same
  1154. X     functions as the _f_t_p program, but does not require any
  1155. X     interactive commands.  You simply specify the file transfer
  1156. X     task on the command line and _x_t_p performs the task
  1157. X     automatically.
  1158. X
  1159. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  1160. X     To retrieve file display.tar.Z from host wizard.dupont.com,
  1161. X     use:
  1162. X
  1163. X          xtp -binary -retrieve display.tar.Z wizard.dupont.com
  1164. X
  1165. X     To retrieve all the files from directory _p_u_b_l_i_c/_d_o_c_u_m_e_n_t_s
  1166. X     from host wizard.dupont.com, use:
  1167. X
  1168. X          xtp -binary -retrieve documents/ wizard.dupont.com
  1169. X     public
  1170. X
  1171. OOOOPPPPTTTTIIIIOOOONNNNSSSS
  1172. X     ----bbbbiiiinnnnaaaarrrryyyy
  1173. X          retrieve files as binary.
  1174. X
  1175. X     ----eeeexxxxcccclllluuuuddddeeee _e_x_p_r_e_s_s_i_o_n
  1176. X          exclude files that match the _r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n.
  1177. X
  1178. X     ----ddddiiiirrrreeeeccccttttoooorrrryyyy _e_x_p_r_e_s_s_i_o_n
  1179. X          list the names of files and their attributes that match
  1180. X          the _r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n.
  1181. X
  1182. X     ----iiiiddddeeeennnntttt _p_a_s_s_w_o_r_d
  1183. X          specifies password.
  1184. X
  1185. X     ----pppprrrriiiinnnntttt _e_x_p_r_e_s_s_i_o_n
  1186. X          print files that match the _r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n.
  1187. X
  1188. X     ----rrrreeeettttrrrriiiieeeevvvveeee _e_x_p_r_e_s_s_i_o_n
  1189. X          retrieve files that match the _r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n.
  1190. X
  1191. X          Retrieved files are stored on your local host directory
  1192. X          as the full name of the retrieved file.  For example,
  1193. X          if the retrieved file is named _d_o_c_u_m_e_n_t_s/_x_t_p._m_a_n on the
  1194. X          remote FTP server, it will appear in your home
  1195. X          directory as _d_o_c_u_m_e_n_t_s/_x_t_p._m_a_n.
  1196. X9
  1197. X
  1198. (printed 12/12/90) Ardent Computer Corporation             Page 1
  1199. X
  1200. X
  1201. X
  1202. X
  1203. X
  1204. X
  1205. X
  1206. X9XTP(1)                    (16 June 1990)                   XTP(1)
  1207. X
  1208. X
  1209. X
  1210. X     ----ttttiiiimmmmeeeeoooouuuutttt _s_e_c_o_n_d_s
  1211. X          specifies maximum seconds to logon to the remote FTP
  1212. X          server.  If this time expires, the program terminates.
  1213. X
  1214. X     ----uuuusssseeeerrrr _n_a_m_e
  1215. X          identify yourself to the remote FTP server.
  1216. X
  1217. X     If ----uuuusssseeeerrrr is specified but not ----iiiiddddeeeennnntttt, the password is
  1218. X     obtained from you interactively.
  1219. X
  1220. X     If neither ----pppprrrriiiinnnntttt or ----rrrreeeettttrrrriiiieeeevvvveeee are specified on the command
  1221. X     line, a directory of files is listed for the remote network
  1222. X     host.
  1223. X
  1224. X     Filename searching begins at the home directory.  Some
  1225. X     remote hosts may have thousands of files causing a
  1226. X     significant delay satisfying your request.  You can reduce
  1227. X     the searching required by specifying <_h_o_m_e _d_i_r_e_c_t_o_r_y> on the
  1228. X     command line.  This limits the filename search to the
  1229. X     specified directory and any of its subdirectories.
  1230. X
  1231. X     If only the program name is specified on the command line,
  1232. X     the program command syntax and options are listed.
  1233. X
  1234. RRRREEEEGGGGUUUULLLLAAAARRRR EEEEXXXXPPPPRRRREEEESSSSSSSSIIIIOOOONNNNSSSS
  1235. X     A _r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n is zero or more branches, separated by
  1236. X     ||||.  It matches anything that matches one of the branches.
  1237. X
  1238. X     A branch is zero or more pieces, concatenated.  It matches a
  1239. X     match for the first, followed by a match for the second,
  1240. X     etc.
  1241. X
  1242. X     A piece is an atom possibly followed by ****, ++++, or ????.  An atom
  1243. X     followed by **** matches a sequence of 0 or more matches of the
  1244. X     atom.  An atom followed by ++++ matches a sequence of 1 or more
  1245. X     matches of the atom.  An atom followed by ???? matches a match
  1246. X     of the atom, or the null pattern.
  1247. X
  1248. X     An atom is a _r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n in parentheses (matching a
  1249. X     match for the _r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n), a range (see below), ....
  1250. X     (matching any single character), ^^^^ (matching the null
  1251. X     pattern at the beginning of the input pattern), $$$$ (matching
  1252. X     the null pattern at the end of the input pattern), a ''''
  1253. X     followed by a single character (matching that character), or
  1254. X     a single character with no other significance (matching that
  1255. X     character).
  1256. X
  1257. X     A range is a sequence of characters enclosed in [[[[]]]].  It
  1258. X     normally matches any single character from the sequence.  If
  1259. X     the sequence begins with ^^^^, it matches any single character
  1260. X     not from the rest of the sequence.  If two characters in the
  1261. X     sequence are separated by ----, this is shorthand for the full
  1262. X
  1263. X
  1264. (printed 12/12/90) Ardent Computer Corporation             Page 2
  1265. X
  1266. X
  1267. X
  1268. X9
  1269. X
  1270. X
  1271. X9XTP(1)                    (16 June 1990)                   XTP(1)
  1272. X
  1273. X
  1274. X
  1275. X     list of ASCII characters between them (e.g.  [[[[0000----9999]]]] matches
  1276. X     any decimal digit). To include a literal ]]]] in the sequence,
  1277. X     make it the first character (following a possible ^^^^).  To
  1278. X     include a literal ----, make it the first or last character.
  1279. X
  1280. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  1281. X     ftp(1C)
  1282. X
  1283. CCCCOOOOPPPPYYYYRRRRIIIIGGGGHHHHTTTT
  1284. X     Copyright 1990 E. I. Dupont de Nemours & Company
  1285. X
  1286. X     Permission to use, copy, modify, distribute, and sell this
  1287. X     software and its documentation for any purpose is hereby
  1288. X     granted without fee, provided that the above copyright
  1289. X     notice appear in all copies and that both that copyright
  1290. X     notice and this permission notice appear in supporting
  1291. X     documentation, and that the name of E. I. Dupont de Nemours
  1292. X     & Company not be used in advertising or publicity pertaining
  1293. X     to distribution of the software without specific, written
  1294. X     prior permission.  E. I. Dupont de Nemours & Company makes
  1295. X     no representations about the suitability of this software
  1296. X     for any purpose.  It is provided "as is" without express or
  1297. X     implied warranty.
  1298. X
  1299. X     E. I. Dupont de Nemours & Company disclaims all warranties
  1300. X     with regard to this software, including all implied
  1301. X     warranties of merchantability and fitness, in no event shall
  1302. X     E. I. Dupont de Nemours & Company be liable for any special,
  1303. X     indirect or consequential damages or any damages whatsoever
  1304. X     resulting from loss of use, data or profits, whether in an
  1305. X     action of contract, negligence or other tortious action,
  1306. X     arising out of or in connection with the use or performance
  1307. X     of this software.
  1308. X
  1309. AAAACCCCKKKKNNNNOOOOWWWWLLLLEEEEDDDDGGGGEEEEMMMMEEEENNNNTTTTSSSS
  1310. X     Steve Singles, University of Delaware, for the initial
  1311. X     implementation of this program.
  1312. X
  1313. X     Henry Spencer, University of Toronto, for the implementation
  1314. X     of the _r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n interpreter and the text in
  1315. X     RRRREEEEGGGGUUUULLLLAAAARRRR EEEEXXXXPPPPRRRREEEESSSSSSSSIIIIOOOONNNNSSSS.
  1316. X
  1317. AAAAUUUUTTTTHHHHOOOORRRR
  1318. X     John Cristy, E.I. DuPont De Nemours & Company Incorporated
  1319. X
  1320. X
  1321. X
  1322. X
  1323. X
  1324. X
  1325. X
  1326. X9
  1327. X
  1328. (printed 12/12/90) Ardent Computer Corporation             Page 3
  1329. X
  1330. X
  1331. X
  1332. X
  1333. SHAR_EOF
  1334. chmod 0755 ImageMagick/xtp/xtp.1 ||
  1335. echo 'restore of ImageMagick/xtp/xtp.1 failed'
  1336. Wc_c="`wc -c < 'ImageMagick/xtp/xtp.1'`"
  1337. test 8203 -eq "$Wc_c" ||
  1338.     echo 'ImageMagick/xtp/xtp.1: original size 8203, current size' "$Wc_c"
  1339. rm -f _shar_wnt_.tmp
  1340. fi
  1341. # ============= ImageMagick/xtp/README ==============
  1342. if test -f 'ImageMagick/xtp/README' -a X"$1" != X"-c"; then
  1343.     echo 'x - skipping ImageMagick/xtp/README (File already exists)'
  1344.     rm -f _shar_wnt_.tmp
  1345. else
  1346. > _shar_wnt_.tmp
  1347. echo 'x - extracting ImageMagick/xtp/README (Text)'
  1348. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/xtp/README' &&
  1349. XXtp is a utility for retrieving, listing, or printing files from a
  1350. remote network site.  Xtp performs most of the same functions as the
  1351. ftp program, but does not require any interactive commands.  You simply
  1352. specify the file transfer task on the command line and xtp performs the
  1353. transfer automatically.
  1354. X
  1355. To retrieve file contrib/ImageMagick.tar.Z from host expo.lcs.mit.edu, 
  1356. use:
  1357. X
  1358. X  xtp -binary -retrieve ImageMagick.tar.Z expo.lcs.mit.edu contrib
  1359. X
  1360. XXtp requires 4.3 BSD compatibilities.  I have successfully executed it on
  1361. a SUN, DEC Ultrix, MIPS, IBM RS/6000, and Ardent Titan.
  1362. X
  1363. The author is cristy@dupont.com.  Comments, suggestions, etc, are
  1364. welcome, but be kind.
  1365. X
  1366. ---
  1367. X
  1368. Copyright 1990 E. I. Dupont de Nemours & Company
  1369. X
  1370. Permission to use, copy, modify, distribute, and sell this software and
  1371. its documentation for any purpose is hereby granted without fee,
  1372. provided that the above copyright notice appear in all copies and that
  1373. both that copyright notice and this permission notice appear in
  1374. supporting documentation, and that the name of E. I. Dupont de Nemours
  1375. & Company not be used in advertising or publicity pertaining to
  1376. distribution of the software without specific, written prior
  1377. permission.  E. I. Dupont de Nemours & Company makes no representations
  1378. about the suitability of this software for any purpose.  It is provided
  1379. "as is" without express or implied warranty.
  1380. X
  1381. E. I. Dupont de Nemours & Company disclaims all warranties with regard
  1382. to this software, including all implied warranties of merchantability
  1383. and fitness, in no event shall E. I. Dupont de Nemours & Company be
  1384. liable for any special, indirect or consequential damages or any
  1385. damages whatsoever resulting from loss of use, data or profits, whether
  1386. in an action of contract, negligence or other tortious action, arising
  1387. out of or in connection with the use or performance of this software.
  1388. X
  1389. SHAR_EOF
  1390. chmod 0755 ImageMagick/xtp/README ||
  1391. echo 'restore of ImageMagick/xtp/README failed'
  1392. Wc_c="`wc -c < 'ImageMagick/xtp/README'`"
  1393. test 1872 -eq "$Wc_c" ||
  1394.     echo 'ImageMagick/xtp/README: original size 1872, current size' "$Wc_c"
  1395. rm -f _shar_wnt_.tmp
  1396. fi
  1397. # ============= ImageMagick/xtp/regular.c ==============
  1398. if test -f 'ImageMagick/xtp/regular.c' -a X"$1" != X"-c"; then
  1399.     echo 'x - skipping ImageMagick/xtp/regular.c (File already exists)'
  1400.     rm -f _shar_wnt_.tmp
  1401. else
  1402. > _shar_wnt_.tmp
  1403. echo 'x - extracting ImageMagick/xtp/regular.c (Text)'
  1404. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/xtp/regular.c' &&
  1405. /*
  1406. %  A regular expression is zero or more branches, separated by `|'. It
  1407. %  matches anything that matches one of the branches.
  1408. %  
  1409. %  A branch is zero or more pieces, concatenated. It matches a match for
  1410. %  the first, followed by a match for the second, etc.
  1411. %  
  1412. %  A piece is an atom possibly followed by `*', `+', or `?'. An atom
  1413. %  followed by `*' matches a sequence of 0 or more matches of the atom. An
  1414. %  atom followed by `+' matches a sequence of 1 or more matches of the
  1415. %  atom. An atom followed by `?' matches a match of the atom, or the null
  1416. %  pattern.
  1417. %  
  1418. %  An atom is a regular expression in parentheses (matching a match for
  1419. %  the regular expression), a range (see below), `.' (matching any single
  1420. %  character), `^' (matching the null pattern at the beginning of the input
  1421. %  pattern), `$' (matching the null pattern at the end of the input pattern),
  1422. %  a `\' fol- lowed by a single character (matching that character), or a
  1423. %  single character with no other significance (matching that character).
  1424. %  
  1425. %  A range is a sequence of characters enclosed in `[]'. It normally
  1426. %  matches any single character from the sequence. If the sequence begins
  1427. %  with `^', it matches any single charac- ter not from the rest of the
  1428. %  sequence. If two characters in the sequence are separated by `-', this
  1429. %  is shorthand for the full list of ASCII characters between them (e.g.
  1430. %  `[0-9]' matches any decimal digit). To include a literal `]' in the
  1431. %  sequence, make it the first character (following a possible `^').  To
  1432. %  include a literal `-', make it the first or last character.
  1433. %  
  1434. %  If a regular expression could match two different parts of the input
  1435. %  pattern, it will match the one which begins earliest. If both begin in
  1436. %  the same placebut match dif- ferent lengths, or match the same length
  1437. %  in different ways, life gets messier, as follows.
  1438. %  
  1439. %  In general, the possibilities in a list of branches are con- sidered in
  1440. %  left-to-right order, the possibilities for `*', `+', and `?' are
  1441. %  considered longest-first, nested constructs are considered from the
  1442. %  outermost in, and concatenated con- structs are considered
  1443. %  leftmost-first. The match that will be chosen is the one that uses the
  1444. %  earliest possibility in the first choice that has to be made. If there
  1445. %  is more than one choice, the next will be made in the same manner
  1446. %  (earli- est possibility) subject to the decision on the first choice.
  1447. %  And so forth.
  1448. %  
  1449. %  For example, `(ab|a)b*c' could match `abc' in one of two ways. The
  1450. %  first choice is between `ab' and `a'; since `ab' is earlier, and does
  1451. %  lead to a successful overall match, it is chosen. Since the `b' is
  1452. %  already spoken for, the `b*' must match its last possibility-the empty
  1453. %  pattern-since it must respect the earlier choice.
  1454. %  
  1455. %  In the particular case where no `|'s are present and there is only one
  1456. %  `*', `+', or `?', the net effect is that the longest possible match
  1457. %  will be chosen. So `ab*', presented with `xabbbby', will match `abbbb'.
  1458. %  Note that if `ab*' is tried against `xabyabbbz', it will match `ab'
  1459. %  just after `x', due to the begins-earliest rule. (In effect, the deci-
  1460. %  sion on where to start the match is the first choice to be made, hence
  1461. %  subsequent choices must respect it even if this leads them to
  1462. %  less-preferred alternatives.)
  1463. %  
  1464. %  CompileRegularExpression returns NULL for a failure, where failures are
  1465. %  syntax errors, exceeding implementation limits, or applying `+' or `*'
  1466. %  to a possibly-null operand.
  1467. %
  1468. %  This is essentially the same routine written and copywrited by Henry 
  1469. %  Spencer, University of Toronto.  I made minor programming changes but 
  1470. %  major variable name changes to improve readibility.
  1471. %
  1472. %
  1473. */
  1474. #include <stdio.h>
  1475. #include <ctype.h>
  1476. #include <malloc.h>
  1477. #include <string.h>
  1478. #include "regular.h"
  1479. X
  1480. char
  1481. X  *code,
  1482. X  **subpattern_end,
  1483. X  *p,
  1484. X  start_code,
  1485. X  *start_pattern,
  1486. X  **subpattern;
  1487. X
  1488. extern char
  1489. X  *strchr();
  1490. X
  1491. static char    
  1492. X  *token;  
  1493. X
  1494. static int      
  1495. X  number_parenthesis;  
  1496. X
  1497. static long     
  1498. X  code_size;  
  1499. X
  1500. /*
  1501. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1502. %                                                                             %
  1503. %                                                                             %
  1504. %                                                                             %
  1505. %   A t o m                                                                   %
  1506. %                                                                             %
  1507. %                                                                             %
  1508. %                                                                             %
  1509. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1510. %
  1511. %
  1512. */
  1513. static char *Atom(flagp)
  1514. int
  1515. X  *flagp;
  1516. {
  1517. X  int
  1518. X    flags;
  1519. X
  1520. X  register char
  1521. X    *status;
  1522. X
  1523. X  static char
  1524. X    *Node(),
  1525. X    *Regular();
  1526. X
  1527. X  static void
  1528. X    EmitCode();
  1529. X
  1530. X  *flagp=WorstCase;
  1531. X  switch(*token++)
  1532. X  {
  1533. X    case '^':
  1534. X    {
  1535. X      status=Node(MatchBeginningOfLine);
  1536. X      break;
  1537. X    }
  1538. X    case '$':
  1539. X    {
  1540. X      status=Node(MatchEndOfProgramOfLine);
  1541. X      break;
  1542. X    }
  1543. X    case '.':
  1544. X    {
  1545. X      status=Node(MatchAnyCharacter);
  1546. X      *flagp|=NonNull | Simple;
  1547. X      break;
  1548. X    }
  1549. X    case '[':
  1550. X    {
  1551. X      register int
  1552. X        class,
  1553. X        class_end;
  1554. X
  1555. X      if (*token != '^')
  1556. X        status=Node(MatchAnyCharacterOf);
  1557. X      else
  1558. X        {
  1559. X          /*
  1560. X            Complement of range.
  1561. X          */
  1562. X          status=Node(MatchAnyCharacterBut);
  1563. X          token++;
  1564. X        }
  1565. X      if ((*token == ']') || (*token == '-'))
  1566. X        EmitCode(*token++);
  1567. X      while ((*token != '\0') && (*token != ']'))
  1568. X      {
  1569. X        if (*token != '-')
  1570. X          EmitCode(*token++);
  1571. X         else
  1572. X          {
  1573. X            token++;
  1574. X            if ((*token == ']') || (*token == '\0'))
  1575. X              EmitCode('-');
  1576. X            else
  1577. X              {
  1578. X                class=((int)*(unsigned char *)(token-2))+1;
  1579. X                class_end=((int)*(unsigned char *)(token));
  1580. X                if (class > class_end+1)
  1581. X                  Fail("invalid [] range");
  1582. X                for(; class <= class_end; class++)
  1583. X                  EmitCode(class);
  1584. X                token++;
  1585. X              }
  1586. X          }
  1587. X      }
  1588. X      EmitCode('\0');
  1589. X      if (*token != ']')
  1590. X        Fail("unmatched []");
  1591. X      token++;
  1592. X      *flagp|=NonNull | Simple;
  1593. X      break;
  1594. X    }
  1595. X    case '(':
  1596. X    {
  1597. X      status=Regular(1,&flags);
  1598. X      if (status == NULL)
  1599. X        return(NULL);
  1600. X      *flagp|=flags & (NonNull | SpecialStart);
  1601. X      break;
  1602. X    }
  1603. X    case '\0':
  1604. X    case '|':
  1605. X    case ')':
  1606. X    {
  1607. X      Fail("internal urp");
  1608. X      break;
  1609. X    }
  1610. X    case '?':
  1611. X    case '+':
  1612. X    case '*':
  1613. X    {
  1614. X      Fail("?+* follows nothing");
  1615. X      break;
  1616. X    }
  1617. X    case '\\':
  1618. X    {
  1619. X      if (*token == '\0')
  1620. X        Fail("trailing \\");
  1621. X      status=Node(MatchExactly);
  1622. X      EmitCode(*token++);
  1623. X      EmitCode('\0');
  1624. X      *flagp|=NonNull | Simple;
  1625. X      break;
  1626. X    }
  1627. X    default:
  1628. X    {
  1629. X      register char
  1630. X        ender;
  1631. X
  1632. X      register int
  1633. X        length;
  1634. X
  1635. X      token--;
  1636. X      length=strcspn(token,Meta);
  1637. X      if (length <= 0)
  1638. X        Fail("internal disaster");
  1639. X      ender=(*(token+length));
  1640. X      if (length > 1 && MultipleMatches(ender))
  1641. X        length--;
  1642. X      *flagp|=NonNull;
  1643. X      if (length == 1)
  1644. X        *flagp|=Simple;
  1645. X      status=Node(MatchExactly);
  1646. X      while (length > 0)
  1647. X      {
  1648. X        EmitCode(*token++);
  1649. X        length--;
  1650. X      }
  1651. X      EmitCode('\0');
  1652. X      break;
  1653. X    }
  1654. X  }
  1655. X  return(status);
  1656. }
  1657. X
  1658. /*
  1659. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1660. %                                                                             %
  1661. %                                                                             %
  1662. %                                                                             %
  1663. %   B r a n c h                                                               %
  1664. %                                                                             %
  1665. %                                                                             %
  1666. %                                                                             %
  1667. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1668. %
  1669. %  Function Branch Implements the | operator.
  1670. %
  1671. %
  1672. */
  1673. static char *Branch(flagp)
  1674. int
  1675. X  *flagp;
  1676. {
  1677. X  int
  1678. X    flags;
  1679. X
  1680. X  register char
  1681. X    *chain,
  1682. X    *latest,
  1683. X    *status;
  1684. X
  1685. X  static char
  1686. X    *Node(),
  1687. X    *Piece();
  1688. X
  1689. X  static void
  1690. X    Tail();
  1691. X
  1692. X  *flagp=WorstCase;
  1693. X  status=Node(MatchThisOrNext);
  1694. X  chain=NULL;
  1695. X  while ((*token != '\0') && (*token != '|') && (*token != ')'))
  1696. X  {
  1697. X    latest=Piece(&flags);
  1698. X    if (latest == NULL)
  1699. X      return(NULL);
  1700. X    *flagp|=flags & NonNull;
  1701. X    if (chain == NULL)
  1702. X      *flagp|=flags & SpecialStart;
  1703. X    else
  1704. X      Tail(chain,latest);
  1705. X    chain=latest;
  1706. X  }
  1707. X  if (chain == NULL)
  1708. X   (void) Node(MatchEmptyString);
  1709. X  return(status);
  1710. }
  1711. X
  1712. /*
  1713. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1714. %                                                                             %
  1715. %                                                                             %
  1716. %                                                                             %
  1717. %   E m i t C o d e                                                           %
  1718. %                                                                             %
  1719. %                                                                             %
  1720. %                                                                             %
  1721. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1722. %
  1723. %
  1724. */
  1725. static void EmitCode(opcode)
  1726. char
  1727. X  opcode;
  1728. {
  1729. X  if (code != &start_code)
  1730. X    *code++=opcode;
  1731. X  else
  1732. X    code_size++;
  1733. }
  1734. X
  1735. /*
  1736. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1737. %                                                                             %
  1738. %                                                                             %
  1739. %                                                                             %
  1740. %   I n s e r t                                                               %
  1741. %                                                                             %
  1742. %                                                                             %
  1743. %                                                                             %
  1744. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1745. %
  1746. %  Function Insert inserts an operator in front of an already-emitted operand.
  1747. %
  1748. */
  1749. static void Insert(opcode,operand)
  1750. char
  1751. X  opcode,
  1752. X  *operand;
  1753. {
  1754. X  register char
  1755. X    *p,
  1756. X    *place,
  1757. X    *q;
  1758. X
  1759. X  if (code == &start_code)
  1760. X    {
  1761. X      code_size+=3;
  1762. X      return;
  1763. X    }
  1764. X  p=code;
  1765. X  code+=3;
  1766. X  q=code;
  1767. X  while (p > operand)
  1768. X    *--q=(*--p);
  1769. X  place=operand;
  1770. X  *place++=opcode;
  1771. X  *place++='\0';
  1772. X  *place++='\0';
  1773. }
  1774. X
  1775. /*
  1776. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1777. %                                                                             %
  1778. %                                                                             %
  1779. %                                                                             %
  1780. %   M a t c h                                                                 %
  1781. %                                                                             %
  1782. %                                                                             %
  1783. %                                                                             %
  1784. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1785. %
  1786. %
  1787. */
  1788. static int Match(regular_expression)
  1789. char
  1790. X  *regular_expression;
  1791. {
  1792. X  char
  1793. X    *next_token;
  1794. X
  1795. X  register char
  1796. X    *scan;
  1797. X
  1798. X  static char
  1799. X    *NextToken();
  1800. X
  1801. X  static int
  1802. X    Repeat();
  1803. X
  1804. X  scan=regular_expression;
  1805. X  while (scan != NULL)
  1806. X  {
  1807. X    next_token=NextToken(scan);
  1808. X    switch(OpCode(scan))
  1809. X    {
  1810. X      case MatchBeginningOfLine:
  1811. X      {
  1812. X        if (p != start_pattern)
  1813. X          return(0);
  1814. X        break;
  1815. X      }
  1816. X      case MatchEndOfProgramOfLine:
  1817. X      {
  1818. X        if (*p != '\0')
  1819. X         return(0);
  1820. X        break;
  1821. X      }
  1822. X      case MatchAnyCharacter:
  1823. X      {
  1824. X        if (*p == '\0')
  1825. X          return(0);
  1826. X        p++;
  1827. X        break;
  1828. X      }
  1829. X      case MatchExactly:
  1830. X      {
  1831. X        register char
  1832. X          *operand;
  1833. X
  1834. X        register int
  1835. X          length;
  1836. X
  1837. X        operand=Operand(scan);
  1838. X        /*
  1839. X          Inline the first character for speed.
  1840. X        */
  1841. X        if (*operand != *p)
  1842. X          return(0);
  1843. X        length=strlen(operand);
  1844. X        if ((length > 1) && (strncmp(operand,p,length) != 0))
  1845. X          return(0);
  1846. X        p+=length;
  1847. X        break;
  1848. X      }
  1849. X      case MatchAnyCharacterOf:
  1850. X      {
  1851. X        if ((*p == '\0' || strchr(Operand(scan),*p) == NULL))
  1852. X          return(0);
  1853. X        p++;
  1854. X        break;
  1855. X      }
  1856. X      case MatchAnyCharacterBut:
  1857. X      {
  1858. X        if ((*p == '\0') || (strchr(Operand(scan),*p) != NULL))
  1859. X          return(0);
  1860. X        p++;
  1861. X        break;
  1862. X      }
  1863. X      case MatchEmptyString:
  1864. X        break;
  1865. X      case Back:
  1866. X        break;
  1867. X      case Open+1:
  1868. X      case Open+2:
  1869. X      case Open+3:
  1870. X      case Open+4:
  1871. X      case Open+5:
  1872. X      case Open+6:
  1873. X      case Open+7:
  1874. X      case Open+8:
  1875. X      case Open+9:
  1876. X      {
  1877. X        register char
  1878. X          *save;
  1879. X
  1880. X        register int
  1881. X          no;
  1882. X
  1883. X        no=OpCode(scan)-Open;
  1884. X        save=p;
  1885. X        if (!Match(next_token))
  1886. X          return(0);
  1887. X        else
  1888. X          {
  1889. X            /*
  1890. X              Don't set subpattern if some later invocation of the same
  1891. X              parentheses already has.
  1892. X            */
  1893. X            if (subpattern[no] == NULL)
  1894. X              subpattern[no]=save;
  1895. X            return(1);
  1896. X          }
  1897. X        break;
  1898. X      }
  1899. X      case Close+1:
  1900. X      case Close+2:
  1901. X      case Close+3:
  1902. X      case Close+4:
  1903. X      case Close+5:
  1904. X      case Close+6:
  1905. X      case Close+7:
  1906. X      case Close+8:
  1907. X      case Close+9:
  1908. X      {
  1909. X        register char
  1910. X          *save;
  1911. X
  1912. X        register int
  1913. X          no;
  1914. X
  1915. X        no=OpCode(scan)-Close;
  1916. X        save=p;
  1917. X        if (!Match(next_token))
  1918. X           return(0);
  1919. X        else
  1920. X          {
  1921. X            /*
  1922. X              Don't set subpattern_end if some later invocation of the same 
  1923. X              parentheses already has.
  1924. X            */
  1925. X            if (subpattern_end[no] == NULL)
  1926. X              subpattern_end[no]=save;
  1927. X            return(1);
  1928. X          }
  1929. X        break;
  1930. X      }
  1931. X      case MatchThisOrNext:
  1932. X      {
  1933. X        register char
  1934. X          *save;
  1935. X
  1936. X        if (OpCode(next_token) != MatchThisOrNext)
  1937. X          next_token=Operand(scan);  
  1938. X        else
  1939. X          {
  1940. X            do
  1941. X            {
  1942. X              save=p;
  1943. X              if (Match(Operand(scan)))
  1944. X                return(1);
  1945. X              p=save;
  1946. X              scan=NextToken(scan);
  1947. X            } while ((scan != NULL) && (OpCode(scan) == MatchThisOrNext));
  1948. X            return(0);
  1949. X          }
  1950. X        break;
  1951. X      }
  1952. X      case MatchZeroOrMore:
  1953. X      case MatchOneOrMore:
  1954. X      {
  1955. X        register char
  1956. X          next_tokench,
  1957. X          *save;
  1958. X
  1959. X        register int
  1960. X          min,
  1961. X          no;
  1962. X
  1963. X        /*
  1964. X          Lookahead to avoid useless match attempts when we know what
  1965. X          character comes next_token.
  1966. X        */
  1967. X        next_tokench='\0';
  1968. X        if (OpCode(next_token) == MatchExactly)
  1969. X          next_tokench=(*Operand(next_token));
  1970. X        min=(OpCode(scan) == MatchZeroOrMore) ? 0 : 1;
  1971. X        save=p;
  1972. X        no=Repeat(Operand(scan));
  1973. X        while (no >= min)
  1974. X        {
  1975. X          /*
  1976. X            If it could work, try it.
  1977. X          */
  1978. X          if ((next_tokench == '\0') || (*p == next_tokench))
  1979. X            if (Match(next_token))
  1980. X              return(1);
  1981. X          /*
  1982. X            Couldn't or didn't -- back up.
  1983. X          */
  1984. X          no--;
  1985. X          p=save+no;
  1986. X        }
  1987. X        return(0);
  1988. X        break;
  1989. X      }
  1990. X      case EndOfProgram:
  1991. X        return(1);
  1992. X        break;
  1993. X      default:
  1994. X        (void) fprintf(stderr,"Regular(3): %s","memory corruption");
  1995. X        return(0);
  1996. X        break;
  1997. X    }
  1998. X    scan=next_token;
  1999. X  }
  2000. X  (void) fprintf(stderr,"Regular(3): %s","corrupted pointers");
  2001. X  return(0);
  2002. }
  2003. X
  2004. /*
  2005. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2006. %                                                                             %
  2007. %                                                                             %
  2008. %                                                                             %
  2009. %   N e x t T o k e n                                                         %
  2010. %                                                                             %
  2011. %                                                                             %
  2012. %                                                                             %
  2013. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2014. %
  2015. %
  2016. */
  2017. static char *NextToken(p)
  2018. register char
  2019. X  *p;
  2020. {
  2021. X  register int
  2022. X    offset;
  2023. X
  2024. X  if (p == &start_code)
  2025. X    return(NULL);
  2026. X  offset=Next(p);
  2027. X  if (offset == 0)
  2028. X    return(NULL);
  2029. X  if (OpCode(p) == Back)
  2030. X    return(p-offset);
  2031. X  else
  2032. X    return(p+offset);
  2033. }
  2034. X
  2035. /*
  2036. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2037. %                                                                             %
  2038. %                                                                             %
  2039. %                                                                             %
  2040. %   N o d e                                                                   %
  2041. %                                                                             %
  2042. %                                                                             %
  2043. %                                                                             %
  2044. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2045. %
  2046. %
  2047. */
  2048. static char *Node(opcode)
  2049. char
  2050. X  opcode;
  2051. {
  2052. X  register char
  2053. X    *ptr,
  2054. X    *status;
  2055. X
  2056. X  status=code;
  2057. X  if (status == &start_code)
  2058. X    {
  2059. X      code_size+=3;
  2060. X      return(status);
  2061. X    }
  2062. X  ptr=status;
  2063. X  *ptr++=opcode;
  2064. X  *ptr++='\0';
  2065. X  *ptr++='\0';
  2066. X  code=ptr;
  2067. X  return(status);
  2068. }
  2069. X
  2070. /*
  2071. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2072. %                                                                             %
  2073. %                                                                             %
  2074. %                                                                             %
  2075. %   O p T a i l                                                               %
  2076. %                                                                             %
  2077. %                                                                             %
  2078. %                                                                             %
  2079. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2080. %
  2081. %
  2082. */
  2083. static void OpTail(p,value)
  2084. char
  2085. X  *p;
  2086. X
  2087. char
  2088. X  *value;
  2089. {
  2090. X  static void
  2091. X    Tail();
  2092. X
  2093. X  /*
  2094. X    "Operandless" and "op != MatchThisOrNext" are synonymous in practice.
  2095. X  */
  2096. X  if ((p == NULL) || (p == &start_code) || (OpCode(p) != MatchThisOrNext))
  2097. X    return;
  2098. X  Tail(Operand(p),value);
  2099. }
  2100. X
  2101. /*
  2102. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2103. %                                                                             %
  2104. SHAR_EOF
  2105. true || echo 'restore of ImageMagick/xtp/regular.c failed'
  2106. fi
  2107. echo 'End of ImageMagick part 2'
  2108. echo 'File ImageMagick/xtp/regular.c is continued in part 3'
  2109. echo 3 > _shar_seq_.tmp
  2110. exit 0
  2111. --
  2112. Dan Heller
  2113. O'Reilly && Associates       Z-Code Software    Comp-sources-x:
  2114. Senior Writer                President          comp-sources-x@uunet.uu.net
  2115. argv@ora.com                 argv@zipcode.com
  2116.