
Путь: Toys/POSIX, команды версии: Ver.4 Ver.9 nl Комментарии в файле nl.c :
Исходный текст в файле nl.c #define FOR_nl
#include "toys.h"
GLOBALS(
char *s, *n, *b;
long w, l, v;
// Count of consecutive blank lines for -l has to persist between files
long lcount, slen;
)
static void do_nl(char **pline, long len)
{
char *line;
int match = *TT.b != 'n';
if (!pline) return;
line = *pline;
if (*TT.b == 'p') match = !regexec((void *)(toybuf+16), line, 0, 0, 0);
if (TT.l || *TT.b == 't')
if (*line == '\n') match = TT.l && ++TT.lcount >= TT.l;
if (match) {
TT.lcount = 0;
printf(toybuf, TT.w, TT.v++, TT.s);
} else printf("%*c", (int)(TT.w+TT.slen), ' ');
xprintf("%s", line);
}
void nl_main(void)
{
char *clip = "";
if (!TT.s) TT.s = "\t";
TT.slen = strlen(TT.s);
if (!TT.n || !strcmp(TT.n, "rn")); // default
else if (!strcmp(TT.n, "ln")) clip = "-";
else if (!strcmp(TT.n, "rz")) clip = "0";
else error_exit("bad -n '%s'", TT.n);
sprintf(toybuf, "%%%s%s", clip, "*ld%s");
if (!TT.b) TT.b = "t";
if (*TT.b=='p' && TT.b[1])
xregcomp((void *)(toybuf+16), TT.b+1, REG_NOSUB|FLAG(E)*REG_EXTENDED);
else if (!TT.b[0] || TT.b[1] || !strchr("atn", *TT.b))
error_exit("bad -b '%s'", TT.b);
loopfiles_lines(toys.optargs, do_nl);
} |
![]() |