-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsgflags.c
110 lines (99 loc) · 2.04 KB
/
msgflags.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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "xutil.h"
#include "lutil.h"
#include "ftnmsg.h"
static char *flnm[] = {
"PVT","CRS","RCV","SNT","ATT","TRN","ORP","K/S",
"LOC","HLD","RSV","FRQ","RRQ","RRC","ARQ","FUP"
};
int flag_on(char *,char *);
int flagset(s)
char *s;
{
char *buf,*p;
int i;
int fl=0;
debug(5,"setting flags from string \"%s\"",S(s));
buf=xstrcpy(s);
for (p=strtok(buf," ,\t\n");p;p=strtok(NULL," ,\t\n"))
{
for (i=0;i<16;i++)
if (!strcasecmp(p,flnm[i]))
{
debug(5,"setting flag bit %d for \"%s\"",
i,S(p));
fl |= (1 << i);
}
}
free(buf);
debug(5,"set flags 0x%04x",fl);
return fl;
}
char *compose_flags(flags,fkludge)
int flags;
char *fkludge;
{
int i;
char *buf=NULL,*p;
debug(5,"composing flag string from binary 0x%04x and string \"%s\"",
flags,S(fkludge));
if (fkludge)
{
if (!isspace(fkludge[0])) buf=xstrcpy(" ");
buf=xstrcat(buf,fkludge);
p=buf+strlen(buf)-1;
while (isspace(*p)) *p--='\0';
}
for (i=0;i<16;i++)
if ((flags & (1 << i)) && (!flag_on(flnm[i],buf)))
{
buf=xstrcat(buf," ");
buf=xstrcat(buf,flnm[i]);
debug(5,"adding \"%s\"",flnm[i]);
}
debug(5,"resulting string is \"%s\"",buf);
return buf;
}
char *strip_flags(flags)
char *flags;
{
char *p,*q=NULL,*tok;
int canonic,i;
debug(5,"stripping official flags from \"%s\"",S(flags));
if (flags == NULL) return NULL;
p=xstrcpy(flags);
for (tok=strtok(flags,", \t\n");tok;tok=strtok(NULL,", \t\n"))
{
canonic=0;
for (i=0;i<16;i++)
if (strcasecmp(tok,flnm[i]) == 0)
canonic=1;
if (!canonic)
{
q=xstrcat(q," ");
q=xstrcat(q,tok);
}
}
free(p);
debug(5,"stripped string is \"%s\"",q);
return q;
}
int flag_on(flag,flags)
char *flag,*flags;
{
char *p,*tok;
int up=0;
debug(5,"checking flag \"%s\" in string \"%s\"",S(flag),S(flags));
if (flags == NULL) return 0;
p=xstrcpy(flags);
for (tok=strtok(p,", \t\n");tok;tok=strtok(NULL,", \t\n"))
{
if (strcasecmp(flag,tok) == 0) up=1;
}
free(p);
debug(5,"flag%s present",up?"":" not");
return up;
}