Esempio n. 1
0
static int
getTable (TextTable **table, const char *name) {
  const char *directory = opt_tablesDirectory;

  *table = NULL;

  if (strcmp(name, tableName_unicode) != 0) {
    char *allocated = NULL;

    if (strcmp(name, tableName_autoselect) == 0) {
      if (!(name = allocated = selectTextTable(directory))) {
        logMessage(LOG_ERR, "cannot find text table for current locale");
      }
    }

    if (name) {
      char *path = makeTextTablePath(directory, name);

      if (path) {
        *table = compileTextTable(path);
        free(path);
      }
    }

    if (allocated) free(allocated);
     if (opt_noBaseCharacters) setTryBaseCharacter(*table, 0);
    if (!*table) return 0;
  }

  return 1;
}
Esempio n. 2
0
int
replaceTextTable (const char *directory, const char *name) {
  TextTable *newTable = NULL;

  if (name) {
    char *path;

    if ((path = makeTextTablePath(directory, name))) {
      logMessage(LOG_DEBUG, "compiling text table: %s", path);

      if (!(newTable = compileTextTable(path))) {
        logMessage(LOG_ERR, "%s: %s", gettext("cannot compile text table"), path);
      }

      free(path);
    }
  } else {
    newTable = &internalTextTable;
  }

  if (newTable) {
    TextTable *oldTable = textTable;

    textTable = newTable;
    destroyTextTable(oldTable);
    return 1;
  }

  logMessage(LOG_ERR, "%s: %s", gettext("cannot load text table"), name);
  return 0;
}
Esempio n. 3
0
static int
testTextTable (const char *directory, char *name) {
  int exists = 0;
  char *path;

  if ((path = makeTextTablePath(directory, name))) {
    logMessage(LOG_DEBUG, "checking for text table: %s", path);
    if (testFilePath(path)) exists = 1;
    free(path);
  }

  return exists;
}
Esempio n. 4
0
unsigned char
convertCharacterToDots (TextTable *table, wchar_t character) {
  switch (character & ~UNICODE_CELL_MASK) {
    case UNICODE_BRAILLE_ROW:
      return character & UNICODE_CELL_MASK;

    case 0XF000: {
      wint_t wc = convertCharToWchar(character & UNICODE_CELL_MASK);
      if (wc == WEOF) goto unknownCharacter;
      character = wc;
    }

    default: {
      {
        SetBrailleRepresentationData sbr = {
          .table = table,
          .dots = 0
        };

        if (handleBestCharacter(character, setBrailleRepresentation, &sbr)) {
          return sbr.dots;
        }
      }

    unknownCharacter:
      {
        const unsigned char *cell;

        if ((cell = getUnicodeCellEntry(table, UNICODE_REPLACEMENT_CHARACTER))) return *cell;
        if ((cell = getUnicodeCellEntry(table, WC_C('?')))) return *cell;
      }

      return BRL_DOT1 | BRL_DOT2 | BRL_DOT3 | BRL_DOT4 | BRL_DOT5 | BRL_DOT6 | BRL_DOT7 | BRL_DOT8;
    }
  }
}

wchar_t
convertDotsToCharacter (TextTable *table, unsigned char dots) {
  const TextTableHeader *header = table->header.fields;
  if (BITMASK_TEST(header->dotsCharacterDefined, dots)) return header->dotsToCharacter[dots];
  return UNICODE_REPLACEMENT_CHARACTER;
}

int
replaceTextTable (const char *directory, const char *name) {
  int ok = 0;
  char *path;

  if ((path = makeTextTablePath(directory, name))) {
    TextTable *newTable;

    logMessage(LOG_DEBUG, "compiling text table: %s", path);
    if ((newTable = compileTextTable(path))) {
      TextTable *oldTable = textTable;
      textTable = newTable;
      destroyTextTable(oldTable);
      ok = 1;
    } else {
      logMessage(LOG_ERR, "%s: %s", gettext("cannot compile text table"), path);
    }

    free(path);
  }

  if (!ok) logMessage(LOG_ERR, "%s: %s", gettext("cannot load text table"), name);
  return ok;
}