/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1992-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* nl.c
* Written by David Korn
* AT&T Labs
* Mon Mar 24 10:10:10 EST 2003
*/
static const char usage[] =
"[-?\n@(#)$Id: nl (AT&T Research) 2003-03-24 $\n]"
"[+NAME? nl - line numbering filter ]"
"[+DESCRIPTION?\bnl\b reads lines from the file \afile\a or from standard "
"input if \afile\a is omitted or is \b-\b, and writes the lines to "
"standard output with possible line numbering preceding each line.]"
"[+?The \bnl\b utility treats its input in terms of logical pages and resets "
"numbering on each logical page. A logical page consists of a header, "
"a body, and a footer any of which can be empty, and each can use "
"their own line numbering options.]"
"[+?The start of logical page sections consist of input lines containing only "
"the two delimiter characters whose defaults are \b\\\b and \b:\b as "
"follows:]{"
"[d1d2d1d2d1d2?Header.]"
"[d1d2d1d2?Body.]"
"[d1d2?Footer.]"
"}"
"[+?\bnl\b assumes that the first section is a logical body until it encounters "
"one of the section delimiters.]"
""
"[b:body-numbering]:[type:=t?\atype\a can be one of the following:]{"
"[+a?Number all lines.]"
"[+t?Number only non-empty lines.]"
"[+n?No line numbering.]"
"[+p\astring\a?Number only lines that contain the basic "
"regular expression \astring\a.]"
"}"
"[d:section-delimiter]:[delim:=\\::?\adelim\a specifies the two delimiter "
"characters that indicate start of a section. If only one character "
"is specified, the second character remains unchanged.]"
"[f:footer-numbering]:[type:=n?\atype\a is the same as for the \bb\b option.]"
"[h:header-numbering]:[type:=n?\atype\a is the same as for the \bb\b option.]"
"[i:page-increment]#[incr:=1?\aincr\a is the increment used to number logical "
"page lines.]"
"[l:join-blank-lines]#[num:=1?\anum\a is the number of blank lines to be "
"treated as one]"
"[n:number-format]:[format?\aformat\a specifies the line numbering format. "
"It must be one of the following:]{"
"[101:ln?left justified, leading zeros supressed.]"
"[102:rn?right justified, leading zeros supressed.]"
"[103:rz?right justified, leading zeros kept.]"
"}"
"[p:no-renumber?Start renumbering at logical page delimiters.]"
"[s:number-separator]:[sep:=\\t?\asep\a is the string that is used to separate the line number "
"and the corresponding text line.]"
"[v:starting-line-number]#[startnum:=1?\astartnum\a is the initial value to number "
"logical pages.]"
"[w:number-width]#[width:=6?\awidth\a is the number of characters to be used "
"for line numbering.]"
"\n"
"\n[file]\n"
"\n"
"[+EXIT STATUS?]{"
"[+0?Success.]"
"[+>0?An error occurred.]"
"}"
"[+SEE ALSO?\bpr\b(1), \bregex\b(3)]"
;
#include <cmd.h>
#include <regex.h>
typedef struct _nl_
{
char *sep;
int delim1;
int delim2;
int format;
int startnum;
int incr;
int width;
int blines;
int pflag;
} Nl_t;
#define SECTION_HEAD 0
/* These numbers need to be the same as with -n option in option string */
{
register char *cp;
else
{
outline = 0;
if(*cp!='\n')
blank = 0;
else
blank++;
{
{
continue;
}
{
{
continue;
}
{
continue;
}
}
}
;
#if 0
{
continue;
}
#endif
{
{
outline = 1;
blank = 0;
}
}
else if(*cp!='\n')
outline = 1;
if(outline)
{
blank = 0;
}
else
}
return(0);
}
int
{
register int n,m;
{
case 'p':
break;
case 'd':
break;
case 'f': case 'b': case 'h':
if(n=='h')
m = SECTION_HEAD;
else if(n=='b')
m = SECTION_BODY;
else
m = SECTION_FOOT;
{
case 'a':
break;
case 't':
break;
case 'n':
break;
case 'p':
break;
}
break;
case 'i':
break;
case 'l':
break;
case 'n':
break;
case 's':
break;
case 'v':
break;
case 'w':
break;
case ':':
break;
case '?':
break;
}
for(m=0; m < 3; m++)
{
}
return(n?1:0);
}