Fix naming covention for uniq(1)

This commit is contained in:
sin 2014-01-20 10:47:46 +00:00
parent 13128a7aa0
commit cb005c150d

47
uniq.c
View File

@ -8,16 +8,16 @@
#include "text.h" #include "text.h"
#include "util.h" #include "util.h"
static void uniq_line(char *); static void uniqline(char *);
static void uniq(FILE *, const char *); static void uniq(FILE *, const char *);
static void uniq_finish(void); static void uniqfinish(void);
static const char *countfmt = ""; static const char *countfmt = "";
static bool dflag = false; static bool dflag = false;
static bool uflag = false; static bool uflag = false;
static char *prev_line = NULL; static char *prevline = NULL;
static long prev_line_count = 0; static long prevlinecount = 0;
static void static void
usage(void) usage(void)
@ -55,36 +55,36 @@ main(int argc, char *argv[])
fclose(fp); fclose(fp);
} else } else
usage(); usage();
uniq_finish(); uniqfinish();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
void void
uniq_line(char *l) uniqline(char *l)
{ {
bool lines_equal = ((l == NULL) || (prev_line == NULL)) bool linesequal = ((l == NULL) || (prevline == NULL))
? l == prev_line ? l == prevline
: !strcmp(l, prev_line); : !strcmp(l, prevline);
if(lines_equal) { if(linesequal) {
++prev_line_count; ++prevlinecount;
return; return;
} }
if(prev_line != NULL) { if(prevline != NULL) {
if((prev_line_count == 1 && !dflag) || if((prevlinecount == 1 && !dflag) ||
(prev_line_count != 1 && !uflag)) { (prevlinecount != 1 && !uflag)) {
printf(countfmt, prev_line_count); printf(countfmt, prevlinecount);
fputs(prev_line, stdout); fputs(prevline, stdout);
} }
free(prev_line); free(prevline);
prev_line = NULL; prevline = NULL;
} }
if(l && !(prev_line = strdup(l))) if(l && !(prevline = strdup(l)))
eprintf("strdup:"); eprintf("strdup:");
prev_line_count = 1; prevlinecount = 1;
} }
void void
@ -94,12 +94,11 @@ uniq(FILE *fp, const char *str)
size_t size = 0; size_t size = 0;
while(afgets(&buf, &size, fp)) while(afgets(&buf, &size, fp))
uniq_line(buf); uniqline(buf);
} }
void void
uniq_finish() uniqfinish()
{ {
uniq_line(NULL); uniqline(NULL);
} }