diff options
author | George Hazan <ghazan@miranda.im> | 2018-02-16 22:07:43 +0200 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-02-16 22:08:26 +0200 |
commit | 8d127430d057891fbd3ac5989d32090715d7923a (patch) | |
tree | 2c02b3401ca7a583302730161c3e11ec9607c1f4 /plugins/MimCmd | |
parent | 9cde0c92420f4811a646964c1304f7c55f8a50a5 (diff) |
fixes #1143 (CmdLine Plugin error when using Diacritics in message)
Diffstat (limited to 'plugins/MimCmd')
-rw-r--r-- | plugins/MimCmd/src/MimCmd.cpp | 55 | ||||
-rw-r--r-- | plugins/MimCmd/src/commands.cpp | 57 | ||||
-rw-r--r-- | plugins/MimCmd/src/commands.h | 6 | ||||
-rw-r--r-- | plugins/MimCmd/src/stdafx.h | 2 | ||||
-rw-r--r-- | plugins/MimCmd/src/version.h | 4 |
5 files changed, 53 insertions, 71 deletions
diff --git a/plugins/MimCmd/src/MimCmd.cpp b/plugins/MimCmd/src/MimCmd.cpp index 14f8667b0c..fea2335465 100644 --- a/plugins/MimCmd/src/MimCmd.cpp +++ b/plugins/MimCmd/src/MimCmd.cpp @@ -22,62 +22,47 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. int hLangpack = 0;
-int lpprintf(const char *format, ...)
+wchar_t* GetProgramName(wchar_t *programName, size_t size)
{
- va_list va;
- va_start(va, format);
- const int MAX_SIZE = 16192;
- char buffer[MAX_SIZE] = { 0 };
- int len = _vsnprintf(buffer, MAX_SIZE, format, va);
- va_end(va);
- std::wcout << (wchar_t*)_A2T(buffer);
- return len;
-}
-
-char* GetProgramName(char *programName, int size)
-{
- char name[512];
- GetModuleFileNameA(GetModuleHandle(nullptr), name, sizeof(name));
- char *p = strrchr(name, '\\');
+ wchar_t name[512];
+ GetModuleFileNameW(GetModuleHandleW(nullptr), name, _countof(name));
+ wchar_t *p = wcsrchr(name, '\\');
if (p)
- strncpy_s(programName, size, p + 1, _TRUNCATE);
+ wcsncpy_s(programName, size, p + 1, _TRUNCATE);
else
- strncpy_s(programName, size, name, _TRUNCATE);
+ wcsncpy_s(programName, size, name, _TRUNCATE);
return programName;
}
void PrintUsage()
{
- char name[128];
- GetProgramName(name, sizeof(name));
+ wchar_t name[128];
+ GetProgramName(name, _countof(name));
- lpprintf(Translate("%s usage:\n"), name);
- lpprintf(Translate("%s <command> [<param> [<param> [...]]].\n"), name);
- lpprintf(Translate("This will tell Miranda to run the specified command. The commands can have zero, one or more parameters. Use '%s help' to get a list of possible commands.\n"), name);
- lpprintf(Translate("No command can have more than %d parameters.\n"), MAX_ARGUMENTS - 1);
+ wprintf(TranslateT("%s usage:\n"), name);
+ wprintf(TranslateT("%s <command> [<param> [<param> [...]]].\n"), name);
+ wprintf(TranslateT("This will tell Miranda to run the specified command. The commands can have zero, one or more parameters. Use '%s help' to get a list of possible commands.\n"), name);
+ wprintf(TranslateT("No command can have more than %d parameters.\n"), MAX_ARGUMENTS - 1);
}
void ShowVersion()
{
- char name[128];
- char message[1024];
- GetProgramName(name, sizeof(name));
- mir_snprintf(message, sizeof(message), Translate("%s version %s"), name, __VERSION_STRING_DOTS);
-
- lpprintf("%s\n", message);
+ wchar_t name[128];
+ GetProgramName(name, _countof(name));
+ wprintf(TranslateT("%s version %s"), name, __VERSION_STRING_DOTS);
}
-int main(int argc, char *argv[])
+int wmain(int argc, wchar_t *argv[])
{
_setmode(_fileno(stdout), _O_U16TEXT);
- if (argc == 2 && !strcmp(argv[1], "-v")) {
+ if (argc == 2 && !wcscmp(argv[1], L"-v")) {
ShowVersion();
return 0;
}
if ((InitClient()) || (ConnectToMiranda()) || (GetKnownCommands()) || (LoadLangPackModule())) {
- lpprintf("Could not create connection with Miranda or could not retrieve list of known commands.\n");
+ wprintf(L"Could not create connection with Miranda or could not retrieve list of known commands.\n");
return MIMRES_NOMIRANDA;
}
@@ -90,10 +75,10 @@ int main(int argc, char *argv[]) PReply reply = ParseCommand(argv, argc);
if (reply) {
error = reply->code;
- lpprintf("%s\n", reply->message);
+ wprintf(L"%s\n", reply->message);
}
else {
- lpprintf(Translate("Unknown command '%s'.\n"), argv[1]);
+ wprintf(TranslateT("Unknown command '%s'.\n"), argv[1]);
error = 0;
}
diff --git a/plugins/MimCmd/src/commands.cpp b/plugins/MimCmd/src/commands.cpp index 4d11c66f24..37a6be7795 100644 --- a/plugins/MimCmd/src/commands.cpp +++ b/plugins/MimCmd/src/commands.cpp @@ -27,9 +27,9 @@ int cKnownCommands = 0; HMODULE hCmdLineDLL = nullptr;
-char *GetMirandaFolder(char *mimFolder, int size)
+wchar_t* GetMirandaFolder(wchar_t *mimFolder, int size)
{
- strncpy_s(mimFolder, size, sdCmdLine->mimFolder, _TRUNCATE);
+ wcsncpy_s(mimFolder, size, sdCmdLine->mimFolder, _TRUNCATE);
return mimFolder;
}
@@ -51,17 +51,17 @@ int ConnectToMiranda() SetEnvironmentVariable(L"PATH", ptszVal);
delete[] ptszVal;
- char pluginPath[1024];
- GetMirandaFolder(pluginPath, sizeof(pluginPath));
- mir_strcat(pluginPath, "\\plugins\\cmdline.dll");
+ wchar_t pluginPath[1024];
+ GetMirandaFolder(pluginPath, _countof(pluginPath));
+ mir_wstrcat(pluginPath, L"\\plugins\\cmdline.dll");
ListCommands = nullptr;
- hCmdLineDLL = LoadLibraryA(pluginPath);
+ hCmdLineDLL = LoadLibraryW(pluginPath);
int failure = 1;
if (hCmdLineDLL)
- ListCommands = (LISTCOMMANDS) GetProcAddress(hCmdLineDLL, "ListCommands");
+ ListCommands = (LISTCOMMANDS)GetProcAddress(hCmdLineDLL, "ListCommands");
if (ListCommands)
failure = 0;
@@ -85,19 +85,19 @@ int DestroyKnownCommands() return 0;
}
-PCommand GetCommand(char *command)
+PCommand GetCommand(wchar_t *command)
{
int i;
- char lower[512];
- strncpy_s(lower, command, _TRUNCATE);
- _strlwr(lower);
+ wchar_t lower[512];
+ wcsncpy_s(lower, command, _TRUNCATE);
+ _wcslwr(lower);
for (i = 0; i < cKnownCommands; i++)
- if (mir_strcmp(knownCommands[i].command, lower) == 0)
+ if (mir_wstrcmp(knownCommands[i].command, lower) == 0)
return &knownCommands[i];
//allow more parameters to trigger the help command - /h -h /? --help
- if ((mir_strcmp(lower, "/h") == 0) || (mir_strcmp(lower, "-h") == 0) || (mir_strcmp(lower, "/?") == 0) || (mir_strcmp(lower, "--help") == 0))
+ if ((mir_wstrcmp(lower, L"/h") == 0) || (mir_wstrcmp(lower, L"-h") == 0) || (mir_wstrcmp(lower, L"/?") == 0) || (mir_wstrcmp(lower, L"--help") == 0))
for (i = 0; i < cKnownCommands; i++)
if (knownCommands[i].ID == MIMCMD_HELP)
return &knownCommands[i];
@@ -105,37 +105,37 @@ PCommand GetCommand(char *command) return nullptr;
}
-void HandleHelpCommand(PCommand, char *argv[], int argc, PReply reply)
+void HandleHelpCommand(PCommand, wchar_t *argv[], int argc, PReply reply)
{
- CMStringA szReply;
+ CMStringW szReply;
if (argc >= 3) {
PCommand command = GetCommand(argv[2]);
if (command) {
reply->code = MIMRES_SUCCESS;
- szReply.Append(Translate(command->help));
+ szReply.Append(TranslateW(command->help));
}
else {
reply->code = MIMRES_NOTFOUND;
- szReply.AppendFormat(Translate("No help for '%s'."), argv[2]);
+ szReply.AppendFormat(TranslateT("No help for '%s'."), argv[2]);
}
}
else {
reply->code = MIMRES_SUCCESS;
- szReply.Append(Translate("Available commands: "));
+ szReply.Append(TranslateT("Available commands: "));
for (int i = 0; i < cKnownCommands - 1; i++) {
szReply.Append(knownCommands[i].command);
- szReply.Append(", ");
+ szReply.Append(L", ");
}
szReply.Append(knownCommands[cKnownCommands-1].command);
szReply.AppendChar('.');
}
- strncpy_s(reply->message, szReply, _TRUNCATE);
+ wcsncpy_s(reply->message, szReply, _TRUNCATE);
}
-PReply ParseCommand(char *argv[], int argc)
+PReply ParseCommand(wchar_t *argv[], int argc)
{
PCommand command = GetCommand(argv[1]);
if (!command)
@@ -150,10 +150,10 @@ PReply ParseCommand(char *argv[], int argc) return reply;
}
-void FillSharedDataStruct(PCommand command, char *arguments[], int count)
+void FillSharedDataStruct(PCommand command, wchar_t *arguments[], int count)
{
for (int i = 0; i < count; i++)
- strncpy_s(sdCmdLine->arguments[i], ARGUMENT_SIZE, arguments[i], _TRUNCATE);
+ wcsncpy_s(sdCmdLine->arguments[i], ARGUMENT_SIZE, arguments[i], _TRUNCATE);
sdCmdLine->cArguments = count;
sdCmdLine->command = *command;
@@ -161,10 +161,9 @@ void FillSharedDataStruct(PCommand command, char *arguments[], int count) sdCmdLine->reply.code =-1;
}
-void ProcessConsoleCommand(PCommand command, char *arguments[], int count, PReply reply)
+void ProcessConsoleCommand(PCommand command, wchar_t *arguments[], int count, PReply reply)
{
const HANDLE events[] = { heServerDone, heServerClose, heServerBufferFull };
- const int cEvents = sizeof(events) / sizeof(events[0]);
if (WaitForSingleObject(hmClient, INFINITE) == WAIT_OBJECT_0) {//got the mutex, we're the only one who can talk to miranda now
FillSharedDataStruct(command, arguments, count);
@@ -173,25 +172,25 @@ void ProcessConsoleCommand(PCommand command, char *arguments[], int count, PRepl int done = FALSE;
while (!done) {
// wait until server either finished processing or miranda was closed
- switch (WaitForMultipleObjects(cEvents, events, FALSE, INFINITE)) {
+ switch (WaitForMultipleObjects(_countof(events), events, FALSE, INFINITE)) {
case WAIT_OBJECT_0: //done event
done = TRUE;
break; //nothing to do
case WAIT_OBJECT_0 + 1: //close event
default:
- mir_strcpy(sdCmdLine->reply.message, Translate("Miranda has been closed or an error has occurred while waiting for the result, could not process request."));
+ mir_wstrcpy(sdCmdLine->reply.message, TranslateT("Miranda has been closed or an error has occurred while waiting for the result, could not process request."));
done = TRUE;
break;
case WAIT_OBJECT_0 + 2: //buffer full event
- lpprintf("%s", reply->message);
+ wprintf(L"%s", reply->message);
break;
}
}
reply->code = sdCmdLine->reply.code;
- strncpy_s(reply->message, sdCmdLine->reply.message, _TRUNCATE);
+ wcsncpy_s(reply->message, sdCmdLine->reply.message, _TRUNCATE);
ReleaseMutex(hmClient); //let other possible clients talk to the server
}
diff --git a/plugins/MimCmd/src/commands.h b/plugins/MimCmd/src/commands.h index 2bd0f74a06..591572d15a 100644 --- a/plugins/MimCmd/src/commands.h +++ b/plugins/MimCmd/src/commands.h @@ -35,8 +35,8 @@ int DisconnectFromMiranda(); int GetKnownCommands();
int DestroyKnownCommands();
-PCommand GetCommand(char *command);
-PReply ParseCommand(char *argv[], int argc);
-void ProcessConsoleCommand(PCommand command, char *arguments[], int count, PReply reply);
+PCommand GetCommand(wchar_t *command);
+PReply ParseCommand(wchar_t *argv[], int argc);
+void ProcessConsoleCommand(PCommand command, wchar_t *arguments[], int count, PReply reply);
#endif
\ No newline at end of file diff --git a/plugins/MimCmd/src/stdafx.h b/plugins/MimCmd/src/stdafx.h index 51c2476f62..0ed8285a81 100644 --- a/plugins/MimCmd/src/stdafx.h +++ b/plugins/MimCmd/src/stdafx.h @@ -36,5 +36,3 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "version.h"
#include "../CmdLine/src/utils.h"
#include "commands.h"
-
-int lpprintf(const char *format, ...);
diff --git a/plugins/MimCmd/src/version.h b/plugins/MimCmd/src/version.h index c9625d9e64..75fb63c56a 100644 --- a/plugins/MimCmd/src/version.h +++ b/plugins/MimCmd/src/version.h @@ -1,6 +1,6 @@ #define __MAJOR_VERSION 0
-#define __MINOR_VERSION 0
-#define __RELEASE_NUM 4
+#define __MINOR_VERSION 1
+#define __RELEASE_NUM 0
#define __BUILD_NUM 1
#include <stdver.h>
|