selective and recursive loc counter in C
Find a file
2026-01-11 15:00:12 +01:00
src pattern search inside files 2026-01-11 13:32:52 +01:00
.gitignore first commit 2026-01-09 14:05:35 +01:00
main.c special cased loc query result 2026-01-11 14:57:36 +01:00
README.md markdown 2026-01-11 15:00:12 +01:00

codectr

A tiny recursive code search & statistics tool by Smolware.

Public domain.

codectr is a small command line C utility to:

Recursively list files

Filter files using glob patterns

Search inside those files

Count lines and symbols, text patterns. Find pattern's line and column.

Simple, cross-platform, dependency-free (ANSI C + POSIX dirs).

Basic usage

codectr <path>
codectr <path> <file-glob>
codectr <path> <file-glob> <mode> <query>
Argument Meaning
path Root directory
file-glob Which files to scan
mode 0 = count, 1 = search
query What to look for inside files

Get the binary on itch

List all files

codectr ./

Recursively prints the directory tree starting at the current directory.

Example:

├─main.c
├─src
│ ├─lexer.h
│ ├─parser.h
│ └─vm.h

Selectively list files

codectr ./ *.c
codectr ./ *.c,*.h
codectr ./ *.?

Glob Pattern Operators Meaning

  • * any sequence

  • ? any single character

  • , OR operator

Examples:

Pattern Matches

*.c	all -> .c files

*.c,*.h	-> .c and .h files

file?.txt -> file1.txt, file2.txt ...

*.? -> all files with one-char extensions 

Count things inside files

codectr <path> <file-glob> <mode> <query>

This searches inside every matching file and counts how many times target appears.

Count lines of code:

codectr ./ *.c,*.h 0 \n

Counts lines in all .c and .h files.

Count specific chars:

codectr ./ *.c,*.h *;* 0 // count semi-colons

How pattern search works

Patterns are searched per line. Combined with the operators:

Counts lines containing 'if':

codectr ./ *.c 0 *if*

Counts lines starting with 'if':

codectr ./ *.c 0 if*

Counts lines ending with 'if':

codectr ./ *.c 0 *if

to really get the correct mental model, replace * by "any sequence of symbols":

*if -> "any sequence of symbols" + if

if* -> if + "any sequence of symbols"

*if* -> "any sequence of symbols" + if + "any sequence of symbols"

What it ignores

The tool automatically skips:

.

..

.git

.gitignore

*.exe

This prevents walking into repositories or binaries.

Examples

Count total C LOC in a project:

codectr ./ *.c,*.h \n

List all shader files:

codectr ./ *.vert,*.frag,*.glsl

Find how many TODOs exist:

codectr ./ *.c,*.h 0 *TODO*

Find locations (file: line:col) of TODOs:

codectr ./ *.c,*.h 1 *TODO*

Find how many statements:

codectr ./ *.c 0 *;*