예제 #1
0
파일: filesys.c 프로젝트: ctubio/alpine
int
write_a_wide_char(UCS ucs, FILE *fp)
{
#ifdef _WINDOWS
    int   rv = 1;
    TCHAR w;

    w = (TCHAR) ucs;
    if(_fputtc(w, fp) == _TEOF)
      rv = EOF;

    return(rv);
#else /* UNIX */
    int rv = 1;
    int i, outchars;
    unsigned char obuf[MAX(MB_LEN_MAX,32)];

     if(ucs < 0x80){
	obuf[0] = (unsigned char) ucs;
	outchars = 1;
    }
    else{
	outchars = wtomb((char *) obuf, ucs);
	if(outchars < 0){
	    outchars = 1;
	    obuf[0] = bad_char;		/* ??? */
	}
    }

    for(i = 0; i < outchars; i++)
      if(fputc(obuf[i], fp) == EOF){
	  rv = EOF;
	  break;
      }
        
    return(rv);
#endif /* UNIX */
}
예제 #2
0
파일: tty.c 프로젝트: RsrchBoy/dpkg-alpine
/*
 * ttputc - Write a character to the display. 
 */
int
ttputc(UCS ucs)
{
    unsigned char obuf[MAX(MB_LEN_MAX,32)];
    int  r, i, width = 0, outchars = 0;
    int  ret = 0;

    if(ucs < 0x80)
      return(putchar((unsigned char) ucs));

    width = wcellwidth(ucs);

    if(width < 0){
	width = 1;
	obuf[outchars++] = '?';
    }
    else{
	/*
	 * Convert the ucs into the multibyte
	 * character that corresponds to the
	 * ucs in the users locale.
	 */
	outchars = wtomb((char *) obuf, ucs);
	if(outchars < 0){
	    width = 1;
	    obuf[0] = '?';
	    outchars = 1;
	}
    }

    for(i = 0; i < outchars; i++){
	r = putchar(obuf[i]);
	ret = (ret == EOF) ? EOF : r;
    }

    return(ret);
}