/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1989-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 prototyped20/*21* Glenn Fowler22* AT&T Research23*24* expression library25*/2627#include "exlib.h"2829/*30* copy input token error context into buf of n chars and reset the context31* end of buf returned32*/3334char*35excontext(Expr_t* p, char* buf, int n)36{37register char* s;38register char* t;39register char* e;4041s = buf;42if (p->linep > p->line || p->linewrap)43{44e = buf + n - 5;45if (p->linewrap)46{47t = p->linep + 1;48while (t < &p->line[sizeof(p->line)] && isspace(*t))49t++;50if ((n = (sizeof(p->line) - (t - (p->linep + 1))) - (e - s)) > 0)51{52if (n > &p->line[sizeof(p->line)] - t)53t = &p->line[sizeof(p->line)];54else t += n;55}56while (t < &p->line[sizeof(p->line)])57*s++ = *t++;58}59t = p->line;60if (p->linewrap)61p->linewrap = 0;62else while (t < p->linep && isspace(*t))63t++;64if ((n = (p->linep - t) - (e - s)) > 0)65t += n;66while (t < p->linep)67*s++ = *t++;68p->linep = p->line;69t = "<<< ";70while (*s = *t++)71s++;72}73*s = 0;74return s;75}767778