- C 100%
| src | ||
| .gitignore | ||
| main.c | ||
| README.md | ||
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 *;*