]> diplodocus.org Git - nmh/blob - docs/historical/mh-nov-1983/subs/m_getfld.c
Update XOAUTH2 documentation.
[nmh] / docs / historical / mh-nov-1983 / subs / m_getfld.c
1 #include "mh.h"
2 #include <stdio.h>
3
4 int m_fldsz;
5
6 m_getfld(state, name, buf, bufsz, iob)
7 int state, bufsz;
8 char *name, *buf;
9 FILE *iob;
10 {
11 register char *cp;
12 register c;
13
14 top: while((c = getc(iob)) == '\001' && peekc(iob) == '\001')
15 while(getc(iob) != '\n');
16
17 if(c < 0)
18 return(FILEEOF);
19 m_fldsz = 0;
20
21 switch(state) {
22
23 case FLDEOF:
24 case BODYEOF:
25 case FLD:
26 if(c == '\n' || c == '-')
27 goto body;
28 cp = name;
29 for(;;) {
30 if(cp >= name+NAMESZ-1) {
31 *cp = 0;
32 fprintf(stderr, "??Component Name Exceeds %d Chars:\n \"%s\"\n", NAMESZ-1, name);
33 return(LENERR);
34 }
35 if(c == ':')
36 break;
37 if(c == '\n' || c < 0) {
38 *cp = 0;
39 fprintf(stderr, "??%s Encountered While Scanning for a colon:\n \"%s\"\n",
40 (c < 0)? "<eof>":"<end of line>", name);
41 return(FMTERR);
42 }
43 *cp++ = c;
44 *cp = 0;
45 c = getc(iob);
46 }
47
48 case FLDPLUS:
49 cp = buf;
50 for(;;) {
51 if((c = getc(iob)) < 0)
52 return(FLDEOF);
53 *cp++ = c;
54 *cp = 0;
55 m_fldsz++;
56 if(c == '\n')
57 if((c = peekc(iob)) != ' ' && c != '\t')
58 if(c == '\001' || c < 0)
59 return(FLDEOF);
60 else
61 return(FLD);
62 if(cp >= buf+bufsz-1)
63 return(peekc(iob) < 0? FLDEOF:FLDPLUS);
64 }
65
66 body: if(c == '-')
67 while(getc(iob) != '\n') ;
68 buf[0] = 0;
69 if((c = getc(iob)) == '\001' && peekc(iob) == '\001')
70 return(BODYEOF);
71
72 case BODY:
73 cp = buf; *cp = 0;
74 for(;;) {
75 if(c < 0 || (c == '\001' && peekc(iob) == '\001'))
76 return(BODYEOF);
77 *cp++ = c;
78 *cp = 0;
79 m_fldsz++;
80 if(cp >= buf+bufsz-1)
81 return(((c=peekc(iob))<0||c=='\001')?
82 BODYEOF: BODY);
83 c = getc(iob);
84 }
85
86 }
87 }