예제 #1
0
static int
block_count (mapDef *mtab, int c)
{
  int count = 0, n;

  n  = mtab[c].len - 1;
  c += 1;
  for (; c < 256; c++) {
    if (LOOKUP_CONTINUE(mtab[c].flag) ||
	!MAP_DEFINED(mtab[c].flag)     ||
	(MAP_TYPE(mtab[c].flag) != MAP_IS_CID &&
	 MAP_TYPE(mtab[c].flag) != MAP_IS_CODE) ||
	mtab[c-1].len != mtab[c].len)
      break;
    else if (!memcmp(mtab[c-1].code, mtab[c].code, n) &&
	     mtab[c-1].code[n] < 255 &&
	     mtab[c-1].code[n] + 1 == mtab[c].code[n])
      count++;
    else {
      break;
    }
  }

  return count;
}
예제 #2
0
static int
add_map (CMap *cmap, mapDef *mtab,
	 unsigned char *codestr, int depth)
{
  int     c;
  mapDef *mtab1;

  for (c = 0; c < 256; c++) {
    codestr[depth] = (unsigned char) (c & 0xff);
    if (LOOKUP_CONTINUE(mtab[c].flag)) {
      mtab1 = mtab[c].next;
      add_map(cmap, mtab1, codestr, depth + 1);
    } else {
      if (MAP_DEFINED(mtab[c].flag)) {
	switch (MAP_TYPE(mtab[c].flag)) {
	case MAP_IS_CID: case MAP_IS_CODE:
	  CMap_add_bfchar(cmap,
			  codestr, depth + 1,
			  mtab[c].code, mtab[c].len);
	  break;
	case MAP_IS_NAME:
	  ERROR("%s: Unexpected error...", CMAP_DEBUG_STR);
	  break;
	case MAP_IS_NOTDEF:
	  break;
	default:
	  ERROR("%s: Unknown mapping type: %d",
		CMAP_DEBUG_STR, MAP_TYPE(mtab[c].flag));
	}
      }
    }
  }

  return 0;
}
예제 #3
0
static int
add_inverse_map (CMap *icmap, mapDef *mtab,
		 unsigned char *codestr, int depth,
		 unsigned char *used_slot)
{
  CID     cid;
  int     c;
  mapDef *mtab1;

  for (c = 0; c < 256; c++) {
    codestr[depth] = (unsigned char) (c & 0xff);
    if (LOOKUP_CONTINUE(mtab[c].flag)) {
      mtab1 = mtab[c].next;
      add_inverse_map(icmap, mtab1, codestr, depth + 1, used_slot);
    } else {
      if (MAP_DEFINED(mtab[c].flag)) {
	switch (MAP_TYPE(mtab[c].flag)) {
	  /* We should restrict it to to-CID mapping.
	   * However...
	   */
	case MAP_IS_CID: case MAP_IS_CODE:
	  if (mtab[c].len == 2) {
	    cid = (mtab[c].code[0] << 8)|mtab[c].code[1];
#ifndef is_used_char2
#define is_used_char2(b,c) (((b)[(c)/8]) & (1 << (7-((c)%8))))
#endif
	    if (!used_slot ||
		is_used_char2(used_slot, cid)) {
	      CMap_add_bfchar(icmap,
			      mtab[c].code, mtab[c].len,
			      codestr, depth + 1);
	    }
	  }
	  break;
	case MAP_IS_NAME:
	  ERROR("%s: Unexpected error...", CMAP_DEBUG_STR);
	  break;
	case MAP_IS_NOTDEF:
	  break;
	default:
	  ERROR("%s: Unknown mapping type: %d",
		CMAP_DEBUG_STR, MAP_TYPE(mtab[c].flag));
	}
      }
    }
  }

  return 0;
}
예제 #4
0
파일: file-utils.c 프로젝트: e8johan/murphy
static inline mrp_dirent_type_t dirent_type(mode_t mode)
{
#define MAP_TYPE(x, y) if (S_IS##x(mode)) return MRP_DIRENT_##y

    MAP_TYPE(REG, REG);
    MAP_TYPE(DIR, DIR);
    MAP_TYPE(LNK, LNK);
    MAP_TYPE(CHR, CHR);
    MAP_TYPE(BLK, BLK);
    MAP_TYPE(FIFO, FIFO);
    MAP_TYPE(SOCK, SOCK);

    return MRP_DIRENT_UNKNOWN;

#undef MAP_TYPE
}
예제 #5
0
static int
write_map (mapDef *mtab, int count,
	   unsigned char *codestr, int depth,
	   struct sbuf *wbuf, pdf_obj *stream)
{
  int     c, i, block_length;
  mapDef *mtab1;
  /* Must be greater than 1 */
#define BLOCK_LEN_MIN 2
  struct {
    int start, count;
  } blocks[256/BLOCK_LEN_MIN+1];
  int num_blocks = 0;

