1
0
mirror of git://git.suckless.org/sbase synced 2024-12-23 07:25:07 +00:00

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