grepの色の仕組み(その4)

pr_sgr_start_ifに埋め込んだ[COLOR]が表示されませんでした。
ということでpr_sgr_start_ifの使用箇所を検索してみます。

takk@deb9:~/tmp/grep-3.1/src$ grep -n pr_sgr_start_if grep.c
316:pr_sgr_start_if (char const *s)
1056:  pr_sgr_start_if (filename_color);
1065:  pr_sgr_start_if (sep_color);
1074:  pr_sgr_start_if (color);
1189:          pr_sgr_start_if (match_color);
1322:          pr_sgr_start_if (sep_color);
takk@deb9:~/tmp/grep-3.1/src$

それぞれの使用関数をさらっと挙げていきます。
316は関数本体なのでスキップ。まずは1056行目。

1052 /* Print the current filename.  */
1053 static void
1054 print_filename (void)
1055 {
1056   pr_sgr_start_if (filename_color);
1057   fputs_errno (input_filename ());
1058   pr_sgr_end_if (filename_color);
1059 }

1065行目。

1061 /* Print a character separator.  */
1062 static void
1063 print_sep (char sep)
1064 {
1065   pr_sgr_start_if (sep_color);
1066   putchar_errno (sep);
1067   pr_sgr_end_if (sep_color);
1068 }

1074行目。

1070 /* Print a line number or a byte offset.  */
1071 static void
1072 print_offset (uintmax_t pos, const char *color)
1073 {
1074   pr_sgr_start_if (color);
1075   printf_errno ("%*"PRIuMAX, offset_width, pos);
1076   pr_sgr_end_if (color);
1077 }

1189行目。

1137 static char *
1138 print_line_middle (char *beg, char *lim,
1139                    const char *line_color, const char *match_color)
1140 {
~省略~
1147   for (cur = beg;
1148        (cur < lim
1149         && ((match_offset = execute (compiled_pattern, beg, lim - beg,
1150                                      &match_size, cur)) != (size_t) -1));
1151        cur = b + match_size)
1152     {

1159       /* Avoid hanging on grep --color "" foo */
1160       if (match_size == 0)
1161         {
~省略~
1167         }
1168       else
1169         {
~省略~
1172           if (only_matching)
1173             {
~省略~
1177             }
1178           else
1179             {
1180               pr_sgr_start (line_color);
~省略~
1187             }
1188
1189           pr_sgr_start_if (match_color);
~省略~
1194         }
1195     }
~省略~
1202   return cur;
1203 }

1322行目。

1295 static void
1296 prtext (char *beg, char *lim)
1297 {
~省略~
1306   if (!out_quiet)
1307     {
1308  
~省略~
1317       /* Print the group separator unless the output is adjacent to
1318          the previous output in the file.  */
1319       if ((0 <= out_before || 0 <= out_after) && used
1320           && p != lastout && group_separator)
1321         {
1322           pr_sgr_start_if (sep_color);
1323           fputs_errno (group_separator);
1324           pr_sgr_end_if (sep_color);
1325           putchar_errno ('\n');
1326         }
1327
~省略~

次回、今回挙げた関数についてみていきます。

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA