Exemplo n.º 1
0
/*
 * Convert an integer to a string.
 */
ESR_ReturnCode litostr(int value, LCHAR *string, size_t *len, int radix)
{
  size_t size;
  /* pxtoa() is guaranteed not to overflow past 33 characters */
  LCHAR buffer[33];
  
  if (!string)
    return ESR_INVALID_ARGUMENT;
    
  if (radix == 10 && value < 0)
    pxtoa((unsigned long) value, buffer, radix, 1);
  else
    pxtoa((unsigned long) value, buffer, radix, 0);
    
  size = LSTRLEN(buffer);
  
  if (size >= *len)   /* + null-terminated character */
  {
    *len = size;
    return ESR_BUFFER_OVERFLOW;
  }
  else
    LSTRCPY(string, buffer);
    
  return ESR_SUCCESS;
}
Exemplo n.º 2
0
/* Convert an unsigned long integer to a string. */
ESR_ReturnCode lultostr(unsigned long  value, LCHAR *string, size_t *len, int radix)
{
  size_t size;
  LCHAR buffer[33];
  
  if (!string)
    return ESR_INVALID_ARGUMENT;
    
  pxtoa(value, buffer, radix, 0);
  
  size = LSTRLEN(buffer);
  
  if (size >= *len)   /* + null-terminated character */
  {
    *len = size;
    return ESR_BUFFER_OVERFLOW;
  }
  else
  {
    *len = size;
    LSTRCPY(string, buffer);
  }
  
  return ESR_SUCCESS;
}
Exemplo n.º 3
0
ESR_ReturnCode HashMap_Put(HashMap* self, const LCHAR* key, void* value)
{
  HashMapImpl* impl = (HashMapImpl*) self;
  PHashTableEntry *entry = NULL;
  ESR_ReturnCode rc;
  ESR_BOOL exists;
  
  CHKLOG(rc, PHashTableContainsKey(impl->table, key, &exists));
  if (!exists)
  {
    /* Not found, clone the key and insert it. */
    LCHAR *clone = (LCHAR *) MALLOC(sizeof(LCHAR) * (LSTRLEN(key) + 1), MTAG);
    if (clone == NULL) return ESR_OUT_OF_MEMORY;
    LSTRCPY(clone, key);
    if ((rc = PHashTablePutValue(impl->table, clone, value, NULL)) != ESR_SUCCESS)
    {
      FREE(clone);
    }
  }
  else
  {
    /* Key already present in table, just change the value. */
    CHKLOG(rc, PHashTableGetEntry(impl->table, key, &entry));
    rc = PHashTableEntrySetValue(entry, value, NULL);
  }
  return rc;
CLEANUP:
  return rc;
}
Exemplo n.º 4
0
VOID text_wh(LONG taddr, WORD type, WORD *w, WORD *h)
{
	WORD	font;

	font = LWGET(TE_FONT(taddr));
	taddr = LLGET( (type == G_TEXT || type == G_BOXTEXT)? TE_PTEXT(taddr): TE_PTMPLT(taddr) );
	*h = ch_height(font);
	*w = ch_width(font) * (WORD)LSTRLEN(taddr);
}
Exemplo n.º 5
0
ESR_ReturnCode SR_Nametag_Clone(const SR_Nametag* self, SR_Nametag** result)
{
  SR_NametagImpl* impl = (SR_NametagImpl*) self;
  ESR_ReturnCode rc;
  
  CHKLOG(rc, SR_NametagCreateFromValue(impl->id, impl->value, LSTRLEN(impl->value)+1, result));
  return ESR_SUCCESS;
CLEANUP:
  return rc;
}
Exemplo n.º 6
0
ESR_ReturnCode SR_EventLog_AudioGetFilename(SR_EventLog* self, LCHAR* waveformFilename, size_t* len)
{
  SR_EventLogImpl *impl = (SR_EventLogImpl*) self;

  if (waveformFilename == NULL)
  {
    PLogError(L("ESR_INVALID_ARGUMENT"));
    return ESR_INVALID_ARGUMENT;
  }

  if (*len < LSTRLEN(impl->waveformFilename))
  {
    PLogError(L("ESR_BUFFER_OVERFLOW"));
    return ESR_BUFFER_OVERFLOW;
  }

  LSTRCPY(waveformFilename, impl->waveformFilename);
  *len = LSTRLEN(waveformFilename);
  return ESR_SUCCESS;
}
Exemplo n.º 7
0
ESR_ReturnCode PFileGetFilenameImpl(PFile* self, LCHAR* filename, size_t* len)
{
  PFileImpl* impl = (PFileImpl*) self;
  ESR_ReturnCode rc;
  
  if (self == NULL || len == NULL)
  {
    PLogError(L("ESR_INVALID_ARGUMENT"));
    return ESR_INVALID_ARGUMENT;
  }
  LOCK_MUTEX(rc, impl);
  if (LSTRLEN(impl->filename) + 1 > *len)
  {
    *len = LSTRLEN(impl->filename) + 1;
    rc = ESR_BUFFER_OVERFLOW;
    goto CLEANUP;
  }
  LSTRCPY(filename, impl->filename);
  CLEANUP_AND_RETURN(rc, impl);
}
Exemplo n.º 8
0
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;
}
Exemplo n.º 9
0
ESR_ReturnCode lstrtrim(LCHAR* text)
{
  size_t beginning, ending, len;
  
  len = LSTRLEN(text);
  
  /* locating first non-whitespace character from beginning */
  for (beginning = 0; beginning < len && LISSPACE(text[beginning]); ++beginning);
  /* locating first non-whitespace character from end */
  for (ending = len - 1; ending > beginning && LISSPACE(text[ending]); --ending);
  
  if (beginning > 0 && beginning <= ending)
    LMEMMOVE(text, text + beginning, ending - beginning + 1);
  text[ending-beginning+1] = '\0';
  return ESR_SUCCESS;
}
Exemplo n.º 10
0
/**
 * Initializes variables declared in the superinterface.
 */
