From: Joel Rosdahl Date: Sun, 1 Aug 2010 08:47:52 +0000 (+0200) Subject: Format code to use a more consistent coding style X-Git-Tag: v3.1~117 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=530dfe7c114eae25d594be539febf3e60c438e8d;p=thirdparty%2Fccache.git Format code to use a more consistent coding style --- diff --git a/HACKING.txt b/HACKING.txt new file mode 100644 index 000000000..223e635db --- /dev/null +++ b/HACKING.txt @@ -0,0 +1,56 @@ +Hacking ccache +============== + +Code formatting +--------------- + +* Use tabs for indenting and spaces for aligning C code. See + . +* Use 4 spaces for indenting other code (and spaces for aligning). +* Put the opening curly brace on a new line when defining a function, otherwise + at the end of the same row. +* Put no space between function name and the following parenthesis. +* Put one space between if/switch/for/while/do and opening curly brace. +* If possible, keep lines at most 80 character wide for a 2 character tab + width. +* Use only lowercase names for functions and variables. +* Use only uppercase names for enum items and (with some exceptins) macros. +* Don't use typedefs for structs and enums. + +Idioms +------ + +* Use NULL to initialize null pointers. +* Don't use NULL to compare null pointers. +* Use format(), x_malloc() and friends instead of checking for memory + allocation failure explicitly. +* Use str_eq() instead of strcmp() when testing for string (in)equality. +* Consider using str_startswith() instead of strncmp(). + +Other +----- + +* Strive to minimize use of global variables. +* Write test cases for new code. + +Commit messages +--------------- + +* Write a short description on the first line. If wanted, leave the second line + empty and write a longer description on line three and below. +* Start the short description with a capital letter. Optional: prefix the short + description with a context follow by a colon. +* The short description should be in "command form" (see examples below). +* Don't put a final period after the short description. +* Keep lines in the message at most 80 characters wide. + +Example 1: + + Hash a delimiter string between parts to separate them + + Previously, "gcc -I-O2 -c file.c" and "gcc -I -O2 -c file.c" would hash to + the same sum. + +Example 2: + + win32: Add a space between filename and error string in x_fmmap() diff --git a/args.c b/args.c index a784e61b3..49d14812b 100644 --- a/args.c +++ b/args.c @@ -30,7 +30,7 @@ args_init(int init_argc, char **init_args) args->argc = 0; args->argv = (char **)x_malloc(sizeof(char *)); args->argv[0] = NULL; - for (i=0;iargv[0]); - memmove(&args->argv[0], - &args->argv[1], - args->argc * sizeof(args->argv[0])); + memmove(&args->argv[0], &args->argv[1], args->argc * sizeof(args->argv[0])); args->argc--; } @@ -121,7 +119,7 @@ args_add_prefix(struct args *args, const char *s) { args->argv = (char**)x_realloc(args->argv, (args->argc + 2) * sizeof(char *)); memmove(&args->argv[1], &args->argv[0], - (args->argc+1) * sizeof(args->argv[0])); + (args->argc+1) * sizeof(args->argv[0])); args->argv[0] = x_strdup(s); args->argc++; } @@ -131,12 +129,12 @@ void args_strip(struct args *args, const char *prefix) { int i; - for (i=0; iargc; ) { + for (i = 0; i < args->argc; ) { if (str_startswith(args->argv[i], prefix)) { free(args->argv[i]); memmove(&args->argv[i], - &args->argv[i+1], - args->argc * sizeof(args->argv[i])); + &args->argv[i+1], + args->argc * sizeof(args->argv[i])); args->argc--; } else { i++; diff --git a/ccache.c b/ccache.c index 3f9be5da6..5942e9a17 100644 --- a/ccache.c +++ b/ccache.c @@ -252,17 +252,16 @@ enum fromcache_call_mode { */ static const char HASH_PREFIX[] = "3"; -/* - something went badly wrong - just execute the real compiler -*/ -static void failed(void) +/* Something went badly wrong - just execute the real compiler. */ +static void +failed(void) { char *e; /* strip any local args */ args_strip(orig_args, "--ccache-"); - if ((e=getenv("CCACHE_PREFIX"))) { + if ((e = getenv("CCACHE_PREFIX"))) { char *p = find_executable(e, MYNAME); if (!p) { fatal("%s: %s", e, strerror(errno)); @@ -301,7 +300,8 @@ clean_up_tmp_files() * Transform a name to a full path into the cache directory, creating needed * sublevels if needed. Caller frees. */ -static char *get_path_in_cache(const char *name, const char *suffix) +static char * +get_path_in_cache(const char *name, const char *suffix) { int i; char *path; @@ -326,7 +326,8 @@ static char *get_path_in_cache(const char *name, const char *suffix) * This function hashes an include file and stores the path and hash in the * global included_files variable. Takes over ownership of path. */ -static void remember_include_file(char *path, size_t path_len) +static void +remember_include_file(char *path, size_t path_len) { struct file_hash *h; struct mdfour fhash; @@ -381,8 +382,7 @@ static void remember_include_file(char *path, size_t path_len) hash_start(&fhash); result = hash_source_code_string(&fhash, source, st.st_size, path); - if (result & HASH_SOURCE_CODE_ERROR - || result & HASH_SOURCE_CODE_FOUND_TIME) { + if (result & HASH_SOURCE_CODE_ERROR || result & HASH_SOURCE_CODE_FOUND_TIME) { goto failure; } @@ -408,7 +408,8 @@ ignore: * Make a relative path from CCACHE_BASEDIR to path. Takes over ownership of * path. Caller frees. */ -static char *make_relative_path(char *path) +static char * +make_relative_path(char *path) { char *relpath; @@ -430,7 +431,8 @@ static char *make_relative_path(char *path) * - Stores the paths and hashes of included files in the global variable * included_files. */ -static int process_preprocessed_file(struct mdfour *hash, const char *path) +static int +process_preprocessed_file(struct mdfour *hash, const char *path) { char *data; char *p, *q, *end; @@ -442,8 +444,7 @@ static int process_preprocessed_file(struct mdfour *hash, const char *path) } if (enable_direct) { - included_files = create_hashtable(1000, hash_from_string, - strings_equal); + included_files = create_hashtable(1000, hash_from_string, strings_equal); } /* Bytes between p and q are pending to be hashed. */ @@ -583,7 +584,8 @@ language_is_preprocessed(const char *language) } /* run the real compiler and put the result in cache */ -static void to_cache(struct args *args) +static void +to_cache(struct args *args) { char *tmp_stdout, *tmp_stderr, *tmp_obj; struct stat st; @@ -651,9 +653,7 @@ static void to_cache(struct args *args) cc_log("Failed opening %s", tmp_stderr2); failed(); } - fd_result = open(tmp_stderr, - O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, - 0666); + fd_result = open(tmp_stderr, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); if (fd_result == -1) { cc_log("Failed opening %s", tmp_stderr); failed(); @@ -678,8 +678,7 @@ static void to_cache(struct args *args) || (access(tmp_obj, R_OK) == 0 && move_file(tmp_obj, output_obj, 0) == 0) || errno == ENOENT) { - /* we can use a quick method of - getting the failed output */ + /* we can use a quick method of getting the failed output */ copy_fd(fd, 2); close(fd); unlink(tmp_stderr); @@ -711,8 +710,7 @@ static void to_cache(struct args *args) if (st.st_size > 0) { if (move_uncompressed_file(tmp_stderr, cached_stderr, enable_compression) != 0) { - cc_log("Failed to move %s to %s", - tmp_stderr, cached_stderr); + cc_log("Failed to move %s to %s", tmp_stderr, cached_stderr); stats_update(STATS_ERROR); failed(); } @@ -864,7 +862,8 @@ get_object_name_from_cpp(struct args *args, struct mdfour *hash) return result; } -static void update_cached_result_globals(struct file_hash *hash) +static void +update_cached_result_globals(struct file_hash *hash) { char *object_name; @@ -881,7 +880,8 @@ static void update_cached_result_globals(struct file_hash *hash) * Update a hash sum with information common for the direct and preprocessor * modes. */ -static void calculate_common_hash(struct args *args, struct mdfour *hash) +static void +calculate_common_hash(struct args *args, struct mdfour *hash) { struct stat st; const char *compilercheck; @@ -970,7 +970,7 @@ calculate_object_hash(struct args *args, struct mdfour *hash, int direct_mode) struct file_hash *object_hash = NULL; /* first the arguments */ - for (i=1;iargc;i++) { + for (i = 1; i < args->argc; i++) { /* -L doesn't affect compilation. */ if (i < args->argc-1 && str_eq(args->argv[i], "-L")) { i++; @@ -1054,8 +1054,7 @@ calculate_object_hash(struct args *args, struct mdfour *hash, int direct_mode) manifest_name = hash_result(hash); manifest_path = get_path_in_cache(manifest_name, ".manifest"); free(manifest_name); - cc_log("Looking for object file hash in %s", - manifest_path); + cc_log("Looking for object file hash in %s", manifest_path); object_hash = manifest_get(manifest_path); if (object_hash) { cc_log("Got object file hash from manifest"); @@ -1074,10 +1073,11 @@ calculate_object_hash(struct args *args, struct mdfour *hash, int direct_mode) } /* - try to return the compile result from cache. If we can return from - cache then this function exits with the correct status code, - otherwise it returns */ -static void from_cache(enum fromcache_call_mode mode, int put_object_in_manifest) + * Try to return the compile result from cache. If we can return from cache + * then this function exits with the correct status code, otherwise it returns. + */ +static void +from_cache(enum fromcache_call_mode mode, int put_object_in_manifest) { int fd_stderr; int ret; @@ -1099,8 +1099,7 @@ static void from_cache(enum fromcache_call_mode mode, int put_object_in_manifest * (If mode != FROMCACHE_DIRECT_MODE, the dependency file is created by * gcc.) */ - produce_dep_file = \ - generating_dependencies && mode == FROMCACHE_DIRECT_MODE; + produce_dep_file = generating_dependencies && mode == FROMCACHE_DIRECT_MODE; /* If the dependency file should be in the cache, check that it is. */ if (produce_dep_file && stat(cached_dep, &st) != 0) { @@ -1113,8 +1112,7 @@ static void from_cache(enum fromcache_call_mode mode, int put_object_in_manifest } else { unlink(output_obj); /* only make a hardlink if the cache file is uncompressed */ - if (getenv("CCACHE_HARDLINK") && - test_if_compressed(cached_obj) == 0) { + if (getenv("CCACHE_HARDLINK") && test_if_compressed(cached_obj) == 0) { ret = link(cached_obj, output_obj); } else { ret = copy_file(cached_obj, output_obj, 0); @@ -1124,8 +1122,7 @@ static void from_cache(enum fromcache_call_mode mode, int put_object_in_manifest if (ret == -1) { if (errno == ENOENT) { /* Someone removed the file just before we began copying? */ - cc_log("Object file %s just disappeared from cache", - cached_obj); + cc_log("Object file %s just disappeared from cache", cached_obj); stats_update(STATS_MISSING); } else { cc_log("Failed to copy/link %s to %s (%s)", @@ -1145,8 +1142,7 @@ static void from_cache(enum fromcache_call_mode mode, int put_object_in_manifest if (produce_dep_file) { unlink(output_dep); /* only make a hardlink if the cache file is uncompressed */ - if (getenv("CCACHE_HARDLINK") && - test_if_compressed(cached_dep) == 0) { + if (getenv("CCACHE_HARDLINK") && test_if_compressed(cached_dep) == 0) { ret = link(cached_dep, output_dep); } else { ret = copy_file(cached_dep, output_dep, 0); @@ -1157,8 +1153,7 @@ static void from_cache(enum fromcache_call_mode mode, int put_object_in_manifest * Someone removed the file just before we * began copying? */ - cc_log("Dependency file %s just disappeared" - " from cache", output_obj); + cc_log("Dependency file %s just disappeared from cache", output_obj); stats_update(STATS_MISSING); } else { cc_log("Failed to copy/link %s to %s (%s)", @@ -1220,10 +1215,9 @@ static void from_cache(enum fromcache_call_mode mode, int put_object_in_manifest cc_log("Added object file hash to %s", manifest_path); update_mtime(manifest_path); stat(manifest_path, &st); - stats_update_size( - STATS_NONE, - (file_size(&st) - old_size) / 1024, - old_size == 0 ? 1 : 0); + stats_update_size(STATS_NONE, + (file_size(&st) - old_size) / 1024, + old_size == 0 ? 1 : 0); } else { cc_log("Failed to add object file hash to %s", manifest_path); } @@ -1252,7 +1246,8 @@ static void from_cache(enum fromcache_call_mode mode, int put_object_in_manifest /* find the real compiler. We just search the PATH to find a executable of the same name that isn't a link to ourselves */ -static void find_compiler(int argc, char **argv) +static void +find_compiler(int argc, char **argv) { char *base; char *path; @@ -1274,7 +1269,7 @@ static void find_compiler(int argc, char **argv) } /* support user override of the compiler */ - if ((path=getenv("CCACHE_CC"))) { + if ((path = getenv("CCACHE_CC"))) { base = x_strdup(path); } @@ -1286,8 +1281,8 @@ static void find_compiler(int argc, char **argv) fatal("Could not find compiler \"%s\" in PATH", base); } if (str_eq(compiler, argv[0])) { - fatal("Recursive invocation (the name of the ccache binary" - " must be \"%s\")", MYNAME); + fatal("Recursive invocation (the name of the ccache binary must be \"%s\")", + MYNAME); } orig_args->argv[0] = compiler; } @@ -1354,8 +1349,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args, /* These are too hard in direct mode. */ if (enable_direct) { if (str_eq(argv[i], "-Xpreprocessor")) { - cc_log("Unsupported compiler option for direct" - " mode: %s", argv[i]); + cc_log("Unsupported compiler option for direct mode: %s", argv[i]); enable_direct = 0; } } @@ -1363,8 +1357,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args, /* Multiple -arch options are too hard. */ if (str_eq(argv[i], "-arch")) { if (found_arch_opt) { - cc_log("More than one -arch compiler option" - " is unsupported"); + cc_log("More than one -arch compiler option is unsupported"); stats_update(STATS_UNSUPPORTED); result = 0; goto out; @@ -1436,8 +1429,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args, if (str_startswith(argv[i], "-g")) { args_add(stripped_args, argv[i]); if (enable_unify && !str_eq(argv[i], "-g0")) { - cc_log("%s used; disabling unify mode", - argv[i]); + cc_log("%s used; disabling unify mode", argv[i]); enable_unify = 0; } if (str_eq(argv[i], "-g3")) { @@ -1445,8 +1437,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args, * Fix for bug 7190 ("commandline macros (-D) * have non-zero lineno when using -g3"). */ - cc_log("%s used; not compiling preprocessed" - " code", argv[i]); + cc_log("%s used; not compiling preprocessed code", argv[i]); compile_preprocessed_source_code = 0; } continue; @@ -1542,8 +1533,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args, for (j = 0; opts[j]; j++) { if (str_eq(argv[i], opts[j])) { if (i == argc-1) { - cc_log("Missing argument to %s", - argv[i]); + cc_log("Missing argument to %s", argv[i]); stats_update(STATS_ARGS); result = 0; goto out; @@ -1609,8 +1599,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args, for (j = 0; opts[j]; j++) { if (str_eq(argv[i], opts[j])) { if (i == argc-1) { - cc_log("Missing argument to %s", - argv[i]); + cc_log("Missing argument to %s", argv[i]); stats_update(STATS_ARGS); result = 0; goto out; @@ -1643,8 +1632,7 @@ cc_process_args(struct args *orig_args, struct args **preprocessor_args, if (input_file) { if (language_for_file(argv[i])) { - cc_log("Multiple input files: %s and %s", - input_file, argv[i]); + cc_log("Multiple input files: %s and %s", input_file, argv[i]); stats_update(STATS_MULTIPLE); } else if (!found_c_opt) { cc_log("Called for link with %s", argv[i]); @@ -1816,7 +1804,8 @@ out: } /* Reset the global state. Used by the test suite. */ -void cc_reset(void) +void +cc_reset(void) { free(current_working_dir); current_working_dir = NULL; free(cache_dir); cache_dir = NULL; @@ -1849,7 +1838,8 @@ void cc_reset(void) compile_preprocessed_source_code = 0; } -static unsigned parse_sloppiness(char *p) +static unsigned +parse_sloppiness(char *p) { unsigned result = 0; char *word, *q; @@ -1879,7 +1869,8 @@ static unsigned parse_sloppiness(char *p) } /* the main ccache driver function */ -static void ccache(int argc, char *argv[]) +static void +ccache(int argc, char *argv[]) { int put_object_in_manifest = 0; struct file_hash *object_hash; @@ -1949,8 +1940,7 @@ static void ccache(int argc, char *argv[]) direct_hash = common_hash; if (enable_direct) { cc_log("Trying direct lookup"); - object_hash = calculate_object_hash( - preprocessor_args, &direct_hash, 1); + object_hash = calculate_object_hash(preprocessor_args, &direct_hash, 1); if (object_hash) { update_cached_result_globals(object_hash); @@ -2041,7 +2031,8 @@ static void ccache(int argc, char *argv[]) failed(); } -static void check_cache_dir(void) +static void +check_cache_dir(void) { if (!cache_dir) { fatal("Unable to determine cache directory"); @@ -2049,7 +2040,8 @@ static void check_cache_dir(void) } /* the main program when not doing a compile */ -static int ccache_main_options(int argc, char *argv[]) +static int +ccache_main_options(int argc, char *argv[]) { int c; size_t v; @@ -2122,8 +2114,7 @@ static int ccache_main_options(int argc, char *argv[]) printf("Unset cache size limit\n"); } else { char *s = format_size(v); - printf("Set cache size limit to %s\n", - s); + printf("Set cache size limit to %s\n", s); free(s); } } else { @@ -2144,7 +2135,8 @@ static int ccache_main_options(int argc, char *argv[]) /* Make a copy of stderr that will not be cached, so things like distcc can send networking errors to it. */ -static void setup_uncached_err(void) +static void +setup_uncached_err(void) { char *buf; int uncached_fd; @@ -2164,7 +2156,8 @@ static void setup_uncached_err(void) } } -int ccache_main(int argc, char *argv[]) +int +ccache_main(int argc, char *argv[]) { char *p; char *program_name; @@ -2233,22 +2226,25 @@ int ccache_main(int argc, char *argv[]) /* make sure the cache dir exists */ if (create_dir(cache_dir) != 0) { - fprintf(stderr,"ccache: failed to create %s (%s)\n", - cache_dir, strerror(errno)); + fprintf(stderr, + "ccache: failed to create %s (%s)\n", + cache_dir, strerror(errno)); exit(1); } /* make sure the temp dir exists */ if (create_dir(temp_dir) != 0) { - fprintf(stderr,"ccache: failed to create %s (%s)\n", - temp_dir, strerror(errno)); + fprintf(stderr, + "ccache: failed to create %s (%s)\n", + temp_dir, strerror(errno)); exit(1); } if (!getenv("CCACHE_READONLY")) { if (create_cachedirtag(cache_dir) != 0) { - fprintf(stderr,"ccache: failed to create %s/CACHEDIR.TAG (%s)\n", - cache_dir, strerror(errno)); + fprintf(stderr, + "ccache: failed to create %s/CACHEDIR.TAG (%s)\n", + cache_dir, strerror(errno)); exit(1); } } diff --git a/ccache.h b/ccache.h index 54919f5c9..35cee1674 100644 --- a/ccache.h +++ b/ccache.h @@ -25,7 +25,7 @@ extern const char CCACHE_VERSION[]; /* statistics fields in storage order */ enum stats { - STATS_NONE=0, + STATS_NONE = 0, STATS_STDOUT, STATS_STATUS, STATS_ERROR, diff --git a/cleanup.c b/cleanup.c index 283e3f0e0..95828274b 100644 --- a/cleanup.c +++ b/cleanup.c @@ -47,7 +47,8 @@ static size_t cache_size_threshold; static size_t files_in_cache_threshold; /* File comparison function that orders files in mtime order, oldest first. */ -static int files_compare(struct files **f1, struct files **f2) +static int +files_compare(struct files **f1, struct files **f2) { if ((*f2)->mtime == (*f1)->mtime) { return strcmp((*f1)->fname, (*f2)->fname); @@ -59,7 +60,8 @@ static int files_compare(struct files **f1, struct files **f2) } /* this builds the list of files in the cache */ -static void traverse_fn(const char *fname, struct stat *st) +static void +traverse_fn(const char *fname, struct stat *st) { char *p; @@ -85,8 +87,7 @@ static void traverse_fn(const char *fname, struct stat *st) if (num_files == allocated) { allocated = 10000 + num_files*2; - files = (struct files **)x_realloc( - files, sizeof(struct files *)*allocated); + files = (struct files **)x_realloc(files, sizeof(struct files *)*allocated); } files[num_files] = (struct files *)x_malloc(sizeof(struct files)); @@ -101,7 +102,8 @@ out: free(p); } -static void delete_file(const char *path, size_t size) +static void +delete_file(const char *path, size_t size) { if (unlink(path) == 0) { cache_size -= size; @@ -111,7 +113,8 @@ static void delete_file(const char *path, size_t size) } } -static void delete_sibling_file(const char *base, const char *extension) +static void +delete_sibling_file(const char *base, const char *extension) { struct stat st; char *path; @@ -127,7 +130,8 @@ static void delete_sibling_file(const char *base, const char *extension) /* sort the files we've found and delete the oldest ones until we are below the thresholds */ -static void sort_and_clean(void) +static void +sort_and_clean(void) { unsigned i; const char *ext; @@ -135,8 +139,7 @@ static void sort_and_clean(void) if (num_files > 1) { /* Sort in ascending mtime order. */ - qsort(files, num_files, sizeof(struct files *), - (COMPAR_FN_T)files_compare); + qsort(files, num_files, sizeof(struct files *), (COMPAR_FN_T)files_compare); } /* delete enough files to bring us below the threshold */ @@ -178,7 +181,8 @@ static void sort_and_clean(void) } /* cleanup in one cache subdir */ -void cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize) +void +cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize) { unsigned i; @@ -230,9 +234,7 @@ void cleanup_all(const char *dir) memset(counters, 0, sizeof(counters)); stats_read(sfile, counters); - cleanup_dir(dname, - counters[STATS_MAXFILES], - counters[STATS_MAXSIZE]); + cleanup_dir(dname, counters[STATS_MAXFILES], counters[STATS_MAXSIZE]); free(dname); free(sfile); } diff --git a/execute.c b/execute.c index c7da11707..ee769d05f 100644 --- a/execute.c +++ b/execute.c @@ -38,7 +38,8 @@ find_executable_in_path(const char *name, const char *exclude_name, char *path); * Re-create a win32 command line string based on **argv. * http://msdn.microsoft.com/en-us/library/17w5ykft.aspx */ -static char *argvtos(char *prefix, char **argv) +static char * +argvtos(char *prefix, char **argv) { char *arg; char *ptr; @@ -52,14 +53,14 @@ static char *argvtos(char *prefix, char **argv) int bs = 0; for (j = 0; arg[j]; j++) { switch (arg[j]) { - case '\\': - bs++; - break; - case '"': - bs = (bs << 1) + 1; - default: - l += bs + 1; - bs = 0; + case '\\': + bs++; + break; + case '"': + bs = (bs << 1) + 1; + default: + l += bs + 1; + bs = 0; } } l += (bs << 1) + 3; @@ -76,15 +77,15 @@ static char *argvtos(char *prefix, char **argv) *ptr++ = '"'; for (j = 0; arg[j]; j++) { switch (arg[j]) { - case '\\': - bs++; - break; - case '"': - bs = (bs << 1) + 1; - default: - while (bs && bs--) - *ptr++ = '\\'; - *ptr++ = arg[j]; + case '\\': + bs++; + break; + case '"': + bs = (bs << 1) + 1; + default: + while (bs && bs--) + *ptr++ = '\\'; + *ptr++ = arg[j]; } } bs <<= 1; @@ -98,8 +99,9 @@ static char *argvtos(char *prefix, char **argv) return str; } -int win32execute(char *path, char **argv, int doreturn, - const char *path_stdout, const char *path_stderr) +int +win32execute(char *path, char **argv, int doreturn, + const char *path_stdout, const char *path_stderr) { PROCESS_INFORMATION pi; STARTUPINFO si; @@ -144,7 +146,7 @@ int win32execute(char *path, char **argv, int doreturn, si.hStdInput = GetStdHandle(STD_INPUT_HANDLE); si.dwFlags = STARTF_USESTDHANDLES; if (si.hStdOutput == INVALID_HANDLE_VALUE || - si.hStdError == INVALID_HANDLE_VALUE) + si.hStdError == INVALID_HANDLE_VALUE) return -1; } args = argvtos(sh, argv); @@ -171,9 +173,8 @@ int win32execute(char *path, char **argv, int doreturn, execute a compiler backend, capturing all output to the given paths the full path to the compiler to run is in argv[0] */ -int execute(char **argv, - const char *path_stdout, - const char *path_stderr) +int +execute(char **argv, const char *path_stdout, const char *path_stderr) { pid_t pid; int status; @@ -219,9 +220,11 @@ int execute(char **argv, /* - find an executable by name in $PATH. Exclude any that are links to exclude_name + * Find an executable by name in $PATH. Exclude any that are links to + * exclude_name. */ -char *find_executable(const char *name, const char *exclude_name) +char * +find_executable(const char *name, const char *exclude_name) { char *path; @@ -250,14 +253,14 @@ find_executable_in_path(const char *name, const char *exclude_name, char *path) /* search the path looking for the first compiler of the right name that isn't us */ - for (tok=strtok(path, PATH_DELIM); tok; tok = strtok(NULL, PATH_DELIM)) { + for (tok = strtok(path, PATH_DELIM); tok; tok = strtok(NULL, PATH_DELIM)) { #ifdef _WIN32 char namebuf[MAX_PATH]; int ret = SearchPath(tok, name, ".exe", sizeof(namebuf), namebuf, NULL); if (!ret) ret = SearchPath(tok, name, NULL, - sizeof(namebuf), namebuf, NULL); + sizeof(namebuf), namebuf, NULL); (void) exclude_name; if (ret) { free(path); @@ -271,14 +274,12 @@ find_executable_in_path(const char *name, const char *exclude_name, char *path) lstat(fname, &st1) == 0 && stat(fname, &st2) == 0 && S_ISREG(st2.st_mode)) { - /* if its a symlink then ensure it doesn't - point at something called exclude_name */ if (S_ISLNK(st1.st_mode)) { char *buf = x_realpath(fname); if (buf) { char *p = basename(buf); if (str_eq(p, exclude_name)) { - /* its a link to "ccache" ! */ + /* It's a link to "ccache"! */ free(p); free(buf); continue; @@ -288,7 +289,7 @@ find_executable_in_path(const char *name, const char *exclude_name, char *path) } } - /* found it! */ + /* Found it! */ free(path); return fname; } @@ -300,7 +301,8 @@ find_executable_in_path(const char *name, const char *exclude_name, char *path) return NULL; } -void print_command(FILE *fp, char **argv) +void +print_command(FILE *fp, char **argv) { int i; for (i = 0; argv[i]; i++) { @@ -309,7 +311,8 @@ void print_command(FILE *fp, char **argv) fprintf(fp, "\n"); } -void print_executed_command(FILE *fp, char **argv) +void +print_executed_command(FILE *fp, char **argv) { fprintf(fp, "%s: executing ", MYNAME); print_command(fp, argv); diff --git a/getopt_long.c b/getopt_long.c index bf518d79d..e426b1aef 100644 --- a/getopt_long.c +++ b/getopt_long.c @@ -48,8 +48,8 @@ int getopt_long(int argc, char *const argv[], - const char *optstring, - const struct option * longopts, int *longindex) + const char *optstring, + const struct option * longopts, int *longindex) { static char *place = EMSG; /* option letter processing */ char *oli; /* option letter list index */ diff --git a/hash.c b/hash.c index 530cc7d9c..151fc2627 100644 --- a/hash.c +++ b/hash.c @@ -28,12 +28,14 @@ #define HASH_DELIMITER "\000cCaChE" -void hash_buffer(struct mdfour *md, const void *s, size_t len) +void +hash_buffer(struct mdfour *md, const void *s, size_t len) { mdfour_update(md, (unsigned char *)s, len); } -void hash_start(struct mdfour *md) +void +hash_start(struct mdfour *md) { mdfour_begin(md); } @@ -48,18 +50,21 @@ void hash_start(struct mdfour *md) * information X if CCACHE_A is set and information Y if CCACHE_B is set, * there should never be a hash collision risk). */ -void hash_delimiter(struct mdfour *md, const char *type) +void +hash_delimiter(struct mdfour *md, const char *type) { hash_buffer(md, HASH_DELIMITER, sizeof(HASH_DELIMITER)); hash_buffer(md, type, strlen(type) + 1); /* Include NUL. */ } -void hash_string(struct mdfour *md, const char *s) +void +hash_string(struct mdfour *md, const char *s) { hash_buffer(md, s, strlen(s)); } -void hash_int(struct mdfour *md, int x) +void +hash_int(struct mdfour *md, int x) { hash_buffer(md, (char *)&x, sizeof(x)); } @@ -67,7 +72,8 @@ void hash_int(struct mdfour *md, int x) /* * Add contents of an open file to the hash. Returns 1 on success, otherwise 0. */ -int hash_fd(struct mdfour *md, int fd) +int +hash_fd(struct mdfour *md, int fd) { char buf[1024]; size_t n; @@ -85,7 +91,8 @@ int hash_fd(struct mdfour *md, int fd) /* * Add contents of a file to the hash. Returns 1 on success, otherwise 0. */ -int hash_file(struct mdfour *md, const char *fname) +int +hash_file(struct mdfour *md, const char *fname) { int fd; int ret; @@ -101,7 +108,8 @@ int hash_file(struct mdfour *md, const char *fname) } /* Return the hash result as a hex string. Caller frees. */ -char *hash_result(struct mdfour *md) +char * +hash_result(struct mdfour *md) { unsigned char sum[16]; @@ -110,7 +118,8 @@ char *hash_result(struct mdfour *md) } /* return the hash result as 16 binary bytes */ -void hash_result_as_bytes(struct mdfour *md, unsigned char *out) +void +hash_result_as_bytes(struct mdfour *md, unsigned char *out) { hash_buffer(md, NULL, 0); mdfour_result(md, out); diff --git a/hashutil.c b/hashutil.c index 102e5d326..0d30fb203 100644 --- a/hashutil.c +++ b/hashutil.c @@ -49,14 +49,14 @@ file_hashes_equal(struct file_hash *fh1, struct file_hash *fh2) && fh1->size == fh2->size; } -#define HASH(ch) \ - do { \ - hashbuf[hashbuflen] = ch; \ - hashbuflen++; \ - if (hashbuflen == sizeof(hashbuf)) { \ - hash_buffer(hash, hashbuf, sizeof(hashbuf)); \ - hashbuflen = 0; \ - } \ +#define HASH(ch) \ + do {\ + hashbuf[hashbuflen] = ch; \ + hashbuflen++; \ + if (hashbuflen == sizeof(hashbuf)) {\ + hash_buffer(hash, hashbuf, sizeof(hashbuf)); \ + hashbuflen = 0; \ + } \ } while (0) /* @@ -88,8 +88,7 @@ hash_source_code_string( } switch (*(p+1)) { case '*': - HASH(' '); /* Don't paste tokens together when - * removing the comment. */ + HASH(' '); /* Don't paste tokens together when removing the comment. */ p += 2; while (p+1 < end && (*p != '*' || *(p+1) != '/')) { @@ -140,19 +139,17 @@ hash_source_code_string( && p[4] == 'T') { result |= HASH_SOURCE_CODE_FOUND_DATE; } else if (p[2] == 'T' && p[3] == 'I' - && p[4] == 'M') { + && p[4] == 'M') { result |= HASH_SOURCE_CODE_FOUND_TIME; } /* - * Of course, we can't be sure that we have - * found a __{DATE,TIME}__ that's actually - * used, but better safe than sorry. And if you - * do something like + * Of course, we can't be sure that we have found a __{DATE,TIME}__ + * that's actually used, but better safe than sorry. And if you do + * something like * * #define TIME __TI ## ME__ * - * in your code, you deserve to get a false - * cache hit. + * in your code, you deserve to get a false cache hit. */ } break; @@ -173,8 +170,8 @@ end: } if (result & HASH_SOURCE_CODE_FOUND_DATE) { /* - * Make sure that the hash sum changes if the (potential) - * expansion of __DATE__ changes. + * Make sure that the hash sum changes if the (potential) expansion of + * __DATE__ changes. */ time_t t = time(NULL); struct tm *now = localtime(&t); @@ -186,12 +183,11 @@ end: } if (result & HASH_SOURCE_CODE_FOUND_TIME) { /* - * We don't know for sure that the program actually uses the - * __TIME__ macro, but we have to assume it anyway and hash the - * time stamp. However, that's not very useful since the chance - * that we get a cache hit later the same second should be - * quite slim... So, just signal back to the caller that - * __TIME__ has been found so that the direct mode can be + * We don't know for sure that the program actually uses the __TIME__ + * macro, but we have to assume it anyway and hash the time stamp. However, + * that's not very useful since the chance that we get a cache hit later + * the same second should be quite slim... So, just signal back to the + * caller that __TIME__ has been found so that the direct mode can be * disabled. */ cc_log("Found __TIME__ in %s", path); diff --git a/manifest.c b/manifest.c index 02cf980c4..ad12000e8 100644 --- a/manifest.c +++ b/manifest.c @@ -77,8 +77,7 @@ static const uint32_t MAX_MANIFEST_ENTRIES = 100; #define static_assert(e) do { enum { static_assert__ = 1/(e) }; } while (0) -struct file_info -{ +struct file_info { /* Index to n_files. */ uint32_t index; /* Hash of referenced file. */ @@ -87,8 +86,7 @@ struct file_info uint32_t size; }; -struct object -{ +struct object { /* Number of entries in file_info_indexes. */ uint32_t n_file_info_indexes; /* Indexes to file_infos. */ @@ -97,8 +95,7 @@ struct object struct file_hash hash; }; -struct manifest -{ +struct manifest { /* Size of hash fields (in bytes). */ uint8_t hash_size; @@ -115,22 +112,25 @@ struct manifest struct object *objects; }; -static unsigned int hash_from_file_info(void *key) +static unsigned int +hash_from_file_info(void *key) { static_assert(sizeof(struct file_info) == 24); /* No padding. */ return murmurhashneutral2(key, sizeof(struct file_info), 0); } -static int file_infos_equal(void *key1, void *key2) +static int +file_infos_equal(void *key1, void *key2) { struct file_info *fi1 = (struct file_info *)key1; struct file_info *fi2 = (struct file_info *)key2; return fi1->index == fi2->index - && memcmp(fi1->hash, fi2->hash, 16) == 0 - && fi1->size == fi2->size; + && memcmp(fi1->hash, fi2->hash, 16) == 0 + && fi1->size == fi2->size; } -static void free_manifest(struct manifest *mf) +static void +free_manifest(struct manifest *mf) { uint16_t i; for (i = 0; i < mf->n_files; i++) { @@ -144,56 +144,57 @@ static void free_manifest(struct manifest *mf) free(mf->objects); } -#define READ_INT(size, var) \ - do { \ - int ch_; \ - size_t i_; \ - (var) = 0; \ - for (i_ = 0; i_ < (size); i_++) { \ - ch_ = gzgetc(f); \ - if (ch_ == EOF) { \ - goto error; \ - } \ - (var) <<= 8; \ - (var) |= ch_ & 0xFF; \ - } \ +#define READ_INT(size, var) \ + do { \ + int ch_; \ + size_t i_; \ + (var) = 0; \ + for (i_ = 0; i_ < (size); i_++) { \ + ch_ = gzgetc(f); \ + if (ch_ == EOF) { \ + goto error; \ + } \ + (var) <<= 8; \ + (var) |= ch_ & 0xFF; \ + } \ } while (0) -#define READ_STR(var) \ - do { \ - char buf_[1024]; \ - size_t i_; \ - int ch_; \ - for (i_ = 0; i_ < sizeof(buf_); i_++) { \ - ch_ = gzgetc(f); \ - if (ch_ == EOF) { \ - goto error; \ - } \ - buf_[i_] = ch_; \ - if (ch_ == '\0') { \ - break; \ - } \ - } \ - if (i_ == sizeof(buf_)) { \ - goto error; \ - } \ - (var) = x_strdup(buf_); \ +#define READ_STR(var) \ + do { \ + char buf_[1024]; \ + size_t i_; \ + int ch_; \ + for (i_ = 0; i_ < sizeof(buf_); i_++) { \ + ch_ = gzgetc(f); \ + if (ch_ == EOF) { \ + goto error; \ + } \ + buf_[i_] = ch_; \ + if (ch_ == '\0') { \ + break; \ + } \ + } \ + if (i_ == sizeof(buf_)) { \ + goto error; \ + } \ + (var) = x_strdup(buf_); \ } while (0) -#define READ_BYTES(n, var) \ - do { \ - size_t i_; \ - int ch_; \ - for (i_ = 0; i_ < (n); i_++) { \ - ch_ = gzgetc(f); \ - if (ch_ == EOF) { \ - goto error; \ - } \ - (var)[i_] = ch_; \ - } \ +#define READ_BYTES(n, var) \ + do { \ + size_t i_; \ + int ch_; \ + for (i_ = 0; i_ < (n); i_++) { \ + ch_ = gzgetc(f); \ + if (ch_ == EOF) { \ + goto error; \ + } \ + (var)[i_] = ch_; \ + } \ } while (0) -static struct manifest *create_empty_manifest(void) +static struct manifest * +create_empty_manifest(void) { struct manifest *mf; @@ -209,7 +210,8 @@ static struct manifest *create_empty_manifest(void) return mf; } -static struct manifest *read_manifest(gzFile f) +static struct manifest * +read_manifest(gzFile f) { struct manifest *mf; uint16_t i, j; @@ -235,10 +237,8 @@ static struct manifest *read_manifest(gzFile f) READ_INT(1, mf->hash_size); if (mf->hash_size != 16) { - /* Temporary measure until we support different hash - * algorithms. */ - cc_log("Manifest file has unsupported hash size %u", - mf->hash_size); + /* Temporary measure until we support different hash algorithms. */ + cc_log("Manifest file has unsupported hash size %u", mf->hash_size); free_manifest(mf); return NULL; } @@ -289,36 +289,37 @@ error: return NULL; } -#define WRITE_INT(size, var) \ - do { \ - char ch_; \ - size_t i_; \ - for (i_ = 0; i_ < (size); i_++) { \ - ch_ = ((var) >> (8 * ((size) - i_ - 1))); \ - if (gzputc(f, ch_) == EOF) { \ - goto error; \ - } \ - } \ +#define WRITE_INT(size, var) \ + do { \ + char ch_; \ + size_t i_; \ + for (i_ = 0; i_ < (size); i_++) { \ + ch_ = ((var) >> (8 * ((size) - i_ - 1))); \ + if (gzputc(f, ch_) == EOF) { \ + goto error; \ + } \ + } \ } while (0) -#define WRITE_STR(var) \ - do { \ - if (gzputs(f, var) == EOF || gzputc(f, '\0') == EOF) { \ - goto error; \ - } \ +#define WRITE_STR(var) \ + do { \ + if (gzputs(f, var) == EOF || gzputc(f, '\0') == EOF) { \ + goto error; \ + } \ } while (0) -#define WRITE_BYTES(n, var) \ - do { \ - size_t i_; \ - for (i_ = 0; i_ < (n); i_++) { \ - if (gzputc(f, (var)[i_]) == EOF) { \ - goto error; \ - } \ - } \ +#define WRITE_BYTES(n, var) \ + do { \ + size_t i_; \ + for (i_ = 0; i_ < (n); i_++) { \ + if (gzputc(f, (var)[i_]) == EOF) { \ + goto error; \ + } \ + } \ } while (0) -static int write_manifest(gzFile f, const struct manifest *mf) +static int +write_manifest(gzFile f, const struct manifest *mf) { uint16_t i, j; @@ -356,8 +357,9 @@ error: return 0; } -static int verify_object(struct manifest *mf, struct object *obj, - struct hashtable *hashed_files) +static int +verify_object(struct manifest *mf, struct object *obj, + struct hashtable *hashed_files) { uint32_t i; struct file_info *fi; @@ -371,11 +373,9 @@ static int verify_object(struct manifest *mf, struct object *obj, if (!actual) { actual = x_malloc(sizeof(*actual)); hash_start(&hash); - result = hash_source_code_file(&hash, - mf->files[fi->index]); + result = hash_source_code_file(&hash, mf->files[fi->index]); if (result & HASH_SOURCE_CODE_ERROR) { - cc_log("Failed hashing %s", - mf->files[fi->index]); + cc_log("Failed hashing %s", mf->files[fi->index]); free(actual); return 0; } @@ -385,9 +385,7 @@ static int verify_object(struct manifest *mf, struct object *obj, } hash_result_as_bytes(&hash, actual->hash); actual->size = hash.totalN; - hashtable_insert(hashed_files, - x_strdup(mf->files[fi->index]), - actual); + hashtable_insert(hashed_files, x_strdup(mf->files[fi->index]), actual); } if (memcmp(fi->hash, actual->hash, mf->hash_size) != 0 || fi->size != actual->size) { @@ -398,7 +396,8 @@ static int verify_object(struct manifest *mf, struct object *obj, return 1; } -static struct hashtable *create_string_index_map(char **strings, uint32_t len) +static struct hashtable * +create_string_index_map(char **strings, uint32_t len) { uint32_t i; struct hashtable *h; @@ -413,8 +412,8 @@ static struct hashtable *create_string_index_map(char **strings, uint32_t len) return h; } -static struct hashtable *create_file_info_index_map(struct file_info *infos, - uint32_t len) +static struct hashtable * +create_file_info_index_map(struct file_info *infos, uint32_t len) { uint32_t i; struct hashtable *h; @@ -432,9 +431,9 @@ static struct hashtable *create_file_info_index_map(struct file_info *infos, return h; } -static uint32_t get_include_file_index(struct manifest *mf, - char *path, - struct hashtable *mf_files) +static uint32_t +get_include_file_index(struct manifest *mf, char *path, + struct hashtable *mf_files) { uint32_t *index; uint32_t n; @@ -452,11 +451,12 @@ static uint32_t get_include_file_index(struct manifest *mf, return n; } -static uint32_t get_file_hash_index(struct manifest *mf, - char *path, - struct file_hash *file_hash, - struct hashtable *mf_files, - struct hashtable *mf_file_infos) +static uint32_t +get_file_hash_index(struct manifest *mf, + char *path, + struct file_hash *file_hash, + struct hashtable *mf_files, + struct hashtable *mf_file_infos) { struct file_info fi; uint32_t *fi_index; @@ -472,8 +472,7 @@ static uint32_t get_file_hash_index(struct manifest *mf, } n = mf->n_file_infos; - mf->file_infos = x_realloc(mf->file_infos, - (n + 1) * sizeof(*mf->file_infos)); + mf->file_infos = x_realloc(mf->file_infos, (n + 1) * sizeof(*mf->file_infos)); mf->n_file_infos++; mf->file_infos[n] = fi; @@ -482,7 +481,7 @@ static uint32_t get_file_hash_index(struct manifest *mf, static void add_file_info_indexes(uint32_t *indexes, uint32_t size, - struct manifest *mf, struct hashtable *included_files) + struct manifest *mf, struct hashtable *included_files) { struct hashtable_itr *iter; uint32_t i; @@ -496,15 +495,14 @@ add_file_info_indexes(uint32_t *indexes, uint32_t size, } mf_files = create_string_index_map(mf->files, mf->n_files); - mf_file_infos = create_file_info_index_map(mf->file_infos, - mf->n_file_infos); + mf_file_infos = create_file_info_index_map(mf->file_infos, mf->n_file_infos); iter = hashtable_iterator(included_files); i = 0; do { path = hashtable_iterator_key(iter); file_hash = hashtable_iterator_value(iter); indexes[i] = get_file_hash_index(mf, path, file_hash, mf_files, - mf_file_infos); + mf_file_infos); i++; } while (hashtable_iterator_advance(iter)); assert(i == size); @@ -513,9 +511,10 @@ add_file_info_indexes(uint32_t *indexes, uint32_t size, hashtable_destroy(mf_files, 1); } -static void add_object_entry(struct manifest *mf, - struct file_hash *object_hash, - struct hashtable *included_files) +static void +add_object_entry(struct manifest *mf, + struct file_hash *object_hash, + struct hashtable *included_files) { struct object *obj; uint32_t n; @@ -537,7 +536,8 @@ static void add_object_entry(struct manifest *mf, * Try to get the object hash from a manifest file. Caller frees. Returns NULL * on failure. */ -struct file_hash *manifest_get(const char *manifest_path) +struct file_hash * +manifest_get(const char *manifest_path) { int fd; gzFile f = NULL; @@ -590,8 +590,9 @@ out: * Put the object name into a manifest file given a set of included files. * Returns 1 on success, otherwise 0. */ -int manifest_put(const char *manifest_path, struct file_hash *object_hash, - struct hashtable *included_files) +int +manifest_put(const char *manifest_path, struct file_hash *object_hash, + struct hashtable *included_files) { int ret = 0; int fd1; @@ -644,21 +645,19 @@ int manifest_put(const char *manifest_path, struct file_hash *object_hash, if (mf->n_objects > MAX_MANIFEST_ENTRIES) { /* - * Normally, there shouldn't be many object entries in the - * manifest since new entries are added only if an include file - * has changed but not the source file, and you typically - * change source files more often than header files. However, - * it's certainly possible to imagine cases where the manifest - * will grow large (for instance, a generated header file that - * changes for every build), and this must be taken care of - * since processing an ever growing manifest eventually will - * take too much time. A good way of solving this would be to - * maintain the object entries in LRU order and discarding the - * old ones. An easy way is to throw away all entries when - * there are too many. Let's do that for now. + * Normally, there shouldn't be many object entries in the manifest since + * new entries are added only if an include file has changed but not the + * source file, and you typically change source files more often than + * header files. However, it's certainly possible to imagine cases where + * the manifest will grow large (for instance, a generated header file that + * changes for every build), and this must be taken care of since + * processing an ever growing manifest eventually will take too much time. + * A good way of solving this would be to maintain the object entries in + * LRU order and discarding the old ones. An easy way is to throw away all + * entries when there are too many. Let's do that for now. */ cc_log("More than %u entries in manifest file; discarding", - MAX_MANIFEST_ENTRIES); + MAX_MANIFEST_ENTRIES); free_manifest(mf); mf = create_empty_manifest(); } @@ -682,8 +681,7 @@ int manifest_put(const char *manifest_path, struct file_hash *object_hash, if (x_rename(tmp_file, manifest_path) == 0) { ret = 1; } else { - cc_log("Failed to rename %s to %s", - tmp_file, manifest_path); + cc_log("Failed to rename %s to %s", tmp_file, manifest_path); goto out; } } else { diff --git a/mdfour.c b/mdfour.c index 311c0cf59..e832fc7df 100644 --- a/mdfour.c +++ b/mdfour.c @@ -37,7 +37,8 @@ static struct mdfour *m; #define ROUND3(a,b,c,d,k,s) a = lshift((a + H(b,c,d) + M[k] + 0x6ED9EBA1)&MASK32,s) /* this applies md4 to 64 byte chunks */ -static void mdfour64(uint32_t *M) +static void +mdfour64(uint32_t *M) { uint32_t AA, BB, CC, DD; uint32_t A,B,C,D; @@ -82,16 +83,18 @@ static void mdfour64(uint32_t *M) m->A = A; m->B = B; m->C = C; m->D = D; } -static void copy64(uint32_t *M, const unsigned char *in) +static void +copy64(uint32_t *M, const unsigned char *in) { int i; - for (i=0;i<16;i++) + for (i = 0; i < 16; i++) M[i] = (in[i*4+3]<<24) | (in[i*4+2]<<16) | (in[i*4+1]<<8) | (in[i*4+0]<<0); } -static void copy4(unsigned char *out, uint32_t x) +static void +copy4(unsigned char *out, uint32_t x) { out[0] = x&0xFF; out[1] = (x>>8)&0xFF; @@ -99,7 +102,8 @@ static void copy4(unsigned char *out, uint32_t x) out[3] = (x>>24)&0xFF; } -void mdfour_begin(struct mdfour *md) +void +mdfour_begin(struct mdfour *md) { md->A = 0x67452301; md->B = 0xefcdab89; @@ -109,8 +113,8 @@ void mdfour_begin(struct mdfour *md) md->tail_len = 0; } - -static void mdfour_tail(const unsigned char *in, size_t n) +static +void mdfour_tail(const unsigned char *in, size_t n) { unsigned char buf[128] = { 0 }; uint32_t M[16]; @@ -136,7 +140,8 @@ static void mdfour_tail(const unsigned char *in, size_t n) } } -void mdfour_update(struct mdfour *md, const unsigned char *in, size_t n) +void +mdfour_update(struct mdfour *md, const unsigned char *in, size_t n) { uint32_t M[16]; @@ -184,8 +189,8 @@ void mdfour_update(struct mdfour *md, const unsigned char *in, size_t n) } } - -void mdfour_result(struct mdfour *md, unsigned char *out) +void +mdfour_result(struct mdfour *md, unsigned char *out) { copy4(out, md->A); copy4(out+4, md->B); diff --git a/murmurhashneutral2.c b/murmurhashneutral2.c index ade30b8bf..e625ba8b4 100644 --- a/murmurhashneutral2.c +++ b/murmurhashneutral2.c @@ -5,7 +5,8 @@ #include "murmurhashneutral2.h" -unsigned int murmurhashneutral2(const void *key, int len, unsigned int seed) +unsigned int +murmurhashneutral2(const void *key, int len, unsigned int seed) { const unsigned int m = 0x5bd1e995; const int r = 24; diff --git a/stats.c b/stats.c index d99a81367..00b468b3a 100644 --- a/stats.c +++ b/stats.c @@ -84,7 +84,8 @@ static struct { { STATS_NONE, NULL, NULL, 0 } }; -static void display_size(size_t v) +static void +display_size(size_t v) { char *s = format_size(v); printf("%15s", s); @@ -92,13 +93,14 @@ static void display_size(size_t v) } /* parse a stats file from a buffer - adding to the counters */ -static void parse_stats(unsigned counters[STATS_END], char *buf) +static void +parse_stats(unsigned counters[STATS_END], char *buf) { int i; char *p, *p2; p = buf; - for (i=0;i static const char *const s_tokens[] = { - "...", ">>=", "<<=", "+=", "-=", "*=", "/=", "%=", "&=", "^=", - "|=", ">>", "<<", "++", "--", "->", "&&", "||", "<=", ">=", - "==", "!=", ";", "{", "<%", "}", "%>", ",", ":", "=", - "(", ")", "[", "<:", "]", ":>", ".", "&", "!", "~", - "-", "+", "*", "/", "%", "<", ">", "^", "|", "?", + "...", ">>=", "<<=", "+=", "-=", "*=", "/=", "%=", "&=", "^=", + "|=", ">>", "<<", "++", "--", "->", "&&", "||", "<=", ">=", + "==", "!=", ";", "{", "<%", "}", "%>", ",", ":", "=", + "(", ")", "[", "<:", "]", ":>", ".", "&", "!", "~", + "-", "+", "*", "/", "%", "<", ">", "^", "|", "?", 0 }; @@ -63,7 +63,8 @@ static struct { } tokens[256]; /* build up the table used by the unifier */ -static void build_table(void) +static void +build_table(void) { unsigned char c; int i; @@ -73,7 +74,7 @@ static void build_table(void) done = 1; memset(tokens, 0, sizeof(tokens)); - for (c=0;c<128;c++) { + for (c = 0; c < 128; c++) { if (isalpha(c) || c == '_') tokens[c].type |= C_ALPHA; if (isdigit(c)) tokens[c].type |= C_DIGIT; if (isspace(c)) tokens[c].type |= C_SPACE; @@ -91,7 +92,7 @@ static void build_table(void) tokens['-'].type |= C_SIGN; tokens['+'].type |= C_SIGN; - for (i=0;s_tokens[i];i++) { + for (i = 0; s_tokens[i]; i++) { c = s_tokens[i][0]; tokens[c].type |= C_TOKEN; tokens[c].toks[tokens[c].num_toks] = s_tokens[i]; @@ -100,7 +101,8 @@ static void build_table(void) } /* buffer up characters before hashing them */ -static void pushchar(struct mdfour *hash, unsigned char c) +static void +pushchar(struct mdfour *hash, unsigned char c) { static unsigned char buf[64]; static size_t len; @@ -122,7 +124,8 @@ static void pushchar(struct mdfour *hash, unsigned char c) } /* hash some C/C++ code after unifying */ -static void unify(struct mdfour *hash, unsigned char *p, size_t size) +static void +unify(struct mdfour *hash, unsigned char *p, size_t size) { size_t ofs; unsigned char q; @@ -130,7 +133,7 @@ static void unify(struct mdfour *hash, unsigned char *p, size_t size) build_table(); - for (ofs=0; ofs 2 && p[ofs+1] == ' ' && isdigit(p[ofs+2])) { do { @@ -152,8 +155,7 @@ static void unify(struct mdfour *hash, unsigned char *p, size_t size) do { pushchar(hash, p[ofs]); ofs++; - } while (ofs < size && - (tokens[p[ofs]].type & (C_ALPHA|C_DIGIT))); + } while (ofs < size && (tokens[p[ofs]].type & (C_ALPHA|C_DIGIT))); pushchar(hash, '\n'); continue; } @@ -173,8 +175,7 @@ static void unify(struct mdfour *hash, unsigned char *p, size_t size) if (ofs < size && (p[ofs] == 'E' || p[ofs] == 'e')) { pushchar(hash, p[ofs]); ofs++; - while (ofs < size && - (tokens[p[ofs]].type & (C_DIGIT|C_SIGN))) { + while (ofs < size && (tokens[p[ofs]].type & (C_DIGIT|C_SIGN))) { pushchar(hash, p[ofs]); ofs++; } @@ -202,7 +203,7 @@ static void unify(struct mdfour *hash, unsigned char *p, size_t size) while (ofs < size-1 && p[ofs] == '\\') { pushchar(hash, p[ofs]); pushchar(hash, p[ofs+1]); - ofs+=2; + ofs += 2; } pushchar(hash, p[ofs]); } while (ofs < size && p[ofs] != q); @@ -213,12 +214,12 @@ static void unify(struct mdfour *hash, unsigned char *p, size_t size) if (tokens[p[ofs]].type & C_TOKEN) { q = p[ofs]; - for (i=0;i= ofs+len && memcmp(&p[ofs], s, len) == 0) { int j; - for (j=0;s[j];j++) { + for (j = 0; s[j]; j++) { pushchar(hash, s[j]); ofs++; } @@ -242,7 +243,8 @@ static void unify(struct mdfour *hash, unsigned char *p, size_t size) /* hash a file that consists of preprocessor output, but remove any line number information from the hash */ -int unify_hash(struct mdfour *hash, const char *fname) +int +unify_hash(struct mdfour *hash, const char *fname) { off_t size; char *map; diff --git a/util.c b/util.c index e69a615e5..1af431880 100644 --- a/util.c +++ b/util.c @@ -51,7 +51,8 @@ static FILE *logfile; -static int init_log(void) +static int +init_log(void) { extern char *cache_logfile; @@ -69,7 +70,8 @@ static int init_log(void) } } -static void log_prefix(void) +static void +log_prefix(void) { #ifdef HAVE_GETTIMEOFDAY char timestamp[100];