1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1992-2010 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* Glenn Fowler <gsf@research.att.com> *
1N/A* David Korn <dgk@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#pragma prototyped
1N/A/*
1N/A * asa.c
1N/A * Written by David Korn
1N/A * AT&T Labs
1N/A * Tue Mar 25 11:03:23 EST 2003
1N/A */
1N/A
1N/Astatic const char usage[] =
1N/A"[-?\n@(#)$Id: asa (AT&T Research) 2003-03-25 $\n]"
1N/A"[-author?David Korn <dgk@research.att.com>]"
1N/A"[-license?http://www.research.att.com/sw/tools/reuse]"
1N/A"[+NAME?asa - interpret carriage-control characters]"
1N/A"[+DESCRIPTION?\basa\b writes its input files to standard output mapping "
1N/A "carriage control characters to line-printer control sequences.]"
1N/A"[+?The first character of each line or record is removed from the input and "
1N/A "is processed as follows before the rest of the line is output:]{"
1N/A "[+0?A new-line is output.]"
1N/A "[+1?Advance to the next page.]"
1N/A "[++?Overwrite the previous line.]"
1N/A "[+\aspace\a?Just output the remainder of the line.]"
1N/A "}"
1N/A "[+?Any other character as the first character is treated as if "
1N/A "it were a space.]"
1N/A"[+?If no \afile\a operands are given or if the \afile\a is \b-\b, \basa\b "
1N/A "reads from standard input. The start of the file is defined as the "
1N/A "current offset.]"
1N/A"[r]#[reclen?If \areclen\a is greater than zero, the file is assumed to "
1N/A "consist of fixed length records of length \areclen\a.]"
1N/A"\n"
1N/A"\n[file ... ]\n"
1N/A"\n"
1N/A"[+EXIT STATUS?]{"
1N/A "[+0?Success.]"
1N/A "[+>0?An error occurred.]"
1N/A"}"
1N/A"[+SEE ALSO?\blpr\b(1)]"
1N/A;
1N/A
1N/A#include <cmd.h>
1N/A
1N/Astatic int asa(register Sfio_t *in, Sfio_t *out, int reclen)
1N/A{
1N/A register char *cp;
1N/A register int n, c = 0;
1N/A while(1)
1N/A {
1N/A if(reclen>0)
1N/A cp = sfreserve(in,n=reclen, -1);
1N/A else
1N/A cp = sfgetr(in,'\n',0);
1N/A if(!cp)
1N/A break;
1N/A if(reclen<=0)
1N/A n = sfvalue(in)-2;
1N/A else
1N/A while(--n>0 && cp[n]==' ');
1N/A switch(*cp)
1N/A {
1N/A case '\n':
1N/A break;
1N/A case '0':
1N/A sfputc(out,'\n');
1N/A break;
1N/A case '1':
1N/A if(c)
1N/A {
1N/A sfputc(out,c);
1N/A c = '\f';
1N/A }
1N/A break;
1N/A case '+':
1N/A c = '\r';
1N/A break;
1N/A }
1N/A if(c)
1N/A sfputc(out,c);
1N/A if(n>0)
1N/A sfwrite(out,cp+1,n);
1N/A c = '\n';
1N/A }
1N/A if(c)
1N/A sfputc(out,c);
1N/A return(0);
1N/A}
1N/A
1N/Aint b_asa(int argc, char *argv[], void *context)
1N/A{
1N/A register char *cp;
1N/A register Sfio_t *fp;
1N/A register int n, reclen=0;
1N/A
1N/A cmdinit(argc, argv, context, ERROR_CATALOG, 0);
1N/A while (n = optget(argv, usage)) switch (n)
1N/A {
1N/A case 'r':
1N/A reclen = opt_info.num;
1N/A break;
1N/A case ':':
1N/A error(2, "%s", opt_info.arg);
1N/A break;
1N/A case '?':
1N/A error(ERROR_usage(2), "%s", opt_info.arg);
1N/A break;
1N/A }
1N/A argv += opt_info.index;
1N/A if(error_info.errors)
1N/A error(ERROR_usage(2),"%s",optusage((char*)0));
1N/A if (cp = *argv)
1N/A argv++;
1N/A do
1N/A {
1N/A if (!cp || streq(cp,"-"))
1N/A fp = sfstdin;
1N/A else if (!(fp = sfopen(NiL, cp, "r")))
1N/A {
1N/A error(ERROR_system(0), "%s: cannot open", cp);
1N/A error_info.errors = 1;
1N/A continue;
1N/A }
1N/A n = asa(fp, sfstdout,reclen);
1N/A if (fp != sfstdin)
1N/A sfclose(fp);
1N/A } while (cp = *argv++);
1N/A return(error_info.errors);
1N/A}