pr.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder/***********************************************************************
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder* This software is part of the ast package *
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder* Copyright (c) 1992-2012 AT&T Intellectual Property *
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder* and is licensed under the *
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder* Eclipse Public License, Version 1.0 *
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder* by AT&T Intellectual Property *
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder* A copy of the License is available at *
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder* http://www.eclipse.org/org/documents/epl-v10.html *
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder* Information and Software Systems Research *
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder* AT&T Research *
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder* Florham Park NJ *
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder* Glenn Fowler <gsf@research.att.com> *
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder* David Korn <dgk@research.att.com> *
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder***********************************************************************/
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder * Written by David Korn
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder * Mon Mar 30 15:07:41 EST 1992
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maederstatic const char usage[] =
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[-n?\n@(#)$Id: pr (AT&T Research) 2004-07-01 $\n]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[+NAME?pr - print files]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[+DESCRIPTION?\bpr\b formats and prints files to the standard output."
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder" If \afile\a is \b-\b or if no files are specified then the"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder" standard input is read.]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[a:across?Print columns across rather than down; \b-\b\acolumns\a must be >1.]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[c:control?Print control characters in hat (^G) and octal form.]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[C:columns|cols?Print \acolumns\a columns of output. Can also be entered"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder" as -\acolumns\a. May not be used with \b-m\b.]#[columns:=1]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[d:double-space?Double space the output.]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[e:expand?Expand \achar\a to \awidth\a.]:?[char[width]]:=\\t8]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[f:formfeed?Use formfeeds instead of newlines to separate pages with"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder" a 3 line page header.]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[F:bigformfeed?Use formfeeds instead of newlines to separate pages with"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder" a 5 line page header and trailer.]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[h:header?Use \aheader\a instead of the file name in header text.]:[header]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[i:replace?Replace spaces with \achar\as to tab \awidth\a.]:?"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder" [char[width]]:=\\t8]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[j:join?Merge full lines.]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[l:lines?The page length in lines. 10 lines are reserved for the header"
1f7453e107b0f5597cfd1c4db9b55435ca6e7e86Christian Maeder" and trailer.]#[lines:=66]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[m:multiple?Print the input files one per column, truncating lines to fit.]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[n:number?Number lines with \adigits\a digits followed by \asep\a.]:?"
2381f0a14cc4ef4eddf0a42290a98d5f1e0cba5aChristian Maeder" [sep[digits]]:=\\t5]"
2381f0a14cc4ef4eddf0a42290a98d5f1e0cba5aChristian Maeder"[o:indent|margin|offset?Indent each line with \aindent\a spaces.]#[indent:=0]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[p:pause?Pause before printing each page if the output is to a terminal."
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder" \apr\a prinst a BEL on the terminal and reads one line of input"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder" before continuing. (Not implemented.)]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[P:page?Start printing with page \apage\a. Can also be entered as +\apage\a.]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[r!:warn?Warn about unreadable input files.]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[s:separate?Separate columns with \astring\a.]:?[string]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[t|T!:headers?Generate headers and trailers and pass form feeds in the input"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder" to the output.]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[w:width?The page width in characters.]#[width:=72]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[v:literal?Print control characters in C-style form.]"
2381f0a14cc4ef4eddf0a42290a98d5f1e0cba5aChristian Maeder"[X:test?Canonicalize output for testing.]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"\n[ file ... ]\n"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maeder"[+SEE ALSO?\bcat\b(1), \bfold\b(1), \bless\b(1), \bmore\b(1)]"
5e9476a2cbc92db56a25dc9f8f631ef68dcfc0c6Christian Maedertypedef struct _pr_
long pageno;
long pageskip;
long lineno;
int pagelen;
int offset;
int offlen;
int numwidth;
int columns;
int colno;
int width;
int flags;
int nopen;
int pageodd;
char **fieldlist;
char *fieldbuff;
char *fieldptr;
char **fieldlast;
char *header;
char *margin;
char *filename;
char *date;
char *buf;
char *cur;
char *end;
unsigned char *map;
} control;
} Pr_t;
return pp;
if(spaces>0)
return n+=spaces;
register int omod=0;
goto skip;
if(n==S_NL)
size = 0;
skip:
if(n==S_SPACE)
size += n;
col += n;
if(n==S_NL)
return size;
size = 0;
register char *cp;
line = 0;
old = 0;
register int n=0, size;
nstream = 0;
if(!skip)
if(fp)
nstream = 0;
if(skip>0)
skip--;
while(cp);
static ssize_t
register char* s = (char*)buf;
ssize_t z;
*s++ = hat[c];
return s - (char*)buf;
static ssize_t
register char* s = (char*)buf;
ssize_t z;
if (strlen(t) > (e - s))
return s - (char*)buf;
register char *cp;
if(opt_info.arg && opt_info.arg==argv[opt_info.index-1] && (!(cp=argv[opt_info.index]) || *cp!='-'))
if(opt_info.arg && opt_info.arg==argv[opt_info.index-1] && (!(cp=argv[opt_info.index]) || *cp!='-'))
argv++;