1 /*
2 **
3 ** Copyright (C) 1993 Swedish University Network (SUNET)
4 **
5 **
6 ** This program is developed by UDAC, Uppsala University by commission
7 ** of the Swedish University Network (SUNET).
8 **
9 ** This program is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (at your option) any later version.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITTNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 **
23 **
24 **                                           Martin.Wendel@its.uu.se
25 ** 				             Torbjorn.Wictorin@its.uu.se
26 **
27 **                                           ITS
28 **                                           P.O. Box 887
29 **                                           S-751 08 Uppsala
30 **                                           Sweden
31 **
32 */
33 #include "emil.h"
34 
35 void
check_bits(struct data * d)36 check_bits(struct data *d)
37 {
38   int offset;
39   unsigned char *c;
40 #ifdef DEBUG
41   int deb = 1;
42   if (edebug)
43     fprintf(stderr, "check_bits: encoding is set to %d, start %lu end %lu\n", d->encoding, d->bodystart, d->bodyend);
44 #endif
45 
46   if (d->encoding == 0)
47     d->encoding = E7BIT;
48   if (d->encoding == E7BIT)
49     {
50       for (offset = d->bodystart, c = d->contents + offset;
51 	   offset < d->bodyend;
52 	   offset++, c++)
53 	{
54 	  if (*c == '\0')
55 	    {
56 #ifdef DEBUG
57 	      if (edebug)
58 		fprintf(stderr, "-   checked 7bit, saw binary.\n");
59 #endif
60 	      d->encoding = EBINARY;
61 	      return;
62 	    }
63 
64 	  if (*c & 0x80)
65 	    {
66 #ifdef DEBUG
67 	      if (edebug && deb)
68 		{
69 		  fprintf(stderr, "-   checked 7bit, saw 8bit.\n");
70 		  deb = 0;
71 		}
72 #endif
73 	      d->encoding = E8BIT;
74 	    }
75 	}
76       return;
77     }
78   if (d->encoding == E8BIT)
79     {
80       for (offset = d->bodystart, c = d->contents + offset;
81 	   offset < d->bodyend;
82 	   offset++, c++)
83 	{
84 	  if (*c == '\0')
85 	    {
86 #ifdef DEBUG
87 	      if (edebug)
88 		fprintf(stderr, "-   checked 8bit, saw binary.\n");
89 #endif
90 	      d->encoding = EBINARY;
91 	      return;
92 	    }
93 	}
94     }
95   return;
96 }
97