|
|
|
@ -9,6 +9,8 @@
@@ -9,6 +9,8 @@
|
|
|
|
|
#include "cosmopolitan.h" |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
int replace_tabs(char **rtext);
|
|
|
|
|
|
|
|
|
|
int read_file(FILE* in, char **out) { |
|
|
|
|
int size_of_buffer = 20; |
|
|
|
|
char *buffer = calloc(size_of_buffer, sizeof(char)); |
|
|
|
@ -127,8 +129,9 @@ char *read_stdin(void) {
@@ -127,8 +129,9 @@ char *read_stdin(void) {
|
|
|
|
|
return NULL; |
|
|
|
|
} else { |
|
|
|
|
strip_excess_char(&text, '\n'); |
|
|
|
|
strip_excess_char(&text, '\t'); |
|
|
|
|
strip_excess_char(&text, ' '); |
|
|
|
|
replace_tabs(&text); |
|
|
|
|
//strip_excess_char(&text, '\t');
|
|
|
|
|
//strip_excess_char(&text, ' ');
|
|
|
|
|
strip_tailing_whitespace(text); |
|
|
|
|
return text; |
|
|
|
|
} |
|
|
|
@ -163,7 +166,7 @@ void insert_char(char **str, char c, int p) {
@@ -163,7 +166,7 @@ void insert_char(char **str, char c, int p) {
|
|
|
|
|
void wrap_text(char *text, int width) { |
|
|
|
|
|
|
|
|
|
char *last_break = NULL; |
|
|
|
|
int current_line = 0; |
|
|
|
|
int current_line = 1; |
|
|
|
|
int last_break_pos = 0; |
|
|
|
|
|
|
|
|
|
for (int i = 0; text[i] != '\0'; i++) { |
|
|
|
@ -174,8 +177,6 @@ void wrap_text(char *text, int width) {
@@ -174,8 +177,6 @@ void wrap_text(char *text, int width) {
|
|
|
|
|
current_line = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *breaks = "\t "; |
|
|
|
|
|
|
|
|
|
// set whitespace to be break point
|
|
|
|
|
if ((text[i] == ' ') && current_line <= width + 2) { |
|
|
|
|
last_break_pos = current_line; |
|
|
|
@ -188,6 +189,7 @@ void wrap_text(char *text, int width) {
@@ -188,6 +189,7 @@ void wrap_text(char *text, int width) {
|
|
|
|
|
last_break = NULL; |
|
|
|
|
current_line = 0; |
|
|
|
|
} else if (current_line > width + 1) { |
|
|
|
|
// normal break
|
|
|
|
|
*last_break = '\n'; |
|
|
|
|
last_break = NULL; |
|
|
|
|
current_line = current_line - last_break_pos; |
|
|
|
@ -292,6 +294,10 @@ int replace_tabs(char **rtext) {
@@ -292,6 +294,10 @@ int replace_tabs(char **rtext) {
|
|
|
|
|
tab = strstr(tab, "\t"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (numtabs == 0) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
len += 3 * numtabs; |
|
|
|
|
char * result = malloc(len); |
|
|
|
|
|
|
|
|
|