home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume12 / hershtools / part04 < prev    next >
Encoding:
Internet Message Format  |  1987-10-24  |  32.6 KB

  1. Subject:  v12i043:  Hershey font manipulation tools and data, Part04/05
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rs@uunet.UU.NET
  5.  
  6. Submitted-by: lee@uhccux.UUCP (Greg Lee)
  7. Posting-number: Volume 12, Issue 43
  8. Archive-name: hershtools/part04
  9.  
  10. # This is a shell archive.  Remove anything before this line
  11. # then unpack it by saving it in a file and typing "sh file"
  12. # (Files unpacked will be owned by you and have default permissions).
  13. # This archive contains the following files:
  14. #    ./Makefile
  15. #    ./README
  16. #    ./eplot.c
  17. #
  18. if `test ! -s ./Makefile`
  19. then
  20. echo "writing ./Makefile"
  21. sed 's/^X//' > ./Makefile << '\Rogue\Monster\'
  22. X#    Makefile 1.0    6/5/87
  23. X#
  24. X# make file for font programs
  25. X#
  26. X#
  27. X
  28. XCFLAGS=    -O -s
  29. XOBJS=    termio.o
  30. XSOURCES= termio.c eplot.c hplot.c
  31. X
  32. Xall:    eplot hplot htrans
  33. X
  34. Xhtrans:    htrans.c
  35. X    ${CC} ${CFLAGS} -o htrans htrans.c
  36. X
  37. Xeplot:    ${OBJS} eplot.o
  38. X    ${CC} ${CFLAGS} -o eplot ${OBJS} eplot.o -ltermlib
  39. X
  40. Xhplot:    ${OBJS} hplot.o
  41. X    ${CC} ${CFLAGS} -o hplot ${OBJS} hplot.o -ltermlib
  42. X
  43. Xeplot.o:    eplot.c
  44. X    ${CC} ${CFLAGS} -c eplot.c
  45. X
  46. Xhplot.o:    hplot.c vfont.c
  47. X    ${CC} ${CFLAGS} -c hplot.c
  48. X
  49. X${OBJS}:    termio.h
  50. X
  51. Xclean:
  52. X    rm -f *.o
  53. X
  54. \Rogue\Monster\
  55. else
  56.   echo "will not over write ./Makefile"
  57. fi
  58. if [ `wc -c ./Makefile | awk '{printf $1}'` -ne 492 ]
  59. then
  60. echo `wc -c ./Makefile | awk '{print "Got " $1 ", Expected " 492}'`
  61. fi
  62. if `test ! -s ./README`
  63. then
  64. echo "writing ./README"
  65. sed 's/^X//' > ./README << '\Rogue\Monster\'
  66. XHere are some programs for making use of the Hershey character data.  Eplot
  67. Xand hplot allow the editing of vector fonts and the creation of other fonts
  68. Xfrom them -- vfont format raster fonts, PostScript analytic fonts -- as
  69. Xwell as tfm files for TeX.  The file format for vector fonts is idiosyncratic,
  70. XI'm sorry to say.  I have not had access to the Hershey data in the usual
  71. Xformats.  I have included two sets of four files each containing the Hershey
  72. Xsimplex and triplex Roman characters in the format required for these
  73. Xprograms -- these are sr?.chr and tr?.chr, where the ? is c for capital
  74. Xletters, s for small letters, d for digits, or p for punctuation.  Just
  75. Xin case anyone has the Hershey data in the compressed form I have it in
  76. X(similar the National Bureau of Standards form) I included the utility
  77. Xhtrans, which converts from the compressed form to my form.  (By the way,
  78. XI would really like to have the Hershey data for oriental characters.)
  79. X
  80. XThese programs have compiled ok in the Ultrix 1.2 and Sun 3.0 versions of
  81. XBSD 4.2.
  82. X
  83. XParts of the source (termio.c, termio.h) were taken from the Xum package
  84. Xdistributed in net.sources by John Paul O'Brien, Nova University, Fort
  85. XLauderdale, Florida, {allegra, ucf-cs, usfvax2}!novavax!john, and (vfont.c) from
  86. Xthe Hfont package by William LeFebvre, Department of Computer Science,
  87. XRice University, <phil@Rice.edu>.  These appear to be in the public domain.
  88. XI am grateful to the above for the use of their code, and I hereby place
  89. Xthe rest of the code and documents for these programs in the public domain.
  90. X
  91. XGreg Lee, Sept 12, 1987.
  92. XU.S.mail: 562 Moore Hall, Dept. of Linguistics, Univ. of Hawaii, HONO, HI 96822
  93. XINTERNET: lee@uhccux.uhcc.hawaii.edu
  94. XUUCP:     {ihnp4,dcdwest,ucbvax}!sdcsvax!nosc!uhccux!lee
  95. XBITNET:   lee%uhccux.uhcc.hawaii.edu@rutgers.edu
  96. \Rogue\Monster\
  97. else
  98.   echo "will not over write ./README"
  99. fi
  100. if [ `wc -c ./README | awk '{printf $1}'` -ne 1811 ]
  101. then
  102. echo `wc -c ./README | awk '{print "Got " $1 ", Expected " 1811}'`
  103. fi
  104. if `test ! -s ./eplot.c`
  105. then
  106. echo "writing ./eplot.c"
  107. sed 's/^X//' > ./eplot.c << '\Rogue\Monster\'
  108. X
  109. X#include <stdio.h>
  110. X#define TRUE 1
  111. X#define FALSE 0
  112. X
  113. Xextern char *term_name;
  114. Xchar w300 = FALSE;
  115. X
  116. X#define STSIZE    32000
  117. X#define KEEPSIZE 80
  118. X
  119. X#define getnam(nm) cook_tty(tty_fid);scanf("%s",nm);uncook_tty(tty_fid);
  120. X
  121. Xint    tty_fid;
  122. X
  123. Xchar penstate, debug, /*ibuf[BUFSIZ],*/ ins[90];
  124. XFILE *ibuf;
  125. Xint cnum;
  126. X
  127. Xint itempt, co1, co2, co3, lebear, ribear, x, y;
  128. Xint deltax, deltay, xinc, yinc;
  129. Xint lx,llx,ly,lly, cx,ccx,cy,ccy, x1,x2,y1,y2, a1,a2,d1,d2, i1,i2;
  130. Xint minx, miny, maxx, maxy, base, obase, xheight, ytop, ybot, serifs;
  131. Xint begy,begx;
  132. Xchar itemtype, letter, linelet, retrace, openflag, lighten, hairflag;
  133. X
  134. Xint xheavy, xlight, yheavy, ylight, penwidth, pxangle, pyangle,
  135. X    squarepen, shading, xshade, yshade;
  136. X
  137. X
  138. X#define ESC    27
  139. X#define RIGHTCOL 79
  140. X#define LEFTCOL  0
  141. X#define BOTROW  23
  142. X
  143. X#define PRPTNL  2
  144. X
  145. X#define BLACK    '1'
  146. X#define BLUE    '2'
  147. X#define GREEN    '3'
  148. X#define CYAN    '4'
  149. X#define RED    '5'
  150. X#define MAGENTA '6'
  151. X#define YELLOW    '7'
  152. X#define WHITE    '8'
  153. X
  154. X#define UPPRDOT    ','
  155. X#define LOWRDOT    '-'
  156. X#define BOTHDOT '7'
  157. X#define NODOT    ' '
  158. Xchar upperdot=UPPRDOT, lowerdot=LOWRDOT, bothdot=BOTHDOT;
  159. X
  160. Xchar    currlet, reallet;
  161. Xunsigned currlines[96];
  162. Xunsigned xpt, penplace,oldpplace, lastplace;
  163. X
  164. X
  165. Xchar    cmd, currch, cch, cbyte, cbyteo, mxflag;
  166. Xint    col, row, xpos, ypos, currlen;
  167. Xchar    erow,ecol, pxc,pyc, penchar;
  168. X
  169. Xchar    ckeep[6][KEEPSIZE], gxoff, gyoff, ib;
  170. X
  171. Xint i, fd;
  172. Xchar ftname[30];
  173. Xchar  duplflag;
  174. X
  175. X/******************/
  176. X
  177. X
  178. X/* char obuf[BUFSIZ];*/
  179. XFILE *obuf;
  180. Xint cocnt;
  181. Xunsigned char sletter;
  182. Xunsigned svpt;
  183. X
  184. X/***************/
  185. X
  186. Xchar gr[100][100];
  187. X
  188. Xchar *_stsz;
  189. Xunsigned stsize, cindex[128], storept;
  190. Xunsigned char psxoff[128], pswidth[128];
  191. Xchar store[STSIZE];
  192. X
  193. X/*****************/
  194. X
  195. Xsavechr()
  196. X{    char fname[30];
  197. X
  198. X    if (storept< 2) {printf("nothing to save\r\n"); return; }
  199. X
  200. X    strcpy(fname,ftname);
  201. X    strcat(fname,".chr");
  202. X    if ((obuf = fopen(fname, "w")) == NULL) exit(1);
  203. X
  204. X    fprintf(obuf, "Height(%d)\n", ytop);
  205. X    if (xheight) fprintf(obuf, "x Height(%d)\n", xheight);
  206. X    if (base) fprintf(obuf, "Base(%d)\n", base);
  207. X
  208. X
  209. X    cocnt = 0;
  210. X
  211. X    for (sletter = 0; sletter < 128 ; sletter++)
  212. X    {
  213. X        if (!(svpt = cindex[sletter])) continue;
  214. X        /*if (kbhit()) return;*/
  215. X
  216. X        if (sletter < ' ') fprintf(obuf, "^%c': ", sletter);
  217. X        else fprintf(obuf, "'%c': ", sletter);
  218. X
  219. X        while (!(dspc(store[svpt], store[svpt+1]))) svpt +=2;
  220. X
  221. X    }
  222. X
  223. X    fprintf(obuf, "\n");
  224. X    fclose(obuf);
  225. X
  226. X}
  227. X
  228. Xdspc(b1, b2)
  229. Xchar b1, b2;
  230. X{
  231. X    co1 = b1 - 64; co2 = b2 - 64;
  232. X
  233. X    if (co1 == -64 && co2 == -64)
  234. X    {    fprintf(obuf," End Char\n");
  235. X        cocnt = 0;
  236. X        return(TRUE);
  237. X    }
  238. X
  239. X
  240. X    if (co1 == -64)
  241. X    {    if (!co2) fprintf(obuf," Pen Up\n    ");
  242. X        else if (b2 == 'H') fprintf(obuf,"\n   Hair ");
  243. X        cocnt = 0;
  244. X    }
  245. X    else
  246. X    {    if (cocnt >8) {cocnt = 0; fprintf(obuf,"\n    ");}
  247. X
  248. X        fprintf(obuf,"(%d,%d)", co1,co2);
  249. X        cocnt++;
  250. X    }
  251. X
  252. X    return(FALSE);
  253. X}
  254. X
  255. X
  256. X
  257. Xsaveasm()
  258. X{    char fname[30];
  259. X
  260. X    if (storept< 2) {printf("nothing to save\r\n"); return; }
  261. X
  262. X    strcpy(fname,ftname);
  263. X    strcat(fname,".a");
  264. X    if ((obuf = fopen(fname, "w")) == NULL) exit(1);
  265. X
  266. X    fprintf(obuf, "\n\tsection  font,data\n");
  267. X    fprintf(obuf, "\tdc.w %d,%d\n", ytop, base);
  268. X    fprintf(obuf, "\txdef\t%s\n%s\n\n", ftname, ftname);
  269. X    fprintf(obuf, "\tinclude\t\"chrdir\"\n\n");
  270. X    fprintf(obuf, ".h20\n\tdc.b -6,6\n  endchar\n");
  271. X
  272. X
  273. X
  274. X    for (sletter = 33; sletter < 128 ; sletter++)
  275. X    {
  276. X
  277. X        if ( (sletter >= 'A' && sletter <= 'Z')
  278. X          || (sletter >= 'a' && sletter <= 'z') )
  279. X            fprintf(obuf, ".%c\n", sletter);
  280. X        else if (sletter >= '0' && sletter <= '9')
  281. X            fprintf(obuf, ".d%c\n", sletter);
  282. X        else fprintf(obuf, ".h%02.2x\n", sletter);
  283. X
  284. X        if (!(svpt = cindex[sletter]))
  285. X        {    fprintf(obuf, "\tdc.b 0,0\n  endchar\n");
  286. X            continue;
  287. X        }
  288. X
  289. X
  290. X        minx = 63; maxx =  -63;
  291. X        while ( (x=store[svpt]) + (y=store[svpt+1]) )
  292. X        {    svpt += 2;
  293. X            if (!(x)) continue;
  294. X            minx = min(minx, x-64);
  295. X            maxx = max(maxx, x-64);
  296. X        }
  297. X        fprintf(obuf, "\tdc.b %d,%d\n", minx-lebear, maxx+ribear);
  298. X
  299. X        svpt = cindex[sletter];
  300. X
  301. X        while (!(dspca(store[svpt], store[svpt+1]))) svpt +=2;
  302. X
  303. X    }
  304. X
  305. X    fprintf(obuf, "\n\tend\n");
  306. X    fclose(obuf);
  307. X
  308. X}
  309. X
  310. Xdspca(b1, b2)
  311. Xchar b1, b2;
  312. X{
  313. X    co1 = b1 - 64; co2 = b2 - 64;
  314. X
  315. X    if (co1 == -64 && co2 == -64)
  316. X    {    fprintf(obuf,"  endchar\n");
  317. X        return(TRUE);
  318. X    }
  319. X
  320. X
  321. X    if (co1 == -64)
  322. X    {    if (!co2) fprintf(obuf,"  penup\n");
  323. X        /* else if (b2 != 'H')
  324. X           fprintf(obuf,"\tdc.b -%d,%d\n", co2,co2); */
  325. X    }
  326. X    else
  327. X    {
  328. X        fprintf(obuf,"\tdc.b %d,%d\n", co1,co2);
  329. X    }
  330. X
  331. X    return(FALSE);
  332. X}
  333. X
  334. X
  335. X
  336. Xsaveps()
  337. X{    char fname[30];
  338. X    char *nameoflet();
  339. X    int letcount;
  340. X    int fbb[4];
  341. X
  342. X    if (storept< 2) {printf("nothing to save\r\n"); return; }
  343. X
  344. X    strcpy(fname,ftname);
  345. X    strcat(fname,".ps");
  346. X    if ((obuf = fopen(fname, "w")) == NULL) exit(1);
  347. X
  348. X    fprintf(obuf, "10 dict dup begin\n");
  349. X    fprintf(obuf, "/FontType 3 def\n");
  350. X    fprintf(obuf, "/FontMatrix [.03 0 0 .03 0 0] def\n");
  351. X    fprintf(obuf, "/Encoding 256 array def\n");
  352. X    fprintf(obuf, "0 1 255 {Encoding exch/.notdef put} for\n");
  353. X    fprintf(obuf, "Encoding\n");
  354. X    for (sletter = 0; sletter < 128 ; sletter++)
  355. X    {    if (!(svpt = cindex[sletter])) continue;
  356. X        fprintf(obuf, "dup %d /%s put\n", sletter, nameoflet(sletter));
  357. X    }
  358. X    fprintf(obuf, "pop\n");
  359. X
  360. X#define HLWIDTH 1
  361. X    letcount = 0;
  362. X    for (sletter = 0; sletter < 128 ; sletter++)
  363. X    {    if (!(svpt = cindex[sletter])) continue;
  364. X        letcount++;
  365. X    }
  366. X
  367. X    fprintf(obuf, "/BBox %d dict def\nBBox begin\n", letcount+1);
  368. X    fprintf(obuf, " /.notdef [0 0 0 0] def\n");
  369. X    fbb[0] = fbb[1] = 63; fbb[2] = fbb[3] = -63;
  370. X    for (sletter = 0; sletter < 128 ; sletter++)
  371. X    {    if (!(svpt = cindex[sletter])) continue;
  372. X        co2 = minx = miny = 63; co3 = maxx = maxy = -63;
  373. X        while ( (x=store[svpt]) + (y=store[svpt+1]) )
  374. X        {    svpt += 2;
  375. X            if (!(co1=x)) continue;
  376. X            if (i1 && i2) co1 += fadjust(-base+y-64,i1,i2)-50;
  377. X            co2 = min(co2, co1-64);
  378. X            minx = min(minx, x-64);
  379. X            miny = min(miny, y-64);
  380. X            co3 = max(co3, co1-64);
  381. X            maxx = max(maxx, x-64);
  382. X            maxy = max(maxy, y-64);
  383. X        }
  384. X        psxoff[sletter] = lebear - minx;
  385. X        pswidth[sletter] = lebear + maxx - minx + 1 + ribear;
  386. X        fprintf(obuf, " /%s [%d %d %d %d] def\n", nameoflet(sletter),
  387. X            co2 + psxoff[sletter] - HLWIDTH,
  388. X            -maxy + base - HLWIDTH,
  389. X            co3 + psxoff[sletter] + HLWIDTH,
  390. X            -miny + base + HLWIDTH);
  391. X        fbb[0] = min(fbb[0], co2 + psxoff[sletter] - HLWIDTH);
  392. X        fbb[1] = min(fbb[1], -maxy + base - HLWIDTH);
  393. X        fbb[2] = max(fbb[2], co3 + psxoff[sletter] + HLWIDTH);
  394. X        fbb[3] = max(fbb[3], -miny + base + HLWIDTH);
  395. X    }
  396. X    fprintf(obuf, "end\n");
  397. X    fprintf(obuf, "/FontBBox [%d %d %d %d] def\n",fbb[0],fbb[1],
  398. X                fbb[2],fbb[3]);
  399. X
  400. X    fprintf(obuf, "/Metrics %d dict def\nMetrics begin\n", letcount+1);
  401. X    fprintf(obuf, " /.notdef 0 def\n");
  402. X    for (sletter = 0; sletter < 128 ; sletter++)
  403. X    {    if (!(svpt = cindex[sletter])) continue;
  404. X        fprintf(obuf, " /%s %d def\n", nameoflet(sletter),
  405. X            pswidth[sletter]);
  406. X    }
  407. X    fprintf(obuf, "end\n");
  408. X
  409. X
  410. X    fprintf(obuf, "/CharacterDefs %d dict def\nCharacterDefs begin\n",
  411. X        letcount+1);
  412. X    fprintf(obuf, "/.notdef {} def\n");
  413. X    cocnt = 0;
  414. X    for (sletter = 0; sletter < 128 ; sletter++)
  415. X    {    if (!(svpt = cindex[sletter])) continue;
  416. X        fprintf(obuf, "/%s\n { newpath\n   ", nameoflet(sletter));
  417. X        penstate = 0;
  418. X        while (!(dsps(store[svpt], store[svpt+1]))) svpt +=2;
  419. X    }
  420. X    fprintf(obuf, "end\n");
  421. X
  422. X    pbuildchar();
  423. X
  424. X    fprintf(obuf, "/UniqueID %d def\n\nend\n", ftname[0]);
  425. X
  426. X    fprintf(obuf, "/%s exch definefont pop\n", ftname);
  427. X
  428. X    fclose(obuf);
  429. X
  430. X}
  431. X
  432. X
  433. Xdsps(b1, b2)
  434. Xchar b1, b2;
  435. X{
  436. X    co1 = b1 - 64; co2 = b2 - 64;
  437. X
  438. X    if (co1 == -64 && co2 == -64)
  439. X    {
  440. X        fprintf(obuf, " stroke } def\n");
  441. X        cocnt = 0;
  442. X        return(TRUE);
  443. X    }
  444. X
  445. X
  446. X    if (co1 == -64)
  447. X    {    if (!co2) penstate = 0;
  448. X        /*else if (b2 == 'H') fprintf(obuf,"\n   Hair ");*/
  449. X    }
  450. X    else
  451. X    {    if (cocnt >3) {cocnt = 0; fprintf(obuf,"\n   ");}
  452. X
  453. X        if (i1 && i2) co1 += fadjust(-base+co2,i1,i2) - 50;
  454. X
  455. X        fprintf(obuf," %d %d ", co1+psxoff[sletter],base-co2);
  456. X        if (penstate) fprintf(obuf,"lineto");
  457. X        else fprintf(obuf,"moveto");
  458. X        penstate = 1;
  459. X        cocnt++;
  460. X    }
  461. X
  462. X    return(FALSE);
  463. X}
  464. X
  465. Xchar *nameoflet(c)
  466. Xchar c;
  467. X{ static char *npc[] = {
  468. X    "A", "ctl@",
  469. X    "esc", "fs", "gs", "rs", "us",
  470. X    "space", "exclam", "quotedbl", "numbersign", "dollar",
  471. X    "percent", "ampersand", "quoteright", "parenleft",
  472. X    "parenright", "asterisk", "plus", "comma", "hyphen",
  473. X    "period", "slash",
  474. X    "zero", "one", "two", "three", "four", "five", "six", "seven",
  475. X    "eight", "nine", "colon", "semicolon", "less", "equal",
  476. X    "greater", "question", "at",
  477. X    "bracketleft", "backslash", "bracketright", "asciicircum",
  478. X    "underscore", "quoteleft",
  479. X    "braceleft", "bar", "braceright", "asciitilde", "del"
  480. X  };
  481. X
  482. X    if (c < 0x1B) { npc[1][3] = c + 0x40; return(npc[1]); }
  483. X    if (c < 'A')    return(npc[c - 0x19]);
  484. X    if (c <= 'Z') {    npc[0][0] = c; return(npc[0]); }
  485. X    if (c < 'a')  {    return(npc[c + 39 - 'Z']); }
  486. X    if (c <= 'z') {    npc[0][0] = c; return(npc[0]); }
  487. X    return(npc[c + 45 - 'z']);
  488. X}
  489. X
  490. Xpbuildchar()
  491. X{
  492. X    fprintf(obuf,"/BuildChar\n");
  493. X    fprintf(obuf,"{ 0 begin\n");
  494. X    fprintf(obuf," /char exch def\n /fontdict exch def\n");
  495. X    fprintf(obuf," /charname fontdict /Encoding get char get def\n");
  496. X    fprintf(obuf," fontdict begin\n");
  497. X    fprintf(obuf,"  Metrics charname get 0\n");
  498. X    fprintf(obuf,"  BBox charname get aload pop\n");
  499. X    fprintf(obuf,"  setcachedevice\n");
  500. X    fprintf(obuf,"  %1.1f setlinewidth\n", 2.0*HLWIDTH);
  501. X    fprintf(obuf,"  CharacterDefs charname get exec\n");
  502. X    fprintf(obuf," end\nend\n} def\n");
  503. X    fprintf(obuf,"/BuildChar load 0 3 dict put\n");
  504. X}
  505. X
  506. X
  507. Xsavetfm()
  508. X{    char fname[30];
  509. X    char *nameoflet();
  510. X
  511. X    if (storept< 2) {printf("nothing to save\r\n"); return; }
  512. X
  513. X    strcpy(fname,ftname);
  514. X    strcat(fname,".pl");
  515. X    if ((obuf = fopen(fname, "w")) == NULL) exit(1);
  516. X
  517. X    fprintf(obuf, "\n");
  518. X
  519. X    fprintf(obuf,"(DESIGNSIZE R 10.0)\n");
  520. X    fprintf(obuf,"(COMMENT DESIGNSIZE IS IN POINTS)\n");
  521. X    fprintf(obuf,"(COMMENT OTHER SIZES ARE MULTIPLES OF DESIGNSIZE)\n");
  522. X    fprintf(obuf,"(FONTDIMEN\n");
  523. X    if (i1 && i2)
  524. X        fprintf(obuf,"   (SLANT R %1.6f)\n", (float)-i1/i2);
  525. X    fprintf(obuf,"   (SPACE R 0.357776)\n");
  526. X    fprintf(obuf,"   (STRETCH R 0.153333)\n");
  527. X    fprintf(obuf,"   (SHRINK R 0.1022215)\n");
  528. X    if (xheight)
  529. X    fprintf(obuf,"   (XHEIGHT R %1.6f)\n", (float)xheight/33.33);
  530. X    else
  531. X    fprintf(obuf,"   (XHEIGHT R 0.430555)\n");
  532. X    fprintf(obuf,"   (QUAD R 1.022217)\n");
  533. X    fprintf(obuf,"   (EXTRASPACE R 0.1022215)\n");
  534. X    fprintf(obuf,"   )\n");
  535. X
  536. X    for (sletter = 0; sletter < 128 ; sletter++)
  537. X    {    if (!(svpt = cindex[sletter])) continue;
  538. X        fprintf(obuf,"(CHARACTER O %o\n", sletter);
  539. X        minx = miny = 63; co2 = maxx = maxy = -63;
  540. X        while ( (x=store[svpt]) + (y=store[svpt+1]) )
  541. X        {    svpt += 2;
  542. X            if (!(co1=x)) continue;
  543. X            if (i1 && i2) co1 += fadjust(-base+y-64,i1,i2)-50;
  544. X            minx = min(minx, x-64);
  545. X            miny = min(miny, y-64);
  546. X            maxx = max(maxx, x-64);
  547. X            maxy = max(maxy, y-64);
  548. X            co2 = max(co2, co1-64);
  549. X        }
  550. X        if ((x = lebear + maxx - minx + 1 + ribear) > 0)
  551. X          fprintf(obuf, "   (CHARWD R %1.6f)\n", (float)x/33.33);
  552. X        if ((x = -miny + base + 1 + HLWIDTH) > 0)
  553. X          fprintf(obuf, "   (CHARHT R %1.6f)\n", (float)x/33.33);
  554. X        if ((x = maxy - base ) > 0)
  555. X          fprintf(obuf, "   (CHARDP R %1.6f)\n", (float)x/33.33);
  556. X        if ((x = co2 - maxx ) > 0)
  557. X          fprintf(obuf, "   (CHARIC R %1.6f)\n", (float)x/33.33);
  558. X        fprintf(obuf, "   )\n");
  559. X    }
  560. X
  561. X    fclose(obuf);
  562. X
  563. X}
  564. X
  565. X/******************/
  566. X
  567. Xmain()
  568. X{    char sp;
  569. X    char key(), conin();
  570. X/* stuff from xum */
  571. X
  572. X    if (term_setup() != 0)
  573. X    {
  574. X        printf("Warning: This program needs to have the\n");
  575. X        printf("TERM environment variable setup before\n");
  576. X        printf("being run. Make sure this is done before\n");
  577. X        printf("executing eplot again (set yourself up like\n");
  578. X        printf("you were going to use vi).\n");
  579. X        exit(1);
  580. X    }
  581. X
  582. X    printf("Terminal is a %s.\n", term_name);
  583. X    if (!strcmp(term_name, "w300")) w300 = TRUE;
  584. X    if (!w300)
  585. X    {    upperdot='^'; lowerdot='j'; bothdot='g';
  586. X    }
  587. X
  588. X    tty_fid = raw_tty("/dev/tty");
  589. X    if (tty_fid == -1)
  590. X    {
  591. X        printf("Error opening terminal for raw i/o\n");
  592. X        exit(1);
  593. X    }
  594. X
  595. X
  596. X    debug = 0;
  597. X
  598. X    stsize = STSIZE;
  599. X
  600. X    printf("\r\nEplot - (c) Greg Lee, Oct. 1984\r\n\n");
  601. X
  602. X    base = 9;
  603. X    ytop = 22;
  604. X    lebear = ribear = 2;
  605. X    strcpy(ftname,"Work");
  606. X    letter = currch = duplflag = 0;
  607. X
  608. X    storept = x1 = x2 = y1 = y2 = a2 = d2 = 1;
  609. X    serifs = 2;
  610. X
  611. X    begy = 50-12;    begx = 50-39;
  612. X
  613. X    do
  614. X    {    printf("\r\n");
  615. X        if (currlet > ' ') printf("%c* ",currlet);
  616. X            else printf("^%c* ",currlet+64);
  617. X        cmd = key();
  618. X    switch (cmd)
  619. X    {
  620. X    case 'e': edit(); break;
  621. X    case 'c': printf("Create letter? : ");
  622. X          /*scanf("%c",&letter);*/ letter = conin(); putchar(letter);
  623. X          cindex[letter] = storept;
  624. X          sto2(0,0);
  625. X          break;
  626. X    case 'r': rdchr(); break;
  627. X    case 'z': /* setmem(cindex, 128*2+2+stsize, 0);*/
  628. X          bzero(cindex, 128*sizeof(int));
  629. X          bzero(store, STSIZE);
  630. X          storept = 1;
  631. X          printf("zapped");
  632. X          break;
  633. X    case 'p': plotlet(); break;
  634. X    case 'v': showgr(); showbits(); break;
  635. X    case 'b': gvar("Base",&base); break;
  636. X    case 'h': gvar("Height",&ytop); break;
  637. X    case 'd': gvar("Depth",&ybot); break;
  638. X    case 'f': printf("FACTORS:\r\n");
  639. X          gvar("X1",&x1);
  640. X          gvar("X2",&x2);
  641. X          gvar("Y1",&y1);
  642. X          gvar("Y2",&y2);
  643. X          break;
  644. X    case 't': duplflag = !duplflag;
  645. X          chkdupl();
  646. X          if (!duplflag) printf("not "); printf("tall");
  647. X          break;
  648. X    case 'L': printf("LINE STYLE:\r\n");
  649. X          gvar("X Heavy",&xheavy);
  650. X          gvar("X Light",&xlight);
  651. X          gvar("Y Heavy",&yheavy);
  652. X          gvar("Y Light",&ylight);
  653. X          break;
  654. X    case 'I': printf("ITALIC:\r\n");
  655. X          gvar("I1",&i1);
  656. X          gvar("I2",&i2);
  657. X          break;
  658. X    case 'B': printf("BEARINGS:\r\n");
  659. X          gvar("Left",&lebear);
  660. X          gvar("Right",&ribear);
  661. X          break;
  662. X    case 'S': gvar("serifs",&serifs);
  663. X          break;
  664. X    case 'n': printf(".chr name(%s) = ",ftname);
  665. X          getnam(ftname);
  666. X          /*strcat(ftname,".chr");*/
  667. X          break;
  668. X    case 's': savechr(); break;
  669. X    case 'a': saveasm(); break;
  670. X    case 'P': saveps(); break;
  671. X    case 'T': savetfm(); break;
  672. X    case '?': cmdinfo();
  673. X          printf("\r\nstore room %d",
  674. X            stsize-storept);
  675. X          break;
  676. X    case '\\': printf("debug");
  677. X          if (debug) printf(" off");
  678. X          debug = !debug;
  679. X    case 'q':
  680. X    case 'x': break;
  681. X    default: conout('?'); printf("%c cmd %d?",cmd,cmd); break;
  682. X    }
  683. X    }
  684. X    while (cmd != 'x' && cmd != 'q');
  685. X
  686. X    reset_tty(tty_fid);
  687. X
  688. X}
  689. X
  690. Xcmdinfo()
  691. X{
  692. X    printf("\r\nRead   Plot      Name .chr   mag.Factors\r\n");
  693. X    printf("Zap    Edit      Save .chr  ^Line style\r\n");
  694. X    printf("Base   Vdisplay ^Serifs     ^Ps file\r\n");
  695. X    printf("Height eXit/Quit Tall       ^Tfm file\r\n");
  696. X    printf("Depth ^Italic   ^Bearings    Asm file\r\n");
  697. X}
  698. X
  699. X
  700. Xgvar(s,v)
  701. Xchar *s; int *v;
  702. X{    char is[80];
  703. X
  704. X    printf(s);
  705. X    printf("(%d) = ", *v);
  706. X    cook_tty(tty_fid);
  707. X    gets(is);
  708. X    if (is[0] >= '0' && is[0] <= '9') sscanf(is,"%d",v);
  709. X    uncook_tty(tty_fid);
  710. X}
  711. X
  712. Xplotlet()
  713. X{
  714. X    printf("Plot a letter? : ");
  715. X    /*scanf("%c", &letter);*/
  716. X    letter = 0x7f & getchar(); putchar(letter);
  717. X    currlet = letter;
  718. X    lplot(letter);
  719. X}
  720. X
  721. X
  722. Xedit()
  723. X{    /*if (!currlet) plotlet();
  724. X    else*/ lplot(currlet);
  725. X
  726. X    penplace = 0;
  727. X
  728. X    edscr();
  729. X
  730. X    gxy(0,22);
  731. X}
  732. X
  733. Xdispline(row)
  734. Xchar row;
  735. X{
  736. X    y = begy + row;
  737. X
  738. X    for (x = begx; x <= begx+79; x++)
  739. X        if (gr[x][y])
  740. X        {    at(x,y);
  741. X            gxy(ecol, erow);
  742. X            putchar(gr[x][y]);
  743. X        }
  744. X}
  745. X
  746. X
  747. Xat(x,y)
  748. Xint x,y;
  749. X{    x -= begx;    y -= begy;
  750. X    if (x >= 0 && x <= 79 && y >= 0 && y <= 23)
  751. X    { ecol = x; erow = y; return(TRUE); }
  752. X    return(FALSE);
  753. X
  754. X}
  755. X
  756. Xrdchr()
  757. X{    char fname[20];
  758. X
  759. X
  760. X    printf(".chr file?  : ");
  761. X    getnam(fname);
  762. X    if (!fname[0]) return;
  763. X    strcat(fname, ".chr");
  764. X    if ((ibuf = fopen(fname, "r")) == NULL) return;
  765. X
  766. X    while (fgets(ins, 90, ibuf))
  767. X    {    itempt = 0;
  768. X        while (itemtype = scnitem())
  769. X        switch(itemtype)
  770. X        {
  771. X        case 1: if (debug) printf("\r\nCnum %d: ", cnum);
  772. X            letter = 0;
  773. X            break;
  774. X        case 2: if (debug) printf("\r\nChar '%c': ", letter);
  775. X            cindex[letter] = storept;
  776. X            break;
  777. X        case 3: if (debug) printf("(%d,%d)", co1, co2);
  778. X
  779. X            if (i1 && i2) co1 += fadjust(co2,i1,i2)-50;
  780. X
  781. X            co1 = fadjust(co1,x1,x2) - 50;
  782. X            co2 = fadjust(co2,y1,y2) - 50;
  783. X            sto2(co1 + 64, co2 + 64);
  784. X            break;
  785. X        case 4: if (debug) printf(" Pen Up\r\n   ");
  786. X            sto2(0, 64);
  787. X            break;
  788. X        case 5: if (debug) printf(" End Char");
  789. X            sto2(0, 0);
  790. X            break;
  791. X        case 6: if (debug) printf(" Hair");
  792. X            sto2(0, 'H');
  793. X            break;
  794. X        case 65:/* if (debug) printf(" Bounds (-%d,%d)", co1, co2);
  795. X            co2 = fadjust(co2,x1,x2) - 50;
  796. X            sto2(0, co2 + 64);
  797. X            break; */
  798. X        case 66:if (debug) printf("(ignored)");
  799. X            break;
  800. X        }
  801. X    }
  802. X
  803. X
  804. X    fclose(ibuf);
  805. X
  806. X    printf("\r\nUsed %u of buffer (%d remaining).", storept,stsize-storept);
  807. X}
  808. X
  809. Xsto2(x,y)
  810. Xchar x, y;
  811. X{
  812. X    if (letter < 0 || letter > 127) return;
  813. X    if (storept > stsize - 2) return;
  814. X
  815. X    store[storept++] = x;
  816. X    store[storept++] = y;
  817. X
  818. X}
  819. X
  820. Xscnitem()
  821. X{    char dc;
  822. X
  823. X    while (ins[itempt] == ' ' || ins[itempt] == '\t') itempt++;
  824. X
  825. X    if (!ins[itempt]) return(0);
  826. X    if (ins[itempt] == '\n') return(0);
  827. X
  828. X    if (sscanf(ins + itempt, "%d:", &cnum))
  829. X    {    match(':');    return(1); }
  830. X
  831. X    if (sscanf(ins + itempt, "'%c':", &letter))
  832. X    {    match(':');    return(2); }
  833. X
  834. X    if (sscanf(ins + itempt, "^%c':", &letter))
  835. X    {    match(':');    letter &=  0x1F; return(2); }
  836. X
  837. X    if (sscanf(ins + itempt, "Bounds(%d,%d)", &co1, &co2))
  838. X    {    match(')');    return(65); }
  839. X
  840. X    if (sscanf(ins + itempt, "s(%d,%d)", &co1, &co2))
  841. X    {    match(')');    if (serifs) return(3); return(66); }
  842. X
  843. X    if (sscanf(ins + itempt, "S(%d,%d)", &co1, &co2))
  844. X    {    match(')');    if (serifs>1) return(3); return(66); }
  845. X
  846. X    if (sscanf(ins + itempt, "(%d,%d)", &co1, &co2))
  847. X    {    match(')');    return(3); }
  848. X
  849. X    if (sscanf(ins + itempt, "Pen Up%c", &dc))
  850. X    {    match('p');    return(4); }
  851. X
  852. X    if (sscanf(ins + itempt, "End Char%c", &dc))
  853. X    {    match('r');    return(5); }
  854. X
  855. X    if (sscanf(ins + itempt, "Hair%c", &dc))
  856. X    {    match('r');    return(6); }
  857. X
  858. X    if (sscanf(ins + itempt, "Base(%d)", &base))
  859. X    {    match(')');    obase = base; return(66); }
  860. X
  861. X    if (sscanf(ins + itempt, "x Height(%d)", &xheight))
  862. X    {    match(')');    return(66); }
  863. X
  864. X    if (sscanf(ins + itempt, "Height(%d)", &ytop))
  865. X    {    match(')');    return(66); }
  866. X
  867. X    if (sscanf(ins + itempt, "Depth(%d)", &ybot))
  868. X    {    match(')');    return(66); }
  869. X
  870. X    return(0);
  871. X
  872. X}
  873. X
  874. Xmatch(c)
  875. Xchar c;
  876. X{    while (ins[itempt++] != c);
  877. X}
  878. X
  879. Xlplot(let)
  880. Xchar let;
  881. X{    char c1, c2, penstate;
  882. X
  883. X    currch = let;
  884. X    chkdupl();
  885. X
  886. X    /*if (let <= 1 || let > 127) return;*/
  887. X    if (let < 0 || let > 127) return;
  888. X
  889. X    if (!(xpt = cindex[let])) return;
  890. X    /*if (kbhit()) return;*/
  891. X
  892. X    cleargr();
  893. X
  894. X    for (penstate = 0 ; (c1 = store[xpt++])
  895. X              + (c2 = store[xpt++]) ; )
  896. X    if (!c1)
  897. X    {    penstate = 0;
  898. X        if (c2 == 'H') hairflag = TRUE;
  899. X    }
  900. X
  901. X    else
  902. X    {    lx = cx; ly = cy;
  903. X        cx = c1 - 64; cy = c2 - 64;
  904. X
  905. X        if (penstate) drawline();
  906. X
  907. X        penstate = 1;
  908. X
  909. X    }
  910. X
  911. X    lastplace = xpt - 2;
  912. X
  913. X
  914. X/*    showgr(); */
  915. X
  916. X}
  917. X
  918. Xgoline(here)
  919. Xunsigned here;
  920. X{    char c1, c2;
  921. X
  922. X    if (!here) return(0);
  923. X
  924. X    c1 = store[here];
  925. X    c2 = store[here + 1];
  926. X    if (!c1) return(0);
  927. X
  928. X    penplace = here;
  929. X
  930. X
  931. X    if (at(fadjust(c1-64,x1,x2), fadjust(c2-64,y1,y2)))
  932. X    {    xpos = c1-64;
  933. X        ypos = c2-64;
  934. X        return(TRUE);
  935. X    }
  936. X    return(0);
  937. X}
  938. X
  939. Xchangeit()
  940. X{
  941. X    if (!penplace) return;
  942. X
  943. X    if (!store[penplace]) return;
  944. X
  945. X    store[penplace] = xpos + 64;
  946. X    store[penplace+1] = ypos + 64; 
  947. X}
  948. X
  949. Xdelline()
  950. X{    if (!penplace) return;
  951. X    if (!store[penplace-2] || !store[penplace+2]) delpoint();
  952. X    else
  953. X    {    store[penplace] = 0;
  954. X        store[penplace+1] = 64;
  955. X        penplace = 0;
  956. X        penchar = 0;
  957. X    }
  958. X}
  959. X
  960. X
  961. Xdelpoint()
  962. X{
  963. X    if (!penplace || !store[penplace]) return;
  964. X
  965. X/*    movmem(store+penplace+2, store+penplace, storept-penplace-2);*/
  966. X    bcopy(store+penplace+2, store+penplace, storept-penplace-2);
  967. X    storept -= 2;
  968. X
  969. X    for (letter = 0; letter < 128; letter++)
  970. X        if (cindex[letter] > penplace)
  971. X            cindex[letter] -= 2;
  972. X
  973. X    lastplace -= 2;
  974. X}
  975. X
  976. Xmakeroom(r)
  977. Xint r;
  978. X{
  979. X    bcopy(store+penplace, store+penplace+r, storept-penplace);
  980. X    storept += r;
  981. X
  982. X    for (letter = 0; letter < 128; letter++)
  983. X        if (cindex[letter] > penplace)
  984. X            cindex[letter] += r;
  985. X    lastplace += r;
  986. X}
  987. X
  988. Xnewpoint()
  989. X{    char puflag;
  990. X
  991. X
  992. X    if (!penplace)
  993. X    {
  994. X        penplace = lastplace;
  995. X        makeroom(6);
  996. X
  997. X        store[penplace] = 0;
  998. X        store[penplace+1] = 64;
  999. X        store[penplace+2] = xpos + 64;
  1000. X        store[penplace+3] = ypos + 64; 
  1001. X        store[penplace+4] = xpos + 64;
  1002. X        store[penplace+5] = ypos + 64;
  1003. X
  1004. X        penplace += 4;
  1005. X    }
  1006. X    else
  1007. X    {
  1008. X        if (store[penplace]) penplace += 2;
  1009. X        makeroom(2);
  1010. X        store[penplace] = xpos + 64;
  1011. X        store[penplace+1] = ypos + 64; 
  1012. X
  1013. X    }
  1014. X}
  1015. X
  1016. X
  1017. Xmakehair()
  1018. X{    char prev;
  1019. X
  1020. X
  1021. X    if (!penplace || !store[penplace] || !store[penplace+2]) return;
  1022. X
  1023. X    if (store[penplace-2]) prev = 2; else prev = 0;
  1024. X
  1025. X    penplace += prev;
  1026. X    makeroom(prev + 2);
  1027. X
  1028. X    store[penplace] = 0;
  1029. X    store[penplace+1] = 'H';
  1030. X
  1031. X    if (prev)
  1032. X    {    store[penplace+2] = store[penplace-2];
  1033. X        store[penplace+3] = store[penplace-1];
  1034. X    }
  1035. X
  1036. X    penplace += 2;
  1037. X}
  1038. X
  1039. Xxcontract()
  1040. X{    unsigned pt;
  1041. X    char key();
  1042. X
  1043. X    key();
  1044. X
  1045. X    for (pt = currlines['1'-' ']; store[pt] || store[pt+1]; pt += 2)
  1046. X    if (store[pt])
  1047. X    switch (reallet)
  1048. X    {
  1049. X    case 'r': if (store[pt] > xpos + 64) store[pt]--;
  1050. X          break;
  1051. X    case 'R': if (store[pt] > xpos + 64) store[pt]++;
  1052. X          break;
  1053. X    case 'l': if (store[pt] < xpos + 64) store[pt]++;
  1054. X          break;
  1055. X    case 'L': if (store[pt] < xpos + 64) store[pt]--;
  1056. X          break;
  1057. X    case 'u': if (store[pt+1] < ypos + 64) store[pt+1]++;
  1058. X          break;
  1059. X    case 'U': if (store[pt+1] < ypos + 64) store[pt+1]--;
  1060. X          break;
  1061. X    case 'd': if (store[pt+1] > ypos + 64) store[pt+1]--;
  1062. X          break;
  1063. X    case 'D': if (store[pt+1] > ypos + 64) store[pt+1]++;
  1064. X          break;
  1065. X    default:  break;
  1066. X    }
  1067. X}
  1068. X
  1069. X
  1070. Xsetpos()
  1071. X{
  1072. X    return(at(fadjust(xpos,x1,x2), fadjust(ypos,y1,y2)));
  1073. X}
  1074. X
  1075. X
  1076. Xcleargr()
  1077. X{
  1078. X    clrscrn();
  1079. X    bzero(gr, 100 * 100);
  1080. X    bzero(currlines, 96*2);
  1081. X    linelet = '0';
  1082. X    penwidth = abs(penwidth);
  1083. X}
  1084. X
  1085. X
  1086. Xdrawline()
  1087. X{
  1088. X    if (debug) printf("\r\nDrawing from (%d,%d) to (%d,%d).", lx,ly,cx,cy);
  1089. X
  1090. X    linelet++;
  1091. X    if (linelet > '9' && linelet < 'A') linelet = 'A';
  1092. X    else if (linelet > 'Z' && linelet < 'a') linelet = 'a';
  1093. X    else if (linelet > 'z') linelet = '!'+1;
  1094. X
  1095. X    currlines[linelet-' '] = xpt-4;
  1096. X
  1097. X
  1098. X    if (abs(cy) <= abs(ly))
  1099. X    {    llx = lx;
  1100. X        lly = ly;
  1101. X        ccx = cx;
  1102. X        ccy = cy;
  1103. X    }
  1104. X    else
  1105. X    {    llx = cx;
  1106. X        lly = cy;
  1107. X        ccx = lx;
  1108. X        ccy = ly;
  1109. X    }
  1110. X
  1111. X
  1112. X    x = fadjust(llx,x1,x2);
  1113. X    ccx = fadjust(ccx,x1,x2);
  1114. X    deltax = abs(ccx - x);
  1115. X    if (ccx >= x) xinc = 1; else xinc = -1;
  1116. X
  1117. X    y = fadjust(lly,y1,y2);
  1118. X    ccy = fadjust(ccy,y1,y2);
  1119. X    deltay = abs(ccy - y);
  1120. X    if (ccy >= y) yinc = 1; else yinc = -1;
  1121. X
  1122. X    drawdot();
  1123. X
  1124. X    if (deltax >= deltay) doforx();
  1125. X    else dofory();
  1126. X
  1127. X    hairflag = 0;
  1128. X}
  1129. X
  1130. Xfadjust(u,f1,f2)
  1131. Xint u,f1,f2;
  1132. X{
  1133. X    return( (u * f1 + f2-1)/f2 + 50);
  1134. X}
  1135. X
  1136. X
  1137. X
  1138. Xdrawdot()
  1139. X{
  1140. X    if (x<0 || x>99 || y<0 || y>99) return;
  1141. X    if (gr[x][y]) return;
  1142. X    gr[x][y] = linelet;
  1143. X    if (at(x,y))
  1144. X    {    gxy(ecol,erow);
  1145. X        putchar(linelet);
  1146. X    }
  1147. X}
  1148. X
  1149. X
  1150. X
  1151. Xdoforx()
  1152. X{    int err, i;
  1153. X
  1154. X    err = deltax / 2;
  1155. X    i = deltax;
  1156. X
  1157. X    while (i--)
  1158. X    {    err += deltay;
  1159. X        if (err >= deltax)
  1160. X        {    err -= deltax;
  1161. X            y += yinc;
  1162. X            if (xheavy) drawdot();
  1163. X            if (xlight) {x += xinc; continue;}
  1164. X        }
  1165. X        x += xinc;
  1166. X        if (hairflag && (i&1)) continue;
  1167. X        drawdot();
  1168. X        if (debug) printf("\r\n   @(%d,%d) [%d,%d]", x-50, y-50, x,y);
  1169. X    }
  1170. X    
  1171. X}
  1172. X
  1173. Xdofory()
  1174. X{    int err, i;
  1175. X
  1176. X    gr[x][y] = linelet;
  1177. X
  1178. X    err = deltay / 2;
  1179. X    i = deltay;
  1180. X
  1181. X    while (i--)
  1182. X    {    err += deltax;
  1183. X        if (err >= deltay)
  1184. X        {    err -= deltay;
  1185. X            x += xinc;
  1186. X            if (yheavy) drawdot();
  1187. X            if (ylight) { y+= yinc; continue; }
  1188. X        }
  1189. X        y += yinc;
  1190. X        if (hairflag && (i&1)) continue;
  1191. X        drawdot();
  1192. X        if (debug) printf("\r\n   @(%d,%d) [%d,%d]", x-50, y-50, x,y);
  1193. X    }
  1194. X    
  1195. X}
  1196. X
  1197. Xshowgr()
  1198. X{    int x, y;
  1199. X
  1200. X    minx = miny = 99;
  1201. X    maxx = maxy = 0;
  1202. X
  1203. X    for (y = 0; y < 100; y++)
  1204. X    {    for (x = 0; x < 100; x++)
  1205. X        if (gr[x][y])
  1206. X        {    if (x < minx) minx = x;
  1207. X            if (y < miny) miny = y;
  1208. X            if (x > maxx) maxx = x;
  1209. X            if (y > maxy) maxy = y;
  1210. X        }
  1211. X    }
  1212. X
  1213. X    if (maxx - minx > KEEPSIZE-1) maxx = minx + KEEPSIZE-1;
  1214. X    rdedf();
  1215. X}
  1216. X
  1217. X
  1218. X
  1219. X
  1220. Xchar conin()
  1221. X{    return (0x7f & getchar());
  1222. X}
  1223. X
  1224. Xconout(c)
  1225. Xchar c;
  1226. X{    putchar(c);
  1227. X}
  1228. X
  1229. X
  1230. X
  1231. Xchar key()
  1232. X{    char c;
  1233. X
  1234. X    reallet = c = 0x7f & getchar();
  1235. X    if (c < ' ') c += '@';
  1236. X        else if (c >='A' && c <= 'Z')
  1237. X        c += ' ';
  1238. X    if (c == 'J') return(key());
  1239. X    return(c);
  1240. X}
  1241. X
  1242. X
  1243. Xdtrans(c, upper)
  1244. Xchar c, upper;
  1245. X{    if (c == 0x20 || c == 0x5F) return(c);
  1246. X
  1247. X    if (c >= 0x60) c -= 0x20;
  1248. X    else if (c < 0x20) c += 0x20;
  1249. X
  1250. X    if (upper) return(c);
  1251. X
  1252. X    if (c < 0x40) c -= 0x20;
  1253. X    else c += 0x20;
  1254. X
  1255. X    return(c);
  1256. X}
  1257. X
  1258. Xchkdupl()
  1259. X{
  1260. X/*    duplflag = fix[0] & PRPTNL; */
  1261. X    if (duplflag) currch = dtrans(currch, TRUE);
  1262. X}
  1263. X
  1264. Xrdedf()
  1265. X{    char c;
  1266. X    int lbear, rbear;
  1267. X    int i, y, lasty, dcurrlen;
  1268. X
  1269. X    if  (duplflag)    currch = dtrans(currch, TRUE);
  1270. X
  1271. X    lbear = rbear = 0;
  1272. X
  1273. X    bzero(ckeep, 6*KEEPSIZE);
  1274. X    row = currlen = 0; dcurrlen = 10000;
  1275. X
  1276. X    y = base + 51 - ytop;
  1277. X    lasty = y + (duplflag ? 47 : 23);
  1278. X    if (lasty >= 100) lasty = 99;
  1279. X
  1280. X    for ( ; y <= lasty; row++,y++)
  1281. X    {
  1282. X        for (i = minx, col = lbear; i <= maxx; col++,i++)
  1283. X         if (gr[i][y]) chngbit(TRUE);
  1284. X
  1285. X        if (currlen < col + rbear)
  1286. X            currlen = col + rbear;
  1287. X    }
  1288. X}
  1289. X
  1290. Xchngbit(biton)
  1291. Xchar biton;
  1292. X{    if (duplflag && row > 23) cchngbit(3, row - 24, biton);
  1293. X    else cchngbit(0, row, biton);
  1294. X}
  1295. X
  1296. Xcchngbit(ib, row, biton)
  1297. Xchar ib, row;
  1298. Xchar biton;
  1299. X{    unsigned char bit, mask;
  1300. X    
  1301. X    bit = row / 3;
  1302. X    mask = 128 >> bit; 
  1303. X    cbyte = ckeep[ib + (row % 3)][col];
  1304. X    if (biton) cbyte |= mask;
  1305. X        else cbyte &= ~mask;
  1306. X    ckeep[ib + (row % 3)][col] = cbyte;
  1307. X}
  1308. X
  1309. Xgxy(x,y)
  1310. Xchar x,y;
  1311. X{    if (w300)
  1312. X    {    conout(ESC); conout('=');
  1313. X        conout(y+' '); conout(x+' ');
  1314. X    } else mov_cur(x,y);
  1315. X}
  1316. X
  1317. Xclrscrn()
  1318. X{
  1319. X    if (w300) conout(0x1A); else cls();
  1320. X    penchar = 0;
  1321. X    sleep(1);
  1322. X}
  1323. X
  1324. Xshowbits()
  1325. X{
  1326. X    clrscrn();
  1327. X    graph(TRUE);
  1328. X    gxoff = 4;
  1329. X
  1330. X    if (duplflag) gyoff = 0; else gyoff = 6;
  1331. X    sshowbits(0);
  1332. X    if (duplflag)
  1333. X    {    gyoff = 12;
  1334. X        sshowbits(3);
  1335. X        gyoff = 0;
  1336. X    }
  1337. X    graph(FALSE);
  1338. X    gxy(0,22);
  1339. X}
  1340. X
  1341. Xsshowbits(ib)
  1342. Xchar ib;
  1343. X{    unsigned char i, j, bit, mask, r;
  1344. X
  1345. X     if (currlen > 0)
  1346. X     {
  1347. X    color(RED,WHITE);
  1348. X    if (gyoff == 6)
  1349. X    {    gxy(gxoff-1,gyoff-1);
  1350. X        conout(w300 ? '2':'+');
  1351. X        for (i = 0; i < currlen; i++)
  1352. X            conout(w300 ? ':':'-');
  1353. X        conout(w300 ? '3':'+');
  1354. X    }
  1355. X    for (i = gyoff; i < (gyoff+12); i++)
  1356. X      {
  1357. X        gxy(gxoff-1,i); conout(w300 ? '6':'|');
  1358. X        gxy(currlen+gxoff,i); conout(w300 ? '6':'|');
  1359. X      }
  1360. X    if (gyoff == 6)
  1361. X    {    gxy(gxoff-1,gyoff+12);
  1362. X        conout(w300 ? '1':'+');
  1363. X        for (i = 0; i < currlen; i++)
  1364. X            conout(w300 ? ':':'-');
  1365. X        conout(w300 ? '5':'+');
  1366. X    }
  1367. X    color(BLACK,WHITE);
  1368. X     }
  1369. X
  1370. X    for (i = 0; i < 3; i++)
  1371. X     for (j = 0; j < currlen; j++)
  1372. X      {    cbyte = ckeep[ib+i][j];
  1373. X        cbyteo = ckeep[ib + ((i+1) % 3)][j];
  1374. X        mask = 0x80;
  1375. X        for (bit = 0; bit < 8; bit++, mask >>= 1)
  1376. X         if (
  1377. X             /* if row is even */
  1378. X            !((r = i + bit*3) & 1)
  1379. X             /* and there is a dot in this row or the next */
  1380. X             && ((mask & cbyte) | ((i==2 ? mask>>1: mask) & cbyteo))
  1381. X            )
  1382. X         {    gxy(j+gxoff, r/2+gyoff);
  1383. X             /* both dots? */
  1384. X            if ((mask & cbyte)&& ((i==2 ? mask>>1: mask) & cbyteo))
  1385. X                conout(bothdot);
  1386. X            /* dot in this row only? */
  1387. X            else if (mask & cbyte)
  1388. X                conout(upperdot);
  1389. X            else conout(lowerdot);    /* must be dot in next row */
  1390. X         }
  1391. X      }
  1392. X}
  1393. X
  1394. X
  1395. Xgraph(yes)
  1396. Xchar yes;
  1397. X{    if (!w300) return;
  1398. X
  1399. X    conout(ESC);    conout('H');
  1400. X    if (yes) conout(2); else conout(3);
  1401. X    conout(ESC);    conout('`');    /* cursor off/on    */
  1402. X    if (yes) conout('0'); else conout('1');
  1403. X    if (!yes) color(BLACK, WHITE);
  1404. X}
  1405. X
  1406. Xcolor(fc, bc)
  1407. Xchar fc, bc;
  1408. X{    if (!w300) return;
  1409. X
  1410. X    conout(ESC);    conout('g');
  1411. X    conout(fc);    conout(bc);
  1412. X}
  1413. X
  1414. Xcheckpoint()
  1415. X{    int sx, sy;
  1416. X
  1417. X    if (!penplace) return;
  1418. X    sx = xpos; sy = ypos;
  1419. X    if (!goline(penplace)) return;
  1420. X    penchar = gr[begx+(pxc=ecol)][begy+(pyc=erow)];
  1421. X    xpos = sx; ypos = sy;
  1422. X    gxy(pxc,pyc);
  1423. X    conout(penchar);
  1424. X}
  1425. X
  1426. X
  1427. Xedscr()
  1428. X{    char key();
  1429. X
  1430. X    oldpplace = 0;
  1431. X    xpos = 0; ypos = 1;
  1432. X    cmd = 'E';
  1433. X    while (cmd != 'M')
  1434. X    {  if (cmd >= 'A' && cmd <= 'Z')
  1435. X        switch (cmd)
  1436. X        {
  1437. X          case 'S': xpos--; break;
  1438. X        case 'D': xpos++; break;
  1439. X        case 'E': ypos--; break;
  1440. X        case 'X': ypos++; break;
  1441. X        case 'R': ypos -= 8; break;
  1442. X        case 'C': ypos += 8; break;
  1443. X          case 'A': xpos -= 8; break;
  1444. X        case 'F': xpos += 8; break;
  1445. X        case 'L': key(); currlet = reallet; penplace = 0;
  1446. X        case 'N': lplot(currlet); break;
  1447. X        case 'W': begy--;
  1448. X              gxy(0,0); printf("                 ");
  1449. X              conout(ESC); conout('E');
  1450. X              displine(0);
  1451. X              break;
  1452. X        case 'Z': begy++;
  1453. X              gxy(0,0); conout(ESC); conout('R');
  1454. X              displine(23);
  1455. X              break;
  1456. X        case 'B': if (penplace) goline(penplace-2); break;
  1457. X        case 'P': changeit();
  1458. X              lplot(currlet); break;
  1459. X        case 'I': newpoint();
  1460. X              lplot(currlet); break;
  1461. X        case 'U': penplace = 0; break;
  1462. X        case 'G': delpoint();
  1463. X              lplot(currlet); break;
  1464. X        case 'Y': delline();
  1465. X              lplot(currlet); break;
  1466. X        case 'T': xcontract();
  1467. X              lplot(currlet); break;
  1468. X        case 'Q': begy = 50-12;    begx = 50-39;
  1469. X              lplot(currlet); break;
  1470. X        case 'H': makehair();
  1471. X              lplot(currlet); break;
  1472. X        default:  conout(7);
  1473. X            }
  1474. X        else switch(cmd)
  1475. X        {
  1476. X        case ' ': if (penplace) goline(penplace+2); break;
  1477. X        default:  goline(currlines[reallet-' ']);
  1478. X        }
  1479. X
  1480. X        if (penplace != oldpplace && penchar)
  1481. X        {    gxy(pxc,pyc);
  1482. X            conout(penchar);
  1483. X            penchar = pxc = pyc = 0;
  1484. X        }
  1485. X
  1486. X        if (penplace)
  1487. X        {
  1488. X            color(WHITE,BLUE);
  1489. X            checkpoint();
  1490. X        }
  1491. X        else    color(RED,YELLOW);
  1492. X        gxy(0,0);
  1493. X        printf("   (%3d,%3d)    ", xpos, ypos);
  1494. X        color(BLACK,WHITE);
  1495. X        oldpplace = penplace;
  1496. X
  1497. X        if (!setpos()) { xpos = 0; ypos = 0; setpos(); }
  1498. X
  1499. X        gxy(ecol, erow);
  1500. X
  1501. X        cmd = key();
  1502. X    }
  1503. X}
  1504. X
  1505. X
  1506. X
  1507. Xmax(x,y)
  1508. Xint x,y;
  1509. X{    if (x >= y) return(x);
  1510. X    return(y);
  1511. X}
  1512. X
  1513. Xmin(x,y)
  1514. Xint x,y;
  1515. X{    if (x >= y) return(y);
  1516. X    return(x);
  1517. X}
  1518. X
  1519. \Rogue\Monster\
  1520. else
  1521.   echo "will not over write ./eplot.c"
  1522. fi
  1523. if [ `wc -c ./eplot.c | awk '{printf $1}'` -ne 28121 ]
  1524. then
  1525. echo `wc -c ./eplot.c | awk '{print "Got " $1 ", Expected " 28121}'`
  1526. fi
  1527. echo "Finished archive 4 of 4"
  1528. # if you want to concatenate archives, remove anything after this line
  1529. exit
  1530.  
  1531.