int enableSpeechInput (const char *name) { const char *directory; onProgramExit("speech-input", exitSpeechInput, NULL); #if defined(__MINGW32__) directory = "//./pipe"; #else /* set speech input directory */ directory = "."; #endif /* set speech input directory */ if ((speechInputPath = makePath(directory, name))) { #if defined(__MINGW32__) if ((speechInputHandle = CreateNamedPipe(speechInputPath, PIPE_ACCESS_INBOUND, PIPE_TYPE_MESSAGE|PIPE_READMODE_MESSAGE|PIPE_NOWAIT, 1, 0, 0, 0, NULL)) != INVALID_HANDLE_VALUE) { logMessage(LOG_DEBUG, "speech input pipe created: %s: handle=%u", speechInputPath, (unsigned)speechInputHandle); return 1; } else { logWindowsSystemError("CreateNamedPipe"); } #elif defined(S_ISFIFO) int result = mkfifo(speechInputPath, 0); if ((result == -1) && (errno == EEXIST)) { struct stat fifo; if ((lstat(speechInputPath, &fifo) != -1) && S_ISFIFO(fifo.st_mode)) result = 0; } if (result != -1) { chmod(speechInputPath, S_IRUSR|S_IWUSR|S_IWGRP|S_IWOTH); if ((speechInputDescriptor = open(speechInputPath, O_RDONLY|O_NONBLOCK)) != -1) { logMessage(LOG_DEBUG, "speech input FIFO created: %s: fd=%d", speechInputPath, speechInputDescriptor); return 1; } else { logMessage(LOG_ERR, "cannot open speech input FIFO: %s: %s", speechInputPath, strerror(errno)); } unlink(speechInputPath); } else { logMessage(LOG_ERR, "cannot create speech input FIFO: %s: %s", speechInputPath, strerror(errno)); } #endif /* enable speech input */ free(speechInputPath); speechInputPath = NULL; } return 0; }
AsyncThreadSpecificData * asyncGetThreadSpecificData (void) { if (!threadSpecificData) { if ((threadSpecificData = newThreadSpecificData())) { onProgramExit("async-data", exitThreadSpecificData, NULL); } } return threadSpecificData; }
int startRouting (int column, int row, int screen) { #ifdef SIGUSR1 int started = 0; stopRouting(); switch (routingProcess = fork()) { case 0: { /* child: cursor routing subprocess */ int result = ROUTING_ERROR; if (!ROUTING_INTERVAL) { int niceness = nice(ROUTING_NICENESS); if (niceness == -1) { logSystemError("nice"); } } if (constructRoutingScreen()) { result = doRouting(column, row, screen); /* terminate child process */ destructRoutingScreen(); /* close second thread of screen reading */ } _exit(result); /* terminate child process */ } case -1: /* error: fork() failed */ logSystemError("fork"); routingProcess = NOT_ROUTING; break; default: /* parent: continue while cursor is being routed */ { static int first = 1; if (first) { first = 0; onProgramExit(exitRouting, "routing"); } } started = 1; break; } return started; #else /* SIGUSR1 */ routingStatus = doRouting(column, row, screen); return 1; #endif /* SIGUSR1 */ }
static TuneRequest * newTuneRequest (TuneRequestType type) { TuneRequest *req; if (!tuneInitialized) { tuneInitialized = 1; onProgramExit("tunes", exitTunes, NULL); } if ((req = malloc(sizeof(*req)))) { memset(req, 0, sizeof(*req)); req->type = type; return req; } else { logMallocError(); } return NULL; }
static int insertAddressEntry (int index, AddressEntry *entry) { if (addressCount == addressLimit) { int newLimit = addressLimit + 1; AddressEntry **newTable = realloc(addressTable, ARRAY_SIZE(newTable, newLimit)); if (!newTable) { logMallocError(); return 0; } if (!addressTable) { onProgramExit("address-table", exitAddressTable, NULL); } addressTable = newTable; addressLimit = newLimit; } moveAddressSlice(index+1, index, (addressCount++ - index)); addressTable[index] = entry; return 1; }
void registerProgramStream (const char *name, FILE **stream) { onProgramExit(name, exitProgramStream, stream); }
void registerProgramMemory (const char *name, void *pointer) { onProgramExit(name, exitProgramMemory, pointer); }