diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 22:43:38 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 22:43:38 +0100 |
| commit | d6d9cb137d1f0f75fd68381ec699f76b518061d5 (patch) | |
| tree | ba482b3cfc1b2a75b832a9bcb2ee52b4bf51394c | |
| parent | 5d8dfe892a2ea89f706ee140c3bdcfd89fe03fda (diff) | |
| download | crep-d6d9cb137d1f0f75fd68381ec699f76b518061d5.tar.gz | |
Enable single file processing
| -rw-r--r-- | list.c | 14 | ||||
| -rw-r--r-- | main.c | 6 |
2 files changed, 15 insertions, 5 deletions
@@ -23,6 +23,17 @@ void add_file_path(Node **head, char *file_path) { } void list_files_recursively(char *base_path, Node **head) { + struct stat statbuf; + if (stat(base_path, &statbuf) == -1) { + perror("stat"); + return; + } + + if (S_ISREG(statbuf.st_mode)) { + add_file_path(head, base_path); + return; + } + char path[2048]; struct dirent *dp; DIR *dir = opendir(base_path); @@ -39,11 +50,10 @@ void list_files_recursively(char *base_path, Node **head) { continue; } - struct stat statbuf; if (stat(path, &statbuf) != -1) { if (S_ISDIR(statbuf.st_mode)) { list_files_recursively(path, head); - } else { + } else if (S_ISREG(statbuf.st_mode)) { add_file_path(head, path); } } @@ -177,13 +177,13 @@ const char *get_file_extension(const char *file_path) { } int main(int argc, char *argv[]) { - if (argc < 3) { - printf("Usage: %s <search term> <directory>\n", argv[0]); + if (argc < 2) { + printf("Usage: %s <search term> [directory|file]\n", argv[0]); return 1; } const char *cfname = argv[1]; - char *directory = argv[2]; + char *directory = (argc > 2) ? argv[2] : "."; TSLanguage *tree_sitter_c(void); TSLanguage *tree_sitter_python(void); |
