~ubuntu-branches/ubuntu/vivid/silversearcher-ag/vivid

« back to all changes in this revision

Viewing changes to src/print.c

  • Committer: Package Import Robot
  • Author(s): Hajime Mizuno
  • Date: 2015-01-26 10:32:49 UTC
  • mfrom: (1.2.1) (10.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20150126103249-bxlxo8eagay3mj4h
Tags: 0.28.0-1
* new upstream release
* upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    }
30
30
}
31
31
 
 
32
void print_path_count(const char *path, const char sep, const size_t count) {
 
33
    if (*path) {
 
34
        print_path(path, ':');
 
35
    }
 
36
    if (opts.color) {
 
37
        fprintf(out_fd, "%s%lu%s%c", opts.color_line_number, count, color_reset, sep);
 
38
    } else {
 
39
        fprintf(out_fd, "%lu%c", count, sep);
 
40
    }
 
41
}
 
42
 
32
43
void print_line(const char *buf, size_t buf_pos, size_t prev_line_offset) {
33
44
    for (; prev_line_offset <= buf_pos; prev_line_offset++) {
34
45
        fputc(buf[prev_line_offset], out_fd);
70
81
    }
71
82
 
72
83
    if (opts.print_path == PATH_PRINT_TOP) {
73
 
        print_path(path, '\n');
 
84
        if (opts.print_count) {
 
85
            print_path_count(path, opts.path_sep, matches_len);
 
86
        } else {
 
87
            print_path(path, opts.path_sep);
 
88
        }
74
89
    }
75
90
 
76
91
    context_prev_lines = ag_calloc(sizeof(char *), (opts.before + 1));
171
186
                        }
172
187
                        /* Don't print the null terminator */
173
188
                        if (j < buf_len) {
174
 
                            fputc(buf[j], out_fd);
 
189
                            /* if only_matching is set, print only matches and newlines */
 
190
                            if (!opts.only_matching || printing_a_match || buf[j] == '\n') {
 
191
                                fputc(buf[j], out_fd);
 
192
                            }
175
193
                        }
176
194
                    }
177
195
                    if (printing_a_match && opts.color) {
219
237
        line = opts.stream_line_num;
220
238
    }
221
239
    if (opts.color) {
222
 
        fprintf(out_fd, "%s%lu%s%c", opts.color_line_number, line, color_reset, sep);
 
240
        fprintf(out_fd, "%s%lu%s%c", opts.color_line_number, (unsigned long)line, color_reset, sep);
223
241
    } else {
224
 
        fprintf(out_fd, "%lu%c", line, sep);
 
242
        fprintf(out_fd, "%lu%c", (unsigned long)line, sep);
225
243
    }
226
244
}
227
245