home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume9 / popi / part03 < prev    next >
Internet Message Format  |  1991-03-08  |  47KB

  1. From: richb@sunaus.sun.oz.AU (Rich Burridge)
  2. Newsgroups: comp.sources.misc
  3. Subject: v09i049: popi, The Digital Darkroom, Part03/09
  4. Message-ID: <2783@basser.oz>
  5. Date: 12 Dec 89 23:46:03 GMT
  6. Approved: john@cs.su.oz.AU (John Mackin - comp.sources.misc)
  7.  
  8. Posting-number: Volume 9, Issue 49
  9. Submitted-by: Rich Burridge <richb@sunaus.sun.oz.AU>
  10. Archive-name: popi/part03
  11.  
  12. ---- Cut Here and unpack ----
  13. #!/bin/sh
  14. # this is part 3 of a multipart archive
  15. # do not concatenate these parts, unpack them in order with /bin/sh
  16. # file mgr.c continued
  17. #
  18. CurArch=3
  19. if test ! -r s2_seq_.tmp
  20. then echo "Please unpack part 1 first!"
  21.      exit 1; fi
  22. ( read Scheck
  23.   if test "$Scheck" != $CurArch
  24.   then echo "Please unpack part $Scheck next!"
  25.        exit 1;
  26.   else exit 0; fi
  27. ) < s2_seq_.tmp || exit 1
  28. echo "x - Continuing file mgr.c"
  29. sed 's/^X//' << 'Funky_Stuff' >> mgr.c
  30. X  m_bitwrite(x, y, width, height) ;
  31. X}
  32. X
  33. X
  34. Xdrawline(x1, y1, x2, y2)
  35. Xint x1, y1, x2, y2 ;
  36. X{
  37. X  m_func(B_COPY) ;
  38. X  m_line(x1, y1, x2, y2) ;
  39. X}
  40. X
  41. X
  42. Xdrawtext(x, y, fontno, str)
  43. Xenum font_type fontno ;
  44. Xint x, y ;
  45. Xchar *str ;
  46. X{
  47. X       if (fontno == NFONT) m_font(N_FONT) ;
  48. X  else if (fontno == BFONT) m_font(B_FONT) ;
  49. X  m_func(B_XOR) ;
  50. X  if (str[strlen(str)-1] == '\n') str[strlen(str)-1] = '\0' ;
  51. X  m_stringto(0, x, y+4, str) ;
  52. X  m_movecursor(2500, 2500) ;
  53. X}
  54. X
  55. X
  56. Xget_next_char(c)      /* Process events, and return when character typed. */
  57. Xchar *c ;
  58. X{
  59. X  int chr ;
  60. X  static struct timeval tval = { 0, 0 } ;
  61. X
  62. X  m_flush() ;
  63. X  for (;;)
  64. X    {
  65. X      readmask = fullmask ;
  66. X#ifdef NO_43SELECT
  67. X      SELECT(32, &readmask, 0, 0, &tval) ;
  68. X      if (readmask && (1 << mgr_infd))
  69. X#else
  70. X      SELECT(FD_SETSIZE, &readmask, (fd_set *) 0, (fd_set *) 0, &tval) ;
  71. X      if (FD_ISSET(mgr_infd, &readmask))
  72. X#endif /* NO_4.3SELECT */
  73. X        {
  74. X          if ((chr = m_getchar()) == EOF)
  75. X            {
  76. X              clearerr(m_termin) ;
  77. X              continue ;
  78. X            }
  79. X          switch (chr)
  80. X            {
  81. X              case '\032' :
  82. X              case '\033' : close_frame() ;    /* Turn window iconic. */
  83. X                            break ;
  84. X              case '\034' : clean(1) ;         /* Window destroyed. */
  85. X              case '\035' : if (iconic) iconic = 0 ;
  86. X              case '\036' : reshape(OPEN) ;
  87. X              case '\037' : paint_canvas() ;   /* Repaint popi canvas. */
  88. X                            break ;
  89. X              default     : *c = chr ;
  90. X                            return ;
  91. X            }
  92. X        }
  93. X    }
  94. X}
  95. X
  96. X
  97. Xinit_fonts()
  98. X{
  99. X  char path[MAXLINE] ;     /* Directory path for font files. */
  100. X
  101. X#ifdef MGRHOME
  102. X  STRCPY(path, MGRHOME) ;
  103. X#else
  104. X  STRCPY(path, "/usr/mgr") ;
  105. X#endif
  106. X
  107. X  SPRINTF(fontname, "%s/font/%s", path, NORMAL_FONT) ;
  108. X  m_loadfont(NFONT, fontname) ;
  109. X  nfont_width = 7 ;
  110. X
  111. X  SPRINTF(fontname, "%s/font/%s", path, BOLD_FONT) ;
  112. X  m_loadfont(BFONT, fontname) ;
  113. X}
  114. X
  115. X
  116. Xinit_ws_type()
  117. X{
  118. X  m_setup(M_FLUSH) ;     /* Setup I/O; turn on flushing. */
  119. X  m_push(P_BITMAP | P_MENU | P_EVENT | P_FONT | P_FLAGS | P_POSITION) ;
  120. X  mgr_infd = fileno(m_termin) ;
  121. X  mgr_outfd = fileno(m_termout) ;
  122. X
  123. X  SIGNAL(SIGHUP, clean) ;
  124. X  SIGNAL(SIGINT, clean) ;
  125. X  SIGNAL(SIGTERM, clean) ;
  126. X  m_ttyset() ;
  127. X  m_setraw() ;
  128. X  m_setmode(M_NOWRAP) ;
  129. X  m_setmode(M_ABS) ;
  130. X  m_setmode(ACTIVATE) ;
  131. X  m_clearmode(M_NOINPUT) ;
  132. X  m_func(B_COPY) ;
  133. X
  134. X  mptr = (unsigned char *) malloc((unsigned) Xsize) ;
  135. X  ops[(int) GCLR] = B_CLEAR ;
  136. X  ops[(int) GSET] = B_SET ;
  137. X  return 0 ;
  138. X}
  139. X
  140. X
  141. Xload_colors()                /* Hardwired to a monochrome version. */
  142. X{
  143. X  iscolor = 0 ;
  144. X}
  145. X
  146. X
  147. Xload_icon(pixrect, ibuf)
  148. Xint pixrect ;
  149. Xshort ibuf[256] ;
  150. X{
  151. X  int size ;
  152. X
  153. X  IOCTL(mgr_outfd, TIOCLGET, &local_mode) ;
  154. X  local_mode |= LLITOUT ;
  155. X  IOCTL(mgr_outfd, TIOCLSET, &local_mode) ;
  156. X
  157. X  size = ICONHEIGHT * (((64 + 15) &~ 15) >> 3) ;
  158. X  m_bitldto(ICONWIDTH, ICONHEIGHT, 0, 0, pixrect, size) ;
  159. X  m_flush() ;
  160. X  WRITE(mgr_outfd, (char *) ibuf, size) ;
  161. X
  162. X  local_mode &= ~LLITOUT ;
  163. X  IOCTL(mgr_outfd, TIOCLSET, &local_mode) ;
  164. X}
  165. X
  166. X
  167. Xmake_items(argc, argv)       /* Create icon, frame, canvas etc.. */
  168. Xint argc ;
  169. Xchar *argv[] ;
  170. X{
  171. X
  172. X#ifdef NO_43SELECT
  173. X  fullmask = 1 << mgr_infd ;
  174. X#else
  175. X  FD_ZERO(&fullmask) ;
  176. X  FD_SET(mgr_infd, &fullmask) ;
  177. X#endif /* NO_4.3SELECT */
  178. X  m_setevent(BUTTON_2U, "\032") ;   /* Middle mouse button released. */
  179. X  m_setevent(BUTTON_1U, "\033") ;   /* Right mouse button released. */
  180. X  m_setevent(DESTROY, "\034") ;     /* Window has been destroyed. */
  181. X  m_setevent(ACTIVATE, "\035") ;    /* Window has been activated. */
  182. X  m_setevent(RESHAPE, "\036") ;     /* Check for window being reshaped. */
  183. X  m_setevent(REDRAW, "\037") ;      /* Check for window being redrawn. */
  184. X
  185. X  m_movecursor(2500, 2500) ;        /* Move character cursor offscreen. */
  186. X  m_font(N_FONT) ;                  /* Default is the normal font. */
  187. X  load_icon(PR_ICON, icon_image) ;
  188. X  reshape(OPEN) ;
  189. X  m_clear() ;                       /* Clear popi window. */
  190. X  load_colors() ;                   /* Hardwired to monochrome. */
  191. X}
  192. X
  193. X
  194. Xreshape(type)
  195. Xint type ;
  196. X{
  197. X  int x, y, w, h ;      /* Position and size of calctool window. */
  198. X
  199. X  get_size(&x, &y, &w, &h) ;
  200. X  switch (type)
  201. X    {
  202. X      case ICONIC : m_shapewindow(x, y, ICONWIDTH+10, ICONHEIGHT+10) ;
  203. X                    m_clear() ;
  204. X                    m_bitcopyto(0, 0, ICONWIDTH, ICONHEIGHT,
  205. X                                0, 0, 0, PR_ICON) ;
  206. X                    break ;
  207. X      case OPEN   : m_shapewindow(x, y, TWIDTH+10, THEIGHT+10) ;
  208. X    }
  209. X  m_movecursor(2500, 2500) ;
  210. X}
  211. X
  212. X
  213. X/*ARGUSED*/
  214. Xset_cursor(type)      /* Doesn't appear to be any way to set the cursor. */
  215. Xenum cur_type type ;
  216. X{
  217. X}
  218. X
  219. X
  220. Xstart_tool()          /* Null routine. */
  221. X{
  222. X}
  223. Funky_Stuff
  224. echo "File mgr.c is complete"
  225. chmod 0444 mgr.c || echo "restore of mgr.c fails"
  226. set `wc -c mgr.c`;Sum=$1
  227. if test "$Sum" != "7681"
  228. then echo original size 7681, current size $Sum;fi
  229. echo "x - extracting graphics.h (Text)"
  230. sed 's/^X//' << 'Funky_Stuff' > graphics.h &&
  231. X
  232. X/*  @(#)graphics.h 1.1 89/12/12
  233. X *
  234. X *  External variable definitions used by the popi program
  235. X *  optional graphics module.
  236. X *
  237. X *  Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
  238. X *  This version is based on the code in his Prentice Hall book,
  239. X *  "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
  240. X *  which is copyright (c) 1988 by Bell Telephone Laboratories, Inc. 
  241. X *
  242. X *  Permission is given to distribute these extensions, as long as these
  243. X *  introductory messages are not removed, and no monies are exchanged.
  244. X *
  245. X *  No responsibility is taken for any errors or inaccuracies inherent
  246. X *  either to the comments or the code of this program, but if reported
  247. X *  (see README file) then an attempt will be made to fix them.
  248. X */
  249. X
  250. X/* External declarations for the variables declared in graphics.c. */
  251. X
  252. Xextern char geometry[] ;       /* X11 geometry information. */
  253. Xextern char nextline[] ;       /* Next input line to be parsed. */
  254. Xextern char x11_display[] ;    /* X11 display information. */
  255. Xextern unsigned char *mptr ;   /* Pointer to scanline data. */
  256. Xextern int iconic ;        /* Set if the window is in an iconic state. */
  257. Xextern int iscolor ;       /* Set if this is a color screen. */
  258. Xextern int ix ;            /* Initial X position of the icon. */
  259. Xextern int iy ;            /* Initial Y position of the icon. */
  260. Xextern int nfont_width ;   /* Width of normal font characters. */
  261. Xextern int ops[] ;         /* Rasterop functions. */
  262. Xextern int posspec ;       /* Set if -Wp or -g option is present (for X11) */
  263. Xextern int tptr ;          /* Input buffer pointer. */
  264. X
  265. Xextern int wx ;            /* Initial X position of the open window. */
  266. Xextern int wy ;            /* Initial Y position of the open window. */
  267. Funky_Stuff
  268. chmod 0444 graphics.h || echo "restore of graphics.h fails"
  269. set `wc -c graphics.h`;Sum=$1
  270. if test "$Sum" != "1762"
  271. then echo original size 1762, current size $Sum;fi
  272. echo "x - extracting news.c (Text)"
  273. sed 's/^X//' << 'Funky_Stuff' > news.c &&
  274. X/*LINTLIBRARY*/
  275. X
  276. X/*  @(#)news.c 1.8 89/12/11
  277. X *
  278. X *  C wrappers for News dependent graphics routines used by popi.
  279. X *  written by Rich Burridge - Sun Microsystems Australia.
  280. X *
  281. X *  Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
  282. X *  This version is based on the code in his Prentice Hall book,
  283. X *  "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
  284. X *  which is copyright (c) 1988 by Bell Telephone Laboratories, Inc. 
  285. X *
  286. X *  Permission is given to distribute these extensions, as long as these
  287. X *  introductory messages are not removed, and no monies are exchanged.
  288. X *
  289. X *  No responsibility is taken for any errors or inaccuracies inherent
  290. X *  either to the comments or the code of this program, but if reported
  291. X *  (see README file) then an attempt will be made to fix them.
  292. X */
  293. X
  294. X#include "popi.h"
  295. X#include "graphics.h"
  296. X#include <sys/types.h>
  297. X
  298. X/* Various pseudo events generated by the popi program. */
  299. X#define  KEYBOARD  100          /* Keyboard character was pressed. */
  300. X#define  REPAINT   101          /* Popi canvas needs repainting. */
  301. X
  302. Xextern FILE *PostScript ;
  303. Xextern FILE *PostScriptInput ;
  304. X
  305. Xunsigned short icon_image[] = {
  306. X#include "popi.icon"
  307. X} ;
  308. X
  309. X
  310. Xcleanup()            /* Null routine for the NeWS version. */
  311. X{
  312. X  FPRINTF(PostScript, "/destroy Frame send\n") ;
  313. X  FFLUSH(PostScript) ;
  314. X}
  315. X
  316. X
  317. Xdraw_scanline(line, y)      /* Display image scanline on the screen. */
  318. Xunsigned char *line ;
  319. Xint y ;
  320. X{
  321. X  int depth, i ;
  322. X
  323. X  depth = (iscolor) ? 8 : 1 ;
  324. X  FPRINTF(PostScript, "/ScanLine %1d 1 %1d { } { < \n", Xsize, depth) ;
  325. X  if (iscolor)
  326. X    {
  327. X      for (i = 0; i < Xsize; i++)
  328. X        FPRINTF(PostScript, "%.2X ", line[i]) ;
  329. X    }
  330. X  else
  331. X    {
  332. X      mptr = (unsigned char *) Emalloc((Xsize / 8) + 1) ;
  333. X      halftone(line, y) ;
  334. X      for (i = 0; i < (Xsize / 8) + 1; i++)
  335. X        FPRINTF(PostScript, "%.2X ", 255 - mptr[i]) ;
  336. X    }
  337. X  FPRINTF(PostScript, "> } buildimage def\n") ;
  338. X  FPRINTF(PostScript, "%1d PSDrawScanLine\n", y) ;
  339. X  FFLUSH(PostScript) ;
  340. X}
  341. X
  342. X
  343. Xdrawarea(x, y, width, height, op)
  344. Xint x, y, width, height ;
  345. Xenum op_type op ;
  346. X{
  347. X  FPRINTF(PostScript, "%d %d %d %d %d PSDrawArea\n",
  348. X          x, y, width, height, (int) op) ;
  349. X  FFLUSH(PostScript) ;
  350. X}
  351. X
  352. X
  353. Xdrawline(x1, y1, x2, y2)
  354. Xint x1, y1, x2, y2 ;
  355. X{
  356. X  FPRINTF(PostScript, "%d %d %d %d PSDrawLine\n", x1, y1, x2, y2) ;
  357. X}
  358. X
  359. X
  360. Xdrawtext(x, y, fontno, str)
  361. Xenum font_type fontno ;
  362. Xint x, y ;
  363. Xchar *str ;
  364. X{
  365. X  int i ;
  366. X  char font, fonttype[6], line[MAXLINE] ;
  367. X
  368. X       if (fontno == NFONT) STRCPY(fonttype, "NFont") ;
  369. X  else if (fontno == BFONT) STRCPY(fonttype, "BFont") ;
  370. X  line[0] = '\0' ;
  371. X  for (i = 0; i < strlen(str); i++)
  372. X    switch (str[i])
  373. X      {
  374. X        case '\\' : STRCAT(line,"\\\\") ;
  375. X                    break ;
  376. X        case '('  : STRCAT(line,"\\(") ;
  377. X                    break ;
  378. X        case ')'  : STRCAT(line,"\\)") ;
  379. X                    break ;
  380. X        default   : STRNCAT(line, &str[i], 1) ;
  381. X      }
  382. X  FPRINTF(PostScript, "%s %d %d (%s) PSDrawText\n", fonttype, x, y, line) ;
  383. X}
  384. X
  385. X
  386. Xget_next_char(c)    /* Process events, and return when character is typed. */
  387. Xchar *c ;
  388. X{
  389. X  int ch, type ;
  390. X
  391. X  for (;;)
  392. X    {
  393. X      FFLUSH(PostScript) ;
  394. X      if (pscanf(PostScriptInput, "%d", &type) == EOF) exit(0) ;
  395. X      switch (type)
  396. X        {
  397. X          case KEYBOARD : pscanf(PostScriptInput, "%d", &ch) ;
  398. X                          *c = ch ;
  399. X                          return ;
  400. X          case REPAINT  : paint_canvas() ;
  401. X        }
  402. X    }
  403. X/*NOTREACHED*/
  404. X}
  405. X
  406. X
  407. Xinit_fonts()
  408. X{
  409. X  FPRINTF(PostScript, "PSInitFonts\n") ;
  410. X  nfont_width = 9 ;
  411. X}
  412. X
  413. X
  414. Xinit_ws_type()
  415. X{
  416. X  if (ps_open_PostScript() < 0) return -1 ;
  417. X  if (send_ps_file(NEWSFILE) == -1)
  418. X    {
  419. X      FCLOSE(PostScript) ;
  420. X      return(-1) ;
  421. X    }
  422. X  FFLUSH(PostScript) ;
  423. X  if (ferror(PostScript))
  424. X    {
  425. X      FCLOSE(PostScript) ;
  426. X      return(-1) ;
  427. X    }
  428. X  FPRINTF(PostScript, "PSIsColor\n") ;
  429. X  pscanf(PostScriptInput, "%d", &iscolor) ;
  430. X  FPRINTF(PostScript, "PSInitialise\n") ;
  431. X  return(0) ;
  432. X}
  433. X
  434. X
  435. Xload_colors()    /* Create and load popi color map. */
  436. X{
  437. X  int i ;
  438. X  u_char red[CMAPLEN], green[CMAPLEN], blue[CMAPLEN] ;
  439. X
  440. X  for (i = 0; i < CMAPLEN; i++)
  441. X    red[i] = green[i] = blue[i] = 255 - i ;
  442. X  FPRINTF(PostScript, "%d PSMakeColorTable\n", 256) ;
  443. X  for (i = 0; i < 256; i++)
  444. X    FPRINTF(PostScript, "%d %d %d %d PSLoadColor\n",
  445. X                       red[i], green[i], blue[i], i) ;
  446. X}
  447. X
  448. X
  449. Xmake_icon()
  450. X{
  451. X  int i, j ;
  452. X
  453. X  FPRINTF(PostScript,"/PopiIcon 64 64 1 { } { <\n") ;
  454. X  for (i = 0; i < 32; i++)
  455. X    {
  456. X      for (j = 0; j < 8; j++) FPRINTF(PostScript,"%.4X ", icon_image[i*8+j]) ;
  457. X      FPRINTF(PostScript,"\n") ;
  458. X    }
  459. X  FPRINTF(PostScript,"> } buildimage def\n") ;
  460. X}
  461. X
  462. X
  463. Xmake_items(argc, argv)       /* Create icon, frame, canvas etc.. */
  464. Xint argc ;
  465. Xchar *argv[] ;
  466. X{
  467. X  make_icon() ;
  468. X  FPRINTF(PostScript, "%d %d %d %d %d %d %d PSMakeItems\n",
  469. X                     wx, wy, TWIDTH, THEIGHT,
  470. X                     ix, iy, iconic) ;
  471. X  load_colors() ;
  472. X}
  473. X
  474. X
  475. Xsend_ps_file(fname)
  476. Xchar *fname ;
  477. X{
  478. X  FILE *stream ;
  479. X  int c ;
  480. X
  481. X  if ((stream = fopen(fname,"r")) == NULL) return -1 ;
  482. X  while ((c = getc(stream)) != EOF) PUTC(c, PostScript) ;
  483. X  FCLOSE(stream) ;
  484. X  return 0 ;
  485. X}
  486. X
  487. X
  488. Xset_cursor(type)
  489. Xenum cur_type type ;
  490. X{
  491. X  FPRINTF(PostScript, "%d PSSetCursor\n", (int) type) ;
  492. X}
  493. X
  494. X
  495. Xstart_tool()          /* Null routine in the NeWS version. */
  496. X{
  497. X}
  498. Funky_Stuff
  499. chmod 0444 news.c || echo "restore of news.c fails"
  500. set `wc -c news.c`;Sum=$1
  501. if test "$Sum" != "5267"
  502. then echo original size 5267, current size $Sum;fi
  503. echo "x - extracting nulldev.c (Text)"
  504. sed 's/^X//' << 'Funky_Stuff' > nulldev.c &&
  505. X/*LINTLIBRARY*/
  506. X
  507. X/*  @(#)nulldev.c 1.7 89/12/11
  508. X *
  509. X *  Popi device driver for a null device.
  510. X *  written by Stephen Frede, Softway Pty Ltd.
  511. X *
  512. X *  Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
  513. X *  This version is based on the code in his Prentice Hall book,
  514. X *  "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
  515. X *  which is copyright (c) 1988 by Bell Telephone Laboratories, Inc. 
  516. X *
  517. X *  Permission is given to distribute these extensions, as long as these
  518. X *  introductory messages are not removed, and no monies are exchanged.
  519. X *
  520. X *  No responsibility is taken for any errors or inaccuracies inherent
  521. X *  either to the comments or the code of this program, but if reported
  522. X *  (see README file) then an attempt will be made to fix them.
  523. X */
  524. X
  525. X#include "popi.h"
  526. X
  527. X/*  There are ten exportable routines used by the popi program.
  528. X *
  529. X *  These are:
  530. X *
  531. X *  disp_init(argc, argv)    - called from main at the start.
  532. X *  disp_finish()            - called from main prior to exit.
  533. X *  disp_imgstart()          - called prior to drawing an image.
  534. X *  disp_imgend()            - called after drawing an image.
  535. X *  disp_putline(line, y)    - to draw an image scanline.
  536. X *  disp_getchar()           - to get the next character typed.
  537. X *  disp_ungetc(c)           - put back the last character typed.
  538. X *  disp_prompt()            - display popi prompt and clear input buffer.
  539. X *  disp_error(errtype)      - display error message.
  540. X *  disp_percentdone(n)      - display percentage value of conversion.
  541. X */
  542. X
  543. X/*ARGSUSED*/
  544. Xvoid
  545. Xdisp_init(argc,argv)           /* called from main at the atart. */
  546. Xint argc;
  547. Xchar *argv[];
  548. X{
  549. X}
  550. X
  551. X
  552. Xvoid
  553. Xdisp_finish()                  /* called from main prior to exit. */
  554. X{
  555. X}
  556. X
  557. X
  558. Xvoid
  559. Xdisp_imgstart()                /* called prior to drawing an image. */
  560. X{
  561. X}
  562. X
  563. X
  564. Xvoid
  565. Xdisp_imgend()                  /* called after drawing an image. */
  566. X{
  567. X}
  568. X
  569. X
  570. Xvoid
  571. Xdisp_putline(line, y)        /* called to draw image scanline y. */
  572. Xpixel_t *line;
  573. Xint y;
  574. X{
  575. X}
  576. X
  577. X
  578. Xdisp_getchar()                 /* get next user typed character. */
  579. X{
  580. X    return(getchar());
  581. X}
  582. X
  583. X
  584. X/*ARGSUSED*/
  585. Xvoid
  586. Xdisp_ungetc(c)                 /* put back the last character typed. */
  587. Xchar c;
  588. X{
  589. X    UNGETC(c, stdin);
  590. X}
  591. X
  592. X
  593. Xdisp_prompt()                  /* display popi prompt. */
  594. X{
  595. X    char    *prompt = "-> ";
  596. X
  597. X    PRINTF(prompt);
  598. X    return sizeof prompt - 1;
  599. X}
  600. X
  601. X
  602. Xvoid
  603. Xdisp_error(errtype, pos)            /* display error message. */
  604. Xint    errtype,
  605. X    pos;
  606. X{
  607. X    extern int  errno;
  608. X    extern char *sys_errlist[];
  609. X
  610. X    if (errtype & ERR_PARSE)
  611. X    {
  612. X        int     i;
  613. X        for (i=1; i < pos; ++i)
  614. X            PUTC('-', stderr);
  615. X        PUTC('^', stderr);
  616. X        PUTC('\n', stderr);
  617. X    }
  618. X    FPRINTF(stderr, "%s\n", ErrBuf);
  619. X    /* we assume errno hasn't been reset by the preceding output */
  620. X    if (errtype & ERR_SYS)
  621. X        FPRINTF(stderr, "\t(%s)\n", sys_errlist[errno]);
  622. X}
  623. X
  624. Xvoid
  625. Xdisp_percentdone(percent)
  626. Xint    percent;
  627. X{
  628. X    static int    lastpercent = 100;
  629. X
  630. X    if (!Verbose)
  631. X    return;
  632. X    if (percent == 100)
  633. X    {
  634. X    printf("\r    \n");
  635. X    return;
  636. X    }
  637. X    if (percent != lastpercent && percent % 5 == 0)
  638. X    {
  639. X    printf("\r%2d%% ", percent);
  640. X    fflush(stdout);
  641. X    lastpercent = percent;
  642. X    }
  643. X}
  644. Funky_Stuff
  645. chmod 0444 nulldev.c || echo "restore of nulldev.c fails"
  646. set `wc -c nulldev.c`;Sum=$1
  647. if test "$Sum" != "3179"
  648. then echo original size 3179, current size $Sum;fi
  649. echo "x - extracting patchlevel.h (Text)"
  650. sed 's/^X//' << 'Funky_Stuff' > patchlevel.h &&
  651. X
  652. X/* @(#)patchlevel.h 1.11 89/12/11
  653. X *
  654. X *  This is the current patchlevel for this version of popi.
  655. X *
  656. X *  Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
  657. X *  This version is based on the code in his Prentice Hall book,
  658. X *  "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
  659. X *  which is copyright (c) 1988 by Bell Telephone Laboratories, Inc. 
  660. X *
  661. X *  Permission is given to distribute these extensions, as long as these
  662. X *  introductory messages are not removed, and no monies are exchanged.
  663. X *
  664. X *  No responsibility is taken for any errors or inaccuracies inherent
  665. X *  either to the comments or the code of this program, but if reported
  666. X *  (see README file) then an attempt will be made to fix them.
  667. X */
  668. X
  669. X#define  PATCHLEVEL  2
  670. Funky_Stuff
  671. chmod 0444 patchlevel.h || echo "restore of patchlevel.h fails"
  672. set `wc -c patchlevel.h`;Sum=$1
  673. if test "$Sum" != "764"
  674. then echo original size 764, current size $Sum;fi
  675. echo "x - extracting polar.c (Text)"
  676. sed 's/^X//' << 'Funky_Stuff' > polar.c &&
  677. X
  678. X/*  @(#)polar.c 1.6 89/12/11
  679. X *
  680. X *  Polar coordinate handling routines used by the popi program.
  681. X *
  682. X *  Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
  683. X *  This version is based on the code in his Prentice Hall book,
  684. X *  "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
  685. X *  which is copyright (c) 1988 by Bell Telephone Laboratories, Inc. 
  686. X *
  687. X *  Permission is given to distribute these extensions, as long as these
  688. X *  introductory messages are not removed, and no monies are exchanged.
  689. X *
  690. X *  No responsibility is taken for any errors or inaccuracies inherent
  691. X *  either to the comments or the code of this program, but if reported
  692. X *  (see README file) then an attempt will be made to fix them.
  693. X */
  694. X
  695. X#include <stdio.h>
  696. X#include "popi.h"
  697. X
  698. Xshort
  699. X    *avals = 0,
  700. X    *rvals = 0;
  701. X
  702. X/*
  703. X *      +y
  704. X *       ^
  705. X *       2 | 1
  706. X * -x <----+----> +x
  707. X *       3 | 4
  708. X *       v
  709. X *      -y
  710. X */
  711. X
  712. X#ifdef AMIGA
  713. Xdouble
  714. Xhypot(x, y)
  715. Xdouble x, y;
  716. X{
  717. X    return(sqrt(x*x + y*y));
  718. X}
  719. X#endif    /* AMIGA */
  720. X
  721. Xvoid
  722. XMakePolar()
  723. X{
  724. X    short    *ap,    /* pointer to angle array */
  725. X        *rp,    /* pointer into radius array */
  726. X        *a1,    /* tmp pointer to angle array */
  727. X        *r1;    /* tmp pointer to radius array */
  728. X    int        x,
  729. X        y,
  730. X        xmin,
  731. X        xmax,
  732. X        ymin,
  733. X        ymax;
  734. X
  735. X    if (avals)
  736. X    return;        /* previously calculated */
  737. X
  738. X    avals = (short *) LINT_CAST(Emalloc((unsigned)Xsize * Ysize * sizeof(short)));
  739. X    rvals = (short *) LINT_CAST(Emalloc((unsigned)Xsize * Ysize * sizeof(short)));
  740. X
  741. X    ymax =  Ysize / 2;
  742. X    ymin = -(Ysize - 1) / 2;
  743. X    xmin = -Xsize / 2;
  744. X    xmax =  (Xsize - 1) / 2;
  745. X
  746. X    rp = rvals;
  747. X    ap = avals;
  748. X
  749. X    for (y = ymax; y >= 0; --y)
  750. X    {
  751. X    /* Quadrant 2 */
  752. X    for (x = xmin; x < 0; ++x)
  753. X    {
  754. X        *ap++ = (short) (RtoD(atan2((double) y, (double) x)) + 0.5);
  755. X        *rp++ = (short) hypot((double) y, (double) x);
  756. X    }
  757. X    /* x == 0 */
  758. X    if (y == 0)
  759. X    {
  760. X        *ap++ = 0;    /* prevent a domain error calling atan2() */
  761. X        *rp++ = 0;
  762. X    }
  763. X    else
  764. X    {
  765. X        *ap++ = (short) (RtoD(atan2((double) y, (double) x)) + 0.5);
  766. X        *rp++ = (short) hypot((double) y, (double) x);
  767. X    }
  768. X    ++x;
  769. X    /* remember location just before the 0 value */
  770. X    r1 = rp -2;
  771. X    a1 = ap - 2;
  772. X    /* Quadrant 1 */
  773. X    for (; x <= xmax; ++x)
  774. X    {
  775. X        *ap++ = 180 - *a1--;
  776. X        *rp++ = *r1--;
  777. X    }
  778. X    }
  779. X    r1 = rp - Xsize - 1;
  780. X    a1 = ap - Xsize - 1;
  781. X    for (; y >= ymin; --y)
  782. X    {
  783. X    /* Quadrant 3, 4 */
  784. X    for (x = xmin; x <= xmax; ++x)
  785. X    {
  786. X        *rp++ = *r1--;
  787. X        *ap++ = *a1-- + 180;
  788. X    }
  789. X    }
  790. X}
  791. Funky_Stuff
  792. chmod 0444 polar.c || echo "restore of polar.c fails"
  793. set `wc -c polar.c`;Sum=$1
  794. if test "$Sum" != "2418"
  795. then echo original size 2418, current size $Sum;fi
  796. echo "x - extracting popi.h (Text)"
  797. sed 's/^X//' << 'Funky_Stuff' > popi.h &&
  798. X/* @(#)popi.h 1.10 89/12/11
  799. X *
  800. X *  Definitions and constants used by the popi program.
  801. X *
  802. X *  Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
  803. X *  This version is based on the code in his Prentice Hall book,
  804. X *  "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
  805. X *  which is copyright (c) 1988 by Bell Telephone Laboratories, Inc. 
  806. X *
  807. X *  Permission is given to distribute these extensions, as long as these
  808. X *  introductory messages are not removed, and no monies are exchanged.
  809. X *
  810. X *  No responsibility is taken for any errors or inaccuracies inherent
  811. X *  either to the comments or the code of this program, but if reported
  812. X *  (see README file) then an attempt will be made to fix them.
  813. X */
  814. X
  815. X#ifndef    POPI_DEFINED
  816. X#define POPI_DEFINED
  817. X
  818. X#if defined(MSDOS) && defined(M_I86)
  819. X/* Assume we are Microsoft C */
  820. X# define __MSC__ 1
  821. X#endif    /* MSC */
  822. X
  823. X/*
  824. X * Some compilers are near enough to ANSI for our purposes.
  825. X * In some situations the compiler has a true ANSI mode which
  826. X * we should set if possible. But sometimes we can't because
  827. X * we need non-standard features of the compiler (eg far pointers
  828. X * under DOS). We can't just set __STDC__ ourselves in these cases
  829. X * because their include files need to know the truth. So we
  830. X * set the token STDC which means that as far as we're concerned
  831. X * we are ANSI.
  832. X */
  833. X
  834. X#if defined(__STDC__) || defined(__TURBOC__) || defined(__MSC__)
  835. X# define STDC    1
  836. X#endif    /* __STDC__ || __TURBOC__ || __MSC__ */
  837. X
  838. X#if defined(STDC) && ! defined(apollo)
  839. X
  840. X# include <stdlib.h>
  841. X
  842. X#else    /* ! STDC || apollo */
  843. X
  844. X/* No <stdlib.h> */
  845. X/* We can't define these as well as including <stdlib.h> because
  846. X * some compilers (eg Turbo C) use silly nonstandard keywords (which
  847. X * we can't #define away) as part of the type.
  848. X */
  849. Xextern char
  850. X        *malloc(),
  851. X        *getenv(),
  852. X# ifdef       BSD
  853. X        *sprintf();
  854. X# endif  /* BSD */
  855. X#endif    /* STDC && !apollo */
  856. X
  857. X#if defined(STDC) || ! defined(BSD)
  858. X# include <string.h>
  859. X#else
  860. X# include <strings.h>
  861. X#endif    /* STDC || ! BSD */
  862. X
  863. X/*
  864. X *    For all function declarations, if ANSI then use a prototype.
  865. X */
  866. X#if    defined(STDC)
  867. X# define P(args)    args
  868. X#else    /* ! STDC */
  869. X# define P(args)    ()
  870. X#endif    /* STDC */
  871. X
  872. X#ifndef    FILE
  873. X# include    <stdio.h>
  874. X#endif    /* FILE */
  875. X#ifndef assert
  876. X# include    <assert.h>
  877. X#endif    /* assert */
  878. X
  879. X/*
  880. X * The assumption we make here is that not all versions of <math.h>
  881. X * define M_PI, but they all define HUGE.
  882. X */
  883. X#ifndef M_PI
  884. X# ifndef    HUGE
  885. X#  include <math.h>
  886. X# endif        /* HUGE */
  887. X
  888. X# ifndef    M_PI
  889. X#  define M_PI    3.14159265358979323846
  890. X# endif        /* M_PI */
  891. X#endif /* M_PI */
  892. Xextern double
  893. X    pow P((double, double)),
  894. X    sin P((double)),
  895. X    cos P((double)),
  896. X    atan2 P((double, double)),
  897. X    hypot P((double, double)),
  898. X    log P((double)),
  899. X    sqrt P((double));
  900. X
  901. X#define NELS(arr)    (sizeof (arr) / sizeof (*(arr)))
  902. X
  903. X#define DtoR(degrees)    ((degrees) * M_PI * 2.0 / 360.0)
  904. X#define RtoD(radians)    ((radians) / (M_PI * 2.0 / 360.0))
  905. X
  906. X#define BITSINBYTE    8
  907. X
  908. X/*
  909. X * define RANDOM to be an expression which returns a value
  910. X * between 0 and some large number (like maxint or maxlong).
  911. X */
  912. X#if    defined(BSD)
  913. X# define RANDOM        random()
  914. Xextern long        random P((void));
  915. X#else    /* ! BSD */
  916. X# if    defined(SYSV)
  917. X#  define RANDOM        lrand48()
  918. Xextern long        lrand48 P((void));
  919. X# else    /* ! SYSV */
  920. X#  define RANDOM        rand()
  921. Xextern int        rand P((void));
  922. X# endif    /* SYSV */
  923. X#endif    /* BSD */
  924. X
  925. Xtypedef long        stack_t;
  926. Xtypedef long        parse_t;
  927. Xtypedef unsigned char    pixel_t;
  928. Xtypedef int        bool;
  929. X
  930. X#ifndef    FALSE
  931. X# define FALSE        0
  932. X# define TRUE        1
  933. X#endif    /* FALSE */
  934. X
  935. X
  936. X/* To make lint happy. */
  937. X
  938. X#define FCLOSE        (void) fclose
  939. X#define FFLUSH          (void) fflush
  940. X#define FPRINTF      (void) fprintf
  941. X#define FPUTS        (void) fputs
  942. X#define FREAD        (void) fread
  943. X#define FWRITE       (void) fwrite
  944. X#define IOCTL           (void) ioctl
  945. X#define PCLOSE        (void) pclose
  946. X#define PRINTF       (void) printf
  947. X#define PUTC            (void) putc
  948. X#define SELECT          (void) select
  949. X#define SIGNAL          (void) signal
  950. X#define SPRINTF         (void) sprintf
  951. X#define STRCAT          (void) strcat
  952. X#define STRCPY       (void) strcpy
  953. X#define STRNCAT        (void) strncat
  954. X#define STRNCPY        (void) strncpy
  955. X#define UNGETC       (void) ungetc
  956. X#define WRITE           (void) write
  957. X
  958. X#ifndef LINT_CAST
  959. X#ifdef lint
  960. X#define LINT_CAST(arg)  (arg ? 0 : 0)
  961. X#else
  962. X#define LINT_CAST(arg)  (arg)
  963. X#endif /* lint */
  964. X#endif /* LINT_CAST */
  965. X
  966. X#define PUTCHAR(ch)    (void) putc(ch, stderr)
  967. X
  968. X#define BACKSPACE       8            /* for input line parsing. */
  969. X#define DEL             127
  970. X#define LINEFEED        13
  971. X#define RETURN          10
  972. X
  973. X#define BITSPERPIXEL    8
  974. X#define BOXH            40           /* height of input dialog box. */
  975. X#define BOXW            (TWIDTH-40)  /* width of input dialog box. */
  976. X#define BOXX            20           /* x position of input dialog box. */
  977. X#define BOXY            10           /* y position of input dialog box. */
  978. X#define CMAPLEN         256          /* length of the color map. */
  979. X#define DEF_X           512          /* image width */
  980. X#define DEF_Y           512          /* image height */
  981. X#define DEF_ZSIZE       (1 << BITSPERPIXEL)
  982. X#define MAXIMG          128
  983. X
  984. X#ifndef MAXLINE
  985. X#define MAXLINE         80           /* length of character strings. */
  986. X#endif  /*MAXLINE*/
  987. X
  988. X#define MAXOPS        2            /* number of pseudo rasterop functions. */
  989. X#define MAXTOKENS    128
  990. X
  991. X#ifndef  SIGRET
  992. X#define  SIGRET         int
  993. X#endif /* SIGRET */
  994. X
  995. X#define THEIGHT         612          /* total height of the popi window. */
  996. X#define TWIDTH          512          /* total width of the popi canvas. */
  997. X
  998. X#define ERR_NONE    0
  999. X#define ERR_SYS        (1<<0)       /* system error (errno set) */
  1000. X#define ERR_PARSE    (1<<1)         /* syntax error while parsing input */
  1001. X#define ERR_SNARK    (1<<2)         /* internal program error */
  1002. X#define ERR_WARN    (1<<3)         /* just a warning */
  1003. X
  1004. X/* larger than any char token. */
  1005. X#define CRVAL    257    /* cartesian image coordinate rval */
  1006. X#define CLVAL    258    /* cartesian image coordinate lval */
  1007. X#define INAME    259    /* image name */
  1008. X#define VALUE    260
  1009. X#define NAME    261
  1010. X#define NEW    262
  1011. X#define AND    264    /* && */
  1012. X#define OR    265    /* || */
  1013. X#define EQ    266    /* == */
  1014. X#define NE    267    /* != */
  1015. X#define GE    268    /* >= */
  1016. X#define LE    269    /* <= */
  1017. X#define UMIN    270    /* unary minus */
  1018. X#define POW    271    /* ** */
  1019. X#define LSHIFT    272    /* << */
  1020. X#define RSHIFT    273    /* >> */
  1021. X#define SPECIAL    274
  1022. X#define INUM    275    /* integer number */
  1023. X#define FNUM    276    /* floating point number */
  1024. X#define PLVAL    277    /* polar image coordinate lval */
  1025. X#define PRVAL    278    /* polar image coordinate rval */
  1026. X#define FNAME    279    /* Filename */
  1027. X#define SIN    300    /* sine() * Z */
  1028. X#define COS    301    /* cosine() * Z */
  1029. X#define ATAN    302    /* atan2(y, x) */
  1030. X#define ABS    303    /* abs() */
  1031. X#define LOG    304    /* natural log */
  1032. X#define SQRT    305
  1033. X#define RAND    306    /* RANDOM() as defined above */
  1034. X#define HYPOT    307    /* hypot(x, y) == sqrt(x*x + y*y) */
  1035. X
  1036. X#ifdef    NDEBUG
  1037. X#  define DEBUG(stuff)
  1038. X#else    /* ! NDEBUG */
  1039. X#  define DEBUG(stuff)    if (Debug) FPRINTF stuff
  1040. X#endif    /* ! NDEBUG */
  1041. X
  1042. Xenum cur_type { BUSY_CUR, NORMAL_CUR } ; /* cursor types. */
  1043. X
  1044. Xenum font_type { BFONT, NFONT } ;        /* fonts used by popi. */
  1045. X
  1046. Xenum op_type  { GCLR, GSET } ;           /* pseudo rasterop functions. */
  1047. X
  1048. Xstruct SRC
  1049. X{
  1050. X    pixel_t        **pix;    /* pix[y][x] */
  1051. X    char        *str;
  1052. X};
  1053. X
  1054. X/* An element of the execution string.
  1055. X * Each such item will perform some operation on the
  1056. X * evaluation stack.
  1057. X */
  1058. Xtypedef
  1059. Xstruct exec
  1060. X{
  1061. X    int        op;
  1062. X    union
  1063. X    {
  1064. X    long    i;    /* integer */
  1065. X    float    f;    /* floating point */
  1066. X    } value;
  1067. X} exec_t;
  1068. X
  1069. X#if    SEQPAR
  1070. X#ifndef    sequent
  1071. X#include "Sorry, this will only work on a sequent"
  1072. X#endif    /* sequent */
  1073. X#define malloc    shmalloc
  1074. X#endif    /* SEQPAR */
  1075. X
  1076. X/* External declarations */
  1077. X
  1078. X/* main.c */
  1079. Xextern char    *Emalloc P((unsigned int));
  1080. Xextern void    PrStrs P((char **));
  1081. Xextern void    version P((void));
  1082. X
  1083. X/* io.c */
  1084. Xextern pixel_t    **ImgAlloc P((void));
  1085. Xextern void    ImgFree P((struct SRC *));
  1086. Xextern void    Efclose P((FILE *));
  1087. Xextern FILE    *EfopenR P((char *)),
  1088. X        *EfopenW P((char *));
  1089. Xextern void    getpix P((char *, char *));
  1090. Xextern void    putpix P((struct SRC *, char *));
  1091. Xextern void    showfiles P((void));
  1092. X
  1093. X/* lex.c */
  1094. Xextern void    Skip P((void));
  1095. Xextern void    lex P((void));
  1096. Xextern void    error P((int));
  1097. Xextern void    pushback P((int));
  1098. X
  1099. X/* expr.c */
  1100. Xextern void    transform P((void));
  1101. X
  1102. X/* special.c */
  1103. Xextern void    help P((void));
  1104. Xextern void    OpenLog P((void));
  1105. Xextern void    special P((void));
  1106. X
  1107. X/* run.c */
  1108. Xextern void    SwapOldNew P((void));
  1109. Xextern void    run P((void));
  1110. X
  1111. X/* polar.c */
  1112. Xextern void    MakePolar P((void));
  1113. X
  1114. X/* driver routines */
  1115. Xvoid    disp_init P((int, char**));
  1116. Xvoid    disp_finish P((void));
  1117. Xvoid    disp_imgstart P((void));
  1118. Xvoid    disp_imgend P((void));
  1119. Xvoid    disp_putline P((pixel_t *, int));
  1120. Xvoid    disp_error P((int, int));
  1121. Xvoid    disp_ungetc P((int));
  1122. Xvoid    disp_percentdone P((int));
  1123. Xint    disp_prompt P((void));
  1124. Xint    disp_getchar P((void));
  1125. X
  1126. X/* External variable declarations */
  1127. X
  1128. Xextern char ErrBuf[] ;
  1129. Xextern char *ProgName ;        /* Name of this program. */
  1130. Xextern char nextline[] ;       /* Next input line to be parsed. */
  1131. Xextern char text[] ;
  1132. Xextern char *LogFile ;         /* Name of file for logging commands */
  1133. X
  1134. Xextern FILE *Debug ;           /* Debugging stream */
  1135. Xextern FILE *LogStr ;          /* command logging stream */
  1136. X
  1137. Xextern double lexfract ;
  1138. X
  1139. Xextern short CUROLD ;
  1140. Xextern short CURNEW ;
  1141. X
  1142. Xextern long parsed[] ;
  1143. X
  1144. Xextern int CharPos ;           /* Position in input line. */
  1145. Xextern int OldPos ;
  1146. Xextern int RangeCheck ;
  1147. Xextern int Xsize ;
  1148. Xextern int Ysize ;
  1149. Xextern int Zsize ;
  1150. Xextern pixel_t Zmax ;
  1151. Xextern short *avals ;
  1152. Xextern int lat ;          /* Lookahead token. */
  1153. Xextern int lexval ;
  1154. Xextern int noerr ;        /* Indicates if an error has occured. */
  1155. Xextern int nsrc ;
  1156. Xextern int prs ;
  1157. Xextern short *rvals ;
  1158. Xextern int Verbose ;
  1159. Xextern void Skip() ;
  1160. Xextern int Truncate ;
  1161. X
  1162. Xextern struct SRC src[MAXIMG] ;
  1163. X
  1164. Xextern int disp_active ;       /* Display results after each operation. */
  1165. X
  1166. X#if       SEQPAR
  1167. Xextern int ncpus;          /* No. cpus to use in parallel */
  1168. X#endif /* SEQPAR */
  1169. X
  1170. X#endif    /* POPI_DEFINED */
  1171. Funky_Stuff
  1172. chmod 0444 popi.h || echo "restore of popi.h fails"
  1173. set `wc -c popi.h`;Sum=$1
  1174. if test "$Sum" != "9927"
  1175. then echo original size 9927, current size $Sum;fi
  1176. echo "x - extracting popi.icon (Text)"
  1177. sed 's/^X//' << 'Funky_Stuff' > popi.icon &&
  1178. X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
  1179. X */
  1180. X    0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x8000,0x0000,0x0001,0x0001,
  1181. X    0x8000,0x0000,0x0001,0x7F81,0x8000,0x0000,0x0001,0x30C1,
  1182. X    0x8000,0x0000,0x0001,0x3061,0x8000,0x0000,0x0001,0x3061,
  1183. X    0x8000,0x0000,0x0001,0x3061,0x8000,0x0000,0x0001,0x30C1,
  1184. X    0x8000,0x7600,0x0001,0x3781,0x8000,0xDF80,0x0001,0x3001,
  1185. X    0x8001,0x76E8,0x0001,0x3001,0x8001,0xFF00,0x0001,0x3001,
  1186. X    0x8002,0x7BFC,0x0001,0x3001,0x8002,0xDE03,0x0001,0x3001,
  1187. X    0x800A,0xD5F8,0x0001,0x3001,0x804A,0xBF45,0xC001,0x7801,
  1188. X    0x801A,0xE97C,0x0001,0x0001,0x81D3,0xAFEB,0x6001,0x0001,
  1189. X    0x823F,0xFBBE,0x1001,0x0F81,0x82EF,0xEAFF,0xF401,0x11C1,
  1190. X    0x857F,0xABFF,0x8401,0x20E1,0x857F,0xE87F,0xF801,0x6061,
  1191. X    0x87FF,0x007F,0xFE01,0x6061,0x8BFF,0x000F,0xF801,0x6061,
  1192. X    0x8FFC,0x0005,0xFE01,0x6061,0x87FE,0x01FF,0xFF01,0x7041,
  1193. X    0x8FFB,0xF37F,0xFE01,0x3881,0x87EF,0xF1E0,0xFF81,0x1F01,
  1194. X    0x8FF8,0xF1FE,0xFF81,0x0001,0x8FFF,0xB110,0x5D01,0x0001,
  1195. X    0x87E2,0xD0C4,0x5FC1,0x0001,0x8FEA,0x0010,0x3FC1,0x77C1,
  1196. X    0x87A0,0xA045,0x1FC1,0x38E1,0x87F4,0xA030,0x5F81,0x3071,
  1197. X    0x87D2,0x8001,0x3F81,0x3031,0x85D6,0xC014,0xBF81,0x3031,
  1198. X    0x87F0,0x39C5,0xBF01,0x3031,0x87DE,0x8F85,0xFE01,0x3031,
  1199. X    0x83EA,0x3FF4,0x3E01,0x3021,0x83FC,0xA85D,0xF801,0x3841,
  1200. X    0x81F7,0xFFE5,0xB801,0x3F81,0x81FE,0xA005,0xF801,0x3001,
  1201. X    0x807E,0x9007,0xF001,0x3001,0x807F,0x96C3,0xF801,0x3001,
  1202. X    0x80FE,0x8A8F,0xFC01,0x3001,0x80FF,0xCBA2,0xFE01,0x7801,
  1203. X    0x80FF,0xD69F,0xFF01,0x0001,0x807F,0xD5D7,0xFC01,0x0001,
  1204. X    0x81FF,0xF77F,0xFC01,0x0601,0x80FF,0xFDDF,0xFE01,0x0601,
  1205. X    0x80FF,0xEFFE,0xFE01,0x0001,0x81FE,0xFFFD,0xFF81,0x0001,
  1206. X    0x87FE,0xFFFD,0xFFC1,0x1E01,0x9FEF,0xBFF5,0xABF1,0x0601,
  1207. X    0xBFFB,0x7FDF,0xFFFD,0x0601,0xFFCF,0xD7F3,0xC7FF,0x0601,
  1208. X    0xFFFF,0xFFDF,0xFFFF,0x0601,0xFFFF,0x6FF7,0xFFFF,0x0601,
  1209. X    0xFFFF,0xFFFF,0xFFFF,0x0601,0xFFFF,0xEFCF,0xFFFF,0x0601,
  1210. X    0xFFFF,0xFFFF,0xFFFF,0x0601,0xFFFF,0xFFFF,0xFFFF,0x1F81,
  1211. X    0xFFFF,0xFFFF,0xFFFF,0x0001,0xFFFF,0xFFFF,0xFFFF,0xFFFF
  1212. Funky_Stuff
  1213. chmod 0444 popi.icon || echo "restore of popi.icon fails"
  1214. set `wc -c popi.icon`;Sum=$1
  1215. if test "$Sum" != "1933"
  1216. then echo original size 1933, current size $Sum;fi
  1217. echo "x - extracting popi.ps (Text)"
  1218. sed 's/^X//' << 'Funky_Stuff' > popi.ps &&
  1219. X
  1220. X%  @(#)popi.ps 1.5 89/12/04
  1221. X%
  1222. X%  NeWS dependent graphics routines used by the popi program.
  1223. X%  written by Rich Burridge - Sun Microsystems Australia.
  1224. X%
  1225. X%  Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
  1226. X%  This version is based on the code in his Prentice Hall book,
  1227. X%  "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
  1228. X%  which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
  1229. X%
  1230. X%  Permission is given to distribute these extensions, as long as these
  1231. X%  introductory messages are not removed, and no monies are exchanged.
  1232. X%
  1233. X%  No responsibility is taken for any errors on inaccuracies inherent
  1234. X%  either to the comments or the code of this program, but if reported
  1235. X%  to me, then an attempt will be made to fix them.
  1236. X
  1237. X/edef { exch def } def
  1238. X
  1239. X/PSDrawArea          % x y width height op => -
  1240. X{
  1241. X  5 dict begin
  1242. X    /Op edef
  1243. X    /Height edef
  1244. X    /Width edef
  1245. X    /Y edef
  1246. X    /Y CanvasHeight Y sub Height sub def
  1247. X    /X edef
  1248. X
  1249. X    Canvas setcanvas
  1250. X    newpath
  1251. X      X Y moveto
  1252. X      Width Height rect
  1253. X      Op [
  1254. X        GSET { 0 setgray }
  1255. X        GCLR { 1 setgray }
  1256. X      ] case
  1257. X    fill
  1258. X  end
  1259. X} def
  1260. X
  1261. X
  1262. X/PSDrawLine          % x1 y1 x2 y2 => -
  1263. X{
  1264. X  4 dict begin
  1265. X    /Y2 edef
  1266. X    /Y2 CanvasHeight Y2 sub def
  1267. X    /X2 edef
  1268. X    /Y1 edef
  1269. X    /Y1 CanvasHeight Y1 sub def
  1270. X    /X1 edef
  1271. X
  1272. X    Canvas setcanvas
  1273. X    0 setgray
  1274. X    X2 Y2 moveto X1 Y1 lineto stroke
  1275. X  end
  1276. X} def
  1277. X
  1278. X
  1279. X/PSDrawScanLine      % y => -
  1280. X{
  1281. X  /Y edef
  1282. X  /Y CanvasHeight Y sub 100 sub def
  1283. X
  1284. X  gsave
  1285. X    Canvas setcanvas
  1286. X    0 Y translate
  1287. X    512 1 scale
  1288. X    ScanLine imagecanvas
  1289. X  grestore
  1290. X} def
  1291. X
  1292. X
  1293. X/PSDrawText          % font x y text => -
  1294. X{
  1295. X  4 dict begin
  1296. X    /Text edef
  1297. X    /Y edef
  1298. X    /Y CanvasHeight Y sub def
  1299. X    /X edef
  1300. X    /Font edef
  1301. X
  1302. X    Canvas setcanvas
  1303. X    Font setfont
  1304. X    0 setgray
  1305. X    X Y moveto Text show
  1306. X  end
  1307. X} def
  1308. X
  1309. X
  1310. X/PSInitFonts         % - => -
  1311. X{
  1312. X  /NFont /Courier findfont 14 scalefont def
  1313. X  /BFont /Courier-Bold findfont 14 scalefont def
  1314. X} def
  1315. X
  1316. X
  1317. X/PSInitialise        % - => -
  1318. X{
  1319. X  /GCLR 0 def
  1320. X  /GSET 1 def
  1321. X  /KEYBOARD 100 def
  1322. X  /REPAINT  101 def
  1323. X  /BUSY_CUR 0 def
  1324. X  /NORMAL_CUR 1 def
  1325. X} def
  1326. X
  1327. X
  1328. X/PSIsColor           % - => iscolorscreen
  1329. X{
  1330. X  /Color? framebuffer /Color get def
  1331. X  Color? {1} {0} ifelse typedprint
  1332. X} def
  1333. X
  1334. X
  1335. X/PSLoadColor         % red green blue index => -
  1336. X{
  1337. X  4 dict begin
  1338. X    /ColorIndex edef
  1339. X    /BlueValue edef
  1340. X    /GreenValue edef
  1341. X    /RedValue edef
  1342. X
  1343. X    /CColor RedValue 255 div GreenValue 255 div BlueValue 255 div rgbcolor def
  1344. X    ColorTable ColorIndex CColor put
  1345. X  end
  1346. X} def
  1347. X
  1348. X
  1349. X/PSMakeColorTable    % size => -
  1350. X{
  1351. X  /TableSize edef
  1352. X  /ColorTable TableSize array def
  1353. X} def
  1354. X
  1355. X
  1356. X/PSMakeItems         % wx wy width height ix iy iconic => -
  1357. X{
  1358. X  [ /IsIcon /IconY /IconX /FrameHeight /FrameWidth /FrameY /FrameX ]
  1359. X  { exch def } forall
  1360. X  clippath pathbbox /ScreenHeight edef pop pop pop
  1361. X  /Frame framebuffer /new DefaultWindow send def
  1362. X  FrameX FrameY IconX IconY
  1363. X    {
  1364. X      [ /IconY /IconX /FrameY /FrameX ] { exch def } forall
  1365. X      /BorderTop 5 def
  1366. X      /BorderLeft 5 def
  1367. X      /BorderBottom 5 def
  1368. X      /BorderRight 5 def
  1369. X      /ControlSize 0 def
  1370. X      /PaintClient
  1371. X        {
  1372. X          REPAINT typedprint
  1373. X        } def
  1374. X      /PaintIcon
  1375. X        {
  1376. X          gsave
  1377. X            IconCanvas setcanvas
  1378. X            1 fillcanvas
  1379. X            clippath pathbbox
  1380. X            scale pop pop
  1381. X            0 setgray
  1382. X            true PopiIcon imagemaskcanvas
  1383. X          grestore
  1384. X        } def
  1385. X    } Frame send
  1386. X  FrameX
  1387. X  ScreenHeight FrameHeight sub FrameY sub
  1388. X  FrameWidth 10 add FrameHeight /reshape Frame send
  1389. X  /map Frame send
  1390. X
  1391. X  /Canvas Frame /ClientCanvas get def
  1392. X  Canvas
  1393. X      begin
  1394. X        /Transparent false def
  1395. X        /Mapped true def
  1396. X        /Retained true def
  1397. X      end
  1398. X  /CanvasHeight FrameHeight def
  1399. X
  1400. X  /KbdEvent
  1401. X    {
  1402. X      begin
  1403. X        Action /DownTransition eq
  1404. X          {
  1405. X            KEYBOARD typedprint Name typedprint
  1406. X          } if
  1407. X      end
  1408. X    } def
  1409. X  /EventMgrKbdInterest
  1410. X    {
  1411. X      [3 1 roll] { MakeEventMgrKbdInterest} append cvx
  1412. X    } def
  1413. X  /MakeEventMgrKbdInterest
  1414. X    {
  1415. X      addkbdinterests
  1416. X      { /ClientData 10 dict dup /CallBack 5 index put put } forall
  1417. X      pop
  1418. X    } def
  1419. X  /EventMgr
  1420. X    [
  1421. X      { KbdEvent } Canvas EventMgrKbdInterest
  1422. X    ] forkeventmgr def
  1423. X} def
  1424. X
  1425. X
  1426. X/PSSetCursor         % type => -
  1427. X{
  1428. X  [
  1429. X    BUSY_CUR   { /hourg /hourg_m }
  1430. X    NORMAL_CUR { /ptr /ptr_m }
  1431. X  ] case
  1432. X  Canvas setstandardcursor
  1433. X} def
  1434. Funky_Stuff
  1435. chmod 0444 popi.ps || echo "restore of popi.ps fails"
  1436. set `wc -c popi.ps`;Sum=$1
  1437. if test "$Sum" != "4365"
  1438. then echo original size 4365, current size $Sum;fi
  1439. echo "x - extracting run.c (Text)"
  1440. sed 's/^X//' << 'Funky_Stuff' > run.c &&
  1441. X/*  @(#)run.c 1.9 89/12/11
  1442. X *
  1443. X *  Run time interpreter used by the popi program.
  1444. X *
  1445. X *  Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
  1446. X *  This version is based on the code in his Prentice Hall book,
  1447. X *  "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
  1448. X *  which is copyright (c) 1988 by Bell Telephone Laboratories, Inc. 
  1449. X *
  1450. X *  Permission is given to distribute these extensions, as long as these
  1451. X *  introductory messages are not removed, and no monies are exchanged.
  1452. X *
  1453. X *  No responsibility is taken for any errors or inaccuracies inherent
  1454. X *  either to the comments or the code of this program, but if reported
  1455. X *  (see README file) then an attempt will be made to fix them.
  1456. X */
  1457. X
  1458. X#include <ctype.h>
  1459. X#include "popi.h"
  1460. X#if    SEQPAR
  1461. X#include <parallel/microtask.h>
  1462. X#endif    /* SEQPAR */
  1463. X
  1464. X#define    STACKSIZE    128
  1465. X
  1466. X#define  dop(OP)  a = *--sp ; tp = sp-1 ; *tp = (*tp OP (stack_t) a)
  1467. X
  1468. X/* local function prototypes */
  1469. Xvoid    prun P((void));
  1470. X
  1471. Xvoid
  1472. XSwapOldNew()
  1473. X{
  1474. X    CUROLD = CURNEW;
  1475. X    CURNEW = 1 - CUROLD;
  1476. X}
  1477. X
  1478. Xstatic void
  1479. Xprun()
  1480. X{
  1481. X    long    *ParseEnd;    /* after end of parse string */
  1482. X    int        x,
  1483. X        y;              /* coordinates */
  1484. X    int        nrange = 0;    /* no. range errors */
  1485. X
  1486. X    ParseEnd = &parsed[prs];
  1487. X
  1488. X    if (Debug)
  1489. X    {
  1490. X    register long
  1491. X        *CurrParse;    /* pointer to current item in parse string */
  1492. X    FPRINTF(Debug, "Parse string\n");
  1493. X    for (CurrParse = parsed; CurrParse != ParseEnd; ++CurrParse)
  1494. X        FPRINTF(Debug, "'%c' (%ld)\n", (char) *CurrParse, *CurrParse);
  1495. X    FPRINTF(Debug, "---\n");
  1496. X    }
  1497. X
  1498. X    /*
  1499. X     * Warning: Microsoft Quick C generates incorrect code
  1500. X     * for the following loop when optimisation is turned on.
  1501. X     */
  1502. X#ifndef SEQPAR
  1503. X    for (y = 0; y < Ysize; ++y)
  1504. X#else    /* ! SEQPAR */
  1505. X    for (y = m_myid; y < Ysize; y += m_numprocs)
  1506. X#endif    /* ! SEQPAR */
  1507. X    {
  1508. X    short    *ap,        /* precalculated polar angles */
  1509. X        *rp;        /* precalculated polar radius */
  1510. X    register pixel_t
  1511. X        *p;        /* default destination */
  1512. X
  1513. X    ap = &avals[y * Xsize];
  1514. X    rp = &rvals[y * Xsize];
  1515. X
  1516. X    p = src[CURNEW].pix[y];
  1517. X
  1518. X    DEBUG((Debug, "y = %d\n", y));
  1519. X    for (x = 0; x < Xsize; ++x, ++p)
  1520. X    {
  1521. X        stack_t
  1522. X        Stack[STACKSIZE];    /* the stack */
  1523. X        register stack_t
  1524. X        *sp,        /* stack pointer (top of stack) */
  1525. X        *tp;            /* temp stack pointer */
  1526. X        stack_t
  1527. X        a,
  1528. X        b;
  1529. X        int
  1530. X        c;              /* scratch */
  1531. X        register pixel_t
  1532. X        *u;        /* explicit destination */
  1533. X        register long
  1534. X        *CurrParse;    /* pointer to current item in parse string */
  1535. X
  1536. X        for (CurrParse = parsed, sp = Stack; CurrParse != ParseEnd; ++CurrParse)
  1537. X        {
  1538. X            if (*CurrParse == VALUE)
  1539. X        {
  1540. X            *sp++ = (stack_t) *++CurrParse;
  1541. X            continue;
  1542. X        }
  1543. X            if (*CurrParse == '@')
  1544. X        {
  1545. X            --sp;
  1546. X            if (Truncate)
  1547. X            {
  1548. X            if (*sp > Zmax)
  1549. X                *sp = Zmax;
  1550. X            else if (*sp < 0)
  1551. X                *sp = 0;
  1552. X            }
  1553. X            *p = (pixel_t) *sp;
  1554. X            continue;
  1555. X        }
  1556. X            switch ((int) *CurrParse)
  1557. X        {
  1558. X            case '+':
  1559. X            dop(+);
  1560. X            break;
  1561. X            case '-':
  1562. X            dop(-);
  1563. X            break;
  1564. X            case '*':
  1565. X            dop(*);
  1566. X            break;
  1567. X            case '/':
  1568. X            a = *--sp;
  1569. X            tp = sp-1;
  1570. X            if (a == 0)
  1571. X                *tp = Zmax;
  1572. X            else
  1573. X                *tp = (*tp / (stack_t) a);
  1574. X            break;
  1575. X            case '%':
  1576. X            a = *--sp;
  1577. X            tp = sp-1;
  1578. X            if (a == 0)
  1579. X                *tp = 0;
  1580. X            else
  1581. X                *tp = (*tp % (stack_t) a);
  1582. X            break;
  1583. X            case '>':
  1584. X            dop(>);
  1585. X            break;
  1586. X            case '<':
  1587. X            dop(<);
  1588. X            break;
  1589. X            case GE:
  1590. X            dop(>=);
  1591. X            break;
  1592. X            case LE:
  1593. X            dop(<=);
  1594. X            break;
  1595. X            case EQ:
  1596. X            dop(==);
  1597. X            break;
  1598. X            case NE:
  1599. X            dop(!=);
  1600. X            break;
  1601. X            case AND:
  1602. X            dop(&&);
  1603. X            break;
  1604. X            case OR:
  1605. X            dop(||);
  1606. X            break;
  1607. X            case '^':
  1608. X            dop(^);
  1609. X            break;
  1610. X            case '|':
  1611. X            dop(|);
  1612. X            break;
  1613. X            case '&':
  1614. X            dop(&);
  1615. X            break;
  1616. X            case 'x':
  1617. X            *sp++ = (stack_t) x;
  1618. X            break;
  1619. X            case 'y':
  1620. X            *sp++ = (stack_t) y;
  1621. X            break;
  1622. X            case UMIN:
  1623. X            tp = sp-1;
  1624. X            *tp = -(*tp);
  1625. X            break;
  1626. X            case '!':
  1627. X            tp = sp-1;
  1628. X            *tp = !(*tp);
  1629. X            break;
  1630. X            case '=':
  1631. X            a = *--sp;
  1632. X            u = (pixel_t *) *--sp;
  1633. X            if (Truncate)
  1634. X            {
  1635. X                if (a > Zmax)
  1636. X                a = Zmax;
  1637. X                else if (a < 0)
  1638. X                a = 0;
  1639. X            }
  1640. X            *u = (pixel_t) a;
  1641. X            break;
  1642. X            case CRVAL:
  1643. X            a = *--sp;        /* y */
  1644. X            b = *--sp;        /* x */
  1645. X            tp = sp-1;
  1646. X            c = (int) *tp;
  1647. X            *tp = (stack_t) src[c].pix[a][b];
  1648. X            break;
  1649. X            case CLVAL:
  1650. X            a = *--sp;        /* y */
  1651. X            b = *--sp;        /* x */
  1652. X            tp = sp-1;
  1653. X            c = (int) *tp;
  1654. X            if
  1655. X            (
  1656. X                RangeCheck &&
  1657. X                (
  1658. X                a > Xsize - 1 || a < 0
  1659. X                ||
  1660. X                b > Ysize - 1 || b < 0
  1661. X                )
  1662. X            )
  1663. X            {
  1664. X                if (nrange++ == 0)
  1665. X                FPRINTF(stderr,
  1666. X                    "Range err at (%d,%d) => %s[%d, %d]\n",
  1667. X                    x, y, src[c].str, b, a);
  1668. X            }
  1669. X            if (a >= Ysize)
  1670. X                a = Ysize - 1;
  1671. X            if (a < 0)
  1672. X                a = 0;
  1673. X            if (b >= Xsize)
  1674. X                b = Xsize - 1;
  1675. X            if (b < 0)
  1676. X                b = 0;
  1677. X            *tp = (stack_t) &(src[c].pix[a][b]);
  1678. X            break;
  1679. X            case PRVAL:
  1680. X            {
  1681. X                int        xval,
  1682. X                    yval;
  1683. X
  1684. X                a = *--sp;        /* angle */
  1685. X                b = *--sp;        /* radius */
  1686. X
  1687. X                xval = (int) (b * cos((double) DtoR(a)) + Xsize / 2.0);
  1688. X                yval = (int) (- b * sin((double) DtoR(a)) + Ysize / 2.0);
  1689. X
  1690. X                tp = sp - 1;
  1691. X                c = (int) *tp;
  1692. X
  1693. X                if (RangeCheck &&
  1694. X                (xval < 0 || xval >= Xsize ||
  1695. X                yval < 0 || yval >= Ysize))
  1696. X                {
  1697. X                if (nrange++ == 0)
  1698. X                    FPRINTF(stderr,
  1699. X                    "Range err at (%d,%d) => %s{%d,%d} [%d,%d]\n",
  1700. X                    x, y, src[c].str, b, a, xval, yval);
  1701. X                }
  1702. X
  1703. X                if (xval < 0)
  1704. X                xval = 0;
  1705. X                if (xval >= Xsize)
  1706. X                xval = Xsize - 1;
  1707. X                if (yval < 0)
  1708. X                yval = 0;
  1709. X                if (yval >= Ysize)
  1710. X                yval = Ysize - 1;
  1711. X
  1712. X                *tp = (stack_t) src[c].pix[yval][xval];
  1713. X            }
  1714. X            break;
  1715. X
  1716. X            case PLVAL:
  1717. X            {
  1718. X                int        xval,
  1719. X                    yval;
  1720. X
  1721. X                a = *--sp;        /* angle */
  1722. X                b = *--sp;        /* radius */
  1723. X
  1724. X                xval = (int) (b * cos((double) DtoR(a)) + Xsize / 2.0);
  1725. X                yval = (int) (- b * sin((double) DtoR(a)) + Ysize / 2.0);
  1726. X
  1727. X                tp = sp - 1;
  1728. X                c = (int) *tp;
  1729. X
  1730. X                if (RangeCheck &&
  1731. X                (xval < 0 || xval >= Xsize ||
  1732. X                yval < 0 || yval >= Ysize))
  1733. X                {
  1734. X                if (nrange++ == 0)
  1735. X                    FPRINTF(stderr,
  1736. X                    "Range err at (%d,%d) => %s{%d,%d} [%d,%d]\n",
  1737. X                    x, y, src[c].str, b, a, xval, yval);
  1738. X                }
  1739. X
  1740. X                if (xval < 0)
  1741. X                xval = 0;
  1742. X                if (xval >= Xsize)
  1743. X                xval = Xsize - 1;
  1744. X                if (yval < 0)
  1745. X                yval = 0;
  1746. X                if (yval >= Ysize)
  1747. X                yval = Ysize - 1;
  1748. X
  1749. X                *tp = (stack_t) &(src[c].pix[yval][xval]);
  1750. X            }
  1751. X            break;
  1752. X
  1753. X            case POW:
  1754. X            a = *--sp;    /* exponent */
  1755. X            tp = sp-1;
  1756. X            *tp = (stack_t) pow((double) *tp, (double) a);
  1757. X            break;
  1758. X            case 'a':
  1759. X#if    NOMEM
  1760. X            *sp++ = (stack_t)
  1761. X                RtoD(atan2((double) y, (double) x)) + 0.5;
  1762. X#else    /* !NOMEM */
  1763. X            *sp++ = (stack_t) *ap;
  1764. X#endif    /* !NOMEM */
  1765. X            break;
  1766. X            case 'r':
  1767. X            *sp++ = (stack_t) *rp;
  1768. X            break;
  1769. X            case SIN:
  1770. X            tp = sp-1;
  1771. X            *tp = (stack_t) (sin((double) DtoR(*tp)) * (double)Zmax);
  1772. X            break;
  1773. X            case COS:
  1774. X            tp = sp-1;
  1775. X            *tp = (stack_t) (cos((double) DtoR(*tp)) * (double)Zmax);
  1776. X            break;
  1777. X            case ATAN:
  1778. X            a = *--sp;
  1779. X            tp = sp-1;
  1780. X            *tp = (stack_t) RtoD(atan2((double) *tp, (double) a));
  1781. X            break;
  1782. X            case HYPOT:
  1783. X            a = *--sp;
  1784. X            tp = sp - 1;
  1785. X            *tp = (stack_t) hypot((double) *tp, (double) a);
  1786. X            break;
  1787. X            case ABS:
  1788. X            tp = sp-1;
  1789. X            *tp = *tp < 0 ? - *tp : *tp;
  1790. X            break;
  1791. X            case LOG:
  1792. X            tp = sp-1;
  1793. X            *tp = (stack_t) log((double) *tp);
  1794. X            break;
  1795. X            case SQRT:
  1796. X            tp = sp-1;
  1797. X            *tp = (stack_t) sqrt((double) *tp);
  1798. X            break;
  1799. X            case RAND:
  1800. X#if 0
  1801. X            tp = sp -1;
  1802. X            *tp = (stack_t) RANDOM % *tp;
  1803. X#else
  1804. X            *sp++ = (stack_t) RANDOM;
  1805. X#endif
  1806. X            break;
  1807. X            case LSHIFT:
  1808. X            dop(<<);
  1809. X            break;
  1810. X            case RSHIFT:
  1811. X            dop(>>);
  1812. X            break;
  1813. X            case '?':
  1814. X            a = *--sp;
  1815. X            CurrParse++;
  1816. X            if (!a)
  1817. X                CurrParse = &parsed[*CurrParse];
  1818. X            break;
  1819. X            case ':':
  1820. X            CurrParse = &parsed[CurrParse[1]];
  1821. X            break;
  1822. X
  1823. X            default:
  1824. X            if (*CurrParse < 127 && isprint(*CurrParse))
  1825. X                SPRINTF(ErrBuf, "run: unknown operator '%c' (%d)",
  1826. X                *CurrParse, *CurrParse);
  1827. X            else
  1828. X                SPRINTF(ErrBuf, "run: unknown operator %d", *CurrParse);
  1829. X            error(ERR_SNARK);
  1830. X            return;
  1831. X        }
  1832. X        }
  1833. X        ++ap;
  1834. Funky_Stuff
  1835. echo "End of part 3"
  1836. echo "File run.c is continued in part 4"
  1837. echo "4" > s2_seq_.tmp
  1838. exit 0
  1839.  
  1840.