Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/sortlib/sync/ss.h
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 2003-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
* ibm dfsort support public interface
24
*
25
* Glenn Fowler
26
* AT&T Research
27
*/
28
29
#ifndef _SS_H
30
#define _SS_H 1
31
32
#include <ast.h>
33
#include <error.h>
34
#include <recsort.h>
35
#include <recfmt.h>
36
#include <vmalloc.h>
37
38
#define SS_VERSION 20050611L
39
40
#define SS_MARKED "*%+([a-z0-9])?(" SS_SUFFIX ")"
41
#define SS_SUFFIX ".*([!A-Z/])"
42
43
#define SS_V_IBM REC_V_TYPE(4,0,2,0,1)
44
45
#define SS_DD_IN "SORTIN"
46
#define SS_DD_OUT "SORTOF"
47
#define SS_DD_XSUM "SORTXSUM"
48
49
#define SS_ascii 'a'
50
#define SS_bcd 'p'
51
#define SS_be 'b'
52
#define SS_bit 'B'
53
#define SS_ebcdic 'c'
54
#define SS_ibm 'i'
55
#define SS_le 'l'
56
#define SS_ss 'S'
57
#define SS_void 'v'
58
#define SS_zd 'z'
59
#define SS_AC_alt 'Q'
60
#define SS_AC_dec 'D'
61
#define SS_AC_flt 'F'
62
#define SS_AC_hex 'H'
63
#define SS_AC_oct 'O'
64
#define SS_CH_dec 'd'
65
#define SS_CH_flt 'f'
66
#define SS_CH_hex 'h'
67
#define SS_CH_oct 'o'
68
69
#define SS_OP_false 0
70
#define SS_OP_true 1
71
#define SS_OP_field 2
72
#define SS_OP_value 3
73
#define SS_OP_lt 4
74
#define SS_OP_le 5
75
#define SS_OP_eq 6
76
#define SS_OP_ne 7
77
#define SS_OP_ge 8
78
#define SS_OP_gt 9
79
#define SS_OP_and 10
80
#define SS_OP_or 11
81
#define SS_OP_not 12
82
83
#define ssopdata(o) ((o)<=SS_OP_value)
84
#define ssopexpr(o) ((o)>=SS_OP_and)
85
86
typedef uintmax_t Sscount_t;
87
88
typedef int (*Ssexit_f)(Rsobj_t*, Rsobj_t*, void**);
89
typedef int (*Ssintercept_f)(Ssexit_f, Rsobj_t*, Rsobj_t*, void**);
90
91
struct Ssdisc_s; typedef struct Ssdisc_s Ssdisc_t;
92
struct Ssexpr_s; typedef struct Ssexpr_s Ssexpr_t;
93
struct Ssfield_s; typedef struct Ssfield_s Ssfield_t;
94
struct Ssfile_s; typedef struct Ssfile_s Ssfile_t;
95
struct Ssgroup_s; typedef struct Ssgroup_s Ssgroup_t;
96
struct Ss_s; typedef struct Ss_s Ss_t;
97
98
union Ssop_u; typedef union Ssop_u Ssop_t;
99
100
struct Ssdisc_s /* user discipline */
101
{
102
unsigned long version; /* interface version */
103
int code; /* default data codeset */
104
Error_f errorf; /* error function */
105
};
106
107
struct Ssfield_s
108
{
109
Ssfield_t* next; /* next in list */
110
size_t offset; /* source record offset */
111
size_t size; /* size in bytes */
112
char* value; /* optional default value */
113
unsigned char type; /* optional type */
114
unsigned char reverse; /* reverse order */
115
};
116
117
union Ssop_u /* expression operand */
118
{
119
Ssfield_t* field; /* field */
120
Ssexpr_t* expr; /* expression */
121
};
122
123
struct Ssexpr_s /* expression node */
124
{
125
Ssop_t left; /* left operand */
126
Ssop_t right; /* right operand */
127
unsigned char op; /* operation */
128
};
129
130
struct Ssgroup_s /* file group circular list */
131
{
132
Ssgroup_t* next; /* next in group (circular) */
133
char* id; /* id name */
134
char* name; /* file name */
135
Sfio_t* io; /* file stream */
136
#ifdef _SS_GROUP_PRIVATE_
137
_SS_GROUP_PRIVATE_
138
#endif
139
};
140
141
struct Ssfile_s /* file info */
142
{
143
Ssfile_t* next; /* next file group */
144
Ssgroup_t* group; /* file group */
145
Ssexpr_t* expr; /* include/omit */
146
Ssfield_t* out; /* output fields */
147
size_t size; /* output record size */
148
Recfmt_t format; /* output record format */
149
unsigned char omit; /* expr is omit */
150
unsigned char save; /* include if omitted by others */
151
#ifdef _SS_FILE_PRIVATE_
152
_SS_FILE_PRIVATE_
153
#endif
154
};
155
156
struct Ss_s /* handle state */
157
{
158
Ssfile_t* file; /* file list -- at least one */
159
Ssfield_t* in; /* input record fields */
160
Ssfield_t* sort; /* optional sort fields */
161
Ssfield_t* sum; /* optional sum fields */
162
Ssdisc_t* disc; /* user discipline */
163
Vmalloc_t* vm; /* handle memory region */
164
Sscount_t skip; /* skip this many records */
165
Sscount_t stop; /* stop after this many records */
166
size_t size; /* input record fixed size */
167
size_t insize; /* in record size */
168
Recfmt_t format; /* input record format */
169
char* suffix; /* input file suffix */
170
Ssexpr_t* expr; /* global include/omit */
171
void* exitstate; /* user exit state */
172
Ssexit_f initexit; /* RS_OPEN exit */
173
Ssexit_f doneexit; /* RS_POP exit */
174
Ssexit_f readexit; /* RS_READ exit */
175
Ssexit_f summaryexit; /* RS_SUMMARY exit */
176
Ssexit_f writeexit; /* RS_WRITE exit */
177
Ssintercept_f intercept; /* Ssexit_f intercept */
178
unsigned char copy; /* copy (no sort) */
179
unsigned char mark; /* mark output files with %size */
180
unsigned char merge; /* merge (no sort) */
181
unsigned char omit; /* expr is omit */
182
unsigned char stable; /* stable sort: 'Y'|'N'|default */
183
unsigned char type; /* input record type */
184
unsigned char uniq; /* drop dup records */
185
#ifdef _SS_PRIVATE_
186
_SS_PRIVATE_
187
#endif
188
};
189
190
#define ssinit(d,e) (memset(d,0,sizeof(Ssdisc_t)),(d)->version=SS_VERSION,(d)->errorf=(Error_f)(e))
191
192
extern Ss_t* ssopen(const char*, Ssdisc_t*);
193
extern int ssdd(const char*, const char*, Ssdisc_t*);
194
extern int sseval(Ss_t*, Ssexpr_t*, const char*, size_t);
195
extern char* sskey(Ss_t*, Ssfield_t*);
196
extern int sslist(Ss_t*, Sfio_t*);
197
extern int sssum(Ss_t*, Ssfield_t*, const char*, size_t, char*);
198
extern ssize_t sscopy(Ss_t*, Ssfile_t*, const char*, size_t, char*, size_t);
199
extern ssize_t sswrite(Ss_t*, Ssfile_t*, const char*, size_t);
200
extern int ssio(Ss_t*, int);
201
extern int ssannounce(Ss_t*, Rs_t*);
202
extern int ssclose(Ss_t*);
203
204
#endif
205
206