牛歩grep読みの続きです。
out_invertがfalseの場合の処理からです。
1348 else
1349 {
1350 /* Just one line is output. */
1351 if (!out_quiet)
1352 prline (beg, lim, SEP_CHAR_SELECTED);
1353 n = 1;
1354 p = lim;
1355 }
1356
out_quietもおそらくオプションのフラグでしょう。定義を見てみます。
1005 static bool out_quiet; /* Suppress all normal output. */
mainで、以下のように処理しているので、他のフラグと関係しているフラグのように見受けられます。
2824 out_quiet = count_matches | done_on_match;
count_matchesとdone_on_matchはそれぞれ以下の定義です。
1012 static bool count_matches; /* Count matching lines. */ 1029 static bool done_on_match; /* Stop scanning file on first match. */
これらのフラグもやはり、他のフラグに依存しています。
2819 if ((exit_on_match | dev_null_output) || list_files != LISTFILES_NONE)
2820 {
2821 count_matches = false;
2822 done_on_match = true;
2823 }
依存しているフラグの元をたどると、
例えば、exit_on_matchは、mainで、qオプションのフラグとして設定していますので、ほとんどのフラグはオプションから設定されると考えて良いかと思います。
2641 case 'q': 2642 exit_on_match = true; 2643 exit_failure = 0; 2644 break;
dev_null_outputの場合もmainで設定しているようですが、少し複雑なことをしています。
2798 bool possibly_tty = false;
2799 struct stat tmp_stat;
2800 if (! exit_on_match && fstat (STDOUT_FILENO, &tmp_stat) == 0)
2801 {
2802 if (S_ISREG (tmp_stat.st_mode))
2803 out_stat = tmp_stat;
2804 else if (S_ISCHR (tmp_stat.st_mode))
2805 {
2806 struct stat null_stat;
2807 if (stat ("/dev/null", &null_stat) == 0
2808 && SAME_INODE (tmp_stat, null_stat))
2809 dev_null_output = true;
2810 else
2811 possibly_tty = true;
2812 }
2813 }
なんとなくですが、grep実行時に、出力をどこへ渡すのか判断していて、フラグ設定しているように思えます。
プログラム中のフラグは、オプションによるものと、出力先によるものがあるようです。
つづく


コメント