From 5b0a53a6d3f1b8d70b34631d96d3815d0a334dd3 Mon Sep 17 00:00:00 2001 From: Vadim Dashevskiy Date: Mon, 16 Jul 2012 16:31:53 +0000 Subject: Clist_mw, Clist_nicer, CmdLine, Console: folder structure change git-svn-id: http://svn.miranda-ng.org/main/trunk@988 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/CmdLine/MimCmd/MimCmd.cpp | 117 ------------- plugins/CmdLine/MimCmd/MimCmd.vcxproj | 14 +- plugins/CmdLine/MimCmd/MimCmd.vcxproj.filters | 14 +- plugins/CmdLine/MimCmd/commands.cpp | 239 -------------------------- plugins/CmdLine/MimCmd/commands.h | 42 ----- plugins/CmdLine/MimCmd/common.h | 36 ---- plugins/CmdLine/MimCmd/res/version.rc | 103 +++++++++++ plugins/CmdLine/MimCmd/resource.h | 14 -- plugins/CmdLine/MimCmd/src/MimCmd.cpp | 117 +++++++++++++ plugins/CmdLine/MimCmd/src/commands.cpp | 239 ++++++++++++++++++++++++++ plugins/CmdLine/MimCmd/src/commands.h | 42 +++++ plugins/CmdLine/MimCmd/src/common.h | 36 ++++ plugins/CmdLine/MimCmd/src/resource.h | 14 ++ plugins/CmdLine/MimCmd/version.rc | 104 ----------- 14 files changed, 565 insertions(+), 566 deletions(-) delete mode 100644 plugins/CmdLine/MimCmd/MimCmd.cpp delete mode 100644 plugins/CmdLine/MimCmd/commands.cpp delete mode 100644 plugins/CmdLine/MimCmd/commands.h delete mode 100644 plugins/CmdLine/MimCmd/common.h create mode 100644 plugins/CmdLine/MimCmd/res/version.rc delete mode 100644 plugins/CmdLine/MimCmd/resource.h create mode 100644 plugins/CmdLine/MimCmd/src/MimCmd.cpp create mode 100644 plugins/CmdLine/MimCmd/src/commands.cpp create mode 100644 plugins/CmdLine/MimCmd/src/commands.h create mode 100644 plugins/CmdLine/MimCmd/src/common.h create mode 100644 plugins/CmdLine/MimCmd/src/resource.h delete mode 100644 plugins/CmdLine/MimCmd/version.rc (limited to 'plugins/CmdLine/MimCmd') diff --git a/plugins/CmdLine/MimCmd/MimCmd.cpp b/plugins/CmdLine/MimCmd/MimCmd.cpp deleted file mode 100644 index cfd0e9b835..0000000000 --- a/plugins/CmdLine/MimCmd/MimCmd.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* -CmdLine plugin for Miranda IM - -Copyright © 2007 Cristian Libotean - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "common.h" -#include "..\utils.h" -#include "..\version.h" - -int hLangpack = 0; - -int lpprintf(const char *format, ...) -{ - va_list va; - va_start(va, format); - const int MAX_SIZE = 16192; - char buffer[MAX_SIZE] = {0}; - int len = _vsnprintf(buffer, MAX_SIZE - 1, format, va); - buffer[MAX_SIZE - 1] = 0; - va_end(va); - CharToOemBuff(buffer, buffer, len); - printf("%s", buffer); - - return len; -} - -char *GetProgramName(char *programName, int size) -{ - char name[512]; - GetModuleFileName(GetModuleHandle(NULL), name, sizeof(name)); - char *p = strrchr(name, '\\'); - if (p) - { - STRNCPY(programName, p + 1, size); - } - else{ - STRNCPY(programName, name, size); - } - - return programName; -} - -void PrintUsage() -{ - char name[128]; - GetProgramName(name, sizeof(name)); - - lpprintf(Translate("%s usage:\n"), name); - lpprintf(Translate("%s [ [, ..]]\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); -} - -void ShowVersion() -{ - char name[128]; - char message[1024]; - GetProgramName(name, sizeof(name)); - mir_snprintf(message, sizeof(message), Translate("%s version %s"), name, __VERSION_STRING); - - lpprintf("%s\n", message); -} - -int main(int argc, char *argv[]) -{ - int error = 0; - if ((argc == 2) && (strcmp(argv[1], "-v") == 0)) - { - ShowVersion(); - - return 0; - } - - if ((InitClient()) || (ConnectToMiranda()) || (GetKnownCommands()) || (LoadLangPackModule())) - { - lpprintf("Could not create connection with Miranda or could not retrieve list of known commands.\n"); - error = MIMRES_NOMIRANDA; - } - else{ - if ((argc <= 1) || (argc > MAX_ARGUMENTS)) - { - PrintUsage(); - } - else{ - PReply reply = ParseCommand(argv, argc); - if (reply) - { - error = reply->code; - lpprintf("%s\n", reply->message); - } - else{ - lpprintf(Translate("Unknown command '%s'.\n"), argv[1]); - } - - DestroyKnownCommands(); - DisconnectFromMiranda(); - DestroyClient(); - } - } - - return error; -} diff --git a/plugins/CmdLine/MimCmd/MimCmd.vcxproj b/plugins/CmdLine/MimCmd/MimCmd.vcxproj index 00e04c32c2..439370c027 100644 --- a/plugins/CmdLine/MimCmd/MimCmd.vcxproj +++ b/plugins/CmdLine/MimCmd/MimCmd.vcxproj @@ -166,21 +166,21 @@ - - + + Create - + NotUsing - - - + + + - + diff --git a/plugins/CmdLine/MimCmd/MimCmd.vcxproj.filters b/plugins/CmdLine/MimCmd/MimCmd.vcxproj.filters index 11c62edbef..4352e86988 100644 --- a/plugins/CmdLine/MimCmd/MimCmd.vcxproj.filters +++ b/plugins/CmdLine/MimCmd/MimCmd.vcxproj.filters @@ -15,29 +15,29 @@ - + Source Files - + Source Files - + Source Files - + Header Files - + Header Files - + Header Files - + Resource Files diff --git a/plugins/CmdLine/MimCmd/commands.cpp b/plugins/CmdLine/MimCmd/commands.cpp deleted file mode 100644 index bae47b089c..0000000000 --- a/plugins/CmdLine/MimCmd/commands.cpp +++ /dev/null @@ -1,239 +0,0 @@ -/* -CmdLine plugin for Miranda IM - -Copyright © 2007 Cristian Libotean - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "common.h" - -inline char *STRNCPY(char *output, const char *input, size_t size) -{ - char *res = strncpy(output, input, size); - output[size - 1] = 0; - - return res; -} - -LISTCOMMANDS ListCommands = NULL; - -PCommand knownCommands = NULL; -int cKnownCommands = 0; - -HMODULE hCmdLineDLL = NULL; - -char *GetMirandaFolder(char *mimFolder, int size) -{ - STRNCPY(mimFolder, sdCmdLine->mimFolder, size); - mimFolder[size - 1] = 0; - - return mimFolder; -} - - -int ConnectToMiranda() -{ - char pluginPath[1024]; - GetMirandaFolder(pluginPath, sizeof(pluginPath)); - strcat(pluginPath, "\\plugins\\cmdline.dll"); - - ListCommands = NULL; - - hCmdLineDLL = LoadLibrary(pluginPath); - - int failure = 1; - if (hCmdLineDLL) - { - ListCommands = (LISTCOMMANDS) GetProcAddress(hCmdLineDLL, "ListCommands"); - } - - if (ListCommands) - { - failure = 0; - } - - return failure; -} - -int DisconnectFromMiranda() -{ - return FreeLibrary(hCmdLineDLL); -} - -int GetKnownCommands() -{ - ListCommands(&knownCommands, &cKnownCommands); - - return (knownCommands == NULL); -} - -int DestroyKnownCommands() -{ - - - return 0; -} - -PCommand GetCommand(char *command) -{ - int i; - char lower[512]; - STRNCPY(lower, command, sizeof(lower)); - _strlwr(lower); - - for (i = 0; i < cKnownCommands; i++) - { - if (strcmp(knownCommands[i].command, lower) == 0) - { - return &knownCommands[i]; - } - } - - //allow more parameters to trigger the help command - /h -h /? --help - if ((strcmp(lower, "/h") == 0) || (strcmp(lower, "-h") == 0) || (strcmp(lower, "/?") == 0) || (strcmp(lower, "--help") == 0)) - { - for (i = 0; i < cKnownCommands; i++) - { - if (knownCommands[i].ID == MIMCMD_HELP) - { - return &knownCommands[i]; - } - } - } - - return NULL; -} - -void HandleHelpCommand(PCommand helpCommand, char *argv[], int argc, PReply reply) -{ - const int size = REPLY_SIZE; - if (argc >= 3) - { - PCommand command = GetCommand(argv[2]); - - if (command) - { - reply->code = MIMRES_SUCCESS; - STRNCPY(reply->message, Translate(command->help), size); - } - else{ - reply->code = MIMRES_NOTFOUND; - _snprintf(reply->message, size, Translate("No help for '%s'."), argv[2]); - reply->message[size -1 ] = 0; - } - } - else{ - reply->code = MIMRES_SUCCESS; - STRNCPY(reply->message, Translate("Available commands: "), size); - - int i; - for (i = 0; i < cKnownCommands - 1; i++) - { - strncat(reply->message, knownCommands[i].command, size); - strncat(reply->message, ", ", size); - } - strncat(reply->message, knownCommands[cKnownCommands - 1].command, size); - strncat(reply->message, ".", size); - } -} - -PReply ParseCommand(char *argv[], int argc) -{ - PCommand command = GetCommand(argv[1]); - if (command) - { - PReply reply = &sdCmdLine->reply; - if (command->ID == MIMCMD_HELP) - { - HandleHelpCommand(command, argv, argc, reply); - } - else{ - ProcessConsoleCommand(command, argv, argc, reply); - } - - return reply; - } - else{ - return NULL; - } -} - -void FillSharedDataStruct(PCommand command, char *arguments[], int count) -{ - int i; - for (i = 0; i < count; i++) - { - STRNCPY(sdCmdLine->arguments[i], arguments[i], ARGUMENT_SIZE); - } - - sdCmdLine->cArguments = count; - sdCmdLine->command = *command; - *sdCmdLine->reply.message = 0; - sdCmdLine->reply.code =-1; -} - -void ProcessConsoleCommand(PCommand command, char *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); - SetEvent(heServerExec); //tell Miranda to process the request - - int done = FALSE; - while (!done) - { - switch (WaitForMultipleObjects(cEvents, events, FALSE, INFINITE)) //wait until server either finished processing or miranda was closed - { - case WAIT_OBJECT_0: //done event - { - done = TRUE; - - break; //nothing to do - } - - case WAIT_OBJECT_0 + 1: //close event - default: - { - strcpy(sdCmdLine->reply.message, Translate("Miranda has been closed or an error has occured while waiting for the result, could not process request.")); - done = TRUE; - - break; - } - - case WAIT_OBJECT_0 + 2: //buffer full event - { - lpprintf("%s", reply->message); - - break; - } - } - } - - reply->code = sdCmdLine->reply.code; - STRNCPY(reply->message, sdCmdLine->reply.message, REPLY_SIZE); - - ReleaseMutex(hmClient); //let other possible clients talk to the server - } - else{ - int err = GetLastError(); - reply->code = -1; - *reply->message = 0; - } - -} \ No newline at end of file diff --git a/plugins/CmdLine/MimCmd/commands.h b/plugins/CmdLine/MimCmd/commands.h deleted file mode 100644 index 4c60b49565..0000000000 --- a/plugins/CmdLine/MimCmd/commands.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -CmdLine plugin for Miranda IM - -Copyright © 2007 Cristian Libotean - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#ifndef M_MIMCMD_COMMANDS_H -#define M_MIMCMD_COMMANDS_H - -extern PCommand knownCommands; -extern int cKnownCommands; - -typedef void (* LISTCOMMANDS)(PCommand *commands, int *count); - -extern LISTCOMMANDS ListCommands; - -char *GetMirandaFolder(); - -int ConnectToMiranda(); -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); - -#endif \ No newline at end of file diff --git a/plugins/CmdLine/MimCmd/common.h b/plugins/CmdLine/MimCmd/common.h deleted file mode 100644 index a733743e07..0000000000 --- a/plugins/CmdLine/MimCmd/common.h +++ /dev/null @@ -1,36 +0,0 @@ -/* -CmdLine plugin for Miranda IM - -Copyright © 2007 Cristian Libotean - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#define _CRT_SECURE_NO_WARNINGS - -#include -#include -#include - -#define NO_MIMCMD_COMMANDS - -#include -#include -#include - -#include "..\mimcmd_ipc.h" -#include "commands.h" - -int lpprintf(const char *format, ...); diff --git a/plugins/CmdLine/MimCmd/res/version.rc b/plugins/CmdLine/MimCmd/res/version.rc new file mode 100644 index 0000000000..b5257e17ef --- /dev/null +++ b/plugins/CmdLine/MimCmd/res/version.rc @@ -0,0 +1,103 @@ +// Microsoft Visual C++ generated resource script. +// +#ifdef APSTUDIO_INVOKED +#error this file is not editable by Microsoft Visual C++ +#endif //APSTUDIO_INVOKED + +#include "..\..\src\version.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION __PLUGINVERSION_STRING + PRODUCTVERSION __PLUGINVERSION_STRING + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "Author", __AUTHOR + VALUE "FileDescription", __DESC + VALUE "FileVersion", __VERSION_STRING + VALUE "InternalName", __PLUGIN_DISPLAY_NAME + VALUE "LegalCopyright", __COPYRIGHT + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/plugins/CmdLine/MimCmd/resource.h b/plugins/CmdLine/MimCmd/resource.h deleted file mode 100644 index c3bc570152..0000000000 --- a/plugins/CmdLine/MimCmd/resource.h +++ /dev/null @@ -1,14 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by version.rc - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 101 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1001 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/plugins/CmdLine/MimCmd/src/MimCmd.cpp b/plugins/CmdLine/MimCmd/src/MimCmd.cpp new file mode 100644 index 0000000000..07daf85a0c --- /dev/null +++ b/plugins/CmdLine/MimCmd/src/MimCmd.cpp @@ -0,0 +1,117 @@ +/* +CmdLine plugin for Miranda IM + +Copyright © 2007 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "common.h" +#include "..\..\src\utils.h" +#include "..\..\src\version.h" + +int hLangpack = 0; + +int lpprintf(const char *format, ...) +{ + va_list va; + va_start(va, format); + const int MAX_SIZE = 16192; + char buffer[MAX_SIZE] = {0}; + int len = _vsnprintf(buffer, MAX_SIZE - 1, format, va); + buffer[MAX_SIZE - 1] = 0; + va_end(va); + CharToOemBuff(buffer, buffer, len); + printf("%s", buffer); + + return len; +} + +char *GetProgramName(char *programName, int size) +{ + char name[512]; + GetModuleFileName(GetModuleHandle(NULL), name, sizeof(name)); + char *p = strrchr(name, '\\'); + if (p) + { + STRNCPY(programName, p + 1, size); + } + else{ + STRNCPY(programName, name, size); + } + + return programName; +} + +void PrintUsage() +{ + char name[128]; + GetProgramName(name, sizeof(name)); + + lpprintf(Translate("%s usage:\n"), name); + lpprintf(Translate("%s [ [, ..]]\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); +} + +void ShowVersion() +{ + char name[128]; + char message[1024]; + GetProgramName(name, sizeof(name)); + mir_snprintf(message, sizeof(message), Translate("%s version %s"), name, __VERSION_STRING); + + lpprintf("%s\n", message); +} + +int main(int argc, char *argv[]) +{ + int error = 0; + if ((argc == 2) && (strcmp(argv[1], "-v") == 0)) + { + ShowVersion(); + + return 0; + } + + if ((InitClient()) || (ConnectToMiranda()) || (GetKnownCommands()) || (LoadLangPackModule())) + { + lpprintf("Could not create connection with Miranda or could not retrieve list of known commands.\n"); + error = MIMRES_NOMIRANDA; + } + else{ + if ((argc <= 1) || (argc > MAX_ARGUMENTS)) + { + PrintUsage(); + } + else{ + PReply reply = ParseCommand(argv, argc); + if (reply) + { + error = reply->code; + lpprintf("%s\n", reply->message); + } + else{ + lpprintf(Translate("Unknown command '%s'.\n"), argv[1]); + } + + DestroyKnownCommands(); + DisconnectFromMiranda(); + DestroyClient(); + } + } + + return error; +} diff --git a/plugins/CmdLine/MimCmd/src/commands.cpp b/plugins/CmdLine/MimCmd/src/commands.cpp new file mode 100644 index 0000000000..bae47b089c --- /dev/null +++ b/plugins/CmdLine/MimCmd/src/commands.cpp @@ -0,0 +1,239 @@ +/* +CmdLine plugin for Miranda IM + +Copyright © 2007 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "common.h" + +inline char *STRNCPY(char *output, const char *input, size_t size) +{ + char *res = strncpy(output, input, size); + output[size - 1] = 0; + + return res; +} + +LISTCOMMANDS ListCommands = NULL; + +PCommand knownCommands = NULL; +int cKnownCommands = 0; + +HMODULE hCmdLineDLL = NULL; + +char *GetMirandaFolder(char *mimFolder, int size) +{ + STRNCPY(mimFolder, sdCmdLine->mimFolder, size); + mimFolder[size - 1] = 0; + + return mimFolder; +} + + +int ConnectToMiranda() +{ + char pluginPath[1024]; + GetMirandaFolder(pluginPath, sizeof(pluginPath)); + strcat(pluginPath, "\\plugins\\cmdline.dll"); + + ListCommands = NULL; + + hCmdLineDLL = LoadLibrary(pluginPath); + + int failure = 1; + if (hCmdLineDLL) + { + ListCommands = (LISTCOMMANDS) GetProcAddress(hCmdLineDLL, "ListCommands"); + } + + if (ListCommands) + { + failure = 0; + } + + return failure; +} + +int DisconnectFromMiranda() +{ + return FreeLibrary(hCmdLineDLL); +} + +int GetKnownCommands() +{ + ListCommands(&knownCommands, &cKnownCommands); + + return (knownCommands == NULL); +} + +int DestroyKnownCommands() +{ + + + return 0; +} + +PCommand GetCommand(char *command) +{ + int i; + char lower[512]; + STRNCPY(lower, command, sizeof(lower)); + _strlwr(lower); + + for (i = 0; i < cKnownCommands; i++) + { + if (strcmp(knownCommands[i].command, lower) == 0) + { + return &knownCommands[i]; + } + } + + //allow more parameters to trigger the help command - /h -h /? --help + if ((strcmp(lower, "/h") == 0) || (strcmp(lower, "-h") == 0) || (strcmp(lower, "/?") == 0) || (strcmp(lower, "--help") == 0)) + { + for (i = 0; i < cKnownCommands; i++) + { + if (knownCommands[i].ID == MIMCMD_HELP) + { + return &knownCommands[i]; + } + } + } + + return NULL; +} + +void HandleHelpCommand(PCommand helpCommand, char *argv[], int argc, PReply reply) +{ + const int size = REPLY_SIZE; + if (argc >= 3) + { + PCommand command = GetCommand(argv[2]); + + if (command) + { + reply->code = MIMRES_SUCCESS; + STRNCPY(reply->message, Translate(command->help), size); + } + else{ + reply->code = MIMRES_NOTFOUND; + _snprintf(reply->message, size, Translate("No help for '%s'."), argv[2]); + reply->message[size -1 ] = 0; + } + } + else{ + reply->code = MIMRES_SUCCESS; + STRNCPY(reply->message, Translate("Available commands: "), size); + + int i; + for (i = 0; i < cKnownCommands - 1; i++) + { + strncat(reply->message, knownCommands[i].command, size); + strncat(reply->message, ", ", size); + } + strncat(reply->message, knownCommands[cKnownCommands - 1].command, size); + strncat(reply->message, ".", size); + } +} + +PReply ParseCommand(char *argv[], int argc) +{ + PCommand command = GetCommand(argv[1]); + if (command) + { + PReply reply = &sdCmdLine->reply; + if (command->ID == MIMCMD_HELP) + { + HandleHelpCommand(command, argv, argc, reply); + } + else{ + ProcessConsoleCommand(command, argv, argc, reply); + } + + return reply; + } + else{ + return NULL; + } +} + +void FillSharedDataStruct(PCommand command, char *arguments[], int count) +{ + int i; + for (i = 0; i < count; i++) + { + STRNCPY(sdCmdLine->arguments[i], arguments[i], ARGUMENT_SIZE); + } + + sdCmdLine->cArguments = count; + sdCmdLine->command = *command; + *sdCmdLine->reply.message = 0; + sdCmdLine->reply.code =-1; +} + +void ProcessConsoleCommand(PCommand command, char *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); + SetEvent(heServerExec); //tell Miranda to process the request + + int done = FALSE; + while (!done) + { + switch (WaitForMultipleObjects(cEvents, events, FALSE, INFINITE)) //wait until server either finished processing or miranda was closed + { + case WAIT_OBJECT_0: //done event + { + done = TRUE; + + break; //nothing to do + } + + case WAIT_OBJECT_0 + 1: //close event + default: + { + strcpy(sdCmdLine->reply.message, Translate("Miranda has been closed or an error has occured while waiting for the result, could not process request.")); + done = TRUE; + + break; + } + + case WAIT_OBJECT_0 + 2: //buffer full event + { + lpprintf("%s", reply->message); + + break; + } + } + } + + reply->code = sdCmdLine->reply.code; + STRNCPY(reply->message, sdCmdLine->reply.message, REPLY_SIZE); + + ReleaseMutex(hmClient); //let other possible clients talk to the server + } + else{ + int err = GetLastError(); + reply->code = -1; + *reply->message = 0; + } + +} \ No newline at end of file diff --git a/plugins/CmdLine/MimCmd/src/commands.h b/plugins/CmdLine/MimCmd/src/commands.h new file mode 100644 index 0000000000..4c60b49565 --- /dev/null +++ b/plugins/CmdLine/MimCmd/src/commands.h @@ -0,0 +1,42 @@ +/* +CmdLine plugin for Miranda IM + +Copyright © 2007 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef M_MIMCMD_COMMANDS_H +#define M_MIMCMD_COMMANDS_H + +extern PCommand knownCommands; +extern int cKnownCommands; + +typedef void (* LISTCOMMANDS)(PCommand *commands, int *count); + +extern LISTCOMMANDS ListCommands; + +char *GetMirandaFolder(); + +int ConnectToMiranda(); +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); + +#endif \ No newline at end of file diff --git a/plugins/CmdLine/MimCmd/src/common.h b/plugins/CmdLine/MimCmd/src/common.h new file mode 100644 index 0000000000..0086237671 --- /dev/null +++ b/plugins/CmdLine/MimCmd/src/common.h @@ -0,0 +1,36 @@ +/* +CmdLine plugin for Miranda IM + +Copyright © 2007 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#define _CRT_SECURE_NO_WARNINGS + +#include +#include +#include + +#define NO_MIMCMD_COMMANDS + +#include +#include +#include + +#include "..\..\src\mimcmd_ipc.h" +#include "commands.h" + +int lpprintf(const char *format, ...); diff --git a/plugins/CmdLine/MimCmd/src/resource.h b/plugins/CmdLine/MimCmd/src/resource.h new file mode 100644 index 0000000000..c3bc570152 --- /dev/null +++ b/plugins/CmdLine/MimCmd/src/resource.h @@ -0,0 +1,14 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by version.rc + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/plugins/CmdLine/MimCmd/version.rc b/plugins/CmdLine/MimCmd/version.rc deleted file mode 100644 index 36d39c3d33..0000000000 --- a/plugins/CmdLine/MimCmd/version.rc +++ /dev/null @@ -1,104 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#ifdef APSTUDIO_INVOKED -#error this file is not editable by Microsoft Visual C++ -#endif //APSTUDIO_INVOKED - -#include "resource.h" -#include "..\..\CmdLine\version.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (U.S.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) -#endif //_WIN32 - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION __PLUGINVERSION_STRING - PRODUCTVERSION __PLUGINVERSION_STRING - FILEFLAGSMASK 0x17L -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "Author", __AUTHOR - VALUE "FileDescription", __DESC - VALUE "FileVersion", __VERSION_STRING - VALUE "InternalName", __PLUGIN_DISPLAY_NAME - VALUE "LegalCopyright", __COPYRIGHT - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END - -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - -- cgit v1.2.3