Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libcs/csinfo.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1990-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
* return Sfio_t stream pointer to host info file
26
* if line!=0 then it points to current line number in file
27
*/
28
29
#include "cslib.h"
30
31
Sfio_t*
32
csinfo(register Cs_t* state, const char* file, int* line)
33
{
34
int n;
35
Sfio_t* sp = 0;
36
char buf[PATH_MAX];
37
char tmp[PATH_MAX];
38
struct stat st;
39
40
messagef((state->id, NiL, -8, "info(%s) call", file));
41
if (!file || streq(file, "-")) file = CS_SVC_INFO;
42
if (strmatch(file, "*[ \t\n=]*")) sp = tokline(file, SF_STRING, line);
43
else if (!strchr(file, '/') || stat(file, &st) || S_ISDIR(st.st_mode) || !(sp = tokline(file, SF_READ, line)))
44
for (n = 0; n <= 1; n++)
45
{
46
sfsprintf(tmp, sizeof(tmp), "%s/%s", n ? csvar(state, CS_VAR_SHARE, 0) : CS_SVC_DIR, file);
47
if (pathpath(tmp, "", PATH_REGULAR|PATH_READ, buf, sizeof(buf)))
48
{
49
sp = tokline(buf, SF_READ, line);
50
break;
51
}
52
}
53
if (!sp) messagef((state->id, NiL, -1, "info: %s: not found", file));
54
return sp;
55
}
56
57
Sfio_t*
58
_cs_info(const char* file, int* line)
59
{
60
return csinfo(&cs, file, line);
61
}
62
63