Exemplo n.º 1
0
VARIANT CMUSHclientDoc::GetCurrentValue(LPCTSTR OptionName) 
{
	VARIANT vaResult;
	VariantInit(&vaResult);

  vaResult.vt = VT_NULL;    // default if not found

int i = GetOptionIndex (OptionName);

  if (i != -1)
    {
    if (m_CurrentPlugin &&
        (OptionsTable [i].iFlags & OPT_PLUGIN_CANNOT_READ))
    	return vaResult;  // not available to plugin
    SetUpVariantLong (vaResult, GetOptionItem (i));
    }  // end of found
  else
    {
    i = GetAlphaOptionIndex (OptionName);
    if (i != -1)
      {
      if (m_CurrentPlugin &&
          (AlphaOptionsTable [i].iFlags & OPT_PLUGIN_CANNOT_READ))
    	  return vaResult;  // not available to plugin
      SetUpVariantString (vaResult, GetAlphaOptionItem (i));
      }  // end of found
    }

	return vaResult;
}    // end of CMUSHclientDoc::GetCurrentValue
Exemplo n.º 2
0
VARIANT CMUSHclientDoc::SpellCheck(LPCTSTR Text) 
{

const char sFunction [] = "spellcheck_string";

	VARIANT vaResult;
	VariantInit(&vaResult);

  if (!App.m_bSpellCheckOK)
    return vaResult;

set<string> errors;

  if (App.m_SpellChecker_Lua)
    {

    lua_settop(App.m_SpellChecker_Lua, 0);   // clear stack

    lua_getglobal (App.m_SpellChecker_Lua, sFunction);  
    if (!lua_isfunction (App.m_SpellChecker_Lua, -1))
      return vaResult;  // cannot spell check string

    lua_pushstring (App.m_SpellChecker_Lua, Text);  // string to be checked

    int narg = lua_gettop(App.m_SpellChecker_Lua) - 1;  // all but the function
    int error = CallLuaWithTraceBack (App.m_SpellChecker_Lua, narg, 1);
  
    if (error)
      {
      LuaError (App.m_SpellChecker_Lua, "Run-time error", sFunction, "world.SpellCheck", "", this);
      return vaResult;  // cannot spell check string - syntax error
      }  

    if (lua_isnumber (App.m_SpellChecker_Lua, -1))
      {
      SetUpVariantLong (vaResult, lua_tonumber (App.m_SpellChecker_Lua, -1));        // no errors
  	  return vaResult;
      }

    // must be table or else return bad result
    if (!lua_istable (App.m_SpellChecker_Lua, -1))
      return vaResult;  // cannot spell check string - syntax error

    // convert returned table into a set
    for (int i = 1; ; i++)
      {
      lua_rawgeti (App.m_SpellChecker_Lua, 1, i);   // get i'th item
      if (lua_isnil (App.m_SpellChecker_Lua, -1))
        break;    // first nil key, leave loop
      // to avoid crashes, ignore table items that are not strings
      if (lua_isstring (App.m_SpellChecker_Lua, -1))
         errors.insert (lua_tostring (App.m_SpellChecker_Lua, -1));
      lua_pop (App.m_SpellChecker_Lua, 1); // remove value
      } // end of looping through table

    // maybe didn't find any errors?
    if (errors.empty ())
      {
      SetUpVariantLong (vaResult, 0);        // no errors
  	  return vaResult;
      }

    // now make array of the errors
    COleSafeArray sa;   // for wildcard list

    sa.CreateOneDim (VT_VARIANT, errors.size ());

    long iCount = 0;

    for (set<string>::const_iterator it = errors.begin (); 
         it != errors.end (); it++, iCount++)
      {
      // the array must be a bloody array of variants, or VBscript kicks up
      COleVariant v (it->c_str ());
      sa.PutElement (&iCount, &v);
      }      // end of looping through each error

	  return sa.Detach ();
    }   // end custom spell check


return vaResult;

} // end of SpellCheck
Exemplo n.º 3
0
VARIANT CMUSHclientDoc::GetTriggerOption(LPCTSTR TriggerName, LPCTSTR OptionName) 
{
CString strTriggerName = TriggerName;
CTrigger * trigger_item;

	VARIANT vaResult;
	VariantInit(&vaResult);

  vaResult.vt = VT_NULL;

  // trim spaces from name, make lower-case
  CheckObjectName (strTriggerName, false);

  vaResult.vt = VT_EMPTY;

  // see if trigger exists, if not return EMPTY
  if (!GetTriggerMap ().Lookup (strTriggerName, trigger_item))
	  return vaResult;

int iItem;
int iResult = FindBaseOption (OptionName, TriggerOptionsTable, iItem);

  
  if (iResult == eOK)
    {

    // numeric option

    if (m_CurrentPlugin &&
        (TriggerOptionsTable [iItem].iFlags & OPT_PLUGIN_CANNOT_READ))
    	return vaResult;  // not available to plugin

    long Value =  GetBaseOptionItem (iItem, 
                              TriggerOptionsTable, 
                              NUMITEMS (TriggerOptionsTable),
                              (char *) trigger_item);  

    SetUpVariantLong (vaResult, Value);
    }  // end of found numeric option
  else
    { // not numeric option, try alpha
    int iResult = FindBaseAlphaOption (OptionName, TriggerAlphaOptionsTable, iItem);
    if (iResult == eOK)
      {

      // alpha option

      if (m_CurrentPlugin &&
          (TriggerAlphaOptionsTable [iItem].iFlags & OPT_PLUGIN_CANNOT_READ))
    	  return vaResult;  // not available to plugin

      CString strValue =  GetBaseAlphaOptionItem (iItem, 
                                                 TriggerAlphaOptionsTable,
                                                 NUMITEMS (TriggerAlphaOptionsTable),
                                                 (char *) trigger_item);

      SetUpVariantString (vaResult, strValue);
      }  // end of found
    }

	return vaResult;
} // end of GetTriggerOption
Exemplo n.º 4
0
VARIANT CMUSHclientDoc::GetTriggerInfo(LPCTSTR TriggerName, short InfoType) 
{
CString strTriggerName = TriggerName;
CTrigger * trigger_item;

	VARIANT vaResult;
	VariantInit(&vaResult);

  vaResult.vt = VT_NULL;

  // trim spaces from name, make lower-case
  CheckObjectName (strTriggerName, false);

  vaResult.vt = VT_EMPTY;

  // see if trigger exists, if not return EMPTY
  if (!GetTriggerMap ().Lookup (strTriggerName, trigger_item))
	  return vaResult;

  switch (InfoType)
    {
    case   1: SetUpVariantString (vaResult, trigger_item->trigger); break;
    case   2: SetUpVariantString (vaResult, trigger_item->contents); break;
    case   3: SetUpVariantString (vaResult, trigger_item->sound_to_play); break;
    case   4: SetUpVariantString (vaResult, trigger_item->strProcedure); break;
    case   5: SetUpVariantBool   (vaResult, trigger_item->omit_from_log); break;
    case   6: SetUpVariantBool   (vaResult, trigger_item->bOmitFromOutput); break;
    case   7: SetUpVariantBool   (vaResult, trigger_item->bKeepEvaluating); break;
    case   8: SetUpVariantBool   (vaResult, trigger_item->bEnabled); break;
    case   9: SetUpVariantBool   (vaResult, trigger_item->bRegexp); break;
    case  10: SetUpVariantBool   (vaResult, trigger_item->ignore_case); break;
    case  11: SetUpVariantBool   (vaResult, trigger_item->bRepeat); break;
    case  12: SetUpVariantBool   (vaResult, trigger_item->bSoundIfInactive); break;
    case  13: SetUpVariantBool   (vaResult, trigger_item->bExpandVariables); break;
    case  14: SetUpVariantShort  (vaResult, trigger_item->iClipboardArg); break;
    case  15: SetUpVariantShort  (vaResult, trigger_item->iSendTo); break;
    case  16: SetUpVariantShort  (vaResult, trigger_item->iSequence); break;
    case  17: SetUpVariantShort  (vaResult, trigger_item->iMatch); break;
    case  18: SetUpVariantShort  (vaResult, trigger_item->iStyle); break;
    case  19: SetUpVariantShort  (vaResult, trigger_item->colour); break;
    case  20: SetUpVariantLong   (vaResult, trigger_item->nInvocationCount); break;
    case  21: SetUpVariantLong   (vaResult, trigger_item->nMatched); break;
    case  22: 
      if (trigger_item->tWhenMatched.GetTime ())     // only if non-zero, otherwise return empty
        SetUpVariantDate   (vaResult, COleDateTime (trigger_item->tWhenMatched.GetTime ())); 
      break;
    case  23: SetUpVariantBool   (vaResult, trigger_item->bTemporary); break;
    case  24: SetUpVariantBool   (vaResult, trigger_item->bIncluded); break;
    case  25: SetUpVariantBool   (vaResult, trigger_item->bLowercaseWildcard); break;
    case  26: SetUpVariantString (vaResult, trigger_item->strGroup); break;
    case  27: SetUpVariantString (vaResult, trigger_item->strVariable); break;
    case  28: SetUpVariantLong   (vaResult, trigger_item->iUserOption); break;
    case  29: SetUpVariantLong   (vaResult, trigger_item->iOtherForeground); break;
    case  30: SetUpVariantLong   (vaResult, trigger_item->iOtherBackground); break;
    case  31: // number of matches to regexp
      if (trigger_item->regexp)      
        SetUpVariantLong   (vaResult, trigger_item->regexp->m_iCount);
      else
        SetUpVariantLong   (vaResult, 0);
      break;

    case  32: // last matching string
      if (trigger_item->regexp)      
        SetUpVariantString   (vaResult, trigger_item->regexp->m_sTarget.c_str ());
      else
        SetUpVariantString   (vaResult, "");
      break;
    case  33: SetUpVariantBool   (vaResult, trigger_item->bExecutingScript); break;
    case  34: SetUpVariantBool   (vaResult, trigger_item->dispid != DISPID_UNKNOWN); break;
    case  35: 
      if (trigger_item->regexp && trigger_item->regexp->m_program == NULL)      
        SetUpVariantLong   (vaResult, trigger_item->regexp->m_iExecutionError);
      else
        SetUpVariantLong   (vaResult, 0);
      break;
    case   36: SetUpVariantBool   (vaResult, trigger_item->bOneShot); break;

    case  37:
      if (trigger_item->regexp && App.m_iCounterFrequency)
        {
        double   elapsed_time;

        elapsed_time = ((double) trigger_item->regexp->iTimeTaken) / 
                       ((double) App.m_iCounterFrequency);

        SetUpVariantDouble (vaResult, elapsed_time);
        }
      break;

    case  38:
      if (trigger_item->regexp)
        SetUpVariantLong   (vaResult, trigger_item->regexp->m_iMatchAttempts);
      break;

#ifdef PANE
    case  38: SetUpVariantString (vaResult, trigger_item->strPane); break;
#endif // PANE

    case 101: SetUpVariantString (vaResult, trigger_item->wildcards [1].c_str ()); break;
    case 102: SetUpVariantString (vaResult, trigger_item->wildcards [2].c_str ()); break;
    case 103: SetUpVariantString (vaResult, trigger_item->wildcards [3].c_str ()); break;
    case 104: SetUpVariantString (vaResult, trigger_item->wildcards [4].c_str ()); break;
    case 105: SetUpVariantString (vaResult, trigger_item->wildcards [5].c_str ()); break;
    case 106: SetUpVariantString (vaResult, trigger_item->wildcards [6].c_str ()); break;
    case 107: SetUpVariantString (vaResult, trigger_item->wildcards [7].c_str ()); break;
    case 108: SetUpVariantString (vaResult, trigger_item->wildcards [8].c_str ()); break;
    case 109: SetUpVariantString (vaResult, trigger_item->wildcards [9].c_str ()); break;
    case 110: SetUpVariantString (vaResult, trigger_item->wildcards [0].c_str ()); break;
    
    default:
      vaResult.vt = VT_NULL;
      break;

    } // end of switch

  return vaResult;
}   // end of CMUSHclientDoc::GetTriggerInfo
Exemplo n.º 5
0
VARIANT CMUSHclientDoc::GetPluginInfo(LPCTSTR PluginID, short InfoType) 
{
	VARIANT vaResult;
	VariantInit(&vaResult);

  vaResult.vt = VT_NULL;

  CPlugin * pPlugin = GetPlugin (PluginID);

  if (!pPlugin)
	  return vaResult;     // plugin not found

  switch (InfoType)
    {
    case   1: SetUpVariantString (vaResult, pPlugin->m_strName); break;
    case   2: SetUpVariantString (vaResult, pPlugin->m_strAuthor); break;
    case   3: SetUpVariantString (vaResult, pPlugin->m_strDescription); break;
    case   4: SetUpVariantString (vaResult, pPlugin->m_strScript); break;
    case   5: SetUpVariantString (vaResult, pPlugin->m_strLanguage); break;
    case   6: SetUpVariantString (vaResult, pPlugin->m_strSource); break;
    case   7: SetUpVariantString (vaResult, pPlugin->m_strID); break;
    case   8: SetUpVariantString (vaResult, pPlugin->m_strPurpose); break;
    case   9: SetUpVariantLong   (vaResult, pPlugin->m_TriggerMap.GetCount ()); break;
    case  10: SetUpVariantLong   (vaResult, pPlugin->m_AliasMap.GetCount ()); break;
    case  11: SetUpVariantLong   (vaResult, pPlugin->m_TimerMap.GetCount ()); break;
    case  12: SetUpVariantLong   (vaResult, pPlugin->m_VariableMap.GetCount ()); break;
    case  13: 
      if (pPlugin->m_tDateWritten.GetTime ())     // only if non-zero, otherwise return empty
        SetUpVariantDate   (vaResult, COleDateTime (pPlugin->m_tDateWritten.GetTime ())); 
      break;
    case  14: 
      if (pPlugin->m_tDateModified.GetTime ())     // only if non-zero, otherwise return empty
        SetUpVariantDate   (vaResult,  COleDateTime (pPlugin->m_tDateModified.GetTime ())); 
      break;
    case 15: SetUpVariantBool (vaResult, pPlugin->m_bSaveState); break;
        // 16: is scripting enabled?
    case 16: SetUpVariantBool (vaResult, pPlugin->m_ScriptEngine != NULL); break;
    case 17: SetUpVariantBool (vaResult, pPlugin->m_bEnabled); break;
    case 18: SetUpVariantDouble (vaResult, pPlugin->m_dRequiredVersion); break;
    case 19: SetUpVariantDouble (vaResult, pPlugin->m_dVersion); break;
    case 20: SetUpVariantString (vaResult, pPlugin->m_strDirectory); break;
    case 21:
      {
      int iCount = 0;

      // first work out what order each plugin is in *now*
      for (PluginListIterator pit = m_PluginList.begin (); 
           pit != m_PluginList.end (); 
           ++pit)
        (*pit)->m_iLoadOrder = ++iCount;

      // now return the order of *this* one
      SetUpVariantLong   (vaResult, pPlugin->m_iLoadOrder); 
      }
      break;

    case  22: SetUpVariantDate   (vaResult, COleDateTime (pPlugin->m_tDateInstalled.GetTime ()));  break;
    case  23: SetUpVariantString (vaResult, pPlugin->m_strCallingPluginID); break;

    case  24:
      {
      double elapsed_time = 0.0;
      if (App.m_iCounterFrequency > 0)
        elapsed_time = ((double) pPlugin->m_iScriptTimeTaken) / 
                       ((double) App.m_iCounterFrequency);

      SetUpVariantDouble (vaResult, elapsed_time); 
      break;
      }

    default:
      vaResult.vt = VT_NULL;
      break;

    } // end of switch

  return vaResult;
}   // end of CMUSHclientDoc::GetPluginInfo
Exemplo n.º 6
0
VARIANT CMUSHclientDoc::GetTimerInfo(LPCTSTR TimerName, short InfoType)
{
    CString strTimerName = TimerName;
    CTimer * timer_item;

    VARIANT vaResult;
    VariantInit(&vaResult);

    vaResult.vt = VT_NULL;

    // trim spaces from name, make lower-case
    CheckObjectName (strTimerName, false);

    vaResult.vt = VT_EMPTY;

    // see if timer exists, if not return EMPTY
    if (!GetTimerMap ().Lookup (strTimerName, timer_item))
        return vaResult;

    switch (InfoType)
    {
    case   1:
        if (timer_item->iType == CTimer::eAtTime)
            SetUpVariantShort  (vaResult, timer_item->iAtHour);
        else
            SetUpVariantShort  (vaResult, timer_item->iEveryHour);
        break;
    case   2:
        if (timer_item->iType == CTimer::eAtTime)
            SetUpVariantShort  (vaResult, timer_item->iAtMinute);
        else
            SetUpVariantShort  (vaResult, timer_item->iEveryMinute);
        break;
    case   3:
        if (timer_item->iType == CTimer::eAtTime)
            SetUpVariantDouble  (vaResult, timer_item->fAtSecond);
        else
            SetUpVariantDouble  (vaResult, timer_item->fEverySecond);
        break;
    case   4:
        SetUpVariantString (vaResult, timer_item->strContents);
        break;
    case   5:
        SetUpVariantString (vaResult, timer_item->strProcedure);
        break;
    case   6:
        SetUpVariantBool   (vaResult, timer_item->bEnabled);
        break;
    case   7:
        SetUpVariantBool   (vaResult, timer_item->bOneShot);
        break;
    case   8:
        SetUpVariantBool   (vaResult, timer_item->iType == CTimer::eAtTime);
        break;
    case   9:
        SetUpVariantLong   (vaResult, timer_item->nInvocationCount);
        break;
    case  10:
        SetUpVariantLong   (vaResult, timer_item->nMatched);
        break;
    case  11:
        if (timer_item->tWhenFired.GetTime ())     // only if non-zero, otherwise return empty
            SetUpVariantDate   (vaResult, COleDateTime (timer_item->tWhenFired.GetTime ()));
        break;
    case  12:
        if (timer_item->tFireTime.GetTime ())     // only if non-zero, otherwise return empty
            SetUpVariantDate   (vaResult, COleDateTime (timer_item->tFireTime.GetTime ()));
        break;
    case  13:
    {
        CmcDateTime tDue = CmcDateTime (timer_item->tFireTime.GetTime ());
        CmcDateTime tNow = CmcDateTime::GetTimeNow ();
        if (tDue < tNow)
            SetUpVariantDouble   (vaResult, 0);  // due immediately
        else
        {
            CmcDateTimeSpan ts = tDue - tNow;
            SetUpVariantDouble   (vaResult, ts.GetTotalSeconds ());  // how many seconds to go
        }
    }
    break;
    case  14:
        SetUpVariantBool   (vaResult, timer_item->bTemporary);
        break;
    case  15:
        SetUpVariantBool   (vaResult, timer_item->iSendTo == eSendToSpeedwalk);
        break;
    case  16:
        SetUpVariantBool   (vaResult, timer_item->iSendTo == eSendToOutput);
        break;
    case  17:
        SetUpVariantBool   (vaResult, timer_item->bActiveWhenClosed);
        break;
    case  18:
        SetUpVariantBool   (vaResult, timer_item->bIncluded);
        break;
    case  19:
        SetUpVariantString (vaResult, timer_item->strGroup);
        break;
    case  20:
        SetUpVariantLong   (vaResult, timer_item->iSendTo);
        break;
    case  21:
        SetUpVariantLong   (vaResult, timer_item->iUserOption);
        break;
    case  22:
        SetUpVariantString (vaResult, timer_item->strLabel);
        break;
    case  23:
        SetUpVariantBool   (vaResult, timer_item->bOmitFromOutput);
        break;
    case  24:
        SetUpVariantBool   (vaResult, timer_item->bOmitFromLog);
        break;
    case  25:
        SetUpVariantBool   (vaResult, timer_item->bExecutingScript);
        break;
    case  26:
        SetUpVariantBool   (vaResult, timer_item->dispid != DISPID_UNKNOWN);
        break;

    default:
        vaResult.vt = VT_NULL;
        break;

    } // end of switch

    return vaResult;
}     // end of CMUSHclientDoc::GetTimerInfo