150118.4 · d8a335ab6e33b08d5f222b7cadf8419ca5e605c7
Cleanup. Change a bunch of s to s because I'm lazy like that. Clang-format.
reading declarations
@@ -77,17 +77,17 @@ lang_spec_t langs[] = { { "yaml", { "yaml", "yml" } } }; -unsigned int get_lang_count() {+size_t get_lang_count() { return sizeof(langs) / sizeof(lang_spec_t); } -char *make_lang_regex(char* ext_array, unsigned int num_exts) {+char *make_lang_regex(char *ext_array, size_t num_exts) { int regex_capacity = 100; char *regex = ag_malloc(regex_capacity); int regex_length = 3; int subsequent = 0; char *extension;- unsigned int i;+ size_t i; strcpy(regex, "\\.("); @@ -113,35 +113,29 @@ char *make_lang_regex(char* ext_array, unsigned int num_exts) { return regex; } -unsigned int-combine_file_extensions(unsigned int* extension_index,- unsigned int len,- char** exts)-{+size_t combine_file_extensions(size_t *extension_index, size_t len, char **exts) { /* Keep it fixed as 100 for the reason that if you have more than 100 * file types to search, you'd better search all the files. * */- unsigned int ext_capacity = 100;- (*exts) = (char*)ag_malloc(ext_capacity * SINGLE_EXT_LEN);+ size_t ext_capacity = 100;+ (*exts) = (char *)ag_malloc(ext_capacity * SINGLE_EXT_LEN); memset((*exts), 0, ext_capacity * SINGLE_EXT_LEN);- unsigned int num_of_extensions= 0;+ size_t num_of_extensions = 0; - unsigned int i = 0;- for (; i < len; ++i) {- unsigned int j = 0;- const char* ext = langs[extension_index[i]].extensions[j];+ size_t i;+ for (i = 0; i < len; ++i) {+ size_t j = 0;+ const char *ext = langs[extension_index[i]].extensions[j]; do { if (num_of_extensions == ext_capacity) { break; }- char* pos = (*exts) + num_of_extensions * SINGLE_EXT_LEN;+ char *pos = (*exts) + num_of_extensions * SINGLE_EXT_LEN; strncpy(pos, ext, strlen(ext)); ++num_of_extensions; ext = langs[extension_index[i]].extensions[++j];- } while(ext);+ } while (ext); } return num_of_extensions; }--
@@ -14,7 +14,7 @@ extern lang_spec_t langs[]; /** Return the language count. */-unsigned int get_lang_count(void);+size_t get_lang_count(void); /** Convert a NULL-terminated array of language extensions@@ -22,7 +22,7 @@ into a regular expression of the form \.(extension1|extension2...)$ Caller is responsible for freeing the returned string. */-char *make_lang_regex(char *ext_array, unsigned int num_exts);+char *make_lang_regex(char *ext_array, size_t num_exts); /**@@ -32,8 +32,5 @@ The combined result is returned through *exts*; *exts* is one-dimension array, which can contain up to 100 extensions; The number of extensions that *exts* actually contain is returned. */-unsigned int-combine_file_extensions(unsigned int* extension_index,- unsigned int len,- char** exts);+size_t combine_file_extensions(size_t *extension_index, size_t len, char **exts); #endif
@@ -159,7 +159,7 @@ void cleanup_options(void) { void parse_options(int argc, char **argv, char **base_paths[], char **paths[]) { int ch;- unsigned int i;+ size_t i; int path_len = 0; int useless = 0; int group = 1;@@ -174,15 +174,15 @@ void parse_options(int argc, char **argv, char **base_paths[], char **paths[]) { int needs_query = 1; struct stat statbuf; int rv;- unsigned int lang_count;- unsigned int lang_num = 0;+ size_t lang_count;+ size_t lang_num = 0; size_t longopts_len, full_len; option_t *longopts; char *lang_regex = NULL;- unsigned int* ext_index = NULL;- char* extensions = NULL;- unsigned int num_exts = 0;+ size_t *ext_index = NULL;+ char *extensions = NULL;+ size_t num_exts = 0; init_options(); @@ -261,8 +261,8 @@ void parse_options(int argc, char **argv, char **base_paths[], char **paths[]) { full_len = (longopts_len + lang_count + 1); longopts = ag_malloc(full_len * sizeof(option_t)); memcpy(longopts, base_longopts, sizeof(base_longopts));- ext_index = (unsigned int*)ag_malloc(sizeof(unsigned int)*lang_count);- memset(ext_index, 0, sizeof(unsigned int)*lang_count);+ ext_index = (size_t *)ag_malloc(sizeof(size_t) * lang_count);+ memset(ext_index, 0, sizeof(size_t) * lang_count); for (i = 0; i < lang_count; i++) { option_t opt = { langs[i].name, no_argument, NULL, 0 };@@ -508,9 +508,13 @@ void parse_options(int argc, char **argv, char **base_paths[], char **paths[]) { compile_study(&opts.file_search_regex, &opts.file_search_regex_extra, lang_regex, 0, 0); } - if (extensions) free(extensions);+ if (extensions) {+ free(extensions);+ } free(ext_index);- if (lang_regex) free(lang_regex);+ if (lang_regex) {+ free(lang_regex);+ } free(longopts); argc -= optind;@@ -539,7 +543,7 @@ void parse_options(int argc, char **argv, char **base_paths[], char **paths[]) { } if (list_file_types) {- unsigned int lang_index;+ size_t lang_index; printf("The following file types are supported:\n"); for (lang_index = 0; lang_index < lang_count; lang_index++) { printf(" --%s\n ", langs[lang_index].name);@@ -659,7 +663,7 @@ skip_group: if (argc > 0) { *paths = ag_calloc(sizeof(char *), argc + 1); *base_paths = ag_calloc(sizeof(char *), argc + 1);- for (i = 0; i < (unsigned int)argc; i++) {+ for (i = 0; i < (size_t)argc; i++) { path = ag_strdup(argv[i]); path_len = strlen(path); /* kill trailing slash */