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