Skip to content

Commit

Permalink
Add python detection and some utility macros to avoid repetition.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericonr committed Feb 22, 2021
1 parent 14cb4cb commit 35d6806
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lang.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,30 @@
enum lang_index {
c_lang,
//cpp_lang,
//python_lang,
python_lang,
//go_lang,
lang_index_n
};
static int c_lang_check(const char *, unsigned char);

struct lang_check {
int (*check)(const char *, unsigned char);
char display[8];
};

#define check_function(lang) lang##_lang_check
#define check_function_decl(lang) static int check_function(lang) (const char *s, unsigned char t)
#define struct_item(lang, d) [lang##_lang] = { .check = check_function(lang), .display = d }

check_function_decl(c);
check_function_decl(python);

const struct lang_check l[] = {
[c_lang] = { .check = c_lang_check, .display = " C" },
struct_item(c, " C"),
struct_item(python, " 🐍"),
};

#undef struct_item

/* bitmap of 1<<lang_index */
void print_lang(uint64_t mask) {
for (int i = 0; i < lang_index_n; i++) {
Expand Down Expand Up @@ -60,7 +69,15 @@ void *lang_thread(void *arg)

static inline int isfile(unsigned char t) { return t & (DT_REG | DT_LNK); }

static int c_lang_check(const char *s, unsigned char t)
check_function_decl(c)
{
return isfile(t) && !fnmatch("*.c", s, 0);
}

check_function_decl(python)
{
return isfile(t) && !fnmatch("*.py", s, 0);
}

#undef check_function
#undef check_function_decl

0 comments on commit 35d6806

Please sign in to comment.