aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/network.c
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2023-12-13 19:40:18 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2023-12-13 19:40:18 +0100
commitb849fc5ab8a31bd47d67a3d3f80b275e0f58d42a (patch)
tree66764719f8e51748e45b4dee527bfd9e3419c6f8 /FICS/network.c
parent6f230a2c8abdc14dc11f8b2b0512f1e876cc2673 (diff)
Reformatted net_send_string()
Diffstat (limited to 'FICS/network.c')
-rw-r--r--FICS/network.c105
1 files 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;
}
/*