Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libdss/dss-return.h
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 2002-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
/*
23
* return "query"
24
*/
25
26
static const char return_usage[] =
27
"[-1ls5P?\n@(#)$Id: dss return query (AT&T Research) 2007-09-21 $\n]"
28
USAGE_LICENSE
29
"[+PLUGIN?\findex\f]"
30
"[+DESCRIPTION?The \bdss\b \breturn\b query returns from the current"
31
" record query. If \astatus\a is omitted or \bskip\b the current"
32
" record is skipped, if \astatus\a is \bselect\b the current"
33
" record is selected, otherwise if \astatus\a is \bterminate\b"
34
" the scan is terminated and \bdss\b returns exit status \b1\b.]"
35
"\n"
36
"\n [ status ]\n"
37
"\n"
38
;
39
40
static int
41
return_beg(Cx_t* cx, Cxexpr_t* expr, void* data, Cxdisc_t* disc)
42
{
43
char** argv = (char**)data;
44
int errors = error_info.errors;
45
46
for (;;)
47
{
48
switch (optget(argv, return_usage))
49
{
50
case '?':
51
if (disc->errorf)
52
(*disc->errorf)(NiL, disc, ERROR_USAGE|4, "%s", opt_info.arg);
53
continue;
54
case ':':
55
if (disc->errorf)
56
(*disc->errorf)(NiL, disc, 2, "%s", opt_info.arg);
57
continue;
58
}
59
break;
60
}
61
if (error_info.errors > errors)
62
return -1;
63
argv += opt_info.index;
64
if (*argv && *(argv + 1))
65
{
66
if (disc->errorf)
67
(*disc->errorf)(NiL, disc, ERROR_USAGE|4, "%s", optusage(NiL));
68
return -1;
69
}
70
return 0;
71
}
72
73
static int
74
return_act(Cx_t* cx, Cxexpr_t* expr, void* data, Cxdisc_t* disc)
75
{
76
char* s;
77
int r;
78
79
if (!(s = expr->argv[1]) || streq(s, "skip"))
80
r = -2;
81
else if (streq(s, "select"))
82
r = 0;
83
else
84
r = -1;
85
return r;
86
}
87
88
#define QUERY_return \
89
{ \
90
"return", \
91
"return from the current record query", \
92
CXH, \
93
return_beg, \
94
0, \
95
return_act, \
96
0 \
97
}
98
99