Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libexpr/excontext.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1989-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
* Glenn Fowler
23
* AT&T Research
24
*
25
* expression library
26
*/
27
28
#include "exlib.h"
29
30
/*
31
* copy input token error context into buf of n chars and reset the context
32
* end of buf returned
33
*/
34
35
char*
36
excontext(Expr_t* p, char* buf, int n)
37
{
38
register char* s;
39
register char* t;
40
register char* e;
41
42
s = buf;
43
if (p->linep > p->line || p->linewrap)
44
{
45
e = buf + n - 5;
46
if (p->linewrap)
47
{
48
t = p->linep + 1;
49
while (t < &p->line[sizeof(p->line)] && isspace(*t))
50
t++;
51
if ((n = (sizeof(p->line) - (t - (p->linep + 1))) - (e - s)) > 0)
52
{
53
if (n > &p->line[sizeof(p->line)] - t)
54
t = &p->line[sizeof(p->line)];
55
else t += n;
56
}
57
while (t < &p->line[sizeof(p->line)])
58
*s++ = *t++;
59
}
60
t = p->line;
61
if (p->linewrap)
62
p->linewrap = 0;
63
else while (t < p->linep && isspace(*t))
64
t++;
65
if ((n = (p->linep - t) - (e - s)) > 0)
66
t += n;
67
while (t < p->linep)
68
*s++ = *t++;
69
p->linep = p->line;
70
t = "<<< ";
71
while (*s = *t++)
72
s++;
73
}
74
*s = 0;
75
return s;
76
}
77
78