home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume13 / faces-1.4.5 / part07 < prev    next >
Text File  |  1990-07-02  |  53KB  |  1,891 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v13i076: Faces v1.4.5: a visual list monitor for mail etc.. (Part 7 of 7).
  3. from: rburridge@Sun.COM (Rich Burridge)
  4. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5.  
  6. Posting-number: Volume 13, Issue 76
  7. Submitted-by: rburridge@Sun.COM (Rich Burridge)
  8. Archive-name: faces-1.4.5/part07
  9.  
  10. ------CUT HERE------faces.part7-----CUT HERE------
  11. #! /bin/sh
  12. # this is a shell archive, meaning:
  13. # 1. Remove everything above the #! /bin/sh line
  14. # 2. Save the resulting text in a file.
  15. # 3. Execute the file with /bin/sh to create the files:
  16. #    compface (directory)
  17. # This archive created: Fri Jun 29 10:45:27 EST 1990
  18. #
  19. #
  20. export PATH; PATH=/bin:$PATH
  21. #
  22. if [ -f compface ]
  23. then
  24. echo shar: can not write a directory over file compface
  25. else
  26. if [ ! -d compface ]
  27. then
  28. echo shar: creating directory compface
  29. mkdir compface
  30. fi
  31. echo shar: entering directory compface
  32. cd compface
  33. if [ -f Makefile ]
  34. then
  35. echo shar: will not over-write existing file Makefile
  36. else
  37. echo shar: extracting 'Makefile',     2054 characters
  38. cat > Makefile <<'Funky_Stuff'
  39. #
  40. #  Compface - 48x48x1 image compression and decompression
  41. #
  42. #  Copyright (c) James Ashton - Sydney University - June 1990.
  43. #
  44. #  Written 11th November 1989.
  45. #
  46. #  Permission is given to distribute these sources, as long as the
  47. #  copyright messages are not removed, and no monies are exchanged. 
  48. #
  49. #  No responsibility is taken for any errors on inaccuracies inherent
  50. #  either to the comments or the code of this program, but if reported
  51. #  to me, then an attempt will be made to fix them.
  52.  
  53. # BINDIR, LIBDIR, and MANDIR are expected to be overridden by the
  54. # calling Makefile
  55.  
  56. BINDIR        = /usr/local/bin
  57. LIBDIR        = /usr/local/lib
  58. MANDIR        = /usr/manl
  59.  
  60. NAME        = compface
  61. UNNAME        = uncompface
  62. EXECUTABLE    = $(BINDIR)/$(NAME)
  63. UNEXECUTABLE    = $(BINDIR)/$(UNNAME)
  64. LIBNAME        = lib$(NAME).a
  65. LIBRARY        = $(LIBDIR)/$(LIBNAME)
  66. MAN1DIR        = $(MANDIR)/man1
  67. MAN3DIR        = $(MANDIR)/man3
  68. OBJECTS        = compface.o arith.o file.o compress.o gen.o
  69. SOURCES        = compface.c arith.c file.c compress.c gen.c main.c
  70. HDRS        = compface.h data.h
  71. OTHERS        = README $(NAME).1 $(NAME).3 Makefile
  72.  
  73. CFLAGS        = -g
  74.  
  75. $(NAME) :    main.o $(LIBNAME)
  76.         cc $(CFLAGS) -o $(NAME) main.o $(LIBNAME)
  77.         rm -f $(UNNAME)
  78.         ln $(NAME) $(UNNAME)
  79.  
  80. $(LIBNAME) :    $(OBJECTS)
  81.         ar rc $(LIBNAME) $(OBJECTS)
  82.         ranlib $(LIBNAME)
  83.  
  84. lint :
  85.         lint -abchx $(SOURCES)
  86.  
  87. clean :
  88.         rm -f *.o
  89.  
  90. clobber :
  91.         rm -f *.o *.a *.sh core a.out $(NAME) $(UNNAME)
  92.  
  93. install :    $(NAME) $(LIBNAME)
  94.         -cp $(NAME) $(EXECUTABLE)
  95.         strip $(EXECUTABLE)
  96.         rm -f $(UNEXECUTABLE)
  97.         ln $(EXECUTABLE) $(UNEXECUTABLE)
  98.         -cp $(NAME).1 $(MAN1DIR)
  99.         rm -f $(MAN1DIR)1/$(UNNAME).1
  100.         -ln $(MAN1DIR)/$(NAME).1 $(MAN1DIR)/$(UNNAME).1
  101.         -cp $(LIBNAME) $(LIBRARY)
  102.         -cp $(NAME).3 $(MAN3DIR)
  103.         rm -f $(MAN3DIR)/$(UNNAME).3
  104.         -ln $(MAN3DIR)/$(NAME).3 $(MAN3DIR)/$(UNNAME).3
  105.  
  106. shar :
  107.         shar.script $(OTHERS) $(HDRS) $(SOURCES) > $(NAME).sh
  108.         compress $(NAME).sh
  109.  
  110. arith.o:    arith.c compface.h data.h
  111. compface.o:    compface.c compface.h data.h
  112. compress.o:    compress.c compface.h data.h
  113. file.o:        file.c compface.h data.h
  114. gen.o:        gen.c compface.h data.h
  115. main.o:        main.c compface.h data.h
  116. Funky_Stuff
  117. len=`wc -c < Makefile`
  118. if [ $len !=     2054 ] ; then
  119. echo error: Makefile was $len bytes long, should have been     2054
  120. fi
  121. fi # end of overwriting check
  122. if [ -f README ]
  123. then
  124. echo shar: will not over-write existing file README
  125. else
  126. echo shar: extracting 'README',     1212 characters
  127. cat > README <<'Funky_Stuff'
  128. Compface - 48x48x1 image compression and decompression
  129. Copyright (c) James Ashton 1990.
  130. Written 89/11/11
  131.  
  132. Feel free to distribute this source at will so long as the above
  133. message and this message are included in full.
  134.  
  135. The programme (two programmes really - but they're just links to each
  136. other) converts 48x48x1 images to and from a compressed format.  The
  137. uncompressed images are expected to contain 48x48/4 (576) hex digits.
  138. All other characters and any `0's followed by `X' or `x' are ignored.
  139. Usually the files are 48 lines of "0x%04X,0x%04X,0x%04X,".  The
  140. compressed images contain some number of printable characters.  Non
  141. printable characters, including ` ' are ignored.  The purpose of the
  142. programme is to allow the inclusion of face images within mail headers
  143. using the field name `X-face: '.
  144.  
  145. The programmes make use of a library which can be used to allow the
  146. compression and decompression algorithms to be used in other
  147. programmes such as mail despatchers and mail notification daemons.
  148.  
  149. A small amount of editing in the Makefile may be required to get it
  150. going - mainly setting EXECUTABLE to what you want and putting the
  151. manual entry in the right place.
  152.  
  153.                         James Ashton.
  154.                         jaa@cs.su.oz.au
  155. Funky_Stuff
  156. len=`wc -c < README`
  157. if [ $len !=     1212 ] ; then
  158. echo error: README was $len bytes long, should have been     1212
  159. fi
  160. fi # end of overwriting check
  161. if [ -f arith.c ]
  162. then
  163. echo shar: will not over-write existing file arith.c
  164. else
  165. echo shar: extracting 'arith.c',     3764 characters
  166. cat > arith.c <<'Funky_Stuff'
  167. /*
  168.  *  Compface - 48x48x1 image compression and decompression
  169.  *
  170.  *  Copyright (c) James Ashton - Sydney University - June 1990.
  171.  *
  172.  *  Written 11th November 1989.
  173.  *
  174.  *  Permission is given to distribute these sources, as long as the
  175.  *  copyright messages are not removed, and no monies are exchanged. 
  176.  *
  177.  *  No responsibility is taken for any errors on inaccuracies inherent
  178.  *  either to the comments or the code of this program, but if reported
  179.  *  to me, then an attempt will be made to fix them.
  180.  */
  181.  
  182. #include "compface.h"
  183.  
  184. void RevPush(p)
  185. Prob *p;
  186. {
  187.     if (NumProbs >= PIXELS * 2 - 1)
  188.         longjmp(comp_env, ERR_INTERNAL);
  189.     ProbBuf[NumProbs++] = p;
  190. }
  191.  
  192. void BigPush(p)
  193. Prob *p;
  194. {
  195.     static WORD tmp;
  196.  
  197.     BigDiv(p->p_range, &tmp);
  198.     BigMul(0);
  199.     BigAdd(tmp + p->p_offset);
  200. }
  201.  
  202. BigPop(p)
  203. register Prob *p; 
  204. {
  205.     static WORD tmp;
  206.     register int i;
  207.  
  208.     BigDiv(0, &tmp);
  209.     i = 0;
  210.     while ((tmp < p->p_offset) || (tmp >= p->p_range + p->p_offset))
  211.     {
  212.         p++;
  213.         i++;
  214.     }
  215.     BigMul(p->p_range);
  216.     BigAdd(tmp - p->p_offset);
  217.     return i;
  218. }
  219.  
  220. #ifdef DEBUG
  221. /* Print a BigInt in HexaDecimal
  222.  */
  223. void BigPrint()
  224. {
  225.     register int i, c, count;
  226.     register WORD *w;
  227.  
  228.     count = 0;
  229.     w = B.b_word + (i = B.b_words);
  230.     while (i--)
  231.     {
  232.         w--;
  233.         c = *((*w >> 4) + HexDigits);
  234.         putc(c, stderr);
  235.         c = *((*w & 0xf) + HexDigits);
  236.         putc(c, stderr);
  237.         if (++count >= 36)
  238.         {
  239.             putc('\\', stderr);
  240.             putc('\n', stderr);
  241.             count = 0;
  242.         }
  243.     }
  244.     putc('\n', stderr);
  245. }
  246. #endif
  247.  
  248. /* Divide B by a storing the result in B and the remainder in the word
  249.  * pointer to by r
  250.  */
  251. void BigDiv(a, r)
  252. register WORD a, *r;
  253. {
  254.     register int i;
  255.     register WORD *w;
  256.     register COMP c, d;
  257.  
  258.     a &= WORDMASK;
  259.     if ((a == 1) || (B.b_words == 0))
  260.     {
  261.         *r = 0;
  262.         return;
  263.     }
  264.     if (a == 0)    /* treat this as a == WORDCARRY */
  265.     {            /* and just shift everything right a WORD */
  266.         i = --B.b_words;
  267.         w = B.b_word;
  268.         *r = *w;
  269.         while (i--)
  270.         {
  271.             *w = *(w + 1);
  272.             w++;
  273.         }
  274.         *w = 0;
  275.         return;
  276.     }
  277.     w = B.b_word + (i = B.b_words);
  278.     c = 0;
  279.     while (i--)
  280.     {
  281.         c <<= BITSPERWORD;
  282.         c += (COMP)*--w;
  283.         d = c / (COMP)a;
  284.         c = c % (COMP)a;
  285.         *w = (WORD)(d & WORDMASK);
  286.     }
  287.     *r = c;
  288.     if (B.b_word[B.b_words - 1] == 0)
  289.         B.b_words--;
  290. }
  291.  
  292. /* Multiply a by B storing the result in B
  293.  */
  294. void BigMul(a)
  295. register WORD a;
  296. {
  297.     register int i;
  298.     register WORD *w;
  299.     register COMP c;
  300.  
  301.     a &= WORDMASK;
  302.     if ((a == 1) || (B.b_words == 0))
  303.         return;
  304.     if (a == 0)    /* treat this as a == WORDCARRY */
  305.     {            /* and just shift everything left a WORD */
  306.         if ((i = B.b_words++) >= MAXWORDS - 1)
  307.             longjmp(comp_env, ERR_INTERNAL);
  308.         w = B.b_word + i;
  309.         while (i--)
  310.         {
  311.             *w = *(w - 1);
  312.             w--;
  313.         }
  314.         *w = 0;
  315.         return;
  316.     }
  317.     i = B.b_words;
  318.     w = B.b_word;
  319.     c = 0;
  320.     while (i--)
  321.     {
  322.         c += (COMP)*w * (COMP)a;
  323.         *(w++) = (WORD)(c & WORDMASK);
  324.         c >>= BITSPERWORD;
  325.     }
  326.     if (c)
  327.     {
  328.         if (B.b_words++ >= MAXWORDS)
  329.             longjmp(comp_env, ERR_INTERNAL);
  330.         *w = (COMP)(c & WORDMASK);
  331.     }
  332. }
  333.  
  334. #if 0
  335. /* Subtract a from B storing the result in B
  336.  */
  337. void BigSub(a)
  338. WORD a;
  339. {
  340.     register int i;
  341.     register WORD *w;
  342.     register COMP c;
  343.  
  344.     a &= WORDMASK;
  345.     if (a == 0)
  346.         return;
  347.     i = 1;
  348.     w = B.b_word;
  349.     c = (COMP)*w - (COMP)a;
  350.     *w = (WORD)(c & WORDMASK);
  351.     while (c & WORDCARRY)
  352.     {
  353.         if (i >= B.b_words)
  354.             longjmp(comp_env, ERR_INTERNAL);
  355.         c = (COMP)*++w - 1;
  356.         *w = (WORD)(c & WORDMASK);
  357.         i++;
  358.     }
  359.     if ((i == B.b_words) && (*w == 0) && (i > 0))
  360.         B.b_words--;
  361. }
  362. #endif
  363.  
  364. /* Add to a to B storing the result in B
  365.  */
  366. void BigAdd(a)
  367. WORD a;
  368. {
  369.     register int i;
  370.     register WORD *w;
  371.     register COMP c;
  372.  
  373.     a &= WORDMASK;
  374.     if (a == 0)
  375.         return;
  376.     i = 1;
  377.     w = B.b_word;
  378.     c = (COMP)*w + (COMP)a;
  379.     *w = (WORD)(c & WORDMASK);
  380.     while (c & WORDCARRY)
  381.     {
  382.         c = (COMP)*++w + 1;
  383.         *w = (WORD)(c & WORDMASK);
  384.         i++;
  385.     }
  386.     if (i > B.b_words)
  387.         if (B.b_words++ >= MAXWORDS)
  388.             longjmp(comp_env, ERR_INTERNAL);
  389.         *w = (COMP)(c & WORDMASK);
  390. }
  391. Funky_Stuff
  392. len=`wc -c < arith.c`
  393. if [ $len !=     3764 ] ; then
  394. echo error: arith.c was $len bytes long, should have been     3764
  395. fi
  396. fi # end of overwriting check
  397. if [ -f compface.1 ]
  398. then
  399. echo shar: will not over-write existing file compface.1
  400. else
  401. echo shar: extracting 'compface.1',     2006 characters
  402. cat > compface.1 <<'Funky_Stuff'
  403. .TH COMPFACE 1 "25 January 1990"
  404. .SH NAME
  405. compface, uncompface \- compress and expand 48x48x1 face image files
  406. .SH SYNOPSIS
  407. .B compface
  408. [
  409. .I infile
  410. [
  411. .I outfile
  412. ]
  413. ]
  414. .LP
  415. .B uncompface
  416. [
  417. .I infile
  418. [
  419. .I outfile
  420. ]
  421. ]
  422. .SH DESCRIPTION
  423. .IX  compface  ""  "\fLcompface\fP \(em compress face image files"
  424. .IX  uncompface  ""  "\fLuncompface\fP \(em uncompress face image files"
  425. .I compface
  426. is a filter for generating highly compressed representations of 48x48x1
  427. face image files.
  428. .I uncompface
  429. is an inverse filter which performs an inverse transformation with no
  430. loss of data.
  431. The algorithm used is highly tuned for its purpose and achieves better
  432. than a five to one compression ratio on average.
  433. Arguments operate identically for both programmes.
  434. The first argument, if present, causes input to be taken from the named
  435. file instead of from standard input unless it is the string ``-''.
  436. A second argument, if present, causes output to go to the named file
  437. instead of to standard output.
  438. .LP
  439. The input format for
  440. .I compface
  441. (and the output format for
  442. .IR uncompface )
  443. is 48 lines each of 3 sixteen bit hexadecimal integers, comma terminated in C
  444. initialiser style.
  445. The output format of
  446. .I compface
  447. (and the input format for
  448. .IR uncompface )
  449. is some number of lines made up of a space followed by printable
  450. characters (in the range ``!'' to ``~'' inclusive).
  451. The first line contains 72 characters and following lines contain
  452. 79 characters except that the last line may be short.
  453. .LP
  454. The amount of compression obtained varies between face image files but
  455. the output of
  456. .I compface
  457. averages less than 200 characters.
  458. The average number of output lines is three.
  459. .SH DIAGNOSTICS
  460. Exit status is normally 0.
  461. Possible errors include IO errors when opening, reading or writing
  462. files, format errors in
  463. .I compface
  464. input files and invalid arguments.
  465. Each results in an explanatory message on standard error and an exit status
  466. of 1.
  467. A warning will be produced if
  468. .I compface
  469. detects extra input data.
  470. .SH SEE ALSO
  471. Compface(3)
  472. Funky_Stuff
  473. len=`wc -c < compface.1`
  474. if [ $len !=     2006 ] ; then
  475. echo error: compface.1 was $len bytes long, should have been     2006
  476. fi
  477. fi # end of overwriting check
  478. if [ -f compface.3 ]
  479. then
  480. echo shar: will not over-write existing file compface.3
  481. else
  482. echo shar: extracting 'compface.3',     1834 characters
  483. cat > compface.3 <<'Funky_Stuff'
  484. .TH COMPFACE 3 "25 January 1990"
  485. .SH NAME
  486. compface, uncompface \- compress and expand 48x48x1 face image files
  487. .SH SYNOPSIS
  488. .B compface (buf)
  489. .LP
  490. .B uncompface (buf)
  491. .LP
  492. .B char *buf
  493. .SH DESCRIPTION
  494. .IX  compface  ""  "\fLcompface\fP \(em compress face image files"
  495. .IX  uncompface  ""  "\fLuncompface\fP \(em uncompress face image files"
  496. .I compface
  497. is a function for generating highly compressed representations of 48x48x1
  498. face image files.
  499. .I uncompface
  500. is an inverse function which performs an inverse transformation with no
  501. loss of data.
  502. The algorithm used is highly tuned for its purpose and achieves better
  503. than a five to one compression ratio on average.
  504. In both functions, input is via a NULL terminated string and a NULL terminated
  505. output string is written over the input string.
  506. .I Buf
  507. should therefore point to a block of 2K size or more to avoid buffer
  508. overruns during output generation.
  509. .LP
  510. The input format for
  511. .I compface
  512. (and the output format for
  513. .IR uncompface )
  514. is 48 lines each of 3 sixteen bit hexadecimal integers, comma terminated in C
  515. initialiser style.
  516. The output format of
  517. .I compface
  518. (and the input format for
  519. .IR uncompface )
  520. is some number of lines made up of a space followed by printable
  521. characters (in the range ``!'' to ``~'' inclusive).
  522. The first line contains 72 characters and following lines contain
  523. 79 characters except that the last line may be short.
  524. .LP
  525. The amount of compression obtained varies between face image files but
  526. the output of
  527. .I compface
  528. averages less than 200 characters.
  529. The average number of output lines is three.
  530. .SH DIAGNOSTICS
  531. The return value is normally 0.
  532. 1 will be returned if extra input has been ignored during a compress operation.
  533. -1 is returned in the case of an invalid input format.
  534. -2 is returned if an internal buffer overrun occurs.
  535. .SH SEE ALSO
  536. Compface(1)
  537. Funky_Stuff
  538. len=`wc -c < compface.3`
  539. if [ $len !=     1834 ] ; then
  540. echo error: compface.3 was $len bytes long, should have been     1834
  541. fi
  542. fi # end of overwriting check
  543. if [ -f compface.c ]
  544. then
  545. echo shar: will not over-write existing file compface.c
  546. else
  547. echo shar: extracting 'compface.c',      850 characters
  548. cat > compface.c <<'Funky_Stuff'
  549. /*
  550.  *  Compface - 48x48x1 image compression and decompression
  551.  *
  552.  *  Copyright (c) James Ashton - Sydney University - June 1990.
  553.  *
  554.  *  Written 11th November 1989.
  555.  *
  556.  *  Permission is given to distribute these sources, as long as the
  557.  *  copyright messages are not removed, and no monies are exchanged. 
  558.  *
  559.  *  No responsibility is taken for any errors on inaccuracies inherent
  560.  *  either to the comments or the code of this program, but if reported
  561.  *  to me, then an attempt will be made to fix them.
  562.  */
  563.  
  564. #define MAIN
  565.  
  566. #include "compface.h"
  567.  
  568. uncompface(fbuf)
  569. char *fbuf;
  570. {
  571.     if (!(status = setjmp(comp_env)))
  572.     {
  573.         UnCompAll(fbuf);/* compress otherwise */
  574.         UnGenFace();
  575.         WriteFace(fbuf);
  576.     }
  577.     return status;
  578. }
  579.  
  580. compface(fbuf)
  581. char *fbuf;
  582. {
  583.     if (!(status = setjmp(comp_env)))
  584.     {
  585.         ReadFace(fbuf);
  586.         GenFace();
  587.         CompAll(fbuf);
  588.     }
  589.     return status;
  590. }
  591. Funky_Stuff
  592. len=`wc -c < compface.c`
  593. if [ $len !=      850 ] ; then
  594. echo error: compface.c was $len bytes long, should have been      850
  595. fi
  596. fi # end of overwriting check
  597. if [ -f compface.h ]
  598. then
  599. echo shar: will not over-write existing file compface.h
  600. else
  601. echo shar: extracting 'compface.h',     4663 characters
  602. cat > compface.h <<'Funky_Stuff'
  603. /*
  604.  *  Compface - 48x48x1 image compression and decompression
  605.  *
  606.  *  Copyright (c) James Ashton - Sydney University - June 1990.
  607.  *
  608.  *  Written 11th November 1989.
  609.  *
  610.  *  Permission is given to distribute these sources, as long as the
  611.  *  copyright messages are not removed, and no monies are exchanged. 
  612.  *
  613.  *  No responsibility is taken for any errors on inaccuracies inherent
  614.  *  either to the comments or the code of this program, but if reported
  615.  *  to me, then an attempt will be made to fix them.
  616.  */
  617.  
  618. #include <strings.h>
  619. #include <fcntl.h>
  620. #include <setjmp.h>
  621.  
  622. #ifdef MAIN
  623. #define EXTERN
  624. #define INIT(x) = x
  625. #else
  626. #define EXTERN extern
  627. #define INIT(x)
  628. #endif
  629.  
  630. /* need to know how many bits per hexadecimal digit for io */
  631. #define BITSPERDIG 4
  632. EXTERN char HexDigits[] INIT("0123456789ABCDEF");
  633.  
  634. /* define the face size - 48x48x1 */
  635. #define WIDTH 48
  636. #define HEIGHT WIDTH
  637.  
  638. /* total number of pixels and digits */
  639. #define PIXELS (WIDTH * HEIGHT)
  640. #define DIGITS (PIXELS / BITSPERDIG)
  641.  
  642. /* internal face representation - 1 char per pixel is faster */
  643. EXTERN char F[PIXELS];
  644.  
  645. /* output formatting word lengths and line lengths */
  646. #define DIGSPERWORD 4
  647. #define WORDSPERLINE (WIDTH / DIGSPERWORD / BITSPERDIG)
  648.  
  649. /* compressed output uses the full range of printable characters.
  650.  * in ascii these are in a contiguous block so we just need to know
  651.  * the first and last.  The total number of printables is needed too */
  652. #define FIRSTPRINT '!'
  653. #define LASTPRINT '~'
  654. #define NUMPRINTS (LASTPRINT - FIRSTPRINT + 1)
  655.  
  656. /* output line length for compressed data */
  657. #define MAXLINELEN 78
  658.  
  659. /* Portable, very large unsigned integer arithmetic is needed.
  660.  * Implementation uses arrays of WORDs.  COMPs must have at least
  661.  * twice as many bits as WORDs to handle intermediate results */
  662. #define WORD unsigned char
  663. #define COMP unsigned long
  664. #define BITSPERWORD 8
  665. #define WORDCARRY (1 << BITSPERWORD)
  666. #define WORDMASK (WORDCARRY - 1)
  667. #define MAXWORDS ((PIXELS * 2 + BITSPERWORD - 1) / BITSPERWORD)
  668.  
  669. typedef struct bigint
  670. {
  671.     int b_words;
  672.     WORD b_word[MAXWORDS];
  673. } BigInt;
  674.  
  675. EXTERN BigInt B;
  676.  
  677. /* This is the guess the next pixel table.  Normally there are 12 neighbour
  678.  * pixels used to give 1<<12 cases but in the upper left corner lesser
  679.  * numbers of neighbours are available, leading to 6231 different guesses */
  680. typedef struct guesses
  681. {
  682.     char g_00[1<<12];
  683.     char g_01[1<<7];
  684.     char g_02[1<<2];
  685.     char g_10[1<<9];
  686.     char g_20[1<<6];
  687.     char g_30[1<<8];
  688.     char g_40[1<<10];
  689.     char g_11[1<<5];
  690.     char g_21[1<<3];
  691.     char g_31[1<<5];
  692.     char g_41[1<<6];
  693.     char g_12[1<<1];
  694.     char g_22[1<<0];
  695.     char g_32[1<<2];
  696.     char g_42[1<<2];
  697. } Guesses;
  698.  
  699. /* data.h was established by sampling over 1000 faces and icons */
  700. EXTERN Guesses G
  701. #ifdef MAIN
  702. =
  703. #include "data.h"
  704. #endif
  705. ;
  706.  
  707. /* Data of varying probabilities are encoded by a value in the range 0 - 255.
  708.  * The probability of the data determines the range of possible encodings.
  709.  * Offset gives the first possible encoding of the range */
  710. typedef struct prob
  711. {
  712.     WORD p_range;
  713.     WORD p_offset;
  714. } Prob;
  715.  
  716. /* A stack of probability values */
  717. EXTERN Prob *ProbBuf[PIXELS * 2];
  718. EXTERN int NumProbs INIT(0);
  719.  
  720. /* Each face is encoded using 9 octrees of 16x16 each.  Each level of the
  721.  * trees has varying probabilities of being white, grey or black.
  722.  * The table below is based on sampling many faces */
  723.  
  724. #define BLACK 0
  725. #define GREY 1
  726. #define WHITE 2
  727.  
  728. EXTERN Prob levels[4][3]
  729. #ifdef MAIN
  730. =
  731. {
  732.     {{1, 255},    {251, 0},    {4, 251}},    /* Top of tree almost always grey */
  733.     {{1, 255},    {200, 0},    {55, 200}},
  734.     {{33, 223},    {159, 0},    {64, 159}},
  735.     {{131, 0},    {0, 0},     {125, 131}}    /* Grey disallowed at bottom */
  736. }
  737. #endif
  738. ;
  739.  
  740. /* At the bottom of the octree 2x2 elements are considered black if any
  741.  * pixel is black.  The probabilities below give the distribution of the
  742.  * 16 possible 2x2 patterns.  All white is not really a possibility and
  743.  * has a probability range of zero.  Again, experimentally derived data */
  744. EXTERN Prob freqs[16]
  745. #ifdef MAIN
  746. =
  747. {
  748.     {0, 0},     {38, 0},    {38, 38},    {13, 152},
  749.     {38, 76},    {13, 165},    {13, 178},    {6, 230},
  750.     {38, 114},    {13, 191},    {13, 204},    {6, 236},
  751.     {13, 217},    {6, 242},    {5, 248},    {3, 253}
  752. }
  753. #endif
  754. ;
  755.  
  756. #define ERR_OK        0    /* successful completion */
  757. #define ERR_EXCESS    1    /* completed OK but some input was ignored */
  758. #define ERR_INSUFF    -1    /* insufficient input.  Bad face format? */
  759. #define ERR_INTERNAL    -2    /* Arithmetic overflow or buffer overflow */
  760.  
  761. EXTERN int status;
  762.  
  763. EXTERN jmp_buf comp_env;
  764.  
  765. void ReadFace(), WriteFace();
  766. void CompAll(), Compress(), PushGreys();
  767. void UnCompAll(), UnCompress(), PopGreys();
  768. void BigAdd(), BigSub(), BigMul(), BigDiv(), BigPrint(), BigPush(), RevPush();
  769. void BigWrite(), BigRead();
  770. void GenFace(), UnGenFace();
  771. Funky_Stuff
  772. len=`wc -c < compface.h`
  773. if [ $len !=     4663 ] ; then
  774. echo error: compface.h was $len bytes long, should have been     4663
  775. fi
  776. fi # end of overwriting check
  777. if [ -f compress.c ]
  778. then
  779. echo shar: will not over-write existing file compress.c
  780. else
  781. echo shar: extracting 'compress.c',     3763 characters
  782. cat > compress.c <<'Funky_Stuff'
  783. /*
  784.  *  Compface - 48x48x1 image compression and decompression
  785.  *
  786.  *  Copyright (c) James Ashton - Sydney University - June 1990.
  787.  *
  788.  *  Written 11th November 1989.
  789.  *
  790.  *  Permission is given to distribute these sources, as long as the
  791.  *  copyright messages are not removed, and no monies are exchanged. 
  792.  *
  793.  *  No responsibility is taken for any errors on inaccuracies inherent
  794.  *  either to the comments or the code of this program, but if reported
  795.  *  to me, then an attempt will be made to fix them.
  796.  */
  797.  
  798. #include "compface.h"
  799.  
  800. Same(f, wid, hei)
  801. register char *f;
  802. register int wid, hei;
  803. {
  804.     register char val, *row;
  805.     register int x;
  806.  
  807.     val = *f;
  808.     while (hei--)
  809.     {
  810.         row = f;
  811.         x = wid;
  812.         while (x--)
  813.             if (*(row++) != val)
  814.                 return(0);
  815.         f += WIDTH;
  816.     }
  817.     return 1;
  818. }
  819.  
  820. AllBlack(f, wid, hei)
  821. char *f;
  822. int wid, hei;
  823. {
  824.     if (wid > 3)
  825.     {
  826.         wid /= 2;
  827.         hei /= 2;
  828.         return (AllBlack(f, wid, hei) && AllBlack(f + wid, wid, hei) &&
  829.           AllBlack(f + WIDTH * hei, wid, hei) &&
  830.           AllBlack(f + WIDTH * hei + wid, wid, hei));
  831.     }
  832.     else
  833.         return (*f || *(f + 1) || *(f + WIDTH) || *(f + WIDTH + 1));
  834. }
  835.  
  836. AllWhite(f, wid, hei)
  837. char *f;
  838. int wid, hei;
  839. {
  840.     return ((*f == 0) && Same(f, wid, hei));
  841. }
  842.  
  843. void PopGreys(f, wid, hei)
  844. char *f;
  845. int wid, hei;
  846. {
  847.     if (wid > 3)
  848.     {
  849.         wid /= 2;
  850.         hei /= 2;
  851.         PopGreys(f, wid, hei);
  852.         PopGreys(f + wid, wid, hei);
  853.         PopGreys(f + WIDTH * hei, wid, hei);
  854.         PopGreys(f + WIDTH * hei + wid, wid, hei);
  855.     }
  856.     else
  857.     {
  858.         wid = BigPop(freqs);
  859.         if (wid & 1)
  860.             *f = 1;
  861.         if (wid & 2)
  862.             *(f + 1) = 1;
  863.         if (wid & 4)
  864.             *(f + WIDTH) = 1;
  865.         if (wid & 8)
  866.             *(f + WIDTH + 1) = 1;
  867.     }
  868. }
  869.  
  870. void PushGreys(f, wid, hei)
  871. char *f;
  872. int wid, hei;
  873. {
  874.     if (wid > 3)
  875.     {
  876.         wid /= 2;
  877.         hei /= 2;
  878.         PushGreys(f, wid, hei);
  879.         PushGreys(f + wid, wid, hei);
  880.         PushGreys(f + WIDTH * hei, wid, hei);
  881.         PushGreys(f + WIDTH * hei + wid, wid, hei);
  882.     }
  883.     else
  884.         RevPush(freqs + *f + 2 * *(f + 1) + 4 * *(f + WIDTH) +
  885.           8 * *(f + WIDTH + 1));
  886. }
  887.  
  888. void UnCompress(f, wid, hei, lev)
  889. register char *f;
  890. register int wid, hei, lev;
  891. {
  892.     switch (BigPop(&levels[lev][0]))
  893.     {
  894.         case WHITE :
  895.             return;
  896.         case BLACK :
  897.             PopGreys(f, wid, hei);
  898.             return;
  899.         default :
  900.             wid /= 2;
  901.             hei /= 2;
  902.             lev++;
  903.             UnCompress(f, wid, hei, lev);
  904.             UnCompress(f + wid, wid, hei, lev);
  905.             UnCompress(f + hei * WIDTH, wid, hei, lev);
  906.             UnCompress(f + wid + hei * WIDTH, wid, hei, lev);
  907.             return;
  908.     }
  909. }
  910.  
  911. void Compress(f, wid, hei, lev)
  912. register char *f;
  913. register int wid, hei, lev;
  914. {
  915.     if (AllWhite(f, wid, hei))
  916.     {
  917.         RevPush(&levels[lev][WHITE]);
  918.         return;
  919.     }
  920.     if (AllBlack(f, wid, hei))
  921.     {
  922.         RevPush(&levels[lev][BLACK]);
  923.         PushGreys(f, wid, hei);
  924.         return;
  925.     }
  926.     RevPush(&levels[lev][GREY]);
  927.     wid /= 2;
  928.     hei /= 2;
  929.     lev++;
  930.     Compress(f, wid, hei, lev);
  931.     Compress(f + wid, wid, hei, lev);
  932.     Compress(f + hei * WIDTH, wid, hei, lev);
  933.     Compress(f + wid + hei * WIDTH, wid, hei, lev);
  934. }
  935.  
  936. void UnCompAll(fbuf)
  937. char *fbuf;
  938. {
  939.     register char *p;
  940.  
  941.     BigRead(fbuf);
  942.     p = F;
  943.     while (p < F + PIXELS)
  944.         *(p++) = 0;
  945.     UnCompress(F, 16, 16, 0);
  946.     UnCompress(F + 16, 16, 16, 0);
  947.     UnCompress(F + 32, 16, 16, 0);
  948.     UnCompress(F + WIDTH * 16, 16, 16, 0);
  949.     UnCompress(F + WIDTH * 16 + 16, 16, 16, 0);
  950.     UnCompress(F + WIDTH * 16 + 32, 16, 16, 0);
  951.     UnCompress(F + WIDTH * 32, 16, 16, 0);
  952.     UnCompress(F + WIDTH * 32 + 16, 16, 16, 0);
  953.     UnCompress(F + WIDTH * 32 + 32, 16, 16, 0);
  954. }
  955.  
  956. void CompAll(fbuf)
  957. char *fbuf;
  958. {
  959.     Compress(F, 16, 16, 0);
  960.     Compress(F + 16, 16, 16, 0);
  961.     Compress(F + 32, 16, 16, 0);
  962.     Compress(F + WIDTH * 16, 16, 16, 0);
  963.     Compress(F + WIDTH * 16 + 16, 16, 16, 0);
  964.     Compress(F + WIDTH * 16 + 32, 16, 16, 0);
  965.     Compress(F + WIDTH * 32, 16, 16, 0);
  966.     Compress(F + WIDTH * 32 + 16, 16, 16, 0);
  967.     Compress(F + WIDTH * 32 + 32, 16, 16, 0);
  968.     B.b_words = 0;
  969.     while (NumProbs > 0)
  970.         BigPush(ProbBuf[--NumProbs]);
  971.     BigWrite(fbuf);
  972. }
  973. Funky_Stuff
  974. len=`wc -c < compress.c`
  975. if [ $len !=     3763 ] ; then
  976. echo error: compress.c was $len bytes long, should have been     3763
  977. fi
  978. fi # end of overwriting check
  979. if [ -f data.h ]
  980. then
  981. echo shar: will not over-write existing file data.h
  982. else
  983. echo shar: extracting 'data.h',    20229 characters
  984. cat > data.h <<'Funky_Stuff'
  985.  
  986. /*
  987.  *  Compface - 48x48x1 image compression and decompression
  988.  *
  989.  *  Copyright (c) James Ashton - Sydney University - June 1990.
  990.  *
  991.  *  Written 11th November 1989.
  992.  *
  993.  *  Permission is given to distribute these sources, as long as the
  994.  *  copyright messages are not removed, and no monies are exchanged. 
  995.  *
  996.  *  No responsibility is taken for any errors on inaccuracies inherent
  997.  *  either to the comments or the code of this program, but if reported
  998.  *  to me, then an attempt will be made to fix them.
  999.  */
  1000.  
  1001. {
  1002.     {
  1003.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1004.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,
  1005.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1006.         1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  1007.         0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1,
  1008.         0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1009.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1,
  1010.         0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  1011.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
  1012.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1013.         0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1014.         0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  1015.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1016.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
  1017.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1,
  1018.         0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1,
  1019.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1020.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1,
  1021.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0,
  1022.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1023.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
  1024.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1,
  1025.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1,
  1026.         1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1027.         0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
  1028.         1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1,
  1029.         0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1030.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1031.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1032.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1033.         0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1,
  1034.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1035.         0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0,
  1036.         0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1,
  1037.         0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1,
  1038.         1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1,
  1039.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1040.         0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1,
  1041.         0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1042.         0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  1043.         0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1044.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1045.         0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  1046.         1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  1047.         0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1048.         0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1,
  1049.         0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1050.         0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1,
  1051.         0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  1052.         0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1,
  1053.         0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  1054.         1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  1055.         0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1056.         0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1057.         1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1058.         1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
  1059.         0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1,
  1060.         1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1,
  1061.         0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  1062.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1063.         0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
  1064.         0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1,
  1065.         0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  1066.         1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1067.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1068.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1,
  1069.         0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  1070.         0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  1071.         0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1072.         0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1073.         0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0,
  1074.         0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1075.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1076.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1077.         0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  1078.         0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1,
  1079.         1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1,
  1080.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1,
  1081.         0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1,
  1082.         0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
  1083.         0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1084.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
  1085.         0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1,
  1086.         1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1,
  1087.         0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1,
  1088.         0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1089.         0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1090.         1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  1091.         0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,
  1092.         0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1093.         0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1094.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
  1095.         0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0,
  1096.         0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
  1097.         0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1098.         1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1,
  1099.         0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0,
  1100.         0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  1101.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
  1102.         1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1103.         0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1,
  1104.         1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  1105.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1106.         0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1107.         0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1,
  1108.         1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  1109.         0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  1110.         0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  1111.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1112.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1113.         1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1,
  1114.         1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  1115.         0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
  1116.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1117.         0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1118.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1119.         0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1120.         0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1,
  1121.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1122.         1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1123.         0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
  1124.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  1125.         0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1126.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1127.         0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1128.         1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1129.         0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1130.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  1131.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1132.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1,
  1133.         0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0,
  1134.         0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1,
  1135.         0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1136.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0,
  1137.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0,
  1138.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
  1139.         0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
  1140.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1141.         0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1142.         0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
  1143.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1144.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
  1145.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
  1146.         0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
  1147.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
  1148.         1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1149.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1150.         1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1151.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0,
  1152.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1,
  1153.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1,
  1154.         1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1155.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
  1156.         0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1157.         0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1158.         0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0,
  1159.         0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1160.         1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1161.         0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1,
  1162.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  1163.         0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1164.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
  1165.         0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  1166.         1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1167.         0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0,
  1168.         0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1169.         0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1,
  1170.         1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1,
  1171.         0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1172.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1173.         0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  1174.         1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  1175.         0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0,
  1176.         0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1,
  1177.         0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  1178.         1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1179.         0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0,
  1180.         0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1,
  1181.         0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1182.         1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1,
  1183.         0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1,
  1184.         0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1185.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1186.         1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1187.         0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1,
  1188.         1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1,
  1189.         0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  1190.         1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  1191.         0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1192.         1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1,
  1193.         0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1194.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1195.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
  1196.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
  1197.         0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1,
  1198.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1,
  1199.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0,
  1200.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1201.         0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0,
  1202.         0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1203.         0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1204.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1205.         0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1,
  1206.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
  1207.         0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
  1208.         1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,
  1209.         0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  1210.         0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
  1211.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0,
  1212.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1213.         0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1,
  1214.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1215.         0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0,
  1216.         0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1217.         0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  1218.         1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  1219.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1220.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1221.         0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
  1222.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1223.         0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0,
  1224.         1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1,
  1225.         1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  1226.         1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
  1227.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1228.         0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  1229.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1,
  1230.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1231.         0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1,
  1232.         0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,
  1233.         0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1,
  1234.         1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1235.         0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0,
  1236.         1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  1237.         0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1238.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1239.         0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0,
  1240.         1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  1241.         0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1242.         1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1243.         0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0,
  1244.         1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1245.         0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1246.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1247.         0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0,
  1248.         1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1,
  1249.         0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1250.         1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1251.         0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1,
  1252.         1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1253.         0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  1254.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1255.         0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0,
  1256.         1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
  1257.         0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1258.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1259.     },
  1260.     {
  1261.         0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1,
  1262.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1,
  1263.         0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,
  1264.         1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1,
  1265.         0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1,
  1266.         1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1,
  1267.         0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1268.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1269.     },
  1270.     {
  1271.         0, 1, 0, 1, 
  1272.     },
  1273.     {
  1274.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  1275.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  1276.         0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  1277.         1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 
  1278.         1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 
  1279.         0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 
  1280.         0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 
  1281.         0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1282.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  1283.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 
  1284.         0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 
  1285.         0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 
  1286.         0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 
  1287.         0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 
  1288.         0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 
  1289.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1290.         0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 
  1291.         0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 
  1292.         0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  1293.         0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 
  1294.         0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 
  1295.         0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 
  1296.         0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 
  1297.         1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1298.         0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 
  1299.         0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 
  1300.         0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 
  1301.         1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 
  1302.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 
  1303.         0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 
  1304.         0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1305.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1306.     },
  1307.     {
  1308.         0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  1309.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 
  1310.         0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 
  1311.         1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 
  1312.     },
  1313.     {
  1314.         0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  1315.         0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  1316.         0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  1317.         0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  1318.         0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  1319.         0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  1320.         0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  1321.         0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  1322.         0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  1323.         0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 
  1324.         0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 
  1325.         0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 
  1326.         0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 
  1327.         0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  1328.         0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  1329.         0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 
  1330.     },
  1331.     {
  1332.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 
  1333.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 
  1334.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 
  1335.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 
  1336.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 
  1337.         0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 
  1338.         1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 
  1339.         0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 
  1340.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 
  1341.         0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 
  1342.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 
  1343.         0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 
  1344.         1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 
  1345.         0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 
  1346.         1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1347.         0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1348.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 
  1349.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  1350.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 
  1351.         0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 
  1352.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 
  1353.         0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 
  1354.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 
  1355.         0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 
  1356.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 
  1357.         0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 
  1358.         0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1359.         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1360.         0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1361.         0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 
  1362.         1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1363.         1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1364.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 
  1365.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  1366.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 
  1367.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 
  1368.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 
  1369.         0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 
  1370.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 
  1371.         0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 
  1372.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 
  1373.         0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 
  1374.         0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1375.         0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 
  1376.         0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 
  1377.         0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1378.         0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1379.         0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1380.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  1381.         0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 
  1382.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 
  1383.         0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 
  1384.         0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 
  1385.         0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1386.         0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 
  1387.         0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 
  1388.         0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 
  1389.         0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 
  1390.         0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 
  1391.         0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 
  1392.         0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 
  1393.         0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1394.         0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 
  1395.         0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1396.     },
  1397.     {
  1398.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 
  1399.         0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 
  1400.     },
  1401.     {
  1402.         0, 0, 0, 1, 0, 1, 1, 1, 
  1403.     },
  1404.     {
  1405.         0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 
  1406.         0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 
  1407.     },
  1408.     {
  1409.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 
  1410.         0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 
  1411.         0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 
  1412.         0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
  1413.     },
  1414.     {
  1415.         0, 1, 
  1416.     },
  1417.     {
  1418.         0, 
  1419.     },
  1420.     {
  1421.         0, 0, 0, 1, 
  1422.     },
  1423.     {
  1424.         0, 0, 0, 1, 
  1425.     }
  1426. }
  1427. Funky_Stuff
  1428. len=`wc -c < data.h`
  1429. if [ $len !=    20229 ] ; then
  1430. echo error: data.h was $len bytes long, should have been    20229
  1431. fi
  1432. fi # end of overwriting check
  1433. if [ -f file.c ]
  1434. then
  1435. echo shar: will not over-write existing file file.c
  1436. else
  1437. echo shar: extracting 'file.c',     2734 characters
  1438. cat > file.c <<'Funky_Stuff'
  1439. /*
  1440.  *  Compface - 48x48x1 image compression and decompression
  1441.  *
  1442.  *  Copyright (c) James Ashton - Sydney University - June 1990.
  1443.  *
  1444.  *  Written 11th November 1989.
  1445.  *
  1446.  *  Permission is given to distribute these sources, as long as the
  1447.  *  copyright messages are not removed, and no monies are exchanged. 
  1448.  *
  1449.  *  No responsibility is taken for any errors on inaccuracies inherent
  1450.  *  either to the comments or the code of this program, but if reported
  1451.  *  to me, then an attempt will be made to fix them.
  1452.  */
  1453.  
  1454. #include "compface.h"
  1455.  
  1456. void BigRead(fbuf)
  1457. register char *fbuf;
  1458. {
  1459.     register int c;
  1460.     register char *s;
  1461.  
  1462.     s = fbuf + strlen(fbuf);
  1463.     while (fbuf < s)
  1464.     {
  1465.         c = *(fbuf++);
  1466.         if ((c < FIRSTPRINT) || (c > LASTPRINT))
  1467.             continue;
  1468.         BigMul(NUMPRINTS);
  1469.         BigAdd((WORD)(c - FIRSTPRINT));
  1470.     }
  1471. }
  1472.  
  1473. void BigWrite(fbuf)
  1474. register char *fbuf;
  1475. {
  1476.     static WORD tmp;
  1477.     static char buf[DIGITS];
  1478.     register char *s;
  1479.     register int i;
  1480.  
  1481.     s = buf;
  1482.     while (B.b_words > 0)
  1483.     {
  1484.         BigDiv(NUMPRINTS, &tmp);
  1485.         *(s++) = tmp + FIRSTPRINT;
  1486.     }
  1487.     i = 7;    /* leave room for the field name on the first line */
  1488.     *(fbuf++) = ' ';
  1489.     while (s-- > buf)
  1490.     {
  1491.         if (i == 0)
  1492.             *(fbuf++) = ' ';
  1493.         *(fbuf++) = *s;
  1494.         if (++i >= MAXLINELEN)
  1495.         {
  1496.             *(fbuf++) = '\n';
  1497.             i = 0;
  1498.         }
  1499.     }
  1500.     if (i > 0)
  1501.         *(fbuf++) = '\n';
  1502.     *(fbuf++) = '\0';
  1503. }
  1504.  
  1505. void ReadFace(fbuf)
  1506. char *fbuf;
  1507. {
  1508.     register int c, i;
  1509.     register char *s, *t;
  1510.  
  1511.     t = s = fbuf;
  1512.     for(i = strlen(s); i > 0; i--)
  1513.     {
  1514.         c = (int)*(s++);
  1515.         if ((c >= '0') && (c <= '9'))
  1516.         {
  1517.             if (t >= fbuf + DIGITS)
  1518.             {
  1519.                 status = ERR_EXCESS;
  1520.                 break;
  1521.             }
  1522.             *(t++) = c - '0';
  1523.         }
  1524.         else if ((c >= 'A') && (c <= 'F'))
  1525.         {
  1526.             if (t >= fbuf + DIGITS)
  1527.             {
  1528.                 status = ERR_EXCESS;
  1529.                 break;
  1530.             }
  1531.             *(t++) = c - 'A' + 10;
  1532.         }
  1533.         else if ((c >= 'a') && (c <= 'f'))
  1534.         {
  1535.             if (t >= fbuf + DIGITS)
  1536.             {
  1537.                 status = ERR_EXCESS;
  1538.                 break;
  1539.             }
  1540.             *(t++) = c - 'a' + 10;
  1541.         }
  1542.         else if (((c == 'x') || (c == 'X')) && (t > fbuf) && (*(t-1) == 0))
  1543.             t--;
  1544.     }
  1545.     if (t < fbuf + DIGITS)
  1546.         longjmp(comp_env, ERR_INSUFF);
  1547.     s = fbuf;
  1548.     t = F;
  1549.     c = 1 << (BITSPERDIG - 1);
  1550.     while (t < F + PIXELS)
  1551.     {
  1552.         *(t++) = (*s & c) ? 1 : 0;
  1553.         if ((c >>= 1) == 0)
  1554.         {
  1555.             s++;
  1556.             c = 1 << (BITSPERDIG - 1);
  1557.         }
  1558.     }
  1559. }
  1560.  
  1561. void WriteFace(fbuf)
  1562. char *fbuf;
  1563. {
  1564.     register char *s, *t;
  1565.     register int i, bits, digits, words;
  1566.  
  1567.     s = F;
  1568.     t = fbuf;
  1569.     bits = digits = words = i = 0;
  1570.     while (s < F + PIXELS)
  1571.     {
  1572.         if ((bits == 0) && (digits == 0))
  1573.         {
  1574.             *(t++) = '0';
  1575.             *(t++) = 'x';
  1576.         }
  1577.         if (*(s++))
  1578.             i = i * 2 + 1;
  1579.         else
  1580.             i *= 2;
  1581.         if (++bits == BITSPERDIG)
  1582.         {
  1583.             *(t++) = *(i + HexDigits);
  1584.             bits = i = 0;
  1585.             if (++digits == DIGSPERWORD)
  1586.             {
  1587.                 *(t++) = ',';
  1588.                 digits = 0;
  1589.                 if (++words == WORDSPERLINE)
  1590.                 {
  1591.                     *(t++) = '\n';
  1592.                     words = 0;
  1593.                 }
  1594.             }
  1595.         }
  1596.     }
  1597.     *(t++) = '\0';
  1598. }
  1599. Funky_Stuff
  1600. len=`wc -c < file.c`
  1601. if [ $len !=     2734 ] ; then
  1602. echo error: file.c was $len bytes long, should have been     2734
  1603. fi
  1604. fi # end of overwriting check
  1605. if [ -f gen.c ]
  1606. then
  1607. echo shar: will not over-write existing file gen.c
  1608. else
  1609. echo shar: extracting 'gen.c',     1900 characters
  1610. cat > gen.c <<'Funky_Stuff'
  1611. /*
  1612.  *  Compface - 48x48x1 image compression and decompression
  1613.  *
  1614.  *  Copyright (c) James Ashton - Sydney University - June 1990.
  1615.  *
  1616.  *  Written 11th November 1989.
  1617.  *
  1618.  *  Permission is given to distribute these sources, as long as the
  1619.  *  copyright messages are not removed, and no monies are exchanged. 
  1620.  *
  1621.  *  No responsibility is taken for any errors on inaccuracies inherent
  1622.  *  either to the comments or the code of this program, but if reported
  1623.  *  to me, then an attempt will be made to fix them.
  1624.  */
  1625.  
  1626. #include "compface.h"
  1627.  
  1628. #define GEN(g) F[h] ^= G.g[k]; break
  1629.  
  1630. static void Gen(f)
  1631. register char *f;
  1632. {
  1633.     register int m, l, k, j, i, h;
  1634.  
  1635.     j = 0;
  1636.     while (j++ < HEIGHT)
  1637.     {
  1638.         i = 0;
  1639.         while (i++ < WIDTH)
  1640.         {
  1641.             h = i + j * WIDTH;
  1642.             k = 0;
  1643.             for (l = i - 2; l <= i + 2; l++)
  1644.                 for (m = j - 2; m <= j; m++)
  1645.                 {
  1646.                     if ((l >= i) && (m == j))
  1647.                         continue;
  1648.                     if ((l > 0) && (l <= WIDTH) && (m > 0))
  1649.                         k = *(f + l + m * WIDTH) ? k * 2 + 1 : k * 2;
  1650.                 }
  1651.             switch (i)
  1652.             {
  1653.                 case 1 :
  1654.                     switch (j)
  1655.                     {
  1656.                         case 1 : GEN(g_22);
  1657.                         case 2 : GEN(g_21);
  1658.                         default : GEN(g_20);
  1659.                     }
  1660.                     break;
  1661.                 case 2 :
  1662.                     switch (j)
  1663.                     {
  1664.                         case 1 : GEN(g_12);
  1665.                         case 2 : GEN(g_11);
  1666.                         default : GEN(g_10);
  1667.                     }
  1668.                     break;
  1669.                 case WIDTH - 1 :
  1670.                     switch (j)
  1671.                     {
  1672.                         case 1 : GEN(g_42);
  1673.                         case 2 : GEN(g_41);
  1674.                         default : GEN(g_40);
  1675.                     }
  1676.                     break;
  1677.                 case WIDTH :
  1678.                     switch (j)
  1679.                     {
  1680.                         case 1 : GEN(g_32);
  1681.                         case 2 : GEN(g_31);
  1682.                         default : GEN(g_30);
  1683.                     }
  1684.                     break;
  1685.                 default :
  1686.                     switch (j)
  1687.                     {
  1688.                         case 1 : GEN(g_02);
  1689.                         case 2 : GEN(g_01);
  1690.                         default : GEN(g_00);
  1691.                     }
  1692.                     break;
  1693.             }
  1694.         }
  1695.     }
  1696. }
  1697.  
  1698. void GenFace()
  1699. {
  1700.     static char new[PIXELS];
  1701.     register char *f1;
  1702.     register char *f2;
  1703.     register int i;
  1704.  
  1705.     f1 = new;
  1706.     f2 = F;
  1707.     i = PIXELS;
  1708.     while (i-- > 0)
  1709.         *(f1++) = *(f2++);
  1710.     Gen(new);
  1711. }
  1712.  
  1713. void UnGenFace()
  1714. {
  1715.     Gen(F);
  1716. }
  1717. Funky_Stuff
  1718. len=`wc -c < gen.c`
  1719. if [ $len !=     1900 ] ; then
  1720. echo error: gen.c was $len bytes long, should have been     1900
  1721. fi
  1722. fi # end of overwriting check
  1723. if [ -f main.c ]
  1724. then
  1725. echo shar: will not over-write existing file main.c
  1726. else
  1727. echo shar: extracting 'main.c',     3065 characters
  1728. cat > main.c <<'Funky_Stuff'
  1729. /*
  1730.  *  Compface - 48x48x1 image compression and decompression
  1731.  *
  1732.  *  Copyright (c) James Ashton - Sydney University - June 1990.
  1733.  *
  1734.  *  Written 11th November 1889.
  1735.  *
  1736.  *  Permission is given to distribute these sources, as long as the
  1737.  *  copyright messages are not removed, and no monies are exchanged. 
  1738.  *
  1739.  *  No responsibility is taken for any errors on inaccuracies inherent
  1740.  *  either to the comments or the code of this program, but if reported
  1741.  *  to me, then an attempt will be made to fix them.
  1742.  */
  1743.  
  1744. #include <fcntl.h>
  1745.  
  1746. /* the buffer is longer than needed to handle sparse input formats */
  1747. #define FACEBUFLEN 2048
  1748. char fbuf[FACEBUFLEN];
  1749.  
  1750. /* IO file descriptors and their names */
  1751. int infile = 0;
  1752. char *inname = "<stdin>";
  1753. int outfile = 1;
  1754. char *outname = "<stdout>";
  1755.  
  1756. /* basename of executable */
  1757. char *cmdname;
  1758.  
  1759. /* error handling definitions follow */
  1760.  
  1761. extern int errno, sys_nerr;
  1762. extern char *sys_errlist[];
  1763.  
  1764. #define ERR ((errno < sys_nerr) ? sys_errlist[errno] : "")
  1765. #define INITERR(s) {(void)strcpy(fbuf, cmdname); (void)strcat(fbuf, ": ");\
  1766.                     (void)strcat(fbuf, (s));}
  1767. #define ADDERR(s) (void)strcat(fbuf, (s));
  1768. #define ERROR {(void)strcat(fbuf, "\n");\
  1769.                 (void)write(2, fbuf, strlen(fbuf)); exit(1);}
  1770. #define INITWARN(s) {(void)strcpy(fbuf, cmdname);\
  1771.                     (void)strcat(fbuf, ": (warning) ");\
  1772.                     (void)strcat(fbuf, (s));}
  1773. #define ADDWARN(s) (void)strcat(fbuf, (s));
  1774. #define WARN {(void)strcat(fbuf, "\n"); (void)write(2, fbuf, strlen(fbuf));}
  1775.  
  1776. main(argc, argv)
  1777. int argc;
  1778. char *argv[];
  1779. {
  1780.     cmdname = *argv;
  1781.     while (**argv)
  1782.         if (*((*argv)++) == '/')
  1783.             cmdname = *argv;    /* find the command's basename */
  1784.     if (argc > 3)
  1785.     {
  1786.         INITERR("usage: ")
  1787.         ADDERR(cmdname)
  1788.         ADDERR(" [infile [outfile]]")
  1789.         ERROR
  1790.     }
  1791.     if ((argc > 1) && strcmp(*++argv, "-"))
  1792.     {
  1793.         inname = *argv;
  1794.         if ((infile = open(inname, O_RDONLY)) == -1)
  1795.         {
  1796.             INITERR(inname)
  1797.             ADDERR(": ")
  1798.             ADDERR(ERR)
  1799.             ERROR
  1800.         }
  1801.     }
  1802.     if (argc > 2)
  1803.     {
  1804.         outname = *++argv;
  1805.         if ((outfile = open(outname, O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1)
  1806.         {
  1807.             INITERR(outname)
  1808.             ADDERR(": ")
  1809.             ADDERR(ERR)
  1810.             ERROR
  1811.         }
  1812.     }
  1813.     ReadBuf();
  1814.     switch ((*cmdname != 'u') ? compface(fbuf) : uncompface(fbuf))
  1815.     {
  1816.         case -2 :
  1817.             INITERR("internal error")
  1818.             ERROR
  1819.         case -1 :
  1820.             INITERR(inname)
  1821.             ADDERR(": insufficient or invalid data")
  1822.             ERROR
  1823.         case 1 :
  1824.             INITWARN(inname)
  1825.             ADDWARN(": excess data ignored")
  1826.             WARN
  1827.         default : ;
  1828.     }
  1829.     WriteBuf();
  1830.     return 0;
  1831. }
  1832.  
  1833. WriteBuf()
  1834. {
  1835.     register char *s, *t;
  1836.     register int len;
  1837.  
  1838.     s = fbuf;
  1839.     t = s + strlen(s);
  1840.     while (s < t)
  1841.     {
  1842.         if ((len = write(outfile, s, t - s)) == -1)
  1843.         {
  1844.             INITERR(outname)
  1845.             ADDERR(": ")
  1846.             ADDERR(ERR)
  1847.             ERROR
  1848.         }
  1849.         s += len;
  1850.     }
  1851.     return 0;
  1852. }
  1853.  
  1854. ReadBuf()
  1855. {
  1856.     register int count, len;
  1857.     register char *t;
  1858.  
  1859.     count = 0;
  1860.     t = fbuf;
  1861.     while (len = read(infile, t, FACEBUFLEN - count))
  1862.     {
  1863.         if (len == -1)
  1864.         {
  1865.             INITERR(inname)
  1866.             ADDERR(": ")
  1867.             ADDERR(ERR)
  1868.             ERROR
  1869.         }
  1870.         t += len;
  1871.         if ((count += len) >= FACEBUFLEN)
  1872.         {
  1873.             INITWARN(inname)
  1874.             ADDWARN(" exceeds internal buffer size.  Data may be lost")
  1875.             WARN
  1876.             break;
  1877.         }
  1878.     }
  1879.     return count;
  1880. }
  1881. Funky_Stuff
  1882. len=`wc -c < main.c`
  1883. if [ $len !=     3065 ] ; then
  1884. echo error: main.c was $len bytes long, should have been     3065
  1885. fi
  1886. fi # end of overwriting check
  1887. cd ..
  1888. echo shar: done with directory compface
  1889. fi
  1890.  
  1891.