Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libdss/dss-count.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
* count query
24
*/
25
26
static const char count_usage[] =
27
"[-1ls5P?\n@(#)$Id: dss count query (AT&T Research) 2002-12-09 $\n]"
28
USAGE_LICENSE
29
"[+PLUGIN?\findex\f]"
30
"[+DESCRIPTION?The \bdss\b \bcount\b query prints the parent expression"
31
" selected/queried record counts. The output line is preceded by"
32
" \alabel:\a if the \alabel\a operand is specified.]"
33
"\n"
34
"\n [ label ]\n"
35
"\n";
36
37
static int
38
count_beg(Cx_t* cx, Cxexpr_t* expr, void* data, Cxdisc_t* disc)
39
{
40
char** argv = (char**)data;
41
int errors = error_info.errors;
42
43
for (;;)
44
{
45
switch (optget(argv, count_usage))
46
{
47
case '?':
48
if (disc->errorf)
49
(*disc->errorf)(NiL, disc, ERROR_USAGE|4, "%s", opt_info.arg);
50
continue;
51
case ':':
52
if (disc->errorf)
53
(*disc->errorf)(NiL, disc, 2, "%s", opt_info.arg);
54
continue;
55
}
56
break;
57
}
58
if (error_info.errors > errors)
59
return -1;
60
argv += opt_info.index;
61
if ((expr->data = *argv++) && *argv)
62
{
63
if (disc->errorf)
64
(*disc->errorf)(NiL, disc, ERROR_USAGE|4, "%s", optusage(NiL));
65
return -1;
66
}
67
return 0;
68
}
69
70
static int
71
count_end(Cx_t* cx, Cxexpr_t* expr, void* data, Cxdisc_t* disc)
72
{
73
if (expr->data)
74
sfprintf(expr->op, "%s: ", (char*)expr->data);
75
sfprintf(expr->op, "%I*u/%I*u\n", sizeof(expr->parent->selected), expr == expr->parent->fail ? (expr->parent->queried - expr->parent->selected) : expr->parent->selected, sizeof(expr->parent->queried), expr->parent->queried);
76
return 0;
77
}
78
79
#define QUERY_count \
80
{ \
81
"count", \
82
"print parent expression record counts", \
83
CXH, \
84
count_beg, \
85
0, \
86
0, \
87
count_end \
88
}
89
90