chiark / gitweb /
Initial commit as found
[modbot-ulm.git] / stump / c / isbinary.c
1 /*
2     isbinary.c
3
4   This program reads an article from standard input and checks if it 
5   is a uuencoded binary. If it is, exits with exit code 0, otherwise 
6   retcode = 1.
7
8   GNU Copyright applies. ichudov@algebra.com
9
10 */
11
12 #include <stdio.h>
13
14 #define MAX_BUF 16384
15 #define MAX_BINARY_LINES 10
16
17 char buf[MAX_BUF];
18
19 int main( int argc, char *argv[] )
20 {
21   int nBinLines = 0, maxNBinLines = 0;
22
23   /* skip header */
24   while( fgets( buf, MAX_BUF, stdin ) ) 
25     if( strlen( buf ) <= 1 ) break;
26
27   while( fgets( buf, MAX_BUF, stdin ) ) {
28     if( strlen( buf ) > 45 /* buf long enough */
29         && (!(strchr( buf, ' ' ) || strchr( buf, '\t' )) /* no spaces */
30            || (buf[0] == 'M') )  /* some uuencoded stuff begins with 'M' */
31       ) { /* likely a uuencoded line */
32       nBinLines++;
33       maxNBinLines = (nBinLines > maxNBinLines) ? nBinLines : maxNBinLines;
34     } else nBinLines = 0;
35   }
36
37   /* more than 10 consecutive 45 char lines with no blank - likely binary */
38   return( maxNBinLines < MAX_BINARY_LINES );
39 }