예제 #1
0
bool Settings::getS32NoEx(const std::string &name, s32 &val) const
{
	try {
		val = getS32(name);
		return true;
	} catch (SettingNotFoundException &e) {
		return false;
	}
}
예제 #2
0
// Respond to an Invoke button press
static void onInvokeBtn(HWND win) {
	int idx = ListBox_GetCurSel(GetDlgItem(win, IDC_FUNCTION_LST));
	int id;
	int i;
	char str[256];
	char path[MAX_PATH];
	SSCE_S16 s16, s16_1, s16_2, s16_3;
	SSCE_S32 s32, s32_1, s32_2, s32_3, s32_4;
	SSCE_CHAR word[SSCE_MAX_WORD_SZ];
	SSCE_CHAR otherWord[SSCE_MAX_WORD_SZ];
	SSCE_CHAR *bfr;
	SSCE_CHAR *p;
	const char *fmt, *lang;
	SSCE_S16 scores[16];

	if (LB_ERR == idx) {
		return;
	}

	id = (int)ListBox_GetItemData(GetDlgItem(win, IDC_FUNCTION_LST), idx);

	// Invoke the selected function.
	switch (id) {
	case AddToLex:
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		GetDlgItemText(win, IDC_PARAM3_EDT, otherWord, sizeof(otherWord));
		s16 = SSCE_AddToLex(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT), word,
		  getS16(win, IDC_PARAM2_EDT), otherWord);
		displayResult(win, "SSCE_AddToLex", s16);
		break;
	case CheckBlock:
		s16 = SSCE_CheckBlock(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), word, sizeof(word),
		  otherWord, sizeof(otherWord));
		displayCheckResult(win, "SSCE_CheckBlock", s16);
		if (s16 >= 0) {
			wsprintf(str, "errWord: %s; otherWord: %s", word, otherWord);
		}
		appendMsg(win, str);
		break;
	case CheckBlockDlg:
		s32_1 = getS32(win, IDC_PARAM1_EDT);
		bfr = (SSCE_CHAR *)malloc((size_t)s32_1);
		GetDlgItemText(win, IDC_TEXT_EDT, bfr, (int)s32_1);
		s32 = SSCE_CheckBlockDlg(win, bfr, strlen(bfr), s32_1,
		  getS16(win, IDC_PARAM2_EDT));
		wsprintf(str, "SSCE_CheckBlockDlg returned %ld", s32);
		appendMsg(win, str);
		if (s32 >= 0) {
			SetDlgItemText(win, IDC_TEXT_EDT, bfr);
		}
		free(bfr);
		break;
	case CheckCtrlDlg:
		s16 = SSCE_CheckCtrlDlg(win, GetDlgItem(win, IDC_TEXT_EDT),
		  getS16(win, IDC_PARAM1_EDT));
		displayResult(win, "SSCE_CheckCtrlDlg", s16);
		break;
	case CheckWord:
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		s16 = SSCE_CheckWord(getS16(win, IDC_SESSION_ID_EDT),
		  word, otherWord, sizeof(otherWord));
		displayCheckResult(win, "SSCE_CheckWord", s16);
		if (s16 >= 0) {
			wsprintf(str, "otherWord: %s", otherWord);
		}
		appendMsg(win, str);
		break;
	case ClearLex:
		s16 = SSCE_ClearLex(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT));
		displayResult(win, "SSCE_ClearLex", s16);
		break;
	case CloseBlock:
		s16 = SSCE_CloseBlock(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT));
		displayResult(win, "SSCE_CloseBlock", s16);
		break;
	case CloseLex:
		s16 = SSCE_CloseLex(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT));
		displayResult(win, "SSCE_CloseLex", s16);
		break;
	case CloseSession:
		s16 = SSCE_CloseSession(getS16(win, IDC_SESSION_ID_EDT));
		displayResult(win, "SSCE_CloseSession", s16);
		break;
	case CreateLex:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_CreateLex(getS16(win, IDC_SESSION_ID_EDT),
		  path, getS16(win, IDC_PARAM2_EDT));
		if (s16 >= 0) {
			wsprintf(str, "%hd", s16);
			SetDlgItemText(win, IDC_LEXICON_ID_EDT, str);
		}
		wsprintf(str, "SSCE_CreateLex(%s) returned %hd", path, s16);
		appendMsg(win, str);
		break;
	case DelBlockText:
		s16 = SSCE_DelBlockText(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), getS32(win, IDC_PARAM1_EDT));
		displayResult(win, "SSCE_DelBlockText", s16);
		break;
	case DelBlockWord:
		s32 = SSCE_DelBlockWord(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), word, sizeof(word));
		wsprintf(str, "SSCE_DelBlockWord returned %ld; deleted text = %s",
		  s32, word);
		appendMsg(win, str);
		break;
	case DelFromLex:
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		s16 = SSCE_DelFromLex(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT), word);
		displayResult(win, "SSCE_DelFromLex", s16);
		break;
	case EditLexDlg:
		s16 = SSCE_EditLexDlg(win);
		displayResult(win, "SSCE_EditLexDlg", s16);
		break;
	case FindLexWord:
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		s16 = SSCE_FindLexWord(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT), word, otherWord, sizeof(otherWord));
		if (s16 < 0) {
			displayResult(win, "SSCE_FindLexWord", s16);
		}
		else {
			int i;
			const char *actionName = "(unknown)";

			for (i = 0; i < sizeof(actions) / sizeof(actions[0]); ++i) {
				if (actions[i].action == s16) {
					actionName = actions[i].name;
					break;
				}
			}
			wsprintf(str, "SSCE_FindLexWord returned %s", actionName);
			appendMsg(win, str);
			if (otherWord[0] != '\0') {
				wsprintf(str, "otherWord: %s", otherWord);
				appendMsg(win, str);
			}
		}
		break;
	case GetAutoCorrect:
		s16 = SSCE_GetAutoCorrect();
		displayResult(win, "SSCE_GetAutoCorrect", s16);
		break;
	case GetBlock:
		s16 = SSCE_GetBlockInfo(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), &s32_1, NULL, NULL, NULL);
		if (s16 < 0) {
			displayResult(win, "SSCE_GetBlockInfo", s16);
			break;
		}
		bfr = (SSCE_CHAR *)malloc((size_t)s32_1 + 1);
		if (NULL == bfr) {
			appendMsg(win, "Out of memory");
			break;
		}
		s16 = (SSCE_S16)SSCE_GetBlock(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), bfr, s32_1 + 1);
		bfr[s32_1] = '\0';
		displayResult(win, "SSCE_GetBlock", s16);
		appendMsg(win, "Block contents:");
		appendMsg(win, bfr);
		free(bfr);
		break;
	case GetBlockInfo:
		s16 = SSCE_GetBlockInfo(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), &s32_1, &s32_2, &s32_3, &s32_4);
		displayResult(win, "SSCE_GetBlockInfo", s16);
		wsprintf(str,
		  "textLen = %ld; blkSz = %ld; curPos = %ld; wordCount = %ld",
		  s32_1, s32_2, s32_3, s32_4);
		appendMsg(win, str);
		break;
	case GetBlockWord:
		s16 = SSCE_GetBlockWord(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), word, sizeof(word));
		displayResult(win, "SSCE_GetBlockWord", s16);
		wsprintf(str, "word: %s", word);
		appendMsg(win, str);
		break;
	case GetHelpFile:
		SSCE_GetHelpFile(path, sizeof(path));
		wsprintf(str, "help file: %s", path);
		appendMsg(win, str);
		break;
	case GetLex:
		s16 = SSCE_GetLexInfo(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT), &s32_1, NULL, NULL);
		if (s16 < 0) {
			displayResult(win, "SSCE_GetLexInfo", s16);
			break;
		}
		bfr = (SSCE_CHAR *)malloc((size_t)s32_1);
		if (NULL == bfr) {
			appendMsg(win, "Out of memory");
			break;
		}
		s32 = SSCE_GetLex(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT), bfr, s32_1);
		wsprintf(str, "SSCE_GetLex returned %ld", s32);
		appendMsg(win, str);
		for (p = bfr; *p != '\0'; p += strlen(p) + 1) {
			appendMsg(win, p);
		}
		free(bfr);
		break;
	case GetLexId:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_GetLexId(path);
		displayResult(win, "SSCE_GetLexId", s16);
		break;
	case GetLexInfo:
		s16 = SSCE_GetLexInfo(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_LEXICON_ID_EDT), &s32_1, &s16_2, &s16_3);
		displayResult(win, "SSCE_GetLexInfo", s16);
		fmt = "(unknown)";
		for (i = 0; i < sizeof(lexFormats) / sizeof(lexFormats[0]); ++i) {
			if (lexFormats[i].format == s16_2) {
				fmt = lexFormats[i].name;
				break;
			}
		}
		lang = "(unknown)";
		for (i = 0; i < sizeof(languages) / sizeof(languages[0]); ++i) {
			if (languages[i].lang == s16_3) {
				lang = languages[i].name;
				break;
			}
		}
		wsprintf(str, "size = %ld; format = %s; language = %s", s32_1,
		  fmt, lang);
		appendMsg(win, str);
		break;
	case GetMainLexFiles:
		SSCE_GetMainLexFiles(path, sizeof(path));
		wsprintf(str, "MainLexFiles: %s", path);
		appendMsg(win, str);
		break;
	case GetMainLexPath:
		SSCE_GetMainLexPath(path, sizeof(path));
		wsprintf(str, "MainLexPath: %s", path);
		appendMsg(win, str);
		break;
	case GetMinSuggestDepth:
		s16 = SSCE_GetMinSuggestDepth();
		displayResult(win, "SSCE_GetMinSuggestDepth", s16);
		break;
	case GetOption:
		s32 = (SSCE_S32)SSCE_GetOption(getS16(win, IDC_SESSION_ID_EDT),
		  (SSCE_U32)getS32(win, IDC_PARAM1_EDT));
		if (s32 < 0) {
			displayResult(win, "SSCE_GetOption", (SSCE_S16)s32);
		}
		else {
			wsprintf(str, "SSCE_GetOption returned %ld", s32);
			appendMsg(win, str);
		}
		break;
	case GetRegTreeName:
		SSCE_GetRegTreeName(path, sizeof(path));
		wsprintf(str, "RegTreeName: %s", path);
		appendMsg(win, str);
		break;
	case GetSid:
		s16 = SSCE_GetSid();
		displayResult(win, "SSCE_GetSid", s16);
		if (s16 >= 0) {
			wsprintf(str, "%hd", s16);
			SetDlgItemText(win, IDC_SESSION_ID_EDT, str);
		}
		break;
	case GetStatistics:
		SSCE_GetStatistics((SSCE_U32 *)&s32_1, (SSCE_U32 *)&s32_2,
		  (SSCE_U32 *)&s32_3);
		wsprintf(str,
		  "wordsChecked = %lu; wordsChanged = %lu; errorsDetected = %lu",
		  s32_1, s32_2, s32_3);
		appendMsg(win, str);
		break;
	case GetStringTableName:
		SSCE_GetStringTableName(path, sizeof(path));
		wsprintf(str, "StringTableName: %s", path);
		appendMsg(win, str);
		break;
	case GetUserLexFiles:
		SSCE_GetUserLexFiles(path, sizeof(path));
		wsprintf(str, "UserLexFiles: %s", path);
		appendMsg(win, str);
		break;
	case GetUserLexPath:
		SSCE_GetUserLexPath(path, sizeof(path));
		wsprintf(str, "UserLexPath: %s", path);
		appendMsg(win, str);
		break;
	case InsertBlockText:
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		s16 = SSCE_InsertBlockText(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), word);
		displayResult(win, "SSCE_InsertBlockText", s16);
		break;
	case NextBlockWord:
		s16 = SSCE_NextBlockWord(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT));
		displayResult(win, "SSCE_NextBlockWord", s16);
		break;
	case OpenBlock:
		s32_1 = getS32(win, IDC_PARAM1_EDT);
		bfr = (SSCE_CHAR *)malloc((size_t)s32_1);
		if (NULL == bfr) {
			appendMsg(win, "Out of memory");
			break;
		}
		GetDlgItemText(win, IDC_TEXT_EDT, bfr, (int)s32_1);
		s16 = SSCE_OpenBlock(getS16(win, IDC_SESSION_ID_EDT),
		  bfr, strlen(bfr), s32_1, TRUE);
		if (s16 >= 0) {
			wsprintf(str, "%hd", s16);
			SetDlgItemText(win, IDC_BLOCK_ID_EDT, str);
		}
		displayResult(win, "SSCE_OpenBlock", s16);
		free(bfr);
		break;
	case OpenLex:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_OpenLex(getS16(win, IDC_SESSION_ID_EDT),
		  path, getS32(win, IDC_PARAM2_EDT));
		if (s16 >= 0) {
			wsprintf(str, "%hd", s16);
			SetDlgItemText(win, IDC_LEXICON_ID_EDT, str);
		}
		wsprintf(str, "SSCE_OpenLex(%s) returned %hd", path, s16);
		appendMsg(win, str);
		break;
	case OpenSession:
		s16 = SSCE_OpenSession();
		if (s16 >= 0) {
			wsprintf(str, "%hd", s16);
			SetDlgItemText(win, IDC_SESSION_ID_EDT, str);
		}
		displayResult(win, "SSCE_OpenSession", s16);
		break;
	case OptionsDlg:
		s16 = SSCE_OptionsDlg(win);
		displayResult(win, "SSCE_OptionsDlg", s16);
		break;
	case ReplaceBlockWord:
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		s16 = SSCE_ReplaceBlockWord(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), word);
		displayResult(win, "SSCE_ReplaceBlockWord", s16);
		break;
	case ResetLex:
		s16 = SSCE_ResetLex();
		displayResult(win, "SSCE_ResetLex", s16);
		break;
	case SetAutoCorrect:
		s16 = SSCE_SetAutoCorrect(getS16(win, IDC_PARAM1_EDT));
		displayResult(win, "SSCE_SetAutoCorrect", s16);
		break;
	case SetBlockCursor:
		s16 = SSCE_SetBlockCursor(getS16(win, IDC_SESSION_ID_EDT),
		  getS16(win, IDC_BLOCK_ID_EDT), getS32(win, IDC_PARAM1_EDT));
		displayResult(win, "SSCE_SetBlockCursor", s16);
		break;
	case SetDebugFile:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		SSCE_SetDebugFile(path);
		wsprintf(str, "Diagnostic file set to %s", path);
		break;
	case SetDialogOrigin:
		SSCE_SetDialogOrigin(getS16(win, IDC_PARAM1_EDT),
		  getS16(win, IDC_PARAM2_EDT));
		appendMsg(win, "Dialog origin set");
		break;
	case SetHelpFile:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetHelpFile(path);
		displayResult(win, "SSCE_SetHelpFile", s16);
		break;
	case SetIniFile:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetIniFile(path);
		displayResult(win, "SSCE_SetIniFile", s16);
		break;
	case SetKey:
		s32 = SSCE_SetKey(getU32(win, IDC_PARAM1_EDT));
		wsprintf(str, "SSCE_SetKey returned %ld", s32);
		appendMsg(win, str);
		break;
	case SetMainLexFiles:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetMainLexFiles(path);
		displayResult(win, "SSCE_SetMainLexFiles", s16);
		break;
	case SetMainLexPath:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetMainLexPath(path);
		displayResult(win, "SSCE_SetMainLexPath", s16);
		break;
	case SetMinSuggestDepth:
		s16 = SSCE_SetMinSuggestDepth(getS16(win, IDC_PARAM1_EDT));
		displayResult(win, "SSCE_SetMinSuggestDepth", s16);
		break;
	case SetOption:
		s32 = (SSCE_S32)SSCE_SetOption(getS16(win, IDC_SESSION_ID_EDT),
		  (SSCE_U32)getS32(win, IDC_PARAM1_EDT),
		  (SSCE_U32)getS32(win, IDC_PARAM2_EDT));
		wsprintf(str, "SSCE_SetOption returned %ld", s32);
		appendMsg(win, str);
		break;
	case SetRegTreeName:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetRegTreeName(path);
		displayResult(win, "SSCE_SetRegTreeName", s16);
		break;
	case SetStringTableName:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetStringTableName(path);
		displayResult(win, "SSCE_SetStringTableName", s16);
		break;
	case SetUserLexFiles:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetUserLexFiles(path);
		displayResult(win, "SSCE_SetUserLexFiles", s16);
		break;
	case SetUserLexPath:
		GetDlgItemText(win, IDC_PARAM1_EDT, path, sizeof(path));
		s16 = SSCE_SetUserLexPath(path);
		displayResult(win, "SSCE_SetUserLexPath", s16);
		break;
	case Suggest:
		s16_1 = SSCE_MAX_WORD_SZ * 16;
		bfr = (SSCE_CHAR *)malloc((size_t)s16_1);
		if (NULL == bfr) {
			appendMsg(win, "Out of memory");
			break;
		}
		GetDlgItemText(win, IDC_PARAM1_EDT, word, sizeof(word));
		s16 = SSCE_Suggest(getS16(win, IDC_SESSION_ID_EDT),
		  word, getS16(win, IDC_PARAM2_EDT), bfr, (SSCE_S32)s16_1,
		  scores, sizeof(scores) / sizeof(scores[0]));
		displayResult(win, "SSCE_Suggest", s16);
		if (s16 >= 0) {
			for (p = bfr, i = 0; *p != '\0'; p += strlen(p) + 1, ++i) {
				wsprintf(str, "%s [%hd]", p, scores[i]);
				appendMsg(win, str);
			}
		}
		free(bfr);
		break;
	case Version:
		SSCE_Version(word, sizeof(word));
		wsprintf(str, "Version: %s", word);
		appendMsg(win, str);
		break;
	}
}