ESR_ReturnCode PFileCreateImpl(PFile* self, const LCHAR* filename, ESR_BOOL isLittleEndian)
{
  PFileImpl* impl = (PFileImpl*) self;
  ESR_ReturnCode rc;
#ifdef USE_THREAD
  ESR_BOOL threadingEnabled;
#endif
  
#ifdef USE_THREAD
  impl->lock = NULL;
#endif
  impl->littleEndian = isLittleEndian;
  
  impl->Interface.destroy = &PFileDestroyImpl;
  impl->Interface.getFilename = &PFileGetFilenameImpl;
  impl->Interface.vfprintf = &PFileVfprintfImpl;
  impl->filename = MALLOC(sizeof(LCHAR) * (LSTRLEN(filename) + 1), MTAG);
  
  if (impl->filename == NULL)
  {
    rc = ESR_OUT_OF_MEMORY;
    PLogError(ESR_rc2str(rc));
    goto CLEANUP;
  }
  LSTRCPY(impl->filename, filename);
  
#ifdef USE_THREAD
  rc = PtrdIsEnabled(&threadingEnabled);
  if (rc != ESR_SUCCESS)
  {
    pfprintf(PSTDERR, L("[%s:%d] PtrdIsEnabled failed with %s\n"), __FILE__, __LINE__, ESR_rc2str(rc));
    goto CLEANUP;
  }
  if (threadingEnabled)
  {
    rc = PtrdMonitorCreate(&impl->lock);
    if (rc != ESR_SUCCESS)
      goto CLEANUP;
  }
#endif
  return ESR_SUCCESS;
CLEANUP:
  self->destroy(self);
  return rc;
}
Exemplo n.º 11
0
ESR_ReturnCode SR_Nametag_SetID(SR_Nametag* self, const LCHAR* id)
{
  SR_NametagImpl* impl = (SR_NametagImpl*) self;
  ESR_ReturnCode rc;
  
  FREE(impl->id);
  impl->id = (LCHAR*) MALLOC(sizeof(LCHAR) * (LSTRLEN(id) + 1), MTAG);
  if (impl->id == NULL)
  {
    rc = ESR_OUT_OF_MEMORY;
    PLogError(ESR_rc2str(rc));
    goto CLEANUP;
  }
  LSTRCPY(impl->id, id);
  
  return ESR_SUCCESS;
CLEANUP:
  return rc;
}
Exemplo n.º 12
0
void doGetProns(SR_Vocabulary *vocab, LCHAR* phrase, size_t len, FILE* fout)
{
  ESR_ReturnCode rc;
  LCHAR prons[MAX_PRONS_LENGTH];

  rc = SR_VocabularyGetPronunciation(vocab, phrase, prons, &len);
  // rc = vocab->getPronunciation(vocab, phrase, prons, &len);

  if (rc != ESR_SUCCESS)
    LFPRINTF(fout,"ERROR: %s\n", ESR_rc2str(rc));
  else {
    size_t len_used;
    LCHAR *pron = 0;
    for(len_used=0; len_used<len; ) {
      pron = &prons[0]+len_used;
      len_used += LSTRLEN(pron)+1;
      LFPRINTF(fout,"%s : %s\n", phrase, pron);
    }
  }
}
Exemplo n.º 13
0
static int quote_delimiter(LCHAR *record, size_t len)
{
  LCHAR qrecord[TOK_BUFLEN * 2];
  LCHAR *s, *d;

  s = record;
  d = qrecord;
  while (*s)
  {
    if (*s == '|')
      *d++ = '|';
    *d++ = *s++;
  }
  *d = L('\0');

  if (LSTRLEN(qrecord) >= len)
    return -1;

  LSTRCPY(record, qrecord);

  return 0;
}
Exemplo n.º 14
0
ESR_ReturnCode PFileVfprintfImpl(PFile* self, int* result, const LCHAR* format, va_list args)
{
  ESR_ReturnCode rc;
  ESR_BOOL isOpen;
#define BUFFER_SIZE 5120
  static LCHAR buffer[BUFFER_SIZE];
  size_t len;
  
  if (self == NULL)
  {
    PLogError(L("ESR_INVALID_ARGUMENT"));
    return ESR_INVALID_ARGUMENT;
  }
  
  CHKLOG(rc, self->isOpen(self, &isOpen));
  if (!isOpen)
  {
    rc = ESR_OPEN_ERROR;
    PLogError(L("%s: cannot operate on closed file"), ESR_rc2str(rc));
    goto CLEANUP;
  }
  
  /*
   * fprintf() is computationally expensive, so we compute its output without grabbing a lock
   * and only lock while actually writing the results into the file.
   */
  if (result != NULL)
    *result = vsprintf(buffer, format, args);
  else
    vsprintf(buffer, format, args);
  len = LSTRLEN(buffer);
  passert(len < BUFFER_SIZE);
  
  CHKLOG(rc, self->write(self, buffer, sizeof(LCHAR), &len));
  return ESR_SUCCESS;
CLEANUP:
  return rc;
}
Exemplo n.º 15
0
ESR_ReturnCode lstrinsert(const LCHAR* source, LCHAR* target, size_t offset, size_t* len)
{
  ESR_ReturnCode rc;
  
  if (source == NULL || target == NULL || len == NULL)
  {
    rc = ESR_INVALID_ARGUMENT;
    PLogError(ESR_rc2str(rc));
    goto CLEANUP;
  }
  if (LSTRLEN(source) + LSTRLEN(target) + 1 > *len)
  {
    *len = LSTRLEN(source) + LSTRLEN(target) + 1;
    rc = ESR_BUFFER_OVERFLOW;
    PLOG_DBG_TRACE((ESR_rc2str(rc)));
    goto CLEANUP;
  }
  memmove(target + offset + LSTRLEN(source), target + offset, LSTRLEN(target + offset) + 1);
  LSTRNCPY(target + offset, source, LSTRLEN(source));
  return ESR_SUCCESS;
CLEANUP:
  return rc;
}
Exemplo n.º 16
0
ESR_ReturnCode SR_NametagsLoadImpl(SR_Nametags* self, const LCHAR* filename)
{
  SR_NametagsImpl* impl = (SR_NametagsImpl*) self;
  ESR_ReturnCode rc;
  PFile* file = NULL;
  LCHAR line[256];
  LCHAR* result = NULL;
  LCHAR* id;
  LCHAR* value;
  SR_Nametag* newNametag = NULL;
  SR_Nametag* oldNametag;
  HashMap* nametags = impl->value;
  size_t size, len, i;
  LCHAR devicePath[P_PATH_MAX];
  LCHAR number[MAX_UINT_DIGITS+1];
#define NAMETAGID_LENGTH 20
  /* strlen("token\0") == 6 */
#define TOKEN_LENGTH 6 + NAMETAGID_LENGTH
  LCHAR tokenName[TOKEN_LENGTH];

  if (filename == NULL)
  {
    rc = ESR_INVALID_STATE;
    PLogError(ESR_rc2str(rc));
    goto CLEANUP;
  }
  size = P_PATH_MAX;
  CHKLOG(rc, ESR_SessionGetLCHAR(L("cmdline.nametagPath"), devicePath, &size));
  /* check if the filename has the path */
  if (LSTRNCMP(filename, devicePath, LSTRLEN(devicePath)) != 0)
    LSTRCAT(devicePath, filename);
  else
    LSTRCPY(devicePath, filename);
  file = pfopen ( devicePath, L("r"));
/*  CHKLOG(rc, PFileSystemCreatePFile(devicePath, ESR_TRUE, &file));
  CHKLOG(rc, file->open(file, L("r")));*/

  if ( file == NULL )
    goto CLEANUP;

  /* Flush collection */
  CHKLOG(rc, nametags->getSize(nametags, &size));
  for (i = 0; i < size; ++i)
  {
    CHKLOG(rc, nametags->getValueAtIndex(nametags, 0, (void **)&oldNametag));
    CHKLOG(rc, nametags->removeAtIndex(nametags, 0));
    CHKLOG(rc, oldNametag->destroy(oldNametag));
  }
  len = MAX_UINT_DIGITS + 1;
  CHKLOG(rc, lultostr(size, number, &len, 10));
  CHKLOG(rc, SR_EventLogToken_BASIC(impl->eventLog, impl->logLevel, L("removeCount"), number));

  while (ESR_TRUE)
  {
    result = pfgets ( line, 256, file );
    if (result == NULL)
      break;
    if (LSTRLEN(line) == 255)
    {
      rc = ESR_BUFFER_OVERFLOW;
      PLogError(ESR_rc2str(rc));
      goto CLEANUP;
    }
    lstrtrim(line);

    /* Get the Nametag ID */
    id = line;

    /* Find next whitespace */
    for (value = id + 1; *value != L('\0') && !LISSPACE(*value); ++value);
    if (*value == L('\0'))
    {
      rc = ESR_INVALID_STATE;
      PLogError(L("%s: Cannot find end of Nametag id"), ESR_rc2str(rc));
      goto CLEANUP;
    }
    /* Delimit end of nametag ID */
    *value = L('\0');

    /* Find next non-whitespace */
    for (++value; *value != L('\0') && LISSPACE(*value); ++value);
    if (*value == L('\0'))
    {
      rc = ESR_INVALID_STATE;
      PLogError(L("%s: Cannot find Nametag value"), ESR_rc2str(rc));
      goto CLEANUP;
    }

    /* We now have both the Nametag ID and value */
	len = (LSTRLEN(value)+1) * sizeof(LCHAR) ;
    CHKLOG(rc, SR_NametagCreateFromValue(id, (const char*)value, len, &newNametag));
    /* Add Nametag to collection */
    CHKLOG(rc, impl->value->put(impl->value, id, newNametag));

    if (LSTRLEN(id) > NAMETAGID_LENGTH)
    {
      rc = ESR_BUFFER_OVERFLOW;
      PLogError(ESR_rc2str(rc));
      goto CLEANUP;
    }
    psprintf(tokenName, L("nametag[%s]"), id);
    CHKLOG(rc, SR_EventLogToken_BASIC(impl->eventLog, impl->logLevel, tokenName, value));
    newNametag = NULL;
  }
  CHKLOG(rc, SR_EventLogToken_BASIC(impl->eventLog, impl->logLevel, L("filename"), filename));
  CHKLOG(rc, nametags->getSize(nametags, &size));
  len = MAX_UINT_DIGITS + 1;
  CHKLOG(rc, lultostr(size, number, &len, 10));
  CHKLOG(rc, SR_EventLogToken_BASIC(impl->eventLog, impl->logLevel, L("addCount"), number));
  CHKLOG(rc, SR_EventLogEvent_BASIC(impl->eventLog, impl->logLevel, L("SR_NametagsLoad")));
  pfclose (file);
  return ESR_SUCCESS;
CLEANUP:
  if (file != NULL)
    pfclose (file);
  if (newNametag != NULL)
    newNametag->destroy(newNametag);
  return rc;
}
Exemplo n.º 17
0
ESR_ReturnCode SR_NametagsSaveImpl(SR_Nametags* self, const LCHAR* filename)
{
  SR_NametagsImpl* impl = (SR_NametagsImpl*) self;
  ESR_ReturnCode rc;
  PFile* file = NULL;
  size_t size, i;
  HashMap* nametags = impl->value;
  SR_NametagImpl* nametag;
  LCHAR* id;
  size_t len;
  LCHAR devicePath[P_PATH_MAX];
#define NAMETAG_LENGTH 200
  LCHAR nametagBuffer[NAMETAG_LENGTH];
  LCHAR number[MAX_UINT_DIGITS+1];
#define NAMETAGID_LENGTH 20
  /* "token\0" == 6 */
#define TOKEN_LENGTH 6 + NAMETAGID_LENGTH
  LCHAR tokenName[TOKEN_LENGTH];
  size_t num_written;

  if (filename == NULL)
  {
    rc = ESR_INVALID_STATE;
    PLogError(ESR_rc2str(rc));
    goto CLEANUP;
  }
  size = P_PATH_MAX;
  CHKLOG(rc, ESR_SessionGetLCHAR(L("cmdline.nametagPath"), devicePath, &size));

  if (LSTRNCMP(filename, devicePath, LSTRLEN(devicePath)) != 0)
    LSTRCAT(devicePath, filename);
  else
    LSTRCPY(devicePath, filename);

  file = pfopen ( devicePath, L("w"));
/*  CHKLOG(rc, PFileSystemCreatePFile(devicePath, ESR_TRUE, &file));
  CHKLOG(rc, file->open(file, L("w")));*/
  CHKLOG(rc, nametags->getSize(nametags, &size));

  if ( file == NULL )
    goto CLEANUP;

  for (i = 0; i < size; ++i)
  {
    CHKLOG(rc, nametags->getValueAtIndex(nametags, i, (void **)&nametag));

    CHKLOG(rc, nametag->Interface.getID(&nametag->Interface, &id));

    if (LSTRLEN(id) + 1 + LSTRLEN(nametag->value) + 2 >= NAMETAG_LENGTH)
    {
      rc = ESR_BUFFER_OVERFLOW;
      PLogError(ESR_rc2str(rc));
      goto CLEANUP;
    }
    psprintf(nametagBuffer, L("%s %s\n"), id, nametag->value);
    len = LSTRLEN(nametagBuffer);
/*    CHKLOG(rc, file->write(file, nametagBuffer, sizeof(LCHAR), &len));*/
    num_written = pfwrite ( nametagBuffer, sizeof ( LCHAR ), len, file );

    if ( num_written != len )
        goto CLEANUP;

    if (LSTRLEN(id) > NAMETAGID_LENGTH)
    {
      rc = ESR_BUFFER_OVERFLOW;
      PLogError(ESR_rc2str(rc));
      goto CLEANUP;
    }
    psprintf(tokenName, L("nametag[%s]"), id);
    CHKLOG(rc, SR_EventLogToken_BASIC(impl->eventLog, impl->logLevel, tokenName, nametag->value));
  }
  CHKLOG(rc, SR_EventLogToken_BASIC(impl->eventLog, impl->logLevel, L("filename"), filename));
  len = MAX_UINT_DIGITS + 1;
  CHKLOG(rc, lultostr(size, (LCHAR*) &number, &len, 10));
  CHKLOG(rc, SR_EventLogToken_BASIC(impl->eventLog, impl->logLevel, L("saveCount"), number));
  CHKLOG(rc, SR_EventLogEvent_BASIC(impl->eventLog, impl->logLevel, L("SR_NametagsSave")));
  pfclose (file);
  return ESR_SUCCESS;
CLEANUP:
  if (file != NULL)
    pfclose (file);
  return rc;
}
ESR_ReturnCode SR_RecognizerResult_GetValue(const SR_RecognizerResult* self, const size_t nbest, 
																						const LCHAR* key, LCHAR* value, size_t* len)
{
  SR_RecognizerResultImpl* impl = (SR_RecognizerResultImpl*) self;
  ArrayList* results;
  SR_SemanticResult* result;
  SR_SemanticResultImpl* resultImpl;
  LCHAR* lValue;
  size_t actualLen = 0, i, resultCount;
  ESR_ReturnCode rc;
  ESR_BOOL noMatch = ESR_TRUE;
  
  /* Choose nbest-list entry */
  CHKLOG(rc, impl->results->get(impl->results, nbest, (void **)&results));
  /* Get the number of semantic results for the entry */
  CHKLOG(rc, results->getSize(results, &resultCount));
  
  for (i = 0; i < resultCount; ++i)
  {
    /* Choose semantic result */
    CHKLOG(rc, results->get(results, i, (void **)&result));
    resultImpl = (SR_SemanticResultImpl*) result;
    rc = resultImpl->results->get(resultImpl->results, key, (void**) & lValue);
    if (rc == ESR_SUCCESS)
    {
      noMatch = ESR_FALSE;
      actualLen += LSTRLEN(lValue);
    }
    else if (rc != ESR_NO_MATCH_ERROR)
      return rc;
  }
  if (noMatch)
    return ESR_NO_MATCH_ERROR;
  ++actualLen;
  
  /* Check for overflow */
  if (actualLen + 1 > *len)
  {
/* Unfortunately some people are using get value functions to get the size of the value by
 * passing a zero length buffer which causes errors to be logged. I am adding code so
 * that the error is not logged when the length is zero, thus preventing lots of logs from
 * flooding the system.  SteveR
 */
    if ( ( *len ) != 0 )
      PLogError(L("Buffer Overflow while fetching value for %s of choice %d Len %d"),
		key, nbest, *len );
    *len = actualLen + 1;
    return ESR_BUFFER_OVERFLOW;
  }
  *len = actualLen;
  
  LSTRCPY(value, L(""));
  for (i = 0; i < resultCount; ++i)
  {
    /* Choose semantic result */
    CHKLOG(rc, results->get(results, i, (void **)&result));
    resultImpl = (SR_SemanticResultImpl*) result;
    rc = resultImpl->results->get(resultImpl->results, key, (void **) & lValue);
    if (rc == ESR_SUCCESS)
      LSTRCAT(value, lValue);
    else if (rc != ESR_NO_MATCH_ERROR)
      return rc;
      
    /* Separate semantic results with '#' token */
	if (i < resultCount - 1) {
		int len = LSTRLEN(value);
		value[len] = MULTIPLE_MEANING_JOIN_CHAR;
        value[len+1] = 0;
	}
  }
  return ESR_SUCCESS;
CLEANUP:
  return rc;
}
Exemplo n.º 19
0
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;
}
Exemplo n.º 20
0
ESR_ReturnCode logIt(SR_EventLogImpl *impl, LCHAR* evtt, LCHAR* log_record, size_t* writtenSize)
{
  struct tm *ct, ct_r;
  LCHAR header[128], header2[64];
  PTimeStamp timestamp;
  const size_t sizeof_LCHAR = sizeof(LCHAR);
  const LCHAR* bar = "|";
  const LCHAR* nl = "\n";
  size_t i, len;
  const LCHAR* toWrite[5];

  toWrite[0] = header;
  toWrite[1] = bar;
  toWrite[2] = evtt;
  toWrite[3] = log_record;
  toWrite[4] = nl;

  ct = &ct_r;
  memset(ct, 0, sizeof(struct tm));

  switch (impl->logFile_state)
  {
    case FILE_OK:
    case SPACE_SETTING:
      PTimeStampSet(&timestamp);
      ct = localtime_r(&timestamp.secs, &ct_r);

      sprintf(header, "TIME=%04d%02d%02d%02d%02d%02d%03d",
              ct->tm_year + 1900, ct->tm_mon + 1, ct->tm_mday, ct->tm_hour,
              ct->tm_min, ct->tm_sec, timestamp.msecs);
      quote_delimiter(header, 128);

      sprintf(header2, "CHAN=%s", L("0")); /* default is channel 0 in ESR */
      quote_delimiter(header2, 128);

      LSTRCAT(header, bar);
      LSTRCAT(header, header2);

      /* write the header,bar,evtt, and record */
      for (*writtenSize = 0, i = 0; i < 5; i++)
      {
        len = LSTRLEN(toWrite[i]);
        if (pfwrite(toWrite[i], sizeof_LCHAR, len, impl->logFile))
          *writtenSize += len;
      }

      if (*writtenSize <= 0)
      {
        PLogError(L("Could not write to log file; logging halted"));
        impl->logFile_state = FILE_ERROR;
        break;
      }
      else
      {
        pfflush(impl->logFile);
      }

      break;

      /* If couldn't open file or error previously, just return */
    case UNINITIALIZED:
    case NO_FILE:
    case FILE_ERROR:
    case SEEK_ERROR:
    default:
      return ESR_INVALID_STATE;

  }

  return ESR_SUCCESS;
}
Exemplo n.º 21
0
VOID view_trees(VOID)
{
	WORD	nobj, iobj;
	WORD	kind, where, nh; 
	LONG	tree, iconad;

	tree = ad_pbx;
	rcs_work[0].ob_next = NIL;	/* construct tree root */
	rcs_work[0].ob_type = G_BOX;
	rcs_work[0].ob_flags = NONE;
	rcs_work[0].ob_state = NORMAL;
#if TURBO_C
	rcs_work[0].ob_spec.index = 0x00000007L;
#else
	rcs_work[0].ob_spec = 0x00000007L;
#endif
	rcs_work[0].ob_x = view.g_x;
	rcs_work[0].ob_y = view.g_y;
	rcs_work[0].ob_width = view.g_w;
	rcs_work[0].ob_height = view.g_h;

	if (!LWGET(RSH_NTREE(head)))
	{
		rcs_work[0].ob_head = NIL;
		rcs_work[0].ob_tail = NIL;
	}
	else
	{
		nobj = min(VIEWSIZE, LWGET(RSH_NTREE(head)) - rcs_trpan); 
		nobj = min(nobj, fit_vtrees() * (nh = fit_htrees()));

		rcs_work[0].ob_head = 1;	/* root pointers */
		rcs_work[0].ob_tail = nobj;

		for (iobj = 0; iobj++ < nobj; )
		{
			if (iobj < nobj)
				rcs_work[iobj].ob_next = iobj + 1;
			else
				rcs_work[iobj].ob_next = ROOT;
			rcs_work[iobj].ob_head = NIL;
			rcs_work[iobj].ob_tail = NIL;
			rcs_work[iobj].ob_flags = NONE;
			rcs_work[iobj].ob_state = NORMAL;
			rcs_work[iobj].ob_type = G_ICON;
#if TURBO_C
			rcs_work[iobj].ob_spec.iconblk =
				(ICONBLK *)ADDR(&rcs_icons[iobj]);
#else
			rcs_work[iobj].ob_spec = ADDR(&rcs_icons[iobj]);
#endif
			rcs_work[iobj].ob_width = ICON_W;
			rcs_work[iobj].ob_height = ICON_H + gl_hschar;
			rcs_work[iobj].ob_x = ((iobj - 1) % nh) * (ICON_W + MIN_WINT);
			rcs_work[iobj].ob_y = ((iobj - 1) / nh) * (ICON_H + MIN_HINT);

			where = find_tree(iobj + rcs_trpan - 1);
			kind = get_kind(where);
			iconad = GET_SPEC(tree, rcs_typ2icn[kind]);
			LBCOPY(ADDR(&rcs_icons[iobj]), iconad, sizeof(ICONBLK));	
			rcs_icons[iobj].ib_ptext = 		/* address of tree */
				(char *)ADDR( get_name(where) );
			rcs_icons[iobj].ib_wtext =
				ch_width(IBM) * (WORD)LSTRLEN(rcs_icons[iobj].ib_ptext);
			rcs_icons[iobj].ib_ytext = ICON_H;
			rcs_icons[iobj].ib_xtext =
				(rcs_icons[iobj].ib_wicon - rcs_icons[iobj].ib_wtext) / 2;
		}
	}
}
Exemplo n.º 22
0
VOID edit_str(LONG tree, WORD sobj)
{
	LONG	obspec; 
	WORD	where, type, exitobj, ok;
	GRECT	p;
	WORD	min_width, neww, len; 
	BYTE	text[73], name[9]; 

	get_fields(tree, sobj, &type, &obspec, &p);
	len = (WORD)LSTRLEN(LLGET(obspec));
	if (len <= 72)
	{
		ini_tree(&tree, STRDIAL);
		where = set_obname(tree, STRNAME, name, ad_view, sobj);
		set_text(tree, OSTRITEM, (LONG)ADDR(&text[0]), 73);
		LLSTRCPY(LLGET(obspec), (LONG)ADDR(&text[0]));
		if ( rcs_state == ALRT_STATE )
			hide_obj( tree, STRNAME);
		if (!text[0])
			text[0] = '@';
		do {
			exitobj = hndl_dial(tree, OSTRITEM, &p);
			desel_obj(tree, exitobj);
			ok = DEFAULT & GET_FLAGS(tree, exitobj);
		} while ( ok && !name_ok(name, where, TRUE));

		if (ok)
		{
			rcs_edited = TRUE;
			get_obname(name, ad_view, sobj);
			if (text[0] == '@')
				text[0] = '\0';

			if (rcs_state == ALRT_STATE)
			{		
				if (strlen(text) > 40 )
				{
					hndl_alert(1, string_addr(STOOLONG));
					text[40] = '\0';
				}
				update_if(obspec, &text[0]);
				fix_alert(ad_view);
				unhide_obj(tree, STRNAME);
			}
			else
			{
				neww = (WORD)(gl_wchar * strlen(text));
				if (rcs_state == MENU_STATE)
				{
					if (type == G_TITLE)
					{
						if (!newsize_obj(ad_view, sobj, neww,gl_hchar, TRUE))
							text[len] = '\0';
						fix_menu_bar(ad_view);
					}
					else if (in_which_menu(ad_view, sobj) == 1
						&& in_menu(ad_view, sobj) == 1
						&& strlen(text) > 20 )
		    		{
						hndl_alert(1, string_addr(STOOLONG));	
						text[20] = '\0';
					}
					else  if(!newsize_obj(ad_view, sobj, neww,gl_hchar, FALSE))
						text[len] = '\0';
				}
				else if (type == G_STRING || type == G_BUTTON )
				{
					min_width = GET_WIDTH(ad_view, sobj);
					if( neww > min_width )
						if(!newsize_obj(ad_view, sobj, neww,gl_hchar, FALSE))
							text[len] = '\0';
				}
			}
			if( rcs_state != ALRT_STATE)
				update_if(obspec, &text[0]);
		}
	}
}
Exemplo n.º 23
0
ESR_ReturnCode SR_NametagCreate(const SR_RecognizerResult* result, const LCHAR* id, SR_Nametag** self)
{
  ESR_Locale locale;
  ESR_ReturnCode rc;
  size_t len;
  LCHAR transcription[MAX_STRING_LEN];

  if (self == NULL)
  {
    PLogError(L("ESR_INVALID_ARGUMENT"));
    return ESR_INVALID_ARGUMENT;
  }
  
  rc = result->getSize(result, &len);
  if (rc != ESR_SUCCESS)
  {
    PLogError(ESR_rc2str(rc));
    goto CLEANUP;
  }
  if (len < 1)
  {
    PLogError(L("ESR_INVALID_ARGUMENT (recognition result nbest-list size=0)"));
    rc = ESR_INVALID_ARGUMENT;
    goto CLEANUP;
  }
  rc = result->getLocale(result, &locale);
  
  len = MAX_STRING_LEN;

  rc = result->getValue(result, 0, L("meaning"), transcription, &len);

  if (rc != ESR_SUCCESS && rc != ESR_BUFFER_OVERFLOW)
  {
    PLogError(ESR_rc2str(rc));
    goto CLEANUP;
  }

#if USE_HMM_BASED_ENROLLMENT /* srec_context.h */
  len = LSTRLEN(transcription)+1;
  rc = SR_NametagCreateFromValue(id, transcription, (int)len, self);
  if(rc ) goto CLEANUP;
#else
  
  if(1) {
    LCHAR short_pron[MAX_STRING_LEN], *short_pron_ptr;
    LCHAR* long_pron = transcription;
    LCHAR* multichar;
    LCHAR* p;
    LCHAR singlechar[2];
    
    *short_pron = 0;
    short_pron_ptr = short_pron;
    len = LSTRLEN(L("ph_"));
    for (multichar = strtok(long_pron, L(" \t\n\r")); multichar; multichar = strtok(NULL, L(" \t\n\r")))
      {
	p = multichar;
	if (LSTRNCMP(p, L("ph_"), len) != 0)
	  {
	    PLogError(L("Expecting 'ph_' prefix, got=%s"), p);
	    rc = ESR_INVALID_STATE;
	    goto CLEANUP;
	  }
	p += len;
	multichar = p;
	while (*p)
	  {
	    if (isdigit(*p))
	      {
		*p = L('\0');
		break;
	      }
	    ++p;
	  }
	if ((rc = SR_Vocabulary_etiinf_conv_from_multichar(locale, multichar, singlechar)) != ESR_SUCCESS)
	  {
	    PLogError(L("Could not convert long to short pron (input=%s, locale=%s)"), multichar, ESR_locale2str(locale));
	    goto CLEANUP;
	  }
	singlechar[1] = 0;
	if((short_pron_ptr - short_pron + 3) >= MAX_STRING_LEN) {
	  PLogError(L("Chopping too long pron in SR_NametagCreate()\n"));
	  break; // just cut if off
	}
	*short_pron_ptr++ = *singlechar;
      }
    *short_pron_ptr++ = 0; // null-term
    *short_pron_ptr++ = 0; // double-null-term!

    /* +2 = +1 for null, +1 for double-null */
    rc = SR_NametagCreateFromValue(id, short_pron, (short_pron_ptr-short_pron), self);
    if(rc ) goto CLEANUP;
  }
#endif

  return ESR_SUCCESS;
CLEANUP:
  return rc;
}
Exemplo n.º 24
0
static ESR_ReturnCode logIt(const LCHAR *format, va_list args, ESR_BOOL showStackTrace)
{
  ESR_ReturnCode rc = ESR_SUCCESS;
  ESR_ReturnCode flushRC = ESR_SUCCESS;
#ifdef USE_STACKTRACE
#define BUFFER_SIZE P_MAX_STACKTRACE + 2000
#else
#define BUFFER_SIZE 2000
#endif
  LCHAR buffer[BUFFER_SIZE] = L("");

  // TODO: Remove once logging subsystem supports "warn" level
  if (strstr(format, "ESR_BUFFER_OVERFLOW")==format)
    return ESR_SUCCESS;
  
#ifdef USE_STACKTRACE
  if (Glogger == NULL)
  {
    /*
     * There are three possible scenerios for why logging would occur although the PLog module
     * is uninitialized:
     *
     * 1) The code fails before PLog is initialized (perhaps in other portable components)
     * 2) The user forgets to initialize the PLog module
     * 3) The code fails after PLog is uninitialized (on shutdown)
     *
     * We do our best by logging any errors but this might result in the memory leak of
     * the PStackTrace module in case 3.
     */
    rc = PStackTraceCreate();
    if (rc != ESR_SUCCESS)
    {
      PLOG_PANIC(L("PStackTraceCreate"), rc);
      goto CLEANUP;
    }
  }
  else
  {
#ifdef USE_THREAD
    rc = PtrdMutexLock(Gmutex);
    if (rc != ESR_SUCCESS)
      return rc;
#endif
  }
  if (locked)
    return ESR_INVALID_STATE;
  locked = ESR_TRUE;
  
  if (GlogFormat & LOG_OUTPUT_FORMAT_DATE_TIME)
  {
    PTimeStamp now;
    struct tm* loctime;
    LCHAR timeStr[TIME_BUF_SIZE];
    size_t timeStrSize;
    
    PTimeStampSet(&now);
    loctime = localtime(&now.secs);
    timeStrSize = LSTRFTIME(timeStr, TIME_BUF_SIZE, TIME_FORMAT, loctime);
    passert(timeStrSize == (TIME_BUF_SIZE - 5));
    psprintf(timeStr + (TIME_BUF_SIZE - 5), ".%03hu", now.msecs);
    
    psprintf(buffer + LSTRLEN(buffer), L("%s|"), timeStr);
    passert(LSTRLEN(buffer) < BUFFER_SIZE);
  }
  
  if (GlogFormat & LOG_OUTPUT_FORMAT_THREAD_ID)
  {
    rc = psprintf(buffer + LSTRLEN(buffer), L("trd=%u|"), PtrdGetCurrentThreadId());
    passert(LSTRLEN(buffer) < BUFFER_SIZE);
  }
  
  if (GlogFormat & LOG_OUTPUT_FORMAT_MODULE_NAME && showStackTrace)
  {
    size_t len = P_MAX_STACKTRACE;
    LCHAR text[P_MAX_STACKTRACE];
    LCHAR* index;
    size_t i;
    
    rc = PStackTraceGetValue((LCHAR*) & text, &len);
    if (rc == ESR_SUCCESS)
    {
      for (i = 0; i < 2; ++i)
      {
        rc = PStackTracePopLevel((LCHAR*) & text);
        if (rc != ESR_SUCCESS)
        {
          PLOG_PANIC(L("PStackTracePopLevel"), rc);
          goto CLEANUP;
        }
      }
      index = text;
      while (index)
      {
        index = LSTRSTR(index, L(" at\n"));
        if (index != NULL)
        {
          *(index + 1) = L('<');
          *(index + 2) = L('-');
          *(index + 3) = L(' ');
        }
      }
    }
    else if (rc == ESR_NOT_SUPPORTED)
      LSTRCPY(text, L(""));
    else if (rc != ESR_SUCCESS)
    {
      PLOG_PANIC(L("PStackTraceGetValue"), rc);
      goto CLEANUP;
    }
    rc = psprintf(buffer + LSTRLEN(buffer), L("Module=%s|"), text);
    passert(LSTRLEN(buffer) < BUFFER_SIZE);
  }
  
  pvsprintf(buffer + LSTRLEN(buffer), format, args);
#else
  pvsprintf(buffer + LSTRLEN(buffer), format, args);
#endif
  passert(LSTRLEN(buffer) < BUFFER_SIZE);
  
  psprintf(buffer + LSTRLEN(buffer), L("\n"));
  passert(LSTRLEN(buffer) < BUFFER_SIZE);
  
  if (Glogger != NULL)
  {
    rc = Glogger->printf(Glogger, L("%s"), buffer);
    if (rc != ESR_SUCCESS)
      goto CLEANUP;
    flushRC = Glogger->flush(Glogger);
  }
  else
  {
    /* We need to log but the logging module is disabled or is locked so we output to stderr instead */
    {
      pfprintf(PSTDERR, L("%s"), buffer);
      pfflush(PSTDERR);
    }
  }
  locked = ESR_FALSE;
#ifdef USE_THREAD
  PtrdMutexUnlock(Gmutex);
#endif
  return flushRC;
CLEANUP:
  if (Glogger != NULL && Glogger->flush != NULL)
    flushRC = Glogger->flush(Glogger);
  locked = ESR_FALSE;
#ifdef USE_THREAD
  PtrdMutexUnlock(Gmutex);
#endif
  return rc != ESR_SUCCESS ? rc : flushRC;
}
Exemplo n.º 25
0
VOID edit_text(LONG tree, WORD sobj)
{
	LONG	obspec, taddr; 
	WORD	min_width, where, type, deftext, w, h, exitobj, ok;
	GRECT	p;
	BYTE	text[73], valid[73], tmplt[73], name[9]; 

	if (rcs_state != ALRT_STATE)
	{
		get_fields(tree, sobj, &type, &obspec, &p);
		taddr = LLGET(obspec);
		if (type == G_FTEXT || type == G_FBOXTEXT)
			if (LSTRLEN(LLGET(TE_PTMPLT(taddr))) > 72)
				return;
		ini_tree(&tree, TEXTDIAL);
		where = set_obname(tree, TEXTNAME, name, ad_view, sobj);
		set_text(tree, OTMPITEM, (LONG)ADDR(&tmplt[0]), 73);
		set_text(tree, OVALITEM, (LONG)ADDR(&valid[0]), 73);
		set_text(tree, OTEXITEM, (LONG)ADDR(&text[0]), 73);
		LLSTRCPY(LLGET(TE_PTMPLT(taddr)), (LONG)ADDR(&tmplt[0]));
		ted_set(taddr, &tmplt[0], &valid[0], &text[0]);

		if (type == G_TEXT || type == G_BOXTEXT)
		{
			if (LSTRLEN(LLGET(TE_PTEXT(taddr))) > 72)
				return;
			hide_obj(tree, TMPLTTAG);
			hide_obj(tree, OTMPITEM);
			hide_obj(tree, VALIDTAG);
			hide_obj(tree, OVALITEM);
			deftext = OTEXITEM;
		}		   
		else
			deftext = (tmplt[0] != '@')? OTMPITEM: OTEXITEM;
		do {
			exitobj = hndl_dial(tree, deftext, &p);
			desel_obj(tree, exitobj);
			ok = DEFAULT & GET_FLAGS(tree, exitobj);
		} while (ok && !name_ok(name, where, TRUE));

		if (ok)
		{
			rcs_edited = TRUE;
			get_obname(name, ad_view, sobj);
			ted_get(taddr, &tmplt[0], &valid[0], &text[0]);
			if (type == G_TEXT || type == G_FTEXT || type == G_BOXTEXT)
			{
				text_wh(taddr, type, &w, &h);
				min_width = GET_WIDTH(ad_view, sobj);
				if ( w > min_width)
					newsize_obj(ad_view, sobj, w, h, TRUE);
			}
		}

		unhide_obj(tree,TMPLTTAG);
		unhide_obj(tree,OTMPITEM);
		unhide_obj(tree, VALIDTAG);
		unhide_obj(tree,OVALITEM);
		map_tree(tree, ROOT, NIL, (fkt_parm)desel_obj);	/* clear radio buttons */
	}
}