Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libdss/dss-write.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
* write query
24
*/
25
26
static const char write_usage[] =
27
"[-1ls5P?\n@(#)$Id: dss write query (AT&T Research) 2002-12-12 $\n]"
28
USAGE_LICENSE
29
"[+PLUGIN?\findex\f]"
30
"[+DESCRIPTION?The \bdss\b \bwrite\b query writes the"
31
" current record according to the method-specific \aformat\a."
32
" If \aformat\a is omitted then the input record format is assumed."
33
" The formats are:]{\fformats\f}"
34
"\n"
35
"\n [ format] \n"
36
"\n";
37
38
static int
39
write_beg(Cx_t* cx, Cxexpr_t* expr, void* data, Cxdisc_t* disc)
40
{
41
char** argv = (char**)data;
42
int errors = error_info.errors;
43
Dssformat_t* format;
44
45
for (;;)
46
{
47
switch (optget(argv, write_usage))
48
{
49
case '?':
50
if (disc->errorf)
51
(*disc->errorf)(NiL, disc, ERROR_USAGE|4, "%s", opt_info.arg);
52
continue;
53
case ':':
54
if (disc->errorf)
55
(*disc->errorf)(NiL, disc, 2, "%s", opt_info.arg);
56
continue;
57
}
58
break;
59
}
60
if (error_info.errors > errors)
61
return -1;
62
argv += opt_info.index;
63
if (expr->data = *argv++)
64
{
65
if (*argv)
66
{
67
if (disc->errorf)
68
(*disc->errorf)(NiL, disc, ERROR_USAGE|4, "%s", optusage(NiL));
69
return -1;
70
}
71
if (!(format = dssformat(expr->data, disc, DSS(cx)->meth)))
72
{
73
if (disc->errorf)
74
(*disc->errorf)(NiL, disc, 2, "%s: unknown format", (char*)expr->data);
75
return -1;
76
}
77
}
78
else
79
format = 0;
80
if (!(expr->data = dssfopen(DSS(cx), expr->file, expr->op, DSS_FILE_WRITE, format)))
81
return -1;
82
return 0;
83
}
84
85
static int
86
write_act(Cx_t* cx, Cxexpr_t* expr, void* data, Cxdisc_t* disc)
87
{
88
return dssfwrite((Dssfile_t*)expr->data, data);
89
}
90
91
static int
92
write_end(Cx_t* cx, Cxexpr_t* expr, void* data, Cxdisc_t* disc)
93
{
94
return dssfclose((Dssfile_t*)expr->data);
95
}
96
97
static int
98
write_ref(Cx_t* cx, Cxexpr_t* expr, void* data, Cxdisc_t* disc)
99
{
100
DSS(cx)->flags |= DSS_WRITE;
101
return 0;
102
}
103
104
#define QUERY_write \
105
{ \
106
"write", \
107
"write the current record", \
108
CXH, \
109
write_beg, \
110
0, \
111
write_act, \
112
write_end, \
113
0, \
114
write_ref \
115
}
116
117