The silver search (ag) 가 ack - grep 보다 빨 라 요.
ag 의 코드 를 보고 나 서 야 이 긴 줄 의 인쇄 억제 가 아직 완성 되 지 않 았 다 는 것 을 알 게 되 었 다.
src/options.h:48:30: int print_long_lines; /* TODO: support this in print.c */
다행히 작가 의 C 코드 가 간단명료 해서 나 는 패 치 를 빨리 쓸 수 있 고 - M 인 자 를 사용 하여 긴 줄 의 출력 을 억제 할 수 있다.패 치 메 일이 발송 되 었 습 니 다.나 도 백업 해 볼 게.
diff --git a/src/options.c b/src/options.c
index b08903f..2f4b18e 100644
--- a/src/options.c
+++ b/src/options.c
@@ -77,6 +77,8 @@ Search options:
\
-p --path-to-agignore STRING
\
Use .agignore file at STRING
\
--print-long-lines Print matches on very long lines (Default: >2k characters)
\
+-M --max-printable-line-length NUM
\
+ Skip print the matching lines that have a length bigger than NUM
\
-Q --literal Don't parse PATTERN as a regular expression
\
-s --case-sensitive Match case sensitively (Enabled by default)
\
-S --smart-case Match case insensitively unless PATTERN contains
\
@@ -115,6 +117,7 @@ void init_options() {
opts.color_path = ag_strdup(color_path);
opts.color_match = ag_strdup(color_match);
opts.color_line_number = ag_strdup(color_line_number);
+ opts.max_printable_line_length = DEFAULT_MAX_PRINTABLE_LINE_LENGTH;
}
void cleanup_options() {
@@ -221,6 +224,7 @@ void parse_options(int argc, char **argv, char **base_paths[], char **paths[]) {
{ "version", no_argument, &version, 1 },
{ "word-regexp", no_argument, NULL, 'w' },
{ "workers", required_argument, NULL, 0 },
+ { "max-printable-line-length", required_argument, NULL, 'M' },
{ NULL, 0, NULL, 0 }
};
@@ -253,7 +257,7 @@ void parse_options(int argc, char **argv, char **base_paths[], char **paths[]) {
opts.stdout_inode = statbuf.st_ino;
}
- while ((ch = getopt_long(argc, argv, "A:aB:C:DG:g:fhiLlm:np:QRrSsvVtuUwz", longopts, &opt_index)) != -1) {
+ while ((ch = getopt_long(argc, argv, "A:aB:C:DG:g:fhiLlm:M:np:QRrSsvVtuUwz", longopts, &opt_index)) != -1) {
switch (ch) {
case 'A':
opts.after = atoi(optarg);
@@ -305,6 +309,9 @@ void parse_options(int argc, char **argv, char **base_paths[], char **paths[]) {
case 'm':
opts.max_matches_per_file = atoi(optarg);
break;
+ case 'M':
+ opts.max_printable_line_length = atoi(optarg);
+ break;
case 'n':
opts.recurse_dirs = 0;
break;
diff --git a/src/options.h b/src/options.h
index 5049ab5..b4d2468 100644
--- a/src/options.h
+++ b/src/options.h
@@ -7,6 +7,7 @@
#include
#define DEFAULT_CONTEXT_LEN 2
+#define DEFAULT_MAX_PRINTABLE_LINE_LENGTH 2000
enum case_behavior {
CASE_SENSITIVE,
@@ -45,6 +46,7 @@ typedef struct {
int print_heading;
int print_line_numbers;
int print_long_lines; /* TODO: support this in print.c */
+ int max_printable_line_length;
pcre *re;
pcre_extra *re_extra;
int recurse_dirs;
diff --git a/src/print.c b/src/print.c
index dc11594..4be9874 100644
--- a/src/print.c
+++ b/src/print.c
@@ -34,6 +34,15 @@ void print_binary_file_matches(const char* path) {
fprintf(out_fd, "Binary file %s matches.
", path);
}
+static void check_printable(int len, int *printable) {
+ if (len > opts.max_printable_line_length) {
+ *printable = FALSE;
+ fprintf(out_fd, "+EVIL+MARK+VERY+LONG+LINES+HERE
");
+ } else {
+ *printable = TRUE;
+ }
+}
+
void print_file_matches(const char* path, const char* buf, const int buf_len, const match matches[], const int matches_len) {
int line = 1;
char **context_prev_lines = NULL;
@@ -49,6 +58,7 @@ void print_file_matches(const char* path, const char* buf, const int buf_len, co
int i, j;
int in_a_match = FALSE;
int printing_a_match = FALSE;
+ int printable = TRUE;
if (opts.ackmate) {
sep = ':';
@@ -129,7 +139,8 @@ void print_file_matches(const char* path, const char* buf, const int buf_len, co
}
j = prev_line_offset;
/* print up to current char */
- for (; j <= i; j++) {
+ check_printable(i - prev_line_offset, &printable);
+ for (; j <= i && printable; j++) {
fputc(buf[j], out_fd);
}
} else {
@@ -141,7 +152,8 @@ void print_file_matches(const char* path, const char* buf, const int buf_len, co
if (printing_a_match && opts.color) {
fprintf(out_fd, "%s", opts.color_match);
}
- for (j = prev_line_offset; j <= i; j++) {
+ check_printable(i - prev_line_offset, &printable);
+ for (j = prev_line_offset; j <= i && printable; j++) {
if (j == matches[last_printed_match].end && last_printed_match < matches_len) {
if (opts.color) {
fprintf(out_fd, "%s", color_reset);
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.