From 183ce099a36e0019d0cd049774100f91eeca7c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Thu, 3 Jul 2014 11:59:13 +0000 Subject: CmdLine: Support for new lines (\n) in message text (as requested on UserVoice) git-svn-id: http://svn.miranda-ng.org/main/trunk@9660 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/CmdLine/src/mimcmd_data.h | 4 ++-- plugins/CmdLine/src/mimcmd_handlers.cpp | 30 ++++++++++++++++++++---------- plugins/CmdLine/src/version.h | 2 +- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/plugins/CmdLine/src/mimcmd_data.h b/plugins/CmdLine/src/mimcmd_data.h index 03500c69b4..713496f7b3 100644 --- a/plugins/CmdLine/src/mimcmd_data.h +++ b/plugins/CmdLine/src/mimcmd_data.h @@ -1,7 +1,7 @@ /* CmdLine plugin for Miranda IM -Copyright © 2007 Cristian Libotean +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 @@ -100,7 +100,7 @@ typedef TSharedData *PSharedData; #define MIMCMD_HELP_EXCHANGE LPGEN("Notifies Exchange plugin to check for email.\nUsage: exchange check.") #define MIMCMD_HELP_YAMN LPGEN("Notifies YAMN plugin to check for email.\nUsage: yamn check.") #define MIMCMD_HELP_CALLSERVICE LPGEN("Calls a Miranda service.\nUsage: callservice (d|s) (d|s).\nThe command will call Miranda service using wParam and lParam as arguments; the first letter of the paramater must be either 'd' if the parameter is a decimal number or 's' if the parameter is a string. Be careful when you use this function as you can only pass numbers and strings as data.\nNOTE: If you pass invalid data to a service Miranda might crash.") -#define MIMCMD_HELP_MESSAGE LPGEN("Sends a message to the specified contact(s).\nUsage: message [ [ [...]]] .\nThe command will send to the specified contact(s) - at least one contact must be specified - all parameters except the last one are considered recipients.\n has the following format: [:]. is the contact display name or unique ID and is an optional parameter representing the account of the contact (useful in case there is more than one contact with the same name).\nNOTE: The message string cannot exceed 512 characters.") +#define MIMCMD_HELP_MESSAGE LPGEN("Sends a message to the specified contact(s).\nUsage: message [ [ [...]]] .\nThe command will send to the specified contact(s) - at least one contact must be specified - all parameters except the last one are considered recipients.\n has the following format: [:]. is the contact display name or unique ID and is an optional parameter representing the account of the contact (useful in case there is more than one contact with the same name).\nNOTE: The message string cannot exceed 512 characters. You can use \\n for new line (and \\\\n for \\n).") #define MIMCMD_HELP_DATABASE LPGEN("Allows you to manage database settings.\nUsage:\n db set (b|i|d|s|w)\n db delete \n db get .\nThe command can set a database entry to the specified value (if the entry does not exist it will be created) as well as read or delete a specified database entry. is the name of the module where the key should be located, is the name of the key and is the value to be written. A character must be placed before in order to specify what kind of data to write: b - byte, i - integer (word), d - double word, s - string, w - wide string.") #define MIMCMD_HELP_PROXY LPGEN("Configures proxy settings either globally or per account.\nUsage: proxy (global|) [].\n is one of the following settings:\n status (disable | enable | toggle)\n server .") #define MIMCMD_HELP_CONTACTS LPGEN("Allows you to search/list contacts or open a message windows for specified contacts.\nUsage:\n contacts list [ [account:] [id:] [status:] [ [...]]].\nThe command will search all contacts and display the ones matching the search criteria. To search for a specific account use the keyword 'account:'. To search for contacts that have a certain ID use the keyword 'id:'. To search for contacts that have a certain status use 'status:'.\n contacts open [ [account:] [id:] [status:] [ [...]]].\nThe command will open a message window for all contacts that match the search criteria. To search for a specific account use the keyword 'account:'. To search for contacts that have a certain ID use the keyword 'id:'. To search for contacts that have a certain status use 'status:'. If no keyword is specified the command will open a message window for all contacts that have unread messages.") diff --git a/plugins/CmdLine/src/mimcmd_handlers.cpp b/plugins/CmdLine/src/mimcmd_handlers.cpp index 6552deb408..20c6c63b4a 100644 --- a/plugins/CmdLine/src/mimcmd_handlers.cpp +++ b/plugins/CmdLine/src/mimcmd_handlers.cpp @@ -1,7 +1,7 @@ /* CmdLine plugin for Miranda IM -Copyright © 2007 Cristian Libotean +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 @@ -1065,6 +1065,18 @@ void HandleCallServiceCommand(PCommand command, TArgument *argv, int argc, PRepl } } +void ParseMessage(char buffer[512], const char *message) { + unsigned int j = 0; + for (unsigned int i = 0; i < strlen(message); ++i) { + char c = message[i]; + if (c == '\\' && i < (strlen(message) - 1) && message[i+1] == 'n') { + c = '\n'; + i++; + } + buffer[j++] = c; + } + buffer[j] = '\0'; +} MCONTACT ParseContactParam(char *contact) { @@ -1095,22 +1107,20 @@ void HandleMessageCommand(PCommand command, TArgument *argv, int argc, PReply re { if (argc >= 4) { - char *message = argv[argc - 1]; //get the message - int i; - char *contact; + char message[512]; + ParseMessage(message, argv[argc - 1]); //get the message + char buffer[1024]; - MCONTACT hContact; - HANDLE hProcess = NULL; ACKDATA *ack = NULL; - for (i = 2; i < argc - 1; i++) + for (int i = 2; i < argc - 1; i++) { - contact = argv[i]; - hContact = ParseContactParam(contact); + char *contact = argv[i]; + MCONTACT hContact = ParseContactParam(contact); if (hContact) { bShouldProcessAcks = TRUE; - hProcess = (HANDLE) CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM) message); + HANDLE hProcess = (HANDLE)CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)message); const int MAX_COUNT = 60; int counter = 0; while (((ack = GetAck(hProcess)) == NULL) && (counter < MAX_COUNT)) diff --git a/plugins/CmdLine/src/version.h b/plugins/CmdLine/src/version.h index 2b2d62a030..fff697ffd6 100644 --- a/plugins/CmdLine/src/version.h +++ b/plugins/CmdLine/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 0 #define __RELEASE_NUM 4 -#define __BUILD_NUM 1 +#define __BUILD_NUM 2 #include -- cgit v1.2.3