| 8847 | /* ── Architecture aspect implementations ───────────────────────── */ |
| 8848 | |
| 8849 | static int arch_languages(cbm_store_t *s, const char *project, const char *path, |
| 8850 | cbm_architecture_info_t *out) { |
| 8851 | char norm[CBM_SZ_512]; |
| 8852 | char like[CBM_SZ_512]; |
| 8853 | bool scoped = arch_path_prepare(path, norm, sizeof(norm), like, sizeof(like)); |
| 8854 | char sqlbuf[ST_SQL_BUF]; |
| 8855 | const char *base = "SELECT file_path FROM nodes WHERE project=?1 AND label='File'"; |
| 8856 | if (scoped) { |
| 8857 | snprintf(sqlbuf, sizeof(sqlbuf), "%s%s", base, arch_path_scope_sql()); |
| 8858 | } else { |
| 8859 | snprintf(sqlbuf, sizeof(sqlbuf), "%s", base); |
| 8860 | } |
| 8861 | sqlite3_stmt *stmt = NULL; |
| 8862 | if (sqlite3_prepare_v2(s->db, sqlbuf, CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK) { |
| 8863 | store_set_error_sqlite(s, "arch_languages"); |
| 8864 | return CBM_STORE_ERR; |
| 8865 | } |
| 8866 | bind_text(stmt, SKIP_ONE, project); |
| 8867 | if (scoped) { |
| 8868 | arch_bind_path_scope(stmt, ST_COL_2, ST_COL_3, norm, like); |
| 8869 | } |
| 8870 | |
| 8871 | /* Count per language using a simple parallel array */ |
| 8872 | const char *lang_names[CBM_SZ_64]; |
| 8873 | int lang_counts[CBM_SZ_64]; |
| 8874 | int nlang = 0; |
| 8875 | |
| 8876 | int scan_rc20; |
| 8877 | while ((scan_rc20 = sqlite3_step(stmt)) == SQLITE_ROW) { |
| 8878 | const char *fp = (const char *)sqlite3_column_text(stmt, 0); |
| 8879 | const char *ext = file_ext(fp); |
| 8880 | const char *lang = ext_to_lang(ext); |
| 8881 | if (!lang) { |
| 8882 | continue; |
| 8883 | } |
| 8884 | int found = ST_FOUND; |
| 8885 | for (int i = 0; i < nlang; i++) { |
| 8886 | if (strcmp(lang_names[i], lang) == 0) { |
| 8887 | found = i; |
| 8888 | break; |
| 8889 | } |
| 8890 | } |
| 8891 | if (found >= 0) { |
| 8892 | lang_counts[found]++; |
| 8893 | } else if (nlang < CBM_SZ_64) { |
| 8894 | lang_names[nlang] = lang; |
| 8895 | lang_counts[nlang] = SKIP_ONE; |
| 8896 | nlang++; |
| 8897 | } |
| 8898 | } |
| 8899 | if (scan_rc20 != SQLITE_DONE) { /* SCANCHK:20:stmt */ |
| 8900 | store_set_error_sqlite(s, "row scan aborted"); |
| 8901 | sqlite3_finalize(stmt); |
| 8902 | return CBM_STORE_ERR; |
| 8903 | } |
| 8904 | sqlite3_finalize(stmt); |
| 8905 | |
| 8906 | /* Sort by count descending (simple insertion sort) */ |
no test coverage detected