Permalink
Browse files

Put else on the same line as }

  • Loading branch information...
1 parent 2729fe9 commit bcb7dc849db5bb9b2756e3fc9c758d9fb642f3d1 @ggreer committed Oct 8, 2012
Showing with 36 additions and 72 deletions.
  1. +1 −2 src/ignore.c
  2. +2 −4 src/main.c
  3. +9 −18 src/options.c
  4. +6 −12 src/print.c
  5. +14 −28 src/search.c
  6. +4 −8 src/util.c
View
@@ -72,8 +72,7 @@ void add_ignore_pattern(ignores *ig, const char* pattern) {
ig->regexes = realloc(ig->regexes, ig->regexes_len * sizeof(char*));
ig->regexes[ig->regexes_len - 1] = strdup(pattern);
log_debug("added regex ignore pattern %s", pattern);
- }
- else {
+ } else {
/* a balanced binary tree is best for performance, but I'm lazy */
ig->names_len++;
ig->names = realloc(ig->names, ig->names_len * sizeof(char*));
View
@@ -78,8 +78,7 @@ int main(int argc, char **argv) {
opts.literal_starts_wordchar = is_wordchar(opts.query[0]);
opts.literal_ends_wordchar = is_wordchar(opts.query[opts.query_len - 1]);
}
- }
- else {
+ } else {
if (opts.casing == CASE_INSENSITIVE) {
pcre_opts = pcre_opts | PCRE_CASELESS;
}
@@ -95,8 +94,7 @@ int main(int argc, char **argv) {
if (opts.search_stream) {
search_stream(stdin, "");
- }
- else {
+ } else {
for (i = 0; i < workers_len; i++) {
pthread_create(&(workers[i]), NULL, &search_file_worker, NULL);
}
View
@@ -206,8 +206,7 @@ void parse_options(int argc, char **argv, char **paths[]) {
optind--;
opts.context = DEFAULT_CONTEXT_LEN;
}
- }
- else {
+ } else {
opts.context = DEFAULT_CONTEXT_LEN;
}
break;
@@ -282,25 +281,20 @@ void parse_options(int argc, char **argv, char **paths[]) {
if (strcmp(longopts[opt_index].name, "ackmate-dir-filter") == 0) {
compile_study(&opts.ackmate_dir_filter, &opts.ackmate_dir_filter_extra, optarg, 0, 0);
break;
- }
- else if (strcmp(longopts[opt_index].name, "depth") == 0) {
+ } else if (strcmp(longopts[opt_index].name, "depth") == 0) {
opts.max_search_depth = atoi(optarg);
break;
- }
- else if (strcmp(longopts[opt_index].name, "ignore") == 0) {
+ } else if (strcmp(longopts[opt_index].name, "ignore") == 0) {
add_ignore_pattern(root_ignores, optarg);
break;
- }
- else if (strcmp(longopts[opt_index].name, "nopager") == 0) {
+ } else if (strcmp(longopts[opt_index].name, "nopager") == 0) {
out_fd = stdout;
opts.pager = NULL;
break;
- }
- else if (strcmp(longopts[opt_index].name, "pager") == 0) {
+ } else if (strcmp(longopts[opt_index].name, "pager") == 0) {
opts.pager = optarg;
break;
- }
- else if (strcmp(longopts[opt_index].name, "workers") == 0) {
+ } else if (strcmp(longopts[opt_index].name, "workers") == 0) {
opts.workers = atoi(optarg);
break;
}
@@ -367,8 +361,7 @@ void parse_options(int argc, char **argv, char **paths[]) {
if (group) {
opts.print_heading = 1;
opts.print_break = 1;
- }
- else {
+ } else {
opts.print_heading = 0;
opts.print_break = 0;
}
@@ -385,8 +378,7 @@ void parse_options(int argc, char **argv, char **paths[]) {
opts.query = strdup(argv[0]);
argc--;
argv++;
- }
- else {
+ } else {
opts.query = strdup(".");
}
opts.query_len = strlen(opts.query);
@@ -418,8 +410,7 @@ void parse_options(int argc, char **argv, char **paths[]) {
(*paths)[i] = NULL;
/* Make sure we search these paths instead of stdin. */
opts.search_stream = 0;
- }
- else {
+ } else {
path = strdup(".");
*paths = malloc(sizeof(char*) * 2);
(*paths)[0] = path;
View
@@ -20,12 +20,10 @@ void print_path(const char* path, const char sep) {
if (opts.ackmate) {
fprintf(out_fd, ":%s%c", path, sep);
- }
- else {
+ } else {
if (opts.color) {
fprintf(out_fd, "%s%s%s%c", colors_path, path, colors_reset, sep);
- }
- else {
+ } else {
fprintf(out_fd, "%s%c", path, sep);
}
}
@@ -83,8 +81,7 @@ void print_file_matches(const char* path, const char* buf, const int buf_len, co
lines_to_print = lines_since_last_match - (opts.after + 1);
if (lines_to_print < 0) {
lines_to_print = 0;
- }
- else if (lines_to_print > opts.before) {
+ } else if (lines_to_print > opts.before) {
lines_to_print = opts.before;
}
@@ -133,8 +130,7 @@ void print_file_matches(const char* path, const char* buf, const int buf_len, co
for (; j <= i; j++) {
fputc(buf[j], out_fd);
}
- }
- else {
+ } else {
print_line_number(line, ':');
if (opts.column) {
fprintf(out_fd, "%i:", (matches[last_printed_match].start - prev_line_offset) + 1);
@@ -161,8 +157,7 @@ void print_file_matches(const char* path, const char* buf, const int buf_len, co
fprintf(out_fd, "%s", colors_reset);
}
}
- }
- else if (lines_since_last_match <= opts.after) {
+ } else if (lines_since_last_match <= opts.after) {
/* print context after matching line */
if (opts.print_heading == 0) {
print_path(path, ':');
@@ -199,8 +194,7 @@ void print_line_number(const int line, const char sep) {
if (opts.color) {
fprintf(out_fd, "%s%i%s%c", colors_line_number, line, colors_reset, sep);
- }
- else {
+ } else {
fprintf(out_fd, "%i%c", line, sep);
}
}
View
@@ -30,8 +30,7 @@ void search_buf(const char *buf, const int buf_len,
matches_size = 100;
matches = malloc(matches_size * sizeof(match));
matches_spare = 1;
- }
- else {
+ } else {
matches_size = 0;
matches = NULL;
matches_spare = 0;
@@ -61,8 +60,7 @@ void search_buf(const char *buf, const int buf_len,
is_wordchar(*end) != opts.literal_ends_wordchar))
{
/* It's a match */
- }
- else {
+ } else {
/* It's not a match */
match_ptr += opts.query_len;
buf_offset = end - buf;
@@ -88,8 +86,7 @@ void search_buf(const char *buf, const int buf_len,
break;
}
}
- }
- else {
+ } else {
int rc;
int offset_vector[3];
while (buf_offset < buf_len &&
@@ -134,16 +131,13 @@ void search_buf(const char *buf, const int buf_len,
pthread_mutex_lock(&print_mtx);
if (opts.print_filename_only) {
print_path(dir_full_path, '\n');
- }
- else if (binary) {
+ } else if (binary) {
print_binary_file_matches(dir_full_path);
- }
- else {
+ } else {
print_file_matches(dir_full_path, buf, buf_len, matches, matches_len);
}
pthread_mutex_unlock(&print_mtx);
- }
- else {
+ } else {
log_debug("No match in %s", dir_full_path);
}
@@ -195,8 +189,7 @@ void search_file(const char *file_full_path) {
pipe = fdopen(fd, "r");
search_stream(pipe, file_full_path);
fclose(pipe);
- }
- else {
+ } else {
f_len = statbuf.st_size;
if (f_len == 0) {
@@ -269,8 +262,7 @@ void search_dir(ignores *ig, const char* path, const int depth) {
asprintf(&dir_full_path, "%s/%s", path, ignore_file);
if (strcmp(SVN_DIR, ignore_file) == 0) {
load_svn_ignore_patterns(ig, dir_full_path);
- }
- else {
+ } else {
load_ignore_patterns(ig, dir_full_path);
}
free(dir_full_path);
@@ -285,17 +277,15 @@ void search_dir(ignores *ig, const char* path, const int depth) {
if (results == 0) {
log_debug("No results found in directory %s", path);
goto search_dir_cleanup;
- }
- else if (results == -1) {
+ } else if (results == -1) {
if (errno == ENOTDIR) {
/* Not a directory. Probably a file. */
/* If we're only searching one file, don't print the filename header at the top. */
if (depth == 0 && opts.paths_len == 1) {
opts.print_heading = -1;
}
search_file(path);
- }
- else {
+ } else {
log_err("Error opening directory %s: %s", path, strerror(errno));
}
goto search_dir_cleanup;
@@ -323,8 +313,7 @@ void search_dir(ignores *ig, const char* path, const int depth) {
if (rc < 0) { /* no match */
log_debug("Skipping %s due to file_search_regex.", dir_full_path);
goto cleanup;
- }
- else if (opts.match_files) {
+ } else if (opts.match_files) {
log_debug("match_files: file_search_regex matched for %s.", dir_full_path);
pthread_mutex_lock(&print_mtx);
print_path(dir_full_path, '\n');
@@ -339,23 +328,20 @@ void search_dir(ignores *ig, const char* path, const int depth) {
pthread_mutex_lock(&work_queue_mtx);
if (work_queue_tail == NULL) {
work_queue = queue_item;
- }
- else {
+ } else {
work_queue_tail->next = queue_item;
}
work_queue_tail = queue_item;
pthread_mutex_unlock(&work_queue_mtx);
pthread_cond_broadcast(&files_ready);
log_debug("%s added to work queue", dir_full_path);
- }
- else if (opts.recurse_dirs) {
+ } else if (opts.recurse_dirs) {
if (depth < opts.max_search_depth) {
log_debug("Searching dir %s", dir_full_path);
ignores *child_ig = init_ignore(ig);
search_dir(child_ig, dir_full_path, depth + 1);
cleanup_ignore(child_ig);
- }
- else {
+ } else {
log_err("Skipping %s. Use the --depth option to search deeper.", dir_full_path);
}
}
View
@@ -19,8 +19,7 @@ void generate_skip_lookup(const char *find, size_t f_len, size_t skip_lookup[],
for (i = 0; i < f_len; i++) {
if (case_sensitive) {
skip_lookup[(unsigned char)find[i]] = f_len - i;
- }
- else {
+ } else {
skip_lookup[(unsigned char)tolower(find[i])] = f_len - i;
skip_lookup[(unsigned char)toupper(find[i])] = f_len - i;
}
@@ -101,8 +100,7 @@ int invert_matches(match matches[], int matches_len, const int buf_len) {
matches[i].end = matches[i+1].start;
}
matches_len--;
- }
- else {
+ } else {
for (i = matches_len; i >= 0; i--) {
matches[i].end = matches[i].start;
matches[i].start = i == 0 ? 0 : matches[i-1].end;
@@ -147,8 +145,7 @@ int is_binary(const void* buf, const int buf_len) {
if (buf_c[i] == '\0') {
/* NULL char. It's binary */
return 1;
- }
- else if ((buf_c[i] < 7 || buf_c[i] > 14) && (buf_c[i] < 32 || buf_c[i] > 127)) {
+ } else if ((buf_c[i] < 7 || buf_c[i] > 14) && (buf_c[i] < 32 || buf_c[i] > 127)) {
suspicious_bytes++;
/* Disk IO is so slow that it's worthwhile to do this calculation after every suspicious byte. */
/* This is true even on a 1.6Ghz Atom with an Intel 320 SSD. */
@@ -207,8 +204,7 @@ int binary_search(const char* needle, char **haystack, int start, int end) {
rc = strcmp(needle, haystack[mid]);
if (rc < 0) {
return binary_search(needle, haystack, start, mid);
- }
- else if (rc > 0) {
+ } else if (rc > 0) {
return binary_search(needle, haystack, mid + 1, end);
}

0 comments on commit bcb7dc8

Please sign in to comment.