Back to index

cell-binutils  2.17cvs20070401
Functions
winduni.c File Reference
#include "bfd.h"
#include "bucomm.h"
#include "winduni.h"
#include "safe-ctype.h"

Go to the source code of this file.

Functions

void unicode_from_ascii (int *length, unichar **unicode, const char *ascii)
void unicode_print (FILE *e, const unichar *unicode, int length)

Function Documentation

void unicode_from_ascii ( int length,
unichar **  unicode,
const char *  ascii 
)

Definition at line 43 of file winduni.c.

{
  int len;
#ifndef _WIN32
  const char *s;
  unsigned short *w;

  len = strlen (ascii);
  *unicode = ((unichar *) res_alloc ((len + 1) * sizeof (unichar)));
  for (s = ascii, w = *unicode; *s != '\0'; s++, w++)
    *w = *s & 0xff;
  *w = 0;
#else
  /* We use  MultiByteToWideChar rather than strlen to get the unicode
     string length to allow multibyte "ascii" chars. The value returned
     by this function includes the trailing '\0'.  */
  len = MultiByteToWideChar (CP_ACP, 0, ascii, -1, NULL, 0);
  if (len)
    {
      *unicode = ((unichar *) res_alloc (len * sizeof (unichar)));
      MultiByteToWideChar (CP_ACP, 0, ascii, -1, *unicode, len);
    }
  /* Discount the trailing '/0'.  If MultiByteToWideChar failed,
     this will set *length to -1.  */
  len--;
#endif

  if (length != NULL)
    *length = len;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unicode_print ( FILE *  e,
const unichar unicode,
int  length 
)

Definition at line 80 of file winduni.c.

{
  while (1)
    {
      unichar ch;

      if (length == 0)
       return;
      if (length > 0)
       --length;

      ch = *unicode;

      if (ch == 0 && length < 0)
       return;

      ++unicode;

      if ((ch & 0x7f) == ch)
       {
         if (ch == '\\')
           fputs ("\\", e);
         else if (ISPRINT (ch))
           putc (ch, e);
         else
           {
             switch (ch)
              {
              case ESCAPE_A:
                fputs ("\\a", e);
                break;

              case ESCAPE_B:
                fputs ("\\b", e);
                break;

              case ESCAPE_F:
                fputs ("\\f", e);
                break;

              case ESCAPE_N:
                fputs ("\\n", e);
                break;

              case ESCAPE_R:
                fputs ("\\r", e);
                break;

              case ESCAPE_T:
                fputs ("\\t", e);
                break;

              case ESCAPE_V:
                fputs ("\\v", e);
                break;

              default:
                fprintf (e, "\\%03o", (unsigned int) ch);
                break;
              }
           }
       }
      else if ((ch & 0xff) == ch)
       fprintf (e, "\\%03o", (unsigned int) ch);
      else
       fprintf (e, "\\x%x", (unsigned int) ch);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function: