+static void show_pre_context(struct grep_opt *opt, const char *name, char *buf,
+ char *bol, unsigned lno)
+{
+ unsigned cur = lno, from = 1;
+
+ if (opt->pre_context < lno)
+ from = lno - opt->pre_context;
+ if (from <= opt->last_shown)
+ from = opt->last_shown + 1;
+
+ /* Rewind. */
+ while (bol > buf && cur > from) {
+ bol--;
+ while (bol > buf && bol[-1] != '\n')
+ bol--;
+ cur--;
+ }
+
+ /* Back forward. */
+ while (cur < lno) {
+ char *eol = bol;
+
+ while (*eol != '\n')
+ eol++;
+ show_line(opt, bol, eol, name, cur, '-');
+ bol = eol + 1;
+ cur++;
+ }
+}
+