SerialDevice * serialOpenDevice (const char *identifier) { char **parameters = serialGetDeviceParameters(identifier); if (parameters) { SerialDevice *serial; if ((serial = malloc(sizeof(*serial)))) { char *path; { const char *name = parameters[SERIAL_DEV_NAME]; if (!*name) name = SERIAL_FIRST_DEVICE; path = getDevicePath(name); } if (path) { int connected; serial->fileDescriptor = -1; serial->stream = NULL; connected = serialConnectDevice(serial, path); free(path); path = NULL; if (connected) { int ok = 1; if (!serialConfigureBaud(serial, parameters[SERIAL_DEV_BAUD])) ok = 0; if (!serialConfigureDataBits(serial, parameters[SERIAL_DEV_DATA_BITS])) ok = 0; if (!serialConfigureStopBits(serial, parameters[SERIAL_DEV_STOP_BITS])) ok = 0; if (!serialConfigureParity(serial, parameters[SERIAL_DEV_PARITY])) ok = 0; if (!serialConfigureFlowControl(serial, parameters[SERIAL_DEV_FLOW_CONTROL])) ok = 0; deallocateStrings(parameters); if (ok) return serial; serialCloseDevice(serial); return NULL; } } free(serial); } else { logMallocError(); } deallocateStrings(parameters); } return NULL; }
void authEnd (AuthDescriptor *auth) { releaseMethodDescriptors(auth, auth->count); if (auth->methods) free(auth->methods); deallocateStrings(auth->parameters); free(auth); }
int parseKeyboardProperties (KeyboardProperties *properties, const char *string) { enum { KBD_PARM_TYPE, KBD_PARM_VENDOR, KBD_PARM_PRODUCT }; static const char *const names[] = {"type", "vendor", "product", NULL}; char **parameters = getParameters(names, NULL, string); int ok = 1; logParameters(names, parameters, "Keyboard Property"); *properties = anyKeyboard; if (*parameters[KBD_PARM_TYPE]) { static const KeyboardType types[] = {KBD_TYPE_Any, KBD_TYPE_PS2, KBD_TYPE_USB, KBD_TYPE_Bluetooth}; static const char *choices[] = {"any", "ps2", "usb", "bluetooth", NULL}; unsigned int choice; if (validateChoice(&choice, parameters[KBD_PARM_TYPE], choices)) { properties->type = types[choice]; } else { logMessage(LOG_WARNING, "invalid keyboard type: %s", parameters[KBD_PARM_TYPE]); ok = 0; } } if (*parameters[KBD_PARM_VENDOR]) { static const int minimum = 0; static const int maximum = 0XFFFF; int value; if (validateInteger(&value, parameters[KBD_PARM_VENDOR], &minimum, &maximum)) { properties->vendor = value; } else { logMessage(LOG_WARNING, "invalid keyboard vendor code: %s", parameters[KBD_PARM_VENDOR]); ok = 0; } } if (*parameters[KBD_PARM_PRODUCT]) { static const int minimum = 0; static const int maximum = 0XFFFF; int value; if (validateInteger(&value, parameters[KBD_PARM_PRODUCT], &minimum, &maximum)) { properties->product = value; } else { logMessage(LOG_WARNING, "invalid keyboard product code: %s", parameters[KBD_PARM_PRODUCT]); ok = 0; } } deallocateStrings(parameters); return ok; }
static void processBootParameters ( OptionProcessingInformation *info, const char *parameter ) { const char *value; char *allocated = NULL; if (!(value = allocated = getBootParameters(parameter))) { if (!(value = getenv(parameter))) { return; } } { int parameterCount = 0; char **parameters = splitString(value, ',', ¶meterCount); for (unsigned int optionIndex=0; optionIndex<info->optionCount; optionIndex+=1) { const OptionEntry *option = &info->optionTable[optionIndex]; if ((option->bootParameter) && (option->bootParameter <= parameterCount)) { char *parameter = parameters[option->bootParameter-1]; if (*parameter) { { char *byte = parameter; do { if (*byte == '+') *byte = ','; } while (*++byte); } ensureSetting(info, option, parameter); } } } deallocateStrings(parameters); } if (allocated) free(allocated); }
static int processParameters_AtSpiScreen (char **parameters) { if (*parameters[PARM_TYPE]) { static const char *const choices[] = {"text" , "terminal" , "all" , NULL}; static int *const flags [] = {&typeText, &typeTerminal, &typeAll, NULL}; int count; char **types = splitString(parameters[PARM_TYPE], '+', &count); { int *const *flag = flags; while (*flag) **flag++ = 0; } { int index; for (index=0; index<count; index++) { const char *type = types[index]; unsigned int choice; if (validateChoice(&choice, type, choices)) { int *flag = flags[choice]; if ((flag == &typeAll) && (index > 0)) { logMessage(LOG_WARNING, "widget type is mutually exclusive: %s", type); } else if (*flag || typeAll) { logMessage(LOG_WARNING, "widget type specified more than once: %s", type); } else { *flag = 1; } } else { logMessage(LOG_WARNING, "%s: %s", "invalid widget type", type); } } } deallocateStrings(types); } return 1; }
static AuthDescriptor * authBegin (const char *parameter, const char *defaultParameter, AuthPerform perform) { AuthDescriptor *auth; if ((auth = malloc(sizeof(*auth)))) { auth->perform = perform; if (!parameter) parameter = ""; if (!*parameter) { parameter = defaultParameter; } else if (strcmp(parameter, "none") == 0) { parameter = ""; } if ((auth->parameters = splitString(parameter, '+', &auth->count))) { if (!auth->count) { auth->methods = NULL; return auth; } if ((auth->methods = malloc(ARRAY_SIZE(auth->methods, auth->count)))) { if (initializeMethodDescriptors(auth)) return auth; free(auth->methods); } else { logMallocError(); } deallocateStrings(auth->parameters); } free(auth); } else { logMallocError(); } return NULL; }
static char * findProgram (const char *name) { char *path = NULL; const char *string; if ((string = getenv("PATH"))) { int count; char **array; if ((array = splitString(string, ':', &count))) { int index; for (index=0; index<count; ++index) { const char *directory = array[index]; if (!*directory) directory = "."; if ((path = testProgram(directory, name))) break; } deallocateStrings(array); } } return path; }
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; }