From b849fc5ab8a31bd47d67a3d3f80b275e0f58d42a Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Wed, 13 Dec 2023 19:40:18 +0100 Subject: Reformatted net_send_string() --- FICS/network.c | 105 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 58 insertions(+), 47 deletions(-) diff --git a/FICS/network.c b/FICS/network.c index 8a81f0c..f22487a 100644 --- a/FICS/network.c +++ b/FICS/network.c @@ -211,55 +211,66 @@ PRIVATE int sendme(int which, char *str, int len) * Doesn't send anything unless the buffer fills, output waits until * flushed */ -PUBLIC int net_send_string(int fd, char *str, int format) +PUBLIC int +net_send_string(int fd, char *str, int format) { - int which, i, j; + int which, i, j; - if ((which = findConnection(fd)) < 0) { - return -1; - } - while (*str) { - for (i = 0; str[i] >= ' '; i++); - if (i) { - if (format && (i >= (j = LINE_WIDTH - con[which].outPos))) { /* word wrap */ - i = j; - while (i > 0 && str[i - 1] != ' ') - i--; - while (i > 0 && str[i - 1] == ' ') - i--; - if (i == 0) - i = j - 1; - sendme(which, str, i); - sendme(which, "\n\r\\ ", 6); - con[which].outPos = 4; - while (str[i] == ' ') /* eat the leading spaces after we wrap */ - i++; - } else { - sendme(which, str, i); - con[which].outPos += i; - } - str += i; - } else { /* non-printable stuff handled here */ - switch (*str) { - case '\t': - sendme(which, " ", 8 - (con[which].outPos & 7)); - con[which].outPos &= ~7; - if (con[which].outPos += 8 >= LINE_WIDTH) - con[which].outPos = 0; - break; - case '\n': - sendme(which, "\n\r", 2); - con[which].outPos = 0; - break; - case '\033': - con[which].outPos -= 3; - default: - sendme(which, str, 1); - } - str++; - } - } - return 0; + if ((which = findConnection(fd)) < 0) + return -1; + while (*str) { + for (i = 0; str[i] >= ' '; i++) { + /* null */; + } + + if (i) { + if (format && + (i >= (j = LINE_WIDTH - con[which].outPos))) { + // word wrap + + i = j; + + while (i > 0 && str[i - 1] != ' ') + i--; + while (i > 0 && str[i - 1] == ' ') + i--; + if (i == 0) + i = j - 1; + sendme(which, str, i); + sendme(which, "\n\r\\ ", 6); + con[which].outPos = 4; + + while (str[i] == ' ') { // eat the leading + // spaces after we wrap + i++; + } + } else { + sendme(which, str, i); + con[which].outPos += i; + } + str += i; + } else { // non-printable stuff handled here + switch (*str) { + case '\t': + sendme(which, " ", + 8 - (con[which].outPos & 7)); + con[which].outPos &= ~7; + if (con[which].outPos += 8 >= LINE_WIDTH) + con[which].outPos = 0; + break; + case '\n': + sendme(which, "\n\r", 2); + con[which].outPos = 0; + break; + case '\033': + con[which].outPos -= 3; + default: + sendme(which, str, 1); + } + str++; + } + } + return 0; } /* -- cgit v1.2.3