My pretty neat website
git clone git://soophie.de/soso
blob: 3f0b9ad29930c398b504c275fab6182f81a63401 (2905 bytes)[raw]
1
% #include "src/duc_macro.h" %2
% #include "src/module/git_repo.h" %3
% #include "src/module/git_repo_blob.h" %4
% #include <math.h> %6
% DUC_TEMPLDEF(7
duc_git_repo_blob,8
git_repo_t *repo;9
git_repo_blob_t *blob;10
bool is_markdown;11
bool is_raw;12
) %14
% if (ctx->is_markdown) { %15
<div class="blob--markdown">% MARKDOWN(ctx->blob->content) %</div>16
% } else if (ctx->is_raw) {17
DUC_CLEAR()18
BINARY(ctx->blob->content, ctx->blob->size)19
return;20
} else { %21
<div class="blob">22
<pre class="blob--meta"><span>blob: % STRING(ctx->blob->oid) % (% NUMBER(ctx->blob->size) % bytes)</span><a class="link--raw" href="/git/% STRING(ctx->repo->meta.name) %/raw?oid=% STRING(ctx->repo->flag_oid) %">[raw]</a></pre>23
% if (ctx->blob->is_binary) { %24
<pre class="blob--code"><span class="blob--binary">Binary file: <a href="/git/% STRING(ctx->repo->meta.name) %/raw?oid=% STRING(ctx->repo->flag_oid) %">[view raw]</p></span></pre>25
% } else { %26
<pre class="blob--code">%28
size_t len = strlen(ctx->blob->content);29
size_t i = 0;30
size_t ln = 0;31
size_t sol = 0;32
while (i < len) {33
char c = ctx->blob->content[i];34
if (c == '\n') {35
ln++;36
}37
i++;38
}39
size_t pad = floor(log10(ln + 1)) + 1;40
i = 0;41
ln = 0;42
sol = 0;43
size_t df = 0;44
bool is_meta = false;45
while (i < len) {46
char c = ctx->blob->content[i];47
if (c == '\n') {48
size_t ln_len = i - sol;49
char line[ln_len + 1];50
memcpy(line, ctx->blob->content + sol, ln_len);51
line[ln_len] = '\0';52
sol = i + 1;53
bool is_diff = strncmp(line, "diff --git", 10) == 0;54
bool is_hunk = strncmp(line, "@@ ", 3) == 0;55
if (is_diff) {56
is_meta = true;57
}58
if (is_diff && ln != 0) {59
df++;60
%</pre>%61
%<pre class="diff--meta">%62
}63
if (is_hunk && is_meta) {64
is_meta = false;65
ln = 0;66
%</pre>%67
%<pre class="diff--code">%68
}69
if (is_meta) {70
%<p>%STRING(line)%</p>%71
}72
else {73
%<p id="% NUMBER(ln + 1) %" class="% if (is_hunk) { %is-hunk% } % % if (strncmp(line, "+", 1) == 0 && strncmp(line, "+++", 3) != 0) { %is-add% } % % if (strncmp(line, "-", 1) == 0 && strncmp(line, "---", 3) != 0) { %is-rem% } %"><span class="ln"><a href="#% NUMBER(ln + 1) %">% PRINTF("%%*ld", pad, ln + 1) %</a></span><span class="line"><code>% STRING(line) %</code></span></p>%74
}75
ln++;76
}77
i++;78
}79
%</pre>80
% } %81
</div>82
% } %84
% DUC_ENDTEMPL %