コード例 #1
0
ファイル: braille.c プロジェクト: hinderer/brltty
/* the one already displayed */
static int brl_writeWindow(BrailleDisplay *brl, const wchar_t *text)
{
  brlapi_writeArguments_t arguments = BRLAPI_WRITEARGUMENTS_INITIALIZER;
  int vt = currentVirtualTerminal();

  if (vt == SCR_NO_VT) {
    /* should leave display */
    if (prevShown) {
      brlapi_write(&arguments);
      prevShown = 0;
    }
  } else {
    if (prevShown &&
        (memcmp(prevData,brl->buffer,displaySize) == 0) &&
        (!text || (wmemcmp(prevText,text,displaySize) == 0)) &&
        (brl->cursor == prevCursor)) {
      return 1;
    }

    unsigned char and[displaySize];
    memset(and, 0, sizeof(and));
    arguments.andMask = and;
    arguments.orMask = brl->buffer;

    if (text) {
      arguments.text = (char*) text;
      arguments.textSize = displaySize * sizeof(wchar_t);
      arguments.charset = (char*) getWcharCharset();
    }

    arguments.regionBegin = 1;
    arguments.regionSize = displaySize;
    arguments.cursor = (brl->cursor != BRL_NO_CURSOR)? (brl->cursor + 1): BRLAPI_CURSOR_OFF;

    if (brlapi_write(&arguments)==0) {
      memcpy(prevData,brl->buffer,displaySize);
      wmemcpy(prevText,text,displaySize);
      prevCursor = brl->cursor;
      prevShown = 1;
    } else {
      logMessage(LOG_ERR, "write: %s", brlapi_strerror(&brlapi_error));
      restart = 1;
    }
  }

  return 1;
}
コード例 #2
0
ファイル: charset_iconv.c プロジェクト: BaJIeK/brltty
int
registerCharacterSet (const char *charset) {
  const char *const wcharCharset = getWcharCharset();

  typedef struct {
    iconv_t *handle;
    const char *fromCharset;
    const char *toCharset;
    unsigned permanent:1;
    iconv_t newHandle;
  } ConvEntry;

  ConvEntry convTable[] = {
    {&iconvCharToWchar, charset, wcharCharset, 0, CHARSET_ICONV_NULL},
    {&iconvWcharToChar, wcharCharset, charset, 0, CHARSET_ICONV_NULL},
    {NULL, NULL, NULL, 1, CHARSET_ICONV_NULL}
  };
  ConvEntry *conv = convTable;

  while (conv->handle) {
    if (conv->permanent && (*conv->handle != CHARSET_ICONV_NULL)) {
      conv->newHandle = CHARSET_ICONV_NULL;
    } else if ((conv->newHandle = iconv_open(conv->toCharset, conv->fromCharset)) == CHARSET_ICONV_NULL) {
      logSystemError("iconv_open");

      while (conv != convTable)
        if ((--conv)->newHandle != CHARSET_ICONV_NULL)
          iconv_close(conv->newHandle);

      return 0;
    } else if (conv->permanent) {
      *conv->handle = conv->newHandle;
      conv->newHandle = CHARSET_ICONV_NULL;
    }

    conv += 1;
  }

  while (conv != convTable) {
    if ((--conv)->newHandle != CHARSET_ICONV_NULL) {
      if (*conv->handle != CHARSET_ICONV_NULL) iconv_close(*conv->handle);
      *conv->handle = conv->newHandle;
    }
  }

  return 1;
}
コード例 #3
0
int
registerCharacterSet (const char *charset) {
  int firstTime = 0;
  const char *const wcharCharset = getWcharCharset();

  typedef struct {
    iconv_t *const handle;
    const char *const fromCharset;
    const char *const toCharset;

    iconv_t newHandle;
  } ConvEntry;

  ConvEntry convTable[] = {
    { .handle = &iconvCharToWchar,
      .fromCharset = charset,
      .toCharset = wcharCharset
    },

    { .handle = &iconvWcharToChar,