/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-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* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped2223#include <ast.h>24#include <ctype.h>2526#define IDENT 0127#define USAGE 022829/*30* format what(1) and/or ident(1) string a31*/3233char*34fmtident(const char* a)35{36register char* s = (char*)a;37register char* t;38char* buf;39int i;4041i = 0;42for (;;)43{44while (isspace(*s))45s++;46if (s[0] == '[')47{48while (*++s && *s != '\n');49i |= USAGE;50}51else if (s[0] == '@' && s[1] == '(' && s[2] == '#' && s[3] == ')')52s += 4;53else if (s[0] == '$' && s[1] == 'I' && s[2] == 'd' && s[3] == ':' && isspace(s[4]))54{55s += 5;56i |= IDENT;57}58else59break;60}61if (i)62{63i &= IDENT;64for (t = s; isprint(*t) && *t != '\n'; t++)65if (i && t[0] == ' ' && t[1] == '$')66break;67while (t > s && isspace(t[-1]))68t--;69i = t - s;70buf = fmtbuf(i + 1);71memcpy(buf, s, i);72s = buf;73s[i] = 0;74}75return s;76}777879