static KEY_NAME_TABLES_REFERENCE getKeyNameTables (const char *keyTableName) { KEY_NAME_TABLES_REFERENCE keyNameTables = NULL; int componentsLeft; char **nameComponents = splitString(keyTableName, '-', &componentsLeft); if (nameComponents) { char **currentComponent = nameComponents; if (componentsLeft) { const char *keyTableType = (componentsLeft--, *currentComponent++); if (strcmp(keyTableType, "kbd") == 0) { if (componentsLeft) { componentsLeft--; currentComponent++; keyNameTables = KEY_NAME_TABLES(keyboard); } else { logMessage(LOG_ERR, "missing keyboard bindings name"); } } else if (strcmp(keyTableType, "brl") == 0) { if (componentsLeft) { void *driverObject; const char *driverCode = (componentsLeft--, *currentComponent++); if (loadBrailleDriver(driverCode, &driverObject, opt_driversDirectory)) { char *keyTablesSymbol; { const char *strings[] = {"brl_ktb_", driverCode}; keyTablesSymbol = joinStrings(strings, ARRAY_COUNT(strings)); } if (keyTablesSymbol) { const KeyTableDefinition *const *keyTableDefinitions; if (findSharedSymbol(driverObject, keyTablesSymbol, &keyTableDefinitions)) { const KeyTableDefinition *const *currentDefinition = keyTableDefinitions; if (componentsLeft) { const char *bindingsName = (componentsLeft--, *currentComponent++); while (*currentDefinition) { if (strcmp(bindingsName, (*currentDefinition)->bindings) == 0) { keyNameTables = (*currentDefinition)->names; break; } currentDefinition += 1; } if (!keyNameTables) { logMessage(LOG_ERR, "unknown %s braille driver bindings name: %s", driverCode, bindingsName); } } else { logMessage(LOG_ERR, "missing braille driver bindings name"); } } free(keyTablesSymbol); } else { logMallocError(); } } } else { logMessage(LOG_ERR, "missing braille driver code"); } } else { logMessage(LOG_ERR, "unknown key table type: %s", keyTableType); } } else { logMessage(LOG_ERR, "missing key table type"); } } if (keyNameTables) { if (componentsLeft) { logMessage(LOG_ERR, "too many key table name components"); keyNameTables = NULL; } } deallocateStrings(nameComponents); return keyNameTables; }
static int getKeyTableDescriptor (KeyTableDescriptor *ktd, const char *name) { int ok = 0; int componentsLeft; char **nameComponents = splitString(name, '-', &componentsLeft); memset(ktd, 0, sizeof(*ktd)); ktd->names = NULL; ktd->path = NULL; if (nameComponents) { char **currentComponent = nameComponents; if (componentsLeft) { const char *tableType = (componentsLeft--, *currentComponent++); if (strcmp(tableType, "kbd") == 0) { if (componentsLeft) { const char *keyboardType = (componentsLeft--, *currentComponent++); ktd->names = KEY_NAME_TABLES(keyboard); if ((ktd->path = makeKeyboardTablePath(opt_tablesDirectory, keyboardType))) ok = 1; } else { logMessage(LOG_ERR, "missing keyboard type"); } } else if (strcmp(tableType, "brl") == 0) { if (componentsLeft) { const char *driverCode = (componentsLeft--, *currentComponent++); if (loadBrailleDriver(driverCode, &driverObject, opt_driversDirectory)) { char *keyTablesSymbol; { const char *strings[] = {"brl_ktb_", driverCode}; keyTablesSymbol = joinStrings(strings, ARRAY_COUNT(strings)); } if (keyTablesSymbol) { const KeyTableDefinition *const *keyTableDefinitions; if (findSharedSymbol(driverObject, keyTablesSymbol, &keyTableDefinitions)) { const KeyTableDefinition *const *currentDefinition = keyTableDefinitions; if (componentsLeft) { const char *deviceType = (componentsLeft--, *currentComponent++); while (*currentDefinition) { if (strcmp(deviceType, (*currentDefinition)->bindings) == 0) { ktd->names = (*currentDefinition)->names; if ((ktd->path = makeInputTablePath(opt_tablesDirectory, driverCode, deviceType))) ok = 1; break; } currentDefinition += 1; } if (!ktd->names) { logMessage(LOG_ERR, "unknown braille device type: %s-%s", driverCode, deviceType); } } else { logMessage(LOG_ERR, "missing braille device type"); } } free(keyTablesSymbol); } else { logMallocError(); } } } else { logMessage(LOG_ERR, "missing braille driver code"); } } else { logMessage(LOG_ERR, "unknown key table type: %s", tableType); } } else { logMessage(LOG_ERR, "missing key table type"); } deallocateStrings(nameComponents); } if (ok) { if (componentsLeft) { logMessage(LOG_ERR, "too many key table name components"); ok = 0; } } if (ok) return 1; if (ktd->path) free(ktd->path); memset(ktd, 0, sizeof(*ktd)); return 0; }