v09i095: PEP filter program [ part 4 of 5 ]
Gisle Hannemyr
gisle at ifi.uio.no
Sat Dec 30 11:00:39 AEST 1989
Posting-number: Volume 9, Issue 95
Submitted-by: gisle at ifi.uio.no (Gisle Hannemyr)
Archive-name: pep/part04
# This is a shell archive [ part 4 of of 5 ]
# Remove everything above and including the cut line.
# Then run the rest of the file through /bin/sh (not csh).
#--cut here-----cut here-----cut here-----cut here-----cut here-----cut here--#
#!/bin/sh
# shar: Shell Archiver
# Execute the following text with /bin/sh to create the file(s):
# main.c
# This archive created: Fri Dec 29 14:42:45 1989
# Wrapped by: Gisle Hannemyr (gisle at ifi.uio.no)
echo shar: extracting main.c
sed 's/^XX//' << \SHAR_EOF > main.c
XX/* main.c 1989 december 28 [gh]
XX+-----------------------------------------------------------------------------
XX| Abstract:
XX| General purpose filter and file cleaning program. 9 out 10 hackers
XX| prefer pep to any other soap. It is named after an excellent Norwegian
XX| detergent.
XX|
XX| Authorship:
XX| Copyright (c) 1988, 1989 Gisle Hannemyr.
XX| Permission is granted to hack, make and distribute copies of this program
XX| as long as this notice and the copyright notices are not removed.
XX| If you intend to distribute changed versions of this program, please make
XX| an entry in the "history" log (below) and mark the hacked lines with your
XX| initials. I maintain the program, and shall appreiciate copies of bug
XX| fixes and new versions.
XX| Flames, bug reports, comments and improvements to:
XX| snail: Gisle Hannemyr, Brageveien 3A, 0452 Oslo, Norway
XX| email: EAN: gisle at nr.uninett
XX| Inet: gisle at ifi.uio.no
XX| UUCP: ...!mcvax!ifi!gisle
XX| (and several BBS mailboxes in the Oslo area).
XX|
XX| Acknowledgments:
XX| SYS V.2 rename courtesy of Robert Andersson (ra at isncr.is.se)
XX| VMS rename courtesy of Bjorn Larsen.
XX| Thanks to Inge Arnesen for finding & fixing a bug, (and to Nils-Eivind
XX| Naas for bringing it to my attention).
XX|
XX| History:
XX| 2.1 29 dec 89 [gh] Fixed pipe bug, added -v option, misc. speedups
XX| 2.0 22 jan 89 [gh] Made it a filter, environment lookup, fixed pathbug.
XX| 1.6 7 nov 88 [gh] Added ANSI interpretation.
XX| 1.5 6 aug 88 [gh] Hacked it to not clobber original date.
XX| 1.4 7 jul 88 [gh] Added general purpose conversion table.
XX| 1.3 13 nov 87 [gh] Fixed find first so it works on true blue too.
XX| 1.2 11 nov 87 [gh] Compensated for Turbo-C bug (isspace > 128 is bogus)
XX| 1.1 31 aug 87 [gh] Added VMS.
XX| 1.0 30 aug 87 [gh] Wrote it.
XX|
XX| Portability:
XX| So far, PEP has been tested under CP/M, MS-DOS, BSD and VMS.
XX| The implementation dependencies are:
XX| * How the compiler identify itself and the operating system.
XX| * How microcomputer compilers simulate the UNIX text line terminator.
XX| * How operating systems folds command lines (i.e. CP/M folds).
XX| * How operating systems expands command line wildcards (ie. UNIX does).
XX|
XX| This dependencies are implemented using IFDEFs. You should make sure that
XX| exactly one of the following symbols (macro names) are defined:
XX| * __CPM86__ -- For CP/M, MP/M, C-DOS and derivatives
XX| * __MSDOS__ -- For MS-DOS and derivatives
XX| * __UNIX__ -- For BSD UNIX (SYS V.3 and generic too?)
XX| * __VMS__ -- For VMS
XX|
XX| In addition, the following symbols may be twiddled if desired:
XX| * STRICMP -- Define this if linker complains about missing "stricmp"
XX| * SYSV2 -- For SYS V.2 UNIX (if no "rename" in standard lib)
XX| * __TURBOC__ -- For Borlands TURBOC (undefine it if you want PEP to
XX| change the date on the files it filters).
XX| * VMSV1 -- For VAX C V.1.x VMS (if no "rename" in standard lib)
XX|
XX| Most compilers already predefines a macro that identify the target oper-
XX| ating system. Unfortunately, different vendors uses slightly different
XX| symbols. Please add to the section headlined "canonize predefined
XX| macroes" (below) if your compiler requires it.
XX|
XX| Note: PEP makes some assumptions about standard headers. See the file
XX| "header.txt" for details.
XX|
XX| Btw. -- these are the compilers I have used to make pep:
XX| * MS-DOS, Microsoft C ver. 5.1
XX| Turbo C ver. 2.0
XX| * BSD UNIX, SunOS Release 4.0
XX| * SVID UNIX, NCR Tower System V.2
XX| * VMS, VAX C release 2.4
XX|
XX| Environment:
XX| PEP -- should point to directory with conversion tables.
XX|
XX| Bugs:
XX| * I do not recompile PEP on all operating systems at each release.
XX| Software rot may cause a particular version to need some tweaking.
XX| Please mail me if you experience this -- but please read the enclosed
XX| file "header.txt" first.
XX+---------------------------------------------------------------------------*/
XX
XX
XX/*---( Includes )-----------------------------------------------------------*/
XX
XX#define MAIN
XX
XX#include <stdio.h>
XX#include "pep.h"
XX#include <string.h>
XX#include <ctype.h>
XX#ifdef __VMS__
XX#include <types.h>
XX#include <stat.h>
XX#else
XX#include <sys/types.h>
XX#include <sys/stat.h>
XX#endif
XX#if __CPM86__ || __MSDOS__
XX#include <dos.h>
XX#include "bdmg.h"
XX#endif
XX#ifdef __MSDOS__
XX#include <fcntl.h>
XX#include <io.h>
XX#endif
XX#ifdef __UNIX__
XX#include <malloc.h>
XX#else
XX#include <stdlib.h>
XX#endif
XX#ifdef VMSV1
XX#include <descrip.h>
XX#endif
XX
XX
XX/*---( defines )------------------------------------------------------------*/
XX
XX#define VERSION "2.1" /* Version number. */
XX#define TEMPFIL "PEP.TMP" /* Tempfile. */
XX
XX
XX/*---( constants )----------------------------------------------------------*/
XX
XXstatic char about1[] = "\n\
XXPep is a program that converts almost anything into plain text files.\n\
XXPermission is granted to make and distribute copies of this program as\n\
XXlong as the copyright and this notice appears; and that all the files\n\
XXin the distribution is included. ( The files in the distribution is\n\
XXdocumented in the release note file \"aaread.me\". )\n\n";
XX
XXstatic char about2[] = "\
XXBug reports, improvements, comments, suggestions and flames to:\n\
XX snail: Gisle Hannemyr, Brageveien 3A, 0452 Oslo, Norway\n\
XX email: EAN: gisle at nr.uninett;\n\
XX Inet: gisle at ifi.uio.no;\n\
XX UUCP: ...!mcvax!ifi!gisle\n\
XX (and several BBS mailboxes).\n";
XX
XXstatic char usage1[] = " Usage: pep [options] [filename ...]\n\
XX Valid options:\n\
XX\t-a -- about pep\n\
XX\t-b -- remove non ASCII-codes\n\
XX\t-c[size] -- compress spaces to tabs\n\
XX\t-d+/- -- convert to/from DEC 8 bit charset\n\
XX\t-e[guard] -- interprete ANSI escape sequences\n\
XX\t-g<file> -- get conversion table from file\n\
XX\t-h -- print this quick summary\n\
XX\t-i+/- -- convert to/from IBM-PC charset\n\
XX\t-k+/- -- convert to/from \"Kman\" charset\n\
XX\t-m+/- -- convert to/from Macintosh charset\n";
XX
XXchar usage2[] = "\
XX\t-o[b] -- write output to named files\n\
XX\t-p -- display transformations and pause\n\
XX\t-s[size] -- extract strings\n\
XX\t-t[size] -- expand tabstops\n\
XX\t-u<term> -- use special line terminator\n\
XX\t-v -- terminate only paragraphs\n\
XX\t-w+/- -- convert to/from WS document mode\n\
XX\t-x -- expand non printing chars\n\
XX\t-z -- zero parity bit\n";
XX
XX
XX/*---( variables )----------------------------------------------------------*/
XX
XXstatic int cright = TRUE; /* Flag copyright undisplayed */
XXstatic int guardl = 0; /* ANSI overwrite guard level */
XX
XXlong LCount = 0L; /* Global line count */
XXint LineXx = 0; /* Horisontal position on line. */
XXint ITabSz = 8; /* Input tabulator size. */
XXint OTabSz = 8; /* Output tabulator size. */
XXint StrSiz = 4; /* String size for strings. */
XX#if __UNIX__ || __VMS__
XXint EndOLn = '\n'; /* Under UNIX, default is LF; */
XX#else
XXint EndOLn = -1; /* else, the default is CRLF. */
XX#endif
XX
XXstatic int backup = FALSE; /* Keep backup copy. */
XX int bflagb = FALSE; /* Binary wash. */
XX int cflagc = FALSE; /* Compress */
XX int dflagd = FALSE; /* DEC character set. */
XXstatic int eflage = FALSE; /* ANSI escape sequences. */
XX int gflagg = FALSE; /* General fold table */
XX int iflagi = FALSE; /* IBM character set. */
XX int kflagk = FALSE; /* Kman character set. */
XX int mflagm = FALSE; /* MAC character set. */
XX#ifdef __VMS__
XXstatic int oflago = TRUE; /* VMS has no pipes. */
XX#else
XXstatic int oflago = FALSE; /* Write output on files. */
XX#endif
XXstatic int pflagp = FALSE; /* Pause. */
XX int sflags = FALSE; /* String extraction. */
XX int tflagt = FALSE; /* Tab expansion */
XXstatic int uflagu = FALSE; /* Use special line terminator. */
XX int vflagv = FALSE; /* Terminate only paragraphs. */
XX int wflag0 = FALSE; /* From WS doc. mode to 7-bit. */
XX int wflag1 = FALSE; /* From 7-bit to WS doc. mode. */
XX int xflagx = FALSE;
XX int zflagz = FALSE;
XX
XX
XX/*---( housekeeping )-------------------------------------------------------*/
XX
XX
XX/*
XX| Abs: Write control or meta character ii on stderr using standard conventions.
XX*/
XXstatic void fputctl(ii)
XXint ii;
XX{
XX if ((ii < 0) || (ii > 255)) fputs("<BOGUS>",stderr);
XX else if (ii == 255) fputs("M-del",stderr);
XX else if (ii == 127) fputs("DEL",stderr);
XX else {
XX if (ii >= 128) { fputc('M',stderr); fputc('-',stderr); ii -= 128; }
XX if (ii < ' ') { fputc('^',stderr); ii += '@'; }
XX fputc(ii,stderr);
XX } /* else */
XX} /* fputctl */
XX
XX
XX/*
XX| Abs: Display copyright notice.
XX| Sef: Sets the cright flag FALSE so that we only displays it once.
XX*/
XXvoid showcright()
XX{
XX fprintf(stderr,"pep ver. %s; Copyright (c) 1989 Gisle Hannemyr\n",VERSION);
XX cright = FALSE;
XX} /* showcright */
XX
XX
XX/*
XX| Abs: Display message and abort.
XX*/
XXvoid mess(err)
XXint err;
XX{
XX if (cright) showcright();
XX fputs("pep: ",stderr);
XX switch(err) {
XX case 1: fputs("incompatible options", stderr); break;
XX case 2: fputs("missing '+' or '-'", stderr); break;
XX case 3: fputs("bad guard digit", stderr); break;
XX case 4: fputs("invalid line terminator", stderr); break;
XX case 5: fputs("no more room", stderr); break;
XX case 6: fputs("bad conversion table", stderr); break;
XX case 7: fputs("no matching files", stderr); break;
XX case 8: fputs("cannot pause reading stdin", stderr); break;
XX case 9: fputs("sorry, not yet implemented", stderr); break;
XX default: fputs("unknown error", stderr); break;
XX } /* switch */
XX putc('\n',stderr);
XX exit(ERROR_EXIT);
XX} /* mess */
XX
XX
XXvoid showprogress()
XX{
XX LCount++;
XX if (oflago && ((LCount % 64) == 0)) fprintf(stderr,"\r%ld ",LCount);
XX} /* showprogress */
XX
XX
XX/*
XX| Abs: Parse desired line terminator.
XX| Des: r = CR
XX| n = NL
XX| s = RS
XX| # = CRLF
XX| - = none
XX| <number> = use this as the terminator
XX| Sef: IFrst, ILast, ILimit.
XX*/
XXvoid getterm(ss)
XXchar *ss;
XX{
XX if (*ss == 'n') EndOLn = '\n';
XX else if (*ss == 'r') EndOLn = '\r';
XX else if (*ss == 's') EndOLn = 30;
XX else if (*ss == '#') EndOLn = -1;
XX else if (*ss == '-') EndOLn = -2;
XX else if (isdigit(*ss)) EndOLn = atoi(ss);
XX else mess(4);
XX} /* getterm */
XX
XX
XX/*
XX| Abs: Check toggle.
XX| Ret: TRUE if toggle is on, else off.
XX*/
XXBOOL swchk(dd)
XXchar dd;
XX{
XX if ((dd != '+') && (dd != '-')) mess(2);
XX return(dd == '+');
XX} /* swchk */
XX
XX
XX/*
XX| Abs: Check fold direction and set up direction flags.
XX| Des: IFrst set to 1 if folding to 8 bit character set.
XX| Sef: IFrst, ILast, ILimit.
XX*/
XXvoid folddir(dd)
XXchar dd;
XX{
XX if (swchk(dd)) { IFrst = 1; ILast = 0; ILimit = 91; }
XX else { IFrst = 0; ILast = 1; ILimit = 128; }
XX} /* folddir */
XX
XX
XX/*
XX| Abs: Show transformations.
XX| Imp: Moved from main() coz MS-C don't like big main functions.
XX*/
XXvoid showoptions(tabledir,cname)
XXchar *tabledir, *cname;
XX{
XX int cc;
XX
XX fputs("Transformations:\n",stderr);
XX if (!vflagv) fputs(" * stripping all trailing spaces;\n",stderr);
XX
XX if (gflagg) {
XX fprintf(stderr," * translating using table in file \"%s\";\n",cname);
XX readtable(tabledir,cname,TRUE);
XX } /* if gflagg */
XX
XX#ifdef __TURBOC__
XX fputs(" * preserving file dates;\n",stderr);
XX#endif
XX if (oflago) fputs(" * output file is input file (not stdout);\n",stderr);
XX if (backup) fputs(" * creating .BAK copies of input file;\n",stderr);
XX if (bflagb) fprintf(stderr," * %sing non ASCII-codes;\n", xflagx ? "expand" : "remov");
XX if (dflagd || iflagi || mflagm) {
XX char *machine;
XX if (dflagd) machine = "DEC";
XX else if (iflagi) machine = "IBM";
XX else if (mflagm) machine = "MAC";
XX if (IFrst) fprintf(stderr," * Norwegian 7-bit ==> 8-bit %s charset", machine);
XX else fprintf(stderr," * 8-bit %s charset ==> norwegian 7-bit", machine);
XX if (kflagk) fputs(",\n using \\\\ for Norwegian \"OE\";\n",stderr);
XX else fputs(";\n",stderr);
XX } /* if (dflagd || iflagi || mflagm) */
XX if (sflags) fprintf(stderr," * extracting strings >= %d characters;\n",StrSiz);
XX if (cflagc && tflagt) {
XX fputs(" * optimizing out spaces from tabulation;\n",stderr);
XX if (ITabSz != OTabSz) fprintf(stderr," * repacking tabs, size: %d --> %d;\n",ITabSz,OTabSz);
XX } else {
XX if (tflagt) fprintf(stderr," * expanding tabs, size: %d;\n",ITabSz);
XX if (cflagc) fprintf(stderr," * inserting tabs, size: %d;\n",OTabSz);
XX }
XX if (eflage) fputs(" * interpreting ANSI escape sequences;\n",stderr);
XX
XX if (wflag0) fputs(" * WS doc. mode ==> 7-bit text files;\n",stderr);
XX if (wflag1) fputs(" * 7-bit text files ==> WS doc. mode;\n",stderr);
XX else {
XX if (EndOLn == -2 ) fputs(" * removing line terminators",stderr);
XX else {
XX if (vflagv) fputs(" * terminating paragraphs only with ",stderr);
XX else fputs(" * terminating lines with ",stderr);
XX if (EndOLn == -1 ) fputs("CRLF",stderr);
XX else if (EndOLn == '\n') fputs("LF", stderr);
XX else if (EndOLn == '\r') fputs("CR", stderr);
XX else if (EndOLn == 30 ) fputs("RS", stderr);
XX else fputctl(EndOLn);
XX } /* if EndOLn != -2 */
XX } /* if else not WS */
XX#ifdef __VMS__
XX fputs(" (Stream_LF);\n",stderr);
XX#else
XX fputs(";\n",stderr);
XX#endif
XX
XX if (zflagz) fputs(" * zeroing parity bit;\n",stderr);
XX fprintf(stderr," * %sing control characters.\n", xflagx ? "expand" : "remov");
XX if (pflagp) {
XX fputs("\nHit CTRL-C to abort, RETURN continue. ",stderr);
XX cc = getc(stdin);
XX if (cc == 3) exit(ERROR_EXIT); /* Not necessary for cooked microes. */
XX } /* if */
XX} /* showoptions */
XX
XX
XX/*
XX| Abs: Do a complete file.
XX| Sef: Zero line cont.
XX*/
XXvoid dofile(eflage)
XXint eflage;
XX{
XX#ifndef __VMS__
XX /* Speed things up using a bigger I/O buffer. */
XX if (setvbuf(Fdi,NULL,_IOFBF,16384) || setvbuf(Fdo,NULL,_IOFBF,16384))
XX mess(5); /* No more room */
XX#endif
XX LCount = 0L;
XX if (eflage) doansi(guardl); else doplain();
XX} /* dofile */
XX
XX
XX/*---( main )---------------------------------------------------------------*/
XX
XXmain(argc, argv)
XXint argc;
XXchar **argv;
XX{
XX struct stat statbuf;
XX unsigned int statype;
XX unsigned int statmod;
XX char *tabledir;
XX char *cname, *nname, *ss;
XX int cc;
XX char dd;
XX#if __CPM86__ || __MSDOS__
XX char *cp;
XX struct DIRLIST *first, *last;
XX#endif
XX#ifdef __TURBOC__
XX struct ftime *filtim;
XX int hh;
XX#endif
XX
XX#ifdef __MSDOS__
XX _fmode = O_BINARY; /* Tell MS-C, Turbo not to do CRLF expansion. */
XX tabledir = argv[0]; /* Look for tables in startup-directory. */
XX#else
XX tabledir = NULL; /* No such startup convention for other OS's. */
XX#endif
XX
XX inittable();
XX
XX argc--; argv++; /* skip program name */
XX while (argc && (**argv == '-')) {
XX (*argv)++; /* skip initial '-' */
XX cc = **argv; /* option letter */
XX#ifdef __CPM86__
XX cc = tolower(cc);
XX#endif
XX (*argv)++; /* skip option letter */
XX dd = **argv; /* arg argument */
XX switch (cc) {
XX case 'a': showcright(); fputs(about1, stderr); fputs(about2, stderr);
XX exit(NORML_EXIT);
XX case 'b': bflagb++; break;
XX case 'c': cflagc++; if (**argv != '\0') OTabSz = atoi(*argv); break;
XX case 'd': dflagd++; folddir(dd); break;
XX case 'e': eflage++; if (**argv != '\0') guardl = atoi(*argv);
XX tflagt++;
XX break;
XX case 'g': gflagg++; cname = *argv; break;
XX /* 'h': OK to fall thru' to default */
XX case 'i': iflagi++; folddir(dd); break;
XX case 'k': kflagk++; folddir(dd); break;
XX case 'm': mflagm++; folddir(dd); break;
XX case 'o': oflago++; if (dd == 'b') backup++; break;
XX case 'p': pflagp++; break;
XX case 's': sflags++; if (**argv != '\0') StrSiz = atoi(*argv); break;
XX case 't': tflagt++; if (**argv != '\0') ITabSz = atoi(*argv); break;
XX case 'u': uflagu++; if (**argv != '\0') getterm(*argv); else mess(4); break;
XX case 'v': vflagv++; break;
XX case 'w': if (swchk(dd)) tflagt = wflag1 = TRUE;
XX else zflagz = wflag0 = TRUE;
XX break;
XX case 'x': xflagx++; break;
XX case 'z': zflagz++; break;
XX default : showcright();
XX fputs(usage1,stderr); fputs(usage2,stderr);
XX exit(NORML_EXIT);
XX } /* switch */
XX argc--; argv++;
XX } /* while options */
XX
XX if (pflagp && !argc) mess(8);
XX if ((dflagd + gflagg + iflagi + mflagm + zflagz) > 1) mess(1);
XX if ((guardl < 0) || (guardl > 2)) mess(3);
XX if (kflagk && !(dflagd + mflagm)) iflagi++;
XX if (!uflagu && dflagd && IFrst) EndOLn = '\n'; /* To DEC (Dec uses LF as terminator) */
XX if (!uflagu && iflagi && IFrst) EndOLn = -1; /* To IBM (Uses CRLF as terminator) */
XX if (!uflagu && mflagm && IFrst) EndOLn = '\r'; /* To Mac (Mac uses CR as terminator) */
XX
XX Fdi = stdin; /* Default */
XX Fdo = stdout;
XX#ifdef __MSDOS__
XX setmode(fileno(Fdi),_fmode); /* Make sure that even braindamaged MS-DOS */
XX setmode(fileno(Fdo),_fmode); /* are transparent when redirecting i/o. */
XX#endif
XX if (!argc) { /* Doing standard input */
XX if (pflagp) showoptions(tabledir,cname);
XX else if (gflagg) readtable(tabledir,cname,FALSE);
XX if (oflago) mess(7);
XX dofile(eflage);
XX } else {
XX showcright();
XX showoptions(tabledir,cname);
XX#if __CPM86__ || __MSDOS__
XX first = expwildcard(argv);
XX if (!first) mess(7);
XX /* Inv: first now points to a start of linked list of files. */
XX last = first;
XX while (last) {
XX cname = last->fnam;
XX if (oflago) {
XX putc('\r',stderr);
XX putc('\n',stderr);
XX#else
XX while (argc) {
XX cname = *argv;
XX if (oflago) {
XX putc('\n',stderr);
XX#endif
XX fputs(cname,stderr);
XX } /* if oflago */
XX
XX#ifdef __UNIX__
XX if (lstat(cname,&statbuf)) {
XX#else
XX if (stat(cname,&statbuf)) {
XX#endif
XX if (!oflago) fputs(cname,stderr);
XX fputs(": can't access\n", stderr);
XX goto cont;
XX } /* if not stat */
XX statmod = statbuf.st_mode;
XX statype = statbuf.st_mode & S_IFMT;
XX
XX if (statype != S_IFREG) {
XX if (!oflago) fputs(cname,stderr);
XX if (statype == S_IFDIR) fputs(": directory\n", stderr);
XX#ifdef __UNIX__
XX else if (statype == S_IFLNK) fputs(": symbolic link\n", stderr);
XX#endif
XX else fputs(": special file\n", stderr);
XX goto cont;
XX } /* if not a regular file */
XX
XX if ((Fdi = fopen(cname,"r")) == NULL) {
XX if (!oflago) fputs(cname,stderr);
XX fputs(": can't open\n", stderr);
XX goto cont;
XX }
XX if (oflago) if ((Fdo = fopen(TEMPFIL,"w")) == NULL) {
XX fputs(": can't create tmpfile\n",stderr); exit(ERROR_EXIT);
XX }
XX#ifdef __TURBOC__
XX if (!(filtim = (struct ftime *)malloc(sizeof(struct ftime))))
XX mess(5); /* No more room */
XX getftime(fileno(Fdi),filtim);
XX#endif
XX if (oflago) putc('\n',stderr);
XX dofile(eflage);
XX if (oflago) fprintf(stderr,"\r Done. %ld lines written.",LCount);
XX
XX if (ferror(Fdi) || ferror(Fdo)) {
XX fputs("\npep: I/O error, file unchanged\n", stderr);
XX } else {
XX fclose(Fdi);
XX if (oflago) {
XX fclose(Fdo);
XX if (chmod(TEMPFIL,statmod)) fputs("\npep: could not set mode\n",stderr);
XX#ifdef __TURBOC__
XX if ((hh = _open(TEMPFIL,O_RDONLY)) != -1) setftime(hh,filtim);
XX _close(hh);
XX#endif
XX } /* if (oflago) */
XX
XX cc = 0; /* error flag */
XX if (backup) {
XX if (!(nname = (char *)malloc(strlen(cname)+5))) mess(5);
XX strcpy(nname,cname);
XX if (ss = strrchr(nname,'.')) *ss = '\0';
XX strcat(nname,".BAK");
XX unlink(nname);
XX#ifdef __UNIX__
XX if (strcmp(nname,cname)) { /* UNIX names are case sensitive */
XX#else
XX if (stricmp(nname,cname)) { /* other filenames are not. */
XX#endif
XX if (rename(cname,nname)) cc++;
XX } /* if same names */
XX } else {
XX if (oflago) if (unlink(cname)) cc++;
XX } /* if .. else no backup */
XX if (oflago) if (rename(TEMPFIL,cname)) cc++;
XX if (cc) {
XX fprintf(stderr, "\npep: error creating %s, file is %s\n",cname,TEMPFIL);
XX exit(ERROR_EXIT);
XX } /* if error */
XX } /* if .. else close file */
XXcont:
XX#if __CPM86__ || __MSDOS__
XX last = last->next;
XX } /* while */
XX dispwildcard(first);
XX#else
XX argc--; argv++;
XX } /* while */
XX if (oflago) putc('\n',stderr);
XX#endif
XX } /* if .. else read named files */
XX exit(NORML_EXIT);
XX} /* main */
XX
XX/* EOF */
SHAR_EOF
if test 21491 -ne "`wc -c main.c`"
then
echo shar: error transmitting main.c '(should have been 21491 characters)'
fi
# End of shell archive
exit 0
More information about the Comp.sources.misc
mailing list