stagit

Stagit fork with syntax colouring
Log | Files | Refs | README | LICENSE

commit 151623731afd25a6259f4023054c850e20075ee2
parent 36afc955e2db58a4737a61dcdec7dece04a0ca73
Author: citbl <citbl@citbl.org>
Date:   Thu, 25 Jun 2026 16:54:18 +1000

add support for enforcing ada

Diffstat:
M.gitignore | 2++
Mstagit.c | 30+++++++++++++++++++++++++++---
2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,3 +1,5 @@ .DS_Store *.o output/ +stagit +stagit-index diff --git a/stagit.c b/stagit.c @@ -542,14 +542,38 @@ writefooter(FILE *fp) { fputs("</div>\n</body>\n<script>hljs.highlightAll();</script>\n</html>\n", fp); } +int +endswith(const char *string, const char *match) { + string = strrchr(string, '.'); + + if (string != NULL) { + int pos = strcmp(string, match); + if (pos == 0) return 1; + } + + return 0; +} + size_t -writeblobhtml(FILE *fp, const git_blob *blob) { +writeblobhtml(FILE *fp, const char *filename, const git_blob *blob) { + char *highlighting_class = ""; + char html_head[128] = {0}; size_t n = 0, i, len, prev; /* const char *nfmt = "<a href=\"#l%zu\" class=\"line\" style=\"color=darkgray\" id=\"l%zu\">%7zu</a> "; */ const char *s = git_blob_rawcontent(blob); + if (endswith(filename, ".ads") || endswith(filename, ".adb")) { + highlighting_class = "language-ada"; + } else if (endswith(filename, ".c") || endswith(filename, ".h")) { + highlighting_class = "language-c"; + } + + snprintf(html_head, 40 + strlen(highlighting_class), "<pre id=\"blob\"><code class=\"%s\">\n", highlighting_class); + len = git_blob_rawsize(blob); - fputs("<pre id=\"blob\"><code>\n", fp); + + // write the html header + fputs(html_head, fp); if (len > 0) { for (i = 0, prev = 0; i < len; i++) { @@ -959,7 +983,7 @@ writeblob(git_object *obj, const char *fpath, const char *filename, size_t files if (git_blob_is_binary((git_blob *)obj)) fputs("<p>Binary file.</p>\n", fp); else - lc = writeblobhtml(fp, (git_blob *)obj); + lc = writeblobhtml(fp, filename, (git_blob *)obj); writefooter(fp); checkfileerror(fp, fpath, 'w');