cut.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5 */
#include <ctype.h>
#include "wish.h"
#include "ctl.h"
#include "eval.h"
#include "moremacros.h"
#include "message.h"
#include "sizes.h"
/* cut : cut and paste columns of a table (projection of a relation) */
/* Release 1.5; handles single backspaces as produced by nroff */
# define BACKSPACE '\b'
void exit();
char *getastr(); /* rjk */
static char usage[] = "Usage: fmlcut [-s] [-d<char>] {-c<list> | -f<list>} file ...";
static char cflist[] = "bad list for c/f option";
int argc;
char *argv[];
{
extern int optind;
extern char *optarg;
register int c;
register char *p, *list;
register int i;
int del = '\t';
int fromfile; /* rjk */
for (i = 0; i < NFIELDS; i++)
sel[i] = 0;
optind = 1;
switch(c) {
case 'c':
if (fflag)
cflag++;
break;
case 'd':
diag("no delimiter");
else
break;
case 'f':
if (cflag)
fflag++;
break;
case 's':
supflag++;
break;
case '?':
}
do {
p = list;
switch(*p) {
case '-':
if (r)
r = 1;
if (num == 0)
s = 1;
else {
s = num;
num = 0;
}
break;
case '\0' :
case ',' :
if (r) {
if (num == 0)
if (num < s)
for (j = s; j <= num; j++)
sel[j] = 1;
} else
s = num = r = 0;
if (*p == '\0')
continue;
break;
default:
if (!isdigit(*p))
list++;
continue;
}
list++;
}while (*p != '\0');
if (j >= NFIELDS)
return(diag("no fields"));
filenr = 0;
do { /* for all input files */
fromfile = 0;
else {
/* rjk */
continue;
}
else
fromfile++;
}
endflag = 0;
do { /* for all lines of a file */
/* rjk ... from a file or form Instr) */
endflag = 1;
continue;
}
do { /* for all char of the line */
return(diag("line too long"));
if (*rbuf != '\n')
backflag++;
else if (!backflag)
poscnt += 1;
else
backflag--;
if ( backflag > 1 )
return(diag("cannot handle multiple adjacent backspaces\n"));
count += 1;
if (fflag)
else
}
} while (*rbuf++ != '\n');
else
*++p1 = '\0';
}
} while (!endflag);
if (fromfile)
return(SUCCESS); /* rjk */
}
diag(s)
char *s;
{
/* for now
fprintf(stderr, "fmlcut: ERROR: %s\n", s);
exit(2);
*/
mess_temp(s);
mess_lock();
return(FAIL);
}