-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompiler.h
280 lines (237 loc) · 8.43 KB
/
compiler.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#ifndef _COMPILER_H_
#define _COMPILER_H_
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <libgen.h>
#include <unistd.h>
#include "error.h"
#include "preamble.h"
#include "usefulFunctions.h"
#include "pile.h"
#include "files.h"
#define MD_WARNING(lineNb, msg) if (lineNb <= 0) \
printf("WARNING (no line specified) :\n\t%s\n", msg); \
else \
printf("WARNING (line %d) :\n\t%s\n", lineNb, msg);
#define MD_ERROR(lineNb, msg) if (lineNb <= 0) \
printf("ERROR (no line specified) :\n\t%s\n", msg); \
else \
printf("ERROR (line %d) :\n\t%s\n", lineNb, msg);
/*
* Opens and closes files and create temporary file.
* Deletes temporary file.
* Calls translateLineByLine and insertPreamble
* @return : RETURN_SUCCESS if everything worked fine
* RETURN_FAILURE if there was a problem with files or translation
*/
STATUS compile(const char* inputFileName, const char* outputFileName, bool keepTmpFile);
/*
* Translates each line of the input file to bodyOutputFile
*/
STATUS translateLineByLine(FILE* bodyOutputFile);
/*
* Translate the line to bodyOutputFile
* If there's need to interpret several lines at once, it calls getNextLineFromFile
*/
STATUS interpretLine(FILE* bodyOutputFile, const char* line);
/*
* @return : a string containing the next unread line of the input file
* NULL if the input file as been entirely read
* @post : the string return MUST be freed
*/
char* getNextLineFromFile();
/*
* @return : number of spaces at the beginning of the line
*/
unsigned short getIndentation(const char* line);
/*
* @return : a string containing the useful part of a line containing the name of a new section
* (thus comments, spaces and hashtags are remmoved)
* @post : the string returned MUST be freed
*/
char* getTitleOfPart(const char* line);
/*
* @return : the index of the part of line where the comment begins (the '%')
* -1 if no comment was found
* @post : DO NOT FREE the string returned
*/
int getFirstIndexOfComment(const char* line);
/*
* Removes useless spaces in string (the string changes), in general there are spaces there because there is a comment afterwards in the input
*/
void removeUselessSpaces(char* string);
/*
* @return : true if the useful part of line is a '['
* false if it isn't
*/
bool isMultilinePlainTextOpeningTag(const char* line);
/*
* same than the function described right above but for closgin tag ']'
*/
bool isMultilinePlainTextClosingTag(const char* line);
/*
* @return : true if the line is in the form "<img image.png [label] [width:height]>"
* false otherwise
*/
bool isImageLine(const char* line);
/*
* writes nbAlinea tabulations to file
*/
void writeAlinea(FILE* file);
/*
* @pre : line must be a valid line characterizing an image file
* @return : the name (or path) of the image
* NULL if there was a problem
* @post : the returned value MUST be freed
*/
char* pickImageFileName(const char* line);
/*
* @pre : line must be a valid line characterizing an image inclusion
* @return : a string containing the caption of the image
* NULL if no label was found
* @post : the returned value MUST be freed
*/
char* pickImageLabel(const char* line);
/*
* @return : true if the line contains '|' not in a comment
* false otherwise
*/
bool containsImageSize(const char* line);
/*
* @pre : line must contain a size tag
* @return : true if the size tag doesn't contain ':'
* false otherwise
*/
bool containsImageScale(const char* line);
/*
* @pre : line must contain the scale of the image
* @return : a double containing the scale of the image
* -1.0 if there was an error
*/
double getImageScale(const char* line);
/*
* @pre : line must contain the width of the image
* @return : a string containing the width and unit of the width of the image
* "/" if it wasn't specified
* NULL if it wasn't found
* @post : the string returned MUST be freed
*/
char* getImageWidth(const char* line);
/*
* @pre : line must contain the height of the image
* @return : a string containing the height and unit of the height of the image
* "/" if it wasn't specified
* NULL if it wasn't found
* @post : the string returned MUST be freed
*/
char* getImageHeight(const char* line);
/*
* @return : a pointer to the pipe that specifies the beginning of the image size
* NULL if it wasn't found (which shouldn't happen)
* @post : the pointer MUST NOT be freed
*/
char* getPointerToImageSizeTag(const char* line);
/*
* @return : length of the number in base 10
*/
unsigned int getNbLength(long nb);
/*
* @pre : firstURLIndex must be the index in line pointing to the 'h' of "http"
* @return : a string containing the url
* NULL if there was a problem
* @post : the string returned MUST be freed
*/
char* pickURL(const char* line, unsigned int firstURLIndex);
/*
* @pre : firstURLIndex must be the index in line pointing to the 'h' of "http"
* @return : a string containing the label that will link to the url
* NULL if no label was found
* @post : the string (not NULL) returned MUST be freed
*/
char* pickURLLabel(const char* line, unsigned int firstURLIndex);
/*
* @return : true if the line begins in "+ " or "+\t"
* false otherwise
*/
bool isItemizeLine(const char* line);
/*
* @return : a string containing an item from a list
* NULL if there was a problem
* @post : the string returned MUST be freed
*/
char* pickItemFromItemize(const char* line);
/*
* Detects and writes an itemize to bodyOutputFile
* @pre : line must be an itemize line
*/
void writeItemize(FILE* bodyOutputFile, const char* line);
/*
* Writes line as an itemize item in bodyOutputFile
* @pre : line MUST be an itemize line (see above)
*/
void writeItemizeItem(FILE* bodyOutputFile, const char* line);
/*
* @return : true if the line begins in form "l. " or "l.\t"
* false otherwise
*/
bool isEnumLine(const char* line);
/*
* Detects and writes an enumerate section to bodyOutputFile
* @pre : line MUST be an enumeration line, hence begin in "l. " or "l.\t" (see above)
*/
void writeEnumerate(FILE* bodyOutputFile, const char* line);
/*
* Writes line as an enumerate item in bodyOutputFile
* @pre : line MUST be an enumerate line (see above)
*/
void writeEnumerateItem(FILE* bodyOutputFile, const char* line);
/*
* @return : a string containing an item from an enumerate section
* NULL if there was a problem
* @post : the string returned MUST be freed
*/
char* pickItemFromEnumerate(const char* line);
/*
* @return : true if the line is an opening or closing line for a tabular environment (thus if the useful part of the line is only made off of equal signs)
* false otherwise
*/
bool isSimpleTableTagLine(const char* line);
/*
* Writes a simple table to bodyOutputFile
* Triggered when an opening line for tabular environments is detected
*/
void writeSimpleTable(FILE* bodyOutputFile);
/*
* @return : true if the first character of the useful part of the line is '|
* false otherwise'
*/
bool isSimpleTableCellsLine(const char* line);
/*
* @return : the number of lines for a simple table found in line
* 0 if the line isn't a simple table cell line
*/
unsigned char getNbSimpleTableColumns(const char* line);
/*
* @return : a string containing the content of the cell with index index (without the spaces around it)
* NULL if the content couldn't be found (wrong index)
* @post : the string returned MUST be freed
*/
char* getSimpleTableCellContent(const char* line, unsigned short index);
/*
* @return : true if the useful part of the line is made off of dashes
* false otherwise
*/
bool isSimpleTableHorizontalLine(const char* line);
/*
* Translates source (in markdown) to destination (in LaTeX)
* No plain text if isTitle == true
* @post : *destination MUST be freed
*/
void translateString(const char* source, char** destination, bool isTitle);
/*
* Translates string (in mardown) in LaTeX and writes it directly in the file bodyOutputFile
*/
void translateToFile(FILE* bodyOutputFile, const char* string);
#endif //_COMPILER_H_