/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1990-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* *18***********************************************************************/19#pragma prototyped2021#include "msglib.h"2223/*24* put list of msg names in mask into buffer b,n25* ! as first char means inverted mask26* size of mask is returned27* negative of required size returned on overflow28* if b==0 then size is just returned29*/3031int32msggetmask(char* buf, register int n, register unsigned long mask)33{34register char* b;35register const char* s;36register int m;37register int n0;38register int n1;39char* e;4041if (n <= 1) return 0;42if (b = buf) e = b + n;43for (n0 = n1 = 0, m = 1; m <= MSG_STD; m++)44{45n = strlen(msgname(m)) + 1;46if (mask & MSG_MASK(m)) n1 += n;47else n0 += n;48}49if (n = (n1 > n0))50{51n0++;52if (!b) return n0;53n0 = -n0;54if (b >= e) return n0;55*b++ = '!';56}57else if (!b) return n1;58else n0 = -n1;59for (m = 1; m <= MSG_STD; m++)60if ((mask & MSG_MASK(m)) == 0 == n)61{62s = msg_info.name[m];63while (n1 = *s++)64{65if (b >= e) return n0;66*b++ = n1;67}68if (b >= e) return n0;69*b++ = ',';70}71if (b > buf && *(b - 1) == ',') b--;72*b = 0;73return b - buf;74}757677