ESR_ReturnCode SR_EventLog_Token(SR_EventLog* self, const LCHAR* token, const LCHAR *value) { SR_EventLogImpl *impl = (SR_EventLogImpl *)self; LCHAR buf[TOK_BUFLEN]; if (self == NULL || token == NULL || value == NULL) return ESR_INVALID_ARGUMENT; if (impl->logLevel == 0) return ESR_SUCCESS; /* token cannot contain '=' */ if (LSTRCHR(token, L('=')) != NULL) { PLogError(L("SLEE: Token '%s' contains illegal '=' character"), token); return ESR_INVALID_ARGUMENT; } /* value cannot contain newline */ if (value && LSTRCHR(value, L('\n')) != NULL) { PLogError(L("SLEE: Value for token '%s' contains illegal newline character"), token); return ESR_INVALID_ARGUMENT; } /* the number 2 in this if statement refers to the '=' and the '|'. */ if (LSTRLEN(token) + LSTRLEN(value) + 2 + LSTRLEN(impl->tokenBuf) < MAX_LOG_RECORD) { if (LSTRLEN(token) + LSTRLEN(value) + 3 > TOK_BUFLEN) { PLogError(L("ESR_BUFFER_OVERFLOW: SLEE '|%s=%s'"), token, value); return ESR_BUFFER_OVERFLOW; } sprintf(buf, "%s=%s", token, value); if (quote_delimiter(buf, TOK_BUFLEN - 2) != 0) { PLogError(L("ESR_BUFFER_OVERFLOW: SLEE '|%s'"), buf); return ESR_BUFFER_OVERFLOW; } if (LSTRLEN(buf) + 1 + LSTRLEN(impl->tokenBuf) >= MAX_LOG_RECORD) { PLogError(L("ESR_BUFFER_OVERFLOW: SLEE '|%s'"), buf); return ESR_BUFFER_OVERFLOW; } strcat(impl->tokenBuf, "|"); strcat(impl->tokenBuf, buf); } else { PLogError(L("ESR_BUFFER_OVERFLOW: SLEE '|%s=%s'"), token, value); return ESR_BUFFER_OVERFLOW; } return ESR_SUCCESS; }
ESR_ReturnCode lstrreplace(LCHAR* text, const LCHAR source, const LCHAR target) { LCHAR* index; while (ESR_TRUE) { index = LSTRCHR(text, source); if (index == NULL) break; *index = target; } return ESR_SUCCESS; }
ESR_ReturnCode SR_EventLog_Event(SR_EventLog* self, const LCHAR* event) { SR_EventLogImpl *impl = (SR_EventLogImpl *)self; ESR_ReturnCode rc; long userTime, kernelTime; long cpuTime; LCHAR buf[P_PATH_MAX]; /* allow space for EVNT=<blah> */ size_t writtenSize; if (impl == NULL || event == NULL) return ESR_INVALID_ARGUMENT; if (impl->logLevel == 0) return ESR_SUCCESS; /* event cannot contain '=' */ if (LSTRCHR(event, L('=')) != NULL) { PLogError(L("SLEE: SR_EventLog_Event: warning: " "SR_EventLog_Event failed. Event '%s' contains illegal '=' " "character\n"), event); return ESR_INVALID_ARGUMENT; } CHKLOG(rc, PGetCPUTimes(&userTime, &kernelTime)); if (!LSTRCMP(event, "SWIrcst")) { impl->serviceStartUserCPU = userTime; impl->serviceStartKernelCPU = kernelTime; } LSTRCPY(buf, event); if (quote_delimiter(buf, LSTRLEN(buf) + 1) != 0) { PLogError(L("ESR_BUFFER_OVERFLOW: '%s' exceeds 8 characters when '|' characters are quoted"), buf); return ESR_BUFFER_OVERFLOW; } /* if this event is an end-of-recognition event then check to see if we want to capture this waveform. */ if (!LSTRCMP(event, "SWIrcnd")) { /* what to do ??? ALTsleeLogCheckWaveCapture(data); */ } cpuTime = userTime - impl->serviceStartUserCPU; SR_EventLogTokenInt(self, L("UCPU"), cpuTime); cpuTime = kernelTime - impl->serviceStartKernelCPU; SR_EventLogTokenInt(self, L("SCPU"), cpuTime); sprintf(buf, "EVNT=%s", event); /* This call will set writtenSize to be some value >= 0 */ logIt(impl, buf, impl->tokenBuf, &writtenSize); impl->tokenBuf[0] = 0; return ESR_SUCCESS; CLEANUP: return rc; }
ESR_ReturnCode SR_GrammarLoad(const LCHAR* grammar, SR_Grammar** self) { SR_Grammar* Interface = NULL; SR_GrammarImpl* impl; LCHAR* tok; ESR_ReturnCode rc; LCHAR filename[P_PATH_MAX]; int addWords; if (self == NULL) { PLogError(L("ESR_INVALID_ARGUMENT")); return ESR_INVALID_ARGUMENT; } CHKLOG(rc, SR_Grammar_Create(&Interface)); impl = (SR_GrammarImpl*) Interface; /** * Our filename (referring to the grammar to load, may have associated grammar properties * appended to the end of it. We need to split up the properties from the filename * example: * recog_nm/namesnnumsSC_dyn,addWords=2000 becomes * filename: recog_nm/namesnnumsSC_dyn * property: addWords=2000 */ /* init */ LSTRCPY(filename, grammar); addWords = 0; for (tok = strtok(filename, ","); tok; tok = strtok(NULL, ",")) { if (LSTRSTR(tok, "addWords")) { addWords = atoi(LSTRCHR(tok, L('=')) + sizeof(LCHAR)); } else if (tok != filename) { PLogError(L("UNKNOWN grammar load property %s"), tok); rc = ESR_INVALID_STATE; goto CLEANUP; } } /** * Based on the filename, determine if you are loading from image or loading from text files. * If from image, then the filename will have extension .g2g. If from file, then only a basename * will be provided (i.e. without extension) */ impl->syntax = CA_AllocateSyntax(); if (impl->syntax == NULL) { rc = ESR_OUT_OF_MEMORY; goto CLEANUP; } if (LSTRSTR(filename, L(".g2g"))) { /* if the filename ends with .g2g, then we have a binary image */ if (CA_LoadSyntaxFromImage(impl->syntax, (LCHAR*) filename)) { rc = ESR_READ_ERROR; PLogError(L("ESR_READ_ERROR: Problem loading syntax from image")); goto CLEANUP; } } else { if (CA_LoadSyntaxAsExtensible(impl->syntax, (LCHAR*) filename, addWords)) { rc = ESR_READ_ERROR; PLogError(L("ESR_READ_ERROR: Problem loading syntax from text")); goto CLEANUP; } } /* * Semantic Graph Loading * * - it was already created in Grammar_Create() * - reuse the same input labels from the recognition context * - load knows how to load from base filename or .g2g image */ rc = impl->semgraph->load(impl->semgraph, impl->syntax->synx->olabels, filename, addWords); if (rc != ESR_SUCCESS) { PLogError(L("%s: loading semgraph from image %s"), ESR_rc2str(rc), filename); impl->semgraph = NULL; goto CLEANUP; } *self = Interface; if (impl->eventLog) { CHKLOG(rc, SR_EventLogTokenPointer_BASIC(impl->eventLog, impl->logLevel, L("igrm"), impl)); CHKLOG(rc, SR_EventLogToken_BASIC(impl->eventLog, impl->logLevel, L("name"), filename)); CHKLOG(rc, SR_EventLogEvent_BASIC(impl->eventLog, impl->logLevel, L("ESRldgrm"))); } return ESR_SUCCESS; CLEANUP: if (Interface != NULL) Interface->destroy(Interface); *self = NULL; return rc; }