Added word wrap and fixed a bunch of bugs in FSE

This commit is contained in:
Andrew Pamment 2016-12-03 20:21:54 +10:00
parent 2901e6cd72
commit 076534efed

View File

@ -42,6 +42,7 @@ char *message_editor() {
int *q_lines; int *q_lines;
int q_line_count; int q_line_count;
int q_unquote; int q_unquote;
int z;
position_x = 0; position_x = 0;
position_y = 0; position_y = 0;
@ -152,7 +153,7 @@ char *message_editor() {
} }
} }
} else if (ch.EventType == EVENT_CHARACTER) { } else if (ch.EventType == EVENT_CHARACTER) {
if (ch.chKeyPress == '\r' || strlen(line) == 78) { if (ch.chKeyPress == '\r' || strlen(line) >= 78) {
if (strcasecmp(line, "/S") == 0) { if (strcasecmp(line, "/S") == 0) {
// save message // save message
body_len = 0; body_len = 0;
@ -328,59 +329,140 @@ char *message_editor() {
memset(line, 0, 81); memset(line, 0, 81);
} else { } else {
if (strlen(line) == 78) { if (strlen(line) >= 78) {
strncat(line, &ch.chKeyPress, 1); if (position_x == strlen(line)) {
position_x++; strncat(line, &ch.chKeyPress, 1);
} z = 1;
if (position_x < strlen(line)) {
// insert line
if (body_line_count == 0) {
body_lines = (char **)malloc(sizeof(char *));
} else { } else {
body_lines = (char **)realloc(body_lines, sizeof(char *) * (body_line_count + 1)); strncpy(line_cpy, line, position_x);
line_cpy[position_x] = '\0';
strncat(line_cpy, &ch.chKeyPress, 1);
strcat(line_cpy, &line[position_x]);
memset(line, 0, 81);
strcpy(line, line_cpy);
memset(line_cpy, 0, 81);
z = 0;
} }
for (i=body_line_count;i>position_y;i--) { for (i=strlen(line)-1;i>0;i--) {
body_lines[i] = body_lines[i-1]; if (line[i] == ' ') {
} line[i] = '\0';
body_line_count++; strcpy(line_cpy, &line[i+1]);
body_lines[i] = (char *)malloc(sizeof(char) * (position_x + 1)); if (body_line_count == 0) {
strncpy(body_lines[i], line, position_x); body_lines = (char **)malloc(sizeof(char *));
body_lines[i][position_x] = '\0'; } else {
strcpy(line_cpy, &line[position_x]); body_lines = (char **)realloc(body_lines, sizeof(char *) * (body_line_count + 1));
memset(line, 0, 81); }
strcpy(line, line_cpy); if (z == 1) {
memset(line_cpy, 0, 81); for (j=body_line_count;j>position_y;j--) {
body_lines[j] = body_lines[j-1];
}
body_line_count++;
body_lines[j] = strdup(line);
position_y++; position_y++;
if (position_y - top_of_screen > 20) { if (position_y - top_of_screen > 20) {
top_of_screen++; top_of_screen++;
} }
strcpy(line, line_cpy);
memset(line_cpy, 0, 81);
position_x = strlen(line);
} else {
if (strlen(body_lines[position_y]) + strlen(line_cpy) + 1 <= 78) {
strcat(line_cpy, " ");
strcat(line_cpy, body_lines[position_y]);
free(body_lines[position_y]);
body_lines[position_y] = strdup(line_cpy);
memset(line_cpy, 0, 81);
position_x++;
} else {
for (j=body_line_count;j>position_y;j--) {
body_lines[j] = body_lines[j-1];
}
body_line_count++;
body_lines[j] = strdup(line_cpy);
memset(line_cpy, 0, 81);
position_x++;
}
}
break;
}
}
if (i==0) {
position_x++;
if (body_line_count == 0) {
body_lines = (char **)malloc(sizeof(char *));
} else {
body_lines = (char **)realloc(body_lines, sizeof(char *) * (body_line_count + 1));
}
for (i=body_line_count;i>position_y;i--) {
body_lines[i] = body_lines[i-1];
}
body_line_count++;
body_lines[i] = strdup(line);
if (z == 1) {
position_y++;
if (position_y - top_of_screen > 20) {
top_of_screen++;
}
position_x = 0;
}
memset(line, 0, 81);
}
} else { } else {
if (body_line_count == 0) {
body_lines = (char **)malloc(sizeof(char *)); if (position_x < strlen(line)) {
// insert line
if (body_line_count == 0) {
body_lines = (char **)malloc(sizeof(char *));
} else {
body_lines = (char **)realloc(body_lines, sizeof(char *) * (body_line_count + 1));
}
for (i=body_line_count;i>position_y;i--) {
body_lines[i] = body_lines[i-1];
}
body_line_count++;
body_lines[i] = (char *)malloc(sizeof(char) * (position_x + 1));
strncpy(body_lines[i], line, position_x);
body_lines[i][position_x] = '\0';
strcpy(line_cpy, &line[position_x]);
memset(line, 0, 81);
strcpy(line, line_cpy);
memset(line_cpy, 0, 81);
position_y++;
if (position_y - top_of_screen > 20) {
top_of_screen++;
}
} else { } else {
body_lines = (char **)realloc(body_lines, sizeof(char *) * (body_line_count + 1)); if (body_line_count == 0) {
} body_lines = (char **)malloc(sizeof(char *));
} else {
body_lines = (char **)realloc(body_lines, sizeof(char *) * (body_line_count + 1));
}
for (i=body_line_count;i>position_y;i--) { for (i=body_line_count;i>position_y;i--) {
body_lines[i] = body_lines[i-1]; body_lines[i] = body_lines[i-1];
} }
body_line_count++; body_line_count++;
body_lines[i] = strdup(line); body_lines[i] = strdup(line);
position_y++; position_y++;
if (position_y - top_of_screen > 20) { if (position_y - top_of_screen > 20) {
top_of_screen++; top_of_screen++;
}
position_x = 0;
memset(line, 0, 81);
} }
position_x = 0;
memset(line, 0, 81);
} }
od_set_cursor(3, 1); od_set_cursor(3, 1);
for (i=top_of_screen;i<position_y;i++) { for (i=top_of_screen;i<position_y;i++) {
@ -406,16 +488,19 @@ char *message_editor() {
} else { } else {
if (position_x >= strlen(line)) { if (position_x >= strlen(line)) {
strncpy(line_cpy, line, strlen(line) - 1); strncpy(line_cpy, line, strlen(line) - 1);
line_cpy[strlen(line) - 1] = '\0';
memset(line, 0, 81); memset(line, 0, 81);
strcpy(line, line_cpy); strcpy(line, line_cpy);
memset(line_cpy, 0, 81); memset(line_cpy, 0, 81);
position_x--; position_x--;
} else { } else {
strncpy(line_cpy, line, position_x -1); strncpy(line_cpy, line, position_x -1);
line_cpy[position_x - 1] = '\0';
strcat(line_cpy, &line[position_x]);
strcpy(line, line_cpy); strcpy(line, line_cpy);
memset(line_cpy, 0, 81); memset(line_cpy, 0, 81);
position_x--; position_x--;
strcat(line_cpy, &line[position_x]);
} }
} }
} else { } else {
@ -423,6 +508,7 @@ char *message_editor() {
strncat(line, &ch.chKeyPress, 1); strncat(line, &ch.chKeyPress, 1);
} else { } else {
strncpy(line_cpy, line, position_x); strncpy(line_cpy, line, position_x);
line_cpy[position_x] = '\0';
strncat(line_cpy, &ch.chKeyPress, 1); strncat(line_cpy, &ch.chKeyPress, 1);
strcat(line_cpy, &line[position_x]); strcat(line_cpy, &line[position_x]);
memset(line, 0, 81); memset(line, 0, 81);