Skip to content

Commit

Permalink
new: only enable syntax highlighting when file is C/C++
Browse files Browse the repository at this point in the history
  • Loading branch information
ikozyris committed Jul 27, 2024
1 parent ef7ef56 commit 8e84b6a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions headers/funcdecl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
long whereis(const char *, char);
1 change: 1 addition & 0 deletions headers/headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
#include <sys/stat.h> // for file size
#include <list>
#include <time.h>
#include "funcdecl.h"
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ int main(int argc, char *argv[])
goto loop;
}

eligible = isc(argv[1]);
if (argc > 2 && (strcmp(argv[2], "-ro") == 0 ||
strcmp(argv[2], "--read-only") == 0)) {
read_fread_sl(fi);
Expand Down
15 changes: 15 additions & 0 deletions utils/highlight.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#include "init.c"

bool eligible;

bool isc(const char *str)
{
long res = whereis(str, '.');
if (res == -1)
return false;
str += res;
if (!strcmp(str, "c") || !strcmp(str, "cpp") || !strcmp(str, "cc"))
return true;
return false;
}

const char *types[] = {"int", "char", "float", "double", "unsigned", "void", "const",
"size_t", "bool", "signed", "long", "enum", "static", "short", "extern"};
const char *defs[] = {"if", "else", "while", "for", "do", "return", "sizeof", "switch",
Expand Down Expand Up @@ -69,6 +82,8 @@ char str[256];

void apply(unsigned line)
{
if (!eligible)
return;
winwstr(text_win, tmp);
unsigned len2 = wcstombs(str, tmp, 256);
unsigned previ = 0;
Expand Down

0 comments on commit 8e84b6a

Please sign in to comment.