Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/librecsort/rslib.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1996-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
* Phong Vo <[email protected]> *
18
* Glenn Fowler <[email protected]> *
19
* *
20
***********************************************************************/
21
#pragma prototyped
22
23
#include "rskeyhdr.h"
24
25
#include <dlldefs.h>
26
#include <option.h>
27
28
typedef Rsdisc_t* (*Rslib_f)(Rskey_t*, const char*);
29
30
int
31
#if __STD_C
32
rslib(Rs_t* rs, Rskey_t* kp, const char* lib, int flags)
33
#else
34
rslib(rs, kp, lib, flags)
35
Rs_t* rs;
36
Rskey_t* kp;
37
const char* lib;
38
int flags;
39
#endif
40
{
41
register char* s;
42
void* dll;
43
Rsdisc_t* disc;
44
Rslib_f fun;
45
char path[PATH_MAX];
46
Opt_t opt;
47
48
static const char symbol[] = "rs_disc";
49
50
for (s = (char*)lib; *s && *s != ',' && *s != '\t' && *s != '\r' && *s != '\n'; s++);
51
sfsprintf(path, sizeof(path), "%-.*s", s - (char*)lib, lib);
52
if (!(dll = dllplugin("sort", path, NiL, RS_PLUGIN_VERSION, NiL, RTLD_LAZY, path, sizeof(path))))
53
{
54
if (!(flags & RS_IGNORE) && kp->keydisc->errorf)
55
(*kp->keydisc->errorf)(kp, kp->keydisc, 2, "%s: library not found", path);
56
return -1;
57
}
58
if (!(fun = (Rslib_f)dlllook(dll, symbol)))
59
{
60
if (!(flags & RS_IGNORE) && kp->keydisc->errorf)
61
(*kp->keydisc->errorf)(kp, kp->keydisc, 2, "%s: %s: initialization function not found in library", path, symbol);
62
return -1;
63
}
64
if (*s)
65
s++;
66
else if (flags & RS_IGNORE)
67
return 0;
68
opt = opt_info;
69
disc = (*fun)(kp, s);
70
opt_info = opt;
71
if (!disc)
72
return -1;
73
if (!kp->disctail)
74
kp->disctail = kp->disc;
75
kp->disctail = kp->disctail->disc = disc;
76
rs->events |= disc->events;
77
return 0;
78
}
79
80