-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreamble.c
More file actions
134 lines (114 loc) · 3.51 KB
/
preamble.c
File metadata and controls
134 lines (114 loc) · 3.51 KB
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
#include "preamble.h"
static Preamble preamble;
void initPreamble()
{
preamble.containsStrikethroughs = false;
preamble.containsEnumerations = false;
preamble.containsImages = false;
preamble.containsLinks = false;
preamble.containsVerbatim = false;
}
void addStrikethroughsToPreamble()
{
preamble.containsStrikethroughs = true;
}
void addEnumToPreamble()
{
preamble.containsEnumerations = true;
}
void addImagesToPreamble()
{
preamble.containsImages = true;
}
void addLinksToPreamble()
{
preamble.containsLinks = true;
}
void addVerbatimToPreamble()
{
preamble.containsVerbatim = true;
}
void addLineToTitle(const char* newLine)
{
if (newLine != NULL)
{
if (preamble.title == NULL)
{
preamble.title = malloc( (strlen(newLine)+1)*sizeof(char) );
strcpy(preamble.title, newLine);
}
else
{
reallocate(&(preamble.title), strlen(preamble.title)+strlen(newLine)+3);
sprintf(preamble.title, "%s\\\\%s", preamble.title, newLine);
}
}
else
{
WARNING_FUNC("addLineToTitle", "Tried to add an empty line to title");
}
}
void addCommentToTitle(const char* newComment)
{
if (newComment != NULL || strcmp(newComment, "%") != 0 || strcmp(newComment, "% ") != 0)
{
if (preamble.titleComments == NULL)
{
preamble.titleComments = malloc( (strlen(newComment)+1)*sizeof(char) );
strcpy(preamble.titleComments, newComment);
}
else
{
reallocate(&(preamble.titleComments), strlen(preamble.titleComments)+strlen(newComment)+2);
sprintf(preamble.titleComments, "%s\n%s", preamble.titleComments, newComment);
}
}
else
{
WARNING_FUNC("addCommentToTitle", "Tried to add an empty comment to the title");
}
}
int insertPreamble(FILE* tmpBodyOutputFile, FILE* outputFile)
{
fputs("\\documentclass{article}\n\n", outputFile);
fputs("\\usepackage[francais]{babel}\n", outputFile);
fputs("\\usepackage[utf8]{inputenc}\n", outputFile);
fputs("\\usepackage[T1]{fontenc}\n\n", outputFile);
if (preamble.containsStrikethroughs)
fputs("\\usepackage[normalem]{ulem}\n", outputFile);
if (preamble.containsEnumerations)
fputs("\\usepackage{enumitem}\n", outputFile);
if (preamble.containsImages)
fputs("\\usepackage{graphicx}\n", outputFile);
if (preamble.containsLinks)
fputs("\\usepackage{hyperref}\n", outputFile);
if (preamble.containsVerbatim)
fputs("\\usepackage{spverbatim}\n", outputFile);
fputs("\\usepackage{textcomp}\n", outputFile);
fputs("\\usepackage[hscale=0.73,vscale=0.82]{geometry}\n", outputFile);
fputs("\\renewcommand*{\\familydefault}{\\sfdefault}\n\n", outputFile);
if (preamble.title != NULL)
fprintf(outputFile, "\\title{%s}\n", preamble.title);
else
fputs("\\title{}\n", outputFile);
fputs("\\author{}\n", outputFile);
fputs("\\date{}\n", outputFile);
if (preamble.titleComments != NULL)
fprintf(outputFile, "%s\n", preamble.titleComments);
fputs("\n", outputFile);
//copy file tmpBodyOutputFile to outputFile
if (fseek(tmpBodyOutputFile, SEEK_SET, 0) != 0)
{
ERROR_MSG("insertPreamble", "Couldn't get to the beginning of the temporary output file");
return RETURN_FAILURE;
}
char currentLine[FGETS_LINE_LENGTH];
while(fgets(currentLine, FGETS_LINE_LENGTH, tmpBodyOutputFile) != NULL)
fputs(currentLine, outputFile);
return RETURN_SUCCESS;
}
void freePreamble()
{
if (preamble.title != NULL)
free(preamble.title);
}