Text wraps in a terrible, horrible way
This commit is contained in:
		
							parent
							
								
									b994cb895d
								
							
						
					
					
						commit
						3ab709d1c5
					
				| @ -3,6 +3,7 @@ | ||||
| 
 | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
| #include <stdio.h> | ||||
| 
 | ||||
| void draw_log(Log* log) { | ||||
|   for(int line_num = 0; line_num < log->line_count; line_num++) { | ||||
| @ -23,11 +24,21 @@ Log *create_log(void) { | ||||
|   return log; | ||||
| } | ||||
| 
 | ||||
| #define MAX(a, b) a > b ? a : b | ||||
| #define MIN(a, b) a < b ? a : b | ||||
| #define LINE_LENGTH 60 | ||||
| 
 | ||||
| void push_line_to_log(Log* log, char* line) { | ||||
|   int line_length = MIN(strlen(line), LINE_LENGTH); | ||||
|   log->lines = realloc(log->lines, (log->line_count + 1) * sizeof(char*)); | ||||
|   log->lines[log->line_count] = malloc(line_length + 1); | ||||
|   memcpy(log->lines[log->line_count], line, line_length); | ||||
|   log->lines[log->line_count][line_length] = '\0'; | ||||
|   log->line_count++; | ||||
|   log->lines = realloc(log->lines, log->line_count * sizeof(char*)); | ||||
|   log->lines[log->line_count - 1] = malloc(strlen(line) + 1); | ||||
|   strcpy(log->lines[log->line_count - 1], line); | ||||
| 
 | ||||
|   if (strlen(line) > LINE_LENGTH) { | ||||
|     push_line_to_log(log, line + LINE_LENGTH); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| void free_log(Log* log) { | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user