forked from mirrors/qotd
feat : unescape carriage returns on client
This commit is contained in:
@@ -7,7 +7,34 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <unistd.h> // read(), write(), close()
|
#include <unistd.h> // read(), write(), close()
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
void unescape(char *buffer, size_t buf_len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
bool last_is_escape = false;
|
||||||
|
for (i = 0; i < buf_len; i++)
|
||||||
|
{
|
||||||
|
if (last_is_escape)
|
||||||
|
{
|
||||||
|
switch (buffer[i])
|
||||||
|
{
|
||||||
|
case 'n':
|
||||||
|
buffer[i - 1] = ' ';
|
||||||
|
buffer[i] = '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffer[i] == '\\')
|
||||||
|
{
|
||||||
|
last_is_escape = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
last_is_escape = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
@@ -43,6 +70,7 @@ int main()
|
|||||||
// function for chat
|
// function for chat
|
||||||
char clientMessage[MESSAGE_STRING_LENGTH] = {0};
|
char clientMessage[MESSAGE_STRING_LENGTH] = {0};
|
||||||
recvfrom(sockfd, clientMessage, MESSAGE_STRING_LENGTH, 0, servaddr, &ss);
|
recvfrom(sockfd, clientMessage, MESSAGE_STRING_LENGTH, 0, servaddr, &ss);
|
||||||
|
unescape(clientMessage, (size_t)MESSAGE_STRING_LENGTH);
|
||||||
puts(clientMessage);
|
puts(clientMessage);
|
||||||
|
|
||||||
// close the socket
|
// close the socket
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
première ligne \n Deuxième ligne \n troixième ligne
|
première ligne\nDeuxième ligne\ntroixième ligne
|
||||||
|
|||||||
Reference in New Issue
Block a user