Example #1
0
/* What? This looks really weird, but that's just because I don't get it */
static void print_utf8(unsigned short c)
{
	if (c == 0) return;
		
	if (c < 0x80) OutputCharCorrected(c);
	else if (c < 0x800) {
		emitchar(0xC0 | (c >>  6));
		put_utf8(c);
	} else {
Example #2
0
void
atsc_utf16_to_utf8(uint8_t *src, int len, char *buf, int buflen)
{
  int i, c, r;

  for(i = 0; i < len; i++) {
    c = (src[i * 2 + 0] << 8) | src[i * 2 + 1];

    if(buflen >= 7) {
      r = put_utf8(buf, c);
      buf += r;
      buflen -= r;
    }
  }
  *buf = 0;
}
Example #3
0
char *Yap_guessFileName(FILE *file, int sno, char *nameb, size_t max) {
  size_t maxs = max(255, max);
  if (!nameb) {
    nameb = malloc(maxs + 1);
  }
  if (!file) {
    strncpy(nameb, "memory buffer", maxs);
    return nameb;
  }
  int f = fileno(file);
  if (f < 0) {
    strcpy(nameb, "???");
    return nameb;
  }

#if __linux__
  char path[256];
  if (snprintf(path, 255, "/proc/self/fd/%d", f) && readlink(path, nameb, max))
    return nameb;
#elif __APPLE__
  if (fcntl(f, F_GETPATH, nameb) != -1) {
    return nameb;
  }
#else
  TCHAR path[MAX_PATH + 1];
  if (!GetFullPathName(path, MAX_PATH, path, NULL))
    return NULL;
  else {
    int i;
    unsigned char *ptr = (unsigned char *)nameb;
    for (i = 0; i < strlen(path); i++)
      ptr += put_utf8(ptr, path[i]);
    *ptr = '\0';
    return nameb;
  }
#endif
  if (!StreamName(sno)) {
    return NULL;
  }
  return RepAtom(AtomOfTerm(StreamName(sno)))->StrOfAE;
}
Example #4
0
int
main(int argc, char **argv)
{
   char *p1, *p2;

   cons_CharsetEntry *cs1 = 0, *cs2 = 0;

   int len1 = 0, len2 = 0;

   unsigned char tbl[256];

   int ch;

   char *s;

   s = getenv("CLIPROOT");
   if (s && *s)
      CLIPROOT = s;

   if (argc < 3)
   {
      fprintf(stderr, "usage: %s source_charset target_charset\n", argv[0]);
      return 1;
   }

   p1 = argv[1];
   p2 = argv[2];

   if (load_charset_name(p1, &cs1, &len1))
   {
      fprintf(stderr, "cannot load charset file '%s': %s", p1, strerror(errno));
      return 2;
   }

   if (!strcasecmp(p2, "utf-8"))
   {
      unsigned short *utbl = (unsigned short *) malloc(sizeof(unsigned short) * 256);

      make_utbl(utbl, cs1, len1);
      while ((ch = getchar()) != EOF)
	 put_utf8(utbl[ch & 0xff]);

      return 0;
   }

   if (!strcasecmp(p2, "ucs-2"))
   {
      unsigned short *utbl = (unsigned short *) malloc(sizeof(unsigned short) * 256);

      make_utbl(utbl, cs1, len1);
      while ((ch = getchar()) != EOF)
	 put_ucs2(utbl[ch & 0xff]);

      return 0;
   }

   if (load_charset_name(p2, &cs2, &len2))
   {
      fprintf(stderr, "cannot load charset file '%s': %s", p2, strerror(errno));
      return 3;
   }

   make_translation(cs1, len1, cs2, len2, tbl);

   while ((ch = getchar()) != EOF)
   {
      putchar(tbl[ch & 0xff]);
   }

   return 0;
}