chiark / gitweb /
send voting url to admin not to voters
[modbot-mtm.git] / stump / c / checkquot.c
1 #include <stdio.h>
2 #include <stdlib.h>
3
4
5 main(int argc, char *argv[])
6 {
7   double Qratio;
8   int MaxLines;
9
10   FILE *fp;
11   char buf[100];
12   int i, lines=0, prefixes[256];
13   
14   /* initialize array of # of prefixes (for each ascii char) */
15   for(i=0; i<256; prefixes[i]=0, i++);
16
17   /* set values for quote ratio and max #lines */
18   Qratio   = argc>1 ? atof(argv[1]) : .75 ;
19   MaxLines = argc>2 ? atoi(argv[2]) : 20 ;
20       
21   /* open input file or stdin */
22   if(argc<=3 || ! ( fp = fopen(argv[3], "r") ) )
23     fp = stdin;
24   
25   /* read input  */
26   while( fgets(buf, 99, fp) )
27     {
28       int i;
29
30       /* get to the first non-white char in line */
31       for(i=0; buf[i] < 33 && buf[i] > 0; i++);
32
33       /* string is non-empty */
34       if( buf[i] != '\0' )
35         {
36           /* increment prefix counter for this prefix */
37           prefixes[ (int) buf[i] ]++;
38       
39           /* increment line counter */
40           lines++;
41         }
42     }
43   
44     if( lines > MaxLines )
45       for( i=0; i<256; i++ )
46
47         /* overquote with char i */
48         if( prefixes[i] > Qratio*lines )
49             exit(1);
50
51   /* everytjing seems ok */
52   exit(0);
53 }
54