Beispiel #1
0
bool UnaryOpExpression::getScalarValue(Variant &value) {
  if (m_exp) {
    if (m_op == T_ARRAY) {
      return m_exp->getScalarValue(value);
    }
    if (m_op == T_DICT) {
      if (m_exp->getScalarValue(value)) {
        value = Array::ConvertToDict(value.toArray());
        return true;
      }
      return false;
    }
    Variant t;
    return m_exp->getScalarValue(t) &&
      preCompute(t, value);
  }

  if (m_op == T_DICT) {
    value = DictInit(0).toArray();
    return true;
  }

  if (m_op != T_ARRAY) return false;
  value = Array::Create();
  return true;
}
Beispiel #2
0
Err AppPerformResidentLookup(char* term)
{
    Err             error;
    AppContext*     appContext=(AppContext*)MemPtrNew(sizeof(AppContext));
    AbstractFile *  chosenDb;

    if (!appContext)
    {
        error=memErrNotEnoughSpace;
        goto OnError;
    }
    error=AppCommonInit(appContext);
    RemoveNonexistingDatabases(appContext);
    ScanForDictsNoahPro(appContext, false);
    if (0 == appContext->dictsCount)
    {
        FrmAlert(alertNoDB);
        goto Exit;
    }
    else

    if (1 == appContext->dictsCount )
        chosenDb = appContext->dicts[0];
    else 
    {
        // because we can't start resident mode without previously gracefully exiting at least one time
        Assert(appContext->prefs.lastDbUsedName); 
        chosenDb=FindOpenDatabase(appContext, appContext->prefs.lastDbUsedName);
    }            

    if (!chosenDb || !DictInit(appContext, chosenDb))
    {
        FrmAlert(alertDbFailed);
        goto Exit;
    }

    if (term)
    {
        appContext->currentWord=dictGetFirstMatching(chosenDb, term);
        error=PopupResidentLookupForm(appContext);
    }
    else
    {
        appContext->currentWord=-1;
        error=PopupResidentBrowseForm(appContext);
        if (!error && appContext->currentWord!=-1)
            error=PopupResidentLookupForm(appContext);
    }
Exit:
    AppCommonFree(appContext);
OnError:
    if (appContext)
        MemPtrFree(appContext);
    return error;
}
Beispiel #3
0
Dict *DictCopy(Dict *in, int deep)
 {
  int hash;
  DictItem *item, *outitem;
  Dict     *out;
  out  = DictInit(in->HashSize);
  if (out==NULL) return NULL;
  item = in->first;
  while (item != NULL)
   {
    outitem           = (DictItem *)lt_malloc_incontext(sizeof(DictItem), out->memory_context);
    if (outitem==NULL) return NULL;
    outitem->prev     = out->last;
    outitem->next     = NULL;
    outitem->key      = (char *)lt_malloc_incontext((strlen(item->key)+1)*sizeof(char), out->memory_context);
    if (outitem->key==NULL) return NULL;
    strcpy(outitem->key, item->key);
    outitem->DataSize = item->DataSize;
    if (item->copyable != 0)
     {
      outitem->data     = (void *)lt_malloc_incontext(outitem->DataSize, out->memory_context);
      if (outitem->data==NULL) return NULL;
      memcpy(outitem->data, item->data, outitem->DataSize);
      outitem->MallocedByUs = 1;
     } else {
      if      ((deep!=0)&&(item->DataType == DATATYPE_LIST)) outitem->data = ListCopy((List *)item->data,1);
      else if ((deep!=0)&&(item->DataType == DATATYPE_DICT)) outitem->data = DictCopy((Dict *)item->data,1);
      else                                                   outitem->data =                  item->data   ;
      outitem->MallocedByUs = 0;
     }
    outitem->copyable = item->copyable;
    outitem->DataType = item->DataType;
    if (out->first == NULL) out->first      = outitem;
    if (out->last  != NULL) out->last->next = outitem;
    out->last = outitem;
    out->length++;
    hash = DictHash(item->key, in->HashSize);
    out->HashTable[hash] = outitem;
    item = item->next;
   }
  return out;
 }