File: bread.c

package info (click to toggle)
ifmail 2.14tx8.10-32
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,056 kB
  • sloc: ansic: 30,328; perl: 4,955; yacc: 839; makefile: 716; sh: 424; cpp: 235; lex: 206; awk: 24
file content (82 lines) | stat: -rw-r--r-- 1,314 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* ### Modified by P.Saratxaga on 29 Oct 1995 ###
 * - deleted transcodage (outtab & intab) code (now transcodage is done by
 *   strconv() function.
 * - added IGNORE_SOFTCR option from T.Tanaka.
 * - added pgpsigned. If true then text is unchanged PGP
 */
#include <stdio.h>
#include "bread.h"
#include "config.h"

#ifndef IGNORE_SOFTCR
extern int pgpsigned;
#endif

/* read short (16bit) integer in "standart" byte order */
int iread(fp)
FILE *fp;
{
	unsigned char lo,hi;

	fread(&lo,1,1,fp);
	fread(&hi,1,1,fp);
	return (hi<<8) | lo;
}

/* read long (32bit) integer in "standart" byte order */
long lread(fp)
FILE *fp;
{
	int c;
	unsigned char buf;
	long ret=0L;

	for (c=0;c<32;c+=8)
	{
		fread(&buf,1,1,fp);
		ret |= ((unsigned long)buf << c);
	}
	return ret;
}

static int at_zero=0;

char *aread(s,count,fp)
char *s;
int count;
FILE *fp;
{
	int i,c,next;

	if (feof(fp)) return(NULL);
	if (s == NULL) return NULL;
	if (at_zero)
	{
		at_zero=0;
		return NULL;
	}

	for (i=0,next=1;(i<count-1) && next;)
	switch (c=getc(fp))
	{
	case '\n':	break;
	case '\r':	s[i]='\n';
			i++;
			next=0;
			break;
#ifndef IGNORE_SOFTCR
	case 0x8d:	if (!pgpsigned) s[i]=' ';
			else s[i]=c;
			i++;
			break;
#endif
	case '\0':	at_zero=1;
			next=0;
			break;
	default:	s[i]=c;
			i++;
			break;
	}
	s[i]='\0';
	return s;
}