I'm working on a dictionary server via telnet, and I'd like it to return it in this format:
**word** (wordType): wordDef wordDef wordDef wordDef
wordDef wordDef wordDef.
Right now I'm outputting the code using:
write( my_socket, ("%s", word.data() ), word.length() ); // Bold this
write( my_socket, ("%s", theRest.data() ), theRest.length() );
So I'd like that first line to be bolded.
Edit
Sorry, I forgot to mention that this is for a command line.
Consider using using something like VT100 escape sequences. Since your server is telnet based the user is likely to have a client that supports various terminal modes.
For instance if you wanted to turn on bold for a VT100 terminal you would output
ESC[1m
where "ESC" is the character value 0x1b. To switch back to normal formatting output
ESC[0m
To use this in your application you can change the example lines from your question to the following.
std::string str = "Hello!"
write( my_socket, "\x1b[1m", 4); // Turn on bold formatting
write( my_socket, str.c_str(), str.size()); // output string
write( my_socket, "\x1b[0m", 4); // Turn all formatting off
There other terminal modes such as VT52, VT220, etc. You might want to look into using ncurses although it might be a bit heavy if all you need is simple bold on/off.
Related
I run a command in CMD through my C++ app which saves the output from that command. In that output, there is a port number and a remote API token, that changes upon each restart of the application im targeting.
This is the output I'm getting through my CMD command, which I store in a string:
"C:/Riot Games/League of Legends/LeagueClientUx.exe" "--riotclient-auth-token=5NFOIOqKB9EfSVsxBMrFUw" "--riotclient-app-port=63498" "--no-rads" "--disable-self-update" "--region=EUW" "--locale=en_GB" "--remoting-auth-token=***vx5yZOk_TkAt9YKq-PEucw***" "--respawn-command=LeagueClient.exe" "--respawn-display-name=League of Legends" "--app-port=63530" "--install-directory=C:\Riot Games\League of Legends" "--app-name=LeagueClient" "--ux-name=LeagueClientUx" "--ux-helper-name=LeagueClientUxHelper" "--log-dir=LeagueClient Logs" "--crash-reporting=crashpad" "--crash-environment=EUW1" "--crash-pipe=\\.\pipe\crashpad_19692_AJMBMQYOZVYYJMRF" "--app-log-file-path=C:/Riot Games/League of Legends/Logs/LeagueClient Logs/2020-07-09T12-55-09_19692_LeagueClient.log" "--app-pid=19692" "--output-base-dir=C:\Riot Games\League of Legends" "--no-proxy-server"
I've tried some stuff with the regex library, and managed to split my results up into words, but I still can't figure out how I save a specific line, that is the port number and the result of remoting-auth-token="characters I want to save".
My code to find out how many words are in the output string:
std::string output = exec("wmic PROCESS WHERE name='LeagueClientUx.exe' GET commandline");
std::regex wregex("(\\w+)");
auto words_begin = std::sregex_iterator(output.begin(), output.end(), wregex);
auto words_end = std::sregex_iterator();
std::cout << "Found: " << std::distance(words_begin, words_end) << std::endl;
PrintMatch(words_begin, words_end);
Output:
´´
Found: 110 CommandLine, C, Riot, Games, League, of, Legends, LeagueClientUx, exe, riotclient, auth, token, 5NFOIOqKB9EfSVsxBMrFUw, riotclient, app, port, 63498, no, rads, disable, self, update, region, EUW, locale, en_GB, remoting, auth, token, vx5yZOk_TkAt9YKq, PEucw, respawn, command, LeagueClient, exe, respawn, display, name, League, of, Legends, app, port, 63530, ´´ And a bit more but character restriction limits me, however the output which I need to store is there. I've set commas to mark new lines in the output.
‘’
It depends on what you mean by "save". Save to file or just assign to a variable? My guess is that you are confused about how iterators work and are wondering how you can fetch the remote-auth-token and the port number to from the words_begin variable. If the number of "words" in the cmd output is always the same you can use:
std::advance(words_begin,16);
std::string port = words_begin->str();
std::advance(words_begin,13);
std::string authToken = words_begin->str();
now, normally you would write the regex so as to only match the part you are interested in. Currently, since you are matching every "word", you are dependent on what position the remote auth token and port number are in the cmd output which might cause your application to break if that output ever changes order or add another word in front.
I'm using windows OS and trying to write ACE_Tstring that contains multiple languages sentence(by Unicode) to a file using ACE_OS::write().
But the result I'm getting in the file is unpredictable characters(gibberish text).
This is my code implemented :
ACE_Tstring *str = new ACE_Tstring(L"مرحبا привет świecie Hello")
ACE_HANDL hFile = ACE_OS::open(L"myfile", _O_WRONLY);
ACE_OS::write(hFile, str, 1048);
wprintf(L"%ls",str->c_str());
As you can see I also print the string to the screen, and on screen I get the characters "????" where any character accept for English characters appear.
Written Text
مرحبا привет świecie Hello
Result on Screen :
?????? ????? ??????? Hello
What am I missing and what is wrong with my code?
ACE_TString is a typedef for ACE_CString when ACE_USES_WCHAR is not set. Try using ACE_WString if you need to force it to wide-chars.
I had read lots of pages on AHK but haven't found any that explains how to make a script that enables me to replace "for" when it's typed by the following:
for(int i=0;i<CONDITION;i++)
{
}
I would like it to set cursor focus on inside the brackets to start writing the loop-code right away.
Here is what I have came up until now:
::for::for(int i=0;i<CONDITION;i++),
{,
,
}
Should replace "for" with the code at top of the post but gets the following error:
Error at line 2.
linetext: ,,
Error: this line does not contain recognised action.
The program will exit.
A hotkey (or hotstring) that executes more than one line must list its first line beneath the hotkey (or hotstring).
https://autohotkey.com/docs/FAQ.htm#autoexec
Comma, semicolon, and other characters such as {}^!+# have special meaning in AHK and need to be escaped in order to be interpreted differently than it normally would.
https://autohotkey.com/docs/commands/_EscapeChar.htm
::for::for(int i=0`;i<CONDITION`;i`{+`}`{+`})`n`{`{`}`n`n`{`}`}{Up}
The easiest way to send such a text is this:
; #If WinActive("ahk_class Notepad")
::for::
ClipSaved := ClipboardAll ; save clipboard
clipboard := "" ; empty clipboard
clipboard = ; send this text to the clipboard:
(
for(int i=0;i<CONDITION;i++)
{
}
)
ClipWait, 1 ; wait for the clipboard to contain data
Send, ^v
Send, {Up}
clipboard := ClipSaved ; restore original clipboard
return
; #If
Also fairly simple is this approach, which works well in Scite and Notepad++ which handles tabbing automatically:
::for::
SendRaw,
(
For(int i=0;i<CONDITION;i++)
{
}
)
Send, {Up}{End}
return
i am working on a cgi program , i am receiving an email address like this : someone#site.com and storing it in a file.
but some thing strange happens. when i use IE the '#' char , won't change and it is same in the file , but when i use chrome , '#' char ,changes to %40 and the only way to retrieve the '#' is to find %40 and replace it with '#'.am i coding wrong or chrome has problem?
to understand better :
IE: someone#site.com
Chrome:someone%40site.com
and when i send information back to the browser , %40 doesn't change to #
It's IE that's doing it wrong in actual fact - You need to change the %xx code back to a character. In the case of %40 this would be ASCII no. 0x40 == 64 == '#'. You can't rely on it being ASCII, however, as unicode characters (such as accented letters) will also be similarly encoded.
Most languages like PHP and Python have a helper function to encode and decode these (PHP's is called url_encode() and url_decode()) - I've not used CGI on C++ for a long while, so not sure if there's a helper readily available or if you'll have to code your own - either way you should be prepared to decode url-encoded strings as all browsers will do this for some characters if not all (eg. %20 instead of a space is very common).
Hope this helps!
the answer above is correct , just in make the topic richer i think this peace of code can be the function you use :
int main()
{
int number;
string dataString="hi %40 c++ programmer %40 !";
string transform;
istringstream input;
string::size_type location = dataString.find("%");
while (location <string::npos)
{
transform = dataString.substr(location+1, 2);
input.str(transform);
input >> hex >> number;
dataString.replace(location,3,1,static_cast<char>(number));
location = dataString.find("%", location+1);
}
cout << dataString << endl;
}
I'm trying to append text to a rich edit control by appending the original string and resending the EM_SETTEXTEX message.
char outputText[4096] = "{\\rtf1\\ansi\\ansicpg0\\deff0{\\colortbl;\\red0\\green0\\blue0;\\red255\\green0\\blue0;\\red50\\green205\\blue50;\\red255\\green140\\blue0;}TEST";
SETTEXTEX s;s.flags = ST_DEFAULT;s.codepage = CP_ACP;
SendMessage(hOutputWndText,EM_SETTEXTMODE,(WPARAM)TM_RICHTEXT,NULL);
SendMessage(hOutputWndText,EM_SETTEXTEX,(WPARAM)&s,(LPARAM)outputText);
I know I do not have a closing bracket on the string but it shows what I want.
TEST
Now I append the string and "re-set" the text inside the rich edit control. Notice, I add a closing bracket just incase.
strcat_s(outputText,"NEWSTUFF}");
SendMessage(hOutputWndText,EM_SETTEXTEX,(WPARAM)&s,(LPARAM)outputText);
And the output this time.
NEWSTUFF}
What gives? I printed the variable outputText to the console and I get the complete string.
{\rtf1\ansi\ansicpg0\deff0{\colortbl;\red0\green0\blue0;\red255\green0\blue0;\red50\green205\blue50;\red255\green140\blue0;}TESTNEWSTUFF}