--- /dev/null
+Hacking ccache
+==============
+
+Code formatting
+---------------
+
+* Use tabs for indenting and spaces for aligning C code. See
+ <http://www.emacswiki.org/emacs/SmartTabs>.
+* 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()
args->argc = 0;
args->argv = (char **)x_malloc(sizeof(char *));
args->argv[0] = NULL;
- for (i=0;i<init_argc;i++) {
+ for (i = 0; i < init_argc; i++) {
args_add(args, init_args[i]);
}
return args;
args_remove_first(struct args *args)
{
free(args->argv[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--;
}
{
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++;
}
args_strip(struct args *args, const char *prefix)
{
int i;
- for (i=0; i<args->argc; ) {
+ 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++;
*/
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));
* 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;
* 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;
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;
}
* 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;
* - 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;
}
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. */
}
/* 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;
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();
|| (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);
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();
}
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;
* 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;
struct file_hash *object_hash = NULL;
/* first the arguments */
- for (i=1;i<args->argc;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++;
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");
}
/*
- 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;
* (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) {
} 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);
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)",
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);
* 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)",
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);
}
/* 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;
}
/* support user override of the compiler */
- if ((path=getenv("CCACHE_CC"))) {
+ if ((path = getenv("CCACHE_CC"))) {
base = x_strdup(path);
}
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;
}
/* 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;
}
}
/* 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;
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")) {
* 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;
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;
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;
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]);
}
/* 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;
compile_preprocessed_source_code = 0;
}
-static unsigned parse_sloppiness(char *p)
+static unsigned
+parse_sloppiness(char *p)
{
unsigned result = 0;
char *word, *q;
}
/* 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;
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);
failed();
}
-static void check_cache_dir(void)
+static void
+check_cache_dir(void)
{
if (!cache_dir) {
fatal("Unable to determine cache directory");
}
/* 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;
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 {
/* 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;
}
}
-int ccache_main(int argc, char *argv[])
+int
+ccache_main(int argc, char *argv[])
{
char *p;
char *program_name;
/* 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);
}
}
/* statistics fields in storage order */
enum stats {
- STATS_NONE=0,
+ STATS_NONE = 0,
STATS_STDOUT,
STATS_STATUS,
STATS_ERROR,
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);
}
/* 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;
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));
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;
}
}
-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;
/* 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;
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 */
}
/* 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;
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);
}
* 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;
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;
*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;
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;
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);
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;
/*
- 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;
/* 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);
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;
}
}
- /* found it! */
+ /* Found it! */
free(path);
return fname;
}
return NULL;
}
-void print_command(FILE *fp, char **argv)
+void
+print_command(FILE *fp, char **argv)
{
int i;
for (i = 0; argv[i]; i++) {
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);
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 */
#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);
}
* 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));
}
/*
* 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;
/*
* 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;
}
/* 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];
}
/* 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);
&& 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)
/*
}
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) != '/')) {
&& 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;
}
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);
}
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);
#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. */
uint32_t size;
};
-struct object
-{
+struct object {
/* Number of entries in file_info_indexes. */
uint32_t n_file_info_indexes;
/* Indexes to file_infos. */
struct file_hash hash;
};
-struct manifest
-{
+struct manifest {
/* Size of hash fields (in bytes). */
uint8_t hash_size;
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++) {
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;
return mf;
}
-static struct manifest *read_manifest(gzFile f)
+static struct manifest *
+read_manifest(gzFile f)
{
struct manifest *mf;
uint16_t i, j;
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;
}
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;
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;
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;
}
}
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) {
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;
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;
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;
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;
}
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;
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;
}
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);
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;
* 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;
* 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;
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();
}
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 {
#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;
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;
out[3] = (x>>24)&0xFF;
}
-void mdfour_begin(struct mdfour *md)
+void
+mdfour_begin(struct mdfour *md)
{
md->A = 0x67452301;
md->B = 0xefcdab89;
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];
}
}
-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];
}
}
-
-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);
#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;
{ 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);
}
/* 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<STATS_END;i++) {
+ for (i = 0; i < STATS_END; i++) {
counters[i] += strtol(p, &p2, 10);
if (!p2 || p2 == p) break;
p = p2;
}
/* fill in some default stats values */
-static void stats_default(unsigned counters[STATS_END])
+static void
+stats_default(unsigned counters[STATS_END])
{
counters[STATS_MAXSIZE] += DEFAULT_MAXSIZE / 16;
}
/* read in the stats from one dir and add to the counters */
-static void stats_read_fd(int fd, unsigned counters[STATS_END])
+static void
+stats_read_fd(int fd, unsigned counters[STATS_END])
{
char buf[1024];
int len;
* Update a statistics counter (unless it's STATS_NONE) and also record that a
* number of bytes and files have been added to the cache. Size is in KiB.
*/
-void stats_update_size(enum stats stat, size_t size, unsigned files)
+void
+stats_update_size(enum stats stat, size_t size, unsigned files)
{
if (stat != STATS_NONE) {
counter_updates[stat]++;
/*
* Write counter updates in pending_counters to disk.
*/
-void stats_flush(void)
+void
+stats_flush(void)
{
int fd;
unsigned counters[STATS_END];
}
/* update a normal stat */
-void stats_update(enum stats stat)
+void
+stats_update(enum stats stat)
{
stats_update_size(stat, 0, 0);
}
/* Get the pending update a counter value. */
-unsigned stats_get_pending(enum stats stat)
+unsigned
+stats_get_pending(enum stats stat)
{
return counter_updates[stat];
}
/* read in the stats from one dir and add to the counters */
-void stats_read(const char *path, unsigned counters[STATS_END])
+void
+stats_read(const char *path, unsigned counters[STATS_END])
{
int fd;
}
/* sum and display the total stats for all cache dirs */
-void stats_summary(void)
+void
+stats_summary(void)
{
int dir, i;
unsigned counters[STATS_END];
memset(counters, 0, sizeof(counters));
/* add up the stats in each directory */
- for (dir=-1;dir<=0xF;dir++) {
+ for (dir = -1; dir <= 0xF; dir++) {
char *fname;
if (dir == -1) {
printf("cache directory %s\n", cache_dir);
/* and display them */
- for (i=0;stats_info[i].message;i++) {
+ for (i = 0; stats_info[i].message; i++) {
enum stats stat = stats_info[i].stat;
- if (counters[stat] == 0 &&
- !(stats_info[i].flags & FLAG_ALWAYS)) {
+ if (counters[stat] == 0 && !(stats_info[i].flags & FLAG_ALWAYS)) {
continue;
}
}
/* zero all the stats structures */
-void stats_zero(void)
+void
+stats_zero(void)
{
int dir, fd;
unsigned i;
unlink(fname);
free(fname);
- for (dir=0;dir<=0xF;dir++) {
+ for (dir = 0; dir <= 0xF; dir++) {
fname = format("%s/%1x/stats", cache_dir, dir);
memset(counters, 0, sizeof(counters));
if (!lockfile_acquire(fname, lock_staleness_limit)) {
}
/* set the per directory limits */
-int stats_set_limits(long maxfiles, long maxsize)
+int
+stats_set_limits(long maxfiles, long maxsize)
{
int dir;
unsigned counters[STATS_END];
}
/* set the per directory sizes */
-void stats_set_sizes(const char *dir, size_t num_files, size_t total_size)
+void
+stats_set_sizes(const char *dir, size_t num_files, size_t total_size)
{
int fd;
unsigned counters[STATS_END];
#include <unistd.h>
static const char *const s_tokens[] = {
- "...", ">>=", "<<=", "+=", "-=", "*=", "/=", "%=", "&=", "^=",
- "|=", ">>", "<<", "++", "--", "->", "&&", "||", "<=", ">=",
- "==", "!=", ";", "{", "<%", "}", "%>", ",", ":", "=",
- "(", ")", "[", "<:", "]", ":>", ".", "&", "!", "~",
- "-", "+", "*", "/", "%", "<", ">", "^", "|", "?",
+ "...", ">>=", "<<=", "+=", "-=", "*=", "/=", "%=", "&=", "^=",
+ "|=", ">>", "<<", "++", "--", "->", "&&", "||", "<=", ">=",
+ "==", "!=", ";", "{", "<%", "}", "%>", ",", ":", "=",
+ "(", ")", "[", "<:", "]", ":>", ".", "&", "!", "~",
+ "-", "+", "*", "/", "%", "<", ">", "^", "|", "?",
0
};
} 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;
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;
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];
}
/* 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;
}
/* 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;
build_table();
- for (ofs=0; ofs<size;) {
+ for (ofs = 0; ofs < size;) {
if (p[ofs] == '#') {
if ((size-ofs) > 2 && p[ofs+1] == ' ' && isdigit(p[ofs+2])) {
do {
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;
}
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++;
}
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);
if (tokens[p[ofs]].type & C_TOKEN) {
q = p[ofs];
- for (i=0;i<tokens[q].num_toks;i++) {
+ for (i = 0; i < tokens[q].num_toks; i++) {
unsigned char *s = (unsigned char *)tokens[q].toks[i];
int len = strlen((char *)s);
if (size >= 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++;
}
/* 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;
static FILE *logfile;
-static int init_log(void)
+static int
+init_log(void)
{
extern char *cache_logfile;
}
}
-static void log_prefix(void)
+static void
+log_prefix(void)
{
#ifdef HAVE_GETTIMEOFDAY
char timestamp[100];