chiark / gitweb /
Group counters into struct
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 29 May 2010 12:56:16 +0000 (13:56 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 29 May 2010 12:56:16 +0000 (13:56 +0100)
cli.c
infile.c
innduct.h
recv.c
statemc.c
xmit.c

diff --git a/cli.c b/cli.c
index b03f37065c799d175edfc627d95e0a85f92a5764..be9af383e0745cdbd4448d5be14db86e4e301c75 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -329,17 +329,17 @@ static void dump_input_file(FILE *f, const CliCommand *c,
   free(dipf);
   
   if (ipf) {
   free(dipf);
   
   if (ipf) {
-    DUMPV("%d", ipf->,readcount_ok);
-    DUMPV("%d", ipf->,readcount_blank);
-    DUMPV("%d", ipf->,readcount_err);
-    DUMPV("%d", ipf->,count_nooffer_missing);
+    DUMPV("%d", ipf->counts.,read_ok);
+    DUMPV("%d", ipf->counts.,read_blank);
+    DUMPV("%d", ipf->counts.,read_err);
+    DUMPV("%d", ipf->counts.,nooffer_missing);
   }
   fprintf(f,"\n");
   if (ipf) {
     ArtState state; const char *const *statename; 
     for (state=0, statename=artstate_names; *statename; state++,statename++) {
 #define RC_DUMP_FMT(x) " " #x "=%d"
   }
   fprintf(f,"\n");
   if (ipf) {
     ArtState state; const char *const *statename; 
     for (state=0, statename=artstate_names; *statename; state++,statename++) {
 #define RC_DUMP_FMT(x) " " #x "=%d"
-#define RC_DUMP_VAL(x) ,ipf->counts[state][RC_##x]
+#define RC_DUMP_VAL(x) ,ipf->counts.counts[state][RC_##x]
       fprintf(f,"input %s counts %-11s"
              RESULT_COUNTS(RC_DUMP_FMT,RC_DUMP_FMT) "\n",
              wh, *statename
       fprintf(f,"input %s counts %-11s"
              RESULT_COUNTS(RC_DUMP_FMT,RC_DUMP_FMT) "\n",
              wh, *statename
index 3fc1ff6c945500db7c68e5ef69fe0ede2eecc2d0..7ff6a518573a862d6615a4dafef8deab8dc46c6f 100644 (file)
--- a/infile.c
+++ b/infile.c
@@ -77,11 +77,11 @@ static void *feedfile_got_bad_data(InputFile *ipf, off_t offset,
                                   const char *data, const char *how) {
   warn("corrupted file: %s, offset %lu: %s: in %s",
        ipf->path, (unsigned long)offset, how, sanitise(data,-1));
                                   const char *data, const char *how) {
   warn("corrupted file: %s, offset %lu: %s: in %s",
        ipf->path, (unsigned long)offset, how, sanitise(data,-1));
-  ipf->readcount_err++;
-  if (ipf->readcount_err > max_bad_data_initial +
-      (ipf->readcount_ok+ipf->readcount_blank) / max_bad_data_ratio)
+  ipf->counts.read_err++;
+  if (ipf->counts.read_err > max_bad_data_initial +
+      (ipf->counts.read_ok + ipf->counts.read_blank) / max_bad_data_ratio)
     crash("too much garbage in input file!  (%d errs, %d ok, %d blank)",
     crash("too much garbage in input file!  (%d errs, %d ok, %d blank)",
-         ipf->readcount_err, ipf->readcount_ok, ipf->readcount_blank);
+         ipf->counts.read_err, ipf->counts.read_ok, ipf->counts.read_blank);
   return OOP_CONTINUE;
 }
 
   return OOP_CONTINUE;
 }
 
@@ -129,7 +129,7 @@ static void *feedfile_got_article(oop_source *lp, oop_read *rd,
 
   if (data[0]==' ') {
     if (strspn(data," ") != recsz) X_BAD_DATA("line partially blanked");
 
   if (data[0]==' ') {
     if (strspn(data," ") != recsz) X_BAD_DATA("line partially blanked");
-    ipf->readcount_blank++;
+    ipf->counts.read_blank++;
     return OOP_CONTINUE;
   }
 
     return OOP_CONTINUE;
   }
 
@@ -144,7 +144,7 @@ static void *feedfile_got_article(oop_source *lp, oop_read *rd,
   tokentextbuf[tokenlen]= 0;
   if (!IsToken(tokentextbuf)) X_BAD_DATA("token wrong syntax");
 
   tokentextbuf[tokenlen]= 0;
   if (!IsToken(tokentextbuf)) X_BAD_DATA("token wrong syntax");
 
-  ipf->readcount_ok++;
+  ipf->counts.read_ok++;
 
   art= xmalloc(sizeof(*art) - 1 + midlen + 1);
   memset(art,0,sizeof(*art));
 
   art= xmalloc(sizeof(*art) - 1 + midlen + 1);
   memset(art,0,sizeof(*art));
index 65077d66b865a80f19d6fbe4a0e2be735ed3d4c6..919b734abfc986b829226a7c89b58eb6277b7829 100644 (file)
--- a/innduct.h
+++ b/innduct.h
@@ -237,6 +237,11 @@ struct XmitDetails {
 
 /*----- core operational data structure types -----*/
 
 
 /*----- core operational data structure types -----*/
 
+typedef struct {
+  int counts[art_MaxState][RCI_max];
+  int read_ok, read_blank, read_err, nooffer_missing;
+} Counts;
+
 struct InputFile {
   /* This is also an instance of struct oop_readable */
   struct oop_readable readable; /* first */
 struct InputFile {
   /* This is also an instance of struct oop_readable */
   struct oop_readable readable; /* first */
@@ -254,8 +259,7 @@ struct InputFile {
   long inprogress; /* includes queue.count and also articles in conns */
   long autodefer; /* -1 means not doing autodefer */
 
   long inprogress; /* includes queue.count and also articles in conns */
   long autodefer; /* -1 means not doing autodefer */
 
-  int counts[art_MaxState][RCI_max];
-  int readcount_ok, readcount_blank, readcount_err, count_nooffer_missing;
+  Counts counts;
   char path[];
 };
 
   char path[];
 };
 
diff --git a/recv.c b/recv.c
index dbeb4b68bb47b3815ba8b25ecc56e41d462e8657..5204dced0e7cca479f17900f712c73092be0957b 100644 (file)
--- a/recv.c
+++ b/recv.c
@@ -117,7 +117,7 @@ static void update_nocheck(int accepted) {
 
 void article_done(Article *art, int whichcount) {
   if (whichcount>=0 && !art->missing)
 
 void article_done(Article *art, int whichcount) {
   if (whichcount>=0 && !art->missing)
-    art->ipf->counts[art->state][whichcount]++;
+    art->ipf->counts.counts[art->state][whichcount]++;
 
   if (whichcount == RC_accepted) update_nocheck(1);
   else if (whichcount == RC_unwanted) update_nocheck(0);
 
   if (whichcount == RC_accepted) update_nocheck(1);
   else if (whichcount == RC_unwanted) update_nocheck(0);
@@ -242,7 +242,7 @@ void *peer_rd_ok(oop_source *lp, oop_read *oread, oop_rd_event ev,
   case 335: /* IHAVE says send it */
     GET_ARTICLE(-1);
     assert(art->state == art_Unchecked);
   case 335: /* IHAVE says send it */
     GET_ARTICLE(-1);
     assert(art->state == art_Unchecked);
-    art->ipf->counts[art->state][RC_accepted]++;
+    art->ipf->counts.counts[art->state][RC_accepted]++;
     art->state= art_Wanted;
     LIST_ADDTAIL(conn->priority, art);
     break;
     art->state= art_Wanted;
     LIST_ADDTAIL(conn->priority, art);
     break;
index 5adecf95997cd79df2ea2dd3d4eb5746b7274547..8b588039b9e4f45e427f93a4e1da8a85dec9dda0 100644 (file)
--- a/statemc.c
+++ b/statemc.c
@@ -222,9 +222,9 @@ static void notice_processed(InputFile *ipf, int completed,
 
 #define RCI_NOTHING(x) /* nothing */
 #define RCI_TRIPLE_FMT(x) " " #x "=" RCI_TRIPLE_FMT_BASE
 
 #define RCI_NOTHING(x) /* nothing */
 #define RCI_TRIPLE_FMT(x) " " #x "=" RCI_TRIPLE_FMT_BASE
-#define RCI_TRIPLE_VALS(x) , RCI_TRIPLE_VALS_BASE(ipf->counts, [RC_##x])
+#define RCI_TRIPLE_VALS(x) , RCI_TRIPLE_VALS_BASE(ipf->counts.counts, [RC_##x])
 
 
-#define CNT(art,rc) (ipf->counts[art_##art][RC_##rc])
+#define CNT(art,rc) (ipf->counts.counts[art_##art][RC_##rc])
 
   char *inprog= completed
     ? xasprintf("%s","") /* GCC produces a stupid warning for printf("") ! */
 
   char *inprog= completed
     ? xasprintf("%s","") /* GCC produces a stupid warning for printf("") ! */
@@ -238,8 +238,8 @@ static void notice_processed(InputFile *ipf, int completed,
        RESULT_COUNTS(RCI_NOTHING, RCI_TRIPLE_FMT)
        ,
        completed?"completed":"processed", what, spec,
        RESULT_COUNTS(RCI_NOTHING, RCI_TRIPLE_FMT)
        ,
        completed?"completed":"processed", what, spec,
-       ipf->readcount_ok, ipf->readcount_blank, ipf->readcount_err,
-       inprog, autodefer, ipf->count_nooffer_missing,
+       ipf->counts.read_ok, ipf->counts.read_blank, ipf->counts.read_err,
+       inprog, autodefer, ipf->counts.nooffer_missing,
        CNT(Unchecked,sent) + CNT(Unsolicited,sent)
        , CNT(Unchecked,sent), CNT(Unsolicited,sent),
        CNT(Wanted,accepted) + CNT(Unsolicited,accepted)
        CNT(Unchecked,sent) + CNT(Unsolicited,sent)
        , CNT(Unchecked,sent), CNT(Unsolicited,sent),
        CNT(Wanted,accepted) + CNT(Unsolicited,accepted)
@@ -247,9 +247,7 @@ static void notice_processed(InputFile *ipf, int completed,
        RESULT_COUNTS(RCI_NOTHING,  RCI_TRIPLE_VALS)
        );
 
        RESULT_COUNTS(RCI_NOTHING,  RCI_TRIPLE_VALS)
        );
 
-  memset(ipf->counts, 0, sizeof(ipf->counts));
-  ipf->readcount_ok= ipf->readcount_blank=
-    ipf->readcount_err= ipf->count_nooffer_missing= 0;
+  memset(&ipf->counts, 0, sizeof(ipf->counts));
 
   free(inprog);
   free(autodefer);
 
   free(inprog);
   free(autodefer);
diff --git a/xmit.c b/xmit.c
index 269e823a91002abd0bb8a6ca7a90eca481cf2e29..a4389166b48e59da3eed973d79648ba226cf9112 100644 (file)
--- a/xmit.c
+++ b/xmit.c
@@ -174,7 +174,7 @@ int article_check_expired(Article *art /* must be queued, not conn */) {
 
   LIST_REMOVE(art->ipf->queue, art);
   art->missing= 1;
 
   LIST_REMOVE(art->ipf->queue, art);
   art->missing= 1;
-  art->ipf->count_nooffer_missing++;
+  art->ipf->counts.nooffer_missing++;
   article_done(art,-1);
   return 1;
 }
   article_done(art,-1);
   return 1;
 }
@@ -329,7 +329,7 @@ void conn_make_some_xmits(Conn *conn) {
        (abort(),-1);
 
       if (!artdata) art->missing= 1;
        (abort(),-1);
 
       if (!artdata) art->missing= 1;
-      art->ipf->counts[art->state][ artdata ? RC_sent : RC_missing ]++;
+      art->ipf->counts.counts[art->state][ artdata ? RC_sent : RC_missing ]++;
 
       if (conn->stream) {
        if (artdata) {
 
       if (conn->stream) {
        if (artdata) {
@@ -363,7 +363,7 @@ void conn_make_some_xmits(Conn *conn) {
       XMIT_LITERAL("\r\n");
 
       assert(art->state == art_Unchecked);
       XMIT_LITERAL("\r\n");
 
       assert(art->state == art_Unchecked);
-      art->ipf->counts[art->state][RC_sent]++;
+      art->ipf->counts.counts[art->state][RC_sent]++;
       LIST_ADDTAIL(conn->sent, art);
     }
   }
       LIST_ADDTAIL(conn->sent, art);
     }
   }