home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume27 / transfig-2.1.8 / part04 < prev    next >
Text File  |  1993-10-05  |  74KB  |  2,784 lines

  1. Newsgroups: comp.sources.unix
  2. From: envbvs@epb12.lbl.gov (Brian V. Smith)
  3. Subject: v27i058: transfig-2.1.8 - a set of tools for creating TeX documents with graphics, Part04/07
  4. References: <1.749903574.10622@gw.home.vix.com>
  5. Sender: unix-sources-moderator@gw.home.vix.com
  6. Approved: vixie@gw.home.vix.com
  7.  
  8. Submitted-By: envbvs@epb12.lbl.gov (Brian V. Smith)
  9. Posting-Number: Volume 27, Issue 58
  10. Archive-Name: transfig-2.1.8/part04
  11.  
  12. #! /bin/sh
  13. # This is a shell archive.  Remove anything before this line, then unpack
  14. # it by saving it into a file and typing "sh file".  To overwrite existing
  15. # files, type "sh file -c".  You can also feed this as standard input via
  16. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  17. # will see the following message at the end:
  18. #        "End of archive 4 (of 7)."
  19. # Contents:  fig2dev/Makefile fig2dev/dev/genpic.c
  20. #   fig2dev/dev/gentextyl.c fig2dev/read.c
  21. # Wrapped by envbvs@epb12.lbl.gov.lbl.gov on Fri Oct  1 14:55:48 1993
  22. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  23. if test -f 'fig2dev/Makefile' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'fig2dev/Makefile'\"
  25. else
  26. echo shar: Extracting \"'fig2dev/Makefile'\" \(16232 characters\)
  27. sed "s/^X//" >'fig2dev/Makefile' <<'END_OF_FILE'
  28. X# Makefile generated by imake - do not edit!
  29. X# $XConsortium: imake.c,v 1.65 91/07/25 17:50:17 rws Exp $
  30. X#
  31. X# The cpp used on this machine replaces all newlines and multiple tabs and
  32. X# spaces in a macro expansion with a single space.  Imake tries to compensate
  33. X# for this, but is not always successful.
  34. X#
  35. X
  36. X# -------------------------------------------------------------------------
  37. X# Makefile generated from "Imake.tmpl" and </tmp/IIf.a21005>
  38. X# $XConsortium: Imake.tmpl,v 1.139 91/09/16 08:52:48 rws Exp $
  39. X#
  40. X# Platform-specific parameters may be set in the appropriate <vendor>.cf
  41. X# configuration files.  Site-specific parameters should be set in the file
  42. X# site.def.  Full rebuilds are recommended if any parameters are changed.
  43. X#
  44. X# If your C preprocessor does not define any unique symbols, you will need
  45. X# to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
  46. X# "make World" the first time).
  47. X#
  48. X
  49. X# -------------------------------------------------------------------------
  50. X# site-specific configuration parameters that need to come before
  51. X# the platform-specific parameters - edit site.def to change
  52. X
  53. X# site:  $XConsortium: site.def,v 1.2 91/07/30 20:26:44 rws Exp $
  54. X
  55. X# -------------------------------------------------------------------------
  56. X# platform-specific configuration parameters - edit sun.cf to change
  57. X
  58. X# platform:  $XConsortium: sun.cf,v 1.72.1.1 92/03/18 13:13:37 rws Exp $
  59. X
  60. X# operating system:  SunOS 4.1.2
  61. X
  62. X# $XConsortium: sunLib.rules,v 1.7 91/12/20 11:19:47 rws Exp $
  63. X
  64. X# -------------------------------------------------------------------------
  65. X# site-specific configuration parameters that go after
  66. X# the platform-specific parameters - edit site.def to change
  67. X
  68. X# site:  $XConsortium: site.def,v 1.2 91/07/30 20:26:44 rws Exp $
  69. X
  70. X            SHELL = /bin/sh
  71. X
  72. X              TOP = ../.
  73. X      CURRENT_DIR = ./fig2dev
  74. X
  75. X               AR = ar clq
  76. X  BOOTSTRAPCFLAGS =
  77. X               CC = cc
  78. X               AS = as
  79. X
  80. X         COMPRESS = compress
  81. X              CPP = /lib/cpp $(STD_CPP_DEFINES)
  82. X    PREPROCESSCMD = cc -E $(STD_CPP_DEFINES)
  83. X          INSTALL = install
  84. X               LD = ld
  85. X             LINT = lint
  86. X      LINTLIBFLAG = -C
  87. X         LINTOPTS = -axz
  88. X               LN = ln -s
  89. X             MAKE = make
  90. X               MV = mv
  91. X               CP = cp
  92. X
  93. X           RANLIB = ranlib
  94. X  RANLIBINSTFLAGS =
  95. X
  96. X               RM = rm -f
  97. X            TROFF = psroff
  98. X         MSMACROS = -ms
  99. X              TBL = tbl
  100. X              EQN = eqn
  101. X     STD_INCLUDES =
  102. X  STD_CPP_DEFINES =
  103. X      STD_DEFINES =
  104. X EXTRA_LOAD_FLAGS =
  105. X  EXTRA_LIBRARIES =
  106. X             TAGS = ctags
  107. X
  108. X    SHAREDCODEDEF = -DSHAREDCODE
  109. X         SHLIBDEF = -DSUNSHLIB
  110. X
  111. X    PROTO_DEFINES =
  112. X
  113. X     INSTPGMFLAGS =
  114. X
  115. X     INSTBINFLAGS = -m 0755
  116. X     INSTUIDFLAGS = -m 4755
  117. X     INSTLIBFLAGS = -m 0644
  118. X     INSTINCFLAGS = -m 0444
  119. X     INSTMANFLAGS = -m 0444
  120. X     INSTDATFLAGS = -m 0444
  121. X    INSTKMEMFLAGS = -g kmem -m 2755
  122. X
  123. X      CDEBUGFLAGS = -O
  124. X        CCOPTIONS =
  125. X
  126. X      ALLINCLUDES = $(INCLUDES) $(EXTRA_INCLUDES) $(TOP_INCLUDES) $(STD_INCLUDES)
  127. X       ALLDEFINES = $(ALLINCLUDES) $(STD_DEFINES) $(EXTRA_DEFINES) $(PROTO_DEFINES) $(DEFINES)
  128. X           CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(ALLDEFINES)
  129. X        LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES)
  130. X
  131. X           LDLIBS = $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  132. X
  133. X        LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS) $(LOCAL_LDFLAGS)
  134. X
  135. X   LDCOMBINEFLAGS = -X -r
  136. X      DEPENDFLAGS =
  137. X
  138. X        MACROFILE = sun.cf
  139. X           RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut
  140. X
  141. X    IMAKE_DEFINES =
  142. X
  143. X         IRULESRC = $(CONFIGDIR)
  144. X        IMAKE_CMD = $(IMAKE) -DUseInstalled -I$(IRULESRC) $(IMAKE_DEFINES)
  145. X
  146. X     ICONFIGFILES = $(IRULESRC)/Imake.tmpl $(IRULESRC)/Imake.rules \
  147. X            $(IRULESRC)/Project.tmpl $(IRULESRC)/site.def \
  148. X            $(IRULESRC)/$(MACROFILE) $(EXTRA_ICONFIGFILES)
  149. X
  150. X# -------------------------------------------------------------------------
  151. X# X Window System Build Parameters
  152. X# $XConsortium: Project.tmpl,v 1.138 91/09/10 09:02:12 rws Exp $
  153. X
  154. X# -------------------------------------------------------------------------
  155. X# X Window System make variables; this need to be coordinated with rules
  156. X
  157. X          PATHSEP = /
  158. X        USRLIBDIR = /usr/lib
  159. X           BINDIR = /usr/bin/X11
  160. X          INCROOT = /usr/include
  161. X     BUILDINCROOT = $(TOP)
  162. X      BUILDINCDIR = $(BUILDINCROOT)/X11
  163. X      BUILDINCTOP = ..
  164. X           INCDIR = $(INCROOT)/X11
  165. X           ADMDIR = /usr/adm
  166. X           LIBDIR = $(USRLIBDIR)/X11
  167. X        CONFIGDIR = $(LIBDIR)/config
  168. X       LINTLIBDIR = $(USRLIBDIR)/lint
  169. X
  170. X          FONTDIR = $(LIBDIR)/fonts
  171. X         XINITDIR = $(LIBDIR)/xinit
  172. X           XDMDIR = $(LIBDIR)/xdm
  173. X           TWMDIR = $(LIBDIR)/twm
  174. X          MANPATH = /usr/man
  175. X    MANSOURCEPATH = $(MANPATH)/man
  176. X        MANSUFFIX = l
  177. X     LIBMANSUFFIX = 3
  178. X           MANDIR = $(MANSOURCEPATH)$(MANSUFFIX)
  179. X        LIBMANDIR = $(MANSOURCEPATH)$(LIBMANSUFFIX)
  180. X           NLSDIR = $(LIBDIR)/nls
  181. X        PEXAPIDIR = $(LIBDIR)/PEX
  182. X      XAPPLOADDIR = $(LIBDIR)/app-defaults
  183. X       FONTCFLAGS = -t
  184. X
  185. X     INSTAPPFLAGS = $(INSTDATFLAGS)
  186. X
  187. X            IMAKE = imake
  188. X           DEPEND = makedepend
  189. X              RGB = rgb
  190. X
  191. X            FONTC = bdftopcf
  192. X
  193. X        MKFONTDIR = mkfontdir
  194. X        MKDIRHIER = /bin/sh $(BINDIR)/mkdirhier
  195. X
  196. X        CONFIGSRC = $(TOP)/config
  197. X       DOCUTILSRC = $(TOP)/doc/util
  198. X        CLIENTSRC = $(TOP)/clients
  199. X          DEMOSRC = $(TOP)/demos
  200. X           LIBSRC = $(TOP)/lib
  201. X          FONTSRC = $(TOP)/fonts
  202. X       INCLUDESRC = $(TOP)/X11
  203. X        SERVERSRC = $(TOP)/server
  204. X          UTILSRC = $(TOP)/util
  205. X        SCRIPTSRC = $(UTILSRC)/scripts
  206. X       EXAMPLESRC = $(TOP)/examples
  207. X       CONTRIBSRC = $(TOP)/../contrib
  208. X           DOCSRC = $(TOP)/doc
  209. X           RGBSRC = $(TOP)/rgb
  210. X        DEPENDSRC = $(UTILSRC)/makedepend
  211. X         IMAKESRC = $(CONFIGSRC)
  212. X         XAUTHSRC = $(LIBSRC)/Xau
  213. X          XLIBSRC = $(LIBSRC)/X
  214. X           XMUSRC = $(LIBSRC)/Xmu
  215. X       TOOLKITSRC = $(LIBSRC)/Xt
  216. X       AWIDGETSRC = $(LIBSRC)/Xaw
  217. X       OLDXLIBSRC = $(LIBSRC)/oldX
  218. X      XDMCPLIBSRC = $(LIBSRC)/Xdmcp
  219. X      BDFTOSNFSRC = $(FONTSRC)/bdftosnf
  220. X      BDFTOSNFSRC = $(FONTSRC)/clients/bdftosnf
  221. X      BDFTOPCFSRC = $(FONTSRC)/clients/bdftopcf
  222. X     MKFONTDIRSRC = $(FONTSRC)/clients/mkfontdir
  223. X         FSLIBSRC = $(FONTSRC)/lib/fs
  224. X    FONTSERVERSRC = $(FONTSRC)/server
  225. X     EXTENSIONSRC = $(TOP)/extensions
  226. X         XILIBSRC = $(EXTENSIONSRC)/lib/xinput
  227. X      PHIGSLIBSRC = $(EXTENSIONSRC)/lib/PEX
  228. X
  229. X# $XConsortium: sunLib.tmpl,v 1.14.1.1 92/03/17 14:58:46 rws Exp $
  230. X
  231. XSHLIBLDFLAGS = -assert pure-text
  232. XPICFLAGS = -pic
  233. X
  234. X  DEPEXTENSIONLIB =
  235. X     EXTENSIONLIB = -lXext
  236. X
  237. X          DEPXLIB = $(DEPEXTENSIONLIB)
  238. X             XLIB = $(EXTENSIONLIB) -lX11
  239. X
  240. X        DEPXMULIB = $(USRLIBDIR)/libXmu.sa.$(SOXMUREV)
  241. X       XMULIBONLY = -lXmu
  242. X           XMULIB = -lXmu
  243. X
  244. X       DEPOLDXLIB =
  245. X          OLDXLIB = -loldX
  246. X
  247. X      DEPXTOOLLIB = $(USRLIBDIR)/libXt.sa.$(SOXTREV)
  248. X         XTOOLLIB = -lXt
  249. X
  250. X        DEPXAWLIB = $(USRLIBDIR)/libXaw.sa.$(SOXAWREV)
  251. X           XAWLIB = -lXaw
  252. X
  253. X        DEPXILIB =
  254. X           XILIB = -lXi
  255. X
  256. X        SOXLIBREV = 4.10
  257. X          SOXTREV = 4.10
  258. X         SOXAWREV = 5.0
  259. X        SOOLDXREV = 4.10
  260. X         SOXMUREV = 4.10
  261. X        SOXEXTREV = 4.10
  262. X      SOXINPUTREV = 4.10
  263. X
  264. X      DEPXAUTHLIB = $(USRLIBDIR)/libXau.a
  265. X         XAUTHLIB =  -lXau
  266. X      DEPXDMCPLIB = $(USRLIBDIR)/libXdmcp.a
  267. X         XDMCPLIB =  -lXdmcp
  268. X
  269. X        DEPPHIGSLIB = $(USRLIBDIR)/libphigs.a
  270. X           PHIGSLIB =  -lphigs
  271. X
  272. X       DEPXBSDLIB = $(USRLIBDIR)/libXbsd.a
  273. X          XBSDLIB =  -lXbsd
  274. X
  275. X LINTEXTENSIONLIB = $(LINTLIBDIR)/llib-lXext.ln
  276. X         LINTXLIB = $(LINTLIBDIR)/llib-lX11.ln
  277. X          LINTXMU = $(LINTLIBDIR)/llib-lXmu.ln
  278. X        LINTXTOOL = $(LINTLIBDIR)/llib-lXt.ln
  279. X          LINTXAW = $(LINTLIBDIR)/llib-lXaw.ln
  280. X           LINTXI = $(LINTLIBDIR)/llib-lXi.ln
  281. X        LINTPHIGS = $(LINTLIBDIR)/llib-lphigs.ln
  282. X
  283. X          DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
  284. X
  285. X         DEPLIBS1 = $(DEPLIBS)
  286. X         DEPLIBS2 = $(DEPLIBS)
  287. X         DEPLIBS3 = $(DEPLIBS)
  288. X
  289. X# -------------------------------------------------------------------------
  290. X# Imake rules for building libraries, programs, scripts, and data files
  291. X# rules:  $XConsortium: Imake.rules,v 1.123 91/09/16 20:12:16 rws Exp $
  292. X
  293. X# -------------------------------------------------------------------------
  294. X# start of Imakefile
  295. X
  296. X#    Fig2dev : General Fig code translation program
  297. X#
  298. X# TransFig: Facility for Translating Fig code
  299. X# Copyright (c) 1985 Supoj Sutantavibul
  300. X# Copyright (c) 1991 Micah Beck
  301. X#
  302. X# Permission to use, copy, modify, distribute, and sell this software and its
  303. X# documentation for any purpose is hereby granted without fee, provided that
  304. X# the above copyright notice appear in all copies and that both that
  305. X# copyright notice and this permission notice appear in supporting
  306. X# documentation. The authors make no representations about the suitability
  307. X# of this software for any purpose.  It is provided "as is" without express
  308. X# or implied warranty.
  309. X#
  310. X# THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  311. X# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN 0
  312. X# EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  313. X# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  314. X# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  315. X# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  316. X# PERFORMANCE OF THIS SOFTWARE.
  317. X#
  318. X#
  319. X# to include drivers for the following languages,
  320. X# add the corresponding symbol to the DEFINES list:
  321. X#
  322. X# -DEPIC -DIBMGL -DLATEX -DPIC -DPICTEX -DPS -DPSTEX -DTEXTYL -DTPIC
  323. X#
  324. XDEFINES = -DEPIC -DIBMGL -DLATEX -DPIC -DPICTEX -DPS -DPSTEX -DTEXTYL -DTPIC
  325. XDEPLIBS =
  326. X
  327. XSUBDIRS = dev
  328. X
  329. XINCLUDES = -I..
  330. X
  331. XSRCS = fig2dev.c getopt.c psfonts.c iso2tex.c \
  332. X    arrow.c bound.c free.c read.c read1_3.c latex_line.c $(STRSTRC)
  333. XOBJS = fig2dev.o getopt.o psfonts.o iso2tex.o \
  334. X    arrow.o bound.o free.o read.o read1_3.o latex_line.o $(STRSTRO) \
  335. X    dev/libtransfig.a
  336. X
  337. XEXTRA_LIBRARIES = -lm
  338. X
  339. Xall::
  340. X    @case '${MFLAGS}' in *[ik]*) set +e;; esac; \
  341. X    for i in $(SUBDIRS) ;\
  342. X    do \
  343. X    (cd $$i ; echo "making" all "in $(CURRENT_DIR)/$$i..."; \
  344. X    $(MAKE) $(MFLAGS) 'CDEBUGFLAGS=$(CDEBUGFLAGS)' all); \
  345. X    done
  346. X
  347. Xdepend::
  348. X    @case '${MFLAGS}' in *[ik]*) set +e;; esac; \
  349. X    for i in $(SUBDIRS) ;\
  350. X    do \
  351. X    (cd $$i ; echo "depending" "in $(CURRENT_DIR)/$$i..."; \
  352. X    $(MAKE) $(MFLAGS)  depend); \
  353. X    done
  354. X
  355. X PROGRAM = fig2dev
  356. X
  357. Xall:: fig2dev
  358. X
  359. Xfig2dev: $(OBJS) $(DEPLIBS)
  360. X    $(RM) $@
  361. X    $(CC) -o $@ $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS)
  362. X
  363. Xsaber_fig2dev:: $(SRCS)
  364. X    # load $(ALLDEFINES) $(SRCS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  365. X
  366. Xosaber_fig2dev:: $(OBJS)
  367. X    # load $(ALLDEFINES) $(OBJS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  368. X
  369. Xinstall:: fig2dev
  370. X    @if [ -d $(DESTDIR)$(BINDIR) ]; then set +x; \
  371. X    else (set -x; $(MKDIRHIER) $(DESTDIR)$(BINDIR)); fi
  372. X    $(INSTALL) -c $(INSTPGMFLAGS)  fig2dev $(DESTDIR)$(BINDIR)
  373. X
  374. Xinstall.man:: fig2dev.man
  375. X    @if [ -d $(DESTDIR)$(MANDIR) ]; then set +x; \
  376. X    else (set -x; $(MKDIRHIER) $(DESTDIR)$(MANDIR)); fi
  377. X    $(INSTALL) -c $(INSTMANFLAGS) fig2dev.man $(DESTDIR)$(MANDIR)/fig2dev.$(MANSUFFIX)
  378. X
  379. Xdepend::
  380. X    $(DEPEND) $(DEPENDFLAGS) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS)
  381. X
  382. Xlint:
  383. X    $(LINT) $(LINTFLAGS) $(SRCS) $(LINTLIBS)
  384. Xlint1:
  385. X    $(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS)
  386. X
  387. Xclean::
  388. X    $(RM) $(PROGRAM)
  389. X
  390. Xinstall:: fig2ps2tex.script
  391. X    @if [ -d $(DESTDIR)$(BINDIR) ]; then set +x; \
  392. X    else (set -x; $(MKDIRHIER) $(DESTDIR)$(BINDIR)); fi
  393. X    $(INSTALL) -c $(INSTBINFLAGS) fig2ps2tex.script $(DESTDIR)$(BINDIR)/fig2ps2tex
  394. X
  395. Xinstall:: pic2tpic.script
  396. X    @if [ -d $(DESTDIR)$(BINDIR) ]; then set +x; \
  397. X    else (set -x; $(MKDIRHIER) $(DESTDIR)$(BINDIR)); fi
  398. X    $(INSTALL) -c $(INSTBINFLAGS) pic2tpic.script $(DESTDIR)$(BINDIR)/pic2tpic
  399. X
  400. Xinstall.man:: fig2ps2tex.man
  401. X    @if [ -d $(DESTDIR)$(MANDIR) ]; then set +x; \
  402. X    else (set -x; $(MKDIRHIER) $(DESTDIR)$(MANDIR)); fi
  403. X    $(INSTALL) -c $(INSTMANFLAGS) fig2ps2tex.man $(DESTDIR)$(MANDIR)/fig2ps2tex.$(MANSUFFIX)
  404. X
  405. Xinstall.man:: pic2tpic.man
  406. X    @if [ -d $(DESTDIR)$(MANDIR) ]; then set +x; \
  407. X    else (set -x; $(MKDIRHIER) $(DESTDIR)$(MANDIR)); fi
  408. X    $(INSTALL) -c $(INSTMANFLAGS) pic2tpic.man $(DESTDIR)$(MANDIR)/pic2tpic.$(MANSUFFIX)
  409. X
  410. Xfig2dev.man: ../doc/fig2dev.1
  411. X    ln -s ../doc/fig2dev.1 fig2dev.man
  412. X
  413. Xfig2ps2tex.man: ../doc/fig2ps2tex.1
  414. X    ln -s ../doc/fig2ps2tex.1 fig2ps2tex.man
  415. X
  416. Xpic2tpic.man: ../doc/pic2tpic.1
  417. X    ln -s ../doc/pic2tpic.1 pic2tpic.man
  418. X
  419. X# -------------------------------------------------------------------------
  420. X# common rules for all Makefiles - do not edit
  421. X
  422. Xemptyrule::
  423. X
  424. Xclean::
  425. X    $(RM_CMD) "#"*
  426. X
  427. XMakefile::
  428. X    -@if [ -f Makefile ]; then set -x; \
  429. X    $(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
  430. X    else exit 0; fi
  431. X    $(IMAKE_CMD) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
  432. X
  433. Xtags::
  434. X    $(TAGS) -w *.[ch]
  435. X    $(TAGS) -xw *.[ch] > TAGS
  436. X
  437. Xsaber:
  438. X    # load $(ALLDEFINES) $(SRCS)
  439. X
  440. Xosaber:
  441. X    # load $(ALLDEFINES) $(OBJS)
  442. X
  443. X# -------------------------------------------------------------------------
  444. X# rules for building in SUBDIRS - do not edit
  445. X
  446. Xinstall::
  447. X    @case '${MFLAGS}' in *[ik]*) set +e;; esac; \
  448. X    for i in $(SUBDIRS) ;\
  449. X    do \
  450. X    (cd $$i ; echo "installing" "in $(CURRENT_DIR)/$$i..."; \
  451. X    $(MAKE) $(MFLAGS) DESTDIR='$(DESTDIR)' install); \
  452. X    done
  453. X
  454. Xinstall.man::
  455. X    @case '${MFLAGS}' in *[ik]*) set +e;; esac; \
  456. X    for i in $(SUBDIRS) ;\
  457. X    do \
  458. X    (cd $$i ; echo "installing man pages" "in $(CURRENT_DIR)/$$i..."; \
  459. X    $(MAKE) $(MFLAGS) DESTDIR='$(DESTDIR)' install.man); \
  460. X    done
  461. X
  462. Xclean::
  463. X    @case '${MFLAGS}' in *[ik]*) set +e;; esac; \
  464. X    for i in $(SUBDIRS) ;\
  465. X    do \
  466. X    (cd $$i ; echo "cleaning" "in $(CURRENT_DIR)/$$i..."; \
  467. X    $(MAKE) $(MFLAGS) RM_CMD='$(RM_CMD)' clean); \
  468. X    done
  469. X
  470. Xtags::
  471. X    @case '${MFLAGS}' in *[ik]*) set +e;; esac; \
  472. X    for i in $(SUBDIRS) ;\
  473. X    do \
  474. X    (cd $$i ; echo "tagging" "in $(CURRENT_DIR)/$$i..."; \
  475. X    $(MAKE) $(MFLAGS) TAGS='$(TAGS)' tags); \
  476. X    done
  477. X
  478. XMakefiles::
  479. X    @case '${MFLAGS}' in *[ik]*) set +e;; esac; \
  480. X    for i in $(SUBDIRS) ;\
  481. X    do \
  482. X    echo "making Makefiles in $(CURRENT_DIR)/$$i..."; \
  483. X    case "$$i" in \
  484. X    ./?*/?*/?*/?*) newtop=../../../../ sub=subsubsubsub;; \
  485. X    ./?*/?*/?*) newtop=../../../ sub=subsubsub;; \
  486. X    ./?*/?*) newtop=../../ sub=subsub;; \
  487. X    ./?*) newtop=../ sub=sub;; \
  488. X    */?*/?*/?*) newtop=../../../../ sub=subsubsubsub;; \
  489. X    */?*/?*) newtop=../../../ sub=subsubsub;; \
  490. X    */?*) newtop=../../ sub=subsub;; \
  491. X    *) newtop=../ sub=sub;; \
  492. X    esac; \
  493. X    case "$(TOP)" in \
  494. X    /?*) newtop= upprefix= ;; \
  495. X    *) upprefix=../ ;; \
  496. X    esac; \
  497. X    $(MAKE) $${sub}dirMakefiles UPPREFIX=$$upprefix NEWTOP=$$newtop \
  498. X    MAKEFILE_SUBDIR=$$i NEW_CURRENT_DIR=$(CURRENT_DIR)/$$i;\
  499. X    done
  500. X
  501. XsubdirMakefiles:
  502. X    $(RM) $(MAKEFILE_SUBDIR)/Makefile.bak
  503. X    -@if [ -f $(MAKEFILE_SUBDIR)/Makefile ]; then set -x; \
  504. X    $(MV) $(MAKEFILE_SUBDIR)/Makefile $(MAKEFILE_SUBDIR)/Makefile.bak; \
  505. X    else exit 0; fi
  506. X    cd $(MAKEFILE_SUBDIR); $(IMAKE_CMD) -DTOPDIR=$(UPPREFIX)$(TOP) -DCURDIR=$(NEW_CURRENT_DIR); \
  507. X    $(MAKE) $(MFLAGS) Makefiles
  508. X
  509. XsubsubdirMakefiles:
  510. X    $(RM) $(MAKEFILE_SUBDIR)/Makefile.bak
  511. X    -@if [ -f $(MAKEFILE_SUBDIR)/Makefile ]; then set -x; \
  512. X    $(MV) $(MAKEFILE_SUBDIR)/Makefile $(MAKEFILE_SUBDIR)/Makefile.bak; \
  513. X    else exit 0; fi
  514. X    cd $(MAKEFILE_SUBDIR); $(IMAKE_CMD) -DTOPDIR=$(UPPREFIX)$(UPPREFIX)$(TOP) -DCURDIR=$(NEW_CURRENT_DIR); \
  515. X    $(MAKE) $(MFLAGS) Makefiles
  516. X
  517. XsubsubsubdirMakefiles:
  518. X    $(RM) $(MAKEFILE_SUBDIR)/Makefile.bak
  519. X    -@if [ -f $(MAKEFILE_SUBDIR)/Makefile ]; then set -x; \
  520. X    $(MV) $(MAKEFILE_SUBDIR)/Makefile $(MAKEFILE_SUBDIR)/Makefile.bak; \
  521. X    else exit 0; fi
  522. X    cd $(MAKEFILE_SUBDIR); $(IMAKE_CMD) -DTOPDIR=$(UPPREFIX)$(UPPREFIX)$(UPPREFIX)$(TOP) -DCURDIR=$(NEW_CURRENT_DIR); \
  523. X    $(MAKE) $(MFLAGS) Makefiles
  524. X
  525. XsubsubsubsubdirMakefiles:
  526. X    $(RM) $(MAKEFILE_SUBDIR)/Makefile.bak
  527. X    -@if [ -f $(MAKEFILE_SUBDIR)/Makefile ]; then set -x; \
  528. X    $(MV) $(MAKEFILE_SUBDIR)/Makefile $(MAKEFILE_SUBDIR)/Makefile.bak; \
  529. X    else exit 0; fi
  530. X    cd $(MAKEFILE_SUBDIR); $(IMAKE_CMD) -DTOPDIR=$(UPPREFIX)$(UPPREFIX)$(UPPREFIX)$(UPPREFIX)$(TOP) -DCURDIR=$(NEW_CURRENT_DIR); \
  531. X    $(MAKE) $(MFLAGS) Makefiles
  532. X
  533. Xincludes::
  534. X    @case '${MFLAGS}' in *[ik]*) set +e;; esac; \
  535. X    for i in $(SUBDIRS) ;\
  536. X    do \
  537. X    (cd $$i ; echo including "in $(CURRENT_DIR)/$$i..."; \
  538. X    $(MAKE) $(MFLAGS)  includes); \
  539. X    done
  540. X
  541. X# -------------------------------------------------------------------------
  542. X# dependencies generated by makedepend
  543. X
  544. END_OF_FILE
  545. if test 16232 -ne `wc -c <'fig2dev/Makefile'`; then
  546.     echo shar: \"'fig2dev/Makefile'\" unpacked with wrong size!
  547. fi
  548. # end of 'fig2dev/Makefile'
  549. fi
  550. if test -f 'fig2dev/dev/genpic.c' -a "${1}" != "-c" ; then 
  551.   echo shar: Will not clobber existing file \"'fig2dev/dev/genpic.c'\"
  552. else
  553. echo shar: Extracting \"'fig2dev/dev/genpic.c'\" \(16429 characters\)
  554. sed "s/^X//" >'fig2dev/dev/genpic.c' <<'END_OF_FILE'
  555. X/*
  556. X * TransFig: Facility for Translating Fig code
  557. X * Copyright (c) 1985 Supoj Sutantavibul
  558. X * Copyright (c) 1991 Micah Beck
  559. X *
  560. X * Permission to use, copy, modify, distribute, and sell this software and its
  561. X * documentation for any purpose is hereby granted without fee, provided that
  562. X * the above copyright notice appear in all copies and that both that
  563. X * copyright notice and this permission notice appear in supporting
  564. X * documentation. The authors make no representations about the suitability 
  565. X * of this software for any purpose.  It is provided "as is" without express 
  566. X * or implied warranty.
  567. X *
  568. X * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  569. X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  570. X * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  571. X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  572. X * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  573. X * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  574. X * PERFORMANCE OF THIS SOFTWARE.
  575. X *
  576. X */
  577. X
  578. X/* 
  579. X *    genpic : PIC driver for fig2dev
  580. X *
  581. X *    Author: Conrad Kwok, UC Davis, 12/88
  582. X *      Modified: Richard Auletta, George Mason Univ., 6/21/89
  583. X *    Added code comments are marked with "rja".
  584. X *      Added: Support for native pic arrowheads.
  585. X *      Added: Support for arrowheads at both ends of lines, arc, splines.
  586. X *
  587. X *      Modified: Stuart Kemp & Dave Bonnell, July, 1991
  588. X *          James Cook University,
  589. X *          Australia
  590. X *      Changes:
  591. X *        Added T_ARC_BOX to genpic_line()
  592. X *        Added 'thickness' attribute all over
  593. X *        Added 'fill' attribute to ellipse
  594. X *        Cleaned up the code
  595. X */
  596. X
  597. X#include <stdio.h>
  598. X#include <math.h>
  599. X#include "object.h"
  600. X#include "fig2dev.h"
  601. X#include "picfonts.h"
  602. X#include "picpsfonts.h"
  603. X
  604. Xvoid genpic_ctl_spline(), genpic_itp_spline();
  605. Xvoid genpic_open_spline(), genpic_closed_spline();
  606. X
  607. X#define            TOP    10.5    /* top of page is 10.5 inch */
  608. Xstatic double        ppi;
  609. Xstatic int        CONV = 0;
  610. Xstatic int LineThickness = 0;
  611. Xstatic int OptArcBox = 0;        /* Conditional use */
  612. Xstatic int OptLineThick = 0;
  613. Xstatic int OptEllipseFill = 0;
  614. Xstatic int OptNoUnps = 0;    /* prohibit unpsfont() */
  615. X
  616. Xvoid
  617. Xgenpic_option(opt, optarg)
  618. Xchar opt, *optarg;
  619. X{
  620. X    switch (opt) {
  621. X
  622. X    case 'f':        /* set default text font */
  623. X            {   int i;
  624. X
  625. X            for ( i = 1; i <= MAX_FONT; i++ )
  626. X            if ( !strcmp(optarg, picfontnames[i]) ) break;
  627. X
  628. X            if ( i > MAX_FONT)
  629. X            fprintf(stderr,
  630. X            "warning: non-standard font name %s\n", optarg);
  631. X        }
  632. X        
  633. X        picfontnames[0] = picfontnames[1] = optarg;
  634. X        break;
  635. X
  636. X    case 's':
  637. X        if (font_size <= 0 || font_size > MAXFONTSIZE) {
  638. X            fprintf(stderr,
  639. X                "warning: font size %d out of bounds\n", font_size);
  640. X        }
  641. X        break;
  642. X
  643. X    case 'm':
  644. X    case 'L':
  645. X        break;
  646. X
  647. X    case 'p':
  648. X        if (strcmp(optarg, "all") == 0)
  649. X          OptArcBox = OptLineThick = OptEllipseFill = 1;
  650. X        else
  651. X          if (strcmp(optarg, "arc") == 0)
  652. X            OptArcBox = 1;
  653. X          else
  654. X            if (strcmp(optarg, "line") == 0)
  655. X              OptLineThick = 1;
  656. X            else
  657. X              if (strcmp(optarg, "fill") == 0)
  658. X            OptEllipseFill = 1;
  659. X              else
  660. X            if (strcmp(optarg, "psfont") == 0)
  661. X              OptNoUnps = 1;
  662. X            else
  663. X              if (strcmp(optarg, "allps") == 0)
  664. X                OptArcBox =
  665. X                  OptLineThick =
  666. X                OptEllipseFill =
  667. X                  OptNoUnps = 1;
  668. X              else
  669. X                { fprintf(stderr, "Invalid option: %s\n", optarg);
  670. X                  exit(1);
  671. X                }
  672. X        break;
  673. X          default:
  674. X        put_msg(Err_badarg, opt, "pic");
  675. X        exit(1);
  676. X    }
  677. X}
  678. X
  679. Xstatic
  680. Xdouble convy(a)
  681. Xdouble    a;
  682. X{
  683. X    return((double)(CONV ? TOP-a : a));
  684. X}
  685. X
  686. Xvoid
  687. Xgenpic_start(objects)
  688. XF_compound    *objects;
  689. X{
  690. X    int        coord_system;
  691. X
  692. X    ppi = objects->nwcorner.x/mag;
  693. X    coord_system = objects->nwcorner.y;
  694. X    if (coord_system == 2) CONV = 1;
  695. X
  696. X    fprintf(tfp, ".PS\n.ps %d\n", font_size);    /* PIC preamble */
  697. X}
  698. X
  699. Xvoid
  700. Xgenpic_end()
  701. X{
  702. X      fprintf(tfp, ".PE\n");                /* PIC ending */
  703. X}
  704. X
  705. X/*
  706. XThe line thickness is, unfortunately, multiple of pixel.
  707. XOne pixel thickness is a little too thick on the hard copy
  708. Xso I scale it with 0.7; i.e., it's a kludge.  The best way is
  709. Xto allow thickness in fraction of pixel.
  710. X
  711. XNote that the current version of psdit (a ditroff to postcript filter)
  712. Xwon't take the legitimate line thickness command.
  713. X*/
  714. Xstatic
  715. Xset_linewidth(w)
  716. Xint    w;
  717. X{
  718. X    static int    cur_thickness = -1;
  719. X
  720. X    LineThickness = w;
  721. X
  722. X    /*
  723. X    if (w == 0) return;
  724. X    if (w != cur_thickness) {
  725. X        cur_thickness = w;
  726. X        fprintf(tfp, "\"\\D't %.5fi'\"\n", 0.7 * cur_thickness / ppi);
  727. X        }
  728. X    */
  729. X}
  730. X
  731. Xstatic void
  732. XAddThickness()
  733. X{
  734. X  if (OptLineThick && LineThickness)
  735. X    fprintf(tfp, " thickness %d", LineThickness);
  736. X}
  737. X
  738. Xstatic void
  739. Xset_style(s, v)
  740. Xint    s;
  741. Xfloat    v;
  742. X{
  743. X    static float    style_val = -1;
  744. X
  745. X    if (s == DASH_LINE || s == DOTTED_LINE) {
  746. X        if (v == style_val) return;
  747. X        if (v == 0.0) return;
  748. X        style_val = v;
  749. X        fprintf(tfp, "dashwid = %.3fi\n", style_val/ppi);
  750. X        }
  751. X}
  752. X
  753. X/*
  754. X * Makes use of the PIC 'box' command
  755. X *
  756. X * Returns 0 if command failed, else non-zero.
  757. X *
  758. X */
  759. X
  760. Xstatic int
  761. Xgenpic_box(l)
  762. XF_line *l;
  763. X{
  764. X  int count, minx, miny, maxx, maxy;
  765. X  int Valid;        /* Valid box */
  766. X  double width, height;
  767. X  F_point *p, *q;
  768. X    
  769. X  p = l->points;
  770. X  q = p->next;
  771. X  count = 1;        /* Just a sanity check */
  772. X  minx = maxx = p->x;
  773. X  miny = maxy = p->y;
  774. X
  775. X  /* Find the boundaries */
  776. X  while (q != NULL)
  777. X  { count++;
  778. X    if (q->x < minx) minx = q->x;
  779. X    else
  780. X      if (q->x > maxx) maxx = q->x;
  781. X
  782. X    if (q->y < miny) miny = q->y;
  783. X    else
  784. X      if (q->y > maxy) maxy = q->y;
  785. X
  786. X    q = q->next;
  787. X  }
  788. X
  789. X  if (Valid = (count == 5))        /* Valid box? */
  790. X  { fprintf(tfp, "box");
  791. X    if (l->thickness == 0)
  792. X      fprintf(tfp, " invis");
  793. X    else
  794. X      if (l->style_val > 0.0)
  795. X      { if (l->style == DASH_LINE)
  796. X      fprintf(tfp, " dashed");
  797. X    else if (l->style == DOTTED_LINE)
  798. X      fprintf(tfp, " dotted");
  799. X      }
  800. X
  801. X    /* Should have a #define somewhere for the # of fill patterns */
  802. X    if (l->area_fill > 0)
  803. X      fprintf(tfp, " fill %.2f", ((double) (l->area_fill - 1)) / 20);
  804. X
  805. X    fprintf(tfp, " with .sw at (%.2f,%.2f) ",
  806. X        minx / ppi, convy(maxy / ppi));
  807. X
  808. X    width = (maxx - minx) / ppi;
  809. X    if (width < 0.0) width = -width;
  810. X    height = convy(maxy / ppi) - convy(miny / ppi);
  811. X    if (height < 0.0) height = -height;
  812. X
  813. X    fprintf(tfp, "width %.2f height %.2f", width, height);
  814. X
  815. X    if (OptArcBox && l->type == T_ARC_BOX)
  816. X      fprintf(tfp, " rad %.2f", l->radius/ppi);
  817. X
  818. X    AddThickness();
  819. X
  820. X    fprintf(tfp, "\n");
  821. X  }
  822. X
  823. X  return(Valid);
  824. X}
  825. X
  826. Xvoid
  827. Xgenpic_line(l)
  828. XF_line    *l;
  829. X{
  830. X    F_point        *p, *q;
  831. X
  832. X    if (l->type == T_ARC_BOX && !OptArcBox)
  833. X    { fprintf(stderr, "Arc box not implemented; substituting box.\n");
  834. X      l->type = T_BOX;
  835. X    }
  836. X
  837. X    set_linewidth(l->thickness);
  838. X    set_style(l->style, l->style_val);
  839. X    p = l->points;
  840. X    q = p->next;
  841. X    if (q == NULL)    /* A single point line */
  842. X    {   fprintf(tfp, "line from %.3f,%.3f to %.3f,%.3f",
  843. X            p->x/ppi, convy(p->y/ppi), p->x/ppi, convy(p->y/ppi));
  844. X        AddThickness();
  845. X        fprintf(tfp, "\n");
  846. X        return;
  847. X    }
  848. X
  849. X    if (l->type == T_BOX || l->type == T_ARC_BOX)
  850. X    { if (genpic_box(l)) return;
  851. X      fprintf(stderr, "Invalid T_BOX or T_ARC_BOX in fig file\n");
  852. X          fprintf(stderr, "  Using 'line' instead\n");
  853. X    }
  854. X
  855. X    fprintf(tfp, "line");
  856. X
  857. X    if (l->style_val > 0.0)
  858. X    { if (l->style == DASH_LINE)
  859. X        fprintf(tfp, " dashed");
  860. X      else
  861. X        if (l->style == DOTTED_LINE)
  862. X          fprintf(tfp, " dotted");
  863. X    }
  864. X
  865. X    /*rja: Place arrowheads or lack there of on the line*/
  866. X    if ((l->for_arrow) && (l->back_arrow))
  867. X        fprintf(tfp, " <->");
  868. X    else if (l->back_arrow)
  869. X        fprintf(tfp, " <-");
  870. X    else if (l->for_arrow)
  871. X        fprintf(tfp, " ->");
  872. X
  873. X    fprintf(tfp, " from %.3f,%.3f", p->x/ppi, convy(p->y/ppi));
  874. X    do
  875. X    { fprintf(tfp, " to %.3f,%.3f", q->x/ppi, convy(q->y/ppi));
  876. X      q = q->next;
  877. X    } while (q != NULL);
  878. X
  879. X    AddThickness();
  880. X
  881. X    fprintf(tfp, "\n");
  882. X}
  883. X
  884. Xvoid
  885. Xgenpic_spline(s)
  886. XF_spline    *s;
  887. X{
  888. X    if (int_spline(s))
  889. X        genpic_itp_spline(s);
  890. X    else
  891. X        genpic_ctl_spline(s);
  892. X    }
  893. X
  894. Xvoid
  895. Xgenpic_ctl_spline(s)
  896. XF_spline    *s;
  897. X{
  898. X    if (closed_spline(s))
  899. X        genpic_closed_spline(s);
  900. X    else
  901. X        genpic_open_spline(s);
  902. X    }
  903. X
  904. Xvoid
  905. Xgenpic_open_spline(s)
  906. XF_spline    *s;
  907. X{
  908. X    double        x1, y1, x2, y2;
  909. X    F_point        *p, *q;
  910. X
  911. X    p = s->points;
  912. X    x1 = p->x/ppi; y1 = convy(p->y/ppi);
  913. X    p = p->next;
  914. X    x2 = p->x/ppi; y2 = convy(p->y/ppi);
  915. X
  916. X
  917. X    /* Pic's spline supports only solid line style */
  918. X    /* set_linewidth(s->thickness); */
  919. X
  920. X    if (p->next == NULL) {
  921. X        fprintf(tfp, "line");
  922. X
  923. X           /*rja: Attach arrowhead as required */
  924. X        if ((s->for_arrow) && (s->back_arrow))
  925. X           fprintf(tfp, " <->");
  926. X        else if (s->back_arrow)
  927. X           fprintf(tfp, " <-");
  928. X        else if (s->for_arrow)
  929. X           fprintf(tfp, " ->");
  930. X
  931. X        fprintf(tfp, " from %.3f,%.3f to %.3f,%.3f", x1, y1, x2, y2);
  932. X
  933. X        AddThickness();
  934. X
  935. X        fprintf(tfp, "\n");
  936. X
  937. X        return;
  938. X        }
  939. X
  940. X    fprintf(tfp, "spline"); 
  941. X
  942. X           /*rja: Attach arrowhead as required */
  943. X        if ((s->for_arrow) && (s->back_arrow))
  944. X           fprintf(tfp, " <->");
  945. X        else if (s->back_arrow)
  946. X           fprintf(tfp, " <-");
  947. X        else if (s->for_arrow)
  948. X           fprintf(tfp, " ->");
  949. X
  950. X    fprintf(tfp, " from %.3f,%.3f to %.3f,%.3f", x1, y1, x2, y2);
  951. X
  952. X    for (q = p->next; q->next != NULL; p = q, q = q->next)
  953. X        fprintf(tfp, " to %.3f,%.3f", q->x/ppi, convy(q->y/ppi));
  954. X    fprintf(tfp, " to %.3f,%.3f", q->x/ppi, convy(q->y/ppi));
  955. X
  956. X    AddThickness();
  957. X
  958. X    fprintf(tfp, "\n");
  959. X}
  960. X
  961. Xvoid
  962. Xgenpic_ellipse(e)
  963. XF_ellipse    *e;
  964. X{
  965. X    set_linewidth(e->thickness);
  966. X    if (e->type == 3 || e->type == 4)
  967. X      fprintf(tfp, "circle at %.3f,%.3f rad %.3f",
  968. X        e->center.x/ppi, convy(e->center.y/ppi),
  969. X        e->radiuses.x/ppi);
  970. X    else
  971. X      fprintf(tfp, "ellipse at %.3f,%.3f wid %.3f ht %.3f",
  972. X        e->center.x/ppi, convy(e->center.y/ppi),
  973. X        2 * e->radiuses.x/ppi, 2 * e->radiuses.y/ppi);
  974. X
  975. X    if ( OptEllipseFill && e->area_fill > 0)
  976. X      fprintf(tfp, " fill %.2f", ((double)(e->area_fill - 1)) / 20);
  977. X
  978. X    AddThickness();
  979. X
  980. X    fprintf(tfp, "\n");
  981. X}
  982. X
  983. X/*
  984. XText is display on the screen with the base line starting at
  985. X(base_x, base_y); some characters extend below this line.
  986. XPic displays the center of the height of text at the given
  987. Xcoordinate. HT_OFFSET is use to compensate all the above factors
  988. Xso text position in fig 1.4 should be at the same position on
  989. Xthe screen as on the hard copy.
  990. X*/
  991. X#define            HT_OFFSET    (0.2 / 72.0)
  992. X
  993. Xvoid
  994. Xgenpic_text(t)
  995. XF_text    *t;
  996. X{
  997. X    float    y;
  998. X        char *tpos;
  999. X
  1000. X    if (!OptNoUnps) {
  1001. X      unpsfont(t);
  1002. X      fprintf(tfp, "\"\\s%d\\f%s", PICFONTMAG(t) ,
  1003. X          PICFONT(t->font) );
  1004. X    } else {
  1005. X      fprintf(tfp, ".ps\n.ps %d\n", PICFONTMAG(t) );
  1006. X      fprintf(tfp, ".ft\n.ft %s\n", PICPSFONT(t) );
  1007. X    }
  1008. X
  1009. X        switch (t->type) {
  1010. X        case T_LEFT_JUSTIFIED:
  1011. X        case DEFAULT:
  1012. X            tpos = "ljust";
  1013. X            break;
  1014. X        case T_CENTER_JUSTIFIED:
  1015. X            tpos = "";
  1016. X            break;
  1017. X        case T_RIGHT_JUSTIFIED:
  1018. X            tpos = "rjust";
  1019. X            break;
  1020. X        default:
  1021. X            fprintf(stderr, "unknown text position type\n");
  1022. X            exit(1);
  1023. X        }    
  1024. X     y = convy(t->base_y/ppi) +
  1025. X         PICFONTMAG(t) *
  1026. X             HT_OFFSET;
  1027. X     if (!OptNoUnps)
  1028. X         fprintf(tfp, "%s\\fP\" at %.3f,%.3f %s\n",
  1029. X             t->cstring, t->base_x/ppi, y, tpos);
  1030. X     else
  1031. X         fprintf(tfp, "\"%s\" at %.3f,%.3f %s\n.ft \n.ps \n",
  1032. X            t->cstring, t->base_x/ppi, y, tpos);
  1033. X    }
  1034. X
  1035. Xvoid
  1036. Xgenpic_arc(a)
  1037. XF_arc    *a;
  1038. X{
  1039. X    double        x, y;
  1040. X    double        cx, cy, sx, sy, ex, ey;
  1041. X
  1042. X    cx = a->center.x/ppi; cy = convy(a->center.y/ppi);
  1043. X    sx = a->point[0].x/ppi; sy = convy(a->point[0].y/ppi);
  1044. X    ex = a->point[2].x/ppi; ey = convy(a->point[2].y/ppi);
  1045. X
  1046. X    set_linewidth(a->thickness);
  1047. X
  1048. X    fprintf(tfp, "arc ");
  1049. X
  1050. X    /*rja: Attach arrowhead as required */
  1051. X    if ((a->for_arrow) && (a->back_arrow))
  1052. X      fprintf(tfp, " <->");
  1053. X    else if (a->back_arrow)
  1054. X      fprintf(tfp, " <-");
  1055. X    else if (a->for_arrow)
  1056. X      fprintf(tfp, " ->");
  1057. X
  1058. X
  1059. X    fprintf(tfp, " at %.3f,%.3f from %.3f,%.3f to %.3f,%.3f",
  1060. X        cx, cy, sx, sy, ex, ey);
  1061. X
  1062. X    if (!a->direction)
  1063. X      fprintf(tfp, " cw");
  1064. X
  1065. X    if (a->area_fill > 0.0)
  1066. X      fprintf(stderr, "PIC does not support filled arcs ... ignoring 'fill' directive\n");
  1067. X
  1068. X    AddThickness();
  1069. X    fprintf(tfp, "\n");
  1070. X}
  1071. X
  1072. Xvoid
  1073. Xarc_tangent(x1, y1, x2, y2, direction, x, y)
  1074. Xdouble    x1, y1, x2, y2, *x, *y;
  1075. Xint    direction;
  1076. X{
  1077. X    if (direction)    /* counter clockwise  */
  1078. X    {   *x = x2 + (y2 - y1);
  1079. X        *y = y2 - (x2 - x1);
  1080. X    }
  1081. X    else
  1082. X    {   *x = x2 - (y2 - y1);
  1083. X        *y = y2 + (x2 - x1);
  1084. X    }
  1085. X}
  1086. X
  1087. X/*    draw arrow heading from (x1, y1) to (x2, y2)    */
  1088. X
  1089. Xdraw_arrow_head(x1, y1, x2, y2, arrowht, arrowwid)
  1090. Xdouble    x1, y1, x2, y2, arrowht, arrowwid;
  1091. X{
  1092. X    double    x, y, xb, yb, dx, dy, l, sina, cosa;
  1093. X    double    xc, yc, xd, yd;
  1094. X
  1095. X    dx = x2 - x1;  dy = y1 - y2;
  1096. X    l = sqrt((dx*dx + dy*dy));
  1097. X    if (l == 0) {
  1098. X         return;
  1099. X    }
  1100. X    else {
  1101. X         sina = dy / l;  cosa = dx / l;
  1102. X    }
  1103. X    xb = x2*cosa - y2*sina;
  1104. X    yb = x2*sina + y2*cosa;
  1105. X    x = xb - arrowht;
  1106. X    y = yb - arrowwid / 2;
  1107. X    xc = x*cosa + y*sina;
  1108. X    yc = -x*sina + y*cosa;
  1109. X    y = yb + arrowwid / 2;
  1110. X    xd = x*cosa + y*sina;
  1111. X    yd = -x*sina + y*cosa;
  1112. X    fprintf(tfp, "line from %.3f,%.3f to %.3f,%.3f to %.3f,%.3f\n",
  1113. X        xc, yc, x2, y2, xd, yd);
  1114. X    }
  1115. X
  1116. X#define        THRESHOLD    .05    /* inch */
  1117. X
  1118. Xquadratic_spline(a1, b1, a2, b2, a3, b3, a4, b4)
  1119. Xdouble    a1, b1, a2, b2, a3, b3, a4, b4;
  1120. X{
  1121. X    double    x1, y1, x4, y4;
  1122. X    double    xmid, ymid;
  1123. X
  1124. X    x1 = a1; y1 = b1;
  1125. X    x4 = a4; y4 = b4;
  1126. X
  1127. X    xmid = (a2 + a3) / 2;
  1128. X    ymid = (b2 + b3) / 2;
  1129. X    if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD)
  1130. X    { fprintf(tfp, " to %.3f,%.3f", xmid, ymid);
  1131. X    }
  1132. X    else {
  1133. X        quadratic_spline(x1, y1, ((x1+a2)/2), ((y1+b2)/2),
  1134. X            ((3*a2+a3)/4), ((3*b2+b3)/4), xmid, ymid);
  1135. X        }
  1136. X
  1137. X    if (fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD)
  1138. X    { fprintf(tfp, " to %.3f,%.3f", x4, y4);
  1139. X    }
  1140. X    else {
  1141. X        quadratic_spline(xmid, ymid, ((a2+3*a3)/4), ((b2+3*b3)/4),
  1142. X            ((a3+x4)/2), ((b3+y4)/2), x4, y4);
  1143. X        }
  1144. X    }
  1145. X
  1146. Xvoid
  1147. Xgenpic_closed_spline(s)
  1148. XF_spline    *s;
  1149. X{
  1150. X    F_point    *p;
  1151. X    double    cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4;
  1152. X    double    x1, y1, x2, y2;
  1153. X
  1154. X    p = s->points;
  1155. X    x1 = p->x/ppi;  y1 = convy(p->y/ppi);
  1156. X    p = p->next;
  1157. X    x2 = p->x/ppi;  y2 = convy(p->y/ppi);
  1158. X    cx1 = (x1 + x2) / 2;      cy1 = (y1 + y2) / 2;
  1159. X    cx2 = (x1 + 3 * x2) / 4;  cy2 = (y1 + 3 * y2) / 4;
  1160. X
  1161. X    for (p = p->next; p != NULL; p = p->next) {
  1162. X        fprintf(tfp, "line from %.3f,%.3f ", cx1, cy1);
  1163. X        x1 = x2;  y1 = y2;
  1164. X        x2 = p->x/ppi;  y2 = convy(p->y/ppi);
  1165. X        cx3 = (3 * x1 + x2) / 4;  cy3 = (3 * y1 + y2) / 4;
  1166. X        cx4 = (x1 + x2) / 2;      cy4 = (y1 + y2) / 2;
  1167. X        quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
  1168. X        AddThickness();
  1169. X        fprintf(tfp, "\n");
  1170. X        cx1 = cx4;  cy1 = cy4;
  1171. X        cx2 = (x1 + 3 * x2) / 4;  cy2 = (y1 + 3 * y2) / 4;
  1172. X        }
  1173. X    x1 = x2;  y1 = y2;
  1174. X    p = s->points->next;
  1175. X    x2 = p->x/ppi;  y2 = convy(p->y/ppi);
  1176. X    cx3 = (3 * x1 + x2) / 4;  cy3 = (3 * y1 + y2) / 4;
  1177. X    cx4 = (x1 + x2) / 2;      cy4 = (y1 + y2) / 2;
  1178. X    fprintf(tfp, "line from %.3f,%.3f ", cx1, cy1);
  1179. X    quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
  1180. X    AddThickness();
  1181. X    fprintf(tfp, "\n");
  1182. X}
  1183. X
  1184. Xvoid
  1185. Xgenpic_itp_spline(s)
  1186. XF_spline    *s;
  1187. X{
  1188. X    F_point        *p1, *p2, *pfirst;
  1189. X    F_control    *cp1, *cp2;
  1190. X    double        x1, x2, y1, y2;
  1191. X
  1192. X    p1 = s->points;
  1193. X    cp1 = s->controls;
  1194. X    cp2 = cp1->next;
  1195. X    x2 = p1->x/ppi; y2 = convy(p1->y/ppi);
  1196. X
  1197. X         pfirst = p1->next;/*save first to test in loop*/
  1198. X    for (p2 = p1->next, cp2 = cp1->next; p2 != NULL;
  1199. X        p1 = p2, cp1 = cp2, p2 = p2->next, cp2 = cp2->next) {
  1200. X
  1201. X        fprintf(tfp, "line ");
  1202. X
  1203. X           /*rja: Attach arrowhead as required */
  1204. X
  1205. X        if ((s->back_arrow) && (p2 == pfirst))
  1206. X           fprintf(tfp, " <- ");
  1207. X        else if ((s->for_arrow) && (p2->next == NULL))
  1208. X           fprintf(tfp, " -> ");
  1209. X
  1210. X        fprintf(tfp, " from %.3f,%.3f", x2, y2);
  1211. X
  1212. X        x1 = x2; y1 = y2;
  1213. X        x2 = p2->x/ppi; y2 = convy(p2->y/ppi);
  1214. X        bezier_spline(x1, y1, (double)cp1->rx/ppi, convy(cp1->ry/ppi),
  1215. X        (double)cp2->lx/ppi, convy(cp2->ly/ppi), x2, y2);
  1216. X        AddThickness();
  1217. X        fprintf(tfp, "\n");
  1218. X        }
  1219. X
  1220. X    }
  1221. X
  1222. Xbezier_spline(a0, b0, a1, b1, a2, b2, a3, b3)
  1223. Xdouble    a0, b0, a1, b1, a2, b2, a3, b3;
  1224. X{
  1225. X    double    x0, y0, x3, y3;
  1226. X    double    sx1, sy1, sx2, sy2, tx, ty, tx1, ty1, tx2, ty2, xmid, ymid;
  1227. X
  1228. X    x0 = a0; y0 = b0;
  1229. X    x3 = a3; y3 = b3;
  1230. X    if (fabs(x0 - x3) < THRESHOLD && fabs(y0 - y3) < THRESHOLD)
  1231. X    { fprintf(tfp, " to %.3f,%.3f", x3, y3);
  1232. X    }
  1233. X    else {
  1234. X        tx = (a1 + a2) / 2;        ty = (b1 + b2) / 2;
  1235. X        sx1 = (x0 + a1) / 2;    sy1 = (y0 + b1) / 2;
  1236. X        sx2 = (sx1 + tx) / 2;    sy2 = (sy1 + ty) / 2;
  1237. X        tx2 = (a2 + x3) / 2;    ty2 = (b2 + y3) / 2;
  1238. X        tx1 = (tx2 + tx) / 2;    ty1 = (ty2 + ty) / 2;
  1239. X        xmid = (sx2 + tx1) / 2;    ymid = (sy2 + ty1) / 2;
  1240. X
  1241. X        bezier_spline(x0, y0, sx1, sy1, sx2, sy2, xmid, ymid);
  1242. X        bezier_spline(xmid, ymid, tx1, ty1, tx2, ty2, x3, y3);
  1243. X        }
  1244. X    }
  1245. X
  1246. Xstruct driver dev_pic = {
  1247. X         genpic_option,
  1248. X    genpic_start,
  1249. X    genpic_arc,
  1250. X    genpic_ellipse,
  1251. X    genpic_line,
  1252. X    genpic_spline,
  1253. X    genpic_text,
  1254. X    genpic_end,
  1255. X    INCLUDE_TEXT
  1256. X};
  1257. END_OF_FILE
  1258. if test 16429 -ne `wc -c <'fig2dev/dev/genpic.c'`; then
  1259.     echo shar: \"'fig2dev/dev/genpic.c'\" unpacked with wrong size!
  1260. fi
  1261. # end of 'fig2dev/dev/genpic.c'
  1262. fi
  1263. if test -f 'fig2dev/dev/gentextyl.c' -a "${1}" != "-c" ; then 
  1264.   echo shar: Will not clobber existing file \"'fig2dev/dev/gentextyl.c'\"
  1265. else
  1266. echo shar: Extracting \"'fig2dev/dev/gentextyl.c'\" \(14413 characters\)
  1267. sed "s/^X//" >'fig2dev/dev/gentextyl.c' <<'END_OF_FILE'
  1268. X/*
  1269. X * TransFig: Facility for Translating Fig code
  1270. X * Copyright (c) 1985 Supoj Sutantavibul
  1271. X * Copyright (c) 1991 Micah Beck
  1272. X *
  1273. X * Permission to use, copy, modify, distribute, and sell this software and its
  1274. X * documentation for any purpose is hereby granted without fee, provided that
  1275. X * the above copyright notice appear in all copies and that both that
  1276. X * copyright notice and this permission notice appear in supporting
  1277. X * documentation. The authors make no representations about the suitability 
  1278. X * of this software for any purpose.  It is provided "as is" without express 
  1279. X * or implied warranty.
  1280. X *
  1281. X * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  1282. X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  1283. X * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  1284. X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  1285. X * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  1286. X * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  1287. X * PERFORMANCE OF THIS SOFTWARE.
  1288. X *
  1289. X */
  1290. X
  1291. X/* 
  1292. X *    gentextyl.c : TeXtyl driver for fig2dev
  1293. X *
  1294. X *     Author: Gary Beihl, MCC 8/90
  1295. X *    (beihl@mcc.com)
  1296. X *
  1297. X *      Based on the pictex driver by Micah Beck
  1298. X *
  1299. X */
  1300. X
  1301. X#if defined(hpux) || defined(SYSV)
  1302. X#include <sys/types.h>
  1303. X#endif
  1304. X#include <sys/file.h>
  1305. X#include <stdio.h>
  1306. X#include <math.h>
  1307. X#include "pi.h"
  1308. X#include "object.h"
  1309. X#include "fig2dev.h"
  1310. X#include "texfonts.h"
  1311. X
  1312. X#ifndef sin
  1313. Xextern double sin();
  1314. X#endif
  1315. X#ifndef cos
  1316. Xextern double cos();
  1317. X#endif
  1318. X#ifndef acos
  1319. Xextern double acos();
  1320. X#endif
  1321. X#ifndef fabs
  1322. Xextern double fabs();
  1323. X#endif
  1324. X
  1325. Xvoid gentextyl_ctl_spline(), gentextyl_itp_spline();
  1326. X
  1327. Xstatic int        coord_system;
  1328. Xstatic double        dash_length = -1;
  1329. Xstatic int        line_style = 0; /* Textyl solid line style */
  1330. Xstatic int         linethick = 2;  /* Range is 1-12 `pixels' */
  1331. X
  1332. Xstatic void gentextyl_option(opt, optarg)
  1333. Xchar opt, *optarg;
  1334. X{
  1335. X    switch (opt) {
  1336. X        case 'a':
  1337. X            /* capfonts = 1; */
  1338. X            break;
  1339. X
  1340. X        case 'f':            /* set default text font */
  1341. X            texfontnames[0] = texfontnames[1] = optarg;
  1342. X            break;
  1343. X
  1344. X        case 'l':            /* set line thickness */
  1345. X            linethick = atoi(optarg);
  1346. X                    if (linethick < 1 || linethick > 12) {
  1347. X                      put_msg(Err_badarg, opt, "textyl");
  1348. X                      exit(1);
  1349. X                    }
  1350. X            break;
  1351. X
  1352. X        case 'p':
  1353. X        case 's':
  1354. X        case 'm':
  1355. X        case 'L':
  1356. X            break;
  1357. X
  1358. X    default:
  1359. X        put_msg(Err_badarg, opt, "textyl");
  1360. X        exit(1);
  1361. X        break;
  1362. X    }
  1363. X}
  1364. X
  1365. X#define            TOP    (10.5)    /* top of page is 10.5 inch */
  1366. X#define SCALE (65536.0*72.27)
  1367. Xstatic double        ppi;
  1368. Xstatic int        CONV = 0;
  1369. X#define measure 'S'
  1370. X
  1371. Xconvy(a)
  1372. Xdouble a;
  1373. X{
  1374. X   return (int)(((ury - a) * SCALE) / ppi);
  1375. X}
  1376. X
  1377. Xconvx(a)
  1378. Xdouble a; {
  1379. X  float f;
  1380. X  f = a * SCALE;
  1381. X  return (int)(f / ppi);
  1382. X}
  1383. X
  1384. Xvoid gentextyl_start(objects)
  1385. XF_compound    *objects;
  1386. X{
  1387. X
  1388. X    texfontsizes[0] = texfontsizes[1] = texfontsizes[font_size+1];
  1389. X    coord_system = objects->nwcorner.y;
  1390. X    ppi = objects->nwcorner.x;
  1391. X
  1392. X    if (coord_system == 2) CONV = 1;
  1393. X    /* Textyl start */
  1394. X    fprintf(tfp, "\\begintyl{%fsp}\n",ury/ppi*SCALE);
  1395. X}
  1396. X
  1397. Xvoid gentextyl_end()
  1398. X{
  1399. X  fprintf(tfp,"\\endtyl\n");
  1400. X}
  1401. X
  1402. X
  1403. Xstatic set_linewidth(w)
  1404. Xint    w;
  1405. X{
  1406. X/* Nop */
  1407. X}
  1408. X
  1409. Xvoid gentextyl_line(l)
  1410. XF_line    *l;
  1411. X{
  1412. X    F_point        *p, *q;
  1413. X
  1414. X    fprintf(tfp, "%%\n%% Fig POLYLINE object\n%%\n");
  1415. X
  1416. X    set_linewidth(l->thickness);
  1417. X    set_style(l->style, l->style_val);
  1418. X
  1419. X    p = l->points;
  1420. X    q = p->next;
  1421. X        
  1422. X
  1423. X    if (q == NULL) { /* A single point line */
  1424. X        fprintf(tfp, "\\special{tyl line %c %d L %d %u %u; %u %u}\n", 
  1425. X               measure,linethick,line_style,
  1426. X            convx((double)p->x), convy((double)p->y), 
  1427. X                        convx((double)p->x), convy((double)p->y));
  1428. X        return;
  1429. X        }
  1430. X    if (l->back_arrow)
  1431. X        draw_arrow_head((double)q->x, (double)q->y, (double)p->x,
  1432. X        (double)p->y, l->back_arrow->ht, l->back_arrow->wid);
  1433. X    set_style(l->style, l->style_val);
  1434. X
  1435. X    while (q->next != NULL) {
  1436. X
  1437. X        putline(p->x, p->y, q->x, q->y);
  1438. X        p = q;
  1439. X        q = q->next;
  1440. X        }
  1441. X
  1442. X    putline(p->x, p->y, q->x, q->y);
  1443. X    if (l->for_arrow)
  1444. X        draw_arrow_head((double)p->x, (double)p->y, (double)q->x,
  1445. X        (double)q->y, l->for_arrow->ht, l->for_arrow->wid);
  1446. X
  1447. X    if (l->area_fill && (int)l->area_fill != DEFAULT)
  1448. X        fprintf(stderr, "Line area fill not implemented\n");
  1449. X    }
  1450. X
  1451. X/* 
  1452. X * set_style - issue style commands as appropriate
  1453. X */
  1454. Xstatic set_style(style, dash_len)
  1455. X     int style;
  1456. X     double dash_len;
  1457. X{
  1458. X  
  1459. X  switch (style) {
  1460. X  case SOLID_LINE:
  1461. X    line_style = 0;
  1462. X    break;
  1463. X    
  1464. X  case DASH_LINE:
  1465. X    line_style = 2;
  1466. X    break;
  1467. X    
  1468. X  case DOTTED_LINE:
  1469. X    line_style = 1;
  1470. X    break;
  1471. X  }
  1472. X}
  1473. X
  1474. X/*
  1475. X * putline
  1476. X */
  1477. Xstatic putline (start_x, start_y, end_x, end_y)
  1478. Xint    start_x, start_y, end_x, end_y;
  1479. X{
  1480. X
  1481. X   fprintf(tfp, "\\special{tyl line %c %d L %d %u %u; %u %u}\n", 
  1482. X        measure, linethick,line_style,
  1483. X    convx((double)start_x), convy((double)start_y), 
  1484. X        convx((double)end_x), convy((double)end_y));
  1485. X
  1486. X}
  1487. X
  1488. X
  1489. Xvoid gentextyl_spline(s)
  1490. XF_spline    *s;
  1491. X{
  1492. X
  1493. X    set_linewidth(s->thickness);
  1494. X    set_style(s->style, s->style_val);
  1495. X
  1496. X    if (int_spline(s))
  1497. X        gentextyl_itp_spline(s);
  1498. X    else
  1499. X        gentextyl_ctl_spline(s);
  1500. X
  1501. X    if (s->area_fill && (int)s->area_fill != DEFAULT)
  1502. X        fprintf(stderr, "Spline area fill not implemented\n");
  1503. X}
  1504. X
  1505. Xvoid gentextyl_ellipse(e)
  1506. XF_ellipse    *e;
  1507. X{
  1508. X   int sx, sy;
  1509. X   int radius;
  1510. X    fprintf(tfp, "%%\n%% Fig ELLIPSE\n%%\n");
  1511. X
  1512. X    set_linewidth(e->thickness);
  1513. X    set_style(e->style, e->style_val);
  1514. X
  1515. X    if (e->radiuses.x == e->radiuses.y) {
  1516. X          fprintf(tfp, "\\special{tyl arc %c %d L 0 %u @ %u,%u 0 360}\n",
  1517. X            measure,linethick,convx((double)e->radiuses.x),
  1518. X            convx((double)e->center.x),convy((double)e->center.y));
  1519. X        }
  1520. X    else {
  1521. X          if (e->radiuses.x > e->radiuses.y) {
  1522. X            sy = 100;
  1523. X            sx = ((float)e->radiuses.x/(float)e->radiuses.y) * 100.0;
  1524. X            radius = e->radiuses.y;
  1525. X          }
  1526. X          else {
  1527. X            sx = 100;
  1528. X            sy = ((float)e->radiuses.y/(float)e->radiuses.x) * 100.0;
  1529. X            radius = e->radiuses.x;            
  1530. X          }
  1531. X                fprintf(tfp, 
  1532. X                 "\\special{tyl arc %c T %u %u 0 0 0 %d L 0 %u @ %u,%u 0 360}\n",
  1533. X                  measure,sx,sy,linethick,convx((double)radius),
  1534. X            convx((double)e->center.x),convy((double)e->center.y));
  1535. X        if (e->area_fill && (int)e->area_fill != DEFAULT)
  1536. X            fprintf(stderr, "Ellipse area fill not implemented\n");
  1537. X        }
  1538. X    }
  1539. X
  1540. X#define            HT_OFFSET    (0.2 / 72.0)
  1541. X
  1542. Xvoid gentextyl_text(t)
  1543. XF_text    *t;
  1544. X{
  1545. X    double    x, y;
  1546. X    char *cp;
  1547. X
  1548. X        fprintf(tfp, "%%\n%% Fig TEXT object\n%%\n");
  1549. X
  1550. X    x = t->base_x;
  1551. X    y = t->base_y;
  1552. X
  1553. X    switch (t->type) {
  1554. X
  1555. X        case T_LEFT_JUSTIFIED:
  1556. X        case DEFAULT:
  1557. X        break;
  1558. X        default:
  1559. X        fprintf(stderr, "Warning: Text incorrectly positioned\n");
  1560. X            break;
  1561. X        }
  1562. X
  1563. X        fprintf(tfp,"\\special{tyl label %c 1 %u %u \"%s\"}\n",
  1564. X          measure,convx(x),convy(y),t->cstring);
  1565. X
  1566. X}
  1567. X
  1568. Xvoid gentextyl_arc(a)
  1569. XF_arc    *a;
  1570. X{
  1571. X    double        x, y;
  1572. X    double        cx, cy, sx, sy, ex, ey;
  1573. X    double        dx1, dy1, dx2, dy2, r1, r2, th1, th2, theta;
  1574. X
  1575. X    set_linewidth(a->thickness);
  1576. X    set_style(a->style, a->style_val);
  1577. X
  1578. X    cx = a->center.x; cy = a->center.y;
  1579. X    sx = a->point[0].x; sy = a->point[0].y;
  1580. X    ex = a->point[2].x; ey = a->point[2].y;
  1581. X
  1582. X    if (a->for_arrow) {
  1583. X        arc_tangent(cx, cy, ex, ey, !a->direction, &x, &y);
  1584. X        draw_arrow_head(x, y, ex, ey,
  1585. X            a->for_arrow->ht, a->for_arrow->wid);
  1586. X        }
  1587. X    if (a->back_arrow) {
  1588. X        arc_tangent(cx, cy, sx, sy, a->direction, &x, &y);
  1589. X        draw_arrow_head(x, y, sx, sy,
  1590. X            a->back_arrow->ht, a->back_arrow->wid);
  1591. X        }
  1592. X
  1593. X
  1594. X    cy = ury - a->center.y;
  1595. X    sy = ury - a->point[0].y;
  1596. X    ey = ury - a->point[2].y;
  1597. X
  1598. X    dx1 = sx - cx;
  1599. X    dy1 = sy - cy;
  1600. X    dx2 = ex - cx;
  1601. X    dy2 = ey - cy;
  1602. X
  1603. X    cy = a->center.y;
  1604. X    sy = a->point[0].y;
  1605. X    ey = a->point[2].y;
  1606. X        
  1607. X    rtop(dx1, dy1, &r1, &th1);
  1608. X    rtop(dx2, dy2, &r2, &th2);
  1609. X    theta = th2 - th1;
  1610. X    if (theta > 0) theta -= 2*M_PI;
  1611. X
  1612. X    set_linewidth(a->thickness);
  1613. X
  1614. X    if (a->direction) { /* Counterclockwise */
  1615. X              fprintf(tfp,"\\special{tyl arc %c %d L 0 %u @ %u,%u %d %d}\n",
  1616. X                measure,linethick,convx(r1),convx(cx),convy(cy),
  1617. X                (int)(180/M_PI * th1), (int)(180/M_PI * th2));
  1618. X          }
  1619. X    else {
  1620. X              fprintf(tfp,"\\special{tyl arc %c %d L 0 %u @ %u,%u %d %d}\n",
  1621. X                measure,linethick,convx(r1),convx(cx),convy(cy),
  1622. X                (int)(180/M_PI * th2), (int)(180/M_PI * th1));
  1623. X          }
  1624. X
  1625. X    if (a->area_fill && (int)a->area_fill != DEFAULT)
  1626. X        fprintf(stderr, "Arc area fill not implemented\n");
  1627. X    }
  1628. X
  1629. X
  1630. X
  1631. X/*
  1632. X * rtop - rectangular to polar conversion
  1633. X */
  1634. Xstatic rtop(x, y, r, th)
  1635. Xdouble x, y, *r, *th;
  1636. X{
  1637. X    *r = sqrt(x*x+y*y);
  1638. X    *th = acos(x/(*r));
  1639. X
  1640. X    if (y < 0) *th = 2*M_PI - *th;
  1641. X}
  1642. X
  1643. Xstatic arc_tangent(x1, y1, x2, y2, direction, x, y)
  1644. Xdouble    x1, y1, x2, y2, *x, *y;
  1645. Xint    direction;
  1646. X{
  1647. X    if (direction) { /* counter clockwise  */
  1648. X        *x = x2 + (y2 - y1);
  1649. X        *y = y2 - (x2 - x1);
  1650. X        }
  1651. X    else {
  1652. X        *x = x2 - (y2 - y1);
  1653. X        *y = y2 + (x2 - x1);
  1654. X        }
  1655. X    }
  1656. X
  1657. X/*    draw arrow heading from (x1, y1) to (x2, y2)    */
  1658. X
  1659. Xstatic draw_arrow_head(x1, y1, x2, y2, arrowht, arrowwid)
  1660. Xdouble    x1, y1, x2, y2;
  1661. Xdouble  arrowht, arrowwid;
  1662. X{
  1663. X    double    x, y, xb, yb, dx, dy, l, sina, cosa;
  1664. X    double    xc, yc, xd, yd;
  1665. X    int style;
  1666. X    double dash;
  1667. X
  1668. X    dx = x2 - x1;  dy = y1 - y2;
  1669. X    l = sqrt(dx*dx+dy*dy);
  1670. X    if (l == 0) {
  1671. X         return;
  1672. X    }
  1673. X    else {
  1674. X         sina = dy / l;  cosa = dx / l;
  1675. X    }
  1676. X    xb = x2*cosa - y2*sina;
  1677. X    yb = x2*sina + y2*cosa;
  1678. X    x = xb - arrowht;
  1679. X    y = yb - arrowwid / 2;
  1680. X    xc = x*cosa + y*sina;
  1681. X    yc = -x*sina + y*cosa;
  1682. X    y = yb + arrowwid / 2;
  1683. X    xd = x*cosa + y*sina;
  1684. X    yd = -x*sina + y*cosa;
  1685. X
  1686. X        fprintf(tfp, "%%\n%% arrow head\n%%\n");
  1687. X
  1688. X    fprintf(tfp, "\\special{tyl line %c %d %u %u; %u %u}\n",measure,linethick,
  1689. X        convx(xc), convy(yc), convx(x2), convy(y2));
  1690. X    fprintf(tfp, "\\special{tyl line %c %d %u %u; %u %u}\n",measure,linethick,
  1691. X                convx(x2), convy(y2), convx(xd), convy(yd));
  1692. X
  1693. X    }
  1694. X
  1695. X#define THRESHOLD (10.0)
  1696. Xdouble last_x, last_y;
  1697. X
  1698. Xstatic quadratic_spline(a1, b1, a2, b2, a3, b3, a4, b4)
  1699. Xdouble    a1, b1, a2, b2, a3, b3, a4, b4;
  1700. X{
  1701. X    double    x1, y1, x4, y4;
  1702. X    double    xmid, ymid;
  1703. X
  1704. X    x1 = a1; y1 = b1;
  1705. X    x4 = a4; y4 = b4;
  1706. X    xmid = (a2 + a3) / 2;
  1707. X    ymid = (b2 + b3) / 2;
  1708. X    if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD) {
  1709. X        fprintf(tfp, "\\special{tyl line %c %d %u %u; %u %u}\n", 
  1710. X              measure, linethick,convx(last_x),convy(last_y),
  1711. X              convx(xmid), convy(ymid));
  1712. X            last_x = xmid; last_y = ymid;
  1713. X    }
  1714. X
  1715. X    else {
  1716. X        quadratic_spline(x1, y1, ((x1+a2)/2), ((y1+b2)/2),
  1717. X            ((3*a2+a3)/4), ((3*b2+b3)/4), xmid, ymid);
  1718. X        }
  1719. X
  1720. X    if (fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD) {
  1721. X        fprintf(tfp, "\\special{tyl line %c %d %u %u; %u %u}\n", 
  1722. X              measure, linethick,convx(last_x),convy(last_y),convx(x4), convy(y4));
  1723. X            last_x = x4; last_y = y4;
  1724. X    }
  1725. X
  1726. X    else {
  1727. X        quadratic_spline(xmid, ymid, ((a2+3*a3)/4), ((b2+3*b3)/4),
  1728. X            ((a3+x4)/2), ((b3+y4)/2), x4, y4);
  1729. X        }
  1730. X    }
  1731. X
  1732. Xstatic void gentextyl_ctl_spline(s)
  1733. XF_spline    *s;
  1734. X{
  1735. X    F_point    *p;
  1736. X    double    cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4;
  1737. X    double    x1, y1, x2, y2;
  1738. X
  1739. X        fprintf(tfp, "%%\n%% Fig CONTROL PT SPLINE\n%%\n");
  1740. X
  1741. X    p = s->points;
  1742. X    x1 = p->x;  y1 = p->y;
  1743. X    p = p->next;
  1744. X    x2 = p->x;  y2 = p->y;
  1745. X    cx1 = (x1 + x2) / 2;      cy1 = (y1 + y2) / 2;
  1746. X    cx2 = (x1 + 3 * x2) / 4;  cy2 = (y1 + 3 * y2) / 4;
  1747. X
  1748. X    if (closed_spline(s)) {
  1749. X        fprintf(tfp, "%% closed spline\n%%\n");
  1750. X            last_x = cx1; last_y = cy1;
  1751. X        }
  1752. X    else {
  1753. X        fprintf(tfp, "%% open spline\n%%\n");
  1754. X        if (s->back_arrow)
  1755. X            draw_arrow_head(cx1, cy1, x1, y1,
  1756. X            s->back_arrow->ht, s->back_arrow->wid);
  1757. X            fprintf(tfp, "\\special{tyl line %c %d %u %u;%u %u}\n",
  1758. X              measure,linethick,
  1759. X              convx(x1),convy(y1),convx(cx1),convy(cy1));
  1760. X            last_x = cx1; last_y = cy1;
  1761. X        }
  1762. X
  1763. X    for (p = p->next; p != NULL; p = p->next) {
  1764. X        x1 = x2;  y1 = y2;
  1765. X        x2 = p->x;  y2 = p->y;
  1766. X        cx3 = (3 * x1 + x2) / 4;  cy3 = (3 * y1 + y2) / 4;
  1767. X        cx4 = (x1 + x2) / 2;      cy4 = (y1 + y2) / 2;
  1768. X        quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
  1769. X        cx1 = cx4;  cy1 = cy4;
  1770. X        cx2 = (x1 + 3 * x2) / 4;  cy2 = (y1 + 3 * y2) / 4;
  1771. X        }
  1772. X    x1 = x2;  y1 = y2;
  1773. X    p = s->points->next;
  1774. X    x2 = p->x;  y2 = p->y;
  1775. X    cx3 = (3 * x1 + x2) / 4;  cy3 = (3 * y1 + y2) / 4;
  1776. X    cx4 = (x1 + x2) / 2;      cy4 = (y1 + y2) / 2;
  1777. X    if (closed_spline(s)) {
  1778. X        quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
  1779. X        }
  1780. X    else {
  1781. X            fprintf(tfp,"\\special{tyl line %c %d %u %u;%u %u}\n",
  1782. X              measure,linethick,
  1783. X              convx(cx1),convy(cy1),convx(x1),convy(y1));
  1784. X        if (s->for_arrow)
  1785. X            draw_arrow_head(cx1, cy1, x1, y1,
  1786. X            s->for_arrow->ht, s->for_arrow->wid);
  1787. X        }
  1788. X
  1789. X    }
  1790. X
  1791. Xstatic void gentextyl_itp_spline(s)
  1792. XF_spline    *s;
  1793. X{
  1794. X  F_point        *p1, *p2;
  1795. X  F_control    *cp1, *cp2;
  1796. X  double        x1, x2, y1, y2;
  1797. X  
  1798. X  
  1799. X  p1 = s->points;
  1800. X  cp1 = s->controls;
  1801. X  x2 = p1->x; y2 = p1->y;
  1802. X  
  1803. X  if (s->back_arrow)
  1804. X    draw_arrow_head(cp1->rx, cp1->ry, x2, y2,
  1805. X            s->back_arrow->ht, s->back_arrow->wid);
  1806. X  
  1807. X  last_x = x2; last_y = y2;
  1808. X  
  1809. X  fprintf(tfp, "%%\n%% Fig INTERPOLATED SPLINE\n%%\n");
  1810. X  for (p2 = p1->next, cp2 = s->controls->next; 
  1811. X       p2 != NULL; 
  1812. X       cp1 = cp2, p2 = p2->next, cp2 = cp2->next) {
  1813. X    x1 = x2; y1 = y2; x2 = p2->x; y2 = p2->y;
  1814. X    bezier_spline(x1,y1,cp1->rx,cp1->ry,
  1815. X          cp2->lx,cp2->ly,x2,y2);
  1816. X  }
  1817. X  
  1818. X  if (s->for_arrow)
  1819. X    draw_arrow_head(cp1->lx, cp1->ly, x2, y2,
  1820. X            s->for_arrow->ht, s->for_arrow->wid);
  1821. X}
  1822. X
  1823. Xstatic bezier_spline(a0, b0, a1, b1, a2, b2, a3, b3)
  1824. Xdouble    a0, b0, a1, b1, a2, b2, a3, b3;
  1825. X{
  1826. X  double    x0, y0, x3, y3;
  1827. X  double    sx1, sy1, sx2, sy2, tx, ty, tx1, ty1, tx2, ty2, xmid, ymid;
  1828. X  
  1829. X  x0 = a0; y0 = b0;
  1830. X  x3 = a3; y3 = b3;
  1831. X  if (fabs(x0 - x3) < THRESHOLD && fabs(y0 - y3) < THRESHOLD)  {
  1832. X    fprintf(tfp,"\\special{tyl line %c %d %u %u ; %u %u}\n",measure,linethick,
  1833. X        convx(last_x),convy(last_y),convx(x3),convy(y3));
  1834. X    last_x = x3; last_y = y3; 
  1835. X  }
  1836. X  
  1837. X  else {
  1838. X    tx = (a1 + a2) / 2;        ty = (b1 + b2) / 2;
  1839. X    sx1 = (x0 + a1) / 2;    sy1 = (y0 + b1) / 2;
  1840. X    sx2 = (sx1 + tx) / 2;    sy2 = (sy1 + ty) / 2;
  1841. X    tx2 = (a2 + x3) / 2;    ty2 = (b2 + y3) / 2;
  1842. X    tx1 = (tx2 + tx) / 2;    ty1 = (ty2 + ty) / 2;
  1843. X    xmid = (sx2 + tx1) / 2;    ymid = (sy2 + ty1) / 2;
  1844. X    
  1845. X    bezier_spline(x0, y0, sx1, sy1, sx2, sy2, xmid, ymid);
  1846. X    bezier_spline(xmid, ymid, tx1, ty1, tx2, ty2, x3, y3);
  1847. X  }
  1848. X}
  1849. X
  1850. Xstruct driver dev_textyl = {
  1851. X         gentextyl_option,
  1852. X    gentextyl_start,
  1853. X    gentextyl_arc,
  1854. X    gentextyl_ellipse,
  1855. X    gentextyl_line,
  1856. X    gentextyl_spline,
  1857. X    gentextyl_text,
  1858. X    gentextyl_end,
  1859. X    EXCLUDE_TEXT
  1860. X};
  1861. X
  1862. END_OF_FILE
  1863. if test 14413 -ne `wc -c <'fig2dev/dev/gentextyl.c'`; then
  1864.     echo shar: \"'fig2dev/dev/gentextyl.c'\" unpacked with wrong size!
  1865. fi
  1866. # end of 'fig2dev/dev/gentextyl.c'
  1867. fi
  1868. if test -f 'fig2dev/read.c' -a "${1}" != "-c" ; then 
  1869.   echo shar: Will not clobber existing file \"'fig2dev/read.c'\"
  1870. else
  1871. echo shar: Extracting \"'fig2dev/read.c'\" \(20800 characters\)
  1872. sed "s/^X//" >'fig2dev/read.c' <<'END_OF_FILE'
  1873. X/*
  1874. X * TransFig: Facility for Translating Fig code
  1875. X * Copyright (c) 1985 Supoj Sutantavibul
  1876. X * Copyright (c) 1991 Micah Beck
  1877. X *
  1878. X * Permission to use, copy, modify, distribute, and sell this software and its
  1879. X * documentation for any purpose is hereby granted without fee, provided that
  1880. X * the above copyright notice appear in all copies and that both that
  1881. X * copyright notice and this permission notice appear in supporting
  1882. X * documentation. The authors make no representations about the suitability 
  1883. X * of this software for any purpose.  It is provided "as is" without express 
  1884. X * or implied warranty.
  1885. X *
  1886. X * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  1887. X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  1888. X * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  1889. X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  1890. X * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  1891. X * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  1892. X * PERFORMANCE OF THIS SOFTWARE.
  1893. X *
  1894. X */
  1895. X
  1896. X/* 
  1897. X *    FIG : Facility for Interactive Generation of figures
  1898. X *
  1899. X *    Copyright (c) 1985, 1988 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
  1900. X *    January 1985.
  1901. X *    1st revision : August 1985.
  1902. X *    2nd revision : March 1988.
  1903. X *
  1904. X *    %W%    %G%
  1905. X*/
  1906. X#include <stdio.h>
  1907. X#include <ctype.h>
  1908. X#include <errno.h>
  1909. X#include "alloc.h"
  1910. X#include "object.h"
  1911. X
  1912. X#if defined(hpux) || defined(SYSV)
  1913. X#define bzero(s,n) memset((s),'\0',(n))
  1914. X#endif
  1915. X
  1916. Xextern int            errno;
  1917. X
  1918. Xextern F_arrow        *make_arrow();
  1919. Xextern char        *calloc();
  1920. Xextern double            floor(), ceil();
  1921. X
  1922. Xstatic F_ellipse    *read_ellipseobject();
  1923. Xstatic F_line        *read_lineobject();
  1924. Xstatic F_text        *read_textobject();
  1925. Xstatic F_spline        *read_splineobject();
  1926. Xstatic F_arc        *read_arcobject();
  1927. Xstatic F_compound    *read_compoundobject();
  1928. X
  1929. X#define            FILL_CONVERT(f) \
  1930. X                ((v2_flag || (f) < WHITE_FILL) \
  1931. X                    ? (f) : 21 - ((f)-1)*5)
  1932. X
  1933. X#define            BUF_SIZE        1024
  1934. X
  1935. Xchar            buf[BUF_SIZE];
  1936. Xint            line_no = 0;
  1937. Xint            num_object;
  1938. Xint            v2_flag;    /* Protocol V2.0 or V2.1 */
  1939. Xint            v21_flag;    /* Protocol V2.1 */
  1940. X
  1941. Xread_fail_message(file, err)
  1942. Xchar    *file;
  1943. Xint    err;
  1944. X{
  1945. X    extern char    *sys_errlist[];
  1946. X
  1947. X    if (err == 0)        /* Successful read */
  1948. X        return;
  1949. X#if !defined(hpux) && !defined(SYSV)
  1950. X    else if (err == ENAMETOOLONG)
  1951. X        put_msg("File name \"%s\" is too long", file);
  1952. X#endif
  1953. X    else if (err == ENOENT)
  1954. X        put_msg("File \"%s\" does not exist", file);
  1955. X    else if (err == ENOTDIR)
  1956. X        put_msg("A name in the path \"%s\" is not a directory", file);
  1957. X    else if (err == EACCES)
  1958. X        put_msg("Read access to file \"%s\" is blocked", file);
  1959. X    else if (err == EISDIR)
  1960. X        put_msg("File \"%s\" is a directory", file);
  1961. X    else if (err == -2) {
  1962. X        put_msg("File \"%s\" is empty", file);
  1963. X        }
  1964. X    else if (err == -1) {
  1965. X        /* Format error; relevant error message is already delivered */
  1966. X        }
  1967. X    else
  1968. X        put_msg("File \"%s\" is not accessable; %s", file, sys_errlist[err]);
  1969. X    }
  1970. X
  1971. X/**********************************************************
  1972. XRead_fig returns :
  1973. X
  1974. X     0 : successful read.
  1975. X    -1 : File is in incorrect format
  1976. X    -2 : File is empty
  1977. Xerr_no : if file can not be read for various reasons
  1978. X
  1979. XThe resolution (ppi) and the cooridnate system (coord_sys) are
  1980. Xstored in obj->nwcorner.x and obj->nwcorner.x respectively.
  1981. X**********************************************************/
  1982. X
  1983. Xread_fig(file_name, obj)
  1984. Xchar        *file_name;
  1985. XF_compound    *obj;
  1986. X{
  1987. X    FILE        *fp;
  1988. X
  1989. X    if ((fp = fopen(file_name, "r")) == NULL)
  1990. X        return(errno);
  1991. X    else
  1992. X        return(readfp_fig(fp, obj));
  1993. X    }
  1994. X
  1995. Xreadfp_fig(fp, obj)
  1996. XFILE    *fp;
  1997. XF_compound    *obj;
  1998. X{
  1999. X    char        c;
  2000. X    int        status;
  2001. X
  2002. X    num_object = 0;
  2003. X    c = fgetc(fp);
  2004. X    if (feof(fp)) return(-2);
  2005. X    ungetc(c, fp);
  2006. X    bzero((char*)obj, COMOBJ_SIZE);
  2007. X    if (c == '#')
  2008. X        status = read_objects(fp, obj);
  2009. X    else
  2010. X        status = read_1_3_objects(fp, obj);
  2011. X    (void)fclose(fp);
  2012. X    return(status);
  2013. X    }
  2014. X    
  2015. Xint
  2016. Xread_objects(fp, obj)
  2017. XFILE        *fp;
  2018. XF_compound    *obj;
  2019. X{
  2020. X    F_ellipse    *e, *le = NULL;
  2021. X    F_line        *l, *ll = NULL;
  2022. X    F_text        *t, *lt = NULL;
  2023. X    F_spline    *s, *ls = NULL;
  2024. X    F_arc        *a, *la = NULL;
  2025. X    F_compound    *c, *lc = NULL;
  2026. X    int        object, ppi, coord_sys;
  2027. X
  2028. X    bzero((char*)obj, COMOBJ_SIZE);
  2029. X    (void)fgets(buf, BUF_SIZE, fp);    /* get the version line */
  2030. X
  2031. X    v2_flag = (!strncmp(buf, "#FIG 2", 6));
  2032. X    v21_flag = (!strncmp(buf, "#FIG 2.1", 8));
  2033. X
  2034. X    line_no++;
  2035. X    if (get_line(fp) < 0) {
  2036. X        put_msg("File is truncated");
  2037. X        return(-1);
  2038. X        }
  2039. X    if (2 != sscanf(buf,"%d%d\n", &ppi, &coord_sys)) {
  2040. X        put_msg("Incomplete data at line %d", line_no);
  2041. X        return(-1);
  2042. X        }
  2043. X
  2044. X    obj->nwcorner.x = ppi;
  2045. X    obj->nwcorner.y = coord_sys;
  2046. X    while (get_line(fp) > 0) {
  2047. X        if (1 != sscanf(buf, "%d", &object)) {
  2048. X        put_msg("Incorrect format at line %d", line_no);
  2049. X        return(-1);
  2050. X        }
  2051. X        switch (object) {
  2052. X        case O_POLYLINE :
  2053. X            if ((l = read_lineobject(fp)) == NULL) return(-1);
  2054. X            if (ll)
  2055. X            ll = (ll->next = l);
  2056. X            else 
  2057. X            ll = obj->lines = l;
  2058. X            num_object++;
  2059. X            break;
  2060. X        case O_SPLINE :
  2061. X            if ((s = read_splineobject(fp)) == NULL) return(-1);
  2062. X            if (ls)
  2063. X            ls = (ls->next = s);
  2064. X            else 
  2065. X            ls = obj->splines = s;
  2066. X            num_object++;
  2067. X            break;
  2068. X        case O_ELLIPSE :
  2069. X            if ((e = read_ellipseobject()) == NULL) return(-1);
  2070. X            if (le)
  2071. X            le = (le->next = e);
  2072. X            else 
  2073. X            le = obj->ellipses = e;
  2074. X            num_object++;
  2075. X            break;
  2076. X        case O_ARC :
  2077. X            if ((a = read_arcobject(fp)) == NULL) return(-1);
  2078. X            if (la)
  2079. X            la = (la->next = a);
  2080. X            else 
  2081. X            la = obj->arcs = a;
  2082. X            num_object++;
  2083. X            break;
  2084. X        case O_TEXT :
  2085. X            if ((t = read_textobject(fp)) == NULL) return(-1);
  2086. X            if (lt)
  2087. X            lt = (lt->next = t);
  2088. X            else 
  2089. X            lt = obj->texts = t;
  2090. X            num_object++;
  2091. X            break;
  2092. X        case O_COMPOUND :
  2093. X            if ((c = read_compoundobject(fp)) == NULL) return(-1);
  2094. X            if (lc)
  2095. X            lc = (lc->next = c);
  2096. X            else 
  2097. X            lc = obj->compounds = c;
  2098. X            num_object++;
  2099. X            break;
  2100. X        default :
  2101. X            put_msg("Incorrect object code at line %d", line_no);
  2102. X            return(-1);
  2103. X        } /*  switch */
  2104. X        } /*  while */
  2105. X    if (feof(fp))
  2106. X        return(0);
  2107. X    else
  2108. X        return(errno);
  2109. X    } /*  read_objects */
  2110. X
  2111. Xstatic F_arc *
  2112. Xread_arcobject(fp)
  2113. XFILE    *fp;
  2114. X{
  2115. X    F_arc    *a;
  2116. X    int    n, fa, ba;
  2117. X    int    type, style;
  2118. X    double    thickness, wid, ht;
  2119. X
  2120. X    if (NULL == (Arc_malloc(a))) {
  2121. X        put_msg(Err_mem);
  2122. X        return(NULL);
  2123. X        }
  2124. X    a->pen = 0;
  2125. X    a->area_fill = 0;
  2126. X    a->for_arrow = NULL;
  2127. X    a->back_arrow = NULL;
  2128. X    a->next = NULL;
  2129. X    n = sscanf(buf, "%*d%d%d%d%d%d%d%d%lf%d%d%d%lf%lf%d%d%d%d%d%d\n",
  2130. X        &a->type, &a->style, &a->thickness, 
  2131. X        &a->color, &a->depth, &a->pen, &a->area_fill, 
  2132. X        &a->style_val, &a->direction, &fa, &ba,
  2133. X        &a->center.x, &a->center.y, 
  2134. X        &a->point[0].x, &a->point[0].y, 
  2135. X        &a->point[1].x, &a->point[1].y, 
  2136. X        &a->point[2].x, &a->point[2].y);
  2137. X    if (n != 19) {
  2138. X        put_msg(Err_incomp, "arc", line_no);
  2139. X        free((char*)a);
  2140. X        return(NULL);
  2141. X        }
  2142. X    a->area_fill = FILL_CONVERT(a->area_fill);
  2143. X    skip_comment(fp);
  2144. X    if (fa) {
  2145. X        line_no++;
  2146. X        if (5 != fscanf(fp, "%d%d%lf%lf%lf", &type, &style, &thickness, &wid, &ht)) {
  2147. X        fprintf(stderr, Err_incomp, "arc", line_no);
  2148. X        return(NULL);
  2149. X        }
  2150. X        skip_line(fp);
  2151. X        a->for_arrow = make_arrow(type, style, thickness, wid, ht);
  2152. X        skip_comment(fp);
  2153. X        }
  2154. X    skip_comment(fp);
  2155. X    if (ba) {
  2156. X        line_no++;
  2157. X        if (5 != fscanf(fp, "%d%d%lf%lf%lf", &type, &style, &thickness, &wid, &ht)) {
  2158. X        fprintf(stderr, Err_incomp, "arc", line_no);
  2159. X        return(NULL);
  2160. X        }
  2161. X        skip_line(fp);
  2162. X        a->back_arrow = make_arrow(type, style, thickness, wid, ht);
  2163. X        }
  2164. X    return(a);
  2165. X    }
  2166. X
  2167. Xstatic F_compound *
  2168. Xread_compoundobject(fp)
  2169. XFILE    *fp;
  2170. X{
  2171. X    F_arc        *a, *la = NULL;
  2172. X    F_ellipse    *e, *le = NULL;
  2173. X    F_line        *l, *ll = NULL;
  2174. X    F_spline    *s, *ls = NULL;
  2175. X    F_text        *t, *lt = NULL;
  2176. X    F_compound    *com, *c, *lc = NULL;
  2177. X    int        n, object;
  2178. X
  2179. X    Compound_malloc(com);
  2180. X    com->arcs = NULL;
  2181. X    com->ellipses = NULL;
  2182. X    com->lines = NULL;
  2183. X    com->splines = NULL;
  2184. X    com->texts = NULL;
  2185. X    com->compounds = NULL;
  2186. X    com->next = NULL;
  2187. X    n = sscanf(buf, "%*d%d%d%d%d\n", &com->nwcorner.x, &com->nwcorner.y,
  2188. X        &com->secorner.x, &com->secorner.y);
  2189. X    if (4 != n) {
  2190. X        put_msg(Err_incomp, "compound", line_no);
  2191. X        free((char*)com);
  2192. X        return(NULL);
  2193. X        }
  2194. X    while (get_line(fp) > 0) {
  2195. X        if (1 != sscanf(buf, "%d", &object)) {
  2196. X        put_msg(Err_incomp, "compound", line_no);
  2197. X        free_compound(&com);
  2198. X        return(NULL);
  2199. X        }
  2200. X        switch (object) {
  2201. X        case O_POLYLINE :
  2202. X            if ((l = read_lineobject(fp)) == NULL) { 
  2203. X            free_line(&l);
  2204. X            return(NULL);
  2205. X            }
  2206. X            if (ll)
  2207. X            ll = (ll->next = l);
  2208. X            else 
  2209. X            ll = com->lines = l;
  2210. X            break;
  2211. X        case O_SPLINE :
  2212. X            if ((s = read_splineobject(fp)) == NULL) { 
  2213. X            free_spline(&s);
  2214. X            return(NULL);
  2215. X            }
  2216. X            if (ls)
  2217. X            ls = (ls->next = s);
  2218. X            else 
  2219. X            ls = com->splines = s;
  2220. X            break;
  2221. X        case O_ELLIPSE :
  2222. X            if ((e = read_ellipseobject()) == NULL) { 
  2223. X            free_ellipse(&e);
  2224. X            return(NULL);
  2225. X            }
  2226. X            if (le)
  2227. X            le = (le->next = e);
  2228. X            else 
  2229. X            le = com->ellipses = e;
  2230. X            break;
  2231. X        case O_ARC :
  2232. X            if ((a = read_arcobject(fp)) == NULL) { 
  2233. X            free_arc(&a);
  2234. X            return(NULL);
  2235. X            }
  2236. X            if (la)
  2237. X            la = (la->next = a);
  2238. X            else 
  2239. X            la = com->arcs = a;
  2240. X            break;
  2241. X        case O_TEXT :
  2242. X            if ((t = read_textobject(fp)) == NULL) { 
  2243. X            free_text(&t);
  2244. X            return(NULL);
  2245. X            }
  2246. X            if (lt)
  2247. X            lt = (lt->next = t);
  2248. X            else 
  2249. X            lt = com->texts = t;
  2250. X            break;
  2251. X        case O_COMPOUND :
  2252. X            if ((c = read_compoundobject(fp)) == NULL) { 
  2253. X            free_compound(&c);
  2254. X            return(NULL);
  2255. X            }
  2256. X            if (lc)
  2257. X            lc = (lc->next = c);
  2258. X            else 
  2259. X            lc = com->compounds = c;
  2260. X            break;
  2261. X        case O_END_COMPOUND :
  2262. X            return(com);
  2263. X        default :
  2264. X            put_msg("Wrong object code at line %d", line_no);
  2265. X            return(NULL);
  2266. X        } /*  switch */
  2267. X        }
  2268. X    if (feof(fp))
  2269. X        return(com);
  2270. X    else
  2271. X        return(NULL);
  2272. X    }
  2273. X
  2274. Xstatic F_ellipse *
  2275. Xread_ellipseobject()
  2276. X{
  2277. X    F_ellipse    *e;
  2278. X    int        n;
  2279. X
  2280. X    Ellipse_malloc(e);
  2281. X    e->area_fill = 0;
  2282. X    e->pen = 0;
  2283. X    e->next = NULL;
  2284. X    n = sscanf(buf, "%*d%d%d%d%d%d%d%d%lf%d%lf%d%d%d%d%d%d%d%d\n",
  2285. X        &e->type, &e->style, &e->thickness,
  2286. X        &e->color, &e->depth, &e->pen, &e->area_fill,
  2287. X        &e->style_val, &e->direction, &e->angle,
  2288. X        &e->center.x, &e->center.y, 
  2289. X        &e->radiuses.x, &e->radiuses.y, 
  2290. X        &e->start.x, &e->start.y, 
  2291. X        &e->end.x, &e->end.y);
  2292. X    if (n != 18) {
  2293. X        put_msg(Err_incomp, "ellipse", line_no);
  2294. X        free((char*)e);
  2295. X        return(NULL);
  2296. X        }
  2297. X    e->area_fill = FILL_CONVERT(e->area_fill);
  2298. X    return(e);
  2299. X    }
  2300. X
  2301. Xstatic F_line *
  2302. Xread_lineobject(fp)
  2303. XFILE    *fp;
  2304. X{
  2305. X    F_line    *l;
  2306. X    F_point    *p, *q;
  2307. X    int    n, x, y, fa, ba;
  2308. X    int    type, style, radius_flag;
  2309. X    double    thickness, wid, ht;
  2310. X
  2311. X    Line_malloc(l);
  2312. X    l->points = NULL;
  2313. X    l->pen = 0;
  2314. X    l->area_fill = 0;
  2315. X    l->for_arrow = NULL;
  2316. X    l->back_arrow = NULL;
  2317. X    l->next = NULL;
  2318. X
  2319. X    sscanf(buf,"%*d%d",&l->type);    /* get the line type */
  2320. X
  2321. X    radius_flag = v21_flag || (v2_flag && l->type == T_ARC_BOX);
  2322. X    if (radius_flag)
  2323. X        {
  2324. X        n = sscanf(buf, "%*d%d%d%d%d%d%d%d%lf%d%d%d",
  2325. X        &l->type, &l->style, &l->thickness, &l->color,
  2326. X        &l->depth, &l->pen, &l->area_fill, &l->style_val, &l->radius, &fa, &ba);
  2327. X        }
  2328. X    /* old format uses pen for radius of arc-box corners */
  2329. X    else
  2330. X        {
  2331. X        n = sscanf(buf, "%*d%d%d%d%d%d%d%d%lf%d%d",
  2332. X        &l->type, &l->style, &l->thickness, &l->color,
  2333. X        &l->depth, &l->pen, &l->area_fill, &l->style_val, &fa, &ba);
  2334. X        if (l->type == T_ARC_BOX)
  2335. X        {
  2336. X        l->radius = (int) l->pen;
  2337. X        l->pen = 0;
  2338. X        }
  2339. X        else
  2340. X        l->radius = 0;
  2341. X        }
  2342. X    if ((!radius_flag && n!=10) || (radius_flag && n!=11)) {
  2343. X        put_msg(Err_incomp, "line", line_no);
  2344. X        free((char*)l);
  2345. X        return(NULL);
  2346. X        }
  2347. X    l->area_fill = FILL_CONVERT(l->area_fill);
  2348. X    skip_comment(fp);
  2349. X    if (fa) {
  2350. X        line_no++;
  2351. X        if (5 != fscanf(fp, "%d%d%lf%lf%lf", &type, &style, &thickness, &wid, &ht)) {
  2352. X        fprintf(stderr, Err_incomp, "line", line_no);
  2353. X        return(NULL);
  2354. X        }
  2355. X        skip_line(fp);
  2356. X        l->for_arrow = make_arrow(type, style, thickness, wid, ht);
  2357. X        skip_comment(fp);
  2358. X        }
  2359. X    if (ba) {
  2360. X        line_no++;
  2361. X        if (5 != fscanf(fp, "%d%d%lf%lf%lf", &type, &style, &thickness, &wid, &ht)) {
  2362. X        fprintf(stderr, Err_incomp, "line", line_no);
  2363. X        return(NULL);
  2364. X        }
  2365. X        skip_line(fp);
  2366. X        l->back_arrow = make_arrow(type, style, thickness, wid, ht);
  2367. X        skip_comment(fp);
  2368. X        }
  2369. X        if (l->type == T_EPS_BOX) {
  2370. X        line_no++;
  2371. X        Eps_malloc(l->eps);
  2372. X        if (l->eps  == NULL) {
  2373. X            free((char *) l);
  2374. X            return (NULL);
  2375. X        }
  2376. X        if (2 != fscanf(fp, "%d %s", &l->eps->flipped, l->eps->file)) {
  2377. X                put_msg(Err_incomp,
  2378. X                "Encapsulated Postscript", line_no);
  2379. X                fprintf(stderr, Err_incomp,
  2380. X                "Encapsulated Postscript", line_no);
  2381. X            return (NULL);
  2382. X        }
  2383. X        read_epsf(l->eps);
  2384. X        } else
  2385. X        l->eps = NULL;
  2386. X
  2387. X    if (NULL == (l->points = Point_malloc(p))) {
  2388. X        put_msg(Err_mem);
  2389. X        return(NULL);
  2390. X        }
  2391. X    p->next = NULL;
  2392. X    if (fscanf(fp, "%d%d", &p->x, &p->y) != 2) {
  2393. X        put_msg(Err_incomp, "line", line_no);
  2394. X        free_linestorage(l);
  2395. X        return(NULL);
  2396. X        }
  2397. X    for (;;) {
  2398. X        if (fscanf(fp, "%d%d", &x, &y) != 2) {
  2399. X        put_msg(Err_incomp, "line", line_no);
  2400. X        free_linestorage(l);
  2401. X        return(NULL);
  2402. X        }
  2403. X        if (x == 9999) break;
  2404. X        if (NULL == (Point_malloc(q))) {
  2405. X        put_msg(Err_mem);
  2406. X        free_linestorage(l);
  2407. X        return(NULL);
  2408. X        }
  2409. X        q->x = x;
  2410. X        q->y = y;
  2411. X        q->next = NULL;
  2412. X        p->next = q;
  2413. X        p = q;
  2414. X        }
  2415. X    skip_line(fp);
  2416. X    return(l);
  2417. X    }
  2418. X
  2419. Xstatic F_spline *
  2420. Xread_splineobject(fp)
  2421. XFILE    *fp;
  2422. X{
  2423. X    F_spline    *s;
  2424. X    F_point        *p, *q;
  2425. X    F_control    *cp, *cq;
  2426. X    int        c, n, x, y, fa, ba;
  2427. X    int        type, style;
  2428. X    double        thickness, wid, ht;
  2429. X    double        lx, ly, rx, ry;
  2430. X
  2431. X    Spline_malloc(s);
  2432. X    s->points = NULL;
  2433. X    s->controls = NULL;
  2434. X    s->pen = 0;
  2435. X    s->area_fill = 0;
  2436. X    s->for_arrow = NULL;
  2437. X    s->back_arrow = NULL;
  2438. X    s->next = NULL;
  2439. X
  2440. X    n = sscanf(buf, "%*d%d%d%d%d%d%d%d%lf%d%d",
  2441. X            &s->type, &s->style, &s->thickness, &s->color,
  2442. X        &s->depth, &s->pen, &s->area_fill, &s->style_val, &fa, &ba);
  2443. X    if (n != 10) {
  2444. X        put_msg(Err_incomp, "spline", line_no);
  2445. X        free((char*)s);
  2446. X        return(NULL);
  2447. X        }
  2448. X    s->area_fill = FILL_CONVERT(s->area_fill);
  2449. X    skip_comment(fp);
  2450. X    if (fa) {
  2451. X        line_no++;
  2452. X        if (5 != fscanf(fp, "%d%d%lf%lf%lf", &type, &style, &thickness, &wid, &ht)) {
  2453. X        fprintf(stderr, Err_incomp, "spline", line_no);
  2454. X        return(NULL);
  2455. X        }
  2456. X        skip_line(fp);
  2457. X        s->for_arrow = make_arrow(type, style, thickness, wid, ht);
  2458. X        skip_comment(fp);
  2459. X        }
  2460. X    if (ba) {
  2461. X        line_no++;
  2462. X        if (5 != fscanf(fp, "%d%d%lf%lf%lf", &type, &style, &thickness, &wid, &ht)) {
  2463. X        fprintf(stderr, Err_incomp, "spline", line_no);
  2464. X        return(NULL);
  2465. X        }
  2466. X        skip_line(fp);
  2467. X        s->back_arrow = make_arrow(type, style, thickness, wid, ht);
  2468. X        skip_comment(fp);
  2469. X        }
  2470. X
  2471. X    /* Read points */
  2472. X    if ((n = fscanf(fp, "%d%d", &x, &y)) != 2) {
  2473. X        put_msg(Err_incomp, "spline", line_no);
  2474. X        free_splinestorage(s);
  2475. X        return(NULL);
  2476. X        };
  2477. X    if (NULL == (s->points = Point_malloc(p))) {
  2478. X        put_msg(Err_mem);
  2479. X        free_splinestorage(s);
  2480. X        return(NULL);
  2481. X        }
  2482. X    p->x = x; p->y = y;
  2483. X    for (c = 1;;) {
  2484. X        if (fscanf(fp, "%d%d", &x, &y) != 2) {
  2485. X        put_msg(Err_incomp, "spline", line_no);
  2486. X        p->next = NULL;
  2487. X        free_splinestorage(s);
  2488. X        return(NULL);
  2489. X        };
  2490. X        if (x == 9999) break;
  2491. X        if (NULL == (Point_malloc(q))) {
  2492. X        put_msg(Err_mem);
  2493. X        free_splinestorage(s);
  2494. X        return(NULL);
  2495. X        }
  2496. X        q->x = x;
  2497. X        q->y = y;
  2498. X        p->next = q;
  2499. X        p = q;
  2500. X        c++;
  2501. X        }
  2502. X    p->next = NULL;
  2503. X    skip_line(fp);
  2504. X
  2505. X    if (normal_spline(s)) return(s);
  2506. X
  2507. X    skip_comment(fp);
  2508. X    /* Read controls */
  2509. X    if ((n = fscanf(fp, "%lf%lf%lf%lf", &lx, &ly, &rx, &ry)) != 4) {
  2510. X        put_msg(Err_incomp, "spline", line_no);
  2511. X        free_splinestorage(s);
  2512. X        return(NULL);
  2513. X        };
  2514. X    if (NULL == (s->controls = Control_malloc(cp))) {
  2515. X        put_msg(Err_mem);
  2516. X        free_splinestorage(s);
  2517. X        return(NULL);
  2518. X        }
  2519. X    cp->lx = lx; cp->ly = ly;
  2520. X    cp->rx = rx; cp->ry = ry;
  2521. X    while (--c) {
  2522. X        if (fscanf(fp, "%lf%lf%lf%lf", &lx, &ly, &rx, &ry) != 4) {
  2523. X        put_msg(Err_incomp, "spline", line_no);
  2524. X        cp->next = NULL;
  2525. X        free_splinestorage(s);
  2526. X        return(NULL);
  2527. X        };
  2528. X        if (NULL == (Control_malloc(cq))) {
  2529. X        put_msg(Err_mem);
  2530. X        cp->next = NULL;
  2531. X        free_splinestorage(s);
  2532. X        return(NULL);
  2533. X        }
  2534. X        cq->lx = lx; cq->ly = ly;
  2535. X        cq->rx = rx; cq->ry = ry;
  2536. X        cp->next = cq;
  2537. X        cp = cq;
  2538. X        }
  2539. X    cp->next = NULL;
  2540. X
  2541. X    skip_line(fp);
  2542. X    return(s);
  2543. X    }
  2544. X
  2545. Xstatic F_text *
  2546. Xread_textobject(fp)
  2547. XFILE    *fp;
  2548. X{
  2549. X    F_text    *t;
  2550. X    int    n, ignore = 0;
  2551. X    char    s[BUF_SIZE], s_temp[BUF_SIZE], junk[2];
  2552. X
  2553. X    Text_malloc(t);
  2554. X    t->font = 0;
  2555. X    t->size = 0.0;
  2556. X    t->next = NULL;
  2557. X    /* The text object is terminated by a CONTROL-A, so we read
  2558. X       everything up to the CONTROL-A and then read that character.
  2559. X       If we do not find the CONTROL-A on this line then this must
  2560. X       be a multi-line text object and we will have to read more. */
  2561. X    n = sscanf(buf,"%*d%d%d%lf%d%d%d%lf%d%lf%lf%d%d%[^\1]%[\1]",
  2562. X        &t->type, &t->font, &t->size, &t->pen,
  2563. X        &t->color, &t->depth, &t->angle,
  2564. X        &t->flags, &t->height, &t->length, 
  2565. X        &t->base_x, &t->base_y, s, junk);
  2566. X    if ((n != 14) && (n != 13)) {
  2567. X      put_msg(Err_incomp, "text", line_no);
  2568. X      free((char*)t);
  2569. X/*       return(NULL); */
  2570. X    }
  2571. X    if (n == 13) {
  2572. X      /* Read in the remainder of the text object. */
  2573. X      do {
  2574. X        fgets(buf, BUF_SIZE, fp);
  2575. X        line_no++;  /* As is done in get_line */
  2576. X        n = sscanf(buf,"%[^\1]%[\1]", s_temp, junk);
  2577. X        /* Safety check */
  2578. X        if (strlen(s)+1 + strlen(s_temp)+1 > BUF_SIZE) {
  2579. X          /* Too many characters.  Ignore the rest. */
  2580. X          ignore = 1;
  2581. X        }
  2582. X        if (!ignore)
  2583. X          strcat(s, s_temp);
  2584. X      } while (n == 1);
  2585. X    }
  2586. X    if (strlen(s) == 0) (void)strcpy(s, " ");
  2587. X    t->cstring = (char*)calloc((unsigned)(strlen(s)), sizeof(char));
  2588. X    if (NULL == t->cstring) {
  2589. X        put_msg(Err_mem);
  2590. X        free((char*)t);
  2591. X        return(NULL);
  2592. X        }
  2593. X    (void)strcpy(t->cstring, s+1);
  2594. X
  2595. X    if (!v21_flag && (t->font == 0 || t->font == DEFAULT))
  2596. X        t->flags = ((t->flags != DEFAULT) ? t->flags : 0)
  2597. X                | SPECIAL_TEXT;
  2598. X
  2599. X    if (v2_flag && !v21_flag && !special_text(t)) 
  2600. X        t->flags = ((t->flags != DEFAULT) ? t->flags : 0)
  2601. X                | PSFONT_TEXT;
  2602. X
  2603. X    return(t);
  2604. X      }
  2605. X
  2606. Xget_line(fp)
  2607. XFILE    *fp;
  2608. X{
  2609. X    while (1) {
  2610. X        if (NULL == fgets(buf, BUF_SIZE, fp)) {
  2611. X        return(-1);
  2612. X        }
  2613. X        line_no++;
  2614. X        if (*buf != '\n' && *buf != '#') return(1);
  2615. X            /* Skip empty and comment lines */
  2616. X        }
  2617. X    }
  2618. X
  2619. Xskip_comment(fp)
  2620. XFILE    *fp;
  2621. X{
  2622. X    char c;
  2623. X
  2624. X    while ((c = fgetc(fp)) == '#') skip_line(fp);
  2625. X    if (c != '#') ungetc(c, fp);
  2626. X    }
  2627. X
  2628. Xskip_line(fp)
  2629. XFILE    *fp;
  2630. X{
  2631. X    while (fgetc(fp) != '\n') {
  2632. X        if (feof(fp)) return;
  2633. X        }
  2634. X    }
  2635. X
  2636. Xread_epsf(eps)
  2637. X    F_eps          *eps;
  2638. X{
  2639. X    int             nbitmap;
  2640. X    int             bitmapz;
  2641. X    char           *cp;
  2642. X    unsigned char  *mp;
  2643. X    int             n;
  2644. X    int             flag;
  2645. X    char            buf[300];
  2646. X    int             llx, lly, urx, ury;
  2647. X    FILE           *epsf;
  2648. X    register unsigned char *last;
  2649. X    double          fllx, flly, furx, fury;
  2650. X
  2651. X    epsf = fopen(eps->file, "r");
  2652. X    if (epsf == NULL) {
  2653. X    put_msg("Cannot open file: %s", eps->file);
  2654. X    return 0;
  2655. X    }
  2656. X    while (fgets(buf, 300, epsf) != NULL) {
  2657. X    lower(buf);
  2658. X    if (!strncmp(buf, "%%boundingbox", 13)) {
  2659. X        if (sscanf(buf, "%%%%boundingbox: %lf %lf %lf %lf",
  2660. X               &fllx, &flly, &furx, &fury) < 4) {
  2661. X        put_msg("Bad EPS bitmap file: %s", eps->file);
  2662. X        fclose(epsf);
  2663. X        return 0;
  2664. X        }
  2665. X          llx= floor(fllx);
  2666. X          lly= floor(flly);
  2667. X          urx= ceil(furx);
  2668. X          ury= ceil(fury);
  2669. X        break;
  2670. X    }
  2671. X    }
  2672. X
  2673. X    eps->hw_ratio = (float) (ury - lly) / (float) (urx - llx);
  2674. X
  2675. X    eps->bitmap = NULL;
  2676. X    eps->bit_size.x = 0;
  2677. X    eps->bit_size.y = 0;
  2678. X
  2679. X    eps->pix_rotation = 0;
  2680. X    eps->pix_width = 0;
  2681. X    eps->pix_height = 0;
  2682. X
  2683. X    if (ury - lly <= 0 || urx - llx <= 0) {
  2684. X    put_msg("Bad values in EPS bitmap bounding box");
  2685. X    }
  2686. X    bitmapz = 0;
  2687. X
  2688. X    /* look for a preview bitmap */
  2689. X    while (fgets(buf, 300, epsf) != NULL) {
  2690. X    lower(buf);
  2691. X    if (!strncmp(buf, "%%beginpreview", 14)) {
  2692. X        sscanf(buf, "%%%%beginpreview: %d %d %d",
  2693. X           &eps->bit_size.x, &eps->bit_size.y, &bitmapz);
  2694. X        break;
  2695. X    }
  2696. X    }
  2697. X
  2698. X    if (eps->bit_size.x > 0 && eps->bit_size.y > 0 && bitmapz == 1) {
  2699. X    nbitmap = (eps->bit_size.x + 7) / 8 * eps->bit_size.y;
  2700. X    eps->bitmap = (unsigned char *) malloc(nbitmap);
  2701. X    if (eps->bitmap == NULL)
  2702. X        fprintf(stderr, "could not allocate %d bytes of memory\n", nbitmap);
  2703. X    }
  2704. X    /* read for a preview bitmap */
  2705. X    if (eps->bitmap != NULL) {
  2706. X    mp = eps->bitmap;
  2707. X    bzero(mp, nbitmap);    /* init bitmap to zero */
  2708. X    last = eps->bitmap + nbitmap;
  2709. X    flag = 1;
  2710. X    while (fgets(buf, 300, epsf) != NULL && mp < last) {
  2711. X        lower(buf);
  2712. X        if (!strncmp(buf, "%%endpreview", 12) ||
  2713. X        !strncmp(buf, "%%endimage", 10))
  2714. X        break;
  2715. X        cp = buf;
  2716. X        if (*cp != '%')
  2717. X        break;
  2718. X        cp++;
  2719. X        while (*cp != '\0') {
  2720. X        if (isxdigit(*cp)) {
  2721. X            n = hex(*cp);
  2722. X            if (flag) {
  2723. X            flag = 0;
  2724. X            *mp = n << 4;
  2725. X            } else {
  2726. X            flag = 1;
  2727. X            *mp = *mp + n;
  2728. X            mp++;
  2729. X            if (mp >= last)
  2730. X                break;
  2731. X            }
  2732. X        }
  2733. X        cp++;
  2734. X        }
  2735. X    }
  2736. X    }
  2737. X    fclose(epsf);
  2738. X    return 1;
  2739. X}
  2740. X
  2741. Xint
  2742. Xhex(c)
  2743. X    char            c;
  2744. X{
  2745. X    if (isdigit(c))
  2746. X    return (c - 48);
  2747. X    else
  2748. X    return (c - 87);
  2749. X}
  2750. X
  2751. Xlower(buf)
  2752. X    char           *buf;
  2753. X{
  2754. X    while (*buf) {
  2755. X    if (isupper(*buf))
  2756. X        *buf = (char) tolower(*buf);
  2757. X    buf++;
  2758. X    }
  2759. X}
  2760. END_OF_FILE
  2761. if test 20800 -ne `wc -c <'fig2dev/read.c'`; then
  2762.     echo shar: \"'fig2dev/read.c'\" unpacked with wrong size!
  2763. fi
  2764. # end of 'fig2dev/read.c'
  2765. fi
  2766. echo shar: End of archive 4 \(of 7\).
  2767. cp /dev/null ark4isdone
  2768. MISSING=""
  2769. for I in 1 2 3 4 5 6 7 ; do
  2770.     if test ! -f ark${I}isdone ; then
  2771.     MISSING="${MISSING} ${I}"
  2772.     fi
  2773. done
  2774. if test "${MISSING}" = "" ; then
  2775.     echo You have unpacked all 7 archives.
  2776.     rm -f ark[1-9]isdone
  2777. else
  2778.     echo You still need to unpack the following archives:
  2779.     echo "        " ${MISSING}
  2780. fi
  2781. ##  End of shell archive.
  2782. exit 0
  2783.