続きです。
パイプ云々の前に、prtextってgrep表示のどの部分に関連するのでしょうか。
関数内部で使っているprlineやpr_sgr_startをコメントにして確認してみます。
修正内容は以下で、://となっている箇所が削除行です。
takk@deb9:~/tmp/grep-3.1/src$ cat -n grep.c | sed -ne 1290,1358p
1290 static void
1291 prtext (char *beg, char *lim)
1292 {
1293 static bool used; /* Avoid printing SEP_STR_GROUP before any output. */
1294 char eol = eolbyte;
1295
1296 if (!out_quiet && pending > 0)
1297 prpending (beg);
1298
1299 char *p = beg;
1300
1301 if (!out_quiet)
1302 {
1303 /* Deal with leading context. */
1304 char const *bp = lastout ? lastout : bufbeg;
1305 intmax_t i;
1306 for (i = 0; i < out_before; ++i)
1307 if (p > bp)
1308 do
1309 --p;
1310 while (p[-1] != eol);
1311
1312 /* Print the group separator unless the output is adjacent to
1313 the previous output in the file. */
1314 if ((0 <= out_before || 0 <= out_after) && used
1315 && p != lastout && group_separator)
1316 {
1317 ;// pr_sgr_start_if (sep_color);
1318 ;// fputs_errno (group_separator);
1319 ;// pr_sgr_end_if (sep_color);
1320 ;// putchar_errno ('\n');
1321 }
1322
1323 while (p < beg)
1324 {
1325 char *nl = memchr (p, eol, beg - p);
1326 nl++;
1327 ;// prline (p, nl, SEP_CHAR_REJECTED);
1328 p = nl;
1329 }
1330 }
1331
1332 intmax_t n;
1333 if (out_invert)
1334 {
1335 /* One or more lines are output. */
1336 for (n = 0; p < lim && n < outleft; n++)
1337 {
1338 char *nl = memchr (p, eol, lim - p);
1339 nl++;
1340 if (!out_quiet)
1341 ;// prline (p, nl, SEP_CHAR_SELECTED);
1342 p = nl;
1343 }
1344 }
1345 else
1346 {
1347 /* Just one line is output. */
1348 if (!out_quiet)
1349 ;// prline (beg, lim, SEP_CHAR_SELECTED);
1350 n = 1;
1351 p = lim;
1352 }
1353
1354 after_last_match = bufoffset - (buflim - p);
1355 pending = out_quiet ? 0 : MAX (0, out_after);
1356 used = true;
1357 outleft -= n;
1358 }
takk@deb9:~/tmp/grep-3.1/src$
makeして確認。通常のgrepと出力結果を比較してみます。
なんと。全く表示されなくなりました。やはりprtext関数が表示の要のようです。

コメント