Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libcs/msggetmask.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1990-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
22
#include "msglib.h"
23
24
/*
25
* put list of msg names in mask into buffer b,n
26
* ! as first char means inverted mask
27
* size of mask is returned
28
* negative of required size returned on overflow
29
* if b==0 then size is just returned
30
*/
31
32
int
33
msggetmask(char* buf, register int n, register unsigned long mask)
34
{
35
register char* b;
36
register const char* s;
37
register int m;
38
register int n0;
39
register int n1;
40
char* e;
41
42
if (n <= 1) return 0;
43
if (b = buf) e = b + n;
44
for (n0 = n1 = 0, m = 1; m <= MSG_STD; m++)
45
{
46
n = strlen(msgname(m)) + 1;
47
if (mask & MSG_MASK(m)) n1 += n;
48
else n0 += n;
49
}
50
if (n = (n1 > n0))
51
{
52
n0++;
53
if (!b) return n0;
54
n0 = -n0;
55
if (b >= e) return n0;
56
*b++ = '!';
57
}
58
else if (!b) return n1;
59
else n0 = -n1;
60
for (m = 1; m <= MSG_STD; m++)
61
if ((mask & MSG_MASK(m)) == 0 == n)
62
{
63
s = msg_info.name[m];
64
while (n1 = *s++)
65
{
66
if (b >= e) return n0;
67
*b++ = n1;
68
}
69
if (b >= e) return n0;
70
*b++ = ',';
71
}
72
if (b > buf && *(b - 1) == ',') b--;
73
*b = 0;
74
return b - buf;
75
}
76
77