version 1.4, 1997/07/25 21:05:46 |
version 1.5, 1997/07/25 22:21:40 |
|
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
|
#include <err.h> |
|
|
#define MAXLINELEN (8 * 1024) |
#define MAXLINELEN (8 * 1024) |
|
|
int cflag, dflag, uflag; |
int cflag, dflag, uflag; |
int numchars, numfields, repeats; |
int numchars, numfields, repeats; |
|
|
void err __P((const char *, ...)); |
|
FILE *file __P((char *, char *)); |
FILE *file __P((char *, char *)); |
void show __P((FILE *, char *)); |
void show __P((FILE *, char *)); |
char *skip __P((char *)); |
char *skip __P((char *)); |
|
|
case 'f': |
case 'f': |
numfields = strtol(optarg, &p, 10); |
numfields = strtol(optarg, &p, 10); |
if (numfields < 0 || *p) |
if (numfields < 0 || *p) |
err("illegal field skip value: %s", optarg); |
errx(1, "illegal field skip value: %s", optarg); |
break; |
break; |
case 's': |
case 's': |
numchars = strtol(optarg, &p, 10); |
numchars = strtol(optarg, &p, 10); |
if (numchars < 0 || *p) |
if (numchars < 0 || *p) |
err("illegal character skip value: %s", optarg); |
errx(1, "illegal character skip value: %s", optarg); |
break; |
break; |
case 'u': |
case 'u': |
uflag = 1; |
uflag = 1; |
|
|
prevline = malloc(MAXLINELEN); |
prevline = malloc(MAXLINELEN); |
thisline = malloc(MAXLINELEN); |
thisline = malloc(MAXLINELEN); |
if (prevline == NULL || thisline == NULL) |
if (prevline == NULL || thisline == NULL) |
err("%s", strerror(errno)); |
err(1, "malloc"); |
|
|
if (fgets(prevline, MAXLINELEN, ifp) == NULL) |
if (fgets(prevline, MAXLINELEN, ifp) == NULL) |
exit(0); |
exit(0); |
|
|
FILE *fp; |
FILE *fp; |
|
|
if ((fp = fopen(name, mode)) == NULL) |
if ((fp = fopen(name, mode)) == NULL) |
err("%s: %s", name, strerror(errno)); |
err(1, name); |
return(fp); |
return(fp); |
} |
} |
|
|
|
|
*/ |
*/ |
len = strlen(ap); |
len = strlen(ap); |
if ((start = p = malloc(len + 3)) == NULL) |
if ((start = p = malloc(len + 3)) == NULL) |
err("%s", strerror(errno)); |
err(1, "malloc"); |
*p++ = '-'; |
*p++ = '-'; |
*p++ = ap[0] == '+' ? 's' : 'f'; |
*p++ = ap[0] == '+' ? 's' : 'f'; |
(void)strcpy(p, ap + 1); |
(void)strcpy(p, ap + 1); |
|
|
(void)fprintf(stderr, |
(void)fprintf(stderr, |
"usage: uniq [-c | -du] [-f fields] [-s chars] [input [output]]\n"); |
"usage: uniq [-c | -du] [-f fields] [-s chars] [input [output]]\n"); |
exit(1); |
exit(1); |
} |
|
|
|
#ifdef __STDC__ |
|
#include <stdarg.h> |
|
#else |
|
#include <varargs.h> |
|
#endif |
|
|
|
void |
|
#ifdef __STDC__ |
|
err(const char *fmt, ...) |
|
#else |
|
err(fmt, va_alist) |
|
char *fmt; |
|
va_dcl |
|
#endif |
|
{ |
|
va_list ap; |
|
#ifdef __STDC__ |
|
va_start(ap, fmt); |
|
#else |
|
va_start(ap); |
|
#endif |
|
(void)fprintf(stderr, "uniq: "); |
|
(void)vfprintf(stderr, fmt, ap); |
|
va_end(ap); |
|
(void)fprintf(stderr, "\n"); |
|
exit(1); |
|
/* NOTREACHED */ |
|
} |
} |