[hackers] [sbase] Rename linecmp and line-structs in join(1) and sort(1) || FRIGN

From: <git_AT_suckless.org>
Date: Thu, 10 Mar 2016 09:48:17 +0100 (CET)

commit 54d3f3b3a5a24276b054d573bee1325da1f4495a
Author: FRIGN <dev_AT_frign.de>
AuthorDate: Mon Mar 7 01:58:31 2016 +0100
Commit: sin <sin_AT_2f30.org>
CommitDate: Thu Mar 10 08:48:09 2016 +0000

    Rename linecmp and line-structs in join(1) and sort(1)
    
    We will steal the names for the global functions.

diff --git a/join.c b/join.c
index caf592f..93d4b38 100644
--- a/join.c
+++ b/join.c
_AT_@ -26,7 +26,7 @@ struct field {
         size_t len;
 };
 
-struct line {
+struct jline {
         char *text;
         size_t nf;
         size_t maxf;
_AT_@ -47,7 +47,7 @@ struct outlist {
 struct span {
         size_t nl;
         size_t maxl;
- struct line **lines;
+ struct jline **lines;
 };
 
 static char *sep = NULL;
_AT_@ -84,9 +84,9 @@ prsep(void)
 }
 
 static void
-swaplines(struct line *la, struct line *lb)
+swaplines(struct jline *la, struct jline *lb)
 {
- struct line tmp;
+ struct jline tmp;
 
         tmp = *la;
         *la = *lb;
_AT_@ -94,7 +94,7 @@ swaplines(struct line *la, struct line *lb)
 }
 
 static void
-prjoin(struct line *la, struct line *lb, size_t jfa, size_t jfb)
+prjoin(struct jline *la, struct jline *lb, size_t jfa, size_t jfb)
 {
         struct spec *sp;
         struct field *joinfield;
_AT_@ -149,7 +149,7 @@ prjoin(struct line *la, struct line *lb, size_t jfa, size_t jfb)
 }
 
 static void
-prline(struct line *lp)
+prline(struct jline *lp)
 {
         size_t len = strlen(lp->text);
 
_AT_@ -160,7 +160,7 @@ prline(struct line *lp)
 }
 
 static int
-linecmp(struct line *la, struct line *lb, size_t jfa, size_t jfb)
+jlinecmp(struct jline *la, struct jline *lb, size_t jfa, size_t jfb)
 {
         int status;
 
_AT_@ -179,7 +179,7 @@ linecmp(struct line *la, struct line *lb, size_t jfa, size_t jfb)
 }
 
 static void
-addfield(struct line *lp, char *sp, size_t len)
+addfield(struct jline *lp, char *sp, size_t len)
 {
         if (lp->nf >= lp->maxf) {
                 lp->fields = ereallocarray(lp->fields, (GROW * lp->maxf),
_AT_@ -201,10 +201,10 @@ prspanjoin(struct span *spa, struct span *spb, size_t jfa, size_t jfb)
                         prjoin(spa->lines[i], spb->lines[j], jfa, jfb);
 }
 
-static struct line *
+static struct jline *
 makeline(char *s, size_t len)
 {
- struct line *lp;
+ struct jline *lp;
         char *sp, *beg, *end;
         size_t i;
         int eol = 0;
_AT_@ -212,7 +212,7 @@ makeline(char *s, size_t len)
         if (s[len-1] == '\n')
                 s[len-1] = '\0';
 
- lp = ereallocarray(NULL, INIT, sizeof(struct line));
+ lp = ereallocarray(NULL, INIT, sizeof(struct jline));
         lp->text = s;
         lp->fields = ereallocarray(NULL, INIT, sizeof(struct field));
         lp->nf = 0;
_AT_@ -274,7 +274,7 @@ addtospan(struct span *sp, FILE *fp, int reset)
 
         if (sp->nl >= sp->maxl) {
                 sp->lines = ereallocarray(sp->lines, (GROW * sp->maxl),
- sizeof(struct line *));
+ sizeof(struct jline *));
                 sp->maxl *= GROW;
         }
 
_AT_@ -288,7 +288,7 @@ initspan(struct span *sp)
 {
         sp->nl = 0;
         sp->maxl = INIT;
- sp->lines = ereallocarray(NULL, INIT, sizeof(struct line *));
+ sp->lines = ereallocarray(NULL, INIT, sizeof(struct jline *));
 }
 
 static void
_AT_@ -385,7 +385,7 @@ join(FILE *fa, FILE *fb, size_t jfa, size_t jfb)
         addtospan(&spb, fb, RESET);
 
         while (spa.nl && spb.nl) {
- if ((cmp = linecmp(spa.lines[0], spb.lines[0], jfa, jfb)) < 0) {
+ if ((cmp = jlinecmp(spa.lines[0], spb.lines[0], jfa, jfb)) < 0) {
                         if (unpairsa)
                                 prline(spa.lines[0]);
                         if (!addtospan(&spa, fa, RESET)) {
_AT_@ -419,7 +419,7 @@ join(FILE *fa, FILE *fb, size_t jfa, size_t jfb)
                                         spa.nl++;
                                         break;
                                 }
- } while (linecmp(spa.lines[spa.nl-1], spb.lines[0], jfa, jfb) == 0);
+ } while (jlinecmp(spa.lines[spa.nl-1], spb.lines[0], jfa, jfb) == 0);
 
                         /* read all consecutive matching lines from b */
                         do {
_AT_@ -428,7 +428,7 @@ join(FILE *fa, FILE *fb, size_t jfa, size_t jfb)
                                         spb.nl++;
                                         break;
                                 }
- } while (linecmp(spa.lines[0], spb.lines[spb.nl-1], jfa, jfb) == 0);
+ } while (jlinecmp(spa.lines[0], spb.lines[spb.nl-1], jfa, jfb) == 0);
 
                         if (pairs)
                                 prspanjoin(&spa, &spb, jfa, jfb);
diff --git a/sort.c b/sort.c
index 6479461..9b88b94 100644
--- a/sort.c
+++ b/sort.c
_AT_@ -171,7 +171,7 @@ skipmodcmp(struct linebufline *a, struct linebufline *b, int flags)
 }
 
 static int
-linecmp(struct linebufline *a, struct linebufline *b)
+slinecmp(struct linebufline *a, struct linebufline *b)
 {
         int res = 0;
         long double x, y;
_AT_@ -218,7 +218,7 @@ check(FILE *fp, const char *fname)
         if (!prev.data && (prev.len = getline(&prev.data, &prevsize, fp)) < 0)
                 eprintf("getline:");
         while ((cur.len = getline(&cur.data, &cursize, fp)) > 0) {
- if (uflag > linecmp(&cur, &prev)) {
+ if (uflag > slinecmp(&cur, &prev)) {
                         if (!Cflag) {
                                 weprintf("disorder %s: ", fname);
                                 fwrite(cur.data, 1, cur.len, stderr);
_AT_@ -412,11 +412,11 @@ main(int argc, char *argv[])
                         eprintf("fopen %s:", outfile);
 
                 qsort(linebuf.lines, linebuf.nlines, sizeof(*linebuf.lines),
- (int (*)(const void *, const void *))linecmp);
+ (int (*)(const void *, const void *))slinecmp);
 
                 for (i = 0; i < linebuf.nlines; i++) {
                         if (!uflag || i == 0 ||
- linecmp(&linebuf.lines[i], &linebuf.lines[i - 1])) {
+ slinecmp(&linebuf.lines[i], &linebuf.lines[i - 1])) {
                                 fwrite(linebuf.lines[i].data, 1,
                                        linebuf.lines[i].len, ofp);
                         }
Received on Thu Mar 10 2016 - 09:48:17 CET

This archive was generated by hypermail 2.3.0 : Thu Mar 10 2016 - 10:00:35 CET