-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLines.h
51 lines (36 loc) · 1.61 KB
/
Lines.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef LINES_H
#define LINES_H
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
typedef struct {
char** lines;
uint32_t no_lines;
uint32_t* lines_len;
} Lines;
// dissectLines dissects buffer of chars into separate lines
// and stores them along with other information in struct Lines
Lines* dissectLines(char* buffer_ptr, uint32_t buffer_len);
// freeLines frees allocated memory in Lines* struct
void freeLines(Lines* lines_ptr);
// insertLines inserts line_n of empty lines at index in the lines_ptr
// initializes each line with n of empty characters
bool insertLines(Lines* lines_ptr, uint32_t index, uint32_t line_n, uint32_t n);
// appendLines appends line_n of empty lines at the end of the lines buffer
// initializes each line with n of empty characters
bool appendLines(Lines* lines_ptr, uint32_t line_n, uint32_t n);
// INSTEAD OF USING _expandLines USE insertLines or appendLines
// _expandLines expands number of lines in lines_ptr
bool _expandLines(Lines* lines_ptr, uint32_t line_n);
// INSTEAD OF USING _makeLines USE insertLines or appendLines
// _makeLines creates n lines starting at index and fills them with n ' ' chars
bool _makeLines(Lines* lines_ptr, uint32_t index, uint32_t line_n, uint32_t n);
// saveToFile saves lines_ptr's buffer to a given path
bool saveToFile(Lines* lines_ptr, char* filename);
// printToStderr prints lines_ptr's buffer to stderr
#define printToStderr(LINES_PTR) _pushLines(LINES_PTR, stderr, true)
// _pushLines pushes lines_ptr's buffer to out
void _pushLines(Lines* lines_ptr, FILE* out, bool show_info);
#endif