Append "# reformatted" to up to max_files .py files in subdir (cross-platform). */
| 78 | |
| 79 | /* Append "# reformatted" to up to max_files .py files in subdir (cross-platform). */ |
| 80 | static int reformat_files(const char *subdir, int max_files) { |
| 81 | char dir[512]; |
| 82 | snprintf(dir, sizeof(dir), "%s/%s", g_repodir, subdir); |
| 83 | cbm_dir_t *d = cbm_opendir(dir); |
| 84 | if (!d) { |
| 85 | return -1; |
| 86 | } |
| 87 | cbm_dirent_t *entry; |
| 88 | int count = 0; |
| 89 | while ((entry = cbm_readdir(d)) != NULL && count < max_files) { |
| 90 | size_t nlen = strlen(entry->name); |
| 91 | if (nlen < 4 || strcmp(entry->name + nlen - 3, ".py") != 0) { |
| 92 | continue; |
| 93 | } |
| 94 | if (entry->is_dir) { |
| 95 | continue; |
| 96 | } |
| 97 | char path[1024]; |
| 98 | snprintf(path, sizeof(path), "%s/%s", dir, entry->name); |
| 99 | th_append_file(path, "# reformatted\n"); |
| 100 | count++; |
| 101 | } |
| 102 | cbm_closedir(d); |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | static char *index_repo(void) { |
| 107 | char args[512]; |
no test coverage detected