/***********************************************************************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 prototyped22/*23* Glenn Fowler24* AT&T Research25*26* escape optget() special chars in s and write to sp27* esc == '?' or ':' also escaped28*/2930#include <optlib.h>31#include <ctype.h>3233int34optesc(Sfio_t* sp, register const char* s, int esc)35{36register const char* m;37register int c;3839if (*s == '[' && *(s + 1) == '+' && *(s + 2) == '?')40{41c = strlen(s);42if (s[c - 1] == ']')43{44sfprintf(sp, "%-.*s", c - 4, s + 3);45return 0;46}47}48if (esc != '?' && esc != ':')49esc = 0;50while (c = *s++)51{52if (isalnum(c))53{54for (m = s - 1; isalnum(*s); s++);55if (isalpha(c) && *s == '(' && isdigit(*(s + 1)) && *(s + 2) == ')')56{57sfputc(sp, '\b');58sfwrite(sp, m, s - m);59sfputc(sp, '\b');60sfwrite(sp, s, 3);61s += 3;62}63else64sfwrite(sp, m, s - m);65}66else if (c == '-' && *s == '-' || c == '<')67{68m = s - 1;69if (c == '-')70s++;71else if (*s == '/')72s++;73while (isalnum(*s))74s++;75if (c == '<' && *s == '>' || isspace(*s) || *s == 0 || *s == '=' || *s == ':' || *s == ';' || *s == '.' || *s == ',')76{77sfputc(sp, '\b');78sfwrite(sp, m, s - m);79sfputc(sp, '\b');80}81else82sfwrite(sp, m, s - m);83}84else85{86if (c == ']' || c == esc)87sfputc(sp, c);88sfputc(sp, c);89}90}91return 0;92}939495