chiark / gitweb /
make individual events in Counts into an array
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 29 May 2010 13:16:58 +0000 (14:16 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 29 May 2010 13:16:58 +0000 (14:16 +0100)
cli.c
infile.c
innduct.h
recv.c
statemc.c
xmit.c

diff --git a/cli.c b/cli.c
index be9af383e0745cdbd4448d5be14db86e4e301c75..f34942f04cfb136286882874ed0cb2860a4f23de 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) {
-    DUMPV("%d", ipf->counts.,read_ok);
-    DUMPV("%d", ipf->counts.,read_blank);
-    DUMPV("%d", ipf->counts.,read_err);
-    DUMPV("%d", ipf->counts.,nooffer_missing);
+    DUMPV("%d", ipf->counts.,events[read_ok]);
+    DUMPV("%d", ipf->counts.,events[read_blank]);
+    DUMPV("%d", ipf->counts.,events[read_err]);
+    DUMPV("%d", ipf->counts.,events[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"
-#define RC_DUMP_VAL(x) ,ipf->counts.counts[state][RC_##x]
+#define RC_DUMP_VAL(x) ,ipf->counts.results[state][RC_##x]
       fprintf(f,"input %s counts %-11s"
              RESULT_COUNTS(RC_DUMP_FMT,RC_DUMP_FMT) "\n",
              wh, *statename
index 7ff6a518573a862d6615a4dafef8deab8dc46c6f..4e34c626e1a34eb4d7599b8cac7f1c717d3a6d85 100644 (file)
--- a/infile.c
+++ b/infile.c
@@ -77,11 +77,13 @@ 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));
-  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)
+  ipf->counts.events[read_err]++;
+  if (ipf->counts.events[read_err] > max_bad_data_initial +
+      (ipf->counts.events[read_ok] + ipf->counts.events[read_blank])
+                                                  / max_bad_data_ratio)
     crash("too much garbage in input file!  (%d errs, %d ok, %d blank)",
-         ipf->counts.read_err, ipf->counts.read_ok, ipf->counts.read_blank);
+         ipf->counts.events[read_err], ipf->counts.events[read_ok],
+         ipf->counts.events[read_blank]);
   return OOP_CONTINUE;
 }
 
@@ -129,7 +131,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");
-    ipf->counts.read_blank++;
+    ipf->counts.events[read_blank]++;
     return OOP_CONTINUE;
   }
 
@@ -144,7 +146,7 @@ static void *feedfile_got_article(oop_source *lp, oop_read *rd,
   tokentextbuf[tokenlen]= 0;
   if (!IsToken(tokentextbuf)) X_BAD_DATA("token wrong syntax");
 
-  ipf->counts.read_ok++;
+  ipf->counts.events[read_ok]++;
 
   art= xmalloc(sizeof(*art) - 1 + midlen + 1);
   memset(art,0,sizeof(*art));
index 919b734abfc986b829226a7c89b58eb6277b7829..d6dc8dd033c6516b26cfdc68785cb3efac50aabc 100644 (file)
--- a/innduct.h
+++ b/innduct.h
@@ -218,6 +218,10 @@ typedef enum {
   RCI_max
 } ResultCountIndex;
 
+typedef enum {
+  read_ok, read_blank, read_err, nooffer_missing,
+  ECI_max
+} EventCountIndex;
 
 /*----- transmission buffers -----*/
 
@@ -238,8 +242,8 @@ struct XmitDetails {
 /*----- core operational data structure types -----*/
 
 typedef struct {
-  int counts[art_MaxState][RCI_max];
-  int read_ok, read_blank, read_err, nooffer_missing;
+  int results[art_MaxState][RCI_max];
+  int events[ECI_max];
 } Counts;
 
 struct InputFile {
diff --git a/recv.c b/recv.c
index 5204dced0e7cca479f17900f712c73092be0957b..115a7831ab00c4ea7e5a5a2a8d95742264cf8b67 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)
-    art->ipf->counts.counts[art->state][whichcount]++;
+    art->ipf->counts.results[art->state][whichcount]++;
 
   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);
-    art->ipf->counts.counts[art->state][RC_accepted]++;
+    art->ipf->counts.results[art->state][RC_accepted]++;
     art->state= art_Wanted;
     LIST_ADDTAIL(conn->priority, art);
     break;
index 8b588039b9e4f45e427f93a4e1da8a85dec9dda0..172bbe8afabf040ac91a9b114267b6b4a920e278 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_TRIPLE_VALS(x) , RCI_TRIPLE_VALS_BASE(ipf->counts.counts, [RC_##x])
+#define RCI_TRIPLE_VALS(x) ,RCI_TRIPLE_VALS_BASE(ipf->counts.results, [RC_##x])
 
-#define CNT(art,rc) (ipf->counts.counts[art_##art][RC_##rc])
+#define CNT(art,rc) (ipf->counts.results[art_##art][RC_##rc])
 
   char *inprog= completed
     ? xasprintf("%s","") /* GCC produces a stupid warning for printf("") ! */
@@ -238,8 +238,9 @@ static void notice_processed(InputFile *ipf, int completed,
        RESULT_COUNTS(RCI_NOTHING, RCI_TRIPLE_FMT)
        ,
        completed?"completed":"processed", what, spec,
-       ipf->counts.read_ok, ipf->counts.read_blank, ipf->counts.read_err,
-       inprog, autodefer, ipf->counts.nooffer_missing,
+       ipf->counts.events[read_ok], ipf->counts.events[read_blank],
+         ipf->counts.events[read_err],
+       inprog, autodefer, ipf->counts.events[nooffer_missing],
        CNT(Unchecked,sent) + CNT(Unsolicited,sent)
        , CNT(Unchecked,sent), CNT(Unsolicited,sent),
        CNT(Wanted,accepted) + CNT(Unsolicited,accepted)
diff --git a/xmit.c b/xmit.c
index a4389166b48e59da3eed973d79648ba226cf9112..ace7286296e9c3b4b34f6883b3325d7e47eb15e6 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;
-  art->ipf->counts.nooffer_missing++;
+  art->ipf->counts.events[nooffer_missing]++;
   article_done(art,-1);
   return 1;
 }
@@ -329,7 +329,7 @@ void conn_make_some_xmits(Conn *conn) {
        (abort(),-1);
 
       if (!artdata) art->missing= 1;
-      art->ipf->counts.counts[art->state][ artdata ? RC_sent : RC_missing ]++;
+      art->ipf->counts.results[art->state][ artdata ? RC_sent : RC_missing ]++;
 
       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);
-      art->ipf->counts.counts[art->state][RC_sent]++;
+      art->ipf->counts.results[art->state][RC_sent]++;
       LIST_ADDTAIL(conn->sent, art);
     }
   }