  for (c = 0; c < 256; c++) {
    codestr[depth] = (unsigned char) (c & 0xff);
    if (LOOKUP_CONTINUE(mtab[c].flag)) {
      mtab1 = mtab[c].next;
      count = write_map(mtab1, count,
			codestr, depth + 1, wbuf, stream);
    } else {
      if (MAP_DEFINED(mtab[c].flag)) {
	switch (MAP_TYPE(mtab[c].flag)) {
	case MAP_IS_CID: case MAP_IS_CODE:
	  block_length = block_count(mtab, c);
	  if (block_length >= BLOCK_LEN_MIN) {
	    blocks[num_blocks].start = c;
	    blocks[num_blocks].count = block_length;
	    num_blocks++;
	    c += block_length;
	  } else {
	    *(wbuf->curptr)++ = '<';
	    for (i = 0; i <= depth; i++)
	      sputx(codestr[i], &(wbuf->curptr), wbuf->limptr);
	    *(wbuf->curptr)++ = '>';
	    *(wbuf->curptr)++ = ' ';
	    *(wbuf->curptr)++ = '<';
	    for (i = 0; i < mtab[c].len; i++)
	      sputx(mtab[c].code[i], &(wbuf->curptr), wbuf->limptr);
	    *(wbuf->curptr)++ = '>';
	    *(wbuf->curptr)++ = '\n';
	    count++;
	  }
	  break;
	case MAP_IS_NAME:
	  ERROR("%s: Unexpected error...", CMAP_DEBUG_STR);
	  break;
	case MAP_IS_NOTDEF:
	  break;
	default:
	  ERROR("%s: Unknown mapping type: %d",
		CMAP_DEBUG_STR, MAP_TYPE(mtab[c].flag));
	}
      }
    }

    /* Flush if necessary */
    if (count >= 100 ||
	wbuf->curptr >= wbuf->limptr ) {
      char fmt_buf[32];
      if (count > 100)
	ERROR("Unexpected error....: %d", count);
      sprintf(fmt_buf, "%d beginbfchar\n", count);
      pdf_add_stream(stream, fmt_buf,  strlen(fmt_buf));
      pdf_add_stream(stream,
		     wbuf->buf, (int) (wbuf->curptr - wbuf->buf));
      wbuf->curptr = wbuf->buf;
      pdf_add_stream(stream,
		     "endbfchar\n", strlen("endbfchar\n"));
      count = 0;
    }
  }

  if (num_blocks > 0) {
    char fmt_buf[32];

    if (count > 0) {
      sprintf(fmt_buf, "%d beginbfchar\n", count);
      pdf_add_stream(stream, fmt_buf,  strlen(fmt_buf));
      pdf_add_stream(stream,
		     wbuf->buf, (int) (wbuf->curptr - wbuf->buf));
      wbuf->curptr = wbuf->buf;
      pdf_add_stream(stream,
		     "endbfchar\n", strlen("endbfchar\n"));
      count = 0;
    }
    sprintf(fmt_buf, "%d beginbfrange\n", num_blocks);
    pdf_add_stream(stream, fmt_buf, strlen(fmt_buf));
    for (i = 0; i < num_blocks; i++) {
      int j;

      c = blocks[i].start;
      *(wbuf->curptr)++ = '<';
      for (j = 0; j < depth; j++)
	sputx(codestr[j], &(wbuf->curptr), wbuf->limptr);
      sputx((unsigned char)c, &(wbuf->curptr), wbuf->limptr);
      *(wbuf->curptr)++ = '>';
      *(wbuf->curptr)++ = ' ';
      *(wbuf->curptr)++ = '<';
      for (j = 0; j < depth; j++)
	sputx(codestr[j], &(wbuf->curptr), wbuf->limptr);
      sputx((unsigned char)(c + blocks[i].count), &(wbuf->curptr), wbuf->limptr);
      *(wbuf->curptr)++ = '>';
      *(wbuf->curptr)++ = ' ';
      *(wbuf->curptr)++ = '<';
      for (j = 0; j < mtab[c].len; j++)
	sputx(mtab[c].code[j], &(wbuf->curptr), wbuf->limptr);
      *(wbuf->curptr)++ = '>';
      *(wbuf->curptr)++ = '\n';
    }
    pdf_add_stream(stream,
		   wbuf->buf, (int) (wbuf->curptr - wbuf->buf));
    wbuf->curptr = wbuf->buf;
    pdf_add_stream(stream,
		   "endbfrange\n", strlen("endbfrange\n"));
  }

  return count;
}