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