[comp.lang.postscript] Postscript <-> eexec conversion programs

cnwietho@immd4.informatik.uni-erlangen.de (Carsten Wiethoff) (10/03/89)

Hi!

For all who have missed my description of the eexec-algorithm some
time ago (or who were not able to make a program from it ;-) I post
two little C-programs that convert postscript to eexec format and
vice versa.
ps2eexec.c is especially useful to convert machine code using the cexec
operator to eexec format.

BTW it might be interesting to know that this algorithm (using different
initial values) is used in the Adobe font format as well. So if these rumours
about Adobe publishing their font format are true, we should see a similar thing
from Adobe soon.

This is ps2eexec.c:
----------------------------------- cut here ----------------------------
/* Quickie to convert postscript from stdin to eexec format on stdout */

#include <stdio.h>

static unsigned short buffer = 0xd971;
static unsigned long startup = 0x00000000; /* or whatever you want */

main()
{
  unsigned char input;
  unsigned char output;
  int init = 4;
  int i;
  int result;

  printf("%08x",startup);
  for (i=0;i<4;++i)
    {
      input = (startup >> ((3-i)*8));
      buffer = (input + buffer) * 0xce6d + 0x58bf;
    }  

  for(;;)
    {
      for (i=0;i<(32-init);++i)
	{
	  result = getchar();
	  if (result == EOF)
	    break;
	  output = (input ^ (buffer>>8));
	  buffer = (output + buffer) * 0xce6d + 0x58bf;
	  printf("%02x",output);
	}
      init = 0;
      printf("\n");
      if (input == EOF)
	break;
    }
}
----------------------------- cut here ----------------------------------

This is eexec2ps.c:
------------------------------ cut here ----------------------------------

/* Quickie to convert eexec format from stdin to postscript on stdout */

#include <stdio.h>

/* Written by Carsten Wiethoff 1989 */
/* You may do what you want with this code, 
   as long as this notice stays in it */

static unsigned short buffer = 0xd971;

main()
{
  unsigned int input;
  char output;
  int ignore = 4;
  int result;

  do
    {
      result = scanf(" %2x",&input);
      if ( (result == EOF) || (result == 0) )
	break;
      output = input ^ (buffer>>8);
      buffer = (input + buffer) * 0xce6d + 0x58bf;
      if ( ignore > 0 ) 
	{
	  ignore--;
	}
      else
	{
	  printf("%c",output);
	}
    } while (1);
}
      
-------------------------------- cut here --------------------------------      





				Carsten Wiethoff
				c/o Frank Kardel

				Friedrich-Alexander Universitaet
				Erlangen-Nuernberg
				
				CS Department IMMD IV
				Martensstrasse 1
				D-8520 Erlangen
				---------------
				West Germany

Voice: +49/(0)9131/85-7908
E-mail: cnwietho@immd4.informatik.uni-erlangen.de

Private:                        Carsten Wiethoff
				Untere Karlstr.7
				D-8520 Erlangen
				West Germany

				Tel.: +49/(0)9131/29136