aboutsummaryrefslogtreecommitdiffstats
path: root/c/head.c
blob: 9363b1cb4d7dd9ac96fadecb631ed81b2835a8e9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "gbos.h"
/* head [n]: print the first n lines of stdin (default 10). Drains the rest to
   EOF so the shell sees a clean end of input. */
void main(void) {
    char *a = getargs();
    unsigned char n = 10;
    unsigned char lines = 0;
    char c;
    if (*a) n = atou(a);
    for (;;) {
        c = readc();
        if (c == EOF) break;
        if (lines < n) putc(c);
        if (c == '\n') lines++;
    }
}