|
|
|
@ -1,7 +1,13 @@
@@ -1,7 +1,13 @@
|
|
|
|
|
#ifndef COSMOPOLITAN |
|
|
|
|
#include <stdio.h> |
|
|
|
|
#include <string.h> |
|
|
|
|
#include <stdbool.h> |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifdef COSMOPOLITAN |
|
|
|
|
#include "cosmopolitan.h" |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
int read_file(FILE* in, char **out) { |
|
|
|
|
int size_of_buffer = 20; |
|
|
|
@ -274,6 +280,39 @@ void print_single_line_bubble(char *text, int len) {
@@ -274,6 +280,39 @@ void print_single_line_bubble(char *text, int len) {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int replace_tabs(char **rtext) { |
|
|
|
|
char *text = *rtext; |
|
|
|
|
size_t len = strlen(text); |
|
|
|
|
|
|
|
|
|
char *tab = strstr(text, "\t"); |
|
|
|
|
int numtabs = 0; |
|
|
|
|
|
|
|
|
|
while (tab != NULL) { |
|
|
|
|
numtabs++; |
|
|
|
|
tab = strstr(tab, "\t"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
len += 3 * numtabs; |
|
|
|
|
char * result = malloc(len); |
|
|
|
|
|
|
|
|
|
int resulti = 0; |
|
|
|
|
for (int i = 0; i < len; i++) { |
|
|
|
|
if (text[i] == '\t') { |
|
|
|
|
for (int j = 0; j < 4; j++) { |
|
|
|
|
result[resulti++] = ' '; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
result[resulti++] = text[i]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
free(text); |
|
|
|
|
*rtext = result; |
|
|
|
|
|
|
|
|
|
return numtabs; |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
void print_speech(char *text, int width) { |
|
|
|
|
|
|
|
|
|
int len = strlen(text); |
|
|
|
@ -284,6 +323,7 @@ void print_speech(char *text, int width) {
@@ -284,6 +323,7 @@ void print_speech(char *text, int width) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
width -= 2; // for margins
|
|
|
|
|
|
|
|
|
|
wrap_text(text, width); |
|
|
|
|
|
|
|
|
|
int line_count = 0; |
|
|
|
|