-
Notifications
You must be signed in to change notification settings - Fork 0
/
parseaddress.c
138 lines (125 loc) · 3.47 KB
/
parseaddress.c
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* parse.c */
#include "packman.h"
/*
ParseAddress : Parse a fidonet address (very forgiving)
uses a finite state machine using a method described in :
Computer Language Volume 8, Number 5 (May 1991) article,
"Goto Yes, goto !" by Tim Cooper
Parameters :
char *line : pointer to first character of address to be parsed
struct fidaddr *fid : Pointer to structure which will contain parsed address
(structure must be allocated)
Returnvalues :
Succes :
x:y/z.q 4 | 3 x:y/z
y/z.q 3 | 2 y/z
z.q 2 | 1 z
+8 | +0
----+----
return value
Failure : -1
*/
int parseaddress(char *line,struct fidaddr *fid,char wild) {
char symbol;
int transport,type;
printmsg(3,"ParseAddress\n");
/* Initialize structure on 0 */
fid->Zone=fid->Net=fid->Node=fid->Point=0;
/* First part must be a number or wildcard */
if (wild==NOWILD || *line!='*') {
if (getnum(&transport,&line)==-1) {
nextstate(NUMERROR);
}
} else {
transport=WILDCARD;
line++;
}
state(START): /* Here we go */
type=1; /* Number of address fields */
switch(symbol) {
case ':' : /* It is address with either 3 or 4 */
/* address fields */
fid->Zone=transport;
if (*line!='*' || wild==NOWILD) {
if (getnum(&transport,&line)==-1) {
nextstate(NUMERROR);
}
} else {
transport=WILDCARD;
line++;
}
nextstate(ADDR3OR4);
case '/' : /* It is address with either 2 or 3 */
/* address fields */
fid->Net=transport;
if (*line!='*' || wild==NOWILD) {
if (getnum(&transport,&line)==-1) {
nextstate(NUMERROR);
}
} else {
transport=WILDCARD;
line++;
}
nextstate(ADDR2OR3);
case '.' : /* It is address with 2 */
/* address fields */
fid->Node=transport;
if (*line!='*' || wild==NOWILD) {
if (getnum(&transport,&line)==-1) {
nextstate(NUMERROR);
}
} else {
transport=WILDCARD;
line++;
}
nextstate(ADDR2);
default: /* It is a 1 field address */
fid->Node=transport;
nextstate(END);
}
state(ADDR3OR4):type+=1; /* Add 1 to number of fields */
/* There needs to be a slash otherwise */
/* it is isn't a correct address */
if (symbol=='/') {
fid->Net=transport;
if (*line!='*' || wild==NOWILD) {
if (getnum(&transport,&line)==-1) {
nextstate(NUMERROR);
}
} else {
transport=WILDCARD;
line++;
}
nextstate(ADDR2OR3);
} else {
nextstate(ERROR);
}
state(ADDR2OR3):type+=1; /* Add 1 to number of fields */
/* It going to be address with or without Point */
if (symbol=='.') {
fid->Node=transport;
if (*line!='*' || wild==NOWILD) {
if (getnum(&transport,&line)==-1) {
nextstate(NUMERROR);
}
} else {
transport=WILDCARD;
line++;
}
nextstate(ADDR2);
} else {
fid->Node=transport;
nextstate(END);
}
state(ADDR2): type+=1; /* Add 1 to number of fields */
type+=8; /* 4D type message */
fid->Point=transport;
nextstate(END);
state(ERROR): printmsg(0,"Parse error malformed address\n");
type=-1;
nextstate(END);
state(NUMERROR):printmsg(0,"Parse error invalid address\n");
type=-1;
nextstate(END);
state(END): return(type);
}