예제 #1
0
// a function which recovers from a malformed command.
static int hpgl_recover(hpgs_reader *reader)
{
  size_t pos;

  if (hpgs_istream_tell(reader->in,&pos))
    return -1;

  reader->bytes_ignored = 0;
  
  while (reader->bytes_ignored < 256 &&
         (reader->last_byte = hpgs_getc(reader->in)) != ';')
    {
      if (reader->last_byte == EOF)
        return hpgs_set_error(hpgs_i18n("EOF during recovery from malformed HPGL command at file position %lu."),(unsigned long)pos);

      ++reader->bytes_ignored;
    }

  if (reader->bytes_ignored >= 256)
    return hpgs_set_error(hpgs_i18n("No semicolon in the next 256 bytes during recovery from malformed HPGL command at file position %lu."),(unsigned long)pos);

  reader->bytes_ignored = 0;
  reader->eoc = 1;

  return 0;
}
예제 #2
0
static int base64_decode (hpgs_reader *reader, unsigned *value)
{
  int digit;
  int i=0;

  *value=0;

  while (i<6)
    {
      if (reader->last_byte == EOF) return -1;

      if (reader->last_byte > 190)
	digit = reader->last_byte - 191;
      else
	digit = reader->last_byte - 63;

      if (digit >= 0 && digit <= 63) 
	{
	  *value |= digit << (6*i);
	  
	  if (reader->last_byte > 190) return 0;
	  ++i;
	}
      else
        // ignore all escape characters, including space.
	if (reader->last_byte > 32) return -1;

      reader->last_byte = hpgs_getc(reader->in);
    }
  return -1;
}
예제 #3
0
/* 
  HPGL command PE (Polyline Encoded)
*/
static int base32_decode (hpgs_reader *reader, unsigned *value)
{
  int digit;
  int i=0;

  *value=0;

  while (i<7)
    {
      if (reader->last_byte == EOF) return -1;

      reader->last_byte &= 0x7f;

      if (reader->last_byte > 94)
	digit = reader->last_byte - 95;
      else
	digit = reader->last_byte - 63;

      if (digit >= 0 && digit <= 31) 
	{
	  *value |= digit << (5*i);

	  if (reader->last_byte > 94) return 0;
	  ++i;
	}
      else
        // ignore all escape characters, including space.
	if (reader->last_byte > 32) return -1;

      reader->last_byte = hpgs_getc(reader->in);
    }

  return -1;
}
예제 #4
0
// skip until we reach 'ENDMF;'
static int skip_MF_block (hpgs_reader *reader, const char *stop_seq)
{
  while (1)
    {
      if (reader->bytes_ignored > 0)
	{
	  if (reader->last_byte != stop_seq[reader->bytes_ignored-1])
	    reader->bytes_ignored = 0;	  
	}

      if (stop_seq[reader->bytes_ignored] == '\0')
	{
	  reader->bytes_ignored = 0;
	  return 0;
	}

      reader->last_byte = hpgs_getc(reader->in);
      if (reader->last_byte == EOF)
	return 1;
     
      ++reader->bytes_ignored;
    }
}
예제 #5
0
static int skip_ESC_block (hpgs_reader *reader)
{
  int arg = 0;
  int arg_sign = 0;
  int r;

  while (1)
    {
      switch (reader->bytes_ignored)
	{
	case 1:
	  if (reader->last_byte != HPGS_ESC)
	    reader->bytes_ignored = 0;
	  break;
	case 2:
	  if (reader->last_byte == '.')
            {
              reader->last_byte = hpgs_getc(reader->in);
              if (reader->last_byte == EOF)
                return 1;

              // <ESC>.( or <ESC>.Y interpretation.
              if (reader->last_byte == '(' ||
                  reader->last_byte == 'Y'   )
                return 0;

              reader->bytes_ignored = 0;
              break;
            }

	  if (reader->last_byte != '%')
	    reader->bytes_ignored = 0;
	  break;
	case 3:
	  switch (hpgs_reader_read_pcl_int(reader,&arg,&arg_sign))
	    {
            case -1:
              return 1;
            case 1:
              break;
            default:
              reader->bytes_ignored = 0;
	    }

	  break;
	case 4:
          reader->bytes_ignored = 0;
          switch (reader->last_byte)
            {
            case 'B':
              return 0;
            case 'A':
              r = hpgs_reader_do_PCL(reader,arg);
              if (r <= 0) return r;
              if (r==2) return 1;
            case 'X':
              r=1;
              while (r)
                switch (hpgs_reader_do_PJL(reader))
                  {
                  case 0: // ESC found.
                    r = 0;
                    break;
                  case 1: // Enter HPGL mode.
                    return 0;
                  case 2: // plotsize found. skip rest of file.
                    return 1;
                  case 3: // Enter PCL mode.
                    r = hpgs_reader_do_PCL(reader,arg);
                    if (r <= 0) return r;
                    if (r==2) return 1;
                    break;
                  default: /* EOF, error */
                    return 1;
                  }
            }
	  break;
	default:
	  reader->bytes_ignored = 0;	  
	}

      if (reader->bytes_ignored != 2)
        {
          reader->last_byte = hpgs_getc(reader->in);
          if (reader->last_byte == EOF)
            return 1;
        }
     
      ++reader->bytes_ignored;
    }